diff options
Diffstat (limited to 'drivers/block')
-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 c4a60badf252..303779cb1fa2 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c | |||
@@ -374,6 +374,34 @@ static int init_vq(struct virtio_blk *vblk) | |||
374 | return err; | 374 | return err; |
375 | } | 375 | } |
376 | 376 | ||
377 | /* | ||
378 | * Legacy naming scheme used for virtio devices. We are stuck with it for | ||
379 | * virtio blk but don't ever use it for any new driver. | ||
380 | */ | ||
381 | static int virtblk_name_format(char *prefix, int index, char *buf, int buflen) | ||
382 | { | ||
383 | const int base = 'z' - 'a' + 1; | ||
384 | char *begin = buf + strlen(prefix); | ||
385 | char *end = buf + buflen; | ||
386 | char *p; | ||
387 | int unit; | ||
388 | |||
389 | p = end - 1; | ||
390 | *p = '\0'; | ||
391 | unit = base; | ||
392 | do { | ||
393 | if (p == begin) | ||
394 | return -EINVAL; | ||
395 | *--p = 'a' + (index % unit); | ||
396 | index = (index / unit) - 1; | ||
397 | } while (index >= 0); | ||
398 | |||
399 | memmove(begin, p, end - p); | ||
400 | memcpy(buf, prefix, strlen(prefix)); | ||
401 | |||
402 | return 0; | ||
403 | } | ||
404 | |||
377 | static int __devinit virtblk_probe(struct virtio_device *vdev) | 405 | static int __devinit virtblk_probe(struct virtio_device *vdev) |
378 | { | 406 | { |
379 | struct virtio_blk *vblk; | 407 | struct virtio_blk *vblk; |
@@ -442,18 +470,7 @@ static int __devinit virtblk_probe(struct virtio_device *vdev) | |||
442 | 470 | ||
443 | q->queuedata = vblk; | 471 | q->queuedata = vblk; |
444 | 472 | ||
445 | if (index < 26) { | 473 | virtblk_name_format("vd", index, vblk->disk->disk_name, DISK_NAME_LEN); |
446 | sprintf(vblk->disk->disk_name, "vd%c", 'a' + index % 26); | ||
447 | } else if (index < (26 + 1) * 26) { | ||
448 | sprintf(vblk->disk->disk_name, "vd%c%c", | ||
449 | 'a' + index / 26 - 1, 'a' + index % 26); | ||
450 | } else { | ||
451 | const unsigned int m1 = (index / 26 - 1) / 26 - 1; | ||
452 | const unsigned int m2 = (index / 26 - 1) % 26; | ||
453 | const unsigned int m3 = index % 26; | ||
454 | sprintf(vblk->disk->disk_name, "vd%c%c%c", | ||
455 | 'a' + m1, 'a' + m2, 'a' + m3); | ||
456 | } | ||
457 | 474 | ||
458 | vblk->disk->major = major; | 475 | vblk->disk->major = major; |
459 | vblk->disk->first_minor = index_to_minor(index); | 476 | vblk->disk->first_minor = index_to_minor(index); |