]> git.ipfire.org Git - thirdparty/libvirt.git/commit
Rename virFileCreate to virFileOperation, add hook function
authorLaine Stump <laine@laine.org>
Fri, 19 Feb 2010 16:43:22 +0000 (17:43 +0100)
committerDaniel Veillard <veillard@redhat.com>
Fri, 19 Feb 2010 16:43:22 +0000 (17:43 +0100)
commitfbadc2b608122f387bfa13fb4f4334eb32ada63d
tree9500b3ab08490afdb4cdf52c78443c9f08b1699c
parent269556e5571acf0dd7a83d3ef26fa9819ae47c7e
Rename virFileCreate to virFileOperation, add hook function

It turns out it is also useful to be able to perform other operations
on a file created while running as a different uid (eg, write things
to that file), and possibly to do this to a file that already
exists. This patch adds an optional hook function to the renamed (for
more accuracy of purpose) virFileOperation; the hook will be called
after the file has been opened (possibly created) and gid/mode
checked/set, before closing it.

As with the other operations on the file, if the VIR_FILE_OP_AS_UID
flag is set, this hook function will be called in the context of a
child process forked from the process that called virFileOperation.
The implication here is that, while all data in memory is available to
this hook function, any modification to that data will not be seen by
the caller - the only indication in memory of what happened in the
hook will be the return value (which the hook should set to 0 on
success, or one of the standard errno values on failure).

Another piece of making the function more flexible was to add an
"openflags" argument. This arg should contain exactly the flags to be
passed to open(2), eg O_RDWR | O_EXCL, etc.

In the process of adding the hook to virFileOperation, I also realized
that the bits to fix up file owner/group/mode settings after creation
were being done in the parent process, which could fail, so I moved
them to the child process where they should be.

* src/util/util.[ch]: rename and rework virFileCreate-->virFileOperation,
  and redo flags in virDirCreate
* storage/storage_backend.c, storage/storage_backend_fs.c: update the
  calls to virFileOperation/virDirCreate to reflect changes in the API,
  but don't yet take advantage of the hook.
src/storage/storage_backend.c
src/storage/storage_backend_fs.c
src/util/util.c
src/util/util.h