Skip to content

Commit a6c467a

Browse files
committed
[quota] config fs quota when mount fs
1 parent 96cde77 commit a6c467a

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

internal/configure/client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const (
5353
KEY_CLIENT_S3_ADDRESS = "s3.endpoint"
5454
KEY_CLIENT_S3_BUCKET_NAME = "s3.bucket_name"
5555

56+
KEY_QUOTA_CAPACITY = "quota.capacity"
57+
KEY_QUOTA_INODES = "quota.inodes"
58+
5659
DEFAULT_CORE_LOCATE_DIR = "/core"
5760
)
5861

@@ -194,6 +197,14 @@ func (cc *ClientConfig) getBool(key string) bool {
194197
return v.(bool)
195198
}
196199

200+
func (cc *ClientConfig) getDigital(key string) int {
201+
v := cc.config[strings.ToLower(key)]
202+
if v == nil {
203+
return 0
204+
}
205+
return v.(int)
206+
}
207+
197208
func (cc *ClientConfig) GetKind() string { return cc.getString(KEY_KIND) }
198209
func (cc *ClientConfig) GetDataDir() string { return cc.getString(KEY_DATA_DIR) }
199210
func (cc *ClientConfig) GetLogDir() string { return cc.getString(KEY_LOG_DIR) }
@@ -205,6 +216,8 @@ func (cc *ClientConfig) GetS3Address() string { return cc.getStri
205216
func (cc *ClientConfig) GetS3BucketName() string { return cc.getString(KEY_CLIENT_S3_BUCKET_NAME) }
206217
func (cc *ClientConfig) GetContainerPid() string { return cc.getString(KEY_CONTAINER_PID) }
207218
func (cc *ClientConfig) GetEnvironments() string { return cc.getString(KEY_ENVIRONMENT) }
219+
func (cc *ClientConfig) GetQuotaCapacity() int { return cc.getDigital(KEY_QUOTA_CAPACITY) }
220+
func (cc *ClientConfig) GetQuotaInodes() int { return cc.getDigital(KEY_QUOTA_INODES) }
208221
func (cc *ClientConfig) GetCoreLocateDir() string { return DEFAULT_CORE_LOCATE_DIR }
209222
func (cc *ClientConfig) GetData() string { return cc.data }
210223
func (cc *ClientConfig) GetServiceConfig() map[string]string { return cc.serviceConfig }

internal/task/scripts/shell/create_fs_v2.sh

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,55 @@
88

99
g_dingofs_tool="dingo"
1010
g_dingofs_tool_operator="create fs"
11+
g_dingofs_tool_config="config fs"
1112
g_fsname="--fsname="
1213
g_fstype="--fstype="
14+
g_quota_capacity="--capacity="
15+
g_quota_inodes="--inodes="
1316
g_entrypoint="/entrypoint.sh"
1417

1518
function createfs() {
1619
g_fsname=$g_fsname$1
1720
g_fstype=$g_fstype$2
1821

22+
# create fs command: dingo create fs --fsname <fsname> --fstype s3 xxx
1923
$g_dingofs_tool $g_dingofs_tool_operator "$g_fsname" "$g_fstype"
2024
}
2125

22-
createfs "$@"
26+
function configfs() {
27+
# config fs quota: dingo config fs --fsname <fsname> --capacity <capacity> --inodes <inodes>
28+
echo "$g_dingofs_tool $g_dingofs_tool_config $g_fsname $g_quota_capacity$1 $g_quota_inodes$2"
29+
$g_dingofs_tool $g_dingofs_tool_config "$g_fsname" "$g_quota_capacity$1" "$g_quota_inodes$2"
30+
}
31+
32+
# Parse command parameters
33+
capacity=""
34+
inodes=""
35+
args=()
36+
for arg in "$@"; do
37+
case $arg in
38+
--capacity=*)
39+
capacity="${arg#*=}"
40+
;;
41+
--inodes=*)
42+
inodes="${arg#*=}"
43+
;;
44+
*)
45+
args+=("$arg")
46+
;;
47+
esac
48+
done
49+
50+
echo "create fs args: ${args[@]}"
51+
createfs "${args[@]}"
2352

2453
ret=$?
2554
if [ $ret -eq 0 ]; then
26-
$g_entrypoint "$@"
55+
if [ -n "$capacity" ] || [ -n "$inodes" ]; then
56+
echo "config fs quota: capacity=$capacity, inodes=$inodes"
57+
configfs "$capacity" "$inodes"
58+
fi
59+
$g_entrypoint "${args[@]}"
2760
ret=$?
2861
exit $ret
2962
else

internal/task/task/fs/mount.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ func getMountCommand(cc *configure.ClientConfig, mountFSName string, mountFSType
8989
format := strings.Join(FORMAT_FUSE_ARGS, " ")
9090
fuseArgs := fmt.Sprintf(format, mountFSName, mountFSType,
9191
configure.GetFSClientConfPath(), configure.GetFSClientMountPath(mountPoint))
92-
return fmt.Sprintf("/client.sh %s %s --role=client --args='%s'", mountFSName, mountFSType, fuseArgs)
92+
93+
fmt.Printf("docker bootstrap command: /client.sh %s %s --role=client --args='%s' --capacity=%d --inodes=%d\n", mountFSName, mountFSType, fuseArgs, cc.GetQuotaCapacity(), cc.GetQuotaInodes())
94+
95+
return fmt.Sprintf("/client.sh %s %s --role=client --args='%s' --capacity=%d --inodes=%d", mountFSName, mountFSType, fuseArgs, cc.GetQuotaCapacity(), cc.GetQuotaInodes())
96+
9397
}
9498

9599
func getMountVolumes(cc *configure.ClientConfig) []step.Volume {

0 commit comments

Comments
 (0)