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
22 use lib
'KSPLICE_DATA_DIR';
25 my ($help, $wantversion, $debug) = (0, 0, 0);
26 GetOptions
("help|?" => \
$help,
27 "version" => \
$wantversion,
28 "verbose|v:+" => \
$Verbose::level
,
29 "debug" => \
$debug) or pod2usage
(1);
35 pod2usage
(1) if($help || scalar(@ARGV) != 1);
37 my $file = abs_path
($ARGV[0]);
39 my $tmpdir = tempdir
('ksplice-tmp-XXXXXX', TMPDIR
=> 1, CLEANUP
=> 1);
41 my $ksplice = unpack_update
($file);
44 my $nounload = runstr
("lsmod") =~ m/- $/m;
46 (my $kid = $ksplice) =~s
|ksplice
[-_
]([^-_
]+)|$1|;
47 my $update = "ksplice_$kid";
48 if(update_loaded
($kid)) {
49 my $stage = get_stage
($kid);
50 if ($stage eq "applied") {
51 print STDERR
"Ksplice update $kid already applied.\n";
54 die "Reversed Ksplice module $update already loaded!" if ($stage eq "reversed");
57 runstr_err
(qw(modprobe -q ksplice)) eq "" || die;
58 if (-e
"ksplice-$kid.ko") {
59 if (runstr
("lsmod") =~ m/^ksplice_$kid\s+/) {
60 die "Ksplice core module ksplice_$kid already loaded.";
62 if (!load_module
("ksplice-$kid.ko", "debug=$debug")) {
63 die "Error loading Ksplice core for update $kid";
67 foreach my $helper (glob('ksplice-*-helper.ko')) {
68 (my $primary = $helper) =~ s/\-helper\.ko$/.ko/;
69 die unless(-e
$primary && -e
$helper);
70 (my $target = $primary) =~ s/^ksplice-[^_]+_(.*)\.ko/$1/;
71 if ($target ne 'vmlinux' && runstr
("lsmod") !~ m/^${target}\s/m) {
73 die "Module $target to be patched not loaded";
76 foreach my $helper (glob('ksplice-*-helper.ko')) {
77 (my $primary = $helper) =~ s/\-helper\.ko$/.ko/;
78 if(!load_module
($primary)) {
79 die "Error loading primary module $primary";
81 if(!load_module
($helper)) {
82 my ($debugfile, $debugout) = get_debug_output
("init_$kid");
83 print STDERR
"Error loading helper module $helper\n";
84 (my $module = $primary) =~ s/-/_/g;
87 if(defined $debugfile) {
89 print("Debugging output saved to $debugfile\n");
95 set_debug_level
($kid, $debug);
96 set_stage
($kid, "applied");
97 my $stage = get_stage
($kid);
98 if($stage ne 'applied') {
99 my ($debugfile, $debugout) = get_debug_output
($kid);
100 my $abort_cause = get_abort_cause
($kid);
101 my $conflicts = get_conflicts
($kid);
103 print STDERR
"Error applying Ksplice update $kid:\n";
105 print_error
($abort_cause);
106 if ($abort_cause eq 'code_busy') {
109 print("Debugging output saved to $debugfile\n");
112 mkpath
("/var/run/ksplice/updates/$kid");
113 copy
("patch", "/var/run/ksplice/updates/$kid/patch");
114 foreach my $helper (glob('ksplice-*-helper.ko')) {
116 $helper =~ s/\.ko$//;
117 runval
('rmmod', $helper) if(!$nounload);
122 my @modules_loaded = qw();
125 my ($module, @params) = @_;
126 if (runval_raw
("insmod", $module, @params) != 0) {
132 push @modules_loaded, $module;
136 sub cleanup_modules
{
137 foreach my $module (reverse(@modules_loaded)) {
138 runval
("rmmod", $module) if(!$nounload);
145 "no_match" => <<'END',
146 Ksplice has aborted the upgrade because Ksplice has been unable to match the
147 object code produced by your current compiler and assembler against the running
148 kernel's object code. If you provided the exact kernel source to the running
149 kernel, then it appears that your current compiler and/or assembler are
150 behaving differently from the compiler and assembler used to build the running
151 kernel. If possible, please use the exact compiler and assembler that were
152 used to build the running kernel. If you are using exactly the same compiler
153 and assembler, consider reporting a bug to PACKAGE_BUGREPORT.
155 "code_busy" => <<'END',
156 Ksplice has aborted the upgrade because it appears that the code that you are
157 trying to patch is continuously in use by the system. More specifically,
158 Ksplice has been unable to find a moment when one or more of the to-be-patched
159 functions is not on a thread's kernel stack.
161 "bad_system_map" => <<'END',
162 Ksplice has aborted the upgrade because it appears that the System.map file
163 provided to ksplice-create does not match the running kernel.
165 "failed_to_find" => <<'END',
166 Ksplice has aborted the upgrade because it was unable to resolve some of the
167 symbols used in the update.
169 "already_reversed" => <<'END',
170 The Ksplice update that you are attempting to apply has already been applied
171 and reversed. You need to unload the Ksplice modules associated with this
172 update before you can apply this update again.
174 "missing_export" => <<'END',
175 Ksplice has aborted the upgrade because the symbols exported by the kernel
176 did not match Ksplice's expectations.
178 "unexpected_running_task" => <<'END',
179 Ksplice has aborted the upgrade because of an unexpected failure during the
180 kernel stack check. Please consider reporting a bug to PACKAGE_BUGREPORT.
182 "out_of_memory" => <<'END',
183 Ksplice has aborted the upgrade because the kernel ran out of memory.
185 "unexpected" => <<'END',
186 Ksplice has aborted because of an unexpected error.
187 Please consider reporting a bug to PACKAGE_BUGREPORT.
189 "UNKNOWN" => <<'END',
190 The Ksplice kernel component has returned an error code that this version of
191 ksplice-apply does not understand.
194 Ksplice has aborted the upgrade for unknown reasons.
195 Please consider reporting a bug to PACKAGE_BUGREPORT.
198 $error = "UNKNOWN" if (!exists $errors{$error});
199 print STDERR
"\n$errors{$error}\n";
204 ksplice-apply - Apply an on-disk Ksplice update to the running kernel
208 B<ksplice-apply> I<UPDATE_TARBALL>
212 B<ksplice-apply> takes as input a Ksplice update tarball, as generated by
213 L<ksplice-create(8)>, and it applies the update to the running binary kernel.
215 The update tarball used with B<ksplice-apply> must have been generated for the
216 running kernel's version.
224 Applies the update with debugging output enabled. Recommended only for
231 L<ksplice-create(8)>, L<ksplice-view(8)>, L<ksplice-undo(8)>
235 Copyright (C) 2007-2008 Jeffrey Brian Arnold <jbarnold@mit.edu>
236 Copyright (C) 2008 Anders Kaseorg <andersk@mit.edu>,
237 Tim Abbott <tabbott@mit.edu>
239 This is free software and documentation. You can redistribute and/or modify it
240 under the terms of the GNU General Public License, version 2.