docs: add package and doc comments for exported identifiers

Document every exported type, function and method in the migration,
storage and cephfsnative packages and add package comments for
migration and the cephmig command, following the commentary rules of
Effective Go. Comments on unexported helpers now start with the name
they describe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-12-03 18:07:48 +01:00
1 parent 7413b9a43a
commit c2ef7a6c3b
12 files changed
+150 -7

No files matched your search

+11 -2
View File
@@ -10,6 +10,9 @@ import (
"strings"
)
// Endpoint describes how to reach one side of a migration: the Ceph
// client identity and configuration, the subvolume and, for the rsync
// backend, the local mount of the CephFS filesystem root.
type Endpoint struct {
User string `json:"user,omitempty"`
Config string `json:"config"`
@@ -20,6 +23,8 @@ type Endpoint struct {
Mount string `json:"mount,omitempty"`
}
// Config is the JSON migration configuration read by ReadConfig.
// Backend selects "native" (libcephfs) or "rsync" (the default).
type Config struct {
Backend string `json:"backend,omitempty"`
Workers int `json:"workers,omitempty"`
@@ -28,6 +33,8 @@ type Config struct {
BandwidthKiB int64 `json:"bandwidth_kib,omitempty"`
}
// ReadConfig reads exactly one JSON object from the regular file at path,
// rejects unknown fields and returns the validated configuration.
func ReadConfig(path string) (Config, error) {
var c Config
f, err := os.Open(path)
@@ -58,6 +65,8 @@ func validName(s string) bool {
!strings.ContainsAny(s, "/\x00\n\r")
}
// Validate checks names, paths, worker and bandwidth limits and reports
// the first problem found.
func (c Config) Validate() error {
if c.Backend != "" && c.Backend != "rsync" && c.Backend != "native" {
return errors.New("backend must be native or rsync")
@@ -105,8 +114,8 @@ func beneath(root, path string) bool {
}
func overlaps(a, b string) bool { return beneath(a, b) || beneath(b, a) }
// Resolve only real directories below the configured filesystem mount. No symlink
// component is permitted, including in the mount path.
// dataPath resolves cephPath to a real directory below the filesystem mount
// root. No symlink component is permitted, including in the mount path.
func dataPath(root, cephPath string) (string, error) {
if !filepath.IsAbs(cephPath) || filepath.Clean(cephPath) != cephPath || cephPath == "/" {
return "", fmt.Errorf("invalid Ceph path %q", cephPath)