发新话题
打印

Linux虚拟文件系统概述(3)

本帖已经被作者加入个人空间

Linux虚拟文件系统概述(3)

三、Superblock对象
一个Superblock对象代表了一个挂载的文件系统。
1、super_operations结构
该结构描述了VFS操作文件系统的方式。在2.6.20内核中,其在include/linux/fs.h定义如下:
struct super_operations {
    struct inode *(*alloc_inode)(struct super_block *sb);
void (*destroy_inode)(struct inode *);
void (*read_inode) (struct inode *);
  
    void (*dirty_inode) (struct inode *);
int (*write_inode) (struct inode *, int);
void (*put_inode) (struct inode *);
void (*drop_inode) (struct inode *);
void (*delete_inode) (struct inode *);
void (*put_super) (struct super_block *);
void (*write_super) (struct super_block *);
int (*sync_fs)(struct super_block *sb, int wait);
void (*write_super_lockfs) (struct super_block *);
void (*unlockfs) (struct super_block *);
int (*statfs) (struct dentry *, struct kstatfs *);
int (*remount_fs) (struct super_block *, int *, char *);
void (*clear_inode) (struct inode *);
void (*umount_begin) (struct vfsmount *, int);
int (*show_options)(struct seq_file *, struct vfsmount *);
int (*show_stats)(struct seq_file *, struct vfsmount *);
#ifdef CONFIG_QUOTA
ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
#endif
};
所有的方法调用时除非特别要求,不会持有任何锁。这意味着,这些方法可以安全的阻塞。这些发放必须在进程的上下文中调用。(不能通过中断句柄或者下半部bottom half调用——没有进程上下文)
alloc_inode: 该方法由inode_alloc调用,为inode结构分配空间和初始化。如果未定义该方法,将分配一个简单的inode结构。通常,alloc_inode被用来分配一个包含inode结构的大型数据结构。
destroy_inode: 该方法由destroy_inode调用,用以释放为inode结构分配的资源。它只在alloc_inode方法被定义时有效,简单的逆向执行(undo)alloc_inode中的处理。
read_inode: 该方法被用来从挂载的文件系统中读取一个特定的inode。VFS设置inode结构中的i_ino成员来指示被读取得inode。其它的成员由该方法设置。
dirty_inode: VFS调用该方法来标记一个脏inode节点。
write_inode: VFS调用该方法将inode结构协会磁盘。第二个参数标示使用同步写还是异步方式,不是所有的文件系统都检查该标记。
put_inode: 在VFS的inode从cache中移除时调用。。
drop_inode: 在最后一个对该inode节点的访问操作被放弃时调用,该操作持有inode_lock自旋锁。 该方法必须或为空(NULL,通常意义上的Unix文件系统语义),或为"generic_delete_inode"(为不需要缓存inode的文件系统,以使无论i_nlink为何值的情况下,都会调用"delete_inode")  "generic_delete_inode()"和曾经在put_inode()中使用的"force_delete"行为相似,但是不会存在"force_delete"方法的竞争。
delete_inode: VFS调用该方法删除一个inode节点。
put_super; VFS调用该方法释放一个superblock(如umount)。在持有superblock锁时调用
write_super: 载VFS superblock需要写入磁盘时调用,该方法为可选。
sync_fs: 在VFS写一个superblock相关的所有inode节点时调用。第二个参数指示是否等待所有的写操作完成后再执行。可选。
write_super_lockfs: 在VFS锁住一个文件系统时调用,并强制进入一致状态。该方法现在由逻辑卷管理器(LVM)使用。
unlockfs; VFS调用该方法释放文件系统的锁,使其重新可写。
statfs:  在VFS需要获得文件系统统计信息时调用。该方法调用需要获得内核锁。
remount_fs: 在文件系统重新挂载时调用。该方法调用需要获得内核锁。
clear_inode: 在VFS清除一个inode节点试调用。可选。
umount_begin; 在VFS卸载文件系统时调用。
//sync_inodes; VFS写superblock关联的脏数据时调用。 --2.6.20中取消
show_options: 在VFS显示/proc/<pid>/mounts的挂载参数时调用。
show_stats:
quota_read: VFS调用该方法读取文件系统的配额文件。
quota_write; VFS调用该方法写入文件系统的配额文件。
read_inode()方法负责填充i_op域,该域是一个指向inode_operations结构的指针,该结构描述了每个inodes的操作方法。
0/1

TOP

发新话题