Skip to content

Commit 68fc0e5

Browse files
committed
compose: handle --fs option to support both ZFS and ROFS
Signed-off-by: Waldemar Kozaczuk <[email protected]>
1 parent 3c09168 commit 68fc0e5

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

capstan.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ func main() {
250250
&cli.StringFlag{Name: "size", Aliases: []string{"s"}, Value: "10G", Usage: "size of the target user partition (use M or G suffix)"},
251251
&cli.StringFlag{Name: "command_line", Aliases: []string{"c"}, Usage: "command line OSv will boot with"},
252252
&cli.BoolFlag{Name: "verbose", Aliases: []string{"v"}, Usage: "verbose mode"},
253+
&cli.StringFlag{Name: "fs", Usage: "specify type of filesystem: zfs or rofs"},
253254
},
254255
Action: func(c *cli.Context) error {
255256
if c.Args().Len() != 2 {
@@ -274,7 +275,12 @@ func main() {
274275
return cli.NewExitError(fmt.Sprintf("Incorrect image size format: %s\n", err), EX_DATAERR)
275276
}
276277

277-
if err := cmd.Compose(repo, loaderImage, imageSize, uploadPath, appName, commandLine, verbose); err != nil {
278+
filesystem := c.String("fs")
279+
if filesystem == "" || (filesystem != "zfs" && filesystem != "rofs") {
280+
filesystem = "zfs"
281+
}
282+
283+
if err := cmd.Compose(repo, loaderImage, imageSize, filesystem, uploadPath, appName, commandLine, verbose); err != nil {
278284
return cli.NewExitError(err.Error(), EX_DATAERR)
279285
}
280286
return nil

cmd/compose.go

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,53 @@ import (
2121
"io/ioutil"
2222
"net"
2323
"os"
24+
"path"
2425
"path/filepath"
2526
"strings"
2627
)
2728

28-
func Compose(r *util.Repo, loaderImage string, imageSize int64, uploadPath string, appName string, commandLine string, verbose bool) error {
29-
zfsBuilderPath, err := r.GetZfsBuilderImagePath()
30-
if err != nil {
31-
return err
32-
}
33-
// Initialize an empty image based on the provided loader image. imageSize is used to
34-
// determine the size of the user partition.
35-
err = r.InitializeZfsImage(loaderImage, appName, imageSize)
29+
func Compose(r *util.Repo, loaderImage string, imageSize int64, filesystem string, uploadPath string, appName string, commandLine string, verbose bool) error {
30+
// If all is well, we have to start preparing the files for upload.
31+
paths, err := CollectPathContents(uploadPath)
3632
if err != nil {
3733
return err
3834
}
3935

4036
// Get the path of imported image.
4137
imagePath := r.ImagePath("qemu", appName)
4238

43-
paths, err := CollectPathContents(uploadPath)
44-
if err != nil {
45-
return err
46-
}
39+
if filesystem == "zfs" {
40+
// Create ZFS
41+
zfsBuilderPath, err := r.GetZfsBuilderImagePath()
42+
if err != nil {
43+
return err
44+
}
45+
// Initialize an empty image based on the provided loader image. imageSize is used to
46+
// determine the size of the user partition.
47+
err = r.InitializeZfsImage(loaderImage, appName, imageSize)
48+
if err != nil {
49+
return err
50+
}
4751

48-
// Upload the specified path onto virtual image.
49-
if _, err = UploadPackageContents(r, imagePath, paths, nil, verbose, zfsBuilderPath); err != nil {
50-
return err
52+
// Upload the specified path onto virtual image.
53+
if _, err = UploadPackageContents(r, imagePath, paths, nil, verbose, zfsBuilderPath); err != nil {
54+
return err
55+
}
56+
} else {
57+
// Create ROFS
58+
// Create temporary folder in which the image will be composed.
59+
tmp, _ := ioutil.TempDir("", "capstan")
60+
// Once this function is finished, remove temporary file.
61+
defer os.RemoveAll(tmp)
62+
rofs_image_path := path.Join(tmp, "rofs.img")
63+
64+
if err := util.WriteRofsImage(rofs_image_path, paths, uploadPath, verbose); err != nil {
65+
return fmt.Errorf("Failed to write ROFS image named %s.\nError was: %s", rofs_image_path, err)
66+
}
67+
68+
if err = r.CreateRofsImage(loaderImage, appName, rofs_image_path); err != nil {
69+
return fmt.Errorf("Failed to create ROFS image named %s.\nError was: %s", appName, err)
70+
}
5171
}
5272

5373
if commandLine != "" {

0 commit comments

Comments
 (0)