From: "Pat Campbell" Subject: RFC: Xen cdrom haldaemon Date: Wed, 05 Sep 2007 10:43:30 -0600 Message-ID: <46DE8884.3E48.0018.0@novell.com> References: <20070903191808.GC22983@redhat.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part8EA91BA2.1__=" Return-path: In-Reply-To: <20070903191808.GC22983@redhat.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --=__Part8EA91BA2.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi, I have found that the DOM0 CDROM device returns a stale disk=20 size if a CD is changed while any application has the device open. Test scenerio: ( Don't need XEN for this ) Two shell processes Shell A runs simple test program with an arg to=20 open the cd for reading=20 report media size using lseek(0, SEEK_END)=20 then enter a sleep loop leaving FD open In Shell B=20 eject=20 insert a different CD=20 eject -t,=20 run simple test progran, no arg=20 ( size is still what was reported in shell A) Kill Shell A test CD process Run test CD process again, now you should have the=20 correct size Simple test program, cdrom-test.c, has been attached. I did enter a defect against the Linux kernel about this but was unable to convince them it was their defect. If we put Xen in the mix, say installing a FV Redhat system from physical CD media you will have two CDROM device file descriptors open. One in blkback and the other in QEMU.=20 When you get to CD #2 you won't be able to complete the install as the total disk size has not been updated for the larger CD #2, stays at the smaller CD #1 size. You can get the QEMU descriptor closed by using xen-store writes but none effect the blkback FD and there is no way, that I have found, to effect ALL open Xen related FDs on=20 that device. I have created a proof of concept patch for 3.1 that addresses the=20 above issue by causing all VMs, FV and PV, to close thier open pyhsical CDROM file descriptors when the device door is opened. File descriptors are re-opened when the door is closed AND a CD was=20 inserted. The basic flow of the patch is: Kernel: blkback driver:=20 if block device is a physical cdrom then Add media_present=3D1 into xenstore backend/vbd=20 for this device Place a xenstore watch on media_present =20 watch_handler if watch token is media_present read value if 0 then close block device fd if 1 then re-open block device fd Any access with fd closed results in EACCESS error qemu if block device is a cdrom Place a xenstore watch on media_present=20 watch_handler if watch token is media_present read value if 0 then close block device if 1 then re-open block device and set media_changed Any access with fd closed results in EACCESS error =20 xend Starts XEN HalDaemon process =20 XEN HalDaemon =20 Registers event callback for HALD events callback handler gets device major/minor numbers for each vbd in xenstore if matching major and minor if add_event ( cdrom door closed with media ) xenstore write 1 to vbd/media_present else ( cddrom door open ) xenstore write 0 to vbd/media_present I am just learning python, could use a python guy to enhance and=20 generalize. With my patch applied I was able to install RHEL5 from the 5 CD set as well as a WIN2003 server from multi CD media. =20 The patch is attached. Patch still needs some work but I would like=20 some feedback before going further down this path. Is this something that fits into the current and near future architecture and might be=20 considered for addition? =20 Thanks in advance Pat --=__Part8EA91BA2.1__= Content-Type: application/octet-stream; name="cdrom-test.c" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="cdrom-test.c" I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzeXMvdHlwZXMuaD4KI2luY2x1ZGUgPHN5cy9z dGF0Lmg+CiNpbmNsdWRlIDxmY250bC5oPgojaW5jbHVkZSA8bGludXgvY2Ryb20uaD4KI2luY2x1 ZGUgPGxpbnV4L2hkcmVnLmg+CiNpbmNsdWRlIDxlcnJuby5oPgoKI2RlZmluZSBPX0xBUkdFRklM RSAgICAgMDEwMDAwMApzdGF0aWMgaW50IHJhd19vcGVuKCBjb25zdCBjaGFyICpmaWxlbmFtZSkK ewogICAgaW50IGZkOwogICAgaW50NjRfdCBzaXplOwogICAgb2ZmX3QgbGVuOwogICAgaW50NjRf dCB0b3RhbF9zZWN0b3JzOwoKICAgIGZwcmludGYoc3RkZXJyLCAiICVzKCkgZmlsZW5hbWU6JXMg XG4iLCBfX1BSRVRUWV9GVU5DVElPTl9fLCBmaWxlbmFtZSk7CiAgICBmZCA9IG9wZW4oZmlsZW5h bWUsIE9fUkRXUiB8ICBPX0xBUkdFRklMRSk7CiAgICBpZiAoZmQgPCAwKSB7CiAgICAgICAgZmQg PSBvcGVuKGZpbGVuYW1lLCBPX1JET05MWSB8IE9fTEFSR0VGSUxFKTsKICAgICAgICBpZiAoZmQg PCAwKQogICAgICAgICAgICByZXR1cm4gLTE7CiAgICB9CgogICAgbGVuID0gbHNlZWsoZmQsIDAs IFNFRUtfRU5EKTsKICAgIGlmICggbGVuID09IC0xICkKICAgIHsKICAgICAgICBwZXJyb3IoImxz ZWVrIik7CiAgICAgICAgZnByaW50ZihzdGRlcnIsICIgbGVuOiVsbGQgZXJybm86JWQgXG4iLGxl biwgZXJybm8pOwogICAgfQogICAgdG90YWxfc2VjdG9ycyA9IGxlbiAvIDUxMjsKICAgIGZwcmlu dGYoc3RkZXJyLCAiICVzKCkgICAgICAgICAgIGxlbjolbGxkIFxuIiwgX19QUkVUVFlfRlVOQ1RJ T05fXywgbGVuICk7CiAgICBmcHJpbnRmKHN0ZGVyciwgIiAlcygpIHRvdGFsX3NlY3RvcnM6JWxs ZCBcbiIsIF9fUFJFVFRZX0ZVTkNUSU9OX18sIHRvdGFsX3NlY3RvcnMgKTsKICAgIHJldHVybiAw Owp9CgoKbWFpbiggaW50IGFyZ2MsIGNoYXIgKiphcmd2ICkKewogICAgcmF3X29wZW4oICIvZGV2 L2Nkcm9tIik7CiAgICBpZiAoIGFyZ2MgIT0gMSApCiAgICB7CiAgICAgICAgd2hpbGUoIDEgKQog ICAgICAgICAgICBzbGVlcCgxKTsKICAgIH0KfQo= --=__Part8EA91BA2.1__= Content-Type: text/plain; name="xen-3.1-cdrom.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-3.1-cdrom.patch" # HG changeset patch # User plc@plc4.provo.novell.com # Date 1182539263 21600 # Node ID fa6ec13addb49f7054c364a90bbcbfae1d79fea8 # Parent 362adec0c4592f130ba17304126656b40f1b0324 CDROM removable media-present attribute plus handling code diff -r 362adec0c459 -r fa6ec13addb4 linux-2.6-xen-sparse/drivers/xen/blkba= ck/Makefile --- a/linux-2.6-xen-sparse/drivers/xen/blkback/Makefile Fri Jun 22 = 13:02:23 2007 -0600 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/Makefile Fri Jun 22 = 13:07:43 2007 -0600 @@ -1,3 +1,3 @@ obj-$(CONFIG_XEN_BLKDEV_BACKEND) :=3D blkb obj-$(CONFIG_XEN_BLKDEV_BACKEND) :=3D blkbk.o =20 -blkbk-y :=3D blkback.o xenbus.o interface.o vbd.o +blkbk-y :=3D blkback.o xenbus.o interface.o vbd.o cdrom.o diff -r 362adec0c459 -r fa6ec13addb4 linux-2.6-xen-sparse/drivers/xen/blkba= ck/cdrom.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/cdrom.c Fri Jun 22 = 13:07:43 2007 -0600 @@ -0,0 +1,169 @@ +/*************************************************************************= ***** + * blkback/cdrom.c + * + * Routines for managing cdrom watch and media-present attribute of a + * cdrom type virtual block device (VBD). + * + * Copyright (c) 2003-2005, Keir Fraser & Steve Hand + * Copyright (c) 2007 Pat Campbell + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation; or, when distributed + * separately from the Linux kernel or incorporated into other + * software packages, subject to the following license: + * + * Permission is hereby granted, free of charge, to any person obtaining = a copy + * of this source file (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, = modify, + * merge, publish, distribute, sublicense, and/or sell copies of the = Software, + * and to permit persons to whom the Software is furnished to do so, = subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be = included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, = EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY= , + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT = SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, = ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER = DEALINGS + * IN THE SOFTWARE. + */ + +#include "common.h" + +#undef DPRINTK +#define DPRINTK(_f, _a...) \ + printk("(%s() file=3D%s, line=3D%d) " _f "\n", \ + __PRETTY_FUNCTION__, __FILE__ , __LINE__ , ##_a ) + + +#define MEDIA_PRESENT "media-present" + +static void cdrom_media_changed(struct xenbus_watch *, const char **, = unsigned int); + +/** + * Writes media-present=3D1 attribute for the given vbd device if not + * already there + */ +static int cdrom_xenstore_write_media_present(struct backend_info *be) +{ + struct xenbus_device *dev =3D be->dev; + struct xenbus_transaction xbt; + int err; + int media_present; + + DPRINTK(" "); + + err =3D xenbus_scanf(XBT_NIL, dev->nodename, MEDIA_PRESENT, "%d", + &media_present); + if ( 0 < err) { + DPRINTK("already written err%d", err); + return(0); + } + media_present =3D 1; + +again: + err =3D xenbus_transaction_start(&xbt); + if (err) { + xenbus_dev_fatal(dev, err, "starting transaction"); + return(-1); + } + + err =3D xenbus_printf(xbt, dev->nodename, MEDIA_PRESENT, "%d", = media_present ); + if (err) { + xenbus_dev_fatal(dev, err, "writing %s/%s", + dev->nodename, MEDIA_PRESENT); + goto abort; + } + err =3D xenbus_transaction_end(xbt, 0); + if (err =3D=3D -EAGAIN) + goto again; + if (err) + xenbus_dev_fatal(dev, err, "ending transaction"); + return(0); + abort: + xenbus_transaction_end(xbt, 1); + return(-1); +} + +/** + * + */ +int cdrom_is_type(struct backend_info *be) +{ + DPRINTK( "type:%x", be->blkif->vbd.type ); + if ( be->blkif->vbd.type & VDISK_CDROM && be->blkif->vbd.type & = GENHD_FL_REMOVABLE){ + return(1); + } + return(0); +} + +/** + * + */ +void cdrom_add_media_watch(struct backend_info *be) +{ + struct xenbus_device *dev =3D be->dev; + int err; + + DPRINTK( "nodename:%s", dev->nodename); + if (cdrom_is_type(be)) { + DPRINTK("is a cdrom"); + if ( cdrom_xenstore_write_media_present(be) =3D=3D 0 ) { + DPRINTK( "xenstore wrote OK"); + err =3D xenbus_watch_path2(dev, dev->nodename, MEDIA_PRESEN= T, + &be->backend_cdrom_watch, cdrom_media_changed); + if (err) { + DPRINTK( "media_present watch add failed" ); + } + } + } +} + +/** + * Callback received when the "media_present" xenstore node is changed + */ +static void cdrom_media_changed(struct xenbus_watch *watch, + const char **vec, unsigned int len) +{ + int err; + unsigned media_present; + struct backend_info *be + =3D container_of(watch, struct backend_info, backend_cdrom_= watch); + struct xenbus_device *dev =3D be->dev; + + DPRINTK(" "); + + if ( !(cdrom_is_type(be))) { + DPRINTK("callback not for a cdrom" ); + return; + } + + err =3D xenbus_scanf(XBT_NIL, dev->nodename, MEDIA_PRESENT, "%d", + &media_present); + if (err =3D=3D 0 || err =3D=3D -ENOENT) { + DPRINTK("xenbus_read of cdrom media_present node error:%d",= err); + return; + } + + if (media_present =3D=3D 0) { + vbd_free(&be->blkif->vbd); + } + else { + char *p =3D strrchr(dev->otherend, '/') + 1; + long handle =3D simple_strtoul(p, NULL, 0); + + if (be->blkif->vbd.bdev =3D=3D NULL) { + err =3D vbd_create(be->blkif, handle, be->major, = be->minor, + (NULL =3D=3D strchr(be->mode, 'w'))); + if (err) { + be->major =3D be->minor =3D 0; + xenbus_dev_fatal(dev, err, "creating vbd = structure"); + return; + } + } + } +} diff -r 362adec0c459 -r fa6ec13addb4 linux-2.6-xen-sparse/drivers/xen/blkba= ck/common.h --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h Fri Jun 22 = 13:02:23 2007 -0600 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h Fri Jun 22 = 13:07:43 2007 -0600 @@ -96,6 +96,17 @@ typedef struct blkif_st { grant_ref_t shmem_ref; } blkif_t; =20 +struct backend_info +{ + struct xenbus_device *dev; + blkif_t *blkif; + struct xenbus_watch backend_watch; + struct xenbus_watch backend_cdrom_watch; + unsigned major; + unsigned minor; + char *mode; +}; + blkif_t *blkif_alloc(domid_t domid); void blkif_disconnect(blkif_t *blkif); void blkif_free(blkif_t *blkif); @@ -136,4 +147,8 @@ int blkback_barrier(struct xenbus_transa int blkback_barrier(struct xenbus_transaction xbt, struct backend_info *be, int state); =20 +/* cdrom media change */ +int cdrom_is_type(struct backend_info *be); +void cdrom_add_media_watch(struct backend_info *be); + #endif /* __BLKIF__BACKEND__COMMON_H__ */ diff -r 362adec0c459 -r fa6ec13addb4 linux-2.6-xen-sparse/drivers/xen/blkba= ck/vbd.c --- a/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c Fri Jun 22 = 13:02:23 2007 -0600 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c Fri Jun 22 = 13:07:43 2007 -0600 @@ -106,6 +106,9 @@ int vbd_translate(struct phys_req *req,=20 if ((operation !=3D READ) && vbd->readonly) goto out; =20 + if (vbd->bdev =3D=3D NULL) + goto out; + if (unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd))) goto out; =20 diff -r 362adec0c459 -r fa6ec13addb4 linux-2.6-xen-sparse/drivers/xen/blkba= ck/xenbus.c --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Fri Jun 22 = 13:02:23 2007 -0600 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Fri Jun 22 = 13:07:43 2007 -0600 @@ -26,16 +26,6 @@ #define DPRINTK(fmt, args...) \ pr_debug("blkback/xenbus (%s:%d) " fmt ".\n", \ __FUNCTION__, __LINE__, ##args) - -struct backend_info -{ - struct xenbus_device *dev; - blkif_t *blkif; - struct xenbus_watch backend_watch; - unsigned major; - unsigned minor; - char *mode; -}; =20 static void connect(struct backend_info *); static int connect_ring(struct backend_info *); @@ -179,6 +169,12 @@ static int blkback_remove(struct xenbus_ be->backend_watch.node =3D NULL; } =20 + if (be->backend_cdrom_watch.node) { + unregister_xenbus_watch(&be->backend_cdrom_watch); + kfree(be->backend_cdrom_watch.node); + be->backend_cdrom_watch.node =3D NULL; + } + if (be->blkif) { blkif_disconnect(be->blkif); vbd_free(&be->blkif->vbd); @@ -330,6 +326,9 @@ static void backend_changed(struct xenbu =20 /* We're potentially connected now */ update_blkif_status(be->blkif); + + /* Add watch for cdrom media status if necessay */ + cdrom_add_media_watch(be); } } =20 diff -r 362adec0c459 -r fa6ec13addb4 tools/ioemu/block.c --- a/tools/ioemu/block.c Fri Jun 22 13:02:23 2007 -0600 +++ b/tools/ioemu/block.c Fri Jun 22 13:07:43 2007 -0600 @@ -185,6 +185,13 @@ static BlockDriver *find_image_format(co uint8_t *buf; size_t bufsize =3D 1024; =20 + if ( strcmp(filename, "/dev/cdrom") =3D=3D 0) { + drv =3D bdrv_find_format("raw"); + if (drv !=3D NULL) { + return(drv); + } + } + fd =3D open(filename, O_RDONLY | O_BINARY | O_LARGEFILE); if (fd < 0) { buf =3D NULL; @@ -531,19 +538,9 @@ int bdrv_is_read_only(BlockDriverState * return bs->read_only; } =20 -int bdrv_is_inserted(BlockDriverState *bs) -{ - return bs->inserted; -} - int bdrv_is_locked(BlockDriverState *bs) { return bs->locked; -} - -void bdrv_set_locked(BlockDriverState *bs, int locked) -{ - bs->locked =3D locked; } =20 void bdrv_set_change_cb(BlockDriverState *bs,=20 @@ -692,8 +689,10 @@ static int raw_open(BlockDriverState *bs fd =3D open(filename, O_RDWR | O_BINARY | O_LARGEFILE); if (fd < 0) { fd =3D open(filename, O_RDONLY | O_BINARY | O_LARGEFILE); - if (fd < 0) - return -1; + if (fd < 0 && strstart(filename, "/dev/cd", NULL)) + fd =3D open(filename, O_RDONLY | O_BINARY | O_LARGEFILE | = O_NONBLOCK ); + if (fd < 0) + return -1; bs->read_only =3D 1; } #ifdef _BSD @@ -764,7 +763,93 @@ static void raw_close(BlockDriverState * BDRVRawState *s =3D bs->opaque; bs->total_sectors =3D 0; close(s->fd); -} + s->fd =3D -1; +} + +#include +#include +static int raw_is_inserted(BlockDriverState *bs) +{ + BDRVRawState *s =3D bs->opaque; + int ret; + + switch(bs->removable) { + case BDRV_TYPE_CDROM: + ret =3D ioctl(s->fd, CDROM_DRIVE_STATUS, CDSL_CURRENT); + if (ret =3D=3D CDS_DISC_OK) { + return 1; + } + else { + return 0; + } + break; + default: + return 1; + } +} + +static int raw_media_changed(BlockDriverState *bs) +{ + int ret =3D 0; + + switch(bs->removable) { + case BDRV_TYPE_CDROM: + { + if( bs->media_changed =3D=3D 1 ) + { + ret =3D 1; + bs->media_changed =3D 0; + } + return ret; + } + default: + return -ENOTSUP; + } +} + + +static int raw_eject(BlockDriverState *bs, int eject_flag) +{ + char cmd[sizeof(bs->device_name) + 32]; + + switch(bs->removable) { + case BDRV_TYPE_CDROM: + if (eject_flag) { + sprintf(cmd, "eject %s", bs->filename); + if (system(cmd) =3D=3D -1) { + perror("CDROMEJECT"); + } + } else { + sprintf(cmd, "eject -t %s", bs->filename); + if (system(cmd) =3D=3D -1) { + perror("CDROMCLOSETRAY"); + } + } + break; + default: + return -ENOTSUP; + } + return 0; +} + +static int raw_set_locked(BlockDriverState *bs, int locked) +{ + BDRVRawState *s =3D bs->opaque; + + switch(bs->removable) { + case BDRV_TYPE_CDROM: + if (ioctl (s->fd, CDROM_LOCKDOOR, locked) < 0) { + /* Note: an error can happen if the distribution automatically= + mounts the CD-ROM */ + // perror("CDROM_LOCKDOOR"); + } + break; + default: + return -ENOTSUP; + } + return 0; +} + =20 #ifdef _WIN32 #include @@ -845,6 +930,12 @@ BlockDriver bdrv_raw =3D { raw_close, raw_create, raw_flush, + + /* removable device support */ + .bdrv_is_inserted =3D raw_is_inserted, + .bdrv_media_changed =3D raw_media_changed, + .bdrv_eject =3D raw_eject, + .bdrv_set_locked =3D raw_set_locked, }; =20 void bdrv_init(void) @@ -861,3 +952,96 @@ void bdrv_init(void) bdrv_register(&bdrv_vpc); bdrv_register(&bdrv_vvfat); } + +/**************************************************************/ +/* removable device support */ + +/** + * Return TRUE if the media is present + */ +int bdrv_is_inserted(BlockDriverState *bs) +{ + BlockDriver *drv =3D bs->drv; + int ret; + if (!drv) + return 0; + if (!drv->bdrv_is_inserted) + return 1; + ret =3D drv->bdrv_is_inserted(bs); + return ret; +} + +/** + * Return TRUE if the media changed since the last call to this + * function. + */ +int bdrv_media_changed(BlockDriverState *bs) +{ + BlockDriver *drv =3D bs->drv; + int ret; + + if (!drv || !drv->bdrv_media_changed) + ret =3D -ENOTSUP; + else + ret =3D drv->bdrv_media_changed(bs); + if (ret =3D=3D -ENOTSUP) + ret =3D bs->media_changed; + bs->media_changed =3D 0; + return ret; +} + + +/** + * If eject_flag is TRUE, eject the media. Otherwise, close the tray + */ +void bdrv_eject(BlockDriverState *bs, int eject_flag) +{ + + int ret =3D 0; + char cmd[sizeof(bs->device_name) + 32]; + BlockDriver *drv =3D bs->drv; + + switch(bs->removable) { + case BDRV_TYPE_CDROM: + if (eject_flag) { + sprintf(cmd, "eject %s", bs->filename); + if (system(cmd) =3D=3D -1) { + perror("CDROMEJECT"); + ret =3D -ENOTSUP; + } + } else { + sprintf(cmd, "eject -t %s", bs->filename); + if (system(cmd) =3D=3D -1) { + perror("CDROMCLOSETRAY"); + ret =3D -ENOTSUP; + } + } + break; + default: + if (!drv || !drv->bdrv_eject) { + ret =3D -ENOTSUP; + } else { + ret =3D drv->bdrv_eject(bs, eject_flag); + } + if (ret =3D=3D -ENOTSUP) { + if (eject_flag) + bdrv_close(bs); + } + } + //return ret; +} + +/** + * Lock or unlock the media (if it is locked, the user won't be able + * to eject it manually). + */ +void bdrv_set_locked(BlockDriverState *bs, int locked) +{ + BlockDriver *drv =3D bs->drv; + + bs->locked =3D locked; + if (drv && drv->bdrv_set_locked) { + drv->bdrv_set_locked(bs, locked); + } +} + diff -r 362adec0c459 -r fa6ec13addb4 tools/ioemu/block_int.h --- a/tools/ioemu/block_int.h Fri Jun 22 13:02:23 2007 -0600 +++ b/tools/ioemu/block_int.h Fri Jun 22 13:07:43 2007 -0600 @@ -41,6 +41,13 @@ struct BlockDriver { int nb_sectors, int *pnum); int (*bdrv_set_key)(BlockDriverState *bs, const char *key); int (*bdrv_make_empty)(BlockDriverState *bs); + + /* removable device specific */ + int (*bdrv_is_inserted)(BlockDriverState *bs); + int (*bdrv_media_changed)(BlockDriverState *bs); + int (*bdrv_eject)(BlockDriverState *bs, int eject_flag); + int (*bdrv_set_locked)(BlockDriverState *bs, int locked); + struct BlockDriver *next; }; =20 @@ -65,6 +72,7 @@ struct BlockDriverState { char backing_file[1024]; /* if non zero, the image is a diff of this file image */ int is_temporary; + int media_changed; =20 BlockDriverState *backing_hd; =20 diff -r 362adec0c459 -r fa6ec13addb4 tools/ioemu/hw/ide.c --- a/tools/ioemu/hw/ide.c Fri Jun 22 13:02:23 2007 -0600 +++ b/tools/ioemu/hw/ide.c Fri Jun 22 13:07:43 2007 -0600 @@ -278,6 +278,7 @@ #define ASC_ILLEGAL_OPCODE 0x20 #define ASC_LOGICAL_BLOCK_OOR 0x21 #define ASC_INV_FIELD_IN_CMD_PACKET 0x24 +#define ASC_MEDIA_CHANGED 0x28 #define ASC_MEDIUM_NOT_PRESENT 0x3a #define ASC_SAVING_PARAMETERS_NOT_SUPPORTED 0x39 =20 @@ -393,6 +394,7 @@ typedef struct PCIIDEState { } PCIIDEState; =20 #define DMA_MULTI_THREAD +#undef DMA_MULTI_THREAD =20 #ifdef DMA_MULTI_THREAD =20 @@ -1341,7 +1343,6 @@ static void ide_atapi_cmd(IDEState *s) } else { ide_atapi_cmd_error(s, SENSE_NOT_READY,=20 ASC_MEDIUM_NOT_PRESENT); - xenstore_check_new_media_present(1000); } break; case GPCMD_MODE_SENSE_10: @@ -1530,7 +1531,10 @@ static void ide_atapi_cmd(IDEState *s) =20 if (eject && !start) { /* eject the disk */ - bdrv_close(s->bs); + bdrv_eject(s->bs, 1); + } else if (eject && start) { + /* close the tray */ + bdrv_eject(s->bs, 0); } ide_atapi_cmd_ok(s); } diff -r 362adec0c459 -r fa6ec13addb4 tools/ioemu/xenstore.c --- a/tools/ioemu/xenstore.c Fri Jun 22 13:02:23 2007 -0600 +++ b/tools/ioemu/xenstore.c Fri Jun 22 13:07:43 2007 -0600 @@ -82,7 +82,7 @@ void xenstore_parse_domain_config(int do char **e =3D NULL; char *buf =3D NULL, *path; char *fpath =3D NULL, *bpath =3D NULL, - *dev =3D NULL, *params =3D NULL, *type =3D NULL; + *dev =3D NULL, *params =3D NULL, *type =3D NULL, *media_present = =3D NULL; int i, is_scsi; unsigned int len, num, hd_index; =20 @@ -168,8 +168,12 @@ void xenstore_parse_domain_config(int do /* check if it is a cdrom */ if (type && !strcmp(type, "cdrom")) { bdrv_set_type_hint(bs_table[hd_index], BDRV_TYPE_CDROM); - if (pasprintf(&buf, "%s/params", bpath) !=3D -1) - xs_watch(xsh, buf, dev); + xs_watch(xsh, buf, dev); + if (pasprintf(&buf, "%s/media-present", bpath) !=3D -1) { + free(media_present); + media_present =3D xs_read(xsh, XBT_NULL, buf, &len); + xs_watch(xsh, buf, "media_present"); + } } /* open device now if media present */ if (params[0]) { @@ -313,7 +317,7 @@ void xenstore_process_logdirty_event(voi =20 void xenstore_process_event(void *opaque) { - char **vec, *image =3D NULL; + char **vec, *image =3D NULL, *media_present =3D NULL; unsigned int len, num, hd_index; =20 vec =3D xs_read_watch(xsh, &num); @@ -322,6 +326,40 @@ void xenstore_process_event(void *opaque =20 if (!strcmp(vec[XS_WATCH_TOKEN], "logdirty")) { xenstore_process_logdirty_event(); + goto out; + } + + if (!strcmp(vec[XS_WATCH_TOKEN], "media_present")) { + media_present =3D xs_read(xsh, XBT_NULL, vec[XS_WATCH_PATH], = &len); + if (media_present) { + BlockDriverState *bs; + char *buf =3D NULL, *cp =3D NULL, *path =3D NULL, *dev =3D = NULL; + + path =3D strdup(vec[XS_WATCH_PATH]); + cp =3D strstr(path, "media-present"); + if (cp){ + *(cp-1) =3D '\0'; + pasprintf(&buf, "%s/dev", path); + dev =3D xs_read(xsh, XBT_NULL, buf, &len); + if (dev) { + bs =3D bdrv_find(dev); + if (!bs) { + term_printf("device not found\n"); + goto out; + } + if (strcmp(media_present, "0") =3D=3D 0 && bs) { + bdrv_close(bs); + } + else if (strcmp(media_present, "1") =3D=3D 0 && bs = !=3D NULL && bs->drv =3D=3D NULL) { + if (bdrv_open(bs, bs->filename, 0 /* snapshot */) = < 0) { + fprintf(stderr, "qemu: could not open hard = disk image '%s'\n", + bs->filename); + } + bs->media_changed =3D 1; + } + } + } + } goto out; } =20 diff -r 362adec0c459 -r fa6ec13addb4 tools/python/xen/xend/server/HalDaemon= .py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/xend/server/HalDaemon.py Fri Jun 22 13:07:43 2007 = -0600 @@ -0,0 +1,228 @@ +#!/usr/bin/env python +# -*- mode: python; -*- +#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General = Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 = USA +#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D +# Copyright (C) 2007 Pat Campbell +# Copyright (C) 2007 Novell Inc. +#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + +"""hald (Hardware Abstraction Layer Daemon) watcher for Xen management + of removable block device media. + +""" + +import gobject +import dbus +import dbus.glib +import os +import types +import sys +import signal +import traceback +from xen.xend.xenstore.xstransact import xstransact, complete +from xen.xend.xenstore.xsutil import xshandle +from xen.xend import PrettyPrint +from xen.xend import XendLogging +from xen.xend.XendLogging import log + +class HalDaemon: + """The Hald block device watcher for XEN + """ + + """Default path to the log file. """ + logfile_default =3D "/var/log/xen/hald.log" + + """Default level of information to be logged.""" + loglevel_default =3D 'INFO' + + def __init__(self): + + XendLogging.init(self.logfile_default, self.loglevel_default) + log.debug( "%s", "__init__") + + self.udi_dict =3D {} + self.debug =3D 0 + self.dbpath =3D "/local/domain/0/backend/vbd" + self.bus =3D dbus.SystemBus() + self.hal_manager_obj =3D self.bus.get_object('org.freedesktop.Hal'= , '/org/freedesktop/Hal/Manager') + self.hal_manager =3D dbus.Interface( self.hal_manager_obj, = 'org.freedesktop.Hal.Manager') + self.gatherBlockDevices() + self.registerDeviceCallbacks() + + def run(self): + log.debug( "%s", "In new run" ); + try: + self.mainloop =3D gobject.MainLoop() + self.mainloop.run() + except KeyboardInterrupt, ex: + log.debug('Keyboard exception handler: %s', ex ) + self.mainloop.quit() + except Exception, ex: + log.debug('Generic exception handler: %s', ex ) + self.mainloop.quit() + + def __del__(self): + log.debug( "%s", "In del " ); + self.unRegisterDeviceCallbacks() + self.mainloop.quit() + + def shutdown(self): + log.debug( "%s", "In shutdown now " ); + self.unRegisterDeviceCallbacks() + self.mainloop.quit() + + def stop(self): + log.debug( "%s", "In stop now " ); + self.unRegisterDeviceCallbacks() + self.mainloop.quit() + + def gatherBlockDevices(self): + + # Get all the current devices from hal and save in a dictionary + try: + device_names =3D self.hal_manager.GetAllDevices() + i =3D 0; + for name in device_names: + #log.debug("device name, device=3D%s",name) + dev_obj =3D self.bus.get_object ('org.freedesktop.Hal', = name) + dev =3D dbus.Interface (dev_obj, 'org.freedesktop.Hal.Devic= e') + dev_properties =3D dev_obj.GetAllProperties(dbus_interface= =3D"org.freedesktop.Hal.Device") + if dev_properties.has_key('block.device'): + dev_str =3D dev_properties['block.device'] + dev_major =3D dev_properties['block.major'] + dev_minor =3D dev_properties['block.minor'] + udi_info =3D {} + udi_info['device'] =3D dev_str + udi_info['major'] =3D dev_major + udi_info['minor'] =3D dev_minor + udi_info['udi'] =3D name + self.udi_dict[i] =3D udi_info + i =3D i + 1 + except Exception, ex: + print >>sys.stderr, 'Exception gathering block devices:', ex + log.warn("Exception gathering block devices (%s)",ex) + + # + def registerDeviceCallbacks(self): + # setup the callbacks for when the gdl changes + self.hal_manager.connect_to_signal('DeviceAdded', self.device_adde= d_callback) + self.hal_manager.connect_to_signal('DeviceRemoved', self.device_re= moved_callback) + + # + def unRegisterDeviceCallbacks(self): + # setup the callbacks for when the gdl changes + self.hal_manager.remove_signal_receiver(self.device_added_callback= ,'DeviceAdded') + self.hal_manager.remove_signal_receiver(self.device_removed_callba= ck,'DeviceRemoved') + + # + def device_removed_callback(self,udi): + log.debug('UDI %s was removed',udi) + self.show_dict(self.udi_dict) + for key in self.udi_dict: + udi_info =3D self.udi_dict[key] + if udi_info['udi'] =3D=3D udi: + device =3D udi_info['device'] + major =3D udi_info['major'] + minor =3D udi_info['minor'] + self.change_xenstore( "remove", device, major, minor) + + # Adds device to dictionary if not already there + def device_added_callback(self,udi): + log.debug('UDI %s was added', udi) + self.show_dict(self.udi_dict) + dev_obj =3D self.bus.get_object ('org.freedesktop.Hal', udi) + dev =3D dbus.Interface (dev_obj, 'org.freedesktop.Hal.Device') + device =3D dev.GetProperty ('block.device') + major =3D dev.GetProperty ('block.major') + minor =3D dev.GetProperty ('block.minor') + udi_info =3D {} + udi_info['device'] =3D device + udi_info['major'] =3D major + udi_info['minor'] =3D minor + udi_info['udi'] =3D udi + already =3D 0 + cnt =3D 0; + for key in self.udi_dict: + info =3D self.udi_dict[key] + if info['udi'] =3D=3D udi: + already =3D 1 + break + cnt =3D cnt + 1 + if already =3D=3D 0: + self.udi_dict[cnt] =3D udi_info; + log.debug('UDI %s was added, device:%s major:%s minor:%s = index:%d\n', udi, device, major, minor, cnt) + self.change_xenstore( "add", device, major, minor) + + # Debug helper, shows dictionary contents + def show_dict(self,dict=3DNone): + if self.debug =3D=3D 0 : + return + if dict =3D=3D None : + dict =3D self.udi_dict + for key in dict: + log.debug('udi_info %s udi_info:%s',key,dict[key]) + + # Set or clear xenstore media-present depending on the action = argument + # for every vbd that has this block device + def change_xenstore(self,action, device, major, minor): + domains =3D xstransact.List(self.dbpath) + log.debug('domains: %s', domains) + for domain in domains: # for each domain + devices =3D xstransact.List( self.dbpath + '/' + domain) + log.debug('devices: %s',devices) + for device in devices: # for each vbd device + str =3D device.split('/') + vbd_type =3D None; + vbd_physical_device =3D None + vbd_media =3D None + vbd_device_path =3D self.dbpath + '/' + domain + '/' + = device + listing =3D xstransact.List(vbd_device_path) + for entry in listing: # for each entry + item =3D self.dbpath + '/' + entry + value =3D xstransact.Read( vbd_device_path + '/' + = entry) + log.debug('%s=3D%s',item,value) + if item.find('media-present') !=3D -1: + vbd_media =3D item; + vbd_media_path =3D item + if item.find('physical-device') !=3D -1: + vbd_physical_device =3D value; + if item.find('type') !=3D -1: + vbd_type =3D value; + if vbd_type is not None and vbd_physical_device is not = None and vbd_media is not None : + inode =3D vbd_physical_device.split(':') + imajor =3D inode[0] + iminor =3D inode[1] + log.debug("action:%s major:%s- minor:%s- imajor:%s- = iminor:%s- inode: %s", + action,major,minor, imajor, iminor, inode) + if int(imajor) =3D=3D int(major) and int(iminor) = =3D=3D int(minor): + if action =3D=3D "add": + xs_dict =3D {'media': "1"} + xstransact.Write(vbd_device_path, 'media-presen= t', "1" ) + log.debug("wrote xenstore media-present 1 = path:%s",vbd_media_path) + else: + xstransact.Write(vbd_device_path, 'media-presen= t', "0" ) + log.debug("wrote xenstore media 0 path:%s",vbd_= media_path) + +def mylog( fmt, *args): + f =3D open('/tmp/haldaemon.log', 'a') + print >>f, "HalDaemon ", fmt % args + f.close() + +if __name__ =3D=3D "__main__": + watcher =3D HalDaemon() + watcher.run() + print 'Falling off end' + + diff -r 362adec0c459 -r fa6ec13addb4 tools/python/xen/xend/server/Hald.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/python/xen/xend/server/Hald.py Fri Jun 22 13:07:43 2007 = -0600 @@ -0,0 +1,113 @@ +#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General = Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 = USA +#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D +# Copyright (C) 2007 Pat Campbell +# Copyright (C) 2007 Novell Inc. +#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + +import errno +import types +import os +import sys +import time +import signal +from traceback import print_exc + +from xen.xend.XendLogging import log + +class Hald: + def __init__(self): + self.ready =3D False + self.running =3D True + + def run(self): + """Starts the HalDaemon process + """ + self.ready =3D True + try: + myfile =3D self.find("xen/xend/server/HalDaemon.py") + args =3D (["python", myfile ]) + self.pid =3D self.daemonize("python", args ) + #log.debug( "%s %s pid:%d", "Hald.py starting ", args, = self.pid ) + except: + self.pid =3D -1 + log.debug("Unable to start HalDaemon process") + + def shutdown(self): + """Shutdown the HalDaemon process + """ + log.debug("%s pid:%d", "Hald.shutdown()", self.pid) + self.running =3D False + self.ready =3D False + if self.pid !=3D -1: + try: + os.kill(self.pid, signal.SIGINT) + except: + print_exc() + + def daemonize(self,prog, args): + """Runs a program as a daemon with the list of arguments. = Returns the PID + of the daemonized program, or returns 0 on error. + Copied from xm/create.py instead of importing to reduce coupling + """ + r, w =3D os.pipe() + pid =3D os.fork() + + if pid =3D=3D 0: + os.close(r) + w =3D os.fdopen(w, 'w') + os.setsid() + try: + pid2 =3D os.fork() + except: + pid2 =3D None + if pid2 =3D=3D 0: + os.chdir("/") + for fd in range(0, 256): + try: + os.close(fd) + except: + pass + os.open("/dev/null", os.O_RDWR) + os.dup2(0, 1) + os.dup2(0, 2) + os.execvp(prog, args) + os._exit(1) + else: + w.write(str(pid2 or 0)) + w.close() + os._exit(0) + os.close(w) + r =3D os.fdopen(r) + daemon_pid =3D int(r.read()) + r.close() + os.waitpid(pid, 0) + #log.debug( "daemon_pid: %d", daemon_pid ) + return daemon_pid + + def find(self,path, matchFunc=3Dos.path.isfile): + """Find a module in the sys.path + From web page: http://aspn.activestate.com/ASPN/Cookbook/Python/Re= cipe/52224 + """ + for dirname in sys.path: + candidate =3D os.path.join(dirname, path) + if matchFunc(candidate): + return candidate + raise Error("Can't find file %s" % path) + +if __name__ =3D=3D "__main__": + watcher =3D Hald() + watcher.run() + time.sleep(10) + watcher.shutdown() diff -r 362adec0c459 -r fa6ec13addb4 tools/python/xen/xend/server/SrvServer= .py --- a/tools/python/xen/xend/server/SrvServer.py Fri Jun 22 13:02:23 2007 = -0600 +++ b/tools/python/xen/xend/server/SrvServer.py Fri Jun 22 13:07:43 2007 = -0600 @@ -57,6 +57,7 @@ from xen.web.SrvDir import SrvDir =20 from SrvRoot import SrvRoot from XMLRPCServer import XMLRPCServer +from xen.xend.server.Hald import Hald =20 xoptions =3D XendOptions.instance() =20 @@ -248,6 +249,8 @@ def _loadConfig(servers, root, reload): if xoptions.get_xend_unix_xmlrpc_server(): servers.add(XMLRPCServer(XendAPI.AUTH_PAM, False)) =20 + servers.add(Hald()) + =20 def create(): root =3D SrvDir() # HG changeset patch # User plc@plc4.provo.novell.com # Date 1182542474 21600 # Node ID 46685041fb424de81500375183149ecb126e1a88 # Parent fa6ec13addb49f7054c364a90bbcbfae1d79fea8 Added return true to raw_is_inserted() if ioctl fails diff -r fa6ec13addb4 -r 46685041fb42 tools/ioemu/block.c --- a/tools/ioemu/block.c Fri Jun 22 13:07:43 2007 -0600 +++ b/tools/ioemu/block.c Fri Jun 22 14:01:14 2007 -0600 @@ -777,6 +777,9 @@ static int raw_is_inserted(BlockDriverSt case BDRV_TYPE_CDROM: ret =3D ioctl(s->fd, CDROM_DRIVE_STATUS, CDSL_CURRENT); if (ret =3D=3D CDS_DISC_OK) { + return 1; + } + if (ret =3D=3D -1) { // iso case return 1; } else { # HG changeset patch # User plc@plc4.provo.novell.com # Date 1182542925 21600 # Node ID 69fc41d0f24bbc6a428d0e5dd23225ef7aa9d6f5 # Parent 46685041fb424de81500375183149ecb126e1a88 Added if test for params diff -r 46685041fb42 -r 69fc41d0f24b tools/ioemu/xenstore.c --- a/tools/ioemu/xenstore.c Fri Jun 22 14:01:14 2007 -0600 +++ b/tools/ioemu/xenstore.c Fri Jun 22 14:08:45 2007 -0600 @@ -168,7 +168,8 @@ void xenstore_parse_domain_config(int do /* check if it is a cdrom */ if (type && !strcmp(type, "cdrom")) { bdrv_set_type_hint(bs_table[hd_index], BDRV_TYPE_CDROM); - xs_watch(xsh, buf, dev); + if (pasprintf(&buf, "%s/params", bpath) !=3D -1) + xs_watch(xsh, buf, dev); if (pasprintf(&buf, "%s/media-present", bpath) !=3D -1) { free(media_present); media_present =3D xs_read(xsh, XBT_NULL, buf, &len); diff -ur a/tools/python/xen/xend/server/Hald.py b/tools/python/xen/xend/ser= ver/Hald.py --- a/tools/python/xen/xend/server/Hald.py 2007-06-28 09:24:34.0000000= 00 -0600 +++ b/tools/python/xen/xend/server/Hald.py 2007-06-28 09:25:33.0000000= 00 -0600 @@ -74,6 +74,8 @@ pid2 =3D None if pid2 =3D=3D 0: os.chdir("/") + env =3D os.environ.copy() + env['PYTHONPATH'] =3D self.getpythonpath() for fd in range(0, 256): try: os.close(fd) @@ -82,7 +84,7 @@ os.open("/dev/null", os.O_RDWR) os.dup2(0, 1) os.dup2(0, 2) - os.execvp(prog, args) + os.execvpe(prog, args, env) os._exit(1) else: w.write(str(pid2 or 0)) @@ -96,6 +98,16 @@ #log.debug( "daemon_pid: %d", daemon_pid ) return daemon_pid =20 + def getpythonpath(self): + str =3D " " + for p in sys.path: + if str !=3D " ": + str =3D str + ":" + p + else: + if str !=3D "": + str =3D p + return str + def find(self,path, matchFunc=3Dos.path.isfile): """Find a module in the sys.path From web page: http://aspn.activestate.com/ASPN/Cookbook/Python/Re= cipe/52224 --=__Part8EA91BA2.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part8EA91BA2.1__=--