]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect: introduce new helper dissected_image_mount_and_warn() and use it everywhere
authorLennart Poettering <lennart@poettering.net>
Tue, 11 Aug 2020 13:56:12 +0000 (15:56 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 11 Aug 2020 20:26:48 +0000 (22:26 +0200)
src/dissect/dissect.c
src/nspawn/nspawn.c
src/shared/dissect-image.c
src/shared/dissect-image.h

index b2ef84c0e97d88dac2bfd9bfbf13054018462e4c..f575e1b28bce7b20718fc9100acff7107eb6d76e 100644 (file)
@@ -450,11 +450,9 @@ static int action_mount(DissectedImage *m, LoopDevice *d) {
         if (r < 0)
                 return r;
 
-        r = dissected_image_mount(m, arg_path, UID_INVALID, arg_flags);
-        if (r == -EUCLEAN)
-                return log_error_errno(r, "File system check on image failed: %m");
+        r = dissected_image_mount_and_warn(m, arg_path, UID_INVALID, arg_flags);
         if (r < 0)
-                return log_error_errno(r, "Failed to mount image: %m");
+                return r;
 
         if (di) {
                 r = decrypted_image_relinquish(di);
@@ -500,11 +498,9 @@ static int action_copy(DissectedImage *m, LoopDevice *d) {
 
         created_dir = TAKE_PTR(temp);
 
-        r = dissected_image_mount(m, created_dir, UID_INVALID, arg_flags);
-        if (r == -EUCLEAN)
-                return log_error_errno(r, "File system check on image failed: %m");
+        r = dissected_image_mount_and_warn(m, created_dir, UID_INVALID, arg_flags);
         if (r < 0)
-                return log_error_errno(r, "Failed to mount image: %m");
+                return r;
 
         mounted_dir = TAKE_PTR(created_dir);
 
index 6d6fe87ed14654427c9937f27fa6d0bbf50b956b..1b83f5ad58a2ebe6f2ce562b4b8782d330e97e20 100644 (file)
@@ -3369,14 +3369,13 @@ static int outer_child(
                  * uid shift known. That way we can mount VFAT file systems shifted to the right place right away. This
                  * makes sure ESP partitions and userns are compatible. */
 
-                r = dissected_image_mount(dissected_image, directory, arg_uid_shift,
-                                          DISSECT_IMAGE_MOUNT_ROOT_ONLY|DISSECT_IMAGE_DISCARD_ON_LOOP|
-                                          (arg_read_only ? DISSECT_IMAGE_READ_ONLY : DISSECT_IMAGE_FSCK)|
-                                          (arg_start_mode == START_BOOT ? DISSECT_IMAGE_VALIDATE_OS : 0));
-                if (r == -EUCLEAN)
-                        return log_error_errno(r, "File system check for image failed: %m");
+                r = dissected_image_mount_and_warn(
+                                dissected_image, directory, arg_uid_shift,
+                                DISSECT_IMAGE_MOUNT_ROOT_ONLY|DISSECT_IMAGE_DISCARD_ON_LOOP|
+                                (arg_read_only ? DISSECT_IMAGE_READ_ONLY : DISSECT_IMAGE_FSCK)|
+                                (arg_start_mode == START_BOOT ? DISSECT_IMAGE_VALIDATE_OS : 0));
                 if (r < 0)
-                        return log_error_errno(r, "Failed to mount image root file system: %m");
+                        return r;
         }
 
         r = determine_uid_shift(directory);
index 9a5a463b205cad64afa14b56dec2db66fb658e7f..bab587ba132137ecca92397b84aa18bac4c0519e 100644 (file)
@@ -1145,6 +1145,29 @@ int dissected_image_mount(DissectedImage *m, const char *where, uid_t uid_shift,
         return 0;
 }
 
+int dissected_image_mount_and_warn(DissectedImage *m, const char *where, uid_t uid_shift, DissectImageFlags flags) {
+        int r;
+
+        assert(m);
+        assert(where);
+
+        r = dissected_image_mount(m, where, uid_shift, flags);
+        if (r == -ENXIO)
+                return log_error_errno(r, "Not root file system found in image.");
+        if (r == -EMEDIUMTYPE)
+                return log_error_errno(r, "No suitable os-release file in image found.");
+        if (r == -EUNATCH)
+                return log_error_errno(r, "Encrypted file system discovered, but decryption not requested.");
+        if (r == -EUCLEAN)
+                return log_error_errno(r, "File system check on image failed.");
+        if (r == -EBUSY)
+                return log_error_errno(r, "File system already mounted elsewhere.");
+        if (r < 0)
+                return log_error_errno(r, "Failed to mount image: %m");
+
+        return r;
+}
+
 #if HAVE_LIBCRYPTSETUP
 typedef struct DecryptedPartition {
         struct crypt_device *device;
@@ -2031,11 +2054,9 @@ int mount_image_privately_interactively(
 
         created_dir = TAKE_PTR(temp);
 
-        r = dissected_image_mount(dissected_image, created_dir, UID_INVALID, flags);
-        if (r == -EUCLEAN)
-                return log_error_errno(r, "File system check on image failed: %m");
+        r = dissected_image_mount_and_warn(dissected_image, created_dir, UID_INVALID, flags);
         if (r < 0)
-                return log_error_errno(r, "Failed to mount image: %m");
+                return r;
 
         if (decrypted_image) {
                 r = decrypted_image_relinquish(decrypted_image);
index 3d0a191d71b2128ecdade7e2e045be8b537c6cea..4d21789e183ebf8a4b53ab69f5e0f19dd0ae35d1 100644 (file)
@@ -106,6 +106,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(DissectedImage*, dissected_image_unref);
 int dissected_image_decrypt(DissectedImage *m, const char *passphrase, const void *root_hash, size_t root_hash_size, const char *verity_data, const char *root_hash_sig_path, const void *root_hash_sig, size_t root_hash_sig_size, DissectImageFlags flags, DecryptedImage **ret);
 int dissected_image_decrypt_interactively(DissectedImage *m, const char *passphrase, const void *root_hash, size_t root_hash_size, const char *verity_data, const char *root_hash_sig_path, const void *root_hash_sig, size_t root_hash_sig_size, DissectImageFlags flags, DecryptedImage **ret);
 int dissected_image_mount(DissectedImage *m, const char *dest, uid_t uid_shift, DissectImageFlags flags);
+int dissected_image_mount_and_warn(DissectedImage *m, const char *where, uid_t uid_shift, DissectImageFlags flags);
 
 int dissected_image_acquire_metadata(DissectedImage *m);