Updated Branches: refs/heads/master 447430c3d -> 3989d6c48
kvm: Resize volumes using libvirt This saves us a lot of code and libvirt is probably a better place to do this. libvirt-java now has the support we want, so we can now resize volumes with libvirt. (C)LVM volumes can't be resized using libvirt, so we have to invoke a resize script for that. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3989d6c4 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3989d6c4 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3989d6c4 Branch: refs/heads/master Commit: 3989d6c48118f31464c87c71b6279a11eb13eb35 Parents: 447430c Author: Wido den Hollander <w...@widodh.nl> Authored: Mon Feb 3 17:04:11 2014 +0100 Committer: Wido den Hollander <w...@widodh.nl> Committed: Tue Feb 4 14:26:51 2014 +0100 ---------------------------------------------------------------------- .../kvm/resource/LibvirtComputingResource.java | 55 ++++++++------------ 1 file changed, 21 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3989d6c4/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 19a75d2..6289dea 100755 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -216,6 +216,7 @@ import org.libvirt.DomainInterfaceStats; import org.libvirt.DomainSnapshot; import org.libvirt.LibvirtException; import org.libvirt.NodeInfo; +import org.libvirt.StorageVol; import javax.ejb.Local; import javax.naming.ConfigurationException; @@ -1773,46 +1774,32 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv String path = vol.getPath(); String type = getResizeScriptType(pool, vol); - /** - * RBD volumes can't be resized via a Bash script or via libvirt - * - * libvirt-java doesn't implemented resizing volumes, so we have to do this manually - * - * Future fix would be to hand this over to libvirt - */ - if (pool.getType() == StoragePoolType.RBD) { - try { - Rados r = new Rados(pool.getAuthUserName()); - r.confSet("mon_host", pool.getSourceHost() + ":" + pool.getSourcePort()); - r.confSet("key", pool.getAuthSecret()); - r.confSet("client_mount_timeout", "30"); - r.connect(); - s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host")); + if (type == null) { + return new ResizeVolumeAnswer(cmd, false, "Unsupported volume format: pool type '" + pool.getType() + "' and volume format '" + vol.getFormat() + "'"); + } else if (type.equals("QCOW2") && shrinkOk) { + return new ResizeVolumeAnswer(cmd, false, "Unable to shrink volumes of type " + type); + } - IoCTX io = r.ioCtxCreate(pool.getSourceDir()); - Rbd rbd = new Rbd(io); - RbdImage image = rbd.open(vol.getName()); + s_logger.debug("Resizing volume: " + path + "," + currentSize + "," + newSize + "," + type + "," + vmInstanceName + "," + shrinkOk); - s_logger.debug("Resizing RBD volume " + vol.getName() + " to " + newSize + " bytes"); - image.resize(newSize); - rbd.close(image); + /* libvirt doesn't support resizing (C)LVM devices, so we have to do that via a Bash script */ + if (pool.getType() != StoragePoolType.CLVM) { + s_logger.debug("Volume " + path + " can be resized by libvirt. Asking libvirt to resize the volume."); + try { + Connect conn = LibvirtConnection.getConnection(); + StorageVol v = conn.storageVolLookupByPath(path); - r.ioCtxDestroy(io); - s_logger.debug("Succesfully resized RBD volume " + vol.getName() + " to " + newSize + " bytes"); - } catch (RadosException e) { - return new ResizeVolumeAnswer(cmd, false, e.toString()); - } catch (RbdException e) { + int flags = 1; + if (shrinkOk) { + flags = 4; + } + + v.resize(newSize, flags); + } catch (LibvirtException e) { return new ResizeVolumeAnswer(cmd, false, e.toString()); } } else { - if (type == null) { - return new ResizeVolumeAnswer(cmd, false, "Unsupported volume format: pool type '" + pool.getType() + "' and volume format '" + vol.getFormat() + "'"); - } else if (type.equals("QCOW2") && shrinkOk) { - return new ResizeVolumeAnswer(cmd, false, "Unable to shrink volumes of type " + type); - } - - s_logger.debug("got to the stage where we execute the volume resize, params:" + path + "," + currentSize + "," + newSize + "," + type + "," + - vmInstanceName + "," + shrinkOk); + s_logger.debug("Volume " + path + " is of the type LVM and can not be resized using libvirt. Invoking resize script."); final Script resizecmd = new Script(_resizeVolumePath, _cmdsTimeout, s_logger); resizecmd.add("-s", String.valueOf(newSize)); resizecmd.add("-c", String.valueOf(currentSize));