mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
StorPool notify libvirt when volume is resized (#10775)
This commit is contained in:
parent
c453aaea2c
commit
17e062a381
@ -412,13 +412,14 @@ public class StorPoolPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
||||
if (err == null && needResize) {
|
||||
err = notifyQemuForTheNewSize(data, err, vol, payload);
|
||||
}
|
||||
|
||||
if (err != null) {
|
||||
// try restoring volume to its initial size
|
||||
SpApiResponse response = StorPoolUtil.volumeUpdate(name, oldSize, true, oldMaxIops, conn);
|
||||
if (response.getError() != null) {
|
||||
logger.debug(String.format("Could not resize StorPool volume %s back to its original size. Error: %s", name, response.getError()));
|
||||
}
|
||||
} else {
|
||||
updateVolumeWithTheNewSize(vol, payload);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.debug("sending resize command failed", e);
|
||||
@ -427,6 +428,17 @@ public class StorPoolPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
||||
return err;
|
||||
}
|
||||
|
||||
private void updateVolumeWithTheNewSize(VolumeObject vol, ResizeVolumePayload payload) {
|
||||
vol.setSize(payload.newSize);
|
||||
vol.update();
|
||||
if (payload.newMaxIops != null) {
|
||||
VolumeVO volume = volumeDao.findById(vol.getId());
|
||||
volume.setMaxIops(payload.newMaxIops);
|
||||
volumeDao.update(volume.getId(), volume);
|
||||
}
|
||||
updateStoragePool(vol.getPoolId(), payload.newSize - vol.getSize());
|
||||
}
|
||||
|
||||
private String notifyQemuForTheNewSize(DataObject data, String err, VolumeObject vol, ResizeVolumePayload payload)
|
||||
throws StorageUnavailableException {
|
||||
StoragePool pool = (StoragePool)data.getDataStore();
|
||||
@ -455,11 +467,24 @@ public class StorPoolPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
||||
}
|
||||
SpApiResponse resp = new SpApiResponse();
|
||||
if (tier != null || template != null) {
|
||||
resp = updateVolumeByStorPoolQoS(payload, conn, name, tier, template);
|
||||
} else {
|
||||
resp = updateVolumeByOffering(vol, payload, conn, name);
|
||||
}
|
||||
if (resp.getError() != null) {
|
||||
err = String.format("Could not resize StorPool volume %s. Error: %s", name, resp.getError());
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
private static SpApiResponse updateVolumeByStorPoolQoS(ResizeVolumePayload payload, SpConnectionDesc conn, String name, String tier, String template) {
|
||||
Map<String, String> tags = StorPoolHelper.addStorPoolTags(null, null, null, null, tier);
|
||||
StorPoolVolumeDef spVolume = new StorPoolVolumeDef(name, payload.newSize, tags, null, null, template, null, null,
|
||||
payload.shrinkOk);
|
||||
resp = StorPoolUtil.volumeUpdate(spVolume, conn);
|
||||
} else {
|
||||
return StorPoolUtil.volumeUpdate(spVolume, conn);
|
||||
}
|
||||
|
||||
private static SpApiResponse updateVolumeByOffering(VolumeObject vol, ResizeVolumePayload payload, SpConnectionDesc conn, String name) {
|
||||
long maxIops = payload.newMaxIops == null ? Long.valueOf(0) : payload.newMaxIops;
|
||||
|
||||
StorPoolVolumeDef spVolume = new StorPoolVolumeDef(name, payload.newSize, null, null, maxIops, null, null, null,
|
||||
@ -467,23 +492,7 @@ public class StorPoolPrimaryDataStoreDriver implements PrimaryDataStoreDriver {
|
||||
StorPoolUtil.spLog(
|
||||
"StorpoolPrimaryDataStoreDriverImpl.resize: name=%s, uuid=%s, oldSize=%d, newSize=%s, shrinkOk=%s, maxIops=%s",
|
||||
name, vol.getUuid(), vol.getSize(), payload.newSize, payload.shrinkOk, maxIops);
|
||||
|
||||
resp = StorPoolUtil.volumeUpdate(spVolume, conn);
|
||||
}
|
||||
if (resp.getError() != null) {
|
||||
err = String.format("Could not resize StorPool volume %s. Error: %s", name, resp.getError());
|
||||
} else {
|
||||
vol.setSize(payload.newSize);
|
||||
vol.update();
|
||||
if (payload.newMaxIops != null) {
|
||||
VolumeVO volume = volumeDao.findById(vol.getId());
|
||||
volume.setMaxIops(payload.newMaxIops);
|
||||
volumeDao.update(volume.getId(), volume);
|
||||
}
|
||||
|
||||
updateStoragePool(vol.getPoolId(), payload.newSize - vol.getSize());
|
||||
}
|
||||
return err;
|
||||
return StorPoolUtil.volumeUpdate(spVolume, conn);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user