Files
CephfsMig/cmd/nativeprobe/main_ceph.go
T
Sebastian UnterschützandClaude Opus 5.5 a6fda8f8d3 style: add blank lines between declarations and statement blocks
Separate top-level declarations and multi-line statements with blank
lines, keeping an "if err != nil" check next to the statement it
belongs to. Expand semicolon one-liners, group the nativeTransport
fields by purpose, and format the cgo preamble as readable C.
Apart from the expanded one-liners and the C preamble, the change
is whitespace only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 18:36:19 +01:00

81 lines
1.6 KiB
Go

//go:build ceph && cgo
// Command nativeprobe exercises the libcephfs binding against a lab cluster:
// it stats a path and optionally prints the snapdiff between two snapshots.
// It is only built with the ceph build tag and cgo.
package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"os"
"git.zb-server.de/Sebi/CephfsMig/internal/cephfsnative"
"git.zb-server.de/Sebi/CephfsMig/internal/storage"
)
func main() {
config := flag.String("config", "/lab/migration.example.json", "config")
root := flag.String("root", "/", "path to stat, or snapshot root")
rel := flag.String("rel", ".", "relative snapshot path")
a := flag.String("from", "", "previous snapshot")
b := flag.String("to", "", "current snapshot")
flag.Parse()
if err := run(os.Stdout, *config, *root, *rel, *a, *b); err != nil {
fmt.Fprintln(os.Stderr, "nativeprobe:", err)
os.Exit(1)
}
}
func run(out io.Writer, config, root, rel, from, to string) error {
data, err := os.ReadFile(config)
if err != nil {
return err
}
var c struct{ Source storage.Options }
if err = json.Unmarshal(data, &c); err != nil {
return fmt.Errorf("config: %w", err)
}
fs, err := cephfsnative.Open(c.Source)
if err != nil {
return err
}
defer fs.Close()
n, err := fs.Stat(root)
if err != nil {
return err
}
if err = json.NewEncoder(out).Encode(n); err != nil {
return err
}
if from == "" {
return nil
}
d, err := fs.SnapDiff(root, rel, from, to)
if err != nil {
return err
}
defer d.Close()
for {
name, err := d.Next()
if errors.Is(err, io.EOF) {
return nil
}
if err != nil {
return err
}
fmt.Fprintf(out, "diff: %q\n", name)
}
}