From nobody Sun Feb 8 05:08:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1574424031; cv=none; d=zohomail.com; s=zohoarc; b=ajtuTpqw4cfM0uphnc5jeKIUbcn+Qy+4PceOpUJIckgXPG/ygptgcreszy1C0uxSogY/t3jgdRPRn77hjxDf02hyVBvHD3b9QutEYm6O4rjU1tQI5Oo3nzM3lEVvHalqbDzzt1Bxp6vvg0dqrkL/MNhDjHy8NMBVKf9oO6Tpf/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574424031; 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=rckqvVaTVRcQkLLrp6w6pLKrOpp4xD8SHR0baAdN+hM=; b=brs9roSzMWD+vIeePQM92XmpIMjh+PMe4Z31M0xYMFMl20HCg12Jc2WAV7MQyQEjiGgMA9z0EC3HKN/PBEPokYBcaKlcwPooIL0HHsxXNyNrw+tZ9p4+AUXAKcc5M9jLYvFRqcf4NvvUNueHI5Z4NH0aOCw3GlyxsUX5VYOoX8s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 157442403177756.07075976981389; Fri, 22 Nov 2019 04:00:31 -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-7-h0FgswPfPVSbziIpzeLkhg-1; Fri, 22 Nov 2019 07:00:22 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E7E30801E76; Fri, 22 Nov 2019 12:00:15 +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 A264F60906; Fri, 22 Nov 2019 12:00:14 +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 2B5C218089C8; Fri, 22 Nov 2019 12:00:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAMC0CN7013070 for ; Fri, 22 Nov 2019 07:00:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 083B01DA; Fri, 22 Nov 2019 12:00:12 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (dhcp-94.gsslab.fab.redhat.com [10.33.9.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63B95541FC; Fri, 22 Nov 2019 12:00:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574424030; 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=rckqvVaTVRcQkLLrp6w6pLKrOpp4xD8SHR0baAdN+hM=; b=eq4ETKXkQw2dFur0gHqAutwuUNunQeH8JPrBUdRQZPJQfo8leLSY3JhVJZaaxInhRvxc6y /CE+ZE9B5/mWx0VyilSjEBP26dUeeIxDQcosFcKor8sieZNn1e+ltJOrI1yJzcBHSbN/nn 90GIOdZTdKgIXajRUxz/zo8VOGupnKM= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 22 Nov 2019 12:00:03 +0000 Message-Id: <20191122120004.11685-2-berrange@redhat.com> In-Reply-To: <20191122120004.11685-1-berrange@redhat.com> References: <20191122120004.11685-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] conf: stop using hash key when free'ing hash entries 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.13 X-MC-Unique: h0FgswPfPVSbziIpzeLkhg-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" The virChrdevHashEntryFree method uses the hash 'key' as the name of the logfile it has to remove. By storing a struct as the value which contains the stream and the dev path, we can avoid relying on the hash key when free'ing entries. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/virchrdev.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c index 4b8f526d35..d5c0fdbe99 100644 --- a/src/conf/virchrdev.c +++ b/src/conf/virchrdev.c @@ -202,23 +202,30 @@ static void virChrdevLockFileRemove(const char *dev G= _GNUC_UNUSED) } #endif /* #ifdef VIR_CHRDEV_LOCK_FILE_PATH */ =20 +typedef struct { + char *dev; + virStreamPtr st; +} virChrdevHashEntry; + /** * Frees an entry from the hash containing domain's active devices * * @data Opaque data, struct holding information about the device - * @name Path of the device. */ -static void virChrdevHashEntryFree(void *data, - const void *name) +static void virChrdevHashEntryFree(void *data, const void *key G_GNUC_UNUS= ED) { - const char *dev =3D name; - virStreamPtr st =3D data; + virChrdevHashEntry *ent =3D data; + + if (!ent) + return; =20 /* free stream reference */ - virObjectUnref(st); + virObjectUnref(ent->st); =20 /* delete lock file */ - virChrdevLockFileRemove(dev); + virChrdevLockFileRemove(ent->dev); + + g_free(ent); } =20 /** @@ -290,9 +297,9 @@ static int virChrdevFreeClearCallbacks(void *payload, const void *name G_GNUC_UNUSED, void *data G_GNUC_UNUSED) { - virStreamPtr st =3D payload; + virChrdevHashEntry *ent =3D payload; =20 - virFDStreamSetInternalCloseCb(st, NULL, NULL, NULL); + virFDStreamSetInternalCloseCb(ent->st, NULL, NULL, NULL); return 0; } =20 @@ -337,7 +344,7 @@ int virChrdevOpen(virChrdevsPtr devs, bool force) { virChrdevStreamInfoPtr cbdata =3D NULL; - virStreamPtr savedStream; + virChrdevHashEntry *ent; char *path; int ret; bool added =3D false; @@ -363,7 +370,7 @@ int virChrdevOpen(virChrdevsPtr devs, =20 virMutexLock(&devs->lock); =20 - if ((savedStream =3D virHashLookup(devs->hash, path))) { + if ((ent =3D virHashLookup(devs->hash, path))) { if (!force) { /* entry found, device is busy */ virMutexUnlock(&devs->lock); @@ -376,8 +383,8 @@ int virChrdevOpen(virChrdevsPtr devs, * same thread. We need to unregister the callback and abort the * stream manually before we create a new device connection. */ - virFDStreamSetInternalCloseCb(savedStream, NULL, NULL, NULL); - virStreamAbort(savedStream); + virFDStreamSetInternalCloseCb(ent->st, NULL, NULL, NULL); + virStreamAbort(ent->st); virHashRemoveEntry(devs->hash, path); /* continue adding a new stream connection */ } @@ -398,8 +405,15 @@ int virChrdevOpen(virChrdevsPtr devs, if (VIR_ALLOC(cbdata) < 0) goto error; =20 - if (virHashAddEntry(devs->hash, path, st) < 0) + if (VIR_ALLOC(ent) < 0) + goto error; + + ent->st =3D st; + ent->dev =3D g_strdup(path); + + if (virHashAddEntry(devs->hash, path, ent) < 0) goto error; + ent =3D NULL; added =3D true; =20 cbdata->devs =3D devs; @@ -441,5 +455,6 @@ int virChrdevOpen(virChrdevsPtr devs, VIR_FREE(cbdata->path); VIR_FREE(cbdata); virMutexUnlock(&devs->lock); + virChrdevHashEntryFree(ent, NULL); return -1; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list