Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Implement parallel importing #1124

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions src/daemon/rpmostreed-transaction-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ deploy_transaction_finalize (GObject *object)

static gboolean
import_local_rpm (OstreeRepo *repo,
int fd,
int *fd,
char **sha256_nevra,
GCancellable *cancellable,
GError **error)
Expand All @@ -482,12 +482,11 @@ import_local_rpm (OstreeRepo *repo,
if (policy == NULL)
return FALSE;

g_autoptr(RpmOstreeImporter) unpacker = rpmostree_importer_new_fd (fd, NULL, 0, error);
g_autoptr(RpmOstreeImporter) unpacker = rpmostree_importer_new_take_fd (fd, repo, NULL, 0, policy, error);
if (unpacker == NULL)
return FALSE;

if (!rpmostree_importer_run (unpacker, repo, policy,
NULL, cancellable, error))
if (!rpmostree_importer_run (unpacker, NULL, cancellable, error))
return FALSE;

g_autofree char *nevra = rpmostree_importer_get_nevra (unpacker);
Expand All @@ -497,6 +496,25 @@ import_local_rpm (OstreeRepo *repo,
return TRUE;
}

static void
ptr_close_fd (gpointer fdp)
{
int fd = GPOINTER_TO_INT (fdp);
glnx_close_fd (&fd);
}

/* GUnixFDList doesn't allow stealing individual members */
static GPtrArray *
unixfdlist_to_ptrarray (GUnixFDList *fdl)
{
gint len;
gint *fds = g_unix_fd_list_steal_fds (fdl, &len);
GPtrArray *ret = g_ptr_array_new_with_free_func ((GDestroyNotify)ptr_close_fd);
for (int i = 0; i < len; i++)
g_ptr_array_add (ret, GINT_TO_POINTER (fds[i]));
return ret;
}

static gboolean
import_many_local_rpms (OstreeRepo *repo,
GUnixFDList *fdl,
Expand All @@ -516,12 +534,15 @@ import_many_local_rpms (OstreeRepo *repo,

g_autoptr(GPtrArray) pkgs = g_ptr_array_new_with_free_func (g_free);

gint nfds = 0;
const gint *fds = g_unix_fd_list_peek_fds (fdl, &nfds);
for (guint i = 0; i < nfds; i++)
g_autoptr(GPtrArray) fds = unixfdlist_to_ptrarray (fdl);
for (guint i = 0; i < fds->len; i++)
{
/* Steal fd from the ptrarray */
glnx_autofd int fd = GPOINTER_TO_INT (fds->pdata[i]);
fds->pdata[i] = GINT_TO_POINTER (-1);
g_autofree char *sha256_nevra = NULL;
if (!import_local_rpm (repo, fds[i], &sha256_nevra, cancellable, error))
/* Transfer fd to import */
if (!import_local_rpm (repo, &fd, &sha256_nevra, cancellable, error))
return FALSE;

g_ptr_array_add (pkgs, g_steal_pointer (&sha256_nevra));
Expand Down
139 changes: 81 additions & 58 deletions src/libpriv/rpmostree-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,12 @@ struct _RpmOstreeContext {
OstreeSePolicy *sepolicy;
char *passwd_dir;

gboolean async_running;
GError *async_error;
DnfState *async_dnfstate;
GPtrArray *pkgs_to_download;
GPtrArray *pkgs_to_import;
guint n_async_pkgs_imported;
GPtrArray *pkgs_to_relabel;

GHashTable *pkgs_to_remove; /* pkgname --> gv_nevra */
Expand Down Expand Up @@ -1374,6 +1378,7 @@ sort_packages (RpmOstreeContext *self,
self->pkgs_to_download = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
g_assert (!self->pkgs_to_import);
self->pkgs_to_import = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
self->n_async_pkgs_imported = 0;
g_assert (!self->pkgs_to_relabel);
self->pkgs_to_relabel = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);

Expand Down Expand Up @@ -1821,6 +1826,7 @@ rpmostree_context_set_packages (RpmOstreeContext *self,
{
g_clear_pointer (&self->pkgs_to_download, (GDestroyNotify)g_ptr_array_unref);
g_clear_pointer (&self->pkgs_to_import, (GDestroyNotify)g_ptr_array_unref);
self->n_async_pkgs_imported = 0;
g_clear_pointer (&self->pkgs_to_relabel, (GDestroyNotify)g_ptr_array_unref);
return sort_packages (self, packages, cancellable, error);
}
Expand Down Expand Up @@ -2023,64 +2029,35 @@ rpmostree_context_download (RpmOstreeContext *self,
return TRUE;
}

static gboolean
import_one_package (RpmOstreeContext *self,
DnfContext *dnfctx,
DnfPackage *pkg,
OstreeSePolicy *sepolicy,
GVariant *jigdo_xattr_table,
GVariant *jigdo_xattrs,
GCancellable *cancellable,
GError **error)
static inline void
dnf_state_assert_done (DnfState *dnfstate)
{
glnx_fd_close int fd = -1;
if (!rpmostree_context_consume_package (self, pkg, &fd, error))
return FALSE;

/* Only set SKIP_EXTRANEOUS for packages we know need it, so that
* people doing custom composes don't have files silently discarded.
* (This will also likely need to be configurable).
*/
const char *pkg_name = dnf_package_get_name (pkg);

int flags = 0;
if (g_str_equal (pkg_name, "filesystem") ||
g_str_equal (pkg_name, "rootfiles"))
flags |= RPMOSTREE_IMPORTER_FLAGS_SKIP_EXTRANEOUS;

{ gboolean docs;
g_assert (g_variant_dict_lookup (self->spec->dict, "documentation", "b", &docs));
if (!docs)
flags |= RPMOSTREE_IMPORTER_FLAGS_NODOCS;
}

/* TODO - tweak the unpacker flags for containers */
g_autoptr(RpmOstreeImporter) unpacker = rpmostree_importer_new_fd (fd, pkg, flags, error);
if (!unpacker)
return FALSE;

if (jigdo_xattrs)
{
g_assert (!sepolicy);
rpmostree_importer_set_jigdo_mode (unpacker, jigdo_xattr_table, jigdo_xattrs);
}

OstreeRepo *ostreerepo = get_pkgcache_repo (self);
g_autofree char *ostree_commit = NULL;
if (!rpmostree_importer_run (unpacker, ostreerepo, sepolicy,
&ostree_commit, cancellable, error))
return glnx_prefix_error (error, "Unpacking %s",
dnf_package_get_nevra (pkg));

return TRUE;
g_assert (dnf_state_done (dnfstate, NULL));
}

static inline void
dnf_state_assert_done (DnfState *hifstate)
static void
on_async_import_done (GObject *obj,
GAsyncResult *res,
gpointer user_data)
{
gboolean r;
r = dnf_state_done (hifstate, NULL);
g_assert (r);
RpmOstreeImporter *importer = (RpmOstreeImporter*) obj;
RpmOstreeContext *self = user_data;
g_autofree char *rev =
rpmostree_importer_run_async_finish (importer, res,
self->async_error ? NULL : &self->async_error);
if (!rev)
{
self->async_running = FALSE;
g_assert (self->async_error != NULL);
}
else
{
g_assert_cmpint (self->n_async_pkgs_imported, <, self->pkgs_to_import->len);
self->n_async_pkgs_imported++;
dnf_state_assert_done (self->async_dnfstate);
if (self->n_async_pkgs_imported == self->pkgs_to_import->len)
self->async_running = FALSE;
}
}

gboolean
Expand Down Expand Up @@ -2114,6 +2091,9 @@ rpmostree_context_import_jigdo (RpmOstreeContext *self,
G_CALLBACK (on_hifstate_percentage_changed),
"Importing:");

self->async_dnfstate = hifstate;
self->async_running = TRUE;

for (guint i = 0; i < self->pkgs_to_import->len; i++)
{
DnfPackage *pkg = self->pkgs_to_import->pdata[i];
Expand All @@ -2124,11 +2104,54 @@ rpmostree_context_import_jigdo (RpmOstreeContext *self,
if (!jigdo_xattrs)
g_error ("Failed to find jigdo xattrs for %s", dnf_package_get_nevra (pkg));
}
if (!import_one_package (self, dnfctx, pkg, self->sepolicy,
jigdo_xattr_table, jigdo_xattrs,
cancellable, error))

glnx_fd_close int fd = -1;
if (!rpmostree_context_consume_package (self, pkg, &fd, error))
return FALSE;

/* Only set SKIP_EXTRANEOUS for packages we know need it, so that
* people doing custom composes don't have files silently discarded.
* (This will also likely need to be configurable).
*/
const char *pkg_name = dnf_package_get_name (pkg);

int flags = 0;
if (g_str_equal (pkg_name, "filesystem") ||
g_str_equal (pkg_name, "rootfiles"))
flags |= RPMOSTREE_IMPORTER_FLAGS_SKIP_EXTRANEOUS;

{ gboolean docs;
g_assert (g_variant_dict_lookup (self->spec->dict, "documentation", "b", &docs));
if (!docs)
flags |= RPMOSTREE_IMPORTER_FLAGS_NODOCS;
}

/* TODO - tweak the unpacker flags for containers */
OstreeRepo *ostreerepo = get_pkgcache_repo (self);
g_autoptr(RpmOstreeImporter) unpacker =
rpmostree_importer_new_take_fd (&fd, ostreerepo, pkg, flags,
self->sepolicy, error);
if (!unpacker)
return FALSE;
dnf_state_assert_done (hifstate);

if (jigdo_xattrs)
{
g_assert (!self->sepolicy);
rpmostree_importer_set_jigdo_mode (unpacker, jigdo_xattr_table, jigdo_xattrs);
}

rpmostree_importer_run_async (unpacker, cancellable, on_async_import_done, self);
}

/* Wait for all of the imports to complete */
GMainContext *mainctx = g_main_context_get_thread_default ();
self->async_error = NULL;
while (self->async_running)
g_main_context_iteration (mainctx, TRUE);
if (self->async_error)
{
g_propagate_error (error, g_steal_pointer (&self->async_error));
return FALSE;
}

g_signal_handler_disconnect (hifstate, progress_sigid);
Expand Down
Loading