diff options
author | Alon Levy <alevy@redhat.com> | 2011-09-21 18:56:09 +0300 |
---|---|---|
committer | Alon Levy <alevy@redhat.com> | 2011-09-21 18:56:09 +0300 |
commit | 5728db969192fb634dde10d1d489e54f463b2a54 (patch) | |
tree | 86f8224683ac417ce9e83cbe9683dda138418a87 | |
parent | fde6477c003c0d89f52d0eacf0ddc297d336e9af (diff) |
jumbo. several additional command line parameters, some cleanup
--snapshot moved
--bios and check for bios existance if supplied
--kdvirtserial, --kd, --kdlisten, --kdflags
--ehci
added but implemented in later patch:
--print-events
--reset-on-shutdown
-rwxr-xr-x | spice2 | 157 |
1 files changed, 123 insertions, 34 deletions
@@ -474,12 +474,12 @@ def build_qemu_cmdline_and_env(args): "-L", bios_dir, "-m", str(args.memory), "-cpu", str(args.cpu)] + build_spice_option(args) - if args.snapshot: - cmdline.append("-snapshot") if args.qmp_port: cmdline.extend(["-chardev", "socket,id=qmpmon,host=localhost,port=%s,server" % args.qmp_port, "-mon", "chardev=qmpmon,mode=control"]) + if args.snapshot: + cmdline.append("-snapshot") if args.no_shutdown: cmdline.append('-no-shutdown') if args.cpus > 1: @@ -516,9 +516,27 @@ def build_qemu_cmdline_and_env(args): cmdline.extend(['-global', 'qxl-vga.revision=%d' % args.revision]) if args.tablet: cmdline.extend(['-usb', '-device', 'usb-tablet']) + need_virtio_serial = args.vdagent or args.kdvirtserial + if need_virtio_serial: + cmdline.extend(['-device', 'virtio-serial,multifunction=on']) if args.vdagent: - cmdline.extend(['-device', 'virtio-serial', '-chardev', 'spicevmc,name=vdagent,id=vdagent', + cmdline.extend(['-chardev', 'spicevmc,name=vdagent,id=vdagent', '-device', 'virtserialport,chardev=vdagent,name=com.redhat.spice.0']) + if False and args.kdvirtserial: + cmdline.extend(['-chardev', 'socket,host=localhost,port=12000,id=kd', + '-device', 'virtserialport,chardev=kd,name=qemu.kd']) + if args.ehci: + cmdline.extend(['-readconfig', '/home/alon/src/spice_rhel6/qemu-kvm-rhel6/docs/ich9-ehci-uhci.cfg']) + if args.kd or args.kdlisten: + # TODO - connect to a kd running on host (wine) or on vm2 (like + # --windbg-server and --windbg-client) + socket_param = 'socket,id=kd,host=localhost,port=%s' % ( + args.kd or args.kdlisten) + if args.kdlisten: + socket_param += ',server' + cmdline.extend(['-chardev', socket_param, + '-device', 'kd,chardev=kd%s' % ( + ','+args.kdflags if args.kdflags else '')]) # user networking if args.smb: cmdline.extend(['-net', 'user,smb=%s,smbserver=10.0.2.2' % args.smb]) @@ -542,8 +560,12 @@ def build_qemu_cmdline_and_env(args): print "error calling brctl" sys.exit(1) cmdline.extend(['-netdev', 'tap,id=hostnet0,ifname=%s,script=no,downscript=no' % args.tun]) - cmdline.extend(["-device", "%s,netdev=hostnet0,id=net0%s" % (args.network_device, - (',mac=%s' % args.mac) if args.mac else '')]) + # TODO: --network-device == 'none' conflicts with bridge, but we don't check for that. + if args.network_device == 'none': + cmdline.extend(['-net', 'none']) + else: + cmdline.extend(["-device", "%s,netdev=hostnet0,id=net0%s" % (args.network_device, + (',mac=%s' % args.mac) if args.mac else '')]) #cmdline.extend(["-net", "nic,model=virtio,macaddr=%s" % args.mac]) # windbg (TODO - better then serial) if args.windbg_server: @@ -592,6 +614,11 @@ def build_qemu_cmdline_and_env(args): sys.exit(1) cmdline.extend(['-cdrom', args.cdrom]) + if args.bios: + if not os.path.exists(args.bios): + print "supplied bios %r does not exist" % args.bios + sys.exit(1) + cmdline.extend(['-bios', args.bios]) ###### print_qemu_and_spice_versions(qemu_exec=qemu_exec, @@ -608,7 +635,13 @@ def build_qemu_cmdline_and_env(args): else: print "missing both cgdb and gdb" sys.exit(1) - cmdline = [cgdb, '--args'] + cmdline + cmds_args = [] + if args.gdbcmds: + cmds_file_name = '/tmp/gdbcmds' + with open(cmds_file_name, 'w+') as fd: + fd.writelines([(x + '\n') for x in args.gdbcmds]) + cmds_args = ['-x', cmds_file_name] + cmdline = [cgdb, '--'] + cmds_args+ ['--args'] + cmdline if args.memcheck: print "wrapping with valgrind memcheck" cmdline = ['valgrind', '--error-limit=no', '--leak-check=full', '--suppressions=%s/bin/kvm.supp' % HOME, @@ -756,6 +789,7 @@ def parseargs(): qemu_group.add_argument('--root', default=root, choices=roots.keys() + [None]) qemu_group.add_argument('--root-dir', default=os.path.join(HOME, 'spice')) qemu_group.add_argument('--bios-dir', default=None) + qemu_group.add_argument('--bios', default=None) disk_group.add_argument('--image', default=image) disk_group.add_argument('--snapshot', action='store_true', default=True) disk_group.add_argument('--no-snapshot', dest='snapshot', action='store_false') @@ -782,8 +816,10 @@ def parseargs(): client_group.add_argument('--host-subject') client_group.add_argument('--sasl', action='store_true', default=False) client_group.add_argument('--vncport', dest='vnc_port', type=int) - client_group.add_argument('--vncclients', dest='vnc_clients', type=int, default=1) - devices_group.add_argument('--vga', choices=['qxl', 'cirrus'], default='qxl') + client_group.add_argument('--vncclients', dest='vnc_clients', + type=int, default=1) + devices_group.add_argument('--vga', choices=['qxl', 'cirrus'], + default='qxl') devices_group.add_argument('--qxl', type=int, default=1) devices_group.add_argument('--qxl-ram', type=int) devices_group.add_argument('--qxl-vram', type=int) @@ -792,55 +828,91 @@ def parseargs(): devices_group.add_argument('--image-compression', choices=['off', 'auto', 'on']) devices_group.add_argument('--tablet', action='store_true', default=False) - devices_group.add_argument('--vdagent', dest='vdagent', action='store_true', default=False) + devices_group.add_argument('--vdagent', dest='vdagent', + action='store_true', default=False) devices_group.add_argument('--no-vdagent', dest='vdagent', action='store_false') + devices_group.add_argument('--kdvirtserial', action='store_true', + default=False) + devices_group.add_argument('--kd', type=int, + help='add virtual kernel debugger') + devices_group.add_argument('--kdlisten', type=int, + help='add virtual kernel debugger in listen') + devices_group.add_argument('--kdflags') devices_group.add_argument('--no-tablet', action='store_false') devices_group.add_argument('--guestdebug', type=int, default=0) devices_group.add_argument('--qxldebug', type=int, default=0) devices_group.add_argument('--cmdlog', type=int, default=0) devices_group.add_argument('--memory', type=int, default=512) devices_group.add_argument('--cpus', type=int, default=2) - devices_group.add_argument('--smartcard', choices=['off','hw','sw'], default='off') + devices_group.add_argument('--smartcard', choices=['off','hw','sw'], + default='off') devices_group.add_argument('--smartcard-dbdir', dest='dbdir') - devices_group.add_argument('--smartcard-certs', dest='certs', action='append') - devices_group.add_argument('--debugbios', action='store_true', default=False) - devices_group.add_argument('--network-device', choices=['virtio-net-pci', 'rtl8139'], default='virtio-net-pci') - devices_group.add_argument('--sound', choices=['intel-hda', 'ac97', None], default=None) + devices_group.add_argument('--smartcard-certs', dest='certs', + action='append') + devices_group.add_argument('--debugbios', action='store_true', + default=False) + devices_group.add_argument('--network-device', + choices=['virtio-net-pci', 'rtl8139','none'], + default='virtio-net-pci') + devices_group.add_argument('--sound', choices=['intel-hda', 'ac97', None], + default=None) network_group.add_argument('--smb', default=None) - network_group.add_argument('--network', choices=['user', 'bridge', None], default='user') + network_group.add_argument('--network', choices=['user', 'bridge', None], + default='user') network_group.add_argument('--mac') network_group.add_argument('--bridge', default='virbr0') network_group.add_argument('--tun', default='tap0') devices_group.add_argument('--revision', default=None, type=int) - devices_group.add_argument('--cpu', choices=['host'], default='host', help='qemu cpu flag') - devices_group.add_argument('--multifunction', action='store_true', default=False, help='libvirt uses multifunction exclusively') - misc_group.add_argument('--shutdown', dest='no_shutdown', action='store_false', default=True) + devices_group.add_argument('--cpu', choices=['host'], default='host', + help='qemu cpu flag') + devices_group.add_argument('--multifunction', action='store_true', + default=False, + help='libvirt uses multifunction exclusively') + devices_group.add_argument('--ehci', action='store_true', default=False) + misc_group.add_argument('--shutdown', dest='no_shutdown', + action='store_false', default=True) misc_group.add_argument('--time', action='store_true', default=False) misc_group.add_argument('--cgdb', default=False, action='store_true') + misc_group.add_argument('--gdbcmd', dest='gdbcmds', type=str, + action='append') misc_group.add_argument('--windbg-server', type=int, default=None) misc_group.add_argument('--windbg-client', type=int, default=None) misc_group.add_argument('--incoming', type=int, default=None) misc_group.add_argument('--title', default=None) misc_group.add_argument('--freeze', default=False, action='store_true') - misc_group.add_argument('--uid', type=int, default=int(os.environ.get('SUDO_UID', os.getuid()))) - misc_group.add_argument('--gid', type=int, default=int(os.environ.get('SUDO_GID', os.getgid()))) - misc_group.add_argument('--showcmdline', default=False, action='store_true') + misc_group.add_argument('--uid', type=int, default= + int(os.environ.get('SUDO_UID', os.getuid()))) + misc_group.add_argument('--gid', type=int, default= + int(os.environ.get('SUDO_GID', os.getgid()))) + misc_group.add_argument('--print-commandline-only', default=False, + action='store_true') misc_group.add_argument('--memcheck', default=False, action='store_true') - misc_group.add_argument('--qmp-port', type=int, default=0) tests_group.add_argument('--wintest', choices=win_tests.keys()) tests_group.add_argument('--record-cmd', help='record qxl command ring') tests_group.add_argument('--xephyr', action='store_true', default=False) - tests_group.add_argument('--xdm', '--xephyr-dbg-mode', dest='xephyr', action='store_const', const='debug') + tests_group.add_argument('--xdm', '--xephyr-dbg-mode', dest='xephyr', + action='store_const', const='debug') tests_group.add_argument('--spicedump', default=False, action='store_true') tests_group.add_argument('--spicedump-filter') tests_group.add_argument('--bandwidthmon', action='store_true') # convenient to run tests via the same framework, though this is not using # any of of the qemu flags, just the client running parts. tests_group.add_argument('--test-prog', dest='test_prog', - choices=test_progs.keys()) + choices=test_progs.keys()) tests_group.add_argument('--test-func', dest='test_func', choices=tests) tests_group.add_argument('--replay-file', dest='replay_file') - args = parser.parse_args(default_args + sys.argv[1:]) + tests_group.add_argument('--print-events', action='store_true', default=False) + tests_group.add_argument('--reset-on-shutdown', action='store_true', default=False) + tests_group.add_argument('--qmp-port', type=int, default=default_qmp_port) + # extract extra parameters, those after "--", from default_args + # the same is done for sys.argv[1:] by parse_known_args + default_rest = [] + if '--' in default_args: + i = default_args.index('--') + default_rest = default_args[i + 1:] + del default_args[i:] + args, rest = parser.parse_known_args(default_args + sys.argv[1:]) + rest = default_rest + rest if args.image in images.keys(): args.image = images[args.image] if len(parts) == 1 and not args.test_prog and not args.image: @@ -856,7 +928,11 @@ def parseargs(): # tls arguments if args.x509_dir: args.ca_cert = os.path.join(args.x509_dir, 'ca-cert.pem') - return args + # qmp arguments validation + if not args.qmp_port and any([args.reset_on_shutdown, args.print_events]): + print "error: cannot disable qmp-port and use --reset-on-shutdown or --print-events" + sys.exit(1) + return args, rest def set_runonce_registry(g, root, runonce_paths): print "setting RunOnce to %r" % runonce_paths @@ -977,6 +1053,10 @@ def start_process(args, kill=False, show_output=True, **kw): processes.append(p) return p +def cleanup_file(filename): + temp_files.append(filename) + return filename + def cleanup(): for p in processes: print "killing pid %s" % p.pid @@ -1022,10 +1102,22 @@ def xephyr_get_display(): yield i i += 1 +def block_until_file_exists(filename): + while not os.path.exists(filename): + time.sleep(1) + def main(): - args = parseargs() + args, rest = parseargs() + # remove first instance of '--' from rest + if '--' in rest: + del rest[rest.index('--')] update_certs(args) - cmdline, env = build_qemu_cmdline_and_env(args) + args_cmdline, env = build_qemu_cmdline_and_env(args) + cmdline = args_cmdline + rest + if args.print_commandline_only: + print repr(cmdline) + print ' '.join(cmdline) + return for k, v in env: print "setting environment variable %s = %r" % (k, v) os.environ[k] = v @@ -1054,9 +1146,6 @@ def main(): 'I ' if args.incoming else '', args.title if args.title else os.path.basename(sys.argv[0]) )) - if args.showcmdline: - print repr(cmdline) - return ignore_ctrlc() exit_on_hup() # At this point drop privileges before executing any process. Networking and @@ -1080,6 +1169,9 @@ def main(): ' -f %s' % args.spicedump_filter if args.spicedump_filter else '' )).split()) if args.bandwidthmon: + if not bandwidthmon_exe or not os.path.exists(bandwidthmon_exe): + print "missing bandwidthmon_exe (%r)" % bandwidthmon_exe + sys.exit(1) print "running bandwidthmon" real_spice_port = args.spice_port args.spice_port = proxy_port = real_spice_port + 1000 @@ -1092,9 +1184,6 @@ def main(): proxy_args.extend(['--listen-port', str(proxy_port), '--remote-port', str(real_vnc_port)]) start_process(args=proxy_args) - if args.qmp_port: - #start_process( - print "TODO" if args.test_func: test_func = globals()['test_'+args.test_func] test_func(server=test_process, args=args) |