lib: Add ostree_sysroot_init_osname() API, bump mtime
And change the command line to use it. rpm-ostree had a copy of this code, and thus there's a clear reason to have an API. While we're moving this into API, ensure the mtime on deploy is bumped after an osname is created, so that daemons like rpm-ostree can notice changes. (In reality, creating the directory should do this, but let's be double sure)
This commit is contained in:
parent
7ace5d35bd
commit
fbd9409ebb
|
|
@ -397,6 +397,7 @@ ostree_sysroot_get_deployment_origin_path
|
||||||
ostree_sysroot_cleanup
|
ostree_sysroot_cleanup
|
||||||
ostree_sysroot_prepare_cleanup
|
ostree_sysroot_prepare_cleanup
|
||||||
ostree_sysroot_get_repo
|
ostree_sysroot_get_repo
|
||||||
|
ostree_sysroot_init_osname
|
||||||
ostree_sysroot_deployment_set_kargs
|
ostree_sysroot_deployment_set_kargs
|
||||||
ostree_sysroot_write_deployments
|
ostree_sysroot_write_deployments
|
||||||
ostree_sysroot_deploy_tree
|
ostree_sysroot_deploy_tree
|
||||||
|
|
|
||||||
|
|
@ -316,4 +316,5 @@ LIBOSTREE_2016.4 {
|
||||||
global:
|
global:
|
||||||
ostree_repo_get_dfd;
|
ostree_repo_get_dfd;
|
||||||
ostree_repo_list_refs_ext;
|
ostree_repo_list_refs_ext;
|
||||||
|
ostree_sysroot_init_osname;
|
||||||
} LIBOSTREE_2016.3;
|
} LIBOSTREE_2016.3;
|
||||||
|
|
|
||||||
|
|
@ -1855,12 +1855,8 @@ ostree_sysroot_write_deployments (OstreeSysroot *self,
|
||||||
requires_new_bootversion ? "yes" : "no",
|
requires_new_bootversion ? "yes" : "no",
|
||||||
new_deployments->len - self->deployments->len);
|
new_deployments->len - self->deployments->len);
|
||||||
|
|
||||||
/* Allow other systems to monitor for changes */
|
if (!_ostree_sysroot_bump_mtime (self, error))
|
||||||
if (utimensat (self->sysroot_fd, "ostree/deploy", NULL, 0) < 0)
|
|
||||||
{
|
|
||||||
glnx_set_prefix_error_from_errno (error, "%s", "futimens");
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
|
||||||
|
|
||||||
/* Now reload from disk */
|
/* Now reload from disk */
|
||||||
if (!ostree_sysroot_load (self, cancellable, error))
|
if (!ostree_sysroot_load (self, cancellable, error))
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,9 @@ gboolean _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
gboolean _ostree_sysroot_bump_mtime (OstreeSysroot *sysroot,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
OSTREE_SYSROOT_CLEANUP_BOOTVERSIONS = 1 << 0,
|
OSTREE_SYSROOT_CLEANUP_BOOTVERSIONS = 1 << 0,
|
||||||
OSTREE_SYSROOT_CLEANUP_DEPLOYMENTS = 1 << 1,
|
OSTREE_SYSROOT_CLEANUP_DEPLOYMENTS = 1 << 1,
|
||||||
|
|
|
||||||
|
|
@ -229,6 +229,19 @@ ostree_sysroot_get_fd (OstreeSysroot *self)
|
||||||
return self->sysroot_fd;
|
return self->sysroot_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
_ostree_sysroot_bump_mtime (OstreeSysroot *self,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
/* Allow other systems to monitor for changes */
|
||||||
|
if (utimensat (self->sysroot_fd, "ostree/deploy", NULL, 0) < 0)
|
||||||
|
{
|
||||||
|
glnx_set_prefix_error_from_errno (error, "%s", "futimens");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ostree_sysroot_unload:
|
* ostree_sysroot_unload:
|
||||||
* @self: Sysroot
|
* @self: Sysroot
|
||||||
|
|
@ -1337,6 +1350,86 @@ ostree_sysroot_lock_finish (OstreeSysroot *self,
|
||||||
return g_task_propagate_boolean ((GTask*)result, error);
|
return g_task_propagate_boolean ((GTask*)result, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ostree_sysroot_init_osname:
|
||||||
|
* @self: Sysroot
|
||||||
|
* @osname: Name group of operating system checkouts
|
||||||
|
* @cancellable: Cancellable
|
||||||
|
* @error: Error
|
||||||
|
*
|
||||||
|
* Initialize the directory structure for an "osname", which is a
|
||||||
|
* group of operating system deployments, with a shared `/var`. One
|
||||||
|
* is required for generating a deployment.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
ostree_sysroot_init_osname (OstreeSysroot *self,
|
||||||
|
const char *osname,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
const char *deploydir = glnx_strjoina ("ostree/deploy/", osname);
|
||||||
|
glnx_fd_close int dfd = -1;
|
||||||
|
|
||||||
|
if (!ensure_sysroot_fd (self, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (mkdirat (self->sysroot_fd, deploydir, 0777) < 0)
|
||||||
|
{
|
||||||
|
glnx_set_prefix_error_from_errno (error, "Creating %s", deploydir);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!glnx_opendirat (self->sysroot_fd, deploydir, TRUE, &dfd, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (mkdirat (dfd, "var", 0777) < 0)
|
||||||
|
{
|
||||||
|
glnx_set_prefix_error_from_errno (error, "Creating %s", "var");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This is a bit of a legacy hack...but we have to keep it around
|
||||||
|
* now. We're ensuring core subdirectories of /var exist.
|
||||||
|
*/
|
||||||
|
if (mkdirat (dfd, "var/tmp", 0777) < 0)
|
||||||
|
{
|
||||||
|
glnx_set_prefix_error_from_errno (error, "Creating %s", "var/tmp");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fchmodat (dfd, "var/tmp", 01777, 0) < 0)
|
||||||
|
{
|
||||||
|
glnx_set_prefix_error_from_errno (error, "Fchmod %s", "var/tmp");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mkdirat (dfd, "var/lib", 0777) < 0)
|
||||||
|
{
|
||||||
|
glnx_set_prefix_error_from_errno (error, "Creating %s", "var/tmp");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (symlinkat ("../run", dfd, "var/run") < 0)
|
||||||
|
{
|
||||||
|
glnx_set_prefix_error_from_errno (error, "Symlinking %s", "var/run");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (symlinkat ("../run/lock", dfd, "var/lock") < 0)
|
||||||
|
{
|
||||||
|
glnx_set_prefix_error_from_errno (error, "Symlinking %s", "var/lock");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_ostree_sysroot_bump_mtime (self, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ret = TRUE;
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ostree_sysroot_simple_write_deployment:
|
* ostree_sysroot_simple_write_deployment:
|
||||||
* @sysroot: Sysroot
|
* @sysroot: Sysroot
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,12 @@ gboolean ostree_sysroot_lock_finish (OstreeSysroot *self,
|
||||||
_OSTREE_PUBLIC
|
_OSTREE_PUBLIC
|
||||||
void ostree_sysroot_unlock (OstreeSysroot *self);
|
void ostree_sysroot_unlock (OstreeSysroot *self);
|
||||||
|
|
||||||
|
_OSTREE_PUBLIC
|
||||||
|
gboolean ostree_sysroot_init_osname (OstreeSysroot *self,
|
||||||
|
const char *osname,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
_OSTREE_PUBLIC
|
_OSTREE_PUBLIC
|
||||||
gboolean ostree_sysroot_cleanup (OstreeSysroot *self,
|
gboolean ostree_sysroot_cleanup (OstreeSysroot *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,6 @@ ot_admin_builtin_os_init (int argc, char **argv, GCancellable *cancellable, GErr
|
||||||
glnx_unref_object OstreeSysroot *sysroot = NULL;
|
glnx_unref_object OstreeSysroot *sysroot = NULL;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
const char *osname = NULL;
|
const char *osname = NULL;
|
||||||
g_autoptr(GFile) deploy_dir = NULL;
|
|
||||||
g_autoptr(GFile) dir = NULL;
|
|
||||||
|
|
||||||
context = g_option_context_new ("OSNAME - Initialize empty state for given operating system");
|
context = g_option_context_new ("OSNAME - Initialize empty state for given operating system");
|
||||||
|
|
||||||
|
|
@ -61,48 +59,10 @@ ot_admin_builtin_os_init (int argc, char **argv, GCancellable *cancellable, GErr
|
||||||
|
|
||||||
osname = argv[1];
|
osname = argv[1];
|
||||||
|
|
||||||
deploy_dir = ot_gfile_get_child_build_path (ostree_sysroot_get_path (sysroot), "ostree", "deploy", osname, NULL);
|
if (!ostree_sysroot_init_osname (sysroot, osname, cancellable, error))
|
||||||
|
|
||||||
/* Ensure core subdirectories of /var exist, since we need them for
|
|
||||||
* dracut generation, and the host will want them too.
|
|
||||||
*/
|
|
||||||
g_clear_object (&dir);
|
|
||||||
dir = ot_gfile_get_child_build_path (deploy_dir, "var", "tmp", NULL);
|
|
||||||
if (!gs_file_ensure_directory (dir, TRUE, cancellable, error))
|
|
||||||
goto out;
|
|
||||||
if (chmod (gs_file_get_path_cached (dir), 01777) < 0)
|
|
||||||
{
|
|
||||||
gs_set_error_from_errno (error, errno);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_clear_object (&dir);
|
|
||||||
dir = ot_gfile_get_child_build_path (deploy_dir, "var", "lib", NULL);
|
|
||||||
if (!gs_file_ensure_directory (dir, TRUE, cancellable, error))
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
g_clear_object (&dir);
|
g_print ("ostree/deploy/%s initialized as OSTree root\n", osname);
|
||||||
dir = ot_gfile_get_child_build_path (deploy_dir, "var", "run", NULL);
|
|
||||||
if (!g_file_test (gs_file_get_path_cached (dir), G_FILE_TEST_IS_SYMLINK))
|
|
||||||
{
|
|
||||||
if (symlink ("../run", gs_file_get_path_cached (dir)) < 0)
|
|
||||||
{
|
|
||||||
gs_set_error_from_errno (error, errno);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dir = ot_gfile_get_child_build_path (deploy_dir, "var", "lock", NULL);
|
|
||||||
if (!g_file_test (gs_file_get_path_cached (dir), G_FILE_TEST_IS_SYMLINK))
|
|
||||||
{
|
|
||||||
if (symlink ("../run/lock", gs_file_get_path_cached (dir)) < 0)
|
|
||||||
{
|
|
||||||
gs_set_error_from_errno (error, errno);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g_print ("%s initialized as OSTree root\n", gs_file_get_path_cached (deploy_dir));
|
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue