linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mountd: Check 'nfsd/clients' directory presence instead of kernel version
@ 2022-05-16 18:55 Konstantin Khorenko
  2022-05-26 17:33 ` Steve Dickson
  0 siblings, 1 reply; 2+ messages in thread
From: Konstantin Khorenko @ 2022-05-16 18:55 UTC (permalink / raw)
  To: linux-nfs; +Cc: Steve Dickson, Konstantin Khorenko

Kernel major version does not always provide 100% certainty about
presence or absence of a feature, for example:
 - some distros backport feature from mainstream kernel to older kernels
 - if NFS server is run inside a system container the reported kernel
   version inside the container may be faked

So let's determine the feature presence by checking
'/proc/fs/nfsd/clients/' directory presence instead of checking the
kernel version.

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 support/export/v4clients.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/support/export/v4clients.c b/support/export/v4clients.c
index 5e4f1058..5f15b614 100644
--- a/support/export/v4clients.c
+++ b/support/export/v4clients.c
@@ -8,9 +8,9 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <sys/inotify.h>
+#include <sys/stat.h>
 #include <errno.h>
 #include "export.h"
-#include "version.h"
 
 /* search.h declares 'struct entry' and nfs_prot.h
  * does too.  Easiest fix is to trick search.h into
@@ -24,7 +24,10 @@ static int clients_fd = -1;
 
 void v4clients_init(void)
 {
-	if (linux_version_code() < MAKE_VERSION(5, 3, 0))
+	struct stat sb;
+
+	if (!stat("/proc/fs/nfsd/clients", &sb) == 0 ||
+	    !S_ISDIR(sb.st_mode))
 		return;
 	if (clients_fd >= 0)
 		return;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mountd: Check 'nfsd/clients' directory presence instead of kernel version
  2022-05-16 18:55 [PATCH] mountd: Check 'nfsd/clients' directory presence instead of kernel version Konstantin Khorenko
@ 2022-05-26 17:33 ` Steve Dickson
  0 siblings, 0 replies; 2+ messages in thread
From: Steve Dickson @ 2022-05-26 17:33 UTC (permalink / raw)
  To: Konstantin Khorenko, linux-nfs



On 5/16/22 2:55 PM, Konstantin Khorenko wrote:
> Kernel major version does not always provide 100% certainty about
> presence or absence of a feature, for example:
>   - some distros backport feature from mainstream kernel to older kernels
>   - if NFS server is run inside a system container the reported kernel
>     version inside the container may be faked
> 
> So let's determine the feature presence by checking
> '/proc/fs/nfsd/clients/' directory presence instead of checking the
> kernel version.
> 
> Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
Committed... (tag: nfs-utils-2-6-2-rc5)

steved.
> ---
>   support/export/v4clients.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/support/export/v4clients.c b/support/export/v4clients.c
> index 5e4f1058..5f15b614 100644
> --- a/support/export/v4clients.c
> +++ b/support/export/v4clients.c
> @@ -8,9 +8,9 @@
>   #include <unistd.h>
>   #include <stdlib.h>
>   #include <sys/inotify.h>
> +#include <sys/stat.h>
>   #include <errno.h>
>   #include "export.h"
> -#include "version.h"
>   
>   /* search.h declares 'struct entry' and nfs_prot.h
>    * does too.  Easiest fix is to trick search.h into
> @@ -24,7 +24,10 @@ static int clients_fd = -1;
>   
>   void v4clients_init(void)
>   {
> -	if (linux_version_code() < MAKE_VERSION(5, 3, 0))
> +	struct stat sb;
> +
> +	if (!stat("/proc/fs/nfsd/clients", &sb) == 0 ||
> +	    !S_ISDIR(sb.st_mode))
>   		return;
>   	if (clients_fd >= 0)
>   		return;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-26 17:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 18:55 [PATCH] mountd: Check 'nfsd/clients' directory presence instead of kernel version Konstantin Khorenko
2022-05-26 17:33 ` Steve Dickson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).