6060import org .libvirt .DomainInterfaceStats ;
6161import org .libvirt .LibvirtException ;
6262import org .libvirt .NodeInfo ;
63- import org .libvirt .StorageVol ;
6463
6564import com .cloud .agent .api .Answer ;
6665import com .cloud .agent .api .Command ;
8079import com .cloud .agent .api .routing .IpAssocVpcCommand ;
8180import com .cloud .agent .api .routing .NetworkElementCommand ;
8281import com .cloud .agent .api .routing .SetSourceNatCommand ;
83- import com .cloud .agent .api .storage .ResizeVolumeAnswer ;
84- import com .cloud .agent .api .storage .ResizeVolumeCommand ;
8582import com .cloud .agent .api .to .DataStoreTO ;
8683import com .cloud .agent .api .to .DataTO ;
8784import com .cloud .agent .api .to .DiskTO ;
8885import com .cloud .agent .api .to .IpAddressTO ;
8986import com .cloud .agent .api .to .NfsTO ;
9087import com .cloud .agent .api .to .NicTO ;
91- import com .cloud .agent .api .to .StorageFilerTO ;
9288import com .cloud .agent .api .to .VirtualMachineTO ;
9389import com .cloud .agent .resource .virtualnetwork .VirtualRouterDeployer ;
9490import com .cloud .agent .resource .virtualnetwork .VirtualRoutingResource ;
@@ -408,6 +404,10 @@ public String getOvsPvlanVmPath() {
408404 return _ovsPvlanVmPath ;
409405 }
410406
407+ public String getResizeVolumePath () {
408+ return _resizeVolumePath ;
409+ }
410+
411411 private static final class KeyValueInterpreter extends OutputInterpreter {
412412 private final Map <String , String > map = new HashMap <String , String >();
413413
@@ -1259,8 +1259,6 @@ public Answer executeRequest(final Command cmd) {
12591259 return execute ((StartCommand )cmd );
12601260 } else if (cmd instanceof NetworkElementCommand ) {
12611261 return _virtRouterResource .executeRequest ((NetworkElementCommand )cmd );
1262- } else if (cmd instanceof ResizeVolumeCommand ) {
1263- return execute ((ResizeVolumeCommand )cmd );
12641262 } else if (cmd instanceof StorageSubSystemCommand ) {
12651263 return storageHandler .handleStorageCommands ((StorageSubSystemCommand )cmd );
12661264 } else {
@@ -1401,7 +1399,7 @@ public KVMPhysicalDisk templateToPrimaryDownload(final String templateUrl, final
14011399 }
14021400 }
14031401
1404- private String getResizeScriptType (final KVMStoragePool pool , final KVMPhysicalDisk vol ) {
1402+ public String getResizeScriptType (final KVMStoragePool pool , final KVMPhysicalDisk vol ) {
14051403 final StoragePoolType poolType = pool .getType ();
14061404 final PhysicalDiskFormat volFormat = vol .getFormat ();
14071405
@@ -1417,92 +1415,6 @@ private String getResizeScriptType(final KVMStoragePool pool, final KVMPhysicalD
14171415 throw new CloudRuntimeException ("Cannot determine resize type from pool type " + pool .getType ());
14181416 }
14191417
1420- /* uses a local script now, eventually support for virStorageVolResize() will maybe work on
1421- qcow2 and lvm and we can do this in libvirt calls */
1422- public Answer execute (final ResizeVolumeCommand cmd ) {
1423- final String volid = cmd .getPath ();
1424- final long newSize = cmd .getNewSize ();
1425- final long currentSize = cmd .getCurrentSize ();
1426- final String vmInstanceName = cmd .getInstanceName ();
1427- final boolean shrinkOk = cmd .getShrinkOk ();
1428- final StorageFilerTO spool = cmd .getPool ();
1429- final String notifyOnlyType = "NOTIFYONLY" ;
1430-
1431- if ( currentSize == newSize ) {
1432- // nothing to do
1433- s_logger .info ("No need to resize volume: current size " + currentSize + " is same as new size " + newSize );
1434- return new ResizeVolumeAnswer (cmd , true , "success" , currentSize );
1435- }
1436-
1437- try {
1438- KVMStoragePool pool = _storagePoolMgr .getStoragePool (spool .getType (), spool .getUuid ());
1439- final KVMPhysicalDisk vol = pool .getPhysicalDisk (volid );
1440- final String path = vol .getPath ();
1441- String type = getResizeScriptType (pool , vol );
1442-
1443- if (pool .getType () != StoragePoolType .RBD ) {
1444- if (type .equals ("QCOW2" ) && shrinkOk ) {
1445- return new ResizeVolumeAnswer (cmd , false , "Unable to shrink volumes of type " + type );
1446- }
1447- } else {
1448- s_logger .debug ("Volume " + path + " is on a RBD storage pool. No need to query for additional information." );
1449- }
1450-
1451- s_logger .debug ("Resizing volume: " + path + "," + currentSize + "," + newSize + "," + type + "," + vmInstanceName + "," + shrinkOk );
1452-
1453- /* libvirt doesn't support resizing (C)LVM devices, and corrupts QCOW2 in some scenarios, so we have to do these via Bash script */
1454- if (pool .getType () != StoragePoolType .CLVM && vol .getFormat () != PhysicalDiskFormat .QCOW2 ) {
1455- s_logger .debug ("Volume " + path + " can be resized by libvirt. Asking libvirt to resize the volume." );
1456- try {
1457- final Connect conn = LibvirtConnection .getConnection ();
1458- final StorageVol v = conn .storageVolLookupByPath (path );
1459- int flags = 0 ;
1460-
1461- if (conn .getLibVirVersion () > 1001000 && vol .getFormat () == PhysicalDiskFormat .RAW && pool .getType () != StoragePoolType .RBD ) {
1462- flags = 1 ;
1463- }
1464- if (shrinkOk ) {
1465- flags = 4 ;
1466- }
1467-
1468- v .resize (newSize , flags );
1469- type = notifyOnlyType ;
1470- } catch (final LibvirtException e ) {
1471- return new ResizeVolumeAnswer (cmd , false , e .toString ());
1472- }
1473- }
1474- s_logger .debug ("Invoking resize script to handle type " + type );
1475- final Script resizecmd = new Script (_resizeVolumePath , _cmdsTimeout , s_logger );
1476- resizecmd .add ("-s" , String .valueOf (newSize ));
1477- resizecmd .add ("-c" , String .valueOf (currentSize ));
1478- resizecmd .add ("-p" , path );
1479- resizecmd .add ("-t" , type );
1480- resizecmd .add ("-r" , String .valueOf (shrinkOk ));
1481- resizecmd .add ("-v" , vmInstanceName );
1482- final String result = resizecmd .execute ();
1483-
1484- if (result != null ) {
1485- if (type .equals (notifyOnlyType )) {
1486- return new ResizeVolumeAnswer (cmd , true , "Resize succeeded, but need reboot to notify guest" );
1487- } else {
1488- return new ResizeVolumeAnswer (cmd , false , result );
1489- }
1490- }
1491-
1492- /* fetch new size as seen from libvirt, don't want to assume anything */
1493- pool = _storagePoolMgr .getStoragePool (spool .getType (), spool .getUuid ());
1494- pool .refresh ();
1495- final long finalSize = pool .getPhysicalDisk (volid ).getVirtualSize ();
1496- s_logger .debug ("after resize, size reports as " + finalSize + ", requested " + newSize );
1497- return new ResizeVolumeAnswer (cmd , true , "success" , finalSize );
1498- } catch (final CloudRuntimeException e ) {
1499- final String error = "Failed to resize volume: " + e .getMessage ();
1500- s_logger .debug (error );
1501- return new ResizeVolumeAnswer (cmd , false , error );
1502- }
1503-
1504- }
1505-
15061418 private String getBroadcastUriFromBridge (final String brName ) {
15071419 final String pif = matchPifFileInDirectory (brName );
15081420 final Pattern pattern = Pattern .compile ("(\\ D+)(\\ d+)(\\ D*)(\\ d*)" );
0 commit comments