diff options
Diffstat (limited to 'drivers/block/virtio_blk.c')
-rw-r--r-- | drivers/block/virtio_blk.c | 41 |
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 | */ | ||
382 | static 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 | |||
378 | static int __devinit virtblk_probe(struct virtio_device *vdev) | 406 | static 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); |