diff --git a/api/api_worker.go b/api/api_worker.go index 77c22a517..609cb4271 100644 --- a/api/api_worker.go +++ b/api/api_worker.go @@ -62,6 +62,7 @@ type Worker interface { StorageLocal(ctx context.Context) (map[storiface.ID]string, error) //perm:admin StorageAddLocal(ctx context.Context, path string) error //perm:admin StorageDetachLocal(ctx context.Context, path string) error //perm:admin + StorageDetachAll(ctx context.Context) error //perm:admin StorageRedeclareLocal(ctx context.Context, id *storiface.ID, dropMissing bool) error //perm:admin // SetEnabled marks the worker as enabled/disabled. Not that this setting diff --git a/api/proxy_gen.go b/api/proxy_gen.go index 1520a5111..64855ab0f 100644 --- a/api/proxy_gen.go +++ b/api/proxy_gen.go @@ -981,6 +981,8 @@ type WorkerStruct struct { StorageAddLocal func(p0 context.Context, p1 string) error `perm:"admin"` + StorageDetachAll func(p0 context.Context) error `perm:"admin"` + StorageDetachLocal func(p0 context.Context, p1 string) error `perm:"admin"` StorageLocal func(p0 context.Context) (map[storiface.ID]string, error) `perm:"admin"` @@ -5668,6 +5670,17 @@ func (s *WorkerStub) StorageAddLocal(p0 context.Context, p1 string) error { return ErrNotSupported } +func (s *WorkerStruct) StorageDetachAll(p0 context.Context) error { + if s.Internal.StorageDetachAll == nil { + return ErrNotSupported + } + return s.Internal.StorageDetachAll(p0) +} + +func (s *WorkerStub) StorageDetachAll(p0 context.Context) error { + return ErrNotSupported +} + func (s *WorkerStruct) StorageDetachLocal(p0 context.Context, p1 string) error { if s.Internal.StorageDetachLocal == nil { return ErrNotSupported diff --git a/build/openrpc/full.json.gz b/build/openrpc/full.json.gz index 24842baa0..fb9fd4e66 100644 Binary files a/build/openrpc/full.json.gz and b/build/openrpc/full.json.gz differ diff --git a/build/openrpc/gateway.json.gz b/build/openrpc/gateway.json.gz index f4f0d3762..3db11ade1 100644 Binary files a/build/openrpc/gateway.json.gz and b/build/openrpc/gateway.json.gz differ diff --git a/build/openrpc/miner.json.gz b/build/openrpc/miner.json.gz index f448d05eb..7177e4f07 100644 Binary files a/build/openrpc/miner.json.gz and b/build/openrpc/miner.json.gz differ diff --git a/build/openrpc/worker.json.gz b/build/openrpc/worker.json.gz index 193c9f056..c2201b2df 100644 Binary files a/build/openrpc/worker.json.gz and b/build/openrpc/worker.json.gz differ diff --git a/cmd/lotus-worker/main.go b/cmd/lotus-worker/main.go index de8e63f1f..353641264 100644 --- a/cmd/lotus-worker/main.go +++ b/cmd/lotus-worker/main.go @@ -129,6 +129,10 @@ var stopCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) + + // Detach any storage associated with this worker + api.StorageDetachAll(ctx) + err = api.Shutdown(ctx) if err != nil { return err diff --git a/cmd/lotus-worker/sealworker/rpc.go b/cmd/lotus-worker/sealworker/rpc.go index fc4354874..613a58081 100644 --- a/cmd/lotus-worker/sealworker/rpc.go +++ b/cmd/lotus-worker/sealworker/rpc.go @@ -146,6 +146,20 @@ func (w *Worker) StorageDetachLocal(ctx context.Context, path string) error { return w.LocalStore.ClosePath(ctx, localPath.ID) } +func (w *Worker) StorageDetachAll(ctx context.Context) error { + + lps, err := w.LocalStore.Local(ctx) + if err != nil { + return xerrors.Errorf("getting local path list: %w", err) + } + + for _, lp := range lps { + w.LocalStore.ClosePath(ctx, lp.ID) + } + + return nil +} + func (w *Worker) StorageRedeclareLocal(ctx context.Context, id *storiface.ID, dropMissing bool) error { return w.LocalStore.Redeclare(ctx, id, dropMissing) } diff --git a/documentation/en/api-v0-methods-worker.md b/documentation/en/api-v0-methods-worker.md index ca98bc4bb..0889a9b3c 100644 --- a/documentation/en/api-v0-methods-worker.md +++ b/documentation/en/api-v0-methods-worker.md @@ -39,6 +39,7 @@ * [SetEnabled](#SetEnabled) * [Storage](#Storage) * [StorageAddLocal](#StorageAddLocal) + * [StorageDetachAll](#StorageDetachAll) * [StorageDetachLocal](#StorageDetachLocal) * [StorageLocal](#StorageLocal) * [StorageRedeclareLocal](#StorageRedeclareLocal) @@ -2121,6 +2122,15 @@ Inputs: Response: `{}` +### StorageDetachAll + + +Perms: admin + +Inputs: `null` + +Response: `{}` + ### StorageDetachLocal