nbd: handle discard requests
Add discard support to nbd. If the nbd-server supports discard, it will send NBD_FLAG_SEND_TRIM to the client. The client will then set the flag in the kernel via NBD_SET_FLAGS, which tells the kernel to enable discards for the device (QUEUE_FLAG_DISCARD). If discard support is enabled, then when the nbd client system receives a discard request, this will be passed along to the nbd-server. When the discard request is received by the nbd-server, it will perform: fallocate(.. FALLOC_FL_PUNCH_HOLE ..) To punch a hole in the backend storage, which is no longer needed. Signed-off-by: Paul Clements <paul.clements@steeleye.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
2f01250888
commit
a336d29870
@@ -32,12 +32,16 @@
|
||||
enum {
|
||||
NBD_CMD_READ = 0,
|
||||
NBD_CMD_WRITE = 1,
|
||||
NBD_CMD_DISC = 2
|
||||
NBD_CMD_DISC = 2,
|
||||
/* there is a gap here to match userspace */
|
||||
NBD_CMD_TRIM = 4
|
||||
};
|
||||
|
||||
/* values for flags field */
|
||||
#define NBD_FLAG_HAS_FLAGS (1 << 0) /* nbd-server supports flags */
|
||||
#define NBD_FLAG_READ_ONLY (1 << 1) /* device is read-only */
|
||||
/* there is a gap here to match userspace */
|
||||
#define NBD_FLAG_SEND_TRIM (1 << 5) /* send trim/discard */
|
||||
|
||||
#define nbd_cmd(req) ((req)->cmd[0])
|
||||
|
||||
|
Reference in New Issue
Block a user