Skip to content

Commit 6f8c0ec

Browse files
authored
fix(host,host-deployer): support lvm disk resize (#23335)
- add resize lvm disk support - support qga online resize disk partitions and filesystems
1 parent 6ec0769 commit 6f8c0ec

File tree

35 files changed

+1871
-443
lines changed

35 files changed

+1871
-443
lines changed

pkg/esxi/handler/handlers.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,17 @@ func resizeHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)
148148
httperrors.GeneralServerError(ctx, w, err)
149149
return
150150
}
151-
hostutils.DelayTask(ctx, disk.Resize, diskInfo)
151+
resizeDiskInfo := &storageman.SDiskResizeInput{
152+
DiskInfo: diskInfo,
153+
}
154+
resizeFunc := func(ctx context.Context, params interface{}) (jsonutils.JSONObject, error) {
155+
input, ok := params.(*storageman.SDiskResizeInput)
156+
if !ok {
157+
return nil, hostutils.ParamsError
158+
}
159+
return disk.Resize(ctx, input)
160+
}
161+
hostutils.DelayTask(ctx, resizeFunc, resizeDiskInfo)
152162
hostutils.ResponseOk(ctx, w)
153163
}
154164

pkg/hostman/diskutils/deploy_iface/deployer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ import (
2020
)
2121

2222
type IDeployer interface {
23-
Connect(desc *apis.GuestDesc) error
23+
Connect(desc *apis.GuestDesc, diskId string) error
2424
Disconnect() error
2525

2626
GetPartitions() []fsdriver.IDiskPartition
2727
IsLVMPartition() bool
2828
Zerofree()
29-
ResizePartition() error
29+
30+
ResizePartition(diskId string, rootPartDev string) error
3031
FormatPartition(fs, uuid string, features *apis.FsFeatures) error
3132
MakePartition(fs string) error
3233

@@ -35,7 +36,7 @@ type IDeployer interface {
3536
DetectIsUEFISupport(rootfs fsdriver.IRootFsDriver) bool
3637

3738
DeployGuestfs(req *apis.DeployParams) (res *apis.DeployGuestFsResponse, err error)
38-
ResizeFs() (res *apis.Empty, err error)
39+
ResizeFs(req *apis.ResizeFsParams) (res *apis.Empty, err error)
3940
FormatFs(req *apis.FormatFsParams) (*apis.Empty, error)
4041
SaveToGlance(req *apis.SaveToGlanceParams) (*apis.SaveToGlanceResponse, error)
4142
ProbeImageInfo(req *apis.ProbeImageInfoPramas) (*apis.ImageInfo, error)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2019 Yunion
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package driver // import "yunion.io/x/onecloud/pkg/hostman/diskutils/fsutils/driver"
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright 2019 Yunion
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package driver
16+
17+
import (
18+
"fmt"
19+
"io"
20+
"io/ioutil"
21+
22+
"yunion.io/x/onecloud/pkg/util/procutils"
23+
)
24+
25+
type IFsutilExecDriver interface {
26+
Run(name string, args ...string) error
27+
Exec(name string, args ...string) ([]byte, error)
28+
ExecInputWait(name string, args []string, input []string) (int, string, string, error)
29+
}
30+
31+
type SProcDriver struct {
32+
}
33+
34+
func NewProcDriver() IFsutilExecDriver {
35+
return new(SProcDriver)
36+
}
37+
38+
func (*SProcDriver) Exec(name string, args ...string) ([]byte, error) {
39+
return procutils.NewCommand(name, args...).Output()
40+
}
41+
42+
func (*SProcDriver) Run(name string, args ...string) error {
43+
return procutils.NewCommand(name, args...).Run()
44+
}
45+
46+
func (*SProcDriver) ExecInputWait(name string, args []string, input []string) (int, string, string, error) {
47+
proc := procutils.NewCommand(name, args...)
48+
stdin, err := proc.StdinPipe()
49+
if err != nil {
50+
return -1, "", "", err
51+
}
52+
defer stdin.Close()
53+
54+
outb, err := proc.StdoutPipe()
55+
if err != nil {
56+
return -1, "", "", err
57+
}
58+
defer outb.Close()
59+
60+
errb, err := proc.StderrPipe()
61+
if err != nil {
62+
return -1, "", "", err
63+
}
64+
defer errb.Close()
65+
if err := proc.Start(); err != nil {
66+
return -1, "", "", err
67+
}
68+
for _, s := range input {
69+
io.WriteString(stdin, fmt.Sprintf("%s\n", s))
70+
}
71+
stdoutPut, err := ioutil.ReadAll(outb)
72+
if err != nil {
73+
return -1, "", "", err
74+
}
75+
stderrOutPut, err := ioutil.ReadAll(errb)
76+
if err != nil {
77+
return -1, "", "", err
78+
}
79+
if err = proc.Wait(); err != nil {
80+
if status, succ := proc.GetExitStatus(err); succ {
81+
return status, string(stdoutPut), string(stderrOutPut), err
82+
} else {
83+
return 0, string(stdoutPut), string(stderrOutPut), err
84+
}
85+
}
86+
return 0, string(stdoutPut), string(stderrOutPut), nil
87+
}

0 commit comments

Comments
 (0)