Skip to content
Snippets Groups Projects
Commit 5d450891 authored by Miek Gieben's avatar Miek Gieben
Browse files

Merge branch 'main' of gitlab.science.ru.nl:cncz/go

parents 3a9c4065 0e73807b
No related branches found
Tags v0.0.24
No related merge requests found
Pipeline #67385 passed
......@@ -7,5 +7,5 @@ func init() { Register(&Always{}, "always") }
type Always struct{}
func (a *Always) OfInterest() []string { return []string{"disk"} }
func (a *Always) Detect(i string) error { return fmt.Errorf("it is kaput") }
func (a *Always) Repair(i string) error { return fmt.Errorf("storage can't be fixed") }
func (a *Always) Detect(_ string) error { return fmt.Errorf("it is kaput") }
func (a *Always) Repair(_ string) error { return fmt.Errorf("storage can't be fixed") }
package repair
import (
"errors"
"context"
"fmt"
"os"
"path/filepath"
"os/exec"
"strings"
"time"
"github.com/bitfield/script"
"go.science.ru.nl/mountinfo"
......@@ -14,8 +15,6 @@ func init() { Register(new(Ceph), "ceph") }
type Ceph struct{}
const testFile = "should-not-exist"
// OfInterest returns the directories where a Ceph filesystem is mounted.
func (c *Ceph) OfInterest() []string {
cephfilter := mountinfo.FSTypeFilter("cephfs")
......@@ -30,18 +29,21 @@ func (c *Ceph) OfInterest() []string {
return roots
}
func (c *Ceph) Detect(i string) error {
dotpath := filepath.Join(i, testFile)
_, err := os.Stat(dotpath)
// if we actually get a file does not exist, it looks like everything is working.
if errors.Is(err, os.ErrNotExist) {
return nil
func (c *Ceph) Detect(mount string) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
err := exec.CommandContext(ctx, "ls", mount).Run()
if err != nil {
if strings.HasPrefix(err.Error(), "signal:") {
// hit our timeout, hanging mount
return err
}
}
return err
return nil
}
func (c *Ceph) Repair(i string) error {
p := script.Exec(fmt.Sprintf("umount -lf %s", i))
func (c *Ceph) Repair(mount string) error {
p := script.Exec(fmt.Sprintf("umount -lf %s", mount))
p.Wait()
if p.ExitStatus() != 0 {
return fmt.Errorf("failed to umount lazily")
......
package repair
import (
"os"
"testing"
)
func TestCeph(t *testing.T) {
c := new(Ceph)
if err := c.Detect("."); err != nil { // should not err, because the file checked for does not exist.
t.Fatalf("expected no error, got %s", err)
}
empty, err := os.Create(testFile)
if err != nil {
t.Fatal(err)
}
empty.Close()
defer os.Remove(testFile)
if err := c.Detect("."); err != nil {
t.Fatalf("expected no error, got %s", err)
}
......
......@@ -5,5 +5,5 @@ func init() { Register(&Noop{}, "noop") }
type Noop struct{}
func (n *Noop) OfInterest() []string { return nil }
func (n *Noop) Detect(i string) error { return nil }
func (n *Noop) Repair(i string) error { return nil }
func (n *Noop) Detect(_ string) error { return nil }
func (n *Noop) Repair(_ string) error { return nil }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment