blocklayout.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. #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. };
  78. };
  79. struct pnfs_block_dev_map {
  80. sector_t start;
  81. sector_t len;
  82. sector_t disk_offset;
  83. struct block_device *bdev;
  84. };
  85. struct pnfs_block_dev {
  86. struct nfs4_deviceid_node node;
  87. u64 start;
  88. u64 len;
  89. u32 nr_children;
  90. struct pnfs_block_dev *children;
  91. u64 chunk_size;
  92. struct block_device *bdev;
  93. u64 disk_offset;
  94. bool (*map)(struct pnfs_block_dev *dev, u64 offset,
  95. struct pnfs_block_dev_map *map);
  96. };
  97. /* sector_t fields are all in 512-byte sectors */
  98. struct pnfs_block_extent {
  99. union {
  100. struct rb_node be_node;
  101. struct list_head be_list;
  102. };
  103. struct nfs4_deviceid_node *be_device;
  104. sector_t be_f_offset; /* the starting offset in the file */
  105. sector_t be_length; /* the size of the extent */
  106. sector_t be_v_offset; /* the starting offset in the volume */
  107. enum pnfs_block_extent_state be_state; /* the state of this extent */
  108. #define EXTENT_WRITTEN 1
  109. #define EXTENT_COMMITTING 2
  110. unsigned int be_tag;
  111. };
  112. struct pnfs_block_layout {
  113. struct pnfs_layout_hdr bl_layout;
  114. struct rb_root bl_ext_rw;
  115. struct rb_root bl_ext_ro;
  116. spinlock_t bl_ext_lock; /* Protects list manipulation */
  117. };
  118. static inline struct pnfs_block_layout *
  119. BLK_LO2EXT(struct pnfs_layout_hdr *lo)
  120. {
  121. return container_of(lo, struct pnfs_block_layout, bl_layout);
  122. }
  123. static inline struct pnfs_block_layout *
  124. BLK_LSEG2EXT(struct pnfs_layout_segment *lseg)
  125. {
  126. return BLK_LO2EXT(lseg->pls_layout);
  127. }
  128. struct bl_pipe_msg {
  129. struct rpc_pipe_msg msg;
  130. wait_queue_head_t *bl_wq;
  131. };
  132. struct bl_msg_hdr {
  133. u8 type;
  134. u16 totallen; /* length of entire message, including hdr itself */
  135. };
  136. #define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */
  137. #define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/
  138. #define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */
  139. #define BL_DEVICE_REQUEST_PROC 0x1 /* User level process succeeds */
  140. #define BL_DEVICE_REQUEST_ERR 0x2 /* User level process fails */
  141. /* dev.c */
  142. struct nfs4_deviceid_node *bl_alloc_deviceid_node(struct nfs_server *server,
  143. struct pnfs_device *pdev, gfp_t gfp_mask);
  144. void bl_free_deviceid_node(struct nfs4_deviceid_node *d);
  145. /* extent_tree.c */
  146. int ext_tree_insert(struct pnfs_block_layout *bl,
  147. struct pnfs_block_extent *new);
  148. int ext_tree_remove(struct pnfs_block_layout *bl, bool rw, sector_t start,
  149. sector_t end);
  150. int ext_tree_mark_written(struct pnfs_block_layout *bl, sector_t start,
  151. sector_t len);
  152. bool ext_tree_lookup(struct pnfs_block_layout *bl, sector_t isect,
  153. struct pnfs_block_extent *ret, bool rw);
  154. int ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg);
  155. void ext_tree_mark_committed(struct nfs4_layoutcommit_args *arg, int status);
  156. /* rpc_pipefs.c */
  157. dev_t bl_resolve_deviceid(struct nfs_server *server,
  158. struct pnfs_block_volume *b, gfp_t gfp_mask);
  159. int __init bl_init_pipefs(void);
  160. void __exit bl_cleanup_pipefs(void);
  161. #endif /* FS_NFS_NFS4BLOCKLAYOUT_H */