Skip to content

Commit 7c1877d

Browse files
committed
Add a lot of logs for NS creation process
These logs make NS creation process more visible and allow to easyly debug problems in it. Log to STDERR only for now to simplify code. Signed-off-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
1 parent 0c13991 commit 7c1877d

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

bin/ns_unshared

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module AutoHCK
1616
'/proc/sys/net/bridge/bridge-nf-call-ip6tables',
1717
'/proc/sys/net/bridge/bridge-nf-call-iptables'
1818
].each do |file|
19+
$stderr.write "[ns_unshared] Writing '0' to #{file}\n"
1920
File.write file, '0'
2021
rescue Errno::ENOENT
2122
# br_netfilter is not loaded
@@ -50,6 +51,7 @@ module AutoHCK
5051
%w[ip link add br_debug type bridge],
5152
%w[ip link set br_debug up]
5253
].each do |cmd|
54+
$stderr.write "[ns_unshared] Running (wait spawn): #{cmd.join(' ')}\n"
5355
Process.wait spawn(*cmd, out: :err)
5456
raise $CHILD_STATUS.to_s unless $CHILD_STATUS.success?
5557
rescue StandardError

bin/nsd

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ module AutoHCK
3333
argv << File.join(__dir__, 'ns_unshared')
3434

3535
e_read, e_write = IO.pipe
36+
$stderr.write "[nsd] Running (e pipe): #{e_read.fileno} => #{e_write.fileno}\n"
3637
r_read, r_write = IO.pipe
38+
$stderr.write "[nsd] Running (r pipe): #{r_read.fileno} => #{r_write.fileno}\n"
3739
parent = Process.pid.to_s
40+
$stderr.write "[nsd] Parent PID: #{parent}\n"
3841

3942
fork do
4043
e_write.close
@@ -60,19 +63,24 @@ module AutoHCK
6063
# Call newgidmap so that virtiofsd can use setgroups() to drop subgroups.
6164
# unshare command in util-linux 2.38 can call newgidmap by its own, but
6265
# unfortunately it is not available on some supported systems.
63-
system 'newgidmap', parent, '0', Process.gid.to_s, '1',
64-
subid_start, subid_start, subid_count, exception: true, out: :err
66+
command = ['newgidmap', parent, '0', Process.gid.to_s, '1', subid_start, subid_start, subid_count]
67+
$stderr.write "[nsd child] Running (system): #{command.join(' ')}\n"
68+
system(*command, exception: true, out: :err)
6569
end
6670

6771
e_read.close_on_exec = false
6872
r_write.close_on_exec = false
69-
exec 'slirp4netns', '-e', e_read.fileno.to_s, '-r', r_write.fileno.to_s,
70-
'-a', 'slirp.sock', parent, 'tap_host', out: :err
73+
74+
command = ['slirp4netns', '-e', e_read.fileno.to_s, '-r', r_write.fileno.to_s,
75+
'-a', 'slirp.sock', parent, 'tap_host']
76+
$stderr.write "[nsd child] Running (exec): #{command.join(' ')}\n"
77+
exec(*command, out: :err)
7178
end
7279

7380
e_read.close
7481
r_write.close
7582

83+
$stderr.write "[nsd] Running (exec, 3 => #{e_write.fileno}, 4 => #{r_read.fileno}): #{argv.join(' ')}\n"
7684
exec(*argv, 3 => e_write, 4 => r_read)
7785
end
7886
end

lib/setupmanagers/qemuhck/ns.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ def self.enter(workspace, chdir, *argv)
1818
pid = pid_file.acquire
1919
begin
2020
Thread.handle_interrupt Object => :immediate do
21-
system(*nsenter_argv(pid, chdir), '--', *argv)
22-
exit $CHILD_STATUS.exitstatus
21+
nsenter(pid, chdir, *argv)
2322
end
2423
ensure
2524
begin
@@ -42,7 +41,14 @@ def self.nsenter_argv(pid, chdir)
4241
argv
4342
end
4443

45-
private_class_method :nsenter_argv
44+
def self.nsenter(pid, chdir, *argv)
45+
command = [*nsenter_argv(pid, chdir), '--', *argv]
46+
$stderr.write "[ns.rb] Running (system): #{command.join(' ')}\n"
47+
system(*command)
48+
exit $CHILD_STATUS.exitstatus
49+
end
50+
51+
private_class_method :nsenter_argv, :nsenter
4652
end
4753
end
4854
end

lib/setupmanagers/qemuhck/qemuhck.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def run_hck_client(scope, studio, name, run_opts)
204204
end
205205

206206
def self.enter(workspace_path)
207+
$stderr.write "[qemuhck.rb] Entering namespace: #{workspace_path}\n"
207208
Ns.enter workspace_path, Dir.pwd, 'bin/auto_hck', '-w',
208209
workspace_path, *ARGV
209210
end

0 commit comments

Comments
 (0)