]> git.proxmox.com Git - mirror_lxc.git/commitdiff
storage_utils: move duplicated function from tools
author2xsec <dh48.jeong@samsung.com>
Sat, 18 Aug 2018 09:05:32 +0000 (18:05 +0900)
committer2xsec <dh48.jeong@samsung.com>
Sat, 18 Aug 2018 09:05:32 +0000 (18:05 +0900)
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
src/lxc/storage/storage_utils.c
src/lxc/storage/storage_utils.h
src/lxc/tools/lxc_copy.c
src/lxc/tools/lxc_create.c

index b0a19043802ebf2f3ab50219ca922276b4a4bc60..da1ed7fcc0afe9ec0a897bf4163fac358b4cef3e 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #define _GNU_SOURCE
+#include <ctype.h>
 #include <dirent.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -457,6 +458,40 @@ 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 is_valid_storage_type(const char *type)
 {
        if (strcmp(type, "dir") == 0 ||
index 3c6bbb0d7422ca026316a25299e35ac49a405f1c..905233a245b0c9557c1212ae44cd8cdd63ce3afe 100644 (file)
@@ -48,6 +48,7 @@ extern int find_fstype_cb(char *buffer, void *data);
 extern const char *linkderef(const char *path, char *dest);
 extern bool unpriv_snap_allowed(struct lxc_storage *b, const char *t, bool snap,
                                bool maybesnap);
+extern uint64_t get_fssize(char *s);
 extern bool is_valid_storage_type(const char *type);
 extern int storage_destroy_wrapper(void *data);
 
index 33e4f9a76f4e4109adbb9c6b7343db0a39b03441..2d608013428c4edb2607704fe726ece978180444 100644 (file)
@@ -17,7 +17,6 @@
  */
 
 #define _GNU_SOURCE
-#include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <getopt.h>
@@ -37,6 +36,7 @@
 
 #include "arguments.h"
 #include "log.h"
+#include "storage_utils.h"
 #include "utils.h"
 
 #ifndef HAVE_GETSUBOPT
@@ -143,7 +143,6 @@ static int do_clone_rename(struct lxc_container *c, char *newname);
 static int do_clone_task(struct lxc_container *c, enum task task, int flags,
                         char **args);
 static void free_mnts(void);
-static uint64_t get_fssize(char *s);
 
 /* Place an ephemeral container started with -e flag on a tmpfs. Restrictions
  * are that you cannot request the data to be kept while placing the container
@@ -538,39 +537,6 @@ static void free_mnts()
        mnt_table_size = 0;
 }
 
-/* we pass fssize in bytes */
-static 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;
-}
-
 static int my_parser(struct lxc_arguments *args, int c, char *arg)
 {
        char *subopts = NULL;
index 8423ff30de7284d4e4fe4a54bedab1f150f1eb36..ae72f929e99f4024a1699f24a4f7a0b7e5a4f48d 100644 (file)
@@ -18,7 +18,6 @@
  */
 
 #define _GNU_SOURCE
-#include <ctype.h>
 #include <fcntl.h>
 #include <libgen.h>
 #include <stdint.h>
@@ -37,7 +36,6 @@
 lxc_log_define(lxc_create, lxc);
 
 static int my_parser(struct lxc_arguments *args, int c, char *arg);
-static uint64_t get_fssize(char *s);
 static void create_helpfn(const struct lxc_arguments *args);
 static bool validate_bdev_args(struct lxc_arguments *args);
 
@@ -146,40 +144,6 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
        return 0;
 }
 
-static 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;
-}
-
 static void create_helpfn(const struct lxc_arguments *args)
 {
        char *argv[3], *path;