Hi Montes,
As the issue described, Golang `setns` won't work with mount namespace, if you want to setns to a mount namespace, I think `cgo` should be a good way(at least I don't know a better one:-) )
Another way to put shim or qemu inside a new mount ns in Golang code is that you can set `Cmd.SysProcAttr.Cloneflags=syscall.CLONE_NEWNS` for the `shim` and `qemu` command, a quick example:
``` package main
import ( "fmt" "os/exec" "syscall" )
func main() { cmd := exec.Cmd{ Path: "/bin/sleep", Args: []string{"sleep", "300"}, Dir: "/", SysProcAttr: &syscall.SysProcAttr{ Cloneflags: syscall.CLONE_NEWNET | syscall.CLONE_NEWNS, }, }
out, err := cmd.CombinedOutput() if err != nil { fmt.Printf("error: %#v\n", err) return } fmt.Printf("output: %s\n", out) } ```
You can see the `sleep 300` process has a standalone mount ns after the programe started and hung, replace the "sleep" with `qemu`, I think it would work.
Hope this can help :-)
-Wei
-----邮件原件----- 发件人: Montes, Julio [mailto:julio.montes@intel.com] 发送时间: 2018年9月28日 1:28 收件人: kata-dev@lists.katacontainers.io 主题: [kata-dev] Namespaces in the host
Hi All
Currently Kata Containers only supports network namespaces in the host, other namespaces are not supported. This week I started to work on this but I faced some issues with the mount namespace in Go, the main issue is that a multithread process can't be reassociated with a new mount namespace [1] as it's reported here [2]. A solution for this might be to write a new binary in C to create and join namespaces and start the kata components (shim, qemu, etc) inside it, also this binary would be used to clean up (unmount, etc) the containers. Another solution might be to use a C constructor in Go (cgo) to create and join the namespace, but that means kata-runtime will run inside the namespace.
If you are already working on this or know how to deal with this issue, please let me know. In the meantime I'll try to figure out how.
Thank you!
-- Julio
[1] - http://man7.org/linux/man-pages/man2/setns.2.html [2] - https://github.com/golang/go/issues/8676 _______________________________________________ kata-dev mailing list kata-dev@lists.katacontainers.io http://lists.katacontainers.io/cgi-bin/mailman/listinfo/kata-dev