Commit 97ee9b02 authored by Aneesh Kumar K.V's avatar Aneesh Kumar K.V Committed by Eric Van Hensbergen

net/9p: Use the tag name in the config space for identifying mount point

This patch use the tag name in the config space to identify the
mount device. The the virtio device name depend on the enumeration
order of the device and may not remain the same across multiple boots
So we use the tag name which is set via qemu option to uniquely identify
the mount device
Signed-off-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: default avatarEric Van Hensbergen <ericvh@gmail.com>
parent daf9fe2e
...@@ -5,4 +5,16 @@ ...@@ -5,4 +5,16 @@
#include <linux/virtio_ids.h> #include <linux/virtio_ids.h>
#include <linux/virtio_config.h> #include <linux/virtio_config.h>
/* The feature bitmap for virtio 9P */
/* The mount point is specified in a config variable */
#define VIRTIO_9P_MOUNT_TAG 0
struct virtio_9p_config {
/* length of the tag name */
__u16 tag_len;
/* non-NULL terminated tag name */
__u8 tag[0];
} __attribute__((packed));
#endif /* _LINUX_VIRTIO_9P_H */ #endif /* _LINUX_VIRTIO_9P_H */
...@@ -78,6 +78,12 @@ struct virtio_chan { ...@@ -78,6 +78,12 @@ struct virtio_chan {
/* Scatterlist: can be too big for stack. */ /* Scatterlist: can be too big for stack. */
struct scatterlist sg[VIRTQUEUE_NUM]; struct scatterlist sg[VIRTQUEUE_NUM];
int tag_len;
/*
* tag name to identify a mount Non-null terminated
*/
char *tag;
struct list_head chan_list; struct list_head chan_list;
}; };
...@@ -224,6 +230,8 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req) ...@@ -224,6 +230,8 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req)
static int p9_virtio_probe(struct virtio_device *vdev) static int p9_virtio_probe(struct virtio_device *vdev)
{ {
__u16 tag_len;
char *tag;
int err; int err;
struct virtio_chan *chan; struct virtio_chan *chan;
...@@ -248,6 +256,23 @@ static int p9_virtio_probe(struct virtio_device *vdev) ...@@ -248,6 +256,23 @@ static int p9_virtio_probe(struct virtio_device *vdev)
sg_init_table(chan->sg, VIRTQUEUE_NUM); sg_init_table(chan->sg, VIRTQUEUE_NUM);
chan->inuse = false; chan->inuse = false;
if (virtio_has_feature(vdev, VIRTIO_9P_MOUNT_TAG)) {
vdev->config->get(vdev,
offsetof(struct virtio_9p_config, tag_len),
&tag_len, sizeof(tag_len));
} else {
err = -EINVAL;
goto out_free_vq;
}
tag = kmalloc(tag_len, GFP_KERNEL);
if (!tag) {
err = -ENOMEM;
goto out_free_vq;
}
vdev->config->get(vdev, offsetof(struct virtio_9p_config, tag),
tag, tag_len);
chan->tag = tag;
chan->tag_len = tag_len;
mutex_lock(&virtio_9p_lock); mutex_lock(&virtio_9p_lock);
list_add_tail(&chan->chan_list, &virtio_chan_list); list_add_tail(&chan->chan_list, &virtio_chan_list);
mutex_unlock(&virtio_9p_lock); mutex_unlock(&virtio_9p_lock);
...@@ -284,7 +309,7 @@ p9_virtio_create(struct p9_client *client, const char *devname, char *args) ...@@ -284,7 +309,7 @@ p9_virtio_create(struct p9_client *client, const char *devname, char *args)
mutex_lock(&virtio_9p_lock); mutex_lock(&virtio_9p_lock);
list_for_each_entry(chan, &virtio_chan_list, chan_list) { list_for_each_entry(chan, &virtio_chan_list, chan_list) {
if (!strcmp(devname, dev_name(&chan->vdev->dev))) { if (!strncmp(devname, chan->tag, chan->tag_len)) {
if (!chan->inuse) { if (!chan->inuse) {
chan->inuse = true; chan->inuse = true;
found = 1; found = 1;
...@@ -323,6 +348,7 @@ static void p9_virtio_remove(struct virtio_device *vdev) ...@@ -323,6 +348,7 @@ static void p9_virtio_remove(struct virtio_device *vdev)
mutex_lock(&virtio_9p_lock); mutex_lock(&virtio_9p_lock);
list_del(&chan->chan_list); list_del(&chan->chan_list);
mutex_unlock(&virtio_9p_lock); mutex_unlock(&virtio_9p_lock);
kfree(chan->tag);
kfree(chan); kfree(chan);
} }
...@@ -332,13 +358,19 @@ static struct virtio_device_id id_table[] = { ...@@ -332,13 +358,19 @@ static struct virtio_device_id id_table[] = {
{ 0 }, { 0 },
}; };
static unsigned int features[] = {
VIRTIO_9P_MOUNT_TAG,
};
/* The standard "struct lguest_driver": */ /* The standard "struct lguest_driver": */
static struct virtio_driver p9_virtio_drv = { static struct virtio_driver p9_virtio_drv = {
.driver.name = KBUILD_MODNAME, .feature_table = features,
.driver.owner = THIS_MODULE, .feature_table_size = ARRAY_SIZE(features),
.id_table = id_table, .driver.name = KBUILD_MODNAME,
.probe = p9_virtio_probe, .driver.owner = THIS_MODULE,
.remove = p9_virtio_remove, .id_table = id_table,
.probe = p9_virtio_probe,
.remove = p9_virtio_remove,
}; };
static struct p9_trans_module p9_virtio_trans = { static struct p9_trans_module p9_virtio_trans = {
......
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