Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues 1179 and 1182 #1232

Merged
merged 941 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
941 commits
Select commit Hold shift + click to select a range
1832594
Clean up formatting
uweseimet Sep 22, 2023
47874cf
Update logging
uweseimet Sep 23, 2023
83e9e76
Remove duplicate code
uweseimet Sep 23, 2023
389ce38
Update comment
uweseimet Sep 23, 2023
52f2210
Remove duplicate code
uweseimet Sep 23, 2023
7f4efe2
Cleanup
uweseimet Sep 23, 2023
24e0e24
Remove duplicate code
uweseimet Sep 23, 2023
1644f1d
Update unit test
uweseimet Sep 23, 2023
5bc4d99
Unit test update
uweseimet Sep 23, 2023
b93107e
Clean up includes
uweseimet Sep 23, 2023
cd21b5c
Update comment
uweseimet Sep 23, 2023
0641153
Update include file order
uweseimet Sep 23, 2023
5c51709
Merge ProtobufSerializer into protobuf_util namespace
uweseimet Sep 23, 2023
6a356a0
Precompile regex
uweseimet Sep 23, 2023
44db3bc
Add const
uweseimet Sep 23, 2023
25e5d34
Add unit test
uweseimet Sep 23, 2023
9815e6e
Add Split() convenience method, update log level/ID parsing
uweseimet Sep 23, 2023
3878463
Update logging
uweseimet Sep 23, 2023
94f9b86
Use Split()
uweseimet Sep 23, 2023
8cea190
Use Split()
uweseimet Sep 23, 2023
098930f
Use Split()
uweseimet Sep 23, 2023
4577ea3
Update Split()
uweseimet Sep 23, 2023
d07d6fb
Update unit test
uweseimet Sep 23, 2023
ec13007
Use Split()
uweseimet Sep 23, 2023
db15f55
Use Split()
uweseimet Sep 23, 2023
c6579be
Fall through
uweseimet Sep 23, 2023
56e9725
Cleanup
uweseimet Sep 23, 2023
2fce486
Fix SonarQube issues
uweseimet Sep 24, 2023
a4e328e
Update unit test
uweseimet Sep 24, 2023
35e08fc
Clean up ID/LUN checks
uweseimet Sep 24, 2023
4902b0d
Add convenience method and unit test
uweseimet Sep 24, 2023
de98e86
Add unit test
uweseimet Sep 24, 2023
5c558bd
Add unit test
uweseimet Sep 24, 2023
a419e5d
Move log.h to legacy folder
uweseimet Sep 24, 2023
c6faaf3
Update TODO
uweseimet Sep 24, 2023
8d5a03c
Add unit test
uweseimet Sep 24, 2023
c789363
Revert "Add unit test"
uweseimet Sep 24, 2023
5805519
Update unit test
uweseimet Sep 24, 2023
f84b465
Update unit test
uweseimet Sep 24, 2023
e6c7db1
Use Split() to extract inet address and netmask
uweseimet Sep 25, 2023
8df3c69
Extract method
uweseimet Sep 25, 2023
51da822
Address SonarQube issue by extracting method
uweseimet Sep 25, 2023
639e82c
Fix SonarQube issue
uweseimet Sep 25, 2023
c5edfaf
Fix SonarQuibe issue
uweseimet Sep 25, 2023
e7300e9
Update logging
uweseimet Sep 25, 2023
fbe066c
Update logging
uweseimet Sep 25, 2023
f2f76b9
Fix SonarQube issue
uweseimet Sep 25, 2023
d543b77
Fix typo
uweseimet Sep 25, 2023
dd938e8
Cleanup
uweseimet Sep 25, 2023
fb3d6eb
Renaming
uweseimet Sep 25, 2023
f13a758
Suppress warning about missing bullseye compiler feature
uweseimet Sep 25, 2023
5e0c1f3
Update header file handling
uweseimet Sep 25, 2023
dcb160c
Add ifdefs
uweseimet Sep 25, 2023
93e3252
Cleanup
uweseimet Sep 25, 2023
cac1095
Add ifdef
uweseimet Sep 25, 2023
80914d2
Add ifdef
uweseimet Sep 25, 2023
001d212
Revert "Add ifdef"
uweseimet Sep 25, 2023
e46c7e3
Add ifdef
uweseimet Sep 25, 2023
877d49f
Move ifdef
uweseimet Sep 25, 2023
196797f
Fix typo
uweseimet Sep 25, 2023
0a0a734
Add include file
uweseimet Sep 25, 2023
c29bbce
Add ifdef
uweseimet Sep 25, 2023
ac1563a
Remove ifdef
uweseimet Sep 25, 2023
06361a2
Add includes
uweseimet Sep 25, 2023
b6a6972
Add ifdef
uweseimet Sep 25, 2023
36e7896
Add include
uweseimet Sep 25, 2023
616c3a9
Add ifdef
uweseimet Sep 25, 2023
323eacf
Add ifdef
uweseimet Sep 25, 2023
ea0da87
Add includes
uweseimet Sep 25, 2023
b49d4b6
Add include
uweseimet Sep 25, 2023
ed02f95
Fix SonarQube issues
uweseimet Sep 25, 2023
a3add4d
Fix potential compatibility issue
uweseimet Sep 25, 2023
0c1d695
Try to address SonarQube issue
uweseimet Sep 25, 2023
07c7e95
Elimininate gotos
uweseimet Sep 25, 2023
b3f475c
Update comments
uweseimet Sep 25, 2023
85c9f21
Fixes for gcc 13
uweseimet Sep 25, 2023
7923c74
gcc 13 fix
uweseimet Sep 25, 2023
ed14808
Update compiler flags
uweseimet Sep 27, 2023
a7121b1
Reset C++ level
uweseimet Sep 27, 2023
8a4c18d
Merge branch 'develop' into test_issue_1182
uweseimet Sep 27, 2023
a232b19
Fix merge issue
uweseimet Sep 27, 2023
3d83df2
Remove useless unit test
uweseimet Sep 27, 2023
e929623
Make piscsi run on aarch64, remote interface support only
uweseimet Sep 28, 2023
0565e6f
Update default folder handling
uweseimet Sep 28, 2023
01fa31c
Cleanup
uweseimet Sep 28, 2023
76c8640
Update flushing caches
uweseimet Sep 28, 2023
a537ad5
Cleanup
uweseimet Sep 28, 2023
882b759
Remove duplicate code
uweseimet Sep 28, 2023
8fbc1b5
Use reference
uweseimet Sep 28, 2023
d6c3d34
Cleanup
uweseimet Sep 28, 2023
fdc57f7
Cleanup
uweseimet Sep 28, 2023
e12427c
Cleanup
uweseimet Sep 28, 2023
f53428a
Cleanup
uweseimet Sep 28, 2023
1891dc1
Use reference instead of pointer
uweseimet Sep 28, 2023
88aafc7
Use reference instead of pointer
uweseimet Sep 28, 2023
ff886a8
Update unit tests
uweseimet Sep 28, 2023
ea992b5
Fix SonarQube issues
uweseimet Sep 28, 2023
82d524a
Update comment
uweseimet Sep 28, 2023
d96002e
Renaming
uweseimet Sep 28, 2023
8acc403
Revert "Renaming"
uweseimet Sep 28, 2023
50c9de4
Comment update
uweseimet Sep 28, 2023
0d51207
Add device cleanup
uweseimet Sep 28, 2023
76a0870
Replace reference by pointer
uweseimet Sep 28, 2023
0803ba8
Update reserving files
uweseimet Sep 28, 2023
25937df
Add TODO
uweseimet Sep 28, 2023
222896a
Move code for better encapsulation
uweseimet Sep 28, 2023
4b1d742
Move code
uweseimet Sep 28, 2023
b61b2aa
Update logging
uweseimet Sep 28, 2023
e9a2459
Update disk device cleanup handling
uweseimet Sep 28, 2023
942c6c3
Add TODO
uweseimet Sep 28, 2023
ef9db7a
Cleanup
uweseimet Sep 28, 2023
a712548
Remove unused method argument
uweseimet Sep 28, 2023
a0d4a9c
Fix logging
uweseimet Sep 28, 2023
f7ad994
Remove duplicate code
uweseimet Sep 28, 2023
94c40c4
Update logging
uweseimet Sep 28, 2023
cc7be38
Cleanup
uweseimet Sep 28, 2023
e107c50
Cleanup
uweseimet Sep 28, 2023
1db93d3
Add convenience method
uweseimet Sep 28, 2023
fea884d
Renaming
uweseimet Sep 28, 2023
17d8913
Renaming
uweseimet Sep 28, 2023
526e531
Update logging
uweseimet Sep 28, 2023
bbd5fa6
Formatting update
uweseimet Sep 28, 2023
3aa52a5
Make method private
uweseimet Sep 28, 2023
d0b8d1b
Cleanup
uweseimet Sep 28, 2023
86cf7c9
Update comment
uweseimet Sep 28, 2023
ab03963
Cleanup
uweseimet Sep 28, 2023
b74fa86
Remove obsolete LUN check
uweseimet Sep 28, 2023
5eca40c
Remove obsolete target_id check during selection
uweseimet Sep 28, 2023
56557f4
Update logging
uweseimet Sep 28, 2023
d5b5804
Add TODO
uweseimet Sep 28, 2023
f984320
Revert "Add TODO"
uweseimet Sep 29, 2023
11629e6
Remove useless comment
uweseimet Sep 29, 2023
1be3cbd
Remove useless comments
uweseimet Sep 29, 2023
e375706
Optimize error handling and block count handling
uweseimet Sep 29, 2023
d8ce09d
Update logging
uweseimet Sep 29, 2023
87e9235
Remove duplicate code
uweseimet Sep 29, 2023
7a68fe7
Update default folder handling
uweseimet Sep 29, 2023
1d93741
Update logging
uweseimet Sep 29, 2023
dd75f56
Remove duplicate code
uweseimet Sep 29, 2023
75372d2
Fix formatting
uweseimet Sep 29, 2023
35e202e
Update logging
uweseimet Sep 29, 2023
1b867e3
Update data types
uweseimet Sep 29, 2023
855b211
Update unit test
uweseimet Sep 29, 2023
6f553e1
Renaming
uweseimet Sep 29, 2023
fd4bd74
Remove obsolete comment
uweseimet Sep 29, 2023
aba44a9
Add const
uweseimet Sep 29, 2023
8d18408
Update logging
uweseimet Sep 29, 2023
8cc83d1
Update logging
uweseimet Sep 29, 2023
9631e9c
Remove obsolete comment
uweseimet Sep 29, 2023
0681215
Renaming
uweseimet Sep 29, 2023
e4babd8
Remove obsolete constant
uweseimet Sep 29, 2023
87b0a38
Move device logger
uweseimet Sep 29, 2023
9d7c592
Remove TODO
uweseimet Sep 29, 2023
2d5c187
Revert "Remove TODO"
uweseimet Sep 29, 2023
0d276b5
Add convenience methods
uweseimet Sep 29, 2023
abc9b2e
Revert change
uweseimet Sep 29, 2023
d02fcb0
Add TODO
uweseimet Sep 29, 2023
ce383c5
Clean up unit test
uweseimet Sep 29, 2023
e0d2bcc
Resolve TODO
uweseimet Sep 29, 2023
9ecacdc
Resolve TODO
uweseimet Sep 29, 2023
738886c
Add TODO
uweseimet Sep 29, 2023
3db2272
Update unit test
uweseimet Sep 29, 2023
c5fa444
Unit test update
uweseimet Sep 29, 2023
a2f81ca
Update unit test
uweseimet Sep 29, 2023
c3c103b
Renaming
uweseimet Sep 29, 2023
81ff1f2
Fix SonarQube issue
uweseimet Sep 29, 2023
d9ccfe7
Fix formatting
uweseimet Sep 29, 2023
ea62921
Update unit tests
uweseimet Sep 29, 2023
9803d23
Update logging
uweseimet Oct 1, 2023
eb067fc
Data type update
uweseimet Oct 1, 2023
a57eafd
Fix typo
uweseimet Oct 1, 2023
100646b
Add const
uweseimet Oct 1, 2023
606cdde
Remove redundant to_string
uweseimet Oct 1, 2023
9b8220b
Cleanup
uweseimet Oct 1, 2023
0d7beab
Rename for consistency
uweseimet Oct 1, 2023
8b89736
Move method
uweseimet Oct 1, 2023
8425919
Remove unused include
uweseimet Oct 1, 2023
2bc0131
Replace hard-coded constant
uweseimet Oct 1, 2023
49a4d31
Update handling of protobuf pointers
uweseimet Oct 1, 2023
559fe9d
Update handling of protobuf pointers
uweseimet Oct 1, 2023
086cc78
Add comment
uweseimet Oct 1, 2023
9530722
Update comment
uweseimet Oct 1, 2023
c30033f
Update device property handling
uweseimet Oct 1, 2023
2617d87
Cleanup
uweseimet Oct 1, 2023
d780c50
Simplify protobuf usage
uweseimet Oct 1, 2023
29f6806
Move code
uweseimet Oct 1, 2023
f82ce8f
Revert "Move code"
uweseimet Oct 1, 2023
9d4fc59
Update unit tests
uweseimet Oct 1, 2023
d1f78da
Simplify protobuf handling
uweseimet Oct 1, 2023
8bc6b43
Simplify protobuf handling
uweseimet Oct 1, 2023
e702ec2
Simplify protobuf handling
uweseimet Oct 1, 2023
25b2875
Simplify protobuf handling
uweseimet Oct 1, 2023
b188510
Renaming
uweseimet Oct 1, 2023
d86a176
Simplify protobuf handling
uweseimet Oct 1, 2023
aec5a0d
Simplify protobuf handling
uweseimet Oct 1, 2023
ee1886d
Add unit test
uweseimet Oct 1, 2023
6ab8745
Fix typo
uweseimet Oct 1, 2023
b1728b6
Cleanup
uweseimet Oct 1, 2023
8ff986a
Fix status handling
uweseimet Oct 1, 2023
0035e7a
Memory handling update
uweseimet Oct 1, 2023
68246e3
Update memory handling
uweseimet Oct 1, 2023
91dad4d
Update memory handling
uweseimet Oct 1, 2023
38263fe
Update memory handling
uweseimet Oct 1, 2023
6e82e6b
Formatting update
uweseimet Oct 1, 2023
e7755a4
Add LUN check
uweseimet Oct 1, 2023
40602c1
Fix unit test
uweseimet Oct 1, 2023
3fd4608
Remove obsolete comment
uweseimet Oct 1, 2023
a6a0c1a
Revert "Remove obsolete comment"
uweseimet Oct 1, 2023
47c5e83
Update unit test
uweseimet Oct 1, 2023
09bea58
Update comments
uweseimet Oct 1, 2023
4ffea6b
Update unit test
uweseimet Oct 1, 2023
3081483
Move code
uweseimet Oct 1, 2023
37874e5
Revert "Move code"
uweseimet Oct 1, 2023
dee5dac
Renaming
uweseimet Oct 1, 2023
aed745a
Renaming
uweseimet Oct 1, 2023
9738723
Cleanup
uweseimet Oct 1, 2023
b3fcf1e
Move code
uweseimet Oct 1, 2023
3bcf5df
Update protobuf handling
uweseimet Oct 1, 2023
87c21a9
Trying to address SonarQube issue
uweseimet Oct 1, 2023
af30e37
Renaming
uweseimet Oct 1, 2023
c9cffc9
Merge branch 'develop' into test_issue_1182
uweseimet Oct 1, 2023
51f3a0d
Version bump
uweseimet Oct 2, 2023
f7dd8fd
Merge with develop
uweseimet Oct 2, 2023
2d4c048
Merge recent changes
uweseimet Oct 2, 2023
c924442
Renaming in order to test PR handling
uweseimet Oct 2, 2023
2ddc1a7
Update project key
uweseimet Oct 2, 2023
1d5efa3
Merge branch 'develop' into issue_1182
uweseimet Oct 2, 2023
f13ccbe
Address SonarQube issues
uweseimet Oct 2, 2023
c40afec
Add param_map
uweseimet Oct 2, 2023
70ab42b
Use hasher
uweseimet Oct 2, 2023
2453d8e
Fix SonarQube issue
uweseimet Oct 2, 2023
f4a7137
Fix SonarQube issues
uweseimet Oct 2, 2023
41a12a9
Add hasher
uweseimet Oct 2, 2023
704abcf
Address SonarQube issues
uweseimet Oct 2, 2023
9e2da83
Fix SonarQube issue
uweseimet Oct 2, 2023
5ffe2c5
Fix SonarQube issues
uweseimet Oct 2, 2023
f330e4f
Fix SonarQube issues
uweseimet Oct 2, 2023
1aac323
Fix SonarQube issue
uweseimet Oct 2, 2023
f8498a9
Fix SonarQube issues
uweseimet Oct 2, 2023
cc8d890
Fix SonarQube issue
uweseimet Oct 2, 2023
b51ce47
Address SonarQube issue
uweseimet Oct 2, 2023
440932f
Move declaration
uweseimet Oct 2, 2023
98a76a7
Revert "Move declaration"
uweseimet Oct 2, 2023
393ff9e
Add comment
uweseimet Oct 2, 2023
4376737
Bugfix: Add missing context initialization with default folder
uweseimet Oct 3, 2023
c386be4
Remove debug output
uweseimet Oct 4, 2023
54a2cb7
Revert __arch64__ checks for #1060
uweseimet Oct 11, 2023
df140ff
Merge with develop
uweseimet Oct 11, 2023
9689618
Merge branch 'develop' into issue_1182
uweseimet Oct 11, 2023
54b1ca4
Fix bookworm issue related to method signature
uweseimet Oct 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 15 additions & 25 deletions cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,28 @@
CROSS_COMPILE =

CXX = $(CROSS_COMPILE)g++
AR = $(CROSS_COMPILE)ar
RANLIB = $(CROSS_COMPILE)ranlib

## DEBUG=1 : A Debug build includes the debugger symbols
## and disables compiler optimization. Typically,
## this is only used by developers.
DEBUG ?= 0
ifeq ($(DEBUG), 1)
# Debug compiler flags
CXXFLAGS += -O0 -g -Wall -Wextra -DDEBUG
BUILD_TYPE = Debug
CXXFLAGS += -Og -g -Wall -Wextra -DDEBUG
else
# Release compiler flags
CXXFLAGS += -O3 -Wall -Werror -Wextra -DNDEBUG
BUILD_TYPE = Release
endif
ifeq ("$(shell uname -s)","Linux")
# -Wno-psabi might not work on non-Linux platforms
CXXFLAGS += -Wno-psabi
endif

# Depending on the GCC version the compilation flags differ
GCCVERSION10 := $(shell expr `$(CXX) -dumpversion` \>= 10)

CXXFLAGS += -std=c++17 -iquote . -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -MD -MP
CXXFLAGS += -std=c++20 -iquote . -D_FILE_OFFSET_BITS=64 -DFMT_HEADER_ONLY -DSPDLOG_FMT_EXTERNAL -MD -MP

## EXTRA_FLAGS : Can be used to pass special purpose flags
CXXFLAGS += $(EXTRA_FLAGS)

ifeq "$(GCCVERSION10)" "1"
CXXFLAGS += -DFMT_HEADER_ONLY
endif


## CONNECT_TYPE=FULLSPEC : Specify the type of PiSCSI board type
## that you are using. The typical options are
Expand Down Expand Up @@ -86,12 +75,12 @@ SRC_PROTOC = piscsi_interface.proto
SRC_GENERATED = $(GENERATED_DIR)/piscsi_interface.pb.cpp

SRC_PROTOBUF = \
shared/protobuf_util.cpp \
shared/protobuf_serializer.cpp
shared/protobuf_util.cpp

SRC_SHARED = \
shared/piscsi_version.cpp \
shared/piscsi_util.cpp
shared/piscsi_util.cpp \
shared/network_util.cpp

SRC_PISCSI_CORE = $(shell find ./piscsi -name '*.cpp')
SRC_PISCSI_CORE += $(shell find ./controllers -name '*.cpp')
Expand Down Expand Up @@ -167,7 +156,7 @@ $(SRC_GENERATED) : $(SRC_PROTOC)
protoc --cpp_out=$(GENERATED_DIR) $(SRC_PROTOC)
mv $(GENERATED_DIR)/piscsi_interface.pb.cc $@

$(OBJ_GENERATED) : $(SRC_GENERATED)
$(OBJ_GENERATED) : $(SRC_GENERATED) | $(OBJDIR)
$(CXX) $(CXXFLAGS) -c $< -o $@

## Build Targets:
Expand All @@ -180,10 +169,11 @@ $(OBJ_GENERATED) : $(SRC_GENERATED)
## Note that you have to run 'make clean' before switching
## between coverage and non-coverage builds.
.DEFAULT_GOAL := all
.PHONY: all ALL docs test coverage lcov
all: $(BIN_ALL) docs
.PHONY: all docs test coverage lcov

all: $(SRC_GENERATED) $(BIN_ALL) docs

test: $(BINDIR)/$(PISCSI_TEST)
test: $(SRC_GENERATED) $(BINDIR)/$(PISCSI_TEST)
$(BINDIR)/$(PISCSI_TEST)

coverage: CXXFLAGS += --coverage
Expand All @@ -198,10 +188,10 @@ docs: $(DOC_DIR)/piscsi_man_page.txt $(DOC_DIR)/scsictl_man_page.txt $(DOC_DIR)/

$(SRC_PISCSI_CORE) $(SRC_SCSICTL_CORE) : $(OBJ_GENERATED)

$(BINDIR)/$(PISCSI): $(SRC_GENERATED) $(OBJ_PISCSI_CORE) $(OBJ_PISCSI) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_PISCSI_CORE) $(OBJ_PISCSI) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lpcap -lprotobuf -lstdc++fs
$(BINDIR)/$(PISCSI): $(OBJ_GENERATED) $(OBJ_PISCSI_CORE) $(OBJ_PISCSI) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_PISCSI_CORE) $(OBJ_PISCSI) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lpcap -lprotobuf

$(BINDIR)/$(SCSICTL): $(SRC_GENERATED) $(OBJ_SCSICTL_CORE) $(OBJ_SCSICTL) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(BINDIR)/$(SCSICTL): $(OBJ_GENERATED) $(OBJ_SCSICTL_CORE) $(OBJ_SCSICTL) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_SCSICTL_CORE) $(OBJ_SCSICTL) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lprotobuf

$(BINDIR)/$(SCSIDUMP): $(OBJ_SCSIDUMP) $(OBJ_SHARED) | $(BINDIR)
Expand All @@ -213,8 +203,8 @@ $(BINDIR)/$(SCSIMON): $(OBJ_SCSIMON) $(OBJ_SHARED) | $(BINDIR)
$(BINDIR)/$(SCSILOOP): $(OBJ_SHARED) $(OBJ_SCSILOOP) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJ_SHARED) $(OBJ_SCSILOOP)

$(BINDIR)/$(PISCSI_TEST): $(SRC_GENERATED) $(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI_TEST) $(OBJ_SCSICTL_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(TEST_WRAPS) -o $@ $(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lpcap -lprotobuf -lstdc++fs -lgmock -lgtest
$(BINDIR)/$(PISCSI_TEST): $(OBJ_GENERATED) $(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI_TEST) $(OBJ_SCSICTL_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) | $(BINDIR)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(TEST_WRAPS) -o $@ $(OBJ_PISCSI_CORE) $(OBJ_SCSICTL_CORE) $(OBJ_PISCSI_TEST) $(OBJ_SHARED) $(OBJ_PROTOBUF) $(OBJ_GENERATED) -lpthread -lpcap -lprotobuf -lgmock -lgtest

# Phony rules for building individual utilities
.PHONY: $(PISCSI) $(SCSICTL) $(SCSIDUMP) $(SCSIMON) $(PISCSI_TEST) $(SCSILOOP)
Expand Down
109 changes: 40 additions & 69 deletions cpp/controllers/abstract_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 Uwe Seimet
// Copyright (C) 2022-2023 Uwe Seimet
//
//---------------------------------------------------------------------------

#include "shared/piscsi_exceptions.h"
#include "devices/primary_device.h"
#include "abstract_controller.h"
#include <ranges>

using namespace scsi_defs;

AbstractController::AbstractController(BUS& bus, int target_id, int max_luns) : bus(bus), target_id(target_id), max_luns(max_luns)
{
device_logger.SetIdAndLun(target_id, -1);
}

void AbstractController::AllocateCmd(size_t size)
{
if (size > ctrl.cmd.size()) {
Expand Down Expand Up @@ -40,9 +46,8 @@ unordered_set<shared_ptr<PrimaryDevice>> AbstractController::GetDevices() const
{
unordered_set<shared_ptr<PrimaryDevice>> devices;

for (const auto& [id, lun] : luns) {
devices.insert(lun);
}
// "luns | views:values" is not supported by the bullseye compiler
ranges::transform(luns, inserter(devices, devices.begin()), [] (const auto& l) { return l.second; } );

return devices;
}
Expand All @@ -56,100 +61,66 @@ void AbstractController::Reset()
{
SetPhase(phase_t::busfree);

ctrl.status = status::GOOD;
ctrl.message = 0x00;
ctrl.blocks = 0;
ctrl.next = 0;
ctrl.offset = 0;
ctrl.length = 0;
ctrl = {};

SetByteTransfer(false);

// Reset all LUNs
for (const auto& [lun, device] : luns) {
for (const auto& [_, device] : luns) {
device->Reset();
}

GetBus().Reset();
}

void AbstractController::ProcessPhase()
void AbstractController::ProcessOnController(int id_data)
{
switch (GetPhase()) {
case phase_t::busfree:
BusFree();
break;

case phase_t::selection:
Selection();
break;

case phase_t::dataout:
DataOut();
break;

case phase_t::datain:
DataIn();
break;

case phase_t::command:
Command();
break;

case phase_t::status:
Status();
break;

case phase_t::msgout:
MsgOut();
break;

case phase_t::msgin:
MsgIn();
break;

default:
throw scsi_exception(sense_key::ABORTED_COMMAND);
break;
device_logger.SetIdAndLun(GetTargetId(), -1);

const int initiator_id = ExtractInitiatorId(id_data);
if (initiator_id != UNKNOWN_INITIATOR_ID) {
LogTrace("++++ Starting processing for initiator ID " + to_string(initiator_id));
}
else {
LogTrace("++++ Starting processing for unknown initiator ID");
}

while (Process(initiator_id)) {
// Handle bus phases until the bus is free for the next command
}
}

bool AbstractController::AddDevice(shared_ptr<PrimaryDevice> device)
{
if (device->GetLun() < 0 || device->GetLun() >= GetMaxLuns() || HasDeviceForLun(device->GetLun())) {
const int lun = device->GetLun();

if (lun < 0 || lun >= GetMaxLuns() || HasDeviceForLun(lun) || device->GetController()) {
return false;
}

luns[device->GetLun()] = device;
device->SetController(shared_from_this());
luns[lun] = device;
device->SetController(this);

return true;
}

bool AbstractController::RemoveDevice(shared_ptr<PrimaryDevice> device)
bool AbstractController::RemoveDevice(PrimaryDevice& device)
{
device->SetController(nullptr);
device.CleanUp();

return luns.erase(device->GetLun()) == 1;
return luns.erase(device.GetLun()) == 1;
}

bool AbstractController::HasDeviceForLun(int lun) const
{
return luns.find(lun) != luns.end();
return luns.contains(lun);
}

int AbstractController::ExtractInitiatorId(int id_data) const
{
int initiator_id = UNKNOWN_INITIATOR_ID;

if (int tmp = id_data - (1 << target_id); tmp) {
initiator_id = 0;
for (int j = 0; j < 8; j++) {
tmp >>= 1;
if (tmp) {
initiator_id++;
}
else {
break;
}
}
if (const int id_data_without_target = id_data - (1 << target_id); id_data_without_target) {
return static_cast<int>(log2(id_data_without_target & -id_data_without_target));
}

return initiator_id;
return UNKNOWN_INITIATOR_ID;
}
Loading
Loading