Skip to content

Commit a37ebbd

Browse files
committed
RGW/S3: truncate S3 LastModified response (timestamp) to exact seconds
With this change, LastModified timestamp in S3 responses will be in seconds granularity: i.e., milliseconds portion will be normalized. Fixes: https://tracker.ceph.com/issues/67846 Signed-off-by: Oguzhan Ozmen <[email protected]>
1 parent 3383af5 commit a37ebbd

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/rgw/rgw_rest.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,11 @@ void dump_time(req_state *s, const char *name, real_time t)
502502
s->formatter->dump_string(name, buf);
503503
}
504504

505+
void dump_time_exact_seconds(req_state *s, const char *name, real_time t)
506+
{
507+
dump_time(s, name, std::chrono::time_point_cast<std::chrono::seconds>(t));
508+
}
509+
505510
void dump_owner(req_state *s, const std::string& id, const string& name,
506511
const char *section)
507512
{

src/rgw/rgw_rest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ extern void dump_range(req_state* s, uint64_t ofs, uint64_t end,
903903
extern void dump_continue(req_state *s);
904904
extern void list_all_buckets_end(req_state *s);
905905
extern void dump_time(req_state *s, const char *name, real_time t);
906+
extern void dump_time_exact_seconds(req_state *s, const char *name, real_time t);
906907
extern std::string dump_time_to_str(const real_time& t);
907908
extern void dump_bucket_from_state(req_state *s);
908909
extern void dump_redirect(req_state *s, const std::string& redirect);

src/rgw/rgw_rest_s3.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ void RGWListBucket_ObjStore_S3::send_versioned_response()
18801880
}
18811881
s->formatter->dump_string("VersionId", version_id);
18821882
s->formatter->dump_bool("IsLatest", iter->is_current());
1883-
dump_time(s, "LastModified", iter->meta.mtime);
1883+
dump_time_exact_seconds(s, "LastModified", iter->meta.mtime);
18841884
if (!iter->is_delete_marker()) {
18851885
s->formatter->dump_format("ETag", "\"%s\"", iter->meta.etag.c_str());
18861886
s->formatter->dump_int("Size", iter->meta.accounted_size);
@@ -1973,7 +1973,7 @@ void RGWListBucket_ObjStore_S3::send_response()
19731973
s->formatter->open_object_section("dummy");
19741974
}
19751975
dump_urlsafe(s ,encode_key, "Key", key.name);
1976-
dump_time(s, "LastModified", iter->meta.mtime);
1976+
dump_time_exact_seconds(s, "LastModified", iter->meta.mtime);
19771977
s->formatter->dump_format("ETag", "\"%s\"", iter->meta.etag.c_str());
19781978
s->formatter->dump_int("Size", iter->meta.accounted_size);
19791979
auto& storage_class = rgw_placement_rule::get_canonical_storage_class(iter->meta.storage_class);
@@ -2047,7 +2047,7 @@ void RGWListBucket_ObjStore_S3v2::send_versioned_response()
20472047
}
20482048
s->formatter->dump_string("VersionId", version_id);
20492049
s->formatter->dump_bool("IsLatest", iter->is_current());
2050-
dump_time(s, "LastModified", iter->meta.mtime);
2050+
dump_time_exact_seconds(s, "LastModified", iter->meta.mtime);
20512051
if (!iter->is_delete_marker()) {
20522052
s->formatter->dump_format("ETag", "\"%s\"", iter->meta.etag.c_str());
20532053
s->formatter->dump_int("Size", iter->meta.accounted_size);
@@ -2117,7 +2117,7 @@ void RGWListBucket_ObjStore_S3v2::send_response()
21172117
rgw_obj_key key(iter->key);
21182118
s->formatter->open_array_section("Contents");
21192119
dump_urlsafe(s, encode_key, "Key", key.name);
2120-
dump_time(s, "LastModified", iter->meta.mtime);
2120+
dump_time_exact_seconds(s, "LastModified", iter->meta.mtime);
21212121
s->formatter->dump_format("ETag", "\"%s\"", iter->meta.etag.c_str());
21222122
s->formatter->dump_int("Size", iter->meta.accounted_size);
21232123
auto& storage_class = rgw_placement_rule::get_canonical_storage_class(iter->meta.storage_class);
@@ -3757,7 +3757,7 @@ void RGWCopyObj_ObjStore_S3::send_response()
37573757
send_partial_response(0);
37583758

37593759
if (op_ret == 0) {
3760-
dump_time(s, "LastModified", mtime);
3760+
dump_time_exact_seconds(s, "LastModified", mtime);
37613761
if (!etag.empty()) {
37623762
s->formatter->dump_format("ETag", "\"%s\"",etag.c_str());
37633763
}
@@ -4329,7 +4329,7 @@ void RGWListMultipart_ObjStore_S3::send_response()
43294329
rgw::sal::MultipartPart* part = iter->second.get();
43304330
s->formatter->open_object_section("Part");
43314331

4332-
dump_time(s, "LastModified", part->get_mtime());
4332+
dump_time_exact_seconds(s, "LastModified", part->get_mtime());
43334333

43344334
s->formatter->dump_unsigned("PartNumber", part->get_num());
43354335
s->formatter->dump_format("ETag", "\"%s\"", part->get_etag().c_str());

0 commit comments

Comments
 (0)