LCOV - code coverage report
Current view: top level - spdk/test/blobfs/mkfs - mkfs.c (source / functions) Hit Total Coverage
Test: Combined Lines: 26 42 61.9 %
Date: 2024-07-15 12:16:15 Functions: 3 5 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 16 31.2 %

           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                 :          2 : shutdown_cb(void *cb_arg, int fserrno)
      19                 :            : {
      20         [ -  + ]:          2 :         if (fserrno) {
      21         [ #  # ]:          0 :                 printf("\nFailed to initialize filesystem on bdev %s...", g_bdev_name);
      22                 :            :         }
      23                 :            : 
      24         [ -  + ]:          2 :         printf("done.\n");
      25                 :            : 
      26                 :          2 :         spdk_app_stop(0);
      27                 :          2 : }
      28                 :            : 
      29                 :            : static void
      30                 :          2 : spdk_mkfs_run(void *arg1)
      31                 :            : {
      32         [ -  + ]:          2 :         printf("Initializing filesystem on bdev %s...", g_bdev_name);
      33                 :          2 :         fflush(stdout);
      34                 :            : 
      35                 :          2 :         spdk_blobfs_bdev_create(g_bdev_name, g_cluster_size, shutdown_cb, NULL);
      36                 :          2 : }
      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                 :          2 : main(int argc, char **argv)
      61                 :            : {
      62                 :          2 :         struct spdk_app_opts opts = {};
      63                 :          2 :         int rc = 0;
      64                 :            : 
      65         [ -  + ]:          2 :         if (argc < 3) {
      66                 :          0 :                 SPDK_ERRLOG("usage: %s <conffile> <bdevname>\n", argv[0]);
      67                 :          0 :                 exit(1);
      68                 :            :         }
      69                 :            : 
      70                 :          2 :         spdk_app_opts_init(&opts, sizeof(opts));
      71                 :          2 :         opts.name = "spdk_mkfs";
      72                 :          2 :         opts.json_config_file = argv[1];
      73                 :          2 :         opts.reactor_mask = "0x3";
      74                 :          2 :         opts.shutdown_cb = NULL;
      75                 :          2 :         opts.rpc_addr = NULL;
      76                 :            : 
      77                 :          2 :         spdk_fs_set_cache_size(512);
      78                 :          2 :         g_bdev_name = argv[2];
      79         [ -  + ]:          2 :         if ((rc = spdk_app_parse_args(argc, argv, &opts, "C:", NULL,
      80                 :            :                                       mkfs_parse_arg, mkfs_usage)) !=
      81                 :            :             SPDK_APP_PARSE_ARGS_SUCCESS) {
      82                 :          0 :                 exit(rc);
      83                 :            :         }
      84                 :            : 
      85                 :          2 :         rc = spdk_app_start(&opts, spdk_mkfs_run, NULL);
      86                 :          2 :         spdk_app_fini();
      87                 :            : 
      88                 :          2 :         return rc;
      89                 :            : }

Generated by: LCOV version 1.14