<?xml-model href='http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng' schematypens='http://relaxng.org/ns/structure/1.0'?><TEI xmlns="http://www.tei-c.org/ns/1.0">
	<teiHeader>
		<fileDesc>
			<titleStmt><title level='a'>Model-Checking Support for File System Development</title></titleStmt>
			<publicationStmt>
				<publisher></publisher>
				<date>07/27/2021</date>
			</publicationStmt>
			<sourceDesc>
				<bibl> 
					<idno type="par_id">10347077</idno>
					<idno type="doi">10.1145/3465332.3470878</idno>
					<title level='j'>Proceedings of the USENIX Workshop on Hot Topics in Storage and File Systems</title>
<idno></idno>
<biblScope unit="volume"></biblScope>
<biblScope unit="issue"></biblScope>					

					<author>Wei Su</author><author>Yifei Liu</author><author>Gomathi Ganesan</author><author>Gerard Holzmann</author><author>Scott Smolka</author><author>Erez Zadok</author><author>Geoff Kuenning</author>
				</bibl>
			</sourceDesc>
		</fileDesc>
		<profileDesc>
			<abstract><ab><![CDATA[Developing and maintaining a file system is time-consuming, typically requiring years of effort.  Developers often test compliance with APIs such as POSIX with hand-written regression suites that, alas, examine only a fraction of a file system's state space.  Conversely, formal model checking can explore vast state spaces efficiently, increasing confidence in the file system's implementation.  Yet model checking is not currently part of file system development.  Our position is that file systems should be designed a priori to facilitate model checking.  To this end, we introduce MCFS, an architecture for efficient and comprehensive file-system model checking.  MCFS relies on two new APIs that save and restore a file system's in-memory and on-disk state.  We describe our earlier attempts at model-checking file systems, including unsuccessful or inefficient ones.  Those attempts led us to develop VeriFS, which implements the new APIs.  We illustrate MCFS's model-checking principles with VeriFS, a FUSE-based file system we were able to quickly develop with MCFS's help.]]></ab></abstract>
		</profileDesc>
	</teiHeader>
	<text><body xmlns="http://www.tei-c.org/ns/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1">INTRODUCTION</head><p>File system development is time-consuming, complex, and error-prone, requiring precise logic, standards compliance (e.g., POSIX), and careful implementation of data structures and concurrency <ref type="bibr">[14,</ref><ref type="bibr">24,</ref><ref type="bibr">49</ref>]. Yet even mature file systems suffer repeated bugs. For example, Btrfs <ref type="bibr">[36]</ref> was designed 14 years ago yet reported 110 bugs in 2020 <ref type="bibr">[21]</ref>. Such bugs can cause data corruption or loss and system crashes <ref type="bibr">[22,</ref><ref type="bibr">24,</ref><ref type="bibr">37]</ref>.</p><p>To help address this state of affairs, we present MCFS, a model-checking framework for file systems that: (1) checks every corner case in a bounded state space; (2) does not require an abstract file system model; (3) retains the original file system behavior; (4) applies to most file systems, whether in-kernel or user-space; and (5) has high performance.</p><p>MCFS compares file systems to each other with concurrent processes that non-deterministically issue file-system calls; it compares their outcomes (e.g., file content and return values) to find discrepancies. MCFS can exhaustively execute systemcall permutations and thus uncover abnormal behavior.</p><p>We implemented MCFS using the Spin model checker <ref type="bibr">[41]</ref> and applied it to a number of file systems. Our position is that thanks to its exhaustive state-space analysis capabilities, model checking should be an integral part of the file-system development process (alongside traditional hand-written regression suites <ref type="bibr">[27,</ref><ref type="bibr">39]</ref>). However, file systems need to facilitate model checking. We make the following contributions:</p><p>(1) We created MCFS to support file system checking that can exhaustively search bounded state spaces. <ref type="bibr">(2)</ref> We uncovered two inherent challenges to modelchecking: cache incoherency and I/O inefficiencies. Ultimately we designed state checkpoint/restore APIs to ease integrating file systems with model checkers. <ref type="bibr">(3)</ref> We developed (two versions of) a FUSE file system, VeriFS, that efficiently checkpoints and restores file-system states using our proposed APIs. (4) We empirically evaluated MCFS's performance. Our results suggest that MCFS is a viable approach: one can use it to find behavioral deviations and bugs while developing or maintaining a file system.</p><p>Related work. Bug-detection techniques for file systems can be grouped into regression testing, verification, model checking, and fuzzing. Regression suites (e.g., xfstests <ref type="bibr">[39]</ref> and ltp <ref type="bibr">[27]</ref>) are useful in development and maintenance, but test only known defects and are unlikely to cover all corner cases. Prior work has demonstrated the benefits of building a machine-verifiable file system from scratch <ref type="bibr">[2, 6&#347;9, 20, 40, 50]</ref>, but this approach does not apply to existing file systems. File-system model checkers have verified test cases <ref type="bibr">[3,</ref><ref type="bibr">28,</ref><ref type="bibr">47,</ref><ref type="bibr">48]</ref> and located corner-case bugs, but are strictly focused on crash consistency. Another approach is to build an abstract model and check whether a file system adheres to it <ref type="bibr">[13,</ref><ref type="bibr">23,</ref><ref type="bibr">26,</ref><ref type="bibr">34,</ref><ref type="bibr">35]</ref>. Constructing a formally verifiable model, however, requires considerable domain knowledge and human effort. It is also impractical to build formal models for large and intricate file systems. Worse, the formal model requires updating when the file system's code changes.</p><p>CMC [29&#347;31] inserts file system code directly into the model checker, for substantial speed advantages, but requires extensive changes to the very code being verified, making the results less trustworthy <ref type="bibr">[47]</ref>. Fuzzing can find real-world bugs <ref type="bibr">[12,</ref><ref type="bibr">22,</ref><ref type="bibr">38,</ref><ref type="bibr">45,</ref><ref type="bibr">46]</ref>, but either is limited to specific types of bugs (e.g., memory safety for Janus <ref type="bibr">[46]</ref>), or needs human effort to create checkers <ref type="bibr">[22]</ref>. Likewise, symbolic-execution tools <ref type="bibr">[4,</ref><ref type="bibr">5]</ref> cannot guarantee thorough coverage because they focus on particular issues (e.g., corrupt input <ref type="bibr">[5]</ref>); they also require a behavioral model of each file system call <ref type="bibr">[4]</ref>.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2">MCFS DESIGN</head><p>Model checking is an automatic method for verifying finite-state concurrent systems. It performs an exhaustive search of the state space to verify whether a system's model conforms to its specification. We exploit this efficient search technology to explore file system states exhaustively. The MCFS model-checking framework is designed to detect discrepant behaviors in file systems; i.e., situations where two file systems behave differently given the same inputs.</p><p>MCFS has five key design goals: (1) Thorough coverage: It should thoroughly explore the state spaces of the file systems we check, so that it can uncover as many corner cases as possible. This requires MCFS to check as many permutations of file system operations as possible, exploring all possible changes that the given set of operations can make. (2) Eliminate need for an abstract model: Traditional model checking requires one to define a model for the system under investigation. MCFS can verify file systems without a model because it directly executes system code to perform state-space exploration.</p><p>(3) Absence of observer effects: To ensure accuracy, MCFS should avoid changing the behavior of the investigated file system, ideally treating it as a black box. If we have to modify it, we must be careful to minimize MCFS's footprint. (4) Universality: The model-checking framework should support a wide range of file systems (e.g., in-kernel, user-level, networked, distributed). (5) High performance: Since a file system's state space is the product of many system calls and their parameters, the number of states can be exponential. The model checker must be able to enumerate new states as fast as possible, exploring large fractions of the state space within a reasonable amount of time.</p><p>MCFS's architecture has four main components: randomized test engines, optimized state-space exploration, integrity checks, and abstraction functions. Driven by the Spin model checker <ref type="bibr">[15]</ref>, randomized test engines nondeterministically issue operation sequences to each file system under consideration. Spin's efficient partial-order reduction algorithm <ref type="bibr">[19]</ref> allows MCFS to execute all permutations of the given set of calls and their parameters without duplication. Its randomized driver processes generate both valid and invalid call sequences. Valid sequences should succeed on all file systems, while invalid ones (e.g., write() before open()) should produce consistent error behavior. Invalid sequences are critical because they exercise error paths, where bugs often lurk.</p><p>We chose Spin to perform optimized state-space exploration because: (i) it is open-source and actively maintained; (ii) C code can be embedded in Spin's model-description language (Promela) to issue system calls, and c_track statements let Spin record C buffers as states <ref type="bibr">[16]</ref>; and (iii) Spin can perform parallel model checking using Swarm verification techniques <ref type="bibr">[17]</ref>, substantially speeding up exploration of large state spaces.</p><p>After each system call, integrity checks verify that all tested file systems have identical states by asserting equality of return values, error codes, file data, and metadata. If a discrepancy is detected, the integrity checker reports a potential bug and halts. Spin logs the precise sequence of operations, parameters, and starting and ending states that led to a problem, simplifying reproducibility. Because file systems have implementation-specific features <ref type="bibr">[35]</ref>, not all discrepancies are bugs. We believe though that many of these non-bug behavior differences are also interesting, since they still affect application behavior <ref type="bibr">[33]</ref>.</p><p>Finally, abstraction functions convert concrete states into abstract ones. In MCFS, each concrete state contains all the information needed to describe the file systems, including file data and metadata. MCFS uses the abstract state to determine whether a state was previously visited. If MCFS reaches a state that is logically equivalent to a previous one, it will backtrack corresponding concrete states to restore the file systems to their earlier versions. The abstraction functions hash the important data in the concrete states (including file paths, data, and relevant metadata) to distinguish logically unique states but omit noisy attributes such as atime timestamps and the physical locations of data blocks. Hashing the entire on-disk state would fail because of those less interesting attributes.</p><p>Designing abstraction functions requires domain knowledge. We wrote the functions to conform to the POSIX specification, so they are generic and applicable to most POSIX-compliant file systems.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3">CHALLENGES</head><p>We now describe challenges we encountered while developing MCFS, and our attempts to work around them.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.1">Access to In-Memory States</head><p>MCFS must save and restore all information related to the tested file systems, including their persistent (on-disk) and dynamic (in-memory) states. Spin could use the underlying block device to track persistent states, but there is no simple way to access in-memory states&#208;in kernel or user space&#208;because they are not part of Spin itself.</p><p>In-kernel file systems. Many file systems (e.g., Ext4 [11], XFS <ref type="bibr">[39]</ref>) run in the Linux kernel, with states in the kernel address space. In theory, one could use /dev/kmem to save and restore those states, but in reality they are so intertwined with other kernel data structures that doing so is impractical.</p><p>User-space file systems. Tracking kernel file systems is hard, so we turned to file systems built on libFUSE <ref type="bibr">[42]</ref> (e.g., fuse-ext2 <ref type="bibr">[1]</ref>). Such file systems, however, are separate processes, so Spin cannot directly track their internal state. We tried several alternatives. First, we modified malloc to allocate memory from a shared-memory pool accessible to Spin, so that it could be saved and restored. This failed because important state was stored in static (non-heap) variables outside the shared-memory segment, leading to incorrect pointers and crashes. We concluded that it was impractical to modify file-system code to avoid these static variables.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.2">Cache Incoherency</head><p>We next explored a compromise in which Spin tracked only the persistent (on-disk) state. Doing so allowed MCFS to run without crashing, but our experiments encountered corrupted file systems. A typical symptom was directory entries with corrupted or zeroed inodes, caused by Spin backtracking and restoring a persistent state. Since we were not restoring in-memory state to match, cached information in the kernel was no longer consistent with the disk content. For example, the dcache might contain a recently created directory, but the restored state might reflect a time before its creation.</p><p>We tried to resolve the inconsistency by calling fsync after each operation, and by mounting the file system with the sync option. Neither approach was effective: although they guaranteed that the caches were flushed to persistent storage, they did not implement the opposite operation&#208; loading any Spin-initiated change in the persistent storage back into the in-memory caches.</p><p>Finally, we compromised again: we unmounted and remounted the file system between each pair of operations. An unmount is the only way to fully guarantee that no state remains in kernel memory. [Re]mounting always loads the latest state from disk, ensuring that the caches are coherent between each Spin state exploration. This compromise caused two problems: (1) it considerably slowed state exploration (see Section 6) and ( <ref type="formula">2</ref>) it prevented us from identifying file-system bugs caused by incorrect in-memory states. These problems led us to consider adding support for file system state checkpointing and restoring (see Section 5). We use Spin's c_track statement to declare memory buffers used by the C code. During state exploration, Spin detects an already-visited state by comparing these buffers against all previously visited states. This causes state explosion because any change in a buffer is considered a new state, yet some changes, such as access-time updates, are rarely relevant to bugs. Consequently, Spin could not fully explore file systems with even moderate parameter spaces. Fortunately, Spin's c_track allows one to define abstract states used for matching, and concrete states used only in state restoration. We thus introduced an abstract state that contained an MD5 hash of file paths, data, and important metadata (e.g., mode, size, nlink, UID, and GID) for all files and directories.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.3">State Explosion</head><p>Algorithm 1 shows the procedure to obtain an abstract state of a file system. We first identify all files and directories in the file system by traversing from the mount point. We then sort them by their pathnames so that they appear in a consistent order. We then read each file's contents and call stat to obtain its metadata. The important_attributes function extracts only the important metadata mentioned above. Finally, we calculate the MD5 hash for the files' content, important metadata, and pathnames.</p><p>We then marked persistent states as concrete, and instructed Spin to track only the hashes that distinguish different abstract states. Doing so not only prevented visiting duplicate states, it also greatly reduced the amount of memory needed to track states, increasing Spin's exploration capacity.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.4">False Positives</head><p>MCFS performs integrity checks that assert state equality of the file systems under investigation. In case of any discrepancy, MCFS terminates and reports a bug, logging the operations it executed and their parameters. We found, however, that MCFS sometimes terminated on discrepancies that were not bugs. We took measures to prevent these false positives and describe several such cases below.</p><p>Directory-size reporting and ordering. In Ext4, directory sizes are a multiple of the block size; other file systems report sizes based on the number of active entries. Thus, directories on two different file systems might have the same contents but different sizes; we thus ignore directory sizes. Similarly, file systems return directory entries in different orders, so we sort the output of getdents before comparing them.</p><p>Special folders. Some file systems create special folders: For example, Ext4 has a lost+found folder to save lost and damaged files, while XFS does not. This caused namespace discrepancies between file systems. We added an exception list of special files and directories; MCFS ignores anything on this list when comparing abstract states.</p><p>Differing data capacity. Although we tested all file systems on block devices of the same size, they exposed different usable data capacities. This is a problem when the file systems are nearly full: calling write can succeed on one file system and fail on another, reporting a false bug. We thus equalize free space among file systems being checked: when MCFS starts, it queries all file systems and records the smallest free space as S L ; then on each file system with free space S n , it creates a dummy file and writes S n -S L bytes of zeros.</p><p>None of these workarounds introduce false negatives, because they are all dealing with unstandardized behavior. For example, an application should not expect sorted output from getdents, so if a given file system suddenly stops sorting, that is not a bug. (However, if the change introduces other misbehavior, we will detect the consequences.)</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4">MCFS PROTOTYPE IMPLEMENTATION</head><p>Figure <ref type="figure">1</ref> shows how MCFS's prototype handles different types of file systems. The file system syscall engine, written in Promela with embedded C code, consists of a multi-entry do ... od nondeterministic loop; each entry contains code to issue file-system operations, perform integrity checks, and record logs. Using Spin, MCFS nondeterministically selects an operation and its parameters, then executes it on all tested file systems. MCFS mmaps the file systems' backend storage devices into Spin's address space so it can track their states.</p><p>To prevent cache-coherency problems, MCFS unmounts and remounts kernel file systems (e.g., Ext4 and JFFS2) before and after each operation (see Section 3.2). However, syscalls such as write that depend on kernel state (e.g., open file descriptors) cannot be used in isolation. We thus developed meta-operations comprising small sequences of syscalls that avoid tracking kernel state: create_file creates and then closes a file; write_file opens, writes some data to, and closes a file. Other operations that can execute alone are run directly by MCFS, e.g., truncate and mkdir. Each operation's parameters are selected nondeterministically from a predefined (bounded) parameter pool. Because we limited our exploration space to fixed syscalls and parameters, the entire exploration&#208;while large&#208;is guaranteed to be bounded.</p><p>For FUSE-based file systems (e.g., fuse-ext2), the syscall is issued to the OS. FUSE's normal behavior results in several user/kernel messages being passed, coordinated via /dev/fuse (see fuse-ext2 in Figure <ref type="figure">1</ref>).</p><p>To avoid being slowed by I/Os, we used RAM block devices as backend storage for block-based file systems (e.g., Ext4 and XFS). Linux's RAM block device driver (brd) requires all RAM disks to be the same size; we slightly modified it (renamed brd2), to allow different-sized RAM disks for file systems with different minimum-size requirements.</p><p>Some file systems must be mounted using special devices. For example, JFFS2 <ref type="bibr">[44]</ref> requires an MTD character device <ref type="bibr">[43]</ref> instead of a regular block device. MCFS sets up JFFS2 differently: it (1) loads the mtdram kernel module, which creates a virtual MTD device in RAM, and then (2) loads the mtdblock module to provide a block interface for the virtual MTD device. This approach allows Spin to mmap the MTD storage via the block device.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5">TRACKING FILE-SYSTEM STATES</head><p>Unmounting and remounting a file system after each operation solved cache-incoherency problems but slowed the model checking and deviated from a normal use case. Due to its backtracking search process, Spin saves and restores all information related to the tested file systems. Therefore, we must track all file-system states, including persistent and in-memory ones. We investigated three approaches:</p><p>(1) process snapshotting and (2) VM snapshotting, which culminated in our (3) MCFS-enabled VeriFS.</p><p>Process snapshotting. User-space file systems run as independent processes. To keep their in-memory states vs. JFFS2, and VeriFS1 vs. VeriFS2. We used 256KB RAM block devices for both Ext2 and Ext4, and 16MB for XFS, which allows a larger minimum file-system size. VeriFS is an in-memory file system and does not need a block device.</p><p>Figure <ref type="figure">2</ref> shows model-checking speeds observed in our experiments. Checking Ext4 vs. XFS on RAM disks was over 11&#215; slower than Ext2 vs. Ext4 because MCFS consumed 105GB of swap space for the former, so swap time dominated. Checking Ext2 vs. Ext4 on HDD was 20&#215; slower than on RAM disks; using SSD was still 18&#215; slower. This illustrates the advantage of using RAM as backend storage. Checking VeriFS1 vs. VeriFS2 was 5.8&#215; faster than Ext2 vs. Ext4 for two reasons: (i) MCFS used the checkpoint/restore APIs (see Section 5) and thus did not have to unmount and remount the VeriFS file systems; (ii) VeriFS runs entirely in-memory, so MCFS did not access block devices to checkpoint and restore persistent states.</p><p>Figure <ref type="figure">3</ref> shows MCFS's speed when checking VeriFS1 over two weeks. MCFS maintained a rate of around 1,500 ops/s in the first 3 days; this rate then dropped drastically and swap usage spiked because Spin was resizing its hash table of visited states. After rebounding, MCFS's speed gradually decreased over time because the checkpointed states could not fit in memory and it began to consume swap space. Its speed increased again between days 13 and 14 because the RAM hit rate was high (states needed by MCFS happened to be in memory and did not need to be swapped in and out).</p><p>Note that by default MCFS remounts and unmounts the file systems before and after each operation. To evaluate the impact of that approach, we also measured MCFS's performance without the inter-operation remounts. The average speed for Ext2 vs. Ext4 (in RAM disks) was 316 ops/s, 38% faster than that when remounts and unmounts were used; and for Ext4 vs. XFS it was 34 ops/s, which is 70% faster.</p><p>Assisting file system development. While developing VeriFS1, we model-checked it vs. Ext4. MCFS found two bugs that we easily fixed, thanks to precise reports of operations and arguments. The first occurred after over 9K operations when test files on VeriFS and Ext4 had different content. The bug arose when truncate failed to clear newly allocated space when expanding a file. The second bug was detected after about 12K operations; MCFS created a test directory in Ext4 but VeriFS failed, claiming that the directory existed&#208; but in fact it did not. This was due to cache incoherency between the kernel and VeriFS's in-memory state. When VeriFS rolled back to an earlier state, the kernel's inode and dentry caches did not keep up. The fix was to call FUSE's cacheinvalidation APIs (fuse_lowlevel_notify_inval_entry and fuse_lowlevel_notify_inval_inode).</p><p>We then developed VeriFS2 (see Section 5) and used MCFS to assist development by model-checking it vs. VeriFS1. MCFS found two more bugs during this phase. The first occurred after over 900K operations, when the test files in VeriFS1 and VeriFS2 had different data. VeriFS2 had failed to zero the file buffer if write created a hole in the file. The second bug was detected after over 1.2M operations: the test file in VeriFS2 was shorter than that in VeriFS1. The reason was that the write method in VeriFS2 updated the file size only when the file was expanded beyond its buffer capacity, rather than whenever the file was appended to.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="7">CONCLUSIONS</head><p>We have proposed MCFS, a new model-checking framework for file system development that exhaustively explores a file system's (bounded) state space, without requiring manual modeling or significant changes to the kernel or the file system itself. We developed VeriFS (v1 and v2), prototypes that demonstrate state checkpointing and restoration functionality via ioctls. These functions let MCFS track VeriFS's full state while avoiding cache incoherency. MCFS found real bugs while we were developing VeriFS. Because both versions of VeriFS are simple and fast to model-check, they serve as a useful baseline against which we can compare other file systems.</p><p>We discussed the challenges we encountered when implementing MCFS, convincing ourselves of the need for file-system-level support to allow MCFS to work correctly and efficiently. Finally, while MCFS is designed to check file systems, its underlying approach is applicable to other system software.</p><p>Future work. We plan to add checkpoint/restore API support to Linux kernel file systems (e.g., Ext4) to eliminate the need for the current mount/remount workaround. We are implementing the checkpoint/restore API at the Linux VFS level, which we hope will apply to many Linux kernel file systems. We are also working on APIs that will checkpoint file system states to help us resume the model-checking process if an interruption occurs (e.g., due to a kernel crash). We also plan to run more than two file systems concurrently with MCFS and use a majority-voting approach to recognize incorrect file-system behavior.</p><p>We are exploring methods to track code coverage while model-checking. We will also use Spin's swarm verification <ref type="bibr">[17,</ref><ref type="bibr">18]</ref> to explore larger state spaces in parallel.</p></div></body>
		</text>
</TEI>
