diff options
Diffstat (limited to 'fs/nfsd/nfs4recover.c')
| -rw-r--r-- | fs/nfsd/nfs4recover.c | 87 |
1 files changed, 42 insertions, 45 deletions
diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c index 7a9ae3254a4b..7e26caab2a26 100644 --- a/fs/nfsd/nfs4recover.c +++ b/fs/nfsd/nfs4recover.c | |||
| @@ -44,8 +44,7 @@ | |||
| 44 | #define NFSDDBG_FACILITY NFSDDBG_PROC | 44 | #define NFSDDBG_FACILITY NFSDDBG_PROC |
| 45 | 45 | ||
| 46 | /* Globals */ | 46 | /* Globals */ |
| 47 | static struct path rec_dir; | 47 | static struct file *rec_file; |
| 48 | static int rec_dir_init = 0; | ||
| 49 | 48 | ||
| 50 | static int | 49 | static int |
| 51 | nfs4_save_creds(const struct cred **original_creds) | 50 | nfs4_save_creds(const struct cred **original_creds) |
| @@ -117,33 +116,28 @@ out_no_tfm: | |||
| 117 | return status; | 116 | return status; |
| 118 | } | 117 | } |
| 119 | 118 | ||
| 120 | static void | ||
| 121 | nfsd4_sync_rec_dir(void) | ||
| 122 | { | ||
| 123 | vfs_fsync(NULL, rec_dir.dentry, 0); | ||
| 124 | } | ||
| 125 | |||
| 126 | int | 119 | int |
| 127 | nfsd4_create_clid_dir(struct nfs4_client *clp) | 120 | nfsd4_create_clid_dir(struct nfs4_client *clp) |
| 128 | { | 121 | { |
| 129 | const struct cred *original_cred; | 122 | const struct cred *original_cred; |
| 130 | char *dname = clp->cl_recdir; | 123 | char *dname = clp->cl_recdir; |
| 131 | struct dentry *dentry; | 124 | struct dentry *dir, *dentry; |
| 132 | int status; | 125 | int status; |
| 133 | 126 | ||
| 134 | dprintk("NFSD: nfsd4_create_clid_dir for \"%s\"\n", dname); | 127 | dprintk("NFSD: nfsd4_create_clid_dir for \"%s\"\n", dname); |
| 135 | 128 | ||
| 136 | if (!rec_dir_init || clp->cl_firststate) | 129 | if (!rec_file || clp->cl_firststate) |
| 137 | return 0; | 130 | return 0; |
| 138 | 131 | ||
| 139 | status = nfs4_save_creds(&original_cred); | 132 | status = nfs4_save_creds(&original_cred); |
| 140 | if (status < 0) | 133 | if (status < 0) |
| 141 | return status; | 134 | return status; |
| 142 | 135 | ||
| 136 | dir = rec_file->f_path.dentry; | ||
| 143 | /* lock the parent */ | 137 | /* lock the parent */ |
| 144 | mutex_lock(&rec_dir.dentry->d_inode->i_mutex); | 138 | mutex_lock(&dir->d_inode->i_mutex); |
| 145 | 139 | ||
| 146 | dentry = lookup_one_len(dname, rec_dir.dentry, HEXDIR_LEN-1); | 140 | dentry = lookup_one_len(dname, dir, HEXDIR_LEN-1); |
| 147 | if (IS_ERR(dentry)) { | 141 | if (IS_ERR(dentry)) { |
| 148 | status = PTR_ERR(dentry); | 142 | status = PTR_ERR(dentry); |
| 149 | goto out_unlock; | 143 | goto out_unlock; |
| @@ -153,18 +147,18 @@ nfsd4_create_clid_dir(struct nfs4_client *clp) | |||
| 153 | dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n"); | 147 | dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n"); |
| 154 | goto out_put; | 148 | goto out_put; |
| 155 | } | 149 | } |
| 156 | status = mnt_want_write(rec_dir.mnt); | 150 | status = mnt_want_write(rec_file->f_path.mnt); |
| 157 | if (status) | 151 | if (status) |
| 158 | goto out_put; | 152 | goto out_put; |
| 159 | status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU); | 153 | status = vfs_mkdir(dir->d_inode, dentry, S_IRWXU); |
| 160 | mnt_drop_write(rec_dir.mnt); | 154 | mnt_drop_write(rec_file->f_path.mnt); |
| 161 | out_put: | 155 | out_put: |
| 162 | dput(dentry); | 156 | dput(dentry); |
| 163 | out_unlock: | 157 | out_unlock: |
| 164 | mutex_unlock(&rec_dir.dentry->d_inode->i_mutex); | 158 | mutex_unlock(&dir->d_inode->i_mutex); |
| 165 | if (status == 0) { | 159 | if (status == 0) { |
| 166 | clp->cl_firststate = 1; | 160 | clp->cl_firststate = 1; |
| 167 | nfsd4_sync_rec_dir(); | 161 | vfs_fsync(rec_file, 0); |
| 168 | } | 162 | } |
| 169 | nfs4_reset_creds(original_cred); | 163 | nfs4_reset_creds(original_cred); |
| 170 | dprintk("NFSD: nfsd4_create_clid_dir returns %d\n", status); | 164 | dprintk("NFSD: nfsd4_create_clid_dir returns %d\n", status); |
| @@ -206,14 +200,14 @@ nfsd4_list_rec_dir(struct dentry *dir, recdir_func *f) | |||
| 206 | struct dentry *dentry; | 200 | struct dentry *dentry; |
| 207 | int status; | 201 | int status; |
| 208 | 202 | ||
| 209 | if (!rec_dir_init) | 203 | if (!rec_file) |
| 210 | return 0; | 204 | return 0; |
| 211 | 205 | ||
| 212 | status = nfs4_save_creds(&original_cred); | 206 | status = nfs4_save_creds(&original_cred); |
| 213 | if (status < 0) | 207 | if (status < 0) |
| 214 | return status; | 208 | return status; |
| 215 | 209 | ||
| 216 | filp = dentry_open(dget(dir), mntget(rec_dir.mnt), O_RDONLY, | 210 | filp = dentry_open(dget(dir), mntget(rec_file->f_path.mnt), O_RDONLY, |
| 217 | current_cred()); | 211 | current_cred()); |
| 218 | status = PTR_ERR(filp); | 212 | status = PTR_ERR(filp); |
| 219 | if (IS_ERR(filp)) | 213 | if (IS_ERR(filp)) |
| @@ -250,13 +244,14 @@ out: | |||
| 250 | static int | 244 | static int |
| 251 | nfsd4_unlink_clid_dir(char *name, int namlen) | 245 | nfsd4_unlink_clid_dir(char *name, int namlen) |
| 252 | { | 246 | { |
| 253 | struct dentry *dentry; | 247 | struct dentry *dir, *dentry; |
| 254 | int status; | 248 | int status; |
| 255 | 249 | ||
| 256 | dprintk("NFSD: nfsd4_unlink_clid_dir. name %.*s\n", namlen, name); | 250 | dprintk("NFSD: nfsd4_unlink_clid_dir. name %.*s\n", namlen, name); |
| 257 | 251 | ||
| 258 | mutex_lock_nested(&rec_dir.dentry->d_inode->i_mutex, I_MUTEX_PARENT); | 252 | dir = rec_file->f_path.dentry; |
| 259 | dentry = lookup_one_len(name, rec_dir.dentry, namlen); | 253 | mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT); |
| 254 | dentry = lookup_one_len(name, dir, namlen); | ||
| 260 | if (IS_ERR(dentry)) { | 255 | if (IS_ERR(dentry)) { |
| 261 | status = PTR_ERR(dentry); | 256 | status = PTR_ERR(dentry); |
| 262 | goto out_unlock; | 257 | goto out_unlock; |
| @@ -264,11 +259,11 @@ nfsd4_unlink_clid_dir(char *name, int namlen) | |||
| 264 | status = -ENOENT; | 259 | status = -ENOENT; |
| 265 | if (!dentry->d_inode) | 260 | if (!dentry->d_inode) |
| 266 | goto out; | 261 | goto out; |
| 267 | status = vfs_rmdir(rec_dir.dentry->d_inode, dentry); | 262 | status = vfs_rmdir(dir->d_inode, dentry); |
| 268 | out: | 263 | out: |
| 269 | dput(dentry); | 264 | dput(dentry); |
| 270 | out_unlock: | 265 | out_unlock: |
| 271 | mutex_unlock(&rec_dir.dentry->d_inode->i_mutex); | 266 | mutex_unlock(&dir->d_inode->i_mutex); |
| 272 | return status; | 267 | return status; |
| 273 | } | 268 | } |
| 274 | 269 | ||
| @@ -278,10 +273,10 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp) | |||
| 278 | const struct cred *original_cred; | 273 | const struct cred *original_cred; |
| 279 | int status; | 274 | int status; |
| 280 | 275 | ||
| 281 | if (!rec_dir_init || !clp->cl_firststate) | 276 | if (!rec_file || !clp->cl_firststate) |
| 282 | return; | 277 | return; |
| 283 | 278 | ||
| 284 | status = mnt_want_write(rec_dir.mnt); | 279 | status = mnt_want_write(rec_file->f_path.mnt); |
| 285 | if (status) | 280 | if (status) |
| 286 | goto out; | 281 | goto out; |
| 287 | clp->cl_firststate = 0; | 282 | clp->cl_firststate = 0; |
| @@ -293,8 +288,8 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp) | |||
| 293 | status = nfsd4_unlink_clid_dir(clp->cl_recdir, HEXDIR_LEN-1); | 288 | status = nfsd4_unlink_clid_dir(clp->cl_recdir, HEXDIR_LEN-1); |
| 294 | nfs4_reset_creds(original_cred); | 289 | nfs4_reset_creds(original_cred); |
| 295 | if (status == 0) | 290 | if (status == 0) |
| 296 | nfsd4_sync_rec_dir(); | 291 | vfs_fsync(rec_file, 0); |
| 297 | mnt_drop_write(rec_dir.mnt); | 292 | mnt_drop_write(rec_file->f_path.mnt); |
| 298 | out: | 293 | out: |
| 299 | if (status) | 294 | if (status) |
| 300 | printk("NFSD: Failed to remove expired client state directory" | 295 | printk("NFSD: Failed to remove expired client state directory" |
| @@ -323,19 +318,19 @@ void | |||
| 323 | nfsd4_recdir_purge_old(void) { | 318 | nfsd4_recdir_purge_old(void) { |
| 324 | int status; | 319 | int status; |
| 325 | 320 | ||
| 326 | if (!rec_dir_init) | 321 | if (!rec_file) |
| 327 | return; | 322 | return; |
| 328 | status = mnt_want_write(rec_dir.mnt); | 323 | status = mnt_want_write(rec_file->f_path.mnt); |
| 329 | if (status) | 324 | if (status) |
| 330 | goto out; | 325 | goto out; |
| 331 | status = nfsd4_list_rec_dir(rec_dir.dentry, purge_old); | 326 | status = nfsd4_list_rec_dir(rec_file->f_path.dentry, purge_old); |
| 332 | if (status == 0) | 327 | if (status == 0) |
| 333 | nfsd4_sync_rec_dir(); | 328 | vfs_fsync(rec_file, 0); |
| 334 | mnt_drop_write(rec_dir.mnt); | 329 | mnt_drop_write(rec_file->f_path.mnt); |
| 335 | out: | 330 | out: |
| 336 | if (status) | 331 | if (status) |
| 337 | printk("nfsd4: failed to purge old clients from recovery" | 332 | printk("nfsd4: failed to purge old clients from recovery" |
| 338 | " directory %s\n", rec_dir.dentry->d_name.name); | 333 | " directory %s\n", rec_file->f_path.dentry->d_name.name); |
| 339 | } | 334 | } |
| 340 | 335 | ||
| 341 | static int | 336 | static int |
| @@ -355,10 +350,13 @@ int | |||
| 355 | nfsd4_recdir_load(void) { | 350 | nfsd4_recdir_load(void) { |
| 356 | int status; | 351 | int status; |
| 357 | 352 | ||
| 358 | status = nfsd4_list_rec_dir(rec_dir.dentry, load_recdir); | 353 | if (!rec_file) |
| 354 | return 0; | ||
| 355 | |||
| 356 | status = nfsd4_list_rec_dir(rec_file->f_path.dentry, load_recdir); | ||
| 359 | if (status) | 357 | if (status) |
| 360 | printk("nfsd4: failed loading clients from recovery" | 358 | printk("nfsd4: failed loading clients from recovery" |
| 361 | " directory %s\n", rec_dir.dentry->d_name.name); | 359 | " directory %s\n", rec_file->f_path.dentry->d_name.name); |
| 362 | return status; | 360 | return status; |
| 363 | } | 361 | } |
| 364 | 362 | ||
| @@ -375,7 +373,7 @@ nfsd4_init_recdir(char *rec_dirname) | |||
| 375 | printk("NFSD: Using %s as the NFSv4 state recovery directory\n", | 373 | printk("NFSD: Using %s as the NFSv4 state recovery directory\n", |
| 376 | rec_dirname); | 374 | rec_dirname); |
| 377 | 375 | ||
| 378 | BUG_ON(rec_dir_init); | 376 | BUG_ON(rec_file); |
| 379 | 377 | ||
| 380 | status = nfs4_save_creds(&original_cred); | 378 | status = nfs4_save_creds(&original_cred); |
| 381 | if (status < 0) { | 379 | if (status < 0) { |
| @@ -385,22 +383,21 @@ nfsd4_init_recdir(char *rec_dirname) | |||
| 385 | return; | 383 | return; |
| 386 | } | 384 | } |
| 387 | 385 | ||
| 388 | status = kern_path(rec_dirname, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, | 386 | rec_file = filp_open(rec_dirname, O_RDONLY | O_DIRECTORY, 0); |
| 389 | &rec_dir); | 387 | if (IS_ERR(rec_file)) { |
| 390 | if (status) | ||
| 391 | printk("NFSD: unable to find recovery directory %s\n", | 388 | printk("NFSD: unable to find recovery directory %s\n", |
| 392 | rec_dirname); | 389 | rec_dirname); |
| 390 | rec_file = NULL; | ||
| 391 | } | ||
| 393 | 392 | ||
| 394 | if (!status) | ||
| 395 | rec_dir_init = 1; | ||
| 396 | nfs4_reset_creds(original_cred); | 393 | nfs4_reset_creds(original_cred); |
| 397 | } | 394 | } |
| 398 | 395 | ||
| 399 | void | 396 | void |
| 400 | nfsd4_shutdown_recdir(void) | 397 | nfsd4_shutdown_recdir(void) |
| 401 | { | 398 | { |
| 402 | if (!rec_dir_init) | 399 | if (!rec_file) |
| 403 | return; | 400 | return; |
| 404 | rec_dir_init = 0; | 401 | fput(rec_file); |
| 405 | path_put(&rec_dir); | 402 | rec_file = NULL; |
| 406 | } | 403 | } |
