btrfs-progs: mkfs: Move out some nodesize code
authorSebastian Thorarensen <sebth@naju.se>
Fri, 20 Mar 2015 01:10:15 +0000 (02:10 +0100)
committerDavid Sterba <dsterba@suse.cz>
Mon, 23 Mar 2015 15:53:15 +0000 (16:53 +0100)
Move the constant DEFAULT_MKFS_LEAF_SIZE to utils.h and rename it to
BTRFS_MKFS_DEFAULT_NODE_SIZE for consistency. Move the function
check_leaf_or_node_size to utils.c and rename it to
btrfs_check_node_or_leaf_size.

Signed-off-by: Sebastian Thorarensen <sebth@naju.se>
[added btrfs_ prefix]
Signed-off-by: David Sterba <dsterba@suse.cz>
mkfs.c
utils.c
utils.h

diff --git a/mkfs.c b/mkfs.c
index f83554d..8fff082 100644 (file)
--- a/mkfs.c
+++ b/mkfs.c
@@ -47,8 +47,6 @@ static u64 index_cnt = 2;
 #define DEFAULT_MKFS_FEATURES  (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF \
                | BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA)
 
-#define DEFAULT_MKFS_LEAF_SIZE 16384
-
 struct directory_name_entry {
        char *dir_name;
        char *path;
@@ -1057,27 +1055,6 @@ static int zero_output_file(int out_fd, u64 size, u32 sectorsize)
        return ret;
 }
 
-static int check_leaf_or_node_size(u32 size, u32 sectorsize)
-{
-       if (size < sectorsize) {
-               fprintf(stderr,
-                       "Illegal leafsize (or nodesize) %u (smaller than %u)\n",
-                       size, sectorsize);
-               return -1;
-       } else if (size > BTRFS_MAX_METADATA_BLOCKSIZE) {
-               fprintf(stderr,
-                       "Illegal leafsize (or nodesize) %u (larger than %u)\n",
-                       size, BTRFS_MAX_METADATA_BLOCKSIZE);
-               return -1;
-       } else if (size & (sectorsize - 1)) {
-               fprintf(stderr,
-                       "Illegal leafsize (or nodesize) %u (not align to %u)\n",
-                       size, sectorsize);
-               return -1;
-       }
-       return 0;
-}
-
 static int is_ssd(const char *file)
 {
        blkid_probe probe;
@@ -1230,7 +1207,8 @@ int main(int ac, char **av)
        u64 alloc_start = 0;
        u64 metadata_profile = 0;
        u64 data_profile = 0;
-       u32 leafsize = max_t(u32, sysconf(_SC_PAGESIZE), DEFAULT_MKFS_LEAF_SIZE);
+       u32 leafsize = max_t(u32, sysconf(_SC_PAGESIZE),
+                       BTRFS_MKFS_DEFAULT_NODE_SIZE);
        u32 sectorsize = 4096;
        u32 nodesize = leafsize;
        u32 stripesize = 4096;
@@ -1359,9 +1337,9 @@ int main(int ac, char **av)
                }
        }
        sectorsize = max(sectorsize, (u32)sysconf(_SC_PAGESIZE));
-       if (check_leaf_or_node_size(leafsize, sectorsize))
+       if (btrfs_check_node_or_leaf_size(leafsize, sectorsize))
                exit(1);
-       if (check_leaf_or_node_size(nodesize, sectorsize))
+       if (btrfs_check_node_or_leaf_size(nodesize, sectorsize))
                exit(1);
        saved_optind = optind;
        dev_cnt = ac - optind;
@@ -1440,7 +1418,7 @@ int main(int ac, char **av)
                if (!leaf_forced) {
                        leafsize = best_leafsize;
                        nodesize = best_leafsize;
-                       if (check_leaf_or_node_size(leafsize, sectorsize))
+                       if (btrfs_check_node_or_leaf_size(leafsize, sectorsize))
                                exit(1);
                }
                if (leafsize != sectorsize) {
diff --git a/utils.c b/utils.c
index 6228c7f..17f31fc 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -2720,3 +2720,24 @@ int btrfs_tree_search2_ioctl_supported(int fd)
 
        return v2_supported;
 }
+
+int btrfs_check_node_or_leaf_size(u32 size, u32 sectorsize)
+{
+       if (size < sectorsize) {
+               fprintf(stderr,
+                       "Illegal leafsize (or nodesize) %u (smaller than %u)\n",
+                       size, sectorsize);
+               return -1;
+       } else if (size > BTRFS_MAX_METADATA_BLOCKSIZE) {
+               fprintf(stderr,
+                       "Illegal leafsize (or nodesize) %u (larger than %u)\n",
+                       size, BTRFS_MAX_METADATA_BLOCKSIZE);
+               return -1;
+       } else if (size & (sectorsize - 1)) {
+               fprintf(stderr,
+                       "Illegal leafsize (or nodesize) %u (not align to %u)\n",
+                       size, sectorsize);
+               return -1;
+       }
+       return 0;
+}
diff --git a/utils.h b/utils.h
index 82ab5e8..599b007 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -25,6 +25,7 @@
 
 #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024)
 #define BTRFS_MKFS_SMALL_VOLUME_SIZE (1024 * 1024 * 1024)
+#define BTRFS_MKFS_DEFAULT_NODE_SIZE 16384
 
 #define BTRFS_SCAN_MOUNTED     (1ULL << 0)
 #define BTRFS_SCAN_LBLKID      (1ULL << 1)
@@ -208,5 +209,6 @@ static inline u64 div_factor(u64 num, int factor)
 }
 
 int btrfs_tree_search2_ioctl_supported(int fd);
+int btrfs_check_node_or_leaf_size(u32 size, u32 sectorsize);
 
 #endif