Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 1 | /* -*- mode: c; c-basic-offset: 8; -*- |
| 2 | * vim: noexpandtab sw=8 ts=8 sts=0: |
| 3 | * |
| 4 | * dlmthread.c |
| 5 | * |
| 6 | * standalone DLM module |
| 7 | * |
| 8 | * Copyright (C) 2004 Oracle. All rights reserved. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public |
| 21 | * License along with this program; if not, write to the |
| 22 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 23 | * Boston, MA 021110-1307, USA. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/fs.h> |
| 30 | #include <linux/types.h> |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 31 | #include <linux/highmem.h> |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 32 | #include <linux/init.h> |
| 33 | #include <linux/sysctl.h> |
| 34 | #include <linux/random.h> |
| 35 | #include <linux/blkdev.h> |
| 36 | #include <linux/socket.h> |
| 37 | #include <linux/inet.h> |
| 38 | #include <linux/timer.h> |
| 39 | #include <linux/kthread.h> |
Kurt Hackel | 8d79d08 | 2006-04-27 17:58:23 -0700 | [diff] [blame] | 40 | #include <linux/delay.h> |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 41 | |
| 42 | |
| 43 | #include "cluster/heartbeat.h" |
| 44 | #include "cluster/nodemanager.h" |
| 45 | #include "cluster/tcp.h" |
| 46 | |
| 47 | #include "dlmapi.h" |
| 48 | #include "dlmcommon.h" |
| 49 | #include "dlmdomain.h" |
| 50 | |
| 51 | #define MLOG_MASK_PREFIX (ML_DLM|ML_DLM_THREAD) |
| 52 | #include "cluster/masklog.h" |
| 53 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 54 | static int dlm_thread(void *data); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 55 | static void dlm_flush_asts(struct dlm_ctxt *dlm); |
| 56 | |
| 57 | #define dlm_lock_is_remote(dlm, lock) ((lock)->ml.node != (dlm)->node_num) |
| 58 | |
| 59 | /* will exit holding res->spinlock, but may drop in function */ |
| 60 | /* waits until flags are cleared on res->state */ |
| 61 | void __dlm_wait_on_lockres_flags(struct dlm_lock_resource *res, int flags) |
| 62 | { |
| 63 | DECLARE_WAITQUEUE(wait, current); |
| 64 | |
| 65 | assert_spin_locked(&res->spinlock); |
| 66 | |
| 67 | add_wait_queue(&res->wq, &wait); |
| 68 | repeat: |
| 69 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 70 | if (res->state & flags) { |
| 71 | spin_unlock(&res->spinlock); |
| 72 | schedule(); |
| 73 | spin_lock(&res->spinlock); |
| 74 | goto repeat; |
| 75 | } |
| 76 | remove_wait_queue(&res->wq, &wait); |
Milind Arun Choudhary | 5c2c9d3 | 2007-04-26 00:29:35 -0700 | [diff] [blame] | 77 | __set_current_state(TASK_RUNNING); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 78 | } |
| 79 | |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 80 | int __dlm_lockres_has_locks(struct dlm_lock_resource *res) |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 81 | { |
| 82 | if (list_empty(&res->granted) && |
| 83 | list_empty(&res->converting) && |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 84 | list_empty(&res->blocked)) |
| 85 | return 0; |
| 86 | return 1; |
| 87 | } |
| 88 | |
| 89 | /* "unused": the lockres has no locks, is not on the dirty list, |
| 90 | * has no inflight locks (in the gap between mastery and acquiring |
| 91 | * the first lock), and has no bits in its refmap. |
| 92 | * truly ready to be freed. */ |
| 93 | int __dlm_lockres_unused(struct dlm_lock_resource *res) |
| 94 | { |
Wengang Wang | a524812 | 2010-07-30 16:14:44 +0800 | [diff] [blame] | 95 | int bit; |
| 96 | |
| 97 | if (__dlm_lockres_has_locks(res)) |
| 98 | return 0; |
| 99 | |
| 100 | if (!list_empty(&res->dirty) || res->state & DLM_LOCK_RES_DIRTY) |
| 101 | return 0; |
| 102 | |
| 103 | if (res->state & DLM_LOCK_RES_RECOVERING) |
| 104 | return 0; |
| 105 | |
| 106 | bit = find_next_bit(res->refmap, O2NM_MAX_NODES, 0); |
| 107 | if (bit < O2NM_MAX_NODES) |
| 108 | return 0; |
| 109 | |
| 110 | /* |
| 111 | * since the bit for dlm->node_num is not set, inflight_locks better |
| 112 | * be zero |
| 113 | */ |
| 114 | BUG_ON(res->inflight_locks != 0); |
| 115 | return 1; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | |
| 119 | /* Call whenever you may have added or deleted something from one of |
| 120 | * the lockres queue's. This will figure out whether it belongs on the |
| 121 | * unused list or not and does the appropriate thing. */ |
| 122 | void __dlm_lockres_calc_usage(struct dlm_ctxt *dlm, |
| 123 | struct dlm_lock_resource *res) |
| 124 | { |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 125 | assert_spin_locked(&dlm->spinlock); |
| 126 | assert_spin_locked(&res->spinlock); |
| 127 | |
| 128 | if (__dlm_lockres_unused(res)){ |
| 129 | if (list_empty(&res->purge)) { |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 130 | mlog(0, "%s: Adding res %.*s to purge list\n", |
| 131 | dlm->name, res->lockname.len, res->lockname.name); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 132 | |
| 133 | res->last_used = jiffies; |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 134 | dlm_lockres_get(res); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 135 | list_add_tail(&res->purge, &dlm->purge_list); |
| 136 | dlm->purge_count++; |
| 137 | } |
| 138 | } else if (!list_empty(&res->purge)) { |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 139 | mlog(0, "%s: Removing res %.*s from purge list\n", |
| 140 | dlm->name, res->lockname.len, res->lockname.name); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 141 | |
| 142 | list_del_init(&res->purge); |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 143 | dlm_lockres_put(res); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 144 | dlm->purge_count--; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | void dlm_lockres_calc_usage(struct dlm_ctxt *dlm, |
| 149 | struct dlm_lock_resource *res) |
| 150 | { |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 151 | spin_lock(&dlm->spinlock); |
| 152 | spin_lock(&res->spinlock); |
| 153 | |
| 154 | __dlm_lockres_calc_usage(dlm, res); |
| 155 | |
| 156 | spin_unlock(&res->spinlock); |
| 157 | spin_unlock(&dlm->spinlock); |
| 158 | } |
| 159 | |
Srinivas Eeda | 7beaf24 | 2010-07-19 16:04:12 -0700 | [diff] [blame] | 160 | static void dlm_purge_lockres(struct dlm_ctxt *dlm, |
Adrian Bunk | faf0ec9 | 2006-12-14 00:17:32 +0100 | [diff] [blame] | 161 | struct dlm_lock_resource *res) |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 162 | { |
| 163 | int master; |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 164 | int ret = 0; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 165 | |
Srinivas Eeda | 7beaf24 | 2010-07-19 16:04:12 -0700 | [diff] [blame] | 166 | assert_spin_locked(&dlm->spinlock); |
| 167 | assert_spin_locked(&res->spinlock); |
Sunil Mushran | 516b7e5 | 2009-02-26 15:00:48 -0800 | [diff] [blame] | 168 | |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 169 | master = (res->owner == dlm->node_num); |
Sunil Mushran | 516b7e5 | 2009-02-26 15:00:48 -0800 | [diff] [blame] | 170 | |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 171 | mlog(0, "%s: Purging res %.*s, master %d\n", dlm->name, |
| 172 | res->lockname.len, res->lockname.name, master); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 173 | |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 174 | if (!master) { |
Srinivas Eeda | 7beaf24 | 2010-07-19 16:04:12 -0700 | [diff] [blame] | 175 | res->state |= DLM_LOCK_RES_DROPPING_REF; |
Sunil Mushran | c824c3c | 2008-03-01 14:04:25 -0800 | [diff] [blame] | 176 | /* drop spinlock... retake below */ |
Srinivas Eeda | 7beaf24 | 2010-07-19 16:04:12 -0700 | [diff] [blame] | 177 | spin_unlock(&res->spinlock); |
Sunil Mushran | c824c3c | 2008-03-01 14:04:25 -0800 | [diff] [blame] | 178 | spin_unlock(&dlm->spinlock); |
| 179 | |
Kurt Hackel | 3b8118c | 2007-01-17 17:05:53 -0800 | [diff] [blame] | 180 | spin_lock(&res->spinlock); |
| 181 | /* This ensures that clear refmap is sent after the set */ |
Sunil Mushran | 7dc102b | 2009-02-03 12:37:13 -0800 | [diff] [blame] | 182 | __dlm_wait_on_lockres_flags(res, DLM_LOCK_RES_SETREF_INPROG); |
Kurt Hackel | 3b8118c | 2007-01-17 17:05:53 -0800 | [diff] [blame] | 183 | spin_unlock(&res->spinlock); |
Sunil Mushran | c824c3c | 2008-03-01 14:04:25 -0800 | [diff] [blame] | 184 | |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 185 | /* clear our bit from the master's refmap, ignore errors */ |
| 186 | ret = dlm_drop_lockres_ref(dlm, res); |
| 187 | if (ret < 0) { |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 188 | if (!dlm_is_host_down(ret)) |
| 189 | BUG(); |
| 190 | } |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 191 | spin_lock(&dlm->spinlock); |
Srinivas Eeda | 7beaf24 | 2010-07-19 16:04:12 -0700 | [diff] [blame] | 192 | spin_lock(&res->spinlock); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 193 | } |
| 194 | |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 195 | if (!list_empty(&res->purge)) { |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 196 | mlog(0, "%s: Removing res %.*s from purgelist, master %d\n", |
| 197 | dlm->name, res->lockname.len, res->lockname.name, master); |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 198 | list_del_init(&res->purge); |
| 199 | dlm_lockres_put(res); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 200 | dlm->purge_count--; |
Srinivas Eeda | 7beaf24 | 2010-07-19 16:04:12 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | if (!__dlm_lockres_unused(res)) { |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 204 | mlog(ML_ERROR, "%s: res %.*s in use after deref\n", |
Srinivas Eeda | 7beaf24 | 2010-07-19 16:04:12 -0700 | [diff] [blame] | 205 | dlm->name, res->lockname.len, res->lockname.name); |
| 206 | __dlm_print_one_lock_resource(res); |
| 207 | BUG(); |
| 208 | } |
Wengang Wang | 83e32d9 | 2009-09-03 15:56:33 +0800 | [diff] [blame] | 209 | |
Sunil Mushran | e9f0b6a | 2011-07-24 10:27:54 -0700 | [diff] [blame^] | 210 | __dlm_unhash_lockres(dlm, res); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 211 | |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 212 | /* lockres is not in the hash now. drop the flag and wake up |
| 213 | * any processes waiting in dlm_get_lock_resource. */ |
| 214 | if (!master) { |
Kurt Hackel | ba2bf21 | 2006-12-01 14:47:20 -0800 | [diff] [blame] | 215 | res->state &= ~DLM_LOCK_RES_DROPPING_REF; |
| 216 | spin_unlock(&res->spinlock); |
| 217 | wake_up(&res->wq); |
Srinivas Eeda | 7beaf24 | 2010-07-19 16:04:12 -0700 | [diff] [blame] | 218 | } else |
| 219 | spin_unlock(&res->spinlock); |
Kurt Hackel | 8b21980 | 2006-05-01 11:16:45 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 222 | static void dlm_run_purge_list(struct dlm_ctxt *dlm, |
| 223 | int purge_now) |
| 224 | { |
| 225 | unsigned int run_max, unused; |
| 226 | unsigned long purge_jiffies; |
| 227 | struct dlm_lock_resource *lockres; |
| 228 | |
| 229 | spin_lock(&dlm->spinlock); |
| 230 | run_max = dlm->purge_count; |
| 231 | |
| 232 | while(run_max && !list_empty(&dlm->purge_list)) { |
| 233 | run_max--; |
| 234 | |
| 235 | lockres = list_entry(dlm->purge_list.next, |
| 236 | struct dlm_lock_resource, purge); |
| 237 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 238 | spin_lock(&lockres->spinlock); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 239 | |
| 240 | purge_jiffies = lockres->last_used + |
| 241 | msecs_to_jiffies(DLM_PURGE_INTERVAL_MS); |
| 242 | |
| 243 | /* Make sure that we want to be processing this guy at |
| 244 | * this time. */ |
| 245 | if (!purge_now && time_after(purge_jiffies, jiffies)) { |
| 246 | /* Since resources are added to the purge list |
| 247 | * in tail order, we can stop at the first |
| 248 | * unpurgable resource -- anyone added after |
| 249 | * him will have a greater last_used value */ |
Srinivas Eeda | 7beaf24 | 2010-07-19 16:04:12 -0700 | [diff] [blame] | 250 | spin_unlock(&lockres->spinlock); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 251 | break; |
| 252 | } |
| 253 | |
Srinivas Eeda | 7beaf24 | 2010-07-19 16:04:12 -0700 | [diff] [blame] | 254 | /* Status of the lockres *might* change so double |
| 255 | * check. If the lockres is unused, holding the dlm |
| 256 | * spinlock will prevent people from getting and more |
| 257 | * refs on it. */ |
| 258 | unused = __dlm_lockres_unused(lockres); |
| 259 | if (!unused || |
| 260 | (lockres->state & DLM_LOCK_RES_MIGRATING)) { |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 261 | mlog(0, "%s: res %.*s is in use or being remastered, " |
| 262 | "used %d, state %d\n", dlm->name, |
| 263 | lockres->lockname.len, lockres->lockname.name, |
| 264 | !unused, lockres->state); |
Srinivas Eeda | 7beaf24 | 2010-07-19 16:04:12 -0700 | [diff] [blame] | 265 | list_move_tail(&dlm->purge_list, &lockres->purge); |
| 266 | spin_unlock(&lockres->spinlock); |
| 267 | continue; |
| 268 | } |
| 269 | |
Sunil Mushran | 78062cb | 2007-03-22 17:01:07 -0700 | [diff] [blame] | 270 | dlm_lockres_get(lockres); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 271 | |
Srinivas Eeda | 7beaf24 | 2010-07-19 16:04:12 -0700 | [diff] [blame] | 272 | dlm_purge_lockres(dlm, lockres); |
Sunil Mushran | 78062cb | 2007-03-22 17:01:07 -0700 | [diff] [blame] | 273 | |
Sunil Mushran | 3fca089 | 2007-03-12 13:24:34 -0700 | [diff] [blame] | 274 | dlm_lockres_put(lockres); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 275 | |
| 276 | /* Avoid adding any scheduling latencies */ |
| 277 | cond_resched_lock(&dlm->spinlock); |
| 278 | } |
| 279 | |
| 280 | spin_unlock(&dlm->spinlock); |
| 281 | } |
| 282 | |
| 283 | static void dlm_shuffle_lists(struct dlm_ctxt *dlm, |
| 284 | struct dlm_lock_resource *res) |
| 285 | { |
| 286 | struct dlm_lock *lock, *target; |
| 287 | struct list_head *iter; |
| 288 | struct list_head *head; |
| 289 | int can_grant = 1; |
| 290 | |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 291 | /* |
| 292 | * Because this function is called with the lockres |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 293 | * spinlock, and because we know that it is not migrating/ |
| 294 | * recovering/in-progress, it is fine to reserve asts and |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 295 | * basts right before queueing them all throughout |
| 296 | */ |
Wengang Wang | d9ef752 | 2010-05-17 20:20:44 +0800 | [diff] [blame] | 297 | assert_spin_locked(&dlm->ast_lock); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 298 | assert_spin_locked(&res->spinlock); |
| 299 | BUG_ON((res->state & (DLM_LOCK_RES_MIGRATING| |
| 300 | DLM_LOCK_RES_RECOVERING| |
| 301 | DLM_LOCK_RES_IN_PROGRESS))); |
| 302 | |
| 303 | converting: |
| 304 | if (list_empty(&res->converting)) |
| 305 | goto blocked; |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 306 | mlog(0, "%s: res %.*s has locks on the convert queue\n", dlm->name, |
| 307 | res->lockname.len, res->lockname.name); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 308 | |
| 309 | target = list_entry(res->converting.next, struct dlm_lock, list); |
| 310 | if (target->ml.convert_type == LKM_IVMODE) { |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 311 | mlog(ML_ERROR, "%s: res %.*s converting lock to invalid mode\n", |
| 312 | dlm->name, res->lockname.len, res->lockname.name); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 313 | BUG(); |
| 314 | } |
| 315 | head = &res->granted; |
| 316 | list_for_each(iter, head) { |
| 317 | lock = list_entry(iter, struct dlm_lock, list); |
| 318 | if (lock==target) |
| 319 | continue; |
| 320 | if (!dlm_lock_compatible(lock->ml.type, |
| 321 | target->ml.convert_type)) { |
| 322 | can_grant = 0; |
| 323 | /* queue the BAST if not already */ |
| 324 | if (lock->ml.highest_blocked == LKM_IVMODE) { |
| 325 | __dlm_lockres_reserve_ast(res); |
Wengang Wang | d9ef752 | 2010-05-17 20:20:44 +0800 | [diff] [blame] | 326 | __dlm_queue_bast(dlm, lock); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 327 | } |
| 328 | /* update the highest_blocked if needed */ |
| 329 | if (lock->ml.highest_blocked < target->ml.convert_type) |
| 330 | lock->ml.highest_blocked = |
| 331 | target->ml.convert_type; |
| 332 | } |
| 333 | } |
| 334 | head = &res->converting; |
| 335 | list_for_each(iter, head) { |
| 336 | lock = list_entry(iter, struct dlm_lock, list); |
| 337 | if (lock==target) |
| 338 | continue; |
| 339 | if (!dlm_lock_compatible(lock->ml.type, |
| 340 | target->ml.convert_type)) { |
| 341 | can_grant = 0; |
| 342 | if (lock->ml.highest_blocked == LKM_IVMODE) { |
| 343 | __dlm_lockres_reserve_ast(res); |
Wengang Wang | d9ef752 | 2010-05-17 20:20:44 +0800 | [diff] [blame] | 344 | __dlm_queue_bast(dlm, lock); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 345 | } |
| 346 | if (lock->ml.highest_blocked < target->ml.convert_type) |
| 347 | lock->ml.highest_blocked = |
| 348 | target->ml.convert_type; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | /* we can convert the lock */ |
| 353 | if (can_grant) { |
| 354 | spin_lock(&target->spinlock); |
| 355 | BUG_ON(target->ml.highest_blocked != LKM_IVMODE); |
| 356 | |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 357 | mlog(0, "%s: res %.*s, AST for Converting lock %u:%llu, type " |
| 358 | "%d => %d, node %u\n", dlm->name, res->lockname.len, |
| 359 | res->lockname.name, |
| 360 | dlm_get_lock_cookie_node(be64_to_cpu(target->ml.cookie)), |
| 361 | dlm_get_lock_cookie_seq(be64_to_cpu(target->ml.cookie)), |
| 362 | target->ml.type, |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 363 | target->ml.convert_type, target->ml.node); |
| 364 | |
| 365 | target->ml.type = target->ml.convert_type; |
| 366 | target->ml.convert_type = LKM_IVMODE; |
Akinobu Mita | f116629 | 2006-06-26 00:24:46 -0700 | [diff] [blame] | 367 | list_move_tail(&target->list, &res->granted); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 368 | |
| 369 | BUG_ON(!target->lksb); |
| 370 | target->lksb->status = DLM_NORMAL; |
| 371 | |
| 372 | spin_unlock(&target->spinlock); |
| 373 | |
| 374 | __dlm_lockres_reserve_ast(res); |
Wengang Wang | d9ef752 | 2010-05-17 20:20:44 +0800 | [diff] [blame] | 375 | __dlm_queue_ast(dlm, target); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 376 | /* go back and check for more */ |
| 377 | goto converting; |
| 378 | } |
| 379 | |
| 380 | blocked: |
| 381 | if (list_empty(&res->blocked)) |
| 382 | goto leave; |
| 383 | target = list_entry(res->blocked.next, struct dlm_lock, list); |
| 384 | |
| 385 | head = &res->granted; |
| 386 | list_for_each(iter, head) { |
| 387 | lock = list_entry(iter, struct dlm_lock, list); |
| 388 | if (lock==target) |
| 389 | continue; |
| 390 | if (!dlm_lock_compatible(lock->ml.type, target->ml.type)) { |
| 391 | can_grant = 0; |
| 392 | if (lock->ml.highest_blocked == LKM_IVMODE) { |
| 393 | __dlm_lockres_reserve_ast(res); |
Wengang Wang | d9ef752 | 2010-05-17 20:20:44 +0800 | [diff] [blame] | 394 | __dlm_queue_bast(dlm, lock); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 395 | } |
| 396 | if (lock->ml.highest_blocked < target->ml.type) |
| 397 | lock->ml.highest_blocked = target->ml.type; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | head = &res->converting; |
| 402 | list_for_each(iter, head) { |
| 403 | lock = list_entry(iter, struct dlm_lock, list); |
| 404 | if (lock==target) |
| 405 | continue; |
| 406 | if (!dlm_lock_compatible(lock->ml.type, target->ml.type)) { |
| 407 | can_grant = 0; |
| 408 | if (lock->ml.highest_blocked == LKM_IVMODE) { |
| 409 | __dlm_lockres_reserve_ast(res); |
Wengang Wang | d9ef752 | 2010-05-17 20:20:44 +0800 | [diff] [blame] | 410 | __dlm_queue_bast(dlm, lock); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 411 | } |
| 412 | if (lock->ml.highest_blocked < target->ml.type) |
| 413 | lock->ml.highest_blocked = target->ml.type; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | /* we can grant the blocked lock (only |
| 418 | * possible if converting list empty) */ |
| 419 | if (can_grant) { |
| 420 | spin_lock(&target->spinlock); |
| 421 | BUG_ON(target->ml.highest_blocked != LKM_IVMODE); |
| 422 | |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 423 | mlog(0, "%s: res %.*s, AST for Blocked lock %u:%llu, type %d, " |
| 424 | "node %u\n", dlm->name, res->lockname.len, |
| 425 | res->lockname.name, |
| 426 | dlm_get_lock_cookie_node(be64_to_cpu(target->ml.cookie)), |
| 427 | dlm_get_lock_cookie_seq(be64_to_cpu(target->ml.cookie)), |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 428 | target->ml.type, target->ml.node); |
| 429 | |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 430 | /* target->ml.type is already correct */ |
Akinobu Mita | f116629 | 2006-06-26 00:24:46 -0700 | [diff] [blame] | 431 | list_move_tail(&target->list, &res->granted); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 432 | |
| 433 | BUG_ON(!target->lksb); |
| 434 | target->lksb->status = DLM_NORMAL; |
| 435 | |
| 436 | spin_unlock(&target->spinlock); |
| 437 | |
| 438 | __dlm_lockres_reserve_ast(res); |
Wengang Wang | d9ef752 | 2010-05-17 20:20:44 +0800 | [diff] [blame] | 439 | __dlm_queue_ast(dlm, target); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 440 | /* go back and check for more */ |
| 441 | goto converting; |
| 442 | } |
| 443 | |
| 444 | leave: |
| 445 | return; |
| 446 | } |
| 447 | |
| 448 | /* must have NO locks when calling this with res !=NULL * */ |
| 449 | void dlm_kick_thread(struct dlm_ctxt *dlm, struct dlm_lock_resource *res) |
| 450 | { |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 451 | if (res) { |
| 452 | spin_lock(&dlm->spinlock); |
| 453 | spin_lock(&res->spinlock); |
| 454 | __dlm_dirty_lockres(dlm, res); |
| 455 | spin_unlock(&res->spinlock); |
| 456 | spin_unlock(&dlm->spinlock); |
| 457 | } |
| 458 | wake_up(&dlm->dlm_thread_wq); |
| 459 | } |
| 460 | |
| 461 | void __dlm_dirty_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res) |
| 462 | { |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 463 | assert_spin_locked(&dlm->spinlock); |
| 464 | assert_spin_locked(&res->spinlock); |
| 465 | |
| 466 | /* don't shuffle secondary queues */ |
Kurt Hackel | ddc09c8 | 2007-01-05 15:00:17 -0800 | [diff] [blame] | 467 | if ((res->owner == dlm->node_num)) { |
| 468 | if (res->state & (DLM_LOCK_RES_MIGRATING | |
| 469 | DLM_LOCK_RES_BLOCK_DIRTY)) |
| 470 | return; |
| 471 | |
| 472 | if (list_empty(&res->dirty)) { |
| 473 | /* ref for dirty_list */ |
| 474 | dlm_lockres_get(res); |
| 475 | list_add_tail(&res->dirty, &dlm->dirty_list); |
| 476 | res->state |= DLM_LOCK_RES_DIRTY; |
| 477 | } |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 478 | } |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 479 | |
| 480 | mlog(0, "%s: res %.*s\n", dlm->name, res->lockname.len, |
| 481 | res->lockname.name); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | |
| 485 | /* Launch the NM thread for the mounted volume */ |
| 486 | int dlm_launch_thread(struct dlm_ctxt *dlm) |
| 487 | { |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 488 | mlog(0, "Starting dlm_thread...\n"); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 489 | |
| 490 | dlm->dlm_thread_task = kthread_run(dlm_thread, dlm, "dlm_thread"); |
| 491 | if (IS_ERR(dlm->dlm_thread_task)) { |
| 492 | mlog_errno(PTR_ERR(dlm->dlm_thread_task)); |
| 493 | dlm->dlm_thread_task = NULL; |
| 494 | return -EINVAL; |
| 495 | } |
| 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | void dlm_complete_thread(struct dlm_ctxt *dlm) |
| 501 | { |
| 502 | if (dlm->dlm_thread_task) { |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 503 | mlog(ML_KTHREAD, "Waiting for dlm thread to exit\n"); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 504 | kthread_stop(dlm->dlm_thread_task); |
| 505 | dlm->dlm_thread_task = NULL; |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | static int dlm_dirty_list_empty(struct dlm_ctxt *dlm) |
| 510 | { |
| 511 | int empty; |
| 512 | |
| 513 | spin_lock(&dlm->spinlock); |
| 514 | empty = list_empty(&dlm->dirty_list); |
| 515 | spin_unlock(&dlm->spinlock); |
| 516 | |
| 517 | return empty; |
| 518 | } |
| 519 | |
| 520 | static void dlm_flush_asts(struct dlm_ctxt *dlm) |
| 521 | { |
| 522 | int ret; |
| 523 | struct dlm_lock *lock; |
| 524 | struct dlm_lock_resource *res; |
| 525 | u8 hi; |
| 526 | |
| 527 | spin_lock(&dlm->ast_lock); |
| 528 | while (!list_empty(&dlm->pending_asts)) { |
| 529 | lock = list_entry(dlm->pending_asts.next, |
| 530 | struct dlm_lock, ast_list); |
| 531 | /* get an extra ref on lock */ |
| 532 | dlm_lock_get(lock); |
| 533 | res = lock->lockres; |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 534 | mlog(0, "%s: res %.*s, Flush AST for lock %u:%llu, type %d, " |
| 535 | "node %u\n", dlm->name, res->lockname.len, |
| 536 | res->lockname.name, |
| 537 | dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)), |
| 538 | dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)), |
| 539 | lock->ml.type, lock->ml.node); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 540 | |
| 541 | BUG_ON(!lock->ast_pending); |
| 542 | |
| 543 | /* remove from list (including ref) */ |
| 544 | list_del_init(&lock->ast_list); |
| 545 | dlm_lock_put(lock); |
| 546 | spin_unlock(&dlm->ast_lock); |
| 547 | |
| 548 | if (lock->ml.node != dlm->node_num) { |
| 549 | ret = dlm_do_remote_ast(dlm, res, lock); |
| 550 | if (ret < 0) |
| 551 | mlog_errno(ret); |
| 552 | } else |
| 553 | dlm_do_local_ast(dlm, res, lock); |
| 554 | |
| 555 | spin_lock(&dlm->ast_lock); |
| 556 | |
| 557 | /* possible that another ast was queued while |
| 558 | * we were delivering the last one */ |
| 559 | if (!list_empty(&lock->ast_list)) { |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 560 | mlog(0, "%s: res %.*s, AST queued while flushing last " |
| 561 | "one\n", dlm->name, res->lockname.len, |
| 562 | res->lockname.name); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 563 | } else |
| 564 | lock->ast_pending = 0; |
| 565 | |
| 566 | /* drop the extra ref. |
| 567 | * this may drop it completely. */ |
| 568 | dlm_lock_put(lock); |
| 569 | dlm_lockres_release_ast(dlm, res); |
| 570 | } |
| 571 | |
| 572 | while (!list_empty(&dlm->pending_basts)) { |
| 573 | lock = list_entry(dlm->pending_basts.next, |
| 574 | struct dlm_lock, bast_list); |
| 575 | /* get an extra ref on lock */ |
| 576 | dlm_lock_get(lock); |
| 577 | res = lock->lockres; |
| 578 | |
| 579 | BUG_ON(!lock->bast_pending); |
| 580 | |
| 581 | /* get the highest blocked lock, and reset */ |
| 582 | spin_lock(&lock->spinlock); |
| 583 | BUG_ON(lock->ml.highest_blocked <= LKM_IVMODE); |
| 584 | hi = lock->ml.highest_blocked; |
| 585 | lock->ml.highest_blocked = LKM_IVMODE; |
| 586 | spin_unlock(&lock->spinlock); |
| 587 | |
| 588 | /* remove from list (including ref) */ |
| 589 | list_del_init(&lock->bast_list); |
| 590 | dlm_lock_put(lock); |
| 591 | spin_unlock(&dlm->ast_lock); |
| 592 | |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 593 | mlog(0, "%s: res %.*s, Flush BAST for lock %u:%llu, " |
| 594 | "blocked %d, node %u\n", |
| 595 | dlm->name, res->lockname.len, res->lockname.name, |
| 596 | dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)), |
| 597 | dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)), |
| 598 | hi, lock->ml.node); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 599 | |
| 600 | if (lock->ml.node != dlm->node_num) { |
| 601 | ret = dlm_send_proxy_bast(dlm, res, lock, hi); |
| 602 | if (ret < 0) |
| 603 | mlog_errno(ret); |
| 604 | } else |
| 605 | dlm_do_local_bast(dlm, res, lock, hi); |
| 606 | |
| 607 | spin_lock(&dlm->ast_lock); |
| 608 | |
| 609 | /* possible that another bast was queued while |
| 610 | * we were delivering the last one */ |
| 611 | if (!list_empty(&lock->bast_list)) { |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 612 | mlog(0, "%s: res %.*s, BAST queued while flushing last " |
| 613 | "one\n", dlm->name, res->lockname.len, |
| 614 | res->lockname.name); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 615 | } else |
| 616 | lock->bast_pending = 0; |
| 617 | |
| 618 | /* drop the extra ref. |
| 619 | * this may drop it completely. */ |
| 620 | dlm_lock_put(lock); |
| 621 | dlm_lockres_release_ast(dlm, res); |
| 622 | } |
| 623 | wake_up(&dlm->ast_wq); |
| 624 | spin_unlock(&dlm->ast_lock); |
| 625 | } |
| 626 | |
| 627 | |
| 628 | #define DLM_THREAD_TIMEOUT_MS (4 * 1000) |
| 629 | #define DLM_THREAD_MAX_DIRTY 100 |
| 630 | #define DLM_THREAD_MAX_ASTS 10 |
| 631 | |
| 632 | static int dlm_thread(void *data) |
| 633 | { |
| 634 | struct dlm_lock_resource *res; |
| 635 | struct dlm_ctxt *dlm = data; |
| 636 | unsigned long timeout = msecs_to_jiffies(DLM_THREAD_TIMEOUT_MS); |
| 637 | |
| 638 | mlog(0, "dlm thread running for %s...\n", dlm->name); |
| 639 | |
| 640 | while (!kthread_should_stop()) { |
| 641 | int n = DLM_THREAD_MAX_DIRTY; |
| 642 | |
| 643 | /* dlm_shutting_down is very point-in-time, but that |
| 644 | * doesn't matter as we'll just loop back around if we |
| 645 | * get false on the leading edge of a state |
| 646 | * transition. */ |
| 647 | dlm_run_purge_list(dlm, dlm_shutting_down(dlm)); |
| 648 | |
| 649 | /* We really don't want to hold dlm->spinlock while |
| 650 | * calling dlm_shuffle_lists on each lockres that |
| 651 | * needs to have its queues adjusted and AST/BASTs |
| 652 | * run. So let's pull each entry off the dirty_list |
| 653 | * and drop dlm->spinlock ASAP. Once off the list, |
| 654 | * res->spinlock needs to be taken again to protect |
| 655 | * the queues while calling dlm_shuffle_lists. */ |
| 656 | spin_lock(&dlm->spinlock); |
| 657 | while (!list_empty(&dlm->dirty_list)) { |
| 658 | int delay = 0; |
| 659 | res = list_entry(dlm->dirty_list.next, |
| 660 | struct dlm_lock_resource, dirty); |
| 661 | |
| 662 | /* peel a lockres off, remove it from the list, |
| 663 | * unset the dirty flag and drop the dlm lock */ |
| 664 | BUG_ON(!res); |
| 665 | dlm_lockres_get(res); |
| 666 | |
| 667 | spin_lock(&res->spinlock); |
Kurt Hackel | ddc09c8 | 2007-01-05 15:00:17 -0800 | [diff] [blame] | 668 | /* We clear the DLM_LOCK_RES_DIRTY state once we shuffle lists below */ |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 669 | list_del_init(&res->dirty); |
| 670 | spin_unlock(&res->spinlock); |
| 671 | spin_unlock(&dlm->spinlock); |
Kurt Hackel | 6ff06a9 | 2006-05-01 11:51:45 -0700 | [diff] [blame] | 672 | /* Drop dirty_list ref */ |
| 673 | dlm_lockres_put(res); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 674 | |
| 675 | /* lockres can be re-dirtied/re-added to the |
| 676 | * dirty_list in this gap, but that is ok */ |
| 677 | |
Wengang Wang | d9ef752 | 2010-05-17 20:20:44 +0800 | [diff] [blame] | 678 | spin_lock(&dlm->ast_lock); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 679 | spin_lock(&res->spinlock); |
| 680 | if (res->owner != dlm->node_num) { |
| 681 | __dlm_print_one_lock_resource(res); |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 682 | mlog(ML_ERROR, "%s: inprog %d, mig %d, reco %d," |
| 683 | " dirty %d\n", dlm->name, |
| 684 | !!(res->state & DLM_LOCK_RES_IN_PROGRESS), |
| 685 | !!(res->state & DLM_LOCK_RES_MIGRATING), |
| 686 | !!(res->state & DLM_LOCK_RES_RECOVERING), |
| 687 | !!(res->state & DLM_LOCK_RES_DIRTY)); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 688 | } |
| 689 | BUG_ON(res->owner != dlm->node_num); |
| 690 | |
| 691 | /* it is now ok to move lockreses in these states |
| 692 | * to the dirty list, assuming that they will only be |
| 693 | * dirty for a short while. */ |
Kurt Hackel | ddc09c8 | 2007-01-05 15:00:17 -0800 | [diff] [blame] | 694 | BUG_ON(res->state & DLM_LOCK_RES_MIGRATING); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 695 | if (res->state & (DLM_LOCK_RES_IN_PROGRESS | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 696 | DLM_LOCK_RES_RECOVERING)) { |
| 697 | /* move it to the tail and keep going */ |
Kurt Hackel | ddc09c8 | 2007-01-05 15:00:17 -0800 | [diff] [blame] | 698 | res->state &= ~DLM_LOCK_RES_DIRTY; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 699 | spin_unlock(&res->spinlock); |
Wengang Wang | d9ef752 | 2010-05-17 20:20:44 +0800 | [diff] [blame] | 700 | spin_unlock(&dlm->ast_lock); |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 701 | mlog(0, "%s: res %.*s, inprogress, delay list " |
| 702 | "shuffle, state %d\n", dlm->name, |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 703 | res->lockname.len, res->lockname.name, |
| 704 | res->state); |
| 705 | delay = 1; |
| 706 | goto in_progress; |
| 707 | } |
| 708 | |
| 709 | /* at this point the lockres is not migrating/ |
| 710 | * recovering/in-progress. we have the lockres |
| 711 | * spinlock and do NOT have the dlm lock. |
| 712 | * safe to reserve/queue asts and run the lists. */ |
| 713 | |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 714 | /* called while holding lockres lock */ |
| 715 | dlm_shuffle_lists(dlm, res); |
Kurt Hackel | ddc09c8 | 2007-01-05 15:00:17 -0800 | [diff] [blame] | 716 | res->state &= ~DLM_LOCK_RES_DIRTY; |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 717 | spin_unlock(&res->spinlock); |
Wengang Wang | d9ef752 | 2010-05-17 20:20:44 +0800 | [diff] [blame] | 718 | spin_unlock(&dlm->ast_lock); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 719 | |
| 720 | dlm_lockres_calc_usage(dlm, res); |
| 721 | |
| 722 | in_progress: |
| 723 | |
| 724 | spin_lock(&dlm->spinlock); |
| 725 | /* if the lock was in-progress, stick |
| 726 | * it on the back of the list */ |
| 727 | if (delay) { |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 728 | spin_lock(&res->spinlock); |
Kurt Hackel | ddc09c8 | 2007-01-05 15:00:17 -0800 | [diff] [blame] | 729 | __dlm_dirty_lockres(dlm, res); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 730 | spin_unlock(&res->spinlock); |
| 731 | } |
| 732 | dlm_lockres_put(res); |
| 733 | |
| 734 | /* unlikely, but we may need to give time to |
| 735 | * other tasks */ |
| 736 | if (!--n) { |
Sunil Mushran | 8e17d16 | 2010-11-19 15:06:49 -0800 | [diff] [blame] | 737 | mlog(0, "%s: Throttling dlm thread\n", |
| 738 | dlm->name); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 739 | break; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | spin_unlock(&dlm->spinlock); |
| 744 | dlm_flush_asts(dlm); |
| 745 | |
| 746 | /* yield and continue right away if there is more work to do */ |
| 747 | if (!n) { |
Kurt Hackel | f85cd47 | 2006-05-01 14:27:41 -0700 | [diff] [blame] | 748 | cond_resched(); |
Kurt Hackel | 6714d8e | 2005-12-15 14:31:23 -0800 | [diff] [blame] | 749 | continue; |
| 750 | } |
| 751 | |
| 752 | wait_event_interruptible_timeout(dlm->dlm_thread_wq, |
| 753 | !dlm_dirty_list_empty(dlm) || |
| 754 | kthread_should_stop(), |
| 755 | timeout); |
| 756 | } |
| 757 | |
| 758 | mlog(0, "quitting DLM thread\n"); |
| 759 | return 0; |
| 760 | } |