Skip to content

Commit

Permalink
lxd: Deny creation of empty ISO volume (#14644)
Browse files Browse the repository at this point in the history
I noticed `lxc storage volume create "${pool}" isoVol --type=iso` worked
inconsistently across drivers. Which led me to see that, according to
the docs: `A custom storage volume of type `iso` can only be created by
importing an ISO file using`, which makes sense because an empty ISO
volume is useless AFAIK. So this implements this prohibition of creating
empty ISO volumes.
  • Loading branch information
tomponline authored Dec 12, 2024
2 parents aee54e3 + 78e7b23 commit a82bf16
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/explanation/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Each storage volume uses one of the following content types:

`iso`
: This content type is used for custom ISO volumes.
A custom storage volume of type `iso` can only be created by importing an ISO file using [`lxc storage volume import`](lxc_storage_volume_import.md).
A custom storage volume of type `iso` can only be created by importing an ISO file using [`lxc storage volume import`](lxc_storage_volume_import.md) or by copying another volume.

Custom storage volumes of content type `iso` can only be attached to virtual machines.
They can be attached to multiple machines simultaneously as they are always read-only.
Expand Down
5 changes: 5 additions & 0 deletions lxd/storage_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,11 @@ func storagePoolVolumesPost(d *Daemon, r *http.Request) response.Response {

switch req.Source.Type {
case "":
// Makes no sense to create an empty ISO volume.
if req.ContentType == "iso" {
return response.BadRequest(errors.New("Creation of empty iso volumes is not allowed, either copy or import"))
}

return doVolumeCreateOrCopy(s, r, requestProjectName, projectName, poolName, &req)
case api.SourceTypeCopy:
if dbVolume != nil {
Expand Down
3 changes: 3 additions & 0 deletions test/suites/storage_local_volume_handling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ test_storage_local_volume_handling() {
lxc storage volume move "${pool}1/vol1" "${pool}1/vol1" --project "${project}" --target-project default
lxc storage volume show "${pool}1" vol1 --project default

# Create empty ISO volumes is not allowed
! lxc storage volume create "${pool}" isoVol --type=iso || false

# Create new pools
lxc storage create pool_1 dir
lxc storage create pool_2 dir
Expand Down

0 comments on commit a82bf16

Please sign in to comment.