multiprotocol blkback drivers (32-on-64)
Hi,
This is a patch for the block interface, frontend drivers, backend drivers and tools to support multiple ring protocols. Right there are now just two: the 32bit and the 64bit one. If needed it can be extended.
Interface changes (io/blkif.h)
* Have both request structs there, with "v1" and "v2" added to the name. The old name is aliased to the native protocol of the architecture.
* Add helper functions to convert v1/v2 requests to native.
Frontend changes:
* Create a new node "protocol", add the protocol number it speaks there.
Backend changes:
* Look at the "protocol" number of the frontend and switch ring handling accordingly. If the protocol node isn't present it assumes native protocol.
* As the request struct is copied anyway before being processed (for security reasons) it is converted to native at that point so most backend code doesn't need to know what the frontend speaks.
* In case of blktap this is completely transparent to userspace, the kernel/userspace ring is always native no matter what the frontend speaks.
Tools changes:
* Add one more option to the disk configuration, so one can specify the protocol the frontend speaks in the config file. This is needed for old frontends which don't advertise the protocol they are speaking themself.
I'm not that happy with this approach, but it works for now and I'm kida lost in the stack of python classes doing domain and device handling ...
Consider the code experimental, not all frontend/backend combinations are tested.
Comments? Questions? Suggesions?
cheers,
Gerd
PS: Anyone working on blkback/blktap code sharing? While walking
through the code I've noticed quite alot of it is cut&paste ...
Signature · 1 line
Gerd Hoffmann <[email protected]>
--- linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c | 79 ++++++++++++----- linux-2.6-xen-sparse/drivers/xen/blkback/common.h | 4 linux-2.6-xen-sparse/drivers/xen/blkback/interface.c | 17 ++- linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c | 14 +++ linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c | 6 + linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c | 86 +++++++++++++------ linux-2.6-xen-sparse/drivers/xen/blktap/common.h | 4 linux-2.6-xen-sparse/drivers/xen/blktap/interface.c | 17 ++- linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c | 14 +++ tools/python/xen/xend/server/blkif.py | 3 tools/python/xen/xm/create.py | 7 + xen/include/public/io/blkif.h | 81 +++++++++++++++-- 12 files changed, 264 insertions(+), 68 deletions(-)
linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c +58 -21
@@ -298,17 +298,33 @@ irqreturn_t blkif_be_int(int irq, void *static int do_block_io_op (blkif_t *blkif) { -blkif_back_ring_t *blk_ring = &blkif->blk_ring; +blkif_v1_back_ring_t *blk_v1_ring =NULL ; +blkif_v2_back_ring_t *blk_v2_ring =NULL ;blkif_request_t req;pending_req_t *pending_req;RING_IDX rc, rp;int more_to_do =0 ; - rc = blk_ring->req_cons; - rp = blk_ring->sring->req_prod; +if (1 == blkif->blk_protocol) { + blk_v1_ring = &blkif->blk_v1_ring; + rc = blk_v1_ring->req_cons; + rp = blk_v1_ring->sring->req_prod; + }else { + blk_v2_ring = &blkif->blk_v2_ring; + rc = blk_v2_ring->req_cons; + rp = blk_v2_ring->sring->req_prod; + }rmb ();/* Ensure we see queued requests up to 'rp'. */ -while ((rc != rp) && !RING_REQUEST_CONS_OVERFLOW (blk_ring, rc)) { +while ((rc != rp)) { + +if (1 == blkif->blk_protocol) { +if (RING_REQUEST_CONS_OVERFLOW (blk_v1_ring, rc)) +break ; + }else { +if (RING_REQUEST_CONS_OVERFLOW (blk_v2_ring, rc)) +break ; + } pending_req =alloc_req ();if (NULL == pending_req) {
@@ -317,8 +333,13 @@ static int do_block_io_op(blkif_t *blkifbreak ; } -memcpy (&req,RING_GET_REQUEST (blk_ring, rc),sizeof (req)); - blk_ring->req_cons = ++rc;/* before make_response() */ +if (1 == blkif->blk_protocol) { +blkif_get_v1_req (&req,RING_GET_REQUEST (blk_v1_ring, rc)); + blk_v1_ring->req_cons = ++rc;/* before make_response() */ + }else { +blkif_get_v2_req (&req,RING_GET_REQUEST (blk_v2_ring, rc)); + blk_v2_ring->req_cons = ++rc;/* before make_response() */ + }switch (req.operation) {case BLKIF_OP_READ :
@@ -500,32 +521,48 @@ static void make_response(blkif_t *blkif {blkif_response_t *resp;unsigned long flags; -blkif_back_ring_t *blk_ring = &blkif->blk_ring; +blkif_v1_back_ring_t *blk_v1_ring =NULL ; +blkif_v2_back_ring_t *blk_v2_ring =NULL ;int more_to_do =0 ;int notify;spin_lock_irqsave (&blkif->blk_ring_lock, flags);/* Place on the response ring for the relevant domain. */ - resp =RING_GET_RESPONSE (blk_ring, blk_ring->rsp_prod_pvt); +if (1 == blkif->blk_protocol) { + blk_v1_ring = &blkif->blk_v1_ring; + resp =RING_GET_RESPONSE (blk_v1_ring, blk_v1_ring->rsp_prod_pvt); + }else { + blk_v2_ring = &blkif->blk_v2_ring; + resp =RING_GET_RESPONSE (blk_v2_ring, blk_v2_ring->rsp_prod_pvt); + } resp->id = id; resp->operation = op; resp->status = st; - blk_ring->rsp_prod_pvt++; -RING_PUSH_RESPONSES_AND_CHECK_NOTIFY (blk_ring, notify); - -if (blk_ring->rsp_prod_pvt == blk_ring->req_cons) { -/* -* Tail check for pending requests. Allows frontend to avoid -* notifications if requests are already in flight (lower -* overheads and promotes batching). -*/ -RING_FINAL_CHECK_FOR_REQUESTS (blk_ring, more_to_do); - - }else if (RING_HAS_UNCONSUMED_REQUESTS (blk_ring)) { - more_to_do =1 ; +if (1 == blkif->blk_protocol) { + blk_v1_ring->rsp_prod_pvt++; +RING_PUSH_RESPONSES_AND_CHECK_NOTIFY (blk_v1_ring, notify); +if (blk_v1_ring->rsp_prod_pvt == blk_v1_ring->req_cons) { +/* +* Tail check for pending requests. Allows frontend to avoid +* notifications if requests are already in flight (lower +* overheads and promotes batching). +*/ +RING_FINAL_CHECK_FOR_REQUESTS (blk_v1_ring, more_to_do); + }else if (RING_HAS_UNCONSUMED_REQUESTS (blk_v1_ring)) { + more_to_do =1 ; + } + }else { + blk_v2_ring->rsp_prod_pvt++; +RING_PUSH_RESPONSES_AND_CHECK_NOTIFY (blk_v2_ring, notify); +if (blk_v2_ring->rsp_prod_pvt == blk_v2_ring->req_cons) { +RING_FINAL_CHECK_FOR_REQUESTS (blk_v2_ring, more_to_do); + }else if (RING_HAS_UNCONSUMED_REQUESTS (blk_v2_ring)) { + more_to_do =1 ; + } } +spin_unlock_irqrestore (&blkif->blk_ring_lock, flags);if (more_to_do)
linux-2.6-xen-sparse/drivers/xen/blkback/common.h +3 -1
@@ -68,7 +68,9 @@ typedef struct blkif_st {unsigned int evtchn;unsigned int irq;/* Comms information. */ -blkif_back_ring_t blk_ring; +int blk_protocol; +blkif_v1_back_ring_t blk_v1_ring; +blkif_v2_back_ring_t blk_v2_ring;struct vm_struct *blk_ring_area;/* The VBD attached to this interface. */ struct vbd vbd;
linux-2.6-xen-sparse/drivers/xen/blkback/interface.c +12 -5
@@ -95,7 +95,8 @@ static void unmap_frontend_page(blkif_tint blkif_map (blkif_t *blkif,unsigned long shared_page,unsigned int evtchn) { -blkif_sring_t *sring; +blkif_v1_sring_t *sring_v1; +blkif_v2_sring_t *sring_v2;int err;struct evtchn_bind_interdomain bind_interdomain;
@@ -125,8 +126,13 @@ int blkif_map(blkif_t *blkif, unsigned l blkif->evtchn = bind_interdomain.local_port; - sring = (blkif_sring_t *)blkif->blk_ring_area->addr; -BACK_RING_INIT (&blkif->blk_ring, sring,PAGE_SIZE ); +if (1 == blkif->blk_protocol) { + sring_v1 = (blkif_v1_sring_t *)blkif->blk_ring_area->addr; +BACK_RING_INIT (&blkif->blk_v1_ring, sring_v1,PAGE_SIZE ); + }else { + sring_v2 = (blkif_v2_sring_t *)blkif->blk_ring_area->addr; +BACK_RING_INIT (&blkif->blk_v2_ring, sring_v2,PAGE_SIZE ); + } blkif->irq =bind_evtchn_to_irqhandler ( blkif->evtchn, blkif_be_int,0 ,"blkif-backend" , blkif);
@@ -150,10 +156,11 @@ void blkif_disconnect(blkif_t *blkif) blkif->irq =0 ; } -if (blkif->blk_ring.sring) { +if (blkif->blk_v1_ring.sring || blkif->blk_v2_ring.sring) {unmap_frontend_page (blkif);free_vm_area (blkif->blk_ring_area); - blkif->blk_ring.sring =NULL ; + blkif->blk_v1_ring.sring =NULL ; + blkif->blk_v2_ring.sring =NULL ; } }
linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c +14 -0
@@ -435,6 +435,7 @@ static int connect_ring(struct backend_istruct xenbus_device *dev = be->dev;unsigned long ring_ref;unsigned int evtchn; +unsigned int protocol;int err;DPRINTK ("%s" , dev->otherend);
@@ -448,6 +449,19 @@ static int connect_ring(struct backend_ireturn err; } + err =xenbus_gather (XBT_NIL , dev->otherend,"protocol" , +"%u" , &protocol,NULL ); +if (err) + protocol =BLKIF_NATIVE_PROTOCOL ; +if (protocol <1 || protocol >2 ) { +xenbus_dev_fatal (dev, err,"unknown fe protocol %d" , protocol); +return -1 ; + } + be->blkif->blk_protocol = protocol; + +printk ("blkback: ring-ref %ld, event-channel %d, protocol %d\n" , + ring_ref, evtchn, protocol); +/* Map the shared frame, irq etc. */ err =blkif_map (be->blkif, ring_ref, evtchn);if (err) {
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c +6 -0
@@ -180,6 +180,12 @@ again: message ="writing event-channel" ; goto abort_transaction; } + err =xenbus_printf (xbt, dev->nodename, +"protocol" ,"%u" ,BLKIF_NATIVE_PROTOCOL ); +if (err) { + message ="writing protocol" ; + goto abort_transaction; + } err =xenbus_transaction_end (xbt,0 );if (err) {
xen/include/public/io/blkif.h +72 -9
99 lines not on this page · raw message
tools/python/xen/xend/server/blkif.py +3 -0
@@ -38,6 +38,7 @@ class BlkifController(DevController): """@see DevController.getDeviceDetails""" uname = config.get('uname', '') dev = config.get('dev', '') + protocol = config.get('protocol') if 'ioemu:' in dev: (_, dev) = string.split(dev, ':', 1)
@@ -85,6 +86,8 @@ class BlkifController(DevController): front = { 'virtual-device' : "%i" % devid, 'device-type' : dev_type } + if protocol: + front.update({ 'protocol' : protocol }); return (devid, back, front)
tools/python/xen/xm/create.py +6 -1
@@ -531,7 +531,7 @@ def configure_image(vals): def configure_disks(config_devs, vals): """Create the config for disks (virtual block devices). """ - for (uname, dev, mode, backend) in vals.disk: + for (uname, dev, mode, backend, protocol) in vals.disk: if uname.startswith('tap:'): cls = 'tap' else:
@@ -543,6 +543,8 @@ def configure_disks(config_devs, vals): ['mode', mode ] ] if backend: config_vbd.append(['backend', backend]) + if protocol: + config_vbd.append(['protocol', protocol]) config_devs.append(['device', config_vbd]) def configure_pci(config_devs, vals):
@@ -787,7 +789,10 @@ def preprocess_disk(vals): n = len(d) if n == 3: d.append(None) + d.append(None) elif n == 4: + d.append(None) + elif n == 5: pass else: err('Invalid disk specifier: ' + v)
linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c +61 -25
129 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/blktap/common.h +3 -1
@@ -59,7 +59,9 @@ typedef struct blkif_st {unsigned int evtchn;unsigned int irq;/* Comms information. */ -blkif_back_ring_t blk_ring; +int blk_protocol; +blkif_v1_back_ring_t blk_v1_ring; +blkif_v2_back_ring_t blk_v2_ring;struct vm_struct *blk_ring_area;/* Back pointer to the backend_info. */ struct backend_info *be;
linux-2.6-xen-sparse/drivers/xen/blktap/interface.c +12 -5
@@ -96,7 +96,8 @@ static void unmap_frontend_page(blkif_tint tap_blkif_map (blkif_t *blkif,unsigned long shared_page,unsigned int evtchn) { -blkif_sring_t *sring; +blkif_v1_sring_t *sring_v1; +blkif_v2_sring_t *sring_v2;int err;struct evtchn_bind_interdomain bind_interdomain;
@@ -126,8 +127,13 @@ int tap_blkif_map(blkif_t *blkif, unsign blkif->evtchn = bind_interdomain.local_port; - sring = (blkif_sring_t *)blkif->blk_ring_area->addr; -BACK_RING_INIT (&blkif->blk_ring, sring,PAGE_SIZE ); +if (1 == blkif->blk_protocol) { + sring_v1 = (blkif_v1_sring_t *)blkif->blk_ring_area->addr; +BACK_RING_INIT (&blkif->blk_v1_ring, sring_v1,PAGE_SIZE ); + }else { + sring_v2 = (blkif_v2_sring_t *)blkif->blk_ring_area->addr; +BACK_RING_INIT (&blkif->blk_v2_ring, sring_v2,PAGE_SIZE ); + } blkif->irq =bind_evtchn_to_irqhandler ( blkif->evtchn, tap_blkif_be_int,0 ,"blkif-backend" , blkif);
@@ -141,10 +147,11 @@ void tap_blkif_unmap(blkif_t *blkif)unbind_from_irqhandler (blkif->irq, blkif); blkif->irq =0 ; } -if (blkif->blk_ring.sring) { +if (blkif->blk_v1_ring.sring || blkif->blk_v2_ring.sring) {unmap_frontend_page (blkif);free_vm_area (blkif->blk_ring_area); - blkif->blk_ring.sring =NULL ; + blkif->blk_v1_ring.sring =NULL ; + blkif->blk_v2_ring.sring =NULL ; } }
linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c +14 -0
@@ -316,6 +316,7 @@ static int connect_ring(struct backend_istruct xenbus_device *dev = be->dev;unsigned long ring_ref;unsigned int evtchn; +unsigned int protocol;int err;DPRINTK ("%s\n" , dev->otherend);
@@ -329,6 +330,19 @@ static int connect_ring(struct backend_ireturn err; } + err =xenbus_gather (XBT_NIL , dev->otherend,"protocol" , +"%u" , &protocol,NULL ); +if (err) + protocol =BLKIF_NATIVE_PROTOCOL ; +if (protocol <1 || protocol >2 ) { +xenbus_dev_fatal (dev, err,"unknown fe protocol %d" , protocol); +return -1 ; + } + be->blkif->blk_protocol = protocol; + +printk ("blktap: ring-ref %ld, event-channel %d, protocol %d\n" , + ring_ref, evtchn, protocol); +/* Map the shared frame, irq etc. */ err =tap_blkif_map (be->blkif, ring_ref, evtchn);if (err) {
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
I understand you favor this over the bi-modal approach I took? Any specific advantages? Jan
Quoted 1 line
Quoted 1 line
Quoted 1 line
Gerd Hoffmann <[email protected]> 18.12.06 17:39 >>>
Hi,
This is a patch for the block interface, frontend drivers, backend drivers and tools to support multiple ring protocols. Right there are now just two: the 32bit and the 64bit one. If needed it can be extended.
Interface changes (io/blkif.h)
* Have both request structs there, with "v1" and "v2" added to the name. The old name is aliased to the native protocol of the architecture.
* Add helper functions to convert v1/v2 requests to native.
Frontend changes:
* Create a new node "protocol", add the protocol number it speaks there.
Backend changes:
* Look at the "protocol" number of the frontend and switch ring handling accordingly. If the protocol node isn't present it assumes native protocol.
* As the request struct is copied anyway before being processed (for security reasons) it is converted to native at that point so most backend code doesn't need to know what the frontend speaks.
* In case of blktap this is completely transparent to userspace, the kernel/userspace ring is always native no matter what the frontend speaks.
Tools changes:
* Add one more option to the disk configuration, so one can specify the protocol the frontend speaks in the config file. This is needed for old frontends which don't advertise the protocol they are speaking themself.
I'm not that happy with this approach, but it works for now and I'm kida lost in the stack of python classes doing domain and device handling ...
Consider the code experimental, not all frontend/backend combinations are tested.
Comments? Questions? Suggesions?
cheers,
Gerd
PS: Anyone working on blkback/blktap code sharing? While walking
through the code I've noticed quite alot of it is cut&paste ...
Signature · 1 line
Gerd Hoffmann <[email protected]>
Gerd's description is along the lines of what I would implement myself. How does your bi-modal approach work?
-- Keir
Quoted 50 lines · Jan Beulich
I understand you favor this over the bi-modal approach I took? Any specific advantages? Jan
Quoted 1 line
Quoted 1 line
Quoted 1 line
Gerd Hoffmann <[email protected]> 18.12.06 17:39 >>>
Hi,
This is a patch for the block interface, frontend drivers, backend drivers and tools to support multiple ring protocols. Right there are now just two: the 32bit and the 64bit one. If needed it can be extended.
Interface changes (
io/blkif.h)
* Have both request structs there, with "v1" and "v2" added to the name. The old name is aliased to the native protocol of the architecture.
* Add helper functions to convert v1/v2 requests to native.Frontend changes:
* Create a new node "protocol", add the protocol number it speaks there.Backend changes:
* Look at the "protocol" number of the frontend and switch ring handling accordingly. If the protocol node isn't present it assumes native protocol.
* As the request struct is copied anyway before being processed (for security reasons) it is converted to native at that point so most backend code doesn't need to know what the frontend speaks.
* In case of blktap this is completely transparent to userspace, the kernel/userspace ring is always native no matter what the frontend speaks.Tools changes:
* Add one more option to the disk configuration, so one can specify the protocol the frontend speaks in the config file. This is needed for old frontends which don't advertise the protocol they are speaking themself.
I'm not that happy with this approach, but it works for now and I'm kida lost in the stack of python classes doing domain and device handling ...Consider the code experimental, not all frontend/backend combinations are tested.
Comments? Questions? Suggesions?
cheers,
GerdPS: Anyone working on blkback/blktap code sharing? While walking
through the code I've noticed quite alot of it is cut&paste ...
By adding abstraction to the ring macros and the affected headers, and then replacing direct structure member accesses with appropriate macros. Reference patches attached (not checked whether they would apply cleanly on -unstable). Jan
Quoted 1 line
Quoted 1 line
Quoted 1 line
Keir Fraser <[email protected]> 18.12.06 18:58 >>>
Gerd's description is along the lines of what I would implement myself. How does your bi-modal approach work?
-- Keir
Quoted 43 lines · Jan Beulich
I understand you favor this over the bi-modal approach I took? Any specific advantages? Jan
Quoted 1 line
Quoted 1 line
Quoted 1 line
Gerd Hoffmann <[email protected]> 18.12.06 17:39 >>>
Hi,
This is a patch for the block interface, frontend drivers, backend drivers and tools to support multiple ring protocols. Right there are now just two: the 32bit and the 64bit one. If needed it can be extended.
Interface changes (
io/blkif.h)
* Have both request structs there, with "v1" and "v2" added to the name. The old name is aliased to the native protocol of the architecture.
* Add helper functions to convert v1/v2 requests to native.Frontend changes:
* Create a new node "protocol", add the protocol number it speaks there.Backend changes:
* Look at the "protocol" number of the frontend and switch ring handling accordingly. If the protocol node isn't present it assumes native protocol.
* As the request struct is copied anyway before being processed (for security reasons) it is converted to native at that point so most backend code doesn't need to know what the frontend speaks.
* In case of blktap this is completely transparent to userspace, the kernel/userspace ring is always native no matter what the frontend speaks.Tools changes:
* Add one more option to the disk configuration, so one can specify the protocol the frontend speaks in the config file. This is needed for old frontends which don't advertise the protocol they are speaking themself.
I'm not that happy with this approach, but it works for now and I'm kida lost in the stack of python classes doing domain and device handling ...Consider the code experimental, not all frontend/backend combinations are tested.
Quoted 7 lines
Comments? Questions? Suggesions?
cheers,
GerdPS: Anyone working on blkback/blktap code sharing? While walking
through the code I've noticed quite alot of it is cut&paste ...
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Enhance tpmback to be capable of dealing with bi-modal operation (frontend running in with different word size than backend).
drivers/xen/tpmback/common.h +16 -2
@@ -12,7 +12,9 @@#include <linux/slab.h> #include <xen/evtchn.h> #include <xen/driver_util.h> -#include <xen/interface/grant_table.h> +#ifdef CONFIG_XEN_BIMODAL_BACKENDS +#define TPMIF_BIMODAL +#endif #include <xen/interface/io/tpmif.h> #include <asm/io.h> #include <asm/pgalloc.h>
@@ -27,6 +29,9 @@ typedef struct tpmif_st {struct list_head tpmif_list;/* Unique identifier for this interface. */ domid_t domid; +#ifdef CONFIG_XEN_BIMODAL_BACKENDS +unsigned char native; +#endif unsigned int handle;/* Physical parameters of the comms window. */
@@ -34,7 +39,7 @@ typedef struct tpmif_st {unsigned int irq;/* The shared rings and indexes. */ -tpmif_tx_interface_t *tx; +tpmif_tx_interface_u tx;struct vm_struct *tx_area;/* Miscellaneous private stuff. */
@@ -54,6 +59,15 @@ typedef struct tpmif_st {char devname[20 ]; } tpmif_t; +#ifdef CONFIG_XEN_BIMODAL_BACKENDS +#define tpmif_request (tpmif, rq, n) \ + ((tpmif)->native \ + ? (void)(rq.nat = &(tpmif)->tx.nat->ring[n].req) \ + : (void)(rq.alt = &(tpmif)->tx.alt->ring[n].req)) +#else +#define tpmif_request (tpmif, rq, n) ((void)(rq = &(tpmif)->tx->ring[n].req)) +#endif +void tpmif_disconnect_complete (tpmif_t * tpmif);tpmif_t *tpmif_find (domid_t domid,struct backend_info *bi);void tpmif_interface_init (void );
drivers/xen/tpmback/interface.c +13 -2
@@ -30,6 +30,9 @@ static tpmif_t *alloc_tpmif(domid_t domimemset (tpmif,0 ,sizeof (*tpmif)); tpmif->domid = domid; +#ifdef CONFIG_XEN_BIMODAL_BACKENDS + tpmif->native =1 ;/* XXX */ +#endif tpmif->status =DISCONNECTED ; tpmif->bi = bi;snprintf (tpmif->devname,sizeof (tpmif->devname),"tpmif%d" , domid);
@@ -115,6 +118,12 @@ static void unmap_frontend_page(tpmif_tBUG_ON (ret); } +#ifndef CONFIG_XEN_BIMODAL_BACKENDS +#define tpmif_tx tpmif->tx +#else +#define tpmif_tx tpmif->tx.nat +#endif +int tpmif_map (tpmif_t *tpmif,unsigned long shared_page,unsigned int evtchn) {int err;
@@ -147,7 +156,7 @@ int tpmif_map(tpmif_t *tpmif, unsigned l tpmif->evtchn = bind_interdomain.local_port; - tpmif->tx = (tpmif_tx_interface_t *)tpmif->tx_area->addr; + tpmif_tx = (tpmif_tx_interface_t *)tpmif->tx_area->addr; tpmif->irq =bind_evtchn_to_irqhandler ( tpmif->evtchn, tpmif_be_int,0 , tpmif->devname, tpmif);
@@ -162,7 +171,7 @@ void tpmif_disconnect_complete(tpmif_t *if (tpmif->irq)unbind_from_irqhandler (tpmif->irq, tpmif); -if (tpmif->tx) { +if (tpmif_tx) {unmap_frontend_page (tpmif);free_vm_area (tpmif->tx_area); }
@@ -170,6 +179,8 @@ void tpmif_disconnect_complete(tpmif_t *free_tpmif (tpmif); } +#undef tpmif_tx +void __init tpmif_interface_init (void ) { tpmif_cachep = kmem_cache_create("tpmif_cache", sizeof (tpmif_t),
drivers/xen/tpmback/tpmback.c +22 -18
@@ -70,6 +70,12 @@ static int packet_read_shmem(struct pack char *buffer, int isuserbuffer, u32 left);static int vtpm_queue_packet (struct packet *pak); +#ifdef CONFIG_XEN_BIMODAL_BACKENDS +#define tx (op) (tpmif->native ? (tx.nat->op) : (tx.alt->op)) +#else +#define tx (op) (tx->op) +#endif +/*************************************************************** Buffer copying fo user and kernel space buffes. ***************************************************************/
@@ -244,17 +250,17 @@ int _packet_write(struct packet *pak,unsigned int tocopy;struct gnttab_map_grant_ref map_op;struct gnttab_unmap_grant_ref unmap_op; -tpmif_tx_request_t *tx; +tpmif_tx_request_u tx; - tx = &tpmif->tx->ring[i].req; +tpmif_request (tpmif, tx, i); -if (0 == tx->addr) { +if (0 ==tx (addr)) {DPRINTK ("ERROR: Buffer for outgoing packet NULL?! i=%d\n" , i);return 0 ; }gnttab_set_map_op (&map_op,idx_to_kaddr (tpmif, i), - GNTMAP_host_map, tx->ref, tpmif->domid); + GNTMAP_host_map,tx (ref), tpmif->domid);if (unlikely (HYPERVISOR_grant_table_op (GNTTABOP_map_grant_ref, &map_op,1 ))) {
@@ -271,12 +277,12 @@ int _packet_write(struct packet *pak, tocopy =min_t (size_t, size - offset,PAGE_SIZE );if (copy_from_buffer ((void *)(idx_to_kaddr (tpmif, i) | - (tx->addr & ~PAGE_MASK )), + (unsigned long )tx (addr & ~PAGE_MASK )), &data[offset], tocopy, isuserbuffer)) {tpmif_put (tpmif);return -EFAULT ; } - tx->size = tocopy; +tx (size = tocopy);gnttab_set_unmap_op (&unmap_op,idx_to_kaddr (tpmif, i), GNTMAP_host_map, handle);
@@ -375,9 +381,6 @@ static int packet_read_shmem(struct packu32 to_copy;grant_handle_t handle; -tpmif_tx_request_t *tx; - - tx = &tpmif->tx->ring[0 ].req;/* * Start copying data at the page with index 'index' * and within that page at offset 'offset'.
@@ -385,14 +388,15 @@ static int packet_read_shmem(struct pack*/ to_copy =min_t (u32,PAGE_SIZE - pg_offset, room_left);while (to_copy >0 ) { +tpmif_tx_request_u tx;void *src;struct gnttab_map_grant_ref map_op;struct gnttab_unmap_grant_ref unmap_op; - tx = &tpmif->tx->ring[i].req; +tpmif_request (tpmif, tx, i);gnttab_set_map_op (&map_op,idx_to_kaddr (tpmif, i), - GNTMAP_host_map, tx->ref, tpmif->domid); + GNTMAP_host_map,tx (ref), tpmif->domid);if (unlikely (HYPERVISOR_grant_table_op (GNTTABOP_map_grant_ref, &map_op,1 ))) {
@@ -406,19 +410,19 @@ static int packet_read_shmem(struct pack handle = map_op.handle; -if (to_copy > tx->size) { +if (to_copy >tx (size)) {/* * User requests more than what's available */ - to_copy =min_t (u32, tx->size, to_copy); + to_copy =min_t (u32,tx (size), to_copy); }DPRINTK ("Copying from mapped memory at %08lx\n" , (unsigned long )(idx_to_kaddr (tpmif, i) | - (tx->addr & ~PAGE_MASK ))); + (unsigned long )tx (addr & ~PAGE_MASK ))); src = (void *)(idx_to_kaddr (tpmif, i) | - ((tx->addr & ~PAGE_MASK ) + pg_offset)); + ((unsigned long )tx (addr & ~PAGE_MASK ) + pg_offset));if (copy_to_buffer (&buffer[offset], src, to_copy, isuserbuffer)) {return -EFAULT ;
@@ -879,7 +883,7 @@ static void tpm_tx_action(unsigned long {struct list_head *ent;tpmif_t *tpmif; -tpmif_tx_request_t *tx; +tpmif_tx_request_u tx;DPRINTK ("%s: Getting data from front-end(s)!\n" , __FUNCTION__);
@@ -890,10 +894,10 @@ static void tpm_tx_action(unsigned longtpmif_get (tpmif);remove_from_tpm_schedule_list (tpmif); - tx = &tpmif->tx->ring[0 ].req; +tpmif_request (tpmif, tx,0 );/* pass it up */ -vtpm_receive (tpmif, tx->size); +vtpm_receive (tpmif,tx (size));tpmif_put (tpmif); }
include/xen/interface/io/tpmif.h +49 -9
86 lines not on this page · raw message
Enhance blkif and ring handling to be capable of dealing with bi-modal operation (frontend running in with different word size than backend).
drivers/xen/Kconfig +8 -0
@@ -45,6 +45,14 @@ config XEN_BACKEND Support for backend device drivers that provide I/O services to other virtual machines. +config XEN_BIMODAL_BACKENDS + bool "Bi-modal backend driver support" + depends on XEN_BACKEND && (X86_PAE || X86_64) + default y + help + Build backend device drivers providing support for both + native as well as compatibility guests. + config XEN_BLKDEV_BACKEND tristate "Block-device backend driver" depends on XEN_BACKEND
include/xen/interface/io/blkif.h +42 -10
87 lines not on this page · raw message
include/xen/interface/io/ring.h +160 -14
291 lines not on this page · raw message
Enhance blktap to be capable of dealing with bi-modal operation (frontend running in with different word size than backend).
drivers/xen/blktap/blktap.c +58 -29
222 lines not on this page · raw message
drivers/xen/blktap/common.h +15 -1
@@ -39,8 +39,10 @@#include <asm/pgalloc.h> #include <xen/evtchn.h> #include <asm/hypervisor.h> +#ifdef CONFIG_XEN_BIMODAL_BACKENDS +#define BLKIF_BIMODAL +#endif #include <xen/interface/io/blkif.h> -#include <xen/interface/io/ring.h> #include <xen/gnttab.h> #include <xen/driver_util.h>
@@ -54,6 +56,9 @@ struct backend_info; typedef struct blkif_st { /* Unique identifier for this interface. */ domid_t domid; +#ifdef CONFIG_XEN_BIMODAL_BACKENDS + unsigned char native; +#endif unsigned int handle; /* Physical parameters of the comms window. */ unsigned int evtchn;
@@ -87,6 +92,15 @@ typedef struct blkif_st {uint64_t sectors; } blkif_t; +#ifdef CONFIG_XEN_BIMODAL_BACKENDS +#define blkif_native (blkif) ((blkif)->native) +static inline int ring_native (const blkif_back_ring_t *ring) { +return blkif_native (container_of (ring, blkif_t, blk_ring)); +} +#else +#define blkif_native (blkif) 1 +#endif +blkif_t *tap_alloc_blkif (domid_t domid);void tap_blkif_free (blkif_t *blkif); int tap_blkif_map(blkif_t *blkif, unsigned long shared_page,
drivers/xen/blktap/interface.c +7 -4
@@ -46,6 +46,9 @@ blkif_t *tap_alloc_blkif(domid_t domid)memset (blkif,0 ,sizeof (*blkif)); blkif->domid = domid; +#ifdef CONFIG_XEN_BIMODAL_BACKENDS + blkif->native =1 ;/* XXX */ +#endif spin_lock_init (&blkif->blk_ring_lock);atomic_set (&blkif->refcnt,1 );init_waitqueue_head (&blkif->wq);
@@ -96,7 +99,7 @@ static void unmap_frontend_page(blkif_tint tap_blkif_map (blkif_t *blkif,unsigned long shared_page,unsigned int evtchn) { -blkif_sring_t *sring; +blkif_sring_u sring;int err;struct evtchn_bind_interdomain bind_interdomain;
@@ -126,7 +129,7 @@ int tap_blkif_map(blkif_t *blkif, unsign blkif->evtchn = bind_interdomain.local_port; - sring = (blkif_sring_t *)blkif->blk_ring_area->addr; +BB_SRING (sring) = (void *)blkif->blk_ring_area->addr;BACK_RING_INIT (&blkif->blk_ring, sring,PAGE_SIZE ); blkif->irq = bind_evtchn_to_irqhandler(
@@ -141,10 +144,10 @@ void tap_blkif_unmap(blkif_t *blkif)unbind_from_irqhandler (blkif->irq, blkif); blkif->irq =0 ; } -if (blkif->blk_ring.sring) { +if (blkif->blk_ring.BB_SRING (sring)) {unmap_frontend_page (blkif);free_vm_area (blkif->blk_ring_area); - blkif->blk_ring.sring =NULL ; + blkif->blk_ring.BB_SRING (sring) =NULL ; } }
Enhance blkback to be capable of dealing with bi-modal operation (frontend running in with different word size than backend).
drivers/xen/blkback/blkback.c +46 -32
203 lines not on this page · raw message
drivers/xen/blkback/common.h +15 -1
@@ -40,8 +40,10 @@#include <asm/pgalloc.h> #include <xen/evtchn.h> #include <asm/hypervisor.h> +#ifdef CONFIG_XEN_BIMODAL_BACKENDS +#define BLKIF_BIMODAL +#endif #include <xen/interface/io/blkif.h> -#include <xen/interface/io/ring.h> #include <xen/gnttab.h> #include <xen/driver_util.h> #include <xen/xenbus.h>
@@ -63,6 +65,9 @@ struct backend_info; typedef struct blkif_st { /* Unique identifier for this interface. */ domid_t domid; +#ifdef CONFIG_XEN_BIMODAL_BACKENDS + unsigned char native; +#endif unsigned int handle; /* Physical parameters of the comms window. */ unsigned int evtchn;
@@ -96,6 +101,15 @@ typedef struct blkif_st {grant_ref_t shmem_ref; } blkif_t; +#ifdef CONFIG_XEN_BIMODAL_BACKENDS +#define blkif_native (blkif) ((blkif)->native) +static inline int ring_native (const blkif_back_ring_t *ring) { +return blkif_native (container_of (ring, blkif_t, blk_ring)); +} +#else +#define blkif_native (blkif) 1 +#endif +blkif_t *blkif_alloc (domid_t domid);void blkif_disconnect (blkif_t *blkif);void blkif_free (blkif_t *blkif);
drivers/xen/blkback/interface.c +7 -4
@@ -46,6 +46,9 @@ blkif_t *blkif_alloc(domid_t domid)memset (blkif,0 ,sizeof (*blkif)); blkif->domid = domid; +#ifdef CONFIG_XEN_BIMODAL_BACKENDS + blkif->native =1 ;/* XXX */ +#endif spin_lock_init (&blkif->blk_ring_lock);atomic_set (&blkif->refcnt,1 );init_waitqueue_head (&blkif->wq);
@@ -95,7 +98,7 @@ static void unmap_frontend_page(blkif_tint blkif_map (blkif_t *blkif,unsigned long shared_page,unsigned int evtchn) { -blkif_sring_t *sring; +blkif_sring_u sring;int err;struct evtchn_bind_interdomain bind_interdomain;
@@ -125,7 +128,7 @@ int blkif_map(blkif_t *blkif, unsigned l blkif->evtchn = bind_interdomain.local_port; - sring = (blkif_sring_t *)blkif->blk_ring_area->addr; +BB_SRING (sring) = (void *)blkif->blk_ring_area->addr;BACK_RING_INIT (&blkif->blk_ring, sring,PAGE_SIZE ); blkif->irq = bind_evtchn_to_irqhandler(
@@ -150,10 +153,10 @@ void blkif_disconnect(blkif_t *blkif) blkif->irq =0 ; } -if (blkif->blk_ring.sring) { +if (blkif->blk_ring.BB_SRING (sring)) {unmap_frontend_page (blkif);free_vm_area (blkif->blk_ring_area); - blkif->blk_ring.sring =NULL ; + blkif->blk_ring.BB_SRING (sring) =NULL ; } }
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
There are a couple of things I'd like to see changed if this is what we want to go with:
- "if (protocol == 1) {} else {}" should be switches, failing (or even BUGing) for all protocol versions other than 1 and 2
- assuming the abstraction is meant to scale to future protocol versions, adding many such explicit version handling code paths seems undesirable, as seems adding extra version specific variables or (non-union) structure members
- using all error possible values returned from xenbus_gather to indicate an old frontend seems odd at least - one specific error value should be recognized here
- unconditionally using #pragma pack(), __attribute__(()), and __i386__ or __x86_64__ in public Xen headers is, in my opinion, a no-go (these header should all be suitable for building e.g. Windows drivers, too - I know this isn't generally the case at present, but I don't think anything else can be the goal, and hence the situation shouldn't be made worse)
Jan
Quoted 1 line
Quoted 1 line
Quoted 1 line
Gerd Hoffmann <[email protected]> 18.12.06 17:39 >>>
Hi,
This is a patch for the block interface, frontend drivers, backend drivers and tools to support multiple ring protocols. Right there are now just two: the 32bit and the 64bit one. If needed it can be extended.
Interface changes (io/blkif.h)
* Have both request structs there, with "v1" and "v2" added to the name. The old name is aliased to the native protocol of the architecture.
* Add helper functions to convert v1/v2 requests to native.
Frontend changes:
* Create a new node "protocol", add the protocol number it speaks there.
Backend changes:
* Look at the "protocol" number of the frontend and switch ring handling accordingly. If the protocol node isn't present it assumes native protocol.
* As the request struct is copied anyway before being processed (for security reasons) it is converted to native at that point so most backend code doesn't need to know what the frontend speaks.
* In case of blktap this is completely transparent to userspace, the kernel/userspace ring is always native no matter what the frontend speaks.
Tools changes:
* Add one more option to the disk configuration, so one can specify the protocol the frontend speaks in the config file. This is needed for old frontends which don't advertise the protocol they are speaking themself.
I'm not that happy with this approach, but it works for now and I'm kida lost in the stack of python classes doing domain and device handling ...
Consider the code experimental, not all frontend/backend combinations are tested.
Comments? Questions? Suggesions?
cheers,
Gerd
PS: Anyone working on blkback/blktap code sharing? While walking
through the code I've noticed quite alot of it is cut&paste ...
Signature · 1 line
Gerd Hoffmann <[email protected]>
Quoted 2 lines · Jan Beulich
I understand you favor this over the bi-modal approach I took? Any specific advantages? Jan
IMHO the code is more readable and I'd rate the chance to be accepted by lkml review higher. I don't like the approach to hide alot of the logic in preprocessor magic.
It leaves the door open to add more protocols. Not that I see a need right now. But maybe the lkml folks ask us to consolidate to some struct layout which doesn't look different on different architectures (i.e. sort struct members by size), then we maybe have to support a third protocol ...
cheers,
Gerd
Signature · 1 line
Gerd Hoffmann <[email protected]>
Quoted 2 lines · Jan Beulich
There are a couple of things I'd like to see changed if this is what we want to go with:
yep, it's a first at least partly working rfc patch, certainly not final yet ;)
Quoted 2 lines
- "if (protocol == 1) {} else {}" should be switches, failing (or even BUGing) for all protocol versions other than 1 and 2
BUG() should be ok, in theory the code should never ever reach one of the switches with an uninitialized protocol.
Quoted 3 lines
- assuming the abstraction is meant to scale to future protocol versions, adding many such explicit version handling code paths seems undesirable, as seems adding extra version specific variables or (non-union) structure members
Using unions is one of the things I plan to change.
Quoted 3 lines
- using all error possible values returned from
xenbus_gatherto indicate an old frontend seems odd at least - one specific error value should be recognized here
Yep, would be a bit cleaner, although I don't see any other possible reason than a nonexisting node why it should fail at that point ...
Quoted 5 lines
- unconditionally using #pragma
pack(), __attribute__(()), and__i386__or__x86_64__in public Xen headers is, in my opinion, a no-go (these header should all be suitable for building e.g. Windows drivers, too - I know this isn't generally the case at present, but I don't think anything else can be the goal, and hence the situation shouldn't be made worse)
Yep, we need some solution for that. The sun folks will veto at least the attribute stuff too. Not sure pragma pack is a portability issue. I think we need some compiler.h which provides that kind of stuff, i.e.
#ifdef __GNUC__
#define __align8__ __attribute__((__aligned__(8))) #endif
#ifdef __suncc__
#define __align8__ something_else
#endif
Also some of the bits I've placed into blkif.h for now should go to a linux-kernel header instead I think.
cheers,
Gerd
Signature · 1 line
Gerd Hoffmann <[email protected]>
Next version attached. WARNING: compiles, but untested otherwise.
Quoted 2 lines
- "if (protocol == 1) {} else {}" should be switches, failing (or even BUGing) for all protocol versions other than 1 and 2
fixed.
Quoted 3 lines
- assuming the abstraction is meant to scale to future protocol versions, adding many such explicit version handling code paths seems undesirable, as seems adding extra version specific variables or (non-union) structure members
switch to unions done, also killed some "switch (protocols)" statements along the way, leaving only two places with different code paths: ring initialization and copying requests out of the ring.
Quoted 3 lines
- using all error possible values returned from
xenbus_gatherto indicate an old frontend seems odd at least - one specific error value should be recognized here
Hmm, looked at netfront/back to figure the correct error code. They act the same way though, i.e. consider errors on reading "feature-*" nodes as "doesn't exist" ...
Quoted 5 lines
- unconditionally using #pragma
pack(), __attribute__(()), and__i386__or__x86_64__in public Xen headers is, in my opinion, a no-go (these header should all be suitable for building e.g. Windows drivers, too - I know this isn't generally the case at present, but I don't think anything else can be the goal, and hence the situation shouldn't be made worse)
Ideas for that one? Ok to create xen/include/public/compiler.h with that kind of stuff in?
cheers,
Gerd
Signature · 1 line
Gerd Hoffmann <[email protected]>
multiprotocol blkback drivers.
This is a patch for the block interface, frontend drivers, backend drivers and tools to support multiple ring protocols. Right there are now just two: the 32bit and the 64bit one. If needed it can be extended.
Interface changes (io/blkif.h)
* Have both request structs there, with "v1" and "v2" added to the name. The old name is aliased to the native protocol of the architecture.
* Add helper functions to convert v1/v2 requests to native.
Frontend changes:
* Create a new node "protocol", add the protocol number it speaks there.
Backend changes:
* Look at the "protocol" number of the frontend and switch ring handling accordingly. If the protocol node isn't present it assumes native protocol.
* As the request struct is copied anyway before being processed (for security reasons) it is converted to native at that point so most backend code doesn't need to know what the frontend speaks.
* In case of blktap this is completely transparent to userspace, the kernel/userspace ring is always native no matter what the frontend speaks.
Tools changes:
* Add one more option to the disk configuration, so one can specify the protocol the frontend speaks in the config file. This is needed for old frontends which don't advertise the protocol they are speaking themself.
I'm not that happy with this approach, but it works for now and I'm kida lost in the stack of python classes doing domain and device handling ...
--- linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c | 43 +++++--- linux-2.6-xen-sparse/drivers/xen/blkback/common.h | 3 linux-2.6-xen-sparse/drivers/xen/blkback/interface.c | 25 +++- linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c | 14 ++ linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c | 6 + linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c | 44 +++++--- linux-2.6-xen-sparse/drivers/xen/blktap/common.h | 3 linux-2.6-xen-sparse/drivers/xen/blktap/interface.c | 25 +++- linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c | 14 ++ tools/python/xen/xend/server/blkif.py | 3 tools/python/xen/xm/create.py | 7 + xen/include/public/io/blkif.h | 97 +++++++++++++++++-- 12 files changed, 229 insertions(+), 55 deletions(-)
linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c +27 -16
@@ -298,17 +298,20 @@ irqreturn_t blkif_be_int(int irq, void *static int do_block_io_op (blkif_t *blkif) { -blkif_back_ring_t *blk_ring = &blkif->blk_ring; +blkif_back_rings_t *blk_rings = &blkif->blk_rings;blkif_request_t req;pending_req_t *pending_req;RING_IDX rc, rp;int more_to_do =0 ; - rc = blk_ring->req_cons; - rp = blk_ring->sring->req_prod; + rc = blk_rings->co.req_cons; + rp = blk_rings->co.sring->req_prod;rmb ();/* Ensure we see queued requests up to 'rp'. */ -while ((rc != rp) && !RING_REQUEST_CONS_OVERFLOW (blk_ring, rc)) { +while ((rc != rp)) { + +if (RING_REQUEST_CONS_OVERFLOW (&blk_rings->co, rc)) +break ; pending_req =alloc_req ();if (NULL == pending_req) {
@@ -317,8 +320,17 @@ static int do_block_io_op(blkif_t *blkifbreak ; } -memcpy (&req,RING_GET_REQUEST (blk_ring, rc),sizeof (req)); - blk_ring->req_cons = ++rc;/* before make_response() */ +switch (blkif->blk_protocol) { +case 1 : +blkif_get_v1_req (&req,RING_GET_REQUEST (&blk_rings->v1, rc)); +break ; +case 2 : +blkif_get_v2_req (&req,RING_GET_REQUEST (&blk_rings->v2, rc)); +break ; +default : +BUG (); + } + blk_rings->co.req_cons = ++rc;/* before make_response() */ switch (req.operation) {case BLKIF_OP_READ :
@@ -500,32 +512,31 @@ static void make_response(blkif_t *blkif {blkif_response_t *resp;unsigned long flags; -blkif_back_ring_t *blk_ring = &blkif->blk_ring; +blkif_back_rings_t *blk_rings = &blkif->blk_rings;int more_to_do =0 ;int notify;spin_lock_irqsave (&blkif->blk_ring_lock, flags);/* Place on the response ring for the relevant domain. */ - resp =RING_GET_RESPONSE (blk_ring, blk_ring->rsp_prod_pvt); + resp =RING_GET_RESPONSE (&blk_rings->co, blk_rings->co.rsp_prod_pvt); resp->id = id; resp->operation = op; resp->status = st; - blk_ring->rsp_prod_pvt++; -RING_PUSH_RESPONSES_AND_CHECK_NOTIFY (blk_ring, notify); - -if (blk_ring->rsp_prod_pvt == blk_ring->req_cons) { + blk_rings->co.rsp_prod_pvt++; +RING_PUSH_RESPONSES_AND_CHECK_NOTIFY (&blk_rings->co, notify); +if (blk_rings->co.rsp_prod_pvt == blk_rings->co.req_cons) {/* * Tail check for pending requests. Allows frontend to avoid * notifications if requests are already in flight (lower * overheads and promotes batching). */ -RING_FINAL_CHECK_FOR_REQUESTS (blk_ring, more_to_do); - - }else if (RING_HAS_UNCONSUMED_REQUESTS (blk_ring)) { +RING_FINAL_CHECK_FOR_REQUESTS (&blk_rings->co, more_to_do); + + }else if (RING_HAS_UNCONSUMED_REQUESTS (&blk_rings->co)) { more_to_do =1 ; - } +spin_unlock_irqrestore (&blkif->blk_ring_lock, flags);if (more_to_do)
linux-2.6-xen-sparse/drivers/xen/blkback/common.h +2 -1
@@ -68,7 +68,8 @@ typedef struct blkif_st {unsigned int evtchn;unsigned int irq;/* Comms information. */ -blkif_back_ring_t blk_ring; +int blk_protocol; +blkif_back_rings_t blk_rings;struct vm_struct *blk_ring_area;/* The VBD attached to this interface. */ struct vbd vbd;
linux-2.6-xen-sparse/drivers/xen/blkback/interface.c +20 -5
@@ -95,7 +95,6 @@ static void unmap_frontend_page(blkif_tint blkif_map (blkif_t *blkif,unsigned long shared_page,unsigned int evtchn) { -blkif_sring_t *sring;int err;struct evtchn_bind_interdomain bind_interdomain;
@@ -125,8 +124,24 @@ int blkif_map(blkif_t *blkif, unsigned l blkif->evtchn = bind_interdomain.local_port; - sring = (blkif_sring_t *)blkif->blk_ring_area->addr; -BACK_RING_INIT (&blkif->blk_ring, sring,PAGE_SIZE ); +switch (blkif->blk_protocol) { +case 1 : + { +blkif_v1_sring_t *sring_v1; + sring_v1 = (blkif_v1_sring_t *)blkif->blk_ring_area->addr; +BACK_RING_INIT (&blkif->blk_rings.v1, sring_v1,PAGE_SIZE ); +break ; + } +case 2 : + { +blkif_v2_sring_t *sring_v2; + sring_v2 = (blkif_v2_sring_t *)blkif->blk_ring_area->addr; +BACK_RING_INIT (&blkif->blk_rings.v2, sring_v2,PAGE_SIZE ); +break ; + } +default : +BUG (); + } blkif->irq =bind_evtchn_to_irqhandler ( blkif->evtchn, blkif_be_int,0 ,"blkif-backend" , blkif);
@@ -150,10 +165,10 @@ void blkif_disconnect(blkif_t *blkif) blkif->irq =0 ; } -if (blkif->blk_ring.sring) { +if (blkif->blk_rings.co.sring) {unmap_frontend_page (blkif);free_vm_area (blkif->blk_ring_area); - blkif->blk_ring.sring =NULL ; + blkif->blk_rings.co.sring =NULL ; } }
linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c +14 -0
@@ -435,6 +435,7 @@ static int connect_ring(struct backend_istruct xenbus_device *dev = be->dev;unsigned long ring_ref;unsigned int evtchn; +unsigned int protocol;int err;DPRINTK ("%s" , dev->otherend);
@@ -448,6 +449,19 @@ static int connect_ring(struct backend_ireturn err; } + err =xenbus_gather (XBT_NIL , dev->otherend,"protocol" , +"%u" , &protocol,NULL ); +if (err) + protocol =BLKIF_NATIVE_PROTOCOL ; +if (protocol <1 || protocol >2 ) { +xenbus_dev_fatal (dev, err,"unknown fe protocol %d" , protocol); +return -1 ; + } + be->blkif->blk_protocol = protocol; + +printk ("blkback: ring-ref %ld, event-channel %d, protocol %d\n" , + ring_ref, evtchn, protocol); +/* Map the shared frame, irq etc. */ err =blkif_map (be->blkif, ring_ref, evtchn);if (err) {
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c +6 -0
@@ -180,6 +180,12 @@ again: message ="writing event-channel" ; goto abort_transaction; } + err =xenbus_printf (xbt, dev->nodename, +"protocol" ,"%u" ,BLKIF_NATIVE_PROTOCOL ); +if (err) { + message ="writing protocol" ; + goto abort_transaction; + } err =xenbus_transaction_end (xbt,0 );if (err) {
xen/include/public/io/blkif.h +88 -9
115 lines not on this page · raw message
tools/python/xen/xend/server/blkif.py +3 -0
@@ -38,6 +38,7 @@ class BlkifController(DevController): """@see DevController.getDeviceDetails""" uname = config.get('uname', '') dev = config.get('dev', '') + protocol = config.get('protocol') if 'ioemu:' in dev: (_, dev) = string.split(dev, ':', 1)
@@ -85,6 +86,8 @@ class BlkifController(DevController): front = { 'virtual-device' : "%i" % devid, 'device-type' : dev_type } + if protocol: + front.update({ 'protocol' : protocol }); return (devid, back, front)
tools/python/xen/xm/create.py +6 -1
@@ -531,7 +531,7 @@ def configure_image(vals): def configure_disks(config_devs, vals): """Create the config for disks (virtual block devices). """ - for (uname, dev, mode, backend) in vals.disk: + for (uname, dev, mode, backend, protocol) in vals.disk: if uname.startswith('tap:'): cls = 'tap' else:
@@ -543,6 +543,8 @@ def configure_disks(config_devs, vals): ['mode', mode ] ] if backend: config_vbd.append(['backend', backend]) + if protocol: + config_vbd.append(['protocol', protocol]) config_devs.append(['device', config_vbd]) def configure_pci(config_devs, vals):
@@ -787,7 +789,10 @@ def preprocess_disk(vals): n = len(d) if n == 3: d.append(None) + d.append(None) elif n == 4: + d.append(None) + elif n == 5: pass else: err('Invalid disk specifier: ' + v)
linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c +27 -17
95 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/blktap/common.h +2 -1
@@ -59,7 +59,8 @@ typedef struct blkif_st {unsigned int evtchn;unsigned int irq;/* Comms information. */ -blkif_back_ring_t blk_ring; +int blk_protocol; +blkif_back_rings_t blk_rings;struct vm_struct *blk_ring_area;/* Back pointer to the backend_info. */ struct backend_info *be;
linux-2.6-xen-sparse/drivers/xen/blktap/interface.c +20 -5
@@ -96,7 +96,6 @@ static void unmap_frontend_page(blkif_tint tap_blkif_map (blkif_t *blkif,unsigned long shared_page,unsigned int evtchn) { -blkif_sring_t *sring;int err;struct evtchn_bind_interdomain bind_interdomain;
@@ -126,8 +125,24 @@ int tap_blkif_map(blkif_t *blkif, unsign blkif->evtchn = bind_interdomain.local_port; - sring = (blkif_sring_t *)blkif->blk_ring_area->addr; -BACK_RING_INIT (&blkif->blk_ring, sring,PAGE_SIZE ); +switch (blkif->blk_protocol) { +case 1 : + { +blkif_v1_sring_t *sring_v1; + sring_v1 = (blkif_v1_sring_t *)blkif->blk_ring_area->addr; +BACK_RING_INIT (&blkif->blk_rings.v1, sring_v1,PAGE_SIZE ); +break ; + } +case 2 : + { +blkif_v2_sring_t *sring_v2; + sring_v2 = (blkif_v2_sring_t *)blkif->blk_ring_area->addr; +BACK_RING_INIT (&blkif->blk_rings.v2, sring_v2,PAGE_SIZE ); +break ; + } +default : +BUG (); + } blkif->irq =bind_evtchn_to_irqhandler ( blkif->evtchn, tap_blkif_be_int,0 ,"blkif-backend" , blkif);
@@ -141,10 +156,10 @@ void tap_blkif_unmap(blkif_t *blkif)unbind_from_irqhandler (blkif->irq, blkif); blkif->irq =0 ; } -if (blkif->blk_ring.sring) { +if (blkif->blk_rings.co.sring) {unmap_frontend_page (blkif);free_vm_area (blkif->blk_ring_area); - blkif->blk_ring.sring =NULL ; + blkif->blk_rings.co.sring =NULL ; } }
linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c +14 -0
@@ -316,6 +316,7 @@ static int connect_ring(struct backend_istruct xenbus_device *dev = be->dev;unsigned long ring_ref;unsigned int evtchn; +unsigned int protocol;int err;DPRINTK ("%s\n" , dev->otherend);
@@ -329,6 +330,19 @@ static int connect_ring(struct backend_ireturn err; } + err =xenbus_gather (XBT_NIL , dev->otherend,"protocol" , +"%u" , &protocol,NULL ); +if (err) + protocol =BLKIF_NATIVE_PROTOCOL ; +if (protocol <1 || protocol >2 ) { +xenbus_dev_fatal (dev, err,"unknown fe protocol %d" , protocol); +return -1 ; + } + be->blkif->blk_protocol = protocol; + +printk ("blktap: ring-ref %ld, event-channel %d, protocol %d\n" , + ring_ref, evtchn, protocol); +/* Map the shared frame, irq etc. */ err =tap_blkif_map (be->blkif, ring_ref, evtchn);if (err) {
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 10 lines · Gerd Hoffmann
Quoted 7 lines
- unconditionally using #pragma
pack(), __attribute__(()), and__i386__or__x86_64__in public Xen headers is, in my opinion, a no-go (these header should all be suitable for building e.g. Windows drivers, too - I know this
isn't
generally the case at present, but I don't think anything else can be the
goal,
and hence the situation shouldn't be made worse)Ideas for that one? Ok to create
xen/include/public/compiler.hwith that kind of stuff in?
I think it would be reasonable to put this stuff in a (new) Linux-specific header file that wraps the Xen-public blkif.h. We could put just enough support in blkif.h itself to allow it to be multiply-compiled. Then different OSes can wrap or rewrite blkif.h as they see fit to get the required layout for 32-bit and 64-bit ABIs. This conveniently sidesteps some of these issues and allows you to concentrate on Linux and GCC, while not constraining the implementation choices for anyone else.
-- Keir
Hi,
Quoted 7 lines
I think it would be reasonable to put this stuff in a (new) Linux-specific header file that wraps the Xen-public
blkif.h. We could put just enough support inblkif.hitself to allow it to be multiply-compiled. Then different OSes can wrap or rewriteblkif.has they see fit to get the required layout for 32-bit and 64-bit ABIs. This conveniently sidesteps some of these issues and allows you to concentrate on Linux and GCC, while not constraining the implementation choices for anyone else.
Next interation with exactly that implemented, this time even tested with blkback in all four combinations out of 32/64 dom0, 32/64 guest.
cheers,
Gerd
Signature · 1 line
Gerd Hoffmann <[email protected]>
multiprotocol blkback drivers.
This is a patch for the block interface, frontend drivers, backend drivers and tools to support multiple ring protocols. Right there are now just two: the 32bit and the 64bit one. If needed it can be extended.
Interface changes (io/blkif.h)
* Have both request structs there, with "v1" and "v2" added to the name. The old name is aliased to the native protocol of the architecture.
* Add helper functions to convert v1/v2 requests to native.
Frontend changes:
* Create a new node "protocol", add the protocol number it speaks there.
Backend changes:
* Look at the "protocol" number of the frontend and switch ring handling accordingly. If the protocol node isn't present it assumes native protocol.
* As the request struct is copied anyway before being processed (for security reasons) it is converted to native at that point so most backend code doesn't need to know what the frontend speaks.
* In case of blktap this is completely transparent to userspace, the kernel/userspace ring is always native no matter what the frontend speaks.
Tools changes:
* Add one more option to the disk configuration, so one can specify the protocol the frontend speaks in the config file. This is needed for old frontends which don't advertise the protocol they are speaking themself.
I'm not that happy with this approach, but it works for now and I'm kida lost in the stack of python classes doing domain and device handling ...
--- linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c | 64 ++++++++---- linux-2.6-xen-sparse/drivers/xen/blkback/common.h | 6 - linux-2.6-xen-sparse/drivers/xen/blkback/interface.c | 25 +++- linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c | 14 ++ linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c | 7 + linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c | 63 ++++++++---- linux-2.6-xen-sparse/drivers/xen/blktap/common.h | 6 - linux-2.6-xen-sparse/drivers/xen/blktap/interface.c | 25 +++- linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c | 14 ++ linux-2.6-xen-sparse/include/xen/blkif.h | 99 +++++++++++++++++++ tools/python/xen/xend/server/blkif.py | 3 tools/python/xen/xm/create.py | 7 + xen/include/public/io/blkif.h | 14 +- 13 files changed, 282 insertions(+), 65 deletions(-)
linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c +43 -21
@@ -298,17 +298,20 @@ irqreturn_t blkif_be_int(int irq, void *static int do_block_io_op (blkif_t *blkif) { -blkif_back_ring_t *blk_ring = &blkif->blk_ring; +blkif_back_rings_t *blk_rings = &blkif->blk_rings;blkif_request_t req;pending_req_t *pending_req;RING_IDX rc, rp;int more_to_do =0 ; - rc = blk_ring->req_cons; - rp = blk_ring->sring->req_prod; + rc = blk_rings->co.req_cons; + rp = blk_rings->co.sring->req_prod;rmb ();/* Ensure we see queued requests up to 'rp'. */ -while ((rc != rp) && !RING_REQUEST_CONS_OVERFLOW (blk_ring, rc)) { +while ((rc != rp)) { + +if (RING_REQUEST_CONS_OVERFLOW (&blk_rings->co, rc)) +break ; pending_req =alloc_req ();if (NULL == pending_req) {
@@ -317,8 +320,17 @@ static int do_block_io_op(blkif_t *blkifbreak ; } -memcpy (&req,RING_GET_REQUEST (blk_ring, rc),sizeof (req)); - blk_ring->req_cons = ++rc;/* before make_response() */ +switch (blkif->blk_protocol) { +case 1 : +blkif_get_v1_req (&req,RING_GET_REQUEST (&blk_rings->v1, rc)); +break ; +case 2 : +blkif_get_v2_req (&req,RING_GET_REQUEST (&blk_rings->v2, rc)); +break ; +default : +BUG (); + } + blk_rings->co.req_cons = ++rc;/* before make_response() */ switch (req.operation) {case BLKIF_OP_READ :
@@ -498,34 +510,44 @@ static void dispatch_rw_block_io(blkif_tstatic void make_response (blkif_t *blkif,unsigned long id,unsigned short op,int st) { -blkif_response_t *resp; +blkif_response_t resp;unsigned long flags; -blkif_back_ring_t *blk_ring = &blkif->blk_ring; +blkif_back_rings_t *blk_rings = &blkif->blk_rings;int more_to_do =0 ;int notify; -spin_lock_irqsave (&blkif->blk_ring_lock, flags); - -/* Place on the response ring for the relevant domain. */ - resp =RING_GET_RESPONSE (blk_ring, blk_ring->rsp_prod_pvt); - resp->id = id; - resp->operation = op; - resp->status = st; - blk_ring->rsp_prod_pvt++; -RING_PUSH_RESPONSES_AND_CHECK_NOTIFY (blk_ring, notify); + resp.id = id; + resp.operation = op; + resp.status = st; -if (blk_ring->rsp_prod_pvt == blk_ring->req_cons) { +spin_lock_irqsave (&blkif->blk_ring_lock, flags); +/* Place on the response ring for the relevant domain. */ +switch (blkif->blk_protocol) { +case 1 : +memcpy (RING_GET_RESPONSE (&blk_rings->v1, blk_rings->v1.rsp_prod_pvt), + &resp,sizeof (resp)); +break ; +case 2 : +memcpy (RING_GET_RESPONSE (&blk_rings->v2, blk_rings->v2.rsp_prod_pvt), + &resp,sizeof (resp)); +break ; +default : +BUG (); + } + blk_rings->co.rsp_prod_pvt++; +RING_PUSH_RESPONSES_AND_CHECK_NOTIFY (&blk_rings->co, notify); +if (blk_rings->co.rsp_prod_pvt == blk_rings->co.req_cons) {/* * Tail check for pending requests. Allows frontend to avoid * notifications if requests are already in flight (lower * overheads and promotes batching). */ -RING_FINAL_CHECK_FOR_REQUESTS (blk_ring, more_to_do); +RING_FINAL_CHECK_FOR_REQUESTS (&blk_rings->co, more_to_do); - }else if (RING_HAS_UNCONSUMED_REQUESTS (blk_ring)) { + }else if (RING_HAS_UNCONSUMED_REQUESTS (&blk_rings->co)) { more_to_do =1 ; - } +spin_unlock_irqrestore (&blkif->blk_ring_lock, flags);if (more_to_do)
linux-2.6-xen-sparse/drivers/xen/blkback/common.h +3 -3
@@ -40,8 +40,7 @@#include <asm/pgalloc.h> #include <xen/evtchn.h> #include <asm/hypervisor.h> -#include <xen/interface/io/blkif.h> -#include <xen/interface/io/ring.h> +#include <xen/blkif.h> #include <xen/gnttab.h> #include <xen/driver_util.h> #include <xen/xenbus.h>
@@ -68,7 +67,8 @@ typedef struct blkif_st {unsigned int evtchn;unsigned int irq;/* Comms information. */ -blkif_back_ring_t blk_ring; +int blk_protocol; +blkif_back_rings_t blk_rings;struct vm_struct *blk_ring_area;/* The VBD attached to this interface. */ struct vbd vbd;
linux-2.6-xen-sparse/drivers/xen/blkback/interface.c +20 -5
@@ -95,7 +95,6 @@ static void unmap_frontend_page(blkif_tint blkif_map (blkif_t *blkif,unsigned long shared_page,unsigned int evtchn) { -blkif_sring_t *sring;int err;struct evtchn_bind_interdomain bind_interdomain;
@@ -125,8 +124,24 @@ int blkif_map(blkif_t *blkif, unsigned l blkif->evtchn = bind_interdomain.local_port; - sring = (blkif_sring_t *)blkif->blk_ring_area->addr; -BACK_RING_INIT (&blkif->blk_ring, sring,PAGE_SIZE ); +switch (blkif->blk_protocol) { +case 1 : + { +blkif_v1_sring_t *sring_v1; + sring_v1 = (blkif_v1_sring_t *)blkif->blk_ring_area->addr; +BACK_RING_INIT (&blkif->blk_rings.v1, sring_v1,PAGE_SIZE ); +break ; + } +case 2 : + { +blkif_v2_sring_t *sring_v2; + sring_v2 = (blkif_v2_sring_t *)blkif->blk_ring_area->addr; +BACK_RING_INIT (&blkif->blk_rings.v2, sring_v2,PAGE_SIZE ); +break ; + } +default : +BUG (); + } blkif->irq =bind_evtchn_to_irqhandler ( blkif->evtchn, blkif_be_int,0 ,"blkif-backend" , blkif);
@@ -150,10 +165,10 @@ void blkif_disconnect(blkif_t *blkif) blkif->irq =0 ; } -if (blkif->blk_ring.sring) { +if (blkif->blk_rings.co.sring) {unmap_frontend_page (blkif);free_vm_area (blkif->blk_ring_area); - blkif->blk_ring.sring =NULL ; + blkif->blk_rings.co.sring =NULL ; } }
linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c +14 -0
@@ -435,6 +435,7 @@ static int connect_ring(struct backend_istruct xenbus_device *dev = be->dev;unsigned long ring_ref;unsigned int evtchn; +unsigned int protocol;int err;DPRINTK ("%s" , dev->otherend);
@@ -448,6 +449,19 @@ static int connect_ring(struct backend_ireturn err; } + err =xenbus_gather (XBT_NIL , dev->otherend,"protocol" , +"%u" , &protocol,NULL ); +if (err) + protocol =BLKIF_NATIVE_PROTOCOL ; +if (protocol <1 || protocol >2 ) { +xenbus_dev_fatal (dev, err,"unknown fe protocol %d" , protocol); +return -1 ; + } + be->blkif->blk_protocol = protocol; + +printk ("blkback: ring-ref %ld, event-channel %d, protocol %d\n" , + ring_ref, evtchn, protocol); +/* Map the shared frame, irq etc. */ err =blkif_map (be->blkif, ring_ref, evtchn);if (err) {
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c +7 -0
@@ -45,6 +45,7 @@#include <xen/xenbus.h> #include <xen/interface/grant_table.h> #include <xen/gnttab.h> +#include <xen/blkif.h> #include <asm/hypervisor.h> #include <asm/maddr.h>
@@ -180,6 +181,12 @@ again: message ="writing event-channel" ; goto abort_transaction; } + err =xenbus_printf (xbt, dev->nodename, +"protocol" ,"%u" ,BLKIF_NATIVE_PROTOCOL ); +if (err) { + message ="writing protocol" ; + goto abort_transaction; + } err =xenbus_transaction_end (xbt,0 );if (err) {
xen/include/public/io/blkif.h +8 -6
@@ -71,18 +71,20 @@*/ #define BLKIF_MAX_SEGMENTS_PER_REQUEST 11 +struct blkif_request_segment { +grant_ref_t gref;/* reference to I/O buffer frame */ +/* @first_sect: first sector in frame to transfer (inclusive). */ +/* @last_sect: last sector in frame to transfer (inclusive). */ +uint8_t first_sect, last_sect; +}; +struct blkif_request {uint8_t operation;/* BLKIF_OP_??? */ uint8_t nr_segments;/* number of segments */ blkif_vdev_t handle;/* only for read/write requests */ uint64_t id;/* private guest value, echoed in resp */ blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ -struct blkif_request_segment { -grant_ref_t gref;/* reference to I/O buffer frame */ -/* @first_sect: first sector in frame to transfer (inclusive). */ -/* @last_sect: last sector in frame to transfer (inclusive). */ -uint8_t first_sect, last_sect; - } seg[BLKIF_MAX_SEGMENTS_PER_REQUEST ]; +struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST ]; };typedef struct blkif_request blkif_request_t ;
tools/python/xen/xend/server/blkif.py +3 -0
@@ -38,6 +38,7 @@ class BlkifController(DevController): """@see DevController.getDeviceDetails""" uname = config.get('uname', '') dev = config.get('dev', '') + protocol = config.get('protocol') if 'ioemu:' in dev: (_, dev) = string.split(dev, ':', 1)
@@ -85,6 +86,8 @@ class BlkifController(DevController): front = { 'virtual-device' : "%i" % devid, 'device-type' : dev_type } + if protocol: + front.update({ 'protocol' : protocol }); return (devid, back, front)
tools/python/xen/xm/create.py +6 -1
@@ -531,7 +531,7 @@ def configure_image(vals): def configure_disks(config_devs, vals): """Create the config for disks (virtual block devices). """ - for (uname, dev, mode, backend) in vals.disk: + for (uname, dev, mode, backend, protocol) in vals.disk: if uname.startswith('tap:'): cls = 'tap' else:
@@ -543,6 +543,8 @@ def configure_disks(config_devs, vals): ['mode', mode ] ] if backend: config_vbd.append(['backend', backend]) + if protocol: + config_vbd.append(['protocol', protocol]) config_devs.append(['device', config_vbd]) def configure_pci(config_devs, vals):
@@ -787,7 +789,10 @@ def preprocess_disk(vals): n = len(d) if n == 3: d.append(None) + d.append(None) elif n == 4: + d.append(None) + elif n == 5: pass else: err('Invalid disk specifier: ' + v)
linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c +42 -21
112 lines not on this page · raw message
linux-2.6-xen-sparse/drivers/xen/blktap/common.h +3 -3
@@ -39,8 +39,7 @@#include <asm/pgalloc.h> #include <xen/evtchn.h> #include <asm/hypervisor.h> -#include <xen/interface/io/blkif.h> -#include <xen/interface/io/ring.h> +#include <xen/blkif.h> #include <xen/gnttab.h> #include <xen/driver_util.h>
@@ -59,7 +58,8 @@ typedef struct blkif_st {unsigned int evtchn;unsigned int irq;/* Comms information. */ -blkif_back_ring_t blk_ring; +int blk_protocol; +blkif_back_rings_t blk_rings;struct vm_struct *blk_ring_area;/* Back pointer to the backend_info. */ struct backend_info *be;
linux-2.6-xen-sparse/drivers/xen/blktap/interface.c +20 -5
@@ -96,7 +96,6 @@ static void unmap_frontend_page(blkif_tint tap_blkif_map (blkif_t *blkif,unsigned long shared_page,unsigned int evtchn) { -blkif_sring_t *sring;int err;struct evtchn_bind_interdomain bind_interdomain;
@@ -126,8 +125,24 @@ int tap_blkif_map(blkif_t *blkif, unsign blkif->evtchn = bind_interdomain.local_port; - sring = (blkif_sring_t *)blkif->blk_ring_area->addr; -BACK_RING_INIT (&blkif->blk_ring, sring,PAGE_SIZE ); +switch (blkif->blk_protocol) { +case 1 : + { +blkif_v1_sring_t *sring_v1; + sring_v1 = (blkif_v1_sring_t *)blkif->blk_ring_area->addr; +BACK_RING_INIT (&blkif->blk_rings.v1, sring_v1,PAGE_SIZE ); +break ; + } +case 2 : + { +blkif_v2_sring_t *sring_v2; + sring_v2 = (blkif_v2_sring_t *)blkif->blk_ring_area->addr; +BACK_RING_INIT (&blkif->blk_rings.v2, sring_v2,PAGE_SIZE ); +break ; + } +default : +BUG (); + } blkif->irq =bind_evtchn_to_irqhandler ( blkif->evtchn, tap_blkif_be_int,0 ,"blkif-backend" , blkif);
@@ -141,10 +156,10 @@ void tap_blkif_unmap(blkif_t *blkif)unbind_from_irqhandler (blkif->irq, blkif); blkif->irq =0 ; } -if (blkif->blk_ring.sring) { +if (blkif->blk_rings.co.sring) {unmap_frontend_page (blkif);free_vm_area (blkif->blk_ring_area); - blkif->blk_ring.sring =NULL ; + blkif->blk_rings.co.sring =NULL ; } }
linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c +14 -0
@@ -316,6 +316,7 @@ static int connect_ring(struct backend_istruct xenbus_device *dev = be->dev;unsigned long ring_ref;unsigned int evtchn; +unsigned int protocol;int err;DPRINTK ("%s\n" , dev->otherend);
@@ -329,6 +330,19 @@ static int connect_ring(struct backend_ireturn err; } + err =xenbus_gather (XBT_NIL , dev->otherend,"protocol" , +"%u" , &protocol,NULL ); +if (err) + protocol =BLKIF_NATIVE_PROTOCOL ; +if (protocol <1 || protocol >2 ) { +xenbus_dev_fatal (dev, err,"unknown fe protocol %d" , protocol); +return -1 ; + } + be->blkif->blk_protocol = protocol; + +printk ("blktap: ring-ref %ld, event-channel %d, protocol %d\n" , + ring_ref, evtchn, protocol); +/* Map the shared frame, irq etc. */ err =tap_blkif_map (be->blkif, ring_ref, evtchn);if (err) {
linux-2.6-xen-sparse/include/xen/blkif.h new file +99 -0
99 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Looks a lot nicer now, except that I dislike the replication of the request/response structures in now three places. Besides possibly being a maintenance issue, this now seems worse in terms of scaling up to eventual future protocol versions. I had understood Keir in a much different way - adding a compiler abstraction header (which maybe could even make use of Linux' native ones) to include/xen, and making use of its abstraction directly in xen/include/public/io/blkif.h.
Jan
Quoted 1 line
Quoted 1 line
Quoted 1 line
Gerd Hoffmann <[email protected]> 20.12.06 16:12 >>>
Hi,
Quoted 7 lines
I think it would be reasonable to put this stuff in a (new) Linux-specific header file that wraps the Xen-public
blkif.h. We could put just enough support inblkif.hitself to allow it to be multiply-compiled. Then different OSes can wrap or rewriteblkif.has they see fit to get the required layout for 32-bit and 64-bit ABIs. This conveniently sidesteps some of these issues and allows you to concentrate on Linux and GCC, while not constraining the implementation choices for anyone else.
Next interation with exactly that implemented, this time even tested with blkback in all four combinations out of 32/64 dom0, 32/64 guest.
cheers,
Gerd
Signature · 1 line
Gerd Hoffmann <[email protected]>
Quoted 9 lines · Jan Beulich
Looks a lot nicer now, except that I dislike the replication of the request/response
structures in now three places. Besides possibly being a maintenance issue, this
now seems worse in terms of scaling up to eventual future protocol versions. I had
understood Keir in a much different way - adding a compiler abstraction header (which maybe could even make use of Linux' native ones) toinclude/xen, and making use of its abstraction directly inxen/include/public/io/blkif.h.
I quite like the explicitness of this approach. The duplication is small and the structures aren't going to change (without changing protocol version too) so maintenance is not that much of an issue. It would be nicer to put the structure definition inside a macro, instantiated multiple times, or inside another header file, included multiple times, though.
My other suggested approach is slightly hindered by the fact that all the Xen public headers are include-only-once, although we could circumvent that for this case I suppose. It's also questionable whether this can be done really cleanly in a way that most compilers can adapt to -- do most have the kind of flexible packing pragmas that GCC has?
Xen/include/public/io/blkif.h changes infrequently enough that we could define linux/include/xen/blkif.h to be Linux's version and not include the Xen-provided one directly at all. The Xen headers need Linux formatting anyway, so it's not like the Linux blkif.h will ever be a direct copy of the original Xen-provided blkif.h.
-- Keir