[pnfs] [PATCH 18/29] pnfs: update nfs4_pnfs_dserver_get

Benny Halevy bhalevy at panasas.com
Fri Dec 28 03:45:33 EST 2007


From: Andy Adamson <andros at umich.edu>

Lookup the device id and use the stripe count to index the multipath data
server for a byte range.

destroy_ds can be called with a NULL struct nfs_client pointer from nfs4_pnfs_ds_add.

Clean up types.

Signed-off-by: Andy Adamson<andros at umich.edu>
Signed-off-by: Benny Halevy <bhalevy at panasas.com>
---
 fs/nfs/nfs4filelayout.h    |    4 +-
 fs/nfs/nfs4filelayoutdev.c |   52 +++++++++++++++++++++++++------------------
 2 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/fs/nfs/nfs4filelayout.h b/fs/nfs/nfs4filelayout.h
index da79e3f..fd099c7 100644
--- a/fs/nfs/nfs4filelayout.h
+++ b/fs/nfs/nfs4filelayout.h
@@ -106,8 +106,8 @@ void nfs4_pnfs_devlist_destroy(struct nfs4_pnfs_dev_hlist *hlist);
 
 int nfs4_pnfs_dserver_get(struct inode *inode,
 			  struct nfs4_filelayout *layout,
-			  u64 offset,
-			  u32 count,
+			  loff_t offset,
+			  size_t count,
 			  struct nfs4_pnfs_dserver *dserver);
 int decode_and_add_devicelist(struct filelayout_mount_type *mt, struct pnfs_devicelist *devlist);
 
diff --git a/fs/nfs/nfs4filelayoutdev.c b/fs/nfs/nfs4filelayoutdev.c
index 001592e..7430658 100644
--- a/fs/nfs/nfs4filelayoutdev.c
+++ b/fs/nfs/nfs4filelayoutdev.c
@@ -263,10 +263,12 @@ unhash_ds(struct nfs4_pnfs_ds *ds)
 static void
 destroy_ds(struct nfs4_pnfs_ds *ds)
 {
-	nfs4_proc_destroy_session(ds->ds_clp->cl_ds_session,
+	if (ds->ds_clp) {
+		nfs4_proc_destroy_session(ds->ds_clp->cl_ds_session,
 					  ds->ds_clp->cl_rpcclient);
-	rpc_shutdown_client(ds->ds_clp->cl_rpcclient);
-	ds->ds_clp->cl_rpcclient = NULL;
+		rpc_shutdown_client(ds->ds_clp->cl_rpcclient);
+		ds->ds_clp->cl_rpcclient = NULL;
+	}
 	kfree(ds);
 }
 
@@ -653,43 +655,49 @@ nfs4_pnfs_device_item_get(struct inode *inode, u32 dev_id)
 int
 nfs4_pnfs_dserver_get(struct inode *inode,
 		      struct nfs4_filelayout *layout,
-		      u64 offset,
-		      u32 count,
+		      loff_t offset,
+		      size_t count,
 		      struct nfs4_pnfs_dserver *dserver)
 {
+	struct nfs4_pnfs_dev_item *di;
 	u64 tmp;
-	u32 stripe_idx, dbg_stripe_idx;
+	u32 stripe_idx, end_idx;
 
 	if (!layout)
 		return 1;
 
+	di = nfs4_pnfs_device_item_get(inode, layout->dev_id);
+	if (di == NULL)
+		return 1;
+
+	/* Want ((offset / layout->stripe_unit) % di->stripe_count)
+	* n_str = stripe for offset */
+
 	tmp = offset;
-	/* Want ((offset / layout->stripe_unit) % layout->num_devs) */
 	do_div(tmp, layout->stripe_unit);
-	stripe_idx = do_div(tmp, layout->num_fh) + layout->first_stripe_index;
+	stripe_idx = do_div(tmp, di->stripe_count) + layout->first_stripe_index;
 
-	/* For debugging */
 	tmp = offset + count - 1;
 	do_div(tmp, layout->stripe_unit);
-	dbg_stripe_idx = do_div(tmp, layout->num_fh) +
-				layout->first_stripe_index;
+	end_idx = do_div(tmp, di->stripe_count) + layout->first_stripe_index;
 
-	dprintk("%s: offset=%Lu, count=%u, si=%u, dsi=%u, "
-		   "num_devs=%u, stripe_unit=%Lu\n",
-		   __FUNCTION__,
-		   offset, count, stripe_idx, dbg_stripe_idx, layout->num_fh,
-		   layout->stripe_unit);
+	dprintk("%s: offset=%Lu, count=%Zu, si=%u, dsi=%u, "
+		"stripe_count=%u, stripe_unit=%Lu first_stripe_index %d\n",
+		__FUNCTION__,
+		offset, count, stripe_idx, end_idx, di->stripe_count,
+		layout->stripe_unit, layout->first_stripe_index);
 
-	BUG_ON(dbg_stripe_idx != stripe_idx);
+	BUG_ON(end_idx != stripe_idx);
 
-	/* TODO: rewrite this function!
-	dserver->dev = nfs4_pnfs_device_get(inode, layout->dev_id, stripe_idx);
+	dserver->dev = &di->stripe_devs[stripe_idx];
 	if (dserver->dev == NULL)
 		return 1;
-	*/
-	dserver->fh = &layout->fh_array[stripe_idx];
+	if (layout->num_fh == 1)
+		dserver->fh = &layout->fh_array[0];
+	else
+		dserver->fh = &layout->fh_array[stripe_idx];
 
-	dprintk("%s: dev_id=%u, idx=%u, offset=%Lu, count=%u\n",
+	dprintk("%s: dev_id=%u, idx=%u, offset=%Lu, count=%Zu\n",
 		__FUNCTION__, layout->dev_id, stripe_idx, offset, count);
 
 	return 0;
-- 
1.5.3.3



More information about the pNFS mailing list