Mailing List Archive

Clean up vbd probing, and include hardware sector size in the probe
ChangeSet 1.1492, 2005/05/20 20:34:47+01:00, kaf24@firebug.cl.cam.ac.uk

Clean up vbd probing, and include hardware sector size in the probe
information. blkback ensures that all requests are aligned to
hardware sector size and returns error if this is not so.
In blkfront we now have a request_queue per vbd, with hardsect_size
set appropriately.
It is now once again possible to mount a CDROM in a domU.
Signed-off-by: Keir Fraser <keir@xensource.com>



linux-2.4.29-xen-sparse/arch/xen/drivers/blkif/frontend/vbd.c | 31 +---
linux-2.6.11-xen-sparse/drivers/xen/blkback/blkback.c | 8 +
linux-2.6.11-xen-sparse/drivers/xen/blkback/vbd.c | 20 +-
linux-2.6.11-xen-sparse/drivers/xen/blkfront/blkfront.c | 38 +++--
linux-2.6.11-xen-sparse/drivers/xen/blkfront/block.h | 5
linux-2.6.11-xen-sparse/drivers/xen/blkfront/vbd.c | 70 +++++-----
netbsd-2.0-xen-sparse/sys/arch/xen/xen/xbd.c | 12 -
tools/blktap/parallax-threaded.c | 2
tools/blktap/parallax.c | 2
xen/include/public/io/blkif.h | 24 +--
10 files changed, 104 insertions(+), 108 deletions(-)


diff -Nru a/linux-2.4.29-xen-sparse/arch/xen/drivers/blkif/frontend/vbd.c b/linux-2.4.29-xen-sparse/arch/xen/drivers/blkif/frontend/vbd.c
--- a/linux-2.4.29-xen-sparse/arch/xen/drivers/blkif/frontend/vbd.c 2005-05-20 16:02:22 -04:00
+++ b/linux-2.4.29-xen-sparse/arch/xen/drivers/blkif/frontend/vbd.c 2005-05-20 16:02:22 -04:00
@@ -136,11 +136,6 @@
major_name = XLSCSI_MAJOR_NAME;
max_part = XLSCSI_MAX_PART;

- } else if (VDISK_VIRTUAL(xd->info)) {
-
- major_name = XLVBD_MAJOR_NAME;
- max_part = XLVBD_MAX_PART;
-
} else {

/* SMH: hmm - probably a CCISS driver or sim; assume CCISS for now */
@@ -247,8 +242,8 @@
blk_size[major] = gd->sizes;
}

- if ( VDISK_READONLY(xd->info) )
- set_device_ro(device, 1);
+ if ( xd->info & VDISK_READONLY )
+ set_device_ro(device, 1);

gd->flags[minor >> gd->minor_shift] |= GENHD_FL_XEN;

@@ -297,20 +292,16 @@
gd->sizes[minor] = capacity>>(BLOCK_SIZE_BITS-9);

/* Some final fix-ups depending on the device type */
- switch ( VDISK_TYPE(xd->info) )
+ if ( xd->info & VDISK_REMOVABLE )
{
- case VDISK_TYPE_CDROM:
- case VDISK_TYPE_FLOPPY:
- case VDISK_TYPE_TAPE:
gd->flags[minor >> gd->minor_shift] |= GENHD_FL_REMOVABLE;
printk(KERN_ALERT
"Skipping partition check on %s /dev/%s\n",
- VDISK_TYPE(xd->info)==VDISK_TYPE_CDROM ? "cdrom" :
- (VDISK_TYPE(xd->info)==VDISK_TYPE_TAPE ? "tape" :
- "floppy"), disk_name(gd, MINOR(device), buf));
- break;
-
- case VDISK_TYPE_DISK:
+ (xd->info & VDISK_CDROM) ? "cdrom" : "removable",
+ disk_name(gd, MINOR(device), buf));
+ }
+ else
+ {
/* Only check partitions on real discs (not virtual!). */
if ( gd->flags[minor>>gd->minor_shift] & GENHD_FL_VIRT_PARTNS )
{
@@ -320,12 +311,6 @@
break;
}
register_disk(gd, device, gd->max_p, &xlvbd_block_fops, capacity);
- break;
-
- default:
- printk(KERN_ALERT "XenoLinux: unknown device type %d\n",
- VDISK_TYPE(xd->info));
- break;
}
}

diff -Nru a/linux-2.6.11-xen-sparse/drivers/xen/blkback/blkback.c b/linux-2.6.11-xen-sparse/drivers/xen/blkback/blkback.c
--- a/linux-2.6.11-xen-sparse/drivers/xen/blkback/blkback.c 2005-05-20 16:02:22 -04:00
+++ b/linux-2.6.11-xen-sparse/drivers/xen/blkback/blkback.c 2005-05-20 16:02:22 -04:00
@@ -623,6 +623,13 @@

for ( i = 0; i < nseg; i++ )
{
+ if ( ((int)preq.sector_number|(int)seg[i].nsec) &
+ ((bdev_hardsect_size(preq.bdev) >> 9) - 1) )
+ {
+ DPRINTK("Misaligned I/O request from domain %d", blkif->domid);
+ goto cleanup_and_fail;
+ }
+
while ( (bio == NULL) ||
(bio_add_page(bio,
virt_to_page(MMAP_VADDR(pending_idx, i)),
@@ -632,6 +639,7 @@
bio = biolist[nbio++] = bio_alloc(GFP_KERNEL, nseg-i);
if ( unlikely(bio == NULL) )
{
+ cleanup_and_fail:
for ( i = 0; i < (nbio-1); i++ )
bio_put(biolist[i]);
fast_flush_area(pending_idx, nseg);
diff -Nru a/linux-2.6.11-xen-sparse/drivers/xen/blkback/vbd.c b/linux-2.6.11-xen-sparse/drivers/xen/blkback/vbd.c
--- a/linux-2.6.11-xen-sparse/drivers/xen/blkback/vbd.c 2005-05-20 16:02:22 -04:00
+++ b/linux-2.6.11-xen-sparse/drivers/xen/blkback/vbd.c 2005-05-20 16:02:22 -04:00
@@ -15,7 +15,7 @@
struct vbd {
blkif_vdev_t vdevice; /* what the domain refers to this vbd as */
unsigned char readonly; /* Non-zero -> read-only */
- unsigned char type; /* VDISK_TYPE_xxx */
+ unsigned char type; /* VDISK_xxx */
blkif_pdev_t pdevice; /* phys device that this vbd maps to */
struct block_device *bdev;
rb_node_t rb; /* for linking into R-B tree lookup struct */
@@ -30,6 +30,7 @@
#else
#define vbd_sz(_v) (blk_size[MAJOR((_v)->pdevice)][MINOR((_v)->pdevice)]*2)
#define bdev_put(_b) ((void)0)
+#define bdev_hardsect_size(_b) 512
#endif

void vbd_create(blkif_be_vbd_create_t *create)
@@ -78,6 +79,7 @@

vbd->vdevice = vdevice;
vbd->readonly = create->readonly;
+ vbd->type = 0;

/* Mask to 16-bit for compatibility with old tools */
vbd->pdevice = create->pdevice & 0xffff;
@@ -101,8 +103,11 @@
return;
}

- vbd->type = (vbd->bdev->bd_disk->flags & GENHD_FL_CD) ?
- VDISK_TYPE_CDROM : VDISK_TYPE_DISK;
+ if ( vbd->bdev->bd_disk->flags & GENHD_FL_CD )
+ vbd->type |= VDISK_CDROM;
+ if ( vbd->bdev->bd_disk->flags & GENHD_FL_REMOVABLE )
+ vbd->type |= VDISK_REMOVABLE;
+
#else
if ( (blk_size[MAJOR(vbd->pdevice)] == NULL) || (vbd_sz(vbd) == 0) )
{
@@ -110,8 +115,6 @@
create->status = BLKIF_BE_STATUS_PHYSDEV_NOT_FOUND;
return;
}
-
- vbd->type = VDISK_TYPE_DISK;
#endif

spin_lock(&blkif->vbd_lock);
@@ -189,9 +192,10 @@
static void vbd_probe_single(
blkif_t *blkif, vdisk_t *vbd_info, struct vbd *vbd)
{
- vbd_info->device = vbd->vdevice;
- vbd_info->info = vbd->type | (vbd->readonly ? VDISK_FLAG_RO : 0);
- vbd_info->capacity = vbd_sz(vbd);
+ vbd_info->device = vbd->vdevice;
+ vbd_info->info = vbd->type | (vbd->readonly ? VDISK_READONLY : 0);
+ vbd_info->capacity = vbd_sz(vbd);
+ vbd_info->sector_size = bdev_hardsect_size(vbd->bdev);
}


diff -Nru a/linux-2.6.11-xen-sparse/drivers/xen/blkfront/blkfront.c b/linux-2.6.11-xen-sparse/drivers/xen/blkfront/blkfront.c
--- a/linux-2.6.11-xen-sparse/drivers/xen/blkfront/blkfront.c 2005-05-20 16:02:22 -04:00
+++ b/linux-2.6.11-xen-sparse/drivers/xen/blkfront/blkfront.c 2005-05-20 16:02:22 -04:00
@@ -193,20 +193,21 @@
}
#endif /* ENABLE_VBD_UPDATE */

+static struct xlbd_disk_info *head_waiting = NULL;
static void kick_pending_request_queues(void)
{
- if ( (xlbd_blk_queue != NULL) &&
- test_bit(QUEUE_FLAG_STOPPED, &xlbd_blk_queue->queue_flags) )
+ struct xlbd_disk_info *di;
+ while ( ((di = head_waiting) != NULL) && !RING_FULL(&blk_ring) )
{
- blk_start_queue(xlbd_blk_queue);
- /* XXXcl call to request_fn should not be needed but
- * we get stuck without... needs investigating
- */
- xlbd_blk_queue->request_fn(xlbd_blk_queue);
+ head_waiting = di->next_waiting;
+ di->next_waiting = NULL;
+ /* Re-enable calldowns. */
+ blk_start_queue(di->rq);
+ /* Kick things off immediately. */
+ do_blkif_request(di->rq);
}
}

-
int blkif_open(struct inode *inode, struct file *filep)
{
struct gendisk *gd = inode->i_bdev->bd_disk;
@@ -277,8 +278,7 @@
*/
static int blkif_queue_request(struct request *req)
{
- struct xlbd_disk_info *di =
- (struct xlbd_disk_info *)req->rq_disk->private_data;
+ struct xlbd_disk_info *di = req->rq_disk->private_data;
unsigned long buffer_ma;
blkif_request_t *ring_req;
struct bio *bio;
@@ -353,6 +353,7 @@
*/
void do_blkif_request(request_queue_t *rq)
{
+ struct xlbd_disk_info *di;
struct request *req;
int queued;

@@ -369,10 +370,7 @@
}

if ( RING_FULL(&blk_ring) )
- {
- blk_stop_queue(rq);
- break;
- }
+ goto wait;

DPRINTK("do_blk_req %p: cmd %p, sec %lx, (%u/%li) buffer:%p [%s]\n",
req, req->cmd, req->sector, req->current_nr_sectors,
@@ -382,7 +380,15 @@
blkdev_dequeue_request(req);
if ( blkif_queue_request(req) )
{
- blk_stop_queue(rq);
+ wait:
+ di = req->rq_disk->private_data;
+ if ( di->next_waiting == NULL )
+ {
+ di->next_waiting = head_waiting;
+ head_waiting = di;
+ /* Avoid pointless unplugs. */
+ blk_stop_queue(rq);
+ }
break;
}

@@ -451,7 +457,7 @@
}

blk_ring.rsp_cons = i;
-
+
kick_pending_request_queues();

spin_unlock_irqrestore(&blkif_io_lock, flags);
diff -Nru a/linux-2.6.11-xen-sparse/drivers/xen/blkfront/block.h b/linux-2.6.11-xen-sparse/drivers/xen/blkfront/block.h
--- a/linux-2.6.11-xen-sparse/drivers/xen/blkfront/block.h 2005-05-20 16:02:22 -04:00
+++ b/linux-2.6.11-xen-sparse/drivers/xen/blkfront/block.h 2005-05-20 16:02:22 -04:00
@@ -90,13 +90,16 @@
struct xlbd_disk_info {

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