Commit fe6e4ccb authored by Mike Snitzer's avatar Mike Snitzer

dm vdo thread-utils: remove all uds_*_mutex wrappers

Just use mutex_init, mutex_lock and mutex_unlock.
Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
Signed-off-by: default avatarMatthew Sakai <msakai@redhat.com>
parent 7f2e494d
...@@ -61,10 +61,10 @@ enum index_session_flag { ...@@ -61,10 +61,10 @@ enum index_session_flag {
/* Release a reference to an index session. */ /* Release a reference to an index session. */
static void release_index_session(struct uds_index_session *index_session) static void release_index_session(struct uds_index_session *index_session)
{ {
uds_lock_mutex(&index_session->request_mutex); mutex_lock(&index_session->request_mutex);
if (--index_session->request_count == 0) if (--index_session->request_count == 0)
uds_broadcast_cond(&index_session->request_cond); uds_broadcast_cond(&index_session->request_cond);
uds_unlock_mutex(&index_session->request_mutex); mutex_unlock(&index_session->request_mutex);
} }
/* /*
...@@ -76,10 +76,10 @@ static int get_index_session(struct uds_index_session *index_session) ...@@ -76,10 +76,10 @@ static int get_index_session(struct uds_index_session *index_session)
unsigned int state; unsigned int state;
int result = UDS_SUCCESS; int result = UDS_SUCCESS;
uds_lock_mutex(&index_session->request_mutex); mutex_lock(&index_session->request_mutex);
index_session->request_count++; index_session->request_count++;
state = index_session->state; state = index_session->state;
uds_unlock_mutex(&index_session->request_mutex); mutex_unlock(&index_session->request_mutex);
if (state == IS_FLAG_LOADED) { if (state == IS_FLAG_LOADED) {
return UDS_SUCCESS; return UDS_SUCCESS;
...@@ -141,9 +141,9 @@ static void enter_callback_stage(struct uds_request *request) ...@@ -141,9 +141,9 @@ static void enter_callback_stage(struct uds_request *request)
{ {
if (request->status != UDS_SUCCESS) { if (request->status != UDS_SUCCESS) {
/* All request errors are considered unrecoverable */ /* All request errors are considered unrecoverable */
uds_lock_mutex(&request->session->request_mutex); mutex_lock(&request->session->request_mutex);
request->session->state |= IS_FLAG_DISABLED; request->session->state |= IS_FLAG_DISABLED;
uds_unlock_mutex(&request->session->request_mutex); mutex_unlock(&request->session->request_mutex);
} }
uds_request_queue_enqueue(request->session->callback_queue, request); uds_request_queue_enqueue(request->session->callback_queue, request);
...@@ -224,28 +224,14 @@ static int __must_check make_empty_index_session(struct uds_index_session **inde ...@@ -224,28 +224,14 @@ static int __must_check make_empty_index_session(struct uds_index_session **inde
if (result != UDS_SUCCESS) if (result != UDS_SUCCESS)
return result; return result;
result = uds_init_mutex(&session->request_mutex); mutex_init(&session->request_mutex);
if (result != UDS_SUCCESS) {
uds_free(session);
return result;
}
uds_init_cond(&session->request_cond); uds_init_cond(&session->request_cond);
mutex_init(&session->load_context.mutex);
result = uds_init_mutex(&session->load_context.mutex);
if (result != UDS_SUCCESS) {
uds_destroy_mutex(&session->request_mutex);
uds_free(session);
return result;
}
uds_init_cond(&session->load_context.cond); uds_init_cond(&session->load_context.cond);
result = uds_make_request_queue("callbackW", &handle_callbacks, result = uds_make_request_queue("callbackW", &handle_callbacks,
&session->callback_queue); &session->callback_queue);
if (result != UDS_SUCCESS) { if (result != UDS_SUCCESS) {
uds_destroy_mutex(&session->load_context.mutex);
uds_destroy_mutex(&session->request_mutex);
uds_free(session); uds_free(session);
return result; return result;
} }
...@@ -268,7 +254,7 @@ static int __must_check start_loading_index_session(struct uds_index_session *in ...@@ -268,7 +254,7 @@ static int __must_check start_loading_index_session(struct uds_index_session *in
{ {
int result; int result;
uds_lock_mutex(&index_session->request_mutex); mutex_lock(&index_session->request_mutex);
if (index_session->state & IS_FLAG_SUSPENDED) { if (index_session->state & IS_FLAG_SUSPENDED) {
uds_log_info("Index session is suspended"); uds_log_info("Index session is suspended");
result = -EBUSY; result = -EBUSY;
...@@ -279,20 +265,20 @@ static int __must_check start_loading_index_session(struct uds_index_session *in ...@@ -279,20 +265,20 @@ static int __must_check start_loading_index_session(struct uds_index_session *in
index_session->state |= IS_FLAG_LOADING; index_session->state |= IS_FLAG_LOADING;
result = UDS_SUCCESS; result = UDS_SUCCESS;
} }
uds_unlock_mutex(&index_session->request_mutex); mutex_unlock(&index_session->request_mutex);
return result; return result;
} }
static void finish_loading_index_session(struct uds_index_session *index_session, static void finish_loading_index_session(struct uds_index_session *index_session,
int result) int result)
{ {
uds_lock_mutex(&index_session->request_mutex); mutex_lock(&index_session->request_mutex);
index_session->state &= ~IS_FLAG_LOADING; index_session->state &= ~IS_FLAG_LOADING;
if (result == UDS_SUCCESS) if (result == UDS_SUCCESS)
index_session->state |= IS_FLAG_LOADED; index_session->state |= IS_FLAG_LOADED;
uds_broadcast_cond(&index_session->request_cond); uds_broadcast_cond(&index_session->request_cond);
uds_unlock_mutex(&index_session->request_mutex); mutex_unlock(&index_session->request_mutex);
} }
static int initialize_index_session(struct uds_index_session *index_session, static int initialize_index_session(struct uds_index_session *index_session,
...@@ -376,12 +362,12 @@ int uds_open_index(enum uds_open_index_type open_type, ...@@ -376,12 +362,12 @@ int uds_open_index(enum uds_open_index_type open_type,
static void wait_for_no_requests_in_progress(struct uds_index_session *index_session) static void wait_for_no_requests_in_progress(struct uds_index_session *index_session)
{ {
uds_lock_mutex(&index_session->request_mutex); mutex_lock(&index_session->request_mutex);
while (index_session->request_count > 0) { while (index_session->request_count > 0) {
uds_wait_cond(&index_session->request_cond, uds_wait_cond(&index_session->request_cond,
&index_session->request_mutex); &index_session->request_mutex);
} }
uds_unlock_mutex(&index_session->request_mutex); mutex_unlock(&index_session->request_mutex);
} }
static int __must_check save_index(struct uds_index_session *index_session) static int __must_check save_index(struct uds_index_session *index_session)
...@@ -392,7 +378,7 @@ static int __must_check save_index(struct uds_index_session *index_session) ...@@ -392,7 +378,7 @@ static int __must_check save_index(struct uds_index_session *index_session)
static void suspend_rebuild(struct uds_index_session *session) static void suspend_rebuild(struct uds_index_session *session)
{ {
uds_lock_mutex(&session->load_context.mutex); mutex_lock(&session->load_context.mutex);
switch (session->load_context.status) { switch (session->load_context.status) {
case INDEX_OPENING: case INDEX_OPENING:
session->load_context.status = INDEX_SUSPENDING; session->load_context.status = INDEX_SUSPENDING;
...@@ -419,7 +405,7 @@ static void suspend_rebuild(struct uds_index_session *session) ...@@ -419,7 +405,7 @@ static void suspend_rebuild(struct uds_index_session *session)
session->load_context.status); session->load_context.status);
break; break;
} }
uds_unlock_mutex(&session->load_context.mutex); mutex_unlock(&session->load_context.mutex);
} }
/* /*
...@@ -433,7 +419,7 @@ int uds_suspend_index_session(struct uds_index_session *session, bool save) ...@@ -433,7 +419,7 @@ int uds_suspend_index_session(struct uds_index_session *session, bool save)
bool rebuilding = false; bool rebuilding = false;
/* Wait for any current index state change to complete. */ /* Wait for any current index state change to complete. */
uds_lock_mutex(&session->request_mutex); mutex_lock(&session->request_mutex);
while (session->state & IS_FLAG_CLOSING) while (session->state & IS_FLAG_CLOSING)
uds_wait_cond(&session->request_cond, &session->request_mutex); uds_wait_cond(&session->request_cond, &session->request_mutex);
...@@ -453,7 +439,7 @@ int uds_suspend_index_session(struct uds_index_session *session, bool save) ...@@ -453,7 +439,7 @@ int uds_suspend_index_session(struct uds_index_session *session, bool save)
session->state |= IS_FLAG_SUSPENDED; session->state |= IS_FLAG_SUSPENDED;
uds_broadcast_cond(&session->request_cond); uds_broadcast_cond(&session->request_cond);
} }
uds_unlock_mutex(&session->request_mutex); mutex_unlock(&session->request_mutex);
if (no_work) if (no_work)
return uds_status_to_errno(result); return uds_status_to_errno(result);
...@@ -465,11 +451,11 @@ int uds_suspend_index_session(struct uds_index_session *session, bool save) ...@@ -465,11 +451,11 @@ int uds_suspend_index_session(struct uds_index_session *session, bool save)
else else
result = uds_flush_index_session(session); result = uds_flush_index_session(session);
uds_lock_mutex(&session->request_mutex); mutex_lock(&session->request_mutex);
session->state &= ~IS_FLAG_WAITING; session->state &= ~IS_FLAG_WAITING;
session->state |= IS_FLAG_SUSPENDED; session->state |= IS_FLAG_SUSPENDED;
uds_broadcast_cond(&session->request_cond); uds_broadcast_cond(&session->request_cond);
uds_unlock_mutex(&session->request_mutex); mutex_unlock(&session->request_mutex);
return uds_status_to_errno(result); return uds_status_to_errno(result);
} }
...@@ -496,7 +482,7 @@ int uds_resume_index_session(struct uds_index_session *session, ...@@ -496,7 +482,7 @@ int uds_resume_index_session(struct uds_index_session *session,
bool no_work = false; bool no_work = false;
bool resume_replay = false; bool resume_replay = false;
uds_lock_mutex(&session->request_mutex); mutex_lock(&session->request_mutex);
if (session->state & IS_FLAG_WAITING) { if (session->state & IS_FLAG_WAITING) {
uds_log_info("Index session is already changing state"); uds_log_info("Index session is already changing state");
no_work = true; no_work = true;
...@@ -510,7 +496,7 @@ int uds_resume_index_session(struct uds_index_session *session, ...@@ -510,7 +496,7 @@ int uds_resume_index_session(struct uds_index_session *session,
if (session->state & IS_FLAG_LOADING) if (session->state & IS_FLAG_LOADING)
resume_replay = true; resume_replay = true;
} }
uds_unlock_mutex(&session->request_mutex); mutex_unlock(&session->request_mutex);
if (no_work) if (no_work)
return result; return result;
...@@ -518,16 +504,16 @@ int uds_resume_index_session(struct uds_index_session *session, ...@@ -518,16 +504,16 @@ int uds_resume_index_session(struct uds_index_session *session,
if ((session->index != NULL) && (bdev != session->parameters.bdev)) { if ((session->index != NULL) && (bdev != session->parameters.bdev)) {
result = replace_device(session, bdev); result = replace_device(session, bdev);
if (result != UDS_SUCCESS) { if (result != UDS_SUCCESS) {
uds_lock_mutex(&session->request_mutex); mutex_lock(&session->request_mutex);
session->state &= ~IS_FLAG_WAITING; session->state &= ~IS_FLAG_WAITING;
uds_broadcast_cond(&session->request_cond); uds_broadcast_cond(&session->request_cond);
uds_unlock_mutex(&session->request_mutex); mutex_unlock(&session->request_mutex);
return uds_status_to_errno(result); return uds_status_to_errno(result);
} }
} }
if (resume_replay) { if (resume_replay) {
uds_lock_mutex(&session->load_context.mutex); mutex_lock(&session->load_context.mutex);
switch (session->load_context.status) { switch (session->load_context.status) {
case INDEX_SUSPENDED: case INDEX_SUSPENDED:
session->load_context.status = INDEX_OPENING; session->load_context.status = INDEX_OPENING;
...@@ -548,14 +534,14 @@ int uds_resume_index_session(struct uds_index_session *session, ...@@ -548,14 +534,14 @@ int uds_resume_index_session(struct uds_index_session *session,
session->load_context.status); session->load_context.status);
break; break;
} }
uds_unlock_mutex(&session->load_context.mutex); mutex_unlock(&session->load_context.mutex);
} }
uds_lock_mutex(&session->request_mutex); mutex_lock(&session->request_mutex);
session->state &= ~IS_FLAG_WAITING; session->state &= ~IS_FLAG_WAITING;
session->state &= ~IS_FLAG_SUSPENDED; session->state &= ~IS_FLAG_SUSPENDED;
uds_broadcast_cond(&session->request_cond); uds_broadcast_cond(&session->request_cond);
uds_unlock_mutex(&session->request_mutex); mutex_unlock(&session->request_mutex);
return UDS_SUCCESS; return UDS_SUCCESS;
} }
...@@ -568,9 +554,9 @@ static int save_and_free_index(struct uds_index_session *index_session) ...@@ -568,9 +554,9 @@ static int save_and_free_index(struct uds_index_session *index_session)
if (index == NULL) if (index == NULL)
return UDS_SUCCESS; return UDS_SUCCESS;
uds_lock_mutex(&index_session->request_mutex); mutex_lock(&index_session->request_mutex);
suspended = (index_session->state & IS_FLAG_SUSPENDED); suspended = (index_session->state & IS_FLAG_SUSPENDED);
uds_unlock_mutex(&index_session->request_mutex); mutex_unlock(&index_session->request_mutex);
if (!suspended) { if (!suspended) {
result = uds_save_index(index); result = uds_save_index(index);
...@@ -585,14 +571,14 @@ static int save_and_free_index(struct uds_index_session *index_session) ...@@ -585,14 +571,14 @@ static int save_and_free_index(struct uds_index_session *index_session)
* Reset all index state that happens to be in the index * Reset all index state that happens to be in the index
* session, so it doesn't affect any future index. * session, so it doesn't affect any future index.
*/ */
uds_lock_mutex(&index_session->load_context.mutex); mutex_lock(&index_session->load_context.mutex);
index_session->load_context.status = INDEX_OPENING; index_session->load_context.status = INDEX_OPENING;
uds_unlock_mutex(&index_session->load_context.mutex); mutex_unlock(&index_session->load_context.mutex);
uds_lock_mutex(&index_session->request_mutex); mutex_lock(&index_session->request_mutex);
/* Only the suspend bit will remain relevant. */ /* Only the suspend bit will remain relevant. */
index_session->state &= IS_FLAG_SUSPENDED; index_session->state &= IS_FLAG_SUSPENDED;
uds_unlock_mutex(&index_session->request_mutex); mutex_unlock(&index_session->request_mutex);
return result; return result;
} }
...@@ -603,7 +589,7 @@ int uds_close_index(struct uds_index_session *index_session) ...@@ -603,7 +589,7 @@ int uds_close_index(struct uds_index_session *index_session)
int result = UDS_SUCCESS; int result = UDS_SUCCESS;
/* Wait for any current index state change to complete. */ /* Wait for any current index state change to complete. */
uds_lock_mutex(&index_session->request_mutex); mutex_lock(&index_session->request_mutex);
while ((index_session->state & IS_FLAG_WAITING) || while ((index_session->state & IS_FLAG_WAITING) ||
(index_session->state & IS_FLAG_CLOSING)) { (index_session->state & IS_FLAG_CLOSING)) {
uds_wait_cond(&index_session->request_cond, uds_wait_cond(&index_session->request_cond,
...@@ -620,7 +606,7 @@ int uds_close_index(struct uds_index_session *index_session) ...@@ -620,7 +606,7 @@ int uds_close_index(struct uds_index_session *index_session)
} else { } else {
index_session->state |= IS_FLAG_CLOSING; index_session->state |= IS_FLAG_CLOSING;
} }
uds_unlock_mutex(&index_session->request_mutex); mutex_unlock(&index_session->request_mutex);
if (result != UDS_SUCCESS) if (result != UDS_SUCCESS)
return uds_status_to_errno(result); return uds_status_to_errno(result);
...@@ -629,10 +615,10 @@ int uds_close_index(struct uds_index_session *index_session) ...@@ -629,10 +615,10 @@ int uds_close_index(struct uds_index_session *index_session)
result = save_and_free_index(index_session); result = save_and_free_index(index_session);
uds_log_debug("Closed index"); uds_log_debug("Closed index");
uds_lock_mutex(&index_session->request_mutex); mutex_lock(&index_session->request_mutex);
index_session->state &= ~IS_FLAG_CLOSING; index_session->state &= ~IS_FLAG_CLOSING;
uds_broadcast_cond(&index_session->request_cond); uds_broadcast_cond(&index_session->request_cond);
uds_unlock_mutex(&index_session->request_mutex); mutex_unlock(&index_session->request_mutex);
return uds_status_to_errno(result); return uds_status_to_errno(result);
} }
...@@ -645,7 +631,7 @@ int uds_destroy_index_session(struct uds_index_session *index_session) ...@@ -645,7 +631,7 @@ int uds_destroy_index_session(struct uds_index_session *index_session)
uds_log_debug("Destroying index session"); uds_log_debug("Destroying index session");
/* Wait for any current index state change to complete. */ /* Wait for any current index state change to complete. */
uds_lock_mutex(&index_session->request_mutex); mutex_lock(&index_session->request_mutex);
while ((index_session->state & IS_FLAG_WAITING) || while ((index_session->state & IS_FLAG_WAITING) ||
(index_session->state & IS_FLAG_CLOSING)) { (index_session->state & IS_FLAG_CLOSING)) {
uds_wait_cond(&index_session->request_cond, uds_wait_cond(&index_session->request_cond,
...@@ -653,7 +639,7 @@ int uds_destroy_index_session(struct uds_index_session *index_session) ...@@ -653,7 +639,7 @@ int uds_destroy_index_session(struct uds_index_session *index_session)
} }
if (index_session->state & IS_FLAG_DESTROYING) { if (index_session->state & IS_FLAG_DESTROYING) {
uds_unlock_mutex(&index_session->request_mutex); mutex_unlock(&index_session->request_mutex);
uds_log_info("Index session is already closing"); uds_log_info("Index session is already closing");
return -EBUSY; return -EBUSY;
} }
...@@ -661,32 +647,30 @@ int uds_destroy_index_session(struct uds_index_session *index_session) ...@@ -661,32 +647,30 @@ int uds_destroy_index_session(struct uds_index_session *index_session)
index_session->state |= IS_FLAG_DESTROYING; index_session->state |= IS_FLAG_DESTROYING;
load_pending = ((index_session->state & IS_FLAG_LOADING) && load_pending = ((index_session->state & IS_FLAG_LOADING) &&
(index_session->state & IS_FLAG_SUSPENDED)); (index_session->state & IS_FLAG_SUSPENDED));
uds_unlock_mutex(&index_session->request_mutex); mutex_unlock(&index_session->request_mutex);
if (load_pending) { if (load_pending) {
/* Tell the index to terminate the rebuild. */ /* Tell the index to terminate the rebuild. */
uds_lock_mutex(&index_session->load_context.mutex); mutex_lock(&index_session->load_context.mutex);
if (index_session->load_context.status == INDEX_SUSPENDED) { if (index_session->load_context.status == INDEX_SUSPENDED) {
index_session->load_context.status = INDEX_FREEING; index_session->load_context.status = INDEX_FREEING;
uds_broadcast_cond(&index_session->load_context.cond); uds_broadcast_cond(&index_session->load_context.cond);
} }
uds_unlock_mutex(&index_session->load_context.mutex); mutex_unlock(&index_session->load_context.mutex);
/* Wait until the load exits before proceeding. */ /* Wait until the load exits before proceeding. */
uds_lock_mutex(&index_session->request_mutex); mutex_lock(&index_session->request_mutex);
while (index_session->state & IS_FLAG_LOADING) { while (index_session->state & IS_FLAG_LOADING) {
uds_wait_cond(&index_session->request_cond, uds_wait_cond(&index_session->request_cond,
&index_session->request_mutex); &index_session->request_mutex);
} }
uds_unlock_mutex(&index_session->request_mutex); mutex_unlock(&index_session->request_mutex);
} }
wait_for_no_requests_in_progress(index_session); wait_for_no_requests_in_progress(index_session);
result = save_and_free_index(index_session); result = save_and_free_index(index_session);
uds_request_queue_finish(index_session->callback_queue); uds_request_queue_finish(index_session->callback_queue);
index_session->callback_queue = NULL; index_session->callback_queue = NULL;
uds_destroy_mutex(&index_session->load_context.mutex);
uds_destroy_mutex(&index_session->request_mutex);
uds_log_debug("Destroyed index session"); uds_log_debug("Destroyed index session");
uds_free(index_session); uds_free(index_session);
return uds_status_to_errno(result); return uds_status_to_errno(result);
...@@ -747,8 +731,8 @@ void uds_wait_cond(struct cond_var *cv, struct mutex *mutex) ...@@ -747,8 +731,8 @@ void uds_wait_cond(struct cond_var *cv, struct mutex *mutex)
DEFINE_WAIT(__wait); DEFINE_WAIT(__wait);
prepare_to_wait(&cv->wait_queue, &__wait, TASK_IDLE); prepare_to_wait(&cv->wait_queue, &__wait, TASK_IDLE);
uds_unlock_mutex(mutex); mutex_unlock(mutex);
schedule(); schedule();
finish_wait(&cv->wait_queue, &__wait); finish_wait(&cv->wait_queue, &__wait);
uds_lock_mutex(mutex); mutex_lock(mutex);
} }
...@@ -180,11 +180,11 @@ static int finish_previous_chapter(struct uds_index *index, u64 current_chapter_ ...@@ -180,11 +180,11 @@ static int finish_previous_chapter(struct uds_index *index, u64 current_chapter_
int result; int result;
struct chapter_writer *writer = index->chapter_writer; struct chapter_writer *writer = index->chapter_writer;
uds_lock_mutex(&writer->mutex); mutex_lock(&writer->mutex);
while (index->newest_virtual_chapter < current_chapter_number) while (index->newest_virtual_chapter < current_chapter_number)
uds_wait_cond(&writer->cond, &writer->mutex); uds_wait_cond(&writer->cond, &writer->mutex);
result = writer->result; result = writer->result;
uds_unlock_mutex(&writer->mutex); mutex_unlock(&writer->mutex);
if (result != UDS_SUCCESS) if (result != UDS_SUCCESS)
return uds_log_error_strerror(result, return uds_log_error_strerror(result,
...@@ -219,11 +219,11 @@ static unsigned int start_closing_chapter(struct uds_index *index, ...@@ -219,11 +219,11 @@ static unsigned int start_closing_chapter(struct uds_index *index,
unsigned int finished_zones; unsigned int finished_zones;
struct chapter_writer *writer = index->chapter_writer; struct chapter_writer *writer = index->chapter_writer;
uds_lock_mutex(&writer->mutex); mutex_lock(&writer->mutex);
finished_zones = ++writer->zones_to_write; finished_zones = ++writer->zones_to_write;
writer->chapters[zone_number] = chapter; writer->chapters[zone_number] = chapter;
uds_broadcast_cond(&writer->cond); uds_broadcast_cond(&writer->cond);
uds_unlock_mutex(&writer->mutex); mutex_unlock(&writer->mutex);
return finished_zones; return finished_zones;
} }
...@@ -678,7 +678,7 @@ static void close_chapters(void *arg) ...@@ -678,7 +678,7 @@ static void close_chapters(void *arg)
struct uds_index *index = writer->index; struct uds_index *index = writer->index;
uds_log_debug("chapter writer starting"); uds_log_debug("chapter writer starting");
uds_lock_mutex(&writer->mutex); mutex_lock(&writer->mutex);
for (;;) { for (;;) {
while (writer->zones_to_write < index->zone_count) { while (writer->zones_to_write < index->zone_count) {
if (writer->stop && (writer->zones_to_write == 0)) { if (writer->stop && (writer->zones_to_write == 0)) {
...@@ -686,7 +686,7 @@ static void close_chapters(void *arg) ...@@ -686,7 +686,7 @@ static void close_chapters(void *arg)
* We've been told to stop, and all of the zones are in the same * We've been told to stop, and all of the zones are in the same
* open chapter, so we can exit now. * open chapter, so we can exit now.
*/ */
uds_unlock_mutex(&writer->mutex); mutex_unlock(&writer->mutex);
uds_log_debug("chapter writer stopping"); uds_log_debug("chapter writer stopping");
return; return;
} }
...@@ -698,7 +698,7 @@ static void close_chapters(void *arg) ...@@ -698,7 +698,7 @@ static void close_chapters(void *arg)
* it seems safer in principle. It's OK to access the chapter and chapter_number * it seems safer in principle. It's OK to access the chapter and chapter_number
* fields without the lock since those aren't allowed to change until we're done. * fields without the lock since those aren't allowed to change until we're done.
*/ */
uds_unlock_mutex(&writer->mutex); mutex_unlock(&writer->mutex);
if (index->has_saved_open_chapter) { if (index->has_saved_open_chapter) {
/* /*
...@@ -719,7 +719,7 @@ static void close_chapters(void *arg) ...@@ -719,7 +719,7 @@ static void close_chapters(void *arg)
writer->collated_records, writer->collated_records,
index->newest_virtual_chapter); index->newest_virtual_chapter);
uds_lock_mutex(&writer->mutex); mutex_lock(&writer->mutex);
index->newest_virtual_chapter++; index->newest_virtual_chapter++;
index->oldest_virtual_chapter += index->oldest_virtual_chapter +=
uds_chapters_to_expire(index->volume->geometry, uds_chapters_to_expire(index->volume->geometry,
...@@ -734,14 +734,14 @@ static void stop_chapter_writer(struct chapter_writer *writer) ...@@ -734,14 +734,14 @@ static void stop_chapter_writer(struct chapter_writer *writer)
{ {
struct thread *writer_thread = NULL; struct thread *writer_thread = NULL;
uds_lock_mutex(&writer->mutex); mutex_lock(&writer->mutex);
if (writer->thread != NULL) { if (writer->thread != NULL) {
writer_thread = writer->thread; writer_thread = writer->thread;
writer->thread = NULL; writer->thread = NULL;
writer->stop = true; writer->stop = true;
uds_broadcast_cond(&writer->cond); uds_broadcast_cond(&writer->cond);
} }
uds_unlock_mutex(&writer->mutex); mutex_unlock(&writer->mutex);
if (writer_thread != NULL) if (writer_thread != NULL)
uds_join_threads(writer_thread); uds_join_threads(writer_thread);
...@@ -753,7 +753,6 @@ static void free_chapter_writer(struct chapter_writer *writer) ...@@ -753,7 +753,6 @@ static void free_chapter_writer(struct chapter_writer *writer)
return; return;
stop_chapter_writer(writer); stop_chapter_writer(writer);
uds_destroy_mutex(&writer->mutex);
uds_free_open_chapter_index(writer->open_chapter_index); uds_free_open_chapter_index(writer->open_chapter_index);
uds_free(writer->collated_records); uds_free(writer->collated_records);
uds_free(writer); uds_free(writer);
...@@ -774,12 +773,7 @@ static int make_chapter_writer(struct uds_index *index, ...@@ -774,12 +773,7 @@ static int make_chapter_writer(struct uds_index *index,
return result; return result;
writer->index = index; writer->index = index;
result = uds_init_mutex(&writer->mutex); mutex_init(&writer->mutex);
if (result != UDS_SUCCESS) {
uds_free(writer);
return result;
}
uds_init_cond(&writer->cond); uds_init_cond(&writer->cond);
result = uds_allocate_cache_aligned(collated_records_size, "collated records", result = uds_allocate_cache_aligned(collated_records_size, "collated records",
...@@ -957,9 +951,9 @@ static bool check_for_suspend(struct uds_index *index) ...@@ -957,9 +951,9 @@ static bool check_for_suspend(struct uds_index *index)
if (index->load_context == NULL) if (index->load_context == NULL)
return false; return false;
uds_lock_mutex(&index->load_context->mutex); mutex_lock(&index->load_context->mutex);
if (index->load_context->status != INDEX_SUSPENDING) { if (index->load_context->status != INDEX_SUSPENDING) {
uds_unlock_mutex(&index->load_context->mutex); mutex_unlock(&index->load_context->mutex);
return false; return false;
} }
...@@ -972,7 +966,7 @@ static bool check_for_suspend(struct uds_index *index) ...@@ -972,7 +966,7 @@ static bool check_for_suspend(struct uds_index *index)
uds_wait_cond(&index->load_context->cond, &index->load_context->mutex); uds_wait_cond(&index->load_context->cond, &index->load_context->mutex);
closing = (index->load_context->status == INDEX_FREEING); closing = (index->load_context->status == INDEX_FREEING);
uds_unlock_mutex(&index->load_context->mutex); mutex_unlock(&index->load_context->mutex);
return closing; return closing;
} }
...@@ -1261,14 +1255,14 @@ int uds_make_index(struct uds_configuration *config, enum uds_open_index_type op ...@@ -1261,14 +1255,14 @@ int uds_make_index(struct uds_configuration *config, enum uds_open_index_type op
} }
if (index->load_context != NULL) { if (index->load_context != NULL) {
uds_lock_mutex(&index->load_context->mutex); mutex_lock(&index->load_context->mutex);
index->load_context->status = INDEX_READY; index->load_context->status = INDEX_READY;
/* /*
* If we get here, suspend is meaningless, but notify any thread trying to suspend * If we get here, suspend is meaningless, but notify any thread trying to suspend
* us so it doesn't hang. * us so it doesn't hang.
*/ */
uds_broadcast_cond(&index->load_context->cond); uds_broadcast_cond(&index->load_context->cond);
uds_unlock_mutex(&index->load_context->mutex); mutex_unlock(&index->load_context->mutex);
} }
index->has_saved_open_chapter = loaded; index->has_saved_open_chapter = loaded;
...@@ -1307,10 +1301,10 @@ void uds_wait_for_idle_index(struct uds_index *index) ...@@ -1307,10 +1301,10 @@ void uds_wait_for_idle_index(struct uds_index *index)
{ {
struct chapter_writer *writer = index->chapter_writer; struct chapter_writer *writer = index->chapter_writer;
uds_lock_mutex(&writer->mutex); mutex_lock(&writer->mutex);
while (writer->zones_to_write > 0) while (writer->zones_to_write > 0)
uds_wait_cond(&writer->cond, &writer->mutex); uds_wait_cond(&writer->cond, &writer->mutex);
uds_unlock_mutex(&writer->mutex); mutex_unlock(&writer->mutex);
} }
/* This function assumes that all requests have been drained. */ /* This function assumes that all requests have been drained. */
......
...@@ -26,27 +26,4 @@ void uds_perform_once(atomic_t *once_state, void (*function) (void)); ...@@ -26,27 +26,4 @@ void uds_perform_once(atomic_t *once_state, void (*function) (void));
int uds_join_threads(struct thread *thread); int uds_join_threads(struct thread *thread);
/* FIXME: all below wrappers should be removed! */
static inline int __must_check uds_init_mutex(struct mutex *mutex)
{
mutex_init(mutex);
return UDS_SUCCESS;
}
static inline int uds_destroy_mutex(struct mutex *mutex)
{
return UDS_SUCCESS;
}
static inline void uds_lock_mutex(struct mutex *mutex)
{
mutex_lock(mutex);
}
static inline void uds_unlock_mutex(struct mutex *mutex)
{
mutex_unlock(mutex);
}
#endif /* UDS_THREADS_H */ #endif /* UDS_THREADS_H */
...@@ -286,13 +286,8 @@ void uds_free_volume_index(struct volume_index *volume_index) ...@@ -286,13 +286,8 @@ void uds_free_volume_index(struct volume_index *volume_index)
if (volume_index == NULL) if (volume_index == NULL)
return; return;
if (volume_index->zones != NULL) { if (volume_index->zones != NULL)
unsigned int zone;
for (zone = 0; zone < volume_index->zone_count; zone++)
uds_destroy_mutex(&volume_index->zones[zone].hook_mutex);
uds_free(uds_forget(volume_index->zones)); uds_free(uds_forget(volume_index->zones));
}
uninitialize_volume_sub_index(&volume_index->vi_non_hook); uninitialize_volume_sub_index(&volume_index->vi_non_hook);
uninitialize_volume_sub_index(&volume_index->vi_hook); uninitialize_volume_sub_index(&volume_index->vi_hook);
...@@ -546,10 +541,10 @@ int uds_get_volume_index_record(struct volume_index *volume_index, ...@@ -546,10 +541,10 @@ int uds_get_volume_index_record(struct volume_index *volume_index,
get_volume_sub_index_zone(&volume_index->vi_hook, name); get_volume_sub_index_zone(&volume_index->vi_hook, name);
struct mutex *mutex = &volume_index->zones[zone].hook_mutex; struct mutex *mutex = &volume_index->zones[zone].hook_mutex;
uds_lock_mutex(mutex); mutex_lock(mutex);
result = get_volume_sub_index_record(&volume_index->vi_hook, name, result = get_volume_sub_index_record(&volume_index->vi_hook, name,
record); record);
uds_unlock_mutex(mutex); mutex_unlock(mutex);
/* Remember the mutex so that other operations on the index record can use it. */ /* Remember the mutex so that other operations on the index record can use it. */
record->mutex = mutex; record->mutex = mutex;
} else { } else {
...@@ -578,13 +573,13 @@ int uds_put_volume_index_record(struct volume_index_record *record, u64 virtual_ ...@@ -578,13 +573,13 @@ int uds_put_volume_index_record(struct volume_index_record *record, u64 virtual_
} }
address = extract_address(sub_index, record->name); address = extract_address(sub_index, record->name);
if (unlikely(record->mutex != NULL)) if (unlikely(record->mutex != NULL))
uds_lock_mutex(record->mutex); mutex_lock(record->mutex);
result = uds_put_delta_index_entry(&record->delta_entry, address, result = uds_put_delta_index_entry(&record->delta_entry, address,
convert_virtual_to_index(sub_index, convert_virtual_to_index(sub_index,
virtual_chapter), virtual_chapter),
record->is_found ? record->name->name : NULL); record->is_found ? record->name->name : NULL);
if (unlikely(record->mutex != NULL)) if (unlikely(record->mutex != NULL))
uds_unlock_mutex(record->mutex); mutex_unlock(record->mutex);
switch (result) { switch (result) {
case UDS_SUCCESS: case UDS_SUCCESS:
record->virtual_chapter = virtual_chapter; record->virtual_chapter = virtual_chapter;
...@@ -614,10 +609,10 @@ int uds_remove_volume_index_record(struct volume_index_record *record) ...@@ -614,10 +609,10 @@ int uds_remove_volume_index_record(struct volume_index_record *record)
/* Mark the record so that it cannot be used again */ /* Mark the record so that it cannot be used again */
record->is_found = false; record->is_found = false;
if (unlikely(record->mutex != NULL)) if (unlikely(record->mutex != NULL))
uds_lock_mutex(record->mutex); mutex_lock(record->mutex);
result = uds_remove_delta_index_entry(&record->delta_entry); result = uds_remove_delta_index_entry(&record->delta_entry);
if (unlikely(record->mutex != NULL)) if (unlikely(record->mutex != NULL))
uds_unlock_mutex(record->mutex); mutex_unlock(record->mutex);
return result; return result;
} }
...@@ -688,10 +683,10 @@ void uds_set_volume_index_zone_open_chapter(struct volume_index *volume_index, ...@@ -688,10 +683,10 @@ void uds_set_volume_index_zone_open_chapter(struct volume_index *volume_index,
* chapter number is changing. * chapter number is changing.
*/ */
if (has_sparse(volume_index)) { if (has_sparse(volume_index)) {
uds_lock_mutex(mutex); mutex_lock(mutex);
set_volume_sub_index_zone_open_chapter(&volume_index->vi_hook, set_volume_sub_index_zone_open_chapter(&volume_index->vi_hook,
zone_number, virtual_chapter); zone_number, virtual_chapter);
uds_unlock_mutex(mutex); mutex_unlock(mutex);
} }
} }
...@@ -730,12 +725,12 @@ int uds_set_volume_index_record_chapter(struct volume_index_record *record, ...@@ -730,12 +725,12 @@ int uds_set_volume_index_record_chapter(struct volume_index_record *record,
} }
if (unlikely(record->mutex != NULL)) if (unlikely(record->mutex != NULL))
uds_lock_mutex(record->mutex); mutex_lock(record->mutex);
result = uds_set_delta_entry_value(&record->delta_entry, result = uds_set_delta_entry_value(&record->delta_entry,
convert_virtual_to_index(sub_index, convert_virtual_to_index(sub_index,
virtual_chapter)); virtual_chapter));
if (unlikely(record->mutex != NULL)) if (unlikely(record->mutex != NULL))
uds_unlock_mutex(record->mutex); mutex_unlock(record->mutex);
if (result != UDS_SUCCESS) if (result != UDS_SUCCESS)
return result; return result;
...@@ -785,9 +780,9 @@ u64 uds_lookup_volume_index_name(const struct volume_index *volume_index, ...@@ -785,9 +780,9 @@ u64 uds_lookup_volume_index_name(const struct volume_index *volume_index,
if (!uds_is_volume_index_sample(volume_index, name)) if (!uds_is_volume_index_sample(volume_index, name))
return NO_CHAPTER; return NO_CHAPTER;
uds_lock_mutex(mutex); mutex_lock(mutex);
virtual_chapter = lookup_volume_sub_index_name(&volume_index->vi_hook, name); virtual_chapter = lookup_volume_sub_index_name(&volume_index->vi_hook, name);
uds_unlock_mutex(mutex); mutex_unlock(mutex);
return virtual_chapter; return virtual_chapter;
} }
...@@ -1258,13 +1253,8 @@ int uds_make_volume_index(const struct uds_configuration *config, u64 volume_non ...@@ -1258,13 +1253,8 @@ int uds_make_volume_index(const struct uds_configuration *config, u64 volume_non
return result; return result;
} }
for (zone = 0; zone < config->zone_count; zone++) { for (zone = 0; zone < config->zone_count; zone++)
result = uds_init_mutex(&volume_index->zones[zone].hook_mutex); mutex_init(&volume_index->zones[zone].hook_mutex);
if (result != UDS_SUCCESS) {
uds_free_volume_index(volume_index);
return result;
}
}
split_configuration(config, &split); split_configuration(config, &split);
result = initialize_volume_sub_index(&split.non_hook_config, volume_nonce, 'd', result = initialize_volume_sub_index(&split.non_hook_config, volume_nonce, 'd',
......
...@@ -554,7 +554,7 @@ static int process_entry(struct volume *volume, struct queued_read *entry) ...@@ -554,7 +554,7 @@ static int process_entry(struct volume *volume, struct queued_read *entry)
page = select_victim_in_cache(&volume->page_cache); page = select_victim_in_cache(&volume->page_cache);
uds_unlock_mutex(&volume->read_threads_mutex); mutex_unlock(&volume->read_threads_mutex);
page_data = dm_bufio_read(volume->client, page_number, &page->buffer); page_data = dm_bufio_read(volume->client, page_number, &page->buffer);
if (IS_ERR(page_data)) { if (IS_ERR(page_data)) {
result = -PTR_ERR(page_data); result = -PTR_ERR(page_data);
...@@ -564,7 +564,7 @@ static int process_entry(struct volume *volume, struct queued_read *entry) ...@@ -564,7 +564,7 @@ static int process_entry(struct volume *volume, struct queued_read *entry)
cancel_page_in_cache(&volume->page_cache, page_number, page); cancel_page_in_cache(&volume->page_cache, page_number, page);
return result; return result;
} }
uds_lock_mutex(&volume->read_threads_mutex); mutex_lock(&volume->read_threads_mutex);
if (entry->invalid) { if (entry->invalid) {
uds_log_warning("Page %u invalidated after read", page_number); uds_log_warning("Page %u invalidated after read", page_number);
...@@ -626,7 +626,7 @@ static void read_thread_function(void *arg) ...@@ -626,7 +626,7 @@ static void read_thread_function(void *arg)
struct volume *volume = arg; struct volume *volume = arg;
uds_log_debug("reader starting"); uds_log_debug("reader starting");
uds_lock_mutex(&volume->read_threads_mutex); mutex_lock(&volume->read_threads_mutex);
while (true) { while (true) {
struct queued_read *queue_entry; struct queued_read *queue_entry;
int result; int result;
...@@ -638,7 +638,7 @@ static void read_thread_function(void *arg) ...@@ -638,7 +638,7 @@ static void read_thread_function(void *arg)
result = process_entry(volume, queue_entry); result = process_entry(volume, queue_entry);
release_queued_requests(volume, queue_entry, result); release_queued_requests(volume, queue_entry, result);
} }
uds_unlock_mutex(&volume->read_threads_mutex); mutex_unlock(&volume->read_threads_mutex);
uds_log_debug("reader done"); uds_log_debug("reader done");
} }
...@@ -769,7 +769,7 @@ static int get_volume_page_protected(struct volume *volume, struct uds_request * ...@@ -769,7 +769,7 @@ static int get_volume_page_protected(struct volume *volume, struct uds_request *
/* Prepare to enqueue a read for the page. */ /* Prepare to enqueue a read for the page. */
end_pending_search(&volume->page_cache, request->zone_number); end_pending_search(&volume->page_cache, request->zone_number);
uds_lock_mutex(&volume->read_threads_mutex); mutex_lock(&volume->read_threads_mutex);
/* /*
* Do the lookup again while holding the read mutex (no longer the fast case so this should * Do the lookup again while holding the read mutex (no longer the fast case so this should
...@@ -787,7 +787,7 @@ static int get_volume_page_protected(struct volume *volume, struct uds_request * ...@@ -787,7 +787,7 @@ static int get_volume_page_protected(struct volume *volume, struct uds_request *
* turns out to be significant in some cases. The page is not available yet so * turns out to be significant in some cases. The page is not available yet so
* the order does not matter for correctness as it does below. * the order does not matter for correctness as it does below.
*/ */
uds_unlock_mutex(&volume->read_threads_mutex); mutex_unlock(&volume->read_threads_mutex);
begin_pending_search(&volume->page_cache, physical_page, begin_pending_search(&volume->page_cache, physical_page,
request->zone_number); request->zone_number);
return UDS_QUEUED; return UDS_QUEUED;
...@@ -799,7 +799,7 @@ static int get_volume_page_protected(struct volume *volume, struct uds_request * ...@@ -799,7 +799,7 @@ static int get_volume_page_protected(struct volume *volume, struct uds_request *
* the caller gets to look at it. * the caller gets to look at it.
*/ */
begin_pending_search(&volume->page_cache, physical_page, request->zone_number); begin_pending_search(&volume->page_cache, physical_page, request->zone_number);
uds_unlock_mutex(&volume->read_threads_mutex); mutex_unlock(&volume->read_threads_mutex);
*page_ptr = page; *page_ptr = page;
return UDS_SUCCESS; return UDS_SUCCESS;
} }
...@@ -810,9 +810,9 @@ static int get_volume_page(struct volume *volume, u32 chapter, u32 page_number, ...@@ -810,9 +810,9 @@ static int get_volume_page(struct volume *volume, u32 chapter, u32 page_number,
int result; int result;
u32 physical_page = map_to_physical_page(volume->geometry, chapter, page_number); u32 physical_page = map_to_physical_page(volume->geometry, chapter, page_number);
uds_lock_mutex(&volume->read_threads_mutex); mutex_lock(&volume->read_threads_mutex);
result = get_volume_page_locked(volume, physical_page, page_ptr); result = get_volume_page_locked(volume, physical_page, page_ptr);
uds_unlock_mutex(&volume->read_threads_mutex); mutex_unlock(&volume->read_threads_mutex);
return result; return result;
} }
...@@ -1053,10 +1053,10 @@ void uds_forget_chapter(struct volume *volume, u64 virtual_chapter) ...@@ -1053,10 +1053,10 @@ void uds_forget_chapter(struct volume *volume, u64 virtual_chapter)
u32 i; u32 i;
uds_log_debug("forgetting chapter %llu", (unsigned long long) virtual_chapter); uds_log_debug("forgetting chapter %llu", (unsigned long long) virtual_chapter);
uds_lock_mutex(&volume->read_threads_mutex); mutex_lock(&volume->read_threads_mutex);
for (i = 0; i < volume->geometry->pages_per_chapter; i++) for (i = 0; i < volume->geometry->pages_per_chapter; i++)
invalidate_page(&volume->page_cache, first_page + i); invalidate_page(&volume->page_cache, first_page + i);
uds_unlock_mutex(&volume->read_threads_mutex); mutex_unlock(&volume->read_threads_mutex);
} }
/* /*
...@@ -1141,10 +1141,10 @@ static int write_index_pages(struct volume *volume, u32 physical_chapter_number, ...@@ -1141,10 +1141,10 @@ static int write_index_pages(struct volume *volume, u32 physical_chapter_number,
physical_chapter_number, index_page_number, physical_chapter_number, index_page_number,
delta_list_number - 1); delta_list_number - 1);
uds_lock_mutex(&volume->read_threads_mutex); mutex_lock(&volume->read_threads_mutex);
result = donate_index_page_locked(volume, physical_chapter_number, result = donate_index_page_locked(volume, physical_chapter_number,
index_page_number, page_buffer); index_page_number, page_buffer);
uds_unlock_mutex(&volume->read_threads_mutex); mutex_unlock(&volume->read_threads_mutex);
if (result != UDS_SUCCESS) { if (result != UDS_SUCCESS) {
dm_bufio_release(page_buffer); dm_bufio_release(page_buffer);
return result; return result;
...@@ -1621,12 +1621,7 @@ int uds_make_volume(const struct uds_configuration *config, struct index_layout ...@@ -1621,12 +1621,7 @@ int uds_make_volume(const struct uds_configuration *config, struct index_layout
return result; return result;
} }
result = uds_init_mutex(&volume->read_threads_mutex); mutex_init(&volume->read_threads_mutex);
if (result != UDS_SUCCESS) {
uds_free_volume(volume);
return result;
}
uds_init_cond(&volume->read_threads_read_done_cond); uds_init_cond(&volume->read_threads_read_done_cond);
uds_init_cond(&volume->read_threads_cond); uds_init_cond(&volume->read_threads_cond);
...@@ -1675,10 +1670,10 @@ void uds_free_volume(struct volume *volume) ...@@ -1675,10 +1670,10 @@ void uds_free_volume(struct volume *volume)
unsigned int i; unsigned int i;
/* This works even if some threads weren't started. */ /* This works even if some threads weren't started. */
uds_lock_mutex(&volume->read_threads_mutex); mutex_lock(&volume->read_threads_mutex);
volume->read_threads_exiting = true; volume->read_threads_exiting = true;
uds_broadcast_cond(&volume->read_threads_cond); uds_broadcast_cond(&volume->read_threads_cond);
uds_unlock_mutex(&volume->read_threads_mutex); mutex_unlock(&volume->read_threads_mutex);
for (i = 0; i < volume->read_thread_count; i++) for (i = 0; i < volume->read_thread_count; i++)
uds_join_threads(volume->reader_threads[i]); uds_join_threads(volume->reader_threads[i]);
uds_free(volume->reader_threads); uds_free(volume->reader_threads);
...@@ -1691,7 +1686,6 @@ void uds_free_volume(struct volume *volume) ...@@ -1691,7 +1686,6 @@ void uds_free_volume(struct volume *volume)
if (volume->client != NULL) if (volume->client != NULL)
dm_bufio_client_destroy(uds_forget(volume->client)); dm_bufio_client_destroy(uds_forget(volume->client));
uds_destroy_mutex(&volume->read_threads_mutex);
uds_free_index_page_map(volume->index_page_map); uds_free_index_page_map(volume->index_page_map);
uds_free_radix_sorter(volume->radix_sorter); uds_free_radix_sorter(volume->radix_sorter);
uds_free(volume->geometry); uds_free(volume->geometry);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment