You need to sign in or sign up before continuing.
  • L
    util: refactor virFileOpenAs · 90e4d681
    Laine Stump 提交于
    virFileOpenAs previously would only try opening a file as the current
    user, or as a different user, but wouldn't try both methods in a
    single call. This made it cumbersome to use as a replacement for
    open(2). Additionally, it had a lot of historical baggage that led to
    it being difficult to understand.
    
    This patch refactors virFileOpenAs in the following ways:
    
    * reorganize the code so that everything dealing with both the parent
      and child sides of the "fork+setuid+setgid+open" method are in a
      separate function. This makes the public function easier to understand.
    
    * Allow a single call to virFileOpenAs() to first attempt the open as
      the current user, and if that fails to automatically re-try after
      doing fork+setuid (if deemed appropriate, i.e. errno indicates it
      would now be successful, and the file is on a networkFS). This makes
      it possible (in many, but possibly not all, cases) to drop-in
      virFileOpenAs() as a replacement for open(2).
    
      (NB: currently qemuOpenFile() calls virFileOpenAs() twice, once
      without forking, then again with forking. That unfortunately can't
      be changed without at least some discussion of the ramifications,
      because the requested file permissions are different in each case,
      which is something that a single call to virFileOpenAs() can't deal
      with.)
    
    * Add a flag so that any fchown() of the file to a different uid:gid
      is explicitly requested when the function is called, rather than it
      being implied by the presence of the O_CREAT flag. This just makes
      for less subtle surprises to consumers. (Commit
      b1643dc1 added the check for O_CREAT
      before forcing ownership. This patch just makes that restriction
      more explicit.)
    
    * If either the uid or gid is specified as "-1", virFileOpenAs will
      interpret this to mean "the current [gu]id".
    
    All current consumers of virFileOpenAs should retain their present
    behavior (after a few minor changes to their setup code and
    arguments).
    90e4d681
storage_backend.c 49.4 KB