Skip to contentSkip to conversation

reiser4: writing plugins

DISCUSSION dannym 5 participants 6 messages Dec 16, 2005 – Dec 23, 2005

lore
Share & tools
lore

dannym

author
#0 lore raw

Hi,

So I want to start writing a small plugin to get a feel for the architecture...

I wonder how to do that?

I read that in order to write plugins, one has to recompile the kernel... which is ok, but that also means that it will affect everything and when I make a mistake, everything goes bad :)

So I wondered if all you reiser4 developers have some kind of sandbox thing that just does the same with a library (without the kernel) and on an image file?

Or do you use a virtual machine for that kind of stuff?

As for what I thought would be a nice intro thing for me to write is:

Adds a pseudo file "tree-contents-size" for directories. Pseudo file contains the "du" starting from this directory.

What it should do is cache some kind of "du"-like value per directory. When you change a file size (or delete a file, add a file, ...) in the dir or one of it's subdirs, it shall set a dirty flag on the value. When the pseudo file is accessed, it shall calculate it anew, also updating the subdirs' pseudo files if so needed, and store it actually on disk...
(could also be updated periodically without anyone requesting it, but that's just a detail)

What do you think? Useful? Bad Thing? Already done? Too hard for a first try?

cheers,
Danny

#1 lore raw

Danny,

It's good to hear from you. The Reiser4 plugin system is somewhat subtle. Over the past four months our group has attempted to become the first group outside Namesys to create a Reiser4 plugin. We have had some various successes and failures and are hoping to document much of the experience for general consumption.

-pvh

Quoted 36 lines · dannym

Hi,

So I want to start writing a small plugin to get a feel for the architecture...

I wonder how to do that?

I read that in order to write plugins, one has to recompile the kernel... which is ok, but that also means that it will affect everything and when I make a mistake, everything goes bad :)

So I wondered if all you reiser4 developers have some kind of sandbox thing that just does the same with a library (without the kernel) and on an image file?

Or do you use a virtual machine for that kind of stuff?

As for what I thought would be a nice intro thing for me to write is:

Adds a pseudo file "tree-contents-size" for directories. Pseudo file contains the "du" starting from this directory.

What it should do is cache some kind of "du"-like value per directory. When you change a file size (or delete a file, add a file, ...) in the dir or one of it's subdirs, it shall set a dirty flag on the value. When the pseudo file is accessed, it shall calculate it anew, also updating the subdirs' pseudo files if so needed, and store it actually on disk...
(could also be updated periodically without anyone requesting it, but that's just a detail)

What do you think? Useful? Bad Thing? Already done? Too hard for a first try?

cheers,
Danny

Signature · 2 lines
Peter van Hardenberg ([email protected])
Victoria, BC, Canada
#2 lore raw

Hi Danny,

It's true that you'll need to recompile the kernel, and you could be at risk for messing up your system. Peter and I were lucky enough to get our hands on an extra PC for our project here, but the system survived for the duration without any damage. We're about to release some documentation about developing plugins that you may find useful.

Initially we looked into using virtual machines, but we found that to be more trouble than it was worth. If you can get your kernel recompiled with Reiser4 enabled, you're well on your way. All you need to do is create a file on your disk and then you can format it with reiser4progs and mount it as a virtual disk.

To do what you're proposing, you're going to have a few problems. First of all, pseudo files are only in memory, without any on disk storage. So to store your "du" value you're going to need to create some space someplace. I'm guessing you'd put your storage in the inode. Once you have that storage somewhere, you'd need to do the following.
-Write your own printing function to output the value in ../reiser4/plugins/pseudo/pseudo.c
-Make a copy of one of the items in the pseudo_plugins array that is located in ../reiser4/plugins/pseudo/pseudo.c
-Rename it and modify its .single_show member to point to your custom function.
-Implement your scheme for updating the value... probably start by looking at inode_ops.c:invoke_create_method() or dir.c:create_child_common()

I don't know how useful it'd be, I think it'd be great for getting you familiar with the code base. It'd add a bit of overhead that's not really that necessary, don't you think? Unless somebody really needs to know disk usage *really* often. What's the case for doing this in kernel space instead of just using the du utility?

Feel free to ask us further questions, we look forward to seeing how you do.

-Ryan Nordman
Victoria, BC, Canada

Quoted 55 lines · Peter van Hardenberg

Danny,

It's good to hear from you. The Reiser4 plugin system is somewhat subtle. Over
the past four months our group has attempted to become the first group outside Namesys to create a Reiser4 plugin. We have had some various successes and failures and are hoping to document much of the experience for
general consumption.

-pvh

Quoted 31 lines · dannym

Hi,

So I want to start writing a small plugin to get a feel for the architecture...

I wonder how to do that?

I read that in order to write plugins, one has to recompile the kernel... which is ok, but that also means that it will affect everything and when I make a mistake, everything goes bad :)

So I wondered if all you reiser4 developers have some kind of sandbox thing that just does the same with a library (without the kernel) and on an image file?

Or do you use a virtual machine for that kind of stuff?

As for what I thought would be a nice intro thing for me to write is:

Adds a pseudo file "tree-contents-size" for directories. Pseudo file contains the "du" starting from this directory.

What it should do is cache some kind of "du"-like value per directory. When you change a file size (or delete a file, add a file, ...) in the dir or one of it's subdirs, it shall set a dirty flag on the value. When the pseudo file is accessed, it shall calculate it anew, also updating the subdirs' pseudo files if so needed, and store it actually on disk...
(could also be updated periodically without anyone requesting it, but that's just a detail)

Quoted 5 lines

What do you think? Useful? Bad Thing? Already done? Too hard for a first try?

cheers,
Danny

--
Peter van Hardenberg ( [email protected])
Victoria, BC, Canada

#3 lore raw
Quoted 5 lines · Ryan Nordman

I don't know how useful it'd be, I think it'd be great for getting you familiar with the code base. It'd add a bit of overhead that's not really that necessary, don't you think? Unless somebody really needs to know disk usage *really* often. What's the case for doing this in kernel space instead of just using the du utility?

Well, my first instinctive thought is that it might help thwart or postpone any potential persons thinking of switching to OpenSolaris+ZFS because of the so-called 'pooled storage' thinking. (ZFS has the ability to have multiple filesystems, even nested within each other, all sharing space from the same partition(s), and uses 'df' as opposed to du to find disk space, apparently df is 'cheaper' in terms of time used. Apparently, with ZFS, you can do a 'df' and suddenly know how much space is used and free in any one folder provided it's a seperate filesystem of it's own. A bit of an ... unusual abstraction to do things, but...)

If done *correctly* in the kernel, I imagine it should be faster - du does what would be the equivilant of listing all the files in the directory and summing all the file sizes it gets (du -s) -- and it is affected by the user's permissions (if I have a directory in the directory i'm du-ing that I can't read, du will fail to account for the files within that directory).

Last thing would be (hopefully) an ability to turn this thing on and off, and maybe to display the size of a folder's contents rather than the size of the directory's metadata in various utilities (if I 'ls -d' a directory, I usually get something like 2048B or 4096B depending on the number of files in there, although IIRC some big folders 'grow' to 16 KB, containing who knows what inside).

Quoted 10 lines
Quoted 10 lines · dannym
Quoted 9 lines

Hi,

So I want to start writing a small plugin to get a feel for the architecture...
As for what I thought would be a nice intro thing for me to write is:

Adds a pseudo file "tree-contents-size" for directories. Pseudo file contains the "du" starting from this directory.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

What it should do is cache some kind of "du"-like value per directory. When you change a file size (or delete a file, add a file, ...) in the dir or one of it's subdirs, it shall set a dirty flag on the value. When the pseudo file is accessed, it shall calculate it anew, also updating the subdirs' pseudo files if so needed, and store it actually on disk...
(could also be updated periodically without anyone requesting it, but that's just a detail)

--
~Mike
- Just the crazy copy cat.

#4 lore raw
Quoted 7 lines · michael chang
Quoted 5 lines · Ryan Nordman

I don't know how useful it'd be, I think it'd be great for getting you familiar with the code base. It'd add a bit of overhead that's not really that necessary, don't you think? Unless somebody really needs to know disk usage *really* often. What's the case for doing this in kernel space instead of just using the du utility?

Quoted 10 lines

Well, my first instinctive thought is that it might help thwart or postpone any potential persons thinking of switching to OpenSolaris+ZFS because of the so-called 'pooled storage' thinking. (ZFS has the ability to have multiple filesystems, even nested within each other, all sharing space from the same partition(s), and uses 'df' as opposed to du to find disk space, apparently df is 'cheaper' in terms of time used. Apparently, with ZFS, you can do a 'df' and suddenly know how much space is used and free in any one folder provided it's a seperate filesystem of it's own. A bit of an ... unusual abstraction to do things, but...)

Being able to use "df" or "zfs list" instead of "du" is a side effect. The real reason for the "unusual abstraction" is to have finer grained control over quotas, reservations, snapshots, checksums, compression, NFS sharing, etc.

Quoted 36 lines

If done *correctly* in the kernel, I imagine it should be faster - du does what would be the equivilant of listing all the files in the directory and summing all the file sizes it gets (du -s) -- and it is affected by the user's permissions (if I have a directory in the directory i'm du-ing that I can't read, du will fail to account for the files within that directory).

Last thing would be (hopefully) an ability to turn this thing on and off, and maybe to display the size of a folder's contents rather than the size of the directory's metadata in various utilities (if I 'ls -d' a directory, I usually get something like 2048B or 4096B depending on the number of files in there, although IIRC some big folders 'grow' to 16 KB, containing who knows what inside).

Quoted 10 lines
Quoted 10 lines · dannym
Quoted 9 lines

Hi,

So I want to start writing a small plugin to get a feel for the architecture...
As for what I thought would be a nice intro thing for me to write is:

Adds a pseudo file "tree-contents-size" for directories. Pseudo file contains the "du" starting from this directory.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

What it should do is cache some kind of "du"-like value per directory. When you change a file size (or delete a file, add a file, ...) in the dir or one of it's subdirs, it shall set a dirty flag on the value. When the pseudo file is accessed, it shall calculate it anew, also updating the subdirs' pseudo files if so needed, and store it actually on disk...
(could also be updated periodically without anyone requesting it, but that's just a detail)

--
~Mike
- Just the crazy copy cat.

Signature · 1 line
Jake Maciejewski <[email protected]>
#5 lore raw
Quoted 5 lines · Jake Maciejewski

Being able to use "df" or "zfs list" instead of "du" is a side effect. The real reason for the "unusual abstraction" is to have finer grained control over quotas, reservations, snapshots, checksums, compression, NFS sharing, etc.

It seems to me that although it could be very valuable in certain situations, for general purpose consumption the performance hit would be too painful. If the data isn't kept up-to-date, it's not a lot better than not having it. You would always have to check if a deep child-directory is out of date before giving quota permission, which means still paying for those disk reads anyway. On the other hand, if the information is always kept correct, you're paying for a lot more writes and reads every time you touch a file...

Also, the speed benefits for moving this in-kernel are not significant. The kernel also needs to essentially do a "du -s" -- the information is kept in the same place and has to be calculated the same way, which is by opening each file's inode and reading the file-size field.

I wonder how Reiser4 would fare performance-wise on that kind of operation. The tree-based nature of the storage makes lookup() very fast, but I have noticed that the "seekable hashed dir" is described in the comments as a hack to work around the fact that real directories aren't actually seekable. This is why B-tree indexed databases maintain leafs in strict increasing order, which can cost a TON to maintain under certain kinds of load.

-pvh

Signature · 2 lines
Peter van Hardenberg ([email protected])
Victoria, BC, Canada