@@ -15,6 +15,7 @@ import (
1515 "time"
1616
1717 dockertypes "github.com/docker/engine-api/types"
18+ "github.com/docker/go-units"
1819 "github.com/golang/glog"
1920 "github.com/hyperhq/hyperd/daemon/daemondb"
2021 "github.com/hyperhq/hyperd/storage"
@@ -105,8 +106,12 @@ func (dms *DevMapperStorage) RootPath() string {
105106
106107func (dms * DevMapperStorage ) Init (c * apitypes.HyperConfig ) error {
107108 size := storage .DEFAULT_DM_POOL_SIZE
108- if c .StorageBaseSize > 0 {
109- size = c .StorageBaseSize
109+ if c .StorageBaseSize != "" {
110+ nsize , err := units .RAMInBytes (c .StorageBaseSize )
111+ if err != nil {
112+ return err
113+ }
114+ size = int (nsize )
110115 }
111116 dmPool := dm.DeviceMapper {
112117 Datafile : filepath .Join (utils .HYPER_ROOT , "lib" ) + "/data" ,
@@ -205,7 +210,7 @@ func (dms *DevMapperStorage) CreateVolume(podId string, spec *apitypes.UserVolum
205210 }
206211 dev_id_str := strconv .Itoa (dev_id )
207212
208- err = dm .CreateVolume (dms .VolPoolName , deviceName , dev_id_str , storage .DEFAULT_VOL_MKFS , storage . DEFAULT_DM_VOL_SIZE , restore )
213+ err = dm .CreateVolume (dms .VolPoolName , deviceName , dev_id_str , storage .DEFAULT_VOL_MKFS , dms . DmPoolData . Size , restore )
209214 if err != nil && ! restore && strings .Contains (err .Error (), "failed: File exists" ) {
210215 glog .V (1 ).Infof ("retry for dev_id #%d creating collision: %v" , dev_id , err )
211216 continue
@@ -501,6 +506,7 @@ func (s *BtrfsStorage) RemoveVolume(podId string, record []byte) error {
501506
502507type RawBlockStorage struct {
503508 rootPath string
509+ size int64
504510}
505511
506512func RawBlockFactory (_ * dockertypes.Info , _ * daemondb.DaemonDB ) (Storage , error ) {
@@ -519,9 +525,21 @@ func (s *RawBlockStorage) RootPath() string {
519525}
520526
521527func (s * RawBlockStorage ) Init (c * apitypes.HyperConfig ) error {
522- 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 {
523530 return err
524531 }
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+
525543 return nil
526544}
527545
@@ -555,7 +573,7 @@ func (s *RawBlockStorage) InjectFile(src io.Reader, mountId, target, baseDir str
555573
556574func (s * RawBlockStorage ) CreateVolume (podId string , spec * apitypes.UserVolume ) error {
557575 block := filepath .Join (s .RootPath (), "volumes" , fmt .Sprintf ("%s-%s" , podId , spec .Name ))
558- 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 {
559577 return err
560578 }
561579 spec .Source = block
0 commit comments