Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp995670pxb; Fri, 22 Apr 2022 16:16:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwpKwx1o7I97P1Kx7q8fojmPSZXoVuir7rPn+u1ZwdSmcEEZ800pGJ5paOg5Z4UKVgkIS/ X-Received: by 2002:a17:90a:4581:b0:1bc:d215:8722 with SMTP id v1-20020a17090a458100b001bcd2158722mr18677532pjg.149.1650669378904; Fri, 22 Apr 2022 16:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650669378; cv=none; d=google.com; s=arc-20160816; b=Gg9H0ftm0xmWnzUofHaTyRcHDRkhWdnYb0A5o+sH+5JFjw6UqpWObExxR9tX8U3plH NaO7UR5LjIECmdsoOYIi8Np5wD2sCpmUm97iTVkz5USWzLnXOFHfxc2SRKLL4WVgHpOu c4p7xRo61K0VHwkq/rlF/kaXNOR3VDTTHpsKIIU1Rb5nBT430MSYap3YByJ8kRixBqwy o15X1xLsxYiSliPka1eaXz8885HiO5zy787/aqEXFNhJrv5GRd1PqCSjb9a1xDJI8dW8 Sjd827zd813wRTrp0VnK4rKNhbvjgrYYSoqRxHMTY7PYsNSPqcf7vULKQ+3fH6b/M5s1 eRMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=XRgs5dgoBGBDr9oS5MRbFhujpNneuzIzg2K4+SgByuA=; b=YkHwEocec1uoVCVgxmq9+Wucl9xf1puzNhUlsnEgVCMsq3KDfiMW8lpTGKqKzpLTTt xkNWFfBR7X5EWUpfA9nN7MS6OSVeyRl37sieQ5e+PaAK42Umk4LqkMX9bDPDIxXRNEx0 6qLrUqkyz8kUh6X+WCXZ6fvEVST24c08rqx9LoRU4R9mWg8pDJS9GDBaBZEeVW5k/ZaX Jodk1yP3E/3WqjxplSHj8MdsbY34yZJ3oSPliRgwS5W2EJBVDQH0Vx16gdNXOLGRyxpI VCuqKqyuz4EcP4D3MJ9h0pmv0DXZ01itoW+MroZnH/ktZam8qXOWqtaCd0dZ7GltUr2Z BNjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crudebyte.com header.s=kylie header.b=LTDQ4JRH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=crudebyte.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j4-20020a17090276c400b0015afeab2a56si4743862plt.69.2022.04.22.16.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 16:16:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@crudebyte.com header.s=kylie header.b=LTDQ4JRH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=crudebyte.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CC12B1B82A9; Fri, 22 Apr 2022 15:22:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232438AbiDVWZn (ORCPT + 99 others); Fri, 22 Apr 2022 18:25:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232155AbiDVWZ1 (ORCPT ); Fri, 22 Apr 2022 18:25:27 -0400 Received: from kylie.crudebyte.com (kylie.crudebyte.com [5.189.157.229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BA791B8282 for ; Fri, 22 Apr 2022 14:17:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Content-Type:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:References:In-Reply-To: Content-ID:Content-Description; bh=XRgs5dgoBGBDr9oS5MRbFhujpNneuzIzg2K4+SgByuA=; b=LTDQ4JRHSj7PS7jOvG31dv/Q7W ZB5cT+8p9nbf0eUz5yz+8PNMcOu8i0/sHYrLMr3C/t55uXOeknvcQDdlGTXTeMpLgihR40eBAQrJl P8l8Yv+c2+K3v1qKaaDgvgjT/zsxA/Gt8AP0vETbSgpH+/Oypsirx7HCyP9w9S5r9Ny+XmwPHYsPh OD0V3dy2DL0UwsPda7DPkigL/etquLdpVrlB4a09h5JMZbQruEXzTWncpVrqar8Pu+2lSR9If/7vj 6Sfamqo8kSVgsRbeLyTkBYnX6ubInNVSO4lRPybZO0yubOK1HC2gLVQOlrVaDga2fNKMRVP8a1TwZ a5O+Mt7SbmZCZ5whMbAq6J/sbt3uRetJNum0op4p4Znw31xcjBGhLnzh6SjDFFt3BbvYihp6cKqn7 dkTGuC1GoUabk3W6/3J1KoJHonNV04yf5QB93sTVhwRrcZxIdWrKbEz6Z4ct2yZuBSshH8WGtUbiz nHkhgpU2Sp4VB5Nd4X/4W4aZjSWomDcCPXUPtxBntMzd5yZ2VuUorQlLZkeLD+smipJlYjfUoGSJz jOZzjLoKQXDyvGhRGNtsJdM0GXy9JXuSlLg+kwYpj7/s3+tMQV1MB6hBmAYF+UHfpIB3b4kVxThdl Ha2e37FPpqkbh9tzHmQsXrvnrM6fckHGNMhBwlTnM=; From: Christian Schoenebeck To: qemu-devel@nongnu.org Cc: Will Cohen , Greg Kurz , Michael Roitzsch , Keno Fischer , Dominique Martinet , Eric Van Hensbergen , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, v9fs-developer@lists.sourceforge.net, Latchesar Ionkov Subject: [RFC PATCH] 9p: case-insensitive host filesystems Date: Fri, 22 Apr 2022 20:02:46 +0200 Message-ID: <1757498.AyhHxzoH2B@silver> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,DATE_IN_PAST_03_06, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that 9p support for macOS hosts just landed in QEMU 7.0 and with support for Windows hosts on the horizon [1], the question is how to deal with case- insensitive host filesystems, which are very common on those two systems? I made some tests, e.g. trying to setup a 9p root fs Linux installation on a macOS host as described in the QEMU HOWTO [2], which at a certain point causes the debootstrap script to fail when trying to unpack the 'libpam-runtime' package. That's because it would try to create this symlink: /usr/share/man/man7/PAM.7.gz -> /usr/share/man/man7/pam.7.gz which fails with EEXIST on a case-insensitive APFS. Unfortunately you can't easily switch an existing APFS partition to case-sensitivity. It requires to reformat the entire partition, loosing all your data, etc. So I did a quick test with QEMU as outlined below, trying to simply let 9p server "eat" EEXIST errors in such cases, but then I realized that most of the time it would not even come that far, as Linux client would first send a 'Twalk' request to check whether target symlink entry already exists, and as it gets a positive response from 9p server (again, due to case-insensitivity) client would stop right there without even trying to send a 'Tsymlink' request. So maybe it's better to handle case-insensitivity entirely on client side? I've read that some generic "case fold" code has landed in the Linux kernel recently that might do the trick? Should 9p server give a hint to 9p client that it's a case-insensitive fs? And if yes, once per entire exported fs or rather for each directory (as there might be submounts on host)? [1] https://lore.kernel.org/all/20220408171013.912436-1-bmeng.cn@gmail.com/ [2] https://wiki.qemu.org/Documentation/9p_root_fs --- hw/9pfs/9p-local.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index d42ce6d8b8..d6cb45c758 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -39,6 +39,10 @@ #endif #endif #include +#ifdef CONFIG_DARWIN +#include +#include +#endif #ifndef XFS_SUPER_MAGIC #define XFS_SUPER_MAGIC 0x58465342 @@ -57,6 +61,18 @@ typedef struct { int mountfd; } LocalData; +#ifdef CONFIG_DARWIN + +/* Compare strings case-insensitive (assuming UTF-8 encoding). */ +static int p9_stricmp(const char *a, const char *b) +{ + g_autofree gchar *cia = g_utf8_casefold(a, -1); + g_autofree gchar *cib = g_utf8_casefold(b, -1); + return g_utf8_collate(cia, cib); +} + +#endif + int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags, mode_t mode) { @@ -931,6 +947,25 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath, fs_ctx->export_flags & V9FS_SM_NONE) { err = symlinkat(oldpath, dirfd, name); if (err) { +#if CONFIG_DARWIN + if (errno == EEXIST) { + printf(" -> symlinkat(oldpath='%s', dirfd=%d, name='%s') = EEXIST\n", oldpath, dirfd, name); + } + if (errno == EEXIST && + strcmp(oldpath, name) && !p9_stricmp(oldpath, name)) + { + struct stat st1, st2; + const int cur_errno = errno; + if (!fstatat(dirfd, oldpath, &st1, AT_SYMLINK_NOFOLLOW) && + !fstatat(dirfd, name, &st2, AT_SYMLINK_NOFOLLOW) && + st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) + { + printf(" -> iCASE SAME\n"); + err = 0; + } + errno = cur_errno; + } +#endif goto out; } err = fchownat(dirfd, name, credp->fc_uid, credp->fc_gid, @@ -983,6 +1018,25 @@ static int local_link(FsContext *ctx, V9fsPath *oldpath, ret = linkat(odirfd, oname, ndirfd, name, 0); if (ret < 0) { +#if CONFIG_DARWIN + if (errno == EEXIST) { + printf(" -> linkat(odirfd=%d, oname='%s', ndirfd=%d, name='%s') = EEXIST\n", odirfd, oname, ndirfd, name); + } + if (errno == EEXIST && + strcmp(oname, name) && !p9_stricmp(oname, name)) + { + struct stat st1, st2; + const int cur_errno = errno; + if (!fstatat(odirfd, oname, &st1, AT_SYMLINK_NOFOLLOW) && + !fstatat(ndirfd, name, &st2, AT_SYMLINK_NOFOLLOW) && + st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino) + { + printf(" -> iCASE SAME\n"); + ret = 0; + } + errno = cur_errno; + } +#endif goto out_close; } -- 2.32.0 (Apple Git-132)