1 //go:build linux 2 // +build linux 3 4 /* 5 Copyright 2018 The Kubernetes Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 */ 19 20 package common 21 22 import ( 23 "regexp" 24 ) 25 26 // QuotaType -- type of quota to be applied 27 type QuotaType int 28 29 const ( 30 // FSQuotaAccounting for quotas for accounting only 31 FSQuotaAccounting QuotaType = 1 << iota 32 // FSQuotaEnforcing for quotas for enforcement 33 FSQuotaEnforcing QuotaType = 1 << iota 34 ) 35 36 // FirstQuota is the quota ID we start with. 37 // XXXXXXX Need a better way of doing this... 38 var FirstQuota QuotaID = 1048577 39 40 // MountsFile is the location of the system mount data 41 var MountsFile = "/proc/self/mounts" 42 43 // MountParseRegexp parses out /proc/sys/self/mounts 44 var MountParseRegexp = regexp.MustCompilePOSIX("^([^ ]*)[ \t]*([^ ]*)[ \t]*([^ ]*)") // Ignore options etc. 45 46 // LinuxVolumeQuotaProvider returns an appropriate quota applier 47 // object if we can support quotas on this device 48 type LinuxVolumeQuotaProvider interface { 49 // GetQuotaApplier retrieves an object that can apply 50 // quotas (or nil if this provider cannot support quotas 51 // on the device) 52 GetQuotaApplier(mountpoint string, backingDev string) LinuxVolumeQuotaApplier 53 } 54 55 // LinuxVolumeQuotaApplier is a generic interface to any quota 56 // mechanism supported by Linux 57 type LinuxVolumeQuotaApplier interface { 58 // GetQuotaOnDir gets the quota ID (if any) that applies to 59 // this directory 60 GetQuotaOnDir(path string) (QuotaID, error) 61 62 // SetQuotaOnDir applies the specified quota ID to a directory. 63 // Negative value for bytes means that a non-enforcing quota 64 // should be applied (perhaps by setting a quota too large to 65 // be hit) 66 SetQuotaOnDir(path string, id QuotaID, bytes int64) error 67 68 // QuotaIDIsInUse determines whether the quota ID is in use. 69 // Implementations should not check /etc/project or /etc/projid, 70 // only whether their underlying mechanism already has the ID in 71 // use. 72 // Return value of false with no error means that the ID is not 73 // in use; true means that it is already in use. An error 74 // return means that any quota ID will fail. 75 QuotaIDIsInUse(id QuotaID) (bool, error) 76 77 // GetConsumption returns the consumption (in bytes) of the 78 // directory, determined by the implementation's quota-based 79 // mechanism. If it is unable to do so using that mechanism, 80 // it should return an error and allow higher layers to 81 // enumerate the directory. 82 GetConsumption(path string, id QuotaID) (int64, error) 83 84 // GetInodes returns the number of inodes used by the 85 // directory, determined by the implementation's quota-based 86 // mechanism. If it is unable to do so using that mechanism, 87 // it should return an error and allow higher layers to 88 // enumerate the directory. 89 GetInodes(path string, id QuotaID) (int64, error) 90 } 91