git://git.camperquake.de
/
zfs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Don't leak mount flags into kernel
[zfs.git]
/
cmd
/
zinject
/
zinject.c
diff --git
a/cmd/zinject/zinject.c
b/cmd/zinject/zinject.c
index
ab04e42
..
13d067d
100644
(file)
--- a/
cmd/zinject/zinject.c
+++ b/
cmd/zinject/zinject.c
@@
-20,6
+20,7
@@
*/
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012 by Delphix. All rights reserved.
*/
/*
*/
/*
@@
-233,10
+234,10
@@
usage(void)
"\t\tInject a fault into a particular device or the device's\n"
"\t\tlabel. Label injection can either be 'nvlist', 'uber',\n "
"\t\t'pad1', or 'pad2'.\n"
"\t\tInject a fault into a particular device or the device's\n"
"\t\tlabel. Label injection can either be 'nvlist', 'uber',\n "
"\t\t'pad1', or 'pad2'.\n"
- "\t\t'errno' can
either be 'nxio' (the default) or 'io
'.\n"
+ "\t\t'errno' can
be 'nxio' (the default), 'io', or 'dtl
'.\n"
"\n"
"\n"
- "\tzinject -d device -A <degrade|fault> pool\n"
- "\t\tPerform a specific action on a particular device\n"
+ "\tzinject -d device -A <degrade|fault>
-D <delay secs>
pool\n"
+ "\t\tPerform a specific action on a particular device
.
\n"
"\n"
"\tzinject -I [-s <seconds> | -g <txgs>] pool\n"
"\t\tCause the pool to stop writing blocks yet not\n"
"\n"
"\tzinject -I [-s <seconds> | -g <txgs>] pool\n"
"\t\tCause the pool to stop writing blocks yet not\n"
@@
-395,17
+396,25
@@
print_panic_handler(int id, const char *pool, zinject_record_t *record,
static int
print_all_handlers(void)
{
static int
print_all_handlers(void)
{
- int count = 0;
+ int count = 0
, total = 0
;
(void) iter_handlers(print_device_handler, &count);
(void) iter_handlers(print_device_handler, &count);
- (void) printf("\n");
- count = 0;
+ if (count > 0) {
+ total += count;
+ (void) printf("\n");
+ count = 0;
+ }
+
(void) iter_handlers(print_data_handler, &count);
(void) iter_handlers(print_data_handler, &count);
- (void) printf("\n");
- count = 0;
+ if (count > 0) {
+ total += count;
+ (void) printf("\n");
+ count = 0;
+ }
+
(void) iter_handlers(print_panic_handler, &count);
(void) iter_handlers(print_panic_handler, &count);
- return (count);
+ return (count
+ total
);
}
/* ARGSUSED */
}
/* ARGSUSED */
@@
-558,18
+567,15
@@
main(int argc, char **argv)
zinject_record_t record = { 0 };
char pool[MAXNAMELEN];
char dataset[MAXNAMELEN];
zinject_record_t record = { 0 };
char pool[MAXNAMELEN];
char dataset[MAXNAMELEN];
- zfs_handle_t *zhp;
+ zfs_handle_t *zhp
= NULL
;
int nowrites = 0;
int dur_txg = 0;
int dur_secs = 0;
int ret;
int flags = 0;
int nowrites = 0;
int dur_txg = 0;
int dur_secs = 0;
int ret;
int flags = 0;
- if ((g_zfs = libzfs_init()) == NULL) {
- (void) fprintf(stderr, "internal error: failed to "
- "initialize ZFS library\n");
+ if ((g_zfs = libzfs_init()) == NULL)
return (1);
return (1);
- }
libzfs_print_on_error(g_zfs, B_TRUE);
libzfs_print_on_error(g_zfs, B_TRUE);
@@
-594,7
+600,7
@@
main(int argc, char **argv)
}
while ((c = getopt(argc, argv,
}
while ((c = getopt(argc, argv,
- ":aA:b:d:f:Fg:qhIc:t:T:l:mr:s:e:uL:p:")) != -1) {
+ ":aA:b:d:
D:
f:Fg:qhIc:t:T:l:mr:s:e:uL:p:")) != -1) {
switch (c) {
case 'a':
flags |= ZINJECT_FLUSH_ARC;
switch (c) {
case 'a':
flags |= ZINJECT_FLUSH_ARC;
@@
-620,6
+626,16
@@
main(int argc, char **argv)
case 'd':
device = optarg;
break;
case 'd':
device = optarg;
break;
+ case 'D':
+ errno = 0;
+ record.zi_timer = strtoull(optarg, &end, 10);
+ if (errno != 0 || *end != '\0') {
+ (void) fprintf(stderr, "invalid i/o delay "
+ "value: '%s'\n", optarg);
+ usage();
+ return (1);
+ }
+ break;
case 'e':
if (strcasecmp(optarg, "io") == 0) {
error = EIO;
case 'e':
if (strcasecmp(optarg, "io") == 0) {
error = EIO;
@@
-627,6
+643,8
@@
main(int argc, char **argv)
error = ECKSUM;
} else if (strcasecmp(optarg, "nxio") == 0) {
error = ENXIO;
error = ECKSUM;
} else if (strcasecmp(optarg, "nxio") == 0) {
error = ENXIO;
+ } else if (strcasecmp(optarg, "dtl") == 0) {
+ error = ECHILD;
} else {
(void) fprintf(stderr, "invalid error type "
"'%s': must be 'io', 'checksum' or "
} else {
(void) fprintf(stderr, "invalid error type "
"'%s': must be 'io', 'checksum' or "
@@
-682,6
+700,7
@@
main(int argc, char **argv)
case 'p':
(void) strlcpy(record.zi_func, optarg,
sizeof (record.zi_func));
case 'p':
(void) strlcpy(record.zi_func, optarg,
sizeof (record.zi_func));
+ record.zi_cmd = ZINJECT_PANIC;
break;
case 'q':
quiet = 1;
break;
case 'q':
quiet = 1;
@@
-755,13
+774,15
@@
main(int argc, char **argv)
argc -= optind;
argv += optind;
argc -= optind;
argv += optind;
+ if (record.zi_duration != 0)
+ record.zi_cmd = ZINJECT_IGNORED_WRITES;
+
if (cancel != NULL) {
/*
* '-c' is invalid with any other options.
*/
if (raw != NULL || range != NULL || type != TYPE_INVAL ||
if (cancel != NULL) {
/*
* '-c' is invalid with any other options.
*/
if (raw != NULL || range != NULL || type != TYPE_INVAL ||
- level != 0 || record.zi_func[0] != '\0' ||
- record.zi_duration != 0) {
+ level != 0 || record.zi_cmd != ZINJECT_UNINITIALIZED) {
(void) fprintf(stderr, "cancel (-c) incompatible with "
"any other options\n");
usage();
(void) fprintf(stderr, "cancel (-c) incompatible with "
"any other options\n");
usage();
@@
-793,8
+814,7
@@
main(int argc, char **argv)
* for doing injection, so handle it separately here.
*/
if (raw != NULL || range != NULL || type != TYPE_INVAL ||
* for doing injection, so handle it separately here.
*/
if (raw != NULL || range != NULL || type != TYPE_INVAL ||
- level != 0 || record.zi_func[0] != '\0' ||
- record.zi_duration != 0) {
+ level != 0 || record.zi_cmd != ZINJECT_UNINITIALIZED) {
(void) fprintf(stderr, "device (-d) incompatible with "
"data error injection\n");
usage();
(void) fprintf(stderr, "device (-d) incompatible with "
"data error injection\n");
usage();
@@
-828,7
+848,7
@@
main(int argc, char **argv)
} else if (raw != NULL) {
if (range != NULL || type != TYPE_INVAL || level != 0 ||
} else if (raw != NULL) {
if (range != NULL || type != TYPE_INVAL || level != 0 ||
- record.zi_
func[0] != '\0' || record.zi_duration != 0
) {
+ record.zi_
cmd != ZINJECT_UNINITIALIZED
) {
(void) fprintf(stderr, "raw (-b) format with "
"any other options\n");
usage();
(void) fprintf(stderr, "raw (-b) format with "
"any other options\n");
usage();
@@
-851,13
+871,14
@@
main(int argc, char **argv)
return (1);
}
return (1);
}
+ record.zi_cmd = ZINJECT_DATA_FAULT;
if (translate_raw(raw, &record) != 0)
return (1);
if (!error)
error = EIO;
if (translate_raw(raw, &record) != 0)
return (1);
if (!error)
error = EIO;
- } else if (record.zi_
func[0] != '\0'
) {
+ } else if (record.zi_
cmd == ZINJECT_PANIC
) {
if (raw != NULL || range != NULL || type != TYPE_INVAL ||
if (raw != NULL || range != NULL || type != TYPE_INVAL ||
- level != 0 || device != NULL
|| record.zi_duration != 0
) {
+ level != 0 || device != NULL) {
(void) fprintf(stderr, "panic (-p) incompatible with "
"other options\n");
usage();
(void) fprintf(stderr, "panic (-p) incompatible with "
"other options\n");
usage();
@@
-875,7
+896,7
@@
main(int argc, char **argv)
if (argv[1] != NULL)
record.zi_type = atoi(argv[1]);
dataset[0] = '\0';
if (argv[1] != NULL)
record.zi_type = atoi(argv[1]);
dataset[0] = '\0';
- } else if (record.zi_
duration != 0
) {
+ } else if (record.zi_
cmd == ZINJECT_IGNORED_WRITES
) {
if (nowrites == 0) {
(void) fprintf(stderr, "-s or -g meaningless "
"without -I (ignore writes)\n");
if (nowrites == 0) {
(void) fprintf(stderr, "-s or -g meaningless "
"without -I (ignore writes)\n");
@@
-929,6
+950,7
@@
main(int argc, char **argv)
return (1);
}
return (1);
}
+ record.zi_cmd = ZINJECT_DATA_FAULT;
if (translate_record(type, argv[0], range, level, &record, pool,
dataset) != 0)
return (1);
if (translate_record(type, argv[0], range, level, &record, pool,
dataset) != 0)
return (1);
@@
-944,7
+966,6
@@
main(int argc, char **argv)
if (dataset[0] != '\0' && domount) {
if ((zhp = zfs_open(g_zfs, dataset, ZFS_TYPE_DATASET)) == NULL)
return (1);
if (dataset[0] != '\0' && domount) {
if ((zhp = zfs_open(g_zfs, dataset, ZFS_TYPE_DATASET)) == NULL)
return (1);
-
if (zfs_unmount(zhp, NULL, 0) != 0)
return (1);
}
if (zfs_unmount(zhp, NULL, 0) != 0)
return (1);
}