Skip to content

Commit

Permalink
update mergerfs
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong committed Oct 7, 2023
1 parent 4ba837d commit 93c02d0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api/local_storage/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ components:
example: "/mnt/a:/mnt/b"
options:
type: string
example: "defaults,allow_other,use_ino,category.create=mfs,moveonenospc=true,minfreespace=1M"
example: "defaults,allow_other,category.create=mfs,moveonenospc=true,minfreespace=1M"
extended:
type: object
description: |-
Expand Down
4 changes: 2 additions & 2 deletions build/sysroot/usr/local/bin/mergerfs.ctl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def control_file(path):


def add_srcmount(ctrlfile,srcmount):
key = b'user.mergerfs.srcmounts'
key = b'user.mergerfs.branches'
value = b'+' + srcmount.encode()
try:
os.setxattr(ctrlfile,key,value)
Expand All @@ -75,7 +75,7 @@ def add_srcmount(ctrlfile,srcmount):


def remove_srcmount(ctrlfile,srcmount):
key = b'user.mergerfs.srcmounts'
key = b'user.mergerfs.branches'
value = b'-' + srcmount.encode()
try:
os.setxattr(ctrlfile,key,value)
Expand Down
6 changes: 3 additions & 3 deletions pkg/fstab/fstab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
const fstabContent = `
# UNCONFIGURED FSTAB FOR BASE SYSTEM
LABEL=UEFI /boot/efi vfat umask=0077 0 1
/mnt/sdb:/mnt/sdc /media mergerfs defaults,allow_other,use_ino,category.create=mfs,moveonenospc=true,minfreespace=1M 0 0
/mnt/sdb:/mnt/sdc /media mergerfs defaults,allow_other,category.create=mfs,moveonenospc=true,minfreespace=1M 0 0
LABEL=desktop-rootfs / ext4 defaults 0 1
`

Expand All @@ -31,7 +31,7 @@ func TestFSTab(t *testing.T) {
assert.Equal(t, entry.Source, "/mnt/sdb:/mnt/sdc")
assert.Equal(t, entry.MountPoint, "/media")
assert.Equal(t, entry.FSType, "mergerfs")
assert.Equal(t, entry.Options, "defaults,allow_other,use_ino,category.create=mfs,moveonenospc=true,minfreespace=1M")
assert.Equal(t, entry.Options, "defaults,allow_other,category.create=mfs,moveonenospc=true,minfreespace=1M")
assert.Equal(t, entry.Dump, 0)
assert.Equal(t, entry.Pass, PassDoNotCheck)

Expand All @@ -51,7 +51,7 @@ func TestFSTab(t *testing.T) {
assert.Equal(t, entry.Source, "/mnt/sdb:/mnt/sdc")
assert.Equal(t, entry.MountPoint, "/media")
assert.Equal(t, entry.FSType, "mergerfs")
assert.Equal(t, entry.Options, "defaults,allow_other,use_ino,category.create=mfs,moveonenospc=true,minfreespace=1M")
assert.Equal(t, entry.Options, "defaults,allow_other,category.create=mfs,moveonenospc=true,minfreespace=1M")
assert.Equal(t, entry.Dump, 0)
assert.Equal(t, entry.Pass, PassDoNotCheck)
}
9 changes: 5 additions & 4 deletions pkg/mergerfs/mergerfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func ListValues(fspath string) (map[string]string, error) {
func SetSource(fspath string, sources []string) error {
ctrlfile := ControlFile(fspath)

key := "user.mergerfs.srcmounts"
key := "user.mergerfs.branches"

sourceMap := make(map[string]interface{})
for _, source := range sources {
Expand All @@ -59,8 +59,9 @@ func SetSource(fspath string, sources []string) error {
}

value := []byte(strings.Join(dedupedSources, ":"))
logger.Error("SetSource", zap.String("key", key), zap.String("value", string(value)), zap.String("ctrlfile", ctrlfile))
//str, err := command.ExecResultStr("setfattr -n " + key + " -v " + string(string(value)) + " " + ctrlfile)
err := syscall.Setxattr(ctrlfile, key, value, 0)
//logger.Error("SetSourceStr", zap.String("str", str))
if err != nil {
logger.Error("SetSource", zap.Error(err))
return err
Expand All @@ -80,7 +81,7 @@ func GetSource(fspath string) ([]string, error) {
func AddSource(fspath string, source string) error {
ctrlfile := ControlFile(fspath)

key := "user.mergerfs.srcmounts"
key := "user.mergerfs.branches"
value := []byte("+" + source)

return syscall.Setxattr(ctrlfile, key, value, 0)
Expand All @@ -89,7 +90,7 @@ func AddSource(fspath string, source string) error {
func RemoveSource(fspath string, source string) error {
ctrlfile := ControlFile(fspath)

key := "user.mergerfs.srcmounts"
key := "user.mergerfs.branches"
value := []byte("-" + source)

return syscall.Setxattr(ctrlfile, key, value, 0)
Expand Down
1 change: 0 additions & 1 deletion route/v2/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func (s *LocalStorage) SetMerge(ctx echo.Context) error {
if m.Fstype != nil {
fstype = *m.Fstype
}
logger.Info("fstype", zap.String("fstype", fstype))
// expand source volume paths to source volumes
var sourceVolumes []*model2.Volume
if m.SourceVolumeUuids != nil {
Expand Down
10 changes: 6 additions & 4 deletions service/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (d *diskService) EnsureDefaultMergePoint() bool {
if len(existingMerges) > 1 {
logger.Error("more than one merge point with the same mount point found", zap.String("mount point", mountPoint))
}
config.ServerInfo.EnableMergerFS = "true"
return true
}

Expand All @@ -111,6 +112,7 @@ func (d *diskService) EnsureDefaultMergePoint() bool {
isExist := false
for _, v := range mounts {
if v.MountPoint == mountPoint {
config.ServerInfo.EnableMergerFS = "true"
isExist = true
merge.SourceBasePath = v.Source
break
Expand All @@ -133,7 +135,7 @@ func (d *diskService) EnsureDefaultMergePoint() bool {
if err := MyService.LocalStorage().CreateMergeInDB(merge); err != nil {
panic(err)
}

config.ServerInfo.EnableMergerFS = "true"
return true
}
func (d *diskService) RemoveLSBLKCache() {
Expand Down Expand Up @@ -163,18 +165,18 @@ func (d *diskService) SmartCTL(path string) model.SmartctlA {
buf := command.ExecSmartCTLByPath(path)
if buf == nil {
if err := Cache.Add(key, m, time.Minute*10); err != nil {
logger.Error("failed to add cache", zap.Error(err), zap.String("key", key))
//logger.Error("failed to add cache", zap.Error(err), zap.String("key", key))
}
return m
}

err := json2.Unmarshal(buf, &m)
if err != nil {
logger.Error("failed to unmarshal json", zap.Error(err), zap.String("json", string(buf)))
//logger.Error("failed to unmarshal json", zap.Error(err), zap.String("json", string(buf)))
}
if !reflect.DeepEqual(m, model.SmartctlA{}) {
if err := Cache.Add(key, m, time.Hour*24); err != nil {
logger.Error("failed to add cache", zap.Error(err), zap.String("key", key))
//logger.Error("failed to add cache", zap.Error(err), zap.String("key", key))
}
}
return m
Expand Down
2 changes: 1 addition & 1 deletion service/v2/fs/mergerfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
const (
MergerFS = "mergerfs"
MergerFSFullName = "fuse.mergerfs"
MergerFSDefaultOptions = "defaults,allow_other,use_ino,category.create=mfs,moveonenospc=true,minfreespace=1M"
MergerFSDefaultOptions = "category.create=mfs,moveonenospc=true,minfreespace=1M"

MergerFSExtendedKeySource = "mergerfs.src" // corresponding value could be for example: /var/lib/casaos/files

Expand Down

0 comments on commit 93c02d0

Please sign in to comment.