mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	Fixed Coverity Issues
This commit is contained in:
		
							parent
							
								
									80846ba98a
								
							
						
					
					
						commit
						1aef5cba66
					
				| @ -222,9 +222,6 @@ public class TrafficSentinelResource implements ServerResource { | |||||||
|                         String publicIp = st.nextToken(); |                         String publicIp = st.nextToken(); | ||||||
|                         Long bytesSent = new Long(st.nextToken()); |                         Long bytesSent = new Long(st.nextToken()); | ||||||
|                         Long bytesRcvd = new Long(st.nextToken()); |                         Long bytesRcvd = new Long(st.nextToken()); | ||||||
|                         if (bytesSent == null || bytesRcvd == null) { |  | ||||||
|                             s_logger.debug("Incorrect bytes for IP: " + publicIp); |  | ||||||
|                         } |  | ||||||
|                         long[] bytesSentAndReceived = new long[2]; |                         long[] bytesSentAndReceived = new long[2]; | ||||||
|                         bytesSentAndReceived[0] = bytesSent; |                         bytesSentAndReceived[0] = bytesSent; | ||||||
|                         bytesSentAndReceived[1] = bytesRcvd; |                         bytesSentAndReceived[1] = bytesRcvd; | ||||||
|  | |||||||
| @ -2675,12 +2675,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac | |||||||
|             s_logger.debug("Not processing listener " + this + " as connect happens on rebalance process"); |             s_logger.debug("Not processing listener " + this + " as connect happens on rebalance process"); | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 |  | ||||||
|         if (forRebalance) { |  | ||||||
|             s_logger.debug("Not processing listener " + this + " as connect happens on rebalance process"); |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         Long clusterId = agent.getClusterId(); |         Long clusterId = agent.getClusterId(); | ||||||
|         long agentId = agent.getId(); |         long agentId = agent.getId(); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -404,14 +404,14 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { | |||||||
|         DataStore dataStore = _dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary); |         DataStore dataStore = _dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary); | ||||||
| 
 | 
 | ||||||
|         Map<String, String> mapCapabilities = dataStore.getDriver().getCapabilities(); |         Map<String, String> mapCapabilities = dataStore.getDriver().getCapabilities(); | ||||||
| 
 |         if(mapCapabilities != null) { | ||||||
|             String value = mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString()); |             String value = mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString()); | ||||||
|             Boolean supportsStorageSystemSnapshots = new Boolean(value); |             Boolean supportsStorageSystemSnapshots = new Boolean(value); | ||||||
| 
 | 
 | ||||||
|             if (supportsStorageSystemSnapshots) { |             if (supportsStorageSystemSnapshots) { | ||||||
|                 return StrategyPriority.HIGHEST; |                 return StrategyPriority.HIGHEST; | ||||||
|             } |             } | ||||||
| 
 |         } | ||||||
|         return StrategyPriority.CANT_HANDLE; |         return StrategyPriority.CANT_HANDLE; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1082,7 +1082,9 @@ public class KVMStorageProcessor implements StorageProcessor { | |||||||
|                                                  volume.getProvisioningType(), disksize); |                                                  volume.getProvisioningType(), disksize); | ||||||
| 
 | 
 | ||||||
|             VolumeObjectTO newVol = new VolumeObjectTO(); |             VolumeObjectTO newVol = new VolumeObjectTO(); | ||||||
|  |             if(vol != null) { | ||||||
|                 newVol.setPath(vol.getName()); |                 newVol.setPath(vol.getName()); | ||||||
|  |             } | ||||||
|             newVol.setSize(volume.getSize()); |             newVol.setSize(volume.getSize()); | ||||||
|             newVol.setFormat(ImageFormat.valueOf(format.toString().toUpperCase())); |             newVol.setFormat(ImageFormat.valueOf(format.toString().toUpperCase())); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -915,6 +915,9 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { | |||||||
|             try { |             try { | ||||||
|                 String newUuid = name; |                 String newUuid = name; | ||||||
|                 disk = destPool.createPhysicalDisk(newUuid, format, provisioningType, template.getVirtualSize()); |                 disk = destPool.createPhysicalDisk(newUuid, format, provisioningType, template.getVirtualSize()); | ||||||
|  |                 if (disk == null) { | ||||||
|  |                     throw new CloudRuntimeException("Failed to create disk from template " + template.getName()); | ||||||
|  |                 } | ||||||
|                 if (template.getFormat() == PhysicalDiskFormat.TAR) { |                 if (template.getFormat() == PhysicalDiskFormat.TAR) { | ||||||
|                     Script.runSimpleBashScript("tar -x -f " + template.getPath() + " -C " + disk.getPath(), timeout); // TO BE FIXED to aware provisioningType |                     Script.runSimpleBashScript("tar -x -f " + template.getPath() + " -C " + disk.getPath(), timeout); // TO BE FIXED to aware provisioningType | ||||||
|                 } else if (template.getFormat() == PhysicalDiskFormat.DIR) { |                 } else if (template.getFormat() == PhysicalDiskFormat.DIR) { | ||||||
| @ -960,9 +963,6 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (disk == null) { |  | ||||||
|             throw new CloudRuntimeException("Failed to create disk from template " + template.getName()); |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         return disk; |         return disk; | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -100,6 +100,9 @@ public class ManagedNfsStorageAdaptor implements StorageAdaptor { | |||||||
|         LibvirtStoragePoolDef spd = null; |         LibvirtStoragePoolDef spd = null; | ||||||
|         try { |         try { | ||||||
|             conn = LibvirtConnection.getConnection(); |             conn = LibvirtConnection.getConnection(); | ||||||
|  |             if (conn == null) { | ||||||
|  |                 throw new CloudRuntimeException("Failed to create Libvrt Connection"); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|             targetPath = "/mnt" + volumeUuid; |             targetPath = "/mnt" + volumeUuid; | ||||||
|             spd = new LibvirtStoragePoolDef(poolType.NETFS, volumeUuid, details.get(DiskTO.UUID), pool.getSourceHost(), details.get(DiskTO.MOUNT_POINT), targetPath); |             spd = new LibvirtStoragePoolDef(poolType.NETFS, volumeUuid, details.get(DiskTO.UUID), pool.getSourceHost(), details.get(DiskTO.MOUNT_POINT), targetPath); | ||||||
| @ -140,7 +143,7 @@ public class ManagedNfsStorageAdaptor implements StorageAdaptor { | |||||||
|                 if (result == null) { |                 if (result == null) { | ||||||
|                     s_logger.error("Succeeded in unmounting " + targetPath); |                     s_logger.error("Succeeded in unmounting " + targetPath); | ||||||
|                     try { |                     try { | ||||||
|                         sp = conn.storagePoolCreateXML(spd.toString(), 0); |                         conn.storagePoolCreateXML(spd.toString(), 0); | ||||||
|                         s_logger.error("Succeeded in redefining storage"); |                         s_logger.error("Succeeded in redefining storage"); | ||||||
|                         return true; |                         return true; | ||||||
|                     } catch (LibvirtException l) { |                     } catch (LibvirtException l) { | ||||||
| @ -176,9 +179,6 @@ public class ManagedNfsStorageAdaptor implements StorageAdaptor { | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         LibvirtStorageVolumeDef.volFormat libvirtformat = null; |         LibvirtStorageVolumeDef.volFormat libvirtformat = null; | ||||||
|         String volPath = null; |  | ||||||
|         String volName = null; |  | ||||||
|         long volAllocation = 0; |  | ||||||
|         long volCapacity = 0; |         long volCapacity = 0; | ||||||
|         // check whether the volume is present on the given pool |         // check whether the volume is present on the given pool | ||||||
|         StorageVol vol = getVolume(virtPool, volumeUuid); |         StorageVol vol = getVolume(virtPool, volumeUuid); | ||||||
| @ -194,13 +194,8 @@ public class ManagedNfsStorageAdaptor implements StorageAdaptor { | |||||||
|                 s_logger.debug(volDef.toString()); |                 s_logger.debug(volDef.toString()); | ||||||
| 
 | 
 | ||||||
|                 vol = virtPool.storageVolCreateXML(volDef.toString(), 0); |                 vol = virtPool.storageVolCreateXML(volDef.toString(), 0); | ||||||
|                 volPath = vol.getPath(); |  | ||||||
|                 volName = vol.getName(); |  | ||||||
|                 volAllocation = vol.getInfo().allocation; |  | ||||||
|                 volCapacity = vol.getInfo().capacity; |  | ||||||
| 
 | 
 | ||||||
|             } |             } | ||||||
| 
 |  | ||||||
|             KVMPhysicalDisk disk = new KVMPhysicalDisk(vol.getPath(), volumeUuid, pool); |             KVMPhysicalDisk disk = new KVMPhysicalDisk(vol.getPath(), volumeUuid, pool); | ||||||
|             disk.setFormat(PhysicalDiskFormat.QCOW2); |             disk.setFormat(PhysicalDiskFormat.QCOW2); | ||||||
|             disk.setSize(vol.getInfo().allocation); |             disk.setSize(vol.getInfo().allocation); | ||||||
|  | |||||||
| @ -294,7 +294,7 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme | |||||||
|                     CiscoNexusVSMDeviceVO vsm = null; |                     CiscoNexusVSMDeviceVO vsm = null; | ||||||
|                     if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) { |                     if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) { | ||||||
|                         vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword); |                         vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword); | ||||||
|                         vsm = _vsmDao.persist(vsm); |                         _vsmDao.persist(vsm); | ||||||
|                     } |                     } | ||||||
|                     // Create a mapping between the cluster and the vsm. |                     // Create a mapping between the cluster and the vsm. | ||||||
|                     vsm = _vsmDao.getVSMbyIpaddress(vsmIp); |                     vsm = _vsmDao.getVSMbyIpaddress(vsmIp); | ||||||
|  | |||||||
| @ -309,17 +309,21 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, | |||||||
|             throw new InvalidParameterValueException("Volume is not in ready state"); |             throw new InvalidParameterValueException("Volume is not in ready state"); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         boolean backedUp = false; | 
 | ||||||
|         // does the caller have the authority to act on this volume |         // does the caller have the authority to act on this volume | ||||||
|         _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, volume); |         _accountMgr.checkAccess(CallContext.current().getCallingAccount(), null, true, volume); | ||||||
| 
 | 
 | ||||||
|         SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotId, DataStoreRole.Primary); |         SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotId, DataStoreRole.Primary); | ||||||
| 
 |         if(snapshot != null) | ||||||
|  |         { | ||||||
|  |             s_logger.debug("Failed to create snapshot"); | ||||||
|  |             throw new CloudRuntimeException("Failed to create snapshot"); | ||||||
|  |         } | ||||||
|         try { |         try { | ||||||
|             postCreateSnapshot(volumeId, snapshot.getId(), policyId); |             postCreateSnapshot(volumeId, snapshot.getId(), policyId); | ||||||
|             //Check if the snapshot was removed while backingUp. If yes, do not log snapshot create usage event |             //Check if the snapshot was removed while backingUp. If yes, do not log snapshot create usage event | ||||||
|             SnapshotVO freshSnapshot = _snapshotDao.findById(snapshot.getId()); |             SnapshotVO freshSnapshot = _snapshotDao.findById(snapshot.getId()); | ||||||
|             if ((freshSnapshot != null) && backedUp) { |             if (freshSnapshot != null)  { | ||||||
|                 UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), snapshot.getDataCenterId(), snapshotId, snapshot.getName(), |                 UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), snapshot.getDataCenterId(), snapshotId, snapshot.getName(), | ||||||
|                     null, null, volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid()); |                     null, null, volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid()); | ||||||
|             } |             } | ||||||
|  | |||||||
| @ -156,7 +156,6 @@ import com.cloud.user.AccountManager; | |||||||
| import com.cloud.user.AccountService; | import com.cloud.user.AccountService; | ||||||
| import com.cloud.user.AccountVO; | import com.cloud.user.AccountVO; | ||||||
| import com.cloud.user.ResourceLimitService; | import com.cloud.user.ResourceLimitService; | ||||||
| import com.cloud.user.User; |  | ||||||
| import com.cloud.user.dao.AccountDao; | import com.cloud.user.dao.AccountDao; | ||||||
| import com.cloud.uservm.UserVm; | import com.cloud.uservm.UserVm; | ||||||
| import com.cloud.utils.DateUtil; | import com.cloud.utils.DateUtil; | ||||||
| @ -1350,10 +1349,6 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, | |||||||
|     @DB |     @DB | ||||||
|     @ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating template", async = true) |     @ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating template", async = true) | ||||||
|     public VirtualMachineTemplate createPrivateTemplate(CreateTemplateCmd command) throws CloudRuntimeException { |     public VirtualMachineTemplate createPrivateTemplate(CreateTemplateCmd command) throws CloudRuntimeException { | ||||||
|         Long userId = CallContext.current().getCallingUserId(); |  | ||||||
|         if (userId == null) { |  | ||||||
|             userId = User.UID_SYSTEM; |  | ||||||
|         } |  | ||||||
|         final long templateId = command.getEntityId(); |         final long templateId = command.getEntityId(); | ||||||
|         Long volumeId = command.getVolumeId(); |         Long volumeId = command.getVolumeId(); | ||||||
|         Long snapshotId = command.getSnapshotId(); |         Long snapshotId = command.getSnapshotId(); | ||||||
|  | |||||||
| @ -748,12 +748,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir | |||||||
|         } catch (CloudException e) { |         } catch (CloudException e) { | ||||||
|             throw new CloudRuntimeException("Unable to contact the agent to stop the virtual machine " + vm, e); |             throw new CloudRuntimeException("Unable to contact the agent to stop the virtual machine " + vm, e); | ||||||
|         } |         } | ||||||
| 
 |  | ||||||
|         if (status) { |  | ||||||
|         return status; |         return status; | ||||||
|         } else { |  | ||||||
|             return status; |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private UserVm rebootVirtualMachine(long userId, long vmId) throws InsufficientCapacityException, ResourceUnavailableException { |     private UserVm rebootVirtualMachine(long userId, long vmId) throws InsufficientCapacityException, ResourceUnavailableException { | ||||||
| @ -1328,8 +1323,6 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir | |||||||
|             if (vmSnapshots.size() > 0) { |             if (vmSnapshots.size() > 0) { | ||||||
|                 throw new InvalidParameterValueException("Unable to scale VM, please remove VM snapshots before scaling VM"); |                 throw new InvalidParameterValueException("Unable to scale VM, please remove VM snapshots before scaling VM"); | ||||||
|             } |             } | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|             if (vmInstance.getState().equals(State.Stopped)) { |             if (vmInstance.getState().equals(State.Stopped)) { | ||||||
|                 upgradeStoppedVirtualMachine(vmId, newServiceOfferingId, customParameters); |                 upgradeStoppedVirtualMachine(vmId, newServiceOfferingId, customParameters); | ||||||
|                 return true; |                 return true; | ||||||
| @ -1337,6 +1330,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir | |||||||
|             if (vmInstance.getState().equals(State.Running)) { |             if (vmInstance.getState().equals(State.Running)) { | ||||||
|                 return upgradeRunningVirtualMachine(vmId, newServiceOfferingId, customParameters); |                 return upgradeRunningVirtualMachine(vmId, newServiceOfferingId, customParameters); | ||||||
|             } |             } | ||||||
|  |         } | ||||||
|     return false; |     return false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -237,11 +237,6 @@ public class RegionsApiUtil { | |||||||
| 
 | 
 | ||||||
|         String apiKey = ""; |         String apiKey = ""; | ||||||
|         String secretKey = ""; |         String secretKey = ""; | ||||||
| 
 |  | ||||||
|         if (apiKey == null || secretKey == null) { |  | ||||||
|             return region.getEndPoint() + "?" + apiParams; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         String encodedApiKey; |         String encodedApiKey; | ||||||
|         try { |         try { | ||||||
|             encodedApiKey = URLEncoder.encode(apiKey, "UTF-8"); |             encodedApiKey = URLEncoder.encode(apiKey, "UTF-8"); | ||||||
|  | |||||||
| @ -988,11 +988,12 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar | |||||||
|             if (host != null) { |             if (host != null) { | ||||||
|                 s_logger.debug("Removing host entry for ssvm id=" + vmId); |                 s_logger.debug("Removing host entry for ssvm id=" + vmId); | ||||||
|                 _hostDao.remove(host.getId()); |                 _hostDao.remove(host.getId()); | ||||||
|             } |  | ||||||
|                 //Expire the download urls in the entire zone for templates and volumes. |                 //Expire the download urls in the entire zone for templates and volumes. | ||||||
|                 _tmplStoreDao.expireDnldUrlsForZone(host.getDataCenterId()); |                 _tmplStoreDao.expireDnldUrlsForZone(host.getDataCenterId()); | ||||||
|                 _volumeStoreDao.expireDnldUrlsForZone(host.getDataCenterId()); |                 _volumeStoreDao.expireDnldUrlsForZone(host.getDataCenterId()); | ||||||
|                 return true; |                 return true; | ||||||
|  |             } | ||||||
|  |             return false; | ||||||
|         } catch (ResourceUnavailableException e) { |         } catch (ResourceUnavailableException e) { | ||||||
|             s_logger.warn("Unable to expunge " + ssvm, e); |             s_logger.warn("Unable to expunge " + ssvm, e); | ||||||
|             return false; |             return false; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user