baremetal: fix ext4 rootfs inode inconsistent

This commit is contained in:
Zexi
2019-08-19 21:27:17 +08:00
parent 1043958d0e
commit 842e33521a
10 changed files with 59 additions and 17 deletions
+3 -1
View File
@@ -1745,7 +1745,9 @@ func (s *SBaremetalServer) deployFs(term *ssh.Client, deployInfo *deployapi.Depl
if err != nil {
return nil, fmt.Errorf("Find rootfs error: %s", err)
}
defer rootDev.Umount()
defer func() {
rootDev.Umount()
}()
if strings.ToLower(rootfs.GetOs()) == "windows" {
return nil, fmt.Errorf("Unsupported OS: %s", rootfs.GetOs())
}
+8
View File
@@ -29,6 +29,7 @@ import (
type IServerBaseDeployTask interface {
IPXEBootTask
DoDeploys(term *ssh.Client) (jsonutils.JSONObject, error)
PostDeploys(term *ssh.Client) error
}
type SBaremetalServerBaseDeployTask struct {
@@ -62,6 +63,10 @@ func (self *SBaremetalServerBaseDeployTask) GetFinishAction() string {
return ""
}
func (self *SBaremetalServerBaseDeployTask) PostDeploys(_ *ssh.Client) error {
return nil
}
func (self *SBaremetalServerBaseDeployTask) OnPXEBoot(ctx context.Context, term *ssh.Client, args interface{}) error {
log.Infof("%s called on stage pxeboot, args: %v", self.GetName(), args)
result, err := self.serverDeployTask.DoDeploys(term)
@@ -75,6 +80,9 @@ func (self *SBaremetalServerBaseDeployTask) OnPXEBoot(ctx context.Context, term
if err != nil {
return errors.Wrap(err, "Sync disk")
}
if err := self.serverDeployTask.PostDeploys(term); err != nil {
return errors.Wrap(err, "post deploy")
}
onFinishAction := self.GetFinishAction()
if utils.IsInStringArray(onFinishAction, []string{"restart", "shutdown"}) {
err = self.EnsurePowerShutdown(false)
+13
View File
@@ -73,6 +73,19 @@ func (self *SBaremetalServerCreateTask) DoDeploys(term *ssh.Client) (jsonutils.J
return data, nil
}
func doPoweroff(term *ssh.Client) error {
if _, err := term.Run("/sbin/poweroff"); err != nil {
log.Errorf("poweroff error: %s", err)
return nil
}
time.Sleep(2 * time.Second)
return nil
}
func (self *SBaremetalServerCreateTask) PostDeploys(term *ssh.Client) error {
return doPoweroff(term)
}
func (self *SBaremetalServerCreateTask) onError(term *ssh.Client, err error) error {
log.Errorf("Create server error: %+v", err)
if err1 := self.Baremetal.GetServer().DoEraseDisk(term); err1 != nil {
+4
View File
@@ -59,3 +59,7 @@ func (self *SBaremetalServerRebuildTask) DoDeploys(term *ssh.Client) (jsonutils.
data.Update(deployInfo)
return data, nil
}
func (self *SBaremetalServerRebuildTask) PostDeploys(term *ssh.Client) error {
return doPoweroff(term)
}
+9 -2
View File
@@ -108,8 +108,7 @@ func (p *Partition) Format(fs string, uuid string) error {
cmdUUID = []string{"/usr/sbin/tune2fs", "-U", uuid}
case "ext4":
// for baremetal, force 64bit support large disks
//cmd = []string{"/usr/sbin/mkfs.ext4", "-O", "64bit", "-E", "lazy_itable_init=1", "-T", "largefile"}
cmd = []string{"/usr/sbin/mkfs.ext4", "-O", "64bit", "-E", "lazy_itable_init=1"}
cmd = []string{"/usr/sbin/mkfs.ext4", "-O", "64bit", "-E", "lazy_itable_init=1", "-T", "largefile"}
cmdUUID = []string{"/usr/sbin/tune2fs", "-U", uuid}
case "ext4dev":
cmd = []string{"/usr/sbin/mkfs.ext4dev", "-E", "lazy_itable_init=1"}
@@ -206,6 +205,10 @@ func (p *Partition) GetSizeMB() (int64, error) {
return p.count * 512 / 1024 / 1024, nil
}
func (p *Partition) GetDisk() *DiskPartitions {
return p.disk
}
type DiskPartitions struct {
driver string
adapter int
@@ -243,6 +246,10 @@ func (p *DiskPartitions) IsRaidDriver() bool {
})
}
func (p *DiskPartitions) GetDev() string {
return p.dev
}
func (p *DiskPartitions) SetInfo(info *types.SDiskInfo) *DiskPartitions {
p.dev = fmt.Sprintf("/dev/%s", info.Dev)
p.devName = info.Dev
+1 -1
View File
@@ -416,4 +416,4 @@ func (self *SSnapshotPolicy) preCheck(
return nil, httperrors.NewNotFoundError("Disks %v not found", notFoundDisks)
}
return diskIds, nil
}
}
+3 -3
View File
@@ -277,16 +277,16 @@ func (l *sLinuxRootFs) DeployStandbyNetworkingScripts(rootFs IDiskPartition, nic
var udevPath = "/etc/udev/rules.d/"
var nicRules string
for _, nic := range nicsStandby {
if len(nic.NicType) == 0 || nic.NicType != "impi" {
if len(nic.NicType) == 0 || nic.NicType != types.NIC_TYPE_IPMI {
nicRules += `KERNEL=="*", SUBSYSTEM=="net", ACTION=="add", `
nicRules += `DRIVERS=="?*", `
mac := nic.Mac
nicRules += fmt.Sprintf(`ATTR{address}=="%s", ATTR{type}=="1", `, strings.ToLower(mac))
idx := nic.Index
nicRules += fmt.Sprintf("NAME=\"eth%d\"\n", idx)
nicRules += fmt.Sprintf(`NAME="eth%d"\n`, idx)
}
}
if err := rootFs.FilePutContents(path.Join(udevPath, "70-persistent-net.rules"), nicRules, false, false); err != nil {
if err := rootFs.FilePutContents(path.Join(udevPath, "70-persistent-net.rules"), nicRules, true, false); err != nil {
return err
}
return nil
+11 -9
View File
@@ -40,13 +40,15 @@ type SSHPartition struct {
term *ssh.Client
partDev string
mountPath string
part *disktool.Partition
}
func NewSSHPartition(term *ssh.Client, dev string) *SSHPartition {
func NewSSHPartition(term *ssh.Client, part *disktool.Partition) *SSHPartition {
p := new(SSHPartition)
p.term = term
p.partDev = dev
p.partDev = part.GetDev()
p.mountPath = fmt.Sprintf("/tmp/%s", strings.Replace(p.partDev, "/", "_", -1))
p.part = part
return p
}
@@ -169,12 +171,17 @@ func (p *SSHPartition) Umount() bool {
"/sbin/sysctl -w vm.drop_caches=3",
fmt.Sprintf("/bin/umount %s", p.mountPath),
fmt.Sprintf("/sbin/hdparm -f %s", p.partDev),
//fmt.Sprintf("/usr/bin/sg_sync %s", p.part.GetDisk().GetDev()),
}
_, err = p.term.Run(cmds...)
if err != nil {
log.Errorf("umount %s error: %v", p.mountPath, err)
time.Sleep(1 * time.Second)
} else {
if err := p.osRmDir(p.mountPath); err != nil {
log.Errorf("remove mount path %s: %v", p.mountPath, err)
return false
}
return true
}
}
@@ -300,11 +307,6 @@ func (p *SSHPartition) sshFilePutContents(sPath, content string, modAppend bool)
op = ">>"
}
if len(content) == 0 {
_, err := p.term.Run(fmt.Sprintf("echo '' %s %s", op, sPath))
return err
}
cmds := []string{}
var chunkSize int = 8192
for offset := 0; offset < len(content); offset += chunkSize {
@@ -316,7 +318,7 @@ func (p *SSHPartition) sshFilePutContents(sPath, content string, modAppend bool)
if err != nil {
return fmt.Errorf("EscapeEchoString %q error: %v", content[offset:end], err)
}
cmd := fmt.Sprintf("echo -n -e \"%s\" %s %s", ll, op, sPath)
cmd := fmt.Sprintf(`echo -n -e "%s" %s %s`, ll, op, sPath)
cmds = append(cmds, cmd)
if op == ">" {
op = ">>"
@@ -534,7 +536,7 @@ func MountSSHRootfs(term *ssh.Client, layouts []baremetal.Layout) (*SSHPartition
return nil, nil, fmt.Errorf("Not found root disk partitions")
}
for _, part := range parts {
dev := NewSSHPartition(term, part.GetDev())
dev := NewSSHPartition(term, part)
if !dev.Mount() {
continue
}
+1 -1
View File
@@ -125,7 +125,7 @@ func (s *Client) run(parseOutput bool, cmds ...string) ([]string, error) {
return nil, err
}
defer session.Close()
log.Debugf("Run command: %q", cmd)
log.Debugf("Run command: %s", cmd)
var stdOut bytes.Buffer
var stdErr bytes.Buffer
session.Stdout = &stdOut
@@ -100,6 +100,12 @@ func TestEscapeEchoString(t *testing.T) {
want: `abcd\n\"Te\\\\rst\"ddd\"\$Test\"aaa\n\$TTT`,
wantErr: false,
},
{
name: "echoInput",
args: args{"SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"1d6b\", ATTRS{idProduct}==\"0001\", RUN+=\"/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup'\""},
want: `SUBSYSTEM==\"usb\", ATTRS{idVendor}==\"1d6b\", ATTRS{idProduct}==\"0001\", RUN+=\"/bin/sh -c 'echo enabled > /sys\$env{DEVPATH}/../power/wakeup'\"`,
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {