[libvirt] [PATCH] Mark defined networks as persistent

We aren't setting the persistent bit when a network is defined, so 'destroy' makes them disappear (though they will reappear later since their persistent config is never removed). Attached patch fixes this. Thanks, Cole

Cole Robinson wrote:
We aren't setting the persistent bit when a network is defined, so 'destroy' makes them disappear (though they will reappear later since their persistent config is never removed).
Attached patch fixes this.
Hi Cole, Looks like you're on the right track. My reflex was to test for it... What before/after behavior change should I see? I tried this: cat <<EOF > net.xml <network> <name>N</name> <ip address="192.168.199.1" netmask="255.255.255.0"></ip> </network> EOF qemud/libvirtd & src/virsh 'net-define net.xml; net-destroy N; net-list' Then net-dumpxml N shows it's still there, as it should be. Of course, net-undefine does get rid of it for good, but you mentioned "destroy" above. Did I miss something?
diff --git a/src/network_conf.c b/src/network_conf.c index e19f0fe..6ad0d01 100644 --- a/src/network_conf.c +++ b/src/network_conf.c @@ -747,6 +747,7 @@ virNetworkObjPtr virNetworkLoadConfig(virConnectPtr conn, goto error;
net->autostart = autostart; + net->persistent = 1;
VIR_FREE(configFile); VIR_FREE(autostartLink); diff --git a/src/network_driver.c b/src/network_driver.c index 3c765c8..4b9c666 100644 --- a/src/network_driver.c +++ b/src/network_driver.c @@ -1153,6 +1153,8 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) { goto cleanup; def = NULL;
+ network->persistent = 1; + if (virNetworkSaveConfig(conn, driver->networkConfigDir, network->newDef ? network->newDef : network->def) < 0) {

Jim Meyering wrote:
Cole Robinson wrote:
We aren't setting the persistent bit when a network is defined, so 'destroy' makes them disappear (though they will reappear later since their persistent config is never removed).
Attached patch fixes this.
Hi Cole,
Looks like you're on the right track. My reflex was to test for it... What before/after behavior change should I see? I tried this:
cat <<EOF > net.xml <network> <name>N</name> <ip address="192.168.199.1" netmask="255.255.255.0"></ip> </network> EOF qemud/libvirtd & src/virsh 'net-define net.xml; net-destroy N; net-list'
Then net-dumpxml N shows it's still there, as it should be. Of course, net-undefine does get rid of it for good, but you mentioned "destroy" above. Did I miss something?
To answer my own question, Yes ;-) we need net-lists' --all option. Before the patch, running this src/virsh 'net-define net.xml; net-destroy N; net-list --all' lists no network. After your patch, it lists N. So, ACK.

Jim Meyering wrote:
Cole Robinson wrote:
We aren't setting the persistent bit when a network is defined, so 'destroy' makes them disappear (though they will reappear later since their persistent config is never removed).
Attached patch fixes this.
Hi Cole,
Looks like you're on the right track. My reflex was to test for it... What before/after behavior change should I see? I tried this:
cat <<EOF > net.xml <network> <name>N</name> <ip address="192.168.199.1" netmask="255.255.255.0"></ip> </network> EOF qemud/libvirtd & src/virsh 'net-define net.xml; net-destroy N; net-list'
Here's the test I've just written for this fix. Before the fix, it fails. After it, the test passes. But note, if I define another network, (all as a regular user), the test fails because that other network shows up in this tests "net-list --all" output. Hence my suggestion to add a single new prefix config string, or many more per-attribute-and-driver config variables.
From 638710cd9ab0a98ff142f221899bf7bd9845ad53 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 2 Mar 2009 14:46:20 +0100 Subject: [PATCH 1/2] virsh: tweak a format string to avoid emitting trailing space
* src/virsh.c (cmdNetworkList): Change format not to right-pad with spaces, as that would have required a trailing blank in an expected output file. --- src/virsh.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/virsh.c b/src/virsh.c index 298dde0..4ba3fe0 100644 --- a/src/virsh.c +++ b/src/virsh.c @@ -2596,7 +2596,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) qsort(&inactiveNames[0], maxinactive, sizeof(char*), namesorter); } } - vshPrintExtra(ctl, "%-20s %-10s %-10s\n", _("Name"), _("State"), _("Autostart")); + vshPrintExtra(ctl, "%-20s %-10s %s\n", _("Name"), _("State"), _("Autostart")); vshPrintExtra(ctl, "-----------------------------------------\n"); for (i = 0; i < maxactive; i++) { -- 1.6.2.rc1.285.gc5f54
From e9b60de9fd07fda9b6c5c703bd79c56c28804046 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 2 Mar 2009 14:32:59 +0100 Subject: [PATCH 2/2] tests: test for a recent fix
* tests/libvirtd-net-persist: New file. Test for the "Mark defined networks as persistent" fix. * tests/Makefile.am (test_scripts): Add it. --- tests/Makefile.am | 1 + tests/libvirtd-net-persist | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 0 deletions(-) create mode 100755 tests/libvirtd-net-persist diff --git a/tests/Makefile.am b/tests/Makefile.am index bec4f60..7479e03 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -81,6 +81,7 @@ test_scripts += \ daemon-conf \ define-dev-segfault \ int-overflow \ + libvirtd-net-persist \ read-bufsiz \ read-non-seekable \ start \ diff --git a/tests/libvirtd-net-persist b/tests/libvirtd-net-persist new file mode 100755 index 0000000..72f2bb8 --- /dev/null +++ b/tests/libvirtd-net-persist @@ -0,0 +1,54 @@ +#!/bin/sh +# ensure that net-destroy doesn't make network disappear (persistence-related) + +if test "$VERBOSE" = yes; then + set -x + libvirtd --version + virsh --version +fi + +test -z "$srcdir" && srcdir=$(pwd) +test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/.. +. "$srcdir/test-lib.sh" + +fail=0 + +pwd=$(pwd) || fail=1 +sock_dir="$pwd" +cat > conf <<EOF || fail=1 +unix_sock_dir = "$sock_dir" +log_outputs = "3:file:$pwd/log" +EOF + +cat > net.xml <<EOF || fail=1 +<network> + <name>N</name> + <ip address="192.168.199.1" netmask="255.255.255.0"></ip> +</network> +EOF + +cat > exp <<EOF || fail=1 +Network N defined from net.xml + +Network N destroyed + +Name State Autostart +----------------------------------------- +N inactive no + +EOF + +libvirtd --config=conf > libvirtd-log 2>&1 & pid=$! +sleep 1 + +url="qemu:///session?socket=@$sock_dir/libvirt-sock" +virsh -c "$url" \ + 'net-define net.xml; net-destroy N; net-list --all' > out 2>&1 \ + || fail=1 + +compare exp out || fail=1 + +printf "Shutting down network 'N'\n" > log-exp +compare log-exp libvirtd-log || fail=1 + +exit $fail -- 1.6.2.rc1.285.gc5f54

On Fri, Feb 27, 2009 at 10:57:20AM -0500, Cole Robinson wrote:
We aren't setting the persistent bit when a network is defined, so 'destroy' makes them disappear (though they will reappear later since their persistent config is never removed).
Attached patch fixes this.
ACK Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (3)
-
Cole Robinson
-
Daniel P. Berrange
-
Jim Meyering