[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel]xl create PV guest with qcow/qcow2 disk images fail
On Thu, 27 Oct 2011, Chun Yan Liu wrote: > > Thank you all. Have tested pv-grub and qemu-nbd trick. Both work. > > Following is the test patch that starts qemu-nbd to mount a non-raw qdisk in > domain0, so that it can work with qcow/qcow2 > disk image and using pygrub. I don't know if we need such a patch, or prefer > to ask user to use pv-grub instead. Just post > here for any chance of use. Thanks. > > Â > > Patch description: start qemu-nbd to mount non-raw qdisk in dom0 so that xl > can create PV guest with qcow/qcow2 disk image > and using pygrub. > > Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx> > > > diff -r b4cf57bbc3fb tools/libxl/libxl.c > > --- a/tools/libxl/libxl.cThu Oct 20 15:24:46 2011 +0800 > > +++ b/tools/libxl/libxl.cThu Oct 20 15:48:45 2011 +0800 > > @@ -1078,12 +1078,41 @@ > > Â Â Â Â Â return rc; > > Â } > > Â > > +static char * nbd_mount_disk(libxl_device_disk *disk) > > +{ > > + Â Â Â int i; > > + Â Â Â int nbds_max = 16; > > + Â Â Â char *nbd_dev, *cmd; > > + Â Â Â char *ret = NULL; > > + > > + Â Â Â for (i = 0; i < nbds_max; i++) { > > + Â Â Â Â Â Â Â asprintf(&nbd_dev,"/dev/nbd%d", i); > > + Â Â Â Â Â Â Â asprintf(&cmd, "qemu-nbd -c %s %s", nbd_dev, disk->pdev_path); > > + Â Â Â Â Â Â Â if (system(cmd) == 0) { > > + Â Â Â Â Â Â Â Â Â Â Â ret = strdup(nbd_dev); > > + Â Â Â Â Â Â Â Â Â Â Â break; > > + Â Â Â Â Â Â Â } > > + Â Â Â } You should use fork, libxl_postfork and exec instead of system. See xl_cmdimpl.c:autoconnect_console for example. Also where are nbd_dev and cmd freed? > + > > + Â Â Â return ret; > > +} > > + > > +static int nbd_unmount_disk(char *diskpath) { > > + Â Â Â char *cmd; > > + Â Â Â asprintf(&cmd, "qemu-nbd -d %s", diskpath); > > + Â Â Â if (system(cmd) == 0) > > + Â Â Â Â Â Â Â return 0; > > + Â Â Â else > > + Â Â Â Â Â Â Â return ERROR_FAIL; > > +} Same here. > + > > Â char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk > *disk) > > Â { > > Â Â Â Â Â libxl__gc gc = LIBXL_INIT_GC(ctx); > > Â Â Â Â Â char *dev = NULL; > > Â Â Â Â Â char *ret = NULL; > > Â Â Â Â Â int rc; > > + Â Â Â char *mdev = NULL; > > Â > > Â Â Â Â Â rc = libxl__device_disk_set_backend(&gc, disk); > > Â Â Â Â Â if (rc) goto out; > > @@ -1118,8 +1147,12 @@ > > Â Â Â Â Â Â Â Â Â Â Â Â Â break; > > Â Â Â Â Â Â Â Â Â case LIBXL_DISK_BACKEND_QDISK: > > Â Â Â Â Â Â Â Â Â Â Â Â Â if (disk->format != LIBXL_DISK_FORMAT_RAW) { > > - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot > locally" > > - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â " attach a qdisk image > if the format is not raw"); > > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "attaching > a non-raw qdisk image to domain 0\n"); > > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â mdev = nbd_mount_disk(disk); > > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (mdev) > > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dev = mdev; > > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â else > > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â LIBXL__LOG(ctx, LIBXL__LOG_ERROR, > "fail to mount image with qemu-nbd"); > > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break; > > Â Â Â Â Â Â Â Â Â Â Â Â Â } > > Â Â Â Â Â Â Â Â Â Â Â Â Â LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally > attaching qdisk %s\n", > > @@ -1135,11 +1168,13 @@ > > Â Â out: > > Â Â Â Â Â if (dev != NULL) > > Â Â Â Â Â Â Â Â Â ret = strdup(dev); > > + Â Â Â if (mdev) > > + Â Â Â Â Â Â Â free(mdev); > > Â Â Â Â Â libxl__free_all(&gc); > > Â Â Â Â Â return ret; > > Â } > > Â > > -int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk) > > +int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk, > char *diskpath) > > Â { > > Â Â Â Â Â /* Nothing to do for PHYSTYPE_PHY. */ > > Â > > @@ -1147,6 +1182,19 @@ > > Â Â Â Â Â Â * For other device types assume that the blktap2 process is > > Â Â Â Â Â Â * needed by the soon to be started domain and do nothing. > > Â Â Â Â Â Â */ > > + Â Â Â int ret; > > + > > + Â Â Â switch (disk->backend) { > > + Â Â Â Â Â Â Â case LIBXL_DISK_BACKEND_QDISK: > > + Â Â Â Â Â Â Â Â Â Â Â if (disk->format != LIBXL_DISK_FORMAT_RAW) { > > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Locally > detach a non-raw " > > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "qdisk image"); > > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ret = nbd_unmount_disk(diskpath); > > + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return ret; > > + Â Â Â Â Â Â Â Â Â Â Â } > > + Â Â Â Â Â Â Â default: > > + Â Â Â Â Â Â Â Â Â Â Â break; > > + Â Â Â } > > Â > > Â Â Â Â Â return 0; > > Â } > > diff -r b4cf57bbc3fb tools/libxl/libxl.h > > --- a/tools/libxl/libxl.hThu Oct 20 15:24:46 2011 +0800 > > +++ b/tools/libxl/libxl.hThu Oct 20 15:48:45 2011 +0800 > > @@ -390,7 +390,7 @@ > > Â Â * Make a disk available in this domain. Returns path to a device. > > Â Â */ > > Â char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk > *disk); > > -int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk); > > +int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk, > char *diskpath); > > Â > > Â int libxl_device_nic_init(libxl_device_nic *nic, int dev_num); > > Â int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic > *nic); > > diff -r b4cf57bbc3fb tools/libxl/libxl_bootloader.c > > --- a/tools/libxl/libxl_bootloader.cThu Oct 20 15:24:46 2011 +0800 > > +++ b/tools/libxl/libxl_bootloader.cThu Oct 20 15:48:45 2011 +0800 > > @@ -424,7 +424,7 @@ > > Â Â Â Â Â rc = 0; > > Â out_close: > > Â Â Â Â Â if (diskpath) { > > - Â Â Â Â Â Â Â libxl_device_disk_local_detach(ctx, disk); > > + Â Â Â Â Â Â Â libxl_device_disk_local_detach(ctx, disk, diskpath); > > Â Â Â Â Â Â Â Â Â free(diskpath); > > Â Â Â Â Â } > > Â Â Â Â Â if (fifo_fd > -1) > > > >>> Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> 10/19/2011 9:40 PM > >>> >>> > On Wed, 19 Oct 2011, Fajar A. Nugraha wrote: > > On Wed, Oct 19, 2011 at 5:55 PM, Stefano Stabellini > > <stefano.stabellini@xxxxxxxxxxxxx> wrote: > > >> This is a PV guest configured with pygrub, correct? > > >> If so, qcow/qcow2 are not supported in this scenario. > > >> > > >> You could: > > >> > > >> - avoid using pygrub (specify the kernel manually) and keep using > > >> qcow/qcow2; > > >> - switch to raw disks and keep using pygrub; > > >> - install a Linux kernel that support blktap2 (like the XCP kernel, see > > >>Â Â http://wiki.xen.org/xenwiki/XenDom0Kernels)Â and switch to VHD > > >>format. > > >> > > > > > > The way to make it work would be to call qemu-nbd and nbd-client from xl > > > so that a /dev/nbd0 comes up in dom0 and pygrub can use it to extract > > > the kernel and initrd from the qcow2 image. > > > > would pv-grub work? If yes, it would give better performance compared > > to nbd workaround. > > Yes, it should. That would be the other alternative. > > > _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |