ia64/xen-unstable

changeset 15652:07655ed2fe58

[HVM] Save/restore: don't leak shared-memory segments after HVM live-migrate.
Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
author Tim Deegan <Tim.Deegan@xensource.com>
date Thu Jul 26 12:00:32 2007 +0100 (2007-07-26)
parents 3ec3e2840a29
children bf512fde6667
files tools/xcutils/xc_save.c
line diff
     1.1 --- a/tools/xcutils/xc_save.c	Wed Jul 25 09:51:14 2007 +0100
     1.2 +++ b/tools/xcutils/xc_save.c	Thu Jul 26 12:00:32 2007 +0100
     1.3 @@ -54,8 +54,18 @@ static int suspend(int domid)
     1.4  
     1.5  static char *qemu_active_path;
     1.6  static char *qemu_next_active_path;
     1.7 +static int qemu_shmid = -1;
     1.8  static struct xs_handle *xs;
     1.9  
    1.10 +
    1.11 +/* Mark the shared-memory segment for destruction */
    1.12 +static void qemu_destroy_buffer(void)
    1.13 +{
    1.14 +    if (qemu_shmid != -1)
    1.15 +        shmctl(qemu_shmid, IPC_RMID, NULL);
    1.16 +    qemu_shmid = -1;
    1.17 +}
    1.18 +
    1.19  /* Get qemu to change buffers. */
    1.20  static void qemu_flip_buffer(int domid, int next_active)
    1.21  {
    1.22 @@ -97,22 +107,23 @@ static void * init_qemu_maps(int domid, 
    1.23  {
    1.24      key_t key;
    1.25      char key_ascii[17] = {0,};
    1.26 -    int shmid = -1;
    1.27      void *seg; 
    1.28      char *path, *p;
    1.29  
    1.30      /* Make a shared-memory segment */
    1.31 -    while (shmid == -1)
    1.32 -    {
    1.33 +    do {
    1.34          key = rand(); /* No security, just a sequence of numbers */
    1.35 -        shmid = shmget(key, 2 * bitmap_size, 
    1.36 +        qemu_shmid = shmget(key, 2 * bitmap_size, 
    1.37                         IPC_CREAT|IPC_EXCL|S_IRUSR|S_IWUSR);
    1.38 -        if (shmid == -1 && errno != EEXIST)
    1.39 +        if (qemu_shmid == -1 && errno != EEXIST)
    1.40              errx(1, "can't get shmem to talk to qemu-dm");
    1.41 -    }
    1.42 +    } while (qemu_shmid == -1);
    1.43 +
    1.44 +    /* Remember to tidy up after ourselves */
    1.45 +    atexit(qemu_destroy_buffer);
    1.46  
    1.47      /* Map it into our address space */
    1.48 -    seg = shmat(shmid, NULL, 0);
    1.49 +    seg = shmat(qemu_shmid, NULL, 0);
    1.50      if (seg == (void *) -1) 
    1.51          errx(1, "can't map shmem to talk to qemu-dm");
    1.52      memset(seg, 0, 2 * bitmap_size);