-
Notifications
You must be signed in to change notification settings - Fork 48
/
print.c
2087 lines (1770 loc) · 53 KB
/
print.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2005 Christophe Varoqui
*/
#include <stdio.h>
#include <string.h>
#include <libdevmapper.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <libudev.h>
#include "checkers.h"
#include "vector.h"
#include "structs.h"
#include "structs_vec.h"
#include "dmparser.h"
#include "config.h"
#include "configure.h"
#include "pgpolicies.h"
#include "print.h"
#include "defaults.h"
#include "parser.h"
#include "blacklist.h"
#include "switchgroup.h"
#include "devmapper.h"
#include "uevent.h"
#include "debug.h"
#include "discovery.h"
#include "util.h"
#include "foreign.h"
#include "strbuf.h"
#include "sysfs.h"
#define PRINT_PATH_LONG "%w %i %d %D %p %t %T %s %o"
#define PRINT_PATH_INDENT "%i %d %D %t %T %o"
#define PRINT_MAP_PROPS "size=%S features='%f' hwhandler='%h' wp=%r"
#define PRINT_PG_INDENT "policy='%s' prio=%p status=%t"
#define PRINT_JSON_MULTIPLIER 5
#define PRINT_JSON_MAJOR_VERSION 0
#define PRINT_JSON_MINOR_VERSION 1
#define PRINT_JSON_START_VERSION " \"major_version\": %d,\n" \
" \"minor_version\": %d,\n"
#define PRINT_JSON_START_ELEM "{\n"
#define PRINT_JSON_START_MAP " \"map\":"
#define PRINT_JSON_START_MAPS "\"maps\": ["
#define PRINT_JSON_START_PATHS "\"paths\": ["
#define PRINT_JSON_START_GROUPS "\"path_groups\": ["
#define PRINT_JSON_END_ELEM "},"
#define PRINT_JSON_END_LAST_ELEM "}"
#define PRINT_JSON_END_LAST "}\n"
#define PRINT_JSON_END_ARRAY "]\n"
#define PRINT_JSON_INDENT_N 3
#define PRINT_JSON_MAP "{\n" \
" \"name\" : \"%n\",\n" \
" \"uuid\" : \"%w\",\n" \
" \"sysfs\" : \"%d\",\n" \
" \"failback\" : \"%F\",\n" \
" \"queueing\" : \"%Q\",\n" \
" \"paths\" : %N,\n" \
" \"write_prot\" : \"%r\",\n" \
" \"dm_st\" : \"%t\",\n" \
" \"features\" : \"%f\",\n" \
" \"hwhandler\" : \"%h\",\n" \
" \"action\" : \"%A\",\n" \
" \"path_faults\" : %0,\n" \
" \"vend\" : \"%v\",\n" \
" \"prod\" : \"%p\",\n" \
" \"rev\" : \"%e\",\n" \
" \"switch_grp\" : %1,\n" \
" \"map_loads\" : %2,\n" \
" \"total_q_time\" : %3,\n" \
" \"q_timeouts\" : %4,"
#define PRINT_JSON_GROUP "{\n" \
" \"selector\" : \"%s\",\n" \
" \"pri\" : %p,\n" \
" \"dm_st\" : \"%t\",\n" \
" \"marginal_st\" : \"%M\","
#define PRINT_JSON_GROUP_NUM " \"group\" : %d,\n"
#define PRINT_JSON_PATH "{\n" \
" \"dev\" : \"%d\",\n"\
" \"dev_t\" : \"%D\",\n" \
" \"dm_st\" : \"%t\",\n" \
" \"dev_st\" : \"%o\",\n" \
" \"chk_st\" : \"%T\",\n" \
" \"checker\" : \"%c\",\n" \
" \"pri\" : %p,\n" \
" \"host_wwnn\" : \"%N\",\n" \
" \"target_wwnn\" : \"%n\",\n" \
" \"host_wwpn\" : \"%R\",\n" \
" \"target_wwpn\" : \"%r\",\n" \
" \"host_adapter\" : \"%a\",\n" \
" \"lun_hex\" : \"%L\",\n" \
" \"marginal_st\" : \"%M\""
#define PROGRESS_LEN 10
struct path_data {
char wildcard;
char * header;
int (*snprint)(struct strbuf *, const struct path * pp);
};
struct multipath_data {
char wildcard;
char * header;
int (*snprint)(struct strbuf *, const struct multipath * mpp);
};
struct pathgroup_data {
char wildcard;
char * header;
int (*snprint)(struct strbuf *, const struct pathgroup * pgp);
};
#define MAX(x,y) (((x) > (y)) ? (x) : (y))
#define MIN(x,y) (((x) > (y)) ? (y) : (x))
/*
* information printing helpers
*/
static int
snprint_str(struct strbuf *buff, const char *str)
{
return append_strbuf_str(buff, str);
}
static int
snprint_int (struct strbuf *buff, int val)
{
return print_strbuf(buff, "%i", val);
}
static int
snprint_uint (struct strbuf *buff, unsigned int val)
{
return print_strbuf(buff, "%u", val);
}
static int
snprint_size (struct strbuf *buff, unsigned long long size)
{
float s = (float)(size >> 1); /* start with KB */
char units[] = {'K','M','G','T','P'};
char *u = units;
while (s >= 1024 && *u != 'P') {
s = s / 1024;
u++;
}
return print_strbuf(buff, "%.*f%c", s < 10, s, *u);
}
/*
* multipath info printing functions
*/
static int
snprint_name (struct strbuf *buff, const struct multipath * mpp)
{
if (mpp->alias)
return append_strbuf_str(buff, mpp->alias);
else
return append_strbuf_str(buff, mpp->wwid);
}
static int
snprint_sysfs (struct strbuf *buff, const struct multipath * mpp)
{
if (has_dm_info(mpp))
return print_strbuf(buff, "dm-%i", mpp->dmi.minor);
else
return append_strbuf_str(buff, "undef");
}
static int
snprint_ro (struct strbuf *buff, const struct multipath * mpp)
{
if (!has_dm_info(mpp))
return append_strbuf_str(buff, "undef");
if (mpp->dmi.read_only)
return append_strbuf_str(buff, "ro");
else
return append_strbuf_str(buff, "rw");
}
static int
snprint_progress (struct strbuf *buff, int cur, int total)
{
size_t initial_len = get_strbuf_len(buff);
int rc;
if (total > 0) {
int i = PROGRESS_LEN * cur / total;
int j = PROGRESS_LEN - i;
if ((rc = fill_strbuf(buff, 'X', i)) < 0 ||
(rc = fill_strbuf(buff, '.', j) < 0)) {
truncate_strbuf(buff, initial_len);
return rc;
}
}
if ((rc = print_strbuf(buff, " %i/%i", cur, total)) < 0)
return rc;
return get_strbuf_len(buff) - initial_len;
}
static int
snprint_failback (struct strbuf *buff, const struct multipath * mpp)
{
if (mpp->pgfailback == -FAILBACK_IMMEDIATE)
return append_strbuf_str(buff, "immediate");
if (mpp->pgfailback == -FAILBACK_FOLLOWOVER)
return append_strbuf_str(buff, "followover");
if (mpp->pgfailback == -FAILBACK_MANUAL)
return append_strbuf_str(buff, "manual");
if (mpp->pgfailback == FAILBACK_UNDEF)
return append_strbuf_str(buff, "undef");
if (!mpp->failback_tick)
return print_strbuf(buff, "deferred:%i", mpp->pgfailback);
else
return snprint_progress(buff, mpp->failback_tick,
mpp->pgfailback);
}
static int
snprint_queueing (struct strbuf *buff, const struct multipath * mpp)
{
if (mpp->no_path_retry == NO_PATH_RETRY_FAIL)
return append_strbuf_str(buff, "off");
else if (mpp->no_path_retry == NO_PATH_RETRY_QUEUE)
return append_strbuf_str(buff, "on");
else if (mpp->no_path_retry == NO_PATH_RETRY_UNDEF)
return append_strbuf_str(buff, "-");
else if (mpp->no_path_retry > 0) {
if (mpp->retry_tick > 0)
return print_strbuf(buff, "%i sec", mpp->retry_tick);
else if (mpp->retry_tick == 0 && count_active_paths(mpp) > 0)
return print_strbuf(buff, "%i chk",
mpp->no_path_retry);
else
return append_strbuf_str(buff, "off");
}
return 0;
}
static int
snprint_nb_paths (struct strbuf *buff, const struct multipath * mpp)
{
return snprint_int(buff, count_active_paths(mpp));
}
static int
snprint_dm_map_state (struct strbuf *buff, const struct multipath * mpp)
{
if (!has_dm_info(mpp))
return append_strbuf_str(buff, "undef");
else if (mpp->dmi.suspended)
return append_strbuf_str(buff, "suspend");
else
return append_strbuf_str(buff, "active");
}
static int
snprint_multipath_size (struct strbuf *buff, const struct multipath * mpp)
{
return snprint_size(buff, mpp->size);
}
static int
snprint_features (struct strbuf *buff, const struct multipath * mpp)
{
return snprint_str(buff, mpp->features);
}
static int
snprint_hwhandler (struct strbuf *buff, const struct multipath * mpp)
{
return snprint_str(buff, mpp->hwhandler);
}
static int
snprint_path_faults (struct strbuf *buff, const struct multipath * mpp)
{
return snprint_uint(buff, mpp->stat_path_failures);
}
static int
snprint_switch_grp (struct strbuf *buff, const struct multipath * mpp)
{
return snprint_uint(buff, mpp->stat_switchgroup);
}
static int
snprint_map_loads (struct strbuf *buff, const struct multipath * mpp)
{
return snprint_uint(buff, mpp->stat_map_loads);
}
static int
snprint_total_q_time (struct strbuf *buff, const struct multipath * mpp)
{
return snprint_uint(buff, mpp->stat_total_queueing_time);
}
static int
snprint_q_timeouts (struct strbuf *buff, const struct multipath * mpp)
{
return snprint_uint(buff, mpp->stat_queueing_timeouts);
}
static int
snprint_map_failures (struct strbuf *buff, const struct multipath * mpp)
{
return snprint_uint(buff, mpp->stat_map_failures);
}
static int
snprint_multipath_uuid (struct strbuf *buff, const struct multipath * mpp)
{
return snprint_str(buff, mpp->wwid);
}
static int
snprint_multipath_vp (struct strbuf *buff, const struct multipath * mpp)
{
struct pathgroup * pgp;
struct path * pp;
int i, j;
vector_foreach_slot(mpp->pg, pgp, i) {
vector_foreach_slot(pgp->paths, pp, j) {
if (strlen(pp->vendor_id) && strlen(pp->product_id))
return print_strbuf(buff, "%s,%s",
pp->vendor_id, pp->product_id);
}
}
return append_strbuf_str(buff, "##,##");
}
static int
snprint_multipath_vend (struct strbuf *buff, const struct multipath * mpp)
{
struct pathgroup * pgp;
struct path * pp;
int i, j;
vector_foreach_slot(mpp->pg, pgp, i) {
vector_foreach_slot(pgp->paths, pp, j) {
if (strlen(pp->vendor_id))
return append_strbuf_str(buff, pp->vendor_id);
}
}
return append_strbuf_str(buff, "##");
}
static int
snprint_multipath_prod (struct strbuf *buff, const struct multipath * mpp)
{
struct pathgroup * pgp;
struct path * pp;
int i, j;
vector_foreach_slot(mpp->pg, pgp, i) {
vector_foreach_slot(pgp->paths, pp, j) {
if (strlen(pp->product_id))
return append_strbuf_str(buff, pp->product_id);
}
}
return append_strbuf_str(buff, "##");
}
static int
snprint_multipath_rev (struct strbuf *buff, const struct multipath * mpp)
{
struct pathgroup * pgp;
struct path * pp;
int i, j;
vector_foreach_slot(mpp->pg, pgp, i) {
vector_foreach_slot(pgp->paths, pp, j) {
if (strlen(pp->rev))
return append_strbuf_str(buff, pp->rev);
}
}
return append_strbuf_str(buff, "##");
}
static int
snprint_multipath_foreign (struct strbuf *buff,
__attribute__((unused)) const struct multipath * pp)
{
return append_strbuf_str(buff, "--");
}
static int
snprint_action (struct strbuf *buff, const struct multipath * mpp)
{
switch (mpp->action) {
case ACT_REJECT:
return snprint_str(buff, ACT_REJECT_STR);
case ACT_RENAME:
return snprint_str(buff, ACT_RENAME_STR);
case ACT_RELOAD:
return snprint_str(buff, ACT_RELOAD_STR);
case ACT_CREATE:
return snprint_str(buff, ACT_CREATE_STR);
case ACT_SWITCHPG:
return snprint_str(buff, ACT_SWITCHPG_STR);
default:
return 0;
}
}
static int
snprint_multipath_vpd_data(struct strbuf *buff,
const struct multipath * mpp)
{
struct pathgroup * pgp;
struct path * pp;
int i, j;
vector_foreach_slot(mpp->pg, pgp, i)
vector_foreach_slot(pgp->paths, pp, j)
if (pp->vpd_data)
return append_strbuf_str(buff, pp->vpd_data);
return append_strbuf_str(buff, "[undef]");
}
static int
snprint_multipath_max_sectors_kb(struct strbuf *buff, const struct multipath *mpp)
{
char buf[11];
int max_sectors_kb;
struct udev_device *udd __attribute__((cleanup(cleanup_udev_device)))
= get_udev_for_mpp(mpp);
if (!udd ||
sysfs_attr_get_value(udd, "queue/max_sectors_kb", buf, sizeof(buf)) <= 0 ||
sscanf(buf, "%d\n", &max_sectors_kb) != 1)
return print_strbuf(buff, "n/a");
return print_strbuf(buff, "%d", max_sectors_kb);
}
/*
* path info printing functions
*/
static int
snprint_path_uuid (struct strbuf *buff, const struct path * pp)
{
return snprint_str(buff, pp->wwid);
}
static int
snprint_hcil (struct strbuf *buff, const struct path * pp)
{
if (!pp || pp->sg_id.host_no < 0)
return append_strbuf_str(buff, "#:#:#:#");
return print_strbuf(buff, "%i:%i:%i:%" PRIu64,
pp->sg_id.host_no,
pp->sg_id.channel,
pp->sg_id.scsi_id,
pp->sg_id.lun);
}
static int
snprint_path_lunhex (struct strbuf *buff, const struct path * pp)
{
uint64_t lunhex = SCSI_INVALID_LUN, scsilun;
if (!pp || pp->sg_id.host_no < 0)
return print_strbuf(buff, "0x%016" PRIx64, lunhex);
scsilun = pp->sg_id.lun;
/* cf. Linux kernel function int_to_scsilun() */
lunhex = ((scsilun & 0x000000000000ffffULL) << 48) |
((scsilun & 0x00000000ffff0000ULL) << 16) |
((scsilun & 0x0000ffff00000000ULL) >> 16) |
((scsilun & 0xffff000000000000ULL) >> 48);
return print_strbuf(buff, "0x%016" PRIx64, lunhex);
}
static int
snprint_dev (struct strbuf *buff, const struct path * pp)
{
if (!pp || !strlen(pp->dev))
return append_strbuf_str(buff, "-");
else
return snprint_str(buff, pp->dev);
}
static int
snprint_dev_t (struct strbuf *buff, const struct path * pp)
{
if (!pp || !strlen(pp->dev))
return append_strbuf_str(buff, "#:#");
else
return snprint_str(buff, pp->dev_t);
}
static int
snprint_offline (struct strbuf *buff, const struct path * pp)
{
if (!pp || !pp->mpp)
return append_strbuf_str(buff, "unknown");
else if (pp->offline)
return append_strbuf_str(buff, "offline");
else
return append_strbuf_str(buff, "running");
}
static int
snprint_chk_state (struct strbuf *buff, const struct path * pp)
{
if (!pp || !pp->mpp)
return append_strbuf_str(buff, "undef");
switch (pp->state) {
case PATH_UP:
return append_strbuf_str(buff, "ready");
case PATH_DOWN:
return append_strbuf_str(buff, "faulty");
case PATH_SHAKY:
return append_strbuf_str(buff, "shaky");
case PATH_GHOST:
return append_strbuf_str(buff, "ghost");
case PATH_PENDING:
return append_strbuf_str(buff, "i/o pending");
case PATH_TIMEOUT:
return append_strbuf_str(buff, "i/o timeout");
case PATH_DELAYED:
return append_strbuf_str(buff, "delayed");
default:
return append_strbuf_str(buff, "undef");
}
}
static int
snprint_dm_path_state (struct strbuf *buff, const struct path * pp)
{
if (!pp)
return append_strbuf_str(buff, "undef");
switch (pp->dmstate) {
case PSTATE_ACTIVE:
return append_strbuf_str(buff, "active");
case PSTATE_FAILED:
return append_strbuf_str(buff, "failed");
default:
return append_strbuf_str(buff, "undef");
}
}
static int snprint_initialized(struct strbuf *buff, const struct path * pp)
{
static const char *init_state_name[] = {
[INIT_NEW] = "new",
[INIT_FAILED] = "failed",
[INIT_MISSING_UDEV] = "udev-missing",
[INIT_REQUESTED_UDEV] = "udev-requested",
[INIT_OK] = "ok",
[INIT_REMOVED] = "removed",
[INIT_PARTIAL] = "partial",
};
const char *str;
if (pp->initialized < INIT_NEW || pp->initialized >= INIT_LAST__)
str = "undef";
else
str = init_state_name[pp->initialized];
return append_strbuf_str(buff, str);
}
static int
snprint_vpr (struct strbuf *buff, const struct path * pp)
{
return print_strbuf(buff, "%s,%s,%s",
strlen(pp->vendor_id) ? pp->vendor_id : "##",
strlen(pp->product_id) ? pp->product_id : "##",
strlen(pp->rev) ? pp->rev : "##");
}
static int
snprint_next_check (struct strbuf *buff, const struct path * pp)
{
if (!pp || !pp->mpp)
return append_strbuf_str(buff, "orphan");
return snprint_progress(buff, pp->tick, pp->checkint);
}
static int
snprint_pri (struct strbuf *buff, const struct path * pp)
{
return snprint_int(buff, pp ? pp->priority : -1);
}
static int
snprint_pg_selector (struct strbuf *buff, const struct pathgroup * pgp)
{
const char *s = pgp->mpp->selector;
return snprint_str(buff, s ? s : "");
}
static int
snprint_pg_pri (struct strbuf *buff, const struct pathgroup * pgp)
{
return snprint_int(buff, pgp->priority);
}
static int
snprint_pg_state (struct strbuf *buff, const struct pathgroup * pgp)
{
switch (pgp->status) {
case PGSTATE_ENABLED:
return append_strbuf_str(buff, "enabled");
case PGSTATE_DISABLED:
return append_strbuf_str(buff, "disabled");
case PGSTATE_ACTIVE:
return append_strbuf_str(buff, "active");
default:
return append_strbuf_str(buff, "undef");
}
}
static int
snprint_pg_marginal (struct strbuf *buff, const struct pathgroup * pgp)
{
if (pgp->marginal)
return append_strbuf_str(buff, "marginal");
return append_strbuf_str(buff, "normal");
}
static int
snprint_path_size (struct strbuf *buff, const struct path * pp)
{
return snprint_size(buff, pp->size);
}
int
snprint_path_serial (struct strbuf *buff, const struct path * pp)
{
return snprint_str(buff, pp->serial);
}
static int
snprint_path_mpp (struct strbuf *buff, const struct path * pp)
{
if (!pp->mpp)
return append_strbuf_str(buff, "[orphan]");
if (!pp->mpp->alias)
return append_strbuf_str(buff, "[unknown]");
return snprint_str(buff, pp->mpp->alias);
}
static int
snprint_host_attr (struct strbuf *buff, const struct path * pp, char *attr)
{
struct udev_device *host_dev = NULL;
char host_id[32];
const char *value = NULL;
int ret;
if (pp->bus != SYSFS_BUS_SCSI ||
pp->sg_id.proto_id != SCSI_PROTOCOL_FCP)
return append_strbuf_str(buff, "[undef]");
sprintf(host_id, "host%d", pp->sg_id.host_no);
host_dev = udev_device_new_from_subsystem_sysname(udev, "fc_host",
host_id);
if (!host_dev) {
condlog(1, "%s: No fc_host device for '%s'", pp->dev, host_id);
goto out;
}
value = udev_device_get_sysattr_value(host_dev, attr);
if (value)
ret = snprint_str(buff, value);
udev_device_unref(host_dev);
out:
if (!value)
ret = append_strbuf_str(buff, "[unknown]");
return ret;
}
int
snprint_host_wwnn (struct strbuf *buff, const struct path * pp)
{
return snprint_host_attr(buff, pp, "node_name");
}
int
snprint_host_wwpn (struct strbuf *buff, const struct path * pp)
{
return snprint_host_attr(buff, pp, "port_name");
}
int
snprint_tgt_wwpn (struct strbuf *buff, const struct path * pp)
{
struct udev_device *rport_dev = NULL;
char rport_id[42];
const char *value = NULL;
int ret;
if (pp->bus != SYSFS_BUS_SCSI ||
pp->sg_id.proto_id != SCSI_PROTOCOL_FCP)
return append_strbuf_str(buff, "[undef]");
sprintf(rport_id, "rport-%d:%d-%d",
pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.transport_id);
rport_dev = udev_device_new_from_subsystem_sysname(udev,
"fc_remote_ports", rport_id);
if (!rport_dev) {
condlog(1, "%s: No fc_remote_port device for '%s'", pp->dev,
rport_id);
goto out;
}
value = udev_device_get_sysattr_value(rport_dev, "port_name");
if (value)
ret = snprint_str(buff, value);
udev_device_unref(rport_dev);
out:
if (!value)
ret = append_strbuf_str(buff, "[unknown]");
return ret;
}
int
snprint_tgt_wwnn (struct strbuf *buff, const struct path * pp)
{
if (pp->tgt_node_name[0] == '\0')
return append_strbuf_str(buff, "[undef]");
return snprint_str(buff, pp->tgt_node_name);
}
static int
snprint_host_adapter (struct strbuf *buff, const struct path * pp)
{
char adapter[SLOT_NAME_SIZE];
if (sysfs_get_host_adapter_name(pp, adapter))
return append_strbuf_str(buff, "[undef]");
return snprint_str(buff, adapter);
}
static int
snprint_path_checker (struct strbuf *buff, const struct path * pp)
{
const char * n = checker_name(&pp->checker);
if (n)
return snprint_str(buff, n);
else
return snprint_str(buff, "(null)");
}
static int
snprint_path_foreign (struct strbuf *buff,
__attribute__((unused)) const struct path * pp)
{
return append_strbuf_str(buff, "--");
}
static int
snprint_path_failures(struct strbuf *buff, const struct path * pp)
{
return snprint_int(buff, pp->failcount);
}
/* if you add a protocol string bigger than "scsi:unspec" you must
* also change PROTOCOL_BUF_SIZE */
int
snprint_path_protocol(struct strbuf *buff, const struct path * pp)
{
const char *pn = protocol_name[bus_protocol_id(pp)];
assert(pn != NULL);
return append_strbuf_str(buff, pn);
}
static int
snprint_path_marginal(struct strbuf *buff, const struct path * pp)
{
if (pp->marginal)
return append_strbuf_str(buff, "marginal");
return append_strbuf_str(buff, "normal");
}
static int
snprint_path_vpd_data(struct strbuf *buff, const struct path * pp)
{
if (pp->vpd_data)
return append_strbuf_str(buff, pp->vpd_data);
return append_strbuf_str(buff, "[undef]");
}
static int
snprint_alua_tpg(struct strbuf *buff, const struct path * pp)
{
if (pp->tpg_id < 0)
return append_strbuf_str(buff, "[undef]");
return print_strbuf(buff, "0x%04x", pp->tpg_id);
}
static int
snprint_path_max_sectors_kb(struct strbuf *buff, const struct path *pp)
{
char buf[11];
int max_sectors_kb;
if (!pp->udev ||
sysfs_attr_get_value(pp->udev, "queue/max_sectors_kb",
buf, sizeof(buf)) <= 0 ||
sscanf(buf, "%d\n", &max_sectors_kb) != 1)
return print_strbuf(buff, "n/a");
return print_strbuf(buff, "%d", max_sectors_kb);
}
static const struct multipath_data mpd[] = {
{'n', "name", snprint_name},
{'w', "uuid", snprint_multipath_uuid},
{'d', "sysfs", snprint_sysfs},
{'F', "failback", snprint_failback},
{'Q', "queueing", snprint_queueing},
{'N', "paths", snprint_nb_paths},
{'r', "write_prot", snprint_ro},
{'t', "dm-st", snprint_dm_map_state},
{'S', "size", snprint_multipath_size},
{'f', "features", snprint_features},
{'x', "failures", snprint_map_failures},
{'h', "hwhandler", snprint_hwhandler},
{'A', "action", snprint_action},
{'0', "path_faults", snprint_path_faults},
{'1', "switch_grp", snprint_switch_grp},
{'2', "map_loads", snprint_map_loads},
{'3', "total_q_time", snprint_total_q_time},
{'4', "q_timeouts", snprint_q_timeouts},
{'s', "vend/prod", snprint_multipath_vp},
{'v', "vend", snprint_multipath_vend},
{'p', "prod", snprint_multipath_prod},
{'e', "rev", snprint_multipath_rev},
{'G', "foreign", snprint_multipath_foreign},
{'g', "vpd page data", snprint_multipath_vpd_data},
{'k', "max_sectors_kb",snprint_multipath_max_sectors_kb},
};
static const struct path_data pd[] = {
{'w', "uuid", snprint_path_uuid},
{'i', "hcil", snprint_hcil},
{'d', "dev", snprint_dev},
{'D', "dev_t", snprint_dev_t},
{'t', "dm_st", snprint_dm_path_state},
{'o', "dev_st", snprint_offline},
{'T', "chk_st", snprint_chk_state},
{'s', "vend/prod/rev", snprint_vpr},
{'c', "checker", snprint_path_checker},
{'C', "next_check", snprint_next_check},
{'p', "pri", snprint_pri},
{'S', "size", snprint_path_size},
{'z', "serial", snprint_path_serial},
{'M', "marginal_st", snprint_path_marginal},
{'m', "multipath", snprint_path_mpp},
{'N', "host WWNN", snprint_host_wwnn},
{'n', "target WWNN", snprint_tgt_wwnn},
{'R', "host WWPN", snprint_host_wwpn},
{'r', "target WWPN", snprint_tgt_wwpn},
{'a', "host adapter", snprint_host_adapter},
{'G', "foreign", snprint_path_foreign},
{'g', "vpd page data", snprint_path_vpd_data},
{'0', "failures", snprint_path_failures},
{'P', "protocol", snprint_path_protocol},
{'I', "init_st", snprint_initialized},
{'L', "LUN hex", snprint_path_lunhex},
{'A', "TPG", snprint_alua_tpg},
{'k', "max_sectors_kb",snprint_path_max_sectors_kb},
};
static const struct pathgroup_data pgd[] = {
{'s', "selector", snprint_pg_selector},
{'p', "pri", snprint_pg_pri},
{'t', "dm_st", snprint_pg_state},
{'M', "marginal_st", snprint_pg_marginal},
};
int snprint_wildcards(struct strbuf *buff)
{
int initial_len = get_strbuf_len(buff);
unsigned int i;
int rc;
if ((rc = append_strbuf_str(buff, "multipath format wildcards:\n")) < 0)
return rc;
for (i = 0; i < ARRAY_SIZE(mpd); i++)
if ((rc = print_strbuf(buff, "%%%c %s\n",
mpd[i].wildcard, mpd[i].header)) < 0)
return rc;
if ((rc = append_strbuf_str(buff, "\npath format wildcards:\n")) < 0)
return rc;
for (i = 0; i < ARRAY_SIZE(pd); i++)
if ((rc = print_strbuf(buff, "%%%c %s\n",
pd[i].wildcard, pd[i].header)) < 0)
return rc;
return get_strbuf_len(buff) - initial_len;
}
fieldwidth_t *alloc_path_layout(void) {
return calloc(ARRAY_SIZE(pd), sizeof(fieldwidth_t));
}
void get_path_layout(vector pathvec, int header, fieldwidth_t *width)
{
vector gpvec = vector_convert(NULL, pathvec, struct path,
dm_path_to_gen);
get_path_layout__(gpvec,
header ? LAYOUT_RESET_HEADER : LAYOUT_RESET_ZERO,
width);
vector_free(gpvec);
}
static void
reset_width(fieldwidth_t *width, enum layout_reset reset, const char *header)
{
switch (reset) {
case LAYOUT_RESET_HEADER:
*width = strlen(header);
break;
case LAYOUT_RESET_ZERO:
*width = 0;
break;
default:
/* don't reset */
break;
}
}
void get_path_layout__ (const struct vector_s *gpvec, enum layout_reset reset,
fieldwidth_t *width)
{
unsigned int i, j;
const struct gen_path *gp;
if (width == NULL)
return;
for (j = 0; j < ARRAY_SIZE(pd); j++) {
STRBUF_ON_STACK(buff);
reset_width(&width[j], reset, pd[j].header);
if (gpvec == NULL)
continue;
vector_foreach_slot (gpvec, gp, i) {
gp->ops->snprint(gp, &buff, pd[j].wildcard);
width[j] = MAX(width[j],
MIN(get_strbuf_len(&buff), MAX_FIELD_WIDTH));
truncate_strbuf(&buff, 0);
}
}
}
fieldwidth_t *alloc_multipath_layout(void) {
return calloc(ARRAY_SIZE(mpd), sizeof(fieldwidth_t));
}
void get_multipath_layout (vector mpvec, int header, fieldwidth_t *width) {
vector gmvec = vector_convert(NULL, mpvec, struct multipath,
dm_multipath_to_gen);
get_multipath_layout__(gmvec,
header ? LAYOUT_RESET_HEADER : LAYOUT_RESET_ZERO,
width);
vector_free(gmvec);
}
void
get_multipath_layout__ (const struct vector_s *gmvec, enum layout_reset reset,
fieldwidth_t *width)
{
unsigned int i, j;
const struct gen_multipath * gm;
if (width == NULL)
return;
for (j = 0; j < ARRAY_SIZE(mpd); j++) {
STRBUF_ON_STACK(buff);