[PATCH] netcf return a clear error message from netcf-transaction.sh
by jiahu
netcf need return a detail message when change-begin/change-commit/change-rollback failed.
I think netcf had better print the returned messages from netcf-transaction.sh into netcf's error directly.
for example:
[root@rhel6 ~]# virsh iface-begin
error: Failed to begin network config change transaction
error: Requested operation is not valid: failed to begin transaction:
Operation invalid in this state - Running '/usr/libexec/netcf-transaction.sh change-begin'
operation is invalid in this state: There is already an open transaction (/var/lib/netcf/network-snapshot exists)
---
src/dutil_posix.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/dutil_posix.c b/src/dutil_posix.c
index 8135cc2..113e7b4 100644
--- a/src/dutil_posix.c
+++ b/src/dutil_posix.c
@@ -246,8 +246,8 @@ int run_program(struct netcf *ncf, const char *const *argv, char **output)
"Running '%s' failed to dup2 child process stdout/stderr",
argv_str);
ERR_THROW(WEXITSTATUS(exitstatus) == EXIT_INVALID_IN_THIS_STATE, ncf, EINVALIDOP,
- "Running '%s' operation is invalid in this state",
- argv_str);
+ "Running '%s' operation is invalid in this state: %s",
+ argv_str, *output);
ERR_THROW(WEXITSTATUS(exitstatus) != 0, ncf, EEXEC,
"Running '%s' failed with exit code %d: %s",
argv_str, WEXITSTATUS(exitstatus), *output);
--
1.8.1.4
9 years, 9 months
Re: [netcf-devel] [libvirt-users] [netcf]IFF_RUNNING flag on a bridge device
by Laine Stump
On 05/27/2014 09:07 AM, Jianwei Hu wrote:
> Hi All,
>
> I have one netcf question, please help me to resolve it, thanks.
>
> I can set a IFF_RUNNING flag to a bridge device which are no interface device attached. What status of a flag on a bridge device in current kernel?(w/o interface), is this a new change in kernel or other component? In netcf, but there is a patch to fix that flag issue, I can't understand it.
>
> fix wrong status of bridge devices
> The IFF_RUNNING flag is not set on a bridge device if there are no devices attached to it. So bridges without attached devices are reported as inactive. Destroying inactive devices leads to an error and thus the device can't be removed (easily) from the operating system. This patch checks if the device is a bridge and if so ignores the IFF_RUNNING flag.
Well, I took the patch submitter (Hendrik Schwartke <hendrik(a)os-t.de>)
at his word about the brokenness, and the patch didn't *hurt* anything,
so I pushed it. But now that I try it out I see that, at least on the
kernel version in Fedora 20 (and RHEL6.6) IFF_RUNNING *is* set when a
bridge device is ifconfiged up.
So I'm not sure what had caused the original problem, maybe Hendrik can
eluminate us on that, but it makes sense (since the whole reason for
adding the check of IFF_RUNNING in the first place was to notice when an
ethernet is unplugged, but a bridge is *never* plugged or unplugged in
the sense that we're looking for) and doesn't harm anything (and
apparently does fix something for Hendrik).
BTW, when you have netcf-specific questions of patches, you can send
them to netcf-devel(a)lists.fedorahosted.org
9 years, 10 months
[PATCH] netcf return a clear error message from netcf-transaction.sh
by jiahu
netcf need return a detail message when change-begin/change-commit/change-rollback failed.
I think netcf had better print the returned messages from netcf-transaction.sh into netcf's error directly.
for example:
[root@rhel6 ~]# virsh iface-begin
error: Failed to begin network config change transaction
error: Requested operation is not valid: failed to begin transaction: Operation invalid in this state -
Running '/usr/libexec/netcf-transaction.sh change-begin' operation is invalid in this state:
There is already an open transaction (/var/lib/netcf/network-snapshot exists)
---
src/dutil_posix.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/dutil_posix.c b/src/dutil_posix.c
index 8135cc2..f62aa7d 100644
--- a/src/dutil_posix.c
+++ b/src/dutil_posix.c
@@ -246,8 +246,8 @@ int run_program(struct netcf *ncf, const char *const *argv, char **output)
"Running '%s' failed to dup2 child process stdout/stderr",
argv_str);
ERR_THROW(WEXITSTATUS(exitstatus) == EXIT_INVALID_IN_THIS_STATE, ncf, EINVALIDOP,
- "Running '%s' operation is invalid in this state",
- argv_str);
+ "Running '%s' operation is invalid in this state: $s",
+ argv_str, *output);
ERR_THROW(WEXITSTATUS(exitstatus) != 0, ncf, EEXEC,
"Running '%s' failed with exit code %d: %s",
argv_str, WEXITSTATUS(exitstatus), *output);
--
1.8.1.4
9 years, 10 months
[PATCH] report link state/speed in interface status
by Laine Stump
This patch adds reporting of link state and speed for appropriate
types of interfaces. It is added to the interface status as a single
element:
<link state='up|down|whatever' speed='nn'/>
(the speed is in Mbits/sec, i.e. exactly what is reported by the
kernel). The information come from the following locations in sysfs:
state - /sys/class/net/$ifname/operstate
speed - /sys/class/net/$ifname/speed
Note that speed will be set to 0 if operstate is anything but
"up". Also, this element is not added if an interface is of type
"bridge" (although any interfaces attached to the bridge, and reported
as subordinate interfaces in the same xml, *will* get a <link>
element.)
An example - this is a bridge device which has one bond attached; the
bond is comprised of two ethernets:
<interface name="br0" type="bridge">
<bridge>
<interface name="bond0" type="bond">
<link state="up" speed="1000"/>
<bond>
<interface name="p13p2_5" type="ethernet">
<link state="up" speed="1000"/>
<mac address="ea:8b:8d:18:67:fe"/>
</interface>
<interface name="p13p2_6" type="ethernet">
<link state="up" speed="1000"/>
<mac address="ea:8b:8d:18:67:fe"/>
</interface>
</bond>
</interface>
</bridge>
</interface>
(note that in this case the bond reports a speed of 1000, although in
some cases I have seen it report "2000". This is an issue of the
kernel driver - netcf merely reports whatever the kernel has said.)
---
src/dutil_linux.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/src/dutil_linux.c b/src/dutil_linux.c
index 2db166a..62e0e72 100644
--- a/src/dutil_linux.c
+++ b/src/dutil_linux.c
@@ -1022,6 +1022,69 @@ static void add_bond_info(struct netcf *ncf,
}
+static void add_link_info(struct netcf *ncf,
+ const char *ifname, int ifindex ATTRIBUTE_UNUSED,
+ xmlDocPtr doc, xmlNodePtr root) {
+ char errbuf[128];
+ xmlNodePtr link_node = NULL;
+ xmlAttrPtr prop = NULL;
+ char *path = NULL;
+ size_t length;
+ char *state = NULL;
+ char *speed = NULL;
+ char *nl;
+
+ link_node = xml_node(doc, root, "link");
+ ERR_NOMEM(link_node == NULL, ncf);
+
+ xasprintf(&path, "/sys/class/net/%s/operstate", ifname);
+ ERR_NOMEM(!path, ncf);
+ state = read_file(path, &length);
+ FREE(path);
+ ERR_THROW_STRERROR(!state, ncf, EFILE, "Failed to read %s", path);
+ if ((nl = strchr(state, '\n')))
+ *nl = 0;
+ prop = xmlSetProp(link_node, BAD_CAST "state", BAD_CAST state);
+ ERR_NOMEM(!prop, ncf);
+
+ if (!strcmp(state, "up")) {
+ /* When the link state is "down", different drivers report a
+ * different value for speed. In one local sample, the
+ * following were seen: "10", "65535", "4294967295". Since the
+ * effective speed is "0", just change it to that whenever the
+ * link state is not "up".
+ */
+ xasprintf(&path, "/sys/class/net/%s/speed", ifname);
+ ERR_NOMEM(path == NULL, ncf);
+ speed = read_file(path, &length);
+ if (!speed && errno == EINVAL) {
+ /* attempts to read $ifname/speed result in EINVAL if the
+ * interface is ifconfiged down (which isn't exactly the
+ * same as an operstate of "down").
+ */
+ speed = strdup("0");
+ ERR_NOMEM(!speed, ncf);
+ }
+ ERR_THROW_STRERROR(!speed, ncf, EFILE, "Failed to read %s", path);
+ if ((nl = strchr(speed, '\n')))
+ *nl = 0;
+ } else {
+ FREE(speed);
+ speed = strdup("0");
+ ERR_NOMEM(!speed, ncf);
+ }
+
+ prop = xmlSetProp(link_node, BAD_CAST "speed", BAD_CAST speed);
+ ERR_NOMEM(prop == NULL, ncf);
+
+ error:
+ FREE(path);
+ FREE(state);
+ FREE(speed);
+ return;
+}
+
+
static void add_type_specific_info(struct netcf *ncf,
const char *ifname, int ifindex,
xmlDocPtr doc, xmlNodePtr root) {
@@ -1041,6 +1104,11 @@ static void add_type_specific_info(struct netcf *ncf,
ERR_NOMEM(prop == NULL, ncf);
}
+ if (iftype != NETCF_IFACE_TYPE_BRIDGE) {
+ add_link_info(ncf, ifname, ifindex, doc, root);
+ ERR_BAIL(ncf);
+ }
+
switch (iftype) {
case NETCF_IFACE_TYPE_ETHERNET:
add_ethernet_info(ncf, ifname, ifindex, doc, root);
@@ -1061,6 +1129,7 @@ error:
return;
}
+
void add_state_to_xml_doc(struct netcf_if *nif, xmlDocPtr doc) {
xmlNodePtr root;
int ifindex, code;
--
1.9.3
9 years, 10 months
[PATCH] Fix memory leaks in interactive mode of ncftool
by jiahu
Signed-off-by: Jianwei Hu <jiahu(a)redhat.com>
---
src/ncftool.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/ncftool.c b/src/ncftool.c
index 90c6cbf..7a1db5b 100644
--- a/src/ncftool.c
+++ b/src/ncftool.c
@@ -830,10 +830,13 @@ static int main_loop(void) {
}
cmdret = run_command_line(line, &cmdstatus);
- if (cmdret == 0 && cmdstatus == CMD_RES_QUIT)
+ if (cmdret == 0 && cmdstatus == CMD_RES_QUIT) {
+ free(line);
return ret;
+ }
add_history(line);
+ free(line);
ret = cmdret;
}
}
--
1.8.1.4
9 years, 10 months