func (inst *instance) Copy(hostSrc string) (string, error) { vmDst := filepath.Join(inst.cfg.Workdir, filepath.Base(hostSrc)) if err := fileutil.CopyFile(hostSrc, vmDst, false); err != nil { return "", err } if err := os.Chmod(vmDst, 0777); err != nil { return "", err } return vmDst, nil }
func (inst *instance) Copy(hostSrc string) (string, error) { vmDst := filepath.Join("/", filepath.Base(hostSrc)) dst := filepath.Join(inst.sandboxPath, vmDst) if err := fileutil.CopyFile(hostSrc, dst, false); err != nil { return "", err } if err := os.Chmod(dst, 0777); err != nil { return "", err } return vmDst, nil }
func ctorImpl(cfg *vm.Config) (vm.Instance, error) { inst := &instance{ cfg: cfg, image: filepath.Join(cfg.Workdir, "image"), } closeInst := inst defer func() { if closeInst != nil { closeInst.Close() } }() if err := validateConfig(cfg); err != nil { return nil, err } os.Remove(inst.image) if err := fileutil.CopyFile(inst.cfg.Image, inst.image, true); err != nil { return nil, fmt.Errorf("failed to copy image file: %v", err) } var err error inst.rpipe, inst.wpipe, err = os.Pipe() if err != nil { return nil, fmt.Errorf("failed to create pipe: %v", err) } for sz := 128 << 10; sz <= 2<<20; sz *= 2 { syscall.Syscall(syscall.SYS_FCNTL, inst.wpipe.Fd(), syscall.F_SETPIPE_SZ, uintptr(sz)) } if err := inst.Boot(); err != nil { return nil, err } closeInst = nil return inst, nil }