-
Notifications
You must be signed in to change notification settings - Fork 3
Add support for MutableCSINodeAllocatableCount #1066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
nschad
wants to merge
3
commits into
main
Choose a base branch
from
dynamic-volume-limits
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,25 @@ | |
|
|
||
| package mount | ||
|
|
||
| import "golang.org/x/sys/unix" | ||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "regexp" | ||
| "strings" | ||
|
|
||
| "golang.org/x/sys/unix" | ||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| var ( | ||
| pciAddressRegex = regexp.MustCompile(`^[0-9a-fA-F]{4}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-9a-fA-F]$`) | ||
| ) | ||
|
|
||
| const ( | ||
| RedhatVendor = "0x1af4" | ||
| VirtioBlockDevice = "0x1042" | ||
| ) | ||
|
|
||
| func newDeviceStats(statfs *unix.Statfs_t) *DeviceStats { | ||
| return &DeviceStats{ | ||
|
|
@@ -17,3 +35,74 @@ func newDeviceStats(statfs *unix.Statfs_t) *DeviceStats { | |
| UsedInodes: int64(statfs.Files) - int64(statfs.Ffree), | ||
| } | ||
| } | ||
|
|
||
| // CountNonVirtioBlockDevices returns the number of PCIe Root ports who | ||
| // are currently occupied by anything else than an VIRTIO 1.0 Block Device | ||
| // returns zero when something went wrong | ||
| func CountNonVirtioBlockDevices() (int64, error) { | ||
| const pciPath = "/sys/bus/pci/devices" | ||
|
|
||
| // Get all PCI devices | ||
| devices, err := os.ReadDir(pciPath) | ||
| if err != nil { | ||
| return 0, fmt.Errorf("failed to read PCI bus: %w", err) | ||
| } | ||
|
|
||
| pcieSlotsOccupiedByNonBlockDevice := 0 | ||
|
|
||
| for _, dev := range devices { | ||
| devPath := filepath.Join(pciPath, dev.Name()) | ||
|
|
||
| // 1. Identify if it's a Root Port / Bridge | ||
| // We check the 'class' file. PCI Bridge class code starts with 0x0604 | ||
| classBuf, err := os.ReadFile(filepath.Join(devPath, "class")) | ||
| if err != nil { | ||
| klog.Errorf("failed to read PCI device class %s : %v", devPath, err) | ||
| continue | ||
| } | ||
| class := strings.TrimSpace(string(classBuf)) | ||
|
|
||
| // Class 0x060400 is a PCI-to-PCI bridge (standard for Root Ports) | ||
| if strings.HasPrefix(class, "0x0604") { | ||
| // 2. Check if the port has downstream devices | ||
| // If the bridge has children, they appear as subdirectories | ||
| // matching the PCI address format (e.g., 0000:01:00.0) | ||
| files, err2 := os.ReadDir(devPath) | ||
| if err2 != nil { | ||
| klog.Errorf("failed to read dir %s : %v", devPath, err2) | ||
| } | ||
| for _, file := range files { | ||
| // Ignore PCI bus directories such as pci001 pci002 and pci010 | ||
| // Devices must follow <domain:bus:device.function> format | ||
| if pciAddressRegex.MatchString(file.Name()) { | ||
| isNonBlockDevice := IsNonBlockDevice(devPath, file) | ||
| if isNonBlockDevice { | ||
| pcieSlotsOccupiedByNonBlockDevice++ | ||
| } | ||
| break | ||
| } | ||
| } | ||
| } else { | ||
| klog.V(4).Infof("skipping class %s: path: %s", class, devPath) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. invert the check above and continue in case it does not have the prefix |
||
| } | ||
| } | ||
|
|
||
| return int64(pcieSlotsOccupiedByNonBlockDevice), nil | ||
| } | ||
|
|
||
| func IsNonBlockDevice(devPath string, file os.DirEntry) bool { | ||
| var isNonBlockDevice bool | ||
| pciDevicePath := filepath.Join(devPath, file.Name()) | ||
| vendorBuf, err := os.ReadFile(filepath.Join(pciDevicePath, "vendor")) | ||
| if err != nil { | ||
| klog.Errorf("failed to read PCI device vendor %s : %v", pciDevicePath, err) | ||
| } | ||
| deviceBuf, err := os.ReadFile(filepath.Join(pciDevicePath, "device")) | ||
| if err != nil { | ||
| klog.Errorf("failed to read PCI device file %s : %v", pciDevicePath, err) | ||
| } | ||
| if strings.TrimSpace(string(vendorBuf)) == RedhatVendor && strings.TrimSpace(string(deviceBuf)) != VirtioBlockDevice { | ||
| isNonBlockDevice = true | ||
| } | ||
| return isNonBlockDevice | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previously we substracted 2. one for root disk and one for configDrive/spare.
Why are we not substracting one for the configDrive / spare anymore?