From patchwork Mon Feb 1 21:28:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 12060101 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 02728C4332D for ; Mon, 1 Feb 2021 21:29:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC93D64ECF for ; Mon, 1 Feb 2021 21:29:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232421AbhBAV33 (ORCPT ); Mon, 1 Feb 2021 16:29:29 -0500 Received: from smtp-36.italiaonline.it ([213.209.10.36]:47606 "EHLO libero.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229680AbhBAV3G (ORCPT ); Mon, 1 Feb 2021 16:29:06 -0500 Received: from venice.bhome ([84.220.24.72]) by smtp-36.iol.local with ESMTPA id 6gkAlJHqMi3tS6gkBlGswl; Mon, 01 Feb 2021 22:28:23 +0100 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2014; t=1612214903; bh=dHpDrAyHYkS2kZf5+eTtb2K4W+ZIMRhrVfPzuguh8vo=; h=From; b=DnR5/u/CTSCAuxRlcngBSFEVBKzB6P32Nbs1ji2iZoskWOJDzzpAeQpXKRnr5vRQ0 eUc/LYM2VXiShd/5PQAC8gkKQJ1kS0Hhqgd5SxvTqL8E3QH/dgiqyw8IfSgjBOAvzy xdZ8itKsM0vsBduZI7UnmnhiNgAjyQaV2i9vOrhercdw7GLlpda2vvJ7TYaAKtQrY6 KjJpuL0W2U4kudxuWdgX70J/DiKbsJb7v2WVzqgBpYprqXGO1JR3MmGj4kKbILWvgo BvQPNsk9PllMOpFcZf7Lp2a3HgdQxJsIHMZXtK8Gh6et82xornGWw2ICaj7QC5A2kq WKRij2aE+hI+A== X-CNFS-Analysis: v=2.4 cv=FqfAQ0nq c=1 sm=1 tr=0 ts=60187277 cx=a_exe a=tAq5w2qrEf5dL+VNPEPBHQ==:117 a=tAq5w2qrEf5dL+VNPEPBHQ==:17 a=tAp6EsRIHxeSHigjOvkA:9 From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Zygo Blaxell , Josef Bacik , Goffredo Baroncelli Subject: [PATCH 1/5] btrfs: add ioctl BTRFS_IOC_DEV_PROPERTIES. Date: Mon, 1 Feb 2021 22:28:16 +0100 Message-Id: <20210201212820.64381-2-kreijack@libero.it> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210201212820.64381-1-kreijack@libero.it> References: <20210201212820.64381-1-kreijack@libero.it> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfFYKrWBstadXte6rQg6x4TKquP1wXXhoyYYM2AI7cSRXuTIpKOEM6dMF0M35KslNX9CHRb27wdGuhAxg+LNzrGNazimiOamvgWENsGVQQxRnL7gBwVNZ mPd9T6PL6syZ26czSUmE+T0PdkmjK5PJtc1TQYNESgEmNTrtOfJ5wYOC2gSYK9chIu500oHYpQp58mLev5aFUl6udwR85k/UJtYCYVQPKp036VUnibjNYwiM ZV+3dgkoAa5mYtxIakOAOHFMX/SQivx+qxj05ZFbefe9Q6hSeOJXG2uFImzCZTzT Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goffredo Baroncelli This ioctl is a base for returning / setting information from / to the fields of the btrfs_dev_item object. For now only the "type" field is returned / set. Signed-off-by: Goffredo Baroncelli --- fs/btrfs/ioctl.c | 67 ++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.c | 2 +- fs/btrfs/volumes.h | 2 ++ include/uapi/linux/btrfs.h | 40 +++++++++++++++++++++++ 4 files changed, 110 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 703212ff50a5..9e67741fa966 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4842,6 +4842,71 @@ static int btrfs_ioctl_set_features(struct file *file, void __user *arg) return ret; } +static long btrfs_ioctl_dev_properties(struct file *file, + void __user *argp) +{ + struct inode *inode = file_inode(file); + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); + struct btrfs_ioctl_dev_properties dev_props; + struct btrfs_device *device; + struct btrfs_root *root = fs_info->chunk_root; + struct btrfs_trans_handle *trans; + int ret; + u64 prev_type; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (copy_from_user(&dev_props, argp, sizeof(dev_props))) + return -EFAULT; + + device = btrfs_find_device(fs_info->fs_devices, dev_props.devid, + NULL, NULL); + if (!device) { + btrfs_info(fs_info, "change_dev_properties: unable to find device %llu", + dev_props.devid); + return -ENODEV; + } + + if (dev_props.properties & BTRFS_DEV_PROPERTY_READ) { + u64 props = dev_props.properties; + memset(&dev_props, 0, sizeof(dev_props)); + if (props & BTRFS_DEV_PROPERTY_TYPE) { + dev_props.properties = BTRFS_DEV_PROPERTY_TYPE; + dev_props.type = device->type; + } + if(copy_to_user(argp, &dev_props, sizeof(dev_props))) + return -EFAULT; + return 0; + } + + /* it is possible to set only BTRFS_DEV_PROPERTY_TYPE for now */ + if (dev_props.properties & ~(BTRFS_DEV_PROPERTY_TYPE)) + return -EPERM; + + trans = btrfs_start_transaction(root, 0); + if (IS_ERR(trans)) + return PTR_ERR(trans); + + prev_type = device->type; + device->type = dev_props.type; + ret = btrfs_update_device(trans, device); + + if (ret < 0) { + btrfs_abort_transaction(trans, ret); + btrfs_end_transaction(trans); + device->type = prev_type; + return ret; + } + + ret = btrfs_commit_transaction(trans); + if (ret < 0) + device->type = prev_type; + + return ret; + +} + static int _btrfs_ioctl_send(struct file *file, void __user *argp, bool compat) { struct btrfs_ioctl_send_args *arg; @@ -5025,6 +5090,8 @@ long btrfs_ioctl(struct file *file, unsigned int return btrfs_ioctl_get_subvol_rootref(file, argp); case BTRFS_IOC_INO_LOOKUP_USER: return btrfs_ioctl_ino_lookup_user(file, argp); + case BTRFS_IOC_DEV_PROPERTIES: + return btrfs_ioctl_dev_properties(file, argp); } return -ENOTTY; diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index ee086fc56c30..68b346c5465d 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2744,7 +2744,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path return ret; } -static noinline int btrfs_update_device(struct btrfs_trans_handle *trans, +int btrfs_update_device(struct btrfs_trans_handle *trans, struct btrfs_device *device) { int ret; diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 1997a4649a66..d776b7f55d56 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -595,5 +595,7 @@ void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info, int btrfs_bg_type_to_factor(u64 flags); const char *btrfs_bg_type_to_raid_name(u64 flags); int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info); +int btrfs_update_device(struct btrfs_trans_handle *trans, + struct btrfs_device *device); #endif diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index 5df73001aad4..e6caef42837a 100644 --- a/include/uapi/linux/btrfs.h +++ b/include/uapi/linux/btrfs.h @@ -860,6 +860,44 @@ struct btrfs_ioctl_get_subvol_rootref_args { __u8 align[7]; }; +#define BTRFS_DEV_PROPERTY_TYPE (1ULL << 0) +#define BTRFS_DEV_PROPERTY_DEV_GROUP (1ULL << 1) +#define BTRFS_DEV_PROPERTY_SEEK_SPEED (1ULL << 2) +#define BTRFS_DEV_PROPERTY_BANDWIDTH (1ULL << 3) +#define BTRFS_DEV_PROPERTY_READ (1ULL << 60) + +/* + * The ioctl BTRFS_IOC_DEV_PROPERTIES can read and write the device properties. + * + * The properties that the user want to write have to be set + * in the 'properties' field using the BTRFS_DEV_PROPERTY_xxxx constants. + * + * If the ioctl is used to read the device properties, the bit + * BTRFS_DEV_PROPERTY_READ has to be set in the 'properties' field. + * In this case the properties that the user want have to be set in the + * 'properties' field. The kernel doesn't return a property that was not + * required, however it may return a subset of the requested properties. + * The returned properties have the corrispondent BTRFS_DEV_PROPERTY_xxxx + * flag set in the 'properties' field. + * + * Up to 2020/05/11 the only properties that can be read/write is the 'type' + * one. + */ +struct btrfs_ioctl_dev_properties { + __u64 devid; + __u64 properties; + __u64 type; + __u32 dev_group; + __u8 seek_speed; + __u8 bandwidth; + + /* + * for future expansion + */ + __u8 unused1[2]; + __u64 unused2[4]; +}; + /* Error codes as returned by the kernel */ enum btrfs_err_code { BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1, @@ -988,5 +1026,7 @@ enum btrfs_err_code { struct btrfs_ioctl_ino_lookup_user_args) #define BTRFS_IOC_SNAP_DESTROY_V2 _IOW(BTRFS_IOCTL_MAGIC, 63, \ struct btrfs_ioctl_vol_args_v2) +#define BTRFS_IOC_DEV_PROPERTIES _IOW(BTRFS_IOCTL_MAGIC, 64, \ + struct btrfs_ioctl_dev_properties) #endif /* _UAPI_LINUX_BTRFS_H */ From patchwork Mon Feb 1 21:28:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 12060097 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 88541C43381 for ; Mon, 1 Feb 2021 21:29:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A94764EC8 for ; Mon, 1 Feb 2021 21:29:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232432AbhBAV3O (ORCPT ); Mon, 1 Feb 2021 16:29:14 -0500 Received: from smtp-36.italiaonline.it ([213.209.10.36]:37045 "EHLO libero.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232305AbhBAV3G (ORCPT ); Mon, 1 Feb 2021 16:29:06 -0500 Received: from venice.bhome ([84.220.24.72]) by smtp-36.iol.local with ESMTPA id 6gkAlJHqMi3tS6gkBlGswt; Mon, 01 Feb 2021 22:28:23 +0100 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2014; t=1612214903; bh=BPdX2M7pzcSlW67unwh3vWdpm9eFhj7jTNAL2JEydi0=; h=From; b=ot213zskJ5faXfMorwuh760KfifMN6Hnw9ZNtK9hPZratxQg5skzWEPipK3J2vLD1 kwSdvoRS0ZD5HNWm+Sr8nY8bPatTtT0Tc+Pi3QZjsWzndDGV6Uai1njLgDQJBUMgG5 FzRK9QQBtV79DXcPJNgDIupw8Yoo1Hw2bw3x94UVRe8i5arrf2wWI1t0Ac8p5DX7H+ gnCEr1013f/L4zx5SRFs9rS6ki1KMI5urSc/3obdlJ1JYIQcAFtKjqk4MULrnyxY7Q RM66ExI4Ely5teOdnCmhMHkYYF1g7Rgi3erbRwEm2h19SC1Sc0iSXRHvYGjMK2S3sz v/F2QnZsbMGDA== X-CNFS-Analysis: v=2.4 cv=FqfAQ0nq c=1 sm=1 tr=0 ts=60187277 cx=a_exe a=tAq5w2qrEf5dL+VNPEPBHQ==:117 a=tAq5w2qrEf5dL+VNPEPBHQ==:17 a=lLZ8wYX2qvZDYXWRsIgA:9 From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Zygo Blaxell , Josef Bacik , Goffredo Baroncelli Subject: [PATCH 2/5] btrfs: add flags to give an hint to the chunk allocator Date: Mon, 1 Feb 2021 22:28:17 +0100 Message-Id: <20210201212820.64381-3-kreijack@libero.it> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210201212820.64381-1-kreijack@libero.it> References: <20210201212820.64381-1-kreijack@libero.it> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfFYKrWBstadXte6rQg6x4TKquP1wXXhoyYYM2AI7cSRXuTIpKOEM6dMF0M35KslNX9CHRb27wdGuhAxg+LNzrGNazimiOamvgWENsGVQQxRnL7gBwVNZ mPd9T6PL6syZ26czSUmE+T0PdkmjK5PJtc1TQYNESgEmNTrtOfJ5wYOC2gSYK9chIu500oHYpQp58mLev5aFUl6udwR85k/UJtYCYVQPKp036VUnibjNYwiM ZV+3dgkoAa5mYtxIakOAOHFMX/SQivx+qxj05ZFbefe9Q6hSeOJXG2uFImzCZTzT Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goffredo Baroncelli Add the following flags to give an hint about which chunk should be allocated in which a disk. The following flags are created: - BTRFS_DEV_ALLOCATION_PREFERRED_DATA preferred data chunk, but metadata chunk allowed - BTRFS_DEV_ALLOCATION_PREFERRED_METADATA preferred metadata chunk, but data chunk allowed - BTRFS_DEV_ALLOCATION_METADATA_ONLY only metadata chunk allowed - BTRFS_DEV_ALLOCATION_DATA_ONLY only data chunk allowed Signed-off-by: Goffredo Baroncelli --- include/uapi/linux/btrfs_tree.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h index 58d7cff9afb1..bd3af853df0c 100644 --- a/include/uapi/linux/btrfs_tree.h +++ b/include/uapi/linux/btrfs_tree.h @@ -361,6 +361,24 @@ struct btrfs_key { __u64 offset; } __attribute__ ((__packed__)); +/* dev_item.type */ + +/* btrfs chunk allocation hints */ +#define BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT 3 +#define BTRFS_DEV_ALLOCATION_MASK ((1ULL << \ + BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT) -1) +#define BTRFS_DEV_ALLOCATION_MASK_COUNT (1ULL << \ + BTRFS_DEV_ALLOCATION_MASK_BIT_COUNT) +/* preferred data chunk, but metadata chunk allowed */ +#define BTRFS_DEV_ALLOCATION_PREFERRED_DATA (0ULL) +/* preferred metadata chunk, but data chunk allowed */ +#define BTRFS_DEV_ALLOCATION_PREFERRED_METADATA (1ULL) +/* only metadata chunk are allowed */ +#define BTRFS_DEV_ALLOCATION_METADATA_ONLY (2ULL) +/* only data chunk allowed */ +#define BTRFS_DEV_ALLOCATION_DATA_ONLY (3ULL) +/* 5..7 are unused values */ + struct btrfs_dev_item { /* the internal btrfs device id */ __le64 devid; From patchwork Mon Feb 1 21:28:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 12060095 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 444B6C433E6 for ; Mon, 1 Feb 2021 21:29:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E969A64ED0 for ; Mon, 1 Feb 2021 21:29:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232446AbhBAV3P (ORCPT ); Mon, 1 Feb 2021 16:29:15 -0500 Received: from smtp-36.italiaonline.it ([213.209.10.36]:34784 "EHLO libero.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232313AbhBAV3H (ORCPT ); Mon, 1 Feb 2021 16:29:07 -0500 Received: from venice.bhome ([84.220.24.72]) by smtp-36.iol.local with ESMTPA id 6gkAlJHqMi3tS6gkBlGswz; Mon, 01 Feb 2021 22:28:24 +0100 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2014; t=1612214904; bh=0JP/g66F4gd3rshMtrmg1Fz4b9jvZAJ2enehMQa3ANY=; h=From; b=G0GaT2idndVwzrcr0DMjWB5KgcWAydsu8HblD//XYYU6up4K3lvJT3jAITHUoZ7wF LokynvTTwB8qapsJqKzYr50l2MOMisJfCRCrbGyCB4fdZBtvqZYQTLvAgL1MMfZVrr OkiMV6S1yiUqLFZ5sm5hRKyKauJqAaXwjqRulT+zZJQ+wrlJ1wNNjhNYazqTv0tMTr bqHVj40mBnNoeXrvIgilp5DAnFZ2TLGnuoFAcQQsAgPloRKOjory9bcPa2CuBF8dZw 0a4qMGxwknCshyfNGT/jBOki5A2hByALVdPVuXv3R1Ph3dfUKVWTrRuyUbneWXT2y2 tj0VAkTvONSkA== X-CNFS-Analysis: v=2.4 cv=FqfAQ0nq c=1 sm=1 tr=0 ts=60187278 cx=a_exe a=tAq5w2qrEf5dL+VNPEPBHQ==:117 a=tAq5w2qrEf5dL+VNPEPBHQ==:17 a=1s11hCFB_oFSRyqhbgYA:9 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Zygo Blaxell , Josef Bacik , Goffredo Baroncelli Subject: [PATCH 3/5] btrfs: export dev_item.type in /sys/fs/btrfs//devinfo//type Date: Mon, 1 Feb 2021 22:28:18 +0100 Message-Id: <20210201212820.64381-4-kreijack@libero.it> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210201212820.64381-1-kreijack@libero.it> References: <20210201212820.64381-1-kreijack@libero.it> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfD1wutszHKIlUZTwtbSYl9z/+e0rnW7j20qXXiecWT5AXhz1p+eoq7tfP/qkU18tBxI9hlc8b8fyHHAUb+UiBU9dxOKncAAE1Ax1BwTnR3D1zRLzikXh L+S6DNQY6KDcXRnYcJdQI2Bo7+IlDMykKZ6jEhGNNoB4oqwzsv+2kRnyr7C8B9E5yWP+X8UVILmdPSYpPNTAywRp04BU3U6AM2jF6VqBiFkf/cJZKfjVFhWW xPf6g9OdpZsmUnI/+mUGmXNUv30pNEKFUw1sSeRxD2gmi2RDNlpfYcVObDHregTq Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goffredo Baroncelli Signed-off-by: Goffredo Baroncelli --- fs/btrfs/sysfs.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 19b9fffa2c9c..594e8445fe21 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1416,11 +1416,22 @@ static ssize_t btrfs_devinfo_writeable_show(struct kobject *kobj, } BTRFS_ATTR(devid, writeable, btrfs_devinfo_writeable_show); +static ssize_t btrfs_devinfo_type_show(struct kobject *kobj, + struct kobj_attribute *a, char *buf) +{ + struct btrfs_device *device = container_of(kobj, struct btrfs_device, + devid_kobj); + + return scnprintf(buf, PAGE_SIZE, "0x%08llx\n",device->type); +} +BTRFS_ATTR(devid, type, btrfs_devinfo_type_show); + 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, type), NULL }; ATTRIBUTE_GROUPS(devid); From patchwork Mon Feb 1 21:28:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 12060089 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 AFAA5C433E0 for ; Mon, 1 Feb 2021 21:29:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C34164D9C for ; Mon, 1 Feb 2021 21:29:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232365AbhBAV3K (ORCPT ); Mon, 1 Feb 2021 16:29:10 -0500 Received: from smtp-36.italiaonline.it ([213.209.10.36]:46918 "EHLO libero.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232322AbhBAV3G (ORCPT ); Mon, 1 Feb 2021 16:29:06 -0500 Received: from venice.bhome ([84.220.24.72]) by smtp-36.iol.local with ESMTPA id 6gkAlJHqMi3tS6gkClGsx4; Mon, 01 Feb 2021 22:28:24 +0100 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2014; t=1612214904; bh=4pM90owA0lQuOq3sYarqIs3hyXtA+t9DmatR8v2mPtc=; h=From; b=JDTpQ2E9CupMknuntp1HbfBqbiRNRYYhwUxM5FizMzNE8IPz4zgIYtItD14ofzs1Q ACB9zaYRsPbLSyfBMskfU2r92n3J9/Y2gp6aQ5Sj4oexhbBI6umwYlvPWyc01VeL6R Fe4Pr6GSLj4+w4xgMfuej07a5fCYfB60T2t8VZCYsHL3eKlvq05uwkM/KO678ZuRC0 IMGSwgivPqkKXqsSlZX3+bXaG5fBP70zsmD7XBxfQPZ/cwuEN01357hHcw9GuUKUbn Pb269yGdsuHP9++tEJLns0xRzXwA6x+SzCc9IsKUOIQ6sLMuL1bGG9ou/WmLia7Xjj Nns006e05y1lg== X-CNFS-Analysis: v=2.4 cv=FqfAQ0nq c=1 sm=1 tr=0 ts=60187278 cx=a_exe a=tAq5w2qrEf5dL+VNPEPBHQ==:117 a=tAq5w2qrEf5dL+VNPEPBHQ==:17 a=WOvS8Uw1l4o9L0ZJ_KUA:9 From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Zygo Blaxell , Josef Bacik , Goffredo Baroncelli Subject: [PATCH 4/5] btrfs: add allocation_hint option. Date: Mon, 1 Feb 2021 22:28:19 +0100 Message-Id: <20210201212820.64381-5-kreijack@libero.it> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210201212820.64381-1-kreijack@libero.it> References: <20210201212820.64381-1-kreijack@libero.it> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfD1wutszHKIlUZTwtbSYl9z/+e0rnW7j20qXXiecWT5AXhz1p+eoq7tfP/qkU18tBxI9hlc8b8fyHHAUb+UiBU9dxOKncAAE1Ax1BwTnR3D1zRLzikXh L+S6DNQY6KDcXRnYcJdQI2Bo7+IlDMykKZ6jEhGNNoB4oqwzsv+2kRnyr7C8B9E5yWP+X8UVILmdPSYpPNTAywRp04BU3U6AM2jF6VqBiFkf/cJZKfjVFhWW xPf6g9OdpZsmUnI/+mUGmXNUv30pNEKFUw1sSeRxD2gmi2RDNlpfYcVObDHregTq Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goffredo Baroncelli Add allocation_hint mount option. This option accepts the following values: - 0 (default): the chunks allocator ignores the disk hints - 1: the chunks allocator considers the disk hints Signed-off-by: Goffredo Baroncelli --- fs/btrfs/ctree.h | 12 ++++++++++++ fs/btrfs/disk-io.c | 2 ++ fs/btrfs/super.c | 17 +++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 1d3c1e479f3d..5cd6d658f157 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -570,6 +570,15 @@ enum btrfs_exclusive_operation { BTRFS_EXCLOP_SWAP_ACTIVATE, }; +/* + * allocation_hint mode + */ + +enum btrfs_allocation_hint_modes { + BTRFS_ALLOCATION_HINT_DISABLED, + BTRFS_ALLOCATION_HINT_ENABLED +}; + struct btrfs_fs_info { u8 chunk_tree_uuid[BTRFS_UUID_SIZE]; unsigned long flags; @@ -961,6 +970,9 @@ struct btrfs_fs_info { u64 zoned; }; + /* allocation_hint mode */ + int allocation_hint_mode; + /* Max size to emit ZONE_APPEND write command */ u64 max_zone_append_size; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 765deefda92b..1edd219c347c 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2794,6 +2794,8 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info) fs_info->swapfile_pins = RB_ROOT; fs_info->send_in_progress = 0; + + fs_info->allocation_hint_mode = BTRFS_ALLOCATION_HINT_DISABLED; } static int init_mount_fs_info(struct btrfs_fs_info *fs_info, struct super_block *sb) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 022f20810089..d0c69c950cd9 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -359,6 +359,7 @@ enum { Opt_thread_pool, Opt_treelog, Opt_notreelog, Opt_user_subvol_rm_allowed, + Opt_allocation_hint, /* Rescue options */ Opt_rescue, @@ -432,6 +433,7 @@ static const match_table_t tokens = { {Opt_treelog, "treelog"}, {Opt_notreelog, "notreelog"}, {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"}, + {Opt_allocation_hint, "allocation_hint=%d"}, /* Rescue options */ {Opt_rescue, "rescue=%s"}, @@ -889,6 +891,19 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, case Opt_user_subvol_rm_allowed: btrfs_set_opt(info->mount_opt, USER_SUBVOL_RM_ALLOWED); break; + case Opt_allocation_hint: + ret = match_int(&args[0], &intarg); + if (ret || (intarg != 1 && intarg != 0)) { + btrfs_err(info, "invalid allocation_hint= parameter\n"); + ret = -EINVAL; + goto out; + } + if (intarg) + btrfs_info(info, "allocation_hint enabled"); + else + btrfs_info(info, "allocation_hint disabled"); + info->allocation_hint_mode = intarg; + break; case Opt_enospc_debug: btrfs_set_opt(info->mount_opt, ENOSPC_DEBUG); break; @@ -1495,6 +1510,8 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) seq_puts(seq, ",clear_cache"); if (btrfs_test_opt(info, USER_SUBVOL_RM_ALLOWED)) seq_puts(seq, ",user_subvol_rm_allowed"); + if (info->allocation_hint_mode) + seq_puts(seq, ",allocation_hint=1"); if (btrfs_test_opt(info, ENOSPC_DEBUG)) seq_puts(seq, ",enospc_debug"); if (btrfs_test_opt(info, AUTO_DEFRAG)) From patchwork Mon Feb 1 21:28:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 12060091 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 1D496C433DB for ; Mon, 1 Feb 2021 21:29:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C168464EC8 for ; Mon, 1 Feb 2021 21:29:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232448AbhBAV3P (ORCPT ); Mon, 1 Feb 2021 16:29:15 -0500 Received: from smtp-36-i2.italiaonline.it ([213.209.12.36]:48938 "EHLO libero.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231426AbhBAV3H (ORCPT ); Mon, 1 Feb 2021 16:29:07 -0500 Received: from venice.bhome ([84.220.24.72]) by smtp-36.iol.local with ESMTPA id 6gkAlJHqMi3tS6gkClGsxB; Mon, 01 Feb 2021 22:28:24 +0100 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2014; t=1612214904; bh=ncWAEAMifVXLmJIv4yy/NJKZs8/oXW42ms01fKRoWRM=; h=From; b=em+nOQ7O2g6D52oFiNM6BgLXz4Sg8H94xK5z6Vr7bzwxD/Zr7khEWR5rUmRKhHTqM 7r9EHmNBYiZ0hHZ7N46ZFhsX3xDFJv9BbZ6bmJlFcJVJUqGuaT4DOb+QqSrFGib6OA p23P0I75v9mBtcIYoUyxa1t1aMopDLrh32ZWwJh8JpqoDX3oE5pBE8JZ7MUywV6xUY iUXocsxtZBf+Hxgp7HOkEOEUrdgbRBgqMeBC1Ii1gfdnqFR29Q8Op1/1nFBSfbH8No M0IjuicFp3gZHT1QR4D4VVEnaeIXlMVjaEicmsRi0tjiOgX4+RzY8hqWUqA4HnrilB QDg4PH2Ru0XNQ== X-CNFS-Analysis: v=2.4 cv=FqfAQ0nq c=1 sm=1 tr=0 ts=60187278 cx=a_exe a=tAq5w2qrEf5dL+VNPEPBHQ==:117 a=tAq5w2qrEf5dL+VNPEPBHQ==:17 a=5fC9_dISOduuxPbwqfAA:9 From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Zygo Blaxell , Josef Bacik , Goffredo Baroncelli Subject: [PATCH 5/5] btrfs: add allocator_hint mode Date: Mon, 1 Feb 2021 22:28:20 +0100 Message-Id: <20210201212820.64381-6-kreijack@libero.it> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210201212820.64381-1-kreijack@libero.it> References: <20210201212820.64381-1-kreijack@libero.it> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfD1wutszHKIlUZTwtbSYl9z/+e0rnW7j20qXXiecWT5AXhz1p+eoq7tfP/qkU18tBxI9hlc8b8fyHHAUb+UiBU9dxOKncAAE1Ax1BwTnR3D1zRLzikXh L+S6DNQY6KDcXRnYcJdQI2Bo7+IlDMykKZ6jEhGNNoB4oqwzsv+2kRnyr7C8B9E5yWP+X8UVILmdPSYpPNTAywRp04BU3U6AM2jF6VqBiFkf/cJZKfjVFhWW xPf6g9OdpZsmUnI/+mUGmXNUv30pNEKFUw1sSeRxD2gmi2RDNlpfYcVObDHregTq Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goffredo Baroncelli When this mode is enabled, the chunk allocation policy is modified as follow. Each disk may have a different tag: - BTRFS_DEV_ALLOCATION_PREFERRED_METADATA - BTRFS_DEV_ALLOCATION_METADATA_ONLY - BTRFS_DEV_ALLOCATION_DATA_ONLY - BTRFS_DEV_ALLOCATION_PREFERRED_DATA (default) Where: - ALLOCATION_PREFERRED_X means that it is preferred to use this disk for the X chunk type (the other type may be allowed when the space is low) - ALLOCATION_X_ONLY means that it is used *only* for the X chunk type. This means also that it is a preferred choice. Each time the allocator allocates a chunk of type X , first it takes the disks tagged as ALLOCATION_X_ONLY or ALLOCATION_PREFERRED_X; if the space is not enough, it uses also the disks tagged as ALLOCATION_METADATA_ONLY; if the space is not enough, it uses also the other disks, with the exception of the one marked as ALLOCATION_PREFERRED_Y, where Y the other type of chunk (i.e. not X). Signed-off-by: Goffredo Baroncelli --- fs/btrfs/volumes.c | 81 +++++++++++++++++++++++++++++++++++++++++++++- fs/btrfs/volumes.h | 1 + 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 68b346c5465d..57ee3e2fdac0 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4806,13 +4806,18 @@ static int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info, } /* - * sort the devices in descending order by max_avail, total_avail + * sort the devices in descending order by alloc_hint, + * max_avail, total_avail */ static int btrfs_cmp_device_info(const void *a, const void *b) { const struct btrfs_device_info *di_a = a; const struct btrfs_device_info *di_b = b; + if (di_a->alloc_hint > di_b->alloc_hint) + return -1; + if (di_a->alloc_hint < di_b->alloc_hint) + return 1; if (di_a->max_avail > di_b->max_avail) return -1; if (di_a->max_avail < di_b->max_avail) @@ -4939,6 +4944,15 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices, int ndevs = 0; u64 max_avail; u64 dev_offset; + int hint; + + static const char alloc_hint_map[BTRFS_DEV_ALLOCATION_MASK_COUNT] = { + [BTRFS_DEV_ALLOCATION_DATA_ONLY] = -1, + [BTRFS_DEV_ALLOCATION_PREFERRED_DATA] = 0, + [BTRFS_DEV_ALLOCATION_METADATA_ONLY] = 1, + [BTRFS_DEV_ALLOCATION_PREFERRED_METADATA] = 2 + /* the other values are set to 0 */ + }; /* * in the first pass through the devices list, we gather information @@ -4991,16 +5005,81 @@ static int gather_device_info(struct btrfs_fs_devices *fs_devices, devices_info[ndevs].max_avail = max_avail; devices_info[ndevs].total_avail = total_avail; devices_info[ndevs].dev = device; + + if (((ctl->type & BTRFS_BLOCK_GROUP_DATA) && + (ctl->type & BTRFS_BLOCK_GROUP_METADATA)) || + info->allocation_hint_mode == + BTRFS_ALLOCATION_HINT_DISABLED) { + /* + * if mixed bg or the allocator hint is + * disable, set all the alloc_hint + * fields to the same value, so the sorting + * is not affected + */ + devices_info[ndevs].alloc_hint = 0; + } else if(ctl->type & BTRFS_BLOCK_GROUP_DATA) { + hint = device->type & BTRFS_DEV_ALLOCATION_MASK; + + /* + * skip BTRFS_DEV_METADATA_ONLY disks + */ + if (hint == BTRFS_DEV_ALLOCATION_METADATA_ONLY) + continue; + /* + * if a data chunk must be allocated, + * sort also by hint (data disk + * higher priority) + */ + devices_info[ndevs].alloc_hint = -alloc_hint_map[hint]; + } else { /* BTRFS_BLOCK_GROUP_METADATA */ + hint = device->type & BTRFS_DEV_ALLOCATION_MASK; + + /* + * skip BTRFS_DEV_DATA_ONLY disks + */ + if (hint == BTRFS_DEV_ALLOCATION_DATA_ONLY) + continue; + /* + * if a data chunk must be allocated, + * sort also by hint (metadata hint + * higher priority) + */ + devices_info[ndevs].alloc_hint = alloc_hint_map[hint]; + } + ++ndevs; } ctl->ndevs = ndevs; + /* + * no devices available + */ + if (!ndevs) + return 0; + /* * now sort the devices by hole size / available space */ sort(devices_info, ndevs, sizeof(struct btrfs_device_info), btrfs_cmp_device_info, NULL); + /* + * select the minimum set of disks grouped by hint that + * can host the chunk + */ + ndevs = 0; + while (ndevs < ctl->ndevs) { + hint = devices_info[ndevs++].alloc_hint; + while (devices_info[ndevs].alloc_hint == hint && + ndevs < ctl->ndevs) + ndevs++; + if (ndevs >= ctl->devs_min) + break; + } + + BUG_ON(ndevs > ctl->ndevs); + ctl->ndevs = ndevs; + return 0; } diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index d776b7f55d56..31a3e4cf93b5 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -364,6 +364,7 @@ struct btrfs_device_info { u64 dev_offset; u64 max_avail; u64 total_avail; + int alloc_hint; }; struct btrfs_raid_attr {