[Libguestfs] RFC: copy-attributes command

Richard W.M. Jones rjones at redhat.com
Fri Jan 10 13:33:38 UTC 2014


On Fri, Jan 10, 2014 at 02:17:48PM +0100, Pino Toscano wrote:
> > This code looks as if it will copy the xattrs, but it won't
> > remove any which don't exist in the source.  eg:
> > 
> >   source xattrs before:
> >     user.foo = 1
> >   dest xattrs before:
> >     user.bar = 2
> >   dest xattrs after:
> >     user.foo = 1
> >     user.bar = 2
> > 
> > That may or may not be what we want, but I would say it's a bit
> > unexpected.
> 
> Yes, the current behaviour is done on purpose; my thought that, given 
> the command is "copy attributes", it would just copy what specified from 
> the source to the destination.
> 
> I see reasons for both the behaviours, so I'm not totally sure which one 
> pick.

On the basis that most users will be creating a new file (which will
have no xattrs except in some very odd corner cases), just leave your
implementation for now, but don't specify it in the documentation so
we could change it later.

> > - Should it default to copying attributes?
> 
> You've convinced me, so I've turned the "permissions" flag into 
> "skipmode", so specifying nothing now copies the file mode (so 
> permissions + bits).
> 
> > The common use case (for virt-edit) is: "I want this other file which
> > is identical to this original file, except in name and content".  That
> > is (I think) an argument for copying everything by default.
> 
> I've added a "all" argument which would enable every change, overriding 
> even mode:false.

The API is now pretty confusing.  Each OBool flag is really a
tristate.  It can either be "true", "false" or "not specified".

Therefore I think it should be:

  xattributes:true            # copies only xattrs and nothing else
  all:true                    # copies everything
  all:true xattributes:false  # copies everything except xattrs

In other words, 'all' changes the default (ie. "not specified") state
of the other flags.

To be clearer, the four OBool parameters would be:

  [OBool "all"; OBool "mode"; OBool "ownership"; OBool "xattributes"]

> > I would have thought owner uid and group gid should be copied.
> 
> Oh true, forgot about them; added a new "ownership" argument.
> 
> > - Is there anything else which is useful to copy?
> 
> Maybe there's also copying atime/mtime too; worth having a single 
> argument ("time") for both, or two separate?

For virt-edit, I would _not_ want it to copy the old time(s).  The
time would be updated.

But I guess there's a use for copying the time(s), so this could be
another flag.

We're allowed to extend the API later by adding optional flags (see
"Note about extending functions" in generator/README for the
complicated rules about extending APIs while preserving binary
compatibility).

> +=over 4
> +
> +=item C<xattributes>
> +
> +Copy the Linux extended attributes (xattrs) from C<source> to C<destination>.
> +This flag does nothing if the I<linuxxattrs> feature is not available
> +(see C<guestfs_feature_available>).
> +
> +=item C<all>

^ Typo in this line.

> +Copy the owner uid and the group gid of C<source> to C<destination>.
> +
> +=item C<all>
> +
> +Copy B<all> the attributes from C<source> to C<destination>.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/




More information about the Libguestfs mailing list