fixing UI and iscsi sync
Some checks failed
CI / test-build (push) Has been cancelled

This commit is contained in:
2025-12-20 19:16:50 +00:00
parent 2bb892dfdc
commit 6202ef8e83
12 changed files with 1436 additions and 116 deletions

View File

@@ -3,6 +3,7 @@ package storage
import (
"errors"
"fmt"
"strings"
"sync"
"gitea.avt.data-center.id/othman.suseno/atlas/internal/models"
@@ -69,6 +70,12 @@ func (s *ISCSIStore) GetByIQN(iqn string) (*models.ISCSITarget, error) {
// Create creates a new iSCSI target
func (s *ISCSIStore) Create(iqn string, initiators []string) (*models.ISCSITarget, error) {
// Default to disk mode for backward compatibility
return s.CreateWithType(iqn, models.ISCSITargetTypeDisk, initiators)
}
// CreateWithType creates a new iSCSI target with specified type
func (s *ISCSIStore) CreateWithType(iqn string, targetType models.ISCSITargetType, initiators []string) (*models.ISCSITarget, error) {
s.mu.Lock()
defer s.mu.Unlock()
@@ -85,6 +92,7 @@ func (s *ISCSIStore) Create(iqn string, initiators []string) (*models.ISCSITarge
target := &models.ISCSITarget{
ID: id,
IQN: iqn,
Type: targetType,
LUNs: []models.LUN{},
Initiators: initiators,
Enabled: true,
@@ -151,10 +159,64 @@ func (s *ISCSIStore) AddLUN(targetID string, zvol string, size uint64) (*models.
}
lun := models.LUN{
ID: lunID,
ZVOL: zvol,
Size: size,
Backend: "zvol",
ID: lunID,
ZVOL: zvol,
Size: size,
Backend: "zvol",
Backstore: "block", // Default to block for ZVOL
}
target.LUNs = append(target.LUNs, lun)
return &lun, nil
}
// AddLUNWithDevice adds a LUN to a target with support for device and backstore type
func (s *ISCSIStore) AddLUNWithDevice(targetID string, zvol string, device string, size uint64, backstore string, backstoreName string) (*models.LUN, error) {
s.mu.Lock()
defer s.mu.Unlock()
target, ok := s.targets[targetID]
if !ok {
return nil, ErrISCSITargetNotFound
}
// Check if device/ZVOL already mapped
for _, lun := range target.LUNs {
if (zvol != "" && lun.ZVOL == zvol) || (device != "" && lun.Device == device) {
return nil, ErrLUNExists
}
}
// Find next available LUN ID
lunID := 0
for _, lun := range target.LUNs {
if lun.ID >= lunID {
lunID = lun.ID + 1
}
}
// Auto-detect backstore type if not specified
if backstore == "" {
if device != "" {
// If device is specified and looks like tape device, use pscsi
if strings.HasPrefix(device, "/dev/st") || strings.HasPrefix(device, "/dev/nst") {
backstore = "pscsi"
} else {
backstore = "block"
}
} else if zvol != "" {
backstore = "block"
}
}
lun := models.LUN{
ID: lunID,
ZVOL: zvol,
Device: device,
Size: size,
Backend: "zvol", // Keep for backward compatibility
Backstore: backstore,
BackstoreName: backstoreName,
}
target.LUNs = append(target.LUNs, lun)