From cb76cadb74a36e220a2b6a886c0c8068abdad0c7 Mon Sep 17 00:00:00 2001 From: "Anand V. Avati" Date: Fri, 16 Oct 2009 07:30:23 +0000 Subject: 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 BUG: 315 (generation number support) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=315 --- xlators/cluster/dht/src/dht-layout.c | 105 ++++++++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 8 deletions(-) (limited to 'xlators/cluster/dht/src/dht-layout.c') 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; -- cgit