From d88b30fdf7a06a24b23c6ac4fb5f8978a5442918 Mon Sep 17 00:00:00 2001 From: Wido den Hollander Date: Tue, 28 Mar 2017 14:22:58 +0200 Subject: [PATCH] rbd: Use libvirt to create new volumes and not rados-java Since libvirt 1.2.2 libvirt will properly create volumes using RBD format 2. We can use libvirt to creates the volumes which strips a bit of code from the CloudStack Agent's responsbility. RBD format 2 is already used by all volumes created by CloudStack. This format is the most recent format of RBD and is still actively being developed. This removes the support for Ubuntu 12.04 as that does not have the proper libvirt version available. Signed-off-by: Wido den Hollander --- debian/control | 3 +- .../kvm/storage/LibvirtStorageAdaptor.java | 78 ++++--------------- 2 files changed, 19 insertions(+), 62 deletions(-) diff --git a/debian/control b/debian/control index fed6622c95da..f4023254c2c7 100644 --- a/debian/control +++ b/debian/control @@ -22,7 +22,8 @@ Description: CloudStack server library Package: cloudstack-agent Architecture: all -Depends: ${python:Depends}, openjdk-8-jre-headless | java8-runtime-headless | java8-runtime, cloudstack-common (= ${source:Version}), lsb-base (>= 4.0), libcommons-daemon-java, openssh-client, qemu-kvm (>= 1.0), libvirt-bin (>= 0.9.8), uuid-runtime, iproute, ebtables, vlan, jsvc, ipset, python-libvirt, ethtool, iptables, lsb-release, init-system-helpers (>= 1.14~) +Depends: ${python:Depends}, openjdk-8-jre-headless | java8-runtime-headless | java8-runtime, cloudstack-common (= ${source:Version}), lsb-base (>= 4.0), libcommons-daemon-java, openssh-client, qemu-kvm (>= 1.0), libvirt-bin (>= 1.2.2), uuid-runtime, iproute, ebtables, vlan, jsvc, ipset, python-libvirt, ethtool, iptables, lsb-release, init-system-helpers (>= 1.14~) +Recommends: init-system-helpers Conflicts: cloud-agent, cloud-agent-libs, cloud-agent-deps, cloud-agent-scripts Description: CloudStack agent The CloudStack agent is in charge of managing shared computing resources in diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java index 6e8ba30ea4aa..96bb068c24f1 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java @@ -659,25 +659,25 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, s_logger.info("Attempting to create volume " + name + " (" + pool.getType().toString() + ") in pool " + pool.getUuid() + " with size " + size); - switch (pool.getType()){ - case RBD: - return createPhysicalDiskOnRBD(name, pool, format, provisioningType, size); - case NetworkFilesystem: - case Filesystem: - switch (format){ - case QCOW2: - return createPhysicalDiskByQemuImg(name, pool, format, provisioningType, size); - case RAW: - return createPhysicalDiskByQemuImg(name, pool, format, provisioningType, size); - case DIR: - return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); - case TAR: + switch (pool.getType()) { + case RBD: return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); + case NetworkFilesystem: + case Filesystem: + switch (format) { + case QCOW2: + return createPhysicalDiskByQemuImg(name, pool, format, provisioningType, size); + case RAW: + return createPhysicalDiskByQemuImg(name, pool, format, provisioningType, size); + case DIR: + return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); + case TAR: + return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); + default: + throw new CloudRuntimeException("Unexpected disk format is specified."); + } default: - throw new CloudRuntimeException("Unexpected disk format is specified."); - } - default: - return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); + return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); } } @@ -748,50 +748,6 @@ private KVMPhysicalDisk createPhysicalDiskByQemuImg(String name, KVMStoragePool return disk; } - private KVMPhysicalDisk createPhysicalDiskOnRBD(String name, KVMStoragePool pool, - PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) { - String volPath = null; - - /** - * To have RBD function properly we want RBD images of format 2 - * libvirt currently defaults to format 1 - * - * This has been fixed in libvirt 1.2.2, but that's not upstream - * in all distributions - * - * For that reason we use the native RBD bindings to create the - * RBD image until libvirt creates RBD format 2 by default - */ - - try { - s_logger.info("Creating RBD image " + pool.getSourceDir() + "/" + name + " with size " + size); - - 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")); - - IoCTX io = r.ioCtxCreate(pool.getSourceDir()); - Rbd rbd = new Rbd(io); - rbd.create(name, size, rbdFeatures, rbdOrder); - - r.ioCtxDestroy(io); - } catch (RadosException e) { - throw new CloudRuntimeException(e.toString()); - } catch (RbdException e) { - throw new CloudRuntimeException(e.toString()); - } - - volPath = pool.getSourceDir() + "/" + name; - KVMPhysicalDisk disk = new KVMPhysicalDisk(volPath, name, pool); - disk.setFormat(PhysicalDiskFormat.RAW); - disk.setSize(size); - disk.setVirtualSize(size); - return disk; - } - @Override public boolean connectPhysicalDisk(String name, KVMStoragePool pool, Map details) { // this is for managed storage that needs to prep disks prior to use