From nobody Mon Sep 16 18:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=riseup.net ARC-Seal: i=1; a=rsa-sha256; t=1693756229; cv=none; d=zohomail.com; s=zohoarc; b=mNCD9vf8gNk0cU+mASQrHTs7nTJJRVKXDIdpuL8gwOkJfcvAzpUn4ARVpA4h0UITwdV2CHGXLHMBjKw7/Ohqb4Am5/MgcLVovf/M/tvCb08JF9rUFpf2swCMk0SGdtEQsCk8v+7TFGxjrltNv6arbi/lYa4bBUNu2sjHqdcNn0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693756229; h=Content-Type:Content-Transfer-Encoding:Cc: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=YtWFwwncE74g/tjEV+wBJZZwBplqwIm/Nlweq8gOhBo=; b=RjrOybwrRMyNc4eOgomJJNG3MDyUjsiW80SivvjmiXHv4qRlkZ1bGzZ2EeeOlhFrC9D0UOTAigNcczykb+PpOCpQPkV6CVdhhoT+3OXbDdMOuwGkbxT6ir7KXgw3YcWpxlT6sJYRwT2hhC8m/R/oZ79riJzXJ3VsIDbl9o1zceU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 169375622993624.274376380618946; Sun, 3 Sep 2023 08:50:29 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-453-up9tX9mxMqe_bnE0IhTsVw-1; Sun, 03 Sep 2023 11:50:22 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1EF838F99FB; Sun, 3 Sep 2023 15:50:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04792400F26A; Sun, 3 Sep 2023 15:50:19 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8C30D1946A6B; Sun, 3 Sep 2023 15:50:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 744A21946588 for ; Sun, 3 Sep 2023 15:50:17 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 647FAD4781D; Sun, 3 Sep 2023 15:50:17 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CC71D4781B for ; Sun, 3 Sep 2023 15:50:17 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3D4EA104086E for ; Sun, 3 Sep 2023 15:50:17 +0000 (UTC) Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-663-MjG5UkG7N-2qeWKd-rKFzQ-1; Sun, 03 Sep 2023 11:50:15 -0400 Received: from fews02-sea.riseup.net (fews02-sea-pn.riseup.net [10.0.1.112]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx1.riseup.net (Postfix) with ESMTPS id 4Rdx6t3knKzDr2N for ; Sun, 3 Sep 2023 15:50:14 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews02-sea.riseup.net (Postfix) with ESMTPSA id 4Rdx6s2S6JzFpfK; Sun, 3 Sep 2023 15:50:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693756228; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=YtWFwwncE74g/tjEV+wBJZZwBplqwIm/Nlweq8gOhBo=; b=UHwg0Jq2n91BjfP1sJt2Fsl0rBMm/Gr3f0WaXrekxEJlHhUwMtsN+5OidhWPBO3cjWLCys TvpnNPig8nmUBU3y9PN+k4aroOmhRgBIHv/SPp5o0+SpFMi+z5Qo9mdTuTdzOl+TRO2eDo SQJ5J0hYe/rnutL+MwCvpEUhiPLEZwM= X-MC-Unique: up9tX9mxMqe_bnE0IhTsVw-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: MjG5UkG7N-2qeWKd-rKFzQ-1 X-Riseup-User-ID: 9C42280D8B5402C431CE4EBC0216086E27D117CF4CCF6B04D06178B8C61AFB44 From: K Shiva Kiran To: libvir-list@redhat.com Subject: [PATCH 06/16] nwfilter: Introduce public API to retrieve user-defined metadata Date: Sun, 3 Sep 2023 21:19:07 +0530 Message-ID: <20230903155034.211476-7-shiva_kr@riseup.net> In-Reply-To: <20230903155034.211476-1-shiva_kr@riseup.net> References: <20230903155034.211476-1-shiva_kr@riseup.net> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: K Shiva Kiran Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: riseup.net Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693756230910100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Introduces `virNWFilterGetMetadata()` to retrieve user defined metadata fields, i.e ``, `<description>` and `<metadata>` Signed-off-by: K Shiva Kiran <shiva_kr@riseup.net> --- include/libvirt/libvirt-nwfilter.h | 5 +++ src/driver-nwfilter.h | 6 +++ src/libvirt-nwfilter.c | 67 ++++++++++++++++++++++++++++++ src/libvirt_public.syms | 1 + 4 files changed, 79 insertions(+) diff --git a/include/libvirt/libvirt-nwfilter.h b/include/libvirt/libvirt-n= wfilter.h index ecab779665..2eed685300 100644 --- a/include/libvirt/libvirt-nwfilter.h +++ b/include/libvirt/libvirt-nwfilter.h @@ -181,4 +181,9 @@ int virNWFilterSetMetadata(virNWFil= terPtr nwfilter, const char *uri, unsigned int flags); =20 +char * virNWFilterGetMetadata(virNWFilterPtr nwfilter, + int type, + const char *uri, + unsigned int flags); + #endif /* LIBVIRT_NWFILTER_H */ diff --git a/src/driver-nwfilter.h b/src/driver-nwfilter.h index 3426781fa0..8d38dbd23c 100644 --- a/src/driver-nwfilter.h +++ b/src/driver-nwfilter.h @@ -94,6 +94,11 @@ typedef int const char *uri, unsigned int flags); =20 +typedef char * +(*virDrvNWFilterGetMetadata)(virNWFilterPtr nwfilter, + int type, + const char *uri, + unsigned int flags); =20 typedef struct _virNWFilterDriver virNWFilterDriver; =20 @@ -120,4 +125,5 @@ struct _virNWFilterDriver { virDrvNWFilterBindingDelete nwfilterBindingDelete; virDrvNWFilterBindingGetXMLDesc nwfilterBindingGetXMLDesc; virDrvNWFilterSetMetadata nwfilterSetMetadata; + virDrvNWFilterGetMetadata nwfilterGetMetadata; }; diff --git a/src/libvirt-nwfilter.c b/src/libvirt-nwfilter.c index 0a0fbdd195..2340d87c4b 100644 --- a/src/libvirt-nwfilter.c +++ b/src/libvirt-nwfilter.c @@ -1007,3 +1007,70 @@ virNWFilterSetMetadata(virNWFilterPtr nwfilter, virDispatchError(nwfilter->conn); return -1; } + + +/** + * virNWFilterGetMetadata: + * @nwfilter: a network filter object + * @type: type of metadata, from virNWFilterMetadataType + * @uri: XML namespace identifier + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Retrieves the appropriate network filter element given by @type. + * If VIR_NWFILTER_METADATA_ELEMENT is requested parameter @uri + * must be set to the name of the namespace the requested elements + * belong to, otherwise must be NULL. + * + * If an element of the network filter XML is not present, the resulting + * error will be VIR_ERR_NO_NWFILTER_METADATA. This method forms + * a shortcut for seeing information from virNWFilterSetMetadata() + * without having to go through virNWFilterGetXMLDesc(). + * + * Returns the metadata string on success (caller must free), + * or NULL in case of failure. + * + * Since: 9.8.0 + */ +char * +virNWFilterGetMetadata(virNWFilterPtr nwfilter, + int type, + const char *uri, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DEBUG("nwfilter=3D%p, type=3D%d, uri=3D'%s', flags=3D0x%x", + nwfilter, type, NULLSTR(uri), flags); + + virResetLastError(); + + virCheckNWFilterReturn(nwfilter, NULL); + + switch (type) { + case VIR_NWFILTER_METADATA_TITLE: + case VIR_NWFILTER_METADATA_DESCRIPTION: + virCheckNullArgGoto(uri, error); + break; + case VIR_NWFILTER_METADATA_ELEMENT: + virCheckNonNullArgGoto(uri, error); + break; + default: + /* For future expansion */ + break; + } + + conn =3D nwfilter->conn; + + if (conn->nwfilterDriver->nwfilterGetMetadata) { + char *ret; + if (!(ret =3D conn->nwfilterDriver->nwfilterGetMetadata(nwfilter, = type, uri, flags))) + goto error; + return ret; + } + + virReportUnsupportedError(); + + error: + virDispatchError(nwfilter->conn); + return NULL; +} diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 4e3b17b475..81cd9afc93 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -940,6 +940,7 @@ LIBVIRT_9.7.0 { =20 LIBVIRT_9.8.0 { global: + virNWFilterGetMetadata; virNWFilterSetMetadata; } LIBVIRT_9.7.0; =20 --=20 2.42.0