Tag Archives: fs

Per directory quota: not just a dream

Ext3 and many other popular filesystems allow per-user and per-group quota. In some cases, a "per directory tree quota" is needed: doesn't matter who writes the files, limit a directory tree from growing to a size of more than X bytes.

As I see it, it can be good for many cases, either limiting a directory from exploding (Lior wrote about a similar problem a few weeks ago), or simply allocating space per team-projects on a file server.

As far as I knew, the only UNIX FS that implemented this feature was Sun's unpopular SAMFS/QFS. However, I've just stumbled upon this man page and was surprised to find out that the good old (well, at least old 🙂 ) XFS does that already!

A quick "howto use project quota" cookbook:

1. Make the filesystem and mount it:

> mkfs.xfs /dev/loop0
> mount /dev/loop0 /mnt/tmp -o pquota

2. Create a project named "project1", which is the "/mnt/tmp/tree1" tree:

> echo "11:/mnt/tmp/tree1" >> /etc/projects
> echo "project1:11" >> /etc/projid
> xfs_quota -x -c 'project -s project1' /mnt/tmp

3. Set the tree quota to 2 MB:

> xfs_quota -x -c 'limit -p bhard=2m project1' /mnt/tmp

4. That's it.. Now let's make some tests:

> dd if=/dev/zero of=/mnt/tmp/tree1/aaa count=10 bs=1024k
dd: writing `aaa': No space left on device
2+0 records in
1+0 records out

2093056 bytes (2.1 MB) copied, 1.51164 s, 1.4 MB/s

> touch fdsa
touch: cannot touch `fdsa': Disk quota exceeded

5. And there's also a nice report! (looks nicer with a fixed-width console font)

> xfs_quota -x -c 'report /mnt/tmp'
Project quota on /mnt/tmp (/dev/loop0)
Project ID       Used       Soft       Hard    Warn/Grace
---------- --------------------------------------------------
project1         2044          0       2048     00 [--------]
project2            0          0          0     00 [--------]