Commit 9abd8bec authored by Andrey Kuzmin's avatar Andrey Kuzmin Committed by Daniel Verkamp
Browse files

Avoid scheduling removal of the same bdev descriptor multiple times.



Deferred descriptor removal invocation under bdev_unregister() does
not account for the possibility of bdev_unregister being entered
multiple times for the same bdev (which is possible thanks to multiple
paths to unregistration - consider bdev hotremove callback and
_spdk_bdev_finish_unregister_bdevs_iter iterator - being present).
Therefore, currently nothing prevents _remove_notify for the same bdev
descriptor from being scheduled multiple times.

This commit adds boolean remove_scheduled field to struct spdk_bdev_desc.
The value is set when remove_notify for the descriptor is being
scheduled for the first time, and checked on subsequent attempts.

Change-Id: If2c5a365c05c4123c50edf5a2db164be9dd26f8e
Signed-off-by: default avatarAndrey Kuzmin <andrey.v.kuzmin@gmail.com>
Reviewed-on: https://review.gerrithub.io/415319


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 980ebc97
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -240,6 +240,7 @@ struct spdk_bdev_desc {
	struct spdk_bdev		*bdev;
	spdk_bdev_remove_cb_t		remove_cb;
	void				*remove_ctx;
	bool				remove_scheduled;
	bool				write;
	TAILQ_ENTRY(spdk_bdev_desc)	link;
};
@@ -2912,9 +2913,13 @@ spdk_bdev_unregister(struct spdk_bdev *bdev, spdk_bdev_unregister_cb cb_fn, void
			 *  we don't recursively unregister this bdev again if the remove_cb
			 *  immediately closes its descriptor.
			 */
			if (!desc->remove_scheduled) {
				/* Avoid scheduling removal of the same descriptor multiple times. */
				desc->remove_scheduled = true;
				spdk_thread_send_msg(thread, _remove_notify, desc);
			}
		}
	}

	if (!do_destruct) {
		pthread_mutex_unlock(&bdev->mutex);