tree-wide: Misc porting to newer libglnx APIs
authorColin Walters <walters@verbum.org>
Wed, 28 Jun 2017 01:26:17 +0000 (21:26 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 28 Jun 2017 15:27:56 +0000 (15:27 +0000)
 - Use the new tmpfile bits
 - `glnx_try_fallocate`
 - `glnx_renameat()`

Depends: https://github.com/GNOME/libglnx/pull/57

Update submodule: libglnx

Closes: #970
Approved by: jlebon

libglnx
src/libostree/ostree-repo-commit.c
src/libostree/ostree-repo-static-delta-compilation.c
src/libostree/ostree-sysroot-deploy.c

diff --git a/libglnx b/libglnx
index caa51ac24ffcdffcb610bc6ccc9da964d4be74ee..01e934c18efdbac071ebc19a8a95916d324970c9 160000 (submodule)
--- a/libglnx
+++ b/libglnx
@@ -1 +1 @@
-Subproject commit caa51ac24ffcdffcb610bc6ccc9da964d4be74ee
+Subproject commit 01e934c18efdbac071ebc19a8a95916d324970c9
index d64f6481593b54dff1f2a921d1281e759da6aeca..ad847e893e1a8133cd53377e4a280ef4a9277226 100644 (file)
@@ -416,22 +416,6 @@ add_size_index_to_metadata (OstreeRepo        *self,
   return ret;
 }
 
-static gboolean
-ot_fallocate (int fd, goffset size, GError **error)
-{
-  if (size == 0)
-    return TRUE;
-
-  int r = posix_fallocate (fd, 0, size);
-  if (r != 0)
-    {
-      /* posix_fallocate is a weird deviation from errno standards */
-      errno = r;
-      return glnx_throw_errno_prefix (error, "fallocate");
-    }
-  return TRUE;
-}
-
 /* Combines a check for whether or not we already have the object with
  * allocating a tempfile if we don't.  Used by the static delta code.
  */
@@ -496,7 +480,7 @@ create_regular_tmpfile_linkable_with_content (OstreeRepo *self,
                                       &tmpf, error))
     return FALSE;
 
-  if (!ot_fallocate (tmpf.fd, length, error))
+  if (!glnx_try_fallocate (tmpf.fd, 0, length, error))
     return FALSE;
 
   if (G_IS_FILE_DESCRIPTOR_BASED (input))
@@ -847,7 +831,7 @@ write_metadata_object (OstreeRepo         *self,
   if (!glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_WRONLY|O_CLOEXEC,
                                       &tmpf, error))
     return FALSE;
-  if (!ot_fallocate (tmpf.fd, len, error))
+  if (!glnx_try_fallocate (tmpf.fd, 0, len, error))
     return FALSE;
   if (glnx_loop_write (tmpf.fd, bufp, len) < 0)
     return glnx_throw_errno_prefix (error, "write()");
@@ -1179,9 +1163,9 @@ rename_pending_loose_objects (OstreeRepo        *self,
                                                     cancellable, error))
             return FALSE;
 
-          if (G_UNLIKELY (renameat (child_dfd_iter.fd, loose_objpath + 3,
-                                    self->objects_dir_fd, loose_objpath) < 0))
-            return glnx_throw_errno (error);
+          if (!glnx_renameat (child_dfd_iter.fd, loose_objpath + 3,
+                              self->objects_dir_fd, loose_objpath, error))
+            return FALSE;
 
           renamed_some_object = TRUE;
         }
index 6d26a1e51ccddf976514f42981ecf021fdbfe8c6..8a1bb1d2ba233b84bc8e985925ab0438e25deb6a 100644 (file)
@@ -442,8 +442,7 @@ get_unpacked_unlinked_content (OstreeRepo       *repo,
   g_autoptr(GInputStream) istream = NULL;
   g_autoptr(GOutputStream) out = NULL;
 
-  if (!glnx_open_tmpfile_linkable_at (AT_FDCWD, "/tmp", O_RDWR | O_CLOEXEC,
-                                      &tmpf, error))
+  if (!glnx_open_anonymous_tmpfile (O_RDWR | O_CLOEXEC, &tmpf, error))
     return FALSE;
 
   if (!ostree_repo_load_file (repo, checksum, &istream, NULL, NULL,
@@ -1159,15 +1158,6 @@ get_fallback_headers (OstreeRepo               *self,
   return TRUE;
 }
 
-static inline void
-glnx_tmpfile_clear_p (void *ptr)
-{
-  GLnxTmpfile *tmpf = ptr;
-  if (!tmpf)
-    return;
-  glnx_tmpfile_clear (tmpf);
-}
-
 /**
  * ostree_repo_static_delta_generate:
  * @self: Repo
@@ -1329,7 +1319,7 @@ ostree_repo_static_delta_generate (OstreeRepo                   *self,
     }
 
   part_headers = g_variant_builder_new (G_VARIANT_TYPE ("a" OSTREE_STATIC_DELTA_META_ENTRY_FORMAT));
-  part_temp_paths = g_ptr_array_new_with_free_func (glnx_tmpfile_clear_p);
+  part_temp_paths = g_ptr_array_new_with_free_func ((GDestroyNotify)glnx_tmpfile_clear);
   for (i = 0; i < builder.parts->len; i++)
     {
       OstreeStaticDeltaPartBuilder *part_builder = builder.parts->pdata[i];
index ed4831c18f5c6a85427c9c2465aa7392fbf7e42b..a1584f8cc8e8526d7e83491b5cbea7f2ccc4355a 100644 (file)
@@ -73,15 +73,9 @@ symlink_at_replace (const char    *oldpath,
       goto out;
     }
 
-  /* Rename it into place */ 
-  do
-    res = renameat (parent_dfd, temppath, parent_dfd, newpath);
-  while (G_UNLIKELY (res == -1 && errno == EINTR));
-  if (res == -1)
-    {
-      glnx_set_error_from_errno (error);
-      goto out;
-    }
+  /* Rename it into place */
+  if (!glnx_renameat (parent_dfd, temppath, parent_dfd, newpath, error))
+    goto out;
 
   ret = TRUE;
  out:
@@ -819,8 +813,8 @@ merge_configuration (OstreeSysroot         *sysroot,
   else if (etc_exists)
     {
       /* Compatibility hack */
-      if (renameat (deployment_dfd, "etc", deployment_dfd, "usr/etc") < 0)
-        return glnx_throw_errno_prefix (error, "renameat");
+      if (!glnx_renameat (deployment_dfd, "etc", deployment_dfd, "usr/etc", error))
+        return FALSE;
       usretc_exists = TRUE;
       etc_exists = FALSE;
     }
@@ -1424,7 +1418,6 @@ swap_bootloader (OstreeSysroot  *sysroot,
                  GError        **error)
 {
   glnx_fd_close int boot_dfd = -1;
-  int res;
 
   g_assert ((current_bootversion == 0 && new_bootversion == 1) ||
             (current_bootversion == 1 && new_bootversion == 0));
@@ -1436,11 +1429,8 @@ swap_bootloader (OstreeSysroot  *sysroot,
    * its data is in place.  Renaming now should give us atomic semantics;
    * see https://bugzilla.gnome.org/show_bug.cgi?id=755595
    */
-  do
-    res = renameat (boot_dfd, "loader.tmp", boot_dfd, "loader");
-  while (G_UNLIKELY (res == -1 && errno == EINTR));
-  if (res == -1)
-    return glnx_throw_errno (error);
+  if (!glnx_renameat (boot_dfd, "loader.tmp", boot_dfd, "loader", error))
+    return FALSE;
 
   /* Now we explicitly fsync this directory, even though it
    * isn't required for atomicity, for two reasons: