]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: new rest api to retrieve object layout 14852/head
authorYehuda Sadeh <yehuda@redhat.com>
Mon, 9 Jan 2017 21:04:43 +0000 (13:04 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 30 Jun 2017 23:44:11 +0000 (16:44 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
(cherry picked from commit 2768583dc486109e49d209243675b99fdd39e92c)

src/rgw/rgw_common.h
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_s3.h

index b852520e4c6ecb7b1f34486b1aae4b7d0f5910e8..112dc09903b506802cb1b27d58b16f4edd5920e8 100644 (file)
@@ -446,7 +446,8 @@ enum RGWOpType {
   RGW_OP_GET_INFO,
 
   /* rgw specific */
-  RGW_OP_ADMIN_SET_METADATA
+  RGW_OP_ADMIN_SET_METADATA,
+  RGW_OP_GET_OBJ_LAYOUT,
 };
 
 class RGWAccessControlPolicy;
index 2731450d8ee8e7d632aef069310492c8d5eec781..bcc7faf54953398976ff69e8e1be7e0382d98260 100644 (file)
@@ -5517,6 +5517,29 @@ void RGWSetAttrs::execute()
   }
 }
 
+void RGWGetObjLayout::pre_exec()
+{
+  rgw_bucket_object_pre_exec(s);
+}
+
+void RGWGetObjLayout::execute()
+{
+  rgw_obj obj(s->bucket, s->object.name);
+  obj.set_instance(s->object.instance);
+  target = new RGWRados::Object(store, s->bucket_info, *static_cast<RGWObjectCtx *>(s->obj_ctx), obj);
+  RGWRados::Object::Read stat_op(target);
+
+  op_ret = stat_op.prepare();
+  if (op_ret < 0) {
+    return;
+  }
+
+  head_obj = stat_op.state.obj;
+
+  op_ret = target->get_manifest(&manifest);
+}
+
+
 RGWHandler::~RGWHandler()
 {
 }
index 44a693c10bb805abddb49fcde8ab9efba5fae79a..62f4e3b838ab1e560c9628865b8ee91f0a22b75b 100644 (file)
@@ -1764,4 +1764,32 @@ public:
   virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; }
 };
 
+class RGWGetObjLayout : public RGWOp {
+protected:
+  RGWRados::Object *target{nullptr};
+  RGWObjManifest *manifest{nullptr};
+  rgw_obj head_obj;
+
+public:
+  RGWGetObjLayout() {
+    delete target;
+  }
+
+  int check_caps(RGWUserCaps& caps) {
+    return caps.check_cap("admin", RGW_CAP_READ);
+  }
+  int verify_permission() {
+    return check_caps(s->user->caps);
+  }
+  void pre_exec();
+  void execute();
+
+  virtual void send_response() = 0;
+  virtual const string name() { return "get_obj_layout"; }
+  virtual RGWOpType get_type() { return RGW_OP_GET_OBJ_LAYOUT; }
+  virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; }
+};
+
+
+
 #endif /* CEPH_RGW_OP_H */
index 47f3790b3313f8bec57941863b15ab60059f5621..85503de79cfb5d4741248f21c2abdf39e273cf5c 100644 (file)
@@ -8644,6 +8644,19 @@ int RGWRados::get_obj_state(RGWObjectCtx *rctx, rgw_obj& obj, RGWObjState **stat
   return ret;
 }
 
+int RGWRados::Object::get_manifest(RGWObjManifest **pmanifest)
+{
+  RGWObjState *astate;
+  int r = get_state(&astate, true);
+  if (r < 0) {
+    return r;
+  }
+
+  *pmanifest = &astate->manifest;
+
+  return 0;
+}
+
 int RGWRados::Object::Read::get_attr(const char *name, bufferlist& dest)
 {
   RGWObjState *state;
index c44cd12c67bd4220ac61d2dbfa3557500aeabad9..c548754c2f6ba216e59a1b42d87d163b8a87e2f4 100644 (file)
@@ -2368,6 +2368,7 @@ public:
     rgw_obj& get_obj() { return obj; }
     RGWObjectCtx& get_ctx() { return ctx; }
     RGWBucketInfo& get_bucket_info() { return bucket_info; }
+    int get_manifest(RGWObjManifest **pmanifest);
 
     int get_bucket_shard(BucketShard **pbs) {
       if (!bs_initialized) {
index 63b100e19a69d87a45fb94adde32fffbe7e98890..a745b95f5a2ef5a6f0a23afdebb756c33151d673 100644 (file)
@@ -2898,6 +2898,38 @@ void RGWDeleteMultiObj_ObjStore_S3::end_response()
   rgw_flush_formatter_and_reset(s, s->formatter);
 }
 
+void RGWGetObjLayout_ObjStore_S3::send_response()
+{
+  if (op_ret)
+    set_req_state_err(s, op_ret);
+  dump_errno(s);
+  end_header(s, this, "application/json");
+
+  JSONFormatter f;
+
+  if (op_ret < 0) {
+    return;
+  }
+
+  f.open_object_section("result");
+  ::encode_json("head", head_obj, &f);
+  ::encode_json("manifest", *manifest, &f);
+  f.open_array_section("data_location");
+  for (auto miter = manifest->obj_begin(); miter != manifest->obj_end(); ++miter) {
+    f.open_object_section("obj");
+    rgw_obj loc = miter.get_location();
+    ::encode_json("ofs", miter.get_ofs(), &f);
+    ::encode_json("loc", loc, &f);
+    ::encode_json("loc_ofs", miter.location_ofs(), &f);
+    ::encode_json("loc_size", miter.get_stripe_size(), &f);
+    f.close_section();
+    rgw_flush_formatter(s, &f);
+  }
+  f.close_section();
+  f.close_section();
+  rgw_flush_formatter(s, &f);
+}
+
 RGWOp *RGWHandler_REST_Service_S3::op_get()
 {
   if (is_usage_op()) {
@@ -3035,6 +3067,8 @@ RGWOp *RGWHandler_REST_Obj_S3::op_get()
     return new RGWGetACLs_ObjStore_S3;
   } else if (s->info.args.exists("uploadId")) {
     return new RGWListMultipart_ObjStore_S3;
+  } else if (s->info.args.exists("layout")) {
+    return new RGWGetObjLayout_ObjStore_S3;
   }
   return get_obj_op(true);
 }
index 91c73613ab677113602ee24cf8c2c5d44f1e43b4..edc7649090cf4fae34ca3d613c1744134a868960 100644 (file)
@@ -398,6 +398,14 @@ public:
   void end_response();
 };
 
+class RGWGetObjLayout_ObjStore_S3 : public RGWGetObjLayout {
+public:
+  RGWGetObjLayout_ObjStore_S3() {}
+  ~RGWGetObjLayout_ObjStore_S3() {}
+
+  void send_response();
+};
+
 class RGW_Auth_S3_Keystone_ValidateToken : public RGWHTTPClient {
 private:
   bufferlist rx_buffer;