Create relocations with bfd_install_relocation.
[ksplice.git] / ksplice-apply.in
blob9cf73af69ffe9a24da6adff6a4bd547b113f1674
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 my $ksplice = unpack_update($file);
43 runcd($ksplice);
45 my $unload = runstr("lsmod") !~ m/- $/m;
47 foreach my $helper (glob('ksplice-*-helper.ko')) {
49 (my $primary = $helper) =~ s/\-helper\.ko$/.ko/;
50 die unless(-e $primary && -e $helper);
52 my ($kid, $target) = $primary =~ m/^ksplice-([^_]+)_(.*)\.ko/;
53 $target =~ s/-/_/;
54 if ($target ne 'vmlinux' && runstr("lsmod") !~ m/^${target}\s/m) {
55 die "Module $target to be patched not loaded";
58 if(runval_raw("insmod $primary debug=$debug") != 0) {
59 die "Error loading primary module $primary";
61 if(runval_raw("insmod $helper") != 0) {
62 runval_raw("rmmod $primary") if $unload;
63 my $dmesg = runstr("dmesg | grep ksplice");
64 while($dmesg =~ /ksplice_h: Preparing and checking/) {
65 $dmesg = $';
68 my $bugreport = 'PACKAGE_BUGREPORT';
69 if($dmesg =~ /could not match some sections/) {
70 print <<END
72 Ksplice has aborted the upgrade because Ksplice has been unable to match the
73 object code produced by your current compiler and assembler against the running
74 kernel's object code. If you provided the exact kernel source to the running
75 kernel, then it appears that your current compiler and/or assembler are
76 behaving differently from the compiler and assembler used to build the running
77 kernel. If possible, please use the exact compiler and assembler that were
78 used to build the running kernel. If you are using exactly the same compiler
79 and assembler, feel free to report a bug to $bugreport.
81 END
83 if($dmesg =~ /to-be-replaced code is busy/) {
84 print <<END
86 Ksplice has aborted the upgrade because it appears that the code that you are
87 trying to patch is continuously in use by the system. More specifically,
88 Ksplice has been unable to find a moment when one or more of the to-be-patched
89 functions is not on a thread's kernel stack.
91 END
93 if($dmesg =~ /System[.]map does not match kernel/) {
94 print <<END
96 Ksplice has aborted the upgrade because it appears that the System.map file
97 provided to ksplice-create does not match the running kernel.
99 END
102 die;
104 die if ($unload && runval_raw("rmmod $helper") != 0)
108 runval("rm -rf $tmpdir");
109 print "Done!\n";
110 exit(0);
112 =head1 NAME
114 ksplice-apply - Apply an on-disk Ksplice update to the running kernel
116 =head1 SYNOPSIS
118 B<ksplice-apply> I<UPDATE_TARBALL>
120 =head1 DESCRIPTION
122 B<ksplice-apply> takes as input a Ksplice update tarball, as generated by
123 L<ksplice-create(8)>, and it applies the update to the running binary kernel.
125 Specifically, B<ksplice-apply> does the following:
127 =over
129 =item 1.
131 Inserts the "primary" module into the kernel.
133 =item 2.
135 Inserts the "helper" module into the kernel (doing so applies the
136 update).
138 =item 3.
140 Removes the "helper" module from the kernel (that module is not needed
141 after the update has been applied).
143 =back
145 The update tarball used with B<ksplice-apply> must have been generated for the
146 running kernel's version.
148 =head1 OPTIONS
150 =over 8
152 =item B<--debug=>I<DEBUG_LEVEL>
154 Applies the update with debugging output enabled. Recommended only for
155 debugging. I<DEBUG_LEVEL> should be an integer between 0 and 4. B<--debug=4>
156 provides the most debugging information.
158 =over
160 =item Z<> B<0>
162 No debugging output.
164 =item Z<> B<1>
166 Provides basic (pre-run matching and kernel stack check) debugging output.
168 =item Z<> B<2>
170 Also provides full kernel stack check debugging output.
172 =item Z<> B<3>
174 Also provides full pre-run matching debugging output.
176 =item Z<> B<4>
178 Also provides full Ksplice relocation debugging output.
180 =back
182 =back
184 =head1 SEE ALSO
186 L<ksplice-create(8)>, L<ksplice-view(8)>, L<ksplice-undo(8)>
188 =head1 COPYRIGHT
190 Copyright (C) 2008 Jeffrey Brian Arnold <jbarnold@mit.edu>.
192 This is free software and documentation. You can redistribute and/or modify it
193 under the terms of the GNU General Public License, version 2.
195 =cut