From: Mike Christie Date: Wed, 1 May 2019 01:14:31 +0000 (-0500) Subject: rbd nbd: move server startup code to function X-Git-Tag: v15.1.0~2539^2~7 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=8c44f8532a38e2eabf5841fbc0c04d95149ba185;p=ceph-ci.git rbd nbd: move server startup code to function The netlink connect cmd interface requires the server to be running when the connect call completes or commands will timeout/fail. This breaks the server code to 2 functions so we can control when it starts and runs. Right now it looks odd in that start_server will allocate and return the server only for it be freed after run, and it is not touched. The netlink enablement patch at the end will use the returned server. Signed-off-by: Mike Christie --- diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index 90034b423c4..5485ce0226b 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -751,6 +751,36 @@ done: return r; } +static NBDServer *start_server(Preforker& forker, int fd, librbd::Image& image) +{ + NBDServer *server; + + if (g_conf()->daemonize) { + global_init_postfork_finish(g_ceph_context); + forker.daemonize(); + } + + server = new NBDServer(fd, image); + server->start(); + + init_async_signal_handler(); + register_async_signal_handler(SIGHUP, sighup_handler); + register_async_signal_handler_oneshot(SIGINT, handle_signal); + register_async_signal_handler_oneshot(SIGTERM, handle_signal); + + return server; +} + +static void run_server(void) +{ + ioctl(nbd, NBD_DO_IT); + + unregister_async_signal_handler(SIGHUP, sighup_handler); + unregister_async_signal_handler(SIGINT, handle_signal); + unregister_async_signal_handler(SIGTERM, handle_signal); + shutdown_async_signal_handler(); +} + static int do_map(int argc, const char *argv[], Config *cfg) { int r; @@ -770,6 +800,7 @@ static int do_map(int argc, const char *argv[], Config *cfg) librbd::image_info_t info; Preforker forker; + NBDServer *server; vector args; argv_to_vec(argc, argv, args); @@ -888,33 +919,14 @@ static int do_map(int argc, const char *argv[], Config *cfg) cout << cfg->devpath << std::endl; - if (g_conf()->daemonize) { - global_init_postfork_finish(g_ceph_context); - forker.daemonize(); - } - - { - NBDServer server(fd[1], image); - - server.start(); - - init_async_signal_handler(); - register_async_signal_handler(SIGHUP, sighup_handler); - register_async_signal_handler_oneshot(SIGINT, handle_signal); - register_async_signal_handler_oneshot(SIGTERM, handle_signal); - - ioctl(nbd, NBD_DO_IT); - - unregister_async_signal_handler(SIGHUP, sighup_handler); - unregister_async_signal_handler(SIGINT, handle_signal); - unregister_async_signal_handler(SIGTERM, handle_signal); - shutdown_async_signal_handler(); - } + server = start_server(forker, fd[1], image); + run_server(); r = image.update_unwatch(handle); ceph_assert(r == 0); } + delete server; close_nbd: if (r < 0) { ioctl(nbd, NBD_CLEAR_SOCK);