Re: [libvirt] [PATCH v3 1/3] utils: Introduce functions for modprobe
On 01/30/2014 06:50 PM, John Ferlan wrote: This patch adds functions for various usages of modprobe Signed-off-by: John Ferlan jfer...@redhat.com --- configure.ac | 6 ++ src/Makefile.am | 1 + src/libvirt_private.syms | 7 ++ src/util/virkmod.c | 182 +++ src/util/virkmod.h | 34 + 5 files changed, 230 insertions(+) create mode 100644 src/util/virkmod.c create mode 100644 src/util/virkmod.h diff --git a/configure.ac b/configure.ac index 1670a41..eb11e3b 100644 --- a/configure.ac +++ b/configure.ac @@ -405,6 +405,8 @@ AC_PATH_PROG([UDEVSETTLE], [udevsettle], [], [/sbin:/usr/sbin:/usr/local/sbin:$PATH]) AC_PATH_PROG([MODPROBE], [modprobe], [modprobe], [/sbin:/usr/sbin:/usr/local/sbin:$PATH]) +AC_PATH_PROG([RMMOD], [rmmod], [rmmod], + [/sbin:/usr/sbin:/usr/local/sbin:$PATH]) AC_PATH_PROG([OVSVSCTL], [ovs-vsctl], [ovs-vsctl], [/sbin:/usr/sbin:/usr/local/sbin:$PATH]) AC_PATH_PROG([SCRUB], [scrub], [scrub], @@ -433,6 +435,10 @@ if test -n $MODPROBE; then AC_DEFINE_UNQUOTED([MODPROBE],[$MODPROBE], [Location or name of the modprobe program]) fi +if test -n $RMMOD; then + AC_DEFINE_UNQUOTED([RMMOD],[$RMMOD], +[Location or name of the rmmod program]) +fi AC_DEFINE_UNQUOTED([SCRUB],[$SCRUB], [Location or name of the scrub program (for wiping algorithms)]) diff --git a/src/Makefile.am b/src/Makefile.am index abe0a51..b704045 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -125,6 +125,7 @@ UTIL_SOURCES = \ util/virnetdevvportprofile.h util/virnetdevvportprofile.c \ util/virnetlink.c util/virnetlink.h \ util/virnodesuspend.c util/virnodesuspend.h \ + util/virkmod.c util/virkmod.h \ util/virnuma.c util/virnuma.h \ util/virobject.c util/virobject.h \ util/virpci.c util/virpci.h \ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 45f3117..372231c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1382,6 +1382,13 @@ virKeyFileLoadFile; virKeyFileNew; +# util/virkmod.h +virKModConfig; Do we need to export KModConfig as well? +virKModIsBlacklisted; +virKModLoad; +virKModUnload; + + # util/virlockspace.h virLockSpaceAcquireResource; virLockSpaceCreateResource; diff --git a/src/util/virkmod.c b/src/util/virkmod.c new file mode 100644 index 000..d39a2e3 --- /dev/null +++ b/src/util/virkmod.c @@ -0,0 +1,182 @@ +/* + * virkmod.c: helper APIs for managing kernel modules + * + * Copyright (C) 2014 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * http://www.gnu.org/licenses/. + * + */ + +#include config.h +#include viralloc.h +#include virkmod.h +#include vircommand.h +#include virstring.h + +static int +doModprobe(const char *opts, const char *module, char **outbuf, char **errbuf) +{ +int ret = -1; +virCommandPtr cmd = NULL; + +cmd = virCommandNew(MODPROBE); +if (opts) +virCommandAddArg(cmd, opts); +if (module) +virCommandAddArg(cmd, module); +if (outbuf) +virCommandSetOutputBuffer(cmd, outbuf); +if (errbuf) +virCommandSetErrorBuffer(cmd, errbuf); + +if (virCommandRun(cmd, NULL) 0) +goto cleanup; + +ret = 0; + +cleanup: +virCommandFree(cmd); +return ret; +} + +static int +doRmmod(const char *module, char **errbuf) +{ +int ret = -1; +virCommandPtr cmd = NULL; + +cmd = virCommandNewArgList(RMMOD, module, NULL); +virCommandSetErrorBuffer(cmd, errbuf); + +if (virCommandRun(cmd, NULL) 0) +goto cleanup; + +ret = 0; + +cleanup: +virCommandFree(cmd); +return ret; +} + +/** + * virKModConfig: + * + * Get the current kernel module configuration + * + * Returns NULL on failure or a pointer to the output which + * must be VIR_FREE()'d by the caller + */ +char * +virKModConfig(void) +{ +char *outbuf = NULL; + +if (doModprobe(-c, NULL, outbuf, NULL) 0) +return NULL; + +return
Re: [libvirt] [PATCH v3 1/3] utils: Introduce functions for modprobe
On 02/04/2014 06:06 AM, Ján Tomko wrote: On 01/30/2014 06:50 PM, John Ferlan wrote: This patch adds functions for various usages of modprobe Signed-off-by: John Ferlan jfer...@redhat.com --- configure.ac | 6 ++ src/Makefile.am | 1 + src/libvirt_private.syms | 7 ++ src/util/virkmod.c | 182 +++ src/util/virkmod.h | 34 + 5 files changed, 230 insertions(+) create mode 100644 src/util/virkmod.c create mode 100644 src/util/virkmod.h diff --git a/configure.ac b/configure.ac index 1670a41..eb11e3b 100644 --- a/configure.ac +++ b/configure.ac @@ -405,6 +405,8 @@ AC_PATH_PROG([UDEVSETTLE], [udevsettle], [], [/sbin:/usr/sbin:/usr/local/sbin:$PATH]) AC_PATH_PROG([MODPROBE], [modprobe], [modprobe], [/sbin:/usr/sbin:/usr/local/sbin:$PATH]) +AC_PATH_PROG([RMMOD], [rmmod], [rmmod], +[/sbin:/usr/sbin:/usr/local/sbin:$PATH]) AC_PATH_PROG([OVSVSCTL], [ovs-vsctl], [ovs-vsctl], [/sbin:/usr/sbin:/usr/local/sbin:$PATH]) AC_PATH_PROG([SCRUB], [scrub], [scrub], @@ -433,6 +435,10 @@ if test -n $MODPROBE; then AC_DEFINE_UNQUOTED([MODPROBE],[$MODPROBE], [Location or name of the modprobe program]) fi +if test -n $RMMOD; then + AC_DEFINE_UNQUOTED([RMMOD],[$RMMOD], +[Location or name of the rmmod program]) +fi AC_DEFINE_UNQUOTED([SCRUB],[$SCRUB], [Location or name of the scrub program (for wiping algorithms)]) diff --git a/src/Makefile.am b/src/Makefile.am index abe0a51..b704045 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -125,6 +125,7 @@ UTIL_SOURCES = \ util/virnetdevvportprofile.h util/virnetdevvportprofile.c \ util/virnetlink.c util/virnetlink.h \ util/virnodesuspend.c util/virnodesuspend.h \ +util/virkmod.c util/virkmod.h \ util/virnuma.c util/virnuma.h \ util/virobject.c util/virobject.h \ util/virpci.c util/virpci.h \ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 45f3117..372231c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1382,6 +1382,13 @@ virKeyFileLoadFile; virKeyFileNew; +# util/virkmod.h +virKModConfig; Do we need to export KModConfig as well? It's called from testKModConfig() as well, so while not necessarily for this specific patch, it will be for 2/3. For me it's less churn/file changes for each patch. +virKModIsBlacklisted; +virKModLoad; +virKModUnload; + + # util/virlockspace.h virLockSpaceAcquireResource; virLockSpaceCreateResource; diff --git a/src/util/virkmod.c b/src/util/virkmod.c new file mode 100644 index 000..d39a2e3 --- /dev/null +++ b/src/util/virkmod.c @@ -0,0 +1,182 @@ +/* + * virkmod.c: helper APIs for managing kernel modules + * + * Copyright (C) 2014 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * http://www.gnu.org/licenses/. + * + */ + +#include config.h +#include viralloc.h +#include virkmod.h +#include vircommand.h +#include virstring.h + +static int +doModprobe(const char *opts, const char *module, char **outbuf, char **errbuf) +{ +int ret = -1; +virCommandPtr cmd = NULL; + +cmd = virCommandNew(MODPROBE); +if (opts) +virCommandAddArg(cmd, opts); +if (module) +virCommandAddArg(cmd, module); +if (outbuf) +virCommandSetOutputBuffer(cmd, outbuf); +if (errbuf) +virCommandSetErrorBuffer(cmd, errbuf); + +if (virCommandRun(cmd, NULL) 0) +goto cleanup; + +ret = 0; + +cleanup: +virCommandFree(cmd); +return ret; +} + +static int +doRmmod(const char *module, char **errbuf) +{ +int ret = -1; +virCommandPtr cmd = NULL; + +cmd = virCommandNewArgList(RMMOD, module, NULL); +virCommandSetErrorBuffer(cmd, errbuf); + +if (virCommandRun(cmd, NULL) 0) +goto cleanup; + +ret = 0; + +cleanup: +virCommandFree(cmd); +return ret; +} + +/** + * virKModConfig: + * + * Get the current kernel module configuration + * + * Returns NULL on failure or a pointer to the output which + *