Skip to content
Snippets Groups Projects
  1. Jul 17, 2017
    • Colin Walters's avatar
      Remove glnx_stream_fstat() · 8b75c8e3
      Colin Walters authored
      There are only two users of this in ostree, and one of them is
      fairly bogus; we can just use `fstat()`.
      8b75c8e3
    • Colin Walters's avatar
      fdio: Add cleanup+flush API for FILE* · e30a773f
      Colin Walters authored
      Mostly in ostree/rpm-ostree, we work in either raw `int fd`, or
      `G{Input,Output}Stream`.  One exception is the rpm-ostree `/etc/passwd`
      handling, which uses `FILE*` since that's what glibc exposes.
      
      And in general, there are use cases for `FILE*`; the raw `GUnixOutputStream` for
      example isn't buffered, and doing so via e.g. `GBufferedOutputStream` means
      allocating *two* GObjects and even worse going through multiple vfuncs for every
      write.
      
      `FILE*` is used heavily in systemd, and provides buffering. It is a bit cheaper
      than gobjects, but has its own trap; by default every operation locks a mutex.
      For more information on that, see `unlocked_stdio(3)`. However, callers can
      avoid that by using e.g. `fwrite_unlocked`, which I plan to do for most users of
      `FILE*` that aren't writing to one of the standard streams like `stdout` etc.
      e30a773f
  2. Jul 10, 2017
  3. Jun 28, 2017
  4. Jun 26, 2017
  5. Jun 14, 2017
    • Colin Walters's avatar
      Add G_IN_SET, patch our internal users via spatch · 9a1b77ef
      Colin Walters authored
      I originally tried to get this into GLib:
      https://bugzilla.gnome.org/show_bug.cgi?id=783751
      
      But that looks like it's going to fail due to MSVC. Let's add it here at least
      so I can start using it tomorrow and not wait for the MSVC team to catch up.
      
      I renamed `glnx-alloca.h` to `glnx-macros.h` as a more natural collective
      home for things from systemd's `macro.h`.
      
      Finally, I used a Coccinelle spatch similar to the one referenced
      in the above BZ to patch our uses.
      9a1b77ef
  6. Jun 13, 2017
  7. May 19, 2017
  8. May 17, 2017
  9. May 15, 2017
    • Colin Walters's avatar
      fdio: Redo tmpfile API with GLnxTmpfile struct · 9929adcd
      Colin Walters authored
      The core problem with the previous tmpfile code
      is we don't have an autocleanup that calls `unlinkat`
      in the non-`O_TMPFILE` case.  And even if we did, it'd
      be awkward still since the `glnx_link_tmpfile_at()` call
      *consumes* the tmpfile.
      
      Fix this by introducing a struct with a cleanup macro. This simplifies a number
      of the callers in libostree - a notable case is where we had two arrays, one of
      fds, one of paths. It makes other places in libostree a bit more complex, but
      that's because some of the commit code paths want to deal with temporary
      *symlinks* too.
      
      Most callers are better though - in libglnx itself, `glnx_file_copy_at()` now
      correctly unlinks on failure for example.
      9929adcd
  10. Apr 28, 2017
    • Colin Walters's avatar
      fdio: Expose glnx_regfile_copy_bytes(), rewrite: GNU style, POSIX errno · 3a4d0f46
      Colin Walters authored
      NOTE: This changes the error handling API of `glnx_loop_write()` to be
      "old school POSIX" instead of "systemd".
      
      In ostree in a few places we use `g_output_stream_splice()`.  I
      thought this would use `splice()`, but actually it doesn't today.
      
      They also, if a cancellable is provided, end up dropping into `poll()` for every
      read and write. (In addition to copying data to/from userspace).
      
      My opinion on this is - for *local files* that's dumb. In the big picture, you
      really only need cancellation when copying gigabytes. Down the line, we could
      perhaps add a `glnx_copy_bytes_cancellable()` that only did that check e.g.
      every gigabyte of copied data. And when we do that we should use
      `g_cancellable_set_error_if_cancelled()` rather than a `poll()` with the regular
      file FD, since regular files are *always* readable and writable.
      
      For my use case with rpm-ostree though, we don't have gigabyte sized files, and
      seeing all of the `poll()` calls in strace is annoying. So let's have the
      non-cancellable file copying API that's modern and uses both reflink and
      `sendfile()` if available, in that order.
      
      My plan at some point once this is tested more is to migrate this code
      into GLib.
      
      Note that in order to keep our APIs consistent, I switched the systemd-imported
      code to "old school POSIX" error conventions. Otherwise we'd have *3* (POSIX,
      systemd, and GError) and particularly given the first two are easily confused,
      it'd be a recipe for bugs.
      3a4d0f46
  11. Apr 25, 2017
    • Colin Walters's avatar
      fdio: Mostly port to new code style · dc1956b2
      Colin Walters authored
      There's one function that did `unlinkat()` in the cleanup section,
      not doing that yet.
      
      Note I uncovered a few bugs in a few places where we didn't preserve errno
      before doing an `unlinkat()` in error paths in a few cases.
      
      I also tried to prefix a few more error cases with the system call name.
      dc1956b2
  12. Mar 23, 2017
    • Jonathan Lebon's avatar
      glnx-errors.h: add glnx_null_throw[_*] variants · 0c52d85e
      Jonathan Lebon authored
      These are equivalent to the non-null throw, except that the returned
      value is a NULL pointer. They can be used in functions where one wants
      to return a pointer. E.g.:
      
      	GKeyFile *foo(GError **error) {
      		return glnx_null_throw (error, "foobar");
      	}
      
      The function call redirections are wrapped around a compound statement
      expression[1] so that they represent a single top-level expression. This
      allows us to avoid -Wunused-value warnings vs using a comma operator if
      the return value isn't used.
      
      I made the 'args...' absorb the fmt argument as well so that callers can
      still use it without always having to specify at least one additional
      variadic argument. I had to check to be sure that the expansion is all
      done by the preprocessor, so we don't need to worry about stack
      intricacies.
      
      [1] https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
      0c52d85e
  13. Mar 02, 2017
  14. Oct 05, 2016
  15. Aug 04, 2016
  16. Aug 03, 2016
  17. Jul 08, 2016
    • Colin Walters's avatar
      fdio: Add unlinkat() in error paths for tmpfiles · d2e588d9
      Colin Walters authored
      This is kind of an ABI change but it's for the better I think; on
      error we consistently clean up the temp file.
      
      This is obviously necessary without `O_TMPFILE`.  With it, we still
      need an error cleanup in the case where we're trying to replace an
      existing file.  I noticed this in ostree's `tests/test-refs.sh` which
      intentionally tries to rename a file over a directory path.
      d2e588d9
    • Colin Walters's avatar
      fdio: Use correct dfd with O_TMPFILE in rename case · 78ae7877
      Colin Walters authored
      While auditing this code to figure out why ostree's
      `tests/test-refs.sh` was failing, while the bug turned out to be
      different, I noticed that in the case where `dfd != target_dfd`, we
      failed to do the right `renameat()`.  (No code I'm aware of does this
      now).
      78ae7877
  18. Jul 01, 2016
    • Colin Walters's avatar
      fdio: Add open_tmpfile_linkable() and link_tmpfile_at() · 113c770d
      Colin Walters authored
      We had a bug previously where we failed to clean up a temporary file
      in an error path.  This is a classic case where the new `O_TMPFILE`
      API in Linux is nicer.
      
      To implement this, as usual we start with some original bits from
      systemd.  But in this case I ended up having to heavily modify it
      because systemd doesn't support "link into place and overwrite".  They
      don't actually use their tempfile code much at all in fact - as far as
      I can tell, just in the coredump code.
      
      Whereas in many apps, ostree included, a very common use case is
      atomically updating an existing file, which is
      `glnx_file_replace_contents_at()`, including subtleties like doing an
      `fdatasync()` if the file already existed.
      
      Implementing this then is slightly weird since we need to link() the
      file into place, then rename() after.
      
      It's still better though because if we e.g. hit `ENOSPC` halfway
      through, we'll clean up the file automatically.
      
      We still do keep the mode where we error out if the file exists.
      Finally, the ostree core though does have a more unusual case where we
      want to ignore EEXIST (allow concurrent object writers), so add
      support for that now.
      
      Note: One really confusing bug I had here was that `O_TMPFILE` ignores
      the provided mode, and this caused ostree to write refs that weren't
      world readable.
      
      Rework things so we always call `fchmod()`, but as a consequence we're
      no longer honoring umask in the default case.  I doubt anyone will
      care, and if they do we should probably fix ostree to consistently use
      a mode inherited from the repo or something.
      113c770d
  19. Jun 16, 2016
    • Yu Qi Zhang's avatar
      fdio: Delete .tmp file on failure · a6d08657
      Yu Qi Zhang authored
      We noticed the temp files being left over in ostree when (mistakenly)
      trying to replace the contents of a subpath that wasn't a directory.
      
      In the future we should look at the systemd code using `O_TMPFILE`
      here.
      a6d08657
  20. May 03, 2016
  21. Jan 11, 2016
    • Colin Walters's avatar
      fdio: Export loop_write · 3c470803
      Colin Walters authored
      I plan to use this in rpm-ostree.  Sad how many times this gets
      reinvented.  Should probably stick a copy in `glib-unix.h` or so.
      3c470803
  22. May 05, 2015
  23. Apr 21, 2015
  24. Apr 14, 2015
  25. Apr 13, 2015
  26. Apr 09, 2015
  27. Mar 17, 2015
  28. Mar 10, 2015
  29. Mar 03, 2015
    • Colin Walters's avatar
      fdio: Add glnx_file_copy_at() · 162d1f6b
      Colin Walters authored
      This will allow deleting some code from OSTree for the config file
      merging.  We're reusing some code from systemd, which a nice modern
      clean codebase, and among other things this gets us BTRFS reflinking
      (if available) again.
      162d1f6b
  30. Feb 20, 2015
    • Colin Walters's avatar
      fdio: New APIs to read/write on fds, fd-relative · 1ebfefa5
      Colin Walters authored
      We don't have this really in GLib, unfortunately.  We do want
      GCancellable, but we also want to operate on raw fds where possible.
      
      The "read a file and validate as UTF-8" is a common use case of mine,
      and this combines that with openat().
      1ebfefa5
Loading