[PATCH 10/4] virsh: split out virsh-interface.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Another relatively easy split, since helper functions were fixed
in the previous patch.

* tools/virsh-interface.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-interface.c: Likewise.
(vshCommandOptInterfaceBy): Check flags.
---
 tools/Makefile.am       |  2 +-
 tools/virsh-interface.c | 28 +++++++++++++++++++---------
 tools/virsh-interface.h | 42 ++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.c           |  2 +-
 4 files changed, 63 insertions(+), 11 deletions(-)
 create mode 100644 tools/virsh-interface.h

diff --git a/tools/Makefile.am b/tools/Makefile.am
index a3e5ff4..4d46a98 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -109,8 +109,8 @@ virsh_SOURCES =							\
 		virsh-domain.c virsh-domain.h			\
 		virsh-domain-monitor.c virsh-domain-monitor.h	\
 		virsh-host.c virsh-host.h			\
+		virsh-interface.c virsh-interface.h		\
 		$(NULL)
-#		virsh-interface.c virsh-interface.h		\
 #		virsh-network.c virsh-network.h			\
 #		virsh-nodedev.c virsh-nodedev.h			\
 #		virsh-nwfilter.c virsh-nwfilter.h		\
diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c
index e43aa91..da02168 100644
--- a/tools/virsh-interface.c
+++ b/tools/virsh-interface.c
@@ -23,18 +23,28 @@
  *
  */

-/* default is lookup by Name and MAC */
-#define vshCommandOptInterface(_ctl, _cmd, _name)                    \
-    vshCommandOptInterfaceBy(_ctl, _cmd, NULL, _name,                \
-                             VSH_BYMAC|VSH_BYNAME)
+#include <config.h>
+#include "virsh-interface.h"

-static virInterfacePtr
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xpath.h>
+#include <libxml/xmlsave.h>
+
+#include "internal.h"
+#include "buf.h"
+#include "memory.h"
+#include "util.h"
+#include "xml.h"
+
+virInterfacePtr
 vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
                          const char *optname,
-                         const char **name, int flag)
+                         const char **name, unsigned int flags)
 {
     virInterfacePtr iface = NULL;
     const char *n = NULL;
+    virCheckFlags(VSH_BYNAME | VSH_BYMAC, NULL);

     if (!optname)
        optname = "interface";
@@ -51,13 +61,13 @@ vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
         *name = n;

     /* try it by NAME */
-    if (flag & VSH_BYNAME) {
+    if (flags & VSH_BYNAME) {
         vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface NAME\n",
                  cmd->def->name, optname);
         iface = virInterfaceLookupByName(ctl->conn, n);
     }
     /* try it by MAC */
-    if (iface == NULL && (flag & VSH_BYMAC)) {
+    if (!iface && (flags & VSH_BYMAC)) {
         vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface MAC\n",
                  cmd->def->name, optname);
         iface = virInterfaceLookupByMACString(ctl->conn, n);
@@ -999,7 +1009,7 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd)
     return ret;
 }

-static const vshCmdDef ifaceCmds[] = {
+const vshCmdDef ifaceCmds[] = {
     {"iface-begin", cmdInterfaceBegin, opts_interface_begin,
      info_interface_begin, 0},
     {"iface-bridge", cmdInterfaceBridge, opts_interface_bridge,
diff --git a/tools/virsh-interface.h b/tools/virsh-interface.h
new file mode 100644
index 0000000..2292cef
--- /dev/null
+++ b/tools/virsh-interface.h
@@ -0,0 +1,42 @@
+/*
+ * virsh-interface.c: Commands to manage host interface
+ *
+ * Copyright (C) 2005, 2007-2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library;  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ *  Daniel Veillard <veillard@xxxxxxxxxx>
+ *  Karel Zak <kzak@xxxxxxxxxx>
+ *  Daniel P. Berrange <berrange@xxxxxxxxxx>
+ *
+ */
+
+#ifndef VIRSH_INTERFACE_H
+# define VIRSH_INTERFACE_H
+
+# include "virsh.h"
+
+virInterfacePtr vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
+                                         const char *optname,
+                                         const char **name, unsigned int flags);
+
+/* default is lookup by Name and MAC */
+# define vshCommandOptInterface(_ctl, _cmd, _name)                    \
+    vshCommandOptInterfaceBy(_ctl, _cmd, NULL, _name,                \
+                             VSH_BYMAC|VSH_BYNAME)
+
+extern const vshCmdDef ifaceCmds[];
+
+#endif /* VIRSH_INTERFACE_H */
diff --git a/tools/virsh.c b/tools/virsh.c
index fe79b7c..d7fd408 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -77,6 +77,7 @@
 #include "virsh-domain.h"
 #include "virsh-domain-monitor.h"
 #include "virsh-host.h"
+#include "virsh-interface.h"

 static char *progname;

@@ -2815,7 +2816,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
     return true;
 }

-#include "virsh-interface.c"
 #include "virsh-network.c"
 #include "virsh-nodedev.c"
 #include "virsh-nwfilter.c"
-- 
1.7.11.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]