From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Yangtao Li <frank.li@vivo.com>
Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to check quota inums
Date: Mon, 6 Mar 2023 12:59:09 -0800 [thread overview]
Message-ID: <ZAZUHQz1GIpPG4jf@google.com> (raw)
In-Reply-To: <20230223073222.81702-1-frank.li@vivo.com>
On 02/23, Yangtao Li wrote:
> We should check quota file ino before enable quota, and not only 0.
>
> BTW fix following check error:
>
> WARNING: Do not crash the kernel unless it is absolutely
> unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible)
> instead of BUG() or variants.
>
> Fixes: ea6767337f86 ("f2fs: support quota sys files")
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
> fs/f2fs/super.c | 54 ++++++++++++++++++++++++++++++++-----------------
> 1 file changed, 36 insertions(+), 18 deletions(-)
>
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index aa55dc12aff2..c7e0639892e2 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -2652,22 +2652,40 @@ int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
> return enabled;
> }
>
> +static inline bool f2fs_check_quota_inum(int type, unsigned long qf_inum)
> +{
> + switch (type) {
> + case USRQUOTA:
> + return qf_inum == 4;
> + case GRPQUOTA:
> + return qf_inum == 5;
> + case PRJQUOTA:
> + return qf_inum == 6;
I don't want to make this dependency of the inode numbers.
> + default:
> + return false;
> + }
> +}
> +
> static int f2fs_quota_enable(struct super_block *sb, int type, int format_id,
> unsigned int flags)
> {
> + struct f2fs_sb_info *sbi = F2FS_SB(sb);
> struct inode *qf_inode;
> unsigned long qf_inum;
> int err;
>
> - BUG_ON(!f2fs_sb_has_quota_ino(F2FS_SB(sb)));
> + f2fs_bug_on(sbi, !f2fs_sb_has_quota_ino(sbi));
>
> qf_inum = f2fs_qf_ino(sb, type);
> - if (!qf_inum)
> - return -EPERM;
> + if (!f2fs_check_quota_inum(type, qf_inum)) {
> + f2fs_err(sbi, "Bad quota inum: %lu, type: %d",
> + qf_inum, type);
> + return -EFSCORRUPTED;
> + }
>
> qf_inode = f2fs_iget(sb, qf_inum);
> if (IS_ERR(qf_inode)) {
> - f2fs_err(F2FS_SB(sb), "Bad quota inode %u:%lu", type, qf_inum);
> + f2fs_err(sbi, "Bad quota inode %u:%lu", type, qf_inum);
> return PTR_ERR(qf_inode);
> }
>
> @@ -2682,7 +2700,7 @@ static int f2fs_enable_quotas(struct super_block *sb)
> {
> struct f2fs_sb_info *sbi = F2FS_SB(sb);
> int type, err = 0;
> - unsigned long qf_inum;
> + char count = MAXQUOTAS;
> bool quota_mopt[MAXQUOTAS] = {
> test_opt(sbi, USRQUOTA),
> test_opt(sbi, GRPQUOTA),
> @@ -2696,21 +2714,21 @@ static int f2fs_enable_quotas(struct super_block *sb)
>
> sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE;
>
> - for (type = 0; type < MAXQUOTAS; type++) {
> - qf_inum = f2fs_qf_ino(sb, type);
> - if (qf_inum) {
> - err = f2fs_quota_enable(sb, type, QFMT_VFS_V1,
> + if (!f2fs_sb_has_project_quota(sbi))
> + count--;
> +
> + for (type = 0; type < count; type++) {
> + err = f2fs_quota_enable(sb, type, QFMT_VFS_V1,
> DQUOT_USAGE_ENABLED |
> (quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0));
> - if (err) {
> - f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.",
> - type, err);
> - for (type--; type >= 0; type--)
> - dquot_quota_off(sb, type);
> - set_sbi_flag(F2FS_SB(sb),
> - SBI_QUOTA_NEED_REPAIR);
> - return err;
> - }
> + if (err) {
> + f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.",
> + type, err);
> + for (type--; type >= 0; type--)
> + dquot_quota_off(sb, type);
> + set_sbi_flag(F2FS_SB(sb),
> + SBI_QUOTA_NEED_REPAIR);
> + return err;
> }
> }
> return 0;
> --
> 2.25.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
WARNING: multiple messages have this Message-ID (diff)
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Yangtao Li <frank.li@vivo.com>
Cc: chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] f2fs: fix to check quota inums
Date: Mon, 6 Mar 2023 12:59:09 -0800 [thread overview]
Message-ID: <ZAZUHQz1GIpPG4jf@google.com> (raw)
In-Reply-To: <20230223073222.81702-1-frank.li@vivo.com>
On 02/23, Yangtao Li wrote:
> We should check quota file ino before enable quota, and not only 0.
>
> BTW fix following check error:
>
> WARNING: Do not crash the kernel unless it is absolutely
> unavoidable--use WARN_ON_ONCE() plus recovery code (if feasible)
> instead of BUG() or variants.
>
> Fixes: ea6767337f86 ("f2fs: support quota sys files")
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
> fs/f2fs/super.c | 54 ++++++++++++++++++++++++++++++++-----------------
> 1 file changed, 36 insertions(+), 18 deletions(-)
>
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index aa55dc12aff2..c7e0639892e2 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -2652,22 +2652,40 @@ int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly)
> return enabled;
> }
>
> +static inline bool f2fs_check_quota_inum(int type, unsigned long qf_inum)
> +{
> + switch (type) {
> + case USRQUOTA:
> + return qf_inum == 4;
> + case GRPQUOTA:
> + return qf_inum == 5;
> + case PRJQUOTA:
> + return qf_inum == 6;
I don't want to make this dependency of the inode numbers.
> + default:
> + return false;
> + }
> +}
> +
> static int f2fs_quota_enable(struct super_block *sb, int type, int format_id,
> unsigned int flags)
> {
> + struct f2fs_sb_info *sbi = F2FS_SB(sb);
> struct inode *qf_inode;
> unsigned long qf_inum;
> int err;
>
> - BUG_ON(!f2fs_sb_has_quota_ino(F2FS_SB(sb)));
> + f2fs_bug_on(sbi, !f2fs_sb_has_quota_ino(sbi));
>
> qf_inum = f2fs_qf_ino(sb, type);
> - if (!qf_inum)
> - return -EPERM;
> + if (!f2fs_check_quota_inum(type, qf_inum)) {
> + f2fs_err(sbi, "Bad quota inum: %lu, type: %d",
> + qf_inum, type);
> + return -EFSCORRUPTED;
> + }
>
> qf_inode = f2fs_iget(sb, qf_inum);
> if (IS_ERR(qf_inode)) {
> - f2fs_err(F2FS_SB(sb), "Bad quota inode %u:%lu", type, qf_inum);
> + f2fs_err(sbi, "Bad quota inode %u:%lu", type, qf_inum);
> return PTR_ERR(qf_inode);
> }
>
> @@ -2682,7 +2700,7 @@ static int f2fs_enable_quotas(struct super_block *sb)
> {
> struct f2fs_sb_info *sbi = F2FS_SB(sb);
> int type, err = 0;
> - unsigned long qf_inum;
> + char count = MAXQUOTAS;
> bool quota_mopt[MAXQUOTAS] = {
> test_opt(sbi, USRQUOTA),
> test_opt(sbi, GRPQUOTA),
> @@ -2696,21 +2714,21 @@ static int f2fs_enable_quotas(struct super_block *sb)
>
> sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE;
>
> - for (type = 0; type < MAXQUOTAS; type++) {
> - qf_inum = f2fs_qf_ino(sb, type);
> - if (qf_inum) {
> - err = f2fs_quota_enable(sb, type, QFMT_VFS_V1,
> + if (!f2fs_sb_has_project_quota(sbi))
> + count--;
> +
> + for (type = 0; type < count; type++) {
> + err = f2fs_quota_enable(sb, type, QFMT_VFS_V1,
> DQUOT_USAGE_ENABLED |
> (quota_mopt[type] ? DQUOT_LIMITS_ENABLED : 0));
> - if (err) {
> - f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.",
> - type, err);
> - for (type--; type >= 0; type--)
> - dquot_quota_off(sb, type);
> - set_sbi_flag(F2FS_SB(sb),
> - SBI_QUOTA_NEED_REPAIR);
> - return err;
> - }
> + if (err) {
> + f2fs_err(sbi, "Failed to enable quota tracking (type=%d, err=%d). Please run fsck to fix.",
> + type, err);
> + for (type--; type >= 0; type--)
> + dquot_quota_off(sb, type);
> + set_sbi_flag(F2FS_SB(sb),
> + SBI_QUOTA_NEED_REPAIR);
> + return err;
> }
> }
> return 0;
> --
> 2.25.1
next prev parent reply other threads:[~2023-03-06 20:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-23 7:32 [f2fs-dev] [PATCH] f2fs: fix to check quota inums Yangtao Li via Linux-f2fs-devel
2023-02-23 7:32 ` Yangtao Li
2023-03-06 20:59 ` Jaegeuk Kim [this message]
2023-03-06 20:59 ` Jaegeuk Kim
2023-04-02 3:16 ` [f2fs-dev] " Chao Yu
2023-04-02 3:16 ` Chao Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZAZUHQz1GIpPG4jf@google.com \
--to=jaegeuk@kernel.org \
--cc=frank.li@vivo.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.