diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2018-11-07 10:27:15 +0200 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-12-05 03:59:29 +0000 |
commit | f80d9be732042477fc08ceb5873cd903002d7d1a (patch) | |
tree | 894d3bd6dfa67104d3a8026549d4ade4a794e907 /libglusterfs | |
parent | f479f4618923ca497d499dcaa533d19a2403e0b5 (diff) |
libglusterfs/src/iobuf.c: small refactor to re-use code.
No functional changes (I hope).
Compile-tested only!
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Change-Id: Ifbec21c18a6dbe27c5271db156bff4d30ca85dbf
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/iobuf.c | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/libglusterfs/src/iobuf.c b/libglusterfs/src/iobuf.c index 46efab692fc..374ea23b660 100644 --- a/libglusterfs/src/iobuf.c +++ b/libglusterfs/src/iobuf.c @@ -466,15 +466,18 @@ __iobuf_select_arena(struct iobuf_pool *iobuf_pool, const size_t page_size, return iobuf_arena; } -/* iobuf_arena variable is validaed to be non-NULL by all callers */ +/* Always called under the iobuf_pool mutex lock */ static struct iobuf * -__iobuf_get(struct iobuf_arena *iobuf_arena, const size_t page_size, +__iobuf_get(struct iobuf_pool *iobuf_pool, const size_t page_size, const int index) { struct iobuf *iobuf = NULL; - struct iobuf_pool *iobuf_pool = NULL; + struct iobuf_arena *iobuf_arena = NULL; - iobuf_pool = iobuf_arena->iobuf_pool; + /* most eligible arena for picking an iobuf */ + iobuf_arena = __iobuf_select_arena(iobuf_pool, page_size, index); + if (!iobuf_arena) + return NULL; list_for_each_entry(iobuf, &iobuf_arena->passive.list, list) break; @@ -545,7 +548,6 @@ struct iobuf * iobuf_get2(struct iobuf_pool *iobuf_pool, size_t page_size) { struct iobuf *iobuf = NULL; - struct iobuf_arena *iobuf_arena = NULL; size_t rounded_size = 0; int index = 0; @@ -580,14 +582,12 @@ iobuf_get2(struct iobuf_pool *iobuf_pool, size_t page_size) pthread_mutex_lock(&iobuf_pool->mutex); { - /* most eligible arena for picking an iobuf */ - iobuf_arena = __iobuf_select_arena(iobuf_pool, rounded_size, index); - if (!iobuf_arena) - goto unlock; - - iobuf = __iobuf_get(iobuf_arena, rounded_size, index); - if (!iobuf) + iobuf = __iobuf_get(iobuf_pool, rounded_size, index); + if (!iobuf) { + gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_IOBUF_NOT_FOUND, + "iobuf not found"); goto unlock; + } iobuf_ref(iobuf); } @@ -633,7 +633,6 @@ struct iobuf * iobuf_get(struct iobuf_pool *iobuf_pool) { struct iobuf *iobuf = NULL; - struct iobuf_arena *iobuf_arena = NULL; int index = 0; GF_VALIDATE_OR_GOTO("iobuf", iobuf_pool, out); @@ -649,16 +648,7 @@ iobuf_get(struct iobuf_pool *iobuf_pool) pthread_mutex_lock(&iobuf_pool->mutex); { - /* most eligible arena for picking an iobuf */ - iobuf_arena = __iobuf_select_arena( - iobuf_pool, iobuf_pool->default_page_size, index); - if (!iobuf_arena) { - gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_ARENA_NOT_FOUND, - "arena not found"); - goto unlock; - } - - iobuf = __iobuf_get(iobuf_arena, iobuf_pool->default_page_size, index); + iobuf = __iobuf_get(iobuf_pool, iobuf_pool->default_page_size, index); if (!iobuf) { gf_msg(THIS->name, GF_LOG_WARNING, 0, LG_MSG_IOBUF_NOT_FOUND, "iobuf not found"); |