From nobody Fri May 3 05:52:11 2024 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 15058316852001019.374837790902; Tue, 19 Sep 2017 07:34:45 -0700 (PDT) Received: from localhost ([::1]:43259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duJbo-0003cg-7z for importer@patchew.org; Tue, 19 Sep 2017 10:34:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duJWv-00087g-53 for qemu-devel@nongnu.org; Tue, 19 Sep 2017 10:29:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duJWs-00061U-Db for qemu-devel@nongnu.org; Tue, 19 Sep 2017 10:29:41 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:33303) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1duJWr-000611-TF for qemu-devel@nongnu.org; Tue, 19 Sep 2017 10:29:38 -0400 Received: by mail-wr0-x241.google.com with SMTP id b9so2362483wra.0 for ; Tue, 19 Sep 2017 07:29:37 -0700 (PDT) Received: from eubridge.org (eubridge.org. [78.46.248.70]) by smtp.gmail.com with ESMTPSA id m138sm1692952wmd.29.2017.09.19.07.29.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Sep 2017 07:29:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=85q4EO+UaluhafGZHSlQXwXCZt9szdiactzxWIvybh0=; b=lEnvrl0ZyJBx+cNoMqL1uTuh2SUkpv7pqiOgEmGmdoir3Fvu4onpYKWT78UZvK0Ecv a2uHGmWaK+Sd268Z4Gxau+DGUKM+8LEK5rqExXP+oorUwc1eGQ9LO6+fYFOcqlPdJ25M pH7hs3IGC2ItqpG9OVvwIU8BYkXL7sHKi3TuKzCCSxi8IZvp0snB94pIK0IP/UU4nfso f96OCl7SgLIM/Pq5ZoIwU8n97Yu9ExafcXMgL2uhE6SolKvfT1ttymkSd+7FGCD3gggU mqVNqfHiM0qKq07xzcWtbphqy+DldoR9uMR2BeopyCEJWV4gGxwzz1bAPLRdfFA/Y6Md Rkkw== 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; bh=85q4EO+UaluhafGZHSlQXwXCZt9szdiactzxWIvybh0=; b=Mx7mYWkd5B7z5V76+uGzAupq0AsMuW06UAs6jLIoVH5hhFxpV3x6XUPcvaU6paA77U XzxMyNnhBQKjoCn8xlrPSvoa3iuDJA6tS/AxtFe3OApAu4E0+IMv1tHTDAz7s5HeVCtH ltnwLPgWHPs3VUGt5YjwSMCWn+tR8FN4iyTdbYH63RH+xwwj5EbiiePLWICyzppdNKIR D5Z/fyCmFGVSxl1doaIdnAvaOoU0yooDif0F3bkAPLQ6xF3DcpH2KUybXCcmPUH3g7PR m3Hz+olOKhDqLp/jBIQaSTZkR7iO36+zVvIDvaz1KimnTm3OQ93G6KPCI/ni/FiwLu9e lnzQ== X-Gm-Message-State: AHPjjUjeojMGXDIwiV/laWDywRRjThs9hphMCxUUOXlu9xl7bwZGRr5g GJnTjPTMIg/IlQMRRKdEJ+Y= X-Google-Smtp-Source: AOwi7QCTzLlD75jPanbCwig1y4rzJDfv4w8cNPIkcSPeKC2jjulTYHc2H0SgEWD3w/upXVJ9Rl1ZOg== X-Received: by 10.223.188.70 with SMTP id a6mr1599057wrh.224.1505831376892; Tue, 19 Sep 2017 07:29:36 -0700 (PDT) From: Jan Dakinevich To: Greg Kurz , qemu-devel@nongnu.org Date: Tue, 19 Sep 2017 16:28:58 +0200 Message-Id: <20170919142858.73056-1-jan.dakinevich@gmail.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170919002659.3cd0004a@bahia.lan> References: <20170919002659.3cd0004a@bahia.lan> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PATCH] 9pfs: fix readdir() for 9p2000.u 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: Jan Dakinevich 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" -- >8 -- Greg, Usually, I use 9p as rootfs and run qemu in one of these way. First, using initrd with built-in 9p modules: $ sudo /path/to/qemu-system-x86_64 \ -machine accel=3Dkvm -m 1G -nographic -vga none -serial mon:stdio \ -kernel $PWD/rootfs/boot/vmlinuz-3.16.0-4-amd64 \ -initrd $PWD/rootfs/boot/initrd.img-3.16.0-4-amd64 \ -append "root=3Drootfs rw rootfstype=3D9p rootflags=3Dtrans=3Dvirtio,ve= rsion=3D9p2000.u console=3DttyS0" \ -fsdev local,id=3Dfsdev0,path=3D$PWD/rootfs,security_model=3Dpassthroug= h \ -device virtio-9p-pci,fsdev=3Dfsdev0,mount_tag=3Drootfs Second, with compiled into the kernel 9p support and without initrd (but this way quite tricky): $ sudo /path/to/qemu-system-x86_64 \ -machine accel=3Dkvm -m 1G -nographic -vga none -serial mon:stdio \ -kernel /path/to/bzImage \ -append "root=3D/dev/root rw rootfstype=3D9p rootflags=3Dtrans=3Dvirtio= ,version=3D9p2000.u console=3DttyS0" \ -fsdev local,id=3Dfsdev0,path=3D$PWD/rootfs,security_model=3Dpassthroug= h \ -device virtio-9p-pci,fsdev=3Dfsdev0,mount_tag=3D/dev/root This patch mostly uses your commit message, because it is much more informative than I could ever suggest. -- Best regards Jan Dakinevich -- >8 -- If the client is using 9p2000.u, the following occurs: $ cd ${virtfs_shared_dir} $ mkdir -p a/b/c $ ls a/b ls: cannot access 'a/b/a': No such file or directory ls: cannot access 'a/b/b': No such file or directory a b c instead of the expected: $ ls a/b c This is a regression introduced by commit f57f5878578a; local_name_to_path() now resolves ".." and "." in paths, and v9fs_do_readdir_with_stat()->stat_to_v9stat() then copies the basename of the resulting path to the response. With the example above, this means that "." and ".." are turned into "b" and "a" respectively... Actually, the name we need to pass is the d_name field of the dirent. Meanwhile, name argument of stat_to_v9stat is preserved, since it used to symbolic links resolving. To satisfy stat_to_v9stat(), v9fs_stat() takes a care of the logic from old stat_to_v9stat() for determining basename of the given path. Signed-off-by: Greg Kurz Signed-off-by: Jan Dakinevich --- hw/9pfs/9p.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 4d4ed85..6cb9dfc 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -804,11 +804,11 @@ static uint32_t stat_to_v9mode(const struct stat *stb= uf) } =20 static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V9fsPath *name, + const char *basename, const struct stat *stbuf, V9fsStat *v9stat) { int err; - const char *str; =20 memset(v9stat, 0, sizeof(*v9stat)); =20 @@ -842,14 +842,7 @@ static int coroutine_fn stat_to_v9stat(V9fsPDU *pdu, V= 9fsPath *name, "HARDLINKCOUNT", (unsigned long)stbuf->st_nlink); } =20 - str =3D strrchr(name->data, '/'); - if (str) { - str +=3D 1; - } else { - str =3D name->data; - } - - v9fs_string_sprintf(&v9stat->name, "%s", str); + v9fs_string_sprintf(&v9stat->name, "%s", basename); =20 v9stat->size =3D 61 + v9fs_string_size(&v9stat->name) + @@ -1058,6 +1051,7 @@ static void coroutine_fn v9fs_stat(void *opaque) struct stat stbuf; V9fsFidState *fidp; V9fsPDU *pdu =3D opaque; + char *basename; =20 err =3D pdu_unmarshal(pdu, offset, "d", &fid); if (err < 0) { @@ -1074,7 +1068,9 @@ static void coroutine_fn v9fs_stat(void *opaque) if (err < 0) { goto out; } - err =3D stat_to_v9stat(pdu, &fidp->path, &stbuf, &v9stat); + basename =3D g_path_get_basename(fidp->path.data); + err =3D stat_to_v9stat(pdu, &fidp->path, basename, &stbuf, &v9stat); + g_free(basename); if (err < 0) { goto out; } @@ -1750,7 +1746,7 @@ static int coroutine_fn v9fs_do_readdir_with_stat(V9f= sPDU *pdu, if (err < 0) { break; } - err =3D stat_to_v9stat(pdu, &path, &stbuf, &v9stat); + err =3D stat_to_v9stat(pdu, &path, dent->d_name, &stbuf, &v9stat); if (err < 0) { break; } --=20 2.10.1