Formally Specifying POSIX File Systems
Gian Ntzik, Pedro da Rocha Pinto and Philippa Gardner
Imperial College London
July 16, 2015
1/39
Formally Specifying POSIX File Systems Gian Ntzik , Pedro da Rocha - - PowerPoint PPT Presentation
Formally Specifying POSIX File Systems Gian Ntzik , Pedro da Rocha Pinto and Philippa Gardner Imperial College London July 16, 2015 1/39 POSIX File Systems POSIX: Portable Operating System Interface Large part devoted to the file system
Imperial College London
1/39
2/39
◮ POSIX: Portable Operating System Interface ◮ Large part devoted to the file system ◮ English Specification
◮ Underspecified ◮ Ambiguous ◮ Absence of proper memory model
3/39
◮ Find formalism suitable for specifying POSIX file system
◮ Suitable for clients and implementations ◮ Client reasoning in a program logic
◮ Focus a core fragment:
◮ Structural operations: mkdir, rmdir, link, unlink, rename, ... ◮ IO: open, read, write, lseek, close, ...
4/39
tmp usr
share bin local lib .X0-lock
git
5/39
6/39
◮ unlink(p) : Atomically remove the file identified by path p. ◮ “Atomic” has an unusual meaning in POSIX.
7/39
tmp usr
share bin local lib .X0-lock
git
7/39
tmp usr
share bin local lib .X0-lock
git ◮ Only removing git is required to be atomic.
7/39
tmp usr
share bin local lib .X0-lock
git ◮ Only removing git is required to be atomic. ◮ Path resolution: a sequence of atomic reads.
8/39
FS1 FS1 FS2 FS2 FS3 FS4 Environment: mupltiple atomic updates Thread: single atomic read in path traversal Thread: single atomic update
usr bin git
unlink(/usr/bin/git)
9/39
P Q
10/39
P1 P2 P3 P4 Pn−1 Pn
11/39
◮ Introduce multi-atomics:
◮ Extend reasoning rules for single atomic steps to multiple steps
12/39
13/39
14/39
15/39
FS1 FS1 FS2 FS2 FS FS'
usr bin
unlink(/usr/bin/git)
git
unlink(/usr/bin/git) ⊑ resolve(/usr/bin, ι0, r); . . .
16/39
FS1 FS1 FS2 FS2 FS FS'
usr bin
unlink(/usr/bin/git)
git
unlink(/usr/bin/git) ⊑ resolve(/usr/bin, ι0, r); (fs(FS) , in(FS, r, git) ⇒ rem(FS, r, git) ∗ ret = 0)
17/39
FS1 FS1 FS2 FS2 FS FS'
usr bin
unlink(/usr/bin/git)
git
unlink(/usr/bin/git) ⊑
in(FS, r, git) ⇒ rem(FS, r, git) ∗ ret = 0 ∧ out(FS, r, git) ⇒ fs(FS) ∗ ret = −1 ∗ errno = ENOENT
18/39
FS1 FS1 FS2 FS2 FS FS'
usr bin
unlink(/usr/bin/git)
git
unlink(/usr/bin/git) ⊑
fs(FS) , r ∈ In ⇒ in(FS, r, git) ⇒ rem(FS, r, git) ∗ ret = 0 ∧ out(FS, r, git) ⇒ fs(FS) ∗ ret = −1 ∗ errno = ENOENT
19/39
20/39
◮ Example: rename(p/a, p′/b) ◮ POSIX does not specify in which order p and p′ are resolved
20/39
◮ Example: rename(p/a, p′/b) ◮ POSIX does not specify in which order p and p′ are resolved ◮ We can’t do:
21/39
◮ Example: rename(p/a, p′/b) ◮ POSIX does not specify in which order p and p′ are resolved ◮ Solution:
22/39
23/39
◮ Lock Files ◮ POSIX pipes ◮ POSIX Advisory Locks/Record Locking (on-going) ◮ Persistent Concurrent Queues (future)
24/39
◮ lock(path): atomically create a non-existing lock file at path ◮ unlock(path): remove the lock file identified by path ◮ Implemented similarly to spin locks
◮ open(path, O CREAT|O EXCL) to try to lock ◮ unlink to unlock
25/39
26/39
◮ We know how to specify locks on the heap
26/39
◮ We know how to specify locks on the heap
26/39
◮ We know how to specify locks on the heap
◮ Ideally, we want the same specification for lock files ◮ Using path instead of heap address x
27/39
28/39
◮ The module owns the newly allocated memory
29/39
◮ The module enforces the sharing protocol
30/39
tmp usr
share bin local lib .X0-lock
git
30/39
tmp usr
share bin local lib .X0-lock
git ◮ No operation to extend with fresh path, unknown to
◮ Global path address space
31/39
tmp usr
share bin local lib .X0-lock
git
31/39
tmp usr
share bin local lib .X0-lock
git
◮ Clients must agree on sharing protocol
31/39
tmp usr
share bin local lib .X0-lock
git
◮ Clients must agree on sharing protocol ◮ Cooporative ownership
32/39
tmp usr
share bin local lib .X0-lock
git
33/39
tmp usr
share bin local lib .X0-lock
git
34/39
tmp usr
share bin local lib .X0-lock
git
35/39
36/39
37/39
◮ Introduced multi-atomic specifications ◮ Ordered sequences of atomic actions ◮ Unordered parallel atomic actions ◮ Formalised a fragment of POSIX file system operations ◮ Client reasoning ◮ Ownership in file systems is cooperative
38/39
◮ Link with operational models & testing ◮ Verify implementations ◮ Explore connection with refinement & Hoare’s algebraic laws ◮ Mechanisation