/* Return Value: On success, pointer to the nilfs object is returned. On error, NULL is returned.  */
struct the_nilfs* find_or_create_nilfs(struct block_device *bdev)
/* Return Value: On success, pointer to the nilfs object is returned. On error, NULL is returned.  */
struct the_nilfs* find_or_create_nilfs(struct block_device *bdev)
{
	struct the_nilfs *nilfs, *new = NULL;
 retry:
	spin_lock(&nilfs_lock);
	list_for_each_entry(nilfs, &nilfs_objects, ns_list) {
		if (nilfs->ns_bdev == bdev) {
			get_nilfs(nilfs);
			spin_unlock(&nilfs_lock);
			if (new)
				put_nilfs(new);
			return nilfs;
		}
	}
	if (new) {
		list_add_tail(&new->ns_list, &nilfs_objects);
		spin_unlock(&nilfs_lock);
		return new;
	}
	spin_unlock(&nilfs_lock);
	new = alloc_nilfs(bdev);
	if (new)
		goto retry;
	return NULL;
}