|
42 | 42 | import java.util.Optional; |
43 | 43 | import java.util.stream.Collectors; |
44 | 44 |
|
| 45 | +import com.cloud.hypervisor.kvm.storage.KVMStoragePool; |
45 | 46 | import com.cloud.utils.Pair; |
46 | 47 | import com.cloud.utils.exception.CloudRuntimeException; |
47 | 48 | import org.apache.logging.log4j.Logger; |
@@ -431,4 +432,37 @@ public static ResourceDefinition findResourceDefinition(DevelopersApi api, Strin |
431 | 432 | public static boolean isRscDiskless(ResourceWithVolumes rsc) { |
432 | 433 | return rsc.getFlags() != null && rsc.getFlags().contains(ApiConsts.FLAG_DISKLESS); |
433 | 434 | } |
| 435 | + |
| 436 | + /** |
| 437 | + * Checks if all diskful resource are on a zeroed block device. |
| 438 | + * @param pool Linstor pool to use |
| 439 | + * @param resName Linstor resource name |
| 440 | + * @return true if all resources are on a provider with zeroed blocks. |
| 441 | + */ |
| 442 | + public static boolean resourceSupportZeroBlocks(KVMStoragePool pool, String resName) { |
| 443 | + final DevelopersApi api = getLinstorAPI(pool.getSourceHost()); |
| 444 | + try { |
| 445 | + List<ResourceWithVolumes> resWithVols = api.viewResources( |
| 446 | + Collections.emptyList(), |
| 447 | + Collections.singletonList(resName), |
| 448 | + Collections.emptyList(), |
| 449 | + Collections.emptyList(), |
| 450 | + null, |
| 451 | + null); |
| 452 | + |
| 453 | + if (resWithVols != null) { |
| 454 | + return resWithVols.stream() |
| 455 | + .allMatch(res -> { |
| 456 | + Volume vol0 = res.getVolumes().get(0); |
| 457 | + return vol0 != null && (vol0.getProviderKind() == ProviderKind.LVM_THIN || |
| 458 | + vol0.getProviderKind() == ProviderKind.ZFS || |
| 459 | + vol0.getProviderKind() == ProviderKind.ZFS_THIN || |
| 460 | + vol0.getProviderKind() == ProviderKind.DISKLESS); |
| 461 | + } ); |
| 462 | + } |
| 463 | + } catch (ApiException apiExc) { |
| 464 | + s_logger.error(apiExc.getMessage()); |
| 465 | + } |
| 466 | + return false; |
| 467 | + } |
434 | 468 | } |
0 commit comments