From owner-freebsd-current@FreeBSD.ORG Wed Aug 21 23:21:19 2013 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 9F5C5CC0; Wed, 21 Aug 2013 23:21:19 +0000 (UTC) (envelope-from jmg@h2.funkthat.com) Received: from h2.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 76AC3261F; Wed, 21 Aug 2013 23:21:19 +0000 (UTC) Received: from h2.funkthat.com (localhost [127.0.0.1]) by h2.funkthat.com (8.14.3/8.14.3) with ESMTP id r7LNLDsR075009 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 21 Aug 2013 16:21:13 -0700 (PDT) (envelope-from jmg@h2.funkthat.com) Received: (from jmg@localhost) by h2.funkthat.com (8.14.3/8.14.3/Submit) id r7LNLDYg075008; Wed, 21 Aug 2013 16:21:13 -0700 (PDT) (envelope-from jmg) Date: Wed, 21 Aug 2013 16:21:13 -0700 From: John-Mark Gurney To: Yuri Subject: Re: How to best overload the fileops ? Message-ID: <20130821232113.GD94127@funkthat.com> Mail-Followup-To: Yuri , current@freebsd.org, Roman Divacky References: <521508F4.6030502@rawbw.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <521508F4.6030502@rawbw.com> User-Agent: Mutt/1.4.2.3i X-Operating-System: FreeBSD 7.2-RELEASE i386 X-PGP-Fingerprint: 54BA 873B 6515 3F10 9E88 9322 9CB1 8F74 6D3F A396 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.2 (h2.funkthat.com [127.0.0.1]); Wed, 21 Aug 2013 16:21:13 -0700 (PDT) Cc: Roman Divacky , current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Aug 2013 23:21:19 -0000 Yuri wrote this message on Wed, Aug 21, 2013 at 11:37 -0700: > I am working on linux epoll functionality for linuxlator. It implements > epoll through kqueue, but there is the need to overload fo_close > function in fileops to free some memory. How did this memory get allocated in the first place? Why does it need to be free'd in fo_close and not another location? > There is no generic mechanism defined in the kernel sources allowing to > do this, and it isn't desirable to do this in a hackish way. So I am > suggesting this particular way, see code snippets below. > This approach is inspired by how C++ classes are sub-classed, with C++ > class being similar to kernel file descriptor type and C++ vtbl being > similar to fileops. > > I am looking for an opinion(s) on these questions: > * Is such code is acceptable for kernel? > * Does it look too ugly? > * Any suggestions on how to improve it? > > As the system develops, other places may require to do such overloading > too, so this approach can be reused. > > Thank you, > Yuri > > > *** In sys/file.h add these macros (they define how overloading is done): > #define FDCLASS_DEFINE(cls) \ > struct fileops* fdcls_##cls##_fileops(void); \ > struct fileops* fdcls_##cls##_fileops(void) { \ > return (&cls##ops); \ > } > #define FDCLASS_INHERIT(cls, cls_parent, cls_init_func) \ > extern struct fileops* fdcls_##cls_parent##_fileops(void); \ > static void cls##_fdcls_init(void *dummy __unused) { \ > cls##ops = *fdcls_##cls_parent##_fileops(); \ > cls_init_func(); \ > } \ > SYSINIT(cls##_fdcls, SI_SUB_PSEUDO, SI_ORDER_ANY, cls##_fdcls_init, > NULL); > > *** In the end of kern/kern_event.c add the line exposing kqueue's fileops: > FDCLASS_DEFINE(kqueue) > > *** In linux_epoll.c add code that would initialize epoll fileops with > the base class fileops: > /* overload kqueue fileops */ > static struct fileops epollops; > static struct fileops epollops_base; > static void > epoll_init(void) { > /* overload only fo_close operation */ > epollops_base = epollops; > epollops.fo_close = epoll_close; > } > FDCLASS_INHERIT(epoll, kqueue, epoll_init) > > > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."