• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubevirt / kubevirt / 7dc86bb8-0ab1-4cde-9ee6-3c44c6e610dd

19 Feb 2025 03:21AM UTC coverage: 71.633% (+0.02%) from 71.609%
7dc86bb8-0ab1-4cde-9ee6-3c44c6e610dd

push

prow

web-flow
Merge pull request #13807 from Barakmor1/diskinfo

Move disk info collection and verification from virt-handler to virt-launcher

54 of 110 new or added lines in 18 files covered. (49.09%)

9 existing lines in 3 files now uncovered.

62190 of 86818 relevant lines covered (71.63%)

0.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

14.63
/pkg/virt-handler/virt-chroot/virt-chroot.go
1
/*
2
 * This file is part of the KubeVirt project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 *
16
 * Copyright 2021 Red Hat, Inc.
17
 *
18
 */
19

20
package virt_chroot
21

22
import (
23
        "os/exec"
24
        "strings"
25

26
        "kubevirt.io/kubevirt/pkg/safepath"
27
        "kubevirt.io/kubevirt/pkg/unsafepath"
28
)
29

30
const (
31
        binaryPath     = "/usr/bin/virt-chroot"
32
        mountNamespace = "/proc/1/ns/mnt"
33
)
34

35
func getBaseArgs() []string {
×
36
        return []string{"--mount", mountNamespace}
×
37
}
×
38

39
func GetChrootBinaryPath() string {
1✔
40
        return binaryPath
1✔
41
}
1✔
42

43
func GetChrootMountNamespace() string {
1✔
44
        return mountNamespace
1✔
45
}
1✔
46

47
func MountChroot(sourcePath, targetPath *safepath.Path, ro bool) *exec.Cmd {
×
48
        return UnsafeMountChroot(trimProcPrefix(sourcePath), trimProcPrefix(targetPath), ro)
×
49
}
×
50

51
// Deprecated: UnsafeMountChroot is used to connect to code which needs to be refactored
52
// to handle mounts securely.
53
func UnsafeMountChroot(sourcePath, targetPath string, ro bool) *exec.Cmd {
×
54
        args := append(getBaseArgs(), "mount", "-o")
×
55
        optionArgs := "bind"
×
56

×
57
        if ro {
×
58
                optionArgs = "ro," + optionArgs
×
59
        }
×
60

61
        args = append(args, optionArgs, sourcePath, targetPath)
×
62
        return exec.Command(binaryPath, args...)
×
63
}
64

65
func UmountChroot(path *safepath.Path) *exec.Cmd {
×
66
        return UnsafeUmountChroot(trimProcPrefix(path))
×
67
}
×
68

69
// Deprecated: UnsafeUmountChroot is used to connect to code which needs to be refactored
70
// to handle mounts securely.
71
func UnsafeUmountChroot(path string) *exec.Cmd {
×
72
        args := append(getBaseArgs(), "umount", path)
×
73
        return exec.Command(binaryPath, args...)
×
74
}
×
75

76
func CreateMDEVType(mdevType string, parentID string, uuid string) *exec.Cmd {
×
77
        args := append(getBaseArgs(), "create-mdev")
×
78
        args = append(args, "--type", mdevType, "--parent", parentID, "--uuid", uuid)
×
79
        return exec.Command(binaryPath, args...)
×
80
}
×
81

82
func RemoveMDEVType(mdevUUID string) *exec.Cmd {
×
83
        args := append(getBaseArgs(), "remove-mdev")
×
84
        args = append(args, "--uuid", mdevUUID)
×
85
        return exec.Command(binaryPath, args...)
×
86
}
×
87

UNCOV
88
func trimProcPrefix(path *safepath.Path) string {
×
89
        return strings.TrimPrefix(unsafepath.UnsafeAbsolute(path.Raw()), "/proc/1/root")
×
90
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc