File: | libglusterfs/src/inode.c |
Location: | line 1737, column 9 |
Description: | Value stored to 'ret' is never read |
1 | /* |
2 | Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> |
3 | This file is part of GlusterFS. |
4 | |
5 | This file is licensed to you under your choice of the GNU Lesser |
6 | General Public License, version 3 or any later version (LGPLv3 or |
7 | later), or the GNU General Public License, version 2 (GPLv2), in all |
8 | cases as published by the Free Software Foundation. |
9 | */ |
10 | |
11 | #ifndef _CONFIG_H |
12 | #define _CONFIG_H |
13 | #include "config.h" |
14 | #endif |
15 | |
16 | #include "inode.h" |
17 | #include "fd.h" |
18 | #include "common-utils.h" |
19 | #include "statedump.h" |
20 | #include <pthread.h> |
21 | #include <sys/types.h> |
22 | #include <stdint.h> |
23 | #include "list.h" |
24 | #include <time.h> |
25 | #include <assert.h> |
26 | |
27 | /* TODO: |
28 | move latest accessed dentry to list_head of inode |
29 | */ |
30 | |
31 | #define INODE_DUMP_LIST(head, key_buf, key_prefix, list_type){ int i = 1; inode_t *inode = ((void*)0); for (inode = ((typeof (*inode) *)((char *)((head)->next)-(unsigned long)(&(( typeof(*inode) *)0)->list))); &inode->list != (head ); inode = ((typeof(*inode) *)((char *)(inode->list.next)- (unsigned long)(&((typeof(*inode) *)0)->list)))) { { _gf_proc_dump_build_key (key_buf, key_prefix, "%s.%d",list_type, i++); }; gf_proc_dump_add_section (key_buf); inode_dump(inode, key); } } \ |
32 | { \ |
33 | int i = 1; \ |
34 | inode_t *inode = NULL((void*)0); \ |
35 | list_for_each_entry (inode, head, list)for (inode = ((typeof(*inode) *)((char *)((head)->next)-(unsigned long)(&((typeof(*inode) *)0)->list))); &inode-> list != (head); inode = ((typeof(*inode) *)((char *)(inode-> list.next)-(unsigned long)(&((typeof(*inode) *)0)->list )))) { \ |
36 | gf_proc_dump_build_key(key_buf, key_prefix, \{ _gf_proc_dump_build_key(key_buf, key_prefix, "%s.%d",list_type , i++); } |
37 | "%s.%d",list_type, i++){ _gf_proc_dump_build_key(key_buf, key_prefix, "%s.%d",list_type , i++); }; \ |
38 | gf_proc_dump_add_section(key_buf); \ |
39 | inode_dump(inode, key); \ |
40 | } \ |
41 | } |
42 | |
43 | static inode_t * |
44 | __inode_unref (inode_t *inode); |
45 | |
46 | static int |
47 | inode_table_prune (inode_table_t *table); |
48 | |
49 | void |
50 | fd_dump (struct list_head *head, char *prefix); |
51 | |
52 | static int |
53 | hash_dentry (inode_t *parent, const char *name, int mod) |
54 | { |
55 | int hash = 0; |
56 | int ret = 0; |
57 | |
58 | hash = *name; |
59 | if (hash) { |
60 | for (name += 1; *name != '\0'; name++) { |
61 | hash = (hash << 5) - hash + *name; |
62 | } |
63 | } |
64 | ret = (hash + (unsigned long)parent) % mod; |
65 | |
66 | return ret; |
67 | } |
68 | |
69 | |
70 | static int |
71 | hash_gfid (uuid_t uuid, int mod) |
72 | { |
73 | int ret = 0; |
74 | |
75 | ret = uuid[15] + (uuid[14] << 8); |
76 | |
77 | return ret; |
78 | } |
79 | |
80 | |
81 | static void |
82 | __dentry_hash (dentry_t *dentry) |
83 | { |
84 | inode_table_t *table = NULL((void*)0); |
85 | int hash = 0; |
86 | |
87 | if (!dentry) { |
88 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "dentry not found")do { do { if (0) printf ("dentry not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 88, GF_LOG_WARNING, "dentry not found"); } while (0); |
89 | return; |
90 | } |
91 | |
92 | table = dentry->inode->table; |
93 | hash = hash_dentry (dentry->parent, dentry->name, |
94 | table->hashsize); |
95 | |
96 | list_del_init (&dentry->hash); |
97 | list_add (&dentry->hash, &table->name_hash[hash]); |
98 | } |
99 | |
100 | |
101 | static int |
102 | __is_dentry_hashed (dentry_t *dentry) |
103 | { |
104 | if (!dentry) { |
105 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "dentry not found")do { do { if (0) printf ("dentry not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 105, GF_LOG_WARNING, "dentry not found"); } while (0); |
106 | return 0; |
107 | } |
108 | |
109 | return !list_empty (&dentry->hash); |
110 | } |
111 | |
112 | |
113 | static void |
114 | __dentry_unhash (dentry_t *dentry) |
115 | { |
116 | if (!dentry) { |
117 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "dentry not found")do { do { if (0) printf ("dentry not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 117, GF_LOG_WARNING, "dentry not found"); } while (0); |
118 | return; |
119 | } |
120 | |
121 | list_del_init (&dentry->hash); |
122 | } |
123 | |
124 | |
125 | static void |
126 | __dentry_unset (dentry_t *dentry) |
127 | { |
128 | if (!dentry) { |
129 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "dentry not found")do { do { if (0) printf ("dentry not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 129, GF_LOG_WARNING, "dentry not found"); } while (0); |
130 | return; |
131 | } |
132 | |
133 | __dentry_unhash (dentry); |
134 | |
135 | list_del_init (&dentry->inode_list); |
136 | |
137 | GF_FREE (dentry->name)__gf_free (dentry->name); |
138 | |
139 | if (dentry->parent) { |
140 | __inode_unref (dentry->parent); |
141 | dentry->parent = NULL((void*)0); |
142 | } |
143 | |
144 | mem_put (dentry); |
145 | } |
146 | |
147 | |
148 | static int |
149 | __foreach_ancestor_dentry (dentry_t *dentry, |
150 | int (per_dentry_fn) (dentry_t *dentry, |
151 | void *data), |
152 | void *data) |
153 | { |
154 | inode_t *parent = NULL((void*)0); |
155 | dentry_t *each = NULL((void*)0); |
156 | int ret = 0; |
157 | |
158 | if (!dentry) { |
159 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "dentry not found")do { do { if (0) printf ("dentry not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 159, GF_LOG_WARNING, "dentry not found"); } while (0); |
160 | return 0; |
161 | } |
162 | |
163 | ret = per_dentry_fn (dentry, data); |
164 | if (ret) { |
165 | gf_log (THIS->name, GF_LOG_WARNING, "per dentry fn returned %d", ret)do { do { if (0) printf ("per dentry fn returned %d", ret); } while (0); _gf_log ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__, 165, GF_LOG_WARNING, "per dentry fn returned %d" , ret); } while (0); |
166 | goto out; |
167 | } |
168 | |
169 | parent = dentry->parent; |
170 | if (!parent) { |
171 | gf_log (THIS->name, GF_LOG_WARNING, "parent not found")do { do { if (0) printf ("parent not found"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 171, GF_LOG_WARNING, "parent not found"); } while (0); |
172 | goto out; |
173 | } |
174 | |
175 | list_for_each_entry (each, &parent->dentry_list, inode_list)for (each = ((typeof(*each) *)((char *)((&parent->dentry_list )->next)-(unsigned long)(&((typeof(*each) *)0)->inode_list ))); &each->inode_list != (&parent->dentry_list ); each = ((typeof(*each) *)((char *)(each->inode_list.next )-(unsigned long)(&((typeof(*each) *)0)->inode_list))) ) { |
176 | ret = __foreach_ancestor_dentry (each, per_dentry_fn, data); |
177 | if (ret) |
178 | goto out; |
179 | } |
180 | out: |
181 | return ret; |
182 | } |
183 | |
184 | |
185 | static int |
186 | __check_cycle (dentry_t *a_dentry, void *data) |
187 | { |
188 | inode_t *link_inode = NULL((void*)0); |
189 | |
190 | link_inode = data; |
191 | |
192 | if (a_dentry->parent == link_inode) |
193 | return 1; |
194 | |
195 | return 0; |
196 | } |
197 | |
198 | |
199 | static int |
200 | __is_dentry_cyclic (dentry_t *dentry) |
201 | { |
202 | int ret = 0; |
203 | inode_t *inode = NULL((void*)0); |
204 | char *name = "<nul>"; |
205 | |
206 | ret = __foreach_ancestor_dentry (dentry, __check_cycle, |
207 | dentry->inode); |
208 | if (ret) { |
209 | inode = dentry->inode; |
210 | |
211 | if (dentry->name) |
212 | name = dentry->name; |
213 | |
214 | gf_log (dentry->inode->table->name, GF_LOG_CRITICAL,do { do { if (0) printf ("detected cyclic loop formation during inode linkage." " inode (%s) linking under itself as %s", uuid_utoa (inode-> gfid), name); } while (0); _gf_log (dentry->inode->table ->name, "inode.c", __FUNCTION__, 217, GF_LOG_CRITICAL, "detected cyclic loop formation during inode linkage." " inode (%s) linking under itself as %s", uuid_utoa (inode-> gfid), name); } while (0) |
215 | "detected cyclic loop formation during inode linkage."do { do { if (0) printf ("detected cyclic loop formation during inode linkage." " inode (%s) linking under itself as %s", uuid_utoa (inode-> gfid), name); } while (0); _gf_log (dentry->inode->table ->name, "inode.c", __FUNCTION__, 217, GF_LOG_CRITICAL, "detected cyclic loop formation during inode linkage." " inode (%s) linking under itself as %s", uuid_utoa (inode-> gfid), name); } while (0) |
216 | " inode (%s) linking under itself as %s",do { do { if (0) printf ("detected cyclic loop formation during inode linkage." " inode (%s) linking under itself as %s", uuid_utoa (inode-> gfid), name); } while (0); _gf_log (dentry->inode->table ->name, "inode.c", __FUNCTION__, 217, GF_LOG_CRITICAL, "detected cyclic loop formation during inode linkage." " inode (%s) linking under itself as %s", uuid_utoa (inode-> gfid), name); } while (0) |
217 | uuid_utoa (inode->gfid), name)do { do { if (0) printf ("detected cyclic loop formation during inode linkage." " inode (%s) linking under itself as %s", uuid_utoa (inode-> gfid), name); } while (0); _gf_log (dentry->inode->table ->name, "inode.c", __FUNCTION__, 217, GF_LOG_CRITICAL, "detected cyclic loop formation during inode linkage." " inode (%s) linking under itself as %s", uuid_utoa (inode-> gfid), name); } while (0); |
218 | } |
219 | |
220 | return ret; |
221 | } |
222 | |
223 | |
224 | static void |
225 | __inode_unhash (inode_t *inode) |
226 | { |
227 | if (!inode) { |
228 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 228, GF_LOG_WARNING, "inode not found"); } while (0); |
229 | return; |
230 | } |
231 | |
232 | list_del_init (&inode->hash); |
233 | } |
234 | |
235 | |
236 | static int |
237 | __is_inode_hashed (inode_t *inode) |
238 | { |
239 | if (!inode) { |
240 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 240, GF_LOG_WARNING, "inode not found"); } while (0); |
241 | return 0; |
242 | } |
243 | |
244 | return !list_empty (&inode->hash); |
245 | } |
246 | |
247 | |
248 | static void |
249 | __inode_hash (inode_t *inode) |
250 | { |
251 | inode_table_t *table = NULL((void*)0); |
252 | int hash = 0; |
253 | |
254 | if (!inode) { |
255 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 255, GF_LOG_WARNING, "inode not found"); } while (0); |
256 | return; |
257 | } |
258 | |
259 | table = inode->table; |
260 | hash = hash_gfid (inode->gfid, 65536); |
261 | |
262 | list_del_init (&inode->hash); |
263 | list_add (&inode->hash, &table->inode_hash[hash]); |
264 | } |
265 | |
266 | |
267 | static dentry_t * |
268 | __dentry_search_for_inode (inode_t *inode, uuid_t pargfid, const char *name) |
269 | { |
270 | dentry_t *dentry = NULL((void*)0); |
271 | dentry_t *tmp = NULL((void*)0); |
272 | |
273 | if (!inode || !name) { |
274 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode || name not found")do { do { if (0) printf ("inode || name not found"); } while ( 0); _gf_log_callingfn ((*__glusterfs_this_location())->name , "inode.c", __FUNCTION__, 274, GF_LOG_WARNING, "inode || name not found" ); } while (0); |
275 | return NULL((void*)0); |
276 | } |
277 | |
278 | /* earlier, just the ino was sent, which could have been 0, now |
279 | we deal with gfid, and if sent gfid is null or 0, no need to |
280 | continue with the check */ |
281 | if (!pargfid || uuid_is_null (pargfid)) |
282 | return NULL((void*)0); |
283 | |
284 | list_for_each_entry (tmp, &inode->dentry_list, inode_list)for (tmp = ((typeof(*tmp) *)((char *)((&inode->dentry_list )->next)-(unsigned long)(&((typeof(*tmp) *)0)->inode_list ))); &tmp->inode_list != (&inode->dentry_list); tmp = ((typeof(*tmp) *)((char *)(tmp->inode_list.next)-(unsigned long)(&((typeof(*tmp) *)0)->inode_list)))) { |
285 | if ((uuid_compare (tmp->parent->gfid, pargfid) == 0) && |
286 | !strcmp (tmp->name, name)) { |
287 | dentry = tmp; |
288 | break; |
289 | } |
290 | } |
291 | |
292 | return dentry; |
293 | } |
294 | |
295 | |
296 | static void |
297 | __inode_destroy (inode_t *inode) |
298 | { |
299 | int index = 0; |
300 | xlator_t *xl = NULL((void*)0); |
301 | xlator_t *old_THIS = NULL((void*)0); |
302 | |
303 | if (!inode) { |
304 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 304, GF_LOG_WARNING, "inode not found"); } while (0); |
305 | return; |
306 | } |
307 | |
308 | if (!inode->_ctx) { |
309 | gf_log (THIS->name, GF_LOG_WARNING, "_ctx not found")do { do { if (0) printf ("_ctx not found"); } while (0); _gf_log ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 309, GF_LOG_WARNING, "_ctx not found"); } while (0); |
310 | goto noctx; |
311 | } |
312 | |
313 | for (index = 0; index < inode->table->xl->graph->xl_count; index++) { |
314 | if (inode->_ctx[index].xl_key) { |
315 | xl = (xlator_t *)(long)inode->_ctx[index].xl_key; |
316 | old_THIS = THIS(*__glusterfs_this_location()); |
317 | THIS(*__glusterfs_this_location()) = xl; |
318 | if (xl->cbks->forget) |
319 | xl->cbks->forget (xl, inode); |
320 | THIS(*__glusterfs_this_location()) = old_THIS; |
321 | } |
322 | } |
323 | |
324 | GF_FREE (inode->_ctx)__gf_free (inode->_ctx); |
325 | noctx: |
326 | LOCK_DESTROY (&inode->lock)pthread_spin_destroy (&inode->lock); |
327 | // memset (inode, 0xb, sizeof (*inode)); |
328 | mem_put (inode); |
329 | } |
330 | |
331 | |
332 | static void |
333 | __inode_activate (inode_t *inode) |
334 | { |
335 | if (!inode) |
336 | return; |
337 | |
338 | list_move (&inode->list, &inode->table->active); |
339 | inode->table->active_size++; |
340 | } |
341 | |
342 | |
343 | static void |
344 | __inode_passivate (inode_t *inode) |
345 | { |
346 | dentry_t *dentry = NULL((void*)0); |
347 | dentry_t *t = NULL((void*)0); |
348 | |
349 | if (!inode) { |
350 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 350, GF_LOG_WARNING, "inode not found"); } while (0); |
351 | return; |
352 | } |
353 | |
354 | list_move_tail (&inode->list, &inode->table->lru); |
355 | inode->table->lru_size++; |
356 | |
357 | list_for_each_entry_safe (dentry, t, &inode->dentry_list, inode_list)for (dentry = ((typeof(*dentry) *)((char *)((&inode->dentry_list )->next)-(unsigned long)(&((typeof(*dentry) *)0)->inode_list ))), t = ((typeof(*dentry) *)((char *)(dentry->inode_list. next)-(unsigned long)(&((typeof(*dentry) *)0)->inode_list ))); &dentry->inode_list != (&inode->dentry_list ); dentry = t, t = ((typeof(*t) *)((char *)(t->inode_list. next)-(unsigned long)(&((typeof(*t) *)0)->inode_list)) )) { |
358 | if (!__is_dentry_hashed (dentry)) |
359 | __dentry_unset (dentry); |
360 | } |
361 | } |
362 | |
363 | |
364 | static void |
365 | __inode_retire (inode_t *inode) |
366 | { |
367 | dentry_t *dentry = NULL((void*)0); |
368 | dentry_t *t = NULL((void*)0); |
369 | |
370 | if (!inode) { |
371 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 371, GF_LOG_WARNING, "inode not found"); } while (0); |
372 | return; |
373 | } |
374 | |
375 | list_move_tail (&inode->list, &inode->table->purge); |
376 | inode->table->purge_size++; |
377 | |
378 | __inode_unhash (inode); |
379 | |
380 | list_for_each_entry_safe (dentry, t, &inode->dentry_list, inode_list)for (dentry = ((typeof(*dentry) *)((char *)((&inode->dentry_list )->next)-(unsigned long)(&((typeof(*dentry) *)0)->inode_list ))), t = ((typeof(*dentry) *)((char *)(dentry->inode_list. next)-(unsigned long)(&((typeof(*dentry) *)0)->inode_list ))); &dentry->inode_list != (&inode->dentry_list ); dentry = t, t = ((typeof(*t) *)((char *)(t->inode_list. next)-(unsigned long)(&((typeof(*t) *)0)->inode_list)) )) { |
381 | __dentry_unset (dentry); |
382 | } |
383 | } |
384 | |
385 | |
386 | static inode_t * |
387 | __inode_unref (inode_t *inode) |
388 | { |
389 | if (!inode) |
390 | return NULL((void*)0); |
391 | |
392 | if (__is_root_gfid(inode->gfid)) |
393 | return inode; |
394 | |
395 | GF_ASSERT (inode->ref)do { if (!(inode->ref)) { do { do { if (0) printf ("Assertion failed: " "inode->ref"); } while (0); _gf_log_callingfn ("", "inode.c" , __FUNCTION__, 395, GF_LOG_ERROR, "Assertion failed: " "inode->ref" ); } while (0); } } while (0); |
396 | |
397 | --inode->ref; |
398 | |
399 | if (!inode->ref) { |
400 | inode->table->active_size--; |
401 | |
402 | if (inode->nlookup) |
403 | __inode_passivate (inode); |
404 | else |
405 | __inode_retire (inode); |
406 | } |
407 | |
408 | return inode; |
409 | } |
410 | |
411 | |
412 | static inode_t * |
413 | __inode_ref (inode_t *inode) |
414 | { |
415 | if (!inode) |
416 | return NULL((void*)0); |
417 | |
418 | if (!inode->ref) { |
419 | inode->table->lru_size--; |
420 | __inode_activate (inode); |
421 | } |
422 | inode->ref++; |
423 | |
424 | return inode; |
425 | } |
426 | |
427 | |
428 | inode_t * |
429 | inode_unref (inode_t *inode) |
430 | { |
431 | inode_table_t *table = NULL((void*)0); |
432 | |
433 | if (!inode) |
434 | return NULL((void*)0); |
435 | |
436 | table = inode->table; |
437 | |
438 | pthread_mutex_lock (&table->lock); |
439 | { |
440 | inode = __inode_unref (inode); |
441 | } |
442 | pthread_mutex_unlock (&table->lock); |
443 | |
444 | inode_table_prune (table); |
445 | |
446 | return inode; |
447 | } |
448 | |
449 | |
450 | inode_t * |
451 | inode_ref (inode_t *inode) |
452 | { |
453 | inode_table_t *table = NULL((void*)0); |
454 | |
455 | if (!inode) |
456 | return NULL((void*)0); |
457 | |
458 | table = inode->table; |
459 | |
460 | pthread_mutex_lock (&table->lock); |
461 | { |
462 | inode = __inode_ref (inode); |
463 | } |
464 | pthread_mutex_unlock (&table->lock); |
465 | |
466 | return inode; |
467 | } |
468 | |
469 | |
470 | static dentry_t * |
471 | __dentry_create (inode_t *inode, inode_t *parent, const char *name) |
472 | { |
473 | dentry_t *newd = NULL((void*)0); |
474 | |
475 | if (!inode || !parent || !name) { |
476 | gf_log_callingfn (THIS->name, GF_LOG_WARNING,do { do { if (0) printf ("inode || parent || name not found") ; } while (0); _gf_log_callingfn ((*__glusterfs_this_location ())->name, "inode.c", __FUNCTION__, 477, GF_LOG_WARNING, "inode || parent || name not found" ); } while (0) |
477 | "inode || parent || name not found")do { do { if (0) printf ("inode || parent || name not found") ; } while (0); _gf_log_callingfn ((*__glusterfs_this_location ())->name, "inode.c", __FUNCTION__, 477, GF_LOG_WARNING, "inode || parent || name not found" ); } while (0); |
478 | return NULL((void*)0); |
479 | } |
480 | |
481 | newd = mem_get0 (parent->table->dentry_pool); |
482 | if (newd == NULL((void*)0)) { |
483 | goto out; |
484 | } |
485 | |
486 | INIT_LIST_HEAD (&newd->inode_list)do { (&newd->inode_list)->next = (&newd->inode_list )->prev = &newd->inode_list; } while (0); |
487 | INIT_LIST_HEAD (&newd->hash)do { (&newd->hash)->next = (&newd->hash)-> prev = &newd->hash; } while (0); |
488 | |
489 | newd->name = gf_strdup (name); |
490 | if (newd->name == NULL((void*)0)) { |
491 | mem_put (newd); |
492 | newd = NULL((void*)0); |
493 | goto out; |
494 | } |
495 | |
496 | if (parent) |
497 | newd->parent = __inode_ref (parent); |
498 | |
499 | list_add (&newd->inode_list, &inode->dentry_list); |
500 | newd->inode = inode; |
501 | |
502 | out: |
503 | return newd; |
504 | } |
505 | |
506 | |
507 | static inode_t * |
508 | __inode_create (inode_table_t *table) |
509 | { |
510 | inode_t *newi = NULL((void*)0); |
511 | |
512 | if (!table) { |
513 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "table not found")do { do { if (0) printf ("table not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 513, GF_LOG_WARNING, "table not found"); } while (0); |
514 | return NULL((void*)0); |
515 | } |
516 | |
517 | newi = mem_get0 (table->inode_pool); |
518 | if (!newi) { |
519 | goto out; |
520 | } |
521 | |
522 | newi->table = table; |
523 | |
524 | LOCK_INIT (&newi->lock)pthread_spin_init (&newi->lock, 0); |
525 | |
526 | INIT_LIST_HEAD (&newi->fd_list)do { (&newi->fd_list)->next = (&newi->fd_list )->prev = &newi->fd_list; } while (0); |
527 | INIT_LIST_HEAD (&newi->list)do { (&newi->list)->next = (&newi->list)-> prev = &newi->list; } while (0); |
528 | INIT_LIST_HEAD (&newi->hash)do { (&newi->hash)->next = (&newi->hash)-> prev = &newi->hash; } while (0); |
529 | INIT_LIST_HEAD (&newi->dentry_list)do { (&newi->dentry_list)->next = (&newi->dentry_list )->prev = &newi->dentry_list; } while (0); |
530 | |
531 | newi->_ctx = GF_CALLOC (1, (sizeof (struct _inode_ctx) *__gf_calloc (1, (sizeof (struct _inode_ctx) * table->xl-> graph->xl_count), gf_common_mt_inode_ctx) |
532 | table->xl->graph->xl_count),__gf_calloc (1, (sizeof (struct _inode_ctx) * table->xl-> graph->xl_count), gf_common_mt_inode_ctx) |
533 | gf_common_mt_inode_ctx)__gf_calloc (1, (sizeof (struct _inode_ctx) * table->xl-> graph->xl_count), gf_common_mt_inode_ctx); |
534 | |
535 | if (newi->_ctx == NULL((void*)0)) { |
536 | LOCK_DESTROY (&newi->lock)pthread_spin_destroy (&newi->lock); |
537 | mem_put (newi); |
538 | newi = NULL((void*)0); |
539 | goto out; |
540 | } |
541 | |
542 | list_add (&newi->list, &table->lru); |
543 | table->lru_size++; |
544 | |
545 | out: |
546 | |
547 | return newi; |
548 | } |
549 | |
550 | |
551 | inode_t * |
552 | inode_new (inode_table_t *table) |
553 | { |
554 | inode_t *inode = NULL((void*)0); |
555 | |
556 | if (!table) { |
557 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 557, GF_LOG_WARNING, "inode not found"); } while (0); |
558 | return NULL((void*)0); |
559 | } |
560 | |
561 | pthread_mutex_lock (&table->lock); |
562 | { |
563 | inode = __inode_create (table); |
564 | if (inode != NULL((void*)0)) { |
565 | __inode_ref (inode); |
566 | } |
567 | } |
568 | pthread_mutex_unlock (&table->lock); |
569 | |
570 | return inode; |
571 | } |
572 | |
573 | |
574 | static inode_t * |
575 | __inode_lookup (inode_t *inode) |
576 | { |
577 | if (!inode) |
578 | return NULL((void*)0); |
579 | |
580 | inode->nlookup++; |
581 | |
582 | return inode; |
583 | } |
584 | |
585 | |
586 | static inode_t * |
587 | __inode_forget (inode_t *inode, uint64_t nlookup) |
588 | { |
589 | if (!inode) |
590 | return NULL((void*)0); |
591 | |
592 | GF_ASSERT (inode->nlookup >= nlookup)do { if (!(inode->nlookup >= nlookup)) { do { do { if ( 0) printf ("Assertion failed: " "inode->nlookup >= nlookup" ); } while (0); _gf_log_callingfn ("", "inode.c", __FUNCTION__ , 592, GF_LOG_ERROR, "Assertion failed: " "inode->nlookup >= nlookup" ); } while (0); } } while (0); |
593 | |
594 | inode->nlookup -= nlookup; |
595 | |
596 | if (!nlookup) |
597 | inode->nlookup = 0; |
598 | |
599 | return inode; |
600 | } |
601 | |
602 | |
603 | dentry_t * |
604 | __dentry_grep (inode_table_t *table, inode_t *parent, const char *name) |
605 | { |
606 | int hash = 0; |
607 | dentry_t *dentry = NULL((void*)0); |
608 | dentry_t *tmp = NULL((void*)0); |
609 | |
610 | if (!table || !name || !parent) |
611 | return NULL((void*)0); |
612 | |
613 | hash = hash_dentry (parent, name, table->hashsize); |
614 | |
615 | list_for_each_entry (tmp, &table->name_hash[hash], hash)for (tmp = ((typeof(*tmp) *)((char *)((&table->name_hash [hash])->next)-(unsigned long)(&((typeof(*tmp) *)0)-> hash))); &tmp->hash != (&table->name_hash[hash] ); tmp = ((typeof(*tmp) *)((char *)(tmp->hash.next)-(unsigned long)(&((typeof(*tmp) *)0)->hash)))) { |
616 | if (tmp->parent == parent && !strcmp (tmp->name, name)) { |
617 | dentry = tmp; |
618 | break; |
619 | } |
620 | } |
621 | |
622 | return dentry; |
623 | } |
624 | |
625 | |
626 | inode_t * |
627 | inode_grep (inode_table_t *table, inode_t *parent, const char *name) |
628 | { |
629 | inode_t *inode = NULL((void*)0); |
630 | dentry_t *dentry = NULL((void*)0); |
631 | |
632 | if (!table || !parent || !name) { |
633 | gf_log_callingfn (THIS->name, GF_LOG_WARNING,do { do { if (0) printf ("table || parent || name not found") ; } while (0); _gf_log_callingfn ((*__glusterfs_this_location ())->name, "inode.c", __FUNCTION__, 634, GF_LOG_WARNING, "table || parent || name not found" ); } while (0) |
634 | "table || parent || name not found")do { do { if (0) printf ("table || parent || name not found") ; } while (0); _gf_log_callingfn ((*__glusterfs_this_location ())->name, "inode.c", __FUNCTION__, 634, GF_LOG_WARNING, "table || parent || name not found" ); } while (0); |
635 | return NULL((void*)0); |
636 | } |
637 | |
638 | pthread_mutex_lock (&table->lock); |
639 | { |
640 | dentry = __dentry_grep (table, parent, name); |
641 | |
642 | if (dentry) |
643 | inode = dentry->inode; |
644 | |
645 | if (inode) |
646 | __inode_ref (inode); |
647 | } |
648 | pthread_mutex_unlock (&table->lock); |
649 | |
650 | return inode; |
651 | } |
652 | |
653 | |
654 | inode_t * |
655 | inode_resolve (inode_table_t *table, char *path) |
656 | { |
657 | char *tmp = NULL((void*)0), *bname = NULL((void*)0), *str = NULL((void*)0), *saveptr = NULL((void*)0); |
658 | inode_t *inode = NULL((void*)0), *parent = NULL((void*)0); |
659 | |
660 | if ((path == NULL((void*)0)) || (table == NULL((void*)0))) { |
661 | goto out; |
662 | } |
663 | |
664 | parent = inode_ref (table->root); |
665 | str = tmp = gf_strdup (path); |
666 | |
667 | while (1) { |
668 | bname = strtok_r (str, "/", &saveptr); |
669 | if (bname == NULL((void*)0)) { |
670 | break; |
671 | } |
672 | |
673 | if (inode != NULL((void*)0)) { |
674 | inode_unref (inode); |
675 | } |
676 | |
677 | inode = inode_grep (table, parent, bname); |
678 | if (inode == NULL((void*)0)) { |
679 | break; |
680 | } |
681 | |
682 | if (parent != NULL((void*)0)) { |
683 | inode_unref (parent); |
684 | } |
685 | |
686 | parent = inode_ref (inode); |
687 | str = NULL((void*)0); |
688 | } |
689 | |
690 | inode_unref (parent); |
691 | GF_FREE (tmp)__gf_free (tmp); |
692 | out: |
693 | return inode; |
694 | } |
695 | |
696 | |
697 | int |
698 | inode_grep_for_gfid (inode_table_t *table, inode_t *parent, const char *name, |
699 | uuid_t gfid, ia_type_t *type) |
700 | { |
701 | inode_t *inode = NULL((void*)0); |
702 | dentry_t *dentry = NULL((void*)0); |
703 | int ret = -1; |
704 | |
705 | if (!table || !parent || !name) { |
706 | gf_log_callingfn (THIS->name, GF_LOG_WARNING,do { do { if (0) printf ("table || parent || name not found") ; } while (0); _gf_log_callingfn ((*__glusterfs_this_location ())->name, "inode.c", __FUNCTION__, 707, GF_LOG_WARNING, "table || parent || name not found" ); } while (0) |
707 | "table || parent || name not found")do { do { if (0) printf ("table || parent || name not found") ; } while (0); _gf_log_callingfn ((*__glusterfs_this_location ())->name, "inode.c", __FUNCTION__, 707, GF_LOG_WARNING, "table || parent || name not found" ); } while (0); |
708 | return ret; |
709 | } |
710 | |
711 | pthread_mutex_lock (&table->lock); |
712 | { |
713 | dentry = __dentry_grep (table, parent, name); |
714 | |
715 | if (dentry) |
716 | inode = dentry->inode; |
717 | |
718 | if (inode) { |
719 | uuid_copy (gfid, inode->gfid); |
720 | *type = inode->ia_type; |
721 | ret = 0; |
722 | } |
723 | } |
724 | pthread_mutex_unlock (&table->lock); |
725 | |
726 | return ret; |
727 | } |
728 | |
729 | |
730 | /* return 1 if gfid is of root, 0 if not */ |
731 | gf_boolean_t |
732 | __is_root_gfid (uuid_t gfid) |
733 | { |
734 | uuid_t root; |
735 | |
736 | memset (root, 0, 16); |
737 | root[15] = 1; |
738 | |
739 | if (uuid_compare (gfid, root) == 0) |
740 | return _gf_true; |
741 | |
742 | return _gf_false; |
743 | } |
744 | |
745 | |
746 | inode_t * |
747 | __inode_find (inode_table_t *table, uuid_t gfid) |
748 | { |
749 | inode_t *inode = NULL((void*)0); |
750 | inode_t *tmp = NULL((void*)0); |
751 | int hash = 0; |
752 | |
753 | if (!table) { |
754 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "table not found")do { do { if (0) printf ("table not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 754, GF_LOG_WARNING, "table not found"); } while (0); |
755 | goto out; |
756 | } |
757 | |
758 | if (__is_root_gfid (gfid)) |
759 | return table->root; |
760 | |
761 | hash = hash_gfid (gfid, 65536); |
762 | |
763 | list_for_each_entry (tmp, &table->inode_hash[hash], hash)for (tmp = ((typeof(*tmp) *)((char *)((&table->inode_hash [hash])->next)-(unsigned long)(&((typeof(*tmp) *)0)-> hash))); &tmp->hash != (&table->inode_hash[hash ]); tmp = ((typeof(*tmp) *)((char *)(tmp->hash.next)-(unsigned long)(&((typeof(*tmp) *)0)->hash)))) { |
764 | if (uuid_compare (tmp->gfid, gfid) == 0) { |
765 | inode = tmp; |
766 | break; |
767 | } |
768 | } |
769 | |
770 | out: |
771 | return inode; |
772 | } |
773 | |
774 | |
775 | inode_t * |
776 | inode_find (inode_table_t *table, uuid_t gfid) |
777 | { |
778 | inode_t *inode = NULL((void*)0); |
779 | |
780 | if (!table) { |
781 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "table not found")do { do { if (0) printf ("table not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 781, GF_LOG_WARNING, "table not found"); } while (0); |
782 | return NULL((void*)0); |
783 | } |
784 | |
785 | pthread_mutex_lock (&table->lock); |
786 | { |
787 | inode = __inode_find (table, gfid); |
788 | if (inode) |
789 | __inode_ref (inode); |
790 | } |
791 | pthread_mutex_unlock (&table->lock); |
792 | |
793 | return inode; |
794 | } |
795 | |
796 | |
797 | static inode_t * |
798 | __inode_link (inode_t *inode, inode_t *parent, const char *name, |
799 | struct iatt *iatt) |
800 | { |
801 | dentry_t *dentry = NULL((void*)0); |
802 | dentry_t *old_dentry = NULL((void*)0); |
803 | inode_t *old_inode = NULL((void*)0); |
804 | inode_table_t *table = NULL((void*)0); |
805 | inode_t *link_inode = NULL((void*)0); |
806 | |
807 | if (!inode) |
808 | return NULL((void*)0); |
809 | |
810 | table = inode->table; |
811 | if (!table) |
812 | return NULL((void*)0); |
813 | |
814 | if (parent) { |
815 | /* We should prevent inode linking between different |
816 | inode tables. This can cause errors which is very |
817 | hard to catch/debug. */ |
818 | if (inode->table != parent->table) { |
819 | GF_ASSERT (!"link attempted b/w inodes of diff table")do { if (!(!"link attempted b/w inodes of diff table")) { do { do { if (0) printf ("Assertion failed: " "!\"link attempted b/w inodes of diff table\"" ); } while (0); _gf_log_callingfn ("", "inode.c", __FUNCTION__ , 819, GF_LOG_ERROR, "Assertion failed: " "!\"link attempted b/w inodes of diff table\"" ); } while (0); } } while (0); |
820 | } |
821 | } |
822 | |
823 | link_inode = inode; |
824 | |
825 | if (!__is_inode_hashed (inode)) { |
826 | if (!iatt) |
827 | return NULL((void*)0); |
828 | |
829 | if (uuid_is_null (iatt->ia_gfid)) |
830 | return NULL((void*)0); |
831 | |
832 | old_inode = __inode_find (table, iatt->ia_gfid); |
833 | |
834 | if (old_inode) { |
835 | link_inode = old_inode; |
836 | } else { |
837 | uuid_copy (inode->gfid, iatt->ia_gfid); |
838 | inode->ia_type = iatt->ia_type; |
839 | __inode_hash (inode); |
840 | } |
841 | } |
842 | |
843 | if (name) { |
844 | if (!strcmp(name, ".") || !strcmp(name, "..")) |
845 | return link_inode; |
846 | } |
847 | |
848 | /* use only link_inode beyond this point */ |
849 | if (parent) { |
850 | old_dentry = __dentry_grep (table, parent, name); |
851 | |
852 | if (!old_dentry || old_dentry->inode != link_inode) { |
853 | dentry = __dentry_create (link_inode, parent, name); |
854 | if (!dentry) { |
855 | gf_log_callingfn (THIS->name, GF_LOG_ERROR,do { do { if (0) printf ("dentry create failed on " "inode %s with parent %s" , uuid_utoa (link_inode->gfid), uuid_utoa (parent->gfid )); } while (0); _gf_log_callingfn ((*__glusterfs_this_location ())->name, "inode.c", __FUNCTION__, 859, GF_LOG_ERROR, "dentry create failed on " "inode %s with parent %s", uuid_utoa (link_inode->gfid), uuid_utoa (parent->gfid)); } while (0) |
856 | "dentry create failed on "do { do { if (0) printf ("dentry create failed on " "inode %s with parent %s" , uuid_utoa (link_inode->gfid), uuid_utoa (parent->gfid )); } while (0); _gf_log_callingfn ((*__glusterfs_this_location ())->name, "inode.c", __FUNCTION__, 859, GF_LOG_ERROR, "dentry create failed on " "inode %s with parent %s", uuid_utoa (link_inode->gfid), uuid_utoa (parent->gfid)); } while (0) |
857 | "inode %s with parent %s",do { do { if (0) printf ("dentry create failed on " "inode %s with parent %s" , uuid_utoa (link_inode->gfid), uuid_utoa (parent->gfid )); } while (0); _gf_log_callingfn ((*__glusterfs_this_location ())->name, "inode.c", __FUNCTION__, 859, GF_LOG_ERROR, "dentry create failed on " "inode %s with parent %s", uuid_utoa (link_inode->gfid), uuid_utoa (parent->gfid)); } while (0) |
858 | uuid_utoa (link_inode->gfid),do { do { if (0) printf ("dentry create failed on " "inode %s with parent %s" , uuid_utoa (link_inode->gfid), uuid_utoa (parent->gfid )); } while (0); _gf_log_callingfn ((*__glusterfs_this_location ())->name, "inode.c", __FUNCTION__, 859, GF_LOG_ERROR, "dentry create failed on " "inode %s with parent %s", uuid_utoa (link_inode->gfid), uuid_utoa (parent->gfid)); } while (0) |
859 | uuid_utoa (parent->gfid))do { do { if (0) printf ("dentry create failed on " "inode %s with parent %s" , uuid_utoa (link_inode->gfid), uuid_utoa (parent->gfid )); } while (0); _gf_log_callingfn ((*__glusterfs_this_location ())->name, "inode.c", __FUNCTION__, 859, GF_LOG_ERROR, "dentry create failed on " "inode %s with parent %s", uuid_utoa (link_inode->gfid), uuid_utoa (parent->gfid)); } while (0); |
860 | return NULL((void*)0); |
861 | } |
862 | if (old_inode && __is_dentry_cyclic (dentry)) { |
863 | __dentry_unset (dentry); |
864 | return NULL((void*)0); |
865 | } |
866 | __dentry_hash (dentry); |
867 | |
868 | if (old_dentry) |
869 | __dentry_unset (old_dentry); |
870 | } |
871 | } |
872 | |
873 | return link_inode; |
874 | } |
875 | |
876 | |
877 | inode_t * |
878 | inode_link (inode_t *inode, inode_t *parent, const char *name, |
879 | struct iatt *iatt) |
880 | { |
881 | inode_table_t *table = NULL((void*)0); |
882 | inode_t *linked_inode = NULL((void*)0); |
883 | |
884 | if (!inode) { |
885 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 885, GF_LOG_WARNING, "inode not found"); } while (0); |
886 | return NULL((void*)0); |
887 | } |
888 | |
889 | table = inode->table; |
890 | |
891 | pthread_mutex_lock (&table->lock); |
892 | { |
893 | linked_inode = __inode_link (inode, parent, name, iatt); |
894 | |
895 | if (linked_inode) |
896 | __inode_ref (linked_inode); |
897 | } |
898 | pthread_mutex_unlock (&table->lock); |
899 | |
900 | inode_table_prune (table); |
901 | |
902 | return linked_inode; |
903 | } |
904 | |
905 | |
906 | int |
907 | inode_lookup (inode_t *inode) |
908 | { |
909 | inode_table_t *table = NULL((void*)0); |
910 | |
911 | if (!inode) { |
912 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 912, GF_LOG_WARNING, "inode not found"); } while (0); |
913 | return -1; |
914 | } |
915 | |
916 | table = inode->table; |
917 | |
918 | pthread_mutex_lock (&table->lock); |
919 | { |
920 | __inode_lookup (inode); |
921 | } |
922 | pthread_mutex_unlock (&table->lock); |
923 | |
924 | return 0; |
925 | } |
926 | |
927 | |
928 | int |
929 | inode_forget (inode_t *inode, uint64_t nlookup) |
930 | { |
931 | inode_table_t *table = NULL((void*)0); |
932 | |
933 | if (!inode) { |
934 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 934, GF_LOG_WARNING, "inode not found"); } while (0); |
935 | return -1; |
936 | } |
937 | |
938 | table = inode->table; |
939 | |
940 | pthread_mutex_lock (&table->lock); |
941 | { |
942 | __inode_forget (inode, nlookup); |
943 | } |
944 | pthread_mutex_unlock (&table->lock); |
945 | |
946 | inode_table_prune (table); |
947 | |
948 | return 0; |
949 | } |
950 | |
951 | /* |
952 | * Invalidate an inode. This is invoked when a translator decides that an inode's |
953 | * cache is no longer valid. Any translator interested in taking action in this |
954 | * situation can define the invalidate callback. |
955 | */ |
956 | int |
957 | inode_invalidate(inode_t *inode) |
958 | { |
959 | int ret = 0; |
960 | xlator_t *xl = NULL((void*)0); |
961 | xlator_t *old_THIS = NULL((void*)0); |
962 | |
963 | if (!inode) { |
964 | gf_log_callingfn(THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 964, GF_LOG_WARNING, "inode not found"); } while (0); |
965 | return -1; |
966 | } |
967 | |
968 | /* |
969 | * The master xlator is not in the graph but it can define an invalidate |
970 | * handler. |
971 | */ |
972 | xl = inode->table->xl->ctx->master; |
973 | if (xl && xl->cbks->invalidate) { |
974 | old_THIS = THIS(*__glusterfs_this_location()); |
975 | THIS(*__glusterfs_this_location()) = xl; |
976 | ret = xl->cbks->invalidate(xl, inode); |
977 | THIS(*__glusterfs_this_location()) = old_THIS; |
978 | if (ret) |
979 | return ret; |
980 | } |
981 | |
982 | xl = inode->table->xl->graph->first; |
983 | while (xl) { |
984 | old_THIS = THIS(*__glusterfs_this_location()); |
985 | THIS(*__glusterfs_this_location()) = xl; |
986 | if (xl->cbks->invalidate) |
987 | ret = xl->cbks->invalidate(xl, inode); |
988 | THIS(*__glusterfs_this_location()) = old_THIS; |
989 | |
990 | if (ret) |
991 | break; |
992 | |
993 | xl = xl->next; |
994 | } |
995 | |
996 | return ret; |
997 | } |
998 | |
999 | |
1000 | static void |
1001 | __inode_unlink (inode_t *inode, inode_t *parent, const char *name) |
1002 | { |
1003 | dentry_t *dentry = NULL((void*)0); |
1004 | |
1005 | if (!inode || !parent || !name) |
1006 | return; |
1007 | |
1008 | dentry = __dentry_search_for_inode (inode, parent->gfid, name); |
1009 | |
1010 | /* dentry NULL for corrupted backend */ |
1011 | if (dentry) |
1012 | __dentry_unset (dentry); |
1013 | } |
1014 | |
1015 | |
1016 | void |
1017 | inode_unlink (inode_t *inode, inode_t *parent, const char *name) |
1018 | { |
1019 | inode_table_t *table = NULL((void*)0); |
1020 | |
1021 | if (!inode) { |
1022 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 1022, GF_LOG_WARNING, "inode not found"); } while (0); |
1023 | return; |
1024 | } |
1025 | |
1026 | table = inode->table; |
1027 | |
1028 | pthread_mutex_lock (&table->lock); |
1029 | { |
1030 | __inode_unlink (inode, parent, name); |
1031 | } |
1032 | pthread_mutex_unlock (&table->lock); |
1033 | |
1034 | inode_table_prune (table); |
1035 | } |
1036 | |
1037 | |
1038 | int |
1039 | inode_rename (inode_table_t *table, inode_t *srcdir, const char *srcname, |
1040 | inode_t *dstdir, const char *dstname, inode_t *inode, |
1041 | struct iatt *iatt) |
1042 | { |
1043 | if (!inode) { |
1044 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 1044, GF_LOG_WARNING, "inode not found"); } while (0); |
1045 | return -1; |
1046 | } |
1047 | |
1048 | table = inode->table; |
1049 | |
1050 | pthread_mutex_lock (&table->lock); |
1051 | { |
1052 | __inode_link (inode, dstdir, dstname, iatt); |
1053 | __inode_unlink (inode, srcdir, srcname); |
1054 | } |
1055 | pthread_mutex_unlock (&table->lock); |
1056 | |
1057 | inode_table_prune (table); |
1058 | |
1059 | return 0; |
1060 | } |
1061 | |
1062 | |
1063 | static dentry_t * |
1064 | __dentry_search_arbit (inode_t *inode) |
1065 | { |
1066 | dentry_t *dentry = NULL((void*)0); |
1067 | dentry_t *trav = NULL((void*)0); |
1068 | |
1069 | if (!inode) |
1070 | return NULL((void*)0); |
1071 | |
1072 | list_for_each_entry (trav, &inode->dentry_list, inode_list)for (trav = ((typeof(*trav) *)((char *)((&inode->dentry_list )->next)-(unsigned long)(&((typeof(*trav) *)0)->inode_list ))); &trav->inode_list != (&inode->dentry_list) ; trav = ((typeof(*trav) *)((char *)(trav->inode_list.next )-(unsigned long)(&((typeof(*trav) *)0)->inode_list))) ) { |
1073 | if (__is_dentry_hashed (trav)) { |
1074 | dentry = trav; |
1075 | break; |
1076 | } |
1077 | } |
1078 | |
1079 | if (!dentry) { |
1080 | list_for_each_entry (trav, &inode->dentry_list, inode_list)for (trav = ((typeof(*trav) *)((char *)((&inode->dentry_list )->next)-(unsigned long)(&((typeof(*trav) *)0)->inode_list ))); &trav->inode_list != (&inode->dentry_list) ; trav = ((typeof(*trav) *)((char *)(trav->inode_list.next )-(unsigned long)(&((typeof(*trav) *)0)->inode_list))) ) { |
1081 | dentry = trav; |
1082 | break; |
1083 | } |
1084 | } |
1085 | |
1086 | return dentry; |
1087 | } |
1088 | |
1089 | |
1090 | inode_t * |
1091 | inode_parent (inode_t *inode, uuid_t pargfid, const char *name) |
1092 | { |
1093 | inode_t *parent = NULL((void*)0); |
1094 | inode_table_t *table = NULL((void*)0); |
1095 | dentry_t *dentry = NULL((void*)0); |
1096 | |
1097 | if (!inode) { |
1098 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "inode not found")do { do { if (0) printf ("inode not found"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 1098, GF_LOG_WARNING, "inode not found"); } while (0); |
1099 | return NULL((void*)0); |
1100 | } |
1101 | |
1102 | table = inode->table; |
1103 | |
1104 | pthread_mutex_lock (&table->lock); |
1105 | { |
1106 | if (pargfid && !uuid_is_null (pargfid) && name) { |
1107 | dentry = __dentry_search_for_inode (inode, pargfid, name); |
1108 | } else { |
1109 | dentry = __dentry_search_arbit (inode); |
1110 | } |
1111 | |
1112 | if (dentry) |
1113 | parent = dentry->parent; |
1114 | |
1115 | if (parent) |
1116 | __inode_ref (parent); |
1117 | } |
1118 | pthread_mutex_unlock (&table->lock); |
1119 | |
1120 | return parent; |
1121 | } |
1122 | |
1123 | |
1124 | int |
1125 | __inode_path (inode_t *inode, const char *name, char **bufp) |
1126 | { |
1127 | inode_table_t *table = NULL((void*)0); |
1128 | inode_t *itrav = NULL((void*)0); |
1129 | dentry_t *trav = NULL((void*)0); |
1130 | size_t i = 0, size = 0; |
1131 | int64_t ret = 0; |
1132 | int len = 0; |
1133 | char *buf = NULL((void*)0); |
1134 | |
1135 | if (!inode || uuid_is_null (inode->gfid)) { |
1136 | GF_ASSERT (0)do { if (!(0)) { do { do { if (0) printf ("Assertion failed: " "0"); } while (0); _gf_log_callingfn ("", "inode.c", __FUNCTION__ , 1136, GF_LOG_ERROR, "Assertion failed: " "0"); } while (0); } } while (0); |
1137 | gf_log_callingfn (THIS->name, GF_LOG_WARNING, "invalid inode")do { do { if (0) printf ("invalid inode"); } while (0); _gf_log_callingfn ((*__glusterfs_this_location())->name, "inode.c", __FUNCTION__ , 1137, GF_LOG_WARNING, "invalid inode"); } while (0); |
1138 | return -1; |
1139 | } |
1140 | |
1141 | table = inode->table; |
1142 | |
1143 | itrav = inode; |
1144 | for (trav = __dentry_search_arbit (itrav); trav; |
1145 | trav = __dentry_search_arbit (itrav)) { |
1146 | itrav = trav->parent; |
1147 | i ++; /* "/" */ |
1148 | i += strlen (trav->name); |
1149 | if (i > PATH_MAX4096) { |
1150 | gf_log (table->name, GF_LOG_CRITICAL,do { do { if (0) printf ("possible infinite loop detected, " "forcing break. name=(%s)" , name); } while (0); _gf_log (table->name, "inode.c", __FUNCTION__ , 1152, GF_LOG_CRITICAL, "possible infinite loop detected, " "forcing break. name=(%s)" , name); } while (0) |
1151 | "possible infinite loop detected, "do { do { if (0) printf ("possible infinite loop detected, " "forcing break. name=(%s)" , name); } while (0); _gf_log (table->name, "inode.c", __FUNCTION__ , 1152, GF_LOG_CRITICAL, "possible infinite loop detected, " "forcing break. name=(%s)" , name); } while (0) |
1152 | "forcing break. name=(%s)", name)do { do { if (0) printf ("possible infinite loop detected, " "forcing break. name=(%s)" , name); } while (0); _gf_log (table->name, "inode.c", __FUNCTION__ , 1152, GF_LOG_CRITICAL, "possible infinite loop detected, " "forcing break. name=(%s)" , name); } while (0); |
1153 | ret = -ENOENT2; |
1154 | goto out; |
1155 | } |
1156 | } |
1157 | |
1158 | if (!__is_root_gfid (itrav->gfid)) { |
1159 | /* "<gfid:00000000-0000-0000-0000-000000000000>"/path */ |
1160 | i += GFID_STR_PFX_LEN(sizeof ("<gfid:" "00000000-0000-0000-0000-000000000000" ">" ) - 1); |
1161 | } |
1162 | |
1163 | if (name) { |
1164 | i++; |
1165 | i += strlen (name); |
1166 | } |
1167 | |
1168 | ret = i; |
1169 | size = i + 1; |
1170 | buf = GF_CALLOC (size, sizeof (char), gf_common_mt_char)__gf_calloc (size, sizeof (char), gf_common_mt_char); |
1171 | if (buf) { |
1172 | |
1173 | buf[size - 1] = 0; |
1174 | |
1175 | if (name) { |
1176 | len = strlen (name); |
1177 | strncpy (buf + (i - len), name, len); |
1178 | buf[i-len-1] = '/'; |
1179 | i -= (len + 1); |
1180 | } |
1181 | |
1182 | itrav = inode; |
1183 | for (trav = __dentry_search_arbit (itrav); trav; |
1184 | trav = __dentry_search_arbit (itrav)) { |
1185 | itrav = trav->parent; |
1186 | len = strlen (trav->name); |
1187 | strncpy (buf + (i - len), trav->name, len); |
1188 | buf[i-len-1] = '/'; |
1189 | i -= (len + 1); |
1190 | } |
1191 | |
1192 | if (!__is_root_gfid (itrav->gfid)) { |
1193 | snprintf (&buf[i-GFID_STR_PFX_LEN(sizeof ("<gfid:" "00000000-0000-0000-0000-000000000000" ">" ) - 1)], GFID_STR_PFX_LEN(sizeof ("<gfid:" "00000000-0000-0000-0000-000000000000" ">" ) - 1), |
1194 | INODE_PATH_FMT"<gfid:%s>", uuid_utoa (itrav->gfid)); |
1195 | buf[i-1] = '>'; |
1196 | } |
1197 | |
1198 | *bufp = buf; |
1199 | } else { |
1200 | ret = -ENOMEM12; |
1201 | } |
1202 | |
1203 | out: |
1204 | if (__is_root_gfid (inode->gfid) && !name) { |
1205 | ret = 1; |
1206 | GF_FREE (buf)__gf_free (buf); |
1207 | buf = GF_CALLOC (ret + 1, sizeof (char), gf_common_mt_char)__gf_calloc (ret + 1, sizeof (char), gf_common_mt_char); |
1208 | if (buf) { |
1209 | strcpy (buf, "/"); |
1210 | *bufp = buf; |
1211 | } else { |
1212 | ret = -ENOMEM12; |
1213 | } |
1214 | } |
1215 | |
1216 | if (ret < 0) |
1217 | *bufp = NULL((void*)0); |
1218 | return ret; |
1219 | } |
1220 | |
1221 | |
1222 | int |
1223 | inode_path (inode_t *inode, const char *name, char **bufp) |
1224 | { |
1225 | inode_table_t *table = NULL((void*)0); |
1226 | int ret = -1; |
1227 | |
1228 | if (!inode) |
1229 | return -1; |
1230 | |
1231 | table = inode->table; |
1232 | |
1233 | pthread_mutex_lock (&table->lock); |
1234 | { |
1235 | ret = __inode_path (inode, name, bufp); |
1236 | } |
1237 | pthread_mutex_unlock (&table->lock); |
1238 | |
1239 | return ret; |
1240 | } |
1241 | |
1242 | |
1243 | static int |
1244 | inode_table_prune (inode_table_t *table) |
1245 | { |
1246 | int ret = 0; |
1247 | struct list_head purge = {0, }; |
1248 | inode_t *del = NULL((void*)0); |
1249 | inode_t *tmp = NULL((void*)0); |
1250 | inode_t *entry = NULL((void*)0); |
1251 | |
1252 | if (!table) |
1253 | return -1; |
1254 | |
1255 | INIT_LIST_HEAD (&purge)do { (&purge)->next = (&purge)->prev = &purge ; } while (0); |
1256 | |
1257 | pthread_mutex_lock (&table->lock); |
1258 | { |
1259 | while (table->lru_limit |
1260 | && table->lru_size > (table->lru_limit)) { |
1261 | |
1262 | entry = list_entry (table->lru.next, inode_t, list)((inode_t *)((char *)(table->lru.next)-(unsigned long)(& ((inode_t *)0)->list))); |
1263 | |
1264 | table->lru_size--; |
1265 | __inode_retire (entry); |
1266 | |
1267 | ret++; |
1268 | } |
1269 | |
1270 | list_splice_init (&table->purge, &purge); |
1271 | table->purge_size = 0; |
1272 | } |
1273 | pthread_mutex_unlock (&table->lock); |
1274 | |
1275 | { |
1276 | list_for_each_entry_safe (del, tmp, &purge, list)for (del = ((typeof(*del) *)((char *)((&purge)->next)- (unsigned long)(&((typeof(*del) *)0)->list))), tmp = ( (typeof(*del) *)((char *)(del->list.next)-(unsigned long)( &((typeof(*del) *)0)->list))); &del->list != (& purge); del = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->list .next)-(unsigned long)(&((typeof(*tmp) *)0)->list)))) { |
1277 | list_del_init (&del->list); |
1278 | __inode_forget (del, 0); |
1279 | __inode_destroy (del); |
1280 | } |
1281 | } |
1282 | |
1283 | return ret; |
1284 | } |
1285 | |
1286 | |
1287 | static void |
1288 | __inode_table_init_root (inode_table_t *table) |
1289 | { |
1290 | inode_t *root = NULL((void*)0); |
1291 | struct iatt iatt = {0, }; |
1292 | |
1293 | if (!table) |
1294 | return; |
1295 | |
1296 | root = __inode_create (table); |
1297 | |
1298 | iatt.ia_gfid[15] = 1; |
1299 | iatt.ia_ino = 1; |
1300 | iatt.ia_type = IA_IFDIR; |
1301 | |
1302 | __inode_link (root, NULL((void*)0), NULL((void*)0), &iatt); |
1303 | table->root = root; |
1304 | } |
1305 | |
1306 | |
1307 | inode_table_t * |
1308 | inode_table_new (size_t lru_limit, xlator_t *xl) |
1309 | { |
1310 | inode_table_t *new = NULL((void*)0); |
1311 | int ret = -1; |
1312 | int i = 0; |
1313 | |
1314 | new = (void *)GF_CALLOC(1, sizeof (*new), gf_common_mt_inode_table_t)__gf_calloc (1, sizeof (*new), gf_common_mt_inode_table_t); |
1315 | if (!new) |
1316 | return NULL((void*)0); |
1317 | |
1318 | new->xl = xl; |
1319 | |
1320 | new->lru_limit = lru_limit; |
1321 | |
1322 | new->hashsize = 14057; /* TODO: Random Number?? */ |
1323 | |
1324 | /* In case FUSE is initing the inode table. */ |
1325 | if (lru_limit == 0) |
1326 | lru_limit = DEFAULT_INODE_MEMPOOL_ENTRIES32 * 1024; |
1327 | |
1328 | new->inode_pool = mem_pool_new (inode_t, lru_limit)mem_pool_new_fn (sizeof(inode_t), lru_limit, "inode_t"); |
1329 | |
1330 | if (!new->inode_pool) |
1331 | goto out; |
1332 | |
1333 | new->dentry_pool = mem_pool_new (dentry_t, lru_limit)mem_pool_new_fn (sizeof(dentry_t), lru_limit, "dentry_t"); |
1334 | |
1335 | if (!new->dentry_pool) |
1336 | goto out; |
1337 | |
1338 | new->inode_hash = (void *)GF_CALLOC (65536,__gf_calloc (65536, sizeof (struct list_head), gf_common_mt_list_head ) |
1339 | sizeof (struct list_head),__gf_calloc (65536, sizeof (struct list_head), gf_common_mt_list_head ) |
1340 | gf_common_mt_list_head)__gf_calloc (65536, sizeof (struct list_head), gf_common_mt_list_head ); |
1341 | if (!new->inode_hash) |
1342 | goto out; |
1343 | |
1344 | new->name_hash = (void *)GF_CALLOC (new->hashsize,__gf_calloc (new->hashsize, sizeof (struct list_head), gf_common_mt_list_head ) |
1345 | sizeof (struct list_head),__gf_calloc (new->hashsize, sizeof (struct list_head), gf_common_mt_list_head ) |
1346 | gf_common_mt_list_head)__gf_calloc (new->hashsize, sizeof (struct list_head), gf_common_mt_list_head ); |
1347 | if (!new->name_hash) |
1348 | goto out; |
1349 | |
1350 | /* if number of fd open in one process is more than this, |
1351 | we may hit perf issues */ |
1352 | new->fd_mem_pool = mem_pool_new (fd_t, 1024)mem_pool_new_fn (sizeof(fd_t), 1024, "fd_t"); |
1353 | |
1354 | if (!new->fd_mem_pool) |
1355 | goto out; |
1356 | |
1357 | for (i = 0; i < 65536; i++) { |
1358 | INIT_LIST_HEAD (&new->inode_hash[i])do { (&new->inode_hash[i])->next = (&new->inode_hash [i])->prev = &new->inode_hash[i]; } while (0); |
1359 | } |
1360 | |
1361 | |
1362 | for (i = 0; i < new->hashsize; i++) { |
1363 | INIT_LIST_HEAD (&new->name_hash[i])do { (&new->name_hash[i])->next = (&new->name_hash [i])->prev = &new->name_hash[i]; } while (0); |
1364 | } |
1365 | |
1366 | INIT_LIST_HEAD (&new->active)do { (&new->active)->next = (&new->active)-> prev = &new->active; } while (0); |
1367 | INIT_LIST_HEAD (&new->lru)do { (&new->lru)->next = (&new->lru)->prev = &new->lru; } while (0); |
1368 | INIT_LIST_HEAD (&new->purge)do { (&new->purge)->next = (&new->purge)-> prev = &new->purge; } while (0); |
1369 | |
1370 | ret = gf_asprintf (&new->name, "%s/inode", xl->name); |
1371 | if (-1 == ret) { |
1372 | /* TODO: This should be ok to continue, check with avati */ |
1373 | ; |
1374 | } |
1375 | |
1376 | __inode_table_init_root (new); |
1377 | |
1378 | pthread_mutex_init (&new->lock, NULL((void*)0)); |
1379 | |
1380 | ret = 0; |
1381 | out: |
1382 | if (ret) { |
1383 | if (new) { |
1384 | GF_FREE (new->inode_hash)__gf_free (new->inode_hash); |
1385 | GF_FREE (new->name_hash)__gf_free (new->name_hash); |
1386 | if (new->dentry_pool) |
1387 | mem_pool_destroy (new->dentry_pool); |
1388 | if (new->inode_pool) |
1389 | mem_pool_destroy (new->inode_pool); |
1390 | GF_FREE (new)__gf_free (new); |
1391 | new = NULL((void*)0); |
1392 | } |
1393 | } |
1394 | |
1395 | return new; |
1396 | } |
1397 | |
1398 | |
1399 | inode_t * |
1400 | inode_from_path (inode_table_t *itable, const char *path) |
1401 | { |
1402 | inode_t *inode = NULL((void*)0); |
1403 | inode_t *parent = NULL((void*)0); |
1404 | inode_t *root = NULL((void*)0); |
1405 | inode_t *curr = NULL((void*)0); |
1406 | char *pathname = NULL((void*)0); |
1407 | char *component = NULL((void*)0), *next_component = NULL((void*)0); |
1408 | char *strtokptr = NULL((void*)0); |
1409 | |
1410 | if (!itable || !path) |
1411 | return NULL((void*)0); |
1412 | |
1413 | /* top-down approach */ |
1414 | pathname = gf_strdup (path); |
1415 | if (pathname == NULL((void*)0)) { |
1416 | goto out; |
1417 | } |
1418 | |
1419 | root = itable->root; |
1420 | parent = inode_ref (root); |
1421 | component = strtok_r (pathname, "/", &strtokptr); |
1422 | |
1423 | if (component == NULL((void*)0)) |
1424 | /* root inode */ |
1425 | inode = inode_ref (parent); |
1426 | |
1427 | while (component) { |
1428 | curr = inode_grep (itable, parent, component); |
1429 | |
1430 | if (curr == NULL((void*)0)) { |
1431 | strtok_r (NULL((void*)0), "/", &strtokptr); |
1432 | break; |
1433 | } |
1434 | |
1435 | next_component = strtok_r (NULL((void*)0), "/", &strtokptr); |
1436 | |
1437 | if (next_component) { |
1438 | inode_unref (parent); |
1439 | parent = curr; |
1440 | curr = NULL((void*)0); |
1441 | } else { |
1442 | inode = curr; |
1443 | } |
1444 | |
1445 | component = next_component; |
1446 | } |
1447 | |
1448 | if (parent) |
1449 | inode_unref (parent); |
1450 | |
1451 | GF_FREE (pathname)__gf_free (pathname); |
1452 | |
1453 | out: |
1454 | return inode; |
1455 | } |
1456 | |
1457 | |
1458 | int |
1459 | __inode_ctx_set2 (inode_t *inode, xlator_t *xlator, uint64_t *value1_p, |
1460 | uint64_t *value2_p) |
1461 | { |
1462 | int ret = 0; |
1463 | int index = 0; |
1464 | int set_idx = -1; |
1465 | |
1466 | if (!inode || !xlator) |
1467 | return -1; |
1468 | |
1469 | for (index = 0; index < xlator->graph->xl_count; index++) { |
1470 | if (!inode->_ctx[index].xl_key) { |
1471 | if (set_idx == -1) |
1472 | set_idx = index; |
1473 | /* dont break, to check if key already exists |
1474 | further on */ |
1475 | } |
1476 | if (inode->_ctx[index].xl_key == xlator) { |
1477 | set_idx = index; |
1478 | break; |
1479 | } |
1480 | } |
1481 | |
1482 | if (set_idx == -1) { |
1483 | ret = -1; |
1484 | goto out;; |
1485 | } |
1486 | |
1487 | inode->_ctx[set_idx].xl_key = xlator; |
1488 | if (value1_p) |
1489 | inode->_ctx[set_idx].value1 = *value1_p; |
1490 | if (value2_p) |
1491 | inode->_ctx[set_idx].value2 = *value2_p; |
1492 | out: |
1493 | return ret; |
1494 | } |
1495 | |
1496 | |
1497 | int |
1498 | inode_ctx_set2 (inode_t *inode, xlator_t *xlator, uint64_t *value1_p, |
1499 | uint64_t *value2_p) |
1500 | { |
1501 | int ret = 0; |
1502 | |
1503 | if (!inode || !xlator) |
1504 | return -1; |
1505 | |
1506 | LOCK (&inode->lock)pthread_spin_lock (&inode->lock); |
1507 | { |
1508 | ret = __inode_ctx_set2 (inode, xlator, value1_p, value2_p); |
1509 | } |
1510 | UNLOCK (&inode->lock)pthread_spin_unlock (&inode->lock); |
1511 | |
1512 | return ret; |
1513 | } |
1514 | |
1515 | |
1516 | int |
1517 | __inode_ctx_get2 (inode_t *inode, xlator_t *xlator, uint64_t *value1, |
1518 | uint64_t *value2) |
1519 | { |
1520 | int index = 0; |
1521 | int ret = 0; |
1522 | |
1523 | if (!inode || !xlator) |
1524 | return -1; |
1525 | |
1526 | for (index = 0; index < xlator->graph->xl_count; index++) { |
1527 | if (inode->_ctx[index].xl_key == xlator) |
1528 | break; |
1529 | } |
1530 | |
1531 | if (index == xlator->graph->xl_count) { |
1532 | ret = -1; |
1533 | goto out; |
1534 | } |
1535 | |
1536 | if (value1) |
1537 | *value1 = inode->_ctx[index].value1; |
1538 | |
1539 | if (value2) |
1540 | *value2 = inode->_ctx[index].value2; |
1541 | |
1542 | out: |
1543 | return ret; |
1544 | } |
1545 | |
1546 | |
1547 | int |
1548 | inode_ctx_get2 (inode_t *inode, xlator_t *xlator, uint64_t *value1, |
1549 | uint64_t *value2) |
1550 | { |
1551 | int ret = 0; |
1552 | |
1553 | if (!inode || !xlator) |
1554 | return -1; |
1555 | |
1556 | LOCK (&inode->lock)pthread_spin_lock (&inode->lock); |
1557 | { |
1558 | ret = __inode_ctx_get2 (inode, xlator, value1, value2); |
1559 | } |
1560 | UNLOCK (&inode->lock)pthread_spin_unlock (&inode->lock); |
1561 | |
1562 | return ret; |
1563 | } |
1564 | |
1565 | |
1566 | int |
1567 | inode_ctx_del2 (inode_t *inode, xlator_t *xlator, uint64_t *value1, |
1568 | uint64_t *value2) |
1569 | { |
1570 | int index = 0; |
1571 | int ret = 0; |
1572 | |
1573 | if (!inode || !xlator) |
1574 | return -1; |
1575 | |
1576 | LOCK (&inode->lock)pthread_spin_lock (&inode->lock); |
1577 | { |
1578 | for (index = 0; index < xlator->graph->xl_count; index++) { |
1579 | if (inode->_ctx[index].xl_key == xlator) |
1580 | break; |
1581 | } |
1582 | |
1583 | if (index == xlator->graph->xl_count) { |
1584 | ret = -1; |
1585 | goto unlock; |
1586 | } |
1587 | |
1588 | if (value1) |
1589 | *value1 = inode->_ctx[index].value1; |
1590 | if (value2) |
1591 | *value2 = inode->_ctx[index].value2; |
1592 | |
1593 | inode->_ctx[index].key = 0; |
1594 | inode->_ctx[index].value1 = 0; |
1595 | inode->_ctx[index].value2 = 0; |
1596 | } |
1597 | unlock: |
1598 | UNLOCK (&inode->lock)pthread_spin_unlock (&inode->lock); |
1599 | |
1600 | return ret; |
1601 | } |
1602 | |
1603 | |
1604 | void |
1605 | inode_dump (inode_t *inode, char *prefix) |
1606 | { |
1607 | int ret = -1; |
1608 | xlator_t *xl = NULL((void*)0); |
1609 | int i = 0; |
1610 | fd_t *fd = NULL((void*)0); |
1611 | struct _inode_ctx *inode_ctx = NULL((void*)0); |
1612 | struct list_head fd_list; |
1613 | |
1614 | if (!inode) |
1615 | return; |
1616 | |
1617 | INIT_LIST_HEAD (&fd_list)do { (&fd_list)->next = (&fd_list)->prev = & fd_list; } while (0); |
1618 | |
1619 | ret = TRY_LOCK(&inode->lock)pthread_spin_trylock (&inode->lock); |
1620 | if (ret != 0) { |
1621 | return; |
1622 | } |
1623 | |
1624 | { |
1625 | gf_proc_dump_write("gfid", "%s", uuid_utoa (inode->gfid)); |
1626 | gf_proc_dump_write("nlookup", "%ld", inode->nlookup); |
1627 | gf_proc_dump_write("fd-count", "%u", inode->fd_count); |
1628 | gf_proc_dump_write("ref", "%u", inode->ref); |
1629 | gf_proc_dump_write("ia_type", "%d", inode->ia_type); |
1630 | if (inode->_ctx) { |
1631 | inode_ctx = GF_CALLOC (inode->table->xl->graph->xl_count,__gf_calloc (inode->table->xl->graph->xl_count, sizeof (*inode_ctx), gf_common_mt_inode_ctx) |
1632 | sizeof (*inode_ctx),__gf_calloc (inode->table->xl->graph->xl_count, sizeof (*inode_ctx), gf_common_mt_inode_ctx) |
1633 | gf_common_mt_inode_ctx)__gf_calloc (inode->table->xl->graph->xl_count, sizeof (*inode_ctx), gf_common_mt_inode_ctx); |
1634 | if (inode_ctx == NULL((void*)0)) { |
1635 | goto unlock; |
1636 | } |
1637 | |
1638 | for (i = 0; i < inode->table->xl->graph->xl_count; i++) { |
1639 | inode_ctx[i] = inode->_ctx[i]; |
1640 | } |
1641 | } |
1642 | |
1643 | if (dump_options.xl_options.dump_fdctx != _gf_true) |
1644 | goto unlock; |
1645 | |
1646 | |
1647 | list_for_each_entry (fd, &inode->fd_list, inode_list)for (fd = ((typeof(*fd) *)((char *)((&inode->fd_list)-> next)-(unsigned long)(&((typeof(*fd) *)0)->inode_list) )); &fd->inode_list != (&inode->fd_list); fd = ( (typeof(*fd) *)((char *)(fd->inode_list.next)-(unsigned long )(&((typeof(*fd) *)0)->inode_list)))) { |
1648 | fd_ctx_dump (fd, prefix); |
1649 | } |
1650 | } |
1651 | unlock: |
1652 | UNLOCK(&inode->lock)pthread_spin_unlock (&inode->lock); |
1653 | |
1654 | if (inode_ctx && (dump_options.xl_options.dump_inodectx == _gf_true)) { |
1655 | for (i = 0; i < inode->table->xl->graph->xl_count; i++) { |
1656 | if (inode_ctx[i].xl_key) { |
1657 | xl = (xlator_t *)(long)inode_ctx[i].xl_key; |
1658 | if (xl->dumpops && xl->dumpops->inodectx) |
1659 | xl->dumpops->inodectx (xl, inode); |
1660 | } |
1661 | } |
1662 | } |
1663 | |
1664 | GF_FREE (inode_ctx)__gf_free (inode_ctx); |
1665 | |
1666 | return; |
1667 | } |
1668 | |
1669 | void |
1670 | inode_table_dump (inode_table_t *itable, char *prefix) |
1671 | { |
1672 | |
1673 | char key[GF_DUMP_MAX_BUF_LEN4096]; |
1674 | int ret = 0; |
1675 | |
1676 | if (!itable) |
1677 | return; |
1678 | |
1679 | memset(key, 0, sizeof(key)); |
1680 | ret = pthread_mutex_trylock(&itable->lock); |
1681 | |
1682 | if (ret != 0) { |
1683 | return; |
1684 | } |
1685 | |
1686 | gf_proc_dump_build_key(key, prefix, "hashsize"){ _gf_proc_dump_build_key(key, prefix, "hashsize"); }; |
1687 | gf_proc_dump_write(key, "%d", itable->hashsize); |
1688 | gf_proc_dump_build_key(key, prefix, "name"){ _gf_proc_dump_build_key(key, prefix, "name"); }; |
1689 | gf_proc_dump_write(key, "%s", itable->name); |
1690 | |
1691 | gf_proc_dump_build_key(key, prefix, "lru_limit"){ _gf_proc_dump_build_key(key, prefix, "lru_limit"); }; |
1692 | gf_proc_dump_write(key, "%d", itable->lru_limit); |
1693 | gf_proc_dump_build_key(key, prefix, "active_size"){ _gf_proc_dump_build_key(key, prefix, "active_size"); }; |
1694 | gf_proc_dump_write(key, "%d", itable->active_size); |
1695 | gf_proc_dump_build_key(key, prefix, "lru_size"){ _gf_proc_dump_build_key(key, prefix, "lru_size"); }; |
1696 | gf_proc_dump_write(key, "%d", itable->lru_size); |
1697 | gf_proc_dump_build_key(key, prefix, "purge_size"){ _gf_proc_dump_build_key(key, prefix, "purge_size"); }; |
1698 | gf_proc_dump_write(key, "%d", itable->purge_size); |
1699 | |
1700 | INODE_DUMP_LIST(&itable->active, key, prefix, "active"){ int i = 1; inode_t *inode = ((void*)0); for (inode = ((typeof (*inode) *)((char *)((&itable->active)->next)-(unsigned long)(&((typeof(*inode) *)0)->list))); &inode-> list != (&itable->active); inode = ((typeof(*inode) *) ((char *)(inode->list.next)-(unsigned long)(&((typeof( *inode) *)0)->list)))) { { _gf_proc_dump_build_key(key, prefix , "%s.%d","active", i++); }; gf_proc_dump_add_section(key); inode_dump (inode, key); } }; |
1701 | INODE_DUMP_LIST(&itable->lru, key, prefix, "lru"){ int i = 1; inode_t *inode = ((void*)0); for (inode = ((typeof (*inode) *)((char *)((&itable->lru)->next)-(unsigned long)(&((typeof(*inode) *)0)->list))); &inode-> list != (&itable->lru); inode = ((typeof(*inode) *)((char *)(inode->list.next)-(unsigned long)(&((typeof(*inode ) *)0)->list)))) { { _gf_proc_dump_build_key(key, prefix, "%s.%d" ,"lru", i++); }; gf_proc_dump_add_section(key); inode_dump(inode , key); } }; |
1702 | INODE_DUMP_LIST(&itable->purge, key, prefix, "purge"){ int i = 1; inode_t *inode = ((void*)0); for (inode = ((typeof (*inode) *)((char *)((&itable->purge)->next)-(unsigned long)(&((typeof(*inode) *)0)->list))); &inode-> list != (&itable->purge); inode = ((typeof(*inode) *)( (char *)(inode->list.next)-(unsigned long)(&((typeof(* inode) *)0)->list)))) { { _gf_proc_dump_build_key(key, prefix , "%s.%d","purge", i++); }; gf_proc_dump_add_section(key); inode_dump (inode, key); } }; |
1703 | |
1704 | pthread_mutex_unlock(&itable->lock); |
1705 | } |
1706 | |
1707 | void |
1708 | inode_dump_to_dict (inode_t *inode, char *prefix, dict_t *dict) |
1709 | { |
1710 | int ret = -1; |
1711 | char key[GF_DUMP_MAX_BUF_LEN4096] = {0,}; |
1712 | |
1713 | ret = TRY_LOCK (&inode->lock)pthread_spin_trylock (&inode->lock); |
1714 | if (ret) |
1715 | return; |
1716 | |
1717 | memset (key, 0, sizeof (key)); |
1718 | snprintf (key, sizeof (key), "%s.gfid", prefix); |
1719 | ret = dict_set_dynstr (dict, key, gf_strdup (uuid_utoa (inode->gfid))); |
1720 | if (ret) |
1721 | goto out; |
1722 | |
1723 | memset (key, 0, sizeof (key)); |
1724 | snprintf (key, sizeof (key), "%s.nlookup", prefix); |
1725 | ret = dict_set_uint64 (dict, key, inode->nlookup); |
1726 | if (ret) |
1727 | goto out; |
1728 | |
1729 | memset (key, 0, sizeof (key)); |
1730 | snprintf (key, sizeof (key), "%s.ref", prefix); |
1731 | ret = dict_set_uint32 (dict, key, inode->ref); |
1732 | if (ret) |
1733 | goto out; |
1734 | |
1735 | memset (key, 0, sizeof (key)); |
1736 | snprintf (key, sizeof (key), "%s.ia_type", prefix); |
1737 | ret = dict_set_int32 (dict, key, inode->ia_type); |
Value stored to 'ret' is never read | |
1738 | |
1739 | out: |
1740 | UNLOCK (&inode->lock)pthread_spin_unlock (&inode->lock); |
1741 | return; |
1742 | } |
1743 | |
1744 | void |
1745 | inode_table_dump_to_dict (inode_table_t *itable, char *prefix, dict_t *dict) |
1746 | { |
1747 | char key[GF_DUMP_MAX_BUF_LEN4096] = {0,}; |
1748 | int ret = 0; |
1749 | inode_t *inode = NULL((void*)0); |
1750 | int count = 0; |
1751 | |
1752 | ret = pthread_mutex_trylock (&itable->lock); |
1753 | if (ret) |
1754 | return; |
1755 | |
1756 | memset (key, 0, sizeof (key)); |
1757 | snprintf (key, sizeof (key), "%s.itable.active_size", prefix); |
1758 | ret = dict_set_uint32 (dict, key, itable->active_size); |
1759 | if (ret) |
1760 | goto out; |
1761 | |
1762 | memset (key, 0, sizeof (key)); |
1763 | snprintf (key, sizeof (key), "%s.itable.lru_size", prefix); |
1764 | ret = dict_set_uint32 (dict, key, itable->lru_size); |
1765 | if (ret) |
1766 | goto out; |
1767 | |
1768 | memset (key, 0, sizeof (key)); |
1769 | snprintf (key, sizeof (key), "%s.itable.purge_size", prefix); |
1770 | ret = dict_set_uint32 (dict, key, itable->purge_size); |
1771 | if (ret) |
1772 | goto out; |
1773 | |
1774 | list_for_each_entry (inode, &itable->active, list)for (inode = ((typeof(*inode) *)((char *)((&itable->active )->next)-(unsigned long)(&((typeof(*inode) *)0)->list ))); &inode->list != (&itable->active); inode = ((typeof(*inode) *)((char *)(inode->list.next)-(unsigned long )(&((typeof(*inode) *)0)->list)))) { |
1775 | memset (key, 0, sizeof (key)); |
1776 | snprintf (key, sizeof (key), "%s.itable.active%d", prefix, |
1777 | count++); |
1778 | inode_dump_to_dict (inode, key, dict); |
1779 | } |
1780 | count = 0; |
1781 | |
1782 | list_for_each_entry (inode, &itable->lru, list)for (inode = ((typeof(*inode) *)((char *)((&itable->lru )->next)-(unsigned long)(&((typeof(*inode) *)0)->list ))); &inode->list != (&itable->lru); inode = (( typeof(*inode) *)((char *)(inode->list.next)-(unsigned long )(&((typeof(*inode) *)0)->list)))) { |
1783 | memset (key, 0, sizeof (key)); |
1784 | snprintf (key, sizeof (key), "%s.itable.lru%d", prefix, |
1785 | count++); |
1786 | inode_dump_to_dict (inode, key, dict); |
1787 | } |
1788 | count = 0; |
1789 | |
1790 | list_for_each_entry (inode, &itable->purge, list)for (inode = ((typeof(*inode) *)((char *)((&itable->purge )->next)-(unsigned long)(&((typeof(*inode) *)0)->list ))); &inode->list != (&itable->purge); inode = ( (typeof(*inode) *)((char *)(inode->list.next)-(unsigned long )(&((typeof(*inode) *)0)->list)))) { |
1791 | memset (key, 0, sizeof (key)); |
1792 | snprintf (key, sizeof (key), "%s.itable.purge%d", prefix, |
1793 | count++); |
1794 | inode_dump_to_dict (inode, key, dict); |
1795 | } |
1796 | |
1797 | out: |
1798 | pthread_mutex_unlock (&itable->lock); |
1799 | |
1800 | return; |
1801 | } |