diff options
author | Anand V. Avati <avati@blackhole.gluster.com> | 2009-10-16 07:30:23 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-10-16 06:22:10 -0700 |
commit | cb76cadb74a36e220a2b6a886c0c8068abdad0c7 (patch) | |
tree | 16136a771cda80b982018c2cf09249307c05d7ee /xlators/cluster/dht/src/dht-layout.c | |
parent | fa4e9d639b95b557ae64dab38c4c3ff8a0ec0d7a (diff) |
distribute,nufa: layout handling changes
changes to make revalidate not fail but instead perform fresh lookup
and swap inode context (layout) safely
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 315 (generation number support)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=315
Diffstat (limited to 'xlators/cluster/dht/src/dht-layout.c')
-rw-r--r-- | xlators/cluster/dht/src/dht-layout.c | 105 |
1 files changed, 97 insertions, 8 deletions
diff --git a/xlators/cluster/dht/src/dht-layout.c b/xlators/cluster/dht/src/dht-layout.c index 7984f2556..4b7b44fc4 100644 --- a/xlators/cluster/dht/src/dht-layout.c +++ b/xlators/cluster/dht/src/dht-layout.c @@ -54,6 +54,8 @@ dht_layout_new (xlator_t *this, int cnt) layout->cnt = cnt; if (conf) layout->gen = conf->gen; + + layout->ref = 1; out: return layout; } @@ -62,12 +64,92 @@ out: dht_layout_t * dht_layout_get (xlator_t *this, inode_t *inode) { - uint64_t layout = 0; - int ret = -1; + dht_conf_t *conf = NULL; + uint64_t layout_int = 0; + dht_layout_t *layout = NULL; + int ret = -1; + + conf = this->private; + LOCK (&conf->layout_lock); + { + ret = inode_ctx_get (inode, this, &layout_int); + if (ret == 0) { + layout = (dht_layout_t *) (unsigned long) layout_int; + layout->ref++; + } + } + UNLOCK (&conf->layout_lock); + + return layout; +} + + +int +dht_layout_set (xlator_t *this, inode_t *inode, dht_layout_t *layout) +{ + dht_conf_t *conf = NULL; + int oldret = -1; + int ret = 0; + dht_layout_t *old_layout; + uint64_t old_layout_int; + + conf = this->private; + LOCK (&conf->layout_lock); + { + oldret = inode_ctx_get (inode, this, &old_layout_int); + + layout->ref++; + ret = inode_ctx_put (inode, this, (uint64_t) (unsigned long) + layout); + } + UNLOCK (&conf->layout_lock); + + if (oldret == 0) { + old_layout = (dht_layout_t *) (unsigned long) old_layout_int; + dht_layout_unref (this, old_layout); + } + + return ret; +} + + +void +dht_layout_unref (xlator_t *this, dht_layout_t *layout) +{ + dht_conf_t *conf = NULL; + int ref = 0; - ret = inode_ctx_get (inode, this, &layout); + if (layout->preset) + return; - return (dht_layout_t *)(long)layout; + conf = this->private; + LOCK (&conf->layout_lock); + { + ref = --layout->ref; + } + UNLOCK (&conf->layout_lock); + + if (!ref) + FREE (layout); +} + + +dht_layout_t * +dht_layout_ref (xlator_t *this, dht_layout_t *layout) +{ + dht_conf_t *conf = NULL; + + if (layout->preset) + return layout; + + conf = this->private; + LOCK (&conf->layout_lock); + { + layout->ref++; + } + UNLOCK (&conf->layout_lock); + + return layout; } @@ -599,10 +681,13 @@ out: int -dht_layout_inode_set (xlator_t *this, xlator_t *subvol, inode_t *inode) +dht_layout_preset (xlator_t *this, xlator_t *subvol, inode_t *inode) { dht_layout_t *layout = NULL; - int ret = -1; + int ret = -1; + dht_conf_t *conf = NULL; + + conf = this->private; layout = dht_layout_for_subvol (this, subvol); if (!layout) { @@ -613,8 +698,12 @@ dht_layout_inode_set (xlator_t *this, xlator_t *subvol, inode_t *inode) goto out; } - inode_ctx_put (inode, this, (uint64_t)(long)layout); - + LOCK (&conf->layout_lock); + { + inode_ctx_put (inode, this, (uint64_t)(long)layout); + } + UNLOCK (&conf->layout_lock); + ret = 0; out: return ret; |