1 * directory tree quota desing and implementation
3 This document contains basic introduction to directory tree
4 quota for didicated trees. Currently Linux support many
5 virtualization extentions. One of approaches is containers.
6 Containers is OS level paravirtualization like jail in BSD.
7 In two words container is a set of process isolated from
8 other system. Each process has it's own name-spaces for
9 network,fs,ipc,etc. You may think of container as secure chroot.
11 ** Containers fs root requirement
12 So container's root are independent tree or several trees.
13 usually they organized like follows */ct-root/CT${ID\}/${tree-content}*
14 There are many reasons to keep this trees separate one from another
16 If inode has links in A and B trees. And A-user call chown() for
17 this inode, then B's owner will be surprised.
18 The only way to overcome this is to virtualize inode atributes
19 (for each tree) which is madness IMHO.
20 - checkpoint/restore/online-backup ::
21 This is like suspend resume for VM, but in this case only
22 container's process are stopped(freezed) for some time. After CT's
23 process are stopped we may create backup CT's tree without freezing
26 As I already say there are many way to accomplish this task. But everyone
27 has strong disadvantages:
29 - Virtual block devices(qemu-like) :: problems with consistency and performance
30 - ext3/4 + stack-fs(unionfs) :: Bad failure resistance. It is impossible to support jorunalling quota file on stack-fs level.
31 - XFS with proj quota :: Lack of quota file journalling.
33 So the only way to implement journalled quota for containers is to
34 implement it on native fs level.
36 ** Containers directory tree-id assumptions
37 1) Tree id is embedded inside inode
38 2) Tree id is inherent from parent dir
39 3) Inode can not belongs to different directory trees
41 Default directory tree (with id == 0) has special meaning.
42 directory which belongs to default tree may contains roots of
43 other trees. Default tree is used for subtree manipulation.
44 *** ->rename() restriction
46 if (S_ISDIR(old_inode->i_mode)) {
47 if ((new_dir->i_tree_id == 0) || /* move to default tree */
48 (new_dir->i_tree_id == old_inode->i_tree_id)) /*same tree */
52 /* If entry have more than one link then it is bad idea to allow
53 rename it to different (even if it's default tree) tree,
54 because this result in rule (3) violation.
56 if (old_inode->i_nlink > 1) &&
57 (new_dir->i_tree_id != old_inode->i_tree_id)
62 *** ->link restriction
64 /* Links may belongs to only one tree */
65 if(new_dir->i_tree_id != old_inode->i_tree_id)
69 I've prepare proof of concept patch queue.
70 [[http://www.2ka.mipt.ru/~mov/tree-quota.tgz][patch-queue]]
72 This part containt some tips of tree-quota usage. Assume you have kernel
73 with tree-quota patch applied.
74 *** Enabling tree quota
76 Currently quota-tools has no tree-quota support. So you have to manually
77 create aquota.tree file. Just copy quota-tree/tool/aquota.tree to the root
79 mount /test/fs.img /mnt -oloop,quota,grpquota,treeid,trquota
80 cp quota-tree/tool/aquota.tree /mnt/
82 quota-tree/tool/quotactl --on --all --path /mnt --dev /dev/loop0
83 # show quotas type ==0 -> usrquota, type == 2 -> trqota
84 quota-tree/tool/quotactl --get --all --type 2 --dev /dev/loop0
86 *** Creating containers tree
88 # create root dir for directory-tree
90 # Assign id for the root
91 ./chattr -Q 1 /mnt/ct-root-1
92 # set quota limits for tree
93 quota-tree/tool/quotactl --set --type 2 --bsoft 100000 --bhard 110000 --dev /dev/loop0
95 quota-tree/tool/quotactl --get --all --type 2 --dev /dev/loop0
96 # Populate root with content, it will be accounted in to
97 # tree-quota with id "1"
98 tar zxf root.tar -C /mnt/ct-root-1
100 quota-tree/tool/quotactl --get --all --type 2 --dev /dev/loop0