Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support size option when creating tmpfs volumes #20451

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/source/markdown/podman-volume-create.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ The `o` option sets options for the mount, and is equivalent to the filesystem
options (also `-o`) passed to **mount(8)** with the following exceptions:

- The `o` option supports `uid` and `gid` options to set the UID and GID of the created volume that are not normally supported by **mount(8)**.
- The `o` option supports the `size` option to set the maximum size of the created volume, the `inodes` option to set the maximum number of inodes for the volume and `noquota` to completely disable quota support even for tracking of disk usage. Currently these flags are only supported on "xfs" file system mounted with the `prjquota` flag described in the **xfs_quota(8)** man page.
- The `o` option supports the `size` option to set the maximum size of the created volume, the `inodes` option to set the maximum number of inodes for the volume, and `noquota` to completely disable quota support even for tracking of disk usage.
The `size` option is supported on the "tmpfs" and "xfs[note]" file systems.
The `inodes` option is supported on the "xfs[note]" file systems.
Note: xfs filesystems must be mounted with the `prjquota` flag described in the **xfs_quota(8)** man page. Podman will throw an error if they're not.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but can someone confirm if this is true? I can't find a way to get a system with xfs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@umohnani8 is working with this now.

- The `o` option supports using volume options other than the UID/GID options with the **local** driver and requires root privileges.
- The `o` options supports the `timeout` option which allows users to set a driver specific timeout in seconds before volume creation fails. For example, **--opt=o=timeout=10** sets a driver timeout of 10 seconds.

Expand All @@ -75,7 +78,7 @@ $ podman volume create

$ podman volume create --label foo=bar myvol

# podman volume create --opt device=tmpfs --opt type=tmpfs --opt o=nodev,noexec myvol
# podman volume create --opt device=tmpfs --opt type=tmpfs --opt o=size=2M,nodev,noexec myvol

# podman volume create --opt device=tmpfs --opt type=tmpfs --opt o=uid=1000,gid=1000 testvol

Expand Down
29 changes: 16 additions & 13 deletions libpod/runtime_volume_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,28 +178,31 @@ func (r *Runtime) newVolume(ctx context.Context, noCreatePluginVolume bool, opti
if err := LabelVolumePath(fullVolPath, volume.config.MountLabel); err != nil {
return nil, err
}
if volume.config.DisableQuota {
switch {
case volume.config.DisableQuota:
if volume.config.Size > 0 || volume.config.Inodes > 0 {
return nil, errors.New("volume options size and inodes cannot be used without quota")
}
} else {
case volume.config.Options["type"] == define.TypeTmpfs:
// tmpfs only supports Size
if volume.config.Inodes > 0 {
return nil, errors.New("volume option inodes not supported on tmpfs filesystem")
}
case volume.config.Inodes > 0 || volume.config.Size > 0:
projectQuotaSupported := false
q, err := quota.NewControl(r.config.Engine.VolumePath)
if err == nil {
projectQuotaSupported = true
}
quota := quota.Quota{}
if volume.config.Size > 0 || volume.config.Inodes > 0 {
if !projectQuotaSupported {
return nil, errors.New("volume options size and inodes not supported. Filesystem does not support Project Quota")
}
quota.Size = volume.config.Size
quota.Inodes = volume.config.Inodes
if !projectQuotaSupported {
return nil, errors.New("volume options size and inodes not supported. Filesystem does not support Project Quota")
}
if projectQuotaSupported {
if err := q.SetQuota(fullVolPath, quota); err != nil {
return nil, fmt.Errorf("failed to set size quota size=%d inodes=%d for volume directory %q: %w", volume.config.Size, volume.config.Inodes, fullVolPath, err)
}
quota := quota.Quota{
Inodes: volume.config.Inodes,
Size: volume.config.Size,
}
if err := q.SetQuota(fullVolPath, quota); err != nil {
return nil, fmt.Errorf("failed to set size quota size=%d inodes=%d for volume directory %q: %w", volume.config.Size, volume.config.Inodes, fullVolPath, err)
}
}

Expand Down
5 changes: 4 additions & 1 deletion test/system/160-volumes.bats
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,14 @@ EOF

@test "podman volume type=tmpfs" {
myvolume=myvol$(random_string)
run_podman volume create -o type=tmpfs -o device=tmpfs $myvolume
run_podman volume create -o type=tmpfs -o o=size=2M -o device=tmpfs $myvolume
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: nuke lines 439-441, and replace this block here with:

    run_podman run --rm -v $myvolume:/vol $IMAGE stat -f -c "%T %b %s" /vol
    read fstype fsblocks fsblocksize <<<"$output"
    assert "$fstype" = "tmpfs" "stat %T - filesystem type"
    assert "$(($fsblocks * $fsblocksize))" == "$((2048 * 1024))" "filesystem size (product of nblocks * blocksize)"

is "$output" "$myvolume" "should successfully create myvolume"

run_podman run --rm -v $myvolume:/vol $IMAGE stat -f -c "%T" /vol
is "$output" "tmpfs" "volume should be tmpfs"

run_podman run --rm -v $myvolume:/vol $IMAGE sh -c "mount| grep /vol"
is "$output" "tmpfs on /vol type tmpfs.*size=2048k.*" "size should be set to 2048k"
}

# Named volumes copyup
Expand Down