pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches for mount long options, bigger namecache+misc, 2024-07-18
Posted by Anonymous on Thu 18th Jul 2024 17:27
raw | new post

  1. From ba4be7bad26b57f19707d7d95945f2e0724ff3b0 Mon Sep 17 00:00:00 2001
  2. From: Dan Shelton <dan.f.shelton@gmail.com>
  3. Date: Wed, 17 Jul 2024 16:33:41 +0200
  4. Subject: [PATCH 1/6] mount: Provide --long options for nfs_mount.exe
  5.  
  6. Provide --long options for nfs_mount.exe
  7.  
  8. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  9. ---
  10. mount/mount.c | 63 +++++++++++++++++++++++++++++++--------------------
  11.  1 file changed, 39 insertions(+), 24 deletions(-)
  12.  
  13. diff --git a/mount/mount.c b/mount/mount.c
  14. index 4fbc670..9758e1c 100644
  15. --- a/mount/mount.c
  16. +++ b/mount/mount.c
  17. @@ -79,18 +79,17 @@ static VOID PrintUsage(LPWSTR pProcess)
  18.          "Usage: %S [options] <drive letter|*> <hostname>:<path>\n"
  19.  
  20.          "* Options:\n"
  21. -        "\t-h\thelp\n"
  22. -        "\t/?\thelp\n"
  23. -        "\t-d\tunmount\n"
  24. -        "\t-f\tforce unmount if the drive is in use\n"
  25. +        "\t-h, --help, /?\thelp\n"
  26. +        "\t-d, --unmount\tunmount\n"
  27. +        "\t-f, --force\tforce unmount if the drive is in use\n"
  28.              "\t-F <type>\tFilesystem type to use (only 'nfs' supported)"
  29.             " (Solaris/Illumos compat)\n"
  30. -        "\t-t <type>\tFilesystem type to use (only 'nfs' supported)"
  31. +        "\t-t, --types <type>\tFilesystem type to use (only 'nfs' supported)"
  32.             " (Linux compat)\n"
  33. -        "\t-p\tmake the mount persist over reboots\n"
  34. -        "\t-o <comma-separated mount options>\n"
  35. -        "\t-r\tAlias for -o ro (read-only mount)\n"
  36. -        "\t-w\tAlias for -o rw (read-write mount)\n"
  37. +        "\t-p, --persistent\tmake the mount persist over reboots\n"
  38. +        "\t-o. --options <comma-separated mount options>\n"
  39. +        "\t-r, --read-only\tAlias for -o ro (read-only mount)\n"
  40. +        "\t-w, --rw, --read-write\tAlias for -o rw (read-write mount)\n"
  41.  
  42.          "* Mount options:\n"
  43.          "\tpublic\tconnect to the server using the public file handle lookup protocol.\n"
  44. @@ -189,20 +188,30 @@ int __cdecl wmain(int argc, wchar_t *argv[])
  45.      {
  46.          if (argv[i][0] == L'-')
  47.          {
  48. -            if (!wcscmp(argv[i], L"-h")) { /* help */
  49. +            /* help */
  50. +            if ((!wcscmp(argv[i], L"-h")) ||
  51. +                (!wcscmp(argv[i], L"--help"))) {
  52.                  PrintUsage(argv[0]);
  53.                  goto out;
  54.              }
  55. -            else if (!wcscmp(argv[i], L"-d")) { /* unmount */
  56. +            /* unmount */
  57. +            else if ((!wcscmp(argv[i], L"-d")) ||
  58. +                    (!wcscmp(argv[i], L"--unmount"))) {
  59.                  bUnmount = TRUE;
  60.              }
  61. -            else if (!wcscmp(argv[i], L"-f")) { /* force unmount */
  62. +            /* force unmount */
  63. +            else if ((!wcscmp(argv[i], L"-f")) ||
  64. +                (!wcscmp(argv[i], L"--force"))) {
  65.                  bForceUnmount = TRUE;
  66.              }
  67. -            else if (!wcscmp(argv[i], L"-p")) { /* persistent */
  68. +            /* persistent */
  69. +            else if ((!wcscmp(argv[i], L"-p")) ||
  70. +                    (!wcscmp(argv[i], L"--persistent"))) {
  71.                  bPersistent = TRUE;
  72.              }
  73. -            else if (!wcscmp(argv[i], L"-o")) { /* mount option */
  74. +            /* mount option */
  75. +            else if ((!wcscmp(argv[i], L"-o")) ||
  76. +                    (!wcscmp(argv[i], L"--options"))) {
  77.                  ++i;
  78.                  if (i >= argc)
  79.                  {
  80. @@ -289,7 +298,9 @@ opt_o_argv_i_again:
  81.                      goto opt_o_argv_i_again;
  82.                  }
  83.              }
  84. -            else if (!wcscmp(argv[i], L"-r")) { /* mount option */
  85. +            /* mount option */
  86. +            else if ((!wcscmp(argv[i], L"-r")) ||
  87. +                    (!wcscmp(argv[i], L"--read-only"))) {
  88.                  if (num_mntopts >= (MAX_MNTOPTS-1)) {
  89.                      result = ERROR_BAD_ARGUMENTS;
  90.                      (void)fwprintf(stderr, L"Too many options.\n\n");
  91. @@ -298,7 +309,10 @@ opt_o_argv_i_again:
  92.  
  93.                  mntopts[num_mntopts++] = L"ro";
  94.              }
  95. -            else if (!wcscmp(argv[i], L"-w")) { /* mount option */
  96. +            /* mount option */
  97. +            else if ((!wcscmp(argv[i], L"-w")) ||
  98. +                    (!wcscmp(argv[i], L"--rw")) ||
  99. +                    (!wcscmp(argv[i], L"--read-write"))) {
  100.                  if (num_mntopts >= (MAX_MNTOPTS-1)) {
  101.                      result = ERROR_BAD_ARGUMENTS;
  102.                      (void)fwprintf(stderr, L"Too many options.\n\n");
  103. @@ -313,8 +327,8 @@ opt_o_argv_i_again:
  104.              * $ mount.nfs4 -t nfs ... # compatiblity
  105.              */
  106.              else if ((!wcscmp(argv[i], L"-F")) ||
  107. -                    (!wcscmp(argv[i], L"-t")))
  108. -            {
  109. +                    (!wcscmp(argv[i], L"-t")) ||
  110. +                    (!wcscmp(argv[i], L"--types"))) {
  111.                  ++i;
  112.                  if (i >= argc)
  113.                  {
  114. @@ -338,23 +352,24 @@ opt_o_argv_i_again:
  115.                      L"'%s', disregarding.\n",
  116.                      argv[i]);
  117.          }
  118. +        /* Windows-style "nfs_mount /?" help */
  119.          else if (!wcscmp(argv[i], L"/?")) {
  120. -           /* Windows-style "nfs_mount /?" help */
  121.              PrintUsage(argv[0]);
  122.              goto out;
  123.         }
  124. -       else if (pLocalName == NULL) /* drive letter */
  125. -        {
  126. +        /* drive letter */
  127. +       else if (pLocalName == NULL) {
  128.              pLocalName = argv[i];
  129.          }
  130. -        else if (pRemoteName == NULL) /* remote path */
  131. -        {
  132. +        /* remote path */
  133. +        else if (pRemoteName == NULL) {
  134.              pRemoteName = argv[i];
  135.          }
  136. -        else
  137. +        else {
  138.              (void)fwprintf(stderr, L"Unrecognized argument "
  139.                  L"'%s', disregarding.\n",
  140.                  argv[i]);
  141. +        }
  142.      }
  143.  
  144.      /* validate local drive letter */
  145. --
  146. 2.45.1
  147.  
  148. From b461a0ad45b8bac26bd05638de491618dce49e3c Mon Sep 17 00:00:00 2001
  149. From: Roland Mainz <roland.mainz@nrubsig.org>
  150. Date: Wed, 17 Jul 2024 17:10:30 +0200
  151. Subject: [PATCH 2/6] daemon: Increase name cache size from 8M to 32M
  152.  
  153. Increase name cache size from 8M to 32M, to better deal
  154. with highly parallel workloads.
  155.  
  156. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  157. ---
  158. daemon/name_cache.c | 4 ++--
  159.  1 file changed, 2 insertions(+), 2 deletions(-)
  160.  
  161. diff --git a/daemon/name_cache.c b/daemon/name_cache.c
  162. index 9c389a6..b95ac5d 100644
  163. --- a/daemon/name_cache.c
  164. +++ b/daemon/name_cache.c
  165. @@ -41,8 +41,8 @@ enum {
  166.  
  167.  #define NAME_CACHE_EXPIRATION 20 /* TODO: get from configuration */
  168.  
  169. -/* allow up to 8M of memory for name and attribute cache entries */
  170. -#define NAME_CACHE_MAX_SIZE (8*1024*1024L)
  171. +/* allow up to 32M of memory for name and attribute cache entries */
  172. +#define NAME_CACHE_MAX_SIZE (32*1024*1024L)
  173.  
  174.  /* negative lookup caching
  175.   *
  176. --
  177. 2.45.1
  178.  
  179. From 79dd9bd66ecf0dda180570ce826ac862699ddd4f Mon Sep 17 00:00:00 2001
  180. From: Roland Mainz <roland.mainz@nrubsig.org>
  181. Date: Wed, 17 Jul 2024 17:18:21 +0200
  182. Subject: [PATCH 3/6] daemon: Increase default name cache timeout from 20s
  183.  seconds to 30s.
  184.  
  185. Increase default name cache timeout from 20 seconds to 30 seconds.
  186. This should really be a mount option.
  187.  
  188. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  189. ---
  190. daemon/name_cache.c | 2 +-
  191.  1 file changed, 1 insertion(+), 1 deletion(-)
  192.  
  193. diff --git a/daemon/name_cache.c b/daemon/name_cache.c
  194. index b95ac5d..c73e8d5 100644
  195. --- a/daemon/name_cache.c
  196. +++ b/daemon/name_cache.c
  197. @@ -39,7 +39,7 @@ enum {
  198.  };
  199.  
  200.  
  201. -#define NAME_CACHE_EXPIRATION 20 /* TODO: get from configuration */
  202. +#define NAME_CACHE_EXPIRATION 30 /* TODO: get from configuration */
  203.  
  204.  /* allow up to 32M of memory for name and attribute cache entries */
  205.  #define NAME_CACHE_MAX_SIZE (32*1024*1024L)
  206. --
  207. 2.45.1
  208.  
  209. From 2f63dcc073564e82f9ed28e38413765b0e56679d Mon Sep 17 00:00:00 2001
  210. From: Roland Mainz <roland.mainz@nrubsig.org>
  211. Date: Thu, 18 Jul 2024 16:16:00 +0200
  212. Subject: [PATCH 4/6] sys: Fix |DWORD|vs|LONG| option parsing+enforce min/max
  213.  values for numeric mount options
  214.  
  215. Fix |DWORD|vs|LONG| option parsing, and enforce min/max values for
  216. numeric mount options
  217.  
  218. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  219. ---
  220. sys/nfs41_driver.c | 63 +++++++++++++++++++++++++++++++++-------------
  221.  1 file changed, 46 insertions(+), 17 deletions(-)
  222.  
  223. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  224. index de5383f..8a92bdb 100644
  225. --- a/sys/nfs41_driver.c
  226. +++ b/sys/nfs41_driver.c
  227. @@ -2896,30 +2896,59 @@ NTSTATUS nfs41_MountConfig_ParseBoolean(
  228.      return status;
  229.  }
  230.  
  231. -NTSTATUS nfs41_MountConfig_ParseDword(
  232. +
  233. +/* Parse |signed| integer value */
  234. +static
  235. +NTSTATUS nfs41_MountConfig_ParseINT64(
  236.      IN PFILE_FULL_EA_INFORMATION Option,
  237.      IN PUNICODE_STRING usValue,
  238. -    OUT PDWORD Value,
  239. -    IN DWORD Minimum,
  240. -    IN DWORD Maximum)
  241. +    OUT INT64 *outValue,
  242. +    IN INT64 Minimum,
  243. +    IN INT64 Maximum)
  244.  {
  245. -    NTSTATUS status = STATUS_INVALID_PARAMETER;
  246. +    NTSTATUS status;
  247. +    LONG64 Value = 0;
  248.      LPWSTR Name = (LPWSTR)Option->EaName;
  249.  
  250. -    if (Option->EaValueLength) {
  251. -        status = RtlUnicodeStringToInteger(usValue, 0, Value);
  252. +    if (!Option->EaValueLength)
  253. +        return STATUS_INVALID_PARAMETER;
  254. +
  255. +    status = RtlUnicodeStringToInt64(usValue, 0, &Value, NULL);
  256. +    if (status == STATUS_SUCCESS) {
  257. +        if ((Value < Minimum) || (Value > Maximum))
  258. +            status = STATUS_INVALID_PARAMETER;
  259. +
  260.          if (status == STATUS_SUCCESS) {
  261. -#ifdef IMPOSE_MINMAX_RWSIZES
  262. -            if (*Value < Minimum)
  263. -                *Value = Minimum;
  264. -            if (*Value > Maximum)
  265. -                *Value = Maximum;
  266. -            DbgP("    '%ls' -> '%wZ' -> %lu\n", Name, usValue, *Value);
  267. -#endif
  268. +            *outValue = Value;
  269.          }
  270. -        else
  271. -            print_error("Failed to convert '%s'='%wZ' to unsigned long.\n",
  272. -                Name, usValue);
  273. +    }
  274. +    else {
  275. +        print_error("nfs41_MountConfig_ParseINT64: "
  276. +            "Failed to convert '%s'='%wZ' to unsigned long.\n",
  277. +            Name, usValue);
  278. +    }
  279. +
  280. +    return status;
  281. +}
  282. +
  283. +/* Parse |unsigned| integer value */
  284. +static
  285. +NTSTATUS nfs41_MountConfig_ParseDword(
  286. +    IN PFILE_FULL_EA_INFORMATION Option,
  287. +    IN PUNICODE_STRING usValue,
  288. +    OUT PDWORD outValue,
  289. +    IN DWORD Minimum,
  290. +    IN DWORD Maximum)
  291. +{
  292. +    INT64 tmpValue;
  293. +    NTSTATUS status;
  294. +
  295. +    status = nfs41_MountConfig_ParseINT64(
  296. +        Option, usValue,
  297. +        &tmpValue, Minimum, Maximum);
  298. +
  299. +    if (status == STATUS_SUCCESS) {
  300. +        *outValue = (DWORD)tmpValue;
  301.      }
  302.  
  303.      return status;
  304. --
  305. 2.45.1
  306.  
  307. From 64416ec401405fe0adc25affd42768e9124e808a Mon Sep 17 00:00:00 2001
  308. From: Roland Mainz <roland.mainz@nrubsig.org>
  309. Date: Thu, 18 Jul 2024 16:27:04 +0200
  310. Subject: [PATCH 5/6] daemon: Make some |*_cmp()| functions |static|
  311.  
  312. Make some |*_cmp()| functions |static|
  313.  
  314. Reported-by: Josh Hurst <joshhurst@gmail.com>
  315. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  316. ---
  317. daemon/name_cache.c   | 4 ++--
  318.  daemon/nfs41_client.c | 2 +-
  319.  2 files changed, 3 insertions(+), 3 deletions(-)
  320.  
  321. diff --git a/daemon/name_cache.c b/daemon/name_cache.c
  322. index c73e8d5..4b62193 100644
  323. --- a/daemon/name_cache.c
  324. +++ b/daemon/name_cache.c
  325. @@ -111,7 +111,7 @@ struct attr_cache {
  326.      struct list_entry       free_entries;
  327.  };
  328.  
  329. -int attr_cmp(struct attr_cache_entry *lhs, struct attr_cache_entry *rhs)
  330. +static int attr_cmp(struct attr_cache_entry *lhs, struct attr_cache_entry *rhs)
  331.  {
  332.      return lhs->fileid < rhs->fileid ? -1 : lhs->fileid > rhs->fileid;
  333.  }
  334. @@ -412,7 +412,7 @@ struct name_cache_entry {
  335.  };
  336.  #define NAME_ENTRY_SIZE sizeof(struct name_cache_entry)
  337.  
  338. -int name_cmp(struct name_cache_entry *lhs, struct name_cache_entry *rhs)
  339. +static int name_cmp(struct name_cache_entry *lhs, struct name_cache_entry *rhs)
  340.  {
  341.      const int diff = rhs->component_len - lhs->component_len;
  342.      return diff ? diff : strncmp(lhs->component, rhs->component, lhs->component_len);
  343. diff --git a/daemon/nfs41_client.c b/daemon/nfs41_client.c
  344. index b99e545..355eb06 100644
  345. --- a/daemon/nfs41_client.c
  346. +++ b/daemon/nfs41_client.c
  347. @@ -254,7 +254,7 @@ struct mac_entry {
  348.      ULONG                   length;
  349.  };
  350.  
  351. -int mac_cmp(struct mac_entry *lhs, struct mac_entry *rhs)
  352. +static int mac_cmp(struct mac_entry *lhs, struct mac_entry *rhs)
  353.  {
  354.      const int diff = rhs->length - lhs->length;
  355.      return diff ? diff : strncmp((const char*)lhs->address,
  356. --
  357. 2.45.1
  358.  
  359. From 79da3c97ec17d1dc59212f9be01d10392c943540 Mon Sep 17 00:00:00 2001
  360. From: Roland Mainz <roland.mainz@nrubsig.org>
  361. Date: Thu, 18 Jul 2024 16:43:02 +0200
  362. Subject: [PATCH 6/6] sys: Driver code should use |NTSTATUS()| to test for
  363.  success
  364.  
  365. Driver code should use |NTSTATUS()| to test for success, not
  366. |(status == STATUS_SUCCESS)|
  367.  
  368. Reported-by: Josh Hurst <joshhurst@gmail.com>
  369. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  370. ---
  371. sys/nfs41_driver.c | 18 ++++++++++--------
  372.  1 file changed, 10 insertions(+), 8 deletions(-)
  373.  
  374. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  375. index 8a92bdb..50f7342 100644
  376. --- a/sys/nfs41_driver.c
  377. +++ b/sys/nfs41_driver.c
  378. @@ -1464,7 +1464,7 @@ NTSTATUS handle_upcall(
  379.  #else
  380.      status = SeImpersonateClientEx(entry->psec_ctx, NULL);
  381.  #endif /* NFS41_DRIVER_STABILITY_HACKS */
  382. -    if (status != STATUS_SUCCESS) {
  383. +    if (!NT_SUCCESS(status)) {
  384.          print_error("handle_upcall: "
  385.              "SeImpersonateClientEx() failed 0x%x\n", status);
  386.          goto out;
  387. @@ -1532,8 +1532,10 @@ NTSTATUS handle_upcall(
  388.          print_error("Unknown nfs41 ops %d\n", entry->opcode);
  389.      }
  390.  
  391. -    if (status == STATUS_SUCCESS)
  392. +#if 0
  393. +    if (NT_SUCCESS(status))
  394.          print_hexbuf(0, (unsigned char *)"upcall buffer", pbOut, *len);
  395. +#endif
  396.  
  397.  out:
  398.      return status;
  399. @@ -1591,7 +1593,7 @@ NTSTATUS nfs41_UpcallCreate(
  400.           */
  401.          status = SeCreateClientSecurityFromSubjectContext(&sec_ctx, &sec_qos,
  402.                      FALSE, entry->psec_ctx);
  403. -        if (status != STATUS_SUCCESS) {
  404. +        if (!NT_SUCCESS(status)) {
  405.              print_error("nfs41_UpcallCreate: "
  406.                  "SeCreateClientSecurityFromSubjectContext() "
  407.                  "failed with 0x%x\n",
  408. @@ -1711,8 +1713,8 @@ process_upcall:
  409.          ExAcquireFastMutex(&entry->lock);
  410.          nfs41_AddEntry(downcallLock, downcall, entry);
  411.          status = handle_upcall(RxContext, entry, &len);
  412. -        if (status == STATUS_SUCCESS &&
  413. -                entry->state == NFS41_WAITING_FOR_UPCALL)
  414. +        if (NT_SUCCESS(status) &&
  415. +            (entry->state == NFS41_WAITING_FOR_UPCALL))
  416.              entry->state = NFS41_WAITING_FOR_DOWNCALL;
  417.          ExReleaseFastMutex(&entry->lock);
  418.          if (status) {
  419. @@ -2142,7 +2144,7 @@ NTSTATUS nfs41_downcall(
  420.      }
  421.      ExReleaseFastMutex(&cur->lock);
  422.      if (cur->async_op) {
  423. -        if (cur->status == STATUS_SUCCESS) {
  424. +        if (NT_SUCCESS(cur->status)) {
  425.              cur->u.ReadWrite.rxcontext->StoredStatus = STATUS_SUCCESS;
  426.              cur->u.ReadWrite.rxcontext->InformationToReturn =
  427.                  cur->buf_len;
  428. @@ -2395,7 +2397,7 @@ NTSTATUS nfs41_CreateConnection(
  429.  
  430.      status = nfs41_GetConnectionInfoFromBuffer(Buffer, BufferLen,
  431.          &FileName, &EaBuffer, &EaLength);
  432. -    if (status != STATUS_SUCCESS)
  433. +    if (!NT_SUCCESS(status))
  434.          goto out;
  435.  
  436.      status = GetConnectionHandle(&FileName, EaBuffer, EaLength, &Handle);
  437. @@ -2500,7 +2502,7 @@ NTSTATUS nfs41_DeleteConnection (
  438.      FileName.MaximumLength = (USHORT) ConnectNameLen;
  439.  
  440.      status = GetConnectionHandle(&FileName, NULL, 0, &Handle);
  441. -    if (status != STATUS_SUCCESS)
  442. +    if (!NT_SUCCESS(status))
  443.          goto out;
  444.  
  445.      status = ObReferenceObjectByHandle(Handle, 0L, NULL, KernelMode,
  446. --
  447. 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