Skip to content

Commit b8c9a3c

Browse files
martin-gpyigaw
authored andcommitted
netapp-smdev: remove redundant code
Remove redundant code in regular and JSON functions, which is already invoked in a separate function. Signed-off-by: Martin George <marting@netapp.com>
1 parent d70d4b1 commit b8c9a3c

File tree

1 file changed

+8
-36
lines changed

1 file changed

+8
-36
lines changed

plugins/netapp/netapp-nvme.c

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ static void netapp_smdevices_print_regular(struct smdevice_info *devices,
300300
char array_label[ARRAY_LABEL_LEN / 2 + 1];
301301
char volume_label[VOLUME_LABEL_LEN / 2 + 1];
302302
char nguid_str[33];
303-
__u8 lba_index;
303+
unsigned long long lba;
304+
char size[128];
304305

305306
char *formatstr = NULL;
306307
char basestr[] =
@@ -325,15 +326,7 @@ static void netapp_smdevices_print_regular(struct smdevice_info *devices,
325326
for (i = 0; i < count; i++) {
326327
if (devname && !strcmp(devname, basename(devices[i].dev))) {
327328
/* found the device, fetch info for that alone */
328-
nvme_id_ns_flbas_to_lbaf_inuse(devices[i].ns.flbas,
329-
&lba_index);
330-
unsigned long long lba = 1ULL <<
331-
devices[i].ns.lbaf[lba_index].ds;
332-
double nsze = le64_to_cpu(devices[i].ns.nsze) * lba;
333-
const char *s_suffix = suffix_si_get(&nsze);
334-
char size[128];
335-
336-
sprintf(size, "%.2f%sB", nsze, s_suffix);
329+
netapp_get_ns_size(size, &lba, &devices[i].ns);
337330
netapp_convert_string(array_label,
338331
(char *)&devices[i].ctrl.vs[20],
339332
ARRAY_LABEL_LEN / 2);
@@ -353,14 +346,7 @@ static void netapp_smdevices_print_regular(struct smdevice_info *devices,
353346

354347
for (i = 0; i < count; i++) {
355348
/* fetch info for all devices */
356-
nvme_id_ns_flbas_to_lbaf_inuse(devices[i].ns.flbas, &lba_index);
357-
unsigned long long lba = 1ULL <<
358-
devices[i].ns.lbaf[lba_index].ds;
359-
double nsze = le64_to_cpu(devices[i].ns.nsze) * lba;
360-
const char *s_suffix = suffix_si_get(&nsze);
361-
char size[128];
362-
363-
sprintf(size, "%.2f%sB", nsze, s_suffix);
349+
netapp_get_ns_size(size, &lba, &devices[i].ns);
364350
netapp_convert_string(array_label,
365351
(char *)&devices[i].ctrl.vs[20],
366352
ARRAY_LABEL_LEN / 2);
@@ -384,7 +370,8 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices,
384370
char array_label[ARRAY_LABEL_LEN / 2 + 1];
385371
char volume_label[VOLUME_LABEL_LEN / 2 + 1];
386372
char nguid_str[33];
387-
__u8 lba_index;
373+
unsigned long long lba;
374+
char size[128];
388375

389376
/* prepare for the json output */
390377
root = json_create_object();
@@ -393,15 +380,7 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices,
393380
for (i = 0; i < count; i++) {
394381
if (devname && !strcmp(devname, basename(devices[i].dev))) {
395382
/* found the device, fetch info for that alone */
396-
nvme_id_ns_flbas_to_lbaf_inuse(devices[i].ns.flbas,
397-
&lba_index);
398-
unsigned long long lba = 1ULL <<
399-
devices[i].ns.lbaf[lba_index].ds;
400-
double nsze = le64_to_cpu(devices[i].ns.nsze) * lba;
401-
const char *s_suffix = suffix_si_get(&nsze);
402-
char size[128];
403-
404-
sprintf(size, "%.2f%sB", nsze, s_suffix);
383+
netapp_get_ns_size(size, &lba, &devices[i].ns);
405384
netapp_convert_string(array_label,
406385
(char *)&devices[i].ctrl.vs[20],
407386
ARRAY_LABEL_LEN / 2);
@@ -421,14 +400,7 @@ static void netapp_smdevices_print_json(struct smdevice_info *devices,
421400

422401
for (i = 0; i < count; i++) {
423402
/* fetch info for all devices */
424-
nvme_id_ns_flbas_to_lbaf_inuse(devices[i].ns.flbas, &lba_index);
425-
unsigned long long lba = 1ULL <<
426-
devices[i].ns.lbaf[lba_index].ds;
427-
double nsze = le64_to_cpu(devices[i].ns.nsze) * lba;
428-
const char *s_suffix = suffix_si_get(&nsze);
429-
char size[128];
430-
431-
sprintf(size, "%.2f%sB", nsze, s_suffix);
403+
netapp_get_ns_size(size, &lba, &devices[i].ns);
432404
netapp_convert_string(array_label,
433405
(char *)&devices[i].ctrl.vs[20],
434406
ARRAY_LABEL_LEN / 2);

0 commit comments

Comments
 (0)