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

This commit is contained in:
2025-12-18 12:49:10 +07:00
parent 8b5183d98a
commit 95b2dbac04
2 changed files with 55 additions and 14 deletions

View File

@@ -226,31 +226,61 @@ func (s *Service) CreatePool(name string, vdevs []string, options map[string]str
args = append(args, name)
args = append(args, vdevs...)
// Log the command we're about to run for debugging
log.Printf("executing: %s %v", s.zpoolPath, args)
// Create the pool (without mountpoint to avoid mount errors)
_, err := s.execCommand(s.zpoolPath, args...)
createOutput, err := s.execCommand(s.zpoolPath, args...)
// Log the command output for debugging
if err != nil {
log.Printf("zpool create failed - output: %s, error: %v", createOutput, err)
} else {
log.Printf("zpool create succeeded - output: %s", createOutput)
}
// CRITICAL: Always check if pool exists, even if creation reported an error
// ZFS often reports mountpoint errors but pool is still created successfully
// Retry checking pool existence up to 3 times with delays
poolExists := false
if existingPools, listErr := s.ListPools(); listErr == nil {
for _, pool := range existingPools {
if pool.Name == name {
poolExists = true
break
for i := 0; i < 3; i++ {
if i > 0 {
// Wait before retry (100ms, 200ms, 300ms)
time.Sleep(time.Duration(i*100) * time.Millisecond)
}
if existingPools, listErr := s.ListPools(); listErr == nil {
for _, pool := range existingPools {
if pool.Name == name {
poolExists = true
log.Printf("pool %s found after %d check(s)", name, i+1)
break
}
}
}
if poolExists {
break
}
}
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)
} else {
log.Printf("info: pool %s created successfully", name)
}
// 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 doesn't exist and we have an error - return it with full context
log.Printf("error: pool %s creation failed and pool does not exist: %v", name, err)
return fmt.Errorf("failed to create pool %s: %v", name, err)
} else {
// No error reported but pool doesn't exist - this shouldn't happen
log.Printf("warning: pool %s creation reported no error but pool does not exist", name)
return fmt.Errorf("pool %s creation reported success but pool was not found", name)
}
// Pool created successfully - now set mountpoint and mount if needed