nfsfh.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. * Fill in the pre_op attr for the wcc data
  118. */
  119. static inline void
  120. fill_pre_wcc(struct svc_fh *fhp)
  121. {
  122. struct inode *inode;
  123. inode = fhp->fh_dentry->d_inode;
  124. if (!fhp->fh_pre_saved) {
  125. fhp->fh_pre_mtime = inode->i_mtime;
  126. fhp->fh_pre_ctime = inode->i_ctime;
  127. fhp->fh_pre_size = inode->i_size;
  128. fhp->fh_pre_change = inode->i_version;
  129. fhp->fh_pre_saved = 1;
  130. }
  131. }
  132. extern void fill_post_wcc(struct svc_fh *);
  133. #else
  134. #define fill_pre_wcc(ignored)
  135. #define fill_post_wcc(notused)
  136. #endif /* CONFIG_NFSD_V3 */
  137. /*
  138. * Lock a file handle/inode
  139. * NOTE: both fh_lock and fh_unlock are done "by hand" in
  140. * vfs.c:nfsd_rename as it needs to grab 2 i_mutex's at once
  141. * so, any changes here should be reflected there.
  142. */
  143. static inline void
  144. fh_lock_nested(struct svc_fh *fhp, unsigned int subclass)
  145. {
  146. struct dentry *dentry = fhp->fh_dentry;
  147. struct inode *inode;
  148. BUG_ON(!dentry);
  149. if (fhp->fh_locked) {
  150. printk(KERN_WARNING "fh_lock: %s/%s already locked!\n",
  151. dentry->d_parent->d_name.name, dentry->d_name.name);
  152. return;
  153. }
  154. inode = dentry->d_inode;
  155. mutex_lock_nested(&inode->i_mutex, subclass);
  156. fill_pre_wcc(fhp);
  157. fhp->fh_locked = 1;
  158. }
  159. static inline void
  160. fh_lock(struct svc_fh *fhp)
  161. {
  162. fh_lock_nested(fhp, I_MUTEX_NORMAL);
  163. }
  164. /*
  165. * Unlock a file handle/inode
  166. */
  167. static inline void
  168. fh_unlock(struct svc_fh *fhp)
  169. {
  170. if (fhp->fh_locked) {
  171. fill_post_wcc(fhp);
  172. mutex_unlock(&fhp->fh_dentry->d_inode->i_mutex);
  173. fhp->fh_locked = 0;
  174. }
  175. }
  176. #endif /* _LINUX_NFSD_FH_INT_H */