Skip to content

Commit 5547aa0

Browse files
committed
update mountpoint
1 parent eb74822 commit 5547aa0

File tree

6 files changed

+45
-37
lines changed

6 files changed

+45
-37
lines changed

main.go

+17-18
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/IceWhaleTech/CasaOS-LocalStorage/pkg/cache"
2525
"github.com/IceWhaleTech/CasaOS-LocalStorage/pkg/config"
2626
"github.com/IceWhaleTech/CasaOS-LocalStorage/pkg/sqlite"
27-
"github.com/IceWhaleTech/CasaOS-LocalStorage/pkg/utils/merge"
2827
"github.com/IceWhaleTech/CasaOS-LocalStorage/route"
2928
"github.com/IceWhaleTech/CasaOS-LocalStorage/service"
3029
"github.com/coreos/go-systemd/daemon"
@@ -81,23 +80,23 @@ func init() {
8180

8281
go service.MyService.Disk().CheckSerialDiskMount()
8382

84-
if strings.ToLower(config.ServerInfo.EnableMergerFS) == "true" {
85-
if !merge.IsMergerFSInstalled() {
86-
config.ServerInfo.EnableMergerFS = "false"
87-
logger.Info("mergerfs is disabled")
88-
}
89-
}
90-
91-
if strings.ToLower(config.ServerInfo.EnableMergerFS) == "true" {
92-
if !service.MyService.Disk().EnsureDefaultMergePoint() {
93-
config.ServerInfo.EnableMergerFS = "false"
94-
logger.Info("mergerfs is disabled")
95-
}
96-
}
97-
98-
if strings.ToLower(config.ServerInfo.EnableMergerFS) == "true" {
99-
go service.MyService.LocalStorage().CheckMergeMount()
100-
}
83+
// if strings.ToLower(config.ServerInfo.EnableMergerFS) == "true" {
84+
// if !merge.IsMergerFSInstalled() {
85+
// config.ServerInfo.EnableMergerFS = "false"
86+
// logger.Info("mergerfs is disabled")
87+
// }
88+
// }
89+
service.MyService.Disk().EnsureDefaultMergePoint()
90+
// if strings.ToLower(config.ServerInfo.EnableMergerFS) == "true" {
91+
// if !service.MyService.Disk().EnsureDefaultMergePoint() {
92+
// config.ServerInfo.EnableMergerFS = "false"
93+
// logger.Info("mergerfs is disabled")
94+
// }
95+
// }
96+
97+
// if strings.ToLower(config.ServerInfo.EnableMergerFS) == "true" {
98+
// go service.MyService.LocalStorage().CheckMergeMount()
99+
// }
101100

102101
checkToken2_11()
103102

route/v1/storage.go

-3
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ func GetStorageList(c *gin.Context) {
135135
}
136136
}
137137
tempDisk.Children = tempStorageArr
138-
logger.Info("system disk", zap.Any("disk", tempDisk))
139138
storages = append(storages, tempDisk)
140-
logger.Info("system disk", zap.Any("storages", storages))
141139
} else if !tempSystemDisk {
142140
tempDisk.Children = storageArr
143141
storages = append(storages, tempDisk)
@@ -246,7 +244,6 @@ func PostAddStorage(c *gin.Context) {
246244
for _, blkChild := range currentDisk.Children {
247245

248246
mountPoint := blkChild.GetMountPoint(name)
249-
250247
// mount disk
251248
if output, err := service.MyService.Disk().MountDisk(blkChild.Path, mountPoint); err != nil {
252249
logger.Error("err", zap.Error(err), zap.String("mountPoint", mountPoint), zap.String("output", output))

route/v2/merge.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package v2
33
import (
44
"fmt"
55

6-
"io/ioutil"
7-
86
"net/http"
97
"os"
108
"strings"
@@ -165,11 +163,10 @@ func (s *LocalStorage) InitMerge(ctx echo.Context) error {
165163
message := "mount point is empty"
166164
return ctx.JSON(http.StatusBadRequest, codegen.ResponseBadRequest{Message: &message})
167165
}
168-
169166
if strings.ToLower(config.ServerInfo.EnableMergerFS) != "true" {
170167
if !file.CheckNotExist(m.MountPoint) {
171168

172-
dir, _ := ioutil.ReadDir(constants.DefaultFilePath)
169+
dir, _ := os.ReadDir(constants.DefaultFilePath)
173170
if len(dir) > 0 {
174171
message := "Please make sure the /var/lib/casaos/files directory is empty"
175172
return ctx.JSON(http.StatusBadRequest, codegen.ResponseBadRequest{Message: &message})

service/disk.go

+26-11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/IceWhaleTech/CasaOS-Common/utils/constants"
2222
"github.com/IceWhaleTech/CasaOS-Common/utils/file"
2323
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
24+
"github.com/IceWhaleTech/CasaOS-LocalStorage/codegen"
2425
"github.com/IceWhaleTech/CasaOS-LocalStorage/codegen/message_bus"
2526
"github.com/IceWhaleTech/CasaOS-LocalStorage/common"
2627
"github.com/IceWhaleTech/CasaOS-LocalStorage/model"
@@ -82,8 +83,6 @@ func (d *diskService) EnsureDefaultMergePoint() bool {
8283
mountPoint := "/DATA"
8384
sourceBasePath := constants.DefaultFilePath
8485

85-
logger.Info("ensure default merge point exists", zap.String("mount point", mountPoint), zap.String("sourceBasePath", sourceBasePath))
86-
8786
existingMerges, err := MyService.LocalStorage().GetMergeAllFromDB(&mountPoint)
8887
if err != nil {
8988
panic(err)
@@ -103,14 +102,30 @@ func (d *diskService) EnsureDefaultMergePoint() bool {
103102
SourceBasePath: &sourceBasePath,
104103
}
105104

106-
if err := MyService.LocalStorage().CreateMerge(merge); err != nil {
107-
if errors.Is(err, v2.ErrMergeMountPointAlreadyExists) {
108-
logger.Info(err.Error(), zap.String("mount point", mountPoint))
109-
} else if errors.Is(err, v2.ErrMountPointIsNotEmpty) {
110-
logger.Error("Mount point "+mountPoint+" is not empty", zap.String("mount point", mountPoint))
111-
return false
112-
} else {
113-
panic(err)
105+
mounts, err := MyService.LocalStorage().GetMounts(codegen.GetMountsParams{})
106+
if err != nil {
107+
logger.Error("failed to get mount list from system", zap.Error(err))
108+
return false
109+
}
110+
isExist := false
111+
for _, v := range mounts {
112+
if v.MountPoint == mountPoint {
113+
isExist = true
114+
merge.SourceBasePath = v.Source
115+
break
116+
}
117+
}
118+
119+
if !isExist {
120+
if err := MyService.LocalStorage().CreateMerge(merge); err != nil {
121+
if errors.Is(err, v2.ErrMergeMountPointAlreadyExists) {
122+
logger.Info(err.Error(), zap.String("mount point", mountPoint))
123+
} else if errors.Is(err, v2.ErrMountPointIsNotEmpty) {
124+
logger.Error("Mount point "+mountPoint+" is not empty", zap.String("mount point", mountPoint))
125+
return false
126+
} else {
127+
panic(err)
128+
}
114129
}
115130
}
116131

@@ -146,7 +161,6 @@ func (d *diskService) SmartCTL(path string) model.SmartctlA {
146161
var m model.SmartctlA
147162
buf := command.ExecSmartCTLByPath(path)
148163
if buf == nil {
149-
logger.Error("failed to exec shell - smartctl exec error")
150164
if err := Cache.Add(key, m, time.Minute*10); err != nil {
151165
logger.Error("failed to add cache", zap.Error(err), zap.String("key", key))
152166
}
@@ -788,6 +802,7 @@ func IsDiskSupported(d model.LSBLKModel) bool {
788802
strings.Contains(d.SubSystems, "virtio") ||
789803
strings.Contains(d.SubSystems, "block:scsi:vmbus:acpi") || // Microsoft Hyper-V
790804
strings.Contains(d.SubSystems, "block:mmc:mmc_host:pci") ||
805+
strings.Contains(d.SubSystems, "block:scsi:pci") ||
791806
(d.Tran == "ata" && d.Type == "disk") || d.Tran == "usb"
792807
}
793808
func IsFormatSupported(d model.LSBLKModel) bool {

service/v2/merge.go

-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ func (s *LocalStorageService) UpdateMerge(merge *model2.Merge) error {
155155
}
156156

157157
func (s *LocalStorageService) CheckMergeMount() {
158-
logger.Info("checking merge mount...")
159158

160159
mergesFromDB, err := s.GetMergeAllFromDB(nil)
161160
if err != nil {

service/v2/mount.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
99
"github.com/IceWhaleTech/CasaOS-LocalStorage/codegen"
1010
"github.com/IceWhaleTech/CasaOS-LocalStorage/pkg/mount"
11+
1112
"github.com/IceWhaleTech/CasaOS-LocalStorage/service/v2/fs"
1213
"github.com/moby/sys/mountinfo"
1314
"go.uber.org/zap"

0 commit comments

Comments
 (0)