Skip to content

Commit

Permalink
Merge pull request #12433 from liupan1111/wip-fix-rbd-nbd-log-sock
Browse files Browse the repository at this point in the history
rbd-nbd: create admin socket only for map command

Reviewed-by: Jason Dillaman <dillaman@redhat.com>
Reviewed-by: Mykola Golub <mgolub@mirantis.com>
  • Loading branch information
Mykola Golub committed Feb 17, 2017
2 parents 92e51fd + 7235265 commit 69e31a8
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/tools/rbd_nbd/rbd-nbd.cc
Expand Up @@ -493,7 +493,7 @@ static int check_device_size(int nbd_index, unsigned long expected_size)
return 0;
}

static int do_map()
static int do_map(int argc, const char *argv[])
{
int r;

Expand All @@ -514,6 +514,15 @@ static int do_map()

Preforker forker;

vector<const char*> args;
argv_to_vec(argc, argv, args);
env_to_vec(args);

auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
CODE_ENVIRONMENT_DAEMON,
CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS);
g_ceph_context->_conf->set_val_or_die("pid_file", "");

if (global_init_prefork(g_ceph_context) >= 0) {
std::string err;
r = forker.prefork(err);
Expand Down Expand Up @@ -707,8 +716,6 @@ static int do_map()

static int do_unmap()
{
common_init_finish(g_ceph_context);

int nbd = open_device(devpath.c_str());
if (nbd < 0) {
cerr << "rbd-nbd: failed to open device: " << devpath << std::endl;
Expand Down Expand Up @@ -750,8 +757,6 @@ static int do_list_mapped_devices()
int m = 0;
int fd[2];

common_init_finish(g_ceph_context);

if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) == -1) {
int r = -errno;
cerr << "rbd-nbd: socketpair failed: " << cpp_strerror(-r) << std::endl;
Expand Down Expand Up @@ -790,11 +795,7 @@ static int rbd_nbd(int argc, const char *argv[])
vector<const char*> args;

argv_to_vec(argc, argv, args);
env_to_vec(args);
auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
CODE_ENVIRONMENT_DAEMON,
CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS);
g_ceph_context->_conf->set_val_or_die("pid_file", "");
md_config_t().parse_argv(args);

std::vector<const char*>::iterator i;
std::ostringstream err;
Expand Down Expand Up @@ -885,7 +886,7 @@ static int rbd_nbd(int argc, const char *argv[])
return EXIT_FAILURE;
}

r = do_map();
r = do_map(argc, argv);
if (r < 0)
return EXIT_FAILURE;
break;
Expand Down

0 comments on commit 69e31a8

Please sign in to comment.