one_xen_4.0_poll.patch

Check for xen version and use different polling strategy - Vivien Bernet-Rollande, 05/17/2011 12:05 PM

Download (2.15 KB)

View differences:

src/vmm_mad/remotes/poll_xen_kvm.rb
179 179

  
180 180
module XEN
181 181
    CONF={
182
        'XM_POLL' => 'sudo /usr/sbin/xentop -bi2'
182
        'XM_INFO' => 'sudo /usr/sbin/xm info',
183
        'XM_POLL_XEN_3' => 'sudo /usr/sbin/xentop -bi2',
184
        'XM_POLL_XEN_4' => 'sudo /usr/sbin/xentop -fbi1'
183 185
    }
184 186
    
185 187
    def self.get_vm_info(vm_id)
......
191 193
            return data
192 194
        end
193 195
    end
194
    
196

  
197
    def self.get_xen_version
198
    begin
199
        xen_major=`xm info |awk '/xen_major/{print $3}'`.to_i
200
        xen_minor=`xm info |awk '/xen_minor/{print $3}'`.to_i
201
        xen_extra=`xm info |awk '/xen_minor/{print $3}'`.delete('.').to_i
202
        return [xen_major, xen_minor, xen_extra]
203
    rescue
204
        STDERR.puts "Failed to get Xen version, assuming 3.0.0"
205
        return [3, 0, 0]
206
    end
207
    end
208

  
195 209
    def self.get_all_vm_info
196 210
    begin
197
        text=`#{CONF['XM_POLL']}`
198
        lines=text.strip.split("\n")
199
        block_size=lines.length/2
200
        valid_lines=lines.last(block_size)
201
        
202
        domain_lines=valid_lines[4..-1]
203
        
211
        # The arguments to xentop change depending on the xentop version.
212
        # The headers are not repeated by default in Xen 4.0.1, unless the -f
213
        # option is specified. Older versions of Xentop do not have a -f flag.
214
        version = get_xen_version
215
        if version[0] <= 3 then
216
            text=`#{CONF['XM_POLL_XEN_3']}`
217
            lines=text.strip.split("\n")
218
            block_size=lines.length/2
219
            valid_lines=lines.last(block_size)
220
            domain_lines=valid_lines[4..-1]
221
        else
222
            text=`#{CONF['XM_POLL_XEN_4']}`
223
            lines=text.strip.split("\n")
224
            domain_lines=lines.last(lines.length - 1)
225
        end
226

  
204 227
        domains=Hash.new
205 228
        
206 229
        domain_lines.each do |dom|
......
221 244
        domains
222 245
    rescue
223 246
        STDERR.puts "Error executing #{CONF['XM_POLL']}"
224
        nil
247
        []
225 248
    end
226 249
    end
227 250