From ed5e4341c31183e52607dc81ba6dcc5cfd6c21f5 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Tue, 18 Oct 2011 13:28:30 -0700 Subject: [PATCH] rgw: add content-type to index dirent --- src/rgw/rgw_cls_api.h | 6 +++++- src/rgw/rgw_formats.cc | 11 ++++++++++- src/rgw/rgw_rados.cc | 15 ++++++++++++--- src/rgw/rgw_rados.h | 2 +- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/rgw/rgw_cls_api.h b/src/rgw/rgw_cls_api.h index 7d729844bdfd3..3f2d21d8f2f66 100644 --- a/src/rgw/rgw_cls_api.h +++ b/src/rgw/rgw_cls_api.h @@ -49,9 +49,10 @@ struct rgw_bucket_dir_entry_meta { string owner; string owner_display_name; string tag; + string content_type; void encode(bufferlist &bl) const { - __u8 struct_v = 1; + __u8 struct_v = 2; ::encode(struct_v, bl); ::encode(category, bl); ::encode(size, bl); @@ -59,6 +60,7 @@ struct rgw_bucket_dir_entry_meta { ::encode(etag, bl); ::encode(owner, bl); ::encode(owner_display_name, bl); + ::encode(content_type, bl); } void decode(bufferlist::iterator &bl) { __u8 struct_v; @@ -69,6 +71,8 @@ struct rgw_bucket_dir_entry_meta { ::decode(etag, bl); ::decode(owner, bl); ::decode(owner_display_name, bl); + if (struct_v >= 2) + ::decode(content_type, bl); } }; WRITE_CLASS_ENCODER(rgw_bucket_dir_entry_meta) diff --git a/src/rgw/rgw_formats.cc b/src/rgw/rgw_formats.cc index 092cc028df71d..4265a8bc94886 100644 --- a/src/rgw/rgw_formats.cc +++ b/src/rgw/rgw_formats.cc @@ -126,6 +126,7 @@ void RGWFormatter_Plain::dump_format(const char *name, const char *fmt, ...) min_stack_level = stack.size(); bool should_print = (stack.size() == min_stack_level && !entry.size); + entry.size++; if (!should_print) @@ -223,6 +224,7 @@ void RGWFormatter_Plain::dump_value_int(const char *name, const char *fmt, ...) struct plain_stack_entry& entry = stack.back(); bool should_print = (stack.size() == min_stack_level && !entry.size); + entry.size++; if (!should_print) @@ -231,5 +233,12 @@ void RGWFormatter_Plain::dump_value_int(const char *name, const char *fmt, ...) va_start(ap, fmt); vsnprintf(buf, LARGE_SIZE, fmt, ap); va_end(ap); - write_data("%s\n", buf); + + const char *eol; + if (len) + eol = "\n"; + else + eol = ""; + + write_data("%s%s", eol, buf); } diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index ed1178573d147..73bfb75f8c751 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -623,6 +623,7 @@ int RGWRados::put_obj_meta(void *ctx, std::string& id, rgw_obj& obj, uint64_t s op.create(exclusive); string etag; + string content_type; bufferlist acl_bl; map::iterator iter; @@ -637,6 +638,8 @@ int RGWRados::put_obj_meta(void *ctx, std::string& id, rgw_obj& obj, uint64_t s if (name.compare(RGW_ATTR_ETAG) == 0) { etag = bl.c_str(); + } else if (name.compare(RGW_ATTR_CONTENT_TYPE) == 0) { + content_type = bl.c_str(); } else if (name.compare(RGW_ATTR_ACL) == 0) { acl_bl = bl; } @@ -658,7 +661,7 @@ int RGWRados::put_obj_meta(void *ctx, std::string& id, rgw_obj& obj, uint64_t s utime_t ut = ceph_clock_now(g_ceph_context); r = complete_update_index(bucket, obj.object, tag, epoch, size, - ut, etag, &acl_bl, category); + ut, etag, content_type, &acl_bl, category); if (mtime) { r = io_ctx.stat(oid, NULL, mtime); @@ -1487,7 +1490,7 @@ int RGWRados::prepare_update_index(RGWObjState *state, rgw_bucket& bucket, strin } int RGWRados::complete_update_index(rgw_bucket& bucket, string& oid, string& tag, uint64_t epoch, uint64_t size, - utime_t& ut, string& etag, bufferlist *acl_bl, RGWObjCategory category) + utime_t& ut, string& etag, string& content_type, bufferlist *acl_bl, RGWObjCategory category) { if (bucket.marker.empty()) return 0; @@ -1506,6 +1509,7 @@ int RGWRados::complete_update_index(rgw_bucket& bucket, string& oid, string& tag } ent.owner = owner.get_id(); ent.owner_display_name = owner.get_display_name(); + ent.content_type = content_type; int ret = cls_obj_complete_add(bucket, tag, epoch, ent, category); @@ -1529,6 +1533,7 @@ int RGWRados::clone_objs_impl(void *ctx, rgw_obj& dst_obj, RGWRadosCtx *rctx = (RGWRadosCtx *)ctx; uint64_t size = 0; string etag; + string content_type; bufferlist acl_bl; int r = open_bucket_ctx(bucket, io_ctx); @@ -1552,6 +1557,8 @@ int RGWRados::clone_objs_impl(void *ctx, rgw_obj& dst_obj, if (name.compare(RGW_ATTR_ETAG) == 0) { etag = bl.c_str(); + } else if (name.compare(RGW_ATTR_CONTENT_TYPE) == 0) { + content_type = bl.c_str(); } else if (name.compare(RGW_ATTR_ACL) == 0) { acl_bl = bl; } @@ -1616,7 +1623,7 @@ done: if (ret >= 0) { ret = complete_update_index(bucket, dst_obj.object, tag, epoch, size, - ut, etag, &acl_bl, category); + ut, etag, content_type, &acl_bl, category); } return ret; @@ -2080,6 +2087,7 @@ int RGWRados::cls_obj_complete_op(rgw_bucket& bucket, uint8_t op, string& tag, u call.meta.etag = ent.etag; call.meta.owner = ent.owner; call.meta.owner_display_name = ent.owner_display_name; + call.meta.content_type = ent.content_type; call.meta.category = category; ::encode(call, in); AioCompletion *c = librados::Rados::aio_create_completion(NULL, NULL, NULL); @@ -2153,6 +2161,7 @@ int RGWRados::cls_bucket_list(rgw_bucket& bucket, string start, uint32_t num, ma e.etag = dirent.meta.etag; e.owner = dirent.meta.owner; e.owner_display_name = dirent.meta.owner_display_name; + e.content_type = dirent.meta.content_type; m[e.name] = e; dout(0) << " got " << e.name << dendl; } diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 405d3d513c04d..a2413c8309e7e 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -309,7 +309,7 @@ public: int cls_bucket_head(rgw_bucket& bucket, struct rgw_bucket_dir_header& header); int prepare_update_index(RGWObjState *state, rgw_bucket& bucket, string& oid, string& tag); int complete_update_index(rgw_bucket& bucket, string& oid, string& tag, uint64_t epoch, uint64_t size, - utime_t& ut, string& etag, bufferlist *acl_bl, RGWObjCategory category); + utime_t& ut, string& etag, string& content_type, bufferlist *acl_bl, RGWObjCategory category); int complete_update_index_del(rgw_bucket& bucket, string& oid, string& tag, uint64_t epoch) { return cls_obj_complete_del(bucket, tag, epoch, oid); } -- 2.39.5