Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 330177
b: refs/heads/master
c: a336d29
h: refs/heads/master
i:
  330175: 85c4e9e
v: v3
  • Loading branch information
Paul Clements authored and Linus Torvalds committed Oct 5, 2012
1 parent 8e6ca29 commit eed898b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2f012508880f8037590372c24ca6e8b6af8fffb6
refs/heads/master: a336d29870f8a1f8e5f10d9f1aa95531c4edeabe
15 changes: 14 additions & 1 deletion trunk/drivers/block/nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -469,7 +470,11 @@ static void nbd_handle_req(struct nbd_device *nbd, struct request *req)

nbd_cmd(req) = NBD_CMD_READ;
if (rq_data_dir(req) == WRITE) {
nbd_cmd(req) = NBD_CMD_WRITE;
if ((req->cmd_flags & REQ_DISCARD)) {
WARN_ON(!(nbd->flags & NBD_FLAG_SEND_TRIM));
nbd_cmd(req) = NBD_CMD_TRIM;
} else
nbd_cmd(req) = NBD_CMD_WRITE;
if (nbd->flags & NBD_FLAG_READ_ONLY) {
dev_err(disk_to_dev(nbd->disk),
"Write on read-only\n");
Expand Down Expand Up @@ -676,6 +681,10 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,

mutex_unlock(&nbd->tx_lock);

if (nbd->flags & NBD_FLAG_SEND_TRIM)
queue_flag_set_unlocked(QUEUE_FLAG_DISCARD,
nbd->disk->queue);

thread = kthread_create(nbd_thread, nbd, nbd->disk->disk_name);
if (IS_ERR(thread)) {
mutex_lock(&nbd->tx_lock);
Expand All @@ -693,6 +702,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
nbd->file = NULL;
nbd_clear_que(nbd);
dev_warn(disk_to_dev(nbd->disk), "queue cleared\n");
queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, nbd->disk->queue);
if (file)
fput(file);
nbd->bytesize = 0;
Expand Down Expand Up @@ -811,6 +821,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")) {
Expand Down
6 changes: 5 additions & 1 deletion trunk/include/linux/nbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down

0 comments on commit eed898b

Please sign in to comment.