]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
objectstore_tool: parse new object description format
authorLoic Dachary <ldachary@redhat.com>
Wed, 26 Nov 2014 23:11:45 +0000 (00:11 +0100)
committerLoic Dachary <ldachary@redhat.com>
Fri, 5 Dec 2014 12:01:36 +0000 (13:01 +0100)
The object format changed from

    {json object}

to

    [pgid,{json object}]

The parser is updated accordingly. If the --pgid is present, check that
it equals the pgid from the object description.

Signed-off-by: Loic Dachary <ldachary@redhat.com>
src/tools/ceph_objectstore_tool.cc

index ed1df237a3e57d4102067321655ed842ed77f945..b96ef07a7c6be5f981bb32414f0b3faa87074950 100644 (file)
@@ -2005,7 +2005,7 @@ void usage(po::options_description &desc)
     cerr << "ceph_objectstore_tool import-rados <pool> [file]" << std::endl;
     cerr << std::endl;
     cerr << "<object> can be a JSON object description as displayed" << std::endl;
-    cerr << "by --op list, with a mandatory --pgid option." << std::endl;
+    cerr << "by --op list." << std::endl;
     cerr << "<object> can be an object name which will be looked up in all" << std::endl;
     cerr << "the OSD's PGs." << std::endl;
     cerr << std::endl;
@@ -2323,7 +2323,31 @@ int main(int argc, char **argv)
          ghobj = found.second;
        }
       } else {
-       ghobj.decode(v);
+       stringstream ss;
+       if (v.type() != json_spirit::array_type) {
+         ss << "object '" << object
+            << "' must be a JSON array but is of type "
+            << v.type() << " instead" << std::endl;
+         throw std::runtime_error(ss.str());
+       }
+       json_spirit::Array array = v.get_array();
+       vector<json_spirit::Value>::iterator i = array.begin();
+       string object_pgidstr = i->get_str();
+       spg_t object_pgid;
+       object_pgid.parse(object_pgidstr.c_str());
+       if (pgidstr.length() > 0) {
+         if (object_pgid != pgid) {
+           ss << "object '" << object
+              << "' has a pgid different from the --pgid="
+              << pgidstr << " option" << std::endl;
+           throw std::runtime_error(ss.str());
+         }
+       } else {
+         pgidstr = object_pgidstr;
+         pgid = object_pgid;
+       }
+       i++;
+       ghobj.decode(*i);
       }
     } catch (std::runtime_error& e) {
       cerr << e.what() << std::endl;