ia64/xen-unstable

changeset 19431:0b13d9787622

libxc: fix link error of xc_save on ia64

The suspend event channel functions are arch independent code
which xc_save uses.
The changeset of 19382:a5f497f02e34 cause link error on ia64.
This patch moves the functions into arch common file from
x86 specific file xc_domain_save.c

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 24 06:55:29 2009 +0000 (2009-03-24)
parents 0477f9061c8a
children e54eeff2de54
files tools/libxc/Makefile tools/libxc/xc_domain_save.c tools/libxc/xc_suspend.c
line diff
     1.1 --- a/tools/libxc/Makefile	Fri Mar 20 17:42:46 2009 +0000
     1.2 +++ b/tools/libxc/Makefile	Tue Mar 24 06:55:29 2009 +0000
     1.3 @@ -29,7 +29,7 @@ CTRL_SRCS-$(CONFIG_NetBSD) += xc_netbsd.
     1.4  CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.c
     1.5  
     1.6  GUEST_SRCS-y :=
     1.7 -GUEST_SRCS-y += xg_private.c
     1.8 +GUEST_SRCS-y += xg_private.c xc_suspend.c
     1.9  GUEST_SRCS-$(CONFIG_MIGRATE) += xc_domain_restore.c xc_domain_save.c
    1.10  GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c
    1.11  
     2.1 --- a/tools/libxc/xc_domain_save.c	Fri Mar 20 17:42:46 2009 +0000
     2.2 +++ b/tools/libxc/xc_domain_save.c	Tue Mar 24 06:55:29 2009 +0000
     2.3 @@ -744,115 +744,6 @@ static xen_pfn_t *map_and_save_p2m_table
     2.4      return success ? p2m : NULL;
     2.5  }
     2.6  
     2.7 -#define SUSPEND_LOCK_FILE "/var/lib/xen/suspend_evtchn_lock.d"
     2.8 -static int lock_suspend_event(void)
     2.9 -{
    2.10 -    int fd, rc;
    2.11 -    mode_t mask;
    2.12 -    char buf[128];
    2.13 -
    2.14 -    mask = umask(022);
    2.15 -    fd = open(SUSPEND_LOCK_FILE, O_CREAT | O_EXCL | O_RDWR, 0666);
    2.16 -    if (fd < 0)
    2.17 -    {
    2.18 -        ERROR("Can't create lock file for suspend event channel\n");
    2.19 -        return -EINVAL;
    2.20 -    }
    2.21 -    umask(mask);
    2.22 -    snprintf(buf, sizeof(buf), "%10ld", (long)getpid());
    2.23 -
    2.24 -    rc = write_exact(fd, buf, strlen(buf));
    2.25 -    close(fd);
    2.26 -
    2.27 -    return rc;
    2.28 -}
    2.29 -
    2.30 -static int unlock_suspend_event(void)
    2.31 -{
    2.32 -    int fd, pid, n;
    2.33 -    char buf[128];
    2.34 -
    2.35 -    fd = open(SUSPEND_LOCK_FILE, O_RDWR);
    2.36 -
    2.37 -    if (fd < 0)
    2.38 -        return -EINVAL;
    2.39 -
    2.40 -    n = read(fd, buf, 127);
    2.41 -
    2.42 -    close(fd);
    2.43 -
    2.44 -    if (n > 0)
    2.45 -    {
    2.46 -        sscanf(buf, "%d", &pid);
    2.47 -        /* We are the owner, so we can simply delete the file */
    2.48 -        if (pid == getpid())
    2.49 -        {
    2.50 -            unlink(SUSPEND_LOCK_FILE);
    2.51 -            return 0;
    2.52 -        }
    2.53 -    }
    2.54 -
    2.55 -    return -EPERM;
    2.56 -}
    2.57 -
    2.58 -int xc_await_suspend(int xce, int suspend_evtchn)
    2.59 -{
    2.60 -    int rc;
    2.61 -
    2.62 -    do {
    2.63 -        rc = xc_evtchn_pending(xce);
    2.64 -        if (rc < 0) {
    2.65 -            ERROR("error polling suspend notification channel: %d", rc);
    2.66 -            return -1;
    2.67 -        }
    2.68 -    } while (rc != suspend_evtchn);
    2.69 -
    2.70 -    /* harmless for one-off suspend */
    2.71 -    if (xc_evtchn_unmask(xce, suspend_evtchn) < 0)
    2.72 -        ERROR("failed to unmask suspend notification channel: %d", rc);
    2.73 -
    2.74 -    return 0;
    2.75 -}
    2.76 -
    2.77 -int xc_suspend_evtchn_release(int xce, int suspend_evtchn)
    2.78 -{
    2.79 -    if (suspend_evtchn >= 0)
    2.80 -        xc_evtchn_unbind(xce, suspend_evtchn);
    2.81 -
    2.82 -    return unlock_suspend_event();
    2.83 -}
    2.84 -
    2.85 -int xc_suspend_evtchn_init(int xc, int xce, int domid, int port)
    2.86 -{
    2.87 -    int rc, suspend_evtchn = -1;
    2.88 -
    2.89 -    if (lock_suspend_event())
    2.90 -        return -EINVAL;
    2.91 -
    2.92 -    suspend_evtchn = xc_evtchn_bind_interdomain(xce, domid, port);
    2.93 -    if (suspend_evtchn < 0) {
    2.94 -        ERROR("failed to bind suspend event channel: %d", suspend_evtchn);
    2.95 -        goto cleanup;
    2.96 -    }
    2.97 -
    2.98 -    rc = xc_domain_subscribe_for_suspend(xc, domid, port);
    2.99 -    if (rc < 0) {
   2.100 -        ERROR("failed to subscribe to domain: %d", rc);
   2.101 -        goto cleanup;
   2.102 -    }
   2.103 -
   2.104 -    /* event channel is pending immediately after binding */
   2.105 -    xc_await_suspend(xce, suspend_evtchn);
   2.106 -
   2.107 -    return suspend_evtchn;
   2.108 -
   2.109 -cleanup:
   2.110 -    if (suspend_evtchn > 0)
   2.111 -        xc_suspend_evtchn_release(xce, suspend_evtchn);
   2.112 -
   2.113 -    return -1;
   2.114 -}
   2.115 -
   2.116  int xc_domain_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
   2.117                     uint32_t max_factor, uint32_t flags, int (*suspend)(void),
   2.118                     int hvm, void *(*init_qemu_maps)(int, unsigned), 
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/libxc/xc_suspend.c	Tue Mar 24 06:55:29 2009 +0000
     3.3 @@ -0,0 +1,117 @@
     3.4 +/*
     3.5 + * This file is subject to the terms and conditions of the GNU General
     3.6 + * Public License.  See the file "COPYING" in the main directory of
     3.7 + * this archive for more details.
     3.8 + */
     3.9 +
    3.10 +#include "xc_private.h"
    3.11 +#include "xenguest.h"
    3.12 +
    3.13 +#define SUSPEND_LOCK_FILE "/var/lib/xen/suspend_evtchn_lock.d"
    3.14 +static int lock_suspend_event(void)
    3.15 +{
    3.16 +    int fd, rc;
    3.17 +    mode_t mask;
    3.18 +    char buf[128];
    3.19 +
    3.20 +    mask = umask(022);
    3.21 +    fd = open(SUSPEND_LOCK_FILE, O_CREAT | O_EXCL | O_RDWR, 0666);
    3.22 +    if (fd < 0)
    3.23 +    {
    3.24 +        ERROR("Can't create lock file for suspend event channel\n");
    3.25 +        return -EINVAL;
    3.26 +    }
    3.27 +    umask(mask);
    3.28 +    snprintf(buf, sizeof(buf), "%10ld", (long)getpid());
    3.29 +
    3.30 +    rc = write_exact(fd, buf, strlen(buf));
    3.31 +    close(fd);
    3.32 +
    3.33 +    return rc;
    3.34 +}
    3.35 +
    3.36 +static int unlock_suspend_event(void)
    3.37 +{
    3.38 +    int fd, pid, n;
    3.39 +    char buf[128];
    3.40 +
    3.41 +    fd = open(SUSPEND_LOCK_FILE, O_RDWR);
    3.42 +
    3.43 +    if (fd < 0)
    3.44 +        return -EINVAL;
    3.45 +
    3.46 +    n = read(fd, buf, 127);
    3.47 +
    3.48 +    close(fd);
    3.49 +
    3.50 +    if (n > 0)
    3.51 +    {
    3.52 +        sscanf(buf, "%d", &pid);
    3.53 +        /* We are the owner, so we can simply delete the file */
    3.54 +        if (pid == getpid())
    3.55 +        {
    3.56 +            unlink(SUSPEND_LOCK_FILE);
    3.57 +            return 0;
    3.58 +        }
    3.59 +    }
    3.60 +
    3.61 +    return -EPERM;
    3.62 +}
    3.63 +
    3.64 +int xc_await_suspend(int xce, int suspend_evtchn)
    3.65 +{
    3.66 +    int rc;
    3.67 +
    3.68 +    do {
    3.69 +        rc = xc_evtchn_pending(xce);
    3.70 +        if (rc < 0) {
    3.71 +            ERROR("error polling suspend notification channel: %d", rc);
    3.72 +            return -1;
    3.73 +        }
    3.74 +    } while (rc != suspend_evtchn);
    3.75 +
    3.76 +    /* harmless for one-off suspend */
    3.77 +    if (xc_evtchn_unmask(xce, suspend_evtchn) < 0)
    3.78 +        ERROR("failed to unmask suspend notification channel: %d", rc);
    3.79 +
    3.80 +    return 0;
    3.81 +}
    3.82 +
    3.83 +int xc_suspend_evtchn_release(int xce, int suspend_evtchn)
    3.84 +{
    3.85 +    if (suspend_evtchn >= 0)
    3.86 +        xc_evtchn_unbind(xce, suspend_evtchn);
    3.87 +
    3.88 +    return unlock_suspend_event();
    3.89 +}
    3.90 +
    3.91 +int xc_suspend_evtchn_init(int xc, int xce, int domid, int port)
    3.92 +{
    3.93 +    int rc, suspend_evtchn = -1;
    3.94 +
    3.95 +    if (lock_suspend_event())
    3.96 +        return -EINVAL;
    3.97 +
    3.98 +    suspend_evtchn = xc_evtchn_bind_interdomain(xce, domid, port);
    3.99 +    if (suspend_evtchn < 0) {
   3.100 +        ERROR("failed to bind suspend event channel: %d", suspend_evtchn);
   3.101 +        goto cleanup;
   3.102 +    }
   3.103 +
   3.104 +    rc = xc_domain_subscribe_for_suspend(xc, domid, port);
   3.105 +    if (rc < 0) {
   3.106 +        ERROR("failed to subscribe to domain: %d", rc);
   3.107 +        goto cleanup;
   3.108 +    }
   3.109 +
   3.110 +    /* event channel is pending immediately after binding */
   3.111 +    xc_await_suspend(xce, suspend_evtchn);
   3.112 +
   3.113 +    return suspend_evtchn;
   3.114 +
   3.115 +cleanup:
   3.116 +    if (suspend_evtchn > 0)
   3.117 +        xc_suspend_evtchn_release(xce, suspend_evtchn);
   3.118 +
   3.119 +    return -1;
   3.120 +}