Skip to content

Commit 353e7c4

Browse files
ikegami-tigaw
authored andcommitted
feat: use nvme_show_err() helper function
It introduced to handle the negative error and the postive status codes. Then reduce the duplicated error and status codes output implementation. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent b8c5e92 commit 353e7c4

1 file changed

Lines changed: 102 additions & 122 deletions

File tree

plugins/feat/feat-nvme.c

Lines changed: 102 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,18 @@ static int feat_get_nsid(struct nvme_transport_handle *hdl, __u32 nsid,
8383

8484
err = nvme_get_features(hdl, nsid, fid, sel, cdw11, uidx, buf, len,
8585
&result);
86+
if (err) {
87+
nvme_show_err(err, "Get %s", feat);
88+
return err;
89+
}
8690

8791
nvme_show_init();
8892

89-
if (!err) {
90-
nvme_feature_show(fid, sel, result);
91-
if (NVME_CHECK(sel, GET_FEATURES_SEL, SUPPORTED))
92-
nvme_show_select_result(fid, result);
93-
else
94-
nvme_feature_show_fields(fid, result, buf);
95-
} else if (err > 0) {
96-
nvme_show_status(err);
97-
} else {
98-
nvme_show_error("Get %s: %s", feat, nvme_strerror(errno));
99-
}
93+
nvme_feature_show(fid, sel, result);
94+
if (NVME_CHECK(sel, GET_FEATURES_SEL, SUPPORTED))
95+
nvme_show_select_result(fid, result);
96+
else
97+
nvme_feature_show_fields(fid, result, buf);
10098

10199
nvme_show_finish();
102100

@@ -119,17 +117,16 @@ static int power_mgmt_set(struct nvme_transport_handle *hdl, const __u8 fid,
119117
err = nvme_set_features(hdl, 0, fid, sv, cdw11, 0, 0, 0, 0, NULL, 0,
120118
&result);
121119

120+
if (err) {
121+
nvme_show_err(err, "Set %s", power_mgmt_feat);
122+
return err;
123+
}
124+
122125
nvme_show_init();
123126

124-
if (err > 0) {
125-
nvme_show_status(err);
126-
} else if (err < 0) {
127-
nvme_show_perror("Set %s", power_mgmt_feat);
128-
} else {
129-
nvme_show_result("Set %s: 0x%04x (%s)", power_mgmt_feat, cdw11,
130-
sv ? "Save" : "Not save");
131-
nvme_feature_show_fields(fid, cdw11, NULL);
132-
}
127+
nvme_show_result("Set %s: 0x%04x (%s)", power_mgmt_feat, cdw11,
128+
sv ? "Save" : "Not save");
129+
nvme_feature_show_fields(fid, cdw11, NULL);
133130

134131
nvme_show_finish();
135132

@@ -211,18 +208,16 @@ static int perfc_set(struct nvme_transport_handle *hdl, __u8 fid, __u32 cdw11,
211208

212209
err = nvme_set_features(hdl, 0, fid, sv, cdw11, 0, 0, 0, 0, &data,
213210
sizeof(data), &result);
211+
if (err) {
212+
nvme_show_err(err, "Set %s", perfc_feat);
213+
return err;
214+
}
214215

215216
nvme_show_init();
216217

217-
if (err > 0) {
218-
nvme_show_status(err);
219-
} else if (err < 0) {
220-
nvme_show_perror("Set %s", perfc_feat);
221-
} else {
222-
nvme_show_result("Set %s: 0x%04x (%s)", perfc_feat, cdw11,
223-
sv ? "Save" : "Not save");
224-
nvme_feature_show_fields(fid, cdw11, NULL);
225-
}
218+
nvme_show_result("Set %s: 0x%04x (%s)", perfc_feat, cdw11,
219+
sv ? "Save" : "Not save");
220+
nvme_feature_show_fields(fid, cdw11, NULL);
226221

227222
nvme_show_finish();
228223

@@ -283,18 +278,16 @@ static int hctm_set(struct nvme_transport_handle *hdl, const __u8 fid,
283278

284279
err = nvme_set_features(hdl, 0, fid, sv, cdw11, 0, 0, 0, 0, NULL, 0,
285280
&result);
281+
if (err) {
282+
nvme_show_err(err, "Set %s", hctm_feat);
283+
return err;
284+
}
286285

287286
nvme_show_init();
288287

289-
if (err > 0) {
290-
nvme_show_status(err);
291-
} else if (err < 0) {
292-
nvme_show_perror("Set %s", hctm_feat);
293-
} else {
294-
nvme_show_result("Set %s: 0x%04x (%s)", hctm_feat, cdw11,
295-
sv ? "Save" : "Not save");
296-
nvme_feature_show_fields(fid, cdw11, NULL);
297-
}
288+
nvme_show_result("Set %s: 0x%04x (%s)", hctm_feat, cdw11,
289+
sv ? "Save" : "Not save");
290+
nvme_feature_show_fields(fid, cdw11, NULL);
298291

299292
nvme_show_finish();
300293

@@ -347,17 +340,16 @@ static int timestamp_set(struct nvme_transport_handle *hdl, const __u8 fid,
347340

348341
err = nvme_set_features(hdl, 0, fid, sv, 0, 0, 0, 0, 0, &ts, sizeof(ts),
349342
&result);
343+
if (err) {
344+
nvme_show_err(err, "Set %s", timestamp_feat);
345+
return err;
346+
}
350347

351348
nvme_show_init();
352349

353-
if (err > 0) {
354-
nvme_show_status(err);
355-
} else if (err < 0) {
356-
nvme_show_perror("Set %s", timestamp_feat);
357-
} else {
358-
nvme_show_result("Set %s: (%s)", timestamp_feat, sv ? "Save" : "Not save");
359-
nvme_feature_show_fields(fid, 0, (unsigned char *)&ts);
360-
}
350+
nvme_show_result("Set %s: (%s)", timestamp_feat,
351+
sv ? "Save" : "Not save");
352+
nvme_feature_show_fields(fid, 0, (unsigned char *)&ts);
361353

362354
nvme_show_finish();
363355

@@ -426,20 +418,19 @@ static int temp_thresh_set(struct nvme_transport_handle *hdl, const __u8 fid,
426418
nvme_init_set_features_temp_thresh(&cmd, sv, cfg->tmpth, cfg->tmpsel,
427419
cfg->thsel, cfg->tmpthh);
428420
err = nvme_submit_admin_passthru(hdl, &cmd);
421+
if (err) {
422+
nvme_show_err(err, "Set %s", temp_thresh_feat);
423+
return err;
424+
}
429425

430426
nvme_show_init();
431427

432-
if (err > 0) {
433-
nvme_show_status(err);
434-
} else if (err < 0) {
435-
nvme_show_perror("Set %s", temp_thresh_feat);
436-
} else {
437-
nvme_show_result("Set %s: (%s)", temp_thresh_feat, sv ? "Save" : "Not save");
438-
nvme_feature_show_fields(fid, NVME_SET(cfg->tmpth, FEAT_TT_TMPTH) |
439-
NVME_SET(cfg->tmpsel, FEAT_TT_TMPSEL) |
440-
NVME_SET(cfg->thsel, FEAT_TT_THSEL) |
441-
NVME_SET(cfg->tmpthh, FEAT_TT_TMPTHH), NULL);
442-
}
428+
nvme_show_result("Set %s: (%s)", temp_thresh_feat,
429+
sv ? "Save" : "Not save");
430+
nvme_feature_show_fields(fid, NVME_SET(cfg->tmpth, FEAT_TT_TMPTH) |
431+
NVME_SET(cfg->tmpsel, FEAT_TT_TMPSEL) |
432+
NVME_SET(cfg->thsel, FEAT_TT_THSEL) |
433+
NVME_SET(cfg->tmpthh, FEAT_TT_TMPTHH), NULL);
443434

444435
nvme_show_finish();
445436

@@ -513,20 +504,21 @@ static int arbitration_set(struct nvme_transport_handle *hdl, const __u8 fid,
513504
nvme_init_set_features_arbitration(&cmd, sv, cfg->ab, cfg->lpw,
514505
cfg->mpw, cfg->hpw);
515506
err = nvme_submit_admin_passthru(hdl, &cmd);
507+
if (err) {
508+
nvme_show_err(err, "Set %s", arbitration_feat);
509+
return err;
510+
}
516511

517512
nvme_show_init();
518513

519-
if (err > 0) {
520-
nvme_show_status(err);
521-
} else if (err < 0) {
522-
nvme_show_perror("Set %s", arbitration_feat);
523-
} else {
524-
nvme_show_result("Set %s: (%s)", arbitration_feat, sv ? "Save" : "Not save");
525-
nvme_feature_show_fields(fid, NVME_SET(cfg->ab, FEAT_ARBITRATION_BURST) |
526-
NVME_SET(cfg->lpw, FEAT_ARBITRATION_LPW) |
527-
NVME_SET(cfg->mpw, FEAT_ARBITRATION_MPW) |
528-
NVME_SET(cfg->hpw, FEAT_ARBITRATION_HPW), NULL);
529-
}
514+
nvme_show_result("Set %s: (%s)", arbitration_feat,
515+
sv ? "Save" : "Not save");
516+
nvme_feature_show_fields(fid,
517+
NVME_SET(cfg->ab, FEAT_ARBITRATION_BURST) |
518+
NVME_SET(cfg->lpw, FEAT_ARBITRATION_LPW) |
519+
NVME_SET(cfg->mpw, FEAT_ARBITRATION_MPW) |
520+
NVME_SET(cfg->hpw, FEAT_ARBITRATION_HPW),
521+
NULL);
530522

531523
nvme_show_finish();
532524

@@ -572,18 +564,16 @@ static int volatile_wc_set(struct nvme_transport_handle *hdl, const __u8 fid,
572564

573565
err = nvme_set_features(hdl, 0, fid, sv, cdw11, 0, 0, 0, 0, NULL, 0,
574566
&result);
567+
if (err) {
568+
nvme_show_err(err, "Set %s", volatile_wc_feat);
569+
return err;
570+
}
575571

576572
nvme_show_init();
577573

578-
if (err > 0) {
579-
nvme_show_status(err);
580-
} else if (err < 0) {
581-
nvme_show_perror("Set %s", volatile_wc_feat);
582-
} else {
583-
nvme_show_result("Set %s: 0x%04x (%s)", volatile_wc_feat, cdw11,
584-
sv ? "Save" : "Not save");
585-
nvme_feature_show_fields(fid, cdw11, NULL);
586-
}
574+
nvme_show_result("Set %s: 0x%04x (%s)", volatile_wc_feat, cdw11,
575+
sv ? "Save" : "Not save");
576+
nvme_feature_show_fields(fid, cdw11, NULL);
587577

588578
nvme_show_finish();
589579

@@ -631,18 +621,16 @@ static int power_limit_set(struct nvme_transport_handle *hdl, const __u8 fid,
631621

632622
err = nvme_set_features(hdl, 0, fid, sv, 0, 0, cdw13, uidx, 0, NULL, 0,
633623
&result);
624+
if (err) {
625+
nvme_show_err(err, "Set %s", power_limit_feat);
626+
return err;
627+
}
634628

635629
nvme_show_init();
636630

637-
if (err > 0) {
638-
nvme_show_status(err);
639-
} else if (err < 0) {
640-
nvme_show_perror("Set %s", power_limit_feat);
641-
} else {
642-
nvme_show_result("Set %s: 0x%04x (%s)", power_limit_feat, cdw13,
643-
sv ? "Save" : "Not save");
644-
nvme_feature_show_fields(fid, cdw13, NULL);
645-
}
631+
nvme_show_result("Set %s: 0x%04x (%s)", power_limit_feat, cdw13,
632+
sv ? "Save" : "Not save");
633+
nvme_feature_show_fields(fid, cdw13, NULL);
646634

647635
nvme_show_finish();
648636

@@ -703,18 +691,16 @@ static int power_thresh_set(struct nvme_transport_handle *hdl, const __u8 fid,
703691

704692
err = nvme_set_features(hdl, 0, fid, sv, cdw11, 0, 0, uidx, 0, NULL, 0,
705693
&result);
694+
if (err) {
695+
nvme_show_err(err, "Set %s", power_thresh_feat);
696+
return err;
697+
}
706698

707699
nvme_show_init();
708700

709-
if (err > 0) {
710-
nvme_show_status(err);
711-
} else if (err < 0) {
712-
nvme_show_perror("Set %s", power_thresh_feat);
713-
} else {
714-
nvme_show_result("Set %s: 0x%04x (%s)", power_thresh_feat,
715-
cdw11, sv ? "Save" : "Not save");
716-
nvme_feature_show_fields(fid, cdw11, NULL);
717-
}
701+
nvme_show_result("Set %s: 0x%04x (%s)", power_thresh_feat,
702+
cdw11, sv ? "Save" : "Not save");
703+
nvme_feature_show_fields(fid, cdw11, NULL);
718704

719705
nvme_show_finish();
720706

@@ -783,18 +769,16 @@ static int power_meas_set(struct nvme_transport_handle *hdl, const __u8 fid,
783769

784770
err = nvme_set_features(hdl, 0, fid, sv, cdw11, 0, 0, uidx, 0, NULL, 0,
785771
&result);
772+
if (err) {
773+
nvme_show_err(err, "Set %s", power_meas_feat);
774+
return err;
775+
}
786776

787777
nvme_show_init();
788778

789-
if (err > 0) {
790-
nvme_show_status(err);
791-
} else if (err < 0) {
792-
nvme_show_perror("Set %s", power_meas_feat);
793-
} else {
794-
nvme_show_result("Set %s: 0x%04x (%s)", power_meas_feat, cdw11,
795-
sv ? "Save" : "Not save");
796-
nvme_feature_show_fields(fid, cdw11, NULL);
797-
}
779+
nvme_show_result("Set %s: 0x%04x (%s)", power_meas_feat, cdw11,
780+
sv ? "Save" : "Not save");
781+
nvme_feature_show_fields(fid, cdw11, NULL);
798782

799783
nvme_show_finish();
800784

@@ -857,18 +841,16 @@ static int err_recovery_set(struct nvme_transport_handle *hdl, const __u8 fid,
857841

858842
err = nvme_set_features(hdl, nsid, fid, sv, cdw11, 0, 0, 0, 0, NULL, 0,
859843
&result);
844+
if (err) {
845+
nvme_show_err(err, "Set %s", err_recovery_feat);
846+
return err;
847+
}
860848

861849
nvme_show_init();
862850

863-
if (err > 0) {
864-
nvme_show_status(err);
865-
} else if (err < 0) {
866-
nvme_show_perror("Set %s", err_recovery_feat);
867-
} else {
868-
nvme_show_result("Set %s: 0x%04x (%s)", err_recovery_feat,
869-
cdw11, sv ? "Save" : "Not save");
870-
nvme_feature_show_fields(fid, cdw11, NULL);
871-
}
851+
nvme_show_result("Set %s: 0x%04x (%s)", err_recovery_feat, cdw11,
852+
sv ? "Save" : "Not save");
853+
nvme_feature_show_fields(fid, cdw11, NULL);
872854

873855
nvme_show_finish();
874856

@@ -944,18 +926,16 @@ static int num_queues_set(struct nvme_transport_handle *hdl, const __u8 fid,
944926

945927
err = nvme_set_features(hdl, 0, fid, sv, cdw11, 0, 0, 0, 0, NULL, 0,
946928
&result);
929+
if (err) {
930+
nvme_show_err(err, "Set %s", num_queues_feat);
931+
return err;
932+
}
947933

948934
nvme_show_init();
949935

950-
if (err > 0) {
951-
nvme_show_status(err);
952-
} else if (err < 0) {
953-
nvme_show_perror("Set %s", num_queues_feat);
954-
} else {
955-
nvme_show_result("Set %s: 0x%04x (%s)", num_queues_feat,
956-
cdw11, sv ? "Save" : "Not save");
957-
nvme_feature_show_fields(fid, cdw11, NULL);
958-
}
936+
nvme_show_result("Set %s: 0x%04x (%s)", num_queues_feat, cdw11,
937+
sv ? "Save" : "Not save");
938+
nvme_feature_show_fields(fid, cdw11, NULL);
959939

960940
nvme_show_finish();
961941

0 commit comments

Comments
 (0)