]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
The checksumming for meta-data of mlvm now agrees with the original lvm.
authorMatthias Goergens <matthias.goergens@citrix.com>
Thu, 8 Jul 2010 14:02:27 +0000 (15:02 +0100)
committerMatthias Goergens <matthias.goergens@citrix.com>
Thu, 8 Jul 2010 14:02:27 +0000 (15:02 +0100)
Signed-off-by: Matthias Goergens <matthias.goergens@citrix.com>
mlvm/pv.ml

index 528f23b33c1071aed2fd2c6be50500bea1ab86ee..c6c14c732ba78361912bc08225133bcf1252548d 100644 (file)
@@ -300,38 +300,40 @@ module MDAHeader = struct
     if written <> Constants.sector_size then failwith "Wrote short!";
     Unix.close fd
       
-  let read_md dev mdah n =
-    (* debug *)
-    let oc = open_out "/tmp/hdr" in
-    Printf.fprintf oc "%s\n%!" (to_ascii mdah);
-    close_out oc;
-
-    let locn = List.nth mdah.mdah_raw_locns n in
-    let fd = 
-      if !Constants.dummy_mode then begin
-       Unix.openfile (dummy_fname dev "md") [Unix.O_RDONLY] 0o000
-      end else begin
-       let fd = Unix.openfile dev [Unix.O_RDONLY] 0o000 in
-       ignore(Unix.LargeFile.lseek fd (Int64.add mdah.mdah_start locn.mrl_offset) Unix.SEEK_SET);  
-       fd
-      end
-    in
-    let md = 
-      if(Int64.add locn.mrl_offset locn.mrl_size > mdah.mdah_size) 
-      then
-       let firstbit = Int64.to_int (Int64.sub mdah.mdah_size locn.mrl_offset) in
-       let firstbitstr = really_read fd firstbit in
-       let secondbit = (Int64.to_int locn.mrl_size) - firstbit - 1 in
-       if not !Constants.dummy_mode then ignore(Unix.LargeFile.lseek fd (Int64.add mdah.mdah_start 512L) Unix.SEEK_SET);  
-       let secondbitstr = really_read fd secondbit in
-       firstbitstr ^ secondbitstr
-      else
-       really_read fd (Int64.to_int locn.mrl_size - 1) in
-    let checksum = Crc.crc md Crc.initial_crc in
-    Unix.close fd;
-    if checksum <> locn.mrl_checksum then
-      Printf.fprintf stderr "Checksum invalid in metadata: Found %lx, expecting %lx\n" checksum locn.mrl_checksum;
-    md
+       let read_md dev mdah n =
+               (* debug *)
+               let oc = open_out "/tmp/hdr" in
+               Printf.fprintf oc "%s\n%!" (to_ascii mdah);
+               close_out oc;
+
+               let locn = List.nth mdah.mdah_raw_locns n in
+               let fd =
+                       if !Constants.dummy_mode then begin
+                               Unix.openfile (dummy_fname dev "md") [Unix.O_RDONLY] 0o000
+                       end else begin
+                               let fd = Unix.openfile dev [Unix.O_RDONLY] 0o000 in
+                               ignore(Unix.LargeFile.lseek fd (Int64.add mdah.mdah_start locn.mrl_offset) Unix.SEEK_SET);
+                               fd
+                       end
+               in
+               let md =
+                       (* Include terminating \0 in this string.
+                        * The checksum calculation in original lvm does so, too.*)
+                       if(Int64.add locn.mrl_offset locn.mrl_size > mdah.mdah_size)
+                       then (* wrap around *)
+                               let firstbit = Int64.to_int (Int64.sub mdah.mdah_size locn.mrl_offset) in
+                               let firstbitstr = really_read fd firstbit in
+                               let secondbit = (Int64.to_int locn.mrl_size) - firstbit in
+                               if not !Constants.dummy_mode then ignore(Unix.LargeFile.lseek fd (Int64.add mdah.mdah_start 512L) Unix.SEEK_SET);
+                               let secondbitstr = really_read fd secondbit in
+                               firstbitstr ^ secondbitstr
+                       else
+                               really_read fd (Int64.to_int locn.mrl_size) in
+               let checksum = Crc.crc md Crc.initial_crc in
+               Unix.close fd;
+               if checksum <> locn.mrl_checksum then
+                       Printf.fprintf stderr "Checksum invalid in metadata: Found %lx, expecting %lx\n" checksum locn.mrl_checksum;
+               md
       
   let write_md device mdah md =
     (* Find the current raw location of the metadata, assuming there's only one copy *)