Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Dec 2023 11:29:50 +0800
From:      Zhenlei Huang <zlei@FreeBSD.org>
To:        Konstantin Belousov <kib@FreeBSD.org>
Cc:        "src-committers@freebsd.org" <src-committers@FreeBSD.org>, "dev-commits-src-all@freebsd.org" <dev-commits-src-all@FreeBSD.org>, "dev-commits-src-main@freebsd.org" <dev-commits-src-main@FreeBSD.org>
Subject:   Re: git: 2a1d50fc12f6 - main - vfs_domount_update(): correct fsidcmp() usage
Message-ID:  <72190C27-0D45-4300-BB78-719F5EB510E9@FreeBSD.org>
In-Reply-To: <202312260136.3BQ1aOxq051977@gitrepo.freebsd.org>
References:  <202312260136.3BQ1aOxq051977@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]


> On Dec 26, 2023, at 9:36 AM, Konstantin Belousov <kib@FreeBSD.org> wrote:
> 
> The branch main has been updated by kib:
> 
> URL: https://cgit.FreeBSD.org/src/commit/?id=2a1d50fc12f6e604da834fbaea961d412aae6e85
> 
> commit 2a1d50fc12f6e604da834fbaea961d412aae6e85
> Author:     Andrew Gierth <andrew@tao146.riddles.org.uk>
> AuthorDate: 2023-12-24 12:04:21 +0000
> Commit:     Konstantin Belousov <kib@FreeBSD.org>
> CommitDate: 2023-12-26 01:35:46 +0000
> 
>    vfs_domount_update(): correct fsidcmp() usage
> 
>    MFC after:      3 days
> ---
> sys/kern/vfs_mount.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c
> index 8e54c832e9f1..331e4887c200 100644
> --- a/sys/kern/vfs_mount.c
> +++ b/sys/kern/vfs_mount.c
> @@ -1388,7 +1388,7 @@ vfs_domount_update(
> 			error = EINVAL;
> 			goto end;
> 		}
> -		if (fsidcmp(&fsid_up, &mp->mnt_stat.f_fsid) != 0) {
> +		if (fsidcmp(fsid_up, &mp->mnt_stat.f_fsid) != 0) {
> 			error = ENOENT;
> 			goto end;
> 		}



I guess we want to ensure ` typeof(a) == typeof(b) == fsid_t `, to prevent such kind of error in future.

I see both gcc [1] and clang [2] have __builtin_types_compatible_p , so probably a good definition of fsidcmp should be

```
#define TYPEASSERT(v, t) \
	_Static_assert(__builtin_types_compatible_p(typeof(v), t), "Requires type '" #t "'")

#define fsidcmp(a, b) ({ \
	TYPEASSERT((a), fsid_t *); \
	TYPEASSERT((b), fsid_t *); \
	memcmp((a), (b), sizeof(fsid_t)); \
})
```

1. https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
2. https://clang.llvm.org/docs/LanguageExtensions.html

Best regards,
Zhenlei


[-- Attachment #2 --]
<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Dec 26, 2023, at 9:36 AM, Konstantin Belousov &lt;<a href="mailto:kib@FreeBSD.org" class="">kib@FreeBSD.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">The branch main has been updated by kib:<br class=""><br class="">URL: <a href="https://cgit.FreeBSD.org/src/commit/?id=2a1d50fc12f6e604da834fbaea961d412aae6e85" class="">https://cgit.FreeBSD.org/src/commit/?id=2a1d50fc12f6e604da834fbaea961d412aae6e85</a><br class=""><br class="">commit 2a1d50fc12f6e604da834fbaea961d412aae6e85<br class="">Author: &nbsp;&nbsp;&nbsp;&nbsp;Andrew Gierth &lt;<a href="mailto:andrew@tao146.riddles.org.uk" class="">andrew@tao146.riddles.org.uk</a>&gt;<br class="">AuthorDate: 2023-12-24 12:04:21 +0000<br class="">Commit: &nbsp;&nbsp;&nbsp;&nbsp;Konstantin Belousov &lt;<a href="mailto:kib@FreeBSD.org" class="">kib@FreeBSD.org</a>&gt;<br class="">CommitDate: 2023-12-26 01:35:46 +0000<br class=""><br class=""> &nbsp;&nbsp;&nbsp;vfs_domount_update(): correct fsidcmp() usage<br class=""><br class=""> &nbsp;&nbsp;&nbsp;MFC after: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3 days<br class="">---<br class=""> sys/kern/vfs_mount.c | 2 +-<br class=""> 1 file changed, 1 insertion(+), 1 deletion(-)<br class=""><br class="">diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c<br class="">index 8e54c832e9f1..331e4887c200 100644<br class="">--- a/sys/kern/vfs_mount.c<br class="">+++ b/sys/kern/vfs_mount.c<br class="">@@ -1388,7 +1388,7 @@ vfs_domount_update(<br class=""> <span class="Apple-tab-span" style="white-space:pre">	</span><span class="Apple-tab-span" style="white-space:pre">	</span><span class="Apple-tab-span" style="white-space:pre">	</span>error = EINVAL;<br class=""> <span class="Apple-tab-span" style="white-space:pre">	</span><span class="Apple-tab-span" style="white-space:pre">	</span><span class="Apple-tab-span" style="white-space:pre">	</span>goto end;<br class=""> <span class="Apple-tab-span" style="white-space:pre">	</span><span class="Apple-tab-span" style="white-space:pre">	</span>}<br class="">-<span class="Apple-tab-span" style="white-space:pre">	</span><span class="Apple-tab-span" style="white-space:pre">	</span>if (fsidcmp(&amp;fsid_up, &amp;mp-&gt;mnt_stat.f_fsid) != 0) {<br class="">+<span class="Apple-tab-span" style="white-space:pre">	</span><span class="Apple-tab-span" style="white-space:pre">	</span>if (fsidcmp(fsid_up, &amp;mp-&gt;mnt_stat.f_fsid) != 0) {</div></div></blockquote><blockquote type="cite" class=""><div class=""><div class=""> <span class="Apple-tab-span" style="white-space:pre">	</span><span class="Apple-tab-span" style="white-space:pre">	</span><span class="Apple-tab-span" style="white-space:pre">	</span>error = ENOENT;<br class=""> <span class="Apple-tab-span" style="white-space:pre">	</span><span class="Apple-tab-span" style="white-space:pre">	</span><span class="Apple-tab-span" style="white-space:pre">	</span>goto end;<br class=""> <span class="Apple-tab-span" style="white-space:pre">	</span><span class="Apple-tab-span" style="white-space:pre">	</span>}<br class=""></div></div></blockquote></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I guess we want to ensure ` typeof(a) ==&nbsp;typeof(b) ==&nbsp;<span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">fsid_t `, to prevent such kind of error in future.</span></div><div class=""><br class=""></div><div class=""><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class="">I see both gcc [1] and clang [2] have&nbsp;__builtin_types_compatible_p , so probably a good definition of&nbsp;</span></font><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">fsidcmp should be</span></div><div class=""><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></span></div><div class=""><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">```</span></div><div class=""><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class="">#define TYPEASSERT(v, t) \</span></font></div><div class=""><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class=""><span class="Apple-tab-span" style="white-space:pre">	</span>_Static_assert(__builtin_types_compatible_p(typeof(v), t), "Requires type '" #t "'")</span></font></div><div class=""><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><br class=""></span></div><div class=""><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class="">#define fsidcmp(a, b) ({ \</span></font></div><div class=""><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class=""><span class="Apple-tab-span" style="white-space:pre">	</span></span></font><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">TYPEASSERT((a),&nbsp;</span><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">fsid_t *); \</span></div><div class=""><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class=""><span class="Apple-tab-span" style="white-space:pre">	</span>TYPEASSERT((b),&nbsp;</span><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">fsid_t *); \</span></div><div class=""><span class="Apple-tab-span" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); white-space: pre;">	</span><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">memcmp((a), (b), sizeof(fsid_t)); \</span></div><div class=""><div class=""><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class="">})</span></font></div><div class=""><span style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">```</span></div><div class=""><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class=""><br class=""></span></font></div><div class=""><font color="#000000" class=""><span style="caret-color: rgb(0, 0, 0);" class=""><div class="">1. <a href="https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html" class="">https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html</a></div><div class="">2. <a href="https://clang.llvm.org/docs/LanguageExtensions.html" class="">https://clang.llvm.org/docs/LanguageExtensions.html</a></div></span></font></div><br class=""><div class="">
<div>Best regards,</div><div>Zhenlei</div>

</div>
<br class=""></div></body></html>

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?72190C27-0D45-4300-BB78-719F5EB510E9>