Skip to content

Commit 4319875

Browse files
hoeppnerjaxboe
authored andcommitted
s390/dasd: Move device name formatting into separate function
The device name formatting can be generalized and made more readable compared to the current state. SCSI already provides a generalized way to format many devices in the same naming scheme as DASD does, which was introduced with commit 3e1a7ff ("block: allow disk to have extended device number"). Use this much cleaner code from drivers/scsi/sd.c to handle the legacy naming scheme in DASD as a replacement for the current implementation. For easier error handling for the new function, move the gendisk free portion of dasd_gendisk_free() out into a new function dasd_gd_free(). Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com> Reviewed-by: Stefan Haberland <sth@linux.ibm.com> Signed-off-by: Stefan Haberland <sth@linux.ibm.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 764def9 commit 4319875

1 file changed

Lines changed: 54 additions & 26 deletions

File tree

drivers/s390/block/dasd_genhd.c

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,45 @@
2222

2323
static unsigned int queue_depth = 32;
2424
static unsigned int nr_hw_queues = 4;
25+
static void dasd_gd_free(struct gendisk *gdp);
2526

2627
module_param(queue_depth, uint, 0444);
2728
MODULE_PARM_DESC(queue_depth, "Default queue depth for new DASD devices");
2829

2930
module_param(nr_hw_queues, uint, 0444);
3031
MODULE_PARM_DESC(nr_hw_queues, "Default number of hardware queues for new DASD devices");
3132

33+
/*
34+
* Set device name.
35+
* dasda - dasdz : 26 devices
36+
* dasdaa - dasdzz : 676 devices, added up = 702
37+
* dasdaaa - dasdzzz : 17576 devices, added up = 18278
38+
* dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
39+
*/
40+
static int dasd_name_format(char *prefix, int index, char *buf, int buflen)
41+
{
42+
const int base = 'z' - 'a' + 1;
43+
char *begin = buf + strlen(prefix);
44+
char *end = buf + buflen;
45+
char *p;
46+
int unit;
47+
48+
p = end - 1;
49+
*p = '\0';
50+
unit = base;
51+
do {
52+
if (p == begin)
53+
return -EINVAL;
54+
*--p = 'a' + (index % unit);
55+
index = (index / unit) - 1;
56+
} while (index >= 0);
57+
58+
memmove(begin, p, end - p);
59+
memcpy(buf, prefix, strlen(prefix));
60+
61+
return 0;
62+
}
63+
3264
/*
3365
* Allocate and register gendisk structure for device.
3466
*/
@@ -45,11 +77,13 @@ int dasd_gendisk_alloc(struct dasd_block *block)
4577
};
4678
struct gendisk *gdp;
4779
struct dasd_device *base;
48-
int len, rc;
80+
unsigned int devindex;
81+
int rc;
4982

5083
/* Make sure the minor for this device exists. */
5184
base = block->base;
52-
if (base->devindex >= DASD_PER_MAJOR)
85+
devindex = base->devindex;
86+
if (devindex >= DASD_PER_MAJOR)
5387
return -EBUSY;
5488

5589
block->tag_set.ops = &dasd_mq_ops;
@@ -69,31 +103,17 @@ int dasd_gendisk_alloc(struct dasd_block *block)
69103

70104
/* Initialize gendisk structure. */
71105
gdp->major = DASD_MAJOR;
72-
gdp->first_minor = base->devindex << DASD_PARTN_BITS;
106+
gdp->first_minor = devindex << DASD_PARTN_BITS;
73107
gdp->minors = 1 << DASD_PARTN_BITS;
74108
gdp->fops = &dasd_device_operations;
75109

76-
/*
77-
* Set device name.
78-
* dasda - dasdz : 26 devices
79-
* dasdaa - dasdzz : 676 devices, added up = 702
80-
* dasdaaa - dasdzzz : 17576 devices, added up = 18278
81-
* dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
82-
*/
83-
len = sprintf(gdp->disk_name, "dasd");
84-
if (base->devindex > 25) {
85-
if (base->devindex > 701) {
86-
if (base->devindex > 18277)
87-
len += sprintf(gdp->disk_name + len, "%c",
88-
'a'+(((base->devindex-18278)
89-
/17576)%26));
90-
len += sprintf(gdp->disk_name + len, "%c",
91-
'a'+(((base->devindex-702)/676)%26));
92-
}
93-
len += sprintf(gdp->disk_name + len, "%c",
94-
'a'+(((base->devindex-26)/26)%26));
110+
rc = dasd_name_format("dasd", devindex, gdp->disk_name, sizeof(gdp->disk_name));
111+
if (rc) {
112+
DBF_DEV_EVENT(DBF_ERR, block->base,
113+
"setting disk name failed, rc %d", rc);
114+
dasd_gd_free(gdp);
115+
return rc;
95116
}
96-
len += sprintf(gdp->disk_name + len, "%c", 'a'+(base->devindex%26));
97117

98118
if (base->features & DASD_FEATURE_READONLY ||
99119
test_bit(DASD_FLAG_DEVICE_RO, &base->flags))
@@ -111,15 +131,23 @@ int dasd_gendisk_alloc(struct dasd_block *block)
111131
return 0;
112132
}
113133

134+
/*
135+
* Free gendisk structure
136+
*/
137+
static void dasd_gd_free(struct gendisk *gd)
138+
{
139+
del_gendisk(gd);
140+
gd->private_data = NULL;
141+
put_disk(gd);
142+
}
143+
114144
/*
115145
* Unregister and free gendisk structure for device.
116146
*/
117147
void dasd_gendisk_free(struct dasd_block *block)
118148
{
119149
if (block->gdp) {
120-
del_gendisk(block->gdp);
121-
block->gdp->private_data = NULL;
122-
put_disk(block->gdp);
150+
dasd_gd_free(block->gdp);
123151
block->gdp = NULL;
124152
blk_mq_free_tag_set(&block->tag_set);
125153
}

0 commit comments

Comments
 (0)