/* The disk structure for the kernel. */
struct gendisk *disk;
- /* Request tracking. */
- struct list_head reqs;
-
mempool_t *pool;
/* Process context for config space updates */
struct virtblk_req
{
- struct list_head list;
struct request *req;
struct virtio_blk_outhdr out_hdr;
struct virtio_scsi_inhdr in_hdr;
}
__blk_end_request_all(vbr->req, error);
- list_del(&vbr->list);
mempool_free(vbr, vblk->pool);
}
/* In case queue is stopped waiting for more buffers. */
return false;
}
- list_add_tail(&vbr->list, &vblk->reqs);
return true;
}
goto out_free_index;
}
- INIT_LIST_HEAD(&vblk->reqs);
spin_lock_init(&vblk->lock);
vblk->vdev = vdev;
vblk->sg_elems = sg_elems;
q->queuedata = vblk;
+#ifdef CONFIG_MARU // for virtio sdcard...
+ // index 0 for root partition
+ // index 1 for swap partition
+ // index over 2 for mmcblk
+ if (index > 1) {
+ snprintf(vblk->disk->disk_name, DISK_NAME_LEN, "mmcblk%d", index - 2);
+ }
+ else {
+ virtblk_name_format("vd", index, vblk->disk->disk_name, DISK_NAME_LEN);
+ }
+#else
virtblk_name_format("vd", index, vblk->disk->disk_name, DISK_NAME_LEN);
+#endif
vblk->disk->major = major;
vblk->disk->first_minor = index_to_minor(index);
{
struct virtio_blk *vblk = vdev->priv;
int index = vblk->index;
+ int refc;
/* Prevent config work handler from accessing the device. */
mutex_lock(&vblk->config_lock);
vblk->config_enable = false;
mutex_unlock(&vblk->config_lock);
- /* Nothing should be pending. */
- BUG_ON(!list_empty(&vblk->reqs));
+ del_gendisk(vblk->disk);
+ blk_cleanup_queue(vblk->disk->queue);
/* Stop all the virtqueues. */
vdev->config->reset(vdev);
flush_work(&vblk->config_work);
- del_gendisk(vblk->disk);
- blk_cleanup_queue(vblk->disk->queue);
+ refc = atomic_read(&disk_to_dev(vblk->disk)->kobj.kref.refcount);
put_disk(vblk->disk);
mempool_destroy(vblk->pool);
vdev->config->del_vqs(vdev);
kfree(vblk);
- ida_simple_remove(&vd_index_ida, index);
+
+ /* Only free device id if we don't have any users */
+ if (refc == 1)
+ ida_simple_remove(&vd_index_ida, index);
}
#ifdef CONFIG_PM
len += sprintf(buf+len, "\n");
return len;
}
+
+#ifdef CONFIG_MARU // for virtio sdcard...
+#include "linux/virtio_ids.h"
+static ssize_t type_show(struct device *_d,
+ struct device_attribute *attr, char *buf)
+{
+ struct virtio_device *dev = container_of(_d, struct virtio_device, dev);
+
+ if (dev->id.device == VIRTIO_ID_BLOCK) {
+ //FIXME
+ return sprintf(buf, "SD\n");
+ }
+ return sprintf(buf, "0\n");
+}
+#endif
static struct device_attribute virtio_dev_attrs[] = {
__ATTR_RO(device),
__ATTR_RO(vendor),
__ATTR_RO(status),
__ATTR_RO(modalias),
__ATTR_RO(features),
+#ifdef CONFIG_MARU
+ __ATTR_RO(type),
+#endif
__ATTR_NULL
};