@@ -8115,17 +8115,25 @@ public Pair<UserVmVO, Volume> doInTransaction(final TransactionStatus status) th
81158115 private void updateVolume (Volume vol , VMTemplateVO template , UserVmVO userVm , DiskOffering diskOffering , Map <String , String > details ) {
81168116 VolumeVO resizedVolume = (VolumeVO ) vol ;
81178117
8118- if (userVmDetailsDao .findDetail (userVm .getId (), VmDetailConstants .ROOT_DISK_SIZE ) == null && !vol .getSize ().equals (template .getSize ())) {
8119- if (template .getSize () != null ) {
8118+ if (template != null && template .getSize () != null ) {
8119+ UserVmDetailVO vmRootDiskSizeDetail = userVmDetailsDao .findDetail (userVm .getId (), VmDetailConstants .ROOT_DISK_SIZE );
8120+ if (vmRootDiskSizeDetail == null ) {
81208121 resizedVolume .setSize (template .getSize ());
8122+ } else {
8123+ long rootDiskSize = Long .parseLong (vmRootDiskSizeDetail .getValue ()) * GiB_TO_BYTES ;
8124+ if (template .getSize () >= rootDiskSize ) {
8125+ resizedVolume .setSize (template .getSize ());
8126+ userVmDetailsDao .remove (vmRootDiskSizeDetail .getId ());
8127+ } else {
8128+ resizedVolume .setSize (rootDiskSize );
8129+ }
81218130 }
81228131 }
81238132
81248133 if (diskOffering != null ) {
81258134 resizedVolume .setDiskOfferingId (diskOffering .getId ());
8126- resizedVolume .setSize (diskOffering .getDiskSize ());
8127- if (diskOffering .isCustomized ()) {
8128- resizedVolume .setSize (vol .getSize ());
8135+ if (!diskOffering .isCustomized ()) {
8136+ resizedVolume .setSize (diskOffering .getDiskSize ());
81298137 }
81308138 if (diskOffering .getMinIops () != null ) {
81318139 resizedVolume .setMinIops (diskOffering .getMinIops ());
@@ -8139,6 +8147,14 @@ private void updateVolume(Volume vol, VMTemplateVO template, UserVmVO userVm, Di
81398147 if (StringUtils .isNumeric (details .get (VmDetailConstants .ROOT_DISK_SIZE ))) {
81408148 Long rootDiskSize = Long .parseLong (details .get (VmDetailConstants .ROOT_DISK_SIZE )) * GiB_TO_BYTES ;
81418149 resizedVolume .setSize (rootDiskSize );
8150+ UserVmDetailVO vmRootDiskSizeDetail = userVmDetailsDao .findDetail (userVm .getId (), VmDetailConstants .ROOT_DISK_SIZE );
8151+ if (vmRootDiskSizeDetail != null ) {
8152+ vmRootDiskSizeDetail .setValue (details .get (VmDetailConstants .ROOT_DISK_SIZE ));
8153+ userVmDetailsDao .update (vmRootDiskSizeDetail .getId (), vmRootDiskSizeDetail );
8154+ } else {
8155+ userVmDetailsDao .persist (new UserVmDetailVO (userVm .getId (), VmDetailConstants .ROOT_DISK_SIZE ,
8156+ details .get (VmDetailConstants .ROOT_DISK_SIZE ), true ));
8157+ }
81428158 }
81438159
81448160 String minIops = details .get (MIN_IOPS );
0 commit comments