Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit c50b22d

Browse files
committed
rawblock: support configurable rootfs/volume size
Signed-off-by: Peng Tao <bergwolf@gmail.com>
1 parent f906895 commit c50b22d

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

daemon/daemon.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,12 @@ func InitDockerCfg(mirrors []string, insecureRegistries []string, graphdriver, b
172172
dockerCfg.GraphDriver = graphdriver
173173
dockerCfg.Root = root
174174
dockerCfg.TrustKeyPath = path.Join(root, "keys")
175-
if graphdriver == "devicemapper" && basesize != "" {
176-
dockerCfg.GraphOptions = append(dockerCfg.GraphOptions, fmt.Sprintf("dm.basesize=%s", basesize))
175+
if basesize != "" {
176+
if graphdriver == "devicemapper" {
177+
dockerCfg.GraphOptions = append(dockerCfg.GraphOptions, fmt.Sprintf("dm.basesize=%s", basesize))
178+
} else if graphdriver == "rawblock" {
179+
dockerCfg.GraphOptions = append(dockerCfg.GraphOptions, fmt.Sprintf("rawblock.basesize=%s", basesize))
180+
}
177181
}
178182

179183
// disable docker network

daemon/storage.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ func (s *BtrfsStorage) RemoveVolume(podId string, record []byte) error {
506506

507507
type RawBlockStorage struct {
508508
rootPath string
509+
size int64
509510
}
510511

511512
func RawBlockFactory(_ *dockertypes.Info, _ *daemondb.DaemonDB) (Storage, error) {
@@ -524,9 +525,21 @@ func (s *RawBlockStorage) RootPath() string {
524525
}
525526

526527
func (s *RawBlockStorage) Init(c *apitypes.HyperConfig) error {
527-
if err := os.MkdirAll(filepath.Join(s.RootPath(), "volumes"), 0700); err != nil {
528+
err := os.MkdirAll(filepath.Join(s.RootPath(), "volumes"), 0700)
529+
if err != nil {
528530
return err
529531
}
532+
533+
size := int64(storage.DEFAULT_DM_VOL_SIZE)
534+
if c.StorageBaseSize != "" {
535+
size, err = units.RAMInBytes(c.StorageBaseSize)
536+
if err != nil {
537+
return err
538+
}
539+
}
540+
541+
s.size = size
542+
530543
return nil
531544
}
532545

@@ -560,7 +573,7 @@ func (s *RawBlockStorage) InjectFile(src io.Reader, mountId, target, baseDir str
560573

561574
func (s *RawBlockStorage) CreateVolume(podId string, spec *apitypes.UserVolume) error {
562575
block := filepath.Join(s.RootPath(), "volumes", fmt.Sprintf("%s-%s", podId, spec.Name))
563-
if err := rawblock.CreateBlock(block, "xfs", "", uint64(storage.DEFAULT_DM_VOL_SIZE)); err != nil {
576+
if err := rawblock.CreateBlock(block, "xfs", "", uint64(s.size)); err != nil {
564577
return err
565578
}
566579
spec.Source = block

storage/graphdriver/rawblock/driver.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import (
55
"os"
66
"os/exec"
77
"path/filepath"
8+
"strings"
89
"sync"
910

1011
"github.com/docker/docker/daemon/graphdriver"
1112
"github.com/docker/docker/pkg/idtools"
13+
"github.com/docker/docker/pkg/parsers"
14+
"github.com/docker/go-units"
1215
"github.com/golang/glog"
1316
"github.com/opencontainers/runc/libcontainer/label"
1417
//"github.com/docker/docker/pkg/mount"
@@ -88,12 +91,31 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
8891
return nil, err
8992
}
9093

94+
var blockSize = uint64(10 * 1024 * 1024 * 1024)
95+
for _, option := range options {
96+
key, val, err := parsers.ParseKeyValueOpt(option)
97+
if err != nil {
98+
return nil, err
99+
}
100+
key = strings.ToLower(key)
101+
switch key {
102+
case "rawblock.basesize":
103+
size, err := units.RAMInBytes(val)
104+
if err != nil {
105+
return nil, err
106+
}
107+
blockSize = uint64(size)
108+
default:
109+
return nil, fmt.Errorf("rawblock: Unknown option %s\n", key)
110+
}
111+
}
112+
91113
d := &Driver{
92114
home: home,
93115
backingFs: backingFs,
94116
cow: cow,
95117
blockFs: blockFs,
96-
blockSize: 10, // TODO: make it configurable
118+
blockSize: blockSize,
97119
uid: rootUID,
98120
gid: rootGID,
99121
active: map[string]int{},
@@ -111,7 +133,7 @@ func (d *Driver) Status() [][2]string {
111133
{"Backing Filesystem", d.backingFs},
112134
{"Support Copy-On-Write", fmt.Sprintf("%v", d.cow)},
113135
{"Block Filesystem", d.blockFs},
114-
{"Block Size", fmt.Sprintf("%dGB", d.blockSize)},
136+
{"Block Size", fmt.Sprintf("%s", units.HumanSize(float64(d.blockSize)))},
115137
}
116138
}
117139

@@ -131,7 +153,7 @@ func (d *Driver) Create(id, parent, mountLabel string) error {
131153
return err
132154
}
133155
if parent == "" {
134-
return CreateBlock(d.block(id), d.blockFs, mountLabel, d.blockSize*1024*1024*1024)
156+
return CreateBlock(d.block(id), d.blockFs, mountLabel, d.blockSize)
135157
}
136158
if out, err := exec.Command("cp", "-a", "--reflink=auto", d.block(parent), d.block(id)).CombinedOutput(); err != nil {
137159
return fmt.Errorf("Failed to reflink:%v:%s", err, string(out))

0 commit comments

Comments
 (0)