All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Simmons <jsimmons@infradead.org>
To: lustre-devel@lists.lustre.org
Subject: [lustre-devel] [PATCH 01/37] lustre: obdclass: char obd_ioctl_getdata type.
Date: Sun, 24 Feb 2019 18:35:08 +0000 (GMT)	[thread overview]
Message-ID: <alpine.LFD.2.21.1902241834240.1485@casper.infradead.org> (raw)
In-Reply-To: <155053494481.24125.17153359714439231322.stgit@noble.brown>


> Instead of having obd_ioctl_getdata() return the allocated
> data as a "char *", return it as it really is,
>  struct obd_ioctl_data *
> 
> This avoids the need for extra variables and casts.

Reviewed-by: James Simmons <jsimmons@infradead.org>
 
> Signed-off-by: NeilBrown <neilb@suse.com>
> ---
>  drivers/staging/lustre/lustre/include/obd_class.h  |    3 ++-
>  drivers/staging/lustre/lustre/llite/dir.c          |   18 ++++++------------
>  drivers/staging/lustre/lustre/llite/llite_lib.c    |    8 +++-----
>  drivers/staging/lustre/lustre/lov/lov_obd.c        |   15 ++++++---------
>  drivers/staging/lustre/lustre/obdclass/class_obd.c |   18 ++++++++----------
>  5 files changed, 25 insertions(+), 37 deletions(-)
> 
> diff --git a/drivers/staging/lustre/lustre/include/obd_class.h b/drivers/staging/lustre/lustre/include/obd_class.h
> index 30b3e2c69f83..32d4ab6e78a0 100644
> --- a/drivers/staging/lustre/lustre/include/obd_class.h
> +++ b/drivers/staging/lustre/lustre/include/obd_class.h
> @@ -1697,6 +1697,7 @@ struct root_squash_info {
>  };
>  
>  /* linux-module.c */
> -int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
> +struct obd_ioctl_data;
> +int obd_ioctl_getdata(struct obd_ioctl_data **data, int *len, void __user *arg);
>  
>  #endif /* __LINUX_OBD_CLASS_H */
> diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
> index fd1af4a5cdad..17bb6185ba87 100644
> --- a/drivers/staging/lustre/lustre/llite/dir.c
> +++ b/drivers/staging/lustre/lustre/llite/dir.c
> @@ -1130,13 +1130,11 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>  	}
>  	case IOC_MDC_LOOKUP: {
>  		int namelen, len = 0;
> -		char *buf = NULL;
>  		char *filename;
>  
> -		rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
> +		rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
>  		if (rc)
>  			return rc;
> -		data = (void *)buf;
>  
>  		filename = data->ioc_inlbuf1;
>  		namelen = strlen(filename);
> @@ -1155,12 +1153,11 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>  			goto out_free;
>  		}
>  out_free:
> -		kvfree(buf);
> +		kvfree(data);
>  		return rc;
>  	}
>  	case LL_IOC_LMV_SETSTRIPE: {
>  		struct lmv_user_md  *lum;
> -		char *buf = NULL;
>  		char *filename;
>  		int namelen = 0;
>  		int lumlen = 0;
> @@ -1168,11 +1165,10 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>  		int len;
>  		int rc;
>  
> -		rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
> +		rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
>  		if (rc)
>  			return rc;
>  
> -		data = (void *)buf;
>  		if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
>  		    data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0) {
>  			rc = -EINVAL;
> @@ -1205,7 +1201,7 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>  #endif
>  		rc = ll_dir_setdirstripe(dentry, lum, filename, mode);
>  lmv_out_free:
> -		kvfree(buf);
> +		kvfree(data);
>  		return rc;
>  	}
>  	case LL_IOC_LMV_SET_DEFAULT_STRIPE: {
> @@ -1651,18 +1647,16 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>  		return rc;
>  	}
>  	case LL_IOC_MIGRATE: {
> -		char *buf = NULL;
>  		const char *filename;
>  		int namelen = 0;
>  		int len;
>  		int rc;
>  		int mdtidx;
>  
> -		rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
> +		rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
>  		if (rc < 0)
>  			return rc;
>  
> -		data = (struct obd_ioctl_data *)buf;
>  		if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
>  		    !data->ioc_inllen1 || !data->ioc_inllen2) {
>  			rc = -EINVAL;
> @@ -1684,7 +1678,7 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
>  
>  		rc = ll_migrate(inode, file, mdtidx, filename, namelen - 1);
>  migrate_free:
> -		kvfree(buf);
> +		kvfree(data);
>  
>  		return rc;
>  	}
> diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c
> index 8e09fdd7a96e..e2417cd5aaed 100644
> --- a/drivers/staging/lustre/lustre/llite/llite_lib.c
> +++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
> @@ -2295,7 +2295,6 @@ int ll_obd_statfs(struct inode *inode, void __user *arg)
>  {
>  	struct ll_sb_info *sbi = NULL;
>  	struct obd_export *exp;
> -	char *buf = NULL;
>  	struct obd_ioctl_data *data = NULL;
>  	u32 type;
>  	int len = 0, rc;
> @@ -2311,11 +2310,10 @@ int ll_obd_statfs(struct inode *inode, void __user *arg)
>  		goto out_statfs;
>  	}
>  
> -	rc = obd_ioctl_getdata(&buf, &len, arg);
> +	rc = obd_ioctl_getdata(&data, &len, arg);
>  	if (rc)
>  		goto out_statfs;
>  
> -	data = (void *)buf;
>  	if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
>  	    !data->ioc_pbuf1 || !data->ioc_pbuf2) {
>  		rc = -EINVAL;
> @@ -2340,11 +2338,11 @@ int ll_obd_statfs(struct inode *inode, void __user *arg)
>  		goto out_statfs;
>  	}
>  
> -	rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL);
> +	rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
>  	if (rc)
>  		goto out_statfs;
>  out_statfs:
> -	kvfree(buf);
> +	kvfree(data);
>  	return rc;
>  }
>  
> diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c
> index 04d0a9ed1d05..fd769c39b482 100644
> --- a/drivers/staging/lustre/lustre/lov/lov_obd.c
> +++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
> @@ -1039,27 +1039,24 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
>  	case OBD_IOC_LOV_GET_CONFIG: {
>  		struct obd_ioctl_data *data;
>  		struct lov_desc *desc;
> -		char *buf = NULL;
>  		u32 *genp;
>  
>  		len = 0;
> -		if (obd_ioctl_getdata(&buf, &len, uarg))
> +		if (obd_ioctl_getdata(&data, &len, uarg))
>  			return -EINVAL;
>  
> -		data = (struct obd_ioctl_data *)buf;
> -
>  		if (sizeof(*desc) > data->ioc_inllen1) {
> -			kvfree(buf);
> +			kvfree(data);
>  			return -EINVAL;
>  		}
>  
>  		if (sizeof(uuidp->uuid) * count > data->ioc_inllen2) {
> -			kvfree(buf);
> +			kvfree(data);
>  			return -EINVAL;
>  		}
>  
>  		if (sizeof(u32) * count > data->ioc_inllen3) {
> -			kvfree(buf);
> +			kvfree(data);
>  			return -EINVAL;
>  		}
>  
> @@ -1076,9 +1073,9 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
>  			*genp = lov->lov_tgts[i]->ltd_gen;
>  		}
>  
> -		if (copy_to_user(uarg, buf, len))
> +		if (copy_to_user(uarg, data, len))
>  			rc = -EFAULT;
> -		kvfree(buf);
> +		kvfree(data);
>  		break;
>  	}
>  	case OBD_IOC_QUOTACTL: {
> diff --git a/drivers/staging/lustre/lustre/obdclass/class_obd.c b/drivers/staging/lustre/lustre/obdclass/class_obd.c
> index 2ee6b96f4830..b8fc74044fe3 100644
> --- a/drivers/staging/lustre/lustre/obdclass/class_obd.c
> +++ b/drivers/staging/lustre/lustre/obdclass/class_obd.c
> @@ -229,7 +229,7 @@ static int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
>  }
>  
>  /* buffer MUST be at least the size of obd_ioctl_hdr */
> -int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
> +int obd_ioctl_getdata(struct obd_ioctl_data **datap, int *len, void __user *arg)
>  {
>  	struct obd_ioctl_data *data;
>  	struct obd_ioctl_hdr hdr;
> @@ -261,16 +261,16 @@ int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
>  	 * obdfilter-survey is an example, which relies on ioctl. So we'd
>  	 * better avoid vmalloc on ioctl path. LU-66
>  	 */
> -	*buf = kvzalloc(hdr.ioc_len, GFP_KERNEL);
> -	if (!*buf) {
> +	data = kvzalloc(hdr.ioc_len, GFP_KERNEL);
> +	if (!data) {
>  		CERROR("Cannot allocate control buffer of len %d\n",
>  		       hdr.ioc_len);
>  		return -EINVAL;
>  	}
>  	*len = hdr.ioc_len;
> -	data = (struct obd_ioctl_data *)*buf;
> +	*datap = data;
>  
> -	if (copy_from_user(*buf, arg, hdr.ioc_len)) {
> +	if (copy_from_user(data, arg, hdr.ioc_len)) {
>  		err = -EFAULT;
>  		goto free_buf;
>  	}
> @@ -307,14 +307,13 @@ int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
>  	return 0;
>  
>  free_buf:
> -	kvfree(*buf);
> +	kvfree(data);
>  	return err;
>  }
>  EXPORT_SYMBOL(obd_ioctl_getdata);
>  
>  int class_handle_ioctl(unsigned int cmd, unsigned long arg)
>  {
> -	char *buf = NULL;
>  	struct obd_ioctl_data *data;
>  	struct libcfs_debug_ioctl_data *debug_data;
>  	struct obd_device *obd = NULL;
> @@ -329,11 +328,10 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
>  	}
>  
>  	CDEBUG(D_IOCTL, "cmd = %x\n", cmd);
> -	if (obd_ioctl_getdata(&buf, &len, (void __user *)arg)) {
> +	if (obd_ioctl_getdata(&data, &len, (void __user *)arg)) {
>  		CERROR("OBD ioctl: data error\n");
>  		return -EINVAL;
>  	}
> -	data = (struct obd_ioctl_data *)buf;
>  
>  	switch (cmd) {
>  	case OBD_IOC_PROCESS_CFG: {
> @@ -542,7 +540,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
>  	}
>  
>   out:
> -	kvfree(buf);
> +	kvfree(data);
>  	return err;
>  } /* class_handle_ioctl */
>  
> 
> 
> 

  reply	other threads:[~2019-02-24 18:35 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-19  0:09 [lustre-devel] [PATCH 00/37] More lustre patches from obdclass NeilBrown
2019-02-19  0:09 ` [lustre-devel] [PATCH 01/37] lustre: obdclass: char obd_ioctl_getdata type NeilBrown
2019-02-24 18:35   ` James Simmons [this message]
2019-02-19  0:09 ` [lustre-devel] [PATCH 02/37] lustre: llite: don't use class_setup_tunables() NeilBrown
2019-02-24 16:35   ` James Simmons
2019-02-25 22:27     ` NeilBrown
2019-02-26 22:18       ` James Simmons
2019-02-24 16:52   ` [lustre-devel] [PATCH 03/37] lustre: embed typ_kobj if obd_type James Simmons
2019-02-25 22:38     ` NeilBrown
2019-02-26 20:41       ` Simmons, James A.
2019-02-19  0:09 ` [lustre-devel] [PATCH 14/37] lustre: llog: change lgh_refcount to struct kref NeilBrown
2019-02-25 18:16   ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 13/37] lustre: llog: remove lgh_hdr_lock NeilBrown
2019-02-24 20:29   ` James Simmons
2019-02-25 18:16   ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 07/37] lustre: obd_type: discard obd_type_lock NeilBrown
2019-02-24 17:02   ` James Simmons
2019-02-19  0:09 ` [lustre-devel] [PATCH 08/37] lustre: obdclass: don't copy ops structures in to new type NeilBrown
2019-02-24 17:03   ` James Simmons
2019-02-19  0:09 ` [lustre-devel] [PATCH 16/37] lustre: obdclass: typo: Banlance -> Balance NeilBrown
2019-02-24 17:39   ` James Simmons
2019-02-19  0:09 ` [lustre-devel] [PATCH 05/37] lustre: obd_type: use typ_kobj.name as typ_name NeilBrown
2019-02-24 16:56   ` James Simmons
2019-02-19  0:09 ` [lustre-devel] [PATCH 03/37] lustre: embed typ_kobj if obd_type NeilBrown
2019-02-19  0:09 ` [lustre-devel] [PATCH 09/37] lustre: obdclass: fix module load locking NeilBrown
2019-02-24 17:04   ` James Simmons
2019-02-19  0:09 ` [lustre-devel] [PATCH 17/37] lustre: simplify lprocfs_read_frac_helper NeilBrown
2019-02-24 17:52   ` James Simmons
2019-02-26 23:59     ` NeilBrown
2019-02-27  1:06       ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 18/37] lustre: obdclass: discard lprocfs_single/seq_release NeilBrown
2019-02-24 17:53   ` James Simmons
2019-02-19  0:09 ` [lustre-devel] [PATCH 12/37] lustre: remove unused function in linkea NeilBrown
2019-02-25 18:16   ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 10/37] lustre: kernelcomm: pass correct gfp_t to kmalloc NeilBrown
2019-02-24 17:05   ` James Simmons
2019-02-25 18:16     ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 21/37] lustre: remove several MAX_STRING_SIZE defines NeilBrown
2019-02-24 19:07   ` James Simmons
2019-02-27  0:41     ` NeilBrown
2019-02-25 18:16   ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 19/37] lustre: discard lprocfs_strnstr() NeilBrown
2019-02-24 17:53   ` James Simmons
2019-02-19  0:09 ` [lustre-devel] [PATCH 15/37] lustre: llog_obd: Convert loc_refcount to refcount_t NeilBrown
2019-02-25 18:16   ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 11/37] lustre: kernelcomm: make libcfs_kkuc_msg_put static NeilBrown
2019-02-24 17:15   ` James Simmons
2019-02-26 23:45     ` NeilBrown
2019-02-27 22:36       ` James Simmons
2019-02-27 22:37   ` James Simmons
2019-02-19  0:09 ` [lustre-devel] [PATCH 04/37] lustre: collect all resource releasing for obj_type NeilBrown
2019-02-24 16:54   ` James Simmons
2019-02-19  0:09 ` [lustre-devel] [PATCH 06/37] lustre: obd_type: discard obd_types linked list NeilBrown
2019-02-24 17:00   ` James Simmons
2019-02-19  0:09 ` [lustre-devel] [PATCH 20/37] lustre: convert rsi_sem to a spinlock NeilBrown
2019-02-25 18:16   ` Andreas Dilger
2019-02-27  0:22     ` NeilBrown
2019-02-27  1:00       ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 32/37] lustre: portals_handle: rename ops to owner NeilBrown
2019-02-19  0:09 ` [lustre-devel] [PATCH 22/37] lustre: lprocfs: use log2.h macros instead of shift loop NeilBrown
2019-02-24 18:09   ` James Simmons
2019-02-26 20:55   ` James Simmons
2019-02-27  0:51     ` NeilBrown
2019-02-27  0:54       ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 25/37] lustre: deprecate libcfs_debug_vmsg2 NeilBrown
2019-02-24 20:02   ` James Simmons
2019-02-25 18:16   ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 30/37] lustre: handle: move refcount into the lustre_handle NeilBrown
2019-02-27  6:32   ` Andreas Dilger
2019-02-27 21:48     ` NeilBrown
2019-02-27 22:14       ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 28/37] lustre: remove scope and source from class_incref and class_decref NeilBrown
2019-02-27  6:52   ` Andreas Dilger
2019-02-28  0:39     ` NeilBrown
2019-02-19  0:09 ` [lustre-devel] [PATCH 26/37] lustre: remove libcfs_debug_vmsg2 NeilBrown
2019-02-25 18:16   ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 23/37] lustre: prefer to use tabs for alignment NeilBrown
2019-02-24 18:51   ` James Simmons
2019-02-25 18:16   ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 27/37] lustre: discard lu_ref NeilBrown
2019-02-24 20:28   ` James Simmons
2019-02-27  1:17     ` NeilBrown
2019-02-27  5:35       ` Andreas Dilger
2019-03-01  6:45         ` Mike Pershin
2019-02-19  0:09 ` [lustre-devel] [PATCH 29/37] lustre: handles: discard h_owner in favour of h_ops NeilBrown
2019-02-27  6:37   ` Andreas Dilger
2019-02-27 21:41     ` NeilBrown
2019-02-28  6:41       ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 33/37] lustre: portals_handle: remove locking from class_handle2object() NeilBrown
2019-02-19  0:09 ` [lustre-devel] [PATCH 34/37] lustre: portals_handle: use hlist for hash lists NeilBrown
2019-02-19  0:09 ` [lustre-devel] [PATCH 31/37] lustre: discard OBD_FREE_RCU NeilBrown
2019-02-19  0:09 ` [lustre-devel] [PATCH 24/37] lustre: lu_object: remove extra newline from debug printing NeilBrown
2019-02-24 19:08   ` James Simmons
2019-02-25 18:16   ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 35/37] lustre: portals_handle: discard h_lock NeilBrown
2019-02-19  0:09 ` [lustre-devel] [PATCH 37/37] lustre: obd_sysfs: error-check value stored in jobid_var NeilBrown
2019-02-27  6:17   ` Andreas Dilger
2019-03-01  2:35     ` NeilBrown
2019-03-01  8:32       ` Andreas Dilger
2019-03-01 14:30         ` Patrick Farrell
2019-03-14  0:34           ` NeilBrown
2019-03-14 14:12             ` Patrick Farrell
2019-03-14 22:56               ` NeilBrown
2019-03-14 23:05               ` Andreas Dilger
2019-02-19  0:09 ` [lustre-devel] [PATCH 36/37] lustre: remove unused fields from struct obd_device NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.21.1902241834240.1485@casper.infradead.org \
    --to=jsimmons@infradead.org \
    --cc=lustre-devel@lists.lustre.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.