diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2010-12-14 10:05:23 -0500 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2010-12-16 12:37:26 -0500 |
commit | a7952f4056d4d9c63c70534bcfd4f2c11e487000 (patch) | |
tree | 0b622ff71d92abb3f6ec3d09fc3ed9c3624282ed /fs/lockd | |
parent | b10e30f6559978e3c8ca2a70c1cb35d6680a4021 (diff) |
lockd: Add nlm_alloc_host()
Refactor nlm_host allocation and initialization into a separate
function. This will be the common piece of server and client nlm_host
lookup logic after the nlm_host cache is split.
Small change: use kmalloc() instead of kzalloc(), as we're overwriting
almost all fields in the new nlm_host struct with non-zero values
immediately after it is allocated. An added benefit is we now have an
explicit reference to each field name where it is initialized (for all
you cscope fans out there).
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/lockd')
-rw-r--r-- | fs/lockd/host.c | 110 |
1 files changed, 65 insertions, 45 deletions
diff --git a/fs/lockd/host.c b/fs/lockd/host.c index 2dbf1392acfc..1911f34be976 100644 --- a/fs/lockd/host.c +++ b/fs/lockd/host.c | |||
@@ -100,6 +100,68 @@ static unsigned int nlm_hash_address(const struct sockaddr *sap) | |||
100 | } | 100 | } |
101 | 101 | ||
102 | /* | 102 | /* |
103 | * Allocate and initialize an nlm_host. Common to both client and server. | ||
104 | */ | ||
105 | static struct nlm_host *nlm_alloc_host(struct nlm_lookup_host_info *ni, | ||
106 | struct nsm_handle *nsm) | ||
107 | { | ||
108 | struct nlm_host *host = NULL; | ||
109 | unsigned long now = jiffies; | ||
110 | |||
111 | if (nsm != NULL) | ||
112 | atomic_inc(&nsm->sm_count); | ||
113 | else { | ||
114 | host = NULL; | ||
115 | nsm = nsm_get_handle(ni->sap, ni->salen, | ||
116 | ni->hostname, ni->hostname_len); | ||
117 | if (unlikely(nsm == NULL)) { | ||
118 | dprintk("lockd: %s failed; no nsm handle\n", | ||
119 | __func__); | ||
120 | goto out; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | host = kmalloc(sizeof(*host), GFP_KERNEL); | ||
125 | if (unlikely(host == NULL)) { | ||
126 | dprintk("lockd: %s failed; no memory\n", __func__); | ||
127 | nsm_release(nsm); | ||
128 | goto out; | ||
129 | } | ||
130 | |||
131 | memcpy(nlm_addr(host), ni->sap, ni->salen); | ||
132 | host->h_addrlen = ni->salen; | ||
133 | rpc_set_port(nlm_addr(host), 0); | ||
134 | host->h_srcaddrlen = 0; | ||
135 | |||
136 | host->h_rpcclnt = NULL; | ||
137 | host->h_name = nsm->sm_name; | ||
138 | host->h_version = ni->version; | ||
139 | host->h_proto = ni->protocol; | ||
140 | host->h_reclaiming = 0; | ||
141 | host->h_server = ni->server; | ||
142 | host->h_noresvport = ni->noresvport; | ||
143 | host->h_inuse = 0; | ||
144 | init_waitqueue_head(&host->h_gracewait); | ||
145 | init_rwsem(&host->h_rwsem); | ||
146 | host->h_state = 0; | ||
147 | host->h_nsmstate = 0; | ||
148 | host->h_pidcount = 0; | ||
149 | atomic_set(&host->h_count, 1); | ||
150 | mutex_init(&host->h_mutex); | ||
151 | host->h_nextrebind = now + NLM_HOST_REBIND; | ||
152 | host->h_expires = now + NLM_HOST_EXPIRE; | ||
153 | INIT_LIST_HEAD(&host->h_lockowners); | ||
154 | spin_lock_init(&host->h_lock); | ||
155 | INIT_LIST_HEAD(&host->h_granted); | ||
156 | INIT_LIST_HEAD(&host->h_reclaim); | ||
157 | host->h_nsmhandle = nsm; | ||
158 | host->h_addrbuf = nsm->sm_addrbuf; | ||
159 | |||
160 | out: | ||
161 | return host; | ||
162 | } | ||
163 | |||
164 | /* | ||
103 | * Common host lookup routine for server & client | 165 | * Common host lookup routine for server & client |
104 | */ | 166 | */ |
105 | static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni) | 167 | static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni) |
@@ -150,55 +212,13 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni) | |||
150 | goto out; | 212 | goto out; |
151 | } | 213 | } |
152 | 214 | ||
153 | /* | 215 | host = nlm_alloc_host(ni, nsm); |
154 | * The host wasn't in our hash table. If we don't | 216 | if (unlikely(host == NULL)) |
155 | * have an NSM handle for it yet, create one. | ||
156 | */ | ||
157 | if (nsm) | ||
158 | atomic_inc(&nsm->sm_count); | ||
159 | else { | ||
160 | host = NULL; | ||
161 | nsm = nsm_get_handle(ni->sap, ni->salen, | ||
162 | ni->hostname, ni->hostname_len); | ||
163 | if (!nsm) { | ||
164 | dprintk("lockd: nlm_lookup_host failed; " | ||
165 | "no nsm handle\n"); | ||
166 | goto out; | ||
167 | } | ||
168 | } | ||
169 | |||
170 | host = kzalloc(sizeof(*host), GFP_KERNEL); | ||
171 | if (!host) { | ||
172 | nsm_release(nsm); | ||
173 | dprintk("lockd: nlm_lookup_host failed; no memory\n"); | ||
174 | goto out; | 217 | goto out; |
175 | } | 218 | |
176 | host->h_name = nsm->sm_name; | ||
177 | host->h_addrbuf = nsm->sm_addrbuf; | ||
178 | memcpy(nlm_addr(host), ni->sap, ni->salen); | ||
179 | host->h_addrlen = ni->salen; | ||
180 | rpc_set_port(nlm_addr(host), 0); | ||
181 | memcpy(nlm_srcaddr(host), ni->src_sap, ni->src_len); | 219 | memcpy(nlm_srcaddr(host), ni->src_sap, ni->src_len); |
182 | host->h_srcaddrlen = ni->src_len; | 220 | host->h_srcaddrlen = ni->src_len; |
183 | host->h_version = ni->version; | ||
184 | host->h_proto = ni->protocol; | ||
185 | host->h_rpcclnt = NULL; | ||
186 | mutex_init(&host->h_mutex); | ||
187 | host->h_nextrebind = jiffies + NLM_HOST_REBIND; | ||
188 | host->h_expires = jiffies + NLM_HOST_EXPIRE; | ||
189 | atomic_set(&host->h_count, 1); | ||
190 | init_waitqueue_head(&host->h_gracewait); | ||
191 | init_rwsem(&host->h_rwsem); | ||
192 | host->h_state = 0; /* pseudo NSM state */ | ||
193 | host->h_nsmstate = 0; /* real NSM state */ | ||
194 | host->h_nsmhandle = nsm; | ||
195 | host->h_server = ni->server; | ||
196 | host->h_noresvport = ni->noresvport; | ||
197 | hlist_add_head(&host->h_hash, chain); | 221 | hlist_add_head(&host->h_hash, chain); |
198 | INIT_LIST_HEAD(&host->h_lockowners); | ||
199 | spin_lock_init(&host->h_lock); | ||
200 | INIT_LIST_HEAD(&host->h_granted); | ||
201 | INIT_LIST_HEAD(&host->h_reclaim); | ||
202 | 222 | ||
203 | nrhosts++; | 223 | nrhosts++; |
204 | 224 | ||