From nobody Sun Feb 8 23:06:11 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550234551336297.7826917119538; Fri, 15 Feb 2019 04:42:31 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ADB37AC2C1; Fri, 15 Feb 2019 12:42:23 +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 63987600C1; Fri, 15 Feb 2019 12:42:22 +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 D69FB3F604; Fri, 15 Feb 2019 12:42:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1FCgLIp012019 for ; Fri, 15 Feb 2019 07:42:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2195926350; Fri, 15 Feb 2019 12:42:21 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74A9E16E20; Fri, 15 Feb 2019 12:42:20 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 15 Feb 2019 13:42:10 +0100 Message-Id: <9767ebe1426288a1a7e584bccd3f2eb53b5bd301.1550234476.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 2/5] util: storage: Turn virStorageSource into a virObject 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 15 Feb 2019 12:42:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" To allow tracking a single virStorageSource in multiple structures without extra hassle allow refcounting by turining it into an object. Signed-off-by: Peter Krempa Reviewed-by: Erik Skultety --- src/util/virstoragefile.c | 40 +++++++++++++++++++++++++++++---------- src/util/virstoragefile.h | 2 ++ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 7f52a5fdc7..56c6510c5e 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -47,6 +47,8 @@ VIR_LOG_INIT("util.storagefile"); +static virClassPtr virStorageSourceClass; + VIR_ENUM_IMPL(virStorage, VIR_STORAGE_TYPE_LAST, "none", "file", @@ -2558,30 +2560,48 @@ virStorageSourceClear(virStorageSourcePtr def) virStorageSourceInitiatorClear(&def->initiator); - memset(def, 0, sizeof(*def)); + /* clear everything except the class header */ + memset((char *) def + sizeof(def->parent), 0, + sizeof(*def) - sizeof(def->parent)); +} + + +static void +virStorageSourceDispose(void *obj) +{ + virStorageSourcePtr src =3D obj; + + virStorageSourceClear(src); } +static int +virStorageSourceOnceInit(void) +{ + if (!VIR_CLASS_NEW(virStorageSource, virClassForObject())) + return -1; + + return 0; +} + + +VIR_ONCE_GLOBAL_INIT(virStorageSource); + + virStorageSourcePtr virStorageSourceNew(void) { - virStorageSourcePtr ret =3D NULL; - - if (VIR_ALLOC(ret) < 0) + if (virStorageSourceInitialize() < 0) return NULL; - return ret; + return virObjectNew(virStorageSourceClass); } void virStorageSourceFree(virStorageSourcePtr def) { - if (!def) - return; - - virStorageSourceClear(def); - VIR_FREE(def); + virObjectUnref(def); } diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 48af06653e..dc75d2d36f 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -242,6 +242,8 @@ typedef virStorageSource *virStorageSourcePtr; * IMPORTANT: When adding fields to this struct it's also necessary to add * appropriate code to the virStorageSourceCopy deep copy function */ struct _virStorageSource { + virObject parent; + unsigned int id; /* backing chain identifier, 0 is unset */ int type; /* virStorageType */ char *path; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list