]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0 |
48c46ee3 | 2 | /* |
da23017d NS |
3 | * Copyright (c) 2004-2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
48c46ee3 NS |
5 | */ |
6 | ||
6b803e5a CH |
7 | #include "command.h" |
8 | #include "input.h" | |
48c46ee3 NS |
9 | #include "init.h" |
10 | #include "io.h" | |
904d9719 | 11 | #include "xfs_errortag.h" |
48c46ee3 NS |
12 | |
13 | static cmdinfo_t inject_cmd; | |
14 | ||
15 | static int | |
16 | error_tag(char *name) | |
17 | { | |
18 | static struct { | |
19 | int tag; | |
20 | char *name; | |
fc60b66d | 21 | } *e, eflags[] = { |
48c46ee3 | 22 | { XFS_ERRTAG_NOERROR, "noerror" }, |
48c46ee3 | 23 | { XFS_ERRTAG_IFLUSH_1, "iflush1" }, |
48c46ee3 | 24 | { XFS_ERRTAG_IFLUSH_2, "iflush2" }, |
48c46ee3 | 25 | { XFS_ERRTAG_IFLUSH_3, "iflush3" }, |
48c46ee3 | 26 | { XFS_ERRTAG_IFLUSH_4, "iflush4" }, |
48c46ee3 | 27 | { XFS_ERRTAG_IFLUSH_5, "iflush5" }, |
48c46ee3 | 28 | { XFS_ERRTAG_IFLUSH_6, "iflush6" }, |
48c46ee3 | 29 | { XFS_ERRTAG_DA_READ_BUF, "dareadbuf" }, |
48c46ee3 | 30 | { XFS_ERRTAG_BTREE_CHECK_LBLOCK, "btree_chk_lblk" }, |
48c46ee3 | 31 | { XFS_ERRTAG_BTREE_CHECK_SBLOCK, "btree_chk_sblk" }, |
48c46ee3 | 32 | { XFS_ERRTAG_ALLOC_READ_AGF, "readagf" }, |
48c46ee3 | 33 | { XFS_ERRTAG_IALLOC_READ_AGI, "readagi" }, |
48c46ee3 | 34 | { XFS_ERRTAG_ITOBP_INOTOBP, "itobp" }, |
48c46ee3 | 35 | { XFS_ERRTAG_IUNLINK, "iunlink" }, |
48c46ee3 | 36 | { XFS_ERRTAG_IUNLINK_REMOVE, "iunlinkrm" }, |
48c46ee3 | 37 | { XFS_ERRTAG_DIR_INO_VALIDATE, "dirinovalid" }, |
48c46ee3 | 38 | { XFS_ERRTAG_BULKSTAT_READ_CHUNK, "bulkstat" }, |
48c46ee3 | 39 | { XFS_ERRTAG_IODONE_IOERR, "logiodone" }, |
48c46ee3 | 40 | { XFS_ERRTAG_STRATREAD_IOERR, "stratread" }, |
48c46ee3 | 41 | { XFS_ERRTAG_STRATCMPL_IOERR, "stratcmpl" }, |
48c46ee3 | 42 | { XFS_ERRTAG_DIOWRITE_IOERR, "diowrite" }, |
48c46ee3 | 43 | { XFS_ERRTAG_BMAPIFORMAT, "bmapifmt" }, |
80afb9a4 | 44 | { XFS_ERRTAG_FREE_EXTENT, "free_extent" }, |
dea764e0 | 45 | { XFS_ERRTAG_RMAP_FINISH_ONE, "rmap_finish_one" }, |
a136ec62 | 46 | { XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE, "refcount_continue_update" }, |
a136ec62 | 47 | { XFS_ERRTAG_REFCOUNT_FINISH_ONE, "refcount_finish_one" }, |
a136ec62 | 48 | { XFS_ERRTAG_BMAP_FINISH_ONE, "bmap_finish_one" }, |
e00481b1 | 49 | { XFS_ERRTAG_AG_RESV_CRITICAL, "ag_resv_critical" }, |
18146cc2 | 50 | { XFS_ERRTAG_DROP_WRITES, "drop_writes" }, |
18146cc2 | 51 | { XFS_ERRTAG_LOG_BAD_CRC, "log_bad_crc" }, |
18146cc2 | 52 | { XFS_ERRTAG_LOG_ITEM_PIN, "log_item_pin" }, |
fc60b66d | 53 | { XFS_ERRTAG_BUF_LRU_REF, "buf_lru_ref" }, |
52818844 | 54 | { XFS_ERRTAG_FORCE_SCRUB_REPAIR, "force_repair" }, |
b09a5970 | 55 | { XFS_ERRTAG_FORCE_SUMMARY_RECALC, "bad_summary" }, |
d9fa4408 | 56 | { XFS_ERRTAG_IUNLINK_FALLBACK, "iunlink_fallback" }, |
3acdd264 | 57 | { XFS_ERRTAG_BUF_IOERROR, "buf_ioerror" }, |
b88613bd | 58 | { XFS_ERRTAG_REDUCE_MAX_IEXTENTS, "reduce_max_iextents" }, |
3006cea4 | 59 | { XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT, "bmap_alloc_minlen_extent" }, |
c4add24c | 60 | { XFS_ERRTAG_AG_RESV_FAIL, "ag_resv_fail" }, |
a2832031 | 61 | { XFS_ERRTAG_LARP, "larp" }, |
7f92d9ee | 62 | { XFS_ERRTAG_DA_LEAF_SPLIT, "da_leaf_split" }, |
c818a9fb | 63 | { XFS_ERRTAG_ATTR_LEAF_TO_NODE, "attr_leaf_to_node" }, |
9061d756 | 64 | { XFS_ERRTAG_WB_DELAY_MS, "wb_delay_ms" }, |
fb084f35 | 65 | { XFS_ERRTAG_WRITE_DELAY_MS, "write_delay_ms" }, |
48c46ee3 NS |
66 | { XFS_ERRTAG_MAX, NULL } |
67 | }; | |
68 | int count; | |
69 | ||
b09a5970 DW |
70 | /* |
71 | * If this fails make sure every tag is defined in the array above, | |
72 | * see xfs_errortag_attrs in kernelspace. | |
73 | */ | |
fc60b66d ES |
74 | BUILD_BUG_ON(sizeof(eflags) != (XFS_ERRTAG_MAX + 1) * sizeof(*e)); |
75 | ||
48c46ee3 NS |
76 | /* Search for a name */ |
77 | if (name) { | |
78 | for (e = eflags; e->name; e++) | |
79 | if (strcmp(name, e->name) == 0) | |
80 | return e->tag; | |
81 | return -1; | |
82 | } | |
83 | ||
84 | /* Dump all the names */ | |
85 | fputs("tags: [ ", stdout); | |
86 | for (count = 0, e = eflags; e->name; e++, count++) { | |
87 | if (count) { | |
88 | fputs(", ", stdout); | |
89 | if (!(count % 5)) | |
90 | fputs("\n\t", stdout); | |
91 | } | |
92 | fputs(e->name, stdout); | |
93 | } | |
94 | fputs(" ]\n", stdout); | |
95 | return 0; | |
96 | } | |
97 | ||
98 | static void | |
99 | inject_help(void) | |
100 | { | |
101 | printf(_( | |
102 | "\n" | |
103 | " inject errors into the filesystem of the currently open file\n" | |
104 | "\n" | |
105 | " Example:\n" | |
106 | " 'inject readagf' - cause errors on allocation group freespace reads\n" | |
107 | "\n" | |
108 | " Causes the kernel to generate and react to errors within XFS, provided\n" | |
109 | " the XFS kernel code has been built with debugging features enabled.\n" | |
110 | " With no arguments, displays the list of error injection tags.\n" | |
111 | "\n")); | |
112 | } | |
113 | ||
114 | static int | |
115 | inject_f( | |
116 | int argc, | |
117 | char **argv) | |
118 | { | |
119 | xfs_error_injection_t error; | |
120 | int command = XFS_IOC_ERROR_INJECTION; | |
121 | ||
122 | if (argc == 1) | |
123 | return error_tag(NULL); | |
124 | ||
125 | while (--argc > 0) { | |
126 | error.fd = file->fd; | |
127 | if ((error.errtag = error_tag(argv[argc])) < 0) { | |
128 | fprintf(stderr, _("no such tag -- %s\n"), argv[1]); | |
129 | continue; | |
130 | } | |
131 | if (error.errtag == XFS_ERRTAG_NOERROR) | |
132 | command = XFS_IOC_ERROR_CLEARALL; | |
133 | if ((xfsctl(file->name, file->fd, command, &error)) < 0) { | |
134 | perror("XFS_IOC_ERROR_INJECTION"); | |
9e1595e6 | 135 | exitcode = 1; |
48c46ee3 NS |
136 | continue; |
137 | } | |
138 | } | |
139 | return 0; | |
140 | } | |
141 | ||
142 | void | |
143 | inject_init(void) | |
144 | { | |
ad765595 | 145 | inject_cmd.name = "inject"; |
48c46ee3 NS |
146 | inject_cmd.cfunc = inject_f; |
147 | inject_cmd.argmin = 0; | |
148 | inject_cmd.argmax = -1; | |
16bf0464 | 149 | inject_cmd.flags = CMD_NOMAP_OK | CMD_FLAG_ONESHOT; |
48c46ee3 NS |
150 | inject_cmd.args = _("[tag ...]"); |
151 | inject_cmd.oneline = _("inject errors into a filesystem"); | |
152 | inject_cmd.help = inject_help; | |
153 | ||
154 | if (expert) | |
155 | add_command(&inject_cmd); | |
156 | } |