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 (-57 / +6 lines)
Lines 5-17 Link Here
5
5
6
optparser = optparse.OptionParser()
6
optparser = optparse.OptionParser()
7
7
8
optparser.add_option('--no-reload-module',
9
                     help = 'do not reload kvm module',
10
                     action = 'store_false',
11
                     dest = 'reload',
12
                     default = True,
13
                     )
14
15
optparser.add_option('--install',
8
optparser.add_option('--install',
16
                     help = 'start up guest in installer boot cd',
9
                     help = 'start up guest in installer boot cd',
17
                     action = 'store_true',
10
                     action = 'store_true',
Lines 50-71 Link Here
50
                     default = None,
43
                     default = None,
51
                     )
44
                     )
52
45
53
optparser.add_option('--no-kvm',
54
                     help = 'use standard qemu, without kvm',
55
                     action = 'store_false',
56
                     dest = 'kvm',
57
                     default = True,
58
                     )
59
optparser.add_option('--image',
46
optparser.add_option('--image',
60
                     help = 'select disk image',
47
                     help = 'select disk image',
61
                     dest = 'image',
48
                     dest = 'image',
62
                     default = '/tmp/disk',
49
                     default = '/tmp/disk',
63
                     )
50
                     )
51
64
optparser.add_option('--cdrom',
52
optparser.add_option('--cdrom',
65
                     help = 'select cdrom image',
53
                     help = 'select cdrom image',
66
                     dest = 'cdrom',
54
                     dest = 'cdrom',
67
                     default = None,
55
                     default = None,
68
                     )
56
                     )
57
69
optparser.add_option('--loadvm',
58
optparser.add_option('--loadvm',
70
                     help = 'select saved vm-image',
59
                     help = 'select saved vm-image',
71
                     dest = 'saved_image',
60
                     dest = 'saved_image',
Lines 100-144 Link Here
100
if len(args) > 1:
89
if len(args) > 1:
101
    options.cdrom = args[1]
90
    options.cdrom = args[1]
102
91
103
def remove_module(module):
92
commands.getstatusoutput('/sbin/udevsettle')
104
    module = module.replace('-', '_')
93
if not os.access('/dev/kvm', os.F_OK):
105
    lines = commands.getoutput('/sbin/lsmod').split('\n')
94
    print '/dev/kvm not present'
106
    for x in lines:
107
        if x.startswith(module + ' '):
108
            if os.spawnl(os.P_WAIT, '/sbin/rmmod', 'rmmod', module) != 0:
109
                raise Exception('failed to remove %s module' % (module,))
110
111
def insert_module(module):
112
    if os.spawnl(os.P_WAIT, '/sbin/insmod', 'insmod',
113
                 'kernel/%s.ko' % (module,)) != 0:
114
        if os.spawnl(os.P_WAIT, '/sbin/modprobe', 'modprobe', module) != 0:
115
            raise Exception('failed to load kvm module')
116
117
def vendor():
118
    for x in file('/proc/cpuinfo').readlines():
119
        m = re.match(r'vendor_id[ \t]*: *([a-zA-Z]+),*', x)
120
        if m:
121
            return m.group(1)
122
    return unknown
123
124
vendor_module = {
125
    'GenuineIntel': 'kvm-intel',
126
    'AuthenticAMD': 'kvm-amd',
127
    }[vendor()]
128
129
if options.kvm and options.reload:
130
    for module in [vendor_module, 'kvm']:
131
        remove_module(module)
132
    for module in ['kvm', vendor_module]:
133
        insert_module(module)
134
    commands.getstatusoutput('/sbin/udevsettle')
135
    if not os.access('/dev/kvm', os.F_OK):
136
        print '/dev/kvm not present'
137
95
138
disk = options.image
96
disk = options.image
139
if options.install:
97
if options.install:
140
    (status, output) = commands.getstatusoutput(
98
    (status, output) = commands.getstatusoutput(
141
        'qemu/qemu-img create -f qcow2 "%s" 10G' % disk)
99
        'qemu-img create -f qcow2 "%s" 10G' % disk)
142
    if status:
100
    if status:
143
        raise Exception, output
101
        raise Exception, output
144
102
Lines 157-168 Link Here
157
else:
115
else:
158
    cmd = 'qemu'
116
    cmd = 'qemu'
159
117
160
local_cmd = 'qemu/' + arch + '-softmmu/' + cmd
161
if os.access(local_cmd, os.F_OK):
162
    cmd = local_cmd
163
else:
164
    cmd = '/usr/bin/kvm'
165
166
qemu_args = (cmd, '-boot', bootdisk,
118
qemu_args = (cmd, '-boot', bootdisk,
167
             '-hda', disk, '-m', str(options.memory),
119
             '-hda', disk, '-m', str(options.memory),
168
             '-serial', 'file:/tmp/serial.log',
120
             '-serial', 'file:/tmp/serial.log',
Lines 172-180 Link Here
172
if options.cdrom:
124
if options.cdrom:
173
    qemu_args += ('-cdrom', options.cdrom,)
125
    qemu_args += ('-cdrom', options.cdrom,)
174
126
175
if not options.kvm:
176
    qemu_args += ('-no-kvm',)
177
178
if options.debugger:
127
if options.debugger:
179
    qemu_args += ('-s',)
128
    qemu_args += ('-s',)
180
129

Return to bug 157987