From b1bfc3a7e0c9088f01f8ff770ae14f569fbc570d Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 5 Nov 2014 13:28:02 -0800 Subject: [PATCH] rgw: send back ETag on S3 object copy Fixes: #9479 Backport: firefly, giant We didn't send the etag back correctly. Original code assumed the etag resided in the attrs, but attrs only contained request attrs. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_op.cc | 1 + src/rgw/rgw_op.h | 1 + src/rgw/rgw_rados.cc | 25 +++++++++++++++++++++++-- src/rgw/rgw_rados.h | 2 ++ src/rgw/rgw_rest_s3.cc | 9 ++------- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 7522fc52a5324..091abed639fe4 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -2217,6 +2217,7 @@ void RGWCopyObj::execute() replace_attrs, attrs, RGW_OBJ_CATEGORY_MAIN, &s->req_id, /* use req_id as tag */ + &etag, &s->err, copy_obj_progress_cb, (void *)this ); diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 44994f37dff46..89e7f14a12a16 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -503,6 +503,7 @@ protected: string source_zone; string client_id; string op_id; + string etag; off_t last_ofs; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 54856bf3a4dd8..6b6f2b7472074 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -3158,7 +3158,7 @@ int RGWRados::rewrite_obj(const string& bucket_owner, rgw_obj& obj) return ret; } - return copy_obj_data((void *)&rctx, bucket_owner, &handle, end, obj, obj, max_chunk_size, NULL, mtime, attrset, RGW_OBJ_CATEGORY_MAIN, NULL, NULL); + return copy_obj_data((void *)&rctx, bucket_owner, &handle, end, obj, obj, max_chunk_size, NULL, mtime, attrset, RGW_OBJ_CATEGORY_MAIN, NULL, NULL, NULL); } /** @@ -3188,6 +3188,7 @@ int RGWRados::copy_obj(void *ctx, map& attrs, RGWObjCategory category, string *ptag, + string *petag, struct rgw_err *err, void (*progress_cb)(off_t, void *), void *progress_data) @@ -3284,6 +3285,10 @@ int RGWRados::copy_obj(void *ctx, if (ret < 0) goto set_err_state; + if (petag) { + *petag = etag; + } + { /* opening scope so that we can do goto, sorry */ bufferlist& extra_data_bl = processor.get_extra_data(); if (extra_data_bl.length()) { @@ -3349,6 +3354,10 @@ set_err_state: if (ret < 0) return ret; + if (petag) { + *petag = etag; + } + return 0; } @@ -3378,7 +3387,7 @@ set_err_state: } if (copy_data) { /* refcounting tail wouldn't work here, just copy the data */ - return copy_obj_data(ctx, dest_bucket_info.owner, &handle, end, dest_obj, src_obj, max_chunk_size, mtime, 0, src_attrs, category, ptag, err); + return copy_obj_data(ctx, dest_bucket_info.owner, &handle, end, dest_obj, src_obj, max_chunk_size, mtime, 0, src_attrs, category, ptag, petag, err); } RGWObjManifest::obj_iterator miter = astate->manifest.obj_begin(); @@ -3457,6 +3466,14 @@ set_err_state: if (mtime) obj_stat(ctx, dest_obj, NULL, mtime, NULL, NULL, NULL, NULL); + if (petag) { + map::iterator iter = src_attrs.find(RGW_ATTR_ETAG); + if (iter != src_attrs.end()) { + bufferlist& etagbl = iter->second; + *petag = string(etagbl.c_str(), etagbl.length()); + } + } + return 0; done_ret: @@ -3494,6 +3511,7 @@ int RGWRados::copy_obj_data(void *ctx, map& attrs, RGWObjCategory category, string *ptag, + string *petag, struct rgw_err *err) { bufferlist first_chunk; @@ -3539,6 +3557,9 @@ int RGWRados::copy_obj_data(void *ctx, if (iter != attrs.end()) { bufferlist& bl = iter->second; etag = string(bl.c_str(), bl.length()); + if (petag) { + *petag = etag; + } } ret = processor.complete(etag, mtime, set_mtime, attrs); diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 669cb2d71ec02..99a87aac96b15 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -1619,6 +1619,7 @@ public: map& attrs, RGWObjCategory category, string *ptag, + string *petag, struct rgw_err *err, void (*progress_cb)(off_t, void *), void *progress_data); @@ -1634,6 +1635,7 @@ public: map& attrs, RGWObjCategory category, string *ptag, + string *petag, struct rgw_err *err); /** diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index d99a00ea444c2..40b6e9021ea1d 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -1305,13 +1305,8 @@ void RGWCopyObj_ObjStore_S3::send_response() if (ret == 0) { dump_time(s, "LastModified", &mtime); - map::iterator iter = attrs.find(RGW_ATTR_ETAG); - if (iter != attrs.end()) { - bufferlist& bl = iter->second; - if (bl.length()) { - char *etag = bl.c_str(); - s->formatter->dump_string("ETag", etag); - } + if (!etag.empty()) { + s->formatter->dump_string("ETag", etag); } s->formatter->close_section(); rgw_flush_formatter_and_reset(s, s->formatter); -- 2.39.5