checkout/commit: Use glnx_regfile_copy_bytes() if possible

Rather than `g_output_stream_splice()`, where the input is a regular
file.

See https://github.com/GNOME/libglnx/pull/44 for some more information.

I didn't try to measure the performance difference, but seeing the
read()/write() to/from userspace mixed in with the pointless `poll()` annoyed me
when reading strace.

As a bonus, we will again start using reflinks (if available) for `/etc`,
which is a regression from the https://github.com/ostreedev/ostree/pull/797
changes (which before used `glnx_file_copy_at()`).

Also, for the first time we'll use reflinks when doing commits from file-backed
content. This happens in `rpm-ostree compose tree` today for example.

Update submodule: libglnx

Closes: #817
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-04-27 14:24:20 -04:00 committed by Atomic Bot
parent 05fda71cb1
commit 63497c65f3
4 changed files with 58 additions and 50 deletions

@ -1 +1 @@
Subproject commit 602fdd93cb7a339c6b5749eee73df926429a5ab8 Subproject commit 3a4d0f4684f4653338c4756c8a1abfc6b5738467

View File

@ -102,7 +102,7 @@ fsync_is_enabled (OstreeRepo *self,
static gboolean static gboolean
write_regular_file_content (OstreeRepo *self, write_regular_file_content (OstreeRepo *self,
OstreeRepoCheckoutAtOptions *options, OstreeRepoCheckoutAtOptions *options,
GOutputStream *output, int outfd,
GFileInfo *file_info, GFileInfo *file_info,
GVariant *xattrs, GVariant *xattrs,
GInputStream *input, GInputStream *input,
@ -110,40 +110,54 @@ write_regular_file_content (OstreeRepo *self,
GError **error) GError **error)
{ {
const OstreeRepoCheckoutMode mode = options->mode; const OstreeRepoCheckoutMode mode = options->mode;
g_autoptr(GOutputStream) outstream = NULL;
if (g_output_stream_splice (output, input, 0, if (G_IS_FILE_DESCRIPTOR_BASED (input))
cancellable, error) < 0) {
return FALSE; int infd = g_file_descriptor_based_get_fd ((GFileDescriptorBased*) input);
guint64 len = g_file_info_get_size (file_info);
if (!g_output_stream_flush (output, cancellable, error)) if (glnx_regfile_copy_bytes (infd, outfd, (off_t)len, TRUE) < 0)
return FALSE; return glnx_throw_errno_prefix (error, "regfile copy");
}
else
{
outstream = g_unix_output_stream_new (outfd, FALSE);
if (g_output_stream_splice (outstream, input, 0,
cancellable, error) < 0)
return FALSE;
int fd = g_file_descriptor_based_get_fd ((GFileDescriptorBased*)output); if (!g_output_stream_flush (outstream, cancellable, error))
return FALSE;
}
if (mode != OSTREE_REPO_CHECKOUT_MODE_USER) if (mode != OSTREE_REPO_CHECKOUT_MODE_USER)
{ {
if (TEMP_FAILURE_RETRY (fchown (fd, g_file_info_get_attribute_uint32 (file_info, "unix::uid"), if (TEMP_FAILURE_RETRY (fchown (outfd, g_file_info_get_attribute_uint32 (file_info, "unix::uid"),
g_file_info_get_attribute_uint32 (file_info, "unix::gid"))) < 0) g_file_info_get_attribute_uint32 (file_info, "unix::gid"))) < 0)
return glnx_throw_errno (error); return glnx_throw_errno (error);
if (TEMP_FAILURE_RETRY (fchmod (fd, g_file_info_get_attribute_uint32 (file_info, "unix::mode"))) < 0) if (TEMP_FAILURE_RETRY (fchmod (outfd, g_file_info_get_attribute_uint32 (file_info, "unix::mode"))) < 0)
return glnx_throw_errno (error); return glnx_throw_errno (error);
if (xattrs) if (xattrs)
{ {
if (!glnx_fd_set_all_xattrs (fd, xattrs, cancellable, error)) if (!glnx_fd_set_all_xattrs (outfd, xattrs, cancellable, error))
return FALSE; return FALSE;
} }
} }
if (fsync_is_enabled (self, options)) if (fsync_is_enabled (self, options))
{ {
if (fsync (fd) == -1) if (fsync (outfd) == -1)
return glnx_throw_errno (error); return glnx_throw_errno (error);
} }
if (!g_output_stream_close (output, cancellable, error)) if (outstream)
return FALSE; {
if (!g_output_stream_close (outstream, cancellable, error))
return FALSE;
}
return TRUE; return TRUE;
} }
@ -231,7 +245,6 @@ create_file_copy_from_input_at (OstreeRepo *repo,
else if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR) else if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR)
{ {
glnx_fd_close int temp_fd = -1; glnx_fd_close int temp_fd = -1;
g_autoptr(GOutputStream) temp_out = NULL;
guint32 file_mode; guint32 file_mode;
GLnxLinkTmpfileReplaceMode replace_mode; GLnxLinkTmpfileReplaceMode replace_mode;
@ -244,7 +257,6 @@ create_file_copy_from_input_at (OstreeRepo *repo,
&temp_fd, &temp_filename, &temp_fd, &temp_filename,
error)) error))
return FALSE; return FALSE;
temp_out = g_unix_output_stream_new (temp_fd, FALSE);
if (sepolicy_enabled) if (sepolicy_enabled)
{ {
@ -258,7 +270,7 @@ create_file_copy_from_input_at (OstreeRepo *repo,
return glnx_throw_errno_prefix (error, "Setting security.selinux"); return glnx_throw_errno_prefix (error, "Setting security.selinux");
} }
if (!write_regular_file_content (repo, options, temp_out, file_info, xattrs, input, if (!write_regular_file_content (repo, options, temp_fd, file_info, xattrs, input,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;

View File

@ -458,29 +458,19 @@ add_size_index_to_metadata (OstreeRepo *self,
} }
static gboolean static gboolean
fallocate_stream (GFileDescriptorBased *stream, ot_fallocate (int fd, goffset size, GError **error)
goffset size,
GCancellable *cancellable,
GError **error)
{ {
gboolean ret = FALSE; if (size == 0)
int fd = g_file_descriptor_based_get_fd (stream); return TRUE;
if (size > 0) int r = posix_fallocate (fd, 0, size);
if (r != 0)
{ {
int r = posix_fallocate (fd, 0, size); /* posix_fallocate is a weird deviation from errno standards */
if (r != 0) errno = r;
{ return glnx_throw_errno_prefix (error, "fallocate");
/* posix_fallocate is a weird deviation from errno standards */
errno = r;
glnx_set_error_from_errno (error);
goto out;
}
} }
return TRUE;
ret = TRUE;
out:
return ret;
} }
gboolean gboolean
@ -510,11 +500,10 @@ _ostree_repo_open_content_bare (OstreeRepo *self,
&fd, &temp_filename, error)) &fd, &temp_filename, error))
goto out; goto out;
ret_stream = g_unix_output_stream_new (fd, TRUE); if (!ot_fallocate (fd, content_len, error))
if (!fallocate_stream ((GFileDescriptorBased*)ret_stream, content_len,
cancellable, error))
goto out; goto out;
ret_stream = g_unix_output_stream_new (fd, TRUE);
} }
ret = TRUE; ret = TRUE;
@ -569,7 +558,6 @@ create_regular_tmpfile_linkable_with_content (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
g_autoptr(GOutputStream) temp_out = NULL;
glnx_fd_close int temp_fd = -1; glnx_fd_close int temp_fd = -1;
g_autofree char *temp_filename = NULL; g_autofree char *temp_filename = NULL;
@ -577,20 +565,27 @@ create_regular_tmpfile_linkable_with_content (OstreeRepo *self,
&temp_fd, &temp_filename, &temp_fd, &temp_filename,
error)) error))
return FALSE; return FALSE;
temp_out = g_unix_output_stream_new (temp_fd, FALSE);
if (!fallocate_stream ((GFileDescriptorBased*)temp_out, length, if (!ot_fallocate (temp_fd, length, error))
cancellable, error))
return FALSE; return FALSE;
if (g_output_stream_splice (temp_out, input, 0, if (G_IS_FILE_DESCRIPTOR_BASED (input))
cancellable, error) < 0)
return FALSE;
if (fchmod (temp_fd, 0644) < 0)
{ {
glnx_set_error_from_errno (error); int infd = g_file_descriptor_based_get_fd ((GFileDescriptorBased*) input);
return FALSE; if (glnx_regfile_copy_bytes (infd, temp_fd, (off_t)length, TRUE) < 0)
return glnx_throw_errno_prefix (error, "regfile copy");
} }
else
{
g_autoptr(GOutputStream) temp_out = g_unix_output_stream_new (temp_fd, FALSE);
if (g_output_stream_splice (temp_out, input, 0,
cancellable, error) < 0)
return FALSE;
}
if (fchmod (temp_fd, 0644) < 0)
return glnx_throw_errno_prefix (error, "fchmod");
*out_fd = temp_fd; temp_fd = -1; *out_fd = temp_fd; temp_fd = -1;
*out_path = g_steal_pointer (&temp_filename); *out_path = g_steal_pointer (&temp_filename);
return TRUE; return TRUE;

View File

@ -40,6 +40,7 @@ git log --pretty=oneline origin/master.. | while read logline; do
echo "Commit $commit modifies submodule: $submodule" echo "Commit $commit modifies submodule: $submodule"
expected_match="Update submodule: $submodule" expected_match="Update submodule: $submodule"
if ! grep -q -e "$expected_match" ${tmpd}/log.txt; then if ! grep -q -e "$expected_match" ${tmpd}/log.txt; then
sed -e 's,^,# ,' < ${tmpd}/log.txt
echo "error: Commit message for ${commit} changes a submodule, but does not match regex ${expected_match}" echo "error: Commit message for ${commit} changes a submodule, but does not match regex ${expected_match}"
exit 1 exit 1
fi fi