Skip to content

Commit

Permalink
iolimit: Change "rootfs" to a variable so we can add support for othe…
Browse files Browse the repository at this point in the history
…r disks in the future
  • Loading branch information
iBug committed Apr 3, 2024
1 parent 3a6eed1 commit ebc7d3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 8 additions & 8 deletions cmd/iolimit/iolimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func showIOLimit(w io.Writer, ctid string) error {
return nil
}

func setIOLimit(ctid string, iops cgroup.IOPS) error {
func setIOLimit(ctid string, diskName string, iops cgroup.IOPS) error {

pveStorage, err := pve.GetStorage()
if err != nil {
Expand All @@ -77,14 +77,14 @@ func setIOLimit(ctid string, iops cgroup.IOPS) error {
if err != nil {
return err
}
rootfs := config["rootfs"]
rootfsIdent := strings.SplitN(rootfs, ",", 2)[0]
rootfsParts := strings.Split(rootfsIdent, ":")
if len(rootfsParts) != 2 {
return fmt.Errorf("invalid rootfs %s", rootfsIdent)
disk := config[diskName]
diskIdent := strings.SplitN(disk, ",", 2)[0]
diskParts := strings.Split(diskIdent, ":")
if len(diskParts) != 2 {
return fmt.Errorf("invalid disk %s", diskIdent)
}

major, minor, err := pve.GetBlockDevForStorage(rootfsParts[0], rootfsParts[1], pveStorage)
major, minor, err := pve.GetBlockDevForStorage(diskParts[0], diskParts[1], pveStorage)
if err != nil {
return err
}
Expand All @@ -100,5 +100,5 @@ func iolimitMain(cmd *cobra.Command, ctid string, iops cgroup.IOPS) error {
if iops.IsZero() {
return showIOLimit(cmd.OutOrStdout(), ctid)
}
return setIOLimit(ctid, iops)
return setIOLimit(ctid, "rootfs", iops)
}
3 changes: 2 additions & 1 deletion cmd/iostat/iostat.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ func iostatMain(diskPath string) error {
func MakeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "iostat DISK",
Short: "Show I/O statistics for DISK",
Short: "Show I/O statistics for disks",
Long: "Show I/O statistics for DISK",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return iostatMain(args[0])
Expand Down

0 comments on commit ebc7d3f

Please sign in to comment.