[libvirt] [PATCH] virsh: Avoid undefine active interface

* tools/virsh.c: libvirt should check if current interface is active before undefine the interface, and don't allow to undefine a active interface. --- tools/virsh.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index bd6fea7..899bf25 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -5675,6 +5675,16 @@ cmdInterfaceUndefine(vshControl *ctl, const vshCmd *cmd) if (!(iface = vshCommandOptInterface(ctl, cmd, &name))) return false; + if (virInterfaceIsActive(iface)) { + vshError(ctl, + _("a active interface like %s cannot be undefined;\n" + "to undefine, first destroy then undefine" + " using its name or MAC address"), + name); + virInterfaceFree(iface); + return false; + } + if (virInterfaceUndefine(iface) == 0) { vshPrint(ctl, _("Interface %s undefined\n"), name); } else { -- 1.7.1

On Fri, Jul 15, 2011 at 12:04:17AM +0800, ajia@redhat.com wrote:
* tools/virsh.c: libvirt should check if current interface is active before undefine the interface, and don't allow to undefine a active interface. --- tools/virsh.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c index bd6fea7..899bf25 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -5675,6 +5675,16 @@ cmdInterfaceUndefine(vshControl *ctl, const vshCmd *cmd) if (!(iface = vshCommandOptInterface(ctl, cmd, &name))) return false;
+ if (virInterfaceIsActive(iface)) { + vshError(ctl, + _("a active interface like %s cannot be undefined;\n" + "to undefine, first destroy then undefine" + " using its name or MAC address"), + name); + virInterfaceFree(iface); + return false; + }
This kind of check should be done in the drivers, rather than virsh 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 :|

On 07/15/2011 12:04 AM, Daniel P. Berrange wrote:
On Fri, Jul 15, 2011 at 12:04:17AM +0800, ajia@redhat.com wrote:
* tools/virsh.c: libvirt should check if current interface is active before undefine the interface, and don't allow to undefine a active interface. --- tools/virsh.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c index bd6fea7..899bf25 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -5675,6 +5675,16 @@ cmdInterfaceUndefine(vshControl *ctl, const vshCmd *cmd) if (!(iface = vshCommandOptInterface(ctl, cmd,&name))) return false;
+ if (virInterfaceIsActive(iface)) { + vshError(ctl, + _("a active interface like %s cannot be undefined;\n" + "to undefine, first destroy then undefine" + " using its name or MAC address"), + name); + virInterfaceFree(iface); + return false; + } This kind of check should be done in the drivers, rather than virsh
Regards, Daniel Yeah, Michal has sent patches to update drivers, thanks for your review.
Regards, Alex
participants (3)
-
ajia
-
ajia@redhat.com
-
Daniel P. Berrange