[libvirt] [PATCH 1/4] virsh: move vshWatchJob earlier

Laine Stump laine at laine.org
Sat Aug 18 05:26:08 UTC 2012


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




More information about the libvir-list mailing list