da9030_battery: Include notifier.h
[platform/adaptation/renesas_rcar/renesas_kernel.git] / fs / nfsd / nfs4recover.c
index 376692a..ba6fdd4 100644 (file)
@@ -58,14 +58,11 @@ struct nfsd4_client_tracking_ops {
        void (*create)(struct nfs4_client *);
        void (*remove)(struct nfs4_client *);
        int (*check)(struct nfs4_client *);
-       void (*grace_done)(struct net *, time_t);
+       void (*grace_done)(struct nfsd_net *, time_t);
 };
 
 /* Globals */
-static struct file *rec_file;
 static char user_recovery_dirname[PATH_MAX] = "/var/lib/nfs/v4recovery";
-static struct nfsd4_client_tracking_ops *client_tracking_ops;
-static bool in_grace;
 
 static int
 nfs4_save_creds(const struct cred **original_creds)
@@ -182,7 +179,7 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)
 
        if (test_and_set_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
                return;
-       if (!rec_file)
+       if (!nn->rec_file)
                return;
 
        status = nfs4_make_rec_clidname(dname, &clp->cl_name);
@@ -193,11 +190,11 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)
        if (status < 0)
                return;
 
-       status = mnt_want_write_file(rec_file);
+       status = mnt_want_write_file(nn->rec_file);
        if (status)
                return;
 
-       dir = rec_file->f_path.dentry;
+       dir = nn->rec_file->f_path.dentry;
        /* lock the parent */
        mutex_lock(&dir->d_inode->i_mutex);
 
@@ -222,19 +219,19 @@ out_put:
 out_unlock:
        mutex_unlock(&dir->d_inode->i_mutex);
        if (status == 0) {
-               if (in_grace) {
+               if (nn->in_grace) {
                        crp = nfs4_client_to_reclaim(dname, nn);
                        if (crp)
                                crp->cr_clp = clp;
                }
-               vfs_fsync(rec_file, 0);
+               vfs_fsync(nn->rec_file, 0);
        } else {
                printk(KERN_ERR "NFSD: failed to write recovery record"
                                " (err %d); please check that %s exists"
                                " and is writeable", status,
                                user_recovery_dirname);
        }
-       mnt_drop_write_file(rec_file);
+       mnt_drop_write_file(nn->rec_file);
        nfs4_reset_creds(original_cred);
 }
 
@@ -267,7 +264,7 @@ static int
 nfsd4_list_rec_dir(recdir_func *f, struct nfsd_net *nn)
 {
        const struct cred *original_cred;
-       struct dentry *dir = rec_file->f_path.dentry;
+       struct dentry *dir = nn->rec_file->f_path.dentry;
        LIST_HEAD(names);
        int status;
 
@@ -275,13 +272,13 @@ nfsd4_list_rec_dir(recdir_func *f, struct nfsd_net *nn)
        if (status < 0)
                return status;
 
-       status = vfs_llseek(rec_file, 0, SEEK_SET);
+       status = vfs_llseek(nn->rec_file, 0, SEEK_SET);
        if (status < 0) {
                nfs4_reset_creds(original_cred);
                return status;
        }
 
-       status = vfs_readdir(rec_file, nfsd4_build_namelist, &names);
+       status = vfs_readdir(nn->rec_file, nfsd4_build_namelist, &names);
        mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
        while (!list_empty(&names)) {
                struct name_list *entry;
@@ -305,14 +302,14 @@ nfsd4_list_rec_dir(recdir_func *f, struct nfsd_net *nn)
 }
 
 static int
-nfsd4_unlink_clid_dir(char *name, int namlen)
+nfsd4_unlink_clid_dir(char *name, int namlen, struct nfsd_net *nn)
 {
        struct dentry *dir, *dentry;
        int status;
 
        dprintk("NFSD: nfsd4_unlink_clid_dir. name %.*s\n", namlen, name);
 
-       dir = rec_file->f_path.dentry;
+       dir = nn->rec_file->f_path.dentry;
        mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
        dentry = lookup_one_len(name, dir, namlen);
        if (IS_ERR(dentry)) {
@@ -339,14 +336,14 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp)
        int status;
        struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
 
-       if (!rec_file || !test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
+       if (!nn->rec_file || !test_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags))
                return;
 
        status = nfs4_make_rec_clidname(dname, &clp->cl_name);
        if (status)
                return legacy_recdir_name_error(status);
 
-       status = mnt_want_write_file(rec_file);
+       status = mnt_want_write_file(nn->rec_file);
        if (status)
                goto out;
        clear_bit(NFSD4_CLIENT_STABLE, &clp->cl_flags);
@@ -355,11 +352,11 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp)
        if (status < 0)
                goto out_drop_write;
 
-       status = nfsd4_unlink_clid_dir(dname, HEXDIR_LEN-1);
+       status = nfsd4_unlink_clid_dir(dname, HEXDIR_LEN-1, nn);
        nfs4_reset_creds(original_cred);
        if (status == 0) {
-               vfs_fsync(rec_file, 0);
-               if (in_grace) {
+               vfs_fsync(nn->rec_file, 0);
+               if (nn->in_grace) {
                        /* remove reclaim record */
                        crp = nfsd4_find_reclaim_client(dname, nn);
                        if (crp)
@@ -367,7 +364,7 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp)
                }
        }
 out_drop_write:
-       mnt_drop_write_file(rec_file);
+       mnt_drop_write_file(nn->rec_file);
 out:
        if (status)
                printk("NFSD: Failed to remove expired client state directory"
@@ -391,26 +388,25 @@ purge_old(struct dentry *parent, struct dentry *child, struct nfsd_net *nn)
 }
 
 static void
-nfsd4_recdir_purge_old(struct net *net, time_t boot_time)
+nfsd4_recdir_purge_old(struct nfsd_net *nn, time_t boot_time)
 {
        int status;
-       struct nfsd_net *nn = net_generic(net, nfsd_net_id);
 
-       in_grace = false;
-       if (!rec_file)
+       nn->in_grace = false;
+       if (!nn->rec_file)
                return;
-       status = mnt_want_write_file(rec_file);
+       status = mnt_want_write_file(nn->rec_file);
        if (status)
                goto out;
        status = nfsd4_list_rec_dir(purge_old, nn);
        if (status == 0)
-               vfs_fsync(rec_file, 0);
-       mnt_drop_write_file(rec_file);
+               vfs_fsync(nn->rec_file, 0);
+       mnt_drop_write_file(nn->rec_file);
 out:
        nfs4_release_reclaim(nn);
        if (status)
                printk("nfsd4: failed to purge old clients from recovery"
-                       " directory %s\n", rec_file->f_path.dentry->d_name.name);
+                       " directory %s\n", nn->rec_file->f_path.dentry->d_name.name);
 }
 
 static int
@@ -431,13 +427,13 @@ nfsd4_recdir_load(struct net *net) {
        int status;
        struct nfsd_net *nn =  net_generic(net, nfsd_net_id);
 
-       if (!rec_file)
+       if (!nn->rec_file)
                return 0;
 
        status = nfsd4_list_rec_dir(load_recdir, nn);
        if (status)
                printk("nfsd4: failed loading clients from recovery"
-                       " directory %s\n", rec_file->f_path.dentry->d_name.name);
+                       " directory %s\n", nn->rec_file->f_path.dentry->d_name.name);
        return status;
 }
 
@@ -446,15 +442,16 @@ nfsd4_recdir_load(struct net *net) {
  */
 
 static int
-nfsd4_init_recdir(void)
+nfsd4_init_recdir(struct net *net)
 {
+       struct nfsd_net *nn = net_generic(net, nfsd_net_id);
        const struct cred *original_cred;
        int status;
 
        printk("NFSD: Using %s as the NFSv4 state recovery directory\n",
                        user_recovery_dirname);
 
-       BUG_ON(rec_file);
+       BUG_ON(nn->rec_file);
 
        status = nfs4_save_creds(&original_cred);
        if (status < 0) {
@@ -464,17 +461,17 @@ nfsd4_init_recdir(void)
                return status;
        }
 
-       rec_file = filp_open(user_recovery_dirname, O_RDONLY | O_DIRECTORY, 0);
-       if (IS_ERR(rec_file)) {
+       nn->rec_file = filp_open(user_recovery_dirname, O_RDONLY | O_DIRECTORY, 0);
+       if (IS_ERR(nn->rec_file)) {
                printk("NFSD: unable to find recovery directory %s\n",
                                user_recovery_dirname);
-               status = PTR_ERR(rec_file);
-               rec_file = NULL;
+               status = PTR_ERR(nn->rec_file);
+               nn->rec_file = NULL;
        }
 
        nfs4_reset_creds(original_cred);
        if (!status)
-               in_grace = true;
+               nn->in_grace = true;
        return status;
 }
 
@@ -510,11 +507,9 @@ nfsd4_load_reboot_recovery_data(struct net *net)
 {
        int status;
 
-       nfs4_lock_state();
-       status = nfsd4_init_recdir();
+       status = nfsd4_init_recdir(net);
        if (!status)
                status = nfsd4_recdir_load(net);
-       nfs4_unlock_state();
        if (status)
                printk(KERN_ERR "NFSD: Failure reading reboot recovery data\n");
        return status;
@@ -547,12 +542,12 @@ err:
 }
 
 static void
-nfsd4_shutdown_recdir(void)
+nfsd4_shutdown_recdir(struct nfsd_net *nn)
 {
-       if (!rec_file)
+       if (!nn->rec_file)
                return;
-       fput(rec_file);
-       rec_file = NULL;
+       fput(nn->rec_file);
+       nn->rec_file = NULL;
 }
 
 static void
@@ -561,7 +556,7 @@ nfsd4_legacy_tracking_exit(struct net *net)
        struct nfsd_net *nn = net_generic(net, nfsd_net_id);
 
        nfs4_release_reclaim(nn);
-       nfsd4_shutdown_recdir();
+       nfsd4_shutdown_recdir(nn);
        nfs4_legacy_state_shutdown(net);
 }
 
@@ -1017,11 +1012,10 @@ nfsd4_cld_check(struct nfs4_client *clp)
 }
 
 static void
-nfsd4_cld_grace_done(struct net *net, time_t boot_time)
+nfsd4_cld_grace_done(struct nfsd_net *nn, time_t boot_time)
 {
        int ret;
        struct cld_upcall *cup;
-       struct nfsd_net *nn = net_generic(net, nfsd_net_id);
        struct cld_net *cn = nn->cld_net;
 
        cup = alloc_cld_upcall(cn);
@@ -1241,7 +1235,7 @@ nfsd4_umh_cltrack_check(struct nfs4_client *clp)
 }
 
 static void
-nfsd4_umh_cltrack_grace_done(struct net __attribute__((unused)) *net,
+nfsd4_umh_cltrack_grace_done(struct nfsd_net __attribute__((unused)) *nn,
                                time_t boot_time)
 {
        char *legacy;
@@ -1267,17 +1261,18 @@ nfsd4_client_tracking_init(struct net *net)
 {
        int status;
        struct path path;
+       struct nfsd_net *nn = net_generic(net, nfsd_net_id);
 
        /* just run the init if it the method is already decided */
-       if (client_tracking_ops)
+       if (nn->client_tracking_ops)
                goto do_init;
 
        /*
         * First, try a UMH upcall. It should succeed or fail quickly, so
         * there's little harm in trying that first.
         */
-       client_tracking_ops = &nfsd4_umh_tracking_ops;
-       status = client_tracking_ops->init(net);
+       nn->client_tracking_ops = &nfsd4_umh_tracking_ops;
+       status = nn->client_tracking_ops->init(net);
        if (!status)
                return status;
 
@@ -1285,7 +1280,7 @@ nfsd4_client_tracking_init(struct net *net)
         * See if the recoverydir exists and is a directory. If it is,
         * then use the legacy ops.
         */
-       client_tracking_ops = &nfsd4_legacy_tracking_ops;
+       nn->client_tracking_ops = &nfsd4_legacy_tracking_ops;
        status = kern_path(nfs4_recoverydir(), LOOKUP_FOLLOW, &path);
        if (!status) {
                status = S_ISDIR(path.dentry->d_inode->i_mode);
@@ -1295,16 +1290,16 @@ nfsd4_client_tracking_init(struct net *net)
        }
 
        /* Finally, try to use nfsdcld */
-       client_tracking_ops = &nfsd4_cld_tracking_ops;
+       nn->client_tracking_ops = &nfsd4_cld_tracking_ops;
        printk(KERN_WARNING "NFSD: the nfsdcld client tracking upcall will be "
                        "removed in 3.10. Please transition to using "
                        "nfsdcltrack.\n");
 do_init:
-       status = client_tracking_ops->init(net);
+       status = nn->client_tracking_ops->init(net);
        if (status) {
                printk(KERN_WARNING "NFSD: Unable to initialize client "
                                    "recovery tracking! (%d)\n", status);
-               client_tracking_ops = NULL;
+               nn->client_tracking_ops = NULL;
        }
        return status;
 }
@@ -1312,41 +1307,49 @@ do_init:
 void
 nfsd4_client_tracking_exit(struct net *net)
 {
-       if (client_tracking_ops) {
-               if (client_tracking_ops->exit)
-                       client_tracking_ops->exit(net);
-               client_tracking_ops = NULL;
+       struct nfsd_net *nn = net_generic(net, nfsd_net_id);
+
+       if (nn->client_tracking_ops) {
+               if (nn->client_tracking_ops->exit)
+                       nn->client_tracking_ops->exit(net);
+               nn->client_tracking_ops = NULL;
        }
 }
 
 void
 nfsd4_client_record_create(struct nfs4_client *clp)
 {
-       if (client_tracking_ops)
-               client_tracking_ops->create(clp);
+       struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
+
+       if (nn->client_tracking_ops)
+               nn->client_tracking_ops->create(clp);
 }
 
 void
 nfsd4_client_record_remove(struct nfs4_client *clp)
 {
-       if (client_tracking_ops)
-               client_tracking_ops->remove(clp);
+       struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
+
+       if (nn->client_tracking_ops)
+               nn->client_tracking_ops->remove(clp);
 }
 
 int
 nfsd4_client_record_check(struct nfs4_client *clp)
 {
-       if (client_tracking_ops)
-               return client_tracking_ops->check(clp);
+       struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
+
+       if (nn->client_tracking_ops)
+               return nn->client_tracking_ops->check(clp);
 
        return -EOPNOTSUPP;
 }
 
 void
-nfsd4_record_grace_done(struct net *net, time_t boot_time)
+nfsd4_record_grace_done(struct nfsd_net *nn, time_t boot_time)
 {
-       if (client_tracking_ops)
-               client_tracking_ops->grace_done(net, boot_time);
+       if (nn->client_tracking_ops)
+               nn->client_tracking_ops->grace_done(nn, boot_time);
 }
 
 static int