Skip to content

Commit

Permalink
nfsd4: simplify recovery dir setting
Browse files Browse the repository at this point in the history
Move around some of this code, simplify a bit.

Reviewed-by: Boaz Harrosh <bharrosh@panasas.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
  • Loading branch information
J. Bruce Fields committed Aug 27, 2011
1 parent 8e82fa8 commit 48483bf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 45 deletions.
36 changes: 32 additions & 4 deletions fs/nfsd/nfs4recover.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

/* Globals */
static struct file *rec_file;
static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery";

static int
nfs4_save_creds(const struct cred **original_creds)
Expand Down Expand Up @@ -354,13 +355,13 @@ nfsd4_recdir_load(void) {
*/

void
nfsd4_init_recdir(char *rec_dirname)
nfsd4_init_recdir()
{
const struct cred *original_cred;
int status;

printk("NFSD: Using %s as the NFSv4 state recovery directory\n",
rec_dirname);
user_recovery_dirname);

BUG_ON(rec_file);

Expand All @@ -372,10 +373,10 @@ nfsd4_init_recdir(char *rec_dirname)
return;
}

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

Expand All @@ -390,3 +391,30 @@ nfsd4_shutdown_recdir(void)
fput(rec_file);
rec_file = NULL;
}

/*
* Change the NFSv4 recovery directory to recdir.
*/
int
nfs4_reset_recoverydir(char *recdir)
{
int status;
struct path path;

status = kern_path(recdir, LOOKUP_FOLLOW, &path);
if (status)
return status;
status = -ENOTDIR;
if (S_ISDIR(path.dentry->d_inode->i_mode)) {
strcpy(user_recovery_dirname, recdir);
status = 0;
}
path_put(&path);
return status;
}

char *
nfs4_recoverydir(void)
{
return user_recovery_dirname;
}
41 changes: 1 addition & 40 deletions fs/nfsd/nfs4state.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ static struct nfs4_stateid * find_stateid(stateid_t *stid, int flags);
static struct nfs4_stateid * search_for_stateid(stateid_t *stid);
static struct nfs4_delegation * search_for_delegation(stateid_t *stid);
static struct nfs4_delegation * find_delegation_stateid(struct inode *ino, stateid_t *stid);
static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery";
static void nfs4_set_recdir(char *recdir);
static int check_for_locks(struct nfs4_file *filp, struct nfs4_stateowner *lowner);

/* Locking: */
Expand Down Expand Up @@ -4523,7 +4521,7 @@ nfsd4_load_reboot_recovery_data(void)
int status;

nfs4_lock_state();
nfsd4_init_recdir(user_recovery_dirname);
nfsd4_init_recdir();
status = nfsd4_recdir_load();
nfs4_unlock_state();
if (status)
Expand Down Expand Up @@ -4632,40 +4630,3 @@ nfs4_state_shutdown(void)
nfs4_unlock_state();
nfsd4_destroy_callback_queue();
}

/*
* user_recovery_dirname is protected by the nfsd_mutex since it's only
* accessed when nfsd is starting.
*/
static void
nfs4_set_recdir(char *recdir)
{
strcpy(user_recovery_dirname, recdir);
}

/*
* Change the NFSv4 recovery directory to recdir.
*/
int
nfs4_reset_recoverydir(char *recdir)
{
int status;
struct path path;

status = kern_path(recdir, LOOKUP_FOLLOW, &path);
if (status)
return status;
status = -ENOTDIR;
if (S_ISDIR(path.dentry->d_inode->i_mode)) {
nfs4_set_recdir(recdir);
status = 0;
}
path_put(&path);
return status;
}

char *
nfs4_recoverydir(void)
{
return user_recovery_dirname;
}
2 changes: 1 addition & 1 deletion fs/nfsd/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ extern void nfsd4_destroy_callback_queue(void);
extern void nfsd4_shutdown_callback(struct nfs4_client *);
extern void nfs4_put_delegation(struct nfs4_delegation *dp);
extern __be32 nfs4_make_rec_clidname(char *clidname, struct xdr_netobj *clname);
extern void nfsd4_init_recdir(char *recdir_name);
extern void nfsd4_init_recdir(void);
extern int nfsd4_recdir_load(void);
extern void nfsd4_shutdown_recdir(void);
extern int nfs4_client_to_reclaim(const char *name);
Expand Down

0 comments on commit 48483bf

Please sign in to comment.