Skip to content

Commit 60b3633

Browse files
committed
Merge pull request #103 from xapi-project/run-without-root
Hook up both test suites to travis
2 parents 533a16f + 5d05350 commit 60b3633

File tree

4 files changed

+70
-51
lines changed

4 files changed

+70
-51
lines changed

.travis.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ eval `opam config env`
55
export BISECT_FILE=_build/xenvm.coverage
66
# Needed to support Unix domain sockets:
77
sudo opam pin add conduit git://github.com/mirage/ocaml-conduit -y
8+
# run the OCaml test suite
89
make test
10+
# run the bash test suite
11+
./setup.sh
912

1013
echo Generating bisect report-- this fails on travis
1114
(cd _build; bisect-report xenvm*.out -summary-only -html /vagrant/report/ || echo Ignoring bisect-report failure)

setup.sh

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,62 @@ 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
25-
BISECT_FILE=_build/xenvmd.coverage ./xenvmd.native --config ./test.xenvmd.conf --daemon
26-
27-
export BISECT_FILE=_build/xenvm.coverage
32+
mkdir -p /tmp/xenvm.d
33+
./xenvm.native format $LOOP --vg djstest --configdir /tmp/xenvm.d $MOCK_ARG
34+
./xenvmd.native --config ./test.xenvmd.conf --daemon
2835

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
36+
./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
3037

31-
./xenvm.native lvcreate -n live -L 4 djstest
32-
./xenvm.native lvchange -ay /dev/djstest/live
38+
./xenvm.native lvcreate -n live -L 4 djstest --configdir /tmp/xenvm.d $MOCK_ARG
39+
./xenvm.native lvchange -ay /dev/djstest/live --configdir /tmp/xenvm.d $MOCK_ARG
3340

3441
#./xenvm.native benchmark
3542
# create and connect to hosts
36-
./xenvm.native host-create /dev/djstest host1
37-
./xenvm.native host-connect /dev/djstest host1
43+
./xenvm.native host-create /dev/djstest host1 --configdir /tmp/xenvm.d $MOCK_ARG
44+
./xenvm.native host-connect /dev/djstest host1 --configdir /tmp/xenvm.d $MOCK_ARG
3845
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 &
46+
./local_allocator.native --config ./test.local_allocator.host1.conf $MOCK_ARG > /dev/null &
4047

41-
./xenvm.native host-create /dev/djstest host2
42-
./xenvm.native host-connect /dev/djstest host2
48+
./xenvm.native host-create /dev/djstest host2 --configdir /tmp/xenvm.d $MOCK_ARG
49+
./xenvm.native host-connect /dev/djstest host2 --configdir /tmp/xenvm.d $MOCK_ARG
4350
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 &
51+
./local_allocator.native --config ./test.local_allocator.host2.conf $MOCK_ARG > /dev/null &
4552

4653
sleep 30
47-
./xenvm.native host-list /dev/djstest
54+
./xenvm.native host-list /dev/djstest --configdir /tmp/xenvm.d $MOCK_ARG
4855

4956
# 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
57+
./xenvm.native host-disconnect /dev/djstest host2 --configdir /tmp/xenvm.d $MOCK_ARG
58+
./xenvm.native host-destroy /dev/djstest host2 --configdir /tmp/xenvm.d $MOCK_ARG
59+
./xenvm.native host-disconnect /dev/djstest host1 --configdir /tmp/xenvm.d $MOCK_ARG
60+
./xenvm.native host-destroy /dev/djstest host1 --configdir /tmp/xenvm.d $MOCK_ARG
5461

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

5764
#shutdown
58-
./xenvm.native lvchange -an /dev/djstest/live || true
59-
./xenvm.native shutdown /dev/djstest
65+
./xenvm.native lvchange -an /dev/djstest/live --configdir /tmp/xenvm.d $MOCK_ARG || true
66+
./xenvm.native shutdown /dev/djstest --configdir /tmp/xenvm.d $MOCK_ARG
6067

6168
#echo Run 'sudo ./xenvm.native host-connect /dev/djstest host1' to connect to the local allocator'
6269
#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)

xenvm-local-allocator/local_allocator.ml

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module Time = struct
1919
let sleep = Lwt_unix.sleep
2020
end
2121

22+
let dm = ref (module Devmapper.Linux : Devmapper.S.DEVMAPPER)
23+
2224
let journal_size = Int64.(mul 4L (mul 1024L 1024L))
2325

2426
let rec try_forever msg f =
@@ -242,21 +244,19 @@ module Op = struct
242244
end
243245

244246
(* Return the virtual size of the volume *)
245-
let sizeof volume =
247+
let sizeof dm_targets =
246248
let open Devmapper in
247-
let open Devmapper.Linux in
248-
let ends = List.map (fun t -> Int64.add t.Target.start t.Target.size) volume.targets in
249+
let ends = List.map (fun t -> Int64.add t.Target.start t.Target.size) dm_targets in
249250
List.fold_left max 0L ends
250251

251252
(* Compute the new segments and device mapper targets if [extents] are appended onto [lv] *)
252-
let extend_volume device vg lv extents =
253+
let extend_volume device vg existing_targets extents =
253254
let open Lvm in
254255
let to_sector pv segment = Int64.(add pv.Pv.pe_start (mul segment vg.Vg.extent_size)) in
255256
(* We will extend the LV, so find the next 'virtual segment' *)
256-
let next_sector = sizeof lv in
257+
let next_sector = sizeof existing_targets in
257258
let _, segments, targets =
258259
let open Devmapper in
259-
let open Devmapper.Linux in
260260
List.fold_left
261261
(fun (next_sector, segments, targets) (pvname, (psegment, size)) ->
262262
try
@@ -282,14 +282,15 @@ let extend_volume device vg lv extents =
282282
) (next_sector, [], []) extents in
283283
List.rev segments, List.rev targets
284284

285-
let stat x =
286-
match Devmapper.Linux.stat x with
287-
| Some x -> return (`Ok x)
285+
let targets_of x =
286+
let module D = (val !dm: Devmapper.S.DEVMAPPER) in
287+
match D.stat x with
288+
| Some x -> return (`Ok x.D.targets)
288289
| None ->
289290
error "The device mapper device %s has disappeared." x;
290291
return (`Error `Retry)
291292

292-
let main config daemon socket journal fromLVM toLVM =
293+
let main use_mock config daemon socket journal fromLVM toLVM =
293294
let config = Config.t_of_sexp (Sexplib.Sexp.load_sexp config) in
294295
let config = { config with
295296
Config.socket = (match socket with None -> config.Config.socket | Some x -> x);
@@ -298,6 +299,10 @@ let main config daemon socket journal fromLVM toLVM =
298299
fromLVM = (match fromLVM with None -> config.Config.fromLVM | Some x -> x);
299300
} in
300301
debug "Loaded configuration: %s" (Sexplib.Sexp.to_string_hum (Config.sexp_of_t config));
302+
dm := if use_mock then (module Devmapper.Mock: Devmapper.S.DEVMAPPER) else (module Devmapper.Linux: Devmapper.S.DEVMAPPER);
303+
304+
let module D = (val !dm: Devmapper.S.DEVMAPPER) in
305+
301306
if daemon then Lwt_daemon.daemonize ();
302307

303308
Pidfile.write_pid (config.Config.socket ^ ".lock");
@@ -352,18 +357,18 @@ let main config daemon socket journal fromLVM toLVM =
352357
ToLVM.push tolvm t.volume
353358
>>= fun position ->
354359
let msg = Printf.sprintf "Querying dm device %s" t.device.ExpandDevice.device in
355-
try_forever msg (fun () -> stat t.device.ExpandDevice.device)
360+
try_forever msg (fun () -> targets_of t.device.ExpandDevice.device)
356361
>>= fun x ->
357362
fatal_error msg (return x)
358-
>>= fun to_device ->
363+
>>= fun to_device_targets ->
359364
(* Append the physical blocks to toLV *)
360-
let to_targets = to_device.Devmapper.Linux.targets @ t.device.ExpandDevice.targets in
361-
Devmapper.Linux.suspend t.device.ExpandDevice.device;
365+
let to_targets = to_device_targets @ t.device.ExpandDevice.targets in
366+
D.suspend t.device.ExpandDevice.device;
362367
print_endline "Suspend local dm device";
363-
Devmapper.Linux.reload t.device.ExpandDevice.device to_targets;
368+
D.reload t.device.ExpandDevice.device to_targets;
364369
ToLVM.advance tolvm position
365370
>>= fun () ->
366-
Devmapper.Linux.resume t.device.ExpandDevice.device;
371+
D.resume t.device.ExpandDevice.device;
367372
print_endline "Resume local dm device";
368373
return ()
369374
) ops
@@ -404,15 +409,15 @@ let main config daemon socket journal fromLVM toLVM =
404409
Lwt_mutex.with_lock m
405410
(fun () ->
406411
(* We may need to enlarge in multiple chunks if the free pool is depleted *)
407-
let rec expand action = match Devmapper.Linux.stat device with
412+
let rec expand action = match D.stat device with
408413
| None ->
409414
(* Log this kind of error. This tapdisk may block but at least
410415
others will keep going *)
411416
error "Couldn't find device mapper device: %s" device;
412417
return (ResizeResponse.Device_mapper_device_does_not_exist device)
413418
| Some data_volume ->
414419
let sector_size = Int64.of_int sector_size in
415-
let current = Int64.mul sector_size (sizeof data_volume) in
420+
let current = Int64.mul sector_size (sizeof data_volume.D.targets) in
416421
let extent_b = Int64.mul sector_size extent_size in
417422
(* NB: make sure we round up to the next extent *)
418423
let nr_extents = match action with
@@ -428,7 +433,7 @@ let main config daemon socket journal fromLVM toLVM =
428433
>>= fun extents ->
429434
(* This may have allocated short *)
430435
let nr_extents' = Lvm.Pv.Allocator.size extents in
431-
let segments, targets = extend_volume vg_device metadata data_volume extents in
436+
let segments, targets = extend_volume vg_device metadata data_volume.D.targets extents in
432437
let _, volume = Mapper.vg_lv_of_name device in
433438
let volume = { ExpandVolume.volume; segments } in
434439
let device = { ExpandDevice.extents; device; targets } in
@@ -448,7 +453,7 @@ let main config daemon socket journal fromLVM toLVM =
448453
expand action
449454
) in
450455

451-
let ls = Devmapper.Linux.ls () in
456+
let ls = D.ls () in
452457
debug "Visible device mapper devices: [ %s ]\n%!" (String.concat "; " ls);
453458

454459
let rec stdin () =
@@ -533,8 +538,12 @@ let fromLVM =
533538
let doc = "Path to the device or file which contains new free blocks from LVM" in
534539
Arg.(value & opt (some file) None & info [ "fromLVM" ] ~docv:"FROMLVM" ~doc)
535540

541+
let mock_dm_arg =
542+
let doc = "Enable mock interfaces on device mapper." in
543+
Arg.(value & flag & info ["mock-devmapper"] ~doc)
544+
536545
let () =
537-
let t = Term.(pure main $ config $ daemon $ socket $ journal $ fromLVM $ toLVM) in
546+
let t = Term.(pure main $ mock_dm_arg $ config $ daemon $ socket $ journal $ fromLVM $ toLVM) in
538547
match Term.eval (t, info) with
539548
| `Error _ -> exit 1
540549
| _ -> exit 0

0 commit comments

Comments
 (0)