Allon Mureinik has posted comments on this change.

Change subject: engine: Disk interface validation
......................................................................


Patch Set 1: Code-Review-1

(6 comments)

The concept of this patch seems sound to me, but there's a potential NPE in the 
current implementation.

See inline comments for details.

....................................................
File 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetAllAttachableDisksQuery.java
Line 23:                 .getDiskDao()
Line 24:                 
.getAllAttachableDisksByPoolId(getParameters().getStoragePoolId(),
Line 25:                         getParameters().getVmId(),
Line 26:                         getUserID(),
Line 27:                         getParameters().isFiltered());
If this list is empty you should return - there's no reason to make an 
additional (expensive) DB call.
Line 28: 
Line 29:         ArrayList<Disk> filteredDiskList = new ArrayList<Disk>();
Line 30: 
Line 31:         VM vm = 
DbFacade.getInstance().getVmDao().get(getParameters().getVmId());


Line 27:                         getParameters().isFiltered());
Line 28: 
Line 29:         ArrayList<Disk> filteredDiskList = new ArrayList<Disk>();
Line 30: 
Line 31:         VM vm = 
DbFacade.getInstance().getVmDao().get(getParameters().getVmId());
You should use the filtered version:
DbFacade.getInstance().getVmDao().get(getParameters().getVmId(), getUserID(), 
getParameters().isFiltered());
Line 32: 
Line 33:         List<String> supportedDiskInterfaceNames =
Line 34:                 getOsRepository().getDiskInterfaces(vm.getOs(), 
vm.getVdsGroupCompatibilityVersion());
Line 35: 


Line 30: 
Line 31:         VM vm = 
DbFacade.getInstance().getVmDao().get(getParameters().getVmId());
Line 32: 
Line 33:         List<String> supportedDiskInterfaceNames =
Line 34:                 getOsRepository().getDiskInterfaces(vm.getOs(), 
vm.getVdsGroupCompatibilityVersion());
There is no guarantee the VM who's ID is passed actually exists.

In the old implementation, the query would silently return an empty list - 
which kind of makes sense - there are no disks you can attach to a non-existent 
VM.
After this patch, passing such a parameter would result in a 
NullPointerException.
I'd add a check before this line:

VM vm = DbFacade....
if (vm == null) {
   setReturnValue(Collections.emptyList());
   return;
}
Line 35: 
Line 36:         List<DiskInterface> supportedDiskInterfaces = new 
ArrayList<DiskInterface>();
Line 37: 
Line 38:         for (String interfaceName : supportedDiskInterfaceNames) {


Line 32: 
Line 33:         List<String> supportedDiskInterfaceNames =
Line 34:                 getOsRepository().getDiskInterfaces(vm.getOs(), 
vm.getVdsGroupCompatibilityVersion());
Line 35: 
Line 36:         List<DiskInterface> supportedDiskInterfaces = new 
ArrayList<DiskInterface>();
Searching this collection is an O(n) operation - changing it to a HashSet 
instead of ArrayList will increase performance.
Line 37: 
Line 38:         for (String interfaceName : supportedDiskInterfaceNames) {
Line 39:             try {
Line 40:                 
supportedDiskInterfaces.add(DiskInterface.valueOf(interfaceName));


Line 38:         for (String interfaceName : supportedDiskInterfaceNames) {
Line 39:             try {
Line 40:                 
supportedDiskInterfaces.add(DiskInterface.valueOf(interfaceName));
Line 41:             } catch (IllegalArgumentException e) {
Line 42:                 // ignore if we can't find the enum value.
I'd log here.
Line 43:             }
Line 44:         }
Line 45: 
Line 46:         for (Disk disk : diskList) {


....................................................
File 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskValidator.java
Line 84:         for (String interfaceName : supportedDiskInterfaceNames) {
Line 85:             try {
Line 86:                 
supportedDiskInterfaces.add(DiskInterface.valueOf(interfaceName));
Line 87:             } catch (IllegalArgumentException e) {
Line 88:                 // ignore if we can't find the enum value.
I'd log here
Line 89:             }
Line 90:         }
Line 91: 
Line 92:         return 
(!supportedDiskInterfaces.contains(disk.getDiskInterface()))


-- 
To view, visit http://gerrit.ovirt.org/18648
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ibe095557089aa5670c50eaa120eac9f60e13aea0
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Gustavo Frederico Temple Pedrosa <[email protected]>
Gerrit-Reviewer: Allon Mureinik <[email protected]>
Gerrit-Reviewer: Daniel Erez <[email protected]>
Gerrit-Reviewer: Itamar Heim <[email protected]>
Gerrit-Reviewer: Leonardo Bianconi <[email protected]>
Gerrit-Reviewer: Roy Golan <[email protected]>
Gerrit-Reviewer: Vitor de Lima <[email protected]>
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to