@@ -7975,17 +7975,25 @@ public Pair<UserVmVO, Volume> doInTransaction(final TransactionStatus status) th
79757975 private void updateVolume (Volume vol , VMTemplateVO template , UserVmVO userVm , DiskOffering diskOffering , Map <String , String > details ) {
79767976 VolumeVO resizedVolume = (VolumeVO ) vol ;
79777977
7978- if (userVmDetailsDao .findDetail (userVm .getId (), VmDetailConstants .ROOT_DISK_SIZE ) == null && !vol .getSize ().equals (template .getSize ())) {
7979- if (template .getSize () != null ) {
7978+ if (template != null && template .getSize () != null ) {
7979+ UserVmDetailVO vmRootDiskSizeDetail = userVmDetailsDao .findDetail (userVm .getId (), VmDetailConstants .ROOT_DISK_SIZE );
7980+ if (vmRootDiskSizeDetail == null ) {
79807981 resizedVolume .setSize (template .getSize ());
7982+ } else {
7983+ long rootDiskSize = Long .parseLong (vmRootDiskSizeDetail .getValue ()) * GiB_TO_BYTES ;
7984+ if (template .getSize () >= rootDiskSize ) {
7985+ resizedVolume .setSize (template .getSize ());
7986+ userVmDetailsDao .remove (vmRootDiskSizeDetail .getId ());
7987+ } else {
7988+ resizedVolume .setSize (rootDiskSize );
7989+ }
79817990 }
79827991 }
79837992
79847993 if (diskOffering != null ) {
79857994 resizedVolume .setDiskOfferingId (diskOffering .getId ());
7986- resizedVolume .setSize (diskOffering .getDiskSize ());
7987- if (diskOffering .isCustomized ()) {
7988- resizedVolume .setSize (vol .getSize ());
7995+ if (!diskOffering .isCustomized ()) {
7996+ resizedVolume .setSize (diskOffering .getDiskSize ());
79897997 }
79907998 if (diskOffering .getMinIops () != null ) {
79917999 resizedVolume .setMinIops (diskOffering .getMinIops ());
@@ -7999,6 +8007,14 @@ private void updateVolume(Volume vol, VMTemplateVO template, UserVmVO userVm, Di
79998007 if (StringUtils .isNumeric (details .get (VmDetailConstants .ROOT_DISK_SIZE ))) {
80008008 Long rootDiskSize = Long .parseLong (details .get (VmDetailConstants .ROOT_DISK_SIZE )) * GiB_TO_BYTES ;
80018009 resizedVolume .setSize (rootDiskSize );
8010+ UserVmDetailVO vmRootDiskSizeDetail = userVmDetailsDao .findDetail (userVm .getId (), VmDetailConstants .ROOT_DISK_SIZE );
8011+ if (vmRootDiskSizeDetail != null ) {
8012+ vmRootDiskSizeDetail .setValue (details .get (VmDetailConstants .ROOT_DISK_SIZE ));
8013+ userVmDetailsDao .update (vmRootDiskSizeDetail .getId (), vmRootDiskSizeDetail );
8014+ } else {
8015+ userVmDetailsDao .persist (new UserVmDetailVO (userVm .getId (), VmDetailConstants .ROOT_DISK_SIZE ,
8016+ details .get (VmDetailConstants .ROOT_DISK_SIZE ), true ));
8017+ }
80028018 }
80038019
80048020 String minIops = details .get (MIN_IOPS );
0 commit comments