2010-12-29 23:36:22 +00:00
|
|
|
#!/bin/bash
|
2010-10-28 21:31:22 +00:00
|
|
|
|
2010-12-29 23:36:22 +00:00
|
|
|
die() {
|
2010-10-28 21:31:22 +00:00
|
|
|
echo "$*"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2010-12-29 23:36:22 +00:00
|
|
|
cleanup() {
|
|
|
|
rm -rf $TDIR
|
|
|
|
TDIR=""
|
|
|
|
}
|
2010-10-28 21:31:22 +00:00
|
|
|
|
2010-12-29 23:36:22 +00:00
|
|
|
set_variables() {
|
|
|
|
# defaults
|
|
|
|
[ -z "$bindir" ] && bindir=$PWD # location of init-ceph
|
|
|
|
if [ -z "$conf" ]; then
|
|
|
|
conf="$basedir/ceph.conf"
|
|
|
|
[ -e $conf ] || conf="/etc/ceph/ceph.conf"
|
|
|
|
fi
|
|
|
|
[ -e $conf ] || die "conf file not found"
|
2010-10-28 21:31:22 +00:00
|
|
|
|
2011-09-21 23:28:43 +00:00
|
|
|
CCONF="ceph-conf -c $conf"
|
2010-10-28 21:31:22 +00:00
|
|
|
|
2010-12-29 23:36:22 +00:00
|
|
|
[ -z "$mnt" ] && mnt="/c"
|
|
|
|
if [ -z "$monhost" ]; then
|
|
|
|
$CCONF -t mon -i 0 'mon addr' > $TDIR/cconf_mon
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
$CCONF -t mon.a -i 0 'mon addr' > $TDIR/cconf_mon
|
|
|
|
[ $? -ne 0 ] && die "can't figure out \$monhost"
|
|
|
|
fi
|
|
|
|
read monhost < $TDIR/cconf_mon
|
|
|
|
fi
|
2010-10-28 21:31:22 +00:00
|
|
|
|
2010-12-29 23:36:22 +00:00
|
|
|
[ -z "$imgsize" ] && imgsize=1024
|
|
|
|
[ -z "$user" ] && user=admin
|
2011-01-02 20:19:35 +00:00
|
|
|
[ -z "$keyring" ] && keyring="`$CCONF keyring`"
|
2011-09-22 22:16:56 +00:00
|
|
|
[ -z "$secret" ] && secret="`ceph-authtool $keyring -n client.$user -p`"
|
2010-10-28 21:31:22 +00:00
|
|
|
|
2010-12-29 23:36:22 +00:00
|
|
|
monip="`echo $monhost | sed 's/:/ /g' | awk '{print $1}'`"
|
|
|
|
monport="`echo $monhost | sed 's/:/ /g' | awk '{print $2}'`"
|
2010-10-28 21:31:22 +00:00
|
|
|
|
2010-12-29 23:36:22 +00:00
|
|
|
[ -z "$monip" ] && die "bad mon address"
|
2010-10-28 21:31:22 +00:00
|
|
|
|
2010-12-29 23:36:22 +00:00
|
|
|
[ -z "$monport" ] && monport=6789
|
2010-10-28 21:31:22 +00:00
|
|
|
|
2010-12-29 23:36:22 +00:00
|
|
|
set -e
|
2010-10-28 21:31:22 +00:00
|
|
|
|
2010-12-29 23:36:22 +00:00
|
|
|
mydir=`hostname`_`echo $0 | sed 's/\//_/g'`
|
2010-10-28 21:31:22 +00:00
|
|
|
|
2010-12-29 23:36:22 +00:00
|
|
|
img_name=test.`hostname`.$$
|
|
|
|
}
|
2010-10-28 21:31:22 +00:00
|
|
|
|
|
|
|
rbd_load() {
|
|
|
|
modprobe rbd
|
|
|
|
}
|
|
|
|
|
|
|
|
rbd_create_image() {
|
2010-10-28 22:40:27 +00:00
|
|
|
id=$1
|
|
|
|
rbd create $img_name.$id --size=$imgsize
|
2010-10-28 21:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rbd_add() {
|
|
|
|
id=$1
|
2010-12-30 07:59:03 +00:00
|
|
|
echo "$monip:$monport name=$user,secret=$secret rbd $img_name.$id" \
|
|
|
|
> /sys/bus/rbd/add
|
|
|
|
|
|
|
|
pushd /sys/bus/rbd/devices &> /dev/null
|
|
|
|
[ $? -eq 0 ] || die "failed to cd"
|
|
|
|
devid=""
|
2010-12-30 08:09:11 +00:00
|
|
|
rm -f "$TDIR/rbd_devs"
|
|
|
|
for f in *; do echo $f >> "$TDIR/rbd_devs"; done
|
|
|
|
sort -nr "$TDIR/rbd_devs" > "$TDIR/rev_rbd_devs"
|
|
|
|
while read f < "$TDIR/rev_rbd_devs"; do
|
2010-12-30 07:59:03 +00:00
|
|
|
read d_img_name < "$f/name"
|
|
|
|
if [ "x$d_img_name" == "x$img_name.$id" ]; then
|
|
|
|
devid=$f
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
popd &> /dev/null
|
|
|
|
|
|
|
|
[ "x$devid" == "x" ] && die "failed to find $img_name.$id"
|
|
|
|
|
2010-10-28 22:40:27 +00:00
|
|
|
export rbd$id=$devid
|
2010-12-30 07:59:03 +00:00
|
|
|
while [ ! -e /dev/rbd$devid ]; do sleep 1; done
|
2010-10-28 21:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rbd_test_init() {
|
|
|
|
rbd_load
|
|
|
|
}
|
|
|
|
|
|
|
|
rbd_remove() {
|
2010-12-30 07:59:03 +00:00
|
|
|
echo $1 > /sys/bus/rbd/remove
|
2010-10-28 21:31:22 +00:00
|
|
|
}
|
2010-10-28 22:40:27 +00:00
|
|
|
|
|
|
|
rbd_rm_image() {
|
|
|
|
id=$1
|
|
|
|
rbd rm $imgname.$id
|
|
|
|
}
|
2010-12-29 23:36:22 +00:00
|
|
|
|
|
|
|
TDIR=`mktemp -d`
|
|
|
|
trap cleanup INT TERM EXIT
|
|
|
|
set_variables
|