From nobody Sat May 18 13:16:14 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693922951; cv=none; d=zohomail.com; s=zohoarc; b=YypDvO8EL2A9/BLcl9LkkMSkj5sGJ3s+me0Sz5RVZznjzivQx4tfrPm0YTrggj7GzOIbFjteCnrp6j8TkglNFJJX3/jFQYECwfWY1xg2tOG2jvBIqRDgWH6aAmcoWrUXjBgDFgN5Y/hpO/ERLhulaU4oKJ4/ettL/PgX3u9FKrg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693922951; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=u0z3dQxzoQrhH/awdg2OBbdXr0Fwd5THIPW3PRjKFSI=; b=CovDYc65jIcUAvsMij9Z1DNaUqFV8NS1K6M6ebeBuy9eoqLCOKBxn4dKSxeK1vz0aF1XSp/Osdpzgm+6Za5MEq5oK2WbmWL/JYqu9IcbnHiYMwL9w+otgSV8pfFwch1F7ykZP38l6lMII8j9eI6nnmvEpGnozwEMkdT3U8gaUd4= 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=pass 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 1693922951911628.4350792639814; Tue, 5 Sep 2023 07:09:11 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-99--G8YgokCO0i9pBXlXZc02A-1; Tue, 05 Sep 2023 10:09:07 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 857321C0754F; Tue, 5 Sep 2023 14:09:01 +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 C6B3D493112; Tue, 5 Sep 2023 14:09:00 +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 9709B1946595; Tue, 5 Sep 2023 14:09:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DADE81946589 for ; Tue, 5 Sep 2023 14:08:58 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C9F2A40CF8EA; Tue, 5 Sep 2023 14:08:58 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71E6140C84A7 for ; Tue, 5 Sep 2023 14:08:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693922950; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=u0z3dQxzoQrhH/awdg2OBbdXr0Fwd5THIPW3PRjKFSI=; b=EYjIBmkBZZ2grnbEuxNmJoHoP6wkcGuuH/7cqjH2p47JKWcBOJMpuiRaJ/IpoxEn08Kc9I 2wDywBmVVQlMRSKh2bGlMDMoxenz9eMlliSu9IZiOhSVU6LJoQlOMyVPsD0PotNjMAD7Yf 8IqcNyUA2QeNlsEeVzmaziQYx9j4y3Q= X-MC-Unique: -G8YgokCO0i9pBXlXZc02A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] storage_util: Drop getDeviceType() Date: Tue, 5 Sep 2023 16:08:56 +0200 Message-ID: <6909da727a66b845c1d88792ffbbc661c43dae36.1693922936.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693923071582100001 Content-Type: text/plain; charset="utf-8"; x-default="true" The sole purpose of getDeviceType() is to parse a file that contains one integer (and a newline character). Well, we already have a function for that: virFileReadValueInt(). Use the latter and drop the former. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/storage/storage_util.c | 75 ++++++++------------------------------ 1 file changed, 15 insertions(+), 60 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index bf8de2475d..7243308a02 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -3847,62 +3847,6 @@ getBlockDevice(uint32_t host, } =20 =20 -/* Function to check if the type file in the given sysfs_path is a - * Direct-Access device (i.e. type 0). Return -1 on failure, type of - * the device otherwise. - */ -static int -getDeviceType(uint32_t host, - uint32_t bus, - uint32_t target, - uint32_t lun, - int *type) -{ - char typestr[3]; - char *gottype, *p; - FILE *typefile; - g_autofree char *type_path =3D NULL; - - type_path =3D g_strdup_printf("/sys/bus/scsi/devices/%u:%u:%u:%u/type"= , host, - bus, target, lun); - - typefile =3D fopen(type_path, "r"); - if (typefile =3D=3D NULL) { - virReportSystemError(errno, - _("Could not find typefile '%1$s'"), - type_path); - /* there was no type file; that doesn't seem right */ - return -1; - } - - gottype =3D fgets(typestr, 3, typefile); - VIR_FORCE_FCLOSE(typefile); - - if (gottype =3D=3D NULL) { - virReportSystemError(errno, - _("Could not read typefile '%1$s'"), - type_path); - /* we couldn't read the type file; have to give up */ - return -1; - } - - /* we don't actually care about p, but if you pass NULL and the last - * character is not \0, virStrToLong_i complains - */ - if (virStrToLong_i(typestr, &p, 10, type) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Device type '%1$s' is not an integer"), - typestr); - /* Hm, type wasn't an integer; seems strange */ - return -1; - } - - VIR_DEBUG("Device type is %d", *type); - - return 0; -} - - /* * Process a Logical Unit entry from the scsi host device directory * @@ -3921,18 +3865,29 @@ processLU(virStoragePoolObj *pool, { int retval =3D -1; int device_type; + int rc; g_autofree char *block_device =3D NULL; =20 VIR_DEBUG("Processing LU %u:%u:%u:%u", host, bus, target, lun); =20 - if (getDeviceType(host, bus, target, lun, &device_type) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to determine if %1$u:%2$u:%3$u:%4$u is a = Direct-Access LUN"), - host, bus, target, lun); + if ((rc =3D virFileReadValueInt(&device_type, + "/sys/bus/scsi/devices/%u:%u:%u:%u/type", + host, bus, target, lun)) < 0) { + + /* Report an error if file doesn't exist. Appropriate + * error was reported otherwise. */ + if (rc =3D=3D -2) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to determine if %1$u:%2$u:%3$u:%4$u i= s a Direct-Access LUN"), + host, bus, target, lun); + } + return -1; } =20 + VIR_DEBUG("Device type is %d", device_type); + /* We don't create volumes for devices other than disk and cdrom * devices, but finding a device that isn't one of those types * isn't an error, either. */ --=20 2.41.0