From 9f04ce282ea4a74ef379278672f1c6afb4b52205 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 24 Apr 2018 09:43:07 +0100 Subject: [PATCH] rc: fix setting bwlimit to unlimited --- fs/accounting/token_bucket.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/accounting/token_bucket.go b/fs/accounting/token_bucket.go index 60005dcc0..124deda70 100644 --- a/fs/accounting/token_bucket.go +++ b/fs/accounting/token_bucket.go @@ -115,6 +115,19 @@ func limitBandwidth(n int) { tokenBucketMu.Unlock() } +// SetBwLimit sets the current bandwidth limit +func SetBwLimit(bandwidth fs.SizeSuffix) { + tokenBucketMu.Lock() + defer tokenBucketMu.Unlock() + if bandwidth > 0 { + tokenBucket = newTokenBucket(bandwidth) + fs.Logf(nil, "Bandwidth limit set to %v", bandwidth) + } else { + tokenBucket = nil + fs.Logf(nil, "Bandwidth limit reset to unlimited") + } +} + // Remote control for the token bucket func init() { rc.Add(rc.Call{ @@ -137,10 +150,7 @@ func init() { return out, errors.New("need exactly 1 bandwidth setting") } bw := bws[0] - tokenBucketMu.Lock() - tokenBucket = newTokenBucket(bw.Bandwidth) - tokenBucketMu.Unlock() - fs.Logf(nil, "Bandwidth limit set to %v", bw.Bandwidth) + SetBwLimit(bw.Bandwidth) return rc.Params{"rate": bw.Bandwidth.String()}, nil }, Title: "Set the bandwidth limit.",