From nobody Mon Feb 9 19:25:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1573660215; cv=none; d=zoho.com; s=zohoarc; b=J90blC15IYnBPFyjkdCtFjx/zSy7qiDEcMPZRZ68UQ75pd6vlc0DQjFYk+kzrKv2vjxh/I44luJn7Prx/1mqvC1Hefr9ZmMIIM0LZLQhcyBAZj3Q6SXBHk0Z02wOVsis9szPcJAHfPoa1UF+n2MO0s7Bf9H14SwCGLiRMnmMQ1E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573660215; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zZ+wPzE1NFc95ni1GIkg/njCDKptKlNA3/uTvO2o5n8=; b=JsrhnsEwu7DtCEQr6Ra5CAcFKMwXkWSLiFsE0khnq9YBAC7dvab67zQCjj8r6lOKn9E1FCO/duJdiyPjy1SOYdz/eqXgVezANc5X4gjM64xi1FTnDZvDr8eb+EwoeR4lKYX/N2nSk3q7KVR0aZENCGJsLYc/Rwh1tMiQAv4YtA4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1573660215689889.8185937671248; Wed, 13 Nov 2019 07:50:15 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-155-2yf9ge7DNp-KB_EaO2Hmyg-1; Wed, 13 Nov 2019 10:48:40 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C13A61010F53; Wed, 13 Nov 2019 15:48:30 +0000 (UTC) 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 94D336293B; Wed, 13 Nov 2019 15:48:30 +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 4D2ED18034FD; Wed, 13 Nov 2019 15:48:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xADFmAE5017664 for ; Wed, 13 Nov 2019 10:48:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 69ACE101E58D; Wed, 13 Nov 2019 15:48:10 +0000 (UTC) Received: from lpt.redhat.com (ovpn-200-61.brq.redhat.com [10.40.200.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id C759B10840DD for ; Wed, 13 Nov 2019 15:48:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573660214; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=zZ+wPzE1NFc95ni1GIkg/njCDKptKlNA3/uTvO2o5n8=; b=SDSTDO+q5wrqCgpN3Gj1Tk9Nwc4dA1niLvN1GudjK+doFsUmRRVxaDuy7WZARx5+2pL2AJ Owt55HOVFCj1Eg6hZ0JPvKvMd+kOQ1wGI/XuEPPP0fKGC4My7foiqMj7z3o1FreBeYamcE 6LBe2/2WhTTQCn3q3KMsDOvT1hTJKSw= From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Wed, 13 Nov 2019 16:48:48 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/12] storage: use GRegex virStorageBackendLogicalParseVolExtents X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: 2yf9ge7DNp-KB_EaO2Hmyg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Using GRegex simplifies the code since g_match_info_fetch will copy the matched substring for us. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Peter Krempa --- src/storage/storage_backend_logical.c | 49 +++++++-------------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index 48023abd1a..d6c81e25b1 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -23,7 +23,6 @@ =20 #include #include -#include #include #include =20 @@ -121,16 +120,16 @@ static int virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol, char **const groups) { + g_autoptr(GRegex) re =3D NULL; + g_autoptr(GError) err =3D NULL; + g_autoptr(GMatchInfo) info =3D NULL; int nextents, ret =3D -1; const char *regex_unit =3D "(\\S+)\\((\\S+)\\)"; char *p =3D NULL; size_t i; - int err, nvars; unsigned long long offset, size, length; virStorageVolSourceExtent extent; g_autofree char *regex =3D NULL; - g_autofree regex_t *reg =3D NULL; - g_autofree regmatch_t *vars =3D NULL; =20 memset(&extent, 0, sizeof(extent)); =20 @@ -174,29 +173,14 @@ virStorageBackendLogicalParseVolExtents(virStorageVol= DefPtr vol, strcat(regex, regex_unit); } =20 - if (VIR_ALLOC(reg) < 0) - goto cleanup; - - /* Each extent has a "path:offset" pair, and vars[0] will - * be the whole matched string. - */ - nvars =3D (nextents * 2) + 1; - if (VIR_ALLOC_N(vars, nvars) < 0) - goto cleanup; - - err =3D regcomp(reg, regex, REG_EXTENDED); - if (err !=3D 0) { - char error[100]; - regerror(err, reg, error, sizeof(error)); + re =3D g_regex_new(regex, 0, 0, &err); + if (!re) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to compile regex %s"), - error); - goto cleanup; + _("Failed to compile regex %s"), err->message); + return -1; } =20 - err =3D regexec(reg, groups[3], nvars, vars, 0); - regfree(reg); - if (err !=3D 0) { + if (!g_regex_match(re, groups[3], 0, &info)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed volume extent devices value")); goto cleanup; @@ -204,23 +188,16 @@ virStorageBackendLogicalParseVolExtents(virStorageVol= DefPtr vol, =20 p =3D groups[3]; =20 - /* vars[0] is skipped */ + /* Each extent has a "path:offset" pair, and match #0 + * is the whole matched string. + */ for (i =3D 0; i < nextents; i++) { size_t j; - int len; g_autofree char *offset_str =3D NULL; =20 j =3D (i * 2) + 1; - len =3D vars[j].rm_eo - vars[j].rm_so; - p[vars[j].rm_eo] =3D '\0'; - - if (VIR_STRNDUP(extent.path, - p + vars[j].rm_so, len) < 0) - goto cleanup; - - len =3D vars[j + 1].rm_eo - vars[j + 1].rm_so; - if (VIR_STRNDUP(offset_str, p + vars[j + 1].rm_so, len) < 0) - goto cleanup; + extent.path =3D g_match_info_fetch(info, j); + offset_str =3D g_match_info_fetch(info, j + 1); =20 if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list