From patchwork Sat Sep 2 22:38:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 9935869 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 AA347601A1 for ; Sat, 2 Sep 2017 23:00:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E9332858D for ; Sat, 2 Sep 2017 23:00:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 934FE2868B; Sat, 2 Sep 2017 23:00:56 +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 405522858D for ; Sat, 2 Sep 2017 23:00:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51FD4C04B32E; Sat, 2 Sep 2017 23:00:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 51FD4C04B32E Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 51FD4C04B32E Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 35F6C5D75F; Sat, 2 Sep 2017 23:00:55 +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 0EEC81806107; Sat, 2 Sep 2017 23:00:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v82MdsF8028112 for ; Sat, 2 Sep 2017 18:39:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9CB155D96A; Sat, 2 Sep 2017 22:39:54 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E2E505D724; Sat, 2 Sep 2017 22:39:52 +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 8813E81DEA; Sat, 2 Sep 2017 22:39:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8813E81DEA Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mwilck@suse.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8813E81DEA Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Sun, 03 Sep 2017 00:39:49 +0200 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); Sat, 02 Sep 2017 23:39:24 +0100 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski , Hannes Reinecke Date: Sun, 3 Sep 2017 00:38:31 +0200 Message-Id: <20170902223900.7339-3-mwilck@suse.com> In-Reply-To: <20170902223900.7339-1-mwilck@suse.com> References: <20170902223900.7339-1-mwilck@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 205 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 02 Sep 2017 22:39:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 02 Sep 2017 22:39:52 +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.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 02/31] kpartx: helper functions for name and uuid generation 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 02 Sep 2017 23:00:55 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP strip_slash() is copied from kpartx.c, and will be removed there in a follow-up patch. The others are new helpers. Signed-off-by: Martin Wilck --- kpartx/devmapper.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/kpartx/devmapper.c b/kpartx/devmapper.c index 4ab58ce9..3d382285 100644 --- a/kpartx/devmapper.c +++ b/kpartx/devmapper.c @@ -92,6 +92,42 @@ out: return r; } +static void +strip_slash (char * device) +{ + char * p = device; + + while (*(p++) != 0x0) { + + if (*p == '/') + *p = '!'; + } +} + +static int format_partname(char *buf, size_t bufsiz, + const char *mapname, const char *delim, int part) +{ + if (snprintf(buf, bufsiz, "%s%s%d", mapname, delim, part) >= bufsiz) + return 0; + strip_slash(buf); + return 1; +} + +static char *make_prefixed_uuid(int part, const char *uuid) +{ + char *prefixed_uuid; + int len = MAX_PREFIX_LEN + strlen(uuid) + 1; + + prefixed_uuid = malloc(len); + if (!prefixed_uuid) { + fprintf(stderr, "cannot create prefixed uuid : %s\n", + strerror(errno)); + return NULL; + } + snprintf(prefixed_uuid, len, UUID_PREFIX "%s", part, uuid); + return prefixed_uuid; +} + int dm_addmap(int task, const char *name, const char *target, const char *params, uint64_t size, int ro, const char *uuid, int part, mode_t mode, uid_t uid, gid_t gid) @@ -117,13 +153,9 @@ int dm_addmap(int task, const char *name, const char *target, goto addout; if (task == DM_DEVICE_CREATE && uuid) { - prefixed_uuid = malloc(MAX_PREFIX_LEN + strlen(uuid) + 1); - if (!prefixed_uuid) { - fprintf(stderr, "cannot create prefixed uuid : %s\n", - strerror(errno)); + prefixed_uuid = make_prefixed_uuid(part, uuid); + if (prefixed_uuid == NULL) goto addout; - } - sprintf(prefixed_uuid, UUID_PREFIX "%s", part, uuid); if (!dm_task_set_uuid(dmt, prefixed_uuid)) goto addout; }