From owner-freebsd-current@FreeBSD.ORG Wed May 24 22:07:41 2006 Return-Path: X-Original-To: current@freebsd.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A462116A455 for ; Wed, 24 May 2006 22:07:41 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (66-23-211-162.clients.speedfactory.net [66.23.211.162]) by mx1.FreeBSD.org (Postfix) with ESMTP id E277643D45 for ; Wed, 24 May 2006 22:07:40 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from [10.0.1.114] (nat-outside.atlanta.corp.yahoo.com [63.172.193.57]) (authenticated bits=0) by server.baldwin.cx (8.13.4/8.13.4) with ESMTP id k4OM7eqT096179 for ; Wed, 24 May 2006 18:07:40 -0400 (EDT) (envelope-from jhb@freebsd.org) From: John Baldwin To: current@freebsd.org Date: Wed, 24 May 2006 18:07:29 -0400 User-Agent: KMail/1.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200605241807.29163.jhb@freebsd.org> X-Virus-Scanned: ClamAV 0.87.1/1480/Wed May 24 12:45:51 2006 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.0 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on server.baldwin.cx Cc: Subject: [PATCH] Change kqueue_register() to use fget() X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 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, 24 May 2006 22:07:42 -0000 This small patch fixes up a part of kevent to use fget() instead of mangling the filedesc struct directly. I haven't had time yet to sit down and test kevent apps with it so would appreciate it if anyone has some idle cycles to do that. --- //depot/vendor/freebsd/src/sys/kern/kern_event.c 2006/04/14 14:33:55 +++ //depot/projects/smpng/sys/kern/kern_event.c 2006/04/25 19:47:56 @@ -754,15 +754,12 @@ int kqueue_register(struct kqueue *kq, struct kevent *kev, struct thread *td, int waitok) { - struct filedesc *fdp; struct filterops *fops; struct file *fp; struct knote *kn, *tkn; int error, filt, event; int haskqglobal; - int fd; - fdp = NULL; fp = NULL; kn = NULL; error = 0; @@ -778,22 +775,13 @@ findkn: if (fops->f_isfd) { KASSERT(td != NULL, ("td is NULL")); - fdp = td->td_proc->p_fd; - FILEDESC_LOCK(fdp); - /* validate descriptor */ - fd = kev->ident; - if (fd < 0 || fd >= fdp->fd_nfiles || - (fp = fdp->fd_ofiles[fd]) == NULL) { - FILEDESC_UNLOCK(fdp); - error = EBADF; + error = fget(td, kev->ident, &fp); + if (error) goto done; - } - fhold(fp); if ((kev->flags & EV_ADD) == EV_ADD && kqueue_expand(kq, fops, kev->ident, 0) != 0) { - /* unlock and try again */ - FILEDESC_UNLOCK(fdp); + /* try again */ fdrop(fp, td); fp = NULL; error = kqueue_expand(kq, fops, kev->ident, waitok); @@ -811,7 +799,6 @@ * they are the same thing. */ if (fp->f_data == kq) { - FILEDESC_UNLOCK(fdp); error = EINVAL; goto done_noglobal; } @@ -819,7 +806,6 @@ KQ_GLOBAL_LOCK(&kq_global, haskqglobal); } - FILEDESC_UNLOCK(fdp); KQ_LOCK(kq); if (kev->ident < kq->kq_knlistsize) { SLIST_FOREACH(kn, &kq->kq_knlist[kev->ident], kn_link) -- John Baldwin