internal.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * NFS internal definitions
  3. */
  4. #include <linux/mount.h>
  5. struct nfs_clone_mount {
  6. const struct super_block *sb;
  7. const struct dentry *dentry;
  8. struct nfs_fh *fh;
  9. struct nfs_fattr *fattr;
  10. char *hostname;
  11. char *mnt_path;
  12. struct sockaddr_in *addr;
  13. rpc_authflavor_t authflavor;
  14. };
  15. /* client.c */
  16. extern void nfs_put_client(struct nfs_client *);
  17. extern struct nfs_client *nfs_find_client(const struct sockaddr_in *, int);
  18. extern struct nfs_client *nfs_get_client(const char *, const struct sockaddr_in *, int);
  19. extern void nfs_mark_client_ready(struct nfs_client *, int);
  20. extern int nfs_create_rpc_client(struct nfs_client *, int, unsigned int,
  21. unsigned int, rpc_authflavor_t);
  22. /* nfs4namespace.c */
  23. #ifdef CONFIG_NFS_V4
  24. extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
  25. #else
  26. static inline
  27. struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
  28. {
  29. return ERR_PTR(-ENOENT);
  30. }
  31. #endif
  32. /* callback_xdr.c */
  33. extern struct svc_version nfs4_callback_version1;
  34. /* pagelist.c */
  35. extern int __init nfs_init_nfspagecache(void);
  36. extern void nfs_destroy_nfspagecache(void);
  37. extern int __init nfs_init_readpagecache(void);
  38. extern void nfs_destroy_readpagecache(void);
  39. extern int __init nfs_init_writepagecache(void);
  40. extern void nfs_destroy_writepagecache(void);
  41. #ifdef CONFIG_NFS_DIRECTIO
  42. extern int __init nfs_init_directcache(void);
  43. extern void nfs_destroy_directcache(void);
  44. #else
  45. #define nfs_init_directcache() (0)
  46. #define nfs_destroy_directcache() do {} while(0)
  47. #endif
  48. /* nfs2xdr.c */
  49. extern int nfs_stat_to_errno(int);
  50. extern struct rpc_procinfo nfs_procedures[];
  51. extern u32 * nfs_decode_dirent(u32 *, struct nfs_entry *, int);
  52. /* nfs3xdr.c */
  53. extern struct rpc_procinfo nfs3_procedures[];
  54. extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
  55. /* nfs4xdr.c */
  56. #ifdef CONFIG_NFS_V4
  57. extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
  58. #endif
  59. /* nfs4proc.c */
  60. #ifdef CONFIG_NFS_V4
  61. extern struct rpc_procinfo nfs4_procedures[];
  62. extern int nfs4_proc_fs_locations(struct inode *dir, struct dentry *dentry,
  63. struct nfs4_fs_locations *fs_locations,
  64. struct page *page);
  65. #endif
  66. /* dir.c */
  67. extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
  68. /* inode.c */
  69. extern struct inode *nfs_alloc_inode(struct super_block *sb);
  70. extern void nfs_destroy_inode(struct inode *);
  71. extern int nfs_write_inode(struct inode *,int);
  72. extern void nfs_clear_inode(struct inode *);
  73. #ifdef CONFIG_NFS_V4
  74. extern void nfs4_clear_inode(struct inode *);
  75. #endif
  76. /* super.c */
  77. extern struct file_system_type nfs_referral_nfs4_fs_type;
  78. extern struct file_system_type clone_nfs_fs_type;
  79. #ifdef CONFIG_NFS_V4
  80. extern struct file_system_type clone_nfs4_fs_type;
  81. #endif
  82. extern struct rpc_stat nfs_rpcstat;
  83. extern int __init register_nfs_fs(void);
  84. extern void __exit unregister_nfs_fs(void);
  85. /* namespace.c */
  86. extern char *nfs_path(const char *base, const struct dentry *dentry,
  87. char *buffer, ssize_t buflen);
  88. /*
  89. * Determine the mount path as a string
  90. */
  91. #ifdef CONFIG_NFS_V4
  92. static inline char *
  93. nfs4_path(const struct dentry *dentry, char *buffer, ssize_t buflen)
  94. {
  95. return nfs_path(NFS_SB(dentry->d_sb)->mnt_path, dentry, buffer, buflen);
  96. }
  97. #endif
  98. /*
  99. * Determine the device name as a string
  100. */
  101. static inline char *nfs_devname(const struct vfsmount *mnt_parent,
  102. const struct dentry *dentry,
  103. char *buffer, ssize_t buflen)
  104. {
  105. return nfs_path(mnt_parent->mnt_devname, dentry, buffer, buflen);
  106. }
  107. /*
  108. * Determine the actual block size (and log2 thereof)
  109. */
  110. static inline
  111. unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
  112. {
  113. /* make sure blocksize is a power of two */
  114. if ((bsize & (bsize - 1)) || nrbitsp) {
  115. unsigned char nrbits;
  116. for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
  117. ;
  118. bsize = 1 << nrbits;
  119. if (nrbitsp)
  120. *nrbitsp = nrbits;
  121. }
  122. return bsize;
  123. }
  124. /*
  125. * Calculate the number of 512byte blocks used.
  126. */
  127. static inline unsigned long nfs_calc_block_size(u64 tsize)
  128. {
  129. loff_t used = (tsize + 511) >> 9;
  130. return (used > ULONG_MAX) ? ULONG_MAX : used;
  131. }
  132. /*
  133. * Compute and set NFS server blocksize
  134. */
  135. static inline
  136. unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
  137. {
  138. if (bsize < NFS_MIN_FILE_IO_SIZE)
  139. bsize = NFS_DEF_FILE_IO_SIZE;
  140. else if (bsize >= NFS_MAX_FILE_IO_SIZE)
  141. bsize = NFS_MAX_FILE_IO_SIZE;
  142. return nfs_block_bits(bsize, nrbitsp);
  143. }
  144. /*
  145. * Determine the maximum file size for a superblock
  146. */
  147. static inline
  148. void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
  149. {
  150. sb->s_maxbytes = (loff_t)maxfilesize;
  151. if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
  152. sb->s_maxbytes = MAX_LFS_FILESIZE;
  153. }
  154. /*
  155. * Check if the string represents a "valid" IPv4 address
  156. */
  157. static inline int valid_ipaddr4(const char *buf)
  158. {
  159. int rc, count, in[4];
  160. rc = sscanf(buf, "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
  161. if (rc != 4)
  162. return -EINVAL;
  163. for (count = 0; count < 4; count++) {
  164. if (in[count] > 255)
  165. return -EINVAL;
  166. }
  167. return 0;
  168. }