lib/deploy: Split /etc merge into two stages
For staged deploy, we want to pay the cost of creating copies from `/usr/etc` → `/etc` at stage time, since it can be expensive. (We want to minimize time spent during shutdown). Split it up into two functions; the logic is also simply clearer. Closes: #1514 Approved by: jlebon
This commit is contained in:
parent
460fb7aebc
commit
7ec3d06014
|
|
@ -390,7 +390,6 @@ copy_modified_config_file (int orig_etc_fd,
|
||||||
* merge_configuration_from:
|
* merge_configuration_from:
|
||||||
* @sysroot: Sysroot
|
* @sysroot: Sysroot
|
||||||
* @merge_deployment: Source of configuration differences
|
* @merge_deployment: Source of configuration differences
|
||||||
* @merge_deployment_dfd: Directory fd, may be -1
|
|
||||||
* @new_deployment: Target for merge of configuration
|
* @new_deployment: Target for merge of configuration
|
||||||
* @new_deployment_dfd: Directory fd for @new_deployment (may *not* be -1)
|
* @new_deployment_dfd: Directory fd for @new_deployment (may *not* be -1)
|
||||||
* @cancellable: Cancellable
|
* @cancellable: Cancellable
|
||||||
|
|
@ -407,27 +406,22 @@ copy_modified_config_file (int orig_etc_fd,
|
||||||
static gboolean
|
static gboolean
|
||||||
merge_configuration_from (OstreeSysroot *sysroot,
|
merge_configuration_from (OstreeSysroot *sysroot,
|
||||||
OstreeDeployment *merge_deployment,
|
OstreeDeployment *merge_deployment,
|
||||||
int merge_deployment_dfd,
|
|
||||||
OstreeDeployment *new_deployment,
|
OstreeDeployment *new_deployment,
|
||||||
int new_deployment_dfd,
|
int new_deployment_dfd,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
glnx_autofd int owned_merge_deployment_dfd = -1;
|
GLNX_AUTO_PREFIX_ERROR ("During /etc merge", error);
|
||||||
const OstreeSysrootDebugFlags flags = sysroot->debug_flags;
|
const OstreeSysrootDebugFlags flags = sysroot->debug_flags;
|
||||||
|
|
||||||
g_assert (merge_deployment != NULL && new_deployment != NULL);
|
g_assert (merge_deployment != NULL && new_deployment != NULL);
|
||||||
g_assert (new_deployment_dfd != -1);
|
g_assert (new_deployment_dfd != -1);
|
||||||
|
|
||||||
/* Allow the caller to pass -1 for the merge, for convenience */
|
g_autofree char *merge_deployment_path = ostree_sysroot_get_deployment_dirpath (sysroot, merge_deployment);
|
||||||
if (merge_deployment_dfd == -1)
|
glnx_autofd int merge_deployment_dfd = -1;
|
||||||
{
|
if (!glnx_opendirat (sysroot->sysroot_fd, merge_deployment_path, FALSE,
|
||||||
g_autofree char *merge_deployment_path = ostree_sysroot_get_deployment_dirpath (sysroot, merge_deployment);
|
&merge_deployment_dfd, error))
|
||||||
if (!glnx_opendirat (sysroot->sysroot_fd, merge_deployment_path, FALSE,
|
return FALSE;
|
||||||
&owned_merge_deployment_dfd, error))
|
|
||||||
return FALSE;
|
|
||||||
merge_deployment_dfd = owned_merge_deployment_dfd;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TODO: get rid of GFile usage here */
|
/* TODO: get rid of GFile usage here */
|
||||||
g_autoptr(GFile) orig_etc = ot_fdrel_to_gfile (merge_deployment_dfd, "usr/etc");
|
g_autoptr(GFile) orig_etc = ot_fdrel_to_gfile (merge_deployment_dfd, "usr/etc");
|
||||||
|
|
@ -741,22 +735,19 @@ selinux_relabel_var_if_needed (OstreeSysroot *sysroot,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* OSTree implements a "3 way" merge model for /etc. For a bit more information
|
/* Handle initial creation of /etc in the deployment. See also
|
||||||
* on this, see the manual. This function uses the configuration for
|
* merge_configuration_from().
|
||||||
* @previous_deployment, and writes the merged configuration into @deployment's
|
|
||||||
* /etc. If available, we also load the SELinux policy from the new root.
|
|
||||||
*/
|
*/
|
||||||
static gboolean
|
static gboolean
|
||||||
merge_configuration (OstreeSysroot *sysroot,
|
prepare_deployment_etc (OstreeSysroot *sysroot,
|
||||||
OstreeRepo *repo,
|
OstreeRepo *repo,
|
||||||
OstreeDeployment *previous_deployment,
|
OstreeDeployment *deployment,
|
||||||
OstreeDeployment *deployment,
|
int deployment_dfd,
|
||||||
int deployment_dfd,
|
OstreeSePolicy **out_sepolicy,
|
||||||
OstreeSePolicy **out_sepolicy,
|
GCancellable *cancellable,
|
||||||
GCancellable *cancellable,
|
GError **error)
|
||||||
GError **error)
|
|
||||||
{
|
{
|
||||||
GLNX_AUTO_PREFIX_ERROR ("During /etc merge", error);
|
GLNX_AUTO_PREFIX_ERROR ("Preparing /etc", error);
|
||||||
g_autoptr(OstreeSePolicy) sepolicy = NULL;
|
g_autoptr(OstreeSePolicy) sepolicy = NULL;
|
||||||
|
|
||||||
struct stat stbuf;
|
struct stat stbuf;
|
||||||
|
|
@ -805,14 +796,6 @@ merge_configuration (OstreeSysroot *sysroot,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previous_deployment)
|
|
||||||
{
|
|
||||||
if (!merge_configuration_from (sysroot, previous_deployment, -1,
|
|
||||||
deployment, deployment_dfd,
|
|
||||||
cancellable, error))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (out_sepolicy)
|
if (out_sepolicy)
|
||||||
*out_sepolicy = g_steal_pointer (&sepolicy);
|
*out_sepolicy = g_steal_pointer (&sepolicy);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
@ -2444,12 +2427,18 @@ ostree_sysroot_deploy_tree (OstreeSysroot *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
g_autoptr(OstreeSePolicy) sepolicy = NULL;
|
g_autoptr(OstreeSePolicy) sepolicy = NULL;
|
||||||
if (!merge_configuration (self, repo, merge_deployment, new_deployment,
|
if (!prepare_deployment_etc (self, repo, new_deployment, deployment_dfd,
|
||||||
deployment_dfd,
|
&sepolicy, cancellable, error))
|
||||||
&sepolicy,
|
|
||||||
cancellable, error))
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
if (merge_deployment)
|
||||||
|
{
|
||||||
|
if (!merge_configuration_from (self, merge_deployment,
|
||||||
|
new_deployment, deployment_dfd,
|
||||||
|
cancellable, error))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!selinux_relabel_var_if_needed (self, sepolicy, os_deploy_dfd,
|
if (!selinux_relabel_var_if_needed (self, sepolicy, os_deploy_dfd,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue