From: Yehuda Sadeh Date: Wed, 8 Jan 2014 22:13:27 +0000 (-0800) Subject: cls/user: some fixes + handle old buckets case X-Git-Tag: v0.78~270^2~30 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c8793fbad0d2856623f64822de973d64c38daf03;p=ceph.git cls/user: some fixes + handle old buckets case If a bucket was created prior to the new accounting, we can't substract the old values, as the header stats didn't account for them. Signed-off-by: Yehuda Sadeh --- diff --git a/src/cls/user/cls_user.cc b/src/cls/user/cls_user.cc index b460d6283ea..ba172898bc2 100644 --- a/src/cls/user/cls_user.cc +++ b/src/cls/user/cls_user.cc @@ -149,11 +149,14 @@ static int cls_user_set_buckets_info(cls_method_context_t hctx, bufferlist *in, if (ret < 0) { CLS_LOG(0, "ERROR: get_existing_bucket_entry() key=%s returned %d", key.c_str(), ret); return ret; - } else if (ret >= 0) { + } else if (ret >= 0 && old_entry.user_stats_sync) { dec_header_stats(&header, old_entry); } - CLS_LOG(20, "storing entry by client/op at %s", key.c_str()); + CLS_LOG(20, "storing entry for key=%s size=%lld count=%lld", + key.c_str(), (long long)entry.size, (long long)entry.count); + + entry.user_stats_sync = true; ret = write_entry(hctx, key, entry); if (ret < 0) @@ -161,7 +164,17 @@ static int cls_user_set_buckets_info(cls_method_context_t hctx, bufferlist *in, add_header_stats(&header, entry); } + + bufferlist bl; + + CLS_LOG(20, "header: total bytes=%lld entries=%lld", (long long)header.total_bytes, (long long)header.total_entries); + + ::encode(header, bl); + ret = cls_cxx_map_write_header(hctx, &bl); + if (ret < 0) + return ret; + return 0; } @@ -198,7 +211,9 @@ static int cls_user_remove_bucket(cls_method_context_t hctx, bufferlist *in, buf return ret; } - dec_header_stats(&header, entry); + if (entry.user_stats_sync) { + dec_header_stats(&header, entry); + } CLS_LOG(20, "removing entry at %s", key.c_str()); diff --git a/src/cls/user/cls_user_types.h b/src/cls/user/cls_user_types.h index dde508b0ab7..d38bf9d1b39 100644 --- a/src/cls/user/cls_user_types.h +++ b/src/cls/user/cls_user_types.h @@ -66,11 +66,12 @@ struct cls_user_bucket_entry { size_t size_rounded; time_t creation_time; uint64_t count; + bool user_stats_sync; - cls_user_bucket_entry() : size(0), size_rounded(0), creation_time(0), count(0) {} + cls_user_bucket_entry() : size(0), size_rounded(0), creation_time(0), count(0), user_stats_sync(false) {} void encode(bufferlist& bl) const { - ENCODE_START(5, 5, bl); + ENCODE_START(6, 5, bl); uint64_t s = size; __u32 mt = creation_time; string empty_str; // originally had the bucket name here, but we encode bucket later @@ -81,10 +82,11 @@ struct cls_user_bucket_entry { ::encode(bucket, bl); s = size_rounded; ::encode(s, bl); + ::encode(user_stats_sync, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { - DECODE_START_LEGACY_COMPAT_LEN(5, 5, 5, bl); + DECODE_START_LEGACY_COMPAT_LEN(6, 5, 5, bl); __u32 mt; uint64_t s; string empty_str; // backward compatibility @@ -100,6 +102,8 @@ struct cls_user_bucket_entry { if (struct_v >= 4) ::decode(s, bl); size_rounded = s; + if (struct_v >= 6) + ::decode(user_stats_sync, bl); DECODE_FINISH(bl); } };