if (ssCmd.getResourceType() != Storage.StorageResourceType.STORAGE_POOL) {
return;
}
StoragePoolInfo pInfo = ssCmd.getPoolInfo();
if (pInfo == null) {
return;
}
DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
if (dc == null || !dc.isLocalStorageEnabled()) {
return;
}
try {
StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), pInfo.getHost(), pInfo.getHostPath(), pInfo.getUuid());
if(pool == null && host.getHypervisorType() == HypervisorType.VMware) {
// perform run-time upgrade. In versions prior to 2.2.12, there is a bug that we don't save local datastore info (host path is empty), this will cause us
// not able to distinguish multiple local datastores that may be available on the host, to support smooth migration, we
// need to perform runtime upgrade here
if(pInfo.getHostPath().length() > 0) {
pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), pInfo.getHost(), "", pInfo.getUuid());
}
}
if (pool == null) {
long poolId = _storagePoolDao.getNextInSequence(Long.class, "id");
String name = cmd.getName() == null ? (host.getName() + " Local Storage") : cmd.getName();
Transaction txn = Transaction.currentTxn();
txn.start();
pool = new StoragePoolVO(poolId, name, pInfo.getUuid(), pInfo.getPoolType(), host.getDataCenterId(),
host.getPodId(), pInfo.getAvailableBytes(), pInfo.getCapacityBytes(), pInfo.getHost(), 0,
pInfo.getHostPath());
pool.setClusterId(host.getClusterId());
_storagePoolDao.persist(pool, pInfo.getDetails());
StoragePoolHostVO poolHost = new StoragePoolHostVO(pool.getId(), host.getId(), pInfo.getLocalPath());
_storagePoolHostDao.persist(poolHost);
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, pool.getCapacityBytes() - pool.getAvailableBytes());
txn.commit();
} else {
Transaction txn = Transaction.currentTxn();
txn.start();
pool.setPath(pInfo.getHostPath());
pool.setAvailableBytes(pInfo.getAvailableBytes());
pool.setCapacityBytes(pInfo.getCapacityBytes());
_storagePoolDao.update(pool.getId(), pool);
if (pInfo.getDetails() != null) {
_storagePoolDao.updateDetails(pool.getId(), pInfo.getDetails());
}
StoragePoolHostVO poolHost = _storagePoolHostDao.findByPoolHost(pool.getId(), host.getId());
if (poolHost == null) {
poolHost = new StoragePoolHostVO(pool.getId(), host.getId(), pInfo.getLocalPath());
_storagePoolHostDao.persist(poolHost);
}
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, pool.getCapacityBytes() - pool.getAvailableBytes());