blocklayout.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. struct block_mount_id {
  39. spinlock_t bm_lock; /* protects list */
  40. struct list_head bm_devlist; /* holds pnfs_block_dev */
  41. };
  42. struct pnfs_block_dev {
  43. struct list_head bm_node;
  44. struct nfs4_deviceid bm_mdevid; /* associated devid */
  45. struct block_device *bm_mdev; /* meta device itself */
  46. };
  47. enum exstate4 {
  48. PNFS_BLOCK_READWRITE_DATA = 0,
  49. PNFS_BLOCK_READ_DATA = 1,
  50. PNFS_BLOCK_INVALID_DATA = 2, /* mapped, but data is invalid */
  51. PNFS_BLOCK_NONE_DATA = 3 /* unmapped, it's a hole */
  52. };
  53. struct pnfs_inval_markings {
  54. /* STUB */
  55. };
  56. /* sector_t fields are all in 512-byte sectors */
  57. struct pnfs_block_extent {
  58. struct kref be_refcnt;
  59. struct list_head be_node; /* link into lseg list */
  60. struct nfs4_deviceid be_devid; /* FIXME: could use device cache instead */
  61. struct block_device *be_mdev;
  62. sector_t be_f_offset; /* the starting offset in the file */
  63. sector_t be_length; /* the size of the extent */
  64. sector_t be_v_offset; /* the starting offset in the volume */
  65. enum exstate4 be_state; /* the state of this extent */
  66. struct pnfs_inval_markings *be_inval; /* tracks INVAL->RW transition */
  67. };
  68. static inline void
  69. BL_INIT_INVAL_MARKS(struct pnfs_inval_markings *marks, sector_t blocksize)
  70. {
  71. /* STUB */
  72. }
  73. enum extentclass4 {
  74. RW_EXTENT = 0, /* READWRTE and INVAL */
  75. RO_EXTENT = 1, /* READ and NONE */
  76. EXTENT_LISTS = 2,
  77. };
  78. static inline int bl_choose_list(enum exstate4 state)
  79. {
  80. if (state == PNFS_BLOCK_READ_DATA || state == PNFS_BLOCK_NONE_DATA)
  81. return RO_EXTENT;
  82. else
  83. return RW_EXTENT;
  84. }
  85. struct pnfs_block_layout {
  86. struct pnfs_layout_hdr bl_layout;
  87. struct pnfs_inval_markings bl_inval; /* tracks INVAL->RW transition */
  88. spinlock_t bl_ext_lock; /* Protects list manipulation */
  89. struct list_head bl_extents[EXTENT_LISTS]; /* R and RW extents */
  90. struct list_head bl_commit; /* Needs layout commit */
  91. struct list_head bl_committing; /* Layout committing */
  92. unsigned int bl_count; /* entries in bl_commit */
  93. sector_t bl_blocksize; /* Server blocksize in sectors */
  94. };
  95. #define BLK_ID(lo) ((struct block_mount_id *)(NFS_SERVER(lo->plh_inode)->pnfs_ld_data))
  96. static inline struct pnfs_block_layout *
  97. BLK_LO2EXT(struct pnfs_layout_hdr *lo)
  98. {
  99. return container_of(lo, struct pnfs_block_layout, bl_layout);
  100. }
  101. static inline struct pnfs_block_layout *
  102. BLK_LSEG2EXT(struct pnfs_layout_segment *lseg)
  103. {
  104. return BLK_LO2EXT(lseg->pls_layout);
  105. }
  106. struct bl_dev_msg {
  107. int status;
  108. uint32_t major, minor;
  109. };
  110. struct bl_msg_hdr {
  111. u8 type;
  112. u16 totallen; /* length of entire message, including hdr itself */
  113. };
  114. extern struct dentry *bl_device_pipe;
  115. extern wait_queue_head_t bl_wq;
  116. #define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */
  117. #define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/
  118. #define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */
  119. #define BL_DEVICE_REQUEST_PROC 0x1 /* User level process succeeds */
  120. #define BL_DEVICE_REQUEST_ERR 0x2 /* User level process fails */
  121. /* blocklayoutdev.c */
  122. ssize_t bl_pipe_upcall(struct file *, struct rpc_pipe_msg *,
  123. char __user *, size_t);
  124. ssize_t bl_pipe_downcall(struct file *, const char __user *, size_t);
  125. void bl_pipe_destroy_msg(struct rpc_pipe_msg *);
  126. struct block_device *nfs4_blkdev_get(dev_t dev);
  127. int nfs4_blkdev_put(struct block_device *bdev);
  128. struct pnfs_block_dev *nfs4_blk_decode_device(struct nfs_server *server,
  129. struct pnfs_device *dev);
  130. int nfs4_blk_process_layoutget(struct pnfs_layout_hdr *lo,
  131. struct nfs4_layoutget_res *lgr, gfp_t gfp_flags);
  132. /* blocklayoutdm.c */
  133. void bl_free_block_dev(struct pnfs_block_dev *bdev);
  134. /* extents.c */
  135. struct pnfs_block_extent *
  136. bl_find_get_extent(struct pnfs_block_layout *bl, sector_t isect,
  137. struct pnfs_block_extent **cow_read);
  138. void bl_put_extent(struct pnfs_block_extent *be);
  139. struct pnfs_block_extent *bl_alloc_extent(void);
  140. int bl_add_merge_extent(struct pnfs_block_layout *bl,
  141. struct pnfs_block_extent *new);
  142. #endif /* FS_NFS_NFS4BLOCKLAYOUT_H */