Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. lock.c
  5. Abstract:
  6. this file contains the routines that help with managing the
  7. volume locks.
  8. Author:
  9. Molly Brown (mollybro) 04-Jan-2001
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #ifdef ALLOC_PRAGMA
  14. #pragma alloc_text( PAGE, SrPauseVolumeActivity )
  15. #pragma alloc_text( PAGE, SrResumeVolumeActivity )
  16. #endif // ALLOC_PRAGMA
  17. /***************************************************************************++
  18. Routine Description:
  19. This routine will exclusively acquire the ActivityLock for each volume
  20. in the system. Once the lock is acquired, we set the flag in the device
  21. extension saying that we know it is acquired so that we know what we need
  22. to release in case of an error.
  23. Note: This routine assumes that the DeviceExtensionListLock is already
  24. held, either shared or exclusive.
  25. Arguments:
  26. None
  27. Return Value:
  28. Returns STATUS_SUCCESS if all the locks were acquired successfully and
  29. returns STATUS_LOCK_NOT_GRANTED otherwise.
  30. --***************************************************************************/
  31. NTSTATUS
  32. SrPauseVolumeActivity (
  33. )
  34. {
  35. NTSTATUS status = STATUS_LOCK_NOT_GRANTED;
  36. PLIST_ENTRY pCurrentEntry;
  37. PSR_DEVICE_EXTENSION pExtension;
  38. ASSERT( IS_DEVICE_EXTENSION_LIST_LOCK_ACQUIRED() );
  39. try {
  40. for (pCurrentEntry = global->DeviceExtensionListHead.Flink;
  41. pCurrentEntry != &global->DeviceExtensionListHead;
  42. pCurrentEntry = pCurrentEntry->Flink) {
  43. pExtension = CONTAINING_RECORD( pCurrentEntry,
  44. SR_DEVICE_EXTENSION,
  45. ListEntry );
  46. ASSERT( IS_VALID_SR_DEVICE_EXTENSION( pExtension ) );
  47. SrAcquireActivityLockExclusive( pExtension );
  48. pExtension->ActivityLockHeldExclusive = TRUE;
  49. }
  50. //
  51. // We successfully acquired all the volume activity locks exclusively.
  52. //
  53. status = STATUS_SUCCESS;
  54. } finally {
  55. status = FinallyUnwind( SrPauseVolumeActivity, status );
  56. if (!NT_SUCCESS( status )) {
  57. SrResumeVolumeActivity();
  58. }
  59. }
  60. RETURN( status );
  61. }
  62. /***************************************************************************++
  63. Routine Description:
  64. This routine will iterate through this list of device extensions and
  65. release any activity locks that are held.
  66. Note: This routine assumes that the DeviceExtensionListLock is already
  67. held, either shared or exclusive.
  68. Arguments:
  69. None
  70. Return Value:
  71. None.
  72. --***************************************************************************/
  73. VOID
  74. SrResumeVolumeActivity (
  75. )
  76. {
  77. PLIST_ENTRY pCurrentEntry;
  78. PSR_DEVICE_EXTENSION pExtension;
  79. ASSERT( IS_DEVICE_EXTENSION_LIST_LOCK_ACQUIRED() );
  80. for (pCurrentEntry = global->DeviceExtensionListHead.Flink;
  81. pCurrentEntry != &global->DeviceExtensionListHead;
  82. pCurrentEntry = pCurrentEntry->Flink) {
  83. pExtension = CONTAINING_RECORD( pCurrentEntry,
  84. SR_DEVICE_EXTENSION,
  85. ListEntry );
  86. ASSERT( IS_VALID_SR_DEVICE_EXTENSION( pExtension ) );
  87. if (pExtension->ActivityLockHeldExclusive) {
  88. pExtension->ActivityLockHeldExclusive = FALSE;
  89. SrReleaseActivityLock( pExtension );
  90. }
  91. }
  92. }