Skip to content

Commit

Permalink
Merge pull request #20451 from rhatdan/volume
Browse files Browse the repository at this point in the history
Support size option when creating tmpfs volumes
  • Loading branch information
openshift-ci[bot] authored Oct 24, 2023
2 parents 83d7c38 + ee60708 commit e9e18ac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
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.
- 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 @@ -179,28 +179,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
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

1 comment on commit e9e18ac

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

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

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.