Skip to contentSkip to conversation

unlink (inode_operations)

DISCUSSION Herbert Poetzl 3 participants 6 messages Jul 5, 2003 – Jul 6, 2003 VFS

lore
Share & tools
lore
#0 lore raw

Hi All!

I'm currently in the process of writing a filesystem which should do nothing but mediate each request to another filesystem (like a noop filter).

(to save reading time, you can skip to LABEL HELP)

I thought I do it the following way:

- on mount a path is given as option this path is translated to an dentry which provides an inode which is 'cloned' and this cloned inode is used as root inode for this filesystem.

- on readdir I do a dcache_readdir on the 'original' dentry and pass this back to the caller.

- on lookup I do a d_lookup in the original filesystem, again the cloning and return the cloned inode.

so far this seems to work reasonably well, now I tried to implement the unlink, again this would perform the unlink in the original filesystem and d_delete the dentry on success.

now what I found was that ext2 seems not to d_delete the dentry at all, at least not when called from my code ...

somewhere I copied the folowing description of
unlink:

called by the unlink(2) system call.
Only required if you want to support deleting inodes.

This should remove the name refered to by the dentry from the directory referred to by the inode. It should d_delete the dentry on success.

---------------------- LABEL HELP

my code does the folowing:
(o_dir is the 'original' directory inode,
o_de the 'original' dentry )

label_a:

	if (o_dir->i_op && o_dir->i_op->unlink)
    	    	ret = o_dir->i_op->unlink(o_dir, o_de);
label_b:
	if (!ret)
	    	d_delete(de);

between label_a and label_b I would expect the d_count of o_de to be decremented ... but this doesn't happen although the file referred to by o_de is unlinked ...

obviously I've missed or misunderstood something, so could anybody explain what is (not) happening?

TIA,
Herbert

#1 lore raw
Quoted 9 lines · Herbert Poetzl

[some background skipped]

label_a:

	if (o_dir->i_op && o_dir->i_op->unlink)
    	    	ret = o_dir->i_op->unlink(o_dir, o_de);
label_b:
	if (!ret)
	    	d_delete(de);
Quoted 3 lines

between label_a and label_b I would expect the d_count of o_de to be decremented ... but this doesn't happen although the file referred to by o_de is unlinked ...

it seems that the current implementation (at least of ext2) does not d_delete the dentry at all, so I assume this is the currently expected behaviour?

I assume the d_delete was moved into vfs_unlink, and I'd better call vfs_unlink instead of the i_op->unlink?

Quoted 2 lines

obviously I've missed or misunderstood something, so could anybody explain what is (not) happening?

any additional explanations are welcome ;)

Quoted 2 lines

TIA,
Herbert

#2 lore raw
In reply to Herbert Poetzl
Quoted 3 lines

I'm currently in the process of writing a filesystem which should do nothing but mediate each request to another filesystem (like a noop filter).

there was a file system like this created for linux 2.2 . it resembles the nullfs of bsd, and called ,similarly, nullfs. i ported the code to 2.4. grab it here:
http://www.cs.bgu.ac.il/~tzachar/nullfs.tar.bz2

it works like a stackable file system, roughly similar to the fist project.

Quoted 2 lines

I assume the d_delete was moved into vfs_unlink, and I'd better call vfs_unlink instead of the i_op->unlink?

ur right, vfs_unlink *does* perform the d_delete if i_op->unlink succeeded. u should really use the vfs code here, since it performs some sanity checks.

========================================================================
nir.

#3 lore raw

Hi Nir!

Quoted 8 lines · Nir Tzachar
Quoted 3 lines

I'm currently in the process of writing a filesystem which should do nothing but mediate each request to another filesystem (like a noop filter).

there was a file system like this created for linux 2.2 . it resembles the nullfs of bsd, and called ,similarly, nullfs. i ported the code to 2.4. grab it here:
http://www.cs.bgu.ac.il/~tzachar/nullfs.tar.bz2

ahh, this is music in my ears ...

many thanks, I will have a close look at this
code before I'll return to the list with more
stupid questions ...

best,
Herbert

Quoted 14 lines

it works like a stackable file system, roughly similar to the fist project.

Quoted 2 lines

I assume the d_delete was moved into vfs_unlink, and I'd better call vfs_unlink instead of the i_op->unlink?

ur right, vfs_unlink *does* perform the d_delete if i_op->unlink succeeded. u should really use the vfs code here, since it performs some sanity checks.

========================================================================
nir.

#4 lore raw
Quoted 1 line

ahh, this is music in my ears ...

<@:-)

Quoted 3 lines

many thanks, I will have a close look at this
code before I'll return to the list with more
stupid questions ...

no question is tooooo stupid...
look at some of my previous postings... ;)

========================================================================
nir.

#5 lore raw
In reply to Nir Tzachar
Quoted 11 lines · Nir Tzachar
Quoted 3 lines

I'm currently in the process of writing a filesystem which should do nothing but mediate each request to another filesystem (like a noop filter).

there was a file system like this created for linux 2.2 . it resembles the nullfs of bsd, and called ,similarly, nullfs. i ported the code to 2.4. grab it here:
http://www.cs.bgu.ac.il/~tzachar/nullfs.tar.bz2

it works like a stackable file system, roughly similar to the fist project.

Herbert, fist (http://www1.cs.columbia.edu/~ezk/research/fist/) can do much more. You can find sources and papers there. With fist, you can produce stackable file systems of different degrees, depending on your needs:

1. A rather small "lite" null-layer f/s that only stacks on struct file/dentry, but shares the inodes b/t the layers. Its measured overhead is less than 0.5%.

2. similar to #1, but it allows you to stack on file name operations: you turn it on in your .fist file w/ the declaration "filter name". This allows you to trap readdir ops, or even change file names (e.g., if you want to encrypt a file name).

3. similar to #1, but it allows you to stack on file data operations: you turn it on in your .fist file w/ the decl "filter data". This allows you to trap read/write and mmap-based ops. Useful when you want, for example, to encrypt file data pages

4. there's code to turn on size-changing file systems, that is, file systems that change the size of the underlying file. For example, compression or other forms of data coding (uuencode). We have examples of gzipfs and uuencodefs.

5. attach-mode: another feature you can turn to generate file systems that allow users to "attach" to a given directory. This is similar to CFS's attach op. We use it in NCryptfs and elsewhere. An attach is like a user-enabled mount.

There's a lot of other things in the fist project, including freebsd and solaris templates. We keep enhancing the code, porting it to new OS versions, fixing bugs when found, etc.

We'll soon release a new fistgen w/ all new freebsd templates, and linux template fixes for all modes (it passes fsx, large parallel compile, and several other f/s exercisers we wrote). Stay tuned on this list.

Cheers,
Erez.