[pnfs] [PATCH 1/3] pnfs-gfs2: initial LAYOUT* work for pNFS/GFS2 integration

Benny Halevy bhalevy at panasas.com
Thu Jun 5 13:18:32 EDT 2008


On Jun. 05, 2008, 18:47 +0300, "David M. Richter" <richterd at citi.umich.edu> wrote:
> Frank Filz's work on the layout_type() and layout_get() export operations,
> with stubs for layout_commit() and layout_return().  Tested at Connectathon.
> 
> Signed-off-by: Frank Filz <ffilzlnx at us.ibm.com>
> Signed-off-by: David M. Richter <richterd at citi.umich.edu>
> ---
>  fs/gfs2/ops_export.c |  103 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 103 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c
> index 334c7f8..3be6986 100644
> --- a/fs/gfs2/ops_export.c
> +++ b/fs/gfs2/ops_export.c
> @@ -27,6 +27,16 @@
>  #include "rgrp.h"
>  #include "util.h"
>  
> +#if defined(CONFIG_PNFSD)
> +#include <linux/nfs_fs.h>
> +#include <linux/sunrpc/svc.h>
> +#include <linux/nfsd/state.h>
> +#include <linux/nfsd/nfsfh.h>
> +#include <linux/nfsd/pnfsd.h>
> +#include <linux/nfsd/nfs4layoutxdr.h>
> +#include <linux/nfs4_pnfs.h>
> +#endif /* CONFIG_PNFSD */
> +
>  #define GFS2_SMALL_FH_SIZE 4
>  #define GFS2_LARGE_FH_SIZE 8
>  #define GFS2_OLD_FH_SIZE 10
> @@ -294,11 +304,104 @@ static struct dentry *gfs2_fh_to_parent(struct super_block *sb, struct fid *fid,
>  	}
>  }
>  
> +#if defined(CONFIG_PNFSD)
> +static int gfs2_layout_type(void)
> +{
> +	return LAYOUT_NFSV4_FILES;
> +}
> +
> +static int get_stripe_unit(int blocksize)
> +{
> +	if (blocksize >= NFSSVC_MAXBLKSIZE)
> +		return blocksize;
> +
> +	return NFSSVC_MAXBLKSIZE - (NFSSVC_MAXBLKSIZE % blocksize);
> +}
> +
> +/*
> + * Retrieve and encode a file layout onto the xdr stream.
> + * @inode: inode for which to retrieve layout
> + * @arg->xdr: xdr stream for encoding
> + * @arg->func: a call into file system to encode the layout on xdr stream.
> + */
> +static int gfs2_layout_get(struct inode *inode, struct pnfs_layoutget_arg *arg)
> +{
> +	int rc = 0;
> +	struct pnfs_filelayout_layout *layout = NULL;
> +	struct knfsd_fh *fhp = NULL;
> +
> +	printk(KERN_DEBUG "%s: LAYOUT_GET\n", __func__);
> +
> +	/* Set layout indept response args */
> +	arg->seg.layout_type = LAYOUT_NFSV4_FILES;
> +	arg->seg.offset = 0;
> +	arg->seg.length = inode->i_sb->s_maxbytes; /* The maximum file size */
> +
> +	layout = kzalloc(sizeof(*layout), GFP_KERNEL);
> +	if (layout == NULL) {
> +		rc = -ENOMEM;
> +		goto error;
> +	}
> +
> +	/* Set file layout response args */
> +	layout->lg_layout_type = LAYOUT_NFSV4_FILES;
> +	layout->lg_stripe_type = STRIPE_SPARSE;
> +	layout->lg_commit_through_mds = true;
> +	layout->lg_stripe_unit = get_stripe_unit(inode->i_sb->s_blocksize);
> +	layout->lg_fh_length = 1;
> +	layout->device_id.pnfs_fsid = arg->fsid;
> +	layout->device_id.pnfs_devid = 1;			/*FSFTEMP*/
> +	layout->lg_first_stripe_index = 0;			/*FSFTEMP*/
> +	layout->lg_pattern_offset = 0;
> +
> +	fhp = kmalloc(sizeof(*fhp), GFP_KERNEL);

I'd allocate it in one piece with the layout above.
Also, since the allocation size is constant, it's a good candidate for
a kmem_cache...

Benny

> +	if (fhp == NULL) {
> +		rc = -ENOMEM;
> +		goto error;
> +	}
> +
> +	memcpy(fhp, arg->fh, sizeof(*fhp));
> +	pnfs_fh_mark_ds(fhp);
> +	layout->lg_fh_list = fhp;
> +
> +	/* Call nfsd to encode layout */
> +	rc = arg->func(&arg->xdr, layout);
> +exit:
> +	kfree(layout);
> +	kfree(fhp);
> +	return rc;
> +
> +error:
> +	arg->seg.length = 0;
> +	goto exit;
> +}
> +
> +static int gfs2_layout_commit(struct inode *inode, void *p)
> +{
> +	printk(KERN_DEBUG "%s: LAYOUT_COMMIT (unimplemented)\n", __func__);
> +
> +	return 0;
> +}
> +
> +static int gfs2_layout_return(struct inode *inode, void *p)
> +{
> +	printk(KERN_DEBUG "%s: LAYOUT_RETURN (unimplemented)\n", __func__);
> +
> +	return 0;
> +}
> +#endif /* CONFIG_PNFSD */
> +
>  const struct export_operations gfs2_export_ops = {
>  	.encode_fh = gfs2_encode_fh,
>  	.fh_to_dentry = gfs2_fh_to_dentry,
>  	.fh_to_parent = gfs2_fh_to_parent,
>  	.get_name = gfs2_get_name,
>  	.get_parent = gfs2_get_parent,
> +#if defined(CONFIG_PNFSD)
> +	.layout_type = gfs2_layout_type,
> +	.layout_get = gfs2_layout_get,
> +	.layout_commit = gfs2_layout_commit,
> +	.layout_return = gfs2_layout_return,
> +#endif /* CONFIG_PNFSD */
>  };
>  



More information about the pNFS mailing list