diff options
author | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2012-03-13 18:43:23 -0400 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2012-03-24 10:04:35 -0400 |
commit | 4dae76705fc8f9854bb732f9944e7ff9ba7a8e9f (patch) | |
tree | e08b16f2ade9d05ac84e7ed8a36a10269dda4569 /drivers/block | |
parent | bc67f63650fad6b3478d9ddfd5406d45a95987c9 (diff) |
xen/blkback: Squash the discard support for 'file' and 'phy' type.
The only reason for the distinction was for the special case of
'file' (which is assumed to be loopback device), was to reach inside
the loopback device, find the underlaying file, and call fallocate on it.
Fortunately "xen-blkback: convert hole punching to discard request on
loop devices" removes that use-case and we now based the discard
support based on blk_queue_discard(q) and extract all appropriate
parameters from the 'struct request_queue'.
CC: Li Dongyang <lidongyang@novell.com>
Acked-by: Jan Beulich <JBeulich@suse.com>
[v1: Dropping pointless initializer and keeping blank line]
[v2: Remove the kfree as it is not used anymore]
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'drivers/block')
-rw-r--r-- | drivers/block/xen-blkback/blkback.c | 19 | ||||
-rw-r--r-- | drivers/block/xen-blkback/common.h | 6 | ||||
-rw-r--r-- | drivers/block/xen-blkback/xenbus.c | 70 |
3 files changed, 34 insertions, 61 deletions
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index 70caa8969972..73f196ca713f 100644 --- a/drivers/block/xen-blkback/blkback.c +++ b/drivers/block/xen-blkback/blkback.c | |||
@@ -398,21 +398,18 @@ static int dispatch_discard_io(struct xen_blkif *blkif, | |||
398 | int err = 0; | 398 | int err = 0; |
399 | int status = BLKIF_RSP_OKAY; | 399 | int status = BLKIF_RSP_OKAY; |
400 | struct block_device *bdev = blkif->vbd.bdev; | 400 | struct block_device *bdev = blkif->vbd.bdev; |
401 | unsigned long secure; | ||
401 | 402 | ||
402 | blkif->st_ds_req++; | 403 | blkif->st_ds_req++; |
403 | 404 | ||
404 | xen_blkif_get(blkif); | 405 | xen_blkif_get(blkif); |
405 | if (blkif->blk_backend_type == BLKIF_BACKEND_PHY || | 406 | secure = (blkif->vbd.discard_secure && |
406 | blkif->blk_backend_type == BLKIF_BACKEND_FILE) { | 407 | (req->u.discard.flag & BLKIF_DISCARD_SECURE)) ? |
407 | unsigned long secure = (blkif->vbd.discard_secure && | 408 | BLKDEV_DISCARD_SECURE : 0; |
408 | (req->u.discard.flag & BLKIF_DISCARD_SECURE)) ? | 409 | |
409 | BLKDEV_DISCARD_SECURE : 0; | 410 | err = blkdev_issue_discard(bdev, req->u.discard.sector_number, |
410 | err = blkdev_issue_discard(bdev, | 411 | req->u.discard.nr_sectors, |
411 | req->u.discard.sector_number, | 412 | GFP_KERNEL, secure); |
412 | req->u.discard.nr_sectors, | ||
413 | GFP_KERNEL, secure); | ||
414 | } else | ||
415 | err = -EOPNOTSUPP; | ||
416 | 413 | ||
417 | if (err == -EOPNOTSUPP) { | 414 | if (err == -EOPNOTSUPP) { |
418 | pr_debug(DRV_PFX "discard op failed, not supported\n"); | 415 | pr_debug(DRV_PFX "discard op failed, not supported\n"); |
diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h index d0ee7edc9be8..773cf27dc23f 100644 --- a/drivers/block/xen-blkback/common.h +++ b/drivers/block/xen-blkback/common.h | |||
@@ -146,11 +146,6 @@ enum blkif_protocol { | |||
146 | BLKIF_PROTOCOL_X86_64 = 3, | 146 | BLKIF_PROTOCOL_X86_64 = 3, |
147 | }; | 147 | }; |
148 | 148 | ||
149 | enum blkif_backend_type { | ||
150 | BLKIF_BACKEND_PHY = 1, | ||
151 | BLKIF_BACKEND_FILE = 2, | ||
152 | }; | ||
153 | |||
154 | struct xen_vbd { | 149 | struct xen_vbd { |
155 | /* What the domain refers to this vbd as. */ | 150 | /* What the domain refers to this vbd as. */ |
156 | blkif_vdev_t handle; | 151 | blkif_vdev_t handle; |
@@ -177,7 +172,6 @@ struct xen_blkif { | |||
177 | unsigned int irq; | 172 | unsigned int irq; |
178 | /* Comms information. */ | 173 | /* Comms information. */ |
179 | enum blkif_protocol blk_protocol; | 174 | enum blkif_protocol blk_protocol; |
180 | enum blkif_backend_type blk_backend_type; | ||
181 | union blkif_back_rings blk_rings; | 175 | union blkif_back_rings blk_rings; |
182 | void *blk_ring; | 176 | void *blk_ring; |
183 | /* The VBD attached to this interface. */ | 177 | /* The VBD attached to this interface. */ |
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 24a2fb57e5d0..d417c13e027e 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c | |||
@@ -390,61 +390,43 @@ int xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be) | |||
390 | { | 390 | { |
391 | struct xenbus_device *dev = be->dev; | 391 | struct xenbus_device *dev = be->dev; |
392 | struct xen_blkif *blkif = be->blkif; | 392 | struct xen_blkif *blkif = be->blkif; |
393 | char *type; | ||
394 | int err; | 393 | int err; |
395 | int state = 0; | 394 | int state = 0; |
395 | struct block_device *bdev = be->blkif->vbd.bdev; | ||
396 | struct request_queue *q = bdev_get_queue(bdev); | ||
396 | 397 | ||
397 | type = xenbus_read(XBT_NIL, dev->nodename, "type", NULL); | 398 | if (blk_queue_discard(q)) { |
398 | if (!IS_ERR(type)) { | 399 | err = xenbus_printf(xbt, dev->nodename, |
399 | if (strncmp(type, "file", 4) == 0) { | 400 | "discard-granularity", "%u", |
400 | state = 1; | 401 | q->limits.discard_granularity); |
401 | blkif->blk_backend_type = BLKIF_BACKEND_FILE; | 402 | if (err) { |
403 | xenbus_dev_fatal(dev, err, | ||
404 | "writing discard-granularity"); | ||
405 | goto out; | ||
406 | } | ||
407 | err = xenbus_printf(xbt, dev->nodename, | ||
408 | "discard-alignment", "%u", | ||
409 | q->limits.discard_alignment); | ||
410 | if (err) { | ||
411 | xenbus_dev_fatal(dev, err, | ||
412 | "writing discard-alignment"); | ||
413 | goto out; | ||
402 | } | 414 | } |
403 | if (strncmp(type, "phy", 3) == 0) { | 415 | state = 1; |
404 | struct block_device *bdev = be->blkif->vbd.bdev; | 416 | /* Optional. */ |
405 | struct request_queue *q = bdev_get_queue(bdev); | 417 | err = xenbus_printf(xbt, dev->nodename, |
406 | if (blk_queue_discard(q)) { | 418 | "discard-secure", "%d", |
407 | err = xenbus_printf(xbt, dev->nodename, | 419 | blkif->vbd.discard_secure); |
408 | "discard-granularity", "%u", | 420 | if (err) { |
409 | q->limits.discard_granularity); | 421 | xenbus_dev_fatal(dev, err, |
410 | if (err) { | ||
411 | xenbus_dev_fatal(dev, err, | ||
412 | "writing discard-granularity"); | ||
413 | goto kfree; | ||
414 | } | ||
415 | err = xenbus_printf(xbt, dev->nodename, | ||
416 | "discard-alignment", "%u", | ||
417 | q->limits.discard_alignment); | ||
418 | if (err) { | ||
419 | xenbus_dev_fatal(dev, err, | ||
420 | "writing discard-alignment"); | ||
421 | goto kfree; | ||
422 | } | ||
423 | state = 1; | ||
424 | blkif->blk_backend_type = BLKIF_BACKEND_PHY; | ||
425 | } | ||
426 | /* Optional. */ | ||
427 | err = xenbus_printf(xbt, dev->nodename, | ||
428 | "discard-secure", "%d", | ||
429 | blkif->vbd.discard_secure); | ||
430 | if (err) { | ||
431 | xenbus_dev_fatal(dev, err, | ||
432 | "writting discard-secure"); | 422 | "writting discard-secure"); |
433 | goto kfree; | 423 | goto out; |
434 | } | ||
435 | } | 424 | } |
436 | } else { | ||
437 | err = PTR_ERR(type); | ||
438 | xenbus_dev_fatal(dev, err, "reading type"); | ||
439 | goto out; | ||
440 | } | 425 | } |
441 | |||
442 | err = xenbus_printf(xbt, dev->nodename, "feature-discard", | 426 | err = xenbus_printf(xbt, dev->nodename, "feature-discard", |
443 | "%d", state); | 427 | "%d", state); |
444 | if (err) | 428 | if (err) |
445 | xenbus_dev_fatal(dev, err, "writing feature-discard"); | 429 | xenbus_dev_fatal(dev, err, "writing feature-discard"); |
446 | kfree: | ||
447 | kfree(type); | ||
448 | out: | 430 | out: |
449 | return err; | 431 | return err; |
450 | } | 432 | } |