diff options
Diffstat (limited to 'net/9p/trans_virtio.c')
| -rw-r--r-- | net/9p/trans_virtio.c | 80 |
1 files changed, 34 insertions, 46 deletions
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c index cb50f4ae5eef..0aaed4819379 100644 --- a/net/9p/trans_virtio.c +++ b/net/9p/trans_virtio.c | |||
| @@ -49,8 +49,6 @@ | |||
| 49 | 49 | ||
| 50 | /* a single mutex to manage channel initialization and attachment */ | 50 | /* a single mutex to manage channel initialization and attachment */ |
| 51 | static DEFINE_MUTEX(virtio_9p_lock); | 51 | static DEFINE_MUTEX(virtio_9p_lock); |
| 52 | /* global which tracks highest initialized channel */ | ||
| 53 | static int chan_index; | ||
| 54 | 52 | ||
| 55 | /** | 53 | /** |
| 56 | * struct virtio_chan - per-instance transport information | 54 | * struct virtio_chan - per-instance transport information |
| @@ -68,8 +66,7 @@ static int chan_index; | |||
| 68 | * | 66 | * |
| 69 | */ | 67 | */ |
| 70 | 68 | ||
| 71 | static struct virtio_chan { | 69 | struct virtio_chan { |
| 72 | bool initialized; | ||
| 73 | bool inuse; | 70 | bool inuse; |
| 74 | 71 | ||
| 75 | spinlock_t lock; | 72 | spinlock_t lock; |
| @@ -80,7 +77,11 @@ static struct virtio_chan { | |||
| 80 | 77 | ||
| 81 | /* Scatterlist: can be too big for stack. */ | 78 | /* Scatterlist: can be too big for stack. */ |
| 82 | struct scatterlist sg[VIRTQUEUE_NUM]; | 79 | struct scatterlist sg[VIRTQUEUE_NUM]; |
| 83 | } channels[MAX_9P_CHAN]; | 80 | |
| 81 | struct list_head chan_list; | ||
| 82 | }; | ||
| 83 | |||
| 84 | static struct list_head virtio_chan_list; | ||
| 84 | 85 | ||
| 85 | /* How many bytes left in this page. */ | 86 | /* How many bytes left in this page. */ |
| 86 | static unsigned int rest_of_page(void *data) | 87 | static unsigned int rest_of_page(void *data) |
| @@ -217,9 +218,7 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req) | |||
| 217 | * p9_virtio_probe - probe for existence of 9P virtio channels | 218 | * p9_virtio_probe - probe for existence of 9P virtio channels |
| 218 | * @vdev: virtio device to probe | 219 | * @vdev: virtio device to probe |
| 219 | * | 220 | * |
| 220 | * This probes for existing virtio channels. At present only | 221 | * This probes for existing virtio channels. |
| 221 | * a single channel is in use, so in the future more work may need | ||
| 222 | * to be done here. | ||
| 223 | * | 222 | * |
| 224 | */ | 223 | */ |
| 225 | 224 | ||
| @@ -227,16 +226,10 @@ static int p9_virtio_probe(struct virtio_device *vdev) | |||
| 227 | { | 226 | { |
| 228 | int err; | 227 | int err; |
| 229 | struct virtio_chan *chan; | 228 | struct virtio_chan *chan; |
| 230 | int index; | ||
| 231 | 229 | ||
| 232 | mutex_lock(&virtio_9p_lock); | 230 | chan = kmalloc(sizeof(struct virtio_chan), GFP_KERNEL); |
| 233 | index = chan_index++; | 231 | if (!chan) { |
| 234 | chan = &channels[index]; | 232 | printk(KERN_ERR "9p: Failed to allocate virtio 9P channel\n"); |
| 235 | mutex_unlock(&virtio_9p_lock); | ||
| 236 | |||
| 237 | if (chan_index > MAX_9P_CHAN) { | ||
| 238 | printk(KERN_ERR "9p: virtio: Maximum channels exceeded\n"); | ||
| 239 | BUG(); | ||
| 240 | err = -ENOMEM; | 233 | err = -ENOMEM; |
| 241 | goto fail; | 234 | goto fail; |
| 242 | } | 235 | } |
| @@ -255,15 +248,15 @@ static int p9_virtio_probe(struct virtio_device *vdev) | |||
| 255 | sg_init_table(chan->sg, VIRTQUEUE_NUM); | 248 | sg_init_table(chan->sg, VIRTQUEUE_NUM); |
| 256 | 249 | ||
| 257 | chan->inuse = false; | 250 | chan->inuse = false; |
| 258 | chan->initialized = true; | 251 | mutex_lock(&virtio_9p_lock); |
| 252 | list_add_tail(&chan->chan_list, &virtio_chan_list); | ||
| 253 | mutex_unlock(&virtio_9p_lock); | ||
| 259 | return 0; | 254 | return 0; |
| 260 | 255 | ||
| 261 | out_free_vq: | 256 | out_free_vq: |
| 262 | vdev->config->del_vqs(vdev); | 257 | vdev->config->del_vqs(vdev); |
| 258 | kfree(chan); | ||
| 263 | fail: | 259 | fail: |
| 264 | mutex_lock(&virtio_9p_lock); | ||
| 265 | chan_index--; | ||
| 266 | mutex_unlock(&virtio_9p_lock); | ||
| 267 | return err; | 260 | return err; |
| 268 | } | 261 | } |
| 269 | 262 | ||
| @@ -280,35 +273,31 @@ fail: | |||
| 280 | * We use a simple reference count mechanism to ensure that only a single | 273 | * We use a simple reference count mechanism to ensure that only a single |
| 281 | * mount has a channel open at a time. | 274 | * mount has a channel open at a time. |
| 282 | * | 275 | * |
| 283 | * Bugs: doesn't allow identification of a specific channel | ||
| 284 | * to allocate, channels are allocated sequentially. This was | ||
| 285 | * a pragmatic decision to get things rolling, but ideally some | ||
| 286 | * way of identifying the channel to attach to would be nice | ||
| 287 | * if we are going to support multiple channels. | ||
| 288 | * | ||
| 289 | */ | 276 | */ |
| 290 | 277 | ||
| 291 | static int | 278 | static int |
| 292 | p9_virtio_create(struct p9_client *client, const char *devname, char *args) | 279 | p9_virtio_create(struct p9_client *client, const char *devname, char *args) |
| 293 | { | 280 | { |
| 294 | struct virtio_chan *chan = channels; | 281 | struct virtio_chan *chan; |
| 295 | int index = 0; | 282 | int ret = -ENOENT; |
| 283 | int found = 0; | ||
| 296 | 284 | ||
| 297 | mutex_lock(&virtio_9p_lock); | 285 | mutex_lock(&virtio_9p_lock); |
| 298 | while (index < MAX_9P_CHAN) { | 286 | list_for_each_entry(chan, &virtio_chan_list, chan_list) { |
| 299 | if (chan->initialized && !chan->inuse) { | 287 | if (!strcmp(devname, dev_name(&chan->vdev->dev))) { |
| 300 | chan->inuse = true; | 288 | if (!chan->inuse) { |
| 301 | break; | 289 | chan->inuse = true; |
| 302 | } else { | 290 | found = 1; |
| 303 | index++; | 291 | break; |
| 304 | chan = &channels[index]; | 292 | } |
| 293 | ret = -EBUSY; | ||
| 305 | } | 294 | } |
| 306 | } | 295 | } |
| 307 | mutex_unlock(&virtio_9p_lock); | 296 | mutex_unlock(&virtio_9p_lock); |
| 308 | 297 | ||
| 309 | if (index >= MAX_9P_CHAN) { | 298 | if (!found) { |
| 310 | printk(KERN_ERR "9p: no channels available\n"); | 299 | printk(KERN_ERR "9p: no channels available\n"); |
| 311 | return -ENODEV; | 300 | return ret; |
| 312 | } | 301 | } |
| 313 | 302 | ||
| 314 | client->trans = (void *)chan; | 303 | client->trans = (void *)chan; |
| @@ -329,11 +318,13 @@ static void p9_virtio_remove(struct virtio_device *vdev) | |||
| 329 | struct virtio_chan *chan = vdev->priv; | 318 | struct virtio_chan *chan = vdev->priv; |
| 330 | 319 | ||
| 331 | BUG_ON(chan->inuse); | 320 | BUG_ON(chan->inuse); |
| 321 | vdev->config->del_vqs(vdev); | ||
| 322 | |||
| 323 | mutex_lock(&virtio_9p_lock); | ||
| 324 | list_del(&chan->chan_list); | ||
| 325 | mutex_unlock(&virtio_9p_lock); | ||
| 326 | kfree(chan); | ||
| 332 | 327 | ||
| 333 | if (chan->initialized) { | ||
| 334 | vdev->config->del_vqs(vdev); | ||
| 335 | chan->initialized = false; | ||
| 336 | } | ||
| 337 | } | 328 | } |
| 338 | 329 | ||
| 339 | static struct virtio_device_id id_table[] = { | 330 | static struct virtio_device_id id_table[] = { |
| @@ -364,10 +355,7 @@ static struct p9_trans_module p9_virtio_trans = { | |||
| 364 | /* The standard init function */ | 355 | /* The standard init function */ |
| 365 | static int __init p9_virtio_init(void) | 356 | static int __init p9_virtio_init(void) |
| 366 | { | 357 | { |
| 367 | int count; | 358 | INIT_LIST_HEAD(&virtio_chan_list); |
| 368 | |||
| 369 | for (count = 0; count < MAX_9P_CHAN; count++) | ||
| 370 | channels[count].initialized = false; | ||
| 371 | 359 | ||
| 372 | v9fs_register_trans(&p9_virtio_trans); | 360 | v9fs_register_trans(&p9_virtio_trans); |
| 373 | return register_virtio_driver(&p9_virtio_drv); | 361 | return register_virtio_driver(&p9_virtio_drv); |
