Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1800014rbb; Tue, 27 Feb 2024 01:13:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXkXIrhV1d2D1PKRqqm3y9qvjSecGa1plvzl5vKUjbLlKVteJLUaS37ZvV5vlxybBErfk1iUxZ0q0yUPuSMPOReDHOgnJgMe5QMpbljhQ== X-Google-Smtp-Source: AGHT+IHw7zSBkTJhr6zVFcrk+y97R1HoWhO/Sev6Xmxma1IEg/TciPNABzVMfzE1trdZVEJOe8X/ X-Received: by 2002:a05:620a:95c:b0:787:c4b0:a24c with SMTP id w28-20020a05620a095c00b00787c4b0a24cmr2139520qkw.13.1709025190216; Tue, 27 Feb 2024 01:13:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709025190; cv=pass; d=google.com; s=arc-20160816; b=RAIM2yJ643DIIUnqBmNFdNnCGJWS189P34z+rl/in0Ev+qvP6Hh0x9WVnfK3OtQbYq z7y5ZGQlZyJzgZWzDvhhwaIjkkGY02lXnu3H8N9odR29lU2Roy48+Cc+XRth755F0c+Z jdQaLzwWBQBCUsU5eKlvz3idIv3owpdFDf2VXGqPYhT9ED+LdxPMtL660uVRqXoXlLWK dFVhDzOmWZQQfnnOEnf+r2Zv78T/WkP3eQPWeBVsy4pVwvyeOdUVQuV/+MEURfMztxER UUH1esEE/2Nc5OrkivwoRWCLwY99eLimXUBAjqFQmeG4PqxKkA4+I6ZcFjAA3dABJbkX 6w/Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=CqXlCNOtvgirTpc8DYczqq5P0V939PDKgfHzk7Agzrw=; fh=4vN4thPQ5z49h0k3wc47Ze2ZGwmxH293ZHjdupTAu0I=; b=a7vHq1lRunQN+izl3vJDwxnaPyguCPTE1/mkuZ+DTGJWp6tdiaTlk2SAnCIbvaLCRJ JaaV6c9Bwr3Zp4DNr2kZTbImZ63uq7M9uijGLWp71y0mt9zj0rhPoAc6n+QaGibcsIXt a303U1/ApmQyGfuW57hon4uP0AceOi64K+YBOllZnpN+zWHcq0PMGU4hDdCUA/WuFJoY RJrsUnBFOzHkQvGXtgsMaIRxOJfVHtFMg3wTGS4xplKcLxt1ItJHzbD4vSD2zz98j3b4 R14NOI/pJQK/UlUstg9My0ntD8IxFBOEp6b59qiRGCOi0D5rwred+gyyotah+RzWyLwH HQxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-ext4+bounces-1403-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1403-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g22-20020ae9e116000000b00787bb8343c2si6890937qkm.785.2024.02.27.01.13.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 01:13:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1403-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-ext4+bounces-1403-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1403-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id F23341C21488 for ; Tue, 27 Feb 2024 09:13:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5817D13A26F; Tue, 27 Feb 2024 09:10:18 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (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 9115B1384BA; Tue, 27 Feb 2024 09:10:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709025018; cv=none; b=uKZR0e6LsO2Tw44pigITMK/PAwVPZ+++Wwx5yPRzWOY3svBh7dqGG8YPpQxN6zhi9ANrpIyNdpr8/QineIjZKkP7C2HqUKovCP6iFE+Q7adveFyPp8C7xGQHMKYM79/SJYij80fpvXvH4+i5nycctFiyDHJW1PLmGRbVZHCFmAM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709025018; c=relaxed/simple; bh=E3tx3eh+bCVYiHAIXeS50xiX4fCWXiXTC4hITGl7KwU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HiliKwNTXRNy+hUKRpWGIhpY/Q4/SdKvGxaL8rHaDZZI+vNq7QKRDdaI/Pn0EaOioiCjF6ssZobnDV3DzeaI5LhAO9LekqZXJBbeWvQH8O9CUY4J6dBgRHigNBPXnE3MdXYkvisu94upGJ/Ln2EuydyGO4borMWzePYAKHhkfpA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4TkWrq0SZzzqhs5; Tue, 27 Feb 2024 17:09:31 +0800 (CST) Received: from dggpeml500021.china.huawei.com (unknown [7.185.36.21]) by mail.maildlp.com (Postfix) with ESMTPS id C79DA140384; Tue, 27 Feb 2024 17:10:07 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggpeml500021.china.huawei.com (7.185.36.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Tue, 27 Feb 2024 17:10:07 +0800 From: Baokun Li To: CC: , , , , , , , , , Subject: [PATCH v2 2/9] ext4: refactor out ext4_generic_attr_store() Date: Tue, 27 Feb 2024 17:11:41 +0800 Message-ID: <20240227091148.178435-3-libaokun1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240227091148.178435-1-libaokun1@huawei.com> References: <20240227091148.178435-1-libaokun1@huawei.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500021.china.huawei.com (7.185.36.21) Refactor out the function ext4_generic_attr_store() to handle the setting of values of various common types, with no functional changes. Signed-off-by: Baokun Li --- fs/ext4/sysfs.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index ca820620b974..2b1c529b7fdf 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c @@ -443,24 +443,20 @@ static ssize_t ext4_attr_show(struct kobject *kobj, return 0; } -static ssize_t ext4_attr_store(struct kobject *kobj, - struct attribute *attr, - const char *buf, size_t len) +static ssize_t ext4_generic_attr_store(struct ext4_attr *a, + struct ext4_sb_info *sbi, + const char *buf, size_t len) { - struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, - s_kobj); - struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); - void *ptr = calc_ptr(a, sbi); + int ret; unsigned int t; unsigned long lt; - int ret; + void *ptr = calc_ptr(a, sbi); + + if (!ptr) + return 0; switch (a->attr_id) { - case attr_reserved_clusters: - return reserved_clusters_store(sbi, buf, len); case attr_pointer_ui: - if (!ptr) - return 0; ret = kstrtouint(skip_spaces(buf), 0, &t); if (ret) return ret; @@ -470,19 +466,33 @@ static ssize_t ext4_attr_store(struct kobject *kobj, *((unsigned int *) ptr) = t; return len; case attr_pointer_ul: - if (!ptr) - return 0; ret = kstrtoul(skip_spaces(buf), 0, <); if (ret) return ret; *((unsigned long *) ptr) = lt; return len; + } + return 0; +} + +static ssize_t ext4_attr_store(struct kobject *kobj, + struct attribute *attr, + const char *buf, size_t len) +{ + struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info, + s_kobj); + struct ext4_attr *a = container_of(attr, struct ext4_attr, attr); + + switch (a->attr_id) { + case attr_reserved_clusters: + return reserved_clusters_store(sbi, buf, len); case attr_inode_readahead: return inode_readahead_blks_store(sbi, buf, len); case attr_trigger_test_error: return trigger_test_error(sbi, buf, len); + default: + return ext4_generic_attr_store(a, sbi, buf, len); } - return 0; } static void ext4_sb_release(struct kobject *kobj) -- 2.31.1