# SRS-01: Storage Management

## 1. Overview
Storage Management module provides comprehensive management of ZFS storage pools, datasets, disks, and storage repositories.

## 2. Functional Requirements

### 2.1 ZFS Pool Management
**FR-SM-001**: System shall allow users to create ZFS pools
- **Input**: Pool name, RAID level, disk selection, compression, deduplication options
- **Output**: Created pool with UUID
- **Validation**: Pool name uniqueness, disk availability, RAID level compatibility

**FR-SM-002**: System shall allow users to list all ZFS pools
- **Output**: List of pools with status, capacity, health information
- **Refresh**: Auto-refresh every 2 minutes

**FR-SM-003**: System shall allow users to view ZFS pool details
- **Output**: Pool configuration, capacity, health, datasets, disk information

**FR-SM-004**: System shall allow users to delete ZFS pools
- **Validation**: Pool must be empty or confirmation required
- **Side Effect**: All datasets in pool are destroyed

**FR-SM-005**: System shall allow users to add spare disks to pools
- **Input**: Pool ID, disk list
- **Validation**: Disk availability, compatibility

### 2.2 ZFS Dataset Management
**FR-SM-006**: System shall allow users to create ZFS datasets
- **Input**: Pool ID, dataset name, type (filesystem/volume), compression, quota, reservation, mount point
- **Output**: Created dataset with UUID
- **Validation**: Name uniqueness within pool, valid mount point

**FR-SM-007**: System shall allow users to list datasets in a pool
- **Input**: Pool ID
- **Output**: List of datasets with properties
- **Refresh**: Auto-refresh every 1 second

**FR-SM-008**: System shall allow users to delete ZFS datasets
- **Input**: Pool ID, dataset name
- **Validation**: Dataset must not be in use

### 2.3 Disk Management
**FR-SM-009**: System shall discover and list all physical disks
- **Output**: Disk list with size, type, status, mount information
- **Refresh**: Auto-refresh every 5 minutes

**FR-SM-010**: System shall allow users to manually sync disk discovery
- **Action**: Trigger disk rescan

**FR-SM-011**: System shall display disk details
- **Output**: Disk properties, partitions, usage, health status

### 2.4 Storage Repository Management
**FR-SM-012**: System shall allow users to create storage repositories
- **Input**: Name, type, path, capacity
- **Output**: Created repository with ID

**FR-SM-013**: System shall allow users to list storage repositories
- **Output**: Repository list with capacity, usage, status

**FR-SM-014**: System shall allow users to view repository details
- **Output**: Repository properties, usage statistics

**FR-SM-015**: System shall allow users to delete storage repositories
- **Validation**: Repository must not be in use

### 2.5 ARC Statistics
**FR-SM-016**: System shall display ZFS ARC statistics
- **Output**: Hit ratio, cache size, eviction statistics
- **Refresh**: Real-time updates

## 3. User Interface Requirements

### 3.1 Storage Dashboard
- Pool overview cards with capacity and health
- Dataset tree view
- Disk list with status indicators
- Quick actions (create pool, create dataset)

### 3.2 Pool Management
- Pool creation wizard
- Pool detail view with tabs (Overview, Datasets, Disks, Settings)
- Pool deletion confirmation dialog

### 3.3 Dataset Management
- Dataset creation form
- Dataset list with filtering and sorting
- Dataset detail view
- Dataset deletion confirmation

## 4. API Endpoints

```
GET    /api/v1/storage/zfs/pools
GET    /api/v1/storage/zfs/pools/:id
POST   /api/v1/storage/zfs/pools
DELETE /api/v1/storage/zfs/pools/:id
POST   /api/v1/storage/zfs/pools/:id/spare

GET    /api/v1/storage/zfs/pools/:id/datasets
POST   /api/v1/storage/zfs/pools/:id/datasets
DELETE /api/v1/storage/zfs/pools/:id/datasets/:dataset

GET    /api/v1/storage/disks
POST   /api/v1/storage/disks/sync

GET    /api/v1/storage/repositories
GET    /api/v1/storage/repositories/:id
POST   /api/v1/storage/repositories
DELETE /api/v1/storage/repositories/:id

GET    /api/v1/storage/zfs/arc/stats
```

## 5. Permissions
- **storage:read**: Required for all read operations
- **storage:write**: Required for create, update, delete operations

## 6. Error Handling
- Invalid pool name format
- Disk not available
- Pool already exists
- Dataset in use
- Insufficient permissions

