From patchwork Tue Feb 20 13:26:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10230061 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DD169602B1 for ; Tue, 20 Feb 2018 13:28:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD73D28505 for ; Tue, 20 Feb 2018 13:28:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C287828511; Tue, 20 Feb 2018 13:28:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6FBD628505 for ; Tue, 20 Feb 2018 13:28:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DDD8EC065F75; Tue, 20 Feb 2018 13:28:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8ED6760602; Tue, 20 Feb 2018 13:28:08 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5AC326B50B; Tue, 20 Feb 2018 13:28:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1KDRsN8020668 for ; Tue, 20 Feb 2018 08:27:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id EDF5F60C94; Tue, 20 Feb 2018 13:27:54 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E2F8760BE5; Tue, 20 Feb 2018 13:27:54 +0000 (UTC) Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C8795D5ED; Tue, 20 Feb 2018 13:27:53 +0000 (UTC) Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Tue, 20 Feb 2018 14:27:51 +0100 Received: from apollon.suse.de.de (nwb-a10-snat.microfocus.com [10.120.13.201]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Tue, 20 Feb 2018 13:27:19 +0000 From: Martin Wilck To: Christophe Varoqui , Hannes Reinecke Date: Tue, 20 Feb 2018 14:26:49 +0100 Message-Id: <20180220132658.22295-12-mwilck@suse.com> In-Reply-To: <20180220132658.22295-1-mwilck@suse.com> References: <20180220132658.22295-1-mwilck@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 20 Feb 2018 13:27:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 20 Feb 2018 13:27:54 +0000 (UTC) for IP:'195.135.221.5' DOMAIN:'smtp.nue.novell.com' HELO:'smtp.nue.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 195.135.221.5 smtp.nue.novell.com 195.135.221.5 smtp.nue.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [RFC PATCH 11/20] libmultipath: add vector_convert() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 20 Feb 2018 13:28:09 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP This is a handy helper for creating one vector from another, mapping each element of the origin vector to an element of the target vector with a given conversion function. It can also be used to "concatenate" vectors by passing in a non-NULL first argument. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- libmultipath/vector.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/libmultipath/vector.h b/libmultipath/vector.h index 3f6e579ae19a..6018b57525bf 100644 --- a/libmultipath/vector.h +++ b/libmultipath/vector.h @@ -42,6 +42,35 @@ typedef struct _vector *vector; #define vector_foreach_slot_backwards(v,p,i) \ for (i = VECTOR_SIZE(v); i > 0 && ((p) = (v)->slot[i-1]); i--) +#define identity(x) (x) +/* + * Given a vector vec with elements of given type, + * return a newly allocated vector with elements conv(e) for each element + * e in vec. "conv" may be a macro or a function. + * Use "identity" for a simple copy. + */ +#define vector_convert(new, vec, type, conv) \ + ({ \ + const struct _vector *__v = (vec); \ + vector __t = (new); \ + type *__j; \ + int __i; \ + \ + if (__t == NULL) \ + __t = vector_alloc(); \ + if (__t != NULL) { \ + vector_foreach_slot(__v, __j, __i) { \ + if (vector_alloc_slot(__t) == NULL) { \ + vector_free(__t); \ + __t = NULL; \ + break; \ + } \ + vector_set_slot(__t, conv(__j)); \ + } \ + } \ + __t; \ + }) + /* Prototypes */ extern vector vector_alloc(void); extern void *vector_alloc_slot(vector v);