From 7c7b107e97aa6bc8328a464fe23b640f39bc5188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 8 Mar 2021 20:57:42 +0100 Subject: [PATCH] Add max-storage flags to storage attach commands --- cmd/lotus-seal-worker/storage.go | 22 ++++++++++++++++++---- cmd/lotus-storage-miner/storage.go | 22 ++++++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/cmd/lotus-seal-worker/storage.go b/cmd/lotus-seal-worker/storage.go index 39cd3ad5a..afb566166 100644 --- a/cmd/lotus-seal-worker/storage.go +++ b/cmd/lotus-seal-worker/storage.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" + "github.com/docker/go-units" "github.com/google/uuid" "github.com/mitchellh/go-homedir" "github.com/urfave/cli/v2" @@ -46,6 +47,10 @@ var storageAttachCmd = &cli.Command{ Name: "store", Usage: "(for init) use path for long-term storage", }, + &cli.StringFlag{ + Name: "max-storage", + Usage: "(for init) limit storage space for sectors (expensive for very large paths!)", + }, }, Action: func(cctx *cli.Context) error { nodeApi, closer, err := lcli.GetWorkerAPI(cctx) @@ -79,11 +84,20 @@ var storageAttachCmd = &cli.Command{ return err } + var maxStor int64 + if cctx.IsSet("max-storage") { + maxStor, err = units.RAMInBytes(cctx.String("max-storage")) + if err != nil { + return xerrors.Errorf("parsing max-storage: %w", err) + } + } + cfg := &stores.LocalStorageMeta{ - ID: stores.ID(uuid.New().String()), - Weight: cctx.Uint64("weight"), - CanSeal: cctx.Bool("seal"), - CanStore: cctx.Bool("store"), + ID: stores.ID(uuid.New().String()), + Weight: cctx.Uint64("weight"), + CanSeal: cctx.Bool("seal"), + CanStore: cctx.Bool("store"), + MaxStorage: uint64(maxStor), } if !(cfg.CanStore || cfg.CanSeal) { diff --git a/cmd/lotus-storage-miner/storage.go b/cmd/lotus-storage-miner/storage.go index e3b699d9e..2f42fd530 100644 --- a/cmd/lotus-storage-miner/storage.go +++ b/cmd/lotus-storage-miner/storage.go @@ -12,6 +12,7 @@ import ( "strings" "time" + "github.com/docker/go-units" "github.com/fatih/color" "github.com/google/uuid" "github.com/mitchellh/go-homedir" @@ -88,6 +89,10 @@ over time Name: "store", Usage: "(for init) use path for long-term storage", }, + &cli.StringFlag{ + Name: "max-storage", + Usage: "(for init) limit storage space for sectors (expensive for very large paths!)", + }, }, Action: func(cctx *cli.Context) error { nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) @@ -121,11 +126,20 @@ over time return err } + var maxStor int64 + if cctx.IsSet("max-storage") { + maxStor, err = units.RAMInBytes(cctx.String("max-storage")) + if err != nil { + return xerrors.Errorf("parsing max-storage: %w", err) + } + } + cfg := &stores.LocalStorageMeta{ - ID: stores.ID(uuid.New().String()), - Weight: cctx.Uint64("weight"), - CanSeal: cctx.Bool("seal"), - CanStore: cctx.Bool("store"), + ID: stores.ID(uuid.New().String()), + Weight: cctx.Uint64("weight"), + CanSeal: cctx.Bool("seal"), + CanStore: cctx.Bool("store"), + MaxStorage: uint64(maxStor), } if !(cfg.CanStore || cfg.CanSeal) {