From patchwork Fri Jun 7 11:58:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 249687 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E7C1B2C0354 for ; Fri, 7 Jun 2013 22:14:30 +1000 (EST) Received: from localhost ([::1]:53610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkvR7-00024m-8o for incoming@patchwork.ozlabs.org; Fri, 07 Jun 2013 08:06:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkvKJ-0001Ux-4o for qemu-devel@nongnu.org; Fri, 07 Jun 2013 07:59:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UkvKE-0004LX-Jf for qemu-devel@nongnu.org; Fri, 07 Jun 2013 07:59:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64945) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkvKE-0004LO-AA for qemu-devel@nongnu.org; Fri, 07 Jun 2013 07:59:22 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r57BxLql000359 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 7 Jun 2013 07:59:21 -0400 Received: from localhost (ovpn-112-30.ams2.redhat.com [10.36.112.30]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r57BxKOC024668; Fri, 7 Jun 2013 07:59:20 -0400 From: Stefan Hajnoczi To: Date: Fri, 7 Jun 2013 13:58:33 +0200 Message-Id: <1370606325-10680-15-git-send-email-stefanha@redhat.com> In-Reply-To: <1370606325-10680-1-git-send-email-stefanha@redhat.com> References: <1370606325-10680-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi Subject: [Qemu-devel] [PULL 14/26] qemu-io: Move remaining helpers from cmd.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Kevin Wolf Signed-off-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi --- Makefile | 2 +- cmd.c | 139 --------------------------------------------------------- cmd.h | 14 ------ qemu-io-cmds.c | 104 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 154 deletions(-) delete mode 100644 cmd.c diff --git a/Makefile b/Makefile index cf932eb..87298e5 100644 --- a/Makefile +++ b/Makefile @@ -186,7 +186,7 @@ qemu-img.o: qemu-img-cmds.h qemu-img$(EXESUF): qemu-img.o $(block-obj-y) libqemuutil.a libqemustub.a qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) libqemuutil.a libqemustub.a -qemu-io$(EXESUF): qemu-io.o qemu-io-cmds.o cmd.o $(block-obj-y) libqemuutil.a libqemustub.a +qemu-io$(EXESUF): qemu-io.o qemu-io-cmds.o $(block-obj-y) libqemuutil.a libqemustub.a qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o diff --git a/cmd.c b/cmd.c deleted file mode 100644 index 26d38a8..0000000 --- a/cmd.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2003-2005 Silicon Graphics, Inc. - * All Rights Reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "cmd.h" -#include "block/aio.h" -#include "qemu/main-loop.h" - -#define _(x) x /* not gettext support yet */ - -/* from libxcmd/command.c */ - -#define EXABYTES(x) ((long long)(x) << 60) -#define PETABYTES(x) ((long long)(x) << 50) -#define TERABYTES(x) ((long long)(x) << 40) -#define GIGABYTES(x) ((long long)(x) << 30) -#define MEGABYTES(x) ((long long)(x) << 20) -#define KILOBYTES(x) ((long long)(x) << 10) - -#define TO_EXABYTES(x) ((x) / EXABYTES(1)) -#define TO_PETABYTES(x) ((x) / PETABYTES(1)) -#define TO_TERABYTES(x) ((x) / TERABYTES(1)) -#define TO_GIGABYTES(x) ((x) / GIGABYTES(1)) -#define TO_MEGABYTES(x) ((x) / MEGABYTES(1)) -#define TO_KILOBYTES(x) ((x) / KILOBYTES(1)) - -void -cvtstr( - double value, - char *str, - size_t size) -{ - char *trim; - const char *suffix; - - if (value >= EXABYTES(1)) { - suffix = " EiB"; - snprintf(str, size - 4, "%.3f", TO_EXABYTES(value)); - } else if (value >= PETABYTES(1)) { - suffix = " PiB"; - snprintf(str, size - 4, "%.3f", TO_PETABYTES(value)); - } else if (value >= TERABYTES(1)) { - suffix = " TiB"; - snprintf(str, size - 4, "%.3f", TO_TERABYTES(value)); - } else if (value >= GIGABYTES(1)) { - suffix = " GiB"; - snprintf(str, size - 4, "%.3f", TO_GIGABYTES(value)); - } else if (value >= MEGABYTES(1)) { - suffix = " MiB"; - snprintf(str, size - 4, "%.3f", TO_MEGABYTES(value)); - } else if (value >= KILOBYTES(1)) { - suffix = " KiB"; - snprintf(str, size - 4, "%.3f", TO_KILOBYTES(value)); - } else { - suffix = " bytes"; - snprintf(str, size - 6, "%f", value); - } - - trim = strstr(str, ".000"); - if (trim) { - strcpy(trim, suffix); - } else { - strcat(str, suffix); - } -} - -struct timeval -tsub(struct timeval t1, struct timeval t2) -{ - t1.tv_usec -= t2.tv_usec; - if (t1.tv_usec < 0) { - t1.tv_usec += 1000000; - t1.tv_sec--; - } - t1.tv_sec -= t2.tv_sec; - return t1; -} - -double -tdiv(double value, struct timeval tv) -{ - return value / ((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0)); -} - -#define HOURS(sec) ((sec) / (60 * 60)) -#define MINUTES(sec) (((sec) % (60 * 60)) / 60) -#define SECONDS(sec) ((sec) % 60) - -void -timestr( - struct timeval *tv, - char *ts, - size_t size, - int format) -{ - double usec = (double)tv->tv_usec / 1000000.0; - - if (format & TERSE_FIXED_TIME) { - if (!HOURS(tv->tv_sec)) { - snprintf(ts, size, "%u:%02u.%02u", - (unsigned int) MINUTES(tv->tv_sec), - (unsigned int) SECONDS(tv->tv_sec), - (unsigned int) (usec * 100)); - return; - } - format |= VERBOSE_FIXED_TIME; /* fallback if hours needed */ - } - - if ((format & VERBOSE_FIXED_TIME) || tv->tv_sec) { - snprintf(ts, size, "%u:%02u:%02u.%02u", - (unsigned int) HOURS(tv->tv_sec), - (unsigned int) MINUTES(tv->tv_sec), - (unsigned int) SECONDS(tv->tv_sec), - (unsigned int) (usec * 100)); - } else { - snprintf(ts, size, "0.%04u sec", (unsigned int) (usec * 10000)); - } -} diff --git a/cmd.h b/cmd.h index da0c7cf..9907795 100644 --- a/cmd.h +++ b/cmd.h @@ -43,20 +43,6 @@ void qemuio_add_command(const cmdinfo_t *ci); int qemuio_command_usage(const cmdinfo_t *ci); -/* from input.h */ -void cvtstr(double value, char *str, size_t sz); - -struct timeval tsub(struct timeval t1, struct timeval t2); -double tdiv(double value, struct timeval tv); - -enum { - DEFAULT_TIME = 0x0, - TERSE_FIXED_TIME = 0x1, - VERBOSE_FIXED_TIME = 0x2 -}; - -void timestr(struct timeval *tv, char *str, size_t sz, int flags); - bool qemuio_command(const char *cmd); #endif /* __COMMAND_H__ */ diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 8acc866..05ce342 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -126,6 +126,110 @@ static int64_t cvtnum(const char *s) return strtosz_suffix(s, &end, STRTOSZ_DEFSUFFIX_B); } +#define EXABYTES(x) ((long long)(x) << 60) +#define PETABYTES(x) ((long long)(x) << 50) +#define TERABYTES(x) ((long long)(x) << 40) +#define GIGABYTES(x) ((long long)(x) << 30) +#define MEGABYTES(x) ((long long)(x) << 20) +#define KILOBYTES(x) ((long long)(x) << 10) + +#define TO_EXABYTES(x) ((x) / EXABYTES(1)) +#define TO_PETABYTES(x) ((x) / PETABYTES(1)) +#define TO_TERABYTES(x) ((x) / TERABYTES(1)) +#define TO_GIGABYTES(x) ((x) / GIGABYTES(1)) +#define TO_MEGABYTES(x) ((x) / MEGABYTES(1)) +#define TO_KILOBYTES(x) ((x) / KILOBYTES(1)) + +static void cvtstr(double value, char *str, size_t size) +{ + char *trim; + const char *suffix; + + if (value >= EXABYTES(1)) { + suffix = " EiB"; + snprintf(str, size - 4, "%.3f", TO_EXABYTES(value)); + } else if (value >= PETABYTES(1)) { + suffix = " PiB"; + snprintf(str, size - 4, "%.3f", TO_PETABYTES(value)); + } else if (value >= TERABYTES(1)) { + suffix = " TiB"; + snprintf(str, size - 4, "%.3f", TO_TERABYTES(value)); + } else if (value >= GIGABYTES(1)) { + suffix = " GiB"; + snprintf(str, size - 4, "%.3f", TO_GIGABYTES(value)); + } else if (value >= MEGABYTES(1)) { + suffix = " MiB"; + snprintf(str, size - 4, "%.3f", TO_MEGABYTES(value)); + } else if (value >= KILOBYTES(1)) { + suffix = " KiB"; + snprintf(str, size - 4, "%.3f", TO_KILOBYTES(value)); + } else { + suffix = " bytes"; + snprintf(str, size - 6, "%f", value); + } + + trim = strstr(str, ".000"); + if (trim) { + strcpy(trim, suffix); + } else { + strcat(str, suffix); + } +} + + + +static struct timeval tsub(struct timeval t1, struct timeval t2) +{ + t1.tv_usec -= t2.tv_usec; + if (t1.tv_usec < 0) { + t1.tv_usec += 1000000; + t1.tv_sec--; + } + t1.tv_sec -= t2.tv_sec; + return t1; +} + +static double tdiv(double value, struct timeval tv) +{ + return value / ((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0)); +} + +#define HOURS(sec) ((sec) / (60 * 60)) +#define MINUTES(sec) (((sec) % (60 * 60)) / 60) +#define SECONDS(sec) ((sec) % 60) + +enum { + DEFAULT_TIME = 0x0, + TERSE_FIXED_TIME = 0x1, + VERBOSE_FIXED_TIME = 0x2, +}; + +static void timestr(struct timeval *tv, char *ts, size_t size, int format) +{ + double usec = (double)tv->tv_usec / 1000000.0; + + if (format & TERSE_FIXED_TIME) { + if (!HOURS(tv->tv_sec)) { + snprintf(ts, size, "%u:%02u.%02u", + (unsigned int) MINUTES(tv->tv_sec), + (unsigned int) SECONDS(tv->tv_sec), + (unsigned int) (usec * 100)); + return; + } + format |= VERBOSE_FIXED_TIME; /* fallback if hours needed */ + } + + if ((format & VERBOSE_FIXED_TIME) || tv->tv_sec) { + snprintf(ts, size, "%u:%02u:%02u.%02u", + (unsigned int) HOURS(tv->tv_sec), + (unsigned int) MINUTES(tv->tv_sec), + (unsigned int) SECONDS(tv->tv_sec), + (unsigned int) (usec * 100)); + } else { + snprintf(ts, size, "0.%04u sec", (unsigned int) (usec * 10000)); + } +} + /* * Parse the pattern argument to various sub-commands. *