From ba918e49c5dca5ee927f0ed5a9c6156e85170c9b Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 27 Jun 2017 21:26:17 -0400 Subject: [PATCH] tree-wide: Misc porting to newer libglnx APIs - 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 | 2 +- src/libostree/ostree-repo-commit.c | 26 ++++--------------- .../ostree-repo-static-delta-compilation.c | 14 ++-------- src/libostree/ostree-sysroot-deploy.c | 24 +++++------------ 4 files changed, 15 insertions(+), 51 deletions(-) diff --git a/libglnx b/libglnx index caa51ac2..01e934c1 160000 --- a/libglnx +++ b/libglnx @@ -1 +1 @@ -Subproject commit caa51ac24ffcdffcb610bc6ccc9da964d4be74ee +Subproject commit 01e934c18efdbac071ebc19a8a95916d324970c9 diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index d64f6481..ad847e89 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -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; } diff --git a/src/libostree/ostree-repo-static-delta-compilation.c b/src/libostree/ostree-repo-static-delta-compilation.c index 6d26a1e5..8a1bb1d2 100644 --- a/src/libostree/ostree-repo-static-delta-compilation.c +++ b/src/libostree/ostree-repo-static-delta-compilation.c @@ -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]; diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index ed4831c1..a1584f8c 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -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: