]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: implement update_device_class
authorLoic Dachary <ldachary@redhat.com>
Mon, 20 Mar 2017 20:08:51 +0000 (21:08 +0100)
committerLoic Dachary <ldachary@redhat.com>
Wed, 5 Apr 2017 07:21:50 +0000 (09:21 +0200)
Change the device class of a given device. The class must already exist.

Signed-off-by: Loic Dachary <loic@dachary.org>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index 2a42d59929d33337cbb16e2ed4d809c0c3741318..868a52d49d34941307921eeac9c11ce12da71399 100644 (file)
@@ -1230,6 +1230,32 @@ int CrushWrapper::remove_rule(int ruleno)
   return 0;
 }
 
+int CrushWrapper::update_device_class(CephContext *cct, int id, const string& class_name, const string& name)
+{
+  int class_id = get_class_id(class_name);
+  if (class_id < 0) {
+    ldout(cct, 0) << "update_device_class class " << class_name << " does not exist " << dendl;
+    return -ENOENT;
+  }
+  if (id < 0) {
+    ldout(cct, 0) << "update_device_class " << name << " id " << id << " is negative " << dendl;
+    return -EINVAL;
+  }
+  assert(item_exists(id));
+
+  if (class_map.count(id) != 0 && class_map[id] == class_id) {
+    ldout(cct, 5) << "update_device_class " << name << " already set to class " << class_name << dendl;
+    return 0;
+  }
+
+  set_item_class(id, class_id);
+
+  int r = rebuild_roots_with_classes();
+  if (r < 0)
+    return r;
+  return 1;
+}
+
 int CrushWrapper::device_class_clone(int original_id, int device_class, int *clone)
 {
   const char *item_name = get_item_name(original_id);
index 17b7998776e2c4d7fd966259e04df7c79d6012d4..50289e0f3733ec071639feb7074ce60e7b8a766d 100644 (file)
@@ -1089,6 +1089,7 @@ public:
     crush_finalize(crush);
   }
 
+  int update_device_class(CephContext *cct, int id, const string& class_name, const string& name);
   int device_class_clone(int original, int device_class, int *clone);
   int populate_classes();
   int rebuild_roots_with_classes();