[pnfs] [PATCH 5/9] nfsd layout cache: struct nfsd4_layout_seg

Benny Halevy bhalevy at panasas.com
Sun May 27 05:27:26 EDT 2007


define a layout segent type and embed it in pnfs xdr level types
(other patches embed it also in other structures, e.g. struct nfs4_layout)

Signed-off-by: Benny Halevy <bhalevy at panasas.com>
---
 fs/nfsd/nfs4proc.c              |   20 ++++++++++--------
 fs/nfsd/nfs4state.c             |   30 ++++++++++++----------------
 fs/nfsd/nfs4xdr.c               |   40 +++++++++++++++++++-------------------
 include/linux/nfsd/nfsd4_pnfs.h |   35 +++++++++++++--------------------
 4 files changed, 58 insertions(+), 67 deletions(-)

diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 1299676..f484a9e 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -805,9 +805,10 @@ nfsd4_layoutget( struct svc_rqst *rqstp, struct current_session *cses, struct sv
 	/* check to see if requested layout type is supported. */
 	status = nfserr_unknown_layouttype;
 	if (!sb->s_export_op->layout_type ||
-		((type = sb->s_export_op->layout_type()) != lgp->lg_type)) {
+		((type = sb->s_export_op->layout_type()) != lgp->lg_seg.layout_type)) {
 
-		printk("pNFS %s: requested layout type %d does not match suppored type %d\n", __FUNCTION__, lgp->lg_type, type);
+		dprintk("pNFS %s: requested layout type %d does not match suppored type %d\n",
+		        __FUNCTION__, lgp->lg_seg.layout_type, type);
 		goto out;
 	}
 
@@ -816,8 +817,7 @@ nfsd4_layoutget( struct svc_rqst *rqstp, struct current_session *cses, struct sv
 
         /* Set file handle and clientid*/
 	memcpy(&lgp->lg_fh, &current_fh->fh_handle, sizeof(struct knfsd_fh));
-	memcpy(&lgp->lg_clientid, &cses->cs_sid.clientid,
-		sizeof(lgp->lg_clientid));
+	lgp->lg_seg.clientid  = *(u64 *)&cses->cs_sid.clientid;
 
         status = nfs4_pnfs_get_layout(sb, current_fh, lgp);
 out:
@@ -857,6 +857,9 @@ nfsd4_layoutcommit( struct svc_rqst *rqstp, struct current_session *cses, struct
 		goto out;
 	}
 
+        /* Set clientid from sessionid */
+	lcp->lc_seg.clientid  = *(u64 *)&cses->cs_sid.clientid;
+
 	/* Try our best to update the file size */
 	dprintk("%s: Modifying file size\n", __FUNCTION__);
 	ia.ia_valid = ATTR_SIZE;
@@ -911,19 +914,18 @@ nfsd4_layoutreturn( struct svc_rqst *rqstp, struct current_session *cses, struct
 	/* check to see if requested layout type is supported. */
 	status = nfserr_unknown_layouttype;
 	if (!sb->s_export_op->layout_type ||
-		((type = sb->s_export_op->layout_type()) != lrp->lr_layout_type)) {
+		((type = sb->s_export_op->layout_type()) != lrp->lr_seg.layout_type)) {
 
-		printk("pNFS %s: requested layout type %d does not match suppored type %d\n", __FUNCTION__, lrp->lr_layout_type, type);
+		printk("pNFS %s: requested layout type %d does not match suppored type %d\n", __FUNCTION__, lrp->lr_seg.layout_type, type);
 		goto out;
 	}
 
         /* Set clientid from sessionid */
-	memcpy(&lrp->lr_clientid, &cses->cs_sid.clientid,
-		sizeof(lrp->lr_clientid));
+	lrp->lr_seg.clientid  = *(u64 *)&cses->cs_sid.clientid;
         status = nfs4_pnfs_return_layout(sb, current_fh, lrp);
 out:
 	dprintk("pNFS %s: status %d layout_type %d\n",
-		__FUNCTION__, status, lrp->lr_layout_type);
+		__FUNCTION__, status, lrp->lr_seg.layout_type);
 	return status;
 }
 
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 220459d..0e2723a 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -3920,11 +3920,11 @@ free_nfs4_layout(struct kref *kref)
 
 	dprintk("pNFS %s: lp %p fp %p ino %p\n", __FUNCTION__, lp, fp, ino);
 	lr.lr_reclaim = 0;
-	lr.lr_layout_type = lp->lo_layout_type;
-	lr.lr_iomode = lp->lo_iomode;
+	lr.lr_seg.layout_type = lp->lo_layout_type;
+	lr.lr_seg.iomode = lp->lo_iomode;
 	lr.lr_return_type = RETURN_FILE;
-	lr.lr_offset = lp->lo_offset;
-	lr.lr_length = lp->lo_length;
+	lr.lr_seg.offset = lp->lo_offset;
+	lr.lr_seg.length = lp->lo_length;
 	lr.lr_flags = 0; /* last return */
 
 //??? recall layout
@@ -3993,10 +3993,10 @@ pnfs_alloc_init_layout(struct nfs4_file *fp, struct nfs4_client *clp, struct svc
 	lp->lo_fhlen = current_fh->fh_handle.fh_size;
 	memcpy(lp->lo_fhval, &current_fh->fh_handle.fh_base,
 		        current_fh->fh_handle.fh_size);
-	lp->lo_layout_type = lg->lg_type;
-	lp->lo_iomode = lg->lg_iomode;
-	lp->lo_offset = lg->lg_offset;
-	lp->lo_length = lg->lg_length;
+	lp->lo_layout_type = lg->lg_seg.layout_type;
+	lp->lo_iomode = lg->lg_seg.iomode;
+	lp->lo_offset = lg->lg_seg.offset;
+	lp->lo_length = lg->lg_seg.length;
 	num_layouts++;
 	pnfs_hash_layoutget(lp);
 	get_nfs4_file(lp->lo_file);
@@ -4066,7 +4066,7 @@ int nfs4_pnfs_get_layout(struct super_block *sb, struct svc_fh *current_fh,
 		if (fp == NULL)
 			goto out;
 	}
-	clp = find_confirmed_client((clientid_t *)&lgp->lg_clientid);
+	clp = find_confirmed_client((clientid_t *)&lgp->lg_seg.clientid);
 	dprintk("pNFS %s: clp %p \n", __FUNCTION__, clp);
 	if (!clp)
 	        goto out;
@@ -4080,7 +4080,7 @@ int nfs4_pnfs_get_layout(struct super_block *sb, struct svc_fh *current_fh,
 					(void *)lgp);
 
 		dprintk("pNFS %s: status %d type %d maxcount %d \n",
-			__FUNCTION__, status, lgp->lg_type, lgp->lg_mxcnt);
+			__FUNCTION__, status, lgp->lg_seg.layout_type, lgp->lg_mxcnt);
 
 		switch (status) {
 			case 0:
@@ -4109,18 +4109,14 @@ int nfs4_pnfs_get_layout(struct super_block *sb, struct svc_fh *current_fh,
 		status = nfserr_layouttrylater;
 
 		if (lgp->lg_ops->layout_encode == NULL &&
-				lgp->lg_type == LAYOUT_NFSV4_FILES)
+				lgp->lg_seg.layout_type == LAYOUT_NFSV4_FILES)
 			filelayout_free_layout(lgp->lg_layout);
 		else
 			lgp->lg_ops->layout_free(lgp->lg_layout);
 
 		lr.lr_reclaim = 0;
-		lr.lr_layout_type = lgp->lg_type;
-		lr.lr_iomode = lgp->lg_iomode;
 		lr.lr_return_type = RETURN_FILE;
-		lr.lr_offset = lgp->lg_offset;
-		lr.lr_length = lgp->lg_length;
-		lr.lr_flags = lgp->lg_flags;
+		lr.lr_seg = lgp->lg_seg;
 		if (sb->s_export_op->layout_return)
 			sb->s_export_op->layout_return(ino, &lr);
 	}
@@ -4149,7 +4145,7 @@ int nfs4_pnfs_return_layout(struct super_block *sb, struct svc_fh *current_fh,
 
 	dprintk("pNFS %s: fp %p\n", __FUNCTION__, fp);
 
-	clp = find_confirmed_client((clientid_t *)&lrp->lr_clientid);
+	clp = find_confirmed_client((clientid_t *)&lrp->lr_seg.clientid);
 	dprintk("pNFS %s: clp %p \n", __FUNCTION__, clp);
 	if (!clp)
 	        goto out;
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 7621ec7..c0f8175 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -1213,10 +1213,10 @@ nfsd4_decode_layoutget(struct nfsd4_compoundargs *argp, struct nfsd4_pnfs_layout
 
 	READ_BUF(40);
 	READ32(lgp->lg_signal);
-	READ32(lgp->lg_type);
-	READ32(lgp->lg_iomode);
-	READ64(lgp->lg_offset);
-	READ64(lgp->lg_length);
+	READ32(lgp->lg_seg.layout_type);
+	READ32(lgp->lg_seg.iomode);
+	READ64(lgp->lg_seg.offset);
+	READ64(lgp->lg_seg.length);
 	READ64(lgp->lg_minlength);
 	READ32(lgp->lg_mxcnt);
 
@@ -1247,8 +1247,8 @@ nfsd4_decode_layoutcommit(struct nfsd4_compoundargs *argp, struct nfsd4_pnfs_lay
 	u32 timechange;
 
 	READ_BUF(36);
-	READ64(lcp->lc_offset);
-	READ64(lcp->lc_length);
+	READ64(lcp->lc_seg.offset);
+	READ64(lcp->lc_seg.length);
 	READ32(lcp->lc_reclaim);
 	READ32(lcp->lc_newoffset);
 	READ64(lcp->lc_last_wr);
@@ -1272,16 +1272,16 @@ nfsd4_decode_layoutcommit(struct nfsd4_compoundargs *argp, struct nfsd4_pnfs_lay
 		lcp->lc_atime.nseconds = 0;
 	}
 	READ_BUF(8);
-	READ32(lcp->lc_loup.up_type);
+	READ32(lcp->lc_seg.layout_type);
 	/* XXX: saving XDR'ed layout update. Since we don't have the
 	 * current_fh yet, and therefore no export_ops, we can't call
 	 * the layout specific decode routines. File and pVFS2
 	 * do not use the layout update....
 	 */
-	READ32(lcp->lc_loup.up_len);
-	if (lcp->lc_loup.up_len > 0) {
-		READ_BUF(lcp->lc_loup.up_len);
-		READMEM(lcp->lc_loup.up_layout, lcp->lc_loup.up_len);
+	READ32(lcp->lc_up_len);
+	if (lcp->lc_up_len > 0) {
+		READ_BUF(lcp->lc_up_len);
+		READMEM(lcp->lc_up_layout, lcp->lc_up_len);
 	}
 
 	DECODE_TAIL;
@@ -1294,13 +1294,13 @@ nfsd4_decode_layoutreturn(struct nfsd4_compoundargs *argp, struct nfsd4_pnfs_lay
 
 	READ_BUF(32);
 	READ32(lrp->lr_reclaim);
-	READ32(lrp->lr_layout_type);
-	READ32(lrp->lr_iomode);
+	READ32(lrp->lr_seg.layout_type);
+	READ32(lrp->lr_seg.iomode);
 	READ32(lrp->lr_return_type);
 	if (lrp->lr_return_type == RETURN_FILE)
 	{
-		READ64(lrp->lr_offset);
-		READ64(lrp->lr_length);
+		READ64(lrp->lr_seg.offset);
+		READ64(lrp->lr_seg.length);
 	}
 
 	DECODE_TAIL;
@@ -2966,13 +2966,13 @@ nfsd4_encode_layoutget(struct nfsd4_compoundres *resp, int nfserr, struct nfsd4_
 	if (!nfserr) {
 		RESERVE_SPACE(32);
 		WRITE32(lgp->lg_return_on_close);
-		WRITE64(lgp->lg_offset);
-		WRITE64(lgp->lg_length);
-		WRITE32(lgp->lg_iomode);
-		WRITE32(lgp->lg_type);
+		WRITE64(lgp->lg_seg.offset);
+		WRITE64(lgp->lg_seg.length);
+		WRITE32(lgp->lg_seg.iomode);
+		WRITE32(lgp->lg_seg.layout_type);
 		ADJUST_ARGS();
 		if (lgp->lg_ops->layout_encode == NULL &&
-				lgp->lg_type == LAYOUT_NFSV4_FILES)
+				lgp->lg_seg.layout_type == LAYOUT_NFSV4_FILES)
 		{
 			len = filelayout_encode_layout(p, resp->end, lgp->lg_layout);
 			filelayout_free_layout(lgp->lg_layout);
diff --git a/include/linux/nfsd/nfsd4_pnfs.h b/include/linux/nfsd/nfsd4_pnfs.h
index fb1c676..f8a472e 100644
--- a/include/linux/nfsd/nfsd4_pnfs.h
+++ b/include/linux/nfsd/nfsd4_pnfs.h
@@ -70,13 +70,17 @@ struct nfsd4_pnfs_getdevinfo {
 	void				*gd_devaddr;    /*response */
 };
 
+struct nfsd4_layout_seg {
+	u64                      clientid;
+	u32                      layout_type;
+	u32                      iomode;
+	u64                      offset;
+	u64                      length;
+};
+
 struct nfsd4_pnfs_layoutget {
-	u64				lg_clientid;	/* request */
+	struct nfsd4_layout_seg		lg_seg;		/* request/response */
 	u32				lg_signal;	/* request */
-	u32				lg_type;	/* request - response */
-	u32				lg_iomode;	/* request - response*/
-	u64				lg_offset;	/* request - response */
-	u64				lg_length;	/* request - response */
 	u64				lg_minlength;	/* request */
 	u32				lg_mxcnt;	/* request */
 	u32				lg_flags;	/* request */
@@ -89,34 +93,23 @@ struct nfsd4_pnfs_layoutget {
 	void				*lg_layout;     /* response callback encoded */
 };
 
-struct nfsd4_pnfs_lo_up{
-	u32	up_type;
-	u32	up_len;     /* layout length */
-	void	*up_layout; /* decoded by callback */
-};
-
 struct nfsd4_pnfs_layoutcommit {
-	u64                     lc_clientid;    /* request */
-	u64                     lc_offset;      /* request */
-	u64                     lc_length;      /* request */
+	struct nfsd4_layout_seg lc_seg;       /* request */
 	u32                     lc_reclaim;     /* request */
 	u32                     lc_newoffset;   /* request */
 	u64                     lc_last_wr;     /* request */
 	struct nfstime4         lc_mtime;       /* request */
 	struct nfstime4         lc_atime;       /* request */
-	struct nfsd4_pnfs_lo_up lc_loup;	/* request */
+	u32                     lc_up_len;     /* layout length */
+	void                   *lc_up_layout; /* decoded by callback */
 	u32			lc_size_chg;	/* boolean for response */
 	u64                     lc_newsize;     /* response */
 };
 
 struct nfsd4_pnfs_layoutreturn {
-	u64				lr_clientid;	/* request */
+	u32                             lr_return_type; /* request */
+	struct nfsd4_layout_seg		lr_seg;		/* request */
 	u32				lr_reclaim;	/* request */
-	u32				lr_layout_type;	/* request */
-	u32				lr_iomode;	/* request */
-	u32				lr_return_type;	/* request */
-	u64				lr_offset;	/* request */
-	u64				lr_length;	/* request */
 	u32				lr_flags;
 };
 
-- 
1.5.1



More information about the pNFS mailing list