Distributed-Virtual-File-System

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: GPL-3.0

README

Distributed Virtual File System

1. System Overview

This document describes the final design of a distributed virtual file system (VFS) inspired by AFS and implemented in userspace on top of the host OS filesystem.

The system consists of:

  • File Servers (FS) – store file data and enforce access control
  • Metadata Server (MDS) – stores indexing metadata for fast shared-file discovery
  • Clients – expose a virtual namespace and interact with FS and MDS
Design Goals
  • Correct filesystem semantics (open, read, write, rename, ls)
  • Each user sees exactly two namespaces:
    • mydrive (private)
    • shared (shared with the user)
  • Fast common case (ls shared)
  • Clear separation between authority and indexing

2. Terminology

2.1 Logical Inode

A logical inode is an internal representation of a file or directory.
It is not an OS inode.

Each logical inode has:

  • a stable identity
  • metadata (name, ACL)
  • a cached OS path

2.2 File Identifier (FID)

A FID uniquely identifies a file or directory globally.

FID = <file_server_id, inode_id, generation_number>
  • file_server_id – which file server owns the file
  • inode_id – unique logical inode number on that server
  • generation_number – increments on delete + recreate

FID is the only identity in the system.


2.3 Access Control List (ACL)

An ACL defines which users may access a file or directory.

ACL {
  read   → users allowed to read file
  write  → users allowed to modify file
  lookup → users allowed to traverse directory
}

Rules:

  • ACLs are stored and enforced only on file servers
  • Metadata server never enforces permissions

2.4 Private vs Shared Files
  • Private file – accessible only to the owner
  • Shared file – ACL allows additional users

2.5 Shared Index

A shared index is denormalized metadata on the metadata server used only for:

ls shared

3. High-Level Architecture

High-level architecture showing client mount-table, AFS-style caching, and MDS callbacks


4. File Server Design (Authoritative)

Each file server stores actual data on the OS filesystem and maintains one authoritative database.

4.1 Unified File Server Database
InodeDB {
  fid                PRIMARY KEY
  type               ENUM {file, directory}
  name               STRING
  os_path            STRING
  child_fids[]       ARRAY<FID>
  acl                ACL
}

Invariants

  • FID is identity
  • os_path is cached, derived state
  • ACLs are enforced before OS access
  • One inode maps to one OS path

4.2 Shared ACL Table (FS-local)
SharedACLTable {
  fid → users[]
}

Used to:

  • track shared inodes
  • notify metadata server
  • rebuild shared state after crashes

5. Metadata Server Design

The metadata server stores no file data and no ACLs.

5.1 Metadata Server Database
SharedIndex {
  fid           PRIMARY KEY
  cached_name
  users[]
}
  • users[] represents visibility only
  • access is always validated by file servers

6. Client Namespace (User View)

Each user sees exactly two directories:

mydrive/
shared/
Semantics
  • mydrive
    • User’s private files
    • Backed by the user’s root directory on a file server
  • shared
    • Virtual directory
    • Contains files and directories shared with the user
    • Backed by metadata server + FIDs

7. Private File Operations (mydrive)

Create Private File
touch mydrive/fileA

File server:

  1. Allocate new FID
  2. Create OS file
  3. Insert entry into InodeDB
  4. ACL allows only owner

Open Private File
open("mydrive/fileA")

File server:

  1. Resolve path → FID
  2. Check ACL
  3. Use os_path
  4. Call OS open()

8. Sharing Operations

Share a File
setacl mydrive/fileA alice read

File server:

  1. Update InodeDB[fid].acl
  2. Update SharedACLTable
  3. Notify metadata server

Metadata server updates SharedIndex.


9. Shared File Discovery (shared)

List Shared Files
ls shared

Client queries metadata server:

SELECT * FROM SharedIndex
WHERE user ∈ users[]

Result:

  • List of (fid, cached_name, fs_id)
  • No file-server RPCs required

10. Open Shared File

open("shared/fileA")

Client:

  • Resolves name → FID using metadata server

File server:

  1. Validate generation number
  2. Check ACL
  3. Use cached os_path
  4. Call OS open()

Client never sees real OS paths.


11. Rename and Move

Rename File (Private or Shared)
mv mydrive/fileA mydrive/fileX

File server:

  • updates name
  • updates os_path
  • FID unchanged
  • metadata server notified if shared

Move Directory (Rare, Expensive)
mv mydrive/project mydrive/archive/project

File server:

  • updates directory os_path
  • recursively updates children os_path
  • notifies metadata server for shared FIDs only

12. Delete / Unshare with Cascade

rm -r mydrive/project

File server:

  1. DFS using child_fids
  2. Remove each FID from SharedACLTable
  3. Notify metadata server
  4. Delete OS files and DB entries

Guarantee:

  • No ghost shared entries
  • No stale visibility

13. Failure Handling

Metadata Server Failure
  • File servers continue enforcing ACLs
  • ls shared may be stale
  • Access remains correct
File Server Failure

On restart:

  1. Scan OS filesystem
  2. Rebuild InodeDB
  3. Rebuild SharedACLTable
  4. Re-register shared FIDs

14. Design Invariants

  1. FID is the only identity
  2. ACLs enforced only on file servers
  3. Metadata server is advisory
  4. os_path must match OS filesystem
  5. Rename/move updates os_path
  6. Shared index staleness is safe

15. Security (TLS)

All gRPC communication (client↔metaserver, client↔fileserver) and the Admin Console are secured with mutual TLS using a private Root CA. TLS is always on — there is no --tls=true/false flag. Certificates are loaded automatically when present on each node.

15.1 Certificate Architecture
Component Role
Root CA (certs/ca.crt + certs/ca.key) 4096-bit RSA CA. ca.key never leaves the admin machine.
Node certs (deploy_certs/<hostname>/server.crt + server.key) 2-year leaf certs signed by the Root CA, with DNS SANs for each cluster hostname.
Client trust RootCAPEM is hardcoded at compile-time in internal/client/ca.go — no CA file needed on client machines.
15.2 One-Time PKI Setup (Admin Machine Only)
# 1. Generate Root CA (writes certs/ca.crt + certs/ca.key — run ONCE, keep ca.key offline)
make certs-root-ca

# 2. Generate localhost dev cert (idempotent — skips if server.crt/server.key already exist)
make certs

# 3. Generate all cluster node certs (dvfs1–dvfs9) into deploy_certs/
make certs-nodes

See docs/TLS_Setup_Guide.md for the complete deployment checklist, including how to scp certs to each node and verify them with openssl.

15.3 Server Startup with TLS

Servers auto-detect TLS: if TLS_CERT and TLS_KEY environment variables (or -tls_cert/-tls_key flags) point to valid cert/key files, TLS is enabled automatically.

# Metaserver on dvfs1
TLS_CERT=certs/server.crt TLS_KEY=certs/server.key ./scripts/start-metaserver.sh

# Admin Console with TLS
TLS_CERT=certs/server.crt TLS_KEY=certs/server.key ./scripts/start-admin.sh
15.4 Client — No Configuration Needed

The Root CA public cert is embedded in the client binary. Clients discover server IPs dynamically via a GitHub Gist (configurable with -gist_url) and automatically resolve the correct TLS ServerName for SNI. No cert files need to be copied to client machines.


16. Summary

Each user interacts with exactly two namespaces—mydrive for private data and shared for shared data. File servers maintain authoritative metadata and enforce ACLs, while the metadata server maintains a denormalized shared index to optimize listing without participating in access control.

Commands To Run the Whole Setup

For Fileserver (from project root)
go run .\cmd\fileserver\main.go --meta_addr <full ip + port of mds> --own_ip=<this fileservers ip to send to mds>

Other flags and defaults:

  • port = 50052
  • id = fs1
  • data = fileserver_data
  • tls_cert = certs/server.crt (TLS auto-enabled when cert+key files exist)
  • tls_key = certs/server.key
For Metadata Server (from project root)
go run .\cmd\metaserver\main.go

Other flags and defaults:

  • port = 50051
  • tls_cert = certs/server.crt (TLS auto-enabled when cert+key files exist)
  • tls_key = certs/server.key
For Client (from root)
go run .\cmd\client\main.go --username <username> --ip_addr <mds/fs ip address>

Other flags and defaults

  • port = 50051
  • meta = true (whether to go to mds or not)
  • use_gist = true (fetch server IP map from GitHub Gist for dynamic discovery)
For Admin Console (from project root)

The admin console provides a centralized web dashboard to monitor fileserver nodes (storage, CPU temperature, RAM, uptime, per-user usage), active users, and system health in real-time.

1. Building the Frontend (one-time setup)

The React SPA source is in cmd/admin/ui. Build the static assets into cmd/admin/static:

cd cmd/admin/ui
npm install
npm run build
cd ../../..

(For live UI development with hot-reload against a running backend, run npm run dev inside cmd/admin/ui)

2. Starting the Admin Server
go run .\cmd\admin\main.go --state_file=./metaserver_state.json --port=8080

Or with make:

make run-admin

Other flags and defaults:

  • port = 8080 (HTTP port for the web dashboard and REST API)
  • state_file = ./metaserver_state.json (metaserver state file used for dynamic node discovery)
  • static = ./cmd/admin/static (path to frontend build directory)

Open your browser at http://localhost:8080 to view the dashboard.

3. How Telemetry Scrapes Work
  • Each fileserver automatically starts a lightweight /metrics HTTP sidecar on port port - 41000 (e.g., gRPC port 50052 → metrics HTTP 9052).
  • The admin backend reads metaserver_state.json, discovers active fileserver addresses, scrapes their /metrics endpoints every 5 seconds, maintains a 60-minute in-memory ring buffer for historical graphs, and serves the UI.
4. Running Admin Console Tests
make test-admin
# or
go test ./internal/admin -v

Directories

Path Synopsis
api
cmd
admin command
client command
fileserver command
metaserver command
internal
scripts
build-release command
gen-certs command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL