Răsfoiți Sursa

Fixed fsh ghost mounting issue

Toby Chui 3 ani în urmă
părinte
comite
56096ea7eb
6 a modificat fișierele cu 50 adăugiri și 23 ștergeri
  1. 4 2
      disk.go
  2. 2 1
      file_system.go
  3. 35 10
      storage.go
  4. 3 5
      storage.pool.go
  5. 2 5
      web/SystemAO/storage/fshBridge.html
  6. 4 0
      web/SystemAO/storage/poolList.html

+ 4 - 2
disk.go

@@ -127,7 +127,8 @@ func DiskServiceInit() {
 			adminRouter.HandleFunc("/system/disk/diskmg/platform", diskmg.HandlePlatform)
 			adminRouter.HandleFunc("/system/disk/diskmg/mount", func(w http.ResponseWriter, r *http.Request) {
 				//Mount option require passing in all filesystem handlers
-				diskmg.HandleMount(w, r, fsHandlers)
+				allFsh := GetAllLoadedFsh()
+				diskmg.HandleMount(w, r, allFsh)
 			})
 			adminRouter.HandleFunc("/system/disk/diskmg/format", func(w http.ResponseWriter, r *http.Request) {
 				//Check if request are made in POST mode
@@ -145,7 +146,8 @@ func DiskServiceInit() {
 				}
 
 				//Format option require passing in all filesystem handlers
-				diskmg.HandleFormat(w, r, fsHandlers)
+				allFsh := GetAllLoadedFsh()
+				diskmg.HandleFormat(w, r, allFsh)
 			})
 			adminRouter.HandleFunc("/system/disk/diskmg/mpt", diskmg.HandleListMountPoints)
 		}

+ 2 - 1
file_system.go

@@ -2875,7 +2875,8 @@ func system_fs_FileVersionHistory(w http.ResponseWriter, r *http.Request) {
 }
 
 func system_fs_clearVersionHistories() {
-	for _, fsh := range fsHandlers {
+	allFsh := GetAllLoadedFsh()
+	for _, fsh := range allFsh {
 		if !fsh.ReadOnly {
 			localversion.CleanExpiredVersionBackups(fsh, fsh.Path, 30*86400)
 		}

+ 35 - 10
storage.go

@@ -18,8 +18,8 @@ import (
 )
 
 var (
-	baseStoragePool *storage.StoragePool    //base storage pool, all user can access these virtual roots
-	fsHandlers      []*fs.FileSystemHandler //All File system handlers. All opened handles must be registered in here
+	baseStoragePool *storage.StoragePool //base storage pool, all user can access these virtual roots
+	//fsHandlers      []*fs.FileSystemHandler //All File system handlers. All opened handles must be registered in here
 	//storagePools    []*storage.StoragePool  //All Storage pool opened
 	bridgeManager *bridge.Record //Manager to handle bridged FSH
 )
@@ -43,6 +43,8 @@ func StorageInit() {
 }
 
 func LoadBaseStoragePool() error {
+	//All fsh for the base pool
+	fsHandlers := []*fs.FileSystemHandler{}
 	//Use for Debian buster local file system
 	localFileSystem := "ext4"
 	if runtime.GOOS == "windows" {
@@ -134,7 +136,7 @@ func LoadStoragePoolForGroup(pg *permission.PermissionGroup) error {
 	expectedConfigPath := "./system/storage/" + pg.Name + ".json"
 	if fs.FileExists(expectedConfigPath) {
 		//Read the config file
-		pgStorageConfig, err := ioutil.ReadFile(expectedConfigPath)
+		pgStorageConfig, err := os.ReadFile(expectedConfigPath)
 		if err != nil {
 			log.Println("Failed to read config for " + pg.Name + ": " + err.Error())
 			return errors.New("Failed to read config for " + pg.Name + ": " + err.Error())
@@ -147,9 +149,8 @@ func LoadStoragePoolForGroup(pg *permission.PermissionGroup) error {
 			return errors.New("Failed to load storage configuration: " + err.Error())
 		}
 
-		//Add these to mounted handlers
+		//Show debug message
 		for _, thisHandler := range thisGroupFsHandlers {
-			fsHandlers = append(fsHandlers, thisHandler)
 			log.Println(thisHandler.Name + " Mounted as " + thisHandler.UUID + ":/ for group " + pg.Name)
 		}
 
@@ -232,14 +233,37 @@ func GetFsHandlerByUUID(uuid string) (*fs.FileSystemHandler, error) {
 	if strings.Contains(uuid, ":") {
 		uuid = strings.Split(uuid, ":")[0]
 	}
-
-	for _, fsh := range fsHandlers {
+	var resultFsh *fs.FileSystemHandler = nil
+	allFsh := GetAllLoadedFsh()
+	for _, fsh := range allFsh {
 		if fsh.UUID == uuid && !fsh.Closed {
-			return fsh, nil
+			resultFsh = fsh
 		}
 	}
+	if resultFsh == nil {
+		return nil, errors.New("Filesystem handler with given UUID not found")
+	} else {
+		return resultFsh, nil
+	}
+}
+
+func GetAllLoadedFsh() []*fs.FileSystemHandler {
+	fshTmp := map[string]*fs.FileSystemHandler{}
+	allFsh := []*fs.FileSystemHandler{}
+	allStoragePools := GetAllStoragePools()
+	for _, thisSP := range allStoragePools {
+		for _, thisFsh := range thisSP.Storages {
+			fshPointer := thisFsh
+			fshTmp[thisFsh.UUID] = fshPointer
+		}
+	}
+
+	//Restructure the map to slice
+	for _, fsh := range fshTmp {
+		allFsh = append(allFsh, fsh)
+	}
 
-	return nil, errors.New("Filesystem handler with given UUID not found")
+	return allFsh
 }
 
 func RegisterStorageSettings() {
@@ -257,7 +281,8 @@ func RegisterStorageSettings() {
 
 //CloseAllStorages Close all storage database
 func CloseAllStorages() {
-	for _, fsh := range fsHandlers {
+	allFsh := GetAllLoadedFsh()
+	for _, fsh := range allFsh {
 		fsh.FilesystemDatabase.Close()
 	}
 }

+ 3 - 5
storage.pool.go

@@ -351,7 +351,6 @@ func HandleStoragePoolReload(w http.ResponseWriter, r *http.Request) {
 		baseStoragePool.Close()
 		emptyPool := storage.StoragePool{}
 		baseStoragePool = &emptyPool
-		fsHandlers = []*fs.FileSystemHandler{}
 
 		//Start BasePool again
 		err := LoadBaseStoragePool()
@@ -384,11 +383,9 @@ func HandleStoragePoolReload(w http.ResponseWriter, r *http.Request) {
 
 		if pool == "system" {
 			//Reload basepool
-
 			baseStoragePool.Close()
 			emptyPool := storage.StoragePool{}
 			baseStoragePool = &emptyPool
-			fsHandlers = []*fs.FileSystemHandler{}
 
 			//Start BasePool again
 			err := LoadBaseStoragePool()
@@ -400,6 +397,7 @@ func HandleStoragePoolReload(w http.ResponseWriter, r *http.Request) {
 			}
 
 			BridgeStoragePoolForGroup("system")
+
 		} else {
 			//Reload the given storage pool
 			if !permissionHandler.GroupExists(pool) {
@@ -676,13 +674,13 @@ func HandleFSHBridging(w http.ResponseWriter, r *http.Request) {
 
 	targetFSH, err := common.Mv(r, "fsh", true)
 	if err != nil {
-		common.SendErrorResponse(w, "Invalid fsh given")
+		common.SendErrorResponse(w, "Invalid File System Handler given")
 		return
 	}
 
 	fsh, err := GetFsHandlerByUUID(targetFSH)
 	if err != nil {
-		common.SendErrorResponse(w, "Given FSH UUID does not exists")
+		common.SendErrorResponse(w, "Given File System Handler UUID does not exists")
 		return
 	}
 

+ 2 - 5
web/SystemAO/storage/fshBridge.html

@@ -113,15 +113,12 @@
                 File System Handler Bridged
             </div>
             <div class="content">
-              <p>Reload storage pool is needed for these changes to take effect</p>
+              <p>Click OK to exit the handler bridging utility.</p>
             </div>
             <div class="actions">
-              <div class="ui basic cancel inverted button" onclick="handleCancel();">
-                Later
-              </div>
               <div class="ui green ok inverted button" onclick="done();">
                 <i class="checkmark icon"></i>
-                Ok
+                OK
               </div>
             </div>
           </div>

+ 4 - 0
web/SystemAO/storage/poolList.html

@@ -274,6 +274,9 @@
                                     <button title="Edit Virtual Disk" onclick="editFsh('${storage.uuid}','${selectedStoragePool}');" class="circular tiny basic ui icon button">
                                         <i class="edit icon"></i>
                                     </button>
+                                    <button onclick="removeFsh('${storage.uuid}','${selectedStoragePool}');" title="Remove Virtual Disk" onclick="" class="circular tiny basic ui icon button removeFshButton">
+                                        <i class="red remove icon"></i>
+                                    </button>
                                 </div>
                                 <div class="statusTextWrapper">
                                     <div class="statusText">
@@ -299,6 +302,7 @@
                                         thisFsh.css({
                                             "border-left": "3px solid #e29eff",
                                         });
+                                        thisFsh.find("img").attr('src', '../../img/system/drive-bridge.svg');
                                         thisFsh.find(".statusText").text("Bridged");
                                     }else{
                                         thisFsh.find(".fshbuttons").hide();