~ubuntu-branches/ubuntu/trusty/glusterfs/trusty

« back to all changes in this revision

Viewing changes to xlators/performance/quick-read/src/quick-read.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Matthäi
  • Date: 2010-07-13 18:40:26 UTC
  • mfrom: (1.2.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100713184026-e09vy2wvcxyb2pgm
Tags: 3.0.5-1
* New upstream release.
* Merge 3.0.4-1~bpo50+1 changelog.
* Bump Standards-Version to 3.9.0 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "quick-read.h"
21
21
#include "statedump.h"
22
22
 
 
23
#define QR_DEFAULT_CACHE_SIZE 134217728 /* 128MB */
 
24
 
23
25
int32_t
24
26
qr_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
25
27
          off_t offset);
26
28
 
27
29
 
 
30
void
 
31
qr_local_free (qr_local_t *local)
 
32
{
 
33
        if (local == NULL) {
 
34
                goto out;
 
35
        }
 
36
 
 
37
        if (local->stub != NULL) {
 
38
                call_stub_destroy (local->stub);
 
39
        }
 
40
 
 
41
        if (local->path != NULL) {
 
42
                FREE (local->path);
 
43
        }
 
44
 
 
45
        FREE (local);
 
46
 
 
47
out:
 
48
        return;
 
49
}
 
50
 
 
51
 
28
52
static void
29
53
qr_loc_wipe (loc_t *loc)
30
54
{
146
170
        return;
147
171
}
148
172
 
 
173
 
 
174
static inline uint32_t
 
175
is_match (const char *path, const char *pattern)
 
176
{
 
177
        int32_t ret = 0;
 
178
 
 
179
        ret = fnmatch (pattern, path, FNM_NOESCAPE);
 
180
  
 
181
        return (ret == 0);
 
182
}
 
183
 
 
184
uint32_t
 
185
qr_get_priority (qr_conf_t *conf, const char *path)
 
186
{
 
187
        uint32_t            priority = 0;
 
188
        struct qr_priority *curr = NULL;
 
189
  
 
190
        list_for_each_entry (curr, &conf->priority_list, list) {
 
191
                if (is_match (path, curr->pattern)) 
 
192
                        priority = curr->priority;
 
193
        }
 
194
 
 
195
        return priority;
 
196
}
 
197
 
 
198
 
 
199
/* To be called with this-priv->table.lock held */
 
200
qr_inode_t *
 
201
__qr_inode_alloc (xlator_t *this, char *path, inode_t *inode)
 
202
{
 
203
        qr_inode_t    *qr_inode     = NULL;
 
204
        qr_private_t  *priv     = NULL;
 
205
        int            priority = 0;
 
206
 
 
207
        priv = this->private;
 
208
 
 
209
        qr_inode = CALLOC (1, sizeof (*qr_inode));
 
210
        if (qr_inode == NULL) {
 
211
                gf_log (this->name, GF_LOG_ERROR, "out of memory");
 
212
                goto out;
 
213
        }
 
214
 
 
215
        INIT_LIST_HEAD (&qr_inode->lru);
 
216
        
 
217
        priority = qr_get_priority (&priv->conf, path);
 
218
 
 
219
        list_add_tail (&qr_inode->lru, &priv->table.lru[priority]);
 
220
 
 
221
        qr_inode->inode = inode;
 
222
        qr_inode->priority = priority;
 
223
out:
 
224
        return qr_inode;
 
225
}
 
226
 
 
227
 
 
228
/* To be called with qr_inode->table->lock held */
 
229
void
 
230
__qr_inode_free (qr_inode_t *qr_inode)
 
231
{
 
232
        if (qr_inode == NULL) {
 
233
                goto out;
 
234
        }
 
235
 
 
236
        if (qr_inode->xattr) {
 
237
                dict_unref (qr_inode->xattr);
 
238
        }
 
239
 
 
240
        list_del (&qr_inode->lru);
 
241
 
 
242
        FREE (qr_inode);
 
243
out:
 
244
        return;
 
245
}
 
246
 
 
247
 
 
248
/* To be called with priv->table.lock held */
 
249
void
 
250
__qr_cache_prune (xlator_t *this)
 
251
{
 
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;
 
256
        int32_t           index = 0;
 
257
        uint64_t          size_to_prune = 0;
 
258
        uint64_t          size_pruned = 0;
 
259
 
 
260
        priv = this->private;
 
261
        table = &priv->table;
 
262
        conf = &priv->conf;
 
263
 
 
264
        size_to_prune = table->cache_used - conf->cache_size;
 
265
 
 
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)
 
272
                                goto done;
 
273
                }
 
274
        }
 
275
 
 
276
done:
 
277
        table->cache_used -= size_pruned;
 
278
        return;
 
279
}
 
280
 
 
281
 
 
282
/* To be called with table->lock held */
 
283
inline char
 
284
__qr_need_cache_prune (qr_conf_t *conf, qr_inode_table_t *table)
 
285
{
 
286
        return (table->cache_used > conf->cache_size);
 
287
}
 
288
 
149
289
        
150
290
int32_t
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)
154
294
{
155
 
        data_t    *content = NULL;
156
 
        qr_file_t *qr_file = NULL;
157
 
        uint64_t   value = 0;
158
 
        int        ret = -1;
159
 
        qr_conf_t *conf = NULL;
 
295
        data_t           *content  = NULL;
 
296
        qr_inode_t       *qr_inode = NULL;
 
297
        uint64_t          value    = 0;
 
298
        int               ret      = -1;
 
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;
160
303
 
161
304
        if ((op_ret == -1) || (dict == NULL)) {
162
305
                goto out;
163
306
        }
164
307
 
165
308
        conf = this->private;
 
309
        priv = this->private;
 
310
        conf = &priv->conf;
 
311
        table = &priv->table;
 
312
 
 
313
        local = frame->local;
166
314
 
167
315
        if (buf->st_size > conf->max_file_size) {
168
316
                goto out;
179
327
        }
180
328
 
181
329
        content = dict_get (dict, GLUSTERFS_CONTENT_KEY);
 
330
        if (content == NULL) {
 
331
                goto out;
 
332
        }
182
333
 
183
 
        LOCK (&inode->lock);
 
334
        LOCK (&table->lock);
184
335
        {
185
 
                ret = __inode_ctx_get (inode, this, &value);
 
336
                ret = inode_ctx_get (inode, this, &value);
186
337
                if (ret == -1) {
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) {
189
340
                                op_ret = -1;
190
341
                                op_errno = ENOMEM;
191
342
                                goto unlock;
192
343
                        }
193
344
                
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);
197
347
                        if (ret == -1) {
198
 
                                FREE (qr_file);
199
 
                                qr_file = NULL;
 
348
                                __qr_inode_free (qr_inode);
 
349
                                qr_inode = NULL;
200
350
                                op_ret = -1;
201
351
                                op_errno = EINVAL;
 
352
                                goto unlock;
202
353
                        }
203
354
                } else {
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) {
206
357
                                op_ret = -1;
207
358
                                op_errno = EINVAL;
 
359
                                goto unlock;
208
360
                        }
209
361
                }
 
362
 
 
363
                if (qr_inode->xattr) {
 
364
                        dict_unref (qr_inode->xattr);
 
365
                        qr_inode->xattr = NULL;
 
366
 
 
367
                        table->cache_used -= qr_inode->stbuf.st_size;
 
368
                }
 
369
 
 
370
                qr_inode->xattr = dict_ref (dict);
 
371
                qr_inode->stbuf = *buf;
 
372
                table->cache_used += buf->st_size;
 
373
 
 
374
                gettimeofday (&qr_inode->tv, NULL);
 
375
 
 
376
                if (__qr_need_cache_prune (conf, table)) {
 
377
                        __qr_cache_prune (this);
 
378
                }
210
379
        }
211
380
unlock:
212
 
        UNLOCK (&inode->lock);
213
 
 
214
 
        if (qr_file != NULL) {
215
 
                LOCK (&qr_file->lock);
216
 
                {
217
 
                        if (qr_file->xattr
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;
223
 
                        }
224
 
 
225
 
                        if (content) {
226
 
                                if (qr_file->xattr) {
227
 
                                        dict_unref (qr_file->xattr);
228
 
                                        qr_file->xattr = NULL;
229
 
                                }
230
 
 
231
 
                                qr_file->xattr = dict_ref (dict);
232
 
                                qr_file->stbuf = *buf;
233
 
                        }
234
 
 
235
 
                        gettimeofday (&qr_file->tv, NULL);
236
 
                }
237
 
                UNLOCK (&qr_file->lock);
238
 
        }
 
381
        UNLOCK (&table->lock);
 
382
 
239
383
 
240
384
out:
241
385
        /*
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.
244
388
         */
245
 
        STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf, dict,
246
 
                             postparent);
 
389
        QR_STACK_UNWIND (lookup, frame, op_ret, op_errno, inode, buf, dict,
 
390
                         postparent);
247
391
        return 0;
248
392
}
249
393
 
251
395
int32_t
252
396
qr_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr_req)
253
397
{
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; 
259
 
        char       cached = 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; 
 
403
        char              cached = 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;
261
408
 
262
 
        conf = this->private;
 
409
        priv = this->private;
 
410
        conf = &priv->conf;
263
411
        if (conf == NULL) {
264
412
                op_ret = -1;
265
413
                op_errno = EINVAL;
266
414
                goto unwind;
267
415
        }
268
416
 
269
 
        op_ret = inode_ctx_get (loc->inode, this, &value);
270
 
        if (op_ret == 0) {
271
 
                qr_file = (qr_file_t *)(long)value;
272
 
        }
273
 
 
274
 
        if (qr_file != NULL) {
275
 
                LOCK (&qr_file->lock);
276
 
                {
277
 
                        if (qr_file->xattr) {
278
 
                                cached = 1;
 
417
        table = &priv->table;
 
418
 
 
419
        local = CALLOC (1, sizeof (*local));
 
420
        GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, unwind, op_errno,
 
421
                                        ENOMEM);
 
422
 
 
423
        frame->local = local;
 
424
 
 
425
        local->path = strdup (loc->path);
 
426
        GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, local, unwind, op_errno,
 
427
                                        ENOMEM);
 
428
        LOCK (&table->lock);
 
429
        {
 
430
                op_ret = inode_ctx_get (loc->inode, this, &value);
 
431
                if (op_ret == 0) {
 
432
                        qr_inode = (qr_inode_t *)(long)value;
 
433
                        if (qr_inode != NULL) {
 
434
                                if (qr_inode->xattr) {
 
435
                                        cached = 1;
 
436
                                }
279
437
                        }
280
438
                }
281
 
                UNLOCK (&qr_file->lock);
282
439
        }
 
440
        UNLOCK (&table->lock);
283
441
 
284
442
        if ((xattr_req == NULL) && (conf->max_file_size > 0)) {
285
443
                new_req_dict = xattr_req = dict_new ();
324
482
        return 0;
325
483
 
326
484
unwind:
327
 
        STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, NULL, NULL, NULL,
328
 
                             NULL);
 
485
        QR_STACK_UNWIND (lookup, frame, op_ret, op_errno, NULL, NULL, NULL,
 
486
                         NULL);
329
487
 
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)
341
499
{
342
 
        uint64_t         value = 0;
343
 
        int32_t          ret = -1;
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;
349
 
        char             is_open = 0;
 
500
        uint64_t          value = 0;
 
501
        int32_t           ret = -1;
 
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;
 
507
        char              is_open = 0;
 
508
        qr_private_t     *priv = NULL;
 
509
        qr_inode_table_t *table = NULL;
 
510
 
 
511
        priv = this->private;
 
512
        table = &priv->table;
350
513
 
351
514
        local = frame->local;
352
515
        if (local != NULL) {
383
546
 
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);
387
 
                        if (ret == 0) {
388
 
                                qr_file = (qr_file_t *)(long) value;
 
549
                        LOCK (&table->lock);
 
550
                        {
 
551
                                ret = inode_ctx_del (fd->inode, this, &value);
 
552
                                if (ret == 0) {
 
553
                                        qr_inode = (qr_inode_t *)(long) value;
389
554
 
390
 
                                if (qr_file) {
391
 
                                        LOCK (&qr_file->lock);
392
 
                                        {
393
 
                                                dict_unref (qr_file->xattr);
394
 
                                                qr_file->xattr = NULL;
 
555
                                        if (qr_inode != NULL) {
 
556
                                                __qr_inode_free (qr_inode);
395
557
                                        }
396
 
                                        UNLOCK (&qr_file->lock);
397
558
                                }
398
559
                        }
 
560
                        UNLOCK (&table->lock);
399
561
                }
400
562
 
401
563
                if (!list_empty (&waiting_ops)) {
408
570
        }
409
571
out: 
410
572
        if (is_open) {
411
 
                STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd);
 
573
                QR_STACK_UNWIND (open, frame, op_ret, op_errno, fd);
412
574
        }
413
575
 
414
576
        return 0;
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)
421
583
{
422
 
        qr_file_t   *qr_file = NULL;
423
 
        int32_t      ret = -1;
424
 
        uint64_t     filep = 0;
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;
 
585
        int32_t           ret = -1;
 
586
        uint64_t          filep = 0;
 
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;
430
594
 
431
 
        conf = this->private;
 
595
        priv = this->private;
 
596
        conf = &priv->conf;
 
597
        table = &priv->table;
432
598
 
433
599
        tmp_fd_ctx = qr_fd_ctx = CALLOC (1, sizeof (*qr_fd_ctx));
434
600
        if (qr_fd_ctx == NULL) {
463
629
        local->is_open = 1;
464
630
        local->open_flags = flags; 
465
631
        frame->local = local;
466
 
        local = NULL;
467
 
 
468
 
        ret = inode_ctx_get (fd->inode, this, &filep);
469
 
        if (ret == 0) {
470
 
                qr_file = (qr_file_t *)(long) filep;
471
 
                if (qr_file) {
472
 
                        LOCK (&qr_file->lock);
473
 
                        {
474
 
                                if (qr_file->xattr) {
 
632
        LOCK (&table->lock);
 
633
        {
 
634
                ret = inode_ctx_get (fd->inode, this, &filep);
 
635
                if (ret == 0) {
 
636
                        qr_inode = (qr_inode_t *)(long) filep;
 
637
                        if (qr_inode) {
 
638
                                if (qr_inode->xattr) {
475
639
                                        content_cached = 1;
476
640
                                }
477
641
                        }
478
 
                        UNLOCK (&qr_file->lock);
479
642
                }
480
643
        }
 
644
        UNLOCK (&table->lock);
481
645
 
482
646
        if (content_cached && ((flags & O_DIRECTORY) == O_DIRECTORY)) {
483
647
                op_ret = -1;
513
677
                qr_fd_ctx_free (tmp_fd_ctx);
514
678
        }
515
679
 
516
 
        if (local != NULL) {
517
 
                FREE (local);
518
 
        }
519
 
 
520
 
        STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd);
 
680
        QR_STACK_UNWIND (open, frame, op_ret, op_errno, fd);
521
681
        return 0;
522
682
 
523
683
wind:
535
695
 
536
696
 
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)
539
699
{
540
700
        struct timeval now = {0, };
541
701
        char           need_validation = 0;
542
702
        
543
703
        gettimeofday (&now, NULL);
544
704
 
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;
547
707
 
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)
555
715
{
556
 
        qr_file_t  *qr_file = NULL;
557
 
        qr_local_t *local = NULL;
558
 
        uint64_t    value = 0;
559
 
        int32_t     ret = 0;
 
716
        qr_inode_t       *qr_inode = NULL;
 
717
        qr_local_t       *local    = NULL;
 
718
        uint64_t          value    = 0;
 
719
        int32_t           ret      = 0;
 
720
        qr_private_t     *priv     = NULL;
 
721
        qr_inode_table_t *table    = NULL;
 
722
        call_stub_t      *stub     = NULL;
560
723
 
561
724
        local = frame->local; 
562
725
        if ((local == NULL) || ((local->fd) == NULL)) {
569
732
                goto unwind;
570
733
        }
571
734
 
572
 
        ret = inode_ctx_get (local->fd->inode, this, &value);
573
 
        if (ret == -1) {
574
 
                op_ret = -1;
575
 
                op_errno = EINVAL;
576
 
                goto unwind;
577
 
        }
578
 
 
579
 
        qr_file = (qr_file_t *)(long) value;
580
 
        if (qr_file == NULL) {
581
 
                op_ret = -1;
582
 
                op_errno = EINVAL;
583
 
                goto unwind;
584
 
        }
585
 
 
586
 
        LOCK (&qr_file->lock);
 
735
        priv = this->private;
 
736
        table = &priv->table;
 
737
 
 
738
        LOCK (&table->lock);
587
739
        {
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;
593
 
                }
594
 
 
595
 
                gettimeofday (&qr_file->tv, NULL);
 
740
                ret = inode_ctx_get (local->fd->inode, this, &value);
 
741
                if (ret == 0) {
 
742
                        qr_inode = (qr_inode_t *)(long) value;
 
743
                }
 
744
 
 
745
                if (qr_inode != NULL) {
 
746
                        gettimeofday (&qr_inode->tv, NULL);
 
747
 
 
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);
 
753
                        }
 
754
                }
596
755
        }
597
 
        UNLOCK (&qr_file->lock);
598
 
 
599
 
        frame->local = NULL;
600
 
 
601
 
        call_resume (local->stub);
602
 
 
603
 
        FREE (local);
 
756
        UNLOCK (&table->lock);
 
757
 
 
758
        stub = local->stub;
 
759
        local->stub = NULL;
 
760
        local->just_validated = 1;
 
761
        call_resume (stub);
 
762
 
604
763
        return 0;
605
764
 
606
765
unwind:
607
 
        if (local && local->stub) {
608
 
                call_stub_destroy (local->stub);
609
 
                local->stub = NULL;
610
 
        }
611
 
 
612
766
        /* this is actually unwind of readv */
613
 
        STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, NULL, -1, NULL,
614
 
                             NULL);
 
767
        QR_STACK_UNWIND (readv, frame, op_ret, op_errno, NULL, -1, NULL,
 
768
                         NULL);
615
769
        return 0;
616
770
}
617
771
 
738
892
              int32_t op_errno, struct iovec *vector, int32_t count,
739
893
              struct stat *stbuf, struct iobref *iobref)
740
894
{
741
 
        STACK_UNWIND_STRICT (readv, frame, op_ret, op_errno, vector, count,
742
 
                             stbuf, iobref);
 
895
        QR_STACK_UNWIND (readv, frame, op_ret, op_errno, vector, count,
 
896
                         stbuf, iobref);
743
897
        return 0;
744
898
}
745
899
 
758
912
qr_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
759
913
          off_t offset)
760
914
{
761
 
        qr_file_t         *file = NULL;
 
915
        qr_inode_t        *qr_inode = NULL;
 
916
        qr_local_t        *local = NULL;
 
917
        char               just_validated = 0;
762
918
        int32_t            ret = -1, op_ret = -1, op_errno = -1;
763
919
        uint64_t           value = 0;
764
920
        int                count = -1, flags = 0, i = 0;
778
934
        off_t              start = 0, end = 0;
779
935
        size_t             len = 0;
780
936
        struct iobuf_pool *iobuf_pool = NULL; 
 
937
        qr_private_t      *priv = NULL;
 
938
        qr_inode_table_t  *table = NULL;
781
939
 
782
940
        op_ret = 0;
783
 
        conf = this->private;
 
941
 
 
942
        priv = this->private;
 
943
        conf = &priv->conf;
 
944
        table = &priv->table;
 
945
 
 
946
        local = frame->local;
 
947
        if (local != NULL) {
 
948
                just_validated = local->just_validated;
 
949
                FREE (local);
 
950
                frame->local = NULL;
 
951
        }
784
952
 
785
953
        ret = fd_ctx_get (fd, this, &value);
786
954
        if (ret == 0) {
794
962
 
795
963
        iobuf_pool = this->ctx->iobuf_pool;
796
964
 
797
 
        ret = inode_ctx_get (fd->inode, this, &value);
798
 
        if (ret == 0) {
799
 
                file = (qr_file_t *)(long)value;
800
 
                if (file) {
801
 
                        LOCK (&file->lock);
802
 
                        {
803
 
                                if (file->xattr){
804
 
                                        if (qr_need_validation (conf,file)) {
 
965
        LOCK (&table->lock);
 
966
        {
 
967
                ret = inode_ctx_get (fd->inode, this, &value);
 
968
                if (ret == 0) {
 
969
                        qr_inode = (qr_inode_t *)(long)value;
 
970
                        if (qr_inode) {
 
971
                                if (qr_inode->xattr){
 
972
                                        if (!just_validated
 
973
                                            && qr_need_validation (conf,
 
974
                                                                   qr_inode)) {
805
975
                                                need_validation = 1;
806
976
                                                goto unlock;
807
977
                                        }
808
978
 
809
 
                                        content = dict_get (file->xattr,
 
979
                                        content = dict_get (qr_inode->xattr,
810
980
                                                            GLUSTERFS_CONTENT_KEY);
811
981
 
812
 
                                        
813
 
                                        stbuf = file->stbuf;
 
982
                                        stbuf = qr_inode->stbuf;
814
983
                                        content_cached = 1;
 
984
                                        list_move_tail (&qr_inode->lru,
 
985
                                                        &table->lru[qr_inode->priority]);
 
986
 
815
987
 
816
988
                                        if (offset > content->len) {
817
989
                                                op_ret = 0;
887
1059
                                        }
888
1060
                                }
889
1061
                        }
890
 
                unlock:
891
 
                        UNLOCK (&file->lock);
892
1062
                }
893
1063
        }
 
1064
unlock:
 
1065
        UNLOCK (&table->lock);
894
1066
 
895
1067
out:
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);
899
1071
 
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)
995
1167
{
996
 
        STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, prebuf, postbuf);
 
1168
        QR_STACK_UNWIND (writev, frame, op_ret, op_errno, prebuf, postbuf);
997
1169
        return 0;
998
1170
}
999
1171
 
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)
1016
1188
{
1017
 
        uint64_t     value = 0;
1018
 
        int          flags = 0;
1019
 
        call_stub_t *stub = NULL; 
1020
 
        char        *path = NULL;
1021
 
        loc_t        loc = {0, };
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; 
 
1189
        uint64_t          value = 0;
 
1190
        int               flags = 0;
 
1191
        call_stub_t      *stub = NULL; 
 
1192
        char             *path = NULL;
 
1193
        loc_t             loc = {0, };
 
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;
 
1200
 
 
1201
        priv = this->private;
 
1202
        table = &priv->table;
1026
1203
        
1027
1204
        ret = fd_ctx_get (fd, this, &value);
1028
 
 
1029
1205
        if (ret == 0) {
1030
1206
                qr_fd_ctx = (qr_fd_ctx_t *)(long) value;
1031
1207
        }
1032
1208
 
1033
 
        ret = inode_ctx_get (fd->inode, this, &value);
1034
 
        if (ret == 0) {
1035
 
                qr_file = (qr_file_t *)(long)value;
1036
 
        }
1037
 
 
1038
 
        if (qr_file) {
1039
 
                LOCK (&qr_file->lock);
1040
 
                {
1041
 
                        if (qr_file->xattr) {
1042
 
                                dict_unref (qr_file->xattr);
1043
 
                                qr_file->xattr = NULL;
 
1209
        LOCK (&table->lock);
 
1210
        {
 
1211
                ret = inode_ctx_get (fd->inode, this, &value);
 
1212
                if (ret == 0) {
 
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);
1044
1217
                        }
1045
1218
                }
1046
 
                UNLOCK (&qr_file->lock);
1047
1219
        }
 
1220
        UNLOCK (&table->lock);
1048
1221
            
1049
1222
        if (qr_fd_ctx) {
1050
1223
                LOCK (&qr_fd_ctx->lock);
1084
1257
 
1085
1258
out:
1086
1259
        if (need_unwind) {
1087
 
                STACK_UNWIND_STRICT (writev, frame, op_ret, op_errno, NULL,
1088
 
                                     NULL);
 
1260
                QR_STACK_UNWIND (writev, frame, op_ret, op_errno, NULL,
 
1261
                                 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,
1109
1282
 
1110
1283
int32_t
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)
1113
1286
{
1114
 
        STACK_UNWIND_STRICT (fstat, frame, op_ret, op_errno, buf);
 
1287
        QR_STACK_UNWIND (fstat, frame, op_ret, op_errno, buf);
1115
1288
        return 0;
1116
1289
}
1117
1290
 
1179
1352
 
1180
1353
out:
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)
1209
1382
{
1210
 
        STACK_UNWIND_STRICT (fsetattr, frame, op_ret, op_errno, preop, postop);
 
1383
        QR_STACK_UNWIND (fsetattr, frame, op_ret, op_errno, preop, postop);
1211
1384
        return 0;
1212
1385
}
1213
1386
 
1278
1451
 
1279
1452
out:
1280
1453
        if (need_unwind) {
1281
 
                STACK_UNWIND_STRICT (fsetattr, frame, op_ret, op_errno, NULL,
1282
 
                                     NULL);
 
1454
                QR_STACK_UNWIND (fsetattr, frame, op_ret, op_errno, NULL,
 
1455
                                 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,
1305
1478
qr_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1306
1479
                  int32_t op_ret, int32_t op_errno)
1307
1480
{
1308
 
        STACK_UNWIND_STRICT (fsetxattr, frame, op_ret, op_errno);
 
1481
        QR_STACK_UNWIND (fsetxattr, frame, op_ret, op_errno);
1309
1482
        return 0;
1310
1483
}
1311
1484
 
1376
1549
 
1377
1550
out:
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,
1401
1574
 
1402
1575
int32_t
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)
1405
1578
{
1406
 
        STACK_UNWIND_STRICT (fgetxattr, frame, op_ret, op_errno, dict);
 
1579
        QR_STACK_UNWIND (fgetxattr, frame, op_ret, op_errno, dict);
1407
1580
        return 0;
1408
1581
}
1409
1582
 
1478
1651
 
1479
1652
out:
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);
1503
1676
qr_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
1504
1677
              int32_t op_errno)
1505
1678
{
1506
 
        STACK_UNWIND_STRICT (flush, frame, op_ret, op_errno);
 
1679
        QR_STACK_UNWIND (flush, frame, op_ret, op_errno);
1507
1680
        return 0;
1508
1681
}
1509
1682
 
1561
1734
        }
1562
1735
 
1563
1736
        if (need_unwind) {
1564
 
                STACK_UNWIND_STRICT (flush, frame, op_ret, op_errno);
 
1737
                QR_STACK_UNWIND (flush, frame, op_ret, op_errno);
1565
1738
        } else if (can_wind) {
1566
1739
                STACK_WIND (frame, qr_flush_cbk, FIRST_CHILD (this),
1567
1740
                            FIRST_CHILD (this)->fops->flush, fd);
1575
1748
qr_fentrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
1576
1749
                 int32_t op_ret, int32_t op_errno)
1577
1750
{
1578
 
        STACK_UNWIND_STRICT (fentrylk, frame, op_ret, op_errno);
 
1751
        QR_STACK_UNWIND (fentrylk, frame, op_ret, op_errno);
1579
1752
        return 0;
1580
1753
}
1581
1754
 
1648
1821
 
1649
1822
out:
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,
1675
1848
                 int32_t op_ret, int32_t op_errno)
1676
1849
 
1677
1850
{
1678
 
        STACK_UNWIND_STRICT (finodelk, frame, op_ret, op_errno);
 
1851
        QR_STACK_UNWIND (finodelk, frame, op_ret, op_errno);
1679
1852
        return 0;
1680
1853
}
1681
1854
 
1747
1920
 
1748
1921
out:
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)
1775
1948
{
1776
 
        STACK_UNWIND_STRICT (fsync, frame, op_ret, op_errno, prebuf, postbuf);
 
1949
        QR_STACK_UNWIND (fsync, frame, op_ret, op_errno, prebuf, postbuf);
1777
1950
        return 0;
1778
1951
}
1779
1952
 
1840
2013
 
1841
2014
out:
1842
2015
        if (need_unwind) {
1843
 
                STACK_UNWIND_STRICT (fsync, frame, op_ret, op_errno, NULL,
1844
 
                                     NULL);
 
2016
                QR_STACK_UNWIND (fsync, frame, op_ret, op_errno, NULL,
 
2017
                                 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)
1870
2043
{
1871
 
        int32_t     ret = 0;
1872
 
        uint64_t    value = 0;
1873
 
        qr_file_t  *qr_file = NULL;
1874
 
        qr_local_t *local = NULL;
 
2044
        int32_t           ret     = 0;
 
2045
        uint64_t          value   = 0;
 
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;
1875
2050
 
1876
2051
        if (op_ret == -1) {
1877
2052
                goto out;
1878
2053
        }
1879
2054
 
 
2055
        priv = this->private;
 
2056
        table = &priv->table;
 
2057
 
1880
2058
        local = frame->local;
1881
2059
        if ((local == NULL) || (local->fd == NULL)
1882
2060
            || (local->fd->inode == NULL)) {
1885
2063
                goto out;
1886
2064
        }
1887
2065
 
1888
 
        ret = inode_ctx_get (local->fd->inode, this, &value);
1889
 
        if (ret == 0) {
1890
 
                qr_file = (qr_file_t *)(long) value;
 
2066
        LOCK (&table->lock);
 
2067
        {
 
2068
                ret = inode_ctx_get (local->fd->inode, this, &value);
 
2069
                if (ret == 0) {
 
2070
                        qr_inode = (qr_inode_t *)(long) value;
1891
2071
 
1892
 
                if (qr_file) {
1893
 
                        LOCK (&qr_file->lock);
1894
 
                        {
1895
 
                                if (qr_file->stbuf.st_size != postbuf->st_size)
 
2072
                        if (qr_inode) {
 
2073
                                if (qr_inode->stbuf.st_size != postbuf->st_size)
1896
2074
                                {
1897
 
                                        dict_unref (qr_file->xattr);
1898
 
                                        qr_file->xattr = NULL;
 
2075
                                        inode_ctx_del (local->fd->inode, this,
 
2076
                                                       NULL);
 
2077
                                        __qr_inode_free (qr_inode);
1899
2078
                                }
1900
2079
                        }
1901
 
                        UNLOCK (&qr_file->lock);
1902
2080
                }
1903
2081
        }
 
2082
        UNLOCK (&table->lock);
1904
2083
 
1905
2084
out:
1906
 
        STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, prebuf,
1907
 
                             postbuf);
 
2085
        QR_STACK_UNWIND (ftruncate, frame, op_ret, op_errno, prebuf,
 
2086
                         postbuf);
1908
2087
        return 0;
1909
2088
}
1910
2089
 
1986
2165
 
1987
2166
out:
1988
2167
        if (need_unwind) {
1989
 
                STACK_UNWIND_STRICT (ftruncate, frame, op_ret, op_errno, NULL,
1990
 
                                     NULL);
 
2168
                QR_STACK_UNWIND (ftruncate, frame, op_ret, op_errno, NULL,
 
2169
                                 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)
2014
2193
{
2015
 
        STACK_UNWIND_STRICT (lk, frame, op_ret, op_errno, lock);
 
2194
        QR_STACK_UNWIND (lk, frame, op_ret, op_errno, lock);
2016
2195
        return 0;
2017
2196
}
2018
2197
 
2083
2262
 
2084
2263
out:
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);
2126
2305
int32_t
2127
2306
qr_forget (xlator_t *this, inode_t *inode)
2128
2307
{
2129
 
        qr_file_t *qr_file = NULL;
2130
 
        uint64_t   value = 0;
2131
 
        int32_t    ret = -1;
2132
 
 
2133
 
        ret = inode_ctx_del (inode, this, &value);
2134
 
        if (ret == 0) {
2135
 
                qr_file = (qr_file_t *)(long) value;
2136
 
                if (qr_file) {
2137
 
                        LOCK (&qr_file->lock);
2138
 
                        {
2139
 
                                if (qr_file->xattr) {
2140
 
                                        dict_unref (qr_file->xattr);
2141
 
                                        qr_file->xattr = NULL;
2142
 
                                }
2143
 
                        }
2144
 
                        UNLOCK (&qr_file->lock);
 
2308
        qr_inode_t    *qr_inode = NULL;
 
2309
        uint64_t      value = 0;
 
2310
        int32_t       ret = -1;
 
2311
        qr_private_t *priv = NULL;
 
2312
 
 
2313
        priv = this->private;
 
2314
 
 
2315
        LOCK (&priv->table.lock);
 
2316
        {
 
2317
                ret = inode_ctx_del (inode, this, &value);
 
2318
                if (ret == 0) {
 
2319
                        qr_inode = (qr_inode_t *)(long) value;
 
2320
                        __qr_inode_free (qr_inode);
2145
2321
                }
2146
 
                
2147
 
                FREE (qr_file);
2148
2322
        }
 
2323
        UNLOCK (&priv->table.lock);
2149
2324
 
2150
2325
        return 0;
2151
2326
}
2153
2328
int
2154
2329
qr_priv_dump (xlator_t *this)
2155
2330
{
2156
 
        qr_conf_t       *conf = NULL;
 
2331
        qr_conf_t      *conf = NULL;
2157
2332
        char            key[GF_DUMP_MAX_BUF_LEN];
2158
2333
        char            key_prefix[GF_DUMP_MAX_BUF_LEN];
 
2334
        qr_private_t   *priv = NULL;
2159
2335
 
2160
2336
        if (!this)
2161
2337
                return -1;
2162
2338
 
2163
 
        conf = this->private;
 
2339
        priv = this->private;
 
2340
        conf = &priv->conf;
2164
2341
        if (!conf) {
2165
2342
                gf_log (this->name, GF_LOG_WARNING,
2166
2343
                        "conf null in xlator");
2181
2358
        return 0;
2182
2359
}
2183
2360
 
 
2361
 
 
2362
int32_t
 
2363
qr_get_priority_list (const char *opt_str, struct list_head *first)
 
2364
{
 
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;
 
2375
 
 
2376
        string = strdup (opt_str);
 
2377
        if (string == NULL) {
 
2378
                max_pri = -1;
 
2379
                goto out;
 
2380
        }
 
2381
                
 
2382
        /* Get the pattern for cache priority. 
 
2383
         * "option priority *.jpg:1,abc*:2" etc 
 
2384
         */
 
2385
        /* TODO: inode_lru in table is statically hard-coded to 5, 
 
2386
         * should be changed to run-time configuration 
 
2387
         */
 
2388
        priority_str = strtok_r (string, ",", &tmp_str);
 
2389
        while (priority_str) {
 
2390
                curr = CALLOC (1, sizeof (*curr));
 
2391
                if (curr == NULL) {
 
2392
                        max_pri = -1;
 
2393
                        goto out;
 
2394
                }
 
2395
 
 
2396
                list_add_tail (&curr->list, first);
 
2397
 
 
2398
                dup_str = strdup (priority_str);
 
2399
                if (dup_str == NULL) {
 
2400
                        max_pri = -1;
 
2401
                        goto out;
 
2402
                }
 
2403
 
 
2404
                pattern = strtok_r (dup_str, ":", &tmp_str1);
 
2405
                if (!pattern) {
 
2406
                        max_pri = -1;
 
2407
                        goto out;
 
2408
                }
 
2409
 
 
2410
                priority = strtok_r (NULL, ":", &tmp_str1);
 
2411
                if (!priority) {
 
2412
                        max_pri = -1;
 
2413
                        goto out;
 
2414
                }
 
2415
 
 
2416
                gf_log ("quick-read", GF_LOG_TRACE,
 
2417
                        "quick-read priority : pattern %s : priority %s",
 
2418
                        pattern,
 
2419
                        priority);
 
2420
 
 
2421
                curr->pattern = strdup (pattern);
 
2422
                if (curr->pattern == NULL) {
 
2423
                        max_pri = -1;
 
2424
                        goto out;
 
2425
                }
 
2426
 
 
2427
                curr->priority = strtol (priority, &tmp_str2, 0);
 
2428
                if (tmp_str2 && (*tmp_str2)) {
 
2429
                        max_pri = -1;
 
2430
                        goto out;
 
2431
                } else {
 
2432
                        max_pri = max (max_pri, curr->priority);
 
2433
                }
 
2434
 
 
2435
                free (dup_str);
 
2436
                dup_str = NULL;
 
2437
 
 
2438
                priority_str = strtok_r (NULL, ",", &tmp_str);
 
2439
        }
 
2440
out:
 
2441
        if (string != NULL) {
 
2442
                free (string);
 
2443
        }
 
2444
 
 
2445
        if (dup_str != NULL) {
 
2446
                free (dup_str);
 
2447
        }
 
2448
 
 
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);
 
2453
                        free (curr);
 
2454
                }
 
2455
        }
 
2456
 
 
2457
        return max_pri;
 
2458
}
 
2459
 
 
2460
 
2184
2461
int32_t 
2185
2462
init (xlator_t *this)
2186
2463
{
2187
 
        char      *str = NULL;
2188
 
        int32_t    ret = -1;
2189
 
        qr_conf_t *conf = NULL;
 
2464
        char         *str  = NULL;
 
2465
        int32_t       ret  = -1, i = 0;
 
2466
        qr_private_t *priv = NULL;
 
2467
        qr_conf_t    *conf = NULL;
2190
2468
 
2191
2469
        if (!this->children || this->children->next) {
2192
2470
                gf_log (this->name, GF_LOG_ERROR,
2200
2478
                        "dangling volume. check volfile ");
2201
2479
        }
2202
2480
 
2203
 
        conf = CALLOC (1, sizeof (*conf));
2204
 
        if (conf == NULL) {
 
2481
        priv = CALLOC (1, sizeof (*priv));
 
2482
        if (priv == NULL) {
2205
2483
                gf_log (this->name, GF_LOG_ERROR,
2206
2484
                        "out of memory");
2207
2485
                ret = -1;
2208
2486
                goto out;
2209
2487
        }
2210
2488
 
 
2489
        LOCK_INIT (&priv->table.lock);
 
2490
 
 
2491
        conf = &priv->conf;
 
2492
 
2211
2493
        conf->max_file_size = 65536;
2212
2494
        ret = dict_get_str (this->options, "max-file-size", 
2213
2495
                            &str);
2236
2518
                } 
2237
2519
        }
2238
2520
 
 
2521
        conf->cache_size = QR_DEFAULT_CACHE_SIZE;
 
2522
        ret = dict_get_str (this->options, "cache-size", &str);
 
2523
        if (ret == 0) {
 
2524
                ret = gf_string2bytesize (str, &conf->cache_size);
 
2525
                if (ret != 0) {
 
2526
                        gf_log (this->name, GF_LOG_ERROR,
 
2527
                                "invalid cache-size value %s", str);
 
2528
                        ret = -1;
 
2529
                        goto out;
 
2530
                } 
 
2531
        }
 
2532
 
 
2533
        INIT_LIST_HEAD (&conf->priority_list);
 
2534
        conf->max_pri = 1;
 
2535
        if (dict_get (this->options, "priority")) {
 
2536
                char *option_list = data_to_str (dict_get (this->options, 
 
2537
                                                           "priority"));
 
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);
 
2543
    
 
2544
                if (conf->max_pri == -1) {
 
2545
                        goto out;
 
2546
                }
 
2547
                conf->max_pri ++;
 
2548
        }
 
2549
 
 
2550
        priv->table.lru = CALLOC (conf->max_pri,
 
2551
                                  sizeof (*priv->table.lru));
 
2552
        if (priv->table.lru == NULL) {
 
2553
                ret = -1;
 
2554
                gf_log (this->name, GF_LOG_ERROR, "out of memory");
 
2555
                goto out;
 
2556
        }
 
2557
 
 
2558
        for (i = 0; i < conf->max_pri; i++) {
 
2559
                INIT_LIST_HEAD (&priv->table.lru[i]);
 
2560
        }
 
2561
 
2239
2562
        ret = 0;
2240
2563
 
2241
 
        this->private = conf;
 
2564
        this->private = priv;
2242
2565
out:
2243
 
        if ((ret == -1) && conf) {
2244
 
                FREE (conf);
 
2566
        if ((ret == -1) && priv) {
 
2567
                FREE (priv);
2245
2568
        }
2246
2569
 
2247
2570
        return ret;
2297
2620
          .min  = 0,
2298
2621
          .max  = 1 * GF_UNIT_KB * 1000,
2299
2622
        },
 
2623
        { .key  = {"priority"}, 
 
2624
          .type = GF_OPTION_TYPE_ANY 
 
2625
        },
 
2626
        { .key  = {"cache-size"},
 
2627
          .type = GF_OPTION_TYPE_SIZET,
 
2628
          .min  = 0,
 
2629
          .max  = 6 * GF_UNIT_GB,
 
2630
        },
2300
2631
};