Skip to content

Commit

Permalink
nfsd: open a file descriptor for fsync in nfs4 recovery
Browse files Browse the repository at this point in the history
Instead of just looking up a path use do_filp_open to get us a file
structure for the nfs4 recovery directory.  This allows us to get
rid of the last non-standard vfs_fsync caller with a NULL file
pointer.

[AV: should be using fput(), not filp_close()]

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Christoph Hellwig authored and Al Viro committed May 21, 2010
1 parent 2e147f1 commit e970a57
Showing 1 changed file with 42 additions and 45 deletions.
87 changes: 42 additions & 45 deletions fs/nfsd/nfs4recover.c
Expand Up @@ -44,8 +44,7 @@
#define NFSDDBG_FACILITY NFSDDBG_PROC

/* Globals */
static struct path rec_dir;
static int rec_dir_init = 0;
static struct file *rec_file;

static int
nfs4_save_creds(const struct cred **original_creds)
Expand Down Expand Up @@ -117,33 +116,28 @@ nfs4_make_rec_clidname(char *dname, struct xdr_netobj *clname)
return status;
}

static void
nfsd4_sync_rec_dir(void)
{
vfs_fsync(NULL, rec_dir.dentry, 0);
}

int
nfsd4_create_clid_dir(struct nfs4_client *clp)
{
const struct cred *original_cred;
char *dname = clp->cl_recdir;
struct dentry *dentry;
struct dentry *dir, *dentry;
int status;

dprintk("NFSD: nfsd4_create_clid_dir for \"%s\"\n", dname);

if (!rec_dir_init || clp->cl_firststate)
if (!rec_file || clp->cl_firststate)
return 0;

status = nfs4_save_creds(&original_cred);
if (status < 0)
return status;

dir = rec_file->f_path.dentry;
/* lock the parent */
mutex_lock(&rec_dir.dentry->d_inode->i_mutex);
mutex_lock(&dir->d_inode->i_mutex);

dentry = lookup_one_len(dname, rec_dir.dentry, HEXDIR_LEN-1);
dentry = lookup_one_len(dname, dir, HEXDIR_LEN-1);
if (IS_ERR(dentry)) {
status = PTR_ERR(dentry);
goto out_unlock;
Expand All @@ -153,18 +147,18 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)
dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n");
goto out_put;
}
status = mnt_want_write(rec_dir.mnt);
status = mnt_want_write(rec_file->f_path.mnt);
if (status)
goto out_put;
status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU);
mnt_drop_write(rec_dir.mnt);
status = vfs_mkdir(dir->d_inode, dentry, S_IRWXU);
mnt_drop_write(rec_file->f_path.mnt);
out_put:
dput(dentry);
out_unlock:
mutex_unlock(&rec_dir.dentry->d_inode->i_mutex);
mutex_unlock(&dir->d_inode->i_mutex);
if (status == 0) {
clp->cl_firststate = 1;
nfsd4_sync_rec_dir();
vfs_fsync(rec_file, rec_file->f_path.dentry, 0);
}
nfs4_reset_creds(original_cred);
dprintk("NFSD: nfsd4_create_clid_dir returns %d\n", status);
Expand Down Expand Up @@ -206,14 +200,14 @@ nfsd4_list_rec_dir(struct dentry *dir, recdir_func *f)
struct dentry *dentry;
int status;

if (!rec_dir_init)
if (!rec_file)
return 0;

status = nfs4_save_creds(&original_cred);
if (status < 0)
return status;

filp = dentry_open(dget(dir), mntget(rec_dir.mnt), O_RDONLY,
filp = dentry_open(dget(dir), mntget(rec_file->f_path.mnt), O_RDONLY,
current_cred());
status = PTR_ERR(filp);
if (IS_ERR(filp))
Expand Down Expand Up @@ -250,25 +244,26 @@ nfsd4_list_rec_dir(struct dentry *dir, recdir_func *f)
static int
nfsd4_unlink_clid_dir(char *name, int namlen)
{
struct dentry *dentry;
struct dentry *dir, *dentry;
int status;

dprintk("NFSD: nfsd4_unlink_clid_dir. name %.*s\n", namlen, name);

mutex_lock_nested(&rec_dir.dentry->d_inode->i_mutex, I_MUTEX_PARENT);
dentry = lookup_one_len(name, rec_dir.dentry, namlen);
dir = rec_file->f_path.dentry;
mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
dentry = lookup_one_len(name, dir, namlen);
if (IS_ERR(dentry)) {
status = PTR_ERR(dentry);
goto out_unlock;
}
status = -ENOENT;
if (!dentry->d_inode)
goto out;
status = vfs_rmdir(rec_dir.dentry->d_inode, dentry);
status = vfs_rmdir(dir->d_inode, dentry);
out:
dput(dentry);
out_unlock:
mutex_unlock(&rec_dir.dentry->d_inode->i_mutex);
mutex_unlock(&dir->d_inode->i_mutex);
return status;
}

Expand All @@ -278,10 +273,10 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp)
const struct cred *original_cred;
int status;

if (!rec_dir_init || !clp->cl_firststate)
if (!rec_file || !clp->cl_firststate)
return;

status = mnt_want_write(rec_dir.mnt);
status = mnt_want_write(rec_file->f_path.mnt);
if (status)
goto out;
clp->cl_firststate = 0;
Expand All @@ -293,8 +288,8 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp)
status = nfsd4_unlink_clid_dir(clp->cl_recdir, HEXDIR_LEN-1);
nfs4_reset_creds(original_cred);
if (status == 0)
nfsd4_sync_rec_dir();
mnt_drop_write(rec_dir.mnt);
vfs_fsync(rec_file, rec_file->f_path.dentry, 0);
mnt_drop_write(rec_file->f_path.mnt);
out:
if (status)
printk("NFSD: Failed to remove expired client state directory"
Expand Down Expand Up @@ -323,19 +318,19 @@ void
nfsd4_recdir_purge_old(void) {
int status;

if (!rec_dir_init)
if (!rec_file)
return;
status = mnt_want_write(rec_dir.mnt);
status = mnt_want_write(rec_file->f_path.mnt);
if (status)
goto out;
status = nfsd4_list_rec_dir(rec_dir.dentry, purge_old);
status = nfsd4_list_rec_dir(rec_file->f_path.dentry, purge_old);
if (status == 0)
nfsd4_sync_rec_dir();
mnt_drop_write(rec_dir.mnt);
vfs_fsync(rec_file, rec_file->f_path.dentry, 0);
mnt_drop_write(rec_file->f_path.mnt);
out:
if (status)
printk("nfsd4: failed to purge old clients from recovery"
" directory %s\n", rec_dir.dentry->d_name.name);
" directory %s\n", rec_file->f_path.dentry->d_name.name);
}

static int
Expand All @@ -355,10 +350,13 @@ int
nfsd4_recdir_load(void) {
int status;

status = nfsd4_list_rec_dir(rec_dir.dentry, load_recdir);
if (!rec_file)
return 0;

status = nfsd4_list_rec_dir(rec_file->f_path.dentry, load_recdir);
if (status)
printk("nfsd4: failed loading clients from recovery"
" directory %s\n", rec_dir.dentry->d_name.name);
" directory %s\n", rec_file->f_path.dentry->d_name.name);
return status;
}

Expand All @@ -375,7 +373,7 @@ nfsd4_init_recdir(char *rec_dirname)
printk("NFSD: Using %s as the NFSv4 state recovery directory\n",
rec_dirname);

BUG_ON(rec_dir_init);
BUG_ON(rec_file);

status = nfs4_save_creds(&original_cred);
if (status < 0) {
Expand All @@ -385,22 +383,21 @@ nfsd4_init_recdir(char *rec_dirname)
return;
}

status = kern_path(rec_dirname, LOOKUP_FOLLOW | LOOKUP_DIRECTORY,
&rec_dir);
if (status)
rec_file = filp_open(rec_dirname, O_RDONLY | O_DIRECTORY, 0);
if (IS_ERR(rec_file)) {
printk("NFSD: unable to find recovery directory %s\n",
rec_dirname);
rec_file = NULL;
}

if (!status)
rec_dir_init = 1;
nfs4_reset_creds(original_cred);
}

void
nfsd4_shutdown_recdir(void)
{
if (!rec_dir_init)
if (!rec_file)
return;
rec_dir_init = 0;
path_put(&rec_dir);
fput(rec_file);
rec_file = NULL;
}

0 comments on commit e970a57

Please sign in to comment.