1 /* 2 * NFS internal definitions 3 */ 4 5 #include <linux/mount.h> 6 #include <linux/security.h> 7 8 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS) 9 10 struct nfs_string; 11 12 /* Maximum number of readahead requests 13 * FIXME: this should really be a sysctl so that users may tune it to suit 14 * their needs. People that do NFS over a slow network, might for 15 * instance want to reduce it to something closer to 1 for improved 16 * interactive response. 17 */ 18 #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1) 19 20 struct nfs_clone_mount { 21 const struct super_block *sb; 22 const struct dentry *dentry; 23 struct nfs_fh *fh; 24 struct nfs_fattr *fattr; 25 char *hostname; 26 char *mnt_path; 27 struct sockaddr *addr; 28 size_t addrlen; 29 rpc_authflavor_t authflavor; 30 }; 31 32 /* 33 * Note: RFC 1813 doesn't limit the number of auth flavors that 34 * a server can return, so make something up. 35 */ 36 #define NFS_MAX_SECFLAVORS (12) 37 38 /* 39 * In-kernel mount arguments 40 */ 41 struct nfs_parsed_mount_data { 42 int flags; 43 int rsize, wsize; 44 int timeo, retrans; 45 int acregmin, acregmax, 46 acdirmin, acdirmax; 47 int namlen; 48 unsigned int options; 49 unsigned int bsize; 50 unsigned int auth_flavor_len; 51 rpc_authflavor_t auth_flavors[1]; 52 char *client_address; 53 char *fscache_uniq; 54 55 struct { 56 struct sockaddr_storage address; 57 size_t addrlen; 58 char *hostname; 59 u32 version; 60 unsigned short port; 61 unsigned short protocol; 62 } mount_server; 63 64 struct { 65 struct sockaddr_storage address; 66 size_t addrlen; 67 char *hostname; 68 char *export_path; 69 unsigned short port; 70 unsigned short protocol; 71 } nfs_server; 72 73 struct security_mnt_opts lsm_opts; 74 }; 75 76 /* mount_clnt.c */ 77 struct nfs_mount_request { 78 struct sockaddr *sap; 79 size_t salen; 80 char *hostname; 81 char *dirpath; 82 u32 version; 83 unsigned short protocol; 84 struct nfs_fh *fh; 85 int noresvport; 86 }; 87 88 extern int nfs_mount(struct nfs_mount_request *info); 89 90 /* client.c */ 91 extern struct rpc_program nfs_program; 92 93 extern void nfs_put_client(struct nfs_client *); 94 extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32); 95 extern struct nfs_client *nfs_find_client_next(struct nfs_client *); 96 extern struct nfs_server *nfs_create_server( 97 const struct nfs_parsed_mount_data *, 98 struct nfs_fh *); 99 extern struct nfs_server *nfs4_create_server( 100 const struct nfs_parsed_mount_data *, 101 struct nfs_fh *); 102 extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *, 103 struct nfs_fh *); 104 extern void nfs_free_server(struct nfs_server *server); 105 extern struct nfs_server *nfs_clone_server(struct nfs_server *, 106 struct nfs_fh *, 107 struct nfs_fattr *); 108 #ifdef CONFIG_PROC_FS 109 extern int __init nfs_fs_proc_init(void); 110 extern void nfs_fs_proc_exit(void); 111 #else 112 static inline int nfs_fs_proc_init(void) 113 { 114 return 0; 115 } 116 static inline void nfs_fs_proc_exit(void) 117 { 118 } 119 #endif 120 121 /* nfs4namespace.c */ 122 #ifdef CONFIG_NFS_V4 123 extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry); 124 #else 125 static inline 126 struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry) 127 { 128 return ERR_PTR(-ENOENT); 129 } 130 #endif 131 132 /* callback_xdr.c */ 133 extern struct svc_version nfs4_callback_version1; 134 135 /* pagelist.c */ 136 extern int __init nfs_init_nfspagecache(void); 137 extern void nfs_destroy_nfspagecache(void); 138 extern int __init nfs_init_readpagecache(void); 139 extern void nfs_destroy_readpagecache(void); 140 extern int __init nfs_init_writepagecache(void); 141 extern void nfs_destroy_writepagecache(void); 142 143 extern int __init nfs_init_directcache(void); 144 extern void nfs_destroy_directcache(void); 145 146 /* nfs2xdr.c */ 147 extern int nfs_stat_to_errno(int); 148 extern struct rpc_procinfo nfs_procedures[]; 149 extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int); 150 151 /* nfs3xdr.c */ 152 extern struct rpc_procinfo nfs3_procedures[]; 153 extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int); 154 155 /* nfs4xdr.c */ 156 #ifdef CONFIG_NFS_V4 157 extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus); 158 #endif 159 160 /* nfs4proc.c */ 161 #ifdef CONFIG_NFS_V4 162 extern struct rpc_procinfo nfs4_procedures[]; 163 #endif 164 165 /* proc.c */ 166 void nfs_close_context(struct nfs_open_context *ctx, int is_sync); 167 168 /* dir.c */ 169 extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask); 170 171 /* inode.c */ 172 extern struct workqueue_struct *nfsiod_workqueue; 173 extern struct inode *nfs_alloc_inode(struct super_block *sb); 174 extern void nfs_destroy_inode(struct inode *); 175 extern int nfs_write_inode(struct inode *,int); 176 extern void nfs_clear_inode(struct inode *); 177 #ifdef CONFIG_NFS_V4 178 extern void nfs4_clear_inode(struct inode *); 179 #endif 180 void nfs_zap_acl_cache(struct inode *inode); 181 extern int nfs_wait_bit_killable(void *word); 182 183 /* super.c */ 184 void nfs_parse_ip_address(char *, size_t, struct sockaddr *, size_t *); 185 extern struct file_system_type nfs_xdev_fs_type; 186 #ifdef CONFIG_NFS_V4 187 extern struct file_system_type nfs4_xdev_fs_type; 188 extern struct file_system_type nfs4_referral_fs_type; 189 #endif 190 191 extern struct rpc_stat nfs_rpcstat; 192 193 extern int __init register_nfs_fs(void); 194 extern void __exit unregister_nfs_fs(void); 195 extern void nfs_sb_active(struct super_block *sb); 196 extern void nfs_sb_deactive(struct super_block *sb); 197 198 /* namespace.c */ 199 extern char *nfs_path(const char *base, 200 const struct dentry *droot, 201 const struct dentry *dentry, 202 char *buffer, ssize_t buflen); 203 204 /* getroot.c */ 205 extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *); 206 #ifdef CONFIG_NFS_V4 207 extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *); 208 209 extern int nfs4_path_walk(struct nfs_server *server, 210 struct nfs_fh *mntfh, 211 const char *path); 212 #endif 213 214 /* 215 * Determine the device name as a string 216 */ 217 static inline char *nfs_devname(const struct vfsmount *mnt_parent, 218 const struct dentry *dentry, 219 char *buffer, ssize_t buflen) 220 { 221 return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root, 222 dentry, buffer, buflen); 223 } 224 225 /* 226 * Determine the actual block size (and log2 thereof) 227 */ 228 static inline 229 unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp) 230 { 231 /* make sure blocksize is a power of two */ 232 if ((bsize & (bsize - 1)) || nrbitsp) { 233 unsigned char nrbits; 234 235 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--) 236 ; 237 bsize = 1 << nrbits; 238 if (nrbitsp) 239 *nrbitsp = nrbits; 240 } 241 242 return bsize; 243 } 244 245 /* 246 * Calculate the number of 512byte blocks used. 247 */ 248 static inline blkcnt_t nfs_calc_block_size(u64 tsize) 249 { 250 blkcnt_t used = (tsize + 511) >> 9; 251 return (used > ULONG_MAX) ? ULONG_MAX : used; 252 } 253 254 /* 255 * Compute and set NFS server blocksize 256 */ 257 static inline 258 unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp) 259 { 260 if (bsize < NFS_MIN_FILE_IO_SIZE) 261 bsize = NFS_DEF_FILE_IO_SIZE; 262 else if (bsize >= NFS_MAX_FILE_IO_SIZE) 263 bsize = NFS_MAX_FILE_IO_SIZE; 264 265 return nfs_block_bits(bsize, nrbitsp); 266 } 267 268 /* 269 * Determine the maximum file size for a superblock 270 */ 271 static inline 272 void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize) 273 { 274 sb->s_maxbytes = (loff_t)maxfilesize; 275 if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0) 276 sb->s_maxbytes = MAX_LFS_FILESIZE; 277 } 278 279 /* 280 * Determine the number of bytes of data the page contains 281 */ 282 static inline 283 unsigned int nfs_page_length(struct page *page) 284 { 285 loff_t i_size = i_size_read(page->mapping->host); 286 287 if (i_size > 0) { 288 pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT; 289 if (page->index < end_index) 290 return PAGE_CACHE_SIZE; 291 if (page->index == end_index) 292 return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1; 293 } 294 return 0; 295 } 296 297 /* 298 * Determine the number of pages in an array of length 'len' and 299 * with a base offset of 'base' 300 */ 301 static inline 302 unsigned int nfs_page_array_len(unsigned int base, size_t len) 303 { 304 return ((unsigned long)len + (unsigned long)base + 305 PAGE_SIZE - 1) >> PAGE_SHIFT; 306 } 307 308 #define IPV6_SCOPE_DELIMITER '%' 309 310 /* 311 * Set the port number in an address. Be agnostic about the address 312 * family. 313 */ 314 static inline void nfs_set_port(struct sockaddr *sap, unsigned short port) 315 { 316 struct sockaddr_in *ap = (struct sockaddr_in *)sap; 317 struct sockaddr_in6 *ap6 = (struct sockaddr_in6 *)sap; 318 319 switch (sap->sa_family) { 320 case AF_INET: 321 ap->sin_port = htons(port); 322 break; 323 case AF_INET6: 324 ap6->sin6_port = htons(port); 325 break; 326 } 327 } 328