From patchwork Mon Feb 17 11:12:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 11386105 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B09117E8 for ; Mon, 17 Feb 2020 11:13:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C0AC20801 for ; Mon, 17 Feb 2020 11:13:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="N+FxkqQ1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728423AbgBQLNL (ORCPT ); Mon, 17 Feb 2020 06:13:11 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:34042 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728337AbgBQLNK (ORCPT ); Mon, 17 Feb 2020 06:13:10 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 01HBD58Q106177; Mon, 17 Feb 2020 11:13:06 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=/J06CE77TwWQOrzIbZ52ForVzwiDpwNIpy4D+Esby1k=; b=N+FxkqQ1ejiZ0m0Etk0WVov2ZgllDKbCRz/thHrbAiyiZWfo94m0W7QUFMp0/Wo6Nz/z 8lCyXlEB5C1lAePiAPhIOsSO65Phvdc3gtDVRuxn+v1p5ljz5nmhidHXiSS0qWHdT32c 6CuqXSztsfQWMjC/aRTaBJY9Y1Or8rNbK9Dn3FxWYAESeyn1rROUbADW9wo3J+FP85cE 1l/cGD7MT4/beVkl9Z3G4EFAelQkUwzkA+z/cvanwu19MK/PUTRfpdqMnTwHAb6L2E1R ucYAYrJGCPq1fYFJX7fujJrsjeG2TVb3rxln7uGqhw1LiUiGi2JvHq8UWgA+Zu8+/H7l qw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2y68kqqmp8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Feb 2020 11:13:06 +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 01HBC6FI086774; Mon, 17 Feb 2020 11:13:06 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 2y6t6thkur-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Feb 2020 11:13:06 +0000 Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 01HBD5kx007832; Mon, 17 Feb 2020 11:13:05 GMT Received: from tp.localdomain (/39.109.145.141) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 17 Feb 2020 03:13:04 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: josef@toxicpanda.com, dsterba@suse.com Subject: [PATCH v5 4/5] btrfs: introduce new device-state read_preferred Date: Mon, 17 Feb 2020 19:12:44 +0800 Message-Id: <1581937965-16569-5-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1581937965-16569-1-git-send-email-anand.jain@oracle.com> References: <1581937965-16569-1-git-send-email-anand.jain@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9533 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 malwarescore=0 bulkscore=0 spamscore=0 suspectscore=1 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002170097 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9533 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 spamscore=0 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 clxscore=1015 mlxscore=0 suspectscore=1 impostorscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002170097 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Preparatory patch to add new read_policy type 'device'. Provides a sysfs interface to set the device state as read_preferred. Signed-off-by: Anand Jain --- v5: born fs/btrfs/sysfs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 1 + 2 files changed, 50 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index c9a8850b186a..638ce3f4abe3 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1317,11 +1317,60 @@ static ssize_t btrfs_devinfo_writeable_show(struct kobject *kobj, } BTRFS_ATTR(devid, writeable, btrfs_devinfo_writeable_show); +static ssize_t btrfs_devinfo_read_pref_show(struct kobject *kobj, + struct kobj_attribute *a, char *buf) +{ + int val; + struct btrfs_device *device = container_of(kobj, struct btrfs_device, + devid_kobj); + + val = !!test_bit(BTRFS_DEV_STATE_READ_PREFERRED, &device->dev_state); + + return snprintf(buf, PAGE_SIZE, "%d\n", val); +} + +static ssize_t btrfs_devinfo_read_pref_store(struct kobject *kobj, + struct kobj_attribute *a, + const char *buf, size_t len) +{ + int ret; + unsigned long val; + struct btrfs_device *device; + + ret = kstrtoul(skip_spaces(buf), 0, &val); + if (ret) + return ret; + + if (val != 0 && val != 1) + return -EINVAL; + + /* + * lock is not required, the btrfs_device struct can't be freed while + * its kobject btrfs_device::devid_kobj is still open. + */ + device = container_of(kobj, struct btrfs_device, devid_kobj); + + if (val) { + set_bit(BTRFS_DEV_STATE_READ_PREFERRED, &device->dev_state); + btrfs_info(device->fs_devices->fs_info, + "set read preferred on devid %llu", device->devid); + } else { + clear_bit(BTRFS_DEV_STATE_READ_PREFERRED, &device->dev_state); + btrfs_info(device->fs_devices->fs_info, + "reset read preferred on devid %llu", device->devid); + } + + return len; +} +BTRFS_ATTR_RW(devid, read_preferred, btrfs_devinfo_read_pref_show, + btrfs_devinfo_read_pref_store); + static struct attribute *devid_attrs[] = { BTRFS_ATTR_PTR(devid, in_fs_metadata), BTRFS_ATTR_PTR(devid, missing), BTRFS_ATTR_PTR(devid, replace_target), BTRFS_ATTR_PTR(devid, writeable), + BTRFS_ATTR_PTR(devid, read_preferred), NULL }; ATTRIBUTE_GROUPS(devid); diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index ed2bba741b6e..07962a0ce898 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -52,6 +52,7 @@ struct btrfs_io_geometry { #define BTRFS_DEV_STATE_MISSING (2) #define BTRFS_DEV_STATE_REPLACE_TGT (3) #define BTRFS_DEV_STATE_FLUSH_SENT (4) +#define BTRFS_DEV_STATE_READ_PREFERRED (5) struct btrfs_device { struct list_head dev_list; /* device_list_mutex */