mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-26 18:41:17 +00:00
Merge all return paths from network driver APIs
This commit is contained in:
parent
055c2b25d2
commit
b6dbbdc9fe
@ -1,3 +1,7 @@
|
|||||||
|
Thu Dec 4 21:37:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* src/network_driver.c: Merge all return paths from driver APIs
|
||||||
|
|
||||||
Thu Dec 4 21:14:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
Thu Dec 4 21:14:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* src/uml_conf.h: Add driver lock variable
|
* src/uml_conf.h: Add driver lock variable
|
||||||
|
@ -118,7 +118,7 @@ networkStartup(void) {
|
|||||||
char *base = NULL;
|
char *base = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(driverState) < 0)
|
if (VIR_ALLOC(driverState) < 0)
|
||||||
return -1;
|
goto error;
|
||||||
|
|
||||||
if (!uid) {
|
if (!uid) {
|
||||||
if (asprintf(&driverState->logDir,
|
if (asprintf(&driverState->logDir,
|
||||||
@ -160,19 +160,20 @@ networkStartup(void) {
|
|||||||
if (virNetworkLoadAllConfigs(NULL,
|
if (virNetworkLoadAllConfigs(NULL,
|
||||||
&driverState->networks,
|
&driverState->networks,
|
||||||
driverState->networkConfigDir,
|
driverState->networkConfigDir,
|
||||||
driverState->networkAutostartDir) < 0) {
|
driverState->networkAutostartDir) < 0)
|
||||||
networkShutdown();
|
goto error;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
networkAutostartConfigs(driverState);
|
networkAutostartConfigs(driverState);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out_of_memory:
|
out_of_memory:
|
||||||
networkLog (NETWORK_ERR,
|
networkLog (NETWORK_ERR,
|
||||||
"%s", _("networkStartup: out of memory\n"));
|
"%s", _("networkStartup: out of memory\n"));
|
||||||
|
|
||||||
|
error:
|
||||||
VIR_FREE(base);
|
VIR_FREE(base);
|
||||||
VIR_FREE(driverState);
|
networkShutdown();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,16 +215,18 @@ networkReload(void) {
|
|||||||
static int
|
static int
|
||||||
networkActive(void) {
|
networkActive(void) {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
int active = 0;
|
||||||
|
|
||||||
if (!driverState)
|
if (!driverState)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (i = 0 ; i < driverState->networks.count ; i++)
|
for (i = 0 ; i < driverState->networks.count ; i++) {
|
||||||
if (virNetworkIsActive(driverState->networks.objs[i]))
|
virNetworkObjPtr net = driverState->networks.objs[i];
|
||||||
return 1;
|
if (virNetworkIsActive(net))
|
||||||
|
active = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Otherwise we're happy to deal with a shutdown */
|
return active;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -239,10 +242,12 @@ networkShutdown(void) {
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* shutdown active networks */
|
/* shutdown active networks */
|
||||||
for (i = 0 ; i < driverState->networks.count ; i++)
|
for (i = 0 ; i < driverState->networks.count ; i++) {
|
||||||
if (virNetworkIsActive(driverState->networks.objs[i]))
|
virNetworkObjPtr net = driverState->networks.objs[i];
|
||||||
|
if (virNetworkIsActive(net))
|
||||||
networkShutdownNetworkDaemon(NULL, driverState,
|
networkShutdownNetworkDaemon(NULL, driverState,
|
||||||
driverState->networks.objs[i]);
|
driverState->networks.objs[i]);
|
||||||
|
}
|
||||||
|
|
||||||
/* free inactive networks */
|
/* free inactive networks */
|
||||||
virNetworkObjListFree(&driverState->networks);
|
virNetworkObjListFree(&driverState->networks);
|
||||||
@ -804,35 +809,42 @@ static int networkShutdownNetworkDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static virNetworkPtr networkLookupByUUID(virConnectPtr conn ATTRIBUTE_UNUSED,
|
static virNetworkPtr networkLookupByUUID(virConnectPtr conn,
|
||||||
const unsigned char *uuid) {
|
const unsigned char *uuid) {
|
||||||
struct network_driver *driver = (struct network_driver *)conn->networkPrivateData;
|
struct network_driver *driver = conn->networkPrivateData;
|
||||||
virNetworkObjPtr network = virNetworkFindByUUID(&driver->networks, uuid);
|
virNetworkObjPtr network;
|
||||||
virNetworkPtr net;
|
virNetworkPtr ret = NULL;
|
||||||
|
|
||||||
|
network = virNetworkFindByUUID(&driver->networks, uuid);
|
||||||
if (!network) {
|
if (!network) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_NO_NETWORK,
|
networkReportError(conn, NULL, NULL, VIR_ERR_NO_NETWORK,
|
||||||
"%s", _("no network with matching uuid"));
|
"%s", _("no network with matching uuid"));
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
net = virGetNetwork(conn, network->def->name, network->def->uuid);
|
ret = virGetNetwork(conn, network->def->name, network->def->uuid);
|
||||||
return net;
|
|
||||||
}
|
|
||||||
static virNetworkPtr networkLookupByName(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
||||||
const char *name) {
|
|
||||||
struct network_driver *driver = (struct network_driver *)conn->networkPrivateData;
|
|
||||||
virNetworkObjPtr network = virNetworkFindByName(&driver->networks, name);
|
|
||||||
virNetworkPtr net;
|
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static virNetworkPtr networkLookupByName(virConnectPtr conn,
|
||||||
|
const char *name) {
|
||||||
|
struct network_driver *driver = conn->networkPrivateData;
|
||||||
|
virNetworkObjPtr network;
|
||||||
|
virNetworkPtr ret = NULL;
|
||||||
|
|
||||||
|
network = virNetworkFindByName(&driver->networks, name);
|
||||||
if (!network) {
|
if (!network) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_NO_NETWORK,
|
networkReportError(conn, NULL, NULL, VIR_ERR_NO_NETWORK,
|
||||||
"%s", _("no network with matching name"));
|
"%s", _("no network with matching name"));
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
net = virGetNetwork(conn, network->def->name, network->def->uuid);
|
ret = virGetNetwork(conn, network->def->name, network->def->uuid);
|
||||||
return net;
|
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static virDrvOpenStatus networkOpenNetwork(virConnectPtr conn,
|
static virDrvOpenStatus networkOpenNetwork(virConnectPtr conn,
|
||||||
@ -852,7 +864,7 @@ static int networkCloseNetwork(virConnectPtr conn) {
|
|||||||
|
|
||||||
static int networkNumNetworks(virConnectPtr conn) {
|
static int networkNumNetworks(virConnectPtr conn) {
|
||||||
int nactive = 0, i;
|
int nactive = 0, i;
|
||||||
struct network_driver *driver = (struct network_driver *)conn->networkPrivateData;
|
struct network_driver *driver = conn->networkPrivateData;
|
||||||
|
|
||||||
for (i = 0 ; i < driver->networks.count ; i++)
|
for (i = 0 ; i < driver->networks.count ; i++)
|
||||||
if (virNetworkIsActive(driver->networks.objs[i]))
|
if (virNetworkIsActive(driver->networks.objs[i]))
|
||||||
@ -862,7 +874,7 @@ static int networkNumNetworks(virConnectPtr conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int networkListNetworks(virConnectPtr conn, char **const names, int nnames) {
|
static int networkListNetworks(virConnectPtr conn, char **const names, int nnames) {
|
||||||
struct network_driver *driver = (struct network_driver *)conn->networkPrivateData;
|
struct network_driver *driver = conn->networkPrivateData;
|
||||||
int got = 0, i;
|
int got = 0, i;
|
||||||
|
|
||||||
for (i = 0 ; i < driver->networks.count && got < nnames ; i++) {
|
for (i = 0 ; i < driver->networks.count && got < nnames ; i++) {
|
||||||
@ -885,7 +897,7 @@ static int networkListNetworks(virConnectPtr conn, char **const names, int nname
|
|||||||
|
|
||||||
static int networkNumDefinedNetworks(virConnectPtr conn) {
|
static int networkNumDefinedNetworks(virConnectPtr conn) {
|
||||||
int ninactive = 0, i;
|
int ninactive = 0, i;
|
||||||
struct network_driver *driver = (struct network_driver *)conn->networkPrivateData;
|
struct network_driver *driver = conn->networkPrivateData;
|
||||||
|
|
||||||
for (i = 0 ; i < driver->networks.count ; i++)
|
for (i = 0 ; i < driver->networks.count ; i++)
|
||||||
if (!virNetworkIsActive(driver->networks.objs[i]))
|
if (!virNetworkIsActive(driver->networks.objs[i]))
|
||||||
@ -895,7 +907,7 @@ static int networkNumDefinedNetworks(virConnectPtr conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int networkListDefinedNetworks(virConnectPtr conn, char **const names, int nnames) {
|
static int networkListDefinedNetworks(virConnectPtr conn, char **const names, int nnames) {
|
||||||
struct network_driver *driver = (struct network_driver *)conn->networkPrivateData;
|
struct network_driver *driver = conn->networkPrivateData;
|
||||||
int got = 0, i;
|
int got = 0, i;
|
||||||
|
|
||||||
for (i = 0 ; i < driver->networks.count && got < nnames ; i++) {
|
for (i = 0 ; i < driver->networks.count && got < nnames ; i++) {
|
||||||
@ -917,45 +929,47 @@ static int networkListDefinedNetworks(virConnectPtr conn, char **const names, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
static virNetworkPtr networkCreate(virConnectPtr conn, const char *xml) {
|
static virNetworkPtr networkCreate(virConnectPtr conn, const char *xml) {
|
||||||
struct network_driver *driver = (struct network_driver *)conn->networkPrivateData;
|
struct network_driver *driver = conn->networkPrivateData;
|
||||||
virNetworkDefPtr def;
|
virNetworkDefPtr def;
|
||||||
virNetworkObjPtr network;
|
virNetworkObjPtr network;
|
||||||
virNetworkPtr net;
|
virNetworkPtr ret = NULL;
|
||||||
|
|
||||||
if (!(def = virNetworkDefParseString(conn, xml)))
|
if (!(def = virNetworkDefParseString(conn, xml)))
|
||||||
return NULL;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(network = virNetworkAssignDef(conn,
|
if (!(network = virNetworkAssignDef(conn,
|
||||||
&driver->networks,
|
&driver->networks,
|
||||||
def))) {
|
def)))
|
||||||
virNetworkDefFree(def);
|
goto cleanup;
|
||||||
return NULL;
|
def = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (networkStartNetworkDaemon(conn, driver, network) < 0) {
|
if (networkStartNetworkDaemon(conn, driver, network) < 0) {
|
||||||
virNetworkRemoveInactive(&driver->networks,
|
virNetworkRemoveInactive(&driver->networks,
|
||||||
network);
|
network);
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
net = virGetNetwork(conn, network->def->name, network->def->uuid);
|
ret = virGetNetwork(conn, network->def->name, network->def->uuid);
|
||||||
return net;
|
|
||||||
|
cleanup:
|
||||||
|
virNetworkDefFree(def);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
|
static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
|
||||||
struct network_driver *driver = (struct network_driver *)conn->networkPrivateData;
|
struct network_driver *driver = conn->networkPrivateData;
|
||||||
virNetworkDefPtr def;
|
virNetworkDefPtr def;
|
||||||
virNetworkObjPtr network;
|
virNetworkObjPtr network;
|
||||||
|
virNetworkPtr ret = NULL;
|
||||||
|
|
||||||
if (!(def = virNetworkDefParseString(conn, xml)))
|
if (!(def = virNetworkDefParseString(conn, xml)))
|
||||||
return NULL;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(network = virNetworkAssignDef(conn,
|
if (!(network = virNetworkAssignDef(conn,
|
||||||
&driver->networks,
|
&driver->networks,
|
||||||
def))) {
|
def)))
|
||||||
virNetworkDefFree(def);
|
goto cleanup;
|
||||||
return NULL;
|
def = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (virNetworkSaveConfig(conn,
|
if (virNetworkSaveConfig(conn,
|
||||||
driver->networkConfigDir,
|
driver->networkConfigDir,
|
||||||
@ -963,158 +977,187 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) {
|
|||||||
network) < 0) {
|
network) < 0) {
|
||||||
virNetworkRemoveInactive(&driver->networks,
|
virNetworkRemoveInactive(&driver->networks,
|
||||||
network);
|
network);
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
return virGetNetwork(conn, network->def->name, network->def->uuid);
|
ret = virGetNetwork(conn, network->def->name, network->def->uuid);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virNetworkDefFree(def);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int networkUndefine(virNetworkPtr net) {
|
static int networkUndefine(virNetworkPtr net) {
|
||||||
struct network_driver *driver = (struct network_driver *)net->conn->networkPrivateData;
|
struct network_driver *driver = net->conn->networkPrivateData;
|
||||||
virNetworkObjPtr network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
virNetworkObjPtr network;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||||
if (!network) {
|
if (!network) {
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_DOMAIN,
|
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_DOMAIN,
|
||||||
"%s", _("no network with matching uuid"));
|
"%s", _("no network with matching uuid"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virNetworkIsActive(network)) {
|
if (virNetworkIsActive(network)) {
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("network is still active"));
|
"%s", _("network is still active"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virNetworkDeleteConfig(net->conn, network) < 0)
|
if (virNetworkDeleteConfig(net->conn, network) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
|
|
||||||
virNetworkRemoveInactive(&driver->networks,
|
virNetworkRemoveInactive(&driver->networks,
|
||||||
network);
|
network);
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
return 0;
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int networkStart(virNetworkPtr net) {
|
static int networkStart(virNetworkPtr net) {
|
||||||
struct network_driver *driver = (struct network_driver *)net->conn->networkPrivateData;
|
struct network_driver *driver = net->conn->networkPrivateData;
|
||||||
virNetworkObjPtr network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
virNetworkObjPtr network;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||||
if (!network) {
|
if (!network) {
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
||||||
"%s", _("no network with matching uuid"));
|
"%s", _("no network with matching uuid"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
return networkStartNetworkDaemon(net->conn, driver, network);
|
ret = networkStartNetworkDaemon(net->conn, driver, network);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int networkDestroy(virNetworkPtr net) {
|
static int networkDestroy(virNetworkPtr net) {
|
||||||
struct network_driver *driver = (struct network_driver *)net->conn->networkPrivateData;
|
struct network_driver *driver = net->conn->networkPrivateData;
|
||||||
virNetworkObjPtr network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
virNetworkObjPtr network;
|
||||||
int ret;
|
int ret = -1;
|
||||||
|
|
||||||
|
network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||||
if (!network) {
|
if (!network) {
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
||||||
"%s", _("no network with matching uuid"));
|
"%s", _("no network with matching uuid"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = networkShutdownNetworkDaemon(net->conn, driver, network);
|
ret = networkShutdownNetworkDaemon(net->conn, driver, network);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *networkDumpXML(virNetworkPtr net, int flags ATTRIBUTE_UNUSED) {
|
static char *networkDumpXML(virNetworkPtr net, int flags ATTRIBUTE_UNUSED) {
|
||||||
struct network_driver *driver = (struct network_driver *)net->conn->networkPrivateData;
|
struct network_driver *driver = net->conn->networkPrivateData;
|
||||||
virNetworkObjPtr network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
virNetworkObjPtr network;
|
||||||
|
char *ret = NULL;
|
||||||
|
|
||||||
|
network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||||
if (!network) {
|
if (!network) {
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
||||||
"%s", _("no network with matching uuid"));
|
"%s", _("no network with matching uuid"));
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
return virNetworkDefFormat(net->conn, network->def);
|
ret = virNetworkDefFormat(net->conn, network->def);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *networkGetBridgeName(virNetworkPtr net) {
|
static char *networkGetBridgeName(virNetworkPtr net) {
|
||||||
struct network_driver *driver = (struct network_driver *)net->conn->networkPrivateData;
|
struct network_driver *driver = net->conn->networkPrivateData;
|
||||||
virNetworkObjPtr network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
virNetworkObjPtr network;
|
||||||
char *bridge;
|
char *bridge = NULL;
|
||||||
|
|
||||||
|
network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||||
if (!network) {
|
if (!network) {
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
||||||
"%s", _("no network with matching id"));
|
"%s", _("no network with matching id"));
|
||||||
return NULL;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
bridge = strdup(network->def->bridge);
|
bridge = strdup(network->def->bridge);
|
||||||
if (!bridge) {
|
if (!bridge)
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_NO_MEMORY,
|
networkReportError(net->conn, NULL, net, VIR_ERR_NO_MEMORY,
|
||||||
"%s", _("failed to allocate space for network bridge string"));
|
"%s", _("failed to allocate space for network bridge string"));
|
||||||
return NULL;
|
|
||||||
}
|
cleanup:
|
||||||
return bridge;
|
return bridge;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int networkGetAutostart(virNetworkPtr net,
|
static int networkGetAutostart(virNetworkPtr net,
|
||||||
int *autostart) {
|
int *autostart) {
|
||||||
struct network_driver *driver = (struct network_driver *)net->conn->networkPrivateData;
|
struct network_driver *driver = net->conn->networkPrivateData;
|
||||||
virNetworkObjPtr network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
virNetworkObjPtr network;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||||
if (!network) {
|
if (!network) {
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
||||||
"%s", _("no network with matching uuid"));
|
"%s", _("no network with matching uuid"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
*autostart = network->autostart;
|
*autostart = network->autostart;
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
return 0;
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int networkSetAutostart(virNetworkPtr net,
|
static int networkSetAutostart(virNetworkPtr net,
|
||||||
int autostart) {
|
int autostart) {
|
||||||
struct network_driver *driver = (struct network_driver *)net->conn->networkPrivateData;
|
struct network_driver *driver = net->conn->networkPrivateData;
|
||||||
virNetworkObjPtr network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
virNetworkObjPtr network;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
network = virNetworkFindByUUID(&driver->networks, net->uuid);
|
||||||
if (!network) {
|
if (!network) {
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
networkReportError(net->conn, NULL, net, VIR_ERR_INVALID_NETWORK,
|
||||||
"%s", _("no network with matching uuid"));
|
"%s", _("no network with matching uuid"));
|
||||||
return -1;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
autostart = (autostart != 0);
|
autostart = (autostart != 0);
|
||||||
|
|
||||||
if (network->autostart == autostart)
|
if (network->autostart != autostart) {
|
||||||
return 0;
|
if (autostart) {
|
||||||
|
int err;
|
||||||
|
|
||||||
if (autostart) {
|
if ((err = virFileMakePath(driver->networkAutostartDir))) {
|
||||||
int err;
|
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("cannot create autostart directory %s: %s"),
|
||||||
|
driver->networkAutostartDir, strerror(err));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
if ((err = virFileMakePath(driver->networkAutostartDir))) {
|
if (symlink(network->configFile, network->autostartLink) < 0) {
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("cannot create autostart directory %s: %s"),
|
_("Failed to create symlink '%s' to '%s': %s"),
|
||||||
driver->networkAutostartDir, strerror(err));
|
network->autostartLink, network->configFile, strerror(errno));
|
||||||
return -1;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (unlink(network->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
|
||||||
|
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Failed to delete symlink '%s': %s"),
|
||||||
|
network->autostartLink, strerror(errno));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (symlink(network->configFile, network->autostartLink) < 0) {
|
network->autostart = autostart;
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Failed to create symlink '%s' to '%s': %s"),
|
|
||||||
network->autostartLink, network->configFile, strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (unlink(network->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
|
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Failed to delete symlink '%s': %s"),
|
|
||||||
network->autostartLink, strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
network->autostart = autostart;
|
cleanup:
|
||||||
|
return ret;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user