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 #define FUSE_USE_VERSION 30
9 #include "fuse3/fuse.h"
10 #include "fuse3/fuse_lowlevel.h"
11
12 #include "spdk/blobfs.h"
13 #include "spdk/bdev.h"
14 #include "spdk/event.h"
15 #include "spdk/thread.h"
16 #include "spdk/blob_bdev.h"
17 #include "spdk/blobfs_bdev.h"
18 #include "spdk/log.h"
19 #include "spdk/string.h"
20
21 char *g_bdev_name;
22 char *g_mountpoint;
23
24 int g_fuse_argc = 0;
25 char **g_fuse_argv = NULL;
26
27 static void
fuse_run_cb(void * cb_arg,int fserrno)28 fuse_run_cb(void *cb_arg, int fserrno)
29 {
30 if (fserrno) {
31 printf("Failed to mount filesystem on bdev %s to path %s: %s\n",
32 g_bdev_name, g_mountpoint, spdk_strerror(fserrno));
33
34 spdk_app_stop(0);
35 return;
36 }
37
38 printf("done.\n");
39 }
40
41 static void
spdk_fuse_run(void * arg1)42 spdk_fuse_run(void *arg1)
43 {
44 printf("Mounting filesystem on bdev %s to path %s...\n",
45 g_bdev_name, g_mountpoint);
46 fflush(stdout);
47
48 spdk_blobfs_bdev_mount(g_bdev_name, g_mountpoint, fuse_run_cb, NULL);
49 }
50
51 static void
spdk_fuse_shutdown(void)52 spdk_fuse_shutdown(void)
53 {
54 spdk_app_stop(0);
55 }
56
57 int
main(int argc,char ** argv)58 main(int argc, char **argv)
59 {
60 struct spdk_app_opts opts = {};
61 int rc = 0;
62
63 if (argc < 4) {
64 fprintf(stderr, "usage: %s <conffile> <bdev name> <mountpoint>\n", argv[0]);
65 exit(1);
66 }
67
68 spdk_app_opts_init(&opts, sizeof(opts));
69 opts.name = "spdk_fuse";
70 opts.json_config_file = argv[1];
71 opts.reactor_mask = "0x3";
72 opts.shutdown_cb = spdk_fuse_shutdown;
73
74 g_bdev_name = argv[2];
75 g_mountpoint = argv[3];
76
77 /* TODO: mount blobfs with extra FUSE options. */
78 g_fuse_argc = argc - 2;
79 g_fuse_argv = &argv[2];
80
81 spdk_fs_set_cache_size(512);
82
83 rc = spdk_app_start(&opts, spdk_fuse_run, NULL);
84 spdk_app_fini();
85
86 return rc;
87 }
88