trans_virtio.c 17 KB

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