mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 02:04:16 +03:00
Load nbd module before running qemu-nbd
So far qemu-nbd is run even if the nbd kernel module isn't loaded. This leads to errors when the user starts his lxc container while libvirt could easily load the nbd module automatically.
This commit is contained in:
parent
b2960501c7
commit
0aedcbd37c
@ -63,6 +63,7 @@
|
|||||||
#include "vircommand.h"
|
#include "vircommand.h"
|
||||||
#include "virerror.h"
|
#include "virerror.h"
|
||||||
#include "virfile.h"
|
#include "virfile.h"
|
||||||
|
#include "virkmod.h"
|
||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
#include "virprocess.h"
|
#include "virprocess.h"
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
@ -745,6 +746,7 @@ int virFileLoopDeviceAssociate(const char *file,
|
|||||||
|
|
||||||
|
|
||||||
# define SYSFS_BLOCK_DIR "/sys/block"
|
# define SYSFS_BLOCK_DIR "/sys/block"
|
||||||
|
# define NBD_DRIVER "nbd"
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -811,18 +813,42 @@ virFileNBDDeviceFindUnused(void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
virFileNBDLoadDriver(void)
|
||||||
|
{
|
||||||
|
if (virKModIsBlacklisted(NBD_DRIVER)) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Failed to load nbd module: "
|
||||||
|
"administratively prohibited"));
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
char *errbuf = NULL;
|
||||||
|
|
||||||
|
if ((errbuf = virKModLoad(NBD_DRIVER, true))) {
|
||||||
|
VIR_FREE(errbuf);
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Failed to load nbd module"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
VIR_FREE(errbuf);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int virFileNBDDeviceAssociate(const char *file,
|
int virFileNBDDeviceAssociate(const char *file,
|
||||||
virStorageFileFormat fmt,
|
virStorageFileFormat fmt,
|
||||||
bool readonly,
|
bool readonly,
|
||||||
char **dev)
|
char **dev)
|
||||||
{
|
{
|
||||||
char *nbddev;
|
char *nbddev = NULL;
|
||||||
char *qemunbd = NULL;
|
char *qemunbd = NULL;
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
const char *fmtstr = NULL;
|
const char *fmtstr = NULL;
|
||||||
|
|
||||||
|
if (!virFileNBDLoadDriver())
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (!(nbddev = virFileNBDDeviceFindUnused()))
|
if (!(nbddev = virFileNBDDeviceFindUnused()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user