From c0bb20c64480b1e10ce78efee0e7f9df230d2513 Mon Sep 17 00:00:00 2001 From: YO4 Date: Sat, 4 Mar 2023 21:47:23 +0900 Subject: [PATCH 1/3] fix unlink in container Deleting files returns STATUS_INVALID_PARAMETE on a bind mounted file system in hyper-v container with FILE_DISPOSITION_POSIX_SEMANTICS. Therefore fall back to default method. This code is suggeted by dscho and I change it more simple. --- winsup/cygwin/syscalls.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 5c7f46a992..ac89888ce2 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -731,7 +731,10 @@ _unlink_nt (path_conv &pc, bool shareable) /* Trying to delete in-use executables and DLLs using FILE_DISPOSITION_POSIX_SEMANTICS returns STATUS_CANNOT_DELETE. Fall back to the default method. */ - if (status != STATUS_CANNOT_DELETE) + /* Additionaly that returns STATUS_INVALID_PARAMETER + on a bind mounted fs in hyper-v container. Falling back too. */ + if (status != STATUS_CANNOT_DELETE + && status != STATUS_INVALID_PARAMETER) goto out; } From 502dc8e66059bc46e7dc2ae35392948594f3be34 Mon Sep 17 00:00:00 2001 From: YO4 Date: Sat, 4 Mar 2023 22:09:19 +0900 Subject: [PATCH 2/3] fix rename in container Renaming files returns STATUS_INVALID_PARAMETE on a bind mounted file system in hyper-v container with FILE_RENAME_POSIX_SEMANTICS. Disable the use_posix_semantics flag and retry. --- winsup/cygwin/syscalls.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index ac89888ce2..69699c8aa9 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -2438,6 +2438,7 @@ rename2 (const char *oldpath, const char *newpath, unsigned int at2flags) && !oldpc.isremote () && oldpc.fs_is_ntfs (); +ignore_posix_semantics_retry: /* Opening the file must be part of the transaction. It's not sufficient to call only NtSetInformationFile under the transaction. Therefore we have to start the transaction here, if necessary. Don't start @@ -2682,6 +2683,15 @@ rename2 (const char *oldpath, const char *newpath, unsigned int at2flags) unlink_nt (*removepc); res = 0; } + else if (use_posix_semantics && status == STATUS_INVALID_PARAMETER) + { + /* NtSetInformationFile returns STATUS_INVALID_PARAMETER + on a bind mounted file system in hyper-v container + with FILE_RENAME_POSIX_SEMANTICS. + Disable the use_posix semntics flag and retry. */ + use_posix_semantics = 0; + goto ignore_posix_semantics_retry; + } else __seterrno_from_nt_status (status); } From 749d3a29aeb3dbc6b8df68fec66cd6dc2a452f18 Mon Sep 17 00:00:00 2001 From: YO4 Date: Sat, 4 Mar 2023 22:24:23 +0900 Subject: [PATCH 3/3] log disabling posix semantics --- winsup/cygwin/syscalls.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 69699c8aa9..ca40681cd4 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -736,6 +736,9 @@ _unlink_nt (path_conv &pc, bool shareable) if (status != STATUS_CANNOT_DELETE && status != STATUS_INVALID_PARAMETER) goto out; + debug_printf ("NtSetInformationFile (%S, FileDispositionInformationEx)" + " returns %y with posix semantics. Disable it and retry.", + pc.get_nt_native_path (), status); } /* If the R/O attribute is set, we have to open the file with @@ -2689,6 +2692,11 @@ rename2 (const char *oldpath, const char *newpath, unsigned int at2flags) on a bind mounted file system in hyper-v container with FILE_RENAME_POSIX_SEMANTICS. Disable the use_posix semntics flag and retry. */ + debug_printf ("NtSetInformationFile " + "(%S, %S, FileRenameInformationEx) failed " + "with posix semantics. Disable it and retry.", + oldpc.get_nt_native_path (), + newpc.get_nt_native_path ()); use_posix_semantics = 0; goto ignore_posix_semantics_retry; }