From 0ddfcc64a07dcfbc91ebde8dcaca20b822da2a44 Mon Sep 17 00:00:00 2001 From: Seth Hollandsworth Date: Tue, 30 Jan 2024 15:59:07 -0500 Subject: [PATCH] adding option of using buffered image reader for faster dmverity hashing Signed-off-by: Seth Hollandsworth --- cmd/dmverity-vhd/main.go | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/cmd/dmverity-vhd/main.go b/cmd/dmverity-vhd/main.go index 6257981d2a..c76d7105db 100644 --- a/cmd/dmverity-vhd/main.go +++ b/cmd/dmverity-vhd/main.go @@ -22,15 +22,16 @@ import ( const usage = `dmverity-vhd is a command line tool for creating LCOW layer VHDs with dm-verity hashes.` const ( - usernameFlag = "username" - passwordFlag = "password" - imageFlag = "image" - verboseFlag = "verbose" - outputDirFlag = "out-dir" - dockerFlag = "docker" - tarballFlag = "tarball" - hashDeviceVhdFlag = "hash-dev-vhd" - maxVHDSize = dmverity.RecommendedVHDSizeGB + usernameFlag = "username" + passwordFlag = "password" + imageFlag = "image" + verboseFlag = "verbose" + outputDirFlag = "out-dir" + dockerFlag = "docker" + bufferedOpenerFlag = "buffered-opener" + tarballFlag = "tarball" + hashDeviceVhdFlag = "hash-dev-vhd" + maxVHDSize = dmverity.RecommendedVHDSizeGB ) func init() { @@ -68,6 +69,10 @@ func main() { Name: tarballFlag + ",t", Usage: "Optional: path to tarball containing image info", }, + cli.BoolFlag{ + Name: bufferedOpenerFlag + ",b", + Usage: "Optional: use buffered opener for image", + }, } if err := app.Run(os.Args); err != nil { @@ -103,11 +108,13 @@ func fetchImageLayers(ctx *cli.Context) (layers []v1.Layer, err error) { // if only an image name is provided and not a tag, the default is "latest" img, err = tarball.ImageFromPath(tarballPath, &imageNameAndTag) } else if dockerDaemon { - // use the unbuffered opener, the tradeoff being the image will stream as needed + // use the unbuffered opener by default, the tradeoff being the image will stream as needed // so it is slower but much more memory efficient var opts []daemon.Option - opt := daemon.WithUnbufferedOpener() - opts = append(opts, opt) + if !ctx.GlobalBool(bufferedOpenerFlag) { + opt := daemon.WithUnbufferedOpener() + opts = append(opts, opt) + } img, err = daemon.Image(ref, opts...) } else {