libvirt: [PATCH] libxl: Check for control_d string to decide about dom0
I have been looking into a bug report (see BugLink) which reported libvirt to fail starting inside a Xen guest. Upon further investigation I found that some tools that help monitoring Xen guests will mount xenfs to /proc/xen. This will create a capabilities files there even if the guest is not dom0. However it will return nothing when reading from it.
Ian, just to sanity check myself. I looked at the xenfs code and to me there only seem to be those two outcomes (either "control_d" for running in dom0 or notrhing if not).
With the following patch applied, libvirt starts up correctly in the normal guests (with xenfs mounted) without initializing libxl. And also in dom0 where it still enables the libxl driver (if the xl toolstack is selected).
-Stefan
Quoted 1 line
From
f11949caca6dfe1a802472a2a6d4fe760115ccc6Mon Sep 17 00:00:00 2001
From: Stefan Bader <[email protected]>
Date: Wed, 12 Mar 2014 11:37:16 +0100
Subject: [PATCH] libxl: Check for control_d string to decide about dom0
As soon as any guest mounts xenfs to /proc/xen, there is a capabilities file in that directory. However it returns nothing when reading from it. Change the test to actually check the contents of the file.
--- src/libxl/libxl_driver.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
src/libxl/libxl_driver.c +12 -2
@@ -944,6 +944,7 @@ libxlDriverShouldLoad(bool privileged)bool ret = false;virCommandPtr cmd;int status; +char *output =NULL ;/* Don't load if non-root */ if (!privileged) {
@@ -951,8 +952,17 @@ libxlDriverShouldLoad(bool privileged)return ret; } -/* Don't load if not running on a Xen control domain (dom0) */ -if (!virFileExists ("/proc/xen/capabilities" )) { +/* +* Don't load if not running on a Xen control domain (dom0). It is not +* sufficient to check for the file to exist as any guest can mount +* xenfs to /proc/xen. +*/ + status =virFileReadAll ("/proc/xen/capabilities" ,10. &output); +if (status >=0 ) { + status =strncmp (output,"control_d" ,9 ); + } +VIR_FREE (output); +if (status) {VIR_INFO ("No Xen capabilities detected, probably not running " "in a Xen Dom0. Disabling libxenlight driver" );
Signature · 1 line
1.7.9.5
Quoted 55 lines · Stefan Bader
I have been looking into a bug report (see BugLink) which reported libvirt to fail starting inside a Xen guest. Upon further investigation I found that some tools that help monitoring Xen guests will mount xenfs to
/proc/xen. This will create a capabilities files there even if the guest is not dom0. However it will return nothing when reading from it.Ian, just to sanity check myself. I looked at the xenfs code and to me there only seem to be those two outcomes (either "
control_d" for running in dom0 or notrhing if not).With the following patch applied, libvirt starts up correctly in the normal guests (with xenfs mounted) without initializing libxl. And also in dom0 where it still enables the libxl driver (if the xl toolstack is selected).
-Stefan
Quoted 1 line
From
f11949caca6dfe1a802472a2a6d4fe760115ccc6Mon Sep 17 00:00:00 2001From: Stefan Bader <[email protected]>
Date: Wed, 12 Mar 2014 11:37:16 +0100
Subject: [PATCH] libxl: Check forcontrol_dstring to decide about dom0As soon as any guest mounts xenfs to
/proc/xen, there is a capabilities file in that directory. However it returns nothing when reading from it. Change the test to actually check the contents of the file.Signed-off-by Stefan Bader <[email protected]>--- src/libxl/libxl_driver.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)src/libxl/libxl_driver.c +4
-2@@ -944,6 +944,7 @@ libxlDriverShouldLoad(bool privileged)bool ret = false;virCommandPtr cmd;int status; +char *output =NULL ;/* Don't load if non-root */ if (!privileged) {@@ -951,8 +952,17 @@ libxlDriverShouldLoad(bool privileged)return ret; } -/* Don't load if not running on a Xen control domain (dom0) */ -if (!virFileExists ("/proc/xen/capabilities" )) { +/* +* Don't load if not running on a Xen control domain (dom0). It is not +* sufficient to check for the file to exist as any guest can mount
src/libxl/libxl_driver.c libxlDriverShouldLoad(bool privileged) · line 967
Quoted 10 lines
src/libxl/libxl_driver.c +8
-0+* xenfs to /proc/xen. +*/ + status =virFileReadAll ("/proc/xen/capabilities" ,10. &output); +if (status >=0 ) { + status =strncmp (output,"control_d" ,9 ); + } +VIR_FREE (output); +if (status) {VIR_INFO ("No Xen capabilities detected, probably not running " "in a Xen Dom0. Disabling libxenlight driver" );
This looks reasonable to me. I recall that the initscripts for the old XenD daemon would also check for this file to decide whether to start or not.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 6 lines · Stefan Bader
I have been looking into a bug report (see BugLink) which reported libvirt to fail starting inside a Xen guest. Upon further investigation I found that some tools that help monitoring Xen guests will mount xenfs to
/proc/xen. This will create a capabilities files there even if the guest is not dom0. However it will return nothing when reading from it.
This seems consistent with the xencommons initscript which does:
# run this script only in dom0:
# no capabilities file in xenlinux domU kernel
# empty capabilities file in pv_ops domU kernel
if test -f /proc/xen/capabilities && \
! grep -q "control_d" /proc/xen/capabilities ; then
exit 0
fiQuoted 42 lines
Ian, just to sanity check myself. I looked at the xenfs code and to me there only seem to be those two outcomes (either "
control_d" for running in dom0 or notrhing if not).With the following patch applied, libvirt starts up correctly in the normal guests (with xenfs mounted) without initializing libxl. And also in dom0 where it still enables the libxl driver (if the xl toolstack is selected).
-Stefan
From
f11949caca6dfe1a802472a2a6d4fe760115ccc6Mon Sep 17 00:00:00 2001
From: Stefan Bader <[email protected]>
Date: Wed, 12 Mar 2014 11:37:16 +0100
Subject: [PATCH] libxl: Check forcontrol_dstring to decide about dom0As soon as any guest mounts xenfs to
/proc/xen, there is a capabilities file in that directory. However it returns nothing when reading from it. Change the test to actually check the contents of the file.Signed-off-by Stefan Bader <[email protected]>--- src/libxl/libxl_driver.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)src/libxl/libxl_driver.c +1
-0@@ -944,6 +944,7 @@ libxlDriverShouldLoad(bool privileged)bool ret = false;virCommandPtr cmd;int status; +char *output =NULL ;/* Don't load if non-root */ if (!privileged) {@@ -951,8 +952,17 @@ libxlDriverShouldLoad(bool privileged)return ret;
src/libxl/libxl_driver.c libxlDriverShouldLoad(bool privileged) · line 960
Quoted 10 lines
src/libxl/libxl_driver.c +6
-2} -/* Don't load if not running on a Xen control domain (dom0) */ -if (!virFileExists ("/proc/xen/capabilities" )) { +/* +* Don't load if not running on a Xen control domain (dom0). It is not +* sufficient to check for the file to exist as any guest can mount +* xenfs to /proc/xen. +*/ + status =virFileReadAll ("/proc/xen/capabilities" ,10. &output);
Is this "." supposed to be a ","?
Quoted 8 lines
src/libxl/libxl_driver.c +5
-0+if (status >=0 ) { + status =strncmp (output,"control_d" ,9 ); + } +VIR_FREE (output); +if (status) {VIR_INFO ("No Xen capabilities detected, probably not running " "in a Xen Dom0. Disabling libxenlight driver" );
Quoted 61 lines · Ian Campbell
Quoted 6 lines · Stefan Bader
I have been looking into a bug report (see BugLink) which reported libvirt to fail starting inside a Xen guest. Upon further investigation I found that some tools that help monitoring Xen guests will mount xenfs to
/proc/xen. This will create a capabilities files there even if the guest is not dom0. However it will return nothing when reading from it.This seems consistent with the xencommons initscript which does:
# run this script only in dom0: # no capabilities file in xenlinux domU kernel # empty capabilities file in pv_ops domU kernel if test -f /proc/xen/capabilities && \ ! grep -q "control_d" /proc/xen/capabilities ; then exit 0 fiQuoted 44 lines
Ian, just to sanity check myself. I looked at the xenfs code and to me there only seem to be those two outcomes (either "
control_d" for running in dom0 or notrhing if not).With the following patch applied, libvirt starts up correctly in the normal guests (with xenfs mounted) without initializing libxl. And also in dom0 where it still enables the libxl driver (if the xl toolstack is selected).
-Stefan
From
f11949caca6dfe1a802472a2a6d4fe760115ccc6Mon Sep 17 00:00:00 2001
From: Stefan Bader <[email protected]>
Date: Wed, 12 Mar 2014 11:37:16 +0100
Subject: [PATCH] libxl: Check forcontrol_dstring to decide about dom0As soon as any guest mounts xenfs to
/proc/xen, there is a capabilities file in that directory. However it returns nothing when reading from it. Change the test to actually check the contents of the file.Signed-off-by Stefan Bader <[email protected]>--- src/libxl/libxl_driver.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)src/libxl/libxl_driver.c +1
-0@@ -944,6 +944,7 @@ libxlDriverShouldLoad(bool privileged)bool ret = false;virCommandPtr cmd;int status; +char *output =NULL ;/* Don't load if non-root */ if (!privileged) {@@ -951,8 +952,17 @@ libxlDriverShouldLoad(bool privileged)return ret; }
Quoted 10 lines
src/libxl/libxl_driver.c libxlDriverShouldLoad(bool privileged) · line 960
Quoted 8 lines
src/libxl/libxl_driver.c +6
-2-/* Don't load if not running on a Xen control domain (dom0) */ -if (!virFileExists ("/proc/xen/capabilities" )) { +/* +* Don't load if not running on a Xen control domain (dom0). It is not +* sufficient to check for the file to exist as any guest can mount +* xenfs to /proc/xen. +*/ + status =virFileReadAll ("/proc/xen/capabilities" ,10. &output);Is this "." supposed to be a ","?
Darn, I thought I had fixed that. Unfortunately in the wrong place. Yes, that should be a ",". Sorry
-Stefan
Quoted 11 lines
Quoted 9 lines
src/libxl/libxl_driver.c +5
-0+if (status >=0 ) { + status =strncmp (output,"control_d" ,9 ); + } +VIR_FREE (output); +if (status) {VIR_INFO ("No Xen capabilities detected, probably not running " "in a Xen Dom0. Disabling libxenlight driver" );
Quoted 76 lines · Stefan Bader
Quoted 62 lines · Ian Campbell
Quoted 7 lines · Stefan Bader
I have been looking into a bug report (see BugLink) which reported libvirt to fail starting inside a Xen guest. Upon further investigation I found that some tools that help monitoring Xen guests will mount xenfs to
/proc/xen. This will create a capabilities files there even if the guest is not dom0. However it will return nothing when reading from it.This seems consistent with the xencommons initscript which does:
# run this script only in dom0: # no capabilities file in xenlinux domU kernel # empty capabilities file in pv_ops domU kernel if test -f /proc/xen/capabilities && \ ! grep -q "control_d" /proc/xen/capabilities ; then exit 0 fiQuoted 43 lines
Ian, just to sanity check myself. I looked at the xenfs code and to me there only seem to be those two outcomes (either "
control_d" for running in dom0 or notrhing if not).With the following patch applied, libvirt starts up correctly in the normal guests (with xenfs mounted) without initializing libxl. And also in dom0 where it still enables the libxl driver (if the xl toolstack is selected).
-Stefan
From
f11949caca6dfe1a802472a2a6d4fe760115ccc6Mon Sep 17 00:00:00 2001
From: Stefan Bader <[email protected]>
Date: Wed, 12 Mar 2014 11:37:16 +0100
Subject: [PATCH] libxl: Check forcontrol_dstring to decide about dom0As soon as any guest mounts xenfs to
/proc/xen, there is a capabilities file in that directory. However it returns nothing when reading from it. Change the test to actually check the contents of the file.Signed-off-by Stefan Bader <[email protected]>--- src/libxl/libxl_driver.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)src/libxl/libxl_driver.c +1
-0@@ -944,6 +944,7 @@ libxlDriverShouldLoad(bool privileged)bool ret = false;virCommandPtr cmd;int status; +char *output =NULL ;/* Don't load if non-root */ if (!privileged) {@@ -951,8 +952,17 @@ libxlDriverShouldLoad(bool privileged)return ret; }Quoted 11 lines
src/libxl/libxl_driver.c libxlDriverShouldLoad(bool privileged) · line 968
Quoted 9 lines
src/libxl/libxl_driver.c +6
-2-/* Don't load if not running on a Xen control domain (dom0) */ -if (!virFileExists ("/proc/xen/capabilities" )) { +/* +* Don't load if not running on a Xen control domain (dom0). It is not +* sufficient to check for the file to exist as any guest can mount +* xenfs to /proc/xen. +*/ + status =virFileReadAll ("/proc/xen/capabilities" ,10. &output);Is this "." supposed to be a ","?
Quoted 3 lines
Darn, I thought I had fixed that. Unfortunately in the wrong place. Yes, that should be a ",". Sorry
I fixed your typo and pushed the patch. Thanks!
Regards,
Jim