-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquota.go
69 lines (59 loc) · 1.64 KB
/
quota.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package libquota
import (
"github.com/pouchcontainer/libquota/drivers/ext4grpquota"
"github.com/pouchcontainer/libquota/drivers/ext4prjquota"
"github.com/pouchcontainer/libquota/drivers/xfsprjquota"
"github.com/pouchcontainer/libquota/pkg/fs"
"github.com/pouchcontainer/libquota/pkg/kernel"
"github.com/pouchcontainer/libquota/types"
"github.com/pkg/errors"
)
// NewQuota returns the quota object.
func NewQuota(file string) (Quota, error) {
var quota Quota
mount, err := fs.GetMountPoint(file)
if err != nil {
return nil, errors.Wrapf(err, "failed to get file(%s) system information", file)
}
quota = QuotaMapGet(mount.MountPoint)
if quota != nil {
return quota, nil
}
kernelVersion, err := kernel.GetKernelVersion()
if err != nil {
return nil, err
}
switch types.FSType(mount.FSType) {
case types.Ext4:
if (kernelVersion.Kernel == 4 && kernelVersion.Major >= 5) ||
(kernelVersion.Kernel > 4) {
quota, err = ext4prjquota.New(file)
if err != nil {
return nil, err
}
} else {
quota, err = ext4grpquota.New(file)
if err != nil {
return nil, err
}
}
case types.Xfs:
if (kernelVersion.Kernel == 3 && kernelVersion.Major >= 10) ||
(kernelVersion.Kernel > 3) {
quota, err = xfsprjquota.New(file)
if err != nil {
return nil, err
}
} else {
return nil, errors.Errorf("Unsupport kernel version(%s) for xfs file system",
kernelVersion.String())
}
default:
return nil, errors.Errorf("Unsupport file system type(%s)", mount.FSType)
}
if quota == nil {
return nil, errors.Errorf("failed to new quota for file(%s)", file)
}
QuotaMapAdd(mount.MountPoint, quota)
return quota, nil
}