]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
import: merge PullFlags enum into ImportFlags
authorLennart Poettering <lennart@poettering.net>
Thu, 22 Feb 2024 12:32:35 +0000 (13:32 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 1 Mar 2024 21:25:42 +0000 (22:25 +0100)
The two enums are mostly the same, the former is just an extension of
the latter. Let's merge them, to simplify things. This is particularly
useful as we then can reuse this systematically as D-Bus method call
flags too, in a generic fashion that works for both imports and pulls
the same.

Pretty much just renaming of flags.

src/import/import-common.h
src/import/pull-common.c
src/import/pull-common.h
src/import/pull-raw.c
src/import/pull-raw.h
src/import/pull-tar.c
src/import/pull-tar.h
src/import/pull.c

index 97fc16d1b9d32c2bf61e9602a155af0fa93c11f2..edde7fd8bd23cd8db7e01199dbc00a5b8e55d108 100644 (file)
@@ -6,16 +6,27 @@
 #include "sd-event.h"
 
 typedef enum ImportFlags {
-        IMPORT_FORCE          = 1 << 0, /* replace existing image */
-        IMPORT_READ_ONLY      = 1 << 1, /* make generated image read-only */
-        IMPORT_BTRFS_SUBVOL   = 1 << 2, /* tar: preferably create images as btrfs subvols */
-        IMPORT_BTRFS_QUOTA    = 1 << 3, /* tar: set up btrfs quota for new subvolume as child of parent subvolume */
-        IMPORT_CONVERT_QCOW2  = 1 << 4, /* raw: if we detect a qcow2 image, unpack it */
-        IMPORT_DIRECT         = 1 << 5, /* import without rename games */
-        IMPORT_SYNC           = 1 << 6, /* fsync() right before we are done */
-
-        IMPORT_FLAGS_MASK_TAR = IMPORT_FORCE|IMPORT_READ_ONLY|IMPORT_BTRFS_SUBVOL|IMPORT_BTRFS_QUOTA|IMPORT_DIRECT|IMPORT_SYNC,
-        IMPORT_FLAGS_MASK_RAW = IMPORT_FORCE|IMPORT_READ_ONLY|IMPORT_CONVERT_QCOW2|IMPORT_DIRECT|IMPORT_SYNC,
+        IMPORT_FORCE                   = 1 <<  0, /* replace existing image */
+        IMPORT_READ_ONLY               = 1 <<  1, /* make generated image read-only */
+        IMPORT_BTRFS_SUBVOL            = 1 <<  2, /* tar: preferably create images as btrfs subvols */
+        IMPORT_BTRFS_QUOTA             = 1 <<  3, /* tar: set up btrfs quota for new subvolume as child of parent subvolume */
+        IMPORT_CONVERT_QCOW2           = 1 <<  4, /* raw: if we detect a qcow2 image, unpack it */
+        IMPORT_DIRECT                  = 1 <<  5, /* import without rename games */
+        IMPORT_SYNC                    = 1 <<  6, /* fsync() right before we are done */
+
+        /* When pulling these flags are defined too */
+        IMPORT_PULL_SETTINGS           = 1 <<  7, /* download .nspawn settings file */
+        IMPORT_PULL_ROOTHASH           = 1 <<  8, /* only for raw: download .roothash file for verity */
+        IMPORT_PULL_ROOTHASH_SIGNATURE = 1 <<  9, /* only for raw: download .roothash.p7s file for verity */
+        IMPORT_PULL_VERITY             = 1 << 10, /* only for raw: download .verity file for verity */
+
+        /* The supported flags for the tar and the raw importing */
+        IMPORT_FLAGS_MASK_TAR          = IMPORT_FORCE|IMPORT_READ_ONLY|IMPORT_BTRFS_SUBVOL|IMPORT_BTRFS_QUOTA|IMPORT_DIRECT|IMPORT_SYNC,
+        IMPORT_FLAGS_MASK_RAW          = IMPORT_FORCE|IMPORT_READ_ONLY|IMPORT_CONVERT_QCOW2|IMPORT_DIRECT|IMPORT_SYNC,
+
+        /* The supported flags for the tar and the raw pulling */
+        IMPORT_PULL_FLAGS_MASK_TAR     = IMPORT_FLAGS_MASK_TAR|IMPORT_PULL_SETTINGS,
+        IMPORT_PULL_FLAGS_MASK_RAW     = IMPORT_FLAGS_MASK_RAW|IMPORT_PULL_SETTINGS|IMPORT_PULL_ROOTHASH|IMPORT_PULL_ROOTHASH_SIGNATURE|IMPORT_PULL_VERITY,
 } ImportFlags;
 
 int import_fork_tar_c(const char *path, pid_t *ret);
index 37387a76e024572d1e7d56ef5955c5a46190f0b0..783905776956f977c6f4b6d34686a543bd0a6065 100644 (file)
@@ -643,9 +643,9 @@ int pull_job_restart_with_sha256sum(PullJob *j, char **ret) {
         return 1;
 }
 
-bool pull_validate_local(const char *name, PullFlags flags) {
+bool pull_validate_local(const char *name, ImportFlags flags) {
 
-        if (FLAGS_SET(flags, PULL_DIRECT))
+        if (FLAGS_SET(flags, IMPORT_DIRECT))
                 return path_is_valid(name);
 
         return hostname_is_valid(name, 0);
index 475613a9076f2c0c99806be2c0c41643ae177c6e..82e25267e3f374001a5c981700840e0e9be8aea7 100644 (file)
@@ -3,27 +3,10 @@
 
 #include <stdbool.h>
 
+#include "import-common.h"
 #include "import-util.h"
 #include "pull-job.h"
 
-typedef enum PullFlags {
-        PULL_FORCE              = 1 << 0, /* replace existing image */
-        PULL_READ_ONLY          = 1 << 1, /* make generated image read-only */
-        PULL_SETTINGS           = 1 << 2, /* download .nspawn settings file */
-        PULL_ROOTHASH           = 1 << 3, /* only for raw: download .roothash file for verity */
-        PULL_ROOTHASH_SIGNATURE = 1 << 4, /* only for raw: download .roothash.p7s file for verity */
-        PULL_VERITY             = 1 << 5, /* only for raw: download .verity file for verity */
-        PULL_BTRFS_SUBVOL       = 1 << 6, /* tar: preferably create images as btrfs subvols */
-        PULL_BTRFS_QUOTA        = 1 << 7, /* tar: set up btrfs quota for new subvolume as child of parent subvolume */
-        PULL_CONVERT_QCOW2      = 1 << 8, /* raw: if we detect a qcow2 image, unpack it */
-        PULL_DIRECT             = 1 << 9, /* download without rename games */
-        PULL_SYNC               = 1 << 10, /* fsync() right before we are done */
-
-        /* The supported flags for the tar and the raw pulling */
-        PULL_FLAGS_MASK_TAR     = PULL_FORCE|PULL_READ_ONLY|PULL_SETTINGS|PULL_BTRFS_SUBVOL|PULL_BTRFS_QUOTA|PULL_DIRECT|PULL_SYNC,
-        PULL_FLAGS_MASK_RAW     = PULL_FORCE|PULL_READ_ONLY|PULL_SETTINGS|PULL_ROOTHASH|PULL_ROOTHASH_SIGNATURE|PULL_VERITY|PULL_CONVERT_QCOW2|PULL_DIRECT|PULL_SYNC,
-} PullFlags;
-
 int pull_find_old_etags(const char *url, const char *root, int dt, const char *prefix, const char *suffix, char ***etags);
 
 int pull_make_path(const char *url, const char *etag, const char *image_root, const char *prefix, const char *suffix, char **ret);
@@ -44,6 +27,6 @@ int verification_style_from_url(const char *url, VerificationStyle *style);
 
 int pull_job_restart_with_sha256sum(PullJob *job, char **ret);
 
-bool pull_validate_local(const char *name, PullFlags flags);
+bool pull_validate_local(const char *name, ImportFlags flags);
 
 int pull_url_needs_checksum(const char *url);
index dc5434cd2d520ade31415423b5d1e67598324381..ebe479fb802874d007a02a3f90631e18fea1fd46 100644 (file)
@@ -42,7 +42,7 @@ struct RawPull {
         sd_event *event;
         CurlGlue *glue;
 
-        PullFlags flags;
+        ImportFlags flags;
         ImportVerify verify;
         char *image_root;
 
@@ -244,9 +244,9 @@ static int raw_pull_maybe_convert_qcow2(RawPull *i) {
 
         assert(i);
         assert(i->raw_job);
-        assert(!FLAGS_SET(i->flags, PULL_DIRECT));
+        assert(!FLAGS_SET(i->flags, IMPORT_DIRECT));
 
-        if (!FLAGS_SET(i->flags, PULL_CONVERT_QCOW2))
+        if (!FLAGS_SET(i->flags, IMPORT_CONVERT_QCOW2))
                 return 0;
 
         assert(i->final_path);
@@ -328,8 +328,8 @@ static int raw_pull_copy_auxiliary_file(
                         local,
                         0644,
                         COPY_REFLINK |
-                        (FLAGS_SET(i->flags, PULL_FORCE) ? COPY_REPLACE : 0) |
-                        (FLAGS_SET(i->flags, PULL_SYNC) ? COPY_FSYNC_FULL : 0));
+                        (FLAGS_SET(i->flags, IMPORT_FORCE) ? COPY_REPLACE : 0) |
+                        (FLAGS_SET(i->flags, IMPORT_SYNC) ? COPY_FSYNC_FULL : 0));
         if (r == -EEXIST)
                 log_warning_errno(r, "File %s already exists, not replacing.", local);
         else if (r == -ENOENT)
@@ -351,7 +351,7 @@ static int raw_pull_make_local_copy(RawPull *i) {
 
         assert(i);
         assert(i->raw_job);
-        assert(!FLAGS_SET(i->flags, PULL_DIRECT));
+        assert(!FLAGS_SET(i->flags, IMPORT_DIRECT));
 
         if (!i->local)
                 return 0;
@@ -401,9 +401,9 @@ static int raw_pull_make_local_copy(RawPull *i) {
 
         r = install_file(AT_FDCWD, tp,
                          AT_FDCWD, p,
-                         (i->flags & PULL_FORCE ? INSTALL_REPLACE : 0) |
-                         (i->flags & PULL_READ_ONLY ? INSTALL_READ_ONLY : 0) |
-                         (i->flags & PULL_SYNC ? INSTALL_FSYNC_FULL : 0));
+                         (i->flags & IMPORT_FORCE ? INSTALL_REPLACE : 0) |
+                         (i->flags & IMPORT_READ_ONLY ? INSTALL_READ_ONLY : 0) |
+                         (i->flags & IMPORT_SYNC ? INSTALL_FSYNC_FULL : 0));
         if (r < 0)
                 return log_error_errno(errno, "Failed to move local image into place '%s': %m", p);
 
@@ -411,25 +411,25 @@ static int raw_pull_make_local_copy(RawPull *i) {
 
         log_info("Created new local image '%s'.", i->local);
 
-        if (FLAGS_SET(i->flags, PULL_SETTINGS)) {
+        if (FLAGS_SET(i->flags, IMPORT_PULL_SETTINGS)) {
                 r = raw_pull_copy_auxiliary_file(i, ".nspawn", &i->settings_path);
                 if (r < 0)
                         return r;
         }
 
-        if (FLAGS_SET(i->flags, PULL_ROOTHASH)) {
+        if (FLAGS_SET(i->flags, IMPORT_PULL_ROOTHASH)) {
                 r = raw_pull_copy_auxiliary_file(i, ".roothash", &i->roothash_path);
                 if (r < 0)
                         return r;
         }
 
-        if (FLAGS_SET(i->flags, PULL_ROOTHASH_SIGNATURE)) {
+        if (FLAGS_SET(i->flags, IMPORT_PULL_ROOTHASH_SIGNATURE)) {
                 r = raw_pull_copy_auxiliary_file(i, ".roothash.p7s", &i->roothash_signature_path);
                 if (r < 0)
                         return r;
         }
 
-        if (FLAGS_SET(i->flags, PULL_VERITY)) {
+        if (FLAGS_SET(i->flags, IMPORT_PULL_VERITY)) {
                 r = raw_pull_copy_auxiliary_file(i, ".verity", &i->verity_path);
                 if (r < 0)
                         return r;
@@ -485,7 +485,7 @@ static int raw_pull_rename_auxiliary_file(
                         AT_FDCWD, *temp_path,
                         AT_FDCWD, *path,
                         INSTALL_READ_ONLY|
-                        (i->flags & PULL_SYNC ? INSTALL_FSYNC_FULL : 0));
+                        (i->flags & IMPORT_SYNC ? INSTALL_FSYNC_FULL : 0));
         if (r < 0)
                 return log_error_errno(r, "Failed to move '%s' into place: %m", *path);
 
@@ -588,7 +588,7 @@ static void raw_pull_job_on_finished(PullJob *j) {
                         goto finish;
         }
 
-        if (i->flags & PULL_DIRECT) {
+        if (i->flags & IMPORT_DIRECT) {
                 assert(!i->settings_job);
                 assert(!i->roothash_job);
                 assert(!i->roothash_signature_job);
@@ -599,8 +599,8 @@ static void raw_pull_job_on_finished(PullJob *j) {
                 if (i->local) {
                         r = install_file(AT_FDCWD, i->local,
                                          AT_FDCWD, NULL,
-                                         ((i->flags & PULL_READ_ONLY) && i->offset == UINT64_MAX ? INSTALL_READ_ONLY : 0) |
-                                         (i->flags & PULL_SYNC ? INSTALL_FSYNC_FULL : 0));
+                                         ((i->flags & IMPORT_READ_ONLY) && i->offset == UINT64_MAX ? INSTALL_READ_ONLY : 0) |
+                                         (i->flags & IMPORT_SYNC ? INSTALL_FSYNC_FULL : 0));
                         if (r < 0) {
                                 log_error_errno(r, "Failed to finalize raw file to '%s': %m", i->local);
                                 goto finish;
@@ -628,7 +628,7 @@ static void raw_pull_job_on_finished(PullJob *j) {
                         r = install_file(AT_FDCWD, i->temp_path,
                                          AT_FDCWD, i->final_path,
                                          INSTALL_READ_ONLY|
-                                         (i->flags & PULL_SYNC ? INSTALL_FSYNC_FULL : 0));
+                                         (i->flags & IMPORT_SYNC ? INSTALL_FSYNC_FULL : 0));
                         if (r < 0) {
                                 log_error_errno(r, "Failed to move raw file to '%s': %m", i->final_path);
                                 goto finish;
@@ -694,7 +694,7 @@ static int raw_pull_job_on_open_disk_generic(
         assert(extra);
         assert(temp_path);
 
-        assert(!FLAGS_SET(i->flags, PULL_DIRECT));
+        assert(!FLAGS_SET(i->flags, IMPORT_DIRECT));
 
         if (!*temp_path) {
                 r = tempfn_random_child(i->image_root, extra, temp_path);
@@ -722,7 +722,7 @@ static int raw_pull_job_on_open_disk_raw(PullJob *j) {
         assert(i->raw_job == j);
         assert(j->disk_fd < 0);
 
-        if (i->flags & PULL_DIRECT) {
+        if (i->flags & IMPORT_DIRECT) {
 
                 if (!i->local) { /* If no local name specified, the pull job will write its data to stdout */
                         j->disk_fd = STDOUT_FILENO;
@@ -816,7 +816,7 @@ int raw_pull_start(
                 const char *local,
                 uint64_t offset,
                 uint64_t size_max,
-                PullFlags flags,
+                ImportFlags flags,
                 ImportVerify verify,
                 const char *checksum) {
 
@@ -827,10 +827,10 @@ int raw_pull_start(
         assert(verify == _IMPORT_VERIFY_INVALID || verify < _IMPORT_VERIFY_MAX);
         assert(verify == _IMPORT_VERIFY_INVALID || verify >= 0);
         assert((verify < 0) || !checksum);
-        assert(!(flags & ~PULL_FLAGS_MASK_RAW));
-        assert(offset == UINT64_MAX || FLAGS_SET(flags, PULL_DIRECT));
-        assert(!(flags & (PULL_SETTINGS|PULL_ROOTHASH|PULL_ROOTHASH_SIGNATURE|PULL_VERITY)) || !(flags & PULL_DIRECT));
-        assert(!(flags & (PULL_SETTINGS|PULL_ROOTHASH|PULL_ROOTHASH_SIGNATURE|PULL_VERITY)) || !checksum);
+        assert(!(flags & ~IMPORT_PULL_FLAGS_MASK_RAW));
+        assert(offset == UINT64_MAX || FLAGS_SET(flags, IMPORT_DIRECT));
+        assert(!(flags & (IMPORT_PULL_SETTINGS|IMPORT_PULL_ROOTHASH|IMPORT_PULL_ROOTHASH_SIGNATURE|IMPORT_PULL_VERITY)) || !(flags & IMPORT_DIRECT));
+        assert(!(flags & (IMPORT_PULL_SETTINGS|IMPORT_PULL_ROOTHASH|IMPORT_PULL_ROOTHASH_SIGNATURE|IMPORT_PULL_VERITY)) || !checksum);
 
         if (!http_url_is_valid(url) && !file_url_is_valid(url))
                 return -EINVAL;
@@ -880,7 +880,7 @@ int raw_pull_start(
         if (offset != UINT64_MAX)
                 i->raw_job->offset = i->offset = offset;
 
-        if (!FLAGS_SET(flags, PULL_DIRECT)) {
+        if (!FLAGS_SET(flags, IMPORT_DIRECT)) {
                 r = pull_find_old_etags(url, i->image_root, DT_REG, ".raw-", ".raw", &i->raw_job->old_etags);
                 if (r < 0)
                         return r;
@@ -898,7 +898,7 @@ int raw_pull_start(
         if (r < 0)
                 return r;
 
-        if (FLAGS_SET(flags, PULL_SETTINGS)) {
+        if (FLAGS_SET(flags, IMPORT_PULL_SETTINGS)) {
                 r = pull_make_auxiliary_job(
                                 &i->settings_job,
                                 url,
@@ -913,7 +913,7 @@ int raw_pull_start(
                         return r;
         }
 
-        if (FLAGS_SET(flags, PULL_ROOTHASH)) {
+        if (FLAGS_SET(flags, IMPORT_PULL_ROOTHASH)) {
                 r = pull_make_auxiliary_job(
                                 &i->roothash_job,
                                 url,
@@ -928,7 +928,7 @@ int raw_pull_start(
                         return r;
         }
 
-        if (FLAGS_SET(flags, PULL_ROOTHASH_SIGNATURE)) {
+        if (FLAGS_SET(flags, IMPORT_PULL_ROOTHASH_SIGNATURE)) {
                 r = pull_make_auxiliary_job(
                                 &i->roothash_signature_job,
                                 url,
@@ -943,7 +943,7 @@ int raw_pull_start(
                         return r;
         }
 
-        if (FLAGS_SET(flags, PULL_VERITY)) {
+        if (FLAGS_SET(flags, IMPORT_PULL_VERITY)) {
                 r = pull_make_auxiliary_job(
                                 &i->verity_job,
                                 url,
@@ -972,7 +972,7 @@ int raw_pull_start(
                         continue;
 
                 j->on_progress = raw_pull_job_on_progress;
-                j->sync = FLAGS_SET(flags, PULL_SYNC);
+                j->sync = FLAGS_SET(flags, IMPORT_SYNC);
 
                 r = pull_job_begin(j);
                 if (r < 0)
index b39e4e257cd4a9008277a2a3ad83a20f556069fd..e50ba326f65f2b132237b7dce5489c6c035e4d72 100644 (file)
@@ -16,4 +16,4 @@ RawPull* raw_pull_unref(RawPull *pull);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(RawPull*, raw_pull_unref);
 
-int raw_pull_start(RawPull *pull, const char *url, const char *local, uint64_t offset, uint64_t size_max, PullFlags flags, ImportVerify verify, const char *checksum);
+int raw_pull_start(RawPull *pull, const char *url, const char *local, uint64_t offset, uint64_t size_max, ImportFlags flags, ImportVerify verify, const char *checksum);
index a0314495605a05b7f32618e63b3f8412c12d1220..99d8ff0553ccd766a3e7590a96d63e8860d41364 100644 (file)
@@ -41,7 +41,7 @@ struct TarPull {
         sd_event *event;
         CurlGlue *glue;
 
-        PullFlags flags;
+        ImportFlags flags;
         ImportVerify verify;
         char *image_root;
 
@@ -238,11 +238,11 @@ static int tar_pull_make_local_copy(TarPull *i) {
         if (r < 0)
                 return log_error_errno(r, "Failed to generate temporary filename for %s: %m", p);
 
-        if (i->flags & PULL_BTRFS_SUBVOL)
+        if (i->flags & IMPORT_BTRFS_SUBVOL)
                 r = btrfs_subvol_snapshot_at(
                                 AT_FDCWD, i->final_path,
                                 AT_FDCWD, t,
-                                (i->flags & PULL_BTRFS_QUOTA ? BTRFS_SNAPSHOT_QUOTA : 0)|
+                                (i->flags & IMPORT_BTRFS_QUOTA ? BTRFS_SNAPSHOT_QUOTA : 0)|
                                 BTRFS_SNAPSHOT_FALLBACK_COPY|
                                 BTRFS_SNAPSHOT_FALLBACK_DIRECTORY|
                                 BTRFS_SNAPSHOT_RECURSIVE);
@@ -253,9 +253,9 @@ static int tar_pull_make_local_copy(TarPull *i) {
 
         r = install_file(AT_FDCWD, t,
                          AT_FDCWD, p,
-                         (i->flags & PULL_FORCE ? INSTALL_REPLACE : 0) |
-                         (i->flags & PULL_READ_ONLY ? INSTALL_READ_ONLY : 0) |
-                         (i->flags & PULL_SYNC ? INSTALL_SYNCFS : 0));
+                         (i->flags & IMPORT_FORCE ? INSTALL_REPLACE : 0) |
+                         (i->flags & IMPORT_READ_ONLY ? INSTALL_READ_ONLY : 0) |
+                         (i->flags & IMPORT_SYNC ? INSTALL_SYNCFS : 0));
         if (r < 0)
                 return log_error_errno(r, "Failed to install local image '%s': %m", p);
 
@@ -263,7 +263,7 @@ static int tar_pull_make_local_copy(TarPull *i) {
 
         log_info("Created new local image '%s'.", i->local);
 
-        if (FLAGS_SET(i->flags, PULL_SETTINGS)) {
+        if (FLAGS_SET(i->flags, IMPORT_PULL_SETTINGS)) {
                 const char *local_settings;
                 assert(i->settings_job);
 
@@ -278,8 +278,8 @@ static int tar_pull_make_local_copy(TarPull *i) {
                                 local_settings,
                                 0664,
                                 COPY_REFLINK |
-                                (FLAGS_SET(i->flags, PULL_FORCE) ? COPY_REPLACE : 0) |
-                                (FLAGS_SET(i->flags, PULL_SYNC) ? COPY_FSYNC_FULL : 0));
+                                (FLAGS_SET(i->flags, IMPORT_FORCE) ? COPY_REPLACE : 0) |
+                                (FLAGS_SET(i->flags, IMPORT_SYNC) ? COPY_FSYNC_FULL : 0));
                 if (r == -EEXIST)
                         log_warning_errno(r, "Settings file %s already exists, not replacing.", local_settings);
                 else if (r == -ENOENT)
@@ -394,7 +394,7 @@ static void tar_pull_job_on_finished(PullJob *j) {
                         goto finish;
         }
 
-        if (i->flags & PULL_DIRECT) {
+        if (i->flags & IMPORT_DIRECT) {
                 assert(!i->settings_job);
                 assert(i->local);
                 assert(!i->temp_path);
@@ -408,8 +408,8 @@ static void tar_pull_job_on_finished(PullJob *j) {
                 r = install_file(
                                 AT_FDCWD, i->local,
                                 AT_FDCWD, NULL,
-                                (i->flags & PULL_READ_ONLY) ? INSTALL_READ_ONLY : 0 |
-                                (i->flags & PULL_SYNC ? INSTALL_SYNCFS : 0));
+                                (i->flags & IMPORT_READ_ONLY) ? INSTALL_READ_ONLY : 0 |
+                                (i->flags & IMPORT_SYNC ? INSTALL_SYNCFS : 0));
                 if (r < 0) {
                         log_error_errno(r, "Failed to finalize '%s': %m", i->local);
                         goto finish;
@@ -435,7 +435,7 @@ static void tar_pull_job_on_finished(PullJob *j) {
                                         AT_FDCWD, i->temp_path,
                                         AT_FDCWD, i->final_path,
                                         INSTALL_READ_ONLY|
-                                        (i->flags & PULL_SYNC ? INSTALL_SYNCFS : 0));
+                                        (i->flags & IMPORT_SYNC ? INSTALL_SYNCFS : 0));
                         if (r < 0) {
                                 log_error_errno(r, "Failed to rename to final image name to %s: %m", i->final_path);
                                 goto finish;
@@ -462,7 +462,7 @@ static void tar_pull_job_on_finished(PullJob *j) {
                                                 AT_FDCWD, i->settings_temp_path,
                                                 AT_FDCWD, i->settings_path,
                                                 INSTALL_READ_ONLY|
-                                                (i->flags & PULL_SYNC ? INSTALL_FSYNC_FULL : 0));
+                                                (i->flags & IMPORT_SYNC ? INSTALL_FSYNC_FULL : 0));
                                 if (r < 0) {
                                         log_error_errno(r, "Failed to rename settings file to %s: %m", i->settings_path);
                                         goto finish;
@@ -500,7 +500,7 @@ static int tar_pull_job_on_open_disk_tar(PullJob *j) {
         assert(i->tar_job == j);
         assert(i->tar_pid <= 0);
 
-        if (i->flags & PULL_DIRECT)
+        if (i->flags & IMPORT_DIRECT)
                 where = i->local;
         else {
                 if (!i->temp_path) {
@@ -514,20 +514,20 @@ static int tar_pull_job_on_open_disk_tar(PullJob *j) {
 
         (void) mkdir_parents_label(where, 0700);
 
-        if (FLAGS_SET(i->flags, PULL_DIRECT|PULL_FORCE))
+        if (FLAGS_SET(i->flags, IMPORT_DIRECT|IMPORT_FORCE))
                 (void) rm_rf(where, REMOVE_ROOT|REMOVE_PHYSICAL|REMOVE_SUBVOLUME);
 
-        if (i->flags & PULL_BTRFS_SUBVOL)
+        if (i->flags & IMPORT_BTRFS_SUBVOL)
                 r = btrfs_subvol_make_fallback(AT_FDCWD, where, 0755);
         else
                 r = RET_NERRNO(mkdir(where, 0755));
-        if (r == -EEXIST && (i->flags & PULL_DIRECT)) /* EEXIST is OK if in direct mode, but not otherwise,
+        if (r == -EEXIST && (i->flags & IMPORT_DIRECT)) /* EEXIST is OK if in direct mode, but not otherwise,
                                                        * because in that case our temporary path collided */
                 r = 0;
         if (r < 0)
                 return log_error_errno(r, "Failed to create directory/subvolume %s: %m", where);
-        if (r > 0 && (i->flags & PULL_BTRFS_QUOTA)) { /* actually btrfs subvol */
-                if (!(i->flags & PULL_DIRECT))
+        if (r > 0 && (i->flags & IMPORT_BTRFS_QUOTA)) { /* actually btrfs subvol */
+                if (!(i->flags & IMPORT_DIRECT))
                         (void) import_assign_pool_quota_and_warn(i->image_root);
                 (void) import_assign_pool_quota_and_warn(where);
         }
@@ -579,7 +579,7 @@ int tar_pull_start(
                 TarPull *i,
                 const char *url,
                 const char *local,
-                PullFlags flags,
+                ImportFlags flags,
                 ImportVerify verify,
                 const char *checksum) {
 
@@ -589,9 +589,9 @@ int tar_pull_start(
         assert(verify == _IMPORT_VERIFY_INVALID || verify < _IMPORT_VERIFY_MAX);
         assert(verify == _IMPORT_VERIFY_INVALID || verify >= 0);
         assert((verify < 0) || !checksum);
-        assert(!(flags & ~PULL_FLAGS_MASK_TAR));
-        assert(!(flags & PULL_SETTINGS) || !(flags & PULL_DIRECT));
-        assert(!(flags & PULL_SETTINGS) || !checksum);
+        assert(!(flags & ~IMPORT_PULL_FLAGS_MASK_TAR));
+        assert(!(flags & IMPORT_PULL_SETTINGS) || !(flags & IMPORT_DIRECT));
+        assert(!(flags & IMPORT_PULL_SETTINGS) || !checksum);
 
         if (!http_url_is_valid(url) && !file_url_is_valid(url))
                 return -EINVAL;
@@ -622,7 +622,7 @@ int tar_pull_start(
         i->tar_job->on_open_disk = tar_pull_job_on_open_disk_tar;
         i->tar_job->calc_checksum = checksum || IN_SET(verify, IMPORT_VERIFY_CHECKSUM, IMPORT_VERIFY_SIGNATURE);
 
-        if (!FLAGS_SET(flags, PULL_DIRECT)) {
+        if (!FLAGS_SET(flags, IMPORT_DIRECT)) {
                 r = pull_find_old_etags(url, i->image_root, DT_DIR, ".tar-", NULL, &i->tar_job->old_etags);
                 if (r < 0)
                         return r;
@@ -642,7 +642,7 @@ int tar_pull_start(
                 return r;
 
         /* Set up download job for the settings file (.nspawn) */
-        if (FLAGS_SET(flags, PULL_SETTINGS)) {
+        if (FLAGS_SET(flags, IMPORT_PULL_SETTINGS)) {
                 r = pull_make_auxiliary_job(
                                 &i->settings_job,
                                 url,
@@ -668,7 +668,7 @@ int tar_pull_start(
                         continue;
 
                 j->on_progress = tar_pull_job_on_progress;
-                j->sync = FLAGS_SET(flags, PULL_SYNC);
+                j->sync = FLAGS_SET(flags, IMPORT_SYNC);
 
                 r = pull_job_begin(j);
                 if (r < 0)
index e54c01c302a4293c10e8dc1bdbc8dfbaa613e7b5..1a5b740463c62a9de3fbc0c22f8f1fa70f1c16fe 100644 (file)
@@ -16,4 +16,4 @@ TarPull* tar_pull_unref(TarPull *pull);
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(TarPull*, tar_pull_unref);
 
-int tar_pull_start(TarPull *pull, const char *url, const char *local, PullFlags flags, ImportVerify verify, const char *checksum);
+int tar_pull_start(TarPull *pull, const char *url, const char *local, ImportFlags flags, ImportVerify verify, const char *checksum);
index a2afc6f390be6c6c8a969346bd10ee5d10a8c452..518755b61df19626d254ec36b0e05c8913ff93ef 100644 (file)
@@ -28,7 +28,7 @@
 
 static const char *arg_image_root = "/var/lib/machines";
 static ImportVerify arg_verify = IMPORT_VERIFY_SIGNATURE;
-static PullFlags arg_pull_flags = PULL_SETTINGS | PULL_ROOTHASH | PULL_ROOTHASH_SIGNATURE | PULL_VERITY | PULL_BTRFS_SUBVOL | PULL_BTRFS_QUOTA | PULL_CONVERT_QCOW2 | PULL_SYNC;
+static ImportFlags arg_import_flags = IMPORT_PULL_SETTINGS | IMPORT_PULL_ROOTHASH | IMPORT_PULL_ROOTHASH_SIGNATURE | IMPORT_PULL_VERITY | IMPORT_BTRFS_SUBVOL | IMPORT_BTRFS_QUOTA | IMPORT_CONVERT_QCOW2 | IMPORT_SYNC;
 static uint64_t arg_offset = UINT64_MAX, arg_size_max = UINT64_MAX;
 static char *arg_checksum = NULL;
 
@@ -38,7 +38,7 @@ static int normalize_local(const char *local, const char *url, char **ret) {
         _cleanup_free_ char *ll = NULL;
         int r;
 
-        if (arg_pull_flags & PULL_DIRECT) {
+        if (arg_import_flags & IMPORT_DIRECT) {
 
                 if (!local)
                         log_debug("Writing downloaded data to STDOUT.");
@@ -63,7 +63,7 @@ static int normalize_local(const char *local, const char *url, char **ret) {
                                                "Local image name '%s' is not valid.",
                                                local);
 
-                if (!FLAGS_SET(arg_pull_flags, PULL_FORCE)) {
+                if (!FLAGS_SET(arg_import_flags, IMPORT_FORCE)) {
                         r = image_find(IMAGE_MACHINE, local, NULL, NULL);
                         if (r < 0) {
                                 if (r != -ENOENT)
@@ -130,7 +130,7 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
                 local = ll;
         }
 
-        if (!local && FLAGS_SET(arg_pull_flags, PULL_DIRECT))
+        if (!local && FLAGS_SET(arg_import_flags, IMPORT_DIRECT))
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Pulling tar images to STDOUT is not supported.");
 
         r = normalize_local(local, url, &normalized);
@@ -141,7 +141,7 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
         if (r < 0)
                 return r;
 
-        if (!FLAGS_SET(arg_pull_flags, PULL_SYNC))
+        if (!FLAGS_SET(arg_import_flags, IMPORT_SYNC))
                 log_info("File system synchronization on completion is off.");
 
         r = tar_pull_new(&pull, event, arg_image_root, on_tar_finished, event);
@@ -152,7 +152,7 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
                         pull,
                         url,
                         normalized,
-                        arg_pull_flags & PULL_FLAGS_MASK_TAR,
+                        arg_import_flags & IMPORT_PULL_FLAGS_MASK_TAR,
                         arg_verify,
                         arg_checksum);
         if (r < 0)
@@ -211,7 +211,7 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
         if (r < 0)
                 return r;
 
-        if (!FLAGS_SET(arg_pull_flags, PULL_SYNC))
+        if (!FLAGS_SET(arg_import_flags, IMPORT_SYNC))
                 log_info("File system synchronization on completion is off.");
 
         r = raw_pull_new(&pull, event, arg_image_root, on_raw_finished, event);
@@ -224,7 +224,7 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
                         normalized,
                         arg_offset,
                         arg_size_max,
-                        arg_pull_flags & PULL_FLAGS_MASK_RAW,
+                        arg_import_flags & IMPORT_PULL_FLAGS_MASK_RAW,
                         arg_verify,
                         arg_checksum);
         if (r < 0)
@@ -335,7 +335,7 @@ static int parse_argv(int argc, char *argv[]) {
                         return version();
 
                 case ARG_FORCE:
-                        arg_pull_flags |= PULL_FORCE;
+                        arg_import_flags |= IMPORT_FORCE;
                         break;
 
                 case ARG_IMAGE_ROOT:
@@ -367,7 +367,7 @@ static int parse_argv(int argc, char *argv[]) {
                                         return log_oom();
 
                                 free_and_replace(arg_checksum, hh);
-                                arg_pull_flags &= ~(PULL_SETTINGS|PULL_ROOTHASH|PULL_ROOTHASH_SIGNATURE|PULL_VERITY);
+                                arg_import_flags &= ~(IMPORT_PULL_SETTINGS|IMPORT_PULL_ROOTHASH|IMPORT_PULL_ROOTHASH_SIGNATURE|IMPORT_PULL_VERITY);
                                 arg_verify = _IMPORT_VERIFY_INVALID;
                         } else
                                 arg_verify = v;
@@ -380,7 +380,7 @@ static int parse_argv(int argc, char *argv[]) {
                         if (r < 0)
                                 return r;
 
-                        SET_FLAG(arg_pull_flags, PULL_SETTINGS, r);
+                        SET_FLAG(arg_import_flags, IMPORT_PULL_SETTINGS, r);
                         break;
 
                 case ARG_ROOTHASH:
@@ -388,11 +388,11 @@ static int parse_argv(int argc, char *argv[]) {
                         if (r < 0)
                                 return r;
 
-                        SET_FLAG(arg_pull_flags, PULL_ROOTHASH, r);
+                        SET_FLAG(arg_import_flags, IMPORT_PULL_ROOTHASH, r);
 
                         /* If we were asked to turn off the root hash, implicitly also turn off the root hash signature */
                         if (!r)
-                                SET_FLAG(arg_pull_flags, PULL_ROOTHASH_SIGNATURE, false);
+                                SET_FLAG(arg_import_flags, IMPORT_PULL_ROOTHASH_SIGNATURE, false);
                         break;
 
                 case ARG_ROOTHASH_SIGNATURE:
@@ -400,7 +400,7 @@ static int parse_argv(int argc, char *argv[]) {
                         if (r < 0)
                                 return r;
 
-                        SET_FLAG(arg_pull_flags, PULL_ROOTHASH_SIGNATURE, r);
+                        SET_FLAG(arg_import_flags, IMPORT_PULL_ROOTHASH_SIGNATURE, r);
                         break;
 
                 case ARG_VERITY:
@@ -408,16 +408,16 @@ static int parse_argv(int argc, char *argv[]) {
                         if (r < 0)
                                 return r;
 
-                        SET_FLAG(arg_pull_flags, PULL_VERITY, r);
+                        SET_FLAG(arg_import_flags, IMPORT_PULL_VERITY, r);
                         break;
 
                 case ARG_READ_ONLY:
-                        arg_pull_flags |= PULL_READ_ONLY;
+                        arg_import_flags |= IMPORT_READ_ONLY;
                         break;
 
                 case ARG_DIRECT:
-                        arg_pull_flags |= PULL_DIRECT;
-                        arg_pull_flags &= ~(PULL_SETTINGS|PULL_ROOTHASH|PULL_ROOTHASH_SIGNATURE|PULL_VERITY);
+                        arg_import_flags |= IMPORT_DIRECT;
+                        arg_import_flags &= ~(IMPORT_PULL_SETTINGS|IMPORT_PULL_ROOTHASH|IMPORT_PULL_ROOTHASH_SIGNATURE|IMPORT_PULL_VERITY);
                         break;
 
                 case ARG_BTRFS_SUBVOL:
@@ -425,7 +425,7 @@ static int parse_argv(int argc, char *argv[]) {
                         if (r < 0)
                                 return r;
 
-                        SET_FLAG(arg_pull_flags, PULL_BTRFS_SUBVOL, r);
+                        SET_FLAG(arg_import_flags, IMPORT_BTRFS_SUBVOL, r);
                         break;
 
                 case ARG_BTRFS_QUOTA:
@@ -433,7 +433,7 @@ static int parse_argv(int argc, char *argv[]) {
                         if (r < 0)
                                 return r;
 
-                        SET_FLAG(arg_pull_flags, PULL_BTRFS_QUOTA, r);
+                        SET_FLAG(arg_import_flags, IMPORT_BTRFS_QUOTA, r);
                         break;
 
                 case ARG_CONVERT_QCOW2:
@@ -441,7 +441,7 @@ static int parse_argv(int argc, char *argv[]) {
                         if (r < 0)
                                 return r;
 
-                        SET_FLAG(arg_pull_flags, PULL_CONVERT_QCOW2, r);
+                        SET_FLAG(arg_import_flags, IMPORT_CONVERT_QCOW2, r);
                         break;
 
                 case ARG_SYNC:
@@ -449,7 +449,7 @@ static int parse_argv(int argc, char *argv[]) {
                         if (r < 0)
                                 return r;
 
-                        SET_FLAG(arg_pull_flags, PULL_SYNC, r);
+                        SET_FLAG(arg_import_flags, IMPORT_SYNC, r);
                         break;
 
                 case ARG_OFFSET: {
@@ -491,10 +491,10 @@ static int parse_argv(int argc, char *argv[]) {
              !FILE_SIZE_VALID(arg_offset + arg_size_max)))
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "File offset und maximum size out of range.");
 
-        if (arg_offset != UINT64_MAX && !FLAGS_SET(arg_pull_flags, PULL_DIRECT))
+        if (arg_offset != UINT64_MAX && !FLAGS_SET(arg_import_flags, IMPORT_DIRECT))
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "File offset only supported in --direct mode.");
 
-        if (arg_checksum && (arg_pull_flags & (PULL_SETTINGS|PULL_ROOTHASH|PULL_ROOTHASH_SIGNATURE|PULL_VERITY)) != 0)
+        if (arg_checksum && (arg_import_flags & (IMPORT_PULL_SETTINGS|IMPORT_PULL_ROOTHASH|IMPORT_PULL_ROOTHASH_SIGNATURE|IMPORT_PULL_VERITY)) != 0)
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Literal checksum verification only supported if no associated files are downloaded.");
 
         return 1;
@@ -508,19 +508,19 @@ static void parse_env(void) {
 
         r = getenv_bool("SYSTEMD_IMPORT_BTRFS_SUBVOL");
         if (r >= 0)
-                SET_FLAG(arg_pull_flags, PULL_BTRFS_SUBVOL, r);
+                SET_FLAG(arg_import_flags, IMPORT_BTRFS_SUBVOL, r);
         else if (r != -ENXIO)
                 log_warning_errno(r, "Failed to parse $SYSTEMD_IMPORT_BTRFS_SUBVOL: %m");
 
         r = getenv_bool("SYSTEMD_IMPORT_BTRFS_QUOTA");
         if (r >= 0)
-                SET_FLAG(arg_pull_flags, PULL_BTRFS_QUOTA, r);
+                SET_FLAG(arg_import_flags, IMPORT_BTRFS_QUOTA, r);
         else if (r != -ENXIO)
                 log_warning_errno(r, "Failed to parse $SYSTEMD_IMPORT_BTRFS_QUOTA: %m");
 
         r = getenv_bool("SYSTEMD_IMPORT_SYNC");
         if (r >= 0)
-                SET_FLAG(arg_pull_flags, PULL_SYNC, r);
+                SET_FLAG(arg_import_flags, IMPORT_SYNC, r);
         else if (r != -ENXIO)
                 log_warning_errno(r, "Failed to parse $SYSTEMD_IMPORT_SYNC: %m");
 }