Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/API-CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Mount logs each write at INFO with the client address, the action, its arguments

### Web Dashboard

Mount serves a web dashboard at `http://<api-addr>/ui/`, unless `-dashboard=false`. It shows status, capacity, the cache, journal, TRIM and lock counters, and the nodes in the registry. It lists snapshots, and for a file you name it creates, clones and deletes them and clones the file. Its Settings page runs the admin endpoints.
Mount serves a web dashboard at `http://<api-addr>/ui/`, unless `-dashboard=false`. It shows status, capacity, the cache, journal, TRIM and lock counters, and the nodes in the registry. It lists snapshots, and for a file you name it creates, clones and deletes them and clones the file. Orphaned snapshots, whose file is gone, get a list of their own where you can delete them. Its Settings page runs the admin endpoints.

The dashboard's files are static and hold no data, so they need no token and skip the rate limit. The page calls `/api/v1/...` on the same origin with the same rules as any client: reads need the token when one is set, and snapshots always need it. Enter the token on the dashboard's Settings page. The browser keeps it in `sessionStorage`, so closing the tab forgets it. Responses carry a `Content-Security-Policy` that lets the page load and call only its own origin and stops other sites from framing it.

Expand Down
15 changes: 15 additions & 0 deletions internal/api/writes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,21 @@ func TestTokenInQueryIsIgnored(t *testing.T) {
}
}

// The dashboard deletes orphans, whose file is gone, by leaving out ?path=.
func TestDeleteWithoutPathReachesTheService(t *testing.T) {
srv, files, _ := startWriteServer(t, "secret")
if status, body := call(t, srv, "DELETE", "/api/v1/snapshots/s1", "secret", ""); status != http.StatusOK {
t.Fatalf("delete without a path: %d %s", status, body)
}
if got := files.lastCall(); got != "delete s1" {
t.Fatalf("service got %q, want an empty path", got)
}
files.err = fmt.Errorf("snapshot %q belongs to inode 12: %w", "s1", syscall.EBUSY)
if status, body := call(t, srv, "DELETE", "/api/v1/snapshots/s1", "secret", ""); status != http.StatusConflict {
t.Fatalf("delete of a snapshot whose file exists: %d %s, want 409", status, body)
}
}

func TestDeleteTakesEscapedNames(t *testing.T) {
srv, files, _ := startWriteServer(t, "secret")
if status, body := call(t, srv, "DELETE", "/api/v1/snapshots/nightly%2F2026%3A1?path=/f", "secret", ""); status != http.StatusOK {
Expand Down
8 changes: 5 additions & 3 deletions web/dashboard/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ export class ApiClient {
}

// Deletion finishes in the background: the snapshot lists as "deleting" until the worker frees it.
deleteSnapshot(name: string, path: string): Promise<WriteResponse> {
return this.send('DELETE', `/api/v1/snapshots/${encodeURIComponent(name)}?path=${encodeURIComponent(path)}`)
// Without a path it deletes only an orphan, and answers 409 if the snapshot's file still exists.
deleteSnapshot(name: string, path?: string): Promise<WriteResponse> {
const query = path ? `?path=${encodeURIComponent(path)}` : ''
return this.send('DELETE', `/api/v1/snapshots/${encodeURIComponent(name)}${query}`)
}

cloneSnapshot(name: string, request: CloneRequest): Promise<WriteResponse> {
Expand Down Expand Up @@ -209,7 +211,7 @@ export const api = {
getClusterStats: (options?: RequestOptions) => apiClient.getClusterStats(options),
listSnapshots: (path?: string, options?: RequestOptions) => apiClient.listSnapshots(path, options),
createSnapshot: (request: SnapshotRequest) => apiClient.createSnapshot(request),
deleteSnapshot: (name: string, path: string) => apiClient.deleteSnapshot(name, path),
deleteSnapshot: (name: string, path?: string) => apiClient.deleteSnapshot(name, path),
cloneSnapshot: (name: string, request: CloneRequest) => apiClient.cloneSnapshot(name, request),
cloneFile: (request: CloneRequest) => apiClient.cloneFile(request),
admin: (operation: AdminOperation) => apiClient.admin(operation),
Expand Down
2 changes: 2 additions & 0 deletions web/dashboard/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ export interface SnapshotInfo {
size_bytes: number
blocks: number
created_at?: string
/** Its file is gone, or it predates the record of which file it belongs to; only the full list shows it */
orphan?: boolean
}

// GET /api/v1/snapshots[?path=]
Expand Down
240 changes: 165 additions & 75 deletions web/dashboard/src/pages/SnapshotsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,66 @@ function FileForm({ path, onChange }: { path: string; onChange: (path: string) =
)
}

function OrphanSnapshots({ orphans, onDelete }: { orphans: SnapshotInfo[]; onDelete: (snapshot: SnapshotInfo) => void }) {
return (
<div className="card space-y-3">
<div>
<h2 className="card-header mb-1">Orphaned snapshots ({orphans.length})</h2>
<p className="text-sm text-gfs-text-muted">
The file each of these was taken of is gone, or it was taken by an older version that did not record its file.
No file lists them and they can't be cloned, but they keep their blocks until you delete them.
</p>
</div>
<div className="overflow-x-auto">
<table className="w-full">
<thead className="bg-gfs-bg-tertiary">
<tr>
<PlainHeader label="Name" />
<PlainHeader label="State" />
<PlainHeader label="Size" />
<PlainHeader label="Blocks" />
<PlainHeader label="Created" />
<PlainHeader label="Old inode" />
<PlainHeader label="Actions" />
</tr>
</thead>
<tbody>
{orphans.map((snapshot) => (
<tr key={snapshot.id} className="border-b border-gfs-border last:border-0">
<td className="px-4 py-3 text-sm font-medium text-gfs-text-primary">{snapshot.name}</td>
<td className="px-4 py-3">
<StateBadge state={snapshot.state} />
</td>
<td className="px-4 py-3 text-sm text-gfs-text-secondary">{formatBytes(snapshot.size_bytes)}</td>
<td className="px-4 py-3 text-sm text-gfs-text-secondary">{formatNumber(snapshot.blocks)}</td>
<td className="px-4 py-3 text-sm text-gfs-text-muted">
{snapshot.created_at ? formatRelativeTime(new Date(snapshot.created_at)) : '-'}
</td>
<td className="px-4 py-3 text-sm font-mono text-gfs-text-muted">{snapshot.inode}</td>
<td className="px-4 py-3 text-sm">
<button
disabled={snapshot.state !== 'active'}
onClick={() => onDelete(snapshot)}
className="text-gfs-status-error hover:underline disabled:opacity-40 disabled:no-underline disabled:cursor-not-allowed"
>
Delete
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
)
}

type Dialog =
| { kind: 'create' }
| { kind: 'clone-file' }
| { kind: 'clone-snapshot'; snapshot: SnapshotInfo }
| { kind: 'delete'; snapshot: SnapshotInfo }
| { kind: 'delete-orphan'; snapshot: SnapshotInfo }

export function SnapshotsPage() {
const refreshInterval = useRefreshInterval()
Expand All @@ -185,7 +240,7 @@ export function SnapshotsPage() {
}

const rows = useMemo(() => {
const list = snapshots.data?.snapshots ?? []
const list = (snapshots.data?.snapshots ?? []).filter((s) => !s.orphan)
const query = search.toLowerCase()
const filtered = query ? list.filter((s) => s.name.toLowerCase().includes(query)) : [...list]
filtered.sort((a, b) => {
Expand All @@ -211,6 +266,8 @@ export function SnapshotsPage() {

const closeDialog = () => setDialog(null)
const list = snapshots.data?.snapshots ?? []
const owned = list.filter((s) => !s.orphan)
const orphans = list.filter((s) => s.orphan)
const totalSize = list.reduce((sum, s) => sum + s.size_bytes, 0)

return (
Expand Down Expand Up @@ -291,82 +348,90 @@ export function SnapshotsPage() {
</div>
</div>

<div className="flex items-center gap-4">
<input
type="text"
placeholder="Filter by name..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="px-3 py-1.5 bg-gfs-bg-tertiary border border-gfs-border rounded text-sm text-gfs-text-primary placeholder-gfs-text-muted focus:outline-none focus:ring-2 focus:ring-gfs-accent-primary w-64"
/>
<button onClick={snapshots.refetch} className="text-sm text-gfs-accent-primary hover:underline">
Refresh
</button>
<span className="text-sm text-gfs-text-muted ml-auto">
Showing {rows.length} of {list.length}
</span>
</div>
{owned.length > 0 && (
<>
<div className="flex items-center gap-4">
<input
type="text"
placeholder="Filter by name..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="px-3 py-1.5 bg-gfs-bg-tertiary border border-gfs-border rounded text-sm text-gfs-text-primary placeholder-gfs-text-muted focus:outline-none focus:ring-2 focus:ring-gfs-accent-primary w-64"
/>
<button onClick={snapshots.refetch} className="text-sm text-gfs-accent-primary hover:underline">
Refresh
</button>
<span className="text-sm text-gfs-text-muted ml-auto">
Showing {rows.length} of {owned.length}
</span>
</div>

<div className="card overflow-hidden">
<div className="overflow-x-auto">
<table className="w-full">
<thead className="bg-gfs-bg-tertiary">
<tr>
<SortableHeader label="Name" field="name" sort={sortField} direction={sortDirection} onSort={handleSort} />
<SortableHeader label="State" field="state" sort={sortField} direction={sortDirection} onSort={handleSort} />
<SortableHeader label="Size" field="size_bytes" sort={sortField} direction={sortDirection} onSort={handleSort} />
<PlainHeader label="Blocks" />
<SortableHeader label="Created" field="created_at" sort={sortField} direction={sortDirection} onSort={handleSort} />
{path ? <PlainHeader label="Actions" /> : <PlainHeader label="Inode" />}
</tr>
</thead>
<tbody>
{rows.map((snapshot) => (
<tr key={snapshot.id} className="border-b border-gfs-border hover:bg-gfs-bg-tertiary/50 transition-colors">
<td className="px-4 py-3 text-sm font-medium text-gfs-text-primary">{snapshot.name}</td>
<td className="px-4 py-3">
<StateBadge state={snapshot.state} />
</td>
<td className="px-4 py-3 text-sm text-gfs-text-secondary">{formatBytes(snapshot.size_bytes)}</td>
<td className="px-4 py-3 text-sm text-gfs-text-secondary">{formatNumber(snapshot.blocks)}</td>
<td className="px-4 py-3 text-sm text-gfs-text-muted">
{snapshot.created_at ? formatRelativeTime(new Date(snapshot.created_at)) : '-'}
</td>
{path ? (
<td className="px-4 py-3">
<div className="flex items-center gap-3 text-sm">
<button
disabled={snapshot.state !== 'active'}
onClick={() => setDialog({ kind: 'clone-snapshot', snapshot })}
className="text-gfs-accent-primary hover:underline disabled:opacity-40 disabled:no-underline disabled:cursor-not-allowed"
>
Clone
</button>
<button
disabled={snapshot.state !== 'active'}
onClick={() => setDialog({ kind: 'delete', snapshot })}
className="text-gfs-status-error hover:underline disabled:opacity-40 disabled:no-underline disabled:cursor-not-allowed"
>
Delete
</button>
</div>
</td>
) : (
<td className="px-4 py-3 text-sm font-mono text-gfs-text-muted">{snapshot.inode}</td>
<div className="card overflow-hidden">
<div className="overflow-x-auto">
<table className="w-full">
<thead className="bg-gfs-bg-tertiary">
<tr>
<SortableHeader label="Name" field="name" sort={sortField} direction={sortDirection} onSort={handleSort} />
<SortableHeader label="State" field="state" sort={sortField} direction={sortDirection} onSort={handleSort} />
<SortableHeader label="Size" field="size_bytes" sort={sortField} direction={sortDirection} onSort={handleSort} />
<PlainHeader label="Blocks" />
<SortableHeader label="Created" field="created_at" sort={sortField} direction={sortDirection} onSort={handleSort} />
{path ? <PlainHeader label="Actions" /> : <PlainHeader label="Inode" />}
</tr>
</thead>
<tbody>
{rows.map((snapshot) => (
<tr key={snapshot.id} className="border-b border-gfs-border hover:bg-gfs-bg-tertiary/50 transition-colors">
<td className="px-4 py-3 text-sm font-medium text-gfs-text-primary">{snapshot.name}</td>
<td className="px-4 py-3">
<StateBadge state={snapshot.state} />
</td>
<td className="px-4 py-3 text-sm text-gfs-text-secondary">{formatBytes(snapshot.size_bytes)}</td>
<td className="px-4 py-3 text-sm text-gfs-text-secondary">{formatNumber(snapshot.blocks)}</td>
<td className="px-4 py-3 text-sm text-gfs-text-muted">
{snapshot.created_at ? formatRelativeTime(new Date(snapshot.created_at)) : '-'}
</td>
{path ? (
<td className="px-4 py-3">
<div className="flex items-center gap-3 text-sm">
<button
disabled={snapshot.state !== 'active'}
onClick={() => setDialog({ kind: 'clone-snapshot', snapshot })}
className="text-gfs-accent-primary hover:underline disabled:opacity-40 disabled:no-underline disabled:cursor-not-allowed"
>
Clone
</button>
<button
disabled={snapshot.state !== 'active'}
onClick={() => setDialog({ kind: 'delete', snapshot })}
className="text-gfs-status-error hover:underline disabled:opacity-40 disabled:no-underline disabled:cursor-not-allowed"
>
Delete
</button>
</div>
</td>
) : (
<td className="px-4 py-3 text-sm font-mono text-gfs-text-muted">{snapshot.inode}</td>
)}
</tr>
))}
{rows.length === 0 && (
<tr>
<td colSpan={6} className="px-4 py-8 text-center text-gfs-text-muted">
No snapshots match the filter
</td>
</tr>
)}
</tr>
))}
{rows.length === 0 && (
<tr>
<td colSpan={6} className="px-4 py-8 text-center text-gfs-text-muted">
No snapshots match the filter
</td>
</tr>
)}
</tbody>
</table>
</div>
</div>
</tbody>
</table>
</div>
</div>
</>
)}

{orphans.length > 0 && (
<OrphanSnapshots orphans={orphans} onDelete={(snapshot) => setDialog({ kind: 'delete-orphan', snapshot })} />
)}
</>
)}

Expand Down Expand Up @@ -440,6 +505,31 @@ export function SnapshotsPage() {
/>
)}

{dialog?.kind === 'delete-orphan' && (
<ConfirmDeleteModal
key={dialog.snapshot.id}
isOpen
onClose={closeDialog}
onConfirm={async () => {
try {
await api.deleteSnapshot(dialog.snapshot.name)
} catch (err) {
if (err instanceof ApiError && err.status === 409) {
throw new Error('Its file still exists, so it is not an orphan. Delete it from that file\'s snapshots.')
}
throw err
}
snapshots.refetch()
}}
title="Delete orphaned snapshot"
itemName={dialog.snapshot.name}
itemType="snapshot"
warning="The snapshot and the blocks only it holds are freed. Its file is gone, so nothing else can reach them. This cannot be undone."
successMessage="Delete started. The snapshot shows as deleting until its blocks are freed."
requireTypeToConfirm
/>
)}

{dialog?.kind === 'delete' && (
<ConfirmDeleteModal
key={dialog.snapshot.id}
Expand Down
Loading