[libvirt] [PATCH] Add a test interface driver.

Daniel P. Berrange berrange at redhat.com
Mon Jul 20 18:53:30 UTC 2009


On Mon, Jul 20, 2009 at 01:42:06PM -0400, Laine Stump wrote:
> +
> +static char *testInterfaceGetXMLDesc(virInterfacePtr iface,
> +                                     unsigned int flags ATTRIBUTE_UNUSED)
> +{
> +    testConnPtr privconn = iface->conn->privateData;
> +    virInterfaceObjPtr privinterface;
> +    char *ret = NULL;
> +
> +    testDriverLock(privconn);
> +    privinterface = virInterfaceFindByName(&privconn->ifaces,
> +                                           iface->name);
> +    testDriverUnlock(privconn);
> +
> +    if (privinterface == NULL) {
> +        testError(iface->conn, VIR_ERR_INVALID_ARG, __FUNCTION__);

Minor bug there - should be VIR_ERR_NO_INTERFACE.

> +        goto cleanup;
> +    }
> +
> +    ret = virInterfaceDefFormat(iface->conn, privinterface->def);
> +
> +cleanup:
> +    if (privinterface)
> +        virInterfaceObjUnlock(privinterface);
> +    return ret;
> +}
> +
> +
> +static virInterfacePtr testInterfaceDefineXML(virConnectPtr conn, const char *xmlStr,
> +                                              unsigned int flags ATTRIBUTE_UNUSED)
> +{
> +    testConnPtr privconn = conn->privateData;
> +    virInterfaceDefPtr def;
> +    virInterfaceObjPtr iface = NULL;
> +    virInterfacePtr ret = NULL;
> +
> +    testDriverLock(privconn);
> +    if ((def = virInterfaceDefParseString(conn, xmlStr)) == NULL)
> +        goto cleanup;
> +
> +    if ((iface = virInterfaceAssignDef(conn, &privconn->ifaces, def)) == NULL)
> +        goto cleanup;
> +    def = NULL;
> +
> +    ret = virGetInterface(conn, iface->def->name, iface->def->mac);
> +
> +cleanup:
> +    virInterfaceDefFree(def);
> +    if (iface)
> +        virInterfaceObjUnlock(iface);
> +    testDriverUnlock(privconn);
> +    return ret;
> +}
> +
> +static int testInterfaceUndefine(virInterfacePtr iface)
> +{
> +    testConnPtr privconn = iface->conn->privateData;
> +    virInterfaceObjPtr privinterface;
> +    int ret = -1;
> +
> +    testDriverLock(privconn);
> +    privinterface = virInterfaceFindByName(&privconn->ifaces,
> +                                           iface->name);
> +
> +    if (privinterface == NULL) {
> +        testError (iface->conn, VIR_ERR_NO_INTERFACE, NULL);
> +        goto cleanup;
> +    }
> +
> +    virInterfaceRemove(&privconn->ifaces,
> +                       privinterface);
> +    ret = 0;
> +
> +cleanup:
> +    testDriverUnlock(privconn);
> +    return ret;
> +}
> +
> +static int testInterfaceCreate(virInterfacePtr iface,
> +                               unsigned int flags ATTRIBUTE_UNUSED)
> +{
> +    testConnPtr privconn = iface->conn->privateData;
> +    virInterfaceObjPtr privinterface;
> +    int ret = -1;
> +
> +    testDriverLock(privconn);
> +    privinterface = virInterfaceFindByName(&privconn->ifaces,
> +                                           iface->name);
> +
> +    if (privinterface == NULL) {
> +        testError (iface->conn, VIR_ERR_NO_INTERFACE, NULL);
> +        goto cleanup;
> +    }
> +
> +    privinterface->active = 1;
> +    ret = 0;
> +
> +cleanup:
> +    if (privinterface)
> +        virInterfaceObjUnlock(privinterface);
> +    testDriverUnlock(privconn);
> +    return ret;
> +}
> +
> +static int testInterfaceDestroy(virInterfacePtr iface,
> +                                unsigned int flags ATTRIBUTE_UNUSED)
> +{
> +    testConnPtr privconn = iface->conn->privateData;
> +    virInterfaceObjPtr privinterface;
> +    int ret = -1;
> +
> +    testDriverLock(privconn);
> +    privinterface = virInterfaceFindByName(&privconn->ifaces,
> +                                           iface->name);
> +
> +    if (privinterface == NULL) {
> +        testError (iface->conn, VIR_ERR_NO_INTERFACE, NULL);
> +        goto cleanup;
> +    }
> +
> +    privinterface->active = 0;
> +    ret = 0;
> +
> +cleanup:
> +    if (privinterface)
> +        virInterfaceObjUnlock(privinterface);
> +    testDriverUnlock(privconn);
> +    return ret;
> +}

The destroy method should give an OPERATION_INVALID if it is
not current active and likewise create should give an error
if it is already active.


Regards,
Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvir-list mailing list