]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/inject.c
xfs_io: replace posix_fadvise64 by equivalent posix_fadvise
[thirdparty/xfsprogs-dev.git] / io / inject.c
1 /*
2 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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
7 * published by the Free Software Foundation.
8 *
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.
13 *
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
17 */
18
19 #include "command.h"
20 #include "input.h"
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_FREE_EXTENT 22
78 { XFS_ERRTAG_FREE_EXTENT, "free_extent" },
79 #define XFS_ERRTAG_RMAP_FINISH_ONE 23
80 { XFS_ERRTAG_RMAP_FINISH_ONE, "rmap_finish_one" },
81 #define XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE 24
82 { XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE, "refcount_continue_update" },
83 #define XFS_ERRTAG_REFCOUNT_FINISH_ONE 25
84 { XFS_ERRTAG_REFCOUNT_FINISH_ONE, "refcount_finish_one" },
85 #define XFS_ERRTAG_BMAP_FINISH_ONE 26
86 { XFS_ERRTAG_BMAP_FINISH_ONE, "bmap_finish_one" },
87 #define XFS_ERRTAG_AG_RESV_CRITICAL 27
88 { XFS_ERRTAG_AG_RESV_CRITICAL, "ag_resv_critical" },
89 #define XFS_ERRTAG_MAX 28
90 { XFS_ERRTAG_MAX, NULL }
91 };
92 int count;
93
94 /* Search for a name */
95 if (name) {
96 for (e = eflags; e->name; e++)
97 if (strcmp(name, e->name) == 0)
98 return e->tag;
99 return -1;
100 }
101
102 /* Dump all the names */
103 fputs("tags: [ ", stdout);
104 for (count = 0, e = eflags; e->name; e++, count++) {
105 if (count) {
106 fputs(", ", stdout);
107 if (!(count % 5))
108 fputs("\n\t", stdout);
109 }
110 fputs(e->name, stdout);
111 }
112 fputs(" ]\n", stdout);
113 return 0;
114 }
115
116 static void
117 inject_help(void)
118 {
119 printf(_(
120 "\n"
121 " inject errors into the filesystem of the currently open file\n"
122 "\n"
123 " Example:\n"
124 " 'inject readagf' - cause errors on allocation group freespace reads\n"
125 "\n"
126 " Causes the kernel to generate and react to errors within XFS, provided\n"
127 " the XFS kernel code has been built with debugging features enabled.\n"
128 " With no arguments, displays the list of error injection tags.\n"
129 "\n"));
130 }
131
132 static int
133 inject_f(
134 int argc,
135 char **argv)
136 {
137 xfs_error_injection_t error;
138 int command = XFS_IOC_ERROR_INJECTION;
139
140 if (argc == 1)
141 return error_tag(NULL);
142
143 while (--argc > 0) {
144 error.fd = file->fd;
145 if ((error.errtag = error_tag(argv[argc])) < 0) {
146 fprintf(stderr, _("no such tag -- %s\n"), argv[1]);
147 continue;
148 }
149 if (error.errtag == XFS_ERRTAG_NOERROR)
150 command = XFS_IOC_ERROR_CLEARALL;
151 if ((xfsctl(file->name, file->fd, command, &error)) < 0) {
152 perror("XFS_IOC_ERROR_INJECTION");
153 continue;
154 }
155 }
156 return 0;
157 }
158
159 void
160 inject_init(void)
161 {
162 inject_cmd.name = "inject";
163 inject_cmd.cfunc = inject_f;
164 inject_cmd.argmin = 0;
165 inject_cmd.argmax = -1;
166 inject_cmd.flags = CMD_NOMAP_OK;
167 inject_cmd.args = _("[tag ...]");
168 inject_cmd.oneline = _("inject errors into a filesystem");
169 inject_cmd.help = inject_help;
170
171 if (expert)
172 add_command(&inject_cmd);
173 }