nfsfh.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de>
  3. *
  4. * This file describes the layout of the file handles as passed
  5. * over the wire.
  6. */
  7. #ifndef _LINUX_NFSD_NFSFH_H
  8. #define _LINUX_NFSD_NFSFH_H
  9. #include <linux/sunrpc/svc.h>
  10. #include <uapi/linux/nfsd/nfsfh.h>
  11. static inline __u32 ino_t_to_u32(ino_t ino)
  12. {
  13. return (__u32) ino;
  14. }
  15. static inline ino_t u32_to_ino_t(__u32 uino)
  16. {
  17. return (ino_t) uino;
  18. }
  19. /*
  20. * This is the internal representation of an NFS handle used in knfsd.
  21. * pre_mtime/post_version will be used to support wcc_attr's in NFSv3.
  22. */
  23. typedef struct svc_fh {
  24. struct knfsd_fh fh_handle; /* FH data */
  25. struct dentry * fh_dentry; /* validated dentry */
  26. struct svc_export * fh_export; /* export pointer */
  27. int fh_maxsize; /* max size for fh_handle */
  28. unsigned char fh_locked; /* inode locked by us */
  29. unsigned char fh_want_write; /* remount protection taken */
  30. #ifdef CONFIG_NFSD_V3
  31. unsigned char fh_post_saved; /* post-op attrs saved */
  32. unsigned char fh_pre_saved; /* pre-op attrs saved */
  33. /* Pre-op attributes saved during fh_lock */
  34. __u64 fh_pre_size; /* size before operation */
  35. struct timespec fh_pre_mtime; /* mtime before oper */
  36. struct timespec fh_pre_ctime; /* ctime before oper */
  37. /*
  38. * pre-op nfsv4 change attr: note must check IS_I_VERSION(inode)
  39. * to find out if it is valid.
  40. */
  41. u64 fh_pre_change;
  42. /* Post-op attributes saved in fh_unlock */
  43. struct kstat fh_post_attr; /* full attrs after operation */
  44. u64 fh_post_change; /* nfsv4 change; see above */
  45. #endif /* CONFIG_NFSD_V3 */
  46. } svc_fh;
  47. enum nfsd_fsid {
  48. FSID_DEV = 0,
  49. FSID_NUM,
  50. FSID_MAJOR_MINOR,
  51. FSID_ENCODE_DEV,
  52. FSID_UUID4_INUM,
  53. FSID_UUID8,
  54. FSID_UUID16,
  55. FSID_UUID16_INUM,
  56. };
  57. enum fsid_source {
  58. FSIDSOURCE_DEV,
  59. FSIDSOURCE_FSID,
  60. FSIDSOURCE_UUID,
  61. };
  62. extern enum fsid_source fsid_source(struct svc_fh *fhp);
  63. /* This might look a little large to "inline" but in all calls except
  64. * one, 'vers' is constant so moste of the function disappears.
  65. */
  66. static inline void mk_fsid(int vers, u32 *fsidv, dev_t dev, ino_t ino,
  67. u32 fsid, unsigned char *uuid)
  68. {
  69. u32 *up;
  70. switch(vers) {
  71. case FSID_DEV:
  72. fsidv[0] = htonl((MAJOR(dev)<<16) |
  73. MINOR(dev));
  74. fsidv[1] = ino_t_to_u32(ino);
  75. break;
  76. case FSID_NUM:
  77. fsidv[0] = fsid;
  78. break;
  79. case FSID_MAJOR_MINOR:
  80. fsidv[0] = htonl(MAJOR(dev));
  81. fsidv[1] = htonl(MINOR(dev));
  82. fsidv[2] = ino_t_to_u32(ino);
  83. break;
  84. case FSID_ENCODE_DEV:
  85. fsidv[0] = new_encode_dev(dev);
  86. fsidv[1] = ino_t_to_u32(ino);
  87. break;
  88. case FSID_UUID4_INUM:
  89. /* 4 byte fsid and inode number */
  90. up = (u32*)uuid;
  91. fsidv[0] = ino_t_to_u32(ino);
  92. fsidv[1] = up[0] ^ up[1] ^ up[2] ^ up[3];
  93. break;
  94. case FSID_UUID8:
  95. /* 8 byte fsid */
  96. up = (u32*)uuid;
  97. fsidv[0] = up[0] ^ up[2];
  98. fsidv[1] = up[1] ^ up[3];
  99. break;
  100. case FSID_UUID16:
  101. /* 16 byte fsid - NFSv3+ only */
  102. memcpy(fsidv, uuid, 16);
  103. break;
  104. case FSID_UUID16_INUM:
  105. /* 8 byte inode and 16 byte fsid */
  106. *(u64*)fsidv = (u64)ino;
  107. memcpy(fsidv+2, uuid, 16);
  108. break;
  109. default: BUG();
  110. }
  111. }
  112. static inline int key_len(int type)
  113. {
  114. switch(type) {
  115. case FSID_DEV: return 8;
  116. case FSID_NUM: return 4;
  117. case FSID_MAJOR_MINOR: return 12;
  118. case FSID_ENCODE_DEV: return 8;
  119. case FSID_UUID4_INUM: return 8;
  120. case FSID_UUID8: return 8;
  121. case FSID_UUID16: return 16;
  122. case FSID_UUID16_INUM: return 24;
  123. default: return 0;
  124. }
  125. }
  126. /*
  127. * Shorthand for dprintk()'s
  128. */
  129. extern char * SVCFH_fmt(struct svc_fh *fhp);
  130. /*
  131. * Function prototypes
  132. */
  133. __be32 fh_verify(struct svc_rqst *, struct svc_fh *, umode_t, int);
  134. __be32 fh_compose(struct svc_fh *, struct svc_export *, struct dentry *, struct svc_fh *);
  135. __be32 fh_update(struct svc_fh *);
  136. void fh_put(struct svc_fh *);
  137. static __inline__ struct svc_fh *
  138. fh_copy(struct svc_fh *dst, struct svc_fh *src)
  139. {
  140. WARN_ON(src->fh_dentry || src->fh_locked);
  141. *dst = *src;
  142. return dst;
  143. }
  144. static inline void
  145. fh_copy_shallow(struct knfsd_fh *dst, struct knfsd_fh *src)
  146. {
  147. dst->fh_size = src->fh_size;
  148. memcpy(&dst->fh_base, &src->fh_base, src->fh_size);
  149. }
  150. static __inline__ struct svc_fh *
  151. fh_init(struct svc_fh *fhp, int maxsize)
  152. {
  153. memset(fhp, 0, sizeof(*fhp));
  154. fhp->fh_maxsize = maxsize;
  155. return fhp;
  156. }
  157. #ifdef CONFIG_NFSD_V3
  158. /*
  159. * The wcc data stored in current_fh should be cleared
  160. * between compound ops.
  161. */
  162. static inline void
  163. fh_clear_wcc(struct svc_fh *fhp)
  164. {
  165. fhp->fh_post_saved = 0;
  166. fhp->fh_pre_saved = 0;
  167. }
  168. /*
  169. * Fill in the pre_op attr for the wcc data
  170. */
  171. static inline void
  172. fill_pre_wcc(struct svc_fh *fhp)
  173. {
  174. struct inode *inode;
  175. inode = fhp->fh_dentry->d_inode;
  176. if (!fhp->fh_pre_saved) {
  177. fhp->fh_pre_mtime = inode->i_mtime;
  178. fhp->fh_pre_ctime = inode->i_ctime;
  179. fhp->fh_pre_size = inode->i_size;
  180. fhp->fh_pre_change = inode->i_version;
  181. fhp->fh_pre_saved = 1;
  182. }
  183. }
  184. extern void fill_post_wcc(struct svc_fh *);
  185. #else
  186. #define fh_clear_wcc(ignored)
  187. #define fill_pre_wcc(ignored)
  188. #define fill_post_wcc(notused)
  189. #endif /* CONFIG_NFSD_V3 */
  190. /*
  191. * Lock a file handle/inode
  192. * NOTE: both fh_lock and fh_unlock are done "by hand" in
  193. * vfs.c:nfsd_rename as it needs to grab 2 i_mutex's at once
  194. * so, any changes here should be reflected there.
  195. */
  196. static inline void
  197. fh_lock_nested(struct svc_fh *fhp, unsigned int subclass)
  198. {
  199. struct dentry *dentry = fhp->fh_dentry;
  200. struct inode *inode;
  201. BUG_ON(!dentry);
  202. if (fhp->fh_locked) {
  203. printk(KERN_WARNING "fh_lock: %pd2 already locked!\n",
  204. dentry);
  205. return;
  206. }
  207. inode = dentry->d_inode;
  208. mutex_lock_nested(&inode->i_mutex, subclass);
  209. fill_pre_wcc(fhp);
  210. fhp->fh_locked = 1;
  211. }
  212. static inline void
  213. fh_lock(struct svc_fh *fhp)
  214. {
  215. fh_lock_nested(fhp, I_MUTEX_NORMAL);
  216. }
  217. /*
  218. * Unlock a file handle/inode
  219. */
  220. static inline void
  221. fh_unlock(struct svc_fh *fhp)
  222. {
  223. if (fhp->fh_locked) {
  224. fill_post_wcc(fhp);
  225. mutex_unlock(&fhp->fh_dentry->d_inode->i_mutex);
  226. fhp->fh_locked = 0;
  227. }
  228. }
  229. #endif /* _LINUX_NFSD_NFSFH_H */