From patchwork Thu Jan 27 19:57:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 12727233 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 74420C433FE for ; Thu, 27 Jan 2022 19:57:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343497AbiA0T5U (ORCPT ); Thu, 27 Jan 2022 14:57:20 -0500 Received: from santino.mail.tiscali.it ([213.205.33.245]:54804 "EHLO smtp.tiscali.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S245663AbiA0T5R (ORCPT ); Thu, 27 Jan 2022 14:57:17 -0500 Received: from venice.bhome ([78.14.151.50]) by santino.mail.tiscali.it with id nvxE2600k15VSme01vxGqk; Thu, 27 Jan 2022 19:57:16 +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 1/3] Rename btrfs_device->type to flags Date: Thu, 27 Jan 2022 20:57:07 +0100 Message-Id: X-Mailer: git-send-email 2.34.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=1643313436; bh=CAQPtjvqCWotgRYhnxRQ23RBAgwimGtz+gup4Fql+2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=SYbccM6KkzwOBZvjFN11ND/vLoMtHTQUTsCxbAftT1AQwcV7WOXKdFdHICnJo9rxd Bn2uFNO/taEOPolMJ59LuJfeSOcnDYjLJx0uIIS2eesAq962uQswchM7j6d1bksSw8 Fw7so/bob6bFGPk/AgrxaGdg9CmjwtagJAV1lldQ= Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goffredo Baroncelli As did in the kernel, rename the device->type to device->flag. Signed-off-by: Goffredo Baroncelli --- cmds/rescue-chunk-recover.c | 2 +- common/device-scan.c | 4 ++-- convert/common.c | 2 +- image/main.c | 6 +++--- kernel-shared/ctree.h | 8 ++++---- kernel-shared/disk-io.c | 2 +- kernel-shared/print-tree.c | 4 ++-- kernel-shared/volumes.c | 6 +++--- kernel-shared/volumes.h | 4 ++-- mkfs/common.c | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/cmds/rescue-chunk-recover.c b/cmds/rescue-chunk-recover.c index da24df4c..5d6c907b 100644 --- a/cmds/rescue-chunk-recover.c +++ b/cmds/rescue-chunk-recover.c @@ -1187,7 +1187,7 @@ static int __rebuild_device_items(struct btrfs_trans_handle *trans, key.offset = dev->devid; btrfs_set_stack_device_generation(dev_item, 0); - btrfs_set_stack_device_type(dev_item, dev->type); + btrfs_set_stack_device_flags(dev_item, dev->flags); btrfs_set_stack_device_id(dev_item, dev->devid); btrfs_set_stack_device_total_bytes(dev_item, dev->total_bytes); btrfs_set_stack_device_bytes_used(dev_item, dev->bytes_used); diff --git a/common/device-scan.c b/common/device-scan.c index 39b12c0e..d87172c9 100644 --- a/common/device-scan.c +++ b/common/device-scan.c @@ -155,7 +155,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans, uuid_generate(device->uuid); device->fs_info = fs_info; device->devid = 0; - device->type = 0; + device->flags = 0; device->io_width = io_width; device->io_align = io_align; device->sector_size = sectorsize; @@ -193,7 +193,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans, btrfs_set_super_bytenr(disk_super, BTRFS_SUPER_INFO_OFFSET); btrfs_set_stack_device_id(dev_item, device->devid); - btrfs_set_stack_device_type(dev_item, device->type); + btrfs_set_stack_device_flags(dev_item, device->flags); btrfs_set_stack_device_io_align(dev_item, device->io_align); btrfs_set_stack_device_io_width(dev_item, device->io_width); btrfs_set_stack_device_sector_size(dev_item, device->sector_size); diff --git a/convert/common.c b/convert/common.c index 00a7e553..c73c3b62 100644 --- a/convert/common.c +++ b/convert/common.c @@ -336,7 +336,7 @@ static int insert_temp_dev_item(int fd, struct extent_buffer *buf, btrfs_set_device_io_align(buf, dev_item, cfg->sectorsize); btrfs_set_device_io_width(buf, dev_item, cfg->sectorsize); btrfs_set_device_sector_size(buf, dev_item, cfg->sectorsize); - btrfs_set_device_type(buf, dev_item, 0); + btrfs_set_device_flags(buf, dev_item, 0); /* Super dev_item is not complete, copy the complete one to sb */ read_extent_buffer(buf, &super.dev_item, (unsigned long)dev_item, diff --git a/image/main.c b/image/main.c index 3125163d..209bdd75 100644 --- a/image/main.c +++ b/image/main.c @@ -2942,7 +2942,7 @@ static int update_disk_super_on_device(struct btrfs_fs_info *info, struct btrfs_super_block disk_super; char dev_uuid[BTRFS_UUID_SIZE]; char fs_uuid[BTRFS_UUID_SIZE]; - u64 devid, type, io_align, io_width; + u64 devid, flags, io_align, io_width; u64 sector_size, total_bytes, bytes_used; int fp = -1; int ret; @@ -2972,7 +2972,7 @@ static int update_disk_super_on_device(struct btrfs_fs_info *info, goto out; } - type = btrfs_device_type(leaf, dev_item); + flags = btrfs_device_flags(leaf, dev_item); io_align = btrfs_device_io_align(leaf, dev_item); io_width = btrfs_device_io_width(leaf, dev_item); sector_size = btrfs_device_sector_size(leaf, dev_item); @@ -2997,7 +2997,7 @@ static int update_disk_super_on_device(struct btrfs_fs_info *info, dev_item = &disk_super.dev_item; - btrfs_set_stack_device_type(dev_item, type); + btrfs_set_stack_device_flags(dev_item, flags); btrfs_set_stack_device_id(dev_item, devid); btrfs_set_stack_device_total_bytes(dev_item, total_bytes); btrfs_set_stack_device_bytes_used(dev_item, bytes_used); diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index 628539c0..720ecbab 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -249,8 +249,8 @@ struct btrfs_dev_item { /* minimal io size for this device */ __le32 sector_size; - /* type and info about this device */ - __le64 type; + /* device flags (e.g. allocation hint) */ + __le64 flags; /* expected generation for this device */ __le64 generation; @@ -1605,7 +1605,7 @@ static inline void btrfs_set_##name(type *s, u##bits val) \ s->member = cpu_to_le##bits(val); \ } -BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64); +BTRFS_SETGET_FUNCS(device_flags, struct btrfs_dev_item, flags, 64); BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64); BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64); BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32); @@ -1619,7 +1619,7 @@ BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8); BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8); BTRFS_SETGET_FUNCS(device_generation, struct btrfs_dev_item, generation, 64); -BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64); +BTRFS_SETGET_STACK_FUNCS(stack_device_flags, struct btrfs_dev_item, flags, 64); BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item, total_bytes, 64); BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item, diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c index e9d945ec..1a9e797a 100644 --- a/kernel-shared/disk-io.c +++ b/kernel-shared/disk-io.c @@ -2099,7 +2099,7 @@ int write_all_supers(struct btrfs_fs_info *fs_info) continue; btrfs_set_stack_device_generation(dev_item, 0); - btrfs_set_stack_device_type(dev_item, dev->type); + btrfs_set_stack_device_flags(dev_item, dev->flags); btrfs_set_stack_device_id(dev_item, dev->devid); btrfs_set_stack_device_total_bytes(dev_item, dev->total_bytes); btrfs_set_stack_device_bytes_used(dev_item, dev->bytes_used); diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c index bd75ae51..9bb0bd42 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -304,7 +304,7 @@ static void print_dev_item(struct extent_buffer *eb, btrfs_device_io_align(eb, dev_item), btrfs_device_io_width(eb, dev_item), btrfs_device_sector_size(eb, dev_item), - (unsigned long long)btrfs_device_type(eb, dev_item), + (unsigned long long)btrfs_device_flags(eb, dev_item), (unsigned long long)btrfs_device_generation(eb, dev_item), (unsigned long long)btrfs_device_start_offset(eb, dev_item), btrfs_device_group(eb, dev_item), @@ -2052,7 +2052,7 @@ void btrfs_print_superblock(struct btrfs_super_block *sb, int full) cmp_res ? "[match]" : "[DON'T MATCH]"); printf("dev_item.type\t\t%llu\n", (unsigned long long) - btrfs_stack_device_type(&sb->dev_item)); + btrfs_stack_device_flags(&sb->dev_item)); printf("dev_item.total_bytes\t%llu\n", (unsigned long long) btrfs_stack_device_total_bytes(&sb->dev_item)); printf("dev_item.bytes_used\t%llu\n", (unsigned long long) diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index 4274c378..82102723 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -992,7 +992,7 @@ int btrfs_add_device(struct btrfs_trans_handle *trans, device->devid = free_devid; btrfs_set_device_id(leaf, dev_item, device->devid); btrfs_set_device_generation(leaf, dev_item, 0); - btrfs_set_device_type(leaf, dev_item, device->type); + btrfs_set_device_flags(leaf, dev_item, device->flags); btrfs_set_device_io_align(leaf, dev_item, device->io_align); btrfs_set_device_io_width(leaf, dev_item, device->io_width); btrfs_set_device_sector_size(leaf, dev_item, device->sector_size); @@ -1050,7 +1050,7 @@ int btrfs_update_device(struct btrfs_trans_handle *trans, dev_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_item); btrfs_set_device_id(leaf, dev_item, device->devid); - btrfs_set_device_type(leaf, dev_item, device->type); + btrfs_set_device_flags(leaf, dev_item, device->flags); btrfs_set_device_io_align(leaf, dev_item, device->io_align); btrfs_set_device_io_width(leaf, dev_item, device->io_width); btrfs_set_device_sector_size(leaf, dev_item, device->sector_size); @@ -2302,7 +2302,7 @@ static int fill_device_from_item(struct extent_buffer *leaf, device->devid = btrfs_device_id(leaf, dev_item); device->total_bytes = btrfs_device_total_bytes(leaf, dev_item); device->bytes_used = btrfs_device_bytes_used(leaf, dev_item); - device->type = btrfs_device_type(leaf, dev_item); + device->flags = btrfs_device_flags(leaf, dev_item); device->io_align = btrfs_device_io_align(leaf, dev_item); device->io_width = btrfs_device_io_width(leaf, dev_item); device->sector_size = btrfs_device_sector_size(leaf, dev_item); diff --git a/kernel-shared/volumes.h b/kernel-shared/volumes.h index 5cfe7e39..1dd873c9 100644 --- a/kernel-shared/volumes.h +++ b/kernel-shared/volumes.h @@ -66,8 +66,8 @@ struct btrfs_device { /* minimal io size for this device */ u32 sector_size; - /* type and info about this device */ - u64 type; + /* device flags (e.g. allocation hint) */ + u64 flags; /* physical drive uuid (or lvm uuid) */ u8 uuid[BTRFS_UUID_SIZE]; diff --git a/mkfs/common.c b/mkfs/common.c index 9608d27f..2ebba7f3 100644 --- a/mkfs/common.c +++ b/mkfs/common.c @@ -445,7 +445,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) btrfs_set_device_io_align(buf, dev_item, cfg->sectorsize); btrfs_set_device_io_width(buf, dev_item, cfg->sectorsize); btrfs_set_device_sector_size(buf, dev_item, cfg->sectorsize); - btrfs_set_device_type(buf, dev_item, 0); + btrfs_set_device_flags(buf, dev_item, 0); write_extent_buffer(buf, super.dev_item.uuid, (unsigned long)btrfs_device_uuid(dev_item), From patchwork Thu Jan 27 19:57:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 12727234 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 E4836C433F5 for ; Thu, 27 Jan 2022 19:57:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343498AbiA0T5V (ORCPT ); Thu, 27 Jan 2022 14:57:21 -0500 Received: from santino.mail.tiscali.it ([213.205.33.245]:54814 "EHLO smtp.tiscali.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S245731AbiA0T5S (ORCPT ); Thu, 27 Jan 2022 14:57:18 -0500 Received: from venice.bhome ([78.14.151.50]) by santino.mail.tiscali.it with id nvxE2600k15VSme01vxGrN; Thu, 27 Jan 2022 19:57:16 +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/3] Rename dev_item.type in flags in the command output. Date: Thu, 27 Jan 2022 20:57:08 +0100 Message-Id: <86bac5161db5a240cdfbd30cde9d045da1237757.1643313144.git.kreijack@inwind.it> X-Mailer: git-send-email 2.34.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=1643313436; bh=sKSHtOFQNJU1lSsFJiLfOSQbX4y6LEZ21uSJ2mpGFxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=vYdumxMqlu0HaMmV2QCmC2KY/ZbVqAtZU4Orbjai+iwRo76jj4faqxC6m05zdCzSB pgzUiQnIGksRe/W1Y3wcPWjHNCAux3EuxYqAR7s2+tTxLqxJGfcm1Q1QVK4TMY7cCJ STE3pM0+WxPHdzJw1BbxI1uZgr7U4uTbs2BAbOvI= Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goffredo Baroncelli As did in the kernel, rename the device->type to device->flags in the printf() functions. Signed-off-by: Goffredo Baroncelli --- kernel-shared/print-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c index 9bb0bd42..3bab0709 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -293,7 +293,7 @@ static void print_dev_item(struct extent_buffer *eb, BTRFS_UUID_SIZE); uuid_unparse(fsid, fsid_str); printf("\t\tdevid %llu total_bytes %llu bytes_used %llu\n" - "\t\tio_align %u io_width %u sector_size %u type %llu\n" + "\t\tio_align %u io_width %u sector_size %u flags %llu\n" "\t\tgeneration %llu start_offset %llu dev_group %u\n" "\t\tseek_speed %hhu bandwidth %hhu\n" "\t\tuuid %s\n" @@ -2051,7 +2051,7 @@ void btrfs_print_superblock(struct btrfs_super_block *sb, int full) printf("dev_item.fsid\t\t%s %s\n", buf, cmp_res ? "[match]" : "[DON'T MATCH]"); - printf("dev_item.type\t\t%llu\n", (unsigned long long) + printf("dev_item.flags\t\t%llu\n", (unsigned long long) btrfs_stack_device_flags(&sb->dev_item)); printf("dev_item.total_bytes\t%llu\n", (unsigned long long) btrfs_stack_device_total_bytes(&sb->dev_item)); From patchwork Thu Jan 27 19:57:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 12727235 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 66845C4332F for ; Thu, 27 Jan 2022 19:57:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343500AbiA0T5V (ORCPT ); Thu, 27 Jan 2022 14:57:21 -0500 Received: from santino.mail.tiscali.it ([213.205.33.245]:54832 "EHLO smtp.tiscali.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1343494AbiA0T5T (ORCPT ); Thu, 27 Jan 2022 14:57:19 -0500 Received: from venice.bhome ([78.14.151.50]) by santino.mail.tiscali.it with id nvxE2600k15VSme01vxGrt; Thu, 27 Jan 2022 19:57:17 +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 3/3] Read/change the allocation_hint prop when unmounted Date: Thu, 27 Jan 2022 20:57:09 +0100 Message-Id: <1c6a98da2f8c4a7400f0a7e8862f697b9e8993a1.1643313144.git.kreijack@inwind.it> X-Mailer: git-send-email 2.34.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=1643313437; bh=bTqA0gtpaBglS1OlwgBE85MoyAQuaipEp1r/2GrGpu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=y4FfiXTNXYg+rdMxTNa742Q68xJqeO7csAEiClIsKwfdoLoeRR6AeErEyaPXCfGOA VMy4zLe7dNTtDngoChA5dkO3cqXq88zRxAPvo63bvpI0h/3uwETc4ITcOgKq6pmxJm 2AyCAmW99ymKGPTm7z4GiSRQgUErKiNnwzqc9NGE= Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Goffredo Baroncelli This patch enable the changing of the allocation_hint even when the filesystem is unmounted. Signed-off-by: Goffredo Baroncelli --- cmds/property.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/cmds/property.c b/cmds/property.c index a409f4e9..55de7e6b 100644 --- a/cmds/property.c +++ b/cmds/property.c @@ -28,6 +28,9 @@ #include "cmds/commands.h" #include "cmds/props.h" #include "kernel-shared/ctree.h" +#include "kernel-shared/volumes.h" +#include "kernel-shared/disk-io.h" +#include "kernel-shared/transaction.h" #include "common/open-utils.h" #include "common/utils.h" #include "common/help.h" @@ -377,6 +380,115 @@ static struct ull_charp_pair_t { {0, NULL} }; +static int find_device(const char *object, struct btrfs_device **device_ret) +{ + struct btrfs_fs_devices *fs_devices; + struct list_head *fs_uuids; + struct stat sttarget, st; + + if (stat(object, &sttarget) < 0) + return -EACCES; + + fs_uuids = btrfs_scanned_uuids(); + + list_for_each_entry(fs_devices, fs_uuids, list) { + struct btrfs_device *device; + + list_for_each_entry(device, &fs_devices->devices, dev_list) { + + if (stat(device->name, &st) < 0) + return -EACCES; + + if (st.st_rdev == sttarget.st_rdev) { + *device_ret = device; + return 0; + } + } + } + + return -ENODEV; +} + +static int prop_allocation_hint_unmounted(const char *object, + const char *name, + const char *val) +{ + + struct btrfs_device *device; + int ret; + struct btrfs_root *root = NULL; + + root = open_ctree(object, btrfs_sb_offset(0), 0); + if (!root) + return -ENODEV; + + ret = find_device(object, &device); + if (ret) + goto out; + + if (!val) { + int i; + u64 v = device->flags & BTRFS_DEV_ALLOCATION_HINT_MASK; + + for (i = 0 ; allocation_hint_description[i].descr ; i++) + if (v == allocation_hint_description[i].value) + break; + + if (allocation_hint_description[i].descr) + printf("allocation_hint=%s\n", + allocation_hint_description[i].descr); + else + printf("allocation_hint=unknown:%llu\n", v); + ret = 0; + } else { + struct btrfs_trans_handle *trans; + int i; + u64 v; + + for (i = 0 ; allocation_hint_description[i].descr ; i++) + if (!strcmp(val, allocation_hint_description[i].descr)) + break; + + if (allocation_hint_description[i].descr) { + v = allocation_hint_description[i].value; + } else if (sscanf(val, "%llu", &v) != 1) { + error("Invalid value '%s'\n", val); + ret = -3; + goto out; + } + if (v & ~BTRFS_DEV_ALLOCATION_HINT_MASK) { + error("Invalid value '%s'\n", val); + ret = -3; + goto out; + } + + trans = btrfs_start_transaction(device->fs_info->chunk_root, 1); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + goto out; + } + + /* Manually update the device item in chunk tree */ + ret = btrfs_update_device(trans, device); + if (ret < 0) { + errno = -ret; + goto out; + } + + /* + * Commit transaction not only to save the above change but also update + * the device item in super block. + */ + ret = btrfs_commit_transaction(trans, device->fs_info->chunk_root); + + } +out: + if (root) + close_ctree(root); + return ret; + +} + static int prop_allocation_hint(enum prop_object_type type, const char *object, const char *name, @@ -394,6 +506,9 @@ static int prop_allocation_hint(enum prop_object_type type, ret = btrfs_find_devid_uuid_by_dev(object, &devid, sysfs_file + sizeof(BTRFSYSFS) - 1); + if (ret == -ENODEV) + return prop_allocation_hint_unmounted(object, name, val); + if (ret) goto out;