Skip to content

Commit

Permalink
Merge pull request #1365 from filecoin-project/feat/miner-storage-add
Browse files Browse the repository at this point in the history
 storageminer: 'storage attach' command
  • Loading branch information
magik6k authored Mar 9, 2020
2 parents c101428 + 0b14ab8 commit 6981cfb
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/lotus-fountain/site/wait.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Sending Funds - Lotus Fountain</title>
<title>Creating Storage Miner (wait) - Lotus Fountain</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-storage-miner/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ var initCmd = &cli.Command{
}

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)
return xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(lr.Path(), "sectorstore.json"), err)
}

sc.StoragePaths = append(sc.StoragePaths, config.LocalPath{
Expand Down
1 change: 1 addition & 0 deletions cmd/lotus-storage-miner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func main() {
rewardsCmd,
runCmd,
sectorsCmd,
storageCmd,
setPriceCmd,
}
jaeger := tracing.SetupJaegerTracing("lotus")
Expand Down
99 changes: 99 additions & 0 deletions cmd/lotus-storage-miner/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package main

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"

"github.com/google/uuid"
"github.com/mitchellh/go-homedir"
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"

lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/node/config"
)

const metaFile = "sectorstore.json"

var storageCmd = &cli.Command{
Name: "storage",
Usage: "manage sector storage",
Subcommands: []*cli.Command{
storageAttachCmd,
},
}

var storageAttachCmd = &cli.Command{
Name: "attach",
Usage: "attach local storage path",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "init",
Usage: "initialize the path first",
},
&cli.Uint64Flag{
Name: "weight",
Usage: "(for init) path weight",
Value: 10,
},
&cli.BoolFlag{
Name: "seal",
Usage: "(for init) use path for sealing",
},
&cli.BoolFlag{
Name: "store",
Usage: "(for init) use path for long-term storage",
},
},
Action: func(cctx *cli.Context) error {
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)

if !cctx.Args().Present() {
return xerrors.Errorf("must specify storage path to attach")
}

p, err := homedir.Expand(cctx.Args().First())
if err != nil {
return xerrors.Errorf("expanding path: %w", err)
}

if cctx.Bool("init") {
_, err := os.Stat(filepath.Join(p, metaFile))
if !os.IsNotExist(err) {
if err == nil {
return xerrors.Errorf("path is already initialized")
}
return err
}

cfg := &config.StorageMeta{
ID: uuid.New().String(),
Weight: cctx.Uint64("weight"),
CanSeal: cctx.Bool("seal"),
CanStore: cctx.Bool("store"),
}

if !(cfg.CanStore || cfg.CanSeal) {
return xerrors.Errorf("must specify at least one of --store of --seal")
}

b, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return xerrors.Errorf("marshaling storage config: %w", err)
}

if err := ioutil.WriteFile(filepath.Join(p, metaFile), b, 0644); err != nil {
return xerrors.Errorf("persisting storage metadata (%s): %w", filepath.Join(p, metaFile), err)
}
}

return nodeApi.StorageAddLocal(ctx, p)
},
}
16 changes: 11 additions & 5 deletions node/repo/memrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,22 @@ type lockedMemRepo struct {

tempDir string
token *byte
sc *config.StorageConfig
}

func (lmem *lockedMemRepo) GetStorage() (config.StorageConfig, error) {
return config.StorageConfig{StoragePaths: []config.LocalPath{
{Path: lmem.Path()},
}}, nil
if lmem.sc == nil {
lmem.sc = &config.StorageConfig{StoragePaths: []config.LocalPath{
{Path: lmem.Path()},
}}
}

return *lmem.sc, nil
}

func (lmem *lockedMemRepo) SetStorage(config.StorageConfig) error {
panic("implement me")
func (lmem *lockedMemRepo) SetStorage(sc config.StorageConfig) error {
lmem.sc = &sc
return nil
}

func (lmem *lockedMemRepo) Path() string {
Expand Down
6 changes: 6 additions & 0 deletions storage/sealmgr/advmgr/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,18 @@ func (m *Manager) AddLocalStorage(path string) error {
return xerrors.Errorf("opening local path: %w", err)
}

// TODO: Locks!

sc, err := m.storage.localStorage.GetStorage()
if err != nil {
return xerrors.Errorf("get storage config: %w", err)
}

sc.StoragePaths = append(sc.StoragePaths, config.LocalPath{Path: path})

if err := m.storage.localStorage.SetStorage(sc); err != nil {
return xerrors.Errorf("get storage config: %w", err)
}
return nil
}

Expand Down

0 comments on commit 6981cfb

Please sign in to comment.