pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch to enable Cygwin idmaper, SIDs, uid/gid in Nfs3Attr EA by default, 2023-12-13
Posted by Anonymous on Wed 13th Dec 2023 17:41
raw | new post

  1. From d59b13cd6e26a6827bff3451a936b3fc78ffb871 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Wed, 13 Dec 2023 16:52:10 +0100
  4. Subject: [PATCH 1/4] features: Rename NFS41...FEATURE NAMESERVICE_CYGWIN to
  5.  IDMAPPER_CYGWIN
  6.  
  7. nfs41_build_features.h: Rename
  8. NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN to
  9. NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN to avoid confusion.
  10.  
  11. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  12. ---
  13. daemon/idmap.c             | 10 +++++-----
  14.  daemon/idmap.h             |  5 +++--
  15.  daemon/idmap_cygwin.c      |  8 ++++----
  16.  daemon/nfs41_daemon.c      | 26 +++++++++++++++++++++-----
  17.  sys/nfs41_build_features.h |  6 +++---
  18.  5 files changed, 36 insertions(+), 19 deletions(-)
  19.  
  20. diff --git a/daemon/idmap.c b/daemon/idmap.c
  21. index 6ce461b..169de15 100644
  22. --- a/daemon/idmap.c
  23. +++ b/daemon/idmap.c
  24. @@ -670,7 +670,7 @@ static int idmap_lookup_user(
  25.          if (difftime(time(NULL), user->last_updated) < (double)context->config.cache_ttl)
  26.              goto out;
  27.      }
  28. -#ifndef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  29. +#ifndef NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN
  30.      /* send the query to the ldap server */
  31.      status = idmap_query_attrs(context, lookup,
  32.          attributes, optional, values, NUM_ATTRIBUTES);
  33. @@ -794,7 +794,7 @@ static int idmap_lookup_user(
  34.              (unsigned long)user->uid,
  35.              (unsigned long)user->gid);
  36.      }
  37. -#endif /* !NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  38. +#endif /* !NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN */
  39.      if (context->config.cache_ttl) {
  40.          /* insert the entry into the cache */
  41.          cache_insert(&context->users, lookup, &user->entry);
  42. @@ -824,7 +824,7 @@ static int idmap_lookup_group(
  43.          if (difftime(time(NULL), group->last_updated) < (double)context->config.cache_ttl)
  44.              goto out;
  45.      }
  46. -#ifndef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  47. +#ifndef NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN
  48.      /* send the query to the ldap server */
  49.      status = idmap_query_attrs(context, lookup,
  50.          attributes, 0, values, NUM_ATTRIBUTES);
  51. @@ -895,7 +895,7 @@ static int idmap_lookup_group(
  52.              group->name,
  53.              (unsigned long)group->gid);
  54.      }
  55. -#endif /* !NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  56. +#endif /* !NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN */
  57.      if (context->config.cache_ttl) {
  58.          /* insert the entry into the cache */
  59.          cache_insert(&context->groups, lookup, &group->entry);
  60. @@ -931,7 +931,7 @@ int nfs41_idmap_create(
  61.          goto out_err_free;
  62.      }
  63.  
  64. -#ifndef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  65. +#ifndef NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN
  66.      /* initialize ldap and configure options */
  67.      context->ldap = ldap_init(context->config.hostname, context->config.port);
  68.      if (context->ldap == NULL) {
  69. diff --git a/daemon/idmap.h b/daemon/idmap.h
  70. index c515084..622bf38 100644
  71. --- a/daemon/idmap.h
  72. +++ b/daemon/idmap.h
  73. @@ -3,6 +3,7 @@
  74.   *
  75.   * Olga Kornievskaia <aglo@umich.edu>
  76.   * Casey Bodley <cbodley@umich.edu>
  77. + * Roland Mainz <roland.mainz@nrubsig.org>
  78.   *
  79.   * This library is free software; you can redistribute it and/or modify it
  80.   * under the terms of the GNU Lesser General Public License as published by
  81. @@ -65,9 +66,9 @@ int nfs41_idmap_gid_to_group(
  82.      size_t len);
  83.  
  84.  /* idmap_cygwin.c */
  85. -#ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  86. +#ifdef NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN
  87.  int cygwin_getent_passwd(const char *name, char *res_loginname, uid_t *res_uid, gid_t *res_gid);
  88.  int cygwin_getent_group(const char* name, char* res_group_name, gid_t* res_gid);
  89. -#endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  90. +#endif /* NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN */
  91.  
  92.  #endif /* !IDMAP_H */
  93. diff --git a/daemon/idmap_cygwin.c b/daemon/idmap_cygwin.c
  94. index f8bb74e..41c2c67 100644
  95. --- a/daemon/idmap_cygwin.c
  96. +++ b/daemon/idmap_cygwin.c
  97. @@ -30,9 +30,9 @@
  98.  #include "nfs41_const.h"
  99.  #include "list.h"
  100.  #include "daemon_debug.h"
  101. -#ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  102. +#ifdef NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN
  103.  #include "cpvparser1.h"
  104. -#endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  105. +#endif /* NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN */
  106.  
  107.  #define CYGWINIDLVL 2   /* dprintf level for idmap logging */
  108.  
  109. @@ -43,7 +43,7 @@
  110.      "/cygdrive/c/cygwin64/lib/msnfs41client/cygwin_idmapper.ksh")
  111.  
  112.  
  113. -#ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  114. +#ifdef NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN
  115.  int cygwin_getent_passwd(const char *name, char *res_loginname, uid_t *res_uid, gid_t *res_gid)
  116.  {
  117.      char cmdbuff[1024];
  118. @@ -259,4 +259,4 @@ fail:
  119.  
  120.      return res;
  121.  }
  122. -#endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  123. +#endif /* NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN */
  124. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  125. index 6eaa0e8..906a951 100644
  126. --- a/daemon/nfs41_daemon.c
  127. +++ b/daemon/nfs41_daemon.c
  128. @@ -3,6 +3,7 @@
  129.   *
  130.   * Olga Kornievskaia <aglo@umich.edu>
  131.   * Casey Bodley <cbodley@umich.edu>
  132. + * Roland Mainz <roland.mainz@nrubsig.org>
  133.   *
  134.   * This library is free software; you can redistribute it and/or modify it
  135.   * under the terms of the GNU Lesser General Public License as published by
  136. @@ -270,9 +271,9 @@ static bool_t parse_cmdlineargs(int argc, TCHAR *argv[], nfsd_args *out)
  137.      }
  138.  
  139.      (void)fprintf(stdout, "parse_cmdlineargs: debug_level %d ldap is %d "
  140. -#ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  141. +#ifdef NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN
  142.          "idmap_cygwin is 1 "
  143. -#endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  144. +#endif /* NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN */
  145.          "\n",
  146.          out->debug_level, out->ldap_enable);
  147.      return TRUE;
  148. @@ -415,7 +416,22 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  149.  #ifdef _DEBUG
  150.      /* dump memory leaks to stderr on exit; this requires the debug heap,
  151.      /* available only when built in debug mode under visual studio -cbodley */
  152. -    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  153. +
  154. +    int crtsetdbgflags = 0;
  155. +    crtsetdbgflags |= _CRTDBG_ALLOC_MEM_DF;  /* use debug heap */
  156. +    crtsetdbgflags |= _CRTDBG_LEAK_CHECK_DF; /* report leaks on exit */
  157. +/* Disabled for now, git clone ... gcc.git does not work with it */
  158. +#ifdef DISABLED_FOR_NOW
  159. +    /*
  160. +     * _CRTDBG_DELAY_FREE_MEM_DF - Delay freeing of memory, but fill
  161. +     * memory blocks passed to |free()| with 0xdd. We rely on that to
  162. +     * see 0xdddddddddddddddd-pointers for use-after-free and catch
  163. +     * them in stress testing instead of having to deal with a core
  164. +     * dump
  165. +     */
  166. +    crtsetdbgflags |= _CRTDBG_DELAY_FREE_MEM_DF;
  167. +#endif
  168. +    (void)_CrtSetDbgFlag(crtsetdbgflags);
  169.      _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
  170.  
  171.      /*
  172. @@ -449,11 +465,11 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  173.          eprintf("Failed to enter HIGH_PRIORITY_CLASS mode\n");
  174.      }
  175.  
  176. -#ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  177. +#ifdef NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN
  178.      /* force enable for cygwin getent passwd/group testing */
  179.      cmd_args.ldap_enable = TRUE;
  180.      DASSERT(0/* test asserts*/, 0);
  181. -#endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  182. +#endif /* NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN */
  183.  
  184.      nfs41_server_list_init();
  185.  
  186. diff --git a/sys/nfs41_build_features.h b/sys/nfs41_build_features.h
  187. index 93ee7a9..19f81f9 100644
  188. --- a/sys/nfs41_build_features.h
  189. +++ b/sys/nfs41_build_features.h
  190. @@ -42,9 +42,9 @@
  191.  // #define NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID 1
  192.  
  193.  /*
  194. - * NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN - use Cygwin /usr/bin/getent
  195. - * as "name service"
  196. + * NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN - use Cygwin shell script
  197. + * as to do the idmapping between NFS client and NFS server
  198.   */
  199. -// #define NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN 1
  200. +// #define NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN 1
  201.  
  202.  #endif /* !_NFS41_DRIVER_BUILDFEATURES_ */
  203. --
  204. 2.42.1
  205.  
  206. From 1d4b36ea449c5f437846432fb069c5467202887f Mon Sep 17 00:00:00 2001
  207. From: Roland Mainz <roland.mainz@nrubsig.org>
  208. Date: Wed, 13 Dec 2023 16:56:24 +0100
  209. Subject: [PATCH 2/4] Enable Cygwin idmapper, SID and NfsV3Attribute support by
  210.  default
  211.  
  212. Enable build features
  213. NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES,
  214. NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID and
  215. NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN by default.
  216.  
  217. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  218. ---
  219. sys/nfs41_build_features.h | 6 +++---
  220.  1 file changed, 3 insertions(+), 3 deletions(-)
  221.  
  222. diff --git a/sys/nfs41_build_features.h b/sys/nfs41_build_features.h
  223. index 19f81f9..5827905 100644
  224. --- a/sys/nfs41_build_features.h
  225. +++ b/sys/nfs41_build_features.h
  226. @@ -32,19 +32,19 @@
  227.  /*
  228.   * NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES - return local uid/gid values
  229.   */
  230. -// #define NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES 1
  231. +#define NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES 1
  232.  
  233.  /*
  234.   * NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID - give NFS
  235.   * files which do not map to a local account a SID in the
  236.   * Unix_User+x/Unix_Group+x range
  237.   */
  238. -// #define NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID 1
  239. +#define NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID 1
  240.  
  241.  /*
  242.   * NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN - use Cygwin shell script
  243.   * as to do the idmapping between NFS client and NFS server
  244.   */
  245. -// #define NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN 1
  246. +#define NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN 1
  247.  
  248.  #endif /* !_NFS41_DRIVER_BUILDFEATURES_ */
  249. --
  250. 2.42.1
  251.  
  252. From 6b427058f9c135c878aa101270449eef4f87795b Mon Sep 17 00:00:00 2001
  253. From: Roland Mainz <roland.mainz@nrubsig.org>
  254. Date: Wed, 13 Dec 2023 18:19:11 +0100
  255. Subject: [PATCH 3/4] cygwin: Sources should go into /usr/src/, not /src/
  256.  
  257. Sources in the binary tarball should go into /usr/src/, not /src
  258.  
  259. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  260. ---
  261. cygwin/Makefile | 8 ++++----
  262.  1 file changed, 4 insertions(+), 4 deletions(-)
  263.  
  264. diff --git a/cygwin/Makefile b/cygwin/Makefile
  265. index 28c03e9..9b4ff11 100644
  266. --- a/cygwin/Makefile
  267. +++ b/cygwin/Makefile
  268. @@ -62,7 +62,7 @@ installdest: $(VS_BUILD_DIR)/nfsd.exe \
  269.         # /usr/lib is a bind mount to C:/cygwin64/lib, so copy library data to /cygdrive/c/cygwin64/lib
  270.         mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/lib
  271.         mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/lib/msnfs41client
  272. -       mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/src/msnfs41client
  273. +       mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/usr/src/msnfs41client
  274.         cp -r $(VS_BUILD_DIR)/nfsd.exe          $(DESTDIR)/cygdrive/c/cygwin64/sbin/nfsd_debug.exe
  275.         cp -r $(VS_BUILD_DIR)/nfsd.pdb          $(DESTDIR)/cygdrive/c/cygwin64/sbin/nfsd_debug.pdb
  276.         cp -r $(VS_BUILD_DIR)/nfs_mount.*       $(DESTDIR)/cygdrive/c/cygwin64/sbin/.
  277. @@ -79,9 +79,9 @@ installdest: $(VS_BUILD_DIR)/nfsd.exe \
  278.         (cd "$(DESTDIR)/cygdrive/c/cygwin64/sbin/" && ln -sf ../lib/msnfs41client/msnfs41client .)
  279.         cp $(PROJECT_BASEDIR_DIR)/cygwin_idmapper.ksh           $(DESTDIR)/cygdrive/c/cygwin64/lib/msnfs41client/.
  280.         @ printf "# Package sources and diffs\n"
  281. -       git bundle create "$(DESTDIR)/cygdrive/c/cygwin64/src/msnfs41client/msnfs41client_git.bundle" HEAD
  282. -       git diff -w     >"$(DESTDIR)/cygdrive/c/cygwin64/src/msnfs41client/msnfs41client_diff_w.diff"
  283. -       git diff        >"$(DESTDIR)/cygdrive/c/cygwin64/src/msnfs41client/msnfs41client_diff.diff"
  284. +       git bundle create "$(DESTDIR)/cygdrive/c/cygwin64/usr/src/msnfs41client/msnfs41client_git.bundle" HEAD
  285. +       git diff -w     >"$(DESTDIR)/cygdrive/c/cygwin64/usr/src/msnfs41client/msnfs41client_diff_w.diff"
  286. +       git diff        >"$(DESTDIR)/cygdrive/c/cygwin64/usr/src/msnfs41client/msnfs41client_diff.diff"
  287.         @ printf "# Package utilties\n"
  288.         cp $(CYGWIN_MAKEFILE_DIR)/utils/mount_sshnfs/mount_sshnfs.ksh $(DESTDIR)/cygdrive/c/cygwin64/sbin/mount_sshnfs
  289.         chmod a+x $(DESTDIR)/cygdrive/c/cygwin64/sbin/mount_sshnfs
  290. --
  291. 2.42.1
  292.  
  293. From e570cca9d618557e1f1d13a2e13d2290ba3dcb6b Mon Sep 17 00:00:00 2001
  294. From: Roland Mainz <roland.mainz@nrubsig.org>
  295. Date: Wed, 13 Dec 2023 18:22:44 +0100
  296. Subject: [PATCH 4/4] Add new build option NFS41_DRIVER_STABILITY_HACKS - and
  297.  use it
  298.  
  299. Add new build option NFS41_DRIVER_STABILITY_HACKS to
  300. sys/nfs41_build_features.h, for horrible workarounds&hacks
  301. to improve "stability" at the expense of sanity - and use it.
  302.  
  303. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  304. ---
  305. daemon/daemon_debug.h      | 22 ++++++++++++++++++++++
  306.  daemon/getattr.c           | 31 ++++++++++++++++++++++++++++++-
  307.  daemon/nfs41_daemon.c      |  1 +
  308.  daemon/nfs41_ops.c         |  4 ++++
  309.  daemon/open.c              | 20 +++++++++++++++++++-
  310.  daemon/upcall.c            |  2 ++
  311.  sys/nfs41_build_features.h |  6 ++++++
  312.  7 files changed, 84 insertions(+), 2 deletions(-)
  313.  
  314. diff --git a/daemon/daemon_debug.h b/daemon/daemon_debug.h
  315. index 24a2683..07898fe 100644
  316. --- a/daemon/daemon_debug.h
  317. +++ b/daemon/daemon_debug.h
  318. @@ -34,6 +34,14 @@
  319.  #define DEFAULT_DEBUG_LEVEL 1
  320.  
  321.  
  322. +/* 0xdd..dd is the filler by the debug memory allocator */
  323. +#define DEBUG_IS_VALID_NON_NULL_PTR(ptr) \
  324. +    ( \
  325. +        (((char *)(ptr)) != ((char *)0xddddddddddddddddLL)) && \
  326. +        (((char *)(ptr)) != ((char *)0xffffffffffffffffLL)) && \
  327. +        ((ptr) != NULL) \
  328. +    )
  329. +
  330.  #define EASSERT(exp) \
  331.      if (!(exp)) { \
  332.          eprintf("ASSERTION '%s' in '%s'/%ld failed.\n", \
  333. @@ -43,6 +51,20 @@
  334.          dprintf((level), "ASSERTION '%s' in '%s'/%ld failed.\n", \
  335.              ""#exp"", __FILE__, (long)__LINE__); }
  336.  
  337. +#define DASSERT_IS_VALID_NON_NULL_PTR(exp, level) \
  338. +    if (!DEBUG_IS_VALID_NON_NULL_PTR(exp)) { \
  339. +        dprintf((level), "ASSERTION " \
  340. +            "!DEBUG_IS_VALID_NON_NULL_PTR('%s'=%p) " \
  341. +            "in '%s'/%ld failed.\n", \
  342. +            ""#exp"", (void *)(exp), __FILE__, (long)__LINE__); }
  343. +
  344. +#define EASSERT_IS_VALID_NON_NULL_PTR(exp) \
  345. +    if (!DEBUG_IS_VALID_NON_NULL_PTR(exp)) { \
  346. +        eprintf("ASSERTION " \
  347. +            "!DEBUG_IS_VALID_NON_NULL_PTR('%s'=%p) " \
  348. +            "in '%s'/%ld failed.\n", \
  349. +            ""#exp"", (void *)(exp), __FILE__, (long)__LINE__); }
  350. +
  351.  /* daemon_debug.h */
  352.  void set_debug_level(int level);
  353.  void dprintf(int level, LPCSTR format, ...);
  354. diff --git a/daemon/getattr.c b/daemon/getattr.c
  355. index 7c5f241..b83085a 100644
  356. --- a/daemon/getattr.c
  357. +++ b/daemon/getattr.c
  358. @@ -23,6 +23,7 @@
  359.  #include <stdio.h>
  360.  #include <strsafe.h>
  361.  
  362. +#include "nfs41_build_features.h"
  363.  #include "nfs41_ops.h"
  364.  #include "name_cache.h"
  365.  #include "upcall.h"
  366. @@ -59,8 +60,19 @@ int nfs41_cached_getattr(
  367.  static int parse_getattr(unsigned char *buffer, uint32_t length, nfs41_upcall *upcall)
  368.  {
  369.      int status;
  370. +#ifdef NFS41_DRIVER_STABILITY_HACKS
  371. +    EASSERT(length > 4);
  372. +    if (length <= 4) {
  373. +        status = ERROR_INVALID_PARAMETER;
  374. +        goto out;
  375. +    }
  376. +    EASSERT_IS_VALID_NON_NULL_PTR(upcall->state_ref);
  377. +    if (!DEBUG_IS_VALID_NON_NULL_PTR(upcall->state_ref)) {
  378. +        status = ERROR_INVALID_PARAMETER;
  379. +        goto out;
  380. +    }
  381. +#endif /* NFS41_DRIVER_STABILITY_HACKS */
  382.      getattr_upcall_args *args = &upcall->args.getattr;
  383. -
  384.      status = safe_read(&buffer, &length, &args->query_class, sizeof(args->query_class));
  385.      if (status) goto out;
  386.      status = safe_read(&buffer, &length, &args->buf_len, sizeof(args->buf_len));
  387. @@ -80,6 +92,23 @@ static int handle_getattr(void *daemon_context, nfs41_upcall *upcall)
  388.      nfs41_open_state *state = upcall->state_ref;
  389.      nfs41_file_info info = { 0 };
  390.  
  391. +#ifdef NFS41_DRIVER_STABILITY_HACKS
  392. +    if (!DEBUG_IS_VALID_NON_NULL_PTR(state->session)) {
  393. +        eprintf("handle_getattr: Invalid session ptr=%p\n",
  394. +            (void *)state->session);
  395. +        status = ERROR_INVALID_PARAMETER;
  396. +        goto out;
  397. +    }
  398. +
  399. +    if (!DEBUG_IS_VALID_NON_NULL_PTR(state->file.fh.superblock)) {
  400. +        eprintf("handle_getattr: Invalid state->file.fh.superblock ptr=%p\n",
  401. +            (void *)state->file.fh.superblock);
  402. +        /* gisburn: fixme: maybe this should be |ERROR_INTERNAL_ERROR| ? */
  403. +        status = ERROR_INVALID_PARAMETER;
  404. +        goto out;
  405. +    }
  406. +#endif /* NFS41_DRIVER_STABILITY_HACKS */
  407. +
  408.      status = nfs41_cached_getattr(state->session, &state->file, &info);
  409.      if (status) {
  410.          eprintf("nfs41_cached_getattr() failed with %d\n", status);
  411. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  412. index 906a951..e6c47ef 100644
  413. --- a/daemon/nfs41_daemon.c
  414. +++ b/daemon/nfs41_daemon.c
  415. @@ -28,6 +28,7 @@
  416.  #include <devioctl.h>
  417.  #include <lmcons.h> /* UNLEN for GetUserName() */
  418.  #include <iphlpapi.h> /* for GetNetworkParam() */
  419. +#include "nfs41_build_features.h"
  420.  #include "nfs41_driver.h" /* for NFS41_USER_DEVICE_NAME_A */
  421.  #include "nfs41_np.h" /* for NFS41NP_SHARED_MEMORY */
  422.  
  423. diff --git a/daemon/nfs41_ops.c b/daemon/nfs41_ops.c
  424. index bcca070..7d89c06 100644
  425. --- a/daemon/nfs41_ops.c
  426. +++ b/daemon/nfs41_ops.c
  427. @@ -25,6 +25,7 @@
  428.  #include <stdlib.h>
  429.  #include <time.h>
  430.  
  431. +#include "nfs41_build_features.h"
  432.  #include "nfs41_ops.h"
  433.  #include "nfs41_compound.h"
  434.  #include "nfs41_xdr.h"
  435. @@ -400,6 +401,9 @@ int nfs41_open(
  436.      bool_t already_delegated = delegation->type == OPEN_DELEGATE_READ
  437.          || delegation->type == OPEN_DELEGATE_WRITE;
  438.  
  439. +    EASSERT_IS_VALID_NON_NULL_PTR(parent);
  440. +    EASSERT_IS_VALID_NON_NULL_PTR(parent->fh.superblock);
  441. +
  442.      /* depending on the claim type, OPEN expects CURRENT_FH set
  443.       * to either the parent directory, or to the file itself */
  444.      switch (claim->claim) {
  445. diff --git a/daemon/open.c b/daemon/open.c
  446. index a2d92a4..defdb6c 100644
  447. --- a/daemon/open.c
  448. +++ b/daemon/open.c
  449. @@ -24,8 +24,8 @@
  450.  #include <ctype.h>
  451.  #include <strsafe.h>
  452.  
  453. -#include "nfs41_ops.h"
  454.  #include "nfs41_build_features.h"
  455. +#include "nfs41_ops.h"
  456.  #include "nfs41_daemon.h"
  457.  #include "delegation.h"
  458.  #include "from_kernel.h"
  459. @@ -99,6 +99,24 @@ static void open_state_free(
  460.  void nfs41_open_state_ref(
  461.      IN nfs41_open_state *state)
  462.  {
  463. +#ifdef NFS41_DRIVER_STABILITY_HACKS
  464. +    /*
  465. +     * gisburn: fixme: sometimes this happens under high parallel
  466. +     * usage with multiple mounts - but why ?
  467. +     * 0:038> kp
  468. +     * Child-SP          RetAddr           Call Site
  469. +     * 0000006d`431fde10 00007ff7`32f7d905 nfsd!nfs41_open_state_ref(struct __nfs41_open_state * state = 0x00000000`00000000)+0x31
  470. +     * 0000006d`431fdf30 00007ff7`32f4d284 nfsd!upcall_parse(unsigned char * buffer = 0x0000006d`431fe180 "???", unsigned int length = 8, struct __nfs41_upcall * upcall = 0x0000006d`431ff1e0)+0x2e5
  471. +     * 0000006d`431fe0b0 00007ffc`1ca24c7c nfsd!thread_main(void * args = 0x00007ff7`32fb6080)+0x144
  472. +     * 0000006d`431ffe00 00007ffc`4d4b7344 ucrtbased!thread_start<unsigned int (void * parameter = 0x0000025d`a9c6def0)+0x9c
  473. +     * 0000006d`431ffe60 00007ffc`4efc26b1 KERNEL32!BaseThreadInitThunk+0x14
  474. +     * 0000006d`431ffe90 00000000`00000000 ntdll!RtlUserThreadStart+0x21
  475. +     */
  476. +    EASSERT_IS_VALID_NON_NULL_PTR(state);
  477. +    if (!DEBUG_IS_VALID_NON_NULL_PTR(state))
  478. +        return;
  479. +#endif /* NFS41_DRIVER_STABILITY_HACKS */
  480. +
  481.      const LONG count = InterlockedIncrement(&state->ref_count);
  482.  
  483.      dprintf(2, "nfs41_open_state_ref(%s) count %d\n", state->path.path, count);
  484. diff --git a/daemon/upcall.c b/daemon/upcall.c
  485. index bd13c61..d8b6b39 100644
  486. --- a/daemon/upcall.c
  487. +++ b/daemon/upcall.c
  488. @@ -23,6 +23,7 @@
  489.  #include <stdio.h>
  490.  #include <time.h>
  491.  
  492. +#include "nfs41_build_features.h"
  493.  #include "upcall.h"
  494.  #include "daemon_debug.h"
  495.  #include "util.h"
  496. @@ -121,6 +122,7 @@ int upcall_parse(
  497.      /* parse the operation's arguments */
  498.      op = g_upcall_op_table[upcall->opcode];
  499.      if (op && op->parse) {
  500. +        EASSERT(length > 0);
  501.          status = op->parse(buffer, length, upcall);
  502.          if (status) {
  503.              eprintf("parsing of upcall '%s' failed with %d.\n",
  504. diff --git a/sys/nfs41_build_features.h b/sys/nfs41_build_features.h
  505. index 5827905..04e5d8f 100644
  506. --- a/sys/nfs41_build_features.h
  507. +++ b/sys/nfs41_build_features.h
  508. @@ -47,4 +47,10 @@
  509.   */
  510.  #define NFS41_DRIVER_FEATURE_IDMAPPER_CYGWIN 1
  511.  
  512. +/*
  513. + * NFS41_DRIVER_STABILITY_HACKS - use horrible
  514. + * hacks to improve stabilty
  515. + */
  516. +#define NFS41_DRIVER_STABILITY_HACKS 1
  517. +
  518.  #endif /* !_NFS41_DRIVER_BUILDFEATURES_ */
  519. --
  520. 2.42.1

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at