Skip to content

Live migration of OSv guests using qemu

Franco Venturi edited this page Mar 13, 2015 · 6 revisions

Intra host (same host) case

Ingredients:

  • 1 Linux host (Ubuntu 14.10 in my case; Fedora should work too)
  • 1 virtual bridge (osvbr0; see below) running DHCP
  • 2 instances of qemu (one active and one stand-by, that we'll be migrating to) attached to the virtual bridge
  • 1 API client that connects to the active qemu instance via the virtual bridge

Diagrams:

+------------------------------------------------------------+
|                                                            |
|   +-----------------+                +-----------------+   |
|   |                 |                |                 |   |
|   |     OSv1        |                |      OSv2       |   |
|   |  (runs cli)     |      -->       |    (standby)    |   |
|   |                 |                | listens on 4444 |   |
|   +-----------------+                +-----------------+   |
|           | 192.168.123.10                   |             |
|           |                                  |             |
|   +----------------------------------------------------+   |   before
|   |          osvbridge - 192.168.123.0/24              |   |   migration
|   |                                                    |   |
|   +----------------------------------------------------+   |
|                         |                                  |
|                         | 192.168.123.1                    |
|               +-----------------------+                    |
|               |     API client        |                    |
|               +-----------------------+                    |
| Ubuntu 14.10 (fvbrick)                                     |
+------------------------------------------------------------+


+------------------------------------------------------------+
|                                                            |
|   +-----------------+                +-----------------+   |
|   |                 |                |                 |   |
|   |     OSv1        |                |      OSv2       |   |
|   |    (idle)       |                |   (runs cli)    |   |
|   |                 |                |                 |   |
|   +-----------------+                +-----------------+   |
|           |                                  | 192.168.123.10
|           |                                  |             |
|   +----------------------------------------------------+   |   after
|   |          osvbridge - 192.168.123.0/24              |   |   migration
|   |                                                    |   |
|   +----------------------------------------------------+   |
|                         |                                  |
|                         | 192.168.123.1                    |
|               +-----------------------+                    |
|               |     API client        |                    |
|               +-----------------------+                    |
| Ubuntu 14.10 (fvbrick)                                     |
+------------------------------------------------------------+

Preparation (all the paths are relative to the root of the OSv install directory):

  1. Add the following lua script as 'modules/cli/commands/loop.lua':

     local OptionParser = require('std.optparse')
     local socket = require('socket')
     
     local cmd = {}
     
     cmd.desc = [[infinite loop]]
     cmd.help = [[Usage: loop [-p period]
     
     Infinte loop.]]
     
     cmd.parser = OptionParser [[
     loop
     
     Usage: loop
     
     infinite loop
     
     Options:
     
       -p, --period=[SECONDS]  Loop interval (in seconds)
     ]]
     
     cmd.main = function(args)
       local args, opts = cmd.parser:parse(args)
     
       local period = 2
       if opts.period then
         period = opts.period
       end
     
       local counter = 0
       local prev_time = socket.gettime()
       while not cli_interrupted() do
         local date, status = osv_request({"os", "date"}, "GET")
         osv_resp_assert(status, 200)
         counter = counter + 1
         local time = socket.gettime()
         io.write(date, ' - ', counter, ' - ', time, ' - ', (time - prev_time), '\n')
         prev_time = time
         socket.sleep(period)
       end
     end
     
     return cmd
    

gjhh

Clone this wiki locally