diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c index 1c3def99bb07..e20ef0459f54 100644 --- a/fs/ocfs2/cluster/heartbeat.c +++ b/fs/ocfs2/cluster/heartbeat.c @@ -273,6 +273,8 @@ struct o2hb_region { /* last hb status, 0 for success, other value for error. */ int hr_last_hb_status; + /* Serializes concurrent writers of the "dev" attribute */ + struct mutex hr_dev_write_mutex; }; static inline struct block_device *reg_bdev(struct o2hb_region *reg) @@ -1879,6 +1881,8 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, ssize_t ret = -EINVAL; int live_threshold; + guard(mutex)(®->hr_dev_write_mutex); + if (reg->hr_bdev_file) return -EINVAL; @@ -2149,6 +2153,8 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g config_item_init_type_name(®->hr_item, name, &o2hb_region_type); + mutex_init(®->hr_dev_write_mutex); + /* this is the same way to generate msg key as dlm, for local heartbeat, * name is also the same, so make initial crc value different to avoid * message key conflict.