mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(host): optimized disk resize
This commit is contained in:
@@ -173,8 +173,10 @@ func (d *SLocalDisk) Resize(ctx context.Context, params interface{}) (jsonutils.
|
||||
resizeFsInfo.EncryptAlg = string(encryptInfo.Alg)
|
||||
}
|
||||
}
|
||||
if err := disk.Resize(int(sizeMb)); err != nil {
|
||||
return nil, err
|
||||
if disk.SizeBytes/1024/1024 < sizeMb {
|
||||
if err := disk.Resize(int(sizeMb)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if options.HostOptions.EnableFallocateDisk {
|
||||
// TODO
|
||||
|
||||
@@ -195,6 +195,13 @@ func (s *SRbdStorage) resizeImage(pool string, name string, sizeMb uint64) error
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetImage")
|
||||
}
|
||||
info, err := img.GetInfo()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "img.GetInfo")
|
||||
}
|
||||
if uint64(info.SizeByte/1024/1024) >= sizeMb {
|
||||
return nil
|
||||
}
|
||||
return img.Resize(int64(sizeMb))
|
||||
}
|
||||
|
||||
|
||||
@@ -294,9 +294,8 @@ func convertOther(srcInfo, destInfo SImageInfo, compact bool, workerOpions []str
|
||||
cmd := procutils.NewRemoteCommandAsFarAsPossible("ionice", cmdline...)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Errorf("qemu convert fail %s, output: %s", err, string(output))
|
||||
os.Remove(destInfo.Path)
|
||||
return err
|
||||
return errors.Wrapf(err, "convert: %s", output)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -364,9 +363,8 @@ func convertEncrypt(srcInfo, destInfo SImageInfo, compact bool, workerOpions []s
|
||||
output, err := cmd.Output()
|
||||
log.Infof("XXXX qemu-img convert command: %s output: %s", cmdline, output)
|
||||
if err != nil {
|
||||
log.Errorf("qemu convert fail %s, output: %s", err, string(output))
|
||||
os.Remove(destInfo.Path)
|
||||
return err
|
||||
return errors.Wrapf(err, "convert: %s", string(output))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -425,9 +423,8 @@ func (img *SQemuImage) convert(format TImageFormat, compact bool, password strin
|
||||
cmd := procutils.NewRemoteCommandAsFarAsPossible("mv", "-f", tmpPath, img.Path)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Errorf("convert move temp file error %s: %s", err, string(output))
|
||||
os.Remove(tmpPath)
|
||||
return errors.Wrap(err, "move")
|
||||
return errors.Wrapf(err, "move %s", string(output))
|
||||
}
|
||||
img.Password = password
|
||||
img.EncryptFormat = encryptFormat
|
||||
@@ -453,9 +450,8 @@ func (img *SQemuImage) Copy(name string) (*SQemuImage, error) {
|
||||
cmd := procutils.NewRemoteCommandAsFarAsPossible("cp", "--sparse=always", img.Path, name)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Errorf("copy fail %s: %s", err, string(output))
|
||||
os.Remove(name)
|
||||
return nil, err
|
||||
return nil, errors.Wrapf(err, "cp: %s", string(output))
|
||||
}
|
||||
newImg, err := NewQemuImage(name)
|
||||
if err != nil {
|
||||
@@ -564,7 +560,6 @@ func (img *SQemuImage) create(sizeMB int, format TImageFormat, options []string,
|
||||
cmd := procutils.NewRemoteCommandAsFarAsPossible("ionice", args...)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Errorf("%v create error %s %s", args, output, err)
|
||||
return errors.Wrapf(err, "create image failed: %s", output)
|
||||
}
|
||||
return img.parse()
|
||||
@@ -690,8 +685,7 @@ func (img *SQemuImage) Resize(sizeMB int) error {
|
||||
cmd := procutils.NewRemoteCommandAsFarAsPossible("ionice", args...)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Errorf("resize fail %s: %s", err, string(output))
|
||||
return err
|
||||
return errors.Wrapf(err, "resize: %s", string(output))
|
||||
}
|
||||
return img.parse()
|
||||
}
|
||||
@@ -709,8 +703,7 @@ func (img *SQemuImage) Rebase(backPath string, force bool) error {
|
||||
cmd := procutils.NewRemoteCommandAsFarAsPossible("ionice", args...)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Errorf("rebase fail %s: %s", err, string(output))
|
||||
return err
|
||||
return errors.Wrapf(err, "rebase %s", string(output))
|
||||
}
|
||||
return img.parse()
|
||||
}
|
||||
@@ -737,8 +730,7 @@ func (img *SQemuImage) Fallocate() error {
|
||||
cmd := procutils.NewCommand("fallocate", "-l", fmt.Sprintf("%dm", img.GetSizeMB()), img.Path)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Errorf("fallocate fail %s: %s", err, string(output))
|
||||
return errors.Wrap(err, "fallocate")
|
||||
return errors.Wrapf(err, "fallocate: %s", string(output))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -779,8 +771,7 @@ func (img *SQemuImage) Check() error {
|
||||
cmd := procutils.NewRemoteCommandAsFarAsPossible("ionice", args...)
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Errorf("rebase fail %s, output %s", err, string(output))
|
||||
return errors.Wrap(err, "check")
|
||||
return errors.Wrapf(err, "check: %s", string(output))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user