libvirt: Use common naming convention for ephemeral disk labels

The _create_ephemeral() method is responsible for creating ephemeral
disks with image type "raw" and formatting them with mkfs. In the case
of [libvirt]images_type "qcow2", _create_ephemeral() will create
backing files.

Currently we are not using a consistent naming convention for choosing
the filesystem label for ephemeral disks. When we create a server for
example, we go through the disks and label them "ephemeral0",
"ephemeral1", "ephemeral2", etc.

When we hard reboot a server, there is a check to create missing
backing files and if so, a new backing file will be created but instead
of being labeled "ephemeralN" the code attempts to label them with the
name of the backing file itself for example "ephemeral_1_40d1d2c". This
will fail if the filesystem used for ephemeral disks has limitations on
the length of filesystem label names (VFAT, XFS, ...). For example:

  mkfs.vfat: Label can be no longer than 11 characters

This adds a helper method for obtaining ephemeral disks filesystem
label names and uses it the same way in the few places fs_label is
specified.

Closes-Bug: #2061701

Change-Id: Id033a5760272e4fb06dee2342414b26aa16ffe24
This commit is contained in:
melanie witt
2025-04-16 15:20:23 -07:00
parent cda0d82570
commit 82856f95c6
3 changed files with 20 additions and 4 deletions

View File

@ -15202,8 +15202,11 @@ class LibvirtConnTestCase(test.NoDBTestCase,
'ephemeral_foo')
]
# This also asserts that the filesystem label name is generated
# correctly as 'ephemeral0' to help prevent regression of the
# related bug fix from https://launchpad.net/bugs/2061701
create_ephemeral_mock.assert_called_once_with(
ephemeral_size=1, fs_label='ephemeral_foo',
ephemeral_size=1, fs_label='ephemeral0',
os_type='linux', target=ephemeral_backing)
fetch_image_mock.assert_called_once_with(

View File

@ -5152,6 +5152,13 @@ class LibvirtDriver(driver.ComputeDriver):
{'img_id': img_id, 'e': e},
instance=instance)
@staticmethod
def _get_fs_label_ephemeral(index: int) -> str:
# Use a consistent naming convention for FS labels. We need to be
# mindful of various filesystems label name length limitations.
# See for example: https://bugs.launchpad.net/nova/+bug/2061701
return f'ephemeral{index}'
# NOTE(sileht): many callers of this method assume that this
# method doesn't fail if an image already exists but instead
# think that it will be reused (ie: (live)-migration/resize)
@ -5267,7 +5274,7 @@ class LibvirtDriver(driver.ComputeDriver):
created_disks = created_disks or not disk_image.exists()
fn = functools.partial(self._create_ephemeral,
fs_label='ephemeral0',
fs_label=self._get_fs_label_ephemeral(0),
os_type=instance.os_type,
is_block_dev=disk_image.is_block_dev,
vm_mode=vm_mode)
@ -5291,7 +5298,7 @@ class LibvirtDriver(driver.ComputeDriver):
raise exception.InvalidBDMFormat(details=msg)
fn = functools.partial(self._create_ephemeral,
fs_label='ephemeral%d' % idx,
fs_label=self._get_fs_label_ephemeral(idx),
os_type=instance.os_type,
is_block_dev=disk_image.is_block_dev,
vm_mode=vm_mode)
@ -11747,7 +11754,7 @@ class LibvirtDriver(driver.ComputeDriver):
# cached.
disk.cache(
fetch_func=self._create_ephemeral,
fs_label=cache_name,
fs_label=self._get_fs_label_ephemeral(0),
os_type=instance.os_type,
filename=cache_name,
size=info['virt_disk_size'],

View File

@ -0,0 +1,6 @@
fixes:
- |
Fixed an issue where certain server actions could fail for servers with
ephemeral disks due to filesystem label name length limitations
(VFAT, XFS, ...). Filesystem label name generation has been fixed for these
cases. See https://launchpad.net/bugs/2061701 for more details.