blob: 1a2ad2150ed007929a22394212c1bf76b0b628d5 [file] [log] [blame]
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
]>
<chapter id="xfs-quotas">
<title>XFS Quotas</title>
<section>
<title>Quotas</title>
<para>Quotas provide a method for managing disk resources.</para>
<itemizedlist>
<listitem><para>Quotas can be used to report on disk usage.</para></listitem>
<listitem><para>Quotas can be used to control disk usage.</para></listitem>
</itemizedlist>
<para>Quotas manage filesystem resources in two ways.</para>
<itemizedlist>
<listitem><para>by Managing Disk Space (blocks)</para></listitem>
<listitem><para>by Managing the Number of Files (inodes)</para></listitem>
</itemizedlist>
<para>These resources can be managed on a per user, group or directory (project) basis.</para>
</section>
<section>
<title>Quota Types</title>
<para>Quotas can be tracked or enforced for</para>
<para>Users</para>
<itemizedlist>
<listitem><para>Manage the disk usage of individuals or system users.</para></listitem>
</itemizedlist>
<para>Groups</para>
<itemizedlist>
<listitem><para>Manage the disk usage of groups.</para></listitem>
</itemizedlist>
<para>Projects</para>
<itemizedlist>
<listitem><para>Manage the disk usage of directories associated with a specific project.
Projects may cross organizational 'group' boundaries</para></listitem>
<listitem><para>Provide broader levels of control than available using user or group quotas.</para></listitem>
<listitem><para>Can be used to effectively shrink a file system allowing administrators to
reallocate disk space as needed.</para></listitem>
</itemizedlist>
</section>
<section>
<title>Reporting Vs Enforcement</title>
<para>Quotas can be used to monitor disk usage and optionally enforce limits.</para>
<para>Quotas can be used to monitor disk usage across quota types.</para>
<itemizedlist>
<listitem><para>More efficient than using unix tools like du that must traverse the filesystem.</para></listitem>
<listitem><para>Quotas are maintained as the filesystem is used.</para></listitem>
</itemizedlist>
<para>Quotas can be used to enforce limits on users, groups or projects. Quota limits can prevent.</para>
<itemizedlist>
<listitem><para>Individual users consuming excessive resources.</para></listitem>
<listitem><para>Rogue processes bringing down a system or causing denial of services.</para></listitem>
</itemizedlist>
</section>
<section>
<title>Enforcement (Limits)</title>
<para>There are two types of limits; Hard and Soft.</para>
<para>Soft limits are advisory.</para>
<itemizedlist>
<listitem><para>Allow additional disk resources to be consumed for a period of time.
this is known as the <emphasis>grace</emphasis> period.</para></listitem>
<listitem><para>Provide flexibility to users and processes that may occasionally
need to exceed there quota temporarily</para></listitem>
</itemizedlist>
<para>Hard Prevent further allocation of disk resources.</para>
<itemizedlist>
<listitem><para>Any I/O that attempt to allocate further disk resources is failed.</para></listitem>
<listitem><para>Existing data on the disk is preserved and existing disk allocations can
still be written.</para></listitem>
<listitem><para>Users must remove existing files to before new resources can be used.</para></listitem>
<listitem><para>Soft limits are be enforced as hard limits after the <emphasis>grace</emphasis> period.</para></listitem>
</itemizedlist>
<para>Limits are never applied to the <emphasis>root</emphasis> user.</para>
</section>
<section>
<title>Configuring Quotas</title>
<para>XFS quotas are enabled as filesystem mount options when the filesystem is mounted.</para>
<para>User, Group and Project quotas are enabled independently. Group and Project quotas are incompatible.</para>
<para>Each quota type can be specified as noenforce, in this case quota reporting will be maintained but not enforced.</para>
<para>Valid mount options are</para>
<itemizedlist>
<listitem><para>uquota, uqnoenforce - User quotas</para></listitem>
<listitem><para>gquota, gqnoenforce - Group quotas</para></listitem>
<listitem><para>pquota, pqnoenforce - Project quota</para></listitem>
</itemizedlist>
</section>
<section>
<title>xfs_quota</title>
<para>Once quotas are configured the xfs_quota tool can be used to report on disk usage and set limits.</para>
<para>Quota operation is controlled by xfs_quota.</para>
<para><command>xfs_quota</command> has two modes of operation, basic and expert mode</para>
<itemizedlist>
<listitem><para>Basic mode includes commands for reporting disk usage to users</para></listitem>
<listitem><para>Expert mode (<command>xfs_quota -x</command>) contains advanced commands
that allow the modification of the quota system.</para></listitem>
</itemizedlist>
</section>
<section>
<title>Quota Reporting</title>
<para><programlisting>
> sudo xfs_quota -xc 'report -h' /home
User quota on /home (/dev/hdb1)
Blocks
User ID Used Soft Hard Warn/Grace
---------- ---------------------------------
root 4.6G 0 0 00 [------]
testuser 103.4G 0 0 00 [------]
...
</programlisting></para>
<para>Running report as an ordinary user simply reports that users disk usage while running as
root allows the disk usage of all users to be reported.</para>
<para>Performance</para>
<itemizedlist>
<listitem><para>sudo xfs_quota -xc 'report -h' /home 0m0.287s</para></listitem>
<listitem><para>sudo du -hs /home 0m3.086s</para></listitem>
</itemizedlist>
</section>
<section>
<title>Quota Limits</title>
<para>User Limits</para>
<itemizedlist>
<listitem><para><command>limits xfs_quota -x -c 'limit bsoft=1000m bhard=1200m username'</command></para></listitem>
<listitem><para><command>limits xfs_quota -x -c 'limit isoft=500 ihard=700 username'</command></para></listitem>
</itemizedlist>
<para>Group Limits.</para>
<itemizedlist>
<listitem><para><command>xfs_quota -x -c 'limit -g bsoft=1000m bhard=1200m groupname'</command></para></listitem>
</itemizedlist>
<para>Project Limits</para>
<itemizedlist>
<listitem><para>Project controlled directories are first added to /etc/projects. Project names are
optionally added to /etc/projid to provide an id/name mapping.</para></listitem>
<listitem><para><command>xfs_quota -c 'project -s projectname'</command> is run to
initialize project directories.</para></listitem>
<listitem><para><command>xfs_quota -x -c 'limit -p bsoft=1000m bhard=1200m projectname'</command></para></listitem>
</itemizedlist>
</section>
<section>
<title>Enabling/Disabling Quotas</title>
<para>xfs_quota can be used to temporarily or permanently disable quotas on a filesystem
using the following commands:</para>
<itemizedlist>
<listitem><para>disable – Temporarily disable quota enforcement.</para></listitem>
<listitem><para>enable – Enable quota enforcement. Used to enable quotas if they have
been disabled or the filesystem was mounted with qnoenforce.</para></listitem>
<listitem><para>off – Switch off quota management quotas can only be re-enabled by un-mounting
and remounting the filesystem
<itemizedlist>
<listitem><para>Limit information is preserved</para></listitem>
</itemizedlist>
</para></listitem>
<listitem><para>remove – remove quota extents from a filesystem. All quota limits are destroyed.</para></listitem>
</itemizedlist>
</section>
<section>
<title>Expert xfs commands</title>
<para>xfs_quota also contains commands to</para>
<itemizedlist>
<listitem><para>Summarise the state of xfs quotas on a system using the
<emphasis>state</emphasis> command.</para></listitem>
<listitem><para>Manipulate the grace period using the <emphasis>timer</emphasis> command.</para></listitem>
<listitem><para>Backup and restore the quota information contained in a filesystem using
the <emphasis>dump</emphasis> and <emphasis>restore</emphasis> commands.
These commands are also used internally by xfsdump</para></listitem>
</itemizedlist>
</section>
<section>
<title>Generic Quota Tools</title>
<para>In addition to xfs_quota xfs also works with generic quota tools provided on Linux.</para>
<para>These tools include</para>
<itemizedlist>
<listitem><para>quota</para></listitem>
<listitem><para>repquota</para></listitem>
<listitem><para>quotactl</para></listitem>
<listitem><para>edquota</para></listitem>
<listitem><para>quotacheck</para></listitem>
<listitem><para>setquota</para></listitem>
<listitem><para>quotaon/quotaoff (enforcement only)</para></listitem>
<listitem><para>quotawarn</para></listitem>
</itemizedlist>
<para>The generic tools to not understand XFS project quotas.</para>
</section>
<section>
<title>Providing user feedback</title>
<para>Usually systems are configured to provide a level of feedback to users if they exceed their quota limits.</para>
<para>The most common method for informing users is to send email using the quotawarn command
from the generic quota package.</para>
<itemizedlist>
<listitem><para>Quotawarn is often run as a cron job daily.</para></listitem>
</itemizedlist>
<para>Feedback can be provided for interactive users by running “xfs_quota -c quota” in users
login scripts (/etc/bash.bashrc.local for example).</para>
</section>
<section>
<title>Implementation</title>
<para>Quota operations and data are treated as first-class operations in XFS</para>
<itemizedlist>
<listitem><para>xfs quotas are implemented as part of the filesystem metadata instead of
maintaining quota data in a file within filesystem</para></listitem>
<listitem><para>Quota changes are journaled</para></listitem>
</itemizedlist>
<para>Quotas are updated in realtime as the filesystem is changed. No “quota checks” need to be run.</para>
</section>
<section>
<title>Implementation – Project Quotas.</title>
<para>Project quotas are implemented using the group quota inode. This excludes project
and group quotas from being enabled at the same time.</para>
<para>Project configuration information is stored in /etc/projects and /etc/projid.</para>
<para>xfs_quota -s projectname initializes the project id in inodes contained under
directories specified in /etc/projects.</para>
</section>
<section>
<title>Quotas Ondisk</title>
<para>xfs_db can be used to understand the internals of the quota implementation.</para>
<para>Quota inodes can be seen in the filesystem superblock</para>
<para><programlisting>
# xfs_db -xr -c sb -c p /dev/hdb1
...
uquotino = 131
gquotino = 148
# xfs_db -xr -c 'inode 131' -c p /dev/hdb1</programlisting></para>
</section>
<section>
<title>Quotas Ondisk</title>
<para>Individual quota entries can be viewed with xfs_db's dquot command.</para>
<para><programlisting># xfs_db -xr -c 'dquot username' -c p /dev/hdb1</programlisting></para>
<para><programlisting># xfs_db -xr -c 'dquot -p projectname' -c p /dev/hdb1</programlisting></para>
<para>inodes can be interrogated to determine which project they belong to.</para>
<para><programlisting>
> ls -ia
> sudo xfs_db -xr -c 'inode 675234191' -c p /dev/hdb1
...
core.projid = 33
core.uid = 0
core.gid = 0</programlisting></para>
</section>
</chapter>