libzfs: teach zfs_create_ancestors() to accept properties

This will be used to support creating non-mountable ancestors in zfs(8).

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Rob Norris <robn@despairlabs.com>
Signed-off-by: Ivan Shapovalov <intelfx@intelfx.name>
Closes #17000
This commit is contained in:
Ivan Shapovalov 2025-01-28 12:07:58 +04:00 committed by Brian Behlendorf
parent 1eace59060
commit 2f3f1ab1ba
5 changed files with 20 additions and 6 deletions

View File

@ -766,6 +766,8 @@ _LIBZFS_H void libzfs_add_handle(get_all_cb_t *, zfs_handle_t *);
_LIBZFS_H int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
nvlist_t *);
_LIBZFS_H int zfs_create_ancestors(libzfs_handle_t *, const char *);
_LIBZFS_H int zfs_create_ancestors_props(libzfs_handle_t *, const char *,
nvlist_t *);
_LIBZFS_H int zfs_destroy(zfs_handle_t *, boolean_t);
_LIBZFS_H int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t);
_LIBZFS_H int zfs_destroy_snaps_nvl(libzfs_handle_t *, nvlist_t *, boolean_t);

View File

@ -356,6 +356,7 @@
<elf-symbol name='zfs_component_namecheck' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfs_create' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfs_create_ancestors' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfs_create_ancestors_props' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfs_crypto_attempt_load_keys' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfs_crypto_clone_check' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>
<elf-symbol name='zfs_crypto_create' type='func-type' binding='global-binding' visibility='default-visibility' is-defined='yes'/>

View File

@ -3581,7 +3581,8 @@ zfs_dataset_exists(libzfs_handle_t *hdl, const char *path, zfs_type_t types)
* Fail if the initial prefixlen-ancestor does not already exist.
*/
int
create_parents(libzfs_handle_t *hdl, char *target, int prefixlen)
create_parents(libzfs_handle_t *hdl, char *target, int prefixlen,
nvlist_t *props)
{
zfs_handle_t *h;
char *cp;
@ -3617,8 +3618,7 @@ create_parents(libzfs_handle_t *hdl, char *target, int prefixlen)
continue;
}
if (zfs_create(hdl, target, ZFS_TYPE_FILESYSTEM,
NULL) != 0) {
if (zfs_create(hdl, target, ZFS_TYPE_FILESYSTEM, props) != 0) {
opname = dgettext(TEXT_DOMAIN, "create");
goto ancestorerr;
}
@ -3656,6 +3656,17 @@ ancestorerr:
*/
int
zfs_create_ancestors(libzfs_handle_t *hdl, const char *path)
{
return zfs_create_ancestors_props(hdl, path, NULL);
}
/*
* Creates non-existing ancestors of the given path, applying extra
* properties provided in an nvlist.
*/
int
zfs_create_ancestors_props(libzfs_handle_t *hdl, const char *path,
nvlist_t *props)
{
int prefix;
char *path_copy;
@ -3679,7 +3690,7 @@ zfs_create_ancestors(libzfs_handle_t *hdl, const char *path)
return (-1);
if ((path_copy = strdup(path)) != NULL) {
rc = create_parents(hdl, path_copy, prefix);
rc = create_parents(hdl, path_copy, prefix, props);
free(path_copy);
}
if (path_copy == NULL || rc != 0)

View File

@ -199,7 +199,7 @@ extern uint32_t zfs_namespace_prop_flag(zfs_prop_t);
extern boolean_t zfs_is_mountable_internal(zfs_handle_t *);
extern int zfs_mount_setattr(zfs_handle_t *, uint32_t);
extern void remove_mountpoint(zfs_handle_t *);
extern int create_parents(libzfs_handle_t *, char *, int);
extern int create_parents(libzfs_handle_t *, char *, int, nvlist_t *);
extern zfs_handle_t *make_dataset_handle(libzfs_handle_t *, const char *);
extern zfs_handle_t *make_bookmark_handle(zfs_handle_t *, const char *,

View File

@ -4947,7 +4947,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap,
*cp = '\0';
if (flags->isprefix && !flags->istail && !flags->dryrun &&
create_parents(hdl, destsnap, strlen(tosnap)) != 0) {
create_parents(hdl, destsnap, strlen(tosnap), NULL) != 0) {
err = zfs_error(hdl, EZFS_BADRESTORE, errbuf);
goto out;
}