Whamcloud - gitweb
LU-14696 llite: check read only mount for setquota 23/44923/3
authorHongchao Zhang <hongchao@whamcloud.com>
Wed, 15 Sep 2021 11:44:23 +0000 (19:44 +0800)
committerOleg Drokin <green@whamcloud.com>
Mon, 18 Oct 2021 17:16:30 +0000 (17:16 +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-on: https://review.whamcloud.com/44923
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/llite/dir.c
lustre/tests/sanity-quota.sh

index 4f44b59..dd2452a 100644 (file)
@@ -1152,14 +1152,15 @@ static int check_owner(int type, int id)
        return 0;
 }
 
-static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
+static int quotactl_ioctl(struct super_block *sb, 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;
+       struct ll_sb_info *sbi = ll_s2sbi(sb);
+       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:
@@ -1167,6 +1168,9 @@ static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
        case LUSTRE_Q_SETDEFAULT:
                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:
@@ -1840,16 +1844,16 @@ out_req:
                return rc;
        }
        case OBD_IOC_QUOTACTL: {
-                struct if_quotactl *qctl;
+               struct if_quotactl *qctl;
 
-                OBD_ALLOC_PTR(qctl);
-                if (!qctl)
-                        RETURN(-ENOMEM);
+               OBD_ALLOC_PTR(qctl);
+               if (!qctl)
+                       RETURN(-ENOMEM);
 
                if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl)))
-                        GOTO(out_quotactl, rc = -EFAULT);
+                       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)))
index 872b81f..f78e0d1 100755 (executable)
@@ -3588,6 +3588,15 @@ test_66() {
 }
 run_test 66 "nonroot user can not change project state in default"
 
+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'"
+
 quota_fini()
 {
        do_nodes $(comma_list $(nodes_list)) "lctl set_param debug=-quota"