mirror of
https://github.com/containers/podman.git
synced 2025-08-03 01:37:51 +08:00
support device-cgroup-rule
fix #4876 Add `--device-cgroup-rule` to podman create and run. This enables to add device rules after the container has been created. Signed-off-by: Qi Wang <qiwan@redhat.com>
This commit is contained in:
@ -2,12 +2,17 @@ package createconfig
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/go-units"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// deviceCgroupRulegex defines the valid format of device-cgroup-rule
|
||||
var deviceCgroupRuleRegex = regexp.MustCompile(`^([acb]) ([0-9]+|\*):([0-9]+|\*) ([rwm]{1,3})$`)
|
||||
|
||||
// Pod signifies a kernel namespace is being shared
|
||||
// by a container with the pod it is associated with
|
||||
const Pod = "pod"
|
||||
@ -205,3 +210,16 @@ func IsValidDeviceMode(mode string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// validateDeviceCgroupRule validates the format of deviceCgroupRule
|
||||
func validateDeviceCgroupRule(deviceCgroupRule string) error {
|
||||
if !deviceCgroupRuleRegex.MatchString(deviceCgroupRule) {
|
||||
return errors.Errorf("invalid device cgroup rule format: '%s'", deviceCgroupRule)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// parseDeviceCgroupRule matches and parses the deviceCgroupRule into slice
|
||||
func parseDeviceCgroupRule(deviceCgroupRule string) [][]string {
|
||||
return deviceCgroupRuleRegex.FindAllStringSubmatch(deviceCgroupRule, -1)
|
||||
}
|
||||
|
Reference in New Issue
Block a user