From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 416F2C34047 for ; Wed, 19 Feb 2020 11:29:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 161BE21D56 for ; Wed, 19 Feb 2020 11:29:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="vNpAfeBT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726891AbgBSL3u (ORCPT ); Wed, 19 Feb 2020 06:29:50 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:57466 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726735AbgBSL3u (ORCPT ); Wed, 19 Feb 2020 06:29:50 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01JBSnZI075633; Wed, 19 Feb 2020 11:29:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=sQYo4AxI5Rxu0KrAjKs6G+r09frvRZxo4b/92mIgvDg=; b=vNpAfeBTfSnxWfZbd1LTkJi0+kQM6Yp68EB8AXtwaKzl7Kl8GsisnPjU+zh06jyM8RRr ZyC7mzs9BfQnyltOa7oFkcRd+Q8ZLdeHSS8DOGbYz/zkfO1awCqMo8Thm2raO1Ob2KVa Qi3TGWfY/+8yCuBKJxiG0LC2bwpMC3ZMrTRTIUCA9To0cnLx6CptpcV4sa9p/Ho3nJuH irQbgQTJe1fGZI8BScga2+TXyHZLAdurktx7a2JV5IKGuIqc3n7HrVYQZ+7s2voJlkHb sRtTuF6n/Yvn8ibHeFgHqig+ZZ3UY/wJ7TGbxT0XeONaMVQ3V4e9zt/4sEuZ4q2vhDdf Iw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2y8udd2c84-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Feb 2020 11:29:45 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01JBSd38180642; Wed, 19 Feb 2020 11:29:45 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2y8udaamhj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Feb 2020 11:29:45 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 01JBThHS027132; Wed, 19 Feb 2020 11:29:44 GMT Received: from tp.localdomain (/39.109.145.141) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 19 Feb 2020 03:29:43 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: josef@toxicpanda.com, dsterba@suse.cz Subject: [PATCH v6 3/5] btrfs: create read policy sysfs attribute, pid Date: Wed, 19 Feb 2020 19:29:24 +0800 Message-Id: <1582111766-8372-4-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1582111766-8372-1-git-send-email-anand.jain@oracle.com> References: <1582111766-8372-1-git-send-email-anand.jain@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9535 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 suspectscore=1 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190087 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9535 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 impostorscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 suspectscore=1 priorityscore=1501 bulkscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002190087 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add /sys/fs/btrfs/UUID/read_policy attribute so that the read policy for the raid1 and raid10 chunks can be tuned. When this attribute is read, it shall show all available policies, with active policy being with in [ ]. The read_policy attribute can be written using one of the items listed in there. For example: $cat /sys/fs/btrfs/UUID/read_policy [pid] $echo pid > /sys/fs/btrfs/UUID/read_policy Signed-off-by: Anand Jain --- v5: Title rename: old: btrfs: sysfs, add read_policy attribute Uses the btrfs_strmatch() helper (BTRFS_READ_POLICY_NAME_MAX dropped). Use the table for the policy names. Rename len to ret. Use a simple logic to prefix space in btrfs_read_policy_show() Reviewed-by: Josef Bacik dropped. v4:- v3: rename [by_pid] to [pid] v2: v2: check input len before strip and kstrdup fs/btrfs/sysfs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 7bb68cef98ab..c9a8850b186a 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -832,6 +832,54 @@ static int btrfs_strmatch(const char *given, const char *golden) return -EINVAL; } +static const char* const btrfs_read_policy_name[] = { "pid" }; + +static ssize_t btrfs_read_policy_show(struct kobject *kobj, + struct kobj_attribute *a, char *buf) +{ + int i; + ssize_t ret = 0; + struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj); + + for (i = 0; i < BTRFS_NR_READ_POLICY; i++) { + if (fs_devices->read_policy == i) + ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s[%s]", + (ret == 0 ? "" : " "), + btrfs_read_policy_name[i]); + else + ret += snprintf(buf + ret, PAGE_SIZE - ret, "%s%s", + (ret == 0 ? "" : " "), + btrfs_read_policy_name[i]); + } + + ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); + + return ret; +} + +static ssize_t btrfs_read_policy_store(struct kobject *kobj, + struct kobj_attribute *a, + const char *buf, size_t len) +{ + int i; + struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj); + + for (i = 0; i < BTRFS_NR_READ_POLICY; i++) { + if (btrfs_strmatch(buf, btrfs_read_policy_name[i]) == 0) { + if (i != fs_devices->read_policy) { + fs_devices->read_policy = i; + btrfs_info(fs_devices->fs_info, + "read policy set to '%s'", + btrfs_read_policy_name[i]); + } + return len; + } + } + + return -EINVAL; +} +BTRFS_ATTR_RW(, read_policy, btrfs_read_policy_show, btrfs_read_policy_store); + static const struct attribute *btrfs_attrs[] = { BTRFS_ATTR_PTR(, label), BTRFS_ATTR_PTR(, nodesize), @@ -840,6 +888,7 @@ static int btrfs_strmatch(const char *given, const char *golden) BTRFS_ATTR_PTR(, quota_override), BTRFS_ATTR_PTR(, metadata_uuid), BTRFS_ATTR_PTR(, checksum), + BTRFS_ATTR_PTR(, read_policy), NULL, }; -- 1.8.3.1