From nobody Mon Feb 9 07:05:15 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=1595413699; cv=none; d=zohomail.com; s=zohoarc; b=l4JdarGpn+zCkFdvpi7nc2W0TsdFUJuB8MICnoO3ghTVADgYd1VtQJF5UuPWVCIg3w1MnvMiGQSP5pFvw7uHWAQZRCcqFpDttkU0zevL1oXjODv87Px2RTj/mCTT4AxFTZouoWdPn+alk9cBBlUTf15bOg7Vka/+XaXKsxmyTao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595413699; 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=pIImdNrb59c5Io7+9w6fHzsXqcliuaaGNw6f6lawMRc=; b=HChkvsPVet7aPhjDAGlj/S2Ivm+ykbJpsGNpxWeDHUFCHdZV/Oon72FBF1iRovWV2cGcunKIC3euETgDclI/kpVQSlLI9//zriMM6O4rgxOjDrMGj34kt9z1+UDiEZ0Q+9D5UK6bVuqglaTC62myIwcE5mEb1z8ZJdkyip6jNNE= 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 1595413699921329.8267554850661; Wed, 22 Jul 2020 03:28:19 -0700 (PDT) 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-513-i0x1UYGmMV2DqsQpiIx8PQ-1; Wed, 22 Jul 2020 06:28:16 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5BAE980BCA5; Wed, 22 Jul 2020 10:28:11 +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 377E461176; Wed, 22 Jul 2020 10:28:11 +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 07CF6730F5; Wed, 22 Jul 2020 10:28:11 +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 06M9f87v001083 for ; Wed, 22 Jul 2020 05:41:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8FBA92B6DB; Wed, 22 Jul 2020 09:41:08 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E6A62B5BF for ; Wed, 22 Jul 2020 09:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595413698; 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=pIImdNrb59c5Io7+9w6fHzsXqcliuaaGNw6f6lawMRc=; b=V5KEj/ee/e6U356mrQsi0mbncr+QwRf6STVAAC1p0QFIXr+Cp4/twBrGeqCkZQL/TBwFVk 3qRwO233rPZemawK8pTPR3CwcNv8/nzuyIH4DS5jNvFLuL2b0lVB/x85tHgzKHZ05BMc/y +DbFym0TGwbspDGvq4o/5AUHI6D9kb4= X-MC-Unique: i0x1UYGmMV2DqsQpiIx8PQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v1 27/34] qemu_domain_namespace: Drop unused functions Date: Wed, 22 Jul 2020 11:40:21 +0200 Message-Id: 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 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.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" After previous cleanup, creating /dev nodes from pre-exec hook is no longer needed and thus can be removed. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_domain_namespace.c | 248 ------------------------------- 1 file changed, 248 deletions(-) diff --git a/src/qemu/qemu_domain_namespace.c b/src/qemu/qemu_domain_namesp= ace.c index e569b1dbe1..41d79559f9 100644 --- a/src/qemu/qemu_domain_namespace.c +++ b/src/qemu/qemu_domain_namespace.c @@ -185,254 +185,6 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr c= fg, } =20 =20 -struct qemuDomainCreateDeviceData { - const char *path; /* Path to temp new /dev location */ - char * const *devMountsPath; - size_t ndevMountsPath; -}; - - -static int -qemuDomainCreateDeviceRecursive(const char *device, - const struct qemuDomainCreateDeviceData *d= ata, - bool allow_noent, - unsigned int ttl) -{ - g_autofree char *devicePath =3D NULL; - g_autofree char *target =3D NULL; - GStatBuf sb; - int ret =3D -1; - bool isLink =3D false; - bool isDev =3D false; - bool isReg =3D false; - bool isDir =3D false; - bool create =3D false; -#ifdef WITH_SELINUX - char *tcon =3D NULL; -#endif - - if (!ttl) { - virReportSystemError(ELOOP, - _("Too many levels of symbolic links: %s"), - device); - return ret; - } - - if (g_lstat(device, &sb) < 0) { - if (errno =3D=3D ENOENT && allow_noent) { - /* Ignore non-existent device. */ - return 0; - } - virReportSystemError(errno, _("Unable to stat %s"), device); - return ret; - } - - isLink =3D S_ISLNK(sb.st_mode); - isDev =3D S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode); - isReg =3D S_ISREG(sb.st_mode) || S_ISFIFO(sb.st_mode) || S_ISSOCK(sb.s= t_mode); - isDir =3D S_ISDIR(sb.st_mode); - - /* Here, @device might be whatever path in the system. We - * should create the path in the namespace iff it's "/dev" - * prefixed. However, if it is a symlink, we need to traverse - * it too (it might point to something in "/dev"). Just - * consider: - * - * /var/sym1 -> /var/sym2 -> /dev/sda (because users can) - * - * This means, "/var/sym1" is not created (it's shared with - * the parent namespace), nor "/var/sym2", but "/dev/sda". - * - * TODO Remove all `.' and `..' from the @device path. - * Otherwise we might get fooled with `/dev/../var/my_image'. - * For now, lets hope callers play nice. - */ - if (STRPREFIX(device, QEMU_DEVPREFIX)) { - size_t i; - - for (i =3D 0; i < data->ndevMountsPath; i++) { - if (STREQ(data->devMountsPath[i], "/dev")) - continue; - if (STRPREFIX(device, data->devMountsPath[i])) - break; - } - - if (i =3D=3D data->ndevMountsPath) { - /* Okay, @device is in /dev but not in any mount point under /= dev. - * Create it. */ - devicePath =3D g_strdup_printf("%s/%s", data->path, - device + strlen(QEMU_DEVPREFIX)); - - if (virFileMakeParentPath(devicePath) < 0) { - virReportSystemError(errno, - _("Unable to create %s"), - devicePath); - goto cleanup; - } - VIR_DEBUG("Creating dev %s", device); - create =3D true; - } else { - VIR_DEBUG("Skipping dev %s because of %s mount point", - device, data->devMountsPath[i]); - } - } - - if (isLink) { - g_autoptr(GError) gerr =3D NULL; - - /* We are dealing with a symlink. Create a dangling symlink and de= scend - * down one level which hopefully creates the symlink's target. */ - if (!(target =3D g_file_read_link(device, &gerr))) { - virReportError(VIR_ERR_SYSTEM_ERROR, - _("failed to resolve symlink %s: %s"), device, = gerr->message); - goto cleanup; - } - - if (create && - symlink(target, devicePath) < 0) { - if (errno =3D=3D EEXIST) { - ret =3D 0; - } else { - virReportSystemError(errno, - _("unable to create symlink %s"), - devicePath); - } - goto cleanup; - } - - /* Tricky part. If the target starts with a slash then we need to = take - * it as it is. Otherwise we need to replace the last component in= the - * original path with the link target: - * /dev/rtc -> rtc0 (want /dev/rtc0) - * /dev/disk/by-id/ata-SanDisk_SDSSDXPS480G_161101402485 -> ../../= sda - * (want /dev/disk/by-id/../../sda) - * /dev/stdout -> /proc/self/fd/1 (no change needed) - */ - if (!g_path_is_absolute(target)) { - g_autofree char *devTmp =3D g_strdup(device); - char *c =3D NULL, *tmp =3D NULL; - - if ((c =3D strrchr(devTmp, '/'))) - *(c + 1) =3D '\0'; - - tmp =3D g_strdup_printf("%s%s", devTmp, target); - VIR_FREE(target); - target =3D g_steal_pointer(&tmp); - } - - if (qemuDomainCreateDeviceRecursive(target, data, - allow_noent, ttl - 1) < 0) - goto cleanup; - } else if (isDev) { - if (create) { - unlink(devicePath); - if (mknod(devicePath, sb.st_mode, sb.st_rdev) < 0) { - virReportSystemError(errno, - _("Failed to make device %s"), - devicePath); - goto cleanup; - } - } - } else if (isReg) { - if (create && - virFileTouch(devicePath, sb.st_mode) < 0) - goto cleanup; - /* Just create the file here so that code below sets - * proper owner and mode. Bind mount only after that. */ - } else if (isDir) { - if (create && - virFileMakePathWithMode(devicePath, sb.st_mode) < 0) { - virReportSystemError(errno, - _("Unable to make dir %s"), - devicePath); - goto cleanup; - } - } else { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, - _("unsupported device type %s 0%o"), - device, sb.st_mode); - goto cleanup; - } - - if (!create) { - ret =3D 0; - goto cleanup; - } - - if (lchown(devicePath, sb.st_uid, sb.st_gid) < 0) { - virReportSystemError(errno, - _("Failed to chown device %s"), - devicePath); - goto cleanup; - } - - /* Symlinks don't have mode */ - if (!isLink && - chmod(devicePath, sb.st_mode) < 0) { - virReportSystemError(errno, - _("Failed to set permissions for device %s"), - devicePath); - goto cleanup; - } - - /* Symlinks don't have ACLs. */ - if (!isLink && - virFileCopyACLs(device, devicePath) < 0 && - errno !=3D ENOTSUP) { - virReportSystemError(errno, - _("Failed to copy ACLs on device %s"), - devicePath); - goto cleanup; - } - -#ifdef WITH_SELINUX - if (lgetfilecon_raw(device, &tcon) < 0 && - (errno !=3D ENOTSUP && errno !=3D ENODATA)) { - virReportSystemError(errno, - _("Unable to get SELinux label from %s"), - device); - goto cleanup; - } - - if (tcon && - lsetfilecon_raw(devicePath, (const char *)tcon) < 0) { - VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR - if (errno !=3D EOPNOTSUPP && errno !=3D ENOTSUP) { - VIR_WARNINGS_RESET - virReportSystemError(errno, - _("Unable to set SELinux label on %s"), - devicePath); - goto cleanup; - } - } -#endif - - /* Finish mount process started earlier. */ - if ((isReg || isDir) && - virFileBindMountDevice(device, devicePath) < 0) - goto cleanup; - - ret =3D 0; - cleanup: -#ifdef WITH_SELINUX - freecon(tcon); -#endif - return ret; -} - - -static int G_GNUC_UNUSED -qemuDomainCreateDevice(const char *device, - const struct qemuDomainCreateDeviceData *data, - bool allow_noent) -{ - long symloop_max =3D sysconf(_SC_SYMLOOP_MAX); - - return qemuDomainCreateDeviceRecursive(device, data, - allow_noent, symloop_max); -} - - static int qemuDomainPopulateDevices(virQEMUDriverConfigPtr cfg, char ***paths) --=20 2.26.2