Skip to content

Commit

Permalink
bectl: push space-in-name check down into libbe
Browse files Browse the repository at this point in the history
This check was previously in `create` only, not applying to renames.  It
should really be applied at the libbe level, so that we can avoid
writing about this restriction over and over again.

While we're here: `bectl rename` always succeeds, even when it doesn't.
Start returning the error.

Approved by:	re (gjb)
Reported By:	Christian McDonald <cmcdonald netgate com>

(cherry picked from commit dadb9c7)
(cherry picked from commit 227e52a)
  • Loading branch information
kevans91 committed Apr 6, 2022
1 parent 41e0b07 commit 568f805
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 11 additions & 0 deletions lib/libbe/be.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,17 @@ be_validate_name(libbe_handle_t *lbh, const char *name)
if (!zfs_name_valid(name, ZFS_TYPE_DATASET))
return (BE_ERR_INVALIDNAME);

/*
* ZFS allows spaces in boot environment names, but the kernel can't
* handle booting from such a dataset right now. vfs.root.mountfrom
* is defined to be a space-separated list, and there's no protocol for
* escaping whitespace in the path component of a dev:path spec. So
* while loader can handle this situation alright, it can't safely pass
* it on to mountroot.
*/
if (strchr(name, ' ') != NULL)
return (BE_ERR_INVALIDNAME);

return (BE_ERR_SUCCESS);
}

Expand Down
9 changes: 2 additions & 7 deletions sbin/bectl/bectl.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ get_cmd_info(const char *cmd)
return (NULL);
}


static int
bectl_cmd_activate(int argc, char *argv[])
{
Expand Down Expand Up @@ -233,10 +232,7 @@ bectl_cmd_create(int argc, char *argv[])
bootenv = *argv;

err = BE_ERR_SUCCESS;
if (strchr(bootenv, ' ') != NULL)
/* BE datasets with spaces are not bootable */
err = BE_ERR_INVALIDNAME;
else if ((atpos = strchr(bootenv, '@')) != NULL) {
if ((atpos = strchr(bootenv, '@')) != NULL) {
/*
* This is the "create a snapshot variant". No new boot
* environment is to be created here.
Expand Down Expand Up @@ -478,7 +474,6 @@ bectl_cmd_rename(int argc, char *argv[])
dest = argv[2];

err = be_rename(be, src, dest);

switch (err) {
case BE_ERR_SUCCESS:
break;
Expand All @@ -487,7 +482,7 @@ bectl_cmd_rename(int argc, char *argv[])
src, dest);
}

return (0);
return (err);
}

static int
Expand Down

0 comments on commit 568f805

Please sign in to comment.