aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-01-21 02:34:42 -0800
committerchrislu <chris.lu@gmail.com>2022-01-21 02:34:42 -0800
commite47f63d15987d38bc721fa06dac137f51e78562d (patch)
tree1ae0c338c9897354c7b85c408a7222e819dfd93c
parent6e57d8d0de6863fd8488eceee621f52d149374b2 (diff)
downloadseaweedfs-e47f63d15987d38bc721fa06dac137f51e78562d.tar.xz
seaweedfs-e47f63d15987d38bc721fa06dac137f51e78562d.zip
enforce bucket quota
-rw-r--r--weed/shell/command_s3_bucket_quota_check.go30
1 files changed, 14 insertions, 16 deletions
diff --git a/weed/shell/command_s3_bucket_quota_check.go b/weed/shell/command_s3_bucket_quota_check.go
index fc8291148..3620b92ed 100644
--- a/weed/shell/command_s3_bucket_quota_check.go
+++ b/weed/shell/command_s3_bucket_quota_check.go
@@ -11,28 +11,28 @@ import (
)
func init() {
- Commands = append(Commands, &commandS3BucketQuotaCheck{})
+ Commands = append(Commands, &commandS3BucketQuotaEnforce{})
}
-type commandS3BucketQuotaCheck struct {
+type commandS3BucketQuotaEnforce struct {
}
-func (c *commandS3BucketQuotaCheck) Name() string {
- return "s3.bucket.quota.check"
+func (c *commandS3BucketQuotaEnforce) Name() string {
+ return "s3.bucket.quota.enforce"
}
-func (c *commandS3BucketQuotaCheck) Help() string {
+func (c *commandS3BucketQuotaEnforce) Help() string {
return `check quota for all buckets, make the bucket read only if over the limit
Example:
- s3.bucket.quota.check -force
+ s3.bucket.quota.enforce -apply
`
}
-func (c *commandS3BucketQuotaCheck) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
+func (c *commandS3BucketQuotaEnforce) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
bucketCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
- enforceQuotaLimit := bucketCommand.Bool("force", false, "actually change the buckets readonly attribute")
+ applyQuotaLimit := bucketCommand.Bool("apply", false, "actually change the buckets readonly attribute")
if err = bucketCommand.Parse(args); err != nil {
return nil
}
@@ -79,11 +79,14 @@ func (c *commandS3BucketQuotaCheck) Do(args []string, commandEnv *CommandEnv, wr
}
// apply the configuration changes
- if hasConfChanges && *enforceQuotaLimit {
+ if hasConfChanges && *applyQuotaLimit {
var buf2 bytes.Buffer
fc.ToText(&buf2)
+ fmt.Fprintf(writer, string(buf2.Bytes()))
+ fmt.Fprintln(writer)
+
if err = commandEnv.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
return filer.SaveInsideFiler(client, filer.DirectoryEtcSeaweedFS, filer.FilerConfName, buf2.Bytes())
}); err != nil && err != filer_pb.ErrNotFound {
@@ -95,16 +98,11 @@ func (c *commandS3BucketQuotaCheck) Do(args []string, commandEnv *CommandEnv, wr
}
-func (c *commandS3BucketQuotaCheck) processEachBucket(fc *filer.FilerConf, filerBucketsPath string, entry *filer_pb.Entry, writer io.Writer, collectionSize uint64) (hasConfChanges bool) {
+func (c *commandS3BucketQuotaEnforce) processEachBucket(fc *filer.FilerConf, filerBucketsPath string, entry *filer_pb.Entry, writer io.Writer, collectionSize uint64) (hasConfChanges bool) {
locPrefix := filerBucketsPath + "/" + entry.Name + "/"
locConf := fc.MatchStorageRule(locPrefix)
- if locConf == nil {
- locConf = &filer_pb.FilerConf_PathConf{
- LocationPrefix: locPrefix,
- Collection: entry.Name,
- }
- }
+ locConf.LocationPrefix = locPrefix
if entry.Quota > 0 {
if locConf.ReadOnly {