lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1315467898-23984-3-git-send-email-pbonzini@redhat.com>
Date:	Thu,  8 Sep 2011 09:44:58 +0200
From:	Paolo Bonzini <pbonzini@...hat.com>
To:	linux-kernel@...r.kernel.org
Cc:	Paul Clements <Paul.Clements@...eleye.com>,
	<nbd-general@...ts.sf.net>
Subject: [PATCH v2 2/2] nbd: map DISCARD requests to a new nbd request type

When the feature is enabled, set QUEUE_FLAG_DISCARD and transmit those as
NBD_CMD_TRIM requests.

I used "trim" instead of "discard" to avoid confusion with the existing
NBD_CMD_DISC that is used for disconnect.

Cc: Paul Clements <Paul.Clements@...eleye.com>
Cc: <nbd-general@...ts.sf.net>
Reviewed-by: Paul Clements <Paul.Clements@...eleye.com>
Signed-off-by: Paolo Bonzini <pbonzini@...hat.com>
---
        This patch is the same as in v1.

 drivers/block/nbd.c |   14 +++++++++++++-
 include/linux/nbd.h |    4 +++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index c4fe9c8..71ebaab 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -98,6 +98,7 @@ static const char *nbdcmd_to_ascii(int cmd)
 	case  NBD_CMD_READ: return "read";
 	case NBD_CMD_WRITE: return "write";
 	case  NBD_CMD_DISC: return "disconnect";
+	case  NBD_CMD_TRIM: return "trim (discard)";
 	}
 	return "invalid";
 }
@@ -453,12 +453,16 @@ static void nbd_handle_req(struct nbd_device *lo, struct request *req)
 
 	nbd_cmd(req) = NBD_CMD_READ;
 	if (rq_data_dir(req) == WRITE) {
-		nbd_cmd(req) = NBD_CMD_WRITE;
 		if (lo->flags & NBD_FLAG_READ_ONLY) {
 			printk(KERN_ERR "%s: Write on read-only\n",
 					lo->disk->disk_name);
 			goto error_out;
 		}
+		if ((req->cmd_flags & REQ_DISCARD)) {
+			WARN_ON(!(lo->flags & NBD_FLAG_HAS_TRIM));
+			nbd_cmd(req) = NBD_CMD_TRIM;
+		} else
+			nbd_cmd(req) = NBD_CMD_WRITE;
 	}
 
 	req->errors = 0;
@@ -659,6 +664,9 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
 			return -EINVAL;
 
 		mutex_unlock(&lo->tx_lock);
+		if (lo->flags & NBD_FLAG_HAS_TRIM)
+			queue_flag_set_unlocked(QUEUE_FLAG_DISCARD,
+						lo->disk->queue);
 
 		thread = kthread_create(nbd_thread, lo, lo->disk->disk_name);
 		if (IS_ERR(thread)) {
@@ -677,6 +685,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
 		lo->file = NULL;
 		nbd_clear_que(lo);
 		printk(KERN_WARNING "%s: queue cleared\n", lo->disk->disk_name);
+		queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, lo->disk->queue);
 		if (file)
 			fput(file);
 		lo->flags = 0;
@@ -796,6 +805,9 @@ static int __init nbd_init(void)
 		 * Tell the block layer that we are not a rotational device
 		 */
 		queue_flag_set_unlocked(QUEUE_FLAG_NONROT, disk->queue);
+		disk->queue->limits.discard_granularity = 512;
+		disk->queue->limits.max_discard_sectors = UINT_MAX;
+		disk->queue->limits.discard_zeroes_data = 0;
 	}
 
 	if (register_blkdev(NBD_MAJOR, "nbd")) {
diff --git a/include/linux/nbd.h b/include/linux/nbd.h
index 926f19d..7048463 100644
--- a/include/linux/nbd.h
+++ b/include/linux/nbd.h
@@ -33,11 +33,13 @@
 
 /* values for flags field */
 #define NBD_FLAG_READ_ONLY	(1 << 1)
+#define NBD_FLAG_HAS_TRIM	(1 << 2)
 
 enum {
 	NBD_CMD_READ = 0,
 	NBD_CMD_WRITE = 1,
-	NBD_CMD_DISC = 2
+	NBD_CMD_DISC = 2,
+	NBD_CMD_TRIM = 3
 };
 
 #define nbd_cmd(req) ((req)->cmd[0])
-- 
1.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ