direct-io.hg

changeset 12456:66a169df22c5

[BLKTAP] Little error handling fix to blktapctrl.c.

Signed-off-by: Andrew Warfield <andy@xensource.com>
author Andrew Warfield <andy@xensource.com>
date Wed Nov 15 12:50:17 2006 -0800 (2006-11-15)
parents 3fa6635d04b9
children 37338c405493
files tools/blktap/drivers/blktapctrl.c
line diff
     1.1 --- a/tools/blktap/drivers/blktapctrl.c	Wed Nov 15 18:41:06 2006 +0000
     1.2 +++ b/tools/blktap/drivers/blktapctrl.c	Wed Nov 15 12:50:17 2006 -0800
     1.3 @@ -167,13 +167,22 @@ static int get_tapdisk_pid(blkif_t *blki
     1.4  	return 1;
     1.5  }
     1.6  
     1.7 -static blkif_t *test_path(char *path, char **dev, int *type)
     1.8 +/* Look up the disk specified by path: 
     1.9 + *   if found, dev points to the device string in the path
    1.10 + *             type is the tapdisk driver type id
    1.11 + *             blkif is the existing interface if this is a shared driver
    1.12 + *             and NULL otherwise.
    1.13 + *   return 0 on success, -1 on error.
    1.14 + */
    1.15 +
    1.16 +static int test_path(char *path, char **dev, int *type, blkif_t *blkif)
    1.17  {
    1.18  	char *ptr, handle[10];
    1.19 -	int i, size;
    1.20 +	int i, size, found = 0;
    1.21  
    1.22  	size = sizeof(dtypes)/sizeof(disk_info_t *);
    1.23  	*type = MAX_DISK_TYPES + 1;
    1.24 +        blkif = NULL;
    1.25  
    1.26  	if ( (ptr = strstr(path, ":"))!=NULL) {
    1.27  		memcpy(handle, path, (ptr - path));
    1.28 @@ -182,26 +191,36 @@ static blkif_t *test_path(char *path, ch
    1.29  		*ptr = '\0';
    1.30  		DPRINTF("Detected handle: [%s]\n",handle);
    1.31  
    1.32 -		for (i = 0; i < size; i++) {
    1.33 -			if (strncmp(handle, dtypes[i]->handle, (ptr - path))
    1.34 -			    ==0) {
    1.35 -				*type = dtypes[i]->idnum;
    1.36 +		for (i = 0; i < size; i++) 
    1.37 +			if (strncmp(handle, dtypes[i]->handle, 
    1.38 +                                    (ptr - path)) ==0) {
    1.39 +                                found = 1;
    1.40 +                                break;
    1.41 +                        }
    1.42  
    1.43 -				if (dtypes[i]->single_handler == 1) {
    1.44 -					/* Check whether tapdisk process 
    1.45 -					   already exists */
    1.46 -					if (active_disks[dtypes[i]->idnum] 
    1.47 -					    == NULL) return NULL;
    1.48 -					else 
    1.49 -						return active_disks[dtypes[i]->idnum]->blkif;
    1.50 -				}
    1.51 -			}
    1.52 -		}
    1.53 -	} else *dev = NULL;
    1.54 +                if (found) {
    1.55 +                        *type = dtypes[i]->idnum;
    1.56 +                        
    1.57 +                        if (dtypes[i]->single_handler == 1) {
    1.58 +                                /* Check whether tapdisk process 
    1.59 +                                   already exists */
    1.60 +                                if (active_disks[dtypes[i]->idnum] == NULL) 
    1.61 +                                        blkif = NULL;
    1.62 +                                else 
    1.63 +                                        blkif = active_disks[dtypes[i]
    1.64 +                                                             ->idnum]->blkif;
    1.65 +                        }
    1.66 +                        return 0;
    1.67 +                }
    1.68 +        }
    1.69  
    1.70 -	return NULL;
    1.71 +        /* Fall-through case, we didn't find a disk driver. */
    1.72 +        DPRINTF("Unknown blktap disk type [%s]!\n",handle);
    1.73 +        *dev = NULL;
    1.74 +        return -1;
    1.75  }
    1.76  
    1.77 +
    1.78  static void add_disktype(blkif_t *blkif, int type)
    1.79  {
    1.80  	driver_list_entry_t *entry, **pprev;
    1.81 @@ -463,7 +482,11 @@ int blktapctrl_new_blkif(blkif_t *blkif)
    1.82  		if (get_new_dev(&major, &minor, blkif)<0)
    1.83  			return -1;
    1.84  
    1.85 -		exist = test_path(blk->params, &ptr, &type);
    1.86 +		if (test_path(blk->params, &ptr, &type, exist) != 0) {
    1.87 +                        DPRINTF("Error in blktap device string(%s).\n",
    1.88 +                                blk->params);
    1.89 +                        return -1;
    1.90 +                }
    1.91  		blkif->drivertype = type;
    1.92  		blkif->cookie = lrand48() % MAX_RAND_VAL;
    1.93