From 4e82209a8aaca24a21345a46cd05671d7335da33 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 18 Dec 2014 13:19:22 -0800 Subject: [PATCH] cls_rgw: only maintain object if there are preserved xattrs rgw.obj_remove op doesn't need to keep the object around if there aren't preserved xattrs found. Signed-off-by: Yehuda Sadeh --- src/cls/rgw/cls_rgw.cc | 48 +++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/cls/rgw/cls_rgw.cc b/src/cls/rgw/cls_rgw.cc index d0b33c395424d..9b05da1f67a7b 100644 --- a/src/cls/rgw/cls_rgw.cc +++ b/src/cls/rgw/cls_rgw.cc @@ -1813,19 +1813,6 @@ static int rgw_obj_remove(cls_method_context_t hctx, bufferlist *in, bufferlist return ret; } - CLS_LOG(20, "%s(): removing object", __func__); - ret = cls_cxx_remove(hctx); - if (ret < 0) { - CLS_LOG(0, "ERROR: %s(): cls_cxx_remove returned %d", __func__, ret); - return ret; - } - - ret = cls_cxx_create(hctx, false); - if (ret < 0) { - CLS_LOG(0, "ERROR: %s(): cls_cxx_create returned %d", __func__, ret); - return ret; - } - map new_attrs; for (list::iterator iter = op.keep_attr_prefixes.begin(); iter != op.keep_attr_prefixes.end(); ++iter) { @@ -1839,16 +1826,39 @@ static int rgw_obj_remove(cls_method_context_t hctx, bufferlist *in, bufferlist break; } - ret = cls_cxx_setxattr(hctx, attr.c_str(), &aiter->second); - CLS_LOG(20, "%s(): setting attr: %s", __func__, attr.c_str()); - if (ret < 0) { - CLS_LOG(0, "ERROR: %s(): cls_cxx_setxattr (attr=%s) returned %d", __func__, attr.c_str(), ret); - return ret; - } + new_attrs[attr] = aiter->second; } } + CLS_LOG(20, "%s(): removing object", __func__); + ret = cls_cxx_remove(hctx); + if (ret < 0) { + CLS_LOG(0, "ERROR: %s(): cls_cxx_remove returned %d", __func__, ret); + return ret; + } + + if (new_attrs.empty()) { + /* no data to keep */ + return 0; + } + + ret = cls_cxx_create(hctx, false); + if (ret < 0) { + CLS_LOG(0, "ERROR: %s(): cls_cxx_create returned %d", __func__, ret); + return ret; + } + + for (map::iterator aiter = new_attrs.begin(); + aiter != new_attrs.end(); ++aiter) { + const string& attr = aiter->first; + ret = cls_cxx_setxattr(hctx, attr.c_str(), &aiter->second); + CLS_LOG(20, "%s(): setting attr: %s", __func__, attr.c_str()); + if (ret < 0) { + CLS_LOG(0, "ERROR: %s(): cls_cxx_setxattr (attr=%s) returned %d", __func__, attr.c_str(), ret); + return ret; + } + } return 0; } -- 2.39.5