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 34 #include "spdk/stdinc.h" 35 36 #define FUSE_USE_VERSION 30 37 #include "fuse3/fuse.h" 38 #include "fuse3/fuse_lowlevel.h" 39 40 #include "spdk/blobfs.h" 41 #include "spdk/bdev.h" 42 #include "spdk/event.h" 43 #include "spdk/thread.h" 44 #include "spdk/blob_bdev.h" 45 #include "spdk/blobfs_bdev.h" 46 #include "spdk/log.h" 47 #include "spdk/string.h" 48 49 char *g_bdev_name; 50 char *g_mountpoint; 51 52 int g_fuse_argc = 0; 53 char **g_fuse_argv = NULL; 54 55 static void 56 fuse_run_cb(void *cb_arg, int fserrno) 57 { 58 if (fserrno) { 59 printf("Failed to mount filesystem on bdev %s to path %s: %s\n", 60 g_bdev_name, g_mountpoint, spdk_strerror(fserrno)); 61 62 spdk_app_stop(0); 63 return; 64 } 65 66 printf("done.\n"); 67 } 68 69 static void 70 spdk_fuse_run(void *arg1) 71 { 72 printf("Mounting filesystem on bdev %s to path %s...\n", 73 g_bdev_name, g_mountpoint); 74 fflush(stdout); 75 76 spdk_blobfs_bdev_mount(g_bdev_name, g_mountpoint, fuse_run_cb, NULL); 77 } 78 79 static void 80 spdk_fuse_shutdown(void) 81 { 82 spdk_app_stop(0); 83 } 84 85 int main(int argc, char **argv) 86 { 87 struct spdk_app_opts opts = {}; 88 int rc = 0; 89 90 if (argc < 4) { 91 fprintf(stderr, "usage: %s <conffile> <bdev name> <mountpoint>\n", argv[0]); 92 exit(1); 93 } 94 95 spdk_app_opts_init(&opts); 96 opts.name = "spdk_fuse"; 97 opts.config_file = argv[1]; 98 opts.reactor_mask = "0x3"; 99 opts.shutdown_cb = spdk_fuse_shutdown; 100 101 g_bdev_name = argv[2]; 102 g_mountpoint = argv[3]; 103 104 /* TODO: mount blobfs with extra FUSE options. */ 105 g_fuse_argc = argc - 2; 106 g_fuse_argv = &argv[2]; 107 108 spdk_fs_set_cache_size(512); 109 110 rc = spdk_app_start(&opts, spdk_fuse_run, NULL); 111 spdk_app_fini(); 112 113 return rc; 114 } 115