mount_helper_windows.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // +build windows
  2. /*
  3. Copyright 2019 The Kubernetes Authors.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package mount
  15. import (
  16. "os"
  17. "syscall"
  18. "k8s.io/klog"
  19. )
  20. // following failure codes are from https://docs.microsoft.com/en-us/windows/desktop/debug/system-error-codes--1300-1699-
  21. // ERROR_BAD_NETPATH = 53
  22. // ERROR_NETWORK_BUSY = 54
  23. // ERROR_UNEXP_NET_ERR = 59
  24. // ERROR_NETNAME_DELETED = 64
  25. // ERROR_NETWORK_ACCESS_DENIED = 65
  26. // ERROR_BAD_DEV_TYPE = 66
  27. // ERROR_BAD_NET_NAME = 67
  28. // ERROR_SESSION_CREDENTIAL_CONFLICT = 1219
  29. // ERROR_LOGON_FAILURE = 1326
  30. var errorNoList = [...]int{53, 54, 59, 64, 65, 66, 67, 1219, 1326}
  31. // IsCorruptedMnt return true if err is about corrupted mount point
  32. func IsCorruptedMnt(err error) bool {
  33. if err == nil {
  34. return false
  35. }
  36. var underlyingError error
  37. switch pe := err.(type) {
  38. case nil:
  39. return false
  40. case *os.PathError:
  41. underlyingError = pe.Err
  42. case *os.LinkError:
  43. underlyingError = pe.Err
  44. case *os.SyscallError:
  45. underlyingError = pe.Err
  46. }
  47. if ee, ok := underlyingError.(syscall.Errno); ok {
  48. for _, errno := range errorNoList {
  49. if int(ee) == errno {
  50. klog.Warningf("IsCorruptedMnt failed with error: %v, error code: %v", err, errno)
  51. return true
  52. }
  53. }
  54. }
  55. return false
  56. }