Skip to content

Commit dc46e27

Browse files
committed
rgw_cksum: address review comments
* remove rgw_cksum_pipe state enum, not needed [Casey review] * remove a format that just took a single string substitution and passed it to an iostream [Casey review] * use boost::to_upper* [Casey review] * remove unused RGW_ATTR_CKSUM_ALGORITHM decl [Casey review] * negate error code values in two places [Casey review] * split cksum digests from base type decls * resolve comment when checksum requested but not available * remove redundant memset * remove junk from rgw_blake3_digest.h * s/ldpp_dout + fmt::format/ldpp_dout_fmt/g; * fix conditional return of parts_count from RGWRados::Object::prepare(). A value for parts_count should be returned iff a *multipart* object manifest exists. * remove /tmp output test * finish moving ceph_crypto headers out of rgw_cksum.h * consume the optional in multipart_parts_count * target_attrs can be a reference (but not const) Signed-off-by: Matt Benjamin <[email protected]>
1 parent ae4a871 commit dc46e27

File tree

10 files changed

+88
-225
lines changed

10 files changed

+88
-225
lines changed

src/rgw/driver/rados/rgw_rados.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6750,7 +6750,10 @@ int RGWRados::Object::Read::prepare(optional_yield y, const DoutPrefixProvider *
67506750
if (manifest /* params.parts_count */) {
67516751
RGWObjManifest::obj_iterator end = manifest->obj_end(dpp);
67526752
auto cur_part_id = end.get_cur_part_id();
6753-
params.parts_count = (cur_part_id == 1) ? 1 : cur_part_id - 1;;
6753+
if (cur_part_id != 0 ) {
6754+
/* end.get_cur_part_id() returns 0 for non-multipart manifests */
6755+
params.parts_count = (cur_part_id == 1) ? 1 : cur_part_id - 1;
6756+
}
67546757
}
67556758

67566759
if (!astate->exists) {

src/rgw/rgw_blake3_digest.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
#include <stdio.h>
2020
#include "BLAKE3/c/blake3.h"
2121

22-
#define XXH_INLINE_ALL 1 /* required for streaming variants */
23-
#include "xxhash.h"
24-
2522
namespace rgw { namespace digest {
2623

2724
class Blake3 {

src/rgw/rgw_cksum.h

Lines changed: 12 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#pragma once
1515

16+
#include <boost/algorithm/string/case_conv.hpp>
1617
#include <boost/algorithm/string/predicate.hpp>
1718
#include <cstdint>
1819
#include <cstring>
@@ -22,15 +23,9 @@
2223
#include <string_view>
2324
#include <array>
2425
#include <iterator>
25-
#include <boost/variant.hpp>
26-
#include <boost/blank.hpp>
2726
#include <boost/algorithm/string.hpp>
2827
#include "fmt/format.h"
29-
#include "common/ceph_crypto.h"
3028
#include "common/armor.h"
31-
#include "rgw_blake3_digest.h"
32-
#include "rgw_crc_digest.h"
33-
#include "rgw_xxh_digest.h"
3429
#include <boost/algorithm/hex.hpp>
3530
#include "rgw_hex.h"
3631
#include "rgw_b64.h"
@@ -83,11 +78,6 @@ namespace rgw { namespace cksum {
8378

8479
namespace ba = boost::algorithm;
8580

86-
static inline std::string safe_upcase_str(std::string s) {
87-
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
88-
return s;
89-
}
90-
9181
class Cksum {
9282
public:
9383
static constexpr std::array<Desc, 8> checksums =
@@ -112,8 +102,10 @@ namespace rgw { namespace cksum {
112102
Cksum(Type _type, const char* _armored_text)
113103
: type(_type) {
114104
const auto& ckd = checksums[uint16_t(type)];
115-
(void) ceph_unarmor((char*) digest.begin(), (char*) digest.begin() + ckd.digest_size,
116-
_armored_text, _armored_text + std::strlen(_armored_text));
105+
(void) ceph_unarmor((char*) digest.begin(),
106+
(char*) digest.begin() + ckd.digest_size,
107+
_armored_text,
108+
_armored_text + std::strlen(_armored_text));
117109
}
118110

119111
const char* type_string() const {
@@ -138,7 +130,7 @@ namespace rgw { namespace cksum {
138130

139131
std::string element_name() const {
140132
std::string ts{type_string()};
141-
return fmt::format("Checksum{}", safe_upcase_str(ts));
133+
return fmt::format("Checksum{}", boost::to_upper_copy(ts));
142134
}
143135

144136
std::string_view raw() const {
@@ -150,7 +142,6 @@ namespace rgw { namespace cksum {
150142
std::string hs;
151143
const auto& ckd = checksums[uint16_t(type)];
152144
hs.resize(ckd.armored_size);
153-
memset(hs.data(), 0, hs.length());
154145
ceph_armor((char*) hs.data(), (char*) hs.data() + ckd.armored_size,
155146
(char*) digest.begin(), (char*) digest.begin() +
156147
ckd.digest_size);
@@ -199,6 +190,12 @@ namespace rgw { namespace cksum {
199190

200191
static inline const std::optional<rgw::cksum::Cksum> no_cksum{std::nullopt};
201192

193+
static inline std::string to_string(const Type type) {
194+
std::string hs;
195+
const auto& ckd = Cksum::checksums[uint16_t(type)];
196+
return ckd.name;
197+
}
198+
202199
static inline Type parse_cksum_type(const char* name)
203200
{
204201
for (const auto& ck : Cksum::checksums) {
@@ -226,117 +223,4 @@ namespace rgw { namespace cksum {
226223
parse_cksum_type_hdr(hdr_name) != Type::none;
227224
} /* is_cksum_hdr */
228225

229-
class Digest {
230-
public:
231-
virtual void Restart() = 0;
232-
virtual void Update (const unsigned char *input, size_t length) = 0;
233-
virtual void Update(const ceph::buffer::list& bl) = 0;
234-
virtual void Final (unsigned char *digest) = 0;
235-
virtual ~Digest() {}
236-
};
237-
238-
template<class T>
239-
class TDigest : public Digest
240-
{
241-
T d;
242-
public:
243-
TDigest() {}
244-
TDigest(TDigest&& rhs) noexcept
245-
: d(std::move(rhs.d))
246-
{}
247-
void Restart() override { d.Restart(); }
248-
void Update(const unsigned char* data, uint64_t len) override {
249-
d.Update(data, len);
250-
}
251-
void Update(const ceph::buffer::list& bl) {
252-
for (auto& p : bl.buffers()) {
253-
d.Update((const unsigned char *)p.c_str(), p.length());
254-
}
255-
}
256-
void Final(unsigned char* digest) override {
257-
d.Final(digest);
258-
}
259-
};
260-
261-
typedef TDigest<rgw::digest::Blake3> Blake3;
262-
typedef TDigest<rgw::digest::Crc32> Crc32;
263-
typedef TDigest<rgw::digest::Crc32c> Crc32c;
264-
typedef TDigest<rgw::digest::XXH3> XXH3;
265-
typedef TDigest<ceph::crypto::SHA1> SHA1;
266-
typedef TDigest<ceph::crypto::SHA256> SHA256;
267-
typedef TDigest<ceph::crypto::SHA512> SHA512;
268-
269-
typedef boost::variant<boost::blank,
270-
Blake3,
271-
Crc32,
272-
Crc32c,
273-
XXH3,
274-
SHA1,
275-
SHA256,
276-
SHA512> DigestVariant;
277-
278-
struct get_digest_ptr : public boost::static_visitor<Digest*>
279-
{
280-
get_digest_ptr() {};
281-
Digest* operator()(const boost::blank& b) const { return nullptr; }
282-
Digest* operator()(Blake3& digest) const { return &digest; }
283-
Digest* operator()(Crc32& digest) const { return &digest; }
284-
Digest* operator()(Crc32c& digest) const { return &digest; }
285-
Digest* operator()(XXH3& digest) const { return &digest; }
286-
Digest* operator()(SHA1& digest) const { return &digest; }
287-
Digest* operator()(SHA256& digest) const { return &digest; }
288-
Digest* operator()(SHA512& digest) const { return &digest; }
289-
};
290-
291-
static inline Digest* get_digest(DigestVariant& ev)
292-
{
293-
return boost::apply_visitor(get_digest_ptr{}, ev);
294-
}
295-
296-
static inline DigestVariant digest_factory(const Type cksum_type)
297-
{
298-
switch (cksum_type) {
299-
case Type::blake3:
300-
return Blake3();
301-
break;
302-
case Type::sha256:
303-
return SHA256();
304-
break;
305-
case Type::crc32:
306-
return Crc32();
307-
break;
308-
case Type::crc32c:
309-
return Crc32c();
310-
break;
311-
case Type::xxh3:
312-
return XXH3();
313-
break;
314-
case Type::sha512:
315-
return SHA512();
316-
break;
317-
case Type::sha1:
318-
return SHA1();
319-
break;
320-
case Type::none:
321-
break;
322-
};
323-
return boost::blank();
324-
} /* digest_factory */
325-
326-
static inline Cksum finalize_digest(Digest* digest, Type type)
327-
{
328-
Cksum cksum(type);
329-
if (digest) {
330-
auto data = cksum.digest.data();
331-
digest->Final(data);
332-
}
333-
return cksum;
334-
}
335-
336-
static inline std::string to_string(const Type type) {
337-
std::string hs;
338-
const auto& ckd = Cksum::checksums[uint16_t(type)];
339-
return ckd.name;
340-
}
341-
342226
}} /* namespace */

src/rgw/rgw_cksum_digest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <boost/variant.hpp>
1717
#include <boost/blank.hpp>
18+
#include "common/ceph_crypto.h"
1819
#include "rgw_blake3_digest.h"
1920
#include "rgw_crc_digest.h"
2021
#include "rgw_xxh_digest.h"

src/rgw/rgw_cksum_pipe.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ namespace rgw::putobj {
3030
: Pipe(next),
3131
_type(_typ),
3232
dv(rgw::cksum::digest_factory(_type)),
33-
_digest(cksum::get_digest(dv)), cksum_hdr(_hdr),
34-
_state(State::DIGEST)
33+
_digest(cksum::get_digest(dv)), cksum_hdr(_hdr)
3534
{}
3635

3736
std::unique_ptr<RGWPutObj_Cksum> RGWPutObj_Cksum::Factory(

src/rgw/rgw_cksum_pipe.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
#include <utility>
2020
#include <tuple>
2121
#include <cstring>
22-
#include "rgw_cksum.h"
22+
#include <boost/algorithm/string/case_conv.hpp>
23+
#include "rgw_cksum_digest.h"
2324
#include "rgw_common.h"
2425
#include "rgw_putobj.h"
2526

@@ -76,7 +77,7 @@ namespace rgw::putobj {
7677
ix <= uint16_t(cksum::Type::blake3); ++ix) {
7778
cksum_type = cksum::Type(ix);
7879
auto hk = fmt::format("HTTP_X_AMZ_CHECKSUM_{}",
79-
safe_upcase_str(to_string(cksum_type)));
80+
boost::to_upper_copy(to_string(cksum_type)));
8081
auto hv = env.get(hk.c_str());
8182
if (hv) {
8283
return
@@ -90,18 +91,11 @@ namespace rgw::putobj {
9091
// PutObj filter for streaming checksums
9192
class RGWPutObj_Cksum : public rgw::putobj::Pipe {
9293

93-
enum class State : uint16_t {
94-
START,
95-
DIGEST,
96-
FINAL
97-
};
98-
9994
cksum::Type _type;
10095
cksum::DigestVariant dv;
10196
cksum::Digest* _digest;
10297
cksum::Cksum _cksum;
10398
cksum_hdr_t cksum_hdr;
104-
State _state;
10599

106100
public:
107101

@@ -118,15 +112,13 @@ namespace rgw::putobj {
118112
cksum::Type type() { return _type; }
119113
cksum::Digest* digest() const { return _digest; }
120114
const cksum::Cksum& cksum() { return _cksum; };
121-
State state() const { return _state; }
122115

123116
const cksum_hdr_t& header() const {
124117
return cksum_hdr;
125118
}
126119

127120
const cksum::Cksum& finalize() {
128121
_cksum = finalize_digest(_digest, _type);
129-
_state = State::FINAL;
130122
return _cksum;
131123
}
132124

@@ -137,7 +129,7 @@ namespace rgw::putobj {
137129
}
138130

139131
VerifyResult verify(const RGWEnv& env) {
140-
if (_state == State::DIGEST) [[likely]] {
132+
if (_cksum.type == cksum::Type::none) [[likely]] {
141133
(void) finalize();
142134
}
143135
auto hv = expected(env);

src/rgw/rgw_common.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <boost/container/flat_map.hpp>
2727
#include <boost/container/flat_set.hpp>
2828

29+
#include "common/dout_fmt.h"
2930
#include "common/ceph_crypto.h"
3031
#include "common/random_string.h"
3132
#include "common/tracer.h"
@@ -85,7 +86,6 @@ using ceph::crypto::MD5;
8586
#define RGW_ATTR_CORS RGW_ATTR_PREFIX "cors"
8687
#define RGW_ATTR_ETAG RGW_ATTR_PREFIX "etag"
8788
#define RGW_ATTR_CKSUM RGW_ATTR_PREFIX "cksum"
88-
#define RGW_ATTR_CKSUM_ALGORITHM RGW_ATTR_PREFIX "x-amz-checksum-algorithm"
8989
#define RGW_ATTR_BUCKETS RGW_ATTR_PREFIX "buckets"
9090
#define RGW_ATTR_META_PREFIX RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX
9191
#define RGW_ATTR_CONTENT_TYPE RGW_ATTR_PREFIX "content_type"
@@ -1992,16 +1992,6 @@ static inline std::string ys_header_mangle(std::string_view name)
19921992
return out;
19931993
} /* ys_header_mangle */
19941994

1995-
static inline std::string& upcase_str(std::string& s) {
1996-
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
1997-
return s;
1998-
}
1999-
2000-
static inline std::string safe_upcase_str(std::string s) {
2001-
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
2002-
return s;
2003-
}
2004-
20051995
extern int rgw_bucket_parse_bucket_instance(const std::string& bucket_instance, std::string *bucket_name, std::string *bucket_id, int *shard_id);
20061996

20071997
boost::intrusive_ptr<CephContext>

0 commit comments

Comments
 (0)