storageminer: Init with default local storage

This commit is contained in:
Łukasz Magiera 2020-03-05 02:12:52 +01:00
parent 7db1dd52bd
commit c91d970c41
4 changed files with 51 additions and 13 deletions

View File

@ -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)
}
}

View File

@ -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,15 +163,17 @@ 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
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 {
@ -175,6 +183,27 @@ var initCmd = &cli.Command{
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)

View File

@ -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, ..., )

View File

@ -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)
}