From fa953347e8f22baf4bf7e8042eeba0d949842a20 Mon Sep 17 00:00:00 2001 From: Raghavendra G Date: Fri, 18 Sep 2009 05:58:23 +0000 Subject: performance/quick-read: checking for qr_file in inode-context and creating if not present should be atomic. Signed-off-by: Anand V. Avati BUG: 273 (Code review and optimize quick-read) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=273 --- xlators/performance/quick-read/src/quick-read.c | 75 +++++++++++++++---------- 1 file changed, 45 insertions(+), 30 deletions(-) (limited to 'xlators/performance/quick-read') diff --git a/xlators/performance/quick-read/src/quick-read.c b/xlators/performance/quick-read/src/quick-read.c index 0ab1052bb..8df53df39 100644 --- a/xlators/performance/quick-read/src/quick-read.c +++ b/xlators/performance/quick-read/src/quick-read.c @@ -176,42 +176,57 @@ qr_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, goto out; } - /* - * FIXME: checking for qr_file and creating (adding in turn) should be - * atomic - */ - ret = inode_ctx_get (inode, this, &value); - if (ret == -1) { - qr_file = CALLOC (1, sizeof (*qr_file)); - if (qr_file == NULL) { - op_ret = -1; - op_errno = ENOMEM; - goto out; - } - - LOCK_INIT (&qr_file->lock); - inode_ctx_put (inode, this, (uint64_t)(long)qr_file); - } else { - qr_file = (qr_file_t *)(long)value; - if (qr_file == NULL) { - op_ret = -1; - op_errno = EINVAL; - goto out; - } + if (inode == NULL) { + op_ret = -1; + op_errno = EINVAL; + goto out; } - LOCK (&qr_file->lock); + LOCK (&inode->lock); { - if (qr_file->xattr) { - dict_unref (qr_file->xattr); - qr_file->xattr = NULL; + ret = __inode_ctx_get (inode, this, &value); + if (ret == -1) { + qr_file = CALLOC (1, sizeof (*qr_file)); + if (qr_file == NULL) { + op_ret = -1; + op_errno = ENOMEM; + goto unlock; + } + + LOCK_INIT (&qr_file->lock); + ret = __inode_ctx_put (inode, this, + (uint64_t)(long)qr_file); + if (ret == -1) { + FREE (qr_file); + qr_file = NULL; + op_ret = -1; + op_errno = EINVAL; + } + } else { + qr_file = (qr_file_t *)(long)value; + if (qr_file == NULL) { + op_ret = -1; + op_errno = EINVAL; + } } + } +unlock: + UNLOCK (&inode->lock); - qr_file->xattr = dict_ref (dict); - qr_file->stbuf = *buf; - gettimeofday (&qr_file->tv, NULL); + if (qr_file != NULL) { + LOCK (&qr_file->lock); + { + if (qr_file->xattr) { + dict_unref (qr_file->xattr); + qr_file->xattr = NULL; + } + + qr_file->xattr = dict_ref (dict); + qr_file->stbuf = *buf; + gettimeofday (&qr_file->tv, NULL); + } + UNLOCK (&qr_file->lock); } - UNLOCK (&qr_file->lock); out: /* -- cgit