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

add persistent handles with pre-generation on background #109

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions cmd/windows_agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func main() {
}

prg := &agentService{}
prg.pregenStatus = make(map[string]bool)
watchdog := newWatchdogService(prg)

s, err := service.New(watchdog, svcConfig)
Expand Down
37 changes: 33 additions & 4 deletions cmd/windows_agent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
"github.com/kardianos/service"
"github.com/sonroyaalmerol/pbs-plus/internal/agent"
"github.com/sonroyaalmerol/pbs-plus/internal/agent/controllers"
"github.com/sonroyaalmerol/pbs-plus/internal/agent/nfs/vssfs"
"github.com/sonroyaalmerol/pbs-plus/internal/agent/registry"
"github.com/sonroyaalmerol/pbs-plus/internal/store/constants"
"github.com/sonroyaalmerol/pbs-plus/internal/syslog"
"github.com/sonroyaalmerol/pbs-plus/internal/utils"
"github.com/sonroyaalmerol/pbs-plus/internal/websockets"
Expand All @@ -41,10 +43,12 @@ type AgentDrivesRequest struct {
}

type agentService struct {
svc service.Service
ctx context.Context
cancel context.CancelFunc
wg sync.WaitGroup
svc service.Service
ctx context.Context
cancel context.CancelFunc
wg sync.WaitGroup
pregenMu sync.Mutex
pregenStatus map[string]bool
}

func (p *agentService) Start(s service.Service) error {
Expand Down Expand Up @@ -177,6 +181,31 @@ func (p *agentService) initializeDrives() error {
if err != nil {
return fmt.Errorf("failed to get local drives list: %w", err)
}
for _, drive := range drives {
p.pregenMu.Lock()
pregenStatus, ok := p.pregenStatus[drive.Letter]
if pregenStatus && ok {
p.pregenMu.Unlock()
continue
}
p.pregenStatus[drive.Letter] = true
p.pregenMu.Unlock()

driveLetter := drive.Letter
go func(letter string) {
defer func() {
p.pregenMu.Lock()
p.pregenStatus[letter] = false
p.pregenMu.Unlock()
}()
constants.RegenPauseChannels[letter] = make(chan struct{})
if err := vssfs.PreGenerateHandles(p.ctx, fmt.Sprintf("%s:\\", letter), constants.RegenPauseChannels[letter]); err != nil {
if err != context.Canceled {
syslog.L.Errorf("Handle pre-generator (%s) error: %v", letter, err)
}
}
}(driveLetter)
}

reqBody, err := json.Marshal(&AgentDrivesRequest{
Hostname: hostname,
Expand Down
15 changes: 12 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@ require (
github.com/alexflint/go-filemutex v1.3.0
github.com/billgraziano/dpapi v0.5.0
github.com/coder/websocket v1.8.12
github.com/cyphar/filepath-securejoin v0.3.6
github.com/dgraph-io/badger/v4 v4.5.1
github.com/fsnotify/fsnotify v1.8.0
github.com/getlantern/systray v1.2.2
github.com/go-git/go-billy/v5 v5.6.2
github.com/gobwas/glob v0.2.3
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/kardianos/service v1.2.2
github.com/mxk/go-vss v1.2.0
github.com/stretchr/testify v1.10.0
github.com/willscott/go-nfs v0.0.3-0.20241211060635-96c060392d22
github.com/zeebo/xxh3 v1.0.2
golang.org/x/crypto v0.32.0
golang.org/x/sys v0.29.0
golang.org/x/time v0.9.0
)

require (
github.com/cyphar/filepath-securejoin v0.3.6 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgraph-io/ristretto/v2 v2.1.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 // indirect
github.com/getlantern/errors v0.0.0-20190325191628-abdb3e3e36f7 // indirect
github.com/getlantern/golog v0.0.0-20190830074920-4ef2e798c2d7 // indirect
Expand All @@ -32,12 +36,17 @@ require (
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/google/flatbuffers v24.12.23+incompatible // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93 // indirect
github.com/willscott/go-nfs-client v0.0.0-20240104095149-b44639837b00 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.34.0 // indirect
google.golang.org/protobuf v1.36.3 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading