[libvirt] [RFC] Create ptmx as a device

Hi, I'm seeing an issue with udev and libvirt-lxc. Libvirt-lxc creates /dev/ptmx as a symlink to /dev/pts/ptmx. When udev starts up, it checks the device type, sees ptmx is 'not right', and replaces it with a 'proper' ptmx. In lxc, /dev/ptmx is bind-mounted from /dev/pts/ptmx instead of being symlinked, so udev sees the right device type and leaves it alone. A patch like the following seems to work for me. Would there be any objections to this?
From 4c5035de52de7e06a0de9c5d0bab8c87a806cba7 Mon Sep 17 00:00:00 2001 From: Ubuntu <ubuntu@domU-12-31-39-14-F0-B3.compute-1.internal> Date: Wed, 31 Aug 2011 18:15:54 +0000 Subject: [PATCH 1/1] make ptmx a bind mount rather than symlink
udev on some systems checks the device type of /dev/ptmx, and replaces it if not as expected. The symlink created by libvirt-lxc therefore gets replaced. By creating it as a bind mount, the device type is correct and udev leaves it alone. Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com> --- src/lxc/lxc_container.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index e425328..6991aec 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -543,18 +543,18 @@ static int lxcContainerPopulateDevices(void) } } + dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX); + if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 || + chmod("/dev/ptmx", 0666)) { + virReportSystemError(errno, "%s", + _("Failed to make device /dev/ptmx")); + return -1; + } + if (access("/dev/pts/ptmx", W_OK) == 0) { - if (symlink("/dev/pts/ptmx", "/dev/ptmx") < 0) { - virReportSystemError(errno, "%s", - _("Failed to create symlink /dev/ptmx to /dev/pts/ptmx")); - return -1; - } - } else { - dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX); - if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 || - chmod("/dev/ptmx", 0666)) { + if (mount("/dev/pts/ptmx", "/dev/ptmx", "ptmx", MS_BIND, NULL) < 0) { virReportSystemError(errno, "%s", - _("Failed to make device /dev/ptmx")); + _("Failed to bind-mount /dev/ptmx to /dev/pts/ptmx")); return -1; } } -- 1.7.5.4

On Wed, Aug 31, 2011 at 01:18:33PM -0500, Serge Hallyn wrote:
Hi,
I'm seeing an issue with udev and libvirt-lxc. Libvirt-lxc creates /dev/ptmx as a symlink to /dev/pts/ptmx. When udev starts up, it checks the device type, sees ptmx is 'not right', and replaces it with a 'proper' ptmx.
In lxc, /dev/ptmx is bind-mounted from /dev/pts/ptmx instead of being symlinked, so udev sees the right device type and leaves it alone.
A patch like the following seems to work for me. Would there be any objections to this?
From 4c5035de52de7e06a0de9c5d0bab8c87a806cba7 Mon Sep 17 00:00:00 2001 From: Ubuntu <ubuntu@domU-12-31-39-14-F0-B3.compute-1.internal> Date: Wed, 31 Aug 2011 18:15:54 +0000 Subject: [PATCH 1/1] make ptmx a bind mount rather than symlink
udev on some systems checks the device type of /dev/ptmx, and replaces it if not as expected. The symlink created by libvirt-lxc therefore gets replaced. By creating it as a bind mount, the device type is correct and udev leaves it alone.
Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com> --- src/lxc/lxc_container.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index e425328..6991aec 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -543,18 +543,18 @@ static int lxcContainerPopulateDevices(void) } }
+ dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX); + if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 || + chmod("/dev/ptmx", 0666)) { + virReportSystemError(errno, "%s", + _("Failed to make device /dev/ptmx")); + return -1; + } + if (access("/dev/pts/ptmx", W_OK) == 0) { - if (symlink("/dev/pts/ptmx", "/dev/ptmx") < 0) { - virReportSystemError(errno, "%s", - _("Failed to create symlink /dev/ptmx to /dev/pts/ptmx")); - return -1; - } - } else { - dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX); - if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 || - chmod("/dev/ptmx", 0666)) { + if (mount("/dev/pts/ptmx", "/dev/ptmx", "ptmx", MS_BIND, NULL) < 0) { virReportSystemError(errno, "%s", - _("Failed to make device /dev/ptmx")); + _("Failed to bind-mount /dev/ptmx to /dev/pts/ptmx")); return -1; } }
Hum, if we do a mount, I would expect to do an unmount somewhere. Also the lifetime of the mount and the symlink is really different, a recursive remove when destroying the container would lead to no resource leak but I think that for a bind mount we absolutely have to clean it up. Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

Quoting Daniel Veillard (veillard@redhat.com):
On Wed, Aug 31, 2011 at 01:18:33PM -0500, Serge Hallyn wrote:
Hi,
I'm seeing an issue with udev and libvirt-lxc. Libvirt-lxc creates /dev/ptmx as a symlink to /dev/pts/ptmx. When udev starts up, it checks the device type, sees ptmx is 'not right', and replaces it with a 'proper' ptmx.
In lxc, /dev/ptmx is bind-mounted from /dev/pts/ptmx instead of being symlinked, so udev sees the right device type and leaves it alone.
A patch like the following seems to work for me. Would there be any objections to this?
From 4c5035de52de7e06a0de9c5d0bab8c87a806cba7 Mon Sep 17 00:00:00 2001 From: Ubuntu <ubuntu@domU-12-31-39-14-F0-B3.compute-1.internal> Date: Wed, 31 Aug 2011 18:15:54 +0000 Subject: [PATCH 1/1] make ptmx a bind mount rather than symlink
udev on some systems checks the device type of /dev/ptmx, and replaces it if not as expected. The symlink created by libvirt-lxc therefore gets replaced. By creating it as a bind mount, the device type is correct and udev leaves it alone.
Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com> --- src/lxc/lxc_container.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index e425328..6991aec 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -543,18 +543,18 @@ static int lxcContainerPopulateDevices(void) } }
+ dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX); + if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 || + chmod("/dev/ptmx", 0666)) { + virReportSystemError(errno, "%s", + _("Failed to make device /dev/ptmx")); + return -1; + } + if (access("/dev/pts/ptmx", W_OK) == 0) { - if (symlink("/dev/pts/ptmx", "/dev/ptmx") < 0) { - virReportSystemError(errno, "%s", - _("Failed to create symlink /dev/ptmx to /dev/pts/ptmx")); - return -1; - } - } else { - dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX); - if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 || - chmod("/dev/ptmx", 0666)) { + if (mount("/dev/pts/ptmx", "/dev/ptmx", "ptmx", MS_BIND, NULL) < 0) { virReportSystemError(errno, "%s", - _("Failed to make device /dev/ptmx")); + _("Failed to bind-mount /dev/ptmx to /dev/pts/ptmx")); return -1; } }
Hum, if we do a mount, I would expect to do an unmount somewhere. Also the lifetime of the mount and the symlink is really different, a recursive remove when destroying the container would lead to no resource leak but I think that for a bind mount we absolutely have to clean it up.
This code is being done in a private mount namespace, so the mount will get automatically cleaned up when that namespace exits. thanks, -serge

On Thu, Sep 01, 2011 at 03:52:48AM -0500, Serge Hallyn wrote:
Quoting Daniel Veillard (veillard@redhat.com):
On Wed, Aug 31, 2011 at 01:18:33PM -0500, Serge Hallyn wrote:
Hi,
I'm seeing an issue with udev and libvirt-lxc. Libvirt-lxc creates /dev/ptmx as a symlink to /dev/pts/ptmx. When udev starts up, it checks the device type, sees ptmx is 'not right', and replaces it with a 'proper' ptmx.
In lxc, /dev/ptmx is bind-mounted from /dev/pts/ptmx instead of being symlinked, so udev sees the right device type and leaves it alone.
A patch like the following seems to work for me. Would there be any objections to this?
From 4c5035de52de7e06a0de9c5d0bab8c87a806cba7 Mon Sep 17 00:00:00 2001 From: Ubuntu <ubuntu@domU-12-31-39-14-F0-B3.compute-1.internal> Date: Wed, 31 Aug 2011 18:15:54 +0000 Subject: [PATCH 1/1] make ptmx a bind mount rather than symlink
udev on some systems checks the device type of /dev/ptmx, and replaces it if not as expected. The symlink created by libvirt-lxc therefore gets replaced. By creating it as a bind mount, the device type is correct and udev leaves it alone.
Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com> --- src/lxc/lxc_container.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index e425328..6991aec 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -543,18 +543,18 @@ static int lxcContainerPopulateDevices(void) } }
+ dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX); + if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 || + chmod("/dev/ptmx", 0666)) { + virReportSystemError(errno, "%s", + _("Failed to make device /dev/ptmx")); + return -1; + } + if (access("/dev/pts/ptmx", W_OK) == 0) { - if (symlink("/dev/pts/ptmx", "/dev/ptmx") < 0) { - virReportSystemError(errno, "%s", - _("Failed to create symlink /dev/ptmx to /dev/pts/ptmx")); - return -1; - } - } else { - dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX); - if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 || - chmod("/dev/ptmx", 0666)) { + if (mount("/dev/pts/ptmx", "/dev/ptmx", "ptmx", MS_BIND, NULL) < 0) { virReportSystemError(errno, "%s", - _("Failed to make device /dev/ptmx")); + _("Failed to bind-mount /dev/ptmx to /dev/pts/ptmx")); return -1; } }
Hum, if we do a mount, I would expect to do an unmount somewhere. Also the lifetime of the mount and the symlink is really different, a recursive remove when destroying the container would lead to no resource leak but I think that for a bind mount we absolutely have to clean it up.
This code is being done in a private mount namespace, so the mount will get automatically cleaned up when that namespace exits.
Ah, okay that looks more reasonable then, thanks Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Thu, Sep 01, 2011 at 02:13:16PM +0800, Daniel Veillard wrote:
On Wed, Aug 31, 2011 at 01:18:33PM -0500, Serge Hallyn wrote:
Hi,
I'm seeing an issue with udev and libvirt-lxc. Libvirt-lxc creates /dev/ptmx as a symlink to /dev/pts/ptmx. When udev starts up, it checks the device type, sees ptmx is 'not right', and replaces it with a 'proper' ptmx.
In lxc, /dev/ptmx is bind-mounted from /dev/pts/ptmx instead of being symlinked, so udev sees the right device type and leaves it alone.
A patch like the following seems to work for me. Would there be any objections to this?
From 4c5035de52de7e06a0de9c5d0bab8c87a806cba7 Mon Sep 17 00:00:00 2001 From: Ubuntu <ubuntu@domU-12-31-39-14-F0-B3.compute-1.internal> Date: Wed, 31 Aug 2011 18:15:54 +0000 Subject: [PATCH 1/1] make ptmx a bind mount rather than symlink
udev on some systems checks the device type of /dev/ptmx, and replaces it if not as expected. The symlink created by libvirt-lxc therefore gets replaced. By creating it as a bind mount, the device type is correct and udev leaves it alone.
Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com> --- src/lxc/lxc_container.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index e425328..6991aec 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -543,18 +543,18 @@ static int lxcContainerPopulateDevices(void) } }
+ dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX); + if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 || + chmod("/dev/ptmx", 0666)) { + virReportSystemError(errno, "%s", + _("Failed to make device /dev/ptmx")); + return -1; + } + if (access("/dev/pts/ptmx", W_OK) == 0) { - if (symlink("/dev/pts/ptmx", "/dev/ptmx") < 0) { - virReportSystemError(errno, "%s", - _("Failed to create symlink /dev/ptmx to /dev/pts/ptmx")); - return -1; - } - } else { - dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX); - if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 || - chmod("/dev/ptmx", 0666)) { + if (mount("/dev/pts/ptmx", "/dev/ptmx", "ptmx", MS_BIND, NULL) < 0) { virReportSystemError(errno, "%s", - _("Failed to make device /dev/ptmx")); + _("Failed to bind-mount /dev/ptmx to /dev/pts/ptmx")); return -1; } }
Hum, if we do a mount, I would expect to do an unmount somewhere. Also the lifetime of the mount and the symlink is really different, a recursive remove when destroying the container would lead to no resource leak but I think that for a bind mount we absolutely have to clean it up.
No need to worry about this, everything in 'lxc_container.c' is executed inside the container filesystem namespace. When the last process in the container exits, the kernel automatically cleans up all the mounts for us. Regards, Daniel -- |: 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 :|

On Wed, Aug 31, 2011 at 01:18:33PM -0500, Serge Hallyn wrote:
Hi,
I'm seeing an issue with udev and libvirt-lxc. Libvirt-lxc creates /dev/ptmx as a symlink to /dev/pts/ptmx. When udev starts up, it checks the device type, sees ptmx is 'not right', and replaces it with a 'proper' ptmx.
Doh, IMHO that's a bug in udev, but what the hell, its easy enough for us to fix as you demonstrate.
In lxc, /dev/ptmx is bind-mounted from /dev/pts/ptmx instead of being symlinked, so udev sees the right device type and leaves it alone.
A patch like the following seems to work for me. Would there be any objections to this?
From 4c5035de52de7e06a0de9c5d0bab8c87a806cba7 Mon Sep 17 00:00:00 2001 From: Ubuntu <ubuntu@domU-12-31-39-14-F0-B3.compute-1.internal> Date: Wed, 31 Aug 2011 18:15:54 +0000 Subject: [PATCH 1/1] make ptmx a bind mount rather than symlink
udev on some systems checks the device type of /dev/ptmx, and replaces it if not as expected. The symlink created by libvirt-lxc therefore gets replaced. By creating it as a bind mount, the device type is correct and udev leaves it alone.
Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com> --- src/lxc/lxc_container.c | 20 ++++++++++---------- 1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index e425328..6991aec 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -543,18 +543,18 @@ static int lxcContainerPopulateDevices(void) } }
+ dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX); + if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 || + chmod("/dev/ptmx", 0666)) { + virReportSystemError(errno, "%s", + _("Failed to make device /dev/ptmx")); + return -1; + } + if (access("/dev/pts/ptmx", W_OK) == 0) { - if (symlink("/dev/pts/ptmx", "/dev/ptmx") < 0) { - virReportSystemError(errno, "%s", - _("Failed to create symlink /dev/ptmx to /dev/pts/ptmx")); - return -1; - } - } else { - dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX); - if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 || - chmod("/dev/ptmx", 0666)) { + if (mount("/dev/pts/ptmx", "/dev/ptmx", "ptmx", MS_BIND, NULL) < 0) { virReportSystemError(errno, "%s", - _("Failed to make device /dev/ptmx")); + _("Failed to bind-mount /dev/ptmx to /dev/pts/ptmx")); return -1; } }
ACK Daniel -- |: 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 :|

On 09/01/2011 03:00 AM, Daniel P. Berrange wrote:
On Wed, Aug 31, 2011 at 01:18:33PM -0500, Serge Hallyn wrote:
Hi,
I'm seeing an issue with udev and libvirt-lxc. Libvirt-lxc creates /dev/ptmx as a symlink to /dev/pts/ptmx. When udev starts up, it checks the device type, sees ptmx is 'not right', and replaces it with a 'proper' ptmx.
ACK
Pushed. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (4)
-
Daniel P. Berrange
-
Daniel Veillard
-
Eric Blake
-
Serge Hallyn