Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1 | /****************************************************************************** |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 2 | * |
| 3 | * Back-end of the driver for virtual block devices. This portion of the |
| 4 | * driver exports a 'unified' block-device interface that can be accessed |
| 5 | * by any operating system that implements a compatible front end. A |
| 6 | * reference front-end implementation can be found in: |
Konrad Rzeszutek Wilk | a1397fa | 2011-04-14 17:05:23 -0400 | [diff] [blame] | 7 | * drivers/block/xen-blkfront.c |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 8 | * |
| 9 | * Copyright (c) 2003-2004, Keir Fraser & Steve Hand |
| 10 | * Copyright (c) 2005, Christopher Clark |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License version 2 |
| 14 | * as published by the Free Software Foundation; or, when distributed |
| 15 | * separately from the Linux kernel or incorporated into other |
| 16 | * software packages, subject to the following license: |
| 17 | * |
| 18 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 19 | * of this source file (the "Software"), to deal in the Software without |
| 20 | * restriction, including without limitation the rights to use, copy, modify, |
| 21 | * merge, publish, distribute, sublicense, and/or sell copies of the Software, |
| 22 | * and to permit persons to whom the Software is furnished to do so, subject to |
| 23 | * the following conditions: |
| 24 | * |
| 25 | * The above copyright notice and this permission notice shall be included in |
| 26 | * all copies or substantial portions of the Software. |
| 27 | * |
| 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 29 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 30 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 31 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 32 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 33 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 34 | * IN THE SOFTWARE. |
| 35 | */ |
| 36 | |
| 37 | #include <linux/spinlock.h> |
| 38 | #include <linux/kthread.h> |
| 39 | #include <linux/list.h> |
| 40 | #include <linux/delay.h> |
Jeremy Fitzhardinge | 8812293 | 2009-02-09 12:05:51 -0800 | [diff] [blame] | 41 | #include <linux/freezer.h> |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 42 | #include <linux/bitmap.h> |
Jeremy Fitzhardinge | afd91d0 | 2009-09-15 14:12:37 -0700 | [diff] [blame] | 43 | |
Jeremy Fitzhardinge | 8812293 | 2009-02-09 12:05:51 -0800 | [diff] [blame] | 44 | #include <xen/events.h> |
| 45 | #include <xen/page.h> |
Stefano Stabellini | e79affc | 2012-08-08 17:21:14 +0000 | [diff] [blame] | 46 | #include <xen/xen.h> |
Jeremy Fitzhardinge | 8812293 | 2009-02-09 12:05:51 -0800 | [diff] [blame] | 47 | #include <asm/xen/hypervisor.h> |
| 48 | #include <asm/xen/hypercall.h> |
Roger Pau Monne | 087ffec | 2013-02-14 11:12:09 +0100 | [diff] [blame] | 49 | #include <xen/balloon.h> |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 50 | #include "common.h" |
| 51 | |
| 52 | /* |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 53 | * Maximum number of unused free pages to keep in the internal buffer. |
| 54 | * Setting this to a value too low will reduce memory used in each backend, |
| 55 | * but can have a performance penalty. |
| 56 | * |
| 57 | * A sane value is xen_blkif_reqs * BLKIF_MAX_SEGMENTS_PER_REQUEST, but can |
| 58 | * be set to a lower value that might degrade performance on some intensive |
| 59 | * IO workloads. |
| 60 | */ |
| 61 | |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 62 | static int xen_blkif_max_buffer_pages = 1024; |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 63 | module_param_named(max_buffer_pages, xen_blkif_max_buffer_pages, int, 0644); |
| 64 | MODULE_PARM_DESC(max_buffer_pages, |
| 65 | "Maximum number of free pages to keep in each block backend buffer"); |
| 66 | |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 67 | /* |
| 68 | * Maximum number of grants to map persistently in blkback. For maximum |
| 69 | * performance this should be the total numbers of grants that can be used |
| 70 | * to fill the ring, but since this might become too high, specially with |
| 71 | * the use of indirect descriptors, we set it to a value that provides good |
| 72 | * performance without using too much memory. |
| 73 | * |
| 74 | * When the list of persistent grants is full we clean it up using a LRU |
| 75 | * algorithm. |
| 76 | */ |
| 77 | |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 78 | static int xen_blkif_max_pgrants = 1056; |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 79 | module_param_named(max_persistent_grants, xen_blkif_max_pgrants, int, 0644); |
| 80 | MODULE_PARM_DESC(max_persistent_grants, |
| 81 | "Maximum number of grants to map persistently"); |
| 82 | |
| 83 | /* |
| 84 | * The LRU mechanism to clean the lists of persistent grants needs to |
| 85 | * be executed periodically. The time interval between consecutive executions |
| 86 | * of the purge mechanism is set in ms. |
| 87 | */ |
| 88 | #define LRU_INTERVAL 100 |
| 89 | |
| 90 | /* |
| 91 | * When the persistent grants list is full we will remove unused grants |
| 92 | * from the list. The percent number of grants to be removed at each LRU |
| 93 | * execution. |
| 94 | */ |
| 95 | #define LRU_PERCENT_CLEAN 5 |
| 96 | |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 97 | /* Run-time switchable: /sys/module/blkback/parameters/ */ |
Konrad Rzeszutek Wilk | 2e9977c | 2011-04-14 17:42:07 -0400 | [diff] [blame] | 98 | static unsigned int log_stats; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 99 | module_param(log_stats, int, 0644); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 100 | |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 101 | #define BLKBACK_INVALID_HANDLE (~0) |
| 102 | |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 103 | /* Number of free pages to remove on each call to free_xenballooned_pages */ |
| 104 | #define NUM_BATCH_FREE_PAGES 10 |
| 105 | |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 106 | static inline int get_free_page(struct xen_blkif *blkif, struct page **page) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 107 | { |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 108 | unsigned long flags; |
| 109 | |
| 110 | spin_lock_irqsave(&blkif->free_pages_lock, flags); |
| 111 | if (list_empty(&blkif->free_pages)) { |
| 112 | BUG_ON(blkif->free_pages_num != 0); |
| 113 | spin_unlock_irqrestore(&blkif->free_pages_lock, flags); |
| 114 | return alloc_xenballooned_pages(1, page, false); |
| 115 | } |
| 116 | BUG_ON(blkif->free_pages_num == 0); |
| 117 | page[0] = list_first_entry(&blkif->free_pages, struct page, lru); |
| 118 | list_del(&page[0]->lru); |
| 119 | blkif->free_pages_num--; |
| 120 | spin_unlock_irqrestore(&blkif->free_pages_lock, flags); |
| 121 | |
| 122 | return 0; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 123 | } |
| 124 | |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 125 | static inline void put_free_pages(struct xen_blkif *blkif, struct page **page, |
| 126 | int num) |
| 127 | { |
| 128 | unsigned long flags; |
| 129 | int i; |
| 130 | |
| 131 | spin_lock_irqsave(&blkif->free_pages_lock, flags); |
| 132 | for (i = 0; i < num; i++) |
| 133 | list_add(&page[i]->lru, &blkif->free_pages); |
| 134 | blkif->free_pages_num += num; |
| 135 | spin_unlock_irqrestore(&blkif->free_pages_lock, flags); |
| 136 | } |
| 137 | |
| 138 | static inline void shrink_free_pagepool(struct xen_blkif *blkif, int num) |
| 139 | { |
| 140 | /* Remove requested pages in batches of NUM_BATCH_FREE_PAGES */ |
| 141 | struct page *page[NUM_BATCH_FREE_PAGES]; |
| 142 | unsigned int num_pages = 0; |
| 143 | unsigned long flags; |
| 144 | |
| 145 | spin_lock_irqsave(&blkif->free_pages_lock, flags); |
| 146 | while (blkif->free_pages_num > num) { |
| 147 | BUG_ON(list_empty(&blkif->free_pages)); |
| 148 | page[num_pages] = list_first_entry(&blkif->free_pages, |
| 149 | struct page, lru); |
| 150 | list_del(&page[num_pages]->lru); |
| 151 | blkif->free_pages_num--; |
| 152 | if (++num_pages == NUM_BATCH_FREE_PAGES) { |
| 153 | spin_unlock_irqrestore(&blkif->free_pages_lock, flags); |
| 154 | free_xenballooned_pages(num_pages, page); |
| 155 | spin_lock_irqsave(&blkif->free_pages_lock, flags); |
| 156 | num_pages = 0; |
| 157 | } |
| 158 | } |
| 159 | spin_unlock_irqrestore(&blkif->free_pages_lock, flags); |
| 160 | if (num_pages != 0) |
| 161 | free_xenballooned_pages(num_pages, page); |
| 162 | } |
| 163 | |
| 164 | #define vaddr(page) ((unsigned long)pfn_to_kaddr(page_to_pfn(page))) |
| 165 | |
Konrad Rzeszutek Wilk | 30fd150 | 2011-05-12 16:47:48 -0400 | [diff] [blame] | 166 | static int do_block_io_op(struct xen_blkif *blkif); |
| 167 | static int dispatch_rw_block_io(struct xen_blkif *blkif, |
Konrad Rzeszutek Wilk | fc53bf7 | 2011-05-05 13:37:23 -0400 | [diff] [blame] | 168 | struct blkif_request *req, |
| 169 | struct pending_req *pending_req); |
Konrad Rzeszutek Wilk | 30fd150 | 2011-05-12 16:47:48 -0400 | [diff] [blame] | 170 | static void make_response(struct xen_blkif *blkif, u64 id, |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 171 | unsigned short op, int st); |
| 172 | |
Roger Pau Monne | 7dc3411 | 2012-12-04 15:21:52 +0100 | [diff] [blame] | 173 | #define foreach_grant_safe(pos, n, rbtree, node) \ |
| 174 | for ((pos) = container_of(rb_first((rbtree)), typeof(*(pos)), node), \ |
Roger Pau Monne | 217fd5e | 2013-03-18 17:49:33 +0100 | [diff] [blame] | 175 | (n) = (&(pos)->node != NULL) ? rb_next(&(pos)->node) : NULL; \ |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 176 | &(pos)->node != NULL; \ |
Roger Pau Monne | 7dc3411 | 2012-12-04 15:21:52 +0100 | [diff] [blame] | 177 | (pos) = container_of(n, typeof(*(pos)), node), \ |
| 178 | (n) = (&(pos)->node != NULL) ? rb_next(&(pos)->node) : NULL) |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 179 | |
| 180 | |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 181 | /* |
| 182 | * We don't need locking around the persistent grant helpers |
| 183 | * because blkback uses a single-thread for each backed, so we |
| 184 | * can be sure that this functions will never be called recursively. |
| 185 | * |
| 186 | * The only exception to that is put_persistent_grant, that can be called |
| 187 | * from interrupt context (by xen_blkbk_unmap), so we have to use atomic |
| 188 | * bit operations to modify the flags of a persistent grant and to count |
| 189 | * the number of used grants. |
| 190 | */ |
| 191 | static int add_persistent_gnt(struct xen_blkif *blkif, |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 192 | struct persistent_gnt *persistent_gnt) |
| 193 | { |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 194 | struct rb_node **new = NULL, *parent = NULL; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 195 | struct persistent_gnt *this; |
| 196 | |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 197 | if (blkif->persistent_gnt_c >= xen_blkif_max_pgrants) { |
| 198 | if (!blkif->vbd.overflow_max_grants) |
| 199 | blkif->vbd.overflow_max_grants = 1; |
| 200 | return -EBUSY; |
| 201 | } |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 202 | /* Figure out where to put new node */ |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 203 | new = &blkif->persistent_gnts.rb_node; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 204 | while (*new) { |
| 205 | this = container_of(*new, struct persistent_gnt, node); |
| 206 | |
| 207 | parent = *new; |
| 208 | if (persistent_gnt->gnt < this->gnt) |
| 209 | new = &((*new)->rb_left); |
| 210 | else if (persistent_gnt->gnt > this->gnt) |
| 211 | new = &((*new)->rb_right); |
| 212 | else { |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 213 | pr_alert_ratelimited(DRV_PFX " trying to add a gref that's already in the tree\n"); |
| 214 | return -EINVAL; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 218 | bitmap_zero(persistent_gnt->flags, PERSISTENT_GNT_FLAGS_SIZE); |
| 219 | set_bit(PERSISTENT_GNT_ACTIVE, persistent_gnt->flags); |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 220 | /* Add new node and rebalance tree. */ |
| 221 | rb_link_node(&(persistent_gnt->node), parent, new); |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 222 | rb_insert_color(&(persistent_gnt->node), &blkif->persistent_gnts); |
| 223 | blkif->persistent_gnt_c++; |
| 224 | atomic_inc(&blkif->persistent_gnt_in_use); |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 225 | return 0; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 226 | } |
| 227 | |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 228 | static struct persistent_gnt *get_persistent_gnt(struct xen_blkif *blkif, |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 229 | grant_ref_t gref) |
| 230 | { |
| 231 | struct persistent_gnt *data; |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 232 | struct rb_node *node = NULL; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 233 | |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 234 | node = blkif->persistent_gnts.rb_node; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 235 | while (node) { |
| 236 | data = container_of(node, struct persistent_gnt, node); |
| 237 | |
| 238 | if (gref < data->gnt) |
| 239 | node = node->rb_left; |
| 240 | else if (gref > data->gnt) |
| 241 | node = node->rb_right; |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 242 | else { |
| 243 | if(test_bit(PERSISTENT_GNT_ACTIVE, data->flags)) { |
| 244 | pr_alert_ratelimited(DRV_PFX " requesting a grant already in use\n"); |
| 245 | return NULL; |
| 246 | } |
| 247 | set_bit(PERSISTENT_GNT_ACTIVE, data->flags); |
| 248 | atomic_inc(&blkif->persistent_gnt_in_use); |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 249 | return data; |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 250 | } |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 251 | } |
| 252 | return NULL; |
| 253 | } |
| 254 | |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 255 | static void put_persistent_gnt(struct xen_blkif *blkif, |
| 256 | struct persistent_gnt *persistent_gnt) |
| 257 | { |
| 258 | if(!test_bit(PERSISTENT_GNT_ACTIVE, persistent_gnt->flags)) |
| 259 | pr_alert_ratelimited(DRV_PFX " freeing a grant already unused"); |
| 260 | set_bit(PERSISTENT_GNT_WAS_ACTIVE, persistent_gnt->flags); |
| 261 | clear_bit(PERSISTENT_GNT_ACTIVE, persistent_gnt->flags); |
| 262 | atomic_dec(&blkif->persistent_gnt_in_use); |
| 263 | } |
| 264 | |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 265 | static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root, |
| 266 | unsigned int num) |
Roger Pau Monne | 4d4f270 | 2012-11-16 19:26:48 +0100 | [diff] [blame] | 267 | { |
| 268 | struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; |
| 269 | struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST]; |
| 270 | struct persistent_gnt *persistent_gnt; |
Roger Pau Monne | 7dc3411 | 2012-12-04 15:21:52 +0100 | [diff] [blame] | 271 | struct rb_node *n; |
Roger Pau Monne | 4d4f270 | 2012-11-16 19:26:48 +0100 | [diff] [blame] | 272 | int ret = 0; |
| 273 | int segs_to_unmap = 0; |
| 274 | |
Roger Pau Monne | 7dc3411 | 2012-12-04 15:21:52 +0100 | [diff] [blame] | 275 | foreach_grant_safe(persistent_gnt, n, root, node) { |
Roger Pau Monne | 4d4f270 | 2012-11-16 19:26:48 +0100 | [diff] [blame] | 276 | BUG_ON(persistent_gnt->handle == |
| 277 | BLKBACK_INVALID_HANDLE); |
| 278 | gnttab_set_unmap_op(&unmap[segs_to_unmap], |
| 279 | (unsigned long) pfn_to_kaddr(page_to_pfn( |
| 280 | persistent_gnt->page)), |
| 281 | GNTMAP_host_map, |
| 282 | persistent_gnt->handle); |
| 283 | |
| 284 | pages[segs_to_unmap] = persistent_gnt->page; |
Roger Pau Monne | 4d4f270 | 2012-11-16 19:26:48 +0100 | [diff] [blame] | 285 | |
| 286 | if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST || |
| 287 | !rb_next(&persistent_gnt->node)) { |
| 288 | ret = gnttab_unmap_refs(unmap, NULL, pages, |
| 289 | segs_to_unmap); |
| 290 | BUG_ON(ret); |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 291 | put_free_pages(blkif, pages, segs_to_unmap); |
Roger Pau Monne | 4d4f270 | 2012-11-16 19:26:48 +0100 | [diff] [blame] | 292 | segs_to_unmap = 0; |
| 293 | } |
Roger Pau Monne | 7dc3411 | 2012-12-04 15:21:52 +0100 | [diff] [blame] | 294 | |
| 295 | rb_erase(&persistent_gnt->node, root); |
| 296 | kfree(persistent_gnt); |
| 297 | num--; |
Roger Pau Monne | 4d4f270 | 2012-11-16 19:26:48 +0100 | [diff] [blame] | 298 | } |
| 299 | BUG_ON(num != 0); |
| 300 | } |
| 301 | |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 302 | static void unmap_purged_grants(struct work_struct *work) |
| 303 | { |
| 304 | struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; |
| 305 | struct page *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST]; |
| 306 | struct persistent_gnt *persistent_gnt; |
| 307 | int ret, segs_to_unmap = 0; |
| 308 | struct xen_blkif *blkif = container_of(work, typeof(*blkif), persistent_purge_work); |
| 309 | |
| 310 | while(!list_empty(&blkif->persistent_purge_list)) { |
| 311 | persistent_gnt = list_first_entry(&blkif->persistent_purge_list, |
| 312 | struct persistent_gnt, |
| 313 | remove_node); |
| 314 | list_del(&persistent_gnt->remove_node); |
| 315 | |
| 316 | gnttab_set_unmap_op(&unmap[segs_to_unmap], |
| 317 | vaddr(persistent_gnt->page), |
| 318 | GNTMAP_host_map, |
| 319 | persistent_gnt->handle); |
| 320 | |
| 321 | pages[segs_to_unmap] = persistent_gnt->page; |
| 322 | |
| 323 | if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST) { |
| 324 | ret = gnttab_unmap_refs(unmap, NULL, pages, |
| 325 | segs_to_unmap); |
| 326 | BUG_ON(ret); |
| 327 | put_free_pages(blkif, pages, segs_to_unmap); |
| 328 | segs_to_unmap = 0; |
| 329 | } |
| 330 | kfree(persistent_gnt); |
| 331 | } |
| 332 | if (segs_to_unmap > 0) { |
| 333 | ret = gnttab_unmap_refs(unmap, NULL, pages, segs_to_unmap); |
| 334 | BUG_ON(ret); |
| 335 | put_free_pages(blkif, pages, segs_to_unmap); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | static void purge_persistent_gnt(struct xen_blkif *blkif) |
| 340 | { |
| 341 | struct persistent_gnt *persistent_gnt; |
| 342 | struct rb_node *n; |
| 343 | unsigned int num_clean, total; |
| 344 | bool scan_used = false; |
| 345 | struct rb_root *root; |
| 346 | |
| 347 | if (blkif->persistent_gnt_c < xen_blkif_max_pgrants || |
| 348 | (blkif->persistent_gnt_c == xen_blkif_max_pgrants && |
| 349 | !blkif->vbd.overflow_max_grants)) { |
| 350 | return; |
| 351 | } |
| 352 | |
| 353 | if (work_pending(&blkif->persistent_purge_work)) { |
| 354 | pr_alert_ratelimited(DRV_PFX "Scheduled work from previous purge is still pending, cannot purge list\n"); |
| 355 | return; |
| 356 | } |
| 357 | |
| 358 | num_clean = (xen_blkif_max_pgrants / 100) * LRU_PERCENT_CLEAN; |
| 359 | num_clean = blkif->persistent_gnt_c - xen_blkif_max_pgrants + num_clean; |
| 360 | num_clean = min(blkif->persistent_gnt_c, num_clean); |
| 361 | if (num_clean > |
| 362 | (blkif->persistent_gnt_c - |
| 363 | atomic_read(&blkif->persistent_gnt_in_use))) |
| 364 | return; |
| 365 | |
| 366 | /* |
| 367 | * At this point, we can assure that there will be no calls |
| 368 | * to get_persistent_grant (because we are executing this code from |
| 369 | * xen_blkif_schedule), there can only be calls to put_persistent_gnt, |
| 370 | * which means that the number of currently used grants will go down, |
| 371 | * but never up, so we will always be able to remove the requested |
| 372 | * number of grants. |
| 373 | */ |
| 374 | |
| 375 | total = num_clean; |
| 376 | |
| 377 | pr_debug(DRV_PFX "Going to purge %u persistent grants\n", num_clean); |
| 378 | |
| 379 | INIT_LIST_HEAD(&blkif->persistent_purge_list); |
| 380 | root = &blkif->persistent_gnts; |
| 381 | purge_list: |
| 382 | foreach_grant_safe(persistent_gnt, n, root, node) { |
| 383 | BUG_ON(persistent_gnt->handle == |
| 384 | BLKBACK_INVALID_HANDLE); |
| 385 | |
| 386 | if (test_bit(PERSISTENT_GNT_ACTIVE, persistent_gnt->flags)) |
| 387 | continue; |
| 388 | if (!scan_used && |
| 389 | (test_bit(PERSISTENT_GNT_WAS_ACTIVE, persistent_gnt->flags))) |
| 390 | continue; |
| 391 | |
| 392 | rb_erase(&persistent_gnt->node, root); |
| 393 | list_add(&persistent_gnt->remove_node, |
| 394 | &blkif->persistent_purge_list); |
| 395 | if (--num_clean == 0) |
| 396 | goto finished; |
| 397 | } |
| 398 | /* |
| 399 | * If we get here it means we also need to start cleaning |
| 400 | * grants that were used since last purge in order to cope |
| 401 | * with the requested num |
| 402 | */ |
| 403 | if (!scan_used) { |
| 404 | pr_debug(DRV_PFX "Still missing %u purged frames\n", num_clean); |
| 405 | scan_used = true; |
| 406 | goto purge_list; |
| 407 | } |
| 408 | finished: |
| 409 | /* Remove the "used" flag from all the persistent grants */ |
| 410 | foreach_grant_safe(persistent_gnt, n, root, node) { |
| 411 | BUG_ON(persistent_gnt->handle == |
| 412 | BLKBACK_INVALID_HANDLE); |
| 413 | clear_bit(PERSISTENT_GNT_WAS_ACTIVE, persistent_gnt->flags); |
| 414 | } |
| 415 | blkif->persistent_gnt_c -= (total - num_clean); |
| 416 | blkif->vbd.overflow_max_grants = 0; |
| 417 | |
| 418 | /* We can defer this work */ |
| 419 | INIT_WORK(&blkif->persistent_purge_work, unmap_purged_grants); |
| 420 | schedule_work(&blkif->persistent_purge_work); |
| 421 | pr_debug(DRV_PFX "Purged %u/%u\n", (total - num_clean), total); |
| 422 | return; |
| 423 | } |
| 424 | |
Konrad Rzeszutek Wilk | a1397fa | 2011-04-14 17:05:23 -0400 | [diff] [blame] | 425 | /* |
| 426 | * Retrieve from the 'pending_reqs' a free pending_req structure to be used. |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 427 | */ |
Roger Pau Monne | bf0720c | 2013-04-17 20:18:59 +0200 | [diff] [blame] | 428 | static struct pending_req *alloc_req(struct xen_blkif *blkif) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 429 | { |
Konrad Rzeszutek Wilk | 2e9977c | 2011-04-14 17:42:07 -0400 | [diff] [blame] | 430 | struct pending_req *req = NULL; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 431 | unsigned long flags; |
| 432 | |
Roger Pau Monne | bf0720c | 2013-04-17 20:18:59 +0200 | [diff] [blame] | 433 | spin_lock_irqsave(&blkif->pending_free_lock, flags); |
| 434 | if (!list_empty(&blkif->pending_free)) { |
| 435 | req = list_entry(blkif->pending_free.next, struct pending_req, |
Konrad Rzeszutek Wilk | 2e9977c | 2011-04-14 17:42:07 -0400 | [diff] [blame] | 436 | free_list); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 437 | list_del(&req->free_list); |
| 438 | } |
Roger Pau Monne | bf0720c | 2013-04-17 20:18:59 +0200 | [diff] [blame] | 439 | spin_unlock_irqrestore(&blkif->pending_free_lock, flags); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 440 | return req; |
| 441 | } |
| 442 | |
Konrad Rzeszutek Wilk | a1397fa | 2011-04-14 17:05:23 -0400 | [diff] [blame] | 443 | /* |
| 444 | * Return the 'pending_req' structure back to the freepool. We also |
| 445 | * wake up the thread if it was waiting for a free page. |
| 446 | */ |
Roger Pau Monne | bf0720c | 2013-04-17 20:18:59 +0200 | [diff] [blame] | 447 | static void free_req(struct xen_blkif *blkif, struct pending_req *req) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 448 | { |
| 449 | unsigned long flags; |
| 450 | int was_empty; |
| 451 | |
Roger Pau Monne | bf0720c | 2013-04-17 20:18:59 +0200 | [diff] [blame] | 452 | spin_lock_irqsave(&blkif->pending_free_lock, flags); |
| 453 | was_empty = list_empty(&blkif->pending_free); |
| 454 | list_add(&req->free_list, &blkif->pending_free); |
| 455 | spin_unlock_irqrestore(&blkif->pending_free_lock, flags); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 456 | if (was_empty) |
Roger Pau Monne | bf0720c | 2013-04-17 20:18:59 +0200 | [diff] [blame] | 457 | wake_up(&blkif->pending_free_wq); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 458 | } |
| 459 | |
Konrad Rzeszutek Wilk | a1397fa | 2011-04-14 17:05:23 -0400 | [diff] [blame] | 460 | /* |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 461 | * Routines for managing virtual block devices (vbds). |
| 462 | */ |
Konrad Rzeszutek Wilk | 3d81473 | 2011-05-12 16:53:56 -0400 | [diff] [blame] | 463 | static int xen_vbd_translate(struct phys_req *req, struct xen_blkif *blkif, |
| 464 | int operation) |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 465 | { |
Konrad Rzeszutek Wilk | 3d81473 | 2011-05-12 16:53:56 -0400 | [diff] [blame] | 466 | struct xen_vbd *vbd = &blkif->vbd; |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 467 | int rc = -EACCES; |
| 468 | |
| 469 | if ((operation != READ) && vbd->readonly) |
| 470 | goto out; |
| 471 | |
Jan Beulich | 8ab5215 | 2011-05-17 11:07:05 +0100 | [diff] [blame] | 472 | if (likely(req->nr_sects)) { |
| 473 | blkif_sector_t end = req->sector_number + req->nr_sects; |
| 474 | |
| 475 | if (unlikely(end < req->sector_number)) |
| 476 | goto out; |
| 477 | if (unlikely(end > vbd_sz(vbd))) |
| 478 | goto out; |
| 479 | } |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 480 | |
| 481 | req->dev = vbd->pdevice; |
| 482 | req->bdev = vbd->bdev; |
| 483 | rc = 0; |
| 484 | |
| 485 | out: |
| 486 | return rc; |
| 487 | } |
| 488 | |
Konrad Rzeszutek Wilk | 3d81473 | 2011-05-12 16:53:56 -0400 | [diff] [blame] | 489 | static void xen_vbd_resize(struct xen_blkif *blkif) |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 490 | { |
Konrad Rzeszutek Wilk | 3d81473 | 2011-05-12 16:53:56 -0400 | [diff] [blame] | 491 | struct xen_vbd *vbd = &blkif->vbd; |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 492 | struct xenbus_transaction xbt; |
| 493 | int err; |
Konrad Rzeszutek Wilk | 8b6bf74 | 2011-04-20 11:50:43 -0400 | [diff] [blame] | 494 | struct xenbus_device *dev = xen_blkbk_xenbus(blkif->be); |
Konrad Rzeszutek Wilk | 42c7841 | 2011-04-20 11:21:43 -0400 | [diff] [blame] | 495 | unsigned long long new_size = vbd_sz(vbd); |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 496 | |
Konrad Rzeszutek Wilk | 22b20f2 | 2011-05-12 16:43:12 -0400 | [diff] [blame] | 497 | pr_info(DRV_PFX "VBD Resize: Domid: %d, Device: (%d, %d)\n", |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 498 | blkif->domid, MAJOR(vbd->pdevice), MINOR(vbd->pdevice)); |
Konrad Rzeszutek Wilk | 22b20f2 | 2011-05-12 16:43:12 -0400 | [diff] [blame] | 499 | pr_info(DRV_PFX "VBD Resize: new size %llu\n", new_size); |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 500 | vbd->size = new_size; |
| 501 | again: |
| 502 | err = xenbus_transaction_start(&xbt); |
| 503 | if (err) { |
Konrad Rzeszutek Wilk | 22b20f2 | 2011-05-12 16:43:12 -0400 | [diff] [blame] | 504 | pr_warn(DRV_PFX "Error starting transaction"); |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 505 | return; |
| 506 | } |
| 507 | err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu", |
Konrad Rzeszutek Wilk | 42c7841 | 2011-04-20 11:21:43 -0400 | [diff] [blame] | 508 | (unsigned long long)vbd_sz(vbd)); |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 509 | if (err) { |
Konrad Rzeszutek Wilk | 22b20f2 | 2011-05-12 16:43:12 -0400 | [diff] [blame] | 510 | pr_warn(DRV_PFX "Error writing new size"); |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 511 | goto abort; |
| 512 | } |
| 513 | /* |
| 514 | * Write the current state; we will use this to synchronize |
| 515 | * the front-end. If the current state is "connected" the |
| 516 | * front-end will get the new size information online. |
| 517 | */ |
| 518 | err = xenbus_printf(xbt, dev->nodename, "state", "%d", dev->state); |
| 519 | if (err) { |
Konrad Rzeszutek Wilk | 22b20f2 | 2011-05-12 16:43:12 -0400 | [diff] [blame] | 520 | pr_warn(DRV_PFX "Error writing the state"); |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 521 | goto abort; |
| 522 | } |
| 523 | |
| 524 | err = xenbus_transaction_end(xbt, 0); |
| 525 | if (err == -EAGAIN) |
| 526 | goto again; |
| 527 | if (err) |
Konrad Rzeszutek Wilk | 22b20f2 | 2011-05-12 16:43:12 -0400 | [diff] [blame] | 528 | pr_warn(DRV_PFX "Error ending transaction"); |
Laszlo Ersek | 496b318 | 2011-05-13 09:45:40 -0400 | [diff] [blame] | 529 | return; |
Konrad Rzeszutek Wilk | ee9ff85 | 2011-04-20 10:57:29 -0400 | [diff] [blame] | 530 | abort: |
| 531 | xenbus_transaction_end(xbt, 1); |
| 532 | } |
| 533 | |
| 534 | /* |
Konrad Rzeszutek Wilk | b0aef17 | 2011-04-15 10:58:05 -0400 | [diff] [blame] | 535 | * Notification from the guest OS. |
| 536 | */ |
Konrad Rzeszutek Wilk | 30fd150 | 2011-05-12 16:47:48 -0400 | [diff] [blame] | 537 | static void blkif_notify_work(struct xen_blkif *blkif) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 538 | { |
Konrad Rzeszutek Wilk | b0aef17 | 2011-04-15 10:58:05 -0400 | [diff] [blame] | 539 | blkif->waiting_reqs = 1; |
| 540 | wake_up(&blkif->wq); |
| 541 | } |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 542 | |
Konrad Rzeszutek Wilk | 8b6bf74 | 2011-04-20 11:50:43 -0400 | [diff] [blame] | 543 | irqreturn_t xen_blkif_be_int(int irq, void *dev_id) |
Konrad Rzeszutek Wilk | b0aef17 | 2011-04-15 10:58:05 -0400 | [diff] [blame] | 544 | { |
| 545 | blkif_notify_work(dev_id); |
| 546 | return IRQ_HANDLED; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 547 | } |
| 548 | |
Konrad Rzeszutek Wilk | 2e9977c | 2011-04-14 17:42:07 -0400 | [diff] [blame] | 549 | /* |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 550 | * SCHEDULER FUNCTIONS |
| 551 | */ |
| 552 | |
Konrad Rzeszutek Wilk | 30fd150 | 2011-05-12 16:47:48 -0400 | [diff] [blame] | 553 | static void print_stats(struct xen_blkif *blkif) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 554 | { |
Zoltan Kiss | 986cacb | 2013-03-11 16:15:50 +0000 | [diff] [blame] | 555 | pr_info("xen-blkback (%s): oo %3llu | rd %4llu | wr %4llu | f %4llu" |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 556 | " | ds %4llu | pg: %4u/%4d\n", |
Konrad Rzeszutek Wilk | ebe8190 | 2011-05-12 16:42:31 -0400 | [diff] [blame] | 557 | current->comm, blkif->st_oo_req, |
Li Dongyang | b3cb0d6 | 2011-09-01 18:39:10 +0800 | [diff] [blame] | 558 | blkif->st_rd_req, blkif->st_wr_req, |
Roger Pau Monne | c1a15d0 | 2013-04-17 20:18:55 +0200 | [diff] [blame] | 559 | blkif->st_f_req, blkif->st_ds_req, |
| 560 | blkif->persistent_gnt_c, |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 561 | xen_blkif_max_pgrants); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 562 | blkif->st_print = jiffies + msecs_to_jiffies(10 * 1000); |
| 563 | blkif->st_rd_req = 0; |
| 564 | blkif->st_wr_req = 0; |
| 565 | blkif->st_oo_req = 0; |
Li Dongyang | b3cb0d6 | 2011-09-01 18:39:10 +0800 | [diff] [blame] | 566 | blkif->st_ds_req = 0; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 567 | } |
| 568 | |
Konrad Rzeszutek Wilk | 8b6bf74 | 2011-04-20 11:50:43 -0400 | [diff] [blame] | 569 | int xen_blkif_schedule(void *arg) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 570 | { |
Konrad Rzeszutek Wilk | 30fd150 | 2011-05-12 16:47:48 -0400 | [diff] [blame] | 571 | struct xen_blkif *blkif = arg; |
Konrad Rzeszutek Wilk | 3d81473 | 2011-05-12 16:53:56 -0400 | [diff] [blame] | 572 | struct xen_vbd *vbd = &blkif->vbd; |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 573 | unsigned long timeout; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 574 | |
Konrad Rzeszutek Wilk | 8b6bf74 | 2011-04-20 11:50:43 -0400 | [diff] [blame] | 575 | xen_blkif_get(blkif); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 576 | |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 577 | while (!kthread_should_stop()) { |
| 578 | if (try_to_freeze()) |
| 579 | continue; |
Konrad Rzeszutek Wilk | 42c7841 | 2011-04-20 11:21:43 -0400 | [diff] [blame] | 580 | if (unlikely(vbd->size != vbd_sz(vbd))) |
Konrad Rzeszutek Wilk | 3d81473 | 2011-05-12 16:53:56 -0400 | [diff] [blame] | 581 | xen_vbd_resize(blkif); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 582 | |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 583 | timeout = msecs_to_jiffies(LRU_INTERVAL); |
| 584 | |
| 585 | timeout = wait_event_interruptible_timeout( |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 586 | blkif->wq, |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 587 | blkif->waiting_reqs || kthread_should_stop(), |
| 588 | timeout); |
| 589 | if (timeout == 0) |
| 590 | goto purge_gnt_list; |
| 591 | timeout = wait_event_interruptible_timeout( |
Roger Pau Monne | bf0720c | 2013-04-17 20:18:59 +0200 | [diff] [blame] | 592 | blkif->pending_free_wq, |
| 593 | !list_empty(&blkif->pending_free) || |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 594 | kthread_should_stop(), |
| 595 | timeout); |
| 596 | if (timeout == 0) |
| 597 | goto purge_gnt_list; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 598 | |
| 599 | blkif->waiting_reqs = 0; |
| 600 | smp_mb(); /* clear flag *before* checking for work */ |
| 601 | |
| 602 | if (do_block_io_op(blkif)) |
| 603 | blkif->waiting_reqs = 1; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 604 | |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 605 | purge_gnt_list: |
| 606 | if (blkif->vbd.feature_gnt_persistent && |
| 607 | time_after(jiffies, blkif->next_lru)) { |
| 608 | purge_persistent_gnt(blkif); |
| 609 | blkif->next_lru = jiffies + msecs_to_jiffies(LRU_INTERVAL); |
| 610 | } |
| 611 | |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 612 | /* Shrink if we have more than xen_blkif_max_buffer_pages */ |
| 613 | shrink_free_pagepool(blkif, xen_blkif_max_buffer_pages); |
| 614 | |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 615 | if (log_stats && time_after(jiffies, blkif->st_print)) |
| 616 | print_stats(blkif); |
| 617 | } |
| 618 | |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 619 | /* Since we are shutting down remove all pages from the buffer */ |
| 620 | shrink_free_pagepool(blkif, 0 /* All */); |
| 621 | |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 622 | /* Free all persistent grant pages */ |
Roger Pau Monne | 4d4f270 | 2012-11-16 19:26:48 +0100 | [diff] [blame] | 623 | if (!RB_EMPTY_ROOT(&blkif->persistent_gnts)) |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 624 | free_persistent_gnts(blkif, &blkif->persistent_gnts, |
Roger Pau Monne | 4d4f270 | 2012-11-16 19:26:48 +0100 | [diff] [blame] | 625 | blkif->persistent_gnt_c); |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 626 | |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 627 | BUG_ON(!RB_EMPTY_ROOT(&blkif->persistent_gnts)); |
Roger Pau Monne | 4d4f270 | 2012-11-16 19:26:48 +0100 | [diff] [blame] | 628 | blkif->persistent_gnt_c = 0; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 629 | |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 630 | if (log_stats) |
| 631 | print_stats(blkif); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 632 | |
| 633 | blkif->xenblkd = NULL; |
Konrad Rzeszutek Wilk | 8b6bf74 | 2011-04-20 11:50:43 -0400 | [diff] [blame] | 634 | xen_blkif_put(blkif); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 635 | |
| 636 | return 0; |
| 637 | } |
| 638 | |
Konrad Rzeszutek Wilk | a1397fa | 2011-04-14 17:05:23 -0400 | [diff] [blame] | 639 | /* |
Konrad Rzeszutek Wilk | b0aef17 | 2011-04-15 10:58:05 -0400 | [diff] [blame] | 640 | * Unmap the grant references, and also remove the M2P over-rides |
| 641 | * used in the 'pending_req'. |
Konrad Rzeszutek Wilk | 01f37f2 | 2011-05-11 15:57:09 -0400 | [diff] [blame] | 642 | */ |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 643 | static void xen_blkbk_unmap(struct xen_blkif *blkif, |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 644 | struct grant_page *pages[], |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 645 | int num) |
Konrad Rzeszutek Wilk | b0aef17 | 2011-04-15 10:58:05 -0400 | [diff] [blame] | 646 | { |
| 647 | struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST]; |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 648 | struct page *unmap_pages[BLKIF_MAX_SEGMENTS_PER_REQUEST]; |
Konrad Rzeszutek Wilk | b0aef17 | 2011-04-15 10:58:05 -0400 | [diff] [blame] | 649 | unsigned int i, invcount = 0; |
Konrad Rzeszutek Wilk | b0aef17 | 2011-04-15 10:58:05 -0400 | [diff] [blame] | 650 | int ret; |
| 651 | |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 652 | for (i = 0; i < num; i++) { |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 653 | if (pages[i]->persistent_gnt != NULL) { |
| 654 | put_persistent_gnt(blkif, pages[i]->persistent_gnt); |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 655 | continue; |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 656 | } |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 657 | if (pages[i]->handle == BLKBACK_INVALID_HANDLE) |
Konrad Rzeszutek Wilk | b0aef17 | 2011-04-15 10:58:05 -0400 | [diff] [blame] | 658 | continue; |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 659 | unmap_pages[invcount] = pages[i]->page; |
| 660 | gnttab_set_unmap_op(&unmap[invcount], vaddr(pages[i]->page), |
| 661 | GNTMAP_host_map, pages[i]->handle); |
| 662 | pages[i]->handle = BLKBACK_INVALID_HANDLE; |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 663 | if (++invcount == BLKIF_MAX_SEGMENTS_PER_REQUEST) { |
| 664 | ret = gnttab_unmap_refs(unmap, NULL, unmap_pages, |
| 665 | invcount); |
| 666 | BUG_ON(ret); |
| 667 | put_free_pages(blkif, unmap_pages, invcount); |
| 668 | invcount = 0; |
| 669 | } |
Konrad Rzeszutek Wilk | b0aef17 | 2011-04-15 10:58:05 -0400 | [diff] [blame] | 670 | } |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 671 | if (invcount) { |
| 672 | ret = gnttab_unmap_refs(unmap, NULL, unmap_pages, invcount); |
| 673 | BUG_ON(ret); |
| 674 | put_free_pages(blkif, unmap_pages, invcount); |
| 675 | } |
Konrad Rzeszutek Wilk | b0aef17 | 2011-04-15 10:58:05 -0400 | [diff] [blame] | 676 | } |
Konrad Rzeszutek Wilk | 01f37f2 | 2011-05-11 15:57:09 -0400 | [diff] [blame] | 677 | |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 678 | static int xen_blkbk_map(struct xen_blkif *blkif, |
| 679 | struct grant_page *pages[], |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 680 | int num, bool ro) |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 681 | { |
| 682 | struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST]; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 683 | struct page *pages_to_gnt[BLKIF_MAX_SEGMENTS_PER_REQUEST]; |
| 684 | struct persistent_gnt *persistent_gnt = NULL; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 685 | phys_addr_t addr = 0; |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 686 | int i, seg_idx, new_map_idx; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 687 | int segs_to_map = 0; |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 688 | int ret = 0; |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 689 | int last_map = 0, map_until = 0; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 690 | int use_persistent_gnts; |
| 691 | |
| 692 | use_persistent_gnts = (blkif->vbd.feature_gnt_persistent); |
| 693 | |
Konrad Rzeszutek Wilk | 01f37f2 | 2011-05-11 15:57:09 -0400 | [diff] [blame] | 694 | /* |
| 695 | * Fill out preq.nr_sects with proper amount of sectors, and setup |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 696 | * assign map[..] with the PFN of the page in our domain with the |
| 697 | * corresponding grant reference for each page. |
| 698 | */ |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 699 | again: |
| 700 | for (i = map_until; i < num; i++) { |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 701 | uint32_t flags; |
| 702 | |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 703 | if (use_persistent_gnts) |
| 704 | persistent_gnt = get_persistent_gnt( |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 705 | blkif, |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 706 | pages[i]->gref); |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 707 | |
| 708 | if (persistent_gnt) { |
| 709 | /* |
| 710 | * We are using persistent grants and |
| 711 | * the grant is already mapped |
| 712 | */ |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 713 | pages[i]->page = persistent_gnt->page; |
| 714 | pages[i]->persistent_gnt = persistent_gnt; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 715 | } else { |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 716 | if (get_free_page(blkif, &pages[i]->page)) |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 717 | goto out_of_memory; |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 718 | addr = vaddr(pages[i]->page); |
| 719 | pages_to_gnt[segs_to_map] = pages[i]->page; |
| 720 | pages[i]->persistent_gnt = NULL; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 721 | flags = GNTMAP_host_map; |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 722 | if (!use_persistent_gnts && ro) |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 723 | flags |= GNTMAP_readonly; |
| 724 | gnttab_set_map_op(&map[segs_to_map++], addr, |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 725 | flags, pages[i]->gref, |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 726 | blkif->domid); |
| 727 | } |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 728 | map_until = i + 1; |
| 729 | if (segs_to_map == BLKIF_MAX_SEGMENTS_PER_REQUEST) |
| 730 | break; |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 731 | } |
| 732 | |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 733 | if (segs_to_map) { |
| 734 | ret = gnttab_map_refs(map, NULL, pages_to_gnt, segs_to_map); |
| 735 | BUG_ON(ret); |
| 736 | } |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 737 | |
Konrad Rzeszutek Wilk | 01f37f2 | 2011-05-11 15:57:09 -0400 | [diff] [blame] | 738 | /* |
| 739 | * Now swizzle the MFN in our domain with the MFN from the other domain |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 740 | * so that when we access vaddr(pending_req,i) it has the contents of |
| 741 | * the page from the other domain. |
| 742 | */ |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 743 | for (seg_idx = last_map, new_map_idx = 0; seg_idx < map_until; seg_idx++) { |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 744 | if (!pages[seg_idx]->persistent_gnt) { |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 745 | /* This is a newly mapped grant */ |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 746 | BUG_ON(new_map_idx >= segs_to_map); |
| 747 | if (unlikely(map[new_map_idx].status != 0)) { |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 748 | pr_debug(DRV_PFX "invalid buffer -- could not remap it\n"); |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 749 | pages[seg_idx]->handle = BLKBACK_INVALID_HANDLE; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 750 | ret |= 1; |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 751 | goto next; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 752 | } |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 753 | pages[seg_idx]->handle = map[new_map_idx].handle; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 754 | } else { |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 755 | continue; |
Roger Pau Monne | 0a8704a | 2012-10-24 18:58:45 +0200 | [diff] [blame] | 756 | } |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 757 | if (use_persistent_gnts && |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 758 | blkif->persistent_gnt_c < xen_blkif_max_pgrants) { |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 759 | /* |
| 760 | * We are using persistent grants, the grant is |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 761 | * not mapped but we might have room for it. |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 762 | */ |
| 763 | persistent_gnt = kmalloc(sizeof(struct persistent_gnt), |
| 764 | GFP_KERNEL); |
| 765 | if (!persistent_gnt) { |
| 766 | /* |
| 767 | * If we don't have enough memory to |
| 768 | * allocate the persistent_gnt struct |
| 769 | * map this grant non-persistenly |
| 770 | */ |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 771 | goto next; |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 772 | } |
| 773 | persistent_gnt->gnt = map[new_map_idx].ref; |
| 774 | persistent_gnt->handle = map[new_map_idx].handle; |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 775 | persistent_gnt->page = pages[seg_idx]->page; |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 776 | if (add_persistent_gnt(blkif, |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 777 | persistent_gnt)) { |
| 778 | kfree(persistent_gnt); |
| 779 | persistent_gnt = NULL; |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 780 | goto next; |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 781 | } |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 782 | pages[seg_idx]->persistent_gnt = persistent_gnt; |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 783 | pr_debug(DRV_PFX " grant %u added to the tree of persistent grants, using %u/%u\n", |
| 784 | persistent_gnt->gnt, blkif->persistent_gnt_c, |
Roger Pau Monne | 3f3aad5 | 2013-04-17 20:18:57 +0200 | [diff] [blame] | 785 | xen_blkif_max_pgrants); |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 786 | goto next; |
| 787 | } |
| 788 | if (use_persistent_gnts && !blkif->vbd.overflow_max_grants) { |
| 789 | blkif->vbd.overflow_max_grants = 1; |
| 790 | pr_debug(DRV_PFX " domain %u, device %#x is using maximum number of persistent grants\n", |
| 791 | blkif->domid, blkif->vbd.handle); |
| 792 | } |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 793 | /* |
| 794 | * We could not map this grant persistently, so use it as |
| 795 | * a non-persistent grant. |
| 796 | */ |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 797 | next: |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 798 | new_map_idx++; |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 799 | } |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 800 | segs_to_map = 0; |
| 801 | last_map = map_until; |
| 802 | if (map_until != num) |
| 803 | goto again; |
| 804 | |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 805 | return ret; |
Roger Pau Monne | c6cc142 | 2013-04-17 20:18:56 +0200 | [diff] [blame] | 806 | |
| 807 | out_of_memory: |
| 808 | pr_alert(DRV_PFX "%s: out of memory\n", __func__); |
| 809 | put_free_pages(blkif, pages_to_gnt, segs_to_map); |
| 810 | return -ENOMEM; |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 811 | } |
| 812 | |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 813 | static int xen_blkbk_map_seg(struct pending_req *pending_req) |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 814 | { |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 815 | int rc; |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 816 | |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 817 | rc = xen_blkbk_map(pending_req->blkif, pending_req->segments, |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 818 | pending_req->nr_pages, |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 819 | (pending_req->operation != BLKIF_OP_READ)); |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 820 | |
| 821 | return rc; |
| 822 | } |
| 823 | |
| 824 | static int xen_blkbk_parse_indirect(struct blkif_request *req, |
| 825 | struct pending_req *pending_req, |
| 826 | struct seg_buf seg[], |
| 827 | struct phys_req *preq) |
| 828 | { |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 829 | struct grant_page **pages = pending_req->indirect_pages; |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 830 | struct xen_blkif *blkif = pending_req->blkif; |
| 831 | int indirect_grefs, rc, n, nseg, i; |
| 832 | struct blkif_request_segment_aligned *segments = NULL; |
| 833 | |
| 834 | nseg = pending_req->nr_pages; |
| 835 | indirect_grefs = INDIRECT_PAGES(nseg); |
| 836 | BUG_ON(indirect_grefs > BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST); |
| 837 | |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 838 | for (i = 0; i < indirect_grefs; i++) |
| 839 | pages[i]->gref = req->u.indirect.indirect_grefs[i]; |
| 840 | |
| 841 | rc = xen_blkbk_map(blkif, pages, indirect_grefs, true); |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 842 | if (rc) |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 843 | goto unmap; |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 844 | |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 845 | for (n = 0, i = 0; n < nseg; n++) { |
| 846 | if ((n % SEGS_PER_INDIRECT_FRAME) == 0) { |
| 847 | /* Map indirect segments */ |
| 848 | if (segments) |
| 849 | kunmap_atomic(segments); |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 850 | segments = kmap_atomic(pages[n/SEGS_PER_INDIRECT_FRAME]->page); |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 851 | } |
| 852 | i = n % SEGS_PER_INDIRECT_FRAME; |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 853 | pending_req->segments[n]->gref = segments[i].gref; |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 854 | seg[n].nsec = segments[i].last_sect - |
| 855 | segments[i].first_sect + 1; |
| 856 | seg[n].offset = (segments[i].first_sect << 9); |
| 857 | if ((segments[i].last_sect >= (PAGE_SIZE >> 9)) || |
| 858 | (segments[i].last_sect < segments[i].first_sect)) { |
| 859 | rc = -EINVAL; |
| 860 | goto unmap; |
| 861 | } |
| 862 | preq->nr_sects += seg[n].nsec; |
| 863 | } |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 864 | |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 865 | unmap: |
| 866 | if (segments) |
| 867 | kunmap_atomic(segments); |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 868 | xen_blkbk_unmap(blkif, pages, indirect_grefs); |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 869 | return rc; |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 870 | } |
| 871 | |
Konrad Rzeszutek Wilk | 4214635 | 2011-10-12 17:26:47 -0400 | [diff] [blame] | 872 | static int dispatch_discard_io(struct xen_blkif *blkif, |
| 873 | struct blkif_request *req) |
Li Dongyang | b3cb0d6 | 2011-09-01 18:39:10 +0800 | [diff] [blame] | 874 | { |
| 875 | int err = 0; |
| 876 | int status = BLKIF_RSP_OKAY; |
| 877 | struct block_device *bdev = blkif->vbd.bdev; |
Konrad Rzeszutek Wilk | 4dae767 | 2012-03-13 18:43:23 -0400 | [diff] [blame] | 878 | unsigned long secure; |
Li Dongyang | b3cb0d6 | 2011-09-01 18:39:10 +0800 | [diff] [blame] | 879 | |
Konrad Rzeszutek Wilk | 4214635 | 2011-10-12 17:26:47 -0400 | [diff] [blame] | 880 | blkif->st_ds_req++; |
| 881 | |
| 882 | xen_blkif_get(blkif); |
Konrad Rzeszutek Wilk | 4dae767 | 2012-03-13 18:43:23 -0400 | [diff] [blame] | 883 | secure = (blkif->vbd.discard_secure && |
| 884 | (req->u.discard.flag & BLKIF_DISCARD_SECURE)) ? |
| 885 | BLKDEV_DISCARD_SECURE : 0; |
| 886 | |
| 887 | err = blkdev_issue_discard(bdev, req->u.discard.sector_number, |
| 888 | req->u.discard.nr_sectors, |
| 889 | GFP_KERNEL, secure); |
Li Dongyang | b3cb0d6 | 2011-09-01 18:39:10 +0800 | [diff] [blame] | 890 | |
| 891 | if (err == -EOPNOTSUPP) { |
| 892 | pr_debug(DRV_PFX "discard op failed, not supported\n"); |
| 893 | status = BLKIF_RSP_EOPNOTSUPP; |
| 894 | } else if (err) |
| 895 | status = BLKIF_RSP_ERROR; |
| 896 | |
Konrad Rzeszutek Wilk | 97e3683 | 2011-10-12 12:12:36 -0400 | [diff] [blame] | 897 | make_response(blkif, req->u.discard.id, req->operation, status); |
Konrad Rzeszutek Wilk | 4214635 | 2011-10-12 17:26:47 -0400 | [diff] [blame] | 898 | xen_blkif_put(blkif); |
| 899 | return err; |
Li Dongyang | b3cb0d6 | 2011-09-01 18:39:10 +0800 | [diff] [blame] | 900 | } |
| 901 | |
David Vrabel | 0e367ae | 2013-03-07 17:32:01 +0000 | [diff] [blame] | 902 | static int dispatch_other_io(struct xen_blkif *blkif, |
| 903 | struct blkif_request *req, |
| 904 | struct pending_req *pending_req) |
| 905 | { |
Roger Pau Monne | bf0720c | 2013-04-17 20:18:59 +0200 | [diff] [blame] | 906 | free_req(blkif, pending_req); |
David Vrabel | 0e367ae | 2013-03-07 17:32:01 +0000 | [diff] [blame] | 907 | make_response(blkif, req->u.other.id, req->operation, |
| 908 | BLKIF_RSP_EOPNOTSUPP); |
| 909 | return -EIO; |
| 910 | } |
| 911 | |
Konrad Rzeszutek Wilk | 29bde09 | 2011-10-10 00:42:22 -0400 | [diff] [blame] | 912 | static void xen_blk_drain_io(struct xen_blkif *blkif) |
| 913 | { |
| 914 | atomic_set(&blkif->drain, 1); |
| 915 | do { |
Konrad Rzeszutek Wilk | 6927d92 | 2011-10-17 14:27:48 -0400 | [diff] [blame] | 916 | /* The initial value is one, and one refcnt taken at the |
| 917 | * start of the xen_blkif_schedule thread. */ |
| 918 | if (atomic_read(&blkif->refcnt) <= 2) |
| 919 | break; |
Konrad Rzeszutek Wilk | 29bde09 | 2011-10-10 00:42:22 -0400 | [diff] [blame] | 920 | wait_for_completion_interruptible_timeout( |
| 921 | &blkif->drain_complete, HZ); |
| 922 | |
| 923 | if (!atomic_read(&blkif->drain)) |
| 924 | break; |
Konrad Rzeszutek Wilk | 29bde09 | 2011-10-10 00:42:22 -0400 | [diff] [blame] | 925 | } while (!kthread_should_stop()); |
| 926 | atomic_set(&blkif->drain, 0); |
| 927 | } |
| 928 | |
Konrad Rzeszutek Wilk | b0aef17 | 2011-04-15 10:58:05 -0400 | [diff] [blame] | 929 | /* |
Konrad Rzeszutek Wilk | a1397fa | 2011-04-14 17:05:23 -0400 | [diff] [blame] | 930 | * Completion callback on the bio's. Called as bh->b_end_io() |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 931 | */ |
| 932 | |
Konrad Rzeszutek Wilk | 2e9977c | 2011-04-14 17:42:07 -0400 | [diff] [blame] | 933 | static void __end_block_io_op(struct pending_req *pending_req, int error) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 934 | { |
| 935 | /* An error fails the entire request. */ |
Konrad Rzeszutek Wilk | 24f567f | 2011-05-04 17:07:27 -0400 | [diff] [blame] | 936 | if ((pending_req->operation == BLKIF_OP_FLUSH_DISKCACHE) && |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 937 | (error == -EOPNOTSUPP)) { |
Konrad Rzeszutek Wilk | 22b20f2 | 2011-05-12 16:43:12 -0400 | [diff] [blame] | 938 | pr_debug(DRV_PFX "flush diskcache op failed, not supported\n"); |
Konrad Rzeszutek Wilk | 24f567f | 2011-05-04 17:07:27 -0400 | [diff] [blame] | 939 | xen_blkbk_flush_diskcache(XBT_NIL, pending_req->blkif->be, 0); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 940 | pending_req->status = BLKIF_RSP_EOPNOTSUPP; |
Konrad Rzeszutek Wilk | 29bde09 | 2011-10-10 00:42:22 -0400 | [diff] [blame] | 941 | } else if ((pending_req->operation == BLKIF_OP_WRITE_BARRIER) && |
| 942 | (error == -EOPNOTSUPP)) { |
| 943 | pr_debug(DRV_PFX "write barrier op failed, not supported\n"); |
| 944 | xen_blkbk_barrier(XBT_NIL, pending_req->blkif->be, 0); |
| 945 | pending_req->status = BLKIF_RSP_EOPNOTSUPP; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 946 | } else if (error) { |
Konrad Rzeszutek Wilk | 22b20f2 | 2011-05-12 16:43:12 -0400 | [diff] [blame] | 947 | pr_debug(DRV_PFX "Buffer not up-to-date at end of operation," |
Konrad Rzeszutek Wilk | ebe8190 | 2011-05-12 16:42:31 -0400 | [diff] [blame] | 948 | " error=%d\n", error); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 949 | pending_req->status = BLKIF_RSP_ERROR; |
| 950 | } |
| 951 | |
Konrad Rzeszutek Wilk | 01f37f2 | 2011-05-11 15:57:09 -0400 | [diff] [blame] | 952 | /* |
| 953 | * If all of the bio's have completed it is time to unmap |
Konrad Rzeszutek Wilk | a1397fa | 2011-04-14 17:05:23 -0400 | [diff] [blame] | 954 | * the grant references associated with 'request' and provide |
Konrad Rzeszutek Wilk | 2e9977c | 2011-04-14 17:42:07 -0400 | [diff] [blame] | 955 | * the proper response on the ring. |
| 956 | */ |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 957 | if (atomic_dec_and_test(&pending_req->pendcnt)) { |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 958 | xen_blkbk_unmap(pending_req->blkif, |
| 959 | pending_req->segments, |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 960 | pending_req->nr_pages); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 961 | make_response(pending_req->blkif, pending_req->id, |
| 962 | pending_req->operation, pending_req->status); |
Konrad Rzeszutek Wilk | 8b6bf74 | 2011-04-20 11:50:43 -0400 | [diff] [blame] | 963 | xen_blkif_put(pending_req->blkif); |
Konrad Rzeszutek Wilk | 29bde09 | 2011-10-10 00:42:22 -0400 | [diff] [blame] | 964 | if (atomic_read(&pending_req->blkif->refcnt) <= 2) { |
| 965 | if (atomic_read(&pending_req->blkif->drain)) |
| 966 | complete(&pending_req->blkif->drain_complete); |
| 967 | } |
Roger Pau Monne | bf0720c | 2013-04-17 20:18:59 +0200 | [diff] [blame] | 968 | free_req(pending_req->blkif, pending_req); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 969 | } |
| 970 | } |
| 971 | |
Konrad Rzeszutek Wilk | a1397fa | 2011-04-14 17:05:23 -0400 | [diff] [blame] | 972 | /* |
| 973 | * bio callback. |
| 974 | */ |
Jeremy Fitzhardinge | 8812293 | 2009-02-09 12:05:51 -0800 | [diff] [blame] | 975 | static void end_block_io_op(struct bio *bio, int error) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 976 | { |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 977 | __end_block_io_op(bio->bi_private, error); |
| 978 | bio_put(bio); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 982 | |
Konrad Rzeszutek Wilk | a1397fa | 2011-04-14 17:05:23 -0400 | [diff] [blame] | 983 | /* |
| 984 | * Function to copy the from the ring buffer the 'struct blkif_request' |
| 985 | * (which has the sectors we want, number of them, grant references, etc), |
| 986 | * and transmute it to the block API to hand it over to the proper block disk. |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 987 | */ |
Daniel Stodden | b4726a9 | 2011-05-28 13:21:10 -0700 | [diff] [blame] | 988 | static int |
| 989 | __do_block_io_op(struct xen_blkif *blkif) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 990 | { |
Jeremy Fitzhardinge | 8812293 | 2009-02-09 12:05:51 -0800 | [diff] [blame] | 991 | union blkif_back_rings *blk_rings = &blkif->blk_rings; |
| 992 | struct blkif_request req; |
Konrad Rzeszutek Wilk | 2e9977c | 2011-04-14 17:42:07 -0400 | [diff] [blame] | 993 | struct pending_req *pending_req; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 994 | RING_IDX rc, rp; |
| 995 | int more_to_do = 0; |
| 996 | |
| 997 | rc = blk_rings->common.req_cons; |
| 998 | rp = blk_rings->common.sring->req_prod; |
| 999 | rmb(); /* Ensure we see queued requests up to 'rp'. */ |
| 1000 | |
| 1001 | while (rc != rp) { |
| 1002 | |
| 1003 | if (RING_REQUEST_CONS_OVERFLOW(&blk_rings->common, rc)) |
| 1004 | break; |
| 1005 | |
Keir Fraser | 8270b45 | 2009-03-06 08:29:15 +0000 | [diff] [blame] | 1006 | if (kthread_should_stop()) { |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1007 | more_to_do = 1; |
| 1008 | break; |
| 1009 | } |
| 1010 | |
Roger Pau Monne | bf0720c | 2013-04-17 20:18:59 +0200 | [diff] [blame] | 1011 | pending_req = alloc_req(blkif); |
Keir Fraser | 8270b45 | 2009-03-06 08:29:15 +0000 | [diff] [blame] | 1012 | if (NULL == pending_req) { |
| 1013 | blkif->st_oo_req++; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1014 | more_to_do = 1; |
| 1015 | break; |
| 1016 | } |
| 1017 | |
| 1018 | switch (blkif->blk_protocol) { |
| 1019 | case BLKIF_PROTOCOL_NATIVE: |
| 1020 | memcpy(&req, RING_GET_REQUEST(&blk_rings->native, rc), sizeof(req)); |
| 1021 | break; |
| 1022 | case BLKIF_PROTOCOL_X86_32: |
| 1023 | blkif_get_x86_32_req(&req, RING_GET_REQUEST(&blk_rings->x86_32, rc)); |
| 1024 | break; |
| 1025 | case BLKIF_PROTOCOL_X86_64: |
| 1026 | blkif_get_x86_64_req(&req, RING_GET_REQUEST(&blk_rings->x86_64, rc)); |
| 1027 | break; |
| 1028 | default: |
| 1029 | BUG(); |
| 1030 | } |
| 1031 | blk_rings->common.req_cons = ++rc; /* before make_response() */ |
| 1032 | |
| 1033 | /* Apply all sanity checks to /private copy/ of request. */ |
| 1034 | barrier(); |
David Vrabel | 0e367ae | 2013-03-07 17:32:01 +0000 | [diff] [blame] | 1035 | |
| 1036 | switch (req.operation) { |
| 1037 | case BLKIF_OP_READ: |
| 1038 | case BLKIF_OP_WRITE: |
| 1039 | case BLKIF_OP_WRITE_BARRIER: |
| 1040 | case BLKIF_OP_FLUSH_DISKCACHE: |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 1041 | case BLKIF_OP_INDIRECT: |
David Vrabel | 0e367ae | 2013-03-07 17:32:01 +0000 | [diff] [blame] | 1042 | if (dispatch_rw_block_io(blkif, &req, pending_req)) |
| 1043 | goto done; |
| 1044 | break; |
| 1045 | case BLKIF_OP_DISCARD: |
Roger Pau Monne | bf0720c | 2013-04-17 20:18:59 +0200 | [diff] [blame] | 1046 | free_req(blkif, pending_req); |
Konrad Rzeszutek Wilk | 4214635 | 2011-10-12 17:26:47 -0400 | [diff] [blame] | 1047 | if (dispatch_discard_io(blkif, &req)) |
David Vrabel | 0e367ae | 2013-03-07 17:32:01 +0000 | [diff] [blame] | 1048 | goto done; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1049 | break; |
David Vrabel | 0e367ae | 2013-03-07 17:32:01 +0000 | [diff] [blame] | 1050 | default: |
| 1051 | if (dispatch_other_io(blkif, &req, pending_req)) |
| 1052 | goto done; |
| 1053 | break; |
| 1054 | } |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1055 | |
| 1056 | /* Yield point for this unbounded loop. */ |
| 1057 | cond_resched(); |
| 1058 | } |
David Vrabel | 0e367ae | 2013-03-07 17:32:01 +0000 | [diff] [blame] | 1059 | done: |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1060 | return more_to_do; |
| 1061 | } |
| 1062 | |
Daniel Stodden | b4726a9 | 2011-05-28 13:21:10 -0700 | [diff] [blame] | 1063 | static int |
| 1064 | do_block_io_op(struct xen_blkif *blkif) |
| 1065 | { |
| 1066 | union blkif_back_rings *blk_rings = &blkif->blk_rings; |
| 1067 | int more_to_do; |
| 1068 | |
| 1069 | do { |
| 1070 | more_to_do = __do_block_io_op(blkif); |
| 1071 | if (more_to_do) |
| 1072 | break; |
| 1073 | |
| 1074 | RING_FINAL_CHECK_FOR_REQUESTS(&blk_rings->common, more_to_do); |
| 1075 | } while (more_to_do); |
| 1076 | |
| 1077 | return more_to_do; |
| 1078 | } |
Konrad Rzeszutek Wilk | a1397fa | 2011-04-14 17:05:23 -0400 | [diff] [blame] | 1079 | /* |
Konrad Rzeszutek Wilk | 01f37f2 | 2011-05-11 15:57:09 -0400 | [diff] [blame] | 1080 | * Transmutation of the 'struct blkif_request' to a proper 'struct bio' |
| 1081 | * and call the 'submit_bio' to pass it to the underlying storage. |
Konrad Rzeszutek Wilk | a1397fa | 2011-04-14 17:05:23 -0400 | [diff] [blame] | 1082 | */ |
Konrad Rzeszutek Wilk | 30fd150 | 2011-05-12 16:47:48 -0400 | [diff] [blame] | 1083 | static int dispatch_rw_block_io(struct xen_blkif *blkif, |
| 1084 | struct blkif_request *req, |
| 1085 | struct pending_req *pending_req) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1086 | { |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1087 | struct phys_req preq; |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 1088 | struct seg_buf *seg = pending_req->seg; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1089 | unsigned int nseg; |
| 1090 | struct bio *bio = NULL; |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 1091 | struct bio **biolist = pending_req->biolist; |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 1092 | int i, nbio = 0; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1093 | int operation; |
Konrad Rzeszutek Wilk | a19be5f | 2011-04-27 12:40:11 -0400 | [diff] [blame] | 1094 | struct blk_plug plug; |
Konrad Rzeszutek Wilk | 29bde09 | 2011-10-10 00:42:22 -0400 | [diff] [blame] | 1095 | bool drain = false; |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 1096 | struct grant_page **pages = pending_req->segments; |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 1097 | unsigned short req_operation; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1098 | |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 1099 | req_operation = req->operation == BLKIF_OP_INDIRECT ? |
| 1100 | req->u.indirect.indirect_op : req->operation; |
| 1101 | if ((req->operation == BLKIF_OP_INDIRECT) && |
| 1102 | (req_operation != BLKIF_OP_READ) && |
| 1103 | (req_operation != BLKIF_OP_WRITE)) { |
| 1104 | pr_debug(DRV_PFX "Invalid indirect operation (%u)\n", |
| 1105 | req_operation); |
| 1106 | goto fail_response; |
| 1107 | } |
| 1108 | |
| 1109 | switch (req_operation) { |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1110 | case BLKIF_OP_READ: |
Konrad Rzeszutek Wilk | fc53bf7 | 2011-05-05 13:37:23 -0400 | [diff] [blame] | 1111 | blkif->st_rd_req++; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1112 | operation = READ; |
| 1113 | break; |
| 1114 | case BLKIF_OP_WRITE: |
Konrad Rzeszutek Wilk | fc53bf7 | 2011-05-05 13:37:23 -0400 | [diff] [blame] | 1115 | blkif->st_wr_req++; |
Konrad Rzeszutek Wilk | 013c3ca | 2011-04-26 16:24:18 -0400 | [diff] [blame] | 1116 | operation = WRITE_ODIRECT; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1117 | break; |
Konrad Rzeszutek Wilk | 29bde09 | 2011-10-10 00:42:22 -0400 | [diff] [blame] | 1118 | case BLKIF_OP_WRITE_BARRIER: |
| 1119 | drain = true; |
Konrad Rzeszutek Wilk | 24f567f | 2011-05-04 17:07:27 -0400 | [diff] [blame] | 1120 | case BLKIF_OP_FLUSH_DISKCACHE: |
Konrad Rzeszutek Wilk | fc53bf7 | 2011-05-05 13:37:23 -0400 | [diff] [blame] | 1121 | blkif->st_f_req++; |
Konrad Rzeszutek Wilk | 24f567f | 2011-05-04 17:07:27 -0400 | [diff] [blame] | 1122 | operation = WRITE_FLUSH; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1123 | break; |
| 1124 | default: |
| 1125 | operation = 0; /* make gcc happy */ |
Konrad Rzeszutek Wilk | fc53bf7 | 2011-05-05 13:37:23 -0400 | [diff] [blame] | 1126 | goto fail_response; |
| 1127 | break; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1128 | } |
| 1129 | |
Konrad Rzeszutek Wilk | 4214635 | 2011-10-12 17:26:47 -0400 | [diff] [blame] | 1130 | /* Check that the number of segments is sane. */ |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 1131 | nseg = req->operation == BLKIF_OP_INDIRECT ? |
| 1132 | req->u.indirect.nr_segments : req->u.rw.nr_segments; |
Konrad Rzeszutek Wilk | 97e3683 | 2011-10-12 12:12:36 -0400 | [diff] [blame] | 1133 | |
Konrad Rzeszutek Wilk | 4214635 | 2011-10-12 17:26:47 -0400 | [diff] [blame] | 1134 | if (unlikely(nseg == 0 && operation != WRITE_FLUSH) || |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 1135 | unlikely((req->operation != BLKIF_OP_INDIRECT) && |
| 1136 | (nseg > BLKIF_MAX_SEGMENTS_PER_REQUEST)) || |
| 1137 | unlikely((req->operation == BLKIF_OP_INDIRECT) && |
| 1138 | (nseg > MAX_INDIRECT_SEGMENTS))) { |
Konrad Rzeszutek Wilk | 22b20f2 | 2011-05-12 16:43:12 -0400 | [diff] [blame] | 1139 | pr_debug(DRV_PFX "Bad number of segments in request (%d)\n", |
Konrad Rzeszutek Wilk | ebe8190 | 2011-05-12 16:42:31 -0400 | [diff] [blame] | 1140 | nseg); |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 1141 | /* Haven't submitted any bio's yet. */ |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1142 | goto fail_response; |
| 1143 | } |
| 1144 | |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1145 | preq.nr_sects = 0; |
| 1146 | |
| 1147 | pending_req->blkif = blkif; |
Konrad Rzeszutek Wilk | 97e3683 | 2011-10-12 12:12:36 -0400 | [diff] [blame] | 1148 | pending_req->id = req->u.rw.id; |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 1149 | pending_req->operation = req_operation; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1150 | pending_req->status = BLKIF_RSP_OKAY; |
| 1151 | pending_req->nr_pages = nseg; |
Konrad Rzeszutek Wilk | e935049 | 2011-04-18 11:34:55 -0400 | [diff] [blame] | 1152 | |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 1153 | if (req->operation != BLKIF_OP_INDIRECT) { |
| 1154 | preq.dev = req->u.rw.handle; |
| 1155 | preq.sector_number = req->u.rw.sector_number; |
| 1156 | for (i = 0; i < nseg; i++) { |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 1157 | pages[i]->gref = req->u.rw.seg[i].gref; |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 1158 | seg[i].nsec = req->u.rw.seg[i].last_sect - |
| 1159 | req->u.rw.seg[i].first_sect + 1; |
| 1160 | seg[i].offset = (req->u.rw.seg[i].first_sect << 9); |
| 1161 | if ((req->u.rw.seg[i].last_sect >= (PAGE_SIZE >> 9)) || |
| 1162 | (req->u.rw.seg[i].last_sect < |
| 1163 | req->u.rw.seg[i].first_sect)) |
| 1164 | goto fail_response; |
| 1165 | preq.nr_sects += seg[i].nsec; |
| 1166 | } |
| 1167 | } else { |
| 1168 | preq.dev = req->u.indirect.handle; |
| 1169 | preq.sector_number = req->u.indirect.sector_number; |
| 1170 | if (xen_blkbk_parse_indirect(req, pending_req, seg, &preq)) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1171 | goto fail_response; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1172 | } |
| 1173 | |
Konrad Rzeszutek Wilk | 3d81473 | 2011-05-12 16:53:56 -0400 | [diff] [blame] | 1174 | if (xen_vbd_translate(&preq, blkif, operation) != 0) { |
Konrad Rzeszutek Wilk | 22b20f2 | 2011-05-12 16:43:12 -0400 | [diff] [blame] | 1175 | pr_debug(DRV_PFX "access denied: %s of [%llu,%llu] on dev=%04x\n", |
Konrad Rzeszutek Wilk | ebe8190 | 2011-05-12 16:42:31 -0400 | [diff] [blame] | 1176 | operation == READ ? "read" : "write", |
| 1177 | preq.sector_number, |
Chen Gang | a72d900 | 2013-02-28 10:34:23 +0800 | [diff] [blame] | 1178 | preq.sector_number + preq.nr_sects, |
| 1179 | blkif->vbd.pdevice); |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 1180 | goto fail_response; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1181 | } |
Konrad Rzeszutek Wilk | 01f37f2 | 2011-05-11 15:57:09 -0400 | [diff] [blame] | 1182 | |
| 1183 | /* |
Konrad Rzeszutek Wilk | 3d81473 | 2011-05-12 16:53:56 -0400 | [diff] [blame] | 1184 | * This check _MUST_ be done after xen_vbd_translate as the preq.bdev |
Konrad Rzeszutek Wilk | 01f37f2 | 2011-05-11 15:57:09 -0400 | [diff] [blame] | 1185 | * is set there. |
| 1186 | */ |
Konrad Rzeszutek Wilk | e935049 | 2011-04-18 11:34:55 -0400 | [diff] [blame] | 1187 | for (i = 0; i < nseg; i++) { |
| 1188 | if (((int)preq.sector_number|(int)seg[i].nsec) & |
| 1189 | ((bdev_logical_block_size(preq.bdev) >> 9) - 1)) { |
Konrad Rzeszutek Wilk | 22b20f2 | 2011-05-12 16:43:12 -0400 | [diff] [blame] | 1190 | pr_debug(DRV_PFX "Misaligned I/O request from domain %d", |
Konrad Rzeszutek Wilk | ebe8190 | 2011-05-12 16:42:31 -0400 | [diff] [blame] | 1191 | blkif->domid); |
Konrad Rzeszutek Wilk | e935049 | 2011-04-18 11:34:55 -0400 | [diff] [blame] | 1192 | goto fail_response; |
| 1193 | } |
| 1194 | } |
Konrad Rzeszutek Wilk | 01f37f2 | 2011-05-11 15:57:09 -0400 | [diff] [blame] | 1195 | |
Konrad Rzeszutek Wilk | 29bde09 | 2011-10-10 00:42:22 -0400 | [diff] [blame] | 1196 | /* Wait on all outstanding I/O's and once that has been completed |
| 1197 | * issue the WRITE_FLUSH. |
| 1198 | */ |
| 1199 | if (drain) |
| 1200 | xen_blk_drain_io(pending_req->blkif); |
| 1201 | |
Konrad Rzeszutek Wilk | 01f37f2 | 2011-05-11 15:57:09 -0400 | [diff] [blame] | 1202 | /* |
| 1203 | * If we have failed at this point, we need to undo the M2P override, |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 1204 | * set gnttab_set_unmap_op on all of the grant references and perform |
| 1205 | * the hypercall to unmap the grants - that is all done in |
Konrad Rzeszutek Wilk | 9f3aedf | 2011-04-15 11:50:34 -0400 | [diff] [blame] | 1206 | * xen_blkbk_unmap. |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 1207 | */ |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 1208 | if (xen_blkbk_map_seg(pending_req)) |
Konrad Rzeszutek Wilk | 1a95fe6 | 2011-04-15 11:35:13 -0400 | [diff] [blame] | 1209 | goto fail_flush; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1210 | |
Li Dongyang | b3cb0d6 | 2011-09-01 18:39:10 +0800 | [diff] [blame] | 1211 | /* |
| 1212 | * This corresponding xen_blkif_put is done in __end_block_io_op, or |
| 1213 | * below (in "!bio") if we are handling a BLKIF_OP_DISCARD. |
| 1214 | */ |
Konrad Rzeszutek Wilk | 8b6bf74 | 2011-04-20 11:50:43 -0400 | [diff] [blame] | 1215 | xen_blkif_get(blkif); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1216 | |
| 1217 | for (i = 0; i < nseg; i++) { |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1218 | while ((bio == NULL) || |
| 1219 | (bio_add_page(bio, |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 1220 | pages[i]->page, |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1221 | seg[i].nsec << 9, |
Roger Pau Monne | ffb1dab | 2013-03-18 17:49:32 +0100 | [diff] [blame] | 1222 | seg[i].offset) == 0)) { |
Konrad Rzeszutek Wilk | 2e9977c | 2011-04-14 17:42:07 -0400 | [diff] [blame] | 1223 | |
Konrad Rzeszutek Wilk | 03e0edf | 2011-05-12 16:19:23 -0400 | [diff] [blame] | 1224 | bio = bio_alloc(GFP_KERNEL, nseg-i); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1225 | if (unlikely(bio == NULL)) |
| 1226 | goto fail_put_bio; |
| 1227 | |
Konrad Rzeszutek Wilk | 03e0edf | 2011-05-12 16:19:23 -0400 | [diff] [blame] | 1228 | biolist[nbio++] = bio; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1229 | bio->bi_bdev = preq.bdev; |
| 1230 | bio->bi_private = pending_req; |
| 1231 | bio->bi_end_io = end_block_io_op; |
| 1232 | bio->bi_sector = preq.sector_number; |
| 1233 | } |
| 1234 | |
| 1235 | preq.sector_number += seg[i].nsec; |
| 1236 | } |
| 1237 | |
Li Dongyang | b3cb0d6 | 2011-09-01 18:39:10 +0800 | [diff] [blame] | 1238 | /* This will be hit if the operation was a flush or discard. */ |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1239 | if (!bio) { |
Konrad Rzeszutek Wilk | 4214635 | 2011-10-12 17:26:47 -0400 | [diff] [blame] | 1240 | BUG_ON(operation != WRITE_FLUSH); |
Konrad Rzeszutek Wilk | b0f8012 | 2011-05-12 16:23:06 -0400 | [diff] [blame] | 1241 | |
Konrad Rzeszutek Wilk | 4214635 | 2011-10-12 17:26:47 -0400 | [diff] [blame] | 1242 | bio = bio_alloc(GFP_KERNEL, 0); |
| 1243 | if (unlikely(bio == NULL)) |
| 1244 | goto fail_put_bio; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1245 | |
Konrad Rzeszutek Wilk | 4214635 | 2011-10-12 17:26:47 -0400 | [diff] [blame] | 1246 | biolist[nbio++] = bio; |
| 1247 | bio->bi_bdev = preq.bdev; |
| 1248 | bio->bi_private = pending_req; |
| 1249 | bio->bi_end_io = end_block_io_op; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1250 | } |
| 1251 | |
Konrad Rzeszutek Wilk | 7708992 | 2011-04-15 10:51:27 -0400 | [diff] [blame] | 1252 | atomic_set(&pending_req->pendcnt, nbio); |
Konrad Rzeszutek Wilk | a19be5f | 2011-04-27 12:40:11 -0400 | [diff] [blame] | 1253 | blk_start_plug(&plug); |
| 1254 | |
Konrad Rzeszutek Wilk | 7708992 | 2011-04-15 10:51:27 -0400 | [diff] [blame] | 1255 | for (i = 0; i < nbio; i++) |
| 1256 | submit_bio(operation, biolist[i]); |
| 1257 | |
Konrad Rzeszutek Wilk | a19be5f | 2011-04-27 12:40:11 -0400 | [diff] [blame] | 1258 | /* Let the I/Os go.. */ |
Konrad Rzeszutek Wilk | 3d68b39 | 2011-05-05 13:42:10 -0400 | [diff] [blame] | 1259 | blk_finish_plug(&plug); |
Konrad Rzeszutek Wilk | a19be5f | 2011-04-27 12:40:11 -0400 | [diff] [blame] | 1260 | |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1261 | if (operation == READ) |
| 1262 | blkif->st_rd_sect += preq.nr_sects; |
Konrad Rzeszutek Wilk | 5c62cb4 | 2011-10-10 12:33:21 -0400 | [diff] [blame] | 1263 | else if (operation & WRITE) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1264 | blkif->st_wr_sect += preq.nr_sects; |
| 1265 | |
Konrad Rzeszutek Wilk | fc53bf7 | 2011-05-05 13:37:23 -0400 | [diff] [blame] | 1266 | return 0; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1267 | |
| 1268 | fail_flush: |
Roger Pau Monne | bb642e8 | 2013-05-02 10:21:17 +0200 | [diff] [blame] | 1269 | xen_blkbk_unmap(blkif, pending_req->segments, |
Roger Pau Monne | 31552ee | 2013-04-17 20:19:00 +0200 | [diff] [blame] | 1270 | pending_req->nr_pages); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1271 | fail_response: |
Konrad Rzeszutek Wilk | 0faa8cc | 2011-04-14 17:58:19 -0400 | [diff] [blame] | 1272 | /* Haven't submitted any bio's yet. */ |
Roger Pau Monne | 402b27f | 2013-04-18 16:06:54 +0200 | [diff] [blame] | 1273 | make_response(blkif, req->u.rw.id, req_operation, BLKIF_RSP_ERROR); |
Roger Pau Monne | bf0720c | 2013-04-17 20:18:59 +0200 | [diff] [blame] | 1274 | free_req(blkif, pending_req); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1275 | msleep(1); /* back off a bit */ |
Konrad Rzeszutek Wilk | fc53bf7 | 2011-05-05 13:37:23 -0400 | [diff] [blame] | 1276 | return -EIO; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1277 | |
| 1278 | fail_put_bio: |
Konrad Rzeszutek Wilk | 03e0edf | 2011-05-12 16:19:23 -0400 | [diff] [blame] | 1279 | for (i = 0; i < nbio; i++) |
Konrad Rzeszutek Wilk | 7708992 | 2011-04-15 10:51:27 -0400 | [diff] [blame] | 1280 | bio_put(biolist[i]); |
Jan Beulich | 0e5e098 | 2013-03-11 09:39:55 +0000 | [diff] [blame] | 1281 | atomic_set(&pending_req->pendcnt, 1); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1282 | __end_block_io_op(pending_req, -EINVAL); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1283 | msleep(1); /* back off a bit */ |
Konrad Rzeszutek Wilk | fc53bf7 | 2011-05-05 13:37:23 -0400 | [diff] [blame] | 1284 | return -EIO; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | |
| 1288 | |
Konrad Rzeszutek Wilk | a1397fa | 2011-04-14 17:05:23 -0400 | [diff] [blame] | 1289 | /* |
| 1290 | * Put a response on the ring on how the operation fared. |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1291 | */ |
Konrad Rzeszutek Wilk | 30fd150 | 2011-05-12 16:47:48 -0400 | [diff] [blame] | 1292 | static void make_response(struct xen_blkif *blkif, u64 id, |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1293 | unsigned short op, int st) |
| 1294 | { |
Jeremy Fitzhardinge | 8812293 | 2009-02-09 12:05:51 -0800 | [diff] [blame] | 1295 | struct blkif_response resp; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1296 | unsigned long flags; |
Jeremy Fitzhardinge | 8812293 | 2009-02-09 12:05:51 -0800 | [diff] [blame] | 1297 | union blkif_back_rings *blk_rings = &blkif->blk_rings; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1298 | int notify; |
| 1299 | |
| 1300 | resp.id = id; |
| 1301 | resp.operation = op; |
| 1302 | resp.status = st; |
| 1303 | |
| 1304 | spin_lock_irqsave(&blkif->blk_ring_lock, flags); |
| 1305 | /* Place on the response ring for the relevant domain. */ |
| 1306 | switch (blkif->blk_protocol) { |
| 1307 | case BLKIF_PROTOCOL_NATIVE: |
| 1308 | memcpy(RING_GET_RESPONSE(&blk_rings->native, blk_rings->native.rsp_prod_pvt), |
| 1309 | &resp, sizeof(resp)); |
| 1310 | break; |
| 1311 | case BLKIF_PROTOCOL_X86_32: |
| 1312 | memcpy(RING_GET_RESPONSE(&blk_rings->x86_32, blk_rings->x86_32.rsp_prod_pvt), |
| 1313 | &resp, sizeof(resp)); |
| 1314 | break; |
| 1315 | case BLKIF_PROTOCOL_X86_64: |
| 1316 | memcpy(RING_GET_RESPONSE(&blk_rings->x86_64, blk_rings->x86_64.rsp_prod_pvt), |
| 1317 | &resp, sizeof(resp)); |
| 1318 | break; |
| 1319 | default: |
| 1320 | BUG(); |
| 1321 | } |
| 1322 | blk_rings->common.rsp_prod_pvt++; |
| 1323 | RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&blk_rings->common, notify); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1324 | spin_unlock_irqrestore(&blkif->blk_ring_lock, flags); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1325 | if (notify) |
| 1326 | notify_remote_via_irq(blkif->irq); |
| 1327 | } |
| 1328 | |
Konrad Rzeszutek Wilk | 8b6bf74 | 2011-04-20 11:50:43 -0400 | [diff] [blame] | 1329 | static int __init xen_blkif_init(void) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1330 | { |
Konrad Rzeszutek Wilk | 8770b26 | 2009-10-08 13:23:09 -0400 | [diff] [blame] | 1331 | int rc = 0; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1332 | |
Daniel De Graaf | b2167ba | 2011-11-28 11:49:05 -0500 | [diff] [blame] | 1333 | if (!xen_domain()) |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1334 | return -ENODEV; |
| 1335 | |
Konrad Rzeszutek Wilk | 8b6bf74 | 2011-04-20 11:50:43 -0400 | [diff] [blame] | 1336 | rc = xen_blkif_interface_init(); |
Konrad Rzeszutek Wilk | 8770b26 | 2009-10-08 13:23:09 -0400 | [diff] [blame] | 1337 | if (rc) |
| 1338 | goto failed_init; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1339 | |
Konrad Rzeszutek Wilk | 8b6bf74 | 2011-04-20 11:50:43 -0400 | [diff] [blame] | 1340 | rc = xen_blkif_xenbus_init(); |
Konrad Rzeszutek Wilk | 8770b26 | 2009-10-08 13:23:09 -0400 | [diff] [blame] | 1341 | if (rc) |
| 1342 | goto failed_init; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1343 | |
Konrad Rzeszutek Wilk | 8770b26 | 2009-10-08 13:23:09 -0400 | [diff] [blame] | 1344 | failed_init: |
Konrad Rzeszutek Wilk | 8770b26 | 2009-10-08 13:23:09 -0400 | [diff] [blame] | 1345 | return rc; |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1346 | } |
| 1347 | |
Konrad Rzeszutek Wilk | 8b6bf74 | 2011-04-20 11:50:43 -0400 | [diff] [blame] | 1348 | module_init(xen_blkif_init); |
Konrad Rzeszutek Wilk | 4d05a28 | 2011-04-14 18:25:47 -0400 | [diff] [blame] | 1349 | |
| 1350 | MODULE_LICENSE("Dual BSD/GPL"); |
Bastian Blank | a7e9357 | 2011-06-29 14:40:50 +0200 | [diff] [blame] | 1351 | MODULE_ALIAS("xen-backend:vbd"); |