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 AD44F645EA; Mon, 18 Jan 2021 23:39:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AD44F645EA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1611002346; bh=BfDzopel4QBVU3orD5YnY5Mctwb7EOMeUcj3hxsfCC8=; 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=vxRrbedZCWYXT+yKOv7HDqEeUgugkdYB/5sW7U1mOzen78CD8iUBrDK+NUKs8Bk6V NFEgVspKRD3gwgdUipEDx7lKk4q2LQlhRffSaaJg4uSErMpXCcSbSGnOq90A4bH8hl Gsmb/O9yY0v+nGpPFNmr/zUA4ZXeDJEN4oyZkd2g= Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 4DD64CC307 for ; Mon, 18 Jan 2021 23:37:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4DD64CC307 Received: by mail-lf1-f53.google.com with SMTP id v67so25939105lfa.0 for ; Mon, 18 Jan 2021 12:37:13 -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=bZR19Xa3WUncHF8Q1MBQ4NAibQlpufXW/AHbMyRxAE0=; b=k/ceq/yTZ9eOWRUoO8MWBVhigS06wYhlhdsgMc8v8FPsU4K/xn4cv8yfsUn0PZTADO glSeXqAWGzAn0LdSgnBRpINrysXqsKRvkHWUMCd8X2YNakEn79LZfSbWtkUt0W6R7Rz+ VoAZqHTI1GcbWEAi1uaMbfQf9dVRk6nrhU93dp72o6aOgVEd5PJgLhfUY5d2iIP1kIjt JEww4JTtrVCs8xVenP+KPpugcVLt1aS9QsdyjyLCskGg7f6M3ZMAn38agVLFEzbZG0qo rI7VLmvpflcPx7sKjiPdRvkAwffymLiL+MlnrYx/WcYITFpkBYhzRLxDdiLQqlUUURUR sBYQ== X-Gm-Message-State: AOAM532VmRu3f4N+ooZ33AF5yBvuTtAVHYxQLcIqDUaDXXT7gHvdoXVx rq1quL5Buv6vxQBCzzreP/sZ/Gi3yXk= X-Google-Smtp-Source: ABdhPJxTlSHeRCPK1ptqyfIdS4i2Q3zPGJGIirpY8nk5Icuf1ClZRBic9fzT7A++2zTfz8KVFSJadg== X-Received: by 2002:a19:8cb:: with SMTP id 194mr353011lfi.463.1611002232322; Mon, 18 Jan 2021 12:37:12 -0800 (PST) Received: from grain.localdomain ([5.18.91.94]) by smtp.gmail.com with ESMTPSA id v10sm1781084lji.130.2021.01.18.12.37.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 12:37:11 -0800 (PST) Received: by grain.localdomain (Postfix, from userid 1000) id 6B594560186; Mon, 18 Jan 2021 23:35:59 +0300 (MSK) To: tml Date: Mon, 18 Jan 2021 23:35:54 +0300 Message-Id: <20210118203556.281700-7-gorcunov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210118203556.281700-1-gorcunov@gmail.com> References: <20210118203556.281700-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v12 6/8] module_cache: provide helpers to load and unload modules 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: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" We need to be able to load and unload modules without functions bound to them, just plain dlopen inside. This is a part of API for future patches. Part-of #4642 Signed-off-by: Cyrill Gorcunov --- src/box/module_cache.c | 47 +++++++++++++++++++++++++++++++----------- src/box/module_cache.h | 19 +++++++++++++++++ 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/box/module_cache.c b/src/box/module_cache.c index ae874caab..cb580f342 100644 --- a/src/box/module_cache.c +++ b/src/box/module_cache.c @@ -198,7 +198,7 @@ module_find(const char *package, const char *package_end, * for cases of a function reload. */ static struct module * -module_load(const char *package, const char *package_end) +module_dlopen(const char *package, const char *package_end) { char path[PATH_MAX]; if (module_find(package, package_end, path, sizeof(path)) != 0) @@ -338,16 +338,10 @@ module_sym_load(struct module_sym *mod_sym) struct func_name_desc d; parse_func_name(mod_sym->name, &d); - struct module *module = module_cache_find(d.package, d.package_end); - if (module == NULL) { - module = module_load(d.package, d.package_end); - if (module == NULL) - return -1; - if (module_cache_add(module) != 0) { - module_delete(module); - return -1; - } - } + size_t len = d.package_end - d.package; + struct module *module = module_load(d.package, len); + if (module == NULL) + return -1; mod_sym->addr = module_sym(module, d.sym); if (mod_sym->addr == NULL) @@ -437,6 +431,34 @@ module_cache_update(const char *name, const char *name_end, return 0; } +/** + * Load a new module. + */ +struct module * +module_load(const char *path, size_t path_len) +{ + struct module *module = module_cache_find(path, &path[path_len]); + if (module == NULL) { + module = module_dlopen(path, &path[path_len]); + if (module == NULL) + return NULL; + if (module_cache_add(module) != 0) { + module_delete(module); + return NULL; + } + } + return module; +} + +/** + * Unload a module. + */ +void +module_unload(struct module *module) +{ + module_gc(module); +} + int module_reload(const char *package, const char *package_end, struct module **module) @@ -448,7 +470,8 @@ module_reload(const char *package, const char *package_end, return 0; } - struct module *new = module_load(package, package_end); + size_t len = package_end - package; + struct module *new = module_dlopen(package, &package[len]); if (new == NULL) return -1; diff --git a/src/box/module_cache.h b/src/box/module_cache.h index feb1f2266..87108ae81 100644 --- a/src/box/module_cache.h +++ b/src/box/module_cache.h @@ -107,6 +107,25 @@ int module_sym_call(struct module_sym *mod_sym, struct port *args, struct port *ret); +/** + * Load a module. + * + * @param path path to a module file without extension. + * @param path_len length of @path. + * + * @return pointer to a module or NULL on error. + */ +struct module * +module_load(const char *path, size_t path_len); + +/** + * Unload a module. + * + * @param module pointer to a module. + */ +void +module_unload(struct module *module); + /** * Reload a module and all associated symbols. * -- 2.29.2