]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: split out virsh-domain.c
authorEric Blake <eblake@redhat.com>
Sat, 18 Aug 2012 04:00:42 +0000 (22:00 -0600)
committerEric Blake <eblake@redhat.com>
Sat, 18 Aug 2012 04:22:42 +0000 (22:22 -0600)
The virsh-domain.c file was pretty self-contained; the only
entry point was the table of command definitions.  The bulk
of this patch is making more functions in virsh.c reusable.
A later patch will clean up poor naming choices.

* tools/Makefile.am (virsh_SOURCES): Build virsh-domain.c.
* tools/virsh-domain.h: New file.
* tools/virsh.h (virshReportError, vshResetLibvirtError)
(vshAskReedit, vshStreamSink): Declare.
* tools/virsh.c: Switch from using .c to .h.
(virshReportError, vshResetLibvirtError, vshAskReedit)
(vshStreamSink, prettyCapacity): Export.
(vshCatchInt): Move...
* tools/virsh-domain.c: ...into sole user.  Use header.

tools/Makefile.am
tools/virsh-domain.c
tools/virsh-domain.h [new file with mode: 0644]
tools/virsh.c
tools/virsh.h

index 52a869987e56969ca6b96956a0c7c91464cd2b25..b8858920cca226c4cd1045dde3a75b6d45ce671a 100644 (file)
@@ -106,8 +106,8 @@ virt_host_validate_CFLAGS = \
 virsh_SOURCES =                                                        \
                console.c console.h                             \
                virsh.c virsh.h                                 \
+               virsh-domain.c virsh-domain.h                   \
                $(NULL)
-#              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             \
index dc8620e678a00f7ab0cd984a2ae9d165782ca26a..edbda91503f61b1c35eb5c1d812a6584c88e12c3 100644 (file)
  *
  */
 
+#include <config.h>
+#include "virsh-domain.h"
+
+#include <fcntl.h>
+#include <poll.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <termios.h>
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xpath.h>
+#include <libxml/xmlsave.h>
+
+#include "internal.h"
+#include "bitmap.h"
+#include "buf.h"
+#include "c-ctype.h"
+#include "conf/domain_conf.h"
+#include "console.h"
+#include "memory.h"
+#include "util.h"
+#include "virfile.h"
+#include "virkeycode.h"
+#include "virmacaddr.h"
+#include "virterror_internal.h"
+#include "virtypedparam.h"
+#include "xml.h"
+
 static const char *
 vshDomainVcpuStateToString(int state)
 {
@@ -1185,6 +1214,15 @@ print_job_progress(const char *label, unsigned long long remaining,
     fflush(stderr);
 }
 
+static volatile sig_atomic_t intCaught = 0;
+
+static void vshCatchInt(int sig ATTRIBUTE_UNUSED,
+                        siginfo_t *siginfo ATTRIBUTE_UNUSED,
+                        void *context ATTRIBUTE_UNUSED)
+{
+    intCaught = 1;
+}
+
 /*
  * "blockcopy" command
  */
@@ -8044,7 +8082,7 @@ cleanup:
     return ret;
 }
 
-static const vshCmdDef domManagementCmds[] = {
+const vshCmdDef domManagementCmds[] = {
     {"attach-device", cmdAttachDevice, opts_attach_device,
      info_attach_device, 0},
     {"attach-disk", cmdAttachDisk, opts_attach_disk,
diff --git a/tools/virsh-domain.h b/tools/virsh-domain.h
new file mode 100644 (file)
index 0000000..797462f
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * virsh-domain.h: Commands to manage domain
+ *
+ * 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@redhat.com>
+ *  Karel Zak <kzak@redhat.com>
+ *  Daniel P. Berrange <berrange@redhat.com>
+ *
+ */
+
+#ifndef VIRSH_DOMAIN_H
+#define VIRSH_DOMAIN_H
+
+# include "virsh.h"
+
+extern const vshCmdDef domManagementCmds[];
+
+#endif /* VIRSH_DOMAIN_H */
index 610236ba1bd4fe25e525602506c4e4480dd26be7..054047fdacee2316d90a1f27a2a937e5e2e9211a 100644 (file)
@@ -78,6 +78,8 @@
 #include "conf/domain_conf.h"
 #include "virtypedparam.h"
 
+#include "virsh-domain.h"
+
 static char *progname;
 
 static const vshCmdGrp cmdGroups[];
@@ -137,9 +139,9 @@ vshNameSorter(const void *a, const void *b)
     return vshStrcasecmp(*sa, *sb);
 }
 
-static double
-prettyCapacity(unsigned long long val,
-               const char **unit) {
+double
+prettyCapacity(unsigned long long val, const char **unit)
+{
     if (val < 1024) {
         *unit = "";
         return (double)val;
@@ -176,7 +178,7 @@ virshErrorHandler(void *unused ATTRIBUTE_UNUSED, virErrorPtr error)
 /*
  * Reset libvirt error on graceful fallback paths
  */
-static void
+void
 vshResetLibvirtError(void)
 {
     virFreeError(last_error);
@@ -191,7 +193,7 @@ vshResetLibvirtError(void)
  * twice during one command.  This case shouldn't really happen anyway,
  * and it's IMHO a bug that libvirt does that sometimes.
  */
-static void
+void
 virshReportError(vshControl *ctl)
 {
     if (last_error == NULL) {
@@ -216,15 +218,6 @@ out:
     vshResetLibvirtError();
 }
 
-static volatile sig_atomic_t intCaught = 0;
-
-static void vshCatchInt(int sig ATTRIBUTE_UNUSED,
-                        siginfo_t *siginfo ATTRIBUTE_UNUSED,
-                        void *context ATTRIBUTE_UNUSED)
-{
-    intCaught = 1;
-}
-
 /*
  * Detection of disconnections and automatic reconnection support
  */
@@ -310,7 +303,7 @@ vshPrintRaw(vshControl *ctl, ...)
  *         -1  on error
  *          0  otherwise
  */
-static int
+int
 vshAskReedit(vshControl *ctl, const char *msg)
 {
     int c = -1;
@@ -359,8 +352,8 @@ vshAskReedit(vshControl *ctl, const char *msg ATTRIBUTE_UNUSED)
 }
 #endif /* WIN32 */
 
-static int vshStreamSink(virStreamPtr st ATTRIBUTE_UNUSED,
-                         const char *bytes, size_t nbytes, void *opaque)
+int vshStreamSink(virStreamPtr st ATTRIBUTE_UNUSED,
+                  const char *bytes, size_t nbytes, void *opaque)
 {
     int *fd = opaque;
 
@@ -2873,7 +2866,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
     return true;
 }
 
-#include "virsh-domain.c"
 #include "virsh-domain-monitor.c"
 #include "virsh-host.c"
 #include "virsh-interface.c"
index 8680a0aa46ede0dc4447c2aa566245eefb433d99..7e505aa24c309bfa6315724a2e23b6ad804145b5 100644 (file)
@@ -329,6 +329,10 @@ char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item)
 char *editWriteToTempFile(vshControl *ctl, const char *doc);
 int   editFile(vshControl *ctl, const char *filename);
 char *editReadBackFile(vshControl *ctl, const char *filename);
+int vshAskReedit(vshControl *ctl, const char *msg);
+int vshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes,
+                  void *opaque);
+double prettyCapacity(unsigned long long val, const char **unit);
 
 /* Typedefs, function prototypes for job progress reporting.
  * There are used by some long lingering commands like
@@ -343,6 +347,12 @@ typedef struct __vshCtrlData {
 typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom,
                                      void *opaque);
 
+/* error handling */
+extern virErrorPtr last_error;
+void virshReportError(vshControl *ctl);
+void vshResetLibvirtError(void);
+
+/* allocation wrappers */
 void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);
 # define vshMalloc(_ctl, _sz)    _vshMalloc(_ctl, _sz, __FILE__, __LINE__)
 
@@ -365,6 +375,4 @@ char *_vshStrdup(vshControl *ctl, const char *s, const char *filename,
 # define realloc use_vshRealloc_instead_of_realloc
 # define strdup use_vshStrdup_instead_of_strdup
 
-extern virErrorPtr last_error;
-
 #endif /* VIRSH_H */