From 8131c788b79a7d643193b019c7f8be457bb37f15 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Mon, 20 Mar 2017 21:08:51 +0100 Subject: [PATCH] crush: implement update_device_class Change the device class of a given device. The class must already exist. Signed-off-by: Loic Dachary --- src/crush/CrushWrapper.cc | 26 ++++++++++++++++++++++++++ src/crush/CrushWrapper.h | 1 + 2 files changed, 27 insertions(+) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 2a42d59929d..868a52d49d3 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -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); diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 17b7998776e..50289e0f373 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -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();