Whamcloud - gitweb
LU-9555 quota: df should return projid-specific values
[fs/lustre-release.git] / lustre / llite / dir.c
index 007f6cf..ce9758b 100644 (file)
@@ -50,6 +50,7 @@
 #include <obd_support.h>
 #include <obd_class.h>
 #include <uapi/linux/lustre/lustre_ioctl.h>
+#include <uapi/linux/llcrypt.h>
 #include <lustre_lib.h>
 #include <lustre_dlm.h>
 #include <lustre_fid.h>
@@ -175,29 +176,6 @@ void ll_release_page(struct inode *inode, struct page *page,
        put_page(page);
 }
 
-/**
- * return IF_* type for given lu_dirent entry.
- * IF_* flag shld be converted to particular OS file type in
- * platform llite module.
- */
-static u16 ll_dirent_type_get(struct lu_dirent *ent)
-{
-       u16 type = 0;
-       struct luda_type *lt;
-       int len = 0;
-
-       if (le32_to_cpu(ent->lde_attrs) & LUDA_TYPE) {
-               const unsigned align = sizeof(struct luda_type) - 1;
-
-               len = le16_to_cpu(ent->lde_namelen);
-               len = (len + align) & ~align;
-               lt = (void *)ent->lde_name + len;
-               type = IFTODT(le16_to_cpu(lt->lt_type));
-       }
-
-       return type;
-}
-
 #ifdef HAVE_DIR_CONTEXT
 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
                struct dir_context *ctx)
@@ -256,7 +234,7 @@ int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
                                lhash = hash;
                        fid_le_to_cpu(&fid, &ent->lde_fid);
                        ino = cl_fid_build_ino(&fid, is_api32);
-                       type = ll_dirent_type_get(ent);
+                       type = IFTODT(lu_dirent_type_get(ent));
                        /* For ll_nfs_get_name_filldir(), it will try to access
                         * 'ent' through 'lde_name', so the parameter 'name'
                         * for 'filldir()' must be part of the 'ent'. */
@@ -440,6 +418,7 @@ static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
                                                  strlen(dirname)),
                },
        };
+       bool encrypt = false;
        int err;
        ENTRY;
 
@@ -499,6 +478,17 @@ static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
        if (IS_ERR(op_data))
                RETURN(PTR_ERR(op_data));
 
+       if (ll_sbi_has_encrypt(sbi) &&
+           (IS_ENCRYPTED(parent) ||
+           unlikely(llcrypt_dummy_context_enabled(parent)))) {
+               err = llcrypt_get_encryption_info(parent);
+               if (err)
+                       GOTO(out_op_data, err);
+               if (!llcrypt_has_encryption_key(parent))
+                       GOTO(out_op_data, err = -ENOKEY);
+               encrypt = true;
+       }
+
        if (sbi->ll_flags & LL_SBI_FILE_SECCTX) {
                /* selinux_dentry_init_security() uses dentry->d_parent and name
                 * to determine the security context for the file. So our fake
@@ -511,6 +501,12 @@ static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
                        GOTO(out_op_data, err);
        }
 
+       if (encrypt) {
+               err = llcrypt_inherit_context(parent, NULL, op_data, false);
+               if (err)
+                       GOTO(out_op_data, err);
+       }
+
        op_data->op_cli_flags |= CLI_SET_MEA;
        err = md_create(sbi->ll_md_exp, op_data, lump, len, mode,
                        from_kuid(&init_user_ns, current_fsuid()),
@@ -528,17 +524,26 @@ static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
        dentry.d_inode = inode;
 
        if (sbi->ll_flags & LL_SBI_FILE_SECCTX) {
-               inode_lock(inode);
+               /* no need to protect selinux_inode_setsecurity() by
+                * inode_lock. Taking it would lead to a client deadlock
+                * LU-13617
+                */
                err = security_inode_notifysecctx(inode,
                                                  op_data->op_file_secctx,
                                                  op_data->op_file_secctx_size);
-               inode_unlock(inode);
        } else {
                err = ll_inode_init_security(&dentry, inode, parent);
        }
        if (err)
                GOTO(out_inode, err);
 
+       if (encrypt) {
+               err = ll_set_encflags(inode, op_data->op_file_encctx,
+                                     op_data->op_file_encctx_size, false);
+               if (err)
+                       GOTO(out_inode, err);
+       }
+
 out_inode:
        if (inode != NULL)
                iput(inode);
@@ -745,10 +750,13 @@ int ll_dir_getstripe_default(struct inode *inode, void **plmm, int *plmm_size,
        rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
                                       &req, valid, 0);
        if (rc == -ENODATA && !fid_is_root(ll_inode2fid(inode)) &&
-           !(valid & (OBD_MD_MEA|OBD_MD_DEFAULT_MEA)) && root_request != NULL)
-               rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
-                                              &root_req, valid,
-                                              GET_DEFAULT_LAYOUT_ROOT);
+           !(valid & (OBD_MD_MEA|OBD_MD_DEFAULT_MEA)) && root_request != NULL){
+               int rc2 = ll_dir_get_default_layout(inode, (void **)&lmm,
+                                                   &lmm_size, &root_req, valid,
+                                                   GET_DEFAULT_LAYOUT_ROOT);
+               if (rc2 == 0)
+                       rc = 0;
+       }
 
        *plmm = lmm;
        *plmm_size = lmm_size;
@@ -1118,14 +1126,15 @@ static int check_owner(int type, int id)
        return 0;
 }
 
-static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
+int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
 {
-        int cmd = qctl->qc_cmd;
-        int type = qctl->qc_type;
-        int id = qctl->qc_id;
-        int valid = qctl->qc_valid;
-        int rc = 0;
-        ENTRY;
+       int cmd = qctl->qc_cmd;
+       int type = qctl->qc_type;
+       int id = qctl->qc_id;
+       int valid = qctl->qc_valid;
+       int rc = 0;
+
+       ENTRY;
 
        switch (cmd) {
        case Q_SETQUOTA:
@@ -1208,13 +1217,21 @@ static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
                if ((cmd == Q_GETQUOTA || cmd == LUSTRE_Q_GETQUOTAPOOL) &&
                    !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
                    !oqctl->qc_dqblk.dqb_curspace) {
-                        struct obd_quotactl *oqctl_tmp;
-
-                        OBD_ALLOC_PTR(oqctl_tmp);
-                        if (oqctl_tmp == NULL)
-                                GOTO(out, rc = -ENOMEM);
-
-                        oqctl_tmp->qc_cmd = Q_GETOQUOTA;
+                       struct obd_quotactl *oqctl_tmp;
+                       int qctl_len = sizeof(*oqctl_tmp) + LOV_MAXPOOLNAME + 1;
+
+                       OBD_ALLOC(oqctl_tmp, qctl_len);
+                       if (oqctl_tmp == NULL)
+                               GOTO(out, rc = -ENOMEM);
+
+                       if (cmd == LUSTRE_Q_GETQUOTAPOOL) {
+                               oqctl_tmp->qc_cmd = LUSTRE_Q_GETQUOTAPOOL;
+                               memcpy(oqctl_tmp->qc_poolname,
+                                      qctl->qc_poolname,
+                                      LOV_MAXPOOLNAME + 1);
+                       } else {
+                               oqctl_tmp->qc_cmd = Q_GETOQUOTA;
+                       }
                         oqctl_tmp->qc_id = oqctl->qc_id;
                         oqctl_tmp->qc_type = oqctl->qc_type;
 
@@ -1227,21 +1244,22 @@ static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
                                 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
                         }
 
-                        /* collect space & inode usage from MDTs */
-                        oqctl_tmp->qc_dqblk.dqb_curspace = 0;
-                        oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
-                        rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
-                        if (!rc || rc == -EREMOTEIO) {
-                                oqctl->qc_dqblk.dqb_curspace +=
-                                        oqctl_tmp->qc_dqblk.dqb_curspace;
-                                oqctl->qc_dqblk.dqb_curinodes =
-                                        oqctl_tmp->qc_dqblk.dqb_curinodes;
-                                oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
-                        } else {
-                                oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
-                        }
+                       /* collect space & inode usage from MDTs */
+                       oqctl_tmp->qc_cmd = Q_GETOQUOTA;
+                       oqctl_tmp->qc_dqblk.dqb_curspace = 0;
+                       oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
+                       rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
+                       if (!rc || rc == -EREMOTEIO) {
+                               oqctl->qc_dqblk.dqb_curspace +=
+                                       oqctl_tmp->qc_dqblk.dqb_curspace;
+                               oqctl->qc_dqblk.dqb_curinodes =
+                                       oqctl_tmp->qc_dqblk.dqb_curinodes;
+                               oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
+                       } else {
+                               oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
+                       }
 
-                        OBD_FREE_PTR(oqctl_tmp);
+                       OBD_FREE(oqctl_tmp, qctl_len);
                 }
 out:
                QCTL_COPY(qctl, oqctl);
@@ -2105,9 +2123,9 @@ migrate_free:
 
                RETURN(rc);
        }
-       case LL_IOC_FSGETXATTR:
+       case FS_IOC_FSGETXATTR:
                RETURN(ll_ioctl_fsgetxattr(inode, cmd, arg));
-       case LL_IOC_FSSETXATTR:
+       case FS_IOC_FSSETXATTR:
                RETURN(ll_ioctl_fssetxattr(inode, cmd, arg));
        case LL_IOC_PCC_DETACH_BY_FID: {
                struct lu_pcc_detach_fid *detach;
@@ -2146,6 +2164,33 @@ 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, (const void __user *)arg);
+       case LL_IOC_GET_ENCRYPTION_POLICY_EX:
+               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
+                       return -EOPNOTSUPP;
+               return llcrypt_ioctl_get_policy_ex(file, (void __user *)arg);
+       case LL_IOC_ADD_ENCRYPTION_KEY:
+               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
+                       return -EOPNOTSUPP;
+               return llcrypt_ioctl_add_key(file, (void __user *)arg);
+       case LL_IOC_REMOVE_ENCRYPTION_KEY:
+               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
+                       return -EOPNOTSUPP;
+               return llcrypt_ioctl_remove_key(file, (void __user *)arg);
+       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,
+                                                         (void __user *)arg);
+       case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
+               if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
+                       return -EOPNOTSUPP;
+               return llcrypt_ioctl_get_key_status(file, (void __user *)arg);
+#endif
        default:
                RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL,
                                     (void __user *)arg));