Blame view
fs/ocfs2/localalloc.c
34.1 KB
ccd979bdb [PATCH] OCFS2: Th... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/* -*- mode: c; c-basic-offset: 8; -*- * vim: noexpandtab sw=8 ts=8 sts=0: * * localalloc.c * * Node local data allocation * * Copyright (C) 2002, 2004 Oracle. All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 021110-1307, USA. */ #include <linux/fs.h> #include <linux/types.h> #include <linux/slab.h> #include <linux/highmem.h> #include <linux/bitops.h> |
ccd979bdb [PATCH] OCFS2: Th... |
31 32 33 34 35 |
#include <cluster/masklog.h> #include "ocfs2.h" #include "alloc.h" |
13723d00e ocfs2: Use metada... |
36 |
#include "blockcheck.h" |
ccd979bdb [PATCH] OCFS2: Th... |
37 38 39 40 41 42 43 |
#include "dlmglue.h" #include "inode.h" #include "journal.h" #include "localalloc.h" #include "suballoc.h" #include "super.h" #include "sysfile.h" |
a04733d8a ocfs2: Remove mlo... |
44 |
#include "ocfs2_trace.h" |
ccd979bdb [PATCH] OCFS2: Th... |
45 46 47 48 |
#include "buffer_head_io.h" #define OCFS2_LOCAL_ALLOC(dinode) (&((dinode)->id2.i_lab)) |
ccd979bdb [PATCH] OCFS2: Th... |
49 50 51 52 |
static u32 ocfs2_local_alloc_count_bits(struct ocfs2_dinode *alloc); static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb, struct ocfs2_dinode *alloc, |
d02f00cc0 ocfs2: allocation... |
53 54 |
u32 *numbits, struct ocfs2_alloc_reservation *resv); |
ccd979bdb [PATCH] OCFS2: Th... |
55 56 57 58 |
static void ocfs2_clear_local_alloc(struct ocfs2_dinode *alloc); static int ocfs2_sync_local_to_main(struct ocfs2_super *osb, |
1fabe1481 ocfs2: Remove str... |
59 |
handle_t *handle, |
ccd979bdb [PATCH] OCFS2: Th... |
60 61 62 63 64 |
struct ocfs2_dinode *alloc, struct inode *main_bm_inode, struct buffer_head *main_bm_bh); static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb, |
ccd979bdb [PATCH] OCFS2: Th... |
65 66 67 68 69 |
struct ocfs2_alloc_context **ac, struct inode **bitmap_inode, struct buffer_head **bitmap_bh); static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb, |
1fabe1481 ocfs2: Remove str... |
70 |
handle_t *handle, |
ccd979bdb [PATCH] OCFS2: Th... |
71 72 73 74 |
struct ocfs2_alloc_context *ac); static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb, struct inode *local_alloc_inode); |
6b82021b9 ocfs2: increase t... |
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
/* * ocfs2_la_default_mb() - determine a default size, in megabytes of * the local alloc. * * Generally, we'd like to pick as large a local alloc as * possible. Performance on large workloads tends to scale * proportionally to la size. In addition to that, the reservations * code functions more efficiently as it can reserve more windows for * write. * * Some things work against us when trying to choose a large local alloc: * * - We need to ensure our sizing is picked to leave enough space in * group descriptors for other allocations (such as block groups, * etc). Picking default sizes which are a multiple of 4 could help * - block groups are allocated in 2mb and 4mb chunks. * * - Likewise, we don't want to starve other nodes of bits on small * file systems. This can easily be taken care of by limiting our * default to a reasonable size (256M) on larger cluster sizes. * * - Some file systems can't support very large sizes - 4k and 8k in * particular are limited to less than 128 and 256 megabytes respectively. * * The following reference table shows group descriptor and local * alloc maximums at various cluster sizes (4k blocksize) * * csize: 4K group: 126M la: 121M * csize: 8K group: 252M la: 243M * csize: 16K group: 504M la: 486M * csize: 32K group: 1008M la: 972M * csize: 64K group: 2016M la: 1944M * csize: 128K group: 4032M la: 3888M * csize: 256K group: 8064M la: 7776M * csize: 512K group: 16128M la: 15552M * csize: 1024K group: 32256M la: 31104M */ #define OCFS2_LA_MAX_DEFAULT_MB 256 #define OCFS2_LA_OLD_DEFAULT 8 unsigned int ocfs2_la_default_mb(struct ocfs2_super *osb) { unsigned int la_mb; unsigned int gd_mb; |
1739da405 ocfs2: Limit defa... |
118 |
unsigned int la_max_mb; |
6b82021b9 ocfs2: increase t... |
119 120 121 122 |
unsigned int megs_per_slot; struct super_block *sb = osb->sb; gd_mb = ocfs2_clusters_to_megabytes(osb->sb, |
8571882c2 ocfs2: ocfs2_grou... |
123 |
8 * ocfs2_group_bitmap_size(sb, 0, osb->s_feature_incompat)); |
6b82021b9 ocfs2: increase t... |
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
/* * This takes care of files systems with very small group * descriptors - 512 byte blocksize at cluster sizes lower * than 16K and also 1k blocksize with 4k cluster size. */ if ((sb->s_blocksize == 512 && osb->s_clustersize <= 8192) || (sb->s_blocksize == 1024 && osb->s_clustersize == 4096)) return OCFS2_LA_OLD_DEFAULT; /* * Leave enough room for some block groups and make the final * value we work from a multiple of 4. */ gd_mb -= 16; gd_mb &= 0xFFFFFFFB; la_mb = gd_mb; /* * Keep window sizes down to a reasonable default */ if (la_mb > OCFS2_LA_MAX_DEFAULT_MB) { /* * Some clustersize / blocksize combinations will have * given us a larger than OCFS2_LA_MAX_DEFAULT_MB * default size, but get poor distribution when * limited to exactly 256 megabytes. * * As an example, 16K clustersize at 4K blocksize * gives us a cluster group size of 504M. Paring the * local alloc size down to 256 however, would give us * only one window and around 200MB left in the * cluster group. Instead, find the first size below * 256 which would give us an even distribution. * * Larger cluster group sizes actually work out pretty * well when pared to 256, so we don't have to do this * for any group that fits more than two * OCFS2_LA_MAX_DEFAULT_MB windows. */ if (gd_mb > (2 * OCFS2_LA_MAX_DEFAULT_MB)) la_mb = 256; else { unsigned int gd_mult = gd_mb; while (gd_mult > 256) gd_mult = gd_mult >> 1; la_mb = gd_mult; } } megs_per_slot = osb->osb_clusters_at_boot / osb->max_slots; megs_per_slot = ocfs2_clusters_to_megabytes(osb->sb, megs_per_slot); /* Too many nodes, too few disk clusters. */ if (megs_per_slot < la_mb) la_mb = megs_per_slot; |
1739da405 ocfs2: Limit defa... |
182 183 184 185 186 |
/* We can't store more bits than we can in a block. */ la_max_mb = ocfs2_clusters_to_megabytes(osb->sb, ocfs2_local_alloc_size(sb) * 8); if (la_mb > la_max_mb) la_mb = la_max_mb; |
6b82021b9 ocfs2: increase t... |
187 188 |
return la_mb; } |
73c8a8000 ocfs2: clean up l... |
189 190 191 |
void ocfs2_la_set_sizes(struct ocfs2_super *osb, int requested_mb) { struct super_block *sb = osb->sb; |
6b82021b9 ocfs2: increase t... |
192 |
unsigned int la_default_mb = ocfs2_la_default_mb(osb); |
73c8a8000 ocfs2: clean up l... |
193 194 195 196 |
unsigned int la_max_mb; la_max_mb = ocfs2_clusters_to_megabytes(sb, ocfs2_local_alloc_size(sb) * 8); |
a04733d8a ocfs2: Remove mlo... |
197 |
trace_ocfs2_la_set_sizes(requested_mb, la_max_mb, la_default_mb); |
73c8a8000 ocfs2: clean up l... |
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
if (requested_mb == -1) { /* No user request - use defaults */ osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, la_default_mb); } else if (requested_mb > la_max_mb) { /* Request is too big, we give the maximum available */ osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, la_max_mb); } else { osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, requested_mb); } osb->local_alloc_bits = osb->local_alloc_default_bits; } |
9c7af40b2 ocfs2: throttle b... |
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
static inline int ocfs2_la_state_enabled(struct ocfs2_super *osb) { return (osb->local_alloc_state == OCFS2_LA_THROTTLED || osb->local_alloc_state == OCFS2_LA_ENABLED); } void ocfs2_local_alloc_seen_free_bits(struct ocfs2_super *osb, unsigned int num_clusters) { spin_lock(&osb->osb_lock); if (osb->local_alloc_state == OCFS2_LA_DISABLED || osb->local_alloc_state == OCFS2_LA_THROTTLED) if (num_clusters >= osb->local_alloc_default_bits) { cancel_delayed_work(&osb->la_enable_wq); osb->local_alloc_state = OCFS2_LA_ENABLED; } spin_unlock(&osb->osb_lock); } void ocfs2_la_enable_worker(struct work_struct *work) { struct ocfs2_super *osb = container_of(work, struct ocfs2_super, la_enable_wq.work); spin_lock(&osb->osb_lock); osb->local_alloc_state = OCFS2_LA_ENABLED; spin_unlock(&osb->osb_lock); } |
ccd979bdb [PATCH] OCFS2: Th... |
242 243 244 |
/* * Tell us whether a given allocation should use the local alloc * file. Otherwise, it has to go to the main bitmap. |
9c7af40b2 ocfs2: throttle b... |
245 246 247 |
* * This function does semi-dirty reads of local alloc size and state! * This is ok however, as the values are re-checked once under mutex. |
ccd979bdb [PATCH] OCFS2: Th... |
248 249 250 |
*/ int ocfs2_alloc_should_use_local(struct ocfs2_super *osb, u64 bits) { |
2fbe8d1eb ocfs2: Local allo... |
251 |
int ret = 0; |
9c7af40b2 ocfs2: throttle b... |
252 253 254 255 |
int la_bits; spin_lock(&osb->osb_lock); la_bits = osb->local_alloc_bits; |
ccd979bdb [PATCH] OCFS2: Th... |
256 |
|
9c7af40b2 ocfs2: throttle b... |
257 |
if (!ocfs2_la_state_enabled(osb)) |
2fbe8d1eb ocfs2: Local allo... |
258 |
goto bail; |
ccd979bdb [PATCH] OCFS2: Th... |
259 260 261 262 263 264 |
/* la_bits should be at least twice the size (in clusters) of * a new block group. We want to be sure block group * allocations go through the local alloc, so allow an * allocation to take up to half the bitmap. */ if (bits > (la_bits / 2)) |
2fbe8d1eb ocfs2: Local allo... |
265 |
goto bail; |
ccd979bdb [PATCH] OCFS2: Th... |
266 |
|
2fbe8d1eb ocfs2: Local allo... |
267 268 |
ret = 1; bail: |
a04733d8a ocfs2: Remove mlo... |
269 270 |
trace_ocfs2_alloc_should_use_local( (unsigned long long)bits, osb->local_alloc_state, la_bits, ret); |
9c7af40b2 ocfs2: throttle b... |
271 |
spin_unlock(&osb->osb_lock); |
2fbe8d1eb ocfs2: Local allo... |
272 |
return ret; |
ccd979bdb [PATCH] OCFS2: Th... |
273 274 275 276 277 278 279 280 281 282 |
} int ocfs2_load_local_alloc(struct ocfs2_super *osb) { int status = 0; struct ocfs2_dinode *alloc = NULL; struct buffer_head *alloc_bh = NULL; u32 num_used; struct inode *inode = NULL; struct ocfs2_local_alloc *la; |
ebcee4b5c ocfs2: Track loca... |
283 |
if (osb->local_alloc_bits == 0) |
2fbe8d1eb ocfs2: Local allo... |
284 |
goto bail; |
ebcee4b5c ocfs2: Track loca... |
285 |
if (osb->local_alloc_bits >= osb->bitmap_cpg) { |
2fbe8d1eb ocfs2: Local allo... |
286 287 288 |
mlog(ML_NOTICE, "Requested local alloc window %d is larger " "than max possible %u. Using defaults. ", |
ebcee4b5c ocfs2: Track loca... |
289 290 291 |
osb->local_alloc_bits, (osb->bitmap_cpg - 1)); osb->local_alloc_bits = ocfs2_megabytes_to_clusters(osb->sb, |
6b82021b9 ocfs2: increase t... |
292 |
ocfs2_la_default_mb(osb)); |
2fbe8d1eb ocfs2: Local allo... |
293 |
} |
ccd979bdb [PATCH] OCFS2: Th... |
294 295 296 297 298 299 300 301 |
/* read the alloc off disk */ inode = ocfs2_get_system_file_inode(osb, LOCAL_ALLOC_SYSTEM_INODE, osb->slot_num); if (!inode) { status = -EINVAL; mlog_errno(status); goto bail; } |
b657c95c1 ocfs2: Wrap inode... |
302 303 |
status = ocfs2_read_inode_block_full(inode, &alloc_bh, OCFS2_BH_IGNORE_CACHE); |
ccd979bdb [PATCH] OCFS2: Th... |
304 305 306 307 308 309 310 311 312 313 |
if (status < 0) { mlog_errno(status); goto bail; } alloc = (struct ocfs2_dinode *) alloc_bh->b_data; la = OCFS2_LOCAL_ALLOC(alloc); if (!(le32_to_cpu(alloc->i_flags) & (OCFS2_LOCAL_ALLOC_FL|OCFS2_BITMAP_FL))) { |
b0697053f ocfs2: don't use ... |
314 315 316 |
mlog(ML_ERROR, "Invalid local alloc inode, %llu ", (unsigned long long)OCFS2_I(inode)->ip_blkno); |
ccd979bdb [PATCH] OCFS2: Th... |
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
status = -EINVAL; goto bail; } if ((la->la_size == 0) || (le16_to_cpu(la->la_size) > ocfs2_local_alloc_size(inode->i_sb))) { mlog(ML_ERROR, "Local alloc size is invalid (la_size = %u) ", le16_to_cpu(la->la_size)); status = -EINVAL; goto bail; } /* do a little verification. */ num_used = ocfs2_local_alloc_count_bits(alloc); /* hopefully the local alloc has always been recovered before * we load it. */ if (num_used || alloc->id1.bitmap1.i_used || alloc->id1.bitmap1.i_total |
5a404f39f ocfs2: fix panic ... |
338 339 340 341 |
|| la->la_bm_off) { mlog(ML_ERROR, "inconsistent detected, clean journal with" " unrecovered local alloc, please run fsck.ocfs2! " |
ccd979bdb [PATCH] OCFS2: Th... |
342 343 344 345 346 |
"found = %u, set = %u, taken = %u, off = %u ", num_used, le32_to_cpu(alloc->id1.bitmap1.i_used), le32_to_cpu(alloc->id1.bitmap1.i_total), OCFS2_LOCAL_ALLOC(alloc)->la_bm_off); |
5a404f39f ocfs2: fix panic ... |
347 348 349 |
status = -EINVAL; goto bail; } |
ccd979bdb [PATCH] OCFS2: Th... |
350 351 352 353 354 |
osb->local_alloc_bh = alloc_bh; osb->local_alloc_state = OCFS2_LA_ENABLED; bail: if (status < 0) |
a81cb88b6 ocfs2: Don't chec... |
355 |
brelse(alloc_bh); |
72865d923 ocfs2: clean up r... |
356 |
iput(inode); |
ccd979bdb [PATCH] OCFS2: Th... |
357 |
|
a04733d8a ocfs2: Remove mlo... |
358 |
trace_ocfs2_load_local_alloc(osb->local_alloc_bits); |
2fbe8d1eb ocfs2: Local allo... |
359 |
|
c1e8d35ef ocfs2: Remove EXI... |
360 361 |
if (status) mlog_errno(status); |
ccd979bdb [PATCH] OCFS2: Th... |
362 363 364 365 366 367 368 369 370 371 372 373 374 |
return status; } /* * return any unused bits to the bitmap and write out a clean * local_alloc. * * local_alloc_bh is optional. If not passed, we will simply use the * one off osb. If you do pass it however, be warned that it *will* be * returned brelse'd and NULL'd out.*/ void ocfs2_shutdown_local_alloc(struct ocfs2_super *osb) { int status; |
1fabe1481 ocfs2: Remove str... |
375 |
handle_t *handle; |
ccd979bdb [PATCH] OCFS2: Th... |
376 377 378 379 380 381 |
struct inode *local_alloc_inode = NULL; struct buffer_head *bh = NULL; struct buffer_head *main_bm_bh = NULL; struct inode *main_bm_inode = NULL; struct ocfs2_dinode *alloc_copy = NULL; struct ocfs2_dinode *alloc = NULL; |
9c7af40b2 ocfs2: throttle b... |
382 |
cancel_delayed_work(&osb->la_enable_wq); |
35ddf78e4 ocfs2: fix occurr... |
383 |
flush_workqueue(osb->ocfs2_wq); |
9c7af40b2 ocfs2: throttle b... |
384 |
|
ccd979bdb [PATCH] OCFS2: Th... |
385 |
if (osb->local_alloc_state == OCFS2_LA_UNUSED) |
8898a5a58 ocfs2: don't pass... |
386 |
goto out; |
ccd979bdb [PATCH] OCFS2: Th... |
387 388 389 390 391 392 393 394 |
local_alloc_inode = ocfs2_get_system_file_inode(osb, LOCAL_ALLOC_SYSTEM_INODE, osb->slot_num); if (!local_alloc_inode) { status = -ENOENT; mlog_errno(status); |
8898a5a58 ocfs2: don't pass... |
395 |
goto out; |
ccd979bdb [PATCH] OCFS2: Th... |
396 397 398 |
} osb->local_alloc_state = OCFS2_LA_DISABLED; |
d02f00cc0 ocfs2: allocation... |
399 |
ocfs2_resmap_uninit(&osb->osb_la_resmap); |
ccd979bdb [PATCH] OCFS2: Th... |
400 401 402 403 404 405 |
main_bm_inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE, OCFS2_INVALID_SLOT); if (!main_bm_inode) { status = -EINVAL; mlog_errno(status); |
8898a5a58 ocfs2: don't pass... |
406 |
goto out; |
ccd979bdb [PATCH] OCFS2: Th... |
407 |
} |
5955102c9 wrappers for ->i_... |
408 |
inode_lock(main_bm_inode); |
8898a5a58 ocfs2: don't pass... |
409 |
|
e63aecb65 ocfs2: Rename ocf... |
410 |
status = ocfs2_inode_lock(main_bm_inode, &main_bm_bh, 1); |
ccd979bdb [PATCH] OCFS2: Th... |
411 412 |
if (status < 0) { mlog_errno(status); |
8898a5a58 ocfs2: don't pass... |
413 |
goto out_mutex; |
ccd979bdb [PATCH] OCFS2: Th... |
414 415 416 |
} /* WINDOW_MOVE_CREDITS is a bit heavy... */ |
65eff9ccf ocfs2: remove han... |
417 |
handle = ocfs2_start_trans(osb, OCFS2_WINDOW_MOVE_CREDITS); |
ccd979bdb [PATCH] OCFS2: Th... |
418 419 420 |
if (IS_ERR(handle)) { mlog_errno(PTR_ERR(handle)); handle = NULL; |
8898a5a58 ocfs2: don't pass... |
421 |
goto out_unlock; |
ccd979bdb [PATCH] OCFS2: Th... |
422 423 424 425 |
} bh = osb->local_alloc_bh; alloc = (struct ocfs2_dinode *) bh->b_data; |
4ba1c5bfd ocfs2: Use GFP_NO... |
426 |
alloc_copy = kmalloc(bh->b_size, GFP_NOFS); |
ccd979bdb [PATCH] OCFS2: Th... |
427 428 |
if (!alloc_copy) { status = -ENOMEM; |
8898a5a58 ocfs2: don't pass... |
429 |
goto out_commit; |
ccd979bdb [PATCH] OCFS2: Th... |
430 431 |
} memcpy(alloc_copy, alloc, bh->b_size); |
0cf2f7632 ocfs2: Pass struc... |
432 433 |
status = ocfs2_journal_access_di(handle, INODE_CACHE(local_alloc_inode), bh, OCFS2_JOURNAL_ACCESS_WRITE); |
ccd979bdb [PATCH] OCFS2: Th... |
434 435 |
if (status < 0) { mlog_errno(status); |
8898a5a58 ocfs2: don't pass... |
436 |
goto out_commit; |
ccd979bdb [PATCH] OCFS2: Th... |
437 438 439 |
} ocfs2_clear_local_alloc(alloc); |
ec20cec7a ocfs2: Make ocfs2... |
440 |
ocfs2_journal_dirty(handle, bh); |
ccd979bdb [PATCH] OCFS2: Th... |
441 442 443 444 445 446 447 448 449 |
brelse(bh); osb->local_alloc_bh = NULL; osb->local_alloc_state = OCFS2_LA_UNUSED; status = ocfs2_sync_local_to_main(osb, handle, alloc_copy, main_bm_inode, main_bm_bh); if (status < 0) mlog_errno(status); |
8898a5a58 ocfs2: don't pass... |
450 |
out_commit: |
02dc1af44 ocfs2: pass ocfs2... |
451 |
ocfs2_commit_trans(osb, handle); |
ccd979bdb [PATCH] OCFS2: Th... |
452 |
|
8898a5a58 ocfs2: don't pass... |
453 |
out_unlock: |
a81cb88b6 ocfs2: Don't chec... |
454 |
brelse(main_bm_bh); |
ccd979bdb [PATCH] OCFS2: Th... |
455 |
|
e63aecb65 ocfs2: Rename ocf... |
456 |
ocfs2_inode_unlock(main_bm_inode, 1); |
ccd979bdb [PATCH] OCFS2: Th... |
457 |
|
8898a5a58 ocfs2: don't pass... |
458 |
out_mutex: |
5955102c9 wrappers for ->i_... |
459 |
inode_unlock(main_bm_inode); |
8898a5a58 ocfs2: don't pass... |
460 461 462 |
iput(main_bm_inode); out: |
72865d923 ocfs2: clean up r... |
463 |
iput(local_alloc_inode); |
ccd979bdb [PATCH] OCFS2: Th... |
464 |
|
d787ab097 ocfs2: remove kfr... |
465 |
kfree(alloc_copy); |
ccd979bdb [PATCH] OCFS2: Th... |
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
} /* * We want to free the bitmap bits outside of any recovery context as * we'll need a cluster lock to do so, but we must clear the local * alloc before giving up the recovered nodes journal. To solve this, * we kmalloc a copy of the local alloc before it's change for the * caller to process with ocfs2_complete_local_alloc_recovery */ int ocfs2_begin_local_alloc_recovery(struct ocfs2_super *osb, int slot_num, struct ocfs2_dinode **alloc_copy) { int status = 0; struct buffer_head *alloc_bh = NULL; struct inode *inode = NULL; struct ocfs2_dinode *alloc; |
a04733d8a ocfs2: Remove mlo... |
483 |
trace_ocfs2_begin_local_alloc_recovery(slot_num); |
ccd979bdb [PATCH] OCFS2: Th... |
484 485 486 487 488 489 490 491 492 493 494 |
*alloc_copy = NULL; inode = ocfs2_get_system_file_inode(osb, LOCAL_ALLOC_SYSTEM_INODE, slot_num); if (!inode) { status = -EINVAL; mlog_errno(status); goto bail; } |
5955102c9 wrappers for ->i_... |
495 |
inode_lock(inode); |
ccd979bdb [PATCH] OCFS2: Th... |
496 |
|
b657c95c1 ocfs2: Wrap inode... |
497 498 |
status = ocfs2_read_inode_block_full(inode, &alloc_bh, OCFS2_BH_IGNORE_CACHE); |
ccd979bdb [PATCH] OCFS2: Th... |
499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
if (status < 0) { mlog_errno(status); goto bail; } *alloc_copy = kmalloc(alloc_bh->b_size, GFP_KERNEL); if (!(*alloc_copy)) { status = -ENOMEM; goto bail; } memcpy((*alloc_copy), alloc_bh->b_data, alloc_bh->b_size); alloc = (struct ocfs2_dinode *) alloc_bh->b_data; ocfs2_clear_local_alloc(alloc); |
13723d00e ocfs2: Use metada... |
513 |
ocfs2_compute_meta_ecc(osb->sb, alloc_bh->b_data, &alloc->i_check); |
8cb471e8f ocfs2: Take the i... |
514 |
status = ocfs2_write_block(osb, alloc_bh, INODE_CACHE(inode)); |
ccd979bdb [PATCH] OCFS2: Th... |
515 516 517 518 |
if (status < 0) mlog_errno(status); bail: |
d787ab097 ocfs2: remove kfr... |
519 |
if (status < 0) { |
ccd979bdb [PATCH] OCFS2: Th... |
520 521 522 |
kfree(*alloc_copy); *alloc_copy = NULL; } |
a81cb88b6 ocfs2: Don't chec... |
523 |
brelse(alloc_bh); |
ccd979bdb [PATCH] OCFS2: Th... |
524 525 |
if (inode) { |
5955102c9 wrappers for ->i_... |
526 |
inode_unlock(inode); |
ccd979bdb [PATCH] OCFS2: Th... |
527 528 |
iput(inode); } |
c1e8d35ef ocfs2: Remove EXI... |
529 530 |
if (status) mlog_errno(status); |
ccd979bdb [PATCH] OCFS2: Th... |
531 532 533 534 535 536 537 538 539 540 541 542 543 |
return status; } /* * Step 2: By now, we've completed the journal recovery, we've stamped * a clean local alloc on disk and dropped the node out of the * recovery map. Dlm locks will no longer stall, so lets clear out the * main bitmap. */ int ocfs2_complete_local_alloc_recovery(struct ocfs2_super *osb, struct ocfs2_dinode *alloc) { int status; |
1fabe1481 ocfs2: Remove str... |
544 |
handle_t *handle; |
ccd979bdb [PATCH] OCFS2: Th... |
545 |
struct buffer_head *main_bm_bh = NULL; |
8898a5a58 ocfs2: don't pass... |
546 |
struct inode *main_bm_inode; |
ccd979bdb [PATCH] OCFS2: Th... |
547 |
|
ccd979bdb [PATCH] OCFS2: Th... |
548 549 550 551 552 553 |
main_bm_inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE, OCFS2_INVALID_SLOT); if (!main_bm_inode) { status = -EINVAL; mlog_errno(status); |
8898a5a58 ocfs2: don't pass... |
554 |
goto out; |
ccd979bdb [PATCH] OCFS2: Th... |
555 |
} |
5955102c9 wrappers for ->i_... |
556 |
inode_lock(main_bm_inode); |
8898a5a58 ocfs2: don't pass... |
557 |
|
e63aecb65 ocfs2: Rename ocf... |
558 |
status = ocfs2_inode_lock(main_bm_inode, &main_bm_bh, 1); |
ccd979bdb [PATCH] OCFS2: Th... |
559 560 |
if (status < 0) { mlog_errno(status); |
8898a5a58 ocfs2: don't pass... |
561 |
goto out_mutex; |
ccd979bdb [PATCH] OCFS2: Th... |
562 |
} |
65eff9ccf ocfs2: remove han... |
563 |
handle = ocfs2_start_trans(osb, OCFS2_WINDOW_MOVE_CREDITS); |
ccd979bdb [PATCH] OCFS2: Th... |
564 565 566 567 |
if (IS_ERR(handle)) { status = PTR_ERR(handle); handle = NULL; mlog_errno(status); |
8898a5a58 ocfs2: don't pass... |
568 |
goto out_unlock; |
ccd979bdb [PATCH] OCFS2: Th... |
569 570 571 |
} /* we want the bitmap change to be recorded on disk asap */ |
1fabe1481 ocfs2: Remove str... |
572 |
handle->h_sync = 1; |
ccd979bdb [PATCH] OCFS2: Th... |
573 574 575 576 577 |
status = ocfs2_sync_local_to_main(osb, handle, alloc, main_bm_inode, main_bm_bh); if (status < 0) mlog_errno(status); |
02dc1af44 ocfs2: pass ocfs2... |
578 |
ocfs2_commit_trans(osb, handle); |
8898a5a58 ocfs2: don't pass... |
579 580 |
out_unlock: |
e63aecb65 ocfs2: Rename ocf... |
581 |
ocfs2_inode_unlock(main_bm_inode, 1); |
8898a5a58 ocfs2: don't pass... |
582 583 |
out_mutex: |
5955102c9 wrappers for ->i_... |
584 |
inode_unlock(main_bm_inode); |
ccd979bdb [PATCH] OCFS2: Th... |
585 |
|
a81cb88b6 ocfs2: Don't chec... |
586 |
brelse(main_bm_bh); |
ccd979bdb [PATCH] OCFS2: Th... |
587 |
|
8898a5a58 ocfs2: don't pass... |
588 |
iput(main_bm_inode); |
ccd979bdb [PATCH] OCFS2: Th... |
589 |
|
8898a5a58 ocfs2: don't pass... |
590 |
out: |
4d0ddb2ce ocfs2: Add inode ... |
591 |
if (!status) |
b89c54282 ocfs2: add extent... |
592 |
ocfs2_init_steal_slots(osb); |
c1e8d35ef ocfs2: Remove EXI... |
593 594 |
if (status) mlog_errno(status); |
ccd979bdb [PATCH] OCFS2: Th... |
595 596 597 598 |
return status; } /* |
9c7af40b2 ocfs2: throttle b... |
599 |
* make sure we've got at least bits_wanted contiguous bits in the |
1b1dcc1b5 [PATCH] mutex sub... |
600 |
* local alloc. You lose them when you drop i_mutex. |
ccd979bdb [PATCH] OCFS2: Th... |
601 602 603 604 605 |
* * We will add ourselves to the transaction passed in, but may start * our own in order to shift windows. */ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb, |
ccd979bdb [PATCH] OCFS2: Th... |
606 607 608 609 610 611 612 |
u32 bits_wanted, struct ocfs2_alloc_context *ac) { int status; struct ocfs2_dinode *alloc; struct inode *local_alloc_inode; unsigned int free_bits; |
ccd979bdb [PATCH] OCFS2: Th... |
613 |
BUG_ON(!ac); |
ccd979bdb [PATCH] OCFS2: Th... |
614 615 616 617 618 619 620 621 622 623 |
local_alloc_inode = ocfs2_get_system_file_inode(osb, LOCAL_ALLOC_SYSTEM_INODE, osb->slot_num); if (!local_alloc_inode) { status = -ENOENT; mlog_errno(status); goto bail; } |
da5cbf2f9 ocfs2: don't use ... |
624 |
|
5955102c9 wrappers for ->i_... |
625 |
inode_lock(local_alloc_inode); |
da5cbf2f9 ocfs2: don't use ... |
626 |
|
9c7af40b2 ocfs2: throttle b... |
627 628 629 630 631 632 633 634 |
/* * We must double check state and allocator bits because * another process may have changed them while holding i_mutex. */ spin_lock(&osb->osb_lock); if (!ocfs2_la_state_enabled(osb) || (bits_wanted > osb->local_alloc_bits)) { spin_unlock(&osb->osb_lock); |
ccd979bdb [PATCH] OCFS2: Th... |
635 636 637 |
status = -ENOSPC; goto bail; } |
9c7af40b2 ocfs2: throttle b... |
638 |
spin_unlock(&osb->osb_lock); |
ccd979bdb [PATCH] OCFS2: Th... |
639 640 |
alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; |
e407e3978 ocfs2: Fix CONFIG... |
641 |
#ifdef CONFIG_OCFS2_DEBUG_FS |
ccd979bdb [PATCH] OCFS2: Th... |
642 643 |
if (le32_to_cpu(alloc->id1.bitmap1.i_used) != ocfs2_local_alloc_count_bits(alloc)) { |
93f5920d8 ocfs2: return -ER... |
644 645 646 647 648 |
status = ocfs2_error(osb->sb, "local alloc inode %llu says it has %u used bits, but a count shows %u ", (unsigned long long)le64_to_cpu(alloc->i_blkno), le32_to_cpu(alloc->id1.bitmap1.i_used), ocfs2_local_alloc_count_bits(alloc)); |
ccd979bdb [PATCH] OCFS2: Th... |
649 650 |
goto bail; } |
5a58c3ef2 [PATCH] ocfs2: Re... |
651 |
#endif |
ccd979bdb [PATCH] OCFS2: Th... |
652 653 654 655 656 657 658 659 660 661 662 663 |
free_bits = le32_to_cpu(alloc->id1.bitmap1.i_total) - le32_to_cpu(alloc->id1.bitmap1.i_used); if (bits_wanted > free_bits) { /* uhoh, window change time. */ status = ocfs2_local_alloc_slide_window(osb, local_alloc_inode); if (status < 0) { if (status != -ENOSPC) mlog_errno(status); goto bail; } |
9c7af40b2 ocfs2: throttle b... |
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 |
/* * Under certain conditions, the window slide code * might have reduced the number of bits available or * disabled the the local alloc entirely. Re-check * here and return -ENOSPC if necessary. */ status = -ENOSPC; if (!ocfs2_la_state_enabled(osb)) goto bail; free_bits = le32_to_cpu(alloc->id1.bitmap1.i_total) - le32_to_cpu(alloc->id1.bitmap1.i_used); if (bits_wanted > free_bits) goto bail; |
ccd979bdb [PATCH] OCFS2: Th... |
679 |
} |
8fccfc829 ocfs2: fix inode ... |
680 |
ac->ac_inode = local_alloc_inode; |
a4a489116 ocfs2: Add ac_all... |
681 682 |
/* We should never use localalloc from another slot */ ac->ac_alloc_slot = osb->slot_num; |
8fccfc829 ocfs2: fix inode ... |
683 |
ac->ac_which = OCFS2_AC_USE_LOCAL; |
ccd979bdb [PATCH] OCFS2: Th... |
684 685 |
get_bh(osb->local_alloc_bh); ac->ac_bh = osb->local_alloc_bh; |
ccd979bdb [PATCH] OCFS2: Th... |
686 687 |
status = 0; bail: |
bda0233b8 ocfs2: Unlock mut... |
688 |
if (status < 0 && local_alloc_inode) { |
5955102c9 wrappers for ->i_... |
689 |
inode_unlock(local_alloc_inode); |
8fccfc829 ocfs2: fix inode ... |
690 |
iput(local_alloc_inode); |
bda0233b8 ocfs2: Unlock mut... |
691 |
} |
ccd979bdb [PATCH] OCFS2: Th... |
692 |
|
a04733d8a ocfs2: Remove mlo... |
693 694 695 |
trace_ocfs2_reserve_local_alloc_bits( (unsigned long long)ac->ac_max_block, bits_wanted, osb->slot_num, status); |
2fbe8d1eb ocfs2: Local allo... |
696 |
|
c1e8d35ef ocfs2: Remove EXI... |
697 698 |
if (status) mlog_errno(status); |
ccd979bdb [PATCH] OCFS2: Th... |
699 700 701 702 |
return status; } int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb, |
1fabe1481 ocfs2: Remove str... |
703 |
handle_t *handle, |
ccd979bdb [PATCH] OCFS2: Th... |
704 |
struct ocfs2_alloc_context *ac, |
415cb8003 ocfs2: Allow smal... |
705 |
u32 bits_wanted, |
ccd979bdb [PATCH] OCFS2: Th... |
706 707 708 709 710 |
u32 *bit_off, u32 *num_bits) { int status, start; struct inode *local_alloc_inode; |
ccd979bdb [PATCH] OCFS2: Th... |
711 712 713 |
void *bitmap; struct ocfs2_dinode *alloc; struct ocfs2_local_alloc *la; |
ccd979bdb [PATCH] OCFS2: Th... |
714 |
BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL); |
ccd979bdb [PATCH] OCFS2: Th... |
715 716 717 |
local_alloc_inode = ac->ac_inode; alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; la = OCFS2_LOCAL_ALLOC(alloc); |
d02f00cc0 ocfs2: allocation... |
718 719 |
start = ocfs2_local_alloc_find_clear_bits(osb, alloc, &bits_wanted, ac->ac_resv); |
ccd979bdb [PATCH] OCFS2: Th... |
720 721 722 723 724 725 726 727 728 |
if (start == -1) { /* TODO: Shouldn't we just BUG here? */ status = -ENOSPC; mlog_errno(status); goto bail; } bitmap = la->la_bitmap; *bit_off = le32_to_cpu(la->la_bm_off) + start; |
ccd979bdb [PATCH] OCFS2: Th... |
729 |
*num_bits = bits_wanted; |
0cf2f7632 ocfs2: Pass struc... |
730 731 |
status = ocfs2_journal_access_di(handle, INODE_CACHE(local_alloc_inode), |
13723d00e ocfs2: Use metada... |
732 733 |
osb->local_alloc_bh, OCFS2_JOURNAL_ACCESS_WRITE); |
ccd979bdb [PATCH] OCFS2: Th... |
734 735 736 737 |
if (status < 0) { mlog_errno(status); goto bail; } |
d02f00cc0 ocfs2: allocation... |
738 739 |
ocfs2_resmap_claimed_bits(&osb->osb_la_resmap, ac->ac_resv, start, bits_wanted); |
ccd979bdb [PATCH] OCFS2: Th... |
740 741 |
while(bits_wanted--) ocfs2_set_bit(start++, bitmap); |
0dd3256e0 [PATCH] ocfs2: le... |
742 |
le32_add_cpu(&alloc->id1.bitmap1.i_used, *num_bits); |
ec20cec7a ocfs2: Make ocfs2... |
743 |
ocfs2_journal_dirty(handle, osb->local_alloc_bh); |
ccd979bdb [PATCH] OCFS2: Th... |
744 |
|
ccd979bdb [PATCH] OCFS2: Th... |
745 |
bail: |
c1e8d35ef ocfs2: Remove EXI... |
746 747 |
if (status) mlog_errno(status); |
ccd979bdb [PATCH] OCFS2: Th... |
748 749 |
return status; } |
fb951eb5e ocfs2: free alloc... |
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 |
int ocfs2_free_local_alloc_bits(struct ocfs2_super *osb, handle_t *handle, struct ocfs2_alloc_context *ac, u32 bit_off, u32 num_bits) { int status, start; u32 clear_bits; struct inode *local_alloc_inode; void *bitmap; struct ocfs2_dinode *alloc; struct ocfs2_local_alloc *la; BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL); local_alloc_inode = ac->ac_inode; alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; la = OCFS2_LOCAL_ALLOC(alloc); bitmap = la->la_bitmap; start = bit_off - le32_to_cpu(la->la_bm_off); clear_bits = num_bits; status = ocfs2_journal_access_di(handle, INODE_CACHE(local_alloc_inode), osb->local_alloc_bh, OCFS2_JOURNAL_ACCESS_WRITE); if (status < 0) { mlog_errno(status); goto bail; } while (clear_bits--) ocfs2_clear_bit(start++, bitmap); le32_add_cpu(&alloc->id1.bitmap1.i_used, -num_bits); ocfs2_journal_dirty(handle, osb->local_alloc_bh); bail: return status; } |
ccd979bdb [PATCH] OCFS2: Th... |
791 792 |
static u32 ocfs2_local_alloc_count_bits(struct ocfs2_dinode *alloc) { |
a75613ec7 ocfs2: use memwei... |
793 |
u32 count; |
ccd979bdb [PATCH] OCFS2: Th... |
794 |
struct ocfs2_local_alloc *la = OCFS2_LOCAL_ALLOC(alloc); |
a75613ec7 ocfs2: use memwei... |
795 |
count = memweight(la->la_bitmap, le16_to_cpu(la->la_size)); |
ccd979bdb [PATCH] OCFS2: Th... |
796 |
|
a04733d8a ocfs2: Remove mlo... |
797 |
trace_ocfs2_local_alloc_count_bits(count); |
ccd979bdb [PATCH] OCFS2: Th... |
798 799 800 801 |
return count; } static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb, |
d02f00cc0 ocfs2: allocation... |
802 803 804 |
struct ocfs2_dinode *alloc, u32 *numbits, struct ocfs2_alloc_reservation *resv) |
ccd979bdb [PATCH] OCFS2: Th... |
805 |
{ |
023d4ea35 ocfs2: fix possib... |
806 |
int numfound = 0, bitoff, left, startoff, lastzero; |
d02f00cc0 ocfs2: allocation... |
807 808 |
int local_resv = 0; struct ocfs2_alloc_reservation r; |
ccd979bdb [PATCH] OCFS2: Th... |
809 |
void *bitmap = NULL; |
d02f00cc0 ocfs2: allocation... |
810 |
struct ocfs2_reservation_map *resmap = &osb->osb_la_resmap; |
ccd979bdb [PATCH] OCFS2: Th... |
811 |
|
ccd979bdb [PATCH] OCFS2: Th... |
812 |
if (!alloc->id1.bitmap1.i_total) { |
ccd979bdb [PATCH] OCFS2: Th... |
813 814 815 |
bitoff = -1; goto bail; } |
d02f00cc0 ocfs2: allocation... |
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 |
if (!resv) { local_resv = 1; ocfs2_resv_init_once(&r); ocfs2_resv_set_type(&r, OCFS2_RESV_FLAG_TMP); resv = &r; } numfound = *numbits; if (ocfs2_resmap_resv_bits(resmap, resv, &bitoff, &numfound) == 0) { if (numfound < *numbits) *numbits = numfound; goto bail; } /* * Code error. While reservations are enabled, local * allocation should _always_ go through them. */ BUG_ON(osb->osb_resv_level != 0); /* * Reservations are disabled. Handle this the old way. */ |
ccd979bdb [PATCH] OCFS2: Th... |
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 |
bitmap = OCFS2_LOCAL_ALLOC(alloc)->la_bitmap; numfound = bitoff = startoff = 0; lastzero = -1; left = le32_to_cpu(alloc->id1.bitmap1.i_total); while ((bitoff = ocfs2_find_next_zero_bit(bitmap, left, startoff)) != -1) { if (bitoff == left) { /* mlog(0, "bitoff (%d) == left", bitoff); */ break; } /* mlog(0, "Found a zero: bitoff = %d, startoff = %d, " "numfound = %d ", bitoff, startoff, numfound);*/ /* Ok, we found a zero bit... is it contig. or do we * start over?*/ if (bitoff == startoff) { /* we found a zero */ numfound++; startoff++; } else { /* got a zero after some ones */ numfound = 1; startoff = bitoff+1; } /* we got everything we needed */ |
d02f00cc0 ocfs2: allocation... |
865 |
if (numfound == *numbits) { |
ccd979bdb [PATCH] OCFS2: Th... |
866 867 868 869 870 |
/* mlog(0, "Found it all! "); */ break; } } |
a04733d8a ocfs2: Remove mlo... |
871 |
trace_ocfs2_local_alloc_find_clear_bits_search_bitmap(bitoff, numfound); |
ccd979bdb [PATCH] OCFS2: Th... |
872 |
|
3e4218df3 ocfs2/trivial: Co... |
873 |
if (numfound == *numbits) |
ccd979bdb [PATCH] OCFS2: Th... |
874 |
bitoff = startoff - numfound; |
3e4218df3 ocfs2/trivial: Co... |
875 |
else |
ccd979bdb [PATCH] OCFS2: Th... |
876 877 878 |
bitoff = -1; bail: |
d02f00cc0 ocfs2: allocation... |
879 880 |
if (local_resv) ocfs2_resv_discard(resmap, resv); |
a04733d8a ocfs2: Remove mlo... |
881 882 883 |
trace_ocfs2_local_alloc_find_clear_bits(*numbits, le32_to_cpu(alloc->id1.bitmap1.i_total), bitoff, numfound); |
ccd979bdb [PATCH] OCFS2: Th... |
884 885 886 887 888 889 890 |
return bitoff; } static void ocfs2_clear_local_alloc(struct ocfs2_dinode *alloc) { struct ocfs2_local_alloc *la = OCFS2_LOCAL_ALLOC(alloc); int i; |
ccd979bdb [PATCH] OCFS2: Th... |
891 892 893 894 895 896 |
alloc->id1.bitmap1.i_total = 0; alloc->id1.bitmap1.i_used = 0; la->la_bm_off = 0; for(i = 0; i < le16_to_cpu(la->la_size); i++) la->la_bitmap[i] = 0; |
ccd979bdb [PATCH] OCFS2: Th... |
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 |
} #if 0 /* turn this on and uncomment below to aid debugging window shifts. */ static void ocfs2_verify_zero_bits(unsigned long *bitmap, unsigned int start, unsigned int count) { unsigned int tmp = count; while(tmp--) { if (ocfs2_test_bit(start + tmp, bitmap)) { printk("ocfs2_verify_zero_bits: start = %u, count = " "%u ", start, count); printk("ocfs2_verify_zero_bits: bit %u is set!", start + tmp); BUG(); } } } #endif /* * sync the local alloc to main bitmap. * * assumes you've already locked the main bitmap -- the bitmap inode * passed is used for caching. */ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb, |
1fabe1481 ocfs2: Remove str... |
926 |
handle_t *handle, |
ccd979bdb [PATCH] OCFS2: Th... |
927 928 929 930 931 932 933 934 935 936 |
struct ocfs2_dinode *alloc, struct inode *main_bm_inode, struct buffer_head *main_bm_bh) { int status = 0; int bit_off, left, count, start; u64 la_start_blk; u64 blkno; void *bitmap; struct ocfs2_local_alloc *la = OCFS2_LOCAL_ALLOC(alloc); |
a04733d8a ocfs2: Remove mlo... |
937 |
trace_ocfs2_sync_local_to_main( |
ef6b689b6 ocfs2: Remove ENT... |
938 939 |
le32_to_cpu(alloc->id1.bitmap1.i_total), le32_to_cpu(alloc->id1.bitmap1.i_used)); |
ccd979bdb [PATCH] OCFS2: Th... |
940 941 |
if (!alloc->id1.bitmap1.i_total) { |
ccd979bdb [PATCH] OCFS2: Th... |
942 943 944 945 946 |
goto bail; } if (le32_to_cpu(alloc->id1.bitmap1.i_used) == le32_to_cpu(alloc->id1.bitmap1.i_total)) { |
ccd979bdb [PATCH] OCFS2: Th... |
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 |
goto bail; } la_start_blk = ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(la->la_bm_off)); bitmap = la->la_bitmap; start = count = bit_off = 0; left = le32_to_cpu(alloc->id1.bitmap1.i_total); while ((bit_off = ocfs2_find_next_zero_bit(bitmap, left, start)) != -1) { if ((bit_off < left) && (bit_off == start)) { count++; start++; continue; } if (count) { blkno = la_start_blk + ocfs2_clusters_to_blocks(osb->sb, start - count); |
a04733d8a ocfs2: Remove mlo... |
967 |
trace_ocfs2_sync_local_to_main_free( |
b0697053f ocfs2: don't use ... |
968 969 970 |
count, start - count, (unsigned long long)la_start_blk, (unsigned long long)blkno); |
ccd979bdb [PATCH] OCFS2: Th... |
971 |
|
b4414eea0 ocfs2: Clear undo... |
972 973 974 975 |
status = ocfs2_release_clusters(handle, main_bm_inode, main_bm_bh, blkno, count); |
ccd979bdb [PATCH] OCFS2: Th... |
976 977 978 979 980 981 982 983 984 985 986 987 |
if (status < 0) { mlog_errno(status); goto bail; } } if (bit_off >= left) break; count = 1; start = bit_off + 1; } bail: |
c1e8d35ef ocfs2: Remove EXI... |
988 989 |
if (status) mlog_errno(status); |
ccd979bdb [PATCH] OCFS2: Th... |
990 991 |
return status; } |
9c7af40b2 ocfs2: throttle b... |
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 |
enum ocfs2_la_event { OCFS2_LA_EVENT_SLIDE, /* Normal window slide. */ OCFS2_LA_EVENT_FRAGMENTED, /* The global bitmap has * enough bits theoretically * free, but a contiguous * allocation could not be * found. */ OCFS2_LA_EVENT_ENOSPC, /* Global bitmap doesn't have * enough bits free to satisfy * our request. */ }; #define OCFS2_LA_ENABLE_INTERVAL (30 * HZ) /* * Given an event, calculate the size of our next local alloc window. * * This should always be called under i_mutex of the local alloc inode * so that local alloc disabling doesn't race with processes trying to * use the allocator. * * Returns the state which the local alloc was left in. This value can * be ignored by some paths. */ static int ocfs2_recalc_la_window(struct ocfs2_super *osb, enum ocfs2_la_event event) { unsigned int bits; int state; spin_lock(&osb->osb_lock); if (osb->local_alloc_state == OCFS2_LA_DISABLED) { WARN_ON_ONCE(osb->local_alloc_state == OCFS2_LA_DISABLED); goto out_unlock; } /* * ENOSPC and fragmentation are treated similarly for now. */ if (event == OCFS2_LA_EVENT_ENOSPC || event == OCFS2_LA_EVENT_FRAGMENTED) { /* * We ran out of contiguous space in the primary * bitmap. Drastically reduce the number of bits used * by local alloc until we have to disable it. */ bits = osb->local_alloc_bits >> 1; if (bits > ocfs2_megabytes_to_clusters(osb->sb, 1)) { /* * By setting state to THROTTLED, we'll keep * the number of local alloc bits used down * until an event occurs which would give us * reason to assume the bitmap situation might * have changed. */ osb->local_alloc_state = OCFS2_LA_THROTTLED; osb->local_alloc_bits = bits; } else { osb->local_alloc_state = OCFS2_LA_DISABLED; } |
35ddf78e4 ocfs2: fix occurr... |
1050 |
queue_delayed_work(osb->ocfs2_wq, &osb->la_enable_wq, |
9c7af40b2 ocfs2: throttle b... |
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 |
OCFS2_LA_ENABLE_INTERVAL); goto out_unlock; } /* * Don't increase the size of the local alloc window until we * know we might be able to fulfill the request. Otherwise, we * risk bouncing around the global bitmap during periods of * low space. */ if (osb->local_alloc_state != OCFS2_LA_THROTTLED) osb->local_alloc_bits = osb->local_alloc_default_bits; out_unlock: state = osb->local_alloc_state; spin_unlock(&osb->osb_lock); return state; } |
ccd979bdb [PATCH] OCFS2: Th... |
1070 |
static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb, |
ccd979bdb [PATCH] OCFS2: Th... |
1071 1072 1073 1074 1075 |
struct ocfs2_alloc_context **ac, struct inode **bitmap_inode, struct buffer_head **bitmap_bh) { int status; |
cd8612808 [PATCH] Fix numer... |
1076 |
*ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL); |
ccd979bdb [PATCH] OCFS2: Th... |
1077 1078 1079 1080 1081 |
if (!(*ac)) { status = -ENOMEM; mlog_errno(status); goto bail; } |
9c7af40b2 ocfs2: throttle b... |
1082 |
retry_enospc: |
7e9b79370 ocfs2: ac_bits_wa... |
1083 |
(*ac)->ac_bits_wanted = osb->local_alloc_bits; |
ccd979bdb [PATCH] OCFS2: Th... |
1084 |
status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac); |
9c7af40b2 ocfs2: throttle b... |
1085 1086 1087 1088 1089 1090 1091 1092 1093 |
if (status == -ENOSPC) { if (ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_ENOSPC) == OCFS2_LA_DISABLED) goto bail; ocfs2_free_ac_resource(*ac); memset(*ac, 0, sizeof(struct ocfs2_alloc_context)); goto retry_enospc; } |
ccd979bdb [PATCH] OCFS2: Th... |
1094 |
if (status < 0) { |
9c7af40b2 ocfs2: throttle b... |
1095 |
mlog_errno(status); |
ccd979bdb [PATCH] OCFS2: Th... |
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 |
goto bail; } *bitmap_inode = (*ac)->ac_inode; igrab(*bitmap_inode); *bitmap_bh = (*ac)->ac_bh; get_bh(*bitmap_bh); status = 0; bail: if ((status < 0) && *ac) { ocfs2_free_alloc_context(*ac); *ac = NULL; } |
c1e8d35ef ocfs2: Remove EXI... |
1109 1110 |
if (status) mlog_errno(status); |
ccd979bdb [PATCH] OCFS2: Th... |
1111 1112 1113 1114 1115 1116 1117 |
return status; } /* * pass it the bitmap lock in lock_bh if you have it. */ static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb, |
1fabe1481 ocfs2: Remove str... |
1118 |
handle_t *handle, |
ccd979bdb [PATCH] OCFS2: Th... |
1119 1120 1121 1122 1123 1124 |
struct ocfs2_alloc_context *ac) { int status = 0; u32 cluster_off, cluster_count; struct ocfs2_dinode *alloc = NULL; struct ocfs2_local_alloc *la; |
ccd979bdb [PATCH] OCFS2: Th... |
1125 1126 |
alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; la = OCFS2_LOCAL_ALLOC(alloc); |
a04733d8a ocfs2: Remove mlo... |
1127 1128 1129 |
trace_ocfs2_local_alloc_new_window( le32_to_cpu(alloc->id1.bitmap1.i_total), osb->local_alloc_bits); |
883d4cae4 ocfs2: allocation... |
1130 1131 1132 1133 1134 |
/* Instruct the allocation code to try the most recently used * cluster group. We'll re-record the group used this pass * below. */ ac->ac_last_group = osb->la_last_gd; |
ccd979bdb [PATCH] OCFS2: Th... |
1135 1136 1137 |
/* we used the generic suballoc reserve function, but we set * everything up nicely, so there's no reason why we can't use * the more specific cluster api to claim bits. */ |
1ed9b777f ocfs2: ocfs2_clai... |
1138 |
status = ocfs2_claim_clusters(handle, ac, osb->local_alloc_bits, |
ccd979bdb [PATCH] OCFS2: Th... |
1139 |
&cluster_off, &cluster_count); |
9c7af40b2 ocfs2: throttle b... |
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 |
if (status == -ENOSPC) { retry_enospc: /* * Note: We could also try syncing the journal here to * allow use of any free bits which the current * transaction can't give us access to. --Mark */ if (ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_FRAGMENTED) == OCFS2_LA_DISABLED) goto bail; |
7e9b79370 ocfs2: ac_bits_wa... |
1150 |
ac->ac_bits_wanted = osb->local_alloc_bits; |
1ed9b777f ocfs2: ocfs2_clai... |
1151 |
status = ocfs2_claim_clusters(handle, ac, |
9c7af40b2 ocfs2: throttle b... |
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 |
osb->local_alloc_bits, &cluster_off, &cluster_count); if (status == -ENOSPC) goto retry_enospc; /* * We only shrunk the *minimum* number of in our * request - it's entirely possible that the allocator * might give us more than we asked for. */ if (status == 0) { spin_lock(&osb->osb_lock); osb->local_alloc_bits = cluster_count; spin_unlock(&osb->osb_lock); } } |
ccd979bdb [PATCH] OCFS2: Th... |
1168 1169 1170 1171 1172 |
if (status < 0) { if (status != -ENOSPC) mlog_errno(status); goto bail; } |
883d4cae4 ocfs2: allocation... |
1173 |
osb->la_last_gd = ac->ac_last_group; |
ccd979bdb [PATCH] OCFS2: Th... |
1174 1175 1176 1177 1178 1179 1180 1181 1182 |
la->la_bm_off = cpu_to_le32(cluster_off); alloc->id1.bitmap1.i_total = cpu_to_le32(cluster_count); /* just in case... In the future when we find space ourselves, * we don't have to get all contiguous -- but we'll have to * set all previously used bits in bitmap and update * la_bits_set before setting the bits in the main bitmap. */ alloc->id1.bitmap1.i_used = 0; memset(OCFS2_LOCAL_ALLOC(alloc)->la_bitmap, 0, le16_to_cpu(la->la_size)); |
d02f00cc0 ocfs2: allocation... |
1183 1184 |
ocfs2_resmap_restart(&osb->osb_la_resmap, cluster_count, OCFS2_LOCAL_ALLOC(alloc)->la_bitmap); |
a04733d8a ocfs2: Remove mlo... |
1185 1186 1187 |
trace_ocfs2_local_alloc_new_window_result( OCFS2_LOCAL_ALLOC(alloc)->la_bm_off, le32_to_cpu(alloc->id1.bitmap1.i_total)); |
ccd979bdb [PATCH] OCFS2: Th... |
1188 1189 |
bail: |
c1e8d35ef ocfs2: Remove EXI... |
1190 1191 |
if (status) mlog_errno(status); |
ccd979bdb [PATCH] OCFS2: Th... |
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 |
return status; } /* Note that we do *NOT* lock the local alloc inode here as * it's been locked already for us. */ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb, struct inode *local_alloc_inode) { int status = 0; struct buffer_head *main_bm_bh = NULL; struct inode *main_bm_inode = NULL; |
1fabe1481 ocfs2: Remove str... |
1203 |
handle_t *handle = NULL; |
ccd979bdb [PATCH] OCFS2: Th... |
1204 1205 1206 |
struct ocfs2_dinode *alloc; struct ocfs2_dinode *alloc_copy = NULL; struct ocfs2_alloc_context *ac = NULL; |
9c7af40b2 ocfs2: throttle b... |
1207 |
ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_SLIDE); |
ccd979bdb [PATCH] OCFS2: Th... |
1208 1209 |
/* This will lock the main bitmap for us. */ status = ocfs2_local_alloc_reserve_for_window(osb, |
ccd979bdb [PATCH] OCFS2: Th... |
1210 1211 1212 1213 1214 1215 1216 1217 |
&ac, &main_bm_inode, &main_bm_bh); if (status < 0) { if (status != -ENOSPC) mlog_errno(status); goto bail; } |
65eff9ccf ocfs2: remove han... |
1218 |
handle = ocfs2_start_trans(osb, OCFS2_WINDOW_MOVE_CREDITS); |
ccd979bdb [PATCH] OCFS2: Th... |
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 |
if (IS_ERR(handle)) { status = PTR_ERR(handle); handle = NULL; mlog_errno(status); goto bail; } alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data; /* We want to clear the local alloc before doing anything * else, so that if we error later during this operation, * local alloc shutdown won't try to double free main bitmap * bits. Make a copy so the sync function knows which bits to * free. */ |
4ba1c5bfd ocfs2: Use GFP_NO... |
1233 |
alloc_copy = kmalloc(osb->local_alloc_bh->b_size, GFP_NOFS); |
ccd979bdb [PATCH] OCFS2: Th... |
1234 1235 1236 1237 1238 1239 |
if (!alloc_copy) { status = -ENOMEM; mlog_errno(status); goto bail; } memcpy(alloc_copy, alloc, osb->local_alloc_bh->b_size); |
0cf2f7632 ocfs2: Pass struc... |
1240 1241 |
status = ocfs2_journal_access_di(handle, INODE_CACHE(local_alloc_inode), |
13723d00e ocfs2: Use metada... |
1242 1243 |
osb->local_alloc_bh, OCFS2_JOURNAL_ACCESS_WRITE); |
ccd979bdb [PATCH] OCFS2: Th... |
1244 1245 1246 1247 1248 1249 |
if (status < 0) { mlog_errno(status); goto bail; } ocfs2_clear_local_alloc(alloc); |
ec20cec7a ocfs2: Make ocfs2... |
1250 |
ocfs2_journal_dirty(handle, osb->local_alloc_bh); |
ccd979bdb [PATCH] OCFS2: Th... |
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 |
status = ocfs2_sync_local_to_main(osb, handle, alloc_copy, main_bm_inode, main_bm_bh); if (status < 0) { mlog_errno(status); goto bail; } status = ocfs2_local_alloc_new_window(osb, handle, ac); if (status < 0) { if (status != -ENOSPC) mlog_errno(status); goto bail; } atomic_inc(&osb->alloc_stats.moves); |
ccd979bdb [PATCH] OCFS2: Th... |
1267 1268 |
bail: if (handle) |
02dc1af44 ocfs2: pass ocfs2... |
1269 |
ocfs2_commit_trans(osb, handle); |
ccd979bdb [PATCH] OCFS2: Th... |
1270 |
|
a81cb88b6 ocfs2: Don't chec... |
1271 |
brelse(main_bm_bh); |
ccd979bdb [PATCH] OCFS2: Th... |
1272 |
|
72865d923 ocfs2: clean up r... |
1273 |
iput(main_bm_inode); |
d787ab097 ocfs2: remove kfr... |
1274 |
kfree(alloc_copy); |
ccd979bdb [PATCH] OCFS2: Th... |
1275 1276 1277 |
if (ac) ocfs2_free_alloc_context(ac); |
c1e8d35ef ocfs2: Remove EXI... |
1278 1279 |
if (status) mlog_errno(status); |
ccd979bdb [PATCH] OCFS2: Th... |
1280 1281 |
return status; } |