Deleted Added
full compact
zinject.c (243674) zinject.c (248369)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012 by Delphix. All rights reserved.
23 */
24
25/*
26 * ZFS Fault Injector
27 *
28 * This userland component takes a set of options and uses libzpool to translate
29 * from a user-visible object type and name to an internal representation.
30 * There are two basic types of faults: device faults and data faults.

--- 567 unchanged lines hidden (view full) ---

598 (void) printf("Run 'zinject -h' for usage "
599 "information.\n");
600 }
601
602 return (0);
603 }
604
605 while ((c = getopt(argc, argv,
24 */
25
26/*
27 * ZFS Fault Injector
28 *
29 * This userland component takes a set of options and uses libzpool to translate
30 * from a user-visible object type and name to an internal representation.
31 * There are two basic types of faults: device faults and data faults.

--- 567 unchanged lines hidden (view full) ---

599 (void) printf("Run 'zinject -h' for usage "
600 "information.\n");
601 }
602
603 return (0);
604 }
605
606 while ((c = getopt(argc, argv,
606 ":aA:b:d:f:Fg:qhIc:t:T:l:mr:s:e:uL:p:")) != -1) {
607 ":aA:b:d:D:f:Fg:qhIc:t:T:l:mr:s:e:uL:p:")) != -1) {
607 switch (c) {
608 case 'a':
609 flags |= ZINJECT_FLUSH_ARC;
610 break;
611 case 'A':
612 if (strcasecmp(optarg, "degrade") == 0) {
613 action = VDEV_STATE_DEGRADED;
614 } else if (strcasecmp(optarg, "fault") == 0) {

--- 9 unchanged lines hidden (view full) ---

624 raw = optarg;
625 break;
626 case 'c':
627 cancel = optarg;
628 break;
629 case 'd':
630 device = optarg;
631 break;
608 switch (c) {
609 case 'a':
610 flags |= ZINJECT_FLUSH_ARC;
611 break;
612 case 'A':
613 if (strcasecmp(optarg, "degrade") == 0) {
614 action = VDEV_STATE_DEGRADED;
615 } else if (strcasecmp(optarg, "fault") == 0) {

--- 9 unchanged lines hidden (view full) ---

625 raw = optarg;
626 break;
627 case 'c':
628 cancel = optarg;
629 break;
630 case 'd':
631 device = optarg;
632 break;
633 case 'D':
634 record.zi_timer = strtoull(optarg, &end, 10);
635 if (errno != 0 || *end != '\0') {
636 (void) fprintf(stderr, "invalid i/o delay "
637 "value: '%s'\n", optarg);
638 usage();
639 return (1);
640 }
641 break;
632 case 'e':
633 if (strcasecmp(optarg, "io") == 0) {
634 error = EIO;
635 } else if (strcasecmp(optarg, "checksum") == 0) {
636 error = ECKSUM;
637 } else if (strcasecmp(optarg, "nxio") == 0) {
638 error = ENXIO;
639 } else if (strcasecmp(optarg, "dtl") == 0) {

--- 48 unchanged lines hidden (view full) ---

688 }
689 break;
690 case 'm':
691 domount = 1;
692 break;
693 case 'p':
694 (void) strlcpy(record.zi_func, optarg,
695 sizeof (record.zi_func));
642 case 'e':
643 if (strcasecmp(optarg, "io") == 0) {
644 error = EIO;
645 } else if (strcasecmp(optarg, "checksum") == 0) {
646 error = ECKSUM;
647 } else if (strcasecmp(optarg, "nxio") == 0) {
648 error = ENXIO;
649 } else if (strcasecmp(optarg, "dtl") == 0) {

--- 48 unchanged lines hidden (view full) ---

698 }
699 break;
700 case 'm':
701 domount = 1;
702 break;
703 case 'p':
704 (void) strlcpy(record.zi_func, optarg,
705 sizeof (record.zi_func));
706 record.zi_cmd = ZINJECT_PANIC;
696 break;
697 case 'q':
698 quiet = 1;
699 break;
700 case 'r':
701 range = optarg;
702 break;
703 case 's':

--- 57 unchanged lines hidden (view full) ---

761 usage();
762 return (2);
763 }
764 }
765
766 argc -= optind;
767 argv += optind;
768
707 break;
708 case 'q':
709 quiet = 1;
710 break;
711 case 'r':
712 range = optarg;
713 break;
714 case 's':

--- 57 unchanged lines hidden (view full) ---

772 usage();
773 return (2);
774 }
775 }
776
777 argc -= optind;
778 argv += optind;
779
780 if (record.zi_duration != 0)
781 record.zi_cmd = ZINJECT_IGNORED_WRITES;
782
769 if (cancel != NULL) {
770 /*
771 * '-c' is invalid with any other options.
772 */
773 if (raw != NULL || range != NULL || type != TYPE_INVAL ||
783 if (cancel != NULL) {
784 /*
785 * '-c' is invalid with any other options.
786 */
787 if (raw != NULL || range != NULL || type != TYPE_INVAL ||
774 level != 0 || record.zi_func[0] != '\0' ||
775 record.zi_duration != 0) {
788 level != 0 || record.zi_cmd != ZINJECT_UNINITIALIZED) {
776 (void) fprintf(stderr, "cancel (-c) incompatible with "
777 "any other options\n");
778 usage();
779 return (2);
780 }
781 if (argc != 0) {
782 (void) fprintf(stderr, "extraneous argument to '-c'\n");
783 usage();

--- 15 unchanged lines hidden (view full) ---

799 }
800
801 if (device != NULL) {
802 /*
803 * Device (-d) injection uses a completely different mechanism
804 * for doing injection, so handle it separately here.
805 */
806 if (raw != NULL || range != NULL || type != TYPE_INVAL ||
789 (void) fprintf(stderr, "cancel (-c) incompatible with "
790 "any other options\n");
791 usage();
792 return (2);
793 }
794 if (argc != 0) {
795 (void) fprintf(stderr, "extraneous argument to '-c'\n");
796 usage();

--- 15 unchanged lines hidden (view full) ---

812 }
813
814 if (device != NULL) {
815 /*
816 * Device (-d) injection uses a completely different mechanism
817 * for doing injection, so handle it separately here.
818 */
819 if (raw != NULL || range != NULL || type != TYPE_INVAL ||
807 level != 0 || record.zi_func[0] != '\0' ||
808 record.zi_duration != 0) {
820 level != 0 || record.zi_cmd != ZINJECT_UNINITIALIZED) {
809 (void) fprintf(stderr, "device (-d) incompatible with "
810 "data error injection\n");
811 usage();
812 return (2);
813 }
814
815 if (argc != 1) {
816 (void) fprintf(stderr, "device (-d) injection requires "

--- 17 unchanged lines hidden (view full) ---

834 if (!error)
835 error = ENXIO;
836
837 if (action != VDEV_STATE_UNKNOWN)
838 return (perform_action(pool, &record, action));
839
840 } else if (raw != NULL) {
841 if (range != NULL || type != TYPE_INVAL || level != 0 ||
821 (void) fprintf(stderr, "device (-d) incompatible with "
822 "data error injection\n");
823 usage();
824 return (2);
825 }
826
827 if (argc != 1) {
828 (void) fprintf(stderr, "device (-d) injection requires "

--- 17 unchanged lines hidden (view full) ---

846 if (!error)
847 error = ENXIO;
848
849 if (action != VDEV_STATE_UNKNOWN)
850 return (perform_action(pool, &record, action));
851
852 } else if (raw != NULL) {
853 if (range != NULL || type != TYPE_INVAL || level != 0 ||
842 record.zi_func[0] != '\0' || record.zi_duration != 0) {
854 record.zi_cmd != ZINJECT_UNINITIALIZED) {
843 (void) fprintf(stderr, "raw (-b) format with "
844 "any other options\n");
845 usage();
846 return (2);
847 }
848
849 if (argc != 1) {
850 (void) fprintf(stderr, "raw (-b) format expects a "

--- 6 unchanged lines hidden (view full) ---

857 dataset[0] = '\0';
858
859 if (error == ENXIO) {
860 (void) fprintf(stderr, "data error type must be "
861 "'checksum' or 'io'\n");
862 return (1);
863 }
864
855 (void) fprintf(stderr, "raw (-b) format with "
856 "any other options\n");
857 usage();
858 return (2);
859 }
860
861 if (argc != 1) {
862 (void) fprintf(stderr, "raw (-b) format expects a "

--- 6 unchanged lines hidden (view full) ---

869 dataset[0] = '\0';
870
871 if (error == ENXIO) {
872 (void) fprintf(stderr, "data error type must be "
873 "'checksum' or 'io'\n");
874 return (1);
875 }
876
877 record.zi_cmd = ZINJECT_DATA_FAULT;
865 if (translate_raw(raw, &record) != 0)
866 return (1);
867 if (!error)
868 error = EIO;
878 if (translate_raw(raw, &record) != 0)
879 return (1);
880 if (!error)
881 error = EIO;
869 } else if (record.zi_func[0] != '\0') {
882 } else if (record.zi_cmd == ZINJECT_PANIC) {
870 if (raw != NULL || range != NULL || type != TYPE_INVAL ||
883 if (raw != NULL || range != NULL || type != TYPE_INVAL ||
871 level != 0 || device != NULL || record.zi_duration != 0) {
884 level != 0 || device != NULL) {
872 (void) fprintf(stderr, "panic (-p) incompatible with "
873 "other options\n");
874 usage();
875 return (2);
876 }
877
878 if (argc < 1 || argc > 2) {
879 (void) fprintf(stderr, "panic (-p) injection requires "
880 "a single pool name and an optional id\n");
881 usage();
882 return (2);
883 }
884
885 (void) strcpy(pool, argv[0]);
886 if (argv[1] != NULL)
887 record.zi_type = atoi(argv[1]);
888 dataset[0] = '\0';
885 (void) fprintf(stderr, "panic (-p) incompatible with "
886 "other options\n");
887 usage();
888 return (2);
889 }
890
891 if (argc < 1 || argc > 2) {
892 (void) fprintf(stderr, "panic (-p) injection requires "
893 "a single pool name and an optional id\n");
894 usage();
895 return (2);
896 }
897
898 (void) strcpy(pool, argv[0]);
899 if (argv[1] != NULL)
900 record.zi_type = atoi(argv[1]);
901 dataset[0] = '\0';
889 } else if (record.zi_duration != 0) {
902 } else if (record.zi_cmd == ZINJECT_IGNORED_WRITES) {
890 if (nowrites == 0) {
891 (void) fprintf(stderr, "-s or -g meaningless "
892 "without -I (ignore writes)\n");
893 usage();
894 return (2);
895 } else if (dur_secs && dur_txg) {
896 (void) fprintf(stderr, "choose a duration either "
897 "in seconds (-s) or a number of txgs (-g) "

--- 37 unchanged lines hidden (view full) ---

935 }
936
937 if (error == ENXIO) {
938 (void) fprintf(stderr, "data error type must be "
939 "'checksum' or 'io'\n");
940 return (1);
941 }
942
903 if (nowrites == 0) {
904 (void) fprintf(stderr, "-s or -g meaningless "
905 "without -I (ignore writes)\n");
906 usage();
907 return (2);
908 } else if (dur_secs && dur_txg) {
909 (void) fprintf(stderr, "choose a duration either "
910 "in seconds (-s) or a number of txgs (-g) "

--- 37 unchanged lines hidden (view full) ---

948 }
949
950 if (error == ENXIO) {
951 (void) fprintf(stderr, "data error type must be "
952 "'checksum' or 'io'\n");
953 return (1);
954 }
955
956 record.zi_cmd = ZINJECT_DATA_FAULT;
943 if (translate_record(type, argv[0], range, level, &record, pool,
944 dataset) != 0)
945 return (1);
946 if (!error)
947 error = EIO;
948 }
949
950 /*

--- 23 unchanged lines hidden ---
957 if (translate_record(type, argv[0], range, level, &record, pool,
958 dataset) != 0)
959 return (1);
960 if (!error)
961 error = EIO;
962 }
963
964 /*

--- 23 unchanged lines hidden ---