Ejemplo n.º 1
0
static int
virStorageDriverLoadBackendModule(const char *name,
                                  const char *regfunc,
                                  bool forceload)
{
    char *modfile = NULL;
    int ret;

    if (!(modfile = virFileFindResourceFull(name,
                                            "libvirt_storage_backend_",
                                            ".so",
                                            abs_topbuilddir "/src/.libs",
                                            STORAGE_BACKEND_MODULE_DIR,
                                            "LIBVIRT_STORAGE_BACKEND_DIR")))
        return 1;

    if ((ret = virDriverLoadModuleFull(modfile, regfunc, NULL)) != 0) {
        if (forceload) {
            virReportError(VIR_ERR_INTERNAL_ERROR,
                           _("failed to load storage backend module '%s'"),
                           name);
            ret = -1;
        }
    }

    VIR_FREE(modfile);

    return ret;
}
Ejemplo n.º 2
0
static virNetClientPtr
virLogManagerConnect(bool privileged,
                     virNetClientProgramPtr *prog)
{
    virNetClientPtr client = NULL;
    char *logdpath;
    char *daemonPath = NULL;

    *prog = NULL;

    if (!(logdpath = virLogManagerDaemonPath(privileged)))
        goto error;

    if (!privileged &&
        !(daemonPath = virFileFindResourceFull("virtlogd",
                                               NULL, NULL,
                                               abs_topbuilddir "/src",
                                               SBINDIR,
                                               "VIRTLOGD_PATH")))
        goto error;

    if (!(client = virNetClientNewUNIX(logdpath,
                                       daemonPath != NULL,
                                       daemonPath)))
        goto error;

    if (!(*prog = virNetClientProgramNew(VIR_LOG_MANAGER_PROTOCOL_PROGRAM,
                                         VIR_LOG_MANAGER_PROTOCOL_PROGRAM_VERSION,
                                         NULL,
                                         0,
                                         NULL)))
        goto error;

    if (virNetClientAddProgram(client, *prog) < 0)
        goto error;

    VIR_FREE(daemonPath);
    VIR_FREE(logdpath);

    return client;

 error:
    VIR_FREE(daemonPath);
    VIR_FREE(logdpath);
    virNetClientClose(client);
    virObjectUnref(client);
    virObjectUnref(*prog);
    return NULL;
}
Ejemplo n.º 3
0
static int
virStorageDriverLoadBackendModule(const char *name,
                                  const char *regfunc,
                                  bool forceload)
{
    VIR_AUTOFREE(char *) modfile = NULL;

    if (!(modfile = virFileFindResourceFull(name,
                                            "libvirt_storage_backend_",
                                            ".so",
                                            abs_top_builddir "/src/.libs",
                                            STORAGE_BACKEND_MODULE_DIR,
                                            "LIBVIRT_STORAGE_BACKEND_DIR")))
        return -1;

    return virModuleLoad(modfile, regfunc, forceload);
}
Ejemplo n.º 4
0
static int
virStorageFileLoadBackendModule(const char *name,
                                const char *regfunc,
                                bool forceload)
{
    char *modfile = NULL;
    int ret;

    if (!(modfile = virFileFindResourceFull(name,
                                            "libvirt_storage_file_",
                                            ".so",
                                            abs_topbuilddir "/src/.libs",
                                            STORAGE_FILE_MODULE_DIR,
                                            "LIBVIRT_STORAGE_FILE_DIR")))
        return -1;

    ret = virModuleLoad(modfile, regfunc, forceload);

    VIR_FREE(modfile);

    return ret;
}
Ejemplo n.º 5
0
int
virDriverLoadModule(const char *name,
                    const char *regfunc)
{
    char *modfile = NULL;
    int ret;

    VIR_DEBUG("Module load %s", name);

    if (!(modfile = virFileFindResourceFull(name,
                                            "libvirt_driver_",
                                            ".so",
                                            abs_topbuilddir "/src/.libs",
                                            DEFAULT_DRIVER_DIR,
                                            "LIBVIRT_DRIVER_DIR")))
        return 1;

    ret = virDriverLoadModuleFull(modfile, regfunc, NULL);

    VIR_FREE(modfile);

    return ret;
}
Ejemplo n.º 6
0
virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
                                                const char *driverName,
                                                const char *configDir,
                                                unsigned int flags)
{
    void *handle = NULL;
    virLockDriverPtr driver;
    virLockManagerPluginPtr plugin = NULL;
    char *modfile = NULL;
    char *configFile = NULL;

    VIR_DEBUG("name=%s driverName=%s configDir=%s flags=0x%x",
              name, driverName, configDir, flags);

    if (virAsprintf(&configFile, "%s/%s-%s.conf",
                    configDir, driverName, name) < 0)
        return NULL;

    if (STREQ(name, "nop")) {
        driver = &virLockDriverNop;
    } else {
        if (!(modfile = virFileFindResourceFull(name,
                                                NULL,
                                                ".so",
                                                abs_top_builddir "/src/.libs",
                                                LIBDIR "/libvirt/lock-driver",
                                                "LIBVIRT_LOCK_MANAGER_PLUGIN_DIR")))
            goto cleanup;

        VIR_DEBUG("Module load %s from %s", name, modfile);

        if (access(modfile, R_OK) < 0) {
            virReportSystemError(errno,
                                 _("Plugin %s not accessible"),
                                 modfile);
            goto cleanup;
        }

        handle = dlopen(modfile, RTLD_NOW | RTLD_LOCAL);
        if (!handle) {
            virReportError(VIR_ERR_SYSTEM_ERROR,
                           _("Failed to load plugin %s: %s"),
                           modfile, dlerror());
            goto cleanup;
        }

        if (!(driver = dlsym(handle, "virLockDriverImpl"))) {
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                           _("Missing plugin initialization symbol 'virLockDriverImpl'"));
            goto cleanup;
        }
    }

    if (driver->drvInit(VIR_LOCK_MANAGER_VERSION, configFile, flags) < 0)
        goto cleanup;

    if (VIR_ALLOC(plugin) < 0)
        goto cleanup;

    plugin->driver = driver;
    plugin->handle = handle;
    plugin->refs = 1;
    if (VIR_STRDUP(plugin->name, name) < 0)
        goto cleanup;

    VIR_FREE(configFile);
    VIR_FREE(modfile);
    return plugin;

 cleanup:
    VIR_FREE(configFile);
    VIR_FREE(plugin);
    VIR_FREE(modfile);
    if (handle)
        dlclose(handle);
    return NULL;
}
Ejemplo n.º 7
0
void *
virDriverLoadModule(const char *name)
{
    char *modfile = NULL, *regfunc = NULL, *fixedname = NULL;
    char *tmp;
    void *handle = NULL;
    int (*regsym)(void);

    VIR_DEBUG("Module load %s", name);

    if (!(modfile = virFileFindResourceFull(name,
                                            "libvirt_driver_",
                                            ".so",
                                            abs_topbuilddir "/src/.libs",
                                            DEFAULT_DRIVER_DIR,
                                            "LIBVIRT_DRIVER_DIR")))
        return NULL;

    if (access(modfile, R_OK) < 0) {
        VIR_INFO("Module %s not accessible", modfile);
        goto cleanup;
    }

    virUpdateSelfLastChanged(modfile);

    handle = dlopen(modfile, RTLD_NOW | RTLD_GLOBAL);
    if (!handle) {
        VIR_ERROR(_("failed to load module %s %s"), modfile, dlerror());
        goto cleanup;
    }

    if (VIR_STRDUP_QUIET(fixedname, name) < 0) {
        VIR_ERROR(_("out of memory"));
        goto cleanup;
    }

    /* convert something_like_this into somethingLikeThis */
    while ((tmp = strchr(fixedname, '_'))) {
        memmove(tmp, tmp + 1, strlen(tmp));
        *tmp = c_toupper(*tmp);
    }

    if (virAsprintfQuiet(&regfunc, "%sRegister", fixedname) < 0)
        goto cleanup;

    regsym = dlsym(handle, regfunc);
    if (!regsym) {
        VIR_ERROR(_("Missing module registration symbol %s"), regfunc);
        goto cleanup;
    }

    if ((*regsym)() < 0) {
        VIR_ERROR(_("Failed module registration %s"), regfunc);
        goto cleanup;
    }

    VIR_FREE(modfile);
    VIR_FREE(regfunc);
    VIR_FREE(fixedname);
    return handle;

 cleanup:
    VIR_FREE(modfile);
    VIR_FREE(regfunc);
    VIR_FREE(fixedname);
    if (handle)
        dlclose(handle);
    return NULL;
}