internal.h 4.9 KB

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