Skip to content

Commit

Permalink
Add support for ramfs as well as tmpfs in volume mounts
Browse files Browse the repository at this point in the history
Fixes: containers#19659

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Aug 17, 2023
1 parent e0b8178 commit 316586d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
23 changes: 12 additions & 11 deletions docs/source/markdown/options/mount.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@

Attach a filesystem mount to the container

Current supported mount TYPEs are **bind**, **devpts**, **glob**, **image**, **tmpfs** and **volume**. <sup>[[1]](#Footnote1)</sup>
Current supported mount TYPEs are **bind**, **devpts**, **glob**, **image**, **ramfs**, **tmpfs** and **volume**. <sup>[[1]](#Footnote1)</sup>

e.g.

type=bind,source=/path/on/host,destination=/path/in/container

type=bind,src=/path/on/host,dst=/path/in/container,relabel=shared

type=bind,src=/path/on/host,dst=/path/in/container,relabel=shared,U=true

type=devpts,destination=/dev/pts

type=glob,src=/usr/lib/libfoo*,destination=/usr/lib,ro=true

type=volume,source=vol1,destination=/path/in/container,ro=true
type=image,source=fedora,destination=/fedora-image,rw=true

type=tmpfs,tmpfs-size=512M,destination=/path/in/container
type=ramfs,tmpfs-size=512M,destination=/path/in/container

type=image,source=fedora,destination=/fedora-image,rw=true
type=tmpfs,tmpfs-size=512M,destination=/path/in/container

type=devpts,destination=/dev/pts
type=volume,source=vol1,destination=/path/in/container,ro=true

Common Options:

Expand Down Expand Up @@ -72,17 +73,17 @@ Current supported mount TYPEs are **bind**, **devpts**, **glob**, **image**, **t

. U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.

Options specific to tmpfs:
Options specific to tmpfs and ramfs:

· ro, readonly: true or false (default).

· tmpfs-size: Size of the tmpfs mount in bytes. Unlimited by default in Linux.
· tmpfs-size: Size of the tmpfs/ramfs mount in bytes. Unlimited by default in Linux.

· tmpfs-mode: File mode of the tmpfs in octal. (e.g. 700 or 0700.) Defaults to 1777 in Linux.
· tmpfs-mode: File mode of the tmpfs/ramfs in octal. (e.g. 700 or 0700.) Defaults to 1777 in Linux.

· tmpcopyup: Enable copyup from the image directory at the same location to the tmpfs. Used by default.
· tmpcopyup: Enable copyup from the image directory at the same location to the tmpfs/ramfs. Used by default.

· notmpcopyup: Disable copying files from the image to the tmpfs.
· notmpcopyup: Disable copying files from the image to the tmpfs/ramfs.

. U, chown: true or false (default). Change recursively the owner and group of the source volume based on the UID and GID of the container.

Expand Down
10 changes: 6 additions & 4 deletions libpod/define/mount.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package define

const (
// TypeVolume is the type for named volumes
TypeVolume = "volume"
// TypeTmpfs is the type for mounting tmpfs
TypeTmpfs = "tmpfs"
// TypeDevpts is the type for creating a devpts
TypeDevpts = "devpts"
// TypeTmpfs is the type for mounting tmpfs
TypeTmpfs = "tmpfs"
// TypeRamfs is the type for mounting ramfs
TypeRamfs = "ramfs"
// TypeVolume is the type for named volumes
TypeVolume = "volume"
)
12 changes: 6 additions & 6 deletions pkg/specgenutil/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ func Mounts(mountFlag []string, configMounts []string) (map[string]spec.Mount, m
}
finalMounts[mount.Destination] = mount
}
case define.TypeTmpfs:
mount, err := getTmpfsMount(tokens)
case define.TypeTmpfs, define.TypeRamfs:
mount, err := getTmpfsMount(tokens, mountType)
if err != nil {
return err
}
Expand Down Expand Up @@ -525,11 +525,11 @@ func getBindMount(args []string) (spec.Mount, error) {
return newMount, nil
}

// Parse a single tmpfs mount entry from the --mount flag
func getTmpfsMount(args []string) (spec.Mount, error) {
// Parse a single tmpfs/ramfs mount entry from the --mount flag
func getTmpfsMount(args []string, tmpfsType string) (spec.Mount, error) {
newMount := spec.Mount{
Type: define.TypeTmpfs,
Source: define.TypeTmpfs,
Type: tmpfsType,
Source: tmpfsType,
}

var err error
Expand Down
6 changes: 6 additions & 0 deletions test/system/060-mount.bats
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,10 @@ EOF
is "$output" "bar1.*bar2.*bar3" "Should match multiple source files on single destination directory"
}

@test "podman mount ramfs" {
# if volumes source and dest match then pass
run_podman run --rm --mount type=ramfs,destination=${PODMAN_TMPDIR} $IMAGE stat -f -c "%T" ${PODMAN_TMPDIR}
is "$output" "ramfs" "ramfs mounted"
}

# vim: filetype=sh

0 comments on commit 316586d

Please sign in to comment.