#include "common/ceph_argparse.h"
#include "common/Preforker.h"
#include "global/global_init.h"
+#include "global/signal_handler.h"
#include "include/rados/librados.hpp"
#include "include/rbd/librbd.hpp"
static int max_part = 255;
static bool set_max_part = false;
static bool exclusive = false;
+static int nbd = -1;
#define RBD_NBD_BLKSIZE 512UL
#endif
#define htonll(a) ntohll(a)
+static void handle_signal(int signum)
+{
+ assert(signum == SIGINT || signum == SIGTERM);
+ derr << "*** Got signal " << sig_str(signum) << " ***" << dendl;
+ ioctl(nbd, NBD_DISCONNECT);
+}
+
class NBDServer
{
private:
int index = 0;
int fd[2];
- int nbd;
librbd::image_info_t info;
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.stop();
}