diff options
author | Colin Walters <walters@verbum.org> | 2016-03-03 11:39:33 -0500 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2016-03-03 14:21:57 -0500 |
commit | fbd9409ebb76c66c5fa33c207f97807deb70951e (patch) | |
tree | 7392e38a48254f2dbb48e49f7fff9cc91a1cadd2 | |
parent | 7ace5d35bd8b9d4d407b725518497df425376573 (diff) | |
download | ostree-fbd9409ebb76c66c5fa33c207f97807deb70951e.tar.gz |
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)
-rw-r--r-- | apidoc/ostree-sections.txt | 1 | ||||
-rw-r--r-- | src/libostree/libostree.sym | 1 | ||||
-rw-r--r-- | src/libostree/ostree-sysroot-deploy.c | 8 | ||||
-rw-r--r-- | src/libostree/ostree-sysroot-private.h | 3 | ||||
-rw-r--r-- | src/libostree/ostree-sysroot.c | 93 | ||||
-rw-r--r-- | src/libostree/ostree-sysroot.h | 6 | ||||
-rw-r--r-- | src/ostree/ot-admin-builtin-os-init.c | 44 |
7 files changed, 108 insertions, 48 deletions
diff --git a/apidoc/ostree-sections.txt b/apidoc/ostree-sections.txt index e4ce525d..ee4ba1c6 100644 --- a/apidoc/ostree-sections.txt +++ b/apidoc/ostree-sections.txt @@ -397,6 +397,7 @@ ostree_sysroot_get_deployment_origin_path ostree_sysroot_cleanup ostree_sysroot_prepare_cleanup ostree_sysroot_get_repo +ostree_sysroot_init_osname ostree_sysroot_deployment_set_kargs ostree_sysroot_write_deployments ostree_sysroot_deploy_tree diff --git a/src/libostree/libostree.sym b/src/libostree/libostree.sym index f86a1ead..03350176 100644 --- a/src/libostree/libostree.sym +++ b/src/libostree/libostree.sym @@ -316,4 +316,5 @@ LIBOSTREE_2016.4 { global: ostree_repo_get_dfd; ostree_repo_list_refs_ext; + ostree_sysroot_init_osname; } LIBOSTREE_2016.3; diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index b4f7cd27..1f15ddcf 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -1855,12 +1855,8 @@ ostree_sysroot_write_deployments (OstreeSysroot *self, requires_new_bootversion ? "yes" : "no", new_deployments->len - self->deployments->len); - /* 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"); - goto out; - } + if (!_ostree_sysroot_bump_mtime (self, error)) + goto out; /* Now reload from disk */ if (!ostree_sysroot_load (self, cancellable, error)) diff --git a/src/libostree/ostree-sysroot-private.h b/src/libostree/ostree-sysroot-private.h index e0dc24fd..356509ad 100644 --- a/src/libostree/ostree-sysroot-private.h +++ b/src/libostree/ostree-sysroot-private.h @@ -98,6 +98,9 @@ gboolean _ostree_sysroot_query_bootloader (OstreeSysroot *sysroot, GCancellable *cancellable, GError **error); +gboolean _ostree_sysroot_bump_mtime (OstreeSysroot *sysroot, + GError **error); + typedef enum { OSTREE_SYSROOT_CLEANUP_BOOTVERSIONS = 1 << 0, OSTREE_SYSROOT_CLEANUP_DEPLOYMENTS = 1 << 1, diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c index 5ad2713a..eb2b353d 100644 --- a/src/libostree/ostree-sysroot.c +++ b/src/libostree/ostree-sysroot.c @@ -229,6 +229,19 @@ ostree_sysroot_get_fd (OstreeSysroot *self) 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: * @self: Sysroot @@ -1338,6 +1351,86 @@ ostree_sysroot_lock_finish (OstreeSysroot *self, } /** + * 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: * @sysroot: Sysroot * @osname: (allow-none): OS name diff --git a/src/libostree/ostree-sysroot.h b/src/libostree/ostree-sysroot.h index bce86985..cab59d0a 100644 --- a/src/libostree/ostree-sysroot.h +++ b/src/libostree/ostree-sysroot.h @@ -98,6 +98,12 @@ _OSTREE_PUBLIC void ostree_sysroot_unlock (OstreeSysroot *self); _OSTREE_PUBLIC +gboolean ostree_sysroot_init_osname (OstreeSysroot *self, + const char *osname, + GCancellable *cancellable, + GError **error); + +_OSTREE_PUBLIC gboolean ostree_sysroot_cleanup (OstreeSysroot *self, GCancellable *cancellable, GError **error); diff --git a/src/ostree/ot-admin-builtin-os-init.c b/src/ostree/ot-admin-builtin-os-init.c index f5b5f64b..fbb04949 100644 --- a/src/ostree/ot-admin-builtin-os-init.c +++ b/src/ostree/ot-admin-builtin-os-init.c @@ -40,8 +40,6 @@ ot_admin_builtin_os_init (int argc, char **argv, GCancellable *cancellable, GErr glnx_unref_object OstreeSysroot *sysroot = NULL; gboolean ret = FALSE; 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"); @@ -61,48 +59,10 @@ ot_admin_builtin_os_init (int argc, char **argv, GCancellable *cancellable, GErr osname = argv[1]; - deploy_dir = ot_gfile_get_child_build_path (ostree_sysroot_get_path (sysroot), "ostree", "deploy", osname, NULL); - - /* 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)) + if (!ostree_sysroot_init_osname (sysroot, osname, cancellable, error)) goto out; - g_clear_object (&dir); - 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)); + g_print ("ostree/deploy/%s initialized as OSTree root\n", osname); ret = TRUE; out: |