@@ -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,18 @@ private String resizeVolume(DataObject data, String path, VolumeObject vol) {
427428 return err ;
428429 }
429430
431+ private void updateVolumeWithTheNewSize (VolumeObject vol , ResizeVolumePayload payload ) {
432+
433+ vol .setSize (payload .newSize );
434+ vol .update ();
435+ if (payload .newMaxIops != null ) {
436+ VolumeVO volume = volumeDao .findById (vol .getId ());
437+ volume .setMaxIops (payload .newMaxIops );
438+ volumeDao .update (volume .getId (), volume );
439+ }
440+ updateStoragePool (vol .getPoolId (), payload .newSize - vol .getSize ());
441+ }
442+
430443 private String notifyQemuForTheNewSize (DataObject data , String err , VolumeObject vol , ResizeVolumePayload payload )
431444 throws StorageUnavailableException {
432445 StoragePool pool = (StoragePool )data .getDataStore ();
@@ -455,37 +468,41 @@ private String updateStorPoolVolume(VolumeObject vol, ResizeVolumePayload payloa
455468 }
456469 SpApiResponse resp = new SpApiResponse ();
457470 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 );
471+ resp = updateVolumeByStorPoolQoS (payload , conn , name , tier , template );
462472 } 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 );
473+ resp = updateVolumeByOffering (vol , payload , conn , name );
472474 }
473475 if (resp .getError () != null ) {
474476 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 ());
485477 }
486478 return err ;
487479 }
488480
481+ private static SpApiResponse updateVolumeByStorPoolQoS (ResizeVolumePayload payload , SpConnectionDesc conn , String name , String tier , String template ) {
482+
483+ SpApiResponse resp ;
484+ Map <String , String > tags = StorPoolHelper .addStorPoolTags (null , null , null , null , tier );
485+ StorPoolVolumeDef spVolume = new StorPoolVolumeDef (name , payload .newSize , tags , null , null , template , null , null ,
486+ payload .shrinkOk );
487+ resp = StorPoolUtil .volumeUpdate (spVolume , conn );
488+ return resp ;
489+ }
490+
491+ private static SpApiResponse updateVolumeByOffering (VolumeObject vol , ResizeVolumePayload payload , SpConnectionDesc conn , String name ) {
492+
493+ SpApiResponse resp ;
494+ long maxIops = payload .newMaxIops == null ? Long .valueOf (0 ) : payload .newMaxIops ;
495+
496+ StorPoolVolumeDef spVolume = new StorPoolVolumeDef (name , payload .newSize , null , null , maxIops , null , null , null ,
497+ payload .shrinkOk );
498+ StorPoolUtil .spLog (
499+ "StorpoolPrimaryDataStoreDriverImpl.resize: name=%s, uuid=%s, oldSize=%d, newSize=%s, shrinkOk=%s, maxIops=%s" ,
500+ name , vol .getUuid (), vol .getSize (), payload .newSize , payload .shrinkOk , maxIops );
501+
502+ resp = StorPoolUtil .volumeUpdate (spVolume , conn );
503+ return resp ;
504+ }
505+
489506 @ Override
490507 public void deleteAsync (DataStore dataStore , DataObject data , AsyncCompletionCallback <CommandResult > callback ) {
491508 String err = null ;
0 commit comments