Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

providers/qemu: support Ignition block device on s390x and ppc64le #936

Merged
merged 2 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
# Canonical version of this in https://github.com/coreos/coreos-assembler/blob/6eb97016f4dab7d13aa00ae10846f26c1cd1cb02/Makefile#L19
GOARCH:=$(shell uname -m)
ifeq ($(GOARCH),x86_64)
GOARCH=amd64
else ifeq ($(GOARCH),aarch64)
GOARCH=arm64
endif

.PHONY: all
all:
./build

# This currently assumes you're using https://github.com/coreos/ignition-dracut/
# If in the future any other initramfs integration appears, feel free to add a PR
# to make this configurable.
.PHONY: install
install: all
install -m 0755 -D -t $(DESTDIR)/usr/lib/dracut/modules.d/30ignition bin/$(GOARCH)/ignition
install -m 0755 -D -t $(DESTDIR)/usr/bin bin/$(GOARCH)/ignition-validate

.PHONY: vendor
vendor:
@glide --quiet update --strip-vendor
Expand Down
89 changes: 89 additions & 0 deletions internal/providers/qemu/qemu_blockdev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2020 Red Hat, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build s390x ppc64le

// The QEMU provider on s390x and ppc64le fetches a configuration file from an
// attached block device with id 'virtio-ignition'.

package qemu

import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"time"

"github.com/coreos/ignition/config/validate/report"
"github.com/coreos/ignition/internal/config/types"
"github.com/coreos/ignition/internal/log"
"github.com/coreos/ignition/internal/providers/util"
"github.com/coreos/ignition/internal/resource"
)

const (
ignitionBlockDevicePath = "/dev/disk/by-id/virtio-ignition"
blockDeviceTimeout = 5 * time.Minute
blockDevicePollingInterval = 5 * time.Second
)

func FetchConfig(f *resource.Fetcher) (types.Config, report.Report, error) {
f.Logger.Warning("Fetching the Ignition config via the Virtio block driver is currently experimental and subject to change.")

_, err := f.Logger.LogCmd(exec.Command("modprobe", "virtio_blk"), "loading Virtio block driver module")
if err != nil {
return types.Config{}, report.Report{}, err
}

data, err := fetchConfigFromBlockDevice(f.Logger)
if err != nil {
return types.Config{}, report.Report{}, err
}

return util.ParseConfig(f.Logger, data)
}

func fetchConfigFromBlockDevice(logger *log.Logger) ([]byte, error) {
var data []byte
c := make(chan error)
go func() {
var err error
for {
if data, err = ioutil.ReadFile(ignitionBlockDevicePath); err != nil {
if !os.IsNotExist(err) {
break
}
logger.Debug("block device (%q) not found. Waiting...", ignitionBlockDevicePath)
time.Sleep(blockDevicePollingInterval)
} else {
err = nil
break
}
}
c <- err
}()

select {
case err := <-c:
if err != nil {
return nil, err
}
case <-time.After(blockDeviceTimeout):
return nil, fmt.Errorf("timed out after %v waiting for block device %q to appear", blockDeviceTimeout, ignitionBlockDevicePath)
}

return bytes.TrimRight(data, "\x00"), nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// The QEMU provider fetches a local configuration from the firmware config
// interface (opt/com.coreos/config).
// +build amd64 arm64

// The QEMU provider on amd64 and arm64 fetches a local configuration from the
// firmware config interface (opt/com.coreos/config).

package qemu

Expand Down