:command:`export` [--export-format *format (1 or 2)*] (*image-spec* | *snap-spec*) [*dest-path*]
Exports image to dest path (use - for stdout).
The --export-format accepts '1' or '2' currently. Format 2 allow us to export not only the content
- of image, but also the snapshots and other priorities, such as image_order, features.
+ of image, but also the snapshots and other properties, such as image_order, features.
-:command:`import` [--import-format *format (1 or 2)*] [--image-format *format-id*] [--object-size *size-in-B/K/M*] [--stripe-unit *size-in-B/K/M* --stripe-count *num*] [--image-feature *feature-name*]... [--image-shared] *src-path* [*image-spec*]
+:command:`import` [--export-format *format (1 or 2)*] [--image-format *format-id*] [--object-size *size-in-B/K/M*] [--stripe-unit *size-in-B/K/M* --stripe-count *num*] [--image-feature *feature-name*]... [--image-shared] *src-path* [*image-spec*]
Creates a new image and imports its data from path (use - for
stdin). The import operation will try to create sparse rbd images
if possible. For import from stdin, the sparsification unit is
The --stripe-unit and --stripe-count arguments are optional, but must be
used together.
- The --import-format accepts '1' or '2' currently. Format 2 allow us to import not only the content
- of image, but also the snapshots and other priorities, such as image_order, features.
+ The --export-format accepts '1' or '2' currently. Format 2 allow us to import not only the content
+ of image, but also the snapshots and other properties, such as image_order, features.
:command:`export-diff` [--from-snap *snap-name*] [--whole-object] (*image-spec* | *snap-spec*) *dest-path*
Exports an incremental diff for an image to dest path (use - for stdout). If
(NO_ERROR.c_str(), po::bool_switch(), "continue after error");
}
+void add_export_format_option(boost::program_options::options_description *opt) {
+ opt->add_options()
+ ("export-format", po::value<ExportFormat>(), "format of image file");
+}
+
std::string get_short_features_help(bool append_suffix) {
std::ostringstream oss;
bool first_feature = true;
throw po::validation_error(po::validation_error::invalid_option_value);
}
+void validate(boost::any& v, const std::vector<std::string>& values,
+ ExportFormat *target_type, int) {
+ po::validators::check_first_occurrence(v);
+ const std::string &s = po::validators::get_single_string(values);
+
+ std::string parse_error;
+ uint64_t format = strict_sistrtoll(s.c_str(), &parse_error);
+ if (!parse_error.empty() || (format != 1 && format != 2)) {
+ throw po::validation_error(po::validation_error::invalid_option_value);
+ }
+
+ v = boost::any(format);
+}
+
} // namespace argument_types
} // namespace rbd
struct JournalObjectSize {};
+struct ExportFormat {};
+
+void validate(boost::any& v, const std::vector<std::string>& values,
+ ExportFormat *target_type, int);
+
+void add_export_format_option(boost::program_options::options_description *opt);
+
std::string get_name_prefix(ArgumentModifier modifier);
std::string get_description_prefix(ArgumentModifier modifier);
static int do_export(librbd::Image& image, const char *path, bool no_progress, int export_format)
{
- // check current supported formats.
- if (export_format != 1 && export_format != 2) {
- std::cerr << "rbd: wrong file format to import" << std::endl;
- return -EINVAL;
- }
-
librbd::image_info_t info;
int64_t r = image.stat(info, sizeof(info));
if (r < 0)
at::add_path_options(positional, options,
"export file (or '-' for stdout)");
at::add_no_progress_option(options);
- options->add_options()
- ("export-format", po::value<int>(), "format to export image");
+ at::add_export_format_option(options);
}
int execute(const po::variables_map &vm) {
librbd::ImageOptions& opts, bool no_progress,
int import_format)
{
- // check current supported formats.
- if (import_format != 1 && import_format != 2) {
- std::cerr << "rbd: wrong file format to import" << std::endl;
- return -EINVAL;
- }
-
int fd, r;
struct stat stat_buf;
utils::ProgressContext pc("Importing image", no_progress);
at::add_image_spec_options(positional, options, at::ARGUMENT_MODIFIER_DEST);
at::add_create_image_options(options, true);
at::add_no_progress_option(options);
- options->add_options()
- ("import-format", po::value<int>(), "format of the file to be imported");
+ at::add_export_format_option(options);
// TODO legacy rbd allowed import to accept both 'image'/'dest' and
// 'pool'/'dest-pool'