trans_virtio.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * The Virtio 9p transport driver
  3. *
  4. * This is a block based transport driver based on the lguest block driver
  5. * code.
  6. *
  7. * Copyright (C) 2007, 2008 Eric Van Hensbergen, IBM Corporation
  8. *
  9. * Based on virtio console driver
  10. * Copyright (C) 2006, 2007 Rusty Russell, IBM Corporation
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to:
  23. * Free Software Foundation
  24. * 51 Franklin Street, Fifth Floor
  25. * Boston, MA 02111-1301 USA
  26. *
  27. */
  28. #include <linux/in.h>
  29. #include <linux/module.h>
  30. #include <linux/net.h>
  31. #include <linux/ipv6.h>
  32. #include <linux/errno.h>
  33. #include <linux/kernel.h>
  34. #include <linux/un.h>
  35. #include <linux/uaccess.h>
  36. #include <linux/inet.h>
  37. #include <linux/idr.h>
  38. #include <linux/file.h>
  39. #include <linux/slab.h>
  40. #include <net/9p/9p.h>
  41. #include <linux/parser.h>
  42. #include <net/9p/client.h>
  43. #include <net/9p/transport.h>
  44. #include <linux/scatterlist.h>
  45. #include <linux/swap.h>
  46. #include <linux/virtio.h>
  47. #include <linux/virtio_9p.h>
  48. #include "trans_common.h"
  49. #define VIRTQUEUE_NUM 128
  50. /* a single mutex to manage channel initialization and attachment */
  51. static DEFINE_MUTEX(virtio_9p_lock);
  52. static DECLARE_WAIT_QUEUE_HEAD(vp_wq);
  53. static atomic_t vp_pinned = ATOMIC_INIT(0);
  54. /**
  55. * struct virtio_chan - per-instance transport information
  56. * @initialized: whether the channel is initialized
  57. * @inuse: whether the channel is in use
  58. * @lock: protects multiple elements within this structure
  59. * @client: client instance
  60. * @vdev: virtio dev associated with this channel
  61. * @vq: virtio queue associated with this channel
  62. * @sg: scatter gather list which is used to pack a request (protected?)
  63. *
  64. * We keep all per-channel information in a structure.
  65. * This structure is allocated within the devices dev->mem space.
  66. * A pointer to the structure will get put in the transport private.
  67. *
  68. */
  69. struct virtio_chan {
  70. bool inuse;
  71. spinlock_t lock;
  72. struct p9_client *client;
  73. struct virtio_device *vdev;
  74. struct virtqueue *vq;
  75. int ring_bufs_avail;
  76. wait_queue_head_t *vc_wq;
  77. /* This is global limit. Since we don't have a global structure,
  78. * will be placing it in each channel.
  79. */
  80. int p9_max_pages;
  81. /* Scatterlist: can be too big for stack. */
  82. struct scatterlist sg[VIRTQUEUE_NUM];
  83. int tag_len;
  84. /*
  85. * tag name to identify a mount Non-null terminated
  86. */
  87. char *tag;
  88. struct list_head chan_list;
  89. };
  90. static struct list_head virtio_chan_list;
  91. /* How many bytes left in this page. */
  92. static unsigned int rest_of_page(void *data)
  93. {
  94. return PAGE_SIZE - ((unsigned long)data % PAGE_SIZE);
  95. }
  96. /**
  97. * p9_virtio_close - reclaim resources of a channel
  98. * @client: client instance
  99. *
  100. * This reclaims a channel by freeing its resources and
  101. * reseting its inuse flag.
  102. *
  103. */
  104. static void p9_virtio_close(struct p9_client *client)
  105. {
  106. struct virtio_chan *chan = client->trans;
  107. mutex_lock(&virtio_9p_lock);
  108. if (chan)
  109. chan->inuse = false;
  110. mutex_unlock(&virtio_9p_lock);
  111. }
  112. /**
  113. * req_done - callback which signals activity from the server
  114. * @vq: virtio queue activity was received on
  115. *
  116. * This notifies us that the server has triggered some activity
  117. * on the virtio channel - most likely a response to request we
  118. * sent. Figure out which requests now have responses and wake up
  119. * those threads.
  120. *
  121. * Bugs: could do with some additional sanity checking, but appears to work.
  122. *
  123. */
  124. static void req_done(struct virtqueue *vq)
  125. {
  126. struct virtio_chan *chan = vq->vdev->priv;
  127. struct p9_fcall *rc;
  128. unsigned int len;
  129. struct p9_req_t *req;
  130. unsigned long flags;
  131. P9_DPRINTK(P9_DEBUG_TRANS, ": request done\n");
  132. while (1) {
  133. spin_lock_irqsave(&chan->lock, flags);
  134. rc = virtqueue_get_buf(chan->vq, &len);
  135. if (rc == NULL) {
  136. spin_unlock_irqrestore(&chan->lock, flags);
  137. break;
  138. }
  139. chan->ring_bufs_avail = 1;
  140. spin_unlock_irqrestore(&chan->lock, flags);
  141. /* Wakeup if anyone waiting for VirtIO ring space. */
  142. wake_up(chan->vc_wq);
  143. P9_DPRINTK(P9_DEBUG_TRANS, ": rc %p\n", rc);
  144. P9_DPRINTK(P9_DEBUG_TRANS, ": lookup tag %d\n", rc->tag);
  145. req = p9_tag_lookup(chan->client, rc->tag);
  146. req->status = REQ_STATUS_RCVD;
  147. p9_client_cb(chan->client, req);
  148. }
  149. }
  150. /**
  151. * pack_sg_list - pack a scatter gather list from a linear buffer
  152. * @sg: scatter/gather list to pack into
  153. * @start: which segment of the sg_list to start at
  154. * @limit: maximum segment to pack data to
  155. * @data: data to pack into scatter/gather list
  156. * @count: amount of data to pack into the scatter/gather list
  157. *
  158. * sg_lists have multiple segments of various sizes. This will pack
  159. * arbitrary data into an existing scatter gather list, segmenting the
  160. * data as necessary within constraints.
  161. *
  162. */
  163. static int pack_sg_list(struct scatterlist *sg, int start,
  164. int limit, char *data, int count)
  165. {
  166. int s;
  167. int index = start;
  168. while (count) {
  169. s = rest_of_page(data);
  170. if (s > count)
  171. s = count;
  172. sg_set_buf(&sg[index++], data, s);
  173. count -= s;
  174. data += s;
  175. BUG_ON(index > limit);
  176. }
  177. return index-start;
  178. }
  179. /* We don't currently allow canceling of virtio requests */
  180. static int p9_virtio_cancel(struct p9_client *client, struct p9_req_t *req)
  181. {
  182. return 1;
  183. }
  184. /**
  185. * pack_sg_list_p - Just like pack_sg_list. Instead of taking a buffer,
  186. * this takes a list of pages.
  187. * @sg: scatter/gather list to pack into
  188. * @start: which segment of the sg_list to start at
  189. * @**pdata: a list of pages to add into sg.
  190. * @nr_pages: number of pages to pack into the scatter/gather list
  191. * @data: data to pack into scatter/gather list
  192. * @count: amount of data to pack into the scatter/gather list
  193. */
  194. static int
  195. pack_sg_list_p(struct scatterlist *sg, int start, int limit,
  196. struct page **pdata, int nr_pages, char *data, int count)
  197. {
  198. int i = 0, s;
  199. int data_off;
  200. int index = start;
  201. BUG_ON(nr_pages > (limit - start));
  202. /*
  203. * if the first page doesn't start at
  204. * page boundary find the offset
  205. */
  206. data_off = offset_in_page(data);
  207. while (nr_pages) {
  208. s = rest_of_page(data);
  209. if (s > count)
  210. s = count;
  211. sg_set_page(&sg[index++], pdata[i++], s, data_off);
  212. data_off = 0;
  213. data += s;
  214. count -= s;
  215. nr_pages--;
  216. }
  217. return index - start;
  218. }
  219. /**
  220. * p9_virtio_request - issue a request
  221. * @client: client instance issuing the request
  222. * @req: request to be issued
  223. *
  224. */
  225. static int
  226. p9_virtio_request(struct p9_client *client, struct p9_req_t *req)
  227. {
  228. int err;
  229. int in, out;
  230. unsigned long flags;
  231. struct virtio_chan *chan = client->trans;
  232. P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio request\n");
  233. req->status = REQ_STATUS_SENT;
  234. req_retry:
  235. spin_lock_irqsave(&chan->lock, flags);
  236. /* Handle out VirtIO ring buffers */
  237. out = pack_sg_list(chan->sg, 0,
  238. VIRTQUEUE_NUM, req->tc->sdata, req->tc->size);
  239. in = pack_sg_list(chan->sg, out,
  240. VIRTQUEUE_NUM, req->rc->sdata, req->rc->capacity);
  241. err = virtqueue_add_buf(chan->vq, chan->sg, out, in, req->tc);
  242. if (err < 0) {
  243. if (err == -ENOSPC) {
  244. chan->ring_bufs_avail = 0;
  245. spin_unlock_irqrestore(&chan->lock, flags);
  246. err = wait_event_interruptible(*chan->vc_wq,
  247. chan->ring_bufs_avail);
  248. if (err == -ERESTARTSYS)
  249. return err;
  250. P9_DPRINTK(P9_DEBUG_TRANS, "9p:Retry virtio request\n");
  251. goto req_retry;
  252. } else {
  253. spin_unlock_irqrestore(&chan->lock, flags);
  254. P9_DPRINTK(P9_DEBUG_TRANS,
  255. "9p debug: "
  256. "virtio rpc add_buf returned failure");
  257. return -EIO;
  258. }
  259. }
  260. virtqueue_kick(chan->vq);
  261. spin_unlock_irqrestore(&chan->lock, flags);
  262. P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio request kicked\n");
  263. return 0;
  264. }
  265. static int p9_get_mapped_pages(struct virtio_chan *chan,
  266. struct page **pages, char *data,
  267. int nr_pages, int write, int kern_buf)
  268. {
  269. int err;
  270. if (!kern_buf) {
  271. /*
  272. * We allow only p9_max_pages pinned. We wait for the
  273. * Other zc request to finish here
  274. */
  275. if (atomic_read(&vp_pinned) >= chan->p9_max_pages) {
  276. err = wait_event_interruptible(vp_wq,
  277. (atomic_read(&vp_pinned) < chan->p9_max_pages));
  278. if (err == -ERESTARTSYS)
  279. return err;
  280. }
  281. err = p9_payload_gup(data, &nr_pages, pages, write);
  282. if (err < 0)
  283. return err;
  284. atomic_add(nr_pages, &vp_pinned);
  285. } else {
  286. /* kernel buffer, no need to pin pages */
  287. int s, index = 0;
  288. int count = nr_pages;
  289. while (nr_pages) {
  290. s = rest_of_page(data);
  291. pages[index++] = virt_to_page(data);
  292. data += s;
  293. nr_pages--;
  294. }
  295. nr_pages = count;
  296. }
  297. return nr_pages;
  298. }
  299. /**
  300. * p9_virtio_zc_request - issue a zero copy request
  301. * @client: client instance issuing the request
  302. * @req: request to be issued
  303. * @uidata: user bffer that should be ued for zero copy read
  304. * @uodata: user buffer that shoud be user for zero copy write
  305. * @inlen: read buffer size
  306. * @olen: write buffer size
  307. * @hdrlen: reader header size, This is the size of response protocol data
  308. *
  309. */
  310. static int
  311. p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
  312. char *uidata, char *uodata, int inlen,
  313. int outlen, int in_hdr_len, int kern_buf)
  314. {
  315. int in, out, err;
  316. unsigned long flags;
  317. int in_nr_pages = 0, out_nr_pages = 0;
  318. struct page **in_pages = NULL, **out_pages = NULL;
  319. struct virtio_chan *chan = client->trans;
  320. P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio request\n");
  321. if (uodata) {
  322. out_nr_pages = p9_nr_pages(uodata, outlen);
  323. out_pages = kmalloc(sizeof(struct page *) * out_nr_pages,
  324. GFP_NOFS);
  325. if (!out_pages) {
  326. err = -ENOMEM;
  327. goto err_out;
  328. }
  329. out_nr_pages = p9_get_mapped_pages(chan, out_pages, uodata,
  330. out_nr_pages, 0, kern_buf);
  331. if (out_nr_pages < 0) {
  332. err = out_nr_pages;
  333. kfree(out_pages);
  334. out_pages = NULL;
  335. goto err_out;
  336. }
  337. }
  338. if (uidata) {
  339. in_nr_pages = p9_nr_pages(uidata, inlen);
  340. in_pages = kmalloc(sizeof(struct page *) * in_nr_pages,
  341. GFP_NOFS);
  342. if (!in_pages) {
  343. err = -ENOMEM;
  344. goto err_out;
  345. }
  346. in_nr_pages = p9_get_mapped_pages(chan, in_pages, uidata,
  347. in_nr_pages, 1, kern_buf);
  348. if (in_nr_pages < 0) {
  349. err = in_nr_pages;
  350. kfree(in_pages);
  351. in_pages = NULL;
  352. goto err_out;
  353. }
  354. }
  355. req->status = REQ_STATUS_SENT;
  356. req_retry_pinned:
  357. spin_lock_irqsave(&chan->lock, flags);
  358. /* out data */
  359. out = pack_sg_list(chan->sg, 0,
  360. VIRTQUEUE_NUM, req->tc->sdata, req->tc->size);
  361. if (out_pages)
  362. out += pack_sg_list_p(chan->sg, out, VIRTQUEUE_NUM,
  363. out_pages, out_nr_pages, uodata, outlen);
  364. /*
  365. * Take care of in data
  366. * For example TREAD have 11.
  367. * 11 is the read/write header = PDU Header(7) + IO Size (4).
  368. * Arrange in such a way that server places header in the
  369. * alloced memory and payload onto the user buffer.
  370. */
  371. in = pack_sg_list(chan->sg, out,
  372. VIRTQUEUE_NUM, req->rc->sdata, in_hdr_len);
  373. if (in_pages)
  374. in += pack_sg_list_p(chan->sg, out + in, VIRTQUEUE_NUM,
  375. in_pages, in_nr_pages, uidata, inlen);
  376. err = virtqueue_add_buf(chan->vq, chan->sg, out, in, req->tc);
  377. if (err < 0) {
  378. if (err == -ENOSPC) {
  379. chan->ring_bufs_avail = 0;
  380. spin_unlock_irqrestore(&chan->lock, flags);
  381. err = wait_event_interruptible(*chan->vc_wq,
  382. chan->ring_bufs_avail);
  383. if (err == -ERESTARTSYS)
  384. goto err_out;
  385. P9_DPRINTK(P9_DEBUG_TRANS, "9p:Retry virtio request\n");
  386. goto req_retry_pinned;
  387. } else {
  388. spin_unlock_irqrestore(&chan->lock, flags);
  389. P9_DPRINTK(P9_DEBUG_TRANS,
  390. "9p debug: "
  391. "virtio rpc add_buf returned failure");
  392. err = -EIO;
  393. goto err_out;
  394. }
  395. }
  396. virtqueue_kick(chan->vq);
  397. spin_unlock_irqrestore(&chan->lock, flags);
  398. P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio request kicked\n");
  399. err = wait_event_interruptible(*req->wq,
  400. req->status >= REQ_STATUS_RCVD);
  401. /*
  402. * Non kernel buffers are pinned, unpin them
  403. */
  404. err_out:
  405. if (!kern_buf) {
  406. if (in_pages) {
  407. p9_release_pages(in_pages, in_nr_pages);
  408. atomic_sub(in_nr_pages, &vp_pinned);
  409. }
  410. if (out_pages) {
  411. p9_release_pages(out_pages, out_nr_pages);
  412. atomic_sub(out_nr_pages, &vp_pinned);
  413. }
  414. /* wakeup anybody waiting for slots to pin pages */
  415. wake_up(&vp_wq);
  416. }
  417. kfree(in_pages);
  418. kfree(out_pages);
  419. return err;
  420. }
  421. static ssize_t p9_mount_tag_show(struct device *dev,
  422. struct device_attribute *attr, char *buf)
  423. {
  424. struct virtio_chan *chan;
  425. struct virtio_device *vdev;
  426. vdev = dev_to_virtio(dev);
  427. chan = vdev->priv;
  428. return snprintf(buf, chan->tag_len + 1, "%s", chan->tag);
  429. }
  430. static DEVICE_ATTR(mount_tag, 0444, p9_mount_tag_show, NULL);
  431. /**
  432. * p9_virtio_probe - probe for existence of 9P virtio channels
  433. * @vdev: virtio device to probe
  434. *
  435. * This probes for existing virtio channels.
  436. *
  437. */
  438. static int p9_virtio_probe(struct virtio_device *vdev)
  439. {
  440. __u16 tag_len;
  441. char *tag;
  442. int err;
  443. struct virtio_chan *chan;
  444. chan = kmalloc(sizeof(struct virtio_chan), GFP_KERNEL);
  445. if (!chan) {
  446. printk(KERN_ERR "9p: Failed to allocate virtio 9P channel\n");
  447. err = -ENOMEM;
  448. goto fail;
  449. }
  450. chan->vdev = vdev;
  451. /* We expect one virtqueue, for requests. */
  452. chan->vq = virtio_find_single_vq(vdev, req_done, "requests");
  453. if (IS_ERR(chan->vq)) {
  454. err = PTR_ERR(chan->vq);
  455. goto out_free_vq;
  456. }
  457. chan->vq->vdev->priv = chan;
  458. spin_lock_init(&chan->lock);
  459. sg_init_table(chan->sg, VIRTQUEUE_NUM);
  460. chan->inuse = false;
  461. if (virtio_has_feature(vdev, VIRTIO_9P_MOUNT_TAG)) {
  462. vdev->config->get(vdev,
  463. offsetof(struct virtio_9p_config, tag_len),
  464. &tag_len, sizeof(tag_len));
  465. } else {
  466. err = -EINVAL;
  467. goto out_free_vq;
  468. }
  469. tag = kmalloc(tag_len, GFP_KERNEL);
  470. if (!tag) {
  471. err = -ENOMEM;
  472. goto out_free_vq;
  473. }
  474. vdev->config->get(vdev, offsetof(struct virtio_9p_config, tag),
  475. tag, tag_len);
  476. chan->tag = tag;
  477. chan->tag_len = tag_len;
  478. err = sysfs_create_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr);
  479. if (err) {
  480. goto out_free_tag;
  481. }
  482. chan->vc_wq = kmalloc(sizeof(wait_queue_head_t), GFP_KERNEL);
  483. if (!chan->vc_wq) {
  484. err = -ENOMEM;
  485. goto out_free_tag;
  486. }
  487. init_waitqueue_head(chan->vc_wq);
  488. chan->ring_bufs_avail = 1;
  489. /* Ceiling limit to avoid denial of service attacks */
  490. chan->p9_max_pages = nr_free_buffer_pages()/4;
  491. mutex_lock(&virtio_9p_lock);
  492. list_add_tail(&chan->chan_list, &virtio_chan_list);
  493. mutex_unlock(&virtio_9p_lock);
  494. return 0;
  495. out_free_tag:
  496. kfree(tag);
  497. out_free_vq:
  498. vdev->config->del_vqs(vdev);
  499. kfree(chan);
  500. fail:
  501. return err;
  502. }
  503. /**
  504. * p9_virtio_create - allocate a new virtio channel
  505. * @client: client instance invoking this transport
  506. * @devname: string identifying the channel to connect to (unused)
  507. * @args: args passed from sys_mount() for per-transport options (unused)
  508. *
  509. * This sets up a transport channel for 9p communication. Right now
  510. * we only match the first available channel, but eventually we couldlook up
  511. * alternate channels by matching devname versus a virtio_config entry.
  512. * We use a simple reference count mechanism to ensure that only a single
  513. * mount has a channel open at a time.
  514. *
  515. */
  516. static int
  517. p9_virtio_create(struct p9_client *client, const char *devname, char *args)
  518. {
  519. struct virtio_chan *chan;
  520. int ret = -ENOENT;
  521. int found = 0;
  522. mutex_lock(&virtio_9p_lock);
  523. list_for_each_entry(chan, &virtio_chan_list, chan_list) {
  524. if (!strncmp(devname, chan->tag, chan->tag_len) &&
  525. strlen(devname) == chan->tag_len) {
  526. if (!chan->inuse) {
  527. chan->inuse = true;
  528. found = 1;
  529. break;
  530. }
  531. ret = -EBUSY;
  532. }
  533. }
  534. mutex_unlock(&virtio_9p_lock);
  535. if (!found) {
  536. printk(KERN_ERR "9p: no channels available\n");
  537. return ret;
  538. }
  539. client->trans = (void *)chan;
  540. client->status = Connected;
  541. chan->client = client;
  542. return 0;
  543. }
  544. /**
  545. * p9_virtio_remove - clean up resources associated with a virtio device
  546. * @vdev: virtio device to remove
  547. *
  548. */
  549. static void p9_virtio_remove(struct virtio_device *vdev)
  550. {
  551. struct virtio_chan *chan = vdev->priv;
  552. BUG_ON(chan->inuse);
  553. vdev->config->del_vqs(vdev);
  554. mutex_lock(&virtio_9p_lock);
  555. list_del(&chan->chan_list);
  556. mutex_unlock(&virtio_9p_lock);
  557. sysfs_remove_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr);
  558. kfree(chan->tag);
  559. kfree(chan->vc_wq);
  560. kfree(chan);
  561. }
  562. static struct virtio_device_id id_table[] = {
  563. { VIRTIO_ID_9P, VIRTIO_DEV_ANY_ID },
  564. { 0 },
  565. };
  566. static unsigned int features[] = {
  567. VIRTIO_9P_MOUNT_TAG,
  568. };
  569. /* The standard "struct lguest_driver": */
  570. static struct virtio_driver p9_virtio_drv = {
  571. .feature_table = features,
  572. .feature_table_size = ARRAY_SIZE(features),
  573. .driver.name = KBUILD_MODNAME,
  574. .driver.owner = THIS_MODULE,
  575. .id_table = id_table,
  576. .probe = p9_virtio_probe,
  577. .remove = p9_virtio_remove,
  578. };
  579. static struct p9_trans_module p9_virtio_trans = {
  580. .name = "virtio",
  581. .create = p9_virtio_create,
  582. .close = p9_virtio_close,
  583. .request = p9_virtio_request,
  584. .zc_request = p9_virtio_zc_request,
  585. .cancel = p9_virtio_cancel,
  586. /*
  587. * We leave one entry for input and one entry for response
  588. * headers. We also skip one more entry to accomodate, address
  589. * that are not at page boundary, that can result in an extra
  590. * page in zero copy.
  591. */
  592. .maxsize = PAGE_SIZE * (VIRTQUEUE_NUM - 3),
  593. .def = 0,
  594. .owner = THIS_MODULE,
  595. };
  596. /* The standard init function */
  597. static int __init p9_virtio_init(void)
  598. {
  599. INIT_LIST_HEAD(&virtio_chan_list);
  600. v9fs_register_trans(&p9_virtio_trans);
  601. return register_virtio_driver(&p9_virtio_drv);
  602. }
  603. static void __exit p9_virtio_cleanup(void)
  604. {
  605. unregister_virtio_driver(&p9_virtio_drv);
  606. v9fs_unregister_trans(&p9_virtio_trans);
  607. }
  608. module_init(p9_virtio_init);
  609. module_exit(p9_virtio_cleanup);
  610. MODULE_DEVICE_TABLE(virtio, id_table);
  611. MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
  612. MODULE_DESCRIPTION("Virtio 9p Transport");
  613. MODULE_LICENSE("GPL");