sysroot: Also maintain canonical boot_fd
Just like we hold a fd for `/sysroot`, also do so for `/boot` instead of opening and closing it in a few places. This is a preparatory cleanup for further work.
This commit is contained in:
parent
10556a95b4
commit
a1c0cffeb3
|
|
@ -1582,11 +1582,11 @@ full_system_sync (OstreeSysroot *self,
|
||||||
|
|
||||||
out_stats->root_syncfs_msec = (end_msec - start_msec);
|
out_stats->root_syncfs_msec = (end_msec - start_msec);
|
||||||
|
|
||||||
start_msec = g_get_monotonic_time () / 1000;
|
if (!_ostree_sysroot_ensure_boot_fd (self, error))
|
||||||
glnx_autofd int boot_dfd = -1;
|
|
||||||
if (!glnx_opendirat (self->sysroot_fd, "boot", TRUE, &boot_dfd, error))
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!fsfreeze_thaw_cycle (self, boot_dfd, cancellable, error))
|
|
||||||
|
start_msec = g_get_monotonic_time () / 1000;
|
||||||
|
if (!fsfreeze_thaw_cycle (self, self->boot_fd, cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
end_msec = g_get_monotonic_time () / 1000;
|
end_msec = g_get_monotonic_time () / 1000;
|
||||||
out_stats->boot_syncfs_msec = (end_msec - start_msec);
|
out_stats->boot_syncfs_msec = (end_msec - start_msec);
|
||||||
|
|
@ -1770,8 +1770,7 @@ install_deployment_kernel (OstreeSysroot *sysroot,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
glnx_autofd int boot_dfd = -1;
|
if (!_ostree_sysroot_ensure_boot_fd (sysroot, error))
|
||||||
if (!glnx_opendirat (sysroot->sysroot_fd, "boot", TRUE, &boot_dfd, error))
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
const char *osname = ostree_deployment_get_osname (deployment);
|
const char *osname = ostree_deployment_get_osname (deployment);
|
||||||
|
|
@ -1781,14 +1780,14 @@ install_deployment_kernel (OstreeSysroot *sysroot,
|
||||||
g_autofree char *bootconf_name = g_strdup_printf ("ostree-%d-%s.conf",
|
g_autofree char *bootconf_name = g_strdup_printf ("ostree-%d-%s.conf",
|
||||||
n_deployments - ostree_deployment_get_index (deployment),
|
n_deployments - ostree_deployment_get_index (deployment),
|
||||||
osname);
|
osname);
|
||||||
if (!glnx_shutil_mkdir_p_at (boot_dfd, bootcsumdir, 0775, cancellable, error))
|
if (!glnx_shutil_mkdir_p_at (sysroot->boot_fd, bootcsumdir, 0775, cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
glnx_autofd int bootcsum_dfd = -1;
|
glnx_autofd int bootcsum_dfd = -1;
|
||||||
if (!glnx_opendirat (boot_dfd, bootcsumdir, TRUE, &bootcsum_dfd, error))
|
if (!glnx_opendirat (sysroot->boot_fd, bootcsumdir, TRUE, &bootcsum_dfd, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!glnx_shutil_mkdir_p_at (boot_dfd, bootconfdir, 0775, cancellable, error))
|
if (!glnx_shutil_mkdir_p_at (sysroot->boot_fd, bootconfdir, 0775, cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Install (hardlink/copy) the kernel into /boot/ostree/osname-${bootcsum} if
|
/* Install (hardlink/copy) the kernel into /boot/ostree/osname-${bootcsum} if
|
||||||
|
|
@ -1879,18 +1878,18 @@ install_deployment_kernel (OstreeSysroot *sysroot,
|
||||||
{
|
{
|
||||||
overlay_initrds = g_ptr_array_new_with_free_func (g_free);
|
overlay_initrds = g_ptr_array_new_with_free_func (g_free);
|
||||||
|
|
||||||
if (!glnx_shutil_mkdir_p_at (boot_dfd, _OSTREE_SYSROOT_BOOT_INITRAMFS_OVERLAYS,
|
if (!glnx_shutil_mkdir_p_at (sysroot->boot_fd, _OSTREE_SYSROOT_BOOT_INITRAMFS_OVERLAYS,
|
||||||
0755, cancellable, error))
|
0755, cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!glnx_fstatat_allow_noent (boot_dfd, rel_destpath, NULL, 0, error))
|
if (!glnx_fstatat_allow_noent (sysroot->boot_fd, rel_destpath, NULL, 0, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
{
|
{
|
||||||
g_autofree char *srcpath =
|
g_autofree char *srcpath =
|
||||||
g_strdup_printf (_OSTREE_SYSROOT_RUNSTATE_STAGED_INITRDS_DIR "/%s", checksum);
|
g_strdup_printf (_OSTREE_SYSROOT_RUNSTATE_STAGED_INITRDS_DIR "/%s", checksum);
|
||||||
if (!install_into_boot (repo, sepolicy, AT_FDCWD, srcpath, boot_dfd, rel_destpath,
|
if (!install_into_boot (repo, sepolicy, AT_FDCWD, srcpath, sysroot->boot_fd, rel_destpath,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
@ -2019,7 +2018,7 @@ install_deployment_kernel (OstreeSysroot *sysroot,
|
||||||
ostree_bootconfig_parser_set (bootconfig, "options", options_key);
|
ostree_bootconfig_parser_set (bootconfig, "options", options_key);
|
||||||
|
|
||||||
glnx_autofd int bootconf_dfd = -1;
|
glnx_autofd int bootconf_dfd = -1;
|
||||||
if (!glnx_opendirat (boot_dfd, bootconfdir, TRUE, &bootconf_dfd, error))
|
if (!glnx_opendirat (sysroot->boot_fd, bootconfdir, TRUE, &bootconf_dfd, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!ostree_bootconfig_parser_write_at (ostree_deployment_get_bootconfig (deployment),
|
if (!ostree_bootconfig_parser_write_at (ostree_deployment_get_bootconfig (deployment),
|
||||||
|
|
@ -2076,15 +2075,14 @@ swap_bootloader (OstreeSysroot *sysroot,
|
||||||
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));
|
||||||
|
|
||||||
glnx_autofd int boot_dfd = -1;
|
if (!_ostree_sysroot_ensure_boot_fd (sysroot, error))
|
||||||
if (!glnx_opendirat (sysroot->sysroot_fd, "boot", TRUE, &boot_dfd, error))
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* The symlink was already written, and we used syncfs() to ensure
|
/* The symlink was already written, and we used syncfs() to ensure
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
if (!glnx_renameat (boot_dfd, "loader.tmp", boot_dfd, "loader", error))
|
if (!glnx_renameat (sysroot->boot_fd, "loader.tmp", sysroot->boot_fd, "loader", error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Now we explicitly fsync this directory, even though it
|
/* Now we explicitly fsync this directory, even though it
|
||||||
|
|
@ -2096,7 +2094,7 @@ swap_bootloader (OstreeSysroot *sysroot,
|
||||||
* for whatever reason, and we wouldn't want to confuse the
|
* for whatever reason, and we wouldn't want to confuse the
|
||||||
* admin by going back to the previous session.
|
* admin by going back to the previous session.
|
||||||
*/
|
*/
|
||||||
if (fsync (boot_dfd) != 0)
|
if (fsync (sysroot->boot_fd) != 0)
|
||||||
return glnx_throw_errno_prefix (error, "fsync(boot)");
|
return glnx_throw_errno_prefix (error, "fsync(boot)");
|
||||||
|
|
||||||
/* TODO: In the future also execute this automatically via a systemd unit
|
/* TODO: In the future also execute this automatically via a systemd unit
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ struct OstreeSysroot {
|
||||||
|
|
||||||
GFile *path;
|
GFile *path;
|
||||||
int sysroot_fd;
|
int sysroot_fd;
|
||||||
|
int boot_fd;
|
||||||
GLnxLockFile lock;
|
GLnxLockFile lock;
|
||||||
|
|
||||||
OstreeSysrootLoadState loadstate;
|
OstreeSysrootLoadState loadstate;
|
||||||
|
|
@ -160,6 +161,9 @@ char * _ostree_sysroot_get_runstate_path (OstreeDeployment *deployment, const ch
|
||||||
|
|
||||||
char *_ostree_sysroot_join_lines (GPtrArray *lines);
|
char *_ostree_sysroot_join_lines (GPtrArray *lines);
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
_ostree_sysroot_ensure_boot_fd (OstreeSysroot *self, GError **error);
|
||||||
|
|
||||||
gboolean _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot,
|
gboolean _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot,
|
||||||
OstreeBootloader **out_bootloader,
|
OstreeBootloader **out_bootloader,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
|
||||||
|
|
@ -198,6 +198,7 @@ ostree_sysroot_init (OstreeSysroot *self)
|
||||||
keys, G_N_ELEMENTS (keys));
|
keys, G_N_ELEMENTS (keys));
|
||||||
|
|
||||||
self->sysroot_fd = -1;
|
self->sysroot_fd = -1;
|
||||||
|
self->boot_fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -278,6 +279,19 @@ ensure_sysroot_fd (OstreeSysroot *self,
|
||||||
&self->sysroot_fd, error))
|
&self->sysroot_fd, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
_ostree_sysroot_ensure_boot_fd (OstreeSysroot *self, GError **error)
|
||||||
|
{
|
||||||
|
if (self->boot_fd == -1)
|
||||||
|
{
|
||||||
|
if (!glnx_opendirat (self->sysroot_fd, "boot", TRUE,
|
||||||
|
&self->boot_fd, error))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -380,6 +394,7 @@ void
|
||||||
ostree_sysroot_unload (OstreeSysroot *self)
|
ostree_sysroot_unload (OstreeSysroot *self)
|
||||||
{
|
{
|
||||||
glnx_close_fd (&self->sysroot_fd);
|
glnx_close_fd (&self->sysroot_fd);
|
||||||
|
glnx_close_fd (&self->boot_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue