From: Matt Benjamin Date: Mon, 11 Apr 2016 21:49:14 +0000 (-0400) Subject: rgw_file: add encode/decode hooks, emplace_attr X-Git-Tag: v10.2.0~8^2~16 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=34ba7c02adc6870d0f0743b10a8799c52839acdf;p=ceph.git rgw_file: add encode/decode hooks, emplace_attr This change implements attr encode/decode glue for RGWGetObj and RGWPutObj. Both now have attr maps as member variables. To save copies, callers producing attrs can use emplace_attr to move attrs into the map. Signed-off-by: Matt Benjamin --- diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index db59a59419b5..fec2e86bcd34 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -106,6 +106,11 @@ namespace rgw { RGWFileHandle* rgw_fh = get<0>(fhr); rgw_fh->set_size(req.get_size()); rgw_fh->set_mtime(real_clock::to_timespec(req.get_mtime())); + /* restore attributes */ + auto ux_attrs = req.get_attr(RGW_ATTR_UNIX1); + if (ux_attrs) { + rgw_fh->decode_attrs(ux_attrs); + } } goto done; } @@ -487,6 +492,17 @@ namespace rgw { } while (! stop); } /* RGWLibFS::gc */ + void RGWFileHandle::encode_attrs(buffer::list& bl) + { + rgw::encode(*this, bl); + } /* RGWFileHandle::decode_attrs */ + + void RGWFileHandle::decode_attrs(const buffer::list* cbl) + { + auto bl_iter = const_cast(cbl)->begin(); + rgw::decode(*this, bl_iter); + } /* RGWFileHandle::decode_attrs */ + bool RGWFileHandle::reclaim() { fs->fh_cache.remove(fh.fh_hk.object, this, cohort::lru::FLAG_NONE); return true; @@ -706,8 +722,7 @@ namespace rgw { int RGWWriteRequest::exec_finish() { - bufferlist bl, aclbl; - map attrs; + buffer::list bl, aclbl, bl_unix; map::iterator iter; char calc_md5[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1]; unsigned char m[CEPH_CRYPTO_MD5_DIGESTSIZE]; @@ -728,15 +743,18 @@ namespace rgw { buf_to_hex(m, CEPH_CRYPTO_MD5_DIGESTSIZE, calc_md5); etag = calc_md5; + bl.append(etag.c_str(), etag.size() + 1); + emplace_attr(RGW_ATTR_ETAG, std::move(bl)); + policy.encode(aclbl); - attrs[RGW_ATTR_ACL] = aclbl; + emplace_attr(RGW_ATTR_ACL, std::move(aclbl)); - bl.append(etag.c_str(), etag.size() + 1); - attrs[RGW_ATTR_ETAG] = bl; + rgw_fh->encode_attrs(bl_unix); + emplace_attr(RGW_ATTR_UNIX1, std::move(bl_unix)); for (iter = s->generic_attrs.begin(); iter != s->generic_attrs.end(); ++iter) { - bufferlist& attrbl = attrs[iter->first]; + buffer::list& attrbl = attrs[iter->first]; const string& val = iter->second; attrbl.append(val.c_str(), val.size() + 1); } @@ -748,13 +766,13 @@ namespace rgw { * is an SLO or not. Appending the attribute must be performed AFTER * processing any input from user in order to prohibit overwriting. */ if (unlikely(!! slo_info)) { - bufferlist slo_userindicator_bl; + buffer::list slo_userindicator_bl; ::encode("True", slo_userindicator_bl); - attrs[RGW_ATTR_SLO_UINDICATOR] = slo_userindicator_bl; + emplace_attr(RGW_ATTR_SLO_UINDICATOR, std::move(slo_userindicator_bl)); } - op_ret = processor->complete(etag, &mtime, real_time(), attrs, delete_at, if_match, - if_nomatch); + op_ret = processor->complete(etag, &mtime, real_time(), attrs, delete_at, + if_match, if_nomatch); if (! op_ret) { /* update stats */ rgw_fh->set_mtime(real_clock::to_timespec(mtime)); diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index ec8bc97c6e84..aba96d622c65 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -522,7 +522,7 @@ namespace rgw { state.atime = ts; } - void encode(bufferlist& bl) const { + void encode(buffer::list& bl) const { ENCODE_START(1, 1, bl); ::encode(fh.fh_hk.bucket, bl); ::encode(fh.fh_hk.object, bl); @@ -558,6 +558,10 @@ namespace rgw { DECODE_FINISH(bl); } + void decode_attrs(const ceph::buffer::list* bl); + + void encode_attrs(ceph::buffer::list& bl); + virtual bool reclaim(); typedef cohort::lru::LRU FhLRU; @@ -641,6 +645,8 @@ namespace rgw { }; /* RGWFileHandle */ + WRITE_CLASS_ENCODER(RGWFileHandle); + static inline RGWFileHandle* get_rgwfh(struct rgw_file_handle* fh) { return static_cast(fh->fh_private); } @@ -1600,7 +1606,12 @@ public: uint64_t get_size() { return _size; } real_time ctime() { return mod_time; } // XXX real_time mtime() { return mod_time; } - map& get_attrs() { return attrs; } + std::map& get_attrs() { return attrs; } + + buffer::list* get_attr(const std::string& k) { + auto iter = attrs.find(k); + return (iter != attrs.end()) ? &(iter->second) : nullptr; + } virtual bool only_bucket() { return false; } @@ -1641,6 +1652,7 @@ public: virtual int send_response_data(ceph::buffer::list& _bl, off_t s_off, off_t e_off) { /* NOP */ + /* XXX save attrs? */ return 0; } diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index c781eb9ffd48..0f24a0227f26 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -2332,14 +2332,12 @@ void RGWPutObj::execute() unsigned char m[CEPH_CRYPTO_MD5_DIGESTSIZE]; MD5 hash; bufferlist bl, aclbl; - map attrs; int len; map::iterator iter; bool multipart; bool need_calc_md5 = (dlo_manifest == NULL) && (slo_info == NULL); - perfcounter->inc(l_rgw_put); op_ret = -EINVAL; if (s->object.empty()) { diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 825dd93b41e0..1bda388c6396 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -647,7 +647,7 @@ protected: RGWAccessControlPolicy policy; const char *dlo_manifest; RGWSLOInfo *slo_info; - + map attrs; ceph::real_time mtime; uint64_t olh_epoch; string version_id; @@ -674,6 +674,10 @@ public: policy.set_ctx(s->cct); } + void emplace_attr(std::string&& key, buffer::list&& bl) { + attrs.emplace(key, bl); /* key and bl are r-value refs */ + } + virtual RGWPutObjProcessor *select_processor(RGWObjectCtx& obj_ctx, bool *is_multipart); void dispose_processor(RGWPutObjProcessor *processor);