From owner-freebsd-hackers@FreeBSD.ORG Wed Mar 4 12:35:39 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 387931065678 for ; Wed, 4 Mar 2009 12:35:39 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.terabit.net.ua (mail.terabit.net.ua [195.137.202.147]) by mx1.freebsd.org (Postfix) with ESMTP id D00C88FC15 for ; Wed, 4 Mar 2009 12:35:38 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from skuns.zoral.com.ua ([91.193.166.194] helo=mail.zoral.com.ua) by mail.terabit.net.ua with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63 (FreeBSD)) (envelope-from ) id 1LeqK0-000CtG-H0; Wed, 04 Mar 2009 14:35:36 +0200 Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id n24CZO8o007853 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 4 Mar 2009 14:35:25 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3) with ESMTP id n24CZOiu049469; Wed, 4 Mar 2009 14:35:24 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3/Submit) id n24CZO6F049468; Wed, 4 Mar 2009 14:35:24 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 4 Mar 2009 14:35:24 +0200 From: Kostik Belousov To: Matthew Fleming Message-ID: <20090304123524.GQ41617@deviant.kiev.zoral.com.ua> References: <06D5F9F6F655AD4C92E28B662F7F853E0275F4E1@seaxch09.desktop.isilon.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="7Zo7F9byXsDd4al8" Content-Disposition: inline In-Reply-To: <06D5F9F6F655AD4C92E28B662F7F853E0275F4E1@seaxch09.desktop.isilon.com> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: ClamAV version 0.94.2, clamav-milter version 0.94.2 on skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=unavailable version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua X-Virus-Scanned: mail.terabit.net.ua 1LeqK0-000CtG-H0 98a262a57b3e4e8a40c407db1c4acce6 X-Terabit: YES Cc: freebsd-hackers@freebsd.org Subject: Re: knotes X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Mar 2009 12:35:39 -0000 --7Zo7F9byXsDd4al8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 03, 2009 at 02:49:45PM -0800, Matthew Fleming wrote: > I am trying to understand the knote system (on 6.1) and I am having some > troubles. >=20 > Specifically, I am confused by the uses of KN_DETACHED and EV_ONESHOT. > >From what I can determine from the comments and code, knotes have a > filterops member, kn_fop. This among other things has a callback to > handle when a note is attached and detached. >=20 > But e.g. in knlist_clear(), when knlist_remove_kq() removes a knote from > the list, it sets KN_DETACHED but does not call the kn_fop->f_detach > routine. Then, in the killkn case, KN_DETACHED is set (again). > Otherwise, EV_ONESHOT is set, presumably so that kqueue_scan() will run > on the knote. However, kqueue_scan() won't call kn_fop->f_detach either > because KN_DETACHED is already set. >=20 > It seems that in knlist_cleardel(), the killkn case should be calling > kn_fop->f_detach before knote_drop(). It also seems that the !killkn > case should not have KN_DETACHED set, which means that > knlist_remove_kq() can't set it. Alternatively, knlist_remove_kq() > should be calling kn_fop->f_detach itself before setting KN_DETACHED. > But in that case I'm not sure I see why there needs to be a use of > EV_ONESHOT. >=20 > So am I reading this wrong, understanding it wrong, or is there a bug in > the code? There are two pathes to each knote, one from the kqueue(2) syscall, and another is from the kernel subsystem. My understanding is that f_detach handler is intended to be called from the syscall path only. For instance, pipe destructor sys_pipe.c:pipeclose() calls knlist_clear, i.e. knlist_cleardel with killkn =3D=3D 0. The detach handler for the pipe removes the knote from the corresponding pipe' knlist. It seems that it is simply wrong to call pipe f_detach from knlist_clear(). --7Zo7F9byXsDd4al8 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAkmudYsACgkQC3+MBN1Mb4hWlgCeKTI3BuN/Tn6n/EQNMzTYLRBh F/cAnA75cfsInrXNvFCpGLLkDGQRrF/C =igUn -----END PGP SIGNATURE----- --7Zo7F9byXsDd4al8--