From f311ce214a55d1899f612c4ef87a126ddef467b3 Mon Sep 17 00:00:00 2001 From: Hongchao Zhang Date: Wed, 9 Mar 2022 11:06:19 -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-by: Bobi Jam Reviewed-by: Andreas Dilger Reviewed-on: https://review.whamcloud.com/46766 Tested-by: jenkins Tested-by: Maloo --- lustre/llite/dir.c | 8 ++++++-- lustre/llite/llite_internal.h | 2 +- lustre/llite/llite_lib.c | 2 +- lustre/tests/sanity-quota.sh | 9 +++++++++ lustre/utils/lfs.c | 3 +++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index 799264a..34ada9e 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -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; diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index 663d401..9e8f328 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -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; diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index 37654a0..638b22d 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -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. diff --git a/lustre/tests/sanity-quota.sh b/lustre/tests/sanity-quota.sh index bd38569..c96b6e5 100755 --- a/lustre/tests/sanity-quota.sh +++ b/lustre/tests/sanity-quota.sh @@ -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) )) || diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index f21bd13..23b7d32 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -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; } -- 1.8.3.1