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

« back to all changes in this revision

Viewing changes to libglusterfs/src/xlator.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Matthäi
  • Date: 2010-02-09 18:53:10 UTC
  • mfrom: (1.2.4 upstream) (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100209185310-ww8p82lsbosorg2u
* New upstream release.
* Uploading to unstable.
* Bump Standards-Version to 3.8.4 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
        SET_DEFAULT_FOP (symlink);
67
67
        SET_DEFAULT_FOP (rename);
68
68
        SET_DEFAULT_FOP (link);
69
 
        SET_DEFAULT_FOP (chmod);
70
 
        SET_DEFAULT_FOP (chown);
71
69
        SET_DEFAULT_FOP (truncate);
72
 
        SET_DEFAULT_FOP (utimens);
73
70
        SET_DEFAULT_FOP (readv);
74
71
        SET_DEFAULT_FOP (writev);
75
72
        SET_DEFAULT_FOP (statfs);
82
79
        SET_DEFAULT_FOP (removexattr);
83
80
        SET_DEFAULT_FOP (opendir);
84
81
        SET_DEFAULT_FOP (readdir);
 
82
        SET_DEFAULT_FOP (readdirp);
85
83
        SET_DEFAULT_FOP (fsyncdir);
86
84
        SET_DEFAULT_FOP (access);
87
85
        SET_DEFAULT_FOP (ftruncate);
92
90
        SET_DEFAULT_FOP (entrylk);
93
91
        SET_DEFAULT_FOP (fentrylk);
94
92
        SET_DEFAULT_FOP (lookup);
95
 
        SET_DEFAULT_FOP (fchown);
96
 
        SET_DEFAULT_FOP (fchmod);
97
93
        SET_DEFAULT_FOP (setdents);
98
94
        SET_DEFAULT_FOP (getdents);
99
95
        SET_DEFAULT_FOP (checksum);
 
96
        SET_DEFAULT_FOP (rchecksum);
100
97
        SET_DEFAULT_FOP (xattrop);
101
98
        SET_DEFAULT_FOP (fxattrop);
102
99
        SET_DEFAULT_FOP (lock_notify);
103
100
        SET_DEFAULT_FOP (lock_fnotify);
104
 
        
 
101
        SET_DEFAULT_FOP (setattr);
 
102
        SET_DEFAULT_FOP (fsetattr);
 
103
 
 
104
        SET_DEFAULT_MOP (log);
105
105
        SET_DEFAULT_MOP (stats);
106
106
 
107
107
        SET_DEFAULT_CBK (release);
246
246
        switch (opt->type) {
247
247
        case GF_OPTION_TYPE_PATH:
248
248
        {
249
 
                        /* Make sure the given path is valid */
 
249
                if (strstr (pair->value->data, "../")) {
 
250
                        gf_log (xl->name, GF_LOG_ERROR,
 
251
                                "invalid path given '%s'",
 
252
                                pair->value->data);
 
253
                        ret = -1;
 
254
                        goto out;
 
255
                }
 
256
 
 
257
                /* Make sure the given path is valid */
250
258
                if (pair->value->data[0] != '/') {
251
259
                        gf_log (xl->name, GF_LOG_WARNING,
252
260
                                "option %s %s: '%s' is not an "
384
392
                    || ((i < ZR_OPTION_MAX_ARRAY_SIZE) 
385
393
                        && (!opt->value[i]))) {
386
394
                        /* enter here only if
387
 
                         * 1. reached end of opt->value array and haven't validated input
 
395
                         * 1. reached end of opt->value array and haven't 
 
396
                         *    validated input
388
397
                         *                      OR
389
 
                         * 2. valid input list is less than ZR_OPTION_MAX_ARRAY_SIZE and
390
 
                         *    input has not matched all possible input values.
 
398
                         * 2. valid input list is less than 
 
399
                         *    ZR_OPTION_MAX_ARRAY_SIZE and input has not 
 
400
                         *    matched all possible input values.
391
401
                         */
392
402
                        char given_array[4096] = {0,};
393
403
                        for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) &&
431
441
                ret = 0;
432
442
        }
433
443
        break;
 
444
        case GF_OPTION_TYPE_PERCENT_OR_SIZET:
 
445
        {
 
446
                uint32_t percent = 0;
 
447
                uint64_t input_size = 0;
 
448
                
 
449
                /* Check if the value is valid percentage */
 
450
                if (gf_string2percent (pair->value->data,
 
451
                                       &percent) == 0) {
 
452
                        if (percent > 100) {
 
453
                                gf_log (xl->name, GF_LOG_DEBUG,
 
454
                                        "value given was greater than 100, "
 
455
                                        "assuming this is actually a size");
 
456
                                if (gf_string2bytesize (pair->value->data,
 
457
                                                        &input_size) == 0) {
 
458
                                        /* Check the range */
 
459
                                        if ((opt->min == 0) && 
 
460
                                            (opt->max == 0)) {
 
461
                                                gf_log (xl->name, GF_LOG_DEBUG,
 
462
                                                        "no range check "
 
463
                                                        "required for "
 
464
                                                        "'option %s %s'",
 
465
                                                        pair->key, 
 
466
                                                        pair->value->data);
 
467
                                                // It is a size
 
468
                                                ret = 0;
 
469
                                                goto out;
 
470
                                        }
 
471
                                        if ((input_size < opt->min) ||
 
472
                                            (input_size > opt->max)) {
 
473
                                                gf_log (xl->name, GF_LOG_ERROR,
 
474
                                                        "'%"PRId64"' in "
 
475
                                                        "'option %s %s' is out"
 
476
                                                        " of range [%"PRId64""
 
477
                                                        "- %"PRId64"]",
 
478
                                                        input_size, pair->key,
 
479
                                                        pair->value->data,
 
480
                                                        opt->min, opt->max);
 
481
                                        }
 
482
                                        // It is a size
 
483
                                        ret = 0;
 
484
                                        goto out;
 
485
                                } else {
 
486
                                        // It's not a percent or size
 
487
                                        gf_log (xl->name, GF_LOG_ERROR,
 
488
                                        "invalid number format \"%s\" "
 
489
                                        "in \"option %s\"",
 
490
                                        pair->value->data, pair->key);
 
491
                                }
 
492
 
 
493
                        }
 
494
                        // It is a percent
 
495
                        ret = 0;
 
496
                        goto out;
 
497
                } else {
 
498
                        if (gf_string2bytesize (pair->value->data,
 
499
                                                &input_size) == 0) {
 
500
                                /* Check the range */
 
501
                                if ((opt->min == 0) && (opt->max == 0)) {
 
502
                                        gf_log (xl->name, GF_LOG_DEBUG,
 
503
                                                "no range check required for "
 
504
                                                "'option %s %s'",
 
505
                                                pair->key, pair->value->data);
 
506
                                        // It is a size
 
507
                                        ret = 0;
 
508
                                        goto out;
 
509
                                }
 
510
                                if ((input_size < opt->min) ||
 
511
                                    (input_size > opt->max)) {
 
512
                                        gf_log (xl->name, GF_LOG_ERROR,
 
513
                                                "'%"PRId64"' in 'option %s %s'"
 
514
                                                " is out of range [%"PRId64" -"
 
515
                                                " %"PRId64"]",
 
516
                                                input_size, pair->key,
 
517
                                                pair->value->data,
 
518
                                                opt->min, opt->max);
 
519
                                }
 
520
                        } else {
 
521
                                // It's not a percent or size
 
522
                                gf_log (xl->name, GF_LOG_ERROR,
 
523
                                        "invalid number format \"%s\" "
 
524
                                        "in \"option %s\"",
 
525
                                        pair->value->data, pair->key);
 
526
                        }
 
527
                        //It is a size
 
528
                        ret = 0;
 
529
                        goto out;
 
530
                }
 
531
 
 
532
        }
 
533
        break;
434
534
        case GF_OPTION_TYPE_TIME:
435
535
        {
436
536
                uint32_t input_time = 0;
578
678
xlator_set_type (xlator_t *xl,
579
679
                 const char *type)
580
680
{
 
681
        int   ret = 0;
581
682
        char *name = NULL;
582
683
        void *handle = NULL;
583
684
        volume_opt_list_t *vol_opt = NULL;
589
690
 
590
691
        xl->type = strdup (type);
591
692
 
592
 
        asprintf (&name, "%s/%s.so", XLATORDIR, type);
 
693
        ret = asprintf (&name, "%s/%s.so", XLATORDIR, type);
 
694
        if (-1 == ret) {
 
695
                gf_log ("xlator", GF_LOG_ERROR, "asprintf failed");
 
696
                return -1;
 
697
        }
593
698
 
594
699
        gf_log ("xlator", GF_LOG_TRACE, "attempt to load file %s", name);
595
700
 
634
739
                        "dlsym(notify) on %s -- neglecting", dlerror ());
635
740
        }
636
741
 
 
742
        if (!(xl->dumpops = dlsym (handle, "dumpops"))) {
 
743
                gf_log ("xlator", GF_LOG_DEBUG,
 
744
                        "dlsym(dumpops) on %s -- neglecting", dlerror ());
 
745
        }
 
746
 
637
747
        INIT_LIST_HEAD (&xl->volume_options);
638
748
 
639
749
        vol_opt = CALLOC (1, sizeof (volume_opt_list_t));
705
815
static int32_t
706
816
xlator_init_rec (xlator_t *xl)
707
817
{
708
 
        xlator_list_t *trav = NULL;
 
818
        xlator_t *trav = NULL;
709
819
        int32_t ret = 0;
710
820
 
711
821
        if (xl == NULL) {
713
823
                return 0;
714
824
        }
715
825
 
716
 
        trav = xl->children;
717
 
 
718
 
        while (trav) {
719
 
                ret = 0;
720
 
                ret = xlator_init_rec (trav->xlator);
721
 
                if (ret != 0)
722
 
                        break;
723
 
                gf_log (trav->xlator->name, GF_LOG_TRACE,
724
 
                        "Initialization done");
725
 
                trav = trav->next;
726
 
        }
727
 
 
728
 
        if (!ret && !xl->ready) {
 
826
        trav = xl;
 
827
        while (trav->prev)
 
828
                trav = trav->prev;
 
829
 
 
830
        while (trav) {
729
831
                ret = -1;
730
 
                if (xl->init) {
731
 
                        ret = xl->init (xl);
 
832
                if (trav->init && !trav->ready) {
 
833
                        ret = xlator_init (trav);
732
834
                        if (ret) {
733
 
                                gf_log ("xlator", GF_LOG_ERROR,
 
835
                                gf_log (trav->name, GF_LOG_ERROR,
734
836
                                        "Initialization of volume '%s' failed,"
735
837
                                        " review your volfile again",
736
 
                                        xl->name);
 
838
                                        trav->name);
 
839
                                break;
737
840
                        } else {
738
 
                                xl->init_succeeded = 1;
 
841
                                trav->init_succeeded = 1;
739
842
                        }
740
843
                } else {
741
 
                        gf_log (xl->name, GF_LOG_DEBUG, "No init() found");
 
844
                        gf_log (trav->name, GF_LOG_DEBUG, "No init() found");
742
845
                }
743
846
                /* This 'xl' is checked */
744
 
                xl->ready = 1;
 
847
                trav->ready = 1;
 
848
                trav = trav->next;
745
849
        }
746
850
 
747
851
        return ret;
807
911
}
808
912
 
809
913
 
 
914
int
 
915
xlator_notify (xlator_t *xl, int event, void *data, ...)
 
916
{
 
917
        xlator_t *old_THIS = NULL;
 
918
        int       ret = 0;
 
919
 
 
920
        old_THIS = THIS;
 
921
        THIS = xl;
 
922
 
 
923
        ret = xl->notify (xl, event, data);
 
924
 
 
925
        THIS = old_THIS;
 
926
 
 
927
        return ret;
 
928
}
 
929
 
 
930
 
 
931
int
 
932
xlator_init (xlator_t *xl)
 
933
{
 
934
        xlator_t *old_THIS = NULL;
 
935
        int       ret = 0;
 
936
 
 
937
        old_THIS = THIS;
 
938
        THIS = xl;
 
939
 
 
940
        ret = xl->init (xl);
 
941
 
 
942
        THIS = old_THIS;
 
943
 
 
944
        return ret;
 
945
}
 
946
 
 
947
 
810
948
void
811
949
xlator_tree_fini (xlator_t *xl)
812
950
{