5

Hello I am a newbie to kernel programming. I am writing a small kernel module that is based on wrapfs template to implement a backup mechanism. This is purely for learning basis.

I am extending wrapfs so that when a write call is made wrapfs transparently makes a copy of that file in a separate directory and then write is performed on the file. But I don't want that I create a copy for every write call.

A naive approach could be I check for existence of file in that directory. But I think for each call checking this could be a severe penalty.

I could also check for first write call and then store a value for that specific file using private_data attribute. But that would not be stored on disk. So I would need to check that again.

I was also thinking of making use of modification time. I could save a modification time. If the older modification time is before that time then only a copy is created otherwise I won't do anything. I tried to use inode.i_mtime for this but it was the modified time even before write was called, also applications can modify that time.

So I was thinking of storing some value in inode on disk that indicates its backup has been created or not. Is that possible? Any other suggestions or approaches are welcome.

sehe
  • 374,641
  • 47
  • 450
  • 633
gaurav
  • 872
  • 2
  • 10
  • 25

2 Answers2

0

You are essentially saying you want to do a Copy-On-Write virtual filesystem layer.

IMO, some of these have been done, and it would be easier to implement these in userland (using libfuse and the fuse module, e.g.). That way, you can be king of your castle and add your metadata in any which way you feel is appriate:

  • just add (hidden) metadata files to each directory
  • use extended POSIX attributes (setfattr and friends)
  • heck, you could even use a sqlite database

If you really insist on doing these things in-kernel, you'll have a lot more work since accessing the metadata from kernel mode is goind to take a lot more effort (you'd most likely want to emulate your own database using memory mapped files so as to minimize the amount of 'userland (style)' work required and to make it relatively easy to get atomicity and reliability right1.


1 On How Everybody Gets File IO Wrong: see also here

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thanks for your reply. I would take a look at using fuse. But actually I have started out with using wrapfs. I have changed unlink code to call rename instead of unlink so If something I could do like manipulating any struct inode attribute to suit my needs – gaurav Mar 05 '12 at 16:06
0

You can use atime instead of mtime. In that case setting S_NOATIME flag on the inode prevents it from updating (see touch_atime() function at the inode.c). The only thing you'll need is to mount your filesystem with noatime option.

Ilya Matveychikov
  • 3,936
  • 2
  • 27
  • 42
  • @liya :Why couldn't I use mtime ? But the problem with using atime is that it will be modified if file is read so that would be a problem with this approach. – gaurav Mar 06 '12 at 13:58
  • @gaurav: With `noatime` mount option there is no `atime` update on access. – Ilya Matveychikov Mar 06 '12 at 14:22
  • Ohh I see Good option I see, But I don't see why atime works and mtime doesn't. Also would atime of lower FS also won't change ? – gaurav Mar 06 '12 at 14:33