src/lxc/lxc_domain.c | 59 +++++++++++++++++++++++++++++++++++++++++++ src/lxc/lxc_domain.h | 8 ++++++ src/lxc/lxc_driver.c | 3 +++ src/lxc/lxc_process.c | 8 ++++++ 4 files changed, 78 insertions(+)
From: Radoslaw Smigielski <rsmigiel@redhat.com>
LXC domains did not assign device aliases to filesystem and network
interface during domain startup. Only console devices received
aliases.
This change introduces two new functions:
- virLXCAssignDeviceNetAlias()
- virLXCAssignDeviceFSAlias()
These functions scan existing devices to find the next available
device index. Also ensure correct alias assignment after network
and block device hotplug/unplug operations when a gap can
be introduced in device numbering.
The new functions are called during:
- domain startup virLXCProcessStart()
- device hotplug lxcDomainAttachDeviceNetLive()
Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com>
---
src/lxc/lxc_domain.c | 59 +++++++++++++++++++++++++++++++++++++++++++
src/lxc/lxc_domain.h | 8 ++++++
src/lxc/lxc_driver.c | 3 +++
src/lxc/lxc_process.c | 8 ++++++
4 files changed, 78 insertions(+)
diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c
index afd8d6e9805f..5326c9852073 100644
--- a/src/lxc/lxc_domain.c
+++ b/src/lxc/lxc_domain.c
@@ -25,6 +25,7 @@
#include "virlog.h"
#include "virerror.h"
+#include "virstring.h"
#include "virtime.h"
#include "virsystemd.h"
#include "virinitctl.h"
@@ -375,3 +376,61 @@ virLXCDomainSetRunlevel(virDomainObj *vm,
g_clear_pointer(&data.st_valid, g_free);
return ret;
}
+
+
+void
+virLXCAssignDeviceNetAlias(virDomainDef *def,
+ virDomainNetDef *net)
+{
+ size_t i;
+ int idx = 0;
+
+ if (net->info.alias)
+ return;
+
+ for (i = 0; i < def->nnets; i++) {
+ int thisidx;
+
+ if (!def->nets[i]->info.alias)
+ continue;
+ if (!STRPREFIX(def->nets[i]->info.alias, "net"))
+ continue;
+
+ if (virStrToLong_i(def->nets[i]->info.alias + 3, NULL, 10, &thisidx) < 0)
+ continue;
+
+ if (thisidx >= idx)
+ idx = thisidx + 1;
+ }
+
+ net->info.alias = g_strdup_printf("net%d", idx);
+}
+
+
+void
+virLXCAssignDeviceFSAlias(virDomainDef *def,
+ virDomainFSDef *fs)
+{
+ size_t i;
+ int idx = 0;
+
+ if (fs->info.alias)
+ return;
+
+ for (i = 0; i < def->nfss; i++) {
+ int thisidx;
+
+ if (!def->fss[i]->info.alias)
+ continue;
+ if (!STRPREFIX(def->fss[i]->info.alias, "fs"))
+ continue;
+
+ if (virStrToLong_i(def->fss[i]->info.alias + 2, NULL, 10, &thisidx) < 0)
+ continue;
+
+ if (thisidx >= idx)
+ idx = thisidx + 1;
+ }
+
+ fs->info.alias = g_strdup_printf("fs%d", idx);
+}
diff --git a/src/lxc/lxc_domain.h b/src/lxc/lxc_domain.h
index d22c2ea153a5..a66688397968 100644
--- a/src/lxc/lxc_domain.h
+++ b/src/lxc/lxc_domain.h
@@ -79,3 +79,11 @@ virLXCDomainGetMachineName(virDomainDef *def, pid_t pid);
int
virLXCDomainSetRunlevel(virDomainObj *vm,
int runlevel);
+
+void
+virLXCAssignDeviceNetAlias(virDomainDef *def,
+ virDomainNetDef *net);
+
+void
+virLXCAssignDeviceFSAlias(virDomainDef *def,
+ virDomainFSDef *fs);
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index b59c080da908..5be087de922a 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -3502,6 +3502,9 @@ lxcDomainAttachDeviceNetLive(virLXCDriver *driver,
if (virDomainActualNetDefValidate(net) < 0)
return -1;
+ /* Assign alias to the new network interface */
+ virLXCAssignDeviceNetAlias(vm->def, net);
+
actualType = virDomainNetGetActualType(net);
switch (actualType) {
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index cac49af6e2b2..466ce07afd03 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -1349,6 +1349,14 @@ 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++)
+ virLXCAssignDeviceFSAlias(vm->def, vm->def->fss[i]);
+
+ VIR_DEBUG("Setting up network interface aliases");
+ for (i = 0; i < vm->def->nnets; i++)
+ virLXCAssignDeviceNetAlias(vm->def, vm->def->nets[i]);
+
VIR_DEBUG("Setting up Interfaces");
if (virLXCProcessSetupInterfaces(driver, vm->def, &veths) < 0)
goto cleanup;
--
2.54.0
On 6/19/26 10:56, Radosław Śmigielski via Devel wrote:
> From: Radoslaw Smigielski <rsmigiel@redhat.com>
>
> LXC domains did not assign device aliases to filesystem and network
> interface during domain startup. Only console devices received
> aliases.
>
> This change introduces two new functions:
> - virLXCAssignDeviceNetAlias()
> - virLXCAssignDeviceFSAlias()
>
> These functions scan existing devices to find the next available
> device index. Also ensure correct alias assignment after network
> and block device hotplug/unplug operations when a gap can
> be introduced in device numbering.
>
> The new functions are called during:
> - domain startup virLXCProcessStart()
> - device hotplug lxcDomainAttachDeviceNetLive()
>
> Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com>
> ---
> src/lxc/lxc_domain.c | 59 +++++++++++++++++++++++++++++++++++++++++++
> src/lxc/lxc_domain.h | 8 ++++++
> src/lxc/lxc_driver.c | 3 +++
> src/lxc/lxc_process.c | 8 ++++++
> 4 files changed, 78 insertions(+)
>
> diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c
> index afd8d6e9805f..5326c9852073 100644
> --- a/src/lxc/lxc_domain.c
> +++ b/src/lxc/lxc_domain.c
> @@ -25,6 +25,7 @@
>
> #include "virlog.h"
> #include "virerror.h"
> +#include "virstring.h"
> #include "virtime.h"
> #include "virsystemd.h"
> #include "virinitctl.h"
> @@ -375,3 +376,61 @@ virLXCDomainSetRunlevel(virDomainObj *vm,
> g_clear_pointer(&data.st_valid, g_free);
> return ret;
> }
> +
> +
> +void
> +virLXCAssignDeviceNetAlias(virDomainDef *def,
> + virDomainNetDef *net)
> +{
> + size_t i;
> + int idx = 0;
> +
> + if (net->info.alias)
> + return;
> +
> + for (i = 0; i < def->nnets; i++) {
> + int thisidx;
> +
> + if (!def->nets[i]->info.alias)
> + continue;
> + if (!STRPREFIX(def->nets[i]->info.alias, "net"))
> + continue;
> +
> + if (virStrToLong_i(def->nets[i]->info.alias + 3, NULL, 10, &thisidx) < 0)
> + continue;
There's a macro that combines STRPREFIX() + this offsetting of a string:
STRSKIP().
> +
> + if (thisidx >= idx)
> + idx = thisidx + 1;
> + }
> +
> + net->info.alias = g_strdup_printf("net%d", idx);
> +}
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
and merged.
Michal
On Fri, 3 Jul 2026 at 12:35, Michal Prívozník <mprivozn@redhat.com> wrote:
> On 6/19/26 10:56, Radosław Śmigielski via Devel wrote:
> > From: Radoslaw Smigielski <rsmigiel@redhat.com>
> >
> > LXC domains did not assign device aliases to filesystem and network
> > interface during domain startup. Only console devices received
> > aliases.
> >
> > This change introduces two new functions:
> > - virLXCAssignDeviceNetAlias()
> > - virLXCAssignDeviceFSAlias()
> >
> > These functions scan existing devices to find the next available
> > device index. Also ensure correct alias assignment after network
> > and block device hotplug/unplug operations when a gap can
> > be introduced in device numbering.
> >
> > The new functions are called during:
> > - domain startup virLXCProcessStart()
> > - device hotplug lxcDomainAttachDeviceNetLive()
> >
> > Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com>
> > ---
> > src/lxc/lxc_domain.c | 59 +++++++++++++++++++++++++++++++++++++++++++
> > src/lxc/lxc_domain.h | 8 ++++++
> > src/lxc/lxc_driver.c | 3 +++
> > src/lxc/lxc_process.c | 8 ++++++
> > 4 files changed, 78 insertions(+)
> >
> > diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c
> > index afd8d6e9805f..5326c9852073 100644
> > --- a/src/lxc/lxc_domain.c
> > +++ b/src/lxc/lxc_domain.c
> > @@ -25,6 +25,7 @@
> >
> > #include "virlog.h"
> > #include "virerror.h"
> > +#include "virstring.h"
> > #include "virtime.h"
> > #include "virsystemd.h"
> > #include "virinitctl.h"
> > @@ -375,3 +376,61 @@ virLXCDomainSetRunlevel(virDomainObj *vm,
> > g_clear_pointer(&data.st_valid, g_free);
> > return ret;
> > }
> > +
> > +
> > +void
> > +virLXCAssignDeviceNetAlias(virDomainDef *def,
> > + virDomainNetDef *net)
> > +{
> > + size_t i;
> > + int idx = 0;
> > +
> > + if (net->info.alias)
> > + return;
> > +
> > + for (i = 0; i < def->nnets; i++) {
> > + int thisidx;
> > +
> > + if (!def->nets[i]->info.alias)
> > + continue;
> > + if (!STRPREFIX(def->nets[i]->info.alias, "net"))
> > + continue;
> > +
> > + if (virStrToLong_i(def->nets[i]->info.alias + 3, NULL, 10,
> &thisidx) < 0)
> > + continue;
>
> There's a macro that combines STRPREFIX() + this offsetting of a string:
> STRSKIP().
>
> > +
> > + if (thisidx >= idx)
> > + idx = thisidx + 1;
> > + }
> > +
> > + net->info.alias = g_strdup_printf("net%d", idx);
> > +}
>
>
> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
>
> and merged.
>
> Michal
>
>
Shall we add this to v12.6.0 (unreleased) NEWS.rst file?
----------------------
< Tℏanks | Radek >
On Fri, 3 Jul 2026 at 12:35, Michal Prívozník <mprivozn@redhat.com> wrote:
>
> There's a macro that combines STRPREFIX() + this offsetting of a string:
> STRSKIP().
>
> > +
> > + if (thisidx >= idx)
> > + idx = thisidx + 1;
> > + }
> > +
> > + net->info.alias = g_strdup_printf("net%d", idx);
> > +}
>
>
> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
>
> and merged.
>
> Michal
>
Thanks for the merge and for the code hint !
-------------
< Radek >
© 2016 - 2026 Red Hat, Inc.