blktap2: The tap-ctl userspace control utility and library
PATCH 1/1 blktap2: The tap-ctl userspace control utility and library
Hi.
Apart from removing some dead code and tidying up tapdisk-vbd a little, the bigger introduces our new tap-ctl utility code.
The code aims to be a complete replacement for the original blktap2 control path, run through sysfs. Fully implemented in userspace, all tapdisks now gained a small IPC layer on top of Unix domain sockets.
Sample usage:
# tap-ctl allocate /dev/xen/blktap-2/tapdev0
# tap-ctl spawn tapdisk spawned with pid 4168
# tap-ctl list
4168 - - - -
- 0 - - -# tap-ctl attach -p 4168 -m 0
# tap-ctl list
4168 0 0 - -# tap-ctl open -p 4168 -m 0 -a aio:/var/tmp/lenny.ext
# tap-ctl list
4168 0 0 aio /var/tmp/lenny.ext# tap-ctl close -p 4168 -m 0 # tap-ctl detach -p 4168 -m 0 # tap-ctl free -m 0
The above example is a bit noisy, because it's mediating between minor number (block devices), tapdisks and tapdisk VBDs (the tapdisk I/O queue running a bdev) in detail.
There are shortcuts. At the same time, the low-level interface should be general enough to stay extensible, and help accomodate some of the more esoteric features, like shared images and/or multiple VBDs sharing the same tapdisk.
Cheers,
Daniel
PATCH 1/1 blktap2: Remove tapdisk-ipc module
Obsoleted with blktapctrl.
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1275947595 25200
# Node ID 0156cca51013424068a563705b0d5689292b5c36 # Parent 4ab68bf4c37e4c97e12efe7aced616ce6946578f
blktap2: Remove tapdisk-ipc module.
Obsoleted with blktapctrl.
tools/blktap2/drivers/Makefile +0 -1
@@ -74,7 +74,6 @@ PORTABLE-OBJS-$(CONFIG_NetBSD) += blk_netbsd.o TAP-OBJS-y := scheduler.o -TAP-OBJS-y += tapdisk-ipc.o TAP-OBJS-y += tapdisk-vbd.o TAP-OBJS-y += tapdisk-image.o TAP-OBJS-y += tapdisk-driver.o
tools/blktap2/drivers/img2qcow.c +2 -2
@@ -201,13 +201,13 @@ (uint64_t)info.size);/* Open Qcow image*/ - err =tapdisk_server_initialize (NULL ,NULL ); + err =tapdisk_server_initialize ();if ( err ) {DPRINTF ("qcow2raw Couldn't initialize server instance.\n" );return err; } - err=tapdisk_vbd_initialize (-1 ,-1 ,QCOW_VBD ); + err=tapdisk_vbd_initialize (QCOW_VBD );if ( err ) {DPRINTF ("qcow2raw Couldn't initialize qcow vbd.\n" );return err;
tools/blktap2/drivers/qcow2raw.c +3 -3
@@ -217,13 +217,13 @@exit (-1 ); } - err =tapdisk_server_initialize (NULL ,NULL ); + err =tapdisk_server_initialize ();if ( err ) {DPRINTF ("qcow2raw Couldn't initialize server instance.\n" );return err; } - err=tapdisk_vbd_initialize (-1 ,-1 ,QCOW_VBD ); + err=tapdisk_vbd_initialize (QCOW_VBD );if ( err ) {DPRINTF ("qcow2raw Couldn't initialize qcow vbd.\n" );return err;
@@ -335,7 +335,7 @@ }//Now the output file should be there, reopen it as an aio VBD - err=tapdisk_vbd_initialize (-1 ,-1 ,AIO_VBD ); + err=tapdisk_vbd_initialize (AIO_VBD );if ( err ) {DPRINTF ("qcow2raw Couldn't initialize aio vbd.\n" );return err;
tools/blktap2/drivers/tapdisk-diff.c +2 -2
@@ -540,7 +540,7 @@ s->id = tapdisk_stream_count++; - err =tapdisk_vbd_initialize (-1 ,-1 , s->id); + err =tapdisk_vbd_initialize (s->id);if (err) goto out;
@@ -755,7 +755,7 @@tapdisk_start_logging ("tapdisk-diff" ); - err =tapdisk_server_initialize (NULL ,NULL ); + err =tapdisk_server_initialize ();if (err) goto out;
tools/blktap2/drivers/tapdisk-ipc.c deleted +0 -353
353 lines not on this page · raw message
tools/blktap2/drivers/tapdisk-ipc.h deleted +0 -47
47 lines not on this page · raw message
tools/blktap2/drivers/tapdisk-server.c +2 -33
@@ -212,27 +212,6 @@tapdisk_vbd_kill_queue (vbd); } -static void -tapdisk_server_send_error (const char *message) -{ -td_vbd_t *vbd, *tmp; - -tapdisk_server_for_each_vbd (vbd, tmp) -tapdisk_ipc_write_error (&vbd->ipc, message); -} - -static int -tapdisk_server_init_ipc (const char *read,const char *write) -{ -return tapdisk_ipc_open (&server.ipc, read, write); -} - -static void -tapdisk_server_close_ipc (void ) -{ -tapdisk_ipc_close (&server.ipc); -} -static int tapdisk_server_init_aio (void ) {
@@ -250,7 +229,6 @@tapdisk_server_close (void) {tapdisk_server_close_aio (); -tapdisk_server_close_ipc (); } static void
@@ -292,7 +270,6 @@if (xfsz_error_sent)break ; -tapdisk_server_send_error ("received SIGXFSZ, closing queues" ); xfsz_error_sent =1 ;break ;
@@ -303,7 +280,7 @@ }int -tapdisk_server_initialize (const char *read,const char *write) +tapdisk_server_initialize (void ) {int err;
@@ -312,21 +289,13 @@scheduler_initialize (&server.scheduler); - err =tapdisk_server_init_ipc (read, write); -if (err) - goto fail; - err =tapdisk_server_init_aio ();if (err) - goto fail; +return err; server.run =1 ;return 0 ; - -fail: -tapdisk_server_close_ipc (); -return err; }int
tools/blktap2/drivers/tapdisk-server.h +1 -2
@@ -47,14 +47,13 @@void tapdisk_server_unregister_event (event_id_t );void tapdisk_server_set_max_timeout (int ); -int tapdisk_server_initialize (const char *,const char *); +int tapdisk_server_initialize (void );int tapdisk_server_run (void );#define TAPDISK_TIOCBS (TAPDISK_DATA_REQUESTS + 50) typedef struct tapdisk_server { int run; - td_ipc_t ipc; struct list_head vbds; scheduler_t scheduler; struct tqueue aio_queue;
tools/blktap2/drivers/tapdisk-stream.c +2 -2
@@ -333,11 +333,11 @@ s->id = tapdisk_stream_count++; - err =tapdisk_server_initialize (NULL ,NULL ); + err =tapdisk_server_initialize ();if (err) goto out; - err =tapdisk_vbd_initialize (-1 ,-1 , s->id); + err =tapdisk_vbd_initialize (s->id);if (err) goto out;
tools/blktap2/drivers/tapdisk-vbd.c +2 -12
@@ -82,7 +82,7 @@ }int -tapdisk_vbd_initialize (int rfd,int wfd,uint16_t uuid) +tapdisk_vbd_initialize (uint16_t uuid) {int i;td_vbd_t *vbd;
@@ -100,9 +100,6 @@ } vbd->uuid = uuid; - vbd->ipc.rfd = rfd; - vbd->ipc.wfd = wfd; - vbd->ipc.uuid = uuid; vbd->ring.fd =-1 ;/* default blktap ring completion */
@@ -995,7 +992,6 @@ vbd->kicked);tapdisk_vbd_close_vdi (vbd); -tapdisk_ipc_write (&vbd->ipc,TAPDISK_MESSAGE_CLOSE_RSP );tapdisk_vbd_unregister_events (vbd);tapdisk_vbd_unmap_device (vbd);tapdisk_server_remove_vbd (vbd);
@@ -1196,7 +1192,6 @@td_flag_clear (vbd->state,TD_VBD_PAUSE_REQUESTED );td_flag_set (vbd->state,TD_VBD_PAUSED ); -tapdisk_ipc_write (&vbd->ipc,TAPDISK_MESSAGE_PAUSE_RSP );return 0 ; }
@@ -1208,7 +1203,6 @@if (!td_flag_test (vbd->state,TD_VBD_PAUSED )) {EPRINTF ("resume request for unpaused vbd %s\n" , vbd->name); -tapdisk_ipc_write (&vbd->ipc,TAPDISK_MESSAGE_ERROR );return -EINVAL ; }
@@ -1216,7 +1210,6 @@ vbd->name =strdup (path);if (!vbd->name) {EPRINTF ("copying new vbd %s name failed\n" , path); -tapdisk_ipc_write (&vbd->ipc,TAPDISK_MESSAGE_ERROR );return -EINVAL ; } vbd->type = drivertype;
@@ -1241,15 +1234,12 @@sleep (TD_VBD_EIO_SLEEP ); } -if (err) { -tapdisk_ipc_write (&vbd->ipc,TAPDISK_MESSAGE_ERROR ); +if (err)return err; - }tapdisk_vbd_start_queue (vbd);td_flag_clear (vbd->state,TD_VBD_PAUSED );td_flag_clear (vbd->state,TD_VBD_PAUSE_REQUESTED ); -tapdisk_ipc_write (&vbd->ipc,TAPDISK_MESSAGE_RESUME_RSP );return 0 ; }
tools/blktap2/drivers/tapdisk-vbd.h +1 -4
@@ -34,7 +34,6 @@#include "tapdisk.h" #include "scheduler.h" -#include "tapdisk-ipc.h" #include "tapdisk-image.h" #define TD_VBD_MAX_RETRIES 100
@@ -101,8 +100,6 @@td_flag_t flags;td_flag_t state; -td_ipc_t ipc; -struct list_head images;struct list_head new_requests;
@@ -171,7 +168,7 @@return list_entry (image->next.next, td_image_t, next); } -int tapdisk_vbd_initialize (int ,int ,td_uuid_t ); +int tapdisk_vbd_initialize (td_uuid_t );void tapdisk_vbd_set_callback (td_vbd_t *,td_vbd_cb_t ,void *);int tapdisk_vbd_parse_stack (td_vbd_t *vbd,const char *path); int tapdisk_vbd_open(td_vbd_t *, const char *, uint16_t,
tools/blktap2/drivers/tapdisk2.c +2 -2
@@ -249,7 +249,7 @@char *devname;struct blktap2_params params; - err =tapdisk_vbd_initialize (-1 ,-1 ,TAPDISK2_VBD ); + err =tapdisk_vbd_initialize (TAPDISK2_VBD );if (err)return err;
@@ -349,7 +349,7 @@if (err) goto out; - err =tapdisk_server_initialize (NULL ,NULL ); + err =tapdisk_server_initialize ();if (err) goto fail;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blktap2: Remove LVM hacks
In reply to Daniel StoddenThese only mattered for XCP's LVHD with blktap1.
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1275947595 25200
# Node ID eb39271223ce6600cb81cf0dab8167a382d1393a # Parent 0156cca51013424068a563705b0d5689292b5c36
blktap2: Remove LVM hacks.
These only mattered for XCP's LVHD with blktap1.
tools/blktap2/drivers/tapdisk-vbd.c +0 -288
@@ -280,272 +280,6 @@return err; } -/* -* LVHD hack: have to rescan LVM metadata on pool -* slaves to register lvchanges made on master. FIXME. -*/ -static int -tapdisk_vbd_reactivate_volume (const char *name) -{ -int err; -char *cmd; - -DPRINTF ("reactivating %s\n" , name); - - err =asprintf (&cmd,"lvchange -an %s" , name); -if (err == -1 ) { -EPRINTF ("failed to deactivate %s\n" , name); -return -errno; - } - - err =system (cmd); -if (err) { -/* -* Assume that LV deactivation failed because the LV is open, -* in which case the LVM information should be up-to-date and -* we don't need this step anyways (so ignore the error). If -* the failure is due to a non-existent LV, the next command -* (lvchange -ay) will catch it. -* If we want to be more prudent/paranoid, we can instead check -* whether the LV is currently open (a bit more work). -*/ - } - -free (cmd); - err =asprintf (&cmd,"lvchange -ay --refresh %s" , name); -if (err == -1 ) { -EPRINTF ("failed to activate %s\n" , name); -return -errno; - } - - err =system (cmd); -if (err) -EPRINTF ("%s failed: %d\n" , cmd, err); -free (cmd); -return err; -} - -static int -tapdisk_vbd_reactivate_volumes (td_vbd_t *vbd,int resume) -{ -int i, cnt, err; -char *name, *new; -vhd_context_t vhd; -vhd_parent_locator_t *loc; - - new =NULL ; - name =NULL ; - -if (vbd->storage !=TAPDISK_STORAGE_TYPE_LVM ) -return 0 ; - -if (!resume && vbd->reactivated) -return 0 ; - - name =strdup (vbd->name); -if (!name) { -EPRINTF ("%s: nomem\n" , vbd->name); -return -ENOMEM ; - } - -for (cnt =0 ;1 ; cnt++) { - -/* only need to reactivate child and parent during resume */ -if (resume && cnt ==2 ) -break ; - - err =tapdisk_vbd_reactivate_volume (name); -if (err) - goto fail; - -if (!strstr (name,"VHD" )) -break ; - -for (i =0 ; i <TD_VBD_EIO_RETRIES ; i++) { - err =vhd_open (&vhd, name,VHD_OPEN_RDONLY ); -if (!err) -break ; - -libvhd_set_log_level (1 ); -sleep (TD_VBD_EIO_SLEEP ); - } -libvhd_set_log_level (0 ); -if (err) - goto fail; - -if (vhd.footer.type !=HD_TYPE_DIFF ) { -vhd_close (&vhd); -break ; - } - - loc =NULL ; -for (i =0 ; i <8 ; i++) -if (vhd.header.loc[i].code ==PLAT_CODE_MACX ) { - loc = vhd.header.loc + i; -break ; - } - -if (!loc) { -vhd_close (&vhd); - err = -EINVAL ; - goto fail; - } - -free (name); - err =vhd_parent_locator_read (&vhd, loc, &name); -vhd_close (&vhd); - -if (err) { - name =NULL ; - goto fail; - } - -/* -* vhd_parent_locator_read returns path relative to child: -* ./VG_XenStorage--<sr-uuid>-VHD--<vdi-uuid> -* we have to convert this to absolute path for lvm -*/ - err =asprintf (&new,"/dev/mapper/%s" , name +2 ); -if (err ==-1 ) { - err = -errno; - goto fail; - } - -free (name); - name = new; - } - - err =0 ; - vbd->reactivated =1 ; - -out: -free (name); -return err; - -fail: -EPRINTF ("failed to reactivate %s: %d\n" , vbd->name, err); - goto out; -} - -/* -* LVHD hack: -* raw volumes are named /dev/<sr-vg-name>-<sr-uuid>/LV-<sr-uuid> -* vhd volumes are named /dev/<sr-vg-name>-<sr-uuid>/VHD-<sr-uuid> -* -* a live snapshot of a raw volume will result in the writeable volume's -* name changing from the raw to vhd format, but this change will not be -* reflected by xenstore. hence this mess. -*/ -static int -tapdisk_vbd_check_file (td_vbd_t *vbd) -{ -int i, err; -regex_t re; -size_t len, max; -regmatch_t matches[4 ]; -char *new, *src, *dst, error[256 ]; - -if (vbd->storage !=TAPDISK_STORAGE_TYPE_LVM ) -return 0 ; - - err =tapdisk_vbd_reactivate_volume (vbd->name); -if (!err) -return 0 ; -else -DPRINTF ("reactivating %s failed\n" , vbd->name); - -#define HEX "[A-Za-z0-9]" -#define UUID HEX"\\{8\\}-"HEX"\\{4\\}-"HEX"\\{4\\}-"HEX"\\{4\\}-"HEX"\\{12\\}" -#define VG "VG_"HEX"\\+" -#define TYPE "\\(LV\\|VHD\\)" -#define RE "\\(/dev/"VG"-"UUID"/\\)"TYPE"\\(-"UUID"\\)" - - err =regcomp (&re,RE ,0 ); -if (err) - goto regerr; - -#undef HEX -#undef UUID -#undef VG -#undef TYPE -#undef RE - - err =regexec (&re, vbd->name,4 , matches,0 ); -if (err) - goto regerr; - - max =strlen ("VHD" ) +1 ; -for (i =1 ; i <4 ; i++) { -if (matches[i].rm_so ==-1 || matches[i].rm_eo ==-1 ) { -EPRINTF ("%s: failed to tokenize name\n" , vbd->name); - err = -EINVAL ; - goto out; - } - - max += matches[i].rm_eo - matches[i].rm_so; - } - - new =malloc (max); -if (!new) { -EPRINTF ("%s: failed to allocate new name\n" , vbd->name); - err = -ENOMEM ; - goto out; - } - - src = new; -for (i =1 ; i <4 ; i++) { - dst = vbd->name + matches[i].rm_so; - len = matches[i].rm_eo - matches[i].rm_so; - -if (i ==2 ) { -if (memcmp (dst,"LV" , len)) { -EPRINTF ("%s: bad name format\n" , vbd->name); -free (new); - err = -EINVAL ; - goto out; - } - - src +=sprintf (src,"VHD" ); -continue ; - } - -memcpy (src, dst, len +1 ); - src += len; - } - - *src ='\0' ; - - err =tapdisk_vbd_reactivate_volume (new); -if (err) -DPRINTF ("reactivating %s failed\n" , new); - - err =access (new,F_OK ); -if (err ==-1 ) { -EPRINTF ("neither %s nor %s accessible\n" , - vbd->name, new); - err = -errno; -free (new); - goto out; - } - -DPRINTF ("couldn't find %s, trying %s\n" , vbd->name, new); - - err =0 ; -free (vbd->name); - vbd->name = new; - vbd->type =DISK_TYPE_VHD ; - -out: -regfree (&re); -return err; - -regerr: -regerror (err, &re, error,sizeof (error)); -EPRINTF ("%s: regex failed: %s\n" , vbd->name, error); - err = -EINVAL ; - goto out; -} -/* TODO: ugh, lets not call it parent info... */ static struct list_head *tapdisk_vbd_open_level (td_vbd_t *vbd,char * params,int driver_type,td_disk_info_t *parent_info,td_flag_t flags)
@@ -658,10 +392,6 @@struct list_head *images;td_disk_info_t *parent_info =NULL ; - err =tapdisk_vbd_reactivate_volumes (vbd,0 ); -if (err) -return err; - flags = (vbd->flags & ~TD_OPEN_SHAREABLE ) | extra_flags;/* loop on each user specified driver.
@@ -1215,22 +945,10 @@ vbd->type = drivertype;for (i =0 ; i <TD_VBD_EIO_RETRIES ; i++) { - err =tapdisk_vbd_check_file (vbd); -if (err) - goto sleep; - - err =tapdisk_vbd_reactivate_volumes (vbd,1 ); -if (err) { -EPRINTF ("failed to reactivate %s: %d\n" , - vbd->name, err); - goto sleep; - } - err =__tapdisk_vbd_open_vdi (vbd,TD_OPEN_STRICT );if (!err)break ; - sleep:sleep (TD_VBD_EIO_SLEEP ); }
@@ -1887,12 +1605,6 @@tapdisk_vbd_start_queue (vbd); - err =tapdisk_vbd_reactivate_volumes (vbd,1 ); -if (err) { -EPRINTF ("failed to reactivate %s, %d\n" , vbd->name, err); - goto out; - } -for (i =0 ; i <TD_VBD_EIO_RETRIES ; i++) { err =__tapdisk_vbd_open_vdi (vbd,TD_OPEN_STRICT );if (err != -EIO )
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blktap2: Fix tapdisk disktype issues
In reply to Daniel StoddenStop coercing drivers/disktype code into the tool stack. Make both blktapctrl and tap-ctl transfer type/path pairs as "<type>:<path>" strings. Remove the message.disktype integer altogether.
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1275947595 25200
# Node ID 5f2119204138ad484ad7ffe0a8eff5c0d70d3f52 # Parent eb39271223ce6600cb81cf0dab8167a382d1393a
blktap2: Fix tapdisk disktype issues.
Stop coercing drivers/disktype code into the tool stack. Make both blktapctrl and tap-ctl transfer type/path pairs as "<type>:<path>" strings. Remove the message.disktype integer altogether.
tools/blktap2/drivers/Makefile +1 -0
@@ -77,6 +77,7 @@ TAP-OBJS-y += tapdisk-vbd.o TAP-OBJS-y += tapdisk-image.o TAP-OBJS-y += tapdisk-driver.o +TAP-OBJS-y += tapdisk-disktype.o TAP-OBJS-y += tapdisk-interface.o TAP-OBJS-y += tapdisk-server.o TAP-OBJS-y += tapdisk-queue.o
tools/blktap2/drivers/block-qcow.c +1 -0
@@ -41,6 +41,7 @@#include "tapdisk.h" #include "tapdisk-driver.h" #include "tapdisk-interface.h" +#include "tapdisk-disktype.h" #include "qcow.h" #include "blk.h" #include "atomicio.h"
tools/blktap2/drivers/block-remus.c +1 -0
@@ -98,6 +98,7 @@*/ td_vbd_t *device_vbd =NULL ;td_image_t *remus_image =NULL ; +struct tap_disk tapdisk_remus;struct ramdisk {size_t sector_size;
tools/blktap2/drivers/block-vhd.c +1 -0
@@ -58,6 +58,7 @@#include "tapdisk.h" #include "tapdisk-driver.h" #include "tapdisk-interface.h" +#include "tapdisk-disktype.h" unsigned int SPB ;
tools/blktap2/drivers/disktypes.h deleted +0 -197
197 lines not on this page · raw message
tools/blktap2/drivers/img2qcow.c +1 -0
@@ -49,6 +49,7 @@#include "tapdisk-server.h" #include "tapdisk-driver.h" #include "tapdisk-interface.h" +#include "tapdisk-disktype.h" #include "qcow.h" #include "blk.h"
tools/blktap2/drivers/qcow2raw.c +1 -0
@@ -47,6 +47,7 @@#include "tapdisk-server.h" #include "tapdisk-driver.h" #include "tapdisk-interface.h" +#include "tapdisk-disktype.h" #include "qcow.h" #if 1
tools/blktap2/drivers/tapdisk-diff.c +11 -8
@@ -38,6 +38,7 @@#include "scheduler.h" #include "tapdisk-vbd.h" #include "tapdisk-server.h" +#include "tapdisk-disktype.h" #include "libvhd.h" #define POLL_READ 0
@@ -670,11 +671,11 @@ tapdisk_stream_open(struct tapdisk_stream *s, const char *arg) { int err, type; -char *path; +const char *path; - err =tapdisk_parse_disk_type (arg, &path, &type); -if (err) -return err; + type =tapdisk_disktype_parse_params (arg, &path); +if (type <0 ) +return type;tapdisk_stream_initialize (s);
@@ -716,7 +717,8 @@ {int c, err, type1;const char *arg1 =NULL , *arg2 =NULL ; -char *path1; +const disk_info_t *info; +const char *path1; err =0 ;
@@ -741,9 +743,10 @@if (!arg1 || !arg2) goto fail_usage; - err =tapdisk_parse_disk_type (arg1, &path1, &type1); -if (err) -return err; + type1 =tapdisk_disktype_parse_params (arg1, &path1); +if (type1 <0 ) +return type1; +if (type1 !=DISK_TYPE_VHD ) {printf ("error: first VDI is not VHD\n" );return EINVAL ;
tools/blktap2/drivers/tapdisk-disktype.c new file +204 -0
204 lines not on this page · raw message
tools/blktap2/drivers/tapdisk-disktype.h new file +62 -0
62 lines not on this page · raw message
tools/blktap2/drivers/tapdisk-driver.c +3 -2
@@ -29,15 +29,16 @@#include "tapdisk-driver.h" #include "tapdisk-server.h" +#include "tapdisk-disktype.h" td_driver_t *tapdisk_driver_allocate (int type,char *name,td_flag_t flags,int storage) {int err;td_driver_t *driver; -struct tap_disk *ops; +const struct tap_disk *ops; - ops =tapdisk_server_find_driver_interface (type); + ops = tapdisk_disk_drivers[type];if (!ops)return NULL ;
tools/blktap2/drivers/tapdisk-driver.h +1 -1
@@ -47,7 +47,7 @@td_disk_info_t info;void *data; -struct tap_disk *ops; +const struct tap_disk *ops;struct list_head next; };
tools/blktap2/drivers/tapdisk-image.c +1 -1
@@ -39,7 +39,7 @@ #define ERR(_err, _f, _a...) tlog_error(_err, _f, ##_a)td_image_t * -tapdisk_image_allocate (char *file,int type,int storage, +tapdisk_image_allocate (const char *file,int type,int storage,td_flag_t flags,void *private) {int err;
tools/blktap2/drivers/tapdisk-image.h +1 -1
@@ -47,7 +47,7 @@struct list_head next; }; -td_image_t *tapdisk_image_allocate (char *,int ,int ,td_flag_t ,void *); +td_image_t *tapdisk_image_allocate (const char *,int ,int ,td_flag_t ,void *);void tapdisk_image_free (td_image_t *);int tapdisk_image_check_td_request (td_image_t *,td_request_t );
tools/blktap2/drivers/tapdisk-server.c +0 -13
@@ -32,7 +32,6 @@#include <sys/ioctl.h> #include <sys/signal.h> -#define TAPDISK #include "tapdisk-utils.h" #include "tapdisk-server.h" #include "tapdisk-driver.h"
@@ -46,18 +45,6 @@#define tapdisk_server_for_each_vbd (vbd, tmp) \ list_for_each_entry_safe(vbd, tmp, &server.vbds, next) -struct tap_disk * -tapdisk_server_find_driver_interface (int type) -{ -int n; - - n =sizeof (dtypes) /sizeof (struct disk_info_t *); -if (type >= n) -return NULL ; - -return dtypes[type]->drv; -} -td_image_t *tapdisk_server_get_shared_image (td_image_t *image) {
tools/blktap2/drivers/tapdisk-stream.c +7 -3
@@ -37,6 +37,7 @@#include "scheduler.h" #include "tapdisk-vbd.h" #include "tapdisk-server.h" +#include "tapdisk-disktype.h" #define POLL_READ 0#define POLL_WRITE 1
@@ -545,7 +546,9 @@ main(int argc, char *argv[]) { int c, err, type; -char *params, *path; +const char *params; +const disk_info_t *info; +const char *path;uint64_t count, skip;struct tapdisk_stream stream;
@@ -575,8 +578,9 @@if (!params)usage (argv[0 ],EINVAL ); - err =tapdisk_parse_disk_type (params, &path, &type); -if (err) { + type =tapdisk_disktype_parse_params (params, &path); +if (type <0 ) { + err = type;fprintf (stderr,"invalid argument %s: %d\n" , params, err);return err; }
tools/blktap2/drivers/tapdisk-utils.c +0 -40
@@ -40,7 +40,6 @@#include "blk.h" #include "tapdisk.h" -#include "disktypes.h" #include "blktaplib.h" #include "tapdisk-log.h" #include "tapdisk-utils.h"
@@ -108,45 +107,6 @@return 0 ; } -int -tapdisk_parse_disk_type (const char *params,char **_path,int *_type) -{ -int i, err, size, handle_len; -char *ptr, *path, handle[10 ]; - -if (strlen (params) +1 >=MAX_NAME_LEN ) -return -ENAMETOOLONG ; - - ptr =strchr (params,':' ); -if (!ptr) -return -EINVAL ; - - path = ptr +1 ; - - handle_len = ptr - params; -if (handle_len >sizeof (handle)) -return -ENAMETOOLONG ; - -memcpy (handle, params, handle_len); - handle[handle_len] ='\0' ; - - size =sizeof (dtypes) /sizeof (disk_info_t *); -for (i =0 ; i < size; i++) { -if (strncmp (handle, dtypes[i]->handle, handle_len)) -continue ; - -if (dtypes[i]->idnum ==-1 ) -return -ENODEV ; - - *_type = dtypes[i]->idnum; - *_path = path; - -return 0 ; - } - -return -ENODEV ; -} -/*Get Image size, secsize*/ int tapdisk_get_image_size (int fd,uint64_t *_sectors,uint32_t *_sector_size)
tools/blktap2/drivers/tapdisk-utils.h +0 -1
@@ -36,7 +36,6 @@void tapdisk_stop_logging (void );int tapdisk_set_resource_limits (void );int tapdisk_namedup (char **,const char *); -int tapdisk_parse_disk_type (const char *,char **,int *);int tapdisk_get_image_size (int ,uint64_t *,uint32_t *);int tapdisk_linux_version (void );
tools/blktap2/drivers/tapdisk-vbd.c +12 -13
@@ -43,6 +43,7 @@#include "tapdisk-driver.h" #include "tapdisk-server.h" #include "tapdisk-interface.h" +#include "tapdisk-disktype.h" #include "tapdisk-vbd.h" #include "blktap2.h"
@@ -282,9 +283,9 @@/* TODO: ugh, lets not call it parent info... */ static struct list_head * -tapdisk_vbd_open_level (td_vbd_t *vbd,char * params,int driver_type,td_disk_info_t *parent_info,td_flag_t flags) +tapdisk_vbd_open_level (td_vbd_t *vbd,const char * params,int driver_type,td_disk_info_t *parent_info,td_flag_t flags) { -char *name; +const char *name;int type, err;td_image_t *image;td_disk_id_t id;
@@ -294,19 +295,16 @@ images =calloc (1 ,sizeof (struct list_head ));INIT_LIST_HEAD (images); - name = params; - type = driver_type; + name = params; + id.name =NULL ; + type = driver_type;for (;;) { err = -ENOMEM ; image =tapdisk_image_allocate (name, type, vbd->storage, flags, vbd); -/* free 'name' if it was created by td_get_parent_id() */ -if (name != params) { -free (name); - name =NULL ; - } +free (id.name);if (!image)return NULL ;
@@ -382,7 +380,7 @@static int __tapdisk_vbd_open_vdi (td_vbd_t *vbd,td_flag_t extra_flags) { -char *file; +const char *file;int err, type;td_flag_t flags;td_disk_id_t id;
@@ -524,9 +522,9 @@ uint16_t drivertype, uint16_t storage, td_flag_t flags) { int i, err; -struct tap_disk *ops; +const struct tap_disk *ops; - ops =tapdisk_server_find_driver_interface (drivertype); + ops = tapdisk_disk_drivers[drivertype];if (!ops)return -EINVAL ; DPRINTF("Loaded %s driver for vbd %u %s 0x%08x\n",
@@ -1573,7 +1571,8 @@ tapdisk_vbd_resume_ring(td_vbd_t *vbd) {int i, err, type; -char *path, message[BLKTAP2_MAX_MESSAGE_LEN ]; +char message[BLKTAP2_MAX_MESSAGE_LEN ]; +const char *path;memset (message,0 ,sizeof (message));
tools/blktap2/drivers/tapdisk-vbd.h +1 -1
@@ -80,7 +80,7 @@ };struct td_vbd_driver_info { -char *params; +const char *params;int type;struct list_head next; };
tools/blktap2/drivers/tapdisk.h +0 -1
@@ -61,7 +61,6 @@#include "list.h" #include "blktaplib.h" -#include "disktypes.h" #include "tapdisk-log.h" #include "tapdisk-utils.h"
tools/blktap2/drivers/tapdisk2.c +2 -1
@@ -43,6 +43,7 @@#include "tapdisk-vbd.h" #include "tapdisk-utils.h" #include "tapdisk-server.h" +#include "tapdisk-disktype.h" #define TAPDISK2_VBD 0
@@ -327,7 +328,7 @@static int tapdisk2_create_device (const char *params) { -char *path; +const char *path;int err, type;chdir ("/" );
tools/blktap2/include/tapdisk-message.h +1 -1
@@ -28,6 +28,7 @@#define _TAPDISK_MESSAGE_H_#include <inttypes.h> +#include <sys/types.h> #define TAPDISK_MESSAGE_MAX_PATH_LENGTH 256#define TAPDISK_MESSAGE_STRING_LENGTH 256
@@ -67,7 +68,6 @@struct tapdisk_message {uint16_t type;uint16_t cookie; -uint16_t drivertype;union {pid_t tapdisk_pid;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blktap2: Fix E/DPRINTF defs all around the driver/ subdir
In reply to Daniel StoddenThis is just to avoid macro madness among subdirs sharing blktaplib.h.
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1275947595 25200
# Node ID d8393489b4c4d93944203f62578f8cf2721ce961 # Parent 5f2119204138ad484ad7ffe0a8eff5c0d70d3f52
blktap2: Fix E/DPRINTF defs all around the driver/ subdir.
This is just to avoid macro madness among subdirs sharing blktaplib.h.
tools/blktap2/drivers/block-remus.c +0 -1
@@ -33,7 +33,6 @@/* due to architectural choices in tapdisk, block-buffer is forced to * reimplement some code which is meant to be private */ -#define TAPDISK #include "tapdisk.h" #include "tapdisk-server.h" #include "tapdisk-driver.h"
tools/blktap2/drivers/img2qcow.c +0 -2
@@ -65,8 +65,6 @@#define O_LARGEFILE 0#endif - -#define TAPDISK 1#define BLOCK_PROCESSSZ 4096#define QCOW_VBD 0#define PROGRESS_QUANT 2
tools/blktap2/drivers/qcow2raw.c +0 -1
@@ -62,7 +62,6 @@#define O_LARGEFILE 0#endif -#define TAPDISK 1#define BLOCK_PROCESSSZ 4096#define QCOW_VBD 0#define AIO_VBD 1
tools/blktap2/drivers/tapdisk.h +4 -0
@@ -64,6 +64,10 @@#include "tapdisk-log.h" #include "tapdisk-utils.h" +#define DPRINTF(_f, _a...) syslog(LOG_INFO, _f, ##_a) +#define EPRINTF(_f, _a...) syslog(LOG_ERR, "tap-err:%s: " _f, __func__, ##_a) +#define PERROR(_f, _a...) EPRINTF(_f ": %s", ##_a, strerror(errno)) +#define MAX_SEGMENTS_PER_REQ 11#define SECTOR_SHIFT 9#define DEFAULT_SECTOR_SIZE 512
tools/blktap2/include/blktaplib.h +0 -9
@@ -36,15 +36,6 @@#include <xenctrl.h> #include <xen/io/blkif.h> -#if 1 -#define DPRINTF(_f, _a...) syslog(LOG_INFO, _f, ##_a) -#else -#define DPRINTF(_f, _a...) ((void)0) -#endif - -#define EPRINTF(_f, _a...) syslog(LOG_ERR, "tap-err:%s: " _f, __func__, ##_a) -#define PERROR(_f, _a...) EPRINTF(_f ": %s", ##_a, strerror(errno)) -#define BLK_RING_SIZE __CONST_RING_SIZE(blkif, XC_PAGE_SIZE)/* size of the extra VMA area to map in attached pages. */
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blktap2: Cleanup vdi stacking code
In reply to Daniel StoddenRemoves some rough edges, memory leakage (?), fixes __list_splice, ...
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1275947595 25200
# Node ID 3ea1751e3fe79c53acec392ee060b34491925235 # Parent d8393489b4c4d93944203f62578f8cf2721ce961
blktap2: Cleanup vdi stacking code.
Removes some rough edges, memory leakage (?), fixes __list_splice, ...
tools/blktap2/drivers/tapdisk-interface.c +10 -1
@@ -59,7 +59,7 @@ }int -td_open (td_image_t *image) +__td_open (td_image_t *image,td_disk_info_t *info) {int err;td_driver_t *driver;
@@ -72,6 +72,9 @@ image->storage);if (!driver)return -ENOMEM ; + +if (info)/* pre-seed driver->info for virtual drivers */ + driver->info = *info; }if (!td_flag_test (driver->state,TD_DRIVER_OPEN )) {
@@ -95,6 +98,12 @@ }int +td_open (td_image_t *image) +{ +return __td_open (image,NULL ); +} + +int td_close (td_image_t *image) {td_driver_t *driver;
tools/blktap2/drivers/tapdisk-interface.h +1 -0
@@ -32,6 +32,7 @@#include "tapdisk-queue.h" int td_open (td_image_t *); +int __td_open (td_image_t *,td_disk_info_t *);int td_load (td_image_t *);int td_close (td_image_t *);int td_get_parent_id (td_image_t *,td_disk_id_t *);
tools/blktap2/drivers/tapdisk-vbd.c +105 -98
313 lines not on this page · raw message
tools/blktap2/drivers/tapdisk-vbd.h +2 -1
@@ -80,7 +80,7 @@ };struct td_vbd_driver_info { -const char *params; +char *params;int type;struct list_head next; };
@@ -174,6 +174,7 @@int tapdisk_vbd_open (td_vbd_t *,const char *,uint16_t ,uint16_t ,const char *,td_flag_t );int tapdisk_vbd_close (td_vbd_t *); +void tapdisk_vbd_free_stack (td_vbd_t *);int tapdisk_vbd_open_vdi (td_vbd_t *,const char *,uint16_t ,uint16_t ,td_flag_t );
tools/blktap2/include/list.h +10 -9
@@ -87,24 +87,25 @@return list->next == head; } -static inline void __list_splice (struct list_head *list, -struct list_head *head) +static inline void __list_splice (const struct list_head *list, +struct list_head *prev, +struct list_head *next) {struct list_head *first = list->next;struct list_head *last = list->prev; -struct list_head *at = head->next; - first->prev = head; - head->next = first; + first->prev = prev; + prev->next = first; - last->next = at; - at->prev = last; + last->next = next; + next->prev = last; } -static inline void list_splice (struct list_head *list,struct list_head *head) +static inline void list_splice (const struct list_head *list, +struct list_head *head) {if (!list_empty (list)) -__list_splice (list, head); +__list_splice (list, head, head->next); }#define list_entry (ptr, type, member) \
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blktap2: The tap-ctl userspace control utility and library
In reply to Daniel StoddenTapdisk control in userspace, a replacement for the original blktap2 control stack, which had to pass a kernel space interface based on sysfs nodes.
All tapdisk processes listen for commands on a unix stream socket. The control library supports scanning the socket namespace for running tapdisks, VBD minors allocated, associated images and state inquiry.
Control operations include allocating/releasing devices, spawning tapdisks, opening/closing images, attaching disk images to devices. disk pause/resume operations and runtime switching of disk images.
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1275947596 25200
# Node ID ccef87cf5f4125061e46c7eb0d1483e6f369fb77 # Parent 3ea1751e3fe79c53acec392ee060b34491925235
blktap2: The tap-ctl userspace control utility and library.
Tapdisk control in userspace, a replacement for the original blktap2 control stack, which had to pass a kernel space interface based on sysfs nodes.
All tapdisk processes listen for commands on a unix stream socket. The control library supports scanning the socket namespace for running tapdisks, VBD minors allocated, associated images and state inquiry.
Control operations include allocating/releasing devices, spawning tapdisks, opening/closing images, attaching disk images to devices. disk pause/resume operations and runtime switching of disk images.
tools/blktap2/Makefile +1 -0
@@ -9,6 +9,7 @@ SUBDIRS-y += lvm SUBDIRS-y += vhd SUBDIRS-y += drivers +SUBDIRS-y += control clean: rm -rf *.a *.so *.o *.rpm $(LIB) *~ $(DEPS) TAGS
tools/blktap2/control/Makefile new file +57 -0
57 lines not on this page · raw message
tools/blktap2/control/tap-ctl-allocate.c new file +242 -0
242 lines not on this page · raw message
tools/blktap2/control/tap-ctl-attach.c new file +61 -0
61 lines not on this page · raw message
tools/blktap2/control/tap-ctl-check.c new file +79 -0
79 lines not on this page · raw message
tools/blktap2/control/tap-ctl-close.c new file +87 -0
87 lines not on this page · raw message
tools/blktap2/control/tap-ctl-create.c new file +65 -0
65 lines not on this page · raw message
tools/blktap2/control/tap-ctl-destroy.c new file +56 -0
56 lines not on this page · raw message
tools/blktap2/control/tap-ctl-detach.c new file +61 -0
61 lines not on this page · raw message
tools/blktap2/control/tap-ctl-free.c new file +54 -0
54 lines not on this page · raw message
tools/blktap2/control/tap-ctl-ipc.c new file +237 -0
237 lines not on this page · raw message
tools/blktap2/control/tap-ctl-list.c new file +506 -0
506 lines not on this page · raw message
tools/blktap2/control/tap-ctl-major.c new file +69 -0
69 lines not on this page · raw message
tools/blktap2/control/tap-ctl-open.c new file +75 -0
75 lines not on this page · raw message
tools/blktap2/control/tap-ctl-pause.c new file +59 -0
59 lines not on this page · raw message
tools/blktap2/control/tap-ctl-spawn.c new file +174 -0
174 lines not on this page · raw message
tools/blktap2/control/tap-ctl-unpause.c new file +64 -0
64 lines not on this page · raw message
tools/blktap2/control/tap-ctl.c new file +815 -0
815 lines not on this page · raw message
tools/blktap2/control/tap-ctl.h new file +101 -0
101 lines not on this page · raw message
tools/blktap2/drivers/Makefile +2 -2
@@ -12,8 +12,7 @@ CFLAGS += -Werror -g -O0 CFLAGS += -Wno-unused CFLAGS += -fno-strict-aliasing -CFLAGS += -I../lib -I../../libxc -CFLAGS += -I../include -I../../include +CFLAGS += -I$(BLKTAP_ROOT)/include -I$(BLKTAP_ROOT)/drivers CFLAGS += $(CFLAGS_libxenctrl) CFLAGS += -I $(LIBAIO_DIR) CFLAGS += -I $(MEMSHR_DIR)
@@ -75,6 +74,7 @@ TAP-OBJS-y := scheduler.o TAP-OBJS-y += tapdisk-vbd.o +TAP-OBJS-y += tapdisk-control.o TAP-OBJS-y += tapdisk-image.o TAP-OBJS-y += tapdisk-driver.o TAP-OBJS-y += tapdisk-disktype.o
tools/blktap2/drivers/blktap2.h deleted +0 -66
66 lines not on this page · raw message
tools/blktap2/drivers/tapdisk-control.c new file +836 -0
49 lines not on this page · raw message
tools/blktap2/drivers/tapdisk-control.h new file +35 -0
Lines of this file are not shown. View the raw message.
tools/blktap2/drivers/tapdisk-server.c +62 -23
85 lines not on this page · raw message
tools/blktap2/drivers/tapdisk-vbd.c +70 -31
101 lines not on this page · raw message
tools/blktap2/drivers/tapdisk2.c +59 -382
441 lines not on this page · raw message
tools/blktap2/include/blktap2.h new file +67 -0
67 lines not on this page · raw message
tools/blktap2/include/tapdisk-message.h +63 -1
64 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Part of the diff is not shown here. View the raw message.
PATCH 1/1 blktap2: Port Xend to the tap-ctl interface
In reply to Daniel Stodden# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1275947596 25200
# Node ID 7e76e35715c885549313acb55b06e607b8276ade # Parent ccef87cf5f4125061e46c7eb0d1483e6f369fb77
blktap2: Port Xend to the tap-ctl interface.
tools/python/xen/xend/XendDomainInfo.py +5 -21
@@ -63,7 +63,7 @@ from xen.xend.XendAPIConstants import * from xen.xend.XendCPUPool import XendCPUPool from xen.xend.server.DevConstants import xenbusState -from xen.xend.server.BlktapController import TAPDISK_DEVICE, parseDeviceString +from xen.xend.server.BlktapController import TapdiskController from xen.xend.XendVMMetrics import XendVMMetrics
@@ -549,15 +549,8 @@ dev = xstransact.List(self.vmpath + '/device/tap2') for x in dev: path = self.getDeviceController('tap2').readBackend(x, 'params') - if path and path.startswith(TAPDISK_DEVICE): - try: - _minor, _dev, ctrl = parseDeviceString(path) - #pause the disk - f = open(ctrl + '/pause', 'w') - f.write('pause'); - f.close() - except: - pass + if path and path.startswith(TapdiskController.TAP_DEV): + TapdiskController.pause(path) except Exception, ex: log.warn('Could not pause blktap disk.');
@@ -578,17 +571,8 @@ dev = xstransact.List(self.vmpath + '/device/tap2') for x in dev: path = self.getDeviceController('tap2').readBackend(x, 'params') - if path and path.startswith(TAPDISK_DEVICE): - try: - #Figure out the sysfs path. - _minor, _dev, ctrl = parseDeviceString(path) - #unpause the disk - if(os.path.exists(ctrl + '/resume')): - f = open(ctrl + '/resume', 'w'); - f.write('resume'); - f.close(); - except: - pass + if path and path.startswith(TapdiskController.TAP_DEV): + TapdiskController.unpause(path) except Exception, ex: log.warn('Could not unpause blktap disk: %s' % str(ex));
tools/python/xen/xend/server/BlktapController.py +115 -55
213 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [PATCH 7 of 7] blktap2: Port Xend to the tap-ctl interface
Quoted 3 lines · Daniel Stodden
Signed-off-by Jake Wires <[email protected]>
Presumably libxl needs corresponding changes? At the moment all my tapdisk processes are dying complaining about being passed a "-n" option.
J
Re: [PATCH 7 of 7] blktap2: Port Xend to the tap-ctl interface
Quoted 7 lines · Jeremy Fitzhardinge
Quoted 3 lines · Daniel Stodden
Signed-off-by Jake Wires <[email protected]>Presumably libxl needs corresponding changes? At the moment all my tapdisk processes are dying complaining about being passed a "-n" option.
Uh, oh. I never looked into that stuff.
Will see what it takes.
Anyone else maybe interested in doing that? No?
Daniel
Re: [PATCH 7 of 7] blktap2: Port Xend to the tap-ctl interface
Quoted 6 lines · Daniel Stodden
Quoted 5 lines · Jeremy Fitzhardinge
Quoted 3 lines · Daniel Stodden
Signed-off-by Jake Wires <[email protected]>
Quoted 8 lines
Quoted 2 lines
Presumably libxl needs corresponding changes? At the moment all my tapdisk processes are dying complaining about being passed a "-n" option.
Uh, oh. I never looked into that stuff.
Will see what it takes.
Anyone else maybe interested in doing that? No?
Does anyone have a sample config file flying around?
Thanks.
Daniel
Re: [PATCH 7 of 7] blktap2: Port Xend to the tap-ctl interface
Quoted 13 lines · Daniel Stodden
Quoted 11 lines · Daniel Stodden
Quoted 9 lines · Jeremy Fitzhardinge
Quoted 4 lines · Daniel Stodden
Signed-off-by Jake Wires <[email protected]>Presumably libxl needs corresponding changes? At the moment all my tapdisk processes are dying complaining about being passed a "-n" option.
Quoted 8 lines
Quoted 6 lines
Uh, oh. I never looked into that stuff.
Will see what it takes.
Anyone else maybe interested in doing that? No?
Does anyone have a sample config file flying around?
Stock xm ones should work almost as-is with xl, except you:
* need to specify a path to the config, as it doesn't default to /etc/xen
* remove all explicit python code and just leave the assignments
* use full paths for things like hvmloader
J
PATCH 1/1 libxl/blktap2
In reply to Jeremy FitzhardingeCheers,
Daniel
tools/blktap2/control/tap-ctl.c | 4 +- tools/blktap2/control/tap-ctl-list.c | 30 +++++++++++ tools/blktap2/control/tap-ctl.h | 1 + tools/Rules.mk | 4 + tools/blktap2/control/Makefile | 23 ++++++-- tools/blktap2/control/tap-ctl.h | 3 +- tools/libxl/Makefile | 4 +- tools/libxl/libxl.c | 93 ++++++++++------------------------- 8 files changed, 83 insertions(+), 79 deletions(-)
PATCH 1/1 blktap2: Fix broken tap-ctl-list type/path filter logic
tools/blktap2/control/tap-ctl.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1276140311 25200
# Node ID bbdfc4c5a31e26d23411a83edbef4a55ff904f2d # Parent 28af9eb507f2c315e53bb72c03399c7e69062787
blktap2: Fix broken tap-ctl-list type/path filter logic.
tools/blktap2/control/tap-ctl.c +2 -2
@@ -147,10 +147,10 @@if (pid >=0 && entry->pid != pid)continue ; -if (type && entry->type &&strcmp (entry->type, type)) +if (type && (!entry->type ||strcmp (entry->type, type)))continue ; -if (file && entry->path &&strcmp (entry->path, file)) +if (file && (!entry->path ||strcmp (entry->path, file)))continue ;if (tty)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blktap2: Add tap_ctl_find_minor
In reply to Daniel StoddenSlack 'tap-ctl find -t <type> -f <path>'.
tools/blktap2/control/tap-ctl-list.c | 30 ++++++++++++++++++++++++++++++ tools/blktap2/control/tap-ctl.h | 1 + 2 files changed, 31 insertions(+), 0 deletions(-)
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1276140316 25200
# Node ID 51ed44eb2e9f899d338d9ee9a88903ff3c4216f5 # Parent bbdfc4c5a31e26d23411a83edbef4a55ff904f2d
blktap2: Add tap_ctl_find_minor.
Slack 'tap-ctl find -t <type> -f <path>'.
tools/blktap2/control/tap-ctl-list.c +30 -0
@@ -504,3 +504,33 @@return err; } + +int +tap_ctl_find_minor (const char *type,const char *path) +{ +tap_list_t **list, **_entry; +int minor, err; + + err =tap_ctl_list (&list); +if (err) +return err; + + minor =-1 ; + +for (_entry = list; *_entry !=NULL ; ++_entry) { +tap_list_t *entry = *_entry; + +if (type && (!entry->type ||strcmp (entry->type, type))) +continue ; + +if (path && (!entry->path ||strcmp (entry->path, path))) +continue ; + + minor = entry->minor; +break ; + } + +tap_ctl_free_list (list); + +return minor >=0 ? minor : -ENOENT ; +}
tools/blktap2/control/tap-ctl.h +1 -0
@@ -77,6 +77,7 @@int tap_ctl_list (tap_list_t ***list);void tap_ctl_free_list (tap_list_t **list); +int tap_ctl_find_minor (const char *type,const char *path);int tap_ctl_allocate (int *minor,char **devname);int tap_ctl_free (const int minor);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 blktap2: Build libblktapctl.so
In reply to Daniel Stoddentools/Rules.mk | 4 ++++ tools/blktap2/control/Makefile | 23 ++++++++++++++++------- tools/blktap2/control/tap-ctl.h | 3 +-- 3 files changed, 21 insertions(+), 9 deletions(-)
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1276140319 25200
# Node ID 6237d4168baad956d987c26f3408749c1c557e18 # Parent 51ed44eb2e9f899d338d9ee9a88903ff3c4216f5
blktap2: Build libblktapctl.so
tools/Rules.mk +4 -0
@@ -13,6 +13,7 @@ XEN_LIBXC = $(XEN_ROOT)/tools/libxc XEN_XENSTORE = $(XEN_ROOT)/tools/xenstore XEN_LIBXENSTAT = $(XEN_ROOT)/tools/xenstat/libxenstat/src +XEN_BLKTAP2 = $(XEN_ROOT)/tools/blktap2 CFLAGS_include = -I$(XEN_INCLUDE)
@@ -25,6 +26,9 @@ CFLAGS_libxenstore = -I$(XEN_XENSTORE) $(CFLAGS_include) LDFLAGS_libxenstore = -L$(XEN_XENSTORE) -lxenstore +CFLAGS_libblktapctl = -I$(XEN_BLKTAP2)/control -I$(XEN_BLKTAP2)/include $(CFLAGS_include) +LDFLAGS_libblktapctl = -L$(XEN_BLKTAP2)/control -lblktapctl + X11_LDPATH = -L/usr/X11R6/$(LIBLEAFDIR) CFLAGS += -D__XEN_TOOLS__
tools/blktap2/control/Makefile +16 -7
@@ -30,25 +30,34 @@ CTL_OBJS += tap-ctl-major.o CTL_OBJS += tap-ctl-check.o -OBJS = $(CTL_OBJS) -LIBS = libblktapctl.a +CTL_PICS = $(patsubst %.o,%.opic,$(CTL_OBJS)) + +OBJS = $(CTL_OBJS) tap-ctl.o +PICS = $(CTL_PICS) + +LIBS = libblktapctl.a libblktapctl.so +IBIN = tap-ctl all: build -build: $(IBIN) +build: $(IBIN) $(LIBS) -tap-ctl: tap-ctl.o libblktapctl.a +tap-ctl: tap-ctl.o libblktapctl.so $(CC) $(CFLAGS) -o $@ $^ libblktapctl.a: $(CTL_OBJS) - ar r $@ $^ + $(AR) r $@ $^ -install: all +libblktapctl.so: $(CTL_PICS) + $(CC) $(CFLAGS) -fPIC -shared -rdynamic $^ -o $@ + +install: $(IBIN) $(LIBS) $(INSTALL_DIR) -p $(DESTDIR)$(SBINDIR) $(INSTALL_PROG) $(IBIN) $(DESTDIR)$(SBINDIR) + $(INSTALL_PROG) $(LIBS) $(DESTDIR)$(LIBDIR) clean: - rm -f $(OBJS) $(DEPS) $(IBIN) $(LIBS) + rm -f $(OBJS) $(PICS) $(DEPS) $(IBIN) $(LIBS) rm -f *~ .PHONY: all build clean install
tools/blktap2/control/tap-ctl.h +1 -2
@@ -30,8 +30,7 @@#include <syslog.h> #include <errno.h> - -#include "tapdisk-message.h" +#include <tapdisk-message.h> extern int tap_ctl_debug;
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
PATCH 1/1 libxl: Use libblktapctl.so
In reply to Daniel Stoddentools/libxl/Makefile | 4 +- tools/libxl/libxl.c | 93 +++++++++++++++------------------------------------ 2 files changed, 29 insertions(+), 68 deletions(-)
# HG changeset patch
# User Daniel Stodden <[email protected]> # Date 1276140349 25200
# Node ID 4b0360d2bba5ee673a866ac996176462214d3645 # Parent 6237d4168baad956d987c26f3408749c1c557e18
libxl: Use libblktapctl.so
tools/libxl/Makefile +2 -2
@@ -13,9 +13,9 @@ CFLAGS += -Werror CFLAGS += -I. -fPIC -CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) +CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl) -LIBS = $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore) +LIBS = $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore) $(LDFLAGS_libblktapctl) LIBXL_OBJS-y = osdeps.o libxl_paths.o LIBXL_OBJS = flexarray.o libxl.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o xenguest.o libxl_utils.o $(LIBXL_OBJS-y)
tools/libxl/libxl.c +27 -66
121 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [PATCH 4 of 4] libxl: Use libblktapctl.so
Quoted 1 line · Daniel Stodden
Signed-off-by Daniel Stodden <[email protected]>
This patch broke file: and tap:aio support in xl/libxl. Did you actually test it?
Re: [PATCH 4 of 4] libxl: Use libblktapctl.so
Quoted 5 lines · Stefano Stabellini
Quoted 1 line · Daniel Stodden
Signed-off-by Daniel Stodden <[email protected]>This patch broke file: and tap:aio support in xl/libxl. Did you actually test it?
Yes. Worked for for a couple runs.
Daniel
Re: [PATCH 4 of 4] libxl: Use libblktapctl.so
In reply to Daniel StoddenQuoted 23 lines
tools/libxl/libxl.c +2
-19-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); - } - }
tools/libxl/libxl.c line 1263
Quoted 10 lines
tools/libxl/libxl.c +7
-2-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.
Quoted 41 lines
int
libxl_device_disk_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk)tools/libxl/libxl.c +3
-32@@ -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)) {
tools/libxl/libxl.c line 1325
Quoted 10 lines
tools/libxl/libxl.c +7
-0+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...
Re: [PATCH 4 of 4] libxl: Use libblktapctl.so
Quoted 28 lines · Stefano Stabellini
Quoted 28 lines
tools/libxl/libxl.c +6
-21-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 ;
Quoted 8 lines
tools/libxl/libxl.c line 1263
Quoted 5 lines
tools/libxl/libxl.c +3
-0+ 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.
I'll send an update. Sorry for that. Please don't hesitate to submit corrections right away if you spot more issues.
Quoted 17 lines
dev = buf;Quoted 5 lines
tools/libxl/libxl.c +3
-1- } +case PHYSTYPE_AIO :case PHYSTYPE_QCOW :case PHYSTYPE_QCOW2 :case PHYSTYPE_VHD : { +const char *msg; +if (!tap_ctl_check (&msg)) {tools/libxl/libxl.c line 1325
Quoted 10 lines
tools/libxl/libxl.c +7
-0+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" );
Quoted 2 lines
you are calling
make_blktap2_deviceonly if(!dev), are you sure it is correct?get_blktap2_devicereturns a pointer on success...
I don't quite manage to follow this comment. The behavior was meant to match the original version of that code. It still looks like it does. Is that what you question?
Unless you're worried about null pointer handling with massively broken compilers? Did you ever manage to find one? I didn't %-)
But again, if you're not happy with it, please just go ahead and make it suit your coding preferences. I got zero stakes in that code.
Btw, someone probably should also fix the device teardown path as well, it seems to be consistently leaking device nodes. I guess enumerating backend physical-device nodes to count vbds would probably do for a 'light' control layer.
Thanks for the input.
Daniel
Re: [PATCH 4 of 4] libxl: Use libblktapctl.so
Quoted 10 lines · Daniel Stodden
I don't quite manage to follow this comment. The behavior was meant to match the original version of that code. It still looks like it does. Is that what you question?
Unless you're worried about null pointer handling with massively broken compilers? Did you ever manage to find one? I didn't %-)
But again, if you're not happy with it, please just go ahead and make it suit your coding preferences. I got zero stakes in that code.
Nope, you are right, after a second look the code seems correct. However it still doesn't work for me.
The device returned by make_blktap2_device is /dev/xen/blktap-2/tapdev0, but "cat /sys/class/blktap2/devices" returns nothing and my VM doesn't start.
Am I missing something?
Quoted 5 lines
Btw, someone probably should also fix the device teardown path as well, it seems to be consistently leaking device nodes. I guess enumerating backend physical-device nodes to count vbds would probably do for a 'light' control layer.
you are right, are you volunteering ? ;-)
Re: [PATCH 4 of 4] libxl: Use libblktapctl.so
Quoted 12 lines · Stefano Stabellini
Quoted 10 lines · Daniel Stodden
I don't quite manage to follow this comment. The behavior was meant to match the original version of that code. It still looks like it does. Is that what you question?
Unless you're worried about null pointer handling with massively broken compilers? Did you ever manage to find one? I didn't %-)
But again, if you're not happy with it, please just go ahead and make it suit your coding preferences. I got zero stakes in that code.
Quoted 6 lines
Nope, you are right, after a second look the code seems correct. However it still doesn't work for me.
The device returned bymake_blktap2_deviceis/dev/xen/blktap-2/tapdev0, but "cat/sys/class/blktap2/devices" returns nothing and my VM doesn't start.
Am I missing something?
Yes, I was missing something: my tapdisk2 was outdated, everything works now.
Quoted 34 lines · On Monday 07 June 2010 23:54:47 Daniel Stodden wrote:
Hi.
Apart from removing some dead code and tidying up tapdisk-vbd a little, the bigger introduces our new tap-ctl utility code.
The code aims to be a complete replacement for the original blktap2 control path, run through sysfs. Fully implemented in userspace, all tapdisks now gained a small IPC layer on top of Unix domain sockets.
Sample usage:
# tap-ctl allocate /dev/xen/blktap-2/tapdev0# tap-ctl spawn tapdisk spawned with pid 4168# tap-ctl list 4168 - - - - - 0 - - -# tap-ctl attach -p 4168 -m 0 # tap-ctl list 4168 0 0 - -# tap-ctl open -p 4168 -m 0 -a aio:/var/tmp/lenny.ext# tap-ctl list 4168 0 0 aio /var/tmp/lenny.ext# tap-ctl close -p 4168 -m 0 # tap-ctl detach -p 4168 -m 0 # tap-ctl free -m 0
Quoted 8 lines
The above example is a bit noisy, because it's mediating between minor number (block devices), tapdisks and tapdisk VBDs (the tapdisk I/O queue running a bdev) in detail.
There are shortcuts. At the same time, the low-level interface should be general enough to stay extensible, and help accomodate some of the more esoteric features, like shared images and/or multiple VBDs sharing the same tapdisk.
I think README file should be also updated.
And maybe its good idea to merge it to xen 4.0?
--
Łukasz Oleś