Commit b43b7e81 authored by Vivek Goyal's avatar Vivek Goyal Committed by Miklos Szeredi

virtiofs: provide a helper function for virtqueue initialization

This reduces code duplication and make it little easier to read code.
Signed-off-by: default avatarVivek Goyal <vgoyal@redhat.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 6bbdd563
...@@ -24,6 +24,8 @@ enum { ...@@ -24,6 +24,8 @@ enum {
VQ_REQUEST VQ_REQUEST
}; };
#define VQ_NAME_LEN 24
/* Per-virtqueue state */ /* Per-virtqueue state */
struct virtio_fs_vq { struct virtio_fs_vq {
spinlock_t lock; spinlock_t lock;
...@@ -36,7 +38,7 @@ struct virtio_fs_vq { ...@@ -36,7 +38,7 @@ struct virtio_fs_vq {
bool connected; bool connected;
long in_flight; long in_flight;
struct completion in_flight_zero; /* No inflight requests */ struct completion in_flight_zero; /* No inflight requests */
char name[24]; char name[VQ_NAME_LEN];
} ____cacheline_aligned_in_smp; } ____cacheline_aligned_in_smp;
/* A virtio-fs device instance */ /* A virtio-fs device instance */
...@@ -596,6 +598,26 @@ static void virtio_fs_vq_done(struct virtqueue *vq) ...@@ -596,6 +598,26 @@ static void virtio_fs_vq_done(struct virtqueue *vq)
schedule_work(&fsvq->done_work); schedule_work(&fsvq->done_work);
} }
static void virtio_fs_init_vq(struct virtio_fs_vq *fsvq, char *name,
int vq_type)
{
strncpy(fsvq->name, name, VQ_NAME_LEN);
spin_lock_init(&fsvq->lock);
INIT_LIST_HEAD(&fsvq->queued_reqs);
INIT_LIST_HEAD(&fsvq->end_reqs);
init_completion(&fsvq->in_flight_zero);
if (vq_type == VQ_REQUEST) {
INIT_WORK(&fsvq->done_work, virtio_fs_requests_done_work);
INIT_DELAYED_WORK(&fsvq->dispatch_work,
virtio_fs_request_dispatch_work);
} else {
INIT_WORK(&fsvq->done_work, virtio_fs_hiprio_done_work);
INIT_DELAYED_WORK(&fsvq->dispatch_work,
virtio_fs_hiprio_dispatch_work);
}
}
/* Initialize virtqueues */ /* Initialize virtqueues */
static int virtio_fs_setup_vqs(struct virtio_device *vdev, static int virtio_fs_setup_vqs(struct virtio_device *vdev,
struct virtio_fs *fs) struct virtio_fs *fs)
...@@ -611,7 +633,7 @@ static int virtio_fs_setup_vqs(struct virtio_device *vdev, ...@@ -611,7 +633,7 @@ static int virtio_fs_setup_vqs(struct virtio_device *vdev,
if (fs->num_request_queues == 0) if (fs->num_request_queues == 0)
return -EINVAL; return -EINVAL;
fs->nvqs = 1 + fs->num_request_queues; fs->nvqs = VQ_REQUEST + fs->num_request_queues;
fs->vqs = kcalloc(fs->nvqs, sizeof(fs->vqs[VQ_HIPRIO]), GFP_KERNEL); fs->vqs = kcalloc(fs->nvqs, sizeof(fs->vqs[VQ_HIPRIO]), GFP_KERNEL);
if (!fs->vqs) if (!fs->vqs)
return -ENOMEM; return -ENOMEM;
...@@ -625,29 +647,17 @@ static int virtio_fs_setup_vqs(struct virtio_device *vdev, ...@@ -625,29 +647,17 @@ static int virtio_fs_setup_vqs(struct virtio_device *vdev,
goto out; goto out;
} }
/* Initialize the hiprio/forget request virtqueue */
callbacks[VQ_HIPRIO] = virtio_fs_vq_done; callbacks[VQ_HIPRIO] = virtio_fs_vq_done;
snprintf(fs->vqs[VQ_HIPRIO].name, sizeof(fs->vqs[VQ_HIPRIO].name), virtio_fs_init_vq(&fs->vqs[VQ_HIPRIO], "hiprio", VQ_HIPRIO);
"hiprio");
names[VQ_HIPRIO] = fs->vqs[VQ_HIPRIO].name; names[VQ_HIPRIO] = fs->vqs[VQ_HIPRIO].name;
INIT_WORK(&fs->vqs[VQ_HIPRIO].done_work, virtio_fs_hiprio_done_work);
INIT_LIST_HEAD(&fs->vqs[VQ_HIPRIO].queued_reqs);
INIT_LIST_HEAD(&fs->vqs[VQ_HIPRIO].end_reqs);
INIT_DELAYED_WORK(&fs->vqs[VQ_HIPRIO].dispatch_work,
virtio_fs_hiprio_dispatch_work);
init_completion(&fs->vqs[VQ_HIPRIO].in_flight_zero);
spin_lock_init(&fs->vqs[VQ_HIPRIO].lock);
/* Initialize the requests virtqueues */ /* Initialize the requests virtqueues */
for (i = VQ_REQUEST; i < fs->nvqs; i++) { for (i = VQ_REQUEST; i < fs->nvqs; i++) {
spin_lock_init(&fs->vqs[i].lock); char vq_name[VQ_NAME_LEN];
INIT_WORK(&fs->vqs[i].done_work, virtio_fs_requests_done_work);
INIT_DELAYED_WORK(&fs->vqs[i].dispatch_work, snprintf(vq_name, VQ_NAME_LEN, "requests.%u", i - VQ_REQUEST);
virtio_fs_request_dispatch_work); virtio_fs_init_vq(&fs->vqs[i], vq_name, VQ_REQUEST);
INIT_LIST_HEAD(&fs->vqs[i].queued_reqs);
INIT_LIST_HEAD(&fs->vqs[i].end_reqs);
init_completion(&fs->vqs[i].in_flight_zero);
snprintf(fs->vqs[i].name, sizeof(fs->vqs[i].name),
"requests.%u", i - VQ_REQUEST);
callbacks[i] = virtio_fs_vq_done; callbacks[i] = virtio_fs_vq_done;
names[i] = fs->vqs[i].name; names[i] = fs->vqs[i].name;
} }
......
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