From patchwork Wed May 29 07:13:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13677947 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (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 1AA1415CD66 for ; Wed, 29 May 2024 07:13:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966820; cv=none; b=bZgEza8LUWKOLFUM4atxp3g/OtbD68NmUycC1i+PjhLidEA8pMulbsDdRTXCLkYwBiScWWVT4oeduCaeukNeLBDieDoBCeC/EFcdlJaNgGKyJ14RNx5DbQ3tYPx0t+iD4PhdamFwJ4aYJL22pql8Zgxtb/0ZnajwXxqDFwf619c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966820; c=relaxed/simple; bh=1mubY9Ki7lkt1l5RUKsl8qI/IIWYwP1BDNsJ3R1fh6g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bSBHWyuQVI8/ij0TcUvjUehLfd5AOGaEYXYDq1uluDQ62hBfGwQ4jUOAgxJMSWJzxBmEgpHURcbBS5+dbXKbITC1klvBwJHGkmoCWcy3ihQ/dPD6meo4DH+QwrcAFB9h+eGwx/RrSDEtj/HVxLGOmawvTA+Uu47BVE9DQNesEz8= 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=ZOSrLaFI; arc=none smtp.client-ip=216.71.154.42 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="ZOSrLaFI" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716966818; x=1748502818; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1mubY9Ki7lkt1l5RUKsl8qI/IIWYwP1BDNsJ3R1fh6g=; b=ZOSrLaFI7F8Qfoyq6HK77KYTwmRtuZaL4O2WVsXctmYUaSub6eSTxOnm 4kovMFY4P7uw1LHJ7W4O0VTuJvF1Bk0GxANvJxc7zv+YW30YLe7dG1/ka jA6CAfFGOiS3TKNXTIGLWpkAFAKSFYRcm3NQA6CPtdS5vlmwZvFWSrltO ZPZLMOVKO3E2Un0YapcnpmCqJd13bu8jQd/D1gRdGA9tSfDDB87R5jucI gGsDk6zLmqXlw0AetKlomSNog9Kqx9Xtx2esXr6L4dBqQefje9ds2nGCZ YGXY96zCvBsBE+ChSJ0vl9eOHl1Ezmcn3mbHw3ZZM4CiNSoFkmT4lXF8N w==; X-CSE-ConnectionGUID: F8T+h7jvTaWsMFKMw/MNbg== X-CSE-MsgGUID: ZluCvW7rRC+R554RpHvIqw== X-IronPort-AV: E=Sophos;i="6.08,197,1712592000"; d="scan'208";a="16865336" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2024 15:13:30 +0800 IronPort-SDR: 6656c94a_x/n7elmNghE5svQpz2vcnDcGZV86nuKf6X34y+bbxMvdWYH mfTZUucO3VQSzFbMuwGsx7q/g+huMT1JHrnX3Qg== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 May 2024 23:20:59 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.62]) by uls-op-cesaip01.wdc.com with ESMTP; 29 May 2024 00:13:30 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Qu Wenruo Subject: [PATCH v4 01/10] btrfs-progs: rename block_count to byte_count Date: Wed, 29 May 2024 16:13:16 +0900 Message-ID: <20240529071325.940910-2-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240529071325.940910-1-naohiro.aota@wdc.com> References: <20240529071325.940910-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 Reviewed-by: Qu Wenruo --- 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 29 07:13:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13677948 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (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 412EE1649CD for ; Wed, 29 May 2024 07:13:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966820; cv=none; b=fDYMk2thf1+k1CvdjSujjmo6HvwXNOuHFS8m2jrdikiVpuJox0882uyMF+n0BoFfZNQf9vf6whAniDE2bf51whKgWJotvkhumbw2qAqFqbS5fEOuk6F+gBCVaLhisQDLtvTJA7F9AkG7CqjibwCYH7ufNiuMDxy+aDNzp2a+AzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966820; c=relaxed/simple; bh=fjNG+MvTZcDGNAylJ8cU+SnnpA6+sZiLFD0FZ+0zI4I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V2BE5DHqpUuEBKlD7c3bVG4rXJpE5cmRrbxnQv3GdNKb26wgh4Gre4Skyr55jXgiuB5nhcmTaRmEqh5O5+i4hmonilNS3RxoLqbq+C3ORLlUdL5RXc1qSpnuTzZE0GEDwCDCj8y++SgWH7B+sBL1KhUfVZ+NdzYKFKsF1aYtPic= 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=CSFhWGdB; arc=none smtp.client-ip=216.71.154.42 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="CSFhWGdB" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716966819; x=1748502819; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fjNG+MvTZcDGNAylJ8cU+SnnpA6+sZiLFD0FZ+0zI4I=; b=CSFhWGdBqpKkMgReEQsIIlXTHmgYArKnUMOSYq3kyOHcMUgrbWfKxRMV k52+bzRHjpkOEKIEZamyzu6Tx3wFKLB6dTsRb8q3iZMEO4JAYf3R3/hRS KmqIcZQ8tkAZuVmGwLNKRwSk0kQeVcO5fb3UD43dSIirGPx2oWdOc4qnu iJtHo0oO9sy6+qjzW9d4QPLylzg3MfMBUtNVBtm9iBsO47YPVkR8pa2IJ E66b2JVC/UA40XDzSmlDnveFUv73KpQimP5txHeoXpG0A2Zyc1PBQrN/X adF1v4huDkGLrkGiX0U7H1MBkHiVj3LKsUduHx8E0aK8V5qHKpVSSD+UF g==; X-CSE-ConnectionGUID: FOREaHjuTFm2zBheqgofgw== X-CSE-MsgGUID: go7gHnlBSf+YZqGuv7hufg== X-IronPort-AV: E=Sophos;i="6.08,197,1712592000"; d="scan'208";a="16865337" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2024 15:13:31 +0800 IronPort-SDR: 6656c94b_s2PMdPHxpevXmoeZKhWV2l6iVkkO2V9oH0YYlMh9CBiNHmr N6PeZxG+X1NmbuH7nImkm0E1UqR+cZLpOOneUeQ== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 May 2024 23:21:00 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.62]) by uls-op-cesaip01.wdc.com with ESMTP; 29 May 2024 00:13:31 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Qu Wenruo Subject: [PATCH v4 02/10] btrfs-progs: mkfs: remove duplicated device size check Date: Wed, 29 May 2024 16:13:17 +0900 Message-ID: <20240529071325.940910-3-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240529071325.940910-1-naohiro.aota@wdc.com> References: <20240529071325.940910-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 Reviewed-by: Qu Wenruo --- 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 29 07:13:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13677949 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (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 1F0431667D1 for ; Wed, 29 May 2024 07:13:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966821; cv=none; b=UDyu8jH7gFQY8hzkuMiM4OHKNANgimFEEuhF/3wV0Y0oSwXdxyXq7RlbA+YuRA8NWyiHxRxpVxoL1L2HRNMZZYjaJIokY68ndq327hDHLYgEQWwBidpLPPY0yFJ1M6B9t3yNd1bUh7DAp+RFYT9eatni9T2lIfxNNW3Hb92SyiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966821; c=relaxed/simple; bh=dRO0k9wA/abSGDe2GyjHKnw78xcScbqtiN0eU87ImLY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VoQuJW7WvW99ECredbhdyfyZ2SW3uUbWhpz8RlZTFaWGOj6D5deX2ziw55xo/NgA+du1/90EC0xPCVQjpnQsnRajGezfCZX1K/rN/ZdQagHkqq7TRVBGhf6A53GDVOQe22c7unlh9dKmZ7MWudtI/178lqw/OVw1rD1Wla9n9Mg= 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=UM4jPGCN; arc=none smtp.client-ip=216.71.154.42 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="UM4jPGCN" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716966820; x=1748502820; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dRO0k9wA/abSGDe2GyjHKnw78xcScbqtiN0eU87ImLY=; b=UM4jPGCNoFlcACbgw/rugtLIPGoiqbO8uZYHvpUx8oYTzISjqMC/SVJP yXwiisAStdzsKiUfnZCecvVaHh7MaitVhwhuQwzWmeYATxUBj1WvLtQSO MFc+V0/dqzvwwn092qthDhMWsbPJlcxydclO01121QUwLU1jE2+ujNpcN euJ+9qXO7kAVl6nOl/bgEJcQC9gdvfDT2H4v+ScJO2g30YEyJyFhWjqRc JxBMtkmX8vRm73iEdOmfob+Jc1+MRn0o88pFDMurXq/4rlW8fSz2NKogI HuSZKwQ5dUo6vmsGCNBv85Lvrb8dYOFRdc38+xUTvuRNXQmv32ZI2BgxC A==; X-CSE-ConnectionGUID: p+EqTmK2RKCMLCNOX6Zugw== X-CSE-MsgGUID: ewbi+wY+Q3WUunXqHfCvMg== X-IronPort-AV: E=Sophos;i="6.08,197,1712592000"; d="scan'208";a="16865341" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2024 15:13:32 +0800 IronPort-SDR: 6656c94c_MasPhWXjL5QrCOOQNVzmR9g8F79aRyMDeqh1AXnzJgK9vgH 39l3fyHViQH9CKKZSUOGsXuHvx8DFIGkTC7t4Vg== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 May 2024 23:21:01 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.62]) by uls-op-cesaip01.wdc.com with ESMTP; 29 May 2024 00:13:32 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Qu Wenruo Subject: [PATCH v4 03/10] btrfs-progs: mkfs: unify zoned mode minimum size calc into btrfs_min_dev_size() Date: Wed, 29 May 2024 16:13:18 +0900 Message-ID: <20240529071325.940910-4-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240529071325.940910-1-naohiro.aota@wdc.com> References: <20240529071325.940910-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 Reviewed-by: Qu Wenruo --- 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 29 07:13:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13677950 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (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 5F17F1667DA for ; Wed, 29 May 2024 07:13:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966821; cv=none; b=AoSl47fV4DRN7spkMD92xt3WyE1xSVmqTE43eHDSBqcpanwcXEqK6kx62z/kWK5e/pgtYxLInYRWqR67cnwLMkvPgkJy+OSwkBJtGZvVJIWac0q7lm2UjYTPGd/NKhPr/KB++pdeU2/1W2xS/Ay9iFIW0o3QDz9W+VuKZpw/1+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966821; c=relaxed/simple; bh=sK5HygYz82g58csk+V4jliSzvR7Yv75tsP9OE+BH2WA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DBOTCHvmB6V0v8HfwihmobBQsgGj8eOpeXhX06/tlRmXTgBC4w8V/6fNT2QzGmkkDGgbrjnuSH9ufpl7+ow+W6P/W7RdQVgmPfMQ39B13eSmG4pQbzQBPWpihfcfbLPiQE2ZH91amIxGrq3+iN/XxBxSaYwzUzzQNtoALVcbphw= 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=OSJ5kMGk; arc=none smtp.client-ip=216.71.154.42 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="OSJ5kMGk" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716966820; x=1748502820; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sK5HygYz82g58csk+V4jliSzvR7Yv75tsP9OE+BH2WA=; b=OSJ5kMGkNByUw4k9jLCwzFBekostNt4L0Qkcy0Dfu/10sjAwkmUY/+jW CXr1HmYrWJi9ayiKJmb1TiOA8SqguWrhZdchJClKdyKntglM5oFoWTsQJ 6TjUqkEK1ZojRM4u7qHw1mMKz9vm7iKKzN384xGPirYDLxFQdG9pI6HTS OnTgKzqqIt7nAkhyoPhEoRQRFJI4wSVZEWyYLv25x1t/gljxo2ibqwVyr RWmTlrVDnAr37iZCtIoHw4JlJdf9QUByrlsap9iNQLM8B/nOv6fzqZfg8 w4+XAnOIVKOXLFysSxtqJjAljIu7cnJxjdygyTcDf67c6F0BOmU1hdU9z w==; X-CSE-ConnectionGUID: EZrOuzUwRI2EFSimbKvAZQ== X-CSE-MsgGUID: hdWqX4YNQEGDom88LoSbkA== X-IronPort-AV: E=Sophos;i="6.08,197,1712592000"; d="scan'208";a="16865344" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2024 15:13:33 +0800 IronPort-SDR: 6656c94d_XfDv6LWJCVs+UEfMphEjM1kB7/57M8Z98NbeXVgotcvEHTf wnB4Zo7Og+8nMBl7tBhaKOigiA+O46tB18Q7blQ== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 May 2024 23:21:02 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.62]) by uls-op-cesaip01.wdc.com with ESMTP; 29 May 2024 00:13:33 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Qu Wenruo Subject: [PATCH v4 04/10] btrfs-progs: mkfs: fix minimum size calculation for zoned mode Date: Wed, 29 May 2024 16:13:19 +0900 Message-ID: <20240529071325.940910-5-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240529071325.940910-1-naohiro.aota@wdc.com> References: <20240529071325.940910-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 Reviewed-by: Qu Wenruo --- 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 29 07:13:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13677951 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (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 081121667EC for ; Wed, 29 May 2024 07:13:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966822; cv=none; b=KMMoSXMccjQeQ65zqgP8qhbz6pjiu3FPlJEU7MFYFqxgQNa4lx3a2WwYUXibWmT/eWThd01mEhPO6H5f9lFMN82EDd0ftrtCknAWm2cDRY8A/Yl9ag76u9xj/JuTUHg+fKznX++rvCe8pwekLZp0fxuzgSQGoNyJyq5jbQwgC+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966822; c=relaxed/simple; bh=RRH0i+zs6OwMRK0hsjxAQJYgGLPDQ5LxzfkK8ZxMQQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SG7rMyncJEaNiLUWxXrqwtz/PtJvft7PhPbnP8xNiH7DV1YP4J7FUAJT4FSKjCMyBTINIlUeeeAIh0Xm8k3B+76DZvVu7iYfW79csnVwKAqLlx9qgUo/wI4pke1XSG1bq8OEyGPsCvxkMOK4guZ+h0B+qYqYTy3Lmzt45kqcVHw= 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=c3l/5+ii; arc=none smtp.client-ip=216.71.154.42 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="c3l/5+ii" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716966821; x=1748502821; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RRH0i+zs6OwMRK0hsjxAQJYgGLPDQ5LxzfkK8ZxMQQA=; b=c3l/5+iiWXY2CgI6rQCvW5za+9fuLJDvbrJFrDWiH/C7bYIZo0MKS1Eq jpuSNQc37tt7Ggylh+71yXeDKhSQyccWTgeHVCfoGJj9oI9hvHQ1hN2Rm 0vAP3MTFjNAi0iYKlCLNX7rinqnSPLp0pVdb+/hP4/Dzfi+Wua2uwZ1w1 FTK7KQF26+w8TMNug3YYa0ZwLALQBOxFTNE8oZqIwMeG60ZewGn/dSsUp DpW/pXZ8x+2QLU89laJi7NvJLAqFse/ODkeMSrXqx+nx0HYYczpnbi8tp oA3ayrJVv4eyDV0XyuhTvYdNUNbFDf8LomQ1TIg62k/8ZwbIYMNjreKYX g==; X-CSE-ConnectionGUID: H+622OaZRSOCc1e2Hd+EFg== X-CSE-MsgGUID: YuILdcp5QpWCQWCWBTd1Ww== X-IronPort-AV: E=Sophos;i="6.08,197,1712592000"; d="scan'208";a="16865345" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2024 15:13:34 +0800 IronPort-SDR: 6656c94e_tkek76fSAaUiNgGUJgSPA5MLXTrvvPeWckGxxnDewcR3Zcs KK8b3apIA2/W/pIDve7tn5khWxAoQtJ1xFD9APA== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 May 2024 23:21:03 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.62]) by uls-op-cesaip01.wdc.com with ESMTP; 29 May 2024 00:13:34 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH v4 05/10] btrfs-progs: mkfs: align byte_count with sectorsize and zone size Date: Wed, 29 May 2024 16:13:20 +0900 Message-ID: <20240529071325.940910-6-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240529071325.940910-1-naohiro.aota@wdc.com> References: <20240529071325.940910-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. device_get_partition_size_fd_stat() must be aligned down not to exceed the device size. And, btrfs_mkfs_size_dir() should have return sectorsize aligned size. So, add an UASSERT for it. Signed-off-by: Naohiro Aota Reviewed-by: Qu Wenruo --- mkfs/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mkfs/main.c b/mkfs/main.c index a437ecc40c7f..3446a5b1222f 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,9 +1630,11 @@ 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_down(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); + UASSERT(IS_ALIGNED(source_dir_size, sectorsize)); if (byte_count < source_dir_size) { if (S_ISREG(statbuf.st_mode)) { byte_count = source_dir_size; From patchwork Wed May 29 07:13:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13677953 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (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 B932E16726B for ; Wed, 29 May 2024 07:13:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966824; cv=none; b=d9Xoqw05Y9HzqaJra/XcALXOWA6KfcKuEIJYVrMPUD9MFlwG6vpFFHUUqeKGOgi99t6Ts/22mP3zUa+xUP2MaUclB5amN7U12czybKmkrPF/mUKS1MUf/J5t7eWHAE2Bsi1QgqSPdKtnPexGVhgRsCiDv64+wIcLd+v0esFKS10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966824; c=relaxed/simple; bh=ry26AqNbwTnYcG7ZE4Czs5f+gXbgatGc4qsIEWVYt7s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UbG8YE4AWCqY9HOafuA75awozBj1WDjAoLNs+6+g7q+befAol7mTtCUjo3VJgZav4lMvEFJtkufs/NhZTcvqh9XucaEz04qe/p6hn4S8g4Ussn2AKHi/PktFAedEkeUYEAlLEeJnwPW2IYb0YwqQ9VmF4ik3Nnu74R0MC833tA4= 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=AShNnZdu; arc=none smtp.client-ip=216.71.154.42 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="AShNnZdu" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716966821; x=1748502821; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ry26AqNbwTnYcG7ZE4Czs5f+gXbgatGc4qsIEWVYt7s=; b=AShNnZduoGT9ICrNDZ+UwOV69d0muFNJfx8yhRVwE1qbPdJqQLhLx+VO Ni5UXZaqZoLJY3NKT+lPkQFXWlTg//HPRc161mWpWSmXpqK5fnCJwlLFw pt4kSTjE+kc9smn1JLG0Wn82vLrDHnJy0eUBiVzsDVDy2XjGL+/UFI5k6 k3UW5IhPQWJClvBwRPyf2TSzCBKuS9eOF33wpjDNrI2AbugoQiVfSGG8b +WCuhPhi7QlprAA4sdeoTO1j4xaU41xtTe+lox5/9PXD0TxQ8q1dygJtM FptKlpWuba8Kw3SQbl8IFk8CN5+iDEn85aGhDg3bPfgzg4bT8BjmkQuaP g==; X-CSE-ConnectionGUID: zmO4x05NTnKsoKOGMSD+GQ== X-CSE-MsgGUID: s4yd2NfTQcSOurlSYYoqDg== X-IronPort-AV: E=Sophos;i="6.08,197,1712592000"; d="scan'208";a="16865347" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2024 15:13:35 +0800 IronPort-SDR: 6656c94f_QAQJYMVoHVAa/Gr6u5WXLEBiOQWwTkRjL5vhOpijO3J2afV xYRnVzuv+Y3y6cU6Vj+h/fx6DGSgluiJrQrBLkw== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 May 2024 23:21:03 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.62]) by uls-op-cesaip01.wdc.com with ESMTP; 29 May 2024 00:13:34 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Qu Wenruo Subject: [PATCH v4 06/10] btrfs-progs: support byte length for zone resetting Date: Wed, 29 May 2024 16:13:21 +0900 Message-ID: <20240529071325.940910-7-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240529071325.940910-1-naohiro.aota@wdc.com> References: <20240529071325.940910-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 29 07:13:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13677952 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (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 F0E76167277 for ; Wed, 29 May 2024 07:13:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966823; cv=none; b=dyEaUD0T8fwDqf88wp3ejWQMD7StPEiAUd1t8tfFguOgKEW5xW3zZ8s+83gt53pwZpmimnZABzzYHiVuKVwF0sfJp9XWUETzTvfFxGZZhXDiWVJRpsRN+7lmQZYo0S36qJc4WHJRsiB2/PgmOeH7xUwxqfI59zY4ehGp84yFw0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966823; c=relaxed/simple; bh=R5LFSscyGt2HluMB4dxYPjK2W3lAzmiVBUiX9O/gb1k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BApbYtmx3YCGD+5GtkhjX0+BAFU60yxnXPUE6vezz/42ulFeAn9wGvnkk24wv164dx6g0jgciiI/csUl902qq6TUgjfFa0wkd5eFL8LqtP6WSHxcp10BcpCUSQ+23kmNnfiJcbHCaCJVDvp2k/8Uz7vVbAm5VwCNc2tuCGF88wQ= 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=d8hE3jeh; arc=none smtp.client-ip=216.71.154.42 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="d8hE3jeh" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716966822; x=1748502822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R5LFSscyGt2HluMB4dxYPjK2W3lAzmiVBUiX9O/gb1k=; b=d8hE3jehSpANZl6q4fzlPejZhQGbRnb3BbUUGYxIHsuVJZ2wJGFd1MpB yaZYmyN+pif4EXdGc7ApDsB5clwrjj52WYoEEKgkXfTvPDO8vgple9elw m1JYKWf8Xnpi//sse/0dHn1VWxrWgcQf6mKqBRBY+cm/g4c57HrLcbrw1 Dx4faQZqTZxGV3YGzLrZvxeTDn1/YzdTeCC2Q9i2Dif91Nna8LfUtasuo 02vlpTUA8MJKzMm1dt+ffR0yFX4Ow71BgsdQaSxx/pbgeAhKRD8R4Erj+ So/iubWkKr2q2zUPf535sdG4olRXpml30CssNqTvQBU8j5Hfd43eObBxK w==; X-CSE-ConnectionGUID: EzTfoKG/Q76b4wROqZBcvg== X-CSE-MsgGUID: cMVZnTvkQMaYrXJi55NxOA== X-IronPort-AV: E=Sophos;i="6.08,197,1712592000"; d="scan'208";a="16865349" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2024 15:13:36 +0800 IronPort-SDR: 6656c950_yGGIEUwQm+CS9uh7IG9xq15MZ7maygSrT1pJ1zJH+4RSoj1 /9BovcRjzgeweow2IBqoHFWF6cNEmSwfYOshv4A== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 May 2024 23:21:05 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.62]) by uls-op-cesaip01.wdc.com with ESMTP; 29 May 2024 00:13:35 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Qu Wenruo Subject: [PATCH v4 07/10] btrfs-progs: test: add nullb setup functions Date: Wed, 29 May 2024 16:13:22 +0900 Message-ID: <20240529071325.940910-8-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240529071325.940910-1-naohiro.aota@wdc.com> References: <20240529071325.940910-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 Reviewed-by: Qu Wenruo --- 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 29 07:13: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: 13677954 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (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 D390616728D for ; Wed, 29 May 2024 07:13:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966824; cv=none; b=T467tecOlYXj3qQLXYMy3istVBRL+kOoHqPgHzoZUufxOSDM78geZdmRHyTW5MaG/Lbs8anAr39Ub0A2wFxPjWReSPJ86xH9GM5XoDyHRakm6kTo9tbcPr+NxjAw74NTfX3uxGkANsIiLNEeseAcOUtMNAHiBuTDBiytWrjm3ak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966824; c=relaxed/simple; bh=fLsf/3m9l3+ERd408z8DH/bzykNNhkf2WOKkiQdOidw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KJzmFF1AajXEu7uv784Tw9/n7r/wjzTEo1+TM4CbLoZpMm/E26+KUSO15Yo0DKjB/eimKX17HYiFZnVIJHC9KRwByhue8SfdmABjsf3XrlOFN9v8zXftRuqqEV0//cu8Q0kb22VACkk+Si04epJxZux2Hmlt5W1sMZDPbC6w1Yw= 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=oOUSMvQn; arc=none smtp.client-ip=216.71.154.42 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="oOUSMvQn" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716966822; x=1748502822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fLsf/3m9l3+ERd408z8DH/bzykNNhkf2WOKkiQdOidw=; b=oOUSMvQnkwVP4z/n+zg9pq3f+1SNqm3N1sFU8BQkf7+/x7AHeN+yM1Bv vX6KiWwwEm3XlkjQ4xFL2Tdox93RCwVPehmEFqWjM4M9ccvvb3k9PBNHE 8PRRzWWszT8VALD5/uTmcftodteZwtGBAGe4LQCnoaSR+i0Ki2ZGY4xXV UgwMFCZO2/YDfntY9wd/ja6l2mhkrFPRhiUJsCG3BiB5fdreEeB90tnnc OGu8IevfbwpbnehNBmbng//nBrGN5P9IhviywnVldPB8pF/rNik1EWzsE 4TY0D4w7GPp3VTnQ26x7bSXU+vweXZV8lBQuoCDe3gte+4Hf8+OsvfF+3 Q==; X-CSE-ConnectionGUID: pLUsa7JsTc2lZoIbFt+xHg== X-CSE-MsgGUID: I5LFWovLR5GKP8RXv4Jyaw== X-IronPort-AV: E=Sophos;i="6.08,197,1712592000"; d="scan'208";a="16865350" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2024 15:13:37 +0800 IronPort-SDR: 6656c951_nMxtgf4rQxdVsmB0miL0lQFf4Lrnf1BqKGLQB1KFz1IxeU/ Efx3UteXjOgT8st1cOS05v0EAJ/VJYNrdFV+/sQ== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 May 2024 23:21:05 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.62]) by uls-op-cesaip01.wdc.com with ESMTP; 29 May 2024 00:13:36 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Qu Wenruo Subject: [PATCH v4 08/10] btrfs-progs: test: add test for zone resetting Date: Wed, 29 May 2024 16:13:23 +0900 Message-ID: <20240529071325.940910-9-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240529071325.940910-1-naohiro.aota@wdc.com> References: <20240529071325.940910-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 Reviewed-by: Qu Wenruo --- 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 29 07:13: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: 13677955 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (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 AC2FD16729F for ; Wed, 29 May 2024 07:13:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966825; cv=none; b=nLg0cuervX19xSRMwmr6H9AUciOoK8lva5gumFqV4aDBkl05KmpV0PWe02gBX92WZxRh8MTu8JJEQsnWzMZIzpzwmzyDihf4y/Wc1TiUPksBJMBFZDovZ36kTqA+wJyZT97GBfgrSabIS88XEzvKjC1TE3jfBmasp5FpLUVZxE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966825; c=relaxed/simple; bh=uZcIG1Z05gbvssV/KG6a10C2OPcE+6aIE5uZvc3mnGY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iEuEY8QTFIYD7nssyvzWsTuyHaqCCILSQcYhd6f8mNINOSWoVQ+h1rp1uSLpUNti3wdkK3GATMzcbkX/UdKRmMHFcp22XKQOFoReSZbdqy7fq2WHA71mDkLIPOzJIvFu33sF1VNqGrcDalhtC7TS1PH/zr8bja73GktzivyUtGU= 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=aM5bB/3k; arc=none smtp.client-ip=216.71.154.42 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="aM5bB/3k" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716966823; x=1748502823; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uZcIG1Z05gbvssV/KG6a10C2OPcE+6aIE5uZvc3mnGY=; b=aM5bB/3kKkhU5fUwTHEyKHhCHhGQTZA2ahPdV6ZfKTERWgITwTZ9lj8G AFO8PcoqSt308bImdbZ/U8X7pd182V9qF0HyebzQsGS3zxLkXmVdcKErC p24NKe1udRK2IQT4/W3yP+0at+Om07fkrl2H4QXhVfIVentT8mxrGktzW UTqP3Jy8kFHQASWK0i7D1v4BqfP/EWGSeBYQqVoVDjfikxEDq/DeXAXvH uPeCqkNgORM/XQtHG9c2Npa3TNvkVKtHTNcqCMVni2b76EMI7ldnKruuP Hslrzxl9K7GeH1ebShGYlboLchclpWatms828dMlDmkTooWCkPzRGUCSC Q==; X-CSE-ConnectionGUID: ahUM2zLdRlWNMxw47Sfc0Q== X-CSE-MsgGUID: 5NPn5GBSQOi0bvujzDZdwA== X-IronPort-AV: E=Sophos;i="6.08,197,1712592000"; d="scan'208";a="16865351" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2024 15:13:38 +0800 IronPort-SDR: 6656c952_GzzN2FM2OO8jaRR1+7DZns/qLpcLiEBleJsOnwlGhE+dp2I nyQaGEy5FrF9FMYDAsHj5/BjaaiNo0wY9Wu4ucA== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 May 2024 23:21:06 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.62]) by uls-op-cesaip01.wdc.com with ESMTP; 29 May 2024 00:13:37 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Qu Wenruo Subject: [PATCH v4 09/10] btrfs-progs: test: use nullb helper and smaller zone size Date: Wed, 29 May 2024 16:13:24 +0900 Message-ID: <20240529071325.940910-10-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240529071325.940910-1-naohiro.aota@wdc.com> References: <20240529071325.940910-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 Reviewed-by: Qu Wenruo --- 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 29 07:13: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: 13677956 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (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 73EC0167D94 for ; Wed, 29 May 2024 07:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966825; cv=none; b=qvBJ1FjhXuUPPZXKoaMp0hpVQJkjHrs1SBEB2UyeQ4gYHecocNL1PNklGnUjWxlFvkeQtNOt4YZ6Rb0ppr11FWpvKB655zeCCx9xEoo5apGxhXARZoKwbIHo4X06gfdEjqwPAs42NskjO/4iDsV5z+kWj8cpo2SlGiFVT9UuvHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716966825; c=relaxed/simple; bh=ZhIrO75nhRZjU15nUgPpUwToGimb0hwXNBSUt61BJpk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pdmJq3OK3lbgDbByQX7INZcbmLNvxhz1+OJ4TYaueMwK3m8h/Akgtoe1IOWU6L9obk/17ABzsXXX2PNyiX9vnfFhtQ8d7nKElJldAcvYYqLevo0OL1hsb7IzdJYqi+AIF6pk169MG3eWpHUjm464xnJpj9ZcLLfFb/y+zIlCXho= 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=o3n2ErrB; arc=none smtp.client-ip=216.71.154.42 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="o3n2ErrB" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1716966824; x=1748502824; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZhIrO75nhRZjU15nUgPpUwToGimb0hwXNBSUt61BJpk=; b=o3n2ErrBCnSIpC3IVKcvDoWWuNYxW/VD941QXTMyxc2ICcYXSG5VETe3 u1Ft7d5b2v49csJmKO2a6ECYEAZ7oqXDDldEbISqusLX7KTNBueY0XgMG TKBYi1wWGK0mi46/0wpQhyzHa4GKP57/wu0pELgG547XM8MWKjtfcrOkV 0HXxhOViGR+w/2oQDmEdqXsZqVkSwp7RF4ITeq7lEJ0oRuD+VhWVc9iJN gFSE7iIZzKIKJnBErI8PfVBj87ysN8Sp5JwiZ20k2LC5c93ZarGuM9sEg jb/hjZAXfQzBrJeY2P4RAac9OATkzLMANvXNf+MKc8BhWewMjhHNe2lAQ g==; X-CSE-ConnectionGUID: NQcxbT/jQhS9/Ij/khGxFA== X-CSE-MsgGUID: DnIjC7I8Qo206Q2xTlkQ8Q== X-IronPort-AV: E=Sophos;i="6.08,197,1712592000"; d="scan'208";a="16865353" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2024 15:13:39 +0800 IronPort-SDR: 6656c953_rZ9onBDbuUeILI1KN+6vxxfMXt2XtdvgcVMnQ6B0m/P82/x wRWhJJjoSWbB81DHNmMLiU6C8iGVHjuXZ3s2KDA== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 May 2024 23:21:07 -0700 WDCIronportException: Internal Received: from unknown (HELO naota-xeon.wdc.com) ([10.225.163.62]) by uls-op-cesaip01.wdc.com with ESMTP; 29 May 2024 00:13:38 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota , Qu Wenruo Subject: [PATCH v4 10/10] btrfs-progs: test: use nullb helpers in 031-zoned-bgt Date: Wed, 29 May 2024 16:13:25 +0900 Message-ID: <20240529071325.940910-11-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240529071325.940910-1-naohiro.aota@wdc.com> References: <20240529071325.940910-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 Reviewed-by: Qu Wenruo --- 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