mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 11:00:25 +00:00
Format ext4 with lazy_journal_init
Skip zeroing of the journal on freshly created images. As only dynamic PVs are supported, it is fine to assume that existingFormat == "" image has never been mapped and written to before. lazy_itable_init is enabled by default, passing it for consistency with lazy_journal_init. Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
This commit is contained in:
parent
cd52798a51
commit
9a61fa0c0a
@ -310,27 +310,40 @@ func getLegacyVolumeName(mountPath string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ns *NodeServer) mountVolumeToStagePath(ctx context.Context, req *csi.NodeStageVolumeRequest, stagingPath, devicePath string) error {
|
func (ns *NodeServer) mountVolumeToStagePath(ctx context.Context, req *csi.NodeStageVolumeRequest, stagingPath, devicePath string) error {
|
||||||
// Publish Path
|
|
||||||
fsType := req.GetVolumeCapability().GetMount().GetFsType()
|
fsType := req.GetVolumeCapability().GetMount().GetFsType()
|
||||||
diskMounter := &mount.SafeFormatAndMount{Interface: ns.mounter, Exec: mount.NewOsExec()}
|
diskMounter := &mount.SafeFormatAndMount{Interface: ns.mounter, Exec: mount.NewOsExec()}
|
||||||
|
|
||||||
|
// rbd images are thin-provisioned and return zeros for unwritten areas. A freshly created
|
||||||
|
// image will not benefit from discard and we also want to avoid as much unnecessary zeroing
|
||||||
|
// as possible. Open-code mkfs here because FormatAndMount() doesn't accept custom mkfs
|
||||||
|
// options.
|
||||||
|
//
|
||||||
|
// Note that "freshly" is very important here. While discard is more of a nice to have,
|
||||||
|
// lazy_journal_init=1 is plain unsafe if the image has been written to before and hasn't
|
||||||
|
// been zeroed afterwards (unlike the name suggests, it leaves the journal completely
|
||||||
|
// uninitialized and carries a risk until the journal is overwritten and wraps around for
|
||||||
|
// the first time).
|
||||||
existingFormat, err := diskMounter.GetDiskFormat(devicePath)
|
existingFormat, err := diskMounter.GetDiskFormat(devicePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf(util.Log(ctx, "failed to get disk format for path %s, error: %v"), devicePath, err)
|
klog.Errorf(util.Log(ctx, "failed to get disk format for path %s, error: %v"), devicePath, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if existingFormat == "" && (fsType == "ext4" || fsType == "xfs") {
|
// TODO: update this when adding support for static (pre-provisioned) PVs
|
||||||
|
if existingFormat == "" /* && !staticVol */ {
|
||||||
args := []string{}
|
args := []string{}
|
||||||
if fsType == "ext4" {
|
if fsType == "ext4" {
|
||||||
args = []string{"-m0", "-Enodiscard", devicePath}
|
args = []string{"-m0", "-Enodiscard,lazy_itable_init=1,lazy_journal_init=1", devicePath}
|
||||||
} else if fsType == "xfs" {
|
} else if fsType == "xfs" {
|
||||||
args = []string{"-K", devicePath}
|
args = []string{"-K", devicePath}
|
||||||
}
|
}
|
||||||
|
if len(args) > 0 {
|
||||||
_, err = diskMounter.Exec.Run("mkfs."+fsType, args...)
|
_, err = diskMounter.Exec.Run("mkfs."+fsType, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf(util.Log(ctx, "failed to run mkfs, error: %v"), err)
|
klog.Errorf(util.Log(ctx, "failed to run mkfs, error: %v"), err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
opt := []string{}
|
opt := []string{}
|
||||||
isBlock := req.GetVolumeCapability().GetBlock() != nil
|
isBlock := req.GetVolumeCapability().GetBlock() != nil
|
||||||
|
Loading…
Reference in New Issue
Block a user