Skip to content

Commit

Permalink
rbd: cleanup passing mkfs arguments for NodeStageVolume
Browse files Browse the repository at this point in the history
Storing the default `mkfs` arguments in a map with key per filesystem
type makes this a little more modular. It prepares th code for fetching
the `mkfs` arguments from the VolumeContext.

Signed-off-by: Niels de Vos <ndevos@ibm.com>
  • Loading branch information
nixpanic committed Mar 3, 2023
1 parent 8fd0383 commit 722350e
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions internal/rbd/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ var (
// xfsHasReflink is set by xfsSupportsReflink(), use the function when
// checking the support for reflink.
xfsHasReflink = xfsReflinkUnset

mkfsDefaultArgs = map[string][]string{
"ext4": {"-m0", "-Enodiscard,lazy_itable_init=1,lazy_journal_init=1"},
"xfs": {"-onouuid", "-K"},
}
)

// parseBoolOption checks if parameters contain option and parse it. If it is
Expand Down Expand Up @@ -771,34 +776,33 @@ func (ns *NodeServer) mountVolumeToStagePath(
readOnly = true
}

if fsType == "xfs" {
opt = append(opt, "nouuid")
}

if existingFormat == "" && !staticVol && !readOnly {
args := []string{}
args := mkfsDefaultArgs[fsType]
switch fsType {
case "ext4":
args = []string{"-m0", "-Enodiscard,lazy_itable_init=1,lazy_journal_init=1"}
if fileEncryption {
args = append(args, "-Oencrypt")
}
args = append(args, devicePath)
case "xfs":
args = []string{"-K", devicePath}
// always disable reflink
// TODO: make enabling an option, see ceph/ceph-csi#1256
if ns.xfsSupportsReflink() {
args = append(args, "-m", "reflink=0")
}
}
if len(args) > 0 {
cmdOut, cmdErr := diskMounter.Exec.Command("mkfs."+fsType, args...).CombinedOutput()
if cmdErr != nil {
log.ErrorLog(ctx, "failed to run mkfs error: %v, output: %v", cmdErr, string(cmdOut))

return cmdErr
}
mkfs := "mkfs"
if fsType != "" {
mkfs += "." + fsType
}

// add device as last argument
args = append(args, devicePath)
cmdOut, cmdErr := diskMounter.Exec.Command(mkfs, args...).CombinedOutput()
if cmdErr != nil {
log.ErrorLog(ctx, "failed to run mkfs.%s (%v) error: %v, output: %v", fsType, args, cmdErr, string(cmdOut))

return cmdErr
}
}

Expand Down

0 comments on commit 722350e

Please sign in to comment.