mirror of
https://github.com/rancher/os.git
synced 2025-08-12 12:02:22 +00:00
find fs type of device automatically
This commit is contained in:
parent
34b3057909
commit
70b376ce6a
@ -82,7 +82,7 @@ func NewConfig() *Config {
|
|||||||
ImagesPattern: "images*.tar",
|
ImagesPattern: "images*.tar",
|
||||||
StateRequired: false,
|
StateRequired: false,
|
||||||
StateDev: "LABEL=RANCHER_STATE",
|
StateDev: "LABEL=RANCHER_STATE",
|
||||||
StateDevFSType: "ext4",
|
StateDevFSType: "auto",
|
||||||
SysInit: "/sbin/init-sys",
|
SysInit: "/sbin/init-sys",
|
||||||
SystemDockerArgs: []string{"docker", "-d", "-s", "overlay", "-b", "none"},
|
SystemDockerArgs: []string{"docker", "-d", "-s", "overlay", "-b", "none"},
|
||||||
UserInit: "/sbin/init-user",
|
UserInit: "/sbin/init-user",
|
||||||
|
31
init/init.go
31
init/init.go
@ -213,12 +213,31 @@ func MainInit() {
|
|||||||
|
|
||||||
func mountState(cfg *config.Config) error {
|
func mountState(cfg *config.Config) error {
|
||||||
var err error
|
var err error
|
||||||
if len(cfg.StateDev) == 0 {
|
|
||||||
log.Debugf("State will not be persisted")
|
dev := util.ResolveDevice(cfg.StateDev)
|
||||||
err = util.Mount("none", STATE, "tmpfs", "")
|
log.Debugf("Mounting state device %s", dev)
|
||||||
} else {
|
|
||||||
log.Debugf("Mounting state device %s", cfg.StateDev)
|
fsType := cfg.StateDevFSType
|
||||||
err = util.Mount(cfg.StateDev, STATE, 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 {
|
if err != nil {
|
||||||
|
@ -1,16 +1,41 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo LDFLAGS: -lblkid -luuid
|
#cgo LDFLAGS: -lmount -lblkid -luuid
|
||||||
#include<blkid/blkid.h>
|
#include<blkid/blkid.h>
|
||||||
|
#include<libmount/libmount.h>
|
||||||
#include<stdlib.h>
|
#include<stdlib.h>
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
func ResolveDevice(spec string) string {
|
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))
|
defer C.free(unsafe.Pointer(cString))
|
||||||
return C.GoString(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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user