From owner-freebsd-arch@FreeBSD.ORG Wed Oct 31 21:02:52 2007 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8F86416A417 for ; Wed, 31 Oct 2007 21:02:52 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from gnome.kiev.sovam.com (gnome.kiev.sovam.com [212.109.32.24]) by mx1.freebsd.org (Postfix) with ESMTP id F288E13C4A5 for ; Wed, 31 Oct 2007 21:02:51 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from relay02.kiev.sovam.com ([62.64.120.197]) by gnome.kiev.sovam.com with esmtp (Exim 4.67 (FreeBSD)) (envelope-from ) id 1InF9Z-0007BU-R1 for freebsd-arch@freebsd.org; Wed, 31 Oct 2007 17:06:45 +0200 Received: from [212.82.216.226] (helo=deviant.kiev.zoral.com.ua) by relay02.kiev.sovam.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.67) (envelope-from ) id 1InF9S-0009J9-Tc for freebsd-arch@freebsd.org; Wed, 31 Oct 2007 17:06:45 +0200 Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.1/8.14.1) with ESMTP id l9VF6NDi000409 for ; Wed, 31 Oct 2007 17:06:23 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.1/8.14.1/Submit) id l9VF6KgE000408 for freebsd-arch@freebsd.org; Wed, 31 Oct 2007 17:06:20 +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, 31 Oct 2007 17:06:20 +0200 From: Kostik Belousov To: freebsd-arch@freebsd.org Message-ID: <20071031150620.GT37471@deviant.kiev.zoral.com.ua> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="dLXnlYbDJNCwF3YM" Content-Disposition: inline User-Agent: Mutt/1.4.2.3i X-Scanner-Signature: 4fe2b897d4d72954524b6b73d18f8617 X-DrWeb-checked: yes X-SpamTest-Envelope-From: kostikbel@gmail.com X-SpamTest-Group-ID: 00000000 X-SpamTest-Info: Profiles 1716 [Oct 31 2007] X-SpamTest-Info: helo_type=3 X-SpamTest-Info: {received from trusted relay: not dialup} X-SpamTest-Method: none X-SpamTest-Method: Local Lists X-SpamTest-Rate: 0 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0255], KAS30/Release Subject: fdclone KPI X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Oct 2007 21:02:52 -0000 --dLXnlYbDJNCwF3YM Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Dear arch@ readers, with the important help from Peter Holm I have implemented the KPI that provides the ability for the driver to implement cloning on the open(2). This is another (IMHO, more UNIXy) way to provide per-fd private data for the driver. It seems that at least /dev/apm, /dev/drm and /dev/sg could immediately benefit from the fdclone() KPI. The patch is at http://people.freebsd.org/~kib/misc/fdclone.9.patch Sample dumb driver that uses the KPI is at http://people.freebsd.org/~kib/fclone The driver that uses the fdclone() shall provide cdevsw for master device, and cdevsw for clones. Master shall have d_fdopen() method that could call int fdclone(struct cdevsw *_csw, struct file *_fp, int _fmode, struct cdev **_clone, void *si_drv1, struct thread *td); to replace the reference in the _fp with newly created cdev. After successfull fdclone() call, all further calls on the _fp are dispatched to the clone _csw instead of master one. si_drv1 of the new cdev is set to respective argument, allowing the clone to find the master. The cloned cdev is not accessible for lookup through the devfs, and is destroyed automatically on the final close of the last filedescriptor that references the vnode. Please, review. Your feedback is welcome ! --dLXnlYbDJNCwF3YM Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4 (FreeBSD) iD8DBQFHKJnrC3+MBN1Mb4gRAt8PAJ0W4QLnP644wDgrWJ4XLqYg9iPyxgCdFbo3 EtzhD11yGt+MgtJWLOzQarE= =nACF -----END PGP SIGNATURE----- --dLXnlYbDJNCwF3YM--