From 430cc075637497b2a67371a1b894d808adff297b Mon Sep 17 00:00:00 2001 From: Li Wei Date: Thu, 9 Jul 2026 14:54:50 +0900 Subject: [PATCH] DAOS-19087 container: Disallow user-specified UUIDs Features: container Signed-off-by: Li Wei --- src/container/cli.c | 7 +++---- src/include/daos_uns.h | 8 ++++---- src/tests/daos_perf.c | 16 +++++++++++++--- src/tests/daos_racer.c | 16 +++++++++++++--- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/container/cli.c b/src/container/cli.c index 8421166f68f..126967cd564 100644 --- a/src/container/cli.c +++ b/src/container/cli.c @@ -365,10 +365,6 @@ dc_cont_create(tse_task_t *task) args = dc_task_get_args(task); - if (!daos_uuid_valid(args->uuid)) - /** generate a UUID for the new container */ - uuid_generate(args->uuid); - entry = daos_prop_entry_get(args->prop, DAOS_PROP_CO_STATUS); if (entry != NULL) { rc = -DER_INVAL; @@ -391,6 +387,9 @@ dc_cont_create(tse_task_t *task) rc = cont_task_create_priv(task, &tpriv); if (rc != 0) goto err_prop; + + /** generate a UUID for the new container */ + uuid_generate(args->uuid); } D_DEBUG(DB_MD, DF_UUID": creating "DF_UUIDF"\n", diff --git a/src/include/daos_uns.h b/src/include/daos_uns.h index c1d27a978ea..5ff9b1cd8f7 100644 --- a/src/include/daos_uns.h +++ b/src/include/daos_uns.h @@ -111,11 +111,11 @@ struct duns_attr_t { * is returned as a string in \a da_pool with duns_resolve_path(). */ uuid_t da_puuid; - /** IN/OUT: (Deprecated) Optional UUID of the cont to be created in duns_create_path(). + /** OUT: (Deprecated) Optional UUID of the cont created in duns_create_path(). * - * The UUID will be used to create the container in duns_create_path() if set, otherwise a - * random one will be generated. The cont UUID or label is returned as a string in \a - * da_cont with duns_resolve_path(). + * The container UUID is always generated by the DAOS system and users are not permitted to + * specify it; any value set on input is ignored. The generated cont UUID or the label is + * returned as a string in \a da_cont with duns_resolve_path(). */ uuid_t da_cuuid; /** IN: (Optional) For a POSIX container, set a default object class for all directories. */ diff --git a/src/tests/daos_perf.c b/src/tests/daos_perf.c index 9b5bbb8b8c5..8f77945c9a6 100644 --- a/src/tests/daos_perf.c +++ b/src/tests/daos_perf.c @@ -439,9 +439,10 @@ main(int argc, char **argv) /* * For daos_perf, if pool/cont uuids are supplied as command line - * arguments it's assumed that the pool/cont were created. If only a - * cont uuid is supplied then a pool and container will be created and - * the cont uuid will be used during creation + * arguments it's assumed that the pool/cont were already created and + * will be opened. Creating a container with a user-specified UUID is + * not allowed; a container UUID may only be supplied together with a + * pool UUID to open an existing container. */ if (!uuid_is_null(ts_ctx.tsc_pool_uuid)) { ts_ctx.tsc_skip_pool_create = true; @@ -449,6 +450,15 @@ main(int argc, char **argv) ts_ctx.tsc_skip_cont_create = true; } + if (!uuid_is_null(ts_ctx.tsc_cont_uuid) && !ts_ctx.tsc_skip_cont_create) { + if (ts_ctx.tsc_mpi_rank == 0) + fprintf(stderr, + "creating a container with a user-specified UUID is not " + "allowed; a container UUID may only be provided together " + "with a pool UUID to open an existing container\n"); + return -1; + } + if (ts_ctx.tsc_mpi_rank == 0) { if (!ts_ctx.tsc_skip_cont_create) uuid_generate(ts_ctx.tsc_cont_uuid); diff --git a/src/tests/daos_racer.c b/src/tests/daos_racer.c index be9ce67bf17..2cfdaa09c9b 100644 --- a/src/tests/daos_racer.c +++ b/src/tests/daos_racer.c @@ -529,9 +529,10 @@ main(int argc, char **argv) /* * For daos_racer, if pool/cont uuids are supplied as command line - * arguments it's assumed that the pool/cont were created. If only a - * cont uuid is supplied then a pool and container will be created and - * the cont uuid will be used during creation + * arguments it's assumed that the pool/cont were already created and + * will be opened. Creating a container with a user-specified UUID is + * not allowed; a container UUID may only be supplied together with a + * pool UUID to open an existing container. */ if (!uuid_is_null(ts_ctx.tsc_pool_uuid)) { ts_ctx.tsc_skip_pool_create = true; @@ -539,6 +540,15 @@ main(int argc, char **argv) ts_ctx.tsc_skip_cont_create = true; } + if (!uuid_is_null(ts_ctx.tsc_cont_uuid) && !ts_ctx.tsc_skip_cont_create) { + if (ts_ctx.tsc_mpi_rank == 0) + fprintf(stderr, + "creating a container with a user-specified UUID is not " + "allowed; a container UUID may only be provided together " + "with a pool UUID to open an existing container\n"); + D_GOTO(out, rc = -1); + } + if (seed == 0) { gettimeofday(&tv, NULL); seed = tv.tv_usec;