From a2d178996b0844c378dd013dde53a5c1f5a17fbd Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 3 Dec 2019 18:46:24 +0100 Subject: vm: add workdir_template functionality The new manager config argument workdir_template refers to a directory. Optional. Each VM will get a recursive copy of the files that are present in workdir_template. VM config can then use these private copies as needed. The copy directory can be referenced with "{{TEMPLATE}}" string. This is different from using the files directly in that each instance will get own clean, private, scratch copy of the files. Currently supported only for qemu_args argument of qemu VM type. Use example: Create a template dir with necessary files: $ mkdir /mytemplatedir $ truncate -s 64K /mytemplatedir/fd Then specify the dir in the manager config: "workdir_template": "/mytemplatedir" Then use these files in VM config: "qemu_args": "-fda {{TEMPLATE}}/fd" --- pkg/osutil/osutil.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'pkg/osutil') diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index 32a8054e7..0bc257e76 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -163,6 +163,30 @@ func CopyFiles(srcDir, dstDir string, files map[string]bool) error { return os.Rename(tmpDir, dstDir) } +func CopyDirRecursively(srcDir, dstDir string) error { + if err := MkdirAll(dstDir); err != nil { + return err + } + files, err := ioutil.ReadDir(srcDir) + if err != nil { + return err + } + for _, file := range files { + src := filepath.Join(srcDir, file.Name()) + dst := filepath.Join(dstDir, file.Name()) + if file.IsDir() { + if err := CopyDirRecursively(src, dst); err != nil { + return err + } + continue + } + if err := CopyFile(src, dst); err != nil { + return err + } + } + return nil +} + // LinkFiles creates hard links for files from dstDir to srcDir. // Files are assumed to be relative names in slash notation. // All other files in dstDir are removed. -- cgit mrf-deployment