Skip to content

Commit b38ee63

Browse files
committed
Merge branch '4.19'
2 parents 8608f28 + dfe4a67 commit b38ee63

File tree

12 files changed

+68
-11
lines changed

12 files changed

+68
-11
lines changed

engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateServiceImpl.java

+5
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,11 @@ public void handleTemplateSync(DataStore store) {
533533
logger.info("Skip downloading template " + tmplt.getUniqueName() + " since no url is specified.");
534534
continue;
535535
}
536+
// if this is private template, skip sync to a new image store
537+
if (isSkipTemplateStoreDownload(tmplt, zoneId)) {
538+
logger.info("Skip sync downloading private template " + tmplt.getUniqueName() + " to a new image store");
539+
continue;
540+
}
536541

537542
// if this is a region store, and there is already an DOWNLOADED entry there without install_path information, which
538543
// means that this is a duplicate entry from migration of previous NFS to staging.

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor {
4343
private static final Map<String, KVMStoragePool> MapStorageUuidToStoragePool = new HashMap<>();
4444

4545
@Override
46-
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, StoragePoolType storagePoolType, Map<String, String> details) {
46+
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, StoragePoolType storagePoolType, Map<String, String> details, boolean isPrimaryStorage) {
4747
IscsiAdmStoragePool storagePool = new IscsiAdmStoragePool(uuid, host, port, storagePoolType, this);
4848

4949
MapStorageUuidToStoragePool.put(uuid, storagePool);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri
389389
//Note: due to bug CLOUDSTACK-4459, createStoragepool can be called in parallel, so need to be synced.
390390
private synchronized KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, Map<String, String> details, boolean primaryStorage) {
391391
StorageAdaptor adaptor = getStorageAdaptor(type);
392-
KVMStoragePool pool = adaptor.createStoragePool(name, host, port, path, userInfo, type, details);
392+
KVMStoragePool pool = adaptor.createStoragePool(name, host, port, path, userInfo, type, details, primaryStorage);
393393

394394
// LibvirtStorageAdaptor-specific statement
395395
if (pool.isPoolSupportHA() && primaryStorage) {

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java

+53-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import java.util.Arrays;
7474
import java.util.HashSet;
7575
import java.util.Set;
76+
import java.util.concurrent.ConcurrentHashMap;
7677
import java.util.stream.Collectors;
7778

7879

@@ -81,6 +82,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
8182
private StorageLayer _storageLayer;
8283
private String _mountPoint = "/mnt";
8384
private String _manageSnapshotPath;
85+
private static final ConcurrentHashMap<String, Integer> storagePoolRefCounts = new ConcurrentHashMap<>();
8486

8587
private String rbdTemplateSnapName = "cloudstack-base-snap";
8688
private static final int RBD_FEATURE_LAYERING = 1;
@@ -644,8 +646,44 @@ public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool) {
644646
}
645647
}
646648

649+
/**
650+
* adjust refcount
651+
*/
652+
private int adjustStoragePoolRefCount(String uuid, int adjustment) {
653+
final String mutexKey = storagePoolRefCounts.keySet().stream()
654+
.filter(k -> k.equals(uuid))
655+
.findFirst()
656+
.orElse(uuid);
657+
synchronized (mutexKey) {
658+
// some access on the storagePoolRefCounts.key(mutexKey) element
659+
int refCount = storagePoolRefCounts.computeIfAbsent(mutexKey, k -> 0);
660+
refCount += adjustment;
661+
if (refCount < 1) {
662+
storagePoolRefCounts.remove(mutexKey);
663+
} else {
664+
storagePoolRefCounts.put(mutexKey, refCount);
665+
}
666+
return refCount;
667+
}
668+
}
669+
/**
670+
* Thread-safe increment storage pool usage refcount
671+
* @param uuid UUID of the storage pool to increment the count
672+
*/
673+
private void incStoragePoolRefCount(String uuid) {
674+
adjustStoragePoolRefCount(uuid, 1);
675+
}
676+
/**
677+
* Thread-safe decrement storage pool usage refcount for the given uuid and return if storage pool still in use.
678+
* @param uuid UUID of the storage pool to decrement the count
679+
* @return true if the storage pool is still used, else false.
680+
*/
681+
private boolean decStoragePoolRefCount(String uuid) {
682+
return adjustStoragePoolRefCount(uuid, -1) > 0;
683+
}
684+
647685
@Override
648-
public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, Map<String, String> details) {
686+
public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, Map<String, String> details, boolean isPrimaryStorage) {
649687
logger.info("Attempting to create storage pool " + name + " (" + type.toString() + ") in libvirt");
650688

651689
StoragePool sp = null;
@@ -751,6 +789,12 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri
751789
}
752790

753791
try {
792+
if (!isPrimaryStorage) {
793+
// only ref count storage pools for secondary storage, as primary storage is assumed
794+
// to be always mounted, as long the primary storage isn't fully deleted.
795+
incStoragePoolRefCount(name);
796+
}
797+
754798
if (sp.isActive() == 0) {
755799
logger.debug("Attempting to activate pool " + name);
756800
sp.create(0);
@@ -762,6 +806,7 @@ public KVMStoragePool createStoragePool(String name, String host, int port, Stri
762806

763807
return getStoragePool(name);
764808
} catch (LibvirtException e) {
809+
decStoragePoolRefCount(name);
765810
String error = e.toString();
766811
if (error.contains("Storage source conflict")) {
767812
throw new CloudRuntimeException("A pool matching this location already exists in libvirt, " +
@@ -812,6 +857,13 @@ private boolean destroyStoragePoolHandleException(Connect conn, String uuid)
812857
@Override
813858
public boolean deleteStoragePool(String uuid) {
814859
logger.info("Attempting to remove storage pool " + uuid + " from libvirt");
860+
861+
// decrement and check if storage pool still in use
862+
if (decStoragePoolRefCount(uuid)) {
863+
logger.info(String.format("deleteStoragePool: Storage pool %s still in use", uuid));
864+
return true;
865+
}
866+
815867
Connect conn = null;
816868
try {
817869
conn = LibvirtConnection.getConnection();

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public ManagedNfsStorageAdaptor(StorageLayer storagelayer) {
5656
}
5757

5858
@Override
59-
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, StoragePoolType storagePoolType, Map<String, String> details) {
59+
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, StoragePoolType storagePoolType, Map<String, String> details, boolean isPrimaryStorage) {
6060

6161
LibvirtStoragePool storagePool = new LibvirtStoragePool(uuid, path, StoragePoolType.ManagedNFS, this, null);
6262
storagePool.setSourceHost(host);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/MultipathSCSIAdapterBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private KVMPhysicalDisk getPhysicalDisk(AddressInfo address, KVMStoragePool pool
169169
}
170170

171171
@Override
172-
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, Storage.StoragePoolType type, Map<String, String> details) {
172+
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, Storage.StoragePoolType type, Map<String, String> details, boolean isPrimaryStorage) {
173173
LOGGER.info(String.format("createStoragePool(uuid,host,port,path,type) called with args (%s, %s, %s, %s, %s)", uuid, host, ""+port, path, type));
174174
MultipathSCSIPool storagePool = new MultipathSCSIPool(uuid, host, port, path, type, details, this);
175175
MapStorageUuidToStoragePool.put(uuid, storagePool);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public KVMPhysicalDisk getPhysicalDisk(String volumePath, KVMStoragePool pool) {
146146
}
147147

148148
@Override
149-
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, Storage.StoragePoolType type, Map<String, String> details) {
149+
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, Storage.StoragePoolType type, Map<String, String> details, boolean isPrimaryStorage) {
150150
ScaleIOStoragePool storagePool = new ScaleIOStoragePool(uuid, host, port, path, type, details, this);
151151
MapStorageUuidToStoragePool.put(uuid, storagePool);
152152
return storagePool;

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public interface StorageAdaptor {
4040
// it with info from local disk, and return it
4141
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool);
4242

43-
public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, Map<String, String> details);
43+
public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, Map<String, String> details, boolean isPrimaryStorage);
4444

4545
public boolean deleteStoragePool(String uuid);
4646

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,6 @@ public void testCreateStoragePoolWithNFSMountOpts() throws Exception {
8686

8787
Map<String, String> details = new HashMap<>();
8888
details.put("nfsmountopts", "vers=4.1, nconnect=4");
89-
KVMStoragePool pool = libvirtStorageAdaptor.createStoragePool(uuid, null, 0, dir, null, Storage.StoragePoolType.NetworkFilesystem, details);
89+
KVMStoragePool pool = libvirtStorageAdaptor.createStoragePool(uuid, null, 0, dir, null, Storage.StoragePoolType.NetworkFilesystem, details, true);
9090
}
9191
}

plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public KVMPhysicalDisk getPhysicalDisk(String name, KVMStoragePool pool)
154154

155155
@Override
156156
public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo,
157-
Storage.StoragePoolType type, Map<String, String> details)
157+
Storage.StoragePoolType type, Map<String, String> details, boolean isPrimaryStorage)
158158
{
159159
logger.debug("Linstor createStoragePool: name: '{}', host: '{}', path: {}, userinfo: {}", name, host, path, userInfo);
160160
LinstorStoragePool storagePool = new LinstorStoragePool(name, host, port, userInfo, type, this);

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static void SP_LOG(String fmt, Object... args) {
5757
private static final Map<String, KVMStoragePool> storageUuidToStoragePool = new HashMap<String, KVMStoragePool>();
5858

5959
@Override
60-
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, StoragePoolType storagePoolType, Map<String, String> details) {
60+
public KVMStoragePool createStoragePool(String uuid, String host, int port, String path, String userInfo, StoragePoolType storagePoolType, Map<String, String> details, boolean isPrimaryStorage) {
6161
SP_LOG("StorPoolStorageAdaptor.createStoragePool: uuid=%s, host=%s:%d, path=%s, userInfo=%s, type=%s", uuid, host, port, path, userInfo, storagePoolType);
6262

6363
StorPoolStoragePool storagePool = new StorPoolStoragePool(uuid, host, port, storagePoolType, this);

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3861,7 +3861,7 @@ private Pair<List<Long>, Integer> searchForServiceOfferingIdsAndCount(ListServic
38613861
serviceOfferingSearch.and().op("vmMemory", serviceOfferingSearch.entity().getRamSize(), Op.GTEQ);
38623862
serviceOfferingSearch.or().op("vmMemoryNull", serviceOfferingSearch.entity().getRamSize(), Op.NULL);
38633863
serviceOfferingSearch.and().op("maxMemoryDetailsSearch", "vmMaxMemoryNull", maxMemoryDetailsSearch.entity().getValue(), Op.NULL);
3864-
serviceOfferingSearch.and("maxMemoryDetailsSearch", "vmMaxMemoryGTEQ", maxMemoryDetailsSearch.entity().getValue(), Op.GTEQ).cp();
3864+
serviceOfferingSearch.or("maxMemoryDetailsSearch", "vmMaxMemoryGTEQ", maxMemoryDetailsSearch.entity().getValue(), Op.GTEQ).cp();
38653865

38663866
serviceOfferingSearch.cp().cp();
38673867
}

0 commit comments

Comments
 (0)