From 2422773e37f6cc2b98408e44f95d1f928b546854 Mon Sep 17 00:00:00 2001 From: Hongchao Zhang Date: Wed, 15 Sep 2021 19:44:23 +0800 Subject: [PATCH] LU-14696 llite: check read only mount for setquota 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 Reviewed-on: https://review.whamcloud.com/44923 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- lustre/llite/dir.c | 30 +++++++++++++++++------------- lustre/tests/sanity-quota.sh | 9 +++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index 4f44b59..dd2452a 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -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))) diff --git a/lustre/tests/sanity-quota.sh b/lustre/tests/sanity-quota.sh index 872b81f..f78e0d1 100755 --- a/lustre/tests/sanity-quota.sh +++ b/lustre/tests/sanity-quota.sh @@ -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" -- 1.8.3.1