summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaghavendra G <raghavendra@gluster.com>2009-09-18 05:58:23 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-09-22 06:13:51 -0700
commitfa953347e8f22baf4bf7e8042eeba0d949842a20 (patch)
tree41e0f2e5714f7c2ce2737a7aa36d71af1f9bdae2
parentb361b3aa5853626f918846894b8e43bff0d89252 (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
-rw-r--r--xlators/performance/quick-read/src/quick-read.c75
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:
/*