crush: implement update_device_class

Change the device class of a given device. The class must already exist.

Signed-off-by: Loic Dachary <loic@dachary.org>
This commit is contained in:
Loic Dachary 2017-03-20 21:08:51 +01:00
parent 81d0f48eed
commit 8131c788b7
2 changed files with 27 additions and 0 deletions

View 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);

View 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();