Skip to content

Commit

Permalink
support incremental formatting
Browse files Browse the repository at this point in the history
Signed-off-by: liuminjian <[email protected]>
  • Loading branch information
liuminjian committed Sep 11, 2023
1 parent 3b6b0a1 commit 8e18359
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
12 changes: 9 additions & 3 deletions cli/command/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ import (

const (
FORMAT_EXAMPLE = `Examples:
$ curveadm format -f /path/to/format.yaml # Format chunkfile pool with specified configure file
$ curveadm format --status -f /path/to/format.yaml # Display formatting status
$ curveadm format --stop -f /path/to/format.yaml # Stop formatting progress`
$ curveadm format -f /path/to/format.yaml # Format chunkfile pool with specified configure file
$ curveadm format -f /path/to/format.yaml --increment # Incremental Format chunkfile pool with specified configure file
$ curveadm format --status -f /path/to/format.yaml # Display formatting status
$ curveadm format --stop -f /path/to/format.yaml # Stop formatting progress`
)

var (
Expand All @@ -62,6 +63,7 @@ type formatOptions struct {
filename string
showStatus bool
stopFormat bool
increment bool
}

func NewFormatCommand(curveadm *cli.CurveAdm) *cobra.Command {
Expand All @@ -82,6 +84,7 @@ func NewFormatCommand(curveadm *cli.CurveAdm) *cobra.Command {
flags.StringVarP(&options.filename, "formatting", "f", "format.yaml", "Specify the configure file for formatting chunkfile pool")
flags.BoolVar(&options.showStatus, "status", false, "Show formatting status")
flags.BoolVar(&options.stopFormat, "stop", false, "Stop formatting progress")
flags.BoolVar(&options.increment, "increment", false, "Incremental formatting")

return cmd
}
Expand Down Expand Up @@ -112,6 +115,9 @@ func genFormatPlaybook(curveadm *cli.CurveAdm,
ExecOptions: playbook.ExecOptions{
SilentSubBar: options.showStatus,
},
Options: map[string]interface{}{
comm.FORMAT_INCREMENTAL: options.increment,
},
})
}
return pb, nil
Expand Down
1 change: 1 addition & 0 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const (

// format
KEY_ALL_FORMAT_STATUS = "ALL_FORMAT_STATUS"
FORMAT_INCREMENTAL = "FORMAT_INCREMENTAL"

// check
KEY_CHECK_WITH_WEAK = "CHECK_WITH_WEAK"
Expand Down
33 changes: 27 additions & 6 deletions internal/task/scripts/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,33 @@ percent=$2
chunkfile_size=$3
chunkfile_pool_dir=$4
chunkfile_pool_meta_path=$5
increment_format=$6
mkdir -p $chunkfile_pool_dir
$binary \
-allocatePercent=$percent \
-fileSize=$chunkfile_size \
-filePoolDir=$chunkfile_pool_dir \
-filePoolMetaPath=$chunkfile_pool_meta_path \
-fileSystemPath=$chunkfile_pool_dir
if [ $increment_format == "true" ]
then
rootdir=$(dirname $chunkfile_pool_dir)
used_percent=$(df $rootdir --output=pcent|tail -n 1|sed 's/%//'|xargs)
let minus=$percent-$used_percent
if [ $minus -gt 0 ]
then
$binary \
-allocatePercent=$minus \
-fileSize=$chunkfile_size \
-filePoolDir=$chunkfile_pool_dir \
-filePoolMetaPath=$chunkfile_pool_meta_path \
-fileSystemPath=$chunkfile_pool_dir
fi
else
$binary \
-allocatePercent=$percent \
-fileSize=$chunkfile_size \
-filePoolDir=$chunkfile_pool_dir \
-filePoolMetaPath=$chunkfile_pool_meta_path \
-fileSystemPath=$chunkfile_pool_dir
fi
`
16 changes: 10 additions & 6 deletions internal/task/task/bs/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package bs

import (
"fmt"
comm "github.com/opencurve/curveadm/internal/common"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -245,8 +246,9 @@ func NewFormatChunkfilePoolTask(curveadm *cli.CurveAdm, fc *configure.FormatConf
chunkfilePoolRootDir := layout.ChunkfilePoolRootDir
formatScript := scripts.SCRIPT_FORMAT
formatScriptPath := fmt.Sprintf("%s/format.sh", layout.ToolsBinDir)
formatCommand := fmt.Sprintf("%s %s %d %d %s %s", formatScriptPath, layout.FormatBinaryPath,
usagePercent, DEFAULT_CHUNKFILE_SIZE, layout.ChunkfilePoolDir, layout.ChunkfilePoolMetaPath)
increment := curveadm.MemStorage().Get(comm.FORMAT_INCREMENTAL).(bool)
formatCommand := fmt.Sprintf("%s %s %d %d %s %s %t", formatScriptPath, layout.FormatBinaryPath,
usagePercent, DEFAULT_CHUNKFILE_SIZE, layout.ChunkfilePoolDir, layout.ChunkfilePoolMetaPath, increment)

// 1: skip if formating container exist
t.AddStep(&step.ListContainers{
Expand Down Expand Up @@ -278,10 +280,12 @@ func NewFormatChunkfilePoolTask(curveadm *cli.CurveAdm, fc *configure.FormatConf
Paths: []string{mountPoint},
ExecOptions: curveadm.ExecOptions(),
})
t.AddStep(&step.CreateFilesystem{ // mkfs.ext4 MOUNT_POINT
Device: device,
ExecOptions: curveadm.ExecOptions(),
})
if !increment {
t.AddStep(&step.CreateFilesystem{ // mkfs.ext4 MOUNT_POINT
Device: device,
ExecOptions: curveadm.ExecOptions(),
})
}
t.AddStep(&step.MountFilesystem{
Source: device,
Directory: mountPoint,
Expand Down

0 comments on commit 8e18359

Please sign in to comment.