[libvirt] [PATCH] network_conf: check sysfs if the bridge exists on host for user created bridges
Shivaprasad bhat
shivaprasadbhat at gmail.com
Mon Mar 9 15:07:45 UTC 2015
On Mon, Mar 9, 2015 at 8:32 PM, Daniel P. Berrange <berrange at redhat.com> wrote:
> On Mon, Mar 09, 2015 at 08:30:08PM +0530, Shivaprasad G Bhat wrote:
>> virNetworkBridgeInUse() doesn't check if the bridge is manually created
>> outside of libvirt. Check the bridge name file in the sysfs to see if the
>> bridge is in use.
>>
>> Signed-off-by: Shivaprasad G Bhat <sbhat at linux.vnet.ibm.com>
>> ---
>> src/conf/network_conf.c | 16 ++++++++++++++--
>> 1 file changed, 14 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
>> index d0e7e1b..4f90425 100644
>> --- a/src/conf/network_conf.c
>> +++ b/src/conf/network_conf.c
>> @@ -3074,16 +3074,28 @@ int virNetworkBridgeInUse(virNetworkObjListPtr nets,
>> {
>> size_t i;
>> unsigned int ret = 0;
>> + int defined_bridge = 0;
>> + char *path = NULL;
>>
>> for (i = 0; i < nets->count; i++) {
>> virNetworkObjLock(nets->objs[i]);
>> if (nets->objs[i]->def->bridge &&
>> - STREQ(nets->objs[i]->def->bridge, bridge) &&
>> - !(skipname && STREQ(nets->objs[i]->def->name, skipname)))
>> + STREQ(nets->objs[i]->def->bridge, bridge)) {
>> + defined_bridge = 1;
>> + if (!(skipname && STREQ(nets->objs[i]->def->name, skipname)))
>> ret = 1;
>> + }
>> virNetworkObjUnlock(nets->objs[i]);
>> }
>>
>> + /* Bridge might have been created by a user manually outside libvirt */
>> + if (!defined_bridge && !ret) {
>> + if (virAsprintf(&path, "/sys/class/net/%s/", bridge) < 0)
>> + return -1;
>> + ret = virFileExists(path) ? 1 : 0;
>> + VIR_FREE(path);
>> + }
>
> You should use virNetDevExists() instead of poking in sysfs
>
Thanks Dan. I'll send the v2 using virNetDevExists() as suggested.
Regards,
Shiva
> Regards,
> Daniel
> --
> |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
> |: http://libvirt.org -o- http://virt-manager.org :|
> |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
> |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
More information about the libvir-list
mailing list