Commit 37c1209d413242d9560e343c040777049a8dd869

Authored by Aneesh Kumar K.V
Committed by Eric Van Hensbergen
1 parent f75580c4af

net/9p: Remove MAX_9P_CHAN limit

Use a list to track the channel instead of statically
allocated array

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>

Showing 2 changed files with 27 additions and 46 deletions Side-by-side Diff

include/linux/virtio_9p.h
... ... @@ -5,8 +5,5 @@
5 5 #include <linux/virtio_ids.h>
6 6 #include <linux/virtio_config.h>
7 7  
8   -/* Maximum number of virtio channels per partition (1 for now) */
9   -#define MAX_9P_CHAN 10
10   -
11 8 #endif /* _LINUX_VIRTIO_9P_H */
net/9p/trans_virtio.c
... ... @@ -49,8 +49,6 @@
49 49  
50 50 /* a single mutex to manage channel initialization and attachment */
51 51 static DEFINE_MUTEX(virtio_9p_lock);
52   -/* global which tracks highest initialized channel */
53   -static int chan_index;
54 52  
55 53 /**
56 54 * struct virtio_chan - per-instance transport information
... ... @@ -68,8 +66,7 @@
68 66 *
69 67 */
70 68  
71   -static struct virtio_chan {
72   - bool initialized;
  69 +struct virtio_chan {
73 70 bool inuse;
74 71  
75 72 spinlock_t lock;
76 73  
... ... @@ -80,8 +77,12 @@
80 77  
81 78 /* Scatterlist: can be too big for stack. */
82 79 struct scatterlist sg[VIRTQUEUE_NUM];
83   -} channels[MAX_9P_CHAN];
84 80  
  81 + struct list_head chan_list;
  82 +};
  83 +
  84 +static struct list_head virtio_chan_list;
  85 +
85 86 /* How many bytes left in this page. */
86 87 static unsigned int rest_of_page(void *data)
87 88 {
... ... @@ -217,9 +218,7 @@
217 218 * p9_virtio_probe - probe for existence of 9P virtio channels
218 219 * @vdev: virtio device to probe
219 220 *
220   - * This probes for existing virtio channels. At present only
221   - * a single channel is in use, so in the future more work may need
222   - * to be done here.
  221 + * This probes for existing virtio channels.
223 222 *
224 223 */
225 224  
226 225  
... ... @@ -227,16 +226,10 @@
227 226 {
228 227 int err;
229 228 struct virtio_chan *chan;
230   - int index;
231 229  
232   - mutex_lock(&virtio_9p_lock);
233   - index = chan_index++;
234   - chan = &channels[index];
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();
  230 + chan = kmalloc(sizeof(struct virtio_chan), GFP_KERNEL);
  231 + if (!chan) {
  232 + printk(KERN_ERR "9p: Failed to allocate virtio 9P channel\n");
240 233 err = -ENOMEM;
241 234 goto fail;
242 235 }
243 236  
244 237  
... ... @@ -255,15 +248,15 @@
255 248 sg_init_table(chan->sg, VIRTQUEUE_NUM);
256 249  
257 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 254 return 0;
260 255  
261 256 out_free_vq:
262 257 vdev->config->del_vqs(vdev);
  258 + kfree(chan);
263 259 fail:
264   - mutex_lock(&virtio_9p_lock);
265   - chan_index--;
266   - mutex_unlock(&virtio_9p_lock);
267 260 return err;
268 261 }
269 262  
270 263  
271 264  
272 265  
273 266  
274 267  
... ... @@ -280,35 +273,27 @@
280 273 * We use a simple reference count mechanism to ensure that only a single
281 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 278 static int
292 279 p9_virtio_create(struct p9_client *client, const char *devname, char *args)
293 280 {
294   - struct virtio_chan *chan = channels;
295   - int index = 0;
  281 + struct virtio_chan *chan;
  282 + int found = 0;
296 283  
297 284 mutex_lock(&virtio_9p_lock);
298   - while (index < MAX_9P_CHAN) {
299   - if (chan->initialized &&
300   - !strcmp(devname, dev_name(&chan->vdev->dev))) {
  285 + list_for_each_entry(chan, &virtio_chan_list, chan_list) {
  286 + if (!strcmp(devname, dev_name(&chan->vdev->dev))) {
301 287 if (!chan->inuse) {
302 288 chan->inuse = true;
  289 + found = 1;
303 290 break;
304 291 }
305 292 }
306   - index++;
307   - chan = &channels[index];
308 293 }
309 294 mutex_unlock(&virtio_9p_lock);
310 295  
311   - if (index >= MAX_9P_CHAN) {
  296 + if (!found) {
312 297 printk(KERN_ERR "9p: no channels available\n");
313 298 return -ENODEV;
314 299 }
315 300  
... ... @@ -331,11 +316,13 @@
331 316 struct virtio_chan *chan = vdev->priv;
332 317  
333 318 BUG_ON(chan->inuse);
  319 + vdev->config->del_vqs(vdev);
334 320  
335   - if (chan->initialized) {
336   - vdev->config->del_vqs(vdev);
337   - chan->initialized = false;
338   - }
  321 + mutex_lock(&virtio_9p_lock);
  322 + list_del(&chan->chan_list);
  323 + mutex_unlock(&virtio_9p_lock);
  324 + kfree(chan);
  325 +
339 326 }
340 327  
341 328 static struct virtio_device_id id_table[] = {
... ... @@ -366,10 +353,7 @@
366 353 /* The standard init function */
367 354 static int __init p9_virtio_init(void)
368 355 {
369   - int count;
370   -
371   - for (count = 0; count < MAX_9P_CHAN; count++)
372   - channels[count].initialized = false;
  356 + INIT_LIST_HEAD(&virtio_chan_list);
373 357  
374 358 v9fs_register_trans(&p9_virtio_trans);
375 359 return register_virtio_driver(&p9_virtio_drv);