]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
discover-image: Move some logic to the implementation file
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 14 May 2025 17:04:53 +0000 (19:04 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 14 May 2025 17:55:56 +0000 (19:55 +0200)
This will allow removing the string-util.h and path-util.h includes
as part of #37344.

src/machine/image.c
src/shared/discover-image.c
src/shared/discover-image.h
src/sysupdate/sysupdated.c

index f30c29e9ddfab68eab899343605491874c2383e5..41b40854d795252b3868c55ec12f96411d100231 100644 (file)
@@ -136,11 +136,11 @@ int image_clean_pool_operation(Manager *manager, ImageCleanPoolMode mode, Operat
 
                 HASHMAP_FOREACH(image, images) {
                         /* We can't remove vendor images (i.e. those in /usr) */
-                        if (IMAGE_IS_VENDOR(image))
+                        if (image_is_vendor(image))
                                 continue;
-                        if (IMAGE_IS_HOST(image))
+                        if (image_is_host(image))
                                 continue;
-                        if (mode == IMAGE_CLEAN_POOL_REMOVE_HIDDEN && !IMAGE_IS_HIDDEN(image))
+                        if (mode == IMAGE_CLEAN_POOL_REMOVE_HIDDEN && !image_is_hidden(image))
                                 continue;
 
                         r = image_remove(image);
index 721ad2d0f20068b008ef64c68c2e8c1ea65795ba..57f72a83ea3495d1de65d8edc6500578068464fa 100644 (file)
@@ -299,7 +299,7 @@ static int image_update_quota(Image *i, int fd) {
 
         assert(i);
 
-        if (IMAGE_IS_VENDOR(i) || IMAGE_IS_HOST(i))
+        if (image_is_vendor(i) || image_is_host(i))
                 return -EROFS;
 
         if (i->type != IMAGE_SUBVOLUME)
@@ -1094,7 +1094,7 @@ int image_remove(Image *i) {
 
         assert(i);
 
-        if (IMAGE_IS_VENDOR(i) || IMAGE_IS_HOST(i))
+        if (image_is_vendor(i) || image_is_host(i))
                 return -EROFS;
 
         settings = image_settings_path(i);
@@ -1189,7 +1189,7 @@ int image_rename(Image *i, const char *new_name, RuntimeScope scope) {
         if (!image_name_is_valid(new_name))
                 return -EINVAL;
 
-        if (IMAGE_IS_VENDOR(i) || IMAGE_IS_HOST(i))
+        if (image_is_vendor(i) || image_is_host(i))
                 return -EROFS;
 
         settings = image_settings_path(i);
@@ -1388,7 +1388,7 @@ int image_read_only(Image *i, bool b) {
 
         assert(i);
 
-        if (IMAGE_IS_VENDOR(i) || IMAGE_IS_HOST(i))
+        if (image_is_vendor(i) || image_is_host(i))
                 return -EROFS;
 
         /* Make sure we don't interfere with a running nspawn */
@@ -1578,7 +1578,7 @@ int image_set_limit(Image *i, uint64_t referenced_max) {
 
         assert(i);
 
-        if (IMAGE_IS_VENDOR(i) || IMAGE_IS_HOST(i))
+        if (image_is_vendor(i) || image_is_host(i))
                 return -EROFS;
 
         if (i->type != IMAGE_SUBVOLUME)
@@ -1831,6 +1831,24 @@ bool image_in_search_path(
         return false;
 }
 
+bool image_is_vendor(const struct Image *i) {
+        assert(i);
+
+        return i->path && path_startswith(i->path, "/usr");
+}
+
+bool image_is_host(const struct Image *i) {
+        assert(i);
+
+        if (i->name && streq(i->name, ".host"))
+                return true;
+
+        if (i->path && path_equal(i->path, "/"))
+                return true;
+
+        return false;
+}
+
 int image_to_json(const struct Image *img, sd_json_variant **ret) {
         assert(img);
 
index 66dc7ef3d283dd2155d9548e807e1242cca6f71f..27d487136446a7d39d4c58234bdfe92a0a0a7e9b 100644 (file)
@@ -95,29 +95,14 @@ static inline char **image_extension_release(Image *image, ImageClass class) {
         return NULL;
 }
 
-static inline bool IMAGE_IS_HIDDEN(const struct Image *i) {
+static inline bool image_is_hidden(const struct Image *i) {
         assert(i);
 
         return i->name && i->name[0] == '.';
 }
 
-static inline bool IMAGE_IS_VENDOR(const struct Image *i) {
-        assert(i);
-
-        return i->path && path_startswith(i->path, "/usr");
-}
-
-static inline bool IMAGE_IS_HOST(const struct Image *i) {
-        assert(i);
-
-        if (i->name && streq(i->name, ".host"))
-                return true;
-
-        if (i->path && path_equal(i->path, "/"))
-                return true;
-
-        return false;
-}
+bool image_is_vendor(const struct Image *i);
+bool image_is_host(const struct Image *i);
 
 int image_to_json(const struct Image *i, sd_json_variant **ret);
 
index 9a8402482c91a002857cd4243cb54945dca3ab9c..430e46e6e99ec85ebac50b5660e395ae0a75682b 100644 (file)
@@ -1766,7 +1766,7 @@ static int manager_enumerate_image_class(Manager *m, TargetClass class) {
                 _cleanup_(target_freep) Target *t = NULL;
                 bool have = false;
 
-                if (IMAGE_IS_HOST(image))
+                if (image_is_host(image))
                         continue; /* We already enroll the host ourselves */
 
                 r = target_new(m, class, image->name, image->path, &t);