"panic",        /* O2NM_FENCE_PANIC */
 };
 
+static inline void o2nm_lock_subsystem(void);
+static inline void o2nm_unlock_subsystem(void);
+
 struct o2nm_node *o2nm_get_node_by_num(u8 node_num)
 {
        struct o2nm_node *node = NULL;
 {
        /* through the first node_set .parent
         * mycluster/nodes/mynode == o2nm_cluster->o2nm_node_group->o2nm_node */
-       return to_o2nm_cluster(node->nd_item.ci_parent->ci_parent);
+       if (node->nd_item.ci_parent)
+               return to_o2nm_cluster(node->nd_item.ci_parent->ci_parent);
+       else
+               return NULL;
 }
 
 enum {
                                   size_t count)
 {
        struct o2nm_node *node = to_o2nm_node(item);
-       struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
+       struct o2nm_cluster *cluster;
        unsigned long tmp;
        char *p = (char *)page;
        int ret = 0;
            !test_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
                return -EINVAL; /* XXX */
 
+       o2nm_lock_subsystem();
+       cluster = to_o2nm_cluster_from_node(node);
+       if (!cluster) {
+               o2nm_unlock_subsystem();
+               return -EINVAL;
+       }
+
        write_lock(&cluster->cl_nodes_lock);
        if (cluster->cl_nodes[tmp])
                ret = -EEXIST;
                set_bit(tmp, cluster->cl_nodes_bitmap);
        }
        write_unlock(&cluster->cl_nodes_lock);
+       o2nm_unlock_subsystem();
+
        if (ret)
                return ret;
 
                                            size_t count)
 {
        struct o2nm_node *node = to_o2nm_node(item);
-       struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
+       struct o2nm_cluster *cluster;
        int ret, i;
        struct rb_node **p, *parent;
        unsigned int octets[4];
                be32_add_cpu(&ipv4_addr, octets[i] << (i * 8));
        }
 
+       o2nm_lock_subsystem();
+       cluster = to_o2nm_cluster_from_node(node);
+       if (!cluster) {
+               o2nm_unlock_subsystem();
+               return -EINVAL;
+       }
+
        ret = 0;
        write_lock(&cluster->cl_nodes_lock);
        if (o2nm_node_ip_tree_lookup(cluster, ipv4_addr, &p, &parent))
                rb_insert_color(&node->nd_ip_node, &cluster->cl_node_ip_tree);
        }
        write_unlock(&cluster->cl_nodes_lock);
+       o2nm_unlock_subsystem();
+
        if (ret)
                return ret;
 
                                     size_t count)
 {
        struct o2nm_node *node = to_o2nm_node(item);
-       struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
+       struct o2nm_cluster *cluster;
        unsigned long tmp;
        char *p = (char *)page;
        ssize_t ret;
            !test_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
                return -EINVAL; /* XXX */
 
+       o2nm_lock_subsystem();
+       cluster = to_o2nm_cluster_from_node(node);
+       if (!cluster) {
+               ret = -EINVAL;
+               goto out;
+       }
+
        /* the only failure case is trying to set a new local node
         * when a different one is already set */
        if (tmp && tmp == cluster->cl_has_local &&
-           cluster->cl_local_node != node->nd_num)
-               return -EBUSY;
+           cluster->cl_local_node != node->nd_num) {
+               ret = -EBUSY;
+               goto out;
+       }
 
        /* bring up the rx thread if we're setting the new local node. */
        if (tmp && !cluster->cl_has_local) {
                ret = o2net_start_listening(node);
                if (ret)
-                       return ret;
+                       goto out;
        }
 
        if (!tmp && cluster->cl_has_local &&
                cluster->cl_local_node = node->nd_num;
        }
 
-       return count;
+       ret = count;
+
+out:
+       o2nm_unlock_subsystem();
+       return ret;
 }
 
 CONFIGFS_ATTR(o2nm_node_, num);
        },
 };
 
+static inline void o2nm_lock_subsystem(void)
+{
+       mutex_lock(&o2nm_cluster_group.cs_subsys.su_mutex);
+}
+
+static inline void o2nm_unlock_subsystem(void)
+{
+       mutex_unlock(&o2nm_cluster_group.cs_subsys.su_mutex);
+}
+
 int o2nm_depend_item(struct config_item *item)
 {
        return configfs_depend_item(&o2nm_cluster_group.cs_subsys, item);