From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 82967686CA; Fri, 5 Feb 2021 21:58:42 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 82967686CA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1612551522; bh=SAjPd1aPbxYRPRuOPyniv3rfAT1ik7016T4gTmh3iXo=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=lqd+roOgwdCBmtff0qO3RHPFUX4+ngO9n8vwsc00MFm0wzEBOx5bc1mkb81UrmWdR 7oP3z9KlH4Xvs9/KyUitLd+XhskfULIIDsCKlXT/O6PiO/sMA0eiSp6gs8z0pcRUUM DO9KSwQFJoSFSp+An/y4IokRVphDxv3nFHQxXaHU= Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id DE1126467C for ; Fri, 5 Feb 2021 21:56:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org DE1126467C Received: by mail-lf1-f45.google.com with SMTP id p21so11302818lfu.11 for ; Fri, 05 Feb 2021 10:56:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fSgjRwiEufjPDP/QXRu6rL6naMWgKo9GMjrMhSeZsUs=; b=fb9lw1ZGqrQQx73SNauU/ivRU5OWtxCnF2lPA4Mm5QXGoV8UX3OHz04XP1DTfPzNw/ CuEkA8RxPYRPlbtbCfmYf6+ZuDEy9cCIpCb7IcYjX3jjA9SV8m19k0KfVSAiTO7H8bbg 68XvsRWG4EDZeyuomTiz0rziozIWYmVSVRvvefTz9Uyv1GQsJg4RFOVI++UmZ956D+OK 7KRu4KJwqDPmT6rBCDrba1+0+iIpfgJhV1esTRv8OC5mioh25M8wvmWm6l3jdF8sVkQp sO39IhMsyk9W+lhWZp3dEJ34zrLtOzzkJuju29wyuRRgWTDtJ0KS9iJ+70xD88ZuUaDQ qh6w== X-Gm-Message-State: AOAM531PIUntdXLo1CgZXitltT0nely4YBxxPUMr377o13v/p7xHLxqU E3RhGAWBc36bn5Etwz4sG9c= X-Google-Smtp-Source: ABdhPJyZGon/tltq+mji18yVcDUdchR4K33osVj3G2jhVOLmooIOKW2oZ1OpIS6AZph4vFRAdbPTDQ== X-Received: by 2002:a19:f707:: with SMTP id z7mr3310551lfe.548.1612551374460; Fri, 05 Feb 2021 10:56:14 -0800 (PST) Received: from grain.localdomain ([5.18.103.226]) by smtp.gmail.com with ESMTPSA id e26sm1103672ljp.24.2021.02.05.10.56.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 10:56:13 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id 9D71E560296; Fri, 5 Feb 2021 21:54:37 +0300 (MSK) To: tml Date: Fri, 5 Feb 2021 21:54:33 +0300 Message-Id: <20210205185436.638894-9-gorcunov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210205185436.638894-1-gorcunov@gmail.com> References: <20210205185436.638894-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v15 08/11] module_cache: make module to carry hash it belongs to X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: Mons Anderson , Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" We will need two hashes for backward compatibility sake, thus make module structure to carry the hash it belongs. Part-of #4642 Signed-off-by: Cyrill Gorcunov --- src/box/module_cache.c | 66 ++++++++++++++++++++++++------------------ src/box/module_cache.h | 4 +++ 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/box/module_cache.c b/src/box/module_cache.c index 44f34b375..786e49cba 100644 --- a/src/box/module_cache.c +++ b/src/box/module_cache.c @@ -72,12 +72,13 @@ func_split_name(const char *str, struct func_name *name) * Look up a module in the modules cache. */ static struct module * -module_cache_find(const char *name, const char *name_end) +module_cache_find(struct mh_strnptr_t *h, const char *name, + const char *name_end) { - mh_int_t e = mh_strnptr_find_inp(mod_hash, name, name_end - name); - if (e == mh_end(mod_hash)) + mh_int_t e = mh_strnptr_find_inp(h, name, name_end - name); + if (e == mh_end(h)) return NULL; - return mh_strnptr_node(mod_hash, e)->val; + return mh_strnptr_node(h, e)->val; } /** @@ -86,6 +87,7 @@ module_cache_find(const char *name, const char *name_end) static int module_cache_add(struct module *module) { + struct mh_strnptr_t *h = module->hash; size_t package_len = strlen(module->package); const struct mh_strnptr_node_t nd = { .str = module->package, @@ -94,7 +96,7 @@ module_cache_add(struct module *module) .val = module, }; - if (mh_strnptr_put(mod_hash, &nd, NULL, NULL) == mh_end(mod_hash)) { + if (mh_strnptr_put(h, &nd, NULL, NULL) == mh_end(h)) { diag_set(OutOfMemory, sizeof(nd), "malloc", "module cache node"); return -1; @@ -107,14 +109,17 @@ module_cache_add(struct module *module) * key based it is safe to just update the value. */ static int -module_cache_update(const char *name, const char *name_end, - struct module *module) +module_cache_update(struct module *module) { - mh_int_t e = mh_strnptr_find_inp(mod_hash, name, name_end - name); - if (e == mh_end(mod_hash)) + struct mh_strnptr_t *h = module->hash; + const char *name = module->package; + size_t len = strlen(module->package); + + mh_int_t e = mh_strnptr_find_inp(h, name, len); + if (e == mh_end(h)) return -1; - mh_strnptr_node(mod_hash, e)->str = module->package; - mh_strnptr_node(mod_hash, e)->val = module; + mh_strnptr_node(h, e)->str = module->package; + mh_strnptr_node(h, e)->val = module; return 0; } @@ -122,11 +127,15 @@ module_cache_update(const char *name, const char *name_end, * Delete a module from the modules cache. */ static void -module_cache_del(const char *name, const char *name_end) +module_cache_del(struct module *module) { - mh_int_t e = mh_strnptr_find_inp(mod_hash, name, name_end - name); - if (e != mh_end(mod_hash)) - mh_strnptr_del(mod_hash, e, NULL); + struct mh_strnptr_t *h = module->hash; + const char *name = module->package; + size_t len = strlen(module->package); + + mh_int_t e = mh_strnptr_find_inp(h, name, len); + if (e != mh_end(h)) + mh_strnptr_del(h, e, NULL); } /** @@ -135,7 +144,7 @@ module_cache_del(const char *name, const char *name_end) static void module_set_orphan(struct module *module) { - module->package[0] = '\0'; + module->hash = NULL; } /** @@ -144,7 +153,7 @@ module_set_orphan(struct module *module) static bool module_is_orphan(struct module *module) { - return module->package[0] == '\0'; + return module->hash == NULL; } /** @@ -256,11 +265,8 @@ module_unref(struct module *module) { assert(module->refs > 0); if (module->refs-- == 1) { - if (!module_is_orphan(module)) { - size_t len = strlen(module->package); - module_cache_del(module->package, - &module->package[len]); - } + if (!module_is_orphan(module)) + module_cache_del(module); module_delete(module); } } @@ -273,7 +279,8 @@ module_unref(struct module *module) * for cases of a function reload. */ static struct module * -module_load(const char *package, const char *package_end) +module_load(struct mh_strnptr_t *h, const char *package, + const char *package_end) { char path[PATH_MAX]; if (module_find(package, package_end, path, sizeof(path)) != 0) @@ -290,6 +297,7 @@ module_load(const char *package, const char *package_end) module->package[package_len] = 0; rlist_create(&module->funcs_list); module->refs = 0; + module->hash = h; const char *tmpdir = getenv("TMPDIR"); if (tmpdir == NULL) @@ -396,9 +404,9 @@ module_sym_load(struct module_sym *mod_sym) * loading and take it from the cache. */ struct module *cached, *module; - cached = module_cache_find(name.package, name.package_end); + cached = module_cache_find(mod_hash, name.package, name.package_end); if (cached == NULL) { - module = module_load(name.package, name.package_end); + module = module_load(mod_hash, name.package, name.package_end); if (module == NULL) return -1; if (module_cache_add(module) != 0) { @@ -498,13 +506,15 @@ module_sym_call(struct module_sym *mod_sym, struct port *args, int module_reload(const char *package, const char *package_end) { - struct module *old = module_cache_find(package, package_end); + struct module *old, *new; + + old = module_cache_find(mod_hash, package, package_end); if (old == NULL) { diag_set(ClientError, ER_NO_SUCH_MODULE, package); return -1; } - struct module *new = module_load(package, package_end); + new = module_load(mod_hash, package, package_end); if (new == NULL) return -1; @@ -531,7 +541,7 @@ module_reload(const char *package, const char *package_end) module_unref(old); } - if (module_cache_update(package, package_end, new) != 0) { + if (module_cache_update(new) != 0) { /* * Module cache must be consistent at this moment, * we've looked up for the package recently. If diff --git a/src/box/module_cache.h b/src/box/module_cache.h index fa62628c3..874cc081c 100644 --- a/src/box/module_cache.h +++ b/src/box/module_cache.h @@ -36,6 +36,10 @@ struct module { * Module dlhandle. */ void *handle; + /** + * Package hash module belongs to. + */ + struct mh_strnptr_t *hash; /** * List of associated symbols (functions). */ -- 2.29.2