aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorWendy Cheng <wcheng@redhat.com>2008-01-17 11:10:12 -0500
committerJ. Bruce Fields <bfields@citi.umich.edu>2008-04-25 13:00:11 -0400
commit17efa372cfe4d189705edf6cd4fbe283827a5dc7 (patch)
treedcf10b96b079fff6edebbf451a32608ce6032663 /fs
parent4373ea84c84d8a96e99d3da99e813d3e36d1bd11 (diff)
lockd: unlock lockd locks held for a certain filesystem
Add /proc/fs/nfsd/unlock_filesystem, which allows e.g.: shell> echo /mnt/sfs1 > /proc/fs/nfsd/unlock_filesystem so that a filesystem can be unmounted before allowing a peer nfsd to take over nfs service for the filesystem. Signed-off-by: S. Wendy Cheng <wcheng@redhat.com> Cc: Lon Hohberger <lhh@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu> fs/lockd/svcsubs.c | 66 +++++++++++++++++++++++++++++++++++++++----- fs/nfsd/nfsctl.c | 65 +++++++++++++++++++++++++++++++++++++++++++ include/linux/lockd/lockd.h | 7 ++++ 3 files changed, 131 insertions(+), 7 deletions(-)
Diffstat (limited to 'fs')
-rw-r--r--fs/lockd/svcsubs.c37
-rw-r--r--fs/nfsd/nfsctl.c32
2 files changed, 64 insertions, 5 deletions
diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c
index 1adcf93cb6e6..d1c48b539df8 100644
--- a/fs/lockd/svcsubs.c
+++ b/fs/lockd/svcsubs.c
@@ -196,6 +196,12 @@ again:
196 return 0; 196 return 0;
197} 197}
198 198
199static int
200nlmsvc_always_match(void *dummy1, struct nlm_host *dummy2)
201{
202 return 1;
203}
204
199/* 205/*
200 * Inspect a single file 206 * Inspect a single file
201 */ 207 */
@@ -232,7 +238,8 @@ nlm_file_inuse(struct nlm_file *file)
232 * Loop over all files in the file table. 238 * Loop over all files in the file table.
233 */ 239 */
234static int 240static int
235nlm_traverse_files(void *data, nlm_host_match_fn_t match) 241nlm_traverse_files(void *data, nlm_host_match_fn_t match,
242 int (*is_failover_file)(void *data, struct nlm_file *file))
236{ 243{
237 struct hlist_node *pos, *next; 244 struct hlist_node *pos, *next;
238 struct nlm_file *file; 245 struct nlm_file *file;
@@ -241,6 +248,8 @@ nlm_traverse_files(void *data, nlm_host_match_fn_t match)
241 mutex_lock(&nlm_file_mutex); 248 mutex_lock(&nlm_file_mutex);
242 for (i = 0; i < FILE_NRHASH; i++) { 249 for (i = 0; i < FILE_NRHASH; i++) {
243 hlist_for_each_entry_safe(file, pos, next, &nlm_files[i], f_list) { 250 hlist_for_each_entry_safe(file, pos, next, &nlm_files[i], f_list) {
251 if (is_failover_file && !is_failover_file(data, file))
252 continue;
244 file->f_count++; 253 file->f_count++;
245 mutex_unlock(&nlm_file_mutex); 254 mutex_unlock(&nlm_file_mutex);
246 255
@@ -345,7 +354,7 @@ void
345nlmsvc_mark_resources(void) 354nlmsvc_mark_resources(void)
346{ 355{
347 dprintk("lockd: nlmsvc_mark_resources\n"); 356 dprintk("lockd: nlmsvc_mark_resources\n");
348 nlm_traverse_files(NULL, nlmsvc_mark_host); 357 nlm_traverse_files(NULL, nlmsvc_mark_host, NULL);
349} 358}
350 359
351/* 360/*
@@ -356,7 +365,7 @@ nlmsvc_free_host_resources(struct nlm_host *host)
356{ 365{
357 dprintk("lockd: nlmsvc_free_host_resources\n"); 366 dprintk("lockd: nlmsvc_free_host_resources\n");
358 367
359 if (nlm_traverse_files(host, nlmsvc_same_host)) { 368 if (nlm_traverse_files(host, nlmsvc_same_host, NULL)) {
360 printk(KERN_WARNING 369 printk(KERN_WARNING
361 "lockd: couldn't remove all locks held by %s\n", 370 "lockd: couldn't remove all locks held by %s\n",
362 host->h_name); 371 host->h_name);
@@ -376,8 +385,26 @@ nlmsvc_invalidate_all(void)
376 * turn, which is about as inefficient as it gets. 385 * turn, which is about as inefficient as it gets.
377 * Now we just do it once in nlm_traverse_files. 386 * Now we just do it once in nlm_traverse_files.
378 */ 387 */
379 nlm_traverse_files(NULL, nlmsvc_is_client); 388 nlm_traverse_files(NULL, nlmsvc_is_client, NULL);
389}
390
391static int
392nlmsvc_match_sb(void *datap, struct nlm_file *file)
393{
394 struct super_block *sb = datap;
395
396 return sb == file->f_file->f_path.mnt->mnt_sb;
397}
398
399int
400nlmsvc_unlock_all_by_sb(struct super_block *sb)
401{
402 int ret;
403
404 ret = nlm_traverse_files(sb, nlmsvc_always_match, nlmsvc_match_sb);
405 return ret ? -EIO : 0;
380} 406}
407EXPORT_SYMBOL_GPL(nlmsvc_unlock_all_by_sb);
381 408
382static int 409static int
383nlmsvc_match_ip(void *datap, struct nlm_host *host) 410nlmsvc_match_ip(void *datap, struct nlm_host *host)
@@ -391,7 +418,7 @@ int
391nlmsvc_unlock_all_by_ip(__be32 server_addr) 418nlmsvc_unlock_all_by_ip(__be32 server_addr)
392{ 419{
393 int ret; 420 int ret;
394 ret = nlm_traverse_files(&server_addr, nlmsvc_match_ip); 421 ret = nlm_traverse_files(&server_addr, nlmsvc_match_ip, NULL);
395 return ret ? -EIO : 0; 422 return ret ? -EIO : 0;
396 423
397} 424}
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 7706f6c9ab8a..42f3820ee8f5 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -56,6 +56,7 @@ enum {
56 NFSD_List, 56 NFSD_List,
57 NFSD_Fh, 57 NFSD_Fh,
58 NFSD_FO_UnlockIP, 58 NFSD_FO_UnlockIP,
59 NFSD_FO_UnlockFS,
59 NFSD_Threads, 60 NFSD_Threads,
60 NFSD_Pool_Threads, 61 NFSD_Pool_Threads,
61 NFSD_Versions, 62 NFSD_Versions,
@@ -93,6 +94,7 @@ static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
93#endif 94#endif
94 95
95static ssize_t failover_unlock_ip(struct file *file, char *buf, size_t size); 96static ssize_t failover_unlock_ip(struct file *file, char *buf, size_t size);
97static ssize_t failover_unlock_fs(struct file *file, char *buf, size_t size);
96 98
97static ssize_t (*write_op[])(struct file *, char *, size_t) = { 99static ssize_t (*write_op[])(struct file *, char *, size_t) = {
98 [NFSD_Svc] = write_svc, 100 [NFSD_Svc] = write_svc,
@@ -104,6 +106,7 @@ static ssize_t (*write_op[])(struct file *, char *, size_t) = {
104 [NFSD_Getfs] = write_getfs, 106 [NFSD_Getfs] = write_getfs,
105 [NFSD_Fh] = write_filehandle, 107 [NFSD_Fh] = write_filehandle,
106 [NFSD_FO_UnlockIP] = failover_unlock_ip, 108 [NFSD_FO_UnlockIP] = failover_unlock_ip,
109 [NFSD_FO_UnlockFS] = failover_unlock_fs,
107 [NFSD_Threads] = write_threads, 110 [NFSD_Threads] = write_threads,
108 [NFSD_Pool_Threads] = write_pool_threads, 111 [NFSD_Pool_Threads] = write_pool_threads,
109 [NFSD_Versions] = write_versions, 112 [NFSD_Versions] = write_versions,
@@ -329,6 +332,33 @@ static ssize_t failover_unlock_ip(struct file *file, char *buf, size_t size)
329 return nlmsvc_unlock_all_by_ip(server_ip); 332 return nlmsvc_unlock_all_by_ip(server_ip);
330} 333}
331 334
335static ssize_t failover_unlock_fs(struct file *file, char *buf, size_t size)
336{
337 struct nameidata nd;
338 char *fo_path;
339 int error;
340
341 /* sanity check */
342 if (size == 0)
343 return -EINVAL;
344
345 if (buf[size-1] != '\n')
346 return -EINVAL;
347
348 fo_path = buf;
349 if (qword_get(&buf, fo_path, size) < 0)
350 return -EINVAL;
351
352 error = path_lookup(fo_path, 0, &nd);
353 if (error)
354 return error;
355
356 error = nlmsvc_unlock_all_by_sb(nd.path.mnt->mnt_sb);
357
358 path_put(&nd.path);
359 return error;
360}
361
332static ssize_t write_filehandle(struct file *file, char *buf, size_t size) 362static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
333{ 363{
334 /* request is: 364 /* request is:
@@ -733,6 +763,8 @@ static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
733 [NFSD_List] = {"exports", &exports_operations, S_IRUGO}, 763 [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
734 [NFSD_FO_UnlockIP] = {"unlock_ip", 764 [NFSD_FO_UnlockIP] = {"unlock_ip",
735 &transaction_ops, S_IWUSR|S_IRUSR}, 765 &transaction_ops, S_IWUSR|S_IRUSR},
766 [NFSD_FO_UnlockFS] = {"unlock_filesystem",
767 &transaction_ops, S_IWUSR|S_IRUSR},
736 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR}, 768 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
737 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR}, 769 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
738 [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR}, 770 [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},