Date: Mon, 5 May 2008 10:13:55 +0200 From: Pawel Jakub Dawidek <pjd@FreeBSD.org> To: Kostik Belousov <kostikbel@gmail.com> Cc: arch@freebsd.org Subject: Re: Per-open file private data for the cdevs Message-ID: <20080505081355.GB1628@garage.freebsd.pl> In-Reply-To: <20080504171002.GN18958@deviant.kiev.zoral.com.ua> References: <20080504171002.GN18958@deviant.kiev.zoral.com.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
--WYTEVAkct0FjGQmd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, May 04, 2008 at 08:10:02PM +0300, Kostik Belousov wrote: > Since the review for the clone-at-open patch (fdclone) posted some time a= go > mostly says that it would be better to implement per-file private data > instead, I produced the patch along this line, >=20 > The patch does not change the cdevsw ABI, instead, three new functions > nt devfs_get_cdevpriv(void **datap); > int devfs_set_cdevpriv(void *priv, cdevpriv_dtr_t dtr); > void devfs_clear_cdevpriv(void); > are provided for manipulation of the per-file private data. >=20 > devfs_set_cdevpriv assigns the priv as private data for the file descript= or > which is used to initiate currently performed driver operation. dtr > is the function that will be called when either the last refernce to > the file goes away or devfs_clear_cdevpriv is called. >=20 > devfs_get_cdevpriv is the obvious accessor. >=20 > devfs_clear_cdevpriv allows to clear the private data for the still > open file. >=20 > The synchronization of the cdev data and file private data is left > to the driver code, I did not found any generic helper mechanism that > could be useful there. >=20 > Patch: > http://people.freebsd.org/~kib/misc/fdpriv.1.patch >=20 > Dumb driver that shows the basic usage of the proposed KPI: > http://people.freebsd.org/~kib/misc/fpclone.c >=20 > Previous version of the patch was tested by Peter Holm. Can you see if my OSD (Object-Specific-Data) KPI can be useful here? I've it only in perforce for now, but I think it's what you are looking for. I use it for jails and threads currently, but it is trivial to use it for other objects. Take a look: http://perforce.freebsd.org/fileViewer.cgi?FSPC=3D//depot/user/pjd/zfs/sys= /sys/osd.h&REV=3D3 When your code is loaded/initialized you call: static int slot; slot =3D osd_file_register(mod_destroy); Where mod_destroy is a function which knows how to free your private data. On unload: osd_file_deregister(slot); Now, when you want to attach private data: error =3D osd_file_set(fp, slot, ptr_to_your_data); You can get it with: ptr =3D osd_file_get(fp, slot); --=20 Pawel Jakub Dawidek http://www.wheel.pl pjd@FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! --WYTEVAkct0FjGQmd Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4 (FreeBSD) iD8DBQFIHsHDForvXbEpPzQRAkXSAKCQ3VsE5whVmlrjXgTVv7w122YL0QCg4D2B /KoYnlPwSlK0gB2U20HVJew= =Th9n -----END PGP SIGNATURE----- --WYTEVAkct0FjGQmd--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080505081355.GB1628>