Whamcloud - gitweb
LU-16634 llite: move common ioctl code to ll_iocontrol() 35/50335/2
authorAndreas Dilger <adilger@whamcloud.com>
Mon, 20 Mar 2023 01:40:41 +0000 (19:40 -0600)
committerOleg Drokin <green@whamcloud.com>
Tue, 11 Apr 2023 20:01:52 +0000 (20:01 +0000)
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
lustre/llite/file.c
lustre/llite/llite_lib.c

index b820773..7714fda 100644 (file)
@@ -1509,30 +1509,6 @@ static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
        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 *filename;
@@ -1844,17 +1820,6 @@ finish_req:
                ptlrpc_req_finished(root_request);
                return rc;
        }
-
-       case LL_IOC_UNLOCK_FOREIGN:
-               /* if not a foreign symlink do nothing */
-               if (ll_foreign_is_removable(dentry, true)) {
-                       CDEBUG(D_INFO,
-                              "prevent rmdir of non-foreign dir ("DFID")\n",
-                              PFID(ll_inode2fid(inode)));
-                       RETURN(-EOPNOTSUPP);
-               }
-               RETURN(0);
-
        case LL_IOC_REMOVE_ENTRY: {
                char            *filename = NULL;
                int              namelen = 0;
@@ -1886,8 +1851,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_V1:
@@ -2100,12 +2063,6 @@ out_quotactl:
                OBD_FREE(qctl, qctl_len);
                RETURN(rc);
        }
-       case OBD_IOC_GETNAME_OLD:
-       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;
@@ -2129,17 +2086,8 @@ out_quotactl:
 
                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;
@@ -2320,12 +2268,6 @@ migrate_free:
 
                RETURN(rc);
        }
-       case FS_IOC_FSGETXATTR:
-               RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
-       case FS_IOC_FSSETXATTR:
-               RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
-       case LL_IOC_PROJECT:
-               RETURN(ll_ioctl_project(file, cmd, uarg));
        case LL_IOC_PCC_DETACH_BY_FID: {
                struct lu_pcc_detach_fid *detach;
                struct lu_fid *fid;
@@ -2361,38 +2303,10 @@ out_detach:
                OBD_FREE_PTR(detach);
                RETURN(rc);
        }
-#ifdef HAVE_LUSTRE_CRYPTO
-       case LL_IOC_SET_ENCRYPTION_POLICY:
-               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
-                       return -EOPNOTSUPP;
-               return llcrypt_ioctl_set_policy(file, uarg);
-       case LL_IOC_GET_ENCRYPTION_POLICY_EX:
-               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
-                       return -EOPNOTSUPP;
-               return llcrypt_ioctl_get_policy_ex(file, uarg);
-       case LL_IOC_ADD_ENCRYPTION_KEY:
-               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
-                       return -EOPNOTSUPP;
-               rc = llcrypt_ioctl_add_key(file, uarg);
-#ifdef CONFIG_LL_ENCRYPTION
-               if (!rc)
-                       sptlrpc_enc_pool_add_user();
-#endif
-               return rc;
-       case LL_IOC_REMOVE_ENCRYPTION_KEY:
-               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
-                       return -EOPNOTSUPP;
-               return llcrypt_ioctl_remove_key(file, uarg);
-       case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
-               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
-                       return -EOPNOTSUPP;
-               return llcrypt_ioctl_remove_key_all_users(file, uarg);
-       case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
-               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
-                       return -EOPNOTSUPP;
-               return llcrypt_ioctl_get_key_status(file, uarg);
-#endif
        default:
+               rc = ll_iocontrol(inode, file, cmd, uarg);
+               if (rc != -ENOTTY)
+                       RETURN(rc);
                RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL, uarg));
        }
 }
index 9428738..70c55e8 100644 (file)
@@ -2579,11 +2579,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 (!capable(CAP_SYS_ADMIN))
@@ -2591,7 +2590,7 @@ static int ll_lov_setea(struct inode *inode, struct file *file,
 
        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);
@@ -4259,39 +4258,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;
@@ -4307,23 +4277,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_GETNAME_OLD:
-       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;
@@ -4559,14 +4512,6 @@ out_ladvise:
                fd->fd_designated_mirror = arg;
                RETURN(0);
        }
-       case FS_IOC_FSGETXATTR:
-               RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
-       case FS_IOC_FSSETXATTR:
-               RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
-       case LL_IOC_PROJECT:
-               RETURN(ll_ioctl_project(file, cmd, uarg));
-       case BLKSSZGET:
-               RETURN(put_user(PAGE_SIZE, (int __user *)arg));
        case LL_IOC_HEAT_GET: {
                struct lu_heat uheat;
                struct lu_heat *heat;
@@ -4641,47 +4586,10 @@ out_state:
                OBD_FREE_PTR(state);
                RETURN(rc);
        }
-#ifdef HAVE_LUSTRE_CRYPTO
-       case LL_IOC_SET_ENCRYPTION_POLICY:
-               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
-                       return -EOPNOTSUPP;
-               return llcrypt_ioctl_set_policy(file, uarg);
-       case LL_IOC_GET_ENCRYPTION_POLICY_EX:
-               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
-                       return -EOPNOTSUPP;
-               return llcrypt_ioctl_get_policy_ex(file, uarg);
-       case LL_IOC_ADD_ENCRYPTION_KEY:
-               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
-                       return -EOPNOTSUPP;
-               return llcrypt_ioctl_add_key(file, uarg);
-       case LL_IOC_REMOVE_ENCRYPTION_KEY:
-               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
-                       return -EOPNOTSUPP;
-               return llcrypt_ioctl_remove_key(file, uarg);
-       case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
-               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
-                       return -EOPNOTSUPP;
-               return llcrypt_ioctl_remove_key_all_users(file, uarg);
-       case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
-               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
-                       return -EOPNOTSUPP;
-               return llcrypt_ioctl_get_key_status(file, uarg);
-#endif
-
-       case LL_IOC_UNLOCK_FOREIGN: {
-               struct dentry *dentry = file_dentry(file);
-
-               /* if not a foreign symlink do nothing */
-               if (ll_foreign_is_removable(dentry, true)) {
-                       CDEBUG(D_INFO,
-                              "prevent unlink of non-foreign file ("DFID")\n",
-                              PFID(ll_inode2fid(inode)));
-                       RETURN(-EOPNOTSUPP);
-               }
-               RETURN(0);
-       }
-
        default:
+               rc = ll_iocontrol(inode, file, cmd, uarg);
+               if (rc != -ENOTTY)
+                       RETURN(rc);
                RETURN(obd_iocontrol(cmd, ll_i2dtexp(inode), 0, NULL, uarg));
        }
 }
index 59613e5..4fcf0a7 100644 (file)
@@ -2974,6 +2974,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)
 {
@@ -2983,27 +2984,31 @@ int ll_iocontrol(struct inode *inode, struct file *file,
        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;
-
-                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) {
+               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->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;
                /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
@@ -3042,8 +3047,8 @@ int ll_iocontrol(struct inode *inode, struct file *file,
                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);
 
@@ -3061,12 +3066,88 @@ int ll_iocontrol(struct inode *inode, struct file *file,
 
                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 LL_IOC_PROJECT:
+               RETURN(ll_ioctl_project(file, 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);
 
-        RETURN(0);
+               if (put_user(rc, (int __user *)uarg))
+                       RETURN(-EFAULT);
+
+               RETURN(0);
+       }
+       case LL_IOC_FLUSHCTX:
+               RETURN(ll_flush_ctx(inode));
+#ifdef HAVE_LUSTRE_CRYPTO
+       case LL_IOC_ADD_ENCRYPTION_KEY:
+               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
+                       return -EOPNOTSUPP;
+               rc = llcrypt_ioctl_add_key(file, uarg);
+#ifdef CONFIG_LL_ENCRYPTION
+               if (!rc && S_ISDIR(inode->i_mode))
+                       sptlrpc_enc_pool_add_user();
+#endif
+               RETURN(rc);
+       case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
+               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
+                       return -EOPNOTSUPP;
+               RETURN(llcrypt_ioctl_get_key_status(file, uarg));
+       case LL_IOC_GET_ENCRYPTION_POLICY_EX:
+               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
+                       return -EOPNOTSUPP;
+               RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
+       case LL_IOC_SET_ENCRYPTION_POLICY:
+               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
+                       return -EOPNOTSUPP;
+               RETURN(llcrypt_ioctl_set_policy(file, uarg));
+       case LL_IOC_REMOVE_ENCRYPTION_KEY:
+               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
+                       return -EOPNOTSUPP;
+               RETURN(llcrypt_ioctl_remove_key(file, uarg));
+       case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
+               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
+                       return -EOPNOTSUPP;
+               RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
+#endif
+       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 LL_IOC_UNLOCK_FOREIGN: {
+               struct dentry *dentry = file_dentry(file);
+
+               /* if not a foreign symlink do nothing */
+               if (ll_foreign_is_removable(dentry, true)) {
+                       CDEBUG(D_INFO,
+                              "prevent unlink of non-foreign file ("DFID")\n",
+                              PFID(ll_inode2fid(inode)));
+                       RETURN(-EOPNOTSUPP);
+               }
+               RETURN(0);
+       }
+       case OBD_IOC_FID2PATH:
+               RETURN(ll_fid2path(inode, uarg));
+       case OBD_IOC_GETNAME_OLD:
+       case OBD_IOC_GETDTNAME:
+       case OBD_IOC_GETMDNAME:
+               RETURN(ll_get_obd_name(inode, cmd, uarg));
+       default:
+               RETURN(-ENOTTY);
+       }
+
+       RETURN(0);
 }
 
 int ll_flush_ctx(struct inode *inode)