Skip to content

Commit 915f92b

Browse files
committed
os/: modify getattrs to clear attrs out param before populating
Passing in a non-empty map would otherwise exhibit quite unexpected behavior. For the bufferptr overload, any preexisting entries would not be overwritten due to how std::map::emplace behaves. For the bufferlist overload, it would result in appending to any pre-existing entries. The prior commit cleans up one such inadvertent caller which resulted in the below bug. Fixes: https://tracker.ceph.com/issues/65185 Signed-off-by: Samuel Just <[email protected]>
1 parent 5671e85 commit 915f92b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/os/ObjectStore.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ class ObjectStore {
611611
*
612612
* @param cid collection for object
613613
* @param oid oid of object
614-
* @param aset place to put output result.
614+
* @param aset upon success, will contain exactly the object attrs
615615
* @returns 0 on success, negative error code on failure.
616616
*/
617617
virtual int getattrs(CollectionHandle &c, const ghobject_t& oid,
@@ -622,13 +622,14 @@ class ObjectStore {
622622
*
623623
* @param cid collection for object
624624
* @param oid oid of object
625-
* @param aset place to put output result.
625+
* @param aset upon success, will contain exactly the object attrs
626626
* @returns 0 on success, negative error code on failure.
627627
*/
628628
int getattrs(CollectionHandle &c, const ghobject_t& oid,
629629
std::map<std::string,ceph::buffer::list,std::less<>>& aset) {
630630
std::map<std::string,ceph::buffer::ptr,std::less<>> bmap;
631631
int r = getattrs(c, oid, bmap);
632+
aset.clear();
632633
for (auto i = bmap.begin(); i != bmap.end(); ++i) {
633634
aset[i->first].append(i->second);
634635
}

src/os/bluestore/BlueStore.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12426,6 +12426,7 @@ int BlueStore::getattrs(
1242612426
r = -ENOENT;
1242712427
goto out;
1242812428
}
12429+
aset.clear();
1242912430
for (auto& i : o->onode.attrs) {
1243012431
aset.emplace(i.first.c_str(), i.second);
1243112432
}

0 commit comments

Comments
 (0)