[Libguestfs] [PATCH 3/4] stub client side mount operation to setup disk and inform server of its location

Mo Morsi mmorsi at redhat.com
Fri May 10 12:19:47 UTC 2013


---
 p2v/client/lib/virt-p2v/connection.rb | 12 ++++++++++++
 p2v/client/lib/virt-p2v/converter.rb  | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/p2v/client/lib/virt-p2v/connection.rb b/p2v/client/lib/virt-p2v/connection.rb
index c3e5537..b923144 100644
--- a/p2v/client/lib/virt-p2v/connection.rb
+++ b/p2v/client/lib/virt-p2v/connection.rb
@@ -243,6 +243,18 @@ class Connection
         }
     end
 
+    def mount(uri, disk_type, &cb)
+        raise NotConnectedError if @channel.nil?
+
+        run(completion) {
+            @channel.write("MOUNT #{uri} #{disk_type}\n")
+            result = parse_return
+
+            Gtk.queue { cb.call(result) }
+        }
+    end
+
+
     private
 
     def run(cb)
diff --git a/p2v/client/lib/virt-p2v/converter.rb b/p2v/client/lib/virt-p2v/converter.rb
index 7cb4e33..ef7541f 100644
--- a/p2v/client/lib/virt-p2v/converter.rb
+++ b/p2v/client/lib/virt-p2v/converter.rb
@@ -37,6 +37,9 @@ module VirtP2V
 #   path          Detected
 #   is_block      1
 #   format        raw
+# mounts        Editable, default to none
+#   device        Detected
+#   uri           Detected
 # removables    Editable, default to all
 #   device        Detected
 #   type          Detected
@@ -47,7 +50,7 @@ module VirtP2V
 
 class Converter
     attr_accessor :profile, :name, :cpus, :memory, :arch, :debug
-    attr_reader :features, :disks, :removables, :nics
+    attr_reader :features, :disks, :mounts, :removables, :nics
 
     attr_reader :connection
 
@@ -74,6 +77,13 @@ class Converter
                 }, cb)
             },
             lambda { |cb|
+                iterate(@mounts.map { |dev|
+                    lambda { |cb2|
+                      mount(dev, status, cb2)
+                    }
+                }, cb)
+            },
+            lambda { |cb|
                 if @debug
                     begin
                         @connection.options({ "DEBUG" => 1 }, &cb)
@@ -140,6 +150,7 @@ class Converter
         # Initialise empty lists for optional devices. These will be added
         # according to the user's selection
         @disks = []
+        @mounts = []
         @removables = []
         @nics = []
 
@@ -174,6 +185,20 @@ class Converter
         ], completion)
     end
 
+    def mount(dev, status, completion)
+        path  = "/dev/#{dev}"
+        status.call("Mounting #{dev}")
+        disk_type  = 'iscsi'
+        # TODO set uri
+        #      if nbd, use qemu-nbd to setup nbd access point to img
+        #      if iscsi, setup loop device infront of img, add new tgt
+        #            target to setup iscsi access point to loop device
+        uri = ""
+        iterate([
+            lambda { |cb| @connection.mount(uri, disk_type, &cb) }
+          ], completion)
+    end
+
     def iterate(stages, completion)
         i = 0
         cb = lambda { |result|
@@ -204,6 +229,13 @@ class Converter
                     'path'      => "/dev/#{device}"
                 }
             },
+            'mounts'    => @mounts.map { |dev|
+                {
+                    'device'     => device,
+                    'path'       => "/dev/#{device}",
+                    'uri'        => ""
+                }
+            },
             'removables' => @removables.map { |device|
                 removable = RemovableBlockDevice[device]
                 {
-- 
1.7.11.7




More information about the Libguestfs mailing list