diff options
author | Jan Beulich <JBeulich@novell.com> | 2011-05-17 06:07:05 -0400 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2011-05-18 11:28:16 -0400 |
commit | 8ab521506c4dbb144f0c04c55e3d8bec42c1b2b9 (patch) | |
tree | 4521381df4e0dad05ec7b0d3746ea520fd824e2f /drivers/block | |
parent | 496b318eb65558c1a3a4fe882cb9da6d1dc6493a (diff) |
xen/blkback: don't fail empty barrier requests
The sector number on empty barrier requests may (will?) be -1, which,
given that it's being treated as unsigned 64-bit quantity, will almost
always exceed the actual (virtual) disk's size.
Inspired by Konrad's "When writting barriers set the sector number to
zero...".
While at it also add overflow checking to the math in vbd_translate().
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'drivers/block')
-rw-r--r-- | drivers/block/xen-blkback/blkback.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index dba55e3a4a86..c73910cc28c9 100644 --- a/drivers/block/xen-blkback/blkback.c +++ b/drivers/block/xen-blkback/blkback.c | |||
@@ -175,8 +175,14 @@ static int xen_vbd_translate(struct phys_req *req, struct xen_blkif *blkif, | |||
175 | if ((operation != READ) && vbd->readonly) | 175 | if ((operation != READ) && vbd->readonly) |
176 | goto out; | 176 | goto out; |
177 | 177 | ||
178 | if (unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd))) | 178 | if (likely(req->nr_sects)) { |
179 | goto out; | 179 | blkif_sector_t end = req->sector_number + req->nr_sects; |
180 | |||
181 | if (unlikely(end < req->sector_number)) | ||
182 | goto out; | ||
183 | if (unlikely(end > vbd_sz(vbd))) | ||
184 | goto out; | ||
185 | } | ||
180 | 186 | ||
181 | req->dev = vbd->pdevice; | 187 | req->dev = vbd->pdevice; |
182 | req->bdev = vbd->bdev; | 188 | req->bdev = vbd->bdev; |
@@ -538,11 +544,6 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, | |||
538 | case BLKIF_OP_FLUSH_DISKCACHE: | 544 | case BLKIF_OP_FLUSH_DISKCACHE: |
539 | blkif->st_f_req++; | 545 | blkif->st_f_req++; |
540 | operation = WRITE_FLUSH; | 546 | operation = WRITE_FLUSH; |
541 | /* | ||
542 | * The frontend likes to set this to -1, which xen_vbd_translate | ||
543 | * is alergic too. | ||
544 | */ | ||
545 | req->u.rw.sector_number = 0; | ||
546 | break; | 547 | break; |
547 | case BLKIF_OP_WRITE_BARRIER: | 548 | case BLKIF_OP_WRITE_BARRIER: |
548 | default: | 549 | default: |