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>
This commit is contained in:
Konrad Rzeszutek Wilk 2012-03-13 18:43:23 -04:00
Родитель bc67f63650
Коммит 4dae76705f
3 изменённых файлов: 34 добавлений и 61 удалений

Просмотреть файл

@ -398,21 +398,18 @@ static int dispatch_discard_io(struct xen_blkif *blkif,
int err = 0; int err = 0;
int status = BLKIF_RSP_OKAY; int status = BLKIF_RSP_OKAY;
struct block_device *bdev = blkif->vbd.bdev; struct block_device *bdev = blkif->vbd.bdev;
unsigned long secure;
blkif->st_ds_req++; blkif->st_ds_req++;
xen_blkif_get(blkif); xen_blkif_get(blkif);
if (blkif->blk_backend_type == BLKIF_BACKEND_PHY || secure = (blkif->vbd.discard_secure &&
blkif->blk_backend_type == BLKIF_BACKEND_FILE) {
unsigned long secure = (blkif->vbd.discard_secure &&
(req->u.discard.flag & BLKIF_DISCARD_SECURE)) ? (req->u.discard.flag & BLKIF_DISCARD_SECURE)) ?
BLKDEV_DISCARD_SECURE : 0; BLKDEV_DISCARD_SECURE : 0;
err = blkdev_issue_discard(bdev,
req->u.discard.sector_number, err = blkdev_issue_discard(bdev, req->u.discard.sector_number,
req->u.discard.nr_sectors, req->u.discard.nr_sectors,
GFP_KERNEL, secure); GFP_KERNEL, secure);
} else
err = -EOPNOTSUPP;
if (err == -EOPNOTSUPP) { if (err == -EOPNOTSUPP) {
pr_debug(DRV_PFX "discard op failed, not supported\n"); pr_debug(DRV_PFX "discard op failed, not supported\n");

Просмотреть файл

@ -146,11 +146,6 @@ enum blkif_protocol {
BLKIF_PROTOCOL_X86_64 = 3, BLKIF_PROTOCOL_X86_64 = 3,
}; };
enum blkif_backend_type {
BLKIF_BACKEND_PHY = 1,
BLKIF_BACKEND_FILE = 2,
};
struct xen_vbd { struct xen_vbd {
/* What the domain refers to this vbd as. */ /* What the domain refers to this vbd as. */
blkif_vdev_t handle; blkif_vdev_t handle;
@ -177,7 +172,6 @@ struct xen_blkif {
unsigned int irq; unsigned int irq;
/* Comms information. */ /* Comms information. */
enum blkif_protocol blk_protocol; enum blkif_protocol blk_protocol;
enum blkif_backend_type blk_backend_type;
union blkif_back_rings blk_rings; union blkif_back_rings blk_rings;
void *blk_ring; void *blk_ring;
/* The VBD attached to this interface. */ /* The VBD attached to this interface. */

Просмотреть файл

@ -390,19 +390,11 @@ int xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be)
{ {
struct xenbus_device *dev = be->dev; struct xenbus_device *dev = be->dev;
struct xen_blkif *blkif = be->blkif; struct xen_blkif *blkif = be->blkif;
char *type;
int err; int err;
int state = 0; int state = 0;
type = xenbus_read(XBT_NIL, dev->nodename, "type", NULL);
if (!IS_ERR(type)) {
if (strncmp(type, "file", 4) == 0) {
state = 1;
blkif->blk_backend_type = BLKIF_BACKEND_FILE;
}
if (strncmp(type, "phy", 3) == 0) {
struct block_device *bdev = be->blkif->vbd.bdev; struct block_device *bdev = be->blkif->vbd.bdev;
struct request_queue *q = bdev_get_queue(bdev); struct request_queue *q = bdev_get_queue(bdev);
if (blk_queue_discard(q)) { if (blk_queue_discard(q)) {
err = xenbus_printf(xbt, dev->nodename, err = xenbus_printf(xbt, dev->nodename,
"discard-granularity", "%u", "discard-granularity", "%u",
@ -410,7 +402,7 @@ int xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be)
if (err) { if (err) {
xenbus_dev_fatal(dev, err, xenbus_dev_fatal(dev, err,
"writing discard-granularity"); "writing discard-granularity");
goto kfree; goto out;
} }
err = xenbus_printf(xbt, dev->nodename, err = xenbus_printf(xbt, dev->nodename,
"discard-alignment", "%u", "discard-alignment", "%u",
@ -418,11 +410,9 @@ int xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be)
if (err) { if (err) {
xenbus_dev_fatal(dev, err, xenbus_dev_fatal(dev, err,
"writing discard-alignment"); "writing discard-alignment");
goto kfree; goto out;
} }
state = 1; state = 1;
blkif->blk_backend_type = BLKIF_BACKEND_PHY;
}
/* Optional. */ /* Optional. */
err = xenbus_printf(xbt, dev->nodename, err = xenbus_printf(xbt, dev->nodename,
"discard-secure", "%d", "discard-secure", "%d",
@ -430,21 +420,13 @@ int xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be)
if (err) { if (err) {
xenbus_dev_fatal(dev, err, xenbus_dev_fatal(dev, err,
"writting discard-secure"); "writting discard-secure");
goto kfree;
}
}
} else {
err = PTR_ERR(type);
xenbus_dev_fatal(dev, err, "reading type");
goto out; goto out;
} }
}
err = xenbus_printf(xbt, dev->nodename, "feature-discard", err = xenbus_printf(xbt, dev->nodename, "feature-discard",
"%d", state); "%d", state);
if (err) if (err)
xenbus_dev_fatal(dev, err, "writing feature-discard"); xenbus_dev_fatal(dev, err, "writing feature-discard");
kfree:
kfree(type);
out: out:
return err; return err;
} }