diff --git a/cmd/lotus-seed/seed/seed.go b/cmd/lotus-seed/seed/seed.go index 3a55eeac3..74804d938 100644 --- a/cmd/lotus-seed/seed/seed.go +++ b/cmd/lotus-seed/seed/seed.go @@ -145,7 +145,7 @@ func PreSeal(maddr address.Address, pt abi.RegisteredProof, offset abi.SectorNum return nil, nil, xerrors.Errorf("marshaling storage config: %w", err) } - if err := ioutil.WriteFile(filepath.Join(sbroot, "storage.json"), b, 0644); err != nil { + if err := ioutil.WriteFile(filepath.Join(sbroot, "sectorstore.json"), b, 0644); err != nil { return nil, nil, xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(sbroot, "storage.json"), err) } } diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index bb88e5427..c2781f714 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -8,6 +8,7 @@ import ( "fmt" "io/ioutil" "os" + "path/filepath" "strconv" "github.com/filecoin-project/go-sectorbuilder" @@ -16,6 +17,7 @@ import ( miner2 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/builtin/power" crypto2 "github.com/filecoin-project/specs-actors/actors/crypto" + "github.com/google/uuid" "github.com/filecoin-project/go-address" cborutil "github.com/filecoin-project/go-cbor-util" @@ -91,6 +93,10 @@ var initCmd = &cli.Command{ Name: "symlink-imported-sectors", Usage: "attempt to symlink to presealed sectors instead of copying them into place", }, + &cli.BoolFlag{ + Name: "no-local-storage", + Usage: "don't use storageminer repo for sector storage", + }, }, Action: func(cctx *cli.Context) error { log.Info("Initializing lotus storage miner") @@ -157,25 +163,48 @@ var initCmd = &cli.Command{ return err } - if pssb := cctx.StringSlice("pre-sealed-sectors"); len(pssb) != 0 { - log.Infof("Setting up storage config with presealed sector", pssb) - + { lr, err := r.Lock(repo.StorageMiner) if err != nil { return err } + var sc config.StorageConfig - for _, psp := range pssb { - psp, err := homedir.Expand(psp) - if err != nil { - return err + if pssb := cctx.StringSlice("pre-sealed-sectors"); len(pssb) != 0 { + log.Infof("Setting up storage config with presealed sector", pssb) + + for _, psp := range pssb { + psp, err := homedir.Expand(psp) + if err != nil { + return err + } + sc.StoragePaths = append(sc.StoragePaths, config.LocalPath{ + Path: psp, + }) } - sc.StoragePaths = append(sc.StoragePaths, config.LocalPath{ - Path: psp, - }) } + if !cctx.Bool("no-local-storage") { + b, err := json.MarshalIndent(&config.StorageMeta{ + ID: uuid.New().String(), + Weight: 10, + CanSeal: true, + CanStore: true, + }, "", " ") + if err != nil { + return xerrors.Errorf("marshaling storage config: %w", err) + } + + if err := ioutil.WriteFile(filepath.Join(lr.Path(), "sectorstore.json"), b, 0644); err != nil { + return xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(lr.Path(), "storage.json"), err) + } + } + + sc.StoragePaths = append(sc.StoragePaths, config.LocalPath{ + Path: lr.Path(), + }) + if err := lr.SetStorage(sc); err != nil { return xerrors.Errorf("set storage config: %w", err) } @@ -185,6 +214,7 @@ var initCmd = &cli.Command{ } } + if err := storageMinerInit(ctx, cctx, api, r, ssize); err != nil { log.Errorf("Failed to initialize lotus-storage-miner: %+v", err) path, err := homedir.Expand(repoPath) diff --git a/storage/sealmgr/advmgr/manager.go b/storage/sealmgr/advmgr/manager.go index 1207b786f..712c65a8c 100644 --- a/storage/sealmgr/advmgr/manager.go +++ b/storage/sealmgr/advmgr/manager.go @@ -140,7 +140,7 @@ func (m *Manager) AddPiece(ctx context.Context, sz abi.UnpaddedPieceSize, sn abi } if len(candidateWorkers) == 0 { - return abi.PieceInfo{}, xerrors.New("no worker selected") + return abi.PieceInfo{}, xerrors.New("no worker found") } // TODO: schedule(addpiece, ..., ) diff --git a/storage/sealmgr/advmgr/storage.go b/storage/sealmgr/advmgr/storage.go index c593c7a20..e392c1b3b 100644 --- a/storage/sealmgr/advmgr/storage.go +++ b/storage/sealmgr/advmgr/storage.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "io/ioutil" + "os" "path/filepath" "sync" @@ -15,7 +16,7 @@ import ( "github.com/filecoin-project/lotus/node/config" ) -const metaFile = "storage.json" +const metaFile = "sectorstore.json" var pathTypes = []sectorbuilder.SectorFileType{sectorbuilder.FTUnsealed, sectorbuilder.FTSealed, sectorbuilder.FTCache} type storage struct { @@ -42,6 +43,13 @@ func openPath(p string, meta config.StorageMeta) (path, error) { for _, t := range pathTypes { ents, err := ioutil.ReadDir(filepath.Join(p, t.String())) if err != nil { + if os.IsNotExist(err) { + if err := os.MkdirAll(filepath.Join(p, t.String()), 0755); err != nil { + return path{}, xerrors.Errorf("mkdir '%s': %w", filepath.Join(p, t.String()), err) + } + + continue + } return path{}, xerrors.Errorf("listing %s: %w", filepath.Join(p, t.String()), err) }