Skip to contentSkip to conversation

mountd: Check 'nfsd/clients' directory presence instead of kernel version

PATCH In review Konstantin Khorenko 2 participants 2 messages May 16, 2022 – May 26, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mountd: Check 'nfsd/clients' directory presence instead of kernel version

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.

---
 support/export/v4clients.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
support/export/v4clients.c +5 -2
index 5e4f1058..5f15b614 100644
@@ -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;
Signature · 1 line
2.31.1
#1 lore raw
Quoted 11 lines · 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.

Committed... (tag: nfs-utils-2-6-2-rc5)

steved.

Quoted 31 lines
---
  support/export/v4clients.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
support/export/v4clients.c +5 -2
index 5e4f1058..5f15b614 100644
@@ -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;