316
o2info_set_request_error(oij, req);
317
o2info_set_request_error(&oij.ij_req, req);
322
int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb,
323
struct inode *inode_alloc, u64 blkno,
324
struct ocfs2_info_freeinode *fi, u32 slot)
326
int status = 0, unlock = 0;
328
struct buffer_head *bh = NULL;
329
struct ocfs2_dinode *dinode_alloc = NULL;
332
mutex_lock(&inode_alloc->i_mutex);
334
if (o2info_coherent(&fi->ifi_req)) {
335
status = ocfs2_inode_lock(inode_alloc, &bh, 0);
342
status = ocfs2_read_blocks_sync(osb, blkno, 1, &bh);
349
dinode_alloc = (struct ocfs2_dinode *)bh->b_data;
351
fi->ifi_stat[slot].lfi_total =
352
le32_to_cpu(dinode_alloc->id1.bitmap1.i_total);
353
fi->ifi_stat[slot].lfi_free =
354
le32_to_cpu(dinode_alloc->id1.bitmap1.i_total) -
355
le32_to_cpu(dinode_alloc->id1.bitmap1.i_used);
359
ocfs2_inode_unlock(inode_alloc, 0);
362
mutex_unlock(&inode_alloc->i_mutex);
369
int ocfs2_info_handle_freeinode(struct inode *inode,
370
struct ocfs2_info_request __user *req)
375
int status = -EFAULT, type = INODE_ALLOC_SYSTEM_INODE;
376
struct ocfs2_info_freeinode *oifi = NULL;
377
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
378
struct inode *inode_alloc = NULL;
380
oifi = kzalloc(sizeof(struct ocfs2_info_freeinode), GFP_KERNEL);
387
if (o2info_from_user(*oifi, req))
390
oifi->ifi_slotnum = osb->max_slots;
392
for (i = 0; i < oifi->ifi_slotnum; i++) {
393
if (o2info_coherent(&oifi->ifi_req)) {
394
inode_alloc = ocfs2_get_system_file_inode(osb, type, i);
396
mlog(ML_ERROR, "unable to get alloc inode in "
402
ocfs2_sprintf_system_inode_name(namebuf,
405
status = ocfs2_lookup_ino_from_name(osb->sys_root_inode,
415
status = ocfs2_info_scan_inode_alloc(osb, inode_alloc, blkno, oifi, i);
423
o2info_set_request_filled(&oifi->ifi_req);
425
if (o2info_to_user(*oifi, req))
431
o2info_set_request_error(&oifi->ifi_req, req);
438
static void o2ffg_update_histogram(struct ocfs2_info_free_chunk_list *hist,
439
unsigned int chunksize)
443
index = __ilog2_u32(chunksize);
444
if (index >= OCFS2_INFO_MAX_HIST)
445
index = OCFS2_INFO_MAX_HIST - 1;
447
hist->fc_chunks[index]++;
448
hist->fc_clusters[index] += chunksize;
451
static void o2ffg_update_stats(struct ocfs2_info_freefrag_stats *stats,
452
unsigned int chunksize)
454
if (chunksize > stats->ffs_max)
455
stats->ffs_max = chunksize;
457
if (chunksize < stats->ffs_min)
458
stats->ffs_min = chunksize;
460
stats->ffs_avg += chunksize;
461
stats->ffs_free_chunks_real++;
464
void ocfs2_info_update_ffg(struct ocfs2_info_freefrag *ffg,
465
unsigned int chunksize)
467
o2ffg_update_histogram(&(ffg->iff_ffs.ffs_fc_hist), chunksize);
468
o2ffg_update_stats(&(ffg->iff_ffs), chunksize);
471
int ocfs2_info_freefrag_scan_chain(struct ocfs2_super *osb,
472
struct inode *gb_inode,
473
struct ocfs2_dinode *gb_dinode,
474
struct ocfs2_chain_rec *rec,
475
struct ocfs2_info_freefrag *ffg,
478
int status = 0, used;
481
struct buffer_head *bh = NULL;
482
struct ocfs2_group_desc *bg = NULL;
484
unsigned int max_bits, num_clusters;
485
unsigned int offset = 0, cluster, chunk;
486
unsigned int chunk_free, last_chunksize = 0;
488
if (!le32_to_cpu(rec->c_free))
493
blkno = le64_to_cpu(rec->c_blkno);
495
blkno = le64_to_cpu(bg->bg_next_group);
502
if (o2info_coherent(&ffg->iff_req))
503
status = ocfs2_read_group_descriptor(gb_inode,
507
status = ocfs2_read_blocks_sync(osb, blkno, 1, &bh);
510
mlog(ML_ERROR, "Can't read the group descriptor # "
511
"%llu from device.", (unsigned long long)blkno);
516
bg = (struct ocfs2_group_desc *)bh->b_data;
518
if (!le16_to_cpu(bg->bg_free_bits_count))
521
max_bits = le16_to_cpu(bg->bg_bits);
524
for (chunk = 0; chunk < chunks_in_group; chunk++) {
526
* last chunk may be not an entire one.
528
if ((offset + ffg->iff_chunksize) > max_bits)
529
num_clusters = max_bits - offset;
531
num_clusters = ffg->iff_chunksize;
534
for (cluster = 0; cluster < num_clusters; cluster++) {
535
used = ocfs2_test_bit(offset,
536
(unsigned long *)bg->bg_bitmap);
538
* - chunk_free counts free clusters in #N chunk.
539
* - last_chunksize records the size(in) clusters
540
* for the last real free chunk being counted.
547
if (used && last_chunksize) {
548
ocfs2_info_update_ffg(ffg,
556
if (chunk_free == ffg->iff_chunksize)
557
ffg->iff_ffs.ffs_free_chunks++;
561
* need to update the info for last free chunk.
564
ocfs2_info_update_ffg(ffg, last_chunksize);
566
} while (le64_to_cpu(bg->bg_next_group));
574
int ocfs2_info_freefrag_scan_bitmap(struct ocfs2_super *osb,
575
struct inode *gb_inode, u64 blkno,
576
struct ocfs2_info_freefrag *ffg)
579
int status = 0, unlock = 0, i;
581
struct buffer_head *bh = NULL;
582
struct ocfs2_chain_list *cl = NULL;
583
struct ocfs2_chain_rec *rec = NULL;
584
struct ocfs2_dinode *gb_dinode = NULL;
587
mutex_lock(&gb_inode->i_mutex);
589
if (o2info_coherent(&ffg->iff_req)) {
590
status = ocfs2_inode_lock(gb_inode, &bh, 0);
597
status = ocfs2_read_blocks_sync(osb, blkno, 1, &bh);
604
gb_dinode = (struct ocfs2_dinode *)bh->b_data;
605
cl = &(gb_dinode->id2.i_chain);
608
* Chunksize(in) clusters from userspace should be
609
* less than clusters in a group.
611
if (ffg->iff_chunksize > le16_to_cpu(cl->cl_cpg)) {
616
memset(&ffg->iff_ffs, 0, sizeof(struct ocfs2_info_freefrag_stats));
618
ffg->iff_ffs.ffs_min = ~0U;
619
ffg->iff_ffs.ffs_clusters =
620
le32_to_cpu(gb_dinode->id1.bitmap1.i_total);
621
ffg->iff_ffs.ffs_free_clusters = ffg->iff_ffs.ffs_clusters -
622
le32_to_cpu(gb_dinode->id1.bitmap1.i_used);
624
chunks_in_group = le16_to_cpu(cl->cl_cpg) / ffg->iff_chunksize + 1;
626
for (i = 0; i < le16_to_cpu(cl->cl_next_free_rec); i++) {
627
rec = &(cl->cl_recs[i]);
628
status = ocfs2_info_freefrag_scan_chain(osb, gb_inode,
636
if (ffg->iff_ffs.ffs_free_chunks_real)
637
ffg->iff_ffs.ffs_avg = (ffg->iff_ffs.ffs_avg /
638
ffg->iff_ffs.ffs_free_chunks_real);
641
ocfs2_inode_unlock(gb_inode, 0);
644
mutex_unlock(&gb_inode->i_mutex);
654
int ocfs2_info_handle_freefrag(struct inode *inode,
655
struct ocfs2_info_request __user *req)
659
int status = -EFAULT, type = GLOBAL_BITMAP_SYSTEM_INODE;
661
struct ocfs2_info_freefrag *oiff;
662
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
663
struct inode *gb_inode = NULL;
665
oiff = kzalloc(sizeof(struct ocfs2_info_freefrag), GFP_KERNEL);
672
if (o2info_from_user(*oiff, req))
675
* chunksize from userspace should be power of 2.
677
if ((oiff->iff_chunksize & (oiff->iff_chunksize - 1)) ||
678
(!oiff->iff_chunksize)) {
683
if (o2info_coherent(&oiff->iff_req)) {
684
gb_inode = ocfs2_get_system_file_inode(osb, type,
687
mlog(ML_ERROR, "unable to get global_bitmap inode\n");
692
ocfs2_sprintf_system_inode_name(namebuf, sizeof(namebuf), type,
694
status = ocfs2_lookup_ino_from_name(osb->sys_root_inode,
704
status = ocfs2_info_freefrag_scan_bitmap(osb, gb_inode, blkno, oiff);
708
o2info_set_request_filled(&oiff->iff_req);
710
if (o2info_to_user(*oiff, req))
716
o2info_set_request_error(&oiff->iff_req, req);