A robust, scalable distributed file system supporting file operations, directory management, streaming, and redundancy.
This project implements a distributed file system (DFS) with three major components:
- Clients: User-facing applications that request file operations (read, write, delete, stream, etc.).
- Naming Server (NM): The central coordinator that manages metadata, directory structure, and orchestrates communication between clients and storage servers.
- Storage Servers (SS): Responsible for actual file storage, retrieval, and redundancy. Multiple SS can be added dynamically.
Clients interact with the system to perform essential file operations, including:
- Write (Sync/Async): Create or update files/folders, with support for asynchronous writes for large files.
- Read: Retrieve file contents.
- Delete: Remove files/folders.
- Create: Generate new files/folders.
- List: List files and folders in a directory.
- Metadata: Get file size, permissions, and timestamps.
- Streaming: Stream audio files directly from the NFS.
-
Naming Server (NM):
- Maintains a global directory of all files/folders and their locations.
- Handles client requests, determines the correct SS, and provides connection details.
- Manages registration and dynamic addition of Storage Servers.
- Handles backup, redundancy, and failure detection.
-
Storage Servers (SS):
- Store and manage files/folders.
- Register with the NM, providing IP, ports, and accessible paths.
- Support file operations and interact directly with clients after NM mediation.
- Support dynamic addition and removal.
-
Clients:
- Connect to NM for metadata and SS location.
- Communicate directly with SS for file operations.
- Support both synchronous and asynchronous writes.
- Distributed Architecture: Centralized metadata management with distributed storage.
- Dynamic Scaling: Add/remove Storage Servers at runtime.
- File & Directory Operations:
ls,write,cat,mkdir,touch,rmdir,rm. - Asynchronous Write Support: Optimizes client response time for large files.
- Streaming: Stream audio files using
ffplay. - Backup & Redundancy: Automatic replication of files/folders across multiple SS for fault tolerance.
- Caching: LRU caching in NM for fast path lookups.
- Access Control: Restricts operations to within server root directories.
- Logging & Bookkeeping: All operations, IPs, and ports are logged for traceability.
- Error Codes: Clear error codes for all failure scenarios.
- Efficient Search: Trie based path lookup in NM for fast response.
- Concurrent Clients: Supports multiple clients with proper locking and ACK mechanisms.
- Failure Detection and Recovery: NM detects SS failures and serves data from replicas.
- C (POSIX Sockets, Threads): Core networking and concurrency.
- Makefile: Build automation.
- Linux/Unix: POSIX-compliant systems.
- ffplay: Media streaming (must be installed).
- Trie: Efficient metadata management.
- LRU Cache: Fast repeated lookups.
NetworkFIleSystem/
├── client.c # Client logic
├── naming_server.c # Naming Server logic
├── storage_server.c # Storage Server logic
├── helper.c/.h # Shared utilities and protocol helpers
├── lock.c/.h # Locking mechanisms
├── tries.c/.h # Trie data structure for path management
├── ErrorCodes.h # Error code definitions
├── Makefile # Build automation
├── log.txt # Operation logs
├── README.md # Project documentation
└── (media/test files)
make all # Builds all components: Naming Server, Storage Server, and ClientOr build individually:
make naming_server # Build only Naming Server
make storage_server # Build only Storage Server
make client # Build only Client-
Naming Server:
make ns
The system will prompt you to enter a port number. Example:
Enter port number for Naming Server: 5000 -
Storage Server:
make ss
The system will prompt you to enter the root path. Example:
Enter root path for Storage Server: /home/nitin/nfs_storageNote: Use absolute paths for the root directory.
Run this command multiple times in different terminals for multiple Storage Servers.
- Client:
The system will prompt you to enter the Naming Server IP address. Example:
make cl
Enter IP address of Naming Server: 127.0.0.1
You can also run the executables directly:
-
Naming Server:
./naming_server <PORT>
Example:
./naming_server 5000 -
Storage Server:
./storage_server <IP> <ROOT_PATH>
Example:
./storage_server 127.0.0.1 /home/nitin/nfs_storage -
Client:
./client <NAMING_SERVER_IP>
Example:
./client 127.0.0.1
To remove backup folders:
rm -rf ./backupfolderforssTo remove all executables and object files:
make cleanTips:
- Always use absolute paths for Storage Server root directories to avoid confusion.
- Ensure the port you choose for the Naming Server is open and not in use.
- For distributed deployment across multiple machines, use the actual IP addresses instead of 127.0.0.1.
- If you encounter issues, check the logs in
log.txtfor troubleshooting. - Each Storage Server should have a unique root path.
- File Operations:
ls,write <src> <dest>,cat <file> - Directory Management:
mkdir <dir>,touch <file>,rmdir <dir>,rm <file> - Streaming:
stream <file>(requiresffplay) - Async Write:
writecommand supports async mode with client-side ACKs.
Command Flow Examples:
READ <path>: NM returns SS IP/port; client fetches file.STREAM <path>: NM returns SS IP/port; client streams audio.CREATE <path> <name>: NM validates, instructs SS, updates metadata.COPY <source> <dest>: NM orchestrates copy between SS, updates metadata.
- Max Storage Servers: Up to 10 (tested with 5).
- Max Clients: Unlimited.
- Path Restriction: All paths must be within the server’s root directory.
- Buffer Size: Default 2048 bytes; max file size 4096 bytes (configurable in
helper.h). - Ports: Assigned automatically for multiple instances.
- Unique Paths: No two SS should share the same root folder.
- Backups: Stored in
backupforss(not accessible as normal paths). - Root Folder Protection: Root folders cannot be copied or removed.
- Buffer Flow: Minor buffer flow issues may occur but do not affect core functionality.
- Root Folder: Cannot copy/remove root folders for safety.