Skip to content

Commit 21d73b7

Browse files
committed
chore(hyperv): add two-phase VHDX transfer and local deep inspection
When preCopySourceDisks is enabled, an init container converts each VHDX from the SMB share to the target block device with qemu-img, then virt-v2v runs in-place. smbMaxChannels (0-16) controls CIFS multichannel negotiation. Hyper-V deep inspection runs virt-inspector on locally mounted VHD/VHDX disks over the SMB mount after power-off. Resolves: NONE Signed-off-by: Elad Hazan <ehazan@redhat.com>
1 parent 41ef4d7 commit 21d73b7

25 files changed

Lines changed: 4994 additions & 91 deletions

File tree

cmd/deep-inspection/main.go

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ You may obtain a copy of the License at
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OF ANY KIND, either express or implied.
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
@@ -28,7 +28,6 @@ import (
2828
)
2929

3030
const (
31-
// secretDir is where the connection Secret is mounted in the deep-inspection pod.
3231
secretDir = "/etc/secret"
3332
)
3433

@@ -37,10 +36,30 @@ func main() {
3736
log.SetLevel(logrus.DebugLevel)
3837
log.SetOutput(os.Stdout)
3938

39+
srv := newResultServer()
40+
41+
source := strings.TrimSpace(os.Getenv("V2V_SOURCE"))
42+
43+
go func() {
44+
var result *vmdetect.DetectResult
45+
var detectErr error
46+
47+
switch source {
48+
case "hyperv":
49+
result, detectErr = detectLocalDisks(log)
50+
default:
51+
result, detectErr = detectVSphere(log)
52+
}
53+
srv.setResult(result, detectErr)
54+
}()
55+
56+
os.Exit(srv.run())
57+
}
58+
59+
func detectVSphere(log *logrus.Logger) (*vmdetect.DetectResult, error) {
4060
creds, err := loadProviderCredentials()
4161
if err != nil {
42-
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
43-
os.Exit(1)
62+
return nil, err
4463
}
4564

4665
detector, err := vmdetect.NewDetector(vmdetect.DetectorConfig{
@@ -50,28 +69,49 @@ func main() {
5069
DB: nil,
5170
})
5271
if err != nil {
53-
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
54-
os.Exit(1)
72+
return nil, err
5573
}
5674

5775
vmMoref, snapshotMoref, err := vmAndSnapshotFromEnv()
5876
if err != nil {
59-
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
60-
os.Exit(1)
77+
return nil, err
6178
}
6279

63-
srv := newResultServer()
80+
return detector.Detect(vmdetect.DetectParams{
81+
Ctx: context.Background(),
82+
VMMoref: vmMoref,
83+
SnapshotMoref: snapshotMoref,
84+
})
85+
}
6486

65-
go func() {
66-
result, detectErr := detector.Detect(vmdetect.DetectParams{
67-
Ctx: context.Background(),
68-
VMMoref: vmMoref,
69-
SnapshotMoref: snapshotMoref,
70-
})
71-
srv.setResult(result, detectErr)
72-
}()
87+
// detectLocalDisks runs virt-inspector directly on locally-mounted disk files
88+
// (Hyper-V VHD/VHDX over SMB mount at /hyperv).
89+
func detectLocalDisks(log *logrus.Logger) (*vmdetect.DetectResult, error) {
90+
diskPath := strings.TrimSpace(os.Getenv("V2V_DISK_PATH"))
91+
if diskPath == "" {
92+
return nil, fmt.Errorf("V2V_DISK_PATH must be set for hyperv deep inspection")
93+
}
7394

74-
os.Exit(srv.run())
95+
format := "vhdx"
96+
if strings.HasSuffix(strings.ToLower(diskPath), ".vhd") {
97+
format = "vpc"
98+
}
99+
100+
log.Infof("Running local deep inspection on %s (format=%s)", diskPath, format)
101+
102+
detector, err := vmdetect.NewDetector(vmdetect.DetectorConfig{
103+
Logger: log,
104+
DB: nil,
105+
})
106+
if err != nil {
107+
return nil, err
108+
}
109+
110+
return detector.DetectLocal(vmdetect.DetectLocalParams{
111+
Ctx: context.Background(),
112+
DiskPaths: []string{diskPath},
113+
Formats: []string{format},
114+
})
75115
}
76116

77117
func loadProviderCredentials() (vmdetect.Credentials, error) {

cmd/vsphere-copy-offload-populator/vendor/github.com/kubev2v/forklift/pkg/apis/forklift/v1beta1/conversion.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/vsphere-copy-offload-populator/vendor/github.com/kubev2v/forklift/pkg/apis/forklift/v1beta1/plan.go

Lines changed: 22 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/vsphere-copy-offload-populator/vendor/github.com/kubev2v/forklift/pkg/apis/forklift/v1beta1/zz_generated.deepcopy.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)