From nobody Fri Apr 19 06:53:09 2024 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 Reviewed-by: Pavel Hrdina --- 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 From nobody Fri Apr 19 06:53:09 2024 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=1567551989; cv=none; d=zoho.com; s=zohoarc; b=SCJJhruve+NdiklgwC0pAxE7YY/4zc2FNx6578HRjYzRaOoZZ+Zx4fBX6OnIuJ0rOCYTNMmCwZfXAcE3Qd7+xmn3k/5R+RROULl+srT+KF4iiMGnglRfDHZquBB7xBe612+L4eC+0FZ6aaIG8PUgkEPn7mECuTY6LruYHAACyHk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567551989; 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=e+YtFyPdNElDr+V6kk3fMaREqszUXrT1EhKNoGFF+uE=; b=GbQsVX/9yzPUSbbkV35X/dinXogUr6Hj5dPueo+vcExR+93azYWdx9R5GC/GNl/xPQEj3cpJDWn9usWEPPaJYbc1OdI3Ej/CfP/ZpRKExPXMn083en6qynXOlXWCtjv0N2ozuGpc0Dq+EJav56oJf3SB3jqeoSwl6mFnycqPfYU= 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 1567551989558100.81022800322876; Tue, 3 Sep 2019 16:06:29 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 602B710A8137; Tue, 3 Sep 2019 23:06:27 +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 9C528194B2; 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 236E5180B536; Tue, 3 Sep 2019 23:06:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x83N6NwP030503 for ; Tue, 3 Sep 2019 19:06:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 060F15E1C1; Tue, 3 Sep 2019 23:06:23 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 00AA61E1 for ; Tue, 3 Sep 2019 23:06:18 +0000 (UTC) Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.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 B6295308404E for ; Tue, 3 Sep 2019 23:06:17 +0000 (UTC) Received: by mail-qt1-f196.google.com with SMTP id n7so22172072qtb.6 for ; Tue, 03 Sep 2019 16:06:17 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 16:06:16 -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=Fubry7CKTCUhG9NkihiOztyk2Xq/hVXr5aV0UoKjCvY=; b=iQ6zJKBGPVNforjlPv7nQi2OolMw9ZJHmIpPTGVH5XxwY8FpvbE6RCxRkuGHTrvMIV QhWk/9e1//Fco1+PuLqNh9RWp59elzaYnX+XwKnMdJVLXkx4uCiZ0AmajHKIXji9eFPj 5njMgLNqx9slMCGWY17dUiAPUIBgZCjhvBlxwIHOi2jGbfeeFtxQeYc07+ZeFRvlmkRw GQEcVco1sADJZic+0AhfrzGSY2wwxiETU6vt+7aYUzp0MmfHYkxQhp96z3Y8QBgshxQg tzB4E6IHbX3lAhutZOJJgz63Sn97JQxQ0Cs8/G7qYy7/XvBpYqmfIjDpLjOmvmY0hP12 l4QA== 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=Fubry7CKTCUhG9NkihiOztyk2Xq/hVXr5aV0UoKjCvY=; b=tnFXtf1HaChLgBvWjNEo3qptOb9iMBdPJ5VUyASyu0jIWrheCOagYlzLgAyoim83Fz JyUMjODhj+V96VrZIvqbhtBO5pSh2d+FTice2MVWoKqW6xKumSVft3MccmpernMrkQuW E3NSMg+5Bsfn6vbAkUdWKaaVRhWDxJfR29BDEBz7pgNMs0S4i8nOPc5j3oVaUv+ixci4 oBW4j1sv6qjvQQZDtJkaSrPJKDAbsXTH8kECHihiMHDAE7KfvKozMLyz08OYk/JzD7Qi vXqXjI8EJWMFkZ7I061BCKweSCIZNZczuHoIHXMiZ1fhlp4pMCsd54DRmweibbW7zZDP qE2w== X-Gm-Message-State: APjAAAXJZllVzxWOGxMtF+3lP/ct17+bQf6NMgKI1XlaQnfJ7JNs5H4E gSgvjUbXC9t6sZeg/8XvsRXvM2qc X-Google-Smtp-Source: APXvYqz3cCn1E2p6cNkmNNP9u3kYtccnzD/ri3IuCTJhIW4/tSE7xBChmq0ZMjK6k04eK1ZK/dPIiw== X-Received: by 2002:aed:35ef:: with SMTP id d44mr15016919qte.306.1567551976905; Tue, 03 Sep 2019 16:06:16 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 3 Sep 2019 20:06:06 -0300 Message-Id: <20190903230607.21557-3-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.40]); Tue, 03 Sep 2019 23:06:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 03 Sep 2019 23:06:17 +0000 (UTC) for IP:'209.85.160.196' DOMAIN:'mail-qt1-f196.google.com' HELO:'mail-qt1-f196.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.153 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS) 209.85.160.196 mail-qt1-f196.google.com 209.85.160.196 mail-qt1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v1 2/3] qemu_conf.c: introduce qemuAddRemoveSharedDiskInternal 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); 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" Following the same idea of avoid code repetition from the previous patch, this commit introduces a new function that aggregates the functions of qemuAddSharedDisk() and qemuRemoveSharedDisk() into a single place, using a flag to switch between add/remove operations. Both qemuAddSharedDisk() and qemuRemoveSharedDisk() are public, so keep them around to avoid changing other files due to an internal qemu_conf.c refactory. No functional change was made. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Pavel Hrdina --- src/qemu/qemu_conf.c | 130 +++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 68 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index a583440807..422f0d743d 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1646,19 +1646,35 @@ qemuSharedDeviceEntryInsert(virQEMUDriverPtr driver, } =20 =20 -/* qemuAddSharedDisk: - * @driver: Pointer to qemu driver struct - * @src: disk source - * @name: The domain name - * - * Increase ref count and add the domain name into the list which - * records all the domains that use the shared device if the entry - * already exists, otherwise add a new entry. - */ -int -qemuAddSharedDisk(virQEMUDriverPtr driver, - virDomainDiskDefPtr disk, - const char *name) +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; + + if (entry->ref !=3D 1) + VIR_DELETE_ELEMENT(entry->domains, idx, entry->ref); + else + ignore_value(virHashRemoveEntry(driver->sharedDevices, key)); + + return 0; +} + + +static int +qemuAddRemoveSharedDiskInternal(virQEMUDriverPtr driver, + virDomainDiskDefPtr disk, + const char *name, + bool addDisk) { char *key =3D NULL; int ret =3D -1; @@ -1670,17 +1686,21 @@ qemuAddSharedDisk(virQEMUDriverPtr driver, =20 qemuDriverLock(driver); =20 - if (qemuCheckSharedDisk(driver->sharedDevices, disk) < 0) - goto cleanup; - if (!(key =3D qemuGetSharedDeviceKey(virDomainDiskGetSource(disk)))) goto cleanup; =20 - if (qemuSharedDeviceEntryInsert(driver, key, name) < 0) - goto cleanup; + if (addDisk) { + if (qemuCheckSharedDisk(driver->sharedDevices, disk) < 0) + goto cleanup; =20 - ret =3D 0; + if (qemuSharedDeviceEntryInsert(driver, key, name) < 0) + goto cleanup; + } else { + if (qemuSharedDeviceEntryRemove(driver, key, name) < 0) + goto cleanup; + } =20 + ret =3D 0; cleanup: qemuDriverUnlock(driver); VIR_FREE(key); @@ -1688,6 +1708,24 @@ qemuAddSharedDisk(virQEMUDriverPtr driver, } =20 =20 +/* qemuAddSharedDisk: + * @driver: Pointer to qemu driver struct + * @src: disk source + * @name: The domain name + * + * Increase ref count and add the domain name into the list which + * records all the domains that use the shared device if the entry + * already exists, otherwise add a new entry. + */ +int +qemuAddSharedDisk(virQEMUDriverPtr driver, + virDomainDiskDefPtr disk, + const char *name) +{ + return qemuAddRemoveSharedDiskInternal(driver, disk, name, true); +} + + static bool qemuIsSharedHostdev(virDomainHostdevDefPtr hostdev) { @@ -1721,30 +1759,6 @@ qemuGetHostdevPath(virDomainHostdevDefPtr hostdev) } =20 =20 -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; - - 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, @@ -1799,7 +1813,8 @@ qemuAddSharedDevice(virQEMUDriverPtr driver, * which is only valid for block disk and scsi host device. */ if (dev->type =3D=3D VIR_DOMAIN_DEVICE_DISK) - return qemuAddSharedDisk(driver, dev->data.disk, name); + return qemuAddRemoveSharedDiskInternal(driver, dev->data.disk, + name, true); else if (dev->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostde= v, name, true); @@ -1813,32 +1828,10 @@ qemuRemoveSharedDisk(virQEMUDriverPtr driver, virDomainDiskDefPtr disk, const char *name) { - char *key =3D NULL; - int ret =3D -1; - - if (virStorageSourceIsEmpty(disk->src) || - !disk->src->shared || - !virStorageSourceIsBlockLocal(disk->src)) - return 0; - - qemuDriverLock(driver); - - if (!(key =3D qemuGetSharedDeviceKey(virDomainDiskGetSource(disk)))) - goto cleanup; - - if (qemuSharedDeviceEntryRemove(driver, key, name) < 0) - goto cleanup; - - ret =3D 0; - cleanup: - qemuDriverUnlock(driver); - VIR_FREE(key); - return ret; + return qemuAddRemoveSharedDiskInternal(driver, disk, name, false); } =20 =20 - - /* qemuRemoveSharedDevice: * @driver: Pointer to qemu driver struct * @device: The device def @@ -1854,7 +1847,8 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver, const char *name) { if (dev->type =3D=3D VIR_DOMAIN_DEVICE_DISK) - return qemuRemoveSharedDisk(driver, dev->data.disk, name); + return qemuAddRemoveSharedDiskInternal(driver, dev->data.disk, + name, false); else if (dev->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostde= v, name, false); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri Apr 19 06:53:09 2024 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=1567552008; cv=none; d=zoho.com; s=zohoarc; b=ENd6fbQXIMefhEEQyU0yXeDiVCZ2vm0EfgrPFjOSJe3fBFnvqi/PPXkJZSNww6GujLVaT8yP+tpvtFX8nt0ua6ANDN9oQMqzjOWha98b4lp6XXXcdtuEZV63AukVs8qVGToFF6KfTkCqNhp5oRa77N+0j30jTdlY154oBi6mc4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567552008; 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=I/qkkWj6Cw8mFa+wj2c4xK7YaX0Eaic+psg8jajHU74=; b=PY7jvaxCs0zOHvrqA3kcbvbYk0yhWeA/aR065MaGi259/4bBnRUnRw/0S62Ps0+QOOCJuZe4+MU7qP0z849scF6V1AHd5iGbNVothiWCuksdxi9age1O51Zu0cFaf/4gUGTI8ay0HLW/eZgTFYqY4kGZ2STn6fPP+q548H0Nq9w= 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 1567552008421952.7174191824848; Tue, 3 Sep 2019 16:06:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C46D3090FD9; Tue, 3 Sep 2019 23:06:47 +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 8EE385E1D1; Tue, 3 Sep 2019 23:06:46 +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 417C22551F; Tue, 3 Sep 2019 23:06:46 +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 x83N6OwN030524 for ; Tue, 3 Sep 2019 19:06:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9EE2419D70; Tue, 3 Sep 2019 23:06:24 +0000 (UTC) Received: from mx1.redhat.com (ext-mx21.extmail.prod.ext.phx2.redhat.com [10.5.110.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A3BC194B2 for ; Tue, 3 Sep 2019 23:06:19 +0000 (UTC) Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) (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 E599F18C4264 for ; Tue, 3 Sep 2019 23:06:18 +0000 (UTC) Received: by mail-qk1-f195.google.com with SMTP id f10so17824363qkg.7 for ; Tue, 03 Sep 2019 16:06:18 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 16:06:17 -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=DNUTJi6U489kYXpk3gtmLiv1YX9GG/64VelrrCNxEh0=; b=G4SDaBpCfNXxpCzm0/QKuUUEb7ZiENUm013Z0HebvIPlPSdBPD5LCVbbUexRQTcrCr 4eMkBpR244IyfGcRiyxDc+3vpN8pz1zarXLHfL1mU1OEg/veYDdnvy3lxZsHl8Iqq45v uEO2rx2x/TsBz7bHUfhmC9ZSRkqQg9Qdr9vuNoFF2pc9KoakTion1lN7/8Pn8xwS42wr a3JDwnK4aB/F6E8gDydmC4pyQUEZT7JMvkl6QiD/0qJf4k5/87WWqPs2A3VYk5e2h+PF 277nD0ywjkTz8qJ/jltNBSlkGPVUo2EJqpLTktzaCb0JR98KgpMSrmfpNH2FlpiBdt/G IhkQ== 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=DNUTJi6U489kYXpk3gtmLiv1YX9GG/64VelrrCNxEh0=; b=CnoOxt22M4bL1vJSACUuhd9WSX7mf4VBlXZH182Vf+PQlYBkBVdgp3dz6pwVg7821k e/f29cDG5bojqK9AYVWrL2GUwleYBQKQ7vmybZ+KQofsrMmEqnYFdgfL7r6Efw0fXeF1 CUkSiceGi7jw1UTXZkyEoCCP0uf72zOyqBpG3NIrPKdx5UP8YsjVOjZAZny77ej6QUqc IFyGfO3CxEmP0Eayd/9O64tlK14ugmSa+4s+aXEPzQBNUJWNxJF2zjt93jbtNvVuzQve Ej3A4aUy9w08jENitXKImWVSD5VMP8YTCJHzveDNrMe0+8XEE0hANAeRxisauz7dQKJa gWQw== X-Gm-Message-State: APjAAAULBa/nZ7huOowu69gnpBxwKg7Gtp3Giaz3tRUgzoCDh/G9gt5g ObKepaicdCWmvEv9H8Wxtl5Wa5DF X-Google-Smtp-Source: APXvYqwyZfhYicUqd5Rqgosa595ccbofhTBjdGcfyKXxG6/VELR0K2CtIf+rQYEoqvHYi+kHdppEmg== X-Received: by 2002:a37:ad8:: with SMTP id 207mr18062156qkk.38.1567551978147; Tue, 03 Sep 2019 16:06:18 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Tue, 3 Sep 2019 20:06:07 -0300 Message-Id: <20190903230607.21557-4-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.6.2 (mx1.redhat.com [10.5.110.62]); Tue, 03 Sep 2019 23:06:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Tue, 03 Sep 2019 23:06:19 +0000 (UTC) for IP:'209.85.222.195' DOMAIN:'mail-qk1-f195.google.com' HELO:'mail-qk1-f195.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.195 mail-qk1-f195.google.com 209.85.222.195 mail-qk1-f195.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.62 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza Subject: [libvirt] [PATCH v1 3/3] qemu_conf.c: introduce qemuAddRemoveSharedDeviceInternal 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 03 Sep 2019 23:06:47 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" After the previous commits, qemuAddSharedDevice() and qemuRemoveSharedDevice() are now the same code with a different flag to call the internal functions. This patch aggregates the common code into a new function called qemuAddRemoveSharedDeviceInternal() to further reduce code repetition. Both qemuAddSharedDevice() and qemuRemoveSharedDevice() are kept since they are public functions used elsewhere. No functional change was made. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Pavel Hrdina --- src/qemu/qemu_conf.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 422f0d743d..6ce2d10ac7 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1793,6 +1793,26 @@ qemuAddRemoveSharedHostdevInternal(virQEMUDriverPtr = driver, =20 } =20 +static int +qemuAddRemoveSharedDeviceInternal(virQEMUDriverPtr driver, + virDomainDeviceDefPtr dev, + const char *name, + bool addDevice) +{ + /* Currently the only conflicts we have to care about for + * the shared disk and shared host device is "sgio" setting, + * which is only valid for block disk and scsi host device. + */ + if (dev->type =3D=3D VIR_DOMAIN_DEVICE_DISK) + return qemuAddRemoveSharedDiskInternal(driver, dev->data.disk, + name, addDevice); + else if (dev->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) + return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostde= v, + name, addDevice); + else + return 0; +} + =20 /* qemuAddSharedDevice: * @driver: Pointer to qemu driver struct @@ -1808,18 +1828,7 @@ qemuAddSharedDevice(virQEMUDriverPtr driver, virDomainDeviceDefPtr dev, const char *name) { - /* Currently the only conflicts we have to care about for - * the shared disk and shared host device is "sgio" setting, - * which is only valid for block disk and scsi host device. - */ - if (dev->type =3D=3D VIR_DOMAIN_DEVICE_DISK) - return qemuAddRemoveSharedDiskInternal(driver, dev->data.disk, - name, true); - else if (dev->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) - return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostde= v, - name, true); - else - return 0; + return qemuAddRemoveSharedDeviceInternal(driver, dev, name, true); } =20 =20 @@ -1846,14 +1855,7 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver, virDomainDeviceDefPtr dev, const char *name) { - if (dev->type =3D=3D VIR_DOMAIN_DEVICE_DISK) - return qemuAddRemoveSharedDiskInternal(driver, dev->data.disk, - name, false); - else if (dev->type =3D=3D VIR_DOMAIN_DEVICE_HOSTDEV) - return qemuAddRemoveSharedHostdevInternal(driver, dev->data.hostde= v, - name, false); - else - return 0; + return qemuAddRemoveSharedDeviceInternal(driver, dev, name, false); } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list