Whamcloud - gitweb
LU-14696 llite: check read only mount for setquota
authorHongchao Zhang <hongchao@whamcloud.com>
Wed, 9 Mar 2022 19:06:19 +0000 (11:06 -0800)
committerAndreas Dilger <adilger@whamcloud.com>
Thu, 31 Mar 2022 04:19:35 +0000 (04:19 +0000)
During setting quota, it should fail if the mount is read-only.

Lustre-change: https://review.whamcloud.com/43765
Lustre-commit: 29e00cecc6019fbdb5bd98511970970ac5ef5318

Change-Id: I966ac71d0a4a72dcb998f09ffc0f99ae28498e27
Signed-off-by: Hongchao Zhang <hongchao@whamcloud.com>
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/46766
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/llite/dir.c
lustre/llite/llite_internal.h
lustre/llite/llite_lib.c
lustre/tests/sanity-quota.sh
lustre/utils/lfs.c

index 799264a..34ada9e 100644 (file)
@@ -1185,8 +1185,9 @@ static int check_owner(int type, int id)
        return 0;
 }
 
-int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
+int quotactl_ioctl(struct super_block *sb, struct if_quotactl *qctl)
 {
+       struct ll_sb_info *sbi = ll_s2sbi(sb);
        int cmd = qctl->qc_cmd;
        int type = qctl->qc_type;
        int id = qctl->qc_id;
@@ -1205,6 +1206,9 @@ int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
        case LUSTRE_Q_DELETEQID:
                if (!cfs_capable(CFS_CAP_SYS_ADMIN))
                        RETURN(-EPERM);
+
+               if (sb->s_flags & SB_RDONLY)
+                       RETURN(-EROFS);
                break;
        case Q_GETQUOTA:
        case LUSTRE_Q_GETDEFAULT:
@@ -1964,7 +1968,7 @@ out_req:
                                GOTO(out_quotactl, rc = -EFAULT);
                }
 
-               rc = quotactl_ioctl(sbi, qctl);
+               rc = quotactl_ioctl(inode->i_sb, qctl);
                if (rc == 0 &&
                    copy_to_user((void __user *)arg, qctl, sizeof(*qctl)))
                         rc = -EFAULT;
index 663d401..9e8f328 100644 (file)
@@ -1123,7 +1123,7 @@ int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid);
 struct page *ll_get_dir_page(struct inode *dir, struct md_op_data *op_data,
                             __u64 offset, struct ll_dir_chain *chain);
 void ll_release_page(struct inode *inode, struct page *page, bool remove);
-int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl);
+int quotactl_ioctl(struct super_block *sb, struct if_quotactl *qctl);
 
 /* llite/namei.c */
 extern const struct inode_operations ll_special_inode_operations;
index 37654a0..638b22d 100644 (file)
@@ -2371,7 +2371,7 @@ static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
        int ret;
 
        qctl.qc_id = ll_i2info(inode)->lli_projid;
-       ret = quotactl_ioctl(ll_i2sbi(inode), &qctl);
+       ret = quotactl_ioctl(inode->i_sb, &qctl);
        if (ret) {
                /* ignore errors if project ID does not have
                 * a quota limit or feature unsupported.
index bd38569..c96b6e5 100755 (executable)
@@ -5154,6 +5154,15 @@ test_76() {
 }
 run_test 76 "project ID 4294967295 should be not allowed"
 
+test_77()
+{
+       mount_client $MOUNT2 "ro"
+       lfs setquota -u quota_usr -b 100M -B 100M -i 10K -I 10K $MOUNT2 &&
+               error "lfs setquota should fail in read-only Lustre mount"
+       umount $MOUNT2
+}
+run_test 77 "lfs setquota should fail in Lustre mount with 'ro'"
+
 test_78()
 {
        (( $OST1_VERSION >= $(version_code 2.14.0.31) )) ||
index f21bd13..23b7d32 100644 (file)
@@ -7638,6 +7638,9 @@ quota_type_def:
                                progname, strerror(-rc));
        }
 out:
+       if (rc)
+               fprintf(stderr, "setquota failed: %s\n", strerror(-rc));
+
        free(qctl);
        return rc;
 }