From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: qemu-devel@nongnu.org
Cc: Will Cohen <wwcohen@gmail.com>,
Keno Fischer <keno@juliacomputing.com>,
Michael Roitzsch <reactorcontrol@icloud.com>,
hi@alyssa.is, Greg Kurz <groug@kaod.org>
Subject: Re: [PATCH v2 03/11] 9p: darwin: Handle struct stat(fs) differences
Date: Thu, 02 Dec 2021 16:35:30 +0100 [thread overview]
Message-ID: <2009241.jLoMpMqClM@silver> (raw)
In-Reply-To: <CAB26zV1Ges+N1kO1Lcy666OPezphy-17Wj2OaL9aKxaT_xx13w@mail.gmail.com>
On Mittwoch, 1. Dezember 2021 23:46:43 CET Will Cohen wrote:
> On Wed, Nov 24, 2021 at 9:23 AM Christian Schoenebeck <
>
> qemu_oss@crudebyte.com> wrote:
> > On Montag, 22. November 2021 01:49:05 CET Will Cohen wrote:
> > > From: Keno Fischer <keno@juliacomputing.com>
> > >
> > > Signed-off-by: Keno Fischer <keno@juliacomputing.com>
> > > Signed-off-by: Michael Roitzsch <reactorcontrol@icloud.com>
> > > Signed-off-by: Will Cohen <wwcohen@gmail.com>
> > > ---
> > >
> > > hw/9pfs/9p-proxy.c | 17 ++++++++++++++---
> > > hw/9pfs/9p-synth.c | 2 ++
> > > hw/9pfs/9p.c | 16 ++++++++++++++--
> > > 3 files changed, 30 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
> > > index 09bd9f1464..be1546c1be 100644
> > > --- a/hw/9pfs/9p-proxy.c
> > > +++ b/hw/9pfs/9p-proxy.c
> > > @@ -123,10 +123,15 @@ static void prstatfs_to_statfs(struct statfs
> > > *stfs,
> > > ProxyStatFS *prstfs) stfs->f_bavail = prstfs->f_bavail;
> > >
> > > stfs->f_files = prstfs->f_files;
> > > stfs->f_ffree = prstfs->f_ffree;
> > >
> > > +#ifdef CONFIG_DARWIN
> > > + stfs->f_fsid.val[0] = prstfs->f_fsid[0] & 0xFFFFFFFFU;
> > > + stfs->f_fsid.val[1] = prstfs->f_fsid[1] >> 32 & 0xFFFFFFFFU;
> > > +#else
> > >
> > > stfs->f_fsid.__val[0] = prstfs->f_fsid[0] & 0xFFFFFFFFU;
> > > stfs->f_fsid.__val[1] = prstfs->f_fsid[1] >> 32 & 0xFFFFFFFFU;
> > > stfs->f_namelen = prstfs->f_namelen;
> > > stfs->f_frsize = prstfs->f_frsize;
> > >
> > > +#endif
> > >
> > > }
> >
> > Please assign some value to f_namelen. You could either use the BSD
> > version
> > MAXNAMLEN from dirent.h (which you actually use for 9p.c below) or
> > NAME_MAX
> > from sys/syslimits.h on macOS.
>
> statfs on darwin has no f_namelen or f_frsize present (
> https://github.com/apple/darwin-xnu/blob/main/bsd/sys/mount.h#L141), which
> is why they're excluded here. Given that this is converting to darwin's
> statfs structure, is it okay if these stay omitted?
Yes, that's OK for both.
With this patch f_frsize is set to zero, and 'man 2 statfs' on Linux sais:
"Fields that are undefined for a particular filesystem are set to 0."
And the Linux kernel (guest side) seems to automatically use f_bsize in its
absence instead:
https://github.com/torvalds/linux/blob/58e1100fdc5990b0cc0d4beaf2562a92e621ac7d/fs/statfs.c#L67
And for f_namelen I realized there is only one place on 9p server where this
field is used at all, which is v9fs_fill_statfs() in 9p.c and you are already
assigning MAXNAMLEN at that place, so OK.
> > > /* Converts proxy_stat structure to VFS stat structure */
> > >
> > > @@ -143,12 +148,18 @@ static void prstat_to_stat(struct stat *stbuf,
> > > ProxyStat *prstat) stbuf->st_size = prstat->st_size;
> > >
> > > stbuf->st_blksize = prstat->st_blksize;
> > > stbuf->st_blocks = prstat->st_blocks;
> > >
> > > - stbuf->st_atim.tv_sec = prstat->st_atim_sec;
> >
> > Where did that go to? ^-
>
> Unless I'm mistaken, I think this logic should still be present. Pre-patch,
> it's ordered so it runs through sec and nsec each for atime, mtime, and
> ctime respectively. To handle the darwin logic more cleanly, it's now
> broken out so it does _sec first, and then only needs one #ifdef to handle
> the two _nsec cases.
If I understand you correctly, your point is that prstat_to_stat()
(9p-proxy.c) would leave st_[amc]time_sec uninitialized, but eventually
stat_to_v9stat_dotl() (9p.c) would fill them subsequently by:
v9lstat->st_[amc]time_sec = stbuf->st_[amc]time;
Still wouldn't hurt to initialize these fields right from the start IMO. Which
was apparently never done in 9p-proxy.c for all 3 BTW.
> > > - stbuf->st_atim.tv_nsec = prstat->st_atim_nsec;
> > > + stbuf->st_atime = prstat->st_atim_sec;
> > >
> > > stbuf->st_mtime = prstat->st_mtim_sec;
> > >
> > > - stbuf->st_mtim.tv_nsec = prstat->st_mtim_nsec;
> > >
> > > stbuf->st_ctime = prstat->st_ctim_sec;
> > >
> > > +#ifdef CONFIG_DARWIN
> > > + stbuf->st_atimespec.tv_nsec = prstat->st_atim_nsec;
> > > + stbuf->st_mtimespec.tv_nsec = prstat->st_mtim_nsec;
> > > + stbuf->st_ctimespec.tv_nsec = prstat->st_ctim_nsec;
> > > +#else
> > > + stbuf->st_atim.tv_nsec = prstat->st_atim_nsec;
> > > + stbuf->st_mtim.tv_nsec = prstat->st_mtim_nsec;
> > >
> > > stbuf->st_ctim.tv_nsec = prstat->st_ctim_nsec;
> > >
> > > +#endif
> > >
> > > }
> > >
> > > /*
> > >
> > > diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
> > > index b38088e066..4a4a776d06 100644
> > > --- a/hw/9pfs/9p-synth.c
> > > +++ b/hw/9pfs/9p-synth.c
> > > @@ -427,7 +427,9 @@ static int synth_statfs(FsContext *s, V9fsPath
> >
> > *fs_path,
> >
> > > stbuf->f_bsize = 512;
> > >
> > > stbuf->f_blocks = 0;
> > > stbuf->f_files = synth_node_count;
> > >
> > > +#ifndef CONFIG_DARWIN
> > >
> > > stbuf->f_namelen = NAME_MAX;
> > >
> > > +#endif
> > >
> > > return 0;
> > >
> > > }
> >
> > As mentioned above.
> >
> > > diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> > > index 9c63e14b28..f4f0c200c7 100644
> > > --- a/hw/9pfs/9p.c
> > > +++ b/hw/9pfs/9p.c
> > > @@ -1313,11 +1313,17 @@ static int stat_to_v9stat_dotl(V9fsPDU *pdu,
> >
> > const
> >
> > > struct stat *stbuf, v9lstat->st_blksize = stat_to_iounit(pdu, stbuf);
> > >
> > > v9lstat->st_blocks = stbuf->st_blocks;
> > > v9lstat->st_atime_sec = stbuf->st_atime;
> > >
> > > - v9lstat->st_atime_nsec = stbuf->st_atim.tv_nsec;
> > >
> > > v9lstat->st_mtime_sec = stbuf->st_mtime;
> > >
> > > - v9lstat->st_mtime_nsec = stbuf->st_mtim.tv_nsec;
> > >
> > > v9lstat->st_ctime_sec = stbuf->st_ctime;
> > >
> > > +#ifdef CONFIG_DARWIN
> > > + v9lstat->st_atime_nsec = stbuf->st_atimespec.tv_nsec;
> > > + v9lstat->st_mtime_nsec = stbuf->st_mtimespec.tv_nsec;
> > > + v9lstat->st_ctime_nsec = stbuf->st_ctimespec.tv_nsec;
> > > +#else
> > > + v9lstat->st_atime_nsec = stbuf->st_atim.tv_nsec;
> > > + v9lstat->st_mtime_nsec = stbuf->st_mtim.tv_nsec;
> > >
> > > v9lstat->st_ctime_nsec = stbuf->st_ctim.tv_nsec;
> > >
> > > +#endif
> > >
> > > /* Currently we only support BASIC fields in stat */
> > > v9lstat->st_result_mask = P9_STATS_BASIC;
> > >
> > > @@ -3519,9 +3525,15 @@ static int v9fs_fill_statfs(V9fsState *s, V9fsPDU
> > > *pdu, struct statfs *stbuf) f_bavail = stbuf->f_bavail / bsize_factor;
> > >
> > > f_files = stbuf->f_files;
> > > f_ffree = stbuf->f_ffree;
> > >
> > > +#ifdef CONFIG_DARWIN
> > > + fsid_val = (unsigned int)stbuf->f_fsid.val[0] |
> > > + (unsigned long long)stbuf->f_fsid.val[1] << 32;
> > > + f_namelen = MAXNAMLEN;
> > > +#else
> > >
> > > fsid_val = (unsigned int) stbuf->f_fsid.__val[0] |
> > >
> > > (unsigned long long)stbuf->f_fsid.__val[1] << 32;
> > >
> > > f_namelen = stbuf->f_namelen;
> > >
> > > +#endif
> > >
> > > return pdu_marshal(pdu, offset, "ddqqqqqqd",
> > >
> > > f_type, f_bsize, f_blocks, f_bfree,
next prev parent reply other threads:[~2021-12-02 15:38 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-22 0:49 [PATCH v2 00/11] 9p: Add support for darwin Will Cohen
2021-11-22 0:49 ` [PATCH v2 01/11] 9p: linux: Fix a couple Linux assumptions Will Cohen
2021-11-24 12:41 ` Christian Schoenebeck
2021-11-22 0:49 ` [PATCH v2 02/11] 9p: Rename 9p-util -> 9p-util-linux Will Cohen
2021-11-22 0:49 ` [PATCH v2 03/11] 9p: darwin: Handle struct stat(fs) differences Will Cohen
2021-11-24 14:23 ` Christian Schoenebeck
2021-12-01 22:46 ` Will Cohen
2021-12-02 15:35 ` Christian Schoenebeck [this message]
2021-11-22 0:49 ` [PATCH v2 04/11] 9p: darwin: Handle struct dirent differences Will Cohen
2021-11-24 14:58 ` Christian Schoenebeck
2021-11-24 15:45 ` Michael Roitzsch
2021-11-24 19:09 ` Christian Schoenebeck
2022-01-27 21:48 ` Will Cohen
2022-01-28 15:48 ` Christian Schoenebeck
2021-11-22 0:49 ` [PATCH v2 05/11] 9p: darwin: Ignore O_{NOATIME, DIRECT} Will Cohen
2021-11-22 0:49 ` [PATCH v2 06/11] 9p: darwin: Compatibility defn for XATTR_SIZE_MAX Will Cohen
2021-11-24 15:44 ` Christian Schoenebeck
2021-11-22 0:49 ` [PATCH v2 07/11] 9p: darwin: *xattr_nofollow implementations Will Cohen
2021-11-22 0:49 ` [PATCH v2 08/11] 9p: darwin: Compatibility for f/l*xattr Will Cohen
2021-11-24 16:20 ` Christian Schoenebeck
2022-01-27 21:47 ` Will Cohen
2021-11-22 0:49 ` [PATCH v2 09/11] 9p: darwin: Provide fallback impl for utimensat Will Cohen
2021-11-24 17:07 ` Christian Schoenebeck
2021-11-22 0:49 ` [PATCH v2 10/11] 9p: darwin: Implement compatibility for mknodat Will Cohen
2021-11-24 17:20 ` Christian Schoenebeck
2022-01-27 21:47 ` Will Cohen
2022-01-28 15:15 ` Christian Schoenebeck
2022-01-28 18:28 ` Will Cohen
2022-01-31 22:26 ` Will Cohen
2022-02-01 12:44 ` Christian Schoenebeck
2021-11-22 0:49 ` [PATCH v2 11/11] 9p: darwin: meson: Allow VirtFS on Darwin 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=2009241.jLoMpMqClM@silver \
--to=qemu_oss@crudebyte.com \
--cc=groug@kaod.org \
--cc=hi@alyssa.is \
--cc=keno@juliacomputing.com \
--cc=qemu-devel@nongnu.org \
--cc=reactorcontrol@icloud.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.