2462
2459
start = ocfs2_find_subtree_root(et, left_path, right_path);
2464
mlog(0, "Subtree root at index %d (blk %llu, depth %d)\n",
2466
(unsigned long long) right_path->p_node[start].bh->b_blocknr,
2467
right_path->p_tree_depth);
2461
trace_ocfs2_rotate_subtree(start,
2462
(unsigned long long)
2463
right_path->p_node[start].bh->b_blocknr,
2464
right_path->p_tree_depth);
2469
2466
ret = ocfs2_extend_rotate_transaction(handle, start,
2470
2467
orig_credits, right_path);
4703
mlog(0, "Insert.appending: %u, Insert.Contig: %u, "
4704
"Insert.contig_index: %d, Insert.free_records: %d, "
4705
"Insert.tree_depth: %d\n",
4706
insert.ins_appending, insert.ins_contig, insert.ins_contig_index,
4707
free_records, insert.ins_tree_depth);
4701
trace_ocfs2_insert_extent(insert.ins_appending, insert.ins_contig,
4702
insert.ins_contig_index, free_records,
4703
insert.ins_tree_depth);
4709
4705
if (insert.ins_contig == CONTIG_NONE && free_records == 0) {
4710
4706
status = ocfs2_grow_tree(handle, et,
5513
5508
BUG_ON(cpos < le32_to_cpu(rec->e_cpos) || trunc_range > rec_range);
5515
mlog(0, "Owner %llu, remove (cpos %u, len %u). Existing index %d "
5516
"(cpos %u, len %u)\n",
5517
(unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
5519
le32_to_cpu(rec->e_cpos), ocfs2_rec_clusters(el, rec));
5510
trace_ocfs2_remove_extent(
5511
(unsigned long long)ocfs2_metadata_cache_owner(et->et_ci),
5512
cpos, len, index, le32_to_cpu(rec->e_cpos),
5513
ocfs2_rec_clusters(el, rec));
5521
5515
if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) {
5522
5516
ret = ocfs2_truncate_rec(handle, et, path, index, dealloc,
5915
5903
/* if start_blk is not set, we ignore the record as
5917
5905
if (start_blk) {
5918
mlog(0, "free record %d, start = %u, clusters = %u\n",
5919
i, le32_to_cpu(rec.t_start), num_clusters);
5906
trace_ocfs2_replay_truncate_records(
5907
(unsigned long long)OCFS2_I(tl_inode)->ip_blkno,
5908
i, le32_to_cpu(rec.t_start), num_clusters);
5921
5910
status = ocfs2_free_clusters(handle, data_alloc_inode,
5922
5911
data_alloc_bh, start_blk,
7189
static int ocfs2_trim_extent(struct super_block *sb,
7190
struct ocfs2_group_desc *gd,
7191
u32 start, u32 count)
7193
u64 discard, bcount;
7195
bcount = ocfs2_clusters_to_blocks(sb, count);
7196
discard = le64_to_cpu(gd->bg_blkno) +
7197
ocfs2_clusters_to_blocks(sb, start);
7199
trace_ocfs2_trim_extent(sb, (unsigned long long)discard, bcount);
7201
return sb_issue_discard(sb, discard, bcount, GFP_NOFS, 0);
7204
static int ocfs2_trim_group(struct super_block *sb,
7205
struct ocfs2_group_desc *gd,
7206
u32 start, u32 max, u32 minbits)
7208
int ret = 0, count = 0, next;
7209
void *bitmap = gd->bg_bitmap;
7211
if (le16_to_cpu(gd->bg_free_bits_count) < minbits)
7214
trace_ocfs2_trim_group((unsigned long long)le64_to_cpu(gd->bg_blkno),
7215
start, max, minbits);
7217
while (start < max) {
7218
start = ocfs2_find_next_zero_bit(bitmap, max, start);
7221
next = ocfs2_find_next_bit(bitmap, max, start);
7223
if ((next - start) >= minbits) {
7224
ret = ocfs2_trim_extent(sb, gd,
7225
start, next - start);
7230
count += next - start;
7234
if (fatal_signal_pending(current)) {
7235
count = -ERESTARTSYS;
7239
if ((le16_to_cpu(gd->bg_free_bits_count) - count) < minbits)
7249
int ocfs2_trim_fs(struct super_block *sb, struct fstrim_range *range)
7251
struct ocfs2_super *osb = OCFS2_SB(sb);
7252
u64 start, len, trimmed, first_group, last_group, group;
7254
u32 first_bit, last_bit, minlen;
7255
struct buffer_head *main_bm_bh = NULL;
7256
struct inode *main_bm_inode = NULL;
7257
struct buffer_head *gd_bh = NULL;
7258
struct ocfs2_dinode *main_bm;
7259
struct ocfs2_group_desc *gd = NULL;
7261
start = range->start >> osb->s_clustersize_bits;
7262
len = range->len >> osb->s_clustersize_bits;
7263
minlen = range->minlen >> osb->s_clustersize_bits;
7271
if (minlen >= osb->bitmap_cpg)
7274
main_bm_inode = ocfs2_get_system_file_inode(osb,
7275
GLOBAL_BITMAP_SYSTEM_INODE,
7276
OCFS2_INVALID_SLOT);
7277
if (!main_bm_inode) {
7283
mutex_lock(&main_bm_inode->i_mutex);
7285
ret = ocfs2_inode_lock(main_bm_inode, &main_bm_bh, 0);
7290
main_bm = (struct ocfs2_dinode *)main_bm_bh->b_data;
7292
if (start >= le32_to_cpu(main_bm->i_clusters)) {
7297
if (start + len > le32_to_cpu(main_bm->i_clusters))
7298
len = le32_to_cpu(main_bm->i_clusters) - start;
7300
trace_ocfs2_trim_fs(start, len, minlen);
7302
/* Determine first and last group to examine based on start and len */
7303
first_group = ocfs2_which_cluster_group(main_bm_inode, start);
7304
if (first_group == osb->first_cluster_group_blkno)
7307
first_bit = start - ocfs2_blocks_to_clusters(sb, first_group);
7308
last_group = ocfs2_which_cluster_group(main_bm_inode, start + len - 1);
7309
last_bit = osb->bitmap_cpg;
7311
for (group = first_group; group <= last_group;) {
7312
if (first_bit + len >= osb->bitmap_cpg)
7313
last_bit = osb->bitmap_cpg;
7315
last_bit = first_bit + len;
7317
ret = ocfs2_read_group_descriptor(main_bm_inode,
7325
gd = (struct ocfs2_group_desc *)gd_bh->b_data;
7326
cnt = ocfs2_trim_group(sb, gd, first_bit, last_bit, minlen);
7336
len -= osb->bitmap_cpg - first_bit;
7338
if (group == osb->first_cluster_group_blkno)
7339
group = ocfs2_clusters_to_blocks(sb, osb->bitmap_cpg);
7341
group += ocfs2_clusters_to_blocks(sb, osb->bitmap_cpg);
7343
range->len = trimmed * sb->s_blocksize;
7345
ocfs2_inode_unlock(main_bm_inode, 0);
7348
mutex_unlock(&main_bm_inode->i_mutex);
7349
iput(main_bm_inode);