📄 client.c
字号:
server->acdirmin = data->acdirmin * HZ; server->acdirmax = data->acdirmax * HZ; error = nfs_init_server_rpcclient(server, data->auth_flavors[0]); /* Done */ dprintk("<-- nfs4_init_server() = %d\n", error); return error;}/* * Create a version 4 volume record * - keyed on server and FSID */struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data, struct nfs_fh *mntfh){ struct nfs_fattr fattr; struct nfs_server *server; int error; dprintk("--> nfs4_create_server()\n"); server = nfs_alloc_server(); if (!server) return ERR_PTR(-ENOMEM); /* Get a client record */ error = nfs4_set_client(server, data->nfs_server.hostname, &data->nfs_server.address, data->client_address, data->auth_flavors[0], data->nfs_server.protocol, data->timeo, data->retrans); if (error < 0) goto error; /* set up the general RPC client */ error = nfs4_init_server(server, data); if (error < 0) goto error; BUG_ON(!server->nfs_client); BUG_ON(!server->nfs_client->rpc_ops); BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); /* Probe the root fh to retrieve its FSID */ error = nfs4_path_walk(server, mntfh, data->nfs_server.export_path); if (error < 0) goto error; dprintk("Server FSID: %llx:%llx\n", (unsigned long long) server->fsid.major, (unsigned long long) server->fsid.minor); dprintk("Mount FH: %d\n", mntfh->size); error = nfs_probe_fsinfo(server, mntfh, &fattr); if (error < 0) goto error; if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) server->namelen = NFS4_MAXNAMLEN; BUG_ON(!server->nfs_client); BUG_ON(!server->nfs_client->rpc_ops); BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); spin_lock(&nfs_client_lock); list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); list_add_tail(&server->master_link, &nfs_volume_list); spin_unlock(&nfs_client_lock); server->mount_time = jiffies; dprintk("<-- nfs4_create_server() = %p\n", server); return server;error: nfs_free_server(server); dprintk("<-- nfs4_create_server() = error %d\n", error); return ERR_PTR(error);}/* * Create an NFS4 referral server record */struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data, struct nfs_fh *mntfh){ struct nfs_client *parent_client; struct nfs_server *server, *parent_server; struct nfs_fattr fattr; int error; dprintk("--> nfs4_create_referral_server()\n"); server = nfs_alloc_server(); if (!server) return ERR_PTR(-ENOMEM); parent_server = NFS_SB(data->sb); parent_client = parent_server->nfs_client; /* Get a client representation. * Note: NFSv4 always uses TCP, */ error = nfs4_set_client(server, data->hostname, data->addr, parent_client->cl_ipaddr, data->authflavor, parent_server->client->cl_xprt->prot, parent_client->retrans_timeo, parent_client->retrans_count); if (error < 0) goto error; /* Initialise the client representation from the parent server */ nfs_server_copy_userdata(server, parent_server); server->caps |= NFS_CAP_ATOMIC_OPEN; error = nfs_init_server_rpcclient(server, data->authflavor); if (error < 0) goto error; BUG_ON(!server->nfs_client); BUG_ON(!server->nfs_client->rpc_ops); BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops); /* Probe the root fh to retrieve its FSID and filehandle */ error = nfs4_path_walk(server, mntfh, data->mnt_path); if (error < 0) goto error; /* probe the filesystem info for this server filesystem */ error = nfs_probe_fsinfo(server, mntfh, &fattr); if (error < 0) goto error; if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) server->namelen = NFS4_MAXNAMLEN; dprintk("Referral FSID: %llx:%llx\n", (unsigned long long) server->fsid.major, (unsigned long long) server->fsid.minor); spin_lock(&nfs_client_lock); list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); list_add_tail(&server->master_link, &nfs_volume_list); spin_unlock(&nfs_client_lock); server->mount_time = jiffies; dprintk("<-- nfs_create_referral_server() = %p\n", server); return server;error: nfs_free_server(server); dprintk("<-- nfs4_create_referral_server() = error %d\n", error); return ERR_PTR(error);}#endif /* CONFIG_NFS_V4 *//* * Clone an NFS2, NFS3 or NFS4 server record */struct nfs_server *nfs_clone_server(struct nfs_server *source, struct nfs_fh *fh, struct nfs_fattr *fattr){ struct nfs_server *server; struct nfs_fattr fattr_fsinfo; int error; dprintk("--> nfs_clone_server(,%llx:%llx,)\n", (unsigned long long) fattr->fsid.major, (unsigned long long) fattr->fsid.minor); server = nfs_alloc_server(); if (!server) return ERR_PTR(-ENOMEM); /* Copy data from the source */ server->nfs_client = source->nfs_client; atomic_inc(&server->nfs_client->cl_count); nfs_server_copy_userdata(server, source); server->fsid = fattr->fsid; error = nfs_init_server_rpcclient(server, source->client->cl_auth->au_flavor); if (error < 0) goto out_free_server; if (!IS_ERR(source->client_acl)) nfs_init_server_aclclient(server); /* probe the filesystem info for this server filesystem */ error = nfs_probe_fsinfo(server, fh, &fattr_fsinfo); if (error < 0) goto out_free_server; if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) server->namelen = NFS4_MAXNAMLEN; dprintk("Cloned FSID: %llx:%llx\n", (unsigned long long) server->fsid.major, (unsigned long long) server->fsid.minor); error = nfs_start_lockd(server); if (error < 0) goto out_free_server; spin_lock(&nfs_client_lock); list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); list_add_tail(&server->master_link, &nfs_volume_list); spin_unlock(&nfs_client_lock); server->mount_time = jiffies; dprintk("<-- nfs_clone_server() = %p\n", server); return server;out_free_server: nfs_free_server(server); dprintk("<-- nfs_clone_server() = error %d\n", error); return ERR_PTR(error);}#ifdef CONFIG_PROC_FSstatic struct proc_dir_entry *proc_fs_nfs;static int nfs_server_list_open(struct inode *inode, struct file *file);static void *nfs_server_list_start(struct seq_file *p, loff_t *pos);static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos);static void nfs_server_list_stop(struct seq_file *p, void *v);static int nfs_server_list_show(struct seq_file *m, void *v);static struct seq_operations nfs_server_list_ops = { .start = nfs_server_list_start, .next = nfs_server_list_next, .stop = nfs_server_list_stop, .show = nfs_server_list_show,};static const struct file_operations nfs_server_list_fops = { .open = nfs_server_list_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release,};static int nfs_volume_list_open(struct inode *inode, struct file *file);static void *nfs_volume_list_start(struct seq_file *p, loff_t *pos);static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos);static void nfs_volume_list_stop(struct seq_file *p, void *v);static int nfs_volume_list_show(struct seq_file *m, void *v);static struct seq_operations nfs_volume_list_ops = { .start = nfs_volume_list_start, .next = nfs_volume_list_next, .stop = nfs_volume_list_stop, .show = nfs_volume_list_show,};static const struct file_operations nfs_volume_list_fops = { .open = nfs_volume_list_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release,};/* * open "/proc/fs/nfsfs/servers" which provides a summary of servers with which * we're dealing */static int nfs_server_list_open(struct inode *inode, struct file *file){ struct seq_file *m; int ret; ret = seq_open(file, &nfs_server_list_ops); if (ret < 0) return ret; m = file->private_data; m->private = PDE(inode)->data; return 0;}/* * set up the iterator to start reading from the server list and return the first item */static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos){ /* lock the list against modification */ spin_lock(&nfs_client_lock); return seq_list_start_head(&nfs_client_list, *_pos);}/* * move to next server */static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos){ return seq_list_next(v, &nfs_client_list, pos);}/* * clean up after reading from the transports list */static void nfs_server_list_stop(struct seq_file *p, void *v){ spin_unlock(&nfs_client_lock);}/* * display a header line followed by a load of call lines */static int nfs_server_list_show(struct seq_file *m, void *v){ struct nfs_client *clp; /* display header on line 1 */ if (v == &nfs_client_list) { seq_puts(m, "NV SERVER PORT USE HOSTNAME\n"); return 0; } /* display one transport per line on subsequent lines */ clp = list_entry(v, struct nfs_client, cl_share_link); seq_printf(m, "v%d %02x%02x%02x%02x %4hx %3d %s\n", clp->cl_nfsversion, NIPQUAD(clp->cl_addr.sin_addr), ntohs(clp->cl_addr.sin_port), atomic_read(&clp->cl_count), clp->cl_hostname); return 0;}/* * open "/proc/fs/nfsfs/volumes" which provides a summary of extant volumes */static int nfs_volume_list_open(struct inode *inode, struct file *file){ struct seq_file *m; int ret; ret = seq_open(file, &nfs_volume_list_ops); if (ret < 0) return ret; m = file->private_data; m->private = PDE(inode)->data; return 0;}/* * set up the iterator to start reading from the volume list and return the first item */static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos){ /* lock the list against modification */ spin_lock(&nfs_client_lock); return seq_list_start_head(&nfs_volume_list, *_pos);}/* * move to next volume */static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos){ return seq_list_next(v, &nfs_volume_list, pos);}/* * clean up after reading from the transports list */static void nfs_volume_list_stop(struct seq_file *p, void *v){ spin_unlock(&nfs_client_lock);}/* * display a header line followed by a load of call lines */static int nfs_volume_list_show(struct seq_file *m, void *v){ struct nfs_server *server; struct nfs_client *clp; char dev[8], fsid[17]; /* display header on line 1 */ if (v == &nfs_volume_list) { seq_puts(m, "NV SERVER PORT DEV FSID\n"); return 0; } /* display one transport per line on subsequent lines */ server = list_entry(v, struct nfs_server, master_link); clp = server->nfs_client; snprintf(dev, 8, "%u:%u", MAJOR(server->s_dev), MINOR(server->s_dev)); snprintf(fsid, 17, "%llx:%llx", (unsigned long long) server->fsid.major, (unsigned long long) server->fsid.minor); seq_printf(m, "v%d %02x%02x%02x%02x %4hx %-7s %-17s\n", clp->cl_nfsversion, NIPQUAD(clp->cl_addr.sin_addr), ntohs(clp->cl_addr.sin_port), dev, fsid); return 0;}/* * initialise the /proc/fs/nfsfs/ directory */int __init nfs_fs_proc_init(void){ struct proc_dir_entry *p; proc_fs_nfs = proc_mkdir("nfsfs", proc_root_fs); if (!proc_fs_nfs) goto error_0; proc_fs_nfs->owner = THIS_MODULE; /* a file of servers with which we're dealing */ p = create_proc_entry("servers", S_IFREG|S_IRUGO, proc_fs_nfs); if (!p) goto error_1; p->proc_fops = &nfs_server_list_fops; p->owner = THIS_MODULE; /* a file of volumes that we have mounted */ p = create_proc_entry("volumes", S_IFREG|S_IRUGO, proc_fs_nfs); if (!p) goto error_2; p->proc_fops = &nfs_volume_list_fops; p->owner = THIS_MODULE; return 0;error_2: remove_proc_entry("servers", proc_fs_nfs);error_1: remove_proc_entry("nfsfs", proc_root_fs);error_0: return -ENOMEM;}/* * clean up the /proc/fs/nfsfs/ directory */void nfs_fs_proc_exit(void){ remove_proc_entry("volumes", proc_fs_nfs); remove_proc_entry("servers", proc_fs_nfs); remove_proc_entry("nfsfs", proc_root_fs);}#endif /* CONFIG_PROC_FS */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -