fix storage
This commit is contained in:
@@ -2,6 +2,7 @@ package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -98,11 +99,17 @@ type PoolInfo struct {
|
||||
func (m *ZFSPoolMonitor) getSystemPools(ctx context.Context) (map[string]PoolInfo, error) {
|
||||
pools := make(map[string]PoolInfo)
|
||||
|
||||
// Get pool list
|
||||
cmd := exec.CommandContext(ctx, "zpool", "list", "-H", "-o", "name,size,alloc,free,health")
|
||||
output, err := cmd.Output()
|
||||
// Get pool list (with sudo for permissions)
|
||||
cmd := exec.CommandContext(ctx, "sudo", "zpool", "list", "-H", "-o", "name,size,alloc,free,health")
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// If no pools exist, zpool list returns exit code 1 but that's OK
|
||||
// Check if output is empty (no pools) vs actual error
|
||||
outputStr := strings.TrimSpace(string(output))
|
||||
if outputStr == "" || strings.Contains(outputStr, "no pools available") {
|
||||
return pools, nil // No pools, return empty map (not an error)
|
||||
}
|
||||
return nil, fmt.Errorf("zpool list failed: %w, output: %s", err, outputStr)
|
||||
}
|
||||
|
||||
lines := strings.Split(strings.TrimSpace(string(output)), "\n")
|
||||
|
||||
Reference in New Issue
Block a user