Skip to content

Commit f692de5

Browse files
committed
add --upperdir option to mount
By default, the upperdir ends up under $mountpoint/meta/, and we purge it when we unmount. Offer the option to mount a different directory as upperdir, so that you can save the diff. Signed-off-by: Serge Hallyn <[email protected]>
1 parent 13ce410 commit f692de5

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

README.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@ atomfs umount mnt
1212

1313
Longer example:
1414
```
15-
serge@jerom ~$ lxc-usernsexec -s
16-
root@jerom ~$ atomfs mount zothub:busybox-squashfs dest
17-
root@jerom ~$ ls dest
15+
$ lxc-usernsexec -s
16+
$ atomfs mount zothub:busybox-squashfs dest
17+
$ ls dest
1818
bin dev etc home lib lib64 root tmp usr var
19-
root@jerom ~$ atomfs umount dest
19+
$ atomfs umount dest
20+
$ mkdir upper
21+
$ atomfs mount --upper=./upper zothub:busybox-squashfs dest
22+
$ ls dest
23+
bin dev etc home lib lib64 root tmp usr var
24+
$ touch dest/ab
25+
$ atomfs umount dest
26+
$ ls upper/
27+
ab
2028
```
2129

2230
# Implementation details

mount.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ var mountCmd = cli.Command{
1919
Usage: "mount atomfs image",
2020
Action: doMount,
2121
Flags: []cli.Flag{
22+
cli.StringFlag{
23+
Name: "upper, upperdir",
24+
Usage: "Directory to use as writeable overlay",
25+
},
2226
cli.BoolFlag{
2327
Name: "ro",
2428
Usage: "Do not make writeable using an overlay",
@@ -27,7 +31,7 @@ var mountCmd = cli.Command{
2731
}
2832

2933
func mountUsage(me string) error {
30-
return fmt.Errorf("Usage: atomfs mount [--unsafe] ocidir:tag target")
34+
return fmt.Errorf("Usage: atomfs mount [--upper=/tmp/upperdir] [--ro=true] ocidir:tag target")
3135
}
3236

3337
func findImage(ctx *cli.Context) (string, string, error) {
@@ -103,7 +107,7 @@ func doMount(ctx *cli.Context) error {
103107
if ctx.Bool("ro") {
104108
err = bind(target, rodest)
105109
} else {
106-
err = overlay(target, rodest, metadir)
110+
err = overlay(target, rodest, metadir, ctx)
107111
}
108112

109113
complete = true
@@ -171,12 +175,15 @@ func squashUmount(p string) error {
171175
return RunCommand("fusermount", "-u", p)
172176
}
173177

174-
func overlay(target, rodest, metadir string) error {
178+
func overlay(target, rodest, metadir string, ctx *cli.Context) error {
175179
workdir := filepath.Join(metadir, "work")
176180
if err := EnsureDir(workdir); err != nil {
177181
return err
178182
}
179183
upperdir := filepath.Join(metadir, "upper")
184+
if ctx.IsSet("upper") {
185+
upperdir = ctx.String("upper")
186+
}
180187
if err := EnsureDir(upperdir); err != nil {
181188
return err
182189
}

0 commit comments

Comments
 (0)