# Possible bugs with quotas in 12.0-RELEASE-p11.



## wayne47 (Nov 22, 2019)

I have been fighting with quotas in jails and have found a number of inconsistencies with quotas and associated commands on both the host system and the jails. In prior releases, I have successfully deployed jails supporting quotated users with *ezjail. *I'm looking to move to 12.x and have been working with Joe who developed qjail. All of this is on a 12.0-RELEASE-p11 system.

Before the usual objections arise, consider this environment:

Any UID which will use quotas will normally, by policy, insured to be unique to a single jail. Test users (_i.e. _sysadmins) may violate this policy and are expected to deal with the implications.
Normal users who have quotas applied do not have root or sudo access on the jail or accounts on the host.
I understand that applying a quota to a UID should apply that at the filesystem level, including files on the host as well as any jails.
For a number of reasons, UFS is the correct solution.  ZFS is not an option.
For testing, I have done the following with an md backed file system to make starting with a clean slate easy. Similar issues arise with disk based file systems. The following issues/bugs are demonstrated:

The repquota command appears to fail on both the host and the jail
When a user, on either the host or the jail, overruns his quota, a proper error message is written but an additional improper message that the filesystem is full is also printed. Mostly cosmetic but it caused *me* to panic when I first saw it.
The quota command fails on a jail, This means that there is no way for a user, running on in a jail, to check his own quotas, despite the quota.user file being viable to the jailed user.
I *would *expect this behavior if I had specified a different quota file location, inaccessible to the jail, in the hosts /etc/fstab but in this case, I did not.
Before I file a PR, I was looking for another set of eyes to check my findings.

Create a clean ufs disk to work on and mount it so the jail can see it

```
host % sudo dd if=/dev/zero of=/usr/jails/ww4/QuotaedFs bs=1k count=25k
host % sudo mdmfs -F QuotaedFs -s 25m md0 /usr/jails/ww4/mnt
Set quotas for normal user
[code]
host % sudo edquota wayne
Quotas for user wayne:
/usr/jails/ww4/mnt: in use: 968k, limits (soft = 500k, hard = 1000k)
        inodes in use: 3, limits (soft = 0, hard = 0)[/ICODE]
On the host, enable quotas and shut off automount
[code]
host % grep quota /etc/fstab
/dev/md0        /usr/jails/ww4/mnt ufs  rw,userquota,noauto 2   2[/ICODE]
```
quota command works correctly on host

```
host % quota wayne
Disk quotas for user wayne (uid 5147):
Filesystem        usage    quota   limit   grace  files   quota  limit   grace
/usr/jails/ww4/mnt
                    968*     500    1000   7days      3       0      0
```
repquota command fails on host
host % sudo repquota -a | grep wayne
(nothing printed, error)
The quota file is there (cksum confirms they are the same)

```
host % % ls -l /usr/jails/ww4/mnt/quota.user
-rw-r-----  1 root  operator  329536 Nov 20 23:33 /usr/jails/ww4/mnt/quota.user
jail % ls -l /mnt/quota.user
-rw-r-----  1 root  operator  329536 Nov 20 23:33 /mnt/quota.user
```
Quotas are enforced correctly on host.
System prints an extra message that the file system is full, which is incorrect

```
host % dd if=/dev/random > foo
/usr/jails/ww4/mnt: warning, user disk quota exceeded
/usr/jails/ww4/mnt: write failed, user disk limit reached
/usr/jails/ww4/mnt: write failed, filesystem is full
dd: stdout: Disc quota exceeded
1857+0 records in
1856+0 records out
950272 bytes transferred in 0.015728 secs (60419609 bytes/sec)
```
File system is *not* full: 

```
host % df .
Filesystem 1K-blocks Used Avail Capacity  Mounted on
/dev/md0       24348 1012 21392     5%    /usr/jails/ww4/mnt
```
Remove foo, created on host, test again from jail.
Quotas enforced correctly on jail, again with the extra message about the file system.

```
jail % rm foo
jail % df .
Filesystem 1K-blocks Used Avail Capacity  Mounted on
/dev/md0       24348   52 22352     0%    [restricted]
jail % dd if=/dev/random > bar
/usr/jails/ww4/mnt: warning, user disk quota exceeded
/usr/jails/ww4/mnt: write failed, user disk limit reached
/usr/jails/ww4/mnt: write failed, filesystem is full
dd: stdout: Disc quota exceeded
1857+0 records in
1856+0 records out
950272 bytes transferred in 0.016952 secs (56055559 bytes/sec)
```
quota command fails on jail

```
jail % quota
Disk quotas for user wayne (uid 5147): none
```
repquota command fails on jail, same as host

```
jail % sudo repquota -a | grep wayne
```
(nothing printed, error)


----------



## SirDice (Nov 25, 2019)

wayne47 said:


> Before I file a PR


Upgrade to 12.1 first. Even if 12.0 would have a bug it's not going to get fixed as it will be EoL in about 2 months.


----------

