From patchwork Sun Mar 6 18:14:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 12770879 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CF96C433EF for ; Sun, 6 Mar 2022 18:15:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232159AbiCFSQs (ORCPT ); Sun, 6 Mar 2022 13:16:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230445AbiCFSQq (ORCPT ); Sun, 6 Mar 2022 13:16:46 -0500 X-Greylist: delayed 63 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 06 Mar 2022 10:15:53 PST Received: from smtp.tiscali.it (michael.mail.tiscali.it [213.205.33.246]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 62BC765D0E for ; Sun, 6 Mar 2022 10:15:53 -0800 (PST) Received: from venice.bhome ([78.12.27.75]) by michael.mail.tiscali.it with id 36El2700C1dDdji016EoHV; Sun, 06 Mar 2022 18:14:48 +0000 x-auth-user: kreijack@tiscali.it From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Zygo Blaxell , Josef Bacik , David Sterba , Sinnamohideen Shafeeq , Paul Jones , Boris Burkov , Goffredo Baroncelli Subject: [PATCH 2/5] btrfs: export the device allocation_hint property in sysfs Date: Sun, 6 Mar 2022 19:14:40 +0100 Message-Id: X-Mailer: git-send-email 2.35.1 In-Reply-To: References: Reply-To: Goffredo Baroncelli MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tiscali.it; s=smtp; t=1646590488; bh=JjRHIaQBH8Q68/ZAJRphaTfGINGKVAAb0+OMlvGVml4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=0CnVRQIdUNLa+/FrN75RNDTSSm2D0vfKq2ndNsBUHUcqp8B8sDspzet1zL5y3VrFp sDRN+wNn9FkBPc9wqKdTv1KMjZsbvsnLpXIJN+hrZM7bkTMJ1NxWqEZJwcFMZEb0Hu w2QsoZj9LwSjaR1+UtIr30YooeMSBEO11VOf2a0w= Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goffredo Baroncelli Export the device allocation_hint property via /sys/fs/btrfs//devinfo//allocation_hint Signed-off-by: Goffredo Baroncelli Reported-by: kernel test robot --- fs/btrfs/sysfs.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 17389a42a3ab..59d92a385a96 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1578,6 +1578,36 @@ static ssize_t btrfs_devinfo_error_stats_show(struct kobject *kobj, } BTRFS_ATTR(devid, error_stats, btrfs_devinfo_error_stats_show); + +struct allocation_hint_name_t { + const char *name; + const u64 value; +} allocation_hint_name[] = { + { "DATA_PREFERRED", BTRFS_DEV_ALLOCATION_HINT_DATA_PREFERRED }, + { "METADATA_PREFERRED", BTRFS_DEV_ALLOCATION_HINT_METADATA_PREFERRED }, + { "DATA_ONLY", BTRFS_DEV_ALLOCATION_HINT_DATA_ONLY }, + { "METADATA_ONLY", BTRFS_DEV_ALLOCATION_HINT_METADATA_ONLY }, +}; + +static ssize_t btrfs_devinfo_allocation_hint_show(struct kobject *kobj, + struct kobj_attribute *a, char *buf) +{ + int i; + struct btrfs_device *device = container_of(kobj, struct btrfs_device, + devid_kobj); + + for (i = 0 ; i < ARRAY_SIZE(allocation_hint_name) ; i++) { + if ((device->type & BTRFS_DEV_ALLOCATION_HINT_MASK) != + allocation_hint_name[i].value) + continue; + + return scnprintf(buf, PAGE_SIZE, "%s\n", + allocation_hint_name[i].name); + } + return scnprintf(buf, PAGE_SIZE, "\n"); +} +BTRFS_ATTR(devid, allocation_hint, btrfs_devinfo_allocation_hint_show); + /* * Information about one device. * @@ -1591,6 +1621,7 @@ static struct attribute *devid_attrs[] = { BTRFS_ATTR_PTR(devid, replace_target), BTRFS_ATTR_PTR(devid, scrub_speed_max), BTRFS_ATTR_PTR(devid, writeable), + BTRFS_ATTR_PTR(devid, allocation_hint), NULL }; ATTRIBUTE_GROUPS(devid);