Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 157987 | Differences between
and this patch

Collapse All | Expand All

(-)kvm.orig (-64 / +4 lines)
Lines 22-34 Link Here
22
22
23
optparser = optparse.OptionParser()
23
optparser = optparse.OptionParser()
24
24
25
optparser.add_option('--no-reload-module',
26
                     help = 'do not reload kvm module',
27
                     action = 'store_false',
28
                     dest = 'reload',
29
                     default = privileged,
30
                     )
31
32
optparser.add_option('--install',
25
optparser.add_option('--install',
33
                     help = 'start up guest in installer boot cd',
26
                     help = 'start up guest in installer boot cd',
34
                     action = 'store_true',
27
                     action = 'store_true',
Lines 67-78 Link Here
67
                     default = None,
60
                     default = None,
68
                     )
61
                     )
69
62
70
optparser.add_option('--no-kvm',
71
                     help = 'use standard qemu, without kvm',
72
                     action = 'store_false',
73
                     dest = 'kvm',
74
                     default = True,
75
                     )
76
optparser.add_option('--image',
63
optparser.add_option('--image',
77
                     help = 'select disk image',
64
                     help = 'select disk image',
78
                     dest = 'image',
65
                     dest = 'image',
Lines 117-168 Link Here
117
if len(args) > 1:
104
if len(args) > 1:
118
    options.cdrom = args[1]
105
    options.cdrom = args[1]
119
106
120
def remove_module(module):
107
commands.getstatusoutput('/sbin/udevsettle')
121
    module = module.replace('-', '_')
108
if not os.access('/dev/kvm', os.F_OK):
122
    lines = commands.getoutput('/sbin/lsmod').split('\n')
109
    print '/dev/kvm not present'
123
    for x in lines:
124
        if x.startswith(module + ' '):
125
            if os.spawnl(os.P_WAIT, '/sbin/rmmod', 'rmmod', module) != 0:
126
                raise Exception('failed to remove %s module' % (module,))
127
128
def insert_module(module):
129
    if os.spawnl(os.P_WAIT, '/sbin/insmod', 'insmod',
130
                 'kernel/%s.ko' % (module,)) != 0:
131
        raise Exception('failed to load kvm module')
132
133
def probe_module(module):
134
    if os.spawnl(os.P_WAIT, '/sbin/modprobe', 'modprobe', module) != 0:
135
        raise Exception('failed to load kvm module')
136
137
def vendor():
138
    for x in file('/proc/cpuinfo').readlines():
139
        m = re.match(r'vendor_id[ \t]*: *([a-zA-Z]+),*', x)
140
        if m:
141
            return m.group(1)
142
    return unknown
143
144
vendor_module = {
145
    'GenuineIntel': 'kvm-intel',
146
    'AuthenticAMD': 'kvm-amd',
147
    }[vendor()]
148
149
if options.kvm and options.reload:
150
    for module in [vendor_module, 'kvm']:
151
        remove_module(module)
152
    if external_module:
153
        insmod = insert_module
154
    else:
155
        insmod = probe_module
156
    for module in ['kvm', vendor_module]:
157
        insmod(module)
158
    commands.getstatusoutput('/sbin/udevsettle')
159
    if not os.access('/dev/kvm', os.F_OK):
160
        print '/dev/kvm not present'
161
110
162
disk = options.image
111
disk = options.image
163
if options.install:
112
if options.install:
164
    (status, output) = commands.getstatusoutput(
113
    (status, output) = commands.getstatusoutput(
165
        'qemu/qemu-img create -f qcow2 "%s" 10G' % disk)
114
        'qemu-img create -f qcow2 "%s" 10G' % disk)
166
    if status:
115
    if status:
167
        raise Exception, output
116
        raise Exception, output
168
117
Lines 177-188 Link Here
177
else:
126
else:
178
    cmd = 'qemu'
127
    cmd = 'qemu'
179
128
180
local_cmd = 'qemu/' + arch + '-softmmu/' + cmd
181
if os.access(local_cmd, os.F_OK):
182
    cmd = local_cmd
183
else:
184
    cmd = '/usr/bin/kvm'
185
186
qemu_args = (cmd, '-boot', bootdisk,
129
qemu_args = (cmd, '-boot', bootdisk,
187
             '-hda', disk, '-m', str(options.memory),
130
             '-hda', disk, '-m', str(options.memory),
188
             '-serial', 'file:/tmp/serial.log',
131
             '-serial', 'file:/tmp/serial.log',
Lines 192-200 Link Here
192
if options.cdrom:
135
if options.cdrom:
193
    qemu_args += ('-cdrom', options.cdrom,)
136
    qemu_args += ('-cdrom', options.cdrom,)
194
137
195
if not options.kvm:
196
    qemu_args += ('-no-kvm',)
197
198
if options.debugger:
138
if options.debugger:
199
    qemu_args += ('-s',)
139
    qemu_args += ('-s',)
200
140

Return to bug 157987