[Pkg-libvirt-commits] [libguestfs] 16/146: v2v: linux: Refactor device replacement code.

Hilko Bengen bengen at moszumanska.debian.org
Sun Mar 29 17:00:06 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch master
in repository libguestfs.

commit 27b668c93cf92be011a9e4db0742633d01f6a87d
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Tue Nov 18 14:17:35 2014 +0000

    v2v: linux: Refactor device replacement code.
    
    No functional change.  This should be equivalent to previously.
    
    (cherry picked from commit 467bbf72f74527ca00678cfea80b1785868cd842)
---
 v2v/convert_linux.ml | 55 ++++++++++++++++++++++++++--------------------------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index f2c4461..f2736f1 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -1310,55 +1310,54 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
       Str.regexp "^/dev/\\([a-z]+\\)$" in
 
     let rec replace_if_device path value =
-      if Str.string_match rex_device_cciss_p value 0 then (
+      let replace device =
+        try List.assoc device map
+        with Not_found ->
+          if string_find device "md" = -1 && string_find device "fd" = -1 &&
+            device <> "cdrom" then
+            warning (f_"%s references unknown device \"%s\".  You may have to fix this entry manually after conversion.")
+              path device;
+          device
+      in
+
+      if string_find path "GRUB_CMDLINE" >= 0 then (
+        (* Handle grub2 resume=<dev> specially. *)
+        if Str.string_match rex_resume value 0 then (
+          let start = Str.matched_group 1 value
+          and device = Str.matched_group 2 value
+          and end_ = Str.matched_group 3 value in
+          let device = replace_if_device path device in
+          start ^ device ^ end_
+        )
+        else value
+      )
+      else if Str.string_match rex_device_cciss_p value 0 then (
         let device = Str.matched_group 1 value
         and part = Str.matched_group 2 value in
-        "/dev/" ^ replace path device ^ part
+        "/dev/" ^ replace device ^ part
       )
       else if Str.string_match rex_device_cciss value 0 then (
         let device = Str.matched_group 1 value in
-        "/dev/" ^ replace path device
+        "/dev/" ^ replace device
       )
       else if Str.string_match rex_device_p value 0 then (
         let device = Str.matched_group 1 value
         and part = Str.matched_group 2 value in
-        "/dev/" ^ replace path device ^ part
+        "/dev/" ^ replace device ^ part
       )
       else if Str.string_match rex_device value 0 then (
         let device = Str.matched_group 1 value in
-        "/dev/" ^ replace path device
+        "/dev/" ^ replace device
       )
       else (* doesn't look like a known device name *)
         value
-
-    and replace path device =
-      try List.assoc device map
-      with Not_found ->
-        if string_find device "md" = -1 && string_find device "fd" = -1 &&
-          device <> "cdrom" then
-          warning (f_"%s references unknown device \"%s\".  You may have to fix this entry manually after conversion.")
-            path device;
-        device
     in
 
     let changed = ref false in
     List.iter (
       fun path ->
         let value = g#aug_get path in
-
-        let new_value =
-          (* Handle grub2 resume=<dev> specially. *)
-          if string_find path "GRUB_CMDLINE" >= 0 then (
-            if Str.string_match rex_resume value 0 then (
-              let start = Str.matched_group 1 value
-              and device = Str.matched_group 2 value
-              and end_ = Str.matched_group 3 value in
-              let device = replace_if_device path device in
-              start ^ device ^ end_
-            )
-            else value
-          )
-          else replace_if_device path value in
+        let new_value = replace_if_device path value in
 
         if value <> new_value then (
           g#aug_set path new_value;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list