From nobody Mon Feb 9 07:56:06 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 1529197580204552.9824344165168; Sat, 16 Jun 2018 18:06:20 -0700 (PDT) Received: from localhost ([::1]:53397 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUM95-0003aZ-9s for importer@patchew.org; Sat, 16 Jun 2018 21:06:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fUM0X-0005jC-Ah for qemu-devel@nongnu.org; Sat, 16 Jun 2018 20:57:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fUM0V-0003HM-WE for qemu-devel@nongnu.org; Sat, 16 Jun 2018 20:57:29 -0400 Received: from mail-qk0-x243.google.com ([2607:f8b0:400d:c09::243]:42650) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fUM0V-0003HI-QX for qemu-devel@nongnu.org; Sat, 16 Jun 2018 20:57:27 -0400 Received: by mail-qk0-x243.google.com with SMTP id j80-v6so7659765qke.9 for ; Sat, 16 Jun 2018 17:57:27 -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 x21-v6sm7302186qto.2.2018.06.16.17.57.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 16 Jun 2018 17:57:26 -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=klfVx99XCNxcT9mF+bCFviXrRMY0EIBLNUH3/i3hZ3c=; b=pfPouAibfqXbRImdax45295e/sGMv/wgoRa78i8XW5fWFeHW/PLtbW06gC5V0h9zRp p7rzYb8yCIu6poJn6bpr6S/icvV/jv/2QCwhYPbdLgfijf7X4d8+icBFRfneiTpqIhRZ yxnaK0RzplUkjI6S4PUPLQwTZDobN6cLNsnVWWKex19eJYyFwUQjV74/1nS0k6P8O4ps L2tSSEHpDqVMF114cjjPgEkWwjEGm4wlI9AlKEBDB1YUspOZdo7RtDzyOr38T40/5Qg1 uAL3KYV8i/xc/exxL6QEBZ1g8HJbcjgBzV06dmxkFNXwWciBDIFLxQsI8Bby8Q7ACMW7 sUyg== 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=klfVx99XCNxcT9mF+bCFviXrRMY0EIBLNUH3/i3hZ3c=; b=cncLl7d12QHEu4xx6ATZPUSSNCcb8BdSk94UbdHo4VpGRFmDxf3KY0lgzJi1zVb6bt MGtJHe9SCaPsiq1dhBPmUlIfA2uZM1LoSgLjBAh01GocsO3i8iIRMLtX7A7Gz43tSgYe HQ6vfG7yRLRxm7tKPpnD9ip6/mqQwnq8o0084UFQthQzFpTbTU4Gqa4tsXX7yvpVkxBq CyonVOQmRq6O/mDntLDA2ms1EzK30aWno27vpaJSxMCbNUbQzUAupo/YqAkp+R6yMa59 aJm20y6CxYUJkMuOQTXA7ERMaeeUw/271iyOgoo+xyh2cXgmCwGlIVgaRU+7QzKBz7dT WCsw== X-Gm-Message-State: APt69E3OITV5uLBaXy7GVsMqrVNBrHVCoVx19xqBdpZey5hohdARFyXu fLUamD1AKbeKYTzIBjB5SAYyn+DRGLM= X-Google-Smtp-Source: ADUXVKIlxtQ5QUZZmWOc3TXBAroDsP8tR/TOT67ZHDxsAGgc/O3d6kdPp9D/xnIJY4Rz2yAk6317/A== X-Received: by 2002:a37:b401:: with SMTP id d1-v6mr6150264qkf.332.1529197047002; Sat, 16 Jun 2018 17:57:27 -0700 (PDT) From: Keno Fischer To: qemu-devel@nongnu.org Date: Sat, 16 Jun 2018 20:56:54 -0400 Message-Id: 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:c09::243 Subject: [Qemu-devel] [PATCH v3 10/13] 9p: darwin: Provide a fallback implementation for utimensat 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" This function is new in Mac OS 10.13. Provide a fallback implementation when building against older SDKs. The complication in the definition comes having to separately handle the used SDK version and the target OS version. - If the SDK version is too low (__MAC_10_13 not defined), utimensat is not defined in the header, so we must not try to use it (doing so would error= ). - Otherwise, if the targetted OS version is at least 10.13, we know this function is available, so we can unconditionally call it. - Lastly, we check for the availability of the __builtin_available macro to potentially insert a dynamic check for this OS version. However, __builti= n_available is only available with sufficiently recent versions of clang and while all Apple clang versions that ship with Xcode versions that support the 10.13 SDK support with builtin, we want to allow building with compilers other than Apple clang that may not support this builtin. Signed-off-by: Keno Fischer --- fsdev/virtfs-proxy-helper.c | 3 +- hw/9pfs/9p-local.c | 2 +- hw/9pfs/9p-util-darwin.c | 96 +++++++++++++++++++++++++++++++++++++++++= ++++ hw/9pfs/9p-util-linux.c | 6 +++ hw/9pfs/9p-util.h | 8 ++++ hw/9pfs/9p.c | 1 + 6 files changed, 113 insertions(+), 3 deletions(-) diff --git a/fsdev/virtfs-proxy-helper.c b/fsdev/virtfs-proxy-helper.c index a26f8b8..d8dd3f5 100644 --- a/fsdev/virtfs-proxy-helper.c +++ b/fsdev/virtfs-proxy-helper.c @@ -957,8 +957,7 @@ static int process_requests(int sock) &spec[0].tv_sec, &spec[0].tv_nsec, &spec[1].tv_sec, &spec[1].tv_nsec); if (retval > 0) { - retval =3D utimensat(AT_FDCWD, path.data, spec, - AT_SYMLINK_NOFOLLOW); + retval =3D utimensat_nofollow(AT_FDCWD, path.data, spec); if (retval < 0) { retval =3D -errno; } diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 768ef6f..56bcabf 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -1071,7 +1071,7 @@ static int local_utimensat(FsContext *s, V9fsPath *fs= _path, goto out; } =20 - ret =3D utimensat(dirfd, name, buf, AT_SYMLINK_NOFOLLOW); + ret =3D utimensat_nofollow(dirfd, name, buf); close_preserve_errno(dirfd); out: g_free(dirpath); diff --git a/hw/9pfs/9p-util-darwin.c b/hw/9pfs/9p-util-darwin.c index cdb4c9e..ac414bc 100644 --- a/hw/9pfs/9p-util-darwin.c +++ b/hw/9pfs/9p-util-darwin.c @@ -62,3 +62,99 @@ int fsetxattrat_nofollow(int dirfd, const char *filename= , const char *name, close_preserve_errno(fd); return ret; } + +#ifndef __has_builtin +#define __has_builtin(x) 0 +#endif + +static int update_times_from_stat(int fd, struct timespec times[2], + int update0, int update1) +{ + struct stat buf; + int ret =3D fstat(fd, &buf); + if (ret =3D=3D -1) { + return ret; + } + if (update0) { + times[0] =3D buf.st_atimespec; + } + if (update1) { + times[1] =3D buf.st_mtimespec; + } + return 0; +} + +int utimensat_nofollow(int dirfd, const char *filename, + const struct timespec times_in[2]) +{ + int ret, fd; + int special0, special1; + struct timeval futimes_buf[2]; + struct timespec times[2]; + memcpy(times, times_in, 2 * sizeof(struct timespec)); + +/* Check whether we have an SDK version that defines utimensat */ +#if defined(__MAC_10_13) +# if __MAC_OS_X_VERSION_MIN_REQUIRED >=3D __MAC_10_13 +# define UTIMENSAT_AVAILABLE 1 +# elif __has_builtin(__builtin_available) +# define UTIMENSAT_AVAILABLE __builtin_available(macos 10.13, *) +# else +# define UTIMENSAT_AVAILABLE 0 +# endif + if (UTIMENSAT_AVAILABLE) { + return utimensat(dirfd, filename, times, AT_SYMLINK_NOFOLLOW); + } +#endif + + /* utimensat not available. Use futimes. */ + fd =3D openat_file(dirfd, filename, O_PATH_9P_UTIL | O_NOFOLLOW, 0); + if (fd =3D=3D -1) { + return -1; + } + + special0 =3D times[0].tv_nsec =3D=3D UTIME_OMIT; + special1 =3D times[1].tv_nsec =3D=3D UTIME_OMIT; + if (special0 || special1) { + /* If both are set, nothing to do */ + if (special0 && special1) { + ret =3D 0; + goto done; + } + + ret =3D update_times_from_stat(fd, times, special0, special1); + if (ret < 0) { + goto done; + } + } + + special0 =3D times[0].tv_nsec =3D=3D UTIME_NOW; + special1 =3D times[1].tv_nsec =3D=3D UTIME_NOW; + if (special0 || special1) { + ret =3D futimes(fd, NULL); + if (ret < 0) { + goto done; + } + + /* If both are set, we are done */ + if (special0 && special1) { + ret =3D 0; + goto done; + } + + ret =3D update_times_from_stat(fd, times, special0, special1); + if (ret < 0) { + goto done; + } + } + + futimes_buf[0].tv_sec =3D times[0].tv_sec; + futimes_buf[0].tv_usec =3D times[0].tv_nsec / 1000; + futimes_buf[1].tv_sec =3D times[1].tv_sec; + futimes_buf[1].tv_usec =3D times[1].tv_nsec / 1000; + ret =3D futimes(fd, futimes_buf); + +done: + close_preserve_errno(fd); + return ret; +} diff --git a/hw/9pfs/9p-util-linux.c b/hw/9pfs/9p-util-linux.c index defa3a4..3902378 100644 --- a/hw/9pfs/9p-util-linux.c +++ b/hw/9pfs/9p-util-linux.c @@ -57,3 +57,9 @@ int fsetxattrat_nofollow(int dirfd, const char *filename,= const char *name, g_free(proc_path); return ret; } + +int utimensat_nofollow(int dirfd, const char *filename, + const struct timespec times[2]) +{ + return utimensat(dirfd, filename, times, AT_SYMLINK_NOFOLLOW); +} diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h index 50a03c7..b1dc08a 100644 --- a/hw/9pfs/9p-util.h +++ b/hw/9pfs/9p-util.h @@ -36,6 +36,12 @@ static inline int qemu_lsetxattr(const char *path, const= char *name, #define qemu_lsetxattr lsetxattr #endif =20 +/* Compatibility with old SDK Versions for Darwin */ +#if defined(CONFIG_DARWIN) && !defined(UTIME_NOW) +#define UTIME_NOW -1 +#define UTIME_OMIT -2 +#endif + static inline void close_preserve_errno(int fd) { int serrno =3D errno; @@ -81,5 +87,7 @@ ssize_t flistxattrat_nofollow(int dirfd, const char *file= name, char *list, size_t size); ssize_t fremovexattrat_nofollow(int dirfd, const char *filename, const char *name); +int utimensat_nofollow(int dirfd, const char *filename, + const struct timespec times[2]); =20 #endif diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index abfb8dc..dc53691 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -21,6 +21,7 @@ #include "virtio-9p.h" #include "fsdev/qemu-fsdev.h" #include "9p-xattr.h" +#include "9p-util.h" #include "coth.h" #include "trace.h" #include "migration/blocker.h" --=20 2.8.1