git: 1ed401626792 - main - cam: add xpt_path_sim_device to return device_t associated with a path

Warner Losh imp at FreeBSD.org
Mon Jun 28 22:24:03 UTC 2021


The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=1ed401626792b2888e2e29befb13c23ff2273c4e

commit 1ed401626792b2888e2e29befb13c23ff2273c4e
Author:     Warner Losh <imp at FreeBSD.org>
AuthorDate: 2021-06-28 21:57:51 +0000
Commit:     Warner Losh <imp at FreeBSD.org>
CommitDate: 2021-06-28 21:57:51 +0000

    cam: add xpt_path_sim_device to return device_t associated with a path
    
    Return the device associated with the sim's bus when it called
    xpt_bus_register, if any. Most real SIMs in the tree set this device,
    but some virtual ones do not have a device_t assocaited with them.
    
    Reviewed by:            scottl@, mav@ (earlier version)
    Sponsored by:           Netflix
    Differential Revision:  https://reviews.freebsd.org/D30853
---
 sys/cam/cam_xpt.c | 18 +++++++++++++++++-
 sys/cam/cam_xpt.h |  1 +
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/sys/cam/cam_xpt.c b/sys/cam/cam_xpt.c
index 81d5d98fb9d4..ee216451bd6d 100644
--- a/sys/cam/cam_xpt.c
+++ b/sys/cam/cam_xpt.c
@@ -5574,7 +5574,23 @@ camisr_runqueue(void)
 	}
 }
 
-struct kv
+/**
+ * @brief Return the device_t associated with the path
+ *
+ * When a SIM is created, it registers a bus with a NEWBUS device_t. This is
+ * stored in the internal cam_eb bus structure. There is no guarnatee any given
+ * path will have a @c device_t associated with it (it's legal to call @c
+ * xpt_bus_register with a @c NULL @c device_t.
+ *
+ * @param path		Path to return the device_t for.
+ */
+device_t
+xpt_path_sim_device(const struct cam_path *path)
+{
+	return (path->bus->parent_dev);
+}
+
+struct kv 
 {
 	uint32_t v;
 	const char *name;
diff --git a/sys/cam/cam_xpt.h b/sys/cam/cam_xpt.h
index 7e7e6ac5880a..c8494d04234a 100644
--- a/sys/cam/cam_xpt.h
+++ b/sys/cam/cam_xpt.h
@@ -113,6 +113,7 @@ target_id_t		xpt_path_target_id(struct cam_path *path);
 lun_id_t		xpt_path_lun_id(struct cam_path *path);
 struct cam_sim		*xpt_path_sim(struct cam_path *path);
 struct cam_periph	*xpt_path_periph(struct cam_path *path);
+device_t		xpt_path_sim_device(const struct cam_path *path);
 void			xpt_print_path(struct cam_path *path);
 void			xpt_print_device(struct cam_ed *device);
 void			xpt_print(struct cam_path *path, const char *fmt, ...);


More information about the dev-commits-src-all mailing list