From 506a891e36d384cb1343f2da1477c5b07abe6731 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 20 Apr 2015 22:02:14 -0400 Subject: [PATCH] deploy: Find kernel/initramfs consistently from filesystem I'm porting the deployment code to be fd-relative, but part of the logic was using `GFile` to talk to `OstreeRepoFile` to determine the "bootcsum" (boot config checksum) before checking out the file tree. We can avoid having both code paths by checking out the tree first, then looking at it on the filesystem. --- src/libostree/ostree-deployment-private.h | 29 +++++++++++++++++ src/libostree/ostree-deployment.c | 10 +++++- src/libostree/ostree-sysroot-deploy.c | 39 ++++++++++++----------- 3 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 src/libostree/ostree-deployment-private.h diff --git a/src/libostree/ostree-deployment-private.h b/src/libostree/ostree-deployment-private.h new file mode 100644 index 00000000..b5ebb957 --- /dev/null +++ b/src/libostree/ostree-deployment-private.h @@ -0,0 +1,29 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2015 Colin Walters + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2 of the licence or (at + * your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#pragma once + +#include "ostree-deployment.h" + +G_BEGIN_DECLS + +void _ostree_deployment_set_bootcsum (OstreeDeployment *self, const char *bootcsum); + +G_END_DECLS diff --git a/src/libostree/ostree-deployment.c b/src/libostree/ostree-deployment.c index 3d50df99..3a80474e 100644 --- a/src/libostree/ostree-deployment.c +++ b/src/libostree/ostree-deployment.c @@ -20,7 +20,7 @@ #include "config.h" -#include "ostree-deployment.h" +#include "ostree-deployment-private.h" #include "libglnx.h" struct _OstreeDeployment @@ -129,6 +129,14 @@ ostree_deployment_set_origin (OstreeDeployment *self, GKeyFile *origin) self->origin = g_key_file_ref (origin); } +void +_ostree_deployment_set_bootcsum (OstreeDeployment *self, + const char *bootcsum) +{ + g_free (self->bootcsum); + self->bootcsum = g_strdup (bootcsum); +} + /** * ostree_deployment_clone: * @self: Deployment diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index f7afe3d2..82834f28 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -24,6 +24,7 @@ #include #include "ostree-sysroot-private.h" +#include "ostree-deployment-private.h" #include "ostree-core-private.h" #include "ostree-linuxfsutil.h" #include "otutil.h" @@ -1934,7 +1935,6 @@ ostree_sysroot_deploy_tree (OstreeSysroot *self, glnx_unref_object OstreeRepo *repo = NULL; g_autoptr(GFile) osdeploydir = NULL; g_autoptr(GFile) deployment_var = NULL; - g_autoptr(GFile) commit_root = NULL; g_autoptr(GFile) tree_kernel_path = NULL; g_autoptr(GFile) tree_initramfs_path = NULL; glnx_fd_close int deployment_dfd = -1; @@ -1960,24 +1960,6 @@ ostree_sysroot_deploy_tree (OstreeSysroot *self, if (!ostree_sysroot_get_repo (self, &repo, cancellable, error)) goto out; - if (!ostree_repo_read_commit (repo, revision, &commit_root, NULL, cancellable, error)) - goto out; - - if (!get_kernel_from_tree (commit_root, &tree_kernel_path, &tree_initramfs_path, - cancellable, error)) - goto out; - - if (tree_initramfs_path != NULL) - { - if (!checksum_from_kernel_src (tree_initramfs_path, &new_bootcsum, error)) - goto out; - } - else - { - if (!checksum_from_kernel_src (tree_kernel_path, &new_bootcsum, error)) - goto out; - } - if (provided_merge_deployment != NULL) merge_deployment = g_object_ref (provided_merge_deployment); @@ -1997,6 +1979,25 @@ ostree_sysroot_deploy_tree (OstreeSysroot *self, goto out; } + deployment_dir = ostree_sysroot_get_deployment_directory (self, new_deployment); + + if (!get_kernel_from_tree (deployment_dir, &tree_kernel_path, &tree_initramfs_path, + cancellable, error)) + goto out; + + if (tree_initramfs_path != NULL) + { + if (!checksum_from_kernel_src (tree_initramfs_path, &new_bootcsum, error)) + goto out; + } + else + { + if (!checksum_from_kernel_src (tree_kernel_path, &new_bootcsum, error)) + goto out; + } + + _ostree_deployment_set_bootcsum (new_deployment, new_bootcsum); + /* Create an empty boot configuration; we will merge things into * it as we go. */