1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-10 05:17:59 +03:00

virsh: split out virsh-domain.c

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.
This commit is contained in:
Eric Blake 2012-08-17 22:00:42 -06:00
parent c2e494cc57
commit f4a7b87de0
5 changed files with 93 additions and 22 deletions

View File

@ -106,8 +106,8 @@ virt_host_validate_CFLAGS = \
virsh_SOURCES = \ virsh_SOURCES = \
console.c console.h \ console.c console.h \
virsh.c virsh.h \ virsh.c virsh.h \
virsh-domain.c virsh-domain.h \
$(NULL) $(NULL)
# virsh-domain.c virsh-domain.h \
# virsh-domain-monitor.c virsh-domain-monitor.h \ # virsh-domain-monitor.c virsh-domain-monitor.h \
# virsh-host.c virsh-host.h \ # virsh-host.c virsh-host.h \
# virsh-interface.c virsh-interface.h \ # virsh-interface.c virsh-interface.h \

View File

@ -23,6 +23,35 @@
* *
*/ */
#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 * static const char *
vshDomainVcpuStateToString(int state) vshDomainVcpuStateToString(int state)
{ {
@ -1185,6 +1214,15 @@ print_job_progress(const char *label, unsigned long long remaining,
fflush(stderr); 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 * "blockcopy" command
*/ */
@ -8044,7 +8082,7 @@ cleanup:
return ret; return ret;
} }
static const vshCmdDef domManagementCmds[] = { const vshCmdDef domManagementCmds[] = {
{"attach-device", cmdAttachDevice, opts_attach_device, {"attach-device", cmdAttachDevice, opts_attach_device,
info_attach_device, 0}, info_attach_device, 0},
{"attach-disk", cmdAttachDisk, opts_attach_disk, {"attach-disk", cmdAttachDisk, opts_attach_disk,

33
tools/virsh-domain.h Normal file
View File

@ -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 */

View File

@ -78,6 +78,8 @@
#include "conf/domain_conf.h" #include "conf/domain_conf.h"
#include "virtypedparam.h" #include "virtypedparam.h"
#include "virsh-domain.h"
static char *progname; static char *progname;
static const vshCmdGrp cmdGroups[]; static const vshCmdGrp cmdGroups[];
@ -137,9 +139,9 @@ vshNameSorter(const void *a, const void *b)
return vshStrcasecmp(*sa, *sb); return vshStrcasecmp(*sa, *sb);
} }
static double double
prettyCapacity(unsigned long long val, prettyCapacity(unsigned long long val, const char **unit)
const char **unit) { {
if (val < 1024) { if (val < 1024) {
*unit = ""; *unit = "";
return (double)val; return (double)val;
@ -176,7 +178,7 @@ virshErrorHandler(void *unused ATTRIBUTE_UNUSED, virErrorPtr error)
/* /*
* Reset libvirt error on graceful fallback paths * Reset libvirt error on graceful fallback paths
*/ */
static void void
vshResetLibvirtError(void) vshResetLibvirtError(void)
{ {
virFreeError(last_error); virFreeError(last_error);
@ -191,7 +193,7 @@ vshResetLibvirtError(void)
* twice during one command. This case shouldn't really happen anyway, * twice during one command. This case shouldn't really happen anyway,
* and it's IMHO a bug that libvirt does that sometimes. * and it's IMHO a bug that libvirt does that sometimes.
*/ */
static void void
virshReportError(vshControl *ctl) virshReportError(vshControl *ctl)
{ {
if (last_error == NULL) { if (last_error == NULL) {
@ -216,15 +218,6 @@ out:
vshResetLibvirtError(); 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 * Detection of disconnections and automatic reconnection support
*/ */
@ -310,7 +303,7 @@ vshPrintRaw(vshControl *ctl, ...)
* -1 on error * -1 on error
* 0 otherwise * 0 otherwise
*/ */
static int int
vshAskReedit(vshControl *ctl, const char *msg) vshAskReedit(vshControl *ctl, const char *msg)
{ {
int c = -1; int c = -1;
@ -359,8 +352,8 @@ vshAskReedit(vshControl *ctl, const char *msg ATTRIBUTE_UNUSED)
} }
#endif /* WIN32 */ #endif /* WIN32 */
static int vshStreamSink(virStreamPtr st ATTRIBUTE_UNUSED, int vshStreamSink(virStreamPtr st ATTRIBUTE_UNUSED,
const char *bytes, size_t nbytes, void *opaque) const char *bytes, size_t nbytes, void *opaque)
{ {
int *fd = opaque; int *fd = opaque;
@ -2873,7 +2866,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv)
return true; return true;
} }
#include "virsh-domain.c"
#include "virsh-domain-monitor.c" #include "virsh-domain-monitor.c"
#include "virsh-host.c" #include "virsh-host.c"
#include "virsh-interface.c" #include "virsh-interface.c"

View File

@ -329,6 +329,10 @@ char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item)
char *editWriteToTempFile(vshControl *ctl, const char *doc); char *editWriteToTempFile(vshControl *ctl, const char *doc);
int editFile(vshControl *ctl, const char *filename); int editFile(vshControl *ctl, const char *filename);
char *editReadBackFile(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. /* Typedefs, function prototypes for job progress reporting.
* There are used by some long lingering commands like * There are used by some long lingering commands like
@ -343,6 +347,12 @@ typedef struct __vshCtrlData {
typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom, typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom,
void *opaque); 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); void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);
# define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __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 realloc use_vshRealloc_instead_of_realloc
# define strdup use_vshStrdup_instead_of_strdup # define strdup use_vshStrdup_instead_of_strdup
extern virErrorPtr last_error;
#endif /* VIRSH_H */ #endif /* VIRSH_H */