1 / 35

FILE SYSTEM FRAMEWORK —— virtual file system framework

FILE SYSTEM FRAMEWORK —— virtual file system framework. Outline. Solaris File System Framework The vnode The vfs Object. Solaris FILE SYSTEM FRAMEWORK. Solaris virtual file system framework the virtual file system framework implementes multiple file system types.

Download Presentation

FILE SYSTEM FRAMEWORK —— virtual file system framework

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FILE SYSTEM FRAMEWORK—— virtual file system framework

  2. Outline • Solaris File System Framework • The vnode • The vfs Object

  3. SolarisFILE SYSTEM FRAMEWORK • Solaris virtual file system framework • the virtual file system framework implementes multiple file system types. • It allows Sun’s distributed computing file system (NFS) to coexist with the UFS file system in SunOS 2.0 • Solaris file systems can be categorized into the following types: • Storage based — Regular file systems . The Solaris UFS and PC/DOS file systems are examples. • Network file systems—for example, NFS • Pseudo file systems —The /proc pseudo file systemis example.

  4. Unified File System Interface • The framework provides a single set of well-defined interfaces . • Two key objects represent these interfaces: • the virtual file, or vnode: The vnode interfaces implement file-related functions. • the virtual file system, or vfs objects:the vfs interfaces implement file system management functions.

  5. the file system layers is shown below T O P E N D B O T T O M E N D Figure 13.1 shows the file system layers.

  6. File System Framework Facilities • The vnode/vfs interfaces • The “top end” of the file system module implement vnode and vfs objects. • The “bottom end” of the file system uses other kernel interfaces to access, store, and cache the data they represent. • Disk-based file systems interface to device drivers to provide persistent storage of their data. • they interface to network file systems access the networking subsystem to transmit and receive data to remote systems. • Pseudo file systems typically access local kernel functions and structures to gather the information they represent.

  7. File System Framework Facilities

  8. File System Framework Facilities • Loadable file system modules are dynamically loaded at the time each file system type is first mounted. • The vnode/vfs framework implementes file functions and file system management functions. • File system caching implements caching interface with the HAT layer of the virtual memory system to map, unmap, and manage the memory used for caching. • Path-name managementconverts paths into vnode pointers. • Directory name cachingprovides a mechanism to cache pathname-to-vnode mappings.

  9. The vnode • A vnode is a representation of a file in the Solaris kernel. • The vnode is said to be objectlike . • it is an encapsulation of a file’s state and the methods that can be used to perform operations on that file. • The vnode hides the implementation of the file system and exposes file system-independent data and methods for that file to the rest of the kernel.

  10. A vnode object Figure 13.2A vnode object

  11. A vnode object contains three important items • File-system-independent data • the type of vnode :file, directory, character device, Block device, Hard link,Named pipe, etc. • flags of vnode : state, pointers to the file system that contains the vnode, a reference count to the vnode. • Functions to implement file methods • A structure of pointers to file-system-dependent functions, to implement file’s open(),close(), read(), and write(). • File-system-specific data • Data that is used internally by each file system implementation; typically the in-memory inode . UFS uses an inode, NFS uses an rnode,and tmpfs uses a tmpnode.

  12. A vnode object • For example, to read from a file without knowing that it resides on a UFS file system, the kernel would simply call the file-system-independent macro for read(), VOP_READ(), which would call the vop_read() method of the vnode, which in turn calls the UFS function, ufs_read().

  13. The data structure of a vnode • typedef struct vnode { • kmutex_t v_lock; /* protects vnode fields */ushort_t v_flag; /* vnode flags (see below) */uint_t v_count; /* reference count */struct vfs *v_vfsmountedhere; /* ptr to vfs mounted here */struct vnodeops *v_op; /* vnode operations */struct vfs *v_vfsp; /* ptr to containing VFS */struct stdata *v_stream; /* associated stream */struct page *v_pages; /* vnode pages list */enum vtype v_type; /* vnode type */dev_t v_rdev; /* device (VCHR, VBLK) */caddr_t v_data; /* private data for fs */struct filock *v_filocks; /* ptr to filock list */struct shrlocklist *v_shrlocks; /* ptr to shrlock list */kcondvar_t v_cv; /* synchronize locking */} vnode_t;

  14. Vnode Methods • The vnode interfaceprovides the set of file system object methods • The Vnode Methods perform all file-system-specific file operations. • The figure is shown below.

  15. Vnode Methods

  16. vnode Reference Count • A vnode is created by the file system at the time a file is first opened or created and stays active until the file system decides the vnode is no longer needed. • The vnode framework provides an infrastructure that keeps track of the number of references to a vnode. • It is important to distinquish a vnode reference from a lock: • A lock ensures exclusive access to the data, • the reference count ensures persistence of the object.

  17. Interfaces for Paging vnode Cache • Solaris unifies file and memory management by using a vnode to represent the backing store for virtual memory. • A page of memory represents a particular vnode and offset. • The file system uses the memory relationship to implement caching for vnodes within a file system. • The virtual memory system provides a set of functions for cache management and I/O for vnodes.

  18. Block I/O on vnode Pages • The block I/O subsystem provides Three functions for initiating I/O to and from vnode pages. • The table shows to initiate I/O between a physical page and a device:

  19. The vfs Object • The vfs layer provides an administrative interface into the file system to support commands like mount and umount in a file-system-independent manner. • The interface achieves independence by means of a virtual file system (vfs) object. • The vfs object represents an encapsulation of a file system’s state and a set of methods for each of the file system administrative interfaces.

  20. Structure per mounted file system typedef struct vfs { struct vfs *vfs_next; /* next VFS in VFS list */ struct vfsops *vfs_op; /* operations on VFS */ struct vnode *vfs_vnodecovered; /* vnode mounted on */ uint_t vfs_flag; /* flags */ uint_t vfs_bsize; /* native block size */ int vfs_fstype; /* file system type index */ fsid_t vfs_fsid; /* file system id */ caddr_t vfs_data; /* private data */ dev_t vfs_dev; /* device of mounted VFS */ ulong_t vfs_bcount; /* I/O count (accounting) */ ushort_t vfs_nsubmounts; /* immediate sub-mount count */ struct vfs *vfs_list; /* sync list pointer */ struct vfs *vfs_hash; /* hash list pointer */ ksema_t vfs_reflock; } /* mount/unmount/sync lock */

  21. Operations supported on virtual file system • typedef struct vfsops { • int (*vfs_mount)(struct vfs *, struct vnode *, struct mounta *, • struct cred *); • int (*vfs_unmount)(struct vfs *, struct cred *); • int (*vfs_root)(struct vfs *, struct vnode **); • int (*vfs_statvfs)(struct vfs *, struct statvfs64 *); • int (*vfs_sync)(struct vfs *, short, struct cred *); • int (*vfs_vget)(struct vfs *, struct vnode **, struct fid *); • int (*vfs_mountroot)(struct vfs *, enum whymountroot); • int (*vfs_swapvp)(struct vfs *, struct vnode **, char *); • }

  22. 启动时UFS的挂载分析 • 在Solaris的整个文件系统体系结构中,所有对于具体文件系统的操作都是通过VFS来进行抽象的。为了分析UFS中的操作,就必须找到VFS与UFS的结合部 。

  23. 挂载相关函数 • 在挂载UFS时,用到的最重要的两个函数是vfs_mountroot()和rootconf()。其中vfs_mountroot()的函数原型定义在src\uts\common\fs\vfs.c中

  24. void vfs_mountroot(void); • 函数功能:挂载根文件系统 • 函数参数:无 • 函数返回值:无 • rootconf()函数的原型也定义在src\uts\common\fs\vfs.c中: • int rootconf(); • 函数功能:选取一种文件系统,作为vfs的根文件系统 • 函数参数:无 • 函数返回值:返回错误号

  25. 挂载过程分析 • 在系统启动时,uts\common\os的main.c中调用了vfs_mountroot函数,这个函数的作用就是挂载根文件系统。

  26. vfs_mountroot • if (rootconf()) • cmn_err(CE_PANIC, "vfs_mountroot: cannot mount root"); • /* • * Get vnode for '/'. Set up rootdir, u.u_rdir and u.u_cdir • * to point to it. These are used by lookuppn() so that it • * knows where to start from ('/' or '.'). • */ • vfs_setmntpoint(rootvfs, "/"); • if (VFS_ROOT(rootvfs, &rootdir)) • cmn_err(CE_PANIC, "vfs_mountroot: no root vnode"); • u.u_cdir = rootdir; • VN_HOLD(u.u_cdir); • u.u_rdir = NULL;

  27. rootconf函数选取了一种文件系统,作为vfs的根文件系统。

  28. rootconf • 调用getrootfs();它判断启动的是否是一个无disk的客户端,如果不是,就返回”ufs”; • 调用modload(”fs”, fstype);它完成ufs模块的装载,其中的参数fstype就是上面getrootfs返回的”ufs”; • 调用vsw = vfs_getvfsswbyname(fstyp);

  29. VSW • struct vfssw { • char *vsw_name; /* type name -- max len _ST_FSTYPSZ */ • int (*vsw_init) (int, char *); • /* init routine (for non-loadable fs only) */ • int vsw_flag; /* flags */ • mntopts_t vsw_optproto; /* mount options table prototype */ • uint_t vsw_count; /* count of references */ • kmutex_t vsw_lock; /* lock to protect vsw_count */ • vfsops_t vsw_vfsops; /* filesystem operations vector */ • }

  30. vsw_vfsops包含了一系列对文件系统的基本操作,是一个由函数指针构成的结构体。vfs_getvfsswbyname(fstyp)函数根据传进来的文件系统的类型名字(这里就是fstype==”ufs”),来找到该类型文件系统的vsw结构体。其实在vfsconf.c中定义了一个表struct vfssw vfssw[],里面的每一项都是对于一种文件系统的描述(用vfssw结构)。vfs_getvfsswbyname(fstyp)函数就是根据fstype来查找对应的vfssw结构,并返回其指针给vsw。

  31. 调用VFS_INIT(rootvfs, &vsw->vsw_vfsops, 0);这个宏完成的工作是将rootvfs这个vfs结构体中的相关函数指针与vsw->vsw_vfsops相关联。 • 调用error = VFS_MOUNTROOT(rootvfs, ROOT_INIT);这里VFS_MOUNTROOT宏只是调用了rootvfs中的mountroot函数,由于刚才已经完成了rootvfs同UFS的关联,所以这里也就是调用了ufs_mountroot。

  32. vfssw[] 0 1 2 3 4 5 6 7 …. struct vfssw struct vfssw struct vfssw vsw_name: proc vsw_name: nfs vsw_name: ufs vsw_vfsops vsw_vfsops vsw_vfsops struct vfsops struct vfsops struct vfsops vfs_mount vfs_mount vfs_mount vfs_umount vfs_umount vfs_umount …. …. …. struct vfs struct vfs struct vfs vfs_op vfs_op vfs_op vfs_next vfs_next vfs_next vfs_prev vfs_prev vfs_prev vfs_fstype: proc vfs_fstype: nfs vfs_fstype: ufs vfs_vnodecovered vfs_vnodecovered vfs_vnodecovered …. …. …. struct vnode struct vnode struct vnode v_vfsmountedhere v_vfsmountedhere v_vfsmountedhere …. …. ….

More Related