Commit Graph

323 Commits

Author SHA1 Message Date
Maksym Pavlenko
3db1c8059d agent: Don't leak fd when reseeding rng
This PR wraps fd raw descriptor with File, so it'll be properly closed once exited.

Fixes: #1192

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2020-12-11 16:18:41 -08:00
Peng Tao
e167bf30e3 Merge pull request #1165 from liubin/fix/exec-hang-when-bg-process-running
agent: exit from exec hangs if background process is present
2020-12-08 20:32:23 +08:00
bin liu
1ca415d87e agent: exit from exec hangs if background process is present
This is the Rust porting of https://github.com/kata-containers/agent/pull/371

`read_stdout`/`read_stderr` is blocking rpc calls, if exec process
exited, these calls is on blocking state for reading on process's
term master fd, and can't get a chance to break the wait.

In this PR, `read_stdout`/`read_stderr` will not read directly from
a term master of a process, instead, it will first have to get
an fd to read from newly added `epoller.poll()`. `epoller.poll()` may returns:

- the term master fd of exec process, if the process is running.
- a fd(piped fd) will return EOF when reading to indicate that th process is exited.

Fixes: #1160

Signed-off-by: bin liu <bin@hyper.sh>
2020-12-07 10:52:44 +08:00
Peng Tao
4bca7312c7 Merge pull request #1158 from liubin/fix/1156-fix-cpuset
handle vcpus properly utilized in the guest
2020-12-04 22:32:15 +08:00
Archana Shinde
f96cdc1a67 Merge pull request #1114 from c3d/bug/1111-agent-oom-killer
agent: Adjust OOM Score to avoid agent being killed.
2020-12-02 11:40:35 -08:00
bin liu
a793b8d90d agent: update cpuset of container path
After cpu hot-plugged is available, cpuset for containers will be written into
cgroup files recursively, the paths should include container's cgroup path, and up
to root path of cgroup filesystem.

Fixes: #1156, #1159

Signed-off-by: bin liu <bin@hyper.sh>
2020-12-02 10:38:26 +08:00
bin liu
705182d04e agent: ignore updating cpuset error when update cgroups
The result of `cpuset_controller.set_cpus(&cpu.cpus)` is unwrapped,
this will lead creating container to fail if cpuset is set.

The sandbox's `CreateContainer` sequence is:

c, err := newContainer(s, &contConfig)
err = c.create()
  c.sandbox.agent.createContainer(c.sandbox, c) (1)
err = s.updateResources()
  oldCPUs, newCPUs, err := s.hypervisor.resizeVCPUs(sandboxVCPUs) (2)

cpuset only avaiable after `s.hypervisor.resizeVCPUs` has been called at (2),
and then cpuset is written to cgourps file.

Fixes: #1159

Signed-off-by: bin liu <bin@hyper.sh>
2020-12-02 10:38:16 +08:00
Bin Liu
b8716d8eec Merge pull request #1141 from lifupan/fix_thread_spwan
rustjail: fork a new child process to change the pid ns
2020-11-25 15:20:36 +08:00
fupan.lfp
9216f2ad63 rustjail: fork a new child process to change the pid ns
The main process do unshare pid namespace, the process
couldn't spawn new thread, in order to avoid this issue,
fork a new child process and do the pid namespace unshare
in the new temporary process.

Fixes: #1140

Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
2020-11-23 17:57:33 +08:00
fupan.lfp
3b08376c4e rustjail: remove the network ns validation against container
Since kata containers shared the network ns with
the guest system, thus there's no need to do the
network ns check.

Fixes: #1047

Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
2020-11-23 14:41:22 +08:00
Julio Montes
f00655a40f Merge pull request #1060 from jongwu/rootbus
agent: create pci root Bus Path for arm64
2020-11-18 08:13:30 -06:00
bin liu
d6acc4c09c agent: enable lto flag for Cargo to get better optimized code
The lto setting controls the -C lto flag which controls LLVM's link time optimizations.
LTO can produce better optimized code, using whole-program analysis,
at the cost of longer linking time.

https://doc.rust-lang.org/cargo/reference/profiles.html#lto

Fixes: #1125

Signed-off-by: bin liu <bin@hyper.sh>
2020-11-18 15:50:27 +08:00
Christophe de Dinechin
53b5d063e9 agent: Adjust OOM Score to avoid agent being killed.
Under stress, the agent can be OOM-killed, which exists the sandbox.
One possible hard-to-diagnose manifestation is a virtiofsd crash.

Fixes: #1111

Reported-by: Qian Cai <caiqian@redhat.com>
Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
2020-11-13 11:10:19 +01:00
Peng Tao
9dbd1007d7 Merge pull request #1070 from jing-wang4/readme
Agent: README updates for build on ppc64le
2020-11-11 10:15:22 +08:00
James O. D. Hunt
8907a33907 agent: Only show ttrpc logs for trace log level
Only display the `ttrpc` crate log output when full logging
(trace level) is enabled.

This is a slight abuse of log levels but provides developers and testers
what they need whilst also keeping the logs relatively quiet for the
default info log level (the `ttrpc` crate logging is a bit "chatty").

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
2020-11-06 10:45:05 +00:00
James O. D. Hunt
21cd7ad172 agent: Log ttrpc messages
The `ttrpc` crate uses the `log` crate for logging. But the agent uses
the `slog` crate. This means that currently, all `ttrpc` log messages
are being discarded.

Use the `slog-stdlog` create to redirect `log` crate logging calls into
`slog` so they are visible in the agents log output.

Fixes: #978.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
2020-11-06 10:05:02 +00:00
James O. D. Hunt
286eebf087 agent: Add env var to set log level
Add support for a `KATA_AGENT_LOG_LEVEL` environment variable for testing.
This is the equivalent to the `agent.log=` kernel command line option.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
2020-11-06 10:05:02 +00:00
James O. D. Hunt
b9c6db4bb8 agent: Add env var tests
Add some tests for the existing `KATA_AGENT_SERVER_ADDR` environment
variable feature.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
2020-11-06 10:05:02 +00:00
James O. D. Hunt
705e995589 agent: Add env var comment
Add a comment stating what the server address environment variable is
for.

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
2020-11-06 10:05:02 +00:00
Jianyong Wu
6c2fc233e2 agent: create pci root Bus Path for arm64
port https://github.com/kata-containers/agent/pull/860 here.

Fixes: #1059
Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
2020-11-05 12:18:09 +08:00
Jing Wang
18a2245986 Agent: README updates for build on ppc64le
README updates for agent build on ppc64le

  Fixes: #1069

Signed-off-by: Jing Wang <jing.wang4@ibm.com>
2020-11-03 15:29:43 +00:00
Jing Wang
655f2649b3 Agent: README updates for build on ppc64le
README updates for agent build on ppc64le

  Fixes: #1069

Signed-off-by: Jing Wang <jing.wang4@ibm.com>
2020-11-03 15:24:08 +00:00
Jing Wang
dfe364f885 Agent: README updates for build on ppc64le
README updates for agent build on ppc64le

Fixes: #1069

Signed-off-by: Jing Wang <jing.wang4@ibm.com>
2020-11-02 20:26:36 +00:00
Bin Liu
8823ca31ad Merge pull request #1042 from devimc/2020-10-21/unitests/sandbox.rs
agent: Improve unit test coverage for src/sandbox.rs
2020-10-30 11:26:29 +08:00
Bin Liu
7b9013f047 Merge pull request #1035 from lifupan/fix_thread_panic
rustjail: fix the issue of create thread failed causing current thread panic
2020-10-30 11:25:32 +08:00
Julio Montes
196e8d81cf Merge pull request #1032 from devimc/2020-10-21/unitests/container.rs
Improve unit test coverage for rustjail/container.rs
2020-10-28 16:08:23 -06:00
Julio Montes
2e1a8f0ae9 agent: Improve unit test coverage for src/sandbox.rs
Improve unit test coverage for src/sandbox.rs

fixes #293

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-10-28 08:10:46 -06:00
fupan.lfp
172d015e1b rustjail: fix the issue of create thread failed causing thread panic
It's should catch the failed error of spawning a new thread, otherwise,
it would cause the current thread panic.

Fixes: #1034

Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
2020-10-27 23:31:34 +08:00
Julio Montes
9e93463bb6 agent/rustjail: improve unit test coverage for rustjail/container.rs
Improve unit test coverage for rustjail/container.rs

fixes #282

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-10-27 09:28:38 -06:00
Julio Montes
ad4f7b86f2 agent/rustjail: make mount and umount2 public
make mount and umount2 public, this way they can be
used in other files

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-10-27 09:28:38 -06:00
Julio Montes
926a618624 agent/rustjail: fix typo
not suppoerted  ->  not supported

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-10-27 09:28:38 -06:00
Julio Montes
8130d9b2dd agent/rustjail: don't use unwrap in container::oci_state
replace unwrap with `match` statements, this way we can write
unit tests that don't panic

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-10-27 09:28:38 -06:00
Julio Montes
5d111071be rustjail: add mock implementation for cgroup manager
Only root is able to create and manipulate cgroups, this mock
implementation of a cgroup manager can used in unit testing.

Signed-off-by: Julio Montes <julio.montes@intel.com>
2020-10-27 09:28:38 -06:00
James O. D. Hunt
157dd041b2 Merge pull request #895 from Apokleos/dev
agent: Update build instructions
2020-10-27 14:54:51 +00:00
LiYa'nan
e3eff0eb15 agent: Update build instructions
Fix the instructions explaining how to build the agent from source now that make needs to be run to auto-generate some source files.

Fixes: #889.

Signed-off-by: LiYa'nan <oliverliyn@gmail.com>
2020-10-27 01:19:21 +00:00
Peng Tao
0896ce80a4 agent: update proto file copyright
Now that it is Ant Group...

Signed-off-by: Peng Tao <bergwolf@hyper.sh>
2020-10-26 16:03:47 +08:00
Peng Tao
6e9ca45732 agent: generate proto files properly
Need to generate all protos.

Depends-on: github.com/kata-containers/tests#3006
Signed-off-by: Peng Tao <bergwolf@hyper.sh>
2020-10-25 11:27:00 +08:00
Peng Tao
54e23c8302 agent: move gogo.proto out of the github.com namespance
To follow the same namespace scope as other proto files.

Signed-off-by: Peng Tao <bergwolf@hyper.sh>
2020-10-25 10:44:53 +08:00
Peng Tao
74a155c65b Merge pull request #1023 from lifupan/fix_stdio
agent: fixes the permissions of PID 1's STDIO
2020-10-25 10:21:11 +08:00
Peng Tao
fba181088b Merge pull request #1021 from Tim-Zhang/autogen-proto
agent: Generate proto files programmatically
2020-10-24 11:12:24 +08:00
LiYa'nan
f134b4a301 agent: Update build instructions
Fix the instructions explaining how to build the agent from source now that make needs to be run to auto-generate some source files.

Fixes: #889

Signed-off-by: LiYa'nan <oliverliyn@gmail.com>
2020-10-24 03:06:41 +00:00
Tim Zhang
9e9988df29 agent/protocols: Move agent.proto out of the mock folder of agent
Because the repos have been merged and the agent repo will be removed in the future,
we do not need mock the file structure any more.

Signed-off-by: Tim Zhang <tim@hyper.sh>
2020-10-23 15:19:35 +08:00
fupan.lfp
e90aa7b417 agent: fixes the permissions of PID 1's STDIO
Fix the permissions of PID 1's STDIO within the container to
the specified user.

The ownership needs to match because it is created outside of the
container and needs to be localized.

Fixes: #1022

Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
2020-10-23 11:06:53 +08:00
Tim Zhang
9cb4150777 agent/protocols: Fix copyright header checking
Caused by: bb718ba1dd

Signed-off-by: Tim Zhang <tim@hyper.sh>
2020-10-22 16:17:24 +08:00
Tim Zhang
0d58d91959 agent/protocols: Stop generate agent proto files in the shellscript
Because the job has been done by build.rs.

Signed-off-by: Tim Zhang <tim@hyper.sh>
2020-10-22 16:12:21 +08:00
Tim Zhang
7559382b15 agent/protocols: Ignore generated files and remove these files from repo
Files generated by build.rs does not need to be stored in repo.

Signed-off-by: Tim Zhang <tim@hyper.sh>
2020-10-22 16:12:21 +08:00
Tim Zhang
fdc33fb7bf agent/protocols: Generate proto files programmatically
Build proto with build.rs

Fixes: #1019

Signed-off-by: Tim Zhang <tim@hyper.sh>
2020-10-22 16:12:15 +08:00
bin liu
df4ce9fab7 ci: add cargo clippy for agent
To run `cargo clippy`, this commit includes changes:

- add a new Makefile target to run `cargo clippy`
- move `make`/`make check` to last step to let a fast retrun if `fmt`/`clippy` failed

Fixes: #951

Signed-off-by: bin liu <bin@hyper.sh>
2020-10-21 15:14:17 +08:00
bin liu
2e13878880 agent: clear match_like_matches_macro/vec_resize_to_zero warnings
This commit fix these warnings for Rust v1.47.0:

- match_like_matches_macro
- vec_resize_to_zero

Signed-off-by: bin liu <bin@hyper.sh>
2020-10-21 15:13:25 +08:00
bin liu
227edfdc9f agent: clear module_inception/type_complexity warnings
To clear these two warnings, this commit did changes:

- add `#![allow(clippy::module_inception)]` to target files
- use type alias for tuple of `(MessageHeader, Vec<u8>)`

Signed-off-by: bin liu <bin@hyper.sh>
2020-10-21 15:03:16 +08:00