]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - io/inject.c
Allow swab.h to be used in -pedantic c++ build environments.
[thirdparty/xfsprogs-dev.git] / io / inject.c
CommitLineData
48c46ee3
NS
1/*
2 * Copyright (c) 2004 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32
33#include <xfs/libxfs.h>
0717a7db
NS
34#include <xfs/command.h>
35#include <xfs/input.h>
48c46ee3
NS
36#include "init.h"
37#include "io.h"
38
39static cmdinfo_t inject_cmd;
40
41static int
42error_tag(char *name)
43{
44 static struct {
45 int tag;
46 char *name;
47 } *e, eflags[] = {
48#define XFS_ERRTAG_NOERROR 0
49 { XFS_ERRTAG_NOERROR, "noerror" },
50#define XFS_ERRTAG_IFLUSH_1 1
51 { XFS_ERRTAG_IFLUSH_1, "iflush1" },
52#define XFS_ERRTAG_IFLUSH_2 2
53 { XFS_ERRTAG_IFLUSH_2, "iflush2" },
54#define XFS_ERRTAG_IFLUSH_3 3
55 { XFS_ERRTAG_IFLUSH_3, "iflush3" },
56#define XFS_ERRTAG_IFLUSH_4 4
57 { XFS_ERRTAG_IFLUSH_4, "iflush4" },
58#define XFS_ERRTAG_IFLUSH_5 5
59 { XFS_ERRTAG_IFLUSH_5, "iflush5" },
60#define XFS_ERRTAG_IFLUSH_6 6
61 { XFS_ERRTAG_IFLUSH_6, "iflush6" },
62#define XFS_ERRTAG_DA_READ_BUF 7
63 { XFS_ERRTAG_DA_READ_BUF, "dareadbuf" },
64#define XFS_ERRTAG_BTREE_CHECK_LBLOCK 8
65 { XFS_ERRTAG_BTREE_CHECK_LBLOCK, "btree_chk_lblk" },
66#define XFS_ERRTAG_BTREE_CHECK_SBLOCK 9
67 { XFS_ERRTAG_BTREE_CHECK_SBLOCK, "btree_chk_sblk" },
68#define XFS_ERRTAG_ALLOC_READ_AGF 10
69 { XFS_ERRTAG_ALLOC_READ_AGF, "readagf" },
70#define XFS_ERRTAG_IALLOC_READ_AGI 11
71 { XFS_ERRTAG_IALLOC_READ_AGI, "readagi" },
72#define XFS_ERRTAG_ITOBP_INOTOBP 12
73 { XFS_ERRTAG_ITOBP_INOTOBP, "itobp" },
74#define XFS_ERRTAG_IUNLINK 13
75 { XFS_ERRTAG_IUNLINK, "iunlink" },
76#define XFS_ERRTAG_IUNLINK_REMOVE 14
77 { XFS_ERRTAG_IUNLINK_REMOVE, "iunlinkrm" },
78#define XFS_ERRTAG_DIR_INO_VALIDATE 15
79 { XFS_ERRTAG_DIR_INO_VALIDATE, "dirinovalid" },
80#define XFS_ERRTAG_BULKSTAT_READ_CHUNK 16
81 { XFS_ERRTAG_BULKSTAT_READ_CHUNK, "bulkstat" },
82#define XFS_ERRTAG_IODONE_IOERR 17
83 { XFS_ERRTAG_IODONE_IOERR, "logiodone" },
84#define XFS_ERRTAG_STRATREAD_IOERR 18
85 { XFS_ERRTAG_STRATREAD_IOERR, "stratread" },
86#define XFS_ERRTAG_STRATCMPL_IOERR 19
87 { XFS_ERRTAG_STRATCMPL_IOERR, "stratcmpl" },
88#define XFS_ERRTAG_DIOWRITE_IOERR 20
89 { XFS_ERRTAG_DIOWRITE_IOERR, "diowrite" },
90#define XFS_ERRTAG_BMAPIFORMAT 21
91 { XFS_ERRTAG_BMAPIFORMAT, "bmapifmt" },
92#define XFS_ERRTAG_MAX 22
93 { XFS_ERRTAG_MAX, NULL }
94 };
95 int count;
96
97 /* Search for a name */
98 if (name) {
99 for (e = eflags; e->name; e++)
100 if (strcmp(name, e->name) == 0)
101 return e->tag;
102 return -1;
103 }
104
105 /* Dump all the names */
106 fputs("tags: [ ", stdout);
107 for (count = 0, e = eflags; e->name; e++, count++) {
108 if (count) {
109 fputs(", ", stdout);
110 if (!(count % 5))
111 fputs("\n\t", stdout);
112 }
113 fputs(e->name, stdout);
114 }
115 fputs(" ]\n", stdout);
116 return 0;
117}
118
119static void
120inject_help(void)
121{
122 printf(_(
123"\n"
124" inject errors into the filesystem of the currently open file\n"
125"\n"
126" Example:\n"
127" 'inject readagf' - cause errors on allocation group freespace reads\n"
128"\n"
129" Causes the kernel to generate and react to errors within XFS, provided\n"
130" the XFS kernel code has been built with debugging features enabled.\n"
131" With no arguments, displays the list of error injection tags.\n"
132"\n"));
133}
134
135static int
136inject_f(
137 int argc,
138 char **argv)
139{
140 xfs_error_injection_t error;
141 int command = XFS_IOC_ERROR_INJECTION;
142
143 if (argc == 1)
144 return error_tag(NULL);
145
146 while (--argc > 0) {
147 error.fd = file->fd;
148 if ((error.errtag = error_tag(argv[argc])) < 0) {
149 fprintf(stderr, _("no such tag -- %s\n"), argv[1]);
150 continue;
151 }
152 if (error.errtag == XFS_ERRTAG_NOERROR)
153 command = XFS_IOC_ERROR_CLEARALL;
154 if ((xfsctl(file->name, file->fd, command, &error)) < 0) {
155 perror("XFS_IOC_ERROR_INJECTION");
156 continue;
157 }
158 }
159 return 0;
160}
161
162void
163inject_init(void)
164{
165 inject_cmd.name = _("inject");
166 inject_cmd.cfunc = inject_f;
167 inject_cmd.argmin = 0;
168 inject_cmd.argmax = -1;
169 inject_cmd.flags = CMD_NOMAP_OK;
170 inject_cmd.args = _("[tag ...]");
171 inject_cmd.oneline = _("inject errors into a filesystem");
172 inject_cmd.help = inject_help;
173
174 if (expert)
175 add_command(&inject_cmd);
176}