@@ -412,13 +412,14 @@ private String resizeVolume(DataObject data, String path, VolumeObject vol) {
412412 if (err == null && needResize ) {
413413 err = notifyQemuForTheNewSize (data , err , vol , payload );
414414 }
415-
416415 if (err != null ) {
417416 // try restoring volume to its initial size
418417 SpApiResponse response = StorPoolUtil .volumeUpdate (name , oldSize , true , oldMaxIops , conn );
419418 if (response .getError () != null ) {
420419 logger .debug (String .format ("Could not resize StorPool volume %s back to its original size. Error: %s" , name , response .getError ()));
421420 }
421+ } else {
422+ updateVolumeWithTheNewSize (vol , payload );
422423 }
423424 } catch (Exception e ) {
424425 logger .debug ("sending resize command failed" , e );
@@ -427,6 +428,17 @@ private String resizeVolume(DataObject data, String path, VolumeObject vol) {
427428 return err ;
428429 }
429430
431+ private void updateVolumeWithTheNewSize (VolumeObject vol , ResizeVolumePayload payload ) {
432+ vol .setSize (payload .newSize );
433+ vol .update ();
434+ if (payload .newMaxIops != null ) {
435+ VolumeVO volume = volumeDao .findById (vol .getId ());
436+ volume .setMaxIops (payload .newMaxIops );
437+ volumeDao .update (volume .getId (), volume );
438+ }
439+ updateStoragePool (vol .getPoolId (), payload .newSize - vol .getSize ());
440+ }
441+
430442 private String notifyQemuForTheNewSize (DataObject data , String err , VolumeObject vol , ResizeVolumePayload payload )
431443 throws StorageUnavailableException {
432444 StoragePool pool = (StoragePool )data .getDataStore ();
@@ -455,37 +467,34 @@ private String updateStorPoolVolume(VolumeObject vol, ResizeVolumePayload payloa
455467 }
456468 SpApiResponse resp = new SpApiResponse ();
457469 if (tier != null || template != null ) {
458- Map <String , String > tags = StorPoolHelper .addStorPoolTags (null , null , null , null , tier );
459- StorPoolVolumeDef spVolume = new StorPoolVolumeDef (name , payload .newSize , tags , null , null , template , null , null ,
460- payload .shrinkOk );
461- resp = StorPoolUtil .volumeUpdate (spVolume , conn );
470+ resp = updateVolumeByStorPoolQoS (payload , conn , name , tier , template );
462471 } else {
463- long maxIops = payload .newMaxIops == null ? Long .valueOf (0 ) : payload .newMaxIops ;
464-
465- StorPoolVolumeDef spVolume = new StorPoolVolumeDef (name , payload .newSize , null , null , maxIops , null , null , null ,
466- payload .shrinkOk );
467- StorPoolUtil .spLog (
468- "StorpoolPrimaryDataStoreDriverImpl.resize: name=%s, uuid=%s, oldSize=%d, newSize=%s, shrinkOk=%s, maxIops=%s" ,
469- name , vol .getUuid (), vol .getSize (), payload .newSize , payload .shrinkOk , maxIops );
470-
471- resp = StorPoolUtil .volumeUpdate (spVolume , conn );
472+ resp = updateVolumeByOffering (vol , payload , conn , name );
472473 }
473474 if (resp .getError () != null ) {
474475 err = String .format ("Could not resize StorPool volume %s. Error: %s" , name , resp .getError ());
475- } else {
476- vol .setSize (payload .newSize );
477- vol .update ();
478- if (payload .newMaxIops != null ) {
479- VolumeVO volume = volumeDao .findById (vol .getId ());
480- volume .setMaxIops (payload .newMaxIops );
481- volumeDao .update (volume .getId (), volume );
482- }
483-
484- updateStoragePool (vol .getPoolId (), payload .newSize - vol .getSize ());
485476 }
486477 return err ;
487478 }
488479
480+ private static SpApiResponse updateVolumeByStorPoolQoS (ResizeVolumePayload payload , SpConnectionDesc conn , String name , String tier , String template ) {
481+ Map <String , String > tags = StorPoolHelper .addStorPoolTags (null , null , null , null , tier );
482+ StorPoolVolumeDef spVolume = new StorPoolVolumeDef (name , payload .newSize , tags , null , null , template , null , null ,
483+ payload .shrinkOk );
484+ return StorPoolUtil .volumeUpdate (spVolume , conn );
485+ }
486+
487+ private static SpApiResponse updateVolumeByOffering (VolumeObject vol , ResizeVolumePayload payload , SpConnectionDesc conn , String name ) {
488+ long maxIops = payload .newMaxIops == null ? Long .valueOf (0 ) : payload .newMaxIops ;
489+
490+ StorPoolVolumeDef spVolume = new StorPoolVolumeDef (name , payload .newSize , null , null , maxIops , null , null , null ,
491+ payload .shrinkOk );
492+ StorPoolUtil .spLog (
493+ "StorpoolPrimaryDataStoreDriverImpl.resize: name=%s, uuid=%s, oldSize=%d, newSize=%s, shrinkOk=%s, maxIops=%s" ,
494+ name , vol .getUuid (), vol .getSize (), payload .newSize , payload .shrinkOk , maxIops );
495+ return StorPoolUtil .volumeUpdate (spVolume , conn );
496+ }
497+
489498 @ Override
490499 public void deleteAsync (DataStore dataStore , DataObject data , AsyncCompletionCallback <CommandResult > callback ) {
491500 String err = null ;
0 commit comments