dm.c (dfbe03f6d09fcebf85ae2a2cbb4ceee9b0985e67) dm.c (354e007121de546e50b5592c2557575117435522)
1/*
2 * Copyright (C) 2001, 2002 Sistina Software (UK) Limited.
3 * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
4 *
5 * This file is released under the GPL.
6 */
7
8#include "dm.h"

--- 1034 unchanged lines hidden (view full) ---

1043 * the background. Before the table can be swapped with
1044 * dm_bind_table, dm_suspend must be called to flush any in
1045 * flight bios and ensure that any further io gets deferred.
1046 */
1047int dm_suspend(struct mapped_device *md)
1048{
1049 struct dm_table *map;
1050 DECLARE_WAITQUEUE(wait, current);
1/*
2 * Copyright (C) 2001, 2002 Sistina Software (UK) Limited.
3 * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
4 *
5 * This file is released under the GPL.
6 */
7
8#include "dm.h"

--- 1034 unchanged lines hidden (view full) ---

1043 * the background. Before the table can be swapped with
1044 * dm_bind_table, dm_suspend must be called to flush any in
1045 * flight bios and ensure that any further io gets deferred.
1046 */
1047int dm_suspend(struct mapped_device *md)
1048{
1049 struct dm_table *map;
1050 DECLARE_WAITQUEUE(wait, current);
1051 int error;
1051
1052 /* Flush I/O to the device. */
1053 down_read(&md->lock);
1054 if (test_bit(DMF_BLOCK_IO, &md->flags)) {
1055 up_read(&md->lock);
1056 return -EINVAL;
1057 }
1058
1052
1053 /* Flush I/O to the device. */
1054 down_read(&md->lock);
1055 if (test_bit(DMF_BLOCK_IO, &md->flags)) {
1056 up_read(&md->lock);
1057 return -EINVAL;
1058 }
1059
1060 error = __lock_fs(md);
1061 if (error) {
1062 up_read(&md->lock);
1063 return error;
1064 }
1065
1059 map = dm_get_table(md);
1060 if (map)
1061 dm_table_presuspend_targets(map);
1066 map = dm_get_table(md);
1067 if (map)
1068 dm_table_presuspend_targets(map);
1062 __lock_fs(md);
1063
1064 up_read(&md->lock);
1065
1066 /*
1069
1070 up_read(&md->lock);
1071
1072 /*
1067 * First we set the BLOCK_IO flag so no more ios will be
1068 * mapped.
1073 * First we set the BLOCK_IO flag so no more ios will be mapped.
1074 *
1075 * If the flag is already set we know another thread is trying to
1076 * suspend as well, so we leave the fs locked for this thread.
1069 */
1070 down_write(&md->lock);
1071 if (test_bit(DMF_BLOCK_IO, &md->flags)) {
1077 */
1078 down_write(&md->lock);
1079 if (test_bit(DMF_BLOCK_IO, &md->flags)) {
1072 /*
1073 * If we get here we know another thread is
1074 * trying to suspend as well, so we leave the fs
1075 * locked for this thread.
1076 */
1077 up_write(&md->lock);
1080 up_write(&md->lock);
1081 if (map)
1082 dm_table_put(map);
1078 return -EINVAL;
1079 }
1080
1081 set_bit(DMF_BLOCK_IO, &md->flags);
1082 add_wait_queue(&md->wait, &wait);
1083 up_write(&md->lock);
1084
1085 /* unplug */

--- 16 unchanged lines hidden (view full) ---

1102 }
1103 set_current_state(TASK_RUNNING);
1104
1105 down_write(&md->lock);
1106 remove_wait_queue(&md->wait, &wait);
1107
1108 /* were we interrupted ? */
1109 if (atomic_read(&md->pending)) {
1083 return -EINVAL;
1084 }
1085
1086 set_bit(DMF_BLOCK_IO, &md->flags);
1087 add_wait_queue(&md->wait, &wait);
1088 up_write(&md->lock);
1089
1090 /* unplug */

--- 16 unchanged lines hidden (view full) ---

1107 }
1108 set_current_state(TASK_RUNNING);
1109
1110 down_write(&md->lock);
1111 remove_wait_queue(&md->wait, &wait);
1112
1113 /* were we interrupted ? */
1114 if (atomic_read(&md->pending)) {
1115 /* FIXME Undo the presuspend_targets */
1110 __unlock_fs(md);
1111 clear_bit(DMF_BLOCK_IO, &md->flags);
1112 up_write(&md->lock);
1113 return -EINTR;
1114 }
1115
1116 set_bit(DMF_SUSPENDED, &md->flags);
1117

--- 84 unchanged lines hidden ---
1116 __unlock_fs(md);
1117 clear_bit(DMF_BLOCK_IO, &md->flags);
1118 up_write(&md->lock);
1119 return -EINTR;
1120 }
1121
1122 set_bit(DMF_SUSPENDED, &md->flags);
1123

--- 84 unchanged lines hidden ---