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
This commit is contained in:
Colin Walters 2017-06-27 21:26:17 -04:00 committed by Atomic Bot
parent 5776d5dcc0
commit ba918e49c5
4 changed files with 15 additions and 51 deletions

@ -1 +1 @@
Subproject commit caa51ac24ffcdffcb610bc6ccc9da964d4be74ee Subproject commit 01e934c18efdbac071ebc19a8a95916d324970c9

View File

@ -416,22 +416,6 @@ add_size_index_to_metadata (OstreeRepo *self,
return ret; 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 /* 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. * 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)) &tmpf, error))
return FALSE; return FALSE;
if (!ot_fallocate (tmpf.fd, length, error)) if (!glnx_try_fallocate (tmpf.fd, 0, length, error))
return FALSE; return FALSE;
if (G_IS_FILE_DESCRIPTOR_BASED (input)) 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, if (!glnx_open_tmpfile_linkable_at (self->tmp_dir_fd, ".", O_WRONLY|O_CLOEXEC,
&tmpf, error)) &tmpf, error))
return FALSE; return FALSE;
if (!ot_fallocate (tmpf.fd, len, error)) if (!glnx_try_fallocate (tmpf.fd, 0, len, error))
return FALSE; return FALSE;
if (glnx_loop_write (tmpf.fd, bufp, len) < 0) if (glnx_loop_write (tmpf.fd, bufp, len) < 0)
return glnx_throw_errno_prefix (error, "write()"); return glnx_throw_errno_prefix (error, "write()");
@ -1179,9 +1163,9 @@ rename_pending_loose_objects (OstreeRepo *self,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;
if (G_UNLIKELY (renameat (child_dfd_iter.fd, loose_objpath + 3, if (!glnx_renameat (child_dfd_iter.fd, loose_objpath + 3,
self->objects_dir_fd, loose_objpath) < 0)) self->objects_dir_fd, loose_objpath, error))
return glnx_throw_errno (error); return FALSE;
renamed_some_object = TRUE; renamed_some_object = TRUE;
} }

View File

@ -442,8 +442,7 @@ get_unpacked_unlinked_content (OstreeRepo *repo,
g_autoptr(GInputStream) istream = NULL; g_autoptr(GInputStream) istream = NULL;
g_autoptr(GOutputStream) out = NULL; g_autoptr(GOutputStream) out = NULL;
if (!glnx_open_tmpfile_linkable_at (AT_FDCWD, "/tmp", O_RDWR | O_CLOEXEC, if (!glnx_open_anonymous_tmpfile (O_RDWR | O_CLOEXEC, &tmpf, error))
&tmpf, error))
return FALSE; return FALSE;
if (!ostree_repo_load_file (repo, checksum, &istream, NULL, NULL, if (!ostree_repo_load_file (repo, checksum, &istream, NULL, NULL,
@ -1159,15 +1158,6 @@ get_fallback_headers (OstreeRepo *self,
return TRUE; 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: * ostree_repo_static_delta_generate:
* @self: Repo * @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_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++) for (i = 0; i < builder.parts->len; i++)
{ {
OstreeStaticDeltaPartBuilder *part_builder = builder.parts->pdata[i]; OstreeStaticDeltaPartBuilder *part_builder = builder.parts->pdata[i];

View File

@ -74,14 +74,8 @@ symlink_at_replace (const char *oldpath,
} }
/* Rename it into place */ /* Rename it into place */
do if (!glnx_renameat (parent_dfd, temppath, parent_dfd, newpath, error))
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; goto out;
}
ret = TRUE; ret = TRUE;
out: out:
@ -819,8 +813,8 @@ merge_configuration (OstreeSysroot *sysroot,
else if (etc_exists) else if (etc_exists)
{ {
/* Compatibility hack */ /* Compatibility hack */
if (renameat (deployment_dfd, "etc", deployment_dfd, "usr/etc") < 0) if (!glnx_renameat (deployment_dfd, "etc", deployment_dfd, "usr/etc", error))
return glnx_throw_errno_prefix (error, "renameat"); return FALSE;
usretc_exists = TRUE; usretc_exists = TRUE;
etc_exists = FALSE; etc_exists = FALSE;
} }
@ -1424,7 +1418,6 @@ swap_bootloader (OstreeSysroot *sysroot,
GError **error) GError **error)
{ {
glnx_fd_close int boot_dfd = -1; glnx_fd_close int boot_dfd = -1;
int res;
g_assert ((current_bootversion == 0 && new_bootversion == 1) || g_assert ((current_bootversion == 0 && new_bootversion == 1) ||
(current_bootversion == 1 && new_bootversion == 0)); (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; * its data is in place. Renaming now should give us atomic semantics;
* see https://bugzilla.gnome.org/show_bug.cgi?id=755595 * see https://bugzilla.gnome.org/show_bug.cgi?id=755595
*/ */
do if (!glnx_renameat (boot_dfd, "loader.tmp", boot_dfd, "loader", error))
res = renameat (boot_dfd, "loader.tmp", boot_dfd, "loader"); return FALSE;
while (G_UNLIKELY (res == -1 && errno == EINTR));
if (res == -1)
return glnx_throw_errno (error);
/* Now we explicitly fsync this directory, even though it /* Now we explicitly fsync this directory, even though it
* isn't required for atomicity, for two reasons: * isn't required for atomicity, for two reasons: