2019-09-30 10:53:48 -04:00
|
|
|
// Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
|
2020-04-27 14:37:46 +08:00
|
|
|
// lxcfs-tools is licensed under the Mulan PSL v2.
|
|
|
|
|
// You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
|
|
|
// You may obtain a copy of Mulan PSL v2 at:
|
|
|
|
|
// http://license.coscl.org.cn/MulanPSL2
|
2019-09-30 10:53:48 -04:00
|
|
|
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
|
|
|
// PURPOSE.
|
2020-04-27 14:37:46 +08:00
|
|
|
// See the Mulan PSL v2 for more details.
|
2019-09-30 10:53:48 -04:00
|
|
|
// Description: mount/umount in container namespace
|
|
|
|
|
// Author: zhangsong
|
|
|
|
|
// Create: 2019-05-31
|
|
|
|
|
|
|
|
|
|
package libmount
|
|
|
|
|
|
|
|
|
|
import (
|
2020-01-21 17:14:32 +08:00
|
|
|
"lxcfs-tools/libmount/nsexec"
|
2019-09-30 10:53:48 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// NsExecMount exec mount in container namespace
|
2019-12-25 16:01:46 +08:00
|
|
|
func NsExecMount(pid string, rootfs string, srcPaths []string, destPaths []string) error {
|
2019-09-30 10:53:48 -04:00
|
|
|
driver := nsexec.NewDefaultNsDriver()
|
2019-12-25 16:01:46 +08:00
|
|
|
mount := &nsexec.Mount{
|
|
|
|
|
Rootfs: rootfs,
|
|
|
|
|
}
|
2019-09-30 10:53:48 -04:00
|
|
|
for i := 0; i < len(srcPaths) && i < len(destPaths); i++ {
|
|
|
|
|
mount.SrcPaths = append(mount.SrcPaths, srcPaths[i])
|
|
|
|
|
mount.DestPaths = append(mount.DestPaths, destPaths[i])
|
|
|
|
|
}
|
|
|
|
|
return driver.Mount(pid, mount)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NsExecUmount exec umount in container namespace
|
|
|
|
|
func NsExecUmount(pid string, paths []string) error {
|
|
|
|
|
driver := nsexec.NewDefaultNsDriver()
|
|
|
|
|
umount := &nsexec.Umount{}
|
|
|
|
|
for i := 0; i < len(paths); i++ {
|
|
|
|
|
umount.Paths = append(umount.Paths, paths[i])
|
|
|
|
|
}
|
|
|
|
|
return driver.Umount(pid, umount)
|
|
|
|
|
}
|