From patchwork Thu Apr 25 11:59:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 10916913 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 53D711575 for ; Thu, 25 Apr 2019 11:59:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46FD528A3E for ; Thu, 25 Apr 2019 11:59:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B43628A8E; Thu, 25 Apr 2019 11:59:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C647428A56 for ; Thu, 25 Apr 2019 11:59:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726637AbfDYL75 (ORCPT ); Thu, 25 Apr 2019 07:59:57 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:58734 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726229AbfDYL74 (ORCPT ); Thu, 25 Apr 2019 07:59:56 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3PBxMeo071761 for ; Thu, 25 Apr 2019 11:59:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=uJ9iFLXrH9aID1v0/X9Ru8OBfcfwqRWFNGvhPxqbQvM=; b=1omVxvHWmMxA+YWVF/5G2BX8Rwu0NGEjQ8o9IG6hevSigwbxf9wPKPD+C5xqpAy8V3oO tQB0ziSxExBI2meNNQBmgzPOOEPFrIqk83+AbXapEWIjpy9fnmw9KPKviLqVspOf07Kd 5U3tPNxk76ZO7eOo+Vgyte57bCMvmS0VQ9OVTTQmnlrmYoaksn3KsrTCBMumWEXjucb1 PRakhEVleayFAERXAKsuL7vkcWin6z5C/iUt46XVRBZao9qC2K70vjWeS8kDaey6Gm0L OxmMbu2/WD1htCPoaOIeQOqEDo3pEglPPwYzlNVjDTB1QWyXiKxjU3ZJj4o+lrEyVbSa NQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2130.oracle.com with ESMTP id 2ryrxd8303-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 25 Apr 2019 11:59:55 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3PBwUUx188644 for ; Thu, 25 Apr 2019 11:59:55 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 2s0f0wkp6b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 25 Apr 2019 11:59:54 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x3PBxrVX023035 for ; Thu, 25 Apr 2019 11:59:54 GMT Received: from localhost.localdomain (/192.188.170.109) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 25 Apr 2019 04:59:53 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/3] btrfs: add inode pointer to prop_handler::validate() Date: Thu, 25 Apr 2019 19:59:44 +0800 Message-Id: <20190425115946.2550-2-anand.jain@oracle.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190425115946.2550-1-anand.jain@oracle.com> References: <20190425115946.2550-1-anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9237 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904250077 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9237 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904250077 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In preparation to add the readmirror property, pass inode in the prop_handler::validate() function vector, so that it can fetch corresponding fs_devices. Signed-off-by: Anand Jain --- fs/btrfs/props.c | 12 +++++++----- fs/btrfs/props.h | 4 ++-- fs/btrfs/xattr.c | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c index ca2716917e37..5c1fccc32b43 100644 --- a/fs/btrfs/props.c +++ b/fs/btrfs/props.c @@ -17,7 +17,7 @@ static DEFINE_HASHTABLE(prop_handlers_ht, BTRFS_PROP_HANDLERS_HT_BITS); struct prop_handler { struct hlist_node node; const char *xattr_name; - int (*validate)(const char *value, size_t len); + int (*validate)(struct inode *inode, const char *value, size_t len); int (*apply)(struct inode *inode, const char *value, size_t len); const char *(*extract)(struct inode *inode); int inheritable; @@ -55,7 +55,8 @@ find_prop_handler(const char *name, return NULL; } -int btrfs_validate_prop(const char *name, const char *value, size_t value_len) +int btrfs_validate_prop(struct inode *inode, const char *name, + const char *value, size_t value_len) { const struct prop_handler *handler; @@ -69,7 +70,7 @@ int btrfs_validate_prop(const char *name, const char *value, size_t value_len) if (value_len == 0) return 0; - return handler->validate(value, value_len); + return handler->validate(inode, value, value_len); } int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode, @@ -252,7 +253,8 @@ int btrfs_load_inode_props(struct inode *inode, struct btrfs_path *path) return ret; } -static int prop_compression_validate(const char *value, size_t len) +static int prop_compression_validate(struct inode *inode, const char *value, + size_t len) { if (!value) return 0; @@ -353,7 +355,7 @@ static int inherit_props(struct btrfs_trans_handle *trans, * This is not strictly necessary as the property should be * valid, but in case it isn't, don't propagate it futher. */ - ret = h->validate(value, strlen(value)); + ret = h->validate(inode, value, strlen(value)); if (ret) continue; diff --git a/fs/btrfs/props.h b/fs/btrfs/props.h index 40b2c65b518c..5b1e39136f7f 100644 --- a/fs/btrfs/props.h +++ b/fs/btrfs/props.h @@ -13,8 +13,8 @@ void __init btrfs_props_init(void); int btrfs_set_prop(struct btrfs_trans_handle *trans, struct inode *inode, const char *name, const char *value, size_t value_len, int flags); -int btrfs_validate_prop(const char *name, const char *value, size_t value_len); - +int btrfs_validate_prop(struct inode *inode, const char *name, + const char *value, size_t value_len); int btrfs_load_inode_props(struct inode *inode, struct btrfs_path *path); int btrfs_inode_inherit_props(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c index 46ad7b5cf209..4e4f0edd4968 100644 --- a/fs/btrfs/xattr.c +++ b/fs/btrfs/xattr.c @@ -378,7 +378,7 @@ static int btrfs_xattr_handler_set_prop(const struct xattr_handler *handler, struct btrfs_root *root = BTRFS_I(inode)->root; name = xattr_full_name(handler, name); - ret = btrfs_validate_prop(name, value, size); + ret = btrfs_validate_prop(inode, name, value, size); if (ret) return ret; From patchwork Thu Apr 25 11:59:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 10916915 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 01139161F for ; Thu, 25 Apr 2019 12:00:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7DFD28A46 for ; Thu, 25 Apr 2019 12:00:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC10128A47; Thu, 25 Apr 2019 12:00:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7069A28A3E for ; Thu, 25 Apr 2019 12:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726891AbfDYL77 (ORCPT ); Thu, 25 Apr 2019 07:59:59 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:52784 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726152AbfDYL76 (ORCPT ); Thu, 25 Apr 2019 07:59:58 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3PBxGsl062823 for ; Thu, 25 Apr 2019 11:59:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=c87tFbIYphrskFwViywAYFUo91vohFohWmpuvfruh+E=; b=PAKvA1VE0FRI5JupeLh1HkSFfO4oDsv8xMaRcvpnLsPvGbvEc8MZteJ3hW0KVjoHCGnq 4I0qLxMK6BLDomAeH09LeJetG6lqJxSd8RUeAjR28icEPNVeijEE87Kav28yx4hq0EOt jWnnMx1udgxKBOC6TbwT8zfixWQDi7UlF8Vgs42FpqOMWSZ6tK1+yqPwz1a+6BZOOPLQ DXTeV9e0yP5m4FGu3Xqb+IR4QS2ol42S35wqhBrFh8ehEc8HASPGSg8qqv0mbFoUzM+1 eGs1fJH9yVNU+T0Q1OwgNDZStx+Rb4+BnyHqeJD2aTPnrDuIop2DFnoWEMhJVtxRTl62 gQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2rytut7v55-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 25 Apr 2019 11:59:56 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3PBwhiS022454 for ; Thu, 25 Apr 2019 11:59:55 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2s0fv43a10-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 25 Apr 2019 11:59:55 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x3PBxtO0018145 for ; Thu, 25 Apr 2019 11:59:55 GMT Received: from localhost.localdomain (/192.188.170.109) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 25 Apr 2019 04:59:54 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/3] btrfs: add readmirror property framework Date: Thu, 25 Apr 2019 19:59:45 +0800 Message-Id: <20190425115946.2550-3-anand.jain@oracle.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190425115946.2550-1-anand.jain@oracle.com> References: <20190425115946.2550-1-anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9237 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904250077 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9237 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904250077 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Function call chain __btrfs_map_block()->find_live_mirror() uses thread %pid to determine the %mirror_num for the read when mirror_num=0 in the argument. This patch introduces a framework so that readmirror is a configurable parameter, with default set to pid. Signed-off-by: Anand Jain --- fs/btrfs/props.c | 41 +++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.c | 9 ++++++++- fs/btrfs/volumes.h | 6 ++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c index 5c1fccc32b43..1d44fbdd5891 100644 --- a/fs/btrfs/props.c +++ b/fs/btrfs/props.c @@ -10,6 +10,7 @@ #include "ctree.h" #include "xattr.h" #include "compression.h" +#include "volumes.h" #define BTRFS_PROP_HANDLERS_HT_BITS 8 static DEFINE_HASHTABLE(prop_handlers_ht, BTRFS_PROP_HANDLERS_HT_BITS); @@ -316,6 +317,39 @@ static const char *prop_compression_extract(struct inode *inode) return NULL; } +static int prop_readmirror_validate(struct inode *inode, const char *value, + size_t len) +{ + struct btrfs_root *root = BTRFS_I(inode)->root; + + if (root->root_key.objectid != BTRFS_FS_TREE_OBJECTID) + return -EINVAL; + + if (!len) + return 0; + + return -EINVAL; +} + +static int prop_readmirror_apply(struct inode *inode, const char *value, + size_t len) +{ + struct btrfs_fs_devices *fs_devices = btrfs_sb(inode->i_sb)->fs_devices; + + fs_devices->readmirror_policy = BTRFS_READMIRROR_DEFAULT; + + return 0; +} + +static const char *prop_readmirror_extract(struct inode *inode) +{ + /* + * readmirror policy is applied for the whole FS, inheritance is not + * applicable. + */ + return NULL; +} + static struct prop_handler prop_handlers[] = { { .xattr_name = XATTR_BTRFS_PREFIX "compression", @@ -324,6 +358,13 @@ static struct prop_handler prop_handlers[] = { .extract = prop_compression_extract, .inheritable = 1 }, + { + .xattr_name = XATTR_BTRFS_PREFIX "readmirror", + .validate = prop_readmirror_validate, + .apply = prop_readmirror_apply, + .extract = prop_readmirror_extract, + .inheritable = 0 + }, }; static int inherit_props(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 78bab7803bda..64c3a2d8b264 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5504,7 +5504,14 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info, else num_stripes = map->num_stripes; - preferred_mirror = first + current->pid % num_stripes; + switch(fs_info->fs_devices->readmirror_policy) { + case BTRFS_READMIRROR_DEFAULT: + /* fall through */ + default: + /* readmirror as per thread pid */ + preferred_mirror = first + current->pid % num_stripes; + break; + } if (dev_replace_is_ongoing && fs_info->dev_replace.cont_reading_from_srcdev_mode == diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index b3a89d767512..5dffaa6f9d18 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -204,6 +204,10 @@ BTRFS_DEVICE_GETSET_FUNCS(total_bytes); BTRFS_DEVICE_GETSET_FUNCS(disk_total_bytes); BTRFS_DEVICE_GETSET_FUNCS(bytes_used); +enum btrfs_readmirror_policy { + BTRFS_READMIRROR_DEFAULT, +}; + struct btrfs_fs_devices { u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ u8 metadata_uuid[BTRFS_FSID_SIZE]; @@ -249,6 +253,8 @@ struct btrfs_fs_devices { struct kobject fsid_kobj; struct kobject *device_dir_kobj; struct completion kobj_unregister; + + int readmirror_policy; }; #define BTRFS_BIO_INLINE_CSUM_SIZE 64 From patchwork Thu Apr 25 11:59:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 10916917 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 71EE31515 for ; Thu, 25 Apr 2019 12:00:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 626AA2846C for ; Thu, 25 Apr 2019 12:00:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5113528A3E; Thu, 25 Apr 2019 12:00:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C955F28A5A for ; Thu, 25 Apr 2019 12:00:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727018AbfDYMAA (ORCPT ); Thu, 25 Apr 2019 08:00:00 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:58772 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726229AbfDYL77 (ORCPT ); Thu, 25 Apr 2019 07:59:59 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3PBxOc8071777 for ; Thu, 25 Apr 2019 11:59:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2018-07-02; bh=QuTpJ3r71WxM/+eGbeBDh4MrxuuyokvaPZMMNyZIi0c=; b=O2nImnT8pEG/z4JH29vmR0eghagE5rb2ykRICKgcno1kpgJjsuJW/4vY6q1GjL7AhLUV m5YqWMVMSQx0kKYzEbbsbvNbMW8jgELx3Zxxh0R7xBJ0RkX70UJ+igvVERZlAr3mb++Q x+q7m4EE3e8QnIeTm6zD6QxB3sKi3mZlbs05Gc62BiJoN7nlHmA1KtvZdEN85Kxoxalu DVRwn3rZ8D34N+VwJAsVGBJJ9wsarAXxkkySn3ap25Lqsn5chMJ7t7diNdy5uHDXSwJB tw5KGG3PQCRgs4ceb4pMucmA95HsCxMmFasyhf6f1Qmru6Pbz/fgyKSQP4CwEbBPmZD/ rg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2130.oracle.com with ESMTP id 2ryrxd8308-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 25 Apr 2019 11:59:58 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3PBwtFX022680 for ; Thu, 25 Apr 2019 11:59:58 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2s0fv43a14-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 25 Apr 2019 11:59:57 +0000 Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x3PBxuDe007168 for ; Thu, 25 Apr 2019 11:59:57 GMT Received: from localhost.localdomain (/192.188.170.109) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 25 Apr 2019 04:59:56 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/3] btrfs: add readmirror devid property Date: Thu, 25 Apr 2019 19:59:46 +0800 Message-Id: <20190425115946.2550-4-anand.jain@oracle.com> X-Mailer: git-send-email 2.20.1 (Apple Git-117) In-Reply-To: <20190425115946.2550-1-anand.jain@oracle.com> References: <20190425115946.2550-1-anand.jain@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9237 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904250077 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9237 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1904250077 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduces devid readmirror property, to direct read IO to the specified device(s). The readmirror property is stored as extended attribute on the root inode. The readmirror input format is devid1,2,3.. etc. And for the each devid provided, a new flag BTRFS_DEV_STATE_READ_OPTIMISED is set. As of now readmirror by devid supports only raid1s. Raid10 support has to leverage device grouping feature, which is yet to be implemented. Signed-off-by: Anand Jain --- fs/btrfs/props.c | 69 +++++++++++++++++++++++++++++++++++++++++++++- fs/btrfs/volumes.c | 16 +++++++++++ fs/btrfs/volumes.h | 2 ++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c index 1d44fbdd5891..c5d17e29ab4e 100644 --- a/fs/btrfs/props.c +++ b/fs/btrfs/props.c @@ -320,7 +320,10 @@ static const char *prop_compression_extract(struct inode *inode) static int prop_readmirror_validate(struct inode *inode, const char *value, size_t len) { + char *value_dup; + char *devid_str; struct btrfs_root *root = BTRFS_I(inode)->root; + struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices; if (root->root_key.objectid != BTRFS_FS_TREE_OBJECTID) return -EINVAL; @@ -328,16 +331,80 @@ static int prop_readmirror_validate(struct inode *inode, const char *value, if (!len) return 0; - return -EINVAL; + if (len <= 5 || strncmp("devid", value, 5)) + return -EINVAL; + + value_dup = kstrndup(value + 5, len - 5, GFP_KERNEL); + if (!value_dup) + return -ENOMEM; + + while ((devid_str = strsep(&value_dup, ",")) != NULL) { + u64 devid; + struct btrfs_device *device; + + if (kstrtoull(devid_str, 10, &devid)) { + kfree(value_dup); + return -EINVAL; + } + + device = btrfs_find_device(fs_devices, devid, NULL, NULL, false); + if (!device) { + kfree(value_dup); + return -EINVAL; + } + } + + return 0; } static int prop_readmirror_apply(struct inode *inode, const char *value, size_t len) { + char *value_dup; + char *devid_str; + struct btrfs_device *device; struct btrfs_fs_devices *fs_devices = btrfs_sb(inode->i_sb)->fs_devices; + if (value) { + value_dup = kstrndup(value + 5, len - 5, GFP_KERNEL); + if (!value_dup) + return -ENOMEM; + } + + /* Both set and reset has to clear the exisiting values */ + list_for_each_entry(device, &fs_devices->devices, dev_list) { + if (test_bit(BTRFS_DEV_STATE_READ_OPTIMISED, + &device->dev_state)) { + clear_bit(BTRFS_DEV_STATE_READ_OPTIMISED, + &device->dev_state); + } + } fs_devices->readmirror_policy = BTRFS_READMIRROR_DEFAULT; + /* Its only reset so just return */ + if (!value) + return 0; + + while ((devid_str = strsep(&value_dup, ",")) != NULL) { + u64 devid; + + /* Has been verified in validate() this will not fail */ + if (kstrtoull(devid_str, 10, &devid)) { + kfree(value_dup); + return -EINVAL; + } + + device = btrfs_find_device(fs_devices, devid, NULL, NULL, false); + if (!device) { + kfree(value_dup); + return -EINVAL; + } + + set_bit(BTRFS_DEV_STATE_READ_OPTIMISED, &device->dev_state); + fs_devices->readmirror_policy = BTRFS_READMIRROR_DEVID; + } + + kfree(value_dup); return 0; } diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 64c3a2d8b264..90cbc03a20f6 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5495,6 +5495,7 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info, int preferred_mirror; int tolerance; struct btrfs_device *srcdev; + bool found = false; ASSERT((map->type & (BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10))); @@ -5505,6 +5506,21 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info, num_stripes = map->num_stripes; switch(fs_info->fs_devices->readmirror_policy) { + case BTRFS_READMIRROR_DEVID: + /* skip raid10 for now */ + if (map->type & BTRFS_BLOCK_GROUP_RAID1) { + for (i = first; i < first + num_stripes; i++) { + if (test_bit(BTRFS_DEV_STATE_READ_OPTIMISED, + &map->stripes[i].dev->dev_state)) { + preferred_mirror = i; + found = true; + break; + } + } + if (found) + break; + } + /* fall through */ case BTRFS_READMIRROR_DEFAULT: /* fall through */ default: diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 5dffaa6f9d18..6c223790dc4c 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -41,6 +41,7 @@ struct btrfs_pending_bios { #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_OPTIMISED (5) struct btrfs_device { struct list_head dev_list; @@ -206,6 +207,7 @@ BTRFS_DEVICE_GETSET_FUNCS(bytes_used); enum btrfs_readmirror_policy { BTRFS_READMIRROR_DEFAULT, + BTRFS_READMIRROR_DEVID, }; struct btrfs_fs_devices {