Skip to content
This repository has been archived by the owner on Sep 22, 2020. It is now read-only.

Commit

Permalink
Allow size as a percent for torusd. Fixes #175
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Howell committed Jun 18, 2016
1 parent b3dbb8d commit a495353
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions cmd/torusd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"net/url"
"os"
"os/signal"
"strings"
"strconv"
"syscall"

"github.com/coreos/pkg/capnslog"
"github.com/dustin/go-humanize"
Expand Down Expand Up @@ -110,10 +113,34 @@ func configureServer(cmd *cobra.Command, args []string) {
fmt.Fprintf(os.Stderr, "error parsing read-cache-size: %s\n", err)
os.Exit(1)
}
size, err = humanize.ParseBytes(sizeStr)
if err != nil {
fmt.Fprintf(os.Stderr, "error parsing size: %s\n", err)
os.Exit(1)
if strings.Contains(sizeStr, "%") {
var stat syscall.Statfs_t
sizePercent := strings.Split(sizeStr, "%")[0]
sizeNumber, err := strconv.Atoi(sizePercent)
if err != nil {
fmt.Fprintf(os.Stderr, "error parsing size: %s\n", err)
os.Exit(1)
}
if sizeNumber < 1 || sizeNumber > 100 {
fmt.Fprintf(os.Stderr, "invalid size; must be between 1%% and 100%%\n")
os.Exit(1)
}
directory := dataDir
if dataDir == "" {
directory, _ = os.Getwd()
}
err = syscall.Statfs(directory, &stat)
if err != nil {
fmt.Fprintf(os.Stderr, "error getting volume for data-dir: %s\n", directory)
os.Exit(1)
}
size = stat.Blocks * uint64(stat.Bsize) * uint64(sizeNumber) / 100
} else {
size, err = humanize.ParseBytes(sizeStr)
if err != nil {
fmt.Fprintf(os.Stderr, "error parsing size: %s\n", err)
os.Exit(1)
}
}

var rl torus.ReadLevel
Expand Down

0 comments on commit a495353

Please sign in to comment.