Commit 6a79248b authored by Mike Snitzer's avatar Mike Snitzer
Browse files

dm vdo permassert: audit all of ASSERT to test for VDO_SUCCESS



Also rename ASSERT to VDO_ASSERT and ASSERT_LOG_ONLY to
VDO_ASSERT_LOG_ONLY.

But re-introduce ASSERT and ASSERT_LOG_ONLY as a placeholder
for the benefit of dm-vdo/indexer.

Signed-off-by: default avatarMike Snitzer <snitzer@kernel.org>
Signed-off-by: default avatarMatthew Sakai <msakai@redhat.com>
parent a958c53a
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -177,7 +177,7 @@ static void apply_to_zone(struct vdo_completion *completion)
	zone_count_t zone;
	struct action_manager *manager = as_action_manager(completion);

	ASSERT_LOG_ONLY((vdo_get_callback_thread_id() == get_acting_zone_thread_id(manager)),
	VDO_ASSERT_LOG_ONLY((vdo_get_callback_thread_id() == get_acting_zone_thread_id(manager)),
			    "%s() called on acting zones's thread", __func__);

	zone = manager->acting_zone++;
@@ -357,7 +357,7 @@ bool vdo_schedule_operation_with_context(struct action_manager *manager,
{
	struct action *current_action;

	ASSERT_LOG_ONLY((vdo_get_callback_thread_id() == manager->initiator_thread_id),
	VDO_ASSERT_LOG_ONLY((vdo_get_callback_thread_id() == manager->initiator_thread_id),
			    "action initiated from correct thread");
	if (!manager->current_action->in_use) {
		current_action = manager->current_action;
+59 −59
Original line number Diff line number Diff line
@@ -246,7 +246,7 @@ static inline void assert_on_cache_thread(struct vdo_page_cache *cache,
{
	thread_id_t thread_id = vdo_get_callback_thread_id();

	ASSERT_LOG_ONLY((thread_id == cache->zone->thread_id),
	VDO_ASSERT_LOG_ONLY((thread_id == cache->zone->thread_id),
			    "%s() must only be called on cache thread %d, not thread %d",
			    function_name, cache->zone->thread_id, thread_id);
}
@@ -254,7 +254,7 @@ static inline void assert_on_cache_thread(struct vdo_page_cache *cache,
/** assert_io_allowed() - Assert that a page cache may issue I/O. */
static inline void assert_io_allowed(struct vdo_page_cache *cache)
{
	ASSERT_LOG_ONLY(!vdo_is_state_quiescent(&cache->zone->state),
	VDO_ASSERT_LOG_ONLY(!vdo_is_state_quiescent(&cache->zone->state),
			    "VDO page cache may issue I/O");
}

@@ -287,9 +287,9 @@ static const char * __must_check get_page_state_name(enum vdo_page_buffer_state

	BUILD_BUG_ON(ARRAY_SIZE(state_names) != PAGE_STATE_COUNT);

	result = ASSERT(state < ARRAY_SIZE(state_names),
	result = VDO_ASSERT(state < ARRAY_SIZE(state_names),
			    "Unknown page_state value %d", state);
	if (result != UDS_SUCCESS)
	if (result != VDO_SUCCESS)
		return "[UNKNOWN PAGE STATE]";

	return state_names[state];
@@ -378,7 +378,7 @@ static int __must_check set_info_pbn(struct page_info *info, physical_block_numb
	struct vdo_page_cache *cache = info->cache;

	/* Either the new or the old page number must be NO_PAGE. */
	int result = ASSERT((pbn == NO_PAGE) || (info->pbn == NO_PAGE),
	int result = VDO_ASSERT((pbn == NO_PAGE) || (info->pbn == NO_PAGE),
				"Must free a page before reusing it.");
	if (result != VDO_SUCCESS)
		return result;
@@ -401,13 +401,13 @@ static int reset_page_info(struct page_info *info)
{
	int result;

	result = ASSERT(info->busy == 0, "VDO Page must not be busy");
	if (result != UDS_SUCCESS)
	result = VDO_ASSERT(info->busy == 0, "VDO Page must not be busy");
	if (result != VDO_SUCCESS)
		return result;

	result = ASSERT(!vdo_waitq_has_waiters(&info->waiting),
	result = VDO_ASSERT(!vdo_waitq_has_waiters(&info->waiting),
			    "VDO Page must not have waiters");
	if (result != UDS_SUCCESS)
	if (result != VDO_SUCCESS)
		return result;

	result = set_info_pbn(info, NO_PAGE);
@@ -592,29 +592,29 @@ static int __must_check validate_completed_page(struct vdo_page_completion *comp
{
	int result;

	result = ASSERT(completion->ready, "VDO Page completion not ready");
	if (result != UDS_SUCCESS)
	result = VDO_ASSERT(completion->ready, "VDO Page completion not ready");
	if (result != VDO_SUCCESS)
		return result;

	result = ASSERT(completion->info != NULL,
	result = VDO_ASSERT(completion->info != NULL,
			    "VDO Page Completion must be complete");
	if (result != UDS_SUCCESS)
	if (result != VDO_SUCCESS)
		return result;

	result = ASSERT(completion->info->pbn == completion->pbn,
	result = VDO_ASSERT(completion->info->pbn == completion->pbn,
			    "VDO Page Completion pbn must be consistent");
	if (result != UDS_SUCCESS)
	if (result != VDO_SUCCESS)
		return result;

	result = ASSERT(is_valid(completion->info),
	result = VDO_ASSERT(is_valid(completion->info),
			    "VDO Page Completion page must be valid");
	if (result != UDS_SUCCESS)
	if (result != VDO_SUCCESS)
		return result;

	if (writable) {
		result = ASSERT(completion->writable,
		result = VDO_ASSERT(completion->writable,
				    "VDO Page Completion must be writable");
		if (result != UDS_SUCCESS)
		if (result != VDO_SUCCESS)
			return result;
	}

@@ -776,7 +776,7 @@ static int __must_check launch_page_load(struct page_info *info,
	if (result != VDO_SUCCESS)
		return result;

	result = ASSERT((info->busy == 0), "Page is not busy before loading.");
	result = VDO_ASSERT((info->busy == 0), "Page is not busy before loading.");
	if (result != VDO_SUCCESS)
		return result;

@@ -949,7 +949,7 @@ static void discard_a_page(struct vdo_page_cache *cache)
		return;
	}

	ASSERT_LOG_ONLY(!is_in_flight(info),
	VDO_ASSERT_LOG_ONLY(!is_in_flight(info),
			    "page selected for discard is not in flight");

	cache->discard_count++;
@@ -1153,7 +1153,7 @@ void vdo_release_page_completion(struct vdo_completion *completion)
			discard_info = page_completion->info;
	}

	ASSERT_LOG_ONLY((page_completion->waiter.next_waiter == NULL),
	VDO_ASSERT_LOG_ONLY((page_completion->waiter.next_waiter == NULL),
			    "Page being released after leaving all queues");

	page_completion->info = NULL;
@@ -1217,7 +1217,7 @@ void vdo_get_page(struct vdo_page_completion *page_completion,
	struct page_info *info;

	assert_on_cache_thread(cache, __func__);
	ASSERT_LOG_ONLY((page_completion->waiter.next_waiter == NULL),
	VDO_ASSERT_LOG_ONLY((page_completion->waiter.next_waiter == NULL),
			    "New page completion was not already on a wait queue");

	*page_completion = (struct vdo_page_completion) {
@@ -1265,7 +1265,7 @@ void vdo_get_page(struct vdo_page_completion *page_completion,
		}

		/* Something horrible has gone wrong. */
		ASSERT_LOG_ONLY(false, "Info found in a usable state.");
		VDO_ASSERT_LOG_ONLY(false, "Info found in a usable state.");
	}

	/* The page must be fetched. */
@@ -1334,7 +1334,7 @@ int vdo_invalidate_page_cache(struct vdo_page_cache *cache)

	/* Make sure we don't throw away any dirty pages. */
	for (info = cache->infos; info < cache->infos + cache->page_count; info++) {
		int result = ASSERT(!is_dirty(info), "cache must have no dirty pages");
		int result = VDO_ASSERT(!is_dirty(info), "cache must have no dirty pages");

		if (result != VDO_SUCCESS)
			return result;
@@ -1440,7 +1440,7 @@ static bool __must_check is_not_older(struct block_map_zone *zone, u8 a, u8 b)
{
	int result;

	result = ASSERT((in_cyclic_range(zone->oldest_generation, a, zone->generation, 1 << 8) &&
	result = VDO_ASSERT((in_cyclic_range(zone->oldest_generation, a, zone->generation, 1 << 8) &&
			     in_cyclic_range(zone->oldest_generation, b, zone->generation, 1 << 8)),
			    "generation(s) %u, %u are out of range [%u, %u]",
			    a, b, zone->oldest_generation, zone->generation);
@@ -1456,7 +1456,7 @@ static void release_generation(struct block_map_zone *zone, u8 generation)
{
	int result;

	result = ASSERT((zone->dirty_page_counts[generation] > 0),
	result = VDO_ASSERT((zone->dirty_page_counts[generation] > 0),
			    "dirty page count underflow for generation %u", generation);
	if (result != VDO_SUCCESS) {
		enter_zone_read_only_mode(zone, result);
@@ -1482,7 +1482,7 @@ static void set_generation(struct block_map_zone *zone, struct tree_page *page,

	page->generation = new_generation;
	new_count = ++zone->dirty_page_counts[new_generation];
	result = ASSERT((new_count != 0), "dirty page count overflow for generation %u",
	result = VDO_ASSERT((new_count != 0), "dirty page count overflow for generation %u",
			    new_generation);
	if (result != VDO_SUCCESS) {
		enter_zone_read_only_mode(zone, result);
@@ -1698,13 +1698,13 @@ static void release_page_lock(struct data_vio *data_vio, char *what)
	struct tree_lock *lock_holder;
	struct tree_lock *lock = &data_vio->tree_lock;

	ASSERT_LOG_ONLY(lock->locked,
	VDO_ASSERT_LOG_ONLY(lock->locked,
			    "release of unlocked block map page %s for key %llu in tree %u",
			    what, (unsigned long long) lock->key, lock->root_index);

	zone = data_vio->logical.zone->block_map_zone;
	lock_holder = vdo_int_map_remove(zone->loading_pages, lock->key);
	ASSERT_LOG_ONLY((lock_holder == lock),
	VDO_ASSERT_LOG_ONLY((lock_holder == lock),
			    "block map page %s mismatch for key %llu in tree %u",
			    what, (unsigned long long) lock->key, lock->root_index);
	lock->locked = false;
@@ -2008,7 +2008,7 @@ static void write_expired_elements(struct block_map_zone *zone)

		list_del_init(&page->entry);

		result = ASSERT(!vdo_waiter_is_waiting(&page->waiter),
		result = VDO_ASSERT(!vdo_waiter_is_waiting(&page->waiter),
				    "Newly expired page not already waiting to write");
		if (result != VDO_SUCCESS) {
			enter_zone_read_only_mode(zone, result);
@@ -2867,8 +2867,8 @@ int vdo_decode_block_map(struct block_map_state_2_0 state, block_count_t logical
	BUILD_BUG_ON(VDO_BLOCK_MAP_ENTRIES_PER_PAGE !=
		     ((VDO_BLOCK_SIZE - sizeof(struct block_map_page)) /
		      sizeof(struct block_map_entry)));
	result = ASSERT(cache_size > 0, "block map cache size is specified");
	if (result != UDS_SUCCESS)
	result = VDO_ASSERT(cache_size > 0, "block map cache size is specified");
	if (result != VDO_SUCCESS)
		return result;

	result = vdo_allocate_extended(struct block_map,
@@ -2937,7 +2937,7 @@ void vdo_initialize_block_map_from_journal(struct block_map *map,
	for (z = 0; z < map->zone_count; z++) {
		struct dirty_lists *dirty_lists = map->zones[z].dirty_lists;

		ASSERT_LOG_ONLY(dirty_lists->next_period == 0, "current period not set");
		VDO_ASSERT_LOG_ONLY(dirty_lists->next_period == 0, "current period not set");
		dirty_lists->oldest_period = map->current_era_point;
		dirty_lists->next_period = map->current_era_point + 1;
		dirty_lists->offset = map->current_era_point % dirty_lists->maximum_age;
@@ -2971,7 +2971,7 @@ static void initiate_drain(struct admin_state *state)
{
	struct block_map_zone *zone = container_of(state, struct block_map_zone, state);

	ASSERT_LOG_ONLY((zone->active_lookups == 0),
	VDO_ASSERT_LOG_ONLY((zone->active_lookups == 0),
			    "%s() called with no active lookups", __func__);

	if (!vdo_is_state_suspending(state)) {
+5 −5
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ void vdo_initialize_completion(struct vdo_completion *completion,

static inline void assert_incomplete(struct vdo_completion *completion)
{
	ASSERT_LOG_ONLY(!completion->complete, "completion is not complete");
	VDO_ASSERT_LOG_ONLY(!completion->complete, "completion is not complete");
}

/**
@@ -111,10 +111,10 @@ void vdo_enqueue_completion(struct vdo_completion *completion,
	struct vdo *vdo = completion->vdo;
	thread_id_t thread_id = completion->callback_thread_id;

	if (ASSERT(thread_id < vdo->thread_config.thread_count,
	if (VDO_ASSERT(thread_id < vdo->thread_config.thread_count,
		       "thread_id %u (completion type %d) is less than thread count %u",
		       thread_id, completion->type,
		   vdo->thread_config.thread_count) != UDS_SUCCESS)
		       vdo->thread_config.thread_count) != VDO_SUCCESS)
		BUG();

	completion->requeue = false;
+3 −3
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ static inline void vdo_fail_completion(struct vdo_completion *completion, int re
static inline int vdo_assert_completion_type(struct vdo_completion *completion,
					     enum vdo_completion_type expected)
{
	return ASSERT(expected == completion->type,
	return VDO_ASSERT(expected == completion->type,
			  "completion type should be %u, not %u", expected,
			  completion->type);
}
+54 −54
Original line number Diff line number Diff line
@@ -232,7 +232,7 @@ static bool check_for_drain_complete_locked(struct data_vio_pool *pool)
	if (pool->limiter.busy > 0)
		return false;

	ASSERT_LOG_ONLY((pool->discard_limiter.busy == 0),
	VDO_ASSERT_LOG_ONLY((pool->discard_limiter.busy == 0),
			    "no outstanding discard permits");

	return (bio_list_empty(&pool->limiter.new_waiters) &&
@@ -277,7 +277,7 @@ static void acknowledge_data_vio(struct data_vio *data_vio)
	if (bio == NULL)
		return;

	ASSERT_LOG_ONLY((data_vio->remaining_discard <=
	VDO_ASSERT_LOG_ONLY((data_vio->remaining_discard <=
			     (u32) (VDO_BLOCK_SIZE - data_vio->offset)),
			    "data_vio to acknowledge is not an incomplete discard");

@@ -443,7 +443,7 @@ static void attempt_logical_block_lock(struct vdo_completion *completion)
		return;
	}

	result = ASSERT(lock_holder->logical.locked, "logical block lock held");
	result = VDO_ASSERT(lock_holder->logical.locked, "logical block lock held");
	if (result != VDO_SUCCESS) {
		continue_data_vio_with_error(data_vio, result);
		return;
@@ -627,7 +627,7 @@ static void update_limiter(struct limiter *limiter)
	struct bio_list *waiters = &limiter->waiters;
	data_vio_count_t available = limiter->limit - limiter->busy;

	ASSERT_LOG_ONLY((limiter->release_count <= limiter->busy),
	VDO_ASSERT_LOG_ONLY((limiter->release_count <= limiter->busy),
			    "Release count %u is not more than busy count %u",
			    limiter->release_count, limiter->busy);

@@ -850,7 +850,7 @@ int make_data_vio_pool(struct vdo *vdo, data_vio_count_t pool_size,
	if (result != VDO_SUCCESS)
		return result;

	ASSERT_LOG_ONLY((discard_limit <= pool_size),
	VDO_ASSERT_LOG_ONLY((discard_limit <= pool_size),
			    "discard limit does not exceed pool size");
	initialize_limiter(&pool->discard_limiter, pool, assign_discard_permit,
			   discard_limit);
@@ -908,13 +908,13 @@ void free_data_vio_pool(struct data_vio_pool *pool)
	BUG_ON(atomic_read(&pool->processing));

	spin_lock(&pool->lock);
	ASSERT_LOG_ONLY((pool->limiter.busy == 0),
	VDO_ASSERT_LOG_ONLY((pool->limiter.busy == 0),
			    "data_vio pool must not have %u busy entries when being freed",
			    pool->limiter.busy);
	ASSERT_LOG_ONLY((bio_list_empty(&pool->limiter.waiters) &&
	VDO_ASSERT_LOG_ONLY((bio_list_empty(&pool->limiter.waiters) &&
			     bio_list_empty(&pool->limiter.new_waiters)),
			    "data_vio pool must not have threads waiting to read or write when being freed");
	ASSERT_LOG_ONLY((bio_list_empty(&pool->discard_limiter.waiters) &&
	VDO_ASSERT_LOG_ONLY((bio_list_empty(&pool->discard_limiter.waiters) &&
			     bio_list_empty(&pool->discard_limiter.new_waiters)),
			    "data_vio pool must not have threads waiting to discard when being freed");
	spin_unlock(&pool->lock);
@@ -961,7 +961,7 @@ void vdo_launch_bio(struct data_vio_pool *pool, struct bio *bio)
{
	struct data_vio *data_vio;

	ASSERT_LOG_ONLY(!vdo_is_state_quiescent(&pool->state),
	VDO_ASSERT_LOG_ONLY(!vdo_is_state_quiescent(&pool->state),
			    "data_vio_pool not quiescent on acquire");

	bio->bi_private = (void *) jiffies;
@@ -998,7 +998,7 @@ static void initiate_drain(struct admin_state *state)

static void assert_on_vdo_cpu_thread(const struct vdo *vdo, const char *name)
{
	ASSERT_LOG_ONLY((vdo_get_callback_thread_id() == vdo->thread_config.cpu_thread),
	VDO_ASSERT_LOG_ONLY((vdo_get_callback_thread_id() == vdo->thread_config.cpu_thread),
			    "%s called on cpu thread", name);
}

@@ -1173,7 +1173,7 @@ static void release_lock(struct data_vio *data_vio, struct lbn_lock *lock)
		/*  The lock is not locked, so it had better not be registered in the lock map. */
		struct data_vio *lock_holder = vdo_int_map_get(lock_map, lock->lbn);

		ASSERT_LOG_ONLY((data_vio != lock_holder),
		VDO_ASSERT_LOG_ONLY((data_vio != lock_holder),
				    "no logical block lock held for block %llu",
				    (unsigned long long) lock->lbn);
		return;
@@ -1181,7 +1181,7 @@ static void release_lock(struct data_vio *data_vio, struct lbn_lock *lock)

	/* Release the lock by removing the lock from the map. */
	lock_holder = vdo_int_map_remove(lock_map, lock->lbn);
	ASSERT_LOG_ONLY((data_vio == lock_holder),
	VDO_ASSERT_LOG_ONLY((data_vio == lock_holder),
			    "logical block lock mismatch for block %llu",
			    (unsigned long long) lock->lbn);
	lock->locked = false;
@@ -1193,7 +1193,7 @@ static void transfer_lock(struct data_vio *data_vio, struct lbn_lock *lock)
	struct data_vio *lock_holder, *next_lock_holder;
	int result;

	ASSERT_LOG_ONLY(lock->locked, "lbn_lock with waiters is not locked");
	VDO_ASSERT_LOG_ONLY(lock->locked, "lbn_lock with waiters is not locked");

	/* Another data_vio is waiting for the lock, transfer it in a single lock map operation. */
	next_lock_holder =
@@ -1210,7 +1210,7 @@ static void transfer_lock(struct data_vio *data_vio, struct lbn_lock *lock)
		return;
	}

	ASSERT_LOG_ONLY((lock_holder == data_vio),
	VDO_ASSERT_LOG_ONLY((lock_holder == data_vio),
			    "logical block lock mismatch for block %llu",
			    (unsigned long long) lock->lbn);
	lock->locked = false;
@@ -1275,9 +1275,9 @@ static void finish_cleanup(struct data_vio *data_vio)
{
	struct vdo_completion *completion = &data_vio->vio.completion;

	ASSERT_LOG_ONLY(data_vio->allocation.lock == NULL,
	VDO_ASSERT_LOG_ONLY(data_vio->allocation.lock == NULL,
			    "complete data_vio has no allocation lock");
	ASSERT_LOG_ONLY(data_vio->hash_lock == NULL,
	VDO_ASSERT_LOG_ONLY(data_vio->hash_lock == NULL,
			    "complete data_vio has no hash lock");
	if ((data_vio->remaining_discard <= VDO_BLOCK_SIZE) ||
	    (completion->result != VDO_SUCCESS)) {
@@ -1404,7 +1404,7 @@ void data_vio_allocate_data_block(struct data_vio *data_vio,
{
	struct allocation *allocation = &data_vio->allocation;

	ASSERT_LOG_ONLY((allocation->pbn == VDO_ZERO_BLOCK),
	VDO_ASSERT_LOG_ONLY((allocation->pbn == VDO_ZERO_BLOCK),
			    "data_vio does not have an allocation");
	allocation->write_lock_type = write_lock_type;
	allocation->zone = vdo_get_next_allocation_zone(data_vio->logical.zone);
@@ -1796,10 +1796,10 @@ static void compress_data_vio(struct vdo_completion *completion)
 */
void launch_compress_data_vio(struct data_vio *data_vio)
{
	ASSERT_LOG_ONLY(!data_vio->is_duplicate, "compressing a non-duplicate block");
	ASSERT_LOG_ONLY(data_vio->hash_lock != NULL,
	VDO_ASSERT_LOG_ONLY(!data_vio->is_duplicate, "compressing a non-duplicate block");
	VDO_ASSERT_LOG_ONLY(data_vio->hash_lock != NULL,
			    "data_vio to compress has a hash_lock");
	ASSERT_LOG_ONLY(data_vio_has_allocation(data_vio),
	VDO_ASSERT_LOG_ONLY(data_vio_has_allocation(data_vio),
			    "data_vio to compress has an allocation");

	/*
@@ -1841,7 +1841,7 @@ static void hash_data_vio(struct vdo_completion *completion)
	struct data_vio *data_vio = as_data_vio(completion);

	assert_data_vio_on_cpu_thread(data_vio);
	ASSERT_LOG_ONLY(!data_vio->is_zero, "zero blocks should not be hashed");
	VDO_ASSERT_LOG_ONLY(!data_vio->is_zero, "zero blocks should not be hashed");

	murmurhash3_128(data_vio->vio.data, VDO_BLOCK_SIZE, 0x62ea60be,
			&data_vio->record_name);
@@ -1856,7 +1856,7 @@ static void hash_data_vio(struct vdo_completion *completion)
static void prepare_for_dedupe(struct data_vio *data_vio)
{
	/* We don't care what thread we are on. */
	ASSERT_LOG_ONLY(!data_vio->is_zero, "must not prepare to dedupe zero blocks");
	VDO_ASSERT_LOG_ONLY(!data_vio->is_zero, "must not prepare to dedupe zero blocks");

	/*
	 * Before we can dedupe, we need to know the record name, so the first
@@ -1929,10 +1929,10 @@ static void acknowledge_write_callback(struct vdo_completion *completion)
	struct data_vio *data_vio = as_data_vio(completion);
	struct vdo *vdo = completion->vdo;

	ASSERT_LOG_ONLY((!vdo_uses_bio_ack_queue(vdo) ||
	VDO_ASSERT_LOG_ONLY((!vdo_uses_bio_ack_queue(vdo) ||
			     (vdo_get_callback_thread_id() == vdo->thread_config.bio_ack_thread)),
			    "%s() called on bio ack queue", __func__);
	ASSERT_LOG_ONLY(data_vio_has_flush_generation_lock(data_vio),
	VDO_ASSERT_LOG_ONLY(data_vio_has_flush_generation_lock(data_vio),
			    "write VIO to be acknowledged has a flush generation lock");
	acknowledge_data_vio(data_vio);
	if (data_vio->new_mapped.pbn == VDO_ZERO_BLOCK) {
@@ -1998,7 +1998,7 @@ static void handle_allocation_error(struct vdo_completion *completion)

static int assert_is_discard(struct data_vio *data_vio)
{
	int result = ASSERT(data_vio->is_discard,
	int result = VDO_ASSERT(data_vio->is_discard,
				"data_vio with no block map page is a discard");

	return ((result == VDO_SUCCESS) ? result : VDO_READ_ONLY);
Loading