Saturday, December 17, 2011

Rolling your own watchdog for Qemu

Sometimes there may arise a need to make your own watchdog for your virtual machine. The process itself is really a simple one, I will base this example on Intel's 6300esb watchdog.

Let's first start by getting the latest source code for Qemu:

git clone git://git.qemu.org/qemu.git && cd qemu


Now it is reasonable to switch to your own git branch in case you want to roll out some patches later on.

git checkout -b custom-watchdog



All of the existing watchdog sources are located at hw folder.

Make a copy of existing watchdog and include it in the build path.

cp hw/wdt_i6300esb.c hw/wdt_custom_watchdog.c


Now lets plug the new watchdog into the build process. For doing that we need to edit Makefile.objs and add a new line
hw-obj-$(CONFIG_PCI) += wdt_custom_watchdog.o

right after the "hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o" line.

Next step is to dig into the code and start modifying the new and improved watchdog. For the sake of simplicity I will leave the core functionality unchanged. I will only change the important parts of the code to enable the registering the new watchdog with Qemu.
Replace every reference to i3600esb and alike with your version of the name. If you skip some of the code then there is a chance that custom watchdog will not behave as expected. Most of the tedious replacement is easily done with sed commands similar to this.

sed -e 's/i6300esb/custom_watchdog/g' hw/wdt_i6300esb.c > hw/wdt_custom_watchdog.c


Now open up the code of the custom watchdog and fill in it's name and description with your own such as:


.wdt_description = "Super Custom Watchdog"


Recompile now and see if the new watchdog is visible and loading with Qemu.


qemu (custom-watchdog)$ ./i386-softmmu/qemu-system-i386 -watchdog ?
custom_watchdog Super Custom Watchdog
i6300esb Intel 6300ESB
ib700 iBASE 700

As it turns out, the new watchdog is visible for Qemu.

Let's run some VM with our new watchdog:

./i386-softmmu/qemu-system-i386 -watchdog custom_watchdog ~/debian.qcow2 



If everything goes well and the virtual machine comes up without any errors regarding the watchdog, the next step would be to replace some of the old variable names in the source code with more appropriate ones, otherwise the new watchdog is ready for further customization.

Source code here.

Software versions used:

  • Qemu sources for  version 1.0

Sunday, May 29, 2011

Low-level awesomeness!

Get the high performance computation as close to the metal as possible:
http://www.returninfinity.com/

Wednesday, May 25, 2011

Distributed Systems Seminar Presentation

Today's presentation slides and a demo of mesh topology setup.

Thursday, May 5, 2011

F2F meets Qemu

This post is about setting up VDE network between qemu machines through a F2F job. Tools I used are dpipe, vde_switch, vde_plug, nc, everything wrapped into python code that is in turn called from F2F job.
  • IPx - machine
  • Sx - vde_switch
Network layout:  star-topology - central node is master VM, all slave nodes are connected to its switch using their switches. Master virtual machine configuration: provide IP addresses on VDE. Slave virtual machine configuration: acquire IP from master VM.


F2F job
Idea
The F2F job defines two possible roles for a host - master or slave. In a master role the host launches master virtual machine which serves as a dhcp server for the VDE network. In a slave role the host launches the slave virtual machine which acquires its IP from master VM and joins VDE network.
I chose to use a separate vde_switch in front of each VM regardless of it being a master or slave VM to achieve uniform configuration layout across the network (machine-switch; switch-switch).

VM configuration
F2F job handles distributing configuration parameters for virtual machines. An unique id is assigned to each of the slave hosts based on the order of joining the group and in turn each of the slaves configure necessary parameters for launching and connecting the VM. Each slave node needs to know ip and port for VDE switch and ID for calculating unique MAC for the VM. 
On the host of the master  VM there is set up also a listening socket for each slave VM which is in turn connected to master switch.

Final notes

Finally I want to add some bits I learned about scaling the VDE network using dhcp. In this post the VDE network consists of a single master machine and several slave machines. Because of the boot times for multiple slave machines are different (MAC-s are assigned in random order) then it is tedious to describe all possible situations for interface names in slave's /etc/network/interfaces because by default udev writes rules for MAC-ethX associations. What I did was that I reconfigured udev to forget MAC addresses for certain MAC ranges. It already had rules for not remembering interfaces for virtual machines (wild-card MAC ranges) but they are overridden by the rules for some generic cards (Realtek, etc) which still force them to be written out. After commenting out rules for generic cards, udev didn't remember any MAC-ethX associations and interfaces configuration file for slave machine could be written in a very minimal manner.
 
Sample F2F job and  helper code can be found here and can be run using the  code from f2f-mobile branch (usual configuration).

Sunday, April 3, 2011

VDE network setup

A sample setup of qemu machines and VDE networking components is described. Configuration parameters for qemu might not be optimal since the emphasis was at the moment on the network configuration.


Tools & Components
Tools used for setting up following VDE network are:
  • vde_switch - a virtual switch
  • dpipe - two-way pipe here used to connect two switches
  • vde_plug - connects virtual machine (VM) to a switch
  • vde_plug2tap - connect tap device to a switch
  • qemu - for running VMs
Network layout 
 Sample network setup consists of two switched networks.
Q1, Q2 and Q3 are qemu virtual machines.
S1,S2  are VDE switches to which VMs are connected.
S1 and S2 are connected using dpipe and vde_plug-s
tap0 is an interface on the actual host machine which is running S2. tap0 is connected to S2 using vde_tap2plug.

Scripts
Setup scripts are currentlty hosted elsewhere. Click on the link to see the code.
  1. Launch S1 and S2, boot machines Q1..Q3 
  2. Connect S1 and S2 to external world
  3. Stop qemu machines and tear down VDE network
  4. Sample /etc/network/interfaces file for qemu machines


Useful links

Tuesday, March 15, 2011

About qemu and VDE

 This post contains general notes on how to get VDE and qemu running on Ubuntu 10.4. In the future it will be broken up into separate posts when this one gets too long and technical.

VDE bits and pieces
VDE network consists of multiple tools:
  • vde_switch - creates a virtual switch
  • vde_plug, vde_plug2tap - for creating virtual cables
  • dpipe - two-directional pipe, connects I/O streams of multiple programs
  • vdeq, vdekvm (deprecated) 
Creating a VDE network
  1. Launching VDE switches
    •  vde_switch  -F -s path/to/vde/socket
  2. Connect VDE switches
    •  use vde_plug, vde_plug2tap, dpipe to connect different vde_switches on the same and/or different machine 
    • Adding qemu machines to the VDE network
      • add to qemu command:  -net nic,macaddr='unique macaddr' -net vde,sock=path/to/vde/socket   
      • configure network on the guest 

      Recompiling qemu package for Ubuntu
      Ubuntu repository (lucid) does not contain qemu with built in VDE support (discussion). That means that one has to compile qemu himself containing VDE support. Here's how I roughly did it based on this:

      #get dependencies and tools for building (clean system probably needs more tools and libs) 
      apt-get source qemu-kvm
      cd qemu-kvm*
      sudo sudo apt-get build-dep qemu-kvm
      sudo sudo apt-get install devscripts
      sudo dch -l local 'qemu-kvm package with vde support'
      #configure and build the sources into the package
      ./configure --enable-vde  
      debuild -us -uc
      # install new packages
      cd .. 
      sudo dpkg -i qemu_0.12.3+noroms-0ubuntu9.4local2_i386.deb
      sudo dpkg -i qemu-kvm_0.12.3+noroms-0ubuntu9.4*.deb
      sudo apt-get install qemu-common_0.12.3+noroms-0ubuntu9.4local2_all.deb
      sudo aptitude install vgabios seabios
      sudo dpkg -i qemu-common_0.12.3+noroms-0ubuntu9.4local2_all.deb





      Links