All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: qemu-devel@nongnu.org
Cc: Will Cohen <wwcohen@gmail.com>,
	Fabian Franz <fabianfranz.oss@gmail.com>,
	Laurent Vivier <lvivier@redhat.com>,
	Thomas Huth <thuth@redhat.com>, Greg Kurz <groug@kaod.org>,
	Keno Fischer <keno@juliacomputing.com>,
	Michael Roitzsch <reactorcontrol@icloud.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	hi@alyssa.is
Subject: Re: [PATCH v4 04/11] 9p: darwin: Handle struct dirent differences
Date: Mon, 07 Feb 2022 18:05:42 +0100	[thread overview]
Message-ID: <2016355.WMyYeBACgR@silver> (raw)
In-Reply-To: <CAB26zV2dt+n8uF2r21VegNy2q2mudUb0QjArQ0dAoyo8+kXAZA@mail.gmail.com>

On Montag, 7. Februar 2022 14:52:58 CET Will Cohen wrote:
> On Mon, Feb 7, 2022 at 4:53 AM Fabian Franz <fabianfranz.oss@gmail.com>
> 
> wrote:
> > Comments inline:
> > 
> > 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);
> > 
> > Maybe call this „off“?
> 
> Yes, off is better. Will adjust for v5.
> 
> >> +    /* If telldir fails, fail the entire readdir call */
> >> +    if (td < 0) {
> >> +        return NULL;
> >> +    }
> >> +    entry->d_seekoff = td;
> >> +#endif
> >> 
> >>      if (!entry) {
> >>      
> >>          return NULL;
> >>      
> >>      }
> > 
> > This needs to be before the #ifdef!
> 
> Good catch, will adjust for v5. I moved it around twice and forgot to put
> it in the right place.
> 
> >> 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

See below ...

> >> 
> >>  }
> >>  
> >>  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.
> >> + */
> >> +
> >> +inline off_t qemu_dirent_off(struct dirent *dent)
> >> +{
> >> +#ifdef CONFIG_DARWIN
> >> +    return dent->d_seekoff;
> >> +#else
> >> +    return dent->d_off;
> >> +#endif
> >> +}
> > 
> > Are we sure we want a helper for two times the same ifdef? Deferring to
> > maintainers here however.
> 
> Either way works for me too -- my current inclination is to leave it this
> way (as originally suggested by the maintainers), if for no other reason
> than that it allows the one comment to be referenced in the case of both
> uses.

As requested by me in this v4, this will be 3 times in v5. So I assume that 
qualifies the dedicated helper function. :)

As an alternative you could make the helper function a macro instead, then you 
could use it in 9p-synth.c as well, which would make it 4 times. But I don't 
mind about that one.

Best regards,
Christian Schoenebeck

> > 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;
> >> +        }
> > 
> > Do we still need this error-handling? I had removed it in my interdiff
> > patch.
> 
> That's correct, it in fact can be removed. d_seekoff yields a __uint64_t (
> https://developer.apple.com/documentation/kernel/direntry/1415494-d_seekoff?
> language=objc). Will adjust for v5.
> 
> >>      }
> >>      
> >>      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;
> >> +        }
> > 
> > Same here - if this can never fail, why add the error handling?
> 
> See above.
> 
> >>          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
> >> 
> >>      }
> >>      
> >>      /* restore (last) saved position */
> >> 
> >> --
> >> 2.32.0 (Apple Git-132)




  reply	other threads:[~2022-02-07 17:31 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 [this message]
2022-02-07 14:41   ` Christian Schoenebeck
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=2016355.WMyYeBACgR@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.