Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
filesystems
lustre_2_12
0057-LU-16634-misc-remove-unnecessary-ioctl-typ...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0057-LU-16634-misc-remove-unnecessary-ioctl-typecasts.patch of Package lustre_2_12
From 4a1465577e1310ce09834103f7136bef0e1a1eeb Mon Sep 17 00:00:00 2001 From: Andreas Dilger <adilger@whamcloud.com> Date: Sun, 19 Mar 2023 13:58:04 -0600 Subject: [PATCH] LU-16634 misc: remove unnecessary ioctl typecasts Declare "void __user *uarg" in the ioctl handling code so that it isn't typecast on every access in the ioctl handler. Unnecessary typecast risks hiding compiler warnings and bugs. Convert indentation to tabs for lines previously using spaces. Change local variable declarations to use only a single space. Test-Parameters: trivial Change-Id: I1a0d2f839949debf346aa15c65b0f407e1ce7057 Signed-off-by: Andreas Dilger <adilger@whamcloud.com> Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50333 Tested-by: jenkins <devops@whamcloud.com> Tested-by: Maloo <maloo@whamcloud.com> Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com> Reviewed-by: Vitaliy Kuznetsov <vkuznetsov@ddn.com> Reviewed-by: jsimmons <jsimmons@infradead.org> Reviewed-by: Oleg Drokin <green@whamcloud.com> --- lustre/include/obd_class.h | 2 lustre/llite/dir.c | 183 +++++++++++++++++------------------- lustre/llite/file.c | 210 +++++++++++++++++++----------------------- lustre/llite/llite_internal.h | 9 - lustre/llite/llite_lib.c | 35 +++---- lustre/obdclass/class_obd.c | 65 ++++++------- 6 files changed, 238 insertions(+), 266 deletions(-) --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -53,7 +53,7 @@ extern rwlock_t obd_dev_lock; /* OBD Operations Declarations */ extern struct obd_device *class_exp2obd(struct obd_export *); -extern int class_handle_ioctl(unsigned int cmd, unsigned long arg); +extern int class_handle_ioctl(unsigned int cmd, void __user *uarg); int lustre_get_jobid(char *jobid, size_t len); void lustre_jobid_clear(const char *jobid); void jobid_cache_fini(void); --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -1362,6 +1362,7 @@ static long ll_dir_ioctl(struct file *fi struct inode *inode = file_inode(file); struct ll_sb_info *sbi = ll_i2sbi(inode); struct obd_ioctl_data *data; + void __user *uarg = (void __user *)arg; int rc = 0; ENTRY; @@ -1376,7 +1377,7 @@ static long ll_dir_ioctl(struct file *fi switch (cmd) { case FS_IOC_GETFLAGS: case FS_IOC_SETFLAGS: - RETURN(ll_iocontrol(inode, file, cmd, arg)); + RETURN(ll_iocontrol(inode, file, cmd, uarg)); case FSFILT_IOC_GETVERSION: case FS_IOC_GETVERSION: RETURN(put_user(inode->i_generation, (int __user *)arg)); @@ -1403,7 +1404,7 @@ static long ll_dir_ioctl(struct file *fi char *buf = NULL; char *filename; - rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg); + rc = obd_ioctl_getdata(&buf, &len, uarg); if (rc != 0) RETURN(rc); data = (void *)buf; @@ -1436,7 +1437,7 @@ out_free: int len; int rc; - rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg); + rc = obd_ioctl_getdata(&buf, &len, uarg); if (rc) RETURN(rc); @@ -1475,10 +1476,9 @@ lmv_out_free: } case LL_IOC_LMV_SET_DEFAULT_STRIPE: { - struct lmv_user_md lum; - struct lmv_user_md __user *ulump = - (struct lmv_user_md __user *)arg; - int rc; + struct lmv_user_md lum; + struct lmv_user_md __user *ulump = uarg; + int rc; if (copy_from_user(&lum, ulump, sizeof(lum))) RETURN(-EFAULT); @@ -1495,12 +1495,9 @@ lmv_out_free: struct lov_user_md_v3 *lumv3 = NULL; struct lov_user_md_v1 lumv1; struct lov_user_md_v1 *lumv1_ptr = &lumv1; - struct lov_user_md_v1 __user *lumv1p = - (struct lov_user_md_v1 __user *)arg; - struct lov_user_md_v3 __user *lumv3p = - (struct lov_user_md_v3 __user *)arg; + struct lov_user_md_v1 __user *lumv1p = uarg; + struct lov_user_md_v3 __user *lumv3p = uarg; int lum_size = 0; - int set_default = 0; CLASSERT(sizeof(struct lov_user_md_v3) > @@ -1540,21 +1537,20 @@ out: RETURN(rc); } case LL_IOC_LMV_GETSTRIPE: { - struct lmv_user_md __user *ulmv = - (struct lmv_user_md __user *)arg; - struct lmv_user_md lum; - struct ptlrpc_request *request = NULL; - struct ptlrpc_request *root_request = NULL; - union lmv_mds_md *lmm = NULL; - int lmmsize; - u64 valid = 0; - struct lmv_user_md *tmp = NULL; - int mdt_index; - int lum_size; - int stripe_count; - int max_stripe_count; - int i; - int rc; + struct lmv_user_md __user *ulmv = uarg; + struct lmv_user_md lum; + struct ptlrpc_request *request = NULL; + struct ptlrpc_request *root_request = NULL; + union lmv_mds_md *lmm = NULL; + int lmmsize; + u64 valid = 0; + struct lmv_user_md *tmp = NULL; + int mdt_index; + int lum_size; + int stripe_count; + int max_stripe_count; + int i; + int rc; if (copy_from_user(&lum, ulmv, sizeof(*ulmv))) RETURN(-EFAULT); @@ -1647,7 +1643,7 @@ finish_req: if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE)) RETURN(-ENOTSUPP); - filename = ll_getname((const char __user *)arg); + filename = ll_getname(uarg); if (IS_ERR(filename)) RETURN(PTR_ERR(filename)); @@ -1657,16 +1653,16 @@ finish_req: rc = ll_rmdir_entry(inode, filename, namelen); out_rmdir: - if (filename) - ll_putname(filename); + if (filename) + ll_putname(filename); RETURN(rc); } case LL_IOC_RMFID: - RETURN(ll_rmfid(file, (void __user *)arg)); + RETURN(ll_rmfid(file, uarg)); case LL_IOC_LOV_SWAP_LAYOUTS: RETURN(-EPERM); case IOC_OBD_STATFS: - RETURN(ll_obd_statfs(inode, (void __user *)arg)); + RETURN(ll_obd_statfs(inode, uarg)); case LL_IOC_LOV_GETSTRIPE: case LL_IOC_LOV_GETSTRIPE_NEW: case LL_IOC_MDC_GETINFO: @@ -1690,7 +1686,7 @@ out_rmdir: if (cmd == IOC_MDC_GETFILEINFO_OLD || cmd == IOC_MDC_GETFILEINFO || cmd == IOC_MDC_GETFILESTRIPE) { - filename = ll_getname((const char __user *)arg); + filename = ll_getname(uarg); if (IS_ERR(filename)) RETURN(PTR_ERR(filename)); @@ -1724,18 +1720,18 @@ out_rmdir: if (cmd == IOC_MDC_GETFILESTRIPE || cmd == LL_IOC_LOV_GETSTRIPE || cmd == LL_IOC_LOV_GETSTRIPE_NEW) { - lump = (struct lov_user_md __user *)arg; + lump = uarg; } else if (cmd == IOC_MDC_GETFILEINFO_OLD || cmd == LL_IOC_MDC_GETINFO_OLD){ struct lov_user_mds_data_v1 __user *lmdp; - lmdp = (struct lov_user_mds_data_v1 __user *)arg; + lmdp = uarg; statp = &lmdp->lmd_st; lump = &lmdp->lmd_lmm; } else { struct lov_user_mds_data __user *lmdp; - lmdp = (struct lov_user_mds_data __user *)arg; + lmdp = uarg; fidp = &lmdp->lmd_fid; stxp = &lmdp->lmd_stx; flagsp = &lmdp->lmd_flags; @@ -1850,66 +1846,62 @@ out_req: if (!qctl) RETURN(-ENOMEM); - if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl))) + if (copy_from_user(qctl, uarg, sizeof(*qctl))) GOTO(out_quotactl, rc = -EFAULT); rc = quotactl_ioctl(inode->i_sb, qctl); if (rc == 0 && - copy_to_user((void __user *)arg, qctl, sizeof(*qctl))) - rc = -EFAULT; - + copy_to_user(uarg, qctl, sizeof(*qctl))) + rc = -EFAULT; out_quotactl: OBD_FREE_PTR(qctl); RETURN(rc); - } + } case OBD_IOC_GETDTNAME: case OBD_IOC_GETMDNAME: - RETURN(ll_get_obd_name(inode, cmd, arg)); - case LL_IOC_FLUSHCTX: - RETURN(ll_flush_ctx(inode)); - case LL_IOC_GETOBDCOUNT: { + RETURN(ll_get_obd_name(inode, cmd, uarg)); + case LL_IOC_FLUSHCTX: + RETURN(ll_flush_ctx(inode)); + case LL_IOC_GETOBDCOUNT: { u32 count, vallen; - struct obd_export *exp; + struct obd_export *exp; - if (copy_from_user(&count, (int __user *)arg, sizeof(int))) - RETURN(-EFAULT); + if (copy_from_user(&count, uarg, sizeof(count))) + RETURN(-EFAULT); - /* get ost count when count is zero, get mdt count otherwise */ - exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp; - vallen = sizeof(count); + /* get ost count when count is zero, get mdt count otherwise */ + exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp; + vallen = sizeof(count); rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT), KEY_TGT_COUNT, &vallen, &count); - if (rc) { - CERROR("get target count failed: %d\n", rc); - RETURN(rc); - } + if (rc) { + CERROR("get target count failed: %d\n", rc); + RETURN(rc); + } - if (copy_to_user((int __user *)arg, &count, sizeof(int))) - RETURN(-EFAULT); + if (copy_to_user(uarg, &count, sizeof(count))) + RETURN(-EFAULT); - RETURN(0); - } - case LL_IOC_PATH2FID: - if (copy_to_user((void __user *)arg, ll_inode2fid(inode), - sizeof(struct lu_fid))) - RETURN(-EFAULT); - RETURN(0); - case LL_IOC_GET_CONNECT_FLAGS: { - RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL, - (void __user *)arg)); - } + RETURN(0); + } + case LL_IOC_PATH2FID: + if (copy_to_user(uarg, ll_inode2fid(inode), + sizeof(struct lu_fid))) + RETURN(-EFAULT); + RETURN(0); + case LL_IOC_GET_CONNECT_FLAGS: + RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL, uarg)); case OBD_IOC_FID2PATH: - RETURN(ll_fid2path(inode, (void __user *)arg)); + RETURN(ll_fid2path(inode, uarg)); case LL_IOC_GETPARENT: - RETURN(ll_getparent(file, (void __user *)arg)); + RETURN(ll_getparent(file, uarg)); case LL_IOC_FID2MDTIDX: { struct obd_export *exp = ll_i2mdexp(inode); - struct lu_fid fid; - __u32 index; + struct lu_fid fid; + __u32 index; - if (copy_from_user(&fid, (const struct lu_fid __user *)arg, - sizeof(fid))) + if (copy_from_user(&fid, uarg, sizeof(fid))) RETURN(-EFAULT); /* Call mdc_iocontrol */ @@ -1921,15 +1913,15 @@ out_req: RETURN(index); } case LL_IOC_HSM_REQUEST: { - struct hsm_user_request *hur; - ssize_t totalsize; + struct hsm_user_request *hur; + ssize_t totalsize; OBD_ALLOC_PTR(hur); if (hur == NULL) RETURN(-ENOMEM); /* We don't know the true size yet; copy the fixed-size part */ - if (copy_from_user(hur, (void __user *)arg, sizeof(*hur))) { + if (copy_from_user(hur, uarg, sizeof(*hur))) { OBD_FREE_PTR(hur); RETURN(-EFAULT); } @@ -1949,7 +1941,7 @@ out_req: RETURN(-ENOMEM); /* Copy the whole struct */ - if (copy_from_user(hur, (void __user *)arg, totalsize)) + if (copy_from_user(hur, uarg, totalsize)) GOTO(out_hur, rc = -EFAULT); if (hur->hur_request.hr_action == HUA_RELEASE) { @@ -1974,17 +1966,16 @@ out_req: rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize, hur, NULL); } - out_hur: OBD_FREE_LARGE(hur, totalsize); RETURN(rc); } case LL_IOC_HSM_PROGRESS: { - struct hsm_progress_kernel hpk; - struct hsm_progress hp; + struct hsm_progress_kernel hpk; + struct hsm_progress hp; - if (copy_from_user(&hp, (void __user *)arg, sizeof(hp))) + if (copy_from_user(&hp, uarg, sizeof(hp))) RETURN(-EFAULT); hpk.hpk_fid = hp.hp_fid; @@ -2004,43 +1995,42 @@ out_hur: if (!cfs_capable(CFS_CAP_SYS_ADMIN)) RETURN(-EPERM); - rc = copy_and_ct_start(cmd, sbi->ll_md_exp, - (struct lustre_kernelcomm __user *)arg); + rc = copy_and_ct_start(cmd, sbi->ll_md_exp, uarg); RETURN(rc); case LL_IOC_HSM_COPY_START: { - struct hsm_copy *copy; - int rc; + struct hsm_copy *copy; + int rc; OBD_ALLOC_PTR(copy); if (copy == NULL) RETURN(-ENOMEM); - if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) { + if (copy_from_user(copy, uarg, sizeof(*copy))) { OBD_FREE_PTR(copy); RETURN(-EFAULT); } rc = ll_ioc_copy_start(inode->i_sb, copy); - if (copy_to_user((char __user *)arg, copy, sizeof(*copy))) + if (copy_to_user(uarg, copy, sizeof(*copy))) rc = -EFAULT; OBD_FREE_PTR(copy); RETURN(rc); } case LL_IOC_HSM_COPY_END: { - struct hsm_copy *copy; - int rc; + struct hsm_copy *copy; + int rc; OBD_ALLOC_PTR(copy); if (copy == NULL) RETURN(-ENOMEM); - if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) { + if (copy_from_user(copy, uarg, sizeof(*copy))) { OBD_FREE_PTR(copy); RETURN(-EFAULT); } rc = ll_ioc_copy_end(inode->i_sb, copy); - if (copy_to_user((char __user *)arg, copy, sizeof(*copy))) + if (copy_to_user(uarg, copy, sizeof(*copy))) rc = -EFAULT; OBD_FREE_PTR(copy); @@ -2054,7 +2044,7 @@ out_hur: int namelen = 0; int rc; - rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg); + rc = obd_ioctl_getdata(&buf, &len, uarg); if (rc) RETURN(rc); @@ -2087,12 +2077,11 @@ migrate_free: RETURN(rc); } case LL_IOC_FSGETXATTR: - RETURN(ll_ioctl_fsgetxattr(inode, cmd, arg)); + RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg)); case LL_IOC_FSSETXATTR: - RETURN(ll_ioctl_fssetxattr(inode, cmd, arg)); + RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg)); default: - RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL, - (void __user *)arg)); + RETURN((obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL, uarg)); } } --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -1224,7 +1224,7 @@ static int ll_lease_close(struct obd_cli * After lease is taken, send the RPC MDS_REINT_RESYNC to the MDT */ static int ll_lease_file_resync(struct obd_client_handle *och, - struct inode *inode, unsigned long arg) + struct inode *inode, void __user *uarg) { struct ll_sb_info *sbi = ll_i2sbi(inode); struct md_op_data *op_data; @@ -1238,8 +1238,7 @@ static int ll_lease_file_resync(struct o if (IS_ERR(op_data)) RETURN(PTR_ERR(op_data)); - if (copy_from_user(&ioc, (struct ll_ioc_lease_id __user *)arg, - sizeof(ioc))) + if (copy_from_user(&ioc, uarg, sizeof(ioc))) RETURN(-EFAULT); /* before starting file resync, it's necessary to clean up page cache @@ -2122,10 +2121,10 @@ static int ll_file_getstripe(struct inod static int ll_lov_setstripe(struct inode *inode, struct file *file, void __user *arg) { - struct lov_user_md __user *lum = (struct lov_user_md __user *)arg; - struct lov_user_md *klum; - int lum_size, rc; - __u64 flags = FMODE_WRITE; + struct lov_user_md __user *lum = arg; + struct lov_user_md *klum; + int lum_size, rc; + __u64 flags = FMODE_WRITE; ENTRY; rc = ll_copy_user_md(lum, &klum); @@ -3039,21 +3038,18 @@ static int ll_lock_noexpand(struct file } int ll_ioctl_fsgetxattr(struct inode *inode, unsigned int cmd, - unsigned long arg) + void __user *uarg) { struct fsxattr fsxattr; - if (copy_from_user(&fsxattr, - (const struct fsxattr __user *)arg, - sizeof(fsxattr))) + if (copy_from_user(&fsxattr, uarg, sizeof(fsxattr))) RETURN(-EFAULT); fsxattr.fsx_xflags = ll_inode_flags_to_xflags(inode->i_flags); if (ll_file_test_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT)) fsxattr.fsx_xflags |= FS_XFLAG_PROJINHERIT; fsxattr.fsx_projid = ll_i2info(inode)->lli_projid; - if (copy_to_user((struct fsxattr __user *)arg, - &fsxattr, sizeof(fsxattr))) + if (copy_to_user(uarg, &fsxattr, sizeof(fsxattr))) RETURN(-EFAULT); RETURN(0); @@ -3084,7 +3080,7 @@ int ll_ioctl_check_project(struct inode } int ll_ioctl_fssetxattr(struct inode *inode, unsigned int cmd, - unsigned long arg) + void __user *uarg) { struct md_op_data *op_data; @@ -3095,9 +3091,7 @@ int ll_ioctl_fssetxattr(struct inode *in struct iattr *attr; int flags; - if (copy_from_user(&fsxattr, - (const struct fsxattr __user *)arg, - sizeof(fsxattr))) + if (copy_from_user(&fsxattr, uarg, sizeof(fsxattr))) RETURN(-EFAULT); rc = ll_ioctl_check_project(inode, &fsxattr); @@ -3138,11 +3132,11 @@ out_fsxattr: } static long ll_file_unlock_lease(struct file *file, struct ll_ioc_lease *ioc, - unsigned long arg) + void __user *uarg) { - struct inode *inode = file_inode(file); - struct ll_file_data *fd = LUSTRE_FPRIVATE(file); - struct ll_inode_info *lli = ll_i2info(inode); + struct inode *inode = file_inode(file); + struct ll_file_data *fd = LUSTRE_FPRIVATE(file); + struct ll_inode_info *lli = ll_i2info(inode); struct obd_client_handle *och = NULL; struct split_param sp; bool lease_broken; @@ -3176,19 +3170,18 @@ static long ll_file_unlock_lease(struct if (!data) GOTO(out, rc = -ENOMEM); - if (copy_from_user(data, (void __user *)arg, data_size)) + if (copy_from_user(data, uarg, data_size)) GOTO(out, rc = -EFAULT); bias = MDS_CLOSE_RESYNC_DONE; break; case LL_LEASE_LAYOUT_MERGE: { int fd; - if (ioc->lil_count != 1) GOTO(out, rc = -EINVAL); - arg += sizeof(*ioc); - if (copy_from_user(&fd, (void __user *)arg, sizeof(__u32))) + uarg += sizeof(*ioc); + if (copy_from_user(&fd, uarg, sizeof(__u32))) GOTO(out, rc = -EFAULT); layout_file = fget(fd); @@ -3210,13 +3203,12 @@ static long ll_file_unlock_lease(struct if (ioc->lil_count != 2) GOTO(out, rc = -EINVAL); - arg += sizeof(*ioc); - if (copy_from_user(&fdv, (void __user *)arg, sizeof(__u32))) + uarg += sizeof(*ioc); + if (copy_from_user(&fdv, uarg, sizeof(__u32))) GOTO(out, rc = -EFAULT); - arg += sizeof(__u32); - if (copy_from_user(&mirror_id, (void __user *)arg, - sizeof(__u32))) + uarg += sizeof(__u32); + if (copy_from_user(&mirror_id, uarg, sizeof(__u32))) GOTO(out, rc = -EFAULT); layout_file = fget(fdv); @@ -3265,7 +3257,7 @@ out: } static long ll_file_set_lease(struct file *file, struct ll_ioc_lease *ioc, - unsigned long arg) + void __user *uarg) { struct inode *inode = file_inode(file); struct ll_inode_info *lli = ll_i2info(inode); @@ -3289,7 +3281,7 @@ static long ll_file_set_lease(struct fil fmode = FMODE_READ; break; case LL_LEASE_UNLCK: - RETURN(ll_file_unlock_lease(file, ioc, arg)); + RETURN(ll_file_unlock_lease(file, ioc, uarg)); default: RETURN(-EINVAL); } @@ -3304,7 +3296,7 @@ static long ll_file_set_lease(struct fil RETURN(PTR_ERR(och)); if (ioc->lil_flags & LL_LEASE_RESYNC) { - rc = ll_lease_file_resync(och, inode, arg); + rc = ll_lease_file_resync(och, inode, uarg); if (rc) { ll_lease_close(och, inode, NULL); RETURN(rc); @@ -3334,9 +3326,10 @@ static long ll_file_set_lease(struct fil static long ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct inode *inode = file_inode(file); - struct ll_file_data *fd = LUSTRE_FPRIVATE(file); - int flags, rc; + struct inode *inode = file_inode(file); + struct ll_file_data *fd = LUSTRE_FPRIVATE(file); + void __user *uarg = (void __user *)arg; + int flags, rc; ENTRY; CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%x\n", @@ -3351,39 +3344,38 @@ ll_file_ioctl(struct file *file, unsigne case LL_IOC_GETFLAGS: /* Get the current value of the file flags */ return put_user(fd->fd_flags, (int __user *)arg); - case LL_IOC_SETFLAGS: - case LL_IOC_CLRFLAGS: - /* Set or clear specific file flags */ - /* XXX This probably needs checks to ensure the flags are - * not abused, and to handle any flag side effects. - */ - if (get_user(flags, (int __user *) arg)) - RETURN(-EFAULT); - - if (cmd == LL_IOC_SETFLAGS) { - if ((flags & LL_FILE_IGNORE_LOCK) && - !(file->f_flags & O_DIRECT)) { - CERROR("%s: unable to disable locking on " - "non-O_DIRECT file\n", current->comm); - RETURN(-EINVAL); - } - - fd->fd_flags |= flags; - } else { - fd->fd_flags &= ~flags; - } - RETURN(0); + case LL_IOC_SETFLAGS: + case LL_IOC_CLRFLAGS: + /* Set or clear specific file flags */ + /* XXX This probably needs checks to ensure the flags are + * not abused, and to handle any flag side effects. + */ + if (get_user(flags, (int __user *)arg)) + RETURN(-EFAULT); + + if (cmd == LL_IOC_SETFLAGS) { + if ((flags & LL_FILE_IGNORE_LOCK) && + !(file->f_flags & O_DIRECT)) { + CERROR("%s: unable to disable locking on " + "non-O_DIRECT file\n", current->comm); + RETURN(-EINVAL); + } + + fd->fd_flags |= flags; + } else { + fd->fd_flags &= ~flags; + } + RETURN(0); case LL_IOC_LOV_SETSTRIPE: case LL_IOC_LOV_SETSTRIPE_NEW: - RETURN(ll_lov_setstripe(inode, file, (void __user *)arg)); + RETURN(ll_lov_setstripe(inode, file, uarg)); case LL_IOC_LOV_SETEA: - RETURN(ll_lov_setea(inode, file, (void __user *)arg)); + RETURN(ll_lov_setea(inode, file, uarg)); case LL_IOC_LOV_SWAP_LAYOUTS: { struct file *file2; struct lustre_swap_layouts lsl; - if (copy_from_user(&lsl, (char __user *)arg, - sizeof(struct lustre_swap_layouts))) + if (copy_from_user(&lsl, uarg, sizeof(lsl))) RETURN(-EFAULT); if ((file->f_flags & O_ACCMODE) == O_RDONLY) @@ -3398,9 +3390,9 @@ ll_file_ioctl(struct file *file, unsigne GOTO(out, rc = -EPERM); if (lsl.sl_flags & SWAP_LAYOUTS_CLOSE) { - struct inode *inode2; - struct ll_inode_info *lli; - struct obd_client_handle *och = NULL; + struct obd_client_handle *och = NULL; + struct ll_inode_info *lli; + struct inode *inode2; lli = ll_i2info(inode); mutex_lock(&lli->lli_och_mutex); @@ -3422,10 +3414,10 @@ out: } case LL_IOC_LOV_GETSTRIPE: case LL_IOC_LOV_GETSTRIPE_NEW: - RETURN(ll_file_getstripe(inode, (void __user *)arg, 0)); + RETURN(ll_file_getstripe(inode, uarg, 0)); case FS_IOC_GETFLAGS: case FS_IOC_SETFLAGS: - RETURN(ll_iocontrol(inode, file, cmd, arg)); + RETURN(ll_iocontrol(inode, file, cmd, uarg)); case FSFILT_IOC_GETVERSION: case FS_IOC_GETVERSION: RETURN(put_user(inode->i_generation, (int __user *)arg)); @@ -3435,63 +3427,62 @@ out: case FS_IOC_SETVERSION: RETURN(-ENOTSUPP); - case LL_IOC_GROUP_LOCK: - RETURN(ll_get_grouplock(inode, file, arg)); - case LL_IOC_GROUP_UNLOCK: - RETURN(ll_put_grouplock(inode, file, arg)); - case IOC_OBD_STATFS: - RETURN(ll_obd_statfs(inode, (void __user *)arg)); + case LL_IOC_GROUP_LOCK: + RETURN(ll_get_grouplock(inode, file, arg)); + case LL_IOC_GROUP_UNLOCK: + RETURN(ll_put_grouplock(inode, file, arg)); + case IOC_OBD_STATFS: + RETURN(ll_obd_statfs(inode, uarg)); case LL_IOC_FLUSHCTX: RETURN(ll_flush_ctx(inode)); case LL_IOC_PATH2FID: { - if (copy_to_user((void __user *)arg, ll_inode2fid(inode), + if (copy_to_user(uarg, ll_inode2fid(inode), sizeof(struct lu_fid))) RETURN(-EFAULT); RETURN(0); } case LL_IOC_GETPARENT: - RETURN(ll_getparent(file, (struct getparent __user *)arg)); + RETURN(ll_getparent(file, uarg)); case OBD_IOC_FID2PATH: - RETURN(ll_fid2path(inode, (void __user *)arg)); + RETURN(ll_fid2path(inode, uarg)); case LL_IOC_DATA_VERSION: { - struct ioc_data_version idv; + struct ioc_data_version idv; int rc; - if (copy_from_user(&idv, (char __user *)arg, sizeof(idv))) + if (copy_from_user(&idv, uarg, sizeof(idv))) RETURN(-EFAULT); idv.idv_flags &= LL_DV_RD_FLUSH | LL_DV_WR_FLUSH; rc = ll_ioc_data_version(inode, &idv); - if (rc == 0 && - copy_to_user((char __user *)arg, &idv, sizeof(idv))) + if (rc == 0 && copy_to_user(uarg, &idv, sizeof(idv))) RETURN(-EFAULT); RETURN(rc); } - case LL_IOC_GET_MDTIDX: { - int mdtidx; + case LL_IOC_GET_MDTIDX: { + int mdtidx; - mdtidx = ll_get_mdt_idx(inode); - if (mdtidx < 0) - RETURN(mdtidx); + mdtidx = ll_get_mdt_idx(inode); + if (mdtidx < 0) + RETURN(mdtidx); - if (put_user((int)mdtidx, (int __user *)arg)) - RETURN(-EFAULT); + if (put_user(mdtidx, (int __user *)arg)) + RETURN(-EFAULT); - RETURN(0); - } + RETURN(0); + } case OBD_IOC_GETDTNAME: case OBD_IOC_GETMDNAME: - RETURN(ll_get_obd_name(inode, cmd, arg)); + RETURN(ll_get_obd_name(inode, cmd, uarg)); case LL_IOC_HSM_STATE_GET: { - struct md_op_data *op_data; - struct hsm_user_state *hus; - int rc; + struct md_op_data *op_data; + struct hsm_user_state *hus; + int rc; OBD_ALLOC_PTR(hus); if (hus == NULL) @@ -3507,7 +3498,7 @@ out: rc = obd_iocontrol(cmd, ll_i2mdexp(inode), sizeof(*op_data), op_data, NULL); - if (copy_to_user((void __user *)arg, hus, sizeof(*hus))) + if (copy_to_user(uarg, hus, sizeof(*hus))) rc = -EFAULT; ll_finish_md_op_data(op_data); @@ -3515,14 +3506,14 @@ out: RETURN(rc); } case LL_IOC_HSM_STATE_SET: { - struct hsm_state_set *hss; - int rc; + struct hsm_state_set *hss; + int rc; OBD_ALLOC_PTR(hss); if (hss == NULL) RETURN(-ENOMEM); - if (copy_from_user(hss, (char __user *)arg, sizeof(*hss))) { + if (copy_from_user(hss, uarg, sizeof(*hss))) { OBD_FREE_PTR(hss); RETURN(-EFAULT); } @@ -3551,7 +3542,7 @@ out: rc = obd_iocontrol(cmd, ll_i2mdexp(inode), sizeof(*op_data), op_data, NULL); - if (copy_to_user((char __user *)arg, hca, sizeof(*hca))) + if (copy_to_user(uarg, hca, sizeof(*hca))) rc = -EFAULT; ll_finish_md_op_data(op_data); @@ -3559,17 +3550,17 @@ out: RETURN(rc); } case LL_IOC_SET_LEASE_OLD: { - struct ll_ioc_lease ioc = { .lil_mode = (__u32)arg }; + struct ll_ioc_lease ioc = { .lil_mode = arg }; RETURN(ll_file_set_lease(file, &ioc, 0)); } case LL_IOC_SET_LEASE: { struct ll_ioc_lease ioc; - if (copy_from_user(&ioc, (void __user *)arg, sizeof(ioc))) + if (copy_from_user(&ioc, uarg, sizeof(ioc))) RETURN(-EFAULT); - RETURN(ll_file_set_lease(file, &ioc, arg)); + RETURN(ll_file_set_lease(file, &ioc, uarg)); } case LL_IOC_GET_LEASE: { struct ll_inode_info *lli = ll_i2info(inode); @@ -3601,7 +3592,7 @@ out: if (hui == NULL) RETURN(-ENOMEM); - if (copy_from_user(hui, (void __user *)arg, sizeof(*hui))) { + if (copy_from_user(hui, uarg, sizeof(*hui))) { OBD_FREE_PTR(hui); RETURN(-EFAULT); } @@ -3614,9 +3605,7 @@ out: case LL_IOC_FUTIMES_3: { struct ll_futimes_3 lfu; - if (copy_from_user(&lfu, - (const struct ll_futimes_3 __user *)arg, - sizeof(lfu))) + if (copy_from_user(&lfu, uarg, sizeof(lfu))) RETURN(-EFAULT); RETURN(ll_file_futimes_3(file, &lfu)); @@ -3629,7 +3618,7 @@ out: int alloc_size = sizeof(*k_ladvise_hdr); rc = 0; - u_ladvise_hdr = (void __user *)arg; + u_ladvise_hdr = uarg; OBD_ALLOC_PTR(k_ladvise_hdr); if (k_ladvise_hdr == NULL) RETURN(-ENOMEM); @@ -3705,18 +3694,17 @@ out_ladvise: if (!(file->f_flags & O_DIRECT)) RETURN(-EINVAL); - fd->fd_designated_mirror = (__u32)arg; + fd->fd_designated_mirror = arg; RETURN(0); } case LL_IOC_FSGETXATTR: - RETURN(ll_ioctl_fsgetxattr(inode, cmd, arg)); + RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg)); case LL_IOC_FSSETXATTR: - RETURN(ll_ioctl_fssetxattr(inode, cmd, arg)); + RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg)); case BLKSSZGET: RETURN(put_user(PAGE_SIZE, (int __user *)arg)); default: - RETURN(obd_iocontrol(cmd, ll_i2dtexp(inode), 0, NULL, - (void __user *)arg)); + RETURN(obd_iocontrol(cmd, ll_i2dtexp(inode), 0, NULL, uarg)); } } --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -914,10 +914,9 @@ int ll_inode_permission(struct inode *in #endif int ll_ioctl_check_project(struct inode *inode, struct fsxattr *fa); int ll_ioctl_fsgetxattr(struct inode *inode, unsigned int cmd, - unsigned long arg); + void __user *uarg); int ll_ioctl_fssetxattr(struct inode *inode, unsigned int cmd, - unsigned long arg); - + void __user *uarg); int ll_lov_setstripe_ea_info(struct inode *inode, struct dentry *dentry, __u64 flags, struct lov_user_md *lum, int lum_size); @@ -978,7 +977,7 @@ void ll_update_inode_flags(struct inode int ll_read_inode2(struct inode *inode, void *opaque); void ll_delete_inode(struct inode *inode); int ll_iocontrol(struct inode *inode, struct file *file, - unsigned int cmd, unsigned long arg); + unsigned int cmd, void __user *uarg); int ll_flush_ctx(struct inode *inode); void ll_umount_begin(struct super_block *sb); int ll_remount_fs(struct super_block *sb, int *flags, char *data); @@ -1009,7 +1008,7 @@ struct md_op_data *ll_prep_md_op_data(st const char *name, size_t namelen, __u32 mode, __u32 opc, void *data); void ll_finish_md_op_data(struct md_op_data *op_data); -int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg); +int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *arg); char *ll_get_fsname(struct super_block *sb, char *buf, int buflen); void ll_compute_rootsquash_state(struct ll_sb_info *sbi); ssize_t ll_copy_user_md(const struct lov_user_md __user *md, --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -2157,7 +2157,7 @@ void ll_delete_inode(struct inode *inode } int ll_iocontrol(struct inode *inode, struct file *file, - unsigned int cmd, unsigned long arg) + unsigned int cmd, void __user *uarg) { struct ll_sb_info *sbi = ll_i2sbi(inode); struct ptlrpc_request *req = NULL; @@ -2191,7 +2191,7 @@ int ll_iocontrol(struct inode *inode, st ptlrpc_req_finished(req); - RETURN(put_user(flags, (int __user *)arg)); + RETURN(put_user(flags, (int __user *)uarg)); } case FS_IOC_SETFLAGS: { struct iattr *attr; @@ -2199,7 +2199,7 @@ int ll_iocontrol(struct inode *inode, st struct cl_object *obj; struct fsxattr fa = { 0 }; - if (get_user(flags, (int __user *)arg)) + if (get_user(flags, (int __user *)uarg)) RETURN(-EFAULT); fa.fsx_projid = ll_i2info(inode)->lli_projid; @@ -2482,7 +2482,7 @@ cleanup: return rc; } -int ll_obd_statfs(struct inode *inode, void __user *arg) +int ll_obd_statfs(struct inode *inode, void __user *uarg) { struct ll_sb_info *sbi = NULL; struct obd_export *exp; @@ -2494,7 +2494,7 @@ int ll_obd_statfs(struct inode *inode, v if (!inode || !(sbi = ll_i2sbi(inode))) GOTO(out_statfs, rc = -EINVAL); - rc = obd_ioctl_getdata(&buf, &len, arg); + rc = obd_ioctl_getdata(&buf, &len, uarg); if (rc) GOTO(out_statfs, rc); @@ -2676,24 +2676,23 @@ int ll_show_options(struct seq_file *seq /** * Get obd name by cmd, and copy out to user space */ -int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg) +int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg) { - struct ll_sb_info *sbi = ll_i2sbi(inode); - struct obd_device *obd; - ENTRY; + struct ll_sb_info *sbi = ll_i2sbi(inode); + struct obd_device *obd; + ENTRY; if (cmd == OBD_IOC_GETDTNAME) - obd = class_exp2obd(sbi->ll_dt_exp); - else if (cmd == OBD_IOC_GETMDNAME) - obd = class_exp2obd(sbi->ll_md_exp); - else - RETURN(-EINVAL); + obd = class_exp2obd(sbi->ll_dt_exp); + else if (cmd == OBD_IOC_GETMDNAME) + obd = class_exp2obd(sbi->ll_md_exp); + else + RETURN(-EINVAL); - if (!obd) - RETURN(-ENOENT); + if (!obd) + RETURN(-ENOENT); - if (copy_to_user((void __user *)arg, obd->obd_name, - strlen(obd->obd_name) + 1)) + if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1)) RETURN(-EFAULT); RETURN(0); --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -285,7 +285,7 @@ int obd_ioctl_getdata(char **buf, int *l } EXPORT_SYMBOL(obd_ioctl_getdata); -int class_handle_ioctl(unsigned int cmd, unsigned long arg) +int class_handle_ioctl(unsigned int cmd, void __user *uarg) { char *buf = NULL; struct obd_ioctl_data *data; @@ -294,7 +294,7 @@ int class_handle_ioctl(unsigned int cmd, ENTRY; CDEBUG(D_IOCTL, "cmd = %x\n", cmd); - if (obd_ioctl_getdata(&buf, &len, (void __user *)arg)) { + if (obd_ioctl_getdata(&buf, &len, uarg)) { CERROR("OBD ioctl: data error\n"); RETURN(-EINVAL); } @@ -345,27 +345,25 @@ int class_handle_ioctl(unsigned int cmd, memcpy(data->ioc_bulk, LUSTRE_VERSION_STRING, strlen(LUSTRE_VERSION_STRING) + 1); - if (copy_to_user((void __user *)arg, data, len)) + if (copy_to_user(uarg, data, len)) err = -EFAULT; GOTO(out, err); } #endif - case OBD_IOC_NAME2DEV: { - /* Resolve a device name. This does not change the - * currently selected device. - */ - int dev; - - dev = class_resolve_dev_name(data->ioc_inllen1, - data->ioc_inlbuf1); - data->ioc_dev = dev; - if (dev < 0) - GOTO(out, err = -EINVAL); + case OBD_IOC_NAME2DEV: { + /* Resolve device name, does not change current selected dev */ + int dev; + + dev = class_resolve_dev_name(data->ioc_inllen1, + data->ioc_inlbuf1); + data->ioc_dev = dev; + if (dev < 0) + GOTO(out, err = -EINVAL); - if (copy_to_user((void __user *)arg, data, sizeof(*data))) - err = -EFAULT; - GOTO(out, err); - } + if (copy_to_user(uarg, data, sizeof(*data))) + err = -EFAULT; + GOTO(out, err); + } case OBD_IOC_UUID2DEV: { /* Resolve a device uuid. This does not change the @@ -393,12 +391,12 @@ int class_handle_ioctl(unsigned int cmd, GOTO(out, err = -EINVAL); } - CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1, - dev); - if (copy_to_user((void __user *)arg, data, sizeof(*data))) - err = -EFAULT; - GOTO(out, err); - } + CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1, + dev); + if (copy_to_user(uarg, data, sizeof(*data))) + err = -EFAULT; + GOTO(out, err); + } case OBD_IOC_GETDEVICE: { int index = data->ioc_count; @@ -425,19 +423,18 @@ int class_handle_ioctl(unsigned int cmd, status = "AT"; else status = "--"; - str = (char *)data->ioc_bulk; - snprintf(str, len - sizeof(*data), "%3d %s %s %s %s %d", - (int)index, status, obd->obd_type->typ_name, - obd->obd_name, obd->obd_uuid.uuid, + str = data->ioc_bulk; + snprintf(str, len - sizeof(*data), "%3d %s %s %s %s %d", + index, status, obd->obd_type->typ_name, + obd->obd_name, obd->obd_uuid.uuid, atomic_read(&obd->obd_refcount)); - if (copy_to_user((void __user *)arg, data, len)) + if (copy_to_user(uarg, data, len)) err = -EFAULT; GOTO(out, err); - } - - } + } + } if (data->ioc_dev == OBD_DEV_BY_DEVNAME) { if (data->ioc_inllen4 <= 0 || data->ioc_inlbuf4 == NULL) @@ -480,7 +477,7 @@ int class_handle_ioctl(unsigned int cmd, if (err) GOTO(out, err); - if (copy_to_user((void __user *)arg, data, len)) + if (copy_to_user(uarg, data, len)) err = -EFAULT; GOTO(out, err); } @@ -522,7 +519,7 @@ static long obd_class_ioctl(struct file if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */ RETURN(err = -ENOTTY); - err = class_handle_ioctl(cmd, (unsigned long)arg); + err = class_handle_ioctl(cmd, (void __user *)arg); RETURN(err); }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor