From 8af75968ac49825700c3d2fb31bf14c5a52ce8b5 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Thu, 5 Dec 2013 09:54:37 +0100 Subject: [PATCH] crush: insert_item returns on error if bucket name is invalid A bucket name may be created as a side effect of insert_item. All names in the loc argument are checked for validity at the beginning of the method and an error is returned immediately if one is found. This allows to not check for errors when setting the name of an item later on. Signed-off-by: Loic Dachary --- src/crush/CrushWrapper.cc | 12 ++++++++++++ src/crush/CrushWrapper.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index d17166bc4a9fe..1a9c81e36b022 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -336,6 +336,17 @@ int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string n if (!is_valid_crush_name(name)) return -EINVAL; + + for (map::const_iterator l = loc.begin(); l != loc.end(); l++) { + if (!is_valid_crush_name(l->second)) { + ldout(cct, 1) << "insert_item with loc[" + << l->first << "] = '" + << l->second << "' is not a valid crush name ([A-Za-z0-9_-.]+)" + << dendl; + return -ENFILE; + } + } + if (name_exists(name)) { if (get_item_id(name) != item) { ldout(cct, 10) << "device name '" << name << "' already exists as id " @@ -371,6 +382,7 @@ int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string n return r; } set_item_name(newid, q->second); + cur = newid; continue; } diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index b4bb67bb7429b..d665496b88f4a 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -337,7 +337,7 @@ public: * insert an item into the map at a specific position * * Add an item as a specific location of the hierarchy. - * Specifically, we look for the most specific location constriant + * Specifically, we look for the most specific location constraint * for which a bucket already exists, and then create intervening * buckets beneath that in order to place the item. * -- 2.39.5