Show the rbd images that are mapped via the rbd kernel module
(default) or other supported device.
-:command:`device map` [-t | --device-type *device-type*] [--show-cookie] [--read-only] [--exclusive] [-o | --options *device-options*] *image-spec* | *snap-spec*
+:command:`device map` [-t | --device-type *device-type*] [--cookie *device-cookie*] [--show-cookie] [--read-only] [--exclusive] [-o | --options *device-options*] *image-spec* | *snap-spec*
Map the specified image to a block device via the rbd kernel module
(default) or other supported device (*nbd* on Linux or *ggate* on
FreeBSD).
The --options argument is a comma separated list of device type
specific options (opt1,opt2=val,...).
-:command:`device attach` [-t | --device-type *device-type*] --device *device-path* [--cookie *device-cookie*] [--read-only] [--exclusive] [--force] [-o | --options *device-options*] *image-spec* | *snap-spec*
+:command:`device attach` [-t | --device-type *device-type*] --device *device-path* [--cookie *device-cookie*] [--show-cookie] [--read-only] [--exclusive] [--force] [-o | --options *device-options*] *image-spec* | *snap-spec*
Attach the specified image to the specified block device (currently only
`nbd` on Linux). This operation is unsafe and should not be normally used.
In particular, specifying the wrong image or the wrong block device may
rbd help device attach
usage: rbd device attach [--device-type <device-type>] [--pool <pool>]
[--namespace <namespace>] [--image <image>]
- [--snap <snap>] --device <device> [--cookie <cookie>]
- [--read-only] [--force] [--exclusive] [--quiesce]
+ [--snap <snap>] --device <device> [--show-cookie]
+ [--cookie <cookie>] [--read-only] [--force]
+ [--exclusive] [--quiesce]
[--quiesce-hook <quiesce-hook>] [--options <options>]
<image-or-snap-spec>
--image arg image name
--snap arg snapshot name
--device arg specify device path
+ --show-cookie show device cookie
--cookie arg specify device cookie
--read-only attach read-only
--force force attach
rbd help device map
usage: rbd device map [--device-type <device-type>] [--pool <pool>]
[--namespace <namespace>] [--image <image>]
- [--snap <snap>] [--show-cookie] [--read-only]
- [--exclusive] [--quiesce]
+ [--snap <snap>] [--show-cookie] [--cookie <cookie>]
+ [--read-only] [--exclusive] [--quiesce]
[--quiesce-hook <quiesce-hook>] [--options <options>]
<image-or-snap-spec>
--image arg image name
--snap arg snapshot name
--show-cookie show device cookie
+ --cookie arg specify device cookie
--read-only map read-only
--exclusive disable automatic exclusive lock transitions
--quiesce use quiesce hooks
at::ARGUMENT_MODIFIER_NONE);
options->add_options()
("show-cookie", po::bool_switch(), "show device cookie")
+ ("cookie", po::value<std::string>(), "specify device cookie")
("read-only", po::bool_switch(), "map read-only")
("exclusive", po::bool_switch(), "disable automatic exclusive lock transitions")
("quiesce", po::bool_switch(), "use quiesce hooks")
at::ARGUMENT_MODIFIER_NONE);
options->add_options()
("device", po::value<std::string>()->required(), "specify device path")
+ ("show-cookie", po::bool_switch(), "show device cookie")
("cookie", po::value<std::string>(), "specify device cookie")
("read-only", po::bool_switch(), "attach read-only")
("force", po::bool_switch(), "force attach")
return -EINVAL;
}
+ if (vm["show-cookie"].as<bool>()) {
+ args.push_back("--show-cookie");
+ }
+
if (vm.count("cookie")) {
args.push_back("--cookie");
args.push_back(vm["cookie"].as<std::string>());
args.push_back("--show-cookie");
}
+ if (vm.count("cookie")) {
+ args.push_back("--cookie");
+ args.push_back(vm["cookie"].as<std::string>());
+ }
+
if (vm["read-only"].as<bool>()) {
args.push_back("--read-only");
}
<< " (default: " << Config().reattach_timeout << ")\n"
<< " --try-netlink Use the nbd netlink interface\n"
<< " --show-cookie Show device cookie\n"
- << " --cookie Specify device cookie for attach\n"
+ << " --cookie Specify device cookie\n"
<< "\n"
<< "List options:\n"
<< " --format plain|json|xml Output format (default: plain)\n"
use_netlink = cfg->try_netlink || reconnect;
if (use_netlink) {
- if (!reconnect) {
+ // generate when the cookie is not supplied at CLI
+ if (!reconnect && cfg->cookie.empty()) {
uuid_d uuid_gen;
uuid_gen.generate_random();
cfg->cookie = uuid_gen.to_string();
goto close_nbd;
std::string cookie;
- if (use_netlink && !cfg->cookie.empty()) {
+ if (use_netlink) {
cookie = get_cookie(cfg->devpath);
- ceph_assert(cookie == cfg->cookie);
+ ceph_assert(cookie == cfg->cookie || cookie.empty());
}
if (cfg->show_cookie && !cookie.empty()) {
cout << cfg->devpath << " " << cookie << std::endl;