diff options
author | Ren Mingxin <renmx@cn.fujitsu.com> | 2012-04-10 03:28:05 -0400 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2012-04-12 03:37:05 -0400 |
commit | c0aa3e0916d7e531e69b02e426f7162dfb1c6c0f (patch) | |
tree | 08968a635c4d43fb16c071cbcdbe25b302b85924 /drivers/block | |
parent | 5e7045b010bdb56abbfe5714e8debf03a024c016 (diff) |
virtio_blk: helper function to format disk names
The current virtio block's naming algorithm just supports 18278
(26^3 + 26^2 + 26) disks. If there are more virtio blocks,
there will be disks with the same name.
Based on commit 3e1a7ff8a0a7b948f2684930166954f9e8e776fe, add
a function "virtblk_name_format()" for virtio block to support mass
of disks naming.
Notes:
- Our naming scheme is ugly. We are stuck with it
for virtio but don't use it for any new driver:
new drivers should name their devices PREFIX%d
where the sequence number can be allocated by ida
- sd_format_disk_name has exactly the same logic.
Moving it to a central place was deferred over worries
that this will make people keep using the legacy naming
in new drivers.
We kept code idential in case someone wants to deduplicate later.
Signed-off-by: Ren Mingxin <renmx@cn.fujitsu.com>
Acked-by: Asias He <asias@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
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); |