Commit f748040b authored by Jens Axboe's avatar Jens Axboe

Merge branch 'stable/for-jens-3.3' of...

Merge branch 'stable/for-jens-3.3' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen into for-3.3/drivers
parents fd638368 f094148a
...@@ -39,9 +39,6 @@ ...@@ -39,9 +39,6 @@
#include <linux/list.h> #include <linux/list.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/freezer.h> #include <linux/freezer.h>
#include <linux/loop.h>
#include <linux/falloc.h>
#include <linux/fs.h>
#include <xen/events.h> #include <xen/events.h>
#include <xen/page.h> #include <xen/page.h>
...@@ -362,7 +359,7 @@ static int xen_blkbk_map(struct blkif_request *req, ...@@ -362,7 +359,7 @@ static int xen_blkbk_map(struct blkif_request *req,
{ {
struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST]; struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST];
int i; int i;
int nseg = req->nr_segments; int nseg = req->u.rw.nr_segments;
int ret = 0; int ret = 0;
/* /*
...@@ -416,30 +413,25 @@ static int xen_blkbk_map(struct blkif_request *req, ...@@ -416,30 +413,25 @@ static int xen_blkbk_map(struct blkif_request *req,
return ret; return ret;
} }
static void xen_blk_discard(struct xen_blkif *blkif, struct blkif_request *req) static int dispatch_discard_io(struct xen_blkif *blkif,
struct blkif_request *req)
{ {
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;
if (blkif->blk_backend_type == BLKIF_BACKEND_PHY) blkif->st_ds_req++;
/* just forward the discard request */
xen_blkif_get(blkif);
if (blkif->blk_backend_type == BLKIF_BACKEND_PHY ||
blkif->blk_backend_type == BLKIF_BACKEND_FILE) {
unsigned long secure = (blkif->vbd.discard_secure &&
(req->u.discard.flag & BLKIF_DISCARD_SECURE)) ?
BLKDEV_DISCARD_SECURE : 0;
err = blkdev_issue_discard(bdev, err = blkdev_issue_discard(bdev,
req->u.discard.sector_number, req->u.discard.sector_number,
req->u.discard.nr_sectors, req->u.discard.nr_sectors,
GFP_KERNEL, 0); GFP_KERNEL, secure);
else if (blkif->blk_backend_type == BLKIF_BACKEND_FILE) {
/* punch a hole in the backing file */
struct loop_device *lo = bdev->bd_disk->private_data;
struct file *file = lo->lo_backing_file;
if (file->f_op->fallocate)
err = file->f_op->fallocate(file,
FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
req->u.discard.sector_number << 9,
req->u.discard.nr_sectors << 9);
else
err = -EOPNOTSUPP;
} else } else
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
...@@ -449,7 +441,9 @@ static void xen_blk_discard(struct xen_blkif *blkif, struct blkif_request *req) ...@@ -449,7 +441,9 @@ static void xen_blk_discard(struct xen_blkif *blkif, struct blkif_request *req)
} else if (err) } else if (err)
status = BLKIF_RSP_ERROR; status = BLKIF_RSP_ERROR;
make_response(blkif, req->id, req->operation, status); make_response(blkif, req->u.discard.id, req->operation, status);
xen_blkif_put(blkif);
return err;
} }
static void xen_blk_drain_io(struct xen_blkif *blkif) static void xen_blk_drain_io(struct xen_blkif *blkif)
...@@ -573,8 +567,11 @@ __do_block_io_op(struct xen_blkif *blkif) ...@@ -573,8 +567,11 @@ __do_block_io_op(struct xen_blkif *blkif)
/* Apply all sanity checks to /private copy/ of request. */ /* Apply all sanity checks to /private copy/ of request. */
barrier(); barrier();
if (unlikely(req.operation == BLKIF_OP_DISCARD)) {
if (dispatch_rw_block_io(blkif, &req, pending_req)) free_req(pending_req);
if (dispatch_discard_io(blkif, &req))
break;
} else if (dispatch_rw_block_io(blkif, &req, pending_req))
break; break;
/* Yield point for this unbounded loop. */ /* Yield point for this unbounded loop. */
...@@ -633,10 +630,6 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, ...@@ -633,10 +630,6 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
blkif->st_f_req++; blkif->st_f_req++;
operation = WRITE_FLUSH; operation = WRITE_FLUSH;
break; break;
case BLKIF_OP_DISCARD:
blkif->st_ds_req++;
operation = REQ_DISCARD;
break;
default: default:
operation = 0; /* make gcc happy */ operation = 0; /* make gcc happy */
goto fail_response; goto fail_response;
...@@ -644,9 +637,9 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, ...@@ -644,9 +637,9 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
} }
/* Check that the number of segments is sane. */ /* Check that the number of segments is sane. */
nseg = req->nr_segments; nseg = req->u.rw.nr_segments;
if (unlikely(nseg == 0 && operation != WRITE_FLUSH &&
operation != REQ_DISCARD) || if (unlikely(nseg == 0 && operation != WRITE_FLUSH) ||
unlikely(nseg > BLKIF_MAX_SEGMENTS_PER_REQUEST)) { unlikely(nseg > BLKIF_MAX_SEGMENTS_PER_REQUEST)) {
pr_debug(DRV_PFX "Bad number of segments in request (%d)\n", pr_debug(DRV_PFX "Bad number of segments in request (%d)\n",
nseg); nseg);
...@@ -654,12 +647,12 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, ...@@ -654,12 +647,12 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
goto fail_response; goto fail_response;
} }
preq.dev = req->handle; preq.dev = req->u.rw.handle;
preq.sector_number = req->u.rw.sector_number; preq.sector_number = req->u.rw.sector_number;
preq.nr_sects = 0; preq.nr_sects = 0;
pending_req->blkif = blkif; pending_req->blkif = blkif;
pending_req->id = req->id; pending_req->id = req->u.rw.id;
pending_req->operation = req->operation; pending_req->operation = req->operation;
pending_req->status = BLKIF_RSP_OKAY; pending_req->status = BLKIF_RSP_OKAY;
pending_req->nr_pages = nseg; pending_req->nr_pages = nseg;
...@@ -707,7 +700,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, ...@@ -707,7 +700,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
* the hypercall to unmap the grants - that is all done in * the hypercall to unmap the grants - that is all done in
* xen_blkbk_unmap. * xen_blkbk_unmap.
*/ */
if (operation != REQ_DISCARD && xen_blkbk_map(req, pending_req, seg)) if (xen_blkbk_map(req, pending_req, seg))
goto fail_flush; goto fail_flush;
/* /*
...@@ -739,23 +732,16 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, ...@@ -739,23 +732,16 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
/* This will be hit if the operation was a flush or discard. */ /* This will be hit if the operation was a flush or discard. */
if (!bio) { if (!bio) {
BUG_ON(operation != WRITE_FLUSH && operation != REQ_DISCARD); BUG_ON(operation != WRITE_FLUSH);
if (operation == WRITE_FLUSH) { bio = bio_alloc(GFP_KERNEL, 0);
bio = bio_alloc(GFP_KERNEL, 0); if (unlikely(bio == NULL))
if (unlikely(bio == NULL)) goto fail_put_bio;
goto fail_put_bio;
biolist[nbio++] = bio; biolist[nbio++] = bio;
bio->bi_bdev = preq.bdev; bio->bi_bdev = preq.bdev;
bio->bi_private = pending_req; bio->bi_private = pending_req;
bio->bi_end_io = end_block_io_op; bio->bi_end_io = end_block_io_op;
} else if (operation == REQ_DISCARD) {
xen_blk_discard(blkif, req);
xen_blkif_put(blkif);
free_req(pending_req);
return 0;
}
} }
/* /*
...@@ -784,7 +770,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, ...@@ -784,7 +770,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
xen_blkbk_unmap(pending_req); xen_blkbk_unmap(pending_req);
fail_response: fail_response:
/* Haven't submitted any bio's yet. */ /* Haven't submitted any bio's yet. */
make_response(blkif, req->id, req->operation, BLKIF_RSP_ERROR); make_response(blkif, req->u.rw.id, req->operation, BLKIF_RSP_ERROR);
free_req(pending_req); free_req(pending_req);
msleep(1); /* back off a bit */ msleep(1); /* back off a bit */
return -EIO; return -EIO;
......
...@@ -60,58 +60,66 @@ struct blkif_common_response { ...@@ -60,58 +60,66 @@ struct blkif_common_response {
char dummy; char dummy;
}; };
/* i386 protocol version */
#pragma pack(push, 4)
struct blkif_x86_32_request_rw { struct blkif_x86_32_request_rw {
uint8_t nr_segments; /* number of segments */
blkif_vdev_t handle; /* only for read/write requests */
uint64_t id; /* private guest value, echoed in resp */
blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
}; } __attribute__((__packed__));
struct blkif_x86_32_request_discard { struct blkif_x86_32_request_discard {
uint8_t flag; /* BLKIF_DISCARD_SECURE or zero */
blkif_vdev_t _pad1; /* was "handle" for read/write requests */
uint64_t id; /* private guest value, echoed in resp */
blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
uint64_t nr_sectors; uint64_t nr_sectors;
}; } __attribute__((__packed__));
struct blkif_x86_32_request { struct blkif_x86_32_request {
uint8_t operation; /* BLKIF_OP_??? */ uint8_t operation; /* BLKIF_OP_??? */
uint8_t nr_segments; /* number of segments */
blkif_vdev_t handle; /* only for read/write requests */
uint64_t id; /* private guest value, echoed in resp */
union { union {
struct blkif_x86_32_request_rw rw; struct blkif_x86_32_request_rw rw;
struct blkif_x86_32_request_discard discard; struct blkif_x86_32_request_discard discard;
} u; } u;
}; } __attribute__((__packed__));
/* i386 protocol version */
#pragma pack(push, 4)
struct blkif_x86_32_response { struct blkif_x86_32_response {
uint64_t id; /* copied from request */ uint64_t id; /* copied from request */
uint8_t operation; /* copied from request */ uint8_t operation; /* copied from request */
int16_t status; /* BLKIF_RSP_??? */ int16_t status; /* BLKIF_RSP_??? */
}; };
#pragma pack(pop) #pragma pack(pop)
/* x86_64 protocol version */ /* x86_64 protocol version */
struct blkif_x86_64_request_rw { struct blkif_x86_64_request_rw {
uint8_t nr_segments; /* number of segments */
blkif_vdev_t handle; /* only for read/write requests */
uint32_t _pad1; /* offsetof(blkif_reqest..,u.rw.id)==8 */
uint64_t id;
blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
}; } __attribute__((__packed__));
struct blkif_x86_64_request_discard { struct blkif_x86_64_request_discard {
uint8_t flag; /* BLKIF_DISCARD_SECURE or zero */
blkif_vdev_t _pad1; /* was "handle" for read/write requests */
uint32_t _pad2; /* offsetof(blkif_..,u.discard.id)==8 */
uint64_t id;
blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
uint64_t nr_sectors; uint64_t nr_sectors;
}; } __attribute__((__packed__));
struct blkif_x86_64_request { struct blkif_x86_64_request {
uint8_t operation; /* BLKIF_OP_??? */ uint8_t operation; /* BLKIF_OP_??? */
uint8_t nr_segments; /* number of segments */
blkif_vdev_t handle; /* only for read/write requests */
uint64_t __attribute__((__aligned__(8))) id;
union { union {
struct blkif_x86_64_request_rw rw; struct blkif_x86_64_request_rw rw;
struct blkif_x86_64_request_discard discard; struct blkif_x86_64_request_discard discard;
} u; } u;
}; } __attribute__((__packed__));
struct blkif_x86_64_response { struct blkif_x86_64_response {
uint64_t __attribute__((__aligned__(8))) id; uint64_t __attribute__((__aligned__(8))) id;
uint8_t operation; /* copied from request */ uint8_t operation; /* copied from request */
...@@ -156,6 +164,7 @@ struct xen_vbd { ...@@ -156,6 +164,7 @@ struct xen_vbd {
/* Cached size parameter. */ /* Cached size parameter. */
sector_t size; sector_t size;
bool flush_support; bool flush_support;
bool discard_secure;
}; };
struct backend_info; struct backend_info;
...@@ -237,22 +246,23 @@ static inline void blkif_get_x86_32_req(struct blkif_request *dst, ...@@ -237,22 +246,23 @@ static inline void blkif_get_x86_32_req(struct blkif_request *dst,
{ {
int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST; int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST;
dst->operation = src->operation; dst->operation = src->operation;
dst->nr_segments = src->nr_segments;
dst->handle = src->handle;
dst->id = src->id;
switch (src->operation) { switch (src->operation) {
case BLKIF_OP_READ: case BLKIF_OP_READ:
case BLKIF_OP_WRITE: case BLKIF_OP_WRITE:
case BLKIF_OP_WRITE_BARRIER: case BLKIF_OP_WRITE_BARRIER:
case BLKIF_OP_FLUSH_DISKCACHE: case BLKIF_OP_FLUSH_DISKCACHE:
dst->u.rw.nr_segments = src->u.rw.nr_segments;
dst->u.rw.handle = src->u.rw.handle;
dst->u.rw.id = src->u.rw.id;
dst->u.rw.sector_number = src->u.rw.sector_number; dst->u.rw.sector_number = src->u.rw.sector_number;
barrier(); barrier();
if (n > dst->nr_segments) if (n > dst->u.rw.nr_segments)
n = dst->nr_segments; n = dst->u.rw.nr_segments;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
dst->u.rw.seg[i] = src->u.rw.seg[i]; dst->u.rw.seg[i] = src->u.rw.seg[i];
break; break;
case BLKIF_OP_DISCARD: case BLKIF_OP_DISCARD:
dst->u.discard.flag = src->u.discard.flag;
dst->u.discard.sector_number = src->u.discard.sector_number; dst->u.discard.sector_number = src->u.discard.sector_number;
dst->u.discard.nr_sectors = src->u.discard.nr_sectors; dst->u.discard.nr_sectors = src->u.discard.nr_sectors;
break; break;
...@@ -266,22 +276,23 @@ static inline void blkif_get_x86_64_req(struct blkif_request *dst, ...@@ -266,22 +276,23 @@ static inline void blkif_get_x86_64_req(struct blkif_request *dst,
{ {
int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST; int i, n = BLKIF_MAX_SEGMENTS_PER_REQUEST;
dst->operation = src->operation; dst->operation = src->operation;
dst->nr_segments = src->nr_segments;
dst->handle = src->handle;
dst->id = src->id;
switch (src->operation) { switch (src->operation) {
case BLKIF_OP_READ: case BLKIF_OP_READ:
case BLKIF_OP_WRITE: case BLKIF_OP_WRITE:
case BLKIF_OP_WRITE_BARRIER: case BLKIF_OP_WRITE_BARRIER:
case BLKIF_OP_FLUSH_DISKCACHE: case BLKIF_OP_FLUSH_DISKCACHE:
dst->u.rw.nr_segments = src->u.rw.nr_segments;
dst->u.rw.handle = src->u.rw.handle;
dst->u.rw.id = src->u.rw.id;
dst->u.rw.sector_number = src->u.rw.sector_number; dst->u.rw.sector_number = src->u.rw.sector_number;
barrier(); barrier();
if (n > dst->nr_segments) if (n > dst->u.rw.nr_segments)
n = dst->nr_segments; n = dst->u.rw.nr_segments;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
dst->u.rw.seg[i] = src->u.rw.seg[i]; dst->u.rw.seg[i] = src->u.rw.seg[i];
break; break;
case BLKIF_OP_DISCARD: case BLKIF_OP_DISCARD:
dst->u.discard.flag = src->u.discard.flag;
dst->u.discard.sector_number = src->u.discard.sector_number; dst->u.discard.sector_number = src->u.discard.sector_number;
dst->u.discard.nr_sectors = src->u.discard.nr_sectors; dst->u.discard.nr_sectors = src->u.discard.nr_sectors;
break; break;
......
...@@ -338,6 +338,9 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, ...@@ -338,6 +338,9 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
if (q && q->flush_flags) if (q && q->flush_flags)
vbd->flush_support = true; vbd->flush_support = true;
if (q && blk_queue_secdiscard(q))
vbd->discard_secure = true;
DPRINTK("Successful creation of handle=%04x (dom=%u)\n", DPRINTK("Successful creation of handle=%04x (dom=%u)\n",
handle, blkif->domid); handle, blkif->domid);
return 0; return 0;
...@@ -420,6 +423,15 @@ int xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be) ...@@ -420,6 +423,15 @@ int xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be)
state = 1; state = 1;
blkif->blk_backend_type = BLKIF_BACKEND_PHY; blkif->blk_backend_type = BLKIF_BACKEND_PHY;
} }
/* Optional. */
err = xenbus_printf(xbt, dev->nodename,
"discard-secure", "%d",
blkif->vbd.discard_secure);
if (err) {
xenbus_dev_fatal(dev, err,
"writting discard-secure");
goto kfree;
}
} }
} else { } else {
err = PTR_ERR(type); err = PTR_ERR(type);
......
...@@ -98,7 +98,8 @@ struct blkfront_info ...@@ -98,7 +98,8 @@ struct blkfront_info
unsigned long shadow_free; unsigned long shadow_free;
unsigned int feature_flush; unsigned int feature_flush;
unsigned int flush_op; unsigned int flush_op;
unsigned int feature_discard; unsigned int feature_discard:1;
unsigned int feature_secdiscard:1;
unsigned int discard_granularity; unsigned int discard_granularity;
unsigned int discard_alignment; unsigned int discard_alignment;
int is_ready; int is_ready;
...@@ -135,15 +136,15 @@ static int get_id_from_freelist(struct blkfront_info *info) ...@@ -135,15 +136,15 @@ static int get_id_from_freelist(struct blkfront_info *info)
{ {
unsigned long free = info->shadow_free; unsigned long free = info->shadow_free;
BUG_ON(free >= BLK_RING_SIZE); BUG_ON(free >= BLK_RING_SIZE);
info->shadow_free = info->shadow[free].req.id; info->shadow_free = info->shadow[free].req.u.rw.id;
info->shadow[free].req.id = 0x0fffffee; /* debug */ info->shadow[free].req.u.rw.id = 0x0fffffee; /* debug */
return free; return free;
} }
static void add_id_to_freelist(struct blkfront_info *info, static void add_id_to_freelist(struct blkfront_info *info,
unsigned long id) unsigned long id)
{ {
info->shadow[id].req.id = info->shadow_free; info->shadow[id].req.u.rw.id = info->shadow_free;
info->shadow[id].request = NULL; info->shadow[id].request = NULL;
info->shadow_free = id; info->shadow_free = id;
} }
...@@ -156,7 +157,7 @@ static int xlbd_reserve_minors(unsigned int minor, unsigned int nr) ...@@ -156,7 +157,7 @@ static int xlbd_reserve_minors(unsigned int minor, unsigned int nr)
if (end > nr_minors) { if (end > nr_minors) {
unsigned long *bitmap, *old; unsigned long *bitmap, *old;
bitmap = kzalloc(BITS_TO_LONGS(end) * sizeof(*bitmap), bitmap = kcalloc(BITS_TO_LONGS(end), sizeof(*bitmap),
GFP_KERNEL); GFP_KERNEL);
if (bitmap == NULL) if (bitmap == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -287,9 +288,9 @@ static int blkif_queue_request(struct request *req) ...@@ -287,9 +288,9 @@ static int blkif_queue_request(struct request *req)
id = get_id_from_freelist(info); id = get_id_from_freelist(info);
info->shadow[id].request = req; info->shadow[id].request = req;
ring_req->id = id; ring_req->u.rw.id = id;
ring_req->u.rw.sector_number = (blkif_sector_t)blk_rq_pos(req); ring_req->u.rw.sector_number = (blkif_sector_t)blk_rq_pos(req);
ring_req->handle = info->handle; ring_req->u.rw.handle = info->handle;
ring_req->operation = rq_data_dir(req) ? ring_req->operation = rq_data_dir(req) ?
BLKIF_OP_WRITE : BLKIF_OP_READ; BLKIF_OP_WRITE : BLKIF_OP_READ;
...@@ -305,16 +306,21 @@ static int blkif_queue_request(struct request *req) ...@@ -305,16 +306,21 @@ static int blkif_queue_request(struct request *req)
ring_req->operation = info->flush_op; ring_req->operation = info->flush_op;
} }
if (unlikely(req->cmd_flags & REQ_DISCARD)) { if (unlikely(req->cmd_flags & (REQ_DISCARD | REQ_SECURE))) {
/* id, sector_number and handle are set above. */ /* id, sector_number and handle are set above. */
ring_req->operation = BLKIF_OP_DISCARD; ring_req->operation = BLKIF_OP_DISCARD;
ring_req->nr_segments = 0;
ring_req->u.discard.nr_sectors = blk_rq_sectors(req); ring_req->u.discard.nr_sectors = blk_rq_sectors(req);
if ((req->cmd_flags & REQ_SECURE) && info->feature_secdiscard)
ring_req->u.discard.flag = BLKIF_DISCARD_SECURE;
else
ring_req->u.discard.flag = 0;
} else { } else {
ring_req->nr_segments = blk_rq_map_sg(req->q, req, info->sg); ring_req->u.rw.nr_segments = blk_rq_map_sg(req->q, req,
BUG_ON(ring_req->nr_segments > BLKIF_MAX_SEGMENTS_PER_REQUEST); info->sg);
BUG_ON(ring_req->u.rw.nr_segments >
BLKIF_MAX_SEGMENTS_PER_REQUEST);
for_each_sg(info->sg, sg, ring_req->nr_segments, i) { for_each_sg(info->sg, sg, ring_req->u.rw.nr_segments, i) {
buffer_mfn = pfn_to_mfn(page_to_pfn(sg_page(sg))); buffer_mfn = pfn_to_mfn(page_to_pfn(sg_page(sg)));
fsect = sg->offset >> 9; fsect = sg->offset >> 9;
lsect = fsect + (sg->length >> 9) - 1; lsect = fsect + (sg->length >> 9) - 1;
...@@ -424,6 +430,8 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size) ...@@ -424,6 +430,8 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
blk_queue_max_discard_sectors(rq, get_capacity(gd)); blk_queue_max_discard_sectors(rq, get_capacity(gd));
rq->limits.discard_granularity = info->discard_granularity; rq->limits.discard_granularity = info->discard_granularity;
rq->limits.discard_alignment = info->discard_alignment; rq->limits.discard_alignment = info->discard_alignment;
if (info->feature_secdiscard)
queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD, rq);
} }
/* Hard sector size and max sectors impersonate the equiv. hardware. */ /* Hard sector size and max sectors impersonate the equiv. hardware. */
...@@ -705,7 +713,9 @@ static void blkif_free(struct blkfront_info *info, int suspend) ...@@ -705,7 +713,9 @@ static void blkif_free(struct blkfront_info *info, int suspend)
static void blkif_completion(struct blk_shadow *s) static void blkif_completion(struct blk_shadow *s)
{ {
int i; int i;
for (i = 0; i < s->req.nr_segments; i++) /* Do not let BLKIF_OP_DISCARD as nr_segment is in the same place
* flag. */
for (i = 0; i < s->req.u.rw.nr_segments; i++)
gnttab_end_foreign_access(s->req.u.rw.seg[i].gref, 0, 0UL); gnttab_end_foreign_access(s->req.u.rw.seg[i].gref, 0, 0UL);
} }
...@@ -736,7 +746,8 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) ...@@ -736,7 +746,8 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
id = bret->id; id = bret->id;
req = info->shadow[id].request; req = info->shadow[id].request;
blkif_completion(&info->shadow[id]); if (bret->operation != BLKIF_OP_DISCARD)
blkif_completion(&info->shadow[id]);
add_id_to_freelist(info, id); add_id_to_freelist(info, id);
...@@ -749,7 +760,9 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) ...@@ -749,7 +760,9 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
info->gd->disk_name); info->gd->disk_name);
error = -EOPNOTSUPP; error = -EOPNOTSUPP;
info->feature_discard = 0; info->feature_discard = 0;
info->feature_secdiscard = 0;
queue_flag_clear(QUEUE_FLAG_DISCARD, rq); queue_flag_clear(QUEUE_FLAG_DISCARD, rq);
queue_flag_clear(QUEUE_FLAG_SECDISCARD, rq);
} }
__blk_end_request_all(req, error); __blk_end_request_all(req, error);
break; break;
...@@ -763,7 +776,7 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) ...@@ -763,7 +776,7 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
error = -EOPNOTSUPP; error = -EOPNOTSUPP;
} }
if (unlikely(bret->status == BLKIF_RSP_ERROR && if (unlikely(bret->status == BLKIF_RSP_ERROR &&
info->shadow[id].req.nr_segments == 0)) { info->shadow[id].req.u.rw.nr_segments == 0)) {
printk(KERN_WARNING "blkfront: %s: empty write %s op failed\n", printk(KERN_WARNING "blkfront: %s: empty write %s op failed\n",
info->flush_op == BLKIF_OP_WRITE_BARRIER ? info->flush_op == BLKIF_OP_WRITE_BARRIER ?
"barrier" : "flush disk cache", "barrier" : "flush disk cache",
...@@ -984,8 +997,8 @@ static int blkfront_probe(struct xenbus_device *dev, ...@@ -984,8 +997,8 @@ static int blkfront_probe(struct xenbus_device *dev,
INIT_WORK(&info->work, blkif_restart_queue); INIT_WORK(&info->work, blkif_restart_queue);
for (i = 0; i < BLK_RING_SIZE; i++) for (i = 0; i < BLK_RING_SIZE; i++)
info->shadow[i].req.id = i+1; info->shadow[i].req.u.rw.id = i+1;
info->shadow[BLK_RING_SIZE-1].req.id = 0x0fffffff; info->shadow[BLK_RING_SIZE-1].req.u.rw.id = 0x0fffffff;
/* Front end dir is a number, which is used as the id. */ /* Front end dir is a number, which is used as the id. */
info->handle = simple_strtoul(strrchr(dev->nodename, '/')+1, NULL, 0); info->handle = simple_strtoul(strrchr(dev->nodename, '/')+1, NULL, 0);
...@@ -1019,9 +1032,9 @@ static int blkif_recover(struct blkfront_info *info) ...@@ -1019,9 +1032,9 @@ static int blkif_recover(struct blkfront_info *info)
/* Stage 2: Set up free list. */ /* Stage 2: Set up free list. */
memset(&info->shadow, 0, sizeof(info->shadow)); memset(&info->shadow, 0, sizeof(info->shadow));
for (i = 0; i < BLK_RING_SIZE; i++) for (i = 0; i < BLK_RING_SIZE; i++)
info->shadow[i].req.id = i+1; info->shadow[i].req.u.rw.id = i+1;
info->shadow_free = info->ring.req_prod_pvt; info->shadow_free = info->ring.req_prod_pvt;
info->shadow[BLK_RING_SIZE-1].req.id = 0x0fffffff; info->shadow[BLK_RING_SIZE-1].req.u.rw.id = 0x0fffffff;
/* Stage 3: Find pending requests and requeue them. */ /* Stage 3: Find pending requests and requeue them. */
for (i = 0; i < BLK_RING_SIZE; i++) { for (i = 0; i < BLK_RING_SIZE; i++) {
...@@ -1034,17 +1047,19 @@ static int blkif_recover(struct blkfront_info *info) ...@@ -1034,17 +1047,19 @@ static int blkif_recover(struct blkfront_info *info)
*req = copy[i].req; *req = copy[i].req;
/* We get a new request id, and must reset the shadow state. */ /* We get a new request id, and must reset the shadow state. */
req->id = get_id_from_freelist(info); req->u.rw.id = get_id_from_freelist(info);
memcpy(&info->shadow[req->id], &copy[i], sizeof(copy[i])); memcpy(&info->shadow[req->u.rw.id], &copy[i], sizeof(copy[i]));
if (req->operation != BLKIF_OP_DISCARD) {
/* Rewrite any grant references invalidated by susp/resume. */ /* Rewrite any grant references invalidated by susp/resume. */
for (j = 0; j < req->nr_segments; j++) for (j = 0; j < req->u.rw.nr_segments; j++)
gnttab_grant_foreign_access_ref( gnttab_grant_foreign_access_ref(
req->u.rw.seg[j].gref, req->u.rw.seg[j].gref,
info->xbdev->otherend_id, info->xbdev->otherend_id,
pfn_to_mfn(info->shadow[req->id].frame[j]), pfn_to_mfn(info->shadow[req->u.rw.id].frame[j]),
rq_data_dir(info->shadow[req->id].request)); rq_data_dir(info->shadow[req->u.rw.id].request));
info->shadow[req->id].req = *req; }
info->shadow[req->u.rw.id].req = *req;
info->ring.req_prod_pvt++; info->ring.req_prod_pvt++;
} }
...@@ -1135,11 +1150,13 @@ static void blkfront_setup_discard(struct blkfront_info *info) ...@@ -1135,11 +1150,13 @@ static void blkfront_setup_discard(struct blkfront_info *info)
char *type; char *type;
unsigned int discard_granularity; unsigned int discard_granularity;
unsigned int discard_alignment; unsigned int discard_alignment;
unsigned int discard_secure;
type = xenbus_read(XBT_NIL, info->xbdev->otherend, "type", NULL); type = xenbus_read(XBT_NIL, info->xbdev->otherend, "type", NULL);
if (IS_ERR(type)) if (IS_ERR(type))
return; return;
info->feature_secdiscard = 0;
if (strncmp(type, "phy", 3) == 0) { if (strncmp(type, "phy", 3) == 0) {
err = xenbus_gather(XBT_NIL, info->xbdev->otherend, err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
"discard-granularity", "%u", &discard_granularity, "discard-granularity", "%u", &discard_granularity,
...@@ -1150,6 +1167,12 @@ static void blkfront_setup_discard(struct blkfront_info *info) ...@@ -1150,6 +1167,12 @@ static void blkfront_setup_discard(struct blkfront_info *info)
info->discard_granularity = discard_granularity; info->discard_granularity = discard_granularity;
info->discard_alignment = discard_alignment; info->discard_alignment = discard_alignment;
} }
err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
"discard-secure", "%d", &discard_secure,
NULL);
if (!err)
info->feature_secdiscard = discard_secure;
} else if (strncmp(type, "file", 4) == 0) } else if (strncmp(type, "file", 4) == 0)
info->feature_discard = 1; info->feature_discard = 1;
......
...@@ -84,6 +84,21 @@ typedef uint64_t blkif_sector_t; ...@@ -84,6 +84,21 @@ typedef uint64_t blkif_sector_t;
* e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc * e07154r6-Data_Set_Management_Proposal_for_ATA-ACS2.doc
* http://www.seagate.com/staticfiles/support/disc/manuals/ * http://www.seagate.com/staticfiles/support/disc/manuals/
* Interface%20manuals/100293068c.pdf * Interface%20manuals/100293068c.pdf
* The backend can optionally provide three extra XenBus attributes to
* further optimize the discard functionality:
* 'discard-aligment' - Devices that support discard functionality may
* internally allocate space in units that are bigger than the exported
* logical block size. The discard-alignment parameter indicates how many bytes
* the beginning of the partition is offset from the internal allocation unit's
* natural alignment.
* 'discard-granularity' - Devices that support discard functionality may
* internally allocate space using units that are bigger than the logical block
* size. The discard-granularity parameter indicates the size of the internal
* allocation unit in bytes if reported by the device. Otherwise the
* discard-granularity will be set to match the device's physical block size.
* 'discard-secure' - All copies of the discarded sectors (potentially created
* by garbage collection) must also be erased. To use this feature, the flag
* BLKIF_DISCARD_SECURE must be set in the blkif_request_trim.
*/ */
#define BLKIF_OP_DISCARD 5 #define BLKIF_OP_DISCARD 5
...@@ -95,6 +110,12 @@ typedef uint64_t blkif_sector_t; ...@@ -95,6 +110,12 @@ typedef uint64_t blkif_sector_t;
#define BLKIF_MAX_SEGMENTS_PER_REQUEST 11 #define BLKIF_MAX_SEGMENTS_PER_REQUEST 11
struct blkif_request_rw { struct blkif_request_rw {
uint8_t nr_segments; /* number of segments */
blkif_vdev_t handle; /* only for read/write requests */
#ifdef CONFIG_X86_64
uint32_t _pad1; /* offsetof(blkif_request,u.rw.id) == 8 */
#endif
uint64_t id; /* private guest value, echoed in resp */
blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
struct blkif_request_segment { struct blkif_request_segment {
grant_ref_t gref; /* reference to I/O buffer frame */ grant_ref_t gref; /* reference to I/O buffer frame */
...@@ -102,23 +123,28 @@ struct blkif_request_rw { ...@@ -102,23 +123,28 @@ struct blkif_request_rw {
/* @last_sect: last sector in frame to transfer (inclusive). */ /* @last_sect: last sector in frame to transfer (inclusive). */
uint8_t first_sect, last_sect; uint8_t first_sect, last_sect;
} seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; } seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
}; } __attribute__((__packed__));
struct blkif_request_discard { struct blkif_request_discard {
uint8_t flag; /* BLKIF_DISCARD_SECURE or zero. */
#define BLKIF_DISCARD_SECURE (1<<0) /* ignored if discard-secure=0 */
blkif_vdev_t _pad1; /* only for read/write requests */
#ifdef CONFIG_X86_64
uint32_t _pad2; /* offsetof(blkif_req..,u.discard.id)==8*/
#endif
uint64_t id; /* private guest value, echoed in resp */
blkif_sector_t sector_number; blkif_sector_t sector_number;
uint64_t nr_sectors; uint64_t nr_sectors;
}; uint8_t _pad3;
} __attribute__((__packed__));
struct blkif_request { struct blkif_request {
uint8_t operation; /* BLKIF_OP_??? */ uint8_t operation; /* BLKIF_OP_??? */
uint8_t nr_segments; /* number of segments */
blkif_vdev_t handle; /* only for read/write requests */
uint64_t id; /* private guest value, echoed in resp */
union { union {
struct blkif_request_rw rw; struct blkif_request_rw rw;
struct blkif_request_discard discard; struct blkif_request_discard discard;
} u; } u;
}; } __attribute__((__packed__));
struct blkif_response { struct blkif_response {
uint64_t id; /* copied from request */ uint64_t id; /* copied from request */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment