Skip to content

Commit 7b5b72b

Browse files
author
David Scott
committed
setup.sh: allow to be run as non-root
If we are running as root: we use real device mapper. If we are not running as root: we use the mock device mapper. Signed-off-by: David Scott <[email protected]>
1 parent 02d5596 commit 7b5b72b

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

setup.sh

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,64 @@ set -x
88
# already included in the RPM.
99

1010
if [ "$EUID" -ne "0" ]; then
11-
echo "Please run me as uid 0. I need to create a loop device and device mapper devices"
12-
exit 1
11+
echo "I am not running with EUID 0. I will use the mock device mapper interface"
12+
USE_MOCK=1
13+
MOCK_ARG="--mock-devmapper"
14+
else
15+
echo "I am running with EUID 0. I will use the real device mapper interface"
16+
USE_MOCK=0
17+
MOCK_ARG=""
1318
fi
1419

1520
# Making a 1G disk
16-
rm -f bigdisk _build/xenvm*.out
21+
rm -f bigdisk
1722
dd if=/dev/zero of=bigdisk bs=1 seek=256G count=0
1823

19-
LOOP=$(losetup -f)
20-
echo Using $LOOP
21-
losetup $LOOP bigdisk
24+
if [ "$USE_MOCK" -eq "0" ]; then
25+
LOOP=$(losetup -f)
26+
echo Using $LOOP
27+
losetup $LOOP bigdisk
28+
else
29+
LOOP=`pwd`/bigdisk
30+
fi
2231
cat test.xenvmd.conf.in | sed -r "s|@BIGDISK@|$LOOP|g" > test.xenvmd.conf
23-
mkdir -p /etc/xenvm.d
24-
BISECT_FILE=_build/xenvm.coverage ./xenvm.native format $LOOP --vg djstest
32+
mkdir -p /tmp/xenvm.d
33+
BISECT_FILE=_build/xenvm.coverage ./xenvm.native format $LOOP --vg djstest --configdir /tmp/xenvm.d $MOCK_ARG
2534
BISECT_FILE=_build/xenvmd.coverage ./xenvmd.native --config ./test.xenvmd.conf --daemon
2635

2736
export BISECT_FILE=_build/xenvm.coverage
2837

29-
./xenvm.native set-vg-info --pvpath $LOOP -S /tmp/xenvmd djstest --local-allocator-path /tmp/xenvm-local-allocator --uri file://local/services/xenvmd/djstest
38+
./xenvm.native set-vg-info --pvpath $LOOP -S /tmp/xenvmd djstest --local-allocator-path /tmp/xenvm-local-allocator --uri file://local/services/xenvmd/djstest --configdir /tmp/xenvm.d $MOCK_ARG
3039

31-
./xenvm.native lvcreate -n live -L 4 djstest
32-
./xenvm.native lvchange -ay /dev/djstest/live
40+
./xenvm.native lvcreate -n live -L 4 djstest --configdir /tmp/xenvm.d $MOCK_ARG
41+
./xenvm.native lvchange -ay /dev/djstest/live --configdir /tmp/xenvm.d $MOCK_ARG
3342

3443
#./xenvm.native benchmark
3544
# create and connect to hosts
36-
./xenvm.native host-create /dev/djstest host1
37-
./xenvm.native host-connect /dev/djstest host1
45+
./xenvm.native host-create /dev/djstest host1 --configdir /tmp/xenvm.d $MOCK_ARG
46+
./xenvm.native host-connect /dev/djstest host1 --configdir /tmp/xenvm.d $MOCK_ARG
3847
cat test.local_allocator.conf.in | sed -r "s|@BIGDISK@|$LOOP|g" | sed -r "s|@HOST@|host1|g" > test.local_allocator.host1.conf
39-
./local_allocator.native --config ./test.local_allocator.host1.conf > /dev/null &
48+
./local_allocator.native --config ./test.local_allocator.host1.conf $MOCK_ARG > /dev/null &
4049

41-
./xenvm.native host-create /dev/djstest host2
42-
./xenvm.native host-connect /dev/djstest host2
50+
./xenvm.native host-create /dev/djstest host2 --configdir /tmp/xenvm.d $MOCK_ARG
51+
./xenvm.native host-connect /dev/djstest host2 --configdir /tmp/xenvm.d $MOCK_ARG
4352
cat test.local_allocator.conf.in | sed -r "s|@BIGDISK@|$LOOP|g" | sed -r "s|@HOST@|host2|g" > test.local_allocator.host2.conf
44-
./local_allocator.native --config ./test.local_allocator.host2.conf > /dev/null &
53+
./local_allocator.native --config ./test.local_allocator.host2.conf $MOCK_ARG > /dev/null &
4554

4655
sleep 30
47-
./xenvm.native host-list /dev/djstest
56+
./xenvm.native host-list /dev/djstest --configdir /tmp/xenvm.d $MOCK_ARG
4857

4958
# destroy hosts
50-
./xenvm.native host-disconnect /dev/djstest host2
51-
./xenvm.native host-destroy /dev/djstest host2
52-
./xenvm.native host-disconnect /dev/djstest host1
53-
./xenvm.native host-destroy /dev/djstest host1
59+
./xenvm.native host-disconnect /dev/djstest host2 --configdir /tmp/xenvm.d $MOCK_ARG
60+
./xenvm.native host-destroy /dev/djstest host2 --configdir /tmp/xenvm.d $MOCK_ARG
61+
./xenvm.native host-disconnect /dev/djstest host1 --configdir /tmp/xenvm.d $MOCK_ARG
62+
./xenvm.native host-destroy /dev/djstest host1 --configdir /tmp/xenvm.d $MOCK_ARG
5463

55-
./xenvm.native host-list /dev/djstest
64+
./xenvm.native host-list /dev/djstest --configdir /tmp/xenvm.d $MOCK_ARG
5665

5766
#shutdown
58-
./xenvm.native lvchange -an /dev/djstest/live || true
59-
./xenvm.native shutdown /dev/djstest
67+
./xenvm.native lvchange -an /dev/djstest/live --configdir /tmp/xenvm.d $MOCK_ARG || true
68+
./xenvm.native shutdown /dev/djstest --configdir /tmp/xenvm.d $MOCK_ARG
6069

6170
#echo Run 'sudo ./xenvm.native host-connect /dev/djstest host1' to connect to the local allocator'
6271
#echo Run 'sudo ./local_allocator.native' and type 'djstest-live' to request an allocation

test.local_allocator.conf.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(
2-
(socket @HOST@-socket)
2+
(socket /tmp/@HOST@-socket)
33
(allocation_quantum 16)
4-
(localJournal localJournal)
4+
(localJournal /tmp/@HOST@-localJournal)
55
(devices (@BIGDISK@))
66
(toLVM @HOST@-toLVM)
77
(fromLVM @HOST@-fromLVM)

0 commit comments

Comments
 (0)