pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Cache owner/group+misc patches
Posted by Anonymous on Sat 21st Oct 2023 12:04
raw | new post

  1. From da2c5d5c4e51013221ab10de961c4f2c2ada2f76 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Sat, 21 Oct 2023 11:35:57 +0200
  4. Subject: [PATCH 1/3] daemon: Add |EASSERT()|/|DASSERT()| macros for assertions
  5.  
  6. daemon: Add |EASSERT()|/|DASSERT()| macros for assertions, so we can
  7. see whether assumptions about our code works in the real-world or
  8. not.
  9. |EASSERT(exp)| uses |eprintf()|, |DASSERT(exp, level)| uses
  10. |dprintf(level, ...)|
  11.  
  12. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  13. ---
  14. daemon/daemon_debug.h | 9 +++++++++
  15.  1 file changed, 9 insertions(+)
  16.  
  17. diff --git a/daemon/daemon_debug.h b/daemon/daemon_debug.h
  18. index f484d58..17cf046 100644
  19. --- a/daemon/daemon_debug.h
  20. +++ b/daemon/daemon_debug.h
  21. @@ -34,6 +34,15 @@
  22.  #define DEFAULT_DEBUG_LEVEL 1
  23.  
  24.  
  25. +#define EASSERT(exp) \
  26. +    if (!(exp)) { \
  27. +        eprintf("ASSERTION '%s' in '%s'/%ld failed.\n", \
  28. +            ""#exp"", __FILE__, (long)__LINE__); }
  29. +#define DASSERT(exp, level) \
  30. +    if (!(exp)) { \
  31. +        dprintf((level), "ASSERTION '%s' in '%s'/%ld failed.\n", \
  32. +            ""#exp"", __FILE__, (long)__LINE__); }
  33. +
  34.  /* daemon_debug.h */
  35.  void set_debug_level(int level);
  36.  void dprintf(int level, LPCSTR format, ...);
  37. --
  38. 2.39.0
  39.  
  40. From fc2d2343eb8352cc0ac80eeca17519556f737954 Mon Sep 17 00:00:00 2001
  41. From: Roland Mainz <roland.mainz@nrubsig.org>
  42. Date: Sat, 21 Oct 2023 11:43:48 +0200
  43. Subject: [PATCH 2/3] msnfs41client.bash: cdb: Print exception stack traces and
  44.  continue
  45.  
  46. msnfs41client.bash: When running the nfsd_debug.exe daemon
  47. under cdb control print the stack traces if an exception occurs,
  48. and then continue, i.e. '!gflag +soe;sxe -c "kp;gn" *;g' in cdb
  49. syntax.
  50.  
  51. Turned out to be very useful in hunting the issues around
  52. "Unknown exception - code 00000005 (first chance)" and other
  53. hiccups in the daemon code, so we enable it now for default in
  54. msnfs41client.bash.
  55.  
  56. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  57. ---
  58. cygwin/devel/msnfs41client.bash | 6 ++++--
  59.  1 file changed, 4 insertions(+), 2 deletions(-)
  60.  
  61. diff --git a/cygwin/devel/msnfs41client.bash b/cygwin/devel/msnfs41client.bash
  62. index 7afaac2..454b4bc 100644
  63. --- a/cygwin/devel/msnfs41client.bash
  64. +++ b/cygwin/devel/msnfs41client.bash
  65. @@ -112,7 +112,8 @@ function nfsclient_rundeamon
  66.         else
  67.                 export _NT_ALT_SYMBOL_PATH="$(cygpath -w "$PWD");srv*https://msdl.microsoft.com/download/symbols"
  68.                 # use '!gflag +full;g' for heap tests, eats lots of memory
  69. -               cdb -c 'g' "$(cygpath -w "$PWD/nfsd_debug.exe")" -d 0 --noldap #--gid 1616 --uid 1616
  70. +               # use '!gflag +soe;sxe -c "kp;gn" *;g' to report exceptions and then continue
  71. +               cdb -c '!gflag +soe;sxe -c "kp;gn" *;g' "$(cygpath -w "$PWD/nfsd_debug.exe")" -d 0 --noldap --gid 1616 --uid 1616
  72.         fi
  73.         return $?
  74.  }
  75. @@ -127,7 +128,8 @@ function nfsclient_system_rundeamon
  76.         else
  77.                 export _NT_ALT_SYMBOL_PATH="$(cygpath -w "$PWD");srv*https://msdl.microsoft.com/download/symbols"
  78.                 # use '!gflag +full;g' for heap tests, eats lots of memory
  79. -               su_system cdb -c 'g' "$(cygpath -w "$PWD/nfsd_debug.exe")" -d 0 --noldap #--gid 1616 --uid 1616
  80. +               # use '!gflag +soe;sxe -c "kp;gn" *;g' to report exceptions and then continue
  81. +               su_system cdb -c '!gflag +soe;sxe -c "kp;gn" *;g' "$(cygpath -w "$PWD/nfsd_debug.exe")" -d 0 --noldap --gid 1616 --uid 1616
  82.         fi
  83.         return $?
  84.  }
  85. --
  86. 2.39.0
  87.  
  88. From f40c9d03d0f228a4b5f56f1bdbcc48c1a92db4da Mon Sep 17 00:00:00 2001
  89. From: Roland Mainz <roland.mainz@nrubsig.org>
  90. Date: Sat, 21 Oct 2023 12:14:27 +0200
  91. Subject: [PATCH 3/3] nfsd: Always get NFSv4 OWNER/OWNER_GROUP data and cache
  92.  it
  93.  
  94. nfsd: Always get NFSv4 FATTR4_WORD1_OWNER|FATTR4_WORD1_OWNER_GROUP
  95. data and cache it in the name cache.
  96.  
  97. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  98. ---
  99. daemon/lookup.c       | 13 ++++++-----
  100.  daemon/name_cache.c   | 19 +++++++++++++++-
  101.  daemon/nfs41_daemon.c |  1 +
  102.  daemon/nfs41_types.h  |  4 ++++
  103.  daemon/nfs41_xdr.c    | 22 +++++++++++++++----
  104.  daemon/open.c         | 51 +++++++++++++++++--------------------------
  105.  daemon/util.c         | 10 +++++++++
  106.  daemon/util.h         |  3 +++
  107.  8 files changed, 82 insertions(+), 41 deletions(-)
  108.  
  109. diff --git a/daemon/lookup.c b/daemon/lookup.c
  110. index ea0a9d2..b90c3bd 100644
  111. --- a/daemon/lookup.c
  112. +++ b/daemon/lookup.c
  113. @@ -85,7 +85,8 @@ static void init_component_args(
  114.      args->attr_request.arr[1] = FATTR4_WORD1_MODE
  115.          | FATTR4_WORD1_NUMLINKS | FATTR4_WORD1_SYSTEM
  116.          | FATTR4_WORD1_TIME_ACCESS | FATTR4_WORD1_TIME_CREATE
  117. -        | FATTR4_WORD1_TIME_MODIFY;
  118. +        | FATTR4_WORD1_TIME_MODIFY
  119. +        | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
  120.  
  121.      args->getrootattr.attr_request = &args->attr_request;
  122.      res->root.path = path;
  123. @@ -210,8 +211,9 @@ static int server_lookup(
  124.      if (count == 0) {
  125.          if (target_out)
  126.              *target_out = dir;
  127. -        if (info_out)
  128. -            memcpy(info_out, res->getrootattr.info, sizeof(nfs41_file_info));
  129. +        if (info_out) {
  130. +            nfs41_file_info_cpy(info_out, res->getrootattr.info);
  131. +        }
  132.      } else if (count == 1) {
  133.          if (parent_out)
  134.              *parent_out = dir;
  135. @@ -258,8 +260,9 @@ static int server_lookup(
  136.          if (i == count-1) {
  137.              if (target_out)
  138.                  *target_out = file;
  139. -            if (info_out)
  140. -                memcpy(info_out, res->getattr[i].info, sizeof(nfs41_file_info));
  141. +            if (info_out) {
  142. +                nfs41_file_info_cpy(info_out, res->getattr[i].info);
  143. +            }
  144.          } else if (i == count-2) {
  145.              if (parent_out)
  146.                  *parent_out = file;
  147. diff --git a/daemon/name_cache.c b/daemon/name_cache.c
  148. index eaa0f36..89879a7 100644
  149. --- a/daemon/name_cache.c
  150. +++ b/daemon/name_cache.c
  151. @@ -99,6 +99,8 @@ struct attr_cache_entry {
  152.      unsigned                type : 4;
  153.      unsigned                invalidated : 1;
  154.      unsigned                delegated : 1;
  155. +    char                    owner[NFS4_OPAQUE_LIMIT+1];
  156. +    char                    owner_group[NFS4_OPAQUE_LIMIT+1];
  157.  };
  158.  #define ATTR_ENTRY_SIZE sizeof(struct attr_cache_entry)
  159.  
  160. @@ -304,6 +306,14 @@ static void attr_cache_update(
  161.      if (info->attrmask.count >= 2) {
  162.          if (info->attrmask.arr[1] & FATTR4_WORD1_MODE)
  163.              entry->mode = info->mode;
  164. +        if (info->attrmask.arr[1] & FATTR4_WORD1_OWNER) {
  165. +            EASSERT(info->owner != NULL);
  166. +            (void)strcpy(entry->owner, info->owner);
  167. +        }
  168. +        if (info->attrmask.arr[1] & FATTR4_WORD1_OWNER_GROUP) {
  169. +            EASSERT(info->owner_group != NULL);
  170. +            (void)strcpy(entry->owner_group, info->owner_group);
  171. +        }
  172.          if (info->attrmask.arr[1] & FATTR4_WORD1_NUMLINKS)
  173.              entry->numlinks = info->numlinks;
  174.          if (info->attrmask.arr[1] & FATTR4_WORD1_TIME_ACCESS) {
  175. @@ -341,6 +351,12 @@ static void copy_attrs(
  176.      dst->type = src->type;
  177.      dst->numlinks = src->numlinks;
  178.      dst->mode = src->mode;
  179. +    EASSERT(src->owner != NULL);
  180. +    dst->owner = dst->owner_buf;
  181. +    (void)strcpy(dst->owner, src->owner);
  182. +    EASSERT(src->owner_group != NULL);
  183. +    dst->owner_group = dst->owner_group_buf;
  184. +    (void)strcpy(dst->owner_group, src->owner_group);
  185.      dst->fileid = src->fileid;
  186.      dst->hidden = src->hidden;
  187.      dst->system = src->system;
  188. @@ -353,7 +369,8 @@ static void copy_attrs(
  189.      dst->attrmask.arr[1] = FATTR4_WORD1_MODE
  190.          | FATTR4_WORD1_NUMLINKS | FATTR4_WORD1_TIME_ACCESS
  191.          | FATTR4_WORD1_TIME_CREATE | FATTR4_WORD1_TIME_MODIFY
  192. -        | FATTR4_WORD1_SYSTEM;
  193. +        | FATTR4_WORD1_SYSTEM
  194. +        | FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
  195.  }
  196.  
  197.  
  198. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  199. index 42bfc6c..63edca4 100644
  200. --- a/daemon/nfs41_daemon.c
  201. +++ b/daemon/nfs41_daemon.c
  202. @@ -402,6 +402,7 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  203.  #ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  204.      /* force enable for cygwin getent passwd/group testing */
  205.      cmd_args.ldap_enable = TRUE;
  206. +    DASSERT(0/* test asserts*/, 0);
  207.  #endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  208.  
  209.      nfs41_server_list_init();
  210. diff --git a/daemon/nfs41_types.h b/daemon/nfs41_types.h
  211. index c5bad79..18a763a 100644
  212. --- a/daemon/nfs41_types.h
  213. +++ b/daemon/nfs41_types.h
  214. @@ -236,6 +236,10 @@ typedef struct __nfs41_file_info {
  215.      char                    *owner;
  216.      char                    *owner_group;
  217.      uint32_t                aclsupport;
  218. +
  219. +    /* Buffers */
  220. +    char owner_buf[NFS4_OPAQUE_LIMIT+1];
  221. +    char owner_group_buf[NFS4_OPAQUE_LIMIT+1];
  222.  } nfs41_file_info;
  223.  
  224.  #endif /* !__NFS41_DAEMON_TYPES_H__ */
  225. diff --git a/daemon/nfs41_xdr.c b/daemon/nfs41_xdr.c
  226. index 176b613..0261c54 100644
  227. --- a/daemon/nfs41_xdr.c
  228. +++ b/daemon/nfs41_xdr.c
  229. @@ -1802,19 +1802,33 @@ static bool_t decode_file_attrs(
  230.                  return FALSE;
  231.          }
  232.          if (attrs->attrmask.arr[1] & FATTR4_WORD1_OWNER) {
  233. -            char *ptr = &info->owner[0];
  234. +            if (info->owner == NULL)
  235. +                info->owner = info->owner_buf;
  236. +
  237. +            char *ptr = info->owner;
  238.              uint32_t owner_len;
  239.              if (!xdr_bytes(xdr, &ptr, &owner_len,
  240. -                            NFS4_OPAQUE_LIMIT))
  241. +                            NFS4_OPAQUE_LIMIT)) {
  242. +                info->owner = NULL;
  243.                  return FALSE;
  244. +            }
  245. +            EASSERT(owner_len > 0);
  246. +            EASSERT(owner_len < sizeof(info->owner_group_buf));
  247.              info->owner[owner_len] = '\0';
  248.          }
  249.          if (attrs->attrmask.arr[1] & FATTR4_WORD1_OWNER_GROUP) {
  250. -            char *ptr = &info->owner_group[0];
  251. +            if (info->owner_group == NULL)
  252. +                info->owner_group = info->owner_group_buf;
  253. +
  254. +            char *ptr = info->owner_group;
  255.              uint32_t owner_group_len;
  256.              if (!xdr_bytes(xdr, &ptr, &owner_group_len,
  257. -                            NFS4_OPAQUE_LIMIT))
  258. +                            NFS4_OPAQUE_LIMIT)) {
  259. +                info->owner_group = NULL;
  260.                  return FALSE;
  261. +            }
  262. +            EASSERT(owner_group_len > 0);
  263. +            EASSERT(owner_group_len < sizeof(info->owner_group_buf));
  264.              info->owner_group[owner_group_len] = '\0';
  265.          }
  266.          if (attrs->attrmask.arr[1] & FATTR4_WORD1_SPACE_AVAIL) {
  267. diff --git a/daemon/open.c b/daemon/open.c
  268. index 13e82b2..6aa5df7 100644
  269. --- a/daemon/open.c
  270. +++ b/daemon/open.c
  271. @@ -629,7 +629,7 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  272.          status = NO_ERROR;
  273.      } else if (args->symlink.len) {
  274.          /* handle cygwin symlinks */
  275. -        nfs41_file_info createattrs;
  276. +        nfs41_file_info createattrs = { 0 };
  277.          createattrs.attrmask.count = 2;
  278.          createattrs.attrmask.arr[0] = 0;
  279.          createattrs.attrmask.arr[1] = FATTR4_WORD1_MODE;
  280. @@ -663,33 +663,22 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  281.          args->changeattr = info.change;
  282.  
  283.  #ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
  284. -        bitmap4 og_attr_request = { 0 };
  285. -        nfs41_file_info og_info = { 0 };
  286. -        char owner[NFS4_OPAQUE_LIMIT], group[NFS4_OPAQUE_LIMIT];
  287. -        nfsacl41 acl = { 0 };
  288. -
  289. -        /*
  290. -         * gisburn:
  291. -         * 1. We should cache owner/group information
  292. -         * 2. We should always ask for
  293. -         * FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP with the other
  294. -         * attributes
  295. -         */
  296. -        og_attr_request.count = 2;
  297. -        og_attr_request.arr[1] = FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
  298. -        og_info.owner = owner;
  299. -        og_info.owner_group = group;
  300. -        status = nfs41_getattr(state->session, &state->file, &og_attr_request, &og_info);
  301. -        if (status) {
  302. -            eprintf("get_stat_data: nfs41_cached_getattr() failed with %d\n",
  303. -            status);
  304. -        }
  305. -
  306. +        char owner[NFS4_OPAQUE_LIMIT], owner_group[NFS4_OPAQUE_LIMIT];
  307.          uid_t map_uid = -1;
  308.          gid_t gid_dummy = -1;
  309.          gid_t map_gid = -1;
  310.          char *at_ch; /* pointer to '@' */
  311.  
  312. +        EASSERT((info.attrmask.arr[1] & FATTR4_WORD1_OWNER) != 0);
  313. +        EASSERT((info.attrmask.arr[1] & FATTR4_WORD1_OWNER_GROUP) != 0);
  314. +        EASSERT(info.owner != NULL);
  315. +        EASSERT(info.owner_group != NULL);
  316. +        EASSERT(info.owner == info.owner_buf);
  317. +        EASSERT(info.owner_group == info.owner_group_buf);
  318. +        /* Make copies as we will modify  them */
  319. +        (void)strcpy(owner, info.owner);
  320. +        (void)strcpy(owner_group, info.owner_group);
  321. +
  322.          /*
  323.           * Map owner to local uid
  324.           *
  325. @@ -697,12 +686,12 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  326.           *  ("gisburn") or username@domain ("gisburn@sun.com")
  327.           */
  328.          /* stomp over '@' */
  329. -        if (at_ch = strchr(og_info.owner, '@'))
  330. +        if (at_ch = strchr(owner, '@'))
  331.              *at_ch = '\0';
  332.  
  333.          if (nfs41_idmap_name_to_ids(
  334.              nfs41dg->idmapper,
  335. -            og_info.owner,
  336. +            owner,
  337.              &map_uid,
  338.              &gid_dummy) == 0) {
  339.               args->owner_local_uid = map_uid;
  340. @@ -711,7 +700,7 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  341.              args->owner_local_uid = NFS_USER_NOBODY_UID;
  342.              eprintf("get_stat_data: "
  343.                  "no username mapping for '%s', fake uid=%d\n",
  344. -                og_info.owner, args->owner_local_uid);
  345. +                owner, args->owner_local_uid);
  346.          }
  347.  
  348.          /*
  349. @@ -721,12 +710,12 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  350.           * ("gisgrp") or username@domain ("gisgrp@sun.com")
  351.           */
  352.          /* stomp over '@' */
  353. -        if (at_ch = strchr(og_info.owner_group, '@'))
  354. +        if (at_ch = strchr(owner_group, '@'))
  355.              *at_ch = '\0';
  356.  
  357.          if (nfs41_idmap_group_to_gid(
  358.              nfs41dg->idmapper,
  359. -            og_info.owner_group,
  360. +            owner_group,
  361.              &map_gid) == 0) {
  362.              args->owner_group_local_gid = map_gid;
  363.          }
  364. @@ -734,12 +723,12 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  365.              args->owner_group_local_gid = NFS_GROUP_NOGROUP_GID;
  366.              eprintf("get_stat_data: "
  367.                  "no group mapping for '%s', fake gid=%d\n",
  368. -                og_info.owner_group, args->owner_group_local_gid);
  369. +                owner_group, args->owner_group_local_gid);
  370.          }
  371.  
  372.          dprintf(1, "handle_open: stat: owner=%u/'%s', owner_group=%u/'%s'\n",
  373. -            (unsigned int)args->owner_local_uid, og_info.owner,
  374. -            (unsigned int)args->owner_group_local_gid, og_info.owner_group);
  375. +            (unsigned int)args->owner_local_uid, owner,
  376. +            (unsigned int)args->owner_group_local_gid, owner_group);
  377.  #endif /* NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES */
  378.      } else {
  379.          nfs41_file_info createattrs = { 0 };
  380. diff --git a/daemon/util.c b/daemon/util.c
  381. index 35cfc5b..0b8cedf 100644
  382. --- a/daemon/util.c
  383. +++ b/daemon/util.c
  384. @@ -201,6 +201,16 @@ void nfs_to_network_openinfo(
  385.      net_out->FileAttributes = nfs_file_info_to_attributes(info);
  386.  }
  387.  
  388. +/* copy |nfs41_file_info| */
  389. +void nfs41_file_info_cpy(
  390. +    OUT nfs41_file_info *dest,
  391. +    IN const nfs41_file_info *src)
  392. +{
  393. +    (void)memcpy(dest, src, sizeof(nfs41_file_info));
  394. +    dest->owner = dest->owner_buf;
  395. +    dest->owner_group = dest->owner_group_buf;
  396. +}
  397. +
  398.  void get_file_time(
  399.      OUT PLARGE_INTEGER file_time)
  400.  {
  401. diff --git a/daemon/util.h b/daemon/util.h
  402. index fa0d32c..c4bc886 100644
  403. --- a/daemon/util.h
  404. +++ b/daemon/util.h
  405. @@ -106,6 +106,9 @@ void nfs_to_standard_info(
  406.  void nfs_to_network_openinfo(
  407.      IN const nfs41_file_info *info,
  408.      OUT PFILE_NETWORK_OPEN_INFORMATION std_out);
  409. +void nfs41_file_info_cpy(
  410. +    OUT nfs41_file_info *dest,
  411. +    IN const nfs41_file_info *src);
  412.  
  413.  /* http://msdn.microsoft.com/en-us/library/ms724290%28VS.85%29.aspx:
  414.   * A file time is a 64-bit value that represents the number of
  415. --
  416. 2.39.0

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