[pnfs] [PATCH] Streamline error code checking for non-pnfs filesystems

Ricardo Labiaga ricardo.labiaga at netapp.com
Thu Oct 18 23:04:35 EDT 2007


It's been pushed to 2.6-latest.

On Tue, 2007-10-16 at 20:15 -0700, seattleplus at gmail.com wrote:
> From: Dean Hildebrand <seattleplus at gmail.com>
> 
> diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
> index 2874ac4..2919adb 100644
> --- a/fs/nfsd/nfs4proc.c
> +++ b/fs/nfsd/nfs4proc.c
> @@ -903,6 +903,33 @@ nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
>  }
>  
>  #if defined(CONFIG_PNFS)
> +
> +static __be32
> +nfsd4_layout_verify(struct super_block *sb, unsigned int layout_type)
> +{
> +	int status;
> +	int type = sb->s_export_op->layout_type();
> +
> +	/* check to see if pNFS  is supported. */
> +	status = nfserr_layoutunavailable;
> +	if (!sb->s_export_op->layout_type) {
> +		printk("pNFS %s: Underlying file system does not support pNFS\n", __FUNCTION__);
> +		goto out;
> +	}
> +
> +	/* check to see if requested layout type is supported. */
> +	status = nfserr_unknown_layouttype;
> +	if (type != layout_type) {
> +		printk("pNFS %s: requested layout type %d does not match suppored type %d\n",
> +		        __FUNCTION__, layout_type, type);
> +		goto out;
> +	}
> +
> +	status = nfs_ok;
> +out:
> +	return status;
> +}
> +
>  static __be32
>  nfsd4_getdevlist( struct svc_rqst *rqstp,
>  		struct nfsd4_compound_state *cstate,
> @@ -910,7 +937,7 @@ nfsd4_getdevlist( struct svc_rqst *rqstp,
>  {
>  	struct super_block *sb;
>  	struct svc_fh *current_fh = &cstate->current_fh;
> -	int type = 0, status = 0;
> +	int status;
>  
>  	status = fh_verify(rqstp, current_fh, 0, MAY_NOP);
>  	if (status) {
> @@ -923,27 +950,29 @@ nfsd4_getdevlist( struct svc_rqst *rqstp,
>  	if (!sb)
>  		goto out;
>  
> -	/* 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()) != gdlp->gd_type)) {
> +	/* Ensure underlying file system supports pNFS and,
> +	 * if so, the requested layout type
> +	 */
> +	status = nfsd4_layout_verify(sb, gdlp->gd_type);
> +	if (status)
> +		goto out;
>  
> -		printk("pNFS %s: requested layout type %d does not match suppored type %d\n", __FUNCTION__, gdlp->gd_type, type);
> +	/* Do nothing if underlying file system does not support getdevicelist */
> +	status = nfs_ok;
> +	if (!sb->s_export_op->get_devicelist)
>  		goto out;
> -	}
>  
>  	/* set the layouttype for encoding the devaddr */
>  	gdlp->gd_ops = sb->s_export_op;
>  
>  	/* device list is allocated by underlying file system, and free'd
>  	 * via export_ops callback. */
> -	if (sb->s_export_op->get_devicelist) {
> -		status = sb->s_export_op->get_devicelist(sb, (void *)gdlp);
> +	status = sb->s_export_op->get_devicelist(sb, (void *)gdlp);
> +
> +	dprintk("%s: status %d type %d maxcount %d len %d\n",
> +		__FUNCTION__, status, gdlp->gd_type, gdlp->gd_maxcount,
> +		gdlp->gd_devlist_len);
>  
> -		dprintk("%s: status %d type %d maxcount %d len %d\n",
> -			__FUNCTION__, status, gdlp->gd_type, gdlp->gd_maxcount,
> -			gdlp->gd_devlist_len);
> -	}
>  	if (gdlp->gd_devlist_len < 0)
>  		status = nfserr_inval;
>  out:
> @@ -958,7 +987,7 @@ nfsd4_layoutget( struct svc_rqst *rqstp,
>  		struct nfsd4_compound_state *cstate,
>  		struct nfsd4_pnfs_layoutget *lgp)
>  {
> -	int type = 0, status = 0;
> +	int status;
>  	struct super_block *sb;
>  	struct current_session *current_ses = cstate->current_ses;
>  	struct svc_fh *current_fh = &cstate->current_fh;
> @@ -974,19 +1003,17 @@ nfsd4_layoutget( struct svc_rqst *rqstp,
>  	if (!sb)
>  		goto out;
>  
> -	/* 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_seg.layout_type)) {
> -
> -		dprintk("pNFS %s: requested layout type %d does not match suppored type %d\n",
> -		        __FUNCTION__, lgp->lg_seg.layout_type, type);
> +	/* Ensure underlying file system supports pNFS and,
> +	 * if so, the requested layout type
> +	 */
> +	status = nfsd4_layout_verify(sb, lgp->lg_seg.layout_type);
> +	if (status)
>  		goto out;
> -	}
>  
> +	/* check to see if pNFS  is supported. */
>  	status = nfserr_layoutunavailable;
>  	if (!sb->s_export_op->layout_get) {
> -		dprintk("pNFS %s: layout_get not implemented for layout type %d\n", __FUNCTION__, type);
> +		printk("pNFS %s: Underlying file system does not support layout_get\n", __FUNCTION__);
>  		goto out;
>  	}
>  
> @@ -1034,7 +1061,22 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,
>  		goto out;
>  	}
>  
> +	status = nfserr_inval;
>  	ino = current_fh->fh_dentry->d_inode;
> +	if (!ino)
> +		goto out;
> +
> +	status = nfserr_inval;
> +	sb = ino->i_sb;
> +	if (!sb)
> +		goto out;
> +
> +	/* Ensure underlying file system supports pNFS and,
> +	 * if so, the requested layout type
> +	 */
> +	status = nfsd4_layout_verify(sb, lcp->lc_seg.layout_type);
> +	if (status)
> +		goto out;
>  
>          /* This will only extend the file length.  Do a quick
>  	 * check to see if there is any point in waiting for the update
> @@ -1059,7 +1101,6 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,
>  	dprintk("%s: Modifying file size\n", __FUNCTION__);
>  	ia.ia_valid = ATTR_SIZE;
>  	ia.ia_size = lcp->lc_last_wr + 1;
> -	sb = current_fh->fh_dentry->d_inode->i_sb;
>  	if (sb->s_export_op->layout_commit) {
>  		status = sb->s_export_op->layout_commit(ino, lcp);
>  		dprintk("%s:layout_commit result %d\n", __FUNCTION__, status);
> @@ -1094,7 +1135,7 @@ nfsd4_layoutreturn(struct svc_rqst *rqstp,
>  		struct nfsd4_compound_state *cstate,
>  		struct nfsd4_pnfs_layoutreturn *lrp)
>  {
> -	int type = 0, status = 0;
> +	int status;
>  	struct super_block *sb;
>  	struct current_session *current_ses = cstate->current_ses;
>  	struct svc_fh *current_fh = &cstate->current_fh;
> @@ -1110,14 +1151,13 @@ nfsd4_layoutreturn(struct svc_rqst *rqstp,
>  	if (!sb)
>  		goto out;
>  
> -	/* 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_seg.layout_type)) {
> -
> -		printk("pNFS %s: requested layout type %d does not match suppored type %d\n", __FUNCTION__, lrp->lr_seg.layout_type, type);
> +	/* Ensure underlying file system supports pNFS and,
> +	 * if so, the requested layout type
> +	 */
> +	status = nfsd4_layout_verify(sb, lrp->lr_seg.layout_type);
> +	if (status)
>  		goto out;
> -	}
> +
>  	status = nfserr_inval;
>  	if (lrp->lr_return_type != RETURN_FILE &&
>  	    lrp->lr_return_type != RETURN_FSID &&
> @@ -1152,7 +1192,7 @@ nfsd4_getdevinfo(struct svc_rqst *rqstp,
>  {
>  	struct super_block *sb;
>  	struct svc_fh *current_fh = &cstate->current_fh;
> -	int type = 0, status;
> +	int status;
>  
>  	printk("%s: type %d dev_id %d\n",
>  		__FUNCTION__, gdp->gd_type, gdp->gd_dev_id);
> @@ -1168,26 +1208,25 @@ nfsd4_getdevinfo(struct svc_rqst *rqstp,
>  	if (!sb)
>  		goto out;
>  
> -	/* 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()) != gdp->gd_type)) {
> +	/* Ensure underlying file system supports pNFS and,
> +	 * if so, the requested layout type
> +	 */
> +	status = nfsd4_layout_verify(sb, gdp->gd_type);
> +	if (status)
> +		goto out;
>  
> -		printk("pNFS %s: requested layout type %d does not match suppored type %d\n", __FUNCTION__, gdp->gd_type, type);
> +	/* Do nothing if underlying file system does not support getdeviceinfo */
> +	status = nfs_ok;
> +	if (!sb->s_export_op->get_deviceinfo)
>  		goto out;
> -}
>  
>          /* set the ops for encoding the devaddr */
>          gdp->gd_ops = sb->s_export_op;
>  
> -	if (sb && sb->s_export_op->get_deviceinfo) {
> -		status = sb->s_export_op->get_deviceinfo(sb, (void *)gdp);
> +	status = sb->s_export_op->get_deviceinfo(sb, (void *)gdp);
>  
> -		dprintk("%s: status %d type %d dev_id %d\n",
> -			__FUNCTION__, status, gdp->gd_type, gdp->gd_dev_id);
> -		goto out;
> -	}
> -	printk("%s:  failed, no support\n",__FUNCTION__);
> +	dprintk("%s: status %d type %d dev_id %d\n",
> +		__FUNCTION__, status, gdp->gd_type, gdp->gd_dev_id);
>  out:
>  	return status;
>  }


More information about the pNFS mailing list