1
0
mirror of https://github.com/rancher/os.git synced 2025-08-01 23:17:50 +00:00

find fs type of device automatically

This commit is contained in:
sidharthamani 2015-02-12 14:34:16 -08:00
parent 34b3057909
commit 70b376ce6a
3 changed files with 53 additions and 9 deletions

View File

@ -82,7 +82,7 @@ func NewConfig() *Config {
ImagesPattern: "images*.tar",
StateRequired: false,
StateDev: "LABEL=RANCHER_STATE",
StateDevFSType: "ext4",
StateDevFSType: "auto",
SysInit: "/sbin/init-sys",
SystemDockerArgs: []string{"docker", "-d", "-s", "overlay", "-b", "none"},
UserInit: "/sbin/init-user",

View File

@ -213,12 +213,31 @@ func MainInit() {
func mountState(cfg *config.Config) error {
var err error
if len(cfg.StateDev) == 0 {
log.Debugf("State will not be persisted")
err = util.Mount("none", STATE, "tmpfs", "")
} else {
log.Debugf("Mounting state device %s", cfg.StateDev)
err = util.Mount(cfg.StateDev, STATE, cfg.StateDevFSType, "")
dev := util.ResolveDevice(cfg.StateDev)
log.Debugf("Mounting state device %s", dev)
fsType := cfg.StateDevFSType
log.Debugf("FsType has been set to %s", fsType)
if fsType == "auto" {
actualFsType, fsErr := util.GetFsType(dev)
if fsErr != nil {
return fsErr
}
fsType = actualFsType
}
err = util.Mount(dev, STATE, fsType, "")
if err != nil {
if cfg.StateRequired {
return err
} else {
log.Debugf("State will not be persisted")
err = util.Mount("none", STATE, "tmpfs", "")
if err != nil {
return err
}
}
}
if err != nil {

View File

@ -1,16 +1,41 @@
package util
/*
#cgo LDFLAGS: -lblkid -luuid
#cgo LDFLAGS: -lmount -lblkid -luuid
#include<blkid/blkid.h>
#include<libmount/libmount.h>
#include<stdlib.h>
*/
import "C"
import "unsafe"
import (
"errors"
)
func ResolveDevice(spec string) string {
cString := C.blkid_evaluate_spec(C.CString(spec), nil)
cSpec := C.CString(spec)
defer C.free(unsafe.Pointer(cSpec))
cString := C.blkid_evaluate_spec(cSpec, nil)
defer C.free(unsafe.Pointer(cString))
return C.GoString(cString)
}
func GetFsType(device string) (string, error) {
var ambi * C.int
cDevice := C.CString(device)
defer C.free(unsafe.Pointer(cDevice))
cString := C.mnt_get_fstype(cDevice, ambi, nil)
defer C.free(unsafe.Pointer(cString))
if cString != nil {
return C.GoString(cString), nil
}
return "", errors.New("Error while getting fstype")
}
func intToBool(value C.int) bool {
if value == 0 {
return false
}
return true
}