+
+ /* First check whether we can touch this command at all. If this
+ * command is a read, and there is an inflight write, OR if this
+ * command is a write, and there is an inflight read or write, then
+ * we need to leave the command alone and signal that we are blocked
+ */
+
+ if (!looseordering)
+ {
+ uint64_t cfrom;
+ uint32_t clen;
+ cfrom = from;
+ clen = len;
+ while (clen > 0) {
+ uint64_t blknum = cfrom>>9;
+ if (cfrom>=size) {
+ snprintf(errstr, errstr_len, "offset %llx beyond size %llx",
+ (long long int) cfrom, (long long int)size);
+ goto err_open;
+ }
+ if (blkhash[blknum].inflightw ||
+ (blkhash[blknum].inflightr &&
+ ((command & NBD_CMD_MASK_COMMAND)==NBD_CMD_WRITE))) {
+ blocked=1;
+ break;
+ }
+ cfrom += 512;
+ clen -= 512;
+ }
+ }
+
+ if (blocked)
+ goto skipdequeue;
+
+ rclist_unlink(&txqueue, prc);
+ rclist_addtail(&inflight, prc);
+
+ dumpcommand("Sending command", prc->req.type);