Content-Type: multipart/mixed; boundary="===============0040933966504294793==" MIME-Version: 1.0 From: ramesh.thomas at intel.com Subject: [Accel-config] [PATCH v1 3/5] accel-config: Check and return error if kernel module is not loaded Date: Mon, 22 Feb 2021 15:27:54 -0500 Message-ID: <20210222202756.186121-4-ramesh.thomas@intel.com> In-Reply-To: 20210222202756.186121-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============0040933966504294793== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ramesh Thomas Check if kernel module is loaded before running commands. Return failure if not loaded. Signed-off-by: Ramesh Thomas --- accfg/accel-config.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/accfg/accel-config.c b/accfg/accel-config.c index b096a5c..f12e449 100644 --- a/accfg/accel-config.c +++ b/accfg/accel-config.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -74,9 +75,34 @@ static struct cmd_struct commands[] =3D { #endif }; = +static int idxd_kmod_init(struct kmod_ctx **ctx, struct kmod_module **mod) +{ + int rc; + + *ctx =3D kmod_new(NULL, NULL); + if (!*ctx) + return -ENXIO; + + rc =3D kmod_module_new_from_name(*ctx, "idxd", mod); + if (rc < 0) { + kmod_unref(*ctx); + return rc; + } + + rc =3D kmod_module_get_initstate(*mod); + if (rc < 0) { + kmod_module_unref(*mod); + kmod_unref(*ctx); + } + + return rc; +} + int main(int argc, const char **argv) { struct accfg_ctx *ctx; + struct kmod_ctx *kmod_ctx; + struct kmod_module *mod; int rc; = /* Look for flags.. */ @@ -95,15 +121,27 @@ int main(int argc, const char **argv) return 0; } = + rc =3D idxd_kmod_init(&kmod_ctx, &mod); + if (rc < 0) { + fprintf(stderr, "Failed initializing kernel module\n"); + goto error_exit; + } + rc =3D accfg_new(&ctx); - if (rc) - return 0; + if (rc) { + kmod_module_unref(mod); + kmod_unref(kmod_ctx); + goto error_exit; + } + rc =3D main_handle_internal_command(argc, argv, ctx, commands, ARRAY_SIZE(commands)); accfg_unref(ctx); + kmod_module_unref(mod); + kmod_unref(kmod_ctx); = if (!rc) return EXIT_SUCCESS; - +error_exit: return EXIT_FAILURE; } -- = 2.26.2 --===============0040933966504294793==--