blob: 914587aabca0cd210eca2856d69a5204aa0005b3 [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -04002/* Xenbus code for blkif backend
3 Copyright (C) 2005 Rusty Russell <rusty@rustcorp.com.au>
4 Copyright (C) 2005 XenSource Ltd
5
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -04006
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -04007*/
8
Tao Chen77387b82015-04-01 15:04:22 +00009#define pr_fmt(fmt) "xen-blkback: " fmt
10
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040011#include <linux/module.h>
12#include <linux/kthread.h>
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -040013#include <xen/events.h>
14#include <xen/grant_table.h>
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040015#include "common.h"
16
Konrad Rzeszutek Wilkfa3184b2016-02-03 16:40:05 -050017/* On the XenBus the max length of 'ring-ref%u'. */
Bob Liu86839c52015-06-03 13:40:03 +080018#define RINGREF_NAME_LEN (20)
Tao Chen13755902015-03-27 13:15:54 +000019
Konrad Rzeszutek Wilkd6091b22011-04-14 17:33:30 -040020struct backend_info {
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -040021 struct xenbus_device *dev;
Konrad Rzeszutek Wilk51854322011-05-12 18:02:28 -040022 struct xen_blkif *blkif;
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -040023 struct xenbus_watch backend_watch;
24 unsigned major;
25 unsigned minor;
26 char *mode;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040027};
28
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -040029static struct kmem_cache *xen_blkif_cachep;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040030static void connect(struct backend_info *);
31static int connect_ring(struct backend_info *);
Juergen Gross5584ea22017-02-09 14:39:57 +010032static void backend_changed(struct xenbus_watch *, const char *,
33 const char *);
Valentin Priescu814d04e2014-05-20 22:28:50 +020034static void xen_blkif_free(struct xen_blkif *blkif);
35static void xen_vbd_free(struct xen_vbd *vbd);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040036
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -040037struct xenbus_device *xen_blkbk_xenbus(struct backend_info *be)
Jeremy Fitzhardinge98e036a2010-03-18 15:35:05 -070038{
39 return be->dev;
40}
41
Valentin Priescu814d04e2014-05-20 22:28:50 +020042/*
43 * The last request could free the device from softirq context and
44 * xen_blkif_free() can sleep.
45 */
46static void xen_blkif_deferred_free(struct work_struct *work)
47{
48 struct xen_blkif *blkif;
49
50 blkif = container_of(work, struct xen_blkif, free_work);
51 xen_blkif_free(blkif);
52}
53
Konrad Rzeszutek Wilk30fd1502011-05-12 16:47:48 -040054static int blkback_name(struct xen_blkif *blkif, char *buf)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040055{
56 char *devpath, *devname;
57 struct xenbus_device *dev = blkif->be->dev;
58
59 devpath = xenbus_read(XBT_NIL, dev->nodename, "dev", NULL);
60 if (IS_ERR(devpath))
61 return PTR_ERR(devpath);
62
Konrad Rzeszutek Wilkd6091b22011-04-14 17:33:30 -040063 devname = strstr(devpath, "/dev/");
64 if (devname != NULL)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040065 devname += strlen("/dev/");
66 else
67 devname = devpath;
68
Konrad Rzeszutek Wilkfa3184b2016-02-03 16:40:05 -050069 snprintf(buf, TASK_COMM_LEN, "%d.%s", blkif->domid, devname);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040070 kfree(devpath);
71
72 return 0;
73}
74
Konrad Rzeszutek Wilk30fd1502011-05-12 16:47:48 -040075static void xen_update_blkif_status(struct xen_blkif *blkif)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040076{
77 int err;
Konrad Rzeszutek Wilkfa3184b2016-02-03 16:40:05 -050078 char name[TASK_COMM_LEN];
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -050079 struct xen_blkif_ring *ring;
80 int i;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040081
82 /* Not ready to connect? */
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -050083 if (!blkif->rings || !blkif->rings[0].irq || !blkif->vbd.bdev)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -040084 return;
85
86 /* Already connected? */
87 if (blkif->be->dev->state == XenbusStateConnected)
88 return;
89
90 /* Attempt to connect: exit if we fail to. */
91 connect(blkif->be);
92 if (blkif->be->dev->state != XenbusStateConnected)
93 return;
94
95 err = blkback_name(blkif, name);
96 if (err) {
97 xenbus_dev_error(blkif->be->dev, err, "get blkback dev name");
98 return;
99 }
100
Christoph Hellwigd39b0a22021-10-19 08:25:26 +0200101 err = sync_blockdev(blkif->vbd.bdev);
Chris Lalancettecbf46292010-07-21 12:41:45 -0700102 if (err) {
103 xenbus_dev_error(blkif->be->dev, err, "block flush");
104 return;
105 }
106 invalidate_inode_pages2(blkif->vbd.bdev->bd_inode->i_mapping);
107
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500108 for (i = 0; i < blkif->nr_rings; i++) {
109 ring = &blkif->rings[i];
110 ring->xenblkd = kthread_run(xen_blkif_schedule, ring, "%s-%d", name, i);
111 if (IS_ERR(ring->xenblkd)) {
112 err = PTR_ERR(ring->xenblkd);
113 ring->xenblkd = NULL;
114 xenbus_dev_fatal(blkif->be->dev, err,
115 "start %s-%d xenblkd", name, i);
116 goto out;
117 }
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400118 }
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500119 return;
120
121out:
122 while (--i >= 0) {
123 ring = &blkif->rings[i];
124 kthread_stop(ring->xenblkd);
125 }
126 return;
127}
128
129static int xen_blkif_alloc_rings(struct xen_blkif *blkif)
130{
131 unsigned int r;
132
Kees Cook6396bb22018-06-12 14:03:40 -0700133 blkif->rings = kcalloc(blkif->nr_rings, sizeof(struct xen_blkif_ring),
134 GFP_KERNEL);
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500135 if (!blkif->rings)
136 return -ENOMEM;
137
138 for (r = 0; r < blkif->nr_rings; r++) {
139 struct xen_blkif_ring *ring = &blkif->rings[r];
140
141 spin_lock_init(&ring->blk_ring_lock);
142 init_waitqueue_head(&ring->wq);
143 INIT_LIST_HEAD(&ring->pending_free);
Bob Liud4bf0062015-11-14 11:12:19 +0800144 INIT_LIST_HEAD(&ring->persistent_purge_list);
145 INIT_WORK(&ring->persistent_purge_work, xen_blkbk_unmap_purged_grants);
Juergen Grossca334792020-12-07 08:31:22 +0100146 gnttab_page_cache_init(&ring->free_pages);
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500147
148 spin_lock_init(&ring->pending_free_lock);
149 init_waitqueue_head(&ring->pending_free_wq);
150 init_waitqueue_head(&ring->shutdown_wq);
151 ring->blkif = blkif;
Bob Liudb6fbc12015-12-09 07:44:02 +0800152 ring->st_print = jiffies;
Juergen Gross46464412017-05-18 17:28:47 +0200153 ring->active = true;
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500154 }
155
156 return 0;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400157}
158
Konrad Rzeszutek Wilk30fd1502011-05-12 16:47:48 -0400159static struct xen_blkif *xen_blkif_alloc(domid_t domid)
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400160{
Konrad Rzeszutek Wilk30fd1502011-05-12 16:47:48 -0400161 struct xen_blkif *blkif;
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400162
Roger Pau Monne402b27f2013-04-18 16:06:54 +0200163 BUILD_BUG_ON(MAX_INDIRECT_PAGES > BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST);
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400164
Wei Yongjun654dbef2012-08-27 12:28:57 +0800165 blkif = kmem_cache_zalloc(xen_blkif_cachep, GFP_KERNEL);
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400166 if (!blkif)
167 return ERR_PTR(-ENOMEM);
168
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400169 blkif->domid = domid;
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400170 atomic_set(&blkif->refcnt, 1);
Konrad Rzeszutek Wilk29bde092011-10-10 00:42:22 -0400171 init_completion(&blkif->drain_complete);
Paul Durrantfa2ac652019-12-10 14:53:05 +0000172
173 /*
174 * Because freeing back to the cache may be deferred, it is not
175 * safe to unload the module (and hence destroy the cache) until
176 * this has completed. To prevent premature unloading, take an
177 * extra module reference here and release only when the object
178 * has been freed back to the cache.
179 */
180 __module_get(THIS_MODULE);
Bob Liu59795702015-11-14 11:12:15 +0800181 INIT_WORK(&blkif->free_work, xen_blkif_deferred_free);
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400182
183 return blkif;
184}
185
Bob Liu59795702015-11-14 11:12:15 +0800186static int xen_blkif_map(struct xen_blkif_ring *ring, grant_ref_t *gref,
Bob Liu86839c52015-06-03 13:40:03 +0800187 unsigned int nr_grefs, unsigned int evtchn)
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400188{
189 int err;
Bob Liu59795702015-11-14 11:12:15 +0800190 struct xen_blkif *blkif = ring->blkif;
Paul Durrantf4eef1b2019-12-11 15:29:56 +0000191 const struct blkif_common_sring *sring_common;
192 RING_IDX rsp_prod, req_prod;
193 unsigned int size;
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400194
195 /* Already connected through? */
Bob Liu59795702015-11-14 11:12:15 +0800196 if (ring->irq)
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400197 return 0;
198
Bob Liu86839c52015-06-03 13:40:03 +0800199 err = xenbus_map_ring_valloc(blkif->be->dev, gref, nr_grefs,
Bob Liu59795702015-11-14 11:12:15 +0800200 &ring->blk_ring);
David Vrabel2d073842011-09-29 16:53:30 +0100201 if (err < 0)
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400202 return err;
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400203
Paul Durrantf4eef1b2019-12-11 15:29:56 +0000204 sring_common = (struct blkif_common_sring *)ring->blk_ring;
205 rsp_prod = READ_ONCE(sring_common->rsp_prod);
206 req_prod = READ_ONCE(sring_common->req_prod);
207
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400208 switch (blkif->blk_protocol) {
209 case BLKIF_PROTOCOL_NATIVE:
210 {
Paul Durrantf4eef1b2019-12-11 15:29:56 +0000211 struct blkif_sring *sring_native =
212 (struct blkif_sring *)ring->blk_ring;
213
214 BACK_RING_ATTACH(&ring->blk_rings.native, sring_native,
215 rsp_prod, XEN_PAGE_SIZE * nr_grefs);
216 size = __RING_SIZE(sring_native, XEN_PAGE_SIZE * nr_grefs);
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400217 break;
218 }
219 case BLKIF_PROTOCOL_X86_32:
220 {
Paul Durrantf4eef1b2019-12-11 15:29:56 +0000221 struct blkif_x86_32_sring *sring_x86_32 =
222 (struct blkif_x86_32_sring *)ring->blk_ring;
223
224 BACK_RING_ATTACH(&ring->blk_rings.x86_32, sring_x86_32,
225 rsp_prod, XEN_PAGE_SIZE * nr_grefs);
226 size = __RING_SIZE(sring_x86_32, XEN_PAGE_SIZE * nr_grefs);
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400227 break;
228 }
229 case BLKIF_PROTOCOL_X86_64:
230 {
Paul Durrantf4eef1b2019-12-11 15:29:56 +0000231 struct blkif_x86_64_sring *sring_x86_64 =
232 (struct blkif_x86_64_sring *)ring->blk_ring;
233
234 BACK_RING_ATTACH(&ring->blk_rings.x86_64, sring_x86_64,
235 rsp_prod, XEN_PAGE_SIZE * nr_grefs);
236 size = __RING_SIZE(sring_x86_64, XEN_PAGE_SIZE * nr_grefs);
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400237 break;
238 }
239 default:
240 BUG();
241 }
242
Paul Durrantf4eef1b2019-12-11 15:29:56 +0000243 err = -EIO;
244 if (req_prod - rsp_prod > size)
245 goto fail;
246
Juergen Grossf2fa0e52021-02-11 11:16:13 +0100247 err = bind_interdomain_evtchn_to_irqhandler_lateeoi(blkif->be->dev,
Juergen Gross01263a12020-09-07 15:47:27 +0200248 evtchn, xen_blkif_be_int, 0, "blkif-backend", ring);
Paul Durrantf4eef1b2019-12-11 15:29:56 +0000249 if (err < 0)
250 goto fail;
Bob Liu59795702015-11-14 11:12:15 +0800251 ring->irq = err;
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400252
253 return 0;
Paul Durrantf4eef1b2019-12-11 15:29:56 +0000254
255fail:
256 xenbus_unmap_ring_vfree(blkif->be->dev, ring->blk_ring);
257 ring->blk_rings.common.sring = NULL;
258 return err;
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400259}
260
Valentin Priescu814d04e2014-05-20 22:28:50 +0200261static int xen_blkif_disconnect(struct xen_blkif *blkif)
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400262{
Roger Pau Monnef929d422015-09-04 12:08:07 +0200263 struct pending_req *req, *n;
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500264 unsigned int j, r;
Annie Lidc52d7832017-08-24 17:25:59 -0400265 bool busy = false;
Roger Pau Monnef929d422015-09-04 12:08:07 +0200266
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500267 for (r = 0; r < blkif->nr_rings; r++) {
268 struct xen_blkif_ring *ring = &blkif->rings[r];
269 unsigned int i = 0;
270
Juergen Gross46464412017-05-18 17:28:47 +0200271 if (!ring->active)
272 continue;
273
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500274 if (ring->xenblkd) {
275 kthread_stop(ring->xenblkd);
Pawel Wieczorkiewicz1c728712020-12-14 10:25:57 +0100276 ring->xenblkd = NULL;
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500277 wake_up(&ring->shutdown_wq);
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500278 }
279
280 /* The above kthread_stop() guarantees that at this point we
281 * don't have any discard_io or other_io requests. So, checking
282 * for inflight IO is enough.
283 */
Annie Lidc52d7832017-08-24 17:25:59 -0400284 if (atomic_read(&ring->inflight) > 0) {
285 busy = true;
286 continue;
287 }
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500288
289 if (ring->irq) {
290 unbind_from_irqhandler(ring->irq, ring);
291 ring->irq = 0;
292 }
293
294 if (ring->blk_rings.common.sring) {
295 xenbus_unmap_ring_vfree(blkif->be->dev, ring->blk_ring);
296 ring->blk_rings.common.sring = NULL;
297 }
298
299 /* Remove all persistent grants and the cache of ballooned pages. */
300 xen_blkbk_free_caches(ring);
301
302 /* Check that there is no request in use */
303 list_for_each_entry_safe(req, n, &ring->pending_free, free_list) {
304 list_del(&req->free_list);
305
306 for (j = 0; j < MAX_INDIRECT_SEGMENTS; j++)
307 kfree(req->segments[j]);
308
309 for (j = 0; j < MAX_INDIRECT_PAGES; j++)
310 kfree(req->indirect_pages[j]);
311
312 kfree(req);
313 i++;
314 }
315
Bob Liud4bf0062015-11-14 11:12:19 +0800316 BUG_ON(atomic_read(&ring->persistent_gnt_in_use) != 0);
317 BUG_ON(!list_empty(&ring->persistent_purge_list));
318 BUG_ON(!RB_EMPTY_ROOT(&ring->persistent_gnts));
Juergen Grossca334792020-12-07 08:31:22 +0100319 BUG_ON(ring->free_pages.num_pages != 0);
Bob Liud4bf0062015-11-14 11:12:19 +0800320 BUG_ON(ring->persistent_gnt_c != 0);
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500321 WARN_ON(i != (XEN_BLKIF_REQS_PER_PAGE * blkif->nr_ring_pages));
Juergen Gross46464412017-05-18 17:28:47 +0200322 ring->active = false;
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400323 }
Annie Lidc52d7832017-08-24 17:25:59 -0400324 if (busy)
325 return -EBUSY;
326
Roger Pau Monnef929d422015-09-04 12:08:07 +0200327 blkif->nr_ring_pages = 0;
Bob Liu93bb2772015-12-10 09:16:48 +0800328 /*
329 * blkif->rings was allocated in connect_ring, so we should free it in
330 * here.
331 */
332 kfree(blkif->rings);
333 blkif->rings = NULL;
334 blkif->nr_rings = 0;
Roger Pau Monnef929d422015-09-04 12:08:07 +0200335
336 return 0;
337}
338
339static void xen_blkif_free(struct xen_blkif *blkif)
340{
Juergen Gross71df1d72017-05-18 17:28:48 +0200341 WARN_ON(xen_blkif_disconnect(blkif));
Roger Pau Monnef929d422015-09-04 12:08:07 +0200342 xen_vbd_free(&blkif->vbd);
Juergen Gross71df1d72017-05-18 17:28:48 +0200343 kfree(blkif->be->mode);
344 kfree(blkif->be);
Roger Pau Monnef929d422015-09-04 12:08:07 +0200345
346 /* Make sure everything is drained before shutting down */
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400347 kmem_cache_free(xen_blkif_cachep, blkif);
Paul Durrantfa2ac652019-12-10 14:53:05 +0000348 module_put(THIS_MODULE);
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400349}
350
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400351int __init xen_blkif_interface_init(void)
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400352{
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400353 xen_blkif_cachep = kmem_cache_create("blkif_cache",
Konrad Rzeszutek Wilk30fd1502011-05-12 16:47:48 -0400354 sizeof(struct xen_blkif),
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400355 0, 0, NULL);
356 if (!xen_blkif_cachep)
Konrad Rzeszutek Wilkee9ff852011-04-20 10:57:29 -0400357 return -ENOMEM;
358
359 return 0;
360}
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400361
Paul Durrant14855952019-12-02 11:41:17 +0000362void xen_blkif_interface_fini(void)
363{
364 kmem_cache_destroy(xen_blkif_cachep);
365 xen_blkif_cachep = NULL;
366}
367
Konrad Rzeszutek Wilka1397fa2011-04-14 17:05:23 -0400368/*
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400369 * sysfs interface for VBD I/O requests
370 */
371
Bob Liudb6fbc12015-12-09 07:44:02 +0800372#define VBD_SHOW_ALLRING(name, format) \
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400373 static ssize_t show_##name(struct device *_dev, \
374 struct device_attribute *attr, \
375 char *buf) \
376 { \
377 struct xenbus_device *dev = to_xenbus_device(_dev); \
Jeremy Fitzhardinge5cf6e4f2010-02-11 16:07:31 -0800378 struct backend_info *be = dev_get_drvdata(&dev->dev); \
Bob Liudb6fbc12015-12-09 07:44:02 +0800379 struct xen_blkif *blkif = be->blkif; \
380 unsigned int i; \
381 unsigned long long result = 0; \
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400382 \
Bob Liudb6fbc12015-12-09 07:44:02 +0800383 if (!blkif->rings) \
384 goto out; \
385 \
386 for (i = 0; i < blkif->nr_rings; i++) { \
387 struct xen_blkif_ring *ring = &blkif->rings[i]; \
388 \
389 result += ring->st_##name; \
390 } \
391 \
392out: \
393 return sprintf(buf, format, result); \
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400394 } \
Joe Perches5657a812018-05-24 13:38:59 -0600395 static DEVICE_ATTR(name, 0444, show_##name, NULL)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400396
Bob Liudb6fbc12015-12-09 07:44:02 +0800397VBD_SHOW_ALLRING(oo_req, "%llu\n");
398VBD_SHOW_ALLRING(rd_req, "%llu\n");
399VBD_SHOW_ALLRING(wr_req, "%llu\n");
400VBD_SHOW_ALLRING(f_req, "%llu\n");
401VBD_SHOW_ALLRING(ds_req, "%llu\n");
402VBD_SHOW_ALLRING(rd_sect, "%llu\n");
403VBD_SHOW_ALLRING(wr_sect, "%llu\n");
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400404
Konrad Rzeszutek Wilk3d814732011-05-12 16:53:56 -0400405static struct attribute *xen_vbdstat_attrs[] = {
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400406 &dev_attr_oo_req.attr,
407 &dev_attr_rd_req.attr,
408 &dev_attr_wr_req.attr,
Konrad Rzeszutek Wilk24f567f2011-05-04 17:07:27 -0400409 &dev_attr_f_req.attr,
Li Dongyangb3cb0d62011-09-01 18:39:10 +0800410 &dev_attr_ds_req.attr,
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400411 &dev_attr_rd_sect.attr,
412 &dev_attr_wr_sect.attr,
413 NULL
414};
415
Jan Beulich53043942016-07-07 01:38:58 -0600416static const struct attribute_group xen_vbdstat_group = {
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400417 .name = "statistics",
Konrad Rzeszutek Wilk3d814732011-05-12 16:53:56 -0400418 .attrs = xen_vbdstat_attrs,
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400419};
420
Bob Liudb6fbc12015-12-09 07:44:02 +0800421#define VBD_SHOW(name, format, args...) \
422 static ssize_t show_##name(struct device *_dev, \
423 struct device_attribute *attr, \
424 char *buf) \
425 { \
426 struct xenbus_device *dev = to_xenbus_device(_dev); \
427 struct backend_info *be = dev_get_drvdata(&dev->dev); \
428 \
429 return sprintf(buf, format, ##args); \
430 } \
Joe Perches5657a812018-05-24 13:38:59 -0600431 static DEVICE_ATTR(name, 0444, show_##name, NULL)
Bob Liudb6fbc12015-12-09 07:44:02 +0800432
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400433VBD_SHOW(physical_device, "%x:%x\n", be->major, be->minor);
434VBD_SHOW(mode, "%s\n", be->mode);
435
Konrad Rzeszutek Wilk29117582012-08-13 10:53:17 -0400436static int xenvbd_sysfs_addif(struct xenbus_device *dev)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400437{
438 int error;
439
440 error = device_create_file(&dev->dev, &dev_attr_physical_device);
Konrad Rzeszutek Wilkd6091b22011-04-14 17:33:30 -0400441 if (error)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400442 goto fail1;
443
444 error = device_create_file(&dev->dev, &dev_attr_mode);
445 if (error)
446 goto fail2;
447
Konrad Rzeszutek Wilk3d814732011-05-12 16:53:56 -0400448 error = sysfs_create_group(&dev->dev.kobj, &xen_vbdstat_group);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400449 if (error)
450 goto fail3;
451
452 return 0;
453
Konrad Rzeszutek Wilk3d814732011-05-12 16:53:56 -0400454fail3: sysfs_remove_group(&dev->dev.kobj, &xen_vbdstat_group);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400455fail2: device_remove_file(&dev->dev, &dev_attr_mode);
456fail1: device_remove_file(&dev->dev, &dev_attr_physical_device);
457 return error;
458}
459
Konrad Rzeszutek Wilk29117582012-08-13 10:53:17 -0400460static void xenvbd_sysfs_delif(struct xenbus_device *dev)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400461{
Konrad Rzeszutek Wilk3d814732011-05-12 16:53:56 -0400462 sysfs_remove_group(&dev->dev.kobj, &xen_vbdstat_group);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400463 device_remove_file(&dev->dev, &dev_attr_mode);
464 device_remove_file(&dev->dev, &dev_attr_physical_device);
465}
466
Konrad Rzeszutek Wilk3d814732011-05-12 16:53:56 -0400467static void xen_vbd_free(struct xen_vbd *vbd)
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400468{
469 if (vbd->bdev)
470 blkdev_put(vbd->bdev, vbd->readonly ? FMODE_READ : FMODE_WRITE);
471 vbd->bdev = NULL;
472}
473
SeongJae Parkaac8a702020-09-23 08:18:39 +0200474/* Enable the persistent grants feature. */
475static bool feature_persistent = true;
476module_param(feature_persistent, bool, 0644);
477MODULE_PARM_DESC(feature_persistent,
478 "Enables the persistent grants feature");
479
Konrad Rzeszutek Wilk3d814732011-05-12 16:53:56 -0400480static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle,
481 unsigned major, unsigned minor, int readonly,
482 int cdrom)
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400483{
Konrad Rzeszutek Wilk3d814732011-05-12 16:53:56 -0400484 struct xen_vbd *vbd;
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400485 struct block_device *bdev;
Konrad Rzeszutek Wilk24f567f2011-05-04 17:07:27 -0400486 struct request_queue *q;
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400487
488 vbd = &blkif->vbd;
489 vbd->handle = handle;
490 vbd->readonly = readonly;
491 vbd->type = 0;
492
493 vbd->pdevice = MKDEV(major, minor);
494
495 bdev = blkdev_get_by_dev(vbd->pdevice, vbd->readonly ?
496 FMODE_READ : FMODE_WRITE, NULL);
497
498 if (IS_ERR(bdev)) {
Tao Chen77387b82015-04-01 15:04:22 +0000499 pr_warn("xen_vbd_create: device %08x could not be opened\n",
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400500 vbd->pdevice);
501 return -ENOENT;
502 }
503
504 vbd->bdev = bdev;
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400505 if (vbd->bdev->bd_disk == NULL) {
Tao Chen77387b82015-04-01 15:04:22 +0000506 pr_warn("xen_vbd_create: device %08x doesn't exist\n",
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400507 vbd->pdevice);
Konrad Rzeszutek Wilk3d814732011-05-12 16:53:56 -0400508 xen_vbd_free(vbd);
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400509 return -ENOENT;
510 }
Laszlo Ersek64649202011-05-25 12:24:25 +0200511 vbd->size = vbd_sz(vbd);
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400512
513 if (vbd->bdev->bd_disk->flags & GENHD_FL_CD || cdrom)
514 vbd->type |= VDISK_CDROM;
515 if (vbd->bdev->bd_disk->flags & GENHD_FL_REMOVABLE)
516 vbd->type |= VDISK_REMOVABLE;
517
Konrad Rzeszutek Wilk24f567f2011-05-04 17:07:27 -0400518 q = bdev_get_queue(bdev);
Jens Axboec888a8f2016-04-13 13:33:19 -0600519 if (q && test_bit(QUEUE_FLAG_WC, &q->queue_flags))
Konrad Rzeszutek Wilk24f567f2011-05-04 17:07:27 -0400520 vbd->flush_support = true;
521
Christoph Hellwig288dab82016-06-09 16:00:36 +0200522 if (q && blk_queue_secure_erase(q))
Konrad Rzeszutek Wilk5ea42982011-10-12 16:23:30 -0400523 vbd->discard_secure = true;
524
SeongJae Parkaac8a702020-09-23 08:18:39 +0200525 vbd->feature_gnt_persistent = feature_persistent;
526
Tao Chen77387b82015-04-01 15:04:22 +0000527 pr_debug("Successful creation of handle=%04x (dom=%u)\n",
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400528 handle, blkif->domid);
529 return 0;
530}
SeongJae Park8557bbe2020-01-27 09:19:57 +0100531
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400532static int xen_blkbk_remove(struct xenbus_device *dev)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400533{
Jeremy Fitzhardinge5cf6e4f2010-02-11 16:07:31 -0800534 struct backend_info *be = dev_get_drvdata(&dev->dev);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400535
Tao Chen77387b82015-04-01 15:04:22 +0000536 pr_debug("%s %p %d\n", __func__, dev, dev->otherend_id);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400537
538 if (be->major || be->minor)
539 xenvbd_sysfs_delif(dev);
540
541 if (be->backend_watch.node) {
542 unregister_xenbus_watch(&be->backend_watch);
543 kfree(be->backend_watch.node);
544 be->backend_watch.node = NULL;
545 }
546
Valentin Priescu814d04e2014-05-20 22:28:50 +0200547 dev_set_drvdata(&dev->dev, NULL);
548
Gustavo A. R. Silva2d4456c2017-05-11 10:27:35 -0500549 if (be->blkif) {
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400550 xen_blkif_disconnect(be->blkif);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400551
Gustavo A. R. Silva2d4456c2017-05-11 10:27:35 -0500552 /* Put the reference we set in xen_blkif_alloc(). */
553 xen_blkif_put(be->blkif);
554 }
555
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400556 return 0;
557}
558
Konrad Rzeszutek Wilk24f567f2011-05-04 17:07:27 -0400559int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt,
560 struct backend_info *be, int state)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400561{
562 struct xenbus_device *dev = be->dev;
563 int err;
564
Konrad Rzeszutek Wilk24f567f2011-05-04 17:07:27 -0400565 err = xenbus_printf(xbt, dev->nodename, "feature-flush-cache",
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400566 "%d", state);
567 if (err)
Konrad Rzeszutek Wilk3389bb82012-03-14 13:04:00 -0400568 dev_warn(&dev->dev, "writing feature-flush-cache (%d)", err);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400569
570 return err;
571}
572
Konrad Rzeszutek Wilk3389bb82012-03-14 13:04:00 -0400573static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be)
Li Dongyangb3cb0d62011-09-01 18:39:10 +0800574{
575 struct xenbus_device *dev = be->dev;
576 struct xen_blkif *blkif = be->blkif;
Li Dongyangb3cb0d62011-09-01 18:39:10 +0800577 int err;
Juergen Gross82357772016-10-31 14:58:40 +0100578 int state = 0;
Konrad Rzeszutek Wilk4dae7672012-03-13 18:43:23 -0400579 struct block_device *bdev = be->blkif->vbd.bdev;
580 struct request_queue *q = bdev_get_queue(bdev);
Li Dongyangb3cb0d62011-09-01 18:39:10 +0800581
Juergen Gross82357772016-10-31 14:58:40 +0100582 if (!xenbus_read_unsigned(dev->nodename, "discard-enable", 1))
Olaf Heringc926b702014-05-21 16:32:42 +0200583 return;
584
Konrad Rzeszutek Wilk4dae7672012-03-13 18:43:23 -0400585 if (blk_queue_discard(q)) {
586 err = xenbus_printf(xbt, dev->nodename,
587 "discard-granularity", "%u",
588 q->limits.discard_granularity);
589 if (err) {
Konrad Rzeszutek Wilk3389bb82012-03-14 13:04:00 -0400590 dev_warn(&dev->dev, "writing discard-granularity (%d)", err);
591 return;
Li Dongyangb3cb0d62011-09-01 18:39:10 +0800592 }
Konrad Rzeszutek Wilk4dae7672012-03-13 18:43:23 -0400593 err = xenbus_printf(xbt, dev->nodename,
594 "discard-alignment", "%u",
595 q->limits.discard_alignment);
596 if (err) {
Konrad Rzeszutek Wilk3389bb82012-03-14 13:04:00 -0400597 dev_warn(&dev->dev, "writing discard-alignment (%d)", err);
598 return;
Konrad Rzeszutek Wilk4dae7672012-03-13 18:43:23 -0400599 }
600 state = 1;
601 /* Optional. */
602 err = xenbus_printf(xbt, dev->nodename,
603 "discard-secure", "%d",
604 blkif->vbd.discard_secure);
605 if (err) {
Konrad Rzeszutek Wilka71e23d2012-04-16 21:55:04 -0400606 dev_warn(&dev->dev, "writing discard-secure (%d)", err);
Konrad Rzeszutek Wilk3389bb82012-03-14 13:04:00 -0400607 return;
Li Dongyangb3cb0d62011-09-01 18:39:10 +0800608 }
Li Dongyangb3cb0d62011-09-01 18:39:10 +0800609 }
Li Dongyangb3cb0d62011-09-01 18:39:10 +0800610 err = xenbus_printf(xbt, dev->nodename, "feature-discard",
611 "%d", state);
612 if (err)
Konrad Rzeszutek Wilk3389bb82012-03-14 13:04:00 -0400613 dev_warn(&dev->dev, "writing feature-discard (%d)", err);
Li Dongyangb3cb0d62011-09-01 18:39:10 +0800614}
SeongJae Park8557bbe2020-01-27 09:19:57 +0100615
Konrad Rzeszutek Wilk29bde092011-10-10 00:42:22 -0400616int xen_blkbk_barrier(struct xenbus_transaction xbt,
617 struct backend_info *be, int state)
618{
619 struct xenbus_device *dev = be->dev;
620 int err;
621
622 err = xenbus_printf(xbt, dev->nodename, "feature-barrier",
623 "%d", state);
624 if (err)
Konrad Rzeszutek Wilk3389bb82012-03-14 13:04:00 -0400625 dev_warn(&dev->dev, "writing feature-barrier (%d)", err);
Konrad Rzeszutek Wilk29bde092011-10-10 00:42:22 -0400626
627 return err;
628}
Li Dongyangb3cb0d62011-09-01 18:39:10 +0800629
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -0400630/*
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400631 * Entry point to this code when a new device is created. Allocate the basic
632 * structures, and watch the store waiting for the hotplug scripts to tell us
633 * the device's physical major and minor numbers. Switch to InitWait.
634 */
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400635static int xen_blkbk_probe(struct xenbus_device *dev,
636 const struct xenbus_device_id *id)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400637{
638 int err;
639 struct backend_info *be = kzalloc(sizeof(struct backend_info),
640 GFP_KERNEL);
Tao Chen77387b82015-04-01 15:04:22 +0000641
642 /* match the pr_debug in xen_blkbk_remove */
643 pr_debug("%s %p %d\n", __func__, dev, dev->otherend_id);
644
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400645 if (!be) {
646 xenbus_dev_fatal(dev, -ENOMEM,
647 "allocating backend structure");
648 return -ENOMEM;
649 }
650 be->dev = dev;
Jeremy Fitzhardinge5cf6e4f2010-02-11 16:07:31 -0800651 dev_set_drvdata(&dev->dev, be);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400652
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400653 be->blkif = xen_blkif_alloc(dev->otherend_id);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400654 if (IS_ERR(be->blkif)) {
655 err = PTR_ERR(be->blkif);
656 be->blkif = NULL;
657 xenbus_dev_fatal(dev, err, "creating block interface");
658 goto fail;
659 }
660
Jan Beulich5a705842016-02-10 04:18:10 -0700661 err = xenbus_printf(XBT_NIL, dev->nodename,
662 "feature-max-indirect-segments", "%u",
663 MAX_INDIRECT_SEGMENTS);
664 if (err)
665 dev_warn(&dev->dev,
666 "writing %s/feature-max-indirect-segments (%d)",
667 dev->nodename, err);
668
Bob Liud62d8602015-11-14 11:12:17 +0800669 /* Multi-queue: advertise how many queues are supported by us.*/
670 err = xenbus_printf(XBT_NIL, dev->nodename,
671 "multi-queue-max-queues", "%u", xenblk_max_queues);
672 if (err)
673 pr_warn("Error writing multi-queue-max-queues\n");
674
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400675 /* setup back pointer */
676 be->blkif->be = be;
677
SeongJae Park2e85d322020-12-14 10:04:18 +0100678 err = xenbus_watch_pathfmt(dev, &be->backend_watch, NULL,
679 backend_changed,
Jeremy Fitzhardinge88122932009-02-09 12:05:51 -0800680 "%s/%s", dev->nodename, "physical-device");
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400681 if (err)
682 goto fail;
683
Bob Liu86839c52015-06-03 13:40:03 +0800684 err = xenbus_printf(XBT_NIL, dev->nodename, "max-ring-page-order", "%u",
685 xen_blkif_max_ring_order);
686 if (err)
687 pr_warn("%s write out 'max-ring-page-order' failed\n", __func__);
688
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400689 err = xenbus_switch_state(dev, XenbusStateInitWait);
690 if (err)
691 goto fail;
692
693 return 0;
694
695fail:
Tao Chen77387b82015-04-01 15:04:22 +0000696 pr_warn("%s failed\n", __func__);
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400697 xen_blkbk_remove(dev);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400698 return err;
699}
700
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -0400701/*
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400702 * Callback received when the hotplug scripts have placed the physical-device
703 * node. Read it and the mode node, and create a vbd. If the frontend is
704 * ready, connect.
705 */
706static void backend_changed(struct xenbus_watch *watch,
Juergen Gross5584ea22017-02-09 14:39:57 +0100707 const char *path, const char *token)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400708{
709 int err;
710 unsigned major;
711 unsigned minor;
712 struct backend_info *be
713 = container_of(watch, struct backend_info, backend_watch);
714 struct xenbus_device *dev = be->dev;
715 int cdrom = 0;
Jan Beulich9d092602012-12-20 10:31:11 +0000716 unsigned long handle;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400717 char *device_type;
718
Tao Chen77387b82015-04-01 15:04:22 +0000719 pr_debug("%s %p %d\n", __func__, dev, dev->otherend_id);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400720
721 err = xenbus_scanf(XBT_NIL, dev->nodename, "physical-device", "%x:%x",
722 &major, &minor);
723 if (XENBUS_EXIST_ERR(err)) {
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -0400724 /*
725 * Since this watch will fire once immediately after it is
726 * registered, we expect this. Ignore it, and wait for the
727 * hotplug scripts.
728 */
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400729 return;
730 }
731 if (err != 2) {
732 xenbus_dev_fatal(dev, err, "reading physical-device");
733 return;
734 }
735
Jan Beulich9d092602012-12-20 10:31:11 +0000736 if (be->major | be->minor) {
737 if (be->major != major || be->minor != minor)
Tao Chen77387b82015-04-01 15:04:22 +0000738 pr_warn("changing physical device (from %x:%x to %x:%x) not supported.\n",
Jan Beulich9d092602012-12-20 10:31:11 +0000739 be->major, be->minor, major, minor);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400740 return;
741 }
742
743 be->mode = xenbus_read(XBT_NIL, dev->nodename, "mode", NULL);
744 if (IS_ERR(be->mode)) {
745 err = PTR_ERR(be->mode);
746 be->mode = NULL;
747 xenbus_dev_fatal(dev, err, "reading mode");
748 return;
749 }
750
751 device_type = xenbus_read(XBT_NIL, dev->otherend, "device-type", NULL);
752 if (!IS_ERR(device_type)) {
753 cdrom = strcmp(device_type, "cdrom") == 0;
754 kfree(device_type);
755 }
756
Jan Beulich9d092602012-12-20 10:31:11 +0000757 /* Front end dir is a number, which is used as the handle. */
Jingoo Hanbb8e0e82013-09-11 14:20:07 -0700758 err = kstrtoul(strrchr(dev->otherend, '/') + 1, 0, &handle);
Jan Beulichaea305e12016-07-07 01:38:13 -0600759 if (err) {
760 kfree(be->mode);
761 be->mode = NULL;
Jan Beulich9d092602012-12-20 10:31:11 +0000762 return;
Jan Beulichaea305e12016-07-07 01:38:13 -0600763 }
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400764
Jan Beulich9d092602012-12-20 10:31:11 +0000765 be->major = major;
766 be->minor = minor;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400767
Jan Beulich9d092602012-12-20 10:31:11 +0000768 err = xen_vbd_create(be->blkif, handle, major, minor,
769 !strchr(be->mode, 'w'), cdrom);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400770
Jan Beulich9d092602012-12-20 10:31:11 +0000771 if (err)
772 xenbus_dev_fatal(dev, err, "creating vbd structure");
773 else {
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400774 err = xenvbd_sysfs_addif(dev);
775 if (err) {
Konrad Rzeszutek Wilk3d814732011-05-12 16:53:56 -0400776 xen_vbd_free(&be->blkif->vbd);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400777 xenbus_dev_fatal(dev, err, "creating sysfs entries");
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400778 }
Jan Beulich9d092602012-12-20 10:31:11 +0000779 }
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400780
Jan Beulich9d092602012-12-20 10:31:11 +0000781 if (err) {
782 kfree(be->mode);
783 be->mode = NULL;
784 be->major = 0;
785 be->minor = 0;
786 } else {
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400787 /* We're potentially connected now */
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400788 xen_update_blkif_status(be->blkif);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400789 }
790}
791
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -0400792/*
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400793 * Callback received when the frontend's state changes.
794 */
795static void frontend_changed(struct xenbus_device *dev,
796 enum xenbus_state frontend_state)
797{
Jeremy Fitzhardinge5cf6e4f2010-02-11 16:07:31 -0800798 struct backend_info *be = dev_get_drvdata(&dev->dev);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400799 int err;
800
Tao Chen77387b82015-04-01 15:04:22 +0000801 pr_debug("%s %p %s\n", __func__, dev, xenbus_strstate(frontend_state));
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400802
803 switch (frontend_state) {
804 case XenbusStateInitialising:
805 if (dev->state == XenbusStateClosed) {
Tao Chen77387b82015-04-01 15:04:22 +0000806 pr_info("%s: prepare for reconnect\n", dev->nodename);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400807 xenbus_switch_state(dev, XenbusStateInitWait);
808 }
809 break;
810
811 case XenbusStateInitialised:
812 case XenbusStateConnected:
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -0400813 /*
814 * Ensure we connect even when two watches fire in
Justin P. Mattock42b2aa82011-11-28 20:31:00 -0800815 * close succession and we miss the intermediate value
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -0400816 * of frontend_state.
817 */
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400818 if (dev->state == XenbusStateConnected)
819 break;
820
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -0400821 /*
822 * Enforce precondition before potential leak point.
Joe Jin1bc05b02011-08-15 12:57:07 +0800823 * xen_blkif_disconnect() is idempotent.
Keir Fraser313d7b02010-11-24 22:08:20 -0800824 */
Valentin Priescu814d04e2014-05-20 22:28:50 +0200825 err = xen_blkif_disconnect(be->blkif);
826 if (err) {
827 xenbus_dev_fatal(dev, err, "pending I/O");
828 break;
829 }
Keir Fraser313d7b02010-11-24 22:08:20 -0800830
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400831 err = connect_ring(be);
Konrad Rzeszutek Wilk2d0382f2015-11-25 13:20:14 -0500832 if (err) {
833 /*
834 * Clean up so that memory resources can be used by
835 * other devices. connect_ring reported already error.
836 */
837 xen_blkif_disconnect(be->blkif);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400838 break;
Konrad Rzeszutek Wilk2d0382f2015-11-25 13:20:14 -0500839 }
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -0400840 xen_update_blkif_status(be->blkif);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400841 break;
842
843 case XenbusStateClosing:
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400844 xenbus_switch_state(dev, XenbusStateClosing);
845 break;
846
847 case XenbusStateClosed:
Joe Jin6f5986b2011-08-15 12:51:31 +0800848 xen_blkif_disconnect(be->blkif);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400849 xenbus_switch_state(dev, XenbusStateClosed);
850 if (xenbus_dev_is_online(dev))
851 break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -0500852 fallthrough;
Bart Van Assche3f2c9402017-08-17 16:23:10 -0700853 /* if not online */
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400854 case XenbusStateUnknown:
Joe Jin1bc05b02011-08-15 12:57:07 +0800855 /* implies xen_blkif_disconnect() via xen_blkbk_remove() */
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400856 device_unregister(&dev->dev);
857 break;
858
859 default:
860 xenbus_dev_fatal(dev, -EINVAL, "saw state %d at frontend",
861 frontend_state);
862 break;
863 }
864}
865
SeongJae Parkcb9369b2020-01-27 09:18:10 +0100866/* Once a memory pressure is detected, squeeze free page pools for a while. */
867static unsigned int buffer_squeeze_duration_ms = 10;
868module_param_named(buffer_squeeze_duration_ms,
869 buffer_squeeze_duration_ms, int, 0644);
870MODULE_PARM_DESC(buffer_squeeze_duration_ms,
871"Duration in ms to squeeze pages buffer when a memory pressure is detected");
872
873/*
874 * Callback received when the memory pressure is detected.
875 */
876static void reclaim_memory(struct xenbus_device *dev)
877{
878 struct backend_info *be = dev_get_drvdata(&dev->dev);
879
880 if (!be)
881 return;
882 be->blkif->buffer_squeeze_end = jiffies +
883 msecs_to_jiffies(buffer_squeeze_duration_ms);
884}
885
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400886/* ** Connection ** */
887
Konrad Rzeszutek Wilk01f37f22011-05-11 15:57:09 -0400888/*
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400889 * Write the physical details regarding the block device to the store, and
890 * switch to Connected state.
891 */
892static void connect(struct backend_info *be)
893{
894 struct xenbus_transaction xbt;
895 int err;
896 struct xenbus_device *dev = be->dev;
897
Tao Chen77387b82015-04-01 15:04:22 +0000898 pr_debug("%s %s\n", __func__, dev->otherend);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400899
900 /* Supply the information about the device the frontend needs */
901again:
902 err = xenbus_transaction_start(&xbt);
903 if (err) {
904 xenbus_dev_fatal(dev, err, "starting transaction");
905 return;
906 }
907
Konrad Rzeszutek Wilk29bde092011-10-10 00:42:22 -0400908 /* If we can't advertise it is OK. */
Konrad Rzeszutek Wilk3389bb82012-03-14 13:04:00 -0400909 xen_blkbk_flush_diskcache(xbt, be, be->blkif->vbd.flush_support);
910
911 xen_blkbk_discard(xbt, be);
912
913 xen_blkbk_barrier(xbt, be, be->blkif->vbd.flush_support);
Konrad Rzeszutek Wilk29bde092011-10-10 00:42:22 -0400914
SeongJae Parkaac8a702020-09-23 08:18:39 +0200915 err = xenbus_printf(xbt, dev->nodename, "feature-persistent", "%u",
916 be->blkif->vbd.feature_gnt_persistent);
Roger Pau Monne0a8704a2012-10-24 18:58:45 +0200917 if (err) {
918 xenbus_dev_fatal(dev, err, "writing %s/feature-persistent",
919 dev->nodename);
920 goto abort;
921 }
922
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400923 err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu",
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400924 (unsigned long long)vbd_sz(&be->blkif->vbd));
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400925 if (err) {
926 xenbus_dev_fatal(dev, err, "writing %s/sectors",
927 dev->nodename);
928 goto abort;
929 }
930
931 /* FIXME: use a typename instead */
932 err = xenbus_printf(xbt, dev->nodename, "info", "%u",
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400933 be->blkif->vbd.type |
934 (be->blkif->vbd.readonly ? VDISK_READONLY : 0));
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400935 if (err) {
936 xenbus_dev_fatal(dev, err, "writing %s/info",
937 dev->nodename);
938 goto abort;
939 }
940 err = xenbus_printf(xbt, dev->nodename, "sector-size", "%lu",
Konrad Rzeszutek Wilk42c78412011-04-20 11:21:43 -0400941 (unsigned long)
942 bdev_logical_block_size(be->blkif->vbd.bdev));
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400943 if (err) {
944 xenbus_dev_fatal(dev, err, "writing %s/sector-size",
945 dev->nodename);
946 goto abort;
947 }
Stefan Bader7c4d7d72013-05-13 16:28:15 +0200948 err = xenbus_printf(xbt, dev->nodename, "physical-sector-size", "%u",
949 bdev_physical_block_size(be->blkif->vbd.bdev));
950 if (err)
951 xenbus_dev_error(dev, err, "writing %s/physical-sector-size",
952 dev->nodename);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400953
954 err = xenbus_transaction_end(xbt, 0);
955 if (err == -EAGAIN)
956 goto again;
957 if (err)
958 xenbus_dev_fatal(dev, err, "ending transaction");
959
960 err = xenbus_switch_state(dev, XenbusStateConnected);
961 if (err)
Joe Perches08b8bfc2011-06-12 09:21:13 -0700962 xenbus_dev_fatal(dev, err, "%s: switching to Connected state",
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400963 dev->nodename);
964
965 return;
966 abort:
967 xenbus_transaction_end(xbt, 1);
968}
969
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500970/*
971 * Each ring may have multi pages, depends on "ring-page-order".
972 */
973static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400974{
Julien Grall9cce2912015-10-13 17:50:11 +0100975 unsigned int ring_ref[XENBUS_MAX_RING_GRANTS];
Bob Liu69b91ed2015-06-03 13:40:01 +0800976 struct pending_req *req, *n;
977 int err, i, j;
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500978 struct xen_blkif *blkif = ring->blkif;
979 struct xenbus_device *dev = blkif->be->dev;
Dongli Zhang4a8c31a2019-02-24 10:17:27 -0500980 unsigned int nr_grefs, evtchn;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400981
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500982 err = xenbus_scanf(XBT_NIL, dir, "event-channel", "%u",
Bob Liu86839c52015-06-03 13:40:03 +0800983 &evtchn);
984 if (err != 1) {
985 err = -EINVAL;
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -0500986 xenbus_dev_fatal(dev, err, "reading %s/event-channel", dir);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -0400987 return err;
988 }
Bob Liu86839c52015-06-03 13:40:03 +0800989
Dongli Zhang4a8c31a2019-02-24 10:17:27 -0500990 nr_grefs = blkif->nr_ring_pages;
991
992 if (unlikely(!nr_grefs)) {
993 WARN_ON(true);
994 return -EINVAL;
995 }
996
997 for (i = 0; i < nr_grefs; i++) {
998 char ring_ref_name[RINGREF_NAME_LEN];
999
Paul Durrantd75e7f62021-02-02 17:56:59 +00001000 if (blkif->multi_ref)
1001 snprintf(ring_ref_name, RINGREF_NAME_LEN, "ring-ref%u", i);
1002 else {
1003 WARN_ON(i != 0);
1004 snprintf(ring_ref_name, RINGREF_NAME_LEN, "ring-ref");
1005 }
1006
Dongli Zhang4a8c31a2019-02-24 10:17:27 -05001007 err = xenbus_scanf(XBT_NIL, dir, ring_ref_name,
1008 "%u", &ring_ref[i]);
1009
1010 if (err != 1) {
Dongli Zhang4a8c31a2019-02-24 10:17:27 -05001011 err = -EINVAL;
1012 xenbus_dev_fatal(dev, err, "reading %s/%s",
1013 dir, ring_ref_name);
1014 return err;
1015 }
1016 }
1017
Wenwen Wangae78ca32019-08-11 12:23:22 -05001018 err = -ENOMEM;
Bob Liu86839c52015-06-03 13:40:03 +08001019 for (i = 0; i < nr_grefs * XEN_BLKIF_REQS_PER_PAGE; i++) {
Bob Liu69b91ed2015-06-03 13:40:01 +08001020 req = kzalloc(sizeof(*req), GFP_KERNEL);
1021 if (!req)
1022 goto fail;
Bob Liu59795702015-11-14 11:12:15 +08001023 list_add_tail(&req->free_list, &ring->pending_free);
Bob Liu69b91ed2015-06-03 13:40:01 +08001024 for (j = 0; j < MAX_INDIRECT_SEGMENTS; j++) {
1025 req->segments[j] = kzalloc(sizeof(*req->segments[0]), GFP_KERNEL);
1026 if (!req->segments[j])
1027 goto fail;
1028 }
1029 for (j = 0; j < MAX_INDIRECT_PAGES; j++) {
1030 req->indirect_pages[j] = kzalloc(sizeof(*req->indirect_pages[0]),
1031 GFP_KERNEL);
1032 if (!req->indirect_pages[j])
1033 goto fail;
1034 }
1035 }
1036
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -04001037 /* Map the shared frame, irq etc. */
Bob Liu59795702015-11-14 11:12:15 +08001038 err = xen_blkif_map(ring, ring_ref, nr_grefs, evtchn);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -04001039 if (err) {
Bob Liu86839c52015-06-03 13:40:03 +08001040 xenbus_dev_fatal(dev, err, "mapping ring-ref port %u", evtchn);
Wenwen Wangae78ca32019-08-11 12:23:22 -05001041 goto fail;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -04001042 }
1043
1044 return 0;
Bob Liu69b91ed2015-06-03 13:40:01 +08001045
1046fail:
Bob Liu59795702015-11-14 11:12:15 +08001047 list_for_each_entry_safe(req, n, &ring->pending_free, free_list) {
Bob Liu69b91ed2015-06-03 13:40:01 +08001048 list_del(&req->free_list);
1049 for (j = 0; j < MAX_INDIRECT_SEGMENTS; j++) {
1050 if (!req->segments[j])
1051 break;
1052 kfree(req->segments[j]);
1053 }
1054 for (j = 0; j < MAX_INDIRECT_PAGES; j++) {
1055 if (!req->indirect_pages[j])
1056 break;
1057 kfree(req->indirect_pages[j]);
1058 }
1059 kfree(req);
1060 }
Wenwen Wangae78ca32019-08-11 12:23:22 -05001061 return err;
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001062}
1063
1064static int connect_ring(struct backend_info *be)
1065{
1066 struct xenbus_device *dev = be->dev;
Dongli Zhang5b8e4322019-01-15 00:41:43 +08001067 struct xen_blkif *blkif = be->blkif;
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001068 char protocol[64] = "";
1069 int err, i;
1070 char *xspath;
1071 size_t xspathsize;
1072 const size_t xenstore_path_ext_size = 11; /* sufficient for "/queue-NNN" */
Bob Liud62d8602015-11-14 11:12:17 +08001073 unsigned int requested_num_queues = 0;
Dongli Zhang4a8c31a2019-02-24 10:17:27 -05001074 unsigned int ring_page_order;
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001075
1076 pr_debug("%s %s\n", __func__, dev->otherend);
1077
Dongli Zhang5b8e4322019-01-15 00:41:43 +08001078 blkif->blk_protocol = BLKIF_PROTOCOL_DEFAULT;
Jan Beulich66943892016-07-07 02:05:21 -06001079 err = xenbus_scanf(XBT_NIL, dev->otherend, "protocol",
1080 "%63s", protocol);
1081 if (err <= 0)
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001082 strcpy(protocol, "unspecified, assuming default");
1083 else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_NATIVE))
Dongli Zhang5b8e4322019-01-15 00:41:43 +08001084 blkif->blk_protocol = BLKIF_PROTOCOL_NATIVE;
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001085 else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_32))
Dongli Zhang5b8e4322019-01-15 00:41:43 +08001086 blkif->blk_protocol = BLKIF_PROTOCOL_X86_32;
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001087 else if (0 == strcmp(protocol, XEN_IO_PROTO_ABI_X86_64))
Dongli Zhang5b8e4322019-01-15 00:41:43 +08001088 blkif->blk_protocol = BLKIF_PROTOCOL_X86_64;
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001089 else {
1090 xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol);
Konrad Rzeszutek Wilkbde21f72015-11-25 13:07:39 -05001091 return -ENOSYS;
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001092 }
SeongJae Parkaac8a702020-09-23 08:18:39 +02001093 if (blkif->vbd.feature_gnt_persistent)
1094 blkif->vbd.feature_gnt_persistent =
1095 xenbus_read_unsigned(dev->otherend,
1096 "feature-persistent", 0);
1097
Dongli Zhang5b8e4322019-01-15 00:41:43 +08001098 blkif->vbd.overflow_max_grants = 0;
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001099
Bob Liud62d8602015-11-14 11:12:17 +08001100 /*
1101 * Read the number of hardware queues from frontend.
1102 */
Juergen Gross82357772016-10-31 14:58:40 +01001103 requested_num_queues = xenbus_read_unsigned(dev->otherend,
1104 "multi-queue-num-queues",
1105 1);
1106 if (requested_num_queues > xenblk_max_queues
1107 || requested_num_queues == 0) {
1108 /* Buggy or malicious guest. */
1109 xenbus_dev_fatal(dev, err,
1110 "guest requested %u queues, exceeding the maximum of %u.",
1111 requested_num_queues, xenblk_max_queues);
1112 return -ENOSYS;
Bob Liud62d8602015-11-14 11:12:17 +08001113 }
Dongli Zhang5b8e4322019-01-15 00:41:43 +08001114 blkif->nr_rings = requested_num_queues;
1115 if (xen_blkif_alloc_rings(blkif))
Bob Liud62d8602015-11-14 11:12:17 +08001116 return -ENOMEM;
1117
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001118 pr_info("%s: using %d queues, protocol %d (%s) %s\n", dev->nodename,
Dongli Zhang5b8e4322019-01-15 00:41:43 +08001119 blkif->nr_rings, blkif->blk_protocol, protocol,
SeongJae Parkaac8a702020-09-23 08:18:39 +02001120 blkif->vbd.feature_gnt_persistent ? "persistent grants" : "");
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001121
Paul Durrantd75e7f62021-02-02 17:56:59 +00001122 err = xenbus_scanf(XBT_NIL, dev->otherend, "ring-page-order", "%u",
1123 &ring_page_order);
1124 if (err != 1) {
1125 blkif->nr_ring_pages = 1;
1126 blkif->multi_ref = false;
1127 } else if (ring_page_order <= xen_blkif_max_ring_order) {
1128 blkif->nr_ring_pages = 1 << ring_page_order;
1129 blkif->multi_ref = true;
1130 } else {
Dongli Zhang4a8c31a2019-02-24 10:17:27 -05001131 err = -EINVAL;
1132 xenbus_dev_fatal(dev, err,
1133 "requested ring page order %d exceed max:%d",
1134 ring_page_order,
1135 xen_blkif_max_ring_order);
1136 return err;
1137 }
1138
Dongli Zhang5b8e4322019-01-15 00:41:43 +08001139 if (blkif->nr_rings == 1)
1140 return read_per_ring_refs(&blkif->rings[0], dev->otherend);
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001141 else {
1142 xspathsize = strlen(dev->otherend) + xenstore_path_ext_size;
1143 xspath = kmalloc(xspathsize, GFP_KERNEL);
1144 if (!xspath) {
1145 xenbus_dev_fatal(dev, -ENOMEM, "reading ring references");
1146 return -ENOMEM;
1147 }
1148
Dongli Zhang5b8e4322019-01-15 00:41:43 +08001149 for (i = 0; i < blkif->nr_rings; i++) {
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001150 memset(xspath, 0, xspathsize);
1151 snprintf(xspath, xspathsize, "%s/queue-%u", dev->otherend, i);
Dongli Zhang5b8e4322019-01-15 00:41:43 +08001152 err = read_per_ring_refs(&blkif->rings[i], xspath);
Konrad Rzeszutek Wilk2fb1ef42015-12-11 12:08:48 -05001153 if (err) {
1154 kfree(xspath);
1155 return err;
1156 }
1157 }
1158 kfree(xspath);
1159 }
1160 return 0;
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -04001161}
1162
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -04001163static const struct xenbus_device_id xen_blkbk_ids[] = {
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -04001164 { "vbd" },
1165 { "" }
1166};
1167
David Vrabel95afae42014-09-08 17:30:41 +01001168static struct xenbus_driver xen_blkbk_driver = {
1169 .ids = xen_blkbk_ids,
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -04001170 .probe = xen_blkbk_probe,
1171 .remove = xen_blkbk_remove,
Paul Durrantf4eef1b2019-12-11 15:29:56 +00001172 .otherend_changed = frontend_changed,
1173 .allow_rebind = true,
SeongJae Parkcb9369b2020-01-27 09:18:10 +01001174 .reclaim_memory = reclaim_memory,
David Vrabel95afae42014-09-08 17:30:41 +01001175};
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -04001176
Konrad Rzeszutek Wilk8b6bf742011-04-20 11:50:43 -04001177int xen_blkif_xenbus_init(void)
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -04001178{
Jan Beulich73db1442011-12-22 09:08:13 +00001179 return xenbus_register_backend(&xen_blkbk_driver);
Konrad Rzeszutek Wilk4d05a282011-04-14 18:25:47 -04001180}
Paul Durrant14855952019-12-02 11:41:17 +00001181
1182void xen_blkif_xenbus_fini(void)
1183{
1184 xenbus_unregister_driver(&xen_blkbk_driver);
1185}