Bug Summary

File:xlators/performance/io-cache/src/io-cache.c
Location:line 1023, column 49
Description:Value stored to 'need_validate' is never read

Annotated Source Code

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 "glusterfs.h"
17#include "logging.h"
18#include "dict.h"
19#include "xlator.h"
20#include "io-cache.h"
21#include "ioc-mem-types.h"
22#include "statedump.h"
23#include <assert.h>
24#include <sys/time.h>
25
26int ioc_log2_page_size;
27
28uint32_t
29ioc_get_priority (ioc_table_t *table, const char *path);
30
31struct volume_options options[];
32
33
34static inline uint32_t
35ioc_hashfn (void *data, int len)
36{
37 off_t offset;
38
39 offset = *(off_t *) data;
40
41 return (offset >> ioc_log2_page_size);
42}
43
44static inline ioc_inode_t *
45ioc_inode_reupdate (ioc_inode_t *ioc_inode)
46{
47 ioc_table_t *table = NULL((void*)0);
48
49 table = ioc_inode->table;
50
51 list_add_tail (&ioc_inode->inode_lru,
52 &table->inode_lru[ioc_inode->weight]);
53
54 return ioc_inode;
55}
56
57static inline ioc_inode_t *
58ioc_get_inode (dict_t *dict, char *name)
59{
60 ioc_inode_t *ioc_inode = NULL((void*)0);
61 data_t *ioc_inode_data = NULL((void*)0);
62 ioc_table_t *table = NULL((void*)0);
63
64 ioc_inode_data = dict_get (dict, name);
65 if (ioc_inode_data) {
66 ioc_inode = data_to_ptr (ioc_inode_data);
67 table = ioc_inode->table;
68
69 ioc_table_lock (table)do { do { do { if (0) printf ("locked table(%p)", table); } while
(0); _gf_log (table->xl->name, "io-cache.c", __FUNCTION__
, 69, GF_LOG_TRACE, "locked table(%p)", table); } while (0); pthread_mutex_lock
(&table->table_lock); } while (0)
;
70 {
71 if (list_empty (&ioc_inode->inode_lru)) {
72 ioc_inode = ioc_inode_reupdate (ioc_inode);
73 }
74 }
75 ioc_table_unlock (table)do { do { do { if (0) printf ("unlocked table(%p)", table); }
while (0); _gf_log (table->xl->name, "io-cache.c", __FUNCTION__
, 75, GF_LOG_TRACE, "unlocked table(%p)", table); } while (0)
; pthread_mutex_unlock (&table->table_lock); } while (
0)
;
76 }
77
78 return ioc_inode;
79}
80
81int32_t
82ioc_inode_need_revalidate (ioc_inode_t *ioc_inode)
83{
84 int8_t need_revalidate = 0;
85 struct timeval tv = {0,};
86 ioc_table_t *table = NULL((void*)0);
87
88 table = ioc_inode->table;
89
90 gettimeofday (&tv, NULL((void*)0));
91
92 if (time_elapsed (&tv, &ioc_inode->cache.tv) >= table->cache_timeout)
93 need_revalidate = 1;
94
95 return need_revalidate;
96}
97
98/*
99 * __ioc_inode_flush - flush all the cached pages of the given inode
100 *
101 * @ioc_inode:
102 *
103 * assumes lock is held
104 */
105int64_t
106__ioc_inode_flush (ioc_inode_t *ioc_inode)
107{
108 ioc_page_t *curr = NULL((void*)0), *next = NULL((void*)0);
109 int64_t destroy_size = 0;
110 int64_t ret = 0;
111
112 list_for_each_entry_safe (curr, next, &ioc_inode->cache.page_lru,for (curr = ((typeof(*curr) *)((char *)((&ioc_inode->cache
.page_lru)->next)-(unsigned long)(&((typeof(*curr) *)0
)->page_lru))), next = ((typeof(*curr) *)((char *)(curr->
page_lru.next)-(unsigned long)(&((typeof(*curr) *)0)->
page_lru))); &curr->page_lru != (&ioc_inode->cache
.page_lru); curr = next, next = ((typeof(*next) *)((char *)(next
->page_lru.next)-(unsigned long)(&((typeof(*next) *)0)
->page_lru))))
113 page_lru)for (curr = ((typeof(*curr) *)((char *)((&ioc_inode->cache
.page_lru)->next)-(unsigned long)(&((typeof(*curr) *)0
)->page_lru))), next = ((typeof(*curr) *)((char *)(curr->
page_lru.next)-(unsigned long)(&((typeof(*curr) *)0)->
page_lru))); &curr->page_lru != (&ioc_inode->cache
.page_lru); curr = next, next = ((typeof(*next) *)((char *)(next
->page_lru.next)-(unsigned long)(&((typeof(*next) *)0)
->page_lru))))
{
114 ret = __ioc_page_destroy (curr);
115
116 if (ret != -1)
117 destroy_size += ret;
118 }
119
120 return destroy_size;
121}
122
123void
124ioc_inode_flush (ioc_inode_t *ioc_inode)
125{
126 int64_t destroy_size = 0;
127
128 ioc_inode_lock (ioc_inode)do { do { do { if (0) printf ("locked inode(%p)", ioc_inode);
} while (0); _gf_log (ioc_inode->table->xl->name, "io-cache.c"
, __FUNCTION__, 128, GF_LOG_TRACE, "locked inode(%p)", ioc_inode
); } while (0); pthread_mutex_lock (&ioc_inode->inode_lock
); } while (0)
;
129 {
130 destroy_size = __ioc_inode_flush (ioc_inode);
131 }
132 ioc_inode_unlock (ioc_inode)do { do { do { if (0) printf ("unlocked inode(%p)", ioc_inode
); } while (0); _gf_log (ioc_inode->table->xl->name,
"io-cache.c", __FUNCTION__, 132, GF_LOG_TRACE, "unlocked inode(%p)"
, ioc_inode); } while (0); pthread_mutex_unlock (&ioc_inode
->inode_lock); } while (0)
;
133
134 if (destroy_size) {
135 ioc_table_lock (ioc_inode->table)do { do { do { if (0) printf ("locked table(%p)", ioc_inode->
table); } while (0); _gf_log (ioc_inode->table->xl->
name, "io-cache.c", __FUNCTION__, 135, GF_LOG_TRACE, "locked table(%p)"
, ioc_inode->table); } while (0); pthread_mutex_lock (&
ioc_inode->table->table_lock); } while (0)
;
136 {
137 ioc_inode->table->cache_used -= destroy_size;
138 }
139 ioc_table_unlock (ioc_inode->table)do { do { do { if (0) printf ("unlocked table(%p)", ioc_inode
->table); } while (0); _gf_log (ioc_inode->table->xl
->name, "io-cache.c", __FUNCTION__, 139, GF_LOG_TRACE, "unlocked table(%p)"
, ioc_inode->table); } while (0); pthread_mutex_unlock (&
ioc_inode->table->table_lock); } while (0)
;
140 }
141
142 return;
143}
144
145int32_t
146ioc_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
147 int32_t op_ret, int32_t op_errno,
148 struct iatt *preop, struct iatt *postop, dict_t *xdata)
149{
150 STACK_UNWIND_STRICT (setattr, frame, op_ret, op_errno, preop, postop,do { fop_setattr_cbk_t fn = ((void*)0); call_frame_t *_parent
= ((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) {
do { do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 151, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_setattr_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, preop, postop, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
151 xdata)do { fop_setattr_cbk_t fn = ((void*)0); call_frame_t *_parent
= ((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) {
do { do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 151, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_setattr_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, preop, postop, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
152 return 0;
153}
154
155int32_t
156ioc_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
157 struct iatt *stbuf, int32_t valid, dict_t *xdata)
158{
159 uint64_t ioc_inode = 0;
160
161 inode_ctx_get (loc->inode, this, &ioc_inode)inode_ctx_get2(loc->inode,this,&ioc_inode,0);
162
163 if (ioc_inode
164 && ((valid & GF_SET_ATTR_ATIME0x10)
165 || (valid & GF_SET_ATTR_MTIME0x20)))
166 ioc_inode_flush ((ioc_inode_t *)(long)ioc_inode);
167
168 STACK_WIND (frame, ioc_setattr_cbk, FIRST_CHILD (this),do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 169, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->setattr_cbk) tmp_cbk = ioc_setattr_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD (this)->fops->setattr"
; _new->unwind_to = "ioc_setattr_cbk"; pthread_spin_init (
&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->setattr); (this->children->xlator
)->fops->setattr (_new, (this->children->xlator),
loc, stbuf, valid, xdata); (*__glusterfs_this_location()) = old_THIS
; } while (0)
169 FIRST_CHILD (this)->fops->setattr, loc, stbuf, valid, xdata)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 169, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->setattr_cbk) tmp_cbk = ioc_setattr_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD (this)->fops->setattr"
; _new->unwind_to = "ioc_setattr_cbk"; pthread_spin_init (
&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->setattr); (this->children->xlator
)->fops->setattr (_new, (this->children->xlator),
loc, stbuf, valid, xdata); (*__glusterfs_this_location()) = old_THIS
; } while (0)
;
170
171 return 0;
172}
173
174int32_t
175ioc_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
176 int32_t op_ret, int32_t op_errno, inode_t *inode,
177 struct iatt *stbuf, dict_t *xdata, struct iatt *postparent)
178{
179 ioc_inode_t *ioc_inode = NULL((void*)0);
180 ioc_table_t *table = NULL((void*)0);
181 uint8_t cache_still_valid = 0;
182 uint64_t tmp_ioc_inode = 0;
183 uint32_t weight = 0xffffffff;
184 const char *path = NULL((void*)0);
185 ioc_local_t *local = NULL((void*)0);
186
187 if (op_ret != 0)
188 goto out;
189
190 local = frame->local;
191 if (local == NULL((void*)0)) {
192 op_ret = -1;
193 op_errno = EINVAL22;
194 goto out;
195 }
196
197 if (!this || !this->private) {
198 op_ret = -1;
199 op_errno = EINVAL22;
200 goto out;
201 }
202
203 table = this->private;
204
205 path = local->file_loc.path;
206
207 LOCK (&inode->lock)pthread_spin_lock (&inode->lock);
208 {
209 __inode_ctx_get (inode, this, &tmp_ioc_inode)__inode_ctx_get2(inode,this,&tmp_ioc_inode,0);
210 ioc_inode = (ioc_inode_t *)(long)tmp_ioc_inode;
211
212 if (!ioc_inode) {
213 weight = ioc_get_priority (table, path);
214
215 ioc_inode = ioc_inode_update (table, inode,
216 weight);
217
218 __inode_ctx_put (inode, this,
219 (uint64_t)(long)ioc_inode);
220 }
221 }
222 UNLOCK (&inode->lock)pthread_spin_unlock (&inode->lock);
223
224 ioc_inode_lock (ioc_inode)do { do { do { if (0) printf ("locked inode(%p)", ioc_inode);
} while (0); _gf_log (ioc_inode->table->xl->name, "io-cache.c"
, __FUNCTION__, 224, GF_LOG_TRACE, "locked inode(%p)", ioc_inode
); } while (0); pthread_mutex_lock (&ioc_inode->inode_lock
); } while (0)
;
225 {
226 if (ioc_inode->cache.mtime == 0) {
227 ioc_inode->cache.mtime = stbuf->ia_mtime;
228 ioc_inode->cache.mtime_nsec = stbuf->ia_mtime_nsec;
229 }
230
231 ioc_inode->ia_size = stbuf->ia_size;
232 }
233 ioc_inode_unlock (ioc_inode)do { do { do { if (0) printf ("unlocked inode(%p)", ioc_inode
); } while (0); _gf_log (ioc_inode->table->xl->name,
"io-cache.c", __FUNCTION__, 233, GF_LOG_TRACE, "unlocked inode(%p)"
, ioc_inode); } while (0); pthread_mutex_unlock (&ioc_inode
->inode_lock); } while (0)
;
234
235 cache_still_valid = ioc_cache_still_valid (ioc_inode,
236 stbuf);
237
238 if (!cache_still_valid) {
239 ioc_inode_flush (ioc_inode);
240 }
241
242 ioc_table_lock (ioc_inode->table)do { do { do { if (0) printf ("locked table(%p)", ioc_inode->
table); } while (0); _gf_log (ioc_inode->table->xl->
name, "io-cache.c", __FUNCTION__, 242, GF_LOG_TRACE, "locked table(%p)"
, ioc_inode->table); } while (0); pthread_mutex_lock (&
ioc_inode->table->table_lock); } while (0)
;
243 {
244 list_move_tail (&ioc_inode->inode_lru,
245 &table->inode_lru[ioc_inode->weight]);
246 }
247 ioc_table_unlock (ioc_inode->table)do { do { do { if (0) printf ("unlocked table(%p)", ioc_inode
->table); } while (0); _gf_log (ioc_inode->table->xl
->name, "io-cache.c", __FUNCTION__, 247, GF_LOG_TRACE, "unlocked table(%p)"
, ioc_inode->table); } while (0); pthread_mutex_unlock (&
ioc_inode->table->table_lock); } while (0)
;
248
249out:
250 if (frame->local != NULL((void*)0)) {
251 local = frame->local;
252 loc_wipe (&local->file_loc);
253 }
254
255 STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, stbuf,do { fop_lookup_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 256, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_lookup_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, inode, stbuf, xdata, postparent); (*__glusterfs_this_location
()) = old_THIS; } while (0)
256 xdata, postparent)do { fop_lookup_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 256, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_lookup_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, inode, stbuf, xdata, postparent); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
257 return 0;
258}
259
260int32_t
261ioc_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc,
262 dict_t *xdata)
263{
264 ioc_local_t *local = NULL((void*)0);
265 int32_t op_errno = -1, ret = -1;
266
267 local = mem_get0 (this->local_pool);
268 if (local == NULL((void*)0)) {
269 op_errno = ENOMEM12;
270 gf_log (this->name, GF_LOG_ERROR, "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(this->name, "io-cache.c", __FUNCTION__, 270, GF_LOG_ERROR
, "out of memory"); } while (0)
;
271 goto unwind;
272 }
273
274 ret = loc_copy (&local->file_loc, loc);
275 if (ret != 0) {
276 op_errno = ENOMEM12;
277 gf_log (this->name, GF_LOG_ERROR, "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(this->name, "io-cache.c", __FUNCTION__, 277, GF_LOG_ERROR
, "out of memory"); } while (0)
;
278 goto unwind;
279 }
280
281 frame->local = local;
282
283 STACK_WIND (frame, ioc_lookup_cbk, FIRST_CHILD (this),do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 284, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->lookup_cbk) tmp_cbk = ioc_lookup_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD (this)->fops->lookup"
; _new->unwind_to = "ioc_lookup_cbk"; pthread_spin_init (&
_new->lock, 0); pthread_spin_lock (&frame->root->
stack_lock); { _new->next = frame->root->frames.next
; _new->prev = &frame->root->frames; if (frame->
root->frames.next) frame->root->frames.next->prev
= _new; frame->root->frames.next = _new; frame->ref_count
++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->lookup); (this->children->xlator
)->fops->lookup (_new, (this->children->xlator), loc
, xdata); (*__glusterfs_this_location()) = old_THIS; } while (
0)
284 FIRST_CHILD (this)->fops->lookup, loc, xdata)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 284, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->lookup_cbk) tmp_cbk = ioc_lookup_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD (this)->fops->lookup"
; _new->unwind_to = "ioc_lookup_cbk"; pthread_spin_init (&
_new->lock, 0); pthread_spin_lock (&frame->root->
stack_lock); { _new->next = frame->root->frames.next
; _new->prev = &frame->root->frames; if (frame->
root->frames.next) frame->root->frames.next->prev
= _new; frame->root->frames.next = _new; frame->ref_count
++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->lookup); (this->children->xlator
)->fops->lookup (_new, (this->children->xlator), loc
, xdata); (*__glusterfs_this_location()) = old_THIS; } while (
0)
;
285
286 return 0;
287
288unwind:
289 STACK_UNWIND_STRICT (lookup, frame, -1, op_errno, NULL, NULL,do { fop_lookup_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 290, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_lookup_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, -1
, op_errno, ((void*)0), ((void*)0), ((void*)0), ((void*)0)); (
*__glusterfs_this_location()) = old_THIS; } while (0)
290 NULL, NULL)do { fop_lookup_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 290, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_lookup_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, -1
, op_errno, ((void*)0), ((void*)0), ((void*)0), ((void*)0)); (
*__glusterfs_this_location()) = old_THIS; } while (0)
;
291
292 return 0;
293}
294
295/*
296 * ioc_forget -
297 *
298 * @frame:
299 * @this:
300 * @inode:
301 *
302 */
303int32_t
304ioc_forget (xlator_t *this, inode_t *inode)
305{
306 uint64_t ioc_inode = 0;
307
308 inode_ctx_get (inode, this, &ioc_inode)inode_ctx_get2(inode,this,&ioc_inode,0);
309
310 if (ioc_inode)
311 ioc_inode_destroy ((ioc_inode_t *)(long)ioc_inode);
312
313 return 0;
314}
315
316static int32_t
317ioc_invalidate(xlator_t *this, inode_t *inode)
318{
319 ioc_inode_t *ioc_inode = NULL((void*)0);
320
321 inode_ctx_get(inode, this, (uint64_t *) &ioc_inode)inode_ctx_get2(inode,this,(uint64_t *) &ioc_inode,0);
322
323 if (ioc_inode)
324 ioc_inode_flush(ioc_inode);
325
326 return 0;
327}
328
329/*
330 * ioc_cache_validate_cbk -
331 *
332 * @frame:
333 * @cookie:
334 * @this:
335 * @op_ret:
336 * @op_errno:
337 * @buf
338 *
339 */
340int32_t
341ioc_cache_validate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
342 int32_t op_ret, int32_t op_errno, struct iatt *stbuf,
343 dict_t *xdata)
344{
345 ioc_local_t *local = NULL((void*)0);
346 ioc_inode_t *ioc_inode = NULL((void*)0);
347 size_t destroy_size = 0;
348 struct iatt *local_stbuf = NULL((void*)0);
349
350 local = frame->local;
351 ioc_inode = local->inode;
352 local_stbuf = stbuf;
353
354 if ((op_ret == -1) ||
355 ((op_ret >= 0) && !ioc_cache_still_valid(ioc_inode, stbuf))) {
356 gf_log (ioc_inode->table->xl->name, GF_LOG_DEBUG,do { do { if (0) printf ("cache for inode(%p) is invalid. flushing all pages"
, ioc_inode); } while (0); _gf_log (ioc_inode->table->xl
->name, "io-cache.c", __FUNCTION__, 358, GF_LOG_DEBUG, "cache for inode(%p) is invalid. flushing all pages"
, ioc_inode); } while (0)
357 "cache for inode(%p) is invalid. flushing all pages",do { do { if (0) printf ("cache for inode(%p) is invalid. flushing all pages"
, ioc_inode); } while (0); _gf_log (ioc_inode->table->xl
->name, "io-cache.c", __FUNCTION__, 358, GF_LOG_DEBUG, "cache for inode(%p) is invalid. flushing all pages"
, ioc_inode); } while (0)
358 ioc_inode)do { do { if (0) printf ("cache for inode(%p) is invalid. flushing all pages"
, ioc_inode); } while (0); _gf_log (ioc_inode->table->xl
->name, "io-cache.c", __FUNCTION__, 358, GF_LOG_DEBUG, "cache for inode(%p) is invalid. flushing all pages"
, ioc_inode); } while (0)
;
359 /* NOTE: only pages with no waiting frames are flushed by
360 * ioc_inode_flush. page_fault will be generated for all
361 * the pages which have waiting frames by ioc_inode_wakeup()
362 */
363 ioc_inode_lock (ioc_inode)do { do { do { if (0) printf ("locked inode(%p)", ioc_inode);
} while (0); _gf_log (ioc_inode->table->xl->name, "io-cache.c"
, __FUNCTION__, 363, GF_LOG_TRACE, "locked inode(%p)", ioc_inode
); } while (0); pthread_mutex_lock (&ioc_inode->inode_lock
); } while (0)
;
364 {
365 destroy_size = __ioc_inode_flush (ioc_inode);
366 if (op_ret >= 0) {
367 ioc_inode->cache.mtime = stbuf->ia_mtime;
368 ioc_inode->cache.mtime_nsec
369 = stbuf->ia_mtime_nsec;
370 }
371 }
372 ioc_inode_unlock (ioc_inode)do { do { do { if (0) printf ("unlocked inode(%p)", ioc_inode
); } while (0); _gf_log (ioc_inode->table->xl->name,
"io-cache.c", __FUNCTION__, 372, GF_LOG_TRACE, "unlocked inode(%p)"
, ioc_inode); } while (0); pthread_mutex_unlock (&ioc_inode
->inode_lock); } while (0)
;
373 local_stbuf = NULL((void*)0);
374 }
375
376 if (destroy_size) {
377 ioc_table_lock (ioc_inode->table)do { do { do { if (0) printf ("locked table(%p)", ioc_inode->
table); } while (0); _gf_log (ioc_inode->table->xl->
name, "io-cache.c", __FUNCTION__, 377, GF_LOG_TRACE, "locked table(%p)"
, ioc_inode->table); } while (0); pthread_mutex_lock (&
ioc_inode->table->table_lock); } while (0)
;
378 {
379 ioc_inode->table->cache_used -= destroy_size;
380 }
381 ioc_table_unlock (ioc_inode->table)do { do { do { if (0) printf ("unlocked table(%p)", ioc_inode
->table); } while (0); _gf_log (ioc_inode->table->xl
->name, "io-cache.c", __FUNCTION__, 381, GF_LOG_TRACE, "unlocked table(%p)"
, ioc_inode->table); } while (0); pthread_mutex_unlock (&
ioc_inode->table->table_lock); } while (0)
;
382 }
383
384 if (op_ret < 0)
385 local_stbuf = NULL((void*)0);
386
387 ioc_inode_lock (ioc_inode)do { do { do { if (0) printf ("locked inode(%p)", ioc_inode);
} while (0); _gf_log (ioc_inode->table->xl->name, "io-cache.c"
, __FUNCTION__, 387, GF_LOG_TRACE, "locked inode(%p)", ioc_inode
); } while (0); pthread_mutex_lock (&ioc_inode->inode_lock
); } while (0)
;
388 {
389 gettimeofday (&ioc_inode->cache.tv, NULL((void*)0));
390 }
391 ioc_inode_unlock (ioc_inode)do { do { do { if (0) printf ("unlocked inode(%p)", ioc_inode
); } while (0); _gf_log (ioc_inode->table->xl->name,
"io-cache.c", __FUNCTION__, 391, GF_LOG_TRACE, "unlocked inode(%p)"
, ioc_inode); } while (0); pthread_mutex_unlock (&ioc_inode
->inode_lock); } while (0)
;
392
393 ioc_inode_wakeup (frame, ioc_inode, local_stbuf);
394
395 /* any page-fault initiated by ioc_inode_wakeup() will have its own
396 * fd_ref on fd, safe to unref validate frame's private copy
397 */
398 fd_unref (local->fd);
399
400 STACK_DESTROY (frame->root);
401
402 return 0;
403}
404
405int32_t
406ioc_wait_on_inode (ioc_inode_t *ioc_inode, ioc_page_t *page)
407{
408 ioc_waitq_t *waiter = NULL((void*)0), *trav = NULL((void*)0);
409 uint32_t page_found = 0;
410 int32_t ret = 0;
411
412 trav = ioc_inode->waitq;
413
414 while (trav) {
415 if (trav->data == page) {
416 page_found = 1;
417 break;
418 }
419 trav = trav->next;
420 }
421
422 if (!page_found) {
423 waiter = GF_CALLOC (1, sizeof (ioc_waitq_t),__gf_calloc (1, sizeof (ioc_waitq_t), gf_ioc_mt_ioc_waitq_t)
424 gf_ioc_mt_ioc_waitq_t)__gf_calloc (1, sizeof (ioc_waitq_t), gf_ioc_mt_ioc_waitq_t);
425 if (waiter == NULL((void*)0)) {
426 gf_log (ioc_inode->table->xl->name, GF_LOG_ERROR,do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(ioc_inode->table->xl->name, "io-cache.c", __FUNCTION__
, 427, GF_LOG_ERROR, "out of memory"); } while (0)
427 "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(ioc_inode->table->xl->name, "io-cache.c", __FUNCTION__
, 427, GF_LOG_ERROR, "out of memory"); } while (0)
;
428 ret = -ENOMEM12;
429 goto out;
430 }
431
432 waiter->data = page;
433 waiter->next = ioc_inode->waitq;
434 ioc_inode->waitq = waiter;
435 }
436
437out:
438 return ret;
439}
440
441/*
442 * ioc_cache_validate -
443 *
444 * @frame:
445 * @ioc_inode:
446 * @fd:
447 *
448 */
449int32_t
450ioc_cache_validate (call_frame_t *frame, ioc_inode_t *ioc_inode, fd_t *fd,
451 ioc_page_t *page)
452{
453 call_frame_t *validate_frame = NULL((void*)0);
454 ioc_local_t *validate_local = NULL((void*)0);
455 ioc_local_t *local = NULL((void*)0);
456 int32_t ret = 0;
457
458 local = frame->local;
459 validate_local = mem_get0 (THIS(*__glusterfs_this_location())->local_pool);
460 if (validate_local == NULL((void*)0)) {
461 ret = -1;
462 local->op_ret = -1;
463 local->op_errno = ENOMEM12;
464 gf_log (ioc_inode->table->xl->name, GF_LOG_ERROR,do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(ioc_inode->table->xl->name, "io-cache.c", __FUNCTION__
, 465, GF_LOG_ERROR, "out of memory"); } while (0)
465 "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(ioc_inode->table->xl->name, "io-cache.c", __FUNCTION__
, 465, GF_LOG_ERROR, "out of memory"); } while (0)
;
466 goto out;
467 }
468
469 validate_frame = copy_frame (frame);
470 if (validate_frame == NULL((void*)0)) {
471 ret = -1;
472 local->op_ret = -1;
473 local->op_errno = ENOMEM12;
474 mem_put (validate_local);
475 gf_log (ioc_inode->table->xl->name, GF_LOG_ERROR,do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(ioc_inode->table->xl->name, "io-cache.c", __FUNCTION__
, 476, GF_LOG_ERROR, "out of memory"); } while (0)
476 "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(ioc_inode->table->xl->name, "io-cache.c", __FUNCTION__
, 476, GF_LOG_ERROR, "out of memory"); } while (0)
;
477 goto out;
478 }
479
480 validate_local->fd = fd_ref (fd);
481 validate_local->inode = ioc_inode;
482 validate_frame->local = validate_local;
483
484 STACK_WIND (validate_frame, ioc_cache_validate_cbk,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (validate_frame->root->pool->
frame_mem_pool); if (!_new) { do { do { if (0) printf ("alloc failed"
); } while (0); _gf_log ("stack", "io-cache.c", __FUNCTION__,
486, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( (frame->this->children->xlator)->fops->fstat_cbk
) tmp_cbk = ioc_cache_validate_cbk; _new->root = validate_frame
->root; _new->this = (frame->this->children->xlator
); _new->ret = (ret_fn_t) tmp_cbk; _new->parent = validate_frame
; _new->cookie = _new; _new->wind_from = __FUNCTION__; _new
->wind_to = "FIRST_CHILD (frame->this)->fops->fstat"
; _new->unwind_to = "ioc_cache_validate_cbk"; pthread_spin_init
(&_new->lock, 0); pthread_spin_lock (&validate_frame
->root->stack_lock); { _new->next = validate_frame->
root->frames.next; _new->prev = &validate_frame->
root->frames; if (validate_frame->root->frames.next)
validate_frame->root->frames.next->prev = _new; validate_frame
->root->frames.next = _new; validate_frame->ref_count
++; } pthread_spin_unlock (&validate_frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (frame->this->children->xlator); if (validate_frame
->this->ctx->measure_latency) gf_latency_begin (_new
, (frame->this->children->xlator)->fops->fstat
); (frame->this->children->xlator)->fops->fstat
(_new, (frame->this->children->xlator), fd, ((void*
)0)); (*__glusterfs_this_location()) = old_THIS; } while (0)
485 FIRST_CHILD (frame->this),do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (validate_frame->root->pool->
frame_mem_pool); if (!_new) { do { do { if (0) printf ("alloc failed"
); } while (0); _gf_log ("stack", "io-cache.c", __FUNCTION__,
486, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( (frame->this->children->xlator)->fops->fstat_cbk
) tmp_cbk = ioc_cache_validate_cbk; _new->root = validate_frame
->root; _new->this = (frame->this->children->xlator
); _new->ret = (ret_fn_t) tmp_cbk; _new->parent = validate_frame
; _new->cookie = _new; _new->wind_from = __FUNCTION__; _new
->wind_to = "FIRST_CHILD (frame->this)->fops->fstat"
; _new->unwind_to = "ioc_cache_validate_cbk"; pthread_spin_init
(&_new->lock, 0); pthread_spin_lock (&validate_frame
->root->stack_lock); { _new->next = validate_frame->
root->frames.next; _new->prev = &validate_frame->
root->frames; if (validate_frame->root->frames.next)
validate_frame->root->frames.next->prev = _new; validate_frame
->root->frames.next = _new; validate_frame->ref_count
++; } pthread_spin_unlock (&validate_frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (frame->this->children->xlator); if (validate_frame
->this->ctx->measure_latency) gf_latency_begin (_new
, (frame->this->children->xlator)->fops->fstat
); (frame->this->children->xlator)->fops->fstat
(_new, (frame->this->children->xlator), fd, ((void*
)0)); (*__glusterfs_this_location()) = old_THIS; } while (0)
486 FIRST_CHILD (frame->this)->fops->fstat, fd, NULL)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (validate_frame->root->pool->
frame_mem_pool); if (!_new) { do { do { if (0) printf ("alloc failed"
); } while (0); _gf_log ("stack", "io-cache.c", __FUNCTION__,
486, GF_LOG_ERROR, "alloc failed"); } while (0); break; } typeof
( (frame->this->children->xlator)->fops->fstat_cbk
) tmp_cbk = ioc_cache_validate_cbk; _new->root = validate_frame
->root; _new->this = (frame->this->children->xlator
); _new->ret = (ret_fn_t) tmp_cbk; _new->parent = validate_frame
; _new->cookie = _new; _new->wind_from = __FUNCTION__; _new
->wind_to = "FIRST_CHILD (frame->this)->fops->fstat"
; _new->unwind_to = "ioc_cache_validate_cbk"; pthread_spin_init
(&_new->lock, 0); pthread_spin_lock (&validate_frame
->root->stack_lock); { _new->next = validate_frame->
root->frames.next; _new->prev = &validate_frame->
root->frames; if (validate_frame->root->frames.next)
validate_frame->root->frames.next->prev = _new; validate_frame
->root->frames.next = _new; validate_frame->ref_count
++; } pthread_spin_unlock (&validate_frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (frame->this->children->xlator); if (validate_frame
->this->ctx->measure_latency) gf_latency_begin (_new
, (frame->this->children->xlator)->fops->fstat
); (frame->this->children->xlator)->fops->fstat
(_new, (frame->this->children->xlator), fd, ((void*
)0)); (*__glusterfs_this_location()) = old_THIS; } while (0)
;
487
488out:
489 return ret;
490}
491
492static inline uint32_t
493is_match (const char *path, const char *pattern)
494{
495 int32_t ret = 0;
496
497 ret = fnmatch (pattern, path, FNM_NOESCAPE(1 << 1));
498
499 return (ret == 0);
500}
501
502uint32_t
503ioc_get_priority (ioc_table_t *table, const char *path)
504{
505 uint32_t priority = 1;
506 struct ioc_priority *curr = NULL((void*)0);
507
508 if (list_empty(&table->priority_list))
509 return priority;
510
511 priority = 0;
512 list_for_each_entry (curr, &table->priority_list, list)for (curr = ((typeof(*curr) *)((char *)((&table->priority_list
)->next)-(unsigned long)(&((typeof(*curr) *)0)->list
))); &curr->list != (&table->priority_list); curr
= ((typeof(*curr) *)((char *)(curr->list.next)-(unsigned long
)(&((typeof(*curr) *)0)->list))))
{
513 if (is_match (path, curr->pattern))
514 priority = curr->priority;
515 }
516
517 return priority;
518}
519
520/*
521 * ioc_open_cbk - open callback for io cache
522 *
523 * @frame: call frame
524 * @cookie:
525 * @this:
526 * @op_ret:
527 * @op_errno:
528 * @fd:
529 *
530 */
531int32_t
532ioc_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
533 int32_t op_errno, fd_t *fd, dict_t *xdata)
534{
535 uint64_t tmp_ioc_inode = 0;
536 ioc_local_t *local = NULL((void*)0);
537 ioc_table_t *table = NULL((void*)0);
538 ioc_inode_t *ioc_inode = NULL((void*)0);
539 uint32_t weight = 0xffffffff;
540
541 local = frame->local;
542 if (!this || !this->private) {
543 op_ret = -1;
544 op_errno = EINVAL22;
545 goto out;
546 }
547
548 table = this->private;
549
550 if (op_ret != -1) {
551 inode_ctx_get (fd->inode, this, &tmp_ioc_inode)inode_ctx_get2(fd->inode,this,&tmp_ioc_inode,0);
552 ioc_inode = (ioc_inode_t *)(long)tmp_ioc_inode;
553
554 //TODO: see why inode context is NULL and handle it.
555 if (!ioc_inode) {
556 gf_log (this->name, GF_LOG_ERROR, "inode context is "do { do { if (0) printf ("inode context is " "NULL (%s)", uuid_utoa
(fd->inode->gfid)); } while (0); _gf_log (this->name
, "io-cache.c", __FUNCTION__, 557, GF_LOG_ERROR, "inode context is "
"NULL (%s)", uuid_utoa (fd->inode->gfid)); } while (0)
557 "NULL (%s)", uuid_utoa (fd->inode->gfid))do { do { if (0) printf ("inode context is " "NULL (%s)", uuid_utoa
(fd->inode->gfid)); } while (0); _gf_log (this->name
, "io-cache.c", __FUNCTION__, 557, GF_LOG_ERROR, "inode context is "
"NULL (%s)", uuid_utoa (fd->inode->gfid)); } while (0)
;
558 goto out;
559 }
560
561 ioc_table_lock (ioc_inode->table)do { do { do { if (0) printf ("locked table(%p)", ioc_inode->
table); } while (0); _gf_log (ioc_inode->table->xl->
name, "io-cache.c", __FUNCTION__, 561, GF_LOG_TRACE, "locked table(%p)"
, ioc_inode->table); } while (0); pthread_mutex_lock (&
ioc_inode->table->table_lock); } while (0)
;
562 {
563 list_move_tail (&ioc_inode->inode_lru,
564 &table->inode_lru[ioc_inode->weight]);
565 }
566 ioc_table_unlock (ioc_inode->table)do { do { do { if (0) printf ("unlocked table(%p)", ioc_inode
->table); } while (0); _gf_log (ioc_inode->table->xl
->name, "io-cache.c", __FUNCTION__, 566, GF_LOG_TRACE, "unlocked table(%p)"
, ioc_inode->table); } while (0); pthread_mutex_unlock (&
ioc_inode->table->table_lock); } while (0)
;
567
568 ioc_inode_lock (ioc_inode)do { do { do { if (0) printf ("locked inode(%p)", ioc_inode);
} while (0); _gf_log (ioc_inode->table->xl->name, "io-cache.c"
, __FUNCTION__, 568, GF_LOG_TRACE, "locked inode(%p)", ioc_inode
); } while (0); pthread_mutex_lock (&ioc_inode->inode_lock
); } while (0)
;
569 {
570 if ((table->min_file_size > ioc_inode->ia_size)
571 || ((table->max_file_size > 0)
572 && (table->max_file_size < ioc_inode->ia_size))) {
573 fd_ctx_set (fd, this, 1);
574 }
575 }
576 ioc_inode_unlock (ioc_inode)do { do { do { if (0) printf ("unlocked inode(%p)", ioc_inode
); } while (0); _gf_log (ioc_inode->table->xl->name,
"io-cache.c", __FUNCTION__, 576, GF_LOG_TRACE, "unlocked inode(%p)"
, ioc_inode); } while (0); pthread_mutex_unlock (&ioc_inode
->inode_lock); } while (0)
;
577
578 /* If O_DIRECT open, we disable caching on it */
579 if ((local->flags & O_DIRECT040000)){
580 /* O_DIRECT is only for one fd, not the inode
581 * as a whole
582 */
583 fd_ctx_set (fd, this, 1);
584 }
585
586 /* weight = 0, we disable caching on it */
587 if (weight == 0) {
588 /* we allow a pattern-matched cache disable this way
589 */
590 fd_ctx_set (fd, this, 1);
591 }
592 }
593
594out:
595 mem_put (local);
596 frame->local = NULL((void*)0);
597
598 STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd, xdata)do { fop_open_cbk_t fn = ((void*)0); call_frame_t *_parent = (
(void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do {
do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 598, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_open_cbk_t )frame->ret; _parent
= frame->parent; pthread_spin_lock (&frame->root->
stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, fd, xdata); (*__glusterfs_this_location()) = old_THIS
; } while (0)
;
599
600 return 0;
601}
602
603/*
604 * ioc_create_cbk - create callback for io cache
605 *
606 * @frame: call frame
607 * @cookie:
608 * @this:
609 * @op_ret:
610 * @op_errno:
611 * @fd:
612 * @inode:
613 * @buf:
614 *
615 */
616int32_t
617ioc_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
618 int32_t op_ret, int32_t op_errno, fd_t *fd,
619 inode_t *inode, struct iatt *buf, struct iatt *preparent,
620 struct iatt *postparent, dict_t *xdata)
621{
622 ioc_local_t *local = NULL((void*)0);
623 ioc_table_t *table = NULL((void*)0);
624 ioc_inode_t *ioc_inode = NULL((void*)0);
625 uint32_t weight = 0xffffffff;
626 const char *path = NULL((void*)0);
627 int ret = -1;
628
629 local = frame->local;
630 if (!this || !this->private) {
631 op_ret = -1;
632 op_errno = EINVAL22;
633 goto out;
634 }
635
636 table = this->private;
637 path = local->file_loc.path;
638
639 if (op_ret != -1) {
640 /* assign weight */
641 weight = ioc_get_priority (table, path);
642
643 ioc_inode = ioc_inode_update (table, inode, weight);
644
645 ioc_inode_lock (ioc_inode)do { do { do { if (0) printf ("locked inode(%p)", ioc_inode);
} while (0); _gf_log (ioc_inode->table->xl->name, "io-cache.c"
, __FUNCTION__, 645, GF_LOG_TRACE, "locked inode(%p)", ioc_inode
); } while (0); pthread_mutex_lock (&ioc_inode->inode_lock
); } while (0)
;
646 {
647 ioc_inode->cache.mtime = buf->ia_mtime;
648 ioc_inode->cache.mtime_nsec = buf->ia_mtime_nsec;
649 ioc_inode->ia_size = buf->ia_size;
650
651 if ((table->min_file_size > ioc_inode->ia_size)
652 || ((table->max_file_size > 0)
653 && (table->max_file_size < ioc_inode->ia_size))) {
654 ret = fd_ctx_set (fd, this, 1);
655 if (ret)
656 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("%s: failed to set fd ctx", local->
file_loc.path); } while (0); _gf_log (this->name, "io-cache.c"
, __FUNCTION__, 658, GF_LOG_WARNING, "%s: failed to set fd ctx"
, local->file_loc.path); } while (0)
657 "%s: failed to set fd ctx",do { do { if (0) printf ("%s: failed to set fd ctx", local->
file_loc.path); } while (0); _gf_log (this->name, "io-cache.c"
, __FUNCTION__, 658, GF_LOG_WARNING, "%s: failed to set fd ctx"
, local->file_loc.path); } while (0)
658 local->file_loc.path)do { do { if (0) printf ("%s: failed to set fd ctx", local->
file_loc.path); } while (0); _gf_log (this->name, "io-cache.c"
, __FUNCTION__, 658, GF_LOG_WARNING, "%s: failed to set fd ctx"
, local->file_loc.path); } while (0)
;
659 }
660 }
661 ioc_inode_unlock (ioc_inode)do { do { do { if (0) printf ("unlocked inode(%p)", ioc_inode
); } while (0); _gf_log (ioc_inode->table->xl->name,
"io-cache.c", __FUNCTION__, 661, GF_LOG_TRACE, "unlocked inode(%p)"
, ioc_inode); } while (0); pthread_mutex_unlock (&ioc_inode
->inode_lock); } while (0)
;
662
663 inode_ctx_put (fd->inode, this,
664 (uint64_t)(long)ioc_inode);
665
666 /* If O_DIRECT open, we disable caching on it */
667 if (local->flags & O_DIRECT040000) {
668 /*
669 * O_DIRECT is only for one fd, not the inode
670 * as a whole */
671 ret = fd_ctx_set (fd, this, 1);
672 if (ret)
673 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("%s: failed to set fd ctx", local->
file_loc.path); } while (0); _gf_log (this->name, "io-cache.c"
, __FUNCTION__, 675, GF_LOG_WARNING, "%s: failed to set fd ctx"
, local->file_loc.path); } while (0)
674 "%s: failed to set fd ctx",do { do { if (0) printf ("%s: failed to set fd ctx", local->
file_loc.path); } while (0); _gf_log (this->name, "io-cache.c"
, __FUNCTION__, 675, GF_LOG_WARNING, "%s: failed to set fd ctx"
, local->file_loc.path); } while (0)
675 local->file_loc.path)do { do { if (0) printf ("%s: failed to set fd ctx", local->
file_loc.path); } while (0); _gf_log (this->name, "io-cache.c"
, __FUNCTION__, 675, GF_LOG_WARNING, "%s: failed to set fd ctx"
, local->file_loc.path); } while (0)
;
676 }
677
678 /* if weight == 0, we disable caching on it */
679 if (!weight) {
680 /* we allow a pattern-matched cache disable this way */
681 ret = fd_ctx_set (fd, this, 1);
682 if (ret)
683 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("%s: failed to set fd ctx", local->
file_loc.path); } while (0); _gf_log (this->name, "io-cache.c"
, __FUNCTION__, 685, GF_LOG_WARNING, "%s: failed to set fd ctx"
, local->file_loc.path); } while (0)
684 "%s: failed to set fd ctx",do { do { if (0) printf ("%s: failed to set fd ctx", local->
file_loc.path); } while (0); _gf_log (this->name, "io-cache.c"
, __FUNCTION__, 685, GF_LOG_WARNING, "%s: failed to set fd ctx"
, local->file_loc.path); } while (0)
685 local->file_loc.path)do { do { if (0) printf ("%s: failed to set fd ctx", local->
file_loc.path); } while (0); _gf_log (this->name, "io-cache.c"
, __FUNCTION__, 685, GF_LOG_WARNING, "%s: failed to set fd ctx"
, local->file_loc.path); } while (0)
;
686 }
687
688 }
689
690out:
691 frame->local = NULL((void*)0);
692 mem_put (local);
693
694 STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd, inode, buf,do { fop_create_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 695, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_create_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, fd, inode, buf, preparent, postparent, xdata); (*
__glusterfs_this_location()) = old_THIS; } while (0)
695 preparent, postparent, xdata)do { fop_create_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 695, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_create_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, fd, inode, buf, preparent, postparent, xdata); (*
__glusterfs_this_location()) = old_THIS; } while (0)
;
696
697 return 0;
698}
699
700
701int32_t
702ioc_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
703 int32_t op_ret, int32_t op_errno, inode_t *inode,
704 struct iatt *buf, struct iatt *preparent,
705 struct iatt *postparent, dict_t *xdata)
706{
707 ioc_local_t *local = NULL((void*)0);
708 ioc_table_t *table = NULL((void*)0);
709 ioc_inode_t *ioc_inode = NULL((void*)0);
710 uint32_t weight = 0xffffffff;
711 const char *path = NULL((void*)0);
712
713 local = frame->local;
714 if (!this || !this->private) {
715 op_ret = -1;
716 op_errno = EINVAL22;
717 goto out;
718 }
719
720 table = this->private;
721 path = local->file_loc.path;
722
723 if (op_ret != -1) {
724 /* assign weight */
725 weight = ioc_get_priority (table, path);
726
727 ioc_inode = ioc_inode_update (table, inode, weight);
728
729 ioc_inode_lock (ioc_inode)do { do { do { if (0) printf ("locked inode(%p)", ioc_inode);
} while (0); _gf_log (ioc_inode->table->xl->name, "io-cache.c"
, __FUNCTION__, 729, GF_LOG_TRACE, "locked inode(%p)", ioc_inode
); } while (0); pthread_mutex_lock (&ioc_inode->inode_lock
); } while (0)
;
730 {
731 ioc_inode->cache.mtime = buf->ia_mtime;
732 ioc_inode->cache.mtime_nsec = buf->ia_mtime_nsec;
733 ioc_inode->ia_size = buf->ia_size;
734 }
735 ioc_inode_unlock (ioc_inode)do { do { do { if (0) printf ("unlocked inode(%p)", ioc_inode
); } while (0); _gf_log (ioc_inode->table->xl->name,
"io-cache.c", __FUNCTION__, 735, GF_LOG_TRACE, "unlocked inode(%p)"
, ioc_inode); } while (0); pthread_mutex_unlock (&ioc_inode
->inode_lock); } while (0)
;
736
737 inode_ctx_put (inode, this,
738 (uint64_t)(long)ioc_inode);
739 }
740
741out:
742 frame->local = NULL((void*)0);
743
744 loc_wipe (&local->file_loc);
745 mem_put (local);
746
747 STACK_UNWIND_STRICT (mknod, frame, op_ret, op_errno, inode, buf,do { fop_mknod_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 748, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_mknod_cbk_t )frame->ret;
_parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, inode, buf, preparent, postparent, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
748 preparent, postparent, xdata)do { fop_mknod_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 748, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_mknod_cbk_t )frame->ret;
_parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, inode, buf, preparent, postparent, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
749 return 0;
750}
751
752
753int
754ioc_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
755 dev_t rdev, mode_t umask, dict_t *xdata)
756{
757 ioc_local_t *local = NULL((void*)0);
758 int32_t op_errno = -1, ret = -1;
759
760 local = mem_get0 (this->local_pool);
761 if (local == NULL((void*)0)) {
762 op_errno = ENOMEM12;
763 gf_log (this->name, GF_LOG_ERROR, "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(this->name, "io-cache.c", __FUNCTION__, 763, GF_LOG_ERROR
, "out of memory"); } while (0)
;
764 goto unwind;
765 }
766
767 ret = loc_copy (&local->file_loc, loc);
768 if (ret != 0) {
769 op_errno = ENOMEM12;
770 gf_log (this->name, GF_LOG_ERROR, "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(this->name, "io-cache.c", __FUNCTION__, 770, GF_LOG_ERROR
, "out of memory"); } while (0)
;
771 goto unwind;
772 }
773
774 frame->local = local;
775
776 STACK_WIND (frame, ioc_mknod_cbk,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 779, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->mknod_cbk) tmp_cbk = ioc_mknod_cbk;
_new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->mknod"; _new
->unwind_to = "ioc_mknod_cbk"; pthread_spin_init (&_new
->lock, 0); pthread_spin_lock (&frame->root->stack_lock
); { _new->next = frame->root->frames.next; _new->
prev = &frame->root->frames; if (frame->root->
frames.next) frame->root->frames.next->prev = _new; frame
->root->frames.next = _new; frame->ref_count++; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = (this->children->
xlator); if (frame->this->ctx->measure_latency) gf_latency_begin
(_new, (this->children->xlator)->fops->mknod); (
this->children->xlator)->fops->mknod (_new, (this
->children->xlator), loc, mode, rdev, umask, xdata); (*
__glusterfs_this_location()) = old_THIS; } while (0)
777 FIRST_CHILD(this),do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 779, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->mknod_cbk) tmp_cbk = ioc_mknod_cbk;
_new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->mknod"; _new
->unwind_to = "ioc_mknod_cbk"; pthread_spin_init (&_new
->lock, 0); pthread_spin_lock (&frame->root->stack_lock
); { _new->next = frame->root->frames.next; _new->
prev = &frame->root->frames; if (frame->root->
frames.next) frame->root->frames.next->prev = _new; frame
->root->frames.next = _new; frame->ref_count++; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = (this->children->
xlator); if (frame->this->ctx->measure_latency) gf_latency_begin
(_new, (this->children->xlator)->fops->mknod); (
this->children->xlator)->fops->mknod (_new, (this
->children->xlator), loc, mode, rdev, umask, xdata); (*
__glusterfs_this_location()) = old_THIS; } while (0)
778 FIRST_CHILD(this)->fops->mknod,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 779, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->mknod_cbk) tmp_cbk = ioc_mknod_cbk;
_new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->mknod"; _new
->unwind_to = "ioc_mknod_cbk"; pthread_spin_init (&_new
->lock, 0); pthread_spin_lock (&frame->root->stack_lock
); { _new->next = frame->root->frames.next; _new->
prev = &frame->root->frames; if (frame->root->
frames.next) frame->root->frames.next->prev = _new; frame
->root->frames.next = _new; frame->ref_count++; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = (this->children->
xlator); if (frame->this->ctx->measure_latency) gf_latency_begin
(_new, (this->children->xlator)->fops->mknod); (
this->children->xlator)->fops->mknod (_new, (this
->children->xlator), loc, mode, rdev, umask, xdata); (*
__glusterfs_this_location()) = old_THIS; } while (0)
779 loc, mode, rdev, umask, xdata)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 779, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->mknod_cbk) tmp_cbk = ioc_mknod_cbk;
_new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->mknod"; _new
->unwind_to = "ioc_mknod_cbk"; pthread_spin_init (&_new
->lock, 0); pthread_spin_lock (&frame->root->stack_lock
); { _new->next = frame->root->frames.next; _new->
prev = &frame->root->frames; if (frame->root->
frames.next) frame->root->frames.next->prev = _new; frame
->root->frames.next = _new; frame->ref_count++; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = (this->children->
xlator); if (frame->this->ctx->measure_latency) gf_latency_begin
(_new, (this->children->xlator)->fops->mknod); (
this->children->xlator)->fops->mknod (_new, (this
->children->xlator), loc, mode, rdev, umask, xdata); (*
__glusterfs_this_location()) = old_THIS; } while (0)
;
780 return 0;
781
782unwind:
783 if (local != NULL((void*)0)) {
784 loc_wipe (&local->file_loc);
785 mem_put (local);
786 }
787
788 STACK_UNWIND_STRICT (mknod, frame, -1, op_errno, NULL, NULL,do { fop_mknod_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 789, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_mknod_cbk_t )frame->ret;
_parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, -1
, op_errno, ((void*)0), ((void*)0), ((void*)0), ((void*)0), (
(void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
789 NULL, NULL, NULL)do { fop_mknod_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 789, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_mknod_cbk_t )frame->ret;
_parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, -1
, op_errno, ((void*)0), ((void*)0), ((void*)0), ((void*)0), (
(void*)0)); (*__glusterfs_this_location()) = old_THIS; } while
(0)
;
790
791 return 0;
792}
793
794
795/*
796 * ioc_open - open fop for io cache
797 * @frame:
798 * @this:
799 * @loc:
800 * @flags:
801 *
802 */
803int32_t
804ioc_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
805 fd_t *fd, dict_t *xdata)
806{
807
808 ioc_local_t *local = NULL((void*)0);
809
810 local = mem_get0 (this->local_pool);
811 if (local == NULL((void*)0)) {
812 gf_log (this->name, GF_LOG_ERROR, "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(this->name, "io-cache.c", __FUNCTION__, 812, GF_LOG_ERROR
, "out of memory"); } while (0)
;
813 STACK_UNWIND_STRICT (open, frame, -1, ENOMEM, NULL, NULL)do { fop_open_cbk_t fn = ((void*)0); call_frame_t *_parent = (
(void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do {
do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 813, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_open_cbk_t )frame->ret; _parent
= frame->parent; pthread_spin_lock (&frame->root->
stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, -1
, 12, ((void*)0), ((void*)0)); (*__glusterfs_this_location())
= old_THIS; } while (0)
;
814 return 0;
815 }
816
817 local->flags = flags;
818 local->file_loc.path = loc->path;
819 local->file_loc.inode = loc->inode;
820
821 frame->local = local;
822
823 STACK_WIND (frame, ioc_open_cbk, FIRST_CHILD(this),do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 825, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->open_cbk) tmp_cbk = ioc_open_cbk; _new
->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->open"; _new
->unwind_to = "ioc_open_cbk"; pthread_spin_init (&_new
->lock, 0); pthread_spin_lock (&frame->root->stack_lock
); { _new->next = frame->root->frames.next; _new->
prev = &frame->root->frames; if (frame->root->
frames.next) frame->root->frames.next->prev = _new; frame
->root->frames.next = _new; frame->ref_count++; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = (this->children->
xlator); if (frame->this->ctx->measure_latency) gf_latency_begin
(_new, (this->children->xlator)->fops->open); (this
->children->xlator)->fops->open (_new, (this->
children->xlator), loc, flags, fd, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
824 FIRST_CHILD(this)->fops->open, loc, flags, fd,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 825, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->open_cbk) tmp_cbk = ioc_open_cbk; _new
->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->open"; _new
->unwind_to = "ioc_open_cbk"; pthread_spin_init (&_new
->lock, 0); pthread_spin_lock (&frame->root->stack_lock
); { _new->next = frame->root->frames.next; _new->
prev = &frame->root->frames; if (frame->root->
frames.next) frame->root->frames.next->prev = _new; frame
->root->frames.next = _new; frame->ref_count++; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = (this->children->
xlator); if (frame->this->ctx->measure_latency) gf_latency_begin
(_new, (this->children->xlator)->fops->open); (this
->children->xlator)->fops->open (_new, (this->
children->xlator), loc, flags, fd, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
825 xdata)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 825, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->open_cbk) tmp_cbk = ioc_open_cbk; _new
->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->open"; _new
->unwind_to = "ioc_open_cbk"; pthread_spin_init (&_new
->lock, 0); pthread_spin_lock (&frame->root->stack_lock
); { _new->next = frame->root->frames.next; _new->
prev = &frame->root->frames; if (frame->root->
frames.next) frame->root->frames.next->prev = _new; frame
->root->frames.next = _new; frame->ref_count++; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = (this->children->
xlator); if (frame->this->ctx->measure_latency) gf_latency_begin
(_new, (this->children->xlator)->fops->open); (this
->children->xlator)->fops->open (_new, (this->
children->xlator), loc, flags, fd, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
826
827 return 0;
828}
829
830/*
831 * ioc_create - create fop for io cache
832 *
833 * @frame:
834 * @this:
835 * @pathname:
836 * @flags:
837 * @mode:
838 *
839 */
840int32_t
841ioc_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
842 mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata)
843{
844 ioc_local_t *local = NULL((void*)0);
845
846 local = mem_get0 (this->local_pool);
847 if (local == NULL((void*)0)) {
848 gf_log (this->name, GF_LOG_ERROR, "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(this->name, "io-cache.c", __FUNCTION__, 848, GF_LOG_ERROR
, "out of memory"); } while (0)
;
849 STACK_UNWIND_STRICT (create, frame, -1, ENOMEM, NULL, NULL,do { fop_create_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 850, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_create_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, -1
, 12, ((void*)0), ((void*)0), ((void*)0), ((void*)0), ((void*
)0), ((void*)0)); (*__glusterfs_this_location()) = old_THIS; }
while (0)
850 NULL, NULL, NULL, NULL)do { fop_create_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 850, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_create_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, -1
, 12, ((void*)0), ((void*)0), ((void*)0), ((void*)0), ((void*
)0), ((void*)0)); (*__glusterfs_this_location()) = old_THIS; }
while (0)
;
851 return 0;
852 }
853
854 local->flags = flags;
855 local->file_loc.path = loc->path;
856 frame->local = local;
857
858 STACK_WIND (frame, ioc_create_cbk, FIRST_CHILD(this),do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 860, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->create_cbk) tmp_cbk = ioc_create_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->create";
_new->unwind_to = "ioc_create_cbk"; pthread_spin_init (&
_new->lock, 0); pthread_spin_lock (&frame->root->
stack_lock); { _new->next = frame->root->frames.next
; _new->prev = &frame->root->frames; if (frame->
root->frames.next) frame->root->frames.next->prev
= _new; frame->root->frames.next = _new; frame->ref_count
++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->create); (this->children->xlator
)->fops->create (_new, (this->children->xlator), loc
, flags, mode, umask, fd, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
859 FIRST_CHILD(this)->fops->create, loc, flags, mode,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 860, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->create_cbk) tmp_cbk = ioc_create_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->create";
_new->unwind_to = "ioc_create_cbk"; pthread_spin_init (&
_new->lock, 0); pthread_spin_lock (&frame->root->
stack_lock); { _new->next = frame->root->frames.next
; _new->prev = &frame->root->frames; if (frame->
root->frames.next) frame->root->frames.next->prev
= _new; frame->root->frames.next = _new; frame->ref_count
++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->create); (this->children->xlator
)->fops->create (_new, (this->children->xlator), loc
, flags, mode, umask, fd, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
860 umask, fd, xdata)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 860, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->create_cbk) tmp_cbk = ioc_create_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->create";
_new->unwind_to = "ioc_create_cbk"; pthread_spin_init (&
_new->lock, 0); pthread_spin_lock (&frame->root->
stack_lock); { _new->next = frame->root->frames.next
; _new->prev = &frame->root->frames; if (frame->
root->frames.next) frame->root->frames.next->prev
= _new; frame->root->frames.next = _new; frame->ref_count
++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->create); (this->children->xlator
)->fops->create (_new, (this->children->xlator), loc
, flags, mode, umask, fd, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
861
862 return 0;
863}
864
865
866
867
868/*
869 * ioc_release - release fop for io cache
870 *
871 * @frame:
872 * @this:
873 * @fd:
874 *
875 */
876int32_t
877ioc_release (xlator_t *this, fd_t *fd)
878{
879 return 0;
880}
881
882/*
883 * ioc_readv_disabled_cbk
884 * @frame:
885 * @cookie:
886 * @this:
887 * @op_ret:
888 * @op_errno:
889 * @vector:
890 * @count:
891 *
892 */
893int32_t
894ioc_readv_disabled_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
895 int32_t op_ret, int32_t op_errno, struct iovec *vector,
896 int32_t count, struct iatt *stbuf,
897 struct iobref *iobref, dict_t *xdata)
898{
899 STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, vector, count,do { fop_readv_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 900, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_readv_cbk_t )frame->ret;
_parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, vector, count, stbuf, iobref, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
900 stbuf, iobref, xdata)do { fop_readv_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 900, GF_LOG_CRITICAL, "!frame")
; } while (0); break; } fn = (fop_readv_cbk_t )frame->ret;
_parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, vector, count, stbuf, iobref, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
901 return 0;
902}
903
904
905int32_t
906ioc_need_prune (ioc_table_t *table)
907{
908 int64_t cache_difference = 0;
909
910 ioc_table_lock (table)do { do { do { if (0) printf ("locked table(%p)", table); } while
(0); _gf_log (table->xl->name, "io-cache.c", __FUNCTION__
, 910, GF_LOG_TRACE, "locked table(%p)", table); } while (0);
pthread_mutex_lock (&table->table_lock); } while (0)
;
911 {
912 cache_difference = table->cache_used - table->cache_size;
913 }
914 ioc_table_unlock (table)do { do { do { if (0) printf ("unlocked table(%p)", table); }
while (0); _gf_log (table->xl->name, "io-cache.c", __FUNCTION__
, 914, GF_LOG_TRACE, "unlocked table(%p)", table); } while (0
); pthread_mutex_unlock (&table->table_lock); } while (
0)
;
915
916 if (cache_difference > 0)
917 return 1;
918 else
919 return 0;
920}
921
922/*
923 * ioc_dispatch_requests -
924 *
925 * @frame:
926 * @inode:
927 *
928 *
929 */
930void
931ioc_dispatch_requests (call_frame_t *frame, ioc_inode_t *ioc_inode, fd_t *fd,
932 off_t offset, size_t size)
933{
934 ioc_local_t *local = NULL((void*)0);
935 ioc_table_t *table = NULL((void*)0);
936 ioc_page_t *trav = NULL((void*)0);
937 ioc_waitq_t *waitq = NULL((void*)0);
938 off_t rounded_offset = 0;
939 off_t rounded_end = 0;
940 off_t trav_offset = 0;
941 int32_t fault = 0;
942 size_t trav_size = 0;
943 off_t local_offset = 0;
944 int32_t ret = -1;
945 int8_t need_validate = 0;
946 int8_t might_need_validate = 0; /*
947 * if a page exists, do we need
948 * to validate it?
949 */
950 local = frame->local;
951 table = ioc_inode->table;
952
953 rounded_offset = floor (offset, table->page_size)(((offset)/((table->page_size)?(table->page_size):1))*(
table->page_size))
;
954 rounded_end = roof (offset + size, table->page_size)((((offset + size)+(table->page_size)-1)/((table->page_size
)?(table->page_size):1))*(table->page_size))
;
955 trav_offset = rounded_offset;
956
957 /* once a frame does read, it should be waiting on something */
958 local->wait_count++;
959
960 /* Requested region can fall in three different pages,
961 * 1. Ready - region is already in cache, we just have to serve it.
962 * 2. In-transit - page fault has been generated on this page, we need
963 * to wait till the page is ready
964 * 3. Fault - page is not in cache, we have to generate a page fault
965 */
966
967 might_need_validate = ioc_inode_need_revalidate (ioc_inode);
968
969 while (trav_offset < rounded_end) {
970 ioc_inode_lock (ioc_inode)do { do { do { if (0) printf ("locked inode(%p)", ioc_inode);
} while (0); _gf_log (ioc_inode->table->xl->name, "io-cache.c"
, __FUNCTION__, 970, GF_LOG_TRACE, "locked inode(%p)", ioc_inode
); } while (0); pthread_mutex_lock (&ioc_inode->inode_lock
); } while (0)
;
971 {
972 /* look for requested region in the cache */
973 trav = __ioc_page_get (ioc_inode, trav_offset);
974
975 local_offset = max (trav_offset, offset)((trav_offset)>(offset)?(trav_offset):(offset));
976 trav_size = min (((offset+size) - local_offset),((((offset+size) - local_offset))<(table->page_size)?((
(offset+size) - local_offset)):(table->page_size))
977 table->page_size)((((offset+size) - local_offset))<(table->page_size)?((
(offset+size) - local_offset)):(table->page_size))
;
978
979 if (!trav) {
980 /* page not in cache, we need to generate page
981 * fault
982 */
983 trav = __ioc_page_create (ioc_inode,
984 trav_offset);
985 fault = 1;
986 if (!trav) {
987 gf_log (frame->this->name,do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(frame->this->name, "io-cache.c", __FUNCTION__, 989, GF_LOG_CRITICAL
, "out of memory"); } while (0)
988 GF_LOG_CRITICAL,do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(frame->this->name, "io-cache.c", __FUNCTION__, 989, GF_LOG_CRITICAL
, "out of memory"); } while (0)
989 "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(frame->this->name, "io-cache.c", __FUNCTION__, 989, GF_LOG_CRITICAL
, "out of memory"); } while (0)
;
990 local->op_ret = -1;
991 local->op_errno = ENOMEM12;
992 goto out;
993 }
994 }
995
996 __ioc_wait_on_page (trav, frame, local_offset,
997 trav_size);
998
999 if (trav->ready) {
1000 /* page found in cache */
1001 if (!might_need_validate && !ioc_inode->waitq) {
1002 /* fresh enough */
1003 gf_log (frame->this->name, GF_LOG_TRACE,do { do { if (0) printf ("cache hit for trav_offset=%" "ll" "d"
"/local_offset=%""ll" "d""", trav_offset, local_offset); } while
(0); _gf_log (frame->this->name, "io-cache.c", __FUNCTION__
, 1006, GF_LOG_TRACE, "cache hit for trav_offset=%" "ll" "d""/local_offset=%"
"ll" "d""", trav_offset, local_offset); } while (0)
1004 "cache hit for trav_offset=%"do { do { if (0) printf ("cache hit for trav_offset=%" "ll" "d"
"/local_offset=%""ll" "d""", trav_offset, local_offset); } while
(0); _gf_log (frame->this->name, "io-cache.c", __FUNCTION__
, 1006, GF_LOG_TRACE, "cache hit for trav_offset=%" "ll" "d""/local_offset=%"
"ll" "d""", trav_offset, local_offset); } while (0)
1005 PRId64"/local_offset=%"PRId64"",do { do { if (0) printf ("cache hit for trav_offset=%" "ll" "d"
"/local_offset=%""ll" "d""", trav_offset, local_offset); } while
(0); _gf_log (frame->this->name, "io-cache.c", __FUNCTION__
, 1006, GF_LOG_TRACE, "cache hit for trav_offset=%" "ll" "d""/local_offset=%"
"ll" "d""", trav_offset, local_offset); } while (0)
1006 trav_offset, local_offset)do { do { if (0) printf ("cache hit for trav_offset=%" "ll" "d"
"/local_offset=%""ll" "d""", trav_offset, local_offset); } while
(0); _gf_log (frame->this->name, "io-cache.c", __FUNCTION__
, 1006, GF_LOG_TRACE, "cache hit for trav_offset=%" "ll" "d""/local_offset=%"
"ll" "d""", trav_offset, local_offset); } while (0)
;
1007 waitq = __ioc_page_wakeup (trav,
1008 trav->op_errno);
1009 } else {
1010 /* if waitq already exists, fstat
1011 * revalidate is
1012 * already on the way
1013 */
1014 if (!ioc_inode->waitq) {
1015 need_validate = 1;
1016 }
1017
1018 ret = ioc_wait_on_inode (ioc_inode,
1019 trav);
1020 if (ret < 0) {
1021 local->op_ret = -1;
1022 local->op_errno = -ret;
1023 need_validate = 0;
Value stored to 'need_validate' is never read
1024
1025 waitq = __ioc_page_wakeup (trav,
1026 trav->op_errno);
1027 ioc_inode_unlock (ioc_inode)do { do { do { if (0) printf ("unlocked inode(%p)", ioc_inode
); } while (0); _gf_log (ioc_inode->table->xl->name,
"io-cache.c", __FUNCTION__, 1027, GF_LOG_TRACE, "unlocked inode(%p)"
, ioc_inode); } while (0); pthread_mutex_unlock (&ioc_inode
->inode_lock); } while (0)
;
1028
1029 ioc_waitq_return (waitq);
1030 waitq = NULL((void*)0);
1031 goto out;
1032 }
1033 }
1034 }
1035
1036 }
1037 ioc_inode_unlock (ioc_inode)do { do { do { if (0) printf ("unlocked inode(%p)", ioc_inode
); } while (0); _gf_log (ioc_inode->table->xl->name,
"io-cache.c", __FUNCTION__, 1037, GF_LOG_TRACE, "unlocked inode(%p)"
, ioc_inode); } while (0); pthread_mutex_unlock (&ioc_inode
->inode_lock); } while (0)
;
1038
1039 ioc_waitq_return (waitq);
1040 waitq = NULL((void*)0);
1041
1042 if (fault) {
1043 fault = 0;
1044 /* new page created, increase the table->cache_used */
1045 ioc_page_fault (ioc_inode, frame, fd, trav_offset);
1046 }
1047
1048 if (need_validate) {
1049 need_validate = 0;
1050 gf_log (frame->this->name, GF_LOG_TRACE,do { do { if (0) printf ("sending validate request for " "inode(%s) at offset=%"
"ll" "d""", uuid_utoa (fd->inode->gfid), trav_offset); }
while (0); _gf_log (frame->this->name, "io-cache.c", __FUNCTION__
, 1053, GF_LOG_TRACE, "sending validate request for " "inode(%s) at offset=%"
"ll" "d""", uuid_utoa (fd->inode->gfid), trav_offset); }
while (0)
1051 "sending validate request for "do { do { if (0) printf ("sending validate request for " "inode(%s) at offset=%"
"ll" "d""", uuid_utoa (fd->inode->gfid), trav_offset); }
while (0); _gf_log (frame->this->name, "io-cache.c", __FUNCTION__
, 1053, GF_LOG_TRACE, "sending validate request for " "inode(%s) at offset=%"
"ll" "d""", uuid_utoa (fd->inode->gfid), trav_offset); }
while (0)
1052 "inode(%s) at offset=%"PRId64"",do { do { if (0) printf ("sending validate request for " "inode(%s) at offset=%"
"ll" "d""", uuid_utoa (fd->inode->gfid), trav_offset); }
while (0); _gf_log (frame->this->name, "io-cache.c", __FUNCTION__
, 1053, GF_LOG_TRACE, "sending validate request for " "inode(%s) at offset=%"
"ll" "d""", uuid_utoa (fd->inode->gfid), trav_offset); }
while (0)
1053 uuid_utoa (fd->inode->gfid), trav_offset)do { do { if (0) printf ("sending validate request for " "inode(%s) at offset=%"
"ll" "d""", uuid_utoa (fd->inode->gfid), trav_offset); }
while (0); _gf_log (frame->this->name, "io-cache.c", __FUNCTION__
, 1053, GF_LOG_TRACE, "sending validate request for " "inode(%s) at offset=%"
"ll" "d""", uuid_utoa (fd->inode->gfid), trav_offset); }
while (0)
;
1054 ret = ioc_cache_validate (frame, ioc_inode, fd, trav);
1055 if (ret == -1) {
1056 ioc_inode_lock (ioc_inode)do { do { do { if (0) printf ("locked inode(%p)", ioc_inode);
} while (0); _gf_log (ioc_inode->table->xl->name, "io-cache.c"
, __FUNCTION__, 1056, GF_LOG_TRACE, "locked inode(%p)", ioc_inode
); } while (0); pthread_mutex_lock (&ioc_inode->inode_lock
); } while (0)
;
1057 {
1058 waitq = __ioc_page_wakeup (trav,
1059 trav->op_errno);
1060 }
1061 ioc_inode_unlock (ioc_inode)do { do { do { if (0) printf ("unlocked inode(%p)", ioc_inode
); } while (0); _gf_log (ioc_inode->table->xl->name,
"io-cache.c", __FUNCTION__, 1061, GF_LOG_TRACE, "unlocked inode(%p)"
, ioc_inode); } while (0); pthread_mutex_unlock (&ioc_inode
->inode_lock); } while (0)
;
1062
1063 ioc_waitq_return (waitq);
1064 waitq = NULL((void*)0);
1065 goto out;
1066 }
1067 }
1068
1069 trav_offset += table->page_size;
1070 }
1071
1072out:
1073 ioc_frame_return (frame);
1074
1075 if (ioc_need_prune (ioc_inode->table)) {
1076 ioc_prune (ioc_inode->table);
1077 }
1078
1079 return;
1080}
1081
1082
1083/*
1084 * ioc_readv -
1085 *
1086 * @frame:
1087 * @this:
1088 * @fd:
1089 * @size:
1090 * @offset:
1091 *
1092 */
1093int32_t
1094ioc_readv (call_frame_t *frame, xlator_t *this, fd_t *fd,
1095 size_t size, off_t offset, uint32_t flags, dict_t *xdata)
1096{
1097 uint64_t tmp_ioc_inode = 0;
1098 ioc_inode_t *ioc_inode = NULL((void*)0);
1099 ioc_local_t *local = NULL((void*)0);
1100 uint32_t weight = 0;
1101 ioc_table_t *table = NULL((void*)0);
1102 int32_t op_errno = -1;
1103
1104 if (!this) {
1105 goto out;
1106 }
1107
1108 inode_ctx_get (fd->inode, this, &tmp_ioc_inode)inode_ctx_get2(fd->inode,this,&tmp_ioc_inode,0);
1109 ioc_inode = (ioc_inode_t *)(long)tmp_ioc_inode;
1110 if (!ioc_inode) {
1111 /* caching disabled, go ahead with normal readv */
1112 STACK_WIND (frame, ioc_readv_disabled_cbk,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1115, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (frame->this
->children->xlator)->fops->readv_cbk) tmp_cbk = ioc_readv_disabled_cbk
; _new->root = frame->root; _new->this = (frame->
this->children->xlator); _new->ret = (ret_fn_t) tmp_cbk
; _new->parent = frame; _new->cookie = _new; _new->wind_from
= __FUNCTION__; _new->wind_to = "FIRST_CHILD (frame->this)->fops->readv"
; _new->unwind_to = "ioc_readv_disabled_cbk"; pthread_spin_init
(&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (frame->this->children->xlator); if (frame->
this->ctx->measure_latency) gf_latency_begin (_new, (frame
->this->children->xlator)->fops->readv); (frame
->this->children->xlator)->fops->readv (_new, (
frame->this->children->xlator), fd, size, offset, flags
, xdata); (*__glusterfs_this_location()) = old_THIS; } while (
0)
1113 FIRST_CHILD (frame->this),do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1115, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (frame->this
->children->xlator)->fops->readv_cbk) tmp_cbk = ioc_readv_disabled_cbk
; _new->root = frame->root; _new->this = (frame->
this->children->xlator); _new->ret = (ret_fn_t) tmp_cbk
; _new->parent = frame; _new->cookie = _new; _new->wind_from
= __FUNCTION__; _new->wind_to = "FIRST_CHILD (frame->this)->fops->readv"
; _new->unwind_to = "ioc_readv_disabled_cbk"; pthread_spin_init
(&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (frame->this->children->xlator); if (frame->
this->ctx->measure_latency) gf_latency_begin (_new, (frame
->this->children->xlator)->fops->readv); (frame
->this->children->xlator)->fops->readv (_new, (
frame->this->children->xlator), fd, size, offset, flags
, xdata); (*__glusterfs_this_location()) = old_THIS; } while (
0)
1114 FIRST_CHILD (frame->this)->fops->readv, fd, size,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1115, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (frame->this
->children->xlator)->fops->readv_cbk) tmp_cbk = ioc_readv_disabled_cbk
; _new->root = frame->root; _new->this = (frame->
this->children->xlator); _new->ret = (ret_fn_t) tmp_cbk
; _new->parent = frame; _new->cookie = _new; _new->wind_from
= __FUNCTION__; _new->wind_to = "FIRST_CHILD (frame->this)->fops->readv"
; _new->unwind_to = "ioc_readv_disabled_cbk"; pthread_spin_init
(&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (frame->this->children->xlator); if (frame->
this->ctx->measure_latency) gf_latency_begin (_new, (frame
->this->children->xlator)->fops->readv); (frame
->this->children->xlator)->fops->readv (_new, (
frame->this->children->xlator), fd, size, offset, flags
, xdata); (*__glusterfs_this_location()) = old_THIS; } while (
0)
1115 offset, flags, xdata)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1115, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (frame->this
->children->xlator)->fops->readv_cbk) tmp_cbk = ioc_readv_disabled_cbk
; _new->root = frame->root; _new->this = (frame->
this->children->xlator); _new->ret = (ret_fn_t) tmp_cbk
; _new->parent = frame; _new->cookie = _new; _new->wind_from
= __FUNCTION__; _new->wind_to = "FIRST_CHILD (frame->this)->fops->readv"
; _new->unwind_to = "ioc_readv_disabled_cbk"; pthread_spin_init
(&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (frame->this->children->xlator); if (frame->
this->ctx->measure_latency) gf_latency_begin (_new, (frame
->this->children->xlator)->fops->readv); (frame
->this->children->xlator)->fops->readv (_new, (
frame->this->children->xlator), fd, size, offset, flags
, xdata); (*__glusterfs_this_location()) = old_THIS; } while (
0)
;
1116 return 0;
1117 }
1118
1119
1120 table = this->private;
1121
1122 if (!table) {
1123 gf_log (this->name, GF_LOG_ERROR, "table is null")do { do { if (0) printf ("table is null"); } while (0); _gf_log
(this->name, "io-cache.c", __FUNCTION__, 1123, GF_LOG_ERROR
, "table is null"); } while (0)
;
1124 op_errno = EINVAL22;
1125 goto out;
1126 }
1127
1128 ioc_inode_lock (ioc_inode)do { do { do { if (0) printf ("locked inode(%p)", ioc_inode);
} while (0); _gf_log (ioc_inode->table->xl->name, "io-cache.c"
, __FUNCTION__, 1128, GF_LOG_TRACE, "locked inode(%p)", ioc_inode
); } while (0); pthread_mutex_lock (&ioc_inode->inode_lock
); } while (0)
;
1129 {
1130 if (!ioc_inode->cache.page_table) {
1131 ioc_inode->cache.page_table
1132 = rbthash_table_init
1133 (IOC_PAGE_TABLE_BUCKET_COUNT1,
1134 ioc_hashfn, NULL((void*)0), 0,
1135 table->mem_pool);
1136
1137 if (ioc_inode->cache.page_table == NULL((void*)0)) {
1138 op_errno = ENOMEM12;
1139 ioc_inode_unlock (ioc_inode)do { do { do { if (0) printf ("unlocked inode(%p)", ioc_inode
); } while (0); _gf_log (ioc_inode->table->xl->name,
"io-cache.c", __FUNCTION__, 1139, GF_LOG_TRACE, "unlocked inode(%p)"
, ioc_inode); } while (0); pthread_mutex_unlock (&ioc_inode
->inode_lock); } while (0)
;
1140 goto out;
1141 }
1142 }
1143 }
1144 ioc_inode_unlock (ioc_inode)do { do { do { if (0) printf ("unlocked inode(%p)", ioc_inode
); } while (0); _gf_log (ioc_inode->table->xl->name,
"io-cache.c", __FUNCTION__, 1144, GF_LOG_TRACE, "unlocked inode(%p)"
, ioc_inode); } while (0); pthread_mutex_unlock (&ioc_inode
->inode_lock); } while (0)
;
1145
1146 if (!fd_ctx_get (fd, this, NULL((void*)0))) {
1147 /* disable caching for this fd, go ahead with normal readv */
1148 STACK_WIND (frame, ioc_readv_disabled_cbk,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1151, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (frame->this
->children->xlator)->fops->readv_cbk) tmp_cbk = ioc_readv_disabled_cbk
; _new->root = frame->root; _new->this = (frame->
this->children->xlator); _new->ret = (ret_fn_t) tmp_cbk
; _new->parent = frame; _new->cookie = _new; _new->wind_from
= __FUNCTION__; _new->wind_to = "FIRST_CHILD (frame->this)->fops->readv"
; _new->unwind_to = "ioc_readv_disabled_cbk"; pthread_spin_init
(&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (frame->this->children->xlator); if (frame->
this->ctx->measure_latency) gf_latency_begin (_new, (frame
->this->children->xlator)->fops->readv); (frame
->this->children->xlator)->fops->readv (_new, (
frame->this->children->xlator), fd, size, offset, flags
, xdata); (*__glusterfs_this_location()) = old_THIS; } while (
0)
1149 FIRST_CHILD (frame->this),do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1151, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (frame->this
->children->xlator)->fops->readv_cbk) tmp_cbk = ioc_readv_disabled_cbk
; _new->root = frame->root; _new->this = (frame->
this->children->xlator); _new->ret = (ret_fn_t) tmp_cbk
; _new->parent = frame; _new->cookie = _new; _new->wind_from
= __FUNCTION__; _new->wind_to = "FIRST_CHILD (frame->this)->fops->readv"
; _new->unwind_to = "ioc_readv_disabled_cbk"; pthread_spin_init
(&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (frame->this->children->xlator); if (frame->
this->ctx->measure_latency) gf_latency_begin (_new, (frame
->this->children->xlator)->fops->readv); (frame
->this->children->xlator)->fops->readv (_new, (
frame->this->children->xlator), fd, size, offset, flags
, xdata); (*__glusterfs_this_location()) = old_THIS; } while (
0)
1150 FIRST_CHILD (frame->this)->fops->readv, fd, size,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1151, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (frame->this
->children->xlator)->fops->readv_cbk) tmp_cbk = ioc_readv_disabled_cbk
; _new->root = frame->root; _new->this = (frame->
this->children->xlator); _new->ret = (ret_fn_t) tmp_cbk
; _new->parent = frame; _new->cookie = _new; _new->wind_from
= __FUNCTION__; _new->wind_to = "FIRST_CHILD (frame->this)->fops->readv"
; _new->unwind_to = "ioc_readv_disabled_cbk"; pthread_spin_init
(&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (frame->this->children->xlator); if (frame->
this->ctx->measure_latency) gf_latency_begin (_new, (frame
->this->children->xlator)->fops->readv); (frame
->this->children->xlator)->fops->readv (_new, (
frame->this->children->xlator), fd, size, offset, flags
, xdata); (*__glusterfs_this_location()) = old_THIS; } while (
0)
1151 offset, flags, xdata)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1151, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (frame->this
->children->xlator)->fops->readv_cbk) tmp_cbk = ioc_readv_disabled_cbk
; _new->root = frame->root; _new->this = (frame->
this->children->xlator); _new->ret = (ret_fn_t) tmp_cbk
; _new->parent = frame; _new->cookie = _new; _new->wind_from
= __FUNCTION__; _new->wind_to = "FIRST_CHILD (frame->this)->fops->readv"
; _new->unwind_to = "ioc_readv_disabled_cbk"; pthread_spin_init
(&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (frame->this->children->xlator); if (frame->
this->ctx->measure_latency) gf_latency_begin (_new, (frame
->this->children->xlator)->fops->readv); (frame
->this->children->xlator)->fops->readv (_new, (
frame->this->children->xlator), fd, size, offset, flags
, xdata); (*__glusterfs_this_location()) = old_THIS; } while (
0)
;
1152 return 0;
1153 }
1154
1155 local = mem_get0 (this->local_pool);
1156 if (local == NULL((void*)0)) {
1157 gf_log (this->name, GF_LOG_ERROR, "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(this->name, "io-cache.c", __FUNCTION__, 1157, GF_LOG_ERROR
, "out of memory"); } while (0)
;
1158 op_errno = ENOMEM12;
1159 goto out;
1160 }
1161
1162 INIT_LIST_HEAD (&local->fill_list)do { (&local->fill_list)->next = (&local->fill_list
)->prev = &local->fill_list; } while (0)
;
1163
1164 frame->local = local;
1165 local->pending_offset = offset;
1166 local->pending_size = size;
1167 local->offset = offset;
1168 local->size = size;
1169 local->inode = ioc_inode;
1170
1171 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("NEW REQ (%p) offset = %""ll" "d"" && size = %"
"zu""", frame, offset, size); } while (0); _gf_log (this->
name, "io-cache.c", __FUNCTION__, 1173, GF_LOG_TRACE, "NEW REQ (%p) offset = %"
"ll" "d"" && size = %""zu""", frame, offset, size); }
while (0)
1172 "NEW REQ (%p) offset = %"PRId64" && size = %"GF_PRI_SIZET"",do { do { if (0) printf ("NEW REQ (%p) offset = %""ll" "d"" && size = %"
"zu""", frame, offset, size); } while (0); _gf_log (this->
name, "io-cache.c", __FUNCTION__, 1173, GF_LOG_TRACE, "NEW REQ (%p) offset = %"
"ll" "d"" && size = %""zu""", frame, offset, size); }
while (0)
1173 frame, offset, size)do { do { if (0) printf ("NEW REQ (%p) offset = %""ll" "d"" && size = %"
"zu""", frame, offset, size); } while (0); _gf_log (this->
name, "io-cache.c", __FUNCTION__, 1173, GF_LOG_TRACE, "NEW REQ (%p) offset = %"
"ll" "d"" && size = %""zu""", frame, offset, size); }
while (0)
;
1174
1175 weight = ioc_inode->weight;
1176
1177 ioc_table_lock (ioc_inode->table)do { do { do { if (0) printf ("locked table(%p)", ioc_inode->
table); } while (0); _gf_log (ioc_inode->table->xl->
name, "io-cache.c", __FUNCTION__, 1177, GF_LOG_TRACE, "locked table(%p)"
, ioc_inode->table); } while (0); pthread_mutex_lock (&
ioc_inode->table->table_lock); } while (0)
;
1178 {
1179 list_move_tail (&ioc_inode->inode_lru,
1180 &ioc_inode->table->inode_lru[weight]);
1181 }
1182 ioc_table_unlock (ioc_inode->table)do { do { do { if (0) printf ("unlocked table(%p)", ioc_inode
->table); } while (0); _gf_log (ioc_inode->table->xl
->name, "io-cache.c", __FUNCTION__, 1182, GF_LOG_TRACE, "unlocked table(%p)"
, ioc_inode->table); } while (0); pthread_mutex_unlock (&
ioc_inode->table->table_lock); } while (0)
;
1183
1184 ioc_dispatch_requests (frame, ioc_inode, fd, offset, size);
1185 return 0;
1186
1187out:
1188 STACK_UNWIND_STRICT (readv, frame, -1, op_errno, NULL, 0, NULL, NULL,do { fop_readv_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 1189, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_readv_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, -1
, op_errno, ((void*)0), 0, ((void*)0), ((void*)0), ((void*)0)
); (*__glusterfs_this_location()) = old_THIS; } while (0)
1189 NULL)do { fop_readv_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 1189, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_readv_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, -1
, op_errno, ((void*)0), 0, ((void*)0), ((void*)0), ((void*)0)
); (*__glusterfs_this_location()) = old_THIS; } while (0)
;
1190 return 0;
1191}
1192
1193/*
1194 * ioc_writev_cbk -
1195 *
1196 * @frame:
1197 * @cookie:
1198 * @this:
1199 * @op_ret:
1200 * @op_errno:
1201 *
1202 */
1203int32_t
1204ioc_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1205 int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
1206 struct iatt *postbuf, dict_t *xdata)
1207{
1208 ioc_local_t *local = NULL((void*)0);
1209 uint64_t ioc_inode = 0;
1210
1211 local = frame->local;
1212 inode_ctx_get (local->fd->inode, this, &ioc_inode)inode_ctx_get2(local->fd->inode,this,&ioc_inode,0);
1213
1214 if (ioc_inode)
1215 ioc_inode_flush ((ioc_inode_t *)(long)ioc_inode);
1216
1217 STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, postbuf,do { fop_writev_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 1218, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_writev_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, prebuf, postbuf, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
1218 xdata)do { fop_writev_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 1218, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_writev_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, prebuf, postbuf, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
1219 return 0;
1220}
1221
1222/*
1223 * ioc_writev
1224 *
1225 * @frame:
1226 * @this:
1227 * @fd:
1228 * @vector:
1229 * @count:
1230 * @offset:
1231 *
1232 */
1233int32_t
1234ioc_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
1235 struct iovec *vector, int32_t count, off_t offset,
1236 uint32_t flags, struct iobref *iobref, dict_t *xdata)
1237{
1238 ioc_local_t *local = NULL((void*)0);
1239 uint64_t ioc_inode = 0;
1240
1241 local = mem_get0 (this->local_pool);
1242 if (local == NULL((void*)0)) {
1243 gf_log (this->name, GF_LOG_ERROR, "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(this->name, "io-cache.c", __FUNCTION__, 1243, GF_LOG_ERROR
, "out of memory"); } while (0)
;
1244
1245 STACK_UNWIND_STRICT (writev, frame, -1, ENOMEM, NULL, NULL, NULL)do { fop_writev_cbk_t fn = ((void*)0); call_frame_t *_parent =
((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do
{ do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 1245, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_writev_cbk_t )frame->ret
; _parent = frame->parent; pthread_spin_lock (&frame->
root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, -1
, 12, ((void*)0), ((void*)0), ((void*)0)); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
1246 return 0;
1247 }
1248
1249 /* TODO: why is it not fd_ref'ed */
1250 local->fd = fd;
1251 frame->local = local;
1252
1253 inode_ctx_get (fd->inode, this, &ioc_inode)inode_ctx_get2(fd->inode,this,&ioc_inode,0);
1254 if (ioc_inode)
1255 ioc_inode_flush ((ioc_inode_t *)(long)ioc_inode);
1256
1257 STACK_WIND (frame, ioc_writev_cbk, FIRST_CHILD(this),do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1259, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->writev_cbk) tmp_cbk = ioc_writev_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->writev";
_new->unwind_to = "ioc_writev_cbk"; pthread_spin_init (&
_new->lock, 0); pthread_spin_lock (&frame->root->
stack_lock); { _new->next = frame->root->frames.next
; _new->prev = &frame->root->frames; if (frame->
root->frames.next) frame->root->frames.next->prev
= _new; frame->root->frames.next = _new; frame->ref_count
++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->writev); (this->children->xlator
)->fops->writev (_new, (this->children->xlator), fd
, vector, count, offset, flags, iobref, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
1258 FIRST_CHILD(this)->fops->writev, fd, vector, count, offset,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1259, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->writev_cbk) tmp_cbk = ioc_writev_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->writev";
_new->unwind_to = "ioc_writev_cbk"; pthread_spin_init (&
_new->lock, 0); pthread_spin_lock (&frame->root->
stack_lock); { _new->next = frame->root->frames.next
; _new->prev = &frame->root->frames; if (frame->
root->frames.next) frame->root->frames.next->prev
= _new; frame->root->frames.next = _new; frame->ref_count
++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->writev); (this->children->xlator
)->fops->writev (_new, (this->children->xlator), fd
, vector, count, offset, flags, iobref, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
1259 flags, iobref, xdata)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1259, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->writev_cbk) tmp_cbk = ioc_writev_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->writev";
_new->unwind_to = "ioc_writev_cbk"; pthread_spin_init (&
_new->lock, 0); pthread_spin_lock (&frame->root->
stack_lock); { _new->next = frame->root->frames.next
; _new->prev = &frame->root->frames; if (frame->
root->frames.next) frame->root->frames.next->prev
= _new; frame->root->frames.next = _new; frame->ref_count
++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->writev); (this->children->xlator
)->fops->writev (_new, (this->children->xlator), fd
, vector, count, offset, flags, iobref, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
1260
1261 return 0;
1262}
1263
1264/*
1265 * ioc_truncate_cbk -
1266 *
1267 * @frame:
1268 * @cookie:
1269 * @this:
1270 * @op_ret:
1271 * @op_errno:
1272 * @buf:
1273 *
1274 */
1275int32_t
1276ioc_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1277 int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
1278 struct iatt *postbuf, dict_t *xdata)
1279{
1280
1281 STACK_UNWIND_STRICT (truncate, frame, op_ret, op_errno, prebuf,do { fop_truncate_cbk_t fn = ((void*)0); call_frame_t *_parent
= ((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) {
do { do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 1282, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_truncate_cbk_t )frame->
ret; _parent = frame->parent; pthread_spin_lock (&frame
->root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, prebuf, postbuf, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
1282 postbuf, xdata)do { fop_truncate_cbk_t fn = ((void*)0); call_frame_t *_parent
= ((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) {
do { do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 1282, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_truncate_cbk_t )frame->
ret; _parent = frame->parent; pthread_spin_lock (&frame
->root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, prebuf, postbuf, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
1283 return 0;
1284}
1285
1286
1287/*
1288 * ioc_ftruncate_cbk -
1289 *
1290 * @frame:
1291 * @cookie:
1292 * @this:
1293 * @op_ret:
1294 * @op_errno:
1295 * @buf:
1296 *
1297 */
1298int32_t
1299ioc_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1300 int32_t op_ret, int32_t op_errno, struct iatt *prebuf,
1301 struct iatt *postbuf, dict_t *xdata)
1302{
1303
1304 STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, prebuf,do { fop_ftruncate_cbk_t fn = ((void*)0); call_frame_t *_parent
= ((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) {
do { do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 1305, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_ftruncate_cbk_t )frame->
ret; _parent = frame->parent; pthread_spin_lock (&frame
->root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, prebuf, postbuf, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
1305 postbuf, xdata)do { fop_ftruncate_cbk_t fn = ((void*)0); call_frame_t *_parent
= ((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) {
do { do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 1305, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_ftruncate_cbk_t )frame->
ret; _parent = frame->parent; pthread_spin_lock (&frame
->root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, prebuf, postbuf, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
1306 return 0;
1307}
1308
1309
1310/*
1311 * ioc_truncate -
1312 *
1313 * @frame:
1314 * @this:
1315 * @loc:
1316 * @offset:
1317 *
1318 */
1319int32_t
1320ioc_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset,
1321 dict_t *xdata)
1322{
1323 uint64_t ioc_inode = 0;
1324
1325 inode_ctx_get (loc->inode, this, &ioc_inode)inode_ctx_get2(loc->inode,this,&ioc_inode,0);
1326
1327 if (ioc_inode)
1328 ioc_inode_flush ((ioc_inode_t *)(long)ioc_inode);
1329
1330 STACK_WIND (frame, ioc_truncate_cbk, FIRST_CHILD(this),do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1331, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->truncate_cbk) tmp_cbk = ioc_truncate_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->truncate"
; _new->unwind_to = "ioc_truncate_cbk"; pthread_spin_init (
&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->truncate); (this->children->xlator
)->fops->truncate (_new, (this->children->xlator)
, loc, offset, xdata); (*__glusterfs_this_location()) = old_THIS
; } while (0)
1331 FIRST_CHILD(this)->fops->truncate, loc, offset, xdata)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1331, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->truncate_cbk) tmp_cbk = ioc_truncate_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->truncate"
; _new->unwind_to = "ioc_truncate_cbk"; pthread_spin_init (
&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->truncate); (this->children->xlator
)->fops->truncate (_new, (this->children->xlator)
, loc, offset, xdata); (*__glusterfs_this_location()) = old_THIS
; } while (0)
;
1332 return 0;
1333}
1334
1335/*
1336 * ioc_ftruncate -
1337 *
1338 * @frame:
1339 * @this:
1340 * @fd:
1341 * @offset:
1342 *
1343 */
1344int32_t
1345ioc_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
1346 dict_t *xdata)
1347{
1348 uint64_t ioc_inode = 0;
1349
1350 inode_ctx_get (fd->inode, this, &ioc_inode)inode_ctx_get2(fd->inode,this,&ioc_inode,0);
1351
1352 if (ioc_inode)
1353 ioc_inode_flush ((ioc_inode_t *)(long)ioc_inode);
1354
1355 STACK_WIND (frame, ioc_ftruncate_cbk, FIRST_CHILD(this),do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1356, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->ftruncate_cbk) tmp_cbk = ioc_ftruncate_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->ftruncate"
; _new->unwind_to = "ioc_ftruncate_cbk"; pthread_spin_init
(&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->ftruncate); (this->children->
xlator)->fops->ftruncate (_new, (this->children->
xlator), fd, offset, xdata); (*__glusterfs_this_location()) =
old_THIS; } while (0)
1356 FIRST_CHILD(this)->fops->ftruncate, fd, offset, xdata)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1356, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->ftruncate_cbk) tmp_cbk = ioc_ftruncate_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->ftruncate"
; _new->unwind_to = "ioc_ftruncate_cbk"; pthread_spin_init
(&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->ftruncate); (this->children->
xlator)->fops->ftruncate (_new, (this->children->
xlator), fd, offset, xdata); (*__glusterfs_this_location()) =
old_THIS; } while (0)
;
1357 return 0;
1358}
1359
1360int32_t
1361ioc_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
1362 int32_t op_errno, struct gf_flock *lock, dict_t *xdata)
1363{
1364 STACK_UNWIND_STRICT (lk, frame, op_ret, op_errno, lock, xdata)do { fop_lk_cbk_t fn = ((void*)0); call_frame_t *_parent = ((
void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do {
do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 1364, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_lk_cbk_t )frame->ret; _parent
= frame->parent; pthread_spin_lock (&frame->root->
stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, lock, xdata); (*__glusterfs_this_location()) = old_THIS
; } while (0)
;
1365 return 0;
1366}
1367
1368int32_t
1369ioc_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd,
1370 struct gf_flock *lock, dict_t *xdata)
1371{
1372 ioc_inode_t *ioc_inode = NULL((void*)0);
1373 uint64_t tmp_inode = 0;
1374
1375 inode_ctx_get (fd->inode, this, &tmp_inode)inode_ctx_get2(fd->inode,this,&tmp_inode,0);
1376 ioc_inode = (ioc_inode_t *)(long)tmp_inode;
1377 if (!ioc_inode) {
1378 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("inode context is NULL: returning EBADFD"
); } while (0); _gf_log (this->name, "io-cache.c", __FUNCTION__
, 1379, GF_LOG_DEBUG, "inode context is NULL: returning EBADFD"
); } while (0)
1379 "inode context is NULL: returning EBADFD")do { do { if (0) printf ("inode context is NULL: returning EBADFD"
); } while (0); _gf_log (this->name, "io-cache.c", __FUNCTION__
, 1379, GF_LOG_DEBUG, "inode context is NULL: returning EBADFD"
); } while (0)
;
1380 STACK_UNWIND_STRICT (lk, frame, -1, EBADFD, NULL, NULL)do { fop_lk_cbk_t fn = ((void*)0); call_frame_t *_parent = ((
void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) { do {
do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 1380, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_lk_cbk_t )frame->ret; _parent
= frame->parent; pthread_spin_lock (&frame->root->
stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, -1
, 77, ((void*)0), ((void*)0)); (*__glusterfs_this_location())
= old_THIS; } while (0)
;
1381 return 0;
1382 }
1383
1384 ioc_inode_lock (ioc_inode)do { do { do { if (0) printf ("locked inode(%p)", ioc_inode);
} while (0); _gf_log (ioc_inode->table->xl->name, "io-cache.c"
, __FUNCTION__, 1384, GF_LOG_TRACE, "locked inode(%p)", ioc_inode
); } while (0); pthread_mutex_lock (&ioc_inode->inode_lock
); } while (0)
;
1385 {
1386 gettimeofday (&ioc_inode->cache.tv, NULL((void*)0));
1387 }
1388 ioc_inode_unlock (ioc_inode)do { do { do { if (0) printf ("unlocked inode(%p)", ioc_inode
); } while (0); _gf_log (ioc_inode->table->xl->name,
"io-cache.c", __FUNCTION__, 1388, GF_LOG_TRACE, "unlocked inode(%p)"
, ioc_inode); } while (0); pthread_mutex_unlock (&ioc_inode
->inode_lock); } while (0)
;
1389
1390 STACK_WIND (frame, ioc_lk_cbk, FIRST_CHILD (this),do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1391, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->lk_cbk) tmp_cbk = ioc_lk_cbk; _new->
root = frame->root; _new->this = (this->children->
xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent =
frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD (this)->fops->lk"; _new
->unwind_to = "ioc_lk_cbk"; pthread_spin_init (&_new->
lock, 0); pthread_spin_lock (&frame->root->stack_lock
); { _new->next = frame->root->frames.next; _new->
prev = &frame->root->frames; if (frame->root->
frames.next) frame->root->frames.next->prev = _new; frame
->root->frames.next = _new; frame->ref_count++; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = (this->children->
xlator); if (frame->this->ctx->measure_latency) gf_latency_begin
(_new, (this->children->xlator)->fops->lk); (this
->children->xlator)->fops->lk (_new, (this->children
->xlator), fd, cmd, lock, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
1391 FIRST_CHILD (this)->fops->lk, fd, cmd, lock, xdata)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1391, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->lk_cbk) tmp_cbk = ioc_lk_cbk; _new->
root = frame->root; _new->this = (this->children->
xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent =
frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD (this)->fops->lk"; _new
->unwind_to = "ioc_lk_cbk"; pthread_spin_init (&_new->
lock, 0); pthread_spin_lock (&frame->root->stack_lock
); { _new->next = frame->root->frames.next; _new->
prev = &frame->root->frames; if (frame->root->
frames.next) frame->root->frames.next->prev = _new; frame
->root->frames.next = _new; frame->ref_count++; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = (this->children->
xlator); if (frame->this->ctx->measure_latency) gf_latency_begin
(_new, (this->children->xlator)->fops->lk); (this
->children->xlator)->fops->lk (_new, (this->children
->xlator), fd, cmd, lock, xdata); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
1392
1393 return 0;
1394}
1395
1396int
1397ioc_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1398 int op_ret, int op_errno, gf_dirent_t *entries, dict_t *xdata)
1399{
1400 gf_dirent_t *entry = NULL((void*)0);
1401
1402 if (op_ret <= 0)
1403 goto unwind;
1404
1405 list_for_each_entry (entry, &entries->list, list)for (entry = ((typeof(*entry) *)((char *)((&entries->list
)->next)-(unsigned long)(&((typeof(*entry) *)0)->list
))); &entry->list != (&entries->list); entry = (
(typeof(*entry) *)((char *)(entry->list.next)-(unsigned long
)(&((typeof(*entry) *)0)->list))))
{
1406 /* TODO: fill things */
1407 }
1408
1409unwind:
1410 STACK_UNWIND_STRICT (readdirp, frame, op_ret, op_errno, entries, xdata)do { fop_readdirp_cbk_t fn = ((void*)0); call_frame_t *_parent
= ((void*)0); xlator_t *old_THIS = ((void*)0); if (!frame) {
do { do { if (0) printf ("!frame"); } while (0); _gf_log ("stack"
, "io-cache.c", __FUNCTION__, 1410, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_readdirp_cbk_t )frame->
ret; _parent = frame->parent; pthread_spin_lock (&frame
->root->stack_lock); { _parent->ref_count--; } pthread_spin_unlock
(&frame->root->stack_lock); old_THIS = (*__glusterfs_this_location
()); (*__glusterfs_this_location()) = _parent->this; frame
->complete = _gf_true; frame->unwind_from = __FUNCTION__
; if (frame->this->ctx->measure_latency) gf_latency_end
(frame); fn (_parent, frame->cookie, _parent->this, op_ret
, op_errno, entries, xdata); (*__glusterfs_this_location()) =
old_THIS; } while (0)
;
1411
1412 return 0;
1413}
1414int
1415ioc_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
1416 off_t offset, dict_t *dict)
1417{
1418 STACK_WIND (frame, ioc_readdirp_cbk,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1420, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->readdirp_cbk) tmp_cbk = ioc_readdirp_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->readdirp"
; _new->unwind_to = "ioc_readdirp_cbk"; pthread_spin_init (
&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->readdirp); (this->children->xlator
)->fops->readdirp (_new, (this->children->xlator)
, fd, size, offset, dict); (*__glusterfs_this_location()) = old_THIS
; } while (0)
1419 FIRST_CHILD(this), FIRST_CHILD(this)->fops->readdirp,do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1420, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->readdirp_cbk) tmp_cbk = ioc_readdirp_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->readdirp"
; _new->unwind_to = "ioc_readdirp_cbk"; pthread_spin_init (
&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->readdirp); (this->children->xlator
)->fops->readdirp (_new, (this->children->xlator)
, fd, size, offset, dict); (*__glusterfs_this_location()) = old_THIS
; } while (0)
1420 fd, size, offset, dict)do { call_frame_t *_new = ((void*)0); xlator_t *old_THIS = ((
void*)0); _new = mem_get0 (frame->root->pool->frame_mem_pool
); if (!_new) { do { do { if (0) printf ("alloc failed"); } while
(0); _gf_log ("stack", "io-cache.c", __FUNCTION__, 1420, GF_LOG_ERROR
, "alloc failed"); } while (0); break; } typeof( (this->children
->xlator)->fops->readdirp_cbk) tmp_cbk = ioc_readdirp_cbk
; _new->root = frame->root; _new->this = (this->children
->xlator); _new->ret = (ret_fn_t) tmp_cbk; _new->parent
= frame; _new->cookie = _new; _new->wind_from = __FUNCTION__
; _new->wind_to = "FIRST_CHILD(this)->fops->readdirp"
; _new->unwind_to = "ioc_readdirp_cbk"; pthread_spin_init (
&_new->lock, 0); pthread_spin_lock (&frame->root
->stack_lock); { _new->next = frame->root->frames
.next; _new->prev = &frame->root->frames; if (frame
->root->frames.next) frame->root->frames.next->
prev = _new; frame->root->frames.next = _new; frame->
ref_count++; } pthread_spin_unlock (&frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = (this->children->xlator); if (frame->this->
ctx->measure_latency) gf_latency_begin (_new, (this->children
->xlator)->fops->readdirp); (this->children->xlator
)->fops->readdirp (_new, (this->children->xlator)
, fd, size, offset, dict); (*__glusterfs_this_location()) = old_THIS
; } while (0)
;
1421
1422 return 0;
1423}
1424
1425int32_t
1426ioc_get_priority_list (const char *opt_str, struct list_head *first)
1427{
1428 int32_t max_pri = 1;
1429 char *tmp_str = NULL((void*)0);
1430 char *tmp_str1 = NULL((void*)0);
1431 char *tmp_str2 = NULL((void*)0);
1432 char *dup_str = NULL((void*)0);
1433 char *stripe_str = NULL((void*)0);
1434 char *pattern = NULL((void*)0);
1435 char *priority = NULL((void*)0);
1436 char *string = NULL((void*)0);
1437 struct ioc_priority *curr = NULL((void*)0), *tmp = NULL((void*)0);
1438
1439 string = gf_strdup (opt_str);
1440 if (string == NULL((void*)0)) {
1441 max_pri = -1;
1442 goto out;
1443 }
1444
1445 /* Get the pattern for cache priority.
1446 * "option priority *.jpg:1,abc*:2" etc
1447 */
1448 /* TODO: inode_lru in table is statically hard-coded to 5,
1449 * should be changed to run-time configuration
1450 */
1451 stripe_str = strtok_r (string, ",", &tmp_str);
1452 while (stripe_str) {
1453 curr = GF_CALLOC (1, sizeof (struct ioc_priority),__gf_calloc (1, sizeof (struct ioc_priority), gf_ioc_mt_ioc_priority
)
1454 gf_ioc_mt_ioc_priority)__gf_calloc (1, sizeof (struct ioc_priority), gf_ioc_mt_ioc_priority
)
;
1455 if (curr == NULL((void*)0)) {
1456 max_pri = -1;
1457 goto out;
1458 }
1459
1460 list_add_tail (&curr->list, first);
1461
1462 dup_str = gf_strdup (stripe_str);
1463 if (dup_str == NULL((void*)0)) {
1464 max_pri = -1;
1465 goto out;
1466 }
1467
1468 pattern = strtok_r (dup_str, ":", &tmp_str1);
1469 if (!pattern) {
1470 max_pri = -1;
1471 goto out;
1472 }
1473
1474 priority = strtok_r (NULL((void*)0), ":", &tmp_str1);
1475 if (!priority) {
1476 max_pri = -1;
1477 goto out;
1478 }
1479
1480 gf_log ("io-cache", GF_LOG_TRACE,do { do { if (0) printf ("ioc priority : pattern %s : priority %s"
, pattern, priority); } while (0); _gf_log ("io-cache", "io-cache.c"
, __FUNCTION__, 1483, GF_LOG_TRACE, "ioc priority : pattern %s : priority %s"
, pattern, priority); } while (0)
1481 "ioc priority : pattern %s : priority %s",do { do { if (0) printf ("ioc priority : pattern %s : priority %s"
, pattern, priority); } while (0); _gf_log ("io-cache", "io-cache.c"
, __FUNCTION__, 1483, GF_LOG_TRACE, "ioc priority : pattern %s : priority %s"
, pattern, priority); } while (0)
1482 pattern,do { do { if (0) printf ("ioc priority : pattern %s : priority %s"
, pattern, priority); } while (0); _gf_log ("io-cache", "io-cache.c"
, __FUNCTION__, 1483, GF_LOG_TRACE, "ioc priority : pattern %s : priority %s"
, pattern, priority); } while (0)
1483 priority)do { do { if (0) printf ("ioc priority : pattern %s : priority %s"
, pattern, priority); } while (0); _gf_log ("io-cache", "io-cache.c"
, __FUNCTION__, 1483, GF_LOG_TRACE, "ioc priority : pattern %s : priority %s"
, pattern, priority); } while (0)
;
1484
1485 curr->pattern = gf_strdup (pattern);
1486 if (curr->pattern == NULL((void*)0)) {
1487 max_pri = -1;
1488 goto out;
1489 }
1490
1491 curr->priority = strtol (priority, &tmp_str2, 0);
1492 if (tmp_str2 && (*tmp_str2)) {
1493 max_pri = -1;
1494 goto out;
1495 } else {
1496 max_pri = max (max_pri, curr->priority)((max_pri)>(curr->priority)?(max_pri):(curr->priority
))
;
1497 }
1498
1499 GF_FREE (dup_str)__gf_free (dup_str);
1500 dup_str = NULL((void*)0);
1501
1502 stripe_str = strtok_r (NULL((void*)0), ",", &tmp_str);
1503 }
1504out:
1505 GF_FREE (string)__gf_free (string);
1506
1507 GF_FREE (dup_str)__gf_free (dup_str);
1508
1509 if (max_pri == -1) {
1510 list_for_each_entry_safe (curr, tmp, first, list)for (curr = ((typeof(*curr) *)((char *)((first)->next)-(unsigned
long)(&((typeof(*curr) *)0)->list))), tmp = ((typeof(
*curr) *)((char *)(curr->list.next)-(unsigned long)(&(
(typeof(*curr) *)0)->list))); &curr->list != (first
); curr = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->list.
next)-(unsigned long)(&((typeof(*tmp) *)0)->list))))
{
1511 list_del_init (&curr->list);
1512 GF_FREE (curr->pattern)__gf_free (curr->pattern);
1513 GF_FREE (curr)__gf_free (curr);
1514 }
1515 }
1516
1517 return max_pri;
1518}
1519
1520int32_t
1521mem_acct_init (xlator_t *this)
1522{
1523 int ret = -1;
1524
1525 if (!this)
1526 return ret;
1527
1528 ret = xlator_mem_acct_init (this, gf_ioc_mt_end + 1);
1529
1530 if (ret != 0) {
1531 gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"do { do { if (0) printf ("Memory accounting init" "failed"); }
while (0); _gf_log (this->name, "io-cache.c", __FUNCTION__
, 1532, GF_LOG_ERROR, "Memory accounting init" "failed"); } while
(0)
1532 "failed")do { do { if (0) printf ("Memory accounting init" "failed"); }
while (0); _gf_log (this->name, "io-cache.c", __FUNCTION__
, 1532, GF_LOG_ERROR, "Memory accounting init" "failed"); } while
(0)
;
1533 return ret;
1534 }
1535
1536 return ret;
1537}
1538
1539
1540static gf_boolean_t
1541check_cache_size_ok (xlator_t *this, uint64_t cache_size)
1542{
1543 gf_boolean_t ret = _gf_true;
1544 uint64_t total_mem = 0;
1545 uint64_t max_cache_size = 0;
1546 volume_option_t *opt = NULL((void*)0);
1547
1548 GF_ASSERT (this)do { if (!(this)) { do { do { if (0) printf ("Assertion failed: "
"this"); } while (0); _gf_log_callingfn ("", "io-cache.c", __FUNCTION__
, 1548, GF_LOG_ERROR, "Assertion failed: " "this"); } while (
0); } } while (0)
;
1549 opt = xlator_volume_option_get (this, "cache-size");
1550 if (!opt) {
1551 ret = _gf_false;
1552 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("could not get cache-size option"); }
while (0); _gf_log (this->name, "io-cache.c", __FUNCTION__
, 1553, GF_LOG_ERROR, "could not get cache-size option"); } while
(0)
1553 "could not get cache-size option")do { do { if (0) printf ("could not get cache-size option"); }
while (0); _gf_log (this->name, "io-cache.c", __FUNCTION__
, 1553, GF_LOG_ERROR, "could not get cache-size option"); } while
(0)
;
1554 goto out;
1555 }
1556
1557 total_mem = get_mem_size ();
1558 if (-1 == total_mem)
1559 max_cache_size = opt->max;
1560 else
1561 max_cache_size = total_mem;
1562
1563 gf_log (this->name, GF_LOG_DEBUG, "Max cache size is %"PRIu64,do { do { if (0) printf ("Max cache size is %""ll" "u", max_cache_size
); } while (0); _gf_log (this->name, "io-cache.c", __FUNCTION__
, 1564, GF_LOG_DEBUG, "Max cache size is %""ll" "u", max_cache_size
); } while (0)
1564 max_cache_size)do { do { if (0) printf ("Max cache size is %""ll" "u", max_cache_size
); } while (0); _gf_log (this->name, "io-cache.c", __FUNCTION__
, 1564, GF_LOG_DEBUG, "Max cache size is %""ll" "u", max_cache_size
); } while (0)
;
1565
1566 if (cache_size > max_cache_size) {
1567 ret = _gf_false;
1568 gf_log (this->name, GF_LOG_ERROR, "Cache size %"PRIu64do { do { if (0) printf ("Cache size %""ll" "u" " is greater than the max size of %"
"ll" "u", cache_size, max_cache_size); } while (0); _gf_log (
this->name, "io-cache.c", __FUNCTION__, 1570, GF_LOG_ERROR
, "Cache size %""ll" "u" " is greater than the max size of %"
"ll" "u", cache_size, max_cache_size); } while (0)
1569 " is greater than the max size of %"PRIu64,do { do { if (0) printf ("Cache size %""ll" "u" " is greater than the max size of %"
"ll" "u", cache_size, max_cache_size); } while (0); _gf_log (
this->name, "io-cache.c", __FUNCTION__, 1570, GF_LOG_ERROR
, "Cache size %""ll" "u" " is greater than the max size of %"
"ll" "u", cache_size, max_cache_size); } while (0)
1570 cache_size, max_cache_size)do { do { if (0) printf ("Cache size %""ll" "u" " is greater than the max size of %"
"ll" "u", cache_size, max_cache_size); } while (0); _gf_log (
this->name, "io-cache.c", __FUNCTION__, 1570, GF_LOG_ERROR
, "Cache size %""ll" "u" " is greater than the max size of %"
"ll" "u", cache_size, max_cache_size); } while (0)
;
1571 goto out;
1572 }
1573out:
1574 return ret;
1575}
1576
1577int
1578reconfigure (xlator_t *this, dict_t *options)
1579{
1580 data_t *data = NULL((void*)0);
1581 ioc_table_t *table = NULL((void*)0);
1582 int ret = -1;
1583 uint64_t cache_size_new = 0;
1584 if (!this || !this->private)
1585 goto out;
1586
1587 table = this->private;
1588
1589 ioc_table_lock (table)do { do { do { if (0) printf ("locked table(%p)", table); } while
(0); _gf_log (table->xl->name, "io-cache.c", __FUNCTION__
, 1589, GF_LOG_TRACE, "locked table(%p)", table); } while (0)
; pthread_mutex_lock (&table->table_lock); } while (0)
;
1590 {
1591 GF_OPTION_RECONF ("cache-timeout", table->cache_timeout,do { int val_ret = 0; val_ret = xlator_option_reconf_int32 ((
*__glusterfs_this_location()), options, "cache-timeout", &
(table->cache_timeout)); if (val_ret) goto unlock; } while
(0)
1592 options, int32, unlock)do { int val_ret = 0; val_ret = xlator_option_reconf_int32 ((
*__glusterfs_this_location()), options, "cache-timeout", &
(table->cache_timeout)); if (val_ret) goto unlock; } while
(0)
;
1593
1594 data = dict_get (options, "priority");
1595 if (data) {
1596 char *option_list = data_to_str (data);
1597
1598 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("option path %s", option_list); } while
(0); _gf_log (this->name, "io-cache.c", __FUNCTION__, 1599
, GF_LOG_TRACE, "option path %s", option_list); } while (0)
1599 "option path %s", option_list)do { do { if (0) printf ("option path %s", option_list); } while
(0); _gf_log (this->name, "io-cache.c", __FUNCTION__, 1599
, GF_LOG_TRACE, "option path %s", option_list); } while (0)
;
1600 /* parse the list of pattern:priority */
1601 table->max_pri = ioc_get_priority_list (option_list,
1602 &table->priority_list);
1603
1604 if (table->max_pri == -1) {
1605 goto unlock;
1606 }
1607 table->max_pri ++;
1608 }
1609
1610 GF_OPTION_RECONF ("max-file-size", table->max_file_size,do { int val_ret = 0; val_ret = xlator_option_reconf_size ((*
__glusterfs_this_location()), options, "max-file-size", &
(table->max_file_size)); if (val_ret) goto unlock; } while
(0)
1611 options, size, unlock)do { int val_ret = 0; val_ret = xlator_option_reconf_size ((*
__glusterfs_this_location()), options, "max-file-size", &
(table->max_file_size)); if (val_ret) goto unlock; } while
(0)
;
1612
1613 GF_OPTION_RECONF ("min-file-size", table->min_file_size,do { int val_ret = 0; val_ret = xlator_option_reconf_size ((*
__glusterfs_this_location()), options, "min-file-size", &
(table->min_file_size)); if (val_ret) goto unlock; } while
(0)
1614 options, size, unlock)do { int val_ret = 0; val_ret = xlator_option_reconf_size ((*
__glusterfs_this_location()), options, "min-file-size", &
(table->min_file_size)); if (val_ret) goto unlock; } while
(0)
;
1615
1616 if ((table->max_file_size >= 0) &&
1617 (table->min_file_size > table->max_file_size)) {
1618 gf_log (this->name, GF_LOG_ERROR, "minimum size (%"do { do { if (0) printf ("minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u""). " "Hence Defaulting to old value"
, table->min_file_size, table->max_file_size); } while (
0); _gf_log (this->name, "io-cache.c", __FUNCTION__, 1622,
GF_LOG_ERROR, "minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u""). " "Hence Defaulting to old value"
, table->min_file_size, table->max_file_size); } while (
0)
1619 PRIu64") of a file that can be cached is "do { do { if (0) printf ("minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u""). " "Hence Defaulting to old value"
, table->min_file_size, table->max_file_size); } while (
0); _gf_log (this->name, "io-cache.c", __FUNCTION__, 1622,
GF_LOG_ERROR, "minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u""). " "Hence Defaulting to old value"
, table->min_file_size, table->max_file_size); } while (
0)
1620 "greater than maximum size (%"PRIu64"). "do { do { if (0) printf ("minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u""). " "Hence Defaulting to old value"
, table->min_file_size, table->max_file_size); } while (
0); _gf_log (this->name, "io-cache.c", __FUNCTION__, 1622,
GF_LOG_ERROR, "minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u""). " "Hence Defaulting to old value"
, table->min_file_size, table->max_file_size); } while (
0)
1621 "Hence Defaulting to old value",do { do { if (0) printf ("minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u""). " "Hence Defaulting to old value"
, table->min_file_size, table->max_file_size); } while (
0); _gf_log (this->name, "io-cache.c", __FUNCTION__, 1622,
GF_LOG_ERROR, "minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u""). " "Hence Defaulting to old value"
, table->min_file_size, table->max_file_size); } while (
0)
1622 table->min_file_size, table->max_file_size)do { do { if (0) printf ("minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u""). " "Hence Defaulting to old value"
, table->min_file_size, table->max_file_size); } while (
0); _gf_log (this->name, "io-cache.c", __FUNCTION__, 1622,
GF_LOG_ERROR, "minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u""). " "Hence Defaulting to old value"
, table->min_file_size, table->max_file_size); } while (
0)
;
1623 goto unlock;
1624 }
1625
1626 GF_OPTION_RECONF ("cache-size", cache_size_new,do { int val_ret = 0; val_ret = xlator_option_reconf_size ((*
__glusterfs_this_location()), options, "cache-size", &(cache_size_new
)); if (val_ret) goto unlock; } while (0)
1627 options, size, unlock)do { int val_ret = 0; val_ret = xlator_option_reconf_size ((*
__glusterfs_this_location()), options, "cache-size", &(cache_size_new
)); if (val_ret) goto unlock; } while (0)
;
1628 if (!check_cache_size_ok (this, cache_size_new)) {
1629 ret = -1;
1630 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Not reconfiguring cache-size"); } while
(0); _gf_log (this->name, "io-cache.c", __FUNCTION__, 1631
, GF_LOG_ERROR, "Not reconfiguring cache-size"); } while (0)
1631 "Not reconfiguring cache-size")do { do { if (0) printf ("Not reconfiguring cache-size"); } while
(0); _gf_log (this->name, "io-cache.c", __FUNCTION__, 1631
, GF_LOG_ERROR, "Not reconfiguring cache-size"); } while (0)
;
1632 goto unlock;
1633 }
1634 table->cache_size = cache_size_new;
1635
1636 ret = 0;
1637 }
1638unlock:
1639 ioc_table_unlock (table)do { do { do { if (0) printf ("unlocked table(%p)", table); }
while (0); _gf_log (table->xl->name, "io-cache.c", __FUNCTION__
, 1639, GF_LOG_TRACE, "unlocked table(%p)", table); } while (
0); pthread_mutex_unlock (&table->table_lock); } while
(0)
;
1640out:
1641 return ret;
1642}
1643
1644
1645/*
1646 * init -
1647 * @this:
1648 *
1649 */
1650int32_t
1651init (xlator_t *this)
1652{
1653 ioc_table_t *table = NULL((void*)0);
1654 dict_t *xl_options = NULL((void*)0);
1655 uint32_t index = 0;
1656 int32_t ret = -1;
1657 glusterfs_ctx_t *ctx = NULL((void*)0);
1658 data_t *data = 0;
1659 uint32_t num_pages = 0;
1660
1661 xl_options = this->options;
1662
1663 if (!this->children || this->children->next) {
1664 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("FATAL: io-cache not configured with exactly "
"one child"); } while (0); _gf_log (this->name, "io-cache.c"
, __FUNCTION__, 1666, GF_LOG_ERROR, "FATAL: io-cache not configured with exactly "
"one child"); } while (0)
1665 "FATAL: io-cache not configured with exactly "do { do { if (0) printf ("FATAL: io-cache not configured with exactly "
"one child"); } while (0); _gf_log (this->name, "io-cache.c"
, __FUNCTION__, 1666, GF_LOG_ERROR, "FATAL: io-cache not configured with exactly "
"one child"); } while (0)
1666 "one child")do { do { if (0) printf ("FATAL: io-cache not configured with exactly "
"one child"); } while (0); _gf_log (this->name, "io-cache.c"
, __FUNCTION__, 1666, GF_LOG_ERROR, "FATAL: io-cache not configured with exactly "
"one child"); } while (0)
;
1667 goto out;
1668 }
1669
1670 if (!this->parents) {
1671 gf_log (this->name, GF_LOG_WARNING,do { do { if (0) printf ("dangling volume. check volfile "); }
while (0); _gf_log (this->name, "io-cache.c", __FUNCTION__
, 1672, GF_LOG_WARNING, "dangling volume. check volfile "); }
while (0)
1672 "dangling volume. check volfile ")do { do { if (0) printf ("dangling volume. check volfile "); }
while (0); _gf_log (this->name, "io-cache.c", __FUNCTION__
, 1672, GF_LOG_WARNING, "dangling volume. check volfile "); }
while (0)
;
1673 }
1674
1675 table = (void *) GF_CALLOC (1, sizeof (*table), gf_ioc_mt_ioc_table_t)__gf_calloc (1, sizeof (*table), gf_ioc_mt_ioc_table_t);
1676 if (table == NULL((void*)0)) {
1677 gf_log (this->name, GF_LOG_ERROR, "out of memory")do { do { if (0) printf ("out of memory"); } while (0); _gf_log
(this->name, "io-cache.c", __FUNCTION__, 1677, GF_LOG_ERROR
, "out of memory"); } while (0)
;
1678 goto out;
1679 }
1680
1681 table->xl = this;
1682 table->page_size = this->ctx->page_size;
1683
1684 GF_OPTION_INIT ("cache-size", table->cache_size, size, out)do { int val_ret = 0; val_ret = xlator_option_init_size ((*__glusterfs_this_location
()), (*__glusterfs_this_location())->options, "cache-size"
, &(table->cache_size)); if (val_ret) goto out; } while
(0)
;
1685
1686 GF_OPTION_INIT ("cache-timeout", table->cache_timeout, int32, out)do { int val_ret = 0; val_ret = xlator_option_init_int32 ((*__glusterfs_this_location
()), (*__glusterfs_this_location())->options, "cache-timeout"
, &(table->cache_timeout)); if (val_ret) goto out; } while
(0)
;
1687
1688 GF_OPTION_INIT ("min-file-size", table->min_file_size, size, out)do { int val_ret = 0; val_ret = xlator_option_init_size ((*__glusterfs_this_location
()), (*__glusterfs_this_location())->options, "min-file-size"
, &(table->min_file_size)); if (val_ret) goto out; } while
(0)
;
1689
1690 GF_OPTION_INIT ("max-file-size", table->max_file_size, size, out)do { int val_ret = 0; val_ret = xlator_option_init_size ((*__glusterfs_this_location
()), (*__glusterfs_this_location())->options, "max-file-size"
, &(table->max_file_size)); if (val_ret) goto out; } while
(0)
;
1691
1692 if (!check_cache_size_ok (this, table->cache_size)) {
1693 ret = -1;
1694 goto out;
1695 }
1696
1697 INIT_LIST_HEAD (&table->priority_list)do { (&table->priority_list)->next = (&table->
priority_list)->prev = &table->priority_list; } while
(0)
;
1698 table->max_pri = 1;
1699 data = dict_get (xl_options, "priority");
1700 if (data) {
1701 char *option_list = data_to_str (data);
1702 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("option path %s", option_list); } while
(0); _gf_log (this->name, "io-cache.c", __FUNCTION__, 1703
, GF_LOG_TRACE, "option path %s", option_list); } while (0)
1703 "option path %s", option_list)do { do { if (0) printf ("option path %s", option_list); } while
(0); _gf_log (this->name, "io-cache.c", __FUNCTION__, 1703
, GF_LOG_TRACE, "option path %s", option_list); } while (0)
;
1704 /* parse the list of pattern:priority */
1705 table->max_pri = ioc_get_priority_list (option_list,
1706 &table->priority_list);
1707
1708 if (table->max_pri == -1) {
1709 goto out;
1710 }
1711 }
1712 table->max_pri ++;
1713
1714 INIT_LIST_HEAD (&table->inodes)do { (&table->inodes)->next = (&table->inodes
)->prev = &table->inodes; } while (0)
;
1715
1716 if ((table->max_file_size >= 0)
1717 && (table->min_file_size > table->max_file_size)) {
1718 gf_log ("io-cache", GF_LOG_ERROR, "minimum size (%"do { do { if (0) printf ("minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u"")", table->min_file_size
, table->max_file_size); } while (0); _gf_log ("io-cache",
"io-cache.c", __FUNCTION__, 1721, GF_LOG_ERROR, "minimum size (%"
"ll" "u"") of a file that can be cached is " "greater than maximum size (%"
"ll" "u"")", table->min_file_size, table->max_file_size
); } while (0)
1719 PRIu64") of a file that can be cached is "do { do { if (0) printf ("minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u"")", table->min_file_size
, table->max_file_size); } while (0); _gf_log ("io-cache",
"io-cache.c", __FUNCTION__, 1721, GF_LOG_ERROR, "minimum size (%"
"ll" "u"") of a file that can be cached is " "greater than maximum size (%"
"ll" "u"")", table->min_file_size, table->max_file_size
); } while (0)
1720 "greater than maximum size (%"PRIu64")",do { do { if (0) printf ("minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u"")", table->min_file_size
, table->max_file_size); } while (0); _gf_log ("io-cache",
"io-cache.c", __FUNCTION__, 1721, GF_LOG_ERROR, "minimum size (%"
"ll" "u"") of a file that can be cached is " "greater than maximum size (%"
"ll" "u"")", table->min_file_size, table->max_file_size
); } while (0)
1721 table->min_file_size, table->max_file_size)do { do { if (0) printf ("minimum size (%" "ll" "u"") of a file that can be cached is "
"greater than maximum size (%""ll" "u"")", table->min_file_size
, table->max_file_size); } while (0); _gf_log ("io-cache",
"io-cache.c", __FUNCTION__, 1721, GF_LOG_ERROR, "minimum size (%"
"ll" "u"") of a file that can be cached is " "greater than maximum size (%"
"ll" "u"")", table->min_file_size, table->max_file_size
); } while (0)
;
1722 goto out;
1723 }
1724
1725 table->inode_lru = GF_CALLOC (table->max_pri,__gf_calloc (table->max_pri, sizeof (struct list_head), gf_ioc_mt_list_head
)
1726 sizeof (struct list_head),__gf_calloc (table->max_pri, sizeof (struct list_head), gf_ioc_mt_list_head
)
1727 gf_ioc_mt_list_head)__gf_calloc (table->max_pri, sizeof (struct list_head), gf_ioc_mt_list_head
)
;
1728 if (table->inode_lru == NULL((void*)0)) {
1729 goto out;
1730 }
1731
1732 for (index = 0; index < (table->max_pri); index++)
1733 INIT_LIST_HEAD (&table->inode_lru[index])do { (&table->inode_lru[index])->next = (&table
->inode_lru[index])->prev = &table->inode_lru[index
]; } while (0)
;
1734
1735 this->local_pool = mem_pool_new (ioc_local_t, 64)mem_pool_new_fn (sizeof(ioc_local_t), 64, "ioc_local_t");
1736 if (!this->local_pool) {
1737 ret = -1;
1738 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("failed to create local_t's memory pool"
); } while (0); _gf_log (this->name, "io-cache.c", __FUNCTION__
, 1739, GF_LOG_ERROR, "failed to create local_t's memory pool"
); } while (0)
1739 "failed to create local_t's memory pool")do { do { if (0) printf ("failed to create local_t's memory pool"
); } while (0); _gf_log (this->name, "io-cache.c", __FUNCTION__
, 1739, GF_LOG_ERROR, "failed to create local_t's memory pool"
); } while (0)
;
1740 goto out;
1741 }
1742
1743 pthread_mutex_init (&table->table_lock, NULL((void*)0));
1744 this->private = table;
1745
1746 num_pages = (table->cache_size / table->page_size)
1747 + ((table->cache_size % table->page_size)
1748 ? 1 : 0);
1749
1750 table->mem_pool = mem_pool_new (rbthash_entry_t, num_pages)mem_pool_new_fn (sizeof(rbthash_entry_t), num_pages, "rbthash_entry_t"
)
;
1751 if (!table->mem_pool) {
1752 gf_log (this->name, GF_LOG_ERROR,do { do { if (0) printf ("Unable to allocate mem_pool"); } while
(0); _gf_log (this->name, "io-cache.c", __FUNCTION__, 1753
, GF_LOG_ERROR, "Unable to allocate mem_pool"); } while (0)
1753 "Unable to allocate mem_pool")do { do { if (0) printf ("Unable to allocate mem_pool"); } while
(0); _gf_log (this->name, "io-cache.c", __FUNCTION__, 1753
, GF_LOG_ERROR, "Unable to allocate mem_pool"); } while (0)
;
1754 goto out;
1755 }
1756
1757 ret = 0;
1758
1759 ctx = this->ctx;
1760 ioc_log2_page_size = log_base2 (ctx->page_size);
1761
1762out:
1763 if (ret == -1) {
1764 if (table != NULL((void*)0)) {
1765 GF_FREE (table->inode_lru)__gf_free (table->inode_lru);
1766 GF_FREE (table)__gf_free (table);
1767 }
1768 }
1769
1770 return ret;
1771}
1772
1773void
1774ioc_page_waitq_dump (ioc_page_t *page, char *prefix)
1775{
1776 ioc_waitq_t *trav = NULL((void*)0);
1777 call_frame_t *frame = NULL((void*)0);
1778 int32_t i = 0;
1779 char key[GF_DUMP_MAX_BUF_LEN4096] = {0, };
1780
1781 trav = page->waitq;
1782
1783 while (trav) {
1784 frame = trav->data;
1785 sprintf (key, "waitq.frame[%d]", i++);
1786 gf_proc_dump_write (key, "%"PRId64"ll" "d", frame->root->unique);
1787
1788 trav = trav->next;
1789 }
1790}
1791
1792void
1793__ioc_inode_waitq_dump (ioc_inode_t *ioc_inode, char *prefix)
1794{
1795 ioc_waitq_t *trav = NULL((void*)0);
1796 ioc_page_t *page = NULL((void*)0);
1797 int32_t i = 0;
1798 char key[GF_DUMP_MAX_BUF_LEN4096] = {0, };
1799
1800 trav = ioc_inode->waitq;
1801
1802 while (trav) {
1803 page = trav->data;
1804
1805 sprintf (key, "cache-validation-waitq.page[%d].offset", i++);
1806 gf_proc_dump_write (key, "%"PRId64"ll" "d", page->offset);
1807
1808 trav = trav->next;
1809 }
1810}
1811
1812void
1813__ioc_page_dump (ioc_page_t *page, char *prefix)
1814{
1815
1816 int ret = -1;
1817
1818 if (!page)
1819 return;
1820 /* ioc_page_lock can be used to hold the mutex. But in statedump
1821 * its better to use trylock to avoid deadlocks.
1822 */
1823 ret = pthread_mutex_trylock (&page->page_lock);
1824 if (ret)
1825 goto out;
1826 {
1827 gf_proc_dump_write ("offset", "%"PRId64"ll" "d", page->offset);
1828 gf_proc_dump_write ("size", "%"PRId64"ll" "d", page->size);
1829 gf_proc_dump_write ("dirty", "%s", page->dirty ? "yes" : "no");
1830 gf_proc_dump_write ("ready", "%s", page->ready ? "yes" : "no");
1831 ioc_page_waitq_dump (page, prefix);
1832 }
1833 pthread_mutex_unlock (&page->page_lock);
1834
1835out:
1836 if (ret && page)
1837 gf_proc_dump_write ("Unable to dump the page information",
1838 "(Lock acquisition failed) %p", page);
1839
1840 return;
1841}
1842
1843void
1844__ioc_cache_dump (ioc_inode_t *ioc_inode, char *prefix)
1845{
1846 off_t offset = 0;
1847 ioc_table_t *table = NULL((void*)0);
1848 ioc_page_t *page = NULL((void*)0);
1849 int i = 0;
1850 char key[GF_DUMP_MAX_BUF_LEN4096] = {0, };
1851 char timestr[256] = {0, };
1852
1853 if ((ioc_inode == NULL((void*)0)) || (prefix == NULL((void*)0))) {
1854 goto out;
1855 }
1856
1857 table = ioc_inode->table;
1858
1859 if (ioc_inode->cache.tv.tv_sec) {
1860 gf_time_fmt (timestr, sizeof timestr,
1861 ioc_inode->cache.tv.tv_sec, gf_timefmt_FT);
1862 snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr),
1863 ".%"GF_PRI_SUSECONDS"06ld", ioc_inode->cache.tv.tv_usec);
1864
1865 gf_proc_dump_write ("last-cache-validation-time", "%s",
1866 timestr);
1867 }
1868
1869 for (offset = 0; offset < ioc_inode->ia_size;
1870 offset += table->page_size) {
1871 page = __ioc_page_get (ioc_inode, offset);
1872 if (page == NULL((void*)0)) {
1873 continue;
1874 }
1875
1876 sprintf (key, "inode.cache.page[%d]", i++);
1877 __ioc_page_dump (page, key);
1878 }
1879out:
1880 return;
1881}
1882
1883
1884int
1885ioc_inode_dump (xlator_t *this, inode_t *inode)
1886{
1887
1888 char *path = NULL((void*)0);
1889 int ret = -1;
1890 char key_prefix[GF_DUMP_MAX_BUF_LEN4096] = {0, };
1891 uint64_t tmp_ioc_inode = 0;
1892 ioc_inode_t *ioc_inode = NULL((void*)0);
1893 gf_boolean_t section_added = _gf_false;
1894 char uuid_str[64] = {0,};
1895
1896 if (this == NULL((void*)0) || inode == NULL((void*)0))
1897 goto out;
1898
1899 gf_proc_dump_build_key (key_prefix, "io-cache", "inode"){ _gf_proc_dump_build_key(key_prefix, "io-cache", "inode"); };
1900
1901 inode_ctx_get (inode, this, &tmp_ioc_inode)inode_ctx_get2(inode,this,&tmp_ioc_inode,0);
1902 ioc_inode = (ioc_inode_t *)(long)tmp_ioc_inode;
1903 if (ioc_inode == NULL((void*)0))
1904 goto out;
1905
1906 gf_proc_dump_add_section (key_prefix);
1907 section_added = _gf_true;
1908
1909 /* Similar to ioc_page_dump function its better to use
1910 * pthread_mutex_trylock and not to use gf_log in statedump
1911 * to avoid deadlocks.
1912 */
1913 ret = pthread_mutex_trylock (&ioc_inode->inode_lock);
1914 if (ret)
1915 goto out;
1916 else
1917 {
1918 gf_proc_dump_write ("inode.weight", "%d", ioc_inode->weight);
1919
1920 //inode_path takes blocking lock on the itable.
1921 __inode_path (ioc_inode->inode, NULL((void*)0), &path);
1922
1923 if (path) {
1924 gf_proc_dump_write ("path", "%s", path);
1925 GF_FREE (path)__gf_free (path);
1926 }
1927 gf_proc_dump_write ("uuid", "%s", uuid_utoa_r
1928 (ioc_inode->inode->gfid, uuid_str));
1929 __ioc_cache_dump (ioc_inode, key_prefix);
1930 __ioc_inode_waitq_dump (ioc_inode, key_prefix);
1931
1932 pthread_mutex_unlock (&ioc_inode->inode_lock);
1933 }
1934
1935out:
1936 if (ret && ioc_inode) {
1937 if (section_added == _gf_false)
1938 gf_proc_dump_add_section (key_prefix);
1939 gf_proc_dump_write ("Unable to print the status of ioc_inode",
1940 "(Lock acquisition failed) %s",
1941 uuid_utoa (inode->gfid));
1942 }
1943 return ret;
1944}
1945
1946int
1947ioc_priv_dump (xlator_t *this)
1948{
1949 ioc_table_t *priv = NULL((void*)0);
1950 char key_prefix[GF_DUMP_MAX_BUF_LEN4096] = {0, };
1951 int ret = -1;
1952 gf_boolean_t add_section = _gf_false;
1953
1954 if (!this || !this->private)
1955 goto out;
1956
1957 priv = this->private;
1958
1959 gf_proc_dump_build_key (key_prefix, "io-cache", "priv"){ _gf_proc_dump_build_key(key_prefix, "io-cache", "priv"); };
1960 gf_proc_dump_add_section (key_prefix);
1961 add_section = _gf_true;
1962
1963 ret = pthread_mutex_trylock (&priv->table_lock);
1964 if (ret)
1965 goto out;
1966 {
1967 gf_proc_dump_write ("page_size", "%ld", priv->page_size);
1968 gf_proc_dump_write ("cache_size", "%ld", priv->cache_size);
1969 gf_proc_dump_write ("cache_used", "%ld", priv->cache_used);
1970 gf_proc_dump_write ("inode_count", "%u", priv->inode_count);
1971 gf_proc_dump_write ("cache_timeout", "%u", priv->cache_timeout);
1972 gf_proc_dump_write ("min-file-size", "%u", priv->min_file_size);
1973 gf_proc_dump_write ("max-file-size", "%u", priv->max_file_size);
1974 }
1975 pthread_mutex_unlock (&priv->table_lock);
1976out:
1977 if (ret && priv) {
1978 if (!add_section) {
1979 gf_proc_dump_build_key (key_prefix, "xlator."{ _gf_proc_dump_build_key(key_prefix, "xlator." "performance.io-cache"
, "priv"); }
1980 "performance.io-cache", "priv"){ _gf_proc_dump_build_key(key_prefix, "xlator." "performance.io-cache"
, "priv"); }
;
1981 gf_proc_dump_add_section (key_prefix);
1982 }
1983 gf_proc_dump_write ("Unable to dump the state of private "
1984 "structure of io-cache xlator", "(Lock "
1985 "acquisition failed) %s", this->name);
1986 }
1987
1988 return 0;
1989}
1990
1991/*
1992 * fini -
1993 *
1994 * @this:
1995 *
1996 */
1997void
1998fini (xlator_t *this)
1999{
2000 ioc_table_t *table = NULL((void*)0);
2001 struct ioc_priority *curr = NULL((void*)0), *tmp = NULL((void*)0);
2002 int i = 0;
2003
2004 table = this->private;
2005
2006 if (table == NULL((void*)0))
2007 return;
2008
2009 this->private = NULL((void*)0);
2010
2011 if (table->mem_pool != NULL((void*)0)) {
2012 mem_pool_destroy (table->mem_pool);
2013 table->mem_pool = NULL((void*)0);
2014 }
2015
2016 list_for_each_entry_safe (curr, tmp, &table->priority_list, list)for (curr = ((typeof(*curr) *)((char *)((&table->priority_list
)->next)-(unsigned long)(&((typeof(*curr) *)0)->list
))), tmp = ((typeof(*curr) *)((char *)(curr->list.next)-(unsigned
long)(&((typeof(*curr) *)0)->list))); &curr->list
!= (&table->priority_list); curr = tmp, tmp = ((typeof
(*tmp) *)((char *)(tmp->list.next)-(unsigned long)(&((
typeof(*tmp) *)0)->list))))
{
2017 list_del_init (&curr->list);
2018 GF_FREE (curr->pattern)__gf_free (curr->pattern);
2019 GF_FREE (curr)__gf_free (curr);
2020 }
2021
2022 for (i = 0; i < table->max_pri; i++) {
2023 GF_ASSERT (list_empty (&table->inode_lru[i]))do { if (!(list_empty (&table->inode_lru[i]))) { do { do
{ if (0) printf ("Assertion failed: " "list_empty (&table->inode_lru[i])"
); } while (0); _gf_log_callingfn ("", "io-cache.c", __FUNCTION__
, 2023, GF_LOG_ERROR, "Assertion failed: " "list_empty (&table->inode_lru[i])"
); } while (0); } } while (0)
;
2024 }
2025
2026 GF_ASSERT (list_empty (&table->inodes))do { if (!(list_empty (&table->inodes))) { do { do { if
(0) printf ("Assertion failed: " "list_empty (&table->inodes)"
); } while (0); _gf_log_callingfn ("", "io-cache.c", __FUNCTION__
, 2026, GF_LOG_ERROR, "Assertion failed: " "list_empty (&table->inodes)"
); } while (0); } } while (0)
;
2027 pthread_mutex_destroy (&table->table_lock);
2028 GF_FREE (table)__gf_free (table);
2029
2030 this->private = NULL((void*)0);
2031 return;
2032}
2033
2034struct xlator_fops fops = {
2035 .open = ioc_open,
2036 .create = ioc_create,
2037 .readv = ioc_readv,
2038 .writev = ioc_writev,
2039 .truncate = ioc_truncate,
2040 .ftruncate = ioc_ftruncate,
2041 .lookup = ioc_lookup,
2042 .lk = ioc_lk,
2043 .setattr = ioc_setattr,
2044 .mknod = ioc_mknod,
2045
2046 .readdirp = ioc_readdirp,
2047};
2048
2049
2050struct xlator_dumpops dumpops = {
2051 .priv = ioc_priv_dump,
2052 .inodectx = ioc_inode_dump,
2053};
2054
2055struct xlator_cbks cbks = {
2056 .forget = ioc_forget,
2057 .release = ioc_release,
2058 .invalidate = ioc_invalidate,
2059};
2060
2061struct volume_options options[] = {
2062 { .key = {"priority"},
2063 .type = GF_OPTION_TYPE_PRIORITY_LIST,
2064 .default_value = "",
2065 .description = "Assigns priority to filenames with specific "
2066 "patterns so that when a page needs to be ejected "
2067 "out of the cache, the page of a file whose "
2068 "priority is the lowest will be ejected earlier"
2069 },
2070 { .key = {"cache-timeout", "force-revalidate-timeout"},
2071 .type = GF_OPTION_TYPE_INT,
2072 .min = 0,
2073 .max = 60,
2074 .default_value = "1",
2075 .description = "The cached data for a file will be retained till "
2076 "'cache-refresh-timeout' seconds, after which data "
2077 "re-validation is performed."
2078 },
2079 { .key = {"cache-size"},
2080 .type = GF_OPTION_TYPE_SIZET,
2081 .min = 4 * GF_UNIT_MB1048576ULL,
2082 .max = 32 * GF_UNIT_GB1073741824ULL,
2083 .default_value = "32MB",
2084 .description = "Size of the read cache."
2085 },
2086 { .key = {"min-file-size"},
2087 .type = GF_OPTION_TYPE_SIZET,
2088 .default_value = "0",
2089 .description = "Minimum file size which would be cached by the "
2090 "io-cache translator."
2091 },
2092 { .key = {"max-file-size"},
2093 .type = GF_OPTION_TYPE_SIZET,
2094 .default_value = "0",
2095 .description = "Maximum file size which would be cached by the "
2096 "io-cache translator."
2097 },
2098 { .key = {NULL((void*)0)} },
2099};