feat: implement cmd management for targets, LUNs, and TPGTs (fixes #36)

- Fix target delete URL path mismatch (/targets/ -> /target/)
- Implement target create/delete server handlers with proper validation
- Add DeleteTarget method with force flag and mutex locking to SCSITargetService
- Implement full LU management: create/list/delete through CLI, client, and server
- Add TPGT list command to show target portal group tags
- Add unit tests for target/LU router handlers and SCSI service

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lei Xue
2026-03-14 20:30:47 +08:00
parent bbd373ba0e
commit 93e1476a0f
16 changed files with 760 additions and 36 deletions

View File

@@ -26,11 +26,9 @@ import (
)
func (s *SCSITargetService) NewSCSITarget(tid int, driverName, name string) (*api.SCSITarget, error) {
// verify the target ID
s.mutex.Lock()
defer s.mutex.Unlock()
// verify the target's Name
// verify the low level driver
var target = &api.SCSITarget{
Name: name,
TID: tid,
@@ -45,6 +43,24 @@ func (s *SCSITargetService) NewSCSITarget(tid int, driverName, name string) (*ap
return target, nil
}
// DeleteTarget removes a target by name. If force is false and there are active sessions, it returns an error.
func (s *SCSITargetService) DeleteTarget(name string, force bool) error {
s.mutex.Lock()
defer s.mutex.Unlock()
for i, t := range s.Targets {
if t.Name == name {
if !force && len(t.ITNexus) > 0 {
return fmt.Errorf("target %s has %d active sessions, use force to remove", name, len(t.ITNexus))
}
s.Targets = append(s.Targets[:i], s.Targets[i+1:]...)
DelTargetLUNMap(name)
return nil
}
}
return fmt.Errorf("target %q not found", name)
}
func (s *SCSITargetService) RereadTargetLUNMap() {
s.mutex.Lock()
defer s.mutex.Unlock()