ia64/xen-unstable

changeset 19353:d8741d4dd05a

blktapctrl: Fix too early close of pipes

Connections to ioemu have single_handler set, so they are closed as
soon as all images of a certain type are closed. This is wrong with
ioemu: All images that belong to the same domain are handled by the
same backend process (usually qemu-dm, but also tapdisk-ioemu for
domains without device model), regardless of the image type.

This patch checks for the same-domain condition for ioemu connections.

Signed-off-by: Kevin Wolf <kwolf@suse.de>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Mar 12 18:46:26 2009 +0000 (2009-03-12)
parents f603aeef0808
children c30742011bb8
files tools/blktap/drivers/blktapctrl.c
line diff
     1.1 --- a/tools/blktap/drivers/blktapctrl.c	Thu Mar 12 18:42:59 2009 +0000
     1.2 +++ b/tools/blktap/drivers/blktapctrl.c	Thu Mar 12 18:46:26 2009 +0000
     1.3 @@ -231,6 +231,24 @@ static void add_disktype(blkif_t *blkif,
     1.4  	entry->pprev = pprev;
     1.5  }
     1.6  
     1.7 +static int qemu_instance_has_disks(pid_t pid)
     1.8 +{
     1.9 +	int i;
    1.10 +	int count = 0;
    1.11 +	driver_list_entry_t *entry;
    1.12 +
    1.13 +	for (i = 0; i < MAX_DISK_TYPES; i++) {
    1.14 +		entry = active_disks[i];
    1.15 +		while (entry) {
    1.16 +			if ((entry->blkif->tappid == pid) && dtypes[i]->use_ioemu)
    1.17 +				count++;
    1.18 +			entry = entry->next;
    1.19 +		}
    1.20 +	}
    1.21 +
    1.22 +	return (count != 0);
    1.23 +}
    1.24 +
    1.25  static int del_disktype(blkif_t *blkif)
    1.26  {
    1.27  	driver_list_entry_t *entry, **pprev;
    1.28 @@ -255,6 +273,14 @@ static int del_disktype(blkif_t *blkif)
    1.29  	DPRINTF("DEL_DISKTYPE: Freeing entry\n");
    1.30  	free(entry);
    1.31  
    1.32 +	/*
    1.33 +	 * When using ioemu, all disks of one VM are connected to the same
    1.34 +	 * qemu-dm instance. We may close the file handle only if there is
    1.35 +	 * no other disk left for this domain.
    1.36 +	 */
    1.37 +	if (dtypes[type]->use_ioemu)
    1.38 +		return !qemu_instance_has_disks(blkif->tappid);
    1.39 +
    1.40  	/* Caller should close() if no single controller, or list is empty. */
    1.41  	return (!dtypes[type]->single_handler || (active_disks[type] == NULL));
    1.42  }
    1.43 @@ -721,6 +747,7 @@ static int unmap_blktapctrl(blkif_t *blk
    1.44  	}
    1.45  
    1.46  	if (del_disktype(blkif)) {
    1.47 +		DPRINTF("Closing communication pipe to pid %d\n", blkif->tappid);
    1.48  		close(blkif->fds[WRITE]);
    1.49  		close(blkif->fds[READ]);
    1.50  	}