]>
Commit | Line | Data |
---|---|---|
48c46ee3 | 1 | /* |
da23017d NS |
2 | * Copyright (c) 2004-2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
48c46ee3 | 4 | * |
da23017d NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
48c46ee3 NS |
7 | * published by the Free Software Foundation. |
8 | * | |
da23017d NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
48c46ee3 | 13 | * |
da23017d NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
48c46ee3 NS |
17 | */ |
18 | ||
6b803e5a CH |
19 | #include "command.h" |
20 | #include "input.h" | |
48c46ee3 NS |
21 | #include "init.h" |
22 | #include "io.h" | |
23 | ||
24 | static cmdinfo_t inject_cmd; | |
25 | ||
26 | static int | |
27 | error_tag(char *name) | |
28 | { | |
29 | static struct { | |
30 | int tag; | |
31 | char *name; | |
32 | } *e, eflags[] = { | |
33 | #define XFS_ERRTAG_NOERROR 0 | |
34 | { XFS_ERRTAG_NOERROR, "noerror" }, | |
35 | #define XFS_ERRTAG_IFLUSH_1 1 | |
36 | { XFS_ERRTAG_IFLUSH_1, "iflush1" }, | |
37 | #define XFS_ERRTAG_IFLUSH_2 2 | |
38 | { XFS_ERRTAG_IFLUSH_2, "iflush2" }, | |
39 | #define XFS_ERRTAG_IFLUSH_3 3 | |
40 | { XFS_ERRTAG_IFLUSH_3, "iflush3" }, | |
41 | #define XFS_ERRTAG_IFLUSH_4 4 | |
42 | { XFS_ERRTAG_IFLUSH_4, "iflush4" }, | |
43 | #define XFS_ERRTAG_IFLUSH_5 5 | |
44 | { XFS_ERRTAG_IFLUSH_5, "iflush5" }, | |
45 | #define XFS_ERRTAG_IFLUSH_6 6 | |
46 | { XFS_ERRTAG_IFLUSH_6, "iflush6" }, | |
47 | #define XFS_ERRTAG_DA_READ_BUF 7 | |
48 | { XFS_ERRTAG_DA_READ_BUF, "dareadbuf" }, | |
49 | #define XFS_ERRTAG_BTREE_CHECK_LBLOCK 8 | |
50 | { XFS_ERRTAG_BTREE_CHECK_LBLOCK, "btree_chk_lblk" }, | |
51 | #define XFS_ERRTAG_BTREE_CHECK_SBLOCK 9 | |
52 | { XFS_ERRTAG_BTREE_CHECK_SBLOCK, "btree_chk_sblk" }, | |
53 | #define XFS_ERRTAG_ALLOC_READ_AGF 10 | |
54 | { XFS_ERRTAG_ALLOC_READ_AGF, "readagf" }, | |
55 | #define XFS_ERRTAG_IALLOC_READ_AGI 11 | |
56 | { XFS_ERRTAG_IALLOC_READ_AGI, "readagi" }, | |
57 | #define XFS_ERRTAG_ITOBP_INOTOBP 12 | |
58 | { XFS_ERRTAG_ITOBP_INOTOBP, "itobp" }, | |
59 | #define XFS_ERRTAG_IUNLINK 13 | |
60 | { XFS_ERRTAG_IUNLINK, "iunlink" }, | |
61 | #define XFS_ERRTAG_IUNLINK_REMOVE 14 | |
62 | { XFS_ERRTAG_IUNLINK_REMOVE, "iunlinkrm" }, | |
63 | #define XFS_ERRTAG_DIR_INO_VALIDATE 15 | |
64 | { XFS_ERRTAG_DIR_INO_VALIDATE, "dirinovalid" }, | |
65 | #define XFS_ERRTAG_BULKSTAT_READ_CHUNK 16 | |
66 | { XFS_ERRTAG_BULKSTAT_READ_CHUNK, "bulkstat" }, | |
67 | #define XFS_ERRTAG_IODONE_IOERR 17 | |
68 | { XFS_ERRTAG_IODONE_IOERR, "logiodone" }, | |
69 | #define XFS_ERRTAG_STRATREAD_IOERR 18 | |
70 | { XFS_ERRTAG_STRATREAD_IOERR, "stratread" }, | |
71 | #define XFS_ERRTAG_STRATCMPL_IOERR 19 | |
72 | { XFS_ERRTAG_STRATCMPL_IOERR, "stratcmpl" }, | |
73 | #define XFS_ERRTAG_DIOWRITE_IOERR 20 | |
74 | { XFS_ERRTAG_DIOWRITE_IOERR, "diowrite" }, | |
75 | #define XFS_ERRTAG_BMAPIFORMAT 21 | |
76 | { XFS_ERRTAG_BMAPIFORMAT, "bmapifmt" }, | |
80afb9a4 DW |
77 | #define XFS_ERRTAG_FREE_EXTENT 22 |
78 | { XFS_ERRTAG_FREE_EXTENT, "free_extent" }, | |
dea764e0 DW |
79 | #define XFS_ERRTAG_RMAP_FINISH_ONE 23 |
80 | { XFS_ERRTAG_RMAP_FINISH_ONE, "rmap_finish_one" }, | |
81 | #define XFS_ERRTAG_MAX 24 | |
48c46ee3 NS |
82 | { XFS_ERRTAG_MAX, NULL } |
83 | }; | |
84 | int count; | |
85 | ||
86 | /* Search for a name */ | |
87 | if (name) { | |
88 | for (e = eflags; e->name; e++) | |
89 | if (strcmp(name, e->name) == 0) | |
90 | return e->tag; | |
91 | return -1; | |
92 | } | |
93 | ||
94 | /* Dump all the names */ | |
95 | fputs("tags: [ ", stdout); | |
96 | for (count = 0, e = eflags; e->name; e++, count++) { | |
97 | if (count) { | |
98 | fputs(", ", stdout); | |
99 | if (!(count % 5)) | |
100 | fputs("\n\t", stdout); | |
101 | } | |
102 | fputs(e->name, stdout); | |
103 | } | |
104 | fputs(" ]\n", stdout); | |
105 | return 0; | |
106 | } | |
107 | ||
108 | static void | |
109 | inject_help(void) | |
110 | { | |
111 | printf(_( | |
112 | "\n" | |
113 | " inject errors into the filesystem of the currently open file\n" | |
114 | "\n" | |
115 | " Example:\n" | |
116 | " 'inject readagf' - cause errors on allocation group freespace reads\n" | |
117 | "\n" | |
118 | " Causes the kernel to generate and react to errors within XFS, provided\n" | |
119 | " the XFS kernel code has been built with debugging features enabled.\n" | |
120 | " With no arguments, displays the list of error injection tags.\n" | |
121 | "\n")); | |
122 | } | |
123 | ||
124 | static int | |
125 | inject_f( | |
126 | int argc, | |
127 | char **argv) | |
128 | { | |
129 | xfs_error_injection_t error; | |
130 | int command = XFS_IOC_ERROR_INJECTION; | |
131 | ||
132 | if (argc == 1) | |
133 | return error_tag(NULL); | |
134 | ||
135 | while (--argc > 0) { | |
136 | error.fd = file->fd; | |
137 | if ((error.errtag = error_tag(argv[argc])) < 0) { | |
138 | fprintf(stderr, _("no such tag -- %s\n"), argv[1]); | |
139 | continue; | |
140 | } | |
141 | if (error.errtag == XFS_ERRTAG_NOERROR) | |
142 | command = XFS_IOC_ERROR_CLEARALL; | |
143 | if ((xfsctl(file->name, file->fd, command, &error)) < 0) { | |
144 | perror("XFS_IOC_ERROR_INJECTION"); | |
145 | continue; | |
146 | } | |
147 | } | |
148 | return 0; | |
149 | } | |
150 | ||
151 | void | |
152 | inject_init(void) | |
153 | { | |
ad765595 | 154 | inject_cmd.name = "inject"; |
48c46ee3 NS |
155 | inject_cmd.cfunc = inject_f; |
156 | inject_cmd.argmin = 0; | |
157 | inject_cmd.argmax = -1; | |
158 | inject_cmd.flags = CMD_NOMAP_OK; | |
159 | inject_cmd.args = _("[tag ...]"); | |
160 | inject_cmd.oneline = _("inject errors into a filesystem"); | |
161 | inject_cmd.help = inject_help; | |
162 | ||
163 | if (expert) | |
164 | add_command(&inject_cmd); | |
165 | } |