1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 * rbd-nbd - RBD in userspace
7 * Copyright (C) 2015 - 2016 Kylin Corporation
9 * Author: Yunchuan Wen <yunchuan.wen@kylin-cloud.com>
10 * Li Wang <li.wang@kylin-cloud.com>
12 * This is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License version 2.1, as published by the Free Software
15 * Foundation. See file COPYING.
19 #include "include/int_types.h"
27 #include <sys/types.h>
30 #include <linux/nbd.h>
32 #include <sys/ioctl.h>
33 #include <sys/socket.h>
37 #include <boost/regex.hpp>
39 #include "mon/MonClient.h"
40 #include "common/config.h"
41 #include "common/dout.h"
43 #include "common/errno.h"
44 #include "common/module.h"
45 #include "common/safe_io.h"
46 #include "common/TextTable.h"
47 #include "common/ceph_argparse.h"
48 #include "common/Preforker.h"
49 #include "common/version.h"
50 #include "global/global_init.h"
51 #include "global/signal_handler.h"
53 #include "include/rados/librados.hpp"
54 #include "include/rbd/librbd.hpp"
55 #include "include/stringify.h"
56 #include "include/xlist.h"
58 #define dout_context g_ceph_context
59 #define dout_subsys ceph_subsys_rbd
61 #define dout_prefix *_dout << "rbd-nbd: "
67 bool exclusive
= false;
68 bool readonly
= false;
69 bool set_max_part
= false;
79 std::cout
<< "Usage: rbd-nbd [options] map <image-or-snap-spec> Map an image to nbd device\n"
80 << " unmap <device path> Unmap nbd device\n"
81 << " list-mapped List mapped nbd devices\n"
83 << " --device <device path> Specify nbd device path\n"
84 << " --read-only Map read-only\n"
85 << " --nbds_max <limit> Override for module param nbds_max\n"
86 << " --max_part <limit> Override for module param max_part\n"
87 << " --exclusive Forbid writes by other clients\n"
89 generic_server_usage();
101 #define RBD_NBD_BLKSIZE 512UL
104 #define VERSION_INFO 2
106 #ifdef CEPH_BIG_ENDIAN
107 #define ntohll(a) (a)
108 #elif defined(CEPH_LITTLE_ENDIAN)
109 #define ntohll(a) swab(a)
111 #error "Could not determine endianess"
113 #define htonll(a) ntohll(a)
115 static int parse_args(vector
<const char*>& args
, std::ostream
*err_msg
, Config
*cfg
);
117 static void handle_signal(int signum
)
119 assert(signum
== SIGINT
|| signum
== SIGTERM
);
120 derr
<< "*** Got signal " << sig_str(signum
) << " ***" << dendl
;
121 dout(20) << __func__
<< ": " << "sending NBD_DISCONNECT" << dendl
;
122 if (ioctl(nbd
, NBD_DISCONNECT
) < 0) {
123 derr
<< "rbd-nbd: disconnect failed: " << cpp_strerror(errno
) << dendl
;
125 dout(20) << __func__
<< ": " << "disconnected" << dendl
;
133 librbd::Image
&image
;
136 NBDServer(int _fd
, librbd::Image
& _image
)
139 , lock("NBDServer::Locker")
140 , reader_thread(*this, &NBDServer::reader_entry
)
141 , writer_thread(*this, &NBDServer::writer_entry
)
146 std::atomic
<bool> terminated
= { false };
150 bool expected
= false;
151 if (terminated
.compare_exchange_strong(expected
, true)) {
152 ::shutdown(fd
, SHUT_RDWR
);
154 Mutex::Locker
l(lock
);
161 xlist
<IOContext
*>::item item
;
163 struct nbd_request request
;
164 struct nbd_reply reply
;
173 friend std::ostream
&operator<<(std::ostream
&os
, const IOContext
&ctx
);
177 xlist
<IOContext
*> io_pending
;
178 xlist
<IOContext
*> io_finished
;
180 void io_start(IOContext
*ctx
)
182 Mutex::Locker
l(lock
);
183 io_pending
.push_back(&ctx
->item
);
186 void io_finish(IOContext
*ctx
)
188 Mutex::Locker
l(lock
);
189 assert(ctx
->item
.is_on_list());
190 ctx
->item
.remove_myself();
191 io_finished
.push_back(&ctx
->item
);
195 IOContext
*wait_io_finish()
197 Mutex::Locker
l(lock
);
198 while(io_finished
.empty() && !terminated
)
201 if (io_finished
.empty())
204 IOContext
*ret
= io_finished
.front();
205 io_finished
.pop_front();
212 assert(!reader_thread
.is_started());
213 Mutex::Locker
l(lock
);
214 while(!io_pending
.empty())
217 while(!io_finished
.empty()) {
218 ceph::unique_ptr
<IOContext
> free_ctx(io_finished
.front());
219 io_finished
.pop_front();
223 static void aio_callback(librbd::completion_t cb
, void *arg
)
225 librbd::RBD::AioCompletion
*aio_completion
=
226 reinterpret_cast<librbd::RBD::AioCompletion
*>(cb
);
228 IOContext
*ctx
= reinterpret_cast<IOContext
*>(arg
);
229 int ret
= aio_completion
->get_return_value();
231 dout(20) << __func__
<< ": " << *ctx
<< dendl
;
233 if (ret
== -EINVAL
) {
234 // if shrinking an image, a pagecache writeback might reference
235 // extents outside of the range of the new image extents
236 dout(0) << __func__
<< ": masking IO out-of-bounds error" << dendl
;
242 ctx
->reply
.error
= htonl(-ret
);
243 } else if ((ctx
->command
== NBD_CMD_READ
) &&
244 ret
< static_cast<int>(ctx
->request
.len
)) {
245 int pad_byte_count
= static_cast<int> (ctx
->request
.len
) - ret
;
246 ctx
->data
.append_zero(pad_byte_count
);
247 dout(20) << __func__
<< ": " << *ctx
<< ": Pad byte count: "
248 << pad_byte_count
<< dendl
;
249 ctx
->reply
.error
= 0;
251 ctx
->reply
.error
= htonl(0);
253 ctx
->server
->io_finish(ctx
);
255 aio_completion
->release();
260 while (!terminated
) {
261 ceph::unique_ptr
<IOContext
> ctx(new IOContext());
264 dout(20) << __func__
<< ": waiting for nbd request" << dendl
;
266 int r
= safe_read_exact(fd
, &ctx
->request
, sizeof(struct nbd_request
));
268 derr
<< "failed to read nbd request header: " << cpp_strerror(r
)
273 if (ctx
->request
.magic
!= htonl(NBD_REQUEST_MAGIC
)) {
274 derr
<< "invalid nbd request header" << dendl
;
278 ctx
->request
.from
= ntohll(ctx
->request
.from
);
279 ctx
->request
.type
= ntohl(ctx
->request
.type
);
280 ctx
->request
.len
= ntohl(ctx
->request
.len
);
282 ctx
->reply
.magic
= htonl(NBD_REPLY_MAGIC
);
283 memcpy(ctx
->reply
.handle
, ctx
->request
.handle
, sizeof(ctx
->reply
.handle
));
285 ctx
->command
= ctx
->request
.type
& 0x0000ffff;
287 dout(20) << *ctx
<< ": start" << dendl
;
289 switch (ctx
->command
)
292 // NBD_DO_IT will return when pipe is closed
293 dout(0) << "disconnect request received" << dendl
;
296 bufferptr
ptr(ctx
->request
.len
);
297 r
= safe_read_exact(fd
, ptr
.c_str(), ctx
->request
.len
);
299 derr
<< *ctx
<< ": failed to read nbd request data: "
300 << cpp_strerror(r
) << dendl
;
303 ctx
->data
.push_back(ptr
);
307 IOContext
*pctx
= ctx
.release();
309 librbd::RBD::AioCompletion
*c
= new librbd::RBD::AioCompletion(pctx
, aio_callback
);
310 switch (pctx
->command
)
313 image
.aio_write(pctx
->request
.from
, pctx
->request
.len
, pctx
->data
, c
);
316 image
.aio_read(pctx
->request
.from
, pctx
->request
.len
, pctx
->data
, c
);
322 image
.aio_discard(pctx
->request
.from
, pctx
->request
.len
, c
);
325 derr
<< *pctx
<< ": invalid request command" << dendl
;
330 dout(20) << __func__
<< ": terminated" << dendl
;
335 while (!terminated
) {
336 dout(20) << __func__
<< ": waiting for io request" << dendl
;
337 ceph::unique_ptr
<IOContext
> ctx(wait_io_finish());
339 dout(20) << __func__
<< ": no io requests, terminating" << dendl
;
343 dout(20) << __func__
<< ": got: " << *ctx
<< dendl
;
345 int r
= safe_write(fd
, &ctx
->reply
, sizeof(struct nbd_reply
));
347 derr
<< *ctx
<< ": failed to write reply header: " << cpp_strerror(r
)
351 if (ctx
->command
== NBD_CMD_READ
&& ctx
->reply
.error
== htonl(0)) {
352 r
= ctx
->data
.write_fd(fd
);
354 derr
<< *ctx
<< ": failed to write replay data: " << cpp_strerror(r
)
359 dout(20) << *ctx
<< ": finish" << dendl
;
361 dout(20) << __func__
<< ": terminated" << dendl
;
364 class ThreadHelper
: public Thread
367 typedef void (NBDServer::*entry_func
)();
372 ThreadHelper(NBDServer
&_server
, entry_func _func
)
377 void* entry() override
383 } reader_thread
, writer_thread
;
390 dout(10) << __func__
<< ": starting" << dendl
;
394 reader_thread
.create("rbd_reader");
395 writer_thread
.create("rbd_writer");
402 dout(10) << __func__
<< ": terminating" << dendl
;
406 reader_thread
.join();
407 writer_thread
.join();
421 std::ostream
&operator<<(std::ostream
&os
, const NBDServer::IOContext
&ctx
) {
423 os
<< "[" << std::hex
<< ntohll(*((uint64_t *)ctx
.request
.handle
));
440 os
<< " UNKNOW(" << ctx
.command
<< ") ";
444 os
<< ctx
.request
.from
<< "~" << ctx
.request
.len
<< " "
445 << ntohl(ctx
.reply
.error
) << "]";
450 class NBDWatchCtx
: public librbd::UpdateWatchCtx
454 librados::IoCtx
&io_ctx
;
455 librbd::Image
&image
;
459 librados::IoCtx
&_io_ctx
,
460 librbd::Image
&_image
,
468 ~NBDWatchCtx() override
{}
470 void handle_notify() override
472 librbd::image_info_t info
;
473 if (image
.stat(info
, sizeof(info
)) == 0) {
474 unsigned long new_size
= info
.size
;
476 if (new_size
!= size
) {
477 dout(5) << "resize detected" << dendl
;
478 if (ioctl(fd
, BLKFLSBUF
, NULL
) < 0)
479 derr
<< "invalidate page cache failed: " << cpp_strerror(errno
)
481 if (ioctl(fd
, NBD_SET_SIZE
, new_size
) < 0) {
482 derr
<< "resize failed: " << cpp_strerror(errno
) << dendl
;
486 if (ioctl(fd
, BLKRRPART
, NULL
) < 0) {
487 derr
<< "rescan of partition table failed: " << cpp_strerror(errno
)
490 if (image
.invalidate_cache() < 0)
491 derr
<< "invalidate rbd cache failed" << dendl
;
497 static int open_device(const char* path
, Config
*cfg
= nullptr, bool try_load_module
= false)
499 int nbd
= open(path
, O_RDWR
);
500 bool loaded_module
= false;
502 if (nbd
< 0 && try_load_module
&& access("/sys/module/nbd", F_OK
) != 0) {
506 param
<< "nbds_max=" << cfg
->nbds_max
;
509 param
<< " max_part=" << cfg
->max_part
;
511 r
= module_load("nbd", param
.str().c_str());
513 cerr
<< "rbd-nbd: failed to load nbd kernel module: " << cpp_strerror(-r
) << std::endl
;
516 loaded_module
= true;
518 nbd
= open(path
, O_RDWR
);
521 if (try_load_module
&& !loaded_module
&&
522 (cfg
->nbds_max
|| cfg
->set_max_part
)) {
523 cerr
<< "rbd-nbd: ignoring kernel module parameter options: nbd module already loaded"
530 static int check_device_size(int nbd_index
, unsigned long expected_size
)
532 // There are bugs with some older kernel versions that result in an
533 // overflow for large image sizes. This check is to ensure we are
536 unsigned long size
= 0;
537 std::string path
= "/sys/block/nbd" + stringify(nbd_index
) + "/size";
539 ifs
.open(path
.c_str(), std::ifstream::in
);
540 if (!ifs
.is_open()) {
541 cerr
<< "rbd-nbd: failed to open " << path
<< std::endl
;
545 size
*= RBD_NBD_BLKSIZE
;
548 // Newer kernel versions will report real size only after nbd
549 // connect. Assume this is the case and return success.
553 if (size
!= expected_size
) {
554 cerr
<< "rbd-nbd: kernel reported invalid device size (" << size
555 << ", expected " << expected_size
<< ")" << std::endl
;
562 static int do_map(int argc
, const char *argv
[], Config
*cfg
)
566 librados::Rados rados
;
568 librados::IoCtx io_ctx
;
578 librbd::image_info_t info
;
582 vector
<const char*> args
;
583 argv_to_vec(argc
, argv
, args
);
586 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
587 CODE_ENVIRONMENT_DAEMON
,
588 CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS
);
589 g_ceph_context
->_conf
->set_val_or_die("pid_file", "");
591 if (global_init_prefork(g_ceph_context
) >= 0) {
593 r
= forker
.prefork(err
);
595 cerr
<< err
<< std::endl
;
598 if (forker
.is_parent()) {
599 if (forker
.parent_wait(err
) != 0) {
604 global_init_postfork_start(g_ceph_context
);
607 common_init_finish(g_ceph_context
);
608 global_init_chdir(g_ceph_context
);
610 if (socketpair(AF_UNIX
, SOCK_STREAM
, 0, fd
) == -1) {
615 r
= rados
.init_with_context(g_ceph_context
);
623 r
= rados
.ioctx_create(cfg
->poolname
.c_str(), io_ctx
);
627 r
= rbd
.open(io_ctx
, image
, cfg
->imgname
.c_str());
631 if (cfg
->exclusive
) {
632 r
= image
.lock_acquire(RBD_LOCK_MODE_EXCLUSIVE
);
634 cerr
<< "rbd-nbd: failed to acquire exclusive lock: " << cpp_strerror(r
)
640 if (!cfg
->snapname
.empty()) {
641 r
= image
.snap_set(cfg
->snapname
.c_str());
646 r
= image
.stat(info
, sizeof(info
));
650 if (cfg
->devpath
.empty()) {
652 bool try_load_module
= true;
653 const char *path
= "/sys/module/nbd/parameters/nbds_max";
655 if (access(path
, F_OK
) == 0) {
657 ifs
.open(path
, std::ifstream::in
);
665 snprintf(dev
, sizeof(dev
), "/dev/nbd%d", index
);
667 nbd
= open_device(dev
, cfg
, try_load_module
);
668 try_load_module
= false;
670 if (nbd
== -EPERM
&& nbds_max
!= -1 && index
< (nbds_max
-1)) {
675 cerr
<< "rbd-nbd: failed to find unused device" << std::endl
;
679 r
= ioctl(nbd
, NBD_SET_SOCK
, fd
[0]);
690 r
= sscanf(cfg
->devpath
.c_str(), "/dev/nbd%d", &index
);
692 cerr
<< "rbd-nbd: invalid device path: " << cfg
->devpath
693 << " (expected /dev/nbd{num})" << std::endl
;
696 nbd
= open_device(cfg
->devpath
.c_str(), cfg
, true);
699 cerr
<< "rbd-nbd: failed to open device: " << cfg
->devpath
<< std::endl
;
703 r
= ioctl(nbd
, NBD_SET_SOCK
, fd
[0]);
706 cerr
<< "rbd-nbd: the device " << cfg
->devpath
<< " is busy" << std::endl
;
712 flags
= NBD_FLAG_SEND_FLUSH
| NBD_FLAG_SEND_TRIM
| NBD_FLAG_HAS_FLAGS
;
713 if (!cfg
->snapname
.empty() || cfg
->readonly
) {
714 flags
|= NBD_FLAG_READ_ONLY
;
718 r
= ioctl(nbd
, NBD_SET_BLKSIZE
, RBD_NBD_BLKSIZE
);
724 if (info
.size
> ULONG_MAX
) {
726 cerr
<< "rbd-nbd: image is too large (" << prettybyte_t(info
.size
)
727 << ", max is " << prettybyte_t(ULONG_MAX
) << ")" << std::endl
;
733 r
= ioctl(nbd
, NBD_SET_SIZE
, size
);
739 r
= check_device_size(index
, size
);
744 ioctl(nbd
, NBD_SET_FLAGS
, flags
);
746 r
= ioctl(nbd
, BLKROSET
, (unsigned long) &read_only
);
755 NBDWatchCtx
watch_ctx(nbd
, io_ctx
, image
, info
.size
);
756 r
= image
.update_watch(&watch_ctx
, &handle
);
760 cout
<< cfg
->devpath
<< std::endl
;
762 if (g_conf
->daemonize
) {
763 global_init_postfork_finish(g_ceph_context
);
768 NBDServer
server(fd
[1], image
);
772 init_async_signal_handler();
773 register_async_signal_handler(SIGHUP
, sighup_handler
);
774 register_async_signal_handler_oneshot(SIGINT
, handle_signal
);
775 register_async_signal_handler_oneshot(SIGTERM
, handle_signal
);
777 ioctl(nbd
, NBD_DO_IT
);
779 unregister_async_signal_handler(SIGHUP
, sighup_handler
);
780 unregister_async_signal_handler(SIGINT
, handle_signal
);
781 unregister_async_signal_handler(SIGTERM
, handle_signal
);
782 shutdown_async_signal_handler();
787 r
= image
.update_unwatch(handle
);
793 ioctl(nbd
, NBD_CLEAR_SOCK
);
794 cerr
<< "rbd-nbd: failed to map, status: " << cpp_strerror(-r
) << std::endl
;
805 forker
.exit(r
< 0 ? EXIT_FAILURE
: 0);
810 static int do_unmap(const std::string
&devpath
)
814 int nbd
= open_device(devpath
.c_str());
816 cerr
<< "rbd-nbd: failed to open device: " << devpath
<< std::endl
;
820 r
= ioctl(nbd
, NBD_DISCONNECT
);
822 cerr
<< "rbd-nbd: the device is not used" << std::endl
;
830 static int parse_imgpath(const std::string
&imgpath
, Config
*cfg
)
832 boost::regex
pattern("^(?:([^/@]+)/)?([^/@]+)(?:@([^/@]+))?$");
834 if (!boost::regex_match(imgpath
, match
, pattern
)) {
835 std::cerr
<< "rbd-nbd: invalid spec '" << imgpath
<< "'" << std::endl
;
839 if (match
[1].matched
) {
840 cfg
->poolname
= match
[1];
843 cfg
->imgname
= match
[2];
845 if (match
[3].matched
)
846 cfg
->snapname
= match
[3];
851 static int get_mapped_info(int pid
, Config
*cfg
)
854 std::string path
= "/proc/" + stringify(pid
) + "/cmdline";
857 std::vector
<const char*> args
;
859 ifs
.open(path
.c_str(), std::ifstream::in
);
864 for (unsigned i
= 0; i
< cmdline
.size(); i
++) {
865 const char *arg
= &cmdline
[i
];
867 if (strcmp(basename(arg
) , "rbd-nbd") != 0) {
874 while (cmdline
[i
] != '\0') {
879 std::ostringstream err_msg
;
880 r
= parse_args(args
, &err_msg
, cfg
);
884 static int get_map_pid(const std::string
& pid_path
)
888 ifs
.open(pid_path
.c_str(), std::ifstream::in
);
889 if (!ifs
.is_open()) {
896 static int do_list_mapped_devices()
899 bool should_print
= false;
903 std::string default_pool_name
;
907 tbl
.define_column("pid", TextTable::LEFT
, TextTable::LEFT
);
908 tbl
.define_column("pool", TextTable::LEFT
, TextTable::LEFT
);
909 tbl
.define_column("image", TextTable::LEFT
, TextTable::LEFT
);
910 tbl
.define_column("snap", TextTable::LEFT
, TextTable::LEFT
);
911 tbl
.define_column("device", TextTable::LEFT
, TextTable::LEFT
);
914 std::string nbd_path
= "/sys/block/nbd" + stringify(index
);
915 if(access(nbd_path
.c_str(), F_OK
) != 0) {
918 std::string pid_path
= nbd_path
+ "/pid";
919 pid
= get_map_pid(pid_path
);
923 r
= get_mapped_info(pid
, &cfg
);
929 if (cfg
.snapname
.empty()) {
932 tbl
<< pid
<< cfg
.poolname
<< cfg
.imgname
<< cfg
.snapname
933 << "/dev/nbd" + stringify(index
) << TextTable::endrow
;
945 static int parse_args(vector
<const char*>& args
, std::ostream
*err_msg
, Config
*cfg
)
947 std::string conf_file_list
;
949 CephInitParameters iparams
= ceph_argparse_early_args(
950 args
, CEPH_ENTITY_TYPE_CLIENT
, &cluster
, &conf_file_list
);
953 config
.name
= iparams
.name
;
954 config
.cluster
= cluster
;
956 if (!conf_file_list
.empty()) {
957 config
.parse_config_files(conf_file_list
.c_str(), nullptr, 0);
959 config
.parse_config_files(nullptr, nullptr, 0);
962 config
.parse_argv(args
);
963 cfg
->poolname
= config
.get_val
<std::string
>("rbd_default_pool");
965 std::vector
<const char*>::iterator i
;
966 std::ostringstream err
;
968 for (i
= args
.begin(); i
!= args
.end(); ) {
969 if (ceph_argparse_flag(args
, i
, "-h", "--help", (char*)NULL
)) {
971 } else if (ceph_argparse_flag(args
, i
, "-v", "--version", (char*)NULL
)) {
973 } else if (ceph_argparse_witharg(args
, i
, &cfg
->devpath
, "--device", (char *)NULL
)) {
974 } else if (ceph_argparse_witharg(args
, i
, &cfg
->nbds_max
, err
, "--nbds_max", (char *)NULL
)) {
975 if (!err
.str().empty()) {
976 *err_msg
<< "rbd-nbd: " << err
.str();
979 if (cfg
->nbds_max
< 0) {
980 *err_msg
<< "rbd-nbd: Invalid argument for nbds_max!";
983 } else if (ceph_argparse_witharg(args
, i
, &cfg
->max_part
, err
, "--max_part", (char *)NULL
)) {
984 if (!err
.str().empty()) {
985 *err_msg
<< "rbd-nbd: " << err
.str();
988 if ((cfg
->max_part
< 0) || (cfg
->max_part
> 255)) {
989 *err_msg
<< "rbd-nbd: Invalid argument for max_part(0~255)!";
992 cfg
->set_max_part
= true;
993 } else if (ceph_argparse_flag(args
, i
, "--read-only", (char *)NULL
)) {
994 cfg
->readonly
= true;
995 } else if (ceph_argparse_flag(args
, i
, "--exclusive", (char *)NULL
)) {
996 cfg
->exclusive
= true;
1002 if (args
.begin() != args
.end()) {
1003 if (strcmp(*args
.begin(), "map") == 0) {
1005 } else if (strcmp(*args
.begin(), "unmap") == 0) {
1007 } else if (strcmp(*args
.begin(), "list-mapped") == 0) {
1010 *err_msg
<< "rbd-nbd: unknown command: " << *args
.begin();
1013 args
.erase(args
.begin());
1017 *err_msg
<< "rbd-nbd: must specify command";
1023 if (args
.begin() == args
.end()) {
1024 *err_msg
<< "rbd-nbd: must specify image-or-snap-spec";
1027 if (parse_imgpath(string(*args
.begin()), cfg
) < 0)
1029 args
.erase(args
.begin());
1032 if (args
.begin() == args
.end()) {
1033 *err_msg
<< "rbd-nbd: must specify nbd device path";
1036 cfg
->devpath
= *args
.begin();
1037 args
.erase(args
.begin());
1044 if (args
.begin() != args
.end()) {
1045 *err_msg
<< "rbd-nbd: unknown args: " << *args
.begin();
1052 static int rbd_nbd(int argc
, const char *argv
[])
1056 vector
<const char*> args
;
1057 argv_to_vec(argc
, argv
, args
);
1059 std::ostringstream err_msg
;
1060 r
= parse_args(args
, &err_msg
, &cfg
);
1061 if (r
== HELP_INFO
) {
1064 } else if (r
== VERSION_INFO
) {
1065 std::cout
<< pretty_version_to_str() << std::endl
;
1069 cerr
<< err_msg
.str() << std::endl
;
1075 if (cfg
.imgname
.empty()) {
1076 cerr
<< "rbd-nbd: image name was not specified" << std::endl
;
1080 r
= do_map(argc
, argv
, &cfg
);
1085 r
= do_unmap(cfg
.devpath
);
1090 r
= do_list_mapped_devices();
1103 int main(int argc
, const char *argv
[])
1105 int r
= rbd_nbd(argc
, argv
);
1107 return EXIT_FAILURE
;