Commit 42c7841d authored by Konrad Rzeszutek Wilk's avatar Konrad Rzeszutek Wilk

xen-blkback: Inline some of the functions that were moved from vbd/interface.c

Shuffling code around.
Signed-off-by: default avatarKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
parent 6cd0388c
...@@ -170,75 +170,9 @@ static void free_req(struct pending_req *req) ...@@ -170,75 +170,9 @@ static void free_req(struct pending_req *req)
* Routines for managing virtual block devices (vbds). * 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) static int vbd_translate(struct phys_req *req, struct blkif_st *blkif,
{ int operation)
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; struct vbd *vbd = &blkif->vbd;
int rc = -EACCES; int rc = -EACCES;
...@@ -257,13 +191,13 @@ int vbd_translate(struct phys_req *req, struct blkif_st *blkif, int operation) ...@@ -257,13 +191,13 @@ int vbd_translate(struct phys_req *req, struct blkif_st *blkif, int operation)
return rc; return rc;
} }
void vbd_resize(struct blkif_st *blkif) static void vbd_resize(struct blkif_st *blkif)
{ {
struct vbd *vbd = &blkif->vbd; struct vbd *vbd = &blkif->vbd;
struct xenbus_transaction xbt; struct xenbus_transaction xbt;
int err; int err;
struct xenbus_device *dev = blkback_xenbus(blkif->be); struct xenbus_device *dev = blkback_xenbus(blkif->be);
unsigned long long new_size = vbd_size(vbd); unsigned long long new_size = vbd_sz(vbd);
printk(KERN_INFO "VBD Resize: Domid: %d, Device: (%d, %d)\n", printk(KERN_INFO "VBD Resize: Domid: %d, Device: (%d, %d)\n",
blkif->domid, MAJOR(vbd->pdevice), MINOR(vbd->pdevice)); blkif->domid, MAJOR(vbd->pdevice), MINOR(vbd->pdevice));
...@@ -276,7 +210,7 @@ void vbd_resize(struct blkif_st *blkif) ...@@ -276,7 +210,7 @@ void vbd_resize(struct blkif_st *blkif)
return; return;
} }
err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu", err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu",
vbd_size(vbd)); (unsigned long long)vbd_sz(vbd));
if (err) { if (err) {
printk(KERN_WARNING "Error writing new size"); printk(KERN_WARNING "Error writing new size");
goto abort; goto abort;
...@@ -344,7 +278,7 @@ int blkif_schedule(void *arg) ...@@ -344,7 +278,7 @@ int blkif_schedule(void *arg)
while (!kthread_should_stop()) { while (!kthread_should_stop()) {
if (try_to_freeze()) if (try_to_freeze())
continue; continue;
if (unlikely(vbd->size != vbd_size(vbd))) if (unlikely(vbd->size != vbd_sz(vbd)))
vbd_resize(blkif); vbd_resize(blkif);
wait_event_interruptible( wait_event_interruptible(
......
...@@ -95,12 +95,10 @@ struct blkif_st { ...@@ -95,12 +95,10 @@ struct blkif_st {
grant_ref_t shmem_ref; grant_ref_t shmem_ref;
}; };
struct blkif_st *blkif_alloc(domid_t domid);
void blkif_disconnect(struct blkif_st *blkif); #define vbd_sz(_v) ((_v)->bdev->bd_part ? \
void blkif_free(struct blkif_st *blkif); (_v)->bdev->bd_part->nr_sects : \
int blkif_map(struct blkif_st *blkif, unsigned long shared_page, get_capacity((_v)->bdev->bd_disk))
unsigned int evtchn);
void vbd_resize(struct blkif_st *blkif);
#define blkif_get(_b) (atomic_inc(&(_b)->refcnt)) #define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
#define blkif_put(_b) \ #define blkif_put(_b) \
...@@ -109,24 +107,12 @@ void vbd_resize(struct blkif_st *blkif); ...@@ -109,24 +107,12 @@ void vbd_resize(struct blkif_st *blkif);
wake_up(&(_b)->waiting_to_free);\ wake_up(&(_b)->waiting_to_free);\
} while (0) } while (0)
/* Create a vbd. */
int vbd_create(struct blkif_st *blkif, blkif_vdev_t vdevice, unsigned major,
unsigned minor, int readonly, int cdrom);
void vbd_free(struct vbd *vbd);
unsigned long long vbd_size(struct vbd *vbd);
unsigned int vbd_info(struct vbd *vbd);
unsigned long vbd_secsize(struct vbd *vbd);
struct phys_req { struct phys_req {
unsigned short dev; unsigned short dev;
unsigned short nr_sects; unsigned short nr_sects;
struct block_device *bdev; struct block_device *bdev;
blkif_sector_t sector_number; blkif_sector_t sector_number;
}; };
int vbd_translate(struct phys_req *req, struct blkif_st *blkif, int operation);
int blkif_interface_init(void); int blkif_interface_init(void);
int blkif_xenbus_init(void); int blkif_xenbus_init(void);
......
...@@ -327,6 +327,56 @@ void xenvbd_sysfs_delif(struct xenbus_device *dev) ...@@ -327,6 +327,56 @@ void xenvbd_sysfs_delif(struct xenbus_device *dev)
device_remove_file(&dev->dev, &dev_attr_physical_device); device_remove_file(&dev->dev, &dev_attr_physical_device);
} }
static void vbd_free(struct vbd *vbd)
{
if (vbd->bdev)
blkdev_put(vbd->bdev, vbd->readonly ? FMODE_READ : FMODE_WRITE);
vbd->bdev = NULL;
}
static 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_sz(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;
}
static int blkback_remove(struct xenbus_device *dev) static int blkback_remove(struct xenbus_device *dev)
{ {
struct backend_info *be = dev_get_drvdata(&dev->dev); struct backend_info *be = dev_get_drvdata(&dev->dev);
...@@ -595,7 +645,7 @@ static void connect(struct backend_info *be) ...@@ -595,7 +645,7 @@ static void connect(struct backend_info *be)
goto abort; goto abort;
err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu", err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu",
vbd_size(&be->blkif->vbd)); (unsigned long long)vbd_sz(&be->blkif->vbd));
if (err) { if (err) {
xenbus_dev_fatal(dev, err, "writing %s/sectors", xenbus_dev_fatal(dev, err, "writing %s/sectors",
dev->nodename); dev->nodename);
...@@ -604,14 +654,16 @@ static void connect(struct backend_info *be) ...@@ -604,14 +654,16 @@ static void connect(struct backend_info *be)
/* FIXME: use a typename instead */ /* FIXME: use a typename instead */
err = xenbus_printf(xbt, dev->nodename, "info", "%u", err = xenbus_printf(xbt, dev->nodename, "info", "%u",
vbd_info(&be->blkif->vbd)); be->blkif->vbd.type |
(be->blkif->vbd.readonly ? VDISK_READONLY : 0));
if (err) { if (err) {
xenbus_dev_fatal(dev, err, "writing %s/info", xenbus_dev_fatal(dev, err, "writing %s/info",
dev->nodename); dev->nodename);
goto abort; goto abort;
} }
err = xenbus_printf(xbt, dev->nodename, "sector-size", "%lu", err = xenbus_printf(xbt, dev->nodename, "sector-size", "%lu",
vbd_secsize(&be->blkif->vbd)); (unsigned long)
bdev_logical_block_size(be->blkif->vbd.bdev));
if (err) { if (err) {
xenbus_dev_fatal(dev, err, "writing %s/sector-size", xenbus_dev_fatal(dev, err, "writing %s/sector-size",
dev->nodename); dev->nodename);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment