diff options
| author | Jens Axboe <axboe@kernel.dk> | 2012-12-19 14:37:10 -0500 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2012-12-19 14:37:10 -0500 |
| commit | b6c46cfa312639a5416959258e6a81bea2fdaf8a (patch) | |
| tree | b087a7aa789e33465cceb70d8f8bc68b6f1ea919 | |
| parent | 12c2bdb232168511c8dd54d6626549391a228918 (diff) | |
| parent | d62f691858252333ff1ddb920e6774d9020734aa (diff) | |
Merge branch 'stable/for-jens-3.8' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen into for-linus
Konrad writes:
Please git pull the following branch:
git://git.kernel.org/pub/scm/linux/kernel/git/konrad/xen.git stable/for-jens-3.8
which has a bug-fix to the xen-blkfront and xen-blkback driver
when using the persistent mode. An issue was discovered where LVM
disks could not be read correctly and this fixes it. There
is also a change in llist.h which has been blessed by akpm.
| -rw-r--r-- | drivers/block/xen-blkback/blkback.c | 18 | ||||
| -rw-r--r-- | drivers/block/xen-blkfront.c | 10 | ||||
| -rw-r--r-- | include/linux/llist.h | 25 |
3 files changed, 42 insertions, 11 deletions
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index 74374fb762aa..5ac841ff6cc7 100644 --- a/drivers/block/xen-blkback/blkback.c +++ b/drivers/block/xen-blkback/blkback.c | |||
| @@ -161,10 +161,12 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif, | |||
| 161 | static void make_response(struct xen_blkif *blkif, u64 id, | 161 | static void make_response(struct xen_blkif *blkif, u64 id, |
| 162 | unsigned short op, int st); | 162 | unsigned short op, int st); |
| 163 | 163 | ||
| 164 | #define foreach_grant(pos, rbtree, node) \ | 164 | #define foreach_grant_safe(pos, n, rbtree, node) \ |
| 165 | for ((pos) = container_of(rb_first((rbtree)), typeof(*(pos)), node); \ | 165 | for ((pos) = container_of(rb_first((rbtree)), typeof(*(pos)), node), \ |
| 166 | (n) = rb_next(&(pos)->node); \ | ||
| 166 | &(pos)->node != NULL; \ | 167 | &(pos)->node != NULL; \ |
| 167 | (pos) = container_of(rb_next(&(pos)->node), typeof(*(pos)), node)) | 168 | (pos) = container_of(n, typeof(*(pos)), node), \ |
| 169 | (n) = (&(pos)->node != NULL) ? rb_next(&(pos)->node) : NULL) | ||
| 168 | 170 | ||
| 169 | 171 | ||
| 170 | static void add_persistent_gnt(struct rb_root *root, | 172 | static void add_persistent_gnt(struct rb_root *root, |
| @@ -217,10 +219,11 @@ static void free_persistent_gnts(struct rb_root *root, unsigned int num) | |||
| 217 | struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; | 219 | struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; |
| 218 | struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST]; | 220 | struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST]; |
| 219 | struct persistent_gnt *persistent_gnt; | 221 | struct persistent_gnt *persistent_gnt; |
| 222 | struct rb_node *n; | ||
| 220 | int ret = 0; | 223 | int ret = 0; |
| 221 | int segs_to_unmap = 0; | 224 | int segs_to_unmap = 0; |
| 222 | 225 | ||
| 223 | foreach_grant(persistent_gnt, root, node) { | 226 | foreach_grant_safe(persistent_gnt, n, root, node) { |
| 224 | BUG_ON(persistent_gnt->handle == | 227 | BUG_ON(persistent_gnt->handle == |
| 225 | BLKBACK_INVALID_HANDLE); | 228 | BLKBACK_INVALID_HANDLE); |
| 226 | gnttab_set_unmap_op(&unmap[segs_to_unmap], | 229 | gnttab_set_unmap_op(&unmap[segs_to_unmap], |
| @@ -230,9 +233,6 @@ static void free_persistent_gnts(struct rb_root *root, unsigned int num) | |||
| 230 | persistent_gnt->handle); | 233 | persistent_gnt->handle); |
| 231 | 234 | ||
| 232 | pages[segs_to_unmap] = persistent_gnt->page; | 235 | pages[segs_to_unmap] = persistent_gnt->page; |
| 233 | rb_erase(&persistent_gnt->node, root); | ||
| 234 | kfree(persistent_gnt); | ||
| 235 | num--; | ||
| 236 | 236 | ||
| 237 | if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST || | 237 | if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST || |
| 238 | !rb_next(&persistent_gnt->node)) { | 238 | !rb_next(&persistent_gnt->node)) { |
| @@ -241,6 +241,10 @@ static void free_persistent_gnts(struct rb_root *root, unsigned int num) | |||
| 241 | BUG_ON(ret); | 241 | BUG_ON(ret); |
| 242 | segs_to_unmap = 0; | 242 | segs_to_unmap = 0; |
| 243 | } | 243 | } |
| 244 | |||
| 245 | rb_erase(&persistent_gnt->node, root); | ||
| 246 | kfree(persistent_gnt); | ||
| 247 | num--; | ||
| 244 | } | 248 | } |
| 245 | BUG_ON(num != 0); | 249 | BUG_ON(num != 0); |
| 246 | } | 250 | } |
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 96e9b00db081..11043c18ac5a 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c | |||
| @@ -792,6 +792,7 @@ static void blkif_free(struct blkfront_info *info, int suspend) | |||
| 792 | { | 792 | { |
| 793 | struct llist_node *all_gnts; | 793 | struct llist_node *all_gnts; |
| 794 | struct grant *persistent_gnt; | 794 | struct grant *persistent_gnt; |
| 795 | struct llist_node *n; | ||
| 795 | 796 | ||
| 796 | /* Prevent new requests being issued until we fix things up. */ | 797 | /* Prevent new requests being issued until we fix things up. */ |
| 797 | spin_lock_irq(&info->io_lock); | 798 | spin_lock_irq(&info->io_lock); |
| @@ -804,7 +805,7 @@ static void blkif_free(struct blkfront_info *info, int suspend) | |||
| 804 | /* Remove all persistent grants */ | 805 | /* Remove all persistent grants */ |
| 805 | if (info->persistent_gnts_c) { | 806 | if (info->persistent_gnts_c) { |
| 806 | all_gnts = llist_del_all(&info->persistent_gnts); | 807 | all_gnts = llist_del_all(&info->persistent_gnts); |
| 807 | llist_for_each_entry(persistent_gnt, all_gnts, node) { | 808 | llist_for_each_entry_safe(persistent_gnt, n, all_gnts, node) { |
| 808 | gnttab_end_foreign_access(persistent_gnt->gref, 0, 0UL); | 809 | gnttab_end_foreign_access(persistent_gnt->gref, 0, 0UL); |
| 809 | __free_page(pfn_to_page(persistent_gnt->pfn)); | 810 | __free_page(pfn_to_page(persistent_gnt->pfn)); |
| 810 | kfree(persistent_gnt); | 811 | kfree(persistent_gnt); |
| @@ -835,7 +836,7 @@ static void blkif_free(struct blkfront_info *info, int suspend) | |||
| 835 | static void blkif_completion(struct blk_shadow *s, struct blkfront_info *info, | 836 | static void blkif_completion(struct blk_shadow *s, struct blkfront_info *info, |
| 836 | struct blkif_response *bret) | 837 | struct blkif_response *bret) |
| 837 | { | 838 | { |
| 838 | int i; | 839 | int i = 0; |
| 839 | struct bio_vec *bvec; | 840 | struct bio_vec *bvec; |
| 840 | struct req_iterator iter; | 841 | struct req_iterator iter; |
| 841 | unsigned long flags; | 842 | unsigned long flags; |
| @@ -852,7 +853,8 @@ static void blkif_completion(struct blk_shadow *s, struct blkfront_info *info, | |||
| 852 | */ | 853 | */ |
| 853 | rq_for_each_segment(bvec, s->request, iter) { | 854 | rq_for_each_segment(bvec, s->request, iter) { |
| 854 | BUG_ON((bvec->bv_offset + bvec->bv_len) > PAGE_SIZE); | 855 | BUG_ON((bvec->bv_offset + bvec->bv_len) > PAGE_SIZE); |
| 855 | i = offset >> PAGE_SHIFT; | 856 | if (bvec->bv_offset < offset) |
| 857 | i++; | ||
| 856 | BUG_ON(i >= s->req.u.rw.nr_segments); | 858 | BUG_ON(i >= s->req.u.rw.nr_segments); |
| 857 | shared_data = kmap_atomic( | 859 | shared_data = kmap_atomic( |
| 858 | pfn_to_page(s->grants_used[i]->pfn)); | 860 | pfn_to_page(s->grants_used[i]->pfn)); |
| @@ -861,7 +863,7 @@ static void blkif_completion(struct blk_shadow *s, struct blkfront_info *info, | |||
| 861 | bvec->bv_len); | 863 | bvec->bv_len); |
| 862 | bvec_kunmap_irq(bvec_data, &flags); | 864 | bvec_kunmap_irq(bvec_data, &flags); |
| 863 | kunmap_atomic(shared_data); | 865 | kunmap_atomic(shared_data); |
| 864 | offset += bvec->bv_len; | 866 | offset = bvec->bv_offset + bvec->bv_len; |
| 865 | } | 867 | } |
| 866 | } | 868 | } |
| 867 | /* Add the persistent grant into the list of free grants */ | 869 | /* Add the persistent grant into the list of free grants */ |
diff --git a/include/linux/llist.h b/include/linux/llist.h index a5199f6d0e82..d0ab98f73d38 100644 --- a/include/linux/llist.h +++ b/include/linux/llist.h | |||
| @@ -125,6 +125,31 @@ static inline void init_llist_head(struct llist_head *list) | |||
| 125 | (pos) = llist_entry((pos)->member.next, typeof(*(pos)), member)) | 125 | (pos) = llist_entry((pos)->member.next, typeof(*(pos)), member)) |
| 126 | 126 | ||
| 127 | /** | 127 | /** |
| 128 | * llist_for_each_entry_safe - iterate safely against remove over some entries | ||
| 129 | * of lock-less list of given type. | ||
| 130 | * @pos: the type * to use as a loop cursor. | ||
| 131 | * @n: another type * to use as a temporary storage. | ||
| 132 | * @node: the fist entry of deleted list entries. | ||
| 133 | * @member: the name of the llist_node with the struct. | ||
| 134 | * | ||
| 135 | * In general, some entries of the lock-less list can be traversed | ||
| 136 | * safely only after being removed from list, so start with an entry | ||
| 137 | * instead of list head. This variant allows removal of entries | ||
| 138 | * as we iterate. | ||
| 139 | * | ||
| 140 | * If being used on entries deleted from lock-less list directly, the | ||
| 141 | * traverse order is from the newest to the oldest added entry. If | ||
| 142 | * you want to traverse from the oldest to the newest, you must | ||
| 143 | * reverse the order by yourself before traversing. | ||
| 144 | */ | ||
| 145 | #define llist_for_each_entry_safe(pos, n, node, member) \ | ||
| 146 | for ((pos) = llist_entry((node), typeof(*(pos)), member), \ | ||
| 147 | (n) = (pos)->member.next; \ | ||
| 148 | &(pos)->member != NULL; \ | ||
| 149 | (pos) = llist_entry(n, typeof(*(pos)), member), \ | ||
| 150 | (n) = (&(pos)->member != NULL) ? (pos)->member.next : NULL) | ||
| 151 | |||
| 152 | /** | ||
| 128 | * llist_empty - tests whether a lock-less list is empty | 153 | * llist_empty - tests whether a lock-less list is empty |
| 129 | * @head: the list to test | 154 | * @head: the list to test |
| 130 | * | 155 | * |
