1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (C) 2017 Intel Corporation.
3 * All rights reserved.
4 */
5
6 #include "spdk/stdinc.h"
7
8 #include "spdk/event.h"
9 #include "spdk/blobfs.h"
10 #include "spdk/blobfs_bdev.h"
11 #include "spdk/log.h"
12 #include "spdk/string.h"
13
14 const char *g_bdev_name;
15 static uint64_t g_cluster_size;
16
17 static void
shutdown_cb(void * cb_arg,int fserrno)18 shutdown_cb(void *cb_arg, int fserrno)
19 {
20 if (fserrno) {
21 printf("\nFailed to initialize filesystem on bdev %s...", g_bdev_name);
22 }
23
24 printf("done.\n");
25
26 spdk_app_stop(0);
27 }
28
29 static void
spdk_mkfs_run(void * arg1)30 spdk_mkfs_run(void *arg1)
31 {
32 printf("Initializing filesystem on bdev %s...", g_bdev_name);
33 fflush(stdout);
34
35 spdk_blobfs_bdev_create(g_bdev_name, g_cluster_size, shutdown_cb, NULL);
36 }
37
38 static void
mkfs_usage(void)39 mkfs_usage(void)
40 {
41 printf(" -C <size> cluster size\n");
42 }
43
44 static int
mkfs_parse_arg(int ch,char * arg)45 mkfs_parse_arg(int ch, char *arg)
46 {
47 bool has_prefix;
48
49 switch (ch) {
50 case 'C':
51 spdk_parse_capacity(arg, &g_cluster_size, &has_prefix);
52 break;
53 default:
54 return -EINVAL;
55 }
56 return 0;
57 }
58
59 int
main(int argc,char ** argv)60 main(int argc, char **argv)
61 {
62 struct spdk_app_opts opts = {};
63 int rc = 0;
64
65 if (argc < 3) {
66 SPDK_ERRLOG("usage: %s <conffile> <bdevname>\n", argv[0]);
67 exit(1);
68 }
69
70 spdk_app_opts_init(&opts, sizeof(opts));
71 opts.name = "spdk_mkfs";
72 opts.json_config_file = argv[1];
73 opts.reactor_mask = "0x3";
74 opts.shutdown_cb = NULL;
75 opts.rpc_addr = NULL;
76
77 spdk_fs_set_cache_size(512);
78 g_bdev_name = argv[2];
79 if ((rc = spdk_app_parse_args(argc, argv, &opts, "C:", NULL,
80 mkfs_parse_arg, mkfs_usage)) !=
81 SPDK_APP_PARSE_ARGS_SUCCESS) {
82 exit(rc);
83 }
84
85 rc = spdk_app_start(&opts, spdk_mkfs_run, NULL);
86 spdk_app_fini();
87
88 return rc;
89 }
90