From patchwork Sat Jun 25 00:16:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 640506 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3rbwjD6ZTxz9sDk for ; Sat, 25 Jun 2016 10:16:16 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 9E29D10D67; Fri, 24 Jun 2016 17:16:15 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id D837110D67 for ; Fri, 24 Jun 2016 17:16:14 -0700 (PDT) Received: from bar6.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 6F5531624C7 for ; Fri, 24 Jun 2016 18:16:14 -0600 (MDT) X-ASG-Debug-ID: 1466813772-0b32375aee2db250001-byXFYA Received: from mx3-pf2.cudamail.com ([192.168.14.1]) by bar6.cudamail.com with ESMTP id RhDenApTkTs6P6pw (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 24 Jun 2016 18:16:13 -0600 (MDT) X-Barracuda-Envelope-From: blp@ovn.org X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.1 Received: from unknown (HELO relay2-d.mail.gandi.net) (217.70.183.194) by mx3-pf2.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 25 Jun 2016 00:16:12 -0000 Received-SPF: pass (mx3-pf2.cudamail.com: SPF record at ovn.org designates 217.70.183.194 as permitted sender) X-Barracuda-Apparent-Source-IP: 217.70.183.194 X-Barracuda-RBL-IP: 217.70.183.194 Received: from mfilter28-d.gandi.net (mfilter28-d.gandi.net [217.70.178.159]) by relay2-d.mail.gandi.net (Postfix) with ESMTP id E2F0FC5A4E; Sat, 25 Jun 2016 02:16:10 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter28-d.gandi.net Received: from relay2-d.mail.gandi.net ([IPv6:::ffff:217.70.183.194]) by mfilter28-d.gandi.net (mfilter28-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id gKbx6fvKymJW; Sat, 25 Jun 2016 02:16:09 +0200 (CEST) X-Originating-IP: 208.91.2.3 Received: from sigabrt.benpfaff.org (unknown [208.91.2.3]) (Authenticated sender: blp@ovn.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id D7599C5A46; Sat, 25 Jun 2016 02:16:08 +0200 (CEST) X-CudaMail-Envelope-Sender: blp@ovn.org From: Ben Pfaff To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V2-623051284 X-CudaMail-DTE: 062416 X-CudaMail-Originating-IP: 217.70.183.194 Date: Fri, 24 Jun 2016 17:16:03 -0700 X-ASG-Orig-Subj: [##CM-V2-623051284##][PATCH] sset: New function sset_from_delimited_string(). Message-Id: <1466813763-30249-1-git-send-email-blp@ovn.org> X-Mailer: git-send-email 2.1.3 X-Barracuda-Connect: UNKNOWN[192.168.14.1] X-Barracuda-Start-Time: 1466813773 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Cc: Ben Pfaff Subject: [ovs-dev] [PATCH] sset: New function sset_from_delimited_string(). X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" This simplifies code in a couple of places. Signed-off-by: Ben Pfaff --- lib/sset.c | 21 ++++++++++++++++++++- lib/sset.h | 3 +++ ovn/utilities/ovn-sbctl.c | 10 ++-------- ovsdb/replication.c | 12 +----------- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/lib/sset.c b/lib/sset.c index 4fd3fae..2913097 100644 --- a/lib/sset.c +++ b/lib/sset.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, 2013, 2015 Nicira, Inc. + * Copyright (c) 2011, 2012, 2013, 2015, 2016 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -99,6 +99,25 @@ sset_moved(struct sset *set) hmap_moved(&set->map); } +/* Initializes 'set' with substrings of 's' that are delimited by any of the + * characters in 'delimiters'. For example, + * sset_from_delimited_string(&set, "a b,c", " ,"); + * initializes 'set' with three strings "a", "b", and "c". */ +void +sset_from_delimited_string(struct sset *set, const char *s_, + const char *delimiters) +{ + sset_init(set); + + char *s = xstrdup(s_); + char *token, *save_ptr = NULL; + for (token = strtok_r(s, delimiters, &save_ptr); token != NULL; + token = strtok_r(NULL, delimiters, &save_ptr)) { + sset_add(set, token); + } + free(tokstr); +} + /* Returns true if 'set' contains no strings, false if it contains at least one * string. */ bool diff --git a/lib/sset.h b/lib/sset.h index 9c2f703..c3b5e97 100644 --- a/lib/sset.h +++ b/lib/sset.h @@ -43,6 +43,9 @@ void sset_clone(struct sset *, const struct sset *); void sset_swap(struct sset *, struct sset *); void sset_moved(struct sset *); +void sset_from_delimited_string(struct sset *, const char *s, + const char *delimiters); + /* Count. */ bool sset_is_empty(const struct sset *); size_t sset_count(const struct sset *); diff --git a/ovn/utilities/ovn-sbctl.c b/ovn/utilities/ovn-sbctl.c index c0ee518..61d9cf5 100644 --- a/ovn/utilities/ovn-sbctl.c +++ b/ovn/utilities/ovn-sbctl.c @@ -548,14 +548,8 @@ cmd_chassis_add(struct ctl_context *ctx) check_conflicts(sbctl_ctx, ch_name, xasprintf("cannot create a chassis named %s", ch_name)); - char *tokstr = xstrdup(encap_types); - char *token, *save_ptr = NULL; - struct sset encap_set = SSET_INITIALIZER(&encap_set); - for (token = strtok_r(tokstr, ",", &save_ptr); token != NULL; - token = strtok_r(NULL, ",", &save_ptr)) { - sset_add(&encap_set, token); - } - free(tokstr); + struct sset encap_set; + sset_from_delimited_string(encap_types, &encap_set, ","); size_t n_encaps = sset_count(&encap_set); struct sbrec_encap **encaps = xmalloc(n_encaps * sizeof *encaps); diff --git a/ovsdb/replication.c b/ovsdb/replication.c index 1fa0f25..aa6b9e2 100644 --- a/ovsdb/replication.c +++ b/ovsdb/replication.c @@ -121,19 +121,9 @@ set_remote_ovsdb_server(const char *remote_server) void set_tables_blacklist(const char *blacklist) { - char *save_ptr = NULL; - char *blacklist_item; - replication_init(); - if (blacklist) { - char *t_blacklist = xstrdup(blacklist); - for (blacklist_item = strtok_r(t_blacklist, ",", &save_ptr); - blacklist_item != NULL; - blacklist_item = strtok_r(NULL, ",", &save_ptr)) { - sset_add(&tables_blacklist, blacklist_item); - } - free(t_blacklist); + sset_from_delimited_string(&tables_blacklist, blacklist, ","); } }