174
static inline uint32_t
175
is_match (const char *path, const char *pattern)
179
ret = fnmatch (pattern, path, FNM_NOESCAPE);
185
qr_get_priority (qr_conf_t *conf, const char *path)
187
uint32_t priority = 0;
188
struct qr_priority *curr = NULL;
190
list_for_each_entry (curr, &conf->priority_list, list) {
191
if (is_match (path, curr->pattern))
192
priority = curr->priority;
199
/* To be called with this-priv->table.lock held */
201
__qr_inode_alloc (xlator_t *this, char *path, inode_t *inode)
203
qr_inode_t *qr_inode = NULL;
204
qr_private_t *priv = NULL;
207
priv = this->private;
209
qr_inode = CALLOC (1, sizeof (*qr_inode));
210
if (qr_inode == NULL) {
211
gf_log (this->name, GF_LOG_ERROR, "out of memory");
215
INIT_LIST_HEAD (&qr_inode->lru);
217
priority = qr_get_priority (&priv->conf, path);
219
list_add_tail (&qr_inode->lru, &priv->table.lru[priority]);
221
qr_inode->inode = inode;
222
qr_inode->priority = priority;
228
/* To be called with qr_inode->table->lock held */
230
__qr_inode_free (qr_inode_t *qr_inode)
232
if (qr_inode == NULL) {
236
if (qr_inode->xattr) {
237
dict_unref (qr_inode->xattr);
240
list_del (&qr_inode->lru);
248
/* To be called with priv->table.lock held */
250
__qr_cache_prune (xlator_t *this)
252
qr_private_t *priv = NULL;
253
qr_conf_t *conf = NULL;
254
qr_inode_table_t *table = NULL;
255
qr_inode_t *curr = NULL, *next = NULL;
257
uint64_t size_to_prune = 0;
258
uint64_t size_pruned = 0;
260
priv = this->private;
261
table = &priv->table;
264
size_to_prune = table->cache_used - conf->cache_size;
266
for (index=0; index < conf->max_pri; index++) {
267
list_for_each_entry_safe (curr, next, &table->lru[index], lru) {
268
size_pruned += curr->stbuf.st_size;
269
inode_ctx_del (curr->inode, this, NULL);
270
__qr_inode_free (curr);
271
if (size_pruned >= size_to_prune)
277
table->cache_used -= size_pruned;
282
/* To be called with table->lock held */
284
__qr_need_cache_prune (qr_conf_t *conf, qr_inode_table_t *table)
286
return (table->cache_used > conf->cache_size);
151
291
qr_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
152
292
int32_t op_ret, int32_t op_errno, inode_t *inode,
153
293
struct stat *buf, dict_t *dict, struct stat *postparent)
155
data_t *content = NULL;
156
qr_file_t *qr_file = NULL;
159
qr_conf_t *conf = NULL;
295
data_t *content = NULL;
296
qr_inode_t *qr_inode = NULL;
299
qr_conf_t *conf = NULL;
300
qr_inode_table_t *table = NULL;
301
qr_private_t *priv = NULL;
302
qr_local_t *local = NULL;
161
304
if ((op_ret == -1) || (dict == NULL)) {
165
308
conf = this->private;
309
priv = this->private;
311
table = &priv->table;
313
local = frame->local;
167
315
if (buf->st_size > conf->max_file_size) {
181
329
content = dict_get (dict, GLUSTERFS_CONTENT_KEY);
330
if (content == NULL) {
185
ret = __inode_ctx_get (inode, this, &value);
336
ret = inode_ctx_get (inode, this, &value);
187
qr_file = CALLOC (1, sizeof (*qr_file));
188
if (qr_file == NULL) {
338
qr_inode = __qr_inode_alloc (this, local->path, inode);
339
if (qr_inode == NULL) {
190
341
op_errno = ENOMEM;
194
LOCK_INIT (&qr_file->lock);
195
ret = __inode_ctx_put (inode, this,
196
(uint64_t)(long)qr_file);
345
ret = inode_ctx_put (inode, this,
346
(uint64_t)(long)qr_inode);
348
__qr_inode_free (qr_inode);
201
351
op_errno = EINVAL;
204
qr_file = (qr_file_t *)(long)value;
205
if (qr_file == NULL) {
355
qr_inode = (qr_inode_t *)(long)value;
356
if (qr_inode == NULL) {
207
358
op_errno = EINVAL;
363
if (qr_inode->xattr) {
364
dict_unref (qr_inode->xattr);
365
qr_inode->xattr = NULL;
367
table->cache_used -= qr_inode->stbuf.st_size;
370
qr_inode->xattr = dict_ref (dict);
371
qr_inode->stbuf = *buf;
372
table->cache_used += buf->st_size;
374
gettimeofday (&qr_inode->tv, NULL);
376
if (__qr_need_cache_prune (conf, table)) {
377
__qr_cache_prune (this);
212
UNLOCK (&inode->lock);
214
if (qr_file != NULL) {
215
LOCK (&qr_file->lock);
218
&& ((qr_file->stbuf.st_mtime != buf->st_mtime)
219
|| (ST_MTIM_NSEC(&qr_file->stbuf)
220
!= ST_MTIM_NSEC(buf)))) {
221
dict_unref (qr_file->xattr);
222
qr_file->xattr = NULL;
226
if (qr_file->xattr) {
227
dict_unref (qr_file->xattr);
228
qr_file->xattr = NULL;
231
qr_file->xattr = dict_ref (dict);
232
qr_file->stbuf = *buf;
235
gettimeofday (&qr_file->tv, NULL);
237
UNLOCK (&qr_file->lock);
381
UNLOCK (&table->lock);
242
386
* FIXME: content size in dict can be greater than the size application
243
387
* requested for. Applications need to be careful till this is fixed.
245
STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf, dict,
389
QR_STACK_UNWIND (lookup, frame, op_ret, op_errno, inode, buf, dict,
252
396
qr_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req)
254
qr_conf_t *conf = NULL;
255
dict_t *new_req_dict = NULL;
256
int32_t op_ret = -1, op_errno = -1;
257
data_t *content = NULL;
258
uint64_t requested_size = 0, size = 0, value = 0;
260
qr_file_t *qr_file = NULL;
398
qr_conf_t *conf = NULL;
399
dict_t *new_req_dict = NULL;
400
int32_t op_ret = -1, op_errno = -1;
401
data_t *content = NULL;
402
uint64_t requested_size = 0, size = 0, value = 0;
404
qr_inode_t *qr_inode = NULL;
405
qr_private_t *priv = NULL;
406
qr_inode_table_t *table = NULL;
407
qr_local_t *local = NULL;
262
conf = this->private;
409
priv = this->private;
263
411
if (conf == NULL) {
265
413
op_errno = EINVAL;
269
op_ret = inode_ctx_get (loc->inode, this, &value);
271
qr_file = (qr_file_t *)(long)value;
274
if (qr_file != NULL) {
275
LOCK (&qr_file->lock);
277
if (qr_file->xattr) {
417
table = &priv->table;
419
local = CALLOC (1, sizeof (*local));
420
GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, unwind, op_errno,
423
frame->local = local;
425
local->path = strdup (loc->path);
426
GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, unwind, op_errno,
430
op_ret = inode_ctx_get (loc->inode, this, &value);
432
qr_inode = (qr_inode_t *)(long)value;
433
if (qr_inode != NULL) {
434
if (qr_inode->xattr) {
281
UNLOCK (&qr_file->lock);
440
UNLOCK (&table->lock);
284
442
if ((xattr_req == NULL) && (conf->max_file_size > 0)) {
285
443
new_req_dict = xattr_req = dict_new ();
327
STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, NULL, NULL, NULL,
485
QR_STACK_UNWIND (lookup, frame, op_ret, op_errno, NULL, NULL, NULL,
330
488
if (new_req_dict) {
331
489
dict_unref (new_req_dict);
339
497
qr_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
340
498
int32_t op_errno, fd_t *fd)
344
struct list_head waiting_ops;
345
qr_local_t *local = NULL;
346
qr_file_t *qr_file = NULL;
347
qr_fd_ctx_t *qr_fd_ctx = NULL;
348
call_stub_t *stub = NULL, *tmp = NULL;
502
struct list_head waiting_ops;
503
qr_local_t *local = NULL;
504
qr_inode_t *qr_inode = NULL;
505
qr_fd_ctx_t *qr_fd_ctx = NULL;
506
call_stub_t *stub = NULL, *tmp = NULL;
508
qr_private_t *priv = NULL;
509
qr_inode_table_t *table = NULL;
511
priv = this->private;
512
table = &priv->table;
351
514
local = frame->local;
352
515
if (local != NULL) {
384
547
if (local && local->is_open
385
548
&& ((local->open_flags & O_TRUNC) == O_TRUNC)) {
386
ret = inode_ctx_get (fd->inode, this, &value);
388
qr_file = (qr_file_t *)(long) value;
551
ret = inode_ctx_del (fd->inode, this, &value);
553
qr_inode = (qr_inode_t *)(long) value;
391
LOCK (&qr_file->lock);
393
dict_unref (qr_file->xattr);
394
qr_file->xattr = NULL;
555
if (qr_inode != NULL) {
556
__qr_inode_free (qr_inode);
396
UNLOCK (&qr_file->lock);
560
UNLOCK (&table->lock);
401
563
if (!list_empty (&waiting_ops)) {
419
581
qr_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
420
582
fd_t *fd, int32_t wbflags)
422
qr_file_t *qr_file = NULL;
425
char content_cached = 0;
426
qr_fd_ctx_t *qr_fd_ctx = NULL, *tmp_fd_ctx = NULL;
427
int32_t op_ret = -1, op_errno = -1;
428
qr_local_t *local = NULL;
429
qr_conf_t *conf = NULL;
584
qr_inode_t *qr_inode = NULL;
587
char content_cached = 0;
588
qr_fd_ctx_t *qr_fd_ctx = NULL, *tmp_fd_ctx = NULL;
589
int32_t op_ret = -1, op_errno = -1;
590
qr_local_t *local = NULL;
591
qr_conf_t *conf = NULL;
592
qr_private_t *priv = NULL;
593
qr_inode_table_t *table = NULL;
431
conf = this->private;
595
priv = this->private;
597
table = &priv->table;
433
599
tmp_fd_ctx = qr_fd_ctx = CALLOC (1, sizeof (*qr_fd_ctx));
434
600
if (qr_fd_ctx == NULL) {
537
697
static inline char
538
qr_need_validation (qr_conf_t *conf, qr_file_t *file)
698
qr_need_validation (qr_conf_t *conf, qr_inode_t *qr_inode)
540
700
struct timeval now = {0, };
541
701
char need_validation = 0;
543
703
gettimeofday (&now, NULL);
545
if (qr_time_elapsed (&now, &file->tv) >= conf->cache_timeout)
705
if (qr_time_elapsed (&now, &qr_inode->tv) >= conf->cache_timeout)
546
706
need_validation = 1;
548
708
return need_validation;
553
713
qr_validate_cache_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
554
714
int32_t op_ret, int32_t op_errno, struct stat *buf)
556
qr_file_t *qr_file = NULL;
557
qr_local_t *local = NULL;
716
qr_inode_t *qr_inode = NULL;
717
qr_local_t *local = NULL;
720
qr_private_t *priv = NULL;
721
qr_inode_table_t *table = NULL;
722
call_stub_t *stub = NULL;
561
724
local = frame->local;
562
725
if ((local == NULL) || ((local->fd) == NULL)) {
572
ret = inode_ctx_get (local->fd->inode, this, &value);
579
qr_file = (qr_file_t *)(long) value;
580
if (qr_file == NULL) {
586
LOCK (&qr_file->lock);
735
priv = this->private;
736
table = &priv->table;
588
if ((qr_file->stbuf.st_mtime != buf->st_mtime)
589
|| (ST_MTIM_NSEC(&qr_file->stbuf) !=
590
ST_MTIM_NSEC(buf))) {
591
dict_unref (qr_file->xattr);
592
qr_file->xattr = NULL;
595
gettimeofday (&qr_file->tv, NULL);
740
ret = inode_ctx_get (local->fd->inode, this, &value);
742
qr_inode = (qr_inode_t *)(long) value;
745
if (qr_inode != NULL) {
746
gettimeofday (&qr_inode->tv, NULL);
748
if ((qr_inode->stbuf.st_mtime != buf->st_mtime)
749
|| (ST_MTIM_NSEC(&qr_inode->stbuf) !=
750
ST_MTIM_NSEC(buf))) {
751
inode_ctx_del (local->fd->inode, this, NULL);
752
__qr_inode_free (qr_inode);
597
UNLOCK (&qr_file->lock);
601
call_resume (local->stub);
756
UNLOCK (&table->lock);
760
local->just_validated = 1;
607
if (local && local->stub) {
608
call_stub_destroy (local->stub);
612
766
/* this is actually unwind of readv */
613
STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, NULL, -1, NULL,
767
QR_STACK_UNWIND (readv, frame, op_ret, op_errno, NULL, -1, NULL,
738
892
int32_t op_errno, struct iovec *vector, int32_t count,
739
893
struct stat *stbuf, struct iobref *iobref)
741
STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, vector, count,
895
QR_STACK_UNWIND (readv, frame, op_ret, op_errno, vector, count,
795
963
iobuf_pool = this->ctx->iobuf_pool;
797
ret = inode_ctx_get (fd->inode, this, &value);
799
file = (qr_file_t *)(long)value;
804
if (qr_need_validation (conf,file)) {
967
ret = inode_ctx_get (fd->inode, this, &value);
969
qr_inode = (qr_inode_t *)(long)value;
971
if (qr_inode->xattr){
973
&& qr_need_validation (conf,
805
975
need_validation = 1;
809
content = dict_get (file->xattr,
979
content = dict_get (qr_inode->xattr,
810
980
GLUSTERFS_CONTENT_KEY);
982
stbuf = qr_inode->stbuf;
814
983
content_cached = 1;
984
list_move_tail (&qr_inode->lru,
985
&table->lru[qr_inode->priority]);
816
988
if (offset > content->len) {
891
UNLOCK (&file->lock);
1065
UNLOCK (&table->lock);
896
1068
if (content_cached || need_unwind) {
897
STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, vector,
898
count, &stbuf, iobref);
1069
QR_STACK_UNWIND (readv, frame, op_ret, op_errno, vector,
1070
count, &stbuf, iobref);
900
1072
} else if (need_validation) {
901
1073
stub = fop_readv_stub (frame, qr_readv, fd, size, offset);
993
1165
int32_t op_ret, int32_t op_errno, struct stat *prebuf,
994
1166
struct stat *postbuf)
996
STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, postbuf);
1168
QR_STACK_UNWIND (writev, frame, op_ret, op_errno, prebuf, postbuf);
1014
1186
qr_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, struct iovec *vector,
1015
1187
int32_t count, off_t off, struct iobref *iobref)
1019
call_stub_t *stub = NULL;
1022
qr_file_t *qr_file = NULL;
1023
qr_fd_ctx_t *qr_fd_ctx = NULL;
1024
int32_t op_ret = -1, op_errno = -1, ret = -1;
1025
char can_wind = 0, need_unwind = 0, need_open = 0;
1191
call_stub_t *stub = NULL;
1194
qr_inode_t *qr_inode = NULL;
1195
qr_fd_ctx_t *qr_fd_ctx = NULL;
1196
int32_t op_ret = -1, op_errno = -1, ret = -1;
1197
char can_wind = 0, need_unwind = 0, need_open = 0;
1198
qr_private_t *priv = NULL;
1199
qr_inode_table_t *table = NULL;
1201
priv = this->private;
1202
table = &priv->table;
1027
1204
ret = fd_ctx_get (fd, this, &value);
1029
1205
if (ret == 0) {
1030
1206
qr_fd_ctx = (qr_fd_ctx_t *)(long) value;
1033
ret = inode_ctx_get (fd->inode, this, &value);
1035
qr_file = (qr_file_t *)(long)value;
1039
LOCK (&qr_file->lock);
1041
if (qr_file->xattr) {
1042
dict_unref (qr_file->xattr);
1043
qr_file->xattr = NULL;
1209
LOCK (&table->lock);
1211
ret = inode_ctx_get (fd->inode, this, &value);
1213
qr_inode = (qr_inode_t *)(long)value;
1214
if (qr_inode != NULL) {
1215
inode_ctx_del (fd->inode, this, NULL);
1216
__qr_inode_free (qr_inode);
1046
UNLOCK (&qr_file->lock);
1220
UNLOCK (&table->lock);
1049
1222
if (qr_fd_ctx) {
1050
1223
LOCK (&qr_fd_ctx->lock);
1086
1259
if (need_unwind) {
1087
STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, NULL,
1260
QR_STACK_UNWIND (writev, frame, op_ret, op_errno, NULL,
1089
1262
} else if (can_wind) {
1090
1263
STACK_WIND (frame, qr_writev_cbk, FIRST_CHILD (this),
1091
1264
FIRST_CHILD (this)->fops->writev, fd, vector, count,
1111
1284
qr_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
1112
int32_t op_errno, struct stat *buf)
1285
int32_t op_errno, struct stat *buf)
1114
STACK_UNWIND_STRICT (fstat, frame, op_ret, op_errno, buf);
1287
QR_STACK_UNWIND (fstat, frame, op_ret, op_errno, buf);
1181
1354
if (need_unwind) {
1182
STACK_UNWIND_STRICT (fstat, frame, op_ret, op_errno, NULL);
1355
QR_STACK_UNWIND (fstat, frame, op_ret, op_errno, NULL);
1183
1356
} else if (can_wind) {
1184
1357
STACK_WIND (frame, qr_fstat_cbk, FIRST_CHILD (this),
1185
1358
FIRST_CHILD (this)->fops->fstat, fd);
1207
1380
int32_t op_ret, int32_t op_errno,
1208
1381
struct stat *preop, struct stat *postop)
1210
STACK_UNWIND_STRICT (fsetattr, frame, op_ret, op_errno, preop, postop);
1383
QR_STACK_UNWIND (fsetattr, frame, op_ret, op_errno, preop, postop);
1280
1453
if (need_unwind) {
1281
STACK_UNWIND_STRICT (fsetattr, frame, op_ret, op_errno, NULL,
1454
QR_STACK_UNWIND (fsetattr, frame, op_ret, op_errno, NULL,
1283
1456
} else if (can_wind) {
1284
1457
STACK_WIND (frame, qr_fsetattr_cbk, FIRST_CHILD (this),
1285
1458
FIRST_CHILD (this)->fops->fsetattr, fd, stbuf,
1378
1551
if (need_unwind) {
1379
STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno);
1552
QR_STACK_UNWIND (fsetxattr, frame, op_ret, op_errno);
1380
1553
} else if (can_wind) {
1381
1554
STACK_WIND (frame, qr_fsetxattr_cbk, FIRST_CHILD (this),
1382
1555
FIRST_CHILD (this)->fops->fsetxattr, fd, dict,
1403
1576
qr_fgetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1404
int32_t op_ret, int32_t op_errno, dict_t *dict)
1577
int32_t op_ret, int32_t op_errno, dict_t *dict)
1406
STACK_UNWIND_STRICT (fgetxattr, frame, op_ret, op_errno, dict);
1579
QR_STACK_UNWIND (fgetxattr, frame, op_ret, op_errno, dict);
1480
1653
if (need_unwind) {
1481
STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, NULL);
1654
QR_STACK_UNWIND (open, frame, op_ret, op_errno, NULL);
1482
1655
} else if (can_wind) {
1483
1656
STACK_WIND (frame, qr_fgetxattr_cbk, FIRST_CHILD (this),
1484
1657
FIRST_CHILD (this)->fops->fgetxattr, fd, name);
1650
1823
if (need_unwind) {
1651
STACK_UNWIND_STRICT (fentrylk, frame, op_ret, op_errno);
1824
QR_STACK_UNWIND (fentrylk, frame, op_ret, op_errno);
1652
1825
} else if (can_wind) {
1653
1826
STACK_WIND (frame, qr_fentrylk_cbk, FIRST_CHILD(this),
1654
1827
FIRST_CHILD(this)->fops->fentrylk, volume, fd,
1749
1922
if (need_unwind) {
1750
STACK_UNWIND_STRICT (finodelk, frame, op_ret, op_errno);
1923
QR_STACK_UNWIND (finodelk, frame, op_ret, op_errno);
1751
1924
} else if (can_wind) {
1752
1925
STACK_WIND (frame, qr_finodelk_cbk, FIRST_CHILD(this),
1753
1926
FIRST_CHILD(this)->fops->finodelk, volume, fd,
1773
1946
qr_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
1774
1947
int32_t op_errno, struct stat *prebuf, struct stat *postbuf)
1776
STACK_UNWIND_STRICT (fsync, frame, op_ret, op_errno, prebuf, postbuf);
1949
QR_STACK_UNWIND (fsync, frame, op_ret, op_errno, prebuf, postbuf);
1842
2015
if (need_unwind) {
1843
STACK_UNWIND_STRICT (fsync, frame, op_ret, op_errno, NULL,
2016
QR_STACK_UNWIND (fsync, frame, op_ret, op_errno, NULL,
1845
2018
} else if (can_wind) {
1846
2019
STACK_WIND (frame, qr_fsync_cbk, FIRST_CHILD (this),
1847
2020
FIRST_CHILD (this)->fops->fsync, fd, flags);
1868
2041
int32_t op_ret, int32_t op_errno, struct stat *prebuf,
1869
2042
struct stat *postbuf)
1873
qr_file_t *qr_file = NULL;
1874
qr_local_t *local = NULL;
2046
qr_inode_t *qr_inode = NULL;
2047
qr_local_t *local = NULL;
2048
qr_private_t *priv = NULL;
2049
qr_inode_table_t *table = NULL;
1876
2051
if (op_ret == -1) {
2055
priv = this->private;
2056
table = &priv->table;
1880
2058
local = frame->local;
1881
2059
if ((local == NULL) || (local->fd == NULL)
1882
2060
|| (local->fd->inode == NULL)) {
1888
ret = inode_ctx_get (local->fd->inode, this, &value);
1890
qr_file = (qr_file_t *)(long) value;
2066
LOCK (&table->lock);
2068
ret = inode_ctx_get (local->fd->inode, this, &value);
2070
qr_inode = (qr_inode_t *)(long) value;
1893
LOCK (&qr_file->lock);
1895
if (qr_file->stbuf.st_size != postbuf->st_size)
2073
if (qr_inode->stbuf.st_size != postbuf->st_size)
1897
dict_unref (qr_file->xattr);
1898
qr_file->xattr = NULL;
2075
inode_ctx_del (local->fd->inode, this,
2077
__qr_inode_free (qr_inode);
1901
UNLOCK (&qr_file->lock);
2082
UNLOCK (&table->lock);
1906
STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, prebuf,
2085
QR_STACK_UNWIND (ftruncate, frame, op_ret, op_errno, prebuf,
1988
2167
if (need_unwind) {
1989
STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, NULL,
2168
QR_STACK_UNWIND (ftruncate, frame, op_ret, op_errno, NULL,
1991
2170
} else if (can_wind) {
1992
2171
STACK_WIND (frame, qr_ftruncate_cbk, FIRST_CHILD(this),
1993
2172
FIRST_CHILD(this)->fops->ftruncate, fd, offset);
2012
2191
qr_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
2013
2192
int32_t op_errno, struct flock *lock)
2015
STACK_UNWIND_STRICT (lk, frame, op_ret, op_errno, lock);
2194
QR_STACK_UNWIND (lk, frame, op_ret, op_errno, lock);
2085
2264
if (need_unwind) {
2086
STACK_UNWIND_STRICT (lk, frame, op_ret, op_errno, NULL);
2265
QR_STACK_UNWIND (lk, frame, op_ret, op_errno, NULL);
2087
2266
} else if (can_wind) {
2088
2267
STACK_WIND (frame, qr_lk_cbk, FIRST_CHILD(this),
2089
2268
FIRST_CHILD(this)->fops->lk, fd, cmd, lock);
2127
2306
qr_forget (xlator_t *this, inode_t *inode)
2129
qr_file_t *qr_file = NULL;
2133
ret = inode_ctx_del (inode, this, &value);
2135
qr_file = (qr_file_t *)(long) value;
2137
LOCK (&qr_file->lock);
2139
if (qr_file->xattr) {
2140
dict_unref (qr_file->xattr);
2141
qr_file->xattr = NULL;
2144
UNLOCK (&qr_file->lock);
2308
qr_inode_t *qr_inode = NULL;
2311
qr_private_t *priv = NULL;
2313
priv = this->private;
2315
LOCK (&priv->table.lock);
2317
ret = inode_ctx_del (inode, this, &value);
2319
qr_inode = (qr_inode_t *)(long) value;
2320
__qr_inode_free (qr_inode);
2323
UNLOCK (&priv->table.lock);
2363
qr_get_priority_list (const char *opt_str, struct list_head *first)
2365
int32_t max_pri = 1;
2366
char *tmp_str = NULL;
2367
char *tmp_str1 = NULL;
2368
char *tmp_str2 = NULL;
2369
char *dup_str = NULL;
2370
char *priority_str = NULL;
2371
char *pattern = NULL;
2372
char *priority = NULL;
2373
char *string = NULL;
2374
struct qr_priority *curr = NULL, *tmp = NULL;
2376
string = strdup (opt_str);
2377
if (string == NULL) {
2382
/* Get the pattern for cache priority.
2383
* "option priority *.jpg:1,abc*:2" etc
2385
/* TODO: inode_lru in table is statically hard-coded to 5,
2386
* should be changed to run-time configuration
2388
priority_str = strtok_r (string, ",", &tmp_str);
2389
while (priority_str) {
2390
curr = CALLOC (1, sizeof (*curr));
2396
list_add_tail (&curr->list, first);
2398
dup_str = strdup (priority_str);
2399
if (dup_str == NULL) {
2404
pattern = strtok_r (dup_str, ":", &tmp_str1);
2410
priority = strtok_r (NULL, ":", &tmp_str1);
2416
gf_log ("quick-read", GF_LOG_TRACE,
2417
"quick-read priority : pattern %s : priority %s",
2421
curr->pattern = strdup (pattern);
2422
if (curr->pattern == NULL) {
2427
curr->priority = strtol (priority, &tmp_str2, 0);
2428
if (tmp_str2 && (*tmp_str2)) {
2432
max_pri = max (max_pri, curr->priority);
2438
priority_str = strtok_r (NULL, ",", &tmp_str);
2441
if (string != NULL) {
2445
if (dup_str != NULL) {
2449
if (max_pri == -1) {
2450
list_for_each_entry_safe (curr, tmp, first, list) {
2451
list_del_init (&curr->list);
2452
free (curr->pattern);
2185
2462
init (xlator_t *this)
2189
qr_conf_t *conf = NULL;
2465
int32_t ret = -1, i = 0;
2466
qr_private_t *priv = NULL;
2467
qr_conf_t *conf = NULL;
2191
2469
if (!this->children || this->children->next) {
2192
2470
gf_log (this->name, GF_LOG_ERROR,
2200
2478
"dangling volume. check volfile ");
2203
conf = CALLOC (1, sizeof (*conf));
2481
priv = CALLOC (1, sizeof (*priv));
2205
2483
gf_log (this->name, GF_LOG_ERROR,
2206
2484
"out of memory");
2489
LOCK_INIT (&priv->table.lock);
2211
2493
conf->max_file_size = 65536;
2212
2494
ret = dict_get_str (this->options, "max-file-size",
2521
conf->cache_size = QR_DEFAULT_CACHE_SIZE;
2522
ret = dict_get_str (this->options, "cache-size", &str);
2524
ret = gf_string2bytesize (str, &conf->cache_size);
2526
gf_log (this->name, GF_LOG_ERROR,
2527
"invalid cache-size value %s", str);
2533
INIT_LIST_HEAD (&conf->priority_list);
2535
if (dict_get (this->options, "priority")) {
2536
char *option_list = data_to_str (dict_get (this->options,
2538
gf_log (this->name, GF_LOG_TRACE,
2539
"option path %s", option_list);
2540
/* parse the list of pattern:priority */
2541
conf->max_pri = qr_get_priority_list (option_list,
2542
&conf->priority_list);
2544
if (conf->max_pri == -1) {
2550
priv->table.lru = CALLOC (conf->max_pri,
2551
sizeof (*priv->table.lru));
2552
if (priv->table.lru == NULL) {
2554
gf_log (this->name, GF_LOG_ERROR, "out of memory");
2558
for (i = 0; i < conf->max_pri; i++) {
2559
INIT_LIST_HEAD (&priv->table.lru[i]);
2241
this->private = conf;
2564
this->private = priv;
2243
if ((ret == -1) && conf) {
2566
if ((ret == -1) && priv) {