pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches for misc bugfixes, cleanup+misc, 2025-06-25
Posted by Anonymous on Wed 25th Jun 2025 18:41
raw | new post

  1. From ca59549c2228c2fa88eddac580c1bb8998ffc8e3 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Sat, 21 Jun 2025 15:28:09 +0200
  4. Subject: [PATCH 01/11] daemon: Fix DrMemory hit in |nfs41_open()|
  5.  
  6. Fix DrMemory hit in |nfs41_open()|.
  7.  
  8. Stack trace looks like this:
  9. ---- snip ----
  10. 0 nfs41_open                     [ms-nfs41-client\daemon\nfs41_ops.c:470]
  11. 1 nfs41_delegation_to_open       [ms-nfs41-client\daemon\delegation.c:589]
  12. 2 delegation_return              [ms-nfs41-client\daemon\delegation.c:306]
  13. 3 nfs41_delegation_return        [ms-nfs41-client\daemon\delegation.c:667]
  14. 4 handle_nfs41_setattr_basicinfo [ms-nfs41-client\daemon\setattr.c:160]
  15. 5 handle_setattr                 [ms-nfs41-client\daemon\setattr.c:661]
  16. 6 upcall_parse                   [ms-nfs41-client\daemon\upcall.c:179]
  17. 7 upcall_handle                  [ms-nfs41-client\daemon\upcall.c:205]
  18. 8 nfsd_worker_thread_main        [ms-nfs41-client\daemon\nfs41_daemon.c:209]
  19. ---- snip ----
  20.  
  21. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  22. ---
  23. daemon/delegation.c | 2 +-
  24.  1 file changed, 1 insertion(+), 1 deletion(-)
  25.  
  26. diff --git a/daemon/delegation.c b/daemon/delegation.c
  27. index efd2b20..3b29797 100644
  28. --- a/daemon/delegation.c
  29. +++ b/daemon/delegation.c
  30. @@ -547,7 +547,7 @@ int nfs41_delegation_to_open(
  31.      IN nfs41_open_state *open,
  32.      IN bool_t try_recovery)
  33.  {
  34. -    open_delegation4 ignore;
  35. +    open_delegation4 ignore = { 0 };
  36.      open_claim4 claim;
  37.      stateid4 open_stateid = { 0 };
  38.      stateid_arg deleg_stateid;
  39. --
  40. 2.45.1
  41.  
  42. From 1fa53ff17bc3e2454199ecf8a874da7616e65363 Mon Sep 17 00:00:00 2001
  43. From: Roland Mainz <roland.mainz@nrubsig.org>
  44. Date: Mon, 23 Jun 2025 13:59:30 +0200
  45. Subject: [PATCH 02/11] daemon: Define maximum number of ACE entries in an ACL
  46.  as |NFS41_ACL_MAX_ACE_ENTRIES|
  47.  
  48. Define maximum number of ACE entries in an ACL as
  49. |NFS41_ACL_MAX_ACE_ENTRIES|.
  50.  
  51. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  52. ---
  53. daemon/nfs41_const.h | 3 +++
  54.  daemon/nfs41_xdr.c   | 9 ++++++---
  55.  2 files changed, 9 insertions(+), 3 deletions(-)
  56.  
  57. diff --git a/daemon/nfs41_const.h b/daemon/nfs41_const.h
  58. index aa0fc29..ee9674a 100644
  59. --- a/daemon/nfs41_const.h
  60. +++ b/daemon/nfs41_const.h
  61. @@ -48,6 +48,9 @@
  62.   */
  63.  #define NFS4_FATTR4_OWNER_LIMIT (256)
  64.  
  65. +/* Maximum number of ACLs per file/dir */
  66. +#define NFS41_ACL_MAX_ACE_ENTRIES (32)
  67. +
  68.  #define NFS41_MAX_SERVER_CACHE  1024
  69.  #define NFS41_MAX_RPC_REQS      128
  70.  
  71. diff --git a/daemon/nfs41_xdr.c b/daemon/nfs41_xdr.c
  72. index bb77072..4ccbeaa 100644
  73. --- a/daemon/nfs41_xdr.c
  74. +++ b/daemon/nfs41_xdr.c
  75. @@ -325,7 +325,8 @@ static bool_t xdr_nfsdacl41(
  76.          return FALSE;
  77.  
  78.      return xdr_array(xdr, (char**)&acl->aces, &acl->count,
  79. -        32, sizeof(nfsace4), (xdrproc_t)xdr_nfsace4);
  80. +        NFS41_ACL_MAX_ACE_ENTRIES, sizeof(nfsace4),
  81. +        (xdrproc_t)xdr_nfsace4);
  82.  }
  83.  
  84.  static bool_t xdr_nfsacl41(
  85. @@ -333,7 +334,8 @@ static bool_t xdr_nfsacl41(
  86.      nfsacl41 *acl)
  87.  {
  88.      return xdr_array(xdr, (char**)&acl->aces, &acl->count,
  89. -        32, sizeof(nfsace4), (xdrproc_t)xdr_nfsace4);
  90. +        NFS41_ACL_MAX_ACE_ENTRIES, sizeof(nfsace4),
  91. +        (xdrproc_t)xdr_nfsace4);
  92.  }
  93.  
  94.  void nfsacl41_free(nfsacl41 *acl)
  95. @@ -1778,7 +1780,8 @@ static bool_t decode_file_attrs(
  96.          if (attrs->attrmask.arr[0] & FATTR4_WORD0_ACL) {
  97.              nfsacl41 *acl = info->acl;
  98.              if (!xdr_array(xdr, (char**)&acl->aces, &acl->count,
  99. -                32, sizeof(nfsace4), (xdrproc_t)xdr_nfsace4))
  100. +                NFS41_ACL_MAX_ACE_ENTRIES, sizeof(nfsace4),
  101. +                (xdrproc_t)xdr_nfsace4))
  102.                  return FALSE;
  103.          }
  104.          if (attrs->attrmask.arr[0] & FATTR4_WORD0_ACLSUPPORT) {
  105. --
  106. 2.45.1
  107.  
  108. From 9c55054c162498f139ca5f6485cd1b7a81b63dde Mon Sep 17 00:00:00 2001
  109. From: Roland Mainz <roland.mainz@nrubsig.org>
  110. Date: Mon, 23 Jun 2025 14:01:18 +0200
  111. Subject: [PATCH 03/11] daemon: Increase SID cache size to 128 to deal with
  112.  larger ACLs
  113.  
  114. Increase SID cache size to 128 to deal with larger ACLs
  115.  
  116. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  117. ---
  118. daemon/sid.c | 13 ++++++++++++-
  119.  1 file changed, 12 insertions(+), 1 deletion(-)
  120.  
  121. diff --git a/daemon/sid.c b/daemon/sid.c
  122. index 945f744..9e0e356 100644
  123. --- a/daemon/sid.c
  124. +++ b/daemon/sid.c
  125. @@ -220,9 +220,20 @@ bool unixgroup_sid2gid(PSID psid, gid_t *pgid)
  126.  
  127.  
  128.  #ifdef NFS41_DRIVER_SID_CACHE
  129. -#define SIDCACHE_SIZE 20
  130. +/*
  131. + * |SIDCACHE_SIZE| - size of SID cache
  132. + * We should at least use the maximum size of ACL entries plus { owner,
  133. + * owner_group, other, nobody, world, ... } entries multiplied by two to
  134. + * make sure two concurrent icacls queries cannot trash the whole cache
  135. + */
  136. +#define SIDCACHE_SIZE 128
  137.  #define SIDCACHE_TTL 600
  138.  
  139. +/* Safety/performance checks */
  140. +#if SIDCACHE_SIZE < ((NFS41_ACL_MAX_ACE_ENTRIES+8)*2)
  141. +#error SIDCACHE_SIZE should be at least ((NFS41_ACL_MAX_ACE_ENTRIES+8)*2)
  142. +#endif
  143. +
  144.  typedef struct _sidcache_entry
  145.  {
  146.  #define SIDCACHE_ENTRY_NAME_SIZE (UTF8_UNLEN + 1)
  147. --
  148. 2.45.1
  149.  
  150. From a9193dbc3f2e3e33ef5d4f7c061579f77e100f52 Mon Sep 17 00:00:00 2001
  151. From: Roland Mainz <roland.mainz@nrubsig.org>
  152. Date: Tue, 24 Jun 2025 12:45:02 +0200
  153. Subject: [PATCH 04/11] libtirpc: Expose libtirpc.dll allocator as external API
  154.  
  155. Expose libtirpc.dll allocator as external API.
  156.  
  157. Windows allows DLLs and EXE to have their own memory allocators
  158. (instances, e.g. multiple CRT allocators using all the same process
  159. heap, or another heap=, so we have to provide an API to allocate
  160. and free memofy using this allocator.
  161.  
  162. Otherwise we get memory corruption if we allocate with one memory
  163. allocator (instance), but free with a different one.
  164.  
  165. FIXME: This should really be part of the libtirpc API
  166.  
  167. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  168. ---
  169. libtirpc/libtirpc/libtirpc.def |  2 ++
  170.  libtirpc/src/wintirpc.c        | 20 ++++++++++++++++++++
  171.  libtirpc/tirpc/wintirpc.h      |  2 ++
  172.  3 files changed, 24 insertions(+)
  173.  
  174. diff --git a/libtirpc/libtirpc/libtirpc.def b/libtirpc/libtirpc/libtirpc.def
  175. index 6509655..ba5ce3e 100644
  176. --- a/libtirpc/libtirpc/libtirpc.def
  177. +++ b/libtirpc/libtirpc/libtirpc.def
  178. @@ -46,6 +46,8 @@ svcudp_create
  179.  taddr2uaddr
  180.  tsd_key_delete
  181.  uaddr2taddr
  182. +wintirpc_mem_alloc
  183. +wintirpc_mem_free
  184.  xdr_array
  185.  xdr_authunix_parms
  186.  xdr_bool
  187. diff --git a/libtirpc/src/wintirpc.c b/libtirpc/src/wintirpc.c
  188. index 836c321..d9f4d4c 100644
  189. --- a/libtirpc/src/wintirpc.c
  190. +++ b/libtirpc/src/wintirpc.c
  191. @@ -536,6 +536,26 @@ void wintirpc_warnx(const char *format, ...)
  192.      va_end(args);
  193.  }
  194.  
  195. +/*
  196. + * Windows allows DLLs and EXE to have their own memory allocators, so we
  197. + * have to provide an API to allocate and free memofy using this allocator
  198. + *
  199. + * FIXME: This should really be part of the libtirpc API
  200. + */
  201. +void *wintirpc_mem_alloc(size_t s)
  202. +{
  203. +    /*
  204. +     * |mem_alloc()| is a macro which uses |calloc()|, therefore we
  205. +     * use |malloc()| here directly
  206. +     */
  207. +    return malloc(s);
  208. +}
  209. +
  210. +void wintirpc_mem_free(void *p)
  211. +{
  212. +    free(p);
  213. +}
  214. +
  215.  int tirpc_exit(void)
  216.  {
  217.         if (init == 0 || --init > 0)
  218. diff --git a/libtirpc/tirpc/wintirpc.h b/libtirpc/tirpc/wintirpc.h
  219. index 878bed0..1649764 100644
  220. --- a/libtirpc/tirpc/wintirpc.h
  221. +++ b/libtirpc/tirpc/wintirpc.h
  222. @@ -163,6 +163,8 @@ int wintirpc_setsockopt(int socket, int level, int option_name,
  223.  void wintirpc_setnfsclientsockopts(int sock);
  224.  void wintirpc_syslog(int prio, const char *format, ...);
  225.  void wintirpc_warnx(const char *format, ...);
  226. +void *wintirpc_mem_alloc(size_t s);
  227. +void wintirpc_mem_free(void *p);
  228.  void wintirpc_register_osfhandle_fd(SOCKET handle, int fd);
  229.  void wintirpc_unregister_osfhandle(SOCKET handle);
  230.  void wintirpc_unregister_osf_fd(int fd);
  231. --
  232. 2.45.1
  233.  
  234. From 82e27f050fcfc6243a30229329d3fb8f3c1fb230 Mon Sep 17 00:00:00 2001
  235. From: Roland Mainz <roland.mainz@nrubsig.org>
  236. Date: Wed, 25 Jun 2025 10:23:18 +0200
  237. Subject: [PATCH 05/11] daemon: Provide |bitmap_or()| function to OR two
  238.  |bitmap4| variables
  239.  
  240. Provide |bitmap_or()| function to logically OR two |bitmap4|
  241. variables.
  242.  
  243. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  244. ---
  245. daemon/util.h | 12 ++++++++++++
  246.  1 file changed, 12 insertions(+)
  247.  
  248. diff --git a/daemon/util.h b/daemon/util.h
  249. index 011d411..058da7b 100644
  250. --- a/daemon/util.h
  251. +++ b/daemon/util.h
  252. @@ -132,6 +132,18 @@ static __inline void bitmap_intersect(
  253.      }
  254.      dst->count = min(dst->count, count);
  255.  }
  256. +static __inline void bitmap_or(
  257. +    IN bitmap4 *restrict dst,
  258. +    IN const bitmap4 *restrict src)
  259. +{
  260. +    uint32_t i, count = 0;
  261. +    for (i = 0; i < 3; i++) {
  262. +        dst->arr[i] = ((i < dst->count)?dst->arr[i]:0) | ((i < src->count)?src->arr[i]:0);
  263. +        if (dst->arr[i])
  264. +            count = i+1;
  265. +    }
  266. +    dst->count = min(dst->count, count);
  267. +}
  268.  
  269.  static __inline void bitmap4_cpy(
  270.      OUT bitmap4 *restrict dst,
  271. --
  272. 2.45.1
  273.  
  274. From 76c56cd8a941a557be684eae871c2a38f611f71e Mon Sep 17 00:00:00 2001
  275. From: Roland Mainz <roland.mainz@nrubsig.org>
  276. Date: Wed, 25 Jun 2025 10:37:45 +0200
  277. Subject: [PATCH 06/11] daemon: |bitmap_*()| functions should use
  278.  |BITMAP4_MAXCOUNT| instead of |3|
  279.  
  280. |bitmap_*()| functions should use |BITMAP4_MAXCOUNT| instead of |3|
  281.  
  282. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  283. ---
  284. daemon/util.h | 4 ++--
  285.  1 file changed, 2 insertions(+), 2 deletions(-)
  286.  
  287. diff --git a/daemon/util.h b/daemon/util.h
  288. index 058da7b..6938372 100644
  289. --- a/daemon/util.h
  290. +++ b/daemon/util.h
  291. @@ -125,7 +125,7 @@ static __inline void bitmap_intersect(
  292.      IN const bitmap4 *restrict src)
  293.  {
  294.      uint32_t i, count = 0;
  295. -    for (i = 0; i < 3; i++) {
  296. +    for (i = 0; i < BITMAP4_MAXCOUNT; i++) {
  297.          dst->arr[i] = ((i < dst->count)?dst->arr[i]:0) & ((i < src->count)?src->arr[i]:0);
  298.          if (dst->arr[i])
  299.              count = i+1;
  300. @@ -137,7 +137,7 @@ static __inline void bitmap_or(
  301.      IN const bitmap4 *restrict src)
  302.  {
  303.      uint32_t i, count = 0;
  304. -    for (i = 0; i < 3; i++) {
  305. +    for (i = 0; i < BITMAP4_MAXCOUNT; i++) {
  306.          dst->arr[i] = ((i < dst->count)?dst->arr[i]:0) | ((i < src->count)?src->arr[i]:0);
  307.          if (dst->arr[i])
  308.              count = i+1;
  309. --
  310. 2.45.1
  311.  
  312. From e6a26a6ec277782dadca5b03b02ce800377d43cc Mon Sep 17 00:00:00 2001
  313. From: Roland Mainz <roland.mainz@nrubsig.org>
  314. Date: Wed, 25 Jun 2025 18:09:54 +0200
  315. Subject: [PATCH 07/11] daemon: |nfs41_cached_getattr()| should have an
  316.  argument to ask for extra attributes
  317.  
  318. |nfs41_cached_getattr()| should have an argument to ask for extra
  319. attributes-
  320.  
  321. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  322. ---
  323. daemon/acl.c       | 72 +++++++++++++++++++---------------------------
  324.  daemon/getattr.c   | 27 +++++++++++++++--
  325.  daemon/nfs41_ops.c | 42 +++++++++++++--------------
  326.  daemon/nfs41_ops.h |  1 +
  327.  daemon/open.c      |  2 +-
  328.  daemon/readdir.c   |  6 ++--
  329.  daemon/setattr.c   |  2 +-
  330.  7 files changed, 79 insertions(+), 73 deletions(-)
  331.  
  332. diff --git a/daemon/acl.c b/daemon/acl.c
  333. index 370f2d3..3e00c4f 100644
  334. --- a/daemon/acl.c
  335. +++ b/daemon/acl.c
  336. @@ -326,62 +326,47 @@ static int handle_getacl(void *daemon_context, nfs41_upcall *upcall)
  337.      PSID osid = NULL, gsid = NULL;
  338.      DWORD sid_len;
  339.      char owner[NFS4_FATTR4_OWNER_LIMIT+1], group[NFS4_FATTR4_OWNER_LIMIT+1];
  340. +    bitmap4 owner_group_acl_bitmap = {
  341. +        .count = 2,
  342. +        .arr[0] = 0,
  343. +        .arr[1] = FATTR4_WORD1_OWNER|FATTR4_WORD1_OWNER_GROUP
  344. +    };
  345.      nfsacl41 acl = { 0 };
  346.  
  347.      DPRINTF(ACLLVL1, ("--> handle_getacl(state->path.path='%s')\n",
  348.          state->path.path));
  349.  
  350.      if (args->query & DACL_SECURITY_INFORMATION) {
  351. -use_nfs41_getattr:
  352. -        bitmap4 attr_request = { 0 };
  353. -        (void)memset(&info, 0, sizeof(nfs41_file_info));
  354. -        info.owner = owner;
  355. -        info.owner_group = group;
  356. -
  357. -        attr_request.count = 2;
  358. -        attr_request.arr[0] = FATTR4_WORD0_ACL;
  359. -        attr_request.arr[1] = FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
  360. -        info.acl = &acl;
  361. -        status = nfs41_getattr(state->session, &state->file, &attr_request, &info);
  362. -        if (status) {
  363. -            eprintf("handle_getacl: nfs41_getattr() failed with %d\n",
  364. -                status);
  365. -            goto out;
  366. -        }
  367. +        owner_group_acl_bitmap.arr[0] |= FATTR4_WORD0_ACL;
  368.      }
  369. -    else {
  370. -        (void)memset(&info, 0, sizeof(nfs41_file_info));
  371. -        info.owner = owner;
  372. -        info.owner_group = group;
  373.  
  374. -        status = nfs41_cached_getattr(state->session, &state->file, &info);
  375. -        if (status) {
  376. -            eprintf("handle_getacl: nfs41_cached_getattr() failed with %d\n",
  377. -                status);
  378. -            goto out;
  379. -        }
  380. +    (void)memset(&info, 0, sizeof(nfs41_file_info));
  381. +    info.owner = owner;
  382. +    info.owner_group = group;
  383. +    info.acl = &acl;
  384.  
  385. -        EASSERT(info.attrmask.count > 1);
  386. -
  387. -        /*
  388. -         * In rare cases owner/owner_group are not in the cache
  389. -         * (usually for new files). In this case do a full
  390. -         * roundtrip to the NFS server to get the data...
  391. -         */
  392. -        if ((bitmap_isset(&info.attrmask, 1,
  393. -                FATTR4_WORD1_OWNER) == false) ||
  394. -            (bitmap_isset(&info.attrmask, 1,
  395. -                FATTR4_WORD1_OWNER_GROUP) == false)) {
  396. -            DPRINTF(ACLLVL2, ("handle_getattr: owner/owner_group not in cache, doing full lookup...\n"));
  397. -            goto use_nfs41_getattr;
  398. -        }
  399. +    /*
  400. +     * |nfs41_cached_getattr()| will first try to get all information from
  401. +     * the cache. But if bits are missing (e.g. |FATTR4_WORD0_ACL|, then
  402. +     * this will do a server roundtrip to get the missing data
  403. +     */
  404. +    status = nfs41_cached_getattr(state->session,
  405. +        &state->file, &owner_group_acl_bitmap, &info);
  406. +    if (status) {
  407. +        eprintf("handle_getacl: nfs41_cached_getattr() failed with %d\n",
  408. +            status);
  409. +        goto out;
  410.      }
  411.  
  412.      EASSERT(info.attrmask.count > 1);
  413. -    EASSERT(bitmap_isset(&info.attrmask, 1, FATTR4_WORD1_OWNER) &&
  414. -        bitmap_isset(&info.attrmask, 1, FATTR4_WORD1_OWNER_GROUP));
  415.      if (args->query & DACL_SECURITY_INFORMATION) {
  416. -        EASSERT(bitmap_isset(&info.attrmask, 0, FATTR4_WORD0_ACL));
  417. +        EASSERT(bitmap_isset(&info.attrmask, 0, FATTR4_WORD0_ACL) == true);
  418. +    }
  419. +    if (args->query & OWNER_SECURITY_INFORMATION) {
  420. +        EASSERT(bitmap_isset(&info.attrmask, 1, FATTR4_WORD1_OWNER) == true);
  421. +    }
  422. +    if (args->query & GROUP_SECURITY_INFORMATION) {
  423. +        EASSERT(bitmap_isset(&info.attrmask, 1, FATTR4_WORD1_OWNER_GROUP) == true);
  424.      }
  425.  
  426.      status = InitializeSecurityDescriptor(&sec_desc,
  427. @@ -433,6 +418,7 @@ use_nfs41_getattr:
  428.              goto out;
  429.          }
  430.      }
  431. +
  432.      if (args->query & DACL_SECURITY_INFORMATION) {
  433.          DPRINTF(ACLLVL2, ("handle_getacl: DACL_SECURITY_INFORMATION\n"));
  434.          status = convert_nfs4acl_2_dacl(nfs41dg,
  435. diff --git a/daemon/getattr.c b/daemon/getattr.c
  436. index 7c8b2d1..752a31b 100644
  437. --- a/daemon/getattr.c
  438. +++ b/daemon/getattr.c
  439. @@ -37,19 +37,40 @@
  440.  int nfs41_cached_getattr(
  441.      IN nfs41_session *session,
  442.      IN nfs41_path_fh *file,
  443. +    IN OPTIONAL bitmap4 *extra_attr_request,
  444.      OUT nfs41_file_info *info)
  445.  {
  446.      int status;
  447. +    bool bits_missing = false;
  448.  
  449.      /* first look for cached attributes */
  450.      status = nfs41_attr_cache_lookup(session_name_cache(session),
  451.          file->fh.fileid, info);
  452.  
  453. -    if (status) {
  454. +    if ((status == 0) && extra_attr_request) {
  455. +        uint32_t i;
  456. +
  457. +        /* Check if bits are missing... */
  458. +        for (i=0 ; i < extra_attr_request->count ; i++) {
  459. +            if ((extra_attr_request->arr[i] != 0) &&
  460. +                ((((i < info->attrmask.count)?(info->attrmask.arr[i]):0) &
  461. +                    extra_attr_request->arr[i]) == 0)) {
  462. +                bits_missing = true;
  463. +                DPRINTF(1, ("nfs41_cached_getattr: bits missing %d\n", i));
  464. +                break;
  465. +            }
  466. +        }
  467. +    }
  468. +
  469. +    if (status || bits_missing) {
  470.          /* fetch attributes from the server */
  471.          bitmap4 attr_request;
  472.          nfs41_superblock_getattr_mask(file->fh.superblock, &attr_request);
  473.  
  474. +        if (extra_attr_request) {
  475. +            bitmap_or(&attr_request, extra_attr_request);
  476. +        }
  477. +
  478.          status = nfs41_getattr(session, file, &attr_request, info);
  479.          if (status) {
  480.              eprintf("nfs41_cached_getattr: "
  481. @@ -88,7 +109,7 @@ static int handle_getattr(void *daemon_context, nfs41_upcall *upcall)
  482.      nfs41_open_state *state = upcall->state_ref;
  483.      nfs41_file_info info = { 0 };
  484.  
  485. -    status = nfs41_cached_getattr(state->session, &state->file, &info);
  486. +    status = nfs41_cached_getattr(state->session, &state->file, NULL, &info);
  487.      if (status) {
  488.          eprintf("handle_getattr(state->path.path='%s'): "
  489.              "nfs41_cached_getattr() failed with %d\n",
  490. @@ -98,7 +119,7 @@ static int handle_getattr(void *daemon_context, nfs41_upcall *upcall)
  491.      }
  492.  
  493.      if (info.type == NF4LNK) {
  494. -        nfs41_file_info target_info;
  495. +        nfs41_file_info target_info = { 0 };
  496.          int target_status = nfs41_symlink_follow(upcall->root_ref,
  497.              state->session, &state->file, &target_info);
  498.          if (target_status == NO_ERROR) {
  499. diff --git a/daemon/nfs41_ops.c b/daemon/nfs41_ops.c
  500. index 862ce0e..0f890e7 100644
  501. --- a/daemon/nfs41_ops.c
  502. +++ b/daemon/nfs41_ops.c
  503. @@ -1478,28 +1478,26 @@ int nfs41_setattr(
  504.  
  505.      nfs41_superblock_getattr_mask(file->fh.superblock, &attr_request);
  506.  
  507. -    if (info->attrmask.count >= 2) {
  508. -        /*
  509. -         * If we set owner and/or owner_group make sure we ask
  510. -         * the server to send the values back for two reasons:
  511. -         * 1, Handle cases like "all_squash" (e.g. nfsd turns
  512. -         * owner/owner_group always into "nobody"/"nogroup")
  513. -         * 2. Make sure we update the name cache with the new
  514. -         * owner/owner_group
  515. -         *
  516. -         * Note that this can be a bit tricky as we might pass
  517. -         * a "name@domain" string to the server, but get a numeric
  518. -         * uid/gid as strings back, which means the name cache
  519. -         * might have both representations.
  520. -         */
  521. -        if (info->attrmask.arr[1] & FATTR4_WORD1_OWNER) {
  522. -            attr_request.count = 2;
  523. -            attr_request.arr[1] |= FATTR4_WORD1_OWNER;
  524. -        }
  525. -        if (info->attrmask.arr[1] & FATTR4_WORD1_OWNER_GROUP) {
  526. -            attr_request.count = 2;
  527. -            attr_request.arr[1] |= FATTR4_WORD1_OWNER_GROUP;
  528. -        }
  529. +    /*
  530. +     * If we set owner and/or owner_group make sure we ask
  531. +     * the server to send the values back for two reasons:
  532. +     * 1, Handle cases like "all_squash" (e.g. nfsd turns
  533. +     * owner/owner_group always into "nobody"/"nogroup")
  534. +     * 2. Make sure we update the name cache with the new
  535. +     * owner/owner_group
  536. +     *
  537. +     * Note that this can be a bit tricky as we might pass
  538. +     * a "name@domain" string to the server, but get a numeric
  539. +     * uid/gid as strings back, which means the name cache
  540. +     * might have both representations.
  541. +     */
  542. +    if (bitmap_isset(&info->attrmask, 1, FATTR4_WORD1_OWNER)) {
  543. +        attr_request.count = __max(attr_request.count, 2);
  544. +        attr_request.arr[1] |= FATTR4_WORD1_OWNER;
  545. +    }
  546. +    if (bitmap_isset(&info->attrmask, 1, FATTR4_WORD1_OWNER_GROUP)) {
  547. +        attr_request.count = __max(attr_request.count, 2);
  548. +        attr_request.arr[1] |= FATTR4_WORD1_OWNER_GROUP;
  549.      }
  550.  
  551.      compound_add_op(&compound, OP_GETATTR, &getattr_args, &getattr_res);
  552. diff --git a/daemon/nfs41_ops.h b/daemon/nfs41_ops.h
  553. index f57f8dc..91cb766 100644
  554. --- a/daemon/nfs41_ops.h
  555. +++ b/daemon/nfs41_ops.h
  556. @@ -1331,6 +1331,7 @@ int nfs41_superblock_getattr(
  557.  int nfs41_cached_getattr(
  558.      IN nfs41_session *session,
  559.      IN nfs41_path_fh *file,
  560. +    IN OPTIONAL bitmap4 *extra_attr_request,
  561.      OUT nfs41_file_info *info);
  562.  
  563.  int nfs41_remove(
  564. diff --git a/daemon/open.c b/daemon/open.c
  565. index aeaae11..2ba788a 100644
  566. --- a/daemon/open.c
  567. +++ b/daemon/open.c
  568. @@ -867,7 +867,7 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  569.              if (args->create_opts & FILE_OPEN_REPARSE_POINT) {
  570.                  /* continue and open the symlink itself, but we need to
  571.                   * know if the target is a regular file or directory */
  572. -                nfs41_file_info target_info;
  573. +                nfs41_file_info target_info = { 0 };
  574.                  int target_status = nfs41_symlink_follow(upcall->root_ref,
  575.                      state->session, &state->file, &target_info);
  576.                  if (target_status == NO_ERROR) {
  577. diff --git a/daemon/readdir.c b/daemon/readdir.c
  578. index f3564bf..a754197 100644
  579. --- a/daemon/readdir.c
  580. +++ b/daemon/readdir.c
  581. @@ -515,7 +515,7 @@ static int lookup_symlink(
  582.  {
  583.      nfs41_abs_path path;
  584.      nfs41_path_fh file;
  585. -    nfs41_file_info info;
  586. +    nfs41_file_info info = { 0 };
  587.      int status;
  588.  
  589.      status = format_abs_path(parent->path, name, &path);
  590. @@ -686,7 +686,7 @@ static int readdir_add_dots(
  591.          ZeroMemory(&entry->attr_info, sizeof(nfs41_file_info));
  592.  
  593.          status = nfs41_cached_getattr(state->session,
  594. -            &state->file, &entry->attr_info);
  595. +            &state->file, NULL, &entry->attr_info);
  596.          if (status) {
  597.              DPRINTF(0, ("readdir_add_dots: failed to add '.' entry.\n"));
  598.              goto out;
  599. @@ -719,7 +719,7 @@ static int readdir_add_dots(
  600.          ZeroMemory(&entry->attr_info, sizeof(nfs41_file_info));
  601.  
  602.          status = nfs41_cached_getattr(state->session,
  603. -            &state->parent, &entry->attr_info);
  604. +            &state->parent, NULL, &entry->attr_info);
  605.          if (status) {
  606.              status = ERROR_FILE_NOT_FOUND;
  607.              DPRINTF(0, ("readdir_add_dots: failed to add '..' entry.\n"));
  608. diff --git a/daemon/setattr.c b/daemon/setattr.c
  609. index 1e2bfdd..a994548 100644
  610. --- a/daemon/setattr.c
  611. +++ b/daemon/setattr.c
  612. @@ -71,7 +71,7 @@ static int handle_nfs41_setattr_basicinfo(void *daemon_context, setattr_upcall_a
  613.      (void)memset(&old_info, 0, sizeof(old_info));
  614.  
  615.      getattr_status = nfs41_cached_getattr(state->session,
  616. -        &state->file, &old_info);
  617. +        &state->file, NULL, &old_info);
  618.      if (getattr_status) {
  619.          DPRINTF(0, ("handle_nfs41_setattr_basicinfo(args->path='%s'): "
  620.              "nfs41_cached_getattr() failed with error %d.\n",
  621. --
  622. 2.45.1
  623.  
  624. From c04b82bea610e00d19f4a56108b2ca59d8f0aec4 Mon Sep 17 00:00:00 2001
  625. From: Roland Mainz <roland.mainz@nrubsig.org>
  626. Date: Wed, 25 Jun 2025 18:15:29 +0200
  627. Subject: [PATCH 08/11] daemon: |UTIL_GETRELTIME()| should use |ULL|, not |UL|
  628.  
  629. |UTIL_GETRELTIME()| should use |ULL|, not |UL|
  630.  
  631. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  632. ---
  633. daemon/util.h | 2 +-
  634.  1 file changed, 1 insertion(+), 1 deletion(-)
  635.  
  636. diff --git a/daemon/util.h b/daemon/util.h
  637. index 6938372..3f640cc 100644
  638. --- a/daemon/util.h
  639. +++ b/daemon/util.h
  640. @@ -47,7 +47,7 @@ enum stable_how4;
  641.   * so hibernation longer than |NAME_CACHE_EXPIRATION| will
  642.   * automagically invalidate the cache
  643.   */
  644. -#define UTIL_GETRELTIME() (GetTickCount64()/1000UL)
  645. +#define UTIL_GETRELTIME() (GetTickCount64()/1000ULL)
  646.  #define UTIL_DIFFRELTIME(t1, t2) \
  647.      (((signed long long)(t1))-((signed long long)(t2)))
  648.  typedef ULONGLONG util_reltimestamp;
  649. --
  650. 2.45.1
  651.  
  652. From df9681d5919093091ce8400cdabd2fc72100f196 Mon Sep 17 00:00:00 2001
  653. From: Roland Mainz <roland.mainz@nrubsig.org>
  654. Date: Wed, 25 Jun 2025 18:50:17 +0200
  655. Subject: [PATCH 09/11] daemon: Use |__max()| to adjust the |bitmap4.count| for
  656.  additional attributes
  657.  
  658. Use |__max()| to adjust the |bitmap4.count| for additional attributes.
  659.  
  660. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  661. ---
  662. daemon/acl.c     |  7 +++----
  663.  daemon/setattr.c | 18 +++++++++---------
  664.  2 files changed, 12 insertions(+), 13 deletions(-)
  665.  
  666. diff --git a/daemon/acl.c b/daemon/acl.c
  667. index 3e00c4f..0a54edc 100644
  668. --- a/daemon/acl.c
  669. +++ b/daemon/acl.c
  670. @@ -1391,7 +1391,7 @@ static int handle_setacl(void *daemon_context, nfs41_upcall *upcall)
  671.  
  672.          info.owner = ownerbuf;
  673.          info.attrmask.arr[1] |= FATTR4_WORD1_OWNER;
  674. -        info.attrmask.count = 2;
  675. +        info.attrmask.count = __max(info.attrmask.count, 2);
  676.  
  677.          EASSERT_MSG(info.owner[0] != '\0',
  678.              ("info.owner='%s'\n", info.owner));
  679. @@ -1413,7 +1413,7 @@ static int handle_setacl(void *daemon_context, nfs41_upcall *upcall)
  680.  
  681.          info.owner_group = groupbuf;
  682.          info.attrmask.arr[1] |= FATTR4_WORD1_OWNER_GROUP;
  683. -        info.attrmask.count = 2;
  684. +        info.attrmask.count = __max(info.attrmask.count, 2);
  685.  
  686.          EASSERT_MSG(info.owner_group[0] != '\0',
  687.              ("info.owner_group='%s'\n", info.owner_group));
  688. @@ -1451,8 +1451,7 @@ static int handle_setacl(void *daemon_context, nfs41_upcall *upcall)
  689.  
  690.          info.acl = &nfs4_acl;
  691.          info.attrmask.arr[0] |= FATTR4_WORD0_ACL;
  692. -        if (!info.attrmask.count)
  693. -            info.attrmask.count = 1;
  694. +        info.attrmask.count = __max(info.attrmask.count, 1);
  695.      }
  696.  
  697.      /* break read delegations before SETATTR */
  698. diff --git a/daemon/setattr.c b/daemon/setattr.c
  699. index a994548..2a87332 100644
  700. --- a/daemon/setattr.c
  701. +++ b/daemon/setattr.c
  702. @@ -87,15 +87,15 @@ static int handle_nfs41_setattr_basicinfo(void *daemon_context, setattr_upcall_a
  703.  
  704.          if (info.hidden != old_info.hidden) {
  705.              info.attrmask.arr[0] |= FATTR4_WORD0_HIDDEN;
  706. -            info.attrmask.count = 1;
  707. +            info.attrmask.count = __max(info.attrmask.count, 1);
  708.          }
  709.          if (info.archive != old_info.archive) {
  710.              info.attrmask.arr[0] |= FATTR4_WORD0_ARCHIVE;
  711. -            info.attrmask.count = 1;
  712. +            info.attrmask.count = __max(info.attrmask.count, 1);
  713.          }
  714.          if (info.system != old_info.system) {
  715.              info.attrmask.arr[1] |= FATTR4_WORD1_SYSTEM;
  716. -            info.attrmask.count = 2;
  717. +            info.attrmask.count = __max(info.attrmask.count, 2);
  718.          }
  719.  
  720.          EASSERT_MSG(((basic_info->FileAttributes & FILE_ATTRIBUTE_EA) == 0),
  721. @@ -112,13 +112,13 @@ static int handle_nfs41_setattr_basicinfo(void *daemon_context, setattr_upcall_a
  722.      if (basic_info->FileAttributes & FILE_ATTRIBUTE_READONLY) {
  723.          info.mode = 0444;
  724.          info.attrmask.arr[1] |= FATTR4_WORD1_MODE;
  725. -        info.attrmask.count = 2;
  726. +        info.attrmask.count = __max(info.attrmask.count, 2);
  727.      }
  728.      else {
  729.          if (old_info.mode == 0444) {
  730.              info.mode = 0644;
  731.              info.attrmask.arr[1] |= FATTR4_WORD1_MODE;
  732. -            info.attrmask.count = 2;
  733. +            info.attrmask.count = __max(info.attrmask.count, 2);
  734.          }
  735.      }
  736.  
  737. @@ -132,28 +132,28 @@ static int handle_nfs41_setattr_basicinfo(void *daemon_context, setattr_upcall_a
  738.              file_time_to_nfs_time(&basic_info->CreationTime,
  739.                  &info.time_create);
  740.              info.attrmask.arr[1] |= FATTR4_WORD1_TIME_CREATE;
  741. -            info.attrmask.count = 2;
  742. +            info.attrmask.count = __max(info.attrmask.count, 2);
  743.          }
  744.          /* time_access_set */
  745.          if (basic_info->LastAccessTime.QuadPart > 0) {
  746.              file_time_to_nfs_time(&basic_info->LastAccessTime,
  747.                  &info.time_access);
  748.              info.attrmask.arr[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
  749. -            info.attrmask.count = 2;
  750. +            info.attrmask.count = __max(info.attrmask.count, 2);
  751.          }
  752.          /* time_modify_set */
  753.          if (basic_info->LastWriteTime.QuadPart > 0) {
  754.              file_time_to_nfs_time(&basic_info->LastWriteTime,
  755.                  &info.time_modify);
  756.              info.attrmask.arr[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
  757. -            info.attrmask.count = 2;
  758. +            info.attrmask.count = __max(info.attrmask.count, 2);
  759.          }
  760.      }
  761.  
  762.      /* mask out unsupported attributes */
  763.      nfs41_superblock_supported_attrs(superblock, &info.attrmask);
  764.  
  765. -    if (!info.attrmask.count)
  766. +    if (info.attrmask.count == 0)
  767.          goto out;
  768.  
  769.      /* break read delegations before SETATTR */
  770. --
  771. 2.45.1
  772.  
  773. From 4953fd90c04d469ca09ff7d422a382ce349c5000 Mon Sep 17 00:00:00 2001
  774. From: Roland Mainz <roland.mainz@nrubsig.org>
  775. Date: Wed, 25 Jun 2025 18:53:22 +0200
  776. Subject: [PATCH 10/11] daemon: Use |bitmap_isset()| instead of "manual"
  777.  testing
  778.  
  779. Use |bitmap_isset()| instead of "manual" testing.
  780.  
  781. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  782. ---
  783. daemon/nfs41_ops.c | 9 ++++-----
  784.  1 file changed, 4 insertions(+), 5 deletions(-)
  785.  
  786. diff --git a/daemon/nfs41_ops.c b/daemon/nfs41_ops.c
  787. index 0f890e7..ba412a0 100644
  788. --- a/daemon/nfs41_ops.c
  789. +++ b/daemon/nfs41_ops.c
  790. @@ -1457,7 +1457,7 @@ int nfs41_setattr(
  791.      nfs41_putfh_args putfh_args;
  792.      nfs41_putfh_res putfh_res;
  793.      nfs41_setattr_args setattr_args;
  794. -    nfs41_setattr_res setattr_res;
  795. +    nfs41_setattr_res setattr_res = { 0 };
  796.      nfs41_getattr_args getattr_args;
  797.      nfs41_getattr_res getattr_res NDSH(= { 0 });
  798.      bitmap4 attr_request;
  799. @@ -1516,11 +1516,10 @@ int nfs41_setattr(
  800.      nfs41_attr_cache_update(session_name_cache(session),
  801.          file->fh.fileid, info);
  802.  
  803. -    if (((setattr_res.attrsset.count > 0) &&
  804. -            (setattr_res.attrsset.arr[0] & FATTR4_WORD0_SIZE)) ||
  805. -        ((setattr_res.attrsset.count > 1) &&
  806. -            (setattr_res.attrsset.arr[1] & FATTR4_WORD1_SPACE_USED)))
  807. +    if (bitmap_isset(&setattr_res.attrsset, 0, FATTR4_WORD0_SIZE) ||
  808. +        bitmap_isset(&setattr_res.attrsset, 1, FATTR4_WORD1_SPACE_USED)) {
  809.          nfs41_superblock_space_changed(file->fh.superblock);
  810. +    }
  811.  out:
  812.      return status;
  813.  }
  814. --
  815. 2.45.1
  816.  
  817. From 532b3886824dc483308d353a163d07bd32a2aa67 Mon Sep 17 00:00:00 2001
  818. From: Roland Mainz <roland.mainz@nrubsig.org>
  819. Date: Wed, 25 Jun 2025 19:06:47 +0200
  820. Subject: [PATCH 11/11] daemon: Fix use of wrong var from commit
  821.  'daemon,nfs41_build_features.h: Add build option to treat unresolveable
  822.  symlinks as symdirs'
  823.  
  824. Fix use of wrong variable from commit 'daemon,nfs41_build_features.h:
  825. Add build option to treat unresolveable symlinks as symdirs'
  826.  
  827. Reported-by: Aurelien Couderc <aurelien.couderc2002@gmail.com>
  828. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  829. ---
  830. daemon/open.c | 4 ++--
  831.  1 file changed, 2 insertions(+), 2 deletions(-)
  832.  
  833. diff --git a/daemon/open.c b/daemon/open.c
  834. index 2ba788a..ac7d102 100644
  835. --- a/daemon/open.c
  836. +++ b/daemon/open.c
  837. @@ -875,9 +875,9 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
  838.                  }
  839.                  else {
  840.  #ifdef NFS41_DRIVER_TREAT_UNRESOLVEABLE_SYMLINKS_AS_DIRS
  841. -                    target_info.type = TRUE;
  842. +                    info.symlink_dir = TRUE;
  843.  #else
  844. -                    target_info.type = FALSE;
  845. +                    info.symlink_dir = FALSE;
  846.  #endif /* NFS41_DRIVER_TREAT_UNRESOLVEABLE_SYMLINKS_AS_DIRS */
  847.                  }
  848.              } else {
  849. --
  850. 2.45.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