pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch for |handle_duplicatedata()| should use src+dst offsets+misc, 2025-04-16
Posted by Anonymous on Wed 16th Apr 2025 11:00
raw | new post

  1. From b3bf7fb93544ab93cba00ee70ef7bf76521b6f34 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Wed, 16 Apr 2025 10:41:02 +0200
  4. Subject: [PATCH 1/3] daemon: |handle_duplicatedata()| should use src+dst
  5.  offsets
  6.  
  7. |handle_duplicatedata()| should use src+dst offsets
  8.  
  9. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  10. ---
  11. daemon/fsctl.c | 31 ++++++++++++++++++++++++-------
  12.  1 file changed, 24 insertions(+), 7 deletions(-)
  13.  
  14. diff --git a/daemon/fsctl.c b/daemon/fsctl.c
  15. index 91f0763..8f93ab3 100644
  16. --- a/daemon/fsctl.c
  17. +++ b/daemon/fsctl.c
  18. @@ -523,14 +523,28 @@ int handle_duplicatedata(void *daemon_context,
  19.      }
  20.      src_file_size = info.size;
  21.  
  22. -    if (args->bytecount > src_file_size)
  23. -        bytecount = src_file_size;
  24. +    if ((args->srcfileoffset+args->bytecount) > src_file_size)
  25. +        bytecount = src_file_size-args->srcfileoffset;
  26.      else
  27.          bytecount = args->bytecount;
  28.  #else
  29.      bytecount = args->bytecount;
  30.  #endif /* CLONE_PUNCH_HOLE_IF_CLONESIZE_BIGGER_THAN_SRCFILESIZE */
  31.  
  32. +    EASSERT(bytecount > 0);
  33. +    if (bytecount <= 0) {
  34. +        DPRINTF(DDLVL,
  35. +            ("handle_duplicatedata("
  36. +            "src_state->path.path='%s' "
  37. +            "dst_state->path.path='%s'): "
  38. +            "Negative bytecount %lld\n",
  39. +            src_state->path.path,
  40. +            dst_state->path.path,
  41. +            bytecount));
  42. +        status = ERROR_INVALID_PARAMETER;
  43. +        goto out;
  44. +    }
  45. +
  46.      status = nfs42_clone(session,
  47.          src_file,
  48.          dst_file,
  49. @@ -553,19 +567,22 @@ int handle_duplicatedata(void *daemon_context,
  50.      }
  51.  
  52.  #ifdef CLONE_PUNCH_HOLE_IF_CLONESIZE_BIGGER_THAN_SRCFILESIZE
  53. -    if (args->bytecount > src_file_size) {
  54. +    if ((args->srcfileoffset+args->bytecount) > src_file_size) {
  55.          DPRINTF(DDLVL,
  56.              ("handle_duplicatedata(): "
  57. -            "Clone range (%llu) bigger than source file size "
  58. -            "(%llu), adding hole at the end of dest file.\n",
  59. +            "Clone range (offset(=%lld)+bytecount(=%lld)=%lld) "
  60. +            "bigger than source file size (%lld), "
  61. +            "adding hole at the end of dest file.\n",
  62. +            args->srcfileoffset,
  63.              args->bytecount,
  64. +            (args->srcfileoffset+args->bytecount),
  65.              src_file_size));
  66.  
  67.          status = nfs42_deallocate(session,
  68.              dst_file,
  69.              &dst_stateid,
  70. -            src_file_size,
  71. -            (args->bytecount - src_file_size),
  72. +            args->destfileoffset+src_file_size,
  73. +            ((args->srcfileoffset+args->bytecount) - src_file_size),
  74.              &info);
  75.          if (status) {
  76.              DPRINTF(DDLVL,
  77. --
  78. 2.45.1
  79.  
  80. From 738235baba453fca88a3ae5a7d514f7645e53a26 Mon Sep 17 00:00:00 2001
  81. From: Roland Mainz <roland.mainz@nrubsig.org>
  82. Date: Wed, 16 Apr 2025 10:50:02 +0200
  83. Subject: [PATCH 2/3] daemon: |DPRINTF()| debug level for
  84.  |handle_duplicatedata()| should be |2| except error code paths
  85.  
  86. |DPRINTF()| debug level for |handle_duplicatedata()| should be |2|
  87. except error code paths.
  88.  
  89. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  90. ---
  91. daemon/fsctl.c | 10 +++++-----
  92.  1 file changed, 5 insertions(+), 5 deletions(-)
  93.  
  94. diff --git a/daemon/fsctl.c b/daemon/fsctl.c
  95. index 8f93ab3..595c7be 100644
  96. --- a/daemon/fsctl.c
  97. +++ b/daemon/fsctl.c
  98. @@ -29,7 +29,7 @@
  99.  
  100.  #define QARLVL 2 /* dprintf level for "query allocated ranges" logging */
  101.  #define SZDLVL 2 /* dprintf level for "set zero data" logging */
  102. -#define DDLVL  0 /* dprintf level for "duplicate data" logging */
  103. +#define DDLVL  2 /* dprintf level for "duplicate data" logging */
  104.  
  105.  static int parse_queryallocatedranges(unsigned char *buffer,
  106.      uint32_t length, nfs41_upcall *upcall)
  107. @@ -533,7 +533,7 @@ int handle_duplicatedata(void *daemon_context,
  108.  
  109.      EASSERT(bytecount > 0);
  110.      if (bytecount <= 0) {
  111. -        DPRINTF(DDLVL,
  112. +        DPRINTF(0/*DDLVL*/,
  113.              ("handle_duplicatedata("
  114.              "src_state->path.path='%s' "
  115.              "dst_state->path.path='%s'): "
  116. @@ -555,7 +555,7 @@ int handle_duplicatedata(void *daemon_context,
  117.          bytecount,
  118.          &info);
  119.      if (status) {
  120. -        DPRINTF(DDLVL,
  121. +        DPRINTF(0/*DDLVL*/,
  122.              ("handle_duplicatedata("
  123.              "src_state->path.path='%s' "
  124.              "dst_state->path.path='%s'): "
  125. @@ -585,7 +585,7 @@ int handle_duplicatedata(void *daemon_context,
  126.              ((args->srcfileoffset+args->bytecount) - src_file_size),
  127.              &info);
  128.          if (status) {
  129. -            DPRINTF(DDLVL,
  130. +            DPRINTF(0/*DDLVL*/,
  131.                  ("handle_duplicatedata("
  132.                  "src_state->path.path='%s' "
  133.                  "dst_state->path.path='%s'): "
  134. @@ -609,7 +609,7 @@ int handle_duplicatedata(void *daemon_context,
  135.          args->ctime));
  136.  
  137.  out:
  138. -    DPRINTF(0,
  139. +    DPRINTF(DDLVL,
  140.          ("<-- handle_duplicatedata(), status=0x%lx\n",
  141.          status));
  142.  
  143. --
  144. 2.45.1
  145.  
  146. From f3741916db9db5c69fac5de8812d2d6a73f2cbac Mon Sep 17 00:00:00 2001
  147. From: Roland Mainz <roland.mainz@nrubsig.org>
  148. Date: Wed, 16 Apr 2025 11:31:15 +0200
  149. Subject: [PATCH 3/3] daemon: Add enable/disable booleans for NFSv4.2 OPs to
  150.  |nfs41_root|
  151.  
  152. Add enable/disable booleans for NFSv4.2 OPs (READ_PLUS, SEEK, ALLOCATE,
  153. DEALLOCATE, CLONE) to |nfs41_root|.
  154.  
  155. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  156. ---
  157. daemon/fsctl.c     | 25 +++++++++++++++++--------
  158.  daemon/namespace.c | 14 +++++++++++---
  159.  daemon/nfs41.h     |  4 ++++
  160.  daemon/open.c      |  2 +-
  161.  4 files changed, 33 insertions(+), 12 deletions(-)
  162.  
  163. diff --git a/daemon/fsctl.c b/daemon/fsctl.c
  164. index 595c7be..1b50fc3 100644
  165. --- a/daemon/fsctl.c
  166. +++ b/daemon/fsctl.c
  167. @@ -65,6 +65,7 @@ int query_sparsefile_datasections(nfs41_open_state *state,
  168.      size_t *restrict res_num_records)
  169.  {
  170.      int status = NO_ERROR;
  171. +    nfs41_session *session = state->session;
  172.      uint64_t next_offset;
  173.      uint64_t data_size;
  174.      int data_seek_status;
  175. @@ -82,8 +83,8 @@ int query_sparsefile_datasections(nfs41_open_state *state,
  176.          ("--> query_sparsefile_datasections(state->path.path='%s')\n",
  177.          state->path.path));
  178.  
  179. -    /* NFS SEEK requires NFSv4.2 */
  180. -    if (state->session->client->root->nfsminorvers < 2) {
  181. +    /* NFS SEEK supported ? */
  182. +    if (session->client->root->supports_nfs42_seek == false) {
  183.          status = ERROR_NOT_SUPPORTED;
  184.          goto out;
  185.      }
  186. @@ -94,7 +95,7 @@ int query_sparsefile_datasections(nfs41_open_state *state,
  187.      *res_num_records = 0;
  188.  
  189.      for (i=0 ; ; i++) {
  190. -        data_seek_status = nfs42_seek(state->session,
  191. +        data_seek_status = nfs42_seek(session,
  192.              &state->file,
  193.              &stateid,
  194.              next_offset,
  195. @@ -143,7 +144,7 @@ int query_sparsefile_datasections(nfs41_open_state *state,
  196.  
  197.          next_offset = data_seek_sr_offset;
  198.  
  199. -        hole_seek_status = nfs42_seek(state->session,
  200. +        hole_seek_status = nfs42_seek(session,
  201.              &state->file,
  202.              &stateid,
  203.              next_offset,
  204. @@ -368,8 +369,8 @@ int handle_setzerodata(void *daemon_context,
  205.              offset_end,
  206.              len));
  207.  
  208. -    /* NFS DEALLOCATE requires NFSv4.2 */
  209. -    if (state->session->client->root->nfsminorvers < 2) {
  210. +    /* NFS DEALLOCATE supported ? */
  211. +    if (session->client->root->supports_nfs42_deallocate == false) {
  212.          status = ERROR_NOT_SUPPORTED;
  213.          goto out;
  214.      }
  215. @@ -501,12 +502,20 @@ int handle_duplicatedata(void *daemon_context,
  216.              dst_state->path.path,
  217.              src_state->path.path));
  218.  
  219. -    /* NFS CLONE requires NFSv4.2 */
  220. -    if (dst_state->session->client->root->nfsminorvers < 2) {
  221. +    /* NFS CLONE supported ? */
  222. +    if (session->client->root->supports_nfs42_clone == false) {
  223.          status = ERROR_NOT_SUPPORTED;
  224.          goto out;
  225.      }
  226.  
  227. +#ifdef CLONE_PUNCH_HOLE_IF_CLONESIZE_BIGGER_THAN_SRCFILESIZE
  228. +    /* NFS DEALLOCATE supported ? */
  229. +    if (session->client->root->supports_nfs42_deallocate == false) {
  230. +        status = ERROR_NOT_SUPPORTED;
  231. +        goto out;
  232. +    }
  233. +#endif /* CLONE_PUNCH_HOLE_IF_CLONESIZE_BIGGER_THAN_SRCFILESIZE */
  234. +
  235.      nfs41_open_stateid_arg(src_state, &src_stateid);
  236.      nfs41_open_stateid_arg(dst_state, &dst_stateid);
  237.  
  238. diff --git a/daemon/namespace.c b/daemon/namespace.c
  239. index b5363eb..4511b52 100644
  240. --- a/daemon/namespace.c
  241. +++ b/daemon/namespace.c
  242. @@ -69,7 +69,11 @@ int nfs41_root_create(
  243.       * nfs41_root_mount_addrs() will enable NFSv4.2 features (like
  244.       * |OP_READ_PLUS|) after NFSv4.x minor version autonegitiation
  245.       */
  246. -    root->supports_nfs42_read_plus = false;
  247. +    root->supports_nfs42_read_plus  = false;
  248. +    root->supports_nfs42_seek       = false;
  249. +    root->supports_nfs42_allocate   = false;
  250. +    root->supports_nfs42_deallocate = false;
  251. +    root->supports_nfs42_clone      = false;
  252.      if (nfsvers == NFS_VERSION_AUTONEGOTIATION) {
  253.          /*
  254.           * Use auto negotiation, |nfs41_root_mount_addrs()| will
  255. @@ -445,8 +449,12 @@ retry_nfs41_exchange_id:
  256.  
  257.      /* Enable NFS features after NFSv4.x minor version negotiation */
  258.      if (root->nfsminorvers >= 2) {
  259. -        DPRINTF(0, ("nfs41_root_mount_addrs: Enabling OP_READ_PLUS\n"));
  260. -        root->supports_nfs42_read_plus = true;
  261. +        DPRINTF(0, ("nfs41_root_mount_addrs: Enabling NFSv4.2 OPs\n"));
  262. +        root->supports_nfs42_read_plus  = true;
  263. +        root->supports_nfs42_seek       = true;
  264. +        root->supports_nfs42_allocate   = true;
  265. +        root->supports_nfs42_deallocate = true;
  266. +        root->supports_nfs42_clone      = true;
  267.      }
  268.  
  269.      /* attempt to match existing clients by the exchangeid response */
  270. diff --git a/daemon/nfs41.h b/daemon/nfs41.h
  271. index 9c2bdab..ef23599 100644
  272. --- a/daemon/nfs41.h
  273. +++ b/daemon/nfs41.h
  274. @@ -304,6 +304,10 @@ typedef struct __nfs41_root {
  275.      struct list_entry clients;
  276.      bool use_nfspubfh;
  277.      bool supports_nfs42_read_plus;
  278. +    bool supports_nfs42_seek;
  279. +    bool supports_nfs42_allocate;
  280. +    bool supports_nfs42_deallocate;
  281. +    bool supports_nfs42_clone;
  282.      DWORD nfsminorvers;
  283.      uint32_t wsize;
  284.      uint32_t rsize;
  285. diff --git a/daemon/open.c b/daemon/open.c
  286. index d2629c0..1996e98 100644
  287. --- a/daemon/open.c
  288. +++ b/daemon/open.c
  289. @@ -1204,7 +1204,7 @@ create_chgrp_out:
  290.  #ifdef DEBUG_OPEN_SPARSE_FILES
  291.      if ((status == 0) &&
  292.          (info.type == NF4REG) &&
  293. -        (state->session->client->root->nfsminorvers >= 2)) {
  294. +        (state->session->client->root->supports_nfs42_seek)) {
  295.          //debug_list_sparsefile_holes(state);
  296.          debug_list_sparsefile_datasections(state);
  297.      }
  298. --
  299. 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