makefs: Record a larger TXG number in the uberblock

By default, OpenZFS will perform metadata verification of the most
recent TXGs, but this can be very slow since all data in a pool
generated by makefs was logically written in a single transaction.

Avoid triggering this verification by default, but add an option to
restore the previous behaviour and enable it in regression test cases.

Reported by:	cperciva
Tested by:	cperciva (previous version)
MFC after:	2 weeks
This commit is contained in:
Mark Johnston 2024-10-14 13:08:09 +00:00
parent 09526a771a
commit 4e15366c6a
4 changed files with 19 additions and 1 deletions

View file

@ -532,6 +532,9 @@ By default,
allocates large (up to 512MB) metaslabs with the expectation that
the image will be auto-expanded upon first use.
This option allows the default heuristic to be overridden.
.It verify-txgs
Prompt OpenZFS to verify pool metadata during import.
This is disabled by default as it may significantly increase import times.
.It poolname
The name of the ZFS pool.
This option must be specified.

View file

@ -28,7 +28,7 @@
# SUCH DAMAGE.
#
MAKEFS="makefs -t zfs"
MAKEFS="makefs -t zfs -o verify-txgs=true"
ZFS_POOL_NAME="makefstest$$"
TEST_ZFS_POOL_NAME="$TMPDIR/poolname"

View file

@ -91,6 +91,8 @@ zfs_prep_opts(fsinfo_t *fsopts)
0, 0, "Prefix for all dataset mount points" },
{ '\0', "ashift", &zfs->ashift, OPT_INT32,
MINBLOCKSHIFT, MAXBLOCKSHIFT, "ZFS pool ashift" },
{ '\0', "verify-txgs", &zfs->verify_txgs, OPT_BOOL,
0, 0, "Make OpenZFS verify data upon import" },
{ '\0', "nowarn", &zfs->nowarn, OPT_BOOL,
0, 0, "Provided for backwards compatibility, ignored" },
{ .name = NULL }
@ -594,7 +596,18 @@ pool_labels_write(zfs_opt_t *zfs)
ub = (uberblock_t *)(&label->vl_uberblock[0] + uoff);
ub->ub_magic = UBERBLOCK_MAGIC;
ub->ub_version = SPA_VERSION;
/*
* Upon import, OpenZFS will perform metadata verification of
* the last TXG by default. If all data is written in the same
* TXG, it'll all get verified, which can be painfully slow in
* some cases, e.g., initial boot in a cloud environment with
* slow storage. So, fabricate additional TXGs to avoid this
* overhead, unless the user requests otherwise.
*/
ub->ub_txg = TXG;
if (!zfs->verify_txgs)
ub->ub_txg += TXG_SIZE;
ub->ub_guid_sum = zfs->poolguid + zfs->vdevguid;
ub->ub_timestamp = 0;

View file

@ -55,6 +55,7 @@ _Static_assert(MINBLOCKSIZE == SPA_MINBLOCKSIZE, "");
/* All data was written in this transaction group. */
#define TXG 4
#define TXG_SIZE 4
typedef struct zfs_dsl_dataset zfs_dsl_dataset_t;
typedef struct zfs_dsl_dir zfs_dsl_dir_t;
@ -82,6 +83,7 @@ typedef struct {
int ashift; /* vdev block size */
uint64_t mssize; /* metaslab size */
STAILQ_HEAD(, dataset_desc) datasetdescs; /* non-root dataset descrs */
bool verify_txgs; /* verify data upon import */
/* Pool state. */
uint64_t poolguid; /* pool and root vdev GUID */