Add extremely verbose debugging output back to ksplice-create.
[ksplice.git] / ksplice-undo.in
blobf295f988cee8cfb0c8fff2c7f48aa4b19fd4bfd3
1 #!/usr/bin/perl
3 # Copyright (C) 2008 Jeffrey Brian Arnold <jbarnold@mit.edu>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License, version 2.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
16 # 02110-1301, USA.
18 use Getopt::Long;
19 use Cwd 'abs_path', 'getcwd';
20 use Pod::Usage;
21 use strict;
22 use warnings;
23 use lib 'KSPLICE_DATA_DIR';
24 use ksplice;
25 use File::Temp;
27 my ($help, $wantversion, $debug) = (0, 0, 0);
28 GetOptions("help|?" => \$help,
29 "version" => \$wantversion,
30 "verbose|v!" => \$verbose::level,
31 "debug=i" => \$debug) or pod2usage(1);
33 if($wantversion) {
34 print $version_str;
35 exit(0);
37 pod2usage(1) if($help || scalar(@ARGV != 1));
39 my $kid = $ARGV[0];
40 $kid =~ s/^ksplice[_-]//;
42 if(! -d "/sys/module") {
43 print "/sys not mounted?\n";
44 exit(1);
46 if(! -d "/sys/module/ksplice_$kid/ksplice") {
47 print "Ksplice id $kid is not present in the kernel\n";
48 exit(1);
51 if($debug) {
52 if(! -d "/sys/module/ksplice_$kid/parameters") {
53 runval("echo $debug > /sys/module/ksplice_$kid/debug");
55 else {
56 runval("echo $debug > /sys/module/ksplice_$kid/parameters/debug");
60 open STATE, '>', "/sys/module/ksplice_$kid/ksplice/stage" or die $!;
61 print STATE "reversed\n";
62 close STATE;
63 unless(runstr("lsmod") =~ m/- $/m or runval_raw("rmmod ksplice_$kid") == 0) {
64 my $debugfs_out = mktemp("/tmp/ksplice-debug-XXXXXX");
65 my $debug = get_debugfs("ksplice_$kid", $debugfs_out);
66 if (!defined($debug)) {
67 my $dmesg = runstr("dmesg | grep ksplice");
68 while($dmesg =~ /ksplice: Preparing to reverse/) {
69 $dmesg = $';
71 $debug = $dmesg;
73 print STDERR "Error undoing Ksplice update $kid:\n";
74 print "$debug";
75 if($debug =~ /to-be-reversed code is busy/) {
76 print <<END
78 Ksplice has aborted the undo operation because it appears that the code that
79 you are trying to change is continuously in use by the system. More
80 specifically, Ksplice has been unable to find a moment when one or more of the
81 to-be-changed functions is not on a thread's kernel stack.
83 END
85 print("Debugging output saved to $debugfs_out\n");
86 die;
89 exit(0);
91 =head1 NAME
93 ksplice-undo - Undo a Ksplice update that has been applied to the running kernel
95 =head1 SYNOPSIS
97 B<ksplice-undo> I<KSPLICE_ID>
99 =head1 DESCRIPTION
101 B<ksplice-undo> takes as input a Ksplice identification tag, as reported by
102 L<ksplice-view(8)>, and it reverses that update within the running binary kernel.
104 =head1 OPTIONS
106 =over 8
108 =item B<--debug>
110 Reverses the update with debugging output enabled. Recommended only for
111 debugging. I<DEBUG_LEVEL> should be an integer between 0 and 2. B<--debug=2>
112 provides the most debugging information.
114 =over
116 =item Z<> B<0>
118 No debugging output.
120 =item Z<> B<1>
122 Provides basic kernel stack check debugging output.
124 =item Z<> B<2>
126 Provides full kernel stack check debugging output.
128 =back
130 =back
132 =head1 SEE ALSO
134 L<ksplice-create(8)>, L<ksplice-apply(8)>, L<ksplice-view(8)>
136 =head1 COPYRIGHT
138 Copyright (C) 2008 Jeffrey Brian Arnold <jbarnold@mit.edu>.
140 This is free software and documentation. You can redistribute and/or modify it
141 under the terms of the GNU General Public License, version 2.
143 =cut