[PATCH v2 0/2] lxc: Assign aliases to filesystem and network devices
From: Radoslaw Smigielski <rsmigiel@redhat.com> This series adds device alias assignment for filesystem and network interface devices in LXC domains, make them working the same way like console devices. This is needed as a prerequisite for fixing bug #63 (loop device path length limitation), where device aliases will be used to compose synthetic lo_file_name references in the format "libvirt-$UUID-$DEVALIAS". It split this patch into two separate commits, filesystem and network related. -- 2.54.0
From: Radoslaw Smigielski <rsmigiel@redhat.com> LXC domains did not assign device aliases to filesystem devices during domain startup. Only console devices received aliases. This change assigns aliases in the format 'fs0', 'fs1', etc. to all filesystem devices during domain startup, following the same pattern used for console devices. Before this patch, virsh dumpxml showed filesystem devices without aliases: <filesystem type='mount' accessmode='passthrough'> <source dir='/var/lib/libvirt/lxc/demo-root'/> <target dir='/'/> </filesystem> <filesystem type='file' accessmode='passthrough'> <driver type='loop' format='raw'/> <source file='/var/tmp/short6.raw'/> <target dir='/short6'/> </filesystem> <console type='pty' tty='/dev/pts/8'> <source path='/dev/pts/8'/> <target type='lxc' port='0'/> <alias name='console0'/> <!-- Only console has alias --> </console> After this patch, filesystem devices have auto-generated aliases: <filesystem type='mount' accessmode='passthrough'> <source dir='/var/lib/libvirt/lxc/demo-root'/> <target dir='/'/> <alias name='fs0'/> <!-- Now assigned --> </filesystem> <filesystem type='file' accessmode='passthrough'> <driver type='loop' format='raw'/> <source file='/var/tmp/short6.raw'/> <target dir='/short6'/> <alias name='fs1'/> <!-- Now assigned --> </filesystem> <console type='pty' tty='/dev/pts/8'> <source path='/dev/pts/8'/> <target type='lxc' port='0'/> <alias name='console0'/> </console> This is a prerequisite for fixing bug #63 (loop device path length limitation), where filesystem device aliases will be used to compose synthetic lo_file_name references in the format "libvirt-$UUID-$DEVALIAS". Related: https://gitlab.com/libvirt/libvirt/-/work_items/63 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- src/lxc/lxc_process.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 2c0bcb9dd3aa..aae9fcc9dfd1 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1350,6 +1350,12 @@ int virLXCProcessStart(virLXCDriver * driver, vm->def->consoles[i]->info.alias = g_strdup_printf("console%zu", i); } + VIR_DEBUG("Setting up filesystem aliases"); + for (i = 0; i < vm->def->nfss; i++) { + g_free(vm->def->fss[i]->info.alias); + vm->def->fss[i]->info.alias = g_strdup_printf("fs%zu", i); + } + VIR_DEBUG("Setting up Interfaces"); if (virLXCProcessSetupInterfaces(driver, vm->def, &veths) < 0) goto cleanup; -- 2.54.0
On 6/12/26 07:14, Radosław Śmigielski via Devel wrote:
From: Radoslaw Smigielski <rsmigiel@redhat.com>
LXC domains did not assign device aliases to filesystem devices during domain startup. Only console devices received aliases.
This change assigns aliases in the format 'fs0', 'fs1', etc. to all filesystem devices during domain startup, following the same pattern used for console devices.
Before this patch, virsh dumpxml showed filesystem devices without aliases:
<filesystem type='mount' accessmode='passthrough'> <source dir='/var/lib/libvirt/lxc/demo-root'/> <target dir='/'/> </filesystem> <filesystem type='file' accessmode='passthrough'> <driver type='loop' format='raw'/> <source file='/var/tmp/short6.raw'/> <target dir='/short6'/> </filesystem> <console type='pty' tty='/dev/pts/8'> <source path='/dev/pts/8'/> <target type='lxc' port='0'/> <alias name='console0'/> <!-- Only console has alias --> </console>
After this patch, filesystem devices have auto-generated aliases:
<filesystem type='mount' accessmode='passthrough'> <source dir='/var/lib/libvirt/lxc/demo-root'/> <target dir='/'/> <alias name='fs0'/> <!-- Now assigned --> </filesystem> <filesystem type='file' accessmode='passthrough'> <driver type='loop' format='raw'/> <source file='/var/tmp/short6.raw'/> <target dir='/short6'/> <alias name='fs1'/> <!-- Now assigned --> </filesystem> <console type='pty' tty='/dev/pts/8'> <source path='/dev/pts/8'/> <target type='lxc' port='0'/> <alias name='console0'/> </console>
This is a prerequisite for fixing bug #63 (loop device path length limitation), where filesystem device aliases will be used to compose synthetic lo_file_name references in the format "libvirt-$UUID-$DEVALIAS".
Related: https://gitlab.com/libvirt/libvirt/-/work_items/63 Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- src/lxc/lxc_process.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 2c0bcb9dd3aa..aae9fcc9dfd1 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1350,6 +1350,12 @@ int virLXCProcessStart(virLXCDriver * driver, vm->def->consoles[i]->info.alias = g_strdup_printf("console%zu", i); }
+ VIR_DEBUG("Setting up filesystem aliases"); + for (i = 0; i < vm->def->nfss; i++) { + g_free(vm->def->fss[i]->info.alias);
I don't think this g_free() is necessary. I know you took inspiration from a couple of lines above but I find it pointless there too. I mean, every domain starts with no aliases (in its inactive state). Then this function calls the following at its beginning: if (virDomainObjSetDefTransient(driver->xmlopt, vm, NULL) < 0) goto cleanup; which copies inactive domain definition (i.e. XML parser skips aliases intentionally) into vm->newDef. So later when domain is shutoff, virDomainObjRemoveTransientDef() is called which throws away vm->def and restores the original definition (without aliases) from vm->newDef. I can remove it before merging, if you want to merge just this one. I worry that 2/2 is a bit more complicated.
+ vm->def->fss[i]->info.alias = g_strdup_printf("fs%zu", i); + } + VIR_DEBUG("Setting up Interfaces"); if (virLXCProcessSetupInterfaces(driver, vm->def, &veths) < 0) goto cleanup;
Michal
From: Radoslaw Smigielski <rsmigiel@redhat.com> LXC domains did not assign device aliases to network interface devices during domain startup. This change assigns aliases in the format 'net0', 'net1', etc. to all network interfaces during domain startup, following the same pattern used for console and filesystem devices. Before this patch, virsh dumpxml showed network interfaces without aliases: <interface type='network'> <mac address='52:54:00:12:34:56'/> <source network='default'/> </interface> After this patch, network interfaces have auto-generated aliases: <interface type='network'> <mac address='52:54:00:12:34:56'/> <source network='default'/> <alias name='net0'/> </interface> This ensures all LXC device types (consoles, filesystems, and network interfaces) have consistent alias assigned. Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- src/lxc/lxc_process.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index aae9fcc9dfd1..f93f3f05c394 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1356,6 +1356,12 @@ int virLXCProcessStart(virLXCDriver * driver, vm->def->fss[i]->info.alias = g_strdup_printf("fs%zu", i); } + VIR_DEBUG("Setting up network interface aliases"); + for (i = 0; i < vm->def->nnets; i++) { + g_free(vm->def->nets[i]->info.alias); + vm->def->nets[i]->info.alias = g_strdup_printf("net%zu", i); + } + VIR_DEBUG("Setting up Interfaces"); if (virLXCProcessSetupInterfaces(driver, vm->def, &veths) < 0) goto cleanup; -- 2.54.0
On 6/12/26 07:14, Radosław Śmigielski via Devel wrote:
From: Radoslaw Smigielski <rsmigiel@redhat.com>
LXC domains did not assign device aliases to network interface devices during domain startup.
This change assigns aliases in the format 'net0', 'net1', etc. to all network interfaces during domain startup, following the same pattern used for console and filesystem devices.
Before this patch, virsh dumpxml showed network interfaces without aliases:
<interface type='network'> <mac address='52:54:00:12:34:56'/> <source network='default'/> </interface>
After this patch, network interfaces have auto-generated aliases:
<interface type='network'> <mac address='52:54:00:12:34:56'/> <source network='default'/> <alias name='net0'/> </interface>
This ensures all LXC device types (consoles, filesystems, and network interfaces) have consistent alias assigned.
Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- src/lxc/lxc_process.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index aae9fcc9dfd1..f93f3f05c394 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1356,6 +1356,12 @@ int virLXCProcessStart(virLXCDriver * driver, vm->def->fss[i]->info.alias = g_strdup_printf("fs%zu", i); }
+ VIR_DEBUG("Setting up network interface aliases"); + for (i = 0; i < vm->def->nnets; i++) { + g_free(vm->def->nets[i]->info.alias);
Again, no need to free this.
+ vm->def->nets[i]->info.alias = g_strdup_printf("net%zu", i); + } + VIR_DEBUG("Setting up Interfaces"); if (virLXCProcessSetupInterfaces(driver, vm->def, &veths) < 0) goto cleanup;
This covers domain startup, but there's one more case to cover: device hotplug. For LXC domains it is possible to attach an <interface/> on the fly, see lxcDomainAttachDeviceLive(). Now, attaching and detaching interfaces complicates alias generation a bit, because we're not starting with an empty canvas. For instance, I can start a domain with one interface and it'd get "net0" alias. Then hotplug another one (say, it'd get "net1" alias) and detach "net0" subsequently. At this point we have vm->def->nnets = 1, and hotplugging another interface must NOT assign "net1" alias because it is already used. But we can re-use what other drivers have, say QEMU driver. If you take a look at how aliases are assigned there, you'd find qemuAssignDeviceNetAlias() which iterates over array of existing interfaces and finds next unused index. We can use the same approach in LXC and then just call the function from lxcDomainAttachDeviceNetLive() - the line just after call to virDomainActualNetDefValidate() looks like a good fit. Michal
participants (2)
-
Michal Prívozník -
rsmigiel@redhat.com