Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 299285
b: refs/heads/master
c: c0aa3e0
h: refs/heads/master
i:
  299283: 5a602d5
v: v3
  • Loading branch information
Ren Mingxin authored and Michael S. Tsirkin committed Apr 12, 2012
1 parent 66bb661 commit d10f42f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 5e7045b010bdb56abbfe5714e8debf03a024c016
refs/heads/master: c0aa3e0916d7e531e69b02e426f7162dfb1c6c0f
41 changes: 29 additions & 12 deletions trunk/drivers/block/virtio_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,34 @@ static int init_vq(struct virtio_blk *vblk)
return err;
}

/*
* Legacy naming scheme used for virtio devices. We are stuck with it for
* virtio blk but don't ever use it for any new driver.
*/
static int virtblk_name_format(char *prefix, int index, char *buf, int buflen)
{
const int base = 'z' - 'a' + 1;
char *begin = buf + strlen(prefix);
char *end = buf + buflen;
char *p;
int unit;

p = end - 1;
*p = '\0';
unit = base;
do {
if (p == begin)
return -EINVAL;
*--p = 'a' + (index % unit);
index = (index / unit) - 1;
} while (index >= 0);

memmove(begin, p, end - p);
memcpy(buf, prefix, strlen(prefix));

return 0;
}

static int __devinit virtblk_probe(struct virtio_device *vdev)
{
struct virtio_blk *vblk;
Expand Down Expand Up @@ -442,18 +470,7 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)

q->queuedata = vblk;

if (index < 26) {
sprintf(vblk->disk->disk_name, "vd%c", 'a' + index % 26);
} else if (index < (26 + 1) * 26) {
sprintf(vblk->disk->disk_name, "vd%c%c",
'a' + index / 26 - 1, 'a' + index % 26);
} else {
const unsigned int m1 = (index / 26 - 1) / 26 - 1;
const unsigned int m2 = (index / 26 - 1) % 26;
const unsigned int m3 = index % 26;
sprintf(vblk->disk->disk_name, "vd%c%c%c",
'a' + m1, 'a' + m2, 'a' + m3);
}
virtblk_name_format("vd", index, vblk->disk->disk_name, DISK_NAME_LEN);

vblk->disk->major = major;
vblk->disk->first_minor = index_to_minor(index);
Expand Down

0 comments on commit d10f42f

Please sign in to comment.