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

📄 nfs4proc.c

📁 Linux Kernel 2.6.9 for OMAP1710
💻 C
📖 第 1 页 / 共 5 页
字号:
static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr){	struct nfs4_exception exception = { };	int err;	do {		err = nfs4_handle_exception(server,				_nfs4_proc_getattr(server, fhandle, fattr),				&exception);	} while (exception.retry);	return err;}/*  * The file is not closed if it is opened due to the a request to change * the size of the file. The open call will not be needed once the * VFS layer lookup-intents are implemented. * * Close is called when the inode is destroyed. * If we haven't opened the file for O_WRONLY, we * need to in the size_change case to obtain a stateid. * * Got race? * Because OPEN is always done by name in nfsv4, it is * possible that we opened a different file by the same * name.  We can recognize this race condition, but we * can't do anything about it besides returning an error. * * This will be fixed with VFS changes (lookup-intent). */static intnfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,		  struct iattr *sattr){	struct inode *		inode = dentry->d_inode;	int			size_change = sattr->ia_valid & ATTR_SIZE;	struct nfs4_state	*state = NULL;	int need_iput = 0;	int status;	fattr->valid = 0;		if (size_change) {		struct rpc_cred *cred = rpcauth_lookupcred(NFS_SERVER(inode)->client->cl_auth, 0);		state = nfs4_find_state(inode, cred, FMODE_WRITE);		if (state == NULL) {			state = nfs4_open_delegated(dentry->d_inode,					FMODE_WRITE, cred);			if (IS_ERR(state))				state = nfs4_do_open(dentry->d_parent->d_inode,						&dentry->d_name, FMODE_WRITE,						NULL, cred);			need_iput = 1;		}		put_rpccred(cred);		if (IS_ERR(state))			return PTR_ERR(state);		if (state->inode != inode) {			printk(KERN_WARNING "nfs: raced in setattr (%p != %p), returning -EIO\n", inode, state->inode);			status = -EIO;			goto out;		}	}	status = nfs4_do_setattr(NFS_SERVER(inode), fattr,			NFS_FH(inode), sattr, state);out:	if (state) {		inode = state->inode;		nfs4_close_state(state, FMODE_WRITE);		if (need_iput)			iput(inode);	}	return status;}static int _nfs4_proc_lookup(struct inode *dir, struct qstr *name,		struct nfs_fh *fhandle, struct nfs_fattr *fattr){	int		       status;	struct nfs_server *server = NFS_SERVER(dir);	struct nfs4_lookup_arg args = {		.bitmask = server->attr_bitmask,		.dir_fh = NFS_FH(dir),		.name = name,	};	struct nfs4_lookup_res res = {		.server = server,		.fattr = fattr,		.fh = fhandle,	};	struct rpc_message msg = {		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LOOKUP],		.rpc_argp = &args,		.rpc_resp = &res,	};		fattr->valid = 0;		dprintk("NFS call  lookup %s\n", name->name);	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);	dprintk("NFS reply lookup: %d\n", status);	return status;}static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr){	struct nfs4_exception exception = { };	int err;	do {		err = nfs4_handle_exception(NFS_SERVER(dir),				_nfs4_proc_lookup(dir, name, fhandle, fattr),				&exception);	} while (exception.retry);	return err;}static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry){	struct nfs4_accessargs args = {		.fh = NFS_FH(inode),	};	struct nfs4_accessres res = { 0 };	struct rpc_message msg = {		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],		.rpc_argp = &args,		.rpc_resp = &res,		.rpc_cred = entry->cred,	};	int mode = entry->mask;	int status;	/*	 * Determine which access bits we want to ask for...	 */	if (mode & MAY_READ)		args.access |= NFS4_ACCESS_READ;	if (S_ISDIR(inode->i_mode)) {		if (mode & MAY_WRITE)			args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE;		if (mode & MAY_EXEC)			args.access |= NFS4_ACCESS_LOOKUP;	} else {		if (mode & MAY_WRITE)			args.access |= NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND;		if (mode & MAY_EXEC)			args.access |= NFS4_ACCESS_EXECUTE;	}	status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);	if (!status) {		entry->mask = 0;		if (res.access & NFS4_ACCESS_READ)			entry->mask |= MAY_READ;		if (res.access & (NFS4_ACCESS_MODIFY | NFS4_ACCESS_EXTEND | NFS4_ACCESS_DELETE))			entry->mask |= MAY_WRITE;		if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))			entry->mask |= MAY_EXEC;	}	return status;}static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry){	struct nfs4_exception exception = { };	int err;	do {		err = nfs4_handle_exception(NFS_SERVER(inode),				_nfs4_proc_access(inode, entry),				&exception);	} while (exception.retry);	return err;}/* * TODO: For the time being, we don't try to get any attributes * along with any of the zero-copy operations READ, READDIR, * READLINK, WRITE. * * In the case of the first three, we want to put the GETATTR * after the read-type operation -- this is because it is hard * to predict the length of a GETATTR response in v4, and thus * align the READ data correctly.  This means that the GETATTR * may end up partially falling into the page cache, and we should * shift it into the 'tail' of the xdr_buf before processing. * To do this efficiently, we need to know the total length * of data received, which doesn't seem to be available outside * of the RPC layer. * * In the case of WRITE, we also want to put the GETATTR after * the operation -- in this case because we want to make sure * we get the post-operation mtime and size.  This means that * we can't use xdr_encode_pages() as written: we need a variant * of it which would leave room in the 'tail' iovec. * * Both of these changes to the XDR layer would in fact be quite * minor, but I decided to leave them for a subsequent patch. */static int _nfs4_proc_readlink(struct inode *inode, struct page *page,		unsigned int pgbase, unsigned int pglen){	struct nfs4_readlink args = {		.fh       = NFS_FH(inode),		.pgbase	  = pgbase,		.pglen    = pglen,		.pages    = &page,	};	struct rpc_message msg = {		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READLINK],		.rpc_argp = &args,		.rpc_resp = NULL,	};	return rpc_call_sync(NFS_CLIENT(inode), &msg, 0);}static int nfs4_proc_readlink(struct inode *inode, struct page *page,		unsigned int pgbase, unsigned int pglen){	struct nfs4_exception exception = { };	int err;	do {		err = nfs4_handle_exception(NFS_SERVER(inode),				_nfs4_proc_readlink(inode, page, pgbase, pglen),				&exception);	} while (exception.retry);	return err;}static int _nfs4_proc_read(struct nfs_read_data *rdata){	int flags = rdata->flags;	struct inode *inode = rdata->inode;	struct nfs_fattr *fattr = rdata->res.fattr;	struct nfs_server *server = NFS_SERVER(inode);	struct rpc_message msg = {		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_READ],		.rpc_argp	= &rdata->args,		.rpc_resp	= &rdata->res,		.rpc_cred	= rdata->cred,	};	unsigned long timestamp = jiffies;	int status;	dprintk("NFS call  read %d @ %Ld\n", rdata->args.count,			(long long) rdata->args.offset);	fattr->valid = 0;	status = rpc_call_sync(server->client, &msg, flags);	if (!status)		renew_lease(server, timestamp);	dprintk("NFS reply read: %d\n", status);	return status;}static int nfs4_proc_read(struct nfs_read_data *rdata){	struct nfs4_exception exception = { };	int err;	do {		err = nfs4_handle_exception(NFS_SERVER(rdata->inode),				_nfs4_proc_read(rdata),				&exception);	} while (exception.retry);	return err;}static int _nfs4_proc_write(struct nfs_write_data *wdata){	int rpcflags = wdata->flags;	struct inode *inode = wdata->inode;	struct nfs_fattr *fattr = wdata->res.fattr;	struct nfs_server *server = NFS_SERVER(inode);	struct rpc_message msg = {		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_WRITE],		.rpc_argp	= &wdata->args,		.rpc_resp	= &wdata->res,		.rpc_cred	= wdata->cred,	};	int status;	dprintk("NFS call  write %d @ %Ld\n", wdata->args.count,			(long long) wdata->args.offset);	fattr->valid = 0;	status = rpc_call_sync(server->client, &msg, rpcflags);	dprintk("NFS reply write: %d\n", status);	return status;}static int nfs4_proc_write(struct nfs_write_data *wdata){	struct nfs4_exception exception = { };	int err;	do {		err = nfs4_handle_exception(NFS_SERVER(wdata->inode),				_nfs4_proc_write(wdata),				&exception);	} while (exception.retry);	return err;}static int _nfs4_proc_commit(struct nfs_write_data *cdata){	struct inode *inode = cdata->inode;	struct nfs_fattr *fattr = cdata->res.fattr;	struct nfs_server *server = NFS_SERVER(inode);	struct rpc_message msg = {		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_COMMIT],		.rpc_argp	= &cdata->args,		.rpc_resp	= &cdata->res,		.rpc_cred	= cdata->cred,	};	int status;	dprintk("NFS call  commit %d @ %Ld\n", cdata->args.count,			(long long) cdata->args.offset);	fattr->valid = 0;	status = rpc_call_sync(server->client, &msg, 0);	dprintk("NFS reply commit: %d\n", status);	return status;}static int nfs4_proc_commit(struct nfs_write_data *cdata){	struct nfs4_exception exception = { };	int err;	do {		err = nfs4_handle_exception(NFS_SERVER(cdata->inode),				_nfs4_proc_commit(cdata),				&exception);	} while (exception.retry);	return err;}/* * Got race? * We will need to arrange for the VFS layer to provide an atomic open. * Until then, this create/open method is prone to inefficiency and race * conditions due to the lookup, create, and open VFS calls from sys_open() * placed on the wire. * * Given the above sorry state of affairs, I'm simply sending an OPEN. * The file will be opened again in the subsequent VFS open call * (nfs4_proc_file_open). * * The open for read will just hang around to be used by any process that * opens the file O_RDONLY. This will all be resolved with the VFS changes. */static struct inode *nfs4_proc_create(struct inode *dir, struct qstr *name, struct iattr *sattr,                 int flags){	struct inode *inode;	struct nfs4_state *state = NULL;	struct rpc_cred *cred;	cred = rpcauth_lookupcred(NFS_SERVER(dir)->client->cl_auth, 0);	state = nfs4_do_open(dir, name, flags, sattr, cred);	put_rpccred(cred);	if (!IS_ERR(state)) {		inode = state->inode;		if (flags & O_EXCL) {			struct nfs_fattr fattr;			int status;			status = nfs4_do_setattr(NFS_SERVER(dir), &fattr,			                     NFS_FH(inode), sattr, state);			if (status != 0) {				nfs4_close_state(state, flags);				iput(inode);				inode = ERR_PTR(status);			}		}	} else		inode = (struct inode *)state;	return inode;}static int _nfs4_proc_remove(struct inode *dir, struct qstr *name){	struct nfs4_remove_arg args = {		.fh = NFS_FH(dir),		.name = name,	};	struct nfs4_change_info	res;	struct rpc_message msg = {		.rpc_proc	= &nfs4_procedures[NFSPROC4_CLNT_REMOVE],		.rpc_argp	= &args,		.rpc_resp	= &res,	};	int			status;	status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);	if (status == 0)		update_changeattr(dir, &res);	return status;}static int nfs4_proc_remove(struct inode *dir, struct qstr *name){	struct nfs4_exception exception = { };	int err;	do {		err = nfs4_handle_exception(NFS_SERVER(dir),				_nfs4_proc_remove(dir, name),				&exception);	} while (exception.retry);	return err;}struct unlink_desc {	struct nfs4_remove_arg	args;	struct nfs4_change_info	res;};static int nfs4_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir,		struct qstr *name){	struct unlink_desc *up;	up = (struct unlink_desc *) kmalloc(sizeof(*up), GFP_KERNEL);	if (!up)		return -ENOMEM;		up->args.fh = NFS_FH(dir->d_inode);	up->args.name = name;		msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];	msg->rpc_argp = &up->args;	msg->rpc_resp = &up->res;	return 0;}static int nfs4_proc_unlink_done(struct dentry *dir, struct rpc_task *task){	struct rpc_message *msg = &task->tk_msg;	struct unlink_desc *up;		if (msg->rpc_resp != NULL) {		up = container_of(msg->rpc_resp, struct unlink_desc, res);		update_changeattr(dir->d_inode, &up->res);		kfree(up);		msg->rpc_resp = NULL;		msg->rpc_argp = NULL;	}	return 0;}static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,		struct inode *new_dir, struct qstr *new_name){	struct nfs4_rename_arg arg = {		.old_dir = NFS_FH(old_dir),		.new_dir = NFS_FH(new_dir),		.old_name = old_name,		.new_name = new_name,	};	struct nfs4_rename_res res = { };	struct rpc_message msg = {		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],		.rpc_argp = &arg,		.rpc_resp = &res,	};	int			status;		status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);	if (!status) {		update_changeattr(old_dir, &res.old_cinfo);		update_changeattr(new_dir, &res.new_cinfo);	}	return status;}static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,		struct inode *new_dir, struct qstr *new_name){	struct nfs4_exception exception = { };	int err;	do {		err = nfs4_handle_exception(NFS_SERVER(old_dir),				_nfs4_proc_rename(old_dir, old_name,					new_dir, new_name),				&exception);	} while (exception.retry);	return err;}

⌨️ 快捷键说明

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