]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Add new file for utility functions and move a few
authorPeter Krempa <pkrempa@redhat.com>
Mon, 10 Apr 2017 15:06:15 +0000 (17:06 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 12 Apr 2017 11:23:10 +0000 (13:23 +0200)
Don't accumulate helpers in virsh.c

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

index bfacaf214b133e58bb52852eb62ecc06ddfe4a17..56691c289e9f17e705b8a20a6aa4200af1d1dbc3 100644 (file)
@@ -226,6 +226,7 @@ virsh_SOURCES =                                                     \
                virsh-pool.c virsh-pool.h                       \
                virsh-secret.c virsh-secret.h                   \
                virsh-snapshot.c virsh-snapshot.h               \
+               virsh-util.c virsh-util.h                       \
                virsh-volume.c virsh-volume.h                   \
                $(NULL)
 
index 901a6ebef6277e3d288e7c7b09ebe20917f43a9c..4ade5651c7000a5f824a2c72d0c68adc30bcc0f2 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <config.h>
 #include "virsh-domain-monitor.h"
+#include "virsh-util.h"
 
 #include <libxml/parser.h>
 #include <libxml/tree.h>
index e5fb11a2e4229e1644a8514ac57447d855d3978f..d2f50177cc854de57f1ee8f499168311daf5a1bd 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <config.h>
 #include "virsh-domain.h"
+#include "virsh-util.h"
 
 #include <fcntl.h>
 #include <poll.h>
diff --git a/tools/virsh-util.c b/tools/virsh-util.c
new file mode 100644 (file)
index 0000000..98f16ff
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * virsh-util.c: helpers for virsh
+ *
+ * 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/>.
+ */
+
+#include <config.h>
+
+#include "virsh-util.h"
+
+#include "virfile.h"
+
+int
+virshDomainState(vshControl *ctl,
+                 virDomainPtr dom,
+                 int *reason)
+{
+    virDomainInfo info;
+    virshControlPtr priv = ctl->privData;
+
+    if (reason)
+        *reason = -1;
+
+    if (!priv->useGetInfo) {
+        int state;
+        if (virDomainGetState(dom, &state, reason, 0) < 0) {
+            virErrorPtr err = virGetLastError();
+            if (err && err->code == VIR_ERR_NO_SUPPORT)
+                priv->useGetInfo = true;
+            else
+                return -1;
+        } else {
+            return state;
+        }
+    }
+
+    /* fall back to virDomainGetInfo if virDomainGetState is not supported */
+    if (virDomainGetInfo(dom, &info) < 0)
+        return -1;
+    else
+        return info.state;
+}
+
+
+int
+virshStreamSink(virStreamPtr st ATTRIBUTE_UNUSED,
+                const char *bytes,
+                size_t nbytes,
+                void *opaque)
+{
+    int *fd = opaque;
+
+    return safewrite(*fd, bytes, nbytes);
+}
diff --git a/tools/virsh-util.h b/tools/virsh-util.h
new file mode 100644 (file)
index 0000000..207d578
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * virsh-util.h: helpers for virsh
+ *
+ * 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/>.
+ */
+
+#ifndef VIRSH_UTIL_H
+# define VIRSH_UTIL_H
+
+# include "virsh.h"
+
+int
+virshDomainState(vshControl *ctl,
+                 virDomainPtr dom,
+                 int *reason);
+
+int
+virshStreamSink(virStreamPtr st,
+                const char *bytes,
+                size_t nbytes,
+                void *opaque);
+
+#endif /* VIRSH_UTIL_H */
index 32ffb8149ea1b62e8740e190e67179e6275b34aa..ddd41d229f052cac77592373979578d93c44f57c 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <config.h>
 #include "virsh-volume.h"
+#include "virsh-util.h"
 
 #include <fcntl.h>
 
index 7eb51ab7dc40c93202cb101fc2c3b7bfd6979734..31e23bd27d1b26775b78de0e00f9a9aef972b1b3 100644 (file)
@@ -257,14 +257,6 @@ virshReconnect(vshControl *ctl, const char *name, bool readonly, bool force)
     return 0;
 }
 
-int virshStreamSink(virStreamPtr st ATTRIBUTE_UNUSED,
-                    const char *bytes, size_t nbytes, void *opaque)
-{
-    int *fd = opaque;
-
-    return safewrite(*fd, bytes, nbytes);
-}
-
 /* ---------------
  * Command Connect
  * ---------------
@@ -347,39 +339,6 @@ virshConnectionHandler(vshControl *ctl)
 }
 
 
-/* ---------------
- * Misc utils
- * ---------------
- */
-int
-virshDomainState(vshControl *ctl, virDomainPtr dom, int *reason)
-{
-    virDomainInfo info;
-    virshControlPtr priv = ctl->privData;
-
-    if (reason)
-        *reason = -1;
-
-    if (!priv->useGetInfo) {
-        int state;
-        if (virDomainGetState(dom, &state, reason, 0) < 0) {
-            virErrorPtr err = virGetLastError();
-            if (err && err->code == VIR_ERR_NO_SUPPORT)
-                priv->useGetInfo = true;
-            else
-                return -1;
-        } else {
-            return state;
-        }
-    }
-
-    /* fall back to virDomainGetInfo if virDomainGetState is not supported */
-    if (virDomainGetInfo(dom, &info) < 0)
-        return -1;
-    else
-        return info.state;
-}
-
 /*
  * Initialize connection.
  */
index fd552bb3a8c656329c50f54b6c75942ae49d8264..9e42ef9bb738983e32895e7de84b923a10c6f0b4 100644 (file)
@@ -145,9 +145,5 @@ typedef enum {
 } virshLookupByFlags;
 
 virConnectPtr virshConnect(vshControl *ctl, const char *uri, bool readonly);
-int virshDomainState(vshControl *ctl, virDomainPtr dom, int *reason);
-
-int virshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes,
-                    void *opaque);
 
 #endif /* VIRSH_H */