forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fix_quota_id tool to fix multi quota id for one volume or mount path. Signed-off-by: Rudy Zhang <[email protected]>
- Loading branch information
1 parent
638b38f
commit 023f02b
Showing
2 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/alibaba/pouch/storage/quota" | ||
|
||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
dir string | ||
size string | ||
quotaID uint32 | ||
recursive bool | ||
) | ||
|
||
func run(cmd *cobra.Command) error { | ||
_, err := quota.StartQuotaDriver(dir) | ||
if err != nil { | ||
logrus.Errorf("failed to start quota driver for %s, err: %v", dir, err) | ||
return err | ||
} | ||
|
||
err = quota.SetDiskQuota(dir, size, quotaID) | ||
if err != nil { | ||
logrus.Errorf("failed to set subtree for %s, quota id: %d, err: %v", dir, quotaID, err) | ||
return err | ||
} | ||
|
||
if !recursive { | ||
return nil | ||
} | ||
|
||
if err := quota.SetQuotaForDir(dir, quotaID); err != nil { | ||
logrus.Errorf("failed to set quota id for %s recursively, quota id: %d, err: %v", dir, quotaID, err) | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func setupFlags(cmd *cobra.Command) { | ||
flagSet := cmd.Flags() | ||
|
||
flagSet.StringVarP(&dir, "dir", "d", "", "The directory is set quota id.") | ||
flagSet.StringVarP(&size, "size", "s", "", "The limit of directory") | ||
flagSet.Uint32VarP("aID, "quota-id", "i", 0, "The quota id to set.") | ||
flagSet.BoolVarP(&recursive, "recursive", "r", true, "Set the directory recursively.") | ||
} | ||
|
||
func main() { | ||
var cmdServe = &cobra.Command{ | ||
Use: "fix_quota_id <-d /path> <-s size> <-i id>", | ||
Short: "Set the quota id of path", | ||
Long: "Set the quota id of path, also can set its sub-directory by recursively", | ||
Args: cobra.NoArgs, | ||
SilenceUsage: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return run(cmd) | ||
}, | ||
} | ||
|
||
setupFlags(cmdServe) | ||
if err := cmdServe.Execute(); err != nil { | ||
logrus.Error(err) | ||
os.Exit(1) | ||
} | ||
} |