Skip to content

Commit f2c65e3

Browse files
melwittpriteau
authored andcommitted
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 (cherry picked from commit 82856f9) (cherry picked from commit 09fc2fa) (cherry picked from commit 2fd65bd) Signed-off-by: Pierre Riteau <pierre@stackhpc.com> (cherry picked from commit d6cdd73) (cherry picked from commit 911cc31) (cherry picked from commit a8c53ef)
1 parent cc8940f commit f2c65e3

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

nova/tests/unit/virt/libvirt/test_driver.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13830,8 +13830,11 @@ def test_create_images_and_backing_ephemeral_gets_created(
1383013830
'ephemeral_foo')
1383113831
]
1383213832

13833+
# This also asserts that the filesystem label name is generated
13834+
# correctly as 'ephemeral0' to help prevent regression of the
13835+
# related bug fix from https://launchpad.net/bugs/2061701
1383313836
create_ephemeral_mock.assert_called_once_with(
13834-
ephemeral_size=1, fs_label='ephemeral_foo',
13837+
ephemeral_size=1, fs_label='ephemeral0',
1383513838
os_type='linux', target=ephemeral_backing)
1383613839

1383713840
fetch_image_mock.assert_called_once_with(

nova/virt/libvirt/driver.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4609,6 +4609,13 @@ def _inject_data(self, disk, instance, injection_info):
46094609
{'img_id': img_id, 'e': e},
46104610
instance=instance)
46114611

4612+
@staticmethod
4613+
def _get_fs_label_ephemeral(index: int) -> str:
4614+
# Use a consistent naming convention for FS labels. We need to be
4615+
# mindful of various filesystems label name length limitations.
4616+
# See for example: https://bugs.launchpad.net/nova/+bug/2061701
4617+
return f'ephemeral{index}'
4618+
46124619
# NOTE(sileht): many callers of this method assume that this
46134620
# method doesn't fail if an image already exists but instead
46144621
# think that it will be reused (ie: (live)-migration/resize)
@@ -4715,7 +4722,7 @@ def raw(fname):
47154722
created_disks = created_disks or not disk_image.exists()
47164723

47174724
fn = functools.partial(self._create_ephemeral,
4718-
fs_label='ephemeral0',
4725+
fs_label=self._get_fs_label_ephemeral(0),
47194726
os_type=instance.os_type,
47204727
is_block_dev=disk_image.is_block_dev,
47214728
vm_mode=vm_mode)
@@ -4739,7 +4746,7 @@ def raw(fname):
47394746
raise exception.InvalidBDMFormat(details=msg)
47404747

47414748
fn = functools.partial(self._create_ephemeral,
4742-
fs_label='ephemeral%d' % idx,
4749+
fs_label=self._get_fs_label_ephemeral(idx),
47434750
os_type=instance.os_type,
47444751
is_block_dev=disk_image.is_block_dev,
47454752
vm_mode=vm_mode)
@@ -10766,7 +10773,7 @@ def _create_images_and_backing(self, context, instance, instance_dir,
1076610773
# cached.
1076710774
disk.cache(
1076810775
fetch_func=self._create_ephemeral,
10769-
fs_label=cache_name,
10776+
fs_label=self._get_fs_label_ephemeral(0),
1077010777
os_type=instance.os_type,
1077110778
filename=cache_name,
1077210779
size=info['virt_disk_size'],
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fixes:
2+
- |
3+
Fixed an issue where certain server actions could fail for servers with
4+
ephemeral disks due to filesystem label name length limitations
5+
(VFAT, XFS, ...). Filesystem label name generation has been fixed for these
6+
cases. See https://launchpad.net/bugs/2061701 for more details.

0 commit comments

Comments
 (0)