nfsfh.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* Copyright (C) 1995, 1996, 1997 Olaf Kirch <okir@monad.swb.de> */
  2. #ifndef _LINUX_NFSD_FH_INT_H
  3. #define _LINUX_NFSD_FH_INT_H
  4. #include <linux/nfsd/nfsfh.h>
  5. enum nfsd_fsid {
  6. FSID_DEV = 0,
  7. FSID_NUM,
  8. FSID_MAJOR_MINOR,
  9. FSID_ENCODE_DEV,
  10. FSID_UUID4_INUM,
  11. FSID_UUID8,
  12. FSID_UUID16,
  13. FSID_UUID16_INUM,
  14. };
  15. enum fsid_source {
  16. FSIDSOURCE_DEV,
  17. FSIDSOURCE_FSID,
  18. FSIDSOURCE_UUID,
  19. };
  20. extern enum fsid_source fsid_source(struct svc_fh *fhp);
  21. /* This might look a little large to "inline" but in all calls except
  22. * one, 'vers' is constant so moste of the function disappears.
  23. */
  24. static inline void mk_fsid(int vers, u32 *fsidv, dev_t dev, ino_t ino,
  25. u32 fsid, unsigned char *uuid)
  26. {
  27. u32 *up;
  28. switch(vers) {
  29. case FSID_DEV:
  30. fsidv[0] = htonl((MAJOR(dev)<<16) |
  31. MINOR(dev));
  32. fsidv[1] = ino_t_to_u32(ino);
  33. break;
  34. case FSID_NUM:
  35. fsidv[0] = fsid;
  36. break;
  37. case FSID_MAJOR_MINOR:
  38. fsidv[0] = htonl(MAJOR(dev));
  39. fsidv[1] = htonl(MINOR(dev));
  40. fsidv[2] = ino_t_to_u32(ino);
  41. break;
  42. case FSID_ENCODE_DEV:
  43. fsidv[0] = new_encode_dev(dev);
  44. fsidv[1] = ino_t_to_u32(ino);
  45. break;
  46. case FSID_UUID4_INUM:
  47. /* 4 byte fsid and inode number */
  48. up = (u32*)uuid;
  49. fsidv[0] = ino_t_to_u32(ino);
  50. fsidv[1] = up[0] ^ up[1] ^ up[2] ^ up[3];
  51. break;
  52. case FSID_UUID8:
  53. /* 8 byte fsid */
  54. up = (u32*)uuid;
  55. fsidv[0] = up[0] ^ up[2];
  56. fsidv[1] = up[1] ^ up[3];
  57. break;
  58. case FSID_UUID16:
  59. /* 16 byte fsid - NFSv3+ only */
  60. memcpy(fsidv, uuid, 16);
  61. break;
  62. case FSID_UUID16_INUM:
  63. /* 8 byte inode and 16 byte fsid */
  64. *(u64*)fsidv = (u64)ino;
  65. memcpy(fsidv+2, uuid, 16);
  66. break;
  67. default: BUG();
  68. }
  69. }
  70. static inline int key_len(int type)
  71. {
  72. switch(type) {
  73. case FSID_DEV: return 8;
  74. case FSID_NUM: return 4;
  75. case FSID_MAJOR_MINOR: return 12;
  76. case FSID_ENCODE_DEV: return 8;
  77. case FSID_UUID4_INUM: return 8;
  78. case FSID_UUID8: return 8;
  79. case FSID_UUID16: return 16;
  80. case FSID_UUID16_INUM: return 24;
  81. default: return 0;
  82. }
  83. }
  84. /*
  85. * Shorthand for dprintk()'s
  86. */
  87. extern char * SVCFH_fmt(struct svc_fh *fhp);
  88. /*
  89. * Function prototypes
  90. */
  91. __be32 fh_verify(struct svc_rqst *, struct svc_fh *, umode_t, int);
  92. __be32 fh_compose(struct svc_fh *, struct svc_export *, struct dentry *, struct svc_fh *);
  93. __be32 fh_update(struct svc_fh *);
  94. void fh_put(struct svc_fh *);
  95. static __inline__ struct svc_fh *
  96. fh_copy(struct svc_fh *dst, struct svc_fh *src)
  97. {
  98. WARN_ON(src->fh_dentry || src->fh_locked);
  99. *dst = *src;
  100. return dst;
  101. }
  102. static inline void
  103. fh_copy_shallow(struct knfsd_fh *dst, struct knfsd_fh *src)
  104. {
  105. dst->fh_size = src->fh_size;
  106. memcpy(&dst->fh_base, &src->fh_base, src->fh_size);
  107. }
  108. static __inline__ struct svc_fh *
  109. fh_init(struct svc_fh *fhp, int maxsize)
  110. {
  111. memset(fhp, 0, sizeof(*fhp));
  112. fhp->fh_maxsize = maxsize;
  113. return fhp;
  114. }
  115. #ifdef CONFIG_NFSD_V3
  116. /*
  117. * The wcc data stored in current_fh should be cleared
  118. * between compound ops.
  119. */
  120. static inline void
  121. fh_clear_wcc(struct svc_fh *fhp)
  122. {
  123. fhp->fh_post_saved = 0;
  124. fhp->fh_pre_saved = 0;
  125. }
  126. /*
  127. * Fill in the pre_op attr for the wcc data
  128. */
  129. static inline void
  130. fill_pre_wcc(struct svc_fh *fhp)
  131. {
  132. struct inode *inode;
  133. inode = fhp->fh_dentry->d_inode;
  134. if (!fhp->fh_pre_saved) {
  135. fhp->fh_pre_mtime = inode->i_mtime;
  136. fhp->fh_pre_ctime = inode->i_ctime;
  137. fhp->fh_pre_size = inode->i_size;
  138. fhp->fh_pre_change = inode->i_version;
  139. fhp->fh_pre_saved = 1;
  140. }
  141. }
  142. extern void fill_post_wcc(struct svc_fh *);
  143. #else
  144. #define fh_clear_wcc(ignored)
  145. #define fill_pre_wcc(ignored)
  146. #define fill_post_wcc(notused)
  147. #endif /* CONFIG_NFSD_V3 */
  148. /*
  149. * Lock a file handle/inode
  150. * NOTE: both fh_lock and fh_unlock are done "by hand" in
  151. * vfs.c:nfsd_rename as it needs to grab 2 i_mutex's at once
  152. * so, any changes here should be reflected there.
  153. */
  154. static inline void
  155. fh_lock_nested(struct svc_fh *fhp, unsigned int subclass)
  156. {
  157. struct dentry *dentry = fhp->fh_dentry;
  158. struct inode *inode;
  159. BUG_ON(!dentry);
  160. if (fhp->fh_locked) {
  161. printk(KERN_WARNING "fh_lock: %pd2 already locked!\n",
  162. dentry);
  163. return;
  164. }
  165. inode = dentry->d_inode;
  166. mutex_lock_nested(&inode->i_mutex, subclass);
  167. fill_pre_wcc(fhp);
  168. fhp->fh_locked = 1;
  169. }
  170. static inline void
  171. fh_lock(struct svc_fh *fhp)
  172. {
  173. fh_lock_nested(fhp, I_MUTEX_NORMAL);
  174. }
  175. /*
  176. * Unlock a file handle/inode
  177. */
  178. static inline void
  179. fh_unlock(struct svc_fh *fhp)
  180. {
  181. if (fhp->fh_locked) {
  182. fill_post_wcc(fhp);
  183. mutex_unlock(&fhp->fh_dentry->d_inode->i_mutex);
  184. fhp->fh_locked = 0;
  185. }
  186. }
  187. #endif /* _LINUX_NFSD_FH_INT_H */