WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH 4 of 4] libxl: Use libblktapctl.so

To: Daniel Stodden <daniel.stodden@xxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH 4 of 4] libxl: Use libblktapctl.so
From: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Date: Thu, 10 Jun 2010 17:25:06 +0100
Cc: Xen <xen-devel@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Thu, 10 Jun 2010 09:27:09 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <4b0360d2bba5ee673a86.1276140415@xxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1276140411@xxxxxxxxxxxxxxxxxxxxxxx> <4b0360d2bba5ee673a86.1276140415@xxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Alpine 2.00 (DEB 1167 2008-08-23)
> -static char *get_blktap2_device(struct libxl_ctx *ctx, char *name, char 
> *type)
> +static char *make_blktap2_device(struct libxl_ctx *ctx,
> +                              const char *name, const char *type)
>  {
> -    char buf[1024];
> -    char *p;
> -    int devnum;
> -    FILE *f = fopen("/sys/class/blktap2/devices", "r");
> -
> -    
> -    while (!feof(f)) {
> -        if (fscanf(f, "%d %s", &devnum, buf) != 2)
> -            continue;
> -        p = strchr(buf, ':');
> -        if (p == NULL)
> -            continue;
> -        p++;
> -        if (!strcmp(p, name) && !strncmp(buf, type, 3)) {
> -            fclose(f);
> -            return libxl_sprintf(ctx, "/dev/xen/blktap-2/tapdev%d", devnum);
> -        }
> -    }
> -    fclose(f);
> -    return NULL;
> +    char *params, *devname;
> +    int err;
> +    params = libxl_sprintf(ctx, "%s:%s", type, name);
> +    devname = NULL;
> +    err = tap_ctl_create(params, &devname);
> +    free(params);
> +    return err ? NULL : devname;
>  }
> 

you shouldn't free pointers returned by libxl internal functions,
because libxl will take care of free'ing them.

 
>  int libxl_device_disk_add(struct libxl_ctx *ctx, uint32_t domid, 
> libxl_device_disk *disk)
> @@ -1328,38 +1310,16 @@
>          case PHYSTYPE_FILE:
>              /* let's pretend is tap:aio for the moment */
>              disk->phystype = PHYSTYPE_AIO;
> -        case PHYSTYPE_AIO: case PHYSTYPE_QCOW: case PHYSTYPE_QCOW2: case 
> PHYSTYPE_VHD:
> -            if (is_blktap2_supported()) {
> -                int rc, c, p[2], tot;
> -                char buf[1024], *dev;
> -                dev = get_blktap2_device(ctx, disk->physpath, 
> device_disk_string_of_phystype(disk->phystype));
> -                if (dev == NULL) {
> -                    rc= libxl_pipe(ctx, p);  if (rc==-1) return -1;
> -                    rc= libxl_fork(ctx);  if (rc==-1) return -1;
> -                    if (!rc) { /* child */
> -                        int null_r, null_w;
> -                        char *args[4];
> -                        args[0] = "tapdisk2";
> -                        args[1] = "-n";
> -                        args[2] = libxl_sprintf(ctx, "%s:%s", 
> device_disk_string_of_phystype(disk->phystype), disk->physpath);
> -                        args[3] = NULL;
> -
> -                        null_r = open("/dev/null", O_RDONLY);
> -                        null_w = open("/dev/null", O_WRONLY);
> -                        libxl_exec(null_r, p[1], null_w,
> -                                   libxl_abs_path(ctx, "tapdisk2",
> -                                                  libxl_sbindir_path()),
> -                                   args);
> -                        XL_LOG(ctx, XL_LOG_ERROR, "Error execing tapdisk2");
> -                    }
> -                    close(p[1]);
> -                    tot = 0;
> -                    while ((c = read(p[0], buf + tot, sizeof(buf) - tot)) > 
> 0)
> -                        tot = tot + c;
> -                    close(p[0]);
> -                    buf[tot - 1] = '\0';
> -                    dev = buf;
> -                }
> +        case PHYSTYPE_AIO: case PHYSTYPE_QCOW: case PHYSTYPE_QCOW2: case 
> PHYSTYPE_VHD: {
> +            const char *msg;
> +            if (!tap_ctl_check(&msg)) {
> +                const char *type = 
> device_disk_string_of_phystype(disk->phystype);
> +                char *dev;
> +                dev = get_blktap2_device(ctx, disk->physpath, type);
> +                if (!dev)
> +                    dev = make_blktap2_device(ctx, disk->physpath, type);
> +                if (!dev)
> +                    return -1;
>                  flexarray_set(back, boffset++, "tapdisk-params");
>                  flexarray_set(back, boffset++, libxl_sprintf(ctx, "%s:%s", 
> device_disk_string_of_phystype(disk->phystype), disk->physpath));
>                  flexarray_set(back, boffset++, "params");
> 

you are calling make_blktap2_device only if(!dev), are you sure it is
correct? get_blktap2_device returns a pointer on success...

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>