Commit 36b319a6 authored by Trond Myklebust's avatar Trond Myklebust Committed by Linus Torvalds

[PATCH] 2.5.6 Fix NFS file creation

  The following patch fixes a bug in NFS file creation. Recently (not
sure exactly when), open_namei() was changed so that it expects
vfs_create() to always return a fully instantiated dentry for the new
file.

The following patch ensures this is done in the cases where the RPC
CREATE call does not return valid attributes/filehandles. This is
always the case for NFSv2, and can sometimes be the case for v3...
parent 3d1504c6
...@@ -614,6 +614,12 @@ static int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle, ...@@ -614,6 +614,12 @@ static int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle,
struct inode *inode; struct inode *inode;
int error = -EACCES; int error = -EACCES;
if (fhandle->size == 0 || !(fattr->valid & NFS_ATTR_FATTR)) {
struct inode *dir = dentry->d_parent->d_inode;
error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, fhandle, fattr);
if (error)
goto out_err;
}
inode = nfs_fhget(dentry, fhandle, fattr); inode = nfs_fhget(dentry, fhandle, fattr);
if (inode) { if (inode) {
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
...@@ -621,6 +627,9 @@ static int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle, ...@@ -621,6 +627,9 @@ static int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fhandle,
error = 0; error = 0;
} }
return error; return error;
out_err:
d_drop(dentry);
return error;
} }
/* /*
...@@ -652,9 +661,9 @@ static int nfs_create(struct inode *dir, struct dentry *dentry, int mode) ...@@ -652,9 +661,9 @@ static int nfs_create(struct inode *dir, struct dentry *dentry, int mode)
nfs_zap_caches(dir); nfs_zap_caches(dir);
error = NFS_PROTO(dir)->create(dir, &dentry->d_name, error = NFS_PROTO(dir)->create(dir, &dentry->d_name,
&attr, 0, &fhandle, &fattr); &attr, 0, &fhandle, &fattr);
if (!error && fhandle.size != 0) if (!error)
error = nfs_instantiate(dentry, &fhandle, &fattr); error = nfs_instantiate(dentry, &fhandle, &fattr);
if (error || fhandle.size == 0) else
d_drop(dentry); d_drop(dentry);
unlock_kernel(); unlock_kernel();
return error; return error;
...@@ -680,9 +689,9 @@ static int nfs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rde ...@@ -680,9 +689,9 @@ static int nfs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rde
nfs_zap_caches(dir); nfs_zap_caches(dir);
error = NFS_PROTO(dir)->mknod(dir, &dentry->d_name, &attr, rdev, error = NFS_PROTO(dir)->mknod(dir, &dentry->d_name, &attr, rdev,
&fhandle, &fattr); &fhandle, &fattr);
if (!error && fhandle.size != 0) if (!error)
error = nfs_instantiate(dentry, &fhandle, &fattr); error = nfs_instantiate(dentry, &fhandle, &fattr);
if (error || fhandle.size == 0) else
d_drop(dentry); d_drop(dentry);
unlock_kernel(); unlock_kernel();
return error; return error;
...@@ -717,9 +726,9 @@ static int nfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) ...@@ -717,9 +726,9 @@ static int nfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
nfs_zap_caches(dir); nfs_zap_caches(dir);
error = NFS_PROTO(dir)->mkdir(dir, &dentry->d_name, &attr, &fhandle, error = NFS_PROTO(dir)->mkdir(dir, &dentry->d_name, &attr, &fhandle,
&fattr); &fattr);
if (!error && fhandle.size != 0) if (!error)
error = nfs_instantiate(dentry, &fhandle, &fattr); error = nfs_instantiate(dentry, &fhandle, &fattr);
if (error || fhandle.size == 0) else
d_drop(dentry); d_drop(dentry);
unlock_kernel(); unlock_kernel();
return error; return error;
...@@ -930,7 +939,7 @@ dentry->d_parent->d_name.name, dentry->d_name.name); ...@@ -930,7 +939,7 @@ dentry->d_parent->d_name.name, dentry->d_name.name);
nfs_zap_caches(dir); nfs_zap_caches(dir);
error = NFS_PROTO(dir)->symlink(dir, &dentry->d_name, &qsymname, error = NFS_PROTO(dir)->symlink(dir, &dentry->d_name, &qsymname,
&attr, &sym_fh, &sym_attr); &attr, &sym_fh, &sym_attr);
if (!error && sym_fh.size != 0 && (sym_attr.valid & NFS_ATTR_FATTR)) { if (!error) {
error = nfs_instantiate(dentry, &sym_fh, &sym_attr); error = nfs_instantiate(dentry, &sym_fh, &sym_attr);
} else { } else {
if (error == -EEXIST) if (error == -EEXIST)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment