^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (c) 2004 The Regents of the University of Michigan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2012 Jeff Layton <jlayton@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Andy Adamson <andros@citi.umich.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * 1. Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * 2. Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * notice, this list of conditions and the following disclaimer in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * documentation and/or other materials provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * 3. Neither the name of the University nor the names of its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * contributors may be used to endorse or promote products derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <crypto/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/sunrpc/rpc_pipe_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <linux/nfsd/cld.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include "nfsd.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include "state.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include "vfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include "netns.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define NFSDDBG_FACILITY NFSDDBG_PROC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /* Declarations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct nfsd4_client_tracking_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) int (*init)(struct net *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) void (*exit)(struct net *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) void (*create)(struct nfs4_client *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) void (*remove)(struct nfs4_client *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int (*check)(struct nfs4_client *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) void (*grace_done)(struct nfsd_net *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) uint8_t version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) size_t msglen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops_v2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* Globals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) nfs4_save_creds(const struct cred **original_creds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct cred *new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) new = prepare_creds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (!new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) new->fsuid = GLOBAL_ROOT_UID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) new->fsgid = GLOBAL_ROOT_GID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) *original_creds = override_creds(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) put_cred(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) nfs4_reset_creds(const struct cred *original)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) revert_creds(original);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) md5_to_hex(char *out, char *md5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) for (i=0; i<16; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) unsigned char c = md5[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) *out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) *out++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) *out = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) nfs4_make_rec_clidname(char *dname, const struct xdr_netobj *clname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct xdr_netobj cksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct crypto_shash *tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) dprintk("NFSD: nfs4_make_rec_clidname for %.*s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) clname->len, clname->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) tfm = crypto_alloc_shash("md5", 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (IS_ERR(tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) status = PTR_ERR(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) goto out_no_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) cksum.len = crypto_shash_digestsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) cksum.data = kmalloc(cksum.len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (cksum.data == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) status = crypto_shash_tfm_digest(tfm, clname->data, clname->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) cksum.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) md5_to_hex(dname, cksum.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) kfree(cksum.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) crypto_free_shash(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) out_no_tfm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * If we had an error generating the recdir name for the legacy tracker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * then warn the admin. If the error doesn't appear to be transient,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * then disable recovery tracking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) legacy_recdir_name_error(struct nfs4_client *clp, int error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) printk(KERN_ERR "NFSD: unable to generate recoverydir "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) "name (%d).\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * if the algorithm just doesn't exist, then disable the recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * tracker altogether. The crypto libs will generally return this if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * FIPS is enabled as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (error == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) printk(KERN_ERR "NFSD: disabling legacy clientid tracking. "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) "Reboot recovery will not function correctly!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) nfsd4_client_tracking_exit(clp->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) __nfsd4_create_reclaim_record_grace(struct nfs4_client *clp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) const char *dname, int len, struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct xdr_netobj name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct xdr_netobj princhash = { .len = 0, .data = NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct nfs4_client_reclaim *crp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) name.data = kmemdup(dname, len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (!name.data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) dprintk("%s: failed to allocate memory for name.data!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) name.len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) crp = nfs4_client_to_reclaim(name, princhash, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (!crp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) kfree(name.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) crp->cr_clp = clp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) nfsd4_create_clid_dir(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) const struct cred *original_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) char dname[HEXDIR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct dentry *dir, *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (test_and_set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (!nn->rec_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) status = nfs4_make_rec_clidname(dname, &clp->cl_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return legacy_recdir_name_error(clp, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) status = nfs4_save_creds(&original_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) status = mnt_want_write_file(nn->rec_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) goto out_creds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) dir = nn->rec_file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /* lock the parent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) inode_lock(d_inode(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) dentry = lookup_one_len(dname, dir, HEXDIR_LEN-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) status = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (d_really_is_positive(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * In the 4.1 case, where we're called from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * reclaim_complete(), records from the previous reboot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * may still be left, so this is OK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * In the 4.0 case, we should never get here; but we may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * as well be forgiving and just succeed silently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) status = vfs_mkdir(d_inode(dir), dentry, S_IRWXU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) inode_unlock(d_inode(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (status == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (nn->in_grace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) __nfsd4_create_reclaim_record_grace(clp, dname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) HEXDIR_LEN, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) vfs_fsync(nn->rec_file, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) printk(KERN_ERR "NFSD: failed to write recovery record"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) " (err %d); please check that %s exists"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) " and is writeable", status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) user_recovery_dirname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) mnt_drop_write_file(nn->rec_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) out_creds:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) nfs4_reset_creds(original_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) typedef int (recdir_func)(struct dentry *, struct dentry *, struct nfsd_net *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) struct name_list {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) char name[HEXDIR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct nfs4_dir_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct dir_context ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct list_head names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) nfsd4_build_namelist(struct dir_context *__ctx, const char *name, int namlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) loff_t offset, u64 ino, unsigned int d_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct nfs4_dir_ctx *ctx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) container_of(__ctx, struct nfs4_dir_ctx, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct name_list *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (namlen != HEXDIR_LEN - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) entry = kmalloc(sizeof(struct name_list), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (entry == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) memcpy(entry->name, name, HEXDIR_LEN - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) entry->name[HEXDIR_LEN - 1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) list_add(&entry->list, &ctx->names);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) nfsd4_list_rec_dir(recdir_func *f, struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) const struct cred *original_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct dentry *dir = nn->rec_file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) struct nfs4_dir_ctx ctx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) .ctx.actor = nfsd4_build_namelist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) .names = LIST_HEAD_INIT(ctx.names)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct name_list *entry, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) status = nfs4_save_creds(&original_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) status = vfs_llseek(nn->rec_file, 0, SEEK_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) nfs4_reset_creds(original_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) status = iterate_dir(nn->rec_file, &ctx.ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) list_for_each_entry_safe(entry, tmp, &ctx.names, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (!status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) dentry = lookup_one_len(entry->name, dir, HEXDIR_LEN-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) status = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) status = f(dir, dentry, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) list_del(&entry->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) kfree(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) inode_unlock(d_inode(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) nfs4_reset_creds(original_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) list_for_each_entry_safe(entry, tmp, &ctx.names, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) dprintk("NFSD: %s. Left entry %s\n", __func__, entry->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) list_del(&entry->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) kfree(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) nfsd4_unlink_clid_dir(char *name, int namlen, struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct dentry *dir, *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) dprintk("NFSD: nfsd4_unlink_clid_dir. name %.*s\n", namlen, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) dir = nn->rec_file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) inode_lock_nested(d_inode(dir), I_MUTEX_PARENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) dentry = lookup_one_len(name, dir, namlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) status = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) status = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (d_really_is_negative(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) status = vfs_rmdir(d_inode(dir), dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) inode_unlock(d_inode(dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) __nfsd4_remove_reclaim_record_grace(const char *dname, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct xdr_netobj name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct nfs4_client_reclaim *crp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) name.data = kmemdup(dname, len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (!name.data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) dprintk("%s: failed to allocate memory for name.data!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) name.len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) crp = nfsd4_find_reclaim_client(name, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) kfree(name.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (crp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) nfs4_remove_reclaim_record(crp, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) nfsd4_remove_clid_dir(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) const struct cred *original_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) char dname[HEXDIR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (!nn->rec_file || !test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) status = nfs4_make_rec_clidname(dname, &clp->cl_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return legacy_recdir_name_error(clp, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) status = mnt_want_write_file(nn->rec_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) status = nfs4_save_creds(&original_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) goto out_drop_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) status = nfsd4_unlink_clid_dir(dname, HEXDIR_LEN-1, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) nfs4_reset_creds(original_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (status == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) vfs_fsync(nn->rec_file, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (nn->in_grace)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) __nfsd4_remove_reclaim_record_grace(dname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) HEXDIR_LEN, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) out_drop_write:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) mnt_drop_write_file(nn->rec_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) printk("NFSD: Failed to remove expired client state directory"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) " %.*s\n", HEXDIR_LEN, dname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) purge_old(struct dentry *parent, struct dentry *child, struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct xdr_netobj name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (child->d_name.len != HEXDIR_LEN - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) printk("%s: illegal name %pd in recovery directory\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) __func__, child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /* Keep trying; maybe the others are OK: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) name.data = kmemdup_nul(child->d_name.name, child->d_name.len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (!name.data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) dprintk("%s: failed to allocate memory for name.data!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) name.len = HEXDIR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (nfs4_has_reclaimed_state(name, nn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) status = vfs_rmdir(d_inode(parent), child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) printk("failed to remove client recovery directory %pd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) kfree(name.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) /* Keep trying, success or failure: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) nfsd4_recdir_purge_old(struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) nn->in_grace = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (!nn->rec_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) status = mnt_want_write_file(nn->rec_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) status = nfsd4_list_rec_dir(purge_old, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if (status == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) vfs_fsync(nn->rec_file, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) mnt_drop_write_file(nn->rec_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) nfs4_release_reclaim(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) printk("nfsd4: failed to purge old clients from recovery"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) " directory %pD\n", nn->rec_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) load_recdir(struct dentry *parent, struct dentry *child, struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) struct xdr_netobj name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) struct xdr_netobj princhash = { .len = 0, .data = NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (child->d_name.len != HEXDIR_LEN - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) printk("%s: illegal name %pd in recovery directory\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) __func__, child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /* Keep trying; maybe the others are OK: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) name.data = kmemdup_nul(child->d_name.name, child->d_name.len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (!name.data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) dprintk("%s: failed to allocate memory for name.data!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) name.len = HEXDIR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (!nfs4_client_to_reclaim(name, princhash, nn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) kfree(name.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) nfsd4_recdir_load(struct net *net) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (!nn->rec_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) status = nfsd4_list_rec_dir(load_recdir, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) printk("nfsd4: failed loading clients from recovery"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) " directory %pD\n", nn->rec_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) * Hold reference to the recovery directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) nfsd4_init_recdir(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) const struct cred *original_cred;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) printk("NFSD: Using %s as the NFSv4 state recovery directory\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) user_recovery_dirname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) BUG_ON(nn->rec_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) status = nfs4_save_creds(&original_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) printk("NFSD: Unable to change credentials to find recovery"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) " directory: error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) nn->rec_file = filp_open(user_recovery_dirname, O_RDONLY | O_DIRECTORY, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (IS_ERR(nn->rec_file)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) printk("NFSD: unable to find recovery directory %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) user_recovery_dirname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) status = PTR_ERR(nn->rec_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) nn->rec_file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) nfs4_reset_creds(original_cred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if (!status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) nn->in_grace = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) nfsd4_shutdown_recdir(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (!nn->rec_file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) fput(nn->rec_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) nn->rec_file = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) nfs4_legacy_state_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) nn->reclaim_str_hashtbl = kmalloc_array(CLIENT_HASH_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) sizeof(struct list_head),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (!nn->reclaim_str_hashtbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) for (i = 0; i < CLIENT_HASH_SIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) INIT_LIST_HEAD(&nn->reclaim_str_hashtbl[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) nn->reclaim_str_hashtbl_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) nfs4_legacy_state_shutdown(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) kfree(nn->reclaim_str_hashtbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) nfsd4_load_reboot_recovery_data(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) status = nfsd4_init_recdir(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) status = nfsd4_recdir_load(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) nfsd4_shutdown_recdir(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) nfsd4_legacy_tracking_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) /* XXX: The legacy code won't work in a container */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) if (net != &init_net) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) pr_warn("NFSD: attempt to initialize legacy client tracking in a container ignored.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) status = nfs4_legacy_state_init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) status = nfsd4_load_reboot_recovery_data(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) printk("NFSD: Using legacy client tracking operations.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) nfs4_legacy_state_shutdown(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) nfsd4_legacy_tracking_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) nfs4_release_reclaim(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) nfsd4_shutdown_recdir(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) nfs4_legacy_state_shutdown(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) * Change the NFSv4 recovery directory to recdir.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) nfs4_reset_recoverydir(char *recdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) struct path path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) status = kern_path(recdir, LOOKUP_FOLLOW, &path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) status = -ENOTDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) if (d_is_dir(path.dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) strcpy(user_recovery_dirname, recdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) path_put(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) nfs4_recoverydir(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) return user_recovery_dirname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) nfsd4_check_legacy_client(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) char dname[HEXDIR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) struct nfs4_client_reclaim *crp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) struct xdr_netobj name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) /* did we already find that this client is stable? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) status = nfs4_make_rec_clidname(dname, &clp->cl_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) legacy_recdir_name_error(clp, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) /* look for it in the reclaim hashtable otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) name.data = kmemdup(dname, HEXDIR_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (!name.data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) dprintk("%s: failed to allocate memory for name.data!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) goto out_enoent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) name.len = HEXDIR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) crp = nfsd4_find_reclaim_client(name, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) kfree(name.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (crp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) crp->cr_clp = clp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) out_enoent:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) static const struct nfsd4_client_tracking_ops nfsd4_legacy_tracking_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) .init = nfsd4_legacy_tracking_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) .exit = nfsd4_legacy_tracking_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) .create = nfsd4_create_clid_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) .remove = nfsd4_remove_clid_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) .check = nfsd4_check_legacy_client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) .grace_done = nfsd4_recdir_purge_old,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) .version = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) .msglen = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) /* Globals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) #define NFSD_PIPE_DIR "nfsd"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) #define NFSD_CLD_PIPE "cld"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) /* per-net-ns structure for holding cld upcall info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) struct cld_net {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) struct rpc_pipe *cn_pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) spinlock_t cn_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) struct list_head cn_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) unsigned int cn_xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) bool cn_has_legacy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) struct crypto_shash *cn_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) struct cld_upcall {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) struct list_head cu_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) struct cld_net *cu_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) struct completion cu_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) struct cld_msg_hdr cu_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) struct cld_msg cu_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) struct cld_msg_v2 cu_msg_v2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) } cu_u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) __cld_pipe_upcall(struct rpc_pipe *pipe, void *cmsg, struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) struct rpc_pipe_msg msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) struct cld_upcall *cup = container_of(cmsg, struct cld_upcall, cu_u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) memset(&msg, 0, sizeof(msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) msg.data = cmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) msg.len = nn->client_tracking_ops->msglen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) ret = rpc_queue_upcall(pipe, &msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) wait_for_completion(&cup->cu_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (msg.errno < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) ret = msg.errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) cld_pipe_upcall(struct rpc_pipe *pipe, void *cmsg, struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) * -EAGAIN occurs when pipe is closed and reopened while there are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) * upcalls queued.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) ret = __cld_pipe_upcall(pipe, cmsg, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) } while (ret == -EAGAIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) __cld_pipe_inprogress_downcall(const struct cld_msg_v2 __user *cmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) uint8_t cmd, princhashlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) struct xdr_netobj name, princhash = { .len = 0, .data = NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) uint16_t namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (get_user(cmd, &cmsg->cm_cmd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) dprintk("%s: error when copying cmd from userspace", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) if (cmd == Cld_GraceStart) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) if (nn->client_tracking_ops->version >= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) const struct cld_clntinfo __user *ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) ci = &cmsg->cm_u.cm_clntinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if (get_user(namelen, &ci->cc_name.cn_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) name.data = memdup_user(&ci->cc_name.cn_id, namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) if (IS_ERR_OR_NULL(name.data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) name.len = namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) get_user(princhashlen, &ci->cc_princhash.cp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) if (princhashlen > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) princhash.data = memdup_user(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) &ci->cc_princhash.cp_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) princhashlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) if (IS_ERR_OR_NULL(princhash.data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) princhash.len = princhashlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) princhash.len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) const struct cld_name __user *cnm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) cnm = &cmsg->cm_u.cm_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) if (get_user(namelen, &cnm->cn_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) name.data = memdup_user(&cnm->cn_id, namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (IS_ERR_OR_NULL(name.data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) name.len = namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) if (name.len > 5 && memcmp(name.data, "hash:", 5) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) name.len = name.len - 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) memmove(name.data, name.data + 5, name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) cn->cn_has_legacy = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) if (!nfs4_client_to_reclaim(name, princhash, nn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) kfree(name.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) kfree(princhash.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) return nn->client_tracking_ops->msglen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) struct cld_upcall *tmp, *cup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) struct cld_msg_hdr __user *hdr = (struct cld_msg_hdr __user *)src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct cld_msg_v2 __user *cmsg = (struct cld_msg_v2 __user *)src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) uint32_t xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) struct nfsd_net *nn = net_generic(file_inode(filp)->i_sb->s_fs_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) int16_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) if (mlen != nn->client_tracking_ops->msglen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) dprintk("%s: got %zu bytes, expected %zu\n", __func__, mlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) nn->client_tracking_ops->msglen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) /* copy just the xid so we can try to find that */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) if (copy_from_user(&xid, &hdr->cm_xid, sizeof(xid)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) dprintk("%s: error when copying xid from userspace", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) * copy the status so we know whether to remove the upcall from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) * list (for -EINPROGRESS, we just want to make sure the xid is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) * valid, not remove the upcall from the list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) if (get_user(status, &hdr->cm_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) dprintk("%s: error when copying status from userspace", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) /* walk the list and find corresponding xid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) cup = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) spin_lock(&cn->cn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) list_for_each_entry(tmp, &cn->cn_list, cu_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) if (get_unaligned(&tmp->cu_u.cu_hdr.cm_xid) == xid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) cup = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) if (status != -EINPROGRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) list_del_init(&cup->cu_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) spin_unlock(&cn->cn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) /* couldn't find upcall? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) if (!cup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) dprintk("%s: couldn't find upcall -- xid=%u\n", __func__, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) if (status == -EINPROGRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) return __cld_pipe_inprogress_downcall(cmsg, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) if (copy_from_user(&cup->cu_u.cu_msg_v2, src, mlen) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) complete(&cup->cu_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) return mlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) cld_pipe_destroy_msg(struct rpc_pipe_msg *msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) struct cld_msg *cmsg = msg->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) struct cld_upcall *cup = container_of(cmsg, struct cld_upcall,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) cu_u.cu_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) /* errno >= 0 means we got a downcall */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) if (msg->errno >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) complete(&cup->cu_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) static const struct rpc_pipe_ops cld_upcall_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) .upcall = rpc_pipe_generic_upcall,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) .downcall = cld_pipe_downcall,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) .destroy_msg = cld_pipe_destroy_msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) static struct dentry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) nfsd4_cld_register_sb(struct super_block *sb, struct rpc_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) struct dentry *dir, *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) dir = rpc_d_lookup_sb(sb, NFSD_PIPE_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) if (dir == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) dentry = rpc_mkpipe_dentry(dir, NFSD_CLD_PIPE, NULL, pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) dput(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) nfsd4_cld_unregister_sb(struct rpc_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) if (pipe->dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) rpc_unlink(pipe->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) static struct dentry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) nfsd4_cld_register_net(struct net *net, struct rpc_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) struct super_block *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) sb = rpc_get_sb_net(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) if (!sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) dentry = nfsd4_cld_register_sb(sb, pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) rpc_put_sb_net(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) return dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) nfsd4_cld_unregister_net(struct net *net, struct rpc_pipe *pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) struct super_block *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) sb = rpc_get_sb_net(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) if (sb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) nfsd4_cld_unregister_sb(pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) rpc_put_sb_net(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) /* Initialize rpc_pipefs pipe for communication with client tracking daemon */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) __nfsd4_init_cld_pipe(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) struct cld_net *cn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) if (nn->cld_net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) cn = kzalloc(sizeof(*cn), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) if (!cn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) cn->cn_pipe = rpc_mkpipe_data(&cld_upcall_ops, RPC_PIPE_WAIT_FOR_OPEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) if (IS_ERR(cn->cn_pipe)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) ret = PTR_ERR(cn->cn_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) spin_lock_init(&cn->cn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) INIT_LIST_HEAD(&cn->cn_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) dentry = nfsd4_cld_register_net(net, cn->cn_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) ret = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) goto err_destroy_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) cn->cn_pipe->dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) cn->cn_has_legacy = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) nn->cld_net = cn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) err_destroy_data:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) rpc_destroy_pipe_data(cn->cn_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) kfree(cn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) printk(KERN_ERR "NFSD: unable to create nfsdcld upcall pipe (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) nfsd4_init_cld_pipe(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) status = __nfsd4_init_cld_pipe(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) if (!status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) printk("NFSD: Using old nfsdcld client tracking operations.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) nfsd4_remove_cld_pipe(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) nfsd4_cld_unregister_net(net, cn->cn_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) rpc_destroy_pipe_data(cn->cn_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) if (cn->cn_tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) crypto_free_shash(cn->cn_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) kfree(nn->cld_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) nn->cld_net = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) static struct cld_upcall *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) alloc_cld_upcall(struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) struct cld_upcall *new, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) new = kzalloc(sizeof(*new), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) if (!new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) return new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) /* FIXME: hard cap on number in flight? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) restart_search:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) spin_lock(&cn->cn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) list_for_each_entry(tmp, &cn->cn_list, cu_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) if (tmp->cu_u.cu_msg.cm_xid == cn->cn_xid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) cn->cn_xid++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) spin_unlock(&cn->cn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) goto restart_search;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) init_completion(&new->cu_done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) new->cu_u.cu_msg.cm_vers = nn->client_tracking_ops->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) put_unaligned(cn->cn_xid++, &new->cu_u.cu_msg.cm_xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) new->cu_net = cn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) list_add(&new->cu_list, &cn->cn_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) spin_unlock(&cn->cn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) dprintk("%s: allocated xid %u\n", __func__, new->cu_u.cu_msg.cm_xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) return new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) free_cld_upcall(struct cld_upcall *victim)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) struct cld_net *cn = victim->cu_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) spin_lock(&cn->cn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) list_del(&victim->cu_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) spin_unlock(&cn->cn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) kfree(victim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) /* Ask daemon to create a new record */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) nfsd4_cld_create(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) struct cld_upcall *cup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) /* Don't upcall if it's already stored */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) cup = alloc_cld_upcall(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) if (!cup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) cup->cu_u.cu_msg.cm_cmd = Cld_Create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) cup->cu_u.cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) memcpy(cup->cu_u.cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) clp->cl_name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) ret = cup->cu_u.cu_msg.cm_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) free_cld_upcall(cup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) printk(KERN_ERR "NFSD: Unable to create client "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) "record on stable storage: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) /* Ask daemon to create a new record */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) nfsd4_cld_create_v2(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) struct cld_upcall *cup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) struct cld_msg_v2 *cmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) struct crypto_shash *tfm = cn->cn_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) struct xdr_netobj cksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) char *principal = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) /* Don't upcall if it's already stored */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) cup = alloc_cld_upcall(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) if (!cup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) cmsg = &cup->cu_u.cu_msg_v2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) cmsg->cm_cmd = Cld_Create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) cmsg->cm_u.cm_clntinfo.cc_name.cn_len = clp->cl_name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) memcpy(cmsg->cm_u.cm_clntinfo.cc_name.cn_id, clp->cl_name.data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) clp->cl_name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) if (clp->cl_cred.cr_raw_principal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) principal = clp->cl_cred.cr_raw_principal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) else if (clp->cl_cred.cr_principal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) principal = clp->cl_cred.cr_principal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) if (principal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) cksum.len = crypto_shash_digestsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) cksum.data = kmalloc(cksum.len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) if (cksum.data == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) ret = crypto_shash_tfm_digest(tfm, principal, strlen(principal),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) cksum.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) kfree(cksum.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) cmsg->cm_u.cm_clntinfo.cc_princhash.cp_len = cksum.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) memcpy(cmsg->cm_u.cm_clntinfo.cc_princhash.cp_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) cksum.data, cksum.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) kfree(cksum.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) cmsg->cm_u.cm_clntinfo.cc_princhash.cp_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) ret = cld_pipe_upcall(cn->cn_pipe, cmsg, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) ret = cmsg->cm_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) free_cld_upcall(cup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) pr_err("NFSD: Unable to create client record on stable storage: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) /* Ask daemon to create a new record */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) nfsd4_cld_remove(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) struct cld_upcall *cup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) /* Don't upcall if it's already removed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) if (!test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) cup = alloc_cld_upcall(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) if (!cup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) cup->cu_u.cu_msg.cm_cmd = Cld_Remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) cup->cu_u.cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) memcpy(cup->cu_u.cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) clp->cl_name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) ret = cup->cu_u.cu_msg.cm_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) free_cld_upcall(cup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) printk(KERN_ERR "NFSD: Unable to remove client "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) "record from stable storage: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) * For older nfsdcld's that do not allow us to "slurp" the clients
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) * from the tracking database during startup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) * Check for presence of a record, and update its timestamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) nfsd4_cld_check_v0(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) struct cld_upcall *cup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) /* Don't upcall if one was already stored during this grace pd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) cup = alloc_cld_upcall(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) if (!cup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) printk(KERN_ERR "NFSD: Unable to check client record on "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) "stable storage: %d\n", -ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) cup->cu_u.cu_msg.cm_cmd = Cld_Check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) cup->cu_u.cu_msg.cm_u.cm_name.cn_len = clp->cl_name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) memcpy(cup->cu_u.cu_msg.cm_u.cm_name.cn_id, clp->cl_name.data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) clp->cl_name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) ret = cup->cu_u.cu_msg.cm_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) free_cld_upcall(cup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) * For newer nfsdcld's that allow us to "slurp" the clients
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) * from the tracking database during startup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) * Check for presence of a record in the reclaim_str_hashtbl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) nfsd4_cld_check(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) struct nfs4_client_reclaim *crp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) char dname[HEXDIR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) struct xdr_netobj name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) /* did we already find that this client is stable? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) /* look for it in the reclaim hashtable otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) crp = nfsd4_find_reclaim_client(clp->cl_name, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) if (crp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) if (cn->cn_has_legacy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) status = nfs4_make_rec_clidname(dname, &clp->cl_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) name.data = kmemdup(dname, HEXDIR_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) if (!name.data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) dprintk("%s: failed to allocate memory for name.data!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) name.len = HEXDIR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) crp = nfsd4_find_reclaim_client(name, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) kfree(name.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) if (crp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) crp->cr_clp = clp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) nfsd4_cld_check_v2(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) struct nfs4_client_reclaim *crp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) char dname[HEXDIR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) struct xdr_netobj name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) struct crypto_shash *tfm = cn->cn_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) struct xdr_netobj cksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) char *principal = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) /* did we already find that this client is stable? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) /* look for it in the reclaim hashtable otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) crp = nfsd4_find_reclaim_client(clp->cl_name, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) if (crp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) if (cn->cn_has_legacy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) status = nfs4_make_rec_clidname(dname, &clp->cl_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) name.data = kmemdup(dname, HEXDIR_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) if (!name.data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) dprintk("%s: failed to allocate memory for name.data\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) name.len = HEXDIR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) crp = nfsd4_find_reclaim_client(name, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) kfree(name.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) if (crp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) if (crp->cr_princhash.len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) if (clp->cl_cred.cr_raw_principal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) principal = clp->cl_cred.cr_raw_principal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) else if (clp->cl_cred.cr_principal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) principal = clp->cl_cred.cr_principal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) if (principal == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) cksum.len = crypto_shash_digestsize(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) cksum.data = kmalloc(cksum.len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) if (cksum.data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) status = crypto_shash_tfm_digest(tfm, principal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) strlen(principal), cksum.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) kfree(cksum.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) if (memcmp(crp->cr_princhash.data, cksum.data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) crp->cr_princhash.len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) kfree(cksum.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) kfree(cksum.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) crp->cr_clp = clp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) nfsd4_cld_grace_start(struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) struct cld_upcall *cup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) cup = alloc_cld_upcall(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) if (!cup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) cup->cu_u.cu_msg.cm_cmd = Cld_GraceStart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) ret = cup->cu_u.cu_msg.cm_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) free_cld_upcall(cup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) dprintk("%s: Unable to get clients from userspace: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) /* For older nfsdcld's that need cm_gracetime */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) nfsd4_cld_grace_done_v0(struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) struct cld_upcall *cup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) cup = alloc_cld_upcall(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) if (!cup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) cup->cu_u.cu_msg.cm_cmd = Cld_GraceDone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) cup->cu_u.cu_msg.cm_u.cm_gracetime = nn->boot_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) ret = cup->cu_u.cu_msg.cm_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) free_cld_upcall(cup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) printk(KERN_ERR "NFSD: Unable to end grace period: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) * For newer nfsdcld's that do not need cm_gracetime. We also need to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) * nfs4_release_reclaim() to clear out the reclaim_str_hashtbl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) nfsd4_cld_grace_done(struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) struct cld_upcall *cup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) cup = alloc_cld_upcall(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) if (!cup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) cup->cu_u.cu_msg.cm_cmd = Cld_GraceDone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) ret = cup->cu_u.cu_msg.cm_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) free_cld_upcall(cup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) nfs4_release_reclaim(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) printk(KERN_ERR "NFSD: Unable to end grace period: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) nfs4_cld_state_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) nn->reclaim_str_hashtbl = kmalloc_array(CLIENT_HASH_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) sizeof(struct list_head),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) if (!nn->reclaim_str_hashtbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) for (i = 0; i < CLIENT_HASH_SIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) INIT_LIST_HEAD(&nn->reclaim_str_hashtbl[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) nn->reclaim_str_hashtbl_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) nn->track_reclaim_completes = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) atomic_set(&nn->nr_reclaim_complete, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) nfs4_cld_state_shutdown(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) nn->track_reclaim_completes = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) kfree(nn->reclaim_str_hashtbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) cld_running(struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) struct rpc_pipe *pipe = cn->cn_pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) return pipe->nreaders || pipe->nwriters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) nfsd4_cld_get_version(struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) struct cld_upcall *cup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) uint8_t version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) cup = alloc_cld_upcall(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) if (!cup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) cup->cu_u.cu_msg.cm_cmd = Cld_GetVersion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) ret = cld_pipe_upcall(cn->cn_pipe, &cup->cu_u.cu_msg, nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) ret = cup->cu_u.cu_msg.cm_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) version = cup->cu_u.cu_msg.cm_u.cm_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) dprintk("%s: userspace returned version %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) __func__, version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) if (version < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) version = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) else if (version > CLD_UPCALL_VERSION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) version = CLD_UPCALL_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) switch (version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) nn->client_tracking_ops = &nfsd4_cld_tracking_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) nn->client_tracking_ops = &nfsd4_cld_tracking_ops_v2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) free_cld_upcall(cup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) dprintk("%s: Unable to get version from userspace: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) nfsd4_cld_tracking_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) bool running;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) int retries = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) struct crypto_shash *tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) status = nfs4_cld_state_init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) status = __nfsd4_init_cld_pipe(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) goto err_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) * rpc pipe upcalls take 30 seconds to time out, so we don't want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) * queue an upcall unless we know that nfsdcld is running (because we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) * want this to fail fast so that nfsd4_client_tracking_init() can try
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) * the next client tracking method). nfsdcld should already be running
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) * before nfsd is started, so the wait here is for nfsdcld to open the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) * pipefs file we just created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) while (!(running = cld_running(nn)) && retries--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) msleep(100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) if (!running) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) status = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) goto err_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) tfm = crypto_alloc_shash("sha256", 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) if (IS_ERR(tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) status = PTR_ERR(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) goto err_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) nn->cld_net->cn_tfm = tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) status = nfsd4_cld_get_version(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) if (status == -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) pr_warn("NFSD: nfsdcld GetVersion upcall failed. Please upgrade nfsdcld.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) status = nfsd4_cld_grace_start(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) if (status == -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) pr_warn("NFSD: nfsdcld GraceStart upcall failed. Please upgrade nfsdcld.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) nfs4_release_reclaim(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) goto err_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) printk("NFSD: Using nfsdcld client tracking operations.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) err_remove:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) nfsd4_remove_cld_pipe(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) err_shutdown:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) nfs4_cld_state_shutdown(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) nfsd4_cld_tracking_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) nfs4_release_reclaim(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) nfsd4_remove_cld_pipe(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) nfs4_cld_state_shutdown(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) /* For older nfsdcld's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops_v0 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) .init = nfsd4_init_cld_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) .exit = nfsd4_remove_cld_pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) .create = nfsd4_cld_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) .remove = nfsd4_cld_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) .check = nfsd4_cld_check_v0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) .grace_done = nfsd4_cld_grace_done_v0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) .version = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) .msglen = sizeof(struct cld_msg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) /* For newer nfsdcld's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) .init = nfsd4_cld_tracking_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) .exit = nfsd4_cld_tracking_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) .create = nfsd4_cld_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) .remove = nfsd4_cld_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) .check = nfsd4_cld_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) .grace_done = nfsd4_cld_grace_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) .version = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) .msglen = sizeof(struct cld_msg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) /* v2 create/check ops include the principal, if available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) static const struct nfsd4_client_tracking_ops nfsd4_cld_tracking_ops_v2 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) .init = nfsd4_cld_tracking_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) .exit = nfsd4_cld_tracking_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) .create = nfsd4_cld_create_v2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) .remove = nfsd4_cld_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) .check = nfsd4_cld_check_v2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) .grace_done = nfsd4_cld_grace_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) .version = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) .msglen = sizeof(struct cld_msg_v2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) /* upcall via usermodehelper */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) static char cltrack_prog[PATH_MAX] = "/sbin/nfsdcltrack";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) module_param_string(cltrack_prog, cltrack_prog, sizeof(cltrack_prog),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) S_IRUGO|S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) MODULE_PARM_DESC(cltrack_prog, "Path to the nfsdcltrack upcall program");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) static bool cltrack_legacy_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) module_param(cltrack_legacy_disable, bool, S_IRUGO|S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) MODULE_PARM_DESC(cltrack_legacy_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) "Disable legacy recoverydir conversion. Default: false");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) #define LEGACY_TOPDIR_ENV_PREFIX "NFSDCLTRACK_LEGACY_TOPDIR="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) #define LEGACY_RECDIR_ENV_PREFIX "NFSDCLTRACK_LEGACY_RECDIR="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) #define HAS_SESSION_ENV_PREFIX "NFSDCLTRACK_CLIENT_HAS_SESSION="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) #define GRACE_START_ENV_PREFIX "NFSDCLTRACK_GRACE_START="
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) static char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) nfsd4_cltrack_legacy_topdir(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) int copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) char *result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) if (cltrack_legacy_disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) len = strlen(LEGACY_TOPDIR_ENV_PREFIX) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) strlen(nfs4_recoverydir()) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) result = kmalloc(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) if (!result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) copied = snprintf(result, len, LEGACY_TOPDIR_ENV_PREFIX "%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) nfs4_recoverydir());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) if (copied >= len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) /* just return nothing if output was truncated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) kfree(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) static char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) nfsd4_cltrack_legacy_recdir(const struct xdr_netobj *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) int copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) char *result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) if (cltrack_legacy_disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) /* +1 is for '/' between "topdir" and "recdir" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) len = strlen(LEGACY_RECDIR_ENV_PREFIX) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) strlen(nfs4_recoverydir()) + 1 + HEXDIR_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) result = kmalloc(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) if (!result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) copied = snprintf(result, len, LEGACY_RECDIR_ENV_PREFIX "%s/",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) nfs4_recoverydir());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) if (copied > (len - HEXDIR_LEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) /* just return nothing if output will be truncated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) kfree(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) copied = nfs4_make_rec_clidname(result + copied, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) if (copied) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) kfree(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) static char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) nfsd4_cltrack_client_has_session(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) int copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) char *result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) /* prefix + Y/N character + terminating NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) len = strlen(HAS_SESSION_ENV_PREFIX) + 1 + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) result = kmalloc(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) if (!result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) copied = snprintf(result, len, HAS_SESSION_ENV_PREFIX "%c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) clp->cl_minorversion ? 'Y' : 'N');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) if (copied >= len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) /* just return nothing if output was truncated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) kfree(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) static char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) nfsd4_cltrack_grace_start(time64_t grace_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) int copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) char *result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) /* prefix + max width of int64_t string + terminating NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) len = strlen(GRACE_START_ENV_PREFIX) + 22 + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) result = kmalloc(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) if (!result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) copied = snprintf(result, len, GRACE_START_ENV_PREFIX "%lld",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) grace_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) if (copied >= len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) /* just return nothing if output was truncated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) kfree(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) nfsd4_umh_cltrack_upcall(char *cmd, char *arg, char *env0, char *env1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) char *envp[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) char *argv[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) if (unlikely(!cltrack_prog[0])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) dprintk("%s: cltrack_prog is disabled\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) dprintk("%s: cmd: %s\n", __func__, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) dprintk("%s: arg: %s\n", __func__, arg ? arg : "(null)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) dprintk("%s: env0: %s\n", __func__, env0 ? env0 : "(null)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) dprintk("%s: env1: %s\n", __func__, env1 ? env1 : "(null)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) envp[0] = env0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) envp[1] = env1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) envp[2] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) argv[0] = (char *)cltrack_prog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) argv[1] = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) argv[2] = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) argv[3] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) * Disable the upcall mechanism if we're getting an ENOENT or EACCES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) * error. The admin can re-enable it on the fly by using sysfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) * once the problem has been fixed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) if (ret == -ENOENT || ret == -EACCES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) dprintk("NFSD: %s was not found or isn't executable (%d). "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) "Setting cltrack_prog to blank string!",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) cltrack_prog, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) cltrack_prog[0] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) dprintk("%s: %s return value: %d\n", __func__, cltrack_prog, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) static char *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) bin_to_hex_dup(const unsigned char *src, int srclen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) /* +1 for terminating NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) buf = kzalloc((srclen * 2) + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) bin2hex(buf, src, srclen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) return buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) nfsd4_umh_cltrack_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) char *grace_start = nfsd4_cltrack_grace_start(nn->boot_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) /* XXX: The usermode helper s not working in container yet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) if (net != &init_net) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) pr_warn("NFSD: attempt to initialize umh client tracking in a container ignored.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) kfree(grace_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) ret = nfsd4_umh_cltrack_upcall("init", NULL, grace_start, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) kfree(grace_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) printk("NFSD: Using UMH upcall client tracking operations.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) nfsd4_cltrack_upcall_lock(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) wait_on_bit_lock(&clp->cl_flags, NFSD4_CLIENT_UPCALL_LOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) nfsd4_cltrack_upcall_unlock(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) smp_mb__before_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) clear_bit(NFSD4_CLIENT_UPCALL_LOCK, &clp->cl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) smp_mb__after_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) wake_up_bit(&clp->cl_flags, NFSD4_CLIENT_UPCALL_LOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) nfsd4_umh_cltrack_create(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) char *hexid, *has_session, *grace_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) * With v4.0 clients, there's little difference in outcome between a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) * create and check operation, and we can end up calling into this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) * function multiple times per client (once for each openowner). So,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) * for v4.0 clients skip upcalling once the client has been recorded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) * on stable storage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) * For v4.1+ clients, the outcome of the two operations is different,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) * so we must ensure that we upcall for the create operation. v4.1+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) * clients call this on RECLAIM_COMPLETE though, so we should only end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) * up doing a single create upcall per client.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) if (clp->cl_minorversion == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) if (!hexid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) dprintk("%s: can't allocate memory for upcall!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) has_session = nfsd4_cltrack_client_has_session(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) grace_start = nfsd4_cltrack_grace_start(nn->boot_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) nfsd4_cltrack_upcall_lock(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) if (!nfsd4_umh_cltrack_upcall("create", hexid, has_session, grace_start))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) nfsd4_cltrack_upcall_unlock(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) kfree(has_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) kfree(grace_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) kfree(hexid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) nfsd4_umh_cltrack_remove(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) char *hexid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) if (!test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) if (!hexid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) dprintk("%s: can't allocate memory for upcall!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) nfsd4_cltrack_upcall_lock(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) nfsd4_umh_cltrack_upcall("remove", hexid, NULL, NULL) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) nfsd4_cltrack_upcall_unlock(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) kfree(hexid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) nfsd4_umh_cltrack_check(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) char *hexid, *has_session, *legacy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) hexid = bin_to_hex_dup(clp->cl_name.data, clp->cl_name.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) if (!hexid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) dprintk("%s: can't allocate memory for upcall!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) has_session = nfsd4_cltrack_client_has_session(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) legacy = nfsd4_cltrack_legacy_recdir(&clp->cl_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) nfsd4_cltrack_upcall_lock(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) if (test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) ret = nfsd4_umh_cltrack_upcall("check", hexid, has_session, legacy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) nfsd4_cltrack_upcall_unlock(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) kfree(has_session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) kfree(legacy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) kfree(hexid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) nfsd4_umh_cltrack_grace_done(struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) char *legacy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) char timestr[22]; /* FIXME: better way to determine max size? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) sprintf(timestr, "%lld", nn->boot_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) legacy = nfsd4_cltrack_legacy_topdir();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) nfsd4_umh_cltrack_upcall("gracedone", timestr, legacy, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) kfree(legacy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) static const struct nfsd4_client_tracking_ops nfsd4_umh_tracking_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) .init = nfsd4_umh_cltrack_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) .exit = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) .create = nfsd4_umh_cltrack_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) .remove = nfsd4_umh_cltrack_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) .check = nfsd4_umh_cltrack_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) .grace_done = nfsd4_umh_cltrack_grace_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) .version = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) .msglen = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) nfsd4_client_tracking_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) struct path path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) /* just run the init if it the method is already decided */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) if (nn->client_tracking_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) goto do_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) /* First, try to use nfsdcld */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) nn->client_tracking_ops = &nfsd4_cld_tracking_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) status = nn->client_tracking_ops->init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) if (!status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) if (status != -ETIMEDOUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) nn->client_tracking_ops = &nfsd4_cld_tracking_ops_v0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) status = nn->client_tracking_ops->init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) if (!status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) * Next, try the UMH upcall.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) nn->client_tracking_ops = &nfsd4_umh_tracking_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) status = nn->client_tracking_ops->init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) if (!status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) * Finally, See if the recoverydir exists and is a directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) * If it is, then use the legacy ops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) nn->client_tracking_ops = &nfsd4_legacy_tracking_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) status = kern_path(nfs4_recoverydir(), LOOKUP_FOLLOW, &path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) if (!status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) status = d_is_dir(path.dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) path_put(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) if (!status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) do_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) status = nn->client_tracking_ops->init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) printk(KERN_WARNING "NFSD: Unable to initialize client "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) "recovery tracking! (%d)\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) nn->client_tracking_ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) nfsd4_client_tracking_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) if (nn->client_tracking_ops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) if (nn->client_tracking_ops->exit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) nn->client_tracking_ops->exit(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) nn->client_tracking_ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) nfsd4_client_record_create(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) if (nn->client_tracking_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) nn->client_tracking_ops->create(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) nfsd4_client_record_remove(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) if (nn->client_tracking_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) nn->client_tracking_ops->remove(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) nfsd4_client_record_check(struct nfs4_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) if (nn->client_tracking_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) return nn->client_tracking_ops->check(clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) nfsd4_record_grace_done(struct nfsd_net *nn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) if (nn->client_tracking_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) nn->client_tracking_ops->grace_done(nn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) rpc_pipefs_event(struct notifier_block *nb, unsigned long event, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) struct super_block *sb = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) struct net *net = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) struct nfsd_net *nn = net_generic(net, nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) struct cld_net *cn = nn->cld_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) if (!try_module_get(THIS_MODULE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) if (!cn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) case RPC_PIPEFS_MOUNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) dentry = nfsd4_cld_register_sb(sb, cn->cn_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) ret = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) cn->cn_pipe->dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) case RPC_PIPEFS_UMOUNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) if (cn->cn_pipe->dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) nfsd4_cld_unregister_sb(cn->cn_pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) ret = -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) static struct notifier_block nfsd4_cld_block = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) .notifier_call = rpc_pipefs_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) register_cld_notifier(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) WARN_ON(!nfsd_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) return rpc_pipefs_notifier_register(&nfsd4_cld_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) unregister_cld_notifier(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) rpc_pipefs_notifier_unregister(&nfsd4_cld_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) }