@@ -443,18 +438,9 @@ class CloneDesign(object):
typ = []
for i in cln_dev_lst:
- if os.path.exists(i) == False:
- size.append(0)
- # if not exists, create file necessary
- typ.append(True)
- continue
- mode = os.stat(i)[stat.ST_MODE]
- if stat.S_ISBLK(mode):
- size.append(util.blkdev_size(i))
- typ.append(False)
- elif stat.S_ISREG(mode):
- size.append(os.path.getsize(i))
- typ.append(True)
+ (t, sz) = util.stat_disk(i)
+ typ.append(t)
+ size.append(sz)
logging.debug("clone device list: %s" % (cln_dev_lst))
logging.debug("clone device size: %s" % (size))
@@ -535,6 +521,14 @@ def _do_duplicate(design):
if src_dev == "/dev/null" or src_dev == dst_dev:
meter.end(size)
continue
+
+ if util.is_vdisk(src_dev) or (os.path.exists(dst_dev) and util.is_vdisk(dst_dev)):
+ if not util.is_vdisk(src_dev) or os.path.exists(dst_dev):
+ raise RuntimeError, _("copying to an existing vdisk is not supported")
+ if not util.vdisk_clone(src_dev, dst_dev):
+ raise RuntimeError, _("failed to clone disk")
+ continue
+
#
# create sparse file
# if a destination file exists and sparse flg is True,
diff --git a/virtinst/Guest.py b/virtinst/Guest.py
--- a/virtinst/Guest.py
+++ b/virtinst/Guest.py
@@ -474,6 +474,9 @@ class Installer(object):
or guest.disks[0].device != VirtualDisk.DEVICE_DISK:
return True
+ if util.is_vdisk(guest.disks[0].path):
+ return True
+
# Check for the 0xaa55 signature at the end of the MBR
try:
fd = os.open(guest.disks[0].path, os.O_RDONLY)
diff --git a/virtinst/ImageManager.py b/virtinst/ImageManager.py
--- a/virtinst/ImageManager.py
+++ b/virtinst/ImageManager.py
@@ -101,8 +101,13 @@ class ImageInstaller(Guest.Installer):
d = VirtualDisk(p, s,
device = device,
type = VirtualDisk.TYPE_FILE)
- if self.boot_caps.type == "xen" and util.is_blktap_capable():
- d.driver_name = VirtualDisk.DRIVER_TAP
+ if util.is_vdisk(p):
+ d.driver_name = Guest.VirtualDisk.DRIVER_TAP
+ d.driver_type = Guest.VirtualDisk.DRIVER_TAP_VDISK
+ else:
+ if self.boot_caps.type == "xen" and util.is_blktap_capable():
+ d.driver_name = Guest.VirtualDisk.DRIVER_TAP
+
d.target = m.target
DEVICE_DISK = "disk"
DEVICE_CDROM = "cdrom"
@@ -424,7 +426,8 @@ class VirtualDisk(VirtualDevice):
or self.vol_object):
logging.debug("VirtualDisk storage exists.")
- if using_path and os.path.isdir(self.path):
+ if (using_path and os.path.isdir(self.path) and
+ not util.is_vdisk(self.path)):
raise ValueError, _("The path must be a file or a device,"
" not a directory")
self.__set_dev_type()
@@ -476,9 +479,24 @@ class VirtualDisk(VirtualDevice):
self._set_vol_object(self.vol_install.install(mete r=progresscb),
validate=False)
return
- elif self.type == VirtualDisk.TYPE_FILE and self.path is not None
- and not os.path.exists(self.path):
+ elif (self.type == VirtualDisk.TYPE_FILE and self.path is not None
+ and os.path.exists(self.path) and util.is_vdisk(self.path)):
+ self._driverName = self.DRIVER_TAP
+ self._driverType = self.DRIVER_TAP_VDISK
+ return
+ elif (self.type == VirtualDisk.TYPE_FILE and self.path is not None
+ and not os.path.exists(self.path)):
size_bytes = long(self.size * 1024L * 1024L * 1024L)
+
+ if util.is_vdisk(self.path):
+ progresscb.update(1024)
+ if (not util.vdisk_create(self.path, size_bytes, "vmdk",
+ self.sparse)):
+ raise RuntimeError, _("Error creating vdisk %s" % self.path)
+ self._driverName = self.DRIVER_TAP
+ self._driverType = self.DRIVER_TAP_VDISK
+ progresscb.end(self.size)
+ return
if progresscb:
progresscb.start(filename=self.path,size=long(size _bytes),
diff --git a/virtinst/util.py b/virtinst/util.py
--- a/virtinst/util.py
+++ b/virtinst/util.py
@@ -29,6 +29,7 @@ import stat
import stat
import popen2
from sys import stderr
+from subprocess import call
import libvirt
from virtinst import _virtinst as _
@@ -283,17 +284,71 @@ def xml_escape(str):
str = str.replace(">", ">")
return str
def compareMAC(p, q):
"""Compare two MAC addresses"""
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
12-04-2008, 11:11 AM
"Daniel P. Berrange"
Add vdisk support
On Wed, Dec 03, 2008 at 08:31:48PM -0800, john.levon@sun.com wrote:
> # HG changeset patch
> # User john.levon@sun.com
> # Date 1228365031 28800
> # Node ID 152e0bfb277efb24679d7c7f440df0b0f6b21529
> # Parent 35baacfe79834400949ebdba69f952ed873ae442
> Add vdisk support
>
> Add support for the vdisk format used in Solaris.
What exactly is vdisk ? Is this the ZFS based logical volume
management ?
The patch looks reasonable to me anyway, though I'd like to make a note
to get these vdisk operations supported in libvirt storage APIs, since
we'd like to remove all this disk munging code from virtinst APIs and
replace it with libvirt storage APIs.
Daniel
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
12-04-2008, 11:16 AM
John Levon
Add vdisk support
On Thu, Dec 04, 2008 at 12:11:39PM +0000, Daniel P. Berrange wrote:
> > Add vdisk support
> >
> > Add support for the vdisk format used in Solaris.
>
> What exactly is vdisk ? Is this the ZFS based logical volume
> management ?
vdisk is basically our tap implementation and disk management tool. (So
nothing to do with zfs.)
> The patch looks reasonable to me anyway, though I'd like to make a note
> to get these vdisk operations supported in libvirt storage APIs, since
> we'd like to remove all this disk munging code from virtinst APIs and
> replace it with libvirt storage APIs.
Agreed. This was a forward port from old code so we haven't had a chance
to look at the storage APIs at all yet.
regards
john
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
12-09-2008, 02:09 AM
Cole Robinson
Add vdisk support
john.levon@sun.com wrote:
> # HG changeset patch
> # User john.levon@sun.com
> # Date 1228365031 28800
> # Node ID 152e0bfb277efb24679d7c7f440df0b0f6b21529
> # Parent 35baacfe79834400949ebdba69f952ed873ae442
> Add vdisk support
>
> Add support for the vdisk format used in Solaris.
>
> Signed-off-by: John Levon <john.levon@sun.com>
>
> diff --git a/virt-install b/virt-install
> --- a/virt-install
> +++ b/virt-install
> @@ -189,9 +189,13 @@ def get_disk(disk, size, sparse, guest,
> readOnly=readOnly, device=device, bus=bus,
> conn=guest.conn)
> # Default file backed PV guests to tap driver
> - if d.type == virtinst.VirtualDisk.TYPE_FILE
> - and not(hvm) and virtinst.util.is_blktap_capable():
> - d.driver_name = virtinst.VirtualDisk.DRIVER_TAP
> + if d.type == virtinst.VirtualDisk.TYPE_FILE and not(hvm):
> + if virtinst.util.is_blktap_capable():
> + d.driver_name = virtinst.VirtualDisk.DRIVER_TAP
> + elif virtinst.util.is_vdisk(path):
> + d.driver_name = Guest.VirtualDisk.DRIVER_TAP
> + d.driver_type = Guest.VirtualDisk.DRIVER_TAP_VDISK
> +
>
Hmm, this whole block should probably be moved into the VirtualDisk
class, and used to set the default driver if the user doesn't
specify one. But it's not a blocker.
> except ValueError, e:
> fail(_("Error with storage parameters: %s" % str(e)))
>
> diff --git a/virtinst/CloneManager.py b/virtinst/CloneManager.py
> --- a/virtinst/CloneManager.py
> +++ b/virtinst/CloneManager.py
> @@ -19,7 +19,6 @@
> # MA 02110-1301 USA.
>
> import os
> -import stat
> import libxml2
> import logging
> import urlgrabber.progress as progress
> @@ -394,13 +393,9 @@ class CloneDesign(object):
> logging.debug("original device list: %s" % (lst))
>
> for i in lst:
> - mode = os.stat(i)[stat.ST_MODE]
> - if stat.S_ISBLK(mode):
> - size.append(util.blkdev_size(i))
> - typ.append(False)
> - elif stat.S_ISREG(mode):
> - size.append(os.path.getsize(i))
> - typ.append(True)
> + (t, sz) = util.stat_disk(i)
> + typ.append(t)
> + size.append(sz)
>
This, and all the other stat_disk code, seems like a separate cleanup.
Could we get this in a separate patch?
> logging.debug("original device size: %s" % (size))
> logging.debug("original device type: %s" % (typ))
>
> @@ -443,18 +438,9 @@ class CloneDesign(object):
> typ = []
>
> for i in cln_dev_lst:
> - if os.path.exists(i) == False:
> - size.append(0)
> - # if not exists, create file necessary
> - typ.append(True)
> - continue
> - mode = os.stat(i)[stat.ST_MODE]
> - if stat.S_ISBLK(mode):
> - size.append(util.blkdev_size(i))
> - typ.append(False)
> - elif stat.S_ISREG(mode):
> - size.append(os.path.getsize(i))
> - typ.append(True)
> + (t, sz) = util.stat_disk(i)
> + typ.append(t)
> + size.append(sz)
>
> logging.debug("clone device list: %s" % (cln_dev_lst))
> logging.debug("clone device size: %s" % (size))
> @@ -535,6 +521,14 @@ def _do_duplicate(design):
> if src_dev == "/dev/null" or src_dev == dst_dev:
> meter.end(size)
> continue
> +
> + if util.is_vdisk(src_dev) or (os.path.exists(dst_dev) and util.is_vdisk(dst_dev)):
> + if not util.is_vdisk(src_dev) or os.path.exists(dst_dev):
> + raise RuntimeError, _("copying to an existing vdisk is not supported")
> + if not util.vdisk_clone(src_dev, dst_dev):
> + raise RuntimeError, _("failed to clone disk")
> + continue
> +
> #
> # create sparse file
> # if a destination file exists and sparse flg is True,
> diff --git a/virtinst/Guest.py b/virtinst/Guest.py
> --- a/virtinst/Guest.py
> +++ b/virtinst/Guest.py
> @@ -474,6 +474,9 @@ class Installer(object):
> or guest.disks[0].device != VirtualDisk.DEVICE_DISK:
> return True
>
> + if util.is_vdisk(guest.disks[0].path):
> + return True
> +
> # Check for the 0xaa55 signature at the end of the MBR
> try:
> fd = os.open(guest.disks[0].path, os.O_RDONLY)
> diff --git a/virtinst/ImageManager.py b/virtinst/ImageManager.py
> --- a/virtinst/ImageManager.py
> +++ b/virtinst/ImageManager.py
> @@ -101,8 +101,13 @@ class ImageInstaller(Guest.Installer):
> d = VirtualDisk(p, s,
> device = device,
> type = VirtualDisk.TYPE_FILE)
> - if self.boot_caps.type == "xen" and util.is_blktap_capable():
> - d.driver_name = VirtualDisk.DRIVER_TAP
> + if util.is_vdisk(p):
> + d.driver_name = Guest.VirtualDisk.DRIVER_TAP
> + d.driver_type = Guest.VirtualDisk.DRIVER_TAP_VDISK
> + else:
> + if self.boot_caps.type == "xen" and util.is_blktap_capable():
> + d.driver_name = Guest.VirtualDisk.DRIVER_TAP
> +
> d.target = m.target
>
> guest._install_disks.append(d)
> diff --git a/virtinst/VirtualDisk.py b/virtinst/VirtualDisk.py
> --- a/virtinst/VirtualDisk.py
> +++ b/virtinst/VirtualDisk.py
> @@ -68,7 +68,9 @@ class VirtualDisk(VirtualDevice):
> DRIVER_TAP_RAW = "aio"
> DRIVER_TAP_QCOW = "qcow"
> DRIVER_TAP_VMDK = "vmdk"
> - driver_types = [DRIVER_TAP_RAW, DRIVER_TAP_QCOW, DRIVER_TAP_VMDK]
> + DRIVER_TAP_VDISK = "vdisk"
> + driver_types = [DRIVER_TAP_RAW, DRIVER_TAP_QCOW,
> + DRIVER_TAP_VMDK, DRIVER_TAP_VDISK]
>
> DEVICE_DISK = "disk"
> DEVICE_CDROM = "cdrom"
> @@ -424,7 +426,8 @@ class VirtualDisk(VirtualDevice):
> or self.vol_object):
> logging.debug("VirtualDisk storage exists.")
>
> - if using_path and os.path.isdir(self.path):
> + if (using_path and os.path.isdir(self.path) and
> + not util.is_vdisk(self.path)):
> raise ValueError, _("The path must be a file or a device,"
> " not a directory")
> self.__set_dev_type()
> @@ -476,9 +479,24 @@ class VirtualDisk(VirtualDevice):
> self._set_vol_object(self.vol_install.install(mete r=progresscb),
> validate=False)
> return
> - elif self.type == VirtualDisk.TYPE_FILE and self.path is not None
> - and not os.path.exists(self.path):
> + elif (self.type == VirtualDisk.TYPE_FILE and self.path is not None
> + and os.path.exists(self.path) and util.is_vdisk(self.path)):
> + self._driverName = self.DRIVER_TAP
> + self._driverType = self.DRIVER_TAP_VDISK
>
This could use a debug statement stating we are forcing the vdisk
driver.
These two can be moved to VirtualDisk and CloneManager respectively
as non class functions. Please prefix them with an underscore to
mark them as private.
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
12-09-2008, 11:47 AM
John Levon
Add vdisk support
On Mon, Dec 08, 2008 at 10:09:16PM -0500, Cole Robinson wrote:
> > for i in lst:
> > - mode = os.stat(i)[stat.ST_MODE]
> > - if stat.S_ISBLK(mode):
> > - size.append(util.blkdev_size(i))
> > - typ.append(False)
> > - elif stat.S_ISREG(mode):
> > - size.append(os.path.getsize(i))
> > - typ.append(True)
> > + (t, sz) = util.stat_disk(i)
> > + typ.append(t)
> > + size.append(sz)
>
> This, and all the other stat_disk code, seems like a separate cleanup.
> Could we get this in a separate patch?
It's not exactly an exciting change without the vdisk part, but OK.
> > + elif (self.type == VirtualDisk.TYPE_FILE and self.path is not None
> > + and os.path.exists(self.path) and util.is_vdisk(self.path)):
> > + self._driverName = self.DRIVER_TAP
> > + self._driverType = self.DRIVER_TAP_VDISK
> >
>
> This could use a debug statement stating we are forcing the vdisk
> driver.
I'll add a debug statement, but we're not forcing it: if we detect a
vdisk, then we know we will have to use vdisk to read it.
> > +def vdisk_create(path, size, kind, sparse = True):
> > +def vdisk_clone(path, clone):
>
> These two can be moved to VirtualDisk and CloneManager respectively
> as non class functions. Please prefix them with an underscore to
> mark them as private.
OK.
regards
john
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
12-09-2008, 07:44 PM
Add vdisk support
# HG changeset patch
# User john.levon@sun.com
# Date 1228852538 28800
# Node ID 4bf39a99d7e438d9ee331cc8b0e10a3aec40ed24
# Parent 50ca2624e7ef5713153ef85c012326fdae125b7f
Add vdisk support
+def _vdisk_clone(path, clone):
+ path = os.path.expanduser(path)
+ clone = os.path.expanduser(clone)
+ try:
+ rc = subprocess.call([ '/usr/sbin/vdiskadm', 'clone', path, clone ])
+ return rc == 0
+ except OSError, e:
+ return False
+
#
# Now this Cloning method is reading and writing devices.
# For future, there are many cloning methods (e.g. fork snapshot cmd).
@@ -521,6 +531,14 @@ def _do_duplicate(design):
if src_dev == "/dev/null" or src_dev == dst_dev:
meter.end(size)
continue
+
+ if _util.is_vdisk(src_dev) or (os.path.exists(dst_dev) and _util.is_vdisk(dst_dev)):
+ if not _util.is_vdisk(src_dev) or os.path.exists(dst_dev):
+ raise RuntimeError, _("copying to an existing vdisk is not supported")
+ if not _vdisk_clone(src_dev, dst_dev):
+ raise RuntimeError, _("failed to clone disk")
+ continue
+
#
# create sparse file
# if a destination file exists and sparse flg is True,
diff --git a/virtinst/Guest.py b/virtinst/Guest.py
--- a/virtinst/Guest.py
+++ b/virtinst/Guest.py
@@ -474,6 +474,9 @@ class Installer(object):
or guest.disks[0].device != VirtualDisk.DEVICE_DISK:
return True
+ if _util.is_vdisk(guest.disks[0].path):
+ return True
+
# Check for the 0xaa55 signature at the end of the MBR
try:
fd = os.open(guest.disks[0].path, os.O_RDONLY)
diff --git a/virtinst/VirtualDisk.py b/virtinst/VirtualDisk.py
--- a/virtinst/VirtualDisk.py
+++ b/virtinst/VirtualDisk.py
@@ -20,6 +20,7 @@
# MA 02110-1301 USA.
logging.debug("Detected storage as type '%s'" % dtype)
if self.type is not None and dtype != self.type:
@@ -424,7 +448,8 @@ class VirtualDisk(VirtualDevice):
or self.vol_object):
logging.debug("VirtualDisk storage exists.")
- if using_path and os.path.isdir(self.path):
+ if (using_path and os.path.isdir(self.path) and
+ not _util.is_vdisk(self.path)):
raise ValueError, _("The path must be a file or a device,"
" not a directory")
self.__set_dev_type()
@@ -476,13 +501,24 @@ class VirtualDisk(VirtualDevice):
self._set_vol_object(self.vol_install.install(mete r=progresscb),
validate=False)
return
- elif self.type == VirtualDisk.TYPE_FILE and self.path is not None
- and not os.path.exists(self.path):
+ elif (self.type == VirtualDisk.TYPE_FILE and self.path is not None
+ and not os.path.exists(self.path)):
size_bytes = long(self.size * 1024L * 1024L * 1024L)
+def _vdisk_clone(path, clone):
+ path = os.path.expanduser(path)
+ clone = os.path.expanduser(clone)
+ try:
+ rc = subprocess.call([ '/usr/sbin/vdiskadm', 'clone', path, clone ])
+ return rc == 0
+ except OSError, e:
+ return False
+
#
# Now this Cloning method is reading and writing devices.
# For future, there are many cloning methods (e.g. fork snapshot cmd).
@@ -521,6 +531,14 @@ def _do_duplicate(design):
if src_dev == "/dev/null" or src_dev == dst_dev:
meter.end(size)
continue
+
+ if _util.is_vdisk(src_dev) or (os.path.exists(dst_dev) and _util.is_vdisk(dst_dev)):
+ if not _util.is_vdisk(src_dev) or os.path.exists(dst_dev):
+ raise RuntimeError, _("copying to an existing vdisk is not supported")
+ if not _vdisk_clone(src_dev, dst_dev):
+ raise RuntimeError, _("failed to clone disk")
+ continue
+
#
# create sparse file
# if a destination file exists and sparse flg is True,
diff --git a/virtinst/Guest.py b/virtinst/Guest.py
--- a/virtinst/Guest.py
+++ b/virtinst/Guest.py
@@ -474,6 +474,9 @@ class Installer(object):
or guest.disks[0].device != VirtualDisk.DEVICE_DISK:
return True
+ if _util.is_vdisk(guest.disks[0].path):
+ return True
+
# Check for the 0xaa55 signature at the end of the MBR
try:
fd = os.open(guest.disks[0].path, os.O_RDONLY)
diff --git a/virtinst/VirtualDisk.py b/virtinst/VirtualDisk.py
--- a/virtinst/VirtualDisk.py
+++ b/virtinst/VirtualDisk.py
@@ -20,6 +20,7 @@
# MA 02110-1301 USA.
logging.debug("Detected storage as type '%s'" % dtype)
if self.type is not None and dtype != self.type:
@@ -424,7 +448,8 @@ class VirtualDisk(VirtualDevice):
or self.vol_object):
logging.debug("VirtualDisk storage exists.")
- if using_path and os.path.isdir(self.path):
+ if (using_path and os.path.isdir(self.path) and
+ not _util.is_vdisk(self.path)):
raise ValueError, _("The path must be a file or a device,"
" not a directory")
self.__set_dev_type()
@@ -476,13 +501,24 @@ class VirtualDisk(VirtualDevice):
self._set_vol_object(self.vol_install.install(mete r=progresscb),
validate=False)
return
- elif self.type == VirtualDisk.TYPE_FILE and self.path is not None
- and not os.path.exists(self.path):
+ elif (self.type == VirtualDisk.TYPE_FILE and self.path is not None
+ and not os.path.exists(self.path)):
size_bytes = long(self.size * 1024L * 1024L * 1024L)
if progresscb:
progresscb.start(filename=self.path,size=long(size _bytes),
text=_("Creating storage file..."))
+
+ if _util.is_vdisk(self.path):
+ progresscb.update(1024)
+ if (not _vdisk_create(self.path, size_bytes, "vmdk",
+ self.sparse)):
+ raise RuntimeError, _("Error creating vdisk %s" % self.path)
+ self._driverName = self.DRIVER_TAP
+ self._driverType = self.DRIVER_TAP_VDISK
+ progresscb.end(self.size)
+ return
+
fd = None
try:
try:
diff --git a/virtinst/_util.py b/virtinst/_util.py
--- a/virtinst/_util.py
+++ b/virtinst/_util.py
@@ -23,15 +23,31 @@
# not be used by clients.
#
+import commands
import stat
import os
from virtinst import util
+def is_vdisk(path):
+ if not os.path.exists("/usr/sbin/vdiskadm"):
+ return False
+ if not os.path.exists(path):
+ return True
+ if os.path.isdir(path) and
+ os.path.exists(path + "/vdisk.xml"):
+ return True
+ return False
+
def stat_disk(path):
"""Returns the tuple (isreg, size)."""
if not os.path.exists(path):
return True, 0
+
+ if is_vdisk(path):
+ size = int(commands.getoutput(
+ "vdiskadm prop-get -p max-size " + path))
+ return True, size
mode = os.stat(path)[stat.ST_MODE]
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
01-12-2009, 06:47 PM
Cole Robinson
Add vdisk support
john.levon@sun.com wrote:
> # HG changeset patch
> # User john.levon@sun.com
> # Date 1228937605 28800
> # Node ID fa56f55633ea7af14af4dd260a00b020a69a2fea
> # Parent 8638073ea45665c7531931515636a862f684c2a5
> Add vdisk support
>
> Add support for the vdisk format used in Solaris.
>
> Signed-off-by: John Levon <john.levon@sun.com>
>
Applied now.
Thanks,
Cole
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools