still fixing UI issue
Some checks failed
CI / test-build (push) Has been cancelled

This commit is contained in:
2025-12-18 12:41:51 +07:00
parent d55206af82
commit 8b5183d98a
3 changed files with 56 additions and 36 deletions

View File

@@ -212,7 +212,13 @@ func (s *Service) CreatePool(name string, vdevs []string, options map[string]str
options["canmount"] = "noauto"
}
// Add options
// IMPORTANT: Don't set mountpoint during pool creation
// ZFS tries to mount immediately during creation, which can fail
// We'll set mountpoint after pool is created
mountpointOption := options["mountpoint"]
delete(options, "mountpoint") // Remove from options temporarily
// Add remaining options
for k, v := range options {
args = append(args, "-o", fmt.Sprintf("%s=%s", k, v))
}
@@ -220,33 +226,41 @@ func (s *Service) CreatePool(name string, vdevs []string, options map[string]str
args = append(args, name)
args = append(args, vdevs...)
// Create the pool
// Create the pool (without mountpoint to avoid mount errors)
_, err := s.execCommand(s.zpoolPath, args...)
// Even if creation reports an error, check if pool actually exists
// Sometimes ZFS reports errors but pool is still created
if err != nil {
// Check if pool exists despite the error
if existingPools, listErr := s.ListPools(); listErr == nil {
for _, pool := range existingPools {
if pool.Name == name {
// Pool exists! Log the original error but don't fail
log.Printf("warning: pool creation reported error but pool %s exists: %v", name, err)
err = nil // Clear error since pool was created
break
}
// CRITICAL: Always check if pool exists, even if creation reported an error
// ZFS often reports mountpoint errors but pool is still created successfully
poolExists := false
if existingPools, listErr := s.ListPools(); listErr == nil {
for _, pool := range existingPools {
if pool.Name == name {
poolExists = true
break
}
}
// If pool doesn't exist and we still have an error, return it
if err != nil {
return err
}
}
// Pool created successfully - now try to set mountpoint and mount if needed
if mountpoint != "none" {
// Set mountpoint property (in case it wasn't set during creation)
if poolExists {
// Pool exists! This is success, regardless of any reported errors
if err != nil {
log.Printf("info: pool %s created successfully despite reported error: %v", name, err)
}
// Clear error since pool was created
err = nil
} else if err != nil {
// Pool doesn't exist and we have an error - return it
return err
}
// Pool created successfully - now set mountpoint and mount if needed
if mountpoint != "none" && mountpointOption != "" && poolExists {
// Ensure mountpoint directory exists
if err := s.createMountpointWithSudo(mountpoint); err != nil {
log.Printf("warning: failed to create mountpoint %s: %v", mountpoint, err)
}
// Set mountpoint property on the root filesystem of the pool
setMountpointArgs := []string{"set", fmt.Sprintf("mountpoint=%s", mountpoint), name}
if _, setErr := s.execCommand(s.zfsPath, setMountpointArgs...); setErr != nil {
log.Printf("warning: failed to set mountpoint property: %v (pool created but not mounted)", setErr)