diff --git a/api/api_storage.go b/api/api_storage.go index 8cca2aa5b..4e09ecfa5 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -145,6 +145,7 @@ type StorageMiner interface { StorageLock(ctx context.Context, sector abi.SectorID, read storiface.SectorFileType, write storiface.SectorFileType) error //perm:admin StorageTryLock(ctx context.Context, sector abi.SectorID, read storiface.SectorFileType, write storiface.SectorFileType) (bool, error) //perm:admin StorageList(ctx context.Context) (map[stores.ID][]stores.Decl, error) //perm:admin + StorageGetLocks(ctx context.Context) (storiface.SectorLocks, error) //perm:admin StorageLocal(ctx context.Context) (map[stores.ID]string, error) //perm:admin StorageStat(ctx context.Context, id stores.ID) (fsutil.FsStat, error) //perm:admin diff --git a/api/docgen/docgen.go b/api/docgen/docgen.go index 5478e5ea6..5d87e9d20 100644 --- a/api/docgen/docgen.go +++ b/api/docgen/docgen.go @@ -254,6 +254,13 @@ func init() { api.SectorState(sealing.Proving): 120, }) addExample([]abi.SectorNumber{123, 124}) + addExample([]storiface.SectorLock{ + { + Sector: abi.SectorID{Number: 123, Miner: 1000}, + Write: [storiface.FileTypes]uint{0, 0, 1}, + Read: [storiface.FileTypes]uint{2, 3, 0}, + }, + }) // worker specific addExample(storiface.AcquireMove) diff --git a/api/proxy_gen.go b/api/proxy_gen.go index feb08531f..88ff4cd15 100644 --- a/api/proxy_gen.go +++ b/api/proxy_gen.go @@ -794,6 +794,8 @@ type StorageMinerStruct struct { StorageFindSector func(p0 context.Context, p1 abi.SectorID, p2 storiface.SectorFileType, p3 abi.SectorSize, p4 bool) ([]stores.SectorStorageInfo, error) `perm:"admin"` + StorageGetLocks func(p0 context.Context) (storiface.SectorLocks, error) `perm:"admin"` + StorageInfo func(p0 context.Context, p1 stores.ID) (stores.StorageInfo, error) `perm:"admin"` StorageList func(p0 context.Context) (map[stores.ID][]stores.Decl, error) `perm:"admin"` @@ -4647,6 +4649,17 @@ func (s *StorageMinerStub) StorageFindSector(p0 context.Context, p1 abi.SectorID return *new([]stores.SectorStorageInfo), ErrNotSupported } +func (s *StorageMinerStruct) StorageGetLocks(p0 context.Context) (storiface.SectorLocks, error) { + if s.Internal.StorageGetLocks == nil { + return *new(storiface.SectorLocks), ErrNotSupported + } + return s.Internal.StorageGetLocks(p0) +} + +func (s *StorageMinerStub) StorageGetLocks(p0 context.Context) (storiface.SectorLocks, error) { + return *new(storiface.SectorLocks), ErrNotSupported +} + func (s *StorageMinerStruct) StorageInfo(p0 context.Context, p1 stores.ID) (stores.StorageInfo, error) { if s.Internal.StorageInfo == nil { return *new(stores.StorageInfo), ErrNotSupported diff --git a/build/openrpc/full.json.gz b/build/openrpc/full.json.gz index 7d44a46a0..e39ebc6a2 100644 Binary files a/build/openrpc/full.json.gz and b/build/openrpc/full.json.gz differ diff --git a/build/openrpc/miner.json.gz b/build/openrpc/miner.json.gz index 571159054..e09ecdcb5 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 83d951047..f5cbf4b84 100644 Binary files a/build/openrpc/worker.json.gz and b/build/openrpc/worker.json.gz differ diff --git a/cmd/lotus-miner/storage.go b/cmd/lotus-miner/storage.go index 4df6a9904..6f7a627f6 100644 --- a/cmd/lotus-miner/storage.go +++ b/cmd/lotus-miner/storage.go @@ -48,6 +48,7 @@ stored while moving through the sealing pipeline (references as 'seal').`, storageListCmd, storageFindCmd, storageCleanupCmd, + storageLocks, }, } @@ -758,3 +759,43 @@ func cleanupRemovedSectorData(ctx context.Context, api api.StorageMiner, napi v0 return nil } + +var storageLocks = &cli.Command{ + Name: "locks", + Usage: "show active sector locks", + Action: func(cctx *cli.Context) error { + api, closer, err := lcli.GetStorageMinerAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := lcli.ReqContext(cctx) + + locks, err := api.StorageGetLocks(ctx) + if err != nil { + return err + } + + for _, lock := range locks.Locks { + st, err := api.SectorsStatus(ctx, lock.Sector.Number, false) + if err != nil { + return xerrors.Errorf("getting sector status(%d): %w", lock.Sector.Number, err) + } + + lockstr := fmt.Sprintf("%d\t%s\t", lock.Sector.Number, color.New(stateOrder[sealing.SectorState(st.State)].col).Sprint(st.State)) + + for i := 0; i < storiface.FileTypes; i++ { + if lock.Write[i] > 0 { + lockstr += fmt.Sprintf("%s(%s) ", storiface.SectorFileType(1< 0 { + lockstr += fmt.Sprintf("%s(%s:%d) ", storiface.SectorFileType(1<