@@ -364,6 +364,14 @@ static void get_list_index_key(rgw_bucket_dir_entry& entry, string *index_key)
364364 index_key->append (entry.key .instance );
365365}
366366
367+ // Format an omap key for an object name that sorts after all versioned keys
368+ // generated by get_list_index_key().
369+ static std::string cls_rgw_after_versions (const std::string& key)
370+ {
371+ // assert: ! key.empty()
372+ return key + ' \1 ' ; // suffix "\1" sorts after suffixes like "\0v123\0iabc"
373+ }
374+
367375static void encode_obj_versioned_data_key (const cls_rgw_obj_key& key, string *index_key, bool append_delete_marker_suffix = false )
368376{
369377 *index_key = BI_PREFIX_CHAR;
@@ -528,8 +536,6 @@ static int read_bucket_header(cls_method_context_t hctx,
528536
529537int rgw_bucket_list (cls_method_context_t hctx, bufferlist *in, bufferlist *out)
530538{
531- CLS_LOG (10 , " entered %s" , __func__);
532-
533539 // maximum number of calls to get_obj_vals we'll try; compromise
534540 // between wanting to return the requested # of entries, but not
535541 // wanting to slow down this op with too many omap reads
@@ -545,6 +551,10 @@ int rgw_bucket_list(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
545551 return -EINVAL;
546552 }
547553
554+ CLS_LOG (10 , " entered %s start=%s count=%u prefix=%s delim=%s versioned=%d" ,
555+ __func__, op.start_obj .to_string ().c_str (), op.num_entries ,
556+ op.filter_prefix .c_str (), op.delimiter .c_str (), (int )op.list_versions );
557+
548558 rgw_cls_list_ret ret;
549559 rgw_bucket_dir& new_dir = ret.dir ;
550560 auto & name_entry_map = new_dir.m ; // map of keys to entries
@@ -652,6 +662,13 @@ int rgw_bucket_list(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
652662 (!entry.is_visible () || op.start_obj .name == key.name )) {
653663 CLS_LOG (20 , " %s: entry %s[%s] is not visible" ,
654664 __func__, key.name .c_str (), key.instance .c_str ());
665+
666+ // advance past any versioned entries for this name
667+ start_after_omap_key = cls_rgw_after_versions (key.name );
668+ start_after_entry_key.set (start_after_omap_key);
669+
670+ kiter = keys.lower_bound (start_after_omap_key);
671+ --kiter;
655672 continue ;
656673 }
657674
0 commit comments