diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-01-15 15:48:41 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-01-15 15:48:41 -0500 |
commit | 16008d641670571ff4cd750b416c7caf2d89f467 (patch) | |
tree | 6dc32821bd4576106cee50d52a90a8106a9d481f /drivers/block/xen-blkfront.c | |
parent | b3c9dd182ed3bdcdaf0e42625a35924b0497afdc (diff) | |
parent | 85a0f7b220777cd3c232fd2f079db5c4a874c4ee (diff) |
Merge branch 'for-3.3/drivers' of git://git.kernel.dk/linux-block
* 'for-3.3/drivers' of git://git.kernel.dk/linux-block:
mtip32xx: do rebuild monitoring asynchronously
xen-blkfront: Use kcalloc instead of kzalloc to allocate array
mtip32xx: uninitialized variable in mtip_quiesce_io()
mtip32xx: updates based on feedback
xen-blkback: convert hole punching to discard request on loop devices
xen/blkback: Move processing of BLKIF_OP_DISCARD from dispatch_rw_block_io
xen/blk[front|back]: Enhance discard support with secure erasing support.
xen/blk[front|back]: Squash blkif_request_rw and blkif_request_discard together
mtip32xx: update to new ->make_request() API
mtip32xx: add module.h include to avoid conflict with moduleh tree
mtip32xx: mark a few more items static
mtip32xx: ensure that all local functions are static
mtip32xx: cleanup compat ioctl handling
mtip32xx: fix warnings/errors on 32-bit compiles
block: Add driver for Micron RealSSD pcie flash cards
Diffstat (limited to 'drivers/block/xen-blkfront.c')
-rw-r--r-- | drivers/block/xen-blkfront.c | 79 |
1 files changed, 51 insertions, 28 deletions
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 9fd3ee203b1e..2f22874c0a37 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c | |||
@@ -98,7 +98,8 @@ struct blkfront_info | |||
98 | unsigned long shadow_free; | 98 | unsigned long shadow_free; |
99 | unsigned int feature_flush; | 99 | unsigned int feature_flush; |
100 | unsigned int flush_op; | 100 | unsigned int flush_op; |
101 | unsigned int feature_discard; | 101 | unsigned int feature_discard:1; |
102 | unsigned int feature_secdiscard:1; | ||
102 | unsigned int discard_granularity; | 103 | unsigned int discard_granularity; |
103 | unsigned int discard_alignment; | 104 | unsigned int discard_alignment; |
104 | int is_ready; | 105 | int is_ready; |
@@ -135,15 +136,15 @@ static int get_id_from_freelist(struct blkfront_info *info) | |||
135 | { | 136 | { |
136 | unsigned long free = info->shadow_free; | 137 | unsigned long free = info->shadow_free; |
137 | BUG_ON(free >= BLK_RING_SIZE); | 138 | BUG_ON(free >= BLK_RING_SIZE); |
138 | info->shadow_free = info->shadow[free].req.id; | 139 | info->shadow_free = info->shadow[free].req.u.rw.id; |
139 | info->shadow[free].req.id = 0x0fffffee; /* debug */ | 140 | info->shadow[free].req.u.rw.id = 0x0fffffee; /* debug */ |
140 | return free; | 141 | return free; |
141 | } | 142 | } |
142 | 143 | ||
143 | static void add_id_to_freelist(struct blkfront_info *info, | 144 | static void add_id_to_freelist(struct blkfront_info *info, |
144 | unsigned long id) | 145 | unsigned long id) |
145 | { | 146 | { |
146 | info->shadow[id].req.id = info->shadow_free; | 147 | info->shadow[id].req.u.rw.id = info->shadow_free; |
147 | info->shadow[id].request = NULL; | 148 | info->shadow[id].request = NULL; |
148 | info->shadow_free = id; | 149 | info->shadow_free = id; |
149 | } | 150 | } |
@@ -156,7 +157,7 @@ static int xlbd_reserve_minors(unsigned int minor, unsigned int nr) | |||
156 | if (end > nr_minors) { | 157 | if (end > nr_minors) { |
157 | unsigned long *bitmap, *old; | 158 | unsigned long *bitmap, *old; |
158 | 159 | ||
159 | bitmap = kzalloc(BITS_TO_LONGS(end) * sizeof(*bitmap), | 160 | bitmap = kcalloc(BITS_TO_LONGS(end), sizeof(*bitmap), |
160 | GFP_KERNEL); | 161 | GFP_KERNEL); |
161 | if (bitmap == NULL) | 162 | if (bitmap == NULL) |
162 | return -ENOMEM; | 163 | return -ENOMEM; |
@@ -287,9 +288,9 @@ static int blkif_queue_request(struct request *req) | |||
287 | id = get_id_from_freelist(info); | 288 | id = get_id_from_freelist(info); |
288 | info->shadow[id].request = req; | 289 | info->shadow[id].request = req; |
289 | 290 | ||
290 | ring_req->id = id; | 291 | ring_req->u.rw.id = id; |
291 | ring_req->u.rw.sector_number = (blkif_sector_t)blk_rq_pos(req); | 292 | ring_req->u.rw.sector_number = (blkif_sector_t)blk_rq_pos(req); |
292 | ring_req->handle = info->handle; | 293 | ring_req->u.rw.handle = info->handle; |
293 | 294 | ||
294 | ring_req->operation = rq_data_dir(req) ? | 295 | ring_req->operation = rq_data_dir(req) ? |
295 | BLKIF_OP_WRITE : BLKIF_OP_READ; | 296 | BLKIF_OP_WRITE : BLKIF_OP_READ; |
@@ -305,16 +306,21 @@ static int blkif_queue_request(struct request *req) | |||
305 | ring_req->operation = info->flush_op; | 306 | ring_req->operation = info->flush_op; |
306 | } | 307 | } |
307 | 308 | ||
308 | if (unlikely(req->cmd_flags & REQ_DISCARD)) { | 309 | if (unlikely(req->cmd_flags & (REQ_DISCARD | REQ_SECURE))) { |
309 | /* id, sector_number and handle are set above. */ | 310 | /* id, sector_number and handle are set above. */ |
310 | ring_req->operation = BLKIF_OP_DISCARD; | 311 | ring_req->operation = BLKIF_OP_DISCARD; |
311 | ring_req->nr_segments = 0; | ||
312 | ring_req->u.discard.nr_sectors = blk_rq_sectors(req); | 312 | ring_req->u.discard.nr_sectors = blk_rq_sectors(req); |
313 | if ((req->cmd_flags & REQ_SECURE) && info->feature_secdiscard) | ||
314 | ring_req->u.discard.flag = BLKIF_DISCARD_SECURE; | ||
315 | else | ||
316 | ring_req->u.discard.flag = 0; | ||
313 | } else { | 317 | } else { |
314 | ring_req->nr_segments = blk_rq_map_sg(req->q, req, info->sg); | 318 | ring_req->u.rw.nr_segments = blk_rq_map_sg(req->q, req, |
315 | BUG_ON(ring_req->nr_segments > BLKIF_MAX_SEGMENTS_PER_REQUEST); | 319 | info->sg); |
320 | BUG_ON(ring_req->u.rw.nr_segments > | ||
321 | BLKIF_MAX_SEGMENTS_PER_REQUEST); | ||
316 | 322 | ||
317 | for_each_sg(info->sg, sg, ring_req->nr_segments, i) { | 323 | for_each_sg(info->sg, sg, ring_req->u.rw.nr_segments, i) { |
318 | buffer_mfn = pfn_to_mfn(page_to_pfn(sg_page(sg))); | 324 | buffer_mfn = pfn_to_mfn(page_to_pfn(sg_page(sg))); |
319 | fsect = sg->offset >> 9; | 325 | fsect = sg->offset >> 9; |
320 | lsect = fsect + (sg->length >> 9) - 1; | 326 | lsect = fsect + (sg->length >> 9) - 1; |
@@ -424,6 +430,8 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size) | |||
424 | blk_queue_max_discard_sectors(rq, get_capacity(gd)); | 430 | blk_queue_max_discard_sectors(rq, get_capacity(gd)); |
425 | rq->limits.discard_granularity = info->discard_granularity; | 431 | rq->limits.discard_granularity = info->discard_granularity; |
426 | rq->limits.discard_alignment = info->discard_alignment; | 432 | rq->limits.discard_alignment = info->discard_alignment; |
433 | if (info->feature_secdiscard) | ||
434 | queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD, rq); | ||
427 | } | 435 | } |
428 | 436 | ||
429 | /* Hard sector size and max sectors impersonate the equiv. hardware. */ | 437 | /* 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 | static void blkif_completion(struct blk_shadow *s) | 713 | static void blkif_completion(struct blk_shadow *s) |
706 | { | 714 | { |
707 | int i; | 715 | int i; |
708 | for (i = 0; i < s->req.nr_segments; i++) | 716 | /* Do not let BLKIF_OP_DISCARD as nr_segment is in the same place |
717 | * flag. */ | ||
718 | for (i = 0; i < s->req.u.rw.nr_segments; i++) | ||
709 | gnttab_end_foreign_access(s->req.u.rw.seg[i].gref, 0, 0UL); | 719 | gnttab_end_foreign_access(s->req.u.rw.seg[i].gref, 0, 0UL); |
710 | } | 720 | } |
711 | 721 | ||
@@ -736,7 +746,8 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) | |||
736 | id = bret->id; | 746 | id = bret->id; |
737 | req = info->shadow[id].request; | 747 | req = info->shadow[id].request; |
738 | 748 | ||
739 | blkif_completion(&info->shadow[id]); | 749 | if (bret->operation != BLKIF_OP_DISCARD) |
750 | blkif_completion(&info->shadow[id]); | ||
740 | 751 | ||
741 | add_id_to_freelist(info, id); | 752 | add_id_to_freelist(info, id); |
742 | 753 | ||
@@ -749,7 +760,9 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) | |||
749 | info->gd->disk_name); | 760 | info->gd->disk_name); |
750 | error = -EOPNOTSUPP; | 761 | error = -EOPNOTSUPP; |
751 | info->feature_discard = 0; | 762 | info->feature_discard = 0; |
763 | info->feature_secdiscard = 0; | ||
752 | queue_flag_clear(QUEUE_FLAG_DISCARD, rq); | 764 | queue_flag_clear(QUEUE_FLAG_DISCARD, rq); |
765 | queue_flag_clear(QUEUE_FLAG_SECDISCARD, rq); | ||
753 | } | 766 | } |
754 | __blk_end_request_all(req, error); | 767 | __blk_end_request_all(req, error); |
755 | break; | 768 | break; |
@@ -763,7 +776,7 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id) | |||
763 | error = -EOPNOTSUPP; | 776 | error = -EOPNOTSUPP; |
764 | } | 777 | } |
765 | if (unlikely(bret->status == BLKIF_RSP_ERROR && | 778 | if (unlikely(bret->status == BLKIF_RSP_ERROR && |
766 | info->shadow[id].req.nr_segments == 0)) { | 779 | info->shadow[id].req.u.rw.nr_segments == 0)) { |
767 | printk(KERN_WARNING "blkfront: %s: empty write %s op failed\n", | 780 | printk(KERN_WARNING "blkfront: %s: empty write %s op failed\n", |
768 | info->flush_op == BLKIF_OP_WRITE_BARRIER ? | 781 | info->flush_op == BLKIF_OP_WRITE_BARRIER ? |
769 | "barrier" : "flush disk cache", | 782 | "barrier" : "flush disk cache", |
@@ -984,8 +997,8 @@ static int blkfront_probe(struct xenbus_device *dev, | |||
984 | INIT_WORK(&info->work, blkif_restart_queue); | 997 | INIT_WORK(&info->work, blkif_restart_queue); |
985 | 998 | ||
986 | for (i = 0; i < BLK_RING_SIZE; i++) | 999 | for (i = 0; i < BLK_RING_SIZE; i++) |
987 | info->shadow[i].req.id = i+1; | 1000 | info->shadow[i].req.u.rw.id = i+1; |
988 | info->shadow[BLK_RING_SIZE-1].req.id = 0x0fffffff; | 1001 | info->shadow[BLK_RING_SIZE-1].req.u.rw.id = 0x0fffffff; |
989 | 1002 | ||
990 | /* Front end dir is a number, which is used as the id. */ | 1003 | /* Front end dir is a number, which is used as the id. */ |
991 | info->handle = simple_strtoul(strrchr(dev->nodename, '/')+1, NULL, 0); | 1004 | info->handle = simple_strtoul(strrchr(dev->nodename, '/')+1, NULL, 0); |
@@ -1019,9 +1032,9 @@ static int blkif_recover(struct blkfront_info *info) | |||
1019 | /* Stage 2: Set up free list. */ | 1032 | /* Stage 2: Set up free list. */ |
1020 | memset(&info->shadow, 0, sizeof(info->shadow)); | 1033 | memset(&info->shadow, 0, sizeof(info->shadow)); |
1021 | for (i = 0; i < BLK_RING_SIZE; i++) | 1034 | for (i = 0; i < BLK_RING_SIZE; i++) |
1022 | info->shadow[i].req.id = i+1; | 1035 | info->shadow[i].req.u.rw.id = i+1; |
1023 | info->shadow_free = info->ring.req_prod_pvt; | 1036 | info->shadow_free = info->ring.req_prod_pvt; |
1024 | info->shadow[BLK_RING_SIZE-1].req.id = 0x0fffffff; | 1037 | info->shadow[BLK_RING_SIZE-1].req.u.rw.id = 0x0fffffff; |
1025 | 1038 | ||
1026 | /* Stage 3: Find pending requests and requeue them. */ | 1039 | /* Stage 3: Find pending requests and requeue them. */ |
1027 | for (i = 0; i < BLK_RING_SIZE; i++) { | 1040 | for (i = 0; i < BLK_RING_SIZE; i++) { |
@@ -1034,17 +1047,19 @@ static int blkif_recover(struct blkfront_info *info) | |||
1034 | *req = copy[i].req; | 1047 | *req = copy[i].req; |
1035 | 1048 | ||
1036 | /* We get a new request id, and must reset the shadow state. */ | 1049 | /* We get a new request id, and must reset the shadow state. */ |
1037 | req->id = get_id_from_freelist(info); | 1050 | req->u.rw.id = get_id_from_freelist(info); |
1038 | memcpy(&info->shadow[req->id], ©[i], sizeof(copy[i])); | 1051 | memcpy(&info->shadow[req->u.rw.id], ©[i], sizeof(copy[i])); |
1039 | 1052 | ||
1053 | if (req->operation != BLKIF_OP_DISCARD) { | ||
1040 | /* Rewrite any grant references invalidated by susp/resume. */ | 1054 | /* Rewrite any grant references invalidated by susp/resume. */ |
1041 | for (j = 0; j < req->nr_segments; j++) | 1055 | for (j = 0; j < req->u.rw.nr_segments; j++) |
1042 | gnttab_grant_foreign_access_ref( | 1056 | gnttab_grant_foreign_access_ref( |
1043 | req->u.rw.seg[j].gref, | 1057 | req->u.rw.seg[j].gref, |
1044 | info->xbdev->otherend_id, | 1058 | info->xbdev->otherend_id, |
1045 | pfn_to_mfn(info->shadow[req->id].frame[j]), | 1059 | pfn_to_mfn(info->shadow[req->u.rw.id].frame[j]), |
1046 | rq_data_dir(info->shadow[req->id].request)); | 1060 | rq_data_dir(info->shadow[req->u.rw.id].request)); |
1047 | info->shadow[req->id].req = *req; | 1061 | } |
1062 | info->shadow[req->u.rw.id].req = *req; | ||
1048 | 1063 | ||
1049 | info->ring.req_prod_pvt++; | 1064 | info->ring.req_prod_pvt++; |
1050 | } | 1065 | } |
@@ -1135,11 +1150,13 @@ static void blkfront_setup_discard(struct blkfront_info *info) | |||
1135 | char *type; | 1150 | char *type; |
1136 | unsigned int discard_granularity; | 1151 | unsigned int discard_granularity; |
1137 | unsigned int discard_alignment; | 1152 | unsigned int discard_alignment; |
1153 | unsigned int discard_secure; | ||
1138 | 1154 | ||
1139 | type = xenbus_read(XBT_NIL, info->xbdev->otherend, "type", NULL); | 1155 | type = xenbus_read(XBT_NIL, info->xbdev->otherend, "type", NULL); |
1140 | if (IS_ERR(type)) | 1156 | if (IS_ERR(type)) |
1141 | return; | 1157 | return; |
1142 | 1158 | ||
1159 | info->feature_secdiscard = 0; | ||
1143 | if (strncmp(type, "phy", 3) == 0) { | 1160 | if (strncmp(type, "phy", 3) == 0) { |
1144 | err = xenbus_gather(XBT_NIL, info->xbdev->otherend, | 1161 | err = xenbus_gather(XBT_NIL, info->xbdev->otherend, |
1145 | "discard-granularity", "%u", &discard_granularity, | 1162 | "discard-granularity", "%u", &discard_granularity, |
@@ -1150,6 +1167,12 @@ static void blkfront_setup_discard(struct blkfront_info *info) | |||
1150 | info->discard_granularity = discard_granularity; | 1167 | info->discard_granularity = discard_granularity; |
1151 | info->discard_alignment = discard_alignment; | 1168 | info->discard_alignment = discard_alignment; |
1152 | } | 1169 | } |
1170 | err = xenbus_gather(XBT_NIL, info->xbdev->otherend, | ||
1171 | "discard-secure", "%d", &discard_secure, | ||
1172 | NULL); | ||
1173 | if (!err) | ||
1174 | info->feature_secdiscard = discard_secure; | ||
1175 | |||
1153 | } else if (strncmp(type, "file", 4) == 0) | 1176 | } else if (strncmp(type, "file", 4) == 0) |
1154 | info->feature_discard = 1; | 1177 | info->feature_discard = 1; |
1155 | 1178 | ||