[pnfs] [PATCH 1/2] layoutrecall: reorganize pnfs code in nfs/delegation.[ch]
Benny Halevy
bhalevy at panasas.com
Mon Sep 10 07:10:55 EDT 2007
just shoving pieces of code around
Signed-off-by: Benny Halevy <bhalevy at panasas.com>
---
fs/nfs/delegation.c | 210 ++++++++++++++++++++++++++-------------------------
fs/nfs/delegation.h | 14 +++-
2 files changed, 117 insertions(+), 107 deletions(-)
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 16cf3f6..02f706a 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -312,15 +312,6 @@ struct recall_threadargs {
int result;
};
-struct recall_layout_threadargs {
- struct inode *inode;
- struct nfs4_client *clp;
- const nfs4_stateid *stateid;
- struct completion started;
- struct cb_pnfs_layoutrecallargs rl;
- int result;
-};
-
static int recall_thread(void *data)
{
struct recall_threadargs *args = (struct recall_threadargs *)data;
@@ -360,6 +351,112 @@ static int recall_thread(void *data)
module_put_and_exit(0);
}
+/*
+ * Asynchronous delegation recall!
+ */
+int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid)
+{
+ struct recall_threadargs data = {
+ .inode = inode,
+ .stateid = stateid,
+ };
+ int status;
+
+ init_completion(&data.started);
+ __module_get(THIS_MODULE);
+ status = kernel_thread(recall_thread, &data, CLONE_KERNEL);
+ if (status < 0)
+ goto out_module_put;
+ wait_for_completion(&data.started);
+ return data.result;
+out_module_put:
+ module_put(THIS_MODULE);
+ return status;
+}
+
+/*
+ * Retrieve the inode associated with a delegation
+ */
+struct inode *nfs_delegation_find_inode(struct nfs4_client *clp, const struct nfs_fh *fhandle)
+{
+ struct nfs_delegation *delegation;
+ struct inode *res = NULL;
+ spin_lock(&clp->cl_lock);
+ list_for_each_entry(delegation, &clp->cl_delegations, super_list) {
+ if (nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) {
+ res = igrab(delegation->inode);
+ break;
+ }
+ }
+ spin_unlock(&clp->cl_lock);
+ return res;
+}
+
+/*
+ * Mark all delegations as needing to be reclaimed
+ */
+void nfs_delegation_mark_reclaim(struct nfs4_client *clp)
+{
+ struct nfs_delegation *delegation;
+ spin_lock(&clp->cl_lock);
+ list_for_each_entry(delegation, &clp->cl_delegations, super_list)
+ delegation->flags |= NFS_DELEGATION_NEED_RECLAIM;
+ spin_unlock(&clp->cl_lock);
+}
+
+/*
+ * Reap all unclaimed delegations after reboot recovery is done
+ */
+void nfs_delegation_reap_unclaimed(struct nfs4_client *clp)
+{
+ struct nfs_delegation *delegation, *n;
+ LIST_HEAD(head);
+ spin_lock(&clp->cl_lock);
+ list_for_each_entry_safe(delegation, n, &clp->cl_delegations, super_list) {
+ if ((delegation->flags & NFS_DELEGATION_NEED_RECLAIM) == 0)
+ continue;
+ list_move(&delegation->super_list, &head);
+ NFS_I(delegation->inode)->delegation = NULL;
+ NFS_I(delegation->inode)->delegation_state = 0;
+ }
+ spin_unlock(&clp->cl_lock);
+ while(!list_empty(&head)) {
+ delegation = list_entry(head.next, struct nfs_delegation, super_list);
+ list_del(&delegation->super_list);
+ nfs_free_delegation(delegation);
+ }
+}
+
+int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode)
+{
+ struct nfs4_client *clp = NFS_SERVER(inode)->nfs4_state;
+ struct nfs_inode *nfsi = NFS_I(inode);
+ struct nfs_delegation *delegation;
+ int res = 0;
+
+ if (nfsi->delegation_state == 0)
+ return 0;
+ spin_lock(&clp->cl_lock);
+ delegation = nfsi->delegation;
+ if (delegation != NULL) {
+ memcpy(dst->data, delegation->stateid.data, sizeof(dst->data));
+ res = 1;
+ }
+ spin_unlock(&clp->cl_lock);
+ return res;
+}
+
+#if defined(CONFIG_PNFS)
+
+struct recall_layout_threadargs {
+ struct inode *inode;
+ struct nfs4_client *clp;
+ const nfs4_stateid *stateid;
+ struct completion started;
+ struct cb_pnfs_layoutrecallargs rl;
+ int result;
+};
+
static int recall_layout_thread(void *data)
{
struct inode *inode = NULL;
@@ -460,29 +557,6 @@ out:
}
/*
- * Asynchronous delegation recall!
- */
-int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid)
-{
- struct recall_threadargs data = {
- .inode = inode,
- .stateid = stateid,
- };
- int status;
-
- init_completion(&data.started);
- __module_get(THIS_MODULE);
- status = kernel_thread(recall_thread, &data, CLONE_KERNEL);
- if (status < 0)
- goto out_module_put;
- wait_for_completion(&data.started);
- return data.result;
-out_module_put:
- module_put(THIS_MODULE);
- return status;
-}
-
-/*
* Asynchronous layout recall!
*/
int nfs_async_return_layout(struct nfs4_client *clp, struct inode *inode, void *args)
@@ -513,24 +587,6 @@ out_module_put:
}
/*
- * Retrieve the inode associated with a delegation
- */
-struct inode *nfs_delegation_find_inode(struct nfs4_client *clp, const struct nfs_fh *fhandle)
-{
- struct nfs_delegation *delegation;
- struct inode *res = NULL;
- spin_lock(&clp->cl_lock);
- list_for_each_entry(delegation, &clp->cl_delegations, super_list) {
- if (nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) {
- res = igrab(delegation->inode);
- break;
- }
- }
- spin_unlock(&clp->cl_lock);
- return res;
-}
-
-/*
* Retrieve the inode associated with a layout
*/
struct inode *nfs_layout_find_inode(struct nfs4_client *clp, const struct nfs_fh *fhandle)
@@ -555,56 +611,4 @@ struct inode *nfs_layout_find_inode(struct nfs4_client *clp, const struct nfs_fh
return res;
}
-/*
- * Mark all delegations as needing to be reclaimed
- */
-void nfs_delegation_mark_reclaim(struct nfs4_client *clp)
-{
- struct nfs_delegation *delegation;
- spin_lock(&clp->cl_lock);
- list_for_each_entry(delegation, &clp->cl_delegations, super_list)
- delegation->flags |= NFS_DELEGATION_NEED_RECLAIM;
- spin_unlock(&clp->cl_lock);
-}
-
-/*
- * Reap all unclaimed delegations after reboot recovery is done
- */
-void nfs_delegation_reap_unclaimed(struct nfs4_client *clp)
-{
- struct nfs_delegation *delegation, *n;
- LIST_HEAD(head);
- spin_lock(&clp->cl_lock);
- list_for_each_entry_safe(delegation, n, &clp->cl_delegations, super_list) {
- if ((delegation->flags & NFS_DELEGATION_NEED_RECLAIM) == 0)
- continue;
- list_move(&delegation->super_list, &head);
- NFS_I(delegation->inode)->delegation = NULL;
- NFS_I(delegation->inode)->delegation_state = 0;
- }
- spin_unlock(&clp->cl_lock);
- while(!list_empty(&head)) {
- delegation = list_entry(head.next, struct nfs_delegation, super_list);
- list_del(&delegation->super_list);
- nfs_free_delegation(delegation);
- }
-}
-
-int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode)
-{
- struct nfs4_client *clp = NFS_SERVER(inode)->nfs4_state;
- struct nfs_inode *nfsi = NFS_I(inode);
- struct nfs_delegation *delegation;
- int res = 0;
-
- if (nfsi->delegation_state == 0)
- return 0;
- spin_lock(&clp->cl_lock);
- delegation = nfsi->delegation;
- if (delegation != NULL) {
- memcpy(dst->data, delegation->stateid.data, sizeof(dst->data));
- res = 1;
- }
- spin_unlock(&clp->cl_lock);
- return res;
-}
+#endif /* defined(CONFIG_PNFS) */
diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h
index 43fcb55..6db79de 100644
--- a/fs/nfs/delegation.h
+++ b/fs/nfs/delegation.h
@@ -8,6 +8,8 @@
#ifndef FS_NFS_DELEGATION_H
#define FS_NFS_DELEGATION_H
+#include "callback.h"
+
#if defined(CONFIG_NFS_V4)
/*
* NFSv4 delegation
@@ -28,10 +30,8 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res);
int __nfs_inode_return_delegation(struct inode *inode);
int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid);
-int nfs_async_return_layout(struct nfs4_client *clp, struct inode *inode, void *arg);
struct inode *nfs_delegation_find_inode(struct nfs4_client *clp, const struct nfs_fh *fhandle);
-struct inode *nfs_layout_find_inode(struct nfs4_client *clp, const struct nfs_fh *fhandle);
void nfs_return_all_delegations(struct super_block *sb);
void nfs_expire_all_delegations(struct nfs4_client *clp);
void nfs_handle_cb_pathdown(struct nfs4_client *clp);
@@ -62,7 +62,13 @@ static inline int nfs_inode_return_delegation(struct inode *inode)
err = __nfs_inode_return_delegation(inode);
return err;
}
-#else
+
+#if defined(CONFIG_PNFS)
+int nfs_async_return_layout(struct nfs4_client *clp, struct inode *inode, void *arg);
+struct inode *nfs_layout_find_inode(struct nfs4_client *clp, const struct nfs_fh *fhandle);
+#endif /* defined(CONFIG_PNFS) */
+
+#else /* defined(CONFIG_NFS_V4) */
static inline int nfs_have_delegation(struct inode *inode, int flags)
{
return 0;
@@ -72,6 +78,6 @@ static inline int nfs_inode_return_delegation(struct inode *inode)
{
return 0;
}
-#endif
+#endif /* defined(CONFIG_NFS_V4) */
#endif
--
1.5.3.1
More information about the pNFS
mailing list