1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/*
Copyright (C) 1995 Free Software Foundation, Inc.
Written by Michael I. Bushnell, p/BSG.
This file is part of the GNU Hurd.
The GNU Hurd is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
The GNU Hurd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
#include "nfs.h"
#include <string.h>
#define CACHESIZE 512
static struct node *nodehash [CACHESIZE];
static inline int
hash (void *fhandle)
{
unsigned int h = 0;
int i;
for (i = 0; i < NFS_FHSIZE; i++)
h += ((char *)fhandle)[i];
return h % CACHESIZE;
}
struct node *
lookup_fhandle (void *fhandle)
{
struct node *np;
struct netnode *nn;
int h = hash (fhandle);
spin_lock (&netfs_node_refcnt_lock);
for (np = nodehash[h]; np; np = np->nn->hnext)
{
if (bcmp (np->nn->handle, fhandle, NFS_FHSIZE) != 0)
continue;
np->references++;
spin_unlock (&netfs_node_refcnt_lock);
mutex_lock (&np->lock);
return np;
}
nn = malloc (sizeof (struct netnode));
bcopy (fhandle, nn->handle, NFS_FHSIZE);
nn->stat_updated = 0;
np = netfs_make_node (nn);
mutex_lock (&np->lock);
nn->hnext = nodehash[h];
if (nn->hnext)
nn->hnext->nn->hprevp = &nn->hnext;
nn->hprevp = &nodehash[h];
spin_unlock (&netfs_node_refcnt_lock);
return np;
}
void
netfs_node_norefs (struct node *np)
{
if (np->nn->dead_dir)
{
np->references++;
spin_unlock (&diskfs_node_refcnt_lock);
netfs_attempt_unlink ((struct netcred *)-1, np->nn->dead_dir,
np->nn->dead_name);
diskfs_nrele (np->nn->dead_dir);
free (np->nn->dead_name);
np->nn->dead_dir = 0;
np->nn->dead_name = 0;
diskfs_nput (np);
/* Caller expects us to leave this locked... */
spin_lock (&diskfs_node_refcnt_lock);
}
else
{
*np->nn->hprevp = np->nn->hnext;
if (np->nn->hnext)
np->nn->hnext->nn->hprevp = np->nn->hprevp;
free (np->nn);
free (np);
}
}
|