ia64/xen-unstable

changeset 19351:d4ad5dd4f411

blktapctrl: Select backend by prefix

This patch adds support for specifying the backend (tapdisk or ioemu)
to blktapctrl. Images can be specified e.g. as tap:tapdisk:aio,
tap:ioemu:qcow2 or tap:vmdk. When omitting the backend, a default is
chosen based on the image type (currently always tapdisk because ioemu
as a backend is broken until a follow-up patch series against qemu-xen
is applied)

Signed-off-by: Kevin Wolf <kwolf@suse.de>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Mar 12 18:42:31 2009 +0000 (2009-03-12)
parents b4f3a52c359e
children f603aeef0808
files tools/blktap/drivers/blktapctrl.c tools/blktap/drivers/tapdisk.h tools/python/xen/xend/server/BlktapController.py
line diff
     1.1 --- a/tools/blktap/drivers/blktapctrl.c	Thu Mar 12 15:40:52 2009 +0000
     1.2 +++ b/tools/blktap/drivers/blktapctrl.c	Thu Mar 12 18:42:31 2009 +0000
     1.3 @@ -148,7 +148,8 @@ static int get_tapdisk_pid(blkif_t *blki
     1.4   *   return 0 on success, -1 on error.
     1.5   */
     1.6  
     1.7 -static int test_path(char *path, char **dev, int *type, blkif_t **blkif)
     1.8 +static int test_path(char *path, char **dev, int *type, blkif_t **blkif,
     1.9 +	int* use_ioemu)
    1.10  {
    1.11  	char *ptr, handle[10];
    1.12  	int i, size, found = 0;
    1.13 @@ -158,6 +159,17 @@ static int test_path(char *path, char **
    1.14  	*type = MAX_DISK_TYPES + 1;
    1.15          *blkif = NULL;
    1.16  
    1.17 +	if (!strncmp(path, "tapdisk:", strlen("tapdisk:"))) {
    1.18 +		*use_ioemu = 0;
    1.19 +		path += strlen("tapdisk:");
    1.20 +	} else if (!strncmp(path, "ioemu:", strlen("ioemu:"))) {
    1.21 +		*use_ioemu = 1;
    1.22 +		path += strlen("ioemu:");
    1.23 +	} else {
    1.24 +		// Use the default for the image type
    1.25 +		*use_ioemu = -1;
    1.26 +	}
    1.27 +
    1.28  	if ( (ptr = strstr(path, ":"))!=NULL) {
    1.29  		handle_len = (ptr - path);
    1.30  		memcpy(handle, path, handle_len);
    1.31 @@ -174,6 +186,8 @@ static int test_path(char *path, char **
    1.32                          }
    1.33  
    1.34  			if (found) {
    1.35 +				if (*use_ioemu == -1)
    1.36 +					*use_ioemu = dtypes[i]->use_ioemu;
    1.37  				*type = dtypes[i]->idnum;
    1.38                          
    1.39                          if (dtypes[i]->single_handler == 1) {
    1.40 @@ -185,6 +199,7 @@ static int test_path(char *path, char **
    1.41                                          *blkif = active_disks[dtypes[i]
    1.42                                                               ->idnum]->blkif;
    1.43                          }
    1.44 +
    1.45                          return 0;
    1.46                  }
    1.47              }
    1.48 @@ -504,7 +519,8 @@ static int connect_qemu(blkif_t *blkif, 
    1.49  	static int tapdisk_ioemu_pid = 0;
    1.50  	static int dom0_readfd = 0;
    1.51  	static int dom0_writefd = 0;
    1.52 -	
    1.53 +	int refresh_pid = 0;
    1.54 +
    1.55  	if (asprintf(&rdctldev, BLKTAP_CTRL_DIR "/qemu-read-%d", domid) < 0)
    1.56  		return -1;
    1.57  
    1.58 @@ -523,15 +539,23 @@ static int connect_qemu(blkif_t *blkif, 
    1.59  		if (tapdisk_ioemu_pid == 0 || kill(tapdisk_ioemu_pid, 0)) {
    1.60  			/* No device model and tapdisk-ioemu doesn't run yet */
    1.61  			DPRINTF("Launching tapdisk-ioemu\n");
    1.62 -			tapdisk_ioemu_pid = launch_tapdisk_ioemu();
    1.63 +			launch_tapdisk_ioemu();
    1.64  			
    1.65  			dom0_readfd = open_ctrl_socket(wrctldev);
    1.66  			dom0_writefd = open_ctrl_socket(rdctldev);
    1.67 +
    1.68 +			refresh_pid = 1;
    1.69  		}
    1.70  
    1.71  		DPRINTF("Using tapdisk-ioemu connection\n");
    1.72  		blkif->fds[READ] = dom0_readfd;
    1.73  		blkif->fds[WRITE] = dom0_writefd;
    1.74 +
    1.75 +		if (refresh_pid) {
    1.76 +			get_tapdisk_pid(blkif);
    1.77 +			tapdisk_ioemu_pid = blkif->tappid;
    1.78 +		}
    1.79 +
    1.80  	} else if (access(rdctldev, R_OK | W_OK) == 0) {
    1.81  		/* Use existing pipe to the device model */
    1.82  		DPRINTF("Using qemu-dm connection\n");
    1.83 @@ -605,13 +629,14 @@ static int blktapctrl_new_blkif(blkif_t 
    1.84  	image_t *image;
    1.85  	blkif_t *exist = NULL;
    1.86  	static uint16_t next_cookie = 0;
    1.87 +	int use_ioemu;
    1.88  
    1.89  	DPRINTF("Received a poll for a new vbd\n");
    1.90  	if ( ((blk=blkif->info) != NULL) && (blk->params != NULL) ) {
    1.91  		if (blktap_interface_create(ctlfd, &major, &minor, blkif) < 0)
    1.92  			return -1;
    1.93  
    1.94 -		if (test_path(blk->params, &ptr, &type, &exist) != 0) {
    1.95 +		if (test_path(blk->params, &ptr, &type, &exist, &use_ioemu) != 0) {
    1.96                          DPRINTF("Error in blktap device string(%s).\n",
    1.97                                  blk->params);
    1.98                          goto fail;
    1.99 @@ -620,7 +645,7 @@ static int blktapctrl_new_blkif(blkif_t 
   1.100  		blkif->cookie = next_cookie++;
   1.101  
   1.102  		if (!exist) {
   1.103 -			if (type == DISK_TYPE_IOEMU) {
   1.104 +			if (use_ioemu) {
   1.105  				if (connect_qemu(blkif, blkif->domid))
   1.106  					goto fail;
   1.107  			} else {
     2.1 --- a/tools/blktap/drivers/tapdisk.h	Thu Mar 12 15:40:52 2009 +0000
     2.2 +++ b/tools/blktap/drivers/tapdisk.h	Thu Mar 12 18:42:31 2009 +0000
     2.3 @@ -145,6 +145,8 @@ typedef struct disk_info {
     2.4  	char handle[10];     /* xend handle, e.g. 'ram' */
     2.5  	int  single_handler; /* is there a single controller for all */
     2.6  	                     /* instances of disk type? */
     2.7 +	int  use_ioemu;      /* backend provider: 0 = tapdisk; 1 = ioemu */
     2.8 +
     2.9  #ifdef TAPDISK
    2.10  	struct tap_disk *drv;	
    2.11  #endif
    2.12 @@ -167,7 +169,6 @@ extern struct tap_disk tapdisk_qcow2;
    2.13  #define DISK_TYPE_RAM      3
    2.14  #define DISK_TYPE_QCOW     4
    2.15  #define DISK_TYPE_QCOW2    5
    2.16 -#define DISK_TYPE_IOEMU    6
    2.17  
    2.18  
    2.19  /*Define Individual Disk Parameters here */
    2.20 @@ -176,6 +177,7 @@ static disk_info_t aio_disk = {
    2.21  	"raw image (aio)",
    2.22  	"aio",
    2.23  	0,
    2.24 +	0,
    2.25  #ifdef TAPDISK
    2.26  	&tapdisk_aio,
    2.27  #endif
    2.28 @@ -186,6 +188,7 @@ static disk_info_t sync_disk = {
    2.29  	"raw image (sync)",
    2.30  	"sync",
    2.31  	0,
    2.32 +	0,
    2.33  #ifdef TAPDISK
    2.34  	&tapdisk_sync,
    2.35  #endif
    2.36 @@ -196,6 +199,7 @@ static disk_info_t vmdk_disk = {
    2.37  	"vmware image (vmdk)",
    2.38  	"vmdk",
    2.39  	1,
    2.40 +	0,
    2.41  #ifdef TAPDISK
    2.42  	&tapdisk_vmdk,
    2.43  #endif
    2.44 @@ -206,6 +210,7 @@ static disk_info_t ram_disk = {
    2.45  	"ramdisk image (ram)",
    2.46  	"ram",
    2.47  	1,
    2.48 +	0,
    2.49  #ifdef TAPDISK
    2.50  	&tapdisk_ram,
    2.51  #endif
    2.52 @@ -216,6 +221,7 @@ static disk_info_t qcow_disk = {
    2.53  	"qcow disk (qcow)",
    2.54  	"qcow",
    2.55  	0,
    2.56 +	0,
    2.57  #ifdef TAPDISK
    2.58  	&tapdisk_qcow,
    2.59  #endif
    2.60 @@ -226,21 +232,12 @@ static disk_info_t qcow2_disk = {
    2.61  	"qcow2 disk (qcow2)",
    2.62  	"qcow2",
    2.63  	0,
    2.64 +	0,
    2.65  #ifdef TAPDISK
    2.66  	&tapdisk_qcow2,
    2.67  #endif
    2.68  };
    2.69  
    2.70 -static disk_info_t ioemu_disk = {
    2.71 -	DISK_TYPE_IOEMU,
    2.72 -	"ioemu disk",
    2.73 -	"ioemu",
    2.74 -	1,
    2.75 -#ifdef TAPDISK
    2.76 -	NULL
    2.77 -#endif
    2.78 -};
    2.79 -
    2.80  /*Main disk info array */
    2.81  static disk_info_t *dtypes[] = {
    2.82  	&aio_disk,
    2.83 @@ -249,7 +246,6 @@ static disk_info_t *dtypes[] = {
    2.84  	&ram_disk,
    2.85  	&qcow_disk,
    2.86  	&qcow2_disk,
    2.87 -	&ioemu_disk,
    2.88  };
    2.89  
    2.90  typedef struct driver_list_entry {
     3.1 --- a/tools/python/xen/xend/server/BlktapController.py	Thu Mar 12 15:40:52 2009 +0000
     3.2 +++ b/tools/python/xen/xend/server/BlktapController.py	Thu Mar 12 18:42:31 2009 +0000
     3.3 @@ -15,7 +15,8 @@ blktap_disk_types = [
     3.4      'qcow',
     3.5      'qcow2',
     3.6  
     3.7 -    'ioemu'
     3.8 +    'ioemu',
     3.9 +    'tapdisk',
    3.10      ]
    3.11  
    3.12  class BlktapController(BlkifController):