blocklayout.h 5.7 KB

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