Merge pull request #6291 from ningmingxiao/dev1
fix when kernel version < 4.13rc1 by using index=off cause test error
This commit is contained in:
commit
653f2f1ce4
@ -107,13 +107,6 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) {
|
||||
if err := os.Mkdir(filepath.Join(root, "snapshots"), 0700); err != nil && !os.IsExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// figure out whether "index=off" option is recognized by the kernel
|
||||
var indexOff bool
|
||||
if _, err = os.Stat("/sys/module/overlay/parameters/index"); err == nil {
|
||||
indexOff = true
|
||||
}
|
||||
|
||||
// figure out whether "userxattr" option is recognized by the kernel && needed
|
||||
userxattr, err := overlayutils.NeedsUserXAttr(root)
|
||||
if err != nil {
|
||||
@ -125,7 +118,7 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) {
|
||||
ms: ms,
|
||||
asyncRemove: config.asyncRemove,
|
||||
upperdirLabel: config.upperdirLabel,
|
||||
indexOff: indexOff,
|
||||
indexOff: supportsIndex(),
|
||||
userxattr: userxattr,
|
||||
}, nil
|
||||
}
|
||||
@ -572,3 +565,11 @@ func (o *snapshotter) workPath(id string) string {
|
||||
func (o *snapshotter) Close() error {
|
||||
return o.ms.Close()
|
||||
}
|
||||
|
||||
// supportsIndex checks whether the "index=off" option is supported by the kernel.
|
||||
func supportsIndex() bool {
|
||||
if _, err := os.Stat("/sys/module/overlay/parameters/index"); err == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -178,6 +178,9 @@ func testOverlayOverlayMount(t *testing.T, newSnapshotter testsuite.SnapshotterF
|
||||
expected := []string{
|
||||
"index=off",
|
||||
}
|
||||
if !supportsIndex() {
|
||||
expected = expected[1:]
|
||||
}
|
||||
if userxattr, err := overlayutils.NeedsUserXAttr(root); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if userxattr {
|
||||
@ -346,7 +349,11 @@ func testOverlayView(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) {
|
||||
t.Errorf("mount source should be overlay but received %q", m.Source)
|
||||
}
|
||||
|
||||
supportsIndex := supportsIndex()
|
||||
expectedOptions := 2
|
||||
if !supportsIndex {
|
||||
expectedOptions--
|
||||
}
|
||||
userxattr, err := overlayutils.NeedsUserXAttr(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -361,6 +368,9 @@ func testOverlayView(t *testing.T, newSnapshotter testsuite.SnapshotterFunc) {
|
||||
lowers := getParents(ctx, o, root, "/tmp/view2")
|
||||
expected = fmt.Sprintf("lowerdir=%s:%s", lowers[0], lowers[1])
|
||||
optIdx := 1
|
||||
if !supportsIndex {
|
||||
optIdx--
|
||||
}
|
||||
if userxattr {
|
||||
optIdx++
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user