linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Monakhov <dmonakhov@openvz.org>
To: Al Viro <viro@ZenIV.linux.org.uk>, linux-fsdevel@vger.kernel.org
Subject: [RFC] vfs generic subtree support
Date: Tue, 16 Feb 2010 13:52:43 +0300	[thread overview]
Message-ID: <87tythtptw.fsf@openvz.org> (raw)

Initially i've posted RFC patch-set which add subtree support for ext4.
http://marc.info/?l=linux-ext4&m=126563931215496&w=2
But in fact this is rather generic feature which may be implemented 
in vfs layer similar to namespace or security feature.

A subtree of a directory tree T is a tree consisting of a directory
(the subtree root) in T and all of its descendants in T.

Subtree assumptions:
* Each inode has subtree id (this id is stored inside inode).
* Subtree id is inherent from parent directory if corresponding flag is set
* Inode can not belongs to different subtrees

i've ommit subtree_type feature in order to simplify brief explanation.

Subtree with id == 0 has special meaning. It may contains roots of
other subtrees (this feature is used for cross subtree renames)
This feature has much in common with XFS project_id.

There are many usecases for such subtrees
1) Choroot environment or Containers on common file-system
   administrator creates a subtree,and setup quota
   #mkdir chroot-env
   #chattr -Q ${subtree_id} chroot-env
   #tar jxf /tmp/fedora-x86_64.tar.bz2 -C chroot-env
   #### as soon as subtree id inherented from parent untared content
   #### automatically belongs to ${subtree_id}
   #quotactl --type=subtree --id=${subtree_id} --bsoft=1000000 --bhard=1000000
   ###
   #chroot chroot-env /bin/bash
2) NFS quota on server side
   Administrator perform exactly the same stages, but instead of chroot
   hi just export result subtree to nfs server
One may imagine it's own usecase.


Usually we already have some content which we want to see as subtree
In this case we have to in-depth traverse it from the subtree root.
add_to_subtree(dir, subtree_id) /* in-depth  tree traversal */
{
	while(de = getdents(dir)) {
	     if (IS_DIR(de))
		    add_to_subtree(de, subtree_id)
             else
	            set_subtree_id(de, subtree);
       }
       set_subtree_id(de, subtree);
}
It is possible to manipulate subtree content

For example we have following hierarchy
/root/subtree-1/a/b/c/d/e/f/g
/root/subtree-2/dir/
want rename /root/subtree-1/a to /root/subtree-2/dir/AA
first we have to move "a" to default tree "root"
 #rename /root/subtree-1/a /root/a-1
Then we have assign to default subtree. Do it in width traverse order
Because otherwise this result in subtree assumptions violation.
 #walk_in_width(/root/AA, 0 /* default subtree */)
Then  assign target subtree_id
 #walk_in_depth(/root/AA, 2)
Ok now all content from /root/a-1 belongs to subtree_id == 2 so it is possible
rename it in to target place
 #rename /root/a-1 /root/subtree-2/dir/AA


             reply	other threads:[~2010-02-16 10:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-16 10:52 Dmitry Monakhov [this message]
2010-02-16 12:20 ` [RFC] vfs generic subtree support Al Viro
2010-02-16 12:37   ` Dmitry Monakhov
2010-02-16 13:38     ` Al Viro
2010-02-16 14:01       ` Dmitry Monakhov
2010-02-16 14:21         ` Al Viro
2010-02-16 15:00           ` Dmitry Monakhov
2010-02-16 15:12             ` Matthew Wilcox
2010-02-16 15:32               ` Dmitry Monakhov
2010-02-16 19:25                 ` J. Bruce Fields
2010-02-16 19:32                   ` Christoph Hellwig
2010-02-16 19:39                     ` J. Bruce Fields

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tythtptw.fsf@openvz.org \
    --to=dmonakhov@openvz.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@ZenIV.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).