Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

GFS2: Eliminate sd_rindex_mutex

Over time, we've slowly eliminated the use of sd_rindex_mutex.
Up to this point, it was only used in two places: function
gfs2_ri_total (which totals the file system size by reading
and parsing the rindex file) and function gfs2_rindex_update
which updates the rgrps in memory. Both of these functions have
the rindex glock to protect them, so the rindex is unnecessary.
Since gfs2_grow writes to the rindex via the meta_fs, the mutex
is in the wrong order according to the normal rules. This patch
eliminates the mutex entirely to avoid the problem.

Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>

authored by

Bob Peterson and committed by
Steven Whitehouse
6aad1c3d a08fd280

+10 -14
-1
fs/gfs2/incore.h
··· 644 644 645 645 int sd_rindex_uptodate; 646 646 spinlock_t sd_rindex_spin; 647 - struct mutex sd_rindex_mutex; 648 647 struct rb_root sd_rindex_tree; 649 648 unsigned int sd_rgrps; 650 649 unsigned int sd_max_rg_data;
-1
fs/gfs2/ops_fstype.c
··· 83 83 spin_lock_init(&sdp->sd_statfs_spin); 84 84 85 85 spin_lock_init(&sdp->sd_rindex_spin); 86 - mutex_init(&sdp->sd_rindex_mutex); 87 86 sdp->sd_rindex_tree.rb_node = NULL; 88 87 89 88 INIT_LIST_HEAD(&sdp->sd_jindex_list);
+10 -12
fs/gfs2/rgrp.c
··· 540 540 struct file_ra_state ra_state; 541 541 int error, rgrps; 542 542 543 - mutex_lock(&sdp->sd_rindex_mutex); 544 543 file_ra_state_init(&ra_state, inode->i_mapping); 545 544 for (rgrps = 0;; rgrps++) { 546 545 loff_t pos = rgrps * sizeof(struct gfs2_rindex); ··· 552 553 break; 553 554 total_data += be32_to_cpu(((struct gfs2_rindex *)buf)->ri_data); 554 555 } 555 - mutex_unlock(&sdp->sd_rindex_mutex); 556 556 return total_data; 557 557 } 558 558 559 - static void rgd_insert(struct gfs2_rgrpd *rgd) 559 + static int rgd_insert(struct gfs2_rgrpd *rgd) 560 560 { 561 561 struct gfs2_sbd *sdp = rgd->rd_sbd; 562 562 struct rb_node **newn = &sdp->sd_rindex_tree.rb_node, *parent = NULL; ··· 571 573 else if (rgd->rd_addr > cur->rd_addr) 572 574 newn = &((*newn)->rb_right); 573 575 else 574 - return; 576 + return -EEXIST; 575 577 } 576 578 577 579 rb_link_node(&rgd->rd_node, parent, newn); 578 580 rb_insert_color(&rgd->rd_node, &sdp->sd_rindex_tree); 581 + sdp->sd_rgrps++; 582 + return 0; 579 583 } 580 584 581 585 /** ··· 631 631 if (rgd->rd_data > sdp->sd_max_rg_data) 632 632 sdp->sd_max_rg_data = rgd->rd_data; 633 633 spin_lock(&sdp->sd_rindex_spin); 634 - rgd_insert(rgd); 635 - sdp->sd_rgrps++; 634 + error = rgd_insert(rgd); 636 635 spin_unlock(&sdp->sd_rindex_spin); 637 - return error; 636 + if (!error) 637 + return 0; 638 + 639 + error = 0; /* someone else read in the rgrp; free it and ignore it */ 638 640 639 641 fail: 640 642 kfree(rgd->rd_bits); ··· 697 695 698 696 /* Read new copy from disk if we don't have the latest */ 699 697 if (!sdp->sd_rindex_uptodate) { 700 - mutex_lock(&sdp->sd_rindex_mutex); 701 698 if (!gfs2_glock_is_locked_by_me(gl)) { 702 699 error = gfs2_glock_nq_init(gl, LM_ST_SHARED, 0, &ri_gh); 703 700 if (error) 704 - goto out_unlock; 701 + return error; 705 702 unlock_required = 1; 706 703 } 707 704 if (!sdp->sd_rindex_uptodate) 708 705 error = gfs2_ri_update(ip); 709 706 if (unlock_required) 710 707 gfs2_glock_dq_uninit(&ri_gh); 711 - out_unlock: 712 - mutex_unlock(&sdp->sd_rindex_mutex); 713 708 } 714 - 715 709 716 710 return error; 717 711 }