From patchwork Wed Aug 2 08:34:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhanchengbin X-Patchwork-Id: 1815853 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=gandalf.ozlabs.org; envelope-from=srs0=9pqg=dt=vger.kernel.org=linux-ext4-owner@ozlabs.org; receiver=) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RG5283dfmz1ydw for ; Wed, 2 Aug 2023 18:37:20 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4RG5255LkTz4xmJ for ; Wed, 2 Aug 2023 18:37:17 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4RG5255GjDz4xmL; Wed, 2 Aug 2023 18:37:17 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=huawei.com Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4RG5245QYsz4xmJ for ; Wed, 2 Aug 2023 18:37:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232361AbjHBIhQ (ORCPT ); Wed, 2 Aug 2023 04:37:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231613AbjHBIhP (ORCPT ); Wed, 2 Aug 2023 04:37:15 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACAB2173A for ; Wed, 2 Aug 2023 01:37:13 -0700 (PDT) Received: from dggpeml500016.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RG4y15y0PzNmcC; Wed, 2 Aug 2023 16:33:45 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpeml500016.china.huawei.com (7.185.36.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 2 Aug 2023 16:37:11 +0800 From: zhanchengbin To: CC: , , , , , , zhanchengbin Subject: [RFC PATCH 2/2] ext4: ioctl add EXT4_IOC_SUPERBLOCK_KEY_S_ERRORS Date: Wed, 2 Aug 2023 16:34:02 +0800 Message-ID: <20230802083402.515570-3-zhanchengbin1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230802083402.515570-1-zhanchengbin1@huawei.com> References: <20230802083402.515570-1-zhanchengbin1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500016.china.huawei.com (7.185.36.70) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Added modifications to s_errors in the modification framework of superblock's attrs. There is no lock protection when the user mode operates on the same block, so I modify the s_errors by the modification framework of superblock's attrs. The parameters passed in from the user mode will be checked by sb_attr_errors_check first, if the check is passed, It will call buffer_lock in ext4_update_superblocks_fn and use sb_attr_errors_set, so it can ensure the atomicity of a modification. Signed-off-by: zhanchengbin --- fs/ext4/ioctl.c | 22 ++++++++++++++++++++++ include/uapi/linux/ext4.h | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index 76653d855073..81cb403bacf7 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -30,10 +30,32 @@ typedef void ext4_update_sb_callback(struct ext4_super_block *es, const void *arg); +int sb_attr_errors_check(struct ext4_sbattr *p_sbattr) +{ + __u16 error_behavior = *(__u16 *)(p_sbattr->sba_value); + + if (p_sbattr->sba_len != EXT4_IOC_SUPERBLOCK_LEN_S_ERRORS) + return -EINVAL; + + if (error_behavior < EXT4_ERRORS_CONTINUE || + error_behavior > EXT4_ERRORS_PANIC) + return -EINVAL; + + return 0; +} + +void sb_attr_errors_set(struct ext4_super_block *es, const void *arg) +{ + struct ext4_sbattr *p_sbattr = (struct ext4_sbattr *)arg; + + es->s_errors = cpu_to_le16(*(__u16 *)p_sbattr->sba_value); +} + /* * Check and modify functions for each superblock variable */ struct ext4_sbattr_operation ext4_sbattr_ops[] = { + {EXT4_IOC_SUPERBLOCK_KEY_S_ERRORS, sb_attr_errors_check, sb_attr_errors_set}, {EXT4_IOC_SUPERBLOCK_KEY_MAX, NULL, NULL}, }; diff --git a/include/uapi/linux/ext4.h b/include/uapi/linux/ext4.h index a9f33a0399e8..aad2de6528dd 100644 --- a/include/uapi/linux/ext4.h +++ b/include/uapi/linux/ext4.h @@ -90,8 +90,10 @@ struct ext4_sbattr { }; enum ext4_ioc_superblock_key { - EXT4_IOC_SUPERBLOCK_KEY_MAX = 0, + EXT4_IOC_SUPERBLOCK_KEY_S_ERRORS = 0, + EXT4_IOC_SUPERBLOCK_KEY_MAX, }; +#define EXT4_IOC_SUPERBLOCK_LEN_S_ERRORS 2 #define EXT4_SBATTR_MAX_COUNT 20