diff options
author | Raghavendra G <raghavendra@gluster.com> | 2009-09-18 05:47:56 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-09-22 06:12:42 -0700 |
commit | 6f692f0f39f9fe32936135947c91629044ae4d2c (patch) | |
tree | bec5b2120a4f26065c00af77a3893aa630cb7ac9 /xlators/performance/quick-read | |
parent | 5de57e490c8e3c2764777da6bf750a4f5e23f2b3 (diff) |
performance/quick-read: checking for qr_file in inode-context and creating if not present should be atomic.
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 273 (Code review and optimize quick-read)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=273
Diffstat (limited to 'xlators/performance/quick-read')
-rw-r--r-- | xlators/performance/quick-read/src/quick-read.c | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/xlators/performance/quick-read/src/quick-read.c b/xlators/performance/quick-read/src/quick-read.c index 0ab1052bb41..8df53df3996 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: /* |