Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
syscontainer-tools
提交
c2ba2183
S
syscontainer-tools
项目概览
openeuler
/
syscontainer-tools
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
syscontainer-tools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c2ba2183
编写于
4月 01, 2020
作者:
Z
zhangsong34
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "syscontainer-tools: internal change"
This reverts commit
b5906f1f
.
上级
a891d298
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
5 addition
and
110 deletion
+5
-110
hooks/syscontainer-hooks/prestart.go
hooks/syscontainer-hooks/prestart.go
+0
-1
libdevice/container_work.go
libdevice/container_work.go
+1
-12
libdevice/devices_unix.go
libdevice/devices_unix.go
+4
-96
types/device.go
types/device.go
+0
-1
未找到文件。
hooks/syscontainer-hooks/prestart.go
浏览文件 @
c2ba2183
...
...
@@ -96,7 +96,6 @@ func AddDevices(state *configs.HookState, hookConfig *hconfig.ContainerHookConfi
// re-calc the dest path of device.
resolvDev
:=
calcPathForDevice
(
state
.
Root
,
dev
)
device
,
err
:=
libdevice
.
ParseDevice
(
resolvDev
)
device
.
Root
=
state
.
Root
if
err
!=
nil
{
logrus
.
Errorf
(
"[device-hook] Add device (%s), parse device failed: %v"
,
resolvDev
,
err
)
return
err
...
...
libdevice/container_work.go
浏览文件 @
c2ba2183
...
...
@@ -237,12 +237,6 @@ func doAddDevice(pipe *os.File) error {
if
err
:=
MknodDevice
(
device
.
Path
,
device
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Current OS kernel do not support mknod in container user namespace for root, err: %s"
,
err
)
}
if
device
.
Type
==
"b"
{
// fdisk: add device soft link to /sys/block
if
err
:=
AddDeviceToSysBlock
(
device
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Add device to /sys/block failed: %s"
,
device
,
err
)
}
}
return
nil
}
...
...
@@ -261,12 +255,7 @@ func doRemoveDevice(pipe *os.File) error {
if
_
,
err
:=
DeviceFromPath
(
device
.
Path
,
""
);
err
!=
nil
{
return
err
}
if
device
.
Type
==
"b"
{
// fdisk: remove device symlink in /sys/block
if
err
:=
RemoveDeviceFromSysBlock
(
device
.
Path
);
err
!=
nil
{
return
err
}
}
// need strict check here?
return
os
.
Remove
(
device
.
Path
)
}
...
...
libdevice/devices_unix.go
浏览文件 @
c2ba2183
...
...
@@ -18,26 +18,20 @@ package libdevice
import
(
"errors"
"fmt"
"github.com/mrunalp/fileutils"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"isula.org/syscontainer-tools/types"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"
"isula.org/syscontainer-tools/types"
"github.com/sirupsen/logrus"
)
var
(
// ErrNotADevice not a device error
ErrNotADevice
=
errors
.
New
(
"not a device"
)
// MountSourcePath mount source path
MountSourcePath
=
"/mnt/sys/block"
// DevBlockPath device block path
DevBlockPath
=
"/sys/dev/block"
// MountDestPath mount dest path
MountDestPath
=
"/sys/block"
)
// Testing dependencies
...
...
@@ -249,92 +243,6 @@ func MknodDevice(dest string, node *types.Device) error {
return
syscall
.
Chown
(
dest
,
int
(
node
.
UID
),
int
(
node
.
GID
))
}
// prepareSysBlockMount bind mount /mnt/sys/block to /sys/block
func
prepareSysBlockMount
(
root
string
)
error
{
if
unix
.
Access
(
filepath
.
Join
(
root
,
MountDestPath
),
unix
.
W_OK
)
==
nil
{
return
nil
}
if
err
:=
os
.
RemoveAll
(
filepath
.
Join
(
root
,
MountSourcePath
));
err
!=
nil
{
return
err
}
if
err
:=
fileutils
.
CopyDirectory
(
filepath
.
Join
(
root
,
MountDestPath
),
filepath
.
Join
(
root
,
MountSourcePath
));
err
!=
nil
{
return
err
}
if
err
:=
syscall
.
Mount
(
filepath
.
Join
(
root
,
MountSourcePath
),
filepath
.
Join
(
root
,
MountDestPath
),
""
,
syscall
.
MS_BIND
|
syscall
.
MS_REC
,
""
);
err
!=
nil
{
return
err
}
return
nil
}
// AddDeviceToSysBlock add device to /sys/block in container
func
AddDeviceToSysBlock
(
node
*
types
.
Device
)
error
{
if
err
:=
prepareSysBlockMount
(
node
.
Root
);
err
!=
nil
{
return
err
}
devStr
:=
fmt
.
Sprintf
(
"%d:%d"
,
node
.
Major
,
node
.
Minor
)
linkPath
:=
filepath
.
Join
(
DevBlockPath
,
devStr
)
if
_
,
err
:=
os
.
Lstat
(
linkPath
);
os
.
IsNotExist
(
err
)
{
return
err
}
realPath
,
err
:=
os
.
Readlink
(
linkPath
)
if
err
!=
nil
{
return
err
}
hostDeviceName
:=
filepath
.
Base
(
realPath
)
containerDeviceName
:=
filepath
.
Base
(
node
.
Path
)
if
err
:=
os
.
Chdir
(
filepath
.
Join
(
node
.
Root
,
MountSourcePath
));
err
!=
nil
{
return
err
}
if
_
,
err
:=
os
.
Lstat
(
containerDeviceName
);
err
==
nil
{
if
err
:=
os
.
Remove
(
containerDeviceName
);
err
!=
nil
{
return
err
}
}
destPath
:=
strings
.
Replace
(
realPath
,
"../"
,
""
,
1
)
if
destPath
==
""
{
return
nil
}
if
err
:=
os
.
Symlink
(
destPath
,
containerDeviceName
);
err
!=
nil
{
return
err
}
if
err
:=
os
.
Chdir
(
filepath
.
Join
(
node
.
Root
,
"/dev"
));
err
!=
nil
{
return
err
}
if
hostDeviceName
!=
containerDeviceName
{
if
_
,
err
:=
os
.
Stat
(
hostDeviceName
);
os
.
IsNotExist
(
err
)
{
return
os
.
Symlink
(
containerDeviceName
,
hostDeviceName
)
}
}
return
nil
}
// RemoveDeviceFromSysBlock remove device from /sys/block in container
func
RemoveDeviceFromSysBlock
(
path
string
)
error
{
containerDeviceName
:=
filepath
.
Base
(
path
)
linkPath
:=
filepath
.
Join
(
MountDestPath
,
containerDeviceName
)
realPath
,
err
:=
os
.
Readlink
(
linkPath
)
if
err
!=
nil
{
return
err
}
hostDeviceName
:=
filepath
.
Base
(
realPath
)
devPath
:=
filepath
.
Join
(
"/dev"
,
hostDeviceName
)
if
_
,
err
:=
os
.
Lstat
(
linkPath
);
err
==
nil
{
if
err
:=
os
.
Remove
(
linkPath
);
err
!=
nil
{
return
err
}
}
if
hostDeviceName
!=
containerDeviceName
{
return
os
.
Remove
(
devPath
)
}
return
nil
}
// SetDefaultPath set default path for device
func
SetDefaultPath
(
dev
*
types
.
Device
)
{
if
dev
.
Path
==
""
{
...
...
types/device.go
浏览文件 @
c2ba2183
...
...
@@ -72,7 +72,6 @@ type Device struct {
GID
uint32
// Group ID
Allow
bool
// Used to differ add or remove
Parent
string
// Parent device name(pathonhost)
Root
string
// Rootfs path, prestart hook needed.
}
// Qos is the device Qos structure
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录