]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/lib/blobfs/mkfs/mkfs.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / spdk / test / lib / blobfs / mkfs / mkfs.c
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <errno.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <pthread.h>
39 #include <stdbool.h>
40 #include <signal.h>
41
42 #include "spdk/blobfs.h"
43 #include "spdk/bdev.h"
44 #include "spdk/event.h"
45 #include "spdk/blob_bdev.h"
46 #include "spdk/log.h"
47
48 struct spdk_bs_dev *g_bs_dev;
49 const char *g_bdev_name;
50
51 static void
52 stop_cb(void *ctx, int fserrno)
53 {
54 spdk_app_stop(0);
55 }
56
57 static void
58 shutdown_cb(void *arg1, void *arg2)
59 {
60 struct spdk_filesystem *fs = arg1;
61
62 printf("done.\n");
63 spdk_fs_unload(fs, stop_cb, NULL);
64 }
65
66 static void
67 init_cb(void *ctx, struct spdk_filesystem *fs, int fserrno)
68 {
69 struct spdk_event *event;
70
71 event = spdk_event_allocate(0, shutdown_cb, fs, NULL);
72 spdk_event_call(event);
73 }
74
75 static void
76 spdk_mkfs_run(void *arg1, void *arg2)
77 {
78 struct spdk_bdev *bdev;
79
80 bdev = spdk_bdev_get_by_name(g_bdev_name);
81
82 if (bdev == NULL) {
83 SPDK_ERRLOG("bdev %s not found\n", g_bdev_name);
84 spdk_app_stop(-1);
85 return;
86 }
87
88 if (!spdk_bdev_claim(bdev, NULL, NULL)) {
89 SPDK_ERRLOG("could not claim bdev %s\n", g_bdev_name);
90 spdk_app_stop(-1);
91 return;
92 }
93
94 printf("Initializing filesystem on bdev %s...", g_bdev_name);
95 fflush(stdout);
96 g_bs_dev = spdk_bdev_create_bs_dev(bdev);
97 spdk_fs_init(g_bs_dev, NULL, init_cb, NULL);
98 }
99
100 int main(int argc, char **argv)
101 {
102 struct spdk_app_opts opts = {};
103
104 if (argc < 3) {
105 SPDK_ERRLOG("usage: %s <conffile> <bdevname>\n", argv[0]);
106 exit(1);
107 }
108
109 spdk_app_opts_init(&opts);
110 opts.name = "spdk_mkfs";
111 opts.config_file = argv[1];
112 opts.reactor_mask = "0x3";
113 opts.dpdk_mem_size = 1024;
114 opts.shutdown_cb = NULL;
115 spdk_app_init(&opts);
116
117 spdk_fs_set_cache_size(512);
118
119 g_bdev_name = argv[2];
120 spdk_app_start(spdk_mkfs_run, NULL, NULL);
121 spdk_app_fini();
122
123 return 0;
124 }