|
|
34b321 |
From f0e4ec43a0a3af6f1e385fae17527ed76cdb00e4 Mon Sep 17 00:00:00 2001
|
|
|
34b321 |
From: John Snow <jsnow@redhat.com>
|
|
|
34b321 |
Date: Mon, 23 Nov 2015 17:38:32 +0100
|
|
|
34b321 |
Subject: [PATCH 13/27] qemu-io: Move remaining helpers from cmd.c
|
|
|
34b321 |
|
|
|
34b321 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
34b321 |
Message-id: <1448300320-7772-14-git-send-email-jsnow@redhat.com>
|
|
|
34b321 |
Patchwork-id: 68437
|
|
|
34b321 |
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 13/21] qemu-io: Move remaining helpers from cmd.c
|
|
|
34b321 |
Bugzilla: 1272523
|
|
|
34b321 |
RH-Acked-by: Thomas Huth <thuth@redhat.com>
|
|
|
34b321 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
34b321 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
34b321 |
|
|
|
34b321 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
34b321 |
|
|
|
34b321 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
34b321 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
34b321 |
(cherry picked from commit 0b613881ae8fc59359b3d91e666fea6c9b1e731b)
|
|
|
34b321 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
34b321 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
34b321 |
---
|
|
|
34b321 |
Makefile | 2 +-
|
|
|
34b321 |
cmd.c | 139 ---------------------------------------------------------
|
|
|
34b321 |
cmd.h | 14 ------
|
|
|
34b321 |
qemu-io-cmds.c | 104 ++++++++++++++++++++++++++++++++++++++++++
|
|
|
34b321 |
4 files changed, 105 insertions(+), 154 deletions(-)
|
|
|
34b321 |
delete mode 100644 cmd.c
|
|
|
34b321 |
|
|
|
34b321 |
diff --git a/Makefile b/Makefile
|
|
|
34b321 |
index f28ce29..f403057 100644
|
|
|
34b321 |
--- a/Makefile
|
|
|
34b321 |
+++ b/Makefile
|
|
|
34b321 |
@@ -205,7 +205,7 @@ qemu-img.o: qemu-img-cmds.h
|
|
|
34b321 |
|
|
|
34b321 |
qemu-img$(EXESUF): qemu-img.o $(block-obj-y) libqemuutil.a libqemustub.a
|
|
|
34b321 |
qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) libqemuutil.a libqemustub.a
|
|
|
34b321 |
-qemu-io$(EXESUF): qemu-io.o qemu-io-cmds.o cmd.o $(block-obj-y) libqemuutil.a libqemustub.a
|
|
|
34b321 |
+qemu-io$(EXESUF): qemu-io.o qemu-io-cmds.o $(block-obj-y) libqemuutil.a libqemustub.a
|
|
|
34b321 |
|
|
|
34b321 |
qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
|
|
|
34b321 |
|
|
|
34b321 |
diff --git a/cmd.c b/cmd.c
|
|
|
34b321 |
deleted file mode 100644
|
|
|
34b321 |
index 26d38a8..0000000
|
|
|
34b321 |
--- a/cmd.c
|
|
|
34b321 |
+++ /dev/null
|
|
|
34b321 |
@@ -1,139 +0,0 @@
|
|
|
34b321 |
-/*
|
|
|
34b321 |
- * Copyright (c) 2003-2005 Silicon Graphics, Inc.
|
|
|
34b321 |
- * All Rights Reserved.
|
|
|
34b321 |
- *
|
|
|
34b321 |
- * This program is free software; you can redistribute it and/or
|
|
|
34b321 |
- * modify it under the terms of the GNU General Public License as
|
|
|
34b321 |
- * published by the Free Software Foundation.
|
|
|
34b321 |
- *
|
|
|
34b321 |
- * This program is distributed in the hope that it would be useful,
|
|
|
34b321 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
34b321 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
34b321 |
- * GNU General Public License for more details.
|
|
|
34b321 |
- *
|
|
|
34b321 |
- * You should have received a copy of the GNU General Public License
|
|
|
34b321 |
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
34b321 |
- */
|
|
|
34b321 |
-
|
|
|
34b321 |
-#include <stdio.h>
|
|
|
34b321 |
-#include <stdlib.h>
|
|
|
34b321 |
-#include <string.h>
|
|
|
34b321 |
-#include <ctype.h>
|
|
|
34b321 |
-#include <errno.h>
|
|
|
34b321 |
-#include <sys/time.h>
|
|
|
34b321 |
-#include <getopt.h>
|
|
|
34b321 |
-
|
|
|
34b321 |
-#include "cmd.h"
|
|
|
34b321 |
-#include "block/aio.h"
|
|
|
34b321 |
-#include "qemu/main-loop.h"
|
|
|
34b321 |
-
|
|
|
34b321 |
-#define _(x) x /* not gettext support yet */
|
|
|
34b321 |
-
|
|
|
34b321 |
-/* from libxcmd/command.c */
|
|
|
34b321 |
-
|
|
|
34b321 |
-#define EXABYTES(x) ((long long)(x) << 60)
|
|
|
34b321 |
-#define PETABYTES(x) ((long long)(x) << 50)
|
|
|
34b321 |
-#define TERABYTES(x) ((long long)(x) << 40)
|
|
|
34b321 |
-#define GIGABYTES(x) ((long long)(x) << 30)
|
|
|
34b321 |
-#define MEGABYTES(x) ((long long)(x) << 20)
|
|
|
34b321 |
-#define KILOBYTES(x) ((long long)(x) << 10)
|
|
|
34b321 |
-
|
|
|
34b321 |
-#define TO_EXABYTES(x) ((x) / EXABYTES(1))
|
|
|
34b321 |
-#define TO_PETABYTES(x) ((x) / PETABYTES(1))
|
|
|
34b321 |
-#define TO_TERABYTES(x) ((x) / TERABYTES(1))
|
|
|
34b321 |
-#define TO_GIGABYTES(x) ((x) / GIGABYTES(1))
|
|
|
34b321 |
-#define TO_MEGABYTES(x) ((x) / MEGABYTES(1))
|
|
|
34b321 |
-#define TO_KILOBYTES(x) ((x) / KILOBYTES(1))
|
|
|
34b321 |
-
|
|
|
34b321 |
-void
|
|
|
34b321 |
-cvtstr(
|
|
|
34b321 |
- double value,
|
|
|
34b321 |
- char *str,
|
|
|
34b321 |
- size_t size)
|
|
|
34b321 |
-{
|
|
|
34b321 |
- char *trim;
|
|
|
34b321 |
- const char *suffix;
|
|
|
34b321 |
-
|
|
|
34b321 |
- if (value >= EXABYTES(1)) {
|
|
|
34b321 |
- suffix = " EiB";
|
|
|
34b321 |
- snprintf(str, size - 4, "%.3f", TO_EXABYTES(value));
|
|
|
34b321 |
- } else if (value >= PETABYTES(1)) {
|
|
|
34b321 |
- suffix = " PiB";
|
|
|
34b321 |
- snprintf(str, size - 4, "%.3f", TO_PETABYTES(value));
|
|
|
34b321 |
- } else if (value >= TERABYTES(1)) {
|
|
|
34b321 |
- suffix = " TiB";
|
|
|
34b321 |
- snprintf(str, size - 4, "%.3f", TO_TERABYTES(value));
|
|
|
34b321 |
- } else if (value >= GIGABYTES(1)) {
|
|
|
34b321 |
- suffix = " GiB";
|
|
|
34b321 |
- snprintf(str, size - 4, "%.3f", TO_GIGABYTES(value));
|
|
|
34b321 |
- } else if (value >= MEGABYTES(1)) {
|
|
|
34b321 |
- suffix = " MiB";
|
|
|
34b321 |
- snprintf(str, size - 4, "%.3f", TO_MEGABYTES(value));
|
|
|
34b321 |
- } else if (value >= KILOBYTES(1)) {
|
|
|
34b321 |
- suffix = " KiB";
|
|
|
34b321 |
- snprintf(str, size - 4, "%.3f", TO_KILOBYTES(value));
|
|
|
34b321 |
- } else {
|
|
|
34b321 |
- suffix = " bytes";
|
|
|
34b321 |
- snprintf(str, size - 6, "%f", value);
|
|
|
34b321 |
- }
|
|
|
34b321 |
-
|
|
|
34b321 |
- trim = strstr(str, ".000");
|
|
|
34b321 |
- if (trim) {
|
|
|
34b321 |
- strcpy(trim, suffix);
|
|
|
34b321 |
- } else {
|
|
|
34b321 |
- strcat(str, suffix);
|
|
|
34b321 |
- }
|
|
|
34b321 |
-}
|
|
|
34b321 |
-
|
|
|
34b321 |
-struct timeval
|
|
|
34b321 |
-tsub(struct timeval t1, struct timeval t2)
|
|
|
34b321 |
-{
|
|
|
34b321 |
- t1.tv_usec -= t2.tv_usec;
|
|
|
34b321 |
- if (t1.tv_usec < 0) {
|
|
|
34b321 |
- t1.tv_usec += 1000000;
|
|
|
34b321 |
- t1.tv_sec--;
|
|
|
34b321 |
- }
|
|
|
34b321 |
- t1.tv_sec -= t2.tv_sec;
|
|
|
34b321 |
- return t1;
|
|
|
34b321 |
-}
|
|
|
34b321 |
-
|
|
|
34b321 |
-double
|
|
|
34b321 |
-tdiv(double value, struct timeval tv)
|
|
|
34b321 |
-{
|
|
|
34b321 |
- return value / ((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0));
|
|
|
34b321 |
-}
|
|
|
34b321 |
-
|
|
|
34b321 |
-#define HOURS(sec) ((sec) / (60 * 60))
|
|
|
34b321 |
-#define MINUTES(sec) (((sec) % (60 * 60)) / 60)
|
|
|
34b321 |
-#define SECONDS(sec) ((sec) % 60)
|
|
|
34b321 |
-
|
|
|
34b321 |
-void
|
|
|
34b321 |
-timestr(
|
|
|
34b321 |
- struct timeval *tv,
|
|
|
34b321 |
- char *ts,
|
|
|
34b321 |
- size_t size,
|
|
|
34b321 |
- int format)
|
|
|
34b321 |
-{
|
|
|
34b321 |
- double usec = (double)tv->tv_usec / 1000000.0;
|
|
|
34b321 |
-
|
|
|
34b321 |
- if (format & TERSE_FIXED_TIME) {
|
|
|
34b321 |
- if (!HOURS(tv->tv_sec)) {
|
|
|
34b321 |
- snprintf(ts, size, "%u:%02u.%02u",
|
|
|
34b321 |
- (unsigned int) MINUTES(tv->tv_sec),
|
|
|
34b321 |
- (unsigned int) SECONDS(tv->tv_sec),
|
|
|
34b321 |
- (unsigned int) (usec * 100));
|
|
|
34b321 |
- return;
|
|
|
34b321 |
- }
|
|
|
34b321 |
- format |= VERBOSE_FIXED_TIME; /* fallback if hours needed */
|
|
|
34b321 |
- }
|
|
|
34b321 |
-
|
|
|
34b321 |
- if ((format & VERBOSE_FIXED_TIME) || tv->tv_sec) {
|
|
|
34b321 |
- snprintf(ts, size, "%u:%02u:%02u.%02u",
|
|
|
34b321 |
- (unsigned int) HOURS(tv->tv_sec),
|
|
|
34b321 |
- (unsigned int) MINUTES(tv->tv_sec),
|
|
|
34b321 |
- (unsigned int) SECONDS(tv->tv_sec),
|
|
|
34b321 |
- (unsigned int) (usec * 100));
|
|
|
34b321 |
- } else {
|
|
|
34b321 |
- snprintf(ts, size, "0.%04u sec", (unsigned int) (usec * 10000));
|
|
|
34b321 |
- }
|
|
|
34b321 |
-}
|
|
|
34b321 |
diff --git a/cmd.h b/cmd.h
|
|
|
34b321 |
index da0c7cf..9907795 100644
|
|
|
34b321 |
--- a/cmd.h
|
|
|
34b321 |
+++ b/cmd.h
|
|
|
34b321 |
@@ -43,20 +43,6 @@ void qemuio_add_command(const cmdinfo_t *ci);
|
|
|
34b321 |
|
|
|
34b321 |
int qemuio_command_usage(const cmdinfo_t *ci);
|
|
|
34b321 |
|
|
|
34b321 |
-/* from input.h */
|
|
|
34b321 |
-void cvtstr(double value, char *str, size_t sz);
|
|
|
34b321 |
-
|
|
|
34b321 |
-struct timeval tsub(struct timeval t1, struct timeval t2);
|
|
|
34b321 |
-double tdiv(double value, struct timeval tv);
|
|
|
34b321 |
-
|
|
|
34b321 |
-enum {
|
|
|
34b321 |
- DEFAULT_TIME = 0x0,
|
|
|
34b321 |
- TERSE_FIXED_TIME = 0x1,
|
|
|
34b321 |
- VERBOSE_FIXED_TIME = 0x2
|
|
|
34b321 |
-};
|
|
|
34b321 |
-
|
|
|
34b321 |
-void timestr(struct timeval *tv, char *str, size_t sz, int flags);
|
|
|
34b321 |
-
|
|
|
34b321 |
bool qemuio_command(const char *cmd);
|
|
|
34b321 |
|
|
|
34b321 |
#endif /* __COMMAND_H__ */
|
|
|
34b321 |
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
|
|
|
34b321 |
index 27a903f..1db7fb9 100644
|
|
|
34b321 |
--- a/qemu-io-cmds.c
|
|
|
34b321 |
+++ b/qemu-io-cmds.c
|
|
|
34b321 |
@@ -127,6 +127,110 @@ static int64_t cvtnum(const char *s)
|
|
|
34b321 |
return strtosz_suffix(s, &end, STRTOSZ_DEFSUFFIX_B);
|
|
|
34b321 |
}
|
|
|
34b321 |
|
|
|
34b321 |
+#define EXABYTES(x) ((long long)(x) << 60)
|
|
|
34b321 |
+#define PETABYTES(x) ((long long)(x) << 50)
|
|
|
34b321 |
+#define TERABYTES(x) ((long long)(x) << 40)
|
|
|
34b321 |
+#define GIGABYTES(x) ((long long)(x) << 30)
|
|
|
34b321 |
+#define MEGABYTES(x) ((long long)(x) << 20)
|
|
|
34b321 |
+#define KILOBYTES(x) ((long long)(x) << 10)
|
|
|
34b321 |
+
|
|
|
34b321 |
+#define TO_EXABYTES(x) ((x) / EXABYTES(1))
|
|
|
34b321 |
+#define TO_PETABYTES(x) ((x) / PETABYTES(1))
|
|
|
34b321 |
+#define TO_TERABYTES(x) ((x) / TERABYTES(1))
|
|
|
34b321 |
+#define TO_GIGABYTES(x) ((x) / GIGABYTES(1))
|
|
|
34b321 |
+#define TO_MEGABYTES(x) ((x) / MEGABYTES(1))
|
|
|
34b321 |
+#define TO_KILOBYTES(x) ((x) / KILOBYTES(1))
|
|
|
34b321 |
+
|
|
|
34b321 |
+static void cvtstr(double value, char *str, size_t size)
|
|
|
34b321 |
+{
|
|
|
34b321 |
+ char *trim;
|
|
|
34b321 |
+ const char *suffix;
|
|
|
34b321 |
+
|
|
|
34b321 |
+ if (value >= EXABYTES(1)) {
|
|
|
34b321 |
+ suffix = " EiB";
|
|
|
34b321 |
+ snprintf(str, size - 4, "%.3f", TO_EXABYTES(value));
|
|
|
34b321 |
+ } else if (value >= PETABYTES(1)) {
|
|
|
34b321 |
+ suffix = " PiB";
|
|
|
34b321 |
+ snprintf(str, size - 4, "%.3f", TO_PETABYTES(value));
|
|
|
34b321 |
+ } else if (value >= TERABYTES(1)) {
|
|
|
34b321 |
+ suffix = " TiB";
|
|
|
34b321 |
+ snprintf(str, size - 4, "%.3f", TO_TERABYTES(value));
|
|
|
34b321 |
+ } else if (value >= GIGABYTES(1)) {
|
|
|
34b321 |
+ suffix = " GiB";
|
|
|
34b321 |
+ snprintf(str, size - 4, "%.3f", TO_GIGABYTES(value));
|
|
|
34b321 |
+ } else if (value >= MEGABYTES(1)) {
|
|
|
34b321 |
+ suffix = " MiB";
|
|
|
34b321 |
+ snprintf(str, size - 4, "%.3f", TO_MEGABYTES(value));
|
|
|
34b321 |
+ } else if (value >= KILOBYTES(1)) {
|
|
|
34b321 |
+ suffix = " KiB";
|
|
|
34b321 |
+ snprintf(str, size - 4, "%.3f", TO_KILOBYTES(value));
|
|
|
34b321 |
+ } else {
|
|
|
34b321 |
+ suffix = " bytes";
|
|
|
34b321 |
+ snprintf(str, size - 6, "%f", value);
|
|
|
34b321 |
+ }
|
|
|
34b321 |
+
|
|
|
34b321 |
+ trim = strstr(str, ".000");
|
|
|
34b321 |
+ if (trim) {
|
|
|
34b321 |
+ strcpy(trim, suffix);
|
|
|
34b321 |
+ } else {
|
|
|
34b321 |
+ strcat(str, suffix);
|
|
|
34b321 |
+ }
|
|
|
34b321 |
+}
|
|
|
34b321 |
+
|
|
|
34b321 |
+
|
|
|
34b321 |
+
|
|
|
34b321 |
+static struct timeval tsub(struct timeval t1, struct timeval t2)
|
|
|
34b321 |
+{
|
|
|
34b321 |
+ t1.tv_usec -= t2.tv_usec;
|
|
|
34b321 |
+ if (t1.tv_usec < 0) {
|
|
|
34b321 |
+ t1.tv_usec += 1000000;
|
|
|
34b321 |
+ t1.tv_sec--;
|
|
|
34b321 |
+ }
|
|
|
34b321 |
+ t1.tv_sec -= t2.tv_sec;
|
|
|
34b321 |
+ return t1;
|
|
|
34b321 |
+}
|
|
|
34b321 |
+
|
|
|
34b321 |
+static double tdiv(double value, struct timeval tv)
|
|
|
34b321 |
+{
|
|
|
34b321 |
+ return value / ((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0));
|
|
|
34b321 |
+}
|
|
|
34b321 |
+
|
|
|
34b321 |
+#define HOURS(sec) ((sec) / (60 * 60))
|
|
|
34b321 |
+#define MINUTES(sec) (((sec) % (60 * 60)) / 60)
|
|
|
34b321 |
+#define SECONDS(sec) ((sec) % 60)
|
|
|
34b321 |
+
|
|
|
34b321 |
+enum {
|
|
|
34b321 |
+ DEFAULT_TIME = 0x0,
|
|
|
34b321 |
+ TERSE_FIXED_TIME = 0x1,
|
|
|
34b321 |
+ VERBOSE_FIXED_TIME = 0x2,
|
|
|
34b321 |
+};
|
|
|
34b321 |
+
|
|
|
34b321 |
+static void timestr(struct timeval *tv, char *ts, size_t size, int format)
|
|
|
34b321 |
+{
|
|
|
34b321 |
+ double usec = (double)tv->tv_usec / 1000000.0;
|
|
|
34b321 |
+
|
|
|
34b321 |
+ if (format & TERSE_FIXED_TIME) {
|
|
|
34b321 |
+ if (!HOURS(tv->tv_sec)) {
|
|
|
34b321 |
+ snprintf(ts, size, "%u:%02u.%02u",
|
|
|
34b321 |
+ (unsigned int) MINUTES(tv->tv_sec),
|
|
|
34b321 |
+ (unsigned int) SECONDS(tv->tv_sec),
|
|
|
34b321 |
+ (unsigned int) (usec * 100));
|
|
|
34b321 |
+ return;
|
|
|
34b321 |
+ }
|
|
|
34b321 |
+ format |= VERBOSE_FIXED_TIME; /* fallback if hours needed */
|
|
|
34b321 |
+ }
|
|
|
34b321 |
+
|
|
|
34b321 |
+ if ((format & VERBOSE_FIXED_TIME) || tv->tv_sec) {
|
|
|
34b321 |
+ snprintf(ts, size, "%u:%02u:%02u.%02u",
|
|
|
34b321 |
+ (unsigned int) HOURS(tv->tv_sec),
|
|
|
34b321 |
+ (unsigned int) MINUTES(tv->tv_sec),
|
|
|
34b321 |
+ (unsigned int) SECONDS(tv->tv_sec),
|
|
|
34b321 |
+ (unsigned int) (usec * 100));
|
|
|
34b321 |
+ } else {
|
|
|
34b321 |
+ snprintf(ts, size, "0.%04u sec", (unsigned int) (usec * 10000));
|
|
|
34b321 |
+ }
|
|
|
34b321 |
+}
|
|
|
34b321 |
+
|
|
|
34b321 |
/*
|
|
|
34b321 |
* Parse the pattern argument to various sub-commands.
|
|
|
34b321 |
*
|
|
|
34b321 |
--
|
|
|
34b321 |
1.8.3.1
|
|
|
34b321 |
|