Skip to contentSkip to conversation

NFSD: delay unmount source's export after inter-server copy completed.

PATCH Superseded Dai Ngo 3 participants 15 messages May 17, 2021 – May 18, 2021

Subsystems (2)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Dai Ngo

author reviewer
#0 lore raw

v5 cover NFSD: delay unmount source's export after inter-server copy completed.

Hi Olga, Bruce,

Currently the source's export is mounted and unmounted on every inter-server copy operation. This causes unnecessary overhead for each copy.

This patch series is an enhancement to allow the export to remain mounted for a configurable period (default to 15 minutes). If the export is not being used for the configured time it will be unmounted by a delayed task. If it's used again then its expiration time is extended for another period.

Since mount and unmount are no longer done on every copy request, the restriction of copy size (14*rsize), in __nfs4_copy_file_range, is removed.

-Dai

v2: fix compiler warning of missing prototype.
v3: remove the used of semaphore.
eliminated all RPC calls for subsequence mount by allowing
all exports from one server to share one vfsmount.
make inter-server threshold a module configuration parameter.
v4: convert nsui_refcnt to use refcount_t.
add note about 20secs wait in nfsd4_interssc_connect. removed (14*rsize) restriction from __nfs4_copy_file_range.
v5: make use of the laundomat thread to service delayed unmount list.
destroy delayed unmount list when nfsd is shutdown. make delayed unmount list per nfsd_net to support container.

author reviewer
#1 lore raw

PATCH v5 1/2 NFSD: delay unmount source's export after inter-server copy completed.

Currently the source's export is mounted and unmounted on every inter-server copy operation. This patch is an enhancement to delay the unmount of the source export for a certain period of time to eliminate the mount and unmount overhead on subsequent copy operations.

After a copy operation completes, a delayed task is scheduled to unmount the export after a configurable idle time. Each time the export is being used again, its expire time is extended to allow the export to remain mounted.

The unmount task and the mount operation of the copy request are synced to make sure the export is not unmounted while it's being used.

---
 fs/nfsd/netns.h         |   5 ++
 fs/nfsd/nfs4proc.c      | 216 +++++++++++++++++++++++++++++++++++++++++++++++-
 fs/nfsd/nfs4state.c     |   8 ++
 fs/nfsd/nfsd.h          |   6 ++
 fs/nfsd/nfssvc.c        |   3 +
 include/linux/nfs_ssc.h |  16 ++++
 6 files changed, 250 insertions(+), 4 deletions(-)
fs/nfsd/netns.h +5 -0
index c330f5bd0cf3..6018e5050cb4 100644
@@ -21,6 +21,7 @@
 
 struct cld_net;
 struct nfsd4_client_tracking_ops;
+struct nfsd4_ssc_umount;
 
 enum {
 	/* cache misses due only to checksum comparison failures */
@@ -176,6 +177,10 @@ struct nfsd_net {
 	unsigned int             longest_chain_cachesize;
 
 	struct shrinker		nfsd_reply_cache_shrinker;
+
+	spinlock_t              nfsd_ssc_lock;
+	struct nfsd4_ssc_umount	*nfsd_ssc_umount;
+
 	/* utsname taken from the process that starts the server */
 	char			nfsd_name[UNX_MAXNODENAME+1];
 };
fs/nfsd/nfs4proc.c +212 -4

246 lines not on this page · raw message

fs/nfsd/nfs4state.c +8 -0
index 97447a64bad0..0cdc898f06c9 100644
@@ -5459,6 +5459,11 @@ nfs4_laundromat(struct nfsd_net *nn)
 		list_del_init(&nbl->nbl_lru);
 		free_blocked_lock(nbl);
 	}
+
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+	/* service the inter-copy delayed unmount list */
+	nfsd4_ssc_expire_umount(nn);
+#endif
 out:
 	new_timeo = max_t(time64_t, new_timeo, NFSD_LAUNDROMAT_MINTIMEOUT);
 	return new_timeo;
@@ -7398,6 +7403,9 @@ nfs4_state_shutdown_net(struct net *net)
 
 	nfsd4_client_tracking_exit(net);
 	nfs4_state_destroy_net(net);
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+	nfsd4_ssc_shutdown_umount(nn);
+#endif
 	mntput(nn->nfsd_mnt);
 }
 
fs/nfsd/nfsd.h +6 -0
index 8bdc37aa2c2e..cf86d9010974 100644
@@ -483,6 +483,12 @@ static inline bool nfsd_attrs_supported(u32 minorversion, const u32 *bmval)
 extern int nfsd4_is_junction(struct dentry *dentry);
 extern int register_cld_notifier(void);
 extern void unregister_cld_notifier(void);
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+extern void nfsd4_ssc_init_umount_work(struct nfsd_net *nn);
+extern void nfsd4_ssc_expire_umount(struct nfsd_net *nn);
+extern void nfsd4_ssc_shutdown_umount(struct nfsd_net *nn);
+#endif
+
 #else /* CONFIG_NFSD_V4 */
 static inline int nfsd4_is_junction(struct dentry *dentry)
 {
fs/nfsd/nfssvc.c +3 -0
index 6de406322106..ce89a8fe07ff 100644
@@ -403,6 +403,9 @@ static int nfsd_startup_net(int nrservs, struct net *net, const struct cred *cre
 	if (ret)
 		goto out_filecache;
 
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+	nfsd4_ssc_init_umount_work(nn);
+#endif
 	nn->nfsd_net_up = true;
 	return 0;
 
include/linux/nfs_ssc.h +16 -0
index f5ba0fbff72f..18afe62988b5 100644
@@ -8,6 +8,7 @@
  */
 
 #include <linux/nfs_fs.h>
+#include <linux/sunrpc/svc.h>
 
 extern struct nfs_ssc_client_ops_tbl nfs_ssc_client_tbl;
 
@@ -52,6 +53,21 @@ static inline void nfs42_ssc_close(struct file *filep)
 	if (nfs_ssc_client_tbl.ssc_nfs4_ops)
 		(*nfs_ssc_client_tbl.ssc_nfs4_ops->sco_close)(filep);
 }
+
+struct nfsd4_ssc_umount_item {
+	struct list_head nsui_list;
+	bool nsui_busy;
+	refcount_t nsui_refcnt;
+	unsigned long nsui_expire;
+	struct vfsmount *nsui_vfsmount;
+	char nsui_ipaddr[RPC_MAX_ADDRBUFLEN];
+};
+
+struct nfsd4_ssc_umount {
+	struct list_head nsu_list;
+	unsigned long nsu_expire;
+	wait_queue_head_t nsu_waitq;
+};
 #endif
 
 /*
Signature · 1 line
2.9.5
#2 lore raw
Quoted 6 lines · Dai Ngo

Currently the source's export is mounted and unmounted on every inter-server copy operation. This patch is an enhancement to delay the unmount of the source export for a certain period of time to eliminate the mount and unmount overhead on subsequent copy operations.

Quoted 8 lines

After a copy operation completes, a delayed task is scheduled to unmount the export after a configurable idle time. Each time the export is being used again, its expire time is extended to allow the export to remain mounted.

The unmount task and the mount operation of the copy request are synced to make sure the export is not unmounted while it's being used.

Can you tell me what this should apply on top of? It doesn't apply to 5.13-rc2. I know Chuck posted a lot of nfsd patches which I don't have, is your patch on top of that?

Quoted 382 lines
---
 fs/nfsd/netns.h         |   5 ++
 fs/nfsd/nfs4proc.c      | 216 +++++++++++++++++++++++++++++++++++++++++++++++-
 fs/nfsd/nfs4state.c     |   8 ++
 fs/nfsd/nfsd.h          |   6 ++
 fs/nfsd/nfssvc.c        |   3 +
 include/linux/nfs_ssc.h |  16 ++++
 6 files changed, 250 insertions(+), 4 deletions(-)
fs/nfsd/netns.h +5 -0
index c330f5bd0cf3..6018e5050cb4 100644
@@ -21,6 +21,7 @@
 
 struct cld_net;
 struct nfsd4_client_tracking_ops;
+struct nfsd4_ssc_umount;
 
 enum {
        /* cache misses due only to checksum comparison failures */
@@ -176,6 +177,10 @@ struct nfsd_net {
        unsigned int             longest_chain_cachesize;
 
        struct shrinker         nfsd_reply_cache_shrinker;
+
+       spinlock_t              nfsd_ssc_lock;
+       struct nfsd4_ssc_umount *nfsd_ssc_umount;
+
        /* utsname taken from the process that starts the server */
        char                    nfsd_name[UNX_MAXNODENAME+1];
 };
fs/nfsd/nfs4proc.c +212 -4
index dd9f38d072dd..892ad72d87ae 100644
@@ -55,6 +55,99 @@ module_param(inter_copy_offload_enable, bool, 0644);
 MODULE_PARM_DESC(inter_copy_offload_enable,
                 "Enable inter server to server copy offload. Default: false");
 
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+static int nfsd4_ssc_umount_timeout = 900000;          /* default to 15 mins */
+module_param(nfsd4_ssc_umount_timeout, int, 0644);
+MODULE_PARM_DESC(nfsd4_ssc_umount_timeout,
+               "idle msecs before unmount export from source server");
+
+void nfsd4_ssc_expire_umount(struct nfsd_net *nn)
+{
+       bool do_wakeup = false;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount *nu;
+
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (time_after(jiffies, ni->nsui_expire)) {
+                       if (refcount_read(&ni->nsui_refcnt) > 0)
+                               continue;
+
+                       /* mark being unmount */
+                       ni->nsui_busy = true;
+                       spin_unlock(&nn->nfsd_ssc_lock);
+                       mntput(ni->nsui_vfsmount);
+                       spin_lock(&nn->nfsd_ssc_lock);
+
+                       /* waiters need to start from begin of list */
+                       list_del(&ni->nsui_list);
+                       kfree(ni);
+
+                       /* wakeup ssc_connect waiters */
+                       do_wakeup = true;
+                       continue;
+               }
+               break;
+       }
+       if (!list_empty(&nu->nsu_list)) {
+               ni = list_first_entry(&nu->nsu_list,
+                       struct nfsd4_ssc_umount_item, nsui_list);
+               nu->nsu_expire = ni->nsui_expire;
+       } else
+               nu->nsu_expire = 0;
+
+       if (do_wakeup)
+               wake_up_all(&nu->nsu_waitq);
+       spin_unlock(&nn->nfsd_ssc_lock);
+}
+
+/*
+ * This is called when nfsd is being shutdown, after all inter_ssc
+ * cleanup were done, to destroy the ssc delayed unmount list.
+ */
+void nfsd4_ssc_shutdown_umount(struct nfsd_net *nn)
+{
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount *nu;
+
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;
+       nn->nfsd_ssc_umount = 0;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               list_del(&ni->nsui_list);
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ni->nsui_vfsmount);
+               kfree(ni);
+               spin_lock(&nn->nfsd_ssc_lock);
+       }
+       spin_unlock(&nn->nfsd_ssc_lock);
+       kfree(nu);
+}
+
+void nfsd4_ssc_init_umount_work(struct nfsd_net *nn)
+{
+       nn->nfsd_ssc_umount = kzalloc(sizeof(struct nfsd4_ssc_umount),
+                                       GFP_KERNEL);
+       if (!nn->nfsd_ssc_umount)
+               return;
+       spin_lock_init(&nn->nfsd_ssc_lock);
+       INIT_LIST_HEAD(&nn->nfsd_ssc_umount->nsu_list);
+       init_waitqueue_head(&nn->nfsd_ssc_umount->nsu_waitq);
+}
+EXPORT_SYMBOL_GPL(nfsd4_ssc_init_umount_work);
+#endif
+
 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
 #include <linux/security.h>
 
@@ -1181,6 +1274,12 @@ nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
        char *ipaddr, *dev_name, *raw_data;
        int len, raw_len;
        __be32 status = nfserr_inval;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *work = NULL;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
+       struct nfsd4_ssc_umount *nu;
+       DEFINE_WAIT(wait);
 
        naddr = &nss->u.nl4_addr;
        tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr,
@@ -1229,12 +1328,76 @@ nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
                goto out_free_rawdata;
        snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep);
 
+       work = kzalloc(sizeof(*work), GFP_KERNEL);
+try_again:
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               kfree(work);
+               work = NULL;
+               goto skip_dul;
+       }
+       nu = nn->nfsd_ssc_umount;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (strncmp(ni->nsui_ipaddr, ipaddr, sizeof(ni->nsui_ipaddr)))
+                       continue;
+               /* found a match */
+               if (ni->nsui_busy) {
+                       /*  wait - and try again */
+                       prepare_to_wait(&nu->nsu_waitq, &wait,
+                               TASK_INTERRUPTIBLE);
+                       spin_unlock(&nn->nfsd_ssc_lock);
+
+                       /* allow 20secs for mount/unmount for now - revisit */
+                       if (signal_pending(current) ||
+                                       (schedule_timeout(20*HZ) == 0)) {
+                               status = nfserr_eagain;
+                               kfree(work);
+                               goto out_free_devname;
+                       }
+                       finish_wait(&nu->nsu_waitq, &wait);
+                       goto try_again;
+               }
+               ss_mnt = ni->nsui_vfsmount;
+               if (refcount_read(&ni->nsui_refcnt) == 0)
+                       refcount_set(&ni->nsui_refcnt, 1);
+               else
+                       refcount_inc(&ni->nsui_refcnt);
+               spin_unlock(&nn->nfsd_ssc_lock);
+               kfree(work);
+               goto out_done;
+       }
+       /* create new entry, set busy, insert list, clear busy after mount */
+       if (work) {
+               strncpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr));
+               refcount_set(&work->nsui_refcnt, 1);
+               work->nsui_busy = true;
+               list_add_tail(&work->nsui_list, &nu->nsu_list);
+       }
+       spin_unlock(&nn->nfsd_ssc_lock);
+skip_dul:
+
        /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */
        ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data);
        module_put(type->owner);
-       if (IS_ERR(ss_mnt))
+       if (IS_ERR(ss_mnt)) {
+               if (work) {
+                       spin_lock(&nn->nfsd_ssc_lock);
+                       list_del(&work->nsui_list);
+                       wake_up_all(&nu->nsu_waitq);
+                       spin_unlock(&nn->nfsd_ssc_lock);
+                       kfree(work);
+               }
                goto out_free_devname;
-
+       }
+       if (work) {
+               spin_lock(&nn->nfsd_ssc_lock);
+               work->nsui_vfsmount = ss_mnt;
+               work->nsui_busy = false;
+               wake_up_all(&nu->nsu_waitq);
+               spin_unlock(&nn->nfsd_ssc_lock);
+       }
+out_done:
        status = 0;
        *mount = ss_mnt;
 
@@ -1301,10 +1464,55 @@ static void
 nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
                        struct nfsd_file *dst)
 {
+       bool found = false;
+       bool resched = false;
+       long timeout;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount *nu;
+       struct nfsd_net *nn = net_generic(dst->nf_net, nfsd_net_id);
+
        nfs42_ssc_close(src->nf_file);
-       fput(src->nf_file);
        nfsd_file_put(dst);
-       mntput(ss_mnt);
+       fput(src->nf_file);
+
+       if (!nn) {
+               mntput(ss_mnt);
+               return;
+       }
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               /* delayed unmount list not setup */
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ss_mnt);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;
+       timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout);
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (ni->nsui_vfsmount->mnt_sb == ss_mnt->mnt_sb) {
+                       list_del(&ni->nsui_list);
+                       /*
+                        * vfsmount can be shared by multiple exports,
+                        * decrement refcnt and schedule delayed task
+                        * if it drops to 0.
+                        */
+                       if (refcount_dec_and_test(&ni->nsui_refcnt))
+                               resched = true;
+                       ni->nsui_expire = jiffies + timeout;
+                       list_add_tail(&ni->nsui_list, &nu->nsu_list);
+                       found = true;
+                       break;
+               }
+       }
+       if (!found) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ss_mnt);
+               return;
+       }
+       if (resched && !nu->nsu_expire)
+               nu->nsu_expire = ni->nsui_expire;
+       spin_unlock(&nn->nfsd_ssc_lock);
 }
 
 #else /* CONFIG_NFSD_V4_2_INTER_SSC */
fs/nfsd/nfs4state.c +8 -0
index 97447a64bad0..0cdc898f06c9 100644
@@ -5459,6 +5459,11 @@ nfs4_laundromat(struct nfsd_net *nn)
                list_del_init(&nbl->nbl_lru);
                free_blocked_lock(nbl);
        }
+
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       /* service the inter-copy delayed unmount list */
+       nfsd4_ssc_expire_umount(nn);
+#endif
 out:
        new_timeo = max_t(time64_t, new_timeo, NFSD_LAUNDROMAT_MINTIMEOUT);
        return new_timeo;
@@ -7398,6 +7403,9 @@ nfs4_state_shutdown_net(struct net *net)
 
        nfsd4_client_tracking_exit(net);
        nfs4_state_destroy_net(net);
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       nfsd4_ssc_shutdown_umount(nn);
+#endif
        mntput(nn->nfsd_mnt);
 }
 
fs/nfsd/nfsd.h +6 -0
index 8bdc37aa2c2e..cf86d9010974 100644
@@ -483,6 +483,12 @@ static inline bool nfsd_attrs_supported(u32 minorversion, const u32 *bmval)
 extern int nfsd4_is_junction(struct dentry *dentry);
 extern int register_cld_notifier(void);
 extern void unregister_cld_notifier(void);
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+extern void nfsd4_ssc_init_umount_work(struct nfsd_net *nn);
+extern void nfsd4_ssc_expire_umount(struct nfsd_net *nn);
+extern void nfsd4_ssc_shutdown_umount(struct nfsd_net *nn);
+#endif
+
 #else /* CONFIG_NFSD_V4 */
 static inline int nfsd4_is_junction(struct dentry *dentry)
 {
fs/nfsd/nfssvc.c +3 -0
index 6de406322106..ce89a8fe07ff 100644
@@ -403,6 +403,9 @@ static int nfsd_startup_net(int nrservs, struct net *net, const struct cred *cre
        if (ret)
                goto out_filecache;
 
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       nfsd4_ssc_init_umount_work(nn);
+#endif
        nn->nfsd_net_up = true;
        return 0;
 
include/linux/nfs_ssc.h +16 -1
index f5ba0fbff72f..18afe62988b5 100644
@@ -8,6 +8,7 @@
  */
 
 #include <linux/nfs_fs.h>
+#include <linux/sunrpc/svc.h>
 
 extern struct nfs_ssc_client_ops_tbl nfs_ssc_client_tbl;
 
@@ -52,6 +53,21 @@ static inline void nfs42_ssc_close(struct file *filep)
        if (nfs_ssc_client_tbl.ssc_nfs4_ops)
                (*nfs_ssc_client_tbl.ssc_nfs4_ops->sco_close)(filep);
 }
+
+struct nfsd4_ssc_umount_item {
+       struct list_head nsui_list;
+       bool nsui_busy;
+       refcount_t nsui_refcnt;
+       unsigned long nsui_expire;
+       struct vfsmount *nsui_vfsmount;
+       char nsui_ipaddr[RPC_MAX_ADDRBUFLEN];
+};
+
+struct nfsd4_ssc_umount {
+       struct list_head nsu_list;
+       unsigned long nsu_expire;
+       wait_queue_head_t nsu_waitq;
+};
 #endif
 
 /*
--

2.9.5

author reviewer
#3 lore raw
Quoted 11 lines · Olga Kornievskaia
Quoted 10 lines · Dai Ngo

Currently the source's export is mounted and unmounted on every inter-server copy operation. This patch is an enhancement to delay the unmount of the source export for a certain period of time to eliminate the mount and unmount overhead on subsequent copy operations.

After a copy operation completes, a delayed task is scheduled to unmount the export after a configurable idle time. Each time the export is being used again, its expire time is extended to allow the export to remain mounted.

Quoted 6 lines
Quoted 3 lines

The unmount task and the mount operation of the copy request are synced to make sure the export is not unmounted while it's being used.

Can you tell me what this should apply on top of? It doesn't apply to 5.13-rc2. I know Chuck posted a lot of nfsd patches which I don't have, is your patch on top of that?

I built it on top of 5.12-rc8.

-Dai

Quoted 382 lines
Quoted 382 lines
---
  fs/nfsd/netns.h         |   5 ++
  fs/nfsd/nfs4proc.c      | 216 +++++++++++++++++++++++++++++++++++++++++++++++-
  fs/nfsd/nfs4state.c     |   8 ++
  fs/nfsd/nfsd.h          |   6 ++
  fs/nfsd/nfssvc.c        |   3 +
  include/linux/nfs_ssc.h |  16 ++++
  6 files changed, 250 insertions(+), 4 deletions(-)
fs/nfsd/netns.h +5 -0
index c330f5bd0cf3..6018e5050cb4 100644
@@ -21,6 +21,7 @@
 
  struct cld_net;
  struct nfsd4_client_tracking_ops;
+struct nfsd4_ssc_umount;
 
  enum {
         /* cache misses due only to checksum comparison failures */
@@ -176,6 +177,10 @@ struct nfsd_net {
         unsigned int             longest_chain_cachesize;
 
         struct shrinker         nfsd_reply_cache_shrinker;
+
+       spinlock_t              nfsd_ssc_lock;
+       struct nfsd4_ssc_umount *nfsd_ssc_umount;
+
         /* utsname taken from the process that starts the server */
         char                    nfsd_name[UNX_MAXNODENAME+1];
  };
fs/nfsd/nfs4proc.c +212 -4
index dd9f38d072dd..892ad72d87ae 100644
@@ -55,6 +55,99 @@ module_param(inter_copy_offload_enable, bool, 0644);
  MODULE_PARM_DESC(inter_copy_offload_enable,
                  "Enable inter server to server copy offload. Default: false");
 
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+static int nfsd4_ssc_umount_timeout = 900000;          /* default to 15 mins */
+module_param(nfsd4_ssc_umount_timeout, int, 0644);
+MODULE_PARM_DESC(nfsd4_ssc_umount_timeout,
+               "idle msecs before unmount export from source server");
+
+void nfsd4_ssc_expire_umount(struct nfsd_net *nn)
+{
+       bool do_wakeup = false;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount *nu;
+
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (time_after(jiffies, ni->nsui_expire)) {
+                       if (refcount_read(&ni->nsui_refcnt) > 0)
+                               continue;
+
+                       /* mark being unmount */
+                       ni->nsui_busy = true;
+                       spin_unlock(&nn->nfsd_ssc_lock);
+                       mntput(ni->nsui_vfsmount);
+                       spin_lock(&nn->nfsd_ssc_lock);
+
+                       /* waiters need to start from begin of list */
+                       list_del(&ni->nsui_list);
+                       kfree(ni);
+
+                       /* wakeup ssc_connect waiters */
+                       do_wakeup = true;
+                       continue;
+               }
+               break;
+       }
+       if (!list_empty(&nu->nsu_list)) {
+               ni = list_first_entry(&nu->nsu_list,
+                       struct nfsd4_ssc_umount_item, nsui_list);
+               nu->nsu_expire = ni->nsui_expire;
+       } else
+               nu->nsu_expire = 0;
+
+       if (do_wakeup)
+               wake_up_all(&nu->nsu_waitq);
+       spin_unlock(&nn->nfsd_ssc_lock);
+}
+
+/*
+ * This is called when nfsd is being shutdown, after all inter_ssc
+ * cleanup were done, to destroy the ssc delayed unmount list.
+ */
+void nfsd4_ssc_shutdown_umount(struct nfsd_net *nn)
+{
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount *nu;
+
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;
+       nn->nfsd_ssc_umount = 0;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               list_del(&ni->nsui_list);
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ni->nsui_vfsmount);
+               kfree(ni);
+               spin_lock(&nn->nfsd_ssc_lock);
+       }
+       spin_unlock(&nn->nfsd_ssc_lock);
+       kfree(nu);
+}
+
+void nfsd4_ssc_init_umount_work(struct nfsd_net *nn)
+{
+       nn->nfsd_ssc_umount = kzalloc(sizeof(struct nfsd4_ssc_umount),
+                                       GFP_KERNEL);
+       if (!nn->nfsd_ssc_umount)
+               return;
+       spin_lock_init(&nn->nfsd_ssc_lock);
+       INIT_LIST_HEAD(&nn->nfsd_ssc_umount->nsu_list);
+       init_waitqueue_head(&nn->nfsd_ssc_umount->nsu_waitq);
+}
+EXPORT_SYMBOL_GPL(nfsd4_ssc_init_umount_work);
+#endif
+
  #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
  #include <linux/security.h>
 
@@ -1181,6 +1274,12 @@ nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
         char *ipaddr, *dev_name, *raw_data;
         int len, raw_len;
         __be32 status = nfserr_inval;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *work = NULL;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
+       struct nfsd4_ssc_umount *nu;
+       DEFINE_WAIT(wait);
 
         naddr = &nss->u.nl4_addr;
         tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr,
@@ -1229,12 +1328,76 @@ nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
                 goto out_free_rawdata;
         snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep);
 
+       work = kzalloc(sizeof(*work), GFP_KERNEL);
+try_again:
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               kfree(work);
+               work = NULL;
+               goto skip_dul;
+       }
+       nu = nn->nfsd_ssc_umount;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (strncmp(ni->nsui_ipaddr, ipaddr, sizeof(ni->nsui_ipaddr)))
+                       continue;
+               /* found a match */
+               if (ni->nsui_busy) {
+                       /*  wait - and try again */
+                       prepare_to_wait(&nu->nsu_waitq, &wait,
+                               TASK_INTERRUPTIBLE);
+                       spin_unlock(&nn->nfsd_ssc_lock);
+
+                       /* allow 20secs for mount/unmount for now - revisit */
+                       if (signal_pending(current) ||
+                                       (schedule_timeout(20*HZ) == 0)) {
+                               status = nfserr_eagain;
+                               kfree(work);
+                               goto out_free_devname;
+                       }
+                       finish_wait(&nu->nsu_waitq, &wait);
+                       goto try_again;
+               }
+               ss_mnt = ni->nsui_vfsmount;
+               if (refcount_read(&ni->nsui_refcnt) == 0)
+                       refcount_set(&ni->nsui_refcnt, 1);
+               else
+                       refcount_inc(&ni->nsui_refcnt);
+               spin_unlock(&nn->nfsd_ssc_lock);
+               kfree(work);
+               goto out_done;
+       }
+       /* create new entry, set busy, insert list, clear busy after mount */
+       if (work) {
+               strncpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr));
+               refcount_set(&work->nsui_refcnt, 1);
+               work->nsui_busy = true;
+               list_add_tail(&work->nsui_list, &nu->nsu_list);
+       }
+       spin_unlock(&nn->nfsd_ssc_lock);
+skip_dul:
+
         /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */
         ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data);
         module_put(type->owner);
-       if (IS_ERR(ss_mnt))
+       if (IS_ERR(ss_mnt)) {
+               if (work) {
+                       spin_lock(&nn->nfsd_ssc_lock);
+                       list_del(&work->nsui_list);
+                       wake_up_all(&nu->nsu_waitq);
+                       spin_unlock(&nn->nfsd_ssc_lock);
+                       kfree(work);
+               }
                 goto out_free_devname;
-
+       }
+       if (work) {
+               spin_lock(&nn->nfsd_ssc_lock);
+               work->nsui_vfsmount = ss_mnt;
+               work->nsui_busy = false;
+               wake_up_all(&nu->nsu_waitq);
+               spin_unlock(&nn->nfsd_ssc_lock);
+       }
+out_done:
         status = 0;
         *mount = ss_mnt;
 
@@ -1301,10 +1464,55 @@ static void
  nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
                         struct nfsd_file *dst)
  {
+       bool found = false;
+       bool resched = false;
+       long timeout;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount *nu;
+       struct nfsd_net *nn = net_generic(dst->nf_net, nfsd_net_id);
+
         nfs42_ssc_close(src->nf_file);
-       fput(src->nf_file);
         nfsd_file_put(dst);
-       mntput(ss_mnt);
+       fput(src->nf_file);
+
+       if (!nn) {
+               mntput(ss_mnt);
+               return;
+       }
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               /* delayed unmount list not setup */
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ss_mnt);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;
+       timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout);
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (ni->nsui_vfsmount->mnt_sb == ss_mnt->mnt_sb) {
+                       list_del(&ni->nsui_list);
+                       /*
+                        * vfsmount can be shared by multiple exports,
+                        * decrement refcnt and schedule delayed task
+                        * if it drops to 0.
+                        */
+                       if (refcount_dec_and_test(&ni->nsui_refcnt))
+                               resched = true;
+                       ni->nsui_expire = jiffies + timeout;
+                       list_add_tail(&ni->nsui_list, &nu->nsu_list);
+                       found = true;
+                       break;
+               }
+       }
+       if (!found) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ss_mnt);
+               return;
+       }
+       if (resched && !nu->nsu_expire)
+               nu->nsu_expire = ni->nsui_expire;
+       spin_unlock(&nn->nfsd_ssc_lock);
  }
 
  #else /* CONFIG_NFSD_V4_2_INTER_SSC */
fs/nfsd/nfs4state.c +8 -0
index 97447a64bad0..0cdc898f06c9 100644
@@ -5459,6 +5459,11 @@ nfs4_laundromat(struct nfsd_net *nn)
                 list_del_init(&nbl->nbl_lru);
                 free_blocked_lock(nbl);
         }
+
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       /* service the inter-copy delayed unmount list */
+       nfsd4_ssc_expire_umount(nn);
+#endif
  out:
         new_timeo = max_t(time64_t, new_timeo, NFSD_LAUNDROMAT_MINTIMEOUT);
         return new_timeo;
@@ -7398,6 +7403,9 @@ nfs4_state_shutdown_net(struct net *net)
 
         nfsd4_client_tracking_exit(net);
         nfs4_state_destroy_net(net);
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       nfsd4_ssc_shutdown_umount(nn);
+#endif
         mntput(nn->nfsd_mnt);
  }
 
fs/nfsd/nfsd.h +6 -0
index 8bdc37aa2c2e..cf86d9010974 100644
@@ -483,6 +483,12 @@ static inline bool nfsd_attrs_supported(u32 minorversion, const u32 *bmval)
  extern int nfsd4_is_junction(struct dentry *dentry);
  extern int register_cld_notifier(void);
  extern void unregister_cld_notifier(void);
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+extern void nfsd4_ssc_init_umount_work(struct nfsd_net *nn);
+extern void nfsd4_ssc_expire_umount(struct nfsd_net *nn);
+extern void nfsd4_ssc_shutdown_umount(struct nfsd_net *nn);
+#endif
+
  #else /* CONFIG_NFSD_V4 */
  static inline int nfsd4_is_junction(struct dentry *dentry)
  {
fs/nfsd/nfssvc.c +3 -0
index 6de406322106..ce89a8fe07ff 100644
@@ -403,6 +403,9 @@ static int nfsd_startup_net(int nrservs, struct net *net, const struct cred *cre
         if (ret)
                 goto out_filecache;
 
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       nfsd4_ssc_init_umount_work(nn);
+#endif
         nn->nfsd_net_up = true;
         return 0;
 
include/linux/nfs_ssc.h +16 -1
index f5ba0fbff72f..18afe62988b5 100644
@@ -8,6 +8,7 @@
   */
 
  #include <linux/nfs_fs.h>
+#include <linux/sunrpc/svc.h>
 
  extern struct nfs_ssc_client_ops_tbl nfs_ssc_client_tbl;
 
@@ -52,6 +53,21 @@ static inline void nfs42_ssc_close(struct file *filep)
         if (nfs_ssc_client_tbl.ssc_nfs4_ops)
                 (*nfs_ssc_client_tbl.ssc_nfs4_ops->sco_close)(filep);
  }
+
+struct nfsd4_ssc_umount_item {
+       struct list_head nsui_list;
+       bool nsui_busy;
+       refcount_t nsui_refcnt;
+       unsigned long nsui_expire;
+       struct vfsmount *nsui_vfsmount;
+       char nsui_ipaddr[RPC_MAX_ADDRBUFLEN];
+};
+
+struct nfsd4_ssc_umount {
+       struct list_head nsu_list;
+       unsigned long nsu_expire;
+       wait_queue_head_t nsu_waitq;
+};
  #endif
 
  /*
--

2.9.5

#4 lore raw
Quoted 14 lines · On Tue, May 18, 2021 at 12:30 PM <[email protected]> wrote:
Quoted 11 lines · Olga Kornievskaia
Quoted 10 lines · Dai Ngo

Currently the source's export is mounted and unmounted on every inter-server copy operation. This patch is an enhancement to delay the unmount of the source export for a certain period of time to eliminate the mount and unmount overhead on subsequent copy operations.

After a copy operation completes, a delayed task is scheduled to unmount the export after a configurable idle time. Each time the export is being used again, its expire time is extended to allow the export to remain mounted.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

The unmount task and the mount operation of the copy request are synced to make sure the export is not unmounted while it's being used.

Can you tell me what this should apply on top of? It doesn't apply to 5.13-rc2. I know Chuck posted a lot of nfsd patches which I don't have, is your patch on top of that?

I built it on top of 5.12-rc8. I'm not sure how.

This chunk fails:
@@ -7398,6 +7403,9 @@ nfs4_state_shutdown_net(struct net *net)

        nfsd4_client_tracking_exit(net);
        nfs4_state_destroy_net(net);
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       nfsd4_ssc_shutdown_umount(nn);
+#endif
        mntput(nn->nfsd_mnt);

}

Looks like this patch "nfsd: Ensure knfsd shuts down when the "nfsd" pseudofs is unmounted" removes it. Can you rebase on the latest?

Quoted 385 lines

-Dai

Quoted 382 lines
Quoted 382 lines
---
  fs/nfsd/netns.h         |   5 ++
  fs/nfsd/nfs4proc.c      | 216 +++++++++++++++++++++++++++++++++++++++++++++++-
  fs/nfsd/nfs4state.c     |   8 ++
  fs/nfsd/nfsd.h          |   6 ++
  fs/nfsd/nfssvc.c        |   3 +
  include/linux/nfs_ssc.h |  16 ++++
  6 files changed, 250 insertions(+), 4 deletions(-)
fs/nfsd/netns.h +5 -0
index c330f5bd0cf3..6018e5050cb4 100644
@@ -21,6 +21,7 @@
 
  struct cld_net;
  struct nfsd4_client_tracking_ops;
+struct nfsd4_ssc_umount;
 
  enum {
         /* cache misses due only to checksum comparison failures */
@@ -176,6 +177,10 @@ struct nfsd_net {
         unsigned int             longest_chain_cachesize;
 
         struct shrinker         nfsd_reply_cache_shrinker;
+
+       spinlock_t              nfsd_ssc_lock;
+       struct nfsd4_ssc_umount *nfsd_ssc_umount;
+
         /* utsname taken from the process that starts the server */
         char                    nfsd_name[UNX_MAXNODENAME+1];
  };
fs/nfsd/nfs4proc.c +212 -4
index dd9f38d072dd..892ad72d87ae 100644
@@ -55,6 +55,99 @@ module_param(inter_copy_offload_enable, bool, 0644);
  MODULE_PARM_DESC(inter_copy_offload_enable,
                  "Enable inter server to server copy offload. Default: false");
 
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+static int nfsd4_ssc_umount_timeout = 900000;          /* default to 15 mins */
+module_param(nfsd4_ssc_umount_timeout, int, 0644);
+MODULE_PARM_DESC(nfsd4_ssc_umount_timeout,
+               "idle msecs before unmount export from source server");
+
+void nfsd4_ssc_expire_umount(struct nfsd_net *nn)
+{
+       bool do_wakeup = false;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount *nu;
+
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (time_after(jiffies, ni->nsui_expire)) {
+                       if (refcount_read(&ni->nsui_refcnt) > 0)
+                               continue;
+
+                       /* mark being unmount */
+                       ni->nsui_busy = true;
+                       spin_unlock(&nn->nfsd_ssc_lock);
+                       mntput(ni->nsui_vfsmount);
+                       spin_lock(&nn->nfsd_ssc_lock);
+
+                       /* waiters need to start from begin of list */
+                       list_del(&ni->nsui_list);
+                       kfree(ni);
+
+                       /* wakeup ssc_connect waiters */
+                       do_wakeup = true;
+                       continue;
+               }
+               break;
+       }
+       if (!list_empty(&nu->nsu_list)) {
+               ni = list_first_entry(&nu->nsu_list,
+                       struct nfsd4_ssc_umount_item, nsui_list);
+               nu->nsu_expire = ni->nsui_expire;
+       } else
+               nu->nsu_expire = 0;
+
+       if (do_wakeup)
+               wake_up_all(&nu->nsu_waitq);
+       spin_unlock(&nn->nfsd_ssc_lock);
+}
+
+/*
+ * This is called when nfsd is being shutdown, after all inter_ssc
+ * cleanup were done, to destroy the ssc delayed unmount list.
+ */
+void nfsd4_ssc_shutdown_umount(struct nfsd_net *nn)
+{
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount *nu;
+
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;
+       nn->nfsd_ssc_umount = 0;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               list_del(&ni->nsui_list);
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ni->nsui_vfsmount);
+               kfree(ni);
+               spin_lock(&nn->nfsd_ssc_lock);
+       }
+       spin_unlock(&nn->nfsd_ssc_lock);
+       kfree(nu);
+}
+
+void nfsd4_ssc_init_umount_work(struct nfsd_net *nn)
+{
+       nn->nfsd_ssc_umount = kzalloc(sizeof(struct nfsd4_ssc_umount),
+                                       GFP_KERNEL);
+       if (!nn->nfsd_ssc_umount)
+               return;
+       spin_lock_init(&nn->nfsd_ssc_lock);
+       INIT_LIST_HEAD(&nn->nfsd_ssc_umount->nsu_list);
+       init_waitqueue_head(&nn->nfsd_ssc_umount->nsu_waitq);
+}
+EXPORT_SYMBOL_GPL(nfsd4_ssc_init_umount_work);
+#endif
+
  #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
  #include <linux/security.h>
 
@@ -1181,6 +1274,12 @@ nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
         char *ipaddr, *dev_name, *raw_data;
         int len, raw_len;
         __be32 status = nfserr_inval;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *work = NULL;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
+       struct nfsd4_ssc_umount *nu;
+       DEFINE_WAIT(wait);
 
         naddr = &nss->u.nl4_addr;
         tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr,
@@ -1229,12 +1328,76 @@ nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
                 goto out_free_rawdata;
         snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep);
 
+       work = kzalloc(sizeof(*work), GFP_KERNEL);
+try_again:
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               kfree(work);
+               work = NULL;
+               goto skip_dul;
+       }
+       nu = nn->nfsd_ssc_umount;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (strncmp(ni->nsui_ipaddr, ipaddr, sizeof(ni->nsui_ipaddr)))
+                       continue;
+               /* found a match */
+               if (ni->nsui_busy) {
+                       /*  wait - and try again */
+                       prepare_to_wait(&nu->nsu_waitq, &wait,
+                               TASK_INTERRUPTIBLE);
+                       spin_unlock(&nn->nfsd_ssc_lock);
+
+                       /* allow 20secs for mount/unmount for now - revisit */
+                       if (signal_pending(current) ||
+                                       (schedule_timeout(20*HZ) == 0)) {
+                               status = nfserr_eagain;
+                               kfree(work);
+                               goto out_free_devname;
+                       }
+                       finish_wait(&nu->nsu_waitq, &wait);
+                       goto try_again;
+               }
+               ss_mnt = ni->nsui_vfsmount;
+               if (refcount_read(&ni->nsui_refcnt) == 0)
+                       refcount_set(&ni->nsui_refcnt, 1);
+               else
+                       refcount_inc(&ni->nsui_refcnt);
+               spin_unlock(&nn->nfsd_ssc_lock);
+               kfree(work);
+               goto out_done;
+       }
+       /* create new entry, set busy, insert list, clear busy after mount */
+       if (work) {
+               strncpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr));
+               refcount_set(&work->nsui_refcnt, 1);
+               work->nsui_busy = true;
+               list_add_tail(&work->nsui_list, &nu->nsu_list);
+       }
+       spin_unlock(&nn->nfsd_ssc_lock);
+skip_dul:
+
         /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */
         ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data);
         module_put(type->owner);
-       if (IS_ERR(ss_mnt))
+       if (IS_ERR(ss_mnt)) {
+               if (work) {
+                       spin_lock(&nn->nfsd_ssc_lock);
+                       list_del(&work->nsui_list);
+                       wake_up_all(&nu->nsu_waitq);
+                       spin_unlock(&nn->nfsd_ssc_lock);
+                       kfree(work);
+               }
                 goto out_free_devname;
-
+       }
+       if (work) {
+               spin_lock(&nn->nfsd_ssc_lock);
+               work->nsui_vfsmount = ss_mnt;
+               work->nsui_busy = false;
+               wake_up_all(&nu->nsu_waitq);
+               spin_unlock(&nn->nfsd_ssc_lock);
+       }
+out_done:
         status = 0;
         *mount = ss_mnt;
 
@@ -1301,10 +1464,55 @@ static void
  nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
                         struct nfsd_file *dst)
  {
+       bool found = false;
+       bool resched = false;
+       long timeout;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount *nu;
+       struct nfsd_net *nn = net_generic(dst->nf_net, nfsd_net_id);
+
         nfs42_ssc_close(src->nf_file);
-       fput(src->nf_file);
         nfsd_file_put(dst);
-       mntput(ss_mnt);
+       fput(src->nf_file);
+
+       if (!nn) {
+               mntput(ss_mnt);
+               return;
+       }
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               /* delayed unmount list not setup */
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ss_mnt);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;
+       timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout);
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (ni->nsui_vfsmount->mnt_sb == ss_mnt->mnt_sb) {
+                       list_del(&ni->nsui_list);
+                       /*
+                        * vfsmount can be shared by multiple exports,
+                        * decrement refcnt and schedule delayed task
+                        * if it drops to 0.
+                        */
+                       if (refcount_dec_and_test(&ni->nsui_refcnt))
+                               resched = true;
+                       ni->nsui_expire = jiffies + timeout;
+                       list_add_tail(&ni->nsui_list, &nu->nsu_list);
+                       found = true;
+                       break;
+               }
+       }
+       if (!found) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ss_mnt);
+               return;
+       }
+       if (resched && !nu->nsu_expire)
+               nu->nsu_expire = ni->nsui_expire;
+       spin_unlock(&nn->nfsd_ssc_lock);
  }
 
  #else /* CONFIG_NFSD_V4_2_INTER_SSC */
fs/nfsd/nfs4state.c +8 -0
index 97447a64bad0..0cdc898f06c9 100644
@@ -5459,6 +5459,11 @@ nfs4_laundromat(struct nfsd_net *nn)
                 list_del_init(&nbl->nbl_lru);
                 free_blocked_lock(nbl);
         }
+
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       /* service the inter-copy delayed unmount list */
+       nfsd4_ssc_expire_umount(nn);
+#endif
  out:
         new_timeo = max_t(time64_t, new_timeo, NFSD_LAUNDROMAT_MINTIMEOUT);
         return new_timeo;
@@ -7398,6 +7403,9 @@ nfs4_state_shutdown_net(struct net *net)
 
         nfsd4_client_tracking_exit(net);
         nfs4_state_destroy_net(net);
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       nfsd4_ssc_shutdown_umount(nn);
+#endif
         mntput(nn->nfsd_mnt);
  }
 
fs/nfsd/nfsd.h +6 -0
index 8bdc37aa2c2e..cf86d9010974 100644
@@ -483,6 +483,12 @@ static inline bool nfsd_attrs_supported(u32 minorversion, const u32 *bmval)
  extern int nfsd4_is_junction(struct dentry *dentry);
  extern int register_cld_notifier(void);
  extern void unregister_cld_notifier(void);
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+extern void nfsd4_ssc_init_umount_work(struct nfsd_net *nn);
+extern void nfsd4_ssc_expire_umount(struct nfsd_net *nn);
+extern void nfsd4_ssc_shutdown_umount(struct nfsd_net *nn);
+#endif
+
  #else /* CONFIG_NFSD_V4 */
  static inline int nfsd4_is_junction(struct dentry *dentry)
  {
fs/nfsd/nfssvc.c +3 -0
index 6de406322106..ce89a8fe07ff 100644
@@ -403,6 +403,9 @@ static int nfsd_startup_net(int nrservs, struct net *net, const struct cred *cre
         if (ret)
                 goto out_filecache;
 
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       nfsd4_ssc_init_umount_work(nn);
+#endif
         nn->nfsd_net_up = true;
         return 0;
 
include/linux/nfs_ssc.h +16 -1
index f5ba0fbff72f..18afe62988b5 100644
@@ -8,6 +8,7 @@
   */
 
  #include <linux/nfs_fs.h>
+#include <linux/sunrpc/svc.h>
 
  extern struct nfs_ssc_client_ops_tbl nfs_ssc_client_tbl;
 
@@ -52,6 +53,21 @@ static inline void nfs42_ssc_close(struct file *filep)
         if (nfs_ssc_client_tbl.ssc_nfs4_ops)
                 (*nfs_ssc_client_tbl.ssc_nfs4_ops->sco_close)(filep);
  }
+
+struct nfsd4_ssc_umount_item {
+       struct list_head nsui_list;
+       bool nsui_busy;
+       refcount_t nsui_refcnt;
+       unsigned long nsui_expire;
+       struct vfsmount *nsui_vfsmount;
+       char nsui_ipaddr[RPC_MAX_ADDRBUFLEN];
+};
+
+struct nfsd4_ssc_umount {
+       struct list_head nsu_list;
+       unsigned long nsu_expire;
+       wait_queue_head_t nsu_waitq;
+};
  #endif
 
  /*
--

2.9.5

#5 lore raw
In reply to Dai Ngo
Quoted 11 lines · Dai Ngo
fs/nfsd/netns.h +4 -0
+struct nfsd4_ssc_umount;
 
 enum {
 	/* cache misses due only to checksum comparison failures */
@@ -176,6 +177,10 @@ struct nfsd_net {
 	unsigned int             longest_chain_cachesize;
 
 	struct shrinker		nfsd_reply_cache_shrinker;
+
+	spinlock_t              nfsd_ssc_lock;
+	struct nfsd4_ssc_umount	*nfsd_ssc_umount;

...

fs/nfsd/nfs4proc.c module_param(inter_copy_offload_enable, bool, 0644); · line 143

Quoted 6 lines
fs/nfsd/nfs4proc.c +6 -0
+void nfsd4_ssc_init_umount_work(struct nfsd_net *nn)
+{
+	nn->nfsd_ssc_umount = kzalloc(sizeof(struct nfsd4_ssc_umount),
+					GFP_KERNEL);
+	if (!nn->nfsd_ssc_umount)
+		return;

Is there any reason this needs to be allocated dynamically? Let's just embed it in nfsd_net.

Actually, I'm not convinced the separate structure definition's really that helpful:

include/linux/nfs_ssc.h static inline void nfs42_ssc_close(struct file *filep) · line 70

Quoted 5 lines
include/linux/nfs_ssc.h +5 -0
+struct nfsd4_ssc_umount {
+	struct list_head nsu_list;
+	unsigned long nsu_expire;
+	wait_queue_head_t nsu_waitq;
+};

How about just:

	struct nfsd_net {
	...
	/* tracking server-to-server copy mounts: */
	spinlock_t		nfsd_ssc_lock;
	struct list_head	nfsd_ssc_mount_list;
	unsigned long		nfsd_ssc_mount_expire;
	wait_queeu_head_t	nfsd_ssc_mount_waitq;

or something along those lines?

--b.

#6 lore raw
Quoted 24 lines · J. Bruce Fields
Quoted 11 lines · Dai Ngo
fs/nfsd/netns.h +4 -0
+struct nfsd4_ssc_umount;
 
 enum {
 	/* cache misses due only to checksum comparison failures */
@@ -176,6 +177,10 @@ struct nfsd_net {
 	unsigned int             longest_chain_cachesize;
 
 	struct shrinker		nfsd_reply_cache_shrinker;
+
+	spinlock_t              nfsd_ssc_lock;
+	struct nfsd4_ssc_umount	*nfsd_ssc_umount;

...

fs/nfsd/nfs4proc.c module_param(inter_copy_offload_enable, bool, 0644); · line 143

Quoted 6 lines
fs/nfsd/nfs4proc.c +6 -0
+void nfsd4_ssc_init_umount_work(struct nfsd_net *nn)
+{
+	nn->nfsd_ssc_umount = kzalloc(sizeof(struct nfsd4_ssc_umount),
+					GFP_KERNEL);
+	if (!nn->nfsd_ssc_umount)
+		return;

Is there any reason this needs to be allocated dynamically? Let's just embed it in nfsd_net.

Quoted 6 lines

Actually, I'm not convinced the separate structure definition's really that helpful:

include/linux/nfs_ssc.h static inline void nfs42_ssc_close(struct file *filep) · line 68

Quoted 3 lines
include/linux/nfs_ssc.h +3 -0
+struct nfsd4_ssc_umount {
+	struct list_head nsu_list;
+	unsigned long nsu_expire;

Also: doesn't look like nsu_expire is actually used. Am I missing something, or is this a leftover from the conversion to the using the laundromat thread?

--b.

Quoted 16 lines

include/linux/nfs_ssc.h static inline void nfs42_ssc_close(struct file *filep) · line 70

Quoted 2 lines
include/linux/nfs_ssc.h +2 -0
+	wait_queue_head_t nsu_waitq;
+};

How about just:

	struct nfsd_net {
	...
	/* tracking server-to-server copy mounts: */
	spinlock_t		nfsd_ssc_lock;
	struct list_head	nfsd_ssc_mount_list;
	unsigned long		nfsd_ssc_mount_expire;
	wait_queeu_head_t	nfsd_ssc_mount_waitq;

or something along those lines?

--b.

author reviewer
#7 lore raw
Quoted 27 lines · J. Bruce Fields
Quoted 26 lines · J. Bruce Fields
Quoted 11 lines · Dai Ngo
fs/nfsd/netns.h +4 -0
+struct nfsd4_ssc_umount;
 
  enum {
  	/* cache misses due only to checksum comparison failures */
@@ -176,6 +177,10 @@ struct nfsd_net {
  	unsigned int             longest_chain_cachesize;
 
  	struct shrinker		nfsd_reply_cache_shrinker;
+
+	spinlock_t              nfsd_ssc_lock;
+	struct nfsd4_ssc_umount	*nfsd_ssc_umount;

...

fs/nfsd/nfs4proc.c module_param(inter_copy_offload_enable, bool, 0644); · line 143

Quoted 6 lines
fs/nfsd/nfs4proc.c +6 -0
+void nfsd4_ssc_init_umount_work(struct nfsd_net *nn)
+{
+	nn->nfsd_ssc_umount = kzalloc(sizeof(struct nfsd4_ssc_umount),
+					GFP_KERNEL);
+	if (!nn->nfsd_ssc_umount)
+		return;

Is there any reason this needs to be allocated dynamically? Let's just embed it in nfsd_net.

Actually, I'm not convinced the separate structure definition's really that helpful:

Quoted 6 lines
Quoted 3 lines

include/linux/nfs_ssc.h static inline void nfs42_ssc_close(struct file *filep) · line 68

Quoted 3 lines
include/linux/nfs_ssc.h +3 -0
+struct nfsd4_ssc_umount {
+	struct list_head nsu_list;
+	unsigned long nsu_expire;

Also: doesn't look like nsu_expire is actually used. Am I missing something, or is this a leftover from the conversion to the using the laundromat thread?

Yes, will be cleaned up in v6.

-Dai

Quoted 18 lines

--b.

Quoted 15 lines

include/linux/nfs_ssc.h static inline void nfs42_ssc_close(struct file *filep) · line 70

Quoted 2 lines
include/linux/nfs_ssc.h +2 -0
+	wait_queue_head_t nsu_waitq;
+};

How about just:

	struct nfsd_net {
	...
	/* tracking server-to-server copy mounts: */
	spinlock_t		nfsd_ssc_lock;
	struct list_head	nfsd_ssc_mount_list;
	unsigned long		nfsd_ssc_mount_expire;
	wait_queeu_head_t	nfsd_ssc_mount_waitq;

or something along those lines?

--b.

author reviewer
#8 lore raw
In reply to J. Bruce Fields
Quoted 41 lines · J. Bruce Fields
Quoted 11 lines · Dai Ngo
fs/nfsd/netns.h +4 -0
+struct nfsd4_ssc_umount;
 
  enum {
  	/* cache misses due only to checksum comparison failures */
@@ -176,6 +177,10 @@ struct nfsd_net {
  	unsigned int             longest_chain_cachesize;
 
  	struct shrinker		nfsd_reply_cache_shrinker;
+
+	spinlock_t              nfsd_ssc_lock;
+	struct nfsd4_ssc_umount	*nfsd_ssc_umount;

...

fs/nfsd/nfs4proc.c module_param(inter_copy_offload_enable, bool, 0644); · line 143

Quoted 6 lines
fs/nfsd/nfs4proc.c +6 -0
+void nfsd4_ssc_init_umount_work(struct nfsd_net *nn)
+{
+	nn->nfsd_ssc_umount = kzalloc(sizeof(struct nfsd4_ssc_umount),
+					GFP_KERNEL);
+	if (!nn->nfsd_ssc_umount)
+		return;

Is there any reason this needs to be allocated dynamically? Let's just embed it in nfsd_net.

Actually, I'm not convinced the separate structure definition's really that helpful:

include/linux/nfs_ssc.h static inline void nfs42_ssc_close(struct file *filep) · line 70

Quoted 5 lines
include/linux/nfs_ssc.h +5 -0
+struct nfsd4_ssc_umount {
+	struct list_head nsu_list;
+	unsigned long nsu_expire;
+	wait_queue_head_t nsu_waitq;
+};

How about just:

	struct nfsd_net {
	...
	/* tracking server-to-server copy mounts: */
	spinlock_t		nfsd_ssc_lock;
	struct list_head	nfsd_ssc_mount_list;
	unsigned long		nfsd_ssc_mount_expire;
	wait_queeu_head_t	nfsd_ssc_mount_waitq;
Quoted 1 line

or something along those lines?

I will move nfsd4_ssc_umount into nfsd_net.

-Dai

Quoted 2 lines

--b.

#9 lore raw
In reply to Dai Ngo

Hi Dai,

General review comments inline

Quoted 53 lines · Dai Ngo

Currently the source's export is mounted and unmounted on every inter-server copy operation. This patch is an enhancement to delay the unmount of the source export for a certain period of time to eliminate the mount and unmount overhead on subsequent copy operations.

After a copy operation completes, a delayed task is scheduled to unmount the export after a configurable idle time. Each time the export is being used again, its expire time is extended to allow the export to remain mounted.

The unmount task and the mount operation of the copy request are synced to make sure the export is not unmounted while it's being used.

---
 fs/nfsd/netns.h         |   5 ++
 fs/nfsd/nfs4proc.c      | 216 +++++++++++++++++++++++++++++++++++++++++++++++-
 fs/nfsd/nfs4state.c     |   8 ++
 fs/nfsd/nfsd.h          |   6 ++
 fs/nfsd/nfssvc.c        |   3 +
 include/linux/nfs_ssc.h |  16 ++++
 6 files changed, 250 insertions(+), 4 deletions(-)
fs/nfsd/netns.h +5 -0
index c330f5bd0cf3..6018e5050cb4 100644
@@ -21,6 +21,7 @@
 
 struct cld_net;
 struct nfsd4_client_tracking_ops;
+struct nfsd4_ssc_umount;
 
 enum {
        /* cache misses due only to checksum comparison failures */
@@ -176,6 +177,10 @@ struct nfsd_net {
        unsigned int             longest_chain_cachesize;
 
        struct shrinker         nfsd_reply_cache_shrinker;
+
+       spinlock_t              nfsd_ssc_lock;
+       struct nfsd4_ssc_umount *nfsd_ssc_umount;
+
        /* utsname taken from the process that starts the server */
        char                    nfsd_name[UNX_MAXNODENAME+1];
 };
fs/nfsd/nfs4proc.c +0 -0
index dd9f38d072dd..892ad72d87ae 100644

fs/nfsd/nfs4proc.c module_param(inter_copy_offload_enable, bool, 0644); · line 64

Quoted 10 lines
fs/nfsd/nfs4proc.c +7 -0
@@ -55,6 +55,99 @@ module_param(inter_copy_offload_enable, bool, 0644);
 MODULE_PARM_DESC(inter_copy_offload_enable,
                 "Enable inter server to server copy offload. Default: false");
 
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+static int nfsd4_ssc_umount_timeout = 900000;          /* default to 15 mins */
+module_param(nfsd4_ssc_umount_timeout, int, 0644);
+MODULE_PARM_DESC(nfsd4_ssc_umount_timeout,
+               "idle msecs before unmount export from source server");
+
+void nfsd4_ssc_expire_umount(struct nfsd_net *nn)

Why should this be in nfs4proc.c when it's used in nfs4state.c only?

Quoted 22 lines
fs/nfsd/nfs4proc.c +22 -0
+{
+       bool do_wakeup = false;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount *nu;
+
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (time_after(jiffies, ni->nsui_expire)) {
+                       if (refcount_read(&ni->nsui_refcnt) > 0)
+                               continue;
+
+                       /* mark being unmount */
+                       ni->nsui_busy = true;
+                       spin_unlock(&nn->nfsd_ssc_lock);
+                       mntput(ni->nsui_vfsmount);
+                       spin_lock(&nn->nfsd_ssc_lock);

fs/nfsd/nfs4proc.c module_param(inter_copy_offload_enable, bool, 0644); · line 96

Quoted 10 lines
fs/nfsd/nfs4proc.c +10 -0
+
+                       /* waiters need to start from begin of list */
+                       list_del(&ni->nsui_list);
+                       kfree(ni);
+
+                       /* wakeup ssc_connect waiters */
+                       do_wakeup = true;
+                       continue;
+               }
+               break;

mnt1, mnt2, mnt3 added all at the same time. mnt1, mnt3 only used once during the expiration time. mnt2 is being used continuously. expiration time comes. delayed mnt1 is processed. mnt2 is next on the list and it's not expired so code quits. mnt3 will not be umounted until mnt2 expires. I think the break is wrong.

Quoted 29 lines
fs/nfsd/nfs4proc.c +29 -0
+       }
+       if (!list_empty(&nu->nsu_list)) {
+               ni = list_first_entry(&nu->nsu_list,
+                       struct nfsd4_ssc_umount_item, nsui_list);
+               nu->nsu_expire = ni->nsui_expire;
+       } else
+               nu->nsu_expire = 0;
+
+       if (do_wakeup)
+               wake_up_all(&nu->nsu_waitq);
+       spin_unlock(&nn->nfsd_ssc_lock);
+}
+
+/*
+ * This is called when nfsd is being shutdown, after all inter_ssc
+ * cleanup were done, to destroy the ssc delayed unmount list.
+ */
+void nfsd4_ssc_shutdown_umount(struct nfsd_net *nn)
+{
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount *nu;
+
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;

fs/nfsd/nfs4proc.c module_param(inter_copy_offload_enable, bool, 0644); · line 135

Quoted 10 lines
fs/nfsd/nfs4proc.c +10 -0
+       nn->nfsd_ssc_umount = 0;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               list_del(&ni->nsui_list);
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ni->nsui_vfsmount);
+               kfree(ni);
+               spin_lock(&nn->nfsd_ssc_lock);
+       }
+       spin_unlock(&nn->nfsd_ssc_lock);
+       kfree(nu);

General question to maybe Bruce: can nfsd_net go away while a compound is using it ? I hope not. I can't quite think thru the scenario where we started the async copy task but then somehow nfsd_net is going away before async_copy is done and if there is anything we need to take care of. I think the net shutdown would not find anything to free so it would just return. And the copy's cleanup would not find a nfsd_net and so it would right away unmount. This is more of thinking out loud but I'd like somebody else to confirm I'm correct that we are OK here.

Quoted 262 lines
fs/nfsd/nfs4proc.c +134 -4
+}
+
+void nfsd4_ssc_init_umount_work(struct nfsd_net *nn)
+{
+       nn->nfsd_ssc_umount = kzalloc(sizeof(struct nfsd4_ssc_umount),
+                                       GFP_KERNEL);
+       if (!nn->nfsd_ssc_umount)
+               return;
+       spin_lock_init(&nn->nfsd_ssc_lock);
+       INIT_LIST_HEAD(&nn->nfsd_ssc_umount->nsu_list);
+       init_waitqueue_head(&nn->nfsd_ssc_umount->nsu_waitq);
+}
+EXPORT_SYMBOL_GPL(nfsd4_ssc_init_umount_work);
+#endif
+
 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
 #include <linux/security.h>
 
@@ -1181,6 +1274,12 @@ nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
        char *ipaddr, *dev_name, *raw_data;
        int len, raw_len;
        __be32 status = nfserr_inval;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *work = NULL;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
+       struct nfsd4_ssc_umount *nu;
+       DEFINE_WAIT(wait);
 
        naddr = &nss->u.nl4_addr;
        tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr,
@@ -1229,12 +1328,76 @@ nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
                goto out_free_rawdata;
        snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep);
 
+       work = kzalloc(sizeof(*work), GFP_KERNEL);
+try_again:
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               kfree(work);
+               work = NULL;
+               goto skip_dul;
+       }
+       nu = nn->nfsd_ssc_umount;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (strncmp(ni->nsui_ipaddr, ipaddr, sizeof(ni->nsui_ipaddr)))
+                       continue;
+               /* found a match */
+               if (ni->nsui_busy) {
+                       /*  wait - and try again */
+                       prepare_to_wait(&nu->nsu_waitq, &wait,
+                               TASK_INTERRUPTIBLE);
+                       spin_unlock(&nn->nfsd_ssc_lock);
+
+                       /* allow 20secs for mount/unmount for now - revisit */
+                       if (signal_pending(current) ||
+                                       (schedule_timeout(20*HZ) == 0)) {
+                               status = nfserr_eagain;
+                               kfree(work);
+                               goto out_free_devname;
+                       }
+                       finish_wait(&nu->nsu_waitq, &wait);
+                       goto try_again;
+               }
+               ss_mnt = ni->nsui_vfsmount;
+               if (refcount_read(&ni->nsui_refcnt) == 0)
+                       refcount_set(&ni->nsui_refcnt, 1);
+               else
+                       refcount_inc(&ni->nsui_refcnt);
+               spin_unlock(&nn->nfsd_ssc_lock);
+               kfree(work);
+               goto out_done;
+       }
+       /* create new entry, set busy, insert list, clear busy after mount */
+       if (work) {
+               strncpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr));
+               refcount_set(&work->nsui_refcnt, 1);
+               work->nsui_busy = true;
+               list_add_tail(&work->nsui_list, &nu->nsu_list);
+       }
+       spin_unlock(&nn->nfsd_ssc_lock);
+skip_dul:
+
        /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */
        ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data);
        module_put(type->owner);
-       if (IS_ERR(ss_mnt))
+       if (IS_ERR(ss_mnt)) {
+               if (work) {
+                       spin_lock(&nn->nfsd_ssc_lock);
+                       list_del(&work->nsui_list);
+                       wake_up_all(&nu->nsu_waitq);
+                       spin_unlock(&nn->nfsd_ssc_lock);
+                       kfree(work);
+               }
                goto out_free_devname;
-
+       }
+       if (work) {
+               spin_lock(&nn->nfsd_ssc_lock);
+               work->nsui_vfsmount = ss_mnt;
+               work->nsui_busy = false;
+               wake_up_all(&nu->nsu_waitq);
+               spin_unlock(&nn->nfsd_ssc_lock);
+       }
+out_done:
        status = 0;
        *mount = ss_mnt;
 
@@ -1301,10 +1464,55 @@ static void
 nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
                        struct nfsd_file *dst)
 {
+       bool found = false;
+       bool resched = false;
+       long timeout;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount *nu;
+       struct nfsd_net *nn = net_generic(dst->nf_net, nfsd_net_id);
+
        nfs42_ssc_close(src->nf_file);
-       fput(src->nf_file);
        nfsd_file_put(dst);
-       mntput(ss_mnt);
+       fput(src->nf_file);
+
+       if (!nn) {
+               mntput(ss_mnt);
+               return;
+       }
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               /* delayed unmount list not setup */
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ss_mnt);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;
+       timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout);
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (ni->nsui_vfsmount->mnt_sb == ss_mnt->mnt_sb) {
+                       list_del(&ni->nsui_list);
+                       /*
+                        * vfsmount can be shared by multiple exports,
+                        * decrement refcnt and schedule delayed task
+                        * if it drops to 0.
+                        */
+                       if (refcount_dec_and_test(&ni->nsui_refcnt))
+                               resched = true;
+                       ni->nsui_expire = jiffies + timeout;
+                       list_add_tail(&ni->nsui_list, &nu->nsu_list);
+                       found = true;
+                       break;
+               }
+       }
+       if (!found) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ss_mnt);
+               return;
+       }
+       if (resched && !nu->nsu_expire)
+               nu->nsu_expire = ni->nsui_expire;
+       spin_unlock(&nn->nfsd_ssc_lock);
 }
 
 #else /* CONFIG_NFSD_V4_2_INTER_SSC */
fs/nfsd/nfs4state.c +8 -0
index 97447a64bad0..0cdc898f06c9 100644
@@ -5459,6 +5459,11 @@ nfs4_laundromat(struct nfsd_net *nn)
                list_del_init(&nbl->nbl_lru);
                free_blocked_lock(nbl);
        }
+
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       /* service the inter-copy delayed unmount list */
+       nfsd4_ssc_expire_umount(nn);
+#endif
 out:
        new_timeo = max_t(time64_t, new_timeo, NFSD_LAUNDROMAT_MINTIMEOUT);
        return new_timeo;
@@ -7398,6 +7403,9 @@ nfs4_state_shutdown_net(struct net *net)
 
        nfsd4_client_tracking_exit(net);
        nfs4_state_destroy_net(net);
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       nfsd4_ssc_shutdown_umount(nn);
+#endif
        mntput(nn->nfsd_mnt);
 }
 
fs/nfsd/nfsd.h +6 -0
index 8bdc37aa2c2e..cf86d9010974 100644
@@ -483,6 +483,12 @@ static inline bool nfsd_attrs_supported(u32 minorversion, const u32 *bmval)
 extern int nfsd4_is_junction(struct dentry *dentry);
 extern int register_cld_notifier(void);
 extern void unregister_cld_notifier(void);
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+extern void nfsd4_ssc_init_umount_work(struct nfsd_net *nn);
+extern void nfsd4_ssc_expire_umount(struct nfsd_net *nn);
+extern void nfsd4_ssc_shutdown_umount(struct nfsd_net *nn);
+#endif
+
 #else /* CONFIG_NFSD_V4 */
 static inline int nfsd4_is_junction(struct dentry *dentry)
 {
fs/nfsd/nfssvc.c +3 -0
index 6de406322106..ce89a8fe07ff 100644
@@ -403,6 +403,9 @@ static int nfsd_startup_net(int nrservs, struct net *net, const struct cred *cre
        if (ret)
                goto out_filecache;
 
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       nfsd4_ssc_init_umount_work(nn);
+#endif
        nn->nfsd_net_up = true;
        return 0;
 
include/linux/nfs_ssc.h +16 -1
index f5ba0fbff72f..18afe62988b5 100644
@@ -8,6 +8,7 @@
  */
 
 #include <linux/nfs_fs.h>
+#include <linux/sunrpc/svc.h>
 
 extern struct nfs_ssc_client_ops_tbl nfs_ssc_client_tbl;
 
@@ -52,6 +53,21 @@ static inline void nfs42_ssc_close(struct file *filep)
        if (nfs_ssc_client_tbl.ssc_nfs4_ops)
                (*nfs_ssc_client_tbl.ssc_nfs4_ops->sco_close)(filep);
 }
+
+struct nfsd4_ssc_umount_item {
+       struct list_head nsui_list;
+       bool nsui_busy;
+       refcount_t nsui_refcnt;
+       unsigned long nsui_expire;
+       struct vfsmount *nsui_vfsmount;
+       char nsui_ipaddr[RPC_MAX_ADDRBUFLEN];
+};
+
+struct nfsd4_ssc_umount {
+       struct list_head nsu_list;
+       unsigned long nsu_expire;
+       wait_queue_head_t nsu_waitq;
+};
 #endif
 
 /*
--

2.9.5

#10 lore raw
Quoted 2 lines · Olga Kornievskaia

General question to maybe Bruce: can nfsd_net go away while a compound is using it ?

No. Any server threads for that container should be shut down before nfsd_net goes away.

--b.

#11 lore raw
Quoted 7 lines · J. Bruce Fields
Quoted 2 lines · Olga Kornievskaia

General question to maybe Bruce: can nfsd_net go away while a compound is using it ?

No. Any server threads for that container should be shut down before nfsd_net goes away.

Right, sorry but the async copy is a task that works after the compound of copy. You say "threads .. should be shut down", who makes sure of that (meaning should async copy code make sure of it)?

Quoted 2 lines

--b.

#12 lore raw
Quoted 11 lines · Olga Kornievskaia
Quoted 7 lines · J. Bruce Fields
Quoted 2 lines · Olga Kornievskaia

General question to maybe Bruce: can nfsd_net go away while a compound is using it ?

No. Any server threads for that container should be shut down before nfsd_net goes away.

Right, sorry but the async copy is a task that works after the compound of copy.

OK, I thought you were talking about normal compound processing from server threads.

Quoted 2 lines

You say "threads .. should be shut down", who makes sure of that (meaning should async copy code make sure of it)?

Just looking at the code... nfsd4_shutdown_copy() is called when a client is destroyed to stop any in-progress copies.

--b.

author reviewer
#13 lore raw
In reply to Olga Kornievskaia
Quoted 60 lines · Olga Kornievskaia

Hi Dai,

General review comments inline

Quoted 55 lines · Dai Ngo

Currently the source's export is mounted and unmounted on every inter-server copy operation. This patch is an enhancement to delay the unmount of the source export for a certain period of time to eliminate the mount and unmount overhead on subsequent copy operations.

After a copy operation completes, a delayed task is scheduled to unmount the export after a configurable idle time. Each time the export is being used again, its expire time is extended to allow the export to remain mounted.

The unmount task and the mount operation of the copy request are synced to make sure the export is not unmounted while it's being used.

---
  fs/nfsd/netns.h         |   5 ++
  fs/nfsd/nfs4proc.c      | 216 +++++++++++++++++++++++++++++++++++++++++++++++-
  fs/nfsd/nfs4state.c     |   8 ++
  fs/nfsd/nfsd.h          |   6 ++
  fs/nfsd/nfssvc.c        |   3 +
  include/linux/nfs_ssc.h |  16 ++++
  6 files changed, 250 insertions(+), 4 deletions(-)
fs/nfsd/netns.h +5 -0
index c330f5bd0cf3..6018e5050cb4 100644
@@ -21,6 +21,7 @@
 
  struct cld_net;
  struct nfsd4_client_tracking_ops;
+struct nfsd4_ssc_umount;
 
  enum {
         /* cache misses due only to checksum comparison failures */
@@ -176,6 +177,10 @@ struct nfsd_net {
         unsigned int             longest_chain_cachesize;
 
         struct shrinker         nfsd_reply_cache_shrinker;
+
+       spinlock_t              nfsd_ssc_lock;
+       struct nfsd4_ssc_umount *nfsd_ssc_umount;
+
         /* utsname taken from the process that starts the server */
         char                    nfsd_name[UNX_MAXNODENAME+1];
  };
fs/nfsd/nfs4proc.c +0 -0
index dd9f38d072dd..892ad72d87ae 100644
@@ -55,6 +55,99 @@ module_param(inter_copy_offload_enable, bool, 0644);
  MODULE_PARM_DESC(inter_copy_offload_enable,
                  "Enable inter server to server copy offload. Default: false");
 
Quoted 8 lines

fs/nfsd/nfs4proc.c module_param(inter_copy_offload_enable, bool, 0644); · line 64

Quoted 7 lines
fs/nfsd/nfs4proc.c +7 -0
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+static int nfsd4_ssc_umount_timeout = 900000;          /* default to 15 mins */
+module_param(nfsd4_ssc_umount_timeout, int, 0644);
+MODULE_PARM_DESC(nfsd4_ssc_umount_timeout,
+               "idle msecs before unmount export from source server");
+
+void nfsd4_ssc_expire_umount(struct nfsd_net *nn)

Why should this be in nfs4proc.c when it's used in nfs4state.c only?

I will move nfsd4_ssc_expire_umount to nfs4state.c

Quoted 27 lines
Quoted 27 lines
fs/nfsd/nfs4proc.c +26 -0
+{
+       bool do_wakeup = false;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount *nu;
+
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (time_after(jiffies, ni->nsui_expire)) {
+                       if (refcount_read(&ni->nsui_refcnt) > 0)
+                               continue;
+
+                       /* mark being unmount */
+                       ni->nsui_busy = true;
+                       spin_unlock(&nn->nfsd_ssc_lock);
+                       mntput(ni->nsui_vfsmount);
+                       spin_lock(&nn->nfsd_ssc_lock);
+
+                       /* waiters need to start from begin of list */
+                       list_del(&ni->nsui_list);
+                       kfree(ni);
Quoted 8 lines

fs/nfsd/nfs4proc.c module_param(inter_copy_offload_enable, bool, 0644); · line 96

Quoted 6 lines
fs/nfsd/nfs4proc.c +6 -0
+
+                       /* wakeup ssc_connect waiters */
+                       do_wakeup = true;
+                       continue;
+               }
+               break;

mnt1, mnt2, mnt3 added all at the same time. mnt1, mnt3 only used once during the expiration time. mnt2 is being used continuously.

m2's nsu_expire is updated and re-inserted to the tail of the list every time it's used.

Quoted 3 lines

expiration time comes. delayed mnt1 is processed. mnt2 is next on the list and it's not expired so code quits. mnt3 will not be umounted until mnt2 expires. I think the break is wrong.

m1 and m3 will be processed first and unmounted if their nsu_expire expires, m2 is last on the list.

-Dai

Quoted 311 lines
Quoted 30 lines
fs/nfsd/nfs4proc.c +29 -0
+       }
+       if (!list_empty(&nu->nsu_list)) {
+               ni = list_first_entry(&nu->nsu_list,
+                       struct nfsd4_ssc_umount_item, nsui_list);
+               nu->nsu_expire = ni->nsui_expire;
+       } else
+               nu->nsu_expire = 0;
+
+       if (do_wakeup)
+               wake_up_all(&nu->nsu_waitq);
+       spin_unlock(&nn->nfsd_ssc_lock);
+}
+
+/*
+ * This is called when nfsd is being shutdown, after all inter_ssc
+ * cleanup were done, to destroy the ssc delayed unmount list.
+ */
+void nfsd4_ssc_shutdown_umount(struct nfsd_net *nn)
+{
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount *nu;
+
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;

fs/nfsd/nfs4proc.c module_param(inter_copy_offload_enable, bool, 0644); · line 135

Quoted 10 lines
fs/nfsd/nfs4proc.c +10 -0
+       nn->nfsd_ssc_umount = 0;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               list_del(&ni->nsui_list);
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ni->nsui_vfsmount);
+               kfree(ni);
+               spin_lock(&nn->nfsd_ssc_lock);
+       }
+       spin_unlock(&nn->nfsd_ssc_lock);
+       kfree(nu);

General question to maybe Bruce: can nfsd_net go away while a compound is using it ? I hope not. I can't quite think thru the scenario where we started the async copy task but then somehow nfsd_net is going away before async_copy is done and if there is anything we need to take care of. I think the net shutdown would not find anything to free so it would just return. And the copy's cleanup would not find a nfsd_net and so it would right away unmount. This is more of thinking out loud but I'd like somebody else to confirm I'm correct that we are OK here.

Quoted 262 lines
fs/nfsd/nfs4proc.c +134 -4
+}
+
+void nfsd4_ssc_init_umount_work(struct nfsd_net *nn)
+{
+       nn->nfsd_ssc_umount = kzalloc(sizeof(struct nfsd4_ssc_umount),
+                                       GFP_KERNEL);
+       if (!nn->nfsd_ssc_umount)
+               return;
+       spin_lock_init(&nn->nfsd_ssc_lock);
+       INIT_LIST_HEAD(&nn->nfsd_ssc_umount->nsu_list);
+       init_waitqueue_head(&nn->nfsd_ssc_umount->nsu_waitq);
+}
+EXPORT_SYMBOL_GPL(nfsd4_ssc_init_umount_work);
+#endif
+
  #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
  #include <linux/security.h>
 
@@ -1181,6 +1274,12 @@ nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
         char *ipaddr, *dev_name, *raw_data;
         int len, raw_len;
         __be32 status = nfserr_inval;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount_item *work = NULL;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
+       struct nfsd4_ssc_umount *nu;
+       DEFINE_WAIT(wait);
 
         naddr = &nss->u.nl4_addr;
         tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr,
@@ -1229,12 +1328,76 @@ nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
                 goto out_free_rawdata;
         snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep);
 
+       work = kzalloc(sizeof(*work), GFP_KERNEL);
+try_again:
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               kfree(work);
+               work = NULL;
+               goto skip_dul;
+       }
+       nu = nn->nfsd_ssc_umount;
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (strncmp(ni->nsui_ipaddr, ipaddr, sizeof(ni->nsui_ipaddr)))
+                       continue;
+               /* found a match */
+               if (ni->nsui_busy) {
+                       /*  wait - and try again */
+                       prepare_to_wait(&nu->nsu_waitq, &wait,
+                               TASK_INTERRUPTIBLE);
+                       spin_unlock(&nn->nfsd_ssc_lock);
+
+                       /* allow 20secs for mount/unmount for now - revisit */
+                       if (signal_pending(current) ||
+                                       (schedule_timeout(20*HZ) == 0)) {
+                               status = nfserr_eagain;
+                               kfree(work);
+                               goto out_free_devname;
+                       }
+                       finish_wait(&nu->nsu_waitq, &wait);
+                       goto try_again;
+               }
+               ss_mnt = ni->nsui_vfsmount;
+               if (refcount_read(&ni->nsui_refcnt) == 0)
+                       refcount_set(&ni->nsui_refcnt, 1);
+               else
+                       refcount_inc(&ni->nsui_refcnt);
+               spin_unlock(&nn->nfsd_ssc_lock);
+               kfree(work);
+               goto out_done;
+       }
+       /* create new entry, set busy, insert list, clear busy after mount */
+       if (work) {
+               strncpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr));
+               refcount_set(&work->nsui_refcnt, 1);
+               work->nsui_busy = true;
+               list_add_tail(&work->nsui_list, &nu->nsu_list);
+       }
+       spin_unlock(&nn->nfsd_ssc_lock);
+skip_dul:
+
         /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */
         ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data);
         module_put(type->owner);
-       if (IS_ERR(ss_mnt))
+       if (IS_ERR(ss_mnt)) {
+               if (work) {
+                       spin_lock(&nn->nfsd_ssc_lock);
+                       list_del(&work->nsui_list);
+                       wake_up_all(&nu->nsu_waitq);
+                       spin_unlock(&nn->nfsd_ssc_lock);
+                       kfree(work);
+               }
                 goto out_free_devname;
-
+       }
+       if (work) {
+               spin_lock(&nn->nfsd_ssc_lock);
+               work->nsui_vfsmount = ss_mnt;
+               work->nsui_busy = false;
+               wake_up_all(&nu->nsu_waitq);
+               spin_unlock(&nn->nfsd_ssc_lock);
+       }
+out_done:
         status = 0;
         *mount = ss_mnt;
 
@@ -1301,10 +1464,55 @@ static void
  nfsd4_cleanup_inter_ssc(struct vfsmount *ss_mnt, struct nfsd_file *src,
                         struct nfsd_file *dst)
  {
+       bool found = false;
+       bool resched = false;
+       long timeout;
+       struct nfsd4_ssc_umount_item *tmp;
+       struct nfsd4_ssc_umount_item *ni = 0;
+       struct nfsd4_ssc_umount *nu;
+       struct nfsd_net *nn = net_generic(dst->nf_net, nfsd_net_id);
+
         nfs42_ssc_close(src->nf_file);
-       fput(src->nf_file);
         nfsd_file_put(dst);
-       mntput(ss_mnt);
+       fput(src->nf_file);
+
+       if (!nn) {
+               mntput(ss_mnt);
+               return;
+       }
+       spin_lock(&nn->nfsd_ssc_lock);
+       if (!nn->nfsd_ssc_umount) {
+               /* delayed unmount list not setup */
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ss_mnt);
+               return;
+       }
+       nu = nn->nfsd_ssc_umount;
+       timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout);
+       list_for_each_entry_safe(ni, tmp, &nu->nsu_list, nsui_list) {
+               if (ni->nsui_vfsmount->mnt_sb == ss_mnt->mnt_sb) {
+                       list_del(&ni->nsui_list);
+                       /*
+                        * vfsmount can be shared by multiple exports,
+                        * decrement refcnt and schedule delayed task
+                        * if it drops to 0.
+                        */
+                       if (refcount_dec_and_test(&ni->nsui_refcnt))
+                               resched = true;
+                       ni->nsui_expire = jiffies + timeout;
+                       list_add_tail(&ni->nsui_list, &nu->nsu_list);
+                       found = true;
+                       break;
+               }
+       }
+       if (!found) {
+               spin_unlock(&nn->nfsd_ssc_lock);
+               mntput(ss_mnt);
+               return;
+       }
+       if (resched && !nu->nsu_expire)
+               nu->nsu_expire = ni->nsui_expire;
+       spin_unlock(&nn->nfsd_ssc_lock);
  }
 
  #else /* CONFIG_NFSD_V4_2_INTER_SSC */
fs/nfsd/nfs4state.c +8 -0
index 97447a64bad0..0cdc898f06c9 100644
@@ -5459,6 +5459,11 @@ nfs4_laundromat(struct nfsd_net *nn)
                 list_del_init(&nbl->nbl_lru);
                 free_blocked_lock(nbl);
         }
+
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       /* service the inter-copy delayed unmount list */
+       nfsd4_ssc_expire_umount(nn);
+#endif
  out:
         new_timeo = max_t(time64_t, new_timeo, NFSD_LAUNDROMAT_MINTIMEOUT);
         return new_timeo;
@@ -7398,6 +7403,9 @@ nfs4_state_shutdown_net(struct net *net)
 
         nfsd4_client_tracking_exit(net);
         nfs4_state_destroy_net(net);
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       nfsd4_ssc_shutdown_umount(nn);
+#endif
         mntput(nn->nfsd_mnt);
  }
 
fs/nfsd/nfsd.h +6 -0
index 8bdc37aa2c2e..cf86d9010974 100644
@@ -483,6 +483,12 @@ static inline bool nfsd_attrs_supported(u32 minorversion, const u32 *bmval)
  extern int nfsd4_is_junction(struct dentry *dentry);
  extern int register_cld_notifier(void);
  extern void unregister_cld_notifier(void);
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+extern void nfsd4_ssc_init_umount_work(struct nfsd_net *nn);
+extern void nfsd4_ssc_expire_umount(struct nfsd_net *nn);
+extern void nfsd4_ssc_shutdown_umount(struct nfsd_net *nn);
+#endif
+
  #else /* CONFIG_NFSD_V4 */
  static inline int nfsd4_is_junction(struct dentry *dentry)
  {
fs/nfsd/nfssvc.c +3 -0
index 6de406322106..ce89a8fe07ff 100644
@@ -403,6 +403,9 @@ static int nfsd_startup_net(int nrservs, struct net *net, const struct cred *cre
         if (ret)
                 goto out_filecache;
 
+#ifdef CONFIG_NFSD_V4_2_INTER_SSC
+       nfsd4_ssc_init_umount_work(nn);
+#endif
         nn->nfsd_net_up = true;
         return 0;
 
include/linux/nfs_ssc.h +16 -1
index f5ba0fbff72f..18afe62988b5 100644
@@ -8,6 +8,7 @@
   */
 
  #include <linux/nfs_fs.h>
+#include <linux/sunrpc/svc.h>
 
  extern struct nfs_ssc_client_ops_tbl nfs_ssc_client_tbl;
 
@@ -52,6 +53,21 @@ static inline void nfs42_ssc_close(struct file *filep)
         if (nfs_ssc_client_tbl.ssc_nfs4_ops)
                 (*nfs_ssc_client_tbl.ssc_nfs4_ops->sco_close)(filep);
  }
+
+struct nfsd4_ssc_umount_item {
+       struct list_head nsui_list;
+       bool nsui_busy;
+       refcount_t nsui_refcnt;
+       unsigned long nsui_expire;
+       struct vfsmount *nsui_vfsmount;
+       char nsui_ipaddr[RPC_MAX_ADDRBUFLEN];
+};
+
+struct nfsd4_ssc_umount {
+       struct list_head nsu_list;
+       unsigned long nsu_expire;
+       wait_queue_head_t nsu_waitq;
+};
  #endif
 
  /*
--

2.9.5

author reviewer
#14 lore raw

PATCH v5 2/2 NFSv4.2: remove restriction of copy size for inter-server copy.

In reply to Dai Ngo

Currently inter-server copy is allowed only if the copy size is larger than (rsize*14) which is the over-head of the mount operation of the source export. This patch, relying on the delayed unmount feature, removes this restriction since the mount and unmount overhead is now not applicable for every inter-server copy.

---
 fs/nfs/nfs4file.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
fs/nfs/nfs4file.c +4 -6
index 441a2fa073c8..b5821ed46994 100644
@@ -158,13 +158,11 @@ static ssize_t __nfs4_copy_file_range(struct file *file_in, loff_t pos_in,
 		sync = true;
 retry:
 	if (!nfs42_files_from_same_server(file_in, file_out)) {
-		/* for inter copy, if copy size if smaller than 12 RPC
-		 * payloads, fallback to traditional copy. There are
-		 * 14 RPCs during an NFSv4.x mount between source/dest
-		 * servers.
+		/*
+		 * for inter copy, if copy size is too small
+		 * then fallback to generic copy.
 		 */
-		if (sync ||
-			count <= 14 * NFS_SERVER(file_inode(file_in))->rsize)
+		if (sync)
 			return -EOPNOTSUPP;
 		cn_resp = kzalloc(sizeof(struct nfs42_copy_notify_res),
 				GFP_NOFS);
Signature · 1 line
2.9.5