We prepare a new function bdi_get_dev_name() to copy device kobj->name into buffer passed by caller. The function is covered by RCU. Thus, caller can access ->dev and copy integral device name. Signed-off-by: Yufen Yu <yuyufen@xxxxxxxxxx> --- include/linux/backing-dev.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h index 67e429b203a1..89d1cb7923f5 100644 --- a/include/linux/backing-dev.h +++ b/include/linux/backing-dev.h @@ -514,4 +514,29 @@ static inline const char *bdi_dev_name(struct backing_dev_info *bdi) return dev_name(&bdi->rcu_dev->dev); } +/** + * bdi_get_dev_name - copy bdi device name into buffer + * @bdi: target bdi + * @dname: Where to copy the device name to + * @len: size of destination buffer + */ +static inline void bdi_get_dev_name(struct backing_dev_info *bdi, + char *dname, int len) +{ + struct bdi_rcu_device *rcu_dev; + + if (!bdi) { + strlcpy(dname, bdi_unknown_name, len); + return; + } + + rcu_read_lock(); + + rcu_dev = rcu_dereference(bdi->rcu_dev); + strlcpy(dname, rcu_dev ? dev_name(&rcu_dev->dev) : + bdi_unknown_name, len); + + rcu_read_unlock(); +} + #endif /* _LINUX_BACKING_DEV_H */ -- 2.16.2.dirty