Skip to content

SimpleDaemons/simple-nfsd

Repository files navigation

Simple NFS Daemon

Version License Build Status

A lightweight, high-performance NFS server implementation designed for modern systems with support for NFSv2, NFSv3, and NFSv4 protocols.

Current Version: 0.5.1 (NFSv2, NFSv3 & NFSv4 Complete + Phase 3 Complete + Full ACL Support - Production Ready)
Phase 3 Status: ✅ 100% Complete (File System Operations Complete)
Latest Features: Full NFSv4 ACL support, File access/sharing mode tracking

Features

NFSv2 Protocol (Complete - Production Ready)

  • All 18 NFSv2 Procedures: NULL, GETATTR, SETATTR, LOOKUP, LINK, READ, SYMLINK, WRITE, CREATE, MKDIR, RMDIR, REMOVE, RENAME, READDIR, STATFS
  • File Operations: Complete file create, read, write, delete, rename operations
  • Directory Operations: Directory creation, removal, listing
  • Link Support: Both hard links and symbolic links
  • File Attributes: Full attribute management and retrieval
  • File System Statistics: Complete STATFS implementation

NFSv3 Protocol (Complete - Production Ready)

  • All 22 NFSv3 Procedures: NULL, GETATTR, SETATTR, LOOKUP, ACCESS, READLINK, READ, WRITE, CREATE, MKDIR, SYMLINK, MKNOD, REMOVE, RMDIR, RENAME, LINK, READDIR, READDIRPLUS, FSSTAT, FSINFO, PATHCONF, COMMIT
  • Enhanced Features: 64-bit file handles, 64-bit offsets, WCC (Weak Cache Consistency) data
  • File Attributes: Enhanced fattr3 structures with full attribute support
  • Directory Operations: READDIRPLUS with full attributes
  • File System Information: FSSTAT, FSINFO, and PATHCONF procedures
  • Comprehensive Testing: Full test suite for all NFSv3 procedures

NFSv4 Protocol (Complete - Production Ready)

  • All 38 NFSv4 Procedures: NULL, COMPOUND, GETATTR, SETATTR, LOOKUP, ACCESS, READLINK, READ, WRITE, CREATE, MKDIR, SYMLINK, MKNOD, REMOVE, RMDIR, RENAME, LINK, READDIR, READDIRPLUS, FSSTAT, FSINFO, PATHCONF, COMMIT, DELEGRETURN, GETACL, SETACL, FS_LOCATIONS, RELEASE_LOCKOWNER, SECINFO, FSID_PRESENT, EXCHANGE_ID, CREATE_SESSION, DESTROY_SESSION, SEQUENCE, GET_DEVICE_INFO, BIND_CONN_TO_SESSION, DESTROY_CLIENTID, RECLAIM_COMPLETE
  • Variable-Length Handles: NFSv4 uses opaque variable-length file handles
  • Advanced Features: COMPOUND operations framework, Full ACL support (GETACL/SETACL), session management, delegation support
  • File Access Tracking: Stateful file access and sharing mode tracking (READ_ONLY, WRITE_ONLY, READ_WRITE, APPEND, EXCLUSIVE, SHARED_READ, SHARED_WRITE, SHARED_ALL)
  • Comprehensive Testing: Full test suite for all NFSv4 procedures

Core Infrastructure (Complete)

  • RPC Portmapper Integration: Full RPC service registration and discovery
  • Multi-Format Configuration: Support for INI, JSON, and YAML configuration files
  • Cross-Platform: Linux, macOS, and Windows support
  • High Performance: Optimized for high-throughput file sharing
  • Easy Deployment: Docker containerization and system service support
  • Comprehensive Testing: 123/131 tests passing (94% success rate)
  • Static Linking: Self-contained binary generation
  • Security Features: Full ACL support, file access tracking, authentication (AUTH_SYS, AUTH_DH, Kerberos frameworks)
  • File System Features: Extended attributes, file locking (NLM), caching, monitoring, quota management

Quick Start

Building

# Regular build
make build

# Static binary build
make static-build

# Run tests
make test

# Create packages
make package
make static-package

Running

# Run in foreground
./simple-nfsd

# Run as daemon
./simple-nfsd --daemon

# With custom configuration
./simple-nfsd --config /path/to/config.json

# Show help
./simple-nfsd --help

Configuration

Simple NFS Daemon supports multiple configuration formats:

INI Format (Default)

[global]
server_name = "Simple NFS Daemon"
listen_address = "0.0.0.0"
listen_port = 2049
max_connections = 1000
log_level = "info"

JSON Format

{
  "global": {
    "server_name": "Simple NFS Daemon",
    "listen_address": "0.0.0.0",
    "listen_port": 2049,
    "max_connections": 1000,
    "log_level": "info"
  }
}

YAML Format

global:
  server_name: "Simple NFS Daemon"
  listen_address: "0.0.0.0"
  listen_port: 2049
  max_connections: 1000
  log_level: "info"

Configuration files are automatically detected based on file extension (.conf, .json, .yaml/.yml).

Configuration Options

Global Settings

  • server_name: Server identification string
  • listen_address: IP address to bind to (default: 0.0.0.0)
  • listen_port: Port to listen on (default: 2049)
  • max_connections: Maximum concurrent connections
  • thread_count: Number of worker threads
  • security_mode: Authentication mode (user, system)
  • root_squash: Enable root squashing
  • log_level: Logging level (debug, info, warn, error)

Export Settings

  • path: Directory path to export
  • clients: Allowed client addresses/networks
  • options: NFS export options (rw, ro, sync, etc.)
  • comment: Export description

Service Management

Systemd (Linux)

# Install service
sudo make service-install

# Start service
sudo systemctl start simple-nfsd

# Enable auto-start
sudo systemctl enable simple-nfsd

# Check status
sudo systemctl status simple-nfsd

Launchd (macOS)

# Install service
sudo make service-install

# Load service
sudo launchctl load /Library/LaunchDaemons/com.simple-nfsd.simple-nfsd.plist

# Check status
sudo launchctl list | grep simple-nfsd

Windows Service

# Install service
simple-nfsd --install-service

# Start service
net start simple-nfsd

# Stop service
net stop simple-nfsd

Docker Support

Using Docker Compose

version: '3.8'
services:
  simple-nfsd:
    image: simple-nfsd:latest
    ports:
      - "2049:2049"
    volumes:
      - ./exports:/var/lib/simple-nfsd/exports
      - ./config:/etc/simple-nfsd
    environment:
      - NFSD_CONFIG_FILE=/etc/simple-nfsd/simple-nfsd.json

Building Docker Image

# Build image
docker build -t simple-nfsd .

# Run container
docker run -d \
  --name simple-nfsd \
  -p 2049:2049 \
  -v /path/to/exports:/var/lib/simple-nfsd/exports \
  simple-nfsd

Development

Prerequisites

  • CMake 3.16+
  • C++17 compatible compiler
  • OpenSSL (for encryption)
  • JsonCPP (for JSON support)
  • yaml-cpp (for YAML support, optional)
  • GTest (for testing)

Building from Source

# Clone repository
git clone https://github.com/SimpleDaemons/simple-nfsd.git
cd simple-nfsd

# Create build directory
mkdir build && cd build

# Configure with CMake
cmake .. -DCMAKE_BUILD_TYPE=Release

# Build
make -j$(nproc)

# Run tests
make test

Testing

# Run all tests
make test

# Run specific test
./build/simple-nfsd-tests --gtest_filter=NfsdAppTest.*

# Run with verbose output
make test-verbose

Package Generation

The build system supports creating packages for multiple platforms:

Linux

  • DEB packages (Ubuntu/Debian)
  • RPM packages (Red Hat/CentOS/Fedora)

macOS

  • DMG disk images
  • PKG installer packages

Windows

  • MSI installer packages
  • ZIP archives

Source Packages

  • TAR.GZ archives
  • ZIP archives

Performance Tuning

Recommended Settings

[global]
# Increase for high-load environments
max_connections = 5000
thread_count = 16

# Optimize I/O
read_size = 65536
write_size = 65536

# Enable caching
cache_enabled = true
cache_size = "500MB"
cache_ttl = 7200

Security Considerations

  • Use root_squash to prevent root access from clients
  • Configure appropriate client access controls
  • Enable logging for audit trails
  • Use secure authentication methods
  • Regularly update to latest version

Troubleshooting

Common Issues

Port already in use

# Check what's using port 2049
sudo netstat -tlnp | grep 2049
sudo lsof -i :2049

Permission denied

# Check file permissions
ls -la /var/lib/simple-nfsd/exports/
sudo chown -R nfsd:nfsd /var/lib/simple-nfsd/

Configuration errors

# Validate configuration
./simple-nfsd --config /path/to/config.json --validate

Logs

  • System logs: /var/log/simple-nfsd/simple-nfsd.log
  • Systemd logs: journalctl -u simple-nfsd
  • Launchd logs: log show --predicate 'process == "simple-nfsd"'

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

Code Style

  • Follow existing code style
  • Use meaningful variable names
  • Add comments for complex logic
  • Write unit tests for new features

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Support

Roadmap

See ROADMAP.md for detailed development plans and upcoming features.

Current development focuses on:

  • Phase 1: Foundation (✅ Complete)
  • Phase 2: Core NFS Protocol Implementation (✅ Complete)
    • NFSv2 Protocol (✅ 100% Complete - v0.2.0)
    • NFSv3 Protocol (✅ 100% Complete - v0.3.0)
    • NFSv4 Protocol (✅ 100% Complete - v0.4.0)
    • Authentication & Security (✅ 100% Complete - v0.4.0)
  • Phase 3: File System Operations (✅ 100% Complete)
    • ✅ File operations (read/write, create/delete/rename)
    • ✅ Directory operations (MKDIR, RMDIR, READDIR)
    • ✅ Symbolic/hard links
    • ✅ File attributes and handle management
    • ✅ Root squash and export configuration
    • ✅ File locking (shared/exclusive locks with NLM support)
    • ✅ Extended attributes (xattrs)
    • ✅ File system caching (metadata and content)
    • ✅ File system monitoring (inotify integration)
    • ✅ Quota management framework
    • ✅ Export hot-reload
    • Full NFSv4 ACL support (GETACL/SETACL procedures)
    • File access and sharing mode tracking (stateful)
  • Phase 4: Advanced Features (📋 Planned)
  • Phase 5: Enterprise Features (📋 Planned)