操作系统–实现文件系统(下)
n Log structured file systems record each update to the
记录结构化文件系统记录对
file system as a transaction
文件系统作为事务
n All transactions are written to a log
所有交易都被写入日志
A transaction is considered committed once it is
事务一旦提交,就被视为已提交
written to the log
写入日志
l However, the file system may not yet be updated
然而,文件系统可能尚未更新
n The transactions in the log are asynchronously written
日志中的交易是异步写入的
to the file system
到文件系统
When the file system is modified, the transaction is removed from the log
当文件系统被修改时,事务将从日志中删除
n If the file system crashes, all remaining transactions in
如果文件系统崩溃,所有剩余的事务都将
the log must still be performed
日志仍然必须被执行
The Sun Network File System (NFS)
太阳网络文件系统(NFS)
n An implementation and a specification of a
的实施和规范
software system for accessing remote files
用于访问远程文件的软件系统
across LANs (or WANs)
跨局域网(或广域网)
n The implementation is part of the Solaris and
实施是Solaris的一部分,并且
SunOS operating systems running on Sun
运行在Sun上的SunOS操作系统
workstations using an unreliable datagram
使用不可靠数据报的工作站
protocol (UDP/IP protocol and Ethernet)
协议(UDP/IP协议和以太网)
n Interconnected workstations viewed as a set of
互联工作站被视为一套
independent machines with independent file
具有独立文件的独立机器
systems, which allows sharing among these file
系统,允许在这些文件之间共享
systems in a transparent manner
透明的系统
NFS (Cont.)
NFS(续)。)
l A remote directory is mounted over a local file system
远程目录安装在本地文件系统上
directory
目录
4 The mounted directory looks like an integral subtree
4:挂载的目录看起来像一个完整的子树
of the local file system, replacing the subtree descending from the local directory
替换从本地目录往下的子树
l Specification of the remote directory for the mount
挂载的远程目录规格
operation is nontransparent;the host name of the
操作不透明;的主机名
remote directory has to be provided
必须提供远程目录
Files in the remote directory can then be accessed in
然后可以在中访问远程目录中的文件
4
4
a transparent manner
透明的方式
l Subject to accessrights accreditation, potentially any file
根据访问权限认证,可能是任何文件
system (or directory within a file system), can be
系统(或文件系统中的目录)可以是
mounted remotely on top of any local directory
远程安装在任何本地目录的顶部
NFS (Cont.)
NFS(续)。)
n The effect of mounting S1:/user/shared over U:/user/local
安装S1:/用户/共享超过U:/用户/本地的效果
n The machine U can access any file within the dir1 directory
机器可以访问目录中的任何文件
using prefix /usr/local/dir1.
使用前缀/usr/local/dir1。
n The original /usr/local on that machine is no longer visible.
该机器上的原始/usr/local不再可见。
NFS (Cont.)
NFS(续)。)
n User mobility
用户移动性
n If a shared file system is mounted over a user’s
如果共享文件系统安装在用户的
home directories on all machines in a network,
网络中所有机器上的主目录,
the user can log into any workstation and get
用户可以登录任何工作站并获得
his home environment.
他的家庭环境。
NFS (Cont.)
NFS(续)。)
n One of the design goals of NFS was to operate in a
NFS的设计目标之一是在一个
heterogeneous environment of different
不同的异质环境
machines, operating systems, and network
机器、操作系统和网络
architectures;
建筑;
n the NFS specifications independent of these media
独立于这些媒体的NFS规范
n This independence is achieved through the use of
这种独立性是通过使用
RPC primitives built on top of an External Data
建立在外部数据之上的RPC原语
Representation (XDR) protocol used between two
两者之间使用的表示(XDR)协议
implementationindependent interfaces
独立于实现的接口
NFS (Cont.)
NFS(续)。)
n The NFS specification distinguishes between the
NFS规范区分了
services provided by a mount mechanism and the
由挂载机制和
actual remotefileaccess services.
实际的remotefileaccess服务。
n Accordingly, two separate protocols are specified
因此,规定了两个独立的协议
for these services:
对于这些服务:
l a mount protocol and
安装协议和
l an NFS protocol for remote file accesses.
远程文件访问的NFS协议。
n The protocols are specified as sets of RPCs.
协议被指定为一组RPC。
l These RPCs are the building blocks used to
这些遥控门锁接收器是用来
implement transparent remote file access.
实现透明的远程文件访问。
NFS Mount Protocol
NFS山议定书
n The mount protocol establishes initial logical connection
安装协议建立初始逻辑连接
between a server and a client.
在服务器和客户端之间。
n A mount operation includes
安装操作包括
l name of remote directory to be mounted and
要安装的远程目录的名称
name of server machine storing it
存储它的服务器的名称
n Mount request is mapped to corresponding RPC and forwarded to mount server running on server machine
装载请求被映射到相应的远程过程控制,并被转发到运行在服务器上的装载服务器
n The server maintains an export list specifies local file
服务器维护一个指定本地文件的导出列表
systems that server exports for mounting, along with
服务器导出用于装载的系统,以及
names of machines that are permitted to mount them
允许安装它们的机器的名称
NFS Mount Protocol
NFS山议定书
n In Solaris, this list is the /etc/dfs/dfstab, which can be
在Solaris中,该列表是/etc/dfs/dfstab,可以是
edited only by a supervisor.
仅由主管编辑。
n Any directory within an exported file system can be
导出文件系统中的任何目录都可以
mounted by an accredited machine.
由认可的机器安装。
n A component unit is such a directory.
组件单元就是这样一个目录。
n Following a mount request that conforms to its export
遵循符合其出口的装载请求
list, the server returns a file handle — a key for further
列表中,服务器返回一个文件句柄——进一步
accesses
访问
n In UNIX terms, the file handle consists of a filesystem
用UNIX术语来说,文件句柄由一个文件系统组成
identifier, and an inode number to identify the mounted directory within the exported file system
标识符和索引节点号,用于标识导出的文件系统中的装载目录
n The mount operation changes only the user’s view and
装载操作仅改变用户的视图
does not affect the server side
不影响服务器端
NFS Protocol
NFS议定书
n The NFS protocol provides a set of RPCs for remote file operations.
NFS协议为远程文件操作提供了一套远程过程控制。
n The procedures support the following operations:
这些程序支持以下操作:
l searching for a file within a directory
在目录中搜索文件
l reading a set of directory entries
阅读一组目录条目
l manipulating links and directories
操纵链接和目录
l accessing file attributes
访问文件属性
l reading and writing files
读写文件
n These procedures can be invoked only after a file
这些程序只能在文件之后调用
handle for the remotely mounted directory has
远程装载目录的句柄有
been established.
已经建立。
NFS Protocol
NFS议定书
n NFS servers are stateless;Servers do not maintain
NFS服务器是无状态的;服务器不维护
information about their clients from one access to another.
从一个访问到另一个访问的客户信息。
Each request has to provide a full set of arguments.
每个请求都必须提供一组完整的参数。
n Every NFS request has a sequence number, allowing the
每个NFS请求都有一个序列号,允许
server to determine if a request is duplicated or missed.
服务器确定请求是否重复或丢失。
n Modified data must be committed to the server’s disk
修改后的数据必须提交到服务器磁盘
before results are returned to the client (lose advantages of
在结果返回给客户之前(失去优势
caching)
缓存)
n The NFS protocol does not provide concurrencycontrol
《NFS议定书》没有提供同时控制
mechanisms
机制
Schematic View of NFS Architecture
NFS建筑示意图
Three Major Layers of NFS Architecture
NFS建筑的三大层
n UNIX filesystem interface (based on the open, read, write,
UNIX文件系统界面(基于打开、读取、写入、
and close calls, and file descriptors)
和关闭调用以及文件描述符)
n Virtual File System (VFS) layer distinguishes local files from remote ones, and local files are further distinguished
虚拟文件系统(VFS)层区分本地文件和远程文件,并进一步区分本地文件
according to their filesystem types
根据它们的文件系统类型
l The VFS activates filesystemspecific operations to
VFS激活文件系统特定操作,以
handle local requests according to their filesystem
根据文件系统处理本地请求
types
类型
l Calls the NFS protocol procedures for remote requests
为远程请求调用NFS协议程序
n NFS service layer bottom layer of the architecture
架构的NFS服务层底层
l Implements the NFS protocol
执行《NFS议定书》
An illustration of NFS Architecture
NFS建筑图解
n NFS is integrated into the OS via a VFS.
NFS通过VFS集成到操作系统中。
n Let’s trace how the operation on an already open remote file
让我们追踪对已经打开的远程文件的操作
is handled.
被处理。
n The client initiates the operation with a regular system call.
客户通过常规系统调用启动操作。
n The OS layer maps this call to a VFS operation on the
操作系统层将该调用映射到上的VFS操作
appropriate vnode.
适当的vnode。
n The VFS layer identifies the file as a remote one and invokes
VFS层将文件识别为远程文件,并调用
the appropriate NFS procedure.
适当的NFS程序。
n An RPC call is made to the NFS service layer at the remote
向远程的NFS服务层发出远程过程控制呼叫
server.This call is reinjected to the VFS layer on the remote
服务器。该呼叫被重新注入到远程的VFS层
system, which finds that it is local and invokes the
系统,它发现它是本地的,并调用
appropriate file system operation.
适当的文件系统操作。
n This path is retraced to return the results.
这条路径被重走以返回结果。
Schematic View of NFS Architecture
NFS建筑示意图
NFS PathName Translation
NFS路径名翻译
n Pathname translation in NFS involves the parsing of a
NFS的路径名翻译包括解析
path name such as /usr/local/dir1/file.txt into separate
路径名,如/usr/local/dir1/file.txt
directory entries, or components: (1) usr, (2) local, and (3)
目录条目或组件:(1) usr,(2) local,和(3)
dir1.
dir1。
n Performed by breaking the path into component names and performing a separate NFS lookup call for every pair
通过将路径分解成组件名称,并对每对组件执行单独的NFS查找调用来执行
of component name and directory vnode.
组件名和目录vnode。
n Once a mount point is crossed, every component lookup
一旦跨越安装点,每个组件都会查找
causes a separate RPC to the server.
导致对服务器进行单独的RPC。
n To make lookup faster, a directory name lookup cache on the client’s side holds the vnodes for remote directory
为了加快查找速度,客户端的目录名称查找缓存保存了远程目录的虚拟节点
names
名称
NFS Remote Operations
NFS远程操作
n Nearly onetoone correspondence between
之间几乎是一对一的对应关系
regular UNIX system calls for file operations and
文件操作的常规UNIX系统调用
the NFS protocol RPCs (except opening and
《NFS议定书》的区域筹备委员会(除开幕和
closing files).
关闭文件)。
n A remote file operation can be translated directly
远程文件操作可以直接翻译
to the corresponding RPC.
到相应的RPC。
n NFS adheres to the remoteservice paradigm, but
NFS坚持远程服务模式,但是
employs buffering and caching techniques for
使用缓冲和缓存技术
the sake of performance.
为了表演。
n There are two caches: the fileattribute cache and
有两个缓存:文件属性缓存和
the fileblocks cache.
文件块缓存。
NFS Remote Operations
NFS远程操作
n When a file is opened, the kernel checks with the remote
打开文件时,内核会用遥控器进行检查
server whether to fetch or revalidate the cached attributes.
服务器是否获取或重新验证缓存的属性。
n The cached file blocks are used only if the corresponding
只有当相应的
cached attributes are up to date.
缓存的属性是最新的。
n The attribute cache is updated whenever new attributes
每当新属性出现时,属性缓存就会更新
arrive from the server.
从服务器到达。
n Cached attributes are discarded after 60 seconds.
60秒后,缓存的属性将被丢弃。
n Both readahead and delayedwrite techniques are used
预读和延迟写技术都被使用
between the server and the client.
在服务器和客户端之间。
n Clients do not free delayedwrite blocks until the server
客户端不会释放延迟写块,直到服务器
confirms that the data have been written to disk.
确认数据已写入磁盘。
Example: WAFL File System
n Disk I/O has a huge impact on system performance.
磁盘输入/输出对系统性能有巨大影响。
n Some file systems are general purpose, others are optimized for specific tasks,
有些文件系统是通用的,有些是针对特定任务优化的,
n The WAFL (“Writeanywhere file layout”) file system from Network Appliance, is a powerful file system optimized for random writes.
网络设备的WAFL(“写随处”文件布局)文件系统是一个针对随机写入进行优化的强大文件系统。
Used on Network Appliance “Files”
用于网络设备“文件”
- distributed file
-分布式文件
n
n
system appliances
系统设备
n Serves up NFS, CIFS, http, ftp protocols
提供NFS、CIFS、http、ftp协议
n Random I/O optimized, write optimized
随机输入/输出优化,写入优化
Example: WAFL File System
示例:WAFL文件系统
n Similar to Berkeley Fast File System, with extensive
类似于伯克利快速文件系统,具有广泛的
modifications.
修改。
n It is blockbased and uses inodes to describe files.Each
它是基于块的,使用索引节点来描述文件。每
inode contains 16 pointers to blocks (or indirect blocks) belonging to the file described by the inode.
inode包含16个指针,指向属于inode描述的文件的块(或间接块)。
The WAFL File Layout
WAFL文件布局
Example: WAFL File System
示例:WAFL文件系统
n Each file system has a root inode.
每个文件系统都有一个根信息节点。
n A WAFL file system is a tree of blocks with the root inode
WAFL文件系统是包含根信息节点的数据块树
as its base.
作为它的基础。
n To take a snapshot, WAFL creates a copy of the root inode.
为了拍摄快照,WAFL创建了根信息节点的副本。
n Any file or metadata updates after that go to new blocks rather than overwriting their existing blocks.
此后,任何文件或元数据更新都会转到新的块,而不是覆盖现有的块。
n Used blocks are never overwritten, so writes are very fast, because a write can occur at the free block nearest the
用过的数据块永远不会被覆盖,因此写入速度非常快,因为写入可以发生在距离最近的空闲数据块上
current head location.
当前磁头位置。
n The snapshot facility is also useful for backups, testing, versioning, and so on.
快照功能对于备份、测试、版本控制等也很有用。
Snapshots in WAFL
WAFL的快照
A write can occur
可以发生写入