nfs4recover.c 30.2 KB
Newer Older
N
NeilBrown 已提交
1 2
/*
*  Copyright (c) 2004 The Regents of the University of Michigan.
3
*  Copyright (c) 2012 Jeff Layton <jlayton@redhat.com>
N
NeilBrown 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
*  All rights reserved.
*
*  Andy Adamson <andros@citi.umich.edu>
*
*  Redistribution and use in source and binary forms, with or without
*  modification, are permitted provided that the following conditions
*  are met:
*
*  1. Redistributions of source code must retain the above copyright
*     notice, this list of conditions and the following disclaimer.
*  2. Redistributions in binary form must reproduce the above copyright
*     notice, this list of conditions and the following disclaimer in the
*     documentation and/or other materials provided with the distribution.
*  3. Neither the name of the University nor the names of its
*     contributors may be used to endorse or promote products derived
*     from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
*  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
*  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
*  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
*  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
*  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
*  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
*  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
*  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

35
#include <linux/file.h>
36
#include <linux/slab.h>
37
#include <linux/namei.h>
N
NeilBrown 已提交
38
#include <linux/crypto.h>
A
Alexey Dobriyan 已提交
39
#include <linux/sched.h>
40
#include <linux/fs.h>
41
#include <linux/module.h>
42 43 44 45
#include <net/net_namespace.h>
#include <linux/sunrpc/rpc_pipe_fs.h>
#include <linux/sunrpc/clnt.h>
#include <linux/nfsd/cld.h>
46 47 48

#include "nfsd.h"
#include "state.h"
49
#include "vfs.h"
50
#include "netns.h"
N
NeilBrown 已提交
51 52 53

#define NFSDDBG_FACILITY                NFSDDBG_PROC

54 55 56 57 58 59 60 61 62 63
/* Declarations */
struct nfsd4_client_tracking_ops {
	int (*init)(struct net *);
	void (*exit)(struct net *);
	void (*create)(struct nfs4_client *);
	void (*remove)(struct nfs4_client *);
	int (*check)(struct nfs4_client *);
	void (*grace_done)(struct net *, time_t);
};

64
/* Globals */
65
static struct file *rec_file;
66
static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery";
67
static struct nfsd4_client_tracking_ops *client_tracking_ops;
68
static bool in_grace;
69

D
David Howells 已提交
70 71
static int
nfs4_save_creds(const struct cred **original_creds)
72
{
D
David Howells 已提交
73 74 75 76 77 78 79 80 81 82 83
	struct cred *new;

	new = prepare_creds();
	if (!new)
		return -ENOMEM;

	new->fsuid = 0;
	new->fsgid = 0;
	*original_creds = override_creds(new);
	put_cred(new);
	return 0;
84 85 86
}

static void
D
David Howells 已提交
87
nfs4_reset_creds(const struct cred *original)
88
{
D
David Howells 已提交
89
	revert_creds(original);
90 91
}

N
NeilBrown 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105
static void
md5_to_hex(char *out, char *md5)
{
	int i;

	for (i=0; i<16; i++) {
		unsigned char c = md5[i];

		*out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
		*out++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1);
	}
	*out = '\0';
}

J
Jeff Layton 已提交
106 107
static int
nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
N
NeilBrown 已提交
108 109
{
	struct xdr_netobj cksum;
110
	struct hash_desc desc;
J
Jens Axboe 已提交
111
	struct scatterlist sg;
J
Jeff Layton 已提交
112
	int status;
N
NeilBrown 已提交
113 114 115

	dprintk("NFSD: nfs4_make_rec_clidname for %.*s\n",
			clname->len, clname->data);
116 117
	desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
	desc.tfm = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC);
J
Jeff Layton 已提交
118 119
	if (IS_ERR(desc.tfm)) {
		status = PTR_ERR(desc.tfm);
120
		goto out_no_tfm;
J
Jeff Layton 已提交
121 122
	}

123
	cksum.len = crypto_hash_digestsize(desc.tfm);
N
NeilBrown 已提交
124
	cksum.data = kmalloc(cksum.len, GFP_KERNEL);
J
Jeff Layton 已提交
125 126
	if (cksum.data == NULL) {
		status = -ENOMEM;
N
NeilBrown 已提交
127
 		goto out;
J
Jeff Layton 已提交
128
	}
N
NeilBrown 已提交
129

J
Jens Axboe 已提交
130
	sg_init_one(&sg, clname->data, clname->len);
N
NeilBrown 已提交
131

J
Jeff Layton 已提交
132 133
	status = crypto_hash_digest(&desc, &sg, sg.length, cksum.data);
	if (status)
134
		goto out;
N
NeilBrown 已提交
135 136 137

	md5_to_hex(dname, cksum.data);

J
Jeff Layton 已提交
138
	status = 0;
N
NeilBrown 已提交
139
out:
140
	kfree(cksum.data);
141 142
	crypto_free_hash(desc.tfm);
out_no_tfm:
N
NeilBrown 已提交
143 144
	return status;
}
145

J
Jeff Layton 已提交
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
/*
 * If we had an error generating the recdir name for the legacy tracker
 * then warn the admin. If the error doesn't appear to be transient,
 * then disable recovery tracking.
 */
static void
legacy_recdir_name_error(int error)
{
	printk(KERN_ERR "NFSD: unable to generate recoverydir "
			"name (%d).\n", error);

	/*
	 * if the algorithm just doesn't exist, then disable the recovery
	 * tracker altogether. The crypto libs will generally return this if
	 * FIPS is enabled as well.
	 */
	if (error == -ENOENT) {
		printk(KERN_ERR "NFSD: disabling legacy clientid tracking. "
			"Reboot recovery will not function correctly!\n");

		/* the argument is ignored by the legacy exit function */
		nfsd4_client_tracking_exit(NULL);
	}
}

171 172
static void
nfsd4_create_clid_dir(struct nfs4_client *clp)
173
{
D
David Howells 已提交
174
	const struct cred *original_cred;
J
Jeff Layton 已提交
175
	char dname[HEXDIR_LEN];
176
	struct dentry *dir, *dentry;
177
	struct nfs4_client_reclaim *crp;
178 179 180 181
	int status;

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

182
	if (test_and_set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
183
		return;
184
	if (!rec_file)
185
		return;
J
Jeff Layton 已提交
186 187 188 189 190

	status = nfs4_make_rec_clidname(dname, &clp->cl_name);
	if (status)
		return legacy_recdir_name_error(status);

D
David Howells 已提交
191 192
	status = nfs4_save_creds(&original_cred);
	if (status < 0)
193
		return;
194

195 196 197 198
	status = mnt_want_write_file(rec_file);
	if (status)
		return;

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

203
	dentry = lookup_one_len(dname, dir, HEXDIR_LEN-1);
204 205 206 207
	if (IS_ERR(dentry)) {
		status = PTR_ERR(dentry);
		goto out_unlock;
	}
208
	if (dentry->d_inode)
209 210 211 212 213 214 215 216
		/*
		 * In the 4.1 case, where we're called from
		 * reclaim_complete(), records from the previous reboot
		 * may still be left, so this is OK.
		 *
		 * In the 4.0 case, we should never get here; but we may
		 * as well be forgiving and just succeed silently.
		 */
217
		goto out_put;
218
	status = vfs_mkdir(dir->d_inode, dentry, S_IRWXU);
219 220 221
out_put:
	dput(dentry);
out_unlock:
222
	mutex_unlock(&dir->d_inode->i_mutex);
223 224
	if (status == 0) {
		if (in_grace) {
J
Jeff Layton 已提交
225
			crp = nfs4_client_to_reclaim(dname);
226 227 228
			if (crp)
				crp->cr_clp = clp;
		}
229
		vfs_fsync(rec_file, 0);
230
	} else {
231 232 233 234
		printk(KERN_ERR "NFSD: failed to write recovery record"
				" (err %d); please check that %s exists"
				" and is writeable", status,
				user_recovery_dirname);
235
	}
236
	mnt_drop_write_file(rec_file);
D
David Howells 已提交
237
	nfs4_reset_creds(original_cred);
238 239
}

240 241
typedef int (recdir_func)(struct dentry *, struct dentry *);

242 243
struct name_list {
	char name[HEXDIR_LEN];
244 245 246 247
	struct list_head list;
};

static int
248
nfsd4_build_namelist(void *arg, const char *name, int namlen,
249
		loff_t offset, u64 ino, unsigned int d_type)
250
{
251 252
	struct list_head *names = arg;
	struct name_list *entry;
253

254
	if (namlen != HEXDIR_LEN - 1)
255
		return 0;
256 257
	entry = kmalloc(sizeof(struct name_list), GFP_KERNEL);
	if (entry == NULL)
258
		return -ENOMEM;
259 260 261
	memcpy(entry->name, name, HEXDIR_LEN - 1);
	entry->name[HEXDIR_LEN - 1] = '\0';
	list_add(&entry->list, names);
262 263 264 265
	return 0;
}

static int
266
nfsd4_list_rec_dir(recdir_func *f)
267
{
D
David Howells 已提交
268
	const struct cred *original_cred;
269
	struct dentry *dir = rec_file->f_path.dentry;
270
	LIST_HEAD(names);
271 272
	int status;

D
David Howells 已提交
273 274 275
	status = nfs4_save_creds(&original_cred);
	if (status < 0)
		return status;
276

277 278 279 280 281 282 283
	status = vfs_llseek(rec_file, 0, SEEK_SET);
	if (status < 0) {
		nfs4_reset_creds(original_cred);
		return status;
	}

	status = vfs_readdir(rec_file, nfsd4_build_namelist, &names);
J
J. Bruce Fields 已提交
284
	mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
285
	while (!list_empty(&names)) {
286
		struct name_list *entry;
287
		entry = list_entry(names.next, struct name_list, list);
288 289 290 291 292 293 294 295 296
		if (!status) {
			struct dentry *dentry;
			dentry = lookup_one_len(entry->name, dir, HEXDIR_LEN-1);
			if (IS_ERR(dentry)) {
				status = PTR_ERR(dentry);
				break;
			}
			status = f(dir, dentry);
			dput(dentry);
297 298 299
		}
		list_del(&entry->list);
		kfree(entry);
300
	}
301
	mutex_unlock(&dir->d_inode->i_mutex);
D
David Howells 已提交
302
	nfs4_reset_creds(original_cred);
303 304 305
	return status;
}

306 307 308
static int
nfsd4_unlink_clid_dir(char *name, int namlen)
{
309
	struct dentry *dir, *dentry;
310 311 312 313
	int status;

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

314 315 316
	dir = rec_file->f_path.dentry;
	mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
	dentry = lookup_one_len(name, dir, namlen);
317 318
	if (IS_ERR(dentry)) {
		status = PTR_ERR(dentry);
319
		goto out_unlock;
320 321 322 323
	}
	status = -ENOENT;
	if (!dentry->d_inode)
		goto out;
324
	status = vfs_rmdir(dir->d_inode, dentry);
325 326
out:
	dput(dentry);
327
out_unlock:
328
	mutex_unlock(&dir->d_inode->i_mutex);
329 330 331
	return status;
}

332
static void
333 334
nfsd4_remove_clid_dir(struct nfs4_client *clp)
{
D
David Howells 已提交
335
	const struct cred *original_cred;
336
	struct nfs4_client_reclaim *crp;
J
Jeff Layton 已提交
337
	char dname[HEXDIR_LEN];
338 339
	int status;

340
	if (!rec_file || !test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
341 342
		return;

J
Jeff Layton 已提交
343 344 345 346
	status = nfs4_make_rec_clidname(dname, &clp->cl_name);
	if (status)
		return legacy_recdir_name_error(status);

347
	status = mnt_want_write_file(rec_file);
348 349
	if (status)
		goto out;
350
	clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
D
David Howells 已提交
351 352 353

	status = nfs4_save_creds(&original_cred);
	if (status < 0)
354
		goto out_drop_write;
D
David Howells 已提交
355

J
Jeff Layton 已提交
356
	status = nfsd4_unlink_clid_dir(dname, HEXDIR_LEN-1);
D
David Howells 已提交
357
	nfs4_reset_creds(original_cred);
358
	if (status == 0) {
359
		vfs_fsync(rec_file, 0);
360 361
		if (in_grace) {
			/* remove reclaim record */
J
Jeff Layton 已提交
362
			crp = nfsd4_find_reclaim_client(dname);
363 364 365 366
			if (crp)
				nfs4_remove_reclaim_record(crp);
		}
	}
367
out_drop_write:
A
Al Viro 已提交
368
	mnt_drop_write_file(rec_file);
369
out:
370 371
	if (status)
		printk("NFSD: Failed to remove expired client state directory"
J
Jeff Layton 已提交
372
				" %.*s\n", HEXDIR_LEN, dname);
373 374 375 376 377 378 379
}

static int
purge_old(struct dentry *parent, struct dentry *child)
{
	int status;

380
	if (nfs4_has_reclaimed_state(child->d_name.name))
381
		return 0;
382

383
	status = vfs_rmdir(parent->d_inode, child);
384 385 386 387
	if (status)
		printk("failed to remove client recovery directory %s\n",
				child->d_name.name);
	/* Keep trying, success or failure: */
388
	return 0;
389 390
}

391 392 393
static void
nfsd4_recdir_purge_old(struct net *net, time_t boot_time)
{
394 395
	int status;

396
	in_grace = false;
397
	if (!rec_file)
398
		return;
399
	status = mnt_want_write_file(rec_file);
400 401
	if (status)
		goto out;
402
	status = nfsd4_list_rec_dir(purge_old);
403
	if (status == 0)
404
		vfs_fsync(rec_file, 0);
A
Al Viro 已提交
405
	mnt_drop_write_file(rec_file);
406
out:
407
	nfs4_release_reclaim();
408 409
	if (status)
		printk("nfsd4: failed to purge old clients from recovery"
410
			" directory %s\n", rec_file->f_path.dentry->d_name.name);
411 412
}

413 414 415 416 417 418 419
static int
load_recdir(struct dentry *parent, struct dentry *child)
{
	if (child->d_name.len != HEXDIR_LEN - 1) {
		printk("nfsd4: illegal name %s in recovery directory\n",
				child->d_name.name);
		/* Keep trying; maybe the others are OK: */
420
		return 0;
421 422
	}
	nfs4_client_to_reclaim(child->d_name.name);
423
	return 0;
424 425
}

426
static int
427 428 429
nfsd4_recdir_load(void) {
	int status;

430 431 432
	if (!rec_file)
		return 0;

433
	status = nfsd4_list_rec_dir(load_recdir);
434 435
	if (status)
		printk("nfsd4: failed loading clients from recovery"
436
			" directory %s\n", rec_file->f_path.dentry->d_name.name);
437 438 439 440 441 442 443
	return status;
}

/*
 * Hold reference to the recovery directory.
 */

444 445
static int
nfsd4_init_recdir(void)
446
{
D
David Howells 已提交
447 448
	const struct cred *original_cred;
	int status;
449 450

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

453
	BUG_ON(rec_file);
454

D
David Howells 已提交
455 456 457 458 459
	status = nfs4_save_creds(&original_cred);
	if (status < 0) {
		printk("NFSD: Unable to change credentials to find recovery"
		       " directory: error %d\n",
		       status);
460
		return status;
D
David Howells 已提交
461
	}
462

463
	rec_file = filp_open(user_recovery_dirname, O_RDONLY | O_DIRECTORY, 0);
464
	if (IS_ERR(rec_file)) {
465
		printk("NFSD: unable to find recovery directory %s\n",
466
				user_recovery_dirname);
467
		status = PTR_ERR(rec_file);
468 469
		rec_file = NULL;
	}
470

D
David Howells 已提交
471
	nfs4_reset_creds(original_cred);
472 473
	if (!status)
		in_grace = true;
474
	return status;
475 476
}

477 478 479 480 481
static int
nfsd4_load_reboot_recovery_data(struct net *net)
{
	int status;

482 483 484 485 486 487 488
	/* XXX: The legacy code won't work in a container */
	if (net != &init_net) {
		WARN(1, KERN_ERR "NFSD: attempt to initialize legacy client "
			"tracking in a container!\n");
		return -EINVAL;
	}

489 490 491 492 493 494 495 496 497 498 499
	nfs4_lock_state();
	status = nfsd4_init_recdir();
	if (!status)
		status = nfsd4_recdir_load();
	nfs4_unlock_state();
	if (status)
		printk(KERN_ERR "NFSD: Failure reading reboot recovery data\n");
	return status;
}

static void
500 501
nfsd4_shutdown_recdir(void)
{
502
	if (!rec_file)
503
		return;
504 505
	fput(rec_file);
	rec_file = NULL;
506
}
507

508 509 510 511 512 513 514
static void
nfsd4_legacy_tracking_exit(struct net *net)
{
	nfs4_release_reclaim();
	nfsd4_shutdown_recdir();
}

515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
/*
 * 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;
}
541 542 543 544

static int
nfsd4_check_legacy_client(struct nfs4_client *clp)
{
J
Jeff Layton 已提交
545 546
	int status;
	char dname[HEXDIR_LEN];
547 548
	struct nfs4_client_reclaim *crp;

549 550 551 552
	/* did we already find that this client is stable? */
	if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
		return 0;

J
Jeff Layton 已提交
553 554 555 556 557 558
	status = nfs4_make_rec_clidname(dname, &clp->cl_name);
	if (status) {
		legacy_recdir_name_error(status);
		return status;
	}

559
	/* look for it in the reclaim hashtable otherwise */
J
Jeff Layton 已提交
560
	crp = nfsd4_find_reclaim_client(dname);
561
	if (crp) {
562
		set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
563
		crp->cr_clp = clp;
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
		return 0;
	}

	return -ENOENT;
}

static struct nfsd4_client_tracking_ops nfsd4_legacy_tracking_ops = {
	.init		= nfsd4_load_reboot_recovery_data,
	.exit		= nfsd4_legacy_tracking_exit,
	.create		= nfsd4_create_clid_dir,
	.remove		= nfsd4_remove_clid_dir,
	.check		= nfsd4_check_legacy_client,
	.grace_done	= nfsd4_recdir_purge_old,
};

579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
/* Globals */
#define NFSD_PIPE_DIR		"nfsd"
#define NFSD_CLD_PIPE		"cld"

/* per-net-ns structure for holding cld upcall info */
struct cld_net {
	struct rpc_pipe		*cn_pipe;
	spinlock_t		 cn_lock;
	struct list_head	 cn_list;
	unsigned int		 cn_xid;
};

struct cld_upcall {
	struct list_head	 cu_list;
	struct cld_net		*cu_net;
	struct task_struct	*cu_task;
	struct cld_msg		 cu_msg;
};

static int
__cld_pipe_upcall(struct rpc_pipe *pipe, struct cld_msg *cmsg)
{
	int ret;
	struct rpc_pipe_msg msg;

	memset(&msg, 0, sizeof(msg));
	msg.data = cmsg;
	msg.len = sizeof(*cmsg);

	/*
	 * Set task state before we queue the upcall. That prevents
	 * wake_up_process in the downcall from racing with schedule.
	 */
	set_current_state(TASK_UNINTERRUPTIBLE);
	ret = rpc_queue_upcall(pipe, &msg);
	if (ret < 0) {
		set_current_state(TASK_RUNNING);
		goto out;
	}

	schedule();
	set_current_state(TASK_RUNNING);

	if (msg.errno < 0)
		ret = msg.errno;
out:
	return ret;
}

static int
cld_pipe_upcall(struct rpc_pipe *pipe, struct cld_msg *cmsg)
{
	int ret;

	/*
	 * -EAGAIN occurs when pipe is closed and reopened while there are
	 *  upcalls queued.
	 */
	do {
		ret = __cld_pipe_upcall(pipe, cmsg);
	} while (ret == -EAGAIN);

	return ret;
}

static ssize_t
cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
{
	struct cld_upcall *tmp, *cup;
648
	struct cld_msg __user *cmsg = (struct cld_msg __user *)src;
649 650 651 652 653 654
	uint32_t xid;
	struct nfsd_net *nn = net_generic(filp->f_dentry->d_sb->s_fs_info,
						nfsd_net_id);
	struct cld_net *cn = nn->cld_net;

	if (mlen != sizeof(*cmsg)) {
655
		dprintk("%s: got %zu bytes, expected %zu\n", __func__, mlen,
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
			sizeof(*cmsg));
		return -EINVAL;
	}

	/* copy just the xid so we can try to find that */
	if (copy_from_user(&xid, &cmsg->cm_xid, sizeof(xid)) != 0) {
		dprintk("%s: error when copying xid from userspace", __func__);
		return -EFAULT;
	}

	/* walk the list and find corresponding xid */
	cup = NULL;
	spin_lock(&cn->cn_lock);
	list_for_each_entry(tmp, &cn->cn_list, cu_list) {
		if (get_unaligned(&tmp->cu_msg.cm_xid) == xid) {
			cup = tmp;
			list_del_init(&cup->cu_list);
			break;
		}
	}
	spin_unlock(&cn->cn_lock);

	/* couldn't find upcall? */
	if (!cup) {
680
		dprintk("%s: couldn't find upcall -- xid=%u\n", __func__, xid);
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
		return -EINVAL;
	}

	if (copy_from_user(&cup->cu_msg, src, mlen) != 0)
		return -EFAULT;

	wake_up_process(cup->cu_task);
	return mlen;
}

static void
cld_pipe_destroy_msg(struct rpc_pipe_msg *msg)
{
	struct cld_msg *cmsg = msg->data;
	struct cld_upcall *cup = container_of(cmsg, struct cld_upcall,
						 cu_msg);

	/* errno >= 0 means we got a downcall */
	if (msg->errno >= 0)
		return;

	wake_up_process(cup->cu_task);
}

static const struct rpc_pipe_ops cld_upcall_ops = {
	.upcall		= rpc_pipe_generic_upcall,
	.downcall	= cld_pipe_downcall,
	.destroy_msg	= cld_pipe_destroy_msg,
};

static struct dentry *
nfsd4_cld_register_sb(struct super_block *sb, struct rpc_pipe *pipe)
{
	struct dentry *dir, *dentry;

	dir = rpc_d_lookup_sb(sb, NFSD_PIPE_DIR);
	if (dir == NULL)
		return ERR_PTR(-ENOENT);
	dentry = rpc_mkpipe_dentry(dir, NFSD_CLD_PIPE, NULL, pipe);
	dput(dir);
	return dentry;
}

static void
nfsd4_cld_unregister_sb(struct rpc_pipe *pipe)
{
	if (pipe->dentry)
		rpc_unlink(pipe->dentry);
}

static struct dentry *
nfsd4_cld_register_net(struct net *net, struct rpc_pipe *pipe)
{
	struct super_block *sb;
	struct dentry *dentry;

	sb = rpc_get_sb_net(net);
	if (!sb)
		return NULL;
	dentry = nfsd4_cld_register_sb(sb, pipe);
	rpc_put_sb_net(net);
	return dentry;
}

static void
nfsd4_cld_unregister_net(struct net *net, struct rpc_pipe *pipe)
{
	struct super_block *sb;

	sb = rpc_get_sb_net(net);
	if (sb) {
		nfsd4_cld_unregister_sb(pipe);
		rpc_put_sb_net(net);
	}
}

/* Initialize rpc_pipefs pipe for communication with client tracking daemon */
static int
nfsd4_init_cld_pipe(struct net *net)
{
	int ret;
	struct dentry *dentry;
	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
	struct cld_net *cn;

	if (nn->cld_net)
		return 0;

	cn = kzalloc(sizeof(*cn), GFP_KERNEL);
	if (!cn) {
		ret = -ENOMEM;
		goto err;
	}

	cn->cn_pipe = rpc_mkpipe_data(&cld_upcall_ops, RPC_PIPE_WAIT_FOR_OPEN);
	if (IS_ERR(cn->cn_pipe)) {
		ret = PTR_ERR(cn->cn_pipe);
		goto err;
	}
	spin_lock_init(&cn->cn_lock);
	INIT_LIST_HEAD(&cn->cn_list);

	dentry = nfsd4_cld_register_net(net, cn->cn_pipe);
	if (IS_ERR(dentry)) {
		ret = PTR_ERR(dentry);
		goto err_destroy_data;
	}

	cn->cn_pipe->dentry = dentry;
	nn->cld_net = cn;
	return 0;

err_destroy_data:
	rpc_destroy_pipe_data(cn->cn_pipe);
err:
	kfree(cn);
	printk(KERN_ERR "NFSD: unable to create nfsdcld upcall pipe (%d)\n",
			ret);
	return ret;
}

static void
nfsd4_remove_cld_pipe(struct net *net)
{
	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
	struct cld_net *cn = nn->cld_net;

	nfsd4_cld_unregister_net(net, cn->cn_pipe);
	rpc_destroy_pipe_data(cn->cn_pipe);
	kfree(nn->cld_net);
	nn->cld_net = NULL;
}

static struct cld_upcall *
alloc_cld_upcall(struct cld_net *cn)
{
	struct cld_upcall *new, *tmp;

	new = kzalloc(sizeof(*new), GFP_KERNEL);
	if (!new)
		return new;

	/* FIXME: hard cap on number in flight? */
restart_search:
	spin_lock(&cn->cn_lock);
	list_for_each_entry(tmp, &cn->cn_list, cu_list) {
		if (tmp->cu_msg.cm_xid == cn->cn_xid) {
			cn->cn_xid++;
			spin_unlock(&cn->cn_lock);
			goto restart_search;
		}
	}
	new->cu_task = current;
	new->cu_msg.cm_vers = CLD_UPCALL_VERSION;
	put_unaligned(cn->cn_xid++, &new->cu_msg.cm_xid);
	new->cu_net = cn;
	list_add(&new->cu_list, &cn->cn_list);
	spin_unlock(&cn->cn_lock);

	dprintk("%s: allocated xid %u\n", __func__, new->cu_msg.cm_xid);

	return new;
}

static void
free_cld_upcall(struct cld_upcall *victim)
{
	struct cld_net *cn = victim->cu_net;

	spin_lock(&cn->cn_lock);
	list_del(&victim->cu_list);
	spin_unlock(&cn->cn_lock);
	kfree(victim);
}

/* Ask daemon to create a new record */
static void
nfsd4_cld_create(struct nfs4_client *clp)
{
	int ret;
	struct cld_upcall *cup;
862
	struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
	struct cld_net *cn = nn->cld_net;

	/* Don't upcall if it's already stored */
	if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
		return;

	cup = alloc_cld_upcall(cn);
	if (!cup) {
		ret = -ENOMEM;
		goto out_err;
	}

	cup->cu_msg.cm_cmd = Cld_Create;
	cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
	memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
			clp->cl_name.len);

	ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
	if (!ret) {
		ret = cup->cu_msg.cm_status;
		set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
	}

	free_cld_upcall(cup);
out_err:
	if (ret)
		printk(KERN_ERR "NFSD: Unable to create client "
				"record on stable storage: %d\n", ret);
}

/* Ask daemon to create a new record */
static void
nfsd4_cld_remove(struct nfs4_client *clp)
{
	int ret;
	struct cld_upcall *cup;
899
	struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935
	struct cld_net *cn = nn->cld_net;

	/* Don't upcall if it's already removed */
	if (!test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
		return;

	cup = alloc_cld_upcall(cn);
	if (!cup) {
		ret = -ENOMEM;
		goto out_err;
	}

	cup->cu_msg.cm_cmd = Cld_Remove;
	cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
	memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
			clp->cl_name.len);

	ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
	if (!ret) {
		ret = cup->cu_msg.cm_status;
		clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
	}

	free_cld_upcall(cup);
out_err:
	if (ret)
		printk(KERN_ERR "NFSD: Unable to remove client "
				"record from stable storage: %d\n", ret);
}

/* Check for presence of a record, and update its timestamp */
static int
nfsd4_cld_check(struct nfs4_client *clp)
{
	int ret;
	struct cld_upcall *cup;
936
	struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999
	struct cld_net *cn = nn->cld_net;

	/* Don't upcall if one was already stored during this grace pd */
	if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
		return 0;

	cup = alloc_cld_upcall(cn);
	if (!cup) {
		printk(KERN_ERR "NFSD: Unable to check client record on "
				"stable storage: %d\n", -ENOMEM);
		return -ENOMEM;
	}

	cup->cu_msg.cm_cmd = Cld_Check;
	cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
	memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
			clp->cl_name.len);

	ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
	if (!ret) {
		ret = cup->cu_msg.cm_status;
		set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
	}

	free_cld_upcall(cup);
	return ret;
}

static void
nfsd4_cld_grace_done(struct net *net, time_t boot_time)
{
	int ret;
	struct cld_upcall *cup;
	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
	struct cld_net *cn = nn->cld_net;

	cup = alloc_cld_upcall(cn);
	if (!cup) {
		ret = -ENOMEM;
		goto out_err;
	}

	cup->cu_msg.cm_cmd = Cld_GraceDone;
	cup->cu_msg.cm_u.cm_gracetime = (int64_t)boot_time;
	ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
	if (!ret)
		ret = cup->cu_msg.cm_status;

	free_cld_upcall(cup);
out_err:
	if (ret)
		printk(KERN_ERR "NFSD: Unable to end grace period: %d\n", ret);
}

static struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops = {
	.init		= nfsd4_init_cld_pipe,
	.exit		= nfsd4_remove_cld_pipe,
	.create		= nfsd4_cld_create,
	.remove		= nfsd4_cld_remove,
	.check		= nfsd4_cld_check,
	.grace_done	= nfsd4_cld_grace_done,
};

1000 1001 1002 1003 1004 1005
/* upcall via usermodehelper */
static char cltrack_prog[PATH_MAX] = "/sbin/nfsdcltrack";
module_param_string(cltrack_prog, cltrack_prog, sizeof(cltrack_prog),
			S_IRUGO|S_IWUSR);
MODULE_PARM_DESC(cltrack_prog, "Path to the nfsdcltrack upcall program");

1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
static bool cltrack_legacy_disable;
module_param(cltrack_legacy_disable, bool, S_IRUGO|S_IWUSR);
MODULE_PARM_DESC(cltrack_legacy_disable,
		"Disable legacy recoverydir conversion. Default: false");

#define LEGACY_TOPDIR_ENV_PREFIX "NFSDCLTRACK_LEGACY_TOPDIR="
#define LEGACY_RECDIR_ENV_PREFIX "NFSDCLTRACK_LEGACY_RECDIR="

static char *
nfsd4_cltrack_legacy_topdir(void)
{
	int copied;
	size_t len;
	char *result;

	if (cltrack_legacy_disable)
		return NULL;

	len = strlen(LEGACY_TOPDIR_ENV_PREFIX) +
		strlen(nfs4_recoverydir()) + 1;

	result = kmalloc(len, GFP_KERNEL);
	if (!result)
		return result;

	copied = snprintf(result, len, LEGACY_TOPDIR_ENV_PREFIX "%s",
				nfs4_recoverydir());
	if (copied >= len) {
		/* just return nothing if output was truncated */
		kfree(result);
		return NULL;
	}

	return result;
}

static char *
J
Jeff Layton 已提交
1043
nfsd4_cltrack_legacy_recdir(const struct xdr_netobj *name)
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
{
	int copied;
	size_t len;
	char *result;

	if (cltrack_legacy_disable)
		return NULL;

	/* +1 is for '/' between "topdir" and "recdir" */
	len = strlen(LEGACY_RECDIR_ENV_PREFIX) +
		strlen(nfs4_recoverydir()) + 1 + HEXDIR_LEN;

	result = kmalloc(len, GFP_KERNEL);
	if (!result)
		return result;

J
Jeff Layton 已提交
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
	copied = snprintf(result, len, LEGACY_RECDIR_ENV_PREFIX "%s/",
				nfs4_recoverydir());
	if (copied > (len - HEXDIR_LEN)) {
		/* just return nothing if output will be truncated */
		kfree(result);
		return NULL;
	}

	copied = nfs4_make_rec_clidname(result + copied, name);
	if (copied) {
1070 1071 1072 1073 1074 1075 1076
		kfree(result);
		return NULL;
	}

	return result;
}

1077
static int
1078
nfsd4_umh_cltrack_upcall(char *cmd, char *arg, char *legacy)
1079
{
1080
	char *envp[2];
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
	char *argv[4];
	int ret;

	if (unlikely(!cltrack_prog[0])) {
		dprintk("%s: cltrack_prog is disabled\n", __func__);
		return -EACCES;
	}

	dprintk("%s: cmd: %s\n", __func__, cmd);
	dprintk("%s: arg: %s\n", __func__, arg ? arg : "(null)");
1091 1092 1093 1094
	dprintk("%s: legacy: %s\n", __func__, legacy ? legacy : "(null)");

	envp[0] = legacy;
	envp[1] = NULL;
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139

	argv[0] = (char *)cltrack_prog;
	argv[1] = cmd;
	argv[2] = arg;
	argv[3] = NULL;

	ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
	/*
	 * Disable the upcall mechanism if we're getting an ENOENT or EACCES
	 * error. The admin can re-enable it on the fly by using sysfs
	 * once the problem has been fixed.
	 */
	if (ret == -ENOENT || ret == -EACCES) {
		dprintk("NFSD: %s was not found or isn't executable (%d). "
			"Setting cltrack_prog to blank string!",
			cltrack_prog, ret);
		cltrack_prog[0] = '\0';
	}
	dprintk("%s: %s return value: %d\n", __func__, cltrack_prog, ret);

	return ret;
}

static char *
bin_to_hex_dup(const unsigned char *src, int srclen)
{
	int i;
	char *buf, *hex;

	/* +1 for terminating NULL */
	buf = kmalloc((srclen * 2) + 1, GFP_KERNEL);
	if (!buf)
		return buf;

	hex = buf;
	for (i = 0; i < srclen; i++) {
		sprintf(hex, "%2.2x", *src++);
		hex += 2;
	}
	return buf;
}

static int
nfsd4_umh_cltrack_init(struct net __attribute__((unused)) *net)
{
1140
	return nfsd4_umh_cltrack_upcall("init", NULL, NULL);
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
}

static void
nfsd4_umh_cltrack_create(struct nfs4_client *clp)
{
	char *hexid;

	hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
	if (!hexid) {
		dprintk("%s: can't allocate memory for upcall!\n", __func__);
		return;
	}
1153
	nfsd4_umh_cltrack_upcall("create", hexid, NULL);
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
	kfree(hexid);
}

static void
nfsd4_umh_cltrack_remove(struct nfs4_client *clp)
{
	char *hexid;

	hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
	if (!hexid) {
		dprintk("%s: can't allocate memory for upcall!\n", __func__);
		return;
	}
1167
	nfsd4_umh_cltrack_upcall("remove", hexid, NULL);
1168 1169 1170 1171 1172 1173 1174
	kfree(hexid);
}

static int
nfsd4_umh_cltrack_check(struct nfs4_client *clp)
{
	int ret;
1175
	char *hexid, *legacy;
1176 1177 1178 1179 1180 1181

	hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
	if (!hexid) {
		dprintk("%s: can't allocate memory for upcall!\n", __func__);
		return -ENOMEM;
	}
J
Jeff Layton 已提交
1182
	legacy = nfsd4_cltrack_legacy_recdir(&clp->cl_name);
1183 1184
	ret = nfsd4_umh_cltrack_upcall("check", hexid, legacy);
	kfree(legacy);
1185 1186 1187 1188 1189 1190 1191 1192
	kfree(hexid);
	return ret;
}

static void
nfsd4_umh_cltrack_grace_done(struct net __attribute__((unused)) *net,
				time_t boot_time)
{
1193
	char *legacy;
1194 1195 1196
	char timestr[22]; /* FIXME: better way to determine max size? */

	sprintf(timestr, "%ld", boot_time);
1197 1198 1199
	legacy = nfsd4_cltrack_legacy_topdir();
	nfsd4_umh_cltrack_upcall("gracedone", timestr, legacy);
	kfree(legacy);
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
}

static struct nfsd4_client_tracking_ops nfsd4_umh_tracking_ops = {
	.init		= nfsd4_umh_cltrack_init,
	.exit		= NULL,
	.create		= nfsd4_umh_cltrack_create,
	.remove		= nfsd4_umh_cltrack_remove,
	.check		= nfsd4_umh_cltrack_check,
	.grace_done	= nfsd4_umh_cltrack_grace_done,
};

1211 1212 1213 1214
int
nfsd4_client_tracking_init(struct net *net)
{
	int status;
1215
	struct path path;
1216

1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
	/* just run the init if it the method is already decided */
	if (client_tracking_ops)
		goto do_init;

	/*
	 * First, try a UMH upcall. It should succeed or fail quickly, so
	 * there's little harm in trying that first.
	 */
	client_tracking_ops = &nfsd4_umh_tracking_ops;
	status = client_tracking_ops->init(net);
	if (!status)
		return status;

	/*
	 * See if the recoverydir exists and is a directory. If it is,
	 * then use the legacy ops.
	 */
	client_tracking_ops = &nfsd4_legacy_tracking_ops;
	status = kern_path(nfs4_recoverydir(), LOOKUP_FOLLOW, &path);
	if (!status) {
		status = S_ISDIR(path.dentry->d_inode->i_mode);
		path_put(&path);
		if (status)
			goto do_init;
1241
	}
1242

1243 1244
	/* Finally, try to use nfsdcld */
	client_tracking_ops = &nfsd4_cld_tracking_ops;
1245 1246 1247
	printk(KERN_WARNING "NFSD: the nfsdcld client tracking upcall will be "
			"removed in 3.10. Please transition to using "
			"nfsdcltrack.\n");
1248
do_init:
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261
	status = client_tracking_ops->init(net);
	if (status) {
		printk(KERN_WARNING "NFSD: Unable to initialize client "
				    "recovery tracking! (%d)\n", status);
		client_tracking_ops = NULL;
	}
	return status;
}

void
nfsd4_client_tracking_exit(struct net *net)
{
	if (client_tracking_ops) {
1262 1263
		if (client_tracking_ops->exit)
			client_tracking_ops->exit(net);
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296
		client_tracking_ops = NULL;
	}
}

void
nfsd4_client_record_create(struct nfs4_client *clp)
{
	if (client_tracking_ops)
		client_tracking_ops->create(clp);
}

void
nfsd4_client_record_remove(struct nfs4_client *clp)
{
	if (client_tracking_ops)
		client_tracking_ops->remove(clp);
}

int
nfsd4_client_record_check(struct nfs4_client *clp)
{
	if (client_tracking_ops)
		return client_tracking_ops->check(clp);

	return -EOPNOTSUPP;
}

void
nfsd4_record_grace_done(struct net *net, time_t boot_time)
{
	if (client_tracking_ops)
		client_tracking_ops->grace_done(net, boot_time);
}
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336

static int
rpc_pipefs_event(struct notifier_block *nb, unsigned long event, void *ptr)
{
	struct super_block *sb = ptr;
	struct net *net = sb->s_fs_info;
	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
	struct cld_net *cn = nn->cld_net;
	struct dentry *dentry;
	int ret = 0;

	if (!try_module_get(THIS_MODULE))
		return 0;

	if (!cn) {
		module_put(THIS_MODULE);
		return 0;
	}

	switch (event) {
	case RPC_PIPEFS_MOUNT:
		dentry = nfsd4_cld_register_sb(sb, cn->cn_pipe);
		if (IS_ERR(dentry)) {
			ret = PTR_ERR(dentry);
			break;
		}
		cn->cn_pipe->dentry = dentry;
		break;
	case RPC_PIPEFS_UMOUNT:
		if (cn->cn_pipe->dentry)
			nfsd4_cld_unregister_sb(cn->cn_pipe);
		break;
	default:
		ret = -ENOTSUPP;
		break;
	}
	module_put(THIS_MODULE);
	return ret;
}

J
J. Bruce Fields 已提交
1337
static struct notifier_block nfsd4_cld_block = {
1338 1339
	.notifier_call = rpc_pipefs_event,
};
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351

int
register_cld_notifier(void)
{
	return rpc_pipefs_notifier_register(&nfsd4_cld_block);
}

void
unregister_cld_notifier(void)
{
	rpc_pipefs_notifier_unregister(&nfsd4_cld_block);
}