diff options
| -rw-r--r-- | libglusterfs/src/inode.c | 76 | ||||
| -rw-r--r-- | libglusterfs/src/inode.h | 6 | ||||
| -rwxr-xr-x | libglusterfsclient/src/libglusterfsclient.c | 60 | ||||
| -rw-r--r-- | xlators/performance/io-cache/src/io-cache.c | 43 | 
4 files changed, 105 insertions, 80 deletions
diff --git a/libglusterfs/src/inode.c b/libglusterfs/src/inode.c index 1b028ef3063..c62d7ca9e7c 100644 --- a/libglusterfs/src/inode.c +++ b/libglusterfs/src/inode.c @@ -1105,9 +1105,31 @@ inode_from_path (inode_table_t *itable, const char *path)  }  int +__inode_ctx_put (inode_t *inode, xlator_t *xlator, uint64_t value) +{ +        int ret = 0; +        int index = 0; + +        for (index = 0; index < xlator->ctx->xl_count; index++) { +                if (!inode->_ctx[index].key ||  +                    (inode->_ctx[index].key == (uint64_t)(long)xlator)) +                        break; +        } +	 +        if (index == xlator->ctx->xl_count) { +                ret = -1; +                goto out;; +        } + +        inode->_ctx[index].key   = (uint64_t)(long) xlator; +        inode->_ctx[index].value = value; +out: +        return ret; +} + +int  inode_ctx_put (inode_t *inode, xlator_t *xlator, uint64_t value)  { -	int index = 0;          int ret = 0;  	if (!inode || !xlator) @@ -1115,30 +1137,38 @@ inode_ctx_put (inode_t *inode, xlator_t *xlator, uint64_t value)          LOCK (&inode->lock);          { -                for (index = 0; index < xlator->ctx->xl_count; index++) { -                        if (!inode->_ctx[index].key ||  -                            (inode->_ctx[index].key == (uint64_t)(long)xlator)) -                                break; -                } -	 -                if (index == xlator->ctx->xl_count) { -                        ret = -1; -                        goto unlock; -                } - -                inode->_ctx[index].key   = (uint64_t)(long) xlator; -                inode->_ctx[index].value = value; +                ret = __inode_ctx_put (inode, xlator, value);          } -unlock:          UNLOCK (&inode->lock);  	return ret;  } +int +__inode_ctx_get (inode_t *inode, xlator_t *xlator, uint64_t *value) +{ +	int index = 0; +        int ret = 0; +        for (index = 0; index < xlator->ctx->xl_count; index++) { +                if (inode->_ctx[index].key == (uint64_t)(long)xlator) +                        break; +        } + +        if (index == xlator->ctx->xl_count) { +                ret = -1; +                goto out; +        } + +        if (value)  +                *value = inode->_ctx[index].value; + +out: +        return ret; +} +  int   inode_ctx_get (inode_t *inode, xlator_t *xlator, uint64_t *value)  { -	int index = 0;          int ret = 0;  	if (!inode || !xlator) @@ -1146,20 +1176,8 @@ inode_ctx_get (inode_t *inode, xlator_t *xlator, uint64_t *value)          LOCK (&inode->lock);          { -                for (index = 0; index < xlator->ctx->xl_count; index++) { -                        if (inode->_ctx[index].key == (uint64_t)(long)xlator) -                                break; -                } - -                if (index == xlator->ctx->xl_count) { -                        ret = -1; -                        goto unlock; -                } - -                if (value)  -                        *value = inode->_ctx[index].value; +                ret = __inode_ctx_get (inode, xlator, value);          } -unlock:          UNLOCK (&inode->lock);  	return ret; diff --git a/libglusterfs/src/inode.h b/libglusterfs/src/inode.h index afcc1552e4c..d434668a3b4 100644 --- a/libglusterfs/src/inode.h +++ b/libglusterfs/src/inode.h @@ -149,8 +149,14 @@ inode_from_path (inode_table_t *table,  		 const char *path);  int +__inode_ctx_put (inode_t *inode, xlator_t *xlator, uint64_t value); + +int  inode_ctx_put (inode_t *inode, xlator_t *xlator, uint64_t value); +int +__inode_ctx_get (inode_t *inode, xlator_t *xlator, uint64_t *value); +  int   inode_ctx_get (inode_t *inode, xlator_t *xlator, uint64_t *value); diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index db8407cbf5b..13afb9facfb 100755 --- a/libglusterfsclient/src/libglusterfsclient.c +++ b/libglusterfsclient/src/libglusterfsclient.c @@ -836,14 +836,20 @@ libgf_client_lookup (libglusterfs_client_ctx_t *ctx,  		uint64_t ptr = 0;  		this = ctx->gf_ctx.graph; -		ret = inode_ctx_get (inode, this, &ptr); -		if (ret == -1) { -			inode_ctx = CALLOC (1, sizeof (*inode_ctx)); -			ERR_ABORT (inode_ctx); -			pthread_mutex_init (&inode_ctx->lock, NULL); -		} else { -			inode_ctx = (libglusterfs_client_inode_ctx_t *)(long)ptr; -		} +                LOCK (&inode->lock); +                { +                        ret = __inode_ctx_get (inode, this, &ptr); +                        if (ret == -1) { +                                inode_ctx = CALLOC (1, sizeof (*inode_ctx)); +                                ERR_ABORT (inode_ctx); +                                pthread_mutex_init (&inode_ctx->lock, NULL); +                                __inode_ctx_put (inode, this, +                                                 (uint64_t)(long)inode_ctx); +                        } else { +                                inode_ctx = (libglusterfs_client_inode_ctx_t *)(long)ptr; +                        } +                } +                UNLOCK (&inode->lock);                  current = time (NULL); @@ -856,11 +862,6 @@ libgf_client_lookup (libglusterfs_client_ctx_t *ctx,  		}  		pthread_mutex_unlock (&inode_ctx->lock); -		ret = inode_ctx_get (inode, this, NULL); -		if (ret == -1) { -			inode_ctx_put (inode, this, (uint64_t)(long)inode_ctx); -		} -                  if (stbuf)                          *stbuf = stub->args.lookup_cbk.buf;  @@ -951,27 +952,33 @@ libgf_client_lookup_async_cbk (call_frame_t *frame,          glusterfs_lookup_cbk_t lookup_cbk = local->fop.lookup_cbk.cbk;          libglusterfs_client_ctx_t *ctx = frame->root->state;  	dict_t *xattr_req = NULL; +        uint64_t ptr = 0;  	int32_t ret = 0;          if (op_ret == 0) {                  time_t current = 0; -                data_t *inode_ctx_data = NULL;                  libglusterfs_client_inode_ctx_t *inode_ctx = NULL;                  /* flat directory structure */                  inode_t *parent = inode_search (ctx->itable, 1, NULL); -                inode_link (inode, parent, local->fop.lookup_cbk.loc->path, buf); -                 -		inode_ctx_data = dict_get (inode->ctx, XLATOR_NAME); -                if (inode_ctx_data) { -                        inode_ctx = data_to_ptr (inode_ctx_data); -                } - -                if (!inode_ctx) { -                        inode_ctx = CALLOC (1, sizeof (*inode_ctx)); -                        pthread_mutex_init (&inode_ctx->lock, NULL); +                inode_link (inode, parent, local->fop.lookup_cbk.loc->path, +                            buf); +                +                LOCK (&inode->lock); +                { +                        ret = __inode_ctx_get (inode, this, &ptr); +                        if (ret == -1) { +                                inode_ctx = CALLOC (1, sizeof (*inode_ctx)); +                                ERR_ABORT (inode_ctx); +                                pthread_mutex_init (&inode_ctx->lock, NULL); +                                __inode_ctx_put (inode, this, +                                                 (uint64_t)(long)inode_ctx); +                        } else { +                                inode_ctx = (libglusterfs_client_inode_ctx_t *)(long)ptr; +                        }                  } +                UNLOCK (&inode->lock);                  current = time (NULL); @@ -983,11 +990,6 @@ libgf_client_lookup_async_cbk (call_frame_t *frame,                  }                  pthread_mutex_unlock (&inode_ctx->lock); -		ret = inode_ctx_get (inode, this, NULL); -		if (ret == -1) { -			inode_ctx_put (inode, this, (uint64_t)(long)inode_ctx); -		} -                  inode_lookup (inode);                  inode_unref (parent);          } else { diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c index 55dfa5ac6ba..00d95857db1 100644 --- a/xlators/performance/io-cache/src/io-cache.c +++ b/xlators/performance/io-cache/src/io-cache.c @@ -616,30 +616,29 @@ ioc_open_cbk (call_frame_t *frame,  	if (op_ret != -1) {  		/* look for ioc_inode corresponding to this fd */  		LOCK (&fd->inode->lock); -		//{ - -		inode_ctx_get (fd->inode, this, &tmp_ioc_inode); -		ioc_inode = (ioc_inode_t *)(long)tmp_ioc_inode; -       -		if (!ioc_inode) { -			/* this is the first time someone is opening this  -			   file, assign weight  -			*/ -			weight = ioc_get_priority (table, path); +		{ +                        __inode_ctx_get (fd->inode, this, &tmp_ioc_inode); +                        ioc_inode = (ioc_inode_t *)(long)tmp_ioc_inode; +                         +                        if (!ioc_inode) { +                                /* this is the first time someone is opening this  +                                   file, assign weight  +                                */ +                                weight = ioc_get_priority (table, path); -			ioc_inode = ioc_inode_update (table, inode, weight); -			inode_ctx_put (fd->inode, this,  -				       (uint64_t)(long)ioc_inode); -		} else { -			ioc_table_lock (ioc_inode->table); -			//{ -			list_move_tail (&ioc_inode->inode_lru, -					&table->inode_lru[ioc_inode->weight]); -			//} -			ioc_table_unlock (ioc_inode->table); -		} +                                ioc_inode = ioc_inode_update (table, inode, weight); +                                __inode_ctx_put (fd->inode, this,  +                                                 (uint64_t)(long)ioc_inode); +                        } else { +                                ioc_table_lock (ioc_inode->table); +                                { +                                        list_move_tail (&ioc_inode->inode_lru, +                                                        &table->inode_lru[ioc_inode->weight]); +                                } +                                ioc_table_unlock (ioc_inode->table); +                        } -		//} +		}  		UNLOCK (&fd->inode->lock);  		/* If mandatory locking has been enabled on this file,  | 
