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
This diff is collapsed.
......@@ -180,11 +180,11 @@ static int finish_previous_chapter(struct uds_index *index, u64 current_chapter_
int result;
struct chapter_writer *writer = index->chapter_writer;
uds_lock_mutex(&writer->mutex);
mutex_lock(&writer->mutex);
while (index->newest_virtual_chapter < current_chapter_number)
uds_wait_cond(&writer->cond, &writer->mutex);
result = writer->result;
uds_unlock_mutex(&writer->mutex);
mutex_unlock(&writer->mutex);
if (result != UDS_SUCCESS)
return uds_log_error_strerror(result,
......@@ -219,11 +219,11 @@ static unsigned int start_closing_chapter(struct uds_index *index,
unsigned int finished_zones;
struct chapter_writer *writer = index->chapter_writer;
uds_lock_mutex(&writer->mutex);
mutex_lock(&writer->mutex);
finished_zones = ++writer->zones_to_write;
writer->chapters[zone_number] = chapter;
uds_broadcast_cond(&writer->cond);
uds_unlock_mutex(&writer->mutex);
mutex_unlock(&writer->mutex);
return finished_zones;
}
......@@ -678,7 +678,7 @@ static void close_chapters(void *arg)
struct uds_index *index = writer->index;
uds_log_debug("chapter writer starting");
uds_lock_mutex(&writer->mutex);
mutex_lock(&writer->mutex);
for (;;) {
while (writer->zones_to_write < index->zone_count) {
if (writer->stop && (writer->zones_to_write == 0)) {
......@@ -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
* open chapter, so we can exit now.
*/
uds_unlock_mutex(&writer->mutex);
mutex_unlock(&writer->mutex);
uds_log_debug("chapter writer stopping");
return;
}
......@@ -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
* 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) {
/*
......@@ -719,7 +719,7 @@ static void close_chapters(void *arg)
writer->collated_records,
index->newest_virtual_chapter);
uds_lock_mutex(&writer->mutex);
mutex_lock(&writer->mutex);
index->newest_virtual_chapter++;
index->oldest_virtual_chapter +=
uds_chapters_to_expire(index->volume->geometry,
......@@ -734,14 +734,14 @@ static void stop_chapter_writer(struct chapter_writer *writer)
{
struct thread *writer_thread = NULL;
uds_lock_mutex(&writer->mutex);
mutex_lock(&writer->mutex);
if (writer->thread != NULL) {
writer_thread = writer->thread;
writer->thread = NULL;
writer->stop = true;
uds_broadcast_cond(&writer->cond);
}
uds_unlock_mutex(&writer->mutex);
mutex_unlock(&writer->mutex);
if (writer_thread != NULL)
uds_join_threads(writer_thread);
......@@ -753,7 +753,6 @@ static void free_chapter_writer(struct chapter_writer *writer)
return;
stop_chapter_writer(writer);
uds_destroy_mutex(&writer->mutex);
uds_free_open_chapter_index(writer->open_chapter_index);
uds_free(writer->collated_records);
uds_free(writer);
......@@ -774,12 +773,7 @@ static int make_chapter_writer(struct uds_index *index,
return result;
writer->index = index;
result = uds_init_mutex(&writer->mutex);
if (result != UDS_SUCCESS) {
uds_free(writer);
return result;
}
mutex_init(&writer->mutex);
uds_init_cond(&writer->cond);
result = uds_allocate_cache_aligned(collated_records_size, "collated records",
......@@ -957,9 +951,9 @@ static bool check_for_suspend(struct uds_index *index)
if (index->load_context == NULL)
return false;
uds_lock_mutex(&index->load_context->mutex);
mutex_lock(&index->load_context->mutex);
if (index->load_context->status != INDEX_SUSPENDING) {
uds_unlock_mutex(&index->load_context->mutex);
mutex_unlock(&index->load_context->mutex);
return false;
}
......@@ -972,7 +966,7 @@ static bool check_for_suspend(struct uds_index *index)
uds_wait_cond(&index->load_context->cond, &index->load_context->mutex);
closing = (index->load_context->status == INDEX_FREEING);
uds_unlock_mutex(&index->load_context->mutex);
mutex_unlock(&index->load_context->mutex);
return closing;
}
......@@ -1261,14 +1255,14 @@ int uds_make_index(struct uds_configuration *config, enum uds_open_index_type op
}
if (index->load_context != NULL) {
uds_lock_mutex(&index->load_context->mutex);
mutex_lock(&index->load_context->mutex);
index->load_context->status = INDEX_READY;
/*
* If we get here, suspend is meaningless, but notify any thread trying to suspend
* us so it doesn't hang.
*/
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;
......@@ -1307,10 +1301,10 @@ void uds_wait_for_idle_index(struct uds_index *index)
{
struct chapter_writer *writer = index->chapter_writer;
uds_lock_mutex(&writer->mutex);
mutex_lock(&writer->mutex);
while (writer->zones_to_write > 0)
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. */
......
......@@ -26,27 +26,4 @@ void uds_perform_once(atomic_t *once_state, void (*function) (void));
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 */
......@@ -286,13 +286,8 @@ void uds_free_volume_index(struct volume_index *volume_index)
if (volume_index == NULL)
return;
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);
if (volume_index->zones != NULL)
uds_free(uds_forget(volume_index->zones));
}
uninitialize_volume_sub_index(&volume_index->vi_non_hook);
uninitialize_volume_sub_index(&volume_index->vi_hook);
......@@ -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);
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,
record);
uds_unlock_mutex(mutex);
mutex_unlock(mutex);
/* Remember the mutex so that other operations on the index record can use it. */
record->mutex = mutex;
} else {
......@@ -578,13 +573,13 @@ int uds_put_volume_index_record(struct volume_index_record *record, u64 virtual_
}
address = extract_address(sub_index, record->name);
if (unlikely(record->mutex != NULL))
uds_lock_mutex(record->mutex);
mutex_lock(record->mutex);
result = uds_put_delta_index_entry(&record->delta_entry, address,
convert_virtual_to_index(sub_index,
virtual_chapter),
record->is_found ? record->name->name : NULL);
if (unlikely(record->mutex != NULL))
uds_unlock_mutex(record->mutex);
mutex_unlock(record->mutex);
switch (result) {
case UDS_SUCCESS:
record->virtual_chapter = virtual_chapter;
......@@ -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 */
record->is_found = false;
if (unlikely(record->mutex != NULL))
uds_lock_mutex(record->mutex);
mutex_lock(record->mutex);
result = uds_remove_delta_index_entry(&record->delta_entry);
if (unlikely(record->mutex != NULL))
uds_unlock_mutex(record->mutex);
mutex_unlock(record->mutex);
return result;
}
......@@ -688,10 +683,10 @@ void uds_set_volume_index_zone_open_chapter(struct volume_index *volume_index,
* chapter number is changing.
*/
if (has_sparse(volume_index)) {
uds_lock_mutex(mutex);
mutex_lock(mutex);
set_volume_sub_index_zone_open_chapter(&volume_index->vi_hook,
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,
}
if (unlikely(record->mutex != NULL))
uds_lock_mutex(record->mutex);
mutex_lock(record->mutex);
result = uds_set_delta_entry_value(&record->delta_entry,
convert_virtual_to_index(sub_index,
virtual_chapter));
if (unlikely(record->mutex != NULL))
uds_unlock_mutex(record->mutex);
mutex_unlock(record->mutex);
if (result != UDS_SUCCESS)
return result;
......@@ -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))
return NO_CHAPTER;
uds_lock_mutex(mutex);
mutex_lock(mutex);
virtual_chapter = lookup_volume_sub_index_name(&volume_index->vi_hook, name);
uds_unlock_mutex(mutex);
mutex_unlock(mutex);
return virtual_chapter;
}
......@@ -1258,13 +1253,8 @@ int uds_make_volume_index(const struct uds_configuration *config, u64 volume_non
return result;
}
for (zone = 0; zone < config->zone_count; zone++) {
result = uds_init_mutex(&volume_index->zones[zone].hook_mutex);
if (result != UDS_SUCCESS) {
uds_free_volume_index(volume_index);
return result;
}
}
for (zone = 0; zone < config->zone_count; zone++)
mutex_init(&volume_index->zones[zone].hook_mutex);
split_configuration(config, &split);
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)
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);
if (IS_ERR(page_data)) {
result = -PTR_ERR(page_data);
......@@ -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);
return result;
}
uds_lock_mutex(&volume->read_threads_mutex);
mutex_lock(&volume->read_threads_mutex);
if (entry->invalid) {
uds_log_warning("Page %u invalidated after read", page_number);
......@@ -626,7 +626,7 @@ static void read_thread_function(void *arg)
struct volume *volume = arg;
uds_log_debug("reader starting");
uds_lock_mutex(&volume->read_threads_mutex);
mutex_lock(&volume->read_threads_mutex);
while (true) {
struct queued_read *queue_entry;
int result;
......@@ -638,7 +638,7 @@ static void read_thread_function(void *arg)
result = process_entry(volume, queue_entry);
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");
}
......@@ -769,7 +769,7 @@ static int get_volume_page_protected(struct volume *volume, struct uds_request *
/* Prepare to enqueue a read for the page. */
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
......@@ -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
* 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,
request->zone_number);
return UDS_QUEUED;
......@@ -799,7 +799,7 @@ static int get_volume_page_protected(struct volume *volume, struct uds_request *
* the caller gets to look at it.
*/
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;
return UDS_SUCCESS;
}
......@@ -810,9 +810,9 @@ static int get_volume_page(struct volume *volume, u32 chapter, u32 page_number,
int result;
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);
uds_unlock_mutex(&volume->read_threads_mutex);
mutex_unlock(&volume->read_threads_mutex);
return result;
}
......@@ -1053,10 +1053,10 @@ void uds_forget_chapter(struct volume *volume, u64 virtual_chapter)
u32 i;
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++)
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,
physical_chapter_number, index_page_number,
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,
index_page_number, page_buffer);
uds_unlock_mutex(&volume->read_threads_mutex);
mutex_unlock(&volume->read_threads_mutex);
if (result != UDS_SUCCESS) {
dm_bufio_release(page_buffer);
return result;
......@@ -1621,12 +1621,7 @@ int uds_make_volume(const struct uds_configuration *config, struct index_layout
return result;
}
result = uds_init_mutex(&volume->read_threads_mutex);
if (result != UDS_SUCCESS) {
uds_free_volume(volume);
return result;
}
mutex_init(&volume->read_threads_mutex);
uds_init_cond(&volume->read_threads_read_done_cond);
uds_init_cond(&volume->read_threads_cond);
......@@ -1675,10 +1670,10 @@ void uds_free_volume(struct volume *volume)
unsigned int i;
/* 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;
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++)
uds_join_threads(volume->reader_threads[i]);
uds_free(volume->reader_threads);
......@@ -1691,7 +1686,6 @@ void uds_free_volume(struct volume *volume)
if (volume->client != NULL)
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_radix_sorter(volume->radix_sorter);
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