• L
    Rename virFileCreate to virFileOperation, add hook function · fbadc2b6
    Laine Stump 提交于
    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.
    fbadc2b6
util.h 9.5 KB