From: Alexander Mikhalitsyn Date: Sun, 18 Feb 2024 15:04:54 +0000 (+0100) Subject: storage_utils: move get_fssize to utils X-Git-Tag: v6.0.0~19^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9eee450d253650699a6f871695bfed1901679931;p=thirdparty%2Flxc.git storage_utils: move get_fssize to utils 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 --- diff --git a/src/lxc/storage/storage_utils.c b/src/lxc/storage/storage_utils.c index 37f154e0f..fc9c433fe 100644 --- a/src/lxc/storage/storage_utils.c +++ b/src/lxc/storage/storage_utils.c @@ -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 || diff --git a/src/lxc/storage/storage_utils.h b/src/lxc/storage/storage_utils.h index 65f073e67..60c332915 100644 --- a/src/lxc/storage/storage_utils.h +++ b/src/lxc/storage/storage_utils.h @@ -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); diff --git a/src/lxc/utils.c b/src/lxc/utils.c index 6847cf69c..616544dd4 100644 --- a/src/lxc/utils.c +++ b/src/lxc/utils.c @@ -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; +} diff --git a/src/lxc/utils.h b/src/lxc/utils.h index f702189cb..4040f9f1e 100644 --- a/src/lxc/utils.h +++ b/src/lxc/utils.h @@ -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) {