]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
storage_utils: move get_fssize to utils
authorAlexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Sun, 18 Feb 2024 15:04:54 +0000 (16:04 +0100)
committerAlexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Sun, 18 Feb 2024 15:04:54 +0000 (16:04 +0100)
This helper is used in the lxc/tools and it's
fully independent of storage_utils code, let's move it
to utils.c

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
src/lxc/storage/storage_utils.c
src/lxc/storage/storage_utils.h
src/lxc/utils.c
src/lxc/utils.h

index 37f154e0f19af15e0fbbfa2df0516dece0b7fff8..fc9c433fe0cc1ddd486dd02e3e87652224785ce6 100644 (file)
@@ -408,40 +408,6 @@ bool unpriv_snap_allowed(struct lxc_storage *b, const char *t, bool snap,
        return false;
 }
 
-uint64_t get_fssize(char *s)
-{
-       uint64_t ret;
-       char *end;
-
-       ret = strtoull(s, &end, 0);
-       if (end == s) {
-               ERROR("Invalid blockdev size '%s', using default size", s);
-               return 0;
-       }
-
-       while (isblank(*end))
-               end++;
-
-       if (*end == '\0') {
-               ret *= 1024ULL * 1024ULL; /* MB by default */
-       } else if (*end == 'b' || *end == 'B') {
-               ret *= 1ULL;
-       } else if (*end == 'k' || *end == 'K') {
-               ret *= 1024ULL;
-       } else if (*end == 'm' || *end == 'M') {
-               ret *= 1024ULL * 1024ULL;
-       } else if (*end == 'g' || *end == 'G') {
-               ret *= 1024ULL * 1024ULL * 1024ULL;
-       } else if (*end == 't' || *end == 'T') {
-               ret *= 1024ULL * 1024ULL * 1024ULL * 1024ULL;
-       } else {
-               ERROR("Invalid blockdev unit size '%c' in '%s', using default size", *end, s);
-               return 0;
-       }
-
-       return ret;
-}
-
 bool lxc_is_valid_storage_type(const char *type)
 {
        if (strcmp(type, "dir") == 0 ||
index 65f073e673589837e22cf59b6c2912cc4a720c8d..60c332915b902a8e79a03ac89844da1b2836ea66 100644 (file)
@@ -36,7 +36,6 @@ __hidden extern int find_fstype_cb(char *buffer, void *data);
 __hidden extern const char *linkderef(const char *path, char *dest);
 __hidden extern bool unpriv_snap_allowed(struct lxc_storage *b, const char *t, bool snap,
                                         bool maybesnap);
-__hidden extern uint64_t get_fssize(char *s);
 extern bool lxc_is_valid_storage_type(const char *type);
 __hidden extern int storage_destroy_wrapper(void *data);
 
index 6847cf69c029c8fe89b7d187234d59766b3a64a0..616544dd489c0cb3656b76f91642f99ff5ef295b 100644 (file)
@@ -2150,3 +2150,37 @@ int print_r(int fd, const char *path)
                     (st.st_mode & ~S_IFMT), st.st_uid, st.st_gid, maybe_empty(path));
        return ret;
 }
+
+uint64_t get_fssize(char *s)
+{
+       uint64_t ret;
+       char *end;
+
+       ret = strtoull(s, &end, 0);
+       if (end == s) {
+               ERROR("Invalid blockdev size '%s', using default size", s);
+               return 0;
+       }
+
+       while (isblank(*end))
+               end++;
+
+       if (*end == '\0') {
+               ret *= 1024ULL * 1024ULL; /* MB by default */
+       } else if (*end == 'b' || *end == 'B') {
+               ret *= 1ULL;
+       } else if (*end == 'k' || *end == 'K') {
+               ret *= 1024ULL;
+       } else if (*end == 'm' || *end == 'M') {
+               ret *= 1024ULL * 1024ULL;
+       } else if (*end == 'g' || *end == 'G') {
+               ret *= 1024ULL * 1024ULL * 1024ULL;
+       } else if (*end == 't' || *end == 'T') {
+               ret *= 1024ULL * 1024ULL * 1024ULL * 1024ULL;
+       } else {
+               ERROR("Invalid blockdev unit size '%c' in '%s', using default size", *end, s);
+               return 0;
+       }
+
+       return ret;
+}
index f702189cbc3b00b4272f5e01b7d165d15108b070..4040f9f1e8b5e7fa9b387aa555bce7cea4e663a4 100644 (file)
@@ -248,6 +248,8 @@ __hidden extern int safe_mount_beneath_at(int beneat_fd, const char *src, const
                                          const char *fstype, unsigned int flags, const void *data);
 __hidden __lxc_unused int print_r(int fd, const char *path);
 
+__hidden extern uint64_t get_fssize(char *s);
+
 static inline int copy_struct_from_client(__u32 server_size, void *dst,
                                          __u32 client_size, const void *src)
 {