From a52ce4a29dd2346c80bebb5722019d7cee712cf3 Mon Sep 17 00:00:00 2001 From: Ivan Kruglov Date: Mon, 21 Oct 2024 13:51:22 +0200 Subject: [PATCH 1/9] machine: align polkit verb of io.systemd.MachineImage.Update with the rest of the code --- src/machine/image-varlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine/image-varlink.c b/src/machine/image-varlink.c index 3177a93847..2909e2a750 100644 --- a/src/machine/image-varlink.c +++ b/src/machine/image-varlink.c @@ -57,7 +57,7 @@ int vl_method_update_image(sd_varlink *link, sd_json_variant *parameters, sd_var manager->bus, "org.freedesktop.machine1.manage-images", (const char**) STRV_MAKE("image", image->name, - "verb", "update_image"), + "verb", "update"), &manager->polkit_registry); if (r <= 0) return r; From 30a34657b84e8a1acc91fb0695ac97c90303fe9c Mon Sep 17 00:00:00 2001 From: Ivan Kruglov Date: Thu, 31 Oct 2024 10:58:21 +0100 Subject: [PATCH 2/9] machine: introduce report_errno_and_exit() --- src/machine/operation.c | 15 +++++++++++++++ src/machine/operation.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/machine/operation.c b/src/machine/operation.c index 7d7bfa5062..0b2139acf0 100644 --- a/src/machine/operation.c +++ b/src/machine/operation.c @@ -154,3 +154,18 @@ Operation *operation_free(Operation *o) { return mfree(o); } + +_noreturn_ void report_errno_and_exit(int errno_fd, int r) { + if (r >= 0) + _exit(EXIT_SUCCESS); + + assert(errno_fd >= 0); + + ssize_t n = write(errno_fd, &r, sizeof(r)); + if (n < 0) + log_debug_errno(errno, "Failed to write operation's errno: %m"); + if (n != sizeof(r)) + log_debug_errno(SYNTHETIC_ERRNO(EIO), "Sent unexpectedly short message"); + + _exit(EXIT_FAILURE); +} diff --git a/src/machine/operation.h b/src/machine/operation.h index 75bf918c2b..ee9149854a 100644 --- a/src/machine/operation.h +++ b/src/machine/operation.h @@ -39,3 +39,5 @@ static inline int operation_new_with_bus_reply(Manager *manager, Machine *machin static inline int operation_new_with_varlink_reply(Manager *manager, Machine *machine, pid_t child, sd_varlink *link, int errno_fd, Operation **ret) { return operation_new(manager, machine, child, /* message = */ NULL, link, errno_fd, ret); } + +void report_errno_and_exit(int errno_fd, int r); From 95d5b9097ba6ecba27cc754c84203b4c5ec6cc74 Mon Sep 17 00:00:00 2001 From: Ivan Kruglov Date: Thu, 31 Oct 2024 11:01:16 +0100 Subject: [PATCH 3/9] machine: use report_errno_and_exit() in dbus code --- src/machine/image-dbus.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/machine/image-dbus.c b/src/machine/image-dbus.c index 2ae61f99b7..8eca1e4c95 100644 --- a/src/machine/image-dbus.c +++ b/src/machine/image-dbus.c @@ -67,14 +67,8 @@ int bus_image_method_remove( return sd_bus_error_set_errnof(error, r, "Failed to fork(): %m"); if (r == 0) { errno_pipe_fd[0] = safe_close(errno_pipe_fd[0]); - r = image_remove(image); - if (r < 0) { - (void) write(errno_pipe_fd[1], &r, sizeof(r)); - _exit(EXIT_FAILURE); - } - - _exit(EXIT_SUCCESS); + report_errno_and_exit(errno_pipe_fd[1], r); } errno_pipe_fd[1] = safe_close(errno_pipe_fd[1]); @@ -184,14 +178,8 @@ int bus_image_method_clone( return sd_bus_error_set_errnof(error, r, "Failed to fork(): %m"); if (r == 0) { errno_pipe_fd[0] = safe_close(errno_pipe_fd[0]); - r = image_clone(image, new_name, read_only); - if (r < 0) { - (void) write(errno_pipe_fd[1], &r, sizeof(r)); - _exit(EXIT_FAILURE); - } - - _exit(EXIT_SUCCESS); + report_errno_and_exit(errno_pipe_fd[1], r); } errno_pipe_fd[1] = safe_close(errno_pipe_fd[1]); From 38a0cf4172f472b24b2001e11412251664de33bb Mon Sep 17 00:00:00 2001 From: Ivan Kruglov Date: Mon, 21 Oct 2024 13:53:38 +0200 Subject: [PATCH 4/9] machine: introduce io.systemd.MachineImage.Clone method --- src/machine/image-varlink.c | 85 ++++++++++++++++++++ src/machine/image-varlink.h | 1 + src/machine/machined-varlink.c | 3 +- src/shared/varlink-io.systemd.MachineImage.c | 20 ++++- 4 files changed, 107 insertions(+), 2 deletions(-) diff --git a/src/machine/image-varlink.c b/src/machine/image-varlink.c index 2909e2a750..f2f745e655 100644 --- a/src/machine/image-varlink.c +++ b/src/machine/image-varlink.c @@ -4,10 +4,22 @@ #include "sd-varlink.h" #include "bus-polkit.h" +#include "fd-util.h" #include "image-varlink.h" #include "machine.h" #include "string-util.h" +typedef struct ImageUpdateParameters { + const char *name; + const char *new_name; + int read_only; +} ImageUpdateParameters; + +#define IMAGE_UPDATE_PARAMETERS_NULL \ + (ImageUpdateParameters) { \ + .read_only = -1, \ + } + int vl_method_update_image(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { struct params { const char *image_name; @@ -86,3 +98,76 @@ int vl_method_update_image(sd_varlink *link, sd_json_variant *parameters, sd_var return sd_varlink_reply(link, NULL); } + +int vl_method_clone_image(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { + static const sd_json_dispatch_field dispatch_table[] = { + { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(ImageUpdateParameters, name), SD_JSON_MANDATORY }, + { "newName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(ImageUpdateParameters, new_name), SD_JSON_MANDATORY }, + { "readOnly", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_tristate, offsetof(ImageUpdateParameters, read_only), 0 }, + VARLINK_DISPATCH_POLKIT_FIELD, + {} + }; + + Manager *manager = ASSERT_PTR(userdata); + _cleanup_close_pair_ int errno_pipe_fd[2] = EBADF_PAIR; + ImageUpdateParameters p = IMAGE_UPDATE_PARAMETERS_NULL; + Image *image; + pid_t child; + int r; + + assert(link); + assert(parameters); + + if (manager->n_operations >= OPERATIONS_MAX) + return sd_varlink_error(link, "io.systemd.MachineImage.TooManyOperations", NULL); + + r = sd_varlink_dispatch(link, parameters, dispatch_table, &p); + if (r != 0) + return r; + + if (!image_name_is_valid(p.name)) + return sd_varlink_error_invalid_parameter_name(link, "name"); + + if (!image_name_is_valid(p.new_name)) + return sd_varlink_error_invalid_parameter_name(link, "newName"); + + r = manager_acquire_image(manager, p.name, &image); + if (r == -ENOENT) + return sd_varlink_error(link, "io.systemd.MachineImage.NoSuchImage", NULL); + if (r < 0) + return r; + + r = varlink_verify_polkit_async( + link, + manager->bus, + "org.freedesktop.machine1.manage-images", + (const char**) STRV_MAKE("image", image->name, + "verb", "clone", + "new_name", p.new_name), + &manager->polkit_registry); + if (r <= 0) + return r; + + if (pipe2(errno_pipe_fd, O_CLOEXEC|O_NONBLOCK) < 0) + return log_debug_errno(errno, "Failed to open pipe: %m"); + + r = safe_fork("(sd-imgclone)", FORK_RESET_SIGNALS, &child); + if (r < 0) + return log_debug_errno(r, "Failed to fork: %m"); + if (r == 0) { + errno_pipe_fd[0] = safe_close(errno_pipe_fd[0]); + r = image_clone(image, p.new_name, p.read_only > 0); + report_errno_and_exit(errno_pipe_fd[1], r); + } + + errno_pipe_fd[1] = safe_close(errno_pipe_fd[1]); + + r = operation_new_with_varlink_reply(manager, /* machine= */ NULL, child, link, errno_pipe_fd[0], /* ret= */ NULL); + if (r < 0) { + sigkill_wait(child); + return r; + } + + TAKE_FD(errno_pipe_fd[0]); + return 1; +} diff --git a/src/machine/image-varlink.h b/src/machine/image-varlink.h index 72028239de..e5532fa887 100644 --- a/src/machine/image-varlink.h +++ b/src/machine/image-varlink.h @@ -4,3 +4,4 @@ #include "sd-varlink.h" int vl_method_update_image(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); +int vl_method_clone_image(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); diff --git a/src/machine/machined-varlink.c b/src/machine/machined-varlink.c index 151d06e5f4..691248e674 100644 --- a/src/machine/machined-varlink.c +++ b/src/machine/machined-varlink.c @@ -774,7 +774,8 @@ static int manager_varlink_init_machine(Manager *m) { "io.systemd.Machine.Terminate", vl_method_terminate, "io.systemd.Machine.Kill", vl_method_kill, "io.systemd.MachineImage.List", vl_method_list_images, - "io.systemd.MachineImage.Update", vl_method_update_image); + "io.systemd.MachineImage.Update", vl_method_update_image, + "io.systemd.MachineImage.Clone", vl_method_clone_image); if (r < 0) return log_error_errno(r, "Failed to register varlink methods: %m"); diff --git a/src/shared/varlink-io.systemd.MachineImage.c b/src/shared/varlink-io.systemd.MachineImage.c index 5d3b3fd32f..68ea5cf279 100644 --- a/src/shared/varlink-io.systemd.MachineImage.c +++ b/src/shared/varlink-io.systemd.MachineImage.c @@ -53,6 +53,11 @@ static SD_VARLINK_DEFINE_METHOD_FULL( SD_VARLINK_FIELD_COMMENT("OS release information of an image. It contains an array of key value pairs read from the os-release(5) file in the image."), SD_VARLINK_DEFINE_OUTPUT(OSRelease, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY)); +#define VARLINK_DEFINE_IMAGE_LOOKUP_AND_POLKIT_FIELDS \ + SD_VARLINK_FIELD_COMMENT("The name of an image"), \ + SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, 0), \ + VARLINK_DEFINE_POLKIT_INPUT + static SD_VARLINK_DEFINE_METHOD( Update, SD_VARLINK_FIELD_COMMENT("The name of a image to update."), @@ -65,7 +70,16 @@ static SD_VARLINK_DEFINE_METHOD( SD_VARLINK_DEFINE_INPUT(limit, SD_VARLINK_INT, SD_VARLINK_NULLABLE), VARLINK_DEFINE_POLKIT_INPUT); +static SD_VARLINK_DEFINE_METHOD( + Clone, + VARLINK_DEFINE_IMAGE_LOOKUP_AND_POLKIT_FIELDS, + SD_VARLINK_FIELD_COMMENT("The new name of the image"), + SD_VARLINK_DEFINE_INPUT(newName, SD_VARLINK_STRING, 0), + SD_VARLINK_FIELD_COMMENT("If non-null value of the read-only flag of the image"), + SD_VARLINK_DEFINE_INPUT(readOnly, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE)); + static SD_VARLINK_DEFINE_ERROR(NoSuchImage); +static SD_VARLINK_DEFINE_ERROR(TooManyOperations); SD_VARLINK_DEFINE_INTERFACE( io_systemd_MachineImage, @@ -76,5 +90,9 @@ SD_VARLINK_DEFINE_INTERFACE( &vl_method_List, SD_VARLINK_SYMBOL_COMMENT("Update image allowing to rename or toggle read-only flag"), &vl_method_Update, + SD_VARLINK_SYMBOL_COMMENT("Clone image"), + &vl_method_Clone, SD_VARLINK_SYMBOL_COMMENT("No matching image exists"), - &vl_error_NoSuchImage); + &vl_error_NoSuchImage, + SD_VARLINK_SYMBOL_COMMENT("Too many ongoing background operations"), + &vl_error_TooManyOperations); From 1663455b63442d225c54c3b63ebade61cd858f8e Mon Sep 17 00:00:00 2001 From: Ivan Kruglov Date: Mon, 21 Oct 2024 13:54:42 +0200 Subject: [PATCH 5/9] machine: introduce io.systemd.MachineImage.Remove method --- src/machine/image-varlink.c | 67 ++++++++++++++++++++ src/machine/image-varlink.h | 1 + src/machine/machined-varlink.c | 3 +- src/shared/varlink-io.systemd.MachineImage.c | 6 ++ 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/machine/image-varlink.c b/src/machine/image-varlink.c index f2f745e655..9254d0beb6 100644 --- a/src/machine/image-varlink.c +++ b/src/machine/image-varlink.c @@ -171,3 +171,70 @@ int vl_method_clone_image(sd_varlink *link, sd_json_variant *parameters, sd_varl TAKE_FD(errno_pipe_fd[0]); return 1; } + +int vl_method_remove_image(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { + static const sd_json_dispatch_field dispatch_table[] = { + { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, 0, SD_JSON_MANDATORY }, + VARLINK_DISPATCH_POLKIT_FIELD, + {} + }; + + Manager *manager = ASSERT_PTR(userdata); + _cleanup_close_pair_ int errno_pipe_fd[2] = EBADF_PAIR; + const char *image_name; + Image *image; + pid_t child; + int r; + + assert(link); + assert(parameters); + + if (manager->n_operations >= OPERATIONS_MAX) + return sd_varlink_error(link, "io.systemd.MachineImage.TooManyOperations", NULL); + + r = sd_varlink_dispatch(link, parameters, dispatch_table, &image_name); + if (r != 0) + return r; + + if (!image_name_is_valid(image_name)) + return sd_varlink_error_invalid_parameter_name(link, "name"); + + r = manager_acquire_image(manager, image_name, &image); + if (r == -ENOENT) + return sd_varlink_error(link, "io.systemd.MachineImage.NoSuchImage", NULL); + if (r < 0) + return r; + + r = varlink_verify_polkit_async( + link, + manager->bus, + "org.freedesktop.machine1.manage-images", + (const char**) STRV_MAKE("image", image->name, + "verb", "remove"), + &manager->polkit_registry); + if (r <= 0) + return r; + + if (pipe2(errno_pipe_fd, O_CLOEXEC|O_NONBLOCK) < 0) + return log_debug_errno(errno, "Failed to open pipe: %m"); + + r = safe_fork("(sd-imgrm)", FORK_RESET_SIGNALS, &child); + if (r < 0) + return log_debug_errno(r, "Failed to fork: %m"); + if (r == 0) { + errno_pipe_fd[0] = safe_close(errno_pipe_fd[0]); + r = image_remove(image); + report_errno_and_exit(errno_pipe_fd[1], r); + } + + errno_pipe_fd[1] = safe_close(errno_pipe_fd[1]); + + r = operation_new_with_varlink_reply(manager, /* machine= */ NULL, child, link, errno_pipe_fd[0], /* ret= */ NULL); + if (r < 0) { + sigkill_wait(child); + return r; + } + + TAKE_FD(errno_pipe_fd[0]); + return 1; +} diff --git a/src/machine/image-varlink.h b/src/machine/image-varlink.h index e5532fa887..8ae1103780 100644 --- a/src/machine/image-varlink.h +++ b/src/machine/image-varlink.h @@ -5,3 +5,4 @@ int vl_method_update_image(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); int vl_method_clone_image(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); +int vl_method_remove_image(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata); diff --git a/src/machine/machined-varlink.c b/src/machine/machined-varlink.c index 691248e674..85cac71dda 100644 --- a/src/machine/machined-varlink.c +++ b/src/machine/machined-varlink.c @@ -775,7 +775,8 @@ static int manager_varlink_init_machine(Manager *m) { "io.systemd.Machine.Kill", vl_method_kill, "io.systemd.MachineImage.List", vl_method_list_images, "io.systemd.MachineImage.Update", vl_method_update_image, - "io.systemd.MachineImage.Clone", vl_method_clone_image); + "io.systemd.MachineImage.Clone", vl_method_clone_image, + "io.systemd.MachineImage.Remove", vl_method_remove_image); if (r < 0) return log_error_errno(r, "Failed to register varlink methods: %m"); diff --git a/src/shared/varlink-io.systemd.MachineImage.c b/src/shared/varlink-io.systemd.MachineImage.c index 68ea5cf279..caab5370dc 100644 --- a/src/shared/varlink-io.systemd.MachineImage.c +++ b/src/shared/varlink-io.systemd.MachineImage.c @@ -78,6 +78,10 @@ static SD_VARLINK_DEFINE_METHOD( SD_VARLINK_FIELD_COMMENT("If non-null value of the read-only flag of the image"), SD_VARLINK_DEFINE_INPUT(readOnly, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE)); +static SD_VARLINK_DEFINE_METHOD( + Remove, + VARLINK_DEFINE_IMAGE_LOOKUP_AND_POLKIT_FIELDS); + static SD_VARLINK_DEFINE_ERROR(NoSuchImage); static SD_VARLINK_DEFINE_ERROR(TooManyOperations); @@ -92,6 +96,8 @@ SD_VARLINK_DEFINE_INTERFACE( &vl_method_Update, SD_VARLINK_SYMBOL_COMMENT("Clone image"), &vl_method_Clone, + SD_VARLINK_SYMBOL_COMMENT("Remove image"), + &vl_method_Remove, SD_VARLINK_SYMBOL_COMMENT("No matching image exists"), &vl_error_NoSuchImage, SD_VARLINK_SYMBOL_COMMENT("Too many ongoing background operations"), From cc060c29105047132e8ddd337bb892d09f523f1a Mon Sep 17 00:00:00 2001 From: Ivan Kruglov Date: Mon, 21 Oct 2024 13:54:58 +0200 Subject: [PATCH 6/9] machine: reuse VARLINK_DEFINE_IMAGE_LOOKUP_AND_POLKIT_FIELDS in io.systemd.MachineImage.Update declaration --- src/shared/varlink-io.systemd.MachineImage.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/shared/varlink-io.systemd.MachineImage.c b/src/shared/varlink-io.systemd.MachineImage.c index caab5370dc..813b6c8e68 100644 --- a/src/shared/varlink-io.systemd.MachineImage.c +++ b/src/shared/varlink-io.systemd.MachineImage.c @@ -60,15 +60,13 @@ static SD_VARLINK_DEFINE_METHOD_FULL( static SD_VARLINK_DEFINE_METHOD( Update, - SD_VARLINK_FIELD_COMMENT("The name of a image to update."), - SD_VARLINK_DEFINE_INPUT(name, SD_VARLINK_STRING, 0), + VARLINK_DEFINE_IMAGE_LOOKUP_AND_POLKIT_FIELDS, SD_VARLINK_FIELD_COMMENT("If non-null the new name of the image"), SD_VARLINK_DEFINE_INPUT(newName, SD_VARLINK_STRING, SD_VARLINK_NULLABLE), SD_VARLINK_FIELD_COMMENT("If non-null value of the read-only flag of the image"), SD_VARLINK_DEFINE_INPUT(readOnly, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE), SD_VARLINK_FIELD_COMMENT("If non-null value of image quota limit"), - SD_VARLINK_DEFINE_INPUT(limit, SD_VARLINK_INT, SD_VARLINK_NULLABLE), - VARLINK_DEFINE_POLKIT_INPUT); + SD_VARLINK_DEFINE_INPUT(limit, SD_VARLINK_INT, SD_VARLINK_NULLABLE)); static SD_VARLINK_DEFINE_METHOD( Clone, From 88d0b72833076f1f35c2bbe509342064e16cbd32 Mon Sep 17 00:00:00 2001 From: Ivan Kruglov Date: Tue, 22 Oct 2024 11:00:41 +0200 Subject: [PATCH 7/9] machine: use ImageUpdateParameters in io.systemd.MachineImage.Update --- src/machine/image-varlink.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/machine/image-varlink.c b/src/machine/image-varlink.c index 9254d0beb6..5eb636960d 100644 --- a/src/machine/image-varlink.c +++ b/src/machine/image-varlink.c @@ -13,35 +13,27 @@ typedef struct ImageUpdateParameters { const char *name; const char *new_name; int read_only; + uint64_t limit; } ImageUpdateParameters; #define IMAGE_UPDATE_PARAMETERS_NULL \ (ImageUpdateParameters) { \ .read_only = -1, \ + .limit = UINT64_MAX, \ } int vl_method_update_image(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) { - struct params { - const char *image_name; - const char *new_name; - int read_only; - uint64_t limit; - }; - static const sd_json_dispatch_field dispatch_table[] = { - { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(struct params, image_name), SD_JSON_MANDATORY }, - { "newName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(struct params, new_name), 0 }, - { "readOnly", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_tristate, offsetof(struct params, read_only), 0 }, - { "limit", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(struct params, limit), 0 }, + { "name", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(ImageUpdateParameters, name), SD_JSON_MANDATORY }, + { "newName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(ImageUpdateParameters, new_name), 0 }, + { "readOnly", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_tristate, offsetof(ImageUpdateParameters, read_only), 0 }, + { "limit", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint64, offsetof(ImageUpdateParameters, limit), 0 }, VARLINK_DISPATCH_POLKIT_FIELD, {} }; Manager *manager = ASSERT_PTR(userdata); - struct params p = { - .read_only = -1, - .limit = UINT64_MAX, - }; + ImageUpdateParameters p = IMAGE_UPDATE_PARAMETERS_NULL; Image *image; int r, ret = 0; @@ -52,13 +44,13 @@ int vl_method_update_image(sd_varlink *link, sd_json_variant *parameters, sd_var if (r != 0) return r; - if (!image_name_is_valid(p.image_name)) + if (!image_name_is_valid(p.name)) return sd_varlink_error_invalid_parameter_name(link, "name"); if (p.new_name && !image_name_is_valid(p.new_name)) return sd_varlink_error_invalid_parameter_name(link, "newName"); - r = manager_acquire_image(manager, p.image_name, &image); + r = manager_acquire_image(manager, p.name, &image); if (r == -ENOENT) return sd_varlink_error(link, "io.systemd.MachineImage.NoSuchImage", NULL); if (r < 0) From 0c16936acc28a8e729374fe8e317960b17a92d5e Mon Sep 17 00:00:00 2001 From: Ivan Kruglov Date: Mon, 21 Oct 2024 13:58:30 +0200 Subject: [PATCH 8/9] machine: tests for io.systemd.MachineImage.{Clone, Remove} methods --- test/units/TEST-13-NSPAWN.machined.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/units/TEST-13-NSPAWN.machined.sh b/test/units/TEST-13-NSPAWN.machined.sh index 9a6e86cefb..7d99880bed 100755 --- a/test/units/TEST-13-NSPAWN.machined.sh +++ b/test/units/TEST-13-NSPAWN.machined.sh @@ -381,3 +381,12 @@ varlinkctl call /run/systemd/machine/io.systemd.MachineImage io.systemd.MachineI varlinkctl call /run/systemd/machine/io.systemd.MachineImage io.systemd.MachineImage.Update '{"name":"long-running-renamed", "newName": "long-running", "readOnly": false}' varlinkctl call /run/systemd/machine/io.systemd.MachineImage io.systemd.MachineImage.List '{"name":"long-running"}' varlinkctl call /run/systemd/machine/io.systemd.MachineImage io.systemd.MachineImage.List '{"name":"long-running"}' | jq '.readOnly' | grep 'false' + +# test io.systemd.MachineImage.Clone +varlinkctl call /run/systemd/machine/io.systemd.MachineImage io.systemd.MachineImage.Clone '{"name":"long-running", "newName": "long-running-cloned", "readOnly": true}' +varlinkctl call /run/systemd/machine/io.systemd.MachineImage io.systemd.MachineImage.List '{"name":"long-running-cloned"}' +varlinkctl call /run/systemd/machine/io.systemd.MachineImage io.systemd.MachineImage.List '{"name":"long-running-cloned"}' | jq '.readOnly' | grep 'true' + +# test io.systemd.MachineImage.Remove +varlinkctl call /run/systemd/machine/io.systemd.MachineImage io.systemd.MachineImage.Remove '{"name":"long-running-cloned"}' +(! varlinkctl call /run/systemd/machine/io.systemd.MachineImage io.systemd.MachineImage.List '{"name":"long-running-cloned"}') From b50fe8a0d9e2a18f55807f185e3209755d2f18b5 Mon Sep 17 00:00:00 2001 From: Ivan Kruglov Date: Tue, 22 Oct 2024 11:16:53 +0200 Subject: [PATCH 9/9] machine: remove redundant --more in TEST-13-NSPAWN.machined --- test/units/TEST-13-NSPAWN.machined.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/units/TEST-13-NSPAWN.machined.sh b/test/units/TEST-13-NSPAWN.machined.sh index 7d99880bed..1da08415df 100755 --- a/test/units/TEST-13-NSPAWN.machined.sh +++ b/test/units/TEST-13-NSPAWN.machined.sh @@ -360,12 +360,12 @@ timeout 10 bash -c "while machinectl status long-running &>/dev/null; do sleep . systemctl kill --signal=KILL systemd-nspawn@long-running.service || : (ip addr show lo | grep -q 192.168.1.100) || ip address add 192.168.1.100/24 dev lo -(! varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": ".host"}' | grep 'addresses') -varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": ".host", "acquireMetadata": "yes"}' | grep 'addresses' -(! varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": ".host"}' | grep 'OSRelease') -varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": ".host", "acquireMetadata": "yes"}' | grep 'OSRelease' -(! varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": ".host"}' | grep 'acquireUIDShift') -varlinkctl --more call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": ".host", "acquireMetadata": "yes"}' | grep 'UIDShift' +(! varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": ".host"}' | grep 'addresses') +varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": ".host", "acquireMetadata": "yes"}' | grep 'addresses' +(! varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": ".host"}' | grep 'OSRelease') +varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": ".host", "acquireMetadata": "yes"}' | grep 'OSRelease' +(! varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": ".host"}' | grep 'acquireUIDShift') +varlinkctl call /run/systemd/machine/io.systemd.Machine io.systemd.Machine.List '{"name": ".host", "acquireMetadata": "yes"}' | grep 'UIDShift' # test io.systemd.MachineImage.List varlinkctl --more call /run/systemd/machine/io.systemd.MachineImage io.systemd.MachineImage.List '{}' | grep 'long-running'