From nobody Sun Feb 8 19:58:44 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AB501F8905; Fri, 17 Jan 2025 08:28:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102530; cv=none; b=oNY7H0B/e0e0ANf5pmHKFxwx5FPp9oWG/f64q/VlgbsfYaEC17USYVx0mkSaVEcvUrZLVnTK7uuCulaYLXfQOkhd5CpGhZkN+oXJDk/9bbfMGj7SH5E2/lnC6ewYqBhknsIEGfBPQeHoXUGsrJ0eViT26hSOmJ9nXbRl8hBiW4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102530; c=relaxed/simple; bh=pcllArBN6kLj9Y9pr+mTHArbMzo/KMXQwv7Ty0KH2Ow=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KtWrWhZRgwenLA1WNYFmq+Dq6fQuEnzQBvm31NeSmm1bFQj/1EFUh4gkOYKSGCOviDPZR1xB9tnSOzvAqmzaV9bIaqH8Ye9FHEz8tL773o8S0QNAPdZOX3vMGiUloozTn4xstEwsADeUzfVToszjERn+Kuvy5JH8SQDsptJl9Sw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4YZCYN3Shbz4f3jR1; Fri, 17 Jan 2025 16:28:24 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id E97BF1A0AD8; Fri, 17 Jan 2025 16:28:44 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgDHKl+5FIpnZbnIBA--.46013S5; Fri, 17 Jan 2025 16:28:44 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 1/7] ext4: convert EXT4_FLAGS_* defines to enum Date: Fri, 17 Jan 2025 16:23:09 +0800 Message-Id: <20250117082315.2869996-2-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250117082315.2869996-1-libaokun@huaweicloud.com> References: <20250117082315.2869996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHKl+5FIpnZbnIBA--.46013S5 X-Coremail-Antispam: 1UD129KBjvdXoWrurWxAFyUZFW7AFyxJry8AFb_yoWfArbEk3 y7Zr4rGrZxCrnakF1ruryYyry0gw4Iyr4UJFsYgryrXr4UJrW5XryDAryDArn5uF4UWF43 Ar48ZryxtFy8XjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbg8FF20E14v26ryj6rWUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGwA2048vs2IY02 0Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84 ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I2 62IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcV AFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG 0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lw4CEc2x0rVAKj4xxMxkF7I0En4 kS14v26r1q6r43MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E 5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtV W8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY 1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI 0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7V Ujtl1JUUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgAJBWeHbHgT0AACs7 Content-Type: text/plain; charset="utf-8" From: Baokun Li Do away with the defines and use an enum as it's cleaner. Signed-off-by: Baokun Li Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 4e7de7eaa374..612208527512 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2232,9 +2232,11 @@ extern int ext4_feature_set_ok(struct super_block *s= b, int readonly); /* * Superblock flags */ -#define EXT4_FLAGS_RESIZING 0 -#define EXT4_FLAGS_SHUTDOWN 1 -#define EXT4_FLAGS_BDEV_IS_DAX 2 +enum { + EXT4_FLAGS_RESIZING, /* Avoid superblock update and resize race */ + EXT4_FLAGS_SHUTDOWN, /* Prevent access to the file system */ + EXT4_FLAGS_BDEV_IS_DAX /* Current block device support DAX */ +}; =20 static inline int ext4_forced_shutdown(struct super_block *sb) { --=20 2.39.2 From nobody Sun Feb 8 19:58:44 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 622B61F8668; Fri, 17 Jan 2025 08:28:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102531; cv=none; b=s3tuupggHbO02J6weAINVwY+DzdiHFRl6V0uAbIBGIIJcj4oPkcvaOqzSTTGGi+tbD9qaPyJa/WjRDyVhTAqFGlk4rNYQOswd67OrB/RFa+K30n58cHyDJc8g3ZL2CwUCBguTThVl9lWkghp5bN8vHNaro2XP44wlYYNyUeYDbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102531; c=relaxed/simple; bh=OWbLh2CBrTkyKYDKi46Ql+RhGUaZdAbiXQQAqjPe6WE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rAkJskW3wSITxbmMhEKKXq0kHO1pSohZ38yWEyq1I+cVO54Fc4sE6yNnb//qNp/2eASs8y/fRT0m+xE9dGpq5E9aY4JEFkATFrcMUoATdhBpcUbs1tsTI/Lz4AnfyhfoBMsE5OqOgK3HzOSspDvGoXcx8dG6QngArERrpaZIIiI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4YZCYM5HH0z4f3lDh; Fri, 17 Jan 2025 16:28:23 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 6F99E1A0AD8; Fri, 17 Jan 2025 16:28:45 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgDHKl+5FIpnZbnIBA--.46013S6; Fri, 17 Jan 2025 16:28:45 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 2/7] ext4: add EXT4_FLAGS_EMERGENCY_RO bit Date: Fri, 17 Jan 2025 16:23:10 +0800 Message-Id: <20250117082315.2869996-3-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250117082315.2869996-1-libaokun@huaweicloud.com> References: <20250117082315.2869996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHKl+5FIpnZbnIBA--.46013S6 X-Coremail-Antispam: 1UD129KBjvJXoW7uw4fWr1UGF1DJr17Kr4xXrb_yoW8XFWDpa n5CFy0kr4FgF1Uuw47WF18X3Wayw18CaykGr1I9ayYgFW8JryrXFyftFyYqFy09rZ7ZFy7 ZF1FgFyUCw43G37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPq14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AI xVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20x vE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xv r2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4kE6xkIj40Ew7xC0wCY1x0262 kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s02 6c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw 0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvE c7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14 v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x 0JUwZ2fUUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQALBWeKD3IBkAABsP Content-Type: text/plain; charset="utf-8" From: Baokun Li EXT4_FLAGS_EMERGENCY_RO Indicates that the current file system has become read-only due to some error. Compared to SB_RDONLY, setting it does not require a lock because we won't clear it, which avoids over-coupling with vfs freeze. Also, add a helper function ext4_emergency_ro() to check if the bit is set. Signed-off-by: Baokun Li Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 612208527512..c5b775482897 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2235,7 +2235,8 @@ extern int ext4_feature_set_ok(struct super_block *sb= , int readonly); enum { EXT4_FLAGS_RESIZING, /* Avoid superblock update and resize race */ EXT4_FLAGS_SHUTDOWN, /* Prevent access to the file system */ - EXT4_FLAGS_BDEV_IS_DAX /* Current block device support DAX */ + EXT4_FLAGS_BDEV_IS_DAX, /* Current block device support DAX */ + EXT4_FLAGS_EMERGENCY_RO /* Emergency read-only due to fs errors */ }; =20 static inline int ext4_forced_shutdown(struct super_block *sb) @@ -2243,6 +2244,11 @@ static inline int ext4_forced_shutdown(struct super_= block *sb) return test_bit(EXT4_FLAGS_SHUTDOWN, &EXT4_SB(sb)->s_ext4_flags); } =20 +static inline int ext4_emergency_ro(struct super_block *sb) +{ + return test_bit(EXT4_FLAGS_EMERGENCY_RO, &EXT4_SB(sb)->s_ext4_flags); +} + /* * Default values for user and/or group using reserved blocks */ --=20 2.39.2 From nobody Sun Feb 8 19:58:44 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F388A1F8920; Fri, 17 Jan 2025 08:28:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102531; cv=none; b=gH/JpoXHFKrT9DU/fOe5+AD7l+jtUyCAGnMy5Z70Dx37o97EBDb2WxqCcNi7XxpcKWr54k55U9c9Eln/F3dex0Z/2JIJQDg/E/SBrWLwYaHG0ZascG1aPC34KGeJaKq307Nwm1IKuhRoGjxaHE95z4t8vF1x4Y1Cy1tVbqE+IQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102531; c=relaxed/simple; bh=2KakkexL4ciD9ycAIn6rGtEEQmwRvfevB1BHrpZvo50=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RvFcUI1mVcthKH/uy7/zUunJCNubtqp29Wh9RPnISGnF3fwXJCOwekr29hlSc0YqJm7TaadKNXfAcmZThywTwHbdVcSOQxaw0s7GbQul8MJdUnhoBhaehBr1kgMHyN1UfoP/9NavS/ph9he0ijutgh5CTJI4QNQtXcto1c9Mbqo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4YZCYP39Ztz4f3jRC; Fri, 17 Jan 2025 16:28:25 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id DC4151A13C7; Fri, 17 Jan 2025 16:28:45 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgDHKl+5FIpnZbnIBA--.46013S7; Fri, 17 Jan 2025 16:28:45 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 3/7] ext4: add ext4_is_emergency() helper function Date: Fri, 17 Jan 2025 16:23:11 +0800 Message-Id: <20250117082315.2869996-4-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250117082315.2869996-1-libaokun@huaweicloud.com> References: <20250117082315.2869996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHKl+5FIpnZbnIBA--.46013S7 X-Coremail-Antispam: 1UD129KBjvAXoW3Kr18Cw4rAF13uw15KF1xXwb_yoW8XFy7Ao WSqF17KFyIka9IvayxCw48tFyUX398Can5C3s8ZF4qq345Arn8uw17Zw47W3W3Ww4rXFWU J34xJa1UJF48ZrWrn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUO57AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20EY4v20xva j40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r1rM28IrcIa0x kI8VCY1x0267AKxVW5JVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84AC jcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwAKzVCY07xG64k0F24lc7CjxV Aaw2AFwI0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2Iq xVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r 1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY 6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67 AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuY vjfUOnmRUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQALBWeKD3IBkQAAsP Content-Type: text/plain; charset="utf-8" From: Baokun Li Since both SHUTDOWN and EMERGENCY_RO are emergency states of the ext4 file system, and they are checked in similar locations, we have added a helper function, ext4_is_emergency(), to determine whether the current file system is in one of these two emergency states. Then, replace calls to ext4_forced_shutdown() with ext4_is_emergency() in those functions that could potentially trigger write operations. Signed-off-by: Baokun Li Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 9 +++++++++ fs/ext4/ext4_jbd2.c | 6 ++++-- fs/ext4/file.c | 24 ++++++++++++++++------- fs/ext4/fsync.c | 12 ++++-------- fs/ext4/ialloc.c | 5 +++-- fs/ext4/inline.c | 2 +- fs/ext4/inode.c | 47 ++++++++++++++++++++++++++------------------- fs/ext4/mballoc.c | 4 ++-- fs/ext4/mmp.c | 2 +- fs/ext4/namei.c | 20 +++++++++++-------- fs/ext4/page-io.c | 2 +- fs/ext4/super.c | 19 +++++++++--------- 12 files changed, 91 insertions(+), 61 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index c5b775482897..ca01b476e42b 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2249,6 +2249,15 @@ static inline int ext4_emergency_ro(struct super_blo= ck *sb) return test_bit(EXT4_FLAGS_EMERGENCY_RO, &EXT4_SB(sb)->s_ext4_flags); } =20 +static inline int ext4_is_emergency(struct super_block *sb) +{ + if (unlikely(ext4_forced_shutdown(sb))) + return -EIO; + if (unlikely(ext4_emergency_ro(sb))) + return -EROFS; + return 0; +} + /* * Default values for user and/or group using reserved blocks */ diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index da4a82456383..2c4e976360f1 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c @@ -63,12 +63,14 @@ static void ext4_put_nojournal(handle_t *handle) */ static int ext4_journal_check_start(struct super_block *sb) { + int ret; journal_t *journal; =20 might_sleep(); =20 - if (unlikely(ext4_forced_shutdown(sb))) - return -EIO; + ret =3D ext4_is_emergency(sb); + if (unlikely(ret)) + return ret; =20 if (WARN_ON_ONCE(sb_rdonly(sb))) return -EROFS; diff --git a/fs/ext4/file.c b/fs/ext4/file.c index a5205149adba..6db052a87b9b 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -688,10 +688,12 @@ ext4_dax_write_iter(struct kiocb *iocb, struct iov_it= er *from) static ssize_t ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from) { + int ret; struct inode *inode =3D file_inode(iocb->ki_filp); =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) - return -EIO; + ret =3D ext4_is_emergency(inode->i_sb); + if (unlikely(ret)) + return ret; =20 #ifdef CONFIG_FS_DAX if (IS_DAX(inode)) @@ -700,7 +702,6 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_ite= r *from) =20 if (iocb->ki_flags & IOCB_ATOMIC) { size_t len =3D iov_iter_count(from); - int ret; =20 if (len < EXT4_SB(inode->i_sb)->s_awu_min || len > EXT4_SB(inode->i_sb)->s_awu_max) @@ -803,11 +804,16 @@ static const struct vm_operations_struct ext4_file_vm= _ops =3D { =20 static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma) { + int ret; struct inode *inode =3D file->f_mapping->host; struct dax_device *dax_dev =3D EXT4_SB(inode->i_sb)->s_daxdev; =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) - return -EIO; + if (file->f_mode & FMODE_WRITE) + ret =3D ext4_is_emergency(inode->i_sb); + else + ret =3D ext4_forced_shutdown(inode->i_sb) ? -EIO : 0; + if (unlikely(ret)) + return ret; =20 /* * We don't support synchronous mappings for non-DAX files and @@ -881,8 +887,12 @@ static int ext4_file_open(struct inode *inode, struct = file *filp) { int ret; =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) - return -EIO; + if (filp->f_mode & FMODE_WRITE) + ret =3D ext4_is_emergency(inode->i_sb); + else + ret =3D ext4_forced_shutdown(inode->i_sb) ? -EIO : 0; + if (unlikely(ret)) + return ret; =20 ret =3D ext4_sample_last_mounted(inode->i_sb, filp->f_path.mnt); if (ret) diff --git a/fs/ext4/fsync.c b/fs/ext4/fsync.c index b40d3b29f7e5..ee9078a5d098 100644 --- a/fs/ext4/fsync.c +++ b/fs/ext4/fsync.c @@ -132,20 +132,16 @@ int ext4_sync_file(struct file *file, loff_t start, l= off_t end, int datasync) bool needs_barrier =3D false; struct inode *inode =3D file->f_mapping->host; =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) - return -EIO; + ret =3D ext4_is_emergency(inode->i_sb); + if (unlikely(ret)) + return ret; =20 ASSERT(ext4_journal_current_handle() =3D=3D NULL); =20 trace_ext4_sync_file_enter(file, datasync); =20 - if (sb_rdonly(inode->i_sb)) { - /* Make sure that we read updated s_ext4_flags value */ - smp_rmb(); - if (ext4_forced_shutdown(inode->i_sb)) - ret =3D -EROFS; + if (sb_rdonly(inode->i_sb)) goto out; - } =20 if (!EXT4_SB(inode->i_sb)->s_journal) { ret =3D ext4_fsync_nojournal(file, start, end, datasync, diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 21d228073d79..4d0af20fa319 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -951,8 +951,9 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap, sb =3D dir->i_sb; sbi =3D EXT4_SB(sb); =20 - if (unlikely(ext4_forced_shutdown(sb))) - return ERR_PTR(-EIO); + ret2 =3D ext4_is_emergency(sb); + if (unlikely(ret2)) + return ERR_PTR(ret2); =20 ngroups =3D ext4_get_groups_count(sb); trace_ext4_request_inode(dir, mode); diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 3536ca7e4fcc..d44cc9b5589e 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -228,7 +228,7 @@ static void ext4_write_inline_data(struct inode *inode,= struct ext4_iloc *iloc, struct ext4_inode *raw_inode; int cp_len =3D 0; =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) + if (unlikely(ext4_is_emergency(inode->i_sb))) return; =20 BUG_ON(!EXT4_I(inode)->i_inline_off); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 7c54ae5fcbd4..3971e10874eb 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1149,8 +1149,9 @@ static int ext4_write_begin(struct file *file, struct= address_space *mapping, pgoff_t index; unsigned from, to; =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) - return -EIO; + ret =3D ext4_is_emergency(inode->i_sb); + if (unlikely(ret)) + return ret; =20 trace_ext4_write_begin(inode, pos, len); /* @@ -2273,7 +2274,7 @@ static int mpage_map_and_submit_extent(handle_t *hand= le, if (err < 0) { struct super_block *sb =3D inode->i_sb; =20 - if (ext4_forced_shutdown(sb)) + if (ext4_is_emergency(sb)) goto invalidate_dirty_pages; /* * Let the uper layers retry transient errors. @@ -2599,10 +2600,9 @@ static int ext4_do_writepages(struct mpage_da_data *= mpd) * *never* be called, so if that ever happens, we would want * the stack trace. */ - if (unlikely(ext4_forced_shutdown(mapping->host->i_sb))) { - ret =3D -EROFS; + ret =3D ext4_is_emergency(mapping->host->i_sb); + if (unlikely(ret)) goto out_writepages; - } =20 /* * If we have inline data and arrive here, it means that @@ -2817,8 +2817,9 @@ static int ext4_writepages(struct address_space *mapp= ing, int ret; int alloc_ctx; =20 - if (unlikely(ext4_forced_shutdown(sb))) - return -EIO; + ret =3D ext4_is_emergency(sb); + if (unlikely(ret)) + return ret; =20 alloc_ctx =3D ext4_writepages_down_read(sb); ret =3D ext4_do_writepages(&mpd); @@ -2858,8 +2859,9 @@ static int ext4_dax_writepages(struct address_space *= mapping, struct inode *inode =3D mapping->host; int alloc_ctx; =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) - return -EIO; + ret =3D ext4_is_emergency(inode->i_sb); + if (unlikely(ret)) + return ret; =20 alloc_ctx =3D ext4_writepages_down_read(inode->i_sb); trace_ext4_writepages(inode, wbc); @@ -2915,8 +2917,9 @@ static int ext4_da_write_begin(struct file *file, str= uct address_space *mapping, pgoff_t index; struct inode *inode =3D mapping->host; =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) - return -EIO; + ret =3D ext4_is_emergency(inode->i_sb); + if (unlikely(ret)) + return ret; =20 index =3D pos >> PAGE_SHIFT; =20 @@ -5228,8 +5231,9 @@ int ext4_write_inode(struct inode *inode, struct writ= eback_control *wbc) if (WARN_ON_ONCE(current->flags & PF_MEMALLOC)) return 0; =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) - return -EIO; + err =3D ext4_is_emergency(inode->i_sb); + if (unlikely(err)) + return err; =20 if (EXT4_SB(inode->i_sb)->s_journal) { if (ext4_journal_current_handle()) { @@ -5351,8 +5355,9 @@ int ext4_setattr(struct mnt_idmap *idmap, struct dent= ry *dentry, const unsigned int ia_valid =3D attr->ia_valid; bool inc_ivers =3D true; =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) - return -EIO; + error =3D ext4_is_emergency(inode->i_sb); + if (unlikely(error)) + return error; =20 if (unlikely(IS_IMMUTABLE(inode))) return -EPERM; @@ -5796,9 +5801,10 @@ int ext4_mark_iloc_dirty(handle_t *handle, { int err =3D 0; =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) { + err =3D ext4_is_emergency(inode->i_sb); + if (unlikely(err)) { put_bh(iloc->bh); - return -EIO; + return err; } ext4_fc_track_inode(handle, inode); =20 @@ -5822,8 +5828,9 @@ ext4_reserve_inode_write(handle_t *handle, struct ino= de *inode, { int err; =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) - return -EIO; + err =3D ext4_is_emergency(inode->i_sb); + if (unlikely(err)) + return err; =20 err =3D ext4_get_inode_loc(inode, iloc); if (!err) { diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index b25a27c86696..7c783cb2a1dc 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -5653,7 +5653,7 @@ static inline void ext4_mb_show_pa(struct super_block= *sb) { ext4_group_t i, ngroups; =20 - if (ext4_forced_shutdown(sb)) + if (ext4_is_emergency(sb)) return; =20 ngroups =3D ext4_get_groups_count(sb); @@ -5687,7 +5687,7 @@ static void ext4_mb_show_ac(struct ext4_allocation_co= ntext *ac) { struct super_block *sb =3D ac->ac_sb; =20 - if (ext4_forced_shutdown(sb)) + if (ext4_is_emergency(sb)) return; =20 mb_debug(sb, "Can't allocate:" diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index d64c04ed061a..a3ae72ce3aa1 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -162,7 +162,7 @@ static int kmmpd(void *data) memcpy(mmp->mmp_nodename, init_utsname()->nodename, sizeof(mmp->mmp_nodename)); =20 - while (!kthread_should_stop() && !ext4_forced_shutdown(sb)) { + while (!kthread_should_stop() && !ext4_is_emergency(sb)) { if (!ext4_has_feature_mmp(sb)) { ext4_warning(sb, "kmmpd being stopped since MMP feature" " has been disabled."); diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 536d56d15072..72907dd96e6a 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3151,8 +3151,9 @@ static int ext4_rmdir(struct inode *dir, struct dentr= y *dentry) struct ext4_dir_entry_2 *de; handle_t *handle =3D NULL; =20 - if (unlikely(ext4_forced_shutdown(dir->i_sb))) - return -EIO; + retval =3D ext4_is_emergency(dir->i_sb); + if (unlikely(retval)) + return retval; =20 /* Initialize quotas before so that eventual writes go in * separate transaction */ @@ -3309,8 +3310,9 @@ static int ext4_unlink(struct inode *dir, struct dent= ry *dentry) { int retval; =20 - if (unlikely(ext4_forced_shutdown(dir->i_sb))) - return -EIO; + retval =3D ext4_is_emergency(dir->i_sb); + if (unlikely(retval)) + return retval; =20 trace_ext4_unlink_enter(dir, dentry); /* @@ -3376,8 +3378,9 @@ static int ext4_symlink(struct mnt_idmap *idmap, stru= ct inode *dir, struct fscrypt_str disk_link; int retries =3D 0; =20 - if (unlikely(ext4_forced_shutdown(dir->i_sb))) - return -EIO; + err =3D ext4_is_emergency(dir->i_sb); + if (unlikely(err)) + return err; =20 err =3D fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize, &disk_link); @@ -4199,8 +4202,9 @@ static int ext4_rename2(struct mnt_idmap *idmap, { int err; =20 - if (unlikely(ext4_forced_shutdown(old_dir->i_sb))) - return -EIO; + err =3D ext4_is_emergency(old_dir->i_sb); + if (unlikely(err)) + return err; =20 if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT)) return -EINVAL; diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c index 69b8a7221a2b..0e5e1de6b534 100644 --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -183,7 +183,7 @@ static int ext4_end_io_end(ext4_io_end_t *io_end) =20 io_end->handle =3D NULL; /* Following call will use up the handle */ ret =3D ext4_convert_unwritten_io_end_vec(handle, io_end); - if (ret < 0 && !ext4_forced_shutdown(inode->i_sb)) { + if (ret < 0 && !ext4_is_emergency(inode->i_sb)) { ext4_msg(inode->i_sb, KERN_EMERG, "failed to convert unwritten extents to written " "extents -- potential data loss! " diff --git a/fs/ext4/super.c b/fs/ext4/super.c index a50e5c31b937..c12133628ee9 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -819,7 +819,7 @@ void __ext4_error(struct super_block *sb, const char *f= unction, struct va_format vaf; va_list args; =20 - if (unlikely(ext4_forced_shutdown(sb))) + if (unlikely(ext4_is_emergency(sb))) return; =20 trace_ext4_error(sb, function, line); @@ -844,7 +844,7 @@ void __ext4_error_inode(struct inode *inode, const char= *function, va_list args; struct va_format vaf; =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) + if (unlikely(ext4_is_emergency(inode->i_sb))) return; =20 trace_ext4_error(inode->i_sb, function, line); @@ -879,7 +879,7 @@ void __ext4_error_file(struct file *file, const char *f= unction, struct inode *inode =3D file_inode(file); char pathname[80], *path; =20 - if (unlikely(ext4_forced_shutdown(inode->i_sb))) + if (unlikely(ext4_is_emergency(inode->i_sb))) return; =20 trace_ext4_error(inode->i_sb, function, line); @@ -959,7 +959,7 @@ void __ext4_std_error(struct super_block *sb, const cha= r *function, char nbuf[16]; const char *errstr; =20 - if (unlikely(ext4_forced_shutdown(sb))) + if (unlikely(ext4_is_emergency(sb))) return; =20 /* Special case: if the error is EROFS, and we're not already @@ -1053,7 +1053,7 @@ __acquires(bitlock) struct va_format vaf; va_list args; =20 - if (unlikely(ext4_forced_shutdown(sb))) + if (unlikely(ext4_is_emergency(sb))) return; =20 trace_ext4_error(sb, function, line); @@ -6336,8 +6336,9 @@ static int ext4_sync_fs(struct super_block *sb, int w= ait) bool needs_barrier =3D false; struct ext4_sb_info *sbi =3D EXT4_SB(sb); =20 - if (unlikely(ext4_forced_shutdown(sb))) - return -EIO; + ret =3D ext4_is_emergency(sb); + if (unlikely(ret)) + return ret; =20 trace_ext4_sync_fs(sb, wait); flush_workqueue(sbi->rsv_conversion_wq); @@ -6419,7 +6420,7 @@ static int ext4_freeze(struct super_block *sb) */ static int ext4_unfreeze(struct super_block *sb) { - if (ext4_forced_shutdown(sb)) + if (ext4_is_emergency(sb)) return 0; =20 if (EXT4_SB(sb)->s_journal) { @@ -6575,7 +6576,7 @@ static int __ext4_remount(struct fs_context *fc, stru= ct super_block *sb) flush_work(&sbi->s_sb_upd_work); =20 if ((bool)(fc->sb_flags & SB_RDONLY) !=3D sb_rdonly(sb)) { - if (ext4_forced_shutdown(sb)) { + if (ext4_is_emergency(sb)) { err =3D -EROFS; goto restore_opts; } --=20 2.39.2 From nobody Sun Feb 8 19:58:44 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F5BD1F8929; Fri, 17 Jan 2025 08:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102532; cv=none; b=tEN7jLzEeBRWgb+B3fyJjwNNO9XFgTEBW6OvMC0Jo+i/lUrjjMhBHV4cL8EZpitOBcBqBNoCoMqTLzDEsLLALxCkA/18Hnh/T+scO4BYlsj5LA87na9Filxltbuq3/EUF2TkUjP6jUcu+NpTID2coUI61TJ6quncWcNjrCxum1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102532; c=relaxed/simple; bh=BSUDrswNPQuPsEB6ImGQqdtp5+65EUxWIdLv13OWBNo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IPgZJ4b0dhDWqdD2kvxgo2fB8fs/223O18qTDj2FX4HLQIIQ4dV04Kj73Z31cvIK2jxk+Ntz8NCuq8PCz7naCn4gEfZYM3JR4A+j/Y/uc2pSWDTDcNqnYP9pha7iZtIGoekGIHFw0BqJoGLR8X8/1cjL1NHcLqD3+nhnE+AIn4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=none smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4YZCYW0v9pz4f3jqx; Fri, 17 Jan 2025 16:28:31 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 62B831A13C7; Fri, 17 Jan 2025 16:28:46 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgDHKl+5FIpnZbnIBA--.46013S8; Fri, 17 Jan 2025 16:28:46 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 4/7] ext4: add ext4_sb_rdonly() helper function Date: Fri, 17 Jan 2025 16:23:12 +0800 Message-Id: <20250117082315.2869996-5-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250117082315.2869996-1-libaokun@huaweicloud.com> References: <20250117082315.2869996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHKl+5FIpnZbnIBA--.46013S8 X-Coremail-Antispam: 1UD129KBjvJXoWxurWfCw4xurWkCry8tw48tFb_yoWrtF1fpr s8CFy09F4j9F1DuwsrGFWUXw1agw40ya4jkrW5Cr1rXry5trn5AF4UtF1YvF17J398uF1f uF4jyrW7Wrs7CrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPl14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr 1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4kE6xkIj40Ew7xC0wCY1x 0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC2 0s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI 0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv2 0xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2js IE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZF pf9x0JU9Aw3UUUUU= X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgALBWeKD3kBggACsW Content-Type: text/plain; charset="utf-8" From: Baokun Li Because both SB_RDONLY and EXT4_FLAGS_EMERGENCY_RO indicate the file system is read-only, the ext4_sb_rdonly() helper function is added. This function returns true if either flag is set, signifying that the file system is read-only. Then replace some sb_rdonly() with ext4_sb_rdonly() to avoid unexpected failures of some read-only operations or modification of the superblock after setting EXT4_FLAGS_EMERGENCY_RO. Signed-off-by: Baokun Li --- fs/ext4/ext4.h | 5 +++++ fs/ext4/file.c | 2 +- fs/ext4/ioctl.c | 2 +- fs/ext4/super.c | 17 +++++++++-------- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index ca01b476e42b..610c18036dc8 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2258,6 +2258,11 @@ static inline int ext4_is_emergency(struct super_blo= ck *sb) return 0; } =20 +static inline int ext4_sb_rdonly(struct super_block *sb) +{ + return sb_rdonly(sb) || ext4_emergency_ro(sb); +} + /* * Default values for user and/or group using reserved blocks */ diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 6db052a87b9b..70b556c87b88 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -844,7 +844,7 @@ static int ext4_sample_last_mounted(struct super_block = *sb, if (likely(ext4_test_mount_flag(sb, EXT4_MF_MNTDIR_SAMPLED))) return 0; =20 - if (sb_rdonly(sb) || !sb_start_intwrite_trylock(sb)) + if (ext4_sb_rdonly(sb) || !sb_start_intwrite_trylock(sb)) return 0; =20 ext4_set_mount_flag(sb, EXT4_MF_MNTDIR_SAMPLED); diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index 7b9ce71c1c81..0807ee8cbcdc 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -1705,7 +1705,7 @@ int ext4_update_overhead(struct super_block *sb, bool= force) { struct ext4_sb_info *sbi =3D EXT4_SB(sb); =20 - if (sb_rdonly(sb)) + if (ext4_sb_rdonly(sb)) return 0; if (!force && (sbi->s_overhead =3D=3D 0 || diff --git a/fs/ext4/super.c b/fs/ext4/super.c index c12133628ee9..fc5d30123f22 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -473,7 +473,7 @@ static void ext4_maybe_update_superblock(struct super_b= lock *sb) __u64 lifetime_write_kbytes; __u64 diff_size; =20 - if (sb_rdonly(sb) || !(sb->s_flags & SB_ACTIVE) || + if (ext4_sb_rdonly(sb) || !(sb->s_flags & SB_ACTIVE) || !journal || (journal->j_flags & JBD2_UNMOUNT)) return; =20 @@ -707,7 +707,7 @@ static void ext4_handle_error(struct super_block *sb, b= ool force_ro, int error, if (test_opt(sb, WARN_ON_ERROR)) WARN_ON_ONCE(1); =20 - if (!continue_fs && !sb_rdonly(sb)) { + if (!continue_fs && !ext4_sb_rdonly(sb)) { set_bit(EXT4_FLAGS_SHUTDOWN, &EXT4_SB(sb)->s_ext4_flags); if (journal) jbd2_journal_abort(journal, -EIO); @@ -737,7 +737,7 @@ static void ext4_handle_error(struct super_block *sb, b= ool force_ro, int error, sb->s_id); } =20 - if (sb_rdonly(sb) || continue_fs) + if (ext4_sb_rdonly(sb) || continue_fs) return; =20 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only"); @@ -765,7 +765,7 @@ static void update_super_work(struct work_struct *work) * We use directly jbd2 functions here to avoid recursing back into * ext4 error handling code during handling of previous errors. */ - if (!sb_rdonly(sbi->s_sb) && journal) { + if (!ext4_sb_rdonly(sbi->s_sb) && journal) { struct buffer_head *sbh =3D sbi->s_sbh; bool call_notify_err =3D false; =20 @@ -1325,12 +1325,12 @@ static void ext4_put_super(struct super_block *sb) ext4_mb_release(sb); ext4_ext_release(sb); =20 - if (!sb_rdonly(sb) && !aborted) { + if (!ext4_sb_rdonly(sb) && !aborted) { ext4_clear_feature_journal_needs_recovery(sb); ext4_clear_feature_orphan_present(sb); es->s_state =3D cpu_to_le16(sbi->s_mount_state); } - if (!sb_rdonly(sb)) + if (!ext4_sb_rdonly(sb)) ext4_commit_super(sb); =20 ext4_group_desc_free(sbi); @@ -3693,7 +3693,8 @@ static int ext4_run_li_request(struct ext4_li_request= *elr) if (group >=3D elr->lr_next_group) { ret =3D 1; if (elr->lr_first_not_zeroed !=3D ngroups && - !sb_rdonly(sb) && test_opt(sb, INIT_INODE_TABLE)) { + !ext4_sb_rdonly(sb) && + test_opt(sb, INIT_INODE_TABLE)) { elr->lr_next_group =3D elr->lr_first_not_zeroed; elr->lr_mode =3D EXT4_LI_MODE_ITABLE; ret =3D 0; @@ -3998,7 +3999,7 @@ int ext4_register_li_request(struct super_block *sb, goto out; } =20 - if (sb_rdonly(sb) || + if (ext4_sb_rdonly(sb) || (test_opt(sb, NO_PREFETCH_BLOCK_BITMAPS) && (first_not_zeroed =3D=3D ngroups || !test_opt(sb, INIT_INODE_TABLE))= )) goto out; --=20 2.39.2 From nobody Sun Feb 8 19:58:44 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 014EF1F8922; Fri, 17 Jan 2025 08:28:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102532; cv=none; b=VlZwbiyhWq79zwZNgxbnUyOSvCmVSptI5aDqKKJIKFrIEDZ2pRwuqPGfcpQ88sZtDFtmuaOw3sJJc+4GtbqqLJXVYbehczrLvnZtXT0qVNC2hcsPehilUGFKOxKgoz6++Jx5WyEkLcXsAXx7TUskJjhSaQpBof1QT9b6ZwsW8YA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102532; c=relaxed/simple; bh=FB0gESHxwMdQ69uZNbzlzp81Ufa4xiL2O6BYs2iAwYM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aqwx9RW27mKdPl2eQvW25boSra9rAnmQ2qm9WKOC6eeESzPldois3VGtzHmqK6FCrON8H2f6G9HVL1xpE7Ji4LMTHZTzFNZAt1+AeUYyaMMbb55/5blk9bwZbP9paGy3VSnTSeb6gUjtWWPHwj4xr0rj3NupAgdfBH/2zy7U/t0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4YZCYQ2Hczz4f3jRG; Fri, 17 Jan 2025 16:28:26 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id BF7321A1518; Fri, 17 Jan 2025 16:28:46 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgDHKl+5FIpnZbnIBA--.46013S9; Fri, 17 Jan 2025 16:28:46 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 5/7] ext4: correct behavior under errors=remount-ro mode Date: Fri, 17 Jan 2025 16:23:13 +0800 Message-Id: <20250117082315.2869996-6-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250117082315.2869996-1-libaokun@huaweicloud.com> References: <20250117082315.2869996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHKl+5FIpnZbnIBA--.46013S9 X-Coremail-Antispam: 1UD129KBjvJXoW7Cw1UZF1rWFWxCFy3CFy8Xwb_yoW8tr47pF WrC3WkZrWvvF109a9rWayxXa429a10kFWUCr4I934xXrW5Arn3Zr48tF1Y9FyvgrWxWFyY qr1xKry7u3y3CrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPC14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwAKzVCY07xG64k0F24lc7 CjxVAaw2AFwI0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l x2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14 v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IY x2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z2 80aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI 43ZEXa7VUbT7KDUUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQALBWeKD3IBkwAAsN Content-Type: text/plain; charset="utf-8" From: Baokun Li And after commit 95257987a638 ("ext4: drop EXT4_MF_FS_ABORTED flag") in v6.6-rc1, the EXT4_FLAGS_SHUTDOWN bit is set in ext4_handle_error() under errors=3Dremount-ro mode. This causes the read to fail even when the error is triggered in errors=3Dremount-ro mode. To correct the behavior under errors=3Dremount-ro, EXT4_FLAGS_SHUTDOWN is replaced by the newly introduced EXT4_FLAGS_EMERGENCY_RO. This new flag only prevents writes, matching the previous behavior with SB_RDONLY. Fixes: 95257987a638 ("ext4: drop EXT4_MF_FS_ABORTED flag") Closes: https://lore.kernel.org/all/22d652f6-cb3c-43f5-b2fe-0a4bb6516a04@hu= awei.com/ Suggested-by: Jan Kara Signed-off-by: Baokun Li --- fs/ext4/super.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index fc5d30123f22..8d9ac8770764 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -707,11 +707,8 @@ static void ext4_handle_error(struct super_block *sb, = bool force_ro, int error, if (test_opt(sb, WARN_ON_ERROR)) WARN_ON_ONCE(1); =20 - if (!continue_fs && !ext4_sb_rdonly(sb)) { - set_bit(EXT4_FLAGS_SHUTDOWN, &EXT4_SB(sb)->s_ext4_flags); - if (journal) - jbd2_journal_abort(journal, -EIO); - } + if (!continue_fs && !ext4_sb_rdonly(sb) && journal) + jbd2_journal_abort(journal, -EIO); =20 if (!bdev_read_only(sb->s_bdev)) { save_error_info(sb, error, ino, block, func, line); @@ -741,13 +738,7 @@ static void ext4_handle_error(struct super_block *sb, = bool force_ro, int error, return; =20 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only"); - /* - * EXT4_FLAGS_SHUTDOWN was set which stops all filesystem - * modifications. We don't set SB_RDONLY because that requires - * sb->s_umount semaphore and setting it without proper remount - * procedure is confusing code such as freeze_super() leading to - * deadlocks and other problems. - */ + set_bit(EXT4_FLAGS_EMERGENCY_RO, &EXT4_SB(sb)->s_ext4_flags); } =20 static void update_super_work(struct work_struct *work) --=20 2.39.2 From nobody Sun Feb 8 19:58:44 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F6121F8939; Fri, 17 Jan 2025 08:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102532; cv=none; b=Xqg+Oi3b4tb0i7Gpgzn/T9tMxgoAkAKENJIo9KTWHLUkdfSU13AmN8qWxk7EsHAkHRVQ4giPcIjk6YmjHPH4Xly8LjmRuMmJV6kDDKAOp6bCNMAEtL0gds+2vPDLbFi5f9DRqe6SxzL3bvIxW17G2UEGUTdzE0rSdlMgMJ6ippk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102532; c=relaxed/simple; bh=xfGXfsxmB5VjpQQB4pkLzmNVWlcWyIKhKeFCT4Rn3EE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z3DG3u1454PE26+4hiK41EThgETaWScMVvK6bS0+k2ChxCavaOsvhxQTDi81SVak0D3fg1iHTrVLYrOMNfqiesbwIJpFBS3+XCG/bEmMo1z//tsBU3HAYBCkiHiUxosGaDyYCr6c+TQtGBh77UoP6tBlH1aFobZyP+Rplw/90Sk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4YZCYQ67HMz4f3jR3; Fri, 17 Jan 2025 16:28:26 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 4F3F21A13C7; Fri, 17 Jan 2025 16:28:47 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgDHKl+5FIpnZbnIBA--.46013S10; Fri, 17 Jan 2025 16:28:47 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 6/7] ext4: show 'emergency_ro' when EXT4_FLAGS_EMERGENCY_RO is set Date: Fri, 17 Jan 2025 16:23:14 +0800 Message-Id: <20250117082315.2869996-7-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250117082315.2869996-1-libaokun@huaweicloud.com> References: <20250117082315.2869996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHKl+5FIpnZbnIBA--.46013S10 X-Coremail-Antispam: 1UD129KBjvJXoWrKFy3ArWUZFy8tFWkKr1xXwb_yoW8Jr4Dp3 ZYkwn7Gr9YvF18CanrGay8W34Fgw1SkayUGrWS9w43KryYq34v934xKryFgFy8urZ8W3s0 gF1I9ry7XrW5CwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPC14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwAKzVCY07xG64k0F24lc7 CjxVAaw2AFwI0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l x2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14 v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IY x2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z2 80aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI 43ZEXa7VUbT7KDUUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQALBWeKD3IBlAAAsK Content-Type: text/plain; charset="utf-8" From: Baokun Li After commit d3476f3dad4a ("ext4: don't set SB_RDONLY after filesystem errors") in v6.12-rc1, the 'errors=3Dremount-ro' mode no longer sets SB_RDONLY on errors, which results in us seeing the filesystem is still in rw state after errors. Therefore, after setting EXT4_FLAGS_EMERGENCY_RO, display the emergency_ro option so that users can query whether the current file system has become emergency read-only due to errors through commands such as 'mount' or 'cat /proc/fs/ext4/sdx/options'. Fixes: d3476f3dad4a ("ext4: don't set SB_RDONLY after filesystem errors") Signed-off-by: Baokun Li Reviewed-by: Jan Kara --- fs/ext4/super.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 8d9ac8770764..2377ebf0aff1 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3029,6 +3029,9 @@ static int _ext4_show_options(struct seq_file *seq, s= truct super_block *sb, if (nodefs && !test_opt(sb, NO_PREFETCH_BLOCK_BITMAPS)) SEQ_OPTS_PUTS("prefetch_block_bitmaps"); =20 + if (ext4_emergency_ro(sb)) + SEQ_OPTS_PUTS("emergency_ro"); + ext4_show_quota_options(seq, sb); return 0; } --=20 2.39.2 From nobody Sun Feb 8 19:58:44 2026 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F67A1F8AC1; Fri, 17 Jan 2025 08:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102532; cv=none; b=mKMP5hflcugLZR/kx1JYSI7Z9toj/CvWf3FhYN7K5lmP4ZrY/4cLy/2dty/CVVxz41iKgUP7hCUSY79dbpPeyRqoyc0ZvB+x/0V91V2VMKrYu9ElbnpYxsza0oEgfqZzZOAUwL1ScDcT0jp11ggW3TIL6zO3YEr/1a11x2C+i7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737102532; c=relaxed/simple; bh=Ek3Sl+5WMSS74V1QklldqLln5s6Se8qKoZ3+CnrEkzI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nNAhKikPX+t0n1s9HeDGbWVBYFuKPSNU9oainbAnSSyeLHnW+/pxAvDoO2QqdDcfj0VT2gNBcmEcLxdohTLTFNtX+tSUUsd3m6LbD+ye5euSLq9Jgkp71TGew95W4bqILATAFFOeg0Wi+B8Qyjw6HoXfkxp579YT646kPGTby80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4YZCYX3L5rz4f3jqx; Fri, 17 Jan 2025 16:28:32 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id B65041A13C7; Fri, 17 Jan 2025 16:28:47 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgDHKl+5FIpnZbnIBA--.46013S11; Fri, 17 Jan 2025 16:28:47 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 7/7] ext4: show 'shutdown' hint when ext4 is forced to shutdown Date: Fri, 17 Jan 2025 16:23:15 +0800 Message-Id: <20250117082315.2869996-8-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20250117082315.2869996-1-libaokun@huaweicloud.com> References: <20250117082315.2869996-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgDHKl+5FIpnZbnIBA--.46013S11 X-Coremail-Antispam: 1UD129KBjvdXoWrZr1fZF48GFWDuFWUKr1DGFg_yoWDurX_Z3 yfGan3XanxCws2y3W8CFW5XrZIkFs2vw15Xr93tryrXw15X3y8JF1DJrW8Ar1fWaySgr98 AFsavF1DXFyxujkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbyxFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAVCq3wA2048vs2 IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28E F7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr 1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0D M2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjx v20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1l F7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4kE6xkIj40Ew7xC0wCY1x 0262kKe7AKxVWUtVW8ZwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC2 0s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI 0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv2 0xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87 Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIF yTuYvjfUYl19UUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgALBWeKD3kBggAGsS Content-Type: text/plain; charset="utf-8" From: Baokun Li Now, if dmesg is cleared, we have no way of knowing if the file system has been shutdown. Moreover, ext4 allows directory reads even after the file system has been shutdown, so when reading a file returns -EIO, we cannot determine whether this is a hardware issue or if the file system has been shutdown. Therefore, when ext4 file system is shutdown, we're adding a 'shutdown' hint to commands like mount so users can easily check the file system's status. Signed-off-by: Baokun Li Reviewed-by: Jan Kara --- fs/ext4/super.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 2377ebf0aff1..b15c36df934c 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3032,6 +3032,9 @@ static int _ext4_show_options(struct seq_file *seq, s= truct super_block *sb, if (ext4_emergency_ro(sb)) SEQ_OPTS_PUTS("emergency_ro"); =20 + if (ext4_forced_shutdown(sb)) + SEQ_OPTS_PUTS("shutdown"); + ext4_show_quota_options(seq, sb); return 0; } --=20 2.39.2