19 #include <linux/fcntl.h>
24 #include <linux/xattr.h>
27 #include <linux/slab.h>
28 #include <asm/uaccess.h>
44 #define NFSDDBG_FACILITY NFSDDBG_FILEOP
69 #define RAPARM_HASH_BITS 4
70 #define RAPARM_HASH_SIZE (1<<RAPARM_HASH_BITS)
71 #define RAPARM_HASH_MASK (RAPARM_HASH_SIZE-1)
87 .dentry = dget(dentry)};
109 if (nfsd_v4client(rqstp) ||
129 static void follow_to_parent(
struct path *
path)
143 struct path path = {.
mnt =
mntget((*exp)->ex_path.mnt),
144 .dentry = dget(dparent)};
146 follow_to_parent(&path);
149 if (PTR_ERR(exp2) == -
ENOENT) {
150 *dentryp = dget(dparent);
151 }
else if (IS_ERR(exp2)) {
153 return PTR_ERR(exp2);
155 *dentryp = dget(path.
dentry);
169 if (d_mountpoint(dentry))
171 if (nfsd4_is_junction(dentry))
180 const char *
name,
unsigned int len,
197 dentry = dget(dparent);
198 else if (dparent != exp->
ex_path.dentry)
200 else if (!
EX_NOHIDE(exp) && !nfsd_v4client(rqstp))
201 dentry = dget(dparent);
204 host_err = nfsd_lookup_parent(rqstp, dparent, &exp, &dentry);
211 host_err = PTR_ERR(dentry);
224 *dentry_ret = dentry;
247 unsigned int len,
struct svc_fh *resfh)
275 static int nfsd_break_lease(
struct inode *
inode)
286 commit_metadata(
struct svc_fh *fhp)
288 struct inode *inode = fhp->
fh_dentry->d_inode;
305 int check_guard,
time_t guardtime)
321 err =
fh_verify(rqstp, fhp, ftype, accmode);
347 #define BOTH_TIME_SET (ATTR_ATIME_SET | ATTR_MTIME_SET)
348 #define MAX_TOUCH_TIME_ERROR (30*60)
384 host_err = get_write_access(inode);
389 host_err = locks_verify_truncate(inode,
NULL, iap->
ia_size);
391 put_write_access(inode);
423 if (!check_guard || guardtime == inode->
i_ctime.tv_sec) {
424 host_err = nfsd_break_lease(inode);
434 put_write_access(inode);
436 commit_metadata(fhp);
445 #if defined(CONFIG_NFSD_V2_ACL) || \
446 defined(CONFIG_NFSD_V3_ACL) || \
447 defined(CONFIG_NFSD_V4)
468 #if defined(CONFIG_NFSD_V4)
470 set_nfsv4_acl_one(
struct dentry *dentry,
struct posix_acl *pacl,
char *key)
477 buflen = posix_acl_xattr_size(pacl->
a_count);
501 struct dentry *dentry;
504 unsigned int flags = 0;
517 if (host_error == -
EINVAL) {
519 }
else if (host_error < 0)
530 posix_acl_release(pacl);
531 posix_acl_release(dpacl);
540 _get_posix_acl(
struct dentry *dentry,
char *key)
546 buflen = nfsd_getxattr(dentry, key, &buf);
550 return ERR_PTR(buflen);
558 nfsd4_get_nfs4_acl(
struct svc_rqst *rqstp,
struct dentry *dentry,
struct nfs4_acl **acl)
560 struct inode *inode = dentry->
d_inode;
563 unsigned int flags = 0;
566 if (IS_ERR(pacl) && PTR_ERR(pacl) == -
ENODATA)
569 error = PTR_ERR(pacl);
576 if (IS_ERR(dpacl) && PTR_ERR(dpacl) == -
ENODATA)
578 else if (IS_ERR(dpacl)) {
579 error = PTR_ERR(dpacl);
588 error = PTR_ERR(*acl);
592 posix_acl_release(pacl);
593 posix_acl_release(dpacl);
600 #define NFSD_JUNCTION_XATTR_NAME XATTR_TRUSTED_PREFIX "junction.nfs"
610 int nfsd4_is_junction(
struct dentry *dentry)
612 struct inode *inode = dentry->
d_inode;
626 #ifdef CONFIG_NFSD_V3
634 static struct accessmap nfs3_regaccess[] = {
643 static struct accessmap nfs3_diraccess[] = {
653 static struct accessmap nfs3_anyaccess[] = {
672 struct accessmap *
map;
674 struct dentry *dentry;
686 map = nfs3_regaccess;
688 map = nfs3_diraccess;
690 map = nfs3_anyaccess;
694 for (; map->access; map++) {
695 if (map->access & query) {
698 sresult |= map->access;
703 result |= map->access;
721 *supported = sresult;
728 static int nfsd_open_break_lease(
struct inode *inode,
int access)
746 int may_flags,
struct file **filp)
754 validate_process_creds();
769 err =
fh_verify(rqstp, fhp, type, may_flags);
775 inode = path.
dentry->d_inode;
794 host_err = nfsd_open_break_lease(inode, may_flags);
798 if (may_flags & NFSD_MAY_WRITE) {
806 host_err = PTR_ERR(*filp);
819 validate_process_creds();
846 rab = &raparm_hash[
hash];
895 if (rqstp->
rq_res.page_len == 0) {
902 }
else if (page != pp[-1]) {
944 host_err =
vfs_readv(file, (
struct iovec __user *)vec, vlen, &offset);
952 fsnotify_access(file);
958 static void kill_suid(
struct dentry *dentry)
982 static int wait_for_concurrent_writes(
struct file *file)
984 struct inode *inode = file->
f_path.dentry->d_inode;
985 static ino_t last_ino;
986 static dev_t last_dev;
990 || (last_ino == inode->
i_ino && last_dev == inode->
i_sb->s_dev)) {
1000 last_ino = inode->
i_ino;
1001 last_dev = inode->
i_sb->s_dev;
1006 nfsd_vfs_write(
struct svc_rqst *rqstp,
struct svc_fh *fhp,
struct file *file,
1007 loff_t offset,
struct kvec *vec,
int vlen,
1008 unsigned long *
cnt,
int *stablep)
1011 struct dentry *dentry;
1012 struct inode *
inode;
1016 int stable = *stablep;
1019 dentry = file->
f_path.dentry;
1033 if (!file->
f_op->fsync) {
1040 if (stable && !use_wgather) {
1041 spin_lock(&file->
f_lock);
1043 spin_unlock(&file->
f_lock);
1048 host_err =
vfs_writev(file, (
struct iovec __user *)vec, vlen, &offset);
1054 fsnotify_modify(file);
1060 if (stable && use_wgather)
1061 host_err = wait_for_concurrent_writes(file);
1064 dprintk(
"nfsd: write complete host_err=%d\n", host_err);
1078 loff_t offset,
struct kvec *vec,
int vlen,
unsigned long *count)
1081 struct inode *
inode;
1089 inode = file->
f_path.dentry->d_inode;
1092 ra = nfsd_get_raparms(inode->
i_sb->s_dev, inode->
i_ino);
1094 if (ra && ra->
p_set)
1097 err = nfsd_vfs_read(rqstp, fhp, file, offset, vec, vlen, count);
1116 loff_t offset,
struct kvec *vec,
int vlen,
1117 unsigned long *count)
1126 err = nfsd_vfs_read(rqstp, fhp, file, offset, vec, vlen, count);
1128 err =
nfsd_read(rqstp, fhp, offset, vec, vlen, count);
1140 loff_t offset,
struct kvec *vec,
int vlen,
unsigned long *cnt,
1150 err = nfsd_vfs_write(rqstp, fhp, file, offset, vec, vlen, cnt,
1158 err = nfsd_vfs_write(rqstp, fhp, file, offset, vec, vlen,
1166 #ifdef CONFIG_NFSD_V3
1178 loff_t offset,
unsigned long count)
1187 end = offset + (loff_t)count - 1;
1212 nfsd_create_setattr(
struct svc_rqst *rqstp,
struct svc_fh *resfhp,
1240 nfsd_check_ignore_resizing(
struct iattr *iap)
1259 struct dentry *dentry, *dchild =
NULL;
1280 if (!dirp->
i_op->lookup)
1287 host_err = fh_want_write(fhp);
1294 host_err = PTR_ERR(dchild);
1306 "nfsd_create: parent %s/%s not locked!\n",
1318 dprintk(
"nfsd_create: dentry %s/%s not negative!\n",
1343 nfsd_check_ignore_resizing(iap);
1358 err = nfsd_create_setattr(rqstp, resfhp, iap);
1365 err2 =
nfserrno(commit_metadata(fhp));
1374 if (dchild && !IS_ERR(dchild))
1383 #ifdef CONFIG_NFSD_V3
1385 static inline int nfsd_create_is_exclusive(
int createmode)
1397 struct svc_fh *resfhp,
int createmode,
u32 *verifier,
1400 struct dentry *dentry, *dchild =
NULL;
1404 __u32 v_mtime=0, v_atime=0;
1424 if (!dirp->
i_op->lookup)
1427 host_err = fh_want_write(fhp);
1437 host_err = PTR_ERR(dchild);
1452 if (nfsd_create_is_exclusive(createmode)) {
1459 v_mtime = verifier[0]&0x7fffffff;
1460 v_atime = verifier[1]&0x7fffffff;
1466 switch (createmode) {
1486 if ( dchild->
d_inode->i_mtime.tv_sec == v_mtime
1487 && dchild->
d_inode->i_atime.tv_sec == v_atime
1488 && dchild->
d_inode->i_size == 0 )
1491 if ( dchild->
d_inode->i_mtime.tv_sec == v_mtime
1492 && dchild->
d_inode->i_atime.tv_sec == v_atime
1493 && dchild->
d_inode->i_size == 0 )
1511 nfsd_check_ignore_resizing(iap);
1513 if (nfsd_create_is_exclusive(createmode)) {
1525 err = nfsd_create_setattr(rqstp, resfhp, iap);
1531 err =
nfserrno(commit_metadata(fhp));
1541 if (dchild && !IS_ERR(dchild))
1560 struct inode *
inode;
1572 inode = path.
dentry->d_inode;
1575 if (!inode->
i_op->readlink)
1605 char *fname,
int flen,
1606 char *path,
int plen,
1610 struct dentry *dentry, *dnew;
1625 host_err = fh_want_write(fhp);
1632 host_err = PTR_ERR(dnew);
1638 if (path_alloced ==
NULL)
1641 strncpy(path_alloced, path, plen);
1642 path_alloced[
plen] = 0;
1644 kfree(path_alloced);
1650 err =
nfserrno(commit_metadata(fhp));
1657 if (err==0) err = cerr;
1674 struct dentry *ddir, *dnew, *dold;
1695 host_err = fh_want_write(tfhp);
1706 host_err = PTR_ERR(dnew);
1715 host_err = nfsd_break_lease(dold->
d_inode);
1720 host_err =
vfs_link(dold, dirp, dnew);
1722 err =
nfserrno(commit_metadata(ffhp));
1724 err =
nfserrno(commit_metadata(tfhp));
1735 fh_drop_write(tfhp);
1750 struct svc_fh *tfhp,
char *tname,
int tlen)
1752 struct dentry *fdentry, *tdentry, *odentry, *ndentry, *
trap;
1753 struct inode *fdir, *tdir;
1778 host_err = fh_want_write(ffhp);
1792 host_err = PTR_ERR(odentry);
1793 if (IS_ERR(odentry))
1800 if (odentry == trap)
1804 host_err = PTR_ERR(ndentry);
1805 if (IS_ERR(ndentry))
1808 if (ndentry == trap)
1815 host_err = nfsd_break_lease(odentry->
d_inode);
1819 host_err = nfsd_break_lease(ndentry->
d_inode);
1823 host_err =
vfs_rename(fdir, odentry, tdir, ndentry);
1825 host_err = commit_metadata(tfhp);
1827 host_err = commit_metadata(ffhp);
1844 fh_drop_write(ffhp);
1856 char *fname,
int flen)
1858 struct dentry *dentry, *rdentry;
1864 if (!flen ||
isdotent(fname, flen))
1870 host_err = fh_want_write(fhp);
1879 host_err = PTR_ERR(rdentry);
1880 if (IS_ERR(rdentry))
1892 host_err = nfsd_break_lease(rdentry->
d_inode);
1900 host_err = commit_metadata(fhp);
1931 static int nfsd_buffered_filldir(
void *__buf,
const char *
name,
int namlen,
1932 loff_t offset,
u64 ino,
unsigned int d_type)
1936 unsigned int reclen;
1949 buf->
used += reclen;
1970 struct inode *dir_inode = file->
f_path.dentry->d_inode;
1971 unsigned int reclen;
1977 host_err =
vfs_readdir(file, nfsd_buffered_filldir, &buf);
2040 loff_t offset = *offsetp;
2057 err = nfsd_buffered_readdir(file, func, cdp, offsetp);
2078 struct path path = {
2098 struct dentry *dentry,
int acc)
2100 struct inode *inode = dentry->
d_inode;
2106 dprintk(
"nfsd: permission 0x%x%s%s%s%s%s%s%s mode 0%o%s%s%s\n",
2119 dprintk(
" owner %d/%d user %d/%d\n",
2128 if (acc & (NFSD_MAY_WRITE | NFSD_MAY_SATTR | NFSD_MAY_TRUNC)) {
2129 if (exp_rdonly(rqstp, exp) ||
2135 if ((acc & NFSD_MAY_TRUNC) &&
IS_APPEND(inode))
2138 if (acc & NFSD_MAY_LOCK) {
2162 if ((acc & NFSD_MAY_OWNER_OVERRIDE) &&
2171 (acc == (NFSD_MAY_READ | NFSD_MAY_OWNER_OVERRIDE) ||
2181 struct raparms *raparm, *last_raparm;
2184 dprintk(
"nfsd: freeing readahead buffers.\n");
2187 raparm = raparm_hash[
i].pb_head;
2189 last_raparm = raparm;
2193 raparm_hash[
i].pb_head =
NULL;
2208 if (raparm_hash[0].pb_head)
2215 dprintk(
"nfsd: allocating %d readahead buffers.\n", cache_size);
2220 raparm = &raparm_hash[
i].pb_head;
2221 for (j = 0; j < nperbucket; j++) {
2225 raparm = &(*raparm)->
p_next;
2234 dprintk(
"nfsd: kmalloc failed, freeing readahead buffers\n");
2239 #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
2241 nfsd_get_posix_acl(
struct svc_fh *fhp,
int type)
2243 struct inode *inode = fhp->
fh_dentry->d_inode;
2263 size = nfsd_getxattr(fhp->
fh_dentry, name, &value);
2265 return ERR_PTR(size);
2273 nfsd_set_posix_acl(
struct svc_fh *fhp,
int type,
struct posix_acl *acl)
2275 struct inode *inode = fhp->
fh_dentry->d_inode;
2282 !inode->
i_op->setxattr || !inode->
i_op->removexattr)
2296 size = posix_acl_xattr_size(acl->
a_count);
2307 error = fh_want_write(fhp);