pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch for flushing src buffers before cloning, cleanup+misc, 2025-09-22
Posted by Anonymous on Mon 22nd Sep 2025 15:00
raw | new post

  1. From 3c2f4639ffd39aec610e631a70a95af633c65e24 Mon Sep 17 00:00:00 2001
  2. From: Dan Shelton <dan.f.shelton@gmail.com>
  3. Date: Mon, 22 Sep 2025 11:29:24 +0200
  4. Subject: [PATCH 1/4] sys: |nfs41_UpcallDestroy()| should clear event per
  5.  Windows API spec
  6.  
  7. |nfs41_UpcallDestroy()| should clear event per Windows API spec.
  8.  
  9. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  10. ---
  11. sys/nfs41sys_updowncall.c | 2 ++
  12.  1 file changed, 2 insertions(+)
  13.  
  14. diff --git a/sys/nfs41sys_updowncall.c b/sys/nfs41sys_updowncall.c
  15. index f629266..749d892 100644
  16. --- a/sys/nfs41sys_updowncall.c
  17. +++ b/sys/nfs41sys_updowncall.c
  18. @@ -497,6 +497,8 @@ void nfs41_UpcallDestroy(nfs41_updowncall_entry *entry)
  19.      }
  20.  #endif /* _DEBUG */
  21.  
  22. +    KeClearEvent(&entry->cond);
  23. +
  24.      if (entry->psec_ctx_clienttoken) {
  25.          ObDereferenceObject(entry->psec_ctx_clienttoken);
  26.      }
  27. --
  28. 2.51.0
  29.  
  30. From f38099d996d0667ae06a846472d20c5d90b22b42 Mon Sep 17 00:00:00 2001
  31. From: Dan Shelton <dan.f.shelton@gmail.com>
  32. Date: Mon, 22 Sep 2025 11:36:55 +0200
  33. Subject: [PATCH 2/4] sys: Remove disabled |MmUnmapLockedPages()| code from
  34.  |nfs41_UpcallDestroy()|
  35.  
  36. Remove disabled |MmUnmapLockedPages()| code from |nfs41_UpcallDestroy()|,
  37. it could've never worked that way anyway because process pages can
  38. only be unmapped in the context of the same process. That's why
  39. $ verifier /standard /driver nfs41_driver.sys # triggered a kernel assert.
  40.  
  41. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  42. ---
  43. sys/nfs41sys_updowncall.c | 52 ---------------------------------------
  44.  1 file changed, 52 deletions(-)
  45.  
  46. diff --git a/sys/nfs41sys_updowncall.c b/sys/nfs41sys_updowncall.c
  47. index 749d892..5066c99 100644
  48. --- a/sys/nfs41sys_updowncall.c
  49. +++ b/sys/nfs41sys_updowncall.c
  50. @@ -445,58 +445,6 @@ void nfs41_UpcallDestroy(nfs41_updowncall_entry *entry)
  51.      if (!entry)
  52.          return;
  53.  
  54. -    /*
  55. -     * Free resources which might otherwise be leaked
  56. -     * FIXME: Does not work yet, the |NFS41_SYSOP_READ| codepath crashes in
  57. -     * |MmUnmapLockedPages()| when
  58. -     * $ verifier /standard /driver nfs41_driver.sys # is active
  59. -     */
  60. -#ifdef XXDISABLED_FOR_NOWXX /*defined(_DEBUG) */
  61. -    switch(entry->opcode) {
  62. -        case NFS41_SYSOP_WRITE:
  63. -        case NFS41_SYSOP_READ:
  64. -            if (entry->buf) {
  65. -                DbgP("nfs41_UpcallDestroy: NFS41_SYSOP_RW mapping leak\n");
  66. -                MmUnmapLockedPages(entry->buf, entry->u.ReadWrite.MdlAddress);
  67. -                entry->buf = NULL;
  68. -            }
  69. -            break;
  70. -        case NFS41_SYSOP_DIR_QUERY:
  71. -            if (entry->u.QueryFile.mdl) {
  72. -                DbgP("nfs41_UpcallDestroy: "
  73. -                    "NFS41_SYSOP_DIR_QUERY mapping leak\n");
  74. -                MmUnmapLockedPages(entry->u.QueryFile.mdl_buf,
  75. -                    entry->u.QueryFile.mdl);
  76. -                IoFreeMdl(entry->u.QueryFile.mdl);
  77. -                entry->u.QueryFile.mdl_buf = NULL;
  78. -                entry->u.QueryFile.mdl = NULL;
  79. -            }
  80. -            break;
  81. -        case NFS41_SYSOP_OPEN:
  82. -            if (entry->u.Open.EaMdl) {
  83. -                DbgP("nfs41_UpcallDestroy: NFS41_SYSOP_OPEN mapping leak\n");
  84. -                MmUnmapLockedPages(entry->u.Open.EaBuffer,
  85. -                    entry->u.Open.EaMdl);
  86. -                IoFreeMdl(entry->u.Open.EaMdl);
  87. -                entry->u.Open.EaBuffer = NULL;
  88. -                entry->u.Open.EaMdl = NULL;
  89. -            }
  90. -            break;
  91. -        case NFS41_SYSOP_FSCTL_QUERYALLOCATEDRANGES:
  92. -            if (entry->u.QueryAllocatedRanges.BufferMdl) {
  93. -                DbgP("nfs41_UpcallDestroy: "
  94. -                    "NFS41_SYSOP_FSCTL_QUERYALLOCATEDRANGES mapping leak\n");
  95. -                MmUnmapLockedPages(
  96. -                    entry->u.QueryAllocatedRanges.Buffer,
  97. -                    entry->u.QueryAllocatedRanges.BufferMdl);
  98. -                IoFreeMdl(entry->u.QueryAllocatedRanges.BufferMdl);
  99. -                entry->u.QueryAllocatedRanges.Buffer = NULL;
  100. -                entry->u.QueryAllocatedRanges.BufferMdl = NULL;
  101. -            }
  102. -            break;
  103. -    }
  104. -#endif /* _DEBUG */
  105. -
  106.      KeClearEvent(&entry->cond);
  107.  
  108.      if (entry->psec_ctx_clienttoken) {
  109. --
  110. 2.51.0
  111.  
  112. From 1730aa5edc0433cb37e0cbdfff04bc9d470329cf Mon Sep 17 00:00:00 2001
  113. From: Roland Mainz <roland.mainz@nrubsig.org>
  114. Date: Mon, 22 Sep 2025 15:42:36 +0200
  115. Subject: [PATCH 3/4] sys: |nfs41_DuplicateData()| should flush the source file
  116.  before cloning
  117.  
  118. |nfs41_DuplicateData()| should flush the source file before cloning.
  119. This should make sure that the NFS server (which is doing the block
  120. cloning) sees the same data as the client, even if the client was writing
  121. into the same handle as is used for cloning.
  122.  
  123. Reported-by: Dan Shelton <dan.f.shelton@gmail.com>
  124. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  125. ---
  126. sys/nfs41sys_fsctl.c | 20 ++++++++++++++++++++
  127.  1 file changed, 20 insertions(+)
  128.  
  129. diff --git a/sys/nfs41sys_fsctl.c b/sys/nfs41sys_fsctl.c
  130. index 16edecb..488db88 100644
  131. --- a/sys/nfs41sys_fsctl.c
  132. +++ b/sys/nfs41sys_fsctl.c
  133. @@ -754,6 +754,26 @@ NTSTATUS nfs41_DuplicateData(
  134.          goto out;
  135.      }
  136.  
  137. +    IO_STATUS_BLOCK flushIoStatus;
  138. +    DbgP("nfs41_DuplicateData: flushing src file buffers\n");
  139. +    status = ZwFlushBuffersFile(dd.handle, &flushIoStatus);
  140. +    if (status) {
  141. +        if (status == STATUS_ACCESS_DENIED) {
  142. +            /*
  143. +             * |ZwFlushBuffersFile()| can fail if |dd.handle| was not opened
  144. +             * for write access
  145. +             */
  146. +            DbgP("nfs41_DuplicateData: "
  147. +                "ZwFlushBuffersFile() failed with STATUS_ACCESS_DENIED\n");
  148. +        }
  149. +        else {
  150. +            DbgP("nfs41_DuplicateData: "
  151. +                "ZwFlushBuffersFile() failed, status=0x%lx\n",
  152. +                (long)status);
  153. +            goto out;
  154. +        }
  155. +    }
  156. +
  157.      /*
  158.       * Disable caching because NFSv4.2 DEALLOCATE is basically a
  159.       * "write" operation. AFAIK we should flush the cache and wait
  160. --
  161. 2.51.0
  162.  
  163. From 1d90c864fa4e40607a5d2046793fbc76c683d498 Mon Sep 17 00:00:00 2001
  164. From: Roland Mainz <roland.mainz@nrubsig.org>
  165. Date: Mon, 22 Sep 2025 15:45:31 +0200
  166. Subject: [PATCH 4/4] sys: Fix comment s/NFSv4.2 DEALLOCATE/NFSv4.2 CLONE/ in
  167.  |nfs41_DuplicateData()|
  168.  
  169. Fix comment s/NFSv4.2 DEALLOCATE/NFSv4.2 CLONE/ in |nfs41_DuplicateData()|.
  170.  
  171. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  172. ---
  173. sys/nfs41sys_fsctl.c | 6 +++---
  174.  1 file changed, 3 insertions(+), 3 deletions(-)
  175.  
  176. diff --git a/sys/nfs41sys_fsctl.c b/sys/nfs41sys_fsctl.c
  177. index 488db88..b65d35b 100644
  178. --- a/sys/nfs41sys_fsctl.c
  179. +++ b/sys/nfs41sys_fsctl.c
  180. @@ -775,12 +775,12 @@ NTSTATUS nfs41_DuplicateData(
  181.      }
  182.  
  183.      /*
  184. -     * Disable caching because NFSv4.2 DEALLOCATE is basically a
  185. +     * Disable caching because NFSv4.2 CLONE is basically a
  186.       * "write" operation. AFAIK we should flush the cache and wait
  187.       * for the kernel lazy writer (which |RxChangeBufferingState()|
  188. -     * AFAIK does) before doing the DEALLOCATE, to avoid that we
  189. +     * AFAIK does) before doing the CLONE, to avoid that we
  190.       * have outstanding writes in the kernel cache at the same
  191. -     * location where the DEALLOCATE should do it's work
  192. +     * location where the CLONE should do it's work
  193.       */
  194.      ULONG flag = DISABLE_CACHING;
  195.      DbgP("nfs41_DuplicateData: disableing caching for file '%wZ'\n",
  196. --
  197. 2.51.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