Change applied flag to a three-state enum.
[ksplice.git] / ksplice-apply.in
bloba432f96acb0ea51f219a8b34b0410ee052ea8814
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;
26 my ($help, $wantversion, $debug) = (0, 0, 0);
27 GetOptions("help|?" => \$help,
28 "version" => \$wantversion,
29 "verbose|v!" => \$verbose,
30 "debug=i" => \$debug) or pod2usage(1);
32 if($wantversion) {
33 print $version_str;
34 exit(0);
36 pod2usage(1) if($help || scalar(@ARGV) != 1);
38 my $file = abs_path($ARGV[0]);
40 my $tmpdir = init_tmpdir();
41 runcd($tmpdir);
42 runval("cp $file .");
43 my $ksplice = unpack_update($file);
45 if(runval_raw("insmod $ksplice/$ksplice.ko debug=$debug") != 0) {
46 die;
48 if(runval_raw("insmod $ksplice/$ksplice-helper.ko debug=$debug") != 0) {
49 runval_raw("rmmod $ksplice");
50 my $dmesg = runstr("dmesg | grep ksplice");
51 while($dmesg =~ /ksplice_h: Preparing and checking/) {
52 $dmesg = $';
55 my $bugreport = 'PACKAGE_BUGREPORT';
56 if($dmesg =~ /could not match some sections/) {
57 print <<END
59 Ksplice has aborted the upgrade because Ksplice has been unable to match the
60 object code produced by your current compiler and assembler against the running
61 kernel's object code. If you provided the exact kernel source to the running
62 kernel, then it appears that your current compiler and/or assembler are
63 behaving differently from the compiler and assembler used to build the running
64 kernel. If possible, please use the exact compiler and assembler that were
65 used to build the running kernel. If you are using exactly the same compiler
66 and assembler, feel free to report a bug to $bugreport.
68 END
70 if($dmesg =~ /to-be-replaced code is busy/) {
71 print <<END
73 Ksplice has aborted the upgrade because it appears that the code that you are
74 trying to patch is continuously in use by the system. More specifically,
75 Ksplice has been unable to find a moment when one or more of the to-be-patched
76 functions is not on a thread's kernel stack.
78 END
80 if($dmesg =~ /System[.]map does not match kernel/) {
81 print <<END
83 Ksplice has aborted the upgrade because it appears that the System.map file
84 provided to ksplice-create does not match the running kernel.
86 END
89 die;
91 if(runval_raw("rmmod $ksplice-helper") != 0) {
92 die;
95 runval("rm -rf $tmpdir");
96 print "Done!\n";
97 exit(0);
99 =head1 NAME
101 ksplice-apply - Apply an on-disk Ksplice update to the running kernel
103 =head1 SYNOPSIS
105 B<ksplice-apply> I<UPDATE_TARBALL>
107 =head1 DESCRIPTION
109 B<ksplice-apply> takes as input a Ksplice update tarball, as generated by
110 L<ksplice-create(8)>, and it applies the update to the running binary kernel.
112 Specifically, B<ksplice-apply> does the following:
114 =over
116 =item 1.
118 Inserts the "primary" module into the kernel.
120 =item 2.
122 Inserts the "helper" module into the kernel (doing so applies the
123 update).
125 =item 3.
127 Removes the "helper" module from the kernel (that module is not needed
128 after the update has been applied).
130 =back
132 The update tarball used with B<ksplice-apply> must have been generated for the
133 running kernel's version.
135 =head1 OPTIONS
137 =over 8
139 =item B<--debug=>I<DEBUG_LEVEL>
141 Applies the update with debugging output enabled. Recommended only for
142 debugging. I<DEBUG_LEVEL> should be an integer between 0 and 4. B<--debug=4>
143 provides the most debugging information.
145 =over
147 =item Z<> B<0>
149 No debugging output.
151 =item Z<> B<1>
153 Provides basic (pre-run matching and kernel stack check) debugging output.
155 =item Z<> B<2>
157 Also provides full kernel stack check debugging output.
159 =item Z<> B<3>
161 Also provides full pre-run matching debugging output.
163 =item Z<> B<4>
165 Also provides full Ksplice relocation debugging output.
167 =back
169 =back
171 =head1 SEE ALSO
173 L<ksplice-create(8)>, L<ksplice-view(8)>, L<ksplice-undo(8)>
175 =head1 COPYRIGHT
177 Copyright (C) 2008 Jeffrey Brian Arnold <jbarnold@mit.edu>.
179 This is free software and documentation. You can redistribute and/or modify it
180 under the terms of the GNU General Public License, version 2.
182 =cut