blocklayout.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * linux/fs/nfs/blocklayout/blocklayout.c
  3. *
  4. * Module for the NFSv4.1 pNFS block layout driver.
  5. *
  6. * Copyright (c) 2006 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Andy Adamson <andros@citi.umich.edu>
  10. * Fred Isaman <iisaman@umich.edu>
  11. *
  12. * permission is granted to use, copy, create derivative works and
  13. * redistribute this software and such derivative works for any purpose,
  14. * so long as the name of the university of michigan is not used in
  15. * any advertising or publicity pertaining to the use or distribution
  16. * of this software without specific, written prior authorization. if
  17. * the above copyright notice or any other identification of the
  18. * university of michigan is included in any copy of any portion of
  19. * this software, then the disclaimer below must also be included.
  20. *
  21. * this software is provided as is, without representation from the
  22. * university of michigan as to its fitness for any purpose, and without
  23. * warranty by the university of michigan of any kind, either express
  24. * or implied, including without limitation the implied warranties of
  25. * merchantability and fitness for a particular purpose. the regents
  26. * of the university of michigan shall not be liable for any damages,
  27. * including special, indirect, incidental, or consequential damages,
  28. * with respect to any claim arising out or in connection with the use
  29. * of the software, even if it has been or is hereafter advised of the
  30. * possibility of such damages.
  31. */
  32. #include <linux/module.h>
  33. #include <linux/init.h>
  34. #include <linux/mount.h>
  35. #include <linux/namei.h>
  36. #include "blocklayout.h"
  37. #define NFSDBG_FACILITY NFSDBG_PNFS_LD
  38. MODULE_LICENSE("GPL");
  39. MODULE_AUTHOR("Andy Adamson <andros@citi.umich.edu>");
  40. MODULE_DESCRIPTION("The NFSv4.1 pNFS Block layout driver");
  41. struct dentry *bl_device_pipe;
  42. wait_queue_head_t bl_wq;
  43. static enum pnfs_try_status
  44. bl_read_pagelist(struct nfs_read_data *rdata)
  45. {
  46. return PNFS_NOT_ATTEMPTED;
  47. }
  48. static enum pnfs_try_status
  49. bl_write_pagelist(struct nfs_write_data *wdata,
  50. int sync)
  51. {
  52. return PNFS_NOT_ATTEMPTED;
  53. }
  54. /* FIXME - range ignored */
  55. static void
  56. release_extents(struct pnfs_block_layout *bl, struct pnfs_layout_range *range)
  57. {
  58. int i;
  59. struct pnfs_block_extent *be;
  60. spin_lock(&bl->bl_ext_lock);
  61. for (i = 0; i < EXTENT_LISTS; i++) {
  62. while (!list_empty(&bl->bl_extents[i])) {
  63. be = list_first_entry(&bl->bl_extents[i],
  64. struct pnfs_block_extent,
  65. be_node);
  66. list_del(&be->be_node);
  67. bl_put_extent(be);
  68. }
  69. }
  70. spin_unlock(&bl->bl_ext_lock);
  71. }
  72. /* STUB */
  73. static void
  74. release_inval_marks(struct pnfs_inval_markings *marks)
  75. {
  76. return;
  77. }
  78. static void bl_free_layout_hdr(struct pnfs_layout_hdr *lo)
  79. {
  80. struct pnfs_block_layout *bl = BLK_LO2EXT(lo);
  81. dprintk("%s enter\n", __func__);
  82. release_extents(bl, NULL);
  83. release_inval_marks(&bl->bl_inval);
  84. kfree(bl);
  85. }
  86. static struct pnfs_layout_hdr *bl_alloc_layout_hdr(struct inode *inode,
  87. gfp_t gfp_flags)
  88. {
  89. struct pnfs_block_layout *bl;
  90. dprintk("%s enter\n", __func__);
  91. bl = kzalloc(sizeof(*bl), gfp_flags);
  92. if (!bl)
  93. return NULL;
  94. spin_lock_init(&bl->bl_ext_lock);
  95. INIT_LIST_HEAD(&bl->bl_extents[0]);
  96. INIT_LIST_HEAD(&bl->bl_extents[1]);
  97. INIT_LIST_HEAD(&bl->bl_commit);
  98. INIT_LIST_HEAD(&bl->bl_committing);
  99. bl->bl_count = 0;
  100. bl->bl_blocksize = NFS_SERVER(inode)->pnfs_blksize >> SECTOR_SHIFT;
  101. BL_INIT_INVAL_MARKS(&bl->bl_inval, bl->bl_blocksize);
  102. return &bl->bl_layout;
  103. }
  104. static void bl_free_lseg(struct pnfs_layout_segment *lseg)
  105. {
  106. dprintk("%s enter\n", __func__);
  107. kfree(lseg);
  108. }
  109. /* We pretty much ignore lseg, and store all data layout wide, so we
  110. * can correctly merge.
  111. */
  112. static struct pnfs_layout_segment *bl_alloc_lseg(struct pnfs_layout_hdr *lo,
  113. struct nfs4_layoutget_res *lgr,
  114. gfp_t gfp_flags)
  115. {
  116. struct pnfs_layout_segment *lseg;
  117. int status;
  118. dprintk("%s enter\n", __func__);
  119. lseg = kzalloc(sizeof(*lseg), gfp_flags);
  120. if (!lseg)
  121. return ERR_PTR(-ENOMEM);
  122. status = nfs4_blk_process_layoutget(lo, lgr, gfp_flags);
  123. if (status) {
  124. /* We don't want to call the full-blown bl_free_lseg,
  125. * since on error extents were not touched.
  126. */
  127. kfree(lseg);
  128. return ERR_PTR(status);
  129. }
  130. return lseg;
  131. }
  132. static void
  133. bl_encode_layoutcommit(struct pnfs_layout_hdr *lo, struct xdr_stream *xdr,
  134. const struct nfs4_layoutcommit_args *arg)
  135. {
  136. }
  137. static void
  138. bl_cleanup_layoutcommit(struct nfs4_layoutcommit_data *lcdata)
  139. {
  140. }
  141. static int
  142. bl_set_layoutdriver(struct nfs_server *server, const struct nfs_fh *fh)
  143. {
  144. dprintk("%s enter\n", __func__);
  145. return 0;
  146. }
  147. static int
  148. bl_clear_layoutdriver(struct nfs_server *server)
  149. {
  150. dprintk("%s enter\n", __func__);
  151. return 0;
  152. }
  153. static const struct nfs_pageio_ops bl_pg_read_ops = {
  154. .pg_init = pnfs_generic_pg_init_read,
  155. .pg_test = pnfs_generic_pg_test,
  156. .pg_doio = pnfs_generic_pg_readpages,
  157. };
  158. static const struct nfs_pageio_ops bl_pg_write_ops = {
  159. .pg_init = pnfs_generic_pg_init_write,
  160. .pg_test = pnfs_generic_pg_test,
  161. .pg_doio = pnfs_generic_pg_writepages,
  162. };
  163. static struct pnfs_layoutdriver_type blocklayout_type = {
  164. .id = LAYOUT_BLOCK_VOLUME,
  165. .name = "LAYOUT_BLOCK_VOLUME",
  166. .read_pagelist = bl_read_pagelist,
  167. .write_pagelist = bl_write_pagelist,
  168. .alloc_layout_hdr = bl_alloc_layout_hdr,
  169. .free_layout_hdr = bl_free_layout_hdr,
  170. .alloc_lseg = bl_alloc_lseg,
  171. .free_lseg = bl_free_lseg,
  172. .encode_layoutcommit = bl_encode_layoutcommit,
  173. .cleanup_layoutcommit = bl_cleanup_layoutcommit,
  174. .set_layoutdriver = bl_set_layoutdriver,
  175. .clear_layoutdriver = bl_clear_layoutdriver,
  176. .pg_read_ops = &bl_pg_read_ops,
  177. .pg_write_ops = &bl_pg_write_ops,
  178. };
  179. static const struct rpc_pipe_ops bl_upcall_ops = {
  180. .upcall = bl_pipe_upcall,
  181. .downcall = bl_pipe_downcall,
  182. .destroy_msg = bl_pipe_destroy_msg,
  183. };
  184. static int __init nfs4blocklayout_init(void)
  185. {
  186. struct vfsmount *mnt;
  187. struct path path;
  188. int ret;
  189. dprintk("%s: NFSv4 Block Layout Driver Registering...\n", __func__);
  190. ret = pnfs_register_layoutdriver(&blocklayout_type);
  191. if (ret)
  192. goto out;
  193. init_waitqueue_head(&bl_wq);
  194. mnt = rpc_get_mount();
  195. if (IS_ERR(mnt)) {
  196. ret = PTR_ERR(mnt);
  197. goto out_remove;
  198. }
  199. ret = vfs_path_lookup(mnt->mnt_root,
  200. mnt,
  201. NFS_PIPE_DIRNAME, 0, &path);
  202. if (ret)
  203. goto out_remove;
  204. bl_device_pipe = rpc_mkpipe(path.dentry, "blocklayout", NULL,
  205. &bl_upcall_ops, 0);
  206. if (IS_ERR(bl_device_pipe)) {
  207. ret = PTR_ERR(bl_device_pipe);
  208. goto out_remove;
  209. }
  210. out:
  211. return ret;
  212. out_remove:
  213. pnfs_unregister_layoutdriver(&blocklayout_type);
  214. return ret;
  215. }
  216. static void __exit nfs4blocklayout_exit(void)
  217. {
  218. dprintk("%s: NFSv4 Block Layout Driver Unregistering...\n",
  219. __func__);
  220. pnfs_unregister_layoutdriver(&blocklayout_type);
  221. rpc_unlink(bl_device_pipe);
  222. }
  223. MODULE_ALIAS("nfs-layouttype4-3");
  224. module_init(nfs4blocklayout_init);
  225. module_exit(nfs4blocklayout_exit);