Re: [RFC] Create ptmx as a device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 01, 2011 at 03:52:48AM -0500, Serge Hallyn wrote:
> Quoting Daniel Veillard (veillard@xxxxxxxxxx):
> > 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@xxxxxxxxxxxxx>
> > > ---
> > >  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@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]