The native libcephfs backend is the only transfer path. The rsync transport, the mounted-filesystem access and its helpers (mount check, path resolution below a mount, mount claim, quota and hardlink repair through the mount) are removed, together with the rsync lab test and the client image that only added rsync. The claim and release tests now exercise the native claim through a local test file system with real flock locks. BREAKING CHANGE: "backend": "rsync" and the endpoint field "mount" are rejected. "backend" is optional and only accepts "native"; jobs created with "native" resume without it. Journals of rsync jobs cannot be resumed. Builds without the build tag ceph only support doctor and status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
117 lines
3.2 KiB
Go
117 lines
3.2 KiB
Go
package migration
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// Endpoint describes how to reach one side of a migration: the Ceph
|
|
// client identity and configuration and the subvolume.
|
|
type Endpoint struct {
|
|
User string `json:"user,omitempty"`
|
|
Config string `json:"config"`
|
|
Keyring string `json:"keyring"`
|
|
Filesystem string `json:"filesystem"`
|
|
Group string `json:"group"`
|
|
Subvolume string `json:"subvolume"`
|
|
}
|
|
|
|
// Config is the JSON migration configuration read by ReadConfig.
|
|
// Backend is optional; the only backend is "native" (libcephfs).
|
|
type Config struct {
|
|
Backend string `json:"backend,omitempty"`
|
|
Workers int `json:"workers,omitempty"`
|
|
Source Endpoint `json:"source"`
|
|
Target Endpoint `json:"target"`
|
|
BandwidthKiB int64 `json:"bandwidth_kib,omitempty"`
|
|
|
|
// FullScan disables the rctime shortcut of the native backend, so every
|
|
// round reads all metadata. finalize always does.
|
|
FullScan bool `json:"full_scan,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)
|
|
if err != nil {
|
|
return c, err
|
|
}
|
|
|
|
defer f.Close()
|
|
st, err := f.Stat()
|
|
if err != nil {
|
|
return c, err
|
|
}
|
|
|
|
if !st.Mode().IsRegular() || st.Size() > 1<<20 {
|
|
return c, errors.New("config must be a regular file of at most 1 MiB")
|
|
}
|
|
|
|
dec := json.NewDecoder(io.LimitReader(f, 1<<20))
|
|
dec.DisallowUnknownFields()
|
|
if err = dec.Decode(&c); err != nil {
|
|
return c, fmt.Errorf("config: %w", err)
|
|
}
|
|
|
|
if err = dec.Decode(new(any)); !errors.Is(err, io.EOF) {
|
|
return c, errors.New("config must contain exactly one JSON object")
|
|
}
|
|
|
|
return c, c.Validate()
|
|
}
|
|
|
|
func validName(s string) bool {
|
|
return s != "" && s != "." && s != ".." && !strings.HasPrefix(s, "-") &&
|
|
!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 != "native" {
|
|
return errors.New(`backend must be "native"; the rsync backend was removed`)
|
|
}
|
|
|
|
if c.Workers < 0 || c.Workers > 64 {
|
|
return errors.New("workers must be between 0 and 64 (0 selects the default)")
|
|
}
|
|
|
|
for _, p := range []struct {
|
|
name string
|
|
e Endpoint
|
|
}{{"source", c.Source}, {"target", c.Target}} {
|
|
if p.e.User != "" && (!strings.HasPrefix(p.e.User, "client.") || !validName(p.e.User)) {
|
|
return fmt.Errorf("%s: user must be a client identity", p.name)
|
|
}
|
|
|
|
for _, s := range []string{p.e.Filesystem, p.e.Subvolume} {
|
|
if !validName(s) {
|
|
return fmt.Errorf("%s: invalid filesystem or subvolume name", p.name)
|
|
}
|
|
}
|
|
|
|
if p.e.Group != "" && !validName(p.e.Group) {
|
|
return fmt.Errorf("%s: invalid group", p.name)
|
|
}
|
|
|
|
for _, path := range []string{p.e.Config, p.e.Keyring} {
|
|
if !filepath.IsAbs(path) || filepath.Clean(path) != path {
|
|
return fmt.Errorf("%s: paths must be absolute and clean: %q", p.name, path)
|
|
}
|
|
}
|
|
}
|
|
|
|
if c.BandwidthKiB < 0 || c.BandwidthKiB > (1<<63-1)/1024 {
|
|
return errors.New("bandwidth_kib must be nonnegative and fit in bytes per second")
|
|
}
|
|
|
|
return nil
|
|
}
|