[libvirt] [PATCH v1 3/3] qemu_conf.c: introduce qemuAddRemoveSharedDeviceInternal

Daniel Henrique Barboza posted 3 patches 6 years, 5 months ago
[libvirt] [PATCH v1 3/3] qemu_conf.c: introduce qemuAddRemoveSharedDeviceInternal
Posted by Daniel Henrique Barboza 6 years, 5 months ago
After the previous commits, qemuAddSharedDevice() and
qemuRemoveSharedDevice() are now the same code with a different
flag to call the internal functions.

This patch aggregates the common code into a new function called
qemuAddRemoveSharedDeviceInternal() to further reduce
code repetition. Both qemuAddSharedDevice() and
qemuRemoveSharedDevice() are kept since they are public
functions used elsewhere.

No functional change was made.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 src/qemu/qemu_conf.c | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 422f0d743d..6ce2d10ac7 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1793,6 +1793,26 @@ qemuAddRemoveSharedHostdevInternal(virQEMUDriverPtr driver,
 
 }
 
+static int
+qemuAddRemoveSharedDeviceInternal(virQEMUDriverPtr driver,
+                                  virDomainDeviceDefPtr dev,
+                                  const char *name,
+                                  bool addDevice)
+{
+    /* Currently the only conflicts we have to care about for
+     * the shared disk and shared host device is "sgio" setting,
+     * which is only valid for block disk and scsi host device.
+     */
+    if (dev->type == VIR_DOMAIN_DEVICE_DISK)
+        return qemuAddRemoveSharedDiskInternal(driver, dev->data.disk,
+                                               name, addDevice);
+    else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV)
+        return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostdev,
+                                                  name, addDevice);
+    else
+        return 0;
+}
+
 
 /* qemuAddSharedDevice:
  * @driver: Pointer to qemu driver struct
@@ -1808,18 +1828,7 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
                     virDomainDeviceDefPtr dev,
                     const char *name)
 {
-    /* Currently the only conflicts we have to care about for
-     * the shared disk and shared host device is "sgio" setting,
-     * which is only valid for block disk and scsi host device.
-     */
-    if (dev->type == VIR_DOMAIN_DEVICE_DISK)
-        return qemuAddRemoveSharedDiskInternal(driver, dev->data.disk,
-                                               name, true);
-    else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV)
-        return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostdev,
-                                                  name, true);
-    else
-        return 0;
+    return qemuAddRemoveSharedDeviceInternal(driver, dev, name, true);
 }
 
 
@@ -1846,14 +1855,7 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver,
                        virDomainDeviceDefPtr dev,
                        const char *name)
 {
-    if (dev->type == VIR_DOMAIN_DEVICE_DISK)
-        return qemuAddRemoveSharedDiskInternal(driver, dev->data.disk,
-                                               name, false);
-    else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV)
-        return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostdev,
-                                                  name, false);
-    else
-        return 0;
+    return qemuAddRemoveSharedDeviceInternal(driver, dev, name, false);
 }
 
 
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v1 3/3] qemu_conf.c: introduce qemuAddRemoveSharedDeviceInternal
Posted by Michal Privoznik 6 years, 5 months ago
On 9/4/19 1:06 AM, Daniel Henrique Barboza wrote:
> After the previous commits, qemuAddSharedDevice() and
> qemuRemoveSharedDevice() are now the same code with a different
> flag to call the internal functions.
> 
> This patch aggregates the common code into a new function called
> qemuAddRemoveSharedDeviceInternal() to further reduce
> code repetition. Both qemuAddSharedDevice() and
> qemuRemoveSharedDevice() are kept since they are public
> functions used elsewhere.
> 
> No functional change was made.
> 
> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
> ---
>   src/qemu/qemu_conf.c | 42 ++++++++++++++++++++++--------------------
>   1 file changed, 22 insertions(+), 20 deletions(-)
> 
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index 422f0d743d..6ce2d10ac7 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -1793,6 +1793,26 @@ qemuAddRemoveSharedHostdevInternal(virQEMUDriverPtr driver,
>   
>   }
>   
> +static int
> +qemuAddRemoveSharedDeviceInternal(virQEMUDriverPtr driver,

Again, qemuSharedDeviceAddRemoveInternal()?

I've made all the changes and keep them locally. Just let me know how 
you feel about my suggestions so that I can ACK these and push them.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v1 3/3] qemu_conf.c: introduce qemuAddRemoveSharedDeviceInternal
Posted by Daniel Henrique Barboza 6 years, 5 months ago

On 9/9/19 9:55 AM, Michal Privoznik wrote:
> On 9/4/19 1:06 AM, Daniel Henrique Barboza wrote:
>> After the previous commits, qemuAddSharedDevice() and
>> qemuRemoveSharedDevice() are now the same code with a different
>> flag to call the internal functions.
>>
>> This patch aggregates the common code into a new function called
>> qemuAddRemoveSharedDeviceInternal() to further reduce
>> code repetition. Both qemuAddSharedDevice() and
>> qemuRemoveSharedDevice() are kept since they are public
>> functions used elsewhere.
>>
>> No functional change was made.
>>
>> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
>> ---
>>   src/qemu/qemu_conf.c | 42 ++++++++++++++++++++++--------------------
>>   1 file changed, 22 insertions(+), 20 deletions(-)
>>
>> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
>> index 422f0d743d..6ce2d10ac7 100644
>> --- a/src/qemu/qemu_conf.c
>> +++ b/src/qemu/qemu_conf.c
>> @@ -1793,6 +1793,26 @@ 
>> qemuAddRemoveSharedHostdevInternal(virQEMUDriverPtr driver,
>>     }
>>   +static int
>> +qemuAddRemoveSharedDeviceInternal(virQEMUDriverPtr driver,
>
> Again, qemuSharedDeviceAddRemoveInternal()?
>
> I've made all the changes and keep them locally. Just let me know how 
> you feel about my suggestions so that I can ACK these and push them.


I'm fine with the changes but it seems like Pavel already pushed the
patches. Feel free to create a patch of your own with these changes
and I'll ack/review it no problem.


Thanks,

DHB

>
> Michal

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