Sun Jan 22 03:48:51 2012 UTC ()
fileassoc_file_delete: pre-check whether fileassoc was used and thus avoid
acquiring kernel-lock, which damages sys_unlink() performance.


(rmind)
diff -r1.34 -r1.35 src/sys/kern/kern_fileassoc.c

cvs diff -r1.34 -r1.35 src/sys/kern/kern_fileassoc.c (expand / switch to unified diff)

--- src/sys/kern/kern_fileassoc.c 2009/12/25 20:07:18 1.34
+++ src/sys/kern/kern_fileassoc.c 2012/01/22 03:48:51 1.35
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_fileassoc.c,v 1.34 2009/12/25 20:07:18 elad Exp $ */ 1/* $NetBSD: kern_fileassoc.c,v 1.35 2012/01/22 03:48:51 rmind Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2006 Elad Efrat <elad@NetBSD.org> 4 * Copyright (c) 2006 Elad Efrat <elad@NetBSD.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -18,44 +18,44 @@ @@ -18,44 +18,44 @@
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31__KERNEL_RCSID(0, "$NetBSD: kern_fileassoc.c,v 1.34 2009/12/25 20:07:18 elad Exp $"); 31__KERNEL_RCSID(0, "$NetBSD: kern_fileassoc.c,v 1.35 2012/01/22 03:48:51 rmind Exp $");
32 32
33#include "opt_fileassoc.h" 33#include "opt_fileassoc.h"
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/mount.h> 36#include <sys/mount.h>
37#include <sys/queue.h> 37#include <sys/queue.h>
38#include <sys/vnode.h> 38#include <sys/vnode.h>
39#include <sys/errno.h> 39#include <sys/errno.h>
40#include <sys/fileassoc.h> 40#include <sys/fileassoc.h>
41#include <sys/specificdata.h> 41#include <sys/specificdata.h>
42#include <sys/hash.h> 42#include <sys/hash.h>
43#include <sys/kmem.h> 43#include <sys/kmem.h>
44#include <sys/once.h> 44#include <sys/once.h>
45 45
46#define FILEASSOC_INITIAL_TABLESIZE 128 46#define FILEASSOC_INITIAL_TABLESIZE 128
47 47
48static specificdata_domain_t fileassoc_domain; 48static specificdata_domain_t fileassoc_domain = NULL;
49static specificdata_key_t fileassoc_mountspecific_key; 49static specificdata_key_t fileassoc_mountspecific_key;
50static ONCE_DECL(control); 50static ONCE_DECL(control);
51 51
52/* 52/*
53 * Assoc entry. 53 * Assoc entry.
54 * Includes the assoc name for identification and private clear callback. 54 * Includes the assoc name for identification and private clear callback.
55 */ 55 */
56struct fileassoc { 56struct fileassoc {
57 LIST_ENTRY(fileassoc) assoc_list; 57 LIST_ENTRY(fileassoc) assoc_list;
58 const char *assoc_name; /* Name. */ 58 const char *assoc_name; /* Name. */
59 fileassoc_cleanup_cb_t assoc_cleanup_cb; /* Clear callback. */ 59 fileassoc_cleanup_cb_t assoc_cleanup_cb; /* Clear callback. */
60 specificdata_key_t assoc_key; 60 specificdata_key_t assoc_key;
61}; 61};
@@ -500,26 +500,30 @@ fileassoc_file_add(struct vnode *vp, fha @@ -500,26 +500,30 @@ fileassoc_file_add(struct vnode *vp, fha
500 500
501 return (faf); 501 return (faf);
502} 502}
503 503
504/* 504/*
505 * Delete a file entry from a table. 505 * Delete a file entry from a table.
506 */ 506 */
507int 507int
508fileassoc_file_delete(struct vnode *vp) 508fileassoc_file_delete(struct vnode *vp)
509{ 509{
510 struct fileassoc_table *tbl; 510 struct fileassoc_table *tbl;
511 struct fileassoc_file *faf; 511 struct fileassoc_file *faf;
512 512
 513 /* Pre-check if fileassoc is used. XXX */
 514 if (!fileassoc_domain) {
 515 return ENOENT;
 516 }
513 KERNEL_LOCK(1, NULL); 517 KERNEL_LOCK(1, NULL);
514 518
515 faf = fileassoc_file_lookup(vp, NULL); 519 faf = fileassoc_file_lookup(vp, NULL);
516 if (faf == NULL) { 520 if (faf == NULL) {
517 KERNEL_UNLOCK_ONE(NULL); 521 KERNEL_UNLOCK_ONE(NULL);
518 return (ENOENT); 522 return (ENOENT);
519 } 523 }
520 524
521 file_free(faf); 525 file_free(faf);
522 526
523 tbl = fileassoc_table_lookup(vp->v_mount); 527 tbl = fileassoc_table_lookup(vp->v_mount);
524 --(tbl->tbl_nused); /* XXX gc? */ 528 --(tbl->tbl_nused); /* XXX gc? */
525 529