⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proc.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  linux/fs/nfs/proc.c * *  Copyright (C) 1992, 1993, 1994  Rick Sladkey * *  OS-independent nfs remote procedure call functions * *  Tuned by Alan Cox <A.Cox@swansea.ac.uk> for >3K buffers *  so at last we can have decent(ish) throughput off a  *  Sun server. * *  Coding optimized and cleaned up by Florian La Roche. *  Note: Error returns are optimized for NFS_OK, which isn't translated via *  nfs_stat_to_errno(), but happens to be already the right return code. * *  Also, the code currently doesn't check the size of the packet, when *  it decodes the packet. * *  Feel free to fix it and mail me the diffs if it worries you. * *  Completely rewritten to support the new RPC call interface; *  rewrote and moved the entire XDR stuff to xdr.c *  --Olaf Kirch June 1996 * *  The code below initializes all auto variables explicitly, otherwise *  it will fail to work as a module (gcc generates a memset call for an *  incomplete struct). */#include <linux/types.h>#include <linux/param.h>#include <linux/slab.h>#include <linux/time.h>#include <linux/mm.h>#include <linux/utsname.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/in.h>#include <linux/pagemap.h>#include <linux/sunrpc/clnt.h>#include <linux/nfs.h>#include <linux/nfs2.h>#include <linux/nfs_fs.h>#include <linux/nfs_page.h>#include <linux/lockd/bind.h>#include "internal.h"#define NFSDBG_FACILITY		NFSDBG_PROC/* * Bare-bones access to getattr: this is for nfs_read_super. */static intnfs_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,		  struct nfs_fsinfo *info){	struct nfs_fattr *fattr = info->fattr;	struct nfs2_fsstat fsinfo;	struct rpc_message msg = {		.rpc_proc	= &nfs_procedures[NFSPROC_GETATTR],		.rpc_argp	= fhandle,		.rpc_resp	= fattr,	};	int status;	dprintk("%s: call getattr\n", __FUNCTION__);	nfs_fattr_init(fattr);	status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);	dprintk("%s: reply getattr: %d\n", __FUNCTION__, status);	if (status)		return status;	dprintk("%s: call statfs\n", __FUNCTION__);	msg.rpc_proc = &nfs_procedures[NFSPROC_STATFS];	msg.rpc_resp = &fsinfo;	status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0);	dprintk("%s: reply statfs: %d\n", __FUNCTION__, status);	if (status)		return status;	info->rtmax  = NFS_MAXDATA;	info->rtpref = fsinfo.tsize;	info->rtmult = fsinfo.bsize;	info->wtmax  = NFS_MAXDATA;	info->wtpref = fsinfo.tsize;	info->wtmult = fsinfo.bsize;	info->dtpref = fsinfo.tsize;	info->maxfilesize = 0x7FFFFFFF;	info->lease_time = 0;	return 0;}/* * One function for each procedure in the NFS protocol. */static intnfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,		struct nfs_fattr *fattr){	struct rpc_message msg = {		.rpc_proc	= &nfs_procedures[NFSPROC_GETATTR],		.rpc_argp	= fhandle,		.rpc_resp	= fattr,	};	int	status;	dprintk("NFS call  getattr\n");	nfs_fattr_init(fattr);	status = rpc_call_sync(server->client, &msg, 0);	dprintk("NFS reply getattr: %d\n", status);	return status;}static intnfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,		 struct iattr *sattr){	struct inode *inode = dentry->d_inode;	struct nfs_sattrargs	arg = { 		.fh	= NFS_FH(inode),		.sattr	= sattr	};	struct rpc_message msg = {		.rpc_proc	= &nfs_procedures[NFSPROC_SETATTR],		.rpc_argp	= &arg,		.rpc_resp	= fattr,	};	int	status;	/* Mask out the non-modebit related stuff from attr->ia_mode */	sattr->ia_mode &= S_IALLUGO;	dprintk("NFS call  setattr\n");	nfs_fattr_init(fattr);	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);	if (status == 0)		nfs_setattr_update_inode(inode, sattr);	dprintk("NFS reply setattr: %d\n", status);	return status;}static intnfs_proc_lookup(struct inode *dir, struct qstr *name,		struct nfs_fh *fhandle, struct nfs_fattr *fattr){	struct nfs_diropargs	arg = {		.fh		= NFS_FH(dir),		.name		= name->name,		.len		= name->len	};	struct nfs_diropok	res = {		.fh		= fhandle,		.fattr		= fattr	};	struct rpc_message msg = {		.rpc_proc	= &nfs_procedures[NFSPROC_LOOKUP],		.rpc_argp	= &arg,		.rpc_resp	= &res,	};	int			status;	dprintk("NFS call  lookup %s\n", name->name);	nfs_fattr_init(fattr);	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);	dprintk("NFS reply lookup: %d\n", status);	return status;}static int nfs_proc_readlink(struct inode *inode, struct page *page,		unsigned int pgbase, unsigned int pglen){	struct nfs_readlinkargs	args = {		.fh		= NFS_FH(inode),		.pgbase		= pgbase,		.pglen		= pglen,		.pages		= &page	};	struct rpc_message msg = {		.rpc_proc	= &nfs_procedures[NFSPROC_READLINK],		.rpc_argp	= &args,	};	int			status;	dprintk("NFS call  readlink\n");	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);	dprintk("NFS reply readlink: %d\n", status);	return status;}static intnfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,		int flags, struct nameidata *nd){	struct nfs_fh		fhandle;	struct nfs_fattr	fattr;	struct nfs_createargs	arg = {		.fh		= NFS_FH(dir),		.name		= dentry->d_name.name,		.len		= dentry->d_name.len,		.sattr		= sattr	};	struct nfs_diropok	res = {		.fh		= &fhandle,		.fattr		= &fattr	};	struct rpc_message msg = {		.rpc_proc	= &nfs_procedures[NFSPROC_CREATE],		.rpc_argp	= &arg,		.rpc_resp	= &res,	};	int			status;	nfs_fattr_init(&fattr);	dprintk("NFS call  create %s\n", dentry->d_name.name);	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);	nfs_mark_for_revalidate(dir);	if (status == 0)		status = nfs_instantiate(dentry, &fhandle, &fattr);	dprintk("NFS reply create: %d\n", status);	return status;}/* * In NFSv2, mknod is grafted onto the create call. */static intnfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,	       dev_t rdev){	struct nfs_fh fhandle;	struct nfs_fattr fattr;	struct nfs_createargs	arg = {		.fh		= NFS_FH(dir),		.name		= dentry->d_name.name,		.len		= dentry->d_name.len,		.sattr		= sattr	};	struct nfs_diropok	res = {		.fh		= &fhandle,		.fattr		= &fattr	};	struct rpc_message msg = {		.rpc_proc	= &nfs_procedures[NFSPROC_CREATE],		.rpc_argp	= &arg,		.rpc_resp	= &res,	};	int status, mode;	dprintk("NFS call  mknod %s\n", dentry->d_name.name);	mode = sattr->ia_mode;	if (S_ISFIFO(mode)) {		sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR;		sattr->ia_valid &= ~ATTR_SIZE;	} else if (S_ISCHR(mode) || S_ISBLK(mode)) {		sattr->ia_valid |= ATTR_SIZE;		sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */	}	nfs_fattr_init(&fattr);	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);	nfs_mark_for_revalidate(dir);	if (status == -EINVAL && S_ISFIFO(mode)) {		sattr->ia_mode = mode;		nfs_fattr_init(&fattr);		status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);	}	if (status == 0)		status = nfs_instantiate(dentry, &fhandle, &fattr);	dprintk("NFS reply mknod: %d\n", status);	return status;}  static intnfs_proc_remove(struct inode *dir, struct qstr *name){	struct nfs_removeargs arg = {		.fh = NFS_FH(dir),		.name.len = name->len,		.name.name = name->name,	};	struct rpc_message msg = { 		.rpc_proc = &nfs_procedures[NFSPROC_REMOVE],		.rpc_argp = &arg,	};	int			status;	dprintk("NFS call  remove %s\n", name->name);	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);	nfs_mark_for_revalidate(dir);	dprintk("NFS reply remove: %d\n", status);	return status;}static voidnfs_proc_unlink_setup(struct rpc_message *msg, struct inode *dir){	msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];}static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir){	nfs_mark_for_revalidate(dir);	return 1;}static intnfs_proc_rename(struct inode *old_dir, struct qstr *old_name,		struct inode *new_dir, struct qstr *new_name){	struct nfs_renameargs	arg = {		.fromfh		= NFS_FH(old_dir),		.fromname	= old_name->name,		.fromlen	= old_name->len,		.tofh		= NFS_FH(new_dir),		.toname		= new_name->name,		.tolen		= new_name->len	};	struct rpc_message msg = {		.rpc_proc	= &nfs_procedures[NFSPROC_RENAME],		.rpc_argp	= &arg,	};	int			status;	dprintk("NFS call  rename %s -> %s\n", old_name->name, new_name->name);	status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -