]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/inject.c
Update copyright/license notices to match SGI legal prefered boilerplate.
[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 <xfs/libxfs.h>
20 #include <xfs/command.h>
21 #include <xfs/input.h>
22 #include "init.h"
23 #include "io.h"
24
25 static cmdinfo_t inject_cmd;
26
27 static int
28 error_tag(char *name)
29 {
30 static struct {
31 int tag;
32 char *name;
33 } *e, eflags[] = {
34 #define XFS_ERRTAG_NOERROR 0
35 { XFS_ERRTAG_NOERROR, "noerror" },
36 #define XFS_ERRTAG_IFLUSH_1 1
37 { XFS_ERRTAG_IFLUSH_1, "iflush1" },
38 #define XFS_ERRTAG_IFLUSH_2 2
39 { XFS_ERRTAG_IFLUSH_2, "iflush2" },
40 #define XFS_ERRTAG_IFLUSH_3 3
41 { XFS_ERRTAG_IFLUSH_3, "iflush3" },
42 #define XFS_ERRTAG_IFLUSH_4 4
43 { XFS_ERRTAG_IFLUSH_4, "iflush4" },
44 #define XFS_ERRTAG_IFLUSH_5 5
45 { XFS_ERRTAG_IFLUSH_5, "iflush5" },
46 #define XFS_ERRTAG_IFLUSH_6 6
47 { XFS_ERRTAG_IFLUSH_6, "iflush6" },
48 #define XFS_ERRTAG_DA_READ_BUF 7
49 { XFS_ERRTAG_DA_READ_BUF, "dareadbuf" },
50 #define XFS_ERRTAG_BTREE_CHECK_LBLOCK 8
51 { XFS_ERRTAG_BTREE_CHECK_LBLOCK, "btree_chk_lblk" },
52 #define XFS_ERRTAG_BTREE_CHECK_SBLOCK 9
53 { XFS_ERRTAG_BTREE_CHECK_SBLOCK, "btree_chk_sblk" },
54 #define XFS_ERRTAG_ALLOC_READ_AGF 10
55 { XFS_ERRTAG_ALLOC_READ_AGF, "readagf" },
56 #define XFS_ERRTAG_IALLOC_READ_AGI 11
57 { XFS_ERRTAG_IALLOC_READ_AGI, "readagi" },
58 #define XFS_ERRTAG_ITOBP_INOTOBP 12
59 { XFS_ERRTAG_ITOBP_INOTOBP, "itobp" },
60 #define XFS_ERRTAG_IUNLINK 13
61 { XFS_ERRTAG_IUNLINK, "iunlink" },
62 #define XFS_ERRTAG_IUNLINK_REMOVE 14
63 { XFS_ERRTAG_IUNLINK_REMOVE, "iunlinkrm" },
64 #define XFS_ERRTAG_DIR_INO_VALIDATE 15
65 { XFS_ERRTAG_DIR_INO_VALIDATE, "dirinovalid" },
66 #define XFS_ERRTAG_BULKSTAT_READ_CHUNK 16
67 { XFS_ERRTAG_BULKSTAT_READ_CHUNK, "bulkstat" },
68 #define XFS_ERRTAG_IODONE_IOERR 17
69 { XFS_ERRTAG_IODONE_IOERR, "logiodone" },
70 #define XFS_ERRTAG_STRATREAD_IOERR 18
71 { XFS_ERRTAG_STRATREAD_IOERR, "stratread" },
72 #define XFS_ERRTAG_STRATCMPL_IOERR 19
73 { XFS_ERRTAG_STRATCMPL_IOERR, "stratcmpl" },
74 #define XFS_ERRTAG_DIOWRITE_IOERR 20
75 { XFS_ERRTAG_DIOWRITE_IOERR, "diowrite" },
76 #define XFS_ERRTAG_BMAPIFORMAT 21
77 { XFS_ERRTAG_BMAPIFORMAT, "bmapifmt" },
78 #define XFS_ERRTAG_MAX 22
79 { XFS_ERRTAG_MAX, NULL }
80 };
81 int count;
82
83 /* Search for a name */
84 if (name) {
85 for (e = eflags; e->name; e++)
86 if (strcmp(name, e->name) == 0)
87 return e->tag;
88 return -1;
89 }
90
91 /* Dump all the names */
92 fputs("tags: [ ", stdout);
93 for (count = 0, e = eflags; e->name; e++, count++) {
94 if (count) {
95 fputs(", ", stdout);
96 if (!(count % 5))
97 fputs("\n\t", stdout);
98 }
99 fputs(e->name, stdout);
100 }
101 fputs(" ]\n", stdout);
102 return 0;
103 }
104
105 static void
106 inject_help(void)
107 {
108 printf(_(
109 "\n"
110 " inject errors into the filesystem of the currently open file\n"
111 "\n"
112 " Example:\n"
113 " 'inject readagf' - cause errors on allocation group freespace reads\n"
114 "\n"
115 " Causes the kernel to generate and react to errors within XFS, provided\n"
116 " the XFS kernel code has been built with debugging features enabled.\n"
117 " With no arguments, displays the list of error injection tags.\n"
118 "\n"));
119 }
120
121 static int
122 inject_f(
123 int argc,
124 char **argv)
125 {
126 xfs_error_injection_t error;
127 int command = XFS_IOC_ERROR_INJECTION;
128
129 if (argc == 1)
130 return error_tag(NULL);
131
132 while (--argc > 0) {
133 error.fd = file->fd;
134 if ((error.errtag = error_tag(argv[argc])) < 0) {
135 fprintf(stderr, _("no such tag -- %s\n"), argv[1]);
136 continue;
137 }
138 if (error.errtag == XFS_ERRTAG_NOERROR)
139 command = XFS_IOC_ERROR_CLEARALL;
140 if ((xfsctl(file->name, file->fd, command, &error)) < 0) {
141 perror("XFS_IOC_ERROR_INJECTION");
142 continue;
143 }
144 }
145 return 0;
146 }
147
148 void
149 inject_init(void)
150 {
151 inject_cmd.name = _("inject");
152 inject_cmd.cfunc = inject_f;
153 inject_cmd.argmin = 0;
154 inject_cmd.argmax = -1;
155 inject_cmd.flags = CMD_NOMAP_OK;
156 inject_cmd.args = _("[tag ...]");
157 inject_cmd.oneline = _("inject errors into a filesystem");
158 inject_cmd.help = inject_help;
159
160 if (expert)
161 add_command(&inject_cmd);
162 }