blocklayout.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * linux/fs/nfs/blocklayout/blocklayout.h
  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. #ifndef FS_NFS_NFS4BLOCKLAYOUT_H
  33. #define FS_NFS_NFS4BLOCKLAYOUT_H
  34. #include <linux/device-mapper.h>
  35. #include <linux/nfs_fs.h>
  36. #include <linux/sunrpc/rpc_pipe_fs.h>
  37. #include "../pnfs.h"
  38. #include "../netns.h"
  39. #define PAGE_CACHE_SECTORS (PAGE_CACHE_SIZE >> SECTOR_SHIFT)
  40. #define PAGE_CACHE_SECTOR_SHIFT (PAGE_CACHE_SHIFT - SECTOR_SHIFT)
  41. #define SECTOR_SIZE (1 << SECTOR_SHIFT)
  42. struct block_mount_id {
  43. spinlock_t bm_lock; /* protects list */
  44. struct list_head bm_devlist; /* holds pnfs_block_dev */
  45. };
  46. struct pnfs_block_dev {
  47. struct list_head bm_node;
  48. struct nfs4_deviceid bm_mdevid; /* associated devid */
  49. struct block_device *bm_mdev; /* meta device itself */
  50. struct net *net;
  51. };
  52. enum exstate4 {
  53. PNFS_BLOCK_READWRITE_DATA = 0,
  54. PNFS_BLOCK_READ_DATA = 1,
  55. PNFS_BLOCK_INVALID_DATA = 2, /* mapped, but data is invalid */
  56. PNFS_BLOCK_NONE_DATA = 3 /* unmapped, it's a hole */
  57. };
  58. #define MY_MAX_TAGS (15) /* tag bitnums used must be less than this */
  59. struct my_tree {
  60. sector_t mtt_step_size; /* Internal sector alignment */
  61. struct list_head mtt_stub; /* Should be a radix tree */
  62. };
  63. struct pnfs_inval_markings {
  64. spinlock_t im_lock;
  65. struct my_tree im_tree; /* Sectors that need LAYOUTCOMMIT */
  66. sector_t im_block_size; /* Server blocksize in sectors */
  67. struct list_head im_extents; /* Short extents for INVAL->RW conversion */
  68. };
  69. struct pnfs_inval_tracking {
  70. struct list_head it_link;
  71. int it_sector;
  72. int it_tags;
  73. };
  74. /* sector_t fields are all in 512-byte sectors */
  75. struct pnfs_block_extent {
  76. struct kref be_refcnt;
  77. struct list_head be_node; /* link into lseg list */
  78. struct nfs4_deviceid be_devid; /* FIXME: could use device cache instead */
  79. struct block_device *be_mdev;
  80. sector_t be_f_offset; /* the starting offset in the file */
  81. sector_t be_length; /* the size of the extent */
  82. sector_t be_v_offset; /* the starting offset in the volume */
  83. enum exstate4 be_state; /* the state of this extent */
  84. struct pnfs_inval_markings *be_inval; /* tracks INVAL->RW transition */
  85. };
  86. /* Shortened extent used by LAYOUTCOMMIT */
  87. struct pnfs_block_short_extent {
  88. struct list_head bse_node;
  89. struct nfs4_deviceid bse_devid;
  90. struct block_device *bse_mdev;
  91. sector_t bse_f_offset; /* the starting offset in the file */
  92. sector_t bse_length; /* the size of the extent */
  93. };
  94. static inline void
  95. BL_INIT_INVAL_MARKS(struct pnfs_inval_markings *marks, sector_t blocksize)
  96. {
  97. spin_lock_init(&marks->im_lock);
  98. INIT_LIST_HEAD(&marks->im_tree.mtt_stub);
  99. INIT_LIST_HEAD(&marks->im_extents);
  100. marks->im_block_size = blocksize;
  101. marks->im_tree.mtt_step_size = min((sector_t)PAGE_CACHE_SECTORS,
  102. blocksize);
  103. }
  104. enum extentclass4 {
  105. RW_EXTENT = 0, /* READWRTE and INVAL */
  106. RO_EXTENT = 1, /* READ and NONE */
  107. EXTENT_LISTS = 2,
  108. };
  109. static inline int bl_choose_list(enum exstate4 state)
  110. {
  111. if (state == PNFS_BLOCK_READ_DATA || state == PNFS_BLOCK_NONE_DATA)
  112. return RO_EXTENT;
  113. else
  114. return RW_EXTENT;
  115. }
  116. struct pnfs_block_layout {
  117. struct pnfs_layout_hdr bl_layout;
  118. struct pnfs_inval_markings bl_inval; /* tracks INVAL->RW transition */
  119. spinlock_t bl_ext_lock; /* Protects list manipulation */
  120. struct list_head bl_extents[EXTENT_LISTS]; /* R and RW extents */
  121. struct list_head bl_commit; /* Needs layout commit */
  122. struct list_head bl_committing; /* Layout committing */
  123. unsigned int bl_count; /* entries in bl_commit */
  124. sector_t bl_blocksize; /* Server blocksize in sectors */
  125. };
  126. #define BLK_ID(lo) ((struct block_mount_id *)(NFS_SERVER(lo->plh_inode)->pnfs_ld_data))
  127. static inline struct pnfs_block_layout *
  128. BLK_LO2EXT(struct pnfs_layout_hdr *lo)
  129. {
  130. return container_of(lo, struct pnfs_block_layout, bl_layout);
  131. }
  132. static inline struct pnfs_block_layout *
  133. BLK_LSEG2EXT(struct pnfs_layout_segment *lseg)
  134. {
  135. return BLK_LO2EXT(lseg->pls_layout);
  136. }
  137. struct bl_pipe_msg {
  138. struct rpc_pipe_msg msg;
  139. wait_queue_head_t *bl_wq;
  140. };
  141. struct bl_msg_hdr {
  142. u8 type;
  143. u16 totallen; /* length of entire message, including hdr itself */
  144. };
  145. #define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */
  146. #define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/
  147. #define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */
  148. #define BL_DEVICE_REQUEST_PROC 0x1 /* User level process succeeds */
  149. #define BL_DEVICE_REQUEST_ERR 0x2 /* User level process fails */
  150. /* blocklayoutdev.c */
  151. ssize_t bl_pipe_downcall(struct file *, const char __user *, size_t);
  152. void bl_pipe_destroy_msg(struct rpc_pipe_msg *);
  153. struct block_device *nfs4_blkdev_get(dev_t dev);
  154. int nfs4_blkdev_put(struct block_device *bdev);
  155. struct pnfs_block_dev *nfs4_blk_decode_device(struct nfs_server *server,
  156. struct pnfs_device *dev);
  157. int nfs4_blk_process_layoutget(struct pnfs_layout_hdr *lo,
  158. struct nfs4_layoutget_res *lgr, gfp_t gfp_flags);
  159. /* blocklayoutdm.c */
  160. void bl_free_block_dev(struct pnfs_block_dev *bdev);
  161. /* extents.c */
  162. struct pnfs_block_extent *
  163. bl_find_get_extent(struct pnfs_block_layout *bl, sector_t isect,
  164. struct pnfs_block_extent **cow_read);
  165. int bl_mark_sectors_init(struct pnfs_inval_markings *marks,
  166. sector_t offset, sector_t length);
  167. void bl_put_extent(struct pnfs_block_extent *be);
  168. struct pnfs_block_extent *bl_alloc_extent(void);
  169. int bl_is_sector_init(struct pnfs_inval_markings *marks, sector_t isect);
  170. int encode_pnfs_block_layoutupdate(struct pnfs_block_layout *bl,
  171. struct xdr_stream *xdr,
  172. const struct nfs4_layoutcommit_args *arg);
  173. void clean_pnfs_block_layoutupdate(struct pnfs_block_layout *bl,
  174. const struct nfs4_layoutcommit_args *arg,
  175. int status);
  176. int bl_add_merge_extent(struct pnfs_block_layout *bl,
  177. struct pnfs_block_extent *new);
  178. int bl_mark_for_commit(struct pnfs_block_extent *be,
  179. sector_t offset, sector_t length,
  180. struct pnfs_block_short_extent *new);
  181. int bl_push_one_short_extent(struct pnfs_inval_markings *marks);
  182. struct pnfs_block_short_extent *
  183. bl_pop_one_short_extent(struct pnfs_inval_markings *marks);
  184. void bl_free_short_extents(struct pnfs_inval_markings *marks, int num_to_free);
  185. #endif /* FS_NFS_NFS4BLOCKLAYOUT_H */