src: remove redundant arg to virKModLoad

All callers except for the test suite pass the same value
for the second arg, so it can be removed, simplifying the
code.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2020-06-16 12:07:30 +01:00
parent fc09f3d823
commit 2d80cbc06a
5 changed files with 17 additions and 42 deletions

View File

@ -905,7 +905,7 @@ virFileNBDLoadDriver(void)
} else { } else {
g_autofree char *errbuf = NULL; g_autofree char *errbuf = NULL;
if ((errbuf = virKModLoad(NBD_DRIVER, true))) { if ((errbuf = virKModLoad(NBD_DRIVER))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed to load nbd module")); _("Failed to load nbd module"));
return false; return false;

View File

@ -30,9 +30,7 @@ doModprobe(const char *opts, const char *module, char **outbuf, char **errbuf)
{ {
g_autoptr(virCommand) cmd = NULL; g_autoptr(virCommand) cmd = NULL;
cmd = virCommandNew(MODPROBE); cmd = virCommandNewArgList(MODPROBE, opts, NULL);
if (opts)
virCommandAddArg(cmd, opts);
if (module) if (module)
virCommandAddArg(cmd, module); virCommandAddArg(cmd, module);
if (outbuf) if (outbuf)
@ -83,7 +81,6 @@ virKModConfig(void)
/** /**
* virKModLoad: * virKModLoad:
* @module: Name of the module to load * @module: Name of the module to load
* @useBlacklist: True if honoring blacklist
* *
* Attempts to load a kernel module * Attempts to load a kernel module
* *
@ -92,11 +89,11 @@ virKModConfig(void)
* by the caller * by the caller
*/ */
char * char *
virKModLoad(const char *module, bool useBlacklist) virKModLoad(const char *module)
{ {
char *errbuf = NULL; char *errbuf = NULL;
if (doModprobe(useBlacklist ? "-b" : NULL, module, NULL, &errbuf) < 0) if (doModprobe("-b", module, NULL, &errbuf) < 0)
return errbuf; return errbuf;
VIR_FREE(errbuf); VIR_FREE(errbuf);

View File

@ -24,7 +24,7 @@
#include "internal.h" #include "internal.h"
char *virKModConfig(void); char *virKModConfig(void);
char *virKModLoad(const char *, bool) char *virKModLoad(const char *)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
char *virKModUnload(const char *) char *virKModUnload(const char *)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);

View File

@ -1013,7 +1013,7 @@ virPCIProbeStubDriver(virPCIStubDriver driver)
if (!probed) { if (!probed) {
g_autofree char *errbuf = NULL; g_autofree char *errbuf = NULL;
probed = true; probed = true;
if ((errbuf = virKModLoad(drvname, true))) { if ((errbuf = virKModLoad(drvname))) {
VIR_WARN("failed to load driver %s: %s", drvname, errbuf); VIR_WARN("failed to load driver %s: %s", drvname, errbuf);
goto cleanup; goto cleanup;
} }

View File

@ -27,11 +27,7 @@
# include "virkmod.h" # include "virkmod.h"
# include "virstring.h" # include "virstring.h"
struct testInfo { # define MODNAME "vfio-pci"
const char *module;
const char *exp_cmd;
bool useBlacklist;
};
# define VIR_FROM_THIS VIR_FROM_NONE # define VIR_FROM_THIS VIR_FROM_NONE
@ -87,24 +83,21 @@ checkOutput(virBufferPtr buf, const char *exp_cmd)
static int static int
testKModLoad(const void *args) testKModLoad(const void *args G_GNUC_UNUSED)
{ {
int ret = -1; int ret = -1;
char *errbuf = NULL; char *errbuf = NULL;
const struct testInfo *info = args;
const char *module = info->module;
bool useBlacklist = info->useBlacklist;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
virCommandSetDryRun(&buf, NULL, NULL); virCommandSetDryRun(&buf, NULL, NULL);
errbuf = virKModLoad(module, useBlacklist); errbuf = virKModLoad(MODNAME);
if (errbuf) { if (errbuf) {
fprintf(stderr, "Failed to load, error: %s\n", errbuf); fprintf(stderr, "Failed to load, error: %s\n", errbuf);
goto cleanup; goto cleanup;
} }
if (checkOutput(&buf, info->exp_cmd) < 0) if (checkOutput(&buf, MODPROBE " -b " MODNAME "\n") < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
@ -117,23 +110,21 @@ testKModLoad(const void *args)
static int static int
testKModUnload(const void *args) testKModUnload(const void *args G_GNUC_UNUSED)
{ {
int ret = -1; int ret = -1;
char *errbuf = NULL; char *errbuf = NULL;
const struct testInfo *info = args;
const char *module = info->module;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
virCommandSetDryRun(&buf, NULL, NULL); virCommandSetDryRun(&buf, NULL, NULL);
errbuf = virKModUnload(module); errbuf = virKModUnload(MODNAME);
if (errbuf) { if (errbuf) {
fprintf(stderr, "Failed to unload, error: %s\n", errbuf); fprintf(stderr, "Failed to unload, error: %s\n", errbuf);
goto cleanup; goto cleanup;
} }
if (checkOutput(&buf, info->exp_cmd) < 0) if (checkOutput(&buf, RMMOD " " MODNAME "\n") < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
@ -152,23 +143,10 @@ mymain(void)
if (virTestRun("config", testKModConfig, NULL) < 0) if (virTestRun("config", testKModConfig, NULL) < 0)
ret = -1; ret = -1;
if (virTestRun("load", testKModLoad, NULL) < 0)
/* Although we cannot run the command on the host, we can compare ret = -1;
* the output of the created command against what we'd expect to be if (virTestRun("unload", testKModUnload, NULL) < 0)
* created. So let's at least do that. ret = -1;
*/
# define DO_TEST(_name, _cb, _blkflag, _exp_cmd) \
do { \
struct testInfo data = {.module = "vfio-pci", \
.exp_cmd = _exp_cmd, \
.useBlacklist = _blkflag}; \
if (virTestRun(_name, _cb, &data) < 0) \
ret = -1; \
} while (0)
DO_TEST("load", testKModLoad, false, MODPROBE " vfio-pci\n");
DO_TEST("unload", testKModUnload, false, RMMOD " vfio-pci\n");
DO_TEST("blklist", testKModLoad, true, MODPROBE " -b vfio-pci\n");
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;