Re: [PATCH v5] btrfs-progs: add --subvol option to mkfs.btrfs

David Sterba
2024-08-14T22:21:02Z

On Thu, Aug 15, 2024 at 07:41:03AM +0930, Qu Wenruo wrote:
>
>
> 在 2024/8/15 07:27, David Sterba 写道:
> [...]
> >>
> >> You ignored all the things like owner/group/privilege bits and maybe
> >> even xattrs (for SELINUX) that will be needed.
> >
> > There are probably two main use cases:
> >
> > - create something simple, with files copied from a directory and now
> > newly also to make some directories subvolumes
> >
> > - create a filesystem where any detail can be specified, like uid/gid,
> > access rights, ACL, XATTR, ...
> >
> > So far the focus is on option 1 and it seems we have the most common use
> > covered. For option 2 the command line options are probably the wron
> > interface.
>
> Nope, the current implementation (inherited from the --rootdir option)
> handles both.
>
> We have everything, except the hardlinks, copied from the rootdir,
> including uid/gid/access mode, XATTR.

For rootdir it copies exactly the uid/git values. The use case I have in
mind is to allow to change it to eg. root:root although the source files
are onwed by a "user:group".

> > I suggest to use an approach using a list of definitions, e.g. in a
> > file, where each line says what should be done on the filesystem. This
> > is not a new idea, XFS has a protofile, which is ancient and we don't
> > have to copy the exact format, but it's the same idea.
>
> I think it's asking for problems that is already resolved.
>
> The current rootdir is already providing every functionality, except
> subvolume related ones (subvolume, snapshot, default subvolume etc).
>
> And Mark's excellent work handles the missing subvolume part, and he is
> also working on the default subvolume part too.
>
> So far I really see no reason to introduce a completely new and complex
> (and conflicting with --rootdir) interface, while everything can be done
> by --rootdir + --subvol already.
>
> The only exception is snapshot, but for mkosi usage, I didn't see much
> need for a snapshot.

I don't agree that everything is possible with --rootdir, like the
example above with the different user:group. Setting a root user
requires root but for cases where the image is built by an unprivileged
user it does not work. The difference is between actually modifying the
existing file (e.g. under SElinux or similar), but allowing the user to
create the filesystem image without limitations.