From: Loic Dachary Date: Wed, 26 Nov 2014 23:11:45 +0000 (+0100) Subject: objectstore_tool: parse new object description format X-Git-Tag: v0.80.10~69^2~32 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f30e053fe7b3e5efc679b20cf1b3e2f7f8ed7e54;p=ceph.git objectstore_tool: parse new object description format 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 (cherry picked from commit df9d5c5cfd8b0ff793647a592c7661965cef5c92) --- diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 216e74478fd..2660759fb1e 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -2000,7 +2000,7 @@ void usage(po::options_description &desc) cerr << "ceph-objectstore-tool import-rados [file]" << std::endl; cerr << std::endl; cerr << " 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 << " can be an object name which will be looked up in all" << std::endl; cerr << "the OSD's PGs." << std::endl; cerr << std::endl; @@ -2317,7 +2317,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::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;