osbase/fat32: adopt structfs
Change the external interface of the FAT32 writer to take a
structfs.Tree instead of a FAT32-specific data structure. Producers of
file system data are no longer specific to FAT32.
With these changes, the blkio package becomes obsolete. The
LazyFileReader did not actually work as intended when used with
osbase/fat32, because fat32 copies data with io.CopyN and thus stops
reading before reaching EOF, so the LazyFileReader is never closed. The
new Blob interface requires the consumer to explicitly Open and Close.
Change-Id: I9a71a5f0bddf36ac38c656659e6dcfe520b88fb0
Reviewed-on: https://review.monogon.dev/c/monogon/+/4037
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/cli/metroctl/BUILD.bazel b/metropolis/cli/metroctl/BUILD.bazel
index f4c5c15..bd7ab70 100644
--- a/metropolis/cli/metroctl/BUILD.bazel
+++ b/metropolis/cli/metroctl/BUILD.bazel
@@ -48,10 +48,9 @@
"//metropolis/node/core/rpc/resolver",
"//metropolis/proto/api",
"//metropolis/proto/common",
- "//osbase/blkio",
- "//osbase/fat32",
"//osbase/logtree",
"//osbase/logtree/proto",
+ "//osbase/structfs",
"//version",
"@com_github_adrg_xdg//:xdg",
"@com_github_schollz_progressbar_v3//:progressbar",
diff --git a/metropolis/cli/metroctl/cmd_install.go b/metropolis/cli/metroctl/cmd_install.go
index a34e470..1b9b8cb 100644
--- a/metropolis/cli/metroctl/cmd_install.go
+++ b/metropolis/cli/metroctl/cmd_install.go
@@ -4,7 +4,6 @@
package main
import (
- "bytes"
"context"
"crypto/ed25519"
_ "embed"
@@ -22,8 +21,7 @@
"source.monogon.dev/metropolis/cli/flagdefs"
"source.monogon.dev/metropolis/cli/metroctl/core"
common "source.monogon.dev/metropolis/node"
- "source.monogon.dev/osbase/blkio"
- "source.monogon.dev/osbase/fat32"
+ "source.monogon.dev/osbase/structfs"
)
var installCmd = &cobra.Command{
@@ -111,20 +109,15 @@
return params, nil
}
-func external(name, datafilePath string, flag *string) (fat32.SizedReader, error) {
+func external(name, datafilePath string, flag *string) (structfs.Blob, error) {
if flag == nil || *flag == "" {
rPath, err := runfiles.Rlocation(datafilePath)
if err != nil {
return nil, fmt.Errorf("no %s specified", name)
}
- df, err := os.ReadFile(rPath)
- if err != nil {
- return nil, fmt.Errorf("can't read file: %w", err)
- }
- return bytes.NewReader(df), nil
+ return structfs.OSPathBlob(rPath)
}
-
- f, err := blkio.NewFileReader(*flag)
+ f, err := structfs.OSPathBlob(*flag)
if err != nil {
return nil, fmt.Errorf("failed to open specified %s: %w", name, err)
}
diff --git a/metropolis/cli/metroctl/cmd_install_ssh.go b/metropolis/cli/metroctl/cmd_install_ssh.go
index efd1fd7..f0a5379 100644
--- a/metropolis/cli/metroctl/cmd_install_ssh.go
+++ b/metropolis/cli/metroctl/cmd_install_ssh.go
@@ -24,7 +24,7 @@
"google.golang.org/protobuf/proto"
"source.monogon.dev/go/net/ssh"
- "source.monogon.dev/osbase/fat32"
+ "source.monogon.dev/osbase/structfs"
)
var sshCmd = &cobra.Command{
@@ -130,14 +130,20 @@
return err
}
- barUploader := func(r fat32.SizedReader, targetPath string) {
+ barUploader := func(blob structfs.Blob, targetPath string) {
+ content, err := blob.Open()
+ if err != nil {
+ log.Fatalf("error while uploading %q: %v", targetPath, err)
+ }
+ defer content.Close()
+
bar := progressbar.DefaultBytes(
- r.Size(),
+ blob.Size(),
targetPath,
)
defer bar.Close()
- proxyReader := progressbar.NewReader(r, bar)
+ proxyReader := progressbar.NewReader(content, bar)
defer proxyReader.Close()
if err := conn.Upload(ctx, targetPath, &proxyReader); err != nil {
diff --git a/metropolis/cli/metroctl/core/BUILD.bazel b/metropolis/cli/metroctl/core/BUILD.bazel
index 3a599a7..73527d5 100644
--- a/metropolis/cli/metroctl/core/BUILD.bazel
+++ b/metropolis/cli/metroctl/core/BUILD.bazel
@@ -21,6 +21,7 @@
"//osbase/blockdev",
"//osbase/fat32",
"//osbase/gpt",
+ "//osbase/structfs",
"@io_k8s_client_go//pkg/apis/clientauthentication/v1:clientauthentication",
"@io_k8s_client_go//tools/clientcmd",
"@io_k8s_client_go//tools/clientcmd/api",
diff --git a/metropolis/cli/metroctl/core/install.go b/metropolis/cli/metroctl/core/install.go
index 190f66a..5d43a89 100644
--- a/metropolis/cli/metroctl/core/install.go
+++ b/metropolis/cli/metroctl/core/install.go
@@ -4,7 +4,6 @@
package core
import (
- "bytes"
"errors"
"fmt"
"math"
@@ -16,6 +15,7 @@
"source.monogon.dev/osbase/blockdev"
"source.monogon.dev/osbase/fat32"
"source.monogon.dev/osbase/gpt"
+ "source.monogon.dev/osbase/structfs"
)
type MakeInstallerImageArgs struct {
@@ -23,13 +23,13 @@
TargetPath string
// Reader for the installer EFI executable. Mandatory.
- Installer fat32.SizedReader
+ Installer structfs.Blob
// Optional NodeParameters to be embedded for use by the installer.
NodeParams *api.NodeParameters
// Optional Reader for a Metropolis bundle for use by the installer.
- Bundle fat32.SizedReader
+ Bundle structfs.Blob
}
// MakeInstallerImage generates an installer disk image containing a Table
@@ -40,7 +40,7 @@
return errors.New("installer is mandatory")
}
- espRoot := fat32.Inode{Attrs: fat32.AttrDirectory}
+ var espRoot structfs.Tree
// This needs to be a "Removable Media" according to the UEFI Specification
// V2.9 Section 3.5.1.1. This file is booted by any compliant UEFI firmware
@@ -54,7 +54,7 @@
if err != nil {
return fmt.Errorf("failed to marshal node params: %w", err)
}
- if err := espRoot.PlaceFile("metropolis-installer/nodeparams.pb", bytes.NewReader(nodeParamsRaw)); err != nil {
+ if err := espRoot.PlaceFile("metropolis-installer/nodeparams.pb", structfs.Bytes(nodeParamsRaw)); err != nil {
return err
}
}