diff options
Diffstat (limited to 'fs/ocfs2/dlm/dlmthread.c')
| -rw-r--r-- | fs/ocfs2/dlm/dlmthread.c | 114 |
1 files changed, 55 insertions, 59 deletions
diff --git a/fs/ocfs2/dlm/dlmthread.c b/fs/ocfs2/dlm/dlmthread.c index d4f73ca68fe5..2211acf33d9b 100644 --- a/fs/ocfs2/dlm/dlmthread.c +++ b/fs/ocfs2/dlm/dlmthread.c | |||
| @@ -92,19 +92,27 @@ int __dlm_lockres_has_locks(struct dlm_lock_resource *res) | |||
| 92 | * truly ready to be freed. */ | 92 | * truly ready to be freed. */ |
| 93 | int __dlm_lockres_unused(struct dlm_lock_resource *res) | 93 | int __dlm_lockres_unused(struct dlm_lock_resource *res) |
| 94 | { | 94 | { |
| 95 | if (!__dlm_lockres_has_locks(res) && | 95 | int bit; |
| 96 | (list_empty(&res->dirty) && !(res->state & DLM_LOCK_RES_DIRTY))) { | 96 | |
| 97 | /* try not to scan the bitmap unless the first two | 97 | if (__dlm_lockres_has_locks(res)) |
| 98 | * conditions are already true */ | 98 | return 0; |
| 99 | int bit = find_next_bit(res->refmap, O2NM_MAX_NODES, 0); | 99 | |
| 100 | if (bit >= O2NM_MAX_NODES) { | 100 | if (!list_empty(&res->dirty) || res->state & DLM_LOCK_RES_DIRTY) |
| 101 | /* since the bit for dlm->node_num is not | 101 | return 0; |
| 102 | * set, inflight_locks better be zero */ | 102 | |
| 103 | BUG_ON(res->inflight_locks != 0); | 103 | if (res->state & DLM_LOCK_RES_RECOVERING) |
| 104 | return 1; | 104 | return 0; |
| 105 | } | 105 | |
| 106 | } | 106 | bit = find_next_bit(res->refmap, O2NM_MAX_NODES, 0); |
| 107 | return 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; | ||
| 108 | } | 116 | } |
| 109 | 117 | ||
| 110 | 118 | ||
| @@ -152,45 +160,25 @@ void dlm_lockres_calc_usage(struct dlm_ctxt *dlm, | |||
| 152 | spin_unlock(&dlm->spinlock); | 160 | spin_unlock(&dlm->spinlock); |
| 153 | } | 161 | } |
| 154 | 162 | ||
| 155 | static int dlm_purge_lockres(struct dlm_ctxt *dlm, | 163 | static void dlm_purge_lockres(struct dlm_ctxt *dlm, |
| 156 | struct dlm_lock_resource *res) | 164 | struct dlm_lock_resource *res) |
| 157 | { | 165 | { |
| 158 | int master; | 166 | int master; |
| 159 | int ret = 0; | 167 | int ret = 0; |
| 160 | 168 | ||
| 161 | spin_lock(&res->spinlock); | 169 | assert_spin_locked(&dlm->spinlock); |
| 162 | if (!__dlm_lockres_unused(res)) { | 170 | assert_spin_locked(&res->spinlock); |
| 163 | mlog(0, "%s:%.*s: tried to purge but not unused\n", | ||
| 164 | dlm->name, res->lockname.len, res->lockname.name); | ||
| 165 | __dlm_print_one_lock_resource(res); | ||
| 166 | spin_unlock(&res->spinlock); | ||
| 167 | BUG(); | ||
| 168 | } | ||
| 169 | |||
| 170 | if (res->state & DLM_LOCK_RES_MIGRATING) { | ||
| 171 | mlog(0, "%s:%.*s: Delay dropref as this lockres is " | ||
| 172 | "being remastered\n", dlm->name, res->lockname.len, | ||
| 173 | res->lockname.name); | ||
| 174 | /* Re-add the lockres to the end of the purge list */ | ||
| 175 | if (!list_empty(&res->purge)) { | ||
| 176 | list_del_init(&res->purge); | ||
| 177 | list_add_tail(&res->purge, &dlm->purge_list); | ||
| 178 | } | ||
| 179 | spin_unlock(&res->spinlock); | ||
| 180 | return 0; | ||
| 181 | } | ||
| 182 | 171 | ||
| 183 | master = (res->owner == dlm->node_num); | 172 | master = (res->owner == dlm->node_num); |
| 184 | 173 | ||
| 185 | if (!master) | ||
| 186 | res->state |= DLM_LOCK_RES_DROPPING_REF; | ||
| 187 | spin_unlock(&res->spinlock); | ||
| 188 | 174 | ||
| 189 | mlog(0, "purging lockres %.*s, master = %d\n", res->lockname.len, | 175 | mlog(0, "purging lockres %.*s, master = %d\n", res->lockname.len, |
| 190 | res->lockname.name, master); | 176 | res->lockname.name, master); |
| 191 | 177 | ||
| 192 | if (!master) { | 178 | if (!master) { |
| 179 | res->state |= DLM_LOCK_RES_DROPPING_REF; | ||
| 193 | /* drop spinlock... retake below */ | 180 | /* drop spinlock... retake below */ |
| 181 | spin_unlock(&res->spinlock); | ||
| 194 | spin_unlock(&dlm->spinlock); | 182 | spin_unlock(&dlm->spinlock); |
| 195 | 183 | ||
| 196 | spin_lock(&res->spinlock); | 184 | spin_lock(&res->spinlock); |
| @@ -208,31 +196,35 @@ static int dlm_purge_lockres(struct dlm_ctxt *dlm, | |||
| 208 | mlog(0, "%s:%.*s: dlm_deref_lockres returned %d\n", | 196 | mlog(0, "%s:%.*s: dlm_deref_lockres returned %d\n", |
| 209 | dlm->name, res->lockname.len, res->lockname.name, ret); | 197 | dlm->name, res->lockname.len, res->lockname.name, ret); |
| 210 | spin_lock(&dlm->spinlock); | 198 | spin_lock(&dlm->spinlock); |
| 199 | spin_lock(&res->spinlock); | ||
| 211 | } | 200 | } |
| 212 | 201 | ||
| 213 | spin_lock(&res->spinlock); | ||
| 214 | if (!list_empty(&res->purge)) { | 202 | if (!list_empty(&res->purge)) { |
| 215 | mlog(0, "removing lockres %.*s:%p from purgelist, " | 203 | mlog(0, "removing lockres %.*s:%p from purgelist, " |
| 216 | "master = %d\n", res->lockname.len, res->lockname.name, | 204 | "master = %d\n", res->lockname.len, res->lockname.name, |
| 217 | res, master); | 205 | res, master); |
| 218 | list_del_init(&res->purge); | 206 | list_del_init(&res->purge); |
| 219 | spin_unlock(&res->spinlock); | ||
| 220 | dlm_lockres_put(res); | 207 | dlm_lockres_put(res); |
| 221 | dlm->purge_count--; | 208 | dlm->purge_count--; |
| 222 | } else | 209 | } |
| 223 | spin_unlock(&res->spinlock); | 210 | |
| 211 | if (!__dlm_lockres_unused(res)) { | ||
| 212 | mlog(ML_ERROR, "found lockres %s:%.*s: in use after deref\n", | ||
| 213 | dlm->name, res->lockname.len, res->lockname.name); | ||
| 214 | __dlm_print_one_lock_resource(res); | ||
| 215 | BUG(); | ||
| 216 | } | ||
| 224 | 217 | ||
| 225 | __dlm_unhash_lockres(res); | 218 | __dlm_unhash_lockres(res); |
| 226 | 219 | ||
| 227 | /* lockres is not in the hash now. drop the flag and wake up | 220 | /* lockres is not in the hash now. drop the flag and wake up |
| 228 | * any processes waiting in dlm_get_lock_resource. */ | 221 | * any processes waiting in dlm_get_lock_resource. */ |
| 229 | if (!master) { | 222 | if (!master) { |
| 230 | spin_lock(&res->spinlock); | ||
| 231 | res->state &= ~DLM_LOCK_RES_DROPPING_REF; | 223 | res->state &= ~DLM_LOCK_RES_DROPPING_REF; |
| 232 | spin_unlock(&res->spinlock); | 224 | spin_unlock(&res->spinlock); |
| 233 | wake_up(&res->wq); | 225 | wake_up(&res->wq); |
| 234 | } | 226 | } else |
| 235 | return 0; | 227 | spin_unlock(&res->spinlock); |
| 236 | } | 228 | } |
| 237 | 229 | ||
| 238 | static void dlm_run_purge_list(struct dlm_ctxt *dlm, | 230 | static void dlm_run_purge_list(struct dlm_ctxt *dlm, |
| @@ -251,17 +243,7 @@ static void dlm_run_purge_list(struct dlm_ctxt *dlm, | |||
| 251 | lockres = list_entry(dlm->purge_list.next, | 243 | lockres = list_entry(dlm->purge_list.next, |
| 252 | struct dlm_lock_resource, purge); | 244 | struct dlm_lock_resource, purge); |
| 253 | 245 | ||
| 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 -- there's no need to keep the lockres | ||
| 258 | * spinlock. */ | ||
| 259 | spin_lock(&lockres->spinlock); | 246 | spin_lock(&lockres->spinlock); |
| 260 | unused = __dlm_lockres_unused(lockres); | ||
| 261 | spin_unlock(&lockres->spinlock); | ||
| 262 | |||
| 263 | if (!unused) | ||
| 264 | continue; | ||
| 265 | 247 | ||
| 266 | purge_jiffies = lockres->last_used + | 248 | purge_jiffies = lockres->last_used + |
| 267 | msecs_to_jiffies(DLM_PURGE_INTERVAL_MS); | 249 | msecs_to_jiffies(DLM_PURGE_INTERVAL_MS); |
| @@ -273,15 +255,29 @@ static void dlm_run_purge_list(struct dlm_ctxt *dlm, | |||
| 273 | * in tail order, we can stop at the first | 255 | * in tail order, we can stop at the first |
| 274 | * unpurgable resource -- anyone added after | 256 | * unpurgable resource -- anyone added after |
| 275 | * him will have a greater last_used value */ | 257 | * him will have a greater last_used value */ |
| 258 | spin_unlock(&lockres->spinlock); | ||
| 276 | break; | 259 | break; |
| 277 | } | 260 | } |
| 278 | 261 | ||
| 262 | /* Status of the lockres *might* change so double | ||
| 263 | * check. If the lockres is unused, holding the dlm | ||
| 264 | * spinlock will prevent people from getting and more | ||
| 265 | * refs on it. */ | ||
| 266 | unused = __dlm_lockres_unused(lockres); | ||
| 267 | if (!unused || | ||
| 268 | (lockres->state & DLM_LOCK_RES_MIGRATING)) { | ||
| 269 | mlog(0, "lockres %s:%.*s: is in use or " | ||
| 270 | "being remastered, used %d, state %d\n", | ||
| 271 | dlm->name, lockres->lockname.len, | ||
| 272 | lockres->lockname.name, !unused, lockres->state); | ||
| 273 | list_move_tail(&dlm->purge_list, &lockres->purge); | ||
| 274 | spin_unlock(&lockres->spinlock); | ||
| 275 | continue; | ||
| 276 | } | ||
| 277 | |||
| 279 | dlm_lockres_get(lockres); | 278 | dlm_lockres_get(lockres); |
| 280 | 279 | ||
| 281 | /* This may drop and reacquire the dlm spinlock if it | 280 | dlm_purge_lockres(dlm, lockres); |
| 282 | * has to do migration. */ | ||
| 283 | if (dlm_purge_lockres(dlm, lockres)) | ||
| 284 | BUG(); | ||
| 285 | 281 | ||
| 286 | dlm_lockres_put(lockres); | 282 | dlm_lockres_put(lockres); |
| 287 | 283 | ||
