]>
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" }, | |
77 | #define XFS_ERRTAG_MAX 22 | |
78 | { XFS_ERRTAG_MAX, NULL } | |
79 | }; | |
80 | int count; | |
81 | ||
82 | /* Search for a name */ | |
83 | if (name) { | |
84 | for (e = eflags; e->name; e++) | |
85 | if (strcmp(name, e->name) == 0) | |
86 | return e->tag; | |
87 | return -1; | |
88 | } | |
89 | ||
90 | /* Dump all the names */ | |
91 | fputs("tags: [ ", stdout); | |
92 | for (count = 0, e = eflags; e->name; e++, count++) { | |
93 | if (count) { | |
94 | fputs(", ", stdout); | |
95 | if (!(count % 5)) | |
96 | fputs("\n\t", stdout); | |
97 | } | |
98 | fputs(e->name, stdout); | |
99 | } | |
100 | fputs(" ]\n", stdout); | |
101 | return 0; | |
102 | } | |
103 | ||
104 | static void | |
105 | inject_help(void) | |
106 | { | |
107 | printf(_( | |
108 | "\n" | |
109 | " inject errors into the filesystem of the currently open file\n" | |
110 | "\n" | |
111 | " Example:\n" | |
112 | " 'inject readagf' - cause errors on allocation group freespace reads\n" | |
113 | "\n" | |
114 | " Causes the kernel to generate and react to errors within XFS, provided\n" | |
115 | " the XFS kernel code has been built with debugging features enabled.\n" | |
116 | " With no arguments, displays the list of error injection tags.\n" | |
117 | "\n")); | |
118 | } | |
119 | ||
120 | static int | |
121 | inject_f( | |
122 | int argc, | |
123 | char **argv) | |
124 | { | |
125 | xfs_error_injection_t error; | |
126 | int command = XFS_IOC_ERROR_INJECTION; | |
127 | ||
128 | if (argc == 1) | |
129 | return error_tag(NULL); | |
130 | ||
131 | while (--argc > 0) { | |
132 | error.fd = file->fd; | |
133 | if ((error.errtag = error_tag(argv[argc])) < 0) { | |
134 | fprintf(stderr, _("no such tag -- %s\n"), argv[1]); | |
135 | continue; | |
136 | } | |
137 | if (error.errtag == XFS_ERRTAG_NOERROR) | |
138 | command = XFS_IOC_ERROR_CLEARALL; | |
139 | if ((xfsctl(file->name, file->fd, command, &error)) < 0) { | |
140 | perror("XFS_IOC_ERROR_INJECTION"); | |
141 | continue; | |
142 | } | |
143 | } | |
144 | return 0; | |
145 | } | |
146 | ||
147 | void | |
148 | inject_init(void) | |
149 | { | |
ad765595 | 150 | inject_cmd.name = "inject"; |
48c46ee3 NS |
151 | inject_cmd.cfunc = inject_f; |
152 | inject_cmd.argmin = 0; | |
153 | inject_cmd.argmax = -1; | |
154 | inject_cmd.flags = CMD_NOMAP_OK; | |
155 | inject_cmd.args = _("[tag ...]"); | |
156 | inject_cmd.oneline = _("inject errors into a filesystem"); | |
157 | inject_cmd.help = inject_help; | |
158 | ||
159 | if (expert) | |
160 | add_command(&inject_cmd); | |
161 | } |