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';
27 GetOptions
(@common_options,
28 "partial" => \
$partial,
29 "debug" => \
$debug) or pod2usage
(1);
31 pod2usage
(1) if($help || scalar(@ARGV) != 1);
33 my $file = abs_path
($ARGV[0]);
35 my $tmpdir = tempdir
('ksplice-tmp-XXXXXX', TMPDIR
=> 1, CLEANUP
=> 1);
37 my $ksplice = unpack_update
($file);
40 die "No contents file in $file\n" if (!-e
"contents");
41 open(CONTENTS
, '<', "contents");
44 my @line = split(' ', $_);
45 if ($line[0] eq 'core') {
46 die "Multiple core modules in $file!" if (defined $core);
55 my $nounload = runstr
("lsmod") =~ m/- $/m;
57 (my $kid = $ksplice) =~s
|ksplice
[-_
]([^-_
]+)|$1|;
58 my $update = "ksplice_$kid";
59 if(update_loaded
($kid)) {
60 my $stage = get_stage
($kid);
61 if ($stage eq "applied") {
62 print STDERR
"Ksplice update $kid already applied.\n";
65 die "Reversed Ksplice module $update already loaded!" if ($stage eq "reversed");
68 runstr_err
(qw(modprobe -q ksplice)) eq "" || die;
70 die "Could not find Ksplice core module $core->{file}\n" if (!-e
$core->{file
});
71 if (runstr
("lsmod") =~ m/^\Q$core->{module}\E\s+/) {
72 die "Ksplice core module $core already loaded.";
74 if (!load_module
($core->{file
}, "debug=$debug")) {
75 die "Error loading Ksplice core module $core->{module} for update $kid";
80 foreach my $helper (glob('ksplice-*-helper.ko')) {
81 (my $primary = $helper) =~ s/\-helper\.ko$/.ko/;
82 die unless(-e
$primary && -e
$helper);
83 (my $target = $primary) =~ s/^ksplice-[^_]+_(.*)\.ko/$1/;
84 if ($target ne 'vmlinux' && runstr
("lsmod") !~ m/^${target}\s/m) {
87 print_error
("target_not_loaded");
88 die "Module $target to be patched not loaded";
91 push @helpers, $helper;
93 foreach my $helper (@helpers) {
94 (my $primary = $helper) =~ s/\-helper\.ko$/.ko/;
95 if(!load_module
($primary)) {
96 die "Error loading primary module $primary";
98 if(!load_module
($helper)) {
99 my ($debugfile, $debugout) = get_debug_output
("init_$kid");
100 print STDERR
"Error loading helper module $helper\n";
101 (my $module = $primary) =~ s/-/_/g;
104 if($debug && defined $debugfile) {
106 print("Debugging output saved to $debugfile\n");
112 set_debug_level
($kid, $debug);
113 set_partial
($kid, $partial);
114 set_stage
($kid, "applied");
115 my $stage = get_stage
($kid);
116 if($stage ne 'applied') {
117 my ($debugfile, $debugout) = get_debug_output
($kid);
118 my $abort_cause = get_abort_cause
($kid);
119 my $conflicts = get_conflicts
($kid);
121 print STDERR
"Error applying Ksplice update $kid:\n";
122 print $debugout if (defined $debugfile);
123 print_error
($abort_cause);
124 if ($abort_cause eq 'code_busy') {
127 if ($debug && defined $debugfile) {
128 print("Debugging output saved to $debugfile\n");
132 mkpath
("/var/run/ksplice/updates/$kid");
133 copy
("patch", "/var/run/ksplice/updates/$kid/patch") if (-e
"patch");
134 copy
("description", "/var/run/ksplice/updates/$kid/description") if (-e
"description");
136 foreach my $helper (@helpers) {
138 $helper =~ s/\.ko$//;
139 (my $primary = $helper) =~ s/_helper$//;
140 runval
('rmmod', $helper);
141 runval
('rmmod', $primary) if ($partial && refcount
($primary) == 0);
147 my @modules_loaded = qw();
150 my ($module, @params) = @_;
151 if (runval_raw
("insmod", $module, @params) != 0) {
157 push @modules_loaded, $module;
163 foreach(split(/\n/, runstr
("lsmod"))) {
164 if (m/^(\S+)\s+[0-9]+\s+([0-9])+\s/) {
165 return $2 if ($1 eq $module);
171 sub cleanup_modules
{
172 foreach my $module (reverse(@modules_loaded)) {
173 runval
("rmmod", $module) if(!$nounload);
180 "no_match" => <<'END',
181 Ksplice has aborted the upgrade because Ksplice has been unable to match the
182 object code produced by your current compiler and assembler against the running
183 kernel's object code. If you provided the exact kernel source to the running
184 kernel, then it appears that your current compiler and/or assembler are
185 behaving differently from the compiler and assembler used to build the running
186 kernel. If possible, please use the exact compiler and assembler that were
187 used to build the running kernel. If you are using exactly the same compiler
188 and assembler, consider reporting a bug to PACKAGE_BUGREPORT.
190 "code_busy" => <<'END',
191 Ksplice has aborted the upgrade because it appears that the code that you are
192 trying to patch is continuously in use by the system. More specifically,
193 Ksplice has been unable to find a moment when one or more of the to-be-patched
194 functions is not on a thread's kernel stack.
196 "bad_system_map" => <<'END',
197 Ksplice has aborted the upgrade because it appears that the System.map file
198 provided to ksplice-create does not match the running kernel.
200 "failed_to_find" => <<'END',
201 Ksplice has aborted the upgrade because it was unable to resolve some of the
202 symbols used in the update.
204 "already_reversed" => <<'END',
205 The Ksplice update that you are attempting to apply has already been applied
206 and reversed. You need to unload the Ksplice modules associated with this
207 update before you can apply this update again.
209 "missing_export" => <<'END',
210 Ksplice has aborted the upgrade because the symbols exported by the kernel
211 did not match Ksplice's expectations.
213 "unexpected_running_task" => <<'END',
214 Ksplice has aborted the upgrade because of an unexpected failure during the
215 kernel stack check. Please consider reporting a bug to PACKAGE_BUGREPORT.
217 "target_not_loaded" => <<'END',
218 Ksplice has aborted the upgrade because one of the modules to be
219 patched by the update was not loaded. If you want to apply this
220 update only to those modules that are loaded, then you should use the
223 "out_of_memory" => <<'END',
224 Ksplice has aborted the upgrade because the kernel ran out of memory.
226 "call_failed" => <<'END',
227 Ksplice has aborted the upgrade at the request of a one of the
228 pre-application hooks that were included as part of this Ksplice
229 update. This is likely the result of a bug in the patch used to
230 generate this update.
232 "unexpected" => <<'END',
233 Ksplice has aborted because of an unexpected error.
234 Please consider reporting a bug to PACKAGE_BUGREPORT.
236 "UNKNOWN" => <<'END',
237 The Ksplice kernel component has returned an error code that this version of
238 ksplice-apply does not understand.
241 Ksplice has aborted the upgrade for unknown reasons.
242 Please consider reporting a bug to PACKAGE_BUGREPORT.
245 $error = "UNKNOWN" if (!exists $errors{$error});
246 print STDERR
"\n$errors{$error}\n";
251 ksplice-apply - Apply an on-disk Ksplice update to the running kernel
255 B<ksplice-apply> I<UPDATE_TARBALL>
259 B<ksplice-apply> takes as input a Ksplice update tarball, as generated by
260 L<ksplice-create(8)>, and it applies the update to the running binary kernel.
262 The update tarball used with B<ksplice-apply> must have been generated for the
263 running kernel's version.
271 Applies the update with debugging output enabled. Recommended only for
276 Applies the update only to those modules which are loaded. Any
277 modules patched by the update that are not loaded are ignored (without
278 this option, Ksplice aborts if any modules patched by the update are
285 L<ksplice-create(8)>, L<ksplice-view(8)>, L<ksplice-undo(8)>
289 Please report bugs to <PACKAGE_BUGREPORT>.
293 Copyright (C) 2007-2008 Jeffrey Brian Arnold <jbarnold@mit.edu>
295 Copyright (C) 2008 Anders Kaseorg <andersk@mit.edu>,
296 Tim Abbott <tabbott@mit.edu>
298 This is free software and documentation. You can redistribute and/or modify it
299 under the terms of the GNU General Public License, version 2.