Branch data Line data Source code
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 18 : 0 : shutdown_cb(void *cb_arg, int fserrno) 19 : : { 20 [ # # ]: 0 : if (fserrno) { 21 [ # # ]: 0 : printf("\nFailed to initialize filesystem on bdev %s...", g_bdev_name); 22 : : } 23 : : 24 [ # # ]: 0 : printf("done.\n"); 25 : : 26 : 0 : spdk_app_stop(0); 27 : 0 : } 28 : : 29 : : static void 30 : 0 : spdk_mkfs_run(void *arg1) 31 : : { 32 [ # # ]: 0 : printf("Initializing filesystem on bdev %s...", g_bdev_name); 33 : 0 : fflush(stdout); 34 : : 35 : 0 : spdk_blobfs_bdev_create(g_bdev_name, g_cluster_size, shutdown_cb, NULL); 36 : 0 : } 37 : : 38 : : static void 39 : 0 : mkfs_usage(void) 40 : : { 41 [ # # ]: 0 : printf(" -C <size> cluster size\n"); 42 : 0 : } 43 : : 44 : : static int 45 : 0 : mkfs_parse_arg(int ch, char *arg) 46 : : { 47 : 0 : bool has_prefix; 48 : : 49 [ # # ]: 0 : switch (ch) { 50 : 0 : case 'C': 51 : 0 : spdk_parse_capacity(arg, &g_cluster_size, &has_prefix); 52 : 0 : break; 53 : 0 : default: 54 : 0 : return -EINVAL; 55 : : } 56 : 0 : return 0; 57 : : } 58 : : 59 : : int 60 : 0 : main(int argc, char **argv) 61 : : { 62 : 0 : struct spdk_app_opts opts = {}; 63 : 0 : int rc = 0; 64 : : 65 [ # # ]: 0 : if (argc < 3) { 66 : 0 : SPDK_ERRLOG("usage: %s <conffile> <bdevname>\n", argv[0]); 67 : 0 : exit(1); 68 : : } 69 : : 70 : 0 : spdk_app_opts_init(&opts, sizeof(opts)); 71 : 0 : opts.name = "spdk_mkfs"; 72 : 0 : opts.json_config_file = argv[1]; 73 : 0 : opts.reactor_mask = "0x3"; 74 : 0 : opts.shutdown_cb = NULL; 75 : : 76 : 0 : spdk_fs_set_cache_size(512); 77 : 0 : g_bdev_name = argv[2]; 78 [ # # ]: 0 : if ((rc = spdk_app_parse_args(argc, argv, &opts, "C:", NULL, 79 : : mkfs_parse_arg, mkfs_usage)) != 80 : : SPDK_APP_PARSE_ARGS_SUCCESS) { 81 : 0 : exit(rc); 82 : : } 83 : : 84 : 0 : rc = spdk_app_start(&opts, spdk_mkfs_run, NULL); 85 : 0 : spdk_app_fini(); 86 : : 87 : 0 : return rc; 88 : : }