Skip to content

Commit

Permalink
fix config equal when checking re-mount (#3059)
Browse files Browse the repository at this point in the history
* fix config equal when checking re-mount

Signed-off-by: xixi <[email protected]>
  • Loading branch information
Hexilee authored Dec 6, 2022
1 parent 760ad91 commit ae49307
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
30 changes: 27 additions & 3 deletions cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,36 @@ func registerMetaMsg(m meta.Meta, store chunk.ChunkStore, chunkConf *chunk.Confi
}

func configEqual(a, b *vfs.Config) bool {
if a == nil || b == nil {
return a == b
}

ac, bc := *a, *b
aFormat, bFormat := *ac.Format, *bc.Format
aFormat.SecretKey, bFormat.SecretKey = "", ""
ac.Meta, ac.Chunk, ac.Format, ac.Port, ac.AttrTimeout, ac.DirEntryTimeout, ac.EntryTimeout = nil, nil, nil, nil, 0, 0, 0
bc.Meta, bc.Chunk, bc.Format, bc.Port, bc.AttrTimeout, bc.DirEntryTimeout, bc.EntryTimeout = nil, nil, nil, nil, 0, 0, 0
return *a.Meta == *b.Meta && *a.Chunk == *b.Chunk && aFormat == bFormat && ac == bc
eq := ac == bc

if a.Format == nil || b.Format == nil {
eq = eq && a.Format == b.Format
} else {
af, bf := *a.Format, *b.Format
af.SecretKey, bf.SecretKey = "", ""
eq = eq && af == bf
}

if a.Meta == nil || b.Meta == nil {
eq = eq && a.Meta == b.Meta
} else {
eq = eq && *a.Meta == *b.Meta
}

if a.Chunk == nil || b.Chunk == nil {
eq = eq && a.Chunk == b.Chunk
} else {
eq = eq && *a.Chunk == *b.Chunk
}

return eq
}

func prepareMp(newCfg *vfs.Config, mp string) (ignore bool) {
Expand Down
42 changes: 42 additions & 0 deletions cmd/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/go-redis/redis/v8"
"github.com/juicedata/juicefs/pkg/meta"
"github.com/juicedata/juicefs/pkg/utils"
"github.com/juicedata/juicefs/pkg/vfs"
. "github.com/smartystreets/goconvey/convey"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -190,3 +191,44 @@ func TestUmount(t *testing.T) {
t.Fatalf("umount failed: inode of %s is 1", testMountPoint)
}
}

func Test_configEqual(t *testing.T) {
cases := []struct {
a, b *vfs.Config
equal bool
}{
{
a: nil, b: nil, equal: true,
},
{
a: &vfs.Config{}, b: nil, equal: false,
},
{
a: nil, b: &vfs.Config{}, equal: false,
},
{
a: &vfs.Config{}, b: &vfs.Config{}, equal: true,
},
{
a: &vfs.Config{Format: &meta.Format{}}, b: &vfs.Config{}, equal: false,
},
{
a: &vfs.Config{}, b: &vfs.Config{Format: &meta.Format{}}, equal: false,
},
{
a: &vfs.Config{Format: &meta.Format{}}, b: &vfs.Config{Format: &meta.Format{}}, equal: true,
},
{
a: &vfs.Config{Format: &meta.Format{SecretKey: "1"}}, b: &vfs.Config{Format: &meta.Format{SecretKey: "2"}}, equal: true,
},
{
a: &vfs.Config{Port: &vfs.Port{}}, b: &vfs.Config{}, equal: true,
},
}

for _, c := range cases {
if configEqual(c.a, c.b) != c.equal {
t.Errorf("configEqual(%v, %v) should be %v", c.a, c.b, c.equal)
}
}
}

0 comments on commit ae49307

Please sign in to comment.