File 0058-LU-16634-llite-move-common-ioctl-code-to-ll_iocontro.patch of Package lustre_2_12
From 3be425883918528ef981af697b34de187c3937b3 Mon Sep 17 00:00:00 2001
From: Andreas Dilger <adilger@whamcloud.com>
Date: Sun, 19 Mar 2023 19:40:41 -0600
Subject: [PATCH] LU-16634 llite: move common ioctl code to ll_iocontrol()
Move common ioctl cases from ll_dir_ioctl() and ll_file_ioctl()
into ll_iocontrol() to avoid duplicate code.
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: I1a0d2f839949debf346aa15c65b0f407e3ce7057
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50335
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: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
---
lustre/llite/dir.c | 49 ++---------------------------
lustre/llite/file.c | 65 ++++----------------------------------
lustre/llite/llite_lib.c | 79 +++++++++++++++++++++++++++++++++--------------
3 files changed, 69 insertions(+), 124 deletions(-)
--- a/lustre/llite/dir.c
+++ b/lustre/llite/dir.c
@@ -1375,30 +1375,6 @@ static long ll_dir_ioctl(struct file *fi
ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
switch (cmd) {
- case FS_IOC_GETFLAGS:
- case FS_IOC_SETFLAGS:
- RETURN(ll_iocontrol(inode, file, cmd, uarg));
- case FSFILT_IOC_GETVERSION:
- case FS_IOC_GETVERSION:
- RETURN(put_user(inode->i_generation, (int __user *)arg));
- /* We need to special case any other ioctls we want to handle,
- * to send them to the MDS/OST as appropriate and to properly
- * network encode the arg field. */
- case FS_IOC_SETVERSION:
- RETURN(-ENOTSUPP);
-
- case LL_IOC_GET_MDTIDX: {
- int mdtidx;
-
- mdtidx = ll_get_mdt_idx(inode);
- if (mdtidx < 0)
- RETURN(mdtidx);
-
- if (put_user((int)mdtidx, (int __user *)arg))
- RETURN(-EFAULT);
-
- return 0;
- }
case IOC_MDC_LOOKUP: {
int namelen, len = 0;
char *buf = NULL;
@@ -1661,8 +1637,6 @@ out_rmdir:
RETURN(ll_rmfid(file, uarg));
case LL_IOC_LOV_SWAP_LAYOUTS:
RETURN(-EPERM);
- case IOC_OBD_STATFS:
- RETURN(ll_obd_statfs(inode, uarg));
case LL_IOC_LOV_GETSTRIPE:
case LL_IOC_LOV_GETSTRIPE_NEW:
case LL_IOC_MDC_GETINFO:
@@ -1858,11 +1832,6 @@ out_req:
OBD_FREE_PTR(qctl);
RETURN(rc);
}
- case OBD_IOC_GETDTNAME:
- case OBD_IOC_GETMDNAME:
- 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;
@@ -1885,17 +1854,8 @@ out_req:
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, uarg));
- case LL_IOC_GETPARENT:
- RETURN(ll_getparent(file, uarg));
case LL_IOC_FID2MDTIDX: {
struct obd_export *exp = ll_i2mdexp(inode);
struct lu_fid fid;
@@ -2076,12 +2036,11 @@ migrate_free:
RETURN(rc);
}
- case LL_IOC_FSGETXATTR:
- RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
- case LL_IOC_FSSETXATTR:
- RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
default:
- RETURN((obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL, uarg));
+ rc = ll_iocontrol(inode, file, cmd, uarg);
+ if (rc != -ENOTTY)
+ RETURN(rc);
+ RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL, uarg));
}
}
--- a/lustre/llite/file.c
+++ b/lustre/llite/file.c
@@ -2076,11 +2076,10 @@ out:
static int ll_lov_setea(struct inode *inode, struct file *file,
void __user *arg)
{
- __u64 flags = MDS_OPEN_HAS_OBJS | FMODE_WRITE;
- struct lov_user_md *lump;
- int lum_size = sizeof(struct lov_user_md) +
- sizeof(struct lov_user_ost_data);
- int rc;
+ __u64 flags = MDS_OPEN_HAS_OBJS | FMODE_WRITE;
+ struct lov_user_md *lump;
+ int lum_size = sizeof(*lump) + sizeof(struct lov_user_ost_data);
+ int rc;
ENTRY;
if (!cfs_capable(CFS_CAP_SYS_ADMIN))
@@ -2088,7 +2087,7 @@ static int ll_lov_setea(struct inode *in
OBD_ALLOC_LARGE(lump, lum_size);
if (lump == NULL)
- RETURN(-ENOMEM);
+ RETURN(-ENOMEM);
if (copy_from_user(lump, arg, lum_size))
GOTO(out_lump, rc = -EFAULT);
@@ -3415,39 +3414,10 @@ out:
case LL_IOC_LOV_GETSTRIPE:
case LL_IOC_LOV_GETSTRIPE_NEW:
RETURN(ll_file_getstripe(inode, uarg, 0));
- case FS_IOC_GETFLAGS:
- case FS_IOC_SETFLAGS:
- RETURN(ll_iocontrol(inode, file, cmd, uarg));
- case FSFILT_IOC_GETVERSION:
- case FS_IOC_GETVERSION:
- RETURN(put_user(inode->i_generation, (int __user *)arg));
- /* We need to special case any other ioctls we want to handle,
- * to send them to the MDS/OST as appropriate and to properly
- * network encode the arg field. */
- 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, uarg));
-
- case LL_IOC_FLUSHCTX:
- RETURN(ll_flush_ctx(inode));
- case LL_IOC_PATH2FID: {
- if (copy_to_user(uarg, ll_inode2fid(inode),
- sizeof(struct lu_fid)))
- RETURN(-EFAULT);
-
- RETURN(0);
- }
- case LL_IOC_GETPARENT:
- RETURN(ll_getparent(file, uarg));
-
- case OBD_IOC_FID2PATH:
- RETURN(ll_fid2path(inode, uarg));
case LL_IOC_DATA_VERSION: {
struct ioc_data_version idv;
int rc;
@@ -3463,22 +3433,6 @@ out:
RETURN(rc);
}
-
- case LL_IOC_GET_MDTIDX: {
- int mdtidx;
-
- mdtidx = ll_get_mdt_idx(inode);
- if (mdtidx < 0)
- RETURN(mdtidx);
-
- if (put_user(mdtidx, (int __user *)arg))
- RETURN(-EFAULT);
-
- RETURN(0);
- }
- case OBD_IOC_GETDTNAME:
- case OBD_IOC_GETMDNAME:
- 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;
@@ -3697,13 +3651,10 @@ out_ladvise:
fd->fd_designated_mirror = arg;
RETURN(0);
}
- case LL_IOC_FSGETXATTR:
- RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
- case LL_IOC_FSSETXATTR:
- RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
- case BLKSSZGET:
- RETURN(put_user(PAGE_SIZE, (int __user *)arg));
default:
+ rc = ll_iocontrol(inode, file, cmd, uarg);
+ if (rc != -ENOTTY)
+ RETURN(rc);
RETURN(obd_iocontrol(cmd, ll_i2dtexp(inode), 0, NULL, uarg));
}
}
--- a/lustre/llite/llite_lib.c
+++ b/lustre/llite/llite_lib.c
@@ -2156,6 +2156,7 @@ void ll_delete_inode(struct inode *inode
EXIT;
}
+/* ioctl commands shared between files and directories */
int ll_iocontrol(struct inode *inode, struct file *file,
unsigned int cmd, void __user *uarg)
{
@@ -2165,27 +2166,31 @@ int ll_iocontrol(struct inode *inode, st
ENTRY;
switch (cmd) {
+ case BLKSSZGET:
+ RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
+ case FSFILT_IOC_GETVERSION:
+ case FS_IOC_GETVERSION:
+ RETURN(put_user(inode->i_generation, (int __user *)uarg));
case FS_IOC_GETFLAGS: {
- struct mdt_body *body;
- struct md_op_data *op_data;
+ struct mdt_body *body;
+ struct md_op_data *op_data;
+
+ op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
+ LUSTRE_OPC_ANY, NULL);
+ if (IS_ERR(op_data))
+ RETURN(PTR_ERR(op_data));
- op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
- 0, 0, LUSTRE_OPC_ANY,
- NULL);
- if (IS_ERR(op_data))
- RETURN(PTR_ERR(op_data));
-
- op_data->op_valid = OBD_MD_FLFLAGS;
- rc = md_getattr(sbi->ll_md_exp, op_data, &req);
- ll_finish_md_op_data(op_data);
- if (rc) {
+ op_data->op_valid = OBD_MD_FLFLAGS;
+ rc = md_getattr(sbi->ll_md_exp, op_data, &req);
+ ll_finish_md_op_data(op_data);
+ if (rc) {
CERROR("%s: failure inode "DFID": rc = %d\n",
sbi->ll_md_exp->exp_obd->obd_name,
PFID(ll_inode2fid(inode)), rc);
- RETURN(-abs(rc));
- }
+ RETURN(-abs(rc));
+ }
- body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
+ body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
flags = body->mbo_flags;
@@ -2218,8 +2223,8 @@ int ll_iocontrol(struct inode *inode, st
op_data->op_attr_flags = flags;
op_data->op_xvalid |= OP_XVALID_FLAGS;
rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
- ll_finish_md_op_data(op_data);
- ptlrpc_req_finished(req);
+ ll_finish_md_op_data(op_data);
+ ptlrpc_req_finished(req);
if (rc)
RETURN(rc);
@@ -2237,12 +2242,42 @@ int ll_iocontrol(struct inode *inode, st
OBD_FREE_PTR(attr);
RETURN(rc);
- }
- default:
- RETURN(-ENOSYS);
- }
+ }
+ case FS_IOC_FSGETXATTR:
+ RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
+ case FS_IOC_FSSETXATTR:
+ RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
+ case IOC_OBD_STATFS:
+ RETURN(ll_obd_statfs(inode, uarg));
+ case LL_IOC_GET_MDTIDX: {
+ rc = ll_get_mdt_idx(inode);
+ if (rc < 0)
+ RETURN(rc);
+
+ if (put_user(rc, (int __user *)uarg))
+ RETURN(-EFAULT);
+
+ RETURN(0);
+ }
+ case LL_IOC_FLUSHCTX:
+ RETURN(ll_flush_ctx(inode));
+ case LL_IOC_GETPARENT:
+ RETURN(ll_getparent(file, uarg));
+ case LL_IOC_PATH2FID:
+ if (copy_to_user(uarg, ll_inode2fid(inode),
+ sizeof(struct lu_fid)))
+ RETURN(-EFAULT);
+ RETURN(0);
+ case OBD_IOC_FID2PATH:
+ RETURN(ll_fid2path(inode, uarg));
+ case OBD_IOC_GETDTNAME:
+ case OBD_IOC_GETMDNAME:
+ RETURN(ll_get_obd_name(inode, cmd, uarg));
+ default:
+ RETURN(-ENOTTY);
+ }
- RETURN(0);
+ RETURN(0);
}
int ll_flush_ctx(struct inode *inode)