summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2013-07-15 16:12:23 -0700
committerDan Mick <dan.mick@inktank.com>2013-07-16 15:13:55 -0700
commit466d0f5fc8ceaa3f0625397aee28c7a7b3b03122 (patch)
treeffd90f525c6d89431eae6cef3e62916f75057d7d
parent93fc07c184c9f48702ef76437e414cd2423c6278 (diff)
downloadceph-466d0f5fc8ceaa3f0625397aee28c7a7b3b03122.tar.gz
crush: return EINVAL on invalid name from {insert,update,create_or_move}_item, set_item_name
Signed-off-by: Sage Weil <sage@inktank.com> Reviewed-by: Dan Mick <dan.mick@inktank.com>
-rw-r--r--src/crush/CrushWrapper.cc10
-rw-r--r--src/crush/CrushWrapper.h5
2 files changed, 14 insertions, 1 deletions
diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc
index 1a4097c08b9..e96e6123aab 100644
--- a/src/crush/CrushWrapper.cc
+++ b/src/crush/CrushWrapper.cc
@@ -333,6 +333,9 @@ int CrushWrapper::insert_item(CephContext *cct, int item, float weight, string n
ldout(cct, 5) << "insert_item item " << item << " weight " << weight
<< " name " << name << " loc " << loc << dendl;
+ if (!is_valid_crush_name(name))
+ return -EINVAL;
+
if (name_exists(name)) {
if (get_item_id(name) != item) {
ldout(cct, 10) << "device name '" << name << "' already exists as id "
@@ -473,6 +476,10 @@ int CrushWrapper::create_or_move_item(CephContext *cct, int item, float weight,
{
int ret = 0;
int old_iweight;
+
+ if (!is_valid_crush_name(name))
+ return -EINVAL;
+
if (check_item_loc(cct, item, loc, &old_iweight)) {
ldout(cct, 5) << "create_or_move_item " << item << " already at " << loc << dendl;
} else {
@@ -497,6 +504,9 @@ int CrushWrapper::update_item(CephContext *cct, int item, float weight, string n
<< " name " << name << " loc " << loc << dendl;
int ret = 0;
+ if (!is_valid_crush_name(name))
+ return -EINVAL;
+
// compare quantized (fixed-point integer) weights!
int iweight = (int)(weight * (float)0x10000);
int old_iweight;
diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h
index f399e342110..3d07a281956 100644
--- a/src/crush/CrushWrapper.h
+++ b/src/crush/CrushWrapper.h
@@ -200,10 +200,13 @@ public:
return p->second.c_str();
return 0;
}
- void set_item_name(int i, const string& name) {
+ int set_item_name(int i, const string& name) {
+ if (!is_valid_crush_name(name))
+ return -EINVAL;
name_map[i] = name;
if (have_rmaps)
name_rmap[name] = i;
+ return 0;
}
// rule names