This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #584 from Mashimiao/add-cgroup-subsystem-net_prio
cgroup: add support for net_prio
- Loading branch information
Showing
5 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package fs | ||
|
||
import ( | ||
"github.com/docker/libcontainer/cgroups" | ||
"github.com/docker/libcontainer/configs" | ||
) | ||
|
||
type NetPrioGroup struct { | ||
} | ||
|
||
func (s *NetPrioGroup) Apply(d *data) error { | ||
dir, err := d.join("net_prio") | ||
if err != nil && !cgroups.IsNotFound(err) { | ||
return err | ||
} | ||
|
||
if err := s.Set(dir, d.c); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s *NetPrioGroup) Set(path string, cgroup *configs.Cgroup) error { | ||
for _, prioMap := range cgroup.NetPrioIfpriomap { | ||
if err := writeFile(path, "net_prio.ifpriomap", prioMap.CgroupString()); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s *NetPrioGroup) Remove(d *data) error { | ||
return removePath(d.path("net_prio")) | ||
} | ||
|
||
func (s *NetPrioGroup) GetStats(path string, stats *cgroups.Stats) error { | ||
return nil | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package fs | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/docker/libcontainer/configs" | ||
) | ||
|
||
var ( | ||
prioMap = []*configs.IfPrioMap{ | ||
{ | ||
Interface: "test", | ||
Priority: 5, | ||
}, | ||
} | ||
) | ||
|
||
func TestNetPrioSetIfPrio(t *testing.T) { | ||
helper := NewCgroupTestUtil("net_prio", t) | ||
defer helper.cleanup() | ||
|
||
helper.CgroupData.c.NetPrioIfpriomap = prioMap | ||
netPrio := &NetPrioGroup{} | ||
if err := netPrio.Set(helper.CgroupPath, helper.CgroupData.c); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
value, err := getCgroupParamString(helper.CgroupPath, "net_prio.ifpriomap") | ||
if err != nil { | ||
t.Fatalf("Failed to parse net_prio.ifpriomap - %s", err) | ||
} | ||
if !strings.Contains(value, "test 5") { | ||
t.Fatal("Got the wrong value, set net_prio.ifpriomap failed.") | ||
} | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package configs | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type IfPrioMap struct { | ||
Interface string `json:"interface"` | ||
Priority int64 `json:"priority"` | ||
} | ||
|
||
func (i *IfPrioMap) CgroupString() string { | ||
return fmt.Sprintf("%s %d", i.Interface, i.Priority) | ||
} |