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

« back to all changes in this revision

Viewing changes to xlators/cluster/dht/src/dht-layout.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:
51
51
                goto out;
52
52
        }
53
53
 
 
54
        layout->type = DHT_HASH_TYPE_DM;
54
55
        layout->cnt = cnt;
55
56
        if (conf)
56
57
                layout->gen = conf->gen;
 
58
 
 
59
        layout->ref = 1;
57
60
out:
58
61
        return layout;
59
62
}
62
65
dht_layout_t *
63
66
dht_layout_get (xlator_t *this, inode_t *inode)
64
67
{
65
 
        uint64_t layout = 0;
66
 
        int      ret    = -1;
67
 
 
68
 
        ret = inode_ctx_get (inode, this, &layout);
69
 
 
70
 
        return (dht_layout_t *)(long)layout;
 
68
        dht_conf_t   *conf = NULL;
 
69
        uint64_t      layout_int = 0;
 
70
        dht_layout_t *layout = NULL;
 
71
        int           ret    = -1;
 
72
 
 
73
        conf = this->private;
 
74
        LOCK (&conf->layout_lock);
 
75
        {
 
76
                ret = inode_ctx_get (inode, this, &layout_int);
 
77
                if (ret == 0) {
 
78
                        layout = (dht_layout_t *) (unsigned long) layout_int;
 
79
                        layout->ref++;
 
80
                }
 
81
        }
 
82
        UNLOCK (&conf->layout_lock);
 
83
 
 
84
        return layout;
 
85
}
 
86
 
 
87
 
 
88
int
 
89
dht_layout_set (xlator_t *this, inode_t *inode, dht_layout_t *layout)
 
90
{
 
91
        dht_conf_t   *conf = NULL;
 
92
        int           oldret = -1;
 
93
        int           ret = 0;
 
94
        dht_layout_t *old_layout;
 
95
        uint64_t      old_layout_int;
 
96
 
 
97
        conf = this->private;
 
98
        LOCK (&conf->layout_lock);
 
99
        {
 
100
                oldret = inode_ctx_get (inode, this, &old_layout_int);
 
101
 
 
102
                layout->ref++;
 
103
                ret = inode_ctx_put (inode, this, (uint64_t) (unsigned long)
 
104
                                     layout);
 
105
        }
 
106
        UNLOCK (&conf->layout_lock);
 
107
 
 
108
        if (oldret == 0) {
 
109
                old_layout = (dht_layout_t *) (unsigned long) old_layout_int;
 
110
                dht_layout_unref (this, old_layout);
 
111
        }
 
112
 
 
113
        return ret;
 
114
}
 
115
 
 
116
 
 
117
void
 
118
dht_layout_unref (xlator_t *this, dht_layout_t *layout)
 
119
{
 
120
        dht_conf_t  *conf = NULL;
 
121
        int          ref = 0;
 
122
 
 
123
        if (layout->preset)
 
124
                return;
 
125
 
 
126
        conf = this->private;
 
127
        LOCK (&conf->layout_lock);
 
128
        {
 
129
                ref = --layout->ref;
 
130
        }
 
131
        UNLOCK (&conf->layout_lock);
 
132
 
 
133
        if (!ref)
 
134
                FREE (layout);
 
135
}
 
136
 
 
137
 
 
138
dht_layout_t *
 
139
dht_layout_ref (xlator_t *this, dht_layout_t *layout)
 
140
{
 
141
        dht_conf_t  *conf = NULL;
 
142
 
 
143
        if (layout->preset)
 
144
                return layout;
 
145
 
 
146
        conf = this->private;
 
147
        LOCK (&conf->layout_lock);
 
148
        {
 
149
                layout->ref++;
 
150
        }
 
151
        UNLOCK (&conf->layout_lock);
 
152
 
 
153
        return layout;
71
154
}
72
155
 
73
156
 
599
682
 
600
683
 
601
684
int
602
 
dht_layout_inode_set (xlator_t *this, xlator_t *subvol, inode_t *inode)
 
685
dht_layout_preset (xlator_t *this, xlator_t *subvol, inode_t *inode)
603
686
{
604
687
        dht_layout_t *layout = NULL;
605
 
        int ret = -1;
 
688
        int           ret = -1;
 
689
        dht_conf_t   *conf = NULL;
 
690
 
 
691
        conf = this->private;
606
692
 
607
693
        layout = dht_layout_for_subvol (this, subvol);
608
694
        if (!layout) {
613
699
                goto out;
614
700
        }
615
701
 
616
 
        inode_ctx_put (inode, this, (uint64_t)(long)layout);
617
 
        
 
702
        LOCK (&conf->layout_lock);
 
703
        {
 
704
                inode_ctx_put (inode, this, (uint64_t)(long)layout);
 
705
        }
 
706
        UNLOCK (&conf->layout_lock);
 
707
 
618
708
        ret = 0;
619
709
out:
620
710
        return ret;