blocklayout.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 "../nfs4_fs.h"
  38. #include "../pnfs.h"
  39. #include "../netns.h"
  40. #define PAGE_CACHE_SECTORS (PAGE_CACHE_SIZE >> SECTOR_SHIFT)
  41. #define PAGE_CACHE_SECTOR_SHIFT (PAGE_CACHE_SHIFT - SECTOR_SHIFT)
  42. #define SECTOR_SIZE (1 << SECTOR_SHIFT)
  43. struct pnfs_block_dev;
  44. enum pnfs_block_volume_type {
  45. PNFS_BLOCK_VOLUME_SIMPLE = 0,
  46. PNFS_BLOCK_VOLUME_SLICE = 1,
  47. PNFS_BLOCK_VOLUME_CONCAT = 2,
  48. PNFS_BLOCK_VOLUME_STRIPE = 3,
  49. };
  50. #define PNFS_BLOCK_MAX_UUIDS 4
  51. #define PNFS_BLOCK_MAX_DEVICES 64
  52. /*
  53. * Random upper cap for the uuid length to avoid unbounded allocation.
  54. * Not actually limited by the protocol.
  55. */
  56. #define PNFS_BLOCK_UUID_LEN 128
  57. struct pnfs_block_volume {
  58. enum pnfs_block_volume_type type;
  59. union {
  60. struct {
  61. int len;
  62. int nr_sigs;
  63. struct {
  64. u64 offset;
  65. u32 sig_len;
  66. u8 sig[PNFS_BLOCK_UUID_LEN];
  67. } sigs[PNFS_BLOCK_MAX_UUIDS];
  68. } simple;
  69. struct {
  70. u64 start;
  71. u64 len;
  72. u32 volume;
  73. } slice;
  74. struct {
  75. u32 volumes_count;
  76. u32 volumes[PNFS_BLOCK_MAX_DEVICES];
  77. } concat;
  78. struct {
  79. u64 chunk_size;
  80. u32 volumes_count;
  81. u32 volumes[PNFS_BLOCK_MAX_DEVICES];
  82. } stripe;
  83. };
  84. };
  85. struct pnfs_block_dev_map {
  86. sector_t start;
  87. sector_t len;
  88. sector_t disk_offset;
  89. struct block_device *bdev;
  90. };
  91. struct pnfs_block_dev {
  92. struct nfs4_deviceid_node node;
  93. u64 start;
  94. u64 len;
  95. u32 nr_children;
  96. struct pnfs_block_dev *children;
  97. u64 chunk_size;
  98. struct block_device *bdev;
  99. u64 disk_offset;
  100. bool (*map)(struct pnfs_block_dev *dev, u64 offset,
  101. struct pnfs_block_dev_map *map);
  102. };
  103. enum exstate4 {
  104. PNFS_BLOCK_READWRITE_DATA = 0,
  105. PNFS_BLOCK_READ_DATA = 1,
  106. PNFS_BLOCK_INVALID_DATA = 2, /* mapped, but data is invalid */
  107. PNFS_BLOCK_NONE_DATA = 3 /* unmapped, it's a hole */
  108. };
  109. /* sector_t fields are all in 512-byte sectors */
  110. struct pnfs_block_extent {
  111. union {
  112. struct rb_node be_node;
  113. struct list_head be_list;
  114. };
  115. struct nfs4_deviceid_node *be_device;
  116. sector_t be_f_offset; /* the starting offset in the file */
  117. sector_t be_length; /* the size of the extent */
  118. sector_t be_v_offset; /* the starting offset in the volume */
  119. enum exstate4 be_state; /* the state of this extent */
  120. #define EXTENT_WRITTEN 1
  121. #define EXTENT_COMMITTING 2
  122. unsigned int be_tag;
  123. };
  124. /* on the wire size of the extent */
  125. #define BL_EXTENT_SIZE (7 * sizeof(__be32) + NFS4_DEVICEID4_SIZE)
  126. struct pnfs_block_layout {
  127. struct pnfs_layout_hdr bl_layout;
  128. struct rb_root bl_ext_rw;
  129. struct rb_root bl_ext_ro;
  130. spinlock_t bl_ext_lock; /* Protects list manipulation */
  131. };
  132. static inline struct pnfs_block_layout *
  133. BLK_LO2EXT(struct pnfs_layout_hdr *lo)
  134. {
  135. return container_of(lo, struct pnfs_block_layout, bl_layout);
  136. }
  137. static inline struct pnfs_block_layout *
  138. BLK_LSEG2EXT(struct pnfs_layout_segment *lseg)
  139. {
  140. return BLK_LO2EXT(lseg->pls_layout);
  141. }
  142. struct bl_pipe_msg {
  143. struct rpc_pipe_msg msg;
  144. wait_queue_head_t *bl_wq;
  145. };
  146. struct bl_msg_hdr {
  147. u8 type;
  148. u16 totallen; /* length of entire message, including hdr itself */
  149. };
  150. #define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */
  151. #define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/
  152. #define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */
  153. #define BL_DEVICE_REQUEST_PROC 0x1 /* User level process succeeds */
  154. #define BL_DEVICE_REQUEST_ERR 0x2 /* User level process fails */
  155. /* dev.c */
  156. struct nfs4_deviceid_node *bl_alloc_deviceid_node(struct nfs_server *server,
  157. struct pnfs_device *pdev, gfp_t gfp_mask);
  158. void bl_free_deviceid_node(struct nfs4_deviceid_node *d);
  159. /* extent_tree.c */
  160. int ext_tree_insert(struct pnfs_block_layout *bl,
  161. struct pnfs_block_extent *new);
  162. int ext_tree_remove(struct pnfs_block_layout *bl, bool rw, sector_t start,
  163. sector_t end);
  164. int ext_tree_mark_written(struct pnfs_block_layout *bl, sector_t start,
  165. sector_t len);
  166. bool ext_tree_lookup(struct pnfs_block_layout *bl, sector_t isect,
  167. struct pnfs_block_extent *ret, bool rw);
  168. int ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg);
  169. void ext_tree_mark_committed(struct nfs4_layoutcommit_args *arg, int status);
  170. /* rpc_pipefs.c */
  171. dev_t bl_resolve_deviceid(struct nfs_server *server,
  172. struct pnfs_block_volume *b, gfp_t gfp_mask);
  173. int __init bl_init_pipefs(void);
  174. void __exit bl_cleanup_pipefs(void);
  175. #endif /* FS_NFS_NFS4BLOCKLAYOUT_H */