Commit 14829422be6d6b6721f61b1e749acf5a9cb664d8

Authored by Joel Becker
Committed by Mark Fasheh
1 parent 631d1febab

ocfs2: Depend on configfs heartbeat items.

ocfs2 mounts require a heartbeat region.  Use the new configfs_depend_item()
facility to actually depend on them so they can't go away from under us.

First, teach cluster/nodemanager.c to depend an item on the o2cb subsystem.
Then teach o2hb_register_callbacks to take a UUID and depend on the
appropriate region.  Finally, teach all users of o2hb to pass a UUID or
NULL if they don't require a pin.

Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>

Showing 7 changed files with 92 additions and 17 deletions Side-by-side Diff

fs/ocfs2/cluster/heartbeat.c
... ... @@ -1665,8 +1665,57 @@
1665 1665 }
1666 1666 EXPORT_SYMBOL_GPL(o2hb_setup_callback);
1667 1667  
1668   -int o2hb_register_callback(struct o2hb_callback_func *hc)
  1668 +static struct o2hb_region *o2hb_find_region(const char *region_uuid)
1669 1669 {
  1670 + struct o2hb_region *p, *reg = NULL;
  1671 +
  1672 + assert_spin_locked(&o2hb_live_lock);
  1673 +
  1674 + list_for_each_entry(p, &o2hb_all_regions, hr_all_item) {
  1675 + if (!strcmp(region_uuid, config_item_name(&p->hr_item))) {
  1676 + reg = p;
  1677 + break;
  1678 + }
  1679 + }
  1680 +
  1681 + return reg;
  1682 +}
  1683 +
  1684 +static int o2hb_region_get(const char *region_uuid)
  1685 +{
  1686 + int ret = 0;
  1687 + struct o2hb_region *reg;
  1688 +
  1689 + spin_lock(&o2hb_live_lock);
  1690 +
  1691 + reg = o2hb_find_region(region_uuid);
  1692 + if (!reg)
  1693 + ret = -ENOENT;
  1694 + spin_unlock(&o2hb_live_lock);
  1695 +
  1696 + if (!ret)
  1697 + ret = o2nm_depend_item(&reg->hr_item);
  1698 +
  1699 + return ret;
  1700 +}
  1701 +
  1702 +static void o2hb_region_put(const char *region_uuid)
  1703 +{
  1704 + struct o2hb_region *reg;
  1705 +
  1706 + spin_lock(&o2hb_live_lock);
  1707 +
  1708 + reg = o2hb_find_region(region_uuid);
  1709 +
  1710 + spin_unlock(&o2hb_live_lock);
  1711 +
  1712 + if (reg)
  1713 + o2nm_undepend_item(&reg->hr_item);
  1714 +}
  1715 +
  1716 +int o2hb_register_callback(const char *region_uuid,
  1717 + struct o2hb_callback_func *hc)
  1718 +{
1670 1719 struct o2hb_callback_func *tmp;
1671 1720 struct list_head *iter;
1672 1721 struct o2hb_callback *hbcall;
... ... @@ -1681,6 +1730,12 @@
1681 1730 goto out;
1682 1731 }
1683 1732  
  1733 + if (region_uuid) {
  1734 + ret = o2hb_region_get(region_uuid);
  1735 + if (ret)
  1736 + goto out;
  1737 + }
  1738 +
1684 1739 down_write(&o2hb_callback_sem);
1685 1740  
1686 1741 list_for_each(iter, &hbcall->list) {
1687 1742  
1688 1743  
... ... @@ -1702,15 +1757,20 @@
1702 1757 }
1703 1758 EXPORT_SYMBOL_GPL(o2hb_register_callback);
1704 1759  
1705   -void o2hb_unregister_callback(struct o2hb_callback_func *hc)
  1760 +void o2hb_unregister_callback(const char *region_uuid,
  1761 + struct o2hb_callback_func *hc)
1706 1762 {
1707 1763 BUG_ON(hc->hc_magic != O2HB_CB_MAGIC);
1708 1764  
1709 1765 mlog(ML_HEARTBEAT, "on behalf of %p for funcs %p\n",
1710 1766 __builtin_return_address(0), hc);
1711 1767  
  1768 + /* XXX Can this happen _with_ a region reference? */
1712 1769 if (list_empty(&hc->hc_item))
1713 1770 return;
  1771 +
  1772 + if (region_uuid)
  1773 + o2hb_region_put(region_uuid);
1714 1774  
1715 1775 down_write(&o2hb_callback_sem);
1716 1776  
fs/ocfs2/cluster/heartbeat.h
... ... @@ -69,8 +69,10 @@
69 69 o2hb_cb_func *func,
70 70 void *data,
71 71 int priority);
72   -int o2hb_register_callback(struct o2hb_callback_func *hc);
73   -void o2hb_unregister_callback(struct o2hb_callback_func *hc);
  72 +int o2hb_register_callback(const char *region_uuid,
  73 + struct o2hb_callback_func *hc);
  74 +void o2hb_unregister_callback(const char *region_uuid,
  75 + struct o2hb_callback_func *hc);
74 76 void o2hb_fill_node_map(unsigned long *map,
75 77 unsigned bytes);
76 78 void o2hb_init(void);
fs/ocfs2/cluster/nodemanager.c
... ... @@ -900,6 +900,16 @@
900 900 },
901 901 };
902 902  
  903 +int o2nm_depend_item(struct config_item *item)
  904 +{
  905 + return configfs_depend_item(&o2nm_cluster_group.cs_subsys, item);
  906 +}
  907 +
  908 +void o2nm_undepend_item(struct config_item *item)
  909 +{
  910 + configfs_undepend_item(&o2nm_cluster_group.cs_subsys, item);
  911 +}
  912 +
903 913 static void __exit exit_o2nm(void)
904 914 {
905 915 if (ocfs2_table_header)
fs/ocfs2/cluster/nodemanager.h
... ... @@ -77,5 +77,8 @@
77 77 void o2nm_node_get(struct o2nm_node *node);
78 78 void o2nm_node_put(struct o2nm_node *node);
79 79  
  80 +int o2nm_depend_item(struct config_item *item);
  81 +void o2nm_undepend_item(struct config_item *item);
  82 +
80 83 #endif /* O2CLUSTER_NODEMANAGER_H */
fs/ocfs2/cluster/tcp.c
... ... @@ -1638,8 +1638,8 @@
1638 1638  
1639 1639 void o2net_unregister_hb_callbacks(void)
1640 1640 {
1641   - o2hb_unregister_callback(&o2net_hb_up);
1642   - o2hb_unregister_callback(&o2net_hb_down);
  1641 + o2hb_unregister_callback(NULL, &o2net_hb_up);
  1642 + o2hb_unregister_callback(NULL, &o2net_hb_down);
1643 1643 }
1644 1644  
1645 1645 int o2net_register_hb_callbacks(void)
1646 1646  
... ... @@ -1651,9 +1651,9 @@
1651 1651 o2hb_setup_callback(&o2net_hb_up, O2HB_NODE_UP_CB,
1652 1652 o2net_hb_node_up_cb, NULL, O2NET_HB_PRI);
1653 1653  
1654   - ret = o2hb_register_callback(&o2net_hb_up);
  1654 + ret = o2hb_register_callback(NULL, &o2net_hb_up);
1655 1655 if (ret == 0)
1656   - ret = o2hb_register_callback(&o2net_hb_down);
  1656 + ret = o2hb_register_callback(NULL, &o2net_hb_down);
1657 1657  
1658 1658 if (ret)
1659 1659 o2net_unregister_hb_callbacks();
fs/ocfs2/dlm/dlmdomain.c
... ... @@ -1128,8 +1128,8 @@
1128 1128  
1129 1129 static void dlm_unregister_domain_handlers(struct dlm_ctxt *dlm)
1130 1130 {
1131   - o2hb_unregister_callback(&dlm->dlm_hb_up);
1132   - o2hb_unregister_callback(&dlm->dlm_hb_down);
  1131 + o2hb_unregister_callback(NULL, &dlm->dlm_hb_up);
  1132 + o2hb_unregister_callback(NULL, &dlm->dlm_hb_down);
1133 1133 o2net_unregister_handler_list(&dlm->dlm_domain_handlers);
1134 1134 }
1135 1135  
1136 1136  
... ... @@ -1141,13 +1141,13 @@
1141 1141  
1142 1142 o2hb_setup_callback(&dlm->dlm_hb_down, O2HB_NODE_DOWN_CB,
1143 1143 dlm_hb_node_down_cb, dlm, DLM_HB_NODE_DOWN_PRI);
1144   - status = o2hb_register_callback(&dlm->dlm_hb_down);
  1144 + status = o2hb_register_callback(NULL, &dlm->dlm_hb_down);
1145 1145 if (status)
1146 1146 goto bail;
1147 1147  
1148 1148 o2hb_setup_callback(&dlm->dlm_hb_up, O2HB_NODE_UP_CB,
1149 1149 dlm_hb_node_up_cb, dlm, DLM_HB_NODE_UP_PRI);
1150   - status = o2hb_register_callback(&dlm->dlm_hb_up);
  1150 + status = o2hb_register_callback(NULL, &dlm->dlm_hb_up);
1151 1151 if (status)
1152 1152 goto bail;
1153 1153  
fs/ocfs2/heartbeat.c
... ... @@ -157,16 +157,16 @@
157 157 if (ocfs2_mount_local(osb))
158 158 return 0;
159 159  
160   - status = o2hb_register_callback(&osb->osb_hb_down);
  160 + status = o2hb_register_callback(osb->uuid_str, &osb->osb_hb_down);
161 161 if (status < 0) {
162 162 mlog_errno(status);
163 163 goto bail;
164 164 }
165 165  
166   - status = o2hb_register_callback(&osb->osb_hb_up);
  166 + status = o2hb_register_callback(osb->uuid_str, &osb->osb_hb_up);
167 167 if (status < 0) {
168 168 mlog_errno(status);
169   - o2hb_unregister_callback(&osb->osb_hb_down);
  169 + o2hb_unregister_callback(osb->uuid_str, &osb->osb_hb_down);
170 170 }
171 171  
172 172 bail:
... ... @@ -178,8 +178,8 @@
178 178 if (ocfs2_mount_local(osb))
179 179 return;
180 180  
181   - o2hb_unregister_callback(&osb->osb_hb_down);
182   - o2hb_unregister_callback(&osb->osb_hb_up);
  181 + o2hb_unregister_callback(osb->uuid_str, &osb->osb_hb_down);
  182 + o2hb_unregister_callback(osb->uuid_str, &osb->osb_hb_up);
183 183 }
184 184  
185 185 void ocfs2_stop_heartbeat(struct ocfs2_super *osb)