makefs/zfs: Avoid generating a GUID of zero

This commit is contained in:
Mark Johnston 2023-05-26 15:14:00 -04:00
parent 844942888f
commit 14c5cf3a16
3 changed files with 20 additions and 3 deletions

View File

@ -274,6 +274,22 @@ nvlist_copy(const nvlist_t *nvl, char *buf, size_t sz)
memcpy(buf + sizeof(nvl->nv_header), nvl->nv_data, nvl->nv_size);
}
/*
* Avoid returning a GUID of 0, just to avoid the possibility that something
* will interpret that as meaning that the GUID is uninitialized.
*/
uint64_t
randomguid(void)
{
uint64_t ret;
do {
ret = ((uint64_t)random() << 32) | random();
} while (ret == 0);
return (ret);
}
static nvlist_t *
pool_config_nvcreate(zfs_opt_t *zfs)
{
@ -529,8 +545,8 @@ pool_init(zfs_opt_t *zfs)
{
uint64_t dnid;
zfs->poolguid = ((uint64_t)random() << 32) | random();
zfs->vdevguid = ((uint64_t)random() << 32) | random();
zfs->poolguid = randomguid();
zfs->vdevguid = randomguid();
zfs->mos = objset_alloc(zfs, DMU_OST_META);

View File

@ -602,7 +602,7 @@ dsl_dataset_alloc(zfs_opt_t *zfs, zfs_dsl_dir_t *dir)
ds->phys->ds_creation_txg = TXG - 1;
if (ds != zfs->snapds)
ds->phys->ds_prev_snap_txg = TXG - 1;
ds->phys->ds_guid = ((uint64_t)random() << 32) | random();
ds->phys->ds_guid = randomguid();
ds->dir = dir;
return (ds);

View File

@ -168,5 +168,6 @@ struct dnode_cursor *dnode_cursor_init(zfs_opt_t *, zfs_objset_t *,
dnode_phys_t *, off_t, off_t);
blkptr_t *dnode_cursor_next(zfs_opt_t *, struct dnode_cursor *, off_t);
void dnode_cursor_finish(zfs_opt_t *, struct dnode_cursor *);
uint64_t randomguid(void);
#endif /* !_MAKEFS_ZFS_H_ */