From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: Will Cohen <wwcohen@gmail.com>
Cc: qemu-devel@nongnu.org, Laurent Vivier <lvivier@redhat.com>,
hi@alyssa.is, Thomas Huth <thuth@redhat.com>,
Greg Kurz <groug@kaod.org>, Paolo Bonzini <pbonzini@redhat.com>,
Keno Fischer <keno@juliacomputing.com>,
Michael Roitzsch <reactorcontrol@icloud.com>,
Fabian Franz <fabianfranz.oss@gmail.com>
Subject: Re: [PATCH v4 04/11] 9p: darwin: Handle struct dirent differences
Date: Mon, 07 Feb 2022 15:41:12 +0100 [thread overview]
Message-ID: <1773154.tHhT6ugY5c@silver> (raw)
In-Reply-To: <20220206200719.74464-5-wwcohen@gmail.com>
On Sonntag, 6. Februar 2022 21:07:12 CET Will Cohen wrote:
> From: Keno Fischer <keno@juliacomputing.com>
>
> On darwin d_seekoff exists, but is optional and does not seem to
> be commonly used by file systems. Use `telldir` instead to obtain
> the seek offset and inject it into d_seekoff, and create a
> qemu_dirent_off helper to call it appropriately when appropriate.
>
> Signed-off-by: Keno Fischer <keno@juliacomputing.com>
> [Michael Roitzsch: - Rebase for NixOS]
> Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
> [Will Cohen: - Adjust to pass testing
> - Ensure that d_seekoff is filled using telldir
> on darwin, and create qemu_dirent_off helper
> to decide which to access]
> [Fabian Franz: - Add telldir error handling for darwin]
> [Will Cohen: - Ensure that telldir error handling uses
> signed int]
> Signed-off-by: Fabian Franz <fabianfranz.oss@gmail.com>
> Signed-off-by: Will Cohen <wwcohen@gmail.com>
> ---
> hw/9pfs/9p-local.c | 9 +++++++++
> hw/9pfs/9p-proxy.c | 16 +++++++++++++++-
> hw/9pfs/9p-synth.c | 4 ++++
> hw/9pfs/9p-util.h | 17 +++++++++++++++++
> hw/9pfs/9p.c | 15 +++++++++++++--
> hw/9pfs/codir.c | 7 +++++++
> 6 files changed, 65 insertions(+), 3 deletions(-)
>
> diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
> index 1a5e3eed73..7137a28109 100644
> --- a/hw/9pfs/9p-local.c
> +++ b/hw/9pfs/9p-local.c
> @@ -559,6 +559,15 @@ static struct dirent *local_readdir(FsContext *ctx,
> V9fsFidOpenState *fs)
>
> again:
> entry = readdir(fs->dir.stream);
> +#ifdef CONFIG_DARWIN
> + int td;
> + td = telldir(fs->dir.stream);
> + /* If telldir fails, fail the entire readdir call */
> + if (td < 0) {
> + return NULL;
> + }
> + entry->d_seekoff = td;
> +#endif
> if (!entry) {
> return NULL;
> }
'entry' may be NULL, so the 'if (!entry) {' check should be before the Darwin
specific code to avoid a crash on macOS.
> diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
> index b1664080d8..8b4b5cf7dc 100644
> --- a/hw/9pfs/9p-proxy.c
> +++ b/hw/9pfs/9p-proxy.c
> @@ -706,7 +706,21 @@ static off_t proxy_telldir(FsContext *ctx,
> V9fsFidOpenState *fs)
>
> static struct dirent *proxy_readdir(FsContext *ctx, V9fsFidOpenState *fs)
> {
> - return readdir(fs->dir.stream);
> + struct dirent *entry;
> + entry = readdir(fs->dir.stream);
> +#ifdef CONFIG_DARWIN
> + if (!entry) {
> + return NULL;
> + }
> + int td;
> + td = telldir(fs->dir.stream);
> + /* If telldir fails, fail the entire readdir call */
> + if (td < 0) {
> + return NULL;
> + }
> + entry->d_seekoff = td;
> +#endif
> + return entry;
> }
>
> static void proxy_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off)
> diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
> index 4a4a776d06..e264a03eef 100644
> --- a/hw/9pfs/9p-synth.c
> +++ b/hw/9pfs/9p-synth.c
> @@ -222,7 +222,11 @@ static void synth_direntry(V9fsSynthNode *node,
> {
> strcpy(entry->d_name, node->name);
> entry->d_ino = node->attr->inode;
> +#ifdef CONFIG_DARWIN
> + entry->d_seekoff = off + 1;
> +#else
> entry->d_off = off + 1;
> +#endif
> }
>
> static struct dirent *synth_get_dentry(V9fsSynthNode *dir,
> diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
> index 546f46dc7d..accbec9987 100644
> --- a/hw/9pfs/9p-util.h
> +++ b/hw/9pfs/9p-util.h
> @@ -79,3 +79,20 @@ ssize_t fremovexattrat_nofollow(int dirfd, const char
> *filename, const char *name);
>
> #endif
> +
> +
> +/**
> + * Darwin has d_seekoff, which appears to function similarly to d_off.
> + * However, it does not appear to be supported on all file systems,
> + * so ensure it is manually injected earlier and call here when
> + * needed.
> + */
> +
Nitpicking: no blank line here please.
> +inline off_t qemu_dirent_off(struct dirent *dent)
> +{
> +#ifdef CONFIG_DARWIN
> + return dent->d_seekoff;
> +#else
> + return dent->d_off;
> +#endif
> +}
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 1563d7b7c6..cf694da354 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -27,6 +27,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"
> @@ -2281,7 +2282,11 @@ static int coroutine_fn
> v9fs_do_readdir_with_stat(V9fsPDU *pdu, count += len;
> v9fs_stat_free(&v9stat);
> v9fs_path_free(&path);
> - saved_dir_pos = dent->d_off;
> + saved_dir_pos = qemu_dirent_off(dent);
> + if (saved_dir_pos < 0) {
> + err = saved_dir_pos;
> + break;
> + }
> }
That check is no longer needed here, is it?
>
> v9fs_readdir_unlock(&fidp->fs.dir);
> @@ -2420,6 +2425,7 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu,
> V9fsFidState *fidp, V9fsString name;
> int len, err = 0;
> int32_t count = 0;
> + off_t off;
> struct dirent *dent;
> struct stat *st;
> struct V9fsDirEnt *entries = NULL;
> @@ -2480,12 +2486,17 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU
> *pdu, V9fsFidState *fidp, qid.version = 0;
> }
>
> + off = qemu_dirent_off(dent);
> + if (off < 0) {
> + err = off;
> + break;
> + }
Likewise: is this check still needed?
> v9fs_string_init(&name);
> v9fs_string_sprintf(&name, "%s", dent->d_name);
>
> /* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */
> len = pdu_marshal(pdu, 11 + count, "Qqbs",
> - &qid, dent->d_off,
> + &qid, off,
> dent->d_type, &name);
>
> v9fs_string_free(&name);
> diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
> index 032cce04c4..fac6759a64 100644
> --- a/hw/9pfs/codir.c
> +++ b/hw/9pfs/codir.c
> @@ -167,7 +167,14 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState
> *fidp, }
>
> size += len;
> + /* This conditional statement is identical in
> + * function to qemu_dirent_off, described in 9p-util.h,
> + * since that header cannot be included here. */
> +#ifdef CONFIG_DARWIN
> + saved_dir_pos = dent->d_seekoff;
> +#else
> saved_dir_pos = dent->d_off;
> +#endif
Why can't the header not be included here? Obvious preference would be to use
qemu_dirent_off() here as well, to have control at one central code location.
> }
>
> /* restore (last) saved position */
next prev parent reply other threads:[~2022-02-07 15:18 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-06 20:07 [PATCH v4 00/11] 9p: Add support for darwin Will Cohen
2022-02-06 20:07 ` [PATCH v4 01/11] 9p: linux: Fix a couple Linux assumptions Will Cohen
2022-02-06 21:15 ` Philippe Mathieu-Daudé via
2022-02-07 8:03 ` Greg Kurz
2022-02-06 20:07 ` [PATCH v4 02/11] 9p: Rename 9p-util -> 9p-util-linux Will Cohen
2022-02-06 21:16 ` Philippe Mathieu-Daudé via
2022-02-06 20:07 ` [PATCH v4 03/11] 9p: darwin: Handle struct stat(fs) differences Will Cohen
2022-02-06 20:07 ` [PATCH v4 04/11] 9p: darwin: Handle struct dirent differences Will Cohen
2022-02-07 9:53 ` Fabian Franz
2022-02-07 13:52 ` Will Cohen
2022-02-07 17:05 ` Christian Schoenebeck
2022-02-07 14:41 ` Christian Schoenebeck [this message]
2022-02-07 16:41 ` Will Cohen
2022-02-06 20:07 ` [PATCH v4 05/11] 9p: darwin: Ignore O_{NOATIME, DIRECT} Will Cohen
2022-02-06 20:07 ` [PATCH v4 06/11] 9p: darwin: Move XATTR_SIZE_MAX->P9_XATTR_SIZE_MAX Will Cohen
2022-02-06 20:07 ` [PATCH v4 07/11] 9p: darwin: *xattr_nofollow implementations Will Cohen
2022-02-06 20:07 ` [PATCH v4 08/11] 9p: darwin: Compatibility for f/l*xattr Will Cohen
2022-02-06 20:07 ` [PATCH v4 09/11] 9p: darwin: Implement compatibility for mknodat Will Cohen
2022-02-06 21:20 ` Philippe Mathieu-Daudé via
2022-02-07 1:10 ` Will Cohen
2022-02-07 8:47 ` Greg Kurz
2022-02-07 10:30 ` Philippe Mathieu-Daudé via
2022-02-07 10:49 ` Greg Kurz
2022-02-07 10:57 ` Dr. David Alan Gilbert
2022-02-07 14:21 ` Christian Schoenebeck
2022-02-07 21:07 ` Will Cohen
2022-02-07 22:37 ` Will Cohen
2022-02-07 22:47 ` Christian Schoenebeck
2022-02-07 22:55 ` Will Cohen
2022-02-07 15:52 ` Vivek Goyal
2022-02-06 20:07 ` [PATCH v4 10/11] 9p: darwin: meson: Allow VirtFS on Darwin Will Cohen
2022-02-06 21:22 ` Philippe Mathieu-Daudé via
2022-02-07 1:05 ` Will Cohen
2022-02-07 14:15 ` Christian Schoenebeck
2022-02-07 14:18 ` Will Cohen
2022-02-07 14:39 ` Greg Kurz
2022-02-07 16:04 ` Christian Schoenebeck
2022-02-07 14:27 ` Christian Schoenebeck
2022-02-07 14:37 ` Will Cohen
2022-02-07 15:38 ` Christian Schoenebeck
2022-02-06 20:07 ` [PATCH v4 11/11] 9p: darwin: Adjust assumption on virtio-9p-test Will Cohen
2022-02-07 6:15 ` Thomas Huth
2022-02-07 14:47 ` [PATCH v4 00/11] 9p: Add support for darwin Christian Schoenebeck
2022-02-07 14:56 ` Will Cohen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1773154.tHhT6ugY5c@silver \
--to=qemu_oss@crudebyte.com \
--cc=fabianfranz.oss@gmail.com \
--cc=groug@kaod.org \
--cc=hi@alyssa.is \
--cc=keno@juliacomputing.com \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=reactorcontrol@icloud.com \
--cc=thuth@redhat.com \
--cc=wwcohen@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.