From nobody Sun Feb 8 23:06:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527817425266712.2765683669675; Thu, 31 May 2018 18:43:45 -0700 (PDT) Received: from localhost ([::1]:46980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOZ6W-0006Oo-4o for importer@patchew.org; Thu, 31 May 2018 21:43:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fOYrE-0003FG-Dt for qemu-devel@nongnu.org; Thu, 31 May 2018 21:27:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fOYrD-0003Iz-3N for qemu-devel@nongnu.org; Thu, 31 May 2018 21:27:56 -0400 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:40627) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fOYrC-0003IZ-VC for qemu-devel@nongnu.org; Thu, 31 May 2018 21:27:55 -0400 Received: by mail-qt0-x241.google.com with SMTP id h2-v6so30292303qtp.7 for ; Thu, 31 May 2018 18:27:54 -0700 (PDT) Received: from localhost.localdomain (96-86-104-61-static.hfc.comcastbusiness.net. [96.86.104.61]) by smtp.gmail.com with ESMTPSA id o68-v6sm2003842qkc.19.2018.05.31.18.27.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 31 May 2018 18:27:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=juliacomputing-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=8Zat6Jv7yNhqDbVlvEPyIjxl3spjALOuCv6+GJx/Y9k=; b=r8TuLHQ5WzPaSoZsdXD6tmYEZWwjxvuzNHvNyxZPLHnsAHNEfVkpNrSayz7taayOgq qRx8F4JdZGM6WQFhS9QvzIpB1V13y5bhYNl+mvC1e6pY9nUwbEA9BkoMUH9SSEtCF4GH WBOFh/0F47Yyt1swo9LxZS3bCC9ptwH4wjqp6J0QgtW2G9CPnpEu3vY1FbqyQeSkqS8M BJ/69ggd+wieeDLEk3Zvz5RCYlPRNMLkmOAn0nBuheuOadmMukGKTa/y9n4oFqZyZ8iN +nDd/zLV5L4xGDfyk4d6RyB5KkA/RGLCdSaubnY0FlIPRUF+SW1G/+EUqhtBkxfJdwpV q8kQ== 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:in-reply-to:references; bh=8Zat6Jv7yNhqDbVlvEPyIjxl3spjALOuCv6+GJx/Y9k=; b=XOhNjmRny83NREe7NWy4GfUNBPdOIhqUyslwi4Fit3IA3yvt67TTslEVkpwwIu4SmP xi4VBINMRU/wQsM/qJyUcbFfngE0YA8qKiq1qJ10VbjWHse1nn7cvqzTNnNVX1SgfLah S1xU/9ydmwu6c7MdtckddAHq0QE7Arqgz6shvkz/HO3syA6ezXs8/O82y+LMQ3u9gII+ PLkmLrZLUlOCi1dY1LyrcxYIuhIvXY6EKdB/hh80momFaBygXFI06+jNkMj9OqR0pCYN mhjwhHmqHNzkPVh+AkMeIWairrM7okN6jPsmRS9EmNS+I3oYCUv94BFBvIeEl39WdEYR PSnA== X-Gm-Message-State: APt69E0QR1oPzLI3LnLQ2jyKNGzEJGqCgM6ttii39jv6J0hSaLh3XUyx SSmbbBFlR/pEjomnYJuNCY+H9hpMBJY= X-Google-Smtp-Source: ADUXVKIuTgvt4Hy+YI2h0oDNdiMdzVx7tvHGnTVptYdD4x5WgbUS+ga4xeG5YiqkGT/kagoqwrO0rw== X-Received: by 2002:ac8:286a:: with SMTP id 39-v6mr9330466qtr.131.1527816474084; Thu, 31 May 2018 18:27:54 -0700 (PDT) From: Keno Fischer To: qemu-devel@nongnu.org Date: Thu, 31 May 2018 21:26:13 -0400 Message-Id: <35ccf95a6898df4e6b5d6f2a61e5612410cc3699.1527814874.git.keno@juliacomputing.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::241 Subject: [Qemu-devel] [PATCH v2 18/20] 9p: darwin: Implement compatibility for mknodat X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Keno Fischer , groug@kaod.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Darwin does not support mknodat. However, to avoid race conditions with later setting the permissions, we must avoid using mknod on the full path instead. We could try to fchdir, but that would cause problems if multiple threads try to call mknodat at the same time. However, luckily there is a solution: Darwin as an (unexposed in the C library) system call that sets the cwd for the current thread only. This should suffice to use mknod safely. Signed-off-by: Keno Fischer --- Changes from v1: New patch. The previous series marked mknodat unsupported. hw/9pfs/9p-local.c | 5 +++-- hw/9pfs/9p-util-darwin.c | 25 +++++++++++++++++++++++++ hw/9pfs/9p-util-linux.c | 5 +++++ hw/9pfs/9p-util.h | 2 ++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 47e8580..c7a2b08 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -668,7 +668,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir= _path, =20 if (fs_ctx->export_flags & V9FS_SM_MAPPED || fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { - err =3D mknodat(dirfd, name, fs_ctx->fmode | S_IFREG, 0); + err =3D qemu_mknodat(dirfd, name, fs_ctx->fmode | S_IFREG, 0); if (err =3D=3D -1) { goto out; } @@ -683,7 +683,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir= _path, } } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH || fs_ctx->export_flags & V9FS_SM_NONE) { - err =3D mknodat(dirfd, name, credp->fc_mode, credp->fc_rdev); + err =3D qemu_mknodat(dirfd, name, credp->fc_mode, credp->fc_rdev); if (err =3D=3D -1) { goto out; } @@ -696,6 +696,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir= _path, =20 err_end: unlinkat_preserve_errno(dirfd, name, 0); + out: close_preserve_errno(dirfd); return err; diff --git a/hw/9pfs/9p-util-darwin.c b/hw/9pfs/9p-util-darwin.c index ac414bc..49fe7d3 100644 --- a/hw/9pfs/9p-util-darwin.c +++ b/hw/9pfs/9p-util-darwin.c @@ -158,3 +158,28 @@ done: close_preserve_errno(fd); return ret; } + +#ifndef SYS___pthread_fchdir +# define SYS___pthread_fchdir 349 +#endif + +static int fchdir_thread_local(int fd) +{ + return syscall(SYS___pthread_fchdir, fd); +} + +int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev) +{ + int preserved_errno, err; + if (fchdir_thread_local(dirfd) < 0) { + return -1; + } + err =3D mknod(filename, mode, dev); + preserved_errno =3D errno; + /* Stop using the thread-local cwd */ + fchdir_thread_local(-1); + if (err < 0) { + errno =3D preserved_errno; + } + return err; +} diff --git a/hw/9pfs/9p-util-linux.c b/hw/9pfs/9p-util-linux.c index 3902378..06399c5 100644 --- a/hw/9pfs/9p-util-linux.c +++ b/hw/9pfs/9p-util-linux.c @@ -63,3 +63,8 @@ int utimensat_nofollow(int dirfd, const char *filename, { return utimensat(dirfd, filename, times, AT_SYMLINK_NOFOLLOW); } + +int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev) +{ + return mknodat(dirfd, filename, mode, dev); +} diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h index b1dc08a..127564d 100644 --- a/hw/9pfs/9p-util.h +++ b/hw/9pfs/9p-util.h @@ -90,4 +90,6 @@ ssize_t fremovexattrat_nofollow(int dirfd, const char *fi= lename, int utimensat_nofollow(int dirfd, const char *filename, const struct timespec times[2]); =20 +int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev); + #endif --=20 2.8.1