On 10/02/2013 05:31 AM, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange(a)redhat.com>
The veth device creation code run in two steps, first it looks
for two free veth device names, then it runs ip link to create
the veth pair. There is an obvious race between finding free
names and creating them, when guests are started in parallel.
Rewrite the code to loop and re-try creation if it fails, to
deal with the race condition.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/util/virnetdevveth.c | 151 +++++++++++++++++++++++++++++------------------
1 file changed, 92 insertions(+), 59 deletions(-)
/* Functions */
+
+static int virNetDevVethExists(int devNum)
+{
+ int ret;
+ char *path = NULL;
+ if (virAsprintf(&path, "/sys/class/net/veth%d/", devNum) < 0)
+ return -1;
+ ret = virFileExists(path) ? 1 : 0;
Looks a bit funny for converting a bool to int. I probably would have
skipped the ternary; but what you did is not wrong.
- if (virAsprintf(veth, "veth%d", devNum) < 0)
- return -1;
+ for (devNum = startDev ; devNum < MAX_DEV_NUM ; devNum++) {
How did this get past 'make syntax-check'? We cleaned up the code base
to avoid space before ';'.
ACK with the syntax cleaned up.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org