Skip to contentSkip to conversation

blktap2 updates

PATCH In review Daniel Stodden 3 participants 23 messages Mar 9, 2011 – Mar 10, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Please pull upstream/xen/dom0/backend/blktap2 at
git://xenbits.xensource.com/people/dstodden/linux.git

Summary:

- Move blktap to drivers/block
- Takes a .config update setting BLK_DEV_TAP
- Redo the ABI definitions, in linux/blktap.h

- Some prerequisites for new commands, such as cache flushing and trim support. Plus more device configuration driven from userspace, such as setting physical sector sizes.

- a new CREATE_DEVICE ioctls to flag extensions, like the above mentioned ones.

- Bugfix from Dominic Curran (Fix reference to freed struct request).

Thanks,
Daniel

#1 lore raw

PATCH 1/10 blktap: Add include/linux/blktap.h

Moves blktap2 definitions into a common header file.

Includes xen/interface/io/ring.h and new ring definitions. Makes blktap build independently from xen-devel headers.

New blktap_ring structs are fully congrent to blkif rings, for binary compat.

---
 drivers/xen/blktap/blktap.h  |   66 ++++----------------------------
 drivers/xen/blktap/control.c |   14 +++---
 drivers/xen/blktap/device.c  |   12 +++---
 drivers/xen/blktap/request.c |    8 ++--
 drivers/xen/blktap/ring.c    |   51 ++++++++++++++-----------
 drivers/xen/blktap/sysfs.c   |    6 +-
 include/linux/blktap.h       |   85 ++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 142 insertions(+), 100 deletions(-)
 create mode 100644 include/linux/blktap.h
drivers/xen/blktap/blktap.h +9 -57
index fe63fc9..1318cad 100644
@@ -6,7 +6,7 @@
 #include <linux/cdev.h>
 #include <linux/init.h>
 #include <linux/scatterlist.h>
-#include <xen/blkif.h>
+#include <linux/blktap.h>
 
 extern int blktap_debug_level;
 extern int blktap_ring_major;
@@ -30,74 +30,26 @@ extern int blktap_device_major;
 #define BLKTAP_DEVICE_CLOSED         5
 #define BLKTAP_SHUTDOWN_REQUESTED    8
 
-/* blktap IOCTLs: */
-#define BLKTAP2_IOCTL_KICK_FE        1
-#define BLKTAP2_IOCTL_ALLOC_TAP      200
-#define BLKTAP2_IOCTL_FREE_TAP       201
-#define BLKTAP2_IOCTL_CREATE_DEVICE  202
-#define BLKTAP2_IOCTL_REMOVE_DEVICE  207
-
-#define BLKTAP2_MAX_MESSAGE_LEN      256
-
-#define BLKTAP2_RING_MESSAGE_CLOSE   3
-
 #define BLKTAP_REQUEST_FREE          0
 #define BLKTAP_REQUEST_PENDING       1
 
-/*
- * The maximum number of requests that can be outstanding at any time
- * is determined by
- *
- *   [mmap_alloc * MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST] 
- *
- * where mmap_alloc < MAX_DYNAMIC_MEM.
- *
- * TODO:
- * mmap_alloc is initialised to 2 and should be adjustable on the fly via
- * sysfs.
- */
-#define BLK_RING_SIZE		__RING_SIZE((struct blkif_sring *)0, PAGE_SIZE)
-#define MAX_DYNAMIC_MEM		BLK_RING_SIZE
-#define MAX_PENDING_REQS	BLK_RING_SIZE
-#define MMAP_PAGES (MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST)
-#define MMAP_VADDR(_start, _req, _seg)					\
-        (_start +                                                       \
-         ((_req) * BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE) +        \
-         ((_seg) * PAGE_SIZE))
-
-struct grant_handle_pair {
-	grant_handle_t                 kernel;
-	grant_handle_t                 user;
-};
-#define INVALID_GRANT_HANDLE           0xFFFF
-
-struct blktap_handle {
-	unsigned int                   ring;
-	unsigned int                   device;
-	unsigned int                   minor;
-};
-
-struct blktap_params {
-	char                           name[BLKTAP2_MAX_MESSAGE_LEN];
-	unsigned long long             capacity;
-	unsigned long                  sector_size;
-};
-
 struct blktap_device {
 	spinlock_t                     lock;
 	struct gendisk                *gd;
 };
 
+struct blktap_request;
+
 struct blktap_ring {
 	struct task_struct            *task;
 
 	struct vm_area_struct         *vma;
-	struct blkif_front_ring        ring;
+	blktap_front_ring_t            ring;
 	unsigned long                  ring_vstart;
 	unsigned long                  user_vstart;
 
 	int                            n_pending;
-	struct blktap_request         *pending[MAX_PENDING_REQS];
+	struct blktap_request         *pending[BLKTAP_RING_SIZE];
 
 	wait_queue_head_t              poll_wait;
 
@@ -128,8 +80,8 @@ struct blktap_request {
 	int                            operation;
 	struct timeval                 time;
 
-	struct scatterlist             sg_table[BLKIF_MAX_SEGMENTS_PER_REQUEST];
-	struct page                   *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST];
+	struct scatterlist             sg_table[BLKTAP_SEGMENT_MAX];
+	struct page                   *pages[BLKTAP_SEGMENT_MAX];
 	int                            nr_pages;
 };
 
@@ -148,7 +100,7 @@ struct blktap {
 
 	wait_queue_head_t              remove_wait;
 	struct work_struct             remove_work;
-	char                           name[BLKTAP2_MAX_MESSAGE_LEN];
+	char                           name[BLKTAP_NAME_MAX];
 
 	struct blktap_statistics       stats;
 };
@@ -189,7 +141,7 @@ void blktap_sysfs_destroy(struct blktap *);
 int blktap_device_init(void);
 void blktap_device_exit(void);
 size_t blktap_device_debug(struct blktap *, char *, size_t);
-int blktap_device_create(struct blktap *, struct blktap_params *);
+int blktap_device_create(struct blktap *, struct blktap_device_info *);
 int blktap_device_destroy(struct blktap *);
 void blktap_device_destroy_sync(struct blktap *);
 void blktap_device_run_queue(struct blktap *);
drivers/xen/blktap/control.c +7 -7
index f339bba..57b1a10 100644
@@ -127,19 +127,19 @@ blktap_control_ioctl(struct inode *inode, struct file *filp,
 	struct blktap *tap;
 
 	switch (cmd) {
-	case BLKTAP2_IOCTL_ALLOC_TAP: {
-		struct blktap_handle h;
+	case BLKTAP_IOCTL_ALLOC_TAP: {
+		struct blktap_info info;
 		void __user *ptr = (void __user*)arg;
 
 		tap = blktap_control_create_tap();
 		if (!tap)
 			return -ENOMEM;
 
-		h.ring   = blktap_ring_major;
-		h.device = blktap_device_major;
-		h.minor  = tap->minor;
+		info.ring_major = blktap_ring_major;
+		info.bdev_major = blktap_device_major;
+		info.ring_minor = tap->minor;
 
-		if (copy_to_user(ptr, &h, sizeof(h))) {
+		if (copy_to_user(ptr, &info, sizeof(info))) {
 			blktap_control_destroy_tap(tap);
 			return -EFAULT;
 		}
@@ -147,7 +147,7 @@ blktap_control_ioctl(struct inode *inode, struct file *filp,
 		return 0;
 	}
 
-	case BLKTAP2_IOCTL_FREE_TAP: {
+	case BLKTAP_IOCTL_FREE_TAP: {
 		int minor = arg;
 
 		if (minor > MAX_BLKTAP_DEVICE)
drivers/xen/blktap/device.c +6 -6
index fce2769..6bb04bd 100644
@@ -186,7 +186,7 @@ blktap_device_make_request(struct blktap *tap, struct request *rq)
 		write ? 'w' : 'r', blk_rq_bytes(rq), nsegs);
 
 	request->rq = rq;
-	request->operation = write ? BLKIF_OP_WRITE : BLKIF_OP_READ;
+	request->operation = write ? BLKTAP_OP_WRITE : BLKTAP_OP_READ;
 
 	err = blktap_request_get_pages(tap, request, nsegs);
 	if (err)
@@ -276,7 +276,7 @@ blktap_device_do_request(struct request_queue *rq)
 
 static void
 blktap_device_configure(struct blktap *tap,
-			struct blktap_params *params)
+			struct blktap_device_info *params)
 {
 	struct request_queue *rq;
 	struct blktap_device *dev = &tap->device;
@@ -297,8 +297,8 @@ blktap_device_configure(struct blktap *tap,
 	blk_queue_max_segment_size(rq, PAGE_SIZE);
 
 	/* Ensure a merged request will fit in a single I/O ring slot. */
-	blk_queue_max_phys_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST);
-	blk_queue_max_hw_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST);
+	blk_queue_max_phys_segments(rq, BLKTAP_SEGMENT_MAX);
+	blk_queue_max_hw_segments(rq, BLKTAP_SEGMENT_MAX);
 
 	/* Make sure buffer addresses are sector-aligned. */
 	blk_queue_dma_alignment(rq, 511);
@@ -311,7 +311,7 @@ blktap_device_configure(struct blktap *tap,
 
 static int
 blktap_device_validate_params(struct blktap *tap,
-			      struct blktap_params *params)
+			      struct blktap_device_info *params)
 {
 	struct device *dev = tap->ring.dev;
 	int sector_order, name_sz;
@@ -425,7 +425,7 @@ blktap_device_destroy_sync(struct blktap *tap)
 }
 
 int
-blktap_device_create(struct blktap *tap, struct blktap_params *params)
+blktap_device_create(struct blktap *tap, struct blktap_device_info *params)
 {
 	int minor, err;
 	struct gendisk *gd;
drivers/xen/blktap/request.c +4 -4
index 9bef48c..8cfd6c9 100644
@@ -7,18 +7,18 @@
 #include "blktap.h"
 
 /* max pages per shared pool. just to prevent accidental dos. */
-#define POOL_MAX_PAGES           (256*BLKIF_MAX_SEGMENTS_PER_REQUEST)
+#define POOL_MAX_PAGES           (256*BLKTAP_SEGMENT_MAX)
 
 /* default page pool size. when considering to shrink a shared pool,
  * note that paused tapdisks may grab a whole lot of pages for a long
  * time. */
-#define POOL_DEFAULT_PAGES       (2 * MMAP_PAGES)
+#define POOL_DEFAULT_PAGES       (2 * BLKTAP_RING_SIZE * BLKTAP_SEGMENT_MAX)
 
 /* max number of pages allocatable per request. */
-#define POOL_MAX_REQUEST_PAGES   BLKIF_MAX_SEGMENTS_PER_REQUEST
+#define POOL_MAX_REQUEST_PAGES   BLKTAP_SEGMENT_MAX
 
 /* min request structs per pool. These grow dynamically. */
-#define POOL_MIN_REQS            BLK_RING_SIZE
+#define POOL_MIN_REQS            BLKTAP_RING_SIZE
 
 static struct kset *pool_set;
 
drivers/xen/blktap/ring.c +28 -23

171 lines not on this page · raw message

drivers/xen/blktap/sysfs.c +3 -3
index 7bbfea8..182de9a 100644
@@ -20,7 +20,7 @@ blktap_sysfs_set_name(struct device *dev, struct device_attribute *attr, const c
 	if (!tap)
 		return 0;
 
-	if (size >= BLKTAP2_MAX_MESSAGE_LEN)
+	if (size >= BLKTAP_NAME_MAX)
 		return -ENAMETOOLONG;
 
 	if (strnlen(buf, size) != size)
@@ -75,8 +75,8 @@ blktap_sysfs_remove_device(struct device *dev,
 		goto wait;
 
 	if (tap->ring.vma) {
-		blkif_sring_t *sring = tap->ring.ring.sring;
-		sring->private.tapif_user.msg = BLKTAP2_RING_MESSAGE_CLOSE;
+		blktap_sring_t *sring = tap->ring.ring.sring;
+		sring->private.tapif_user.msg = BLKTAP_RING_MESSAGE_CLOSE;
 		blktap_ring_kick_user(tap);
 	} else {
 		INIT_WORK(&tap->remove_work, blktap_sysfs_remove_work);
include/linux/blktap.h new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#2 lore raw

Re: [PATCH 01/10] blktap: Add include/linux/blktap.h

Quoted 9 lines · Daniel Stodden

Moves blktap2 definitions into a common header file.

Includes xen/interface/io/ring.h and new ring definitions. Makes blktap build independently from xen-devel headers.

New blktap_ring structs are fully congrent to blkif rings, for binary compat.

Quoted 8 lines
---
 drivers/xen/blktap/blktap.h  |   66 ++++----------------------------
 drivers/xen/blktap/control.c |   14 +++---
 drivers/xen/blktap/device.c  |   12 +++---
 drivers/xen/blktap/request.c |    8 ++--
 drivers/xen/blktap/ring.c    |   51 ++++++++++++++-----------
 drivers/xen/blktap/sysfs.c   |    6 +-
 include/linux/blktap.h       |   85 ++++++++++++++++++++++++++++++++++++++++++

This new file defines the kernel<->user (tapdisk process) ring protocol, right?

I think its proper home would be under include/xen somewhere, which is where the gntdev and evtchn etc driver interfaces are defined.

Where is the canonical definition of this interface stored? In the kernel tree or the hypervisor tree?

Ian.

Quoted 555 lines
 7 files changed, 142 insertions(+), 100 deletions(-)
 create mode 100644 include/linux/blktap.h
drivers/xen/blktap/blktap.h +9 -57
index fe63fc9..1318cad 100644
@@ -6,7 +6,7 @@
 #include <linux/cdev.h>
 #include <linux/init.h>
 #include <linux/scatterlist.h>
-#include <xen/blkif.h>
+#include <linux/blktap.h>
 
 extern int blktap_debug_level;
 extern int blktap_ring_major;
@@ -30,74 +30,26 @@ extern int blktap_device_major;
 #define BLKTAP_DEVICE_CLOSED         5
 #define BLKTAP_SHUTDOWN_REQUESTED    8
 
-/* blktap IOCTLs: */
-#define BLKTAP2_IOCTL_KICK_FE        1
-#define BLKTAP2_IOCTL_ALLOC_TAP      200
-#define BLKTAP2_IOCTL_FREE_TAP       201
-#define BLKTAP2_IOCTL_CREATE_DEVICE  202
-#define BLKTAP2_IOCTL_REMOVE_DEVICE  207
-
-#define BLKTAP2_MAX_MESSAGE_LEN      256
-
-#define BLKTAP2_RING_MESSAGE_CLOSE   3
-
 #define BLKTAP_REQUEST_FREE          0
 #define BLKTAP_REQUEST_PENDING       1
 
-/*
- * The maximum number of requests that can be outstanding at any time
- * is determined by
- *
- *   [mmap_alloc * MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST]
- *
- * where mmap_alloc < MAX_DYNAMIC_MEM.
- *
- * TODO:
- * mmap_alloc is initialised to 2 and should be adjustable on the fly via
- * sysfs.
- */
-#define BLK_RING_SIZE          __RING_SIZE((struct blkif_sring *)0, PAGE_SIZE)
-#define MAX_DYNAMIC_MEM                BLK_RING_SIZE
-#define MAX_PENDING_REQS       BLK_RING_SIZE
-#define MMAP_PAGES (MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST)
-#define MMAP_VADDR(_start, _req, _seg)                                 \
-        (_start +                                                       \
-         ((_req) * BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE) +        \
-         ((_seg) * PAGE_SIZE))
-
-struct grant_handle_pair {
-       grant_handle_t                 kernel;
-       grant_handle_t                 user;
-};
-#define INVALID_GRANT_HANDLE           0xFFFF
-
-struct blktap_handle {
-       unsigned int                   ring;
-       unsigned int                   device;
-       unsigned int                   minor;
-};
-
-struct blktap_params {
-       char                           name[BLKTAP2_MAX_MESSAGE_LEN];
-       unsigned long long             capacity;
-       unsigned long                  sector_size;
-};
-
 struct blktap_device {
        spinlock_t                     lock;
        struct gendisk                *gd;
 };
 
+struct blktap_request;
+
 struct blktap_ring {
        struct task_struct            *task;
 
        struct vm_area_struct         *vma;
-       struct blkif_front_ring        ring;
+       blktap_front_ring_t            ring;
        unsigned long                  ring_vstart;
        unsigned long                  user_vstart;
 
        int                            n_pending;
-       struct blktap_request         *pending[MAX_PENDING_REQS];
+       struct blktap_request         *pending[BLKTAP_RING_SIZE];
 
        wait_queue_head_t              poll_wait;
 
@@ -128,8 +80,8 @@ struct blktap_request {
        int                            operation;
        struct timeval                 time;
 
-       struct scatterlist             sg_table[BLKIF_MAX_SEGMENTS_PER_REQUEST];
-       struct page                   *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST];
+       struct scatterlist             sg_table[BLKTAP_SEGMENT_MAX];
+       struct page                   *pages[BLKTAP_SEGMENT_MAX];
        int                            nr_pages;
 };
 
@@ -148,7 +100,7 @@ struct blktap {
 
        wait_queue_head_t              remove_wait;
        struct work_struct             remove_work;
-       char                           name[BLKTAP2_MAX_MESSAGE_LEN];
+       char                           name[BLKTAP_NAME_MAX];
 
        struct blktap_statistics       stats;
 };
@@ -189,7 +141,7 @@ void blktap_sysfs_destroy(struct blktap *);
 int blktap_device_init(void);
 void blktap_device_exit(void);
 size_t blktap_device_debug(struct blktap *, char *, size_t);
-int blktap_device_create(struct blktap *, struct blktap_params *);
+int blktap_device_create(struct blktap *, struct blktap_device_info *);
 int blktap_device_destroy(struct blktap *);
 void blktap_device_destroy_sync(struct blktap *);
 void blktap_device_run_queue(struct blktap *);
drivers/xen/blktap/control.c +7 -7
index f339bba..57b1a10 100644
@@ -127,19 +127,19 @@ blktap_control_ioctl(struct inode *inode, struct file *filp,
        struct blktap *tap;
 
        switch (cmd) {
-       case BLKTAP2_IOCTL_ALLOC_TAP: {
-               struct blktap_handle h;
+       case BLKTAP_IOCTL_ALLOC_TAP: {
+               struct blktap_info info;
                void __user *ptr = (void __user*)arg;
 
                tap = blktap_control_create_tap();
                if (!tap)
                        return -ENOMEM;
 
-               h.ring   = blktap_ring_major;
-               h.device = blktap_device_major;
-               h.minor  = tap->minor;
+               info.ring_major = blktap_ring_major;
+               info.bdev_major = blktap_device_major;
+               info.ring_minor = tap->minor;
 
-               if (copy_to_user(ptr, &h, sizeof(h))) {
+               if (copy_to_user(ptr, &info, sizeof(info))) {
                        blktap_control_destroy_tap(tap);
                        return -EFAULT;
                }
@@ -147,7 +147,7 @@ blktap_control_ioctl(struct inode *inode, struct file *filp,
                return 0;
        }
 
-       case BLKTAP2_IOCTL_FREE_TAP: {
+       case BLKTAP_IOCTL_FREE_TAP: {
                int minor = arg;
 
                if (minor > MAX_BLKTAP_DEVICE)
drivers/xen/blktap/device.c +6 -6
index fce2769..6bb04bd 100644
@@ -186,7 +186,7 @@ blktap_device_make_request(struct blktap *tap, struct request *rq)
                write ? 'w' : 'r', blk_rq_bytes(rq), nsegs);
 
        request->rq = rq;
-       request->operation = write ? BLKIF_OP_WRITE : BLKIF_OP_READ;
+       request->operation = write ? BLKTAP_OP_WRITE : BLKTAP_OP_READ;
 
        err = blktap_request_get_pages(tap, request, nsegs);
        if (err)
@@ -276,7 +276,7 @@ blktap_device_do_request(struct request_queue *rq)
 
 static void
 blktap_device_configure(struct blktap *tap,
-                       struct blktap_params *params)
+                       struct blktap_device_info *params)
 {
        struct request_queue *rq;
        struct blktap_device *dev = &tap->device;
@@ -297,8 +297,8 @@ blktap_device_configure(struct blktap *tap,
        blk_queue_max_segment_size(rq, PAGE_SIZE);
 
        /* Ensure a merged request will fit in a single I/O ring slot. */
-       blk_queue_max_phys_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST);
-       blk_queue_max_hw_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST);
+       blk_queue_max_phys_segments(rq, BLKTAP_SEGMENT_MAX);
+       blk_queue_max_hw_segments(rq, BLKTAP_SEGMENT_MAX);
 
        /* Make sure buffer addresses are sector-aligned. */
        blk_queue_dma_alignment(rq, 511);
@@ -311,7 +311,7 @@ blktap_device_configure(struct blktap *tap,
 
 static int
 blktap_device_validate_params(struct blktap *tap,
-                             struct blktap_params *params)
+                             struct blktap_device_info *params)
 {
        struct device *dev = tap->ring.dev;
        int sector_order, name_sz;
@@ -425,7 +425,7 @@ blktap_device_destroy_sync(struct blktap *tap)
 }
 
 int
-blktap_device_create(struct blktap *tap, struct blktap_params *params)
+blktap_device_create(struct blktap *tap, struct blktap_device_info *params)
 {
        int minor, err;
        struct gendisk *gd;
drivers/xen/blktap/request.c +4 -4
index 9bef48c..8cfd6c9 100644
@@ -7,18 +7,18 @@
 #include "blktap.h"
 
 /* max pages per shared pool. just to prevent accidental dos. */
-#define POOL_MAX_PAGES           (256*BLKIF_MAX_SEGMENTS_PER_REQUEST)
+#define POOL_MAX_PAGES           (256*BLKTAP_SEGMENT_MAX)
 
 /* default page pool size. when considering to shrink a shared pool,
  * note that paused tapdisks may grab a whole lot of pages for a long
  * time. */
-#define POOL_DEFAULT_PAGES       (2 * MMAP_PAGES)
+#define POOL_DEFAULT_PAGES       (2 * BLKTAP_RING_SIZE * BLKTAP_SEGMENT_MAX)
 
 /* max number of pages allocatable per request. */
-#define POOL_MAX_REQUEST_PAGES   BLKIF_MAX_SEGMENTS_PER_REQUEST
+#define POOL_MAX_REQUEST_PAGES   BLKTAP_SEGMENT_MAX
 
 /* min request structs per pool. These grow dynamically. */
-#define POOL_MIN_REQS            BLK_RING_SIZE
+#define POOL_MIN_REQS            BLKTAP_RING_SIZE
 
 static struct kset *pool_set;
 
drivers/xen/blktap/ring.c +28 -23
index 6b86be5..9442a64 100644
@@ -18,7 +18,7 @@ static struct cdev blktap_ring_cdev;
 
 static void
 blktap_ring_read_response(struct blktap *tap,
-                    const struct blkif_response *rsp)
+                         const blktap_ring_rsp_t *rsp)
 {
        struct blktap_ring *ring = &tap->ring;
        struct blktap_request *request;
@@ -27,7 +27,7 @@ blktap_ring_read_response(struct blktap *tap,
        request = NULL;
 
        usr_idx = rsp->id;
-       if (usr_idx < 0 || usr_idx >= MAX_PENDING_REQS) {
+       if (usr_idx < 0 || usr_idx >= BLKTAP_RING_SIZE) {
                err = -ERANGE;
                goto invalid;
        }
@@ -48,7 +48,7 @@ blktap_ring_read_response(struct blktap *tap,
                "request %d [%p] response: %d\n",
                request->usr_idx, request, rsp->status);
 
-       err = rsp->status == BLKIF_RSP_OKAY ? 0 : -EIO;
+       err = rsp->status == BLKTAP_RSP_OKAY ? 0 : -EIO;
 end_request:
        blktap_device_end_request(tap, request, err);
        return;
@@ -67,7 +67,7 @@ static void
 blktap_read_ring(struct blktap *tap)
 {
        struct blktap_ring *ring = &tap->ring;
-       struct blkif_response rsp;
+       blktap_ring_rsp_t rsp;
        RING_IDX rc, rp;
 
        down_read(&current->mm->mmap_sem);
@@ -90,6 +90,11 @@ blktap_read_ring(struct blktap *tap)
        up_read(&current->mm->mmap_sem);
 }
 
+#define MMAP_VADDR(_start, _req, _seg)                         \
+       ((_start) +                                             \
+        ((_req) * BLKTAP_SEGMENT_MAX * BLKTAP_PAGE_SIZE) +     \
+        ((_seg) * BLKTAP_PAGE_SIZE))
+
 static int blktap_ring_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
        return VM_FAULT_SIGBUS;
@@ -102,7 +107,7 @@ blktap_ring_fail_pending(struct blktap *tap)
        struct blktap_request *request;
        int usr_idx;
 
-       for (usr_idx = 0; usr_idx < MAX_PENDING_REQS; usr_idx++) {
+       for (usr_idx = 0; usr_idx < BLKTAP_RING_SIZE; usr_idx++) {
                request = ring->pending[usr_idx];
                if (!request)
                        continue;
@@ -154,7 +159,7 @@ blktap_ring_map_request(struct blktap *tap,
        int seg, err = 0;
        int write;
 
-       write = request->operation == BLKIF_OP_WRITE;
+       write = request->operation == BLKTAP_OP_WRITE;
 
        for (seg = 0; seg < request->nr_pages; seg++) {
                if (write)
@@ -182,7 +187,7 @@ blktap_ring_unmap_request(struct blktap *tap,
 
        uaddr = MMAP_VADDR(ring->user_vstart, request->usr_idx, 0);
        size  = request->nr_pages << PAGE_SHIFT;
-       read  = request->operation == BLKIF_OP_READ;
+       read  = request->operation == BLKTAP_OP_READ;
 
        if (read)
                for (seg = 0; seg < request->nr_pages; seg++)
@@ -217,11 +222,11 @@ blktap_ring_make_request(struct blktap *tap)
        if (!request)
                return ERR_PTR(-ENOMEM);
 
-       for (usr_idx = 0; usr_idx < BLK_RING_SIZE; usr_idx++)
+       for (usr_idx = 0; usr_idx < BLKTAP_RING_SIZE; usr_idx++)
                if (!ring->pending[usr_idx])
                        break;
 
-       BUG_ON(usr_idx >= BLK_RING_SIZE);
+       BUG_ON(usr_idx >= BLKTAP_RING_SIZE);
 
        request->tap     = tap;
        request->usr_idx = usr_idx;
@@ -237,7 +242,7 @@ blktap_ring_submit_request(struct blktap *tap,
                           struct blktap_request *request)
 {
        struct blktap_ring *ring = &tap->ring;
-       struct blkif_request *breq;
+       blktap_ring_req_t *breq;
        struct scatterlist *sg;
        int i, nsecs = 0;
 
@@ -248,12 +253,12 @@ blktap_ring_submit_request(struct blktap *tap,
 
        breq->id            = request->usr_idx;
        breq->sector_number = blk_rq_pos(request->rq);
-       breq->handle        = 0;
+       breq->__pad         = 0;
        breq->operation     = request->operation;
        breq->nr_segments   = request->nr_pages;
 
        blktap_for_each_sg(sg, request, i) {
-               struct blkif_request_segment *seg = &breq->seg[i];
+               struct blktap_segment *seg = &breq->seg[i];
                int first, count;
 
                count = sg->length >> 9;
@@ -270,12 +275,12 @@ blktap_ring_submit_request(struct blktap *tap,
        do_gettimeofday(&request->time);
 
 
-       if (request->operation == BLKIF_OP_WRITE) {
+       if (request->operation == BLKTAP_OP_WRITE) {
                tap->stats.st_wr_sect += nsecs;
                tap->stats.st_wr_req++;
        }
 
-       if (request->operation == BLKIF_OP_READ) {
+       if (request->operation == BLKTAP_OP_READ) {
                tap->stats.st_rd_sect += nsecs;
                tap->stats.st_rd_req++;
        }
@@ -327,7 +332,7 @@ blktap_ring_mmap(struct file *filp, struct vm_area_struct *vma)
 {
        struct blktap *tap = filp->private_data;
        struct blktap_ring *ring = &tap->ring;
-       struct blkif_sring *sring;
+       blktap_sring_t *sring;
        struct page *page = NULL;
        int err;
 
@@ -384,25 +389,25 @@ blktap_ring_ioctl(struct inode *inode, struct file *filp,
                return -EACCES;
 
        switch(cmd) {
-       case BLKTAP2_IOCTL_KICK_FE:
+       case BLKTAP_IOCTL_RESPOND:
 
                blktap_read_ring(tap);
                return 0;
 
-       case BLKTAP2_IOCTL_CREATE_DEVICE: {
-               struct blktap_params params;
+       case BLKTAP_IOCTL_CREATE_DEVICE: {
+               struct blktap_device_info info;
                void __user *ptr = (void *)arg;
 
                if (!arg)
                        return -EINVAL;
 
-               if (copy_from_user(&params, ptr, sizeof(params)))
+               if (copy_from_user(&info, ptr, sizeof(info)))
                        return -EFAULT;
 
-               return blktap_device_create(tap, &params);
+               return blktap_device_create(tap, &info);
        }
 
-       case BLKTAP2_IOCTL_REMOVE_DEVICE:
+       case BLKTAP_IOCTL_REMOVE_DEVICE:
 
                return blktap_device_destroy(tap);
        }
@@ -482,7 +487,7 @@ blktap_ring_debug(struct blktap *tap, char *buf, size_t size)
        s += snprintf(s, end - s,
                      "begin pending:%d\n", ring->n_pending);
 
-       for (usr_idx = 0; usr_idx < MAX_PENDING_REQS; usr_idx++) {
+       for (usr_idx = 0; usr_idx < BLKTAP_RING_SIZE; usr_idx++) {
                struct blktap_request *request;
                struct timeval *time;
                int write;
@@ -491,7 +496,7 @@ blktap_ring_debug(struct blktap *tap, char *buf, size_t size)
                if (!request)
                        continue;
 
-               write = request->operation == BLKIF_OP_WRITE;
+               write = request->operation == BLKTAP_OP_WRITE;
                time  = &request->time;
 
                s += snprintf(s, end - s,
drivers/xen/blktap/sysfs.c +3 -3
index 7bbfea8..182de9a 100644
@@ -20,7 +20,7 @@ blktap_sysfs_set_name(struct device *dev, struct device_attribute *attr, const c
        if (!tap)
                return 0;
 
-       if (size >= BLKTAP2_MAX_MESSAGE_LEN)
+       if (size >= BLKTAP_NAME_MAX)
                return -ENAMETOOLONG;
 
        if (strnlen(buf, size) != size)
@@ -75,8 +75,8 @@ blktap_sysfs_remove_device(struct device *dev,
                goto wait;
 
        if (tap->ring.vma) {
-               blkif_sring_t *sring = tap->ring.ring.sring;
-               sring->private.tapif_user.msg = BLKTAP2_RING_MESSAGE_CLOSE;
+               blktap_sring_t *sring = tap->ring.ring.sring;
+               sring->private.tapif_user.msg = BLKTAP_RING_MESSAGE_CLOSE;
                blktap_ring_kick_user(tap);
        } else {
                INIT_WORK(&tap->remove_work, blktap_sysfs_remove_work);
include/linux/blktap.h new file +85 -1
new file mode 100644
index 0000000..ec33429
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2011, XenSource Inc.
+ * All rights reserved.
+ */
+
+#ifndef _LINUX_BLKTAP_H
+#define _LINUX_BLKTAP_H
+
+/*
+ * Control
+ */
+
+#define BLKTAP_IOCTL_RESPOND        1
+#define BLKTAP_IOCTL_ALLOC_TAP      200
+#define BLKTAP_IOCTL_FREE_TAP       201
+#define BLKTAP_IOCTL_CREATE_DEVICE  202
+#define BLKTAP_IOCTL_REMOVE_DEVICE  207
+
+#define BLKTAP_NAME_MAX             256
+
+struct blktap_info {
+       unsigned int            ring_major;
+       unsigned int            bdev_major;
+       unsigned int            ring_minor;
+};
+
+struct blktap_device_info {
+       char                    name[BLKTAP_NAME_MAX];
+       unsigned long long      capacity;
+       unsigned long           sector_size;
+};
+
+/*
+ * I/O ring
+ */
+
+#ifdef __KERNEL__
+#define BLKTAP_PAGE_SIZE PAGE_SIZE
+#endif
+
+#include <xen/interface/io/ring.h>
+
+typedef struct blktap_ring_request  blktap_ring_req_t;
+typedef struct blktap_ring_response blktap_ring_rsp_t;
+
+struct blktap_segment {
+       uint32_t                __pad;
+       uint8_t                 first_sect;
+       uint8_t                 last_sect;
+};
+
+#define BLKTAP_OP_READ          0
+#define BLKTAP_OP_WRITE         1
+
+#define BLKTAP_SEGMENT_MAX      11
+
+struct blktap_ring_request {
+       uint8_t                 operation;
+       uint8_t                 nr_segments;
+       uint16_t                __pad;
+       uint64_t                id;
+       uint64_t                sector_number;
+       struct blktap_segment   seg[BLKTAP_SEGMENT_MAX];
+};
+
+#define BLKTAP_RSP_EOPNOTSUPP  -2
+#define BLKTAP_RSP_ERROR       -1
+#define BLKTAP_RSP_OKAY         0
+
+struct blktap_ring_response {
+       uint64_t                id;
+       uint8_t                 operation;
+       int16_t                 status;
+};
+
+DEFINE_RING_TYPES(blktap, struct blktap_ring_request, struct blktap_ring_response);
+#define BLKTAP_RING_SIZE __CONST_RING_SIZE(blktap, BLKTAP_PAGE_SIZE)
+
+/*
+ * Ring messages (DEPRECATED)
+ */
+
+#define BLKTAP_RING_MESSAGE_CLOSE   3
+
+#endif /* _LINUX_BLKTAP_H */
--

1.7.0.4

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw

Re: [PATCH 01/10] blktap: Add include/linux/blktap.h

Quoted 19 lines · Ian Campbell
Quoted 9 lines · Daniel Stodden

Moves blktap2 definitions into a common header file.

Includes xen/interface/io/ring.h and new ring definitions. Makes blktap build independently from xen-devel headers.

New blktap_ring structs are fully congrent to blkif rings, for binary compat.

Quoted 8 lines
---
 drivers/xen/blktap/blktap.h  |   66 ++++----------------------------
 drivers/xen/blktap/control.c |   14 +++---
 drivers/xen/blktap/device.c  |   12 +++---
 drivers/xen/blktap/request.c |    8 ++--
 drivers/xen/blktap/ring.c    |   51 ++++++++++++++-----------
 drivers/xen/blktap/sysfs.c   |    6 +-
 include/linux/blktap.h       |   85 ++++++++++++++++++++++++++++++++++++++++++
Quoted 2 lines

This new file defines the kernel<->user (tapdisk process) ring protocol, right?

Yes. It's exactly as far as I can go right now maintaining compatibility. The main objective was rather to get off xen-devel headers in favour of kernel sources.

- includes xen/interface/io/ring.
- doesn't include xen/interface/io/blkif.
- certainly doesn't include xen/interface/blkif.h
(the alignment stuff for guests).

The old code used blkif and struct blkif_* definitions. The new one got it's own struct blktap_*s, identical as far as READ/WRITE commands go.

But this also means one can develop the userland stuff independently from blkif.h. New commands (flush, trim, ...) get quite a bit more useful freedom.

Quoted 2 lines

I think its proper home would be under include/xen somewhere, which is where the gntdev and evtchn etc driver interfaces are defined.

A very long time ago, a somewhat obvious choice was made to use xen ring headers for the blktap user <-> kernel interface. So this header presently still wants xen/interface.

It doesn't depend on anything xenish, nor is this a Xen driver anymore. I thought even with that header dependency, that's somewhat a linux/blktap.h already, so I made it so.

I'm feeling some heat from boston-newxen people because in XCP I'm actually building blktap.hg against the kernel devel rpm contents right now. That's got to vanish. It's great for hacking extensions, but the component dependency is a bit gross, admittedly.

Once doing so, it's a standalone kernel blktap.h which can be copied over into userland trees, without additional definitions included.

This isn't sick: Blktap2 doesn't need the full ring.h macro contents with memory barriers etc anyway, because the userland dispatching is synchronous. It could be just bare structs, and the standard PUSH/PULL macros are rather decoration and could be dropped (or reimplemented as memcpy()s).

Will this justify linux/blktap.h?

One could also revert that ring.h pad space hack.

I'm not passionate about it. If you still disagree, I'll give up and we move it elsewhere.

In this case, it could as well go back into drivers/block/blktap, and I'll just give up on 'development mode' hacks to verify tapdisk builds against the kernel tree altogether.

Quoted 2 lines

Where is the canonical definition of this interface stored? In the kernel tree or the hypervisor tree?

You mean blktap.h? This is not a xen driver. I'd call this the canonical definition, a reference with what that kernel/driver revision supports, that's why I put it there.

It wouldn't belong elsewhere, except for occasionally updated verbatim copies in updated blktap sources, to unstress build dependencies.

Daniel

Quoted 559 lines

Ian.

Quoted 555 lines
 7 files changed, 142 insertions(+), 100 deletions(-)
 create mode 100644 include/linux/blktap.h
drivers/xen/blktap/blktap.h +9 -57
index fe63fc9..1318cad 100644
@@ -6,7 +6,7 @@
 #include <linux/cdev.h>
 #include <linux/init.h>
 #include <linux/scatterlist.h>
-#include <xen/blkif.h>
+#include <linux/blktap.h>
 
 extern int blktap_debug_level;
 extern int blktap_ring_major;
@@ -30,74 +30,26 @@ extern int blktap_device_major;
 #define BLKTAP_DEVICE_CLOSED         5
 #define BLKTAP_SHUTDOWN_REQUESTED    8
 
-/* blktap IOCTLs: */
-#define BLKTAP2_IOCTL_KICK_FE        1
-#define BLKTAP2_IOCTL_ALLOC_TAP      200
-#define BLKTAP2_IOCTL_FREE_TAP       201
-#define BLKTAP2_IOCTL_CREATE_DEVICE  202
-#define BLKTAP2_IOCTL_REMOVE_DEVICE  207
-
-#define BLKTAP2_MAX_MESSAGE_LEN      256
-
-#define BLKTAP2_RING_MESSAGE_CLOSE   3
-
 #define BLKTAP_REQUEST_FREE          0
 #define BLKTAP_REQUEST_PENDING       1
 
-/*
- * The maximum number of requests that can be outstanding at any time
- * is determined by
- *
- *   [mmap_alloc * MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST]
- *
- * where mmap_alloc < MAX_DYNAMIC_MEM.
- *
- * TODO:
- * mmap_alloc is initialised to 2 and should be adjustable on the fly via
- * sysfs.
- */
-#define BLK_RING_SIZE          __RING_SIZE((struct blkif_sring *)0, PAGE_SIZE)
-#define MAX_DYNAMIC_MEM                BLK_RING_SIZE
-#define MAX_PENDING_REQS       BLK_RING_SIZE
-#define MMAP_PAGES (MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST)
-#define MMAP_VADDR(_start, _req, _seg)                                 \
-        (_start +                                                       \
-         ((_req) * BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE) +        \
-         ((_seg) * PAGE_SIZE))
-
-struct grant_handle_pair {
-       grant_handle_t                 kernel;
-       grant_handle_t                 user;
-};
-#define INVALID_GRANT_HANDLE           0xFFFF
-
-struct blktap_handle {
-       unsigned int                   ring;
-       unsigned int                   device;
-       unsigned int                   minor;
-};
-
-struct blktap_params {
-       char                           name[BLKTAP2_MAX_MESSAGE_LEN];
-       unsigned long long             capacity;
-       unsigned long                  sector_size;
-};
-
 struct blktap_device {
        spinlock_t                     lock;
        struct gendisk                *gd;
 };
 
+struct blktap_request;
+
 struct blktap_ring {
        struct task_struct            *task;
 
        struct vm_area_struct         *vma;
-       struct blkif_front_ring        ring;
+       blktap_front_ring_t            ring;
        unsigned long                  ring_vstart;
        unsigned long                  user_vstart;
 
        int                            n_pending;
-       struct blktap_request         *pending[MAX_PENDING_REQS];
+       struct blktap_request         *pending[BLKTAP_RING_SIZE];
 
        wait_queue_head_t              poll_wait;
 
@@ -128,8 +80,8 @@ struct blktap_request {
        int                            operation;
        struct timeval                 time;
 
-       struct scatterlist             sg_table[BLKIF_MAX_SEGMENTS_PER_REQUEST];
-       struct page                   *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST];
+       struct scatterlist             sg_table[BLKTAP_SEGMENT_MAX];
+       struct page                   *pages[BLKTAP_SEGMENT_MAX];
        int                            nr_pages;
 };
 
@@ -148,7 +100,7 @@ struct blktap {
 
        wait_queue_head_t              remove_wait;
        struct work_struct             remove_work;
-       char                           name[BLKTAP2_MAX_MESSAGE_LEN];
+       char                           name[BLKTAP_NAME_MAX];
 
        struct blktap_statistics       stats;
 };
@@ -189,7 +141,7 @@ void blktap_sysfs_destroy(struct blktap *);
 int blktap_device_init(void);
 void blktap_device_exit(void);
 size_t blktap_device_debug(struct blktap *, char *, size_t);
-int blktap_device_create(struct blktap *, struct blktap_params *);
+int blktap_device_create(struct blktap *, struct blktap_device_info *);
 int blktap_device_destroy(struct blktap *);
 void blktap_device_destroy_sync(struct blktap *);
 void blktap_device_run_queue(struct blktap *);
drivers/xen/blktap/control.c +7 -7
index f339bba..57b1a10 100644
@@ -127,19 +127,19 @@ blktap_control_ioctl(struct inode *inode, struct file *filp,
        struct blktap *tap;
 
        switch (cmd) {
-       case BLKTAP2_IOCTL_ALLOC_TAP: {
-               struct blktap_handle h;
+       case BLKTAP_IOCTL_ALLOC_TAP: {
+               struct blktap_info info;
                void __user *ptr = (void __user*)arg;
 
                tap = blktap_control_create_tap();
                if (!tap)
                        return -ENOMEM;
 
-               h.ring   = blktap_ring_major;
-               h.device = blktap_device_major;
-               h.minor  = tap->minor;
+               info.ring_major = blktap_ring_major;
+               info.bdev_major = blktap_device_major;
+               info.ring_minor = tap->minor;
 
-               if (copy_to_user(ptr, &h, sizeof(h))) {
+               if (copy_to_user(ptr, &info, sizeof(info))) {
                        blktap_control_destroy_tap(tap);
                        return -EFAULT;
                }
@@ -147,7 +147,7 @@ blktap_control_ioctl(struct inode *inode, struct file *filp,
                return 0;
        }
 
-       case BLKTAP2_IOCTL_FREE_TAP: {
+       case BLKTAP_IOCTL_FREE_TAP: {
                int minor = arg;
 
                if (minor > MAX_BLKTAP_DEVICE)
drivers/xen/blktap/device.c +6 -6
index fce2769..6bb04bd 100644
@@ -186,7 +186,7 @@ blktap_device_make_request(struct blktap *tap, struct request *rq)
                write ? 'w' : 'r', blk_rq_bytes(rq), nsegs);
 
        request->rq = rq;
-       request->operation = write ? BLKIF_OP_WRITE : BLKIF_OP_READ;
+       request->operation = write ? BLKTAP_OP_WRITE : BLKTAP_OP_READ;
 
        err = blktap_request_get_pages(tap, request, nsegs);
        if (err)
@@ -276,7 +276,7 @@ blktap_device_do_request(struct request_queue *rq)
 
 static void
 blktap_device_configure(struct blktap *tap,
-                       struct blktap_params *params)
+                       struct blktap_device_info *params)
 {
        struct request_queue *rq;
        struct blktap_device *dev = &tap->device;
@@ -297,8 +297,8 @@ blktap_device_configure(struct blktap *tap,
        blk_queue_max_segment_size(rq, PAGE_SIZE);
 
        /* Ensure a merged request will fit in a single I/O ring slot. */
-       blk_queue_max_phys_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST);
-       blk_queue_max_hw_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST);
+       blk_queue_max_phys_segments(rq, BLKTAP_SEGMENT_MAX);
+       blk_queue_max_hw_segments(rq, BLKTAP_SEGMENT_MAX);
 
        /* Make sure buffer addresses are sector-aligned. */
        blk_queue_dma_alignment(rq, 511);
@@ -311,7 +311,7 @@ blktap_device_configure(struct blktap *tap,
 
 static int
 blktap_device_validate_params(struct blktap *tap,
-                             struct blktap_params *params)
+                             struct blktap_device_info *params)
 {
        struct device *dev = tap->ring.dev;
        int sector_order, name_sz;
@@ -425,7 +425,7 @@ blktap_device_destroy_sync(struct blktap *tap)
 }
 
 int
-blktap_device_create(struct blktap *tap, struct blktap_params *params)
+blktap_device_create(struct blktap *tap, struct blktap_device_info *params)
 {
        int minor, err;
        struct gendisk *gd;
drivers/xen/blktap/request.c +4 -4
index 9bef48c..8cfd6c9 100644
@@ -7,18 +7,18 @@
 #include "blktap.h"
 
 /* max pages per shared pool. just to prevent accidental dos. */
-#define POOL_MAX_PAGES           (256*BLKIF_MAX_SEGMENTS_PER_REQUEST)
+#define POOL_MAX_PAGES           (256*BLKTAP_SEGMENT_MAX)
 
 /* default page pool size. when considering to shrink a shared pool,
  * note that paused tapdisks may grab a whole lot of pages for a long
  * time. */
-#define POOL_DEFAULT_PAGES       (2 * MMAP_PAGES)
+#define POOL_DEFAULT_PAGES       (2 * BLKTAP_RING_SIZE * BLKTAP_SEGMENT_MAX)
 
 /* max number of pages allocatable per request. */
-#define POOL_MAX_REQUEST_PAGES   BLKIF_MAX_SEGMENTS_PER_REQUEST
+#define POOL_MAX_REQUEST_PAGES   BLKTAP_SEGMENT_MAX
 
 /* min request structs per pool. These grow dynamically. */
-#define POOL_MIN_REQS            BLK_RING_SIZE
+#define POOL_MIN_REQS            BLKTAP_RING_SIZE
 
 static struct kset *pool_set;
 
drivers/xen/blktap/ring.c +28 -23
index 6b86be5..9442a64 100644
@@ -18,7 +18,7 @@ static struct cdev blktap_ring_cdev;
 
 static void
 blktap_ring_read_response(struct blktap *tap,
-                    const struct blkif_response *rsp)
+                         const blktap_ring_rsp_t *rsp)
 {
        struct blktap_ring *ring = &tap->ring;
        struct blktap_request *request;
@@ -27,7 +27,7 @@ blktap_ring_read_response(struct blktap *tap,
        request = NULL;
 
        usr_idx = rsp->id;
-       if (usr_idx < 0 || usr_idx >= MAX_PENDING_REQS) {
+       if (usr_idx < 0 || usr_idx >= BLKTAP_RING_SIZE) {
                err = -ERANGE;
                goto invalid;
        }
@@ -48,7 +48,7 @@ blktap_ring_read_response(struct blktap *tap,
                "request %d [%p] response: %d\n",
                request->usr_idx, request, rsp->status);
 
-       err = rsp->status == BLKIF_RSP_OKAY ? 0 : -EIO;
+       err = rsp->status == BLKTAP_RSP_OKAY ? 0 : -EIO;
 end_request:
        blktap_device_end_request(tap, request, err);
        return;
@@ -67,7 +67,7 @@ static void
 blktap_read_ring(struct blktap *tap)
 {
        struct blktap_ring *ring = &tap->ring;
-       struct blkif_response rsp;
+       blktap_ring_rsp_t rsp;
        RING_IDX rc, rp;
 
        down_read(&current->mm->mmap_sem);
@@ -90,6 +90,11 @@ blktap_read_ring(struct blktap *tap)
        up_read(&current->mm->mmap_sem);
 }
 
+#define MMAP_VADDR(_start, _req, _seg)                         \
+       ((_start) +                                             \
+        ((_req) * BLKTAP_SEGMENT_MAX * BLKTAP_PAGE_SIZE) +     \
+        ((_seg) * BLKTAP_PAGE_SIZE))
+
 static int blktap_ring_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
        return VM_FAULT_SIGBUS;
@@ -102,7 +107,7 @@ blktap_ring_fail_pending(struct blktap *tap)
        struct blktap_request *request;
        int usr_idx;
 
-       for (usr_idx = 0; usr_idx < MAX_PENDING_REQS; usr_idx++) {
+       for (usr_idx = 0; usr_idx < BLKTAP_RING_SIZE; usr_idx++) {
                request = ring->pending[usr_idx];
                if (!request)
                        continue;
@@ -154,7 +159,7 @@ blktap_ring_map_request(struct blktap *tap,
        int seg, err = 0;
        int write;
 
-       write = request->operation == BLKIF_OP_WRITE;
+       write = request->operation == BLKTAP_OP_WRITE;
 
        for (seg = 0; seg < request->nr_pages; seg++) {
                if (write)
@@ -182,7 +187,7 @@ blktap_ring_unmap_request(struct blktap *tap,
 
        uaddr = MMAP_VADDR(ring->user_vstart, request->usr_idx, 0);
        size  = request->nr_pages << PAGE_SHIFT;
-       read  = request->operation == BLKIF_OP_READ;
+       read  = request->operation == BLKTAP_OP_READ;
 
        if (read)
                for (seg = 0; seg < request->nr_pages; seg++)
@@ -217,11 +222,11 @@ blktap_ring_make_request(struct blktap *tap)
        if (!request)
                return ERR_PTR(-ENOMEM);
 
-       for (usr_idx = 0; usr_idx < BLK_RING_SIZE; usr_idx++)
+       for (usr_idx = 0; usr_idx < BLKTAP_RING_SIZE; usr_idx++)
                if (!ring->pending[usr_idx])
                        break;
 
-       BUG_ON(usr_idx >= BLK_RING_SIZE);
+       BUG_ON(usr_idx >= BLKTAP_RING_SIZE);
 
        request->tap     = tap;
        request->usr_idx = usr_idx;
@@ -237,7 +242,7 @@ blktap_ring_submit_request(struct blktap *tap,
                           struct blktap_request *request)
 {
        struct blktap_ring *ring = &tap->ring;
-       struct blkif_request *breq;
+       blktap_ring_req_t *breq;
        struct scatterlist *sg;
        int i, nsecs = 0;
 
@@ -248,12 +253,12 @@ blktap_ring_submit_request(struct blktap *tap,
 
        breq->id            = request->usr_idx;
        breq->sector_number = blk_rq_pos(request->rq);
-       breq->handle        = 0;
+       breq->__pad         = 0;
        breq->operation     = request->operation;
        breq->nr_segments   = request->nr_pages;
 
        blktap_for_each_sg(sg, request, i) {
-               struct blkif_request_segment *seg = &breq->seg[i];
+               struct blktap_segment *seg = &breq->seg[i];
                int first, count;
 
                count = sg->length >> 9;
@@ -270,12 +275,12 @@ blktap_ring_submit_request(struct blktap *tap,
        do_gettimeofday(&request->time);
 
 
-       if (request->operation == BLKIF_OP_WRITE) {
+       if (request->operation == BLKTAP_OP_WRITE) {
                tap->stats.st_wr_sect += nsecs;
                tap->stats.st_wr_req++;
        }
 
-       if (request->operation == BLKIF_OP_READ) {
+       if (request->operation == BLKTAP_OP_READ) {
                tap->stats.st_rd_sect += nsecs;
                tap->stats.st_rd_req++;
        }
@@ -327,7 +332,7 @@ blktap_ring_mmap(struct file *filp, struct vm_area_struct *vma)
 {
        struct blktap *tap = filp->private_data;
        struct blktap_ring *ring = &tap->ring;
-       struct blkif_sring *sring;
+       blktap_sring_t *sring;
        struct page *page = NULL;
        int err;
 
@@ -384,25 +389,25 @@ blktap_ring_ioctl(struct inode *inode, struct file *filp,
                return -EACCES;
 
        switch(cmd) {
-       case BLKTAP2_IOCTL_KICK_FE:
+       case BLKTAP_IOCTL_RESPOND:
 
                blktap_read_ring(tap);
                return 0;
 
-       case BLKTAP2_IOCTL_CREATE_DEVICE: {
-               struct blktap_params params;
+       case BLKTAP_IOCTL_CREATE_DEVICE: {
+               struct blktap_device_info info;
                void __user *ptr = (void *)arg;
 
                if (!arg)
                        return -EINVAL;
 
-               if (copy_from_user(&params, ptr, sizeof(params)))
+               if (copy_from_user(&info, ptr, sizeof(info)))
                        return -EFAULT;
 
-               return blktap_device_create(tap, &params);
+               return blktap_device_create(tap, &info);
        }
 
-       case BLKTAP2_IOCTL_REMOVE_DEVICE:
+       case BLKTAP_IOCTL_REMOVE_DEVICE:
 
                return blktap_device_destroy(tap);
        }
@@ -482,7 +487,7 @@ blktap_ring_debug(struct blktap *tap, char *buf, size_t size)
        s += snprintf(s, end - s,
                      "begin pending:%d\n", ring->n_pending);
 
-       for (usr_idx = 0; usr_idx < MAX_PENDING_REQS; usr_idx++) {
+       for (usr_idx = 0; usr_idx < BLKTAP_RING_SIZE; usr_idx++) {
                struct blktap_request *request;
                struct timeval *time;
                int write;
@@ -491,7 +496,7 @@ blktap_ring_debug(struct blktap *tap, char *buf, size_t size)
                if (!request)
                        continue;
 
-               write = request->operation == BLKIF_OP_WRITE;
+               write = request->operation == BLKTAP_OP_WRITE;
                time  = &request->time;
 
                s += snprintf(s, end - s,
drivers/xen/blktap/sysfs.c +3 -3
index 7bbfea8..182de9a 100644
@@ -20,7 +20,7 @@ blktap_sysfs_set_name(struct device *dev, struct device_attribute *attr, const c
        if (!tap)
                return 0;
 
-       if (size >= BLKTAP2_MAX_MESSAGE_LEN)
+       if (size >= BLKTAP_NAME_MAX)
                return -ENAMETOOLONG;
 
        if (strnlen(buf, size) != size)
@@ -75,8 +75,8 @@ blktap_sysfs_remove_device(struct device *dev,
                goto wait;
 
        if (tap->ring.vma) {
-               blkif_sring_t *sring = tap->ring.ring.sring;
-               sring->private.tapif_user.msg = BLKTAP2_RING_MESSAGE_CLOSE;
+               blktap_sring_t *sring = tap->ring.ring.sring;
+               sring->private.tapif_user.msg = BLKTAP_RING_MESSAGE_CLOSE;
                blktap_ring_kick_user(tap);
        } else {
                INIT_WORK(&tap->remove_work, blktap_sysfs_remove_work);
include/linux/blktap.h new file +85 -1
new file mode 100644
index 0000000..ec33429
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2011, XenSource Inc.
+ * All rights reserved.
+ */
+
+#ifndef _LINUX_BLKTAP_H
+#define _LINUX_BLKTAP_H
+
+/*
+ * Control
+ */
+
+#define BLKTAP_IOCTL_RESPOND        1
+#define BLKTAP_IOCTL_ALLOC_TAP      200
+#define BLKTAP_IOCTL_FREE_TAP       201
+#define BLKTAP_IOCTL_CREATE_DEVICE  202
+#define BLKTAP_IOCTL_REMOVE_DEVICE  207
+
+#define BLKTAP_NAME_MAX             256
+
+struct blktap_info {
+       unsigned int            ring_major;
+       unsigned int            bdev_major;
+       unsigned int            ring_minor;
+};
+
+struct blktap_device_info {
+       char                    name[BLKTAP_NAME_MAX];
+       unsigned long long      capacity;
+       unsigned long           sector_size;
+};
+
+/*
+ * I/O ring
+ */
+
+#ifdef __KERNEL__
+#define BLKTAP_PAGE_SIZE PAGE_SIZE
+#endif
+
+#include <xen/interface/io/ring.h>
+
+typedef struct blktap_ring_request  blktap_ring_req_t;
+typedef struct blktap_ring_response blktap_ring_rsp_t;
+
+struct blktap_segment {
+       uint32_t                __pad;
+       uint8_t                 first_sect;
+       uint8_t                 last_sect;
+};
+
+#define BLKTAP_OP_READ          0
+#define BLKTAP_OP_WRITE         1
+
+#define BLKTAP_SEGMENT_MAX      11
+
+struct blktap_ring_request {
+       uint8_t                 operation;
+       uint8_t                 nr_segments;
+       uint16_t                __pad;
+       uint64_t                id;
+       uint64_t                sector_number;
+       struct blktap_segment   seg[BLKTAP_SEGMENT_MAX];
+};
+
+#define BLKTAP_RSP_EOPNOTSUPP  -2
+#define BLKTAP_RSP_ERROR       -1
+#define BLKTAP_RSP_OKAY         0
+
+struct blktap_ring_response {
+       uint64_t                id;
+       uint8_t                 operation;
+       int16_t                 status;
+};
+
+DEFINE_RING_TYPES(blktap, struct blktap_ring_request, struct blktap_ring_response);
+#define BLKTAP_RING_SIZE __CONST_RING_SIZE(blktap, BLKTAP_PAGE_SIZE)
+
+/*
+ * Ring messages (DEPRECATED)
+ */
+
+#define BLKTAP_RING_MESSAGE_CLOSE   3
+
+#endif /* _LINUX_BLKTAP_H */
--

1.7.0.4

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#4 lore raw

Re: [PATCH 01/10] blktap: Add include/linux/blktap.h

Quoted 42 lines · Daniel Stodden
Quoted 19 lines · Ian Campbell
Quoted 9 lines · Daniel Stodden

Moves blktap2 definitions into a common header file.

Includes xen/interface/io/ring.h and new ring definitions. Makes blktap build independently from xen-devel headers.

New blktap_ring structs are fully congrent to blkif rings, for binary compat.

Quoted 8 lines
---
 drivers/xen/blktap/blktap.h  |   66 ++++----------------------------
 drivers/xen/blktap/control.c |   14 +++---
 drivers/xen/blktap/device.c  |   12 +++---
 drivers/xen/blktap/request.c |    8 ++--
 drivers/xen/blktap/ring.c    |   51 ++++++++++++++-----------
 drivers/xen/blktap/sysfs.c   |    6 +-
 include/linux/blktap.h       |   85 ++++++++++++++++++++++++++++++++++++++++++
Quoted 2 lines

This new file defines the kernel<->user (tapdisk process) ring protocol, right?

Yes. It's exactly as far as I can go right now maintaining compatibility. The main objective was rather to get off xen-devel headers in favour of kernel sources.

- includes xen/interface/io/ring.
- doesn't include xen/interface/io/blkif.
- certainly doesn't include xen/interface/blkif.h
(the alignment stuff for guests).

The old code used blkif and struct blkif_* definitions. The new one got it's own struct blktap_*s, identical as far as READ/WRITE commands go.

But this also means one can develop the userland stuff independently from blkif.h. New commands (flush, trim, ...) get quite a bit more useful freedom.

Quoted 2 lines

I think its proper home would be under include/xen somewhere, which is where the gntdev and evtchn etc driver interfaces are defined.

Quoted 7 lines

A very long time ago, a somewhat obvious choice was made to use xen ring headers for the blktap user <-> kernel interface. So this header presently still wants xen/interface.

It doesn't depend on anything xenish, nor is this a Xen driver anymore. I thought even with that header dependency, that's somewhat a linux/blktap.h already, so I made it so.

OK.

Quoted 4 lines

I'm feeling some heat from boston-newxen people because in XCP I'm actually building blktap.hg against the kernel devel rpm contents right now. That's got to vanish. It's great for hacking extensions, but the component dependency is a bit gross, admittedly.

Sure, but you could build against a copy of the kernel source tree, which would remove the dependency on the kernel binary RPMs.

Quoted 2 lines

Once doing so, it's a standalone kernel blktap.h which can be copied over into userland trees, without additional definitions included.

If the other user of this interface is the tapdisk userspace, but that includes a copy of the interface header (note: I'm not convinced that is a good idea) then I think the right place for this copy of the header is drivers/block/blktap/.

If on the other hand userland is building against this exact header then include/linux is probably right given that the driver has no Xen dependency.

Quoted 8 lines

This isn't sick: Blktap2 doesn't need the full ring.h macro contents with memory barriers etc anyway, because the userland dispatching is synchronous. It could be just bare structs, and the standard PUSH/PULL macros are rather decoration and could be dropped (or reimplemented as memcpy()s).

Will this justify linux/blktap.h?

Quoted 8 lines

One could also revert that ring.h pad space hack.

I'm not passionate about it. If you still disagree, I'll give up and we move it elsewhere.

In this case, it could as well go back into drivers/block/blktap, and I'll just give up on 'development mode' hacks to verify tapdisk builds against the kernel tree altogether.

What sort of "'development mode' hacks"?

Quoted 573 lines
Quoted 2 lines

Where is the canonical definition of this interface stored? In the kernel tree or the hypervisor tree?

You mean blktap.h? This is not a xen driver. I'd call this the canonical definition, a reference with what that kernel/driver revision supports, that's why I put it there.

It wouldn't belong elsewhere, except for occasionally updated verbatim copies in updated blktap sources, to unstress build dependencies.

Daniel

Quoted 559 lines

Ian.

Quoted 555 lines
 7 files changed, 142 insertions(+), 100 deletions(-)
 create mode 100644 include/linux/blktap.h
drivers/xen/blktap/blktap.h +9 -57
index fe63fc9..1318cad 100644
@@ -6,7 +6,7 @@
 #include <linux/cdev.h>
 #include <linux/init.h>
 #include <linux/scatterlist.h>
-#include <xen/blkif.h>
+#include <linux/blktap.h>
 
 extern int blktap_debug_level;
 extern int blktap_ring_major;
@@ -30,74 +30,26 @@ extern int blktap_device_major;
 #define BLKTAP_DEVICE_CLOSED         5
 #define BLKTAP_SHUTDOWN_REQUESTED    8
 
-/* blktap IOCTLs: */
-#define BLKTAP2_IOCTL_KICK_FE        1
-#define BLKTAP2_IOCTL_ALLOC_TAP      200
-#define BLKTAP2_IOCTL_FREE_TAP       201
-#define BLKTAP2_IOCTL_CREATE_DEVICE  202
-#define BLKTAP2_IOCTL_REMOVE_DEVICE  207
-
-#define BLKTAP2_MAX_MESSAGE_LEN      256
-
-#define BLKTAP2_RING_MESSAGE_CLOSE   3
-
 #define BLKTAP_REQUEST_FREE          0
 #define BLKTAP_REQUEST_PENDING       1
 
-/*
- * The maximum number of requests that can be outstanding at any time
- * is determined by
- *
- *   [mmap_alloc * MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST]
- *
- * where mmap_alloc < MAX_DYNAMIC_MEM.
- *
- * TODO:
- * mmap_alloc is initialised to 2 and should be adjustable on the fly via
- * sysfs.
- */
-#define BLK_RING_SIZE          __RING_SIZE((struct blkif_sring *)0, PAGE_SIZE)
-#define MAX_DYNAMIC_MEM                BLK_RING_SIZE
-#define MAX_PENDING_REQS       BLK_RING_SIZE
-#define MMAP_PAGES (MAX_PENDING_REQS * BLKIF_MAX_SEGMENTS_PER_REQUEST)
-#define MMAP_VADDR(_start, _req, _seg)                                 \
-        (_start +                                                       \
-         ((_req) * BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE) +        \
-         ((_seg) * PAGE_SIZE))
-
-struct grant_handle_pair {
-       grant_handle_t                 kernel;
-       grant_handle_t                 user;
-};
-#define INVALID_GRANT_HANDLE           0xFFFF
-
-struct blktap_handle {
-       unsigned int                   ring;
-       unsigned int                   device;
-       unsigned int                   minor;
-};
-
-struct blktap_params {
-       char                           name[BLKTAP2_MAX_MESSAGE_LEN];
-       unsigned long long             capacity;
-       unsigned long                  sector_size;
-};
-
 struct blktap_device {
        spinlock_t                     lock;
        struct gendisk                *gd;
 };
 
+struct blktap_request;
+
 struct blktap_ring {
        struct task_struct            *task;
 
        struct vm_area_struct         *vma;
-       struct blkif_front_ring        ring;
+       blktap_front_ring_t            ring;
        unsigned long                  ring_vstart;
        unsigned long                  user_vstart;
 
        int                            n_pending;
-       struct blktap_request         *pending[MAX_PENDING_REQS];
+       struct blktap_request         *pending[BLKTAP_RING_SIZE];
 
        wait_queue_head_t              poll_wait;
 
@@ -128,8 +80,8 @@ struct blktap_request {
        int                            operation;
        struct timeval                 time;
 
-       struct scatterlist             sg_table[BLKIF_MAX_SEGMENTS_PER_REQUEST];
-       struct page                   *pages[BLKIF_MAX_SEGMENTS_PER_REQUEST];
+       struct scatterlist             sg_table[BLKTAP_SEGMENT_MAX];
+       struct page                   *pages[BLKTAP_SEGMENT_MAX];
        int                            nr_pages;
 };
 
@@ -148,7 +100,7 @@ struct blktap {
 
        wait_queue_head_t              remove_wait;
        struct work_struct             remove_work;
-       char                           name[BLKTAP2_MAX_MESSAGE_LEN];
+       char                           name[BLKTAP_NAME_MAX];
 
        struct blktap_statistics       stats;
 };
@@ -189,7 +141,7 @@ void blktap_sysfs_destroy(struct blktap *);
 int blktap_device_init(void);
 void blktap_device_exit(void);
 size_t blktap_device_debug(struct blktap *, char *, size_t);
-int blktap_device_create(struct blktap *, struct blktap_params *);
+int blktap_device_create(struct blktap *, struct blktap_device_info *);
 int blktap_device_destroy(struct blktap *);
 void blktap_device_destroy_sync(struct blktap *);
 void blktap_device_run_queue(struct blktap *);
drivers/xen/blktap/control.c +7 -7
index f339bba..57b1a10 100644
@@ -127,19 +127,19 @@ blktap_control_ioctl(struct inode *inode, struct file *filp,
        struct blktap *tap;
 
        switch (cmd) {
-       case BLKTAP2_IOCTL_ALLOC_TAP: {
-               struct blktap_handle h;
+       case BLKTAP_IOCTL_ALLOC_TAP: {
+               struct blktap_info info;
                void __user *ptr = (void __user*)arg;
 
                tap = blktap_control_create_tap();
                if (!tap)
                        return -ENOMEM;
 
-               h.ring   = blktap_ring_major;
-               h.device = blktap_device_major;
-               h.minor  = tap->minor;
+               info.ring_major = blktap_ring_major;
+               info.bdev_major = blktap_device_major;
+               info.ring_minor = tap->minor;
 
-               if (copy_to_user(ptr, &h, sizeof(h))) {
+               if (copy_to_user(ptr, &info, sizeof(info))) {
                        blktap_control_destroy_tap(tap);
                        return -EFAULT;
                }
@@ -147,7 +147,7 @@ blktap_control_ioctl(struct inode *inode, struct file *filp,
                return 0;
        }
 
-       case BLKTAP2_IOCTL_FREE_TAP: {
+       case BLKTAP_IOCTL_FREE_TAP: {
                int minor = arg;
 
                if (minor > MAX_BLKTAP_DEVICE)
drivers/xen/blktap/device.c +6 -6
index fce2769..6bb04bd 100644
@@ -186,7 +186,7 @@ blktap_device_make_request(struct blktap *tap, struct request *rq)
                write ? 'w' : 'r', blk_rq_bytes(rq), nsegs);
 
        request->rq = rq;
-       request->operation = write ? BLKIF_OP_WRITE : BLKIF_OP_READ;
+       request->operation = write ? BLKTAP_OP_WRITE : BLKTAP_OP_READ;
 
        err = blktap_request_get_pages(tap, request, nsegs);
        if (err)
@@ -276,7 +276,7 @@ blktap_device_do_request(struct request_queue *rq)
 
 static void
 blktap_device_configure(struct blktap *tap,
-                       struct blktap_params *params)
+                       struct blktap_device_info *params)
 {
        struct request_queue *rq;
        struct blktap_device *dev = &tap->device;
@@ -297,8 +297,8 @@ blktap_device_configure(struct blktap *tap,
        blk_queue_max_segment_size(rq, PAGE_SIZE);
 
        /* Ensure a merged request will fit in a single I/O ring slot. */
-       blk_queue_max_phys_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST);
-       blk_queue_max_hw_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST);
+       blk_queue_max_phys_segments(rq, BLKTAP_SEGMENT_MAX);
+       blk_queue_max_hw_segments(rq, BLKTAP_SEGMENT_MAX);
 
        /* Make sure buffer addresses are sector-aligned. */
        blk_queue_dma_alignment(rq, 511);
@@ -311,7 +311,7 @@ blktap_device_configure(struct blktap *tap,
 
 static int
 blktap_device_validate_params(struct blktap *tap,
-                             struct blktap_params *params)
+                             struct blktap_device_info *params)
 {
        struct device *dev = tap->ring.dev;
        int sector_order, name_sz;
@@ -425,7 +425,7 @@ blktap_device_destroy_sync(struct blktap *tap)
 }
 
 int
-blktap_device_create(struct blktap *tap, struct blktap_params *params)
+blktap_device_create(struct blktap *tap, struct blktap_device_info *params)
 {
        int minor, err;
        struct gendisk *gd;
drivers/xen/blktap/request.c +4 -4
index 9bef48c..8cfd6c9 100644
@@ -7,18 +7,18 @@
 #include "blktap.h"
 
 /* max pages per shared pool. just to prevent accidental dos. */
-#define POOL_MAX_PAGES           (256*BLKIF_MAX_SEGMENTS_PER_REQUEST)
+#define POOL_MAX_PAGES           (256*BLKTAP_SEGMENT_MAX)
 
 /* default page pool size. when considering to shrink a shared pool,
  * note that paused tapdisks may grab a whole lot of pages for a long
  * time. */
-#define POOL_DEFAULT_PAGES       (2 * MMAP_PAGES)
+#define POOL_DEFAULT_PAGES       (2 * BLKTAP_RING_SIZE * BLKTAP_SEGMENT_MAX)
 
 /* max number of pages allocatable per request. */
-#define POOL_MAX_REQUEST_PAGES   BLKIF_MAX_SEGMENTS_PER_REQUEST
+#define POOL_MAX_REQUEST_PAGES   BLKTAP_SEGMENT_MAX
 
 /* min request structs per pool. These grow dynamically. */
-#define POOL_MIN_REQS            BLK_RING_SIZE
+#define POOL_MIN_REQS            BLKTAP_RING_SIZE
 
 static struct kset *pool_set;
 
drivers/xen/blktap/ring.c +28 -23
index 6b86be5..9442a64 100644
@@ -18,7 +18,7 @@ static struct cdev blktap_ring_cdev;
 
 static void
 blktap_ring_read_response(struct blktap *tap,
-                    const struct blkif_response *rsp)
+                         const blktap_ring_rsp_t *rsp)
 {
        struct blktap_ring *ring = &tap->ring;
        struct blktap_request *request;
@@ -27,7 +27,7 @@ blktap_ring_read_response(struct blktap *tap,
        request = NULL;
 
        usr_idx = rsp->id;
-       if (usr_idx < 0 || usr_idx >= MAX_PENDING_REQS) {
+       if (usr_idx < 0 || usr_idx >= BLKTAP_RING_SIZE) {
                err = -ERANGE;
                goto invalid;
        }
@@ -48,7 +48,7 @@ blktap_ring_read_response(struct blktap *tap,
                "request %d [%p] response: %d\n",
                request->usr_idx, request, rsp->status);
 
-       err = rsp->status == BLKIF_RSP_OKAY ? 0 : -EIO;
+       err = rsp->status == BLKTAP_RSP_OKAY ? 0 : -EIO;
 end_request:
        blktap_device_end_request(tap, request, err);
        return;
@@ -67,7 +67,7 @@ static void
 blktap_read_ring(struct blktap *tap)
 {
        struct blktap_ring *ring = &tap->ring;
-       struct blkif_response rsp;
+       blktap_ring_rsp_t rsp;
        RING_IDX rc, rp;
 
        down_read(&current->mm->mmap_sem);
@@ -90,6 +90,11 @@ blktap_read_ring(struct blktap *tap)
        up_read(&current->mm->mmap_sem);
 }
 
+#define MMAP_VADDR(_start, _req, _seg)                         \
+       ((_start) +                                             \
+        ((_req) * BLKTAP_SEGMENT_MAX * BLKTAP_PAGE_SIZE) +     \
+        ((_seg) * BLKTAP_PAGE_SIZE))
+
 static int blktap_ring_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
        return VM_FAULT_SIGBUS;
@@ -102,7 +107,7 @@ blktap_ring_fail_pending(struct blktap *tap)
        struct blktap_request *request;
        int usr_idx;
 
-       for (usr_idx = 0; usr_idx < MAX_PENDING_REQS; usr_idx++) {
+       for (usr_idx = 0; usr_idx < BLKTAP_RING_SIZE; usr_idx++) {
                request = ring->pending[usr_idx];
                if (!request)
                        continue;
@@ -154,7 +159,7 @@ blktap_ring_map_request(struct blktap *tap,
        int seg, err = 0;
        int write;
 
-       write = request->operation == BLKIF_OP_WRITE;
+       write = request->operation == BLKTAP_OP_WRITE;
 
        for (seg = 0; seg < request->nr_pages; seg++) {
                if (write)
@@ -182,7 +187,7 @@ blktap_ring_unmap_request(struct blktap *tap,
 
        uaddr = MMAP_VADDR(ring->user_vstart, request->usr_idx, 0);
        size  = request->nr_pages << PAGE_SHIFT;
-       read  = request->operation == BLKIF_OP_READ;
+       read  = request->operation == BLKTAP_OP_READ;
 
        if (read)
                for (seg = 0; seg < request->nr_pages; seg++)
@@ -217,11 +222,11 @@ blktap_ring_make_request(struct blktap *tap)
        if (!request)
                return ERR_PTR(-ENOMEM);
 
-       for (usr_idx = 0; usr_idx < BLK_RING_SIZE; usr_idx++)
+       for (usr_idx = 0; usr_idx < BLKTAP_RING_SIZE; usr_idx++)
                if (!ring->pending[usr_idx])
                        break;
 
-       BUG_ON(usr_idx >= BLK_RING_SIZE);
+       BUG_ON(usr_idx >= BLKTAP_RING_SIZE);
 
        request->tap     = tap;
        request->usr_idx = usr_idx;
@@ -237,7 +242,7 @@ blktap_ring_submit_request(struct blktap *tap,
                           struct blktap_request *request)
 {
        struct blktap_ring *ring = &tap->ring;
-       struct blkif_request *breq;
+       blktap_ring_req_t *breq;
        struct scatterlist *sg;
        int i, nsecs = 0;
 
@@ -248,12 +253,12 @@ blktap_ring_submit_request(struct blktap *tap,
 
        breq->id            = request->usr_idx;
        breq->sector_number = blk_rq_pos(request->rq);
-       breq->handle        = 0;
+       breq->__pad         = 0;
        breq->operation     = request->operation;
        breq->nr_segments   = request->nr_pages;
 
        blktap_for_each_sg(sg, request, i) {
-               struct blkif_request_segment *seg = &breq->seg[i];
+               struct blktap_segment *seg = &breq->seg[i];
                int first, count;
 
                count = sg->length >> 9;
@@ -270,12 +275,12 @@ blktap_ring_submit_request(struct blktap *tap,
        do_gettimeofday(&request->time);
 
 
-       if (request->operation == BLKIF_OP_WRITE) {
+       if (request->operation == BLKTAP_OP_WRITE) {
                tap->stats.st_wr_sect += nsecs;
                tap->stats.st_wr_req++;
        }
 
-       if (request->operation == BLKIF_OP_READ) {
+       if (request->operation == BLKTAP_OP_READ) {
                tap->stats.st_rd_sect += nsecs;
                tap->stats.st_rd_req++;
        }
@@ -327,7 +332,7 @@ blktap_ring_mmap(struct file *filp, struct vm_area_struct *vma)
 {
        struct blktap *tap = filp->private_data;
        struct blktap_ring *ring = &tap->ring;
-       struct blkif_sring *sring;
+       blktap_sring_t *sring;
        struct page *page = NULL;
        int err;
 
@@ -384,25 +389,25 @@ blktap_ring_ioctl(struct inode *inode, struct file *filp,
                return -EACCES;
 
        switch(cmd) {
-       case BLKTAP2_IOCTL_KICK_FE:
+       case BLKTAP_IOCTL_RESPOND:
 
                blktap_read_ring(tap);
                return 0;
 
-       case BLKTAP2_IOCTL_CREATE_DEVICE: {
-               struct blktap_params params;
+       case BLKTAP_IOCTL_CREATE_DEVICE: {
+               struct blktap_device_info info;
                void __user *ptr = (void *)arg;
 
                if (!arg)
                        return -EINVAL;
 
-               if (copy_from_user(&params, ptr, sizeof(params)))
+               if (copy_from_user(&info, ptr, sizeof(info)))
                        return -EFAULT;
 
-               return blktap_device_create(tap, &params);
+               return blktap_device_create(tap, &info);
        }
 
-       case BLKTAP2_IOCTL_REMOVE_DEVICE:
+       case BLKTAP_IOCTL_REMOVE_DEVICE:
 
                return blktap_device_destroy(tap);
        }
@@ -482,7 +487,7 @@ blktap_ring_debug(struct blktap *tap, char *buf, size_t size)
        s += snprintf(s, end - s,
                      "begin pending:%d\n", ring->n_pending);
 
-       for (usr_idx = 0; usr_idx < MAX_PENDING_REQS; usr_idx++) {
+       for (usr_idx = 0; usr_idx < BLKTAP_RING_SIZE; usr_idx++) {
                struct blktap_request *request;
                struct timeval *time;
                int write;
@@ -491,7 +496,7 @@ blktap_ring_debug(struct blktap *tap, char *buf, size_t size)
                if (!request)
                        continue;
 
-               write = request->operation == BLKIF_OP_WRITE;
+               write = request->operation == BLKTAP_OP_WRITE;
                time  = &request->time;
 
                s += snprintf(s, end - s,
drivers/xen/blktap/sysfs.c +3 -3
index 7bbfea8..182de9a 100644
@@ -20,7 +20,7 @@ blktap_sysfs_set_name(struct device *dev, struct device_attribute *attr, const c
        if (!tap)
                return 0;
 
-       if (size >= BLKTAP2_MAX_MESSAGE_LEN)
+       if (size >= BLKTAP_NAME_MAX)
                return -ENAMETOOLONG;
 
        if (strnlen(buf, size) != size)
@@ -75,8 +75,8 @@ blktap_sysfs_remove_device(struct device *dev,
                goto wait;
 
        if (tap->ring.vma) {
-               blkif_sring_t *sring = tap->ring.ring.sring;
-               sring->private.tapif_user.msg = BLKTAP2_RING_MESSAGE_CLOSE;
+               blktap_sring_t *sring = tap->ring.ring.sring;
+               sring->private.tapif_user.msg = BLKTAP_RING_MESSAGE_CLOSE;
                blktap_ring_kick_user(tap);
        } else {
                INIT_WORK(&tap->remove_work, blktap_sysfs_remove_work);
include/linux/blktap.h new file +85 -1
new file mode 100644
index 0000000..ec33429
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2011, XenSource Inc.
+ * All rights reserved.
+ */
+
+#ifndef _LINUX_BLKTAP_H
+#define _LINUX_BLKTAP_H
+
+/*
+ * Control
+ */
+
+#define BLKTAP_IOCTL_RESPOND        1
+#define BLKTAP_IOCTL_ALLOC_TAP      200
+#define BLKTAP_IOCTL_FREE_TAP       201
+#define BLKTAP_IOCTL_CREATE_DEVICE  202
+#define BLKTAP_IOCTL_REMOVE_DEVICE  207
+
+#define BLKTAP_NAME_MAX             256
+
+struct blktap_info {
+       unsigned int            ring_major;
+       unsigned int            bdev_major;
+       unsigned int            ring_minor;
+};
+
+struct blktap_device_info {
+       char                    name[BLKTAP_NAME_MAX];
+       unsigned long long      capacity;
+       unsigned long           sector_size;
+};
+
+/*
+ * I/O ring
+ */
+
+#ifdef __KERNEL__
+#define BLKTAP_PAGE_SIZE PAGE_SIZE
+#endif
+
+#include <xen/interface/io/ring.h>
+
+typedef struct blktap_ring_request  blktap_ring_req_t;
+typedef struct blktap_ring_response blktap_ring_rsp_t;
+
+struct blktap_segment {
+       uint32_t                __pad;
+       uint8_t                 first_sect;
+       uint8_t                 last_sect;
+};
+
+#define BLKTAP_OP_READ          0
+#define BLKTAP_OP_WRITE         1
+
+#define BLKTAP_SEGMENT_MAX      11
+
+struct blktap_ring_request {
+       uint8_t                 operation;
+       uint8_t                 nr_segments;
+       uint16_t                __pad;
+       uint64_t                id;
+       uint64_t                sector_number;
+       struct blktap_segment   seg[BLKTAP_SEGMENT_MAX];
+};
+
+#define BLKTAP_RSP_EOPNOTSUPP  -2
+#define BLKTAP_RSP_ERROR       -1
+#define BLKTAP_RSP_OKAY         0
+
+struct blktap_ring_response {
+       uint64_t                id;
+       uint8_t                 operation;
+       int16_t                 status;
+};
+
+DEFINE_RING_TYPES(blktap, struct blktap_ring_request, struct blktap_ring_response);
+#define BLKTAP_RING_SIZE __CONST_RING_SIZE(blktap, BLKTAP_PAGE_SIZE)
+
+/*
+ * Ring messages (DEPRECATED)
+ */
+
+#define BLKTAP_RING_MESSAGE_CLOSE   3
+
+#endif /* _LINUX_BLKTAP_H */
--

1.7.0.4

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#5 lore raw

Re: [PATCH 01/10] blktap: Add include/linux/blktap.h

Quoted 64 lines · Ian Campbell
Quoted 42 lines · Daniel Stodden
Quoted 19 lines · Ian Campbell
Quoted 9 lines · Daniel Stodden

Moves blktap2 definitions into a common header file.

Includes xen/interface/io/ring.h and new ring definitions. Makes blktap build independently from xen-devel headers.

New blktap_ring structs are fully congrent to blkif rings, for binary compat.

Quoted 8 lines
---
 drivers/xen/blktap/blktap.h  |   66 ++++----------------------------
 drivers/xen/blktap/control.c |   14 +++---
 drivers/xen/blktap/device.c  |   12 +++---
 drivers/xen/blktap/request.c |    8 ++--
 drivers/xen/blktap/ring.c    |   51 ++++++++++++++-----------
 drivers/xen/blktap/sysfs.c   |    6 +-
 include/linux/blktap.h       |   85 ++++++++++++++++++++++++++++++++++++++++++
Quoted 2 lines

This new file defines the kernel<->user (tapdisk process) ring protocol, right?

Yes. It's exactly as far as I can go right now maintaining compatibility. The main objective was rather to get off xen-devel headers in favour of kernel sources.

- includes xen/interface/io/ring.
- doesn't include xen/interface/io/blkif.
- certainly doesn't include xen/interface/blkif.h
(the alignment stuff for guests).

The old code used blkif and struct blkif_* definitions. The new one got it's own struct blktap_*s, identical as far as READ/WRITE commands go.

But this also means one can develop the userland stuff independently from blkif.h. New commands (flush, trim, ...) get quite a bit more useful freedom.

Quoted 2 lines

I think its proper home would be under include/xen somewhere, which is where the gntdev and evtchn etc driver interfaces are defined.

Quoted 7 lines

A very long time ago, a somewhat obvious choice was made to use xen ring headers for the blktap user <-> kernel interface. So this header presently still wants xen/interface.

It doesn't depend on anything xenish, nor is this a Xen driver anymore. I thought even with that header dependency, that's somewhat a linux/blktap.h already, so I made it so.

OK.

Quoted 4 lines

I'm feeling some heat from boston-newxen people because in XCP I'm actually building blktap.hg against the kernel devel rpm contents right now. That's got to vanish. It's great for hacking extensions, but the component dependency is a bit gross, admittedly.

Sure, but you could build against a copy of the kernel source tree, which would remove the dependency on the kernel binary RPMs.

Quoted 2 lines

Once doing so, it's a standalone kernel blktap.h which can be copied over into userland trees, without additional definitions included.

Quoted 8 lines

If the other user of this interface is the tapdisk userspace, but that includes a copy of the interface header (note: I'm not convinced that is a good idea) then I think the right place for this copy of the header is drivers/block/blktap/.

If on the other hand userland is building against this exact header then include/linux is probably right given that the driver has no Xen dependency.

If include/linux is acceptable, good, I'd keep it.

Copies might sound dangerous, but building against kernel headers means sources need to be in sync. The compile-time #ifdef-mess would cause much more grief. Without, it's just negotiating at runtime, that's much more flexible.

Quoted 10 lines
Quoted 10 lines

This isn't sick: Blktap2 doesn't need the full ring.h macro contents with memory barriers etc anyway, because the userland dispatching is synchronous. It could be just bare structs, and the standard PUSH/PULL macros are rather decoration and could be dropped (or reimplemented as memcpy()s).

Will this justify linux/blktap.h?

One could also revert that ring.h pad space hack.

Quoted 8 lines
Quoted 6 lines

I'm not passionate about it. If you still disagree, I'll give up and we move it elsewhere.

In this case, it could as well go back into drivers/block/blktap, and I'll just give up on 'development mode' hacks to verify tapdisk builds against the kernel tree altogether.

What sort of "'development mode' hacks"?

Just referring to the above: Userspace requiring original kernel includes. Nice for development, but iirc mainline stopped promoting that entirely, a long time ago.

Daniel

Quoted 23 lines
Quoted 21 lines
Quoted 2 lines

Where is the canonical definition of this interface stored? In the kernel tree or the hypervisor tree?

You mean blktap.h? This is not a xen driver. I'd call this the canonical definition, a reference with what that kernel/driver revision supports, that's why I put it there.

It wouldn't belong elsewhere, except for occasionally updated verbatim copies in updated blktap sources, to unstress build dependencies.

Daniel

Quoted 9 lines

Ian.

Quoted 7 lines
 7 files changed, 142 insertions(+), 100 deletions(-)
 create mode 100644 include/linux/blktap.h
drivers/xen/blktap/blktap.h +0 -0
index fe63fc9..1318cad 100644
#6 lore raw

PATCH 2/10 blktap: Upgrade CREATE_DEVICE ioctl.

In reply to Daniel Stodden

Alternative for the blktap2_params-compatible call.

* drops the image name parameter.
* flags: adds support for disk R/O-mode, and later extensions.

Bumps up the relevant ioctl nr, for new tapdisk sources. The old slot remains supported through translation. Note that set_disk_ro might sleep, so just drop a gratuitous spinlock.

---
 drivers/xen/blktap/device.c |   55 ++++++++++++++++--------------------------
 drivers/xen/blktap/ring.c   |   48 ++++++++++++++++++++++++++++++++++---
 include/linux/blktap.h      |   18 ++++++++++----
 3 files changed, 78 insertions(+), 43 deletions(-)
drivers/xen/blktap/device.c +21 -34
index 6bb04bd..9a09457 100644
@@ -276,20 +276,17 @@ blktap_device_do_request(struct request_queue *rq)
 
 static void
 blktap_device_configure(struct blktap *tap,
-			struct blktap_device_info *params)
+			struct blktap_device_info *info)
 {
-	struct request_queue *rq;
-	struct blktap_device *dev = &tap->device;
-
-	dev = &tap->device;
-	rq  = dev->gd->queue;
-
-	spin_lock_irq(&dev->lock);
+	struct blktap_device *tapdev = &tap->device;
+	struct gendisk *gd = tapdev->gd;
+	struct request_queue *rq = gd->queue;
 
-	set_capacity(dev->gd, params->capacity);
+	set_capacity(gd, info->capacity);
+	set_disk_ro(gd, !!(info->flags & BLKTAP_DEVICE_FLAG_RO));
 
 	/* Hard sector size and max sectors impersonate the equiv. hardware. */
-	blk_queue_logical_block_size(rq, params->sector_size);
+	blk_queue_logical_block_size(rq, info->sector_size);
 	blk_queue_max_sectors(rq, 512);
 
 	/* Each segment in a request is up to an aligned page in size. */
@@ -305,38 +302,30 @@ blktap_device_configure(struct blktap *tap,
 
 	/* We are reordering, but cacheless. */
 	blk_queue_ordered(rq, QUEUE_ORDERED_DRAIN, NULL);
-
-	spin_unlock_irq(&dev->lock);
 }
 
 static int
-blktap_device_validate_params(struct blktap *tap,
-			      struct blktap_device_info *params)
+blktap_device_validate_info(struct blktap *tap,
+			    struct blktap_device_info *info)
 {
 	struct device *dev = tap->ring.dev;
-	int sector_order, name_sz;
-
-	sector_order = ffs(params->sector_size) - 1;
+	int sector_order;
 
+	sector_order = ffs(info->sector_size) - 1;
 	if (sector_order <  9 ||
 	    sector_order > 12 ||
-	    params->sector_size != 1U<<sector_order)
-		goto fail;
-
-	if (!params->capacity ||
-	    (params->capacity > ULLONG_MAX >> sector_order))
+	    info->sector_size != 1U<<sector_order)
 		goto fail;
 
-	name_sz = min(sizeof(params->name), sizeof(tap->name));
-	if (strnlen(params->name, name_sz) >= name_sz)
+	if (!info->capacity ||
+	    (info->capacity > ULLONG_MAX >> sector_order))
 		goto fail;
 
 	return 0;
 
 fail:
-	params->name[name_sz-1] = 0;
-	dev_err(dev, "capacity: %llu, sector-size: %lu, name: %s\n",
-		params->capacity, params->sector_size, params->name);
+	dev_err(dev, "capacity: %llu, sector-size: %u\n",
+		info->capacity, info->sector_size);
 	return -EINVAL;
 }
 
@@ -425,7 +414,7 @@ blktap_device_destroy_sync(struct blktap *tap)
 }
 
 int
-blktap_device_create(struct blktap *tap, struct blktap_device_info *params)
+blktap_device_create(struct blktap *tap, struct blktap_device_info *info)
 {
 	int minor, err;
 	struct gendisk *gd;
@@ -440,7 +429,7 @@ blktap_device_create(struct blktap *tap, struct blktap_device_info *params)
 	if (test_bit(BLKTAP_DEVICE, &tap->dev_inuse))
 		return -EEXIST;
 
-	if (blktap_device_validate_params(tap, params))
+	if (blktap_device_validate_info(tap, info))
 		return -EINVAL;
 
 	gd = alloc_disk(1);
@@ -479,16 +468,14 @@ blktap_device_create(struct blktap *tap, struct blktap_device_info *params)
 	rq->queuedata = tapdev;
 	tapdev->gd    = gd;
 
-	blktap_device_configure(tap, params);
+	blktap_device_configure(tap, info);
 	add_disk(gd);
 
-	if (params->name[0])
-		strncpy(tap->name, params->name, sizeof(tap->name)-1);
-
 	set_bit(BLKTAP_DEVICE, &tap->dev_inuse);
 
-	dev_info(disk_to_dev(gd), "sector-size: %u capacity: %llu\n",
+	dev_info(disk_to_dev(gd), "sector-size: %u/%u capacity: %llu\n",
 		 queue_logical_block_size(rq),
+		 queue_physical_block_size(rq),
 		 (unsigned long long)get_capacity(gd));
 
 	return 0;
drivers/xen/blktap/ring.c +44 -4

70 lines not on this page · raw message

include/linux/blktap.h +13 -5
index ec33429..2c3c924 100644
@@ -13,10 +13,10 @@
 #define BLKTAP_IOCTL_RESPOND        1
 #define BLKTAP_IOCTL_ALLOC_TAP      200
 #define BLKTAP_IOCTL_FREE_TAP       201
-#define BLKTAP_IOCTL_CREATE_DEVICE  202
+#define BLKTAP_IOCTL_CREATE_DEVICE  208
 #define BLKTAP_IOCTL_REMOVE_DEVICE  207
 
-#define BLKTAP_NAME_MAX             256
+#define BLKTAP_DEVICE_FLAG_RO       0x00000001UL /* disk is R/O */
 
 struct blktap_info {
 	unsigned int            ring_major;
@@ -25,9 +25,9 @@ struct blktap_info {
 };
 
 struct blktap_device_info {
-	char                    name[BLKTAP_NAME_MAX];
 	unsigned long long      capacity;
-	unsigned long           sector_size;
+	unsigned int            sector_size;
+	unsigned long           flags;
 };
 
 /*
@@ -77,9 +77,17 @@ DEFINE_RING_TYPES(blktap, struct blktap_ring_request, struct blktap_ring_respons
 #define BLKTAP_RING_SIZE __CONST_RING_SIZE(blktap, BLKTAP_PAGE_SIZE)
 
 /*
- * Ring messages (DEPRECATED)
+ * Ring messages + old ioctls (DEPRECATED)
  */
 
 #define BLKTAP_RING_MESSAGE_CLOSE   3
+#define BLKTAP_IOCTL_CREATE_DEVICE_COMPAT 202
+#define BLKTAP_NAME_MAX 256
+
+struct blktap2_params {
+	char               name[BLKTAP_NAME_MAX];
+	unsigned long long capacity;
+	unsigned long      sector_size;
+};
 
 #endif /* _LINUX_BLKTAP_H */
Signature · 1 line
1.7.0.4
#7 lore raw

PATCH 3/10 blktap: Move from drivers/xen to drivers/block

In reply to Daniel Stodden

From: Daniel Stodden <[email protected]>

---
 drivers/block/Kconfig          |    9 +
 drivers/block/Makefile         |    1 +
 drivers/block/blktap/Makefile  |    3 +
 drivers/block/blktap/blktap.h  |  161 +++++++++++
 drivers/block/blktap/control.c |  315 +++++++++++++++++++++
 drivers/block/blktap/device.c  |  551 +++++++++++++++++++++++++++++++++++++
 drivers/block/blktap/request.c |  418 ++++++++++++++++++++++++++++
 drivers/block/blktap/ring.c    |  595 ++++++++++++++++++++++++++++++++++++++++
 drivers/block/blktap/sysfs.c   |  288 +++++++++++++++++++
 drivers/xen/Kconfig            |   11 -
 drivers/xen/Makefile           |    1 -
 drivers/xen/blktap/Makefile    |    3 -
 drivers/xen/blktap/blktap.h    |  161 -----------
 drivers/xen/blktap/control.c   |  315 ---------------------
 drivers/xen/blktap/device.c    |  551 -------------------------------------
 drivers/xen/blktap/request.c   |  418 ----------------------------
 drivers/xen/blktap/ring.c      |  595 ----------------------------------------
 drivers/xen/blktap/sysfs.c     |  288 -------------------
 18 files changed, 2341 insertions(+), 2343 deletions(-)
 create mode 100644 drivers/block/blktap/Makefile
 create mode 100644 drivers/block/blktap/blktap.h
 create mode 100644 drivers/block/blktap/control.c
 create mode 100644 drivers/block/blktap/device.c
 create mode 100644 drivers/block/blktap/request.c
 create mode 100644 drivers/block/blktap/ring.c
 create mode 100644 drivers/block/blktap/sysfs.c
 delete mode 100644 drivers/xen/blktap/Makefile
 delete mode 100644 drivers/xen/blktap/blktap.h
 delete mode 100644 drivers/xen/blktap/control.c
 delete mode 100644 drivers/xen/blktap/device.c
 delete mode 100644 drivers/xen/blktap/request.c
 delete mode 100644 drivers/xen/blktap/ring.c
 delete mode 100644 drivers/xen/blktap/sysfs.c
drivers/block/Kconfig +9 -0
index bea8ae7..c4a55a3 100644
@@ -471,4 +471,13 @@ config BLK_DEV_HD
 
 	  If unsure, say N.
 
+config BLK_DEV_TAP
+	tristate "Blktap userspace devices"
+	help
+	  The block tap driver allows block device requests to be
+	  redirected to processes, through a device interface.
+	  Doing so allows user-space development of high-performance
+	  block storage backends, where disk images may be implemented
+	  as files, in memory, or on other hosts across the network.
+
 endif # BLK_DEV
drivers/block/Makefile +1 -0
index 7755a5e..8389917 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_BLK_DEV_UMEM)	+= umem.o
 obj-$(CONFIG_BLK_DEV_NBD)	+= nbd.o
 obj-$(CONFIG_BLK_DEV_CRYPTOLOOP) += cryptoloop.o
 obj-$(CONFIG_VIRTIO_BLK)	+= virtio_blk.o
+obj-$(CONFIG_BLK_DEV_TAP)	+= blktap/
 
 obj-$(CONFIG_VIODASD)		+= viodasd.o
 obj-$(CONFIG_BLK_DEV_SX8)	+= sx8.o
drivers/block/blktap/Makefile new file +3 -0
new file mode 100644
index 0000000..923a7c5
@@ -0,0 +1,3 @@
+obj-$(CONFIG_BLK_DEV_TAP) := blktap.o
+
+blktap-objs := control.o ring.o device.o request.o sysfs.o
drivers/block/blktap/blktap.h new file +161 -0

161 lines not on this page · raw message

drivers/block/blktap/control.c new file +315 -0

315 lines not on this page · raw message

drivers/block/blktap/device.c new file +551 -0

551 lines not on this page · raw message

drivers/block/blktap/request.c new file +418 -0

418 lines not on this page · raw message

drivers/block/blktap/ring.c new file +595 -0

595 lines not on this page · raw message

drivers/block/blktap/sysfs.c new file +288 -0

288 lines not on this page · raw message

drivers/xen/Kconfig +0 -11
index c34e71c..b951b83 100644
@@ -45,17 +45,6 @@ config XEN_BLKDEV_BACKEND
 	  interface.
 
  
-config XEN_BLKDEV_TAP
-	tristate "Block-device tap backend driver"
-	depends on XEN_BACKEND && BLOCK
-	help
-	  The block tap driver is an alternative to the block back driver
-	  and allows VM block requests to be redirected to userspace through
-	  a device interface.  The tap allows user-space development of
-	  high-performance block backends, where disk images may be implemented
-	  as files, in memory, or on other hosts across the network.  This
-	  driver can safely coexist with the existing blockback driver.
-
 config XEN_BLKBACK_PAGEMAP
 	tristate
 	depends on XEN_BLKDEV_BACKEND != n && XEN_BLKDEV_TAP != n
drivers/xen/Makefile +0 -1
index aa4d6e2..44f835e 100644
@@ -6,6 +6,5 @@ obj-$(CONFIG_XEN_XENCOMM)		+= xencomm.o
 obj-$(CONFIG_XEN_BALLOON)		+= balloon.o
 obj-$(CONFIG_XEN_DEV_EVTCHN)	+= evtchn.o
 obj-$(CONFIG_XEN_BLKDEV_BACKEND)	+= blkback/
-obj-$(CONFIG_XEN_BLKDEV_TAP)            += blktap/
 obj-$(CONFIG_XENFS)			+= xenfs/
 obj-$(CONFIG_XEN_SYS_HYPERVISOR)	+= sys-hypervisor.o
\ No newline at end of file
drivers/xen/blktap/Makefile deleted +0 -3
deleted file mode 100644
index 822b4e4..0000000
@@ -1,3 +0,0 @@
-obj-$(CONFIG_XEN_BLKDEV_TAP) := blktap.o
-
-blktap-objs := control.o ring.o device.o request.o sysfs.o
drivers/xen/blktap/blktap.h deleted +0 -161

161 lines not on this page · raw message

drivers/xen/blktap/control.c deleted +0 -315

315 lines not on this page · raw message

drivers/xen/blktap/device.c deleted +0 -551

146 lines not on this page · raw message

drivers/xen/blktap/request.c deleted +0 -418

418 lines not on this page · raw message

drivers/xen/blktap/ring.c deleted +0 -595

595 lines not on this page · raw message

drivers/xen/blktap/sysfs.c deleted +0 -288

288 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.0.4

Part of the diff is not shown here. View the raw message.

#8 lore raw

Re: [PATCH 03/10] blktap: Move from drivers/xen to drivers/block

Quoted 29 lines · Daniel Stodden

From: Daniel Stodden <[email protected]>

---
 drivers/block/Kconfig          |    9 +
 drivers/block/Makefile         |    1 +
 drivers/block/blktap/Makefile  |    3 +
 drivers/block/blktap/blktap.h  |  161 +++++++++++
 drivers/block/blktap/control.c |  315 +++++++++++++++++++++
 drivers/block/blktap/device.c  |  551 +++++++++++++++++++++++++++++++++++++
 drivers/block/blktap/request.c |  418 ++++++++++++++++++++++++++++
 drivers/block/blktap/ring.c    |  595 ++++++++++++++++++++++++++++++++++++++++
 drivers/block/blktap/sysfs.c   |  288 +++++++++++++++++++
 drivers/xen/Kconfig            |   11 -
 drivers/xen/Makefile           |    1 -
 drivers/xen/blktap/Makefile    |    3 -
 drivers/xen/blktap/blktap.h    |  161 -----------
 drivers/xen/blktap/control.c   |  315 ---------------------
 drivers/xen/blktap/device.c    |  551 -------------------------------------
 drivers/xen/blktap/request.c   |  418 ----------------------------
 drivers/xen/blktap/ring.c      |  595 ----------------------------------------
 drivers/xen/blktap/sysfs.c     |  288 -------------------
 18 files changed, 2341 insertions(+), 2343 deletions(-)
 create mode 100644 drivers/block/blktap/Makefile
 create mode 100644 drivers/block/blktap/blktap.h
 create mode 100644 drivers/block/blktap/control.c
 create mode 100644 drivers/block/blktap/device.c
 create mode 100644 drivers/block/blktap/request.c
 create mode 100644 drivers/block/blktap/ring.c
Quoted 8 lines
 create mode 100644 drivers/block/blktap/sysfs.c
 delete mode 100644 drivers/xen/blktap/Makefile
 delete mode 100644 drivers/xen/blktap/blktap.h
 delete mode 100644 drivers/xen/blktap/control.c
 delete mode 100644 drivers/xen/blktap/device.c
 delete mode 100644 drivers/xen/blktap/request.c
 delete mode 100644 drivers/xen/blktap/ring.c
 delete mode 100644 drivers/xen/blktap/sysfs.c

Given the right options "git format-patch" should display this as:

 drivers/block/Kconfig                   |    9 +++++++++
 drivers/block/Makefile                  |    1 +
 drivers/{xen => block}/blktap/Makefile  |    2 +-
 drivers/{xen => block}/blktap/blktap.h  |    0 
 drivers/{xen => block}/blktap/control.c |    0 
 drivers/{xen => block}/blktap/device.c  |    0 
 drivers/{xen => block}/blktap/request.c |    0 
 drivers/{xen => block}/blktap/ring.c    |    0 
 drivers/{xen => block}/blktap/sysfs.c   |    0 
 drivers/xen/Kconfig                     |   11 -----------
 drivers/xen/Makefile                    |    1 -
 11 files changed, 11 insertions(+), 13 deletions(-)

[...]

drivers/block/blktap/blktap.h renamed from drivers/xen/blktap/blktap.h +0 -0
similarity index 100%
rename from drivers/xen/blktap/blktap.h
rename to drivers/block/blktap/blktap.h

[...]
which is far easier to review.

I think it's -M you want.

Ian.

#9 lore raw

Re: [PATCH 03/10] blktap: Move from drivers/xen to drivers/block

Quoted 60 lines · Ian Campbell
Quoted 29 lines · Daniel Stodden

From: Daniel Stodden <[email protected]>

---
 drivers/block/Kconfig          |    9 +
 drivers/block/Makefile         |    1 +
 drivers/block/blktap/Makefile  |    3 +
 drivers/block/blktap/blktap.h  |  161 +++++++++++
 drivers/block/blktap/control.c |  315 +++++++++++++++++++++
 drivers/block/blktap/device.c  |  551 +++++++++++++++++++++++++++++++++++++
 drivers/block/blktap/request.c |  418 ++++++++++++++++++++++++++++
 drivers/block/blktap/ring.c    |  595 ++++++++++++++++++++++++++++++++++++++++
 drivers/block/blktap/sysfs.c   |  288 +++++++++++++++++++
 drivers/xen/Kconfig            |   11 -
 drivers/xen/Makefile           |    1 -
 drivers/xen/blktap/Makefile    |    3 -
 drivers/xen/blktap/blktap.h    |  161 -----------
 drivers/xen/blktap/control.c   |  315 ---------------------
 drivers/xen/blktap/device.c    |  551 -------------------------------------
 drivers/xen/blktap/request.c   |  418 ----------------------------
 drivers/xen/blktap/ring.c      |  595 ----------------------------------------
 drivers/xen/blktap/sysfs.c     |  288 -------------------
 18 files changed, 2341 insertions(+), 2343 deletions(-)
 create mode 100644 drivers/block/blktap/Makefile
 create mode 100644 drivers/block/blktap/blktap.h
 create mode 100644 drivers/block/blktap/control.c
 create mode 100644 drivers/block/blktap/device.c
 create mode 100644 drivers/block/blktap/request.c
 create mode 100644 drivers/block/blktap/ring.c
Quoted 8 lines
 create mode 100644 drivers/block/blktap/sysfs.c
 delete mode 100644 drivers/xen/blktap/Makefile
 delete mode 100644 drivers/xen/blktap/blktap.h
 delete mode 100644 drivers/xen/blktap/control.c
 delete mode 100644 drivers/xen/blktap/device.c
 delete mode 100644 drivers/xen/blktap/request.c
 delete mode 100644 drivers/xen/blktap/ring.c
 delete mode 100644 drivers/xen/blktap/sysfs.c

Given the right options "git format-patch" should display this as:

 drivers/block/Kconfig                   |    9 +++++++++
 drivers/block/Makefile                  |    1 +
 drivers/{xen => block}/blktap/Makefile  |    2 +-
 drivers/{xen => block}/blktap/blktap.h  |    0 
 drivers/{xen => block}/blktap/control.c |    0 
 drivers/{xen => block}/blktap/device.c  |    0 
 drivers/{xen => block}/blktap/request.c |    0 
 drivers/{xen => block}/blktap/ring.c    |    0 
 drivers/{xen => block}/blktap/sysfs.c   |    0 
 drivers/xen/Kconfig                     |   11 -----------
 drivers/xen/Makefile                    |    1 -
 11 files changed, 11 insertions(+), 13 deletions(-)

[...]

drivers/block/blktap/blktap.h renamed from drivers/xen/blktap/blktap.h +0 -0
similarity index 100%
rename from drivers/xen/blktap/blktap.h
rename to drivers/block/blktap/blktap.h
[...]

which is far easier to review.

Quoted 1 line

I think it's -M you want.

Hmm, sounds true.

Back then when I created that change, I'm pretty sure I performed a number of git mv, applied some fixup and committed.

I rebased that tree a couple times, though. Do you mean to say I must have broken that commit somehere.

Okay, I'll try it again and see if that improves the output.

Daniel

#10 lore raw

Re: [PATCH 03/10] blktap: Move from drivers/xen to drivers/block

Quoted 65 lines · Daniel Stodden
Quoted 60 lines · Ian Campbell
Quoted 29 lines · Daniel Stodden

From: Daniel Stodden <[email protected]>

---
 drivers/block/Kconfig          |    9 +
 drivers/block/Makefile         |    1 +
 drivers/block/blktap/Makefile  |    3 +
 drivers/block/blktap/blktap.h  |  161 +++++++++++
 drivers/block/blktap/control.c |  315 +++++++++++++++++++++
 drivers/block/blktap/device.c  |  551 +++++++++++++++++++++++++++++++++++++
 drivers/block/blktap/request.c |  418 ++++++++++++++++++++++++++++
 drivers/block/blktap/ring.c    |  595 ++++++++++++++++++++++++++++++++++++++++
 drivers/block/blktap/sysfs.c   |  288 +++++++++++++++++++
 drivers/xen/Kconfig            |   11 -
 drivers/xen/Makefile           |    1 -
 drivers/xen/blktap/Makefile    |    3 -
 drivers/xen/blktap/blktap.h    |  161 -----------
 drivers/xen/blktap/control.c   |  315 ---------------------
 drivers/xen/blktap/device.c    |  551 -------------------------------------
 drivers/xen/blktap/request.c   |  418 ----------------------------
 drivers/xen/blktap/ring.c      |  595 ----------------------------------------
 drivers/xen/blktap/sysfs.c     |  288 -------------------
 18 files changed, 2341 insertions(+), 2343 deletions(-)
 create mode 100644 drivers/block/blktap/Makefile
 create mode 100644 drivers/block/blktap/blktap.h
 create mode 100644 drivers/block/blktap/control.c
 create mode 100644 drivers/block/blktap/device.c
 create mode 100644 drivers/block/blktap/request.c
 create mode 100644 drivers/block/blktap/ring.c
Quoted 8 lines
 create mode 100644 drivers/block/blktap/sysfs.c
 delete mode 100644 drivers/xen/blktap/Makefile
 delete mode 100644 drivers/xen/blktap/blktap.h
 delete mode 100644 drivers/xen/blktap/control.c
 delete mode 100644 drivers/xen/blktap/device.c
 delete mode 100644 drivers/xen/blktap/request.c
 delete mode 100644 drivers/xen/blktap/ring.c
 delete mode 100644 drivers/xen/blktap/sysfs.c

Given the right options "git format-patch" should display this as:

 drivers/block/Kconfig                   |    9 +++++++++
 drivers/block/Makefile                  |    1 +
 drivers/{xen => block}/blktap/Makefile  |    2 +-
 drivers/{xen => block}/blktap/blktap.h  |    0 
 drivers/{xen => block}/blktap/control.c |    0 
 drivers/{xen => block}/blktap/device.c  |    0 
 drivers/{xen => block}/blktap/request.c |    0 
 drivers/{xen => block}/blktap/ring.c    |    0 
 drivers/{xen => block}/blktap/sysfs.c   |    0 
 drivers/xen/Kconfig                     |   11 -----------
 drivers/xen/Makefile                    |    1 -
 11 files changed, 11 insertions(+), 13 deletions(-)

[...]

drivers/block/blktap/blktap.h renamed from drivers/xen/blktap/blktap.h +0 -0
similarity index 100%
rename from drivers/xen/blktap/blktap.h
rename to drivers/block/blktap/blktap.h
[...]

which is far easier to review.

Quoted 1 line

I think it's -M you want.

Hmm, sounds true.

Quoted 7 lines

Back then when I created that change, I'm pretty sure I performed a number of git mv, applied some fixup and committed.

I rebased that tree a couple times, though. Do you mean to say I must have broken that commit somehere.

Okay, I'll try it again and see if that improves the output.

Thinking of it: Iirc this diff is not only a plain rename, there were some additional changes made in source to have everything compile again. Could that be the reason?

Want those split out?

Thanks,
Daniel

#11 lore raw

Re: [PATCH 03/10] blktap: Move from drivers/xen to drivers/block

Quoted 72 lines · Daniel Stodden
Quoted 71 lines · Daniel Stodden
Quoted 60 lines · Ian Campbell
Quoted 29 lines · Daniel Stodden

From: Daniel Stodden <[email protected]>

---
 drivers/block/Kconfig          |    9 +
 drivers/block/Makefile         |    1 +
 drivers/block/blktap/Makefile  |    3 +
 drivers/block/blktap/blktap.h  |  161 +++++++++++
 drivers/block/blktap/control.c |  315 +++++++++++++++++++++
 drivers/block/blktap/device.c  |  551 +++++++++++++++++++++++++++++++++++++
 drivers/block/blktap/request.c |  418 ++++++++++++++++++++++++++++
 drivers/block/blktap/ring.c    |  595 ++++++++++++++++++++++++++++++++++++++++
 drivers/block/blktap/sysfs.c   |  288 +++++++++++++++++++
 drivers/xen/Kconfig            |   11 -
 drivers/xen/Makefile           |    1 -
 drivers/xen/blktap/Makefile    |    3 -
 drivers/xen/blktap/blktap.h    |  161 -----------
 drivers/xen/blktap/control.c   |  315 ---------------------
 drivers/xen/blktap/device.c    |  551 -------------------------------------
 drivers/xen/blktap/request.c   |  418 ----------------------------
 drivers/xen/blktap/ring.c      |  595 ----------------------------------------
 drivers/xen/blktap/sysfs.c     |  288 -------------------
 18 files changed, 2341 insertions(+), 2343 deletions(-)
 create mode 100644 drivers/block/blktap/Makefile
 create mode 100644 drivers/block/blktap/blktap.h
 create mode 100644 drivers/block/blktap/control.c
 create mode 100644 drivers/block/blktap/device.c
 create mode 100644 drivers/block/blktap/request.c
 create mode 100644 drivers/block/blktap/ring.c
Quoted 8 lines
 create mode 100644 drivers/block/blktap/sysfs.c
 delete mode 100644 drivers/xen/blktap/Makefile
 delete mode 100644 drivers/xen/blktap/blktap.h
 delete mode 100644 drivers/xen/blktap/control.c
 delete mode 100644 drivers/xen/blktap/device.c
 delete mode 100644 drivers/xen/blktap/request.c
 delete mode 100644 drivers/xen/blktap/ring.c
 delete mode 100644 drivers/xen/blktap/sysfs.c

Given the right options "git format-patch" should display this as:

 drivers/block/Kconfig                   |    9 +++++++++
 drivers/block/Makefile                  |    1 +
 drivers/{xen => block}/blktap/Makefile  |    2 +-
 drivers/{xen => block}/blktap/blktap.h  |    0 
 drivers/{xen => block}/blktap/control.c |    0 
 drivers/{xen => block}/blktap/device.c  |    0 
 drivers/{xen => block}/blktap/request.c |    0 
 drivers/{xen => block}/blktap/ring.c    |    0 
 drivers/{xen => block}/blktap/sysfs.c   |    0 
 drivers/xen/Kconfig                     |   11 -----------
 drivers/xen/Makefile                    |    1 -
 11 files changed, 11 insertions(+), 13 deletions(-)

[...]

drivers/block/blktap/blktap.h renamed from drivers/xen/blktap/blktap.h +0 -0
similarity index 100%
rename from drivers/xen/blktap/blktap.h
rename to drivers/block/blktap/blktap.h
[...]

which is far easier to review.

Quoted 1 line

I think it's -M you want.

Hmm, sounds true.

Back then when I created that change, I'm pretty sure I performed a number of git mv, applied some fixup and committed.

I rebased that tree a couple times, though. Do you mean to say I must have broken that commit somehere.

Quoted 7 lines
Quoted 1 line

Okay, I'll try it again and see if that improves the output.

Thinking of it: Iirc this diff is not only a plain rename, there were some additional changes made in source to have everything compile again. Could that be the reason?

Want those split out?

Oooh, scratch that, that's not even the case.

I seem to finally be getting what you're really talking about. This is not really a broken commit, it's solely about send-email not enabling rename *detection*. Interesting, I always assumed the renaming case must be a property of the commit object, not a diff feature.

That correct now?

Daniel

#12 lore raw

Re: [PATCH 03/10] blktap: Move from drivers/xen to drivers/block

Quoted 79 lines · Daniel Stodden
Quoted 78 lines · Daniel Stodden
Quoted 65 lines · Daniel Stodden
Quoted 60 lines · Ian Campbell
Quoted 29 lines · Daniel Stodden

From: Daniel Stodden <[email protected]>

---
 drivers/block/Kconfig          |    9 +
 drivers/block/Makefile         |    1 +
 drivers/block/blktap/Makefile  |    3 +
 drivers/block/blktap/blktap.h  |  161 +++++++++++
 drivers/block/blktap/control.c |  315 +++++++++++++++++++++
 drivers/block/blktap/device.c  |  551 +++++++++++++++++++++++++++++++++++++
 drivers/block/blktap/request.c |  418 ++++++++++++++++++++++++++++
 drivers/block/blktap/ring.c    |  595 ++++++++++++++++++++++++++++++++++++++++
 drivers/block/blktap/sysfs.c   |  288 +++++++++++++++++++
 drivers/xen/Kconfig            |   11 -
 drivers/xen/Makefile           |    1 -
 drivers/xen/blktap/Makefile    |    3 -
 drivers/xen/blktap/blktap.h    |  161 -----------
 drivers/xen/blktap/control.c   |  315 ---------------------
 drivers/xen/blktap/device.c    |  551 -------------------------------------
 drivers/xen/blktap/request.c   |  418 ----------------------------
 drivers/xen/blktap/ring.c      |  595 ----------------------------------------
 drivers/xen/blktap/sysfs.c     |  288 -------------------
 18 files changed, 2341 insertions(+), 2343 deletions(-)
 create mode 100644 drivers/block/blktap/Makefile
 create mode 100644 drivers/block/blktap/blktap.h
 create mode 100644 drivers/block/blktap/control.c
 create mode 100644 drivers/block/blktap/device.c
 create mode 100644 drivers/block/blktap/request.c
 create mode 100644 drivers/block/blktap/ring.c
Quoted 8 lines
 create mode 100644 drivers/block/blktap/sysfs.c
 delete mode 100644 drivers/xen/blktap/Makefile
 delete mode 100644 drivers/xen/blktap/blktap.h
 delete mode 100644 drivers/xen/blktap/control.c
 delete mode 100644 drivers/xen/blktap/device.c
 delete mode 100644 drivers/xen/blktap/request.c
 delete mode 100644 drivers/xen/blktap/ring.c
 delete mode 100644 drivers/xen/blktap/sysfs.c

Given the right options "git format-patch" should display this as:

 drivers/block/Kconfig                   |    9 +++++++++
 drivers/block/Makefile                  |    1 +
 drivers/{xen => block}/blktap/Makefile  |    2 +-
 drivers/{xen => block}/blktap/blktap.h  |    0 
 drivers/{xen => block}/blktap/control.c |    0 
 drivers/{xen => block}/blktap/device.c  |    0 
 drivers/{xen => block}/blktap/request.c |    0 
 drivers/{xen => block}/blktap/ring.c    |    0 
 drivers/{xen => block}/blktap/sysfs.c   |    0 
 drivers/xen/Kconfig                     |   11 -----------
 drivers/xen/Makefile                    |    1 -
 11 files changed, 11 insertions(+), 13 deletions(-)

[...]

drivers/block/blktap/blktap.h renamed from drivers/xen/blktap/blktap.h +0 -0
similarity index 100%
rename from drivers/xen/blktap/blktap.h
rename to drivers/block/blktap/blktap.h
[...]

which is far easier to review.

Quoted 1 line

I think it's -M you want.

Hmm, sounds true.

Quoted 7 lines

Back then when I created that change, I'm pretty sure I performed a number of git mv, applied some fixup and committed.

I rebased that tree a couple times, though. Do you mean to say I must have broken that commit somehere.

Okay, I'll try it again and see if that improves the output.

Thinking of it: Iirc this diff is not only a plain rename, there were some additional changes made in source to have everything compile again. Could that be the reason?

Quoted 8 lines
Quoted 1 line

Want those split out?

Oooh, scratch that, that's not even the case.

I seem to finally be getting what you're really talking about. This is not really a broken commit, it's solely about send-email not enabling rename *detection*. Interesting, I always assumed the renaming case must be a property of the commit object, not a diff feature.

I don't know if it is a feature of the commit metadata (which FWIW I'd expect to be retained over a rebase etc) or something which is computed at diff generation time. In any case -M is required to get the git patch syntax, the default is to be compatible with old-school patch utils.

Quoted 1 line

That correct now?

<[email protected]> looks good.

Quoted 8 lines

Daniel

#13 lore raw

Re: [PATCH 03/10] blktap: Move from drivers/xen to drivers/block

Quoted 12 lines · Ian Campbell
Quoted 6 lines

Oooh, scratch that, that's not even the case.

I seem to finally be getting what you're really talking about. This is not really a broken commit, it's solely about send-email not enabling rename *detection*. Interesting, I always assumed the renaming case must be a property of the commit object, not a diff feature.

I don't know if it is a feature of the commit metadata (which FWIW I'd expect to be retained over a rebase etc) or something which is computed at diff generation time. In any case -M is required to get the git patch syntax, the default is to be compatible with old-school patch utils.

Quoted 4 lines
Quoted 1 line

That correct now?

<[email protected]> looks good.

Okay.

I learned -M is actually a git-diff option passed through. The man page mentions it's O(n^2).

I had to learn all that while wondering if there's a config option to turn it on, and that took me O(n).

It's [diff] renames = true btw, but might be a bad idea.

Cheers.
Daniel

Quoted 10 lines
Quoted 8 lines

Daniel

#14 lore raw

PATCH 1/1 blktap: Move from drivers/xen to drivers/block

In reply to Daniel Stodden

From: Daniel Stodden <[email protected]>

---
 drivers/block/Kconfig                   |    9 +++++++++
 drivers/block/Makefile                  |    1 +
 drivers/{xen => block}/blktap/Makefile  |    2 +-
 drivers/{xen => block}/blktap/blktap.h  |    0
 drivers/{xen => block}/blktap/control.c |    0
 drivers/{xen => block}/blktap/device.c  |    0
 drivers/{xen => block}/blktap/request.c |    0
 drivers/{xen => block}/blktap/ring.c    |    0
 drivers/{xen => block}/blktap/sysfs.c   |    0
 drivers/xen/Kconfig                     |   11 -----------
 drivers/xen/Makefile                    |    1 -
 11 files changed, 11 insertions(+), 13 deletions(-)
 rename drivers/{xen => block}/blktap/Makefile (59%)
 rename drivers/{xen => block}/blktap/blktap.h (100%)
 rename drivers/{xen => block}/blktap/control.c (100%)
 rename drivers/{xen => block}/blktap/device.c (100%)
 rename drivers/{xen => block}/blktap/request.c (100%)
 rename drivers/{xen => block}/blktap/ring.c (100%)
 rename drivers/{xen => block}/blktap/sysfs.c (100%)
drivers/block/Kconfig +9 -0
index bea8ae7..c4a55a3 100644
@@ -471,4 +471,13 @@ config BLK_DEV_HD
 
 	  If unsure, say N.
 
+config BLK_DEV_TAP
+	tristate "Blktap userspace devices"
+	help
+	  The block tap driver allows block device requests to be
+	  redirected to processes, through a device interface.
+	  Doing so allows user-space development of high-performance
+	  block storage backends, where disk images may be implemented
+	  as files, in memory, or on other hosts across the network.
+
 endif # BLK_DEV
drivers/block/Makefile +1 -0
index 7755a5e..8389917 100644
@@ -28,6 +28,7 @@ obj-$(CONFIG_BLK_DEV_UMEM)	+= umem.o
 obj-$(CONFIG_BLK_DEV_NBD)	+= nbd.o
 obj-$(CONFIG_BLK_DEV_CRYPTOLOOP) += cryptoloop.o
 obj-$(CONFIG_VIRTIO_BLK)	+= virtio_blk.o
+obj-$(CONFIG_BLK_DEV_TAP)	+= blktap/
 
 obj-$(CONFIG_VIODASD)		+= viodasd.o
 obj-$(CONFIG_BLK_DEV_SX8)	+= sx8.o
drivers/block/blktap/Makefile renamed from drivers/xen/blktap/Makefile +1 -1
similarity index 59%
rename from drivers/xen/blktap/Makefile
rename to drivers/block/blktap/Makefile
index 822b4e4..923a7c5 100644
@@ -1,3 +1,3 @@
-obj-$(CONFIG_XEN_BLKDEV_TAP) := blktap.o
+obj-$(CONFIG_BLK_DEV_TAP) := blktap.o
 
 blktap-objs := control.o ring.o device.o request.o sysfs.o
drivers/block/blktap/blktap.h renamed from drivers/xen/blktap/blktap.h +0 -0
similarity index 100%
rename from drivers/xen/blktap/blktap.h
rename to drivers/block/blktap/blktap.h
drivers/block/blktap/control.c renamed from drivers/xen/blktap/control.c +0 -0
similarity index 100%
rename from drivers/xen/blktap/control.c
rename to drivers/block/blktap/control.c
drivers/block/blktap/device.c renamed from drivers/xen/blktap/device.c +0 -0
similarity index 100%
rename from drivers/xen/blktap/device.c
rename to drivers/block/blktap/device.c
drivers/block/blktap/request.c renamed from drivers/xen/blktap/request.c +0 -0
similarity index 100%
rename from drivers/xen/blktap/request.c
rename to drivers/block/blktap/request.c
drivers/block/blktap/ring.c renamed from drivers/xen/blktap/ring.c +0 -0
similarity index 100%
rename from drivers/xen/blktap/ring.c
rename to drivers/block/blktap/ring.c
drivers/block/blktap/sysfs.c renamed from drivers/xen/blktap/sysfs.c +0 -0
similarity index 100%
rename from drivers/xen/blktap/sysfs.c
rename to drivers/block/blktap/sysfs.c
drivers/xen/Kconfig +0 -11
index c34e71c..b951b83 100644
@@ -45,17 +45,6 @@ config XEN_BLKDEV_BACKEND
 	  interface.
 
  
-config XEN_BLKDEV_TAP
-	tristate "Block-device tap backend driver"
-	depends on XEN_BACKEND && BLOCK
-	help
-	  The block tap driver is an alternative to the block back driver
-	  and allows VM block requests to be redirected to userspace through
-	  a device interface.  The tap allows user-space development of
-	  high-performance block backends, where disk images may be implemented
-	  as files, in memory, or on other hosts across the network.  This
-	  driver can safely coexist with the existing blockback driver.
-
 config XEN_BLKBACK_PAGEMAP
 	tristate
 	depends on XEN_BLKDEV_BACKEND != n && XEN_BLKDEV_TAP != n
drivers/xen/Makefile +0 -1
index aa4d6e2..44f835e 100644
@@ -6,6 +6,5 @@ obj-$(CONFIG_XEN_XENCOMM)		+= xencomm.o
 obj-$(CONFIG_XEN_BALLOON)		+= balloon.o
 obj-$(CONFIG_XEN_DEV_EVTCHN)	+= evtchn.o
 obj-$(CONFIG_XEN_BLKDEV_BACKEND)	+= blkback/
-obj-$(CONFIG_XEN_BLKDEV_TAP)            += blktap/
 obj-$(CONFIG_XENFS)			+= xenfs/
 obj-$(CONFIG_XEN_SYS_HYPERVISOR)	+= sys-hypervisor.o
\ No newline at end of file
Signature · 1 line
1.7.0.4
#15 lore raw

PATCH 4/10 blktap: Fix reference to freed struct request.

In reply to Daniel Stodden

The request will be freed by the call to __blktap_end_rq(), so rq->q is invalid before spin_unlock_irq().

---
 drivers/block/blktap/device.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/block/blktap/device.c +4 -2
index 9a09457..8caff9f 100644
@@ -135,9 +135,11 @@ __blktap_end_rq(struct request *rq, int err)
 static inline void
 blktap_end_rq(struct request *rq, int err)
 {
-	spin_lock_irq(rq->q->queue_lock);
+	struct request_queue *q = rq->q;
+
+	spin_lock_irq(q->queue_lock);
 	__blktap_end_rq(rq, err);
-	spin_unlock_irq(rq->q->queue_lock);
+	spin_unlock_irq(q->queue_lock);
 }
 
 void
Signature · 1 line
1.7.0.4
#16 lore raw

PATCH 5/10 blktap: Support non-R/W requests

In reply to Daniel Stodden

Special cases segment vector writes on the blktap ring. Anticipate non-fs requests on the queue. Add some switches, for trim or flush operations to settle.

---
 drivers/block/blktap/device.c |   24 ++++++--------
 drivers/block/blktap/ring.c   |   68 +++++++++++++++++++++++++---------------
 2 files changed, 53 insertions(+), 39 deletions(-)
drivers/block/blktap/device.c +11 -13
index 8caff9f..fcf16c9 100644
@@ -166,7 +166,7 @@ blktap_device_make_request(struct blktap *tap, struct request *rq)
 {
 	struct blktap_device *tapdev = &tap->device;
 	struct blktap_request *request;
-	int write, nsegs;
+	int nsegs;
 	int err;
 
 	request = blktap_ring_make_request(tap);
@@ -180,15 +180,17 @@ blktap_device_make_request(struct blktap *tap, struct request *rq)
 		goto fail;
 	}
 
-	write = rq_data_dir(rq) == WRITE;
+	if (!blk_fs_request(rq)) {
+		err = -EOPNOTSUPP;
+		goto fail;
+	}
+
 	nsegs = blk_rq_map_sg(rq->q, rq, request->sg_table);
 
-	dev_dbg(disk_to_dev(tapdev->gd),
-		"make_request: op=%c bytes=%d nsegs=%d\n",
-		write ? 'w' : 'r', blk_rq_bytes(rq), nsegs);
-
-	request->rq = rq;
-	request->operation = write ? BLKTAP_OP_WRITE : BLKTAP_OP_READ;
+	if (rq_data_dir(rq) == WRITE)
+		request->operation = BLKTAP_OP_WRITE;
+	else
+		request->operation = BLKTAP_OP_READ;
 
 	err = blktap_request_get_pages(tap, request, nsegs);
 	if (err)
@@ -198,6 +200,7 @@ blktap_device_make_request(struct blktap *tap, struct request *rq)
 	if (err)
 		goto fail;
 
+	request->rq = rq;
 	blktap_ring_submit_request(tap, request);
 
 	return 0;
@@ -242,11 +245,6 @@ blktap_device_run_queue(struct blktap *tap)
 		if (!rq)
 			break;
 
-		if (!blk_fs_request(rq)) {
-			__blktap_end_queued_rq(rq, -EOPNOTSUPP);
-			continue;
-		}
-
 		spin_unlock_irq(&tapdev->lock);
 
 		err = blktap_device_make_request(tap, rq);
drivers/block/blktap/ring.c +42 -26

114 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#17 lore raw

PATCH 6/10 blktap: Drop the ring message timestamp.

In reply to Daniel Stodden

Using gettimeofday() seems overkill. The debug node now just dumps struct request age at jiffy resolution, not time of ring submission. Looks ok because we never really differentiated from block request time anyway.

---
 drivers/block/blktap/blktap.h |    1 -
 drivers/block/blktap/ring.c   |    8 +++-----
 2 files changed, 3 insertions(+), 6 deletions(-)
drivers/block/blktap/blktap.h +0 -1
index 1318cad..05cfd1f 100644
@@ -78,7 +78,6 @@ struct blktap_request {
 	int                            usr_idx;
 
 	int                            operation;
-	struct timeval                 time;
 
 	struct scatterlist             sg_table[BLKTAP_SEGMENT_MAX];
 	struct page                   *pages[BLKTAP_SEGMENT_MAX];
drivers/block/blktap/ring.c +3 -5
index bae6f82..e667d2d 100644
@@ -304,8 +304,6 @@ blktap_ring_submit_request(struct blktap *tap,
 	}
 
 	ring->ring.req_prod_pvt++;
-
-	do_gettimeofday(&request->time);
 }
 
 static int
@@ -547,20 +545,20 @@ blktap_ring_debug(struct blktap *tap, char *buf, size_t size)
 
 	for (usr_idx = 0; usr_idx < BLKTAP_RING_SIZE; usr_idx++) {
 		struct blktap_request *request;
-		struct timeval *time;
+		struct timeval t;
 
 		request = ring->pending[usr_idx];
 		if (!request)
 			continue;
 
-		time  = &request->time;
+		jiffies_to_timeval(jiffies - request->rq->start_time, &t);
 
 		s += snprintf(s, end - s,
 			      "%02d: usr_idx:%02d "
 			      "op:%x nr_pages:%02d time:%lu.%09lu\n",
 			      usr_idx, request->usr_idx,
 			      request->operation, request->nr_pages,
-			      time->tv_sec, time->tv_usec);
+			      t.tv_sec, t.tv_usec);
 	}
 
 	s += snprintf(s, end - s, "end pending\n");
Signature · 1 line
1.7.0.4
#18 lore raw

PATCH 7/10 blktap: Avoid some header quirks.

In reply to Daniel Stodden

- Include linux/slab.h where needed.
- Avoid the ring typedefs, use struct blktap_x instead.

---
 drivers/block/blktap/blktap.h  |    2 +-
 drivers/block/blktap/control.c |    1 +
 drivers/block/blktap/request.c |    1 +
 drivers/block/blktap/ring.c    |    2 +-
 drivers/block/blktap/sysfs.c   |    2 +-
 5 files changed, 5 insertions(+), 3 deletions(-)
drivers/block/blktap/blktap.h +1 -1
index 05cfd1f..e0f7d99 100644
@@ -44,7 +44,7 @@ struct blktap_ring {
 	struct task_struct            *task;
 
 	struct vm_area_struct         *vma;
-	blktap_front_ring_t            ring;
+	struct blktap_front_ring       ring;
 	unsigned long                  ring_vstart;
 	unsigned long                  user_vstart;
 
drivers/block/blktap/control.c +1 -0
index 57b1a10..9294a13 100644
@@ -2,6 +2,7 @@
 #include <linux/sched.h>
 #include <linux/miscdevice.h>
 #include <linux/device.h>
+#include <linux/slab.h>
 #include <asm/uaccess.h>
 
 #include "blktap.h"
drivers/block/blktap/request.c +1 -0
index 8cfd6c9..e799d08 100644
@@ -3,6 +3,7 @@
 #include <linux/mutex.h>
 #include <linux/sched.h>
 #include <linux/device.h>
+#include <linux/slab.h>
 
 #include "blktap.h"
 
drivers/block/blktap/ring.c +1 -1
index e667d2d..134583d 100644
@@ -352,7 +352,7 @@ blktap_ring_mmap(struct file *filp, struct vm_area_struct *vma)
 {
 	struct blktap *tap = filp->private_data;
 	struct blktap_ring *ring = &tap->ring;
-	blktap_sring_t *sring;
+	struct blktap_sring *sring;
 	struct page *page = NULL;
 	int err;
 
drivers/block/blktap/sysfs.c +1 -1
index 182de9a..97ebc53 100644
@@ -75,7 +75,7 @@ blktap_sysfs_remove_device(struct device *dev,
 		goto wait;
 
 	if (tap->ring.vma) {
-		blktap_sring_t *sring = tap->ring.ring.sring;
+		struct blktap_sring *sring = tap->ring.ring.sring;
 		sring->private.tapif_user.msg = BLKTAP_RING_MESSAGE_CLOSE;
 		blktap_ring_kick_user(tap);
 	} else {
Signature · 1 line
1.7.0.4
#19 lore raw

PATCH 8/10 blktap: Set up physical sector size and alignment offsets.

In reply to Daniel Stodden

Misaligned access wrt to physical block size is a major performance killer. Alignment offsets is for devices which are 'naturally misaligned', e.g. to compensate for stuff like DOS 63S/track partitioning. Accept a BLKTAP_DEVICE_FLAG_PSZ here, and expect userspace to figure out the physical details.

---
 drivers/block/blktap/device.c |   37 +++++++++++++++++++++++++++++++++----
 drivers/block/blktap/ring.c   |    4 ++++
 include/linux/blktap.h        |    3 +++
 3 files changed, 40 insertions(+), 4 deletions(-)
drivers/block/blktap/device.c +33 -4
index fcf16c9..0e8eb0a 100644
@@ -285,10 +285,13 @@ blktap_device_configure(struct blktap *tap,
 	set_capacity(gd, info->capacity);
 	set_disk_ro(gd, !!(info->flags & BLKTAP_DEVICE_FLAG_RO));
 
-	/* Hard sector size and max sectors impersonate the equiv. hardware. */
 	blk_queue_logical_block_size(rq, info->sector_size);
 	blk_queue_max_sectors(rq, 512);
 
+	/* Hard sector size and alignment in hardware */
+	blk_queue_physical_block_size(rq, info->phys_sector_size);
+	blk_queue_alignment_offset(rq, info->phys_sector_offset);
+
 	/* Each segment in a request is up to an aligned page in size. */
 	blk_queue_segment_boundary(rq, PAGE_SIZE - 1);
 	blk_queue_max_segment_size(rq, PAGE_SIZE);
@@ -309,6 +312,7 @@ blktap_device_validate_info(struct blktap *tap,
 			    struct blktap_device_info *info)
 {
 	struct device *dev = tap->ring.dev;
+	unsigned int phys_mask;
 	int sector_order;
 
 	sector_order = ffs(info->sector_size) - 1;
@@ -321,11 +325,34 @@ blktap_device_validate_info(struct blktap *tap,
 	    (info->capacity > ULLONG_MAX >> sector_order))
 		goto fail;
 
+	/* physical blocks default to logical ones */
+	if (!(info->flags & BLKTAP_DEVICE_FLAG_PSZ)) {
+		info->phys_sector_size   = info->sector_size;
+		info->phys_sector_offset = 0;
+	}
+
+	/* phys block size is 2^n and >= logical */
+	sector_order = ilog2(info->phys_sector_size);
+	if (sector_order <  9 ||
+	    info->phys_sector_size != 1U<<sector_order ||
+	    info->phys_sector_size < info->sector_size)
+		goto fail;
+
+	/* alignment offset < physical/logical */
+	phys_mask = (info->phys_sector_size /
+		     info->sector_size) - 1;
+	if ((info->phys_sector_offset & ~phys_mask) != 0)
+		goto fail;
+
 	return 0;
 
 fail:
-	dev_err(dev, "capacity: %llu, sector-size: %u\n",
-		info->capacity, info->sector_size);
+	dev_err(dev,
+		"capacity: %llu, sector-size: %u/%u, "
+		"phys-offset: %u\n",
+		info->capacity, info->sector_size,
+		info->phys_sector_size, info->phys_sector_offset);
+
 	return -EINVAL;
 }
 
@@ -473,9 +500,11 @@ blktap_device_create(struct blktap *tap, struct blktap_device_info *info)
 
 	set_bit(BLKTAP_DEVICE, &tap->dev_inuse);
 
-	dev_info(disk_to_dev(gd), "sector-size: %u/%u capacity: %llu\n",
+	dev_info(disk_to_dev(gd),
+		 "sector-size: %u/%u phys-offset: %d capacity: %llu\n",
 		 queue_logical_block_size(rq),
 		 queue_physical_block_size(rq),
+		 queue_alignment_offset(rq),
 		 (unsigned long long)get_capacity(gd));
 
 	return 0;
drivers/block/blktap/ring.c +4 -0
index 134583d..25bd311 100644
@@ -446,6 +446,7 @@ blktap_ring_ioctl(struct inode *inode, struct file *filp,
 		size_t base_sz, sz;
 
 		mask  = BLKTAP_DEVICE_FLAG_RO;
+		mask |= BLKTAP_DEVICE_FLAG_PSZ;
 
 		memset(&info, 0, sizeof(info));
 		sz = base_sz = BLKTAP_INFO_SIZE_AT(flags);
@@ -453,6 +454,9 @@ blktap_ring_ioctl(struct inode *inode, struct file *filp,
 		if (copy_from_user(&info, ptr, sz))
 			return -EFAULT;
 
+		if ((info.flags & BLKTAP_DEVICE_FLAG_PSZ) != 0)
+			sz = BLKTAP_INFO_SIZE_AT(phys_sector_offset);
+
 		if (sz > base_sz)
 			if (copy_from_user(&info, ptr, sz))
 				return -EFAULT;
include/linux/blktap.h +3 -0
index 2c3c924..9a280d9 100644
@@ -17,6 +17,7 @@
 #define BLKTAP_IOCTL_REMOVE_DEVICE  207
 
 #define BLKTAP_DEVICE_FLAG_RO       0x00000001UL /* disk is R/O */
+#define BLKTAP_DEVICE_FLAG_PSZ      0x00000002UL /* physical sector size */
 
 struct blktap_info {
 	unsigned int            ring_major;
@@ -28,6 +29,8 @@ struct blktap_device_info {
 	unsigned long long      capacity;
 	unsigned int            sector_size;
 	unsigned long           flags;
+	unsigned int            phys_sector_size;
+	unsigned int            phys_sector_offset;
 };
 
 /*
Signature · 1 line
1.7.0.4
#20 lore raw

PATCH 9/10 blktap: device_info validation fixes.

In reply to Daniel Stodden

- Logical block size <= 4k is too paranoid.
- Use ilog2 and add more comments.

---
 drivers/block/blktap/device.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/block/blktap/device.c +3 -2
index 0e8eb0a..2379643 100644
@@ -315,12 +315,13 @@ blktap_device_validate_info(struct blktap *tap,
 	unsigned int phys_mask;
 	int sector_order;
 
-	sector_order = ffs(info->sector_size) - 1;
+	/* sector size is is 2^(n >= 9) */
+	sector_order = ilog2(info->sector_size);
 	if (sector_order <  9 ||
-	    sector_order > 12 ||
 	    info->sector_size != 1U<<sector_order)
 		goto fail;
 
+	/* make sure capacity doesn't overflow */
 	if (!info->capacity ||
 	    (info->capacity > ULLONG_MAX >> sector_order))
 		goto fail;
Signature · 1 line
1.7.0.4
#21 lore raw

PATCH 10/10 blktap: Add BLKTAP_OP_FLUSH command option.

In reply to Daniel Stodden

Wants to be enabled by userspace with a device flag. Semantics equal a cache flush, i.e. durability for completed I/O but no particular ordering constraints of in-flight requests.

---
 drivers/block/blktap/blktap.h |    1 +
 drivers/block/blktap/device.c |   30 ++++++++++++++++++++++++++----
 drivers/block/blktap/ring.c   |    7 +++++++
 include/linux/blktap.h        |    2 ++
 4 files changed, 36 insertions(+), 4 deletions(-)
drivers/block/blktap/blktap.h +1 -0
index e0f7d99..1b63d0e 100644
@@ -62,6 +62,7 @@ struct blktap_statistics {
 	int                            st_rd_req;
 	int                            st_wr_req;
 	int                            st_oo_req;
+	int                            st_fl_req;
 	int                            st_rd_sect;
 	int                            st_wr_sect;
 	s64                            st_rd_cnt;
drivers/block/blktap/device.c +26 -4
index 2379643..74c3daf 100644
@@ -161,6 +161,15 @@ blktap_device_end_request(struct blktap *tap,
 	blktap_end_rq(rq, error);
 }
 
+static void
+blktap_device_prepare_flush(struct request_queue *q, struct request *rq)
+{
+	rq->cmd_type = REQ_TYPE_BLOCK_PC;
+	rq->timeout  = q->rq_timeout;
+	rq->cmd[0]   = BLKTAP_OP_FLUSH;
+	rq->cmd_len  = 1;
+}
+
 int
 blktap_device_make_request(struct blktap *tap, struct request *rq)
 {
@@ -180,6 +189,12 @@ blktap_device_make_request(struct blktap *tap, struct request *rq)
 		goto fail;
 	}
 
+	if (blk_pc_request(rq)) {
+		request->operation = rq->cmd[0];
+		request->nr_pages  = 0;
+		goto submit;
+	}
+
 	if (!blk_fs_request(rq)) {
 		err = -EOPNOTSUPP;
 		goto fail;
@@ -200,6 +215,7 @@ blktap_device_make_request(struct blktap *tap, struct request *rq)
 	if (err)
 		goto fail;
 
+submit:
 	request->rq = rq;
 	blktap_ring_submit_request(tap, request);
 
@@ -303,8 +319,12 @@ blktap_device_configure(struct blktap *tap,
 	/* Make sure buffer addresses are sector-aligned. */
 	blk_queue_dma_alignment(rq, 511);
 
-	/* We are reordering, but cacheless. */
-	blk_queue_ordered(rq, QUEUE_ORDERED_DRAIN, NULL);
+	/* Enable cache control */
+	if (info->flags & BLKTAP_DEVICE_FLAG_FLUSH)
+		blk_queue_ordered(rq, QUEUE_ORDERED_DRAIN_FLUSH,
+				  blktap_device_prepare_flush);
+	else
+		blk_queue_ordered(rq, QUEUE_ORDERED_DRAIN, NULL);
 }
 
 static int
@@ -502,11 +522,13 @@ blktap_device_create(struct blktap *tap, struct blktap_device_info *info)
 	set_bit(BLKTAP_DEVICE, &tap->dev_inuse);
 
 	dev_info(disk_to_dev(gd),
-		 "sector-size: %u/%u phys-offset: %d capacity: %llu\n",
+		 "sector-size: %u/%u phys-offset: %d capacity: %llu"
+		 " ordered: %#x\n",
 		 queue_logical_block_size(rq),
 		 queue_physical_block_size(rq),
 		 queue_alignment_offset(rq),
-		 (unsigned long long)get_capacity(gd));
+		 (unsigned long long)get_capacity(gd),
+		 rq->ordered);
 
 	return 0;
 
drivers/block/blktap/ring.c +7 -0
index 25bd311..9a7696e 100644
@@ -299,6 +299,12 @@ blktap_ring_submit_request(struct blktap *tap,
 		tap->stats.st_wr_sect += nsecs;
 		tap->stats.st_wr_req++;
 		break;
+
+	case BLKTAP_OP_FLUSH:
+		breq->sector_number = 0;
+		tap->stats.st_fl_req++;
+		break;
+
 	default:
 		BUG();
 	}
@@ -447,6 +453,7 @@ blktap_ring_ioctl(struct inode *inode, struct file *filp,
 
 		mask  = BLKTAP_DEVICE_FLAG_RO;
 		mask |= BLKTAP_DEVICE_FLAG_PSZ;
+		mask |= BLKTAP_DEVICE_FLAG_FLUSH;
 
 		memset(&info, 0, sizeof(info));
 		sz = base_sz = BLKTAP_INFO_SIZE_AT(flags);
include/linux/blktap.h +2 -0
index 9a280d9..4739320 100644
@@ -18,6 +18,7 @@
 
 #define BLKTAP_DEVICE_FLAG_RO       0x00000001UL /* disk is R/O */
 #define BLKTAP_DEVICE_FLAG_PSZ      0x00000002UL /* physical sector size */
+#define BLKTAP_DEVICE_FLAG_FLUSH    0x00000004UL /* supports FLUSH */
 
 struct blktap_info {
 	unsigned int            ring_major;
@@ -54,6 +55,7 @@ struct blktap_segment {
 
 #define BLKTAP_OP_READ          0
 #define BLKTAP_OP_WRITE         1
+#define BLKTAP_OP_FLUSH         2
 
 #define BLKTAP_SEGMENT_MAX      11
 
Signature · 1 line
1.7.0.4
#22 lore raw
In reply to Daniel Stodden
Quoted 2 lines · Daniel Stodden

Please pull upstream/xen/dom0/backend/blktap2 at
git://xenbits.xensource.com/people/dstodden/linux.git

Revoke. Could use some further improvements and I'd like to at least fix some missing comments, and maybe modify stuff according to Ian's input. I'll resend it then.

Thanks,
Daniel

Quoted 14 lines

Summary:

- Move blktap to drivers/block
- Takes a .config update setting BLK_DEV_TAP
- Redo the ABI definitions, in linux/blktap.h

- Some prerequisites for new commands, such as cache flushing and trim support. Plus more device configuration driven from userspace, such as setting physical sector sizes.

- a new CREATE_DEVICE ioctls to flag extensions, like the above mentioned ones.

- Bugfix from Dominic Curran (Fix reference to freed struct request).