[udis86] Add VMLAUNCH, VMREAD, and VMWRITE instructions.
[ksplice.git] / ksplice-undo.in
blob071109fc9a428ab104c2bfcf6034591fc1a47522
1 #!/usr/bin/perl
3 # Copyright (C) 2007-2008 Jeffrey Brian Arnold <jbarnold@mit.edu>
4 # Copyright (C) 2008 Anders Kaseorg <andersk@mit.edu>,
5 # Tim Abbott <tabbott@mit.edu>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License, version 2.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
18 # 02110-1301, USA.
20 use strict;
21 use warnings;
22 use lib 'KSPLICE_DATA_DIR';
23 use Ksplice;
25 my $debug = 0;
26 GetOptions(@common_options,
27 "debug" => \$debug) or pod2usage(1);
29 pod2usage(1) if($help || scalar(@ARGV) != 1);
31 my $kid = $ARGV[0];
32 $kid =~ s/^ksplice[-_]//;
33 $kid =~ s/[-_].*$//;
34 my $update = "ksplice_$kid";
35 my $nounload = runstr("lsmod") =~ m/- $/m;
37 if (!update_loaded($kid)) {
38 print "Ksplice id $kid is not present in the kernel\n";
39 exit(1);
42 chdir("/sys/module/");
43 set_debug_level($kid, $debug) if(defined($debug));
44 my $stage = get_stage($kid);
45 if ($stage ne 'applied') {
46 print "Ksplice id $kid is not applied\n";
48 else {
49 set_stage($kid, "reversed");
52 my $failed = 0;
53 foreach my $module (glob("${update}_*")) {
54 if (!$nounload && runval_raw('rmmod', $module) != 0) {
55 child_error();
56 $failed = 1;
59 if ($failed == 0 && -e "/sys/module/$update") {
60 if (!$nounload && runval_raw('rmmod', $update) != 0) {
61 child_error();
62 $failed = 1;
65 unless($failed == 0) {
66 my ($debugfile, $debugout) = get_debug_output($kid);
67 print STDERR "Error undoing Ksplice update $kid:\n";
68 print $debugout;
69 my $abort_cause = get_abort_cause($kid);
70 my $conflicts = get_conflicts($kid);
71 print_error($abort_cause);
72 if ($abort_cause eq 'code_busy') {
73 print $conflicts;
75 if(defined $debugfile) {
76 print $debugout;
77 print("Debugging output saved to $debugfile\n");
79 die;
81 exit(0);
83 sub print_error {
84 my ($error) = @_;
85 my %errors = (
86 "code_busy" => <<'END',
87 Ksplice has aborted the undo operation because it appears that the code that
88 you are trying to change is continuously in use by the system. More
89 specifically, Ksplice has been unable to find a moment when one or more of the
90 to-be-changed functions is not on a thread's kernel stack.
91 END
92 "module_busy" => <<'END',
93 Ksplice has aborted the undo operation because it appears that the Ksplice
94 update that you are trying to unload is in use by another module. You can find
95 out what module is using the Ksplice update using the lsmod command.
96 END
97 "unexpected_running_task" => <<'END',
98 Ksplice has aborted the undo operation because of an unexpected failure during
99 the kernel stack check. Please consider reporting a bug to PACKAGE_BUGREPORT.
101 "out_of_memory" => <<'END',
102 Ksplice has aborted the undo operation because the kernel ran out of memory.
104 "unexpected" => <<'END',
105 Ksplice has aborted because of an unexpected error.
106 Please consider reporting a bug to PACKAGE_BUGREPORT.
108 "UNKNOWN" => <<'END',
109 The Ksplice kernel component has returned an error code that this version of
110 ksplice-undo does not understand.
112 "ok" => <<'END',
113 Ksplice has aborted the undo operation for unknown reasons.
114 Please consider reporting a bug to PACKAGE_BUGREPORT.
117 $error = "UNKNOWN" if (!exists $errors{$error});
118 print STDERR "\n$errors{$error}\n";
121 =head1 NAME
123 ksplice-undo - Undo a Ksplice update that has been applied to the running kernel
125 =head1 SYNOPSIS
127 B<ksplice-undo> I<KSPLICE_ID>
129 =head1 DESCRIPTION
131 B<ksplice-undo> takes as input a Ksplice identification tag, as reported by
132 L<ksplice-view(8)>, and it reverses that update within the running binary kernel.
134 =head1 OPTIONS
136 =over 8
138 =item B<--debug>
140 Reverses the update with debugging output enabled. Recommended only for
141 debugging.
143 =back
145 =head1 SEE ALSO
147 L<ksplice-create(8)>, L<ksplice-apply(8)>, L<ksplice-view(8)>
149 =head1 COPYRIGHT
151 Copyright (C) 2007-2008 Jeffrey Brian Arnold <jbarnold@mit.edu>
152 Copyright (C) 2008 Anders Kaseorg <andersk@mit.edu>,
153 Tim Abbott <tabbott@mit.edu>
155 This is free software and documentation. You can redistribute and/or modify it
156 under the terms of the GNU General Public License, version 2.
158 =cut