I wonder about the filesystem order as given by “zfs list”, for scripting purposes. It seems to be alphabetical and hierarchical, but is that guaranteed?
The man page describes the “-s” parameters, but ends with this paragraph:
“If no sorting options are specified the existing behavior of zfs list is preserved.”
Note that the man page never stated the default behavior…
(Not that it matters for my question above, but the script in question modifies non-default mountpoints on a backup system, so that custom mountpoints (e.g., under /var) don’t interfere with normal operation.)
Well, I agree that it seems the default sort order is zfs list -s name, but since it is not explicitly defined in the man pages, it is something that might change (not that I think it will) in future releases. And yes, I have some scripts that assume it is that way, so I guess it’s good coding practice to explicitly define the order every time I use zfs list.
By the way, I just found a problem with the sort order, in a case where I wanted to sort primarily on the hierarchical structure.
One dataset was named pool/vmstorage, and another was named pool/vmstorage-extra, both of these had several child datasets. The “-” made the vmstorage-extra dataset end up in the “wrong” place, so I had to use an underscore instead.
I looked in the zfsprops manpage (since that what’s the zfs list manpage refers to), but did not find any property that seemed to do exactly what I wanted it to.
If this was not totally clear, this is what zfs list -s name outputs:
I didn’t really care whether or not vmstorage or vmstorage-extra ended up on top, but I did want the two filesystems, including children, to be grouped together.
(Just for completeness, here is the output when using underscore instead:)
And yes, I could have created a script that managed this for me, but it is in my mind an unnecessary complexity (but still minor compared to all the other ways ZFS quirks have surprised me in the past).
I’d say this counts as a naive bug on what’s intended to be a simple alphanumeric sort, and I would encourage you to file it as such at the OpenZFS github.
“-” comes before “/” in ASCII, so you wind up with vmstorage_extra sorting above vmstorage/1. But in a filesystem-specific context, even a simple alpha sort should be prioritizing the slash above all other characters, so that you don’t wind up with child datasets orphaned from parents the way you’re complaining about here.
Again, if you ask me, this is a bug, and should be reported as such. Would be a pretty simple fix, and a worthwhile one to implement, but that’s gotta happen there, not here.