全部博文(48)
分类: LINUX
2013-01-06 12:05:11
It has been 3 months for me after grduated from DLNU. Recently, I came to 帝都Beijing for hunting a KERNEL relating job. Leaking of projects experences makes me unconfiendt. I made a determine that devote all my energies to submit a kernel patch. I read linux kernel bugzilla all day and nighty. I find an appropriate one. Knowing nothing about Btrfs, I begin to collect the infor maion about Btrfs and read the source code of Btrfs.
Btrfs at Wikipedia.
Initialization
-->init_btrfs_fs()
In this function kernel initlize Btrfs and use register_filesystem to inject Btrfs into kernel witn a paramater btrfs_fs_type:
static struct file_system_type btrfs_fs_type = {
.owner = THIS_MODULE,
.name = "btrfs",
.mount = btrfs_mount,
.kill_sb = btrfs_kill_super,
.fs_flags = FS_REQUIRES_DEV,
};
The mount member of btrfs_fs_type btrfs_mount() is a critical function!
Mount
When we use mount command on shell, it directs kernel to call btrfs_mount() function mentioned above. If you trace the procedures will can find it happens in mount_fs().
-->btrfs_mount()
-->sget():find or create a superblock
-->btrfs_fill_super()
-->btrfs_iget()
-->btrfs_read_locked_inode()
-->inode->i_mapping->a_ops = &btrfs_aops;
-->inode->i_fop = &btrfs_file_operations;
-->inode->i_op = &btrfs_file_inode_operations;
Here is the defination of btrfs_file_operations is all the operations that a file will use:
const struct file_operations btrfs_file_operations = {
.llseek = btrfs_file_llseek,
.read = do_sync_read,
.write = do_sync_write,
.aio_read = generic_file_aio_read,
.splice_read = generic_file_splice_read,
.aio_write = btrfs_file_aio_write,
.mmap = btrfs_file_mmap,
.open = generic_file_open,
.release = btrfs_release_file,
.fsync = btrfs_sync_file,
.fallocate = btrfs_fallocate,
.unlocked_ioctl = btrfs_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = btrfs_ioctl,
#endif
};