direct-io.hg

changeset 1196:17430e51466a

bitkeeper revision 1.810 (4059c6e8EQAxVfRpkNjdygO1O6otTQ)

schedule.c, sched_bvt.c, main.py, Makefile, setup.py, Xc.c:
Python tool fixes.
tempfile.py:
new file
author kaf24@scramble.cl.cam.ac.uk
date Thu Mar 18 15:57:28 2004 +0000 (2004-03-18)
parents aaaaffbe35aa
children d0cff1fdeff3
files .rootkeys Makefile tools/xc/py/Makefile tools/xc/py/Xc.c tools/xenctl/Makefile tools/xenctl/lib/tempfile.py tools/xenctl/setup.py tools/xend/Makefile tools/xend/lib/main.py xen/common/sched_bvt.c xen/common/schedule.c
line diff
     1.1 --- a/.rootkeys	Thu Mar 18 14:48:11 2004 +0000
     1.2 +++ b/.rootkeys	Thu Mar 18 15:57:28 2004 +0000
     1.3 @@ -93,6 +93,7 @@ 3fbd0a40yT6G3M9hMpaz5xTUdl0E4g tools/xc/
     1.4  4055ee41IfFazrwadCH2J72nz-A9YA tools/xenctl/Makefile
     1.5  4055ee4b_4Rvns_KzE12csI14EKK6Q tools/xenctl/lib/__init__.py
     1.6  4055ee4dwy4l0MghZosxoiu6zmhc9Q tools/xenctl/lib/console_client.py
     1.7 +4059c6a0pnxhG8hwSOivXybbGOwuXw tools/xenctl/lib/tempfile.py
     1.8  3fbd4bd6GtGwZGxYUJPOheYIR7bPaA tools/xenctl/lib/utils.py
     1.9  4055ee44Bu6oP7U0WxxXypbUt4dNPQ tools/xenctl/setup.py
    1.10  40431ac64Hj4ixUnKmlugZKhXPFE_Q tools/xend/Makefile
     2.1 --- a/Makefile	Thu Mar 18 14:48:11 2004 +0000
     2.2 +++ b/Makefile	Thu Mar 18 15:57:28 2004 +0000
     2.3 @@ -19,8 +19,8 @@ install: all
     2.4  	$(MAKE) -C tools install
     2.5  
     2.6  dist: all
     2.7 -	$(MAKE) prefix=`pwd`/../install -C xen install
     2.8 -	$(MAKE) prefix=`pwd`/../install -C tools install
     2.9 +	$(MAKE) prefix=`pwd`/../install dist=yes -C xen install
    2.10 +	$(MAKE) prefix=`pwd`/../install dist=yes -C tools install
    2.11  
    2.12  clean:
    2.13  	$(MAKE) -C xen clean
     3.1 --- a/tools/xc/py/Makefile	Thu Mar 18 14:48:11 2004 +0000
     3.2 +++ b/tools/xc/py/Makefile	Thu Mar 18 15:57:28 2004 +0000
     3.3 @@ -3,8 +3,13 @@ all:
     3.4  	python setup.py build
     3.5  
     3.6  install: all
     3.7 -	if [ "$(prefix)" = "" ]; then python setup.py install; \
     3.8 -	else python setup.py install --root="$(prefix)"; fi
     3.9 +	if [ "$(prefix)" = "" ]; then                   \
    3.10 +	    python setup.py install;                    \
    3.11 +	elif [ "$(dist)" = "yes" ]; then                \
    3.12 +	    python setup.py install --home="$(prefix)"; \
    3.13 +	else                                            \
    3.14 +	    python setup.py install --root="$(prefix)"; \
    3.15 +	fi
    3.16  
    3.17  clean:
    3.18  	rm -rf build *.pyc *.pyo *.o *.a *~
     4.1 --- a/tools/xc/py/Xc.c	Thu Mar 18 14:48:11 2004 +0000
     4.2 +++ b/tools/xc/py/Xc.c	Thu Mar 18 15:57:28 2004 +0000
     4.3 @@ -867,7 +867,6 @@ static PyObject *pyxc_atropos_domain_set
     4.4                                           PyObject *kwds)
     4.5  {
     4.6      XcObject *xc = (XcObject *)self;
     4.7 -    PyObject *ret_obj;
     4.8      int xtratime;
     4.9      u64 domid;
    4.10  
    4.11 @@ -889,7 +888,6 @@ static PyObject *pyxc_rrobin_global_set(
    4.12                                          PyObject *kwds)
    4.13  {
    4.14      XcObject *xc = (XcObject *)self;
    4.15 -    PyObject *ret_obj;
    4.16      u64 slice;
    4.17      
    4.18      static char *kwd_list[] = { "slice", NULL };
     5.1 --- a/tools/xenctl/Makefile	Thu Mar 18 14:48:11 2004 +0000
     5.2 +++ b/tools/xenctl/Makefile	Thu Mar 18 15:57:28 2004 +0000
     5.3 @@ -3,8 +3,13 @@ all:
     5.4  	python setup.py build
     5.5  
     5.6  install: all
     5.7 -	if [ "$(prefix)" = "" ]; then python setup.py install; \
     5.8 -	else python setup.py install --root="$(prefix)"; fi
     5.9 +	if [ "$(prefix)" = "" ]; then                   \
    5.10 +	    python setup.py install;                    \
    5.11 +	elif [ "$(dist)" = "yes" ]; then                \
    5.12 +	    python setup.py install --home="$(prefix)"; \
    5.13 +	else                                            \
    5.14 +	    python setup.py install --root="$(prefix)"; \
    5.15 +	fi
    5.16  
    5.17  clean:
    5.18  	rm -rf build *.pyc *.pyo *.o *.a *~
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/xenctl/lib/tempfile.py	Thu Mar 18 15:57:28 2004 +0000
     6.3 @@ -0,0 +1,451 @@
     6.4 +"""Temporary files.
     6.5 +
     6.6 +This module provides generic, low- and high-level interfaces for
     6.7 +creating temporary files and directories.  The interfaces listed
     6.8 +as "safe" just below can be used without fear of race conditions.
     6.9 +Those listed as "unsafe" cannot, and are provided for backward
    6.10 +compatibility only.
    6.11 +
    6.12 +This module also provides some data items to the user:
    6.13 +
    6.14 +  TMP_MAX  - maximum number of names that will be tried before
    6.15 +             giving up.
    6.16 +  template - the default prefix for all temporary names.
    6.17 +             You may change this to control the default prefix.
    6.18 +  tempdir  - If this is set to a string before the first use of
    6.19 +             any routine from this module, it will be considered as
    6.20 +             another candidate location to store temporary files.
    6.21 +"""
    6.22 +
    6.23 +__all__ = [
    6.24 +    "NamedTemporaryFile", "TemporaryFile", # high level safe interfaces
    6.25 +    "mkstemp", "mkdtemp",                  # low level safe interfaces
    6.26 +    "mktemp",                              # deprecated unsafe interface
    6.27 +    "TMP_MAX", "gettempprefix",            # constants
    6.28 +    "tempdir", "gettempdir"
    6.29 +   ]
    6.30 +
    6.31 +
    6.32 +# Imports.
    6.33 +
    6.34 +import os as _os
    6.35 +import errno as _errno
    6.36 +from random import Random as _Random
    6.37 +
    6.38 +if _os.name == 'mac':
    6.39 +    import Carbon.Folder as _Folder
    6.40 +    import Carbon.Folders as _Folders
    6.41 +
    6.42 +try:
    6.43 +    import fcntl as _fcntl
    6.44 +    # If PYTHONCASEOK is set on Windows, stinking FCNTL.py gets
    6.45 +    # imported, and we don't get an ImportError then.  Provoke
    6.46 +    # an AttributeError instead in that case.
    6.47 +    _fcntl.fcntl
    6.48 +except (ImportError, AttributeError):
    6.49 +    def _set_cloexec(fd):
    6.50 +        pass
    6.51 +else:
    6.52 +    def _set_cloexec(fd):
    6.53 +        flags = _fcntl.fcntl(fd, _fcntl.F_GETFD, 0)
    6.54 +        if flags >= 0:
    6.55 +            # flags read successfully, modify
    6.56 +            flags |= _fcntl.FD_CLOEXEC
    6.57 +            _fcntl.fcntl(fd, _fcntl.F_SETFD, flags)
    6.58 +
    6.59 +
    6.60 +try:
    6.61 +    import thread as _thread
    6.62 +except ImportError:
    6.63 +    import dummy_thread as _thread
    6.64 +_allocate_lock = _thread.allocate_lock
    6.65 +
    6.66 +_text_openflags = _os.O_RDWR | _os.O_CREAT | _os.O_EXCL
    6.67 +if hasattr(_os, 'O_NOINHERIT'):
    6.68 +    _text_openflags |= _os.O_NOINHERIT
    6.69 +if hasattr(_os, 'O_NOFOLLOW'):
    6.70 +    _text_openflags |= _os.O_NOFOLLOW
    6.71 +
    6.72 +_bin_openflags = _text_openflags
    6.73 +if hasattr(_os, 'O_BINARY'):
    6.74 +    _bin_openflags |= _os.O_BINARY
    6.75 +
    6.76 +if hasattr(_os, 'TMP_MAX'):
    6.77 +    TMP_MAX = _os.TMP_MAX
    6.78 +else:
    6.79 +    TMP_MAX = 10000
    6.80 +
    6.81 +template = "tmp"
    6.82 +
    6.83 +tempdir = None
    6.84 +
    6.85 +# Internal routines.
    6.86 +
    6.87 +_once_lock = _allocate_lock()
    6.88 +
    6.89 +class _RandomNameSequence:
    6.90 +    """An instance of _RandomNameSequence generates an endless
    6.91 +    sequence of unpredictable strings which can safely be incorporated
    6.92 +    into file names.  Each string is six characters long.  Multiple
    6.93 +    threads can safely use the same instance at the same time.
    6.94 +
    6.95 +    _RandomNameSequence is an iterator."""
    6.96 +
    6.97 +    characters = ("abcdefghijklmnopqrstuvwxyz" +
    6.98 +                  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
    6.99 +                  "0123456789-_")
   6.100 +
   6.101 +    def __init__(self):
   6.102 +        self.mutex = _allocate_lock()
   6.103 +        self.rng = _Random()
   6.104 +        self.normcase = _os.path.normcase
   6.105 +
   6.106 +    def __iter__(self):
   6.107 +        return self
   6.108 +
   6.109 +    def next(self):
   6.110 +        m = self.mutex
   6.111 +        c = self.characters
   6.112 +        choose = self.rng.choice
   6.113 +
   6.114 +        m.acquire()
   6.115 +        try:
   6.116 +            letters = [choose(c) for dummy in "123456"]
   6.117 +        finally:
   6.118 +            m.release()
   6.119 +
   6.120 +        return self.normcase(''.join(letters))
   6.121 +
   6.122 +def _candidate_tempdir_list():
   6.123 +    """Generate a list of candidate temporary directories which
   6.124 +    _get_default_tempdir will try."""
   6.125 +
   6.126 +    dirlist = []
   6.127 +
   6.128 +    # First, try the environment.
   6.129 +    for envname in 'TMPDIR', 'TEMP', 'TMP':
   6.130 +        dirname = _os.getenv(envname)
   6.131 +        if dirname: dirlist.append(dirname)
   6.132 +
   6.133 +    # Failing that, try OS-specific locations.
   6.134 +    if _os.name == 'mac':
   6.135 +        try:
   6.136 +            fsr = _Folder.FSFindFolder(_Folders.kOnSystemDisk,
   6.137 +                                              _Folders.kTemporaryFolderType, 1)
   6.138 +            dirname = fsr.as_pathname()
   6.139 +            dirlist.append(dirname)
   6.140 +        except _Folder.error:
   6.141 +            pass
   6.142 +    elif _os.name == 'riscos':
   6.143 +        dirname = _os.getenv('Wimp$ScrapDir')
   6.144 +        if dirname: dirlist.append(dirname)
   6.145 +    elif _os.name == 'nt':
   6.146 +        dirlist.extend([ r'c:\temp', r'c:\tmp', r'\temp', r'\tmp' ])
   6.147 +    else:
   6.148 +        dirlist.extend([ '/tmp', '/var/tmp', '/usr/tmp' ])
   6.149 +
   6.150 +    # As a last resort, the current directory.
   6.151 +    try:
   6.152 +        dirlist.append(_os.getcwd())
   6.153 +    except (AttributeError, _os.error):
   6.154 +        dirlist.append(_os.curdir)
   6.155 +
   6.156 +    return dirlist
   6.157 +
   6.158 +def _get_default_tempdir():
   6.159 +    """Calculate the default directory to use for temporary files.
   6.160 +    This routine should be called exactly once.
   6.161 +
   6.162 +    We determine whether or not a candidate temp dir is usable by
   6.163 +    trying to create and write to a file in that directory.  If this
   6.164 +    is successful, the test file is deleted.  To prevent denial of
   6.165 +    service, the name of the test file must be randomized."""
   6.166 +
   6.167 +    namer = _RandomNameSequence()
   6.168 +    dirlist = _candidate_tempdir_list()
   6.169 +    flags = _text_openflags
   6.170 +
   6.171 +    for dir in dirlist:
   6.172 +        if dir != _os.curdir:
   6.173 +            dir = _os.path.normcase(_os.path.abspath(dir))
   6.174 +        # Try only a few names per directory.
   6.175 +        for seq in xrange(100):
   6.176 +            name = namer.next()
   6.177 +            filename = _os.path.join(dir, name)
   6.178 +            try:
   6.179 +                fd = _os.open(filename, flags, 0600)
   6.180 +                fp = _os.fdopen(fd, 'w')
   6.181 +                fp.write('blat')
   6.182 +                fp.close()
   6.183 +                _os.unlink(filename)
   6.184 +                del fp, fd
   6.185 +                return dir
   6.186 +            except (OSError, IOError), e:
   6.187 +                if e[0] != _errno.EEXIST:
   6.188 +                    break # no point trying more names in this directory
   6.189 +                pass
   6.190 +    raise IOError, (_errno.ENOENT,
   6.191 +                    ("No usable temporary directory found in %s" % dirlist))
   6.192 +
   6.193 +_name_sequence = None
   6.194 +
   6.195 +def _get_candidate_names():
   6.196 +    """Common setup sequence for all user-callable interfaces."""
   6.197 +
   6.198 +    global _name_sequence
   6.199 +    if _name_sequence is None:
   6.200 +        _once_lock.acquire()
   6.201 +        try:
   6.202 +            if _name_sequence is None:
   6.203 +                _name_sequence = _RandomNameSequence()
   6.204 +        finally:
   6.205 +            _once_lock.release()
   6.206 +    return _name_sequence
   6.207 +
   6.208 +
   6.209 +def _mkstemp_inner(dir, pre, suf, flags):
   6.210 +    """Code common to mkstemp, TemporaryFile, and NamedTemporaryFile."""
   6.211 +
   6.212 +    names = _get_candidate_names()
   6.213 +
   6.214 +    for seq in xrange(TMP_MAX):
   6.215 +        name = names.next()
   6.216 +        file = _os.path.join(dir, pre + name + suf)
   6.217 +        try:
   6.218 +            fd = _os.open(file, flags, 0600)
   6.219 +            _set_cloexec(fd)
   6.220 +            return (fd, file)
   6.221 +        except OSError, e:
   6.222 +            if e.errno == _errno.EEXIST:
   6.223 +                continue # try again
   6.224 +            raise
   6.225 +
   6.226 +    raise IOError, (_errno.EEXIST, "No usable temporary file name found")
   6.227 +
   6.228 +
   6.229 +# User visible interfaces.
   6.230 +
   6.231 +def gettempprefix():
   6.232 +    """Accessor for tempdir.template."""
   6.233 +    return template
   6.234 +
   6.235 +tempdir = None
   6.236 +
   6.237 +def gettempdir():
   6.238 +    """Accessor for tempdir.tempdir."""
   6.239 +    global tempdir
   6.240 +    if tempdir is None:
   6.241 +        _once_lock.acquire()
   6.242 +        try:
   6.243 +            if tempdir is None:
   6.244 +                tempdir = _get_default_tempdir()
   6.245 +        finally:
   6.246 +            _once_lock.release()
   6.247 +    return tempdir
   6.248 +
   6.249 +def mkstemp(suffix="", prefix=template, dir=None, text=False):
   6.250 +    """mkstemp([suffix, [prefix, [dir, [text]]]])
   6.251 +    User-callable function to create and return a unique temporary
   6.252 +    file.  The return value is a pair (fd, name) where fd is the
   6.253 +    file descriptor returned by os.open, and name is the filename.
   6.254 +
   6.255 +    If 'suffix' is specified, the file name will end with that suffix,
   6.256 +    otherwise there will be no suffix.
   6.257 +
   6.258 +    If 'prefix' is specified, the file name will begin with that prefix,
   6.259 +    otherwise a default prefix is used.
   6.260 +
   6.261 +    If 'dir' is specified, the file will be created in that directory,
   6.262 +    otherwise a default directory is used.
   6.263 +
   6.264 +    If 'text' is specified and true, the file is opened in text
   6.265 +    mode.  Else (the default) the file is opened in binary mode.  On
   6.266 +    some operating systems, this makes no difference.
   6.267 +
   6.268 +    The file is readable and writable only by the creating user ID.
   6.269 +    If the operating system uses permission bits to indicate whether a
   6.270 +    file is executable, the file is executable by no one. The file
   6.271 +    descriptor is not inherited by children of this process.
   6.272 +
   6.273 +    Caller is responsible for deleting the file when done with it.
   6.274 +    """
   6.275 +
   6.276 +    if dir is None:
   6.277 +        dir = gettempdir()
   6.278 +
   6.279 +    if text:
   6.280 +        flags = _text_openflags
   6.281 +    else:
   6.282 +        flags = _bin_openflags
   6.283 +
   6.284 +    return _mkstemp_inner(dir, prefix, suffix, flags)
   6.285 +
   6.286 +
   6.287 +def mkdtemp(suffix="", prefix=template, dir=None):
   6.288 +    """mkdtemp([suffix, [prefix, [dir]]])
   6.289 +    User-callable function to create and return a unique temporary
   6.290 +    directory.  The return value is the pathname of the directory.
   6.291 +
   6.292 +    Arguments are as for mkstemp, except that the 'text' argument is
   6.293 +    not accepted.
   6.294 +
   6.295 +    The directory is readable, writable, and searchable only by the
   6.296 +    creating user.
   6.297 +
   6.298 +    Caller is responsible for deleting the directory when done with it.
   6.299 +    """
   6.300 +
   6.301 +    if dir is None:
   6.302 +        dir = gettempdir()
   6.303 +
   6.304 +    names = _get_candidate_names()
   6.305 +
   6.306 +    for seq in xrange(TMP_MAX):
   6.307 +        name = names.next()
   6.308 +        file = _os.path.join(dir, prefix + name + suffix)
   6.309 +        try:
   6.310 +            _os.mkdir(file, 0700)
   6.311 +            return file
   6.312 +        except OSError, e:
   6.313 +            if e.errno == _errno.EEXIST:
   6.314 +                continue # try again
   6.315 +            raise
   6.316 +
   6.317 +    raise IOError, (_errno.EEXIST, "No usable temporary directory name found")
   6.318 +
   6.319 +def mktemp(suffix="", prefix=template, dir=None):
   6.320 +    """mktemp([suffix, [prefix, [dir]]])
   6.321 +    User-callable function to return a unique temporary file name.  The
   6.322 +    file is not created.
   6.323 +
   6.324 +    Arguments are as for mkstemp, except that the 'text' argument is
   6.325 +    not accepted.
   6.326 +
   6.327 +    This function is unsafe and should not be used.  The file name
   6.328 +    refers to a file that did not exist at some point, but by the time
   6.329 +    you get around to creating it, someone else may have beaten you to
   6.330 +    the punch.
   6.331 +    """
   6.332 +
   6.333 +##    from warnings import warn as _warn
   6.334 +##    _warn("mktemp is a potential security risk to your program",
   6.335 +##          RuntimeWarning, stacklevel=2)
   6.336 +
   6.337 +    if dir is None:
   6.338 +        dir = gettempdir()
   6.339 +
   6.340 +    names = _get_candidate_names()
   6.341 +    for seq in xrange(TMP_MAX):
   6.342 +        name = names.next()
   6.343 +        file = _os.path.join(dir, prefix + name + suffix)
   6.344 +        if not _os.path.exists(file):
   6.345 +            return file
   6.346 +
   6.347 +    raise IOError, (_errno.EEXIST, "No usable temporary filename found")
   6.348 +
   6.349 +class _TemporaryFileWrapper:
   6.350 +    """Temporary file wrapper
   6.351 +
   6.352 +    This class provides a wrapper around files opened for
   6.353 +    temporary use.  In particular, it seeks to automatically
   6.354 +    remove the file when it is no longer needed.
   6.355 +    """
   6.356 +
   6.357 +    def __init__(self, file, name):
   6.358 +        self.file = file
   6.359 +        self.name = name
   6.360 +        self.close_called = False
   6.361 +
   6.362 +    def __getattr__(self, name):
   6.363 +        file = self.__dict__['file']
   6.364 +        a = getattr(file, name)
   6.365 +        if type(a) != type(0):
   6.366 +            setattr(self, name, a)
   6.367 +        return a
   6.368 +
   6.369 +    # NT provides delete-on-close as a primitive, so we don't need
   6.370 +    # the wrapper to do anything special.  We still use it so that
   6.371 +    # file.name is useful (i.e. not "(fdopen)") with NamedTemporaryFile.
   6.372 +    if _os.name != 'nt':
   6.373 +
   6.374 +        # Cache the unlinker so we don't get spurious errors at
   6.375 +        # shutdown when the module-level "os" is None'd out.  Note
   6.376 +        # that this must be referenced as self.unlink, because the
   6.377 +        # name TemporaryFileWrapper may also get None'd out before
   6.378 +        # __del__ is called.
   6.379 +        unlink = _os.unlink
   6.380 +
   6.381 +        def close(self):
   6.382 +            if not self.close_called:
   6.383 +                self.close_called = True
   6.384 +                self.file.close()
   6.385 +                self.unlink(self.name)
   6.386 +
   6.387 +        def __del__(self):
   6.388 +            self.close()
   6.389 +
   6.390 +def NamedTemporaryFile(mode='w+b', bufsize=-1, suffix="",
   6.391 +                       prefix=template, dir=None):
   6.392 +    """Create and return a temporary file.
   6.393 +    Arguments:
   6.394 +    'prefix', 'suffix', 'dir' -- as for mkstemp.
   6.395 +    'mode' -- the mode argument to os.fdopen (default "w+b").
   6.396 +    'bufsize' -- the buffer size argument to os.fdopen (default -1).
   6.397 +    The file is created as mkstemp() would do it.
   6.398 +
   6.399 +    Returns a file object; the name of the file is accessible as
   6.400 +    file.name.  The file will be automatically deleted when it is
   6.401 +    closed.
   6.402 +    """
   6.403 +
   6.404 +    if dir is None:
   6.405 +        dir = gettempdir()
   6.406 +
   6.407 +    if 'b' in mode:
   6.408 +        flags = _bin_openflags
   6.409 +    else:
   6.410 +        flags = _text_openflags
   6.411 +
   6.412 +    # Setting O_TEMPORARY in the flags causes the OS to delete
   6.413 +    # the file when it is closed.  This is only supported by Windows.
   6.414 +    if _os.name == 'nt':
   6.415 +        flags |= _os.O_TEMPORARY
   6.416 +
   6.417 +    (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
   6.418 +    file = _os.fdopen(fd, mode, bufsize)
   6.419 +    return _TemporaryFileWrapper(file, name)
   6.420 +
   6.421 +if _os.name != 'posix' or _os.sys.platform == 'cygwin':
   6.422 +    # On non-POSIX and Cygwin systems, assume that we cannot unlink a file
   6.423 +    # while it is open.
   6.424 +    TemporaryFile = NamedTemporaryFile
   6.425 +
   6.426 +else:
   6.427 +    def TemporaryFile(mode='w+b', bufsize=-1, suffix="",
   6.428 +                      prefix=template, dir=None):
   6.429 +        """Create and return a temporary file.
   6.430 +        Arguments:
   6.431 +        'prefix', 'suffix', 'directory' -- as for mkstemp.
   6.432 +        'mode' -- the mode argument to os.fdopen (default "w+b").
   6.433 +        'bufsize' -- the buffer size argument to os.fdopen (default -1).
   6.434 +        The file is created as mkstemp() would do it.
   6.435 +
   6.436 +        Returns a file object.  The file has no name, and will cease to
   6.437 +        exist when it is closed.
   6.438 +        """
   6.439 +
   6.440 +        if dir is None:
   6.441 +            dir = gettempdir()
   6.442 +
   6.443 +        if 'b' in mode:
   6.444 +            flags = _bin_openflags
   6.445 +        else:
   6.446 +            flags = _text_openflags
   6.447 +
   6.448 +        (fd, name) = _mkstemp_inner(dir, prefix, suffix, flags)
   6.449 +        try:
   6.450 +            _os.unlink(name)
   6.451 +            return _os.fdopen(fd, mode, bufsize)
   6.452 +        except:
   6.453 +            _os.close(fd)
   6.454 +            raise
     7.1 --- a/tools/xenctl/setup.py	Thu Mar 18 14:48:11 2004 +0000
     7.2 +++ b/tools/xenctl/setup.py	Thu Mar 18 15:57:28 2004 +0000
     7.3 @@ -1,8 +1,19 @@
     7.4  
     7.5  from distutils.core import setup, Extension
     7.6 +import sys
     7.7  
     7.8 -setup(name = "xenctl",
     7.9 -      version = "1.0",
    7.10 -      packages = ["xenctl"],
    7.11 -      package_dir = { "xenctl" : "lib" },
    7.12 +modules = [ 'xenctl.console_client', 'xenctl.utils' ]
    7.13 +
    7.14 +# We need the 'tempfile' module from Python 2.3. We install this ourselves
    7.15 +# if the installed Python is older than 2.3.
    7.16 +major = sys.version_info[0]
    7.17 +minor = sys.version_info[1]
    7.18 +if major == 2 and minor < 3:
    7.19 +    modules.append('xenctl.tempfile')
    7.20 +
    7.21 +setup(name = 'xenctl',
    7.22 +      version = '1.0',
    7.23 +      py_modules = modules,
    7.24 +      package_dir = { 'xenctl' : 'lib' },
    7.25        )
    7.26 +
     8.1 --- a/tools/xend/Makefile	Thu Mar 18 14:48:11 2004 +0000
     8.2 +++ b/tools/xend/Makefile	Thu Mar 18 15:57:28 2004 +0000
     8.3 @@ -3,8 +3,13 @@ all:
     8.4  	python setup.py build
     8.5  
     8.6  install: all
     8.7 -	if [ "$(prefix)" = "" ]; then python setup.py install; \
     8.8 -	else python setup.py install --root="$(prefix)"; fi
     8.9 +	if [ "$(prefix)" = "" ]; then                   \
    8.10 +	    python setup.py install;                    \
    8.11 +	elif [ "$(dist)" = "yes" ]; then                \
    8.12 +	    python setup.py install --home="$(prefix)"; \
    8.13 +	else                                            \
    8.14 +	    python setup.py install --root="$(prefix)"; \
    8.15 +	fi
    8.16  	mkdir -p $(prefix)/usr/sbin
    8.17  	install -m0755 xend $(prefix)/usr/sbin
    8.18  
     9.1 --- a/tools/xend/lib/main.py	Thu Mar 18 14:48:11 2004 +0000
     9.2 +++ b/tools/xend/lib/main.py	Thu Mar 18 15:57:28 2004 +0000
     9.3 @@ -4,7 +4,7 @@
     9.4  ## Copyright (c) 2004, K A Fraser (University of Cambridge)
     9.5  ###########################################################
     9.6  
     9.7 -import errno, re, os, pwd, select, signal, socket, struct, sys, tempfile, time
     9.8 +import errno, re, os, pwd, select, signal, socket, struct, sys, time
     9.9  import xend.console, xend.manager, xend.utils, Xc
    9.10  
    9.11  
    10.1 --- a/xen/common/sched_bvt.c	Thu Mar 18 14:48:11 2004 +0000
    10.2 +++ b/xen/common/sched_bvt.c	Thu Mar 18 15:57:28 2004 +0000
    10.3 @@ -48,9 +48,9 @@ struct bvt_cpu_info
    10.4  };
    10.5  
    10.6  
    10.7 -#define DOM_INF(p) 	((struct bvt_dom_info *)(p)->sched_priv)
    10.8 -#define CPU_INF(cpu)  ((struct bvt_cpu_info *)(schedule_data[cpu]).sched_priv)
    10.9 -#define CPU_SVT(cpu)  (CPU_INF(cpu)->svt)
   10.10 +#define BVT_INFO(p)   ((struct bvt_dom_info *)(p)->sched_priv)
   10.11 +#define CPU_INFO(cpu) ((struct bvt_cpu_info *)(schedule_data[cpu]).sched_priv)
   10.12 +#define CPU_SVT(cpu)  (CPU_INFO(cpu)->svt)
   10.13  
   10.14  #define MCU            (s32)MICROSECS(100)    /* Minimum unit */
   10.15  #define MCU_ADVANCE    10                     /* default weight */
   10.16 @@ -98,10 +98,7 @@ static void __calc_evt(struct bvt_dom_in
   10.17   */
   10.18  int bvt_alloc_task(struct task_struct *p)
   10.19  {
   10.20 -    DOM_INF(p)
   10.21 -        = (struct bvt_dom_info *)kmem_cache_alloc(dom_info_cache,GFP_KERNEL);
   10.22 -	
   10.23 -	if ( DOM_INF(p) == NULL )
   10.24 +    if ( (BVT_INFO(p) = kmem_cache_alloc(dom_info_cache,GFP_KERNEL)) == NULL )
   10.25          return -1;
   10.26      
   10.27      return 0;
   10.28 @@ -112,7 +109,7 @@ int bvt_alloc_task(struct task_struct *p
   10.29   */
   10.30  void bvt_add_task(struct task_struct *p) 
   10.31  {
   10.32 -    struct bvt_dom_info *inf = DOM_INF(p);
   10.33 +    struct bvt_dom_info *inf = BVT_INFO(p);
   10.34  
   10.35      ASSERT(inf != NULL);
   10.36      ASSERT(p   != NULL);
   10.37 @@ -151,10 +148,9 @@ void bvt_free_task(struct task_struct *p
   10.38  
   10.39  void bvt_wake_up(struct task_struct *p)
   10.40  {
   10.41 -    struct bvt_dom_info *inf = DOM_INF(p);
   10.42 +    struct bvt_dom_info *inf = BVT_INFO(p);
   10.43  
   10.44      ASSERT(inf != NULL);
   10.45 -    
   10.46  
   10.47      /* set the BVT parameters */
   10.48      if (inf->avt < CPU_SVT(p->processor))
   10.49 @@ -172,7 +168,7 @@ void bvt_wake_up(struct task_struct *p)
   10.50   */
   10.51  static long bvt_do_block(struct task_struct *p)
   10.52  {
   10.53 -    DOM_INF(p)->warpback = 0; 
   10.54 +    BVT_INFO(p)->warpback = 0; 
   10.55      return 0;
   10.56  }
   10.57  
   10.58 @@ -196,7 +192,7 @@ int bvt_adjdom(struct task_struct *p,
   10.59                      warpl = params->warpl,
   10.60                      warpu = params->warpu;
   10.61      
   10.62 -    struct bvt_dom_info *inf = DOM_INF(p);
   10.63 +    struct bvt_dom_info *inf = BVT_INFO(p);
   10.64  
   10.65      /* Sanity -- this can avoid divide-by-zero. */
   10.66      if ( mcu_adv == 0 )
   10.67 @@ -229,7 +225,7 @@ static task_slice_t bvt_do_schedule(s_ti
   10.68      s32                 ranfor;     /* assume we never run longer than 2.1s! */
   10.69      s32                 mcus;
   10.70      u32                 next_evt, next_prime_evt, min_avt;
   10.71 -    struct bvt_dom_info *prev_inf       = DOM_INF(prev),
   10.72 +    struct bvt_dom_info *prev_inf       = BVT_INFO(prev),
   10.73                          *p_inf          = NULL,
   10.74                          *next_inf       = NULL,
   10.75                          *next_prime_inf = NULL;
   10.76 @@ -271,7 +267,7 @@ static task_slice_t bvt_do_schedule(s_ti
   10.77      list_for_each ( tmp, &schedule_data[cpu].runqueue )
   10.78      {
   10.79          p     = list_entry(tmp, struct task_struct, run_list);
   10.80 -        p_inf = DOM_INF(p);
   10.81 +        p_inf = BVT_INFO(p);
   10.82  
   10.83          if ( p_inf->evt < next_evt )
   10.84          {
   10.85 @@ -331,8 +327,8 @@ static task_slice_t bvt_do_schedule(s_ti
   10.86          goto sched_done;
   10.87      }
   10.88  
   10.89 -    next_prime_inf = DOM_INF(next_prime);
   10.90 -    next_inf       = DOM_INF(next);
   10.91 +    next_prime_inf = BVT_INFO(next_prime);
   10.92 +    next_inf       = BVT_INFO(next);
   10.93  
   10.94      /*
   10.95       * If we are here then we have two runnable tasks.
   10.96 @@ -357,7 +353,7 @@ static task_slice_t bvt_do_schedule(s_ti
   10.97  
   10.98  static void bvt_dump_runq_el(struct task_struct *p)
   10.99  {
  10.100 -    struct bvt_dom_info *inf = DOM_INF(p);
  10.101 +    struct bvt_dom_info *inf = BVT_INFO(p);
  10.102      
  10.103      printk("mcua=0x%04lX ev=0x%08X av=0x%08X ",
  10.104             inf->mcu_advance, inf->evt, inf->avt);
  10.105 @@ -381,11 +377,11 @@ int bvt_init_scheduler()
  10.106  
  10.107      for ( i = 0; i < NR_CPUS; i++ )
  10.108      {
  10.109 -        CPU_INF(i) = kmalloc(sizeof(struct bvt_cpu_info), GFP_KERNEL);
  10.110 +        CPU_INFO(i) = kmalloc(sizeof(struct bvt_cpu_info), GFP_KERNEL);
  10.111  
  10.112 -        if ( CPU_INF(i) == NULL )
  10.113 +        if ( CPU_INFO(i) == NULL )
  10.114          {
  10.115 -            printk("Failed to allocate BVT scheduler private per-CPU memory!\n");
  10.116 +            printk("Failed to allocate BVT scheduler per-CPU memory!\n");
  10.117              return -1;
  10.118          }
  10.119  
    11.1 --- a/xen/common/schedule.c	Thu Mar 18 14:48:11 2004 +0000
    11.2 +++ b/xen/common/schedule.c	Thu Mar 18 15:57:28 2004 +0000
    11.3 @@ -112,9 +112,7 @@ struct task_struct *alloc_task_struct(vo
    11.4  {
    11.5      struct task_struct *p;
    11.6  
    11.7 -    p=((struct task_struct *)kmem_cache_alloc(task_struct_cachep,GFP_KERNEL));
    11.8 -
    11.9 -    if ( p == NULL )
   11.10 +    if ( (p = kmem_cache_alloc(task_struct_cachep,GFP_KERNEL)) == NULL )
   11.11          return NULL;
   11.12  
   11.13      memset(p, 0, sizeof(*p));    
   11.14 @@ -135,7 +133,7 @@ void sched_add_domain(struct task_struct
   11.15  {
   11.16      p->state = TASK_STOPPED;
   11.17  
   11.18 -    if( p->domain != IDLE_DOMAIN_ID )
   11.19 +    if ( p->domain != IDLE_DOMAIN_ID )
   11.20      {
   11.21          /* Initialise the per-domain timer. */
   11.22          init_ac_timer(&p->timer);
   11.23 @@ -175,8 +173,8 @@ void init_idle_task(void)
   11.24      unsigned long flags;
   11.25      struct task_struct *p = current;
   11.26  
   11.27 -    if ( SCHED_FN (alloc_task, p) < 0)
   11.28 -		panic("Failed to allocate scheduler private data for idle task");
   11.29 +    if ( SCHED_FN(alloc_task, p) < 0 )
   11.30 +        panic("Failed to allocate scheduler private data for idle task");
   11.31      SCHED_FN(add_task, p);
   11.32  
   11.33      spin_lock_irqsave(&schedule_lock[p->processor], flags);
   11.34 @@ -671,7 +669,7 @@ void dump_runq(u_char key, void *dev_id,
   11.35      s_time_t now = NOW();
   11.36      int i;
   11.37  
   11.38 -	printk("Scheduler: %s (%s)\n", ops.name, ops.opt_name);
   11.39 +    printk("Scheduler: %s (%s)\n", ops.name, ops.opt_name);
   11.40      SCHED_FN(dump_settings);
   11.41      printk("NOW=0x%08X%08X\n",  (u32)(now>>32), (u32)now); 
   11.42      for (i = 0; i < smp_num_cpus; i++) {