From patchwork Thu Oct 15 11:32:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Anufriev X-Patchwork-Id: 1382568 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=yandex-team.ru Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=yandex-team.ru header.i=@yandex-team.ru header.a=rsa-sha256 header.s=default header.b=t3nc7Sju; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CBnHk6zKzz9sTK for ; Thu, 15 Oct 2020 22:34:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728481AbgJOLe0 (ORCPT ); Thu, 15 Oct 2020 07:34:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728558AbgJOLeY (ORCPT ); Thu, 15 Oct 2020 07:34:24 -0400 X-Greylist: delayed 66 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 15 Oct 2020 04:34:24 PDT Received: from forwardcorp1p.mail.yandex.net (forwardcorp1p.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b6:217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78EEAC061755 for ; Thu, 15 Oct 2020 04:34:24 -0700 (PDT) Received: from sas1-ec30c78b6c5b.qloud-c.yandex.net (sas1-ec30c78b6c5b.qloud-c.yandex.net [IPv6:2a02:6b8:c14:2704:0:640:ec30:c78b]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id A26A32E037C; Thu, 15 Oct 2020 14:33:14 +0300 (MSK) Received: from sas1-58a37b48fb94.qloud-c.yandex.net (sas1-58a37b48fb94.qloud-c.yandex.net [2a02:6b8:c08:1d1b:0:640:58a3:7b48]) by sas1-ec30c78b6c5b.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id 6nXrIxENpq-XDwK2mjN; Thu, 15 Oct 2020 14:33:14 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1602761594; bh=ejDKbwUm8l9WNB7fFUSrvTLqiu0Jr68y8dUJwU1UsHQ=; h=Message-Id:Date:Subject:To:From:Cc; b=t3nc7SjuZC8LcASh6WLw/UQWWhJcwiDqseFQQHD3NDNX/I2E3VhC4T8UAzgXW/0uR RZiSTJELenxoWau8iZlLyU35I7YIfjbcYdhqvAkUvbV9EZUTdLBUebNjEv6lRr0DJS t0JsX2G0ClIl1TNkovkWoKSwovYYDAJysCe9MzUI= Authentication-Results: sas1-ec30c78b6c5b.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from kernel1.search.yandex.net (kernel1.search.yandex.net [2a02:6b8:c02:550:0:604:9094:6282]) by sas1-58a37b48fb94.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 5auaoVnUe2-XDmGknm4; Thu, 15 Oct 2020 14:33:13 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Roman Anufriev To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, jack@suse.cz, dmtrmonakhov@yandex-team.ru, dotdot@yandex-team.ru Subject: [PATCH 1/2] ext4: add helpers for checking whether quota is enabled/journalled Date: Thu, 15 Oct 2020 14:32:51 +0300 Message-Id: <1602761572-4713-1-git-send-email-dotdot@yandex-team.ru> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Right now, there are several places, where we check whether quota is enabled or journalled with quite long and non-self-descriptive condition statements. This patch wraps these statements into helpers (with naming along with existing ones like sb_has_quota_loaded) for better readability and easier usage. Signed-off-by: Roman Anufriev Reviewed-by: Dmitry Monakhov Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 15 +++++++++++++++ fs/ext4/ext4_jbd2.h | 9 +++------ fs/ext4/super.c | 5 +---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 250e905..217ae7b 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3251,6 +3251,21 @@ static inline void ext4_unlock_group(struct super_block *sb, spin_unlock(ext4_group_lock_ptr(sb, group)); } +#ifdef CONFIG_QUOTA +static inline bool ext4_any_quota_enabled(struct super_block *sb) +{ + return (test_opt(sb, QUOTA) || ext4_has_feature_quota(sb)); +} + +static inline bool ext4_is_quota_journalled(struct super_block *sb) +{ + struct ext4_sb_info *sbi = EXT4_SB(sb); + + return (ext4_has_feature_quota(sb) || + sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]); +} +#endif + /* * Block validity checking */ diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index 00dc668..4a4eb3f 100644 --- a/fs/ext4/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h @@ -86,17 +86,14 @@ #ifdef CONFIG_QUOTA /* Amount of blocks needed for quota update - we know that the structure was * allocated so we need to update only data block */ -#define EXT4_QUOTA_TRANS_BLOCKS(sb) ((test_opt(sb, QUOTA) ||\ - ext4_has_feature_quota(sb)) ? 1 : 0) +#define EXT4_QUOTA_TRANS_BLOCKS(sb) ((ext4_any_quota_enabled(sb)) ? 1 : 0) /* Amount of blocks needed for quota insert/delete - we do some block writes * but inode, sb and group updates are done only once */ -#define EXT4_QUOTA_INIT_BLOCKS(sb) ((test_opt(sb, QUOTA) ||\ - ext4_has_feature_quota(sb)) ?\ +#define EXT4_QUOTA_INIT_BLOCKS(sb) ((ext4_any_quota_enabled(sb)) ?\ (DQUOT_INIT_ALLOC*(EXT4_SINGLEDATA_TRANS_BLOCKS(sb)-3)\ +3+DQUOT_INIT_REWRITE) : 0) -#define EXT4_QUOTA_DEL_BLOCKS(sb) ((test_opt(sb, QUOTA) ||\ - ext4_has_feature_quota(sb)) ?\ +#define EXT4_QUOTA_DEL_BLOCKS(sb) ((ext4_any_quota_enabled(sb)) ?\ (DQUOT_DEL_ALLOC*(EXT4_SINGLEDATA_TRANS_BLOCKS(sb)-3)\ +3+DQUOT_DEL_REWRITE) : 0) #else diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 9d01318..a988cf3 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -6158,11 +6158,8 @@ static int ext4_release_dquot(struct dquot *dquot) static int ext4_mark_dquot_dirty(struct dquot *dquot) { struct super_block *sb = dquot->dq_sb; - struct ext4_sb_info *sbi = EXT4_SB(sb); - /* Are we journaling quotas? */ - if (ext4_has_feature_quota(sb) || - sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { + if (ext4_is_quota_journalled(sb)) { dquot_mark_dquot_dirty(dquot); return ext4_write_dquot(dquot); } else { From patchwork Thu Oct 15 11:32:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Anufriev X-Patchwork-Id: 1382569 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=yandex-team.ru Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=yandex-team.ru header.i=@yandex-team.ru header.a=rsa-sha256 header.s=default header.b=YYZtkOW8; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CBnHq3lZzz9sTL for ; Thu, 15 Oct 2020 22:34:31 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729070AbgJOLea (ORCPT ); Thu, 15 Oct 2020 07:34:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728558AbgJOLe2 (ORCPT ); Thu, 15 Oct 2020 07:34:28 -0400 X-Greylist: delayed 66 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 15 Oct 2020 04:34:27 PDT Received: from forwardcorp1o.mail.yandex.net (forwardcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::193]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6DBFC061755 for ; Thu, 15 Oct 2020 04:34:27 -0700 (PDT) Received: from sas1-ec30c78b6c5b.qloud-c.yandex.net (sas1-ec30c78b6c5b.qloud-c.yandex.net [IPv6:2a02:6b8:c14:2704:0:640:ec30:c78b]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 6858A2E126C; Thu, 15 Oct 2020 14:33:18 +0300 (MSK) Received: from sas1-58a37b48fb94.qloud-c.yandex.net (sas1-58a37b48fb94.qloud-c.yandex.net [2a02:6b8:c08:1d1b:0:640:58a3:7b48]) by sas1-ec30c78b6c5b.qloud-c.yandex.net (mxbackcorp/Yandex) with ESMTP id QoMHH0ecuw-XIwmmqpH; Thu, 15 Oct 2020 14:33:18 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1602761598; bh=wzlVYHmMsgv3eR/Cb2uagafTpDCSyF8dvlbUEmVutA4=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=YYZtkOW8meqYglwC1UZina7124K7bhzBZJkFBEFF3h6Gq/5f4BPWzaIwpZ/HasTYq 5ZwurZeUT0ldPzW6cm9ivud6o3Ur1giKuehwMos5qnKBhjyOlqSbvqkoHFVg6NSm5Q WZWIRCv7tJRxG+oWOsnTV5nhFUUCA03u1Ha71Dzc= Authentication-Results: sas1-ec30c78b6c5b.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from kernel1.search.yandex.net (kernel1.search.yandex.net [2a02:6b8:c02:550:0:604:9094:6282]) by sas1-58a37b48fb94.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 5auaoVnUe2-XHmGoLPj; Thu, 15 Oct 2020 14:33:17 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Roman Anufriev To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, jack@suse.cz, dmtrmonakhov@yandex-team.ru, dotdot@yandex-team.ru Subject: [PATCH 2/2] ext4: export quota journalling mode via sysfs attr quota_mode Date: Thu, 15 Oct 2020 14:32:52 +0300 Message-Id: <1602761572-4713-2-git-send-email-dotdot@yandex-team.ru> In-Reply-To: <1602761572-4713-1-git-send-email-dotdot@yandex-team.ru> References: <1602761572-4713-1-git-send-email-dotdot@yandex-team.ru> Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Right now, it is hard to understand what quota journalling type is enabled: you need to be quite familiar with kernel code and trace it or really understand what different combinations of fs flags/mount options lead to. This patch exports via sysfs attr /sys/fs/ext4//quota_mode current quota jounalling mode, making it easier to check at a glance/in autotests. The semantics is similar to ext4 data journalling modes: * journalled - quota accounting and journaling are enabled * writeback - quota accounting is enabled, but journalling is disabled * none - quota accounting is disabled * disabled - kernel compiled without CONFIG_QUOTA feature Signed-off-by: Roman Anufriev Reviewed-by: Dmitry Monakhov --- fs/ext4/sysfs.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index bfabb79..a46487f 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c @@ -36,6 +36,7 @@ typedef enum { attr_pointer_string, attr_pointer_atomic, attr_journal_task, + attr_quota_mode, } attr_id_t; typedef enum { @@ -140,6 +141,23 @@ static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf) task_pid_vnr(sbi->s_journal->j_task)); } +static ssize_t quota_mode_show(struct ext4_sb_info *sbi, char *buf) +{ +#ifdef CONFIG_QUOTA + struct super_block *sb = sbi->s_buddy_cache->i_sb; + + if (!ext4_any_quota_enabled(sb)) + return snprintf(buf, PAGE_SIZE, "none\n"); + + if (ext4_is_quota_journalled(sb)) + return snprintf(buf, PAGE_SIZE, "journalled\n"); + else + return snprintf(buf, PAGE_SIZE, "writeback\n"); +#else + return snprintf(buf, PAGE_SIZE, "disabled\n"); +#endif +} + #define EXT4_ATTR(_name,_mode,_id) \ static struct ext4_attr ext4_attr_##_name = { \ .attr = {.name = __stringify(_name), .mode = _mode }, \ @@ -248,6 +266,7 @@ EXT4_ATTR(last_error_time, 0444, last_error_time); EXT4_ATTR(journal_task, 0444, journal_task); EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch); EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit); +EXT4_ATTR_FUNC(quota_mode, 0444); static unsigned int old_bump_val = 128; EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val); @@ -296,6 +315,7 @@ static struct attribute *ext4_attrs[] = { #endif ATTR_LIST(mb_prefetch), ATTR_LIST(mb_prefetch_limit), + ATTR_LIST(quota_mode), NULL, }; ATTRIBUTE_GROUPS(ext4); @@ -425,6 +445,8 @@ static ssize_t ext4_attr_show(struct kobject *kobj, return print_tstamp(buf, sbi->s_es, s_last_error_time); case attr_journal_task: return journal_task_show(sbi, buf); + case attr_quota_mode: + return quota_mode_show(sbi, buf); } return 0;