[libvirt] [PATCH 0/4] start cleaning up virsh split

Not complete, but this is what I got done in a couple hours after complaining about Osier's series: https://www.redhat.com/archives/libvir-list/2012-August/msg01247.html There's more work to be done, but this should give an idea at the sort of cleanups made possible when we cleanly split into different .o files. Eric Blake (4): virsh: move vshWatchJob earlier virsh: split out virsh.h virsh: split out virsh-domain.c virsh: kill some double underscores tools/Makefile.am | 15 +- tools/virsh-domain-monitor.c | 2 +- tools/virsh-domain.c | 220 ++++++++++++--------- tools/virsh-domain.h | 33 ++++ tools/virsh.c | 460 ++++++------------------------------------- tools/virsh.h | 384 ++++++++++++++++++++++++++++++++++++ 6 files changed, 622 insertions(+), 492 deletions(-) create mode 100644 tools/virsh-domain.h create mode 100644 tools/virsh.h -- 1.7.11.2

It's easier to order things in topological order than it is to forward declare in one file for use only by one other file. * tools/virsh.c (vshWatchJob, parseRateStr) (vshDomainStateToString, vshDomainStateReasonToString) (vshDomainControlStateToString, vshDomainVcpuStateToString): Drop useless prototypes. * tools/virsh-domain.c (vshWatchJob): Move earlier. --- tools/virsh-domain.c | 180 +++++++++++++++++++++++++-------------------------- tools/virsh.c | 16 ----- 2 files changed, 90 insertions(+), 106 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 676c002..dc8620e 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2772,6 +2772,96 @@ out_sig: } static bool +vshWatchJob(vshControl *ctl, + virDomainPtr dom, + bool verbose, + int pipe_fd, + int timeout, + jobWatchTimeoutFunc timeout_func, + void *opaque, + const char *label) +{ + struct sigaction sig_action; + struct sigaction old_sig_action; + struct pollfd pollfd; + struct timeval start, curr; + virDomainJobInfo jobinfo; + int ret = -1; + char retchar; + bool functionReturn = false; + sigset_t sigmask, oldsigmask; + + sigemptyset(&sigmask); + sigaddset(&sigmask, SIGINT); + + intCaught = 0; + sig_action.sa_sigaction = vshCatchInt; + sig_action.sa_flags = SA_SIGINFO; + sigemptyset(&sig_action.sa_mask); + sigaction(SIGINT, &sig_action, &old_sig_action); + + pollfd.fd = pipe_fd; + pollfd.events = POLLIN; + pollfd.revents = 0; + + GETTIMEOFDAY(&start); + while (1) { +repoll: + ret = poll(&pollfd, 1, 500); + if (ret > 0) { + if (pollfd.revents & POLLIN && + saferead(pipe_fd, &retchar, sizeof(retchar)) > 0 && + retchar == '0') { + if (verbose) { + /* print [100 %] */ + print_job_progress(label, 0, 1); + } + break; + } + goto cleanup; + } + + if (ret < 0) { + if (errno == EINTR) { + if (intCaught) { + virDomainAbortJob(dom); + intCaught = 0; + } else { + goto repoll; + } + } + goto cleanup; + } + + GETTIMEOFDAY(&curr); + if (timeout && (((int)(curr.tv_sec - start.tv_sec) * 1000 + + (int)(curr.tv_usec - start.tv_usec) / 1000) > + timeout * 1000)) { + /* suspend the domain when migration timeouts. */ + vshDebug(ctl, VSH_ERR_DEBUG, "%s timeout", label); + if (timeout_func) + (timeout_func)(ctl, dom, opaque); + timeout = 0; + } + + if (verbose) { + pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask); + ret = virDomainGetJobInfo(dom, &jobinfo); + pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); + if (ret == 0) + print_job_progress(label, jobinfo.dataRemaining, + jobinfo.dataTotal); + } + } + + functionReturn = true; + +cleanup: + sigaction(SIGINT, &old_sig_action, NULL); + return functionReturn; +} + +static bool cmdSave(vshControl *ctl, const vshCmd *cmd) { bool ret = false; @@ -6426,96 +6516,6 @@ vshMigrationTimeout(vshControl *ctl, } static bool -vshWatchJob(vshControl *ctl, - virDomainPtr dom, - bool verbose, - int pipe_fd, - int timeout, - jobWatchTimeoutFunc timeout_func, - void *opaque, - const char *label) -{ - struct sigaction sig_action; - struct sigaction old_sig_action; - struct pollfd pollfd; - struct timeval start, curr; - virDomainJobInfo jobinfo; - int ret = -1; - char retchar; - bool functionReturn = false; - sigset_t sigmask, oldsigmask; - - sigemptyset(&sigmask); - sigaddset(&sigmask, SIGINT); - - intCaught = 0; - sig_action.sa_sigaction = vshCatchInt; - sig_action.sa_flags = SA_SIGINFO; - sigemptyset(&sig_action.sa_mask); - sigaction(SIGINT, &sig_action, &old_sig_action); - - pollfd.fd = pipe_fd; - pollfd.events = POLLIN; - pollfd.revents = 0; - - GETTIMEOFDAY(&start); - while (1) { -repoll: - ret = poll(&pollfd, 1, 500); - if (ret > 0) { - if (pollfd.revents & POLLIN && - saferead(pipe_fd, &retchar, sizeof(retchar)) > 0 && - retchar == '0') { - if (verbose) { - /* print [100 %] */ - print_job_progress(label, 0, 1); - } - break; - } - goto cleanup; - } - - if (ret < 0) { - if (errno == EINTR) { - if (intCaught) { - virDomainAbortJob(dom); - intCaught = 0; - } else { - goto repoll; - } - } - goto cleanup; - } - - GETTIMEOFDAY(&curr); - if (timeout && (((int)(curr.tv_sec - start.tv_sec) * 1000 + - (int)(curr.tv_usec - start.tv_usec) / 1000) > - timeout * 1000)) { - /* suspend the domain when migration timeouts. */ - vshDebug(ctl, VSH_ERR_DEBUG, "%s timeout", label); - if (timeout_func) - (timeout_func)(ctl, dom, opaque); - timeout = 0; - } - - if (verbose) { - pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask); - ret = virDomainGetJobInfo(dom, &jobinfo); - pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); - if (ret == 0) - print_job_progress(label, jobinfo.dataRemaining, - jobinfo.dataTotal); - } - } - - functionReturn = true; - -cleanup: - sigaction(SIGINT, &old_sig_action, NULL); - return functionReturn; -} - -static bool cmdMigrate(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom = NULL; diff --git a/tools/virsh.c b/tools/virsh.c index 4dff02e..3be2f99 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -361,10 +361,6 @@ static void vshDebug(vshControl *ctl, int level, const char *format, ...) #define vshStrcasecmp(S1, S2) strcasecmp(S1, S2) static int vshDomainState(vshControl *ctl, virDomainPtr dom, int *reason); -static const char *vshDomainStateToString(int state); -static const char *vshDomainStateReasonToString(int state, int reason); -static const char *vshDomainControlStateToString(int state); -static const char *vshDomainVcpuStateToString(int state); static bool vshConnectionUsability(vshControl *ctl, virConnectPtr conn); static virTypedParameterPtr vshFindTypedParamByName(const char *name, virTypedParameterPtr list, @@ -389,16 +385,6 @@ typedef struct __vshCtrlData { typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom, void *opaque); -static bool -vshWatchJob(vshControl *ctl, - virDomainPtr dom, - bool verbose, - int pipe_fd, - int timeout, - jobWatchTimeoutFunc timeout_func, - void *opaque, - const char *label); - static void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line); #define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __LINE__) @@ -408,8 +394,6 @@ static void *_vshCalloc(vshControl *ctl, size_t nmemb, size_t sz, const char *fi static char *_vshStrdup(vshControl *ctl, const char *s, const char *filename, int line); #define vshStrdup(_ctl, _s) _vshStrdup(_ctl, _s, __FILE__, __LINE__) -static int parseRateStr(const char *rateStr, virNetDevBandwidthRatePtr rate); - static void * _vshMalloc(vshControl *ctl, size_t size, const char *filename, int line) { -- 1.7.11.2

On 08/18/2012 12:38 AM, Eric Blake wrote:
It's easier to order things in topological order than it is to forward declare in one file for use only by one other file.
* tools/virsh.c (vshWatchJob, parseRateStr) (vshDomainStateToString, vshDomainStateReasonToString) (vshDomainControlStateToString, vshDomainVcpuStateToString): Drop useless prototypes. * tools/virsh-domain.c (vshWatchJob): Move earlier.
mechanical code movement and it still compiles; I trust you've got a reasonable plan with where this is going, so ACK.
--- tools/virsh-domain.c | 180 +++++++++++++++++++++++++-------------------------- tools/virsh.c | 16 ----- 2 files changed, 90 insertions(+), 106 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 676c002..dc8620e 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2772,6 +2772,96 @@ out_sig: }
static bool +vshWatchJob(vshControl *ctl, + virDomainPtr dom, + bool verbose, + int pipe_fd, + int timeout, + jobWatchTimeoutFunc timeout_func, + void *opaque, + const char *label) +{ + struct sigaction sig_action; + struct sigaction old_sig_action; + struct pollfd pollfd; + struct timeval start, curr; + virDomainJobInfo jobinfo; + int ret = -1; + char retchar; + bool functionReturn = false; + sigset_t sigmask, oldsigmask; + + sigemptyset(&sigmask); + sigaddset(&sigmask, SIGINT); + + intCaught = 0; + sig_action.sa_sigaction = vshCatchInt; + sig_action.sa_flags = SA_SIGINFO; + sigemptyset(&sig_action.sa_mask); + sigaction(SIGINT, &sig_action, &old_sig_action); + + pollfd.fd = pipe_fd; + pollfd.events = POLLIN; + pollfd.revents = 0; + + GETTIMEOFDAY(&start); + while (1) { +repoll: + ret = poll(&pollfd, 1, 500); + if (ret > 0) { + if (pollfd.revents & POLLIN && + saferead(pipe_fd, &retchar, sizeof(retchar)) > 0 && + retchar == '0') { + if (verbose) { + /* print [100 %] */ + print_job_progress(label, 0, 1); + } + break; + } + goto cleanup; + } + + if (ret < 0) { + if (errno == EINTR) { + if (intCaught) { + virDomainAbortJob(dom); + intCaught = 0; + } else { + goto repoll; + } + } + goto cleanup; + } + + GETTIMEOFDAY(&curr); + if (timeout && (((int)(curr.tv_sec - start.tv_sec) * 1000 + + (int)(curr.tv_usec - start.tv_usec) / 1000) > + timeout * 1000)) { + /* suspend the domain when migration timeouts. */ + vshDebug(ctl, VSH_ERR_DEBUG, "%s timeout", label); + if (timeout_func) + (timeout_func)(ctl, dom, opaque); + timeout = 0; + } + + if (verbose) { + pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask); + ret = virDomainGetJobInfo(dom, &jobinfo); + pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); + if (ret == 0) + print_job_progress(label, jobinfo.dataRemaining, + jobinfo.dataTotal); + } + } + + functionReturn = true; + +cleanup: + sigaction(SIGINT, &old_sig_action, NULL); + return functionReturn; +} + +static bool cmdSave(vshControl *ctl, const vshCmd *cmd) { bool ret = false; @@ -6426,96 +6516,6 @@ vshMigrationTimeout(vshControl *ctl, }
static bool -vshWatchJob(vshControl *ctl, - virDomainPtr dom, - bool verbose, - int pipe_fd, - int timeout, - jobWatchTimeoutFunc timeout_func, - void *opaque, - const char *label) -{ - struct sigaction sig_action; - struct sigaction old_sig_action; - struct pollfd pollfd; - struct timeval start, curr; - virDomainJobInfo jobinfo; - int ret = -1; - char retchar; - bool functionReturn = false; - sigset_t sigmask, oldsigmask; - - sigemptyset(&sigmask); - sigaddset(&sigmask, SIGINT); - - intCaught = 0; - sig_action.sa_sigaction = vshCatchInt; - sig_action.sa_flags = SA_SIGINFO; - sigemptyset(&sig_action.sa_mask); - sigaction(SIGINT, &sig_action, &old_sig_action); - - pollfd.fd = pipe_fd; - pollfd.events = POLLIN; - pollfd.revents = 0; - - GETTIMEOFDAY(&start); - while (1) { -repoll: - ret = poll(&pollfd, 1, 500); - if (ret > 0) { - if (pollfd.revents & POLLIN && - saferead(pipe_fd, &retchar, sizeof(retchar)) > 0 && - retchar == '0') { - if (verbose) { - /* print [100 %] */ - print_job_progress(label, 0, 1); - } - break; - } - goto cleanup; - } - - if (ret < 0) { - if (errno == EINTR) { - if (intCaught) { - virDomainAbortJob(dom); - intCaught = 0; - } else { - goto repoll; - } - } - goto cleanup; - } - - GETTIMEOFDAY(&curr); - if (timeout && (((int)(curr.tv_sec - start.tv_sec) * 1000 + - (int)(curr.tv_usec - start.tv_usec) / 1000) > - timeout * 1000)) { - /* suspend the domain when migration timeouts. */ - vshDebug(ctl, VSH_ERR_DEBUG, "%s timeout", label); - if (timeout_func) - (timeout_func)(ctl, dom, opaque); - timeout = 0; - } - - if (verbose) { - pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask); - ret = virDomainGetJobInfo(dom, &jobinfo); - pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); - if (ret == 0) - print_job_progress(label, jobinfo.dataRemaining, - jobinfo.dataTotal); - } - } - - functionReturn = true; - -cleanup: - sigaction(SIGINT, &old_sig_action, NULL); - return functionReturn; -} - -static bool cmdMigrate(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom = NULL; diff --git a/tools/virsh.c b/tools/virsh.c index 4dff02e..3be2f99 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -361,10 +361,6 @@ static void vshDebug(vshControl *ctl, int level, const char *format, ...) #define vshStrcasecmp(S1, S2) strcasecmp(S1, S2)
static int vshDomainState(vshControl *ctl, virDomainPtr dom, int *reason); -static const char *vshDomainStateToString(int state); -static const char *vshDomainStateReasonToString(int state, int reason); -static const char *vshDomainControlStateToString(int state); -static const char *vshDomainVcpuStateToString(int state); static bool vshConnectionUsability(vshControl *ctl, virConnectPtr conn); static virTypedParameterPtr vshFindTypedParamByName(const char *name, virTypedParameterPtr list, @@ -389,16 +385,6 @@ typedef struct __vshCtrlData { typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom, void *opaque);
-static bool -vshWatchJob(vshControl *ctl, - virDomainPtr dom, - bool verbose, - int pipe_fd, - int timeout, - jobWatchTimeoutFunc timeout_func, - void *opaque, - const char *label); - static void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line); #define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __LINE__)
@@ -408,8 +394,6 @@ static void *_vshCalloc(vshControl *ctl, size_t nmemb, size_t sz, const char *fi static char *_vshStrdup(vshControl *ctl, const char *s, const char *filename, int line); #define vshStrdup(_ctl, _s) _vshStrdup(_ctl, _s, __FILE__, __LINE__)
-static int parseRateStr(const char *rateStr, virNetDevBandwidthRatePtr rate); - static void * _vshMalloc(vshControl *ctl, size_t size, const char *filename, int line) {

Having one .c file include another does not give any compilation benefits; move towards modular .o files by first splitting out reused declarations into a new virsh.h. This patch doesn't try very hard to see which functions are used or not, to make it easier to review the file split. Future patches can further trim the header to be smaller. * tools/Makefile.am (virsh_SOURCES): List new file, and prepare for others. * tools/virsh.c: Split declarations... * tools/virsh.h: ...into new file, and make several functions non-static. * tools/virsh-domain-monitor.c (vshGetDomainDescription): Make non-static. --- tools/Makefile.am | 15 +- tools/virsh-domain-monitor.c | 2 +- tools/virsh.c | 407 +++++-------------------------------------- tools/virsh.h | 370 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 431 insertions(+), 363 deletions(-) create mode 100644 tools/virsh.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 7c048b2..52a8699 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -105,7 +105,20 @@ virt_host_validate_CFLAGS = \ virsh_SOURCES = \ console.c console.h \ - virsh.c + virsh.c virsh.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 \ +# virsh-network.c virsh-network.h \ +# virsh-nodedev.c virsh-nodedev.h \ +# virsh-nwfilter.c virsh-nwfilter.h \ +# virsh-pool.c virsh-pool.h \ +# virsh-secret.c virsh-secret.h \ +# virsh-snapshot.c virsh-snapshot.h \ +# virsh-volume.c virsh-volume.h \ +# virsh_LDFLAGS = $(WARN_LDFLAGS) $(COVERAGE_LDFLAGS) virsh_LDADD = \ diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 1272a05..52e44c9 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -43,7 +43,7 @@ vshDomainIOErrorToString(int error) } /* extract description or title from domain xml */ -static char * +char * vshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title, unsigned int flags) { diff --git a/tools/virsh.c b/tools/virsh.c index 3be2f99..610236b 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -23,6 +23,7 @@ */ #include <config.h> +#include "virsh.h" #include <stdio.h> #include <stdlib.h> @@ -79,322 +80,12 @@ static char *progname; -#define VIRSH_MAX_XML_FILE 10*1024*1024 - -#define VSH_PROMPT_RW "virsh # " -#define VSH_PROMPT_RO "virsh > " - -#define VIR_FROM_THIS VIR_FROM_NONE - -#define GETTIMEOFDAY(T) gettimeofday(T, NULL) -#define DIFF_MSEC(T, U) \ - ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \ - ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0) - -/* Default escape char Ctrl-] as per telnet */ -#define CTRL_CLOSE_BRACKET "^]" - -/** - * The log configuration - */ -#define MSG_BUFFER 4096 -#define SIGN_NAME "virsh" -#define DIR_MODE (S_IWUSR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) /* 0755 */ -#define FILE_MODE (S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH) /* 0644 */ -#define LOCK_MODE (S_IWUSR | S_IRUSR) /* 0600 */ -#define LVL_DEBUG "DEBUG" -#define LVL_INFO "INFO" -#define LVL_NOTICE "NOTICE" -#define LVL_WARNING "WARNING" -#define LVL_ERROR "ERROR" - -/** - * vshErrorLevel: - * - * Indicates the level of a log message - */ -typedef enum { - VSH_ERR_DEBUG = 0, - VSH_ERR_INFO, - VSH_ERR_NOTICE, - VSH_ERR_WARNING, - VSH_ERR_ERROR -} vshErrorLevel; - -#define VSH_DEBUG_DEFAULT VSH_ERR_ERROR - -/* - * virsh command line grammar: - * - * command_line = <command>\n | <command>; <command>; ... - * - * command = <keyword> <option> [--] <data> - * - * option = <bool_option> | <int_option> | <string_option> - * data = <string> - * - * bool_option = --optionname - * int_option = --optionname <number> | --optionname=<number> - * string_option = --optionname <string> | --optionname=<string> - * - * keyword = [a-zA-Z][a-zA-Z-]* - * number = [0-9]+ - * string = ('[^']*'|"([^\\"]|\\.)*"|([^ \t\n\\'"]|\\.))+ - * - */ - -/* - * vshCmdOptType - command option type - */ -typedef enum { - VSH_OT_BOOL, /* optional boolean option */ - VSH_OT_STRING, /* optional string option */ - VSH_OT_INT, /* optional or mandatory int option */ - VSH_OT_DATA, /* string data (as non-option) */ - VSH_OT_ARGV, /* remaining arguments */ - VSH_OT_ALIAS, /* alternate spelling for a later argument */ -} vshCmdOptType; - -/* - * Command group types - */ -#define VSH_CMD_GRP_DOM_MANAGEMENT "Domain Management" -#define VSH_CMD_GRP_DOM_MONITORING "Domain Monitoring" -#define VSH_CMD_GRP_STORAGE_POOL "Storage Pool" -#define VSH_CMD_GRP_STORAGE_VOL "Storage Volume" -#define VSH_CMD_GRP_NETWORK "Networking" -#define VSH_CMD_GRP_NODEDEV "Node Device" -#define VSH_CMD_GRP_IFACE "Interface" -#define VSH_CMD_GRP_NWFILTER "Network Filter" -#define VSH_CMD_GRP_SECRET "Secret" -#define VSH_CMD_GRP_SNAPSHOT "Snapshot" -#define VSH_CMD_GRP_HOST_AND_HV "Host and Hypervisor" -#define VSH_CMD_GRP_VIRSH "Virsh itself" - -/* - * Command Option Flags - */ -enum { - VSH_OFLAG_NONE = 0, /* without flags */ - VSH_OFLAG_REQ = (1 << 0), /* option required */ - VSH_OFLAG_EMPTY_OK = (1 << 1), /* empty string option allowed */ - VSH_OFLAG_REQ_OPT = (1 << 2), /* --optionname required */ -}; - -/* dummy */ -typedef struct __vshControl vshControl; -typedef struct __vshCmd vshCmd; - -/* - * vshCmdInfo -- name/value pair for information about command - * - * Commands should have at least the following names: - * "name" - command name - * "desc" - description of command, or empty string - */ -typedef struct { - const char *name; /* name of information, or NULL for list end */ - const char *data; /* non-NULL information */ -} vshCmdInfo; - -/* - * vshCmdOptDef - command option definition - */ -typedef struct { - const char *name; /* the name of option, or NULL for list end */ - vshCmdOptType type; /* option type */ - unsigned int flags; /* flags */ - const char *help; /* non-NULL help string; or for VSH_OT_ALIAS - * the name of a later public option */ -} vshCmdOptDef; - -/* - * vshCmdOpt - command options - * - * After parsing a command, all arguments to the command have been - * collected into a list of these objects. - */ -typedef struct vshCmdOpt { - const vshCmdOptDef *def; /* non-NULL pointer to option definition */ - char *data; /* allocated data, or NULL for bool option */ - struct vshCmdOpt *next; -} vshCmdOpt; - -/* - * Command Usage Flags - */ -enum { - VSH_CMD_FLAG_NOCONNECT = (1 << 0), /* no prior connection needed */ - VSH_CMD_FLAG_ALIAS = (1 << 1), /* command is an alias */ -}; - -/* - * vshCmdDef - command definition - */ -typedef struct { - const char *name; /* name of command, or NULL for list end */ - bool (*handler) (vshControl *, const vshCmd *); /* command handler */ - const vshCmdOptDef *opts; /* definition of command options */ - const vshCmdInfo *info; /* details about command */ - unsigned int flags; /* bitwise OR of VSH_CMD_FLAG */ -} vshCmdDef; - -/* - * vshCmd - parsed command - */ -typedef struct __vshCmd { - const vshCmdDef *def; /* command definition */ - vshCmdOpt *opts; /* list of command arguments */ - struct __vshCmd *next; /* next command */ -} __vshCmd; - -/* - * vshControl - */ -typedef struct __vshControl { - char *name; /* connection name */ - virConnectPtr conn; /* connection to hypervisor (MAY BE NULL) */ - vshCmd *cmd; /* the current command */ - char *cmdstr; /* string with command */ - bool imode; /* interactive mode? */ - bool quiet; /* quiet mode */ - int debug; /* print debug messages? */ - bool timing; /* print timing info? */ - bool readonly; /* connect readonly (first time only, not - * during explicit connect command) - */ - char *logfile; /* log file name */ - int log_fd; /* log file descriptor */ - char *historydir; /* readline history directory name */ - char *historyfile; /* readline history file name */ - bool useGetInfo; /* must use virDomainGetInfo, since - virDomainGetState is not supported */ - bool useSnapshotOld; /* cannot use virDomainSnapshotGetParent or - virDomainSnapshotNumChildren */ - virThread eventLoop; - virMutex lock; - bool eventLoopStarted; - bool quit; - - const char *escapeChar; /* String representation of - console escape character */ -} __vshControl; - -typedef struct vshCmdGrp { - const char *name; /* name of group, or NULL for list end */ - const char *keyword; /* help keyword */ - const vshCmdDef *commands; -} vshCmdGrp; - static const vshCmdGrp cmdGroups[]; -static void vshError(vshControl *ctl, const char *format, ...) - ATTRIBUTE_FMT_PRINTF(2, 3); -static bool vshInit(vshControl *ctl); -static bool vshDeinit(vshControl *ctl); -static void vshUsage(void); -static void vshOpenLogFile(vshControl *ctl); -static void vshOutputLogFile(vshControl *ctl, int log_level, const char *format, va_list ap) - ATTRIBUTE_FMT_PRINTF(3, 0); -static void vshCloseLogFile(vshControl *ctl); - -static bool vshParseArgv(vshControl *ctl, int argc, char **argv); - -static const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info); -static const vshCmdDef *vshCmddefSearch(const char *cmdname); -static bool vshCmddefHelp(vshControl *ctl, const char *name); -static const vshCmdGrp *vshCmdGrpSearch(const char *grpname); -static bool vshCmdGrpHelp(vshControl *ctl, const char *name); - -static int vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) - ATTRIBUTE_RETURN_CHECK; -static int vshCommandOptInt(const vshCmd *cmd, const char *name, int *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -static int vshCommandOptUInt(const vshCmd *cmd, const char *name, - unsigned int *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -static int vshCommandOptUL(const vshCmd *cmd, const char *name, - unsigned long *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -static int vshCommandOptString(const vshCmd *cmd, const char *name, - const char **value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -static int vshCommandOptLongLong(const vshCmd *cmd, const char *name, - long long *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -static int vshCommandOptULongLong(const vshCmd *cmd, const char *name, - unsigned long long *value) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -static int vshCommandOptScaledInt(const vshCmd *cmd, const char *name, - unsigned long long *value, int scale, - unsigned long long max) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; -static bool vshCommandOptBool(const vshCmd *cmd, const char *name); -static const vshCmdOpt *vshCommandOptArgv(const vshCmd *cmd, - const vshCmdOpt *opt); -static char *vshGetDomainDescription(vshControl *ctl, virDomainPtr dom, - bool title, unsigned int flags) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; - -#define VSH_BYID (1 << 1) -#define VSH_BYUUID (1 << 2) -#define VSH_BYNAME (1 << 3) -#define VSH_BYMAC (1 << 4) - -static virDomainPtr vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, - const char **name, int flag); - -/* default is lookup by Id, Name and UUID */ -#define vshCommandOptDomain(_ctl, _cmd, _name) \ - vshCommandOptDomainBy(_ctl, _cmd, _name, VSH_BYID|VSH_BYUUID|VSH_BYNAME) - -static void vshPrintExtra(vshControl *ctl, const char *format, ...) - ATTRIBUTE_FMT_PRINTF(2, 3); -static void vshDebug(vshControl *ctl, int level, const char *format, ...) - ATTRIBUTE_FMT_PRINTF(3, 4); - -/* XXX: add batch support */ -#define vshPrint(_ctl, ...) vshPrintExtra(NULL, __VA_ARGS__) - -/* User visible sort, so we want locale-specific case comparison. */ -#define vshStrcasecmp(S1, S2) strcasecmp(S1, S2) - -static int vshDomainState(vshControl *ctl, virDomainPtr dom, int *reason); -static bool vshConnectionUsability(vshControl *ctl, virConnectPtr conn); -static virTypedParameterPtr vshFindTypedParamByName(const char *name, - virTypedParameterPtr list, - int count); -static char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); - -static char *editWriteToTempFile(vshControl *ctl, const char *doc); -static int editFile(vshControl *ctl, const char *filename); -static char *editReadBackFile(vshControl *ctl, const char *filename); - -/* Typedefs, function prototypes for job progress reporting. - * There are used by some long lingering commands like - * migrate, dump, save, managedsave. - */ -typedef struct __vshCtrlData { - vshControl *ctl; - const vshCmd *cmd; - int writefd; -} vshCtrlData; - -typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom, - void *opaque); - -static void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line); -#define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __LINE__) - -static void *_vshCalloc(vshControl *ctl, size_t nmemb, size_t sz, const char *filename, int line); -#define vshCalloc(_ctl, _nmemb, _sz) _vshCalloc(_ctl, _nmemb, _sz, __FILE__, __LINE__) - -static char *_vshStrdup(vshControl *ctl, const char *s, const char *filename, int line); -#define vshStrdup(_ctl, _s) _vshStrdup(_ctl, _s, __FILE__, __LINE__) +/* Bypass header poison */ +#undef strdup -static void * +void * _vshMalloc(vshControl *ctl, size_t size, const char *filename, int line) { char *x; @@ -406,8 +97,9 @@ _vshMalloc(vshControl *ctl, size_t size, const char *filename, int line) exit(EXIT_FAILURE); } -static void * -_vshCalloc(vshControl *ctl, size_t nmemb, size_t size, const char *filename, int line) +void * +_vshCalloc(vshControl *ctl, size_t nmemb, size_t size, const char *filename, + int line) { char *x; @@ -419,7 +111,7 @@ _vshCalloc(vshControl *ctl, size_t nmemb, size_t size, const char *filename, int exit(EXIT_FAILURE); } -static char * +char * _vshStrdup(vshControl *ctl, const char *s, const char *filename, int line) { char *x; @@ -434,13 +126,6 @@ _vshStrdup(vshControl *ctl, const char *s, const char *filename, int line) } /* Poison the raw allocating identifiers in favor of our vsh variants. */ -#undef malloc -#undef calloc -#undef realloc -#undef strdup -#define malloc use_vshMalloc_instead_of_malloc -#define calloc use_vshCalloc_instead_of_calloc -#define realloc use_vshRealloc_instead_of_realloc #define strdup use_vshStrdup_instead_of_strdup static int @@ -474,7 +159,7 @@ prettyCapacity(unsigned long long val, } -static virErrorPtr last_error; +virErrorPtr last_error; /* * Quieten libvirt until we're done with the command. @@ -830,7 +515,7 @@ vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque, } /* Common code for the edit / net-edit / pool-edit functions which follow. */ -static char * +char * editWriteToTempFile(vshControl *ctl, const char *doc) { char *ret; @@ -875,7 +560,7 @@ editWriteToTempFile(vshControl *ctl, const char *doc) #define ACCEPTED_CHARS \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/_.:@" -static int +int editFile(vshControl *ctl, const char *filename) { const char *editor; @@ -927,7 +612,7 @@ cleanup: return ret; } -static char * +char * editReadBackFile(vshControl *ctl, const char *filename) { char *ret; @@ -1105,7 +790,7 @@ cmdQuit(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) * Utils for work with command definition * --------------- */ -static const char * +const char * vshCmddefGetInfo(const vshCmdDef * cmd, const char *name) { const vshCmdInfo *info; @@ -1258,7 +943,7 @@ vshCommandCheckOpts(vshControl *ctl, const vshCmd *cmd, uint32_t opts_required, return -1; } -static const vshCmdDef * +const vshCmdDef * vshCmddefSearch(const char *cmdname) { const vshCmdGrp *g; @@ -1274,7 +959,7 @@ vshCmddefSearch(const char *cmdname) return NULL; } -static const vshCmdGrp * +const vshCmdGrp * vshCmdGrpSearch(const char *grpname) { const vshCmdGrp *g; @@ -1287,7 +972,7 @@ vshCmdGrpSearch(const char *grpname) return NULL; } -static bool +bool vshCmdGrpHelp(vshControl *ctl, const char *grpname) { const vshCmdGrp *grp = vshCmdGrpSearch(grpname); @@ -1309,7 +994,7 @@ vshCmdGrpHelp(vshControl *ctl, const char *grpname) return true; } -static bool +bool vshCmddefHelp(vshControl *ctl, const char *cmdname) { const vshCmdDef *def = vshCmddefSearch(cmdname); @@ -1479,7 +1164,7 @@ vshCommandFree(vshCmd *cmd) * the option is required but not present, and -2 if NAME is not valid * (-2 indicates a programming error). No error messages are issued. */ -static int +int vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt) { vshCmdOpt *candidate = cmd->opts; @@ -1519,7 +1204,7 @@ vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt) * 0 if option not found and not required (@value untouched) * <0 in all other cases (@value untouched) */ -static int +int vshCommandOptInt(const vshCmd *cmd, const char *name, int *value) { vshCmdOpt *arg; @@ -1549,7 +1234,7 @@ vshCommandOptInt(const vshCmd *cmd, const char *name, int *value) * Convert option to unsigned int * See vshCommandOptInt() */ -static int +int vshCommandOptUInt(const vshCmd *cmd, const char *name, unsigned int *value) { vshCmdOpt *arg; @@ -1579,7 +1264,7 @@ vshCommandOptUInt(const vshCmd *cmd, const char *name, unsigned int *value) * Convert option to unsigned long * See vshCommandOptInt() */ -static int +int vshCommandOptUL(const vshCmd *cmd, const char *name, unsigned long *value) { vshCmdOpt *arg; @@ -1611,7 +1296,7 @@ vshCommandOptUL(const vshCmd *cmd, const char *name, unsigned long *value) * 0 if option not found and not required (@value untouched) * <0 in all other cases (@value untouched) */ -static int +int vshCommandOptString(const vshCmd *cmd, const char *name, const char **value) { vshCmdOpt *arg; @@ -1642,7 +1327,7 @@ vshCommandOptString(const vshCmd *cmd, const char *name, const char **value) * Returns option as long long * See vshCommandOptInt() */ -static int +int vshCommandOptLongLong(const vshCmd *cmd, const char *name, long long *value) { @@ -1672,7 +1357,7 @@ vshCommandOptLongLong(const vshCmd *cmd, const char *name, * Returns option as long long * See vshCommandOptInt() */ -static int +int vshCommandOptULongLong(const vshCmd *cmd, const char *name, unsigned long long *value) { @@ -1705,7 +1390,7 @@ vshCommandOptULongLong(const vshCmd *cmd, const char *name, * Returns option as long long, scaled according to suffix * See vshCommandOptInt() */ -static int +int vshCommandOptScaledInt(const vshCmd *cmd, const char *name, unsigned long long *value, int scale, unsigned long long max) @@ -1734,7 +1419,7 @@ vshCommandOptScaledInt(const vshCmd *cmd, const char *name, * name is legal; so that this can be used to probe whether a data * option is present without actually using that data. */ -static bool +bool vshCommandOptBool(const vshCmd *cmd, const char *name) { vshCmdOpt *dummy; @@ -1753,7 +1438,7 @@ vshCommandOptBool(const vshCmd *cmd, const char *name) * Requires that a VSH_OT_ARGV option be last in the * list of supported options in CMD->def->opts. */ -static const vshCmdOpt * +const vshCmdOpt * vshCommandOptArgv(const vshCmd *cmd, const vshCmdOpt *opt) { opt = opt ? opt->next : cmd->opts; @@ -1790,7 +1475,7 @@ cmd_has_option(vshControl *ctl, const vshCmd *cmd, const char *optname) return found; } -static virDomainPtr +virDomainPtr vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, const char **name, int flag) { @@ -2218,7 +1903,7 @@ vshCommandStringParse(vshControl *ctl, char *cmdstr) * Misc utils * --------------- */ -static int +int vshDomainState(vshControl *ctl, virDomainPtr dom, int *reason) { virDomainInfo info; @@ -2248,7 +1933,7 @@ vshDomainState(vshControl *ctl, virDomainPtr dom, int *reason) /* Return a non-NULL string representation of a typed parameter; exit * if we are out of memory. */ -static char * +char * vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item) { int ret = 0; @@ -2294,7 +1979,7 @@ vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item) return str; } -static virTypedParameterPtr +virTypedParameterPtr vshFindTypedParamByName(const char *name, virTypedParameterPtr list, int count) { int i = count; @@ -2314,7 +1999,7 @@ vshFindTypedParamByName(const char *name, virTypedParameterPtr list, int count) return NULL; } -static bool +bool vshConnectionUsability(vshControl *ctl, virConnectPtr conn) { /* TODO: use something like virConnectionState() to @@ -2327,7 +2012,7 @@ vshConnectionUsability(vshControl *ctl, virConnectPtr conn) return true; } -static void +void vshDebug(vshControl *ctl, int level, const char *format, ...) { va_list ap; @@ -2355,7 +2040,7 @@ vshDebug(vshControl *ctl, int level, const char *format, ...) VIR_FREE(str); } -static void +void vshPrintExtra(vshControl *ctl, const char *format, ...) { va_list ap; @@ -2376,7 +2061,7 @@ vshPrintExtra(vshControl *ctl, const char *format, ...) } -static void +void vshError(vshControl *ctl, const char *format, ...) { va_list ap; @@ -2429,7 +2114,7 @@ vshEventLoop(void *opaque) /* * Initialize connection. */ -static bool +bool vshInit(vshControl *ctl) { char *debugEnv; @@ -2500,7 +2185,7 @@ vshInit(vshControl *ctl) * * Open log file. */ -static void +void vshOpenLogFile(vshControl *ctl) { struct stat st; @@ -2538,7 +2223,7 @@ vshOpenLogFile(vshControl *ctl) * * Outputting an error to log file. */ -static void +void vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format, va_list ap) { @@ -2620,7 +2305,7 @@ error: * * Close log file. */ -static void +void vshCloseLogFile(vshControl *ctl) { /* log file close */ @@ -2865,7 +2550,7 @@ vshDeinitTimer(int timer ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) /* * Deinitialize virsh */ -static bool +bool vshDeinit(vshControl *ctl) { vshReadlineDeinit(ctl); @@ -2904,7 +2589,7 @@ vshDeinit(vshControl *ctl) /* * Print usage */ -static void +void vshUsage(void) { const vshCmdGrp *grp; @@ -3095,7 +2780,7 @@ vshAllowedEscapeChar(char c) * argv[]: virsh [options] [command] * */ -static bool +bool vshParseArgv(vshControl *ctl, int argc, char **argv) { int arg, len, debug; @@ -3190,15 +2875,15 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) #include "virsh-domain.c" #include "virsh-domain-monitor.c" -#include "virsh-pool.c" -#include "virsh-volume.c" +#include "virsh-host.c" +#include "virsh-interface.c" #include "virsh-network.c" #include "virsh-nodedev.c" -#include "virsh-interface.c" #include "virsh-nwfilter.c" +#include "virsh-pool.c" #include "virsh-secret.c" #include "virsh-snapshot.c" -#include "virsh-host.c" +#include "virsh-volume.c" static const vshCmdDef virshCmds[] = { {"cd", cmdCd, opts_cd, info_cd, VSH_CMD_FLAG_NOCONNECT}, diff --git a/tools/virsh.h b/tools/virsh.h new file mode 100644 index 0000000..8680a0a --- /dev/null +++ b/tools/virsh.h @@ -0,0 +1,370 @@ +/* + * virsh.h: a shell to exercise the libvirt API + * + * 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_H +#define VIRSH_H + +# include <stdio.h> +# include <stdlib.h> +# include <string.h> +# include <stdarg.h> +# include <unistd.h> +# include <sys/stat.h> +# include <inttypes.h> + +# include "internal.h" +# include "virterror_internal.h" +# include "threads.h" +# include "virnetdevbandwidth.h" + +# define VIRSH_MAX_XML_FILE 10*1024*1024 + +# define VSH_PROMPT_RW "virsh # " +# define VSH_PROMPT_RO "virsh > " + +# define VIR_FROM_THIS VIR_FROM_NONE + +# define GETTIMEOFDAY(T) gettimeofday(T, NULL) +# define DIFF_MSEC(T, U) \ + ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \ + ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0) + +/* Default escape char Ctrl-] as per telnet */ +# define CTRL_CLOSE_BRACKET "^]" + +/** + * The log configuration + */ +# define MSG_BUFFER 4096 +# define SIGN_NAME "virsh" +# define DIR_MODE (S_IWUSR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) /* 0755 */ +# define FILE_MODE (S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH) /* 0644 */ +# define LOCK_MODE (S_IWUSR | S_IRUSR) /* 0600 */ +# define LVL_DEBUG "DEBUG" +# define LVL_INFO "INFO" +# define LVL_NOTICE "NOTICE" +# define LVL_WARNING "WARNING" +# define LVL_ERROR "ERROR" + +/** + * vshErrorLevel: + * + * Indicates the level of a log message + */ +typedef enum { + VSH_ERR_DEBUG = 0, + VSH_ERR_INFO, + VSH_ERR_NOTICE, + VSH_ERR_WARNING, + VSH_ERR_ERROR +} vshErrorLevel; + +# define VSH_DEBUG_DEFAULT VSH_ERR_ERROR + +/* + * virsh command line grammar: + * + * command_line = <command>\n | <command>; <command>; ... + * + * command = <keyword> <option> [--] <data> + * + * option = <bool_option> | <int_option> | <string_option> + * data = <string> + * + * bool_option = --optionname + * int_option = --optionname <number> | --optionname=<number> + * string_option = --optionname <string> | --optionname=<string> + * + * keyword = [a-zA-Z][a-zA-Z-]* + * number = [0-9]+ + * string = ('[^']*'|"([^\\"]|\\.)*"|([^ \t\n\\'"]|\\.))+ + * + */ + +/* + * vshCmdOptType - command option type + */ +typedef enum { + VSH_OT_BOOL, /* optional boolean option */ + VSH_OT_STRING, /* optional string option */ + VSH_OT_INT, /* optional or mandatory int option */ + VSH_OT_DATA, /* string data (as non-option) */ + VSH_OT_ARGV, /* remaining arguments */ + VSH_OT_ALIAS, /* alternate spelling for a later argument */ +} vshCmdOptType; + +/* + * Command group types + */ +# define VSH_CMD_GRP_DOM_MANAGEMENT "Domain Management" +# define VSH_CMD_GRP_DOM_MONITORING "Domain Monitoring" +# define VSH_CMD_GRP_STORAGE_POOL "Storage Pool" +# define VSH_CMD_GRP_STORAGE_VOL "Storage Volume" +# define VSH_CMD_GRP_NETWORK "Networking" +# define VSH_CMD_GRP_NODEDEV "Node Device" +# define VSH_CMD_GRP_IFACE "Interface" +# define VSH_CMD_GRP_NWFILTER "Network Filter" +# define VSH_CMD_GRP_SECRET "Secret" +# define VSH_CMD_GRP_SNAPSHOT "Snapshot" +# define VSH_CMD_GRP_HOST_AND_HV "Host and Hypervisor" +# define VSH_CMD_GRP_VIRSH "Virsh itself" + +/* + * Command Option Flags + */ +enum { + VSH_OFLAG_NONE = 0, /* without flags */ + VSH_OFLAG_REQ = (1 << 0), /* option required */ + VSH_OFLAG_EMPTY_OK = (1 << 1), /* empty string option allowed */ + VSH_OFLAG_REQ_OPT = (1 << 2), /* --optionname required */ +}; + +/* dummy */ +typedef struct __vshControl vshControl; +typedef struct __vshCmd vshCmd; + +/* + * vshCmdInfo -- name/value pair for information about command + * + * Commands should have at least the following names: + * "name" - command name + * "desc" - description of command, or empty string + */ +typedef struct { + const char *name; /* name of information, or NULL for list end */ + const char *data; /* non-NULL information */ +} vshCmdInfo; + +/* + * vshCmdOptDef - command option definition + */ +typedef struct { + const char *name; /* the name of option, or NULL for list end */ + vshCmdOptType type; /* option type */ + unsigned int flags; /* flags */ + const char *help; /* non-NULL help string; or for VSH_OT_ALIAS + * the name of a later public option */ +} vshCmdOptDef; + +/* + * vshCmdOpt - command options + * + * After parsing a command, all arguments to the command have been + * collected into a list of these objects. + */ +typedef struct vshCmdOpt { + const vshCmdOptDef *def; /* non-NULL pointer to option definition */ + char *data; /* allocated data, or NULL for bool option */ + struct vshCmdOpt *next; +} vshCmdOpt; + +/* + * Command Usage Flags + */ +enum { + VSH_CMD_FLAG_NOCONNECT = (1 << 0), /* no prior connection needed */ + VSH_CMD_FLAG_ALIAS = (1 << 1), /* command is an alias */ +}; + +/* + * vshCmdDef - command definition + */ +typedef struct { + const char *name; /* name of command, or NULL for list end */ + bool (*handler) (vshControl *, const vshCmd *); /* command handler */ + const vshCmdOptDef *opts; /* definition of command options */ + const vshCmdInfo *info; /* details about command */ + unsigned int flags; /* bitwise OR of VSH_CMD_FLAG */ +} vshCmdDef; + +/* + * vshCmd - parsed command + */ +typedef struct __vshCmd { + const vshCmdDef *def; /* command definition */ + vshCmdOpt *opts; /* list of command arguments */ + struct __vshCmd *next; /* next command */ +} __vshCmd; + +/* + * vshControl + */ +typedef struct __vshControl { + char *name; /* connection name */ + virConnectPtr conn; /* connection to hypervisor (MAY BE NULL) */ + vshCmd *cmd; /* the current command */ + char *cmdstr; /* string with command */ + bool imode; /* interactive mode? */ + bool quiet; /* quiet mode */ + int debug; /* print debug messages? */ + bool timing; /* print timing info? */ + bool readonly; /* connect readonly (first time only, not + * during explicit connect command) + */ + char *logfile; /* log file name */ + int log_fd; /* log file descriptor */ + char *historydir; /* readline history directory name */ + char *historyfile; /* readline history file name */ + bool useGetInfo; /* must use virDomainGetInfo, since + virDomainGetState is not supported */ + bool useSnapshotOld; /* cannot use virDomainSnapshotGetParent or + virDomainSnapshotNumChildren */ + virThread eventLoop; + virMutex lock; + bool eventLoopStarted; + bool quit; + + const char *escapeChar; /* String representation of + console escape character */ +} __vshControl; + +typedef struct vshCmdGrp { + const char *name; /* name of group, or NULL for list end */ + const char *keyword; /* help keyword */ + const vshCmdDef *commands; +} vshCmdGrp; + +void vshError(vshControl *ctl, const char *format, ...) + ATTRIBUTE_FMT_PRINTF(2, 3); +bool vshInit(vshControl *ctl); +bool vshDeinit(vshControl *ctl); +void vshUsage(void); +void vshOpenLogFile(vshControl *ctl); +void vshOutputLogFile(vshControl *ctl, int log_level, const char *format, + va_list ap) + ATTRIBUTE_FMT_PRINTF(3, 0); +void vshCloseLogFile(vshControl *ctl); + +bool vshParseArgv(vshControl *ctl, int argc, char **argv); + +const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info); +const vshCmdDef *vshCmddefSearch(const char *cmdname); +bool vshCmddefHelp(vshControl *ctl, const char *name); +const vshCmdGrp *vshCmdGrpSearch(const char *grpname); +bool vshCmdGrpHelp(vshControl *ctl, const char *name); + +int vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) + ATTRIBUTE_RETURN_CHECK; +int vshCommandOptInt(const vshCmd *cmd, const char *name, int *value) + ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptUInt(const vshCmd *cmd, const char *name, + unsigned int *value) + ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptUL(const vshCmd *cmd, const char *name, + unsigned long *value) + ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptString(const vshCmd *cmd, const char *name, + const char **value) + ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptLongLong(const vshCmd *cmd, const char *name, + long long *value) + ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptULongLong(const vshCmd *cmd, const char *name, + unsigned long long *value) + ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; +int vshCommandOptScaledInt(const vshCmd *cmd, const char *name, + unsigned long long *value, int scale, + unsigned long long max) + ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; +bool vshCommandOptBool(const vshCmd *cmd, const char *name); +const vshCmdOpt *vshCommandOptArgv(const vshCmd *cmd, + const vshCmdOpt *opt); +char *vshGetDomainDescription(vshControl *ctl, virDomainPtr dom, + bool title, unsigned int flags) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; + +# define VSH_BYID (1 << 1) +# define VSH_BYUUID (1 << 2) +# define VSH_BYNAME (1 << 3) +# define VSH_BYMAC (1 << 4) + +virDomainPtr vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, + const char **name, int flag); + +/* default is lookup by Id, Name and UUID */ +# define vshCommandOptDomain(_ctl, _cmd, _name) \ + vshCommandOptDomainBy(_ctl, _cmd, _name, VSH_BYID|VSH_BYUUID|VSH_BYNAME) + +void vshPrintExtra(vshControl *ctl, const char *format, ...) + ATTRIBUTE_FMT_PRINTF(2, 3); +void vshDebug(vshControl *ctl, int level, const char *format, ...) + ATTRIBUTE_FMT_PRINTF(3, 4); + +/* XXX: add batch support */ +# define vshPrint(_ctl, ...) vshPrintExtra(NULL, __VA_ARGS__) + +/* User visible sort, so we want locale-specific case comparison. */ +# define vshStrcasecmp(S1, S2) strcasecmp(S1, S2) + +int vshDomainState(vshControl *ctl, virDomainPtr dom, int *reason); +bool vshConnectionUsability(vshControl *ctl, virConnectPtr conn); +virTypedParameterPtr vshFindTypedParamByName(const char *name, + virTypedParameterPtr list, + int count); +char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + +char *editWriteToTempFile(vshControl *ctl, const char *doc); +int editFile(vshControl *ctl, const char *filename); +char *editReadBackFile(vshControl *ctl, const char *filename); + +/* Typedefs, function prototypes for job progress reporting. + * There are used by some long lingering commands like + * migrate, dump, save, managedsave. + */ +typedef struct __vshCtrlData { + vshControl *ctl; + const vshCmd *cmd; + int writefd; +} vshCtrlData; + +typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom, + void *opaque); + +void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line); +# define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __LINE__) + +void *_vshCalloc(vshControl *ctl, size_t nmemb, size_t sz, + const char *filename, int line); +# define vshCalloc(_ctl, _nmemb, _sz) \ + _vshCalloc(_ctl, _nmemb, _sz, __FILE__, __LINE__) + +char *_vshStrdup(vshControl *ctl, const char *s, const char *filename, + int line); +# define vshStrdup(_ctl, _s) _vshStrdup(_ctl, _s, __FILE__, __LINE__) + +/* Poison the raw allocating identifiers in favor of our vsh variants. */ +# undef malloc +# undef calloc +# undef realloc +# undef strdup +# define malloc use_vshMalloc_instead_of_malloc +# define calloc use_vshCalloc_instead_of_calloc +# define realloc use_vshRealloc_instead_of_realloc +# define strdup use_vshStrdup_instead_of_strdup + +extern virErrorPtr last_error; + +#endif /* VIRSH_H */ -- 1.7.11.2

On 08/18/2012 12:38 AM, Eric Blake wrote:
Having one .c file include another does not give any compilation benefits; move towards modular .o files by first splitting out reused declarations into a new virsh.h. This patch doesn't try very hard to see which functions are used or not, to make it easier to review the file split. Future patches can further trim the header to be smaller.
and it still compiles. ACK.

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 | 2 +- tools/virsh-domain.c | 40 +++++++++++++++++++++++++++++++++++++++- tools/virsh-domain.h | 33 +++++++++++++++++++++++++++++++++ tools/virsh.c | 28 ++++++++++------------------ tools/virsh.h | 12 ++++++++++-- 5 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 tools/virsh-domain.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 52a8699..b885892 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -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 \ diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index dc8620e..edbda91 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -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 * 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 index 0000000..797462f --- /dev/null +++ b/tools/virsh-domain.h @@ -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 */ diff --git a/tools/virsh.c b/tools/virsh.c index 610236b..054047f 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -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" diff --git a/tools/virsh.h b/tools/virsh.h index 8680a0a..7e505aa 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -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 */ -- 1.7.11.2

On 08/18/2012 12:38 AM, Eric Blake wrote:
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.
Yep, still compiles. ACK.

Use of __foo naming is against C99. Besides, we had several different styles in use; this consolidates things to set up the typedefs up front then declare the types. * tools/virsh.h: Use consistent struct naming. * tools/virsh.c (_vshCommandParser): Likewise. --- tools/virsh.c | 9 +++++---- tools/virsh.h | 48 +++++++++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 054047f..ecb27df 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -1581,15 +1581,16 @@ typedef enum { VSH_TK_END /* No more commands */ } vshCommandToken; -typedef struct __vshCommandParser { - vshCommandToken(*getNextArg)(vshControl *, struct __vshCommandParser *, - char **); +typedef struct _vshCommandParser vshCommandParser; +struct _vshCommandParser { + vshCommandToken(*getNextArg)(vshControl *, vshCommandParser *, + char **); /* vshCommandStringGetArg() */ char *pos; /* vshCommandArgvGetArg() */ char **arg_pos; char **arg_end; -} vshCommandParser; +}; static bool vshCommandParse(vshControl *ctl, vshCommandParser *parser) diff --git a/tools/virsh.h b/tools/virsh.h index 7e505aa..69f37cc 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -140,9 +140,15 @@ enum { VSH_OFLAG_REQ_OPT = (1 << 2), /* --optionname required */ }; -/* dummy */ -typedef struct __vshControl vshControl; -typedef struct __vshCmd vshCmd; +/* forward declarations */ +typedef struct _vshCmd vshCmd; +typedef struct _vshCmdDef vshCmdDef; +typedef struct _vshCmdGrp vshCmdGrp; +typedef struct _vshCmdInfo vshCmdInfo; +typedef struct _vshCmdOpt vshCmdOpt; +typedef struct _vshCmdOptDef vshCmdOptDef; +typedef struct _vshControl vshControl; +typedef struct _vshCtrlData vshCtrlData; /* * vshCmdInfo -- name/value pair for information about command @@ -151,21 +157,21 @@ typedef struct __vshCmd vshCmd; * "name" - command name * "desc" - description of command, or empty string */ -typedef struct { +struct _vshCmdInfo { const char *name; /* name of information, or NULL for list end */ const char *data; /* non-NULL information */ -} vshCmdInfo; +}; /* * vshCmdOptDef - command option definition */ -typedef struct { +struct _vshCmdOptDef { const char *name; /* the name of option, or NULL for list end */ vshCmdOptType type; /* option type */ unsigned int flags; /* flags */ const char *help; /* non-NULL help string; or for VSH_OT_ALIAS * the name of a later public option */ -} vshCmdOptDef; +}; /* * vshCmdOpt - command options @@ -173,11 +179,11 @@ typedef struct { * After parsing a command, all arguments to the command have been * collected into a list of these objects. */ -typedef struct vshCmdOpt { +struct _vshCmdOpt { const vshCmdOptDef *def; /* non-NULL pointer to option definition */ char *data; /* allocated data, or NULL for bool option */ - struct vshCmdOpt *next; -} vshCmdOpt; + vshCmdOpt *next; +}; /* * Command Usage Flags @@ -190,27 +196,27 @@ enum { /* * vshCmdDef - command definition */ -typedef struct { +struct _vshCmdDef { const char *name; /* name of command, or NULL for list end */ bool (*handler) (vshControl *, const vshCmd *); /* command handler */ const vshCmdOptDef *opts; /* definition of command options */ const vshCmdInfo *info; /* details about command */ unsigned int flags; /* bitwise OR of VSH_CMD_FLAG */ -} vshCmdDef; +}; /* * vshCmd - parsed command */ -typedef struct __vshCmd { +struct _vshCmd { const vshCmdDef *def; /* command definition */ vshCmdOpt *opts; /* list of command arguments */ - struct __vshCmd *next; /* next command */ -} __vshCmd; + vshCmd *next; /* next command */ +}; /* * vshControl */ -typedef struct __vshControl { +struct _vshControl { char *name; /* connection name */ virConnectPtr conn; /* connection to hypervisor (MAY BE NULL) */ vshCmd *cmd; /* the current command */ @@ -237,13 +243,13 @@ typedef struct __vshControl { const char *escapeChar; /* String representation of console escape character */ -} __vshControl; +}; -typedef struct vshCmdGrp { +struct _vshCmdGrp { const char *name; /* name of group, or NULL for list end */ const char *keyword; /* help keyword */ const vshCmdDef *commands; -} vshCmdGrp; +}; void vshError(vshControl *ctl, const char *format, ...) ATTRIBUTE_FMT_PRINTF(2, 3); @@ -338,11 +344,11 @@ double prettyCapacity(unsigned long long val, const char **unit); * There are used by some long lingering commands like * migrate, dump, save, managedsave. */ -typedef struct __vshCtrlData { +struct _vshCtrlData { vshControl *ctl; const vshCmd *cmd; int writefd; -} vshCtrlData; +}; typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom, void *opaque); -- 1.7.11.2

On 08/18/2012 12:38 AM, Eric Blake wrote:
Use of __foo naming is against C99. Besides, we had several different styles in use; this consolidates things to set up the typedefs up front then declare the types.
* tools/virsh.h: Use consistent struct naming. * tools/virsh.c (_vshCommandParser): Likewise.
Haven't seen the results yet, but I'm sure this is going somewhere, and it still builds. ACK.

On 08/17/2012 11:38 PM, Laine Stump wrote:
On 08/18/2012 12:38 AM, Eric Blake wrote:
Use of __foo naming is against C99. Besides, we had several different styles in use; this consolidates things to set up the typedefs up front then declare the types.
* tools/virsh.h: Use consistent struct naming. * tools/virsh.c (_vshCommandParser): Likewise.
Haven't seen the results yet, but I'm sure this is going somewhere, and it still builds. ACK.
I've pushed 1-4, and am now working on more. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 08/18/2012 12:38 AM, Eric Blake wrote:
Not complete, but this is what I got done in a couple hours after complaining about Osier's series: https://www.redhat.com/archives/libvir-list/2012-August/msg01247.html
I hadn't noticed that virsh.c was split up like that either, but definitely I agree. Although I earlier begrudgingly went along with having the virsh-edit.c template #included by virsh.c (simply because it was better than what it was replacing), in general #including .c files is a very gross and misleading hack that should be avoided.

Oops, I pushed patches without doing syntax checks along the way. * cfg.mk (exclude_file_name_regexp--sc_avoid_strcase): Track file split. * tools/virsh-domain.h (VIRSH_DOMAIN_H): Fix indentation. * tools/virsh.h (VIRSH_H): Likewise. --- Pushing under the build-breaker rule. cfg.mk | 2 +- tools/virsh-domain.h | 2 +- tools/virsh.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cfg.mk b/cfg.mk index e9138a8..d2e54e3 100644 --- a/cfg.mk +++ b/cfg.mk @@ -727,7 +727,7 @@ $(srcdir)/src/remote/remote_client_bodies.h: $(srcdir)/src/remote/remote_protoco $(MAKE) -C src remote/remote_client_bodies.h # List all syntax-check exemptions: -exclude_file_name_regexp--sc_avoid_strcase = ^tools/virsh\.c$$ +exclude_file_name_regexp--sc_avoid_strcase = ^tools/virsh\.h$$ _src1=libvirt|fdstream|qemu/qemu_monitor|util/(command|util)|xen/xend_internal|rpc/virnetsocket|lxc/lxc_controller exclude_file_name_regexp--sc_avoid_write = \ diff --git a/tools/virsh-domain.h b/tools/virsh-domain.h index 797462f..b1b7930 100644 --- a/tools/virsh-domain.h +++ b/tools/virsh-domain.h @@ -24,7 +24,7 @@ */ #ifndef VIRSH_DOMAIN_H -#define VIRSH_DOMAIN_H +# define VIRSH_DOMAIN_H # include "virsh.h" diff --git a/tools/virsh.h b/tools/virsh.h index 69f37cc..0b1f123 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -23,7 +23,7 @@ */ #ifndef VIRSH_H -#define VIRSH_H +# define VIRSH_H # include <stdio.h> # include <stdlib.h> -- 1.7.11.4

Convert the exported items in virsh.h to use a common 'vsh' prefix. * tools/virsh.h (VIRSH_MAX_XML_FILE, GETTIMEOFDAY): Rename... (VSH_MAX_XML_FILE): ...and parenthesize. (DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete. (vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype. (editWriteToTempFile, editFile, editReadBackFile, prettyCapacity) (virshReportError): Rename... (vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile) (vshPrettyCapacity, vshReportError): ...into vsh namespace. (jobWatchTimeoutFunc): Move to virsh-domain.c. * tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC. (main): Inline former CTRL_CLOSE_BRACKET. (vshUsage, vshInit, vshDeinit, vshParseArgv): Make static. (prettyCapacity, virshReportError, editWriteToTempFile, editFile): Fix naming, and adjust usage. (vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust usage. * tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare) (cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice) (cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount) (cmdAttachDevice, cmdDomjobinfo): Likewise. * tools/virsh-edit.c (do): Likewise. * tools/virsh-interface.c (cmdInterfaceDefine): Likewise. * tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine): Likewise. * tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise. * tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise. * tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine) (cmdPoolDiscoverSources, cmdPoolList): Likewise. * tools/virsh-secret.c (cmdSecretDefine): Likewise. * tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate) (vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent) (vshGetSnapshotParent): Likewise. * tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom) (cmdVolInfo, cmdVolList): Likewise. --- tools/virsh-domain.c | 65 ++++++++++++++++++++++++++----------------------- tools/virsh-edit.c | 6 ++--- tools/virsh-interface.c | 2 +- tools/virsh-network.c | 4 +-- tools/virsh-nodedev.c | 2 +- tools/virsh-nwfilter.c | 2 +- tools/virsh-pool.c | 19 ++++++++------- tools/virsh-secret.c | 2 +- tools/virsh-snapshot.c | 16 ++++++------ tools/virsh-volume.c | 16 ++++++------ tools/virsh.c | 43 +++++++++++++++++--------------- tools/virsh.h | 26 +++++--------------- 12 files changed, 98 insertions(+), 105 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index edbda91..d102378 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -105,8 +105,8 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) return false; } - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { + vshReportError(ctl); virDomainFree(dom); return false; } @@ -2544,7 +2544,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) goto cleanup; } if (virDomainManagedSaveRemove(dom, 0) < 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } } @@ -2618,7 +2618,7 @@ cleanup: return ret; error: - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } @@ -2687,7 +2687,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) goto started; if (last_error->code != VIR_ERR_NO_SUPPORT && last_error->code != VIR_ERR_INVALID_ARG) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } vshResetLibvirtError(); @@ -2697,7 +2697,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) vshResetLibvirtError(); } else if (rc > 0) { if (virDomainManagedSaveRemove(dom, 0) < 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } } @@ -2809,6 +2809,9 @@ out_sig: ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); } +typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom, + void *opaque); + static bool vshWatchJob(vshControl *ctl, virDomainPtr dom, @@ -4088,27 +4091,27 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) if (info.type == VIR_DOMAIN_JOB_BOUNDED) vshPrint(ctl, "%-17s %-12llu ms\n", _("Time remaining:"), info.timeRemaining); if (info.dataTotal || info.dataRemaining || info.dataProcessed) { - val = prettyCapacity(info.dataProcessed, &unit); + val = vshPrettyCapacity(info.dataProcessed, &unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data processed:"), val, unit); - val = prettyCapacity(info.dataRemaining, &unit); + val = vshPrettyCapacity(info.dataRemaining, &unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data remaining:"), val, unit); - val = prettyCapacity(info.dataTotal, &unit); + val = vshPrettyCapacity(info.dataTotal, &unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data total:"), val, unit); } if (info.memTotal || info.memRemaining || info.memProcessed) { - val = prettyCapacity(info.memProcessed, &unit); + val = vshPrettyCapacity(info.memProcessed, &unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory processed:"), val, unit); - val = prettyCapacity(info.memRemaining, &unit); + val = vshPrettyCapacity(info.memRemaining, &unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory remaining:"), val, unit); - val = prettyCapacity(info.memTotal, &unit); + val = vshPrettyCapacity(info.memTotal, &unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory total:"), val, unit); } if (info.fileTotal || info.fileRemaining || info.fileProcessed) { - val = prettyCapacity(info.fileProcessed, &unit); + val = vshPrettyCapacity(info.fileProcessed, &unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("File processed:"), val, unit); - val = prettyCapacity(info.fileRemaining, &unit); + val = vshPrettyCapacity(info.fileRemaining, &unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("File remaining:"), val, unit); - val = prettyCapacity(info.fileTotal, &unit); + val = vshPrettyCapacity(info.fileTotal, &unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("File total:"), val, unit); } } else { @@ -4275,7 +4278,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) count = virDomainGetVcpusFlags(dom, maximum ? VIR_DOMAIN_VCPU_MAXIMUM : 0); if (count < 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else { vshPrint(ctl, "%d\n", count); @@ -4299,7 +4302,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) } if (count < 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else if (all) { vshPrint(ctl, "%-12s %-12s %3d\n", _("maximum"), _("config"), @@ -4319,7 +4322,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) } if (count < 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else if (all) { vshPrint(ctl, "%-12s %-12s %3d\n", _("maximum"), _("live"), @@ -4355,7 +4358,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) } if (count < 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else if (all) { vshPrint(ctl, "%-12s %-12s %3d\n", _("current"), _("config"), @@ -4376,7 +4379,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) } if (count < 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else if (all) { vshPrint(ctl, "%-12s %-12s %3d\n", _("current"), _("live"), @@ -4869,7 +4872,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) return false; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { vshError(ctl, _("Failed to read file '%s' to compare"), from); return false; @@ -4972,7 +4975,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) return false; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; /* add a separate container around the xml */ @@ -5234,7 +5237,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) return false; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; if (vshCommandOptBool(cmd, "paused")) @@ -5288,7 +5291,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) return false; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; dom = virDomainDefineXML(ctl->conn, buffer); @@ -5448,15 +5451,15 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) if (edit) { /* Create and open the temporary file. */ - if (!(tmp = editWriteToTempFile(ctl, desc))) + if (!(tmp = vshEditWriteToTempFile(ctl, desc))) goto cleanup; /* Start the editor. */ - if (editFile(ctl, tmp) == -1) + if (vshEditFile(ctl, tmp) == -1) goto cleanup; /* Read back the edited file. */ - if (!(desc_edited = editReadBackFile(ctl, tmp))) + if (!(desc_edited = vshEditReadBackFile(ctl, tmp))) goto cleanup; /* strip a possible newline at the end of file; some @@ -7368,8 +7371,8 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) goto cleanup; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { + vshReportError(ctl); goto cleanup; } @@ -7434,8 +7437,8 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) return false; } - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { + vshReportError(ctl); virDomainFree(dom); return false; } diff --git a/tools/virsh-edit.c b/tools/virsh-edit.c index 4dea4b8..512ac0d 100644 --- a/tools/virsh-edit.c +++ b/tools/virsh-edit.c @@ -75,17 +75,17 @@ do { goto edit_cleanup; /* Create and open the temporary file. */ - tmp = editWriteToTempFile(ctl, doc); + tmp = vshEditWriteToTempFile(ctl, doc); if (!tmp) goto edit_cleanup; reedit: /* Start the editor. */ - if (editFile(ctl, tmp) == -1) + if (vshEditFile(ctl, tmp) == -1) goto edit_cleanup; /* Read back the edited file. */ - doc_edited = editReadBackFile(ctl, tmp); + doc_edited = vshEditReadBackFile(ctl, tmp); if (!doc_edited) goto edit_cleanup; diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 12019b4..ad080a1 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -369,7 +369,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) return false; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; iface = virInterfaceDefineXML(ctl->conn, buffer, 0); diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 49ec34f..b33e2d6 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -143,7 +143,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) return false; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; network = virNetworkCreateXML(ctl->conn, buffer); @@ -188,7 +188,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) return false; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; network = virNetworkDefineXML(ctl->conn, buffer); diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 5a0987d..1398fbd 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -55,7 +55,7 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) return false; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; dev = virNodeDeviceCreateXML(ctl->conn, buffer, 0); diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index e937b63..501e20d 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -94,7 +94,7 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) return false; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; nwfilter = virNWFilterDefineXML(ctl->conn, buffer); diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index af80427..e015547 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -141,7 +141,7 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) return false; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; pool = virStoragePoolCreateXML(ctl->conn, buffer, 0); @@ -303,7 +303,7 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) return false; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; pool = virStoragePoolDefineXML(ctl->conn, buffer, 0); @@ -748,7 +748,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) const char *unit; /* Create the capacity output string */ - val = prettyCapacity(info.capacity, &unit); + val = vshPrettyCapacity(info.capacity, &unit); ret = virAsprintf(&poolInfoTexts[i].capacity, "%.2lf %s", val, unit); if (ret < 0) { @@ -757,7 +757,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) } /* Create the allocation output string */ - val = prettyCapacity(info.allocation, &unit); + val = vshPrettyCapacity(info.allocation, &unit); ret = virAsprintf(&poolInfoTexts[i].allocation, "%.2lf %s", val, unit); if (ret < 0) { @@ -766,7 +766,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) } /* Create the available space output string */ - val = prettyCapacity(info.available, &unit); + val = vshPrettyCapacity(info.available, &unit); ret = virAsprintf(&poolInfoTexts[i].available, "%.2lf %s", val, unit); if (ret < 0) { @@ -1090,7 +1090,8 @@ cmdPoolDiscoverSources(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED) if (!vshConnectionUsability(ctl, ctl->conn)) return false; - if (srcSpecFile && virFileReadAll(srcSpecFile, VIRSH_MAX_XML_FILE, &srcSpec) < 0) + if (srcSpecFile && virFileReadAll(srcSpecFile, VSH_MAX_XML_FILE, + &srcSpec) < 0) return false; srcList = virConnectFindStoragePoolSources(ctl->conn, type, srcSpec, 0); @@ -1186,13 +1187,13 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd) if (info.state == VIR_STORAGE_POOL_RUNNING || info.state == VIR_STORAGE_POOL_DEGRADED) { - val = prettyCapacity(info.capacity, &unit); + val = vshPrettyCapacity(info.capacity, &unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit); - val = prettyCapacity(info.allocation, &unit); + val = vshPrettyCapacity(info.allocation, &unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit); - val = prettyCapacity(info.available, &unit); + val = vshPrettyCapacity(info.available, &unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Available:"), val, unit); } } else { diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index e6c2ece..049ead5 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -78,7 +78,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file", &from) <= 0) return false; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; res = virSecretDefineXML(ctl->conn, buffer, 0); diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 24e44b0..c480d1b 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -46,7 +46,7 @@ vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer, vshResetLibvirtError(); persistent = virDomainIsPersistent(dom); if (persistent < 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } if (!persistent) { @@ -64,7 +64,7 @@ vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer, goto cleanup; if (halt && virDomainDestroy(dom) < 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } @@ -149,12 +149,12 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "xmlfile", &from) <= 0) buffer = vshStrdup(ctl, "<domainsnapshot/>"); else { - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { /* we have to report the error here because during cleanup * we'll run through virDomainFree(), which loses the * last error */ - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } } @@ -362,7 +362,7 @@ vshLookupSnapshot(vshControl *ctl, const vshCmd *cmd, return -1; } if (!*snap) { - virshReportError(ctl); + vshReportError(ctl); return -1; } @@ -455,7 +455,7 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd) delete_flags = VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY; if (virDomainSnapshotDelete(rename_okay ? snapshot : edited, delete_flags) < 0) { - virshReportError(ctl); + vshReportError(ctl); vshError(ctl, _("Failed to clean up %s"), rename_okay ? name : edited_name); goto cleanup; @@ -583,7 +583,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd) cleanup: if (!ret) - virshReportError(ctl); + vshReportError(ctl); VIR_FREE(xml); if (snapshot) virDomainSnapshotFree(snapshot); @@ -640,7 +640,7 @@ vshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot, cleanup: if (ret < 0) { - virshReportError(ctl); + vshReportError(ctl); vshError(ctl, "%s", _("unable to determine if snapshot has parent")); } else { vshResetLibvirtError(); diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 5e5d925..d8ff920 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -300,8 +300,8 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) return false; } - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { + vshReportError(ctl); virStoragePoolFree(pool); return false; } @@ -360,8 +360,8 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) if (!(inputvol = vshCommandOptVol(ctl, cmd, "vol", "inputpool", NULL))) goto cleanup; - if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { + vshReportError(ctl); goto cleanup; } @@ -847,10 +847,10 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%-15s %s\n", _("Type:"), _("unknown")); } - val = prettyCapacity(info.capacity, &unit); + val = vshPrettyCapacity(info.capacity, &unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit); - val = prettyCapacity(info.allocation, &unit); + val = vshPrettyCapacity(info.allocation, &unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit); } else { ret = false; @@ -1098,7 +1098,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) } /* Create the capacity output string */ - val = prettyCapacity(volumeInfo.capacity, &unit); + val = vshPrettyCapacity(volumeInfo.capacity, &unit); ret = virAsprintf(&volInfoTexts[i].capacity, "%.2lf %s", val, unit); if (ret < 0) { @@ -1107,7 +1107,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) } /* Create the allocation output string */ - val = prettyCapacity(volumeInfo.allocation, &unit); + val = vshPrettyCapacity(volumeInfo.allocation, &unit); ret = virAsprintf(&volInfoTexts[i].allocation, "%.2lf %s", val, unit); if (ret < 0) { diff --git a/tools/virsh.c b/tools/virsh.c index ecb27df..14d7cae 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -140,7 +140,7 @@ vshNameSorter(const void *a, const void *b) } double -prettyCapacity(unsigned long long val, const char **unit) +vshPrettyCapacity(unsigned long long val, const char **unit) { if (val < 1024) { *unit = ""; @@ -194,7 +194,7 @@ vshResetLibvirtError(void) * and it's IMHO a bug that libvirt does that sometimes. */ void -virshReportError(vshControl *ctl) +vshReportError(vshControl *ctl) { if (last_error == NULL) { /* Calling directly into libvirt util functions won't trigger the @@ -312,7 +312,7 @@ vshAskReedit(vshControl *ctl, const char *msg) if (!isatty(STDIN_FILENO)) return -1; - virshReportError(ctl); + vshReportError(ctl); if (vshMakeStdinRaw(&ttyattr, false) < 0) return -1; @@ -509,7 +509,7 @@ vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque, /* Common code for the edit / net-edit / pool-edit functions which follow. */ char * -editWriteToTempFile(vshControl *ctl, const char *doc) +vshEditWriteToTempFile(vshControl *ctl, const char *doc) { char *ret; const char *tmpdir; @@ -554,7 +554,7 @@ editWriteToTempFile(vshControl *ctl, const char *doc) "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/_.:@" int -editFile(vshControl *ctl, const char *filename) +vshEditFile(vshControl *ctl, const char *filename) { const char *editor; virCommandPtr cmd; @@ -595,7 +595,7 @@ editFile(vshControl *ctl, const char *filename) virCommandSetErrorFD(cmd, &errfd); if (virCommandRunAsync(cmd, NULL) < 0 || virCommandWait(cmd, NULL) < 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } ret = 0; @@ -606,11 +606,11 @@ cleanup: } char * -editReadBackFile(vshControl *ctl, const char *filename) +vshEditReadBackFile(vshControl *ctl, const char *filename) { char *ret; - if (virFileReadAll(filename, VIRSH_MAX_XML_FILE, &ret) == -1) { + if (virFileReadAll(filename, VSH_MAX_XML_FILE, &ret) == -1) { vshError(ctl, _("%s: failed to read temporary file: %s"), filename, strerror(errno)); @@ -1551,7 +1551,7 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd) disconnected++; if (!ret) - virshReportError(ctl); + vshReportError(ctl); if (!ret && disconnected != 0) vshReconnect(ctl); @@ -1559,11 +1559,14 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd) if (STREQ(cmd->def->name, "quit")) /* hack ... */ return ret; - if (enable_timing) - vshPrint(ctl, _("\n(Time: %.3f ms)\n\n"), - DIFF_MSEC(&after, &before)); - else + if (enable_timing) { + double diff_ms = (((after.tv_sec - before.tv_sec) * 1000000.0) + + ((after.tv_usec - before.tv_usec) / 1000.0)); + + vshPrint(ctl, _("\n(Time: %.3f ms)\n\n"), diff_ms); + } else { vshPrintExtra(ctl, "\n"); + } cmd = cmd->next; } return ret; @@ -2100,7 +2103,7 @@ vshEventLoop(void *opaque) break; if (virEventRunDefaultImpl() < 0) - virshReportError(ctl); + vshReportError(ctl); } } @@ -2108,7 +2111,7 @@ vshEventLoop(void *opaque) /* * Initialize connection. */ -bool +static bool vshInit(vshControl *ctl) { char *debugEnv; @@ -2163,7 +2166,7 @@ vshInit(vshControl *ctl) * connection). */ if (!ctl->conn) { - virshReportError(ctl); + vshReportError(ctl); vshError(ctl, "%s", _("failed to connect to the hypervisor")); return false; } @@ -2544,7 +2547,7 @@ vshDeinitTimer(int timer ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) /* * Deinitialize virsh */ -bool +static bool vshDeinit(vshControl *ctl) { vshReadlineDeinit(ctl); @@ -2583,7 +2586,7 @@ vshDeinit(vshControl *ctl) /* * Print usage */ -void +static void vshUsage(void) { const vshCmdGrp *grp; @@ -2774,7 +2777,7 @@ vshAllowedEscapeChar(char c) * argv[]: virsh [options] [command] * */ -bool +static bool vshParseArgv(vshControl *ctl, int argc, char **argv) { int arg, len, debug; @@ -2915,7 +2918,7 @@ main(int argc, char **argv) ctl->imode = true; /* default is interactive mode */ ctl->log_fd = -1; /* Initialize log file descriptor */ ctl->debug = VSH_DEBUG_DEFAULT; - ctl->escapeChar = CTRL_CLOSE_BRACKET; + ctl->escapeChar = "^]"; /* Same default as telnet */ if (!setlocale(LC_ALL, "")) { diff --git a/tools/virsh.h b/tools/virsh.h index 0b1f123..764369e 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -38,7 +38,7 @@ # include "threads.h" # include "virnetdevbandwidth.h" -# define VIRSH_MAX_XML_FILE 10*1024*1024 +# define VSH_MAX_XML_FILE (10*1024*1024) # define VSH_PROMPT_RW "virsh # " # define VSH_PROMPT_RO "virsh > " @@ -46,12 +46,6 @@ # define VIR_FROM_THIS VIR_FROM_NONE # define GETTIMEOFDAY(T) gettimeofday(T, NULL) -# define DIFF_MSEC(T, U) \ - ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \ - ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0) - -/* Default escape char Ctrl-] as per telnet */ -# define CTRL_CLOSE_BRACKET "^]" /** * The log configuration @@ -253,17 +247,12 @@ struct _vshCmdGrp { void vshError(vshControl *ctl, const char *format, ...) ATTRIBUTE_FMT_PRINTF(2, 3); -bool vshInit(vshControl *ctl); -bool vshDeinit(vshControl *ctl); -void vshUsage(void); void vshOpenLogFile(vshControl *ctl); void vshOutputLogFile(vshControl *ctl, int log_level, const char *format, va_list ap) ATTRIBUTE_FMT_PRINTF(3, 0); void vshCloseLogFile(vshControl *ctl); -bool vshParseArgv(vshControl *ctl, int argc, char **argv); - const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info); const vshCmdDef *vshCmddefSearch(const char *cmdname); bool vshCmddefHelp(vshControl *ctl, const char *name); @@ -332,13 +321,13 @@ virTypedParameterPtr vshFindTypedParamByName(const char *name, char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); -char *editWriteToTempFile(vshControl *ctl, const char *doc); -int editFile(vshControl *ctl, const char *filename); -char *editReadBackFile(vshControl *ctl, const char *filename); +char *vshEditWriteToTempFile(vshControl *ctl, const char *doc); +int vshEditFile(vshControl *ctl, const char *filename); +char *vshEditReadBackFile(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); +double vshPrettyCapacity(unsigned long long val, const char **unit); /* Typedefs, function prototypes for job progress reporting. * There are used by some long lingering commands like @@ -350,12 +339,9 @@ struct _vshCtrlData { int writefd; }; -typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom, - void *opaque); - /* error handling */ extern virErrorPtr last_error; -void virshReportError(vshControl *ctl); +void vshReportError(vshControl *ctl); void vshResetLibvirtError(void); /* allocation wrappers */ -- 1.7.11.4

On 2012年08月19日 12:10, Eric Blake wrote:
Convert the exported items in virsh.h to use a common 'vsh' prefix.
* tools/virsh.h (VIRSH_MAX_XML_FILE, GETTIMEOFDAY): Rename... (VSH_MAX_XML_FILE): ...and parenthesize. (DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete. (vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype. (editWriteToTempFile, editFile, editReadBackFile, prettyCapacity) (virshReportError): Rename... (vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile) (vshPrettyCapacity, vshReportError): ...into vsh namespace. (jobWatchTimeoutFunc): Move to virsh-domain.c. * tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC. (main): Inline former CTRL_CLOSE_BRACKET. (vshUsage, vshInit, vshDeinit, vshParseArgv): Make static. (prettyCapacity, virshReportError, editWriteToTempFile, editFile): Fix naming, and adjust usage. (vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust usage. * tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare) (cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice) (cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount) (cmdAttachDevice, cmdDomjobinfo): Likewise. * tools/virsh-edit.c (do): Likewise. * tools/virsh-interface.c (cmdInterfaceDefine): Likewise. * tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine): Likewise. * tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise. * tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise. * tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine) (cmdPoolDiscoverSources, cmdPoolList): Likewise. * tools/virsh-secret.c (cmdSecretDefine): Likewise. * tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate) (vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent) (vshGetSnapshotParent): Likewise. * tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom) (cmdVolInfo, cmdVolList): Likewise. --- tools/virsh-domain.c | 65 ++++++++++++++++++++++++++----------------------- tools/virsh-edit.c | 6 ++--- tools/virsh-interface.c | 2 +- tools/virsh-network.c | 4 +-- tools/virsh-nodedev.c | 2 +- tools/virsh-nwfilter.c | 2 +- tools/virsh-pool.c | 19 ++++++++------- tools/virsh-secret.c | 2 +- tools/virsh-snapshot.c | 16 ++++++------ tools/virsh-volume.c | 16 ++++++------ tools/virsh.c | 43 +++++++++++++++++--------------- tools/virsh.h | 26 +++++--------------- 12 files changed, 98 insertions(+), 105 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index edbda91..d102378 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -105,8 +105,8 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) return false; }
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { + vshReportError(ctl); virDomainFree(dom); return false; } @@ -2544,7 +2544,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) goto cleanup; } if (virDomainManagedSaveRemove(dom, 0)< 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } } @@ -2618,7 +2618,7 @@ cleanup: return ret;
error: - virshReportError(ctl); + vshReportError(ctl); goto cleanup; }
@@ -2687,7 +2687,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) goto started; if (last_error->code != VIR_ERR_NO_SUPPORT&& last_error->code != VIR_ERR_INVALID_ARG) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } vshResetLibvirtError(); @@ -2697,7 +2697,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) vshResetLibvirtError(); } else if (rc> 0) { if (virDomainManagedSaveRemove(dom, 0)< 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } } @@ -2809,6 +2809,9 @@ out_sig: ignore_value(safewrite(data->writefd,&ret, sizeof(ret))); }
+typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom, + void *opaque); + static bool vshWatchJob(vshControl *ctl, virDomainPtr dom, @@ -4088,27 +4091,27 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd) if (info.type == VIR_DOMAIN_JOB_BOUNDED) vshPrint(ctl, "%-17s %-12llu ms\n", _("Time remaining:"), info.timeRemaining); if (info.dataTotal || info.dataRemaining || info.dataProcessed) { - val = prettyCapacity(info.dataProcessed,&unit); + val = vshPrettyCapacity(info.dataProcessed,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data processed:"), val, unit); - val = prettyCapacity(info.dataRemaining,&unit); + val = vshPrettyCapacity(info.dataRemaining,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data remaining:"), val, unit); - val = prettyCapacity(info.dataTotal,&unit); + val = vshPrettyCapacity(info.dataTotal,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data total:"), val, unit); } if (info.memTotal || info.memRemaining || info.memProcessed) { - val = prettyCapacity(info.memProcessed,&unit); + val = vshPrettyCapacity(info.memProcessed,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory processed:"), val, unit); - val = prettyCapacity(info.memRemaining,&unit); + val = vshPrettyCapacity(info.memRemaining,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory remaining:"), val, unit); - val = prettyCapacity(info.memTotal,&unit); + val = vshPrettyCapacity(info.memTotal,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory total:"), val, unit); } if (info.fileTotal || info.fileRemaining || info.fileProcessed) { - val = prettyCapacity(info.fileProcessed,&unit); + val = vshPrettyCapacity(info.fileProcessed,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("File processed:"), val, unit); - val = prettyCapacity(info.fileRemaining,&unit); + val = vshPrettyCapacity(info.fileRemaining,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("File remaining:"), val, unit); - val = prettyCapacity(info.fileTotal,&unit); + val = vshPrettyCapacity(info.fileTotal,&unit); vshPrint(ctl, "%-17s %-.3lf %s\n", _("File total:"), val, unit); } } else { @@ -4275,7 +4278,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) count = virDomainGetVcpusFlags(dom, maximum ? VIR_DOMAIN_VCPU_MAXIMUM : 0); if (count< 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else { vshPrint(ctl, "%d\n", count); @@ -4299,7 +4302,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) }
if (count< 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else if (all) { vshPrint(ctl, "%-12s %-12s %3d\n", _("maximum"), _("config"), @@ -4319,7 +4322,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) }
if (count< 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else if (all) { vshPrint(ctl, "%-12s %-12s %3d\n", _("maximum"), _("live"), @@ -4355,7 +4358,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) }
if (count< 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else if (all) { vshPrint(ctl, "%-12s %-12s %3d\n", _("current"), _("config"), @@ -4376,7 +4379,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd) }
if (count< 0) { - virshReportError(ctl); + vshReportError(ctl); ret = false; } else if (all) { vshPrint(ctl, "%-12s %-12s %3d\n", _("current"), _("live"), @@ -4869,7 +4872,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { vshError(ctl, _("Failed to read file '%s' to compare"), from); return false; @@ -4972,7 +4975,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
/* add a separate container around the xml */ @@ -5234,7 +5237,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
if (vshCommandOptBool(cmd, "paused")) @@ -5288,7 +5291,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
dom = virDomainDefineXML(ctl->conn, buffer); @@ -5448,15 +5451,15 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
if (edit) { /* Create and open the temporary file. */ - if (!(tmp = editWriteToTempFile(ctl, desc))) + if (!(tmp = vshEditWriteToTempFile(ctl, desc))) goto cleanup;
/* Start the editor. */ - if (editFile(ctl, tmp) == -1) + if (vshEditFile(ctl, tmp) == -1) goto cleanup;
/* Read back the edited file. */ - if (!(desc_edited = editReadBackFile(ctl, tmp))) + if (!(desc_edited = vshEditReadBackFile(ctl, tmp))) goto cleanup;
/* strip a possible newline at the end of file; some @@ -7368,8 +7371,8 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) goto cleanup;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { + vshReportError(ctl); goto cleanup; }
@@ -7434,8 +7437,8 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd) return false; }
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { + vshReportError(ctl); virDomainFree(dom); return false; } diff --git a/tools/virsh-edit.c b/tools/virsh-edit.c index 4dea4b8..512ac0d 100644 --- a/tools/virsh-edit.c +++ b/tools/virsh-edit.c @@ -75,17 +75,17 @@ do { goto edit_cleanup;
/* Create and open the temporary file. */ - tmp = editWriteToTempFile(ctl, doc); + tmp = vshEditWriteToTempFile(ctl, doc); if (!tmp) goto edit_cleanup;
reedit: /* Start the editor. */ - if (editFile(ctl, tmp) == -1) + if (vshEditFile(ctl, tmp) == -1) goto edit_cleanup;
/* Read back the edited file. */ - doc_edited = editReadBackFile(ctl, tmp); + doc_edited = vshEditReadBackFile(ctl, tmp); if (!doc_edited) goto edit_cleanup;
diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 12019b4..ad080a1 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -369,7 +369,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
iface = virInterfaceDefineXML(ctl->conn, buffer, 0); diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 49ec34f..b33e2d6 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -143,7 +143,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
network = virNetworkCreateXML(ctl->conn, buffer); @@ -188,7 +188,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
network = virNetworkDefineXML(ctl->conn, buffer); diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 5a0987d..1398fbd 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -55,7 +55,7 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
dev = virNodeDeviceCreateXML(ctl->conn, buffer, 0); diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index e937b63..501e20d 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -94,7 +94,7 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
nwfilter = virNWFilterDefineXML(ctl->conn, buffer); diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index af80427..e015547 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -141,7 +141,7 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
pool = virStoragePoolCreateXML(ctl->conn, buffer, 0); @@ -303,7 +303,7 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
pool = virStoragePoolDefineXML(ctl->conn, buffer, 0); @@ -748,7 +748,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) const char *unit;
/* Create the capacity output string */ - val = prettyCapacity(info.capacity,&unit); + val = vshPrettyCapacity(info.capacity,&unit); ret = virAsprintf(&poolInfoTexts[i].capacity, "%.2lf %s", val, unit); if (ret< 0) { @@ -757,7 +757,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) }
/* Create the allocation output string */ - val = prettyCapacity(info.allocation,&unit); + val = vshPrettyCapacity(info.allocation,&unit); ret = virAsprintf(&poolInfoTexts[i].allocation, "%.2lf %s", val, unit); if (ret< 0) { @@ -766,7 +766,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) }
/* Create the available space output string */ - val = prettyCapacity(info.available,&unit); + val = vshPrettyCapacity(info.available,&unit); ret = virAsprintf(&poolInfoTexts[i].available, "%.2lf %s", val, unit); if (ret< 0) { @@ -1090,7 +1090,8 @@ cmdPoolDiscoverSources(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED) if (!vshConnectionUsability(ctl, ctl->conn)) return false;
- if (srcSpecFile&& virFileReadAll(srcSpecFile, VIRSH_MAX_XML_FILE,&srcSpec)< 0) + if (srcSpecFile&& virFileReadAll(srcSpecFile, VSH_MAX_XML_FILE, +&srcSpec)< 0) return false;
srcList = virConnectFindStoragePoolSources(ctl->conn, type, srcSpec, 0); @@ -1186,13 +1187,13 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
if (info.state == VIR_STORAGE_POOL_RUNNING || info.state == VIR_STORAGE_POOL_DEGRADED) { - val = prettyCapacity(info.capacity,&unit); + val = vshPrettyCapacity(info.capacity,&unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit);
- val = prettyCapacity(info.allocation,&unit); + val = vshPrettyCapacity(info.allocation,&unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit);
- val = prettyCapacity(info.available,&unit); + val = vshPrettyCapacity(info.available,&unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Available:"), val, unit); } } else { diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index e6c2ece..049ead5 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -78,7 +78,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "file",&from)<= 0) return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) return false;
res = virSecretDefineXML(ctl->conn, buffer, 0); diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 24e44b0..c480d1b 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -46,7 +46,7 @@ vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer, vshResetLibvirtError(); persistent = virDomainIsPersistent(dom); if (persistent< 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } if (!persistent) { @@ -64,7 +64,7 @@ vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer, goto cleanup;
if (halt&& virDomainDestroy(dom)< 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; }
@@ -149,12 +149,12 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptString(cmd, "xmlfile",&from)<= 0) buffer = vshStrdup(ctl, "<domainsnapshot/>"); else { - if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { /* we have to report the error here because during cleanup * we'll run through virDomainFree(), which loses the * last error */ - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } } @@ -362,7 +362,7 @@ vshLookupSnapshot(vshControl *ctl, const vshCmd *cmd, return -1; } if (!*snap) { - virshReportError(ctl); + vshReportError(ctl); return -1; }
@@ -455,7 +455,7 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd) delete_flags = VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY; if (virDomainSnapshotDelete(rename_okay ? snapshot : edited, delete_flags)< 0) { - virshReportError(ctl); + vshReportError(ctl); vshError(ctl, _("Failed to clean up %s"), rename_okay ? name : edited_name); goto cleanup; @@ -583,7 +583,7 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
cleanup: if (!ret) - virshReportError(ctl); + vshReportError(ctl); VIR_FREE(xml); if (snapshot) virDomainSnapshotFree(snapshot); @@ -640,7 +640,7 @@ vshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot,
cleanup: if (ret< 0) { - virshReportError(ctl); + vshReportError(ctl); vshError(ctl, "%s", _("unable to determine if snapshot has parent")); } else { vshResetLibvirtError(); diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 5e5d925..d8ff920 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -300,8 +300,8 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) return false; }
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { + vshReportError(ctl); virStoragePoolFree(pool); return false; } @@ -360,8 +360,8 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) if (!(inputvol = vshCommandOptVol(ctl, cmd, "vol", "inputpool", NULL))) goto cleanup;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE,&buffer)< 0) { - virshReportError(ctl); + if (virFileReadAll(from, VSH_MAX_XML_FILE,&buffer)< 0) { + vshReportError(ctl); goto cleanup; }
@@ -847,10 +847,10 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%-15s %s\n", _("Type:"), _("unknown")); }
- val = prettyCapacity(info.capacity,&unit); + val = vshPrettyCapacity(info.capacity,&unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit);
- val = prettyCapacity(info.allocation,&unit); + val = vshPrettyCapacity(info.allocation,&unit); vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit); } else { ret = false; @@ -1098,7 +1098,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) }
/* Create the capacity output string */ - val = prettyCapacity(volumeInfo.capacity,&unit); + val = vshPrettyCapacity(volumeInfo.capacity,&unit); ret = virAsprintf(&volInfoTexts[i].capacity, "%.2lf %s", val, unit); if (ret< 0) { @@ -1107,7 +1107,7 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) }
/* Create the allocation output string */ - val = prettyCapacity(volumeInfo.allocation,&unit); + val = vshPrettyCapacity(volumeInfo.allocation,&unit); ret = virAsprintf(&volInfoTexts[i].allocation, "%.2lf %s", val, unit); if (ret< 0) { diff --git a/tools/virsh.c b/tools/virsh.c index ecb27df..14d7cae 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -140,7 +140,7 @@ vshNameSorter(const void *a, const void *b) }
double -prettyCapacity(unsigned long long val, const char **unit) +vshPrettyCapacity(unsigned long long val, const char **unit) { if (val< 1024) { *unit = ""; @@ -194,7 +194,7 @@ vshResetLibvirtError(void) * and it's IMHO a bug that libvirt does that sometimes. */ void -virshReportError(vshControl *ctl) +vshReportError(vshControl *ctl) { if (last_error == NULL) { /* Calling directly into libvirt util functions won't trigger the @@ -312,7 +312,7 @@ vshAskReedit(vshControl *ctl, const char *msg) if (!isatty(STDIN_FILENO)) return -1;
- virshReportError(ctl); + vshReportError(ctl);
if (vshMakeStdinRaw(&ttyattr, false)< 0) return -1; @@ -509,7 +509,7 @@ vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque,
/* Common code for the edit / net-edit / pool-edit functions which follow. */ char * -editWriteToTempFile(vshControl *ctl, const char *doc) +vshEditWriteToTempFile(vshControl *ctl, const char *doc) { char *ret; const char *tmpdir; @@ -554,7 +554,7 @@ editWriteToTempFile(vshControl *ctl, const char *doc) "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/_.:@"
int -editFile(vshControl *ctl, const char *filename) +vshEditFile(vshControl *ctl, const char *filename) { const char *editor; virCommandPtr cmd; @@ -595,7 +595,7 @@ editFile(vshControl *ctl, const char *filename) virCommandSetErrorFD(cmd,&errfd); if (virCommandRunAsync(cmd, NULL)< 0 || virCommandWait(cmd, NULL)< 0) { - virshReportError(ctl); + vshReportError(ctl); goto cleanup; } ret = 0; @@ -606,11 +606,11 @@ cleanup: }
char * -editReadBackFile(vshControl *ctl, const char *filename) +vshEditReadBackFile(vshControl *ctl, const char *filename) { char *ret;
- if (virFileReadAll(filename, VIRSH_MAX_XML_FILE,&ret) == -1) { + if (virFileReadAll(filename, VSH_MAX_XML_FILE,&ret) == -1) { vshError(ctl, _("%s: failed to read temporary file: %s"), filename, strerror(errno)); @@ -1551,7 +1551,7 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd) disconnected++;
if (!ret) - virshReportError(ctl); + vshReportError(ctl);
if (!ret&& disconnected != 0) vshReconnect(ctl); @@ -1559,11 +1559,14 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd) if (STREQ(cmd->def->name, "quit")) /* hack ... */ return ret;
- if (enable_timing) - vshPrint(ctl, _("\n(Time: %.3f ms)\n\n"), - DIFF_MSEC(&after,&before)); - else + if (enable_timing) { + double diff_ms = (((after.tv_sec - before.tv_sec) * 1000000.0) + + ((after.tv_usec - before.tv_usec) / 1000.0)); + + vshPrint(ctl, _("\n(Time: %.3f ms)\n\n"), diff_ms); + } else { vshPrintExtra(ctl, "\n"); + } cmd = cmd->next; } return ret; @@ -2100,7 +2103,7 @@ vshEventLoop(void *opaque) break;
if (virEventRunDefaultImpl()< 0) - virshReportError(ctl); + vshReportError(ctl); } }
@@ -2108,7 +2111,7 @@ vshEventLoop(void *opaque) /* * Initialize connection. */ -bool +static bool vshInit(vshControl *ctl) { char *debugEnv; @@ -2163,7 +2166,7 @@ vshInit(vshControl *ctl) * connection). */ if (!ctl->conn) { - virshReportError(ctl); + vshReportError(ctl); vshError(ctl, "%s", _("failed to connect to the hypervisor")); return false; } @@ -2544,7 +2547,7 @@ vshDeinitTimer(int timer ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED) /* * Deinitialize virsh */ -bool +static bool vshDeinit(vshControl *ctl) { vshReadlineDeinit(ctl); @@ -2583,7 +2586,7 @@ vshDeinit(vshControl *ctl) /* * Print usage */ -void +static void vshUsage(void) { const vshCmdGrp *grp; @@ -2774,7 +2777,7 @@ vshAllowedEscapeChar(char c) * argv[]: virsh [options] [command] * */ -bool +static bool vshParseArgv(vshControl *ctl, int argc, char **argv) { int arg, len, debug; @@ -2915,7 +2918,7 @@ main(int argc, char **argv) ctl->imode = true; /* default is interactive mode */ ctl->log_fd = -1; /* Initialize log file descriptor */ ctl->debug = VSH_DEBUG_DEFAULT; - ctl->escapeChar = CTRL_CLOSE_BRACKET; + ctl->escapeChar = "^]"; /* Same default as telnet */
if (!setlocale(LC_ALL, "")) { diff --git a/tools/virsh.h b/tools/virsh.h index 0b1f123..764369e 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -38,7 +38,7 @@ # include "threads.h" # include "virnetdevbandwidth.h"
-# define VIRSH_MAX_XML_FILE 10*1024*1024 +# define VSH_MAX_XML_FILE (10*1024*1024)
# define VSH_PROMPT_RW "virsh # " # define VSH_PROMPT_RO "virsh> " @@ -46,12 +46,6 @@ # define VIR_FROM_THIS VIR_FROM_NONE
# define GETTIMEOFDAY(T) gettimeofday(T, NULL) -# define DIFF_MSEC(T, U) \ - ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \ - ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0) - -/* Default escape char Ctrl-] as per telnet */ -# define CTRL_CLOSE_BRACKET "^]"
/** * The log configuration @@ -253,17 +247,12 @@ struct _vshCmdGrp {
void vshError(vshControl *ctl, const char *format, ...) ATTRIBUTE_FMT_PRINTF(2, 3); -bool vshInit(vshControl *ctl); -bool vshDeinit(vshControl *ctl); -void vshUsage(void); void vshOpenLogFile(vshControl *ctl); void vshOutputLogFile(vshControl *ctl, int log_level, const char *format, va_list ap) ATTRIBUTE_FMT_PRINTF(3, 0); void vshCloseLogFile(vshControl *ctl);
-bool vshParseArgv(vshControl *ctl, int argc, char **argv); - const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info); const vshCmdDef *vshCmddefSearch(const char *cmdname); bool vshCmddefHelp(vshControl *ctl, const char *name); @@ -332,13 +321,13 @@ virTypedParameterPtr vshFindTypedParamByName(const char *name, char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-char *editWriteToTempFile(vshControl *ctl, const char *doc); -int editFile(vshControl *ctl, const char *filename); -char *editReadBackFile(vshControl *ctl, const char *filename); +char *vshEditWriteToTempFile(vshControl *ctl, const char *doc); +int vshEditFile(vshControl *ctl, const char *filename); +char *vshEditReadBackFile(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); +double vshPrettyCapacity(unsigned long long val, const char **unit);
/* Typedefs, function prototypes for job progress reporting. * There are used by some long lingering commands like @@ -350,12 +339,9 @@ struct _vshCtrlData { int writefd; };
-typedef void (*jobWatchTimeoutFunc) (vshControl *ctl, virDomainPtr dom, - void *opaque); - /* error handling */ extern virErrorPtr last_error; -void virshReportError(vshControl *ctl); +void vshReportError(vshControl *ctl); void vshResetLibvirtError(void);
/* allocation wrappers */
ACK.

On 08/20/2012 04:14 AM, Osier Yang wrote:
On 2012年08月19日 12:10, Eric Blake wrote:
Convert the exported items in virsh.h to use a common 'vsh' prefix.
ACK.
Thanks; pushed. More to come... -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Another file worth compiling on its own instead of by .c inclusion. * tools/virsh-domain-monitor.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.h (vshGetDomainDescription): Move to correct header. * tools/virsh-domain-monitor.c: Use new header. * tools/virsh.c: Likewise. * tools/virsh-domain.c: Likewise. --- tools/Makefile.am | 2 +- tools/virsh-domain-monitor.c | 15 ++++++++++++++- tools/virsh-domain-monitor.h | 37 +++++++++++++++++++++++++++++++++++++ tools/virsh-domain.c | 1 + tools/virsh.c | 2 +- tools/virsh.h | 3 --- 6 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 tools/virsh-domain-monitor.h diff --git a/tools/Makefile.am b/tools/Makefile.am index b885892..6b066f6 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -107,8 +107,8 @@ virsh_SOURCES = \ console.c console.h \ virsh.c virsh.h \ virsh-domain.c virsh-domain.h \ + virsh-domain-monitor.c virsh-domain-monitor.h \ $(NULL) -# virsh-domain-monitor.c virsh-domain-monitor.h \ # virsh-host.c virsh-host.h \ # virsh-interface.c virsh-interface.h \ # virsh-network.c virsh-network.h \ diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 52e44c9..4f00e65 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -23,7 +23,20 @@ * */ +#include <config.h> +#include "virsh-domain-monitor.h" + +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> + +#include "internal.h" +#include "conf/domain_conf.h" #include "intprops.h" +#include "memory.h" +#include "virmacaddr.h" +#include "xml.h" static const char * vshDomainIOErrorToString(int error) @@ -1683,7 +1696,7 @@ cleanup: } #undef FILTER -static const vshCmdDef domMonitoringCmds[] = { +const vshCmdDef domMonitoringCmds[] = { {"domblkerror", cmdDomBlkError, opts_domblkerror, info_domblkerror, 0}, {"domblkinfo", cmdDomblkinfo, opts_domblkinfo, info_domblkinfo, 0}, {"domblklist", cmdDomblklist, opts_domblklist, info_domblklist, 0}, diff --git a/tools/virsh-domain-monitor.h b/tools/virsh-domain-monitor.h new file mode 100644 index 0000000..e322006 --- /dev/null +++ b/tools/virsh-domain-monitor.h @@ -0,0 +1,37 @@ +/* + * virsh-domain-monitor.h: Commands to monitor domain status + * + * 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_MONITOR_H +# define VIRSH_DOMAIN_MONITOR_H + +# include "virsh.h" + +char *vshGetDomainDescription(vshControl *ctl, virDomainPtr dom, + bool title, unsigned int flags) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; + +extern const vshCmdDef domMonitoringCmds[]; + +#endif /* VIRSH_DOMAIN_MONITOR_H */ diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index d102378..bf707c4 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -48,6 +48,7 @@ #include "virfile.h" #include "virkeycode.h" #include "virmacaddr.h" +#include "virsh-domain-monitor.h" #include "virterror_internal.h" #include "virtypedparam.h" #include "xml.h" diff --git a/tools/virsh.c b/tools/virsh.c index 95a8bf6..89ccdb1 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -79,6 +79,7 @@ #include "virtypedparam.h" #include "virsh-domain.h" +#include "virsh-domain-monitor.h" static char *progname; @@ -2870,7 +2871,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; } -#include "virsh-domain-monitor.c" #include "virsh-host.c" #include "virsh-interface.c" #include "virsh-network.c" diff --git a/tools/virsh.h b/tools/virsh.h index 764369e..24d2020 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -286,9 +286,6 @@ int vshCommandOptScaledInt(const vshCmd *cmd, const char *name, bool vshCommandOptBool(const vshCmd *cmd, const char *name); const vshCmdOpt *vshCommandOptArgv(const vshCmd *cmd, const vshCmdOpt *opt); -char *vshGetDomainDescription(vshControl *ctl, virDomainPtr dom, - bool title, unsigned int flags) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; # define VSH_BYID (1 << 1) # define VSH_BYUUID (1 << 2) -- 1.7.11.4

The splits are getting easier, with fewer cleanups needed in virsh.h. * tools/virsh-host.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh-host.c: Use new header. * tools/virsh.c: Likewise. --- tools/Makefile.am | 2 +- tools/virsh-host.c | 16 +++++++++++++++- tools/virsh-host.h | 33 +++++++++++++++++++++++++++++++++ tools/virsh.c | 2 +- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 tools/virsh-host.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 6b066f6..a3e5ff4 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -108,8 +108,8 @@ virsh_SOURCES = \ virsh.c virsh.h \ virsh-domain.c virsh-domain.h \ virsh-domain-monitor.c virsh-domain-monitor.h \ + virsh-host.c virsh-host.h \ $(NULL) -# virsh-host.c virsh-host.h \ # virsh-interface.c virsh-interface.h \ # virsh-network.c virsh-network.h \ # virsh-nodedev.c virsh-nodedev.h \ diff --git a/tools/virsh-host.c b/tools/virsh-host.c index b09d9f9..e3cff8e 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -23,6 +23,20 @@ * */ +#include <config.h> +#include "virsh-host.h" + +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> + +#include "internal.h" +#include "buf.h" +#include "memory.h" +#include "util.h" +#include "xml.h" + /* * "capabilities" command */ @@ -819,7 +833,7 @@ cmdVersion(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) return true; } -static const vshCmdDef hostAndHypervisorCmds[] = { +const vshCmdDef hostAndHypervisorCmds[] = { {"capabilities", cmdCapabilities, NULL, info_capabilities, 0}, {"connect", cmdConnect, opts_connect, info_connect, VSH_CMD_FLAG_NOCONNECT}, diff --git a/tools/virsh-host.h b/tools/virsh-host.h new file mode 100644 index 0000000..8242f91 --- /dev/null +++ b/tools/virsh-host.h @@ -0,0 +1,33 @@ +/* + * virsh-host.h: Commands in "Host and Hypervisor" group. + * + * 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_HOST_H +# define VIRSH_HOST_H + +# include "virsh.h" + +extern const vshCmdDef hostAndHypervisorCmds[]; + +#endif /* VIRSH_HOST_H */ diff --git a/tools/virsh.c b/tools/virsh.c index fb1af42..793a357 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -76,6 +76,7 @@ #include "virsh-domain.h" #include "virsh-domain-monitor.h" +#include "virsh-host.h" static char *progname; @@ -2862,7 +2863,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; } -#include "virsh-host.c" #include "virsh-interface.c" #include "virsh-network.c" #include "virsh-nodedev.c" -- 1.7.11.4

On 08/20/2012 04:13 PM, Eric Blake wrote:
The splits are getting easier, with fewer cleanups needed in virsh.h.
* tools/virsh-host.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh-host.c: Use new header. * tools/virsh.c: Likewise. --- tools/Makefile.am | 2 +- tools/virsh-host.c | 16 +++++++++++++++- tools/virsh-host.h | 33 +++++++++++++++++++++++++++++++++ tools/virsh.c | 2 +- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 tools/virsh-host.h
Disclaimer: all of my reviews in this series are based purely on a manual examination of the diffs and the assumption that "make check && make syntax-check" passes with no errors. That said, this one seems pretty clear. ACK.

In preparation for splitting virsh-interface.c, I found these functions need to be declared in virsh.h, as well as one that belongs more properly in virsh-domain.h. * tools/virsh.h (vshNameSorter, vshCmdHasOption): Declare. (vshCommandOptDomainBy): Move... * tools/virsh-domain.h): ...here. * tools/virsh.c: (vshNameSorter): Export. (cmd_has_option): Rename... (vshCmdHasOption): ...and export. (vshCommandOptDomainBy): Move... * tools/virsh-domain.c (vshCommandOptDomainBy): ...here. * tools/virsh-network.c (vshCommandOptNetworkBy): Update callers. * tools/virsh-nwfilter.c (vshCommandOptNWFilterBy): Likewise. * tools/virsh-secret.c (vshCommandOptSecret): Likewise. * tools/virsh-domain-monitor.c (includes): Likewise. * tools/virsh-host.c (includes): Likewise. --- tools/virsh-domain-monitor.c | 1 + tools/virsh-domain.c | 48 +++++++++++++++++++++++++++++++++++++++ tools/virsh-domain.h | 12 ++++++++++ tools/virsh-host.c | 1 + tools/virsh-interface.c | 2 +- tools/virsh-network.c | 2 +- tools/virsh-nwfilter.c | 2 +- tools/virsh-secret.c | 2 +- tools/virsh.c | 54 +++----------------------------------------- tools/virsh.h | 14 ++---------- 10 files changed, 71 insertions(+), 67 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 4f00e65..44f65ad 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -36,6 +36,7 @@ #include "intprops.h" #include "memory.h" #include "virmacaddr.h" +#include "virsh-domain.h" #include "xml.h" static const char * diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e949dcf..31f15dc 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -58,6 +58,54 @@ # define SA_SIGINFO 0 #endif +virDomainPtr +vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, + const char **name, int flag) +{ + virDomainPtr dom = NULL; + const char *n = NULL; + int id; + const char *optname = "domain"; + if (!vshCmdHasOption(ctl, cmd, optname)) + return NULL; + + if (vshCommandOptString(cmd, optname, &n) <= 0) + return NULL; + + vshDebug(ctl, VSH_ERR_INFO, "%s: found option <%s>: %s\n", + cmd->def->name, optname, n); + + if (name) + *name = n; + + /* try it by ID */ + if (flag & VSH_BYID) { + if (virStrToLong_i(n, NULL, 10, &id) == 0 && id >= 0) { + vshDebug(ctl, VSH_ERR_DEBUG, + "%s: <%s> seems like domain ID\n", + cmd->def->name, optname); + dom = virDomainLookupByID(ctl->conn, id); + } + } + /* try it by UUID */ + if (dom==NULL && (flag & VSH_BYUUID) && strlen(n)==VIR_UUID_STRING_BUFLEN-1) { + vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as domain UUID\n", + cmd->def->name, optname); + dom = virDomainLookupByUUIDString(ctl->conn, n); + } + /* try it by NAME */ + if (dom==NULL && (flag & VSH_BYNAME)) { + vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as domain NAME\n", + cmd->def->name, optname); + dom = virDomainLookupByName(ctl->conn, n); + } + + if (!dom) + vshError(ctl, _("failed to get domain '%s'"), n); + + return dom; +} + static const char * vshDomainVcpuStateToString(int state) { diff --git a/tools/virsh-domain.h b/tools/virsh-domain.h index b1b7930..21672e7 100644 --- a/tools/virsh-domain.h +++ b/tools/virsh-domain.h @@ -28,6 +28,18 @@ # include "virsh.h" +# define VSH_BYID (1 << 1) +# define VSH_BYUUID (1 << 2) +# define VSH_BYNAME (1 << 3) +# define VSH_BYMAC (1 << 4) + +virDomainPtr vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, + const char **name, int flag); + +/* default is lookup by Id, Name and UUID */ +# define vshCommandOptDomain(_ctl, _cmd, _name) \ + vshCommandOptDomainBy(_ctl, _cmd, _name, VSH_BYID|VSH_BYUUID|VSH_BYNAME) + extern const vshCmdDef domManagementCmds[]; #endif /* VIRSH_DOMAIN_H */ diff --git a/tools/virsh-host.c b/tools/virsh-host.c index e3cff8e..3c44969 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -35,6 +35,7 @@ #include "buf.h" #include "memory.h" #include "util.h" +#include "virsh-domain.h" #include "xml.h" /* diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index ad080a1..e43aa91 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -38,7 +38,7 @@ vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd, if (!optname) optname = "interface"; - if (!cmd_has_option(ctl, cmd, optname)) + if (!vshCmdHasOption(ctl, cmd, optname)) return NULL; if (vshCommandOptString(cmd, optname, &n) <= 0) diff --git a/tools/virsh-network.c b/tools/virsh-network.c index b33e2d6..b891c91 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -35,7 +35,7 @@ vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, virNetworkPtr network = NULL; const char *n = NULL; const char *optname = "network"; - if (!cmd_has_option(ctl, cmd, optname)) + if (!vshCmdHasOption(ctl, cmd, optname)) return NULL; if (vshCommandOptString(cmd, optname, &n) <= 0) diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index 501e20d..a6ef233 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -35,7 +35,7 @@ vshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd, virNWFilterPtr nwfilter = NULL; const char *n = NULL; const char *optname = "nwfilter"; - if (!cmd_has_option(ctl, cmd, optname)) + if (!vshCmdHasOption(ctl, cmd, optname)) return NULL; if (vshCommandOptString(cmd, optname, &n) <= 0) diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 049ead5..6f971da 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -30,7 +30,7 @@ vshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name) const char *n = NULL; const char *optname = "secret"; - if (!cmd_has_option(ctl, cmd, optname)) + if (!vshCmdHasOption(ctl, cmd, optname)) return NULL; if (vshCommandOptString(cmd, optname, &n) <= 0) diff --git a/tools/virsh.c b/tools/virsh.c index 793a357..fe79b7c 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -128,7 +128,7 @@ _vshStrdup(vshControl *ctl, const char *s, const char *filename, int line) /* Poison the raw allocating identifiers in favor of our vsh variants. */ #define strdup use_vshStrdup_instead_of_strdup -static int +int vshNameSorter(const void *a, const void *b) { const char **sa = (const char**)a; @@ -1441,8 +1441,8 @@ vshCommandOptArgv(const vshCmd *cmd, const vshCmdOpt *opt) /* Determine whether CMD->opts includes an option with name OPTNAME. If not, give a diagnostic and return false. If so, return true. */ -static bool -cmd_has_option(vshControl *ctl, const vshCmd *cmd, const char *optname) +bool +vshCmdHasOption(vshControl *ctl, const vshCmd *cmd, const char *optname) { /* Iterate through cmd->opts, to ensure that there is an entry with name OPTNAME and type VSH_OT_DATA. */ @@ -1461,54 +1461,6 @@ cmd_has_option(vshControl *ctl, const vshCmd *cmd, const char *optname) return found; } -virDomainPtr -vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, - const char **name, int flag) -{ - virDomainPtr dom = NULL; - const char *n = NULL; - int id; - const char *optname = "domain"; - if (!cmd_has_option(ctl, cmd, optname)) - return NULL; - - if (vshCommandOptString(cmd, optname, &n) <= 0) - return NULL; - - vshDebug(ctl, VSH_ERR_INFO, "%s: found option <%s>: %s\n", - cmd->def->name, optname, n); - - if (name) - *name = n; - - /* try it by ID */ - if (flag & VSH_BYID) { - if (virStrToLong_i(n, NULL, 10, &id) == 0 && id >= 0) { - vshDebug(ctl, VSH_ERR_DEBUG, - "%s: <%s> seems like domain ID\n", - cmd->def->name, optname); - dom = virDomainLookupByID(ctl->conn, id); - } - } - /* try it by UUID */ - if (dom==NULL && (flag & VSH_BYUUID) && strlen(n)==VIR_UUID_STRING_BUFLEN-1) { - vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as domain UUID\n", - cmd->def->name, optname); - dom = virDomainLookupByUUIDString(ctl->conn, n); - } - /* try it by NAME */ - if (dom==NULL && (flag & VSH_BYNAME)) { - vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as domain NAME\n", - cmd->def->name, optname); - dom = virDomainLookupByName(ctl->conn, n); - } - - if (!dom) - vshError(ctl, _("failed to get domain '%s'"), n); - - return dom; -} - /* * Executes command(s) and returns return code from last command */ diff --git a/tools/virsh.h b/tools/virsh.h index 24d2020..58a2dcd 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -286,18 +286,7 @@ int vshCommandOptScaledInt(const vshCmd *cmd, const char *name, bool vshCommandOptBool(const vshCmd *cmd, const char *name); const vshCmdOpt *vshCommandOptArgv(const vshCmd *cmd, const vshCmdOpt *opt); - -# define VSH_BYID (1 << 1) -# define VSH_BYUUID (1 << 2) -# define VSH_BYNAME (1 << 3) -# define VSH_BYMAC (1 << 4) - -virDomainPtr vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, - const char **name, int flag); - -/* default is lookup by Id, Name and UUID */ -# define vshCommandOptDomain(_ctl, _cmd, _name) \ - vshCommandOptDomainBy(_ctl, _cmd, _name, VSH_BYID|VSH_BYUUID|VSH_BYNAME) +bool vshCmdHasOption(vshControl *ctl, const vshCmd *cmd, const char *optname); void vshPrintExtra(vshControl *ctl, const char *format, ...) ATTRIBUTE_FMT_PRINTF(2, 3); @@ -309,6 +298,7 @@ void vshDebug(vshControl *ctl, int level, const char *format, ...) /* User visible sort, so we want locale-specific case comparison. */ # define vshStrcasecmp(S1, S2) strcasecmp(S1, S2) +int vshNameSorter(const void *a, const void *b); int vshDomainState(vshControl *ctl, virDomainPtr dom, int *reason); bool vshConnectionUsability(vshControl *ctl, virConnectPtr conn); -- 1.7.11.4

On 08/20/2012 04:54 PM, Eric Blake wrote:
In preparation for splitting virsh-interface.c, I found these functions need to be declared in virsh.h, as well as one that belongs more properly in virsh-domain.h.
* tools/virsh.h (vshNameSorter, vshCmdHasOption): Declare. (vshCommandOptDomainBy): Move... * tools/virsh-domain.h): ...here. * tools/virsh.c: (vshNameSorter): Export. (cmd_has_option): Rename... (vshCmdHasOption): ...and export. (vshCommandOptDomainBy): Move... * tools/virsh-domain.c (vshCommandOptDomainBy): ...here. * tools/virsh-network.c (vshCommandOptNetworkBy): Update callers. * tools/virsh-nwfilter.c (vshCommandOptNWFilterBy): Likewise. * tools/virsh-secret.c (vshCommandOptSecret): Likewise. * tools/virsh-domain-monitor.c (includes): Likewise. * tools/virsh-host.c (includes): Likewise. --- tools/virsh-domain-monitor.c | 1 + tools/virsh-domain.c | 48 +++++++++++++++++++++++++++++++++++++++ tools/virsh-domain.h | 12 ++++++++++ tools/virsh-host.c | 1 + tools/virsh-interface.c | 2 +- tools/virsh-network.c | 2 +- tools/virsh-nwfilter.c | 2 +- tools/virsh-secret.c | 2 +- tools/virsh.c | 54 +++----------------------------------------- tools/virsh.h | 14 ++---------- 10 files changed, 71 insertions(+), 67 deletions(-)
Code movement and one function renamed. ACK.

In preparation for splitting virsh-interface.c, I found these functions need to be declared in virsh.h, as well as one that belongs more properly in virsh-domain.h. Also, since we use the VSH_BY* flags in more than one function, I improved how they are used. * tools/virsh.h (vshNameSorter, vshCmdHasOption): Declare. (VSH_BYID): Turn into enum. (vshCommandOptDomainBy): Move... * tools/virsh-domain.h): ...here. * tools/virsh.c: (vshNameSorter): Export. (cmd_has_option): Rename... (vshCmdHasOption): ...and export. (vshCommandOptDomainBy): Move... * tools/virsh-domain.c (vshCommandOptDomainBy): ...here, adjust signature, and check flags. * tools/virsh-network.c (vshCommandOptNetworkBy): Update callers. * tools/virsh-nwfilter.c (vshCommandOptNWFilterBy): Likewise. * tools/virsh-secret.c (vshCommandOptSecret): Likewise. * tools/virsh-domain-monitor.c (includes): Likewise. * tools/virsh-host.c (includes): Likewise. --- v2: keep VSH_BYID in virsh.h after all, but convert to enum and add virCheckFlags sanity checking tools/virsh-domain-monitor.c | 1 + tools/virsh-domain.c | 51 +++++++++++++++++++++++++++++++++++++++++ tools/virsh-domain.h | 7 ++++++ tools/virsh-host.c | 1 + tools/virsh-interface.c | 2 +- tools/virsh-network.c | 2 +- tools/virsh-nwfilter.c | 2 +- tools/virsh-secret.c | 2 +- tools/virsh.c | 54 +++----------------------------------------- tools/virsh.h | 20 ++++++++-------- 10 files changed, 76 insertions(+), 66 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 4f00e65..44f65ad 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -36,6 +36,7 @@ #include "intprops.h" #include "memory.h" #include "virmacaddr.h" +#include "virsh-domain.h" #include "xml.h" static const char * diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e949dcf..6a87d49 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -58,6 +58,57 @@ # define SA_SIGINFO 0 #endif +virDomainPtr +vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, + const char **name, unsigned int flags) +{ + virDomainPtr dom = NULL; + const char *n = NULL; + int id; + const char *optname = "domain"; + virCheckFlags(VSH_BYID | VSH_BYUUID | VSH_BYNAME, NULL); + + if (!vshCmdHasOption(ctl, cmd, optname)) + return NULL; + + if (vshCommandOptString(cmd, optname, &n) <= 0) + return NULL; + + vshDebug(ctl, VSH_ERR_INFO, "%s: found option <%s>: %s\n", + cmd->def->name, optname, n); + + if (name) + *name = n; + + /* try it by ID */ + if (flags & VSH_BYID) { + if (virStrToLong_i(n, NULL, 10, &id) == 0 && id >= 0) { + vshDebug(ctl, VSH_ERR_DEBUG, + "%s: <%s> seems like domain ID\n", + cmd->def->name, optname); + dom = virDomainLookupByID(ctl->conn, id); + } + } + /* try it by UUID */ + if (!dom && (flags & VSH_BYUUID) && + strlen(n) == VIR_UUID_STRING_BUFLEN-1) { + vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as domain UUID\n", + cmd->def->name, optname); + dom = virDomainLookupByUUIDString(ctl->conn, n); + } + /* try it by NAME */ + if (!dom && (flags & VSH_BYNAME)) { + vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as domain NAME\n", + cmd->def->name, optname); + dom = virDomainLookupByName(ctl->conn, n); + } + + if (!dom) + vshError(ctl, _("failed to get domain '%s'"), n); + + return dom; +} + static const char * vshDomainVcpuStateToString(int state) { diff --git a/tools/virsh-domain.h b/tools/virsh-domain.h index b1b7930..cd51b57 100644 --- a/tools/virsh-domain.h +++ b/tools/virsh-domain.h @@ -28,6 +28,13 @@ # include "virsh.h" +virDomainPtr vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, + const char **name, unsigned int flags); + +/* default is lookup by Id, Name and UUID */ +# define vshCommandOptDomain(_ctl, _cmd, _name) \ + vshCommandOptDomainBy(_ctl, _cmd, _name, VSH_BYID|VSH_BYUUID|VSH_BYNAME) + extern const vshCmdDef domManagementCmds[]; #endif /* VIRSH_DOMAIN_H */ diff --git a/tools/virsh-host.c b/tools/virsh-host.c index e3cff8e..3c44969 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -35,6 +35,7 @@ #include "buf.h" #include "memory.h" #include "util.h" +#include "virsh-domain.h" #include "xml.h" /* diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index ad080a1..e43aa91 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -38,7 +38,7 @@ vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd, if (!optname) optname = "interface"; - if (!cmd_has_option(ctl, cmd, optname)) + if (!vshCmdHasOption(ctl, cmd, optname)) return NULL; if (vshCommandOptString(cmd, optname, &n) <= 0) diff --git a/tools/virsh-network.c b/tools/virsh-network.c index b33e2d6..b891c91 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -35,7 +35,7 @@ vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, virNetworkPtr network = NULL; const char *n = NULL; const char *optname = "network"; - if (!cmd_has_option(ctl, cmd, optname)) + if (!vshCmdHasOption(ctl, cmd, optname)) return NULL; if (vshCommandOptString(cmd, optname, &n) <= 0) diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index 501e20d..a6ef233 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -35,7 +35,7 @@ vshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd, virNWFilterPtr nwfilter = NULL; const char *n = NULL; const char *optname = "nwfilter"; - if (!cmd_has_option(ctl, cmd, optname)) + if (!vshCmdHasOption(ctl, cmd, optname)) return NULL; if (vshCommandOptString(cmd, optname, &n) <= 0) diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 049ead5..6f971da 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -30,7 +30,7 @@ vshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name) const char *n = NULL; const char *optname = "secret"; - if (!cmd_has_option(ctl, cmd, optname)) + if (!vshCmdHasOption(ctl, cmd, optname)) return NULL; if (vshCommandOptString(cmd, optname, &n) <= 0) diff --git a/tools/virsh.c b/tools/virsh.c index 793a357..fe79b7c 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -128,7 +128,7 @@ _vshStrdup(vshControl *ctl, const char *s, const char *filename, int line) /* Poison the raw allocating identifiers in favor of our vsh variants. */ #define strdup use_vshStrdup_instead_of_strdup -static int +int vshNameSorter(const void *a, const void *b) { const char **sa = (const char**)a; @@ -1441,8 +1441,8 @@ vshCommandOptArgv(const vshCmd *cmd, const vshCmdOpt *opt) /* Determine whether CMD->opts includes an option with name OPTNAME. If not, give a diagnostic and return false. If so, return true. */ -static bool -cmd_has_option(vshControl *ctl, const vshCmd *cmd, const char *optname) +bool +vshCmdHasOption(vshControl *ctl, const vshCmd *cmd, const char *optname) { /* Iterate through cmd->opts, to ensure that there is an entry with name OPTNAME and type VSH_OT_DATA. */ @@ -1461,54 +1461,6 @@ cmd_has_option(vshControl *ctl, const vshCmd *cmd, const char *optname) return found; } -virDomainPtr -vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, - const char **name, int flag) -{ - virDomainPtr dom = NULL; - const char *n = NULL; - int id; - const char *optname = "domain"; - if (!cmd_has_option(ctl, cmd, optname)) - return NULL; - - if (vshCommandOptString(cmd, optname, &n) <= 0) - return NULL; - - vshDebug(ctl, VSH_ERR_INFO, "%s: found option <%s>: %s\n", - cmd->def->name, optname, n); - - if (name) - *name = n; - - /* try it by ID */ - if (flag & VSH_BYID) { - if (virStrToLong_i(n, NULL, 10, &id) == 0 && id >= 0) { - vshDebug(ctl, VSH_ERR_DEBUG, - "%s: <%s> seems like domain ID\n", - cmd->def->name, optname); - dom = virDomainLookupByID(ctl->conn, id); - } - } - /* try it by UUID */ - if (dom==NULL && (flag & VSH_BYUUID) && strlen(n)==VIR_UUID_STRING_BUFLEN-1) { - vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as domain UUID\n", - cmd->def->name, optname); - dom = virDomainLookupByUUIDString(ctl->conn, n); - } - /* try it by NAME */ - if (dom==NULL && (flag & VSH_BYNAME)) { - vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as domain NAME\n", - cmd->def->name, optname); - dom = virDomainLookupByName(ctl->conn, n); - } - - if (!dom) - vshError(ctl, _("failed to get domain '%s'"), n); - - return dom; -} - /* * Executes command(s) and returns return code from last command */ diff --git a/tools/virsh.h b/tools/virsh.h index 24d2020..818d515 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -286,18 +286,15 @@ int vshCommandOptScaledInt(const vshCmd *cmd, const char *name, bool vshCommandOptBool(const vshCmd *cmd, const char *name); const vshCmdOpt *vshCommandOptArgv(const vshCmd *cmd, const vshCmdOpt *opt); +bool vshCmdHasOption(vshControl *ctl, const vshCmd *cmd, const char *optname); -# define VSH_BYID (1 << 1) -# define VSH_BYUUID (1 << 2) -# define VSH_BYNAME (1 << 3) -# define VSH_BYMAC (1 << 4) - -virDomainPtr vshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd, - const char **name, int flag); - -/* default is lookup by Id, Name and UUID */ -# define vshCommandOptDomain(_ctl, _cmd, _name) \ - vshCommandOptDomainBy(_ctl, _cmd, _name, VSH_BYID|VSH_BYUUID|VSH_BYNAME) +/* Filter flags for various vshCommandOpt*By() functions */ +typedef enum { + VSH_BYID = (1 << 1), + VSH_BYUUID = (1 << 2), + VSH_BYNAME = (1 << 3), + VSH_BYMAC = (1 << 4), +} vshLookupByFlags; void vshPrintExtra(vshControl *ctl, const char *format, ...) ATTRIBUTE_FMT_PRINTF(2, 3); @@ -309,6 +306,7 @@ void vshDebug(vshControl *ctl, int level, const char *format, ...) /* User visible sort, so we want locale-specific case comparison. */ # define vshStrcasecmp(S1, S2) strcasecmp(S1, S2) +int vshNameSorter(const void *a, const void *b); int vshDomainState(vshControl *ctl, virDomainPtr dom, int *reason); bool vshConnectionUsability(vshControl *ctl, virConnectPtr conn); -- 1.7.11.4

On 08/20/2012 05:30 PM, Eric Blake wrote:
In preparation for splitting virsh-interface.c, I found these functions need to be declared in virsh.h, as well as one that belongs more properly in virsh-domain.h. Also, since we use the VSH_BY* flags in more than one function, I improved how they are used.
* tools/virsh.h (vshNameSorter, vshCmdHasOption): Declare. (VSH_BYID): Turn into enum. (vshCommandOptDomainBy): Move... * tools/virsh-domain.h): ...here. * tools/virsh.c: (vshNameSorter): Export. (cmd_has_option): Rename... (vshCmdHasOption): ...and export. (vshCommandOptDomainBy): Move... * tools/virsh-domain.c (vshCommandOptDomainBy): ...here, adjust signature, and check flags. * tools/virsh-network.c (vshCommandOptNetworkBy): Update callers. * tools/virsh-nwfilter.c (vshCommandOptNWFilterBy): Likewise. * tools/virsh-secret.c (vshCommandOptSecret): Likewise. * tools/virsh-domain-monitor.c (includes): Likewise. * tools/virsh-host.c (includes): Likewise. ---
v2: keep VSH_BYID in virsh.h after all, but convert to enum and add virCheckFlags sanity checking
Okay, sure. ACK to this version instead.

Another relatively easy split, since helper functions were fixed in the previous patch. * tools/virsh-interface.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-interface.c: Likewise. (vshCommandOptInterfaceBy): Check flags. --- tools/Makefile.am | 2 +- tools/virsh-interface.c | 28 +++++++++++++++++++--------- tools/virsh-interface.h | 42 ++++++++++++++++++++++++++++++++++++++++++ tools/virsh.c | 2 +- 4 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 tools/virsh-interface.h diff --git a/tools/Makefile.am b/tools/Makefile.am index a3e5ff4..4d46a98 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -109,8 +109,8 @@ virsh_SOURCES = \ 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 \ $(NULL) -# virsh-interface.c virsh-interface.h \ # virsh-network.c virsh-network.h \ # virsh-nodedev.c virsh-nodedev.h \ # virsh-nwfilter.c virsh-nwfilter.h \ diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index e43aa91..da02168 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -23,18 +23,28 @@ * */ -/* default is lookup by Name and MAC */ -#define vshCommandOptInterface(_ctl, _cmd, _name) \ - vshCommandOptInterfaceBy(_ctl, _cmd, NULL, _name, \ - VSH_BYMAC|VSH_BYNAME) +#include <config.h> +#include "virsh-interface.h" -static virInterfacePtr +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> + +#include "internal.h" +#include "buf.h" +#include "memory.h" +#include "util.h" +#include "xml.h" + +virInterfacePtr vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd, const char *optname, - const char **name, int flag) + const char **name, unsigned int flags) { virInterfacePtr iface = NULL; const char *n = NULL; + virCheckFlags(VSH_BYNAME | VSH_BYMAC, NULL); if (!optname) optname = "interface"; @@ -51,13 +61,13 @@ vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd, *name = n; /* try it by NAME */ - if (flag & VSH_BYNAME) { + if (flags & VSH_BYNAME) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface NAME\n", cmd->def->name, optname); iface = virInterfaceLookupByName(ctl->conn, n); } /* try it by MAC */ - if (iface == NULL && (flag & VSH_BYMAC)) { + if (!iface && (flags & VSH_BYMAC)) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface MAC\n", cmd->def->name, optname); iface = virInterfaceLookupByMACString(ctl->conn, n); @@ -999,7 +1009,7 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd) return ret; } -static const vshCmdDef ifaceCmds[] = { +const vshCmdDef ifaceCmds[] = { {"iface-begin", cmdInterfaceBegin, opts_interface_begin, info_interface_begin, 0}, {"iface-bridge", cmdInterfaceBridge, opts_interface_bridge, diff --git a/tools/virsh-interface.h b/tools/virsh-interface.h new file mode 100644 index 0000000..2292cef --- /dev/null +++ b/tools/virsh-interface.h @@ -0,0 +1,42 @@ +/* + * virsh-interface.c: Commands to manage host interface + * + * 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_INTERFACE_H +# define VIRSH_INTERFACE_H + +# include "virsh.h" + +virInterfacePtr vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd, + const char *optname, + const char **name, unsigned int flags); + +/* default is lookup by Name and MAC */ +# define vshCommandOptInterface(_ctl, _cmd, _name) \ + vshCommandOptInterfaceBy(_ctl, _cmd, NULL, _name, \ + VSH_BYMAC|VSH_BYNAME) + +extern const vshCmdDef ifaceCmds[]; + +#endif /* VIRSH_INTERFACE_H */ diff --git a/tools/virsh.c b/tools/virsh.c index fe79b7c..d7fd408 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -77,6 +77,7 @@ #include "virsh-domain.h" #include "virsh-domain-monitor.h" #include "virsh-host.h" +#include "virsh-interface.h" static char *progname; @@ -2815,7 +2816,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; } -#include "virsh-interface.c" #include "virsh-network.c" #include "virsh-nodedev.c" #include "virsh-nwfilter.c" -- 1.7.11.4

On 08/20/2012 05:37 PM, Eric Blake wrote:
Another relatively easy split, since helper functions were fixed in the previous patch.
* tools/virsh-interface.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-interface.c: Likewise. (vshCommandOptInterfaceBy): Check flags. --- tools/Makefile.am | 2 +- tools/virsh-interface.c | 28 +++++++++++++++++++--------- tools/virsh-interface.h | 42 ++++++++++++++++++++++++++++++++++++++++++ tools/virsh.c | 2 +- 4 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 tools/virsh-interface.h
No surprises there. ACK.

Another relatively easy file split. * tools/virsh-network.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-network.c: Likewise. --- tools/Makefile.am | 2 +- tools/virsh-network.c | 29 ++++++++++++++++++++--------- tools/virsh-network.h | 42 ++++++++++++++++++++++++++++++++++++++++++ tools/virsh.c | 2 +- 4 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 tools/virsh-network.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 4d46a98..595d64a 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -110,8 +110,8 @@ virsh_SOURCES = \ virsh-domain-monitor.c virsh-domain-monitor.h \ virsh-host.c virsh-host.h \ virsh-interface.c virsh-interface.h \ + virsh-network.c virsh-network.h \ $(NULL) -# virsh-network.c virsh-network.h \ # virsh-nodedev.c virsh-nodedev.h \ # virsh-nwfilter.c virsh-nwfilter.h \ # virsh-pool.c virsh-pool.h \ diff --git a/tools/virsh-network.c b/tools/virsh-network.c index b891c91..37fa3ba 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -23,18 +23,29 @@ * */ -/* default is lookup by Name and UUID */ -#define vshCommandOptNetwork(_ctl, _cmd, _name) \ - vshCommandOptNetworkBy(_ctl, _cmd, _name, \ - VSH_BYUUID|VSH_BYNAME) +#include <config.h> +#include "virsh-network.h" -static virNetworkPtr +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> + +#include "internal.h" +#include "buf.h" +#include "memory.h" +#include "util.h" +#include "xml.h" + +virNetworkPtr vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, - const char **name, int flag) + const char **name, unsigned int flags) { virNetworkPtr network = NULL; const char *n = NULL; const char *optname = "network"; + virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL); + if (!vshCmdHasOption(ctl, cmd, optname)) return NULL; @@ -48,13 +59,13 @@ vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, *name = n; /* try it by UUID */ - if ((flag & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) { + if ((flags & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as network UUID\n", cmd->def->name, optname); network = virNetworkLookupByUUIDString(ctl->conn, n); } /* try it by NAME */ - if (network==NULL && (flag & VSH_BYNAME)) { + if (!network && (flags & VSH_BYNAME)) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as network NAME\n", cmd->def->name, optname); network = virNetworkLookupByName(ctl->conn, n); @@ -686,7 +697,7 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd) return ret; } -static const vshCmdDef networkCmds[] = { +const vshCmdDef networkCmds[] = { {"net-autostart", cmdNetworkAutostart, opts_network_autostart, info_network_autostart, 0}, {"net-create", cmdNetworkCreate, opts_network_create, diff --git a/tools/virsh-network.h b/tools/virsh-network.h new file mode 100644 index 0000000..b5d151c --- /dev/null +++ b/tools/virsh-network.h @@ -0,0 +1,42 @@ +/* + * virsh-network.c: Commands to manage network + * + * 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_NETWORK_H +# define VIRSH_NETWORK_H + +# include "virsh.h" + +virNetworkPtr +vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd, + const char **name, unsigned int flags); + +/* default is lookup by Name and UUID */ +# define vshCommandOptNetwork(_ctl, _cmd, _name) \ + vshCommandOptNetworkBy(_ctl, _cmd, _name, \ + VSH_BYUUID|VSH_BYNAME) + +extern const vshCmdDef networkCmds[]; + +#endif /* VIRSH_NETWORK_H */ diff --git a/tools/virsh.c b/tools/virsh.c index d7fd408..2a9c673 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -78,6 +78,7 @@ #include "virsh-domain-monitor.h" #include "virsh-host.h" #include "virsh-interface.h" +#include "virsh-network.h" static char *progname; @@ -2816,7 +2817,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; } -#include "virsh-network.c" #include "virsh-nodedev.c" #include "virsh-nwfilter.c" #include "virsh-pool.c" -- 1.7.11.4

On 08/20/2012 05:47 PM, Eric Blake wrote:
Another relatively easy file split.
* tools/virsh-network.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-network.c: Likewise. --- tools/Makefile.am | 2 +- tools/virsh-network.c | 29 ++++++++++++++++++++--------- tools/virsh-network.h | 42 ++++++++++++++++++++++++++++++++++++++++++ tools/virsh.c | 2 +- 4 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 tools/virsh-network.h
These are getting very predictable. That's a good sign! ACK.

Another worthwhile split, needed one more public function. * tools/virsh-nodedev.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh-nodedev.c: Use new header. * tools/virsh.c: Likewise. (vshTreePrint): Export. * tools/virsh.h (vshTreePrint): Declare. --- tools/Makefile.am | 2 +- tools/virsh-nodedev.c | 16 +++++++++++++++- tools/virsh-nodedev.h | 33 +++++++++++++++++++++++++++++++++ tools/virsh.c | 8 ++------ tools/virsh.h | 6 ++++++ 5 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 tools/virsh-nodedev.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 595d64a..0b3e080 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -111,8 +111,8 @@ virsh_SOURCES = \ virsh-host.c virsh-host.h \ virsh-interface.c virsh-interface.h \ virsh-network.c virsh-network.h \ + virsh-nodedev.c virsh-nodedev.h \ $(NULL) -# virsh-nodedev.c virsh-nodedev.h \ # virsh-nwfilter.c virsh-nwfilter.h \ # virsh-pool.c virsh-pool.h \ # virsh-secret.c virsh-secret.h \ diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 1398fbd..bcdc3d8 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -23,6 +23,20 @@ * */ +#include <config.h> +#include "virsh-nodedev.h" + +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> + +#include "internal.h" +#include "buf.h" +#include "memory.h" +#include "util.h" +#include "xml.h" + /* * "nodedev-create" command */ @@ -381,7 +395,7 @@ cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd) return ret; } -static const vshCmdDef nodedevCmds[] = { +const vshCmdDef nodedevCmds[] = { {"nodedev-create", cmdNodeDeviceCreate, opts_node_device_create, info_node_device_create, 0}, {"nodedev-destroy", cmdNodeDeviceDestroy, opts_node_device_destroy, diff --git a/tools/virsh-nodedev.h b/tools/virsh-nodedev.h new file mode 100644 index 0000000..fa3cf4f --- /dev/null +++ b/tools/virsh-nodedev.h @@ -0,0 +1,33 @@ +/* + * virsh-nodedev.h: Commands in node device group + * + * 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_NODEDEV_H +# define VIRSH_NODEDEV_H + +# include "virsh.h" + +extern const vshCmdDef nodedevCmds[]; + +#endif /* VIRSH_NODEDEV_H */ diff --git a/tools/virsh.c b/tools/virsh.c index 2a9c673..364ca25 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -79,6 +79,7 @@ #include "virsh-host.h" #include "virsh-interface.h" #include "virsh-network.h" +#include "virsh-nodedev.h" static char *progname; @@ -416,10 +417,6 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd) /* Tree listing helpers. */ -/* Given an index, return either the name of that device (non-NULL) or - * of its parent (NULL if a root). */ -typedef const char * (*vshTreeLookup)(int devid, bool parent, void *opaque); - static int vshTreePrintInternal(vshControl *ctl, vshTreeLookup lookup, @@ -487,7 +484,7 @@ cleanup: return ret; } -static int +int vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque, int num_devices, int devid) { @@ -2817,7 +2814,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; } -#include "virsh-nodedev.c" #include "virsh-nwfilter.c" #include "virsh-pool.c" #include "virsh-secret.c" diff --git a/tools/virsh.h b/tools/virsh.h index 818d515..698899d 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -296,6 +296,12 @@ typedef enum { VSH_BYMAC = (1 << 4), } vshLookupByFlags; +/* Given an index, return either the name of that device (non-NULL) or + * of its parent (NULL if a root). */ +typedef const char * (*vshTreeLookup)(int devid, bool parent, void *opaque); +int vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque, + int num_devices, int devid); + void vshPrintExtra(vshControl *ctl, const char *format, ...) ATTRIBUTE_FMT_PRINTF(2, 3); void vshDebug(vshControl *ctl, int level, const char *format, ...) -- 1.7.11.4

On 08/20/2012 06:28 PM, Eric Blake wrote:
Another worthwhile split, needed one more public function.
* tools/virsh-nodedev.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh-nodedev.c: Use new header. * tools/virsh.c: Likewise. (vshTreePrint): Export. * tools/virsh.h (vshTreePrint): Declare. --- tools/Makefile.am | 2 +- tools/virsh-nodedev.c | 16 +++++++++++++++- tools/virsh-nodedev.h | 33 +++++++++++++++++++++++++++++++++ tools/virsh.c | 8 ++------ tools/virsh.h | 6 ++++++ 5 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 tools/virsh-nodedev.h
diff --git a/tools/Makefile.am b/tools/Makefile.am index 595d64a..0b3e080 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -111,8 +111,8 @@ virsh_SOURCES = \ virsh-host.c virsh-host.h \ virsh-interface.c virsh-interface.h \ virsh-network.c virsh-network.h \ + virsh-nodedev.c virsh-nodedev.h \ $(NULL) -# virsh-nodedev.c virsh-nodedev.h \ # virsh-nwfilter.c virsh-nwfilter.h \ # virsh-pool.c virsh-pool.h \ # virsh-secret.c virsh-secret.h \ diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 1398fbd..bcdc3d8 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -23,6 +23,20 @@ * */
+#include <config.h> +#include "virsh-nodedev.h" + +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> + +#include "internal.h" +#include "buf.h" +#include "memory.h" +#include "util.h" +#include "xml.h" + /* * "nodedev-create" command */ @@ -381,7 +395,7 @@ cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd) return ret; }
-static const vshCmdDef nodedevCmds[] = { +const vshCmdDef nodedevCmds[] = { {"nodedev-create", cmdNodeDeviceCreate, opts_node_device_create, info_node_device_create, 0}, {"nodedev-destroy", cmdNodeDeviceDestroy, opts_node_device_destroy, diff --git a/tools/virsh-nodedev.h b/tools/virsh-nodedev.h new file mode 100644 index 0000000..fa3cf4f --- /dev/null +++ b/tools/virsh-nodedev.h @@ -0,0 +1,33 @@ +/* + * virsh-nodedev.h: Commands in node device group + * + * 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_NODEDEV_H +# define VIRSH_NODEDEV_H + +# include "virsh.h" + +extern const vshCmdDef nodedevCmds[]; + +#endif /* VIRSH_NODEDEV_H */ diff --git a/tools/virsh.c b/tools/virsh.c index 2a9c673..364ca25 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -79,6 +79,7 @@ #include "virsh-host.h" #include "virsh-interface.h" #include "virsh-network.h" +#include "virsh-nodedev.h"
static char *progname;
@@ -416,10 +417,6 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd)
/* Tree listing helpers. */
-/* Given an index, return either the name of that device (non-NULL) or - * of its parent (NULL if a root). */ -typedef const char * (*vshTreeLookup)(int devid, bool parent, void *opaque); - static int vshTreePrintInternal(vshControl *ctl, vshTreeLookup lookup, @@ -487,7 +484,7 @@ cleanup: return ret; }
-static int +int vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque, int num_devices, int devid)
Okay. Public, but already in virsh.c, not something that needed to be moved from one of the split files. ACK.
{ @@ -2817,7 +2814,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; }
-#include "virsh-nodedev.c" #include "virsh-nwfilter.c" #include "virsh-pool.c" #include "virsh-secret.c" diff --git a/tools/virsh.h b/tools/virsh.h index 818d515..698899d 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -296,6 +296,12 @@ typedef enum { VSH_BYMAC = (1 << 4), } vshLookupByFlags;
+/* Given an index, return either the name of that device (non-NULL) or + * of its parent (NULL if a root). */ +typedef const char * (*vshTreeLookup)(int devid, bool parent, void *opaque); +int vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque, + int num_devices, int devid); + void vshPrintExtra(vshControl *ctl, const char *format, ...) ATTRIBUTE_FMT_PRINTF(2, 3); void vshDebug(vshControl *ctl, int level, const char *format, ...)

Another worthwhile split, needed one more public function. * tools/virsh-nodedev.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh-nodedev.c: Use new header. * tools/virsh.c: Likewise. (vshTreePrint): Export. * tools/virsh.h (vshTreePrint): Declare. --- tools/Makefile.am | 2 +- tools/virsh-nodedev.c | 16 +++++++++++++++- tools/virsh-nodedev.h | 33 +++++++++++++++++++++++++++++++++ tools/virsh.c | 8 ++------ tools/virsh.h | 6 ++++++ 5 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 tools/virsh-nodedev.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 595d64a..0b3e080 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -111,8 +111,8 @@ virsh_SOURCES = \ virsh-host.c virsh-host.h \ virsh-interface.c virsh-interface.h \ virsh-network.c virsh-network.h \ + virsh-nodedev.c virsh-nodedev.h \ $(NULL) -# virsh-nodedev.c virsh-nodedev.h \ # virsh-nwfilter.c virsh-nwfilter.h \ # virsh-pool.c virsh-pool.h \ # virsh-secret.c virsh-secret.h \ diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 1398fbd..bcdc3d8 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -23,6 +23,20 @@ * */ +#include <config.h> +#include "virsh-nodedev.h" + +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> + +#include "internal.h" +#include "buf.h" +#include "memory.h" +#include "util.h" +#include "xml.h" + /* * "nodedev-create" command */ @@ -381,7 +395,7 @@ cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd) return ret; } -static const vshCmdDef nodedevCmds[] = { +const vshCmdDef nodedevCmds[] = { {"nodedev-create", cmdNodeDeviceCreate, opts_node_device_create, info_node_device_create, 0}, {"nodedev-destroy", cmdNodeDeviceDestroy, opts_node_device_destroy, diff --git a/tools/virsh-nodedev.h b/tools/virsh-nodedev.h new file mode 100644 index 0000000..fa3cf4f --- /dev/null +++ b/tools/virsh-nodedev.h @@ -0,0 +1,33 @@ +/* + * virsh-nodedev.h: Commands in node device group + * + * 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_NODEDEV_H +# define VIRSH_NODEDEV_H + +# include "virsh.h" + +extern const vshCmdDef nodedevCmds[]; + +#endif /* VIRSH_NODEDEV_H */ diff --git a/tools/virsh.c b/tools/virsh.c index 2a9c673..364ca25 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -79,6 +79,7 @@ #include "virsh-host.h" #include "virsh-interface.h" #include "virsh-network.h" +#include "virsh-nodedev.h" static char *progname; @@ -416,10 +417,6 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd) /* Tree listing helpers. */ -/* Given an index, return either the name of that device (non-NULL) or - * of its parent (NULL if a root). */ -typedef const char * (*vshTreeLookup)(int devid, bool parent, void *opaque); - static int vshTreePrintInternal(vshControl *ctl, vshTreeLookup lookup, @@ -487,7 +484,7 @@ cleanup: return ret; } -static int +int vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque, int num_devices, int devid) { @@ -2817,7 +2814,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; } -#include "virsh-nodedev.c" #include "virsh-nwfilter.c" #include "virsh-pool.c" #include "virsh-secret.c" diff --git a/tools/virsh.h b/tools/virsh.h index 818d515..698899d 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -296,6 +296,12 @@ typedef enum { VSH_BYMAC = (1 << 4), } vshLookupByFlags; +/* Given an index, return either the name of that device (non-NULL) or + * of its parent (NULL if a root). */ +typedef const char * (*vshTreeLookup)(int devid, bool parent, void *opaque); +int vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque, + int num_devices, int devid); + void vshPrintExtra(vshControl *ctl, const char *format, ...) ATTRIBUTE_FMT_PRINTF(2, 3); void vshDebug(vshControl *ctl, int level, const char *format, ...) -- 1.7.11.4

On 08/20/2012 06:40 PM, Eric Blake wrote:
Another worthwhile split, needed one more public function.
* tools/virsh-nodedev.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh-nodedev.c: Use new header. * tools/virsh.c: Likewise. (vshTreePrint): Export. * tools/virsh.h (vshTreePrint): Declare. --- tools/Makefile.am | 2 +- tools/virsh-nodedev.c | 16 +++++++++++++++- tools/virsh-nodedev.h | 33 +++++++++++++++++++++++++++++++++ tools/virsh.c | 8 ++------ tools/virsh.h | 6 ++++++ 5 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 tools/virsh-nodedev.h
This is a duplicate of PATCH 13/4

Yet another split file. * tools/virsh-network.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-nwfilter.c: Likewise. --- tools/Makefile.am | 2 +- tools/virsh-nwfilter.c | 31 +++++++++++++++++++++---------- tools/virsh-nwfilter.h | 42 ++++++++++++++++++++++++++++++++++++++++++ tools/virsh.c | 2 +- 4 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 tools/virsh-nwfilter.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 0b3e080..1a6b97b 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -112,8 +112,8 @@ virsh_SOURCES = \ virsh-interface.c virsh-interface.h \ virsh-network.c virsh-network.h \ virsh-nodedev.c virsh-nodedev.h \ + virsh-nwfilter.c virsh-nwfilter.h \ $(NULL) -# virsh-nwfilter.c virsh-nwfilter.h \ # virsh-pool.c virsh-pool.h \ # virsh-secret.c virsh-secret.h \ # virsh-snapshot.c virsh-snapshot.h \ diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index a6ef233..5e8f540 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -1,5 +1,5 @@ /* - * virsh-domain.c: Commands to manage network filters + * virsh-nwfilter.c: Commands to manage network filters * * Copyright (C) 2005, 2007-2012 Red Hat, Inc. * @@ -23,18 +23,29 @@ * */ -/* default is lookup by Name and UUID */ -#define vshCommandOptNWFilter(_ctl, _cmd, _name) \ - vshCommandOptNWFilterBy(_ctl, _cmd, _name, \ - VSH_BYUUID|VSH_BYNAME) +#include <config.h> +#include "virsh-nwfilter.h" -static virNWFilterPtr +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> + +#include "internal.h" +#include "buf.h" +#include "memory.h" +#include "util.h" +#include "xml.h" + +virNWFilterPtr vshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd, - const char **name, int flag) + const char **name, unsigned int flags) { virNWFilterPtr nwfilter = NULL; const char *n = NULL; const char *optname = "nwfilter"; + virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL); + if (!vshCmdHasOption(ctl, cmd, optname)) return NULL; @@ -48,13 +59,13 @@ vshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd, *name = n; /* try it by UUID */ - if ((flag & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) { + if ((flags & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as nwfilter UUID\n", cmd->def->name, optname); nwfilter = virNWFilterLookupByUUIDString(ctl->conn, n); } /* try it by NAME */ - if (nwfilter == NULL && (flag & VSH_BYNAME)) { + if (!nwfilter && (flags & VSH_BYNAME)) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as nwfilter NAME\n", cmd->def->name, optname); nwfilter = virNWFilterLookupByName(ctl->conn, n); @@ -309,7 +320,7 @@ cleanup: return ret; } -static const vshCmdDef nwfilterCmds[] = { +const vshCmdDef nwfilterCmds[] = { {"nwfilter-define", cmdNWFilterDefine, opts_nwfilter_define, info_nwfilter_define, 0}, {"nwfilter-dumpxml", cmdNWFilterDumpXML, opts_nwfilter_dumpxml, diff --git a/tools/virsh-nwfilter.h b/tools/virsh-nwfilter.h new file mode 100644 index 0000000..74b4bcc --- /dev/null +++ b/tools/virsh-nwfilter.h @@ -0,0 +1,42 @@ +/* + * virsh-nwfilter.h: Commands to manage network filters + * + * 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_NWFILTER_H +# define VIRSH_NWFILTER_H + +# include "virsh.h" + +virNWFilterPtr +vshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd, + const char **name, unsigned int flags); + +/* default is lookup by Name and UUID */ +#define vshCommandOptNWFilter(_ctl, _cmd, _name) \ + vshCommandOptNWFilterBy(_ctl, _cmd, _name, \ + VSH_BYUUID|VSH_BYNAME) + +extern const vshCmdDef nwfilterCmds[]; + +#endif /* VIRSH_NWFILTER_H */ diff --git a/tools/virsh.c b/tools/virsh.c index 364ca25..ab88fcb 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -80,6 +80,7 @@ #include "virsh-interface.h" #include "virsh-network.h" #include "virsh-nodedev.h" +#include "virsh-nwfilter.h" static char *progname; @@ -2814,7 +2815,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; } -#include "virsh-nwfilter.c" #include "virsh-pool.c" #include "virsh-secret.c" #include "virsh-snapshot.c" -- 1.7.11.4

On 08/20/2012 06:56 PM, Eric Blake wrote:
Yet another split file.
* tools/virsh-network.h: New file.
Comment is incorrect - virsh-nwfilter.h ACK.
* tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-nwfilter.c: Likewise. --- tools/Makefile.am | 2 +- tools/virsh-nwfilter.c | 31 +++++++++++++++++++++---------- tools/virsh-nwfilter.h | 42 ++++++++++++++++++++++++++++++++++++++++++ tools/virsh.c | 2 +- 4 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 tools/virsh-nwfilter.h
diff --git a/tools/Makefile.am b/tools/Makefile.am index 0b3e080..1a6b97b 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -112,8 +112,8 @@ virsh_SOURCES = \ virsh-interface.c virsh-interface.h \ virsh-network.c virsh-network.h \ virsh-nodedev.c virsh-nodedev.h \ + virsh-nwfilter.c virsh-nwfilter.h \ $(NULL) -# virsh-nwfilter.c virsh-nwfilter.h \ # virsh-pool.c virsh-pool.h \ # virsh-secret.c virsh-secret.h \ # virsh-snapshot.c virsh-snapshot.h \ diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index a6ef233..5e8f540 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -1,5 +1,5 @@ /* - * virsh-domain.c: Commands to manage network filters + * virsh-nwfilter.c: Commands to manage network filters * * Copyright (C) 2005, 2007-2012 Red Hat, Inc. * @@ -23,18 +23,29 @@ * */
-/* default is lookup by Name and UUID */ -#define vshCommandOptNWFilter(_ctl, _cmd, _name) \ - vshCommandOptNWFilterBy(_ctl, _cmd, _name, \ - VSH_BYUUID|VSH_BYNAME) +#include <config.h> +#include "virsh-nwfilter.h"
-static virNWFilterPtr +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> + +#include "internal.h" +#include "buf.h" +#include "memory.h" +#include "util.h" +#include "xml.h" + +virNWFilterPtr vshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd, - const char **name, int flag) + const char **name, unsigned int flags) { virNWFilterPtr nwfilter = NULL; const char *n = NULL; const char *optname = "nwfilter"; + virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL); + if (!vshCmdHasOption(ctl, cmd, optname)) return NULL;
@@ -48,13 +59,13 @@ vshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd, *name = n;
/* try it by UUID */ - if ((flag & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) { + if ((flags & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as nwfilter UUID\n", cmd->def->name, optname); nwfilter = virNWFilterLookupByUUIDString(ctl->conn, n); } /* try it by NAME */ - if (nwfilter == NULL && (flag & VSH_BYNAME)) { + if (!nwfilter && (flags & VSH_BYNAME)) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as nwfilter NAME\n", cmd->def->name, optname); nwfilter = virNWFilterLookupByName(ctl->conn, n); @@ -309,7 +320,7 @@ cleanup: return ret; }
-static const vshCmdDef nwfilterCmds[] = { +const vshCmdDef nwfilterCmds[] = { {"nwfilter-define", cmdNWFilterDefine, opts_nwfilter_define, info_nwfilter_define, 0}, {"nwfilter-dumpxml", cmdNWFilterDumpXML, opts_nwfilter_dumpxml, diff --git a/tools/virsh-nwfilter.h b/tools/virsh-nwfilter.h new file mode 100644 index 0000000..74b4bcc --- /dev/null +++ b/tools/virsh-nwfilter.h @@ -0,0 +1,42 @@ +/* + * virsh-nwfilter.h: Commands to manage network filters + * + * 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_NWFILTER_H +# define VIRSH_NWFILTER_H + +# include "virsh.h" + +virNWFilterPtr +vshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd, + const char **name, unsigned int flags); + +/* default is lookup by Name and UUID */ +#define vshCommandOptNWFilter(_ctl, _cmd, _name) \ + vshCommandOptNWFilterBy(_ctl, _cmd, _name, \ + VSH_BYUUID|VSH_BYNAME) + +extern const vshCmdDef nwfilterCmds[]; + +#endif /* VIRSH_NWFILTER_H */ diff --git a/tools/virsh.c b/tools/virsh.c index 364ca25..ab88fcb 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -80,6 +80,7 @@ #include "virsh-interface.h" #include "virsh-network.h" #include "virsh-nodedev.h" +#include "virsh-nwfilter.h"
static char *progname;
@@ -2814,7 +2815,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; }
-#include "virsh-nwfilter.c" #include "virsh-pool.c" #include "virsh-secret.c" #include "virsh-snapshot.c"

More in a series of file splits. * tools/virsh-pool.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-pool.c: Likewise. --- tools/Makefile.am | 2 +- tools/virsh-pool.c | 28 +++++++++++++++++++--------- tools/virsh-pool.h | 42 ++++++++++++++++++++++++++++++++++++++++++ tools/virsh.c | 2 +- 4 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 tools/virsh-pool.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 1a6b97b..5f4e529 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -113,8 +113,8 @@ virsh_SOURCES = \ virsh-network.c virsh-network.h \ virsh-nodedev.c virsh-nodedev.h \ virsh-nwfilter.c virsh-nwfilter.h \ + virsh-pool.c virsh-pool.h \ $(NULL) -# virsh-pool.c virsh-pool.h \ # virsh-secret.c virsh-secret.h \ # virsh-snapshot.c virsh-snapshot.h \ # virsh-volume.c virsh-volume.h \ diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index e015547..d9cba4e 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -23,17 +23,27 @@ * */ -/* default is lookup by Name and UUID */ -#define vshCommandOptPool(_ctl, _cmd, _optname, _name) \ - vshCommandOptPoolBy(_ctl, _cmd, _optname, _name, \ - VSH_BYUUID|VSH_BYNAME) +#include <config.h> +#include "virsh-pool.h" -static virStoragePoolPtr +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> + +#include "internal.h" +#include "buf.h" +#include "memory.h" +#include "util.h" +#include "xml.h" + +virStoragePoolPtr vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname, - const char **name, int flag) + const char **name, unsigned int flags) { virStoragePoolPtr pool = NULL; const char *n = NULL; + virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL); if (vshCommandOptString(cmd, optname, &n) <= 0) return NULL; @@ -45,13 +55,13 @@ vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname, *name = n; /* try it by UUID */ - if ((flag & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) { + if ((flags & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as pool UUID\n", cmd->def->name, optname); pool = virStoragePoolLookupByUUIDString(ctl->conn, n); } /* try it by NAME */ - if (pool == NULL && (flag & VSH_BYNAME)) { + if (!pool && (flags & VSH_BYNAME)) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as pool NAME\n", cmd->def->name, optname); pool = virStoragePoolLookupByName(ctl->conn, n); @@ -1414,7 +1424,7 @@ cmdPoolEdit(vshControl *ctl, const vshCmd *cmd) return ret; } -static const vshCmdDef storagePoolCmds[] = { +const vshCmdDef storagePoolCmds[] = { {"find-storage-pool-sources-as", cmdPoolDiscoverSourcesAs, opts_find_storage_pool_sources_as, info_find_storage_pool_sources_as, 0}, {"find-storage-pool-sources", cmdPoolDiscoverSources, diff --git a/tools/virsh-pool.h b/tools/virsh-pool.h new file mode 100644 index 0000000..30ecb55 --- /dev/null +++ b/tools/virsh-pool.h @@ -0,0 +1,42 @@ +/* + * virsh-pool.h: Commands to manage storage pool + * + * 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_POOL_H +# define VIRSH_POOL_H + +# include "virsh.h" + +virStoragePoolPtr +vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname, + const char **name, unsigned int flags); + +/* default is lookup by Name and UUID */ +#define vshCommandOptPool(_ctl, _cmd, _optname, _name) \ + vshCommandOptPoolBy(_ctl, _cmd, _optname, _name, \ + VSH_BYUUID|VSH_BYNAME) + +extern const vshCmdDef storagePoolCmds[]; + +#endif /* VIRSH_POOL_H */ diff --git a/tools/virsh.c b/tools/virsh.c index ab88fcb..96b31f0 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -81,6 +81,7 @@ #include "virsh-network.h" #include "virsh-nodedev.h" #include "virsh-nwfilter.h" +#include "virsh-pool.h" static char *progname; @@ -2815,7 +2816,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; } -#include "virsh-pool.c" #include "virsh-secret.c" #include "virsh-snapshot.c" #include "virsh-volume.c" -- 1.7.11.4

One of the simpler splits. * tools/virsh-secret.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-secret.c: Likewise. --- tools/Makefile.am | 2 +- tools/virsh-secret.c | 17 ++++++++++++++++- tools/virsh-secret.h | 33 +++++++++++++++++++++++++++++++++ tools/virsh.c | 2 +- 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 tools/virsh-secret.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 5f4e529..a735022 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -114,8 +114,8 @@ virsh_SOURCES = \ virsh-nodedev.c virsh-nodedev.h \ virsh-nwfilter.c virsh-nwfilter.h \ virsh-pool.c virsh-pool.h \ + virsh-secret.c virsh-secret.h \ $(NULL) -# virsh-secret.c virsh-secret.h \ # virsh-snapshot.c virsh-snapshot.h \ # virsh-volume.c virsh-volume.h \ # diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c index 6f971da..7247eee 100644 --- a/tools/virsh-secret.c +++ b/tools/virsh-secret.c @@ -23,6 +23,21 @@ * */ +#include <config.h> +#include "virsh-secret.h" + +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> + +#include "internal.h" +#include "base64.h" +#include "buf.h" +#include "memory.h" +#include "util.h" +#include "xml.h" + static virSecretPtr vshCommandOptSecret(vshControl *ctl, const vshCmd *cmd, const char **name) { @@ -357,7 +372,7 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) return true; } -static const vshCmdDef secretCmds[] = { +const vshCmdDef secretCmds[] = { {"secret-define", cmdSecretDefine, opts_secret_define, info_secret_define, 0}, {"secret-dumpxml", cmdSecretDumpXML, opts_secret_dumpxml, diff --git a/tools/virsh-secret.h b/tools/virsh-secret.h new file mode 100644 index 0000000..6ecb921 --- /dev/null +++ b/tools/virsh-secret.h @@ -0,0 +1,33 @@ +/* + * virsh-secret.h: Commands to manage secret + * + * 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_SECRET_H +# define VIRSH_SECRET_H + +# include "virsh.h" + +extern const vshCmdDef secretCmds[]; + +#endif /* VIRSH_SECRET_H */ diff --git a/tools/virsh.c b/tools/virsh.c index 96b31f0..a9745d7 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -82,6 +82,7 @@ #include "virsh-nodedev.h" #include "virsh-nwfilter.h" #include "virsh-pool.h" +#include "virsh-secret.h" static char *progname; @@ -2816,7 +2817,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; } -#include "virsh-secret.c" #include "virsh-snapshot.c" #include "virsh-volume.c" -- 1.7.11.4

On 08/20/2012 07:23 PM, Eric Blake wrote:
One of the simpler splits.
The last couple seemed pretty simple too (well, okay, so one of them did rename "flag" to "flags" :-) ACK.
* tools/virsh-secret.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-secret.c: Likewise. --- tools/Makefile.am | 2 +- tools/virsh-secret.c | 17 ++++++++++++++++- tools/virsh-secret.h | 33 +++++++++++++++++++++++++++++++++ tools/virsh.c | 2 +- 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 tools/virsh-secret.h

Almost done with the splits. * tools/virsh-snapshot.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-snapshot.c: Likewise. --- tools/Makefile.am | 2 +- tools/virsh-snapshot.c | 21 +++++++++++++++++++-- tools/virsh-snapshot.h | 33 +++++++++++++++++++++++++++++++++ tools/virsh.c | 2 +- 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 tools/virsh-snapshot.h diff --git a/tools/Makefile.am b/tools/Makefile.am index a735022..3cdebab 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -115,8 +115,8 @@ virsh_SOURCES = \ virsh-nwfilter.c virsh-nwfilter.h \ virsh-pool.c virsh-pool.h \ virsh-secret.c virsh-secret.h \ + virsh-snapshot.c virsh-snapshot.h \ $(NULL) -# virsh-snapshot.c virsh-snapshot.h \ # virsh-volume.c virsh-volume.h \ # diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index c480d1b..aff91d3 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -1,5 +1,5 @@ /* - * virsh-domain.c: Commands to manage domain snapshot + * virsh-snapshot.c: Commands to manage domain snapshot * * Copyright (C) 2005, 2007-2012 Red Hat, Inc. * @@ -23,6 +23,23 @@ * */ +#include <config.h> +#include "virsh-snapshot.h" + +#include <assert.h> + +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> + +#include "internal.h" +#include "buf.h" +#include "memory.h" +#include "util.h" +#include "virsh-domain.h" +#include "xml.h" + /* Helper for snapshot-create and snapshot-create-as */ static bool vshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer, @@ -1597,7 +1614,7 @@ cleanup: return ret; } -static const vshCmdDef snapshotCmds[] = { +const vshCmdDef snapshotCmds[] = { {"snapshot-create", cmdSnapshotCreate, opts_snapshot_create, info_snapshot_create, 0}, {"snapshot-create-as", cmdSnapshotCreateAs, opts_snapshot_create_as, diff --git a/tools/virsh-snapshot.h b/tools/virsh-snapshot.h new file mode 100644 index 0000000..97e7811 --- /dev/null +++ b/tools/virsh-snapshot.h @@ -0,0 +1,33 @@ +/* + * virsh-snapshot.h: Commands to manage domain snapshot + * + * 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_SNAPSHOT_H +# define VIRSH_SNAPSHOT_H + +# include "virsh.h" + +extern const vshCmdDef snapshotCmds[]; + +#endif /* VIRSH_SNAPSHOT_H */ diff --git a/tools/virsh.c b/tools/virsh.c index a9745d7..8cbdd3e 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -83,6 +83,7 @@ #include "virsh-nwfilter.h" #include "virsh-pool.h" #include "virsh-secret.h" +#include "virsh-snapshot.h" static char *progname; @@ -2817,7 +2818,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; } -#include "virsh-snapshot.c" #include "virsh-volume.c" static const vshCmdDef virshCmds[] = { -- 1.7.11.4

On 08/20/2012 07:33 PM, Eric Blake wrote:
Almost done with the splits.
* tools/virsh-snapshot.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-snapshot.c: Likewise. --- tools/Makefile.am | 2 +- tools/virsh-snapshot.c | 21 +++++++++++++++++++-- tools/virsh-snapshot.h | 33 +++++++++++++++++++++++++++++++++ tools/virsh.c | 2 +- 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 tools/virsh-snapshot.h
ACK.

Last of the file splits. * tools/virsh-volume.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-volume.c: Likewise. --- tools/Makefile.am | 3 +-- tools/virsh-volume.c | 36 +++++++++++++++++++++++++----------- tools/virsh-volume.h | 43 +++++++++++++++++++++++++++++++++++++++++++ tools/virsh.c | 3 +-- 4 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 tools/virsh-volume.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 3cdebab..0d7822d 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -116,9 +116,8 @@ virsh_SOURCES = \ virsh-pool.c virsh-pool.h \ virsh-secret.c virsh-secret.h \ virsh-snapshot.c virsh-snapshot.h \ + virsh-volume.c virsh-volume.h \ $(NULL) -# virsh-volume.c virsh-volume.h \ -# virsh_LDFLAGS = $(WARN_LDFLAGS) $(COVERAGE_LDFLAGS) virsh_LDADD = \ diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index d8ff920..74ac19d 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -23,20 +23,34 @@ * */ -/* default is lookup by Name and UUID */ -#define vshCommandOptVol(_ctl, _cmd, _optname, _pooloptname, _name) \ - vshCommandOptVolBy(_ctl, _cmd, _optname, _pooloptname, _name, \ - VSH_BYUUID|VSH_BYNAME) +#include <config.h> +#include "virsh-volume.h" -static virStorageVolPtr +#include <fcntl.h> + +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> + +#include "internal.h" +#include "buf.h" +#include "memory.h" +#include "util.h" +#include "virfile.h" +#include "virsh-pool.h" +#include "xml.h" + +virStorageVolPtr vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd, const char *optname, const char *pooloptname, - const char **name, int flag) + const char **name, unsigned int flags) { virStorageVolPtr vol = NULL; virStoragePoolPtr pool = NULL; const char *n = NULL, *p = NULL; + virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL); if (vshCommandOptString(cmd, optname, &n) <= 0) return NULL; @@ -47,7 +61,7 @@ vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd, } if (p) - pool = vshCommandOptPoolBy(ctl, cmd, pooloptname, name, flag); + pool = vshCommandOptPoolBy(ctl, cmd, pooloptname, name, flags); vshDebug(ctl, VSH_ERR_DEBUG, "%s: found option <%s>: %s\n", cmd->def->name, optname, n); @@ -56,19 +70,19 @@ vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd, *name = n; /* try it by name */ - if (pool && (flag & VSH_BYNAME)) { + if (pool && (flags & VSH_BYNAME)) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as vol name\n", cmd->def->name, optname); vol = virStorageVolLookupByName(pool, n); } /* try it by key */ - if (vol == NULL && (flag & VSH_BYUUID)) { + if (!vol && (flags & VSH_BYUUID)) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as vol key\n", cmd->def->name, optname); vol = virStorageVolLookupByKey(ctl->conn, n); } /* try it by path */ - if (vol == NULL && (flag & VSH_BYUUID)) { + if (!vol && (flags & VSH_BYUUID)) { vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as vol path\n", cmd->def->name, optname); vol = virStorageVolLookupByPath(ctl->conn, n); @@ -1439,7 +1453,7 @@ cmdVolPath(vshControl *ctl, const vshCmd *cmd) return true; } -static const vshCmdDef storageVolCmds[] = { +const vshCmdDef storageVolCmds[] = { {"vol-clone", cmdVolClone, opts_vol_clone, info_vol_clone, 0}, {"vol-create-as", cmdVolCreateAs, opts_vol_create_as, info_vol_create_as, 0}, diff --git a/tools/virsh-volume.h b/tools/virsh-volume.h new file mode 100644 index 0000000..1b0371b --- /dev/null +++ b/tools/virsh-volume.h @@ -0,0 +1,43 @@ +/* + * virsh-volume.h: Commands to manage storage volume + * + * 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_VOLUME_H +# define VIRSH_VOLUME_H + +# include "virsh.h" + +virStorageVolPtr vshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd, + const char *optname, + const char *pooloptname, + const char **name, unsigned int flags); + +/* default is lookup by Name and UUID */ +# define vshCommandOptVol(_ctl, _cmd, _optname, _pooloptname, _name) \ + vshCommandOptVolBy(_ctl, _cmd, _optname, _pooloptname, _name, \ + VSH_BYUUID|VSH_BYNAME) + +extern const vshCmdDef storageVolCmds[]; + +#endif /* VIRSH_VOLUME_H */ diff --git a/tools/virsh.c b/tools/virsh.c index 8cbdd3e..7a5b92c 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -84,6 +84,7 @@ #include "virsh-pool.h" #include "virsh-secret.h" #include "virsh-snapshot.h" +#include "virsh-volume.h" static char *progname; @@ -2818,8 +2819,6 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) return true; } -#include "virsh-volume.c" - static const vshCmdDef virshCmds[] = { {"cd", cmdCd, opts_cd, info_cd, VSH_CMD_FLAG_NOCONNECT}, {"echo", cmdEcho, opts_echo, info_echo, VSH_CMD_FLAG_NOCONNECT}, -- 1.7.11.4

On 08/20/2012 07:48 PM, Eric Blake wrote:
Last of the file splits.
* tools/virsh-volume.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-volume.c: Likewise. --- tools/Makefile.am | 3 +-- tools/virsh-volume.c | 36 +++++++++++++++++++++++++----------- tools/virsh-volume.h | 43 +++++++++++++++++++++++++++++++++++++++++++ tools/virsh.c | 3 +-- 4 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 tools/virsh-volume.h
Another one that does the standard stuff plus rename flag to flags, and use virCheckFlags to validate the VSH_BYx values used. ACK.

On 08/20/2012 10:58 PM, Laine Stump wrote:
On 08/20/2012 07:48 PM, Eric Blake wrote:
Last of the file splits.
* tools/virsh-volume.h: New file. * tools/Makefile.am (virsh_SOURCES): Build it. * tools/virsh.c: Use new header. * tools/virsh-volume.c: Likewise. --- tools/Makefile.am | 3 +-- tools/virsh-volume.c | 36 +++++++++++++++++++++++++----------- tools/virsh-volume.h | 43 +++++++++++++++++++++++++++++++++++++++++++ tools/virsh.c | 3 +-- 4 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 tools/virsh-volume.h
Another one that does the standard stuff plus rename flag to flags, and use virCheckFlags to validate the VSH_BYx values used.
ACK.
I fixed the commit message nit you pointed out, double-checked that the patches all build independently and pass syntax-check (I had to tweak one or two #define lines to pass cppi), and pushed the series. Osier will have to rebase his pending virsh changes for the 40+ listAll series, but I think the end result will be much easier to follow. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (3)
-
Eric Blake
-
Laine Stump
-
Osier Yang