]>
git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd/action/Wnbd.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "tools/rbd/ArgumentTypes.h"
5 #include "tools/rbd/Shell.h"
6 #include "tools/rbd/Utils.h"
7 #include "include/stringify.h"
8 #include "common/SubProcess.h"
10 #include <boost/algorithm/string.hpp>
11 #include <boost/algorithm/string/predicate.hpp>
12 #include <boost/program_options.hpp>
18 namespace at
= argument_types
;
19 namespace po
= boost::program_options
;
22 static int call_wnbd_cmd(const po::variables_map
&vm
,
23 const std::vector
<std::string
> &args
,
24 const std::vector
<std::string
> &ceph_global_init_args
) {
25 char exe_path
[PATH_MAX
];
26 ssize_t exe_path_bytes
= get_self_exe_path(exe_path
, PATH_MAX
);
28 if (exe_path_bytes
> 4) {
29 // Drop .exe suffix as we're going to add the "-wnbd" suffix.
30 exe_path
[strlen(exe_path
) - 4] = '\0';
34 if (exe_path_bytes
< 0) {
35 strcpy(exe_path
, "rbd-wnbd");
37 if (snprintf(exe_path
+ exe_path_bytes
,
38 sizeof(exe_path
) - exe_path_bytes
,
44 SubProcess
process(exe_path
, SubProcess::KEEP
, SubProcess::KEEP
, SubProcess::KEEP
);
46 for (auto &arg
: ceph_global_init_args
) {
47 process
.add_cmd_arg(arg
.c_str());
50 for (auto &arg
: args
) {
51 process
.add_cmd_arg(arg
.c_str());
54 if (process
.spawn()) {
55 std::cerr
<< "rbd: failed to run rbd-wnbd: " << process
.err() << std::endl
;
58 int exit_code
= process
.join();
60 std::cerr
<< "rbd: rbd-wnbd failed with error: " << process
.err() << std::endl
;
68 int execute_list(const po::variables_map
&vm
,
69 const std::vector
<std::string
> &ceph_global_init_args
) {
71 std::cerr
<< "rbd: wnbd is only supported on Windows" << std::endl
;
74 std::vector
<std::string
> args
;
76 args
.push_back("list");
78 if (vm
.count("format")) {
79 args
.push_back("--format");
80 args
.push_back(vm
["format"].as
<at::Format
>().value
);
82 if (vm
["pretty-format"].as
<bool>()) {
83 args
.push_back("--pretty-format");
86 return call_wnbd_cmd(vm
, args
, ceph_global_init_args
);
90 int execute_map(const po::variables_map
&vm
,
91 const std::vector
<std::string
> &ceph_global_init_args
) {
93 std::cerr
<< "rbd: wnbd is only supported on Windows" << std::endl
;
96 std::vector
<std::string
> args
;
98 args
.push_back("map");
100 int r
= utils::get_image_or_snap_spec(vm
, &img
);
106 if (vm
["read-only"].as
<bool>()) {
107 args
.push_back("--read-only");
110 if (vm
["exclusive"].as
<bool>()) {
111 args
.push_back("--exclusive");
114 if (vm
.count("options")) {
115 utils::append_options_as_args(vm
["options"].as
<std::vector
<std::string
>>(),
119 return call_wnbd_cmd(vm
, args
, ceph_global_init_args
);
123 int execute_unmap(const po::variables_map
&vm
,
124 const std::vector
<std::string
> &ceph_global_init_args
) {
126 std::cerr
<< "rbd: wnbd is only supported on Windows" << std::endl
;
129 std::string image_name
;
131 int r
= utils::get_image_or_snap_spec(vm
, &image_name
);
136 std::vector
<std::string
> args
;
138 args
.push_back("unmap");
139 args
.push_back(image_name
);
141 if (vm
.count("options")) {
142 utils::append_options_as_args(vm
["options"].as
<std::vector
<std::string
>>(),
146 return call_wnbd_cmd(vm
, args
, ceph_global_init_args
);
150 int execute_attach(const po::variables_map
&vm
,
151 const std::vector
<std::string
> &ceph_global_init_args
) {
153 std::cerr
<< "rbd: wnbd is only supported on Windows" << std::endl
;
155 std::cerr
<< "rbd: wnbd attach command not supported" << std::endl
;
160 int execute_detach(const po::variables_map
&vm
,
161 const std::vector
<std::string
> &ceph_global_init_args
) {
163 std::cerr
<< "rbd: wnbd is only supported on Windows" << std::endl
;
165 std::cerr
<< "rbd: wnbd detach command not supported" << std::endl
;
171 } // namespace action