fix regex, remove unsafe pointer usage, and add graceful HTTP shutdown

- Fix versionMatcher regex: gorilla/mux does not support (?:) syntax,
  and -dirty suffix was required instead of optional
- Replace unsafe.Pointer LUN casts with binary.LittleEndian.Uint64
  in sbc.go, scsi.go, and target.go
- Implement graceful HTTP server shutdown with 5s timeout using
  srv.Shutdown() instead of raw listener close
- Replace golang.org/x/net/context with standard library context
- Respect existing req.Cancel value in canceler to avoid overwriting
- Add early context cancellation check in Do() to fail fast

Based on review of PR #120 by @orzhang, with fixes applied.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lei Xue
2026-03-14 18:27:56 +08:00
parent 345b8b2507
commit f1cec4f5d4
6 changed files with 21 additions and 10 deletions

View File

@@ -21,7 +21,6 @@ import (
"bytes"
"encoding/binary"
"fmt"
"unsafe"
"github.com/gostor/gotgt/pkg/api"
"github.com/gostor/gotgt/pkg/util"
@@ -498,7 +497,7 @@ func SBCReserve(host int, cmd *api.SCSICommand) api.SAMStat {
}
func SBCRelease(host int, cmd *api.SCSICommand) api.SAMStat {
lun := *(*uint64)(unsafe.Pointer(&cmd.Lun))
lun := binary.LittleEndian.Uint64(cmd.Lun[:])
if err := deviceRelease(cmd.Target.TID, cmd.ITNexusID, lun, false); err != nil {
return api.SAMStatReservationConflict
}