From: Lennart Poettering Date: Mon, 16 Feb 2026 08:37:58 +0000 (+0100) Subject: tree-wide: move logging from varlink clients in nsresource.c/dissect-image.c into... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=116394f7ceff8cf48b3f7578bbd5150edbeaafa5;p=thirdparty%2Fsystemd.git tree-wide: move logging from varlink clients in nsresource.c/dissect-image.c into callers These calls are "library-like", hence better should only debug log on their own, not more. --- diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c index a699c007bf6..7303cfc3bd8 100644 --- a/src/dissect/dissect.c +++ b/src/dissect/dissect.c @@ -2261,7 +2261,7 @@ static int run(int argc, char *argv[]) { arg_flags, &m); if (r < 0) - return r; + return log_error_errno(r, "Failed to mount image via mountfsd: %m"); } } diff --git a/src/import/export-tar.c b/src/import/export-tar.c index e945abe8c37..81fab3714bd 100644 --- a/src/import/export-tar.c +++ b/src/import/export-tar.c @@ -365,7 +365,7 @@ int tar_export_start( _cleanup_close_ int mapped_fd = -EBADF; r = mountfsd_mount_directory_fd(directory_fd, e->userns_fd, DISSECT_IMAGE_FOREIGN_UID, &mapped_fd); if (r < 0) - return r; + return log_error_errno(r, "Failed to mount directory via mountfsd: %m"); /* Drop O_PATH */ e->tree_fd = fd_reopen(mapped_fd, O_DIRECTORY|O_CLOEXEC); diff --git a/src/import/import-tar.c b/src/import/import-tar.c index ed96e27222b..b3d3fc61040 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -259,11 +259,11 @@ static int tar_import_fork_tar(TarImport *i) { _cleanup_close_ int directory_fd = -EBADF; r = mountfsd_make_directory(d, MODE_INVALID, /* flags= */ 0, &directory_fd); if (r < 0) - return r; + return log_error_errno(r, "Failed to make directory via mountfsd: %m"); r = mountfsd_mount_directory_fd(directory_fd, i->userns_fd, DISSECT_IMAGE_FOREIGN_UID, &i->tree_fd); if (r < 0) - return r; + return log_error_errno(r, "Failed mount directory via mountfsd: %m"); } else { if (i->flags & IMPORT_BTRFS_SUBVOL) r = btrfs_subvol_make_fallback(AT_FDCWD, d, 0755); diff --git a/src/import/pull-tar.c b/src/import/pull-tar.c index b0cafd95f49..b3d80921067 100644 --- a/src/import/pull-tar.c +++ b/src/import/pull-tar.c @@ -296,18 +296,18 @@ static int tar_pull_make_local_copy(TarPull *p) { r = mountfsd_mount_directory_fd(directory_fd, p->userns_fd, DISSECT_IMAGE_FOREIGN_UID, &p->tree_fd); if (r < 0) - return r; + return log_error_errno(r, "Failed to mount directory via mountfsd: %m"); } _cleanup_close_ int directory_fd = -EBADF; r = mountfsd_make_directory(t, MODE_INVALID, /* flags= */ 0, &directory_fd); if (r < 0) - return r; + return log_error_errno(r, "Failed to make directory via mountfsd: %m"); _cleanup_close_ int copy_fd = -EBADF; r = mountfsd_mount_directory_fd(directory_fd, p->userns_fd, DISSECT_IMAGE_FOREIGN_UID, ©_fd); if (r < 0) - return r; + return log_error_errno(r, "Failed to mount directory via mountfsd: %m"); r = copy_tree_at_foreign(p->tree_fd, copy_fd, p->userns_fd); if (r < 0) @@ -614,11 +614,11 @@ static int tar_pull_job_on_open_disk_tar(PullJob *j) { _cleanup_close_ int directory_fd = -EBADF; r = mountfsd_make_directory(where, MODE_INVALID, /* flags= */ 0, &directory_fd); if (r < 0) - return r; + return log_error_errno(r, "Failed to make directory via mountfsd: %m"); r = mountfsd_mount_directory_fd(directory_fd, p->userns_fd, DISSECT_IMAGE_FOREIGN_UID, &p->tree_fd); if (r < 0) - return r; + return log_error_errno(r, "Failed to mount directory via mountfsd: %m"); } else { if (p->flags & IMPORT_BTRFS_SUBVOL) r = btrfs_subvol_make_fallback(AT_FDCWD, where, 0755); diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 623de6d9328..47300ff7e3c 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -6297,8 +6297,10 @@ static int run(int argc, char *argv[]) { userns_fd, determine_dissect_image_flags(), &mount_fd); - if (r < 0) + if (r < 0) { + log_error_errno(r, "Failed to mount directory via mountfsd: %m"); goto finish; + } } } else if (arg_image) { @@ -6448,8 +6450,10 @@ static int run(int argc, char *argv[]) { &arg_verity_settings, dissect_image_flags, &dissected_image); - if (r < 0) + if (r < 0) { + log_error_errno(r, "Failed to mount image via mountfsd: %m"); goto finish; + } } /* Now that we mounted the image, let's try to remove it again, if it is ephemeral */ @@ -6474,8 +6478,10 @@ static int run(int argc, char *argv[]) { r = mstack_load(arg_mstack, /* dir_fd= */ -EBADF, &mstack); - if (r < 0) + if (r < 0) { + log_error_errno(r, "Failed to load .mstack/ directory '%s': %m", arg_mstack); goto finish; + } r = mstack_open_images( mstack, diff --git a/src/portable/portable.c b/src/portable/portable.c index 403a05005ce..ed249fed9bc 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -490,7 +490,7 @@ static int portable_extract_by_path( _cleanup_close_ int mfd = -EBADF; r = mountfsd_mount_directory_fd(rfd, userns_fd, DISSECT_IMAGE_FOREIGN_UID, &mfd); if (r < 0) - return log_debug_errno(r, "Failed to open '%s' via mountfsd: %m", path); + return r; _cleanup_close_pair_ int seq[2] = EBADF_PAIR; if (socketpair(AF_UNIX, SOCK_SEQPACKET|SOCK_CLOEXEC, 0, seq) < 0) diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 41569037744..0c0274fbc52 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -5173,32 +5173,32 @@ int mountfsd_mount_image_fd( image_fd = fd_reopen_condition(image_fd, O_CLOEXEC|O_NOCTTY|O_NONBLOCK|(FLAGS_SET(flags, DISSECT_IMAGE_MOUNT_READ_ONLY) ? O_RDONLY : O_RDWR), O_PATH, &reopened_fd); if (image_fd < 0) - return log_error_errno(image_fd, "Failed to reopen fd: %m"); + return log_debug_errno(image_fd, "Failed to reopen fd: %m"); r = sd_varlink_push_dup_fd(vl, image_fd); if (r < 0) - return log_error_errno(r, "Failed to push image fd into varlink connection: %m"); + return log_debug_errno(r, "Failed to push image fd into varlink connection: %m"); if (userns_fd >= 0) { r = sd_varlink_push_dup_fd(vl, userns_fd); if (r < 0) - return log_error_errno(r, "Failed to push image fd into varlink connection: %m"); + return log_debug_errno(r, "Failed to push image fd into varlink connection: %m"); } if (image_policy) { r = image_policy_to_string(image_policy, /* simplify= */ false, &ps); if (r < 0) - return log_error_errno(r, "Failed to format image policy to string: %m"); + return log_debug_errno(r, "Failed to format image policy to string: %m"); } if (verity && verity->data_path) { verity_data_fd = open(verity->data_path, O_RDONLY|O_CLOEXEC); if (verity_data_fd < 0) - return log_error_errno(errno, "Failed to open verity data file '%s': %m", verity->data_path); + return log_debug_errno(errno, "Failed to open verity data file '%s': %m", verity->data_path); r = sd_varlink_push_dup_fd(vl, verity_data_fd); if (r < 0) - return log_error_errno(r, "Failed to push verity data fd into varlink connection: %m"); + return log_debug_errno(r, "Failed to push verity data fd into varlink connection: %m"); } _cleanup_(sd_json_variant_unrefp) sd_json_variant *mount_options = NULL; @@ -5220,7 +5220,7 @@ int mountfsd_mount_image_fd( /* ret_values= */ NULL, &filtered); if (r < 0) - return log_error_errno(r, "Failed to filter mount options: %m"); + return log_debug_errno(r, "Failed to filter mount options: %m"); if (isempty(filtered)) continue; @@ -5230,7 +5230,7 @@ int mountfsd_mount_image_fd( &mount_options, SD_JSON_BUILD_PAIR_STRING(partition_designator_to_string(i), filtered ?: o)); if (r < 0) - return log_error_errno(r, "Failed to build mount options array: %m"); + return log_debug_errno(r, "Failed to build mount options array: %m"); } sd_json_variant *reply = NULL; @@ -5256,7 +5256,7 @@ int mountfsd_mount_image_fd( r = sd_json_dispatch(reply, dispatch_table, SD_JSON_ALLOW_EXTENSIONS, &p); if (r < 0) - return log_error_errno(r, "Failed to parse MountImage() reply: %m"); + return log_debug_errno(r, "Failed to parse MountImage() reply: %m"); log_debug("Effective image policy: %s", p.image_policy); @@ -5289,7 +5289,7 @@ int mountfsd_mount_image_fd( r = sd_json_dispatch(i, partition_dispatch_table, SD_JSON_ALLOW_EXTENSIONS, &pp); if (r < 0) - return log_error_errno(r, "Failed to parse partition data: %m"); + return log_debug_errno(r, "Failed to parse partition data: %m"); if (pp.fsmount_fd_idx != UINT_MAX) { fsmount_fd = sd_varlink_take_fd(vl, pp.fsmount_fd_idx); @@ -5302,11 +5302,11 @@ int mountfsd_mount_image_fd( if (!di) { r = dissected_image_new(/* path= */ NULL, &di); if (r < 0) - return log_error_errno(r, "Failed to allocated new dissected image structure: %m"); + return log_debug_errno(r, "Failed to allocated new dissected image structure: %m"); } if (di->partitions[pp.designator].found) - return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "Duplicate partition data for '%s'.", partition_designator_to_string(pp.designator)); + return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG), "Duplicate partition data for '%s'.", partition_designator_to_string(pp.designator)); di->partitions[pp.designator] = (DissectedPartition) { .found = true, @@ -5352,7 +5352,7 @@ int mountfsd_mount_image( _cleanup_close_ int image_fd = open(path, O_RDONLY|O_CLOEXEC); if (image_fd < 0) - return log_error_errno(errno, "Failed to open '%s': %m", path); + return log_debug_errno(errno, "Failed to open '%s': %m", path); _cleanup_(dissected_image_unrefp) DissectedImage *di = NULL; r = mountfsd_mount_image_fd(image_fd, userns_fd, options, image_policy, verity, flags, &di); @@ -5398,12 +5398,12 @@ int mountfsd_mount_directory_fd( r = sd_varlink_push_dup_fd(vl, directory_fd); if (r < 0) - return log_error_errno(r, "Failed to push directory fd into varlink connection: %m"); + return log_debug_errno(r, "Failed to push directory fd into varlink connection: %m"); if (userns_fd >= 0) { r = sd_varlink_push_dup_fd(vl, userns_fd); if (r < 0) - return log_error_errno(r, "Failed to push user namespace fd into varlink connection: %m"); + return log_debug_errno(r, "Failed to push user namespace fd into varlink connection: %m"); } sd_json_variant *reply = NULL; @@ -5430,11 +5430,11 @@ int mountfsd_mount_directory_fd( unsigned fsmount_fd_idx = UINT_MAX; r = sd_json_dispatch(reply, dispatch_table, SD_JSON_ALLOW_EXTENSIONS, &fsmount_fd_idx); if (r < 0) - return log_error_errno(r, "Failed to parse MountImage() reply: %m"); + return log_debug_errno(r, "Failed to parse MountImage() reply: %m"); _cleanup_close_ int fsmount_fd = sd_varlink_take_fd(vl, fsmount_fd_idx); if (fsmount_fd < 0) - return log_error_errno(fsmount_fd, "Failed to take mount fd from Varlink connection: %m"); + return log_debug_errno(fsmount_fd, "Failed to take mount fd from Varlink connection: %m"); *ret_mount_fd = TAKE_FD(fsmount_fd); return 0; @@ -5451,7 +5451,7 @@ int mountfsd_mount_directory( _cleanup_close_ int directory_fd = open(path, O_DIRECTORY|O_RDONLY|O_CLOEXEC|O_PATH); if (directory_fd < 0) - return log_error_errno(errno, "Failed to open '%s': %m", path); + return log_debug_errno(errno, "Failed to open '%s': %m", path); return mountfsd_mount_directory_fd(directory_fd, userns_fd, flags, ret_mount_fd); } @@ -5483,7 +5483,7 @@ int mountfsd_make_directory_fd( r = sd_varlink_push_dup_fd(vl, parent_fd); if (r < 0) - return log_error_errno(r, "Failed to push parent fd into varlink connection: %m"); + return log_debug_errno(r, "Failed to push parent fd into varlink connection: %m"); sd_json_variant *reply = NULL; const char *error_id = NULL; @@ -5507,11 +5507,11 @@ int mountfsd_make_directory_fd( unsigned directory_fd_idx = UINT_MAX; r = sd_json_dispatch(reply, dispatch_table, SD_JSON_ALLOW_EXTENSIONS, &directory_fd_idx); if (r < 0) - return log_error_errno(r, "Failed to parse MountImage() reply: %m"); + return log_debug_errno(r, "Failed to parse MountImage() reply: %m"); _cleanup_close_ int directory_fd = sd_varlink_take_fd(vl, directory_fd_idx); if (directory_fd < 0) - return log_error_errno(directory_fd, "Failed to take directory fd from Varlink connection: %m"); + return log_debug_errno(directory_fd, "Failed to take directory fd from Varlink connection: %m"); if (ret_directory_fd) *ret_directory_fd = TAKE_FD(directory_fd); @@ -5529,16 +5529,16 @@ int mountfsd_make_directory( _cleanup_free_ char *parent = NULL; r = path_extract_directory(path, &parent); if (r < 0) - return log_error_errno(r, "Failed to extract parent directory from '%s': %m", path); + return log_debug_errno(r, "Failed to extract parent directory from '%s': %m", path); _cleanup_free_ char *dirname = NULL; r = path_extract_filename(path, &dirname); if (r < 0) - return log_error_errno(r, "Failed to extract directory name from '%s': %m", path); + return log_debug_errno(r, "Failed to extract directory name from '%s': %m", path); _cleanup_close_ int fd = open(parent, O_DIRECTORY|O_CLOEXEC); if (fd < 0) - return log_error_errno(r, "Failed to open '%s': %m", parent); + return log_debug_errno(r, "Failed to open '%s': %m", parent); return mountfsd_make_directory_fd(fd, dirname, mode, flags, ret_directory_fd); } diff --git a/src/shared/nsresource.c b/src/shared/nsresource.c index 31d96bad7cc..651d9bdf4d6 100644 --- a/src/shared/nsresource.c +++ b/src/shared/nsresource.c @@ -195,11 +195,11 @@ int nsresource_add_mount(int userns_fd, int mount_fd) { userns_fd_idx = sd_varlink_push_dup_fd(vl, userns_fd); if (userns_fd_idx < 0) - return log_error_errno(userns_fd_idx, "Failed to push userns fd into varlink connection: %m"); + return log_debug_errno(userns_fd_idx, "Failed to push userns fd into varlink connection: %m"); mount_fd_idx = sd_varlink_push_dup_fd(vl, mount_fd); if (mount_fd_idx < 0) - return log_error_errno(mount_fd_idx, "Failed to push mount fd into varlink connection: %m"); + return log_debug_errno(mount_fd_idx, "Failed to push mount fd into varlink connection: %m"); sd_json_variant *reply = NULL; r = sd_varlink_callbo( @@ -210,13 +210,13 @@ int nsresource_add_mount(int userns_fd, int mount_fd) { SD_JSON_BUILD_PAIR_UNSIGNED("userNamespaceFileDescriptor", userns_fd_idx), SD_JSON_BUILD_PAIR_UNSIGNED("mountFileDescriptor", mount_fd_idx)); if (r < 0) - return log_error_errno(r, "Failed to call AddMountToUserNamespace() varlink call: %m"); + return log_debug_errno(r, "Failed to call AddMountToUserNamespace() varlink call: %m"); if (streq_ptr(error_id, "io.systemd.NamespaceResource.UserNamespaceNotRegistered")) { - log_notice("User namespace has not been allocated via namespace resource registry, not adding mount to registration."); + log_debug("User namespace has not been allocated via namespace resource registry, not adding mount to registration."); return 0; } if (error_id) - return log_error_errno(sd_varlink_error_to_errno(error_id, reply), "Failed to mount image: %s", error_id); + return log_debug_errno(sd_varlink_error_to_errno(error_id, reply), "Failed to mount image: %s", error_id); return 1; } @@ -264,7 +264,7 @@ int nsresource_add_cgroup(int userns_fd, int cgroup_fd) { if (r < 0) return log_debug_errno(r, "Failed to call AddControlGroupToUserNamespace() varlink call: %m"); if (streq_ptr(error_id, "io.systemd.NamespaceResource.UserNamespaceNotRegistered")) { - log_notice("User namespace has not been allocated via namespace resource registry, not adding cgroup to registration."); + log_debug("User namespace has not been allocated via namespace resource registry, not adding cgroup to registration."); return 0; } if (error_id) @@ -343,7 +343,7 @@ int nsresource_add_netif_veth( if (r < 0) return log_debug_errno(r, "Failed to call AddNetworkToUserNamespace() varlink call: %m"); if (streq_ptr(error_id, "io.systemd.NamespaceResource.UserNamespaceNotRegistered")) { - log_notice("User namespace has not been allocated via namespace resource registry, not adding network to registration."); + log_debug("User namespace has not been allocated via namespace resource registry, not adding network to registration."); return 0; } if (error_id)