2 * Copyright (c) 2004 The Regents of the University of Michigan.
3 * Copyright (c) 2012 Jeff Layton <jlayton@redhat.com>
6 * Andy Adamson <andros@citi.umich.edu>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <crypto/hash.h>
36 #include <linux/file.h>
37 #include <linux/slab.h>
38 #include <linux/namei.h>
39 #include <linux/sched.h>
41 #include <linux/module.h>
42 #include <net/net_namespace.h>
43 #include <linux/sunrpc/rpc_pipe_fs.h>
44 #include <linux/sunrpc/clnt.h>
45 #include <linux/nfsd/cld.h>
52 #define NFSDDBG_FACILITY NFSDDBG_PROC
55 struct nfsd4_client_tracking_ops {
56 int (*init)(struct net *);
57 void (*exit)(struct net *);
58 void (*create)(struct nfs4_client *);
59 void (*remove)(struct nfs4_client *);
60 int (*check)(struct nfs4_client *);
61 void (*grace_done)(struct nfsd_net *);
65 static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery";
68 nfs4_save_creds(const struct cred **original_creds)
72 new = prepare_creds();
76 new->fsuid = GLOBAL_ROOT_UID;
77 new->fsgid = GLOBAL_ROOT_GID;
78 *original_creds = override_creds(new);
84 nfs4_reset_creds(const struct cred *original)
86 revert_creds(original);
90 md5_to_hex(char *out, char *md5)
94 for (i=0; i<16; i++) {
95 unsigned char c = md5[i];
97 *out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
98 *out++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1);
104 nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
106 struct xdr_netobj cksum;
107 struct crypto_shash *tfm;
110 dprintk("NFSD: nfs4_make_rec_clidname for %.*s\n",
111 clname->len, clname->data);
112 tfm = crypto_alloc_shash("md5", 0, 0);
114 status = PTR_ERR(tfm);
118 cksum.len = crypto_shash_digestsize(tfm);
119 cksum.data = kmalloc(cksum.len, GFP_KERNEL);
120 if (cksum.data == NULL) {
126 SHASH_DESC_ON_STACK(desc, tfm);
130 status = crypto_shash_digest(desc, clname->data, clname->len,
132 shash_desc_zero(desc);
138 md5_to_hex(dname, cksum.data);
143 crypto_free_shash(tfm);
149 * If we had an error generating the recdir name for the legacy tracker
150 * then warn the admin. If the error doesn't appear to be transient,
151 * then disable recovery tracking.
154 legacy_recdir_name_error(struct nfs4_client *clp, int error)
156 printk(KERN_ERR "NFSD: unable to generate recoverydir "
157 "name (%d).\n", error);
160 * if the algorithm just doesn't exist, then disable the recovery
161 * tracker altogether. The crypto libs will generally return this if
162 * FIPS is enabled as well.
164 if (error == -ENOENT) {
165 printk(KERN_ERR "NFSD: disabling legacy clientid tracking. "
166 "Reboot recovery will not function correctly!\n");
167 nfsd4_client_tracking_exit(clp->net);
172 __nfsd4_create_reclaim_record_grace(struct nfs4_client *clp,
173 const char *dname, int len, struct nfsd_net *nn)
175 struct xdr_netobj name;
176 struct nfs4_client_reclaim *crp;
178 name.data = kmemdup(dname, len, GFP_KERNEL);
180 dprintk("%s: failed to allocate memory for name.data!\n",
185 crp = nfs4_client_to_reclaim(name, nn);
194 nfsd4_create_clid_dir(struct nfs4_client *clp)
196 const struct cred *original_cred;
197 char dname[HEXDIR_LEN];
198 struct dentry *dir, *dentry;
200 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
202 if (test_and_set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
207 status = nfs4_make_rec_clidname(dname, &clp->cl_name);
209 return legacy_recdir_name_error(clp, status);
211 status = nfs4_save_creds(&original_cred);
215 status = mnt_want_write_file(nn->rec_file);
219 dir = nn->rec_file->f_path.dentry;
220 /* lock the parent */
221 inode_lock(d_inode(dir));
223 dentry = lookup_one_len(dname, dir, HEXDIR_LEN-1);
224 if (IS_ERR(dentry)) {
225 status = PTR_ERR(dentry);
228 if (d_really_is_positive(dentry))
230 * In the 4.1 case, where we're called from
231 * reclaim_complete(), records from the previous reboot
232 * may still be left, so this is OK.
234 * In the 4.0 case, we should never get here; but we may
235 * as well be forgiving and just succeed silently.
238 status = vfs_mkdir(d_inode(dir), dentry, S_IRWXU);
242 inode_unlock(d_inode(dir));
245 __nfsd4_create_reclaim_record_grace(clp, dname,
247 vfs_fsync(nn->rec_file, 0);
249 printk(KERN_ERR "NFSD: failed to write recovery record"
250 " (err %d); please check that %s exists"
251 " and is writeable", status,
252 user_recovery_dirname);
254 mnt_drop_write_file(nn->rec_file);
256 nfs4_reset_creds(original_cred);
259 typedef int (recdir_func)(struct dentry *, struct dentry *, struct nfsd_net *);
262 char name[HEXDIR_LEN];
263 struct list_head list;
266 struct nfs4_dir_ctx {
267 struct dir_context ctx;
268 struct list_head names;
272 nfsd4_build_namelist(struct dir_context *__ctx, const char *name, int namlen,
273 loff_t offset, u64 ino, unsigned int d_type)
275 struct nfs4_dir_ctx *ctx =
276 container_of(__ctx, struct nfs4_dir_ctx, ctx);
277 struct name_list *entry;
279 if (namlen != HEXDIR_LEN - 1)
281 entry = kmalloc(sizeof(struct name_list), GFP_KERNEL);
284 memcpy(entry->name, name, HEXDIR_LEN - 1);
285 entry->name[HEXDIR_LEN - 1] = '\0';
286 list_add(&entry->list, &ctx->names);
291 nfsd4_list_rec_dir(recdir_func *f, struct nfsd_net *nn)
293 const struct cred *original_cred;
294 struct dentry *dir = nn->rec_file->f_path.dentry;
295 struct nfs4_dir_ctx ctx = {
296 .ctx.actor = nfsd4_build_namelist,
297 .names = LIST_HEAD_INIT(ctx.names)
299 struct name_list *entry, *tmp;
302 status = nfs4_save_creds(&original_cred);
306 status = vfs_llseek(nn->rec_file, 0, SEEK_SET);
308 nfs4_reset_creds(original_cred);
312 status = iterate_dir(nn->rec_file, &ctx.ctx);
313 inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);
315 list_for_each_entry_safe(entry, tmp, &ctx.names, list) {
317 struct dentry *dentry;
318 dentry = lookup_one_len(entry->name, dir, HEXDIR_LEN-1);
319 if (IS_ERR(dentry)) {
320 status = PTR_ERR(dentry);
323 status = f(dir, dentry, nn);
326 list_del(&entry->list);
329 inode_unlock(d_inode(dir));
330 nfs4_reset_creds(original_cred);
332 list_for_each_entry_safe(entry, tmp, &ctx.names, list) {
333 dprintk("NFSD: %s. Left entry %s\n", __func__, entry->name);
334 list_del(&entry->list);
341 nfsd4_unlink_clid_dir(char *name, int namlen, struct nfsd_net *nn)
343 struct dentry *dir, *dentry;
346 dprintk("NFSD: nfsd4_unlink_clid_dir. name %.*s\n", namlen, name);
348 dir = nn->rec_file->f_path.dentry;
349 inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);
350 dentry = lookup_one_len(name, dir, namlen);
351 if (IS_ERR(dentry)) {
352 status = PTR_ERR(dentry);
356 if (d_really_is_negative(dentry))
358 status = vfs_rmdir(d_inode(dir), dentry);
362 inode_unlock(d_inode(dir));
367 __nfsd4_remove_reclaim_record_grace(const char *dname, int len,
370 struct xdr_netobj name;
371 struct nfs4_client_reclaim *crp;
373 name.data = kmemdup(dname, len, GFP_KERNEL);
375 dprintk("%s: failed to allocate memory for name.data!\n",
380 crp = nfsd4_find_reclaim_client(name, nn);
383 nfs4_remove_reclaim_record(crp, nn);
387 nfsd4_remove_clid_dir(struct nfs4_client *clp)
389 const struct cred *original_cred;
390 char dname[HEXDIR_LEN];
392 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
394 if (!nn->rec_file || !test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
397 status = nfs4_make_rec_clidname(dname, &clp->cl_name);
399 return legacy_recdir_name_error(clp, status);
401 status = mnt_want_write_file(nn->rec_file);
404 clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
406 status = nfs4_save_creds(&original_cred);
410 status = nfsd4_unlink_clid_dir(dname, HEXDIR_LEN-1, nn);
411 nfs4_reset_creds(original_cred);
413 vfs_fsync(nn->rec_file, 0);
415 __nfsd4_remove_reclaim_record_grace(dname,
419 mnt_drop_write_file(nn->rec_file);
422 printk("NFSD: Failed to remove expired client state directory"
423 " %.*s\n", HEXDIR_LEN, dname);
427 purge_old(struct dentry *parent, struct dentry *child, struct nfsd_net *nn)
430 struct xdr_netobj name;
432 if (child->d_name.len != HEXDIR_LEN - 1) {
433 printk("%s: illegal name %pd in recovery directory\n",
435 /* Keep trying; maybe the others are OK: */
438 name.data = kmemdup_nul(child->d_name.name, child->d_name.len, GFP_KERNEL);
440 dprintk("%s: failed to allocate memory for name.data!\n",
444 name.len = HEXDIR_LEN;
445 if (nfs4_has_reclaimed_state(name, nn))
448 status = vfs_rmdir(d_inode(parent), child);
450 printk("failed to remove client recovery directory %pd\n",
455 /* Keep trying, success or failure: */
460 nfsd4_recdir_purge_old(struct nfsd_net *nn)
464 nn->in_grace = false;
467 status = mnt_want_write_file(nn->rec_file);
470 status = nfsd4_list_rec_dir(purge_old, nn);
472 vfs_fsync(nn->rec_file, 0);
473 mnt_drop_write_file(nn->rec_file);
475 nfs4_release_reclaim(nn);
477 printk("nfsd4: failed to purge old clients from recovery"
478 " directory %pD\n", nn->rec_file);
482 load_recdir(struct dentry *parent, struct dentry *child, struct nfsd_net *nn)
484 struct xdr_netobj name;
486 if (child->d_name.len != HEXDIR_LEN - 1) {
487 printk("%s: illegal name %pd in recovery directory\n",
489 /* Keep trying; maybe the others are OK: */
492 name.data = kmemdup_nul(child->d_name.name, child->d_name.len, GFP_KERNEL);
494 dprintk("%s: failed to allocate memory for name.data!\n",
498 name.len = HEXDIR_LEN;
499 if (!nfs4_client_to_reclaim(name, nn))
506 nfsd4_recdir_load(struct net *net) {
508 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
513 status = nfsd4_list_rec_dir(load_recdir, nn);
515 printk("nfsd4: failed loading clients from recovery"
516 " directory %pD\n", nn->rec_file);
521 * Hold reference to the recovery directory.
525 nfsd4_init_recdir(struct net *net)
527 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
528 const struct cred *original_cred;
531 printk("NFSD: Using %s as the NFSv4 state recovery directory\n",
532 user_recovery_dirname);
534 BUG_ON(nn->rec_file);
536 status = nfs4_save_creds(&original_cred);
538 printk("NFSD: Unable to change credentials to find recovery"
539 " directory: error %d\n",
544 nn->rec_file = filp_open(user_recovery_dirname, O_RDONLY | O_DIRECTORY, 0);
545 if (IS_ERR(nn->rec_file)) {
546 printk("NFSD: unable to find recovery directory %s\n",
547 user_recovery_dirname);
548 status = PTR_ERR(nn->rec_file);
552 nfs4_reset_creds(original_cred);
559 nfsd4_shutdown_recdir(struct net *net)
561 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
570 nfs4_legacy_state_init(struct net *net)
572 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
575 nn->reclaim_str_hashtbl = kmalloc_array(CLIENT_HASH_SIZE,
576 sizeof(struct list_head),
578 if (!nn->reclaim_str_hashtbl)
581 for (i = 0; i < CLIENT_HASH_SIZE; i++)
582 INIT_LIST_HEAD(&nn->reclaim_str_hashtbl[i]);
583 nn->reclaim_str_hashtbl_size = 0;
589 nfs4_legacy_state_shutdown(struct net *net)
591 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
593 kfree(nn->reclaim_str_hashtbl);
597 nfsd4_load_reboot_recovery_data(struct net *net)
601 status = nfsd4_init_recdir(net);
605 status = nfsd4_recdir_load(net);
607 nfsd4_shutdown_recdir(net);
613 nfsd4_legacy_tracking_init(struct net *net)
617 /* XXX: The legacy code won't work in a container */
618 if (net != &init_net) {
619 pr_warn("NFSD: attempt to initialize legacy client tracking in a container ignored.\n");
623 status = nfs4_legacy_state_init(net);
627 status = nfsd4_load_reboot_recovery_data(net);
630 printk("NFSD: Using legacy client tracking operations.\n");
634 nfs4_legacy_state_shutdown(net);
639 nfsd4_legacy_tracking_exit(struct net *net)
641 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
643 nfs4_release_reclaim(nn);
644 nfsd4_shutdown_recdir(net);
645 nfs4_legacy_state_shutdown(net);
649 * Change the NFSv4 recovery directory to recdir.
652 nfs4_reset_recoverydir(char *recdir)
657 status = kern_path(recdir, LOOKUP_FOLLOW, &path);
661 if (d_is_dir(path.dentry)) {
662 strcpy(user_recovery_dirname, recdir);
670 nfs4_recoverydir(void)
672 return user_recovery_dirname;
676 nfsd4_check_legacy_client(struct nfs4_client *clp)
679 char dname[HEXDIR_LEN];
680 struct nfs4_client_reclaim *crp;
681 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
682 struct xdr_netobj name;
684 /* did we already find that this client is stable? */
685 if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
688 status = nfs4_make_rec_clidname(dname, &clp->cl_name);
690 legacy_recdir_name_error(clp, status);
694 /* look for it in the reclaim hashtable otherwise */
695 name.data = kmemdup(dname, HEXDIR_LEN, GFP_KERNEL);
697 dprintk("%s: failed to allocate memory for name.data!\n",
701 name.len = HEXDIR_LEN;
702 crp = nfsd4_find_reclaim_client(name, nn);
705 set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
714 static const struct nfsd4_client_tracking_ops nfsd4_legacy_tracking_ops = {
715 .init = nfsd4_legacy_tracking_init,
716 .exit = nfsd4_legacy_tracking_exit,
717 .create = nfsd4_create_clid_dir,
718 .remove = nfsd4_remove_clid_dir,
719 .check = nfsd4_check_legacy_client,
720 .grace_done = nfsd4_recdir_purge_old,
724 #define NFSD_PIPE_DIR "nfsd"
725 #define NFSD_CLD_PIPE "cld"
727 /* per-net-ns structure for holding cld upcall info */
729 struct rpc_pipe *cn_pipe;
731 struct list_head cn_list;
737 struct list_head cu_list;
738 struct cld_net *cu_net;
739 struct completion cu_done;
740 struct cld_msg cu_msg;
744 __cld_pipe_upcall(struct rpc_pipe *pipe, struct cld_msg *cmsg)
747 struct rpc_pipe_msg msg;
748 struct cld_upcall *cup = container_of(cmsg, struct cld_upcall, cu_msg);
750 memset(&msg, 0, sizeof(msg));
752 msg.len = sizeof(*cmsg);
754 ret = rpc_queue_upcall(pipe, &msg);
759 wait_for_completion(&cup->cu_done);
768 cld_pipe_upcall(struct rpc_pipe *pipe, struct cld_msg *cmsg)
773 * -EAGAIN occurs when pipe is closed and reopened while there are
777 ret = __cld_pipe_upcall(pipe, cmsg);
778 } while (ret == -EAGAIN);
784 __cld_pipe_inprogress_downcall(const struct cld_msg __user *cmsg,
788 struct xdr_netobj name;
790 struct cld_net *cn = nn->cld_net;
792 if (get_user(cmd, &cmsg->cm_cmd)) {
793 dprintk("%s: error when copying cmd from userspace", __func__);
796 if (cmd == Cld_GraceStart) {
797 if (get_user(namelen, &cmsg->cm_u.cm_name.cn_len))
799 name.data = memdup_user(&cmsg->cm_u.cm_name.cn_id, namelen);
800 if (IS_ERR_OR_NULL(name.data))
803 if (name.len > 5 && memcmp(name.data, "hash:", 5) == 0) {
804 name.len = name.len - 5;
805 memmove(name.data, name.data + 5, name.len);
806 cn->cn_has_legacy = true;
808 if (!nfs4_client_to_reclaim(name, nn)) {
812 return sizeof(*cmsg);
818 cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
820 struct cld_upcall *tmp, *cup;
821 struct cld_msg __user *cmsg = (struct cld_msg __user *)src;
823 struct nfsd_net *nn = net_generic(file_inode(filp)->i_sb->s_fs_info,
825 struct cld_net *cn = nn->cld_net;
828 if (mlen != sizeof(*cmsg)) {
829 dprintk("%s: got %zu bytes, expected %zu\n", __func__, mlen,
834 /* copy just the xid so we can try to find that */
835 if (copy_from_user(&xid, &cmsg->cm_xid, sizeof(xid)) != 0) {
836 dprintk("%s: error when copying xid from userspace", __func__);
841 * copy the status so we know whether to remove the upcall from the
842 * list (for -EINPROGRESS, we just want to make sure the xid is
843 * valid, not remove the upcall from the list)
845 if (get_user(status, &cmsg->cm_status)) {
846 dprintk("%s: error when copying status from userspace", __func__);
850 /* walk the list and find corresponding xid */
852 spin_lock(&cn->cn_lock);
853 list_for_each_entry(tmp, &cn->cn_list, cu_list) {
854 if (get_unaligned(&tmp->cu_msg.cm_xid) == xid) {
856 if (status != -EINPROGRESS)
857 list_del_init(&cup->cu_list);
861 spin_unlock(&cn->cn_lock);
863 /* couldn't find upcall? */
865 dprintk("%s: couldn't find upcall -- xid=%u\n", __func__, xid);
869 if (status == -EINPROGRESS)
870 return __cld_pipe_inprogress_downcall(cmsg, nn);
872 if (copy_from_user(&cup->cu_msg, src, mlen) != 0)
875 complete(&cup->cu_done);
880 cld_pipe_destroy_msg(struct rpc_pipe_msg *msg)
882 struct cld_msg *cmsg = msg->data;
883 struct cld_upcall *cup = container_of(cmsg, struct cld_upcall,
886 /* errno >= 0 means we got a downcall */
890 complete(&cup->cu_done);
893 static const struct rpc_pipe_ops cld_upcall_ops = {
894 .upcall = rpc_pipe_generic_upcall,
895 .downcall = cld_pipe_downcall,
896 .destroy_msg = cld_pipe_destroy_msg,
899 static struct dentry *
900 nfsd4_cld_register_sb(struct super_block *sb, struct rpc_pipe *pipe)
902 struct dentry *dir, *dentry;
904 dir = rpc_d_lookup_sb(sb, NFSD_PIPE_DIR);
906 return ERR_PTR(-ENOENT);
907 dentry = rpc_mkpipe_dentry(dir, NFSD_CLD_PIPE, NULL, pipe);
913 nfsd4_cld_unregister_sb(struct rpc_pipe *pipe)
916 rpc_unlink(pipe->dentry);
919 static struct dentry *
920 nfsd4_cld_register_net(struct net *net, struct rpc_pipe *pipe)
922 struct super_block *sb;
923 struct dentry *dentry;
925 sb = rpc_get_sb_net(net);
928 dentry = nfsd4_cld_register_sb(sb, pipe);
934 nfsd4_cld_unregister_net(struct net *net, struct rpc_pipe *pipe)
936 struct super_block *sb;
938 sb = rpc_get_sb_net(net);
940 nfsd4_cld_unregister_sb(pipe);
945 /* Initialize rpc_pipefs pipe for communication with client tracking daemon */
947 __nfsd4_init_cld_pipe(struct net *net)
950 struct dentry *dentry;
951 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
957 cn = kzalloc(sizeof(*cn), GFP_KERNEL);
963 cn->cn_pipe = rpc_mkpipe_data(&cld_upcall_ops, RPC_PIPE_WAIT_FOR_OPEN);
964 if (IS_ERR(cn->cn_pipe)) {
965 ret = PTR_ERR(cn->cn_pipe);
968 spin_lock_init(&cn->cn_lock);
969 INIT_LIST_HEAD(&cn->cn_list);
971 dentry = nfsd4_cld_register_net(net, cn->cn_pipe);
972 if (IS_ERR(dentry)) {
973 ret = PTR_ERR(dentry);
974 goto err_destroy_data;
977 cn->cn_pipe->dentry = dentry;
978 cn->cn_has_legacy = false;
983 rpc_destroy_pipe_data(cn->cn_pipe);
986 printk(KERN_ERR "NFSD: unable to create nfsdcld upcall pipe (%d)\n",
992 nfsd4_init_cld_pipe(struct net *net)
996 status = __nfsd4_init_cld_pipe(net);
998 printk("NFSD: Using old nfsdcld client tracking operations.\n");
1003 nfsd4_remove_cld_pipe(struct net *net)
1005 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1006 struct cld_net *cn = nn->cld_net;
1008 nfsd4_cld_unregister_net(net, cn->cn_pipe);
1009 rpc_destroy_pipe_data(cn->cn_pipe);
1014 static struct cld_upcall *
1015 alloc_cld_upcall(struct cld_net *cn)
1017 struct cld_upcall *new, *tmp;
1019 new = kzalloc(sizeof(*new), GFP_KERNEL);
1023 /* FIXME: hard cap on number in flight? */
1025 spin_lock(&cn->cn_lock);
1026 list_for_each_entry(tmp, &cn->cn_list, cu_list) {
1027 if (tmp->cu_msg.cm_xid == cn->cn_xid) {
1029 spin_unlock(&cn->cn_lock);
1030 goto restart_search;
1033 init_completion(&new->cu_done);
1034 new->cu_msg.cm_vers = CLD_UPCALL_VERSION;
1035 put_unaligned(cn->cn_xid++, &new->cu_msg.cm_xid);
1037 list_add(&new->cu_list, &cn->cn_list);
1038 spin_unlock(&cn->cn_lock);
1040 dprintk("%s: allocated xid %u\n", __func__, new->cu_msg.cm_xid);
1046 free_cld_upcall(struct cld_upcall *victim)
1048 struct cld_net *cn = victim->cu_net;
1050 spin_lock(&cn->cn_lock);
1051 list_del(&victim->cu_list);
1052 spin_unlock(&cn->cn_lock);
1056 /* Ask daemon to create a new record */
1058 nfsd4_cld_create(struct nfs4_client *clp)
1061 struct cld_upcall *cup;
1062 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
1063 struct cld_net *cn = nn->cld_net;
1065 /* Don't upcall if it's already stored */
1066 if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
1069 cup = alloc_cld_upcall(cn);
1075 cup->cu_msg.cm_cmd = Cld_Create;
1076 cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
1077 memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
1080 ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
1082 ret = cup->cu_msg.cm_status;
1083 set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
1086 free_cld_upcall(cup);
1089 printk(KERN_ERR "NFSD: Unable to create client "
1090 "record on stable storage: %d\n", ret);
1093 /* Ask daemon to create a new record */
1095 nfsd4_cld_remove(struct nfs4_client *clp)
1098 struct cld_upcall *cup;
1099 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
1100 struct cld_net *cn = nn->cld_net;
1102 /* Don't upcall if it's already removed */
1103 if (!test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
1106 cup = alloc_cld_upcall(cn);
1112 cup->cu_msg.cm_cmd = Cld_Remove;
1113 cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
1114 memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
1117 ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
1119 ret = cup->cu_msg.cm_status;
1120 clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
1123 free_cld_upcall(cup);
1126 printk(KERN_ERR "NFSD: Unable to remove client "
1127 "record from stable storage: %d\n", ret);
1131 * For older nfsdcld's that do not allow us to "slurp" the clients
1132 * from the tracking database during startup.
1134 * Check for presence of a record, and update its timestamp
1137 nfsd4_cld_check_v0(struct nfs4_client *clp)
1140 struct cld_upcall *cup;
1141 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
1142 struct cld_net *cn = nn->cld_net;
1144 /* Don't upcall if one was already stored during this grace pd */
1145 if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
1148 cup = alloc_cld_upcall(cn);
1150 printk(KERN_ERR "NFSD: Unable to check client record on "
1151 "stable storage: %d\n", -ENOMEM);
1155 cup->cu_msg.cm_cmd = Cld_Check;
1156 cup->cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
1157 memcpy(cup->cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
1160 ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
1162 ret = cup->cu_msg.cm_status;
1163 set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
1166 free_cld_upcall(cup);
1171 * For newer nfsdcld's that allow us to "slurp" the clients
1172 * from the tracking database during startup.
1174 * Check for presence of a record in the reclaim_str_hashtbl
1177 nfsd4_cld_check(struct nfs4_client *clp)
1179 struct nfs4_client_reclaim *crp;
1180 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
1181 struct cld_net *cn = nn->cld_net;
1183 char dname[HEXDIR_LEN];
1184 struct xdr_netobj name;
1186 /* did we already find that this client is stable? */
1187 if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
1190 /* look for it in the reclaim hashtable otherwise */
1191 crp = nfsd4_find_reclaim_client(clp->cl_name, nn);
1195 if (cn->cn_has_legacy) {
1196 status = nfs4_make_rec_clidname(dname, &clp->cl_name);
1200 name.data = kmemdup(dname, HEXDIR_LEN, GFP_KERNEL);
1202 dprintk("%s: failed to allocate memory for name.data!\n",
1206 name.len = HEXDIR_LEN;
1207 crp = nfsd4_find_reclaim_client(name, nn);
1220 nfsd4_cld_grace_start(struct nfsd_net *nn)
1223 struct cld_upcall *cup;
1224 struct cld_net *cn = nn->cld_net;
1226 cup = alloc_cld_upcall(cn);
1232 cup->cu_msg.cm_cmd = Cld_GraceStart;
1233 ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
1235 ret = cup->cu_msg.cm_status;
1237 free_cld_upcall(cup);
1240 dprintk("%s: Unable to get clients from userspace: %d\n",
1245 /* For older nfsdcld's that need cm_gracetime */
1247 nfsd4_cld_grace_done_v0(struct nfsd_net *nn)
1250 struct cld_upcall *cup;
1251 struct cld_net *cn = nn->cld_net;
1253 cup = alloc_cld_upcall(cn);
1259 cup->cu_msg.cm_cmd = Cld_GraceDone;
1260 cup->cu_msg.cm_u.cm_gracetime = (int64_t)nn->boot_time;
1261 ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
1263 ret = cup->cu_msg.cm_status;
1265 free_cld_upcall(cup);
1268 printk(KERN_ERR "NFSD: Unable to end grace period: %d\n", ret);
1272 * For newer nfsdcld's that do not need cm_gracetime. We also need to call
1273 * nfs4_release_reclaim() to clear out the reclaim_str_hashtbl.
1276 nfsd4_cld_grace_done(struct nfsd_net *nn)
1279 struct cld_upcall *cup;
1280 struct cld_net *cn = nn->cld_net;
1282 cup = alloc_cld_upcall(cn);
1288 cup->cu_msg.cm_cmd = Cld_GraceDone;
1289 ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_msg);
1291 ret = cup->cu_msg.cm_status;
1293 free_cld_upcall(cup);
1295 nfs4_release_reclaim(nn);
1297 printk(KERN_ERR "NFSD: Unable to end grace period: %d\n", ret);
1301 nfs4_cld_state_init(struct net *net)
1303 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1306 nn->reclaim_str_hashtbl = kmalloc_array(CLIENT_HASH_SIZE,
1307 sizeof(struct list_head),
1309 if (!nn->reclaim_str_hashtbl)
1312 for (i = 0; i < CLIENT_HASH_SIZE; i++)
1313 INIT_LIST_HEAD(&nn->reclaim_str_hashtbl[i]);
1314 nn->reclaim_str_hashtbl_size = 0;
1315 nn->track_reclaim_completes = true;
1316 atomic_set(&nn->nr_reclaim_complete, 0);
1322 nfs4_cld_state_shutdown(struct net *net)
1324 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1326 nn->track_reclaim_completes = false;
1327 kfree(nn->reclaim_str_hashtbl);
1331 cld_running(struct nfsd_net *nn)
1333 struct cld_net *cn = nn->cld_net;
1334 struct rpc_pipe *pipe = cn->cn_pipe;
1336 return pipe->nreaders || pipe->nwriters;
1340 nfsd4_cld_tracking_init(struct net *net)
1343 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1347 status = nfs4_cld_state_init(net);
1351 status = __nfsd4_init_cld_pipe(net);
1356 * rpc pipe upcalls take 30 seconds to time out, so we don't want to
1357 * queue an upcall unless we know that nfsdcld is running (because we
1358 * want this to fail fast so that nfsd4_client_tracking_init() can try
1359 * the next client tracking method). nfsdcld should already be running
1360 * before nfsd is started, so the wait here is for nfsdcld to open the
1361 * pipefs file we just created.
1363 while (!(running = cld_running(nn)) && retries--)
1367 status = -ETIMEDOUT;
1371 status = nfsd4_cld_grace_start(nn);
1373 if (status == -EOPNOTSUPP)
1374 printk(KERN_WARNING "NFSD: Please upgrade nfsdcld.\n");
1375 nfs4_release_reclaim(nn);
1378 printk("NFSD: Using nfsdcld client tracking operations.\n");
1382 nfsd4_remove_cld_pipe(net);
1384 nfs4_cld_state_shutdown(net);
1389 nfsd4_cld_tracking_exit(struct net *net)
1391 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1393 nfs4_release_reclaim(nn);
1394 nfsd4_remove_cld_pipe(net);
1395 nfs4_cld_state_shutdown(net);
1398 /* For older nfsdcld's */
1399 static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops_v0 = {
1400 .init = nfsd4_init_cld_pipe,
1401 .exit = nfsd4_remove_cld_pipe,
1402 .create = nfsd4_cld_create,
1403 .remove = nfsd4_cld_remove,
1404 .check = nfsd4_cld_check_v0,
1405 .grace_done = nfsd4_cld_grace_done_v0,
1408 /* For newer nfsdcld's */
1409 static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops = {
1410 .init = nfsd4_cld_tracking_init,
1411 .exit = nfsd4_cld_tracking_exit,
1412 .create = nfsd4_cld_create,
1413 .remove = nfsd4_cld_remove,
1414 .check = nfsd4_cld_check,
1415 .grace_done = nfsd4_cld_grace_done,
1418 /* upcall via usermodehelper */
1419 static char cltrack_prog[PATH_MAX] = "/sbin/nfsdcltrack";
1420 module_param_string(cltrack_prog, cltrack_prog, sizeof(cltrack_prog),
1422 MODULE_PARM_DESC(cltrack_prog, "Path to the nfsdcltrack upcall program");
1424 static bool cltrack_legacy_disable;
1425 module_param(cltrack_legacy_disable, bool, S_IRUGO|S_IWUSR);
1426 MODULE_PARM_DESC(cltrack_legacy_disable,
1427 "Disable legacy recoverydir conversion. Default: false");
1429 #define LEGACY_TOPDIR_ENV_PREFIX "NFSDCLTRACK_LEGACY_TOPDIR="
1430 #define LEGACY_RECDIR_ENV_PREFIX "NFSDCLTRACK_LEGACY_RECDIR="
1431 #define HAS_SESSION_ENV_PREFIX "NFSDCLTRACK_CLIENT_HAS_SESSION="
1432 #define GRACE_START_ENV_PREFIX "NFSDCLTRACK_GRACE_START="
1435 nfsd4_cltrack_legacy_topdir(void)
1441 if (cltrack_legacy_disable)
1444 len = strlen(LEGACY_TOPDIR_ENV_PREFIX) +
1445 strlen(nfs4_recoverydir()) + 1;
1447 result = kmalloc(len, GFP_KERNEL);
1451 copied = snprintf(result, len, LEGACY_TOPDIR_ENV_PREFIX "%s",
1452 nfs4_recoverydir());
1453 if (copied >= len) {
1454 /* just return nothing if output was truncated */
1463 nfsd4_cltrack_legacy_recdir(const struct xdr_netobj *name)
1469 if (cltrack_legacy_disable)
1472 /* +1 is for '/' between "topdir" and "recdir" */
1473 len = strlen(LEGACY_RECDIR_ENV_PREFIX) +
1474 strlen(nfs4_recoverydir()) + 1 + HEXDIR_LEN;
1476 result = kmalloc(len, GFP_KERNEL);
1480 copied = snprintf(result, len, LEGACY_RECDIR_ENV_PREFIX "%s/",
1481 nfs4_recoverydir());
1482 if (copied > (len - HEXDIR_LEN)) {
1483 /* just return nothing if output will be truncated */
1488 copied = nfs4_make_rec_clidname(result + copied, name);
1498 nfsd4_cltrack_client_has_session(struct nfs4_client *clp)
1504 /* prefix + Y/N character + terminating NULL */
1505 len = strlen(HAS_SESSION_ENV_PREFIX) + 1 + 1;
1507 result = kmalloc(len, GFP_KERNEL);
1511 copied = snprintf(result, len, HAS_SESSION_ENV_PREFIX "%c",
1512 clp->cl_minorversion ? 'Y' : 'N');
1513 if (copied >= len) {
1514 /* just return nothing if output was truncated */
1523 nfsd4_cltrack_grace_start(time_t grace_start)
1529 /* prefix + max width of int64_t string + terminating NULL */
1530 len = strlen(GRACE_START_ENV_PREFIX) + 22 + 1;
1532 result = kmalloc(len, GFP_KERNEL);
1536 copied = snprintf(result, len, GRACE_START_ENV_PREFIX "%ld",
1538 if (copied >= len) {
1539 /* just return nothing if output was truncated */
1548 nfsd4_umh_cltrack_upcall(char *cmd, char *arg, char *env0, char *env1)
1554 if (unlikely(!cltrack_prog[0])) {
1555 dprintk("%s: cltrack_prog is disabled\n", __func__);
1559 dprintk("%s: cmd: %s\n", __func__, cmd);
1560 dprintk("%s: arg: %s\n", __func__, arg ? arg : "(null)");
1561 dprintk("%s: env0: %s\n", __func__, env0 ? env0 : "(null)");
1562 dprintk("%s: env1: %s\n", __func__, env1 ? env1 : "(null)");
1568 argv[0] = (char *)cltrack_prog;
1573 ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
1575 * Disable the upcall mechanism if we're getting an ENOENT or EACCES
1576 * error. The admin can re-enable it on the fly by using sysfs
1577 * once the problem has been fixed.
1579 if (ret == -ENOENT || ret == -EACCES) {
1580 dprintk("NFSD: %s was not found or isn't executable (%d). "
1581 "Setting cltrack_prog to blank string!",
1583 cltrack_prog[0] = '\0';
1585 dprintk("%s: %s return value: %d\n", __func__, cltrack_prog, ret);
1591 bin_to_hex_dup(const unsigned char *src, int srclen)
1596 /* +1 for terminating NULL */
1597 buf = kmalloc((srclen * 2) + 1, GFP_KERNEL);
1602 for (i = 0; i < srclen; i++) {
1603 sprintf(hex, "%2.2x", *src++);
1610 nfsd4_umh_cltrack_init(struct net *net)
1613 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1614 char *grace_start = nfsd4_cltrack_grace_start(nn->boot_time);
1616 /* XXX: The usermode helper s not working in container yet. */
1617 if (net != &init_net) {
1618 pr_warn("NFSD: attempt to initialize umh client tracking in a container ignored.\n");
1623 ret = nfsd4_umh_cltrack_upcall("init", NULL, grace_start, NULL);
1626 printk("NFSD: Using UMH upcall client tracking operations.\n");
1631 nfsd4_cltrack_upcall_lock(struct nfs4_client *clp)
1633 wait_on_bit_lock(&clp->cl_flags, NFSD4_CLIENT_UPCALL_LOCK,
1634 TASK_UNINTERRUPTIBLE);
1638 nfsd4_cltrack_upcall_unlock(struct nfs4_client *clp)
1640 smp_mb__before_atomic();
1641 clear_bit(NFSD4_CLIENT_UPCALL_LOCK, &clp->cl_flags);
1642 smp_mb__after_atomic();
1643 wake_up_bit(&clp->cl_flags, NFSD4_CLIENT_UPCALL_LOCK);
1647 nfsd4_umh_cltrack_create(struct nfs4_client *clp)
1649 char *hexid, *has_session, *grace_start;
1650 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
1653 * With v4.0 clients, there's little difference in outcome between a
1654 * create and check operation, and we can end up calling into this
1655 * function multiple times per client (once for each openowner). So,
1656 * for v4.0 clients skip upcalling once the client has been recorded
1657 * on stable storage.
1659 * For v4.1+ clients, the outcome of the two operations is different,
1660 * so we must ensure that we upcall for the create operation. v4.1+
1661 * clients call this on RECLAIM_COMPLETE though, so we should only end
1662 * up doing a single create upcall per client.
1664 if (clp->cl_minorversion == 0 &&
1665 test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
1668 hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
1670 dprintk("%s: can't allocate memory for upcall!\n", __func__);
1674 has_session = nfsd4_cltrack_client_has_session(clp);
1675 grace_start = nfsd4_cltrack_grace_start(nn->boot_time);
1677 nfsd4_cltrack_upcall_lock(clp);
1678 if (!nfsd4_umh_cltrack_upcall("create", hexid, has_session, grace_start))
1679 set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
1680 nfsd4_cltrack_upcall_unlock(clp);
1688 nfsd4_umh_cltrack_remove(struct nfs4_client *clp)
1692 if (!test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
1695 hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
1697 dprintk("%s: can't allocate memory for upcall!\n", __func__);
1701 nfsd4_cltrack_upcall_lock(clp);
1702 if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags) &&
1703 nfsd4_umh_cltrack_upcall("remove", hexid, NULL, NULL) == 0)
1704 clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
1705 nfsd4_cltrack_upcall_unlock(clp);
1711 nfsd4_umh_cltrack_check(struct nfs4_client *clp)
1714 char *hexid, *has_session, *legacy;
1716 if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
1719 hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
1721 dprintk("%s: can't allocate memory for upcall!\n", __func__);
1725 has_session = nfsd4_cltrack_client_has_session(clp);
1726 legacy = nfsd4_cltrack_legacy_recdir(&clp->cl_name);
1728 nfsd4_cltrack_upcall_lock(clp);
1729 if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags)) {
1732 ret = nfsd4_umh_cltrack_upcall("check", hexid, has_session, legacy);
1734 set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
1736 nfsd4_cltrack_upcall_unlock(clp);
1745 nfsd4_umh_cltrack_grace_done(struct nfsd_net *nn)
1748 char timestr[22]; /* FIXME: better way to determine max size? */
1750 sprintf(timestr, "%ld", nn->boot_time);
1751 legacy = nfsd4_cltrack_legacy_topdir();
1752 nfsd4_umh_cltrack_upcall("gracedone", timestr, legacy, NULL);
1756 static const struct nfsd4_client_tracking_ops nfsd4_umh_tracking_ops = {
1757 .init = nfsd4_umh_cltrack_init,
1759 .create = nfsd4_umh_cltrack_create,
1760 .remove = nfsd4_umh_cltrack_remove,
1761 .check = nfsd4_umh_cltrack_check,
1762 .grace_done = nfsd4_umh_cltrack_grace_done,
1766 nfsd4_client_tracking_init(struct net *net)
1770 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1772 /* just run the init if it the method is already decided */
1773 if (nn->client_tracking_ops)
1776 /* First, try to use nfsdcld */
1777 nn->client_tracking_ops = &nfsd4_cld_tracking_ops;
1778 status = nn->client_tracking_ops->init(net);
1781 if (status != -ETIMEDOUT) {
1782 nn->client_tracking_ops = &nfsd4_cld_tracking_ops_v0;
1783 status = nn->client_tracking_ops->init(net);
1789 * Next, try the UMH upcall.
1791 nn->client_tracking_ops = &nfsd4_umh_tracking_ops;
1792 status = nn->client_tracking_ops->init(net);
1797 * Finally, See if the recoverydir exists and is a directory.
1798 * If it is, then use the legacy ops.
1800 nn->client_tracking_ops = &nfsd4_legacy_tracking_ops;
1801 status = kern_path(nfs4_recoverydir(), LOOKUP_FOLLOW, &path);
1803 status = d_is_dir(path.dentry);
1812 status = nn->client_tracking_ops->init(net);
1815 printk(KERN_WARNING "NFSD: Unable to initialize client "
1816 "recovery tracking! (%d)\n", status);
1817 nn->client_tracking_ops = NULL;
1823 nfsd4_client_tracking_exit(struct net *net)
1825 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1827 if (nn->client_tracking_ops) {
1828 if (nn->client_tracking_ops->exit)
1829 nn->client_tracking_ops->exit(net);
1830 nn->client_tracking_ops = NULL;
1835 nfsd4_client_record_create(struct nfs4_client *clp)
1837 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
1839 if (nn->client_tracking_ops)
1840 nn->client_tracking_ops->create(clp);
1844 nfsd4_client_record_remove(struct nfs4_client *clp)
1846 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
1848 if (nn->client_tracking_ops)
1849 nn->client_tracking_ops->remove(clp);
1853 nfsd4_client_record_check(struct nfs4_client *clp)
1855 struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
1857 if (nn->client_tracking_ops)
1858 return nn->client_tracking_ops->check(clp);
1864 nfsd4_record_grace_done(struct nfsd_net *nn)
1866 if (nn->client_tracking_ops)
1867 nn->client_tracking_ops->grace_done(nn);
1871 rpc_pipefs_event(struct notifier_block *nb, unsigned long event, void *ptr)
1873 struct super_block *sb = ptr;
1874 struct net *net = sb->s_fs_info;
1875 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
1876 struct cld_net *cn = nn->cld_net;
1877 struct dentry *dentry;
1880 if (!try_module_get(THIS_MODULE))
1884 module_put(THIS_MODULE);
1889 case RPC_PIPEFS_MOUNT:
1890 dentry = nfsd4_cld_register_sb(sb, cn->cn_pipe);
1891 if (IS_ERR(dentry)) {
1892 ret = PTR_ERR(dentry);
1895 cn->cn_pipe->dentry = dentry;
1897 case RPC_PIPEFS_UMOUNT:
1898 if (cn->cn_pipe->dentry)
1899 nfsd4_cld_unregister_sb(cn->cn_pipe);
1905 module_put(THIS_MODULE);
1909 static struct notifier_block nfsd4_cld_block = {
1910 .notifier_call = rpc_pipefs_event,
1914 register_cld_notifier(void)
1916 return rpc_pipefs_notifier_register(&nfsd4_cld_block);
1920 unregister_cld_notifier(void)
1922 rpc_pipefs_notifier_unregister(&nfsd4_cld_block);