{"id":80,"date":"2008-07-29T01:44:58","date_gmt":"2008-07-28T22:44:58","guid":{"rendered":"http:\/\/www.held.org.il\/blog\/?p=80"},"modified":"2012-06-20T09:42:17","modified_gmt":"2012-06-20T06:42:17","slug":"per-directory-quota-not-a-dream","status":"publish","type":"post","link":"http:\/\/www.held.org.il\/blog\/2008\/07\/per-directory-quota-not-a-dream\/","title":{"rendered":"Per directory quota: not just a dream"},"content":{"rendered":"<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Ext3\">Ext3<\/a> 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.<\/p>\n<p>As I see it, it can be good for many cases, either limiting a directory from exploding (Lior <a href=\"http:\/\/liorkaplan.wordpress.com\/2008\/07\/02\/to-separate-or-not-to-separate-the-file-systems\/\">wrote about a similar problem<\/a> a few weeks ago), or simply allocating space per team-projects on a file server.<\/p>\n<p>As far as I knew, the only UNIX FS that implemented this feature was Sun's unpopular <a href=\"http:\/\/en.wikipedia.org\/wiki\/QFS\">SAMFS\/QFS<\/a>. However, I've just stumbled upon <a title=\"xfs_quota(8) manpage\" href=\"http:\/\/linux.die.net\/man\/8\/xfs_quota\">this man page<\/a> and was surprised to find out that the good old (well, at least old \ud83d\ude42 ) <a href=\"http:\/\/en.wikipedia.org\/wiki\/XFS\">XFS<\/a> does that already!<\/p>\n<p><span style=\"color: #888888;\"><strong>A quick \"howto use project quota\" cookbook:<\/strong><\/span><\/p>\n<p>1. Make the filesystem and mount it:<\/p>\n<blockquote><p>&gt; mkfs.xfs \/dev\/loop0<br \/>\n&gt; mount \/dev\/loop0 \/mnt\/tmp -o pquota<\/p><\/blockquote>\n<p>2. Create a project named \"project1\", which is the \"\/mnt\/tmp\/tree1\" tree:<\/p>\n<blockquote><p>&gt; echo \"11:\/mnt\/tmp\/tree1\" &gt;&gt; \/etc\/projects<br \/>\n&gt; echo \"project1:11\" &gt;&gt; \/etc\/projid<br \/>\n&gt; xfs_quota -x -c 'project -s project1' \/mnt\/tmp<\/p><\/blockquote>\n<p>3. Set the tree quota to 2 MB:<\/p>\n<blockquote><p>&gt; xfs_quota -x -c 'limit -p bhard=2m project1' \/mnt\/tmp<\/p><\/blockquote>\n<p>4. That's it.. Now let's make some tests:<\/p>\n<blockquote><p>&gt; dd if=\/dev\/zero of=\/mnt\/tmp\/tree1\/aaa count=10 bs=1024k<br \/>\ndd: writing `aaa': No space left on device<br \/>\n2+0 records in<br \/>\n1+0 records out<\/p>\n<p>2093056 bytes (2.1 MB) copied, 1.51164 s, 1.4 MB\/s<\/p><\/blockquote>\n<blockquote><p>&gt; touch fdsa<br \/>\ntouch: cannot touch `fdsa': Disk quota exceeded<\/p><\/blockquote>\n<p>5. And there's also a nice report! (looks nicer with a fixed-width console font)<\/p>\n<blockquote><p>&gt; xfs_quota -x -c 'report \/mnt\/tmp'<br \/>\nProject quota on \/mnt\/tmp (\/dev\/loop0)<br \/>\nBlocks<br \/>\nProject ID\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Used\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Soft\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Hard\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Warn\/Grace<br \/>\n---------- --------------------------------------------------<br \/>\nproject1\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 2044\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 2048\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 00 [--------]<br \/>\nproject2\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 00 [--------]<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Ext3 and many other popular filesystems allow per-user and per-group quota. In some cases, a &#8220;per directory tree quota&#8221; is needed: doesn&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[75],"tags":[39,44,203,94,131],"_links":{"self":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts\/80"}],"collection":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/comments?post=80"}],"version-history":[{"count":0,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts\/80\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/media?parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/categories?post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/tags?post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}