From f91e6bf262065ae7fe62d07e3859a81057af88f6 Mon Sep 17 00:00:00 2001 From: Matthew Mattox Date: Sat, 24 Oct 2026 03:46:48 -0500 Subject: [PATCH 1/3] fix: resolve trivial staticcheck, unused and ineffassign findings Replace deprecated os.SEEK_* with io.Seek*, drop dead code (unused writeRecord, batchSyncInFlight, mock inode table, empty branches, ineffective assignments) and apply two loop/switch simplifications. No behavior change. Co-Authored-By: Claude Opus 5.5 --- internal/cache/broadcast/receiver.go | 5 ++--- internal/cache/cache_test.go | 30 ---------------------------- internal/dir/dir.go | 8 -------- internal/dir/dir_test.go | 2 +- internal/journal/journal.go | 1 - internal/journal/recovery.go | 14 ++----------- internal/lock/lock.go | 14 ------------- internal/refcount/refcount.go | 6 +++--- internal/sfb/sfb.go | 6 ------ internal/storage/device.go | 5 +++-- 10 files changed, 11 insertions(+), 80 deletions(-) diff --git a/internal/cache/broadcast/receiver.go b/internal/cache/broadcast/receiver.go index 6b0e87fc..e3323ee1 100644 --- a/internal/cache/broadcast/receiver.go +++ b/internal/cache/broadcast/receiver.go @@ -252,9 +252,8 @@ func (b *Broadcaster) heartbeatLoop() { return case <-ticker.C: msg := b.builder.Heartbeat() - if err := b.transport.Send(msg); err != nil { - // Heartbeat failures are expected during network issues - } + // Heartbeat failures are expected during network issues + _ = b.transport.Send(msg) } } } diff --git a/internal/cache/cache_test.go b/internal/cache/cache_test.go index 1644f3a9..52d27f06 100644 --- a/internal/cache/cache_test.go +++ b/internal/cache/cache_test.go @@ -3,8 +3,6 @@ package cache import ( "testing" "time" - - "github.com/supporttools/GoClusterFS/internal/inode" ) // TestLRU tests the generic LRU cache implementation. @@ -273,34 +271,6 @@ func TestConfig(t *testing.T) { }) } -// mockInodeTable implements a simple mock for testing cache operations. -type mockInodeTable struct { - inodes map[uint32]*inode.Inode -} - -func newMockInodeTable() *mockInodeTable { - return &mockInodeTable{ - inodes: make(map[uint32]*inode.Inode), - } -} - -func (m *mockInodeTable) Read(inodeNum uint32) (*inode.Inode, error) { - ino, ok := m.inodes[inodeNum] - if !ok { - return &inode.Inode{}, nil // Return empty inode (Magic == 0) - } - return ino, nil -} - -func (m *mockInodeTable) Write(ino *inode.Inode) error { - m.inodes[ino.InodeNum] = ino - return nil -} - -func (m *mockInodeTable) setInode(ino *inode.Inode) { - m.inodes[ino.InodeNum] = ino -} - // Note: Full integration tests for Manager.GetInode require a real inode.Table // which needs storage.Device. Those tests belong in integration tests. // Here we test what we can in isolation. diff --git a/internal/dir/dir.go b/internal/dir/dir.go index 5fde1468..5ac6aa24 100644 --- a/internal/dir/dir.go +++ b/internal/dir/dir.go @@ -290,7 +290,6 @@ func (m *Manager) addInternal(ctx context.Context, dirIno *inode.Inode, entry *D // (bitmap lock level 6 < inode lock level 8) if lockHeld { m.lockMgr.Release(lock.LockTypeInode, uint64(dirIno.InodeNum)) - lockHeld = false } // Allocate block without holding inode lock @@ -355,7 +354,6 @@ func (m *Manager) Remove(ctx context.Context, dirIno *inode.Inode, name string) // Scan for the entry offset := uint32(0) prevOffset := uint32(0) - found := false for offset < uint32(len(data)) { entry, err := parseEntry(data[offset:]) @@ -369,8 +367,6 @@ func (m *Manager) Remove(ctx context.Context, dirIno *inode.Inode, name string) if entry.InodeNum != 0 && entry.Name == name { // Found it - mark as deleted - found = true - // Option 1: Zero the inode number (simple deletion) binary.LittleEndian.PutUint64(data[offset:], 0) @@ -392,10 +388,6 @@ func (m *Manager) Remove(ctx context.Context, dirIno *inode.Inode, name string) prevOffset = offset offset += uint32(entry.RecLen) } - - if found { - break - } } return ErrNotFound diff --git a/internal/dir/dir_test.go b/internal/dir/dir_test.go index 91f0835f..38521c4e 100644 --- a/internal/dir/dir_test.go +++ b/internal/dir/dir_test.go @@ -338,7 +338,7 @@ func TestLookup(t *testing.T) { } // Lookup ".." - ino, ftype, err = dirMgr.Lookup(ctx, dirIno, "..") + ino, _, err = dirMgr.Lookup(ctx, dirIno, "..") if err != nil { t.Fatalf("Lookup(..) failed: %v", err) } diff --git a/internal/journal/journal.go b/internal/journal/journal.go index 93df568b..705d1964 100644 --- a/internal/journal/journal.go +++ b/internal/journal/journal.go @@ -113,7 +113,6 @@ type Journal struct { batchFirstCommit time.Time // Time of first commit in current batch batchSyncCond *sync.Cond // Signals waiting goroutines when batch syncs batchSyncTimer *time.Timer // Timer for MaxBatchAge - batchSyncInFlight bool // True if a batch sync is in progress batchSyncWaiters []chan struct{} // Channels waiting for current batch sync // Metrics diff --git a/internal/journal/recovery.go b/internal/journal/recovery.go index a6896178..79248c24 100644 --- a/internal/journal/recovery.go +++ b/internal/journal/recovery.go @@ -92,12 +92,7 @@ func Recover(region *Region, handler RecoveryHandler) (*RecoveryStats, error) { // Records are identified by IntentCompletionMagic (0x43544E49 "INTC"). func scanForCompletions(region *Region, head, tail, dataAreaSize uint32, completed map[uint64]bool, stats *RecoveryStats) error { pos := head - for { - // Check if we've reached the tail - if pos == tail { - break - } - + for pos != tail { // Handle wrap-around if pos >= dataAreaSize { pos = 0 @@ -181,12 +176,7 @@ func scanJournal(region *Region, handler RecoveryHandler, stats *RecoveryStats) // Phase 2: Replay transactions that are not completed pos := head - for { - // Check if we've reached the tail - if pos == tail { - break - } - + for pos != tail { // Handle wrap-around if pos >= dataAreaSize { pos = 0 diff --git a/internal/lock/lock.go b/internal/lock/lock.go index 450407f4..042fed5f 100644 --- a/internal/lock/lock.go +++ b/internal/lock/lock.go @@ -710,20 +710,6 @@ func (m *Manager) readRecord(recordID uint64) (*Record, error) { return deserializeRecord(buf.Bytes()) } -// writeRecord writes a lock record to disk. -func (m *Manager) writeRecord(recordID uint64, record *Record) error { - offset := int64(m.offset) + int64(recordID)*RecordSize - - data := serializeRecord(record) - - buf := storage.GetBuffer(RecordSize) - defer storage.PutBuffer(buf) - copy(buf.Bytes(), data) - - _, err := m.dev.WriteAt(buf.Bytes(), offset) - return err -} - // casRecordOptimistic performs an optimistic CAS using only the expected sequence. // It writes the new record directly, then reads back to verify the sequence. // Returns true if the write succeeded (sequence matched), false if stale. diff --git a/internal/refcount/refcount.go b/internal/refcount/refcount.go index 34e8c717..7c221f91 100644 --- a/internal/refcount/refcount.go +++ b/internal/refcount/refcount.go @@ -414,10 +414,10 @@ func (r *Region) Scan(ctx context.Context) (stats ScanStats, err error) { } entry := decodeEntry(sectorData, entryIdx) - switch { - case entry.RefCount == 0: + switch entry.RefCount { + case 0: stats.FreeBlocks++ - case entry.RefCount == 1: + case 1: stats.ExclusiveBlocks++ default: stats.SharedBlocks++ diff --git a/internal/sfb/sfb.go b/internal/sfb/sfb.go index 9ade7df7..6abc48d5 100644 --- a/internal/sfb/sfb.go +++ b/internal/sfb/sfb.go @@ -439,12 +439,6 @@ func (m *Manager) FreeSlot(ctx context.Context, containerBlock uint64, slotIndex m.addToFreeList(container.Header.Tier, containerBlock) } - // If container is now completely empty, consider recycling the block - if container.Header.FreeSlots == container.Header.SlotCount { - // For now, keep empty containers in the pool for reuse. - // A background garbage collector could reclaim them later. - } - return nil } diff --git a/internal/storage/device.go b/internal/storage/device.go index 7283302b..3b4de6e4 100644 --- a/internal/storage/device.go +++ b/internal/storage/device.go @@ -8,6 +8,7 @@ package storage import ( "fmt" + "io" "os" "sync" "syscall" @@ -122,14 +123,14 @@ func Open(path string) (*Device, error) { } // Get device size - size, err := file.Seek(0, os.SEEK_END) + size, err := file.Seek(0, io.SeekEnd) if err != nil { file.Close() return nil, fmt.Errorf("failed to get device size: %w", err) } // Rewind to start - if _, err := file.Seek(0, os.SEEK_SET); err != nil { + if _, err := file.Seek(0, io.SeekStart); err != nil { file.Close() return nil, fmt.Errorf("failed to seek to start: %w", err) } From c877eda74fa4c67d4957b923b72f9232f82385f2 Mon Sep 17 00:00:00 2001 From: Matthew Mattox Date: Sat, 24 Oct 2026 03:46:48 -0500 Subject: [PATCH 2/3] ci: add race, coverage, lint, govulncheck and tidy gates - Unit tests run with -race and print coverage to the job summary. - golangci-lint v2.15.0 and govulncheck v1.9.0 are pinned; make lint and make vuln run the same versions and config as CI. - CI installs the latest Go 1.26 patch and checks it matches go.mod. Go 1.26.0, which go-version-file picked, has two stdlib vulns that govulncheck reports as reachable. - Pin all actions to commit SHAs and default the token to read-only; only the Docker job gets checks: write for the JUnit report. - Add build-fsck to make build, drop the legacy GoClusterFS binary from clean, and anchor .gitignore entries so they stop hiding new files in internal/goclusterfs, internal/fsck, cmd/fsck and cmd/mount. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 85 ++++++++++++++++++++++-- .github/workflows/docker-integration.yml | 14 ++-- .gitignore | 12 ++-- .golangci.yml | 38 +++++++++++ Makefile | 32 ++++++--- 5 files changed, 156 insertions(+), 25 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73389e01..ed1e0eb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,18 +6,26 @@ on: pull_request: branches: [main, master] +permissions: + contents: read + +env: + GO_VERSION: "1.26" + GOLANGCI_LINT_VERSION: v2.15.0 + jobs: build-and-unit-test: name: Build and Unit Tests runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up Go - uses: actions/setup-go@v5 + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 with: - go-version-file: go.mod + go-version: ${{ env.GO_VERSION }} + check-latest: true cache: true - name: Download dependencies @@ -38,7 +46,69 @@ jobs: fi - name: Unit Tests - run: make test-unit + shell: bash + run: make test-unit 2>&1 | tee unit-test.log + + - name: Coverage summary + run: | + { + echo "## Unit test coverage" + echo + echo "**Total: $(go tool cover -func=coverage.out | awk '/^total:/ {print $NF}')**" + echo + echo "| Package | Coverage |" + echo "| --- | --- |" + awk '$1 == "ok" && $4 == "coverage:" {print "| " $2 " | " $5 " |"}' unit-test.log + } >> "$GITHUB_STEP_SUMMARY" + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Set up Go + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version: ${{ env.GO_VERSION }} + check-latest: true + cache: true + + - name: Check Go version matches go.mod + run: | + gomod=$(go list -m -f '{{.GoVersion}}' | cut -d. -f1,2) + if [ "$gomod" != "$GO_VERSION" ]; then + echo "::error file=go.mod::go.mod requires Go $gomod but CI uses Go $GO_VERSION. Update GO_VERSION in .github/workflows/ci.yml." + exit 1 + fi + + - name: golangci-lint + uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 + with: + version: ${{ env.GOLANGCI_LINT_VERSION }} + + - name: Check go.mod and go.sum are tidy + run: | + go mod tidy + git diff --exit-code go.mod go.sum + + govulncheck: + name: Vulnerability Check + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - name: Set up Go + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version: ${{ env.GO_VERSION }} + check-latest: true + cache: true + + - name: Run govulncheck + run: make vuln integration-tests: name: Integration Tests @@ -46,12 +116,13 @@ jobs: needs: build-and-unit-test steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up Go - uses: actions/setup-go@v5 + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 with: - go-version-file: go.mod + go-version: ${{ env.GO_VERSION }} + check-latest: true cache: true - name: Install FUSE diff --git a/.github/workflows/docker-integration.yml b/.github/workflows/docker-integration.yml index deeae038..f9b4dba0 100644 --- a/.github/workflows/docker-integration.yml +++ b/.github/workflows/docker-integration.yml @@ -11,18 +11,24 @@ on: # Allow manual trigger workflow_dispatch: +permissions: + contents: read + jobs: docker-multinode-tests: name: Multi-Node Docker Tests runs-on: ubuntu-latest timeout-minutes: 15 + permissions: + contents: read + checks: write steps: - name: Checkout code - uses: actions/checkout@v4 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1 - name: Build test images run: | @@ -111,14 +117,14 @@ jobs: - name: Upload test results if: always() - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: docker-test-results path: tests/docker/results/ retention-days: 7 - name: Publish Test Report - uses: mikepenz/action-junit-report@v4 + uses: mikepenz/action-junit-report@6ef3fdcfcd5f0b5d14df3e659ef19b8c6820f93d # v6.6.1 if: always() with: report_paths: 'tests/docker/results/junit.xml' diff --git a/.gitignore b/.gitignore index 224beda6..dc7ea205 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ # Build artifacts -goclusterfs -goclusterfs-mount -GoClusterFS +/goclusterfs +/goclusterfs-mount +/goclusterfs-fsck +/GoClusterFS +/coverage.out # Test artifacts *.img @@ -20,9 +22,9 @@ Thumbs.db # Go vendor/ -mount +/mount # VM test runtime artifacts tests/vm/runtime/ tests/vm/results/ -fsck +/fsck diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..333fc989 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,38 @@ +version: "2" + +linters: + default: none + enable: + - govet + - ineffassign + - staticcheck + - unused + settings: + staticcheck: + checks: + - all + - -ST1000 + - -ST1003 + - -ST1016 + - -ST1020 + - -ST1021 + - -ST1022 + - -QF1008 + exclusions: + # Known findings as of 2026-10-24 in code other open PRs are changing; delete each rule once fixed. + rules: + - path: ^main\.go$ + linters: [staticcheck] + text: "SA1019: os\\.SEEK_" + - path: ^internal/goclusterfs/fs\.go$ + linters: [unused] + text: "errRetryCreate|field sb is unused" + - path: ^internal/extent/extent_test\.go$ + linters: [staticcheck] + text: "SA4006: this value of found is never used" + - path: ^internal/fsck/phase7_snapshots\.go$ + linters: [staticcheck] + text: "SA9003" + - path: ^internal/dir/dir_test\.go$ + linters: [staticcheck] + text: "SA1019: .*inode\\.Table\\)\\.Alloc is deprecated" diff --git a/Makefile b/Makefile index 277229c1..f8cefc2c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # GoClusterFS Makefile # Build and test automation for the distributed filesystem -.PHONY: build build-mount test test-unit test-integration test-all test-parity test-multinode-docker docker-build-test docker-clean-test test-multinode-vm vm-clean clean fmt vet check-fuse check-qemu lint help +.PHONY: build build-mount build-fsck test test-unit test-integration test-all test-parity test-multinode-docker docker-build-test docker-clean-test test-multinode-vm vm-clean clean fmt vet check-fuse check-qemu lint vuln help # Go parameters GOCMD=go @@ -13,24 +13,34 @@ GOMOD=$(GOCMD) mod # Binary names MOUNT_BINARY=goclusterfs-mount +FSCK_BINARY=goclusterfs-fsck + +GOLANGCI_LINT_VERSION=v2.15.0 +GOVULNCHECK_VERSION=v1.9.0 +COVER_PROFILE=coverage.out # Default target .DEFAULT_GOAL := help # Build all binaries -build: build-mount +build: build-mount build-fsck build-mount: @echo "Building $(MOUNT_BINARY)..." $(GOBUILD) -o $(MOUNT_BINARY) ./cmd/mount @echo "Built $(MOUNT_BINARY) successfully" +build-fsck: + @echo "Building $(FSCK_BINARY)..." + $(GOBUILD) -o $(FSCK_BINARY) ./cmd/fsck + @echo "Built $(FSCK_BINARY) successfully" + # Unit tests (fast, no FUSE needed) test: test-unit test-unit: - @echo "Running unit tests..." - $(GOTEST) -v ./internal/... + @echo "Running unit tests with race detector..." + $(GOTEST) -v -race -covermode=atomic -coverprofile=$(COVER_PROFILE) ./internal/... # Integration tests (requires FUSE and built binary) test-integration: check-fuse build-mount @@ -148,14 +158,16 @@ check-fuse: @which fusermount > /dev/null 2>&1 || (echo "Error: fusermount not found. Install FUSE first." && exit 1) @echo "FUSE is available" -# Run linter (if golangci-lint is installed) lint: - @which golangci-lint > /dev/null 2>&1 && golangci-lint run ./... || echo "golangci-lint not installed, skipping" + $(GOCMD) run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run ./... + +vuln: + $(GOCMD) run golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION) ./... # Utilities clean: @echo "Cleaning build artifacts..." - rm -f $(MOUNT_BINARY) GoClusterFS + rm -f $(MOUNT_BINARY) $(FSCK_BINARY) $(COVER_PROFILE) rm -f *.img @echo "Clean complete" @@ -181,10 +193,11 @@ help: @echo " Build:" @echo " build - Build all binaries" @echo " build-mount - Build goclusterfs-mount binary" + @echo " build-fsck - Build goclusterfs-fsck binary" @echo "" @echo " Test:" @echo " test - Run unit tests (alias for test-unit)" - @echo " test-unit - Run unit tests only (fast, no FUSE needed)" + @echo " test-unit - Run unit tests with race detector and coverage (no FUSE needed)" @echo " test-integration - Run integration tests (requires FUSE)" @echo " test-all - Run all tests (unit + integration)" @echo " test-parity - Validate test coverage across environments" @@ -207,7 +220,8 @@ help: @echo " Code Quality:" @echo " fmt - Format code with go fmt" @echo " vet - Run go vet" - @echo " lint - Run golangci-lint (if installed)" + @echo " lint - Run golangci-lint $(GOLANGCI_LINT_VERSION) with .golangci.yml" + @echo " vuln - Run govulncheck $(GOVULNCHECK_VERSION)" @echo "" @echo " Utilities:" @echo " clean - Remove build artifacts" From 214be20c97166374c9f3add74287d2e93d5c7959 Mon Sep 17 00:00:00 2001 From: Matthew Mattox Date: Sat, 24 Oct 2026 03:48:27 -0500 Subject: [PATCH 3/3] ci: raise Docker multi-node test timeout to 20 minutes The test step took 446-496s on the last four green runs, up to 83% of the 600s orchestrator wait, and PR #4 run 40077489458 ran past it during "Stress Random Failures". Raise the wait to 1200s and the step and job limits to match. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/docker-integration.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-integration.yml b/.github/workflows/docker-integration.yml index f9b4dba0..d4ce7d23 100644 --- a/.github/workflows/docker-integration.yml +++ b/.github/workflows/docker-integration.yml @@ -18,7 +18,7 @@ jobs: docker-multinode-tests: name: Multi-Node Docker Tests runs-on: ubuntu-latest - timeout-minutes: 15 + timeout-minutes: 30 permissions: contents: read checks: write @@ -58,9 +58,9 @@ jobs: docker compose -f tests/docker/docker-compose.test.yml up -d \ node1 node2 node3 node4 orchestrator - # Wait for orchestrator to complete (poll every 5s, timeout 10min) + # Wait for orchestrator to complete (poll every 5s, timeout 20min) echo "Waiting for orchestrator to complete..." - TIMEOUT=600 + TIMEOUT=1200 ELAPSED=0 while [ $ELAPSED -lt $TIMEOUT ]; do # Check if orchestrator is still running @@ -97,7 +97,7 @@ jobs: docker logs goclusterfs-orchestrator 2>&1 >> tests/docker/results/container-logs.txt || true docker compose -f tests/docker/docker-compose.test.yml down exit 1 - timeout-minutes: 12 + timeout-minutes: 22 - name: Collect logs on failure if: failure()