From: Hongchao Zhang Date: Thu, 12 Aug 2021 11:06:45 +0000 (+0800) Subject: LU-14696 llite: check read only mount for setquota X-Git-Tag: 2.14.55~66 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=29e00cecc6019fbdb5bd98511970970ac5ef5318 LU-14696 llite: check read only mount for setquota During setting quota, it should fail if the mount is read-only. Change-Id: I966ac71d0a4a72dcb998f09ffc0f99ae28498e27 Signed-off-by: Hongchao Zhang Reviewed-on: https://review.whamcloud.com/43765 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Bobi Jam Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index e9805e7..1a06c0f 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -1121,8 +1121,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; @@ -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); + + if (sb->s_flags & SB_RDONLY) + RETURN(-EROFS); break; case Q_GETQUOTA: case LUSTRE_Q_GETDEFAULT: @@ -1897,7 +1901,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 c3f8a4e..854ca79 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -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); -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 fec9d10..906b530 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -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; - 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 af8df2e..a0c987d 100755 --- a/lustre/tests/sanity-quota.sh +++ b/lustre/tests/sanity-quota.sh @@ -5061,6 +5061,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'" + quota_fini() { do_nodes $(comma_list $(nodes_list)) \ diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 2f52650..e8aea7b 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -7941,6 +7941,9 @@ quota_type_def: obd_uuid2str(&qctl->obd_uuid), strerror(-rc)); } out: + if (rc) + fprintf(stderr, "setquota failed: %s\n", strerror(-rc)); + free(qctl); return rc; }