virNetworkObjMacMgrAdd does not ensure dnsmasqStateDir exists before writing files there
Software environment
- Operating system:
Fedora 36 - Architecture:
amd64 - kernel version:
5.18.7-200.fc36.x86_64 - libvirt version:
8.1.0-2.fc36 - Hypervisor and version:
qemu-kvm (6.2.0-12.fc36)
Description of problem
The dnsmasq state directory (/var/lib/libvirt/dnsmasq) is used by virNetworkObj to store the macmap. However, virNetworkObjMacMgrAdd does not ensure that the dnsmasqStateDir directory exists before writing to files there. If the directory doesn't exist, the following error is printed:
File "/usr/lib64/python3.10/site-packages/libvirt.py", line 1353, in create
raise libvirtError('virDomainCreate() failed')
libvirt.libvirtError: Failed to create file '/var/lib/libvirt/dnsmasq/virbr1.macs.new': No such file or directory
This directory is only created when starting a network that requests a DHCP server. Normally the default Network takes care of this, but if the default Network has not previously been started, a DHCP-less Network does not work.
Steps to reproduce
- Stop all networks:
virsh -c qemu:///system net-destroy default - Remove the state dir:
rm -rf /var/lib/libvirt/dnsmasq - Define a Network that does not use DHCP.
# virsh -c qemu:///system net-dumpxml test-state <network> <name>test-state</name> <uuid>3ef98e80-d5ce-4c2f-a295-6fe729453dfc</uuid> <bridge name='virbr1' stp='on' delay='0'/> <mac address='52:54:00:0b:0c:0d'/> </network> - Start a Domain attached to the new
test-stateNetwork.
Edited by Mike Haboustak