- From 88665bc5c1be353497e79ebc923995e94c7f47ff Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Fri, 26 Jul 2024 12:47:53 +0200
- Subject: [PATCH 1/6] daemon: Add |bitmap4_cpy()|+|bitmap4_clear()| utility
- functions
- Add |bitmap4_cpy()| and |bitmap4_clear()| utility functions, so we
- have a typesafe way to init+copy |bitmap4| types.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/lookup.c | 8 ++++----
- daemon/nfs41.h | 2 +-
- daemon/nfs41_ops.c | 44 +++++++++++++++-----------------------------
- daemon/nfs41_xdr.c | 4 ++--
- daemon/util.h | 19 +++++++++++++++++++
- 5 files changed, 41 insertions(+), 36 deletions(-)
- diff --git a/daemon/lookup.c b/daemon/lookup.c
- index ade3354..e895612 100644
- --- a/daemon/lookup.c
- +++ b/daemon/lookup.c
- @@ -224,8 +224,8 @@ static int server_lookup(
- last_component(path, count ? args->lookup[0].name->name : path_end, &name);
- /* add the file handle and attributes to the name cache */
- - memcpy(&res->getrootattr.info->attrmask,
- - &res->getrootattr.obj_attributes.attrmask, sizeof(bitmap4));
- + bitmap4_cpy(&res->getrootattr.info->attrmask,
- + &res->getrootattr.obj_attributes.attrmask);
- nfs41_name_cache_insert(session_name_cache(session), path, &name,
- &dir->fh, res->getrootattr.info, NULL, OPEN_DELEGATE_NONE);
- }
- @@ -274,8 +274,8 @@ static int server_lookup(
- break;
- /* add the file handle and attributes to the name cache */
- - memcpy(&res->getattr[i].info->attrmask,
- - &res->getattr[i].obj_attributes.attrmask, sizeof(bitmap4));
- + bitmap4_cpy(&res->getattr[i].info->attrmask,
- + &res->getattr[i].obj_attributes.attrmask);
- nfs41_name_cache_insert(session_name_cache(session),
- path, args->lookup[i].name, &res->file[i].fh,
- res->getattr[i].info, NULL, OPEN_DELEGATE_NONE);
- diff --git a/daemon/nfs41.h b/daemon/nfs41.h
- index f69f79d..fd2373a 100644
- --- a/daemon/nfs41.h
- +++ b/daemon/nfs41.h
- @@ -482,7 +482,7 @@ static __inline void nfs41_superblock_getattr_mask(
- IN const nfs41_superblock *superblock,
- OUT bitmap4 *attrs)
- {
- - memcpy(attrs, &superblock->default_getattr, sizeof(bitmap4));
- + bitmap4_cpy(attrs, &superblock->default_getattr);
- }
- static __inline void nfs41_superblock_supported_attrs(
- IN const nfs41_superblock *superblock,
- diff --git a/daemon/nfs41_ops.c b/daemon/nfs41_ops.c
- index 9bf8832..fbb4fad 100644
- --- a/daemon/nfs41_ops.c
- +++ b/daemon/nfs41_ops.c
- @@ -397,13 +397,11 @@ static void open_update_cache(
- uint32_t status;
- /* update the attributes of the parent directory */
- - memcpy(&dir_attrs->info->attrmask, &dir_attrs->obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&dir_attrs->info->attrmask, &dir_attrs->obj_attributes.attrmask);
- nfs41_attr_cache_update(cache, parent->fh.fileid, dir_attrs->info);
- /* add the file handle and attributes to the name cache */
- - memcpy(&file_attrs->info->attrmask, &file_attrs->obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&file_attrs->info->attrmask, &file_attrs->obj_attributes.attrmask);
- retry_cache_insert:
- AcquireSRWLockShared(&file->path->lock);
- status = nfs41_name_cache_insert(cache, file->path->path, &file->name,
- @@ -672,14 +670,12 @@ int nfs41_create(
- file->fh.superblock = parent->fh.superblock;
- /* update the attributes of the parent directory */
- - memcpy(&dir_info.attrmask, &pgetattr_res.obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&dir_info.attrmask, &pgetattr_res.obj_attributes.attrmask);
- nfs41_attr_cache_update(session_name_cache(session),
- parent->fh.fileid, &dir_info);
- /* add the new file handle and attributes to the name cache */
- - memcpy(&info->attrmask, &getattr_res.obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&info->attrmask, &getattr_res.obj_attributes.attrmask);
- AcquireSRWLockShared(&file->path->lock);
- nfs41_name_cache_insert(session_name_cache(session),
- file->path->path, &file->name, &file->fh,
- @@ -741,8 +737,7 @@ int nfs41_close(
- goto out;
- /* update the attributes of the parent directory */
- - memcpy(&info.attrmask, &getattr_res.obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&info.attrmask, &getattr_res.obj_attributes.attrmask);
- nfs41_attr_cache_update(session_name_cache(session),
- file->fh.fileid, &info);
- out:
- @@ -817,8 +812,7 @@ int nfs41_write(
- if (stable != UNSTABLE4 && pinfo->type != NF4NAMEDATTR) {
- /* update the attribute cache */
- - memcpy(&pinfo->attrmask, &getattr_res.obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&pinfo->attrmask, &getattr_res.obj_attributes.attrmask);
- nfs41_attr_cache_update(session_name_cache(session),
- file->fh.fileid, pinfo);
- }
- @@ -958,8 +952,7 @@ int nfs41_commit(
- if (do_getattr) {
- /* update the attribute cache */
- - memcpy(&pinfo->attrmask, &getattr_res.obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&pinfo->attrmask, &getattr_res.obj_attributes.attrmask);
- nfs41_attr_cache_update(session_name_cache(session),
- file->fh.fileid, pinfo);
- }
- @@ -1176,8 +1169,7 @@ int nfs41_getattr(
- if (file) {
- /* update the name cache with whatever attributes we got */
- - memcpy(&info->attrmask, &getattr_res.obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&info->attrmask, &getattr_res.obj_attributes.attrmask);
- nfs41_attr_cache_update(session_name_cache(session),
- file->fh.fileid, info);
- }
- @@ -1300,8 +1292,7 @@ int nfs41_remove(
- goto out;
- /* update the attributes of the parent directory */
- - memcpy(&info.attrmask, &getattr_res.obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&info.attrmask, &getattr_res.obj_attributes.attrmask);
- nfs41_attr_cache_update(session_name_cache(session),
- parent->fh.fileid, &info);
- @@ -1382,14 +1373,12 @@ int nfs41_rename(
- goto out;
- /* update the attributes of the source directory */
- - memcpy(&src_info.attrmask, &src_getattr_res.obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&src_info.attrmask, &src_getattr_res.obj_attributes.attrmask);
- nfs41_attr_cache_update(session_name_cache(session),
- src_dir->fh.fileid, &src_info);
- /* update the attributes of the destination directory */
- - memcpy(&dst_info.attrmask, &dst_getattr_res.obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&dst_info.attrmask, &dst_getattr_res.obj_attributes.attrmask);
- nfs41_attr_cache_update(session_name_cache(session),
- dst_dir->fh.fileid, &dst_info);
- @@ -1491,7 +1480,7 @@ int nfs41_setattr(
- if (compound_error(status = compound.res.status))
- goto out;
- - memcpy(&info->attrmask, &attr_request, sizeof(bitmap4));
- + bitmap4_cpy(&info->attrmask, &attr_request);
- nfs41_attr_cache_update(session_name_cache(session),
- file->fh.fileid, info);
- @@ -1586,14 +1575,12 @@ int nfs41_link(
- goto out;
- /* update the attributes of the destination directory */
- - memcpy(&info.attrmask, &getattr_res[0].obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&info.attrmask, &getattr_res[0].obj_attributes.attrmask);
- nfs41_attr_cache_update(session_name_cache(session),
- info.fileid, &info);
- /* add the new file handle and attributes to the name cache */
- - memcpy(&cinfo->attrmask, &getattr_res[1].obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&cinfo->attrmask, &getattr_res[1].obj_attributes.attrmask);
- AcquireSRWLockShared(&dst_dir->path->lock);
- nfs41_name_cache_insert(session_name_cache(session),
- dst_dir->path->path, target, &file.fh,
- @@ -2160,8 +2147,7 @@ enum nfsstat4 pnfs_rpc_layoutcommit(
- goto out;
- /* update the attribute cache */
- - memcpy(&info->attrmask, &getattr_res.obj_attributes.attrmask,
- - sizeof(bitmap4));
- + bitmap4_cpy(&info->attrmask, &getattr_res.obj_attributes.attrmask);
- nfs41_attr_cache_update(session_name_cache(session),
- file->fh.fileid, info);
- out:
- diff --git a/daemon/nfs41_xdr.c b/daemon/nfs41_xdr.c
- index d2f65be..3a1ff8d 100644
- --- a/daemon/nfs41_xdr.c
- +++ b/daemon/nfs41_xdr.c
- @@ -2371,7 +2371,7 @@ static bool_t decode_readdir_entry(
- xdrmem_create(&fattr_xdr, (char *)attrs.attr_vals, attrs.attr_vals_len, XDR_DECODE);
- if (!(decode_file_attrs(&fattr_xdr, &attrs, &entry->attr_info)))
- entry->attr_info.rdattr_error = NFS4ERR_BADXDR;
- - (void)memcpy(&entry->attr_info.attrmask, &attrs.attrmask, sizeof(bitmap4));
- + bitmap4_cpy(&entry->attr_info.attrmask, &attrs.attrmask);
- StringCchCopyA(entry->name, name_len, (STRSAFE_LPCSTR)name);
- it->buf_pos += (size_t)entry_len + name_len;
- @@ -2617,7 +2617,7 @@ static bool_t encode_file_attrs(
- xdrmem_create(&localxdr, (char *)attrs->attr_vals, NFS4_OPAQUE_LIMIT, XDR_ENCODE);
- attrs->attr_vals_len = 0;
- - ZeroMemory(&attrs->attrmask, sizeof(bitmap4));
- + bitmap4_clear(&attrs->attrmask);
- attrs->attrmask.count = info->attrmask.count;
- if (info->attrmask.count > 0) {
- diff --git a/daemon/util.h b/daemon/util.h
- index 7f7d585..e4876ba 100644
- --- a/daemon/util.h
- +++ b/daemon/util.h
- @@ -126,6 +126,25 @@ static __inline void bitmap_intersect(
- dst->count = min(dst->count, count);
- }
- +static __inline void bitmap4_cpy(
- + OUT bitmap4 *restrict dst,
- + IN const bitmap4 *restrict src)
- +{
- + (void)memcpy(dst, src, sizeof(bitmap4));
- +}
- +
- +static __inline void bitmap4_clear(
- + OUT bitmap4 *restrict dst)
- +{
- + /*
- + * gisburn: FIXME: Only set the count field to 0, and use
- + * Rational Purify/DrMemory to see if someone does not play
- + * by the rules
- + */
- + (void)memset(dst, 0, sizeof(bitmap4));
- +}
- +
- +
- ULONG nfs_file_info_to_attributes(
- IN const nfs41_file_info *info);
- void nfs_to_basic_info(
- --
- 2.45.1
- From a57074aa1be78c0fc85ca9e14b3700869379fcd6 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Fri, 26 Jul 2024 12:50:13 +0200
- Subject: [PATCH 2/6] daemon: Fix DrMemory "UNINITIALIZED READ" hits in
- |attr_cache_update()|
- Fix DrMemory hits in |attr_cache_update()|, which were triggered by
- using the request |bitmap4| instead of the response |bitmap4|
- DrMemory hits look like this:
- ---- snip ----
- Error #1: UNINITIALIZED READ: reading 8 byte(s)
- attr_cache_update [ms-nfs41-client\daemon\name_cache.c:323]
- nfs41_attr_cache_update [ms-nfs41-client\daemon\name_cache.c:957]
- nfs41_setattr [ms-nfs41-client\daemon\nfs41_ops.c:1495]
- handle_setexattr [ms-nfs41-client\daemon\ea.c:186]
- upcall_handle [ms-nfs41-client\daemon\upcall.c:220]
- nfsd_worker_thread_main [ms-nfs41-client\daemon\nfs41_daemon.c:188]
- nfsd_thread_main [ms-nfs41-client\daemon\nfs41_daemon.c:226]
- KERNEL32.dll!BaseThreadInitThunk +0x13 (0x00007ffe78f47374 <KERNEL32.dll+0x17374>)
- Error #2: UNINITIALIZED READ: reading 4 byte(s)
- attr_cache_update [ms-nfs41-client\daemon\name_cache.c:324]
- nfs41_attr_cache_update [ms-nfs41-client\daemon\name_cache.c:957]
- nfs41_setattr [ms-nfs41-client\daemon\nfs41_ops.c:1495]
- handle_setexattr [ms-nfs41-client\daemon\ea.c:186]
- upcall_handle [ms-nfs41-client\daemon\upcall.c:220]
- nfsd_worker_thread_main [ms-nfs41-client\daemon\nfs41_daemon.c:188]
- nfsd_thread_main [ms-nfs41-client\daemon\nfs41_daemon.c:226]
- KERNEL32.dll!BaseThreadInitThunk +0x13 (0x00007ffe78f47374 <KERNEL32.dll+0x17374>)
- ---- snip ----
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/nfs41_ops.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
- diff --git a/daemon/nfs41_ops.c b/daemon/nfs41_ops.c
- index fbb4fad..837d24a 100644
- --- a/daemon/nfs41_ops.c
- +++ b/daemon/nfs41_ops.c
- @@ -1480,7 +1480,7 @@ int nfs41_setattr(
- if (compound_error(status = compound.res.status))
- goto out;
- - bitmap4_cpy(&info->attrmask, &attr_request);
- + bitmap4_cpy(&info->attrmask, &getattr_res.obj_attributes.attrmask);
- nfs41_attr_cache_update(session_name_cache(session),
- file->fh.fileid, info);
- --
- 2.45.1
- From ec66d370ae8d252e7e8e0aa916c30be9497370d3 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Fri, 26 Jul 2024 13:24:00 +0200
- Subject: [PATCH 3/6] daemon: Add asserts for
- |FATTR4_WORD0_CHANGE|+|FATTR4_WORD1_MODE| before using data
- Add asserts to test for |FATTR4_WORD0_CHANGE|+|FATTR4_WORD1_MODE|
- before using the data for these attributes.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/acl.c | 4 ++++
- daemon/ea.c | 3 +++
- daemon/getattr.c | 2 ++
- daemon/open.c | 12 ++++++++++++
- daemon/readwrite.c | 6 ++++++
- daemon/setattr.c | 6 ++++++
- 6 files changed, 33 insertions(+)
- diff --git a/daemon/acl.c b/daemon/acl.c
- index 1a4f312..7ee91d9 100644
- --- a/daemon/acl.c
- +++ b/daemon/acl.c
- @@ -1428,7 +1428,11 @@ static int handle_setacl(void *daemon_context, nfs41_upcall *upcall)
- print_nfs41_file_info("handle_setacl: nfs41_setattr() success info OUT:", &info);
- }
- }
- +
- + EASSERT((info.attrmask.count >= 1) &&
- + (info.attrmask.arr[0] & FATTR4_WORD0_CHANGE));
- args->ctime = info.change;
- +
- if (args->query & DACL_SECURITY_INFORMATION)
- free(nfs4_acl.aces);
- out:
- diff --git a/daemon/ea.c b/daemon/ea.c
- index d5e8d92..b7925c7 100644
- --- a/daemon/ea.c
- +++ b/daemon/ea.c
- @@ -3,6 +3,7 @@
- *
- * Olga Kornievskaia <aglo@umich.edu>
- * Casey Bodley <cbodley@umich.edu>
- + * Roland Mainz <roland.mainz@nrubsig.org>
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- @@ -190,6 +191,8 @@ static int handle_setexattr(void *daemon_context, nfs41_upcall *upcall)
- goto out;
- }
- + EASSERT((info.attrmask.count >= 1) &&
- + (info.attrmask.arr[0] & FATTR4_WORD0_CHANGE));
- args->ctime = info.change;
- goto out;
- }
- diff --git a/daemon/getattr.c b/daemon/getattr.c
- index 2b8a91d..c3b79b6 100644
- --- a/daemon/getattr.c
- +++ b/daemon/getattr.c
- @@ -168,6 +168,8 @@ static int handle_getattr(void *daemon_context, nfs41_upcall *upcall)
- switch (args->query_class) {
- case FileBasicInformation:
- nfs_to_basic_info(state->file.name.name, &info, &args->basic_info);
- + EASSERT((info.attrmask.count >= 1) &&
- + (info.attrmask.arr[0] & FATTR4_WORD0_CHANGE));
- args->ctime = info.change;
- break;
- case FileStandardInformation:
- diff --git a/daemon/open.c b/daemon/open.c
- index 6769e93..a033a65 100644
- --- a/daemon/open.c
- +++ b/daemon/open.c
- @@ -760,7 +760,11 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
- }
- nfs_to_basic_info(state->file.name.name, &info, &args->basic_info);
- nfs_to_standard_info(&info, &args->std_info);
- + EASSERT((info.attrmask.count >= 2) &&
- + (info.attrmask.arr[1] & FATTR4_WORD1_MODE));
- args->mode = info.mode;
- + EASSERT((info.attrmask.count >= 1) &&
- + (info.attrmask.arr[0] & FATTR4_WORD0_CHANGE));
- args->changeattr = info.change;
- } else if (open_for_attributes(state->type, args->access_mask,
- args->disposition, status)) {
- @@ -771,7 +775,11 @@ static int handle_open(void *daemon_context, nfs41_upcall *upcall)
- nfs_to_basic_info(state->file.name.name, &info, &args->basic_info);
- nfs_to_standard_info(&info, &args->std_info);
- + EASSERT((info.attrmask.count >= 2) &&
- + (info.attrmask.arr[1] & FATTR4_WORD1_MODE));
- args->mode = info.mode;
- + EASSERT((info.attrmask.count >= 1) &&
- + (info.attrmask.arr[0] & FATTR4_WORD0_CHANGE));
- args->changeattr = info.change;
- #ifdef NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES
- @@ -997,7 +1005,11 @@ create_chgrp_out:
- nfs_to_basic_info(state->file.name.name, &info, &args->basic_info);
- nfs_to_standard_info(&info, &args->std_info);
- + EASSERT((info.attrmask.count >= 2) &&
- + (info.attrmask.arr[1] & FATTR4_WORD1_MODE));
- args->mode = info.mode;
- + EASSERT((info.attrmask.count >= 1) &&
- + (info.attrmask.arr[0] & FATTR4_WORD0_CHANGE));
- args->changeattr = info.change;
- }
- diff --git a/daemon/readwrite.c b/daemon/readwrite.c
- index 694ea88..a1e521b 100644
- --- a/daemon/readwrite.c
- +++ b/daemon/readwrite.c
- @@ -238,7 +238,11 @@ retry_write:
- if (status)
- goto out;
- }
- +
- + EASSERT((info.attrmask.count >= 1) &&
- + (info.attrmask.arr[0] & FATTR4_WORD0_CHANGE));
- args->ctime = info.change;
- +
- out:
- args->out_len = len;
- return nfs_to_windows_error(status, ERROR_NET_WRITE_FAULT);
- @@ -268,6 +272,8 @@ static int write_to_pnfs(
- status = ERROR_WRITE_FAULT;
- goto out;
- }
- + EASSERT((info.attrmask.count >= 1) &&
- + (info.attrmask.arr[0] & FATTR4_WORD0_CHANGE));
- args->ctime = info.change;
- out:
- return status;
- diff --git a/daemon/setattr.c b/daemon/setattr.c
- index 8dc764d..9053e8e 100644
- --- a/daemon/setattr.c
- +++ b/daemon/setattr.c
- @@ -144,6 +144,8 @@ static int handle_nfs41_setattr(void *daemon_context, setattr_upcall_args *args)
- nfs_error_string(status)));
- status = nfs_to_windows_error(status, ERROR_NOT_SUPPORTED);
- }
- + EASSERT((info.attrmask.count >= 1) &&
- + (info.attrmask.arr[0] & FATTR4_WORD0_CHANGE));
- args->ctime = info.change;
- out:
- return status;
- @@ -382,6 +384,8 @@ static int handle_nfs41_set_size(void *daemon_context, setattr_upcall_args *args
- AcquireSRWLockExclusive(&state->lock);
- state->pnfs_last_offset = info.size ? info.size - 1 : 0;
- ReleaseSRWLockExclusive(&state->lock);
- + EASSERT((info.attrmask.count >= 1) &&
- + (info.attrmask.arr[0] & FATTR4_WORD0_CHANGE));
- args->ctime = info.change;
- out:
- return status = nfs_to_windows_error(status, ERROR_NOT_SUPPORTED);
- @@ -484,6 +488,8 @@ static int handle_nfs41_link(void *daemon_context, setattr_upcall_args *args)
- nfs_error_string(status)));
- status = nfs_to_windows_error(status, ERROR_INVALID_PARAMETER);
- }
- + EASSERT((info.attrmask.count >= 1) &&
- + (info.attrmask.arr[0] & FATTR4_WORD0_CHANGE));
- args->ctime = info.change;
- out:
- return status;
- --
- 2.45.1
- From a5d5db25532a4f1e69c240217f90b735749c28b4 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Fri, 26 Jul 2024 13:53:35 +0200
- Subject: [PATCH 4/6] daemon: Add
- |stateid4_cpy()|+|stateid4_clear()|+|stateid4_cmd()| utility functions
- Add |stateid4_cpy()|, |stateid4_clear()| and |stateid4_cmd()| utility
- functions, so we have a typesafe way to init+copy |stateid4| types.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- daemon/delegation.c | 18 +++++++++---------
- daemon/lock.c | 9 +++++----
- daemon/nfs41_ops.c | 2 +-
- daemon/open.c | 12 ++++++------
- daemon/pnfs_layout.c | 7 ++++---
- daemon/readwrite.c | 3 ++-
- daemon/recovery.c | 31 ++++++++++++++++---------------
- daemon/util.h | 19 +++++++++++++++++++
- 8 files changed, 62 insertions(+), 39 deletions(-)
- diff --git a/daemon/delegation.c b/daemon/delegation.c
- index 5318d2c..d91eecd 100644
- --- a/daemon/delegation.c
- +++ b/daemon/delegation.c
- @@ -3,6 +3,7 @@
- *
- * Olga Kornievskaia <aglo@umich.edu>
- * Casey Bodley <cbodley@umich.edu>
- + * Roland Mainz <roland.mainz@nrubsig.org>
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- @@ -226,10 +227,10 @@ static int delegation_flush_locks(
- /* get the starting open/lock stateid */
- AcquireSRWLockShared(&open->lock);
- if (open->locks.stateid.seqid) {
- - memcpy(&stateid.stateid, &open->locks.stateid, sizeof(stateid4));
- + stateid4_cpy(&stateid.stateid, &open->locks.stateid);
- stateid.type = STATEID_LOCK;
- } else {
- - memcpy(&stateid.stateid, &open->stateid, sizeof(stateid4));
- + stateid4_cpy(&stateid.stateid, &open->stateid);
- stateid.type = STATEID_OPEN;
- }
- ReleaseSRWLockShared(&open->lock);
- @@ -249,7 +250,7 @@ static int delegation_flush_locks(
- AcquireSRWLockExclusive(&open->lock);
- if (open->locks.stateid.seqid == 0) {
- /* if it's a new lock stateid, copy it in */
- - memcpy(&open->locks.stateid, &stateid.stateid, sizeof(stateid4));
- + stateid4_cpy(&open->locks.stateid, &stateid.stateid);
- } else if (stateid.stateid.seqid > open->locks.stateid.seqid) {
- /* update the seqid if it's more recent */
- open->locks.stateid.seqid = stateid.stateid.seqid;
- @@ -313,7 +314,7 @@ out_downcall:
- stateid.open = NULL;
- stateid.delegation = deleg;
- AcquireSRWLockShared(&deleg->lock);
- - memcpy(&stateid.stateid, &deleg->state.stateid, sizeof(stateid4));
- + stateid4_cpy(&stateid.stateid, &deleg->state.stateid);
- ReleaseSRWLockShared(&deleg->lock);
- status = nfs41_delegreturn(client->session,
- @@ -366,7 +367,7 @@ out:
- return status;
- out_return: /* return the delegation on failure */
- - memcpy(&stateid.stateid, &delegation->stateid, sizeof(stateid4));
- + stateid4_cpy(&stateid.stateid, &delegation->stateid);
- stateid.type = STATEID_DELEG_FILE;
- stateid.open = NULL;
- stateid.delegation = NULL;
- @@ -498,7 +499,7 @@ int nfs41_delegate_open(
- stateid.open = NULL;
- stateid.delegation = deleg;
- stateid.type = STATEID_DELEG_FILE;
- - memcpy(&stateid.stateid, &deleg->state.stateid, sizeof(stateid4));
- + stateid4_cpy(&stateid.stateid, &deleg->state.stateid);
- }
- if (!status) {
- DPRINTF(1, ("nfs41_delegate_open: updating srv_open from %x to %x\n",
- @@ -569,8 +570,7 @@ int nfs41_delegation_to_open(
- deleg_stateid.open = open;
- deleg_stateid.delegation = NULL;
- deleg_stateid.type = STATEID_DELEG_FILE;
- - memcpy(&deleg_stateid.stateid, &open->delegation.state->state.stateid,
- - sizeof(stateid4));
- + stateid4_cpy(&deleg_stateid.stateid, &open->delegation.state->state.stateid);
- ReleaseSRWLockShared(&open->delegation.state->lock);
- ReleaseSRWLockExclusive(&open->lock);
- @@ -587,7 +587,7 @@ int nfs41_delegation_to_open(
- AcquireSRWLockExclusive(&open->lock);
- if (status == NFS4_OK) {
- /* save the new open stateid */
- - memcpy(&open->stateid, &open_stateid, sizeof(stateid4));
- + stateid4_cpy(&open->stateid, &open_stateid);
- open->do_close = 1;
- } else if (open->do_close && (status == NFS4ERR_BAD_STATEID ||
- status == NFS4ERR_STALE_STATEID || status == NFS4ERR_EXPIRED)) {
- diff --git a/daemon/lock.c b/daemon/lock.c
- index 01cbe66..da306cc 100644
- --- a/daemon/lock.c
- +++ b/daemon/lock.c
- @@ -3,6 +3,7 @@
- *
- * Olga Kornievskaia <aglo@umich.edu>
- * Casey Bodley <cbodley@umich.edu>
- + * Roland Mainz <roland.mainz@nrubsig.org>
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- @@ -41,13 +42,13 @@ static void lock_stateid_arg(
- AcquireSRWLockShared(&state->lock);
- if (state->locks.stateid.seqid) {
- - memcpy(&arg->stateid, &state->locks.stateid, sizeof(stateid4));
- + stateid4_cpy(&arg->stateid, &state->locks.stateid);
- arg->type = STATEID_LOCK;
- } else if (state->do_close) {
- - memcpy(&arg->stateid, &state->stateid, sizeof(stateid4));
- + stateid4_cpy(&arg->stateid, &state->stateid);
- arg->type = STATEID_OPEN;
- } else {
- - memset(&arg->stateid, 0, sizeof(stateid4));
- + stateid4_clear(&arg->stateid);
- arg->type = STATEID_SPECIAL;
- }
- ReleaseSRWLockShared(&state->lock);
- @@ -60,7 +61,7 @@ static void lock_stateid_update(
- {
- if (state->locks.stateid.seqid == 0) {
- /* if it's a new lock stateid, copy it in */
- - memcpy(&state->locks.stateid, stateid, sizeof(stateid4));
- + stateid4_cpy(&state->locks.stateid, stateid);
- } else if (stateid->seqid > state->locks.stateid.seqid) {
- /* update the seqid if it's more recent */
- state->locks.stateid.seqid = stateid->seqid;
- diff --git a/daemon/nfs41_ops.c b/daemon/nfs41_ops.c
- index 837d24a..c1c72f5 100644
- --- a/daemon/nfs41_ops.c
- +++ b/daemon/nfs41_ops.c
- @@ -374,7 +374,7 @@ static void open_delegation_return(
- stateid.open = NULL;
- stateid.delegation = NULL;
- stateid.type = STATEID_DELEG_FILE;
- - memcpy(&stateid.stateid, &delegation->stateid, sizeof(stateid4));
- + stateid4_cpy(&stateid.stateid, &delegation->stateid);
- status = nfs41_delegreturn(session, file, &stateid, try_recovery);
- diff --git a/daemon/open.c b/daemon/open.c
- index a033a65..f7c1d04 100644
- --- a/daemon/open.c
- +++ b/daemon/open.c
- @@ -241,7 +241,7 @@ void nfs41_open_stateid_arg(
- AcquireSRWLockShared(&deleg->lock);
- if (deleg->status == DELEGATION_GRANTED) {
- arg->type = STATEID_DELEG_FILE;
- - memcpy(&arg->stateid, &deleg->state.stateid, sizeof(stateid4));
- + stateid4_cpy(&arg->stateid, &deleg->state.stateid);
- }
- ReleaseSRWLockShared(&deleg->lock);
- @@ -257,13 +257,13 @@ void nfs41_open_stateid_arg(
- }
- if (state->locks.stateid.seqid) {
- - memcpy(&arg->stateid, &state->locks.stateid, sizeof(stateid4));
- + stateid4_cpy(&arg->stateid, &state->locks.stateid);
- arg->type = STATEID_LOCK;
- } else if (state->do_close) {
- - memcpy(&arg->stateid, &state->stateid, sizeof(stateid4));
- + stateid4_cpy(&arg->stateid, &state->stateid);
- arg->type = STATEID_OPEN;
- } else {
- - memset(&arg->stateid, 0, sizeof(stateid4));
- + stateid4_clear(&arg->stateid);
- arg->type = STATEID_SPECIAL;
- }
- out:
- @@ -1089,7 +1089,7 @@ static void cancel_open(IN nfs41_upcall *upcall)
- stateid.open = state;
- stateid.delegation = NULL;
- stateid.type = STATEID_OPEN;
- - memcpy(&stateid.stateid, &state->stateid, sizeof(stateid4));
- + stateid4_cpy(&stateid.stateid, &state->stateid);
- status = nfs41_close(state->session, &state->file, &stateid);
- if (status) {
- @@ -1148,7 +1148,7 @@ static int do_nfs41_close(nfs41_open_state *state)
- stateid.open = state;
- stateid.delegation = NULL;
- stateid.type = STATEID_OPEN;
- - memcpy(&stateid.stateid, &state->stateid, sizeof(stateid4));
- + stateid4_cpy(&stateid.stateid, &state->stateid);
- status = nfs41_close(state->session, &state->file, &stateid);
- if (status) {
- diff --git a/daemon/pnfs_layout.c b/daemon/pnfs_layout.c
- index ec99840..a83a0e7 100644
- --- a/daemon/pnfs_layout.c
- +++ b/daemon/pnfs_layout.c
- @@ -3,6 +3,7 @@
- *
- * Olga Kornievskaia <aglo@umich.edu>
- * Casey Bodley <cbodley@umich.edu>
- + * Roland Mainz <roland.mainz@nrubsig.org>
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- @@ -379,7 +380,7 @@ static enum pnfs_status layout_update_stateid(
- if (state->stateid.seqid == 0) {
- /* save a new layout stateid */
- - memcpy(&state->stateid, stateid, sizeof(stateid4));
- + stateid4_cpy(&state->stateid, stateid);
- } else if (memcmp(&state->stateid.other, stateid->other,
- NFS4_STATEID_OTHER) == 0) {
- /* update an existing layout stateid */
- @@ -527,7 +528,7 @@ static enum pnfs_status layout_fetch(
- /* if there's an existing layout stateid, use it */
- if (state->stateid.seqid) {
- - memcpy(&layout_stateid.stateid, &state->stateid, sizeof(stateid4));
- + stateid4_cpy(&layout_stateid.stateid, &state->stateid);
- layout_stateid.type = STATEID_LAYOUT;
- stateid = &layout_stateid;
- }
- @@ -813,7 +814,7 @@ static enum pnfs_status file_layout_return(
- /* 12.5.3. Layout Stateid: Once a client has no more
- * layouts on a file, the layout stateid is no longer
- * valid and MUST NOT be used. */
- - ZeroMemory(&state->stateid, sizeof(stateid4));
- + stateid4_clear(&state->stateid);
- }
- }
- diff --git a/daemon/readwrite.c b/daemon/readwrite.c
- index a1e521b..9320970 100644
- --- a/daemon/readwrite.c
- +++ b/daemon/readwrite.c
- @@ -3,6 +3,7 @@
- *
- * Olga Kornievskaia <aglo@umich.edu>
- * Casey Bodley <cbodley@umich.edu>
- + * Roland Mainz <roland.mainz@nrubsig.org>
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- @@ -80,7 +81,7 @@ static int read_from_mds(
- p, &bytes_read, &eof);
- if (status == NFS4ERR_OPENMODE && !len) {
- stateid->type = STATEID_SPECIAL;
- - memcpy(&stateid->stateid, &special_read_stateid, sizeof(stateid4));
- + stateid4_cpy(&stateid->stateid, &special_read_stateid);
- continue;
- } else if (status && !len) {
- status = nfs_to_windows_error(status, ERROR_NET_WRITE_FAULT);
- diff --git a/daemon/recovery.c b/daemon/recovery.c
- index bce908f..7c45671 100644
- --- a/daemon/recovery.c
- +++ b/daemon/recovery.c
- @@ -3,6 +3,7 @@
- *
- * Olga Kornievskaia <aglo@umich.edu>
- * Casey Bodley <cbodley@umich.edu>
- + * Roland Mainz <roland.mainz@nrubsig.org>
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- @@ -252,7 +253,7 @@ static int recover_open(
- AcquireSRWLockExclusive(&open->lock);
- /* update the open stateid */
- - memcpy(&open->stateid, &stateid, sizeof(stateid4));
- + stateid4_cpy(&open->stateid, &stateid);
- open->do_close = TRUE;
- if (open->delegation.state) {
- @@ -291,7 +292,7 @@ static int recover_locks(
- AcquireSRWLockExclusive(&open->lock);
- /* initialize the open stateid for the first lock request */
- - memcpy(&stateid.stateid, &open->stateid, sizeof(stateid4));
- + stateid4_cpy(&stateid.stateid, &open->stateid);
- stateid.type = STATEID_OPEN;
- stateid.open = open;
- stateid.delegation = NULL;
- @@ -325,7 +326,7 @@ static int recover_locks(
- if (status != NFS4ERR_BADSESSION) {
- /* if we got a lock stateid back, save the lock with the open */
- if (stateid.type == STATEID_LOCK)
- - memcpy(&open->locks.stateid, &stateid.stateid, sizeof(stateid4));
- + stateid4_cpy(&open->locks.stateid, &stateid.stateid);
- else
- open->locks.stateid.seqid = 0;
- }
- @@ -580,7 +581,7 @@ static uint32_t stateid_array(
- deleg = list_container(entry, nfs41_delegation_state, client_entry);
- AcquireSRWLockShared(&deleg->lock);
- /* delegation stateid */
- - memcpy(&stateids[i].stateid, &deleg->state.stateid, sizeof(stateid4));
- + stateid4_cpy(&stateids[i].stateid, &deleg->state.stateid);
- stateids[i].type = STATEID_DELEG_FILE;
- stateids[i].delegation = deleg;
- i++;
- @@ -592,13 +593,13 @@ static uint32_t stateid_array(
- AcquireSRWLockShared(&open->lock);
- /* open stateid */
- - memcpy(&stateids[i].stateid, &open->stateid, sizeof(stateid4));
- + stateid4_cpy(&stateids[i].stateid, &open->stateid);
- stateids[i].type = STATEID_OPEN;
- stateids[i].open = open;
- i++;
- if (open->locks.stateid.seqid) { /* lock stateid? */
- - memcpy(&stateids[i].stateid, &open->locks.stateid, sizeof(stateid4));
- + stateid4_cpy(&stateids[i].stateid, &open->locks.stateid);
- stateids[i].type = STATEID_LOCK;
- stateids[i].open = open;
- i++;
- @@ -607,7 +608,7 @@ static uint32_t stateid_array(
- if (open->layout) { /* layout stateid? */
- AcquireSRWLockShared(&open->layout->lock);
- if (open->layout->stateid.seqid) {
- - memcpy(&stateids[i].stateid, &open->layout->stateid, sizeof(stateid4));
- + stateid4_cpy(&stateids[i].stateid, &open->layout->stateid);
- stateids[i].type = STATEID_LAYOUT;
- stateids[i].open = open;
- i++;
- @@ -711,8 +712,8 @@ static bool_t recover_stateid_open(
- /* if the source stateid is different, update and retry */
- AcquireSRWLockShared(&stateid->open->lock);
- - if (memcmp(&stateid->stateid, source, sizeof(stateid4))) {
- - memcpy(&stateid->stateid, source, sizeof(stateid4));
- + if (stateid4_cmp(&stateid->stateid, source)) {
- + stateid4_cpy(&stateid->stateid, source);
- retry = TRUE;
- }
- ReleaseSRWLockShared(&stateid->open->lock);
- @@ -731,7 +732,7 @@ static bool_t recover_stateid_lock(
- /* if the source stateid is different, update and retry */
- AcquireSRWLockShared(&stateid->open->lock);
- - if (memcmp(&stateid->stateid, source, sizeof(stateid4))) {
- + if (stateid4_cmp(&stateid->stateid, source)) {
- if (argop->op == OP_LOCK && source->seqid == 0) {
- /* resend LOCK with an open stateid */
- nfs41_lock_args *lock = (nfs41_lock_args*)argop->arg;
- @@ -741,7 +742,7 @@ static bool_t recover_stateid_lock(
- source = &stateid->open->stateid;
- }
- - memcpy(&stateid->stateid, source, sizeof(stateid4));
- + stateid4_cpy(&stateid->stateid, source);
- retry = TRUE;
- }
- ReleaseSRWLockShared(&stateid->open->lock);
- @@ -765,8 +766,8 @@ static bool_t recover_stateid_delegation(
- nfs41_delegation_state *deleg = stateid->open->delegation.state;
- stateid4 *source = &deleg->state.stateid;
- AcquireSRWLockShared(&deleg->lock);
- - if (memcmp(&stateid->stateid, source, sizeof(stateid4))) {
- - memcpy(&stateid->stateid, source, sizeof(stateid4));
- + if (stateid4_cmp(&stateid->stateid, source)) {
- + stateid4_cpy(&stateid->stateid, source);
- retry = TRUE;
- }
- ReleaseSRWLockShared(&deleg->lock);
- @@ -776,8 +777,8 @@ static bool_t recover_stateid_delegation(
- nfs41_delegation_state *deleg = stateid->delegation;
- stateid4 *source = &deleg->state.stateid;
- AcquireSRWLockShared(&deleg->lock);
- - if (memcmp(&stateid->stateid, source, sizeof(stateid4))) {
- - memcpy(&stateid->stateid, source, sizeof(stateid4));
- + if (stateid4_cmp(&stateid->stateid, source)) {
- + stateid4_cpy(&stateid->stateid, source);
- retry = TRUE;
- }
- ReleaseSRWLockShared(&deleg->lock);
- diff --git a/daemon/util.h b/daemon/util.h
- index e4876ba..a191ffa 100644
- --- a/daemon/util.h
- +++ b/daemon/util.h
- @@ -144,6 +144,25 @@ static __inline void bitmap4_clear(
- (void)memset(dst, 0, sizeof(bitmap4));
- }
- +static __inline void stateid4_cpy(
- + OUT stateid4 *restrict dst,
- + IN const stateid4 *restrict src)
- +{
- + (void)memcpy(dst, src, sizeof(stateid4));
- +}
- +
- +static __inline void stateid4_clear(
- + OUT stateid4 *restrict dst)
- +{
- + (void)memset(dst, 0, sizeof(stateid4));
- +}
- +
- +static __inline int stateid4_cmp(
- + IN const stateid4 *restrict s1,
- + IN const stateid4 *restrict s2)
- +{
- + return memcmp(s1, s2, sizeof(stateid4));
- +}
- ULONG nfs_file_info_to_attributes(
- IN const nfs41_file_info *info);
- --
- 2.45.1
- From f6cff2b3f9de8376ac17556515df43c25117fb2d Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Sat, 27 Jul 2024 16:11:22 +0200
- Subject: [PATCH 5/6] cygwin: msnfs41client *run_daemon should test for
- idmapper dependencies
- msnfs41client.bash run_daemon/sys_run_daemon should test for idmapper
- dependencies (e.g. /bin/ksh93, /lib/msnfs41client/cygwin_idmapper.ksh)
- Reported-by: Dan Shelton <dan.f.shelton@gmail.com>
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- cygwin/devel/msnfs41client.bash | 15 +++++++++++++++
- 1 file changed, 15 insertions(+)
- diff --git a/cygwin/devel/msnfs41client.bash b/cygwin/devel/msnfs41client.bash
- index 34a9634..0553938 100644
- --- a/cygwin/devel/msnfs41client.bash
- +++ b/cygwin/devel/msnfs41client.bash
- @@ -561,6 +561,17 @@ function require_cmd
- return 0
- }
- +function require_file
- +{
- + typeset testfile="$1"
- +
- + if [[ ! -f "$testfile" ]] ; then
- + printf $"%s: File %q not found in %q\n" "$0" "$cmd" "$PWD" 1>&2
- + return 1
- + fi
- + return 0
- +}
- +
- # execute cmd as Windows user "SYSTEM"
- function su_system
- {
- @@ -658,6 +669,8 @@ function main
- require_cmd 'nfsd.exe' || (( numerr++ ))
- require_cmd 'nfsd_debug.exe' || (( numerr++ ))
- require_cmd 'nfs_mount.exe' || (( numerr++ ))
- + require_cmd 'ksh93.exe' || (( numerr++ ))
- + require_file '/lib/msnfs41client/cygwin_idmapper.ksh' || (( numerr++ ))
- (( numerr > 0 )) && return 1
- nfsclient_rundeamon
- @@ -670,6 +683,8 @@ function main
- require_cmd 'nfsd.exe' || (( numerr++ ))
- require_cmd 'nfsd_debug.exe' || (( numerr++ ))
- require_cmd 'nfs_mount.exe' || (( numerr++ ))
- + require_cmd 'ksh93.exe' || (( numerr++ ))
- + require_file '/lib/msnfs41client/cygwin_idmapper.ksh' || (( numerr++ ))
- if ! is_windows_admin_account ; then
- printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
- (( numerr++ ))
- --
- 2.45.1
- From 94f6c896fb914b98b5505e4c4c399db6e5e3da47 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Sat, 27 Jul 2024 16:29:10 +0200
- Subject: [PATCH 6/6] cygwin: make -f cygwin/Makefile installdest on a clean
- repro fails
- make -f cygwin/Makefile installdest on a clean repro fails due
- to missing dependencies.
- Reported-by: Dan Shelton <dan.f.shelton@gmail.com>
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- cygwin/Makefile | 8 ++++++++
- 1 file changed, 8 insertions(+)
- diff --git a/cygwin/Makefile b/cygwin/Makefile
- index 15d5336..8a2a7b5 100644
- --- a/cygwin/Makefile
- +++ b/cygwin/Makefile
- @@ -30,6 +30,11 @@ $(VS_BUILD_DIR32)/nfsd.exe \
- $(VS_BUILD_DIR64)/nfs41_driver.sys \
- $(VS_BUILD_DIR64)/libtirpc.dll: build
- +# trigger "build_testutils" target when these binaries are needed
- +$(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.exe \
- + $(PROJECT_BASEDIR_DIR)/tests/winfsinfo1/winfsinfo.exe \
- + $(PROJECT_BASEDIR_DIR)/tests/winsg/winsg.exe: build_testutils
- +
- #
- # build the code
- #
- @@ -86,6 +91,9 @@ installdest: \
- $(PROJECT_BASEDIR_DIR)/nfs41rdr.inf \
- $(PROJECT_BASEDIR_DIR)/etc_netconfig \
- $(PROJECT_BASEDIR_DIR)/ms-nfs41-idmap.conf \
- + $(PROJECT_BASEDIR_DIR)/tests/ea/nfs_ea.exe \
- + $(PROJECT_BASEDIR_DIR)/tests/winfsinfo1/winfsinfo.exe \
- + $(PROJECT_BASEDIR_DIR)/tests/winsg/winsg.exe \
- $(CYGWIN_MAKEFILE_DIR)/devel/msnfs41client.bash
- # installdest 32bit Windows
- make -f $(CYGWIN_MAKEFILE_DIR)/Makefile.install \
- --
- 2.45.1
msnfs41client: Patches for DrMemory hits, code cleanup, startup dependencies checks+misc, 2024-07-27
Posted by Anonymous on Sat 27th Jul 2024 16:58
raw | new post
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.