1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * linux/fs/nfs/nfs3proc.c 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Client-side NFSv3 procedures stubs. 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * Copyright (C) 1997, Olaf Kirch 81da177e4SLinus Torvalds */ 91da177e4SLinus Torvalds 101da177e4SLinus Torvalds #include <linux/mm.h> 111da177e4SLinus Torvalds #include <linux/errno.h> 121da177e4SLinus Torvalds #include <linux/string.h> 131da177e4SLinus Torvalds #include <linux/sunrpc/clnt.h> 145a0e3ad6STejun Heo #include <linux/slab.h> 151da177e4SLinus Torvalds #include <linux/nfs.h> 161da177e4SLinus Torvalds #include <linux/nfs3.h> 171da177e4SLinus Torvalds #include <linux/nfs_fs.h> 181da177e4SLinus Torvalds #include <linux/nfs_page.h> 191da177e4SLinus Torvalds #include <linux/lockd/bind.h> 20b7fa0554SAndreas Gruenbacher #include <linux/nfs_mount.h> 21d310310cSJeff Layton #include <linux/freezer.h> 220a6be655STejun Heo #include <linux/xattr.h> 231da177e4SLinus Torvalds 24006ea73eSChuck Lever #include "iostat.h" 25f7b422b1SDavid Howells #include "internal.h" 2600a36a10SAnna Schumaker #include "nfs3_fs.h" 27006ea73eSChuck Lever 281da177e4SLinus Torvalds #define NFSDBG_FACILITY NFSDBG_PROC 291da177e4SLinus Torvalds 30eb96d5c9SAndy Adamson /* A wrapper to handle the EJUKEBOX error messages */ 311da177e4SLinus Torvalds static int 321da177e4SLinus Torvalds nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags) 331da177e4SLinus Torvalds { 341da177e4SLinus Torvalds int res; 351da177e4SLinus Torvalds do { 361da177e4SLinus Torvalds res = rpc_call_sync(clnt, msg, flags); 37eb96d5c9SAndy Adamson if (res != -EJUKEBOX) 381da177e4SLinus Torvalds break; 39416ad3c9SColin Cross freezable_schedule_timeout_killable_unsafe(NFS_JUKEBOX_RETRY_TIME); 401da177e4SLinus Torvalds res = -ERESTARTSYS; 41150030b7SMatthew Wilcox } while (!fatal_signal_pending(current)); 421da177e4SLinus Torvalds return res; 431da177e4SLinus Torvalds } 441da177e4SLinus Torvalds 45dead28daSChuck Lever #define rpc_call_sync(clnt, msg, flags) nfs3_rpc_wrapper(clnt, msg, flags) 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds static int 48006ea73eSChuck Lever nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode) 491da177e4SLinus Torvalds { 50eb96d5c9SAndy Adamson if (task->tk_status != -EJUKEBOX) 511da177e4SLinus Torvalds return 0; 52b68d69b8SJeff Layton if (task->tk_status == -EJUKEBOX) 53006ea73eSChuck Lever nfs_inc_stats(inode, NFSIOS_DELAY); 541da177e4SLinus Torvalds task->tk_status = 0; 551da177e4SLinus Torvalds rpc_restart_call(task); 561da177e4SLinus Torvalds rpc_delay(task, NFS_JUKEBOX_RETRY_TIME); 571da177e4SLinus Torvalds return 1; 581da177e4SLinus Torvalds } 591da177e4SLinus Torvalds 6003c21733SJ. Bruce Fields static int 6103c21733SJ. Bruce Fields do_proc_get_root(struct rpc_clnt *client, struct nfs_fh *fhandle, 6203c21733SJ. Bruce Fields struct nfs_fsinfo *info) 6303c21733SJ. Bruce Fields { 64dead28daSChuck Lever struct rpc_message msg = { 65dead28daSChuck Lever .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO], 66dead28daSChuck Lever .rpc_argp = fhandle, 67dead28daSChuck Lever .rpc_resp = info, 68dead28daSChuck Lever }; 6903c21733SJ. Bruce Fields int status; 7003c21733SJ. Bruce Fields 713110ff80SHarvey Harrison dprintk("%s: call fsinfo\n", __func__); 7203c21733SJ. Bruce Fields nfs_fattr_init(info->fattr); 73dead28daSChuck Lever status = rpc_call_sync(client, &msg, 0); 743110ff80SHarvey Harrison dprintk("%s: reply fsinfo: %d\n", __func__, status); 7508660043STrond Myklebust if (status == 0 && !(info->fattr->valid & NFS_ATTR_FATTR)) { 76dead28daSChuck Lever msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR]; 77dead28daSChuck Lever msg.rpc_resp = info->fattr; 78dead28daSChuck Lever status = rpc_call_sync(client, &msg, 0); 793110ff80SHarvey Harrison dprintk("%s: reply getattr: %d\n", __func__, status); 8003c21733SJ. Bruce Fields } 8103c21733SJ. Bruce Fields return status; 8203c21733SJ. Bruce Fields } 8303c21733SJ. Bruce Fields 841da177e4SLinus Torvalds /* 8554ceac45SDavid Howells * Bare-bones access to getattr: this is for nfs_get_root/nfs_get_sb 861da177e4SLinus Torvalds */ 871da177e4SLinus Torvalds static int 881da177e4SLinus Torvalds nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, 891da177e4SLinus Torvalds struct nfs_fsinfo *info) 901da177e4SLinus Torvalds { 911da177e4SLinus Torvalds int status; 921da177e4SLinus Torvalds 9303c21733SJ. Bruce Fields status = do_proc_get_root(server->client, fhandle, info); 945006a76cSDavid Howells if (status && server->nfs_client->cl_rpcclient != server->client) 955006a76cSDavid Howells status = do_proc_get_root(server->nfs_client->cl_rpcclient, fhandle, info); 961da177e4SLinus Torvalds return status; 971da177e4SLinus Torvalds } 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds /* 1001da177e4SLinus Torvalds * One function for each procedure in the NFS protocol. 1011da177e4SLinus Torvalds */ 1021da177e4SLinus Torvalds static int 1031da177e4SLinus Torvalds nfs3_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, 104a841b54dSTrond Myklebust struct nfs_fattr *fattr, struct nfs4_label *label, 105a841b54dSTrond Myklebust struct inode *inode) 1061da177e4SLinus Torvalds { 107dead28daSChuck Lever struct rpc_message msg = { 108dead28daSChuck Lever .rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR], 109dead28daSChuck Lever .rpc_argp = fhandle, 110dead28daSChuck Lever .rpc_resp = fattr, 111dead28daSChuck Lever }; 1121da177e4SLinus Torvalds int status; 113c74dfe97STrond Myklebust unsigned short task_flags = 0; 114c74dfe97STrond Myklebust 115c74dfe97STrond Myklebust /* Is this is an attribute revalidation, subject to softreval? */ 116c74dfe97STrond Myklebust if (inode && (server->flags & NFS_MOUNT_SOFTREVAL)) 117c74dfe97STrond Myklebust task_flags |= RPC_TASK_TIMEOUT; 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds dprintk("NFS call getattr\n"); 1200e574af1STrond Myklebust nfs_fattr_init(fattr); 121c74dfe97STrond Myklebust status = rpc_call_sync(server->client, &msg, task_flags); 1221da177e4SLinus Torvalds dprintk("NFS reply getattr: %d\n", status); 1231da177e4SLinus Torvalds return status; 1241da177e4SLinus Torvalds } 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds static int 1271da177e4SLinus Torvalds nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, 1281da177e4SLinus Torvalds struct iattr *sattr) 1291da177e4SLinus Torvalds { 1302b0143b5SDavid Howells struct inode *inode = d_inode(dentry); 1311da177e4SLinus Torvalds struct nfs3_sattrargs arg = { 1321da177e4SLinus Torvalds .fh = NFS_FH(inode), 1331da177e4SLinus Torvalds .sattr = sattr, 1341da177e4SLinus Torvalds }; 135dead28daSChuck Lever struct rpc_message msg = { 136dead28daSChuck Lever .rpc_proc = &nfs3_procedures[NFS3PROC_SETATTR], 137dead28daSChuck Lever .rpc_argp = &arg, 138dead28daSChuck Lever .rpc_resp = fattr, 139dead28daSChuck Lever }; 1401da177e4SLinus Torvalds int status; 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds dprintk("NFS call setattr\n"); 143659bfcd6STrond Myklebust if (sattr->ia_valid & ATTR_FILE) 144659bfcd6STrond Myklebust msg.rpc_cred = nfs_file_cred(sattr->ia_file); 1450e574af1STrond Myklebust nfs_fattr_init(fattr); 146dead28daSChuck Lever status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); 147dbc898aeSchendt if (status == 0) { 148fe1e8dbeSSu Yanjun nfs_setattr_update_inode(inode, sattr, fattr); 149dbc898aeSchendt if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_ACL) 150dbc898aeSchendt nfs_zap_acl_cache(inode); 151dbc898aeSchendt } 1521da177e4SLinus Torvalds dprintk("NFS reply setattr: %d\n", status); 1531da177e4SLinus Torvalds return status; 1541da177e4SLinus Torvalds } 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds static int 1575f447cb8STrond Myklebust __nfs3_proc_lookup(struct inode *dir, const char *name, size_t len, 1581775fd3eSDavid Quigley struct nfs_fh *fhandle, struct nfs_fattr *fattr, 1595f447cb8STrond Myklebust unsigned short task_flags) 1601da177e4SLinus Torvalds { 1611da177e4SLinus Torvalds struct nfs3_diropargs arg = { 1621da177e4SLinus Torvalds .fh = NFS_FH(dir), 1635f447cb8STrond Myklebust .name = name, 1645f447cb8STrond Myklebust .len = len 1651da177e4SLinus Torvalds }; 1661da177e4SLinus Torvalds struct nfs3_diropres res = { 1671da177e4SLinus Torvalds .fh = fhandle, 1681da177e4SLinus Torvalds .fattr = fattr 1691da177e4SLinus Torvalds }; 170dead28daSChuck Lever struct rpc_message msg = { 171dead28daSChuck Lever .rpc_proc = &nfs3_procedures[NFS3PROC_LOOKUP], 172dead28daSChuck Lever .rpc_argp = &arg, 173dead28daSChuck Lever .rpc_resp = &res, 174dead28daSChuck Lever }; 1751da177e4SLinus Torvalds int status; 176f7b37b8bSTrond Myklebust 177e1fb4d05STrond Myklebust res.dir_attr = nfs_alloc_fattr(); 178e1fb4d05STrond Myklebust if (res.dir_attr == NULL) 179e1fb4d05STrond Myklebust return -ENOMEM; 180e1fb4d05STrond Myklebust 1810e574af1STrond Myklebust nfs_fattr_init(fattr); 182f7b37b8bSTrond Myklebust status = rpc_call_sync(NFS_CLIENT(dir), &msg, task_flags); 183e1fb4d05STrond Myklebust nfs_refresh_inode(dir, res.dir_attr); 184dead28daSChuck Lever if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) { 185dead28daSChuck Lever msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR]; 186dead28daSChuck Lever msg.rpc_argp = fhandle; 187dead28daSChuck Lever msg.rpc_resp = fattr; 188f7b37b8bSTrond Myklebust status = rpc_call_sync(NFS_CLIENT(dir), &msg, task_flags); 189dead28daSChuck Lever } 190e1fb4d05STrond Myklebust nfs_free_fattr(res.dir_attr); 1911da177e4SLinus Torvalds dprintk("NFS reply lookup: %d\n", status); 1921da177e4SLinus Torvalds return status; 1931da177e4SLinus Torvalds } 1941da177e4SLinus Torvalds 1955f447cb8STrond Myklebust static int 1965f447cb8STrond Myklebust nfs3_proc_lookup(struct inode *dir, struct dentry *dentry, 1975f447cb8STrond Myklebust struct nfs_fh *fhandle, struct nfs_fattr *fattr, 1985f447cb8STrond Myklebust struct nfs4_label *label) 1995f447cb8STrond Myklebust { 2005f447cb8STrond Myklebust unsigned short task_flags = 0; 2015f447cb8STrond Myklebust 2025f447cb8STrond Myklebust /* Is this is an attribute revalidation, subject to softreval? */ 2035f447cb8STrond Myklebust if (nfs_lookup_is_soft_revalidate(dentry)) 2045f447cb8STrond Myklebust task_flags |= RPC_TASK_TIMEOUT; 2055f447cb8STrond Myklebust 2065f447cb8STrond Myklebust dprintk("NFS call lookup %pd2\n", dentry); 2075f447cb8STrond Myklebust return __nfs3_proc_lookup(dir, dentry->d_name.name, 2085f447cb8STrond Myklebust dentry->d_name.len, fhandle, fattr, 2095f447cb8STrond Myklebust task_flags); 2105f447cb8STrond Myklebust } 2115f447cb8STrond Myklebust 2123c5e9a59STrond Myklebust static int nfs3_proc_lookupp(struct inode *inode, struct nfs_fh *fhandle, 2133c5e9a59STrond Myklebust struct nfs_fattr *fattr, struct nfs4_label *label) 2143c5e9a59STrond Myklebust { 2153c5e9a59STrond Myklebust const char dotdot[] = ".."; 2163c5e9a59STrond Myklebust const size_t len = strlen(dotdot); 2173c5e9a59STrond Myklebust unsigned short task_flags = 0; 2183c5e9a59STrond Myklebust 2193c5e9a59STrond Myklebust if (NFS_SERVER(inode)->flags & NFS_MOUNT_SOFTREVAL) 2203c5e9a59STrond Myklebust task_flags |= RPC_TASK_TIMEOUT; 2213c5e9a59STrond Myklebust 2223c5e9a59STrond Myklebust return __nfs3_proc_lookup(inode, dotdot, len, fhandle, fattr, 2233c5e9a59STrond Myklebust task_flags); 2243c5e9a59STrond Myklebust } 2253c5e9a59STrond Myklebust 2261da177e4SLinus Torvalds static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry) 2271da177e4SLinus Torvalds { 2281da177e4SLinus Torvalds struct nfs3_accessargs arg = { 2291da177e4SLinus Torvalds .fh = NFS_FH(inode), 2301750d929SAnna Schumaker .access = entry->mask, 2311da177e4SLinus Torvalds }; 232c407d41aSTrond Myklebust struct nfs3_accessres res; 2331da177e4SLinus Torvalds struct rpc_message msg = { 2341da177e4SLinus Torvalds .rpc_proc = &nfs3_procedures[NFS3PROC_ACCESS], 2351da177e4SLinus Torvalds .rpc_argp = &arg, 2361da177e4SLinus Torvalds .rpc_resp = &res, 237a52458b4SNeilBrown .rpc_cred = entry->cred, 2381da177e4SLinus Torvalds }; 239c407d41aSTrond Myklebust int status = -ENOMEM; 2401da177e4SLinus Torvalds 2411da177e4SLinus Torvalds dprintk("NFS call access\n"); 242c407d41aSTrond Myklebust res.fattr = nfs_alloc_fattr(); 243c407d41aSTrond Myklebust if (res.fattr == NULL) 244c407d41aSTrond Myklebust goto out; 245c407d41aSTrond Myklebust 2461da177e4SLinus Torvalds status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); 247c407d41aSTrond Myklebust nfs_refresh_inode(inode, res.fattr); 248eda3e208STrond Myklebust if (status == 0) 249eda3e208STrond Myklebust nfs_access_set_mask(entry, res.access); 250c407d41aSTrond Myklebust nfs_free_fattr(res.fattr); 251c407d41aSTrond Myklebust out: 2521da177e4SLinus Torvalds dprintk("NFS reply access: %d\n", status); 2531da177e4SLinus Torvalds return status; 2541da177e4SLinus Torvalds } 2551da177e4SLinus Torvalds 2561da177e4SLinus Torvalds static int nfs3_proc_readlink(struct inode *inode, struct page *page, 2571da177e4SLinus Torvalds unsigned int pgbase, unsigned int pglen) 2581da177e4SLinus Torvalds { 2593b14d654STrond Myklebust struct nfs_fattr *fattr; 2601da177e4SLinus Torvalds struct nfs3_readlinkargs args = { 2611da177e4SLinus Torvalds .fh = NFS_FH(inode), 2621da177e4SLinus Torvalds .pgbase = pgbase, 2631da177e4SLinus Torvalds .pglen = pglen, 2641da177e4SLinus Torvalds .pages = &page 2651da177e4SLinus Torvalds }; 266dead28daSChuck Lever struct rpc_message msg = { 267dead28daSChuck Lever .rpc_proc = &nfs3_procedures[NFS3PROC_READLINK], 268dead28daSChuck Lever .rpc_argp = &args, 269dead28daSChuck Lever }; 2703b14d654STrond Myklebust int status = -ENOMEM; 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds dprintk("NFS call readlink\n"); 2733b14d654STrond Myklebust fattr = nfs_alloc_fattr(); 2743b14d654STrond Myklebust if (fattr == NULL) 2753b14d654STrond Myklebust goto out; 2763b14d654STrond Myklebust msg.rpc_resp = fattr; 2773b14d654STrond Myklebust 278dead28daSChuck Lever status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); 2793b14d654STrond Myklebust nfs_refresh_inode(inode, fattr); 2803b14d654STrond Myklebust nfs_free_fattr(fattr); 2813b14d654STrond Myklebust out: 2821da177e4SLinus Torvalds dprintk("NFS reply readlink: %d\n", status); 2831da177e4SLinus Torvalds return status; 2841da177e4SLinus Torvalds } 2851da177e4SLinus Torvalds 2860b4aae7aSTrond Myklebust struct nfs3_createdata { 2870b4aae7aSTrond Myklebust struct rpc_message msg; 2880b4aae7aSTrond Myklebust union { 2890b4aae7aSTrond Myklebust struct nfs3_createargs create; 2900b4aae7aSTrond Myklebust struct nfs3_mkdirargs mkdir; 2910b4aae7aSTrond Myklebust struct nfs3_symlinkargs symlink; 2920b4aae7aSTrond Myklebust struct nfs3_mknodargs mknod; 2930b4aae7aSTrond Myklebust } arg; 2940b4aae7aSTrond Myklebust struct nfs3_diropres res; 2950b4aae7aSTrond Myklebust struct nfs_fh fh; 2960b4aae7aSTrond Myklebust struct nfs_fattr fattr; 2970b4aae7aSTrond Myklebust struct nfs_fattr dir_attr; 2980b4aae7aSTrond Myklebust }; 2990b4aae7aSTrond Myklebust 3000b4aae7aSTrond Myklebust static struct nfs3_createdata *nfs3_alloc_createdata(void) 3010b4aae7aSTrond Myklebust { 3020b4aae7aSTrond Myklebust struct nfs3_createdata *data; 3030b4aae7aSTrond Myklebust 3040b4aae7aSTrond Myklebust data = kzalloc(sizeof(*data), GFP_KERNEL); 3050b4aae7aSTrond Myklebust if (data != NULL) { 3060b4aae7aSTrond Myklebust data->msg.rpc_argp = &data->arg; 3070b4aae7aSTrond Myklebust data->msg.rpc_resp = &data->res; 3080b4aae7aSTrond Myklebust data->res.fh = &data->fh; 3090b4aae7aSTrond Myklebust data->res.fattr = &data->fattr; 3100b4aae7aSTrond Myklebust data->res.dir_attr = &data->dir_attr; 3110b4aae7aSTrond Myklebust nfs_fattr_init(data->res.fattr); 3120b4aae7aSTrond Myklebust nfs_fattr_init(data->res.dir_attr); 3130b4aae7aSTrond Myklebust } 3140b4aae7aSTrond Myklebust return data; 3150b4aae7aSTrond Myklebust } 3160b4aae7aSTrond Myklebust 31717fd6e45SBenjamin Coddington static struct dentry * 31817fd6e45SBenjamin Coddington nfs3_do_create(struct inode *dir, struct dentry *dentry, struct nfs3_createdata *data) 3190b4aae7aSTrond Myklebust { 3200b4aae7aSTrond Myklebust int status; 3210b4aae7aSTrond Myklebust 3220b4aae7aSTrond Myklebust status = rpc_call_sync(NFS_CLIENT(dir), &data->msg, 0); 3230b4aae7aSTrond Myklebust nfs_post_op_update_inode(dir, data->res.dir_attr); 32417fd6e45SBenjamin Coddington if (status != 0) 32517fd6e45SBenjamin Coddington return ERR_PTR(status); 32617fd6e45SBenjamin Coddington 32717fd6e45SBenjamin Coddington return nfs_add_or_obtain(dentry, data->res.fh, data->res.fattr, NULL); 3280b4aae7aSTrond Myklebust } 3290b4aae7aSTrond Myklebust 3300b4aae7aSTrond Myklebust static void nfs3_free_createdata(struct nfs3_createdata *data) 3310b4aae7aSTrond Myklebust { 3320b4aae7aSTrond Myklebust kfree(data); 3330b4aae7aSTrond Myklebust } 3340b4aae7aSTrond Myklebust 3351da177e4SLinus Torvalds /* 3361da177e4SLinus Torvalds * Create a regular file. 3371da177e4SLinus Torvalds */ 3381da177e4SLinus Torvalds static int 3391da177e4SLinus Torvalds nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, 3408867fe58SMiklos Szeredi int flags) 3411da177e4SLinus Torvalds { 342013cdf10SChristoph Hellwig struct posix_acl *default_acl, *acl; 3430b4aae7aSTrond Myklebust struct nfs3_createdata *data; 34417fd6e45SBenjamin Coddington struct dentry *d_alias; 3450b4aae7aSTrond Myklebust int status = -ENOMEM; 3461da177e4SLinus Torvalds 3476de1472fSAl Viro dprintk("NFS call create %pd\n", dentry); 3480b4aae7aSTrond Myklebust 3490b4aae7aSTrond Myklebust data = nfs3_alloc_createdata(); 3500b4aae7aSTrond Myklebust if (data == NULL) 3510b4aae7aSTrond Myklebust goto out; 3520b4aae7aSTrond Myklebust 3530b4aae7aSTrond Myklebust data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_CREATE]; 3540b4aae7aSTrond Myklebust data->arg.create.fh = NFS_FH(dir); 3550b4aae7aSTrond Myklebust data->arg.create.name = dentry->d_name.name; 3560b4aae7aSTrond Myklebust data->arg.create.len = dentry->d_name.len; 3570b4aae7aSTrond Myklebust data->arg.create.sattr = sattr; 3580b4aae7aSTrond Myklebust 3590b4aae7aSTrond Myklebust data->arg.create.createmode = NFS3_CREATE_UNCHECKED; 3601da177e4SLinus Torvalds if (flags & O_EXCL) { 3610b4aae7aSTrond Myklebust data->arg.create.createmode = NFS3_CREATE_EXCLUSIVE; 362a9943d11STrond Myklebust data->arg.create.verifier[0] = cpu_to_be32(jiffies); 363a9943d11STrond Myklebust data->arg.create.verifier[1] = cpu_to_be32(current->pid); 3641da177e4SLinus Torvalds } 3651da177e4SLinus Torvalds 366013cdf10SChristoph Hellwig status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl); 367013cdf10SChristoph Hellwig if (status) 368013cdf10SChristoph Hellwig goto out; 369055ffbeaSAndreas Gruenbacher 3700b4aae7aSTrond Myklebust for (;;) { 37117fd6e45SBenjamin Coddington d_alias = nfs3_do_create(dir, dentry, data); 37217fd6e45SBenjamin Coddington status = PTR_ERR_OR_ZERO(d_alias); 3731da177e4SLinus Torvalds 3740b4aae7aSTrond Myklebust if (status != -ENOTSUPP) 3750b4aae7aSTrond Myklebust break; 3760b4aae7aSTrond Myklebust /* If the server doesn't support the exclusive creation 3770b4aae7aSTrond Myklebust * semantics, try again with simple 'guarded' mode. */ 3780b4aae7aSTrond Myklebust switch (data->arg.create.createmode) { 3791da177e4SLinus Torvalds case NFS3_CREATE_EXCLUSIVE: 3800b4aae7aSTrond Myklebust data->arg.create.createmode = NFS3_CREATE_GUARDED; 3811da177e4SLinus Torvalds break; 3821da177e4SLinus Torvalds 3831da177e4SLinus Torvalds case NFS3_CREATE_GUARDED: 3840b4aae7aSTrond Myklebust data->arg.create.createmode = NFS3_CREATE_UNCHECKED; 3851da177e4SLinus Torvalds break; 3861da177e4SLinus Torvalds 3871da177e4SLinus Torvalds case NFS3_CREATE_UNCHECKED: 388*1fcb6fcdSGao Xiang goto out_release_acls; 3891da177e4SLinus Torvalds } 3900b4aae7aSTrond Myklebust nfs_fattr_init(data->res.dir_attr); 3910b4aae7aSTrond Myklebust nfs_fattr_init(data->res.fattr); 3921da177e4SLinus Torvalds } 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds if (status != 0) 395013cdf10SChristoph Hellwig goto out_release_acls; 3961da177e4SLinus Torvalds 39717fd6e45SBenjamin Coddington if (d_alias) 39817fd6e45SBenjamin Coddington dentry = d_alias; 39917fd6e45SBenjamin Coddington 4001da177e4SLinus Torvalds /* When we created the file with exclusive semantics, make 4011da177e4SLinus Torvalds * sure we set the attributes afterwards. */ 4020b4aae7aSTrond Myklebust if (data->arg.create.createmode == NFS3_CREATE_EXCLUSIVE) { 4031da177e4SLinus Torvalds dprintk("NFS call setattr (post-create)\n"); 4041da177e4SLinus Torvalds 4051da177e4SLinus Torvalds if (!(sattr->ia_valid & ATTR_ATIME_SET)) 4061da177e4SLinus Torvalds sattr->ia_valid |= ATTR_ATIME; 4071da177e4SLinus Torvalds if (!(sattr->ia_valid & ATTR_MTIME_SET)) 4081da177e4SLinus Torvalds sattr->ia_valid |= ATTR_MTIME; 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds /* Note: we could use a guarded setattr here, but I'm 4111da177e4SLinus Torvalds * not sure this buys us anything (and I'd have 4121da177e4SLinus Torvalds * to revamp the NFSv3 XDR code) */ 4130b4aae7aSTrond Myklebust status = nfs3_proc_setattr(dentry, data->res.fattr, sattr); 4142b0143b5SDavid Howells nfs_post_op_update_inode(d_inode(dentry), data->res.fattr); 4151da177e4SLinus Torvalds dprintk("NFS reply setattr (post-create): %d\n", status); 416055ffbeaSAndreas Gruenbacher if (status != 0) 41717fd6e45SBenjamin Coddington goto out_dput; 4180b4aae7aSTrond Myklebust } 419013cdf10SChristoph Hellwig 4202b0143b5SDavid Howells status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl); 421013cdf10SChristoph Hellwig 42217fd6e45SBenjamin Coddington out_dput: 42317fd6e45SBenjamin Coddington dput(d_alias); 424013cdf10SChristoph Hellwig out_release_acls: 425013cdf10SChristoph Hellwig posix_acl_release(acl); 426013cdf10SChristoph Hellwig posix_acl_release(default_acl); 4271da177e4SLinus Torvalds out: 4280b4aae7aSTrond Myklebust nfs3_free_createdata(data); 4291da177e4SLinus Torvalds dprintk("NFS reply create: %d\n", status); 4301da177e4SLinus Torvalds return status; 4311da177e4SLinus Torvalds } 4321da177e4SLinus Torvalds 4331da177e4SLinus Torvalds static int 434912678dbSTrond Myklebust nfs3_proc_remove(struct inode *dir, struct dentry *dentry) 4351da177e4SLinus Torvalds { 4364fdc17b2STrond Myklebust struct nfs_removeargs arg = { 4371da177e4SLinus Torvalds .fh = NFS_FH(dir), 438912678dbSTrond Myklebust .name = dentry->d_name, 4391da177e4SLinus Torvalds }; 4404fdc17b2STrond Myklebust struct nfs_removeres res; 4411da177e4SLinus Torvalds struct rpc_message msg = { 4421da177e4SLinus Torvalds .rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE], 4431da177e4SLinus Torvalds .rpc_argp = &arg, 4444fdc17b2STrond Myklebust .rpc_resp = &res, 4451da177e4SLinus Torvalds }; 446d346890bSTrond Myklebust int status = -ENOMEM; 4471da177e4SLinus Torvalds 448912678dbSTrond Myklebust dprintk("NFS call remove %pd2\n", dentry); 449d346890bSTrond Myklebust res.dir_attr = nfs_alloc_fattr(); 450d346890bSTrond Myklebust if (res.dir_attr == NULL) 451d346890bSTrond Myklebust goto out; 452d346890bSTrond Myklebust 4531da177e4SLinus Torvalds status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 454d346890bSTrond Myklebust nfs_post_op_update_inode(dir, res.dir_attr); 455d346890bSTrond Myklebust nfs_free_fattr(res.dir_attr); 456d346890bSTrond Myklebust out: 4571da177e4SLinus Torvalds dprintk("NFS reply remove: %d\n", status); 4581da177e4SLinus Torvalds return status; 4591da177e4SLinus Torvalds } 4601da177e4SLinus Torvalds 461e4eff1a6STrond Myklebust static void 462ed7e9ad0STrond Myklebust nfs3_proc_unlink_setup(struct rpc_message *msg, 463ed7e9ad0STrond Myklebust struct dentry *dentry, 464ed7e9ad0STrond Myklebust struct inode *inode) 4651da177e4SLinus Torvalds { 4661da177e4SLinus Torvalds msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE]; 4671da177e4SLinus Torvalds } 4681da177e4SLinus Torvalds 46934e137ccSBryan Schumaker static void nfs3_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data) 47034e137ccSBryan Schumaker { 47134e137ccSBryan Schumaker rpc_call_start(task); 47234e137ccSBryan Schumaker } 47334e137ccSBryan Schumaker 4741da177e4SLinus Torvalds static int 475e4eff1a6STrond Myklebust nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir) 4761da177e4SLinus Torvalds { 477e4eff1a6STrond Myklebust struct nfs_removeres *res; 478e4eff1a6STrond Myklebust if (nfs3_async_handle_jukebox(task, dir)) 4791da177e4SLinus Torvalds return 0; 480e4eff1a6STrond Myklebust res = task->tk_msg.rpc_resp; 481d346890bSTrond Myklebust nfs_post_op_update_inode(dir, res->dir_attr); 482e4eff1a6STrond Myklebust return 1; 4831da177e4SLinus Torvalds } 4841da177e4SLinus Torvalds 485d3d4152aSJeff Layton static void 486f2c2c552STrond Myklebust nfs3_proc_rename_setup(struct rpc_message *msg, 487f2c2c552STrond Myklebust struct dentry *old_dentry, 488f2c2c552STrond Myklebust struct dentry *new_dentry) 489d3d4152aSJeff Layton { 490d3d4152aSJeff Layton msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME]; 491d3d4152aSJeff Layton } 492d3d4152aSJeff Layton 493c6bfa1a1SBryan Schumaker static void nfs3_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data) 494c6bfa1a1SBryan Schumaker { 495c6bfa1a1SBryan Schumaker rpc_call_start(task); 496c6bfa1a1SBryan Schumaker } 497c6bfa1a1SBryan Schumaker 498d3d4152aSJeff Layton static int 499d3d4152aSJeff Layton nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir, 500d3d4152aSJeff Layton struct inode *new_dir) 501d3d4152aSJeff Layton { 502d3d4152aSJeff Layton struct nfs_renameres *res; 503d3d4152aSJeff Layton 504d3d4152aSJeff Layton if (nfs3_async_handle_jukebox(task, old_dir)) 505d3d4152aSJeff Layton return 0; 506d3d4152aSJeff Layton res = task->tk_msg.rpc_resp; 507d3d4152aSJeff Layton 508d3d4152aSJeff Layton nfs_post_op_update_inode(old_dir, res->old_fattr); 509d3d4152aSJeff Layton nfs_post_op_update_inode(new_dir, res->new_fattr); 510d3d4152aSJeff Layton return 1; 511d3d4152aSJeff Layton } 512d3d4152aSJeff Layton 5131da177e4SLinus Torvalds static int 514beffb8feSAl Viro nfs3_proc_link(struct inode *inode, struct inode *dir, const struct qstr *name) 5151da177e4SLinus Torvalds { 5161da177e4SLinus Torvalds struct nfs3_linkargs arg = { 5171da177e4SLinus Torvalds .fromfh = NFS_FH(inode), 5181da177e4SLinus Torvalds .tofh = NFS_FH(dir), 5191da177e4SLinus Torvalds .toname = name->name, 5201da177e4SLinus Torvalds .tolen = name->len 5211da177e4SLinus Torvalds }; 522136f2627STrond Myklebust struct nfs3_linkres res; 523dead28daSChuck Lever struct rpc_message msg = { 524dead28daSChuck Lever .rpc_proc = &nfs3_procedures[NFS3PROC_LINK], 525dead28daSChuck Lever .rpc_argp = &arg, 526dead28daSChuck Lever .rpc_resp = &res, 527dead28daSChuck Lever }; 528136f2627STrond Myklebust int status = -ENOMEM; 5291da177e4SLinus Torvalds 5301da177e4SLinus Torvalds dprintk("NFS call link %s\n", name->name); 531136f2627STrond Myklebust res.fattr = nfs_alloc_fattr(); 532136f2627STrond Myklebust res.dir_attr = nfs_alloc_fattr(); 533136f2627STrond Myklebust if (res.fattr == NULL || res.dir_attr == NULL) 534136f2627STrond Myklebust goto out; 535136f2627STrond Myklebust 536dead28daSChuck Lever status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); 537136f2627STrond Myklebust nfs_post_op_update_inode(dir, res.dir_attr); 538136f2627STrond Myklebust nfs_post_op_update_inode(inode, res.fattr); 539136f2627STrond Myklebust out: 540136f2627STrond Myklebust nfs_free_fattr(res.dir_attr); 541136f2627STrond Myklebust nfs_free_fattr(res.fattr); 5421da177e4SLinus Torvalds dprintk("NFS reply link: %d\n", status); 5431da177e4SLinus Torvalds return status; 5441da177e4SLinus Torvalds } 5451da177e4SLinus Torvalds 5461da177e4SLinus Torvalds static int 54794a6d753SChuck Lever nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page, 54894a6d753SChuck Lever unsigned int len, struct iattr *sattr) 5491da177e4SLinus Torvalds { 5500b4aae7aSTrond Myklebust struct nfs3_createdata *data; 55117fd6e45SBenjamin Coddington struct dentry *d_alias; 5520b4aae7aSTrond Myklebust int status = -ENOMEM; 5531da177e4SLinus Torvalds 55494a6d753SChuck Lever if (len > NFS3_MAXPATHLEN) 5551da177e4SLinus Torvalds return -ENAMETOOLONG; 5564f390c15SChuck Lever 5576de1472fSAl Viro dprintk("NFS call symlink %pd\n", dentry); 55894a6d753SChuck Lever 5590b4aae7aSTrond Myklebust data = nfs3_alloc_createdata(); 5600b4aae7aSTrond Myklebust if (data == NULL) 5614f390c15SChuck Lever goto out; 5620b4aae7aSTrond Myklebust data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_SYMLINK]; 5630b4aae7aSTrond Myklebust data->arg.symlink.fromfh = NFS_FH(dir); 5640b4aae7aSTrond Myklebust data->arg.symlink.fromname = dentry->d_name.name; 5650b4aae7aSTrond Myklebust data->arg.symlink.fromlen = dentry->d_name.len; 5660b4aae7aSTrond Myklebust data->arg.symlink.pages = &page; 5670b4aae7aSTrond Myklebust data->arg.symlink.pathlen = len; 5680b4aae7aSTrond Myklebust data->arg.symlink.sattr = sattr; 5690b4aae7aSTrond Myklebust 57017fd6e45SBenjamin Coddington d_alias = nfs3_do_create(dir, dentry, data); 57117fd6e45SBenjamin Coddington status = PTR_ERR_OR_ZERO(d_alias); 57217fd6e45SBenjamin Coddington 57317fd6e45SBenjamin Coddington if (status == 0) 57417fd6e45SBenjamin Coddington dput(d_alias); 5750b4aae7aSTrond Myklebust 5760b4aae7aSTrond Myklebust nfs3_free_createdata(data); 5774f390c15SChuck Lever out: 5781da177e4SLinus Torvalds dprintk("NFS reply symlink: %d\n", status); 5791da177e4SLinus Torvalds return status; 5801da177e4SLinus Torvalds } 5811da177e4SLinus Torvalds 5821da177e4SLinus Torvalds static int 5831da177e4SLinus Torvalds nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) 5841da177e4SLinus Torvalds { 585013cdf10SChristoph Hellwig struct posix_acl *default_acl, *acl; 5860b4aae7aSTrond Myklebust struct nfs3_createdata *data; 58717fd6e45SBenjamin Coddington struct dentry *d_alias; 5880b4aae7aSTrond Myklebust int status = -ENOMEM; 5891da177e4SLinus Torvalds 5906de1472fSAl Viro dprintk("NFS call mkdir %pd\n", dentry); 591055ffbeaSAndreas Gruenbacher 5920b4aae7aSTrond Myklebust data = nfs3_alloc_createdata(); 5930b4aae7aSTrond Myklebust if (data == NULL) 5940b4aae7aSTrond Myklebust goto out; 5950b4aae7aSTrond Myklebust 596013cdf10SChristoph Hellwig status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl); 597013cdf10SChristoph Hellwig if (status) 598013cdf10SChristoph Hellwig goto out; 599013cdf10SChristoph Hellwig 6000b4aae7aSTrond Myklebust data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR]; 6010b4aae7aSTrond Myklebust data->arg.mkdir.fh = NFS_FH(dir); 6020b4aae7aSTrond Myklebust data->arg.mkdir.name = dentry->d_name.name; 6030b4aae7aSTrond Myklebust data->arg.mkdir.len = dentry->d_name.len; 6040b4aae7aSTrond Myklebust data->arg.mkdir.sattr = sattr; 6050b4aae7aSTrond Myklebust 60617fd6e45SBenjamin Coddington d_alias = nfs3_do_create(dir, dentry, data); 60717fd6e45SBenjamin Coddington status = PTR_ERR_OR_ZERO(d_alias); 60817fd6e45SBenjamin Coddington 609055ffbeaSAndreas Gruenbacher if (status != 0) 610013cdf10SChristoph Hellwig goto out_release_acls; 6110b4aae7aSTrond Myklebust 61217fd6e45SBenjamin Coddington if (d_alias) 61317fd6e45SBenjamin Coddington dentry = d_alias; 61417fd6e45SBenjamin Coddington 6152b0143b5SDavid Howells status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl); 616013cdf10SChristoph Hellwig 61717fd6e45SBenjamin Coddington dput(d_alias); 618013cdf10SChristoph Hellwig out_release_acls: 619013cdf10SChristoph Hellwig posix_acl_release(acl); 620013cdf10SChristoph Hellwig posix_acl_release(default_acl); 621055ffbeaSAndreas Gruenbacher out: 6220b4aae7aSTrond Myklebust nfs3_free_createdata(data); 6231da177e4SLinus Torvalds dprintk("NFS reply mkdir: %d\n", status); 6241da177e4SLinus Torvalds return status; 6251da177e4SLinus Torvalds } 6261da177e4SLinus Torvalds 6271da177e4SLinus Torvalds static int 628beffb8feSAl Viro nfs3_proc_rmdir(struct inode *dir, const struct qstr *name) 6291da177e4SLinus Torvalds { 63039967ddfSTrond Myklebust struct nfs_fattr *dir_attr; 6311da177e4SLinus Torvalds struct nfs3_diropargs arg = { 6321da177e4SLinus Torvalds .fh = NFS_FH(dir), 6331da177e4SLinus Torvalds .name = name->name, 6341da177e4SLinus Torvalds .len = name->len 6351da177e4SLinus Torvalds }; 636dead28daSChuck Lever struct rpc_message msg = { 637dead28daSChuck Lever .rpc_proc = &nfs3_procedures[NFS3PROC_RMDIR], 638dead28daSChuck Lever .rpc_argp = &arg, 639dead28daSChuck Lever }; 64039967ddfSTrond Myklebust int status = -ENOMEM; 6411da177e4SLinus Torvalds 6421da177e4SLinus Torvalds dprintk("NFS call rmdir %s\n", name->name); 64339967ddfSTrond Myklebust dir_attr = nfs_alloc_fattr(); 64439967ddfSTrond Myklebust if (dir_attr == NULL) 64539967ddfSTrond Myklebust goto out; 64639967ddfSTrond Myklebust 64739967ddfSTrond Myklebust msg.rpc_resp = dir_attr; 648dead28daSChuck Lever status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 64939967ddfSTrond Myklebust nfs_post_op_update_inode(dir, dir_attr); 65039967ddfSTrond Myklebust nfs_free_fattr(dir_attr); 65139967ddfSTrond Myklebust out: 6521da177e4SLinus Torvalds dprintk("NFS reply rmdir: %d\n", status); 6531da177e4SLinus Torvalds return status; 6541da177e4SLinus Torvalds } 6551da177e4SLinus Torvalds 6561da177e4SLinus Torvalds /* 6571da177e4SLinus Torvalds * The READDIR implementation is somewhat hackish - we pass the user buffer 6581da177e4SLinus Torvalds * to the encode function, which installs it in the receive iovec. 6591da177e4SLinus Torvalds * The decode function itself doesn't perform any decoding, it just makes 6601da177e4SLinus Torvalds * sure the reply is syntactically correct. 6611da177e4SLinus Torvalds * 6621da177e4SLinus Torvalds * Also note that this implementation handles both plain readdir and 6631da177e4SLinus Torvalds * readdirplus. 6641da177e4SLinus Torvalds */ 66582e22a5eSTrond Myklebust static int nfs3_proc_readdir(struct nfs_readdir_arg *nr_arg, 66682e22a5eSTrond Myklebust struct nfs_readdir_res *nr_res) 6671da177e4SLinus Torvalds { 66882e22a5eSTrond Myklebust struct inode *dir = d_inode(nr_arg->dentry); 6691da177e4SLinus Torvalds struct nfs3_readdirargs arg = { 6701da177e4SLinus Torvalds .fh = NFS_FH(dir), 67182e22a5eSTrond Myklebust .cookie = nr_arg->cookie, 67282e22a5eSTrond Myklebust .plus = nr_arg->plus, 67382e22a5eSTrond Myklebust .count = nr_arg->page_len, 67482e22a5eSTrond Myklebust .pages = nr_arg->pages 6751da177e4SLinus Torvalds }; 6761da177e4SLinus Torvalds struct nfs3_readdirres res = { 67782e22a5eSTrond Myklebust .verf = nr_res->verf, 67882e22a5eSTrond Myklebust .plus = nr_arg->plus, 6791da177e4SLinus Torvalds }; 6801da177e4SLinus Torvalds struct rpc_message msg = { 6811da177e4SLinus Torvalds .rpc_proc = &nfs3_procedures[NFS3PROC_READDIR], 6821da177e4SLinus Torvalds .rpc_argp = &arg, 6831da177e4SLinus Torvalds .rpc_resp = &res, 68482e22a5eSTrond Myklebust .rpc_cred = nr_arg->cred, 6851da177e4SLinus Torvalds }; 686aa49b4cfSTrond Myklebust int status = -ENOMEM; 6871da177e4SLinus Torvalds 68882e22a5eSTrond Myklebust if (nr_arg->plus) 6891da177e4SLinus Torvalds msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS]; 69082e22a5eSTrond Myklebust if (arg.cookie) 69182e22a5eSTrond Myklebust memcpy(arg.verf, nr_arg->verf, sizeof(arg.verf)); 6921da177e4SLinus Torvalds 69382e22a5eSTrond Myklebust dprintk("NFS call readdir%s %llu\n", nr_arg->plus ? "plus" : "", 69482e22a5eSTrond Myklebust (unsigned long long)nr_arg->cookie); 6951da177e4SLinus Torvalds 696aa49b4cfSTrond Myklebust res.dir_attr = nfs_alloc_fattr(); 697aa49b4cfSTrond Myklebust if (res.dir_attr == NULL) 698aa49b4cfSTrond Myklebust goto out; 699aa49b4cfSTrond Myklebust 7001da177e4SLinus Torvalds status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 701c4812998STrond Myklebust 702c4812998STrond Myklebust nfs_invalidate_atime(dir); 703aa49b4cfSTrond Myklebust nfs_refresh_inode(dir, res.dir_attr); 704c4812998STrond Myklebust 705aa49b4cfSTrond Myklebust nfs_free_fattr(res.dir_attr); 706aa49b4cfSTrond Myklebust out: 70782e22a5eSTrond Myklebust dprintk("NFS reply readdir%s: %d\n", nr_arg->plus ? "plus" : "", 70882e22a5eSTrond Myklebust status); 7091da177e4SLinus Torvalds return status; 7101da177e4SLinus Torvalds } 7111da177e4SLinus Torvalds 7121da177e4SLinus Torvalds static int 7131da177e4SLinus Torvalds nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr, 7141da177e4SLinus Torvalds dev_t rdev) 7151da177e4SLinus Torvalds { 716013cdf10SChristoph Hellwig struct posix_acl *default_acl, *acl; 7170b4aae7aSTrond Myklebust struct nfs3_createdata *data; 71817fd6e45SBenjamin Coddington struct dentry *d_alias; 7190b4aae7aSTrond Myklebust int status = -ENOMEM; 7201da177e4SLinus Torvalds 7216de1472fSAl Viro dprintk("NFS call mknod %pd %u:%u\n", dentry, 7221da177e4SLinus Torvalds MAJOR(rdev), MINOR(rdev)); 723055ffbeaSAndreas Gruenbacher 7240b4aae7aSTrond Myklebust data = nfs3_alloc_createdata(); 7250b4aae7aSTrond Myklebust if (data == NULL) 726055ffbeaSAndreas Gruenbacher goto out; 7270b4aae7aSTrond Myklebust 728013cdf10SChristoph Hellwig status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl); 729013cdf10SChristoph Hellwig if (status) 730013cdf10SChristoph Hellwig goto out; 731013cdf10SChristoph Hellwig 7320b4aae7aSTrond Myklebust data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKNOD]; 7330b4aae7aSTrond Myklebust data->arg.mknod.fh = NFS_FH(dir); 7340b4aae7aSTrond Myklebust data->arg.mknod.name = dentry->d_name.name; 7350b4aae7aSTrond Myklebust data->arg.mknod.len = dentry->d_name.len; 7360b4aae7aSTrond Myklebust data->arg.mknod.sattr = sattr; 7370b4aae7aSTrond Myklebust data->arg.mknod.rdev = rdev; 7380b4aae7aSTrond Myklebust 7390b4aae7aSTrond Myklebust switch (sattr->ia_mode & S_IFMT) { 7400b4aae7aSTrond Myklebust case S_IFBLK: 7410b4aae7aSTrond Myklebust data->arg.mknod.type = NF3BLK; 7420b4aae7aSTrond Myklebust break; 7430b4aae7aSTrond Myklebust case S_IFCHR: 7440b4aae7aSTrond Myklebust data->arg.mknod.type = NF3CHR; 7450b4aae7aSTrond Myklebust break; 7460b4aae7aSTrond Myklebust case S_IFIFO: 7470b4aae7aSTrond Myklebust data->arg.mknod.type = NF3FIFO; 7480b4aae7aSTrond Myklebust break; 7490b4aae7aSTrond Myklebust case S_IFSOCK: 7500b4aae7aSTrond Myklebust data->arg.mknod.type = NF3SOCK; 7510b4aae7aSTrond Myklebust break; 7520b4aae7aSTrond Myklebust default: 7530b4aae7aSTrond Myklebust status = -EINVAL; 754*1fcb6fcdSGao Xiang goto out_release_acls; 7550b4aae7aSTrond Myklebust } 7560b4aae7aSTrond Myklebust 75717fd6e45SBenjamin Coddington d_alias = nfs3_do_create(dir, dentry, data); 75817fd6e45SBenjamin Coddington status = PTR_ERR_OR_ZERO(d_alias); 759055ffbeaSAndreas Gruenbacher if (status != 0) 760013cdf10SChristoph Hellwig goto out_release_acls; 761013cdf10SChristoph Hellwig 76217fd6e45SBenjamin Coddington if (d_alias) 76317fd6e45SBenjamin Coddington dentry = d_alias; 76417fd6e45SBenjamin Coddington 7652b0143b5SDavid Howells status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl); 766013cdf10SChristoph Hellwig 76717fd6e45SBenjamin Coddington dput(d_alias); 768013cdf10SChristoph Hellwig out_release_acls: 769013cdf10SChristoph Hellwig posix_acl_release(acl); 770013cdf10SChristoph Hellwig posix_acl_release(default_acl); 771055ffbeaSAndreas Gruenbacher out: 7720b4aae7aSTrond Myklebust nfs3_free_createdata(data); 7731da177e4SLinus Torvalds dprintk("NFS reply mknod: %d\n", status); 7741da177e4SLinus Torvalds return status; 7751da177e4SLinus Torvalds } 7761da177e4SLinus Torvalds 7771da177e4SLinus Torvalds static int 7781da177e4SLinus Torvalds nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, 7791da177e4SLinus Torvalds struct nfs_fsstat *stat) 7801da177e4SLinus Torvalds { 781dead28daSChuck Lever struct rpc_message msg = { 782dead28daSChuck Lever .rpc_proc = &nfs3_procedures[NFS3PROC_FSSTAT], 783dead28daSChuck Lever .rpc_argp = fhandle, 784dead28daSChuck Lever .rpc_resp = stat, 785dead28daSChuck Lever }; 7861da177e4SLinus Torvalds int status; 7871da177e4SLinus Torvalds 7881da177e4SLinus Torvalds dprintk("NFS call fsstat\n"); 7890e574af1STrond Myklebust nfs_fattr_init(stat->fattr); 790dead28daSChuck Lever status = rpc_call_sync(server->client, &msg, 0); 791d141d974SChuck Lever dprintk("NFS reply fsstat: %d\n", status); 7921da177e4SLinus Torvalds return status; 7931da177e4SLinus Torvalds } 7941da177e4SLinus Torvalds 7951da177e4SLinus Torvalds static int 79637ca8f5cSEG Keizer do_proc_fsinfo(struct rpc_clnt *client, struct nfs_fh *fhandle, 7971da177e4SLinus Torvalds struct nfs_fsinfo *info) 7981da177e4SLinus Torvalds { 799dead28daSChuck Lever struct rpc_message msg = { 800dead28daSChuck Lever .rpc_proc = &nfs3_procedures[NFS3PROC_FSINFO], 801dead28daSChuck Lever .rpc_argp = fhandle, 802dead28daSChuck Lever .rpc_resp = info, 803dead28daSChuck Lever }; 8041da177e4SLinus Torvalds int status; 8051da177e4SLinus Torvalds 8061da177e4SLinus Torvalds dprintk("NFS call fsinfo\n"); 8070e574af1STrond Myklebust nfs_fattr_init(info->fattr); 80837ca8f5cSEG Keizer status = rpc_call_sync(client, &msg, 0); 8091da177e4SLinus Torvalds dprintk("NFS reply fsinfo: %d\n", status); 8101da177e4SLinus Torvalds return status; 8111da177e4SLinus Torvalds } 8121da177e4SLinus Torvalds 81337ca8f5cSEG Keizer /* 81437ca8f5cSEG Keizer * Bare-bones access to fsinfo: this is for nfs_get_root/nfs_get_sb via 81537ca8f5cSEG Keizer * nfs_create_server 81637ca8f5cSEG Keizer */ 81737ca8f5cSEG Keizer static int 81837ca8f5cSEG Keizer nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, 81937ca8f5cSEG Keizer struct nfs_fsinfo *info) 82037ca8f5cSEG Keizer { 82137ca8f5cSEG Keizer int status; 82237ca8f5cSEG Keizer 82337ca8f5cSEG Keizer status = do_proc_fsinfo(server->client, fhandle, info); 82437ca8f5cSEG Keizer if (status && server->nfs_client->cl_rpcclient != server->client) 82537ca8f5cSEG Keizer status = do_proc_fsinfo(server->nfs_client->cl_rpcclient, fhandle, info); 82637ca8f5cSEG Keizer return status; 82737ca8f5cSEG Keizer } 82837ca8f5cSEG Keizer 8291da177e4SLinus Torvalds static int 8301da177e4SLinus Torvalds nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, 8311da177e4SLinus Torvalds struct nfs_pathconf *info) 8321da177e4SLinus Torvalds { 833dead28daSChuck Lever struct rpc_message msg = { 834dead28daSChuck Lever .rpc_proc = &nfs3_procedures[NFS3PROC_PATHCONF], 835dead28daSChuck Lever .rpc_argp = fhandle, 836dead28daSChuck Lever .rpc_resp = info, 837dead28daSChuck Lever }; 8381da177e4SLinus Torvalds int status; 8391da177e4SLinus Torvalds 8401da177e4SLinus Torvalds dprintk("NFS call pathconf\n"); 8410e574af1STrond Myklebust nfs_fattr_init(info->fattr); 842dead28daSChuck Lever status = rpc_call_sync(server->client, &msg, 0); 8431da177e4SLinus Torvalds dprintk("NFS reply pathconf: %d\n", status); 8441da177e4SLinus Torvalds return status; 8451da177e4SLinus Torvalds } 8461da177e4SLinus Torvalds 847d45f60c6SWeston Andros Adamson static int nfs3_read_done(struct rpc_task *task, struct nfs_pgio_header *hdr) 8481da177e4SLinus Torvalds { 849d45f60c6SWeston Andros Adamson struct inode *inode = hdr->inode; 8508d8928d8STrond Myklebust struct nfs_server *server = NFS_SERVER(inode); 851cd841605SFred Isaman 85216cecdf6STrond Myklebust if (hdr->pgio_done_cb != NULL) 85316cecdf6STrond Myklebust return hdr->pgio_done_cb(task, hdr); 85416cecdf6STrond Myklebust 855cd841605SFred Isaman if (nfs3_async_handle_jukebox(task, inode)) 856ec06c096STrond Myklebust return -EAGAIN; 8578850df99STrond Myklebust 8588d8928d8STrond Myklebust if (task->tk_status >= 0 && !server->read_hdrsize) 8598d8928d8STrond Myklebust cmpxchg(&server->read_hdrsize, 0, hdr->res.replen); 8608d8928d8STrond Myklebust 861cd841605SFred Isaman nfs_invalidate_atime(inode); 862d45f60c6SWeston Andros Adamson nfs_refresh_inode(inode, &hdr->fattr); 863ec06c096STrond Myklebust return 0; 8641da177e4SLinus Torvalds } 8651da177e4SLinus Torvalds 866d45f60c6SWeston Andros Adamson static void nfs3_proc_read_setup(struct nfs_pgio_header *hdr, 867d45f60c6SWeston Andros Adamson struct rpc_message *msg) 8681da177e4SLinus Torvalds { 869bdc7f021STrond Myklebust msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ]; 8708d8928d8STrond Myklebust hdr->args.replen = NFS_SERVER(hdr->inode)->read_hdrsize; 8711da177e4SLinus Torvalds } 8721da177e4SLinus Torvalds 873d45f60c6SWeston Andros Adamson static int nfs3_proc_pgio_rpc_prepare(struct rpc_task *task, 874d45f60c6SWeston Andros Adamson struct nfs_pgio_header *hdr) 875ea7c3303SBryan Schumaker { 876ea7c3303SBryan Schumaker rpc_call_start(task); 877ef1820f9SNeilBrown return 0; 878ea7c3303SBryan Schumaker } 879ea7c3303SBryan Schumaker 880d45f60c6SWeston Andros Adamson static int nfs3_write_done(struct rpc_task *task, struct nfs_pgio_header *hdr) 8811da177e4SLinus Torvalds { 882d45f60c6SWeston Andros Adamson struct inode *inode = hdr->inode; 883cd841605SFred Isaman 88416cecdf6STrond Myklebust if (hdr->pgio_done_cb != NULL) 88516cecdf6STrond Myklebust return hdr->pgio_done_cb(task, hdr); 88616cecdf6STrond Myklebust 887cd841605SFred Isaman if (nfs3_async_handle_jukebox(task, inode)) 888788e7a89STrond Myklebust return -EAGAIN; 8891da177e4SLinus Torvalds if (task->tk_status >= 0) 890a08a8cd3STrond Myklebust nfs_writeback_update_inode(hdr); 891788e7a89STrond Myklebust return 0; 8921da177e4SLinus Torvalds } 8931da177e4SLinus Torvalds 894d45f60c6SWeston Andros Adamson static void nfs3_proc_write_setup(struct nfs_pgio_header *hdr, 895fb91fb0eSAnna Schumaker struct rpc_message *msg, 896fb91fb0eSAnna Schumaker struct rpc_clnt **clnt) 8971da177e4SLinus Torvalds { 898bdc7f021STrond Myklebust msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE]; 8991da177e4SLinus Torvalds } 9001da177e4SLinus Torvalds 9010b7c0153SFred Isaman static void nfs3_proc_commit_rpc_prepare(struct rpc_task *task, struct nfs_commit_data *data) 9020b7c0153SFred Isaman { 9030b7c0153SFred Isaman rpc_call_start(task); 9040b7c0153SFred Isaman } 9050b7c0153SFred Isaman 9060b7c0153SFred Isaman static int nfs3_commit_done(struct rpc_task *task, struct nfs_commit_data *data) 9071da177e4SLinus Torvalds { 90816cecdf6STrond Myklebust if (data->commit_done_cb != NULL) 90916cecdf6STrond Myklebust return data->commit_done_cb(task, data); 91016cecdf6STrond Myklebust 911006ea73eSChuck Lever if (nfs3_async_handle_jukebox(task, data->inode)) 912788e7a89STrond Myklebust return -EAGAIN; 9139e08a3c5STrond Myklebust nfs_refresh_inode(data->inode, data->res.fattr); 914788e7a89STrond Myklebust return 0; 9151da177e4SLinus Torvalds } 9161da177e4SLinus Torvalds 917e9ae1ee2SAnna Schumaker static void nfs3_proc_commit_setup(struct nfs_commit_data *data, struct rpc_message *msg, 918e9ae1ee2SAnna Schumaker struct rpc_clnt **clnt) 9191da177e4SLinus Torvalds { 920bdc7f021STrond Myklebust msg->rpc_proc = &nfs3_procedures[NFS3PROC_COMMIT]; 9211da177e4SLinus Torvalds } 9221da177e4SLinus Torvalds 923bb3393d5STrond Myklebust static void nfs3_nlm_alloc_call(void *data) 924f30cb757SBenjamin Coddington { 925f30cb757SBenjamin Coddington struct nfs_lock_context *l_ctx = data; 926f30cb757SBenjamin Coddington if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) { 927f30cb757SBenjamin Coddington get_nfs_open_context(l_ctx->open_context); 928f30cb757SBenjamin Coddington nfs_get_lock_context(l_ctx->open_context); 929f30cb757SBenjamin Coddington } 930f30cb757SBenjamin Coddington } 931f30cb757SBenjamin Coddington 932bb3393d5STrond Myklebust static bool nfs3_nlm_unlock_prepare(struct rpc_task *task, void *data) 933f30cb757SBenjamin Coddington { 934f30cb757SBenjamin Coddington struct nfs_lock_context *l_ctx = data; 935f30cb757SBenjamin Coddington if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) 936f30cb757SBenjamin Coddington return nfs_async_iocounter_wait(task, l_ctx); 937f30cb757SBenjamin Coddington return false; 938f30cb757SBenjamin Coddington 939f30cb757SBenjamin Coddington } 940f30cb757SBenjamin Coddington 941bb3393d5STrond Myklebust static void nfs3_nlm_release_call(void *data) 942f30cb757SBenjamin Coddington { 943f30cb757SBenjamin Coddington struct nfs_lock_context *l_ctx = data; 944f30cb757SBenjamin Coddington struct nfs_open_context *ctx; 945f30cb757SBenjamin Coddington if (l_ctx && test_bit(NFS_CONTEXT_UNLOCK, &l_ctx->open_context->flags)) { 946f30cb757SBenjamin Coddington ctx = l_ctx->open_context; 947f30cb757SBenjamin Coddington nfs_put_lock_context(l_ctx); 948f30cb757SBenjamin Coddington put_nfs_open_context(ctx); 949f30cb757SBenjamin Coddington } 950f30cb757SBenjamin Coddington } 951f30cb757SBenjamin Coddington 9521b720406SColin Ian King static const struct nlmclnt_operations nlmclnt_fl_close_lock_ops = { 953f30cb757SBenjamin Coddington .nlmclnt_alloc_call = nfs3_nlm_alloc_call, 954f30cb757SBenjamin Coddington .nlmclnt_unlock_prepare = nfs3_nlm_unlock_prepare, 955f30cb757SBenjamin Coddington .nlmclnt_release_call = nfs3_nlm_release_call, 956f30cb757SBenjamin Coddington }; 957f30cb757SBenjamin Coddington 9581da177e4SLinus Torvalds static int 9591da177e4SLinus Torvalds nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl) 9601da177e4SLinus Torvalds { 961496ad9aaSAl Viro struct inode *inode = file_inode(filp); 962f30cb757SBenjamin Coddington struct nfs_lock_context *l_ctx = NULL; 963f30cb757SBenjamin Coddington struct nfs_open_context *ctx = nfs_file_open_context(filp); 964f30cb757SBenjamin Coddington int status; 9651093a60eSChuck Lever 966f30cb757SBenjamin Coddington if (fl->fl_flags & FL_CLOSE) { 967f30cb757SBenjamin Coddington l_ctx = nfs_get_lock_context(ctx); 968f30cb757SBenjamin Coddington if (IS_ERR(l_ctx)) 969f30cb757SBenjamin Coddington l_ctx = NULL; 970f30cb757SBenjamin Coddington else 971f30cb757SBenjamin Coddington set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags); 972f30cb757SBenjamin Coddington } 973f30cb757SBenjamin Coddington 974f30cb757SBenjamin Coddington status = nlmclnt_proc(NFS_SERVER(inode)->nlm_host, cmd, fl, l_ctx); 975f30cb757SBenjamin Coddington 976f30cb757SBenjamin Coddington if (l_ctx) 977f30cb757SBenjamin Coddington nfs_put_lock_context(l_ctx); 978f30cb757SBenjamin Coddington 979f30cb757SBenjamin Coddington return status; 9801da177e4SLinus Torvalds } 9811da177e4SLinus Torvalds 982011e2a7fSBryan Schumaker static int nfs3_have_delegation(struct inode *inode, fmode_t flags) 983011e2a7fSBryan Schumaker { 984011e2a7fSBryan Schumaker return 0; 985011e2a7fSBryan Schumaker } 986011e2a7fSBryan Schumaker 987ab96291eSBryan Schumaker static const struct inode_operations nfs3_dir_inode_operations = { 988ab96291eSBryan Schumaker .create = nfs_create, 989ab96291eSBryan Schumaker .lookup = nfs_lookup, 990ab96291eSBryan Schumaker .link = nfs_link, 991ab96291eSBryan Schumaker .unlink = nfs_unlink, 992ab96291eSBryan Schumaker .symlink = nfs_symlink, 993ab96291eSBryan Schumaker .mkdir = nfs_mkdir, 994ab96291eSBryan Schumaker .rmdir = nfs_rmdir, 995ab96291eSBryan Schumaker .mknod = nfs_mknod, 996ab96291eSBryan Schumaker .rename = nfs_rename, 997ab96291eSBryan Schumaker .permission = nfs_permission, 998ab96291eSBryan Schumaker .getattr = nfs_getattr, 999ab96291eSBryan Schumaker .setattr = nfs_setattr, 10005f13ee9cSChristoph Hellwig #ifdef CONFIG_NFS_V3_ACL 100174adf83fSChristoph Hellwig .listxattr = nfs3_listxattr, 1002013cdf10SChristoph Hellwig .get_acl = nfs3_get_acl, 1003013cdf10SChristoph Hellwig .set_acl = nfs3_set_acl, 1004013cdf10SChristoph Hellwig #endif 1005ab96291eSBryan Schumaker }; 1006ab96291eSBryan Schumaker 1007ab96291eSBryan Schumaker static const struct inode_operations nfs3_file_inode_operations = { 1008ab96291eSBryan Schumaker .permission = nfs_permission, 1009ab96291eSBryan Schumaker .getattr = nfs_getattr, 1010ab96291eSBryan Schumaker .setattr = nfs_setattr, 10115f13ee9cSChristoph Hellwig #ifdef CONFIG_NFS_V3_ACL 101274adf83fSChristoph Hellwig .listxattr = nfs3_listxattr, 1013013cdf10SChristoph Hellwig .get_acl = nfs3_get_acl, 1014013cdf10SChristoph Hellwig .set_acl = nfs3_set_acl, 1015013cdf10SChristoph Hellwig #endif 1016ab96291eSBryan Schumaker }; 1017ab96291eSBryan Schumaker 1018509de811SDavid Howells const struct nfs_rpc_ops nfs_v3_clientops = { 10191da177e4SLinus Torvalds .version = 3, /* protocol version */ 10201da177e4SLinus Torvalds .dentry_ops = &nfs_dentry_operations, 1021b7fa0554SAndreas Gruenbacher .dir_inode_ops = &nfs3_dir_inode_operations, 1022b7fa0554SAndreas Gruenbacher .file_inode_ops = &nfs3_file_inode_operations, 10231788ea6eSJeff Layton .file_ops = &nfs_file_operations, 1024f30cb757SBenjamin Coddington .nlmclnt_ops = &nlmclnt_fl_close_lock_ops, 10251da177e4SLinus Torvalds .getroot = nfs3_proc_get_root, 1026281cad46SBryan Schumaker .submount = nfs_submount, 1027f2aedb71SDavid Howells .try_get_tree = nfs_try_get_tree, 10281da177e4SLinus Torvalds .getattr = nfs3_proc_getattr, 10291da177e4SLinus Torvalds .setattr = nfs3_proc_setattr, 10301da177e4SLinus Torvalds .lookup = nfs3_proc_lookup, 10313c5e9a59STrond Myklebust .lookupp = nfs3_proc_lookupp, 10321da177e4SLinus Torvalds .access = nfs3_proc_access, 10331da177e4SLinus Torvalds .readlink = nfs3_proc_readlink, 10341da177e4SLinus Torvalds .create = nfs3_proc_create, 10351da177e4SLinus Torvalds .remove = nfs3_proc_remove, 10361da177e4SLinus Torvalds .unlink_setup = nfs3_proc_unlink_setup, 103734e137ccSBryan Schumaker .unlink_rpc_prepare = nfs3_proc_unlink_rpc_prepare, 10381da177e4SLinus Torvalds .unlink_done = nfs3_proc_unlink_done, 1039d3d4152aSJeff Layton .rename_setup = nfs3_proc_rename_setup, 1040c6bfa1a1SBryan Schumaker .rename_rpc_prepare = nfs3_proc_rename_rpc_prepare, 1041d3d4152aSJeff Layton .rename_done = nfs3_proc_rename_done, 10421da177e4SLinus Torvalds .link = nfs3_proc_link, 10431da177e4SLinus Torvalds .symlink = nfs3_proc_symlink, 10441da177e4SLinus Torvalds .mkdir = nfs3_proc_mkdir, 10451da177e4SLinus Torvalds .rmdir = nfs3_proc_rmdir, 10461da177e4SLinus Torvalds .readdir = nfs3_proc_readdir, 10471da177e4SLinus Torvalds .mknod = nfs3_proc_mknod, 10481da177e4SLinus Torvalds .statfs = nfs3_proc_statfs, 10491da177e4SLinus Torvalds .fsinfo = nfs3_proc_fsinfo, 10501da177e4SLinus Torvalds .pathconf = nfs3_proc_pathconf, 10511da177e4SLinus Torvalds .decode_dirent = nfs3_decode_dirent, 1052a4cdda59SAnna Schumaker .pgio_rpc_prepare = nfs3_proc_pgio_rpc_prepare, 10531da177e4SLinus Torvalds .read_setup = nfs3_proc_read_setup, 1054ec06c096STrond Myklebust .read_done = nfs3_read_done, 10551da177e4SLinus Torvalds .write_setup = nfs3_proc_write_setup, 1056788e7a89STrond Myklebust .write_done = nfs3_write_done, 10571da177e4SLinus Torvalds .commit_setup = nfs3_proc_commit_setup, 10580b7c0153SFred Isaman .commit_rpc_prepare = nfs3_proc_commit_rpc_prepare, 1059788e7a89STrond Myklebust .commit_done = nfs3_commit_done, 10601da177e4SLinus Torvalds .lock = nfs3_proc_lock, 1061013cdf10SChristoph Hellwig .clear_acl_cache = forget_all_cached_acls, 10627fe5c398STrond Myklebust .close_context = nfs_close_context, 1063011e2a7fSBryan Schumaker .have_delegation = nfs3_have_delegation, 10646663ee7fSBryan Schumaker .alloc_client = nfs_alloc_client, 106545a52a02SAndy Adamson .init_client = nfs_init_client, 1066cdb7ecedSBryan Schumaker .free_client = nfs_free_client, 10671179acc6SBryan Schumaker .create_server = nfs3_create_server, 10681179acc6SBryan Schumaker .clone_server = nfs3_clone_server, 10691da177e4SLinus Torvalds }; 1070