📄 dlmdomain.c
字号:
if (status < 0) { mlog_errno(status); goto bail; } status = dlm_launch_recovery_thread(dlm); if (status < 0) { mlog_errno(status); goto bail; } dlm->dlm_worker = create_singlethread_workqueue("dlm_wq"); if (!dlm->dlm_worker) { status = -ENOMEM; mlog_errno(status); goto bail; } do { status = dlm_try_to_join_domain(dlm); /* If we're racing another node to the join, then we * need to back off temporarily and let them * complete. */#define DLM_JOIN_TIMEOUT_MSECS 90000 if (status == -EAGAIN) { if (signal_pending(current)) { status = -ERESTARTSYS; goto bail; } if (total_backoff > msecs_to_jiffies(DLM_JOIN_TIMEOUT_MSECS)) { status = -ERESTARTSYS; mlog(ML_NOTICE, "Timed out joining dlm domain " "%s after %u msecs\n", dlm->name, jiffies_to_msecs(total_backoff)); goto bail; } /* * <chip> After you! * <dale> No, after you! * <chip> I insist! * <dale> But you first! * ... */ backoff = (unsigned int)(jiffies & 0x3); backoff *= DLM_DOMAIN_BACKOFF_MS; total_backoff += backoff; mlog(0, "backoff %d\n", backoff); msleep(backoff); } } while (status == -EAGAIN); if (status < 0) { mlog_errno(status); goto bail; } status = 0;bail: wake_up(&dlm_domain_events); if (status) { dlm_unregister_domain_handlers(dlm); dlm_debug_shutdown(dlm); dlm_complete_thread(dlm); dlm_complete_recovery_thread(dlm); dlm_destroy_dlm_worker(dlm); } return status;}static struct dlm_ctxt *dlm_alloc_ctxt(const char *domain, u32 key){ int i; int ret; struct dlm_ctxt *dlm = NULL; dlm = kzalloc(sizeof(*dlm), GFP_KERNEL); if (!dlm) { mlog_errno(-ENOMEM); goto leave; } dlm->name = kmalloc(strlen(domain) + 1, GFP_KERNEL); if (dlm->name == NULL) { mlog_errno(-ENOMEM); kfree(dlm); dlm = NULL; goto leave; } dlm->lockres_hash = (struct hlist_head **)dlm_alloc_pagevec(DLM_HASH_PAGES); if (!dlm->lockres_hash) { mlog_errno(-ENOMEM); kfree(dlm->name); kfree(dlm); dlm = NULL; goto leave; } for (i = 0; i < DLM_HASH_BUCKETS; i++) INIT_HLIST_HEAD(dlm_lockres_hash(dlm, i)); strcpy(dlm->name, domain); dlm->key = key; dlm->node_num = o2nm_this_node(); ret = dlm_create_debugfs_subroot(dlm); if (ret < 0) { dlm_free_pagevec((void **)dlm->lockres_hash, DLM_HASH_PAGES); kfree(dlm->name); kfree(dlm); dlm = NULL; goto leave; } spin_lock_init(&dlm->spinlock); spin_lock_init(&dlm->master_lock); spin_lock_init(&dlm->ast_lock); INIT_LIST_HEAD(&dlm->list); INIT_LIST_HEAD(&dlm->dirty_list); INIT_LIST_HEAD(&dlm->reco.resources); INIT_LIST_HEAD(&dlm->reco.received); INIT_LIST_HEAD(&dlm->reco.node_data); INIT_LIST_HEAD(&dlm->purge_list); INIT_LIST_HEAD(&dlm->dlm_domain_handlers); INIT_LIST_HEAD(&dlm->tracking_list); dlm->reco.state = 0; INIT_LIST_HEAD(&dlm->pending_asts); INIT_LIST_HEAD(&dlm->pending_basts); mlog(0, "dlm->recovery_map=%p, &(dlm->recovery_map[0])=%p\n", dlm->recovery_map, &(dlm->recovery_map[0])); memset(dlm->recovery_map, 0, sizeof(dlm->recovery_map)); memset(dlm->live_nodes_map, 0, sizeof(dlm->live_nodes_map)); memset(dlm->domain_map, 0, sizeof(dlm->domain_map)); dlm->dlm_thread_task = NULL; dlm->dlm_reco_thread_task = NULL; dlm->dlm_worker = NULL; init_waitqueue_head(&dlm->dlm_thread_wq); init_waitqueue_head(&dlm->dlm_reco_thread_wq); init_waitqueue_head(&dlm->reco.event); init_waitqueue_head(&dlm->ast_wq); init_waitqueue_head(&dlm->migration_wq); INIT_LIST_HEAD(&dlm->master_list); INIT_LIST_HEAD(&dlm->mle_hb_events); dlm->joining_node = DLM_LOCK_RES_OWNER_UNKNOWN; init_waitqueue_head(&dlm->dlm_join_events); dlm->reco.new_master = O2NM_INVALID_NODE_NUM; dlm->reco.dead_node = O2NM_INVALID_NODE_NUM; atomic_set(&dlm->local_resources, 0); atomic_set(&dlm->remote_resources, 0); atomic_set(&dlm->unknown_resources, 0); spin_lock_init(&dlm->work_lock); INIT_LIST_HEAD(&dlm->work_list); KAPI_INIT_WORK(&dlm->dispatched_work, dlm_dispatch_work, dlm); kref_init(&dlm->dlm_refs); dlm->dlm_state = DLM_CTXT_NEW; INIT_LIST_HEAD(&dlm->dlm_eviction_callbacks); mlog(0, "context init: refcount %u\n", atomic_read(&dlm->dlm_refs.refcount));leave: return dlm;}/* * Compare a requested locking protocol version against the current one. * * If the major numbers are different, they are incompatible. * If the current minor is greater than the request, they are incompatible. * If the current minor is less than or equal to the request, they are * compatible, and the requester should run at the current minor version. */static int dlm_protocol_compare(struct dlm_protocol_version *existing, struct dlm_protocol_version *request){ if (existing->pv_major != request->pv_major) return 1; if (existing->pv_minor > request->pv_minor) return 1; if (existing->pv_minor < request->pv_minor) request->pv_minor = existing->pv_minor; return 0;}/* * dlm_register_domain: one-time setup per "domain". * * The filesystem passes in the requested locking version via proto. * If registration was successful, proto will contain the negotiated * locking protocol. */struct dlm_ctxt * dlm_register_domain(const char *domain, u32 key, struct dlm_protocol_version *fs_proto){ int ret; struct dlm_ctxt *dlm = NULL; struct dlm_ctxt *new_ctxt = NULL; if (strlen(domain) > O2NM_MAX_NAME_LEN) { ret = -ENAMETOOLONG; mlog(ML_ERROR, "domain name length too long\n"); goto leave; } if (!o2hb_check_local_node_heartbeating()) { mlog(ML_ERROR, "the local node has not been configured, or is " "not heartbeating\n"); ret = -EPROTO; goto leave; } mlog(0, "register called for domain \"%s\"\n", domain);retry: dlm = NULL; if (signal_pending(current)) { ret = -ERESTARTSYS; mlog_errno(ret); goto leave; } spin_lock(&dlm_domain_lock); dlm = __dlm_lookup_domain(domain); if (dlm) { if (dlm->dlm_state != DLM_CTXT_JOINED) { spin_unlock(&dlm_domain_lock); mlog(0, "This ctxt is not joined yet!\n"); wait_event_interruptible(dlm_domain_events, dlm_wait_on_domain_helper( domain)); goto retry; } if (dlm_protocol_compare(&dlm->fs_locking_proto, fs_proto)) { mlog(ML_ERROR, "Requested locking protocol version is not " "compatible with already registered domain " "\"%s\"\n", domain); ret = -EPROTO; goto leave; } __dlm_get(dlm); dlm->num_joins++; spin_unlock(&dlm_domain_lock); ret = 0; goto leave; } /* doesn't exist */ if (!new_ctxt) { spin_unlock(&dlm_domain_lock); new_ctxt = dlm_alloc_ctxt(domain, key); if (new_ctxt) goto retry; ret = -ENOMEM; mlog_errno(ret); goto leave; } /* a little variable switch-a-roo here... */ dlm = new_ctxt; new_ctxt = NULL; /* add the new domain */ list_add_tail(&dlm->list, &dlm_domains); spin_unlock(&dlm_domain_lock); /* * Pass the locking protocol version into the join. If the join * succeeds, it will have the negotiated protocol set. */ dlm->dlm_locking_proto = dlm_protocol; dlm->fs_locking_proto = *fs_proto; ret = dlm_join_domain(dlm); if (ret) { mlog_errno(ret); dlm_put(dlm); goto leave; } /* Tell the caller what locking protocol we negotiated */ *fs_proto = dlm->fs_locking_proto; ret = 0;leave: if (new_ctxt) dlm_free_ctxt_mem(new_ctxt); if (ret < 0) dlm = ERR_PTR(ret); return dlm;}EXPORT_SYMBOL_GPL(dlm_register_domain);static LIST_HEAD(dlm_join_handlers);static void dlm_unregister_net_handlers(void){ o2net_unregister_handler_list(&dlm_join_handlers);}static int dlm_register_net_handlers(void){ int status = 0; status = o2net_register_handler(DLM_QUERY_JOIN_MSG, DLM_MOD_KEY, sizeof(struct dlm_query_join_request), dlm_query_join_handler, NULL, NULL, &dlm_join_handlers); if (status) goto bail; status = o2net_register_handler(DLM_ASSERT_JOINED_MSG, DLM_MOD_KEY, sizeof(struct dlm_assert_joined), dlm_assert_joined_handler, NULL, NULL, &dlm_join_handlers); if (status) goto bail; status = o2net_register_handler(DLM_CANCEL_JOIN_MSG, DLM_MOD_KEY, sizeof(struct dlm_cancel_join), dlm_cancel_join_handler, NULL, NULL, &dlm_join_handlers);bail: if (status < 0) dlm_unregister_net_handlers(); return status;}/* Domain eviction callback handling. * * The file system requires notification of node death *before* the * dlm completes it's recovery work, otherwise it may be able to * acquire locks on resources requiring recovery. Since the dlm can * evict a node from it's domain *before* heartbeat fires, a similar * mechanism is required. *//* Eviction is not expected to happen often, so a per-domain lock is * not necessary. Eviction callbacks are allowed to sleep for short * periods of time. */static DECLARE_RWSEM(dlm_callback_sem);void dlm_fire_domain_eviction_callbacks(struct dlm_ctxt *dlm, int node_num){ struct list_head *iter; struct dlm_eviction_cb *cb; down_read(&dlm_callback_sem); list_for_each(iter, &dlm->dlm_eviction_callbacks) { cb = list_entry(iter, struct dlm_eviction_cb, ec_item); cb->ec_func(node_num, cb->ec_data); } up_read(&dlm_callback_sem);}void dlm_setup_eviction_cb(struct dlm_eviction_cb *cb, dlm_eviction_func *f, void *data){ INIT_LIST_HEAD(&cb->ec_item); cb->ec_func = f; cb->ec_data = data;}EXPORT_SYMBOL_GPL(dlm_setup_eviction_cb);void dlm_register_eviction_cb(struct dlm_ctxt *dlm, struct dlm_eviction_cb *cb){ down_write(&dlm_callback_sem); list_add_tail(&cb->ec_item, &dlm->dlm_eviction_callbacks); up_write(&dlm_callback_sem);}EXPORT_SYMBOL_GPL(dlm_register_eviction_cb);void dlm_unregister_eviction_cb(struct dlm_eviction_cb *cb){ down_write(&dlm_callback_sem); list_del_init(&cb->ec_item); up_write(&dlm_callback_sem);}EXPORT_SYMBOL_GPL(dlm_unregister_eviction_cb);static int __init dlm_init(void){ int status; dlm_print_version(); status = dlm_init_mle_cache(); if (status) { mlog(ML_ERROR, "Could not create o2dlm_mle slabcache\n"); goto error; } status = dlm_init_master_caches(); if (status) { mlog(ML_ERROR, "Could not create o2dlm_lockres and " "o2dlm_lockname slabcaches\n"); goto error; } status = dlm_init_lock_cache(); if (status) { mlog(ML_ERROR, "Count not create o2dlm_lock slabcache\n"); goto error; } status = dlm_register_net_handlers(); if (status) { mlog(ML_ERROR, "Unable to register network handlers\n"); goto error; } status = dlm_create_debugfs_root(); if (status) goto error; return 0;error: dlm_unregister_net_handlers(); dlm_destroy_lock_cache(); dlm_destroy_master_caches(); dlm_destroy_mle_cache(); return -1;}static void __exit dlm_exit (void){ dlm_destroy_debugfs_root(); dlm_unregister_net_handlers(); dlm_destroy_lock_cache(); dlm_destroy_master_caches(); dlm_destroy_mle_cache();}MODULE_AUTHOR("Oracle");MODULE_LICENSE("GPL");module_init(dlm_init);module_exit(dlm_exit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -