class CephName(CephArgtype):
"""
- Name, or type.id, where type is osd|mon|client|mds, and id is a base10 int,
- or just id.
+ Name (type.id) where:
+ type is osd|mon|client|mds
+ id is a base10 int, if type == osd, or a string otherwise
Also accept '*'
"""
self.nameid = None
return True
if s.find('.') == -1:
- i = s
+ raise ArgumentFormat('CephName: no . in {0}'.format(s))
else:
t, i = s.split('.')
if not t in ('osd', 'mon', 'client', 'mds'):
def __str__(self):
return '<name (type.id)>'
+class CephOsdName(CephArgtype):
+ """
+ Like CephName, but specific to osds: allow <id> alone
+
+ osd.<id>, or <id>, or *, where id is a base10 int
+ """
+ def valid(self, s, partial=False):
+ if s == '*':
+ self.val = s
+ self.nametype = None
+ self.nameid = None
+ return True
+ if s.find('.') != -1:
+ t, i = s.split('.')
+ else:
+ t = 'osd'
+ i = s
+ if t != 'osd':
+ raise ArgumentValid('unknown type ' + self.t)
+ try:
+ i = int(i)
+ except:
+ raise ArgumentFormat('osd id ' + i + ' not integer')
+ self.nametype = t
+ self.nameid = i
+ self.val = i
+ return True
+
+ def __str__(self):
+ return '<osdname (id|osd.id)>'
class CephChoices(CephArgtype):
"""
* CephObjectname: Another plainold string
* CephPgid: n.xxx where n is an int > 0, xxx is a hex number > 0
* CephName: daemon name, '*' or '<type>.<id>' (id must be int for type osd)
+ * CephOsdName: osd name, '*' or '<id> or 'osd.<id>' (id must be int)
* CephChoices: strings="foo|bar" means this param can be either
* CephFilepath: openable file
* CephFragment: cephfs 'fragID': val/bits, val in hex 0xnnn, bits in dec
"name=type,type=CephString", \
"add no-parent (probably root) crush bucket <name> of type <type>")
COMMAND("osd crush set " \
- "name=id,type=CephInt,range=0 " \
- "name=name,type=CephName,req=false " \
+ "name=id,type=CephOsdName " \
"name=weight,type=CephFloat,range=0.0 " \
"name=args,type=CephString,n=N", \
- "set crushmap entry for <id> to <weight> with location <args>")
+ "set crushmap entry for <name> to <weight> with location <args>")
COMMAND("osd crush add " \
- "name=id,type=CephInt,range=0 " \
- "name=name,type=CephName,req=false " \
+ "name=id,type=CephOsdName " \
"name=weight,type=CephFloat,range=0.0 " \
"name=args,type=CephString,n=N", \
- "add crushmap entry for <id> with <weight> and location <args>")
+ "add crushmap entry for <name> with <weight> and location <args>")
COMMAND("osd crush create-or-move " \
- "name=id,type=CephInt,range=0 " \
+ "name=id,type=CephOsdName " \
"name=weight,type=CephFloat,range=0.0 " \
"name=args,type=CephString,n=N", \
- "create entry or move existing entry for <id> <weight> at/to location <args>")
+ "create entry or move existing entry for <name> <weight> at/to location <args>")
COMMAND("osd crush move " \
- "name=name,type=CephString " \
+ "name=id,type=CephOsdName " \
"name=args,type=CephString,n=N", \
"move existing entry for <name> to location <args>")
COMMAND("osd crush link " \
cmd_getval(g_ceph_context, cmdmap, "prefix", prefix);
int64_t id;
+ string name;
bool osdid_present = cmd_getval(g_ceph_context, cmdmap, "id", id);
+ if (osdid_present) {
+ ostringstream oss;
+ oss << "osd." << id;
+ name = oss.str();
+ }
if (prefix == "osd setcrushmap" ||
(prefix == "osd crush set" && !osdid_present)) {
ss << "added bucket " << name << " type " << typestr
<< " to crush map";
goto update;
- } else if (osdid_present &&
+ } else if (osdid_present &&
(prefix == "osd crush set" || prefix == "osd crush add")) {
do {
- // osd crush set <osd-id> [<osd.* name>] <weight> <loc1> [<loc2> ...]
- // osd crush add <osd-id> [<osd.* name>] <weight> <loc1> [<loc2> ...]
+ // <OsdName> is 'osd.<id>' or '<id>', passed as int64_t id
+ // osd crush set <OsdName> <weight> <loc1> [<loc2> ...]
+ // osd crush add <OsdName> <weight> <loc1> [<loc2> ...]
+
if (!osdmap.exists(id)) {
err = -ENOENT;
- ss << "osd." << id << " does not exist. create it before updating the crush map";
+ ss << name << " does not exist. create it before updating the crush map";
goto reply;
}
- string name;
- if (!cmd_getval(g_ceph_context, cmdmap, "name", name)) {
- // new usage; infer name
- name = "osd." + stringify(id);
- }
-
double weight;
cmd_getval(g_ceph_context, cmdmap, "weight", weight);
} else if (prefix == "osd crush create-or-move") {
do {
- // osd crush create-or-move <id> <initial_weight> <loc1> [<loc2> ...]
- int64_t id;
- cmd_getval(g_ceph_context, cmdmap, "id", id);
+ // osd crush create-or-move <OsdName> <initial_weight> <loc1> [<loc2> ...]
if (!osdmap.exists(id)) {
err = -ENOENT;
- ss << "osd." << id << " does not exist. create it before updating the crush map";
+ ss << name << " does not exist. create it before updating the crush map";
goto reply;
}
- string name = "osd." + stringify(id);
double weight;
cmd_getval(g_ceph_context, cmdmap, "weight", weight);
map<string,string> loc;
parse_loc_map(argvec, &loc);
- dout(0) << "create-or-move crush item id " << id << " name '" << name << "' initial_weight " << weight
+ dout(0) << "create-or-move crush item name '" << name << "' initial_weight " << weight
<< " at location " << loc << dendl;
CrushWrapper newcrush;
err = newcrush.create_or_move_item(g_ceph_context, id, weight, name, loc);
if (err == 0) {
- ss << "create-or-move updated item id " << id << " name '" << name << "' weight " << weight
+ ss << "create-or-move updated item name '" << name << "' weight " << weight
<< " at location " << loc << " to crush map";
break;
}
if (err > 0) {
pending_inc.crush.clear();
newcrush.encode(pending_inc.crush);
- ss << "create-or-move updating item id " << id << " name '" << name << "' weight " << weight
+ ss << "create-or-move updating item name '" << name << "' weight " << weight
<< " at location " << loc << " to crush map";
getline(ss, rs);
wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs, get_version()));
} else if (prefix == "osd crush move") {
do {
// osd crush move <name> <loc1> [<loc2> ...]
- string name;
- cmd_getval(g_ceph_context, cmdmap, "name", name);
string args;
vector<string> argvec;
uuid=`uuidgen`
echo "add osd$osd $uuid"
$SUDO $CEPH_ADM osd create $uuid
- $SUDO $CEPH_ADM osd crush set $osd osd.$osd 1.0 host=localhost rack=localrack root=default
+ $SUDO $CEPH_ADM osd crush set osd.$osd 1.0 host=localhost rack=localrack root=default
$SUDO $CEPH_BIN/ceph-osd -i $osd $ARGS --mkfs --mkkey --osd-uuid $uuid
key_fn=dev/osd$osd/keyring