aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block/virtio_blk.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-04-16 21:34:12 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-04-16 21:34:12 -0400
commitcdd5983063cadf40db63117f4a299881b3bb71c1 (patch)
tree3acf64aaeeceb1e2e3b50749356c3cd05348e1a9 /drivers/block/virtio_blk.c
parenta6cb9ee7cabe68002c3f2ab07224ea27d2617cf1 (diff)
parent3ccc9372ed0fab33d20f10be3c1efd5776ff5913 (diff)
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio fixes from Michael S. Tsirkin: "Here are some virtio fixes for 3.4: a test build fix, a patch by Ren fixing naming for systems with a massive number of virtio blk devices, and balloon fixes for powerpc by David Gibson. There was some discussion about Ren's patch for virtio disc naming: some people wanted to move the legacy name mangling function to the block core. But there's no concensus on that yet, and we can always deduplicate later. Added comments in the hope that this will stop people from copying this legacy naming scheme into future drivers." * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: virtio_balloon: fix handling of PAGE_SIZE != 4k virtio_balloon: Fix endian bug virtio_blk: helper function to format disk names tools/virtio: fix up vhost/test module build
Diffstat (limited to 'drivers/block/virtio_blk.c')
-rw-r--r--drivers/block/virtio_blk.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 0e4ef3de9d5d..0d39f2f4294a 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -375,6 +375,34 @@ static int init_vq(struct virtio_blk *vblk)
375 return err; 375 return err;
376} 376}
377 377
378/*
379 * Legacy naming scheme used for virtio devices. We are stuck with it for
380 * virtio blk but don't ever use it for any new driver.
381 */
382static int virtblk_name_format(char *prefix, int index, char *buf, int buflen)
383{
384 const int base = 'z' - 'a' + 1;
385 char *begin = buf + strlen(prefix);
386 char *end = buf + buflen;
387 char *p;
388 int unit;
389
390 p = end - 1;
391 *p = '\0';
392 unit = base;
393 do {
394 if (p == begin)
395 return -EINVAL;
396 *--p = 'a' + (index % unit);
397 index = (index / unit) - 1;
398 } while (index >= 0);
399
400 memmove(begin, p, end - p);
401 memcpy(buf, prefix, strlen(prefix));
402
403 return 0;
404}
405
378static int __devinit virtblk_probe(struct virtio_device *vdev) 406static int __devinit virtblk_probe(struct virtio_device *vdev)
379{ 407{
380 struct virtio_blk *vblk; 408 struct virtio_blk *vblk;
@@ -443,18 +471,7 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
443 471
444 q->queuedata = vblk; 472 q->queuedata = vblk;
445 473
446 if (index < 26) { 474 virtblk_name_format("vd", index, vblk->disk->disk_name, DISK_NAME_LEN);
447 sprintf(vblk->disk->disk_name, "vd%c", 'a' + index % 26);
448 } else if (index < (26 + 1) * 26) {
449 sprintf(vblk->disk->disk_name, "vd%c%c",
450 'a' + index / 26 - 1, 'a' + index % 26);
451 } else {
452 const unsigned int m1 = (index / 26 - 1) / 26 - 1;
453 const unsigned int m2 = (index / 26 - 1) % 26;
454 const unsigned int m3 = index % 26;
455 sprintf(vblk->disk->disk_name, "vd%c%c%c",
456 'a' + m1, 'a' + m2, 'a' + m3);
457 }
458 475
459 vblk->disk->major = major; 476 vblk->disk->major = major;
460 vblk->disk->first_minor = index_to_minor(index); 477 vblk->disk->first_minor = index_to_minor(index);