summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-08-11 15:56:12 +0200
committerLennart Poettering <lennart@poettering.net>2020-08-11 22:26:48 +0200
commitaf187ab237827788c8361170e851ef02d9a3b1bd (patch)
tree58d30970f548a6c763ac4844f2d73fbd758ba63c
parentfa45d12c1c601a91bd85533f79158007b49971c1 (diff)
downloadsystemd-af187ab237827788c8361170e851ef02d9a3b1bd.tar.gz
dissect: introduce new helper dissected_image_mount_and_warn() and use it everywhere
-rw-r--r--src/dissect/dissect.c12
-rw-r--r--src/nspawn/nspawn.c13
-rw-r--r--src/shared/dissect-image.c29
-rw-r--r--src/shared/dissect-image.h1
4 files changed, 36 insertions, 19 deletions
diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c
index b2ef84c0e9..f575e1b28b 100644
--- a/src/dissect/dissect.c
+++ b/src/dissect/dissect.c
@@ -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);
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 6d6fe87ed1..1b83f5ad58 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -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);
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c
index 9a5a463b20..bab587ba13 100644
--- a/src/shared/dissect-image.c
+++ b/src/shared/dissect-image.c
@@ -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);
diff --git a/src/shared/dissect-image.h b/src/shared/dissect-image.h
index 3d0a191d71..4d21789e18 100644
--- a/src/shared/dissect-image.h
+++ b/src/shared/dissect-image.h
@@ -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);