Skip to contentSkip to conversation

nbd: Zero from and len fields in NBD_CMD_DISCONNECT.

PATCH In review Hani Benhabiles 2 participants 2 messages May 25, 2014 – May 26, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nbd: Zero from and len fields in NBD_CMD_DISCONNECT.

Len field is already set to zero, but not the from field which is sent as 0xfffffffffffffe00. This makes no sense, and may cause confuse server implementations doing sanity checks (qemu-nbd is an example.)

---

Compared to v1:
* Zero the request structure instead of conditionally zeroing specific fields.

 drivers/block/nbd.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/block/nbd.c +2 -5
index 3a70ea2..8e1df52 100644
@@ -243,14 +243,11 @@ static int nbd_send_req(struct nbd_device *nbd, struct request *req)
 	struct nbd_request request;
 	unsigned long size = blk_rq_bytes(req);
 
+	memset(&request, 0, sizeof(request));
 	request.magic = htonl(NBD_REQUEST_MAGIC);
 	request.type = htonl(nbd_cmd(req));
 
-	if (nbd_cmd(req) == NBD_CMD_FLUSH) {
-		/* Other values are reserved for FLUSH requests.  */
-		request.from = 0;
-		request.len = 0;
-	} else {
+	if (nbd_cmd(req) != NBD_CMD_FLUSH && nbd_cmd(req) != NBD_CMD_DISC) {
 		request.from = cpu_to_be64((u64)blk_rq_pos(req) << 9);
 		request.len = htonl(size);
 	}
Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 9 lines · Hani Benhabiles

Len field is already set to zero, but not the from field which is sent as 0xfffffffffffffe00. This makes no sense, and may cause confuse server implementations doing sanity checks (qemu-nbd is an example.)

---

Compared to v1:
* Zero the request structure instead of conditionally zeroing specific fields.

Yeah, this one looks good. Sorry for the confusion on the structs...

Quoted 27 lines
 drivers/block/nbd.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/block/nbd.c +2 -6
index 3a70ea2..8e1df52 100644
@@ -243,14 +243,11 @@ static int nbd_send_req(struct nbd_device *nbd, struct request *req)
        struct nbd_request request;
        unsigned long size = blk_rq_bytes(req);
 
+       memset(&request, 0, sizeof(request));
        request.magic = htonl(NBD_REQUEST_MAGIC);
        request.type = htonl(nbd_cmd(req));
 
-       if (nbd_cmd(req) == NBD_CMD_FLUSH) {
-               /* Other values are reserved for FLUSH requests.  */
-               request.from = 0;
-               request.len = 0;
-       } else {
+       if (nbd_cmd(req) != NBD_CMD_FLUSH && nbd_cmd(req) != NBD_CMD_DISC) {
                request.from = cpu_to_be64((u64)blk_rq_pos(req) << 9);
                request.len = htonl(size);
        }
--

1.8.3.2