mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
interface: Take interface status into account when starting and destroying
https://bugzilla.redhat.com/show_bug.cgi?id=956994 Currently, it is possible to start an interface that is already running: # virsh iface-start eth2 Interface eth2 started # echo $? 0 # virsh iface-start eth2 Interface eth2 started # echo $? 0 # virsh iface-start eth2 Interface eth2 started # echo $? 0 Same applies for destroying a dead interface. We should not allow such state transitions. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
50f5468c96
commit
5bd7ac029e
@ -944,6 +944,7 @@ static int netcfInterfaceCreate(virInterfacePtr ifinfo,
|
|||||||
struct netcf_if *iface = NULL;
|
struct netcf_if *iface = NULL;
|
||||||
virInterfaceDefPtr def = NULL;
|
virInterfaceDefPtr def = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
bool active;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
@ -962,6 +963,15 @@ static int netcfInterfaceCreate(virInterfacePtr ifinfo,
|
|||||||
if (virInterfaceCreateEnsureACL(ifinfo->conn, def) < 0)
|
if (virInterfaceCreateEnsureACL(ifinfo->conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (netcfInterfaceObjIsActive(iface, &active) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (active) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("interface is already running"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
ret = ncf_if_up(iface);
|
ret = ncf_if_up(iface);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
const char *errmsg, *details;
|
const char *errmsg, *details;
|
||||||
@ -987,6 +997,7 @@ static int netcfInterfaceDestroy(virInterfacePtr ifinfo,
|
|||||||
struct netcf_if *iface = NULL;
|
struct netcf_if *iface = NULL;
|
||||||
virInterfaceDefPtr def = NULL;
|
virInterfaceDefPtr def = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
bool active;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
@ -1005,6 +1016,15 @@ static int netcfInterfaceDestroy(virInterfacePtr ifinfo,
|
|||||||
if (virInterfaceDestroyEnsureACL(ifinfo->conn, def) < 0)
|
if (virInterfaceDestroyEnsureACL(ifinfo->conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
if (netcfInterfaceObjIsActive(iface, &active) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!active) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("interface is not running"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
ret = ncf_if_down(iface);
|
ret = ncf_if_down(iface);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
const char *errmsg, *details;
|
const char *errmsg, *details;
|
||||||
|
Loading…
Reference in New Issue
Block a user