direct-io.hg

changeset 1693:62169ad13597

bitkeeper revision 1.1041.1.15 (40eaf4876ULxkQbaOYOreUHaxX6Xhw)

Merge ssh://xenbk@gandalf//var/bk/djm/xeno-unstable-common.bk
into kirby.fc.hp.com:/home/djm/src/xen/xeno-unstable-common.bk
author djm@kirby.fc.hp.com
date Tue Jul 06 18:50:47 2004 +0000 (2004-07-06)
parents ce83dd94e73c 1aadd0200ecb
children b89292506038
files linux-2.4.26-xen-sparse/arch/xen/kernel/setup.c tools/python/xen/util/ip.py tools/python/xen/xm/create.py tools/python/xen/xm/opts.py
line diff
     1.1 --- a/linux-2.4.26-xen-sparse/arch/xen/kernel/setup.c	Tue Jul 06 18:49:28 2004 +0000
     1.2 +++ b/linux-2.4.26-xen-sparse/arch/xen/kernel/setup.c	Tue Jul 06 18:50:47 2004 +0000
     1.3 @@ -8,6 +8,8 @@
     1.4   * This file handles the architecture-dependent parts of initialization
     1.5   */
     1.6  
     1.7 +#define __KERNEL_SYSCALLS__
     1.8 +static int errno;
     1.9  #include <linux/errno.h>
    1.10  #include <linux/sched.h>
    1.11  #include <linux/kernel.h>
    1.12 @@ -30,6 +32,7 @@
    1.13  #include <linux/highmem.h>
    1.14  #include <linux/bootmem.h>
    1.15  #include <linux/seq_file.h>
    1.16 +#include <linux/reboot.h>
    1.17  #include <asm/processor.h>
    1.18  #include <linux/console.h>
    1.19  #include <linux/module.h>
    1.20 @@ -1148,10 +1151,10 @@ void __init cpu_init (void)
    1.21  
    1.22  #include <asm/suspend.h>
    1.23  
    1.24 -/* Treat multiple suspend requests as a single one. */
    1.25 -static int suspending;
    1.26 +/* Ignore multiple shutdown requests. */
    1.27 +static int shutting_down = -1;
    1.28  
    1.29 -static void suspend_task(void *unused)
    1.30 +static void __do_suspend(void)
    1.31  {
    1.32      /* Hmmm... a cleaner interface to suspend/resume blkdevs would be nice. */
    1.33      extern void blkdev_suspend(void);
    1.34 @@ -1220,7 +1223,7 @@ static void suspend_task(void *unused)
    1.35  
    1.36      HYPERVISOR_suspend(virt_to_machine(suspend_record) >> PAGE_SHIFT);
    1.37  
    1.38 -    suspending = 0; 
    1.39 +    shutting_down = -1; 
    1.40  
    1.41      memcpy(&start_info, &suspend_record->resume_info, sizeof(start_info));
    1.42  
    1.43 @@ -1272,25 +1275,78 @@ static void suspend_task(void *unused)
    1.44          free_page((unsigned long)suspend_record);
    1.45  }
    1.46  
    1.47 -static struct tq_struct suspend_tq;
    1.48 +static int shutdown_process(void *__unused)
    1.49 +{
    1.50 +    static char *envp[] = { "HOME=/", "TERM=linux", 
    1.51 +                            "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
    1.52 +    static char *restart_argv[]  = { "/sbin/shutdown", "-r", "now", NULL };
    1.53 +    static char *poweroff_argv[] = { "/sbin/halt",     "-p",        NULL };
    1.54 +
    1.55 +    extern asmlinkage long sys_reboot(int magic1, int magic2,
    1.56 +                                      unsigned int cmd, void *arg);
    1.57 +
    1.58 +    daemonize();
    1.59 +
    1.60 +    switch ( shutting_down )
    1.61 +    {
    1.62 +    case CMSG_SHUTDOWN_POWEROFF:
    1.63 +        if ( execve("/sbin/halt", poweroff_argv, envp) < 0 )
    1.64 +        {
    1.65 +            sys_reboot(LINUX_REBOOT_MAGIC1,
    1.66 +                       LINUX_REBOOT_MAGIC2,
    1.67 +                       LINUX_REBOOT_CMD_POWER_OFF,
    1.68 +                       NULL);
    1.69 +        }
    1.70 +        break;
    1.71 +
    1.72 +    case CMSG_SHUTDOWN_REBOOT:
    1.73 +        if ( execve("/sbin/shutdown", restart_argv, envp) < 0 )
    1.74 +        {
    1.75 +            sys_reboot(LINUX_REBOOT_MAGIC1,
    1.76 +                       LINUX_REBOOT_MAGIC2,
    1.77 +                       LINUX_REBOOT_CMD_RESTART,
    1.78 +                       NULL);
    1.79 +        }
    1.80 +        break;
    1.81 +    }
    1.82 +
    1.83 +    return 0;
    1.84 +}
    1.85 +
    1.86 +static void __shutdown_handler(void *unused)
    1.87 +{
    1.88 +    int err;
    1.89 +
    1.90 +    if ( shutting_down != CMSG_SHUTDOWN_SUSPEND )
    1.91 +    {
    1.92 +        err = kernel_thread(shutdown_process, NULL, CLONE_FS | CLONE_FILES);
    1.93 +        if ( err < 0 )
    1.94 +            printk(KERN_ALERT "Error creating shutdown process!\n");
    1.95 +        else
    1.96 +            shutting_down = -1; /* could try again */
    1.97 +    }
    1.98 +    else
    1.99 +    {
   1.100 +        __do_suspend();
   1.101 +    }
   1.102 +}
   1.103  
   1.104  static void shutdown_handler(ctrl_msg_t *msg, unsigned long id)
   1.105  {
   1.106 -    if ( msg->subtype != CMSG_SHUTDOWN_SUSPEND )
   1.107 +    static struct tq_struct shutdown_tq;
   1.108 +
   1.109 +    if ( (shutting_down == -1) &&
   1.110 +         ((msg->subtype == CMSG_SHUTDOWN_POWEROFF) ||
   1.111 +          (msg->subtype == CMSG_SHUTDOWN_REBOOT) ||
   1.112 +          (msg->subtype == CMSG_SHUTDOWN_SUSPEND)) )
   1.113      {
   1.114 -        extern void ctrl_alt_del(void);
   1.115 -        ctrl_if_send_response(msg);
   1.116 -        ctrl_alt_del();
   1.117 -    }
   1.118 -    else if ( !suspending )
   1.119 -    {
   1.120 -	suspending = 1;
   1.121 -	suspend_tq.routine = suspend_task;
   1.122 -	schedule_task(&suspend_tq);	
   1.123 +        shutting_down = msg->subtype;
   1.124 +        shutdown_tq.routine = __shutdown_handler;
   1.125 +        schedule_task(&shutdown_tq);
   1.126      }
   1.127      else
   1.128      {
   1.129 -	printk(KERN_ALERT"Ignore queued suspend request\n");
   1.130 +	printk("Ignore spurious shutdown request\n");
   1.131      }
   1.132  
   1.133      ctrl_if_send_response(msg);
     2.1 --- a/tools/python/xen/util/ip.py	Tue Jul 06 18:49:28 2004 +0000
     2.2 +++ b/tools/python/xen/util/ip.py	Tue Jul 06 18:50:47 2004 +0000
     2.3 @@ -3,7 +3,7 @@ import re
     2.4  import socket
     2.5  import struct
     2.6  
     2.7 -def readlines(fd):
     2.8 +def _readlines(fd):
     2.9      """Version of readlines safe against EINTR.
    2.10      """
    2.11      import errno
    2.12 @@ -21,7 +21,7 @@ def readlines(fd):
    2.13          lines.append(line)
    2.14      return lines
    2.15  
    2.16 -def readline(fd):
    2.17 +def _readline(fd):
    2.18      """Version of readline safe against EINTR.
    2.19      """
    2.20      while 1:
    2.21 @@ -42,11 +42,14 @@ as it may have been moved onto the bridg
    2.22  NBE_BRIDGE = 'nbe-br'
    2.23  
    2.24  def get_current_ipaddr(dev='eth0'):
    2.25 -    """Return a string containing the primary IP address for the given
    2.26 -    network interface (default 'eth0').
    2.27 +    """Get the primary IP address for the given network interface.
    2.28 +
    2.29 +    dev     network interface (default eth0)
    2.30 +
    2.31 +    returns interface address as a string
    2.32      """
    2.33      fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
    2.34 -    lines = readlines(fd)
    2.35 +    lines = _readlines(fd)
    2.36      for line in lines:
    2.37          m = re.search( '^\s+inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
    2.38                         line )
    2.39 @@ -57,11 +60,14 @@ def get_current_ipaddr(dev='eth0'):
    2.40      return None
    2.41  
    2.42  def get_current_ipmask(dev='eth0'):
    2.43 -    """Return a string containing the primary IP netmask for the given
    2.44 -    network interface (default 'eth0').
    2.45 +    """Get the primary IP netmask for a network interface.
    2.46 +
    2.47 +    dev     network interface (default eth0)
    2.48 +
    2.49 +    returns interface netmask as a string
    2.50      """
    2.51      fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
    2.52 -    lines = readlines(fd)
    2.53 +    lines = _readlines(fd)
    2.54      for line in lines:
    2.55          m = re.search( '^.+Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
    2.56                         line )
    2.57 @@ -72,11 +78,14 @@ def get_current_ipmask(dev='eth0'):
    2.58      return None
    2.59  
    2.60  def get_current_ipgw(dev='eth0'):
    2.61 -    """Return a string containing the IP gateway for the given
    2.62 -    network interface (default 'eth0').
    2.63 +    """Get the IP gateway for a network interface.
    2.64 +
    2.65 +    dev     network interface (default eth0)
    2.66 +
    2.67 +    returns gateway address as a string
    2.68      """
    2.69      fd = os.popen( '/sbin/route -n' )
    2.70 -    lines = readlines(fd)
    2.71 +    lines = _readlines(fd)
    2.72      for line in lines:
    2.73          m = re.search( '^\S+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' +
    2.74                         '\s+\S+\s+\S*G.*' + dev + '.*', line )
    2.75 @@ -88,24 +97,46 @@ def get_current_ipgw(dev='eth0'):
    2.76  
    2.77  def inet_aton(addr):
    2.78      """Convert an IP addr in IPv4 dot notation into an int.
    2.79 +
    2.80 +    addr    IP address as a string
    2.81 +
    2.82 +    returns integer
    2.83      """
    2.84      b = socket.inet_aton(addr)
    2.85      return struct.unpack('!I', b)[0]
    2.86  
    2.87  def inet_ntoa(n):
    2.88      """Convert an int into an IP addr in IPv4 dot notation.
    2.89 +
    2.90 +    n       IP address
    2.91 +
    2.92 +    returns string
    2.93      """
    2.94      b = struct.pack('!I', n)
    2.95      return socket.inet_ntoa(b)
    2.96  
    2.97  def add_offset_to_ip(addr, offset):
    2.98      """Add a numerical offset to an IP addr in IPv4 dot notation.
    2.99 +
   2.100 +    addr    IP address
   2.101 +    offset  offset to add
   2.102 +
   2.103 +    returns new address
   2.104      """
   2.105      n = inet_aton(addr)
   2.106      n += offset
   2.107      return inet_ntoa(n)
   2.108  
   2.109  def check_subnet( ip, network, netmask ):
   2.110 +    """Check if an IP address is in the subnet defined by
   2.111 +    a network address and mask'.
   2.112 +
   2.113 +    ip      IP adress
   2.114 +    network network address
   2.115 +    netmask network mask
   2.116 +    
   2.117 +    returns 1 if it is in the subnet, 0 if not
   2.118 +    """
   2.119      n_ip = inet_aton(ip)
   2.120      n_net = inet_aton(network)
   2.121      n_mask = inet_aton(netmask)
     3.1 --- a/tools/python/xen/xm/create.py	Tue Jul 06 18:49:28 2004 +0000
     3.2 +++ b/tools/python/xen/xm/create.py	Tue Jul 06 18:50:47 2004 +0000
     3.3 @@ -13,7 +13,7 @@ from xen.util import console_client
     3.4  
     3.5  from xen.xm.opts import *
     3.6  
     3.7 -gopts = Opts(use="""[options]
     3.8 +gopts = Opts(use="""[options] [vars]
     3.9  
    3.10  Create a domain.
    3.11  
    3.12 @@ -66,54 +66,49 @@ gopts.opt('load', short='L', val='FILE',
    3.13            fn=set_value, default=None,
    3.14            use='Domain saved state to load.')
    3.15  
    3.16 -#gopts.opt('define', short='D', val='VAR=VAL',
    3.17 -#         fn=set_var, default=None,
    3.18 -#         use="""Set a variable before loading defaults, e.g. '-D vmid=3'
    3.19 -#         to set vmid. May be repeated to set more than one variable.""")
    3.20 -
    3.21  gopts.opt('dryrun', short='n',
    3.22           fn=set_true, default=0,
    3.23           use="""Dry run - print the config but don't create the domain.
    3.24  The defaults file is loaded and the SXP configuration is created and printed.         
    3.25  """)
    3.26  
    3.27 -gopts.opt('name', short='N', val='NAME',
    3.28 -          fn=set_value, default=None,
    3.29 -          use="Domain name.")
    3.30 -
    3.31  gopts.opt('console_autoconnect', short='c',
    3.32           fn=set_true, default=0,
    3.33           use="Connect to console after domain is created.")
    3.34  
    3.35 -gopts.opt('kernel', short='k', val='FILE',
    3.36 +gopts.var('name', val='NAME',
    3.37 +          fn=set_value, default=None,
    3.38 +          use="Domain name.")
    3.39 +
    3.40 +gopts.var('kernel', val='FILE',
    3.41           fn=set_value, default=None,
    3.42           use="Path to kernel image.")
    3.43  
    3.44 -gopts.opt('ramdisk', short='r', val='FILE',
    3.45 +gopts.var('ramdisk', val='FILE',
    3.46           fn=set_value, default='',
    3.47           use="Path to ramdisk.")
    3.48  
    3.49 -gopts.opt('builder', short='b', val='FUNCTION',
    3.50 +gopts.var('builder', val='FUNCTION',
    3.51           fn=set_value, default='linux',
    3.52           use="Function to use to build the domain.")
    3.53  
    3.54 -gopts.opt('memory', short='m', val='MEMORY',
    3.55 +gopts.var('memory', val='MEMORY',
    3.56           fn=set_value, default=128,
    3.57           use="Domain memory in MB.")
    3.58  
    3.59 -gopts.opt('autorestart',
    3.60 -         fn=set_true, default=0,
    3.61 +gopts.var('autorestart', val='no|yes',
    3.62 +         fn=set_bool, default=0,
    3.63           use="Whether to restart the domain on exit.")
    3.64  
    3.65 -gopts.opt('blkif',
    3.66 -          fn=set_true, default=0,
    3.67 +gopts.var('blkif', val='no|yes',
    3.68 +          fn=set_bool, default=0,
    3.69            use="Make the domain a block device backend.")
    3.70  
    3.71 -gopts.opt('netif',
    3.72 -          fn=set_true, default=0,
    3.73 +gopts.var('netif', val='no|yes',
    3.74 +          fn=set_bool, default=0,
    3.75            use="Make the domain a network interface backend.")
    3.76  
    3.77 -gopts.opt('disk', short='d', val='phy:DEV,VDEV,MODE',
    3.78 +gopts.var('disk', val='phy:DEV,VDEV,MODE',
    3.79           fn=append_value, default=[],
    3.80           use="""Add a disk device to a domain. The physical device is DEV,
    3.81           which is exported to the domain as VDEV. The disk is read-only if MODE
    3.82 @@ -121,18 +116,18 @@ gopts.opt('disk', short='d', val='phy:DE
    3.83           The option may be repeated to add more than one disk.
    3.84           """)
    3.85  
    3.86 -gopts.opt('pci', val='BUS,DEV,FUNC',
    3.87 +gopts.var('pci', val='BUS,DEV,FUNC',
    3.88           fn=append_value, default=[],
    3.89           use="""Add a PCI device to a domain, using given params (in hex).
    3.90           For example '-pci c0,02,1a'.
    3.91           The option may be repeated to add more than one pci device.
    3.92           """)
    3.93  
    3.94 -gopts.opt('ipaddr', short='i', val="IPADDR",
    3.95 +gopts.var('ipaddr', val="IPADDR",
    3.96           fn=append_value, default=[],
    3.97           use="Add an IP address to the domain.")
    3.98  
    3.99 -gopts.opt('vif', val="mac=MAC,bridge=BRIDGE",
   3.100 +gopts.var('vif', val="mac=MAC,bridge=BRIDGE",
   3.101           fn=append_value, default=[],
   3.102           use="""Add a network interface with the given MAC address and bridge.
   3.103           If mac is not specified a random MAC address is used.
   3.104 @@ -141,7 +136,7 @@ gopts.opt('vif', val="mac=MAC,bridge=BRI
   3.105           Specifying vifs will increase the number of interfaces as needed.
   3.106           """)
   3.107  
   3.108 -gopts.opt('nics', val="NUM",
   3.109 +gopts.var('nics', val="NUM",
   3.110           fn=set_int, default=1,
   3.111           use="""Set the number of network interfaces.
   3.112           Use the vif option to define interface parameters, otherwise
   3.113 @@ -149,44 +144,44 @@ gopts.opt('nics', val="NUM",
   3.114           number of interfaces as needed.
   3.115           """)
   3.116  
   3.117 -gopts.opt('root', short='R', val='DEVICE',
   3.118 +gopts.var('root', val='DEVICE',
   3.119           fn=set_value, default='',
   3.120           use="""Set the root= parameter on the kernel command line.
   3.121           Use a device, e.g. /dev/sda1, or /dev/nfs for NFS root.""")
   3.122  
   3.123 -gopts.opt('extra', short='E', val="ARGS",
   3.124 +gopts.var('extra', val="ARGS",
   3.125           fn=set_value, default='',
   3.126           use="Set extra arguments to append to the kernel command line.")
   3.127  
   3.128 -gopts.opt('ip', short='I', val='IPADDR',
   3.129 +gopts.var('ip', val='IPADDR',
   3.130           fn=set_value, default='',
   3.131           use="Set the kernel IP interface address.")
   3.132  
   3.133 -gopts.opt('gateway', val="IPADDR",
   3.134 +gopts.var('gateway', val="IPADDR",
   3.135           fn=set_value, default='',
   3.136           use="Set the kernel IP gateway.")
   3.137  
   3.138 -gopts.opt('netmask', val="MASK",
   3.139 +gopts.var('netmask', val="MASK",
   3.140           fn=set_value, default = '',
   3.141           use="Set the kernel IP netmask.")
   3.142  
   3.143 -gopts.opt('hostname', val="NAME",
   3.144 +gopts.var('hostname', val="NAME",
   3.145           fn=set_value, default='',
   3.146           use="Set the kernel IP hostname.")
   3.147  
   3.148 -gopts.opt('interface', val="INTF",
   3.149 +gopts.var('interface', val="INTF",
   3.150           fn=set_value, default="eth0",
   3.151           use="Set the kernel IP interface name.")
   3.152  
   3.153 -gopts.opt('dhcp', val="off|dhcp",
   3.154 +gopts.var('dhcp', val="off|dhcp",
   3.155           fn=set_value, default='off',
   3.156           use="Set the kernel dhcp option.")
   3.157  
   3.158 -gopts.opt('nfs_server', val="IPADDR",
   3.159 +gopts.var('nfs_server', val="IPADDR",
   3.160           fn=set_value, default=None,
   3.161           use="Set the address of the NFS server for NFS root.")
   3.162  
   3.163 -gopts.opt('nfs_root', val="PATH",
   3.164 +gopts.var('nfs_root', val="PATH",
   3.165           fn=set_value, default=None,
   3.166           use="Set the path of the root NFS directory.")
   3.167  
   3.168 @@ -315,7 +310,7 @@ def preprocess_vifs(opts):
   3.169          d = {}
   3.170          a = vif.split(',')
   3.171          for b in a:
   3.172 -            (k, v) = b.strip().split('=')
   3.173 +            (k, v) = b.strip().split('=', 1)
   3.174              k = k.strip()
   3.175              v = v.strip()
   3.176              if k not in ['mac', 'bridge']:
   3.177 @@ -392,7 +387,7 @@ def main(argv):
   3.178      # Process remaining args as config variables.
   3.179      for arg in args:
   3.180          if '=' in arg:
   3.181 -            (var, val) = arg.strip().split('=')
   3.182 +            (var, val) = arg.strip().split('=', 1)
   3.183              gopts.setvar(var.strip(), val.strip())
   3.184      if opts.vals.config:
   3.185          pass
     4.1 --- a/tools/python/xen/xm/opts.py	Tue Jul 06 18:49:28 2004 +0000
     4.2 +++ b/tools/python/xen/xm/opts.py	Tue Jul 06 18:50:47 2004 +0000
     4.3 @@ -126,6 +126,42 @@ class Opt:
     4.4          """
     4.5          return self.specified_opt
     4.6  
     4.7 +class OptVar(Opt):
     4.8 +    """An individual option variable.
     4.9 +    """
    4.10 +    def __init__(self, opts, name,
    4.11 +                 val=None, fn=None, use=None, default=None):
    4.12 +        """Create an option.
    4.13 +
    4.14 +        opts    parent options object
    4.15 +        name    name of the field it controls
    4.16 +        val     string used to print option args in help.
    4.17 +                If val is not specified the option has no arg.
    4.18 +        fn      function to call when the option is specified.
    4.19 +        use     usage (help) string
    4.20 +        default default value if not specified on command-line
    4.21 +        """
    4.22 +        if val is None:
    4.23 +            val = name.upper()
    4.24 +        Opt.__init__(self, opts, name, val=val, fn=fn, use=use, default=default)
    4.25 +        self.optkeys = []
    4.26 +        self.optkeys.append(self.long)
    4.27 +
    4.28 +    def short_opt(self):
    4.29 +        return None
    4.30 +
    4.31 +    def long_opt(self):
    4.32 +        return None
    4.33 +
    4.34 +    def show(self):
    4.35 +        print '%s=%s' %(self.optkeys[0], self.val) 
    4.36 +        print
    4.37 +        if self.use:
    4.38 +            print '\t',
    4.39 +            print self.use
    4.40 +        if self.val:
    4.41 +            print '\tDefault', self.default or 'None'
    4.42 +
    4.43  class OptVals:
    4.44      """Class to hold option values.
    4.45      """
    4.46 @@ -134,6 +170,13 @@ class OptVals:
    4.47  class Opts:
    4.48      """Container for options.
    4.49      """
    4.50 +
    4.51 +    imports = ["import sys",
    4.52 +               "import os",
    4.53 +               "import os.path",
    4.54 +               "from xen.util.ip import *",
    4.55 +               ]
    4.56 +
    4.57      def __init__(self, use=None):
    4.58          """Options constructor.
    4.59  
    4.60 @@ -168,6 +211,12 @@ class Opts:
    4.61          self.options_map[name] = x
    4.62          return x
    4.63  
    4.64 +    def var(self, name, **args):
    4.65 +        x = OptVar(self, name, **args)
    4.66 +        self.options.append(x)
    4.67 +        self.options_map[name] = x
    4.68 +        return x     
    4.69 +
    4.70      def setvar(self, var, val):
    4.71          """Set a default script variable.
    4.72          """
    4.73 @@ -232,7 +281,18 @@ class Opts:
    4.74              else:
    4.75                  print >>sys.stderr, "Error: Unknown option:", k
    4.76                  self.usage()
    4.77 -        return args
    4.78 +        xargs = []
    4.79 +        for arg in args:
    4.80 +            isvar = 0
    4.81 +            if '=' in arg:
    4.82 +                (k, v) = arg.split('=', 1)
    4.83 +                for opt in self.options:
    4.84 +                    if opt.specify(k, v):
    4.85 +                        isvar = 1
    4.86 +                        break
    4.87 +            if not isvar:
    4.88 +                xargs.append(arg)
    4.89 +        return xargs
    4.90  
    4.91      def short_opts(self):
    4.92          """Get short options specifier for getopt.
    4.93 @@ -257,6 +317,7 @@ class Opts:
    4.94      def usage(self):
    4.95          print 'Usage: ', self.argv[0], self.use or 'OPTIONS'
    4.96          for opt in self.options:
    4.97 +            print
    4.98              opt.show()
    4.99  
   4.100      def load_defaults(self, help=0):
   4.101 @@ -287,21 +348,22 @@ class Opts:
   4.102          globals = {}
   4.103          locals = {}
   4.104          locals.update(self.vars)
   4.105 -        cmd = '\n'.join(["import sys",
   4.106 -                         "import os",
   4.107 -                         "import os.path",
   4.108 -                         "from xen.xm.help import Vars",
   4.109 -                         "from xen.util import ip",
   4.110 -                         "xm_file = '%s'" % defaults,
   4.111 -                         "xm_help = %d" % help,
   4.112 -                         "xm_vars = Vars(xm_file, xm_help, locals())",
   4.113 -                         ])
   4.114 +        cmd = '\n'.join(self.imports + 
   4.115 +                        [ "from xen.xm.help import Vars",
   4.116 +                          "xm_file = '%s'" % defaults,
   4.117 +                          "xm_help = %d" % help,
   4.118 +                          "xm_vars = Vars(xm_file, xm_help, locals())"
   4.119 +                          ])
   4.120          exec cmd in globals, locals
   4.121          try:
   4.122              execfile(defaults, globals, locals)
   4.123          except:
   4.124              if not help: raise
   4.125 -        if help: return
   4.126 +        if help:
   4.127 +            print 'The following imports are done automatically:'
   4.128 +            for x in self.imports:
   4.129 +                print x
   4.130 +            return
   4.131          # Extract the values set by the script and set the corresponding
   4.132          # options, if not set on the command line.
   4.133          vtypes = [ types.StringType,
   4.134 @@ -322,6 +384,17 @@ def set_false(opt, k, v):
   4.135      """Set an option false."""
   4.136      opt.set(0)
   4.137  
   4.138 +def set_bool(opt, k, v):
   4.139 +    """Set a boolean option.
   4.140 +    """
   4.141 +    if v in ['yes']:
   4.142 +        opt.set(1)
   4.143 +    elif v in ['no']:
   4.144 +        opt.set(0)
   4.145 +    else:
   4.146 +        opt.opts.err('Invalid value:' +v)
   4.147 +        
   4.148 +
   4.149  def set_value(opt, k, v):
   4.150      """Set an option to a valoue."""
   4.151      opt.set(v)
   4.152 @@ -341,6 +414,6 @@ def append_value(opt, k, v):
   4.153  def set_var(opt, k, v):
   4.154      """Set a default script variable.
   4.155      """
   4.156 -    (var, val) = v.strip().split('=')
   4.157 +    (var, val) = v.strip().split('=', 1)
   4.158      opt.opts.setvar(var.strip(), val.strip())
   4.159