| 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* |
| 3 | * linux/fs/9p/trans_xen |
| 4 | * |
| 5 | * Xen transport layer. |
| 6 | * |
| 7 | * Copyright (C) 2017 by Stefano Stabellini <stefano@aporeto.com> |
| 8 | */ |
| 9 | |
| 10 | #include <xen/events.h> |
| 11 | #include <xen/grant_table.h> |
| 12 | #include <xen/xen.h> |
| 13 | #include <xen/xenbus.h> |
| 14 | #include <xen/interface/io/9pfs.h> |
| 15 | |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/spinlock.h> |
| 18 | #include <linux/fs_context.h> |
| 19 | #include <net/9p/9p.h> |
| 20 | #include <net/9p/client.h> |
| 21 | #include <net/9p/transport.h> |
| 22 | |
| 23 | #define XEN_9PFS_NUM_RINGS 2 |
| 24 | #define XEN_9PFS_RING_ORDER 9 |
| 25 | #define XEN_9PFS_RING_SIZE(ring) XEN_FLEX_RING_SIZE(ring->intf->ring_order) |
| 26 | |
| 27 | struct { |
| 28 | uint32_t ; |
| 29 | uint8_t ; |
| 30 | uint16_t ; |
| 31 | |
| 32 | /* uint8_t sdata[]; */ |
| 33 | } __attribute__((packed)); |
| 34 | |
| 35 | /* One per ring, more than one per 9pfs share */ |
| 36 | struct xen_9pfs_dataring { |
| 37 | struct xen_9pfs_front_priv *priv; |
| 38 | |
| 39 | struct xen_9pfs_data_intf *intf; |
| 40 | grant_ref_t ref; |
| 41 | int evtchn; |
| 42 | int irq; |
| 43 | /* protect a ring from concurrent accesses */ |
| 44 | spinlock_t lock; |
| 45 | |
| 46 | struct xen_9pfs_data data; |
| 47 | wait_queue_head_t wq; |
| 48 | struct work_struct work; |
| 49 | }; |
| 50 | |
| 51 | /* One per 9pfs share */ |
| 52 | struct xen_9pfs_front_priv { |
| 53 | struct list_head list; |
| 54 | struct xenbus_device *dev; |
| 55 | char *tag; |
| 56 | struct p9_client *client; |
| 57 | |
| 58 | struct xen_9pfs_dataring *rings; |
| 59 | }; |
| 60 | |
| 61 | static LIST_HEAD(xen_9pfs_devs); |
| 62 | static DEFINE_RWLOCK(xen_9pfs_lock); |
| 63 | |
| 64 | /* We don't currently allow canceling of requests */ |
| 65 | static int p9_xen_cancel(struct p9_client *client, struct p9_req_t *req) |
| 66 | { |
| 67 | return 1; |
| 68 | } |
| 69 | |
| 70 | static int p9_xen_create(struct p9_client *client, struct fs_context *fc) |
| 71 | { |
| 72 | const char *addr = fc->source; |
| 73 | struct xen_9pfs_front_priv *priv; |
| 74 | |
| 75 | if (addr == NULL) |
| 76 | return -EINVAL; |
| 77 | |
| 78 | read_lock(&xen_9pfs_lock); |
| 79 | list_for_each_entry(priv, &xen_9pfs_devs, list) { |
| 80 | if (!strcmp(priv->tag, addr)) { |
| 81 | priv->client = client; |
| 82 | read_unlock(&xen_9pfs_lock); |
| 83 | return 0; |
| 84 | } |
| 85 | } |
| 86 | read_unlock(&xen_9pfs_lock); |
| 87 | return -EINVAL; |
| 88 | } |
| 89 | |
| 90 | static void p9_xen_close(struct p9_client *client) |
| 91 | { |
| 92 | struct xen_9pfs_front_priv *priv; |
| 93 | |
| 94 | read_lock(&xen_9pfs_lock); |
| 95 | list_for_each_entry(priv, &xen_9pfs_devs, list) { |
| 96 | if (priv->client == client) { |
| 97 | priv->client = NULL; |
| 98 | read_unlock(&xen_9pfs_lock); |
| 99 | return; |
| 100 | } |
| 101 | } |
| 102 | read_unlock(&xen_9pfs_lock); |
| 103 | } |
| 104 | |
| 105 | static bool p9_xen_write_todo(struct xen_9pfs_dataring *ring, RING_IDX size) |
| 106 | { |
| 107 | RING_IDX cons, prod; |
| 108 | |
| 109 | cons = ring->intf->out_cons; |
| 110 | prod = ring->intf->out_prod; |
| 111 | virt_mb(); |
| 112 | |
| 113 | return XEN_9PFS_RING_SIZE(ring) - |
| 114 | xen_9pfs_queued(prod, cons, XEN_9PFS_RING_SIZE(ring)) >= size; |
| 115 | } |
| 116 | |
| 117 | static int p9_xen_request(struct p9_client *client, struct p9_req_t *p9_req) |
| 118 | { |
| 119 | struct xen_9pfs_front_priv *priv; |
| 120 | RING_IDX cons, prod, masked_cons, masked_prod; |
| 121 | unsigned long flags; |
| 122 | u32 size = p9_req->tc.size; |
| 123 | struct xen_9pfs_dataring *ring; |
| 124 | int num; |
| 125 | |
| 126 | read_lock(&xen_9pfs_lock); |
| 127 | list_for_each_entry(priv, &xen_9pfs_devs, list) { |
| 128 | if (priv->client == client) |
| 129 | break; |
| 130 | } |
| 131 | read_unlock(&xen_9pfs_lock); |
| 132 | if (list_entry_is_head(priv, &xen_9pfs_devs, list)) |
| 133 | return -EINVAL; |
| 134 | |
| 135 | num = p9_req->tc.tag % XEN_9PFS_NUM_RINGS; |
| 136 | ring = &priv->rings[num]; |
| 137 | |
| 138 | again: |
| 139 | while (wait_event_killable(ring->wq, |
| 140 | p9_xen_write_todo(ring, size)) != 0) |
| 141 | ; |
| 142 | |
| 143 | spin_lock_irqsave(&ring->lock, flags); |
| 144 | cons = ring->intf->out_cons; |
| 145 | prod = ring->intf->out_prod; |
| 146 | virt_mb(); |
| 147 | |
| 148 | if (XEN_9PFS_RING_SIZE(ring) - |
| 149 | xen_9pfs_queued(prod, cons, XEN_9PFS_RING_SIZE(ring)) < size) { |
| 150 | spin_unlock_irqrestore(lock: &ring->lock, flags); |
| 151 | goto again; |
| 152 | } |
| 153 | |
| 154 | masked_prod = xen_9pfs_mask(idx: prod, XEN_9PFS_RING_SIZE(ring)); |
| 155 | masked_cons = xen_9pfs_mask(idx: cons, XEN_9PFS_RING_SIZE(ring)); |
| 156 | |
| 157 | xen_9pfs_write_packet(buf: ring->data.out, opaque: p9_req->tc.sdata, size, |
| 158 | masked_prod: &masked_prod, masked_cons, |
| 159 | XEN_9PFS_RING_SIZE(ring)); |
| 160 | |
| 161 | WRITE_ONCE(p9_req->status, REQ_STATUS_SENT); |
| 162 | virt_wmb(); /* write ring before updating pointer */ |
| 163 | prod += size; |
| 164 | ring->intf->out_prod = prod; |
| 165 | spin_unlock_irqrestore(lock: &ring->lock, flags); |
| 166 | notify_remote_via_irq(irq: ring->irq); |
| 167 | p9_req_put(c: client, r: p9_req); |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static void p9_xen_response(struct work_struct *work) |
| 173 | { |
| 174 | struct xen_9pfs_front_priv *priv; |
| 175 | struct xen_9pfs_dataring *ring; |
| 176 | RING_IDX cons, prod, masked_cons, masked_prod; |
| 177 | struct xen_9pfs_header h; |
| 178 | struct p9_req_t *req; |
| 179 | int status; |
| 180 | |
| 181 | ring = container_of(work, struct xen_9pfs_dataring, work); |
| 182 | priv = ring->priv; |
| 183 | |
| 184 | while (1) { |
| 185 | cons = ring->intf->in_cons; |
| 186 | prod = ring->intf->in_prod; |
| 187 | virt_rmb(); |
| 188 | |
| 189 | if (xen_9pfs_queued(prod, cons, XEN_9PFS_RING_SIZE(ring)) < |
| 190 | sizeof(h)) { |
| 191 | notify_remote_via_irq(irq: ring->irq); |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | masked_prod = xen_9pfs_mask(idx: prod, XEN_9PFS_RING_SIZE(ring)); |
| 196 | masked_cons = xen_9pfs_mask(idx: cons, XEN_9PFS_RING_SIZE(ring)); |
| 197 | |
| 198 | /* First, read just the header */ |
| 199 | xen_9pfs_read_packet(opaque: &h, buf: ring->data.in, size: sizeof(h), |
| 200 | masked_prod, masked_cons: &masked_cons, |
| 201 | XEN_9PFS_RING_SIZE(ring)); |
| 202 | |
| 203 | req = p9_tag_lookup(c: priv->client, tag: h.tag); |
| 204 | if (!req || req->status != REQ_STATUS_SENT) { |
| 205 | dev_warn(&priv->dev->dev, "Wrong req tag=%x\n" , h.tag); |
| 206 | cons += h.size; |
| 207 | virt_mb(); |
| 208 | ring->intf->in_cons = cons; |
| 209 | continue; |
| 210 | } |
| 211 | |
| 212 | if (h.size > req->rc.capacity) { |
| 213 | dev_warn(&priv->dev->dev, |
| 214 | "requested packet size too big: %d for tag %d with capacity %zd\n" , |
| 215 | h.size, h.tag, req->rc.capacity); |
| 216 | WRITE_ONCE(req->status, REQ_STATUS_ERROR); |
| 217 | goto recv_error; |
| 218 | } |
| 219 | |
| 220 | req->rc.size = h.size; |
| 221 | req->rc.id = h.id; |
| 222 | req->rc.tag = h.tag; |
| 223 | req->rc.offset = 0; |
| 224 | |
| 225 | masked_cons = xen_9pfs_mask(idx: cons, XEN_9PFS_RING_SIZE(ring)); |
| 226 | /* Then, read the whole packet (including the header) */ |
| 227 | xen_9pfs_read_packet(opaque: req->rc.sdata, buf: ring->data.in, size: h.size, |
| 228 | masked_prod, masked_cons: &masked_cons, |
| 229 | XEN_9PFS_RING_SIZE(ring)); |
| 230 | |
| 231 | recv_error: |
| 232 | virt_mb(); |
| 233 | cons += h.size; |
| 234 | ring->intf->in_cons = cons; |
| 235 | |
| 236 | status = (req->status != REQ_STATUS_ERROR) ? |
| 237 | REQ_STATUS_RCVD : REQ_STATUS_ERROR; |
| 238 | |
| 239 | p9_client_cb(c: priv->client, req, status); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | static irqreturn_t xen_9pfs_front_event_handler(int irq, void *r) |
| 244 | { |
| 245 | struct xen_9pfs_dataring *ring = r; |
| 246 | |
| 247 | if (!ring || !ring->priv->client) { |
| 248 | /* ignore spurious interrupt */ |
| 249 | return IRQ_HANDLED; |
| 250 | } |
| 251 | |
| 252 | wake_up_interruptible(&ring->wq); |
| 253 | schedule_work(work: &ring->work); |
| 254 | |
| 255 | return IRQ_HANDLED; |
| 256 | } |
| 257 | |
| 258 | static struct p9_trans_module p9_xen_trans = { |
| 259 | .name = "xen" , |
| 260 | .maxsize = 1 << (XEN_9PFS_RING_ORDER + XEN_PAGE_SHIFT - 2), |
| 261 | .pooled_rbuffers = false, |
| 262 | .def = true, |
| 263 | .supports_vmalloc = false, |
| 264 | .create = p9_xen_create, |
| 265 | .close = p9_xen_close, |
| 266 | .request = p9_xen_request, |
| 267 | .cancel = p9_xen_cancel, |
| 268 | .owner = THIS_MODULE, |
| 269 | }; |
| 270 | |
| 271 | static const struct xenbus_device_id xen_9pfs_front_ids[] = { |
| 272 | { "9pfs" }, |
| 273 | { "" } |
| 274 | }; |
| 275 | |
| 276 | static void xen_9pfs_front_free(struct xen_9pfs_front_priv *priv) |
| 277 | { |
| 278 | int i, j; |
| 279 | |
| 280 | write_lock(&xen_9pfs_lock); |
| 281 | list_del(entry: &priv->list); |
| 282 | write_unlock(&xen_9pfs_lock); |
| 283 | |
| 284 | for (i = 0; i < XEN_9PFS_NUM_RINGS; i++) { |
| 285 | struct xen_9pfs_dataring *ring = &priv->rings[i]; |
| 286 | |
| 287 | cancel_work_sync(work: &ring->work); |
| 288 | |
| 289 | if (!priv->rings[i].intf) |
| 290 | break; |
| 291 | if (priv->rings[i].irq > 0) |
| 292 | unbind_from_irqhandler(irq: priv->rings[i].irq, dev_id: ring); |
| 293 | if (priv->rings[i].data.in) { |
| 294 | for (j = 0; |
| 295 | j < (1 << priv->rings[i].intf->ring_order); |
| 296 | j++) { |
| 297 | grant_ref_t ref; |
| 298 | |
| 299 | ref = priv->rings[i].intf->ref[j]; |
| 300 | gnttab_end_foreign_access(ref, NULL); |
| 301 | } |
| 302 | free_pages_exact(virt: priv->rings[i].data.in, |
| 303 | size: 1UL << (priv->rings[i].intf->ring_order + |
| 304 | XEN_PAGE_SHIFT)); |
| 305 | } |
| 306 | gnttab_end_foreign_access(ref: priv->rings[i].ref, NULL); |
| 307 | free_page((unsigned long)priv->rings[i].intf); |
| 308 | } |
| 309 | kfree(objp: priv->rings); |
| 310 | kfree(objp: priv->tag); |
| 311 | kfree(objp: priv); |
| 312 | } |
| 313 | |
| 314 | static void xen_9pfs_front_remove(struct xenbus_device *dev) |
| 315 | { |
| 316 | struct xen_9pfs_front_priv *priv = dev_get_drvdata(dev: &dev->dev); |
| 317 | |
| 318 | dev_set_drvdata(dev: &dev->dev, NULL); |
| 319 | xen_9pfs_front_free(priv); |
| 320 | } |
| 321 | |
| 322 | static int xen_9pfs_front_alloc_dataring(struct xenbus_device *dev, |
| 323 | struct xen_9pfs_dataring *ring, |
| 324 | unsigned int order) |
| 325 | { |
| 326 | int i = 0; |
| 327 | int ret = -ENOMEM; |
| 328 | void *bytes = NULL; |
| 329 | |
| 330 | init_waitqueue_head(&ring->wq); |
| 331 | spin_lock_init(&ring->lock); |
| 332 | INIT_WORK(&ring->work, p9_xen_response); |
| 333 | |
| 334 | ring->intf = (struct xen_9pfs_data_intf *)get_zeroed_page(GFP_KERNEL); |
| 335 | if (!ring->intf) |
| 336 | return ret; |
| 337 | ret = gnttab_grant_foreign_access(domid: dev->otherend_id, |
| 338 | virt_to_gfn(ring->intf), readonly: 0); |
| 339 | if (ret < 0) |
| 340 | goto out; |
| 341 | ring->ref = ret; |
| 342 | bytes = alloc_pages_exact(1UL << (order + XEN_PAGE_SHIFT), |
| 343 | GFP_KERNEL | __GFP_ZERO); |
| 344 | if (!bytes) { |
| 345 | ret = -ENOMEM; |
| 346 | goto out; |
| 347 | } |
| 348 | for (; i < (1 << order); i++) { |
| 349 | ret = gnttab_grant_foreign_access( |
| 350 | domid: dev->otherend_id, virt_to_gfn(bytes) + i, readonly: 0); |
| 351 | if (ret < 0) |
| 352 | goto out; |
| 353 | ring->intf->ref[i] = ret; |
| 354 | } |
| 355 | ring->intf->ring_order = order; |
| 356 | ring->data.in = bytes; |
| 357 | ring->data.out = bytes + XEN_FLEX_RING_SIZE(order); |
| 358 | |
| 359 | ret = xenbus_alloc_evtchn(dev, port: &ring->evtchn); |
| 360 | if (ret) |
| 361 | goto out; |
| 362 | ring->irq = bind_evtchn_to_irqhandler(evtchn: ring->evtchn, |
| 363 | handler: xen_9pfs_front_event_handler, |
| 364 | irqflags: 0, devname: "xen_9pfs-frontend" , dev_id: ring); |
| 365 | if (ring->irq >= 0) |
| 366 | return 0; |
| 367 | |
| 368 | xenbus_free_evtchn(dev, port: ring->evtchn); |
| 369 | ret = ring->irq; |
| 370 | out: |
| 371 | if (bytes) { |
| 372 | for (i--; i >= 0; i--) |
| 373 | gnttab_end_foreign_access(ref: ring->intf->ref[i], NULL); |
| 374 | free_pages_exact(virt: bytes, size: 1UL << (order + XEN_PAGE_SHIFT)); |
| 375 | } |
| 376 | gnttab_end_foreign_access(ref: ring->ref, NULL); |
| 377 | free_page((unsigned long)ring->intf); |
| 378 | return ret; |
| 379 | } |
| 380 | |
| 381 | static int xen_9pfs_front_init(struct xenbus_device *dev) |
| 382 | { |
| 383 | int ret, i; |
| 384 | struct xenbus_transaction xbt; |
| 385 | struct xen_9pfs_front_priv *priv = dev_get_drvdata(dev: &dev->dev); |
| 386 | char *versions, *v; |
| 387 | unsigned int max_rings, max_ring_order, len = 0; |
| 388 | |
| 389 | versions = xenbus_read(XBT_NIL, dir: dev->otherend, node: "versions" , len: &len); |
| 390 | if (IS_ERR(versions)) |
| 391 | return PTR_ERR(versions); |
| 392 | for (v = versions; *v; v++) { |
| 393 | if (simple_strtoul(v, &v, 10) == 1) { |
| 394 | v = NULL; |
| 395 | break; |
| 396 | } |
| 397 | } |
| 398 | if (v) { |
| 399 | kfree(versions); |
| 400 | return -EINVAL; |
| 401 | } |
| 402 | kfree(versions); |
| 403 | max_rings = xenbus_read_unsigned(dev->otherend, "max-rings" , 0); |
| 404 | if (max_rings < XEN_9PFS_NUM_RINGS) |
| 405 | return -EINVAL; |
| 406 | max_ring_order = xenbus_read_unsigned(dev->otherend, |
| 407 | "max-ring-page-order" , 0); |
| 408 | if (max_ring_order > XEN_9PFS_RING_ORDER) |
| 409 | max_ring_order = XEN_9PFS_RING_ORDER; |
| 410 | if (p9_xen_trans.maxsize > XEN_FLEX_RING_SIZE(max_ring_order)) |
| 411 | p9_xen_trans.maxsize = XEN_FLEX_RING_SIZE(max_ring_order) / 2; |
| 412 | |
| 413 | priv->rings = kcalloc(XEN_9PFS_NUM_RINGS, sizeof(*priv->rings), |
| 414 | GFP_KERNEL); |
| 415 | if (!priv->rings) { |
| 416 | kfree(priv); |
| 417 | return -ENOMEM; |
| 418 | } |
| 419 | |
| 420 | for (i = 0; i < XEN_9PFS_NUM_RINGS; i++) { |
| 421 | priv->rings[i].priv = priv; |
| 422 | ret = xen_9pfs_front_alloc_dataring(dev, &priv->rings[i], |
| 423 | max_ring_order); |
| 424 | if (ret < 0) |
| 425 | goto error; |
| 426 | } |
| 427 | |
| 428 | again: |
| 429 | ret = xenbus_transaction_start(&xbt); |
| 430 | if (ret) { |
| 431 | xenbus_dev_fatal(dev, ret, "starting transaction" ); |
| 432 | goto error; |
| 433 | } |
| 434 | ret = xenbus_printf(xbt, dev->nodename, "version" , "%u" , 1); |
| 435 | if (ret) |
| 436 | goto error_xenbus; |
| 437 | ret = xenbus_printf(xbt, dev->nodename, "num-rings" , "%u" , |
| 438 | XEN_9PFS_NUM_RINGS); |
| 439 | if (ret) |
| 440 | goto error_xenbus; |
| 441 | |
| 442 | for (i = 0; i < XEN_9PFS_NUM_RINGS; i++) { |
| 443 | char str[16]; |
| 444 | |
| 445 | BUILD_BUG_ON(XEN_9PFS_NUM_RINGS > 9); |
| 446 | sprintf(str, "ring-ref%d" , i); |
| 447 | ret = xenbus_printf(xbt, dev->nodename, str, "%d" , |
| 448 | priv->rings[i].ref); |
| 449 | if (ret) |
| 450 | goto error_xenbus; |
| 451 | |
| 452 | sprintf(str, "event-channel-%d" , i); |
| 453 | ret = xenbus_printf(xbt, dev->nodename, str, "%u" , |
| 454 | priv->rings[i].evtchn); |
| 455 | if (ret) |
| 456 | goto error_xenbus; |
| 457 | } |
| 458 | priv->tag = xenbus_read(xbt, dev->nodename, "tag" , NULL); |
| 459 | if (IS_ERR(priv->tag)) { |
| 460 | ret = PTR_ERR(priv->tag); |
| 461 | goto error_xenbus; |
| 462 | } |
| 463 | ret = xenbus_transaction_end(xbt, 0); |
| 464 | if (ret) { |
| 465 | if (ret == -EAGAIN) |
| 466 | goto again; |
| 467 | xenbus_dev_fatal(dev, ret, "completing transaction" ); |
| 468 | goto error; |
| 469 | } |
| 470 | |
| 471 | xenbus_switch_state(dev, XenbusStateInitialised); |
| 472 | return 0; |
| 473 | |
| 474 | error_xenbus: |
| 475 | xenbus_transaction_end(xbt, 1); |
| 476 | xenbus_dev_fatal(dev, ret, "writing xenstore" ); |
| 477 | error: |
| 478 | xen_9pfs_front_free(priv); |
| 479 | return ret; |
| 480 | } |
| 481 | |
| 482 | static int xen_9pfs_front_probe(struct xenbus_device *dev, |
| 483 | const struct xenbus_device_id *id) |
| 484 | { |
| 485 | struct xen_9pfs_front_priv *priv = NULL; |
| 486 | |
| 487 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 488 | if (!priv) |
| 489 | return -ENOMEM; |
| 490 | |
| 491 | priv->dev = dev; |
| 492 | dev_set_drvdata(dev: &dev->dev, data: priv); |
| 493 | |
| 494 | write_lock(&xen_9pfs_lock); |
| 495 | list_add_tail(new: &priv->list, head: &xen_9pfs_devs); |
| 496 | write_unlock(&xen_9pfs_lock); |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | static int xen_9pfs_front_resume(struct xenbus_device *dev) |
| 502 | { |
| 503 | dev_warn(&dev->dev, "suspend/resume unsupported\n" ); |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | static void xen_9pfs_front_changed(struct xenbus_device *dev, |
| 508 | enum xenbus_state backend_state) |
| 509 | { |
| 510 | switch (backend_state) { |
| 511 | case XenbusStateReconfiguring: |
| 512 | case XenbusStateReconfigured: |
| 513 | case XenbusStateInitialising: |
| 514 | case XenbusStateInitialised: |
| 515 | case XenbusStateUnknown: |
| 516 | break; |
| 517 | |
| 518 | case XenbusStateInitWait: |
| 519 | if (dev->state != XenbusStateInitialising) |
| 520 | break; |
| 521 | |
| 522 | xen_9pfs_front_init(dev); |
| 523 | break; |
| 524 | |
| 525 | case XenbusStateConnected: |
| 526 | xenbus_switch_state(dev, new_state: XenbusStateConnected); |
| 527 | break; |
| 528 | |
| 529 | case XenbusStateClosed: |
| 530 | if (dev->state == XenbusStateClosed) |
| 531 | break; |
| 532 | fallthrough; /* Missed the backend's CLOSING state */ |
| 533 | case XenbusStateClosing: |
| 534 | xenbus_frontend_closed(dev); |
| 535 | break; |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | static struct xenbus_driver xen_9pfs_front_driver = { |
| 540 | .ids = xen_9pfs_front_ids, |
| 541 | .probe = xen_9pfs_front_probe, |
| 542 | .remove = xen_9pfs_front_remove, |
| 543 | .resume = xen_9pfs_front_resume, |
| 544 | .otherend_changed = xen_9pfs_front_changed, |
| 545 | }; |
| 546 | |
| 547 | static int __init p9_trans_xen_init(void) |
| 548 | { |
| 549 | int rc; |
| 550 | |
| 551 | if (!xen_domain()) |
| 552 | return -ENODEV; |
| 553 | |
| 554 | pr_info("Initialising Xen transport for 9pfs\n" ); |
| 555 | |
| 556 | v9fs_register_trans(m: &p9_xen_trans); |
| 557 | rc = xenbus_register_frontend(&xen_9pfs_front_driver); |
| 558 | if (rc) |
| 559 | v9fs_unregister_trans(m: &p9_xen_trans); |
| 560 | |
| 561 | return rc; |
| 562 | } |
| 563 | module_init(p9_trans_xen_init); |
| 564 | MODULE_ALIAS_9P("xen" ); |
| 565 | |
| 566 | static void __exit p9_trans_xen_exit(void) |
| 567 | { |
| 568 | v9fs_unregister_trans(m: &p9_xen_trans); |
| 569 | return xenbus_unregister_driver(drv: &xen_9pfs_front_driver); |
| 570 | } |
| 571 | module_exit(p9_trans_xen_exit); |
| 572 | |
| 573 | MODULE_ALIAS("xen:9pfs" ); |
| 574 | MODULE_AUTHOR("Stefano Stabellini <stefano@aporeto.com>" ); |
| 575 | MODULE_DESCRIPTION("Xen Transport for 9P" ); |
| 576 | MODULE_LICENSE("GPL" ); |
| 577 | |