86 Commits

Author SHA1 Message Date
Lei Xue
76ab15b0df feat: add S3-compatible object storage backend
Add a new backend store that enables iSCSI targets backed by
S3-compatible object storage (AWS S3, MinIO, Ceph RGW, etc.).

The implementation uses a chunked storage strategy where the virtual
block device is divided into fixed-size chunks (default 4 MiB), each
stored as an independent S3 object. This enables efficient random
read/write access on top of object storage.

Key features:
- Chunked storage with configurable chunk size
- Sparse device support (unwritten chunks treated as zeros)
- Concurrent multi-chunk I/O via errgroup
- Per-chunk locking for safe read-modify-write
- AWS SDK v2 with default credential chain
- In-process gofakes3 test server (no Docker needed)
- 12 unit tests + 2 integration tests

Also updates CI workflow to run S3 backend tests and updates
README with S3 backend documentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 16:22:57 +08:00
Lei Xue
93e1476a0f 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>
2026-03-14 20:30:47 +08:00
Lei Xue
a5628f4ec0 add end-to-end IO benchmarks and fix pprof-identified hotspots
Add comprehensive benchmark suite (io_bench_test.go):
- BenchmarkEndToEndRead/Write: full SCSI stack (512B to 256KB)
- BenchmarkEndToEndReadParallel/WriteParallel: concurrent IO
- BenchmarkFileBackingStoreRead/Write: isolated backing store

pprof-guided optimizations:
- Guard hot-path log.Debugf with log.GetLevel() check in scsi.go,
  sbc.go, backingstore.go — eliminates 22% CPU overhead from logrus
  Entry allocation even when debug logging is disabled
- Add FileBackingStore.ReadAt for zero-copy reads directly into
  caller's buffer, bypassing Read()'s per-call make([]byte, tl)
- Use ReadAt via interface assertion in bsPerformCommand to read
  directly into InSDBBuffer, eliminating allocation + copy

Results (256KB reads): +42% throughput, allocs reduced from 10 to 5

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 19:41:48 +08:00
Lei Xue
16108ced95 optimize performance: reduce allocations, buffered I/O, and zero-copy reads
- Read path: eliminate redundant allocation in bsPerformCommand - remove
  the pre-allocation before bs.Read() and the append loop for zero-fill,
  use direct copy and in-place zero-fill instead
- parseHeader: use command pool (getCommand) instead of direct allocation,
  reducing GC pressure on the hot path
- Unmap: use a shared 1MB zero buffer instead of allocating per-descriptor,
  dramatically reducing allocations for large unmap operations
- Network I/O: add 256KB bufio.Writer to iSCSI connections, batching
  small PDU writes into fewer syscalls. Flush after txHandler completes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 19:03:30 +08:00
Lei Xue
f1cec4f5d4 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>
2026-03-14 18:27:56 +08:00
Lei Xue
36149cd4a9 support more SCSI commands: ReadDefectData, Sanitize, and expanded CI
New SCSI commands implemented:
- READ DEFECT DATA(10/12): returns empty defect list (virtual device)
- SANITIZE: supports OVERWRITE and BLOCK ERASE (zeros all blocks)
- EXTENDED COPY / RECEIVE COPY RESULTS: registered as unsupported

New unit tests for ReadDefectData10/12, Sanitize, and command registration.

New CI libiscsi test cases:
- PersistentReservation (PrinReadKeys, PrinReportCapabilities,
  ProutRegister, ProutReserve)
- ReadDefectData10/12 (Simple)
- CompareAndWrite (Simple)
- OrWrite (Simple, BeyondEol, ZeroBlocks)
- GetLBAStatus (Simple, BeyondEol)
- ReportSupportedOpcodes (OneCommand)

Partial fix for #55

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 13:06:35 +08:00
Lei Xue
3c41cd619b Merge pull request #123 from gostor/fix/unmap-data-corruption
fix UNMAP data corruption by implementing block zeroing
2026-03-14 12:31:48 +08:00
Lei Xue
00d0c3a306 fix UNMAP data corruption by implementing block zeroing
The UNMAP command was a no-op in all backing stores, causing unmapped
blocks to retain stale data instead of returning zeros per SCSI spec.

- Implement Unmap in FileBackingStore to zero out unmapped blocks
- Implement Unmap in IOUringBackingStore to zero out unmapped blocks
- Enable Unmap in RemBackingStore (was commented out)
- Change UnmapBlockDescriptor.TL from uint32 to uint64 to prevent
  integer overflow when converting block count to byte length with
  large block shifts

Fixes #119

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 12:29:12 +08:00
Lei Xue
b2776dc5c2 fix critical bugs and improve iSCSI protocol compliance
- Fix nil pointer dereference in BindISCSISession when existSess is nil
- Fix reversed logic in SPCLuOffline/SPCLuOnline (Online flag was swapped)
- Use negotiated MaxXmitDataSegmentLength for response PDU segmentation (issue #41)
- Fix debug log incorrectly using Warn level in SBCGetLbaStatus

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 12:11:23 +08:00
Lei Xue
00cfac3d24 optimize the perf and support more features 2026-03-14 11:45:35 +08:00
Lei Xue
d94641a8d7 add target port as command flag 2022-12-13 09:49:34 +08:00
Lei Xue
1c9f8d3e06 fix part of golint 2022-12-11 09:59:06 +08:00
Lei Xue
8a3e19f0c9 fix daemon 's host flag 2022-12-10 22:05:19 +08:00
Lei Xue
7745d3ae3b compile with 'ceph' flag to enable/disable cephstore 2022-12-08 17:51:02 +08:00
Lei Xue
82b42798ee Merge pull request #103 from jeremy-gill/master
Add support for block device storage endpoints.
2022-12-08 17:22:37 +08:00
shubham
b278ab3133 Add flag to disable login on multiple hosts
Signed-off-by: shubham <shubham.bajpai@mayadata.io>
2021-06-29 21:15:54 +05:30
Jeremy Gill
a8468ecec8 Resolve travis-ci / gofmt issue with common.go 2020-12-15 11:26:26 -05:00
Jeremy Gill
228e53351d Add support for block device storage endpoints. 2020-09-04 13:28:51 -04:00
Utkarsh Mani Tripathi
7f31722587 Listen on configured IP
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-26 17:45:09 +05:30
Utkarsh Mani Tripathi
583e9b3a4a Add option to disable multipath and other fixes
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-21 13:42:32 +05:30
Utkarsh Mani Tripathi
d7891b1f68 Implement stats and resize and fix remote backing store apis
- Convert constant to var so that it can be configured from backend
- Add options to disable persistent reservation and ORWrite16 commands

Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-20 14:34:35 +05:30
Utkarsh Mani Tripathi
d7caf89610 Implement InitSCSILuMap func for jiva
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-19 10:19:58 +05:30
Utkarsh Mani Tripathi
1b02c7897e fix error handling for unsupported commands
- Respond with failure for unsupported task management commands
- Increase MaxRecvDataSegmentLength to 65536, to match FirstBurstLength

Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-18 18:20:59 +05:30
Utkarsh Mani Tripathi
3b8e996a6c Reply with LUN busy when there is a read/write error from backend
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-18 16:30:46 +05:30
Utkarsh Mani Tripathi
a8cc3e6db2 improve logs and add client (initiator) status
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-18 16:25:55 +05:30
Utkarsh Mani Tripathi
e5339f347a Add nil pointer check for InSDBBuffer
- Gotgt was crashing for few opcodes (sg_inq (sg3-utils)) because InSDBBuffer
  was not initialized for such opcodes (Need help)

Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-18 15:56:34 +05:30
Utkarsh Mani Tripathi
1dbc82435f iSCSI target fixes for iSCSIResiduals tests causing libiscsi test suite to hang
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-18 15:16:41 +05:30
Utkarsh Mani Tripathi
f3ef8c973d add initial implementation of remote backing store
This commit implement the BackingStore Interface for remote backing
store.

Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-11-18 14:52:03 +05:30
Utkarsh Mani Tripathi
4f270eb4d8 fix the scsi inquiry command for TPGS
Signed-off-by: Utkarsh Mani Tripathi <utkarsh.tripathi@mayadata.io>
2019-09-29 07:26:53 +05:30
Lei Xue
5f8aa301ff Merge pull request #86 from datomia/max-unmap-descs
set max unmap block descriptor count to a feasible value
2019-07-04 15:14:20 +08:00
chessman
a83e8ce5c0 REPORT LUNS: truncate response by allocation length 2019-07-03 19:34:49 +03:00
Lei Xue
43deee91c0 Merge pull request #85 from datomia/fix-pool-leak
Fix memory leak
2019-06-30 18:57:44 +08:00
chessman
791e74fea5 don't use pool to allocate buffers 2019-06-28 17:55:51 +03:00
chessman
5582973077 set max unmap block descriptor count to a feasible value 2019-06-28 16:32:26 +03:00
chessman
58fb435e3d add the ability to delete luns at runtime 2019-06-28 13:00:40 +03:00
chessman
93a6cf0c31 add iscsi target driver closer 2019-06-28 13:00:40 +03:00
chessman
f11001ec71 add the ability to add luns dynamically 2019-06-28 13:00:40 +03:00
chessman
0b1ffd5704 provide offset and tl to DataSync 2019-06-27 19:54:16 +03:00
chessman
a5aba61803 move cephstore to a separate package 2019-06-13 13:23:13 +03:00
chessman
8d17243b3a update dependencies 2019-06-12 19:10:59 +03:00
Lei Xue
3a9dceae6e Merge pull request #79 from datomia/thin-provisioned-lun
enable UNMAP when LUN is thin provisioned
2019-06-10 18:17:52 +08:00
chessman
e2b7ea4891 rename: Thinprovisioning -> ThinProvisioning 2019-06-10 12:42:21 +03:00
chessman
c8962b89db MODE SENSE: ALLOCATION LENGTH shouldn't affect a size in response 2019-05-31 14:09:32 +03:00
chessman
c2184d789f add Logical Block Provisioning VPD page (0xB2) 2019-05-30 17:41:10 +03:00
chessman
12b06c21ef UNMAP: propagate request to backing store 2019-05-29 16:14:31 +03:00
chessman
22d47a9212 enable UNMAP when LUN is thin provisioned
- support Block Limits VPD page (0xB0)
 - add UNMAP to REPORT SUPPORTED OPERATION CODES
 - READ CAPACITY(16): set LBPME when Thin provisioning is enabled
 - move Thinprovisioning and BlockShift to config
 - add Unmap to BackingStore
2019-05-28 13:53:06 +03:00
xgwang
29b6c29902 Fix typo of fmt format 2018-05-10 10:30:12 +08:00
Lei Xue
ff9541bc1d Merge pull request #71 from orzhang/ceph
add ceph backing store
2018-03-03 14:32:07 +08:00
Le Zhang
a969203cba add ceph backing store plugin 2018-03-03 14:20:23 +08:00
Donald Tang
6d2a114697 add lock for SCSI Target Service instance 2017-12-10 23:16:48 +08:00