[PATCH 0/5] Couple of trivial improvements to virnetdevopenvswitch.c

In fact, so trivial I've pushed them directly. Michal Prívozník (5): virNetDevOpenvswitchConstructVlans: Use g_auto() for virBuffer virNetDevOpenvswitchConstructVlans: Bring @i into the block where it's used virNetDevOpenvswitchConstructVlans: return void virNetDevOpenvswitchGetVhostuserIfname: Fix const correctness virNetDevOpenvswitchGetVhostuserIfname: Drop cleanup label src/util/virnetdevopenvswitch.c | 41 +++++++++++---------------------- 1 file changed, 13 insertions(+), 28 deletions(-) -- 2.26.2

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virnetdevopenvswitch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index d16af72bdf..6c4e817941 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -72,7 +72,7 @@ virNetDevOpenvswitchConstructVlans(virCommandPtr cmd, const virNetDevVlan *virtV { int ret = -1; size_t i = 0; - virBuffer buf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; if (!virtVlan || !virtVlan->nTags) return 0; @@ -113,7 +113,6 @@ virNetDevOpenvswitchConstructVlans(virCommandPtr cmd, const virNetDevVlan *virtV } ret = 0; - virBufferFreeAndReset(&buf); return ret; } -- 2.26.2

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virnetdevopenvswitch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index 6c4e817941..c9e0c4e956 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -71,7 +71,6 @@ static int virNetDevOpenvswitchConstructVlans(virCommandPtr cmd, const virNetDevVlan *virtVlan) { int ret = -1; - size_t i = 0; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; if (!virtVlan || !virtVlan->nTags) @@ -92,6 +91,8 @@ virNetDevOpenvswitchConstructVlans(virCommandPtr cmd, const virNetDevVlan *virtV } if (virtVlan->trunk) { + size_t i; + virBufferAddLit(&buf, "trunk="); /* @@ -100,7 +101,7 @@ virNetDevOpenvswitchConstructVlans(virCommandPtr cmd, const virNetDevVlan *virtV * start of the for loop if there are more than one VLANs * on this trunk port. */ - virBufferAsprintf(&buf, "%d", virtVlan->tag[i]); + virBufferAsprintf(&buf, "%d", virtVlan->tag[0]); for (i = 1; i < virtVlan->nTags; i++) { virBufferAddLit(&buf, ","); -- 2.26.2

This function returns nothing else than zero. Make it void. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virnetdevopenvswitch.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index c9e0c4e956..c4cf2cf476 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -64,17 +64,14 @@ virNetDevOpenvswitchAddTimeout(virCommandPtr cmd) * * Construct the VLAN configuration parameters to be passed to * ovs-vsctl command. - * - * Returns 0 in case of success or -1 in case of failure. */ -static int +static void virNetDevOpenvswitchConstructVlans(virCommandPtr cmd, const virNetDevVlan *virtVlan) { - int ret = -1; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; if (!virtVlan || !virtVlan->nTags) - return 0; + return; switch (virtVlan->nativeMode) { case VIR_NATIVE_VLAN_MODE_TAGGED: @@ -112,9 +109,6 @@ virNetDevOpenvswitchConstructVlans(virCommandPtr cmd, const virNetDevVlan *virtV } else if (virtVlan->nTags) { virCommandAddArgFormat(cmd, "tag=%d", virtVlan->tag[0]); } - - ret = 0; - return ret; } /** @@ -162,8 +156,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, virCommandAddArgList(cmd, "--", "--if-exists", "del-port", ifname, "--", "add-port", brname, ifname, NULL); - if (virNetDevOpenvswitchConstructVlans(cmd, virtVlan) < 0) - return -1; + virNetDevOpenvswitchConstructVlans(cmd, virtVlan); if (ovsport->profileID[0] == '\0') { virCommandAddArgList(cmd, @@ -547,8 +540,7 @@ int virNetDevOpenvswitchUpdateVlan(const char *ifname, "--", "--if-exists", "clear", "Port", ifname, "vlan_mode", "--", "--if-exists", "set", "Port", ifname, NULL); - if (virNetDevOpenvswitchConstructVlans(cmd, virtVlan) < 0) - return -1; + virNetDevOpenvswitchConstructVlans(cmd, virtVlan); if (virCommandRun(cmd, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, -- 2.26.2

The @tmpIfname is a pointer into a const string. To avoid mistakenly changing the const string via the pointer, make the pointer const too. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virnetdevopenvswitch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index c4cf2cf476..bc6a130035 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -483,7 +483,7 @@ int virNetDevOpenvswitchGetVhostuserIfname(const char *path, char **ifname) { - char *tmpIfname = NULL; + const char *tmpIfname = NULL; int status; int ret = -1; g_autoptr(virCommand) cmd = NULL; -- 2.26.2

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virnetdevopenvswitch.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index bc6a130035..dbb489d174 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -485,7 +485,6 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, { const char *tmpIfname = NULL; int status; - int ret = -1; g_autoptr(virCommand) cmd = NULL; /* Openvswitch vhostuser path are hardcoded to @@ -495,10 +494,8 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, * so we pick the filename and check it's a openvswitch interface */ if (!path || - !(tmpIfname = strrchr(path, '/'))) { - ret = 0; - goto cleanup; - } + !(tmpIfname = strrchr(path, '/'))) + return 0; tmpIfname++; cmd = virCommandNew(OVSVSCTL); @@ -507,15 +504,11 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path, if (virCommandRun(cmd, &status) < 0 || status) { /* it's not a openvswitch vhostuser interface. */ - ret = 0; - goto cleanup; + return 0; } *ifname = g_strdup(tmpIfname); - ret = 1; - - cleanup: - return ret; + return 1; } /** -- 2.26.2
participants (1)
-
Michal Privoznik