-
Notifications
You must be signed in to change notification settings - Fork 949
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
feature: add local disk quota #725
Conversation
volume/modules/local/quota.go
Outdated
return st.Dev, nil | ||
} | ||
|
||
func toByteSize(s string) uint64 { |
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.
Please add a unit test for this function? @rudyfly 😄
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.
And this is similar to the function ToBytes
in vendor package code.cloudfouncry.org/bytefmt/bytes.go.
We have a plan to remove this vendored package, could you encapsulate them into a package in pkg.
See #356
volume/modules/local/quota.go
Outdated
|
||
// BaseQuota defines the quota operation interface. | ||
type BaseQuota interface { | ||
QuotaDriverStart(dir string) (string, error) |
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.
From my own point of view, StartQuotaDriver is better than QuotaDriverStart. WDYT?
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.
ok
36a4fcf
to
2390e5e
Compare
Codecov Report
@@ Coverage Diff @@
## master #725 +/- ##
==========================================
- Coverage 13.58% 13.57% -0.01%
==========================================
Files 97 97
Lines 5927 5928 +1
==========================================
Hits 805 805
- Misses 5068 5069 +1
Partials 54 54
Continue to review full report at Codecov.
|
e0f667f
to
5945c19
Compare
volume/modules/local/grpquota.go
Outdated
continue | ||
} | ||
parts := strings.Split(line, " ") | ||
if len(parts) == 0 { |
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.
I think
if len(parts) == 0 {
continue
}
is redundant.
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.
yeah, it should be < 2
volume/modules/local/quota.go
Outdated
|
||
var ( | ||
lock sync.Mutex | ||
quotaLastID uint32 |
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.
Could you please add more description or comments on these global variables in pkg local?
I think this is very useful for others to understand your thoughts. Actually currently I can read your code with logic, but have no idea about your thoughts. 😢
return quota.setUserQuota(id, limit, mountPoint) | ||
} | ||
|
||
// CheckMountpoint is used to check mount point. |
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.
Could you add one example valid line in /proc/mounts in comment please?
like:
// CheckMountpoint is used to check mount point which is in file /proc/mounts.
// one valid line must have the following format:
// cgroup /sys/fs/cgroup/hugetlb cgroup rw,nosuid,nodev,noexec,relatime,hugetlb 0 0
You can also tell others more about the exact meanings of each column. 😄
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.
ok
That is a great work for you to complete this. @rudyfly |
volume/modules/local/grpquota.go
Outdated
|
||
// on | ||
exit, stdout, stderr, err := exec.Run(0, "quotaon", "-pg", mountPoint) | ||
if err != nil && exit != 1 { |
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.
Should this be if err != nil || exit != 0
?
Since if the exit code is non-zero, it means running into an error.
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.
exit = 1 is also valid.
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.
Oh, that is some kind of strange. Could you add some illustration here to tell code readers about that?
This is a great work. While I have one thing may need discussion.
Currently we have grpquota as the default quota driver, and to be honest, I am afraid we have not taken full advantage of the interface I am wondering if we could still
Maybe we can define a global variable
As a result, we could make users input their wanted quota drivers. And others could also add another quota driver via implementing the interface BaseQuota. |
apis/server/volume_bridge.go
Outdated
CreatedAt: volume.CreationTimestamp.Format("2006-1-2 15:04:05"), | ||
Status: make(map[string]interface{}), | ||
} | ||
for k, v := range volume.Options() { |
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.
I think we can move the following codes above just before respVolume's initialization. We can use
var status map[string]string
for k, v := range volume.Options() {
if k != "" && v != "" {
status[k] = v
}
}
Then we can use this status
in the respVolume
initialization.
Although two ways can achieve the same effect, maybe we can make code more clear with two parts: data preparation and respVolume
initialization. And this makes no separated assignments.
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.
ok
apis/server/volume_bridge.go
Outdated
}, | ||
Status: make(map[string]interface{}), | ||
} | ||
for k, v := range volume.Options() { |
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.
The same as the previous comment.
056c8b9
to
36f4f47
Compare
Add local disk quota. In alikernel, with dirquota feature to limit directory block size. Signed-off-by: Rudy Zhang <rudyflyzhang@gmail.com>
@allencloud PTAL 😄 |
LGTM, thanks again for the work. How about the test cases and disk quota document? @rudyfly |
if devID == devID2 { | ||
mountPoint = parts[1] | ||
fsType = parts[2] | ||
for _, opt := range strings.Split(parts[3], ",") { |
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.
Could we just use
if strings.Contains(parts[3], "prjquota") {
hasQuota = true
}
?
if devID == devID2 { | ||
mountPoint = parts[1] | ||
fsType = parts[2] | ||
for _, opt := range strings.Split(parts[3], ",") { |
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.
Could we just use
if strings.Contains(parts[3], "grpquota") {
hasQuota = true
}
?
Ⅰ. Describe what this PR did
Add local disk quota. In alikernel, with dirquota feature to limit
directory block size.
Ⅱ. Does this pull request fix one issue?
fixes #101
Ⅲ. Describe how you did it
Ⅳ. Describe how to verify it
In alikernel, you can use it like this:
set volume size is 10G
run a container, use df to see the volume size.
# pouch run -ti -v pouchvolume:/mnt --name test registry.hub.docker.com/library/busybox:latest df -h Filesystem Size Used Available Use% Mounted on overlay 29.4G 19.6G 8.3G 70% / tmpfs 64.0M 0 64.0M 0% /dev shm 64.0M 0 64.0M 0% /dev/shm tmpfs 64.0M 0 64.0M 0% /run /dev/sda3 10.0G 4.0K 10.0G 0% /mnt
Ⅴ. Special notes for reviews
Signed-off-by: Rudy Zhang rudyflyzhang@gmail.com