[Ovirt-devel] [PATCH] Virtio support

Arthur Clement aclement at linagora.com
Wed Aug 25 09:05:02 UTC 2010


From: Simon Courtois <scourtois at linagora.com>


Signed-off-by: Simon Courtois <scourtois at linagora.com>
---
 src/app/controllers/vm_controller.rb           |   19 ++++++++++++++++-
 src/app/views/vm/_form.rhtml                   |   25 ++++++++++++++++++++---
 src/db/migrate/044_add_virtio_to_vm_and_nic.rb |   11 ++++++++++
 src/public/stylesheets/components.css          |    5 ++++
 src/task-omatic/task_vm.rb                     |   10 ++++++++-
 src/task-omatic/taskomatic.rb                  |    4 +-
 6 files changed, 65 insertions(+), 9 deletions(-)
 create mode 100644 src/db/migrate/044_add_virtio_to_vm_and_nic.rb

diff --git a/src/app/controllers/vm_controller.rb b/src/app/controllers/vm_controller.rb
index 9860843..bc01a8c 100644
--- a/src/app/controllers/vm_controller.rb
+++ b/src/app/controllers/vm_controller.rb
@@ -146,6 +146,18 @@ class VmController < ApplicationController
     render :layout => false
   end
 
+  def edit_vmpool
+    svc_modify(params[:id])
+    @vm = Vm.find(params[:id])
+    render :layout => 'popup'
+  end
+
+  def update_vmpool
+    svc_modify(params[:id])
+    @vm = Vm.find(params[:id])
+    # TODO
+  end
+
   protected
   def _setup_provisioning_options
     @provisioning_options = [[Vm::PXE_OPTION_LABEL, Vm::PXE_OPTION_VALUE],
@@ -176,7 +188,8 @@ class VmController < ApplicationController
       @vm.nics.each { |nic|
          nnic = Nic.new(:mac => nic.mac,
                         :vm_id => @vm.id,
-                        :network => nic.network)
+                        :network => nic.network,
+                        :virtio => nic.virtio)
 
          if(nic.network.boot_type.proto == 'static')
            nnic.ip_addresses << IpAddress.new(:address => nic.ip_address)
@@ -216,7 +229,9 @@ class VmController < ApplicationController
           network_id = params[:networks][i]
           unless network_id.nil? || network_id == ""
              nic = { :mac => params[:macs][i],
-                     :network_id => network_id, :bandwidth => 0 }
+                     :network_id => network_id,
+                     :bandwidth => 0,
+                     :virtio => params[:virtio][i.to_s] }
 
              if(Network.find(network_id).boot_type.proto == 'static')
                 # FIXME make this able to be v4 or v6 address
diff --git a/src/app/views/vm/_form.rhtml b/src/app/views/vm/_form.rhtml
index adb75d2..272889c 100644
--- a/src/app/views/vm/_form.rhtml
+++ b/src/app/views/vm/_form.rhtml
@@ -44,6 +44,11 @@
     <!-- FIXME: fill in total here -->
     <div style="background:#F3F3F3; padding:6px; border-left:#CCCCCC solid 1px; border-right:#CCCCCC solid 1px; border-bottom:#CCCCCC solid 1px; ">Total:</div>
     <div class="clear_row" style="height:15px;"></div>
+
+    <div class="form_field">
+      <%= check_box "vm", "virtio" %>
+      <%= label "vm", "virtio", "Use virtio" %>
+    </div>
   </div>
   <div class="clear_row"></div>
 
@@ -87,6 +92,12 @@
                  
               </div>
 
+              <div class="vm_network_config_virtio">
+                <%= hidden_field_tag "virtio[#{i}]", "0" %>
+                <%= check_box_tag "virtio[#{i}]", "1", @nics[i].virtio, :id => "vm_network_config_virtio_#{i}" %>
+		<%= label_tag "vm_network_config_virtio_#{i}", "Use virtio" %>
+              </div>
+
               <% if i != 0 %>
                 <div id="vm_network_config_remove_<%= i %>" class="vm_network_config_remove">
                   Remove
@@ -113,10 +124,11 @@
   </div>
   <div class="clear_row"></div>
 
-   <div class="form_heading"/>
-   <%= check_box_tag_with_label "Start VM Now? (pending current resource availability)", "start_now", nil if create or @vm.state == Vm::STATE_STOPPED %>
-   <%= check_box_tag_with_label "Restart VM Now? (pending current resource availability)", "restart_now", nil if @vm.state == Vm::STATE_RUNNING %>
-
+   <div class="form_heading clickable closed">Restart</div>
+   <div class="vm_form_section" style="display:none;">
+    <%= check_box_tag_with_label "Start VM Now? (pending current resource availability)", "start_now", nil if create or @vm.state == Vm::STATE_STOPPED %>
+    <%= check_box_tag_with_label "Restart VM Now? (pending current resource availability)", "restart_now", nil if @vm.state == Vm::STATE_RUNNING %>
+   </div>
 <!--[eoform:vm]-->
 
 <textarea id="storage_volumes_template" style="display:none;">
@@ -180,6 +192,7 @@ ${htmlList(pools, id)}
        jnic.name        = "<%= rnic.network.name %>";
        jnic.mac         = "<%= rnic.mac %>";
        jnic.ip          = "<%= rnic.ip_address %>";
+       jnic.virtio      = <%= rnic.virtio ? 'true' : 'false' %>;
        jnic.static_ip   = <%= rnic.network.boot_type.proto == 'static' %>;
        jnic.selected    = false;
        jnic.row         = null;
@@ -260,6 +273,9 @@ ${htmlList(pools, id)}
                ip_div.html(' ');
 	         }
 
+             // set virtio if checked
+             $('#vm_network_config_virtio_'+row).attr('checked', nic.virtio ? 'checked' : '');
+
              // show new row only if last row's select box was
              // previously empty, and if all are not shown
 	         displayed_rows = $('.vm_network_config_row:visible').size();
@@ -282,6 +298,7 @@ ${htmlList(pools, id)}
             // clear row mac and ip addresses
             $('#vm_network_config_mac_'+row).attr('value', '');
             $('#vm_network_config_mac_'+row).parent().next().html(' ');
+            $('#vm_network_config_virtio_'+row).attr('checked', '');
 
             // hide row if not the first
 	        if(row != 0){
diff --git a/src/db/migrate/044_add_virtio_to_vm_and_nic.rb b/src/db/migrate/044_add_virtio_to_vm_and_nic.rb
new file mode 100644
index 0000000..06875c9
--- /dev/null
+++ b/src/db/migrate/044_add_virtio_to_vm_and_nic.rb
@@ -0,0 +1,11 @@
+class AddVirtioToVmAndNic < ActiveRecord::Migration
+  def self.up
+    add_column :vms, :virtio, :boolean, :default => false
+    add_column :nics, :virtio, :boolean, :default => false
+  end
+
+  def self.down
+    remove_column :vms, :virtio
+    remove_column :nics, :virtio
+  end
+end
diff --git a/src/public/stylesheets/components.css b/src/public/stylesheets/components.css
index 2cda65d..70cda97 100644
--- a/src/public/stylesheets/components.css
+++ b/src/public/stylesheets/components.css
@@ -367,6 +367,11 @@
   max-width: 150px;
 }
 
+.vm_network_config_virtio {
+  float: left;
+  width: 80px;
+}
+
 .vm_network_config_net select,
 .vm_network_config_mac input,
 .vm_network_config_ip input {
diff --git a/src/task-omatic/task_vm.rb b/src/task-omatic/task_vm.rb
index dd71747..cc2071f 100644
--- a/src/task-omatic/task_vm.rb
+++ b/src/task-omatic/task_vm.rb
@@ -35,7 +35,7 @@ end
 
 
 def create_vm_xml(name, uuid, memAllocated, memUsed, vcpus, bootDevice,
-                  net_interfaces, diskDevices)
+                  virtio, net_interfaces, diskDevices)
   doc = Document.new
 
   doc.add_element("domain", {"type" => "kvm"})
@@ -78,6 +78,10 @@ def create_vm_xml(name, uuid, memAllocated, memUsed, vcpus, bootDevice,
       diskdev.add_element("readonly")
       diskdev.add_element("source", {"file" => disk})
       diskdev.add_element("target", {"dev" => devs[which_device], "bus" => "ide"})
+    elsif virtio
+      diskdev.add_element("driver", {"name" => "qemu", "type" => "raw"})
+      diskdev.add_element("source", {"dev" => disk})
+      diskdev.add_element("target", {"dev" => "vda", "bus" => "virtio"})
     else
       diskdev.add_element("source", {"dev" => disk})
       diskdev.add_element("target", {"dev" => devs[which_device]})
@@ -92,6 +96,10 @@ def create_vm_xml(name, uuid, memAllocated, memUsed, vcpus, bootDevice,
     interface.add_attribute("type", "bridge")
     interface.add_element("mac", {"address" => nic[:mac]})
     interface.add_element("source", {"bridge" => nic[:interface]})
+
+    if nic[:virtio]
+      interface.add_element("model", {"type" => "virtio"})
+    end
     doc.root.elements["devices"] << interface
   }
 
diff --git a/src/task-omatic/taskomatic.rb b/src/task-omatic/taskomatic.rb
index 31c38e3..5c6a673 100755
--- a/src/task-omatic/taskomatic.rb
+++ b/src/task-omatic/taskomatic.rb
@@ -409,12 +409,12 @@ class TaskOmatic
        else
           net_device = "breth0" # FIXME remove this default at some point
        end
-       net_interfaces.push({ :mac => nic.mac, :interface => net_device })
+       net_interfaces.push({ :mac => nic.mac, :interface => net_device, :virtio => nic.virtio })
     }
 
     xml = create_vm_xml(db_vm.description, db_vm.uuid, db_vm.memory_allocated,
               db_vm.memory_used, db_vm.num_vcpus_allocated, db_vm.boot_device,
-              net_interfaces, storagedevs)
+              db_vm.virtio, net_interfaces, storagedevs)
 
     @logger.debug("XML Domain definition: #{xml}")
 
-- 
1.7.2.1




More information about the ovirt-devel mailing list