Skip to content

Commit cd0704b

Browse files
author
David Scott
committed
Refuse to open a device if it has the wrong PV label
We don't want to race with the existing LVM tools, so if we see an old-style volume then we will refuse to open it. Fixes #64 Signed-off-by: David Scott <[email protected]>
1 parent b531e58 commit cd0704b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

xenvmd/xenvmd.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,26 @@ module VolumeManager = struct
146146
| `Ok x -> return x
147147
) devices'
148148
>>= fun devices' ->
149+
let module Label_IO = Lvm.Label.Make(Block) in
150+
Lwt_list.iter_s
151+
(fun device ->
152+
Label_IO.read device >>= function
153+
| `Error (`Msg m) ->
154+
error "Failed to read PV label from device: %s" m;
155+
fail (Failure "Failed to read PV label from device")
156+
| `Ok label ->
157+
begin match Lvm.Label.Label_header.magic_of label.Lvm.Label.label_header with
158+
| Some `Lvm ->
159+
error "Device has normal LVM PV label. I will only open devices with the new PV label.";
160+
fail (Failure "Device has wrong LVM PV label")
161+
| Some `Journalled ->
162+
return ()
163+
| _ ->
164+
error "Device has an unrecognised LVM PV label. I will only open devices with the new PV label.";
165+
fail (Failure "Device has wrong PV label")
166+
end
167+
) devices'
168+
>>= fun () ->
149169
Vg_IO.connect ~flush_interval:5. devices' `RW >>|= fun vg ->
150170
Lwt.wakeup_later myvg_u vg;
151171
return ()

0 commit comments

Comments
 (0)