]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-crush-location: new crush location hook
authorSage Weil <sage@inktank.com>
Tue, 29 Oct 2013 18:03:04 +0000 (11:03 -0700)
committerSage Weil <sage@inktank.com>
Tue, 29 Oct 2013 21:00:03 +0000 (14:00 -0700)
This generalizes the bit of code that builds a key=value pair list to
update an entity's CRUSH location.

Signed-off-by: Sage Weil <sage@inktank.com>
ceph.spec.in
debian/ceph-common.install
src/.gitignore
src/Makefile.am
src/ceph-crush-location.in [new file with mode: 0755]

index a9c5dc3c74b7955d3794b0c9830e0fde81ba8eff..7aeca1a4ddb0a671acd01fda05ae808ff2336e92 100644 (file)
@@ -392,6 +392,7 @@ fi
 %{_bindir}/ceph-authtool
 %{_bindir}/ceph-syn
 %{_bindir}/ceph-post-file
+%{_bindir}/ceph-crush-location
 %{_bindir}/ceph-run
 %{_bindir}/ceph-mon
 %{_bindir}/ceph-mds
index 41453f5a6463453c7331dda440b99c56a4eca767..8e3e48b9b82f3f6edec2040e2b814c7ae1cc481b 100644 (file)
@@ -6,6 +6,7 @@ usr/bin/ceph-conf
 usr/bin/ceph-dencoder
 usr/bin/ceph-rest-api
 usr/bin/ceph-syn
+usr/bin/ceph-crush-location
 usr/bin/rados
 usr/bin/rbd
 usr/bin/ceph-post-file
index 8542ba868f9d2e001730964be8ebb30c6c709c54..817fee955ffa6cf5a15da4159e7ecd4f4f8edafa 100644 (file)
@@ -11,6 +11,7 @@ Makefile
 /ceph-authtool
 /ceph-conf
 /ceph-coverage
+/ceph-crush-location
 /ceph-debugpack
 /ceph-post-file
 /ceph-dencoder
index d9189bde9cabc82daa234bfc28e87bc9f82237f4..fa0224524170c786ca921a0597094e4463f1f24d 100644 (file)
@@ -128,7 +128,7 @@ editpaths = sed \
        -e 's|@datadir[@]|$(pkgdatadir)|g' \
        -e 's|@prefix[@]|$(prefix)|g' \
        -e 's|@@GCOV_PREFIX_STRIP[@][@]|$(GCOV_PREFIX_STRIP)|g'
-shell_scripts = ceph-debugpack ceph-post-file
+shell_scripts = ceph-debugpack ceph-post-file ceph-crush-location
 $(shell_scripts): Makefile
 $(shell_scripts): %: %.in
        rm -f $@ $@.tmp
@@ -180,6 +180,7 @@ EXTRA_DIST += \
        ceph-disk-udev \
        ceph-create-keys \
        ceph-rest-api \
+       ceph-crush-location \
        mount.fuse.ceph \
        rbdmap \
        unittest_bufferlist.sh \
@@ -236,7 +237,8 @@ bin_SCRIPTS += \
        ceph-clsinfo \
        ceph-debugpack \
        ceph-rbdnamer \
-       ceph-post-file
+       ceph-post-file \
+       ceph-crush-location
 
 BUILT_SOURCES += init-ceph
 su_sbin_SCRIPTS += mkcephfs
diff --git a/src/ceph-crush-location.in b/src/ceph-crush-location.in
new file mode 100755 (executable)
index 0000000..b5043f2
--- /dev/null
@@ -0,0 +1,87 @@
+#!/bin/sh
+#
+# Generate a CRUSH location for the given entity
+#
+# The CRUSH location consists of a list of key=value pairs, separated
+# by spaces, all on a single line.  This describes where in CRUSH
+# hierarhcy this entity should be placed.
+#
+# Arguments:
+#   --cluster <clustername>   name of the cluster (see /etc/ceph/$cluster.conf)
+#   --type <osd|mds|client>   daemon/entity type
+#   --id <id>                 id (osd number, mds name, client name)
+#
+
+# if we start up as ./ceph-crush-location, assume everything else is
+# in the current directory too.
+if [ `dirname $0` = "." ] && [ $PWD != "/usr/bin" ]; then
+    BINDIR=.
+    SBINDIR=.
+    LIBDIR=.
+    ETCDIR=.
+else
+    BINDIR=@bindir@
+    SBINDIR=@prefix@/sbin
+    LIBDIR=@libdir@/ceph
+    ETCDIR=@sysconfdir@/ceph
+fi
+
+usage_exit() {
+    echo "usage: $0 [--cluster <cluster>] --id <id> --type <osd|mds|client>"
+    exit
+}
+
+cluster="ceph"
+type=""
+id=""
+while [ $# -ge 1 ]; do
+    case $1 in
+       --cluster | -C)
+           shift
+           cluster="$1"
+           shift
+           ;;
+       --id | -i)
+           shift
+           id="$1"
+           shift
+           ;;
+       --type | -t)
+           shift
+           type="$1"
+           shift
+           ;;
+       *)
+           echo "unrecognized option '$1'"
+           usage_exit
+           ;;
+    esac
+done
+
+if [ -z "$type" ]; then
+    echo "must specify entity type"
+    usage_exit
+fi
+
+if [ -z "$id" ]; then
+    echo "must specify id"
+    usage_exit
+fi
+
+# try a type-specific config, e.g. 'osd crush location'
+location="$($BINDIR/ceph-conf --cluster=${cluster:-ceph} --name=$type.$id --lookup ${type}_crush_location || :)"
+if [ -n "$location" ]; then
+    echo $location
+    exit 0
+fi
+
+# try a generic location
+location="$($BINDIR/ceph-conf --cluster=${cluster:-ceph} --name=$type.$id --lookup crush_location || :)"
+if [ -n "$location" ]; then
+    echo $location
+    exit 0
+fi
+
+# spit out something generic
+echo "host=$(hostname -s) root=default"
+