diff --git a/pkg/apis/compute/disk.go b/pkg/apis/compute/disk.go index 40b9b1f6f2..0d0f27e726 100644 --- a/pkg/apis/compute/disk.go +++ b/pkg/apis/compute/disk.go @@ -362,6 +362,7 @@ type DiskRebuildInput struct { BackupId *string `json:"backup_id,allowempty"` TemplateId *string `json:"template_id,allowempty"` Size *string `json:"size,allowempty"` + Fs *string `json:"fs,allowempty"` } type DiskFsExt4Features struct { diff --git a/pkg/apis/compute/storage_const.go b/pkg/apis/compute/storage_const.go index 18e6601fc7..23160ed281 100644 --- a/pkg/apis/compute/storage_const.go +++ b/pkg/apis/compute/storage_const.go @@ -196,6 +196,8 @@ var ( // supported shared storage types SHARED_STORAGE = []string{STORAGE_NFS, STORAGE_GPFS, STORAGE_RBD, STORAGE_CLVM, STORAGE_SLVM} + + SUPPORTED_FS = []string{"swap", "ext2", "ext3", "ext4", "xfs", "f2fs"} ) func IsDiskTypeMatch(t1, t2 string) bool { diff --git a/pkg/compute/models/disks.go b/pkg/compute/models/disks.go index a9fdb18c95..fbd595b340 100644 --- a/pkg/compute/models/disks.go +++ b/pkg/compute/models/disks.go @@ -3318,6 +3318,9 @@ func (disk *SDisk) resetDiskinfo( if diskSize > 0 { disk.DiskSize = diskSize } + if input.Fs != nil { + disk.FsFormat = *input.Fs + } return nil }) if err != nil { diff --git a/pkg/hostman/diskutils/fsutils/fsutils.go b/pkg/hostman/diskutils/fsutils/fsutils.go index 2b2e648057..6e141f213a 100644 --- a/pkg/hostman/diskutils/fsutils/fsutils.go +++ b/pkg/hostman/diskutils/fsutils/fsutils.go @@ -279,6 +279,10 @@ func ResizePartitionFs(fpath, fs string, raiseError, mounted bool) (error, bool) // comment out the following codes only impact Windows 2003 // as windows 2003 deprecated, so choose to sacrifies windows 2003 // cmds = [][]string{{"ntfsresize", "-c", fpath}, {"ntfsresize", "-P", "-f", fpath}} + } else if fs == "f2fs" { + if !mounted { + cmds = [][]string{{"resize.f2fs"}} + } } if len(cmds) > 0 { @@ -436,6 +440,8 @@ func FormatPartition(path, fs, uuid string, fsFeatures *apis.FsFeatures) error { case fs == "xfs": cmd = []string{"mkfs.xfs", "-f", "-m", "crc=0", "-i", "projid32bit=0", "-n", "ftype=1"} cmdUuid = []string{"xfs_admin", "-U", uuid} + case fs == "f2fs": + cmd = []string{"mkfs.f2fs", "-U", uuid, "-O", "extra_attr,inode_checksum,sb_checksum"} } if len(cmd) > 0 { diff --git a/pkg/hostman/guestfs/kvmpart/kvmpart.go b/pkg/hostman/guestfs/kvmpart/kvmpart.go index 32bf7008d0..ecc4d476cd 100644 --- a/pkg/hostman/guestfs/kvmpart/kvmpart.go +++ b/pkg/hostman/guestfs/kvmpart/kvmpart.go @@ -255,6 +255,9 @@ func (p *SKVMGuestDiskPartition) fsck() error { case "ntfs": checkCmd = []string{"ntfsfix", "-n", p.partDev} fixCmd = []string{"ntfsfix", p.partDev} + case "f2fs": + checkCmd = []string{"fsck.f2fs", "-f", p.partDev} + fixCmd = []string{"fsck.f2fs", "-a", p.partDev} } if len(checkCmd) > 0 { _, err := procutils.NewCommand(checkCmd[0], checkCmd[1:]...).Output() diff --git a/pkg/hostman/storageman/disk_local.go b/pkg/hostman/storageman/disk_local.go index 4ef8a55b7f..e25c8e8356 100644 --- a/pkg/hostman/storageman/disk_local.go +++ b/pkg/hostman/storageman/disk_local.go @@ -426,7 +426,7 @@ func (d *SLocalDisk) CreateRaw(ctx context.Context, sizeMB int, diskFormat strin diskInfo.EncryptPassword = encryptInfo.Key diskInfo.EncryptAlg = string(encryptInfo.Alg) } - if utils.IsInStringArray(fsFormat, []string{"swap", "ext2", "ext3", "ext4", "xfs"}) { + if utils.IsInStringArray(fsFormat, api.SUPPORTED_FS) { d.FormatFs(fsFormat, fsFeatures, diskId, diskInfo) } diff --git a/pkg/hostman/storageman/disk_lvm.go b/pkg/hostman/storageman/disk_lvm.go index 6b9be9d305..7c4c3d9349 100644 --- a/pkg/hostman/storageman/disk_lvm.go +++ b/pkg/hostman/storageman/disk_lvm.go @@ -150,7 +150,7 @@ func (d *SLVMDisk) CreateRaw(ctx context.Context, sizeMB int, diskFormat string, diskInfo.EncryptPassword = encryptInfo.Key diskInfo.EncryptAlg = string(encryptInfo.Alg) } - if utils.IsInStringArray(fsFormat, []string{"swap", "ext2", "ext3", "ext4", "xfs"}) { + if utils.IsInStringArray(fsFormat, api.SUPPORTED_FS) { d.FormatFs(fsFormat, nil, diskId, diskInfo) } return d.GetDiskDesc(), nil diff --git a/pkg/hostman/storageman/disk_rbd.go b/pkg/hostman/storageman/disk_rbd.go index 339cad03ef..3ea56a70c4 100644 --- a/pkg/hostman/storageman/disk_rbd.go +++ b/pkg/hostman/storageman/disk_rbd.go @@ -227,7 +227,7 @@ func (d *SRBDDisk) CreateRaw(ctx context.Context, sizeMb int, diskFormat string, diskInfo := &deployapi.DiskInfo{ Path: d.GetPath(), } - if utils.IsInStringArray(fsFormat, []string{"swap", "ext2", "ext3", "ext4", "xfs"}) { + if utils.IsInStringArray(fsFormat, api.SUPPORTED_FS) { d.FormatFs(fsFormat, nil, diskId, diskInfo) } diff --git a/pkg/mcclient/options/compute/disks.go b/pkg/mcclient/options/compute/disks.go index 145b8107e7..003a069c2d 100644 --- a/pkg/mcclient/options/compute/disks.go +++ b/pkg/mcclient/options/compute/disks.go @@ -111,6 +111,7 @@ type DiskRebuildOptions struct { BackupId string `help:"disk backup id" json:"backup_id"` TemplateId string `help:"disk template id" json:"template_id"` Size string `help:"disk size in MB" json:"size"` + Fs string `help:"disk fs type"` } func (o *DiskRebuildOptions) Params() (jsonutils.JSONObject, error) { diff --git a/pkg/util/fileutils2/fileutils.go b/pkg/util/fileutils2/fileutils.go index 8a42d0630e..cf551d7330 100644 --- a/pkg/util/fileutils2/fileutils.go +++ b/pkg/util/fileutils2/fileutils.go @@ -382,7 +382,7 @@ func FsFormatToDiskType(fsFormat string) string { switch { case fsFormat == "swap": return "linux-swap" - case strings.HasPrefix(fsFormat, "ext") || fsFormat == "xfs": + case strings.HasPrefix(fsFormat, "ext") || fsFormat == "xfs" || fsFormat == "f2fs": return "ext2" case strings.HasPrefix(fsFormat, "fat"): return "fat32"