protected String getMountPoint(NfsStoragePool storagePool) { StoragePool pool = null; String poolName = null; try { pool = LibvirtConnection.getConnection().storagePoolLookupByUUIDString(storagePool._poolUUID); if (pool != null) { StoragePoolInfo spi = pool.getInfo(); if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) { pool.create(0); } else { /* * Sometimes, the mount point is lost, even libvirt thinks * the storage pool still running */ } poolName = pool.getName(); } } catch (LibvirtException e) { s_logger.debug("Ignoring libvirt error.", e); } finally { try { if (pool != null) { pool.free(); } } catch (LibvirtException e) { s_logger.debug("Ignoring libvirt error.", e); } } return checkingMountPoint(storagePool, poolName); }
@Override public List<KVMPhysicalDisk> listPhysicalDisks(String storagePoolUuid, KVMStoragePool pool) { LibvirtStoragePool libvirtPool = (LibvirtStoragePool)pool; StoragePool virtPool = libvirtPool.getPool(); List<KVMPhysicalDisk> disks = new ArrayList<KVMPhysicalDisk>(); try { String[] vols = virtPool.listVolumes(); for (String volName : vols) { KVMPhysicalDisk disk = getPhysicalDisk(volName, pool); disks.add(disk); } return disks; } catch (LibvirtException e) { throw new CloudRuntimeException(e.toString()); } }
public StorageVol createVolume(Connect conn, StoragePool pool, String uuid, long size, VolumeFormat format) throws LibvirtException { LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), size, format, null, null); s_logger.debug(volDef.toString()); return pool.storageVolCreateXML(volDef.toString(), 0); }
private StoragePool createCLVMStoragePool(Connect conn, String uuid, String host, String path) { String volgroupPath = "/dev/" + path; String volgroupName = path; volgroupName = volgroupName.replaceFirst("/", ""); LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(PoolType.LOGICAL, volgroupName, uuid, host, volgroupPath, volgroupPath); StoragePool sp = null; try { s_logger.debug(spd.toString()); sp = conn.storagePoolCreateXML(spd.toString(), 0); return sp; } catch (LibvirtException e) { s_logger.error(e.toString()); if (sp != null) { try { if (sp.isPersistent() == 1) { sp.destroy(); sp.undefine(); } else { sp.destroy(); } sp.free(); } catch (LibvirtException l) { s_logger.debug("Failed to define clvm storage pool with: " + l.toString()); } } return null; } }
public StorageVol getVolume(StoragePool pool, String volName) { StorageVol vol = null; try { vol = pool.storageVolLookupByName(volName); } catch (LibvirtException e) { s_logger.debug("Could not find volume " + volName + ": " + e.getMessage()); } /** * The volume was not found in the storage pool * This can happen when a volume has just been created on a different host and * since then the libvirt storage pool has not been refreshed. */ if (vol == null) { try { s_logger.debug("Refreshing storage pool " + pool.getName()); refreshPool(pool); } catch (LibvirtException e) { s_logger.debug("Failed to refresh storage pool: " + e.getMessage()); } try { vol = pool.storageVolLookupByName(volName); s_logger.debug("Found volume " + volName + " in storage pool " + pool.getName() + " after refreshing the pool"); } catch (LibvirtException e) { throw new CloudRuntimeException("Could not find volume " + volName + ": " + e.getMessage()); } } return vol; }
if (sp != null && sp.isActive() == 0) { sp.undefine(); sp = null; s_logger.info("Found existing defined storage pool " + name + ". It wasn't running, so we undefined it."); s_logger.debug("Storage pool utilizing path '" + path + "' already exists as pool " + poolname + ", undefining so we can re-define with correct name " + name); if (p.isPersistent() == 1) { p.destroy(); p.undefine(); } else { p.destroy(); if (sp.isActive() == 0) { s_logger.debug("Attempting to activate pool " + name); sp.create(0);
private static StorageVol findVolumeInPool(StoragePool sp, String image) throws LibvirtException { for (String v : sp.listVolumes()) { StorageVol vol = sp.storageVolLookupByName(v); if (vol.getPath().equals(image)) { log.debug("Found volume '{}' for image '{}'", vol.getName(), image); return vol; } } return null; }
storage = conn.storagePoolLookupByUUIDString(uuid); if (storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) { s_logger.warn("Storage pool " + uuid + " is not in running state. Attempting to start it."); storage.create(0); LibvirtStoragePool pool = new LibvirtStoragePool(uuid, storage.getName(), type, this, storage); pool.refresh(); pool.setCapacity(storage.getInfo().capacity); pool.setUsed(storage.getInfo().allocation); pool.setAvailable(storage.getInfo().available); " Capacity: " + storage.getInfo().capacity + " Used: " + storage.getInfo().allocation + " Available: " + storage.getInfo().available);
StoragePoolInfo poolinfo = virtPool.getInfo(); volCapacity = poolinfo.available; s_logger.debug(volDef.toString()); vol = virtPool.storageVolCreateXML(volDef.toString(), 0);
public StorageVol getVolume(StoragePool pool, String volName) { StorageVol vol = null; try { vol = pool.storageVolLookupByName(volName); } catch (LibvirtException e) { s_logger.debug("Can't find volume: " + e.toString()); } if (vol == null) { try { refreshPool(pool); } catch (LibvirtException e) { s_logger.debug("failed to refresh pool: " + e.toString()); } s_logger.debug("no volume is present on the pool, creating a new one"); } return vol; }
public static StoragePool findStoragePoolWithFile(Connect conn, String path) throws LibvirtException { for (String spn : conn.listStoragePools()) { StoragePool sp = conn.storagePoolLookupByName(spn); if (findVolumeInPool(sp, path) != null) { log.debug("Found storage pool '{}' for image '{}'", sp.getName(), path); return sp; } } throw new LibvirtRuntimeException("pool with image " + path + " not found"); }
public boolean disconnectPhysicalDisk(KVMStoragePool pool, String mountpoint) throws LibvirtException { LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool; StoragePool sp = libvirtPool.getPool(); // destroy the pool sp.destroy(); return true; }
public void storagePoolRefresh(StoragePool pool) { try { synchronized (getStoragePool(pool.getUUIDString())) { refreshPool(pool); } } catch (LibvirtException e) { s_logger.debug("refresh storage pool failed: " + e.toString()); } }
continue; } else if (storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) { s_logger.debug("Libvirt storage pool " + uuid + " found, but not running, removing from HA list");
StorageVol vol = getVolume(libvirtPool.getPool(), volumeUuid); KVMPhysicalDisk disk; LibvirtStorageVolumeDef voldef = getStorageVolumeDef(libvirtPool.getPool().getConnect(), vol); disk = new KVMPhysicalDisk(vol.getPath(), vol.getName(), pool); disk.setSize(vol.getInfo().allocation);
private StoragePool createSharedStoragePool(Connect conn, String uuid, String host, String path) { String mountPoint = path; if (!_storageLayer.exists(mountPoint)) { s_logger.error(mountPoint + " does not exists. Check local.storage.path in agent.properties."); return null; } LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(PoolType.DIR, uuid, uuid, host, path, path); StoragePool sp = null; try { s_logger.debug(spd.toString()); sp = conn.storagePoolCreateXML(spd.toString(), 0); return sp; } catch (LibvirtException e) { s_logger.error(e.toString()); if (sp != null) { try { if (sp.isPersistent() == 1) { sp.destroy(); sp.undefine(); } else { sp.destroy(); } sp.free(); } catch (LibvirtException l) { s_logger.debug("Failed to define shared mount point storage pool with: " + l.toString()); } } return null; } }
/** Look up a disk image's {@link StorageVol} in the {@link StoragePool}s attached to connection. */ public static StorageVol findVolume(Connect connection, String path) throws LibvirtException { log.debug("Looking up StorageVolume for path '{}'", path); for (String s : connection.listStoragePools()) { StoragePool sp = connection.storagePoolLookupByName(s); for (String v : sp.listVolumes()) { StorageVol vol = sp.storageVolLookupByName(v); if (vol.getPath().equals(path)) { log.debug("Found volume '{}' for path '{}'", vol.getName(), path); return vol; } } } throw new LibvirtRuntimeException("no volume found for path " + path); }
if (sp.isPersistent() == 1) { sp.destroy(); sp.undefine(); } else { sp.destroy(); sp.free(); if (s != null) { s.undefine();
public StorageVol copyVolume(StoragePool destPool, LibvirtStorageVolumeDef destVol, StorageVol srcVol, int timeout) throws LibvirtException { StorageVol vol = destPool.storageVolCreateXML(destVol.toString(), 0); String srcPath = srcVol.getKey(); String destPath = vol.getKey(); Script.runSimpleBashScript("cp " + srcPath + " " + destPath, timeout); return vol; }