From nobody Sun Feb 8 18:15:12 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; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1567551988; cv=none; d=zoho.com; s=zohoarc; b=UaKoeJEbEZAbTiHZ+rq3DsdL0/be627+Zcyh5T4SB4Yn/lZMBbI2dD01DRB3MDNL8IGL0HrQTNYj84oxdMLoihLHQi6c+P5BnZNPM2wS+kCGuhuUsv0rUug9xymlDjeb2A3yP5Psxb8CODn591l0KYtEqCe7M3x8gMW3RAVvgo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567551988; 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:ARC-Authentication-Results; bh=mvXktbk7T6aFJGE515bLIu9vuTzGcr+xfvCToSqE32o=; b=l9VbbcpOvGx7m87Dja/96lzkQP2q+/eDsWvzwgMCBbEXLKKrgzBJntIzZc8zuijqEEaoR/OFUSFIP4P6gsnl3Iz0jej9HvmYGN0StcgPhuPIDoLc9lN2T37heCQl0SixccYpl4SgXenTjB3yB4ZA/KLQ/vAHe1nmfuOCN4j2myo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1567551988919530.2705613997283; Tue, 3 Sep 2019 16:06:28 -0700 (PDT) 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 6B2B818B3D87; Tue, 3 Sep 2019 23:06:27 +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 93A1460126; Tue, 3 Sep 2019 23:06:26 +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 2782789CF; Tue, 3 Sep 2019 23:06:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x83N6MS6030498 for ; Tue, 3 Sep 2019 19:06:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3EA334142; Tue, 3 Sep 2019 23:06:22 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3812461140 for ; Tue, 3 Sep 2019 23:06:17 +0000 (UTC) Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F6C4307D976 for ; Tue, 3 Sep 2019 23:06:16 +0000 (UTC) Received: by mail-qk1-f196.google.com with SMTP id x134so7664087qkb.0 for ; Tue, 03 Sep 2019 16:06:16 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:5c9f:9471:e230:52b:8c93]) by smtp.gmail.com with ESMTPSA id r19sm8383133qtm.44.2019.09.03.16.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 16:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Olmqu3ZggxuYHeSYUP+D2pBUvPYQoXDeQxbs2Mu5bhw=; b=bE2NRZQNTjBCMK3+5j1NKLSkrYuuNYHRn907JlzRY7JqCHtyvgdCKwT1flYX4T76G4 cMllCupi+YRxSWKdQVAvy22V/r5HwEwfEQaCrIjzjGHFgEsSoEhKW9g31hmpL8un4Ra4 mcNjVVSQUkSYln38EqaYa2OTaK4ZSBaXZq3jvCRifG+artwtdhpRU3T+Tj3I9OOOhV33 6no86woCPeCxczHKBVE5zH/0WvSBfZ2ed6Nf9eQ7ZjEYsDxE8+pKPHDqIPTtEEbBLCTb d/MYP0U1HT8vt/Fk1tlW6egT2LF7qDI2w6J7DsgZYd7/tSVjhoAMqdpovfBNQJxCEVrl U6og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Olmqu3ZggxuYHeSYUP+D2pBUvPYQoXDeQxbs2Mu5bhw=; b=Gs6oWwoIr/u81CMdRsGP2EdL49i8FEyRFB1UsrAYP/wcZUFDIZHGYrTv3GoljFuI3X uocXsAN3EgXM57gmgO1a9rrbSPSFiRvDfUQov7MOmRunhA3BtoHaGwiRvm7qnRIzbJ17 y482mJQQsg9lOx3rhQCzQd7DkfGoXhSfcPZDd0EevkcGB1lQY/27irPcQv7LMtD19YT5 ojEIERDHkeofyAowpd4O/BfWTIO1PKAckm4Le+7lo6j9ODOzpHQGyGDZTO2ac6ABfF1Z PEDc8sV1JaL6FP0jlrbZl5grdWNuqyTN7YKcd5DGtWEmd0mfewiu5QsftF0d6qiaX2Rc i1+g== X-Gm-Message-State: APjAAAVdLDsgXVjAnHKbNxDEKfGr9RB33WS96GJkYNdZkztWbo4zR7TQ 7HtDwEW89JiP7lwjbP/fRikw7N5Q X-Google-Smtp-Source: APXvYqz2jpZ6RNOeLekFjYddDqEabWX6i3ySAaiDvkss1emXY9iU5e9r5R9Vyl0r8ICDYwMhlJrogg== X-Received: by 2002:a37:749:: with SMTP id 70mr35770837qkh.399.1567551975629; Tue, 03 Sep 2019 16:06:15 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 3 Sep 2019 20:06:05 -0300 Message-Id: <20190903230607.21557-2-danielhb413@gmail.com> In-Reply-To: <20190903230607.21557-1-danielhb413@gmail.com> References: <20190903230607.21557-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 03 Sep 2019 23:06:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 03 Sep 2019 23:06:16 +0000 (UTC) for IP:'209.85.222.196' DOMAIN:'mail-qk1-f196.google.com' HELO:'mail-qk1-f196.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.15 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS) 209.85.222.196 mail-qk1-f196.google.com 209.85.222.196 mail-qk1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v1 1/3] qemu_conf.c: introduce qemuAddRemoveSharedHostdevInternal 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.6.2 (mx1.redhat.com [10.5.110.63]); Tue, 03 Sep 2019 23:06:27 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" qemuAddSharedHostdev() has a code similar to qemuRemoveSharedHostdev(), with exception of one line that defines the operation (add or remove). This patch introduces a new function that aggregates the common code, using a flag to switch between the operations, avoiding code repetition. No functional change was made. Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_conf.c | 93 ++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 56 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index d771bb6916..a583440807 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1722,9 +1722,33 @@ qemuGetHostdevPath(virDomainHostdevDefPtr hostdev) =20 =20 static int -qemuAddSharedHostdev(virQEMUDriverPtr driver, - virDomainHostdevDefPtr hostdev, - const char *name) +qemuSharedDeviceEntryRemove(virQEMUDriverPtr driver, + const char *key, + const char *name) +{ + qemuSharedDeviceEntryPtr entry =3D NULL; + int idx; + + if (!(entry =3D virHashLookup(driver->sharedDevices, key))) + return -1; + + /* Nothing to do if the shared disk is not recored in the table. */ + if (!qemuSharedDeviceEntryDomainExists(entry, name, &idx)) + return 0; + + if (entry->ref !=3D 1) + VIR_DELETE_ELEMENT(entry->domains, idx, entry->ref); + else + ignore_value(virHashRemoveEntry(driver->sharedDevices, key)); + + return 0; +} + + +static int +qemuAddRemoveSharedHostdevInternal(virQEMUDriverPtr driver, + virDomainHostdevDefPtr hostdev, + const char *name, bool addDevice) { char *dev_path =3D NULL; char *key =3D NULL; @@ -1740,37 +1764,19 @@ qemuAddSharedHostdev(virQEMUDriverPtr driver, goto cleanup; =20 qemuDriverLock(driver); - ret =3D qemuSharedDeviceEntryInsert(driver, key, name); + + if (addDevice) + ret =3D qemuSharedDeviceEntryInsert(driver, key, name); + else + ret =3D qemuSharedDeviceEntryRemove(driver, key, name); + qemuDriverUnlock(driver); =20 cleanup: VIR_FREE(dev_path); VIR_FREE(key); return ret; -} - - -static int -qemuSharedDeviceEntryRemove(virQEMUDriverPtr driver, - const char *key, - const char *name) -{ - qemuSharedDeviceEntryPtr entry =3D NULL; - int idx; - - if (!(entry =3D virHashLookup(driver->sharedDevices, key))) - return -1; - - /* Nothing to do if the shared disk is not recored in the table. */ - if (!qemuSharedDeviceEntryDomainExists(entry, name, &idx)) - return 0; =20 - if (entry->ref !=3D 1) - VIR_DELETE_ELEMENT(entry->domains, idx, entry->ref); - else - ignore_value(virHashRemoveEntry(driver->sharedDevices, key)); - - return 0; } =20 =20 @@ -1795,7 +1801,8 @@ qemuAddSharedDevice(virQEMUDriverPtr driver, if (dev->type =3D=3D VIR_DOMAIN_DEVICE_DISK) return qemuAddSharedDisk(driver, dev->data.disk, name); else if (dev->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) - return qemuAddSharedHostdev(driver, dev->data.hostdev, name); + return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostde= v, + name, true); else return 0; } @@ -1830,33 +1837,6 @@ qemuRemoveSharedDisk(virQEMUDriverPtr driver, } =20 =20 -static int -qemuRemoveSharedHostdev(virQEMUDriverPtr driver, - virDomainHostdevDefPtr hostdev, - const char *name) -{ - char *dev_path =3D NULL; - char *key =3D NULL; - int ret =3D -1; - - if (!qemuIsSharedHostdev(hostdev)) - return 0; - - if (!(dev_path =3D qemuGetHostdevPath(hostdev))) - goto cleanup; - - if (!(key =3D qemuGetSharedDeviceKey(dev_path))) - goto cleanup; - - qemuDriverLock(driver); - ret =3D qemuSharedDeviceEntryRemove(driver, key, name); - qemuDriverUnlock(driver); - - cleanup: - VIR_FREE(dev_path); - VIR_FREE(key); - return ret; -} =20 =20 /* qemuRemoveSharedDevice: @@ -1876,7 +1856,8 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver, if (dev->type =3D=3D VIR_DOMAIN_DEVICE_DISK) return qemuRemoveSharedDisk(driver, dev->data.disk, name); else if (dev->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) - return qemuRemoveSharedHostdev(driver, dev->data.hostdev, name); + return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostde= v, + name, false); else return 0; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list