Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sysupdate.d: Add way to drop binaries into $BOOT #27794

Merged
merged 1 commit into from
Jun 3, 2023

Conversation

AdrianVovk
Copy link
Contributor

As described in the BLS, we should place binaries into the XBOOTLDR directory if it is available, otherwise into the ESP. Thus, we might need to put binaries into /boot or into /efi depending on the existence of the XBOOTLDR partition.

With this change, if the Path= config option in the file starts with $BOOT, we replace that with either /boot or /efi, depending on what is available on the system.

man/sysupdate.d.xml Outdated Show resolved Hide resolved
@poettering poettering added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label May 26, 2023
@AdrianVovk AdrianVovk force-pushed the sysupdate-boot-wildcard branch 2 times, most recently from b77bf16 to 2a6564b Compare May 26, 2023 20:52
@AdrianVovk AdrianVovk marked this pull request as ready for review May 26, 2023 20:52
@AdrianVovk
Copy link
Contributor Author

I think this is ready for another look

@github-actions github-actions bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels May 26, 2023
@AdrianVovk AdrianVovk force-pushed the sysupdate-boot-wildcard branch from 2a6564b to dca5db6 Compare May 30, 2023 15:36
@poettering
Copy link
Member

anyway, I think we should do the PathRelativeTo= idea as per suggestions above. can you rework?

@poettering poettering added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels May 31, 2023
@AdrianVovk AdrianVovk force-pushed the sysupdate-boot-wildcard branch from dca5db6 to 2592f82 Compare May 31, 2023 19:41
@github-actions github-actions bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels May 31, 2023
@AdrianVovk
Copy link
Contributor Author

Done. I didn't implement the test as you suggested because it turns out to be rather finicky/annoying to get working (I'd have to figure out how to build sysupdate without the CLI so that I can graft a test onto it) and I feel isn't worth all that much (since it'd have to be manually updated and thus doesn't really prevent diverging...)

My work on the test before I scrapped it
diff --git a/src/sysupdate/meson.build b/src/sysupdate/meson.build
index 2f8c2305da..c42ca043c5 100644
--- a/src/sysupdate/meson.build
+++ b/src/sysupdate/meson.build
@@ -20,3 +20,22 @@ systemd_sysupdate_sources = files(
         'sysupdate.c',
         'sysupdate.h',
 )
+
+############################################################
+
+tests += [
+	{
+		'sources' : files(
+		        'sysupdate-resource.c',
+                        'sysupdate-resource.h',
+		        'test-resource.c',
+		 ),
+		'link_with' : [
+		        libshared,
+		        libshared_fdisk,
+		],
+		'dependencies': [
+		        libfdisk,
+		],
+	},
+]
diff --git a/src/sysupdate/sysupdate-resource.h b/src/sysupdate/sysupdate-resource.h
index 960f463c58..ee786311c2 100644
--- a/src/sysupdate/sysupdate-resource.h
+++ b/src/sysupdate/sysupdate-resource.h
@@ -68,7 +68,7 @@ static inline bool RESOURCE_IS_URL(ResourceType t) {
 
 typedef enum PathRelativeTo {
         /* Please make sure to folow the naming of the corresponding PartitionDesignator enum values,
-         * where this makes sense, like for the following three. */
+         * where this makes sense, like for the following cases. Make sure to update the test too! */
         PATH_RELATIVE_TO_ROOT,
         PATH_RELATIVE_TO_ESP,
         PATH_RELATIVE_TO_XBOOTLDR,
diff --git a/src/sysupdate/test-resource.c b/src/sysupdate/test-resource.c
new file mode 100644
index 0000000000..d9d5d1d967
--- /dev/null
+++ b/src/sysupdate/test-resource.c
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+/* Some unit tests for the helper functions in sysupdate-reousrce. */
+
+#include "gpt.h"
+#include "log.h"
+#include "sysupdate-resource.h"
+#include "tests.h"
+
+TEST(path_relative_to_to_string) {
+        /* Make sure that PathRelativeTo's to_string function matches
+         * those in PartitionDesignator */
+
+        struct {
+                PathRelativeTo relative_to;
+                PartitionDesignator designator;
+        } cases[] = {
+                { PATH_RELATIVE_TO_ROOT,     PARTITION_ROOT },
+                { PATH_RELATIVE_TO_ESP,      PARTITION_ESP },
+                { PATH_RELATIVE_TO_XBOOTLDR, PARTITION_XBOOTLDR },
+        };
+
+        for (size_t i = 0; i < ELEMENTSOF(cases); i++) {
+                assert(streq_ptr(path_relative_to_to_string(cases[i].relative_to),
+                                 partition_designator_to_string(cases[i].designator)));
+        }
+}
+
+DEFINE_TEST_MAIN(LOG_DEBUG);

@bluca
Copy link
Member

bluca commented May 31, 2023

There's an integration test that uses scripts, there is already one for sysupdate (TEST-72-SYSUPDATE) so it should be doable to update it to test this too

@AdrianVovk AdrianVovk force-pushed the sysupdate-boot-wildcard branch from 2592f82 to 73d5e73 Compare May 31, 2023 20:18
@github-actions github-actions bot added the tests label May 31, 2023
test/units/testsuite-72.sh Fixed Show fixed Hide fixed
@AdrianVovk AdrianVovk force-pushed the sysupdate-boot-wildcard branch 2 times, most recently from eda90c6 to 59c303c Compare May 31, 2023 20:22
@poettering poettering added good-to-merge/with-minor-suggestions and removed please-review PR is ready for (re-)review by a maintainer labels May 31, 2023
@poettering
Copy link
Member

looks excellent, good to go if you address the oom issue. thanks!

@AdrianVovk AdrianVovk force-pushed the sysupdate-boot-wildcard branch from 59c303c to a521ff9 Compare May 31, 2023 20:25
@AdrianVovk
Copy link
Contributor Author

Looks like CI failure is my fault. I'll investigate tomorrow

@poettering poettering added the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label Jun 1, 2023
@AdrianVovk
Copy link
Contributor Author

So CI was failing because the behavior of sysupdate changed in a way that breaks the pre-existing parts of the test. The test previously deleted /var/tmp/72-dirs, which is a destination that sysupdate is supposed to put files into. However, it would never recreate this directory, and instead sysupdate would do so

Prior to my changes, if --root was unset sysupdate wouldn't actually try to resolve the path in any way. Instead, it would just use the path as-specified by the user verbatim. It seems like this would eventually end up creating the destination directory. However, if you were to specify --root, sysupdate would chase the provided path and this could fail if the path doesn't exist.

With my changes, sysupdate chases the path even if --root is unspecified. This means that it will fail for a path that doesn't exist. I think this is reasonable behavior and I've updated the test to reflect (just added a mkdir call to create /var/tmp/72-dirs). However, if you intended the behavior where non-existing destination directories get created, I can rework the PR in another way if you prefer (probably by adding CHASE_NONEXISTENT and possibly even CHASE_MKDIR_0755 to the chase call?)

@AdrianVovk AdrianVovk force-pushed the sysupdate-boot-wildcard branch from a521ff9 to 9b7cc69 Compare June 1, 2023 17:11
@github-actions github-actions bot removed the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label Jun 1, 2023
@AdrianVovk AdrianVovk force-pushed the sysupdate-boot-wildcard branch from 9b7cc69 to 4dc257f Compare June 1, 2023 19:01
@poettering
Copy link
Member

hmm, still ci failures

@poettering poettering added the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label Jun 2, 2023
As described in the BLS, we should place binaries into the XBOOTLDR
directory if it is available, otherwise into the ESP. Thus, we might
need to put binaries into /boot or into /efi depending on the existence
of the XBOOTLDR partition.

With this change, we introduce a new PathRelativeTo= config option that
makes this functionality possible
@AdrianVovk AdrianVovk force-pushed the sysupdate-boot-wildcard branch from 4dc257f to 7e96ae6 Compare June 2, 2023 20:25
@github-actions github-actions bot removed the ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR label Jun 2, 2023
@AdrianVovk
Copy link
Contributor Author

The test passed but then I had a silly oversight on cleanup :(

Anyway, should hopefully be fixed now 🤞. Thanks for your patience

@poettering poettering merged commit 0470f91 into systemd:main Jun 3, 2023
@AdrianVovk AdrianVovk deleted the sysupdate-boot-wildcard branch June 3, 2023 12:05
@AdrianVovk
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants