]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: use the unified --export-format option for rbd export and rbd import
authorDongsheng Yang <dongsheng.yang@easystack.cn>
Thu, 20 Oct 2016 11:41:26 +0000 (07:41 -0400)
committerDongsheng Yang <dongsheng.yang@easystack.cn>
Sun, 19 Feb 2017 12:42:03 +0000 (20:42 +0800)
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
doc/man/8/rbd.rst
src/tools/rbd/ArgumentTypes.cc
src/tools/rbd/ArgumentTypes.h
src/tools/rbd/action/Export.cc
src/tools/rbd/action/Import.cc

index f2d0d92a3a60e7fb6e184af5279f5867a82766af..a3471ffc10c9b87b401e0e0dc30e03cfab0ada3a 100644 (file)
@@ -227,9 +227,9 @@ Commands
 :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
@@ -238,8 +238,8 @@ Commands
   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
index eff0726e5ccd554cba41709343ebc9e883744ea8..0bb92f98453ceed02f35d453dda9001c2cf790fe 100644 (file)
@@ -331,6 +331,11 @@ void add_no_error_option(boost::program_options::options_description *opt) {
     (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;
@@ -492,5 +497,19 @@ void validate(boost::any& v, const std::vector<std::string>& values,
   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
index 325b0418b659ccde93bb99ec51c124f5b8bdb81c..c18ceb2ddb4cc55d84766dfdabe9e4afa5741c79 100644 (file)
@@ -114,6 +114,13 @@ struct Format : public TypedValue<std::string> {
 
 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);
 
index 7fada5442ca75deb09388f65a55df5725b7dcaa0..b7fa6a44d21034e973849641f2deba30c7317b9c 100644 (file)
@@ -358,12 +358,6 @@ private:
 
 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)
@@ -520,8 +514,7 @@ void get_arguments(po::options_description *positional,
   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) {
index 453bf5e35dec3f87fddbd9b00f5ad68f03ee3bdd..342f43e14c1defbfa283f9cfbdd297d8c0962e3d 100644 (file)
@@ -294,12 +294,6 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx,
                     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);
@@ -569,8 +563,7 @@ void get_arguments(po::options_description *positional,
   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'