virsh: move vshWatchJob earlier

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.
This commit is contained in:
Eric Blake 2012-08-17 21:23:07 -06:00
parent 1610b71a96
commit 8e8809e131
2 changed files with 90 additions and 106 deletions

View File

@ -2771,6 +2771,96 @@ out_sig:
ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
}
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)
{
@ -6425,96 +6515,6 @@ vshMigrationTimeout(vshControl *ctl,
virDomainSuspend(dom);
}
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)
{

View File

@ -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)
{