Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 251239
b: refs/heads/master
c: ee9ff85
h: refs/heads/master
i:
  251237: 7e408e1
  251235: 74fd568
  251231: 3493c5d
v: v3
  • Loading branch information
Konrad Rzeszutek Wilk committed Apr 20, 2011
1 parent cbf228c commit 116e8e0
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 349 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: dfc07b13dcacefda6ebdea14584ed8724dc980ef
refs/heads/master: ee9ff8537eacb4383bf9146df6c21b9301c9baa2
2 changes: 1 addition & 1 deletion trunk/drivers/block/xen-blkback/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
obj-$(CONFIG_XEN_BLKDEV_BACKEND) := xen-blkback.o

xen-blkback-y := blkback.o xenbus.o interface.o vbd.o
xen-blkback-y := blkback.o xenbus.o
135 changes: 135 additions & 0 deletions trunk/drivers/block/xen-blkback/blkback.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,141 @@ static void free_req(struct pending_req *req)
wake_up(&blkbk->pending_free_wq);
}

/*
* Routines for managing virtual block devices (vbds).
*/

#define vbd_sz(_v) ((_v)->bdev->bd_part ? \
(_v)->bdev->bd_part->nr_sects : \
get_capacity((_v)->bdev->bd_disk))

unsigned long long vbd_size(struct vbd *vbd)
{
return vbd_sz(vbd);
}

unsigned int vbd_info(struct vbd *vbd)
{
return vbd->type | (vbd->readonly ? VDISK_READONLY : 0);
}

unsigned long vbd_secsize(struct vbd *vbd)
{
return bdev_logical_block_size(vbd->bdev);
}

int vbd_create(struct blkif_st *blkif, blkif_vdev_t handle, unsigned major,
unsigned minor, int readonly, int cdrom)
{
struct vbd *vbd;
struct block_device *bdev;

vbd = &blkif->vbd;
vbd->handle = handle;
vbd->readonly = readonly;
vbd->type = 0;

vbd->pdevice = MKDEV(major, minor);

bdev = blkdev_get_by_dev(vbd->pdevice, vbd->readonly ?
FMODE_READ : FMODE_WRITE, NULL);

if (IS_ERR(bdev)) {
DPRINTK("vbd_creat: device %08x could not be opened.\n",
vbd->pdevice);
return -ENOENT;
}

vbd->bdev = bdev;
vbd->size = vbd_size(vbd);

if (vbd->bdev->bd_disk == NULL) {
DPRINTK("vbd_creat: device %08x doesn't exist.\n",
vbd->pdevice);
vbd_free(vbd);
return -ENOENT;
}

if (vbd->bdev->bd_disk->flags & GENHD_FL_CD || cdrom)
vbd->type |= VDISK_CDROM;
if (vbd->bdev->bd_disk->flags & GENHD_FL_REMOVABLE)
vbd->type |= VDISK_REMOVABLE;

DPRINTK("Successful creation of handle=%04x (dom=%u)\n",
handle, blkif->domid);
return 0;
}

void vbd_free(struct vbd *vbd)
{
if (vbd->bdev)
blkdev_put(vbd->bdev, vbd->readonly ? FMODE_READ : FMODE_WRITE);
vbd->bdev = NULL;
}

int vbd_translate(struct phys_req *req, struct blkif_st *blkif, int operation)
{
struct vbd *vbd = &blkif->vbd;
int rc = -EACCES;

if ((operation != READ) && vbd->readonly)
goto out;

if (unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd)))
goto out;

req->dev = vbd->pdevice;
req->bdev = vbd->bdev;
rc = 0;

out:
return rc;
}

void vbd_resize(struct blkif_st *blkif)
{
struct vbd *vbd = &blkif->vbd;
struct xenbus_transaction xbt;
int err;
struct xenbus_device *dev = blkback_xenbus(blkif->be);
unsigned long long new_size = vbd_size(vbd);

printk(KERN_INFO "VBD Resize: Domid: %d, Device: (%d, %d)\n",
blkif->domid, MAJOR(vbd->pdevice), MINOR(vbd->pdevice));
printk(KERN_INFO "VBD Resize: new size %llu\n", new_size);
vbd->size = new_size;
again:
err = xenbus_transaction_start(&xbt);
if (err) {
printk(KERN_WARNING "Error starting transaction");
return;
}
err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu",
vbd_size(vbd));
if (err) {
printk(KERN_WARNING "Error writing new size");
goto abort;
}
/*
* Write the current state; we will use this to synchronize
* the front-end. If the current state is "connected" the
* front-end will get the new size information online.
*/
err = xenbus_printf(xbt, dev->nodename, "state", "%d", dev->state);
if (err) {
printk(KERN_WARNING "Error writing the state");
goto abort;
}

err = xenbus_transaction_end(xbt, 0);
if (err == -EAGAIN)
goto again;
if (err)
printk(KERN_WARNING "Error ending transaction");
abort:
xenbus_transaction_end(xbt, 1);
}

/*
* Notification from the guest OS.
*/
Expand Down
185 changes: 0 additions & 185 deletions trunk/drivers/block/xen-blkback/interface.c

This file was deleted.

Loading

0 comments on commit 116e8e0

Please sign in to comment.