Re: [PATCH v2 04/14] nodedev: Use switch for virNodeDeviceObjHasCap and virNodeDeviceCapMatch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 05/26/2017 03:14 AM, Peter Krempa wrote:
> On Thu, May 25, 2017 at 15:57:01 -0400, John Ferlan wrote:
>> In order to ensure that whenever something is added to virNodeDevCapType
>> that both functions are considered for processing of a new capability,
>> change the if-then-else construct into a switch statement.
>>
>> Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
>> ---
>>  src/conf/virnodedeviceobj.c | 80 +++++++++++++++++++++++++++++++++------------
>>  1 file changed, 60 insertions(+), 20 deletions(-)
>>
>> diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
>> index bbb6eeb..913cdda 100644
>> --- a/src/conf/virnodedeviceobj.c
>> +++ b/src/conf/virnodedeviceobj.c
>> @@ -48,19 +48,41 @@ virNodeDeviceObjHasCap(const virNodeDeviceObj *dev,
>>      while (caps) {
>>          if (STREQ(cap, virNodeDevCapTypeToString(caps->data.type))) {
>>              return 1;
>> -        } else if (caps->data.type == VIR_NODE_DEV_CAP_SCSI_HOST) {
>> -            if ((STREQ(cap, fc_host_cap) &&
>> -                (caps->data.scsi_host.flags &
>> -                 VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) ||
>> -                (STREQ(cap, vports_cap) &&
>> -                (caps->data.scsi_host.flags &
>> -                 VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)))
>> -                return 1;
>> -        } else if (caps->data.type == VIR_NODE_DEV_CAP_PCI_DEV) {
>> -            if ((STREQ(cap, mdev_types)) &&
>> -                (caps->data.pci_dev.flags &
>> -                 VIR_NODE_DEV_CAP_FLAG_PCI_MDEV))
>> -                return 1;
>> +        } else {
>> +            switch (caps->data.type) {
>> +            case VIR_NODE_DEV_CAP_PCI_DEV:
>> +                if ((STREQ(cap, mdev_types)) &&
>> +                    (caps->data.pci_dev.flags &
>> +                     VIR_NODE_DEV_CAP_FLAG_PCI_MDEV))
> 
> Since you are touching this, put this on a single line. It looks very
> ugly this way. It also fits into the 80 col boundary, so I don't see a
> reaosn for this.

For MDEV - it can fit, for SCSI_HOST, not as clean, but it could be:

                if ((STREQ(cap, fc_host_cap) && (caps->data.scsi_host.flags &
                     VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) ||
                    (STREQ(cap, vports_cap) && (caps->data.scsi_host.flags &
                     VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)))
                    return 1;

Although I'm not sure I like the way that looks.

So, as an option I could also:

...
    virNodeDevCapSCSIHostPtr scsi_host;
...

and

            case VIR_NODE_DEV_CAP_SCSI_HOST:
                scsi_host = &caps->data.scsi_host;
                if ((STREQ(cap, fc_host_cap) &&
                    (scsi_host->flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST)) ||
                    (STREQ(cap, vports_cap) &&
                    (scsi_host->flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS)))
                    return 1;

and

        case VIR_NODE_DEV_CAP_SCSI_HOST:
            scsi_host = &cap->data.scsi_host;
            if (type == VIR_NODE_DEV_CAP_FC_HOST &&
                (scsi_host->flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST))
                return true;

            if (type == VIR_NODE_DEV_CAP_VPORTS &&
                (scsi_host->flags & VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS))
                return true;


But does that "violate" the too many changes at once "guideline"? 


John

> 
> ACK with this adjustment applied to the whole patch.
> 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux