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 (-65 / +4 lines)
Lines 17-34 Link Here
17
config = ShellConfigParser()
17
config = ShellConfigParser()
18
config.read('config.mak')
18
config.read('config.mak')
19
19
20
external_module = config.get('shell', 'want_module')
21
privileged = os.getuid() == 0
20
privileged = os.getuid() == 0
22
21
23
optparser = optparse.OptionParser()
22
optparser = optparse.OptionParser()
24
23
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',
24
optparser.add_option('--install',
33
                     help = 'start up guest in installer boot cd',
25
                     help = 'start up guest in installer boot cd',
34
                     action = 'store_true',
26
                     action = 'store_true',
Lines 67-78 Link Here
67
                     default = None,
59
                     default = None,
68
                     )
60
                     )
69
61
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',
62
optparser.add_option('--image',
77
                     help = 'select disk image',
63
                     help = 'select disk image',
78
                     dest = 'image',
64
                     dest = 'image',
Lines 124-175 Link Here
124
if len(args) > 1:
110
if len(args) > 1:
125
    options.cdrom = args[1]
111
    options.cdrom = args[1]
126
112
127
def remove_module(module):
113
commands.getstatusoutput('/sbin/udevsettle')
128
    module = module.replace('-', '_')
114
if not os.access('/dev/kvm', os.F_OK):
129
    lines = commands.getoutput('/sbin/lsmod').split('\n')
115
    print '/dev/kvm not present'
130
    for x in lines:
131
        if x.startswith(module + ' '):
132
            if os.spawnl(os.P_WAIT, '/sbin/rmmod', 'rmmod', module) != 0:
133
                raise Exception('failed to remove %s module' % (module,))
134
135
def insert_module(module):
136
    if os.spawnl(os.P_WAIT, '/sbin/insmod', 'insmod',
137
                 'kernel/%s.ko' % (module,)) != 0:
138
        raise Exception('failed to load kvm module')
139
140
def probe_module(module):
141
    if os.spawnl(os.P_WAIT, '/sbin/modprobe', 'modprobe', module) != 0:
142
        raise Exception('failed to load kvm module')
143
144
def vendor():
145
    for x in file('/proc/cpuinfo').readlines():
146
        m = re.match(r'vendor_id[ \t]*: *([a-zA-Z]+),*', x)
147
        if m:
148
            return m.group(1)
149
    return unknown
150
151
vendor_module = {
152
    'GenuineIntel': 'kvm-intel',
153
    'AuthenticAMD': 'kvm-amd',
154
    }[vendor()]
155
156
if options.kvm and options.reload:
157
    for module in [vendor_module, 'kvm']:
158
        remove_module(module)
159
    if external_module:
160
        insmod = insert_module
161
    else:
162
        insmod = probe_module
163
    for module in ['kvm', vendor_module]:
164
        insmod(module)
165
    commands.getstatusoutput('/sbin/udevsettle')
166
    if not os.access('/dev/kvm', os.F_OK):
167
        print '/dev/kvm not present'
168
116
169
disk = options.image
117
disk = options.image
170
if options.install:
118
if options.install:
171
    (status, output) = commands.getstatusoutput(
119
    (status, output) = commands.getstatusoutput(
172
        'qemu/qemu-img create -f qcow2 "%s" 10G' % disk)
120
        'qemu-img create -f qcow2 "%s" 10G' % disk)
173
    if status:
121
    if status:
174
        raise Exception, output
122
        raise Exception, output
175
123
Lines 184-195 Link Here
184
else:
132
else:
185
    cmd = 'qemu'
133
    cmd = 'qemu'
186
134
187
local_cmd = 'qemu/' + arch + '-softmmu/' + cmd
188
if os.access(local_cmd, os.F_OK):
189
    cmd = local_cmd
190
else:
191
    cmd = '/usr/bin/kvm'
192
193
qemu_args = (cmd, '-boot', bootdisk,
135
qemu_args = (cmd, '-boot', bootdisk,
194
             '-hda', disk, '-m', str(options.memory),
136
             '-hda', disk, '-m', str(options.memory),
195
             '-serial', 'file:/tmp/serial.log',
137
             '-serial', 'file:/tmp/serial.log',
Lines 200-208 Link Here
200
if options.cdrom:
142
if options.cdrom:
201
    qemu_args += ('-cdrom', options.cdrom,)
143
    qemu_args += ('-cdrom', options.cdrom,)
202
144
203
if not options.kvm:
204
    qemu_args += ('-no-kvm',)
205
206
if options.debugger:
145
if options.debugger:
207
    qemu_args += ('-s',)
146
    qemu_args += ('-s',)
208
147

Return to bug 157987