Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name component rules seem arbitrary and are inconsistent internally and with the OS #17202

Open
dodexahedron opened this issue Mar 30, 2025 · 0 comments
Labels
Type: Defect Incorrect behavior (e.g. crash, hang)

Comments

@dodexahedron
Copy link
Contributor

dodexahedron commented Mar 30, 2025

Not necessarily a "bug," per se, but questionable behavior, perhaps?

zfs create, zfs snapshot, and zfs bookmark are pretty lax with naming, compared to zpool create.

zpool create mandates that the first character of the pool name must be [a-zA-Z].

But each child dataset, including snapshots and bookmarks, allows a wider range of characters, including the initial character and final characters, to be in the range [a-z-A-Z0-9_:. -].

Observe:

zfs list -r -t all -H a
a       264K    13.1G   24K     /a
a/      97K     13.1G   24K     /a/
a/ /    73K     13.1G   25K     /a/ /
a/ / /  24K     13.1G   24K     /a/ / /
a/ / / @        0B      -       24K     -
a/ / / @        0B      -       24K     -
a/ / /          24K     13.1G   24K     /a/ / /
a/ / /  @       0B      -       24K     -
a/ / /  @       0B      -       24K     -
a/ / /  @               0B      -       24K     -

I mean sure, maybe that's your own fault if you name something so badly. Though it's easily conceivable for scripts to do things like this if input isn't trimmed properly.

Steps to reproduce (note this requires code from ece35e0 or later for relative paths):

truncate -s 1G a b c
zpool create a ./a ./b ./c
zfs create a/\ 
zfs create a/\ /\ 
zfs create a/\ /\ /\ 
zfs snapshot a/\ /\ /\ @\ 
zfs snapshot a/\ /\ /\ @\ \ 
zfs create a/\ /\ /\ \ 
zfs snapshot a/\ /\ /\ \ @\ 
zfs snapshot a/\ /\ /\ \ @\ \ 
zfs snapshot a/\ /\ /\ \ @\ \ \ \ \ \ \ \ \ \ 
zfs list -r -t all -H a

Everything but space seems just fine as the initial character, but, if pool names have tighter restrictions, shouldn't datasets follow the same rules?

A possible argument for tightening the dataset name rules could conceivably be that it makes copy/paste from terminals error-prone, as I realized while pasting this here, for two reasons:

  • The spaces are unescaped in the output
  • Many terminals will trim trailing spaces in output lines when copying to clipboard, which would have rendered the zpool history I ran to get the above repro commands useless had I not piped it through sed (zpool history a | sed s/\ /'\\'\ /g).

My thinking, if more restrictive naming is desired, is that name components should probably at least have the requirement of the initial character not being space, and perhaps the final character, as well.

Or, counterpoint (and what I think makes more sense overall):

If naming is cool to be so lax, why are there any artificial restrictions on printable non-reserved characters for name components at all? Why, for example, are $, ,, ', +, =, etc not allowed, so long as they're legal path components for the operating system?

And, either way, why can't the rules for the pool component of the name be the same as the rest of the dataset components? If it's just a string, that seems arbitrary as well. Especially the restriction that the first character of a pool name MUST be alpha. Why not at least alphanumeric? I'm not aware of any supported kernel that wouldn't allow a mountpoint of, for example /1.

To wit:

mkdir /1 && touch /1/2 && rm /1/2 && rmdir /1 && echo COOL || echo NOT COOL
@dodexahedron dodexahedron added the Type: Defect Incorrect behavior (e.g. crash, hang) label Mar 30, 2025
@dodexahedron dodexahedron changed the title Should spaces really be allowed as the first and last characters of a name component? Name component rules seem arbitrary and are inconsistent internally and with the OS Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Defect Incorrect behavior (e.g. crash, hang)
Projects
None yet
Development

No branches or pull requests

1 participant