mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
btrfs: Do not disable quota on cleanup
Before this change, cleanup of the btrfs driver (occuring on each daemon
shutdown) resulted in disabling quotas. It was done with an assumption
that quotas can be enabled or disabled on a subvolume level, which is
not true - enabling or disabling quota is always done on a filesystem
level.
That was leading to disabling quota on btrfs filesystems on each daemon
shutdown.
This change fixes that behavior and removes misleading `subvol` prefix
from functions and methods which set up quota (on a filesystem level).
Fixes: #34593
Fixes: 401c8d1767
("Add disk quota support for btrfs")
Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
This commit is contained in:
parent
68bec0fcf7
commit
1ec689c4c2
1 changed files with 8 additions and 42 deletions
|
@ -96,7 +96,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
|
||||||
}
|
}
|
||||||
|
|
||||||
if userDiskQuota {
|
if userDiskQuota {
|
||||||
if err := driver.subvolEnableQuota(); err != nil {
|
if err := driver.enableQuota(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,18 +165,10 @@ func (d *Driver) GetMetadata(id string) (map[string]string, error) {
|
||||||
|
|
||||||
// Cleanup unmounts the home directory.
|
// Cleanup unmounts the home directory.
|
||||||
func (d *Driver) Cleanup() error {
|
func (d *Driver) Cleanup() error {
|
||||||
err := d.subvolDisableQuota()
|
if err := mount.Unmount(d.home); err != nil {
|
||||||
umountErr := mount.Unmount(d.home)
|
|
||||||
|
|
||||||
// in case we have two errors, prefer the one from disableQuota()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if umountErr != nil {
|
|
||||||
return umountErr
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,7 +326,7 @@ func (d *Driver) updateQuotaStatus() {
|
||||||
d.once.Do(func() {
|
d.once.Do(func() {
|
||||||
if !d.quotaEnabled {
|
if !d.quotaEnabled {
|
||||||
// In case quotaEnabled is not set, check qgroup and update quotaEnabled as needed
|
// In case quotaEnabled is not set, check qgroup and update quotaEnabled as needed
|
||||||
if err := subvolQgroupStatus(d.home); err != nil {
|
if err := qgroupStatus(d.home); err != nil {
|
||||||
// quota is still not enabled
|
// quota is still not enabled
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -343,7 +335,7 @@ func (d *Driver) updateQuotaStatus() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) subvolEnableQuota() error {
|
func (d *Driver) enableQuota() error {
|
||||||
d.updateQuotaStatus()
|
d.updateQuotaStatus()
|
||||||
|
|
||||||
if d.quotaEnabled {
|
if d.quotaEnabled {
|
||||||
|
@ -369,32 +361,6 @@ func (d *Driver) subvolEnableQuota() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) subvolDisableQuota() error {
|
|
||||||
d.updateQuotaStatus()
|
|
||||||
|
|
||||||
if !d.quotaEnabled {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
dir, err := openDir(d.home)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer closeDir(dir)
|
|
||||||
|
|
||||||
var args C.struct_btrfs_ioctl_quota_ctl_args
|
|
||||||
args.cmd = C.BTRFS_QUOTA_CTL_DISABLE
|
|
||||||
_, _, errno := unix.Syscall(unix.SYS_IOCTL, getDirFd(dir), C.BTRFS_IOC_QUOTA_CTL,
|
|
||||||
uintptr(unsafe.Pointer(&args)))
|
|
||||||
if errno != 0 {
|
|
||||||
return fmt.Errorf("Failed to disable btrfs quota for %s: %v", dir, errno.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
d.quotaEnabled = false
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Driver) subvolRescanQuota() error {
|
func (d *Driver) subvolRescanQuota() error {
|
||||||
d.updateQuotaStatus()
|
d.updateQuotaStatus()
|
||||||
|
|
||||||
|
@ -437,11 +403,11 @@ func subvolLimitQgroup(path string, size uint64) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// subvolQgroupStatus performs a BTRFS_IOC_TREE_SEARCH on the root path
|
// qgroupStatus performs a BTRFS_IOC_TREE_SEARCH on the root path
|
||||||
// with search key of BTRFS_QGROUP_STATUS_KEY.
|
// with search key of BTRFS_QGROUP_STATUS_KEY.
|
||||||
// In case qgroup is enabled, the retuned key type will match BTRFS_QGROUP_STATUS_KEY.
|
// In case qgroup is enabled, the retuned key type will match BTRFS_QGROUP_STATUS_KEY.
|
||||||
// For more details please see https://github.com/kdave/btrfs-progs/blob/v4.9/qgroup.c#L1035
|
// For more details please see https://github.com/kdave/btrfs-progs/blob/v4.9/qgroup.c#L1035
|
||||||
func subvolQgroupStatus(path string) error {
|
func qgroupStatus(path string) error {
|
||||||
dir, err := openDir(path)
|
dir, err := openDir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -608,7 +574,7 @@ func (d *Driver) setStorageSize(dir string, driver *Driver) error {
|
||||||
if d.options.minSpace > 0 && driver.options.size < d.options.minSpace {
|
if d.options.minSpace > 0 && driver.options.size < d.options.minSpace {
|
||||||
return fmt.Errorf("btrfs: storage size cannot be less than %s", units.HumanSize(float64(d.options.minSpace)))
|
return fmt.Errorf("btrfs: storage size cannot be less than %s", units.HumanSize(float64(d.options.minSpace)))
|
||||||
}
|
}
|
||||||
if err := d.subvolEnableQuota(); err != nil {
|
if err := d.enableQuota(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return subvolLimitQgroup(dir, driver.options.size)
|
return subvolLimitQgroup(dir, driver.options.size)
|
||||||
|
@ -662,7 +628,7 @@ func (d *Driver) Get(id, mountLabel string) (containerfs.ContainerFS, error) {
|
||||||
|
|
||||||
if quota, err := ioutil.ReadFile(d.quotasDirID(id)); err == nil {
|
if quota, err := ioutil.ReadFile(d.quotasDirID(id)); err == nil {
|
||||||
if size, err := strconv.ParseUint(string(quota), 10, 64); err == nil && size >= d.options.minSpace {
|
if size, err := strconv.ParseUint(string(quota), 10, 64); err == nil && size >= d.options.minSpace {
|
||||||
if err := d.subvolEnableQuota(); err != nil {
|
if err := d.enableQuota(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := subvolLimitQgroup(dir, size); err != nil {
|
if err := subvolLimitQgroup(dir, size); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue