summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoic Dachary <ldachary@redhat.com>2017-04-10 22:52:35 +0200
committerLoic Dachary <ldachary@redhat.com>2017-04-11 17:06:57 +0200
commitd198fdb7aedaf20bea1732a85ec59eecfcb617de (patch)
treeb7fe4f98844e5af2933351689ed448c4a1505843 /src
parentosd: split mon_cmd_maybe_osd_create out of update_crush_location (diff)
downloadceph-d198fdb7aedaf20bea1732a85ec59eecfcb617de.tar.xz
ceph-d198fdb7aedaf20bea1732a85ec59eecfcb617de.zip
ceph-disk,osd: add support for crush device classes
Fixes: http://tracker.ceph.com/issues/19513 Signed-off-by: Loic Dachary <loic@dachary.org>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/ceph-disk/ceph_disk/main.py7
-rwxr-xr-xsrc/ceph-disk/tests/ceph-disk.sh42
-rw-r--r--src/osd/OSD.cc20
-rw-r--r--src/osd/OSD.h1
4 files changed, 70 insertions, 0 deletions
diff --git a/src/ceph-disk/ceph_disk/main.py b/src/ceph-disk/ceph_disk/main.py
index 9837649ef86..f3b669a94bd 100755
--- a/src/ceph-disk/ceph_disk/main.py
+++ b/src/ceph-disk/ceph_disk/main.py
@@ -1922,6 +1922,10 @@ class Prepare(object):
help='unique OSD uuid to assign this disk to',
)
parser.add_argument(
+ '--crush-device-class',
+ help='crush device class to assign this disk to',
+ )
+ parser.add_argument(
'--dmcrypt',
action='store_true', default=None,
help='encrypt DATA and/or JOURNAL devices with dm-crypt',
@@ -2788,6 +2792,9 @@ class PrepareData(object):
write_one_line(path, 'ceph_fsid', self.args.cluster_uuid)
write_one_line(path, 'fsid', self.args.osd_uuid)
+ if self.args.crush_device_class:
+ write_one_line(path, 'crush_device_class',
+ self.args.crush_device_class)
write_one_line(path, 'magic', CEPH_OSD_ONDISK_MAGIC)
for to_prepare in to_prepare_list:
diff --git a/src/ceph-disk/tests/ceph-disk.sh b/src/ceph-disk/tests/ceph-disk.sh
index 454ec444151..ae216bc102d 100755
--- a/src/ceph-disk/tests/ceph-disk.sh
+++ b/src/ceph-disk/tests/ceph-disk.sh
@@ -362,6 +362,47 @@ function test_ceph_osd_mkfs() {
[ -f $dir/used-ceph-osd ] || return 1
}
+function test_crush_device_class() {
+ local dir=$1
+ shift
+
+ run_mon $dir a
+
+ local osd_data=$dir/dir
+ $mkdir -p $osd_data
+
+ local osd_uuid=$($uuidgen)
+
+ $mkdir -p $osd_data
+
+ ${CEPH_DISK} $CEPH_DISK_ARGS \
+ prepare --osd-uuid $osd_uuid \
+ --crush-device-class CRUSH_CLASS \
+ $osd_data || return 1
+ test -f $osd_data/crush_device_class || return 1
+ test $(cat $osd_data/crush_device_class) = CRUSH_CLASS || return 1
+
+ ceph osd crush class create CRUSH_CLASS || return 1
+
+ CEPH_ARGS="--crush-location=root=default $CEPH_ARGS" \
+ ${CEPH_DISK} $CEPH_DISK_ARGS \
+ --verbose \
+ activate \
+ --mark-init=none \
+ $osd_data || return 1
+
+ ok=false
+ for delay in 2 4 8 16 32 64 128 256 ; do
+ if ceph osd crush dump | grep --quiet 'CRUSH_CLASS' ; then
+ ok=true
+ break
+ fi
+ sleep $delay
+ ceph osd crush dump # for debugging purposes
+ done
+ $ok || return 1
+}
+
function run() {
local dir=$1
shift
@@ -402,6 +443,7 @@ function run() {
[ `uname` != FreeBSD ] && \
default_actions+="test_activate_dir_bluestore "
default_actions+="test_ceph_osd_mkfs "
+ default_actions+="test_crush_device_class "
local actions=${@:-$default_actions}
for action in $actions ; do
setup $dir || return 1
diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc
index ea67e40f843..bdc2878d785 100644
--- a/src/osd/OSD.cc
+++ b/src/osd/OSD.cc
@@ -2382,6 +2382,12 @@ int OSD::init()
}
}
+ r = update_crush_device_class();
+ if (r < 0) {
+ osd_lock.Lock();
+ goto monout;
+ }
+
r = update_crush_location();
if (r < 0) {
osd_lock.Lock();
@@ -3100,6 +3106,20 @@ int OSD::update_crush_location()
return mon_cmd_maybe_osd_create(cmd);
}
+int OSD::update_crush_device_class()
+{
+ string device_class;
+ int r = store->read_meta("crush_device_class", &device_class);
+ if (r < 0)
+ return 0;
+
+ string cmd =
+ string("{\"prefix\": \"osd crush set-device-class\", ") +
+ string("\"id\": ") + stringify(whoami) + string(", ") +
+ string("\"class\": \"") + device_class + string("\"}");
+
+ return mon_cmd_maybe_osd_create(cmd);
+}
void OSD::write_superblock(ObjectStore::Transaction& t)
{
diff --git a/src/osd/OSD.h b/src/osd/OSD.h
index 90821997caa..71db4878d91 100644
--- a/src/osd/OSD.h
+++ b/src/osd/OSD.h
@@ -2415,6 +2415,7 @@ protected:
private:
int mon_cmd_maybe_osd_create(string &cmd);
+ int update_crush_device_class();
int update_crush_location();
static int write_meta(ObjectStore *store,