Whamcloud - gitweb
LU-14696 llite: check read only mount for setquota 65/43765/6
authorHongchao Zhang <hongchao@whamcloud.com>
Thu, 12 Aug 2021 11:06:45 +0000 (19:06 +0800)
committerOleg Drokin <green@whamcloud.com>
Sat, 11 Sep 2021 06:20:30 +0000 (06:20 +0000)
During setting quota, it should fail if the mount is read-only.

Change-Id: I966ac71d0a4a72dcb998f09ffc0f99ae28498e27
Signed-off-by: Hongchao Zhang <hongchao@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/43765
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@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 e9805e7..1a06c0f 100644 (file)
@@ -1121,8 +1121,9 @@ static int check_owner(int type, int id)
        return 0;
 }
 
        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;
        int cmd = qctl->qc_cmd;
        int type = qctl->qc_type;
        int id = qctl->qc_id;
@@ -1140,6 +1141,9 @@ int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
        case LUSTRE_Q_SETDEFAULT_POOL:
                if (!capable(CAP_SYS_ADMIN))
                        RETURN(-EPERM);
        case LUSTRE_Q_SETDEFAULT_POOL:
                if (!capable(CAP_SYS_ADMIN))
                        RETURN(-EPERM);
+
+               if (sb->s_flags & SB_RDONLY)
+                       RETURN(-EROFS);
                break;
        case Q_GETQUOTA:
        case LUSTRE_Q_GETDEFAULT:
                break;
        case Q_GETQUOTA:
        case LUSTRE_Q_GETDEFAULT:
@@ -1897,7 +1901,7 @@ out_req:
                                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)))
                         rc = -EFAULT;
                if (rc == 0 &&
                    copy_to_user((void __user *)arg, qctl, sizeof(*qctl)))
                         rc = -EFAULT;
index c3f8a4e..854ca79 100644 (file)
@@ -1071,7 +1071,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);
 void ll_release_page(struct inode *inode, struct page *page, bool remove);
 struct page *ll_get_dir_page(struct inode *dir, struct md_op_data *op_data,
                             __u64 offset);
 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;
 
 /* llite/namei.c */
 extern const struct inode_operations ll_special_inode_operations;
index fec9d10..906b530 100644 (file)
@@ -2342,7 +2342,7 @@ static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
        int ret;
 
        qctl.qc_id = ll_i2info(inode)->lli_projid;
        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.
        if (ret) {
                /* ignore errors if project ID does not have
                 * a quota limit or feature unsupported.
index af8df2e..a0c987d 100755 (executable)
@@ -5061,6 +5061,15 @@ test_76() {
 }
 run_test 76 "project ID 4294967295 should be not allowed"
 
 }
 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'"
+
 quota_fini()
 {
        do_nodes $(comma_list $(nodes_list)) \
 quota_fini()
 {
        do_nodes $(comma_list $(nodes_list)) \
index 2f52650..e8aea7b 100644 (file)
@@ -7941,6 +7941,9 @@ quota_type_def:
                                obd_uuid2str(&qctl->obd_uuid), strerror(-rc));
        }
 out:
                                obd_uuid2str(&qctl->obd_uuid), strerror(-rc));
        }
 out:
+       if (rc)
+               fprintf(stderr, "setquota failed: %s\n", strerror(-rc));
+
        free(qctl);
        return rc;
 }
        free(qctl);
        return rc;
 }