diff options
author | Simon Rettberg | 2020-07-28 17:49:17 +0200 |
---|---|---|
committer | Simon Rettberg | 2020-07-28 17:49:17 +0200 |
commit | e4dec3562e6cab27e1a3f40165e4c0d9d0bf05c9 (patch) | |
tree | 4b9b9a2ddf0cec0188f64639ed18f18f437b7c74 /src/server/server.c | |
parent | Merge branch 'no-working-flag' into fuse_ll (diff) | |
download | dnbd3-e4dec3562e6cab27e1a3f40165e4c0d9d0bf05c9.tar.gz dnbd3-e4dec3562e6cab27e1a3f40165e4c0d9d0bf05c9.tar.xz dnbd3-e4dec3562e6cab27e1a3f40165e4c0d9d0bf05c9.zip |
[SERVER] Add FUSE mode
Still needs some cleanup and optimizations, variable naming sucks,
comments, etc.
Diffstat (limited to 'src/server/server.c')
-rw-r--r-- | src/server/server.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/server/server.c b/src/server/server.c index fa7bcda..ad8b13e 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -29,6 +29,7 @@ #include "integrity.h" #include "threadpool.h" #include "rpc.h" +#include "fuse.h" #include "../version.h" #include "../shared/sockhelper.h" @@ -108,6 +109,9 @@ void dnbd3_printHelp(char *argv_0) printf( "Usage: %s [OPTIONS]...\n", argv_0 ); printf( "Start the DNBD3 server\n" ); printf( "-c or --config Configuration directory (default /etc/dnbd3-server/)\n" ); +#ifdef BUILD_SERVER_FUSE + printf( "-m or --mount FUSE mount point\n "); +#endif printf( "-n or --nodaemon Start server in foreground\n" ); printf( "-b or --bind Local Address to bind to\n" ); printf( "-h or --help Show this help text and quit\n" ); @@ -140,6 +144,8 @@ _Noreturn static void dnbd3_cleanup() _shutdown = true; logadd( LOG_INFO, "Cleanup..." ); + dfuse_shutdown(); + if ( hasTimerThread ) { pthread_kill( timerThread, SIGINT ); thread_join( timerThread, NULL ); @@ -190,11 +196,13 @@ int main(int argc, char *argv[]) char *paramCreate = NULL; char *bindAddress = NULL; char *errorMsg = NULL; + char *mountDir = NULL; int64_t paramSize = -1; int paramRevision = -1; - static const char *optString = "b:c:d:hnv?"; + static const char *optString = "b:c:m:d:hnv?"; static const struct option longOpts[] = { { "config", required_argument, NULL, 'c' }, + { "mount", required_argument, NULL, 'm' }, { "nodaemon", no_argument, NULL, 'n' }, { "reload", no_argument, NULL, 'r' }, { "help", no_argument, NULL, 'h' }, @@ -218,6 +226,13 @@ int main(int argc, char *argv[]) case 'c': _configDir = strdup( optarg ); break; + case 'm': +#ifndef BUILD_SERVER_FUSE + fprintf( "FUSE support not enabled at build time.\n" ); + return 8; +#endif + mountDir = strdup( optarg ); + break; case 'n': demonize = 0; break; @@ -342,6 +357,11 @@ int main(int argc, char *argv[]) net_init(); uplink_globalsInit(); rpc_init(); + if ( mountDir != NULL && !dfuse_init( NULL, mountDir ) ) { + logadd( LOG_ERROR, "Cannot mount fuse directory to %s", mountDir ); + dnbd3_cleanup(); + return EXIT_FAILURE; + } logadd( LOG_INFO, "DNBD3 server starting...." ); logadd( LOG_INFO, "Machine type: " ENDIAN_MODE ); logadd( LOG_INFO, "Build Type: " TOSTRING( BUILD_TYPE ) ); @@ -385,6 +405,7 @@ int main(int argc, char *argv[]) // Initialize thread pool if ( !threadpool_init( 8 ) ) { logadd( LOG_ERROR, "Could not init thread pool!\n" ); + dnbd3_cleanup(); exit( EXIT_FAILURE ); } @@ -526,10 +547,11 @@ static void dnbd3_handleSignal2(int signum, siginfo_t *info, void *data UNUSED) if ( info->si_pid != 0 && !pthread_equal( pthread_self(), mainThread ) ) { pthread_kill( mainThread, info->si_signo ); // And relay signal if we're not the main thread } - } - if ( pthread_equal( pthread_self(), mainThread ) ) { - // Signal received by main thread -- handle - dnbd3_handleSignal( signum ); + // Source is not this process -- only then do we honor signals + if ( pthread_equal( pthread_self(), mainThread ) ) { + // Signal received by main thread -- handle + dnbd3_handleSignal( signum ); + } } } |