From patchwork Wed May 22 06:02:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13670447 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B91B378C83 for ; Wed, 22 May 2024 06:03:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357833; cv=none; b=r7dKApXZmQJtbFnnawIEjHJeWxZTVsdipMaJDGRQMQk2U/geNN5O8893irNxDx1zLaLVrSPKLWWtQyjoUc9A+R5xDFh6IvM2/KSlcZTLwrfQ9IenoA+fqpt6jgrhzY3YXBwSJbGA5h+o4R9s5bKuEBssy3eFEEM52UVt1ckVun4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357833; c=relaxed/simple; bh=n+5xSJcL+VuS5aRFWqkQXOLHbXD/Z38/eAHI0/C0xJs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CBH3UcorjVWyef3gRp53yS4PVYLl4Ogq6nW0tr7LZscm5eDjFd8KmcI8D6no+3F5oUbasTeiUU6ULb6bLSL+tt0Dhm9zHGDoCoIMpqGNIiYXlndMAsDeQEg1ONtngBA5NDKz+IU6v3iwsXp1lNUEmszricFJ6TiFLJ72wZHB7YI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=IsGRBS0f; arc=none smtp.client-ip=68.232.141.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="IsGRBS0f" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716357831; x=1747893831; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=n+5xSJcL+VuS5aRFWqkQXOLHbXD/Z38/eAHI0/C0xJs=; b=IsGRBS0fGvPAo0zE+a49gQASg81bkXdf+ePazHsi/vxpM/5jdrrkVYOj ocbZ5QpkVVIe4myDPfvR7wY9IFVIXYHyP0BQCg3g/yjVDCzBmsWiqpBC+ day6eu99e7Iz5zYofKXi2slEx3A+ZXY0msBHXS0hHm90ohZ5ZlXXJ7zC3 G1Obj/SdlBLlgwr6mAri9CFWiFhyk93h1v2luMO2MeE0R6Vpvc+iaqIIi lE9Ldah+adyrXD0G9GdMkeLFRy9Sodagk/6JvZzZv4CBTE8Rfi6U0zvUR Q7R5ZqlOOkfI4MRpecuqXCUcCLkVE4CRQ6l45GDomSpyJ1ysWsz1WPCsk g==; X-CSE-ConnectionGUID: Ovuvk8htQpWhKgj6Bxj53A== X-CSE-MsgGUID: wbZgPC8HRp6uMjYcSX1Emg== X-IronPort-AV: E=Sophos;i="6.08,179,1712592000"; d="scan'208";a="17170967" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 May 2024 14:03:42 +0800 IronPort-SDR: 664d7d1f_1/e5l3AgLdXghWm1HUAs1K+uJtB6boRfhfA2ERg1MZr37fw 4mOZ/bzfAxinGqrVhYe9SFY5iK7WCFq6++NIlSw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 21 May 2024 22:05:35 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.60]) by uls-op-cesaip02.wdc.com with ESMTP; 21 May 2024 23:03:39 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v3 01/10] btrfs-progs: rename block_count to byte_count Date: Wed, 22 May 2024 15:02:23 +0900 Message-ID: <20240522060232.3569226-2-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522060232.3569226-1-naohiro.aota@wdc.com> References: <20240522060232.3569226-1-naohiro.aota@wdc.com> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 block_count and dev_block_count are counting the size in bytes. And, comparing them with e.g, "min_dev_size" is confusing. Rename them to represent the unit better. Signed-off-by: Naohiro Aota --- common/device-utils.c | 28 +++++++++++----------- mkfs/main.c | 56 +++++++++++++++++++++---------------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/common/device-utils.c b/common/device-utils.c index d086e9ea2564..86942e0c7041 100644 --- a/common/device-utils.c +++ b/common/device-utils.c @@ -222,11 +222,11 @@ out: * - reset zones * - delete end of the device */ -int btrfs_prepare_device(int fd, const char *file, u64 *block_count_ret, - u64 max_block_count, unsigned opflags) +int btrfs_prepare_device(int fd, const char *file, u64 *byte_count_ret, + u64 max_byte_count, unsigned opflags) { struct btrfs_zoned_device_info *zinfo = NULL; - u64 block_count; + u64 byte_count; struct stat st; int i, ret; @@ -236,13 +236,13 @@ int btrfs_prepare_device(int fd, const char *file, u64 *block_count_ret, return 1; } - block_count = device_get_partition_size_fd_stat(fd, &st); - if (block_count == 0) { + byte_count = device_get_partition_size_fd_stat(fd, &st); + if (byte_count == 0) { error("unable to determine size of %s", file); return 1; } - if (max_block_count) - block_count = min(block_count, max_block_count); + if (max_byte_count) + byte_count = min(byte_count, max_byte_count); if (opflags & PREP_DEVICE_ZONED) { ret = btrfs_get_zone_info(fd, file, &zinfo); @@ -276,18 +276,18 @@ int btrfs_prepare_device(int fd, const char *file, u64 *block_count_ret, if (discard_supported(file)) { if (opflags & PREP_DEVICE_VERBOSE) printf("Performing full device TRIM %s (%s) ...\n", - file, pretty_size(block_count)); - device_discard_blocks(fd, 0, block_count); + file, pretty_size(byte_count)); + device_discard_blocks(fd, 0, byte_count); } } - ret = zero_dev_clamped(fd, zinfo, 0, ZERO_DEV_BYTES, block_count); + ret = zero_dev_clamped(fd, zinfo, 0, ZERO_DEV_BYTES, byte_count); for (i = 0 ; !ret && i < BTRFS_SUPER_MIRROR_MAX; i++) ret = zero_dev_clamped(fd, zinfo, btrfs_sb_offset(i), - BTRFS_SUPER_INFO_SIZE, block_count); + BTRFS_SUPER_INFO_SIZE, byte_count); if (!ret && (opflags & PREP_DEVICE_ZERO_END)) - ret = zero_dev_clamped(fd, zinfo, block_count - ZERO_DEV_BYTES, - ZERO_DEV_BYTES, block_count); + ret = zero_dev_clamped(fd, zinfo, byte_count - ZERO_DEV_BYTES, + ZERO_DEV_BYTES, byte_count); if (ret < 0) { errno = -ret; @@ -302,7 +302,7 @@ int btrfs_prepare_device(int fd, const char *file, u64 *block_count_ret, } free(zinfo); - *block_count_ret = block_count; + *byte_count_ret = byte_count; return 0; err: diff --git a/mkfs/main.c b/mkfs/main.c index a467795d4428..950f76101058 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -80,8 +80,8 @@ static int opt_oflags = O_RDWR; struct prepare_device_progress { int fd; char *file; - u64 dev_block_count; - u64 block_count; + u64 dev_byte_count; + u64 byte_count; int ret; }; @@ -1159,8 +1159,8 @@ static void *prepare_one_device(void *ctx) } prepare_ctx->ret = btrfs_prepare_device(prepare_ctx->fd, prepare_ctx->file, - &prepare_ctx->dev_block_count, - prepare_ctx->block_count, + &prepare_ctx->dev_byte_count, + prepare_ctx->byte_count, (bconf.verbose ? PREP_DEVICE_VERBOSE : 0) | (opt_zero_end ? PREP_DEVICE_ZERO_END : 0) | (opt_discard ? PREP_DEVICE_DISCARD : 0) | @@ -1204,8 +1204,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv) bool metadata_profile_set = false; u64 data_profile = 0; bool data_profile_set = false; - u64 block_count = 0; - u64 dev_block_count = 0; + u64 byte_count = 0; + u64 dev_byte_count = 0; bool mixed = false; char *label = NULL; int nr_global_roots = sysconf(_SC_NPROCESSORS_ONLN); @@ -1347,7 +1347,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) sectorsize = arg_strtou64_with_suffix(optarg); break; case 'b': - block_count = arg_strtou64_with_suffix(optarg); + byte_count = arg_strtou64_with_suffix(optarg); opt_zero_end = false; break; case 'v': @@ -1623,34 +1623,34 @@ int BOX_MAIN(mkfs)(int argc, char **argv) * Block_count not specified, use file/device size first. * Or we will always use source_dir_size calculated for mkfs. */ - if (!block_count) - block_count = device_get_partition_size_fd_stat(fd, &statbuf); + if (!byte_count) + byte_count = device_get_partition_size_fd_stat(fd, &statbuf); source_dir_size = btrfs_mkfs_size_dir(source_dir, sectorsize, min_dev_size, metadata_profile, data_profile); - if (block_count < source_dir_size) { + if (byte_count < source_dir_size) { if (S_ISREG(statbuf.st_mode)) { - block_count = source_dir_size; + byte_count = source_dir_size; } else { warning( "the target device %llu (%s) is smaller than the calculated source directory size %llu (%s), mkfs may fail", - block_count, pretty_size(block_count), + byte_count, pretty_size(byte_count), source_dir_size, pretty_size(source_dir_size)); } } - ret = zero_output_file(fd, block_count); + ret = zero_output_file(fd, byte_count); if (ret) { error("unable to zero the output file"); close(fd); goto error; } /* our "device" is the new image file */ - dev_block_count = block_count; + dev_byte_count = byte_count; close(fd); } - /* Check device/block_count after the nodesize is determined */ - if (block_count && block_count < min_dev_size) { + /* Check device/byte_count after the nodesize is determined */ + if (byte_count && byte_count < min_dev_size) { error("size %llu is too small to make a usable filesystem", - block_count); + byte_count); error("minimum size for btrfs filesystem is %llu", min_dev_size); goto error; @@ -1661,9 +1661,9 @@ int BOX_MAIN(mkfs)(int argc, char **argv) * 1 zone for a metadata block group * 1 zone for a data block group */ - if (opt_zoned && block_count && block_count < 5 * zone_size(file)) { + if (opt_zoned && byte_count && byte_count < 5 * zone_size(file)) { error("size %llu is too small to make a usable filesystem", - block_count); + byte_count); error("minimum size for a zoned btrfs filesystem is %llu", min_dev_size); goto error; @@ -1741,8 +1741,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv) /* Start threads */ for (i = 0; i < device_count; i++) { prepare_ctx[i].file = argv[optind + i - 1]; - prepare_ctx[i].block_count = block_count; - prepare_ctx[i].dev_block_count = block_count; + prepare_ctx[i].byte_count = byte_count; + prepare_ctx[i].dev_byte_count = byte_count; ret = pthread_create(&t_prepare[i], NULL, prepare_one_device, &prepare_ctx[i]); if (ret) { @@ -1763,16 +1763,16 @@ int BOX_MAIN(mkfs)(int argc, char **argv) goto error; } - dev_block_count = prepare_ctx[0].dev_block_count; - if (block_count && block_count > dev_block_count) { + dev_byte_count = prepare_ctx[0].dev_byte_count; + if (byte_count && byte_count > dev_byte_count) { error("%s is smaller than requested size, expected %llu, found %llu", - file, block_count, dev_block_count); + file, byte_count, dev_byte_count); goto error; } /* To create the first block group and chunk 0 in make_btrfs */ system_group_size = (opt_zoned ? zone_size(file) : BTRFS_MKFS_SYSTEM_GROUP_SIZE); - if (dev_block_count < system_group_size) { + if (dev_byte_count < system_group_size) { error("device is too small to make filesystem, must be at least %llu", system_group_size); goto error; @@ -1794,7 +1794,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) mkfs_cfg.label = label; memcpy(mkfs_cfg.fs_uuid, fs_uuid, sizeof(mkfs_cfg.fs_uuid)); memcpy(mkfs_cfg.dev_uuid, dev_uuid, sizeof(mkfs_cfg.dev_uuid)); - mkfs_cfg.num_bytes = dev_block_count; + mkfs_cfg.num_bytes = dev_byte_count; mkfs_cfg.nodesize = nodesize; mkfs_cfg.sectorsize = sectorsize; mkfs_cfg.stripesize = stripesize; @@ -1889,7 +1889,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) file); continue; } - dev_block_count = prepare_ctx[i].dev_block_count; + dev_byte_count = prepare_ctx[i].dev_byte_count; if (prepare_ctx[i].ret) { errno = -prepare_ctx[i].ret; @@ -1898,7 +1898,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) } ret = btrfs_add_to_fsid(trans, root, prepare_ctx[i].fd, - prepare_ctx[i].file, dev_block_count, + prepare_ctx[i].file, dev_byte_count, sectorsize, sectorsize, sectorsize); if (ret) { error("unable to add %s to filesystem: %d", From patchwork Wed May 22 06:02:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13670443 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C757B7710B for ; Wed, 22 May 2024 06:03:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357829; cv=none; b=AkLJiLWlOKsBACAC5KlMjaSS8aBAF6daIzkFVxTH0/VSxaH4vlLE2DKOv4o2ERa3sf9A0OfPSa/rsc0ovUWuPcGICeMBvVztYtdbeAlWy15BZP1kyDHznZD459BswRhX8dKNFRUyDsK5Zn0oRpCm1vVWiPf/48V9N620xFwJP0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357829; c=relaxed/simple; bh=eQ7qyZA19r71928d/RA8iSLKqiOcKrFbwrcrBkRKmY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZOIJWxO2CVJDG3ABDS472NRvFsWFZatZnWpXuX1jTaJKq5w96SaD+/exeMq44eYpuLNjucaJLYe7whWiuL+5X4X1chGtdtapLwBvw82fzQvH6VdF3rRoYHoO3tY0slexesSdIRlKR6t/semALHX9eW6oZF7QoZmzYxuqiH5WOHg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=HOCnt5/K; arc=none smtp.client-ip=216.71.153.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="HOCnt5/K" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716357827; x=1747893827; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eQ7qyZA19r71928d/RA8iSLKqiOcKrFbwrcrBkRKmY4=; b=HOCnt5/KJQpSGCZYjus+tAm9GbwIyUBFWqomKviKn6eoqma9l/9WaR4N NDYkn+N1y5G7AS7gyHjupSfFEoag0sQB5JF31e/DMBqbnPp+l9vVtAohr jUqx1vg01JlQpuDtOClnoElni3OTo05qE+ref3xUApP3QI3gl9d/RVtfj dN0OJNtBcK681BPqcGTTWTeL/RNHwGBvJfeN8nol3vu+o46IMxzZfzIzl 1GXto/LU1UMpMeU43KiOtXA9t12oKqcM+C6U4fCaOYyWb5hSqmE3md1BU DuoCpwqJPV+yTVG3ZL95TL+tDqFHp3vscTHw3pSha3MfDeiZ1bcT1XOUC w==; X-CSE-ConnectionGUID: fN52nwXGSc6owJvvAZakeg== X-CSE-MsgGUID: sHqZpfHGStWVSLLi6jiV6Q== X-IronPort-AV: E=Sophos;i="6.08,179,1712592000"; d="scan'208";a="16664802" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 May 2024 14:03:42 +0800 IronPort-SDR: 664d7d20_vkQSYLvAqWCjiRzRWtNYuWPgQVDDIaKJd11ML/Omt9H6UX7 BHoPPN068j7gdMz+iSc60vUto9Z5JovSbHWEJOQ== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 21 May 2024 22:05:36 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.60]) by uls-op-cesaip02.wdc.com with ESMTP; 21 May 2024 23:03:40 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v3 02/10] btrfs-progs: mkfs: remove duplicated device size check Date: Wed, 22 May 2024 15:02:24 +0900 Message-ID: <20240522060232.3569226-3-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522060232.3569226-1-naohiro.aota@wdc.com> References: <20240522060232.3569226-1-naohiro.aota@wdc.com> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 test_minimum_size() already checks if each device can host the initial block groups. There is no need to check if the first device can host the initial system chunk again. Signed-off-by: Naohiro Aota --- mkfs/main.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/mkfs/main.c b/mkfs/main.c index 950f76101058..f6f67abf3b0e 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -1189,7 +1189,6 @@ int BOX_MAIN(mkfs)(int argc, char **argv) struct prepare_device_progress *prepare_ctx = NULL; struct mkfs_allocation allocation = { 0 }; struct btrfs_mkfs_config mkfs_cfg; - u64 system_group_size; /* Options */ bool force_overwrite = false; struct btrfs_mkfs_features features = btrfs_mkfs_default_features; @@ -1770,14 +1769,6 @@ int BOX_MAIN(mkfs)(int argc, char **argv) goto error; } - /* To create the first block group and chunk 0 in make_btrfs */ - system_group_size = (opt_zoned ? zone_size(file) : BTRFS_MKFS_SYSTEM_GROUP_SIZE); - if (dev_byte_count < system_group_size) { - error("device is too small to make filesystem, must be at least %llu", - system_group_size); - goto error; - } - if (btrfs_bg_type_to_tolerated_failures(metadata_profile) < btrfs_bg_type_to_tolerated_failures(data_profile)) warning("metadata has lower redundancy than data!\n"); From patchwork Wed May 22 06:02:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13670442 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E185554784 for ; Wed, 22 May 2024 06:03:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357828; cv=none; b=Cd5LU7Thfz/7ekGxwE4UA83zYbIZcxDkNhI4dwN0SvFeIVzzk9JfX35pG/jwv/U+rBw3+UfjQglJl+i14QO5FjHY+/ztD0JoL03JwHbxzKeu13CUK8ypQVcPiu7mJXdUD6HHiV8VaiZ5NNdwnlDldayzSbYt4a58/5iWtcMLqaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357828; c=relaxed/simple; bh=mqtq6Zofgd59bWW6LEF9iOeD0q1uUFf/xD1zDyu48hg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uBG/WfYrKofkDRBsf0FjtkABBLwjt3bSe/8TGn7KYYORjQGERD9QAQfiznLR3bRqMUh6yFYMl7QKyutrLLQLyluOzWMFnvZzRMQk3gyoQvssJppCfS4J1O0rtAW5JJRJCdBwiYwzR6JEVjq5FJWeiApIS9hwLSX+OjAtRjtE/5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=djWMqdJS; arc=none smtp.client-ip=216.71.153.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="djWMqdJS" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716357827; x=1747893827; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mqtq6Zofgd59bWW6LEF9iOeD0q1uUFf/xD1zDyu48hg=; b=djWMqdJSTus7AY4N6NH9IKxXNM86v8X6Mh/vCsmcZ71PZhyv1VLwwHei Z3b3lAtl4AfjvS08hFHhSLujP8/8Y3EeVloQmYMFHpLctl5hqQbHnyUXA uyzYFRBHi5W0CbRSizamum0LPplVCqD91xlO/5rnFSYiMcBJim9hJnOCl wzgyiElAqL3bF5BPbSFvdfeppd2mfawWNI/TURreejr4Sl+wSbWMmDLt1 E36q0WTXD2emz1nhQvioOmKmCf9tmwmjVRuZEIlrjUuOZWIRPSlzYafGz XWE3x1RQWFONttrVOxYGbkt85lusm/2Eivd8bVDH7YEsPZ43A6a7EEUDo A==; X-CSE-ConnectionGUID: /ZTuGSmhTPmV3GZSI9eihw== X-CSE-MsgGUID: o2AgooZxT8qByx9ANTlsZw== X-IronPort-AV: E=Sophos;i="6.08,179,1712592000"; d="scan'208";a="16664803" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 May 2024 14:03:42 +0800 IronPort-SDR: 664d7d21_2WzOM9s1gRC7w8CrE6IjcUa4s2kvj/QLZWw/PfkakSl3dpm mNK+WFp7MWxUj6woNz0KdhMmv3MiF7a0O2sGedw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 21 May 2024 22:05:37 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.60]) by uls-op-cesaip02.wdc.com with ESMTP; 21 May 2024 23:03:41 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v3 03/10] btrfs-progs: mkfs: unify zoned mode minimum size calc into btrfs_min_dev_size() Date: Wed, 22 May 2024 15:02:25 +0900 Message-ID: <20240522060232.3569226-4-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522060232.3569226-1-naohiro.aota@wdc.com> References: <20240522060232.3569226-1-naohiro.aota@wdc.com> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We are going to implement a better minimum size calculation for the zoned mode. Move the current logic to btrfs_min_dev_size() and unify the size checking path. Also, convert "int mixed" to "bool mixed" while at it. Signed-off-by: Naohiro Aota --- mkfs/common.c | 11 ++++++++++- mkfs/common.h | 2 +- mkfs/main.c | 22 +++++----------------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/mkfs/common.c b/mkfs/common.c index e61020002417..2550c2219c90 100644 --- a/mkfs/common.c +++ b/mkfs/common.c @@ -811,13 +811,22 @@ static u64 btrfs_min_global_blk_rsv_size(u32 nodesize) return (u64)nodesize << 10; } -u64 btrfs_min_dev_size(u32 nodesize, int mixed, u64 meta_profile, +u64 btrfs_min_dev_size(u32 nodesize, bool mixed, u64 zone_size, u64 meta_profile, u64 data_profile) { u64 reserved = 0; u64 meta_size; u64 data_size; + /* + * 2 zones for the primary superblock + * 1 zone for the system block group + * 1 zone for a metadata block group + * 1 zone for a data block group + */ + if (zone_size) + return 5 * zone_size; + if (mixed) return 2 * (BTRFS_MKFS_SYSTEM_GROUP_SIZE + btrfs_min_global_blk_rsv_size(nodesize)); diff --git a/mkfs/common.h b/mkfs/common.h index d9183c997bb2..de0ff57beee8 100644 --- a/mkfs/common.h +++ b/mkfs/common.h @@ -105,7 +105,7 @@ struct btrfs_mkfs_config { int make_btrfs(int fd, struct btrfs_mkfs_config *cfg); int btrfs_make_root_dir(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 objectid); -u64 btrfs_min_dev_size(u32 nodesize, int mixed, u64 meta_profile, +u64 btrfs_min_dev_size(u32 nodesize, bool mixed, u64 zone_size, u64 meta_profile, u64 data_profile); int test_minimum_size(const char *file, u64 min_dev_size); int is_vol_small(const char *file); diff --git a/mkfs/main.c b/mkfs/main.c index f6f67abf3b0e..a437ecc40c7f 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -1588,8 +1588,9 @@ int BOX_MAIN(mkfs)(int argc, char **argv) goto error; } - min_dev_size = btrfs_min_dev_size(nodesize, mixed, metadata_profile, - data_profile); + min_dev_size = btrfs_min_dev_size(nodesize, mixed, + opt_zoned ? zone_size(file) : 0, + metadata_profile, data_profile); /* * Enlarge the destination file or create a new one, using the size * calculated from source dir. @@ -1650,21 +1651,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv) if (byte_count && byte_count < min_dev_size) { error("size %llu is too small to make a usable filesystem", byte_count); - error("minimum size for btrfs filesystem is %llu", - min_dev_size); - goto error; - } - /* - * 2 zones for the primary superblock - * 1 zone for the system block group - * 1 zone for a metadata block group - * 1 zone for a data block group - */ - if (opt_zoned && byte_count && byte_count < 5 * zone_size(file)) { - error("size %llu is too small to make a usable filesystem", - byte_count); - error("minimum size for a zoned btrfs filesystem is %llu", - min_dev_size); + error("minimum size for a %sbtrfs filesystem is %llu", + opt_zoned ? "zoned mode " : "", min_dev_size); goto error; } From patchwork Wed May 22 06:02:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13670441 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4C221C6B4 for ; Wed, 22 May 2024 06:03:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357826; cv=none; b=XsNTCDXOIh90Mjx4f1ltlRxIIzCYwLLsk59i2C29hwmXud7g6NgPmsswG4yu6uMA/IbxD89s0wrR5HnnxGUPWs8zjaJqhaUM6ReUezDvUlV5HXdUYUlEB0H9kuDTvrK1Z7R2hiorkhfFLwpvd+F+ZvAXe92gOM0gA5IxQaHP9cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357826; c=relaxed/simple; bh=mqFV2FaVrGXTpH+fUM5qiY8Frwq6H/J1hKtT8VeNFqs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TCM0kTeawpEzmeRIXJVI4WLsE+nKGEmYSZn4LOdS1tKfkyUSueMsw/Ql8QNLJb7Xy7v6y7qjsei47ExW10sNjnX9CCCkjZh36xdCmJFV7Qdvmq/u0AWTQN823pKw4nBw600NsBKbBYv9Koc7C2GJGX8HJQFRFGDHtFAqxczGNAU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=F+2SzmEc; arc=none smtp.client-ip=216.71.153.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="F+2SzmEc" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716357825; x=1747893825; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mqFV2FaVrGXTpH+fUM5qiY8Frwq6H/J1hKtT8VeNFqs=; b=F+2SzmEcHgoE8qPzyUtct1VoZSNao3QRtS57aYtjHWrSs8m8ga+cz1RY geco4Z3nn3R07fY4a2yiGSa9WXMQ0RJcEX/PDqNk2wcMOUFbyFMgZC39A 9BbNXWJSdYDdrJ4gP9E/D7Qg/BpFL4S6JQ0a56mkNoGet9LDvge1r+Wiu 7GtLP0qb7yB9bCMiVHh5pKMDBABn05isyqm+QHzOl4zQeYM+5DcTmXClD nKZ0y6iXPqzuHckb3d6WQKAFNcbgCyYkVSbXL/QBzVOjsGkjZhBPM/jBX udIwS6DwmzR/ZmnomT7lbvVmadPL3pq5U2pEJGAlkaFD8SIqb8aBrETYz A==; X-CSE-ConnectionGUID: EvNFiAWYSW+VCzte1eMPug== X-CSE-MsgGUID: yC4oRtUGQO+iGfpllsSc4Q== X-IronPort-AV: E=Sophos;i="6.08,179,1712592000"; d="scan'208";a="16664804" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 May 2024 14:03:42 +0800 IronPort-SDR: 664d7d21_0U7YxcEyt9mVMYvjUgGFuvCu+YsNqDZcqRBeL0lwqfXdpEZ vm6UlRxbSGzaPO+ELDK7HDfkeebQBO4ILAYcr1A== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 21 May 2024 22:05:38 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.60]) by uls-op-cesaip02.wdc.com with ESMTP; 21 May 2024 23:03:41 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v3 04/10] btrfs-progs: mkfs: fix minimum size calculation for zoned mode Date: Wed, 22 May 2024 15:02:26 +0900 Message-ID: <20240522060232.3569226-5-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522060232.3569226-1-naohiro.aota@wdc.com> References: <20240522060232.3569226-1-naohiro.aota@wdc.com> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, we check if a device is larger than 5 zones to determine we can create btrfs on the device or not. Actually, we need more zones to create DUP block groups, so it fails with "ERROR: not enough free space to allocate chunk". Implement proper support for non-SINGLE profile. Also, current code does not ensure we can create tree-log BG and data relocation BG, which are essential for the real usage. Count them as requirement too. The calculation for a regular btrfs is also adjusted to use dev_stripes style. Signed-off-by: Naohiro Aota --- mkfs/common.c | 67 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/mkfs/common.c b/mkfs/common.c index 2550c2219c90..1b09c8b1a673 100644 --- a/mkfs/common.c +++ b/mkfs/common.c @@ -817,15 +817,50 @@ u64 btrfs_min_dev_size(u32 nodesize, bool mixed, u64 zone_size, u64 meta_profile u64 reserved = 0; u64 meta_size; u64 data_size; + u64 dev_stripes; - /* - * 2 zones for the primary superblock - * 1 zone for the system block group - * 1 zone for a metadata block group - * 1 zone for a data block group - */ - if (zone_size) - return 5 * zone_size; + if (zone_size) { + /* 2 zones for the primary superblock. */ + reserved += 2 * zone_size; + + /* + * 1 zone each for the initial SINGLE system, SINGLE + * metadata, and SINGLE data block group + */ + reserved += 3 * zone_size; + + /* + * On non-SINGLE profile, we need to add real system and + * metadata block group. And, we also need to add a space + * for a tree-log block group. + * + * SINGLE profile can reuse the initial block groups and + * only need to add a tree-log block group + */ + dev_stripes = (meta_profile & BTRFS_BLOCK_GROUP_DUP) ? 2 : 1; + if (meta_profile & BTRFS_BLOCK_GROUP_PROFILE_MASK) + meta_size = 3 * dev_stripes * zone_size; + else + meta_size = dev_stripes * zone_size; + reserved += meta_size; + + /* + * On non-SINGLE profile, we need to add real data block + * group. And, we also need to add a space for a data + * relocation block group. + * + * SINGLE profile can reuse the initial block groups and + * only need to add a data relocation block group. + */ + dev_stripes = (data_profile & BTRFS_BLOCK_GROUP_DUP) ? 2 : 1; + if (data_profile & BTRFS_BLOCK_GROUP_PROFILE_MASK) + data_size = 2 * dev_stripes * zone_size; + else + data_size = dev_stripes * zone_size; + reserved += data_size; + + return reserved; + } if (mixed) return 2 * (BTRFS_MKFS_SYSTEM_GROUP_SIZE + @@ -863,22 +898,18 @@ u64 btrfs_min_dev_size(u32 nodesize, bool mixed, u64 zone_size, u64 meta_profile * * And use the stripe size to calculate its physical used space. */ + dev_stripes = (meta_profile & BTRFS_BLOCK_GROUP_DUP) ? 2 : 1; if (meta_profile & BTRFS_BLOCK_GROUP_PROFILE_MASK) - meta_size = SZ_8M + SZ_32M; + meta_size = dev_stripes * (SZ_8M + SZ_32M); else - meta_size = SZ_8M + SZ_8M; - /* For DUP/metadata, 2 stripes on one disk */ - if (meta_profile & BTRFS_BLOCK_GROUP_DUP) - meta_size *= 2; + meta_size = dev_stripes * (SZ_8M + SZ_8M); reserved += meta_size; + dev_stripes = (data_profile & BTRFS_BLOCK_GROUP_DUP) ? 2 : 1; if (data_profile & BTRFS_BLOCK_GROUP_PROFILE_MASK) - data_size = SZ_64M; + data_size = dev_stripes * SZ_64M; else - data_size = SZ_8M; - /* For DUP/data, 2 stripes on one disk */ - if (data_profile & BTRFS_BLOCK_GROUP_DUP) - data_size *= 2; + data_size = dev_stripes * SZ_8M; reserved += data_size; return reserved; From patchwork Wed May 22 06:02:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13670444 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9C2277F13 for ; Wed, 22 May 2024 06:03:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357830; cv=none; b=dC9TryT6MpGwxPDm/BIAwmus5AnUjXnD2nA3C0o5suqjGv76eFdR4dIdbJM3t1BZeaMbxPwpXAu6psd2ocsLl1SGREpvnx7j7XJ35PzFTwAAC0hVKZR16rX2UCpuo4oxjKxsavOgqDtVJINE5eIh03hMs1h67U5kBwAQeRu5fcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357830; c=relaxed/simple; bh=VXq0f4lmSAMQ7qpNIpQ1Dxc8+Hfcw7+vt2hvmdRIYpo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AmDeR/Jg9zpgG8ecDCtwBezu1gIfo/sKm8glolKCCIYcNVpZ/q1e8i8xVSycZPqgkjgejgROkFVNmYMw9Q/XEflIoLS6XXLbf9mIYT2sgMp2PAw8m1P/z4Z8OStCJuQcz4AWB1Autb3Mn9oz+4arLSAYjNna/lStuAY/FbTw6WQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=I+ru+U1/; arc=none smtp.client-ip=216.71.153.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="I+ru+U1/" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716357828; x=1747893828; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VXq0f4lmSAMQ7qpNIpQ1Dxc8+Hfcw7+vt2hvmdRIYpo=; b=I+ru+U1/zTBUORuNErCM8gB+6guLTQqd5PpVExfbLzn4UiIrf4hT2TvM XqCvohYOhEn9V07k6jEhJdXuw0wkpOryd7qUIt+g8aFSlQd1xgRAO7/YV vn6dtJaj5CJxkuIgsnaV8E68revFerBfUUoginF9HacuPj2jSPlA8O5MV T6LzCnZkLRlxZ/zoaoXFCU37W7iisyRo5spjG2se90CaDsK+vS+fT1hIy 3GbeKSi80LLWbTXfMNyVxfFHh0+yb1OMLbY6OZtpnm0gPDTJMtsnhpqJs rPWEt0Q7v+Nhpm0pRt1ItmdFWv730P5kKhvEjBKEETjLm8MFoXgMCY1wG g==; X-CSE-ConnectionGUID: 6hHx2P1CRkKu23EPSPKjgw== X-CSE-MsgGUID: +l8xGOGoSpGqKJ9YjBx6KQ== X-IronPort-AV: E=Sophos;i="6.08,179,1712592000"; d="scan'208";a="16664805" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 May 2024 14:03:42 +0800 IronPort-SDR: 664d7d22_nqADyQR11VmgvAUSQI/Isy8Ug2kFoc0br9JgBw+lfvV+Wwk 6W2pTWWT4c2eHuXefI185VKmcgFQGCkwaL9piMw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 21 May 2024 22:05:38 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.60]) by uls-op-cesaip02.wdc.com with ESMTP; 21 May 2024 23:03:42 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v3 05/10] btrfs-progs: mkfs: align byte_count with sectorsize and zone size Date: Wed, 22 May 2024 15:02:27 +0900 Message-ID: <20240522060232.3569226-6-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522060232.3569226-1-naohiro.aota@wdc.com> References: <20240522060232.3569226-1-naohiro.aota@wdc.com> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 While "byte_count" is eventually rounded down to sectorsize at make_btrfs() or btrfs_add_to_fs_id(), it would be better round it down first and do the size checks not to confuse the things. Also, on a zoned device, creating a btrfs whose size is not aligned to the zone boundary can be confusing. Round it down further to the zone boundary. The size calculation with a source directory is also tweaked to be aligned. Signed-off-by: Naohiro Aota --- mkfs/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mkfs/main.c b/mkfs/main.c index a437ecc40c7f..baf889873b41 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -1591,6 +1591,12 @@ int BOX_MAIN(mkfs)(int argc, char **argv) min_dev_size = btrfs_min_dev_size(nodesize, mixed, opt_zoned ? zone_size(file) : 0, metadata_profile, data_profile); + if (byte_count) { + byte_count = round_down(byte_count, sectorsize); + if (opt_zoned) + byte_count = round_down(byte_count, zone_size(file)); + } + /* * Enlarge the destination file or create a new one, using the size * calculated from source dir. @@ -1624,12 +1630,13 @@ int BOX_MAIN(mkfs)(int argc, char **argv) * Or we will always use source_dir_size calculated for mkfs. */ if (!byte_count) - byte_count = device_get_partition_size_fd_stat(fd, &statbuf); + byte_count = round_up(device_get_partition_size_fd_stat(fd, &statbuf), + sectorsize); source_dir_size = btrfs_mkfs_size_dir(source_dir, sectorsize, min_dev_size, metadata_profile, data_profile); if (byte_count < source_dir_size) { if (S_ISREG(statbuf.st_mode)) { - byte_count = source_dir_size; + byte_count = round_up(source_dir_size, sectorsize); } else { warning( "the target device %llu (%s) is smaller than the calculated source directory size %llu (%s), mkfs may fail", From patchwork Wed May 22 06:02:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13670445 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 958AB78B60 for ; Wed, 22 May 2024 06:03:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357831; cv=none; b=XVxd7ii/hWm1TA6VvcGR8UiOLiX6HscCPKwh26BMPmYJvC3V4CXCxbDv16RGwfD1lAqjz/b+3Eyjq98l2FhA9yJalpIcOxgtacwcVwIeT16ABdgxDgr3FXUjcz6QICinhs4f0WcVq/nIwMRBNUgm6bYDwD3JqFckJvSXbtKmnZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357831; c=relaxed/simple; bh=ry26AqNbwTnYcG7ZE4Czs5f+gXbgatGc4qsIEWVYt7s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HImgBJRs4Pa9yIQoGTTH3KBD8S3nJgvPPc9QyAvU4gGajSca00bLV92Snm50CdfjavQnA1R3c4ubh02SBsCC0HnbbRZ1U8UGoMowQ1w8484LLSxOKgZQdJQF9waXC3nKew2H7QHwPD2TTg/YkF00UGssvMm2LX58DZMKxT6f6Vw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=IAMw/nsr; arc=none smtp.client-ip=216.71.153.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="IAMw/nsr" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716357829; x=1747893829; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ry26AqNbwTnYcG7ZE4Czs5f+gXbgatGc4qsIEWVYt7s=; b=IAMw/nsrtjR2XWZ60A5xoZGNJhahNHHn7bI5uxJuTYQUlG2j7n1x4hUz nlpitcmS/+jw7pYhqeyjWFIZlLWb9lknKYXfzqowShBmhPp3WC42/htoN mLJ7ZwIfhs8wog40yCo/Gmopj2X9PTdTsPgkeRQyqCJ169IqCI53CJBcA XZ1RlV/cf+ogsBA/IjofAiTuq5OeHpFll/cmFvIxlZTcvdahw3qQOkZ4c xoaAUIxPqCip44nRGegmVF9T9pVopouj76/W9S/j9z16WN+mNLF7qMwN4 7GgcDHm/4VD5Cu6a/0G5jtuQ7O2hcW3UFsWL96UT+mk61jNAGQ5Jes6yS w==; X-CSE-ConnectionGUID: NZXcJXpbTmKrgaUeseIsmw== X-CSE-MsgGUID: hJha6BjjRmioNAyPQ1iIbg== X-IronPort-AV: E=Sophos;i="6.08,179,1712592000"; d="scan'208";a="16664807" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 May 2024 14:03:43 +0800 IronPort-SDR: 664d7d23_nB8Y2EfuRCaa8N5Iafog2+13BfakvI2gxgS4lYIZEYRgGt+ u8zspY7QT5orEqdnAn6nOP8So8hxo/c6ETsrXmA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 21 May 2024 22:05:39 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.60]) by uls-op-cesaip02.wdc.com with ESMTP; 21 May 2024 23:03:43 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Qu Wenruo Subject: [PATCH v3 06/10] btrfs-progs: support byte length for zone resetting Date: Wed, 22 May 2024 15:02:28 +0900 Message-ID: <20240522060232.3569226-7-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522060232.3569226-1-naohiro.aota@wdc.com> References: <20240522060232.3569226-1-naohiro.aota@wdc.com> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Even with "mkfs.btrfs -b", mkfs.btrfs resets all the zones on the device. Limit the reset target within the specified length. Also, we need to check that there is no active zone outside of the FS range. Having an active zone outside FS reduces the number of zones btrfs can write simultaneously. Technically, we can still scan all the device zones and keep active zones outside FS intact and try to live with the limited active zones. But, that will make btrfs operations harder. It is generally bad idea to use "-b" on a non-test usage on a device with active zone limit in the first place. You really need to take care that FS and outside the FS goes over the limit. That means you'll never be able to use zones outside the FS anyway. So, until there is a strong request for that, I don't think it's worthwhile to do so. Signed-off-by: Naohiro Aota Reviewed-by: Qu Wenruo --- common/device-utils.c | 17 ++++++++++++----- kernel-shared/zoned.c | 23 ++++++++++++++++++++++- kernel-shared/zoned.h | 7 ++++--- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/common/device-utils.c b/common/device-utils.c index 86942e0c7041..7df7d9ce39d8 100644 --- a/common/device-utils.c +++ b/common/device-utils.c @@ -254,16 +254,23 @@ int btrfs_prepare_device(int fd, const char *file, u64 *byte_count_ret, if (!zinfo->emulated) { if (opflags & PREP_DEVICE_VERBOSE) - printf("Resetting device zones %s (%u zones) ...\n", - file, zinfo->nr_zones); + printf("Resetting device zones %s (%llu zones) ...\n", + file, byte_count / zinfo->zone_size); /* * We cannot ignore zone reset errors for a zoned block * device as this could result in the inability to write * to non-empty sequential zones of the device. */ - if (btrfs_reset_all_zones(fd, zinfo)) { - error("zoned: failed to reset device '%s' zones: %m", - file); + ret = btrfs_reset_zones(fd, zinfo, byte_count); + if (ret) { + if (ret == EBUSY) { + error("zoned: device '%s' contains an active zone outside of the FS range", + file); + error("zoned: btrfs needs full control of active zones"); + } else { + error("zoned: failed to reset device '%s' zones: %m", + file); + } goto err; } } diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index fb1e1388804e..b4244966ca36 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -395,16 +395,24 @@ static int report_zones(int fd, const char *file, * Discard blocks in the zones of a zoned block device. Process this with zone * size granularity so that blocks in conventional zones are discarded using * discard_range and blocks in sequential zones are reset though a zone reset. + * + * We need to ensure that zones outside of the FS is not active, so that + * the FS can use all the active zones. Return EBUSY if there is an active + * zone. */ -int btrfs_reset_all_zones(int fd, struct btrfs_zoned_device_info *zinfo) +int btrfs_reset_zones(int fd, struct btrfs_zoned_device_info *zinfo, u64 byte_count) { unsigned int i; int ret = 0; ASSERT(zinfo); + ASSERT(IS_ALIGNED(byte_count, zinfo->zone_size)); /* Zone size granularity */ for (i = 0; i < zinfo->nr_zones; i++) { + if (byte_count == 0) + break; + if (zinfo->zones[i].type == BLK_ZONE_TYPE_CONVENTIONAL) { ret = device_discard_blocks(fd, zinfo->zones[i].start << SECTOR_SHIFT, @@ -419,7 +427,20 @@ int btrfs_reset_all_zones(int fd, struct btrfs_zoned_device_info *zinfo) if (ret) return ret; + + byte_count -= zinfo->zone_size; } + for (; i < zinfo->nr_zones; i++) { + const enum blk_zone_cond cond = zinfo->zones[i].cond; + + if (zinfo->zones[i].type == BLK_ZONE_TYPE_CONVENTIONAL) + continue; + if (cond == BLK_ZONE_COND_IMP_OPEN || + cond == BLK_ZONE_COND_EXP_OPEN || + cond == BLK_ZONE_COND_CLOSED) + return EBUSY; + } + return fsync(fd); } diff --git a/kernel-shared/zoned.h b/kernel-shared/zoned.h index 6eba86d266bf..2bf24cbba62a 100644 --- a/kernel-shared/zoned.h +++ b/kernel-shared/zoned.h @@ -149,7 +149,7 @@ bool btrfs_redirty_extent_buffer_for_zoned(struct btrfs_fs_info *fs_info, u64 start, u64 end); int btrfs_reset_chunk_zones(struct btrfs_fs_info *fs_info, u64 devid, u64 offset, u64 length); -int btrfs_reset_all_zones(int fd, struct btrfs_zoned_device_info *zinfo); +int btrfs_reset_zones(int fd, struct btrfs_zoned_device_info *zinfo, u64 byte_count); int zero_zone_blocks(int fd, struct btrfs_zoned_device_info *zinfo, off_t start, size_t len); int btrfs_wipe_temporary_sb(struct btrfs_fs_devices *fs_devices); @@ -203,8 +203,9 @@ static inline int btrfs_reset_chunk_zones(struct btrfs_fs_info *fs_info, return 0; } -static inline int btrfs_reset_all_zones(int fd, - struct btrfs_zoned_device_info *zinfo) +static inline int btrfs_reset_zones(int fd, + struct btrfs_zoned_device_info *zinfo, + u64 byte_count) { return -EOPNOTSUPP; } From patchwork Wed May 22 06:02:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13670448 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F90578C8F for ; Wed, 22 May 2024 06:03:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357834; cv=none; b=MuU0+c82Z4qKnHzIg7ogwrXiIBRh3LW2hGTGxMWJZJ/wYaHh421glPcSMPn3X4Jq4u1dn6sQdgG56IjV7T8+47QmStC4NFhulrQfwtG4xLPe7js8DHe2EA1eOY4YqHbTneoxFt/TbT2D3pvU/xCvjus/Ae0a8Llf3x/QH9XHDn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357834; c=relaxed/simple; bh=gvRqCmH3sPkyvRq89KJhIgW3RDMLvYt3mUEUvK97J78=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GaLByRMS2KvM4wKlO1xD3pnO4ELniXA6lFLg/1nVMgk8WgLG77y6uyJdRZgjBN8TpnwuNq6TZhIKiZeO6UvIA3sML+LdT62Qw9FqKdovmDP1NJe5M9T2Rz/cbwqhYBXMh/Wl0U96xYxjsDJehVJ2mGDEwd4eN1qpP6uvR1tn4Ek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=UMTgQbS4; arc=none smtp.client-ip=68.232.141.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="UMTgQbS4" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716357832; x=1747893832; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gvRqCmH3sPkyvRq89KJhIgW3RDMLvYt3mUEUvK97J78=; b=UMTgQbS4aDLPnvTPlgBiI9kw1B15fTqP/xNbVhsLWZTDpoYrmwHJMEhU iywVpFcjLEoLoUYifKwh+Og701H7nAqvOBo52tBf98K2NheZAw7T2RMug 9YWJlz98+qWIcZzY9CCv1kye2LGIIQ7d1zDXpEuxGIigyyzplobD4ZWkE 6s3J9TeCsGPcg8Xke0Gs8pYPwPQxuXjR/csA6PyJV4rx1WHvV6fE2wnRj wcn029rsoPCxPqUnDVwr8+oDbk9fIK4etfVhuUpgxp3sNnBMyQMX+uI4P nv6iqMwAjlfdbIDcEVwqRAw3/woHDCDOF6Dy4XGVVQ6UQ7J1nAjwraBeS w==; X-CSE-ConnectionGUID: EhN8pg/QRkm6xWUrTmSmPQ== X-CSE-MsgGUID: v4XhL6YpSbComrinYBBi3Q== X-IronPort-AV: E=Sophos;i="6.08,179,1712592000"; d="scan'208";a="17170976" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 May 2024 14:03:43 +0800 IronPort-SDR: 664d7d24_Wkbi7Ap5AEkfWkuvqsZ1qwgwWJ2pBwdC09zwiv/ghdooGSe j7A24f8zo6Wd4O5MP3CB6xU/KoirdskmQQUswpA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 21 May 2024 22:05:40 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.60]) by uls-op-cesaip02.wdc.com with ESMTP; 21 May 2024 23:03:44 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v3 07/10] btrfs-progs: test: add nullb setup functions Date: Wed, 22 May 2024 15:02:29 +0900 Message-ID: <20240522060232.3569226-8-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522060232.3569226-1-naohiro.aota@wdc.com> References: <20240522060232.3569226-1-naohiro.aota@wdc.com> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add functions to setup, create and remove nullb devices. Signed-off-by: Naohiro Aota --- tests/common | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/common b/tests/common index 1f880adead6d..ef9fcd32870a 100644 --- a/tests/common +++ b/tests/common @@ -882,6 +882,69 @@ cond_wait_for_loopdevs() { fi } +# prepare environment for nullb devices, set up the following variables +# - nullb_count -- number of desired devices +# - nullb_size -- size of the devices +# - nullb_zone_size -- zone size of the devices +# - nullb_devs -- array containing paths to all devices (after prepare is called) +# +# $1: number of nullb devices to be set up +# $2: size of the devices +# $3: zone size of the devices +setup_nullbdevs() +{ + if [ "$#" -lt 3 ]; then + _fail "setup_nullbdevs " + fi + + setup_root_helper + local nullb="${TEST_TOP}/nullb" + + run_mayfail $SUDO_HELPER "${nullb}" setup + if [ $? != 0 ]; then + _not_run "cannot setup nullb environment for zoned devices" + fi + + nullb_count="$1" + nullb_size="$2" + nullb_zone_size="$3" + declare -a nullb_devs +} + +# create all nullb devices from a given nullb environment +prepare_nullbdevs() +{ + setup_root_helper + local nullb="${TEST_TOP}/nullb" + + # Record any other pre-existing devices in case creation fails + run_check $SUDO_HELPER "${nullb}" ls + + for i in `seq ${nullb_count}`; do + # Last line has the name of the device node path + out=$(run_check_stdout $SUDO_HELPER "${nullb}" create -s "${nullb_size}" -z "${nullb_zone_size}") + if [ $? != 0 ]; then + _fail "cannot create nullb zoned device $i" + fi + dev=$(echo "${out}" | tail -n 1) + nullb_devs[$i]=${dev} + done + + run_check $SUDO_HELPER "${nullb}" ls +} + +# remove nullb devices +cleanup_nullbdevs() +{ + setup_root_helper + local nullb="${TEST_TOP}/nullb" + + for dev in ${nullb_devs[@]}; do + name=$(basename ${dev}) + run_check $SUDO_HELPER "${nullb}" rm "${name}" + done +} + init_env() { TEST_MNT="${TEST_MNT:-$TEST_TOP/mnt}" From patchwork Wed May 22 06:02:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13670449 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2CC8763FC for ; Wed, 22 May 2024 06:03:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357835; cv=none; b=Oe7SbBc6QV88ybtm+sG6CcWIeQ285tsq5ZXB/Otad5ArswUTaUgH48+gORICD6smWJ5KoW8VovXm7NKV2ctnPhena9BLSTGWxH9ldv67ZKapcyQUaMCEXTW8iQOZAzyFEztc9zpJS2noysUDFpkfec830V/DzdVWhnIsTUGWmw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357835; c=relaxed/simple; bh=0a9Ok1Pil5K+RV1V9LVFBmoQFHRNpWTveGIfvgBVqMM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tWnAn4K/V2mNLlHXkUdL5RVXeWD3oKpyV85//t2LtxzVlCPq/PEi1ctGOYAezNgal8LN+/Zx3yRw5MKde5jvdWG8f+mAtCpy/xyq5HHBvH+pceL9kBW8fC+pDiVS+bOF9crsF8GgIJ0TR8x8bJTMxzHn6MRjbzYXuKCs54/TA+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=CK/nFD8I; arc=none smtp.client-ip=68.232.141.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="CK/nFD8I" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716357833; x=1747893833; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0a9Ok1Pil5K+RV1V9LVFBmoQFHRNpWTveGIfvgBVqMM=; b=CK/nFD8IYgGRsn9NQO6uUbdbgUOKuw8OeRWV563cBPdAnz5ksqAv8f+E 8StLzkHv6nWBBQMcIOkumiigQlHmbeObEsPbiHU4GEWFYqIfCY25wKYTU 9oYP2kjpmYMFPMJDJqXTkZ0V3wMtBakHCof42WB9B4qmR2IM7tRTti/Ir lSz1lNOvcbXFD0bHC2pzcJkcc0cu436TfknDoRUdREdMMXffnVItPAhIR RhydYtfPjOpWzjeClaHPvIfX+B5u7qj17NWhD13f/OrJDbbqd9CYFCwRz hTqAl3k15I/ga1M/XhB18nbGRww/UnVXBVpaNgAEmEZ6BwhKvCC+W0we5 Q==; X-CSE-ConnectionGUID: vu3zCIClSHydGCDNCNHZWg== X-CSE-MsgGUID: OU0VIRqeTr+mp9B56g6oJw== X-IronPort-AV: E=Sophos;i="6.08,179,1712592000"; d="scan'208";a="17170981" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 May 2024 14:03:44 +0800 IronPort-SDR: 664d7d24_dSGirlmfmNbvAkf1rHifrJjhZR2GgNRYiMeP2uEO2+p7u+/ 9GexkRRlojJBrhQZuDNvsbOnfAXm7HbsrHcjssw== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 21 May 2024 22:05:41 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.60]) by uls-op-cesaip02.wdc.com with ESMTP; 21 May 2024 23:03:45 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v3 08/10] btrfs-progs: test: add test for zone resetting Date: Wed, 22 May 2024 15:02:30 +0900 Message-ID: <20240522060232.3569226-9-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522060232.3569226-1-naohiro.aota@wdc.com> References: <20240522060232.3569226-1-naohiro.aota@wdc.com> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add test for mkfs.btrfs's zone reset behavior to check if - it resets all the zones without "-b" option - it detects an active zone outside of the FS range - it do not reset a zone outside of the range Signed-off-by: Naohiro Aota --- tests/mkfs-tests/032-zoned-reset/test.sh | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 tests/mkfs-tests/032-zoned-reset/test.sh diff --git a/tests/mkfs-tests/032-zoned-reset/test.sh b/tests/mkfs-tests/032-zoned-reset/test.sh new file mode 100755 index 000000000000..2aedb14abb03 --- /dev/null +++ b/tests/mkfs-tests/032-zoned-reset/test.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# Verify mkfs for zoned devices support block-group-tree feature + +source "$TEST_TOP/common" || exit + +check_global_prereq blkzone +setup_root_helper +# Create one 128M device with 4M zones, 32 of them +setup_nullbdevs 1 128 4 + +prepare_nullbdevs + +TEST_DEV="${nullb_devs[1]}" +last_zone_sector=$(( 4 * 31 * 1024 * 1024 / 512 )) +# Write some data to the last zone +run_check $SUDO_HELPER dd if=/dev/urandom of="${TEST_DEV}" bs=1M count=4 seek=$(( 4 * 31 )) +# Use single as it's supported on more kernels +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -m single -d single "${TEST_DEV}" +# Check if the lat zone is empty +run_check_stdout $SUDO_HELPER blkzone report -o ${last_zone_sector} -c 1 "${TEST_DEV}" | grep -Fq '(em)' +if [ $? != 0 ]; then + _fail "last zone is not empty" +fi + +# Write some data to the last zone +run_check $SUDO_HELPER dd if=/dev/urandom of="${TEST_DEV}" bs=1M count=1 seek=$(( 4 * 31 )) +# Create a FS excluding the last zone +run_mayfail $SUDO_HELPER "$TOP/mkfs.btrfs" -f -b $(( 4 * 31 ))M -m single -d single "${TEST_DEV}" +if [ $? == 0 ]; then + _fail "mkfs.btrfs should detect active zone outside of FS range" +fi + +# Fill the last zone to finish it +run_check $SUDO_HELPER dd if=/dev/urandom of="${TEST_DEV}" bs=1M count=3 seek=$(( 4 * 31 + 1 )) +# Create a FS excluding the last zone +run_mayfail $SUDO_HELPER "$TOP/mkfs.btrfs" -f -b $(( 4 * 31 ))M -m single -d single "${TEST_DEV}" +# Check if the lat zone is not empty +run_check_stdout $SUDO_HELPER blkzone report -o ${last_zone_sector} -c 1 "${TEST_DEV}" | grep -Fq '(em)' +if [ $? == 0 ]; then + _fail "last zone is empty" +fi + +cleanup_nullbdevs From patchwork Wed May 22 06:02:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13670450 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C44178C9B for ; Wed, 22 May 2024 06:03:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357836; cv=none; b=Q5E1YdjlBICRI0HEI1/BGH88L/A1EMbZulslz8SS03VkF0cfM9dM0QGMexmbgj9M8qsS/uSoqi0vE6HYRgbP5Ayrft/RcLYyxnV+5ENofxil9xzWuJnLFwKnxZFNX8/ypatUYxRAcb2YUfzVCxr1Oc+zFCZDjRzkdJjJVKKtDTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357836; c=relaxed/simple; bh=vveptgKvf6jZr400dXREY6y4NYyFXwV9ioLYEwPVTKw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CUbad4ayWpNrhh8esiaW/oW2glWXzZP2cFvXKniOMN+AUeqr/5yRusmIAU+jggg2H8dM9MbOSwWd3dIrzcJoxS36lg0gIG7/I/wrfEKK0xOayTR2sXDB2TleY5wuh/qjUGzSFwnnTihtfcq3MUrvVSx29RIzHBVCxfLgem9BCJs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=E4DfaRAr; arc=none smtp.client-ip=68.232.141.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="E4DfaRAr" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716357834; x=1747893834; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vveptgKvf6jZr400dXREY6y4NYyFXwV9ioLYEwPVTKw=; b=E4DfaRAriPob1j5sza1v+Gtef1iSYWqado49dCp+FO3VD+nVSxZqeF2s Zf0Mi1yegBpLVhPWAkQpU/gc+4QhIm+r41vY8kzUuAVfgvEshgYCU2jdC 4wz4QO3ecafi2cJ/2I9SxSBzUmtbSlG87CrOYXzMS/WI/f7zLDjYVmm+S NiA5BmfZcWwkeNcf4u/oiyk4P8+Ov4eYD6OyTs6/chxns+hLVdiC28M7X JlhbGjGEukzSxScr1RNMhYhyxt6mJoI6MFgMVxn3ZKclFIrrHqCJVqX3F 97ezHs0nMGDlGOTR9T1CR7lfBRp33OFIGEUhUFnORyFaoNcE8Dq7iL33M g==; X-CSE-ConnectionGUID: DgBEaYNmTPmJ9Ikx+Mu2xA== X-CSE-MsgGUID: xpx1mdtYRF6nQbjZrGDDUA== X-IronPort-AV: E=Sophos;i="6.08,179,1712592000"; d="scan'208";a="17170983" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 May 2024 14:03:45 +0800 IronPort-SDR: 664d7d25_iQqbFOPCm4KoFdu9lZoKshoqz6O4ccnfDlahJN60oe8ODIY sdXzWcTMQLq89ntykkLafjYiJXLsxUT7/sx230w== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 21 May 2024 22:05:41 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.60]) by uls-op-cesaip02.wdc.com with ESMTP; 21 May 2024 23:03:45 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v3 09/10] btrfs-progs: test: use nullb helper and smaller zone size Date: Wed, 22 May 2024 15:02:31 +0900 Message-ID: <20240522060232.3569226-10-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522060232.3569226-1-naohiro.aota@wdc.com> References: <20240522060232.3569226-1-naohiro.aota@wdc.com> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With the change of minimal number of zones, mkfs-tests/030-zoned-rst now fails because the loopback device is 2GB and can contain 8x 256MB zones. Use the nullb helpers to choose a smaller zone size. Signed-off-by: Naohiro Aota --- tests/mkfs-tests/030-zoned-rst/test.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/mkfs-tests/030-zoned-rst/test.sh b/tests/mkfs-tests/030-zoned-rst/test.sh index 2e048cf79f20..b1c696c96eb7 100755 --- a/tests/mkfs-tests/030-zoned-rst/test.sh +++ b/tests/mkfs-tests/030-zoned-rst/test.sh @@ -4,22 +4,22 @@ source "$TEST_TOP/common" || exit setup_root_helper -setup_loopdevs 4 -prepare_loopdevs -TEST_DEV=${loopdevs[1]} +setup_nullbdevs 4 128 4 +prepare_nullbdevs +TEST_DEV=${nullb_devs[1]} profiles="single dup raid1 raid1c3 raid1c4 raid10" for dprofile in $profiles; do for mprofile in $profiles; do # It's sufficient to specify only 'zoned', the rst will be enabled - run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -O zoned -d "$dprofile" -m "$mprofile" "${loopdevs[@]}" + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -O zoned -d "$dprofile" -m "$mprofile" "${nullb_devs[@]}" done done run_mustfail "unsupported profile raid56 created" \ - $SUDO_HELPER "$TOP/mkfs.btrfs" -f -O zoned -d raid5 -m raid5 "${loopdevs[@]}" + $SUDO_HELPER "$TOP/mkfs.btrfs" -f -O zoned -d raid5 -m raid5 "${nullb_devs[@]}" run_mustfail "unsupported profile raid56 created" \ - $SUDO_HELPER "$TOP/mkfs.btrfs" -f -O zoned -d raid6 -m raid6 "${loopdevs[@]}" + $SUDO_HELPER "$TOP/mkfs.btrfs" -f -O zoned -d raid6 -m raid6 "${nullb_devs[@]}" -cleanup_loopdevs +cleanup_nullbdevs From patchwork Wed May 22 06:02:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13670451 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E55F578C83 for ; Wed, 22 May 2024 06:03:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357836; cv=none; b=FtysxnnXR8PoxvX8kkgxCm+Qt9nmZN56QshcVgog0DgJ2Jnx5ARVVqzIt1O/PD4CyHDHIAuQn/M4dvK4hGWbTzRyAl/GKTDJ/7XY8w8NCTQgQWEG3+4MT8TayD0CV/k5RvaIdRn9XfuPgtx92Gk2/J7MyIfJ/200udMvQzpNjeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716357836; c=relaxed/simple; bh=P/+3Yz1jAL+wNpcETlU/vWrCw9svhZwTT5lyGR4l3dw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kmthh2OgbcYH6twOpUUdy092Qf7uImVnQgn87fXm1T7e5ihfBqvRoAoqZZJaLA2yasAj4hgW19gcEJL3EQhDFWM1y8trR+Ndwv90T9bBps3HzstbyYQVUh20J2AWDBnwU//GKfN52wmatKI+hEDKOf4X23lTARtAMMvGPvQbT1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=GWGIe04k; arc=none smtp.client-ip=68.232.141.245 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="GWGIe04k" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716357834; x=1747893834; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=P/+3Yz1jAL+wNpcETlU/vWrCw9svhZwTT5lyGR4l3dw=; b=GWGIe04kXKEayYblYRzVYuZ8eZGsr710G8pBngH+YbHCydMdpIOkqG/B klgRcQVWW5njJFHtOUfh400W/MJwsNz6ASyM4L4w3gF3hDDI7zlihR5q7 iDXKjk+KtnJlhN83eo6CbTOc1LHyLEJQo/vtGnBiLH06AFaeou2juODpU 3XfdWR7cyrcub5fb62lTZqAFLl50LQAvO5hsiJbo6QgA7mm3gXyk7YN+I BTJTpSmj8OGX4P//t5//YH9mW4znDR2oxuz05WwEz3j0II7KhYTV1fd3f cO2qBBYaZ/lK//M3Qra61pyBetOHEMjKspMiXiL4NlrtHQTNU/k+RGjh+ g==; X-CSE-ConnectionGUID: QDM1T00uRpiRLGDOur2Dvg== X-CSE-MsgGUID: fLo8R8oXSBWd0gPVlU58rw== X-IronPort-AV: E=Sophos;i="6.08,179,1712592000"; d="scan'208";a="17170985" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 22 May 2024 14:03:46 +0800 IronPort-SDR: 664d7d26_qWCUIQUk2EdzuJWJtaXXXAYdoQcTRlBKWwdLtQ1+Ti93ZMV OOn3O7uXwsmdHO9pyrR+tKVYlRqSwYX2v2rciYA== Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 21 May 2024 22:05:42 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.60]) by uls-op-cesaip02.wdc.com with ESMTP; 21 May 2024 23:03:46 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v3 10/10] btrfs-progs: test: use nullb helpers in 031-zoned-bgt Date: Wed, 22 May 2024 15:02:32 +0900 Message-ID: <20240522060232.3569226-11-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240522060232.3569226-1-naohiro.aota@wdc.com> References: <20240522060232.3569226-1-naohiro.aota@wdc.com> Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Rewrite 031-zoned-bgt with the nullb helpers. Signed-off-by: Naohiro Aota --- tests/mkfs-tests/031-zoned-bgt/test.sh | 30 +++++--------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/tests/mkfs-tests/031-zoned-bgt/test.sh b/tests/mkfs-tests/031-zoned-bgt/test.sh index 91c107cd5a3b..e296c29b9238 100755 --- a/tests/mkfs-tests/031-zoned-bgt/test.sh +++ b/tests/mkfs-tests/031-zoned-bgt/test.sh @@ -4,37 +4,17 @@ source "$TEST_TOP/common" || exit setup_root_helper -prepare_test_dev - -nullb="$TEST_TOP/nullb" # Create one 128M device with 4M zones, 32 of them -size=128 -zone=4 - -run_mayfail $SUDO_HELPER "$nullb" setup -if [ $? != 0 ]; then - _not_run "cannot setup nullb environment for zoned devices" -fi - -# Record any other pre-existing devices in case creation fails -run_check $SUDO_HELPER "$nullb" ls - -# Last line has the name of the device node path -out=$(run_check_stdout $SUDO_HELPER "$nullb" create -s "$size" -z "$zone") -if [ $? != 0 ]; then - _fail "cannot create nullb zoned device $i" -fi -dev=$(echo "$out" | tail -n 1) -name=$(basename "${dev}") +setup_nullbdevs 1 128 4 -run_check $SUDO_HELPER "$nullb" ls +prepare_nullbdevs -TEST_DEV="${dev}" +TEST_DEV="${nullb_devs[1]}" # Use single as it's supported on more kernels -run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -m single -d single -O block-group-tree "${dev}" +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -m single -d single -O block-group-tree "${TEST_DEV}" run_check_mount_test_dev run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT"/file bs=1M count=1 run_check $SUDO_HELPER "$TOP/btrfs" filesystem usage -T "$TEST_MNT" run_check_umount_test_dev -run_check $SUDO_HELPER "$nullb" rm "${name}" +cleanup_nullbdevs