Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbd-nbd: create admin socket only for map command #12433

Merged
merged 1 commit into from Feb 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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