[gnome-build-meta/valentindavid/fix-ostree-patch] ostree: Fix EFI boot patch




commit 75a85d861f5cf6a46a5f88477339746d2ca780d3
Author: Valentin David <valentin david codethink co uk>
Date:   Thu Apr 29 16:51:02 2021 +0200

    ostree: Fix EFI boot patch

 files/ostree/no-boot-symlink.patch | 158 ++++++++++++++++++++++++-------------
 1 file changed, 101 insertions(+), 57 deletions(-)
---
diff --git a/files/ostree/no-boot-symlink.patch b/files/ostree/no-boot-symlink.patch
index 8c2a9363..5402f28b 100644
--- a/files/ostree/no-boot-symlink.patch
+++ b/files/ostree/no-boot-symlink.patch
@@ -1,8 +1,95 @@
-diff --git a/src/libostree/ostree-sysroot-cleanup.c b/src/libostree/ostree-sysroot-cleanup.c
-index 27122834..a99d4bb6 100644
---- a/src/libostree/ostree-sysroot-cleanup.c
-+++ b/src/libostree/ostree-sysroot-cleanup.c
-@@ -216,6 +216,15 @@ cleanup_other_bootversions (OstreeSysroot       *self,
+diff -ur ostree.old/src/libostree/ostree-sysroot.c ostree/src/libostree/ostree-sysroot.c
+--- ostree.old/src/libostree/ostree-sysroot.c  2021-04-29 15:55:43.998198430 +0200
++++ ostree/src/libostree/ostree-sysroot.c      2021-04-29 15:59:41.072765930 +0200
+@@ -558,6 +558,13 @@
+   return compare_boot_loader_configs (a, b);
+ }
+ 
++static gboolean
++read_current_bootversion (OstreeSysroot *self,
++                          int           *out_bootversion,
++                          GCancellable  *cancellable,
++                          GError       **error);
++
++
+ /* Read all the bootconfigs from `/boot/loader/`. */
+ gboolean
+ _ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self,
+@@ -572,12 +579,22 @@
+   g_autoptr(GPtrArray) ret_loader_configs =
+     g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
+ 
+-  g_autofree char *entries_path = g_strdup_printf ("boot/loader.%d/entries", bootversion);
++  g_autofree char *entries_path = NULL;
++  int current_version;
++  if (!read_current_bootversion (self, &current_version, cancellable, error))
++    return FALSE;
++
++  if (current_version == bootversion)
++    entries_path = g_strdup ("boot/loader/entries");
++  else
++    entries_path = g_strdup_printf ("boot/loader.%d/entries", bootversion);
++
+   gboolean entries_exists;
+   g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
+   if (!ot_dfd_iter_init_allow_noent (self->sysroot_fd, entries_path,
+                                      &dfd_iter, &entries_exists, error))
+     return FALSE;
++
+   if (!entries_exists)
+     {
+       /* Note early return */
+@@ -637,18 +654,35 @@
+   else
+     {
+       if (!S_ISLNK (stbuf.st_mode))
+-        return glnx_throw (error, "Not a symbolic link: boot/loader");
+-
+-      g_autofree char *target =
+-        glnx_readlinkat_malloc (self->sysroot_fd, "boot/loader", cancellable, error);
+-      if (!target)
+-        return FALSE;
+-      if (g_strcmp0 (target, "loader.0") == 0)
+-        ret_bootversion = 0;
+-      else if (g_strcmp0 (target, "loader.1") == 0)
+-        ret_bootversion = 1;
++        {
++          gsize len;
++          g_autofree char* version_content = glnx_file_get_contents_utf8_at(self->sysroot_fd, 
"boot/loader/version",
++                                                                            &len, cancellable, error);
++          if (version_content == NULL) {
++            return FALSE;
++          }
++          if (len != 8)
++            return glnx_throw (error, "Invalid version in boot/loader/version");
++          else if (g_strcmp0 (version_content, "loader.0") == 0)
++            ret_bootversion = 0;
++          else if (g_strcmp0 (version_content, "loader.1") == 0)
++            ret_bootversion = 1;
++          else
++            return glnx_throw (error, "Invalid version in boot/loader/version");
++        }
+       else
+-        return glnx_throw (error, "Invalid target '%s' in boot/loader", target);
++        {
++          g_autofree char *target =
++            glnx_readlinkat_malloc (self->sysroot_fd, "boot/loader", cancellable, error);
++          if (!target)
++            return FALSE;
++          if (g_strcmp0 (target, "loader.0") == 0)
++            ret_bootversion = 0;
++          else if (g_strcmp0 (target, "loader.1") == 0)
++            ret_bootversion = 1;
++          else
++            return glnx_throw (error, "Invalid target '%s' in boot/loader", target);
++        }
+     }
+ 
+   *out_bootversion = ret_bootversion;
+diff -ur ostree.old/src/libostree/ostree-sysroot-cleanup.c ostree/src/libostree/ostree-sysroot-cleanup.c
+--- ostree.old/src/libostree/ostree-sysroot-cleanup.c  2021-04-29 15:55:43.998198430 +0200
++++ ostree/src/libostree/ostree-sysroot-cleanup.c      2021-04-29 15:55:54.015206216 +0200
+@@ -216,6 +216,15 @@
    const int cleanup_subbootversion = self->subbootversion == 0 ? 1 : 0;
    /* Reusable buffer for path */
    g_autoptr(GString) buf = g_string_new ("");
@@ -18,11 +105,10 @@ index 27122834..a99d4bb6 100644
  
    /* These directories are for the other major version */
    g_string_truncate (buf, 0); g_string_append_printf (buf, "boot/loader.%d", cleanup_bootversion);
-diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c
-index 32748a62..c308fb76 100644
---- a/src/libostree/ostree-sysroot-deploy.c
-+++ b/src/libostree/ostree-sysroot-deploy.c
-@@ -2028,17 +2028,15 @@ install_deployment_kernel (OstreeSysroot   *sysroot,
+diff -ur ostree.old/src/libostree/ostree-sysroot-deploy.c ostree/src/libostree/ostree-sysroot-deploy.c
+--- ostree.old/src/libostree/ostree-sysroot-deploy.c   2021-04-29 15:55:43.998198430 +0200
++++ ostree/src/libostree/ostree-sysroot-deploy.c       2021-04-29 15:55:54.015206216 +0200
+@@ -2028,17 +2028,15 @@
    return TRUE;
  }
  
@@ -47,7 +133,7 @@ index 32748a62..c308fb76 100644
    GLNX_AUTO_PREFIX_ERROR ("Preparing final bootloader swap", error);
    g_assert ((current_bootversion == 0 && new_bootversion == 1) ||
              (current_bootversion == 1 && new_bootversion == 0));
-@@ -2049,23 +2047,76 @@ prepare_new_bootloader_link (OstreeSysroot  *sysroot,
+@@ -2049,23 +2047,76 @@
      if (errno != EEXIST)
        return glnx_throw_errno_prefix (error, "symlinkat");
  
@@ -129,7 +215,7 @@ index 32748a62..c308fb76 100644
                   GCancellable   *cancellable,
                   GError        **error)
  {
-@@ -2081,8 +2132,9 @@ swap_bootloader (OstreeSysroot  *sysroot,
+@@ -2081,8 +2132,9 @@
     * its data is in place.  Renaming now should give us atomic semantics;
     * see https://bugzilla.gnome.org/show_bug.cgi?id=755595
     */
@@ -141,7 +227,7 @@ index 32748a62..c308fb76 100644
  
    /* Now we explicitly fsync this directory, even though it
     * isn't required for atomicity, for two reasons:
-@@ -2255,6 +2307,7 @@ write_deployments_bootswap (OstreeSysroot     *self,
+@@ -2255,6 +2307,7 @@
                              OstreeSysrootWriteDeploymentsOpts *opts,
                              OstreeBootloader  *bootloader,
                              SyncStats         *out_syncstats,
@@ -149,7 +235,7 @@ index 32748a62..c308fb76 100644
                              char             **out_subbootdir,
                              GCancellable      *cancellable,
                              GError           **error)
-@@ -2319,15 +2372,15 @@ write_deployments_bootswap (OstreeSysroot     *self,
+@@ -2319,15 +2372,15 @@
          return glnx_prefix_error (error, "Bootloader write config");
      }
  
@@ -168,7 +254,7 @@ index 32748a62..c308fb76 100644
      return FALSE;
  
    if (out_subbootdir)
-@@ -2536,7 +2589,8 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot     *self,
+@@ -2536,7 +2589,8 @@
        bootloader_is_atomic = bootloader != NULL && _ostree_bootloader_is_atomic (bootloader);
  
        if (!write_deployments_bootswap (self, new_deployments, opts, bootloader,
@@ -178,45 +264,3 @@ index 32748a62..c308fb76 100644
          return FALSE;
      }
  
-diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c
-index b0ae66cf..6dd278f3 100644
---- a/src/libostree/ostree-sysroot.c
-+++ b/src/libostree/ostree-sysroot.c
-@@ -558,6 +558,13 @@ compare_loader_configs_for_sorting (gconstpointer  a_pp,
-   return compare_boot_loader_configs (a, b);
- }
- 
-+static gboolean
-+read_current_bootversion (OstreeSysroot *self,
-+                          int           *out_bootversion,
-+                          GCancellable  *cancellable,
-+                          GError       **error);
-+
-+
- /* Read all the bootconfigs from `/boot/loader/`. */
- gboolean
- _ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self,
-@@ -572,12 +579,22 @@ _ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self,
-   g_autoptr(GPtrArray) ret_loader_configs =
-     g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
- 
--  g_autofree char *entries_path = g_strdup_printf ("boot/loader.%d/entries", bootversion);
-+  g_autofree char *entries_path = NULL;
-+  int current_version;
-+  if (!read_current_bootversion (self, &current_version, cancellable, error))
-+    return FALSE;
-+
-+  if (current_version == bootversion)
-+    entries_path = g_strdup ("boot/loader/entries");
-+  else
-+    entries_path = g_strdup_printf ("boot/loader.%d/entries", bootversion);
-+
-   gboolean entries_exists;
-   g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
-   if (!ot_dfd_iter_init_allow_noent (self->sysroot_fd, entries_path,
-                                      &dfd_iter, &entries_exists, error))
-     return FALSE;
-+
-   if (!entries_exists)
-     {
-       /* Note early return */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]