Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1799689rbb; Tue, 27 Feb 2024 01:12:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWwmfqrEJllzmGLwm/73GVTlWpl8MZEbiZSisx1LCBhHCSoClY+Ho1scZ1gL9jadJqN9aIJXOJZwRDyj5pi7XdejBlwO0cJ3UVTHHJjAA== X-Google-Smtp-Source: AGHT+IFsouKsN5EKy6B34036A4uJPiS6GuDJSg6JoD8o2E7Z7R3CxtqTYRR+0NuNAh/cCnsmk/8B X-Received: by 2002:a05:620a:20cf:b0:787:e512:46b4 with SMTP id f15-20020a05620a20cf00b00787e51246b4mr1046980qka.71.1709025135386; Tue, 27 Feb 2024 01:12:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709025135; cv=pass; d=google.com; s=arc-20160816; b=Y1chApwJgPuMuzd8anpRBVUbrPXOQe8MroxFYXrGPk//LzBkS8MGLLOUIQis2VpaR0 v6tiC99bBIr7A6WqTboyikHb7DbZKuQdK+ih1ibc19/TbI991g3mnYvQjSNzJAf2Wt0u gHAqKFJSSY658a153HQmyfcgk4tXVDOyKhPMROnVdCIw8nkqKn6PzMJkG82TGJdrJbaM 492T85YbBUfvT1Wc6W1B7DQhDo1b4MDQrbPng0ZsFWldCsG3vt/jc5u3mHU7hodv0d+Q m9VNrS6uC5LoQ37CDakKIz+dbzBb+wWtaZE/2Nnykc0os1CDUFvAJhqLEv4xP9nWT5XX mDvA== 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=AUYUkliL/rqt22ft9Ezm3s0qi9DsRCfDQuriWQbIQjc=; fh=4vN4thPQ5z49h0k3wc47Ze2ZGwmxH293ZHjdupTAu0I=; b=PGos8iWYw4VKlgumzM7I4j7U9Xkc4OshNfWwbf+5EY7nvj+Dz8bTKLdt6P8AUOwbeA NW5e+9HeSJ0qVi6yVpRXQ4a4513E+yTMfknwQqz1ZVyAyOzIUs+MCZKyEbhFkOtasbG0 /vHyGJY4yNLr+f6TSs4AMuM+pVzg55LastiScdB1ovTy6Vdoz0/453k1YkgACYg3Omhl Grv2al4EfeKd3jiM6yl2z8n9DWjb4z8/jjBMA81Mae4ha2gpyD/vEDHJR0Kut0X/9nlA DwOCgmgsR+7bQ55lLaPGpNYT9r83znXKuWOIt7FLoWPG1XSrVyb79sxdmU15wRDQwMcg zw4w==; 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-kernel+bounces-82920-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82920-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 ya21-20020a05620a5e5500b00787318d29bfsi7077702qkn.217.2024.02.27.01.12.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 01:12:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82920-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-kernel+bounces-82920-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82920-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 7BB081C238FB for ; Tue, 27 Feb 2024 09:11:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3007137C39; Tue, 27 Feb 2024 09:10:13 +0000 (UTC) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 D1D0013666E; Tue, 27 Feb 2024 09:10:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709025013; cv=none; b=eu9cDPWsom2RAaxFxxaONgacSu24I8wn3RTZNS21G96zZI/wBbCMHgWgLFxZcSOMGplpktlDM9jHisiIrEIf5WoFaOOvOE7Np4fx64Cb+sjmnOetf/eWsyraH93kt7PMwEMq4PNif7uY1RrQHJxfxJ5eFVjNucn7kH5yalfX424= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709025013; c=relaxed/simple; bh=GQePeHmLBXBOXIAO3Kr28EekfNyWO9K0IjzdXcsDa/c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UHFqT01zUwTEaJfPnW3NhEURsbznocL+WoxPpyRocqTHNcF4/ijsbxhXlIGWYgA02NAY4TzhZc3ZC0hy0OXjNOOWN9/ae5EC6yw8oOHy28JlzNyfvim/sPKam9mp4CnmPZEHCFQOsk0Kuwo46fd3FZ7As6C+S95yOtdwgFXsqxo= 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.190 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.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4TkWqq2TCbz1xpPH; Tue, 27 Feb 2024 17:08:39 +0800 (CST) Received: from dggpeml500021.china.huawei.com (unknown [7.185.36.21]) by mail.maildlp.com (Postfix) with ESMTPS id 5A2821400F4; Tue, 27 Feb 2024 17:10:08 +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 3/9] ext4: refactor out ext4_generic_attr_show() Date: Tue, 27 Feb 2024 17:11:42 +0800 Message-ID: <20240227091148.178435-4-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-kernel@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_show() to handle the reading of values of various common types, with no functional changes. Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara --- fs/ext4/sysfs.c | 74 +++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 42 deletions(-) diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index 2b1c529b7fdf..7f455b5f22c0 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c @@ -366,13 +366,42 @@ static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi) #define print_tstamp(buf, es, tstamp) \ __print_tstamp(buf, (es)->tstamp, (es)->tstamp ## _hi) +static ssize_t ext4_generic_attr_show(struct ext4_attr *a, + struct ext4_sb_info *sbi, char *buf) +{ + void *ptr = calc_ptr(a, sbi); + + if (!ptr) + return 0; + + switch (a->attr_id) { + case attr_inode_readahead: + case attr_pointer_ui: + if (a->attr_ptr == ptr_ext4_super_block_offset) + return sysfs_emit(buf, "%u\n", le32_to_cpup(ptr)); + return sysfs_emit(buf, "%u\n", *((unsigned int *) ptr)); + case attr_pointer_ul: + return sysfs_emit(buf, "%lu\n", *((unsigned long *) ptr)); + case attr_pointer_u8: + return sysfs_emit(buf, "%u\n", *((unsigned char *) ptr)); + case attr_pointer_u64: + if (a->attr_ptr == ptr_ext4_super_block_offset) + return sysfs_emit(buf, "%llu\n", le64_to_cpup(ptr)); + return sysfs_emit(buf, "%llu\n", *((unsigned long long *) ptr)); + case attr_pointer_string: + return sysfs_emit(buf, "%.*s\n", a->attr_size, (char *) ptr); + case attr_pointer_atomic: + return sysfs_emit(buf, "%d\n", atomic_read((atomic_t *) ptr)); + } + return 0; +} + static ssize_t ext4_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) { 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); switch (a->attr_id) { case attr_delayed_allocation_blocks: @@ -391,45 +420,6 @@ static ssize_t ext4_attr_show(struct kobject *kobj, return sysfs_emit(buf, "%llu\n", (unsigned long long) percpu_counter_sum(&sbi->s_sra_exceeded_retry_limit)); - case attr_inode_readahead: - case attr_pointer_ui: - if (!ptr) - return 0; - if (a->attr_ptr == ptr_ext4_super_block_offset) - return sysfs_emit(buf, "%u\n", - le32_to_cpup(ptr)); - else - return sysfs_emit(buf, "%u\n", - *((unsigned int *) ptr)); - case attr_pointer_ul: - if (!ptr) - return 0; - return sysfs_emit(buf, "%lu\n", - *((unsigned long *) ptr)); - case attr_pointer_u8: - if (!ptr) - return 0; - return sysfs_emit(buf, "%u\n", - *((unsigned char *) ptr)); - case attr_pointer_u64: - if (!ptr) - return 0; - if (a->attr_ptr == ptr_ext4_super_block_offset) - return sysfs_emit(buf, "%llu\n", - le64_to_cpup(ptr)); - else - return sysfs_emit(buf, "%llu\n", - *((unsigned long long *) ptr)); - case attr_pointer_string: - if (!ptr) - return 0; - return sysfs_emit(buf, "%.*s\n", a->attr_size, - (char *) ptr); - case attr_pointer_atomic: - if (!ptr) - return 0; - return sysfs_emit(buf, "%d\n", - atomic_read((atomic_t *) ptr)); case attr_feature: return sysfs_emit(buf, "supported\n"); case attr_first_error_time: @@ -438,9 +428,9 @@ 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); + default: + return ext4_generic_attr_show(a, sbi, buf); } - - return 0; } static ssize_t ext4_generic_attr_store(struct ext4_attr *a, -- 2.31.1