]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cls/rbd: GroupSnapshotNamespace comparator violates ordering rules 45021/head
authorIlya Dryomov <idryomov@gmail.com>
Mon, 14 Feb 2022 12:04:00 +0000 (13:04 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 14 Feb 2022 12:31:54 +0000 (13:31 +0100)
For

  GroupSnapshotNamespace a(1, "group-1", "snap-2");
  GroupSnapshotNamespace b(1, "group-2", "snap-1");

both a < b and b < a evaluate to true.  This violates STL strict weak
ordering requirements which is a problem because GroupSnapshotNamespace
is used as a key in std::map (ictx->snap_ids at least), etc.

Fixes: https://tracker.ceph.com/issues/49792
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
src/cls/rbd/cls_rbd_types.h

index 3e7ca77fa87c04ade9029a508009a0bf9b342b24..645861b2d8fd70353e1a743783ba9fc6605a99fb 100644 (file)
@@ -475,14 +475,13 @@ struct GroupSnapshotNamespace {
   }
 
   inline bool operator<(const GroupSnapshotNamespace& gsn) const {
-    if (group_pool < gsn.group_pool) {
-      return true;
-    } else if (group_id < gsn.group_id) {
-      return true;
-    } else {
-      return (group_snapshot_id < gsn.group_snapshot_id);
+    if (group_pool != gsn.group_pool) {
+      return group_pool < gsn.group_pool;
     }
-    return false;
+    if (group_id != gsn.group_id) {
+      return group_id < gsn.group_id;
+    }
+    return group_snapshot_id < gsn.group_snapshot_id;
   }
 };