diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-01 11:51:04 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-01 11:51:04 -0400 |
| commit | e151960a23cc99e310f90adad7ee592821a77434 (patch) | |
| tree | 3bc01871b1548b4e15d89a54b18f8c9213c90acc | |
| parent | a0d271cbfed1dd50278c6b06bead3d00ba0a88f9 (diff) | |
| parent | 2216db70c95a9610f5279b8da53bec614d98270f (diff) | |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw
Pull GFS2 updates from Steven Whitehouse:
"The major feature this time is the "rbm" conversion in the resource
group code. The new struct gfs2_rbm specifies the location of an
allocatable block in (resource group, bitmap, offset) form. There are
a number of added helper functions, and later patches then rewrite
some of the resource group code in terms of this new structure. Not
only does this give us a nice code clean up, but it also removes some
of the previous restrictions where extents could not cross bitmap
boundaries, for example.
In addition to that, there are a few bug fixes and clean ups, but the
rbm work is by far the majority of this patch set in terms of number
of changed lines."
* git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-3.0-nmw: (27 commits)
GFS2: Write out dirty inode metadata in delayed deletes
GFS2: fix s_writers.counter imbalance in gfs2_ail_empty_gl
GFS2: Fix infinite loop in rbm_find
GFS2: Consolidate free block searching functions
GFS2: Get rid of I_MUTEX_QUOTA usage
GFS2: Stop block extents at the end of bitmaps
GFS2: Fix unclaimed_blocks() wrapping bug and clean up
GFS2: Improve block reservation tracing
GFS2: Fall back to ignoring reservations, if there are no other blocks left
GFS2: Fix ->show_options() for statfs slow
GFS2: Use rbm for gfs2_setbit()
GFS2: Use rbm for gfs2_testbit()
GFS2: Eliminate unnecessary check for state > 3 in bitfit
GFS2: Eliminate redundant calls to may_grant
GFS2: Combine functions gfs2_glock_dq_wait and wait_on_demote
GFS2: Combine functions gfs2_glock_wait and wait_on_holder
GFS2: inline __gfs2_glock_schedule_for_reclaim
GFS2: change function gfs2_direct_IO to use a normal gfs2_glock_dq
GFS2: rbm code cleanup
GFS2: Fix case where reservation finished at end of rgrp
...
| -rw-r--r-- | fs/gfs2/aops.c | 11 | ||||
| -rw-r--r-- | fs/gfs2/bmap.c | 2 | ||||
| -rw-r--r-- | fs/gfs2/file.c | 4 | ||||
| -rw-r--r-- | fs/gfs2/glock.c | 60 | ||||
| -rw-r--r-- | fs/gfs2/glops.c | 1 | ||||
| -rw-r--r-- | fs/gfs2/incore.h | 30 | ||||
| -rw-r--r-- | fs/gfs2/inode.c | 20 | ||||
| -rw-r--r-- | fs/gfs2/ops_fstype.c | 8 | ||||
| -rw-r--r-- | fs/gfs2/quota.c | 11 | ||||
| -rw-r--r-- | fs/gfs2/rgrp.c | 1203 | ||||
| -rw-r--r-- | fs/gfs2/rgrp.h | 28 | ||||
| -rw-r--r-- | fs/gfs2/super.c | 9 | ||||
| -rw-r--r-- | fs/gfs2/trace_gfs2.h | 20 | ||||
| -rw-r--r-- | fs/gfs2/trans.h | 7 | ||||
| -rw-r--r-- | fs/gfs2/xattr.c | 96 |
15 files changed, 710 insertions, 800 deletions
diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c index d6526347d386..01c4975da4bc 100644 --- a/fs/gfs2/aops.c +++ b/fs/gfs2/aops.c | |||
| @@ -612,6 +612,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping, | |||
| 612 | struct gfs2_sbd *sdp = GFS2_SB(mapping->host); | 612 | struct gfs2_sbd *sdp = GFS2_SB(mapping->host); |
| 613 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); | 613 | struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode); |
| 614 | unsigned int data_blocks = 0, ind_blocks = 0, rblocks; | 614 | unsigned int data_blocks = 0, ind_blocks = 0, rblocks; |
| 615 | unsigned requested = 0; | ||
| 615 | int alloc_required; | 616 | int alloc_required; |
| 616 | int error = 0; | 617 | int error = 0; |
| 617 | pgoff_t index = pos >> PAGE_CACHE_SHIFT; | 618 | pgoff_t index = pos >> PAGE_CACHE_SHIFT; |
| @@ -641,7 +642,8 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping, | |||
| 641 | if (error) | 642 | if (error) |
| 642 | goto out_unlock; | 643 | goto out_unlock; |
| 643 | 644 | ||
| 644 | error = gfs2_inplace_reserve(ip, data_blocks + ind_blocks); | 645 | requested = data_blocks + ind_blocks; |
| 646 | error = gfs2_inplace_reserve(ip, requested); | ||
| 645 | if (error) | 647 | if (error) |
| 646 | goto out_qunlock; | 648 | goto out_qunlock; |
| 647 | } | 649 | } |
| @@ -654,7 +656,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping, | |||
| 654 | if (&ip->i_inode == sdp->sd_rindex) | 656 | if (&ip->i_inode == sdp->sd_rindex) |
| 655 | rblocks += 2 * RES_STATFS; | 657 | rblocks += 2 * RES_STATFS; |
| 656 | if (alloc_required) | 658 | if (alloc_required) |
| 657 | rblocks += gfs2_rg_blocks(ip); | 659 | rblocks += gfs2_rg_blocks(ip, requested); |
| 658 | 660 | ||
| 659 | error = gfs2_trans_begin(sdp, rblocks, | 661 | error = gfs2_trans_begin(sdp, rblocks, |
| 660 | PAGE_CACHE_SIZE/sdp->sd_sb.sb_bsize); | 662 | PAGE_CACHE_SIZE/sdp->sd_sb.sb_bsize); |
| @@ -868,8 +870,7 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping, | |||
| 868 | brelse(dibh); | 870 | brelse(dibh); |
| 869 | failed: | 871 | failed: |
| 870 | gfs2_trans_end(sdp); | 872 | gfs2_trans_end(sdp); |
| 871 | if (gfs2_mb_reserved(ip)) | 873 | gfs2_inplace_release(ip); |
| 872 | gfs2_inplace_release(ip); | ||
| 873 | if (ip->i_res->rs_qa_qd_num) | 874 | if (ip->i_res->rs_qa_qd_num) |
| 874 | gfs2_quota_unlock(ip); | 875 | gfs2_quota_unlock(ip); |
| 875 | if (inode == sdp->sd_rindex) { | 876 | if (inode == sdp->sd_rindex) { |
| @@ -1023,7 +1024,7 @@ static ssize_t gfs2_direct_IO(int rw, struct kiocb *iocb, | |||
| 1023 | offset, nr_segs, gfs2_get_block_direct, | 1024 | offset, nr_segs, gfs2_get_block_direct, |
| 1024 | NULL, NULL, 0); | 1025 | NULL, NULL, 0); |
| 1025 | out: | 1026 | out: |
| 1026 | gfs2_glock_dq_m(1, &gh); | 1027 | gfs2_glock_dq(&gh); |
| 1027 | gfs2_holder_uninit(&gh); | 1028 | gfs2_holder_uninit(&gh); |
| 1028 | return rv; | 1029 | return rv; |
| 1029 | } | 1030 | } |
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index 49cd7dd4a9fa..1fd3ae237bdd 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c | |||
| @@ -786,7 +786,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, | |||
| 786 | goto out_rlist; | 786 | goto out_rlist; |
| 787 | 787 | ||
| 788 | if (gfs2_rs_active(ip->i_res)) /* needs to be done with the rgrp glock held */ | 788 | if (gfs2_rs_active(ip->i_res)) /* needs to be done with the rgrp glock held */ |
| 789 | gfs2_rs_deltree(ip->i_res); | 789 | gfs2_rs_deltree(ip, ip->i_res); |
| 790 | 790 | ||
| 791 | error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + | 791 | error = gfs2_trans_begin(sdp, rg_blocks + RES_DINODE + |
| 792 | RES_INDIRECT + RES_STATFS + RES_QUOTA, | 792 | RES_INDIRECT + RES_STATFS + RES_QUOTA, |
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 382000ffac1f..30e21997a1a1 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c | |||
| @@ -441,7 +441,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
| 441 | rblocks += data_blocks ? data_blocks : 1; | 441 | rblocks += data_blocks ? data_blocks : 1; |
| 442 | if (ind_blocks || data_blocks) { | 442 | if (ind_blocks || data_blocks) { |
| 443 | rblocks += RES_STATFS + RES_QUOTA; | 443 | rblocks += RES_STATFS + RES_QUOTA; |
| 444 | rblocks += gfs2_rg_blocks(ip); | 444 | rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks); |
| 445 | } | 445 | } |
| 446 | ret = gfs2_trans_begin(sdp, rblocks, 0); | 446 | ret = gfs2_trans_begin(sdp, rblocks, 0); |
| 447 | if (ret) | 447 | if (ret) |
| @@ -845,7 +845,7 @@ retry: | |||
| 845 | &max_bytes, &data_blocks, &ind_blocks); | 845 | &max_bytes, &data_blocks, &ind_blocks); |
| 846 | 846 | ||
| 847 | rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA + | 847 | rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA + |
| 848 | RES_RG_HDR + gfs2_rg_blocks(ip); | 848 | RES_RG_HDR + gfs2_rg_blocks(ip, data_blocks + ind_blocks); |
| 849 | if (gfs2_is_jdata(ip)) | 849 | if (gfs2_is_jdata(ip)) |
| 850 | rblocks += data_blocks ? data_blocks : 1; | 850 | rblocks += data_blocks ? data_blocks : 1; |
| 851 | 851 | ||
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 1ed81f40da0d..e6c2fd53cab2 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c | |||
| @@ -186,20 +186,6 @@ static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl) | |||
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | /** | 188 | /** |
| 189 | * __gfs2_glock_schedule_for_reclaim - Add a glock to the reclaim list | ||
| 190 | * @gl: the glock | ||
| 191 | * | ||
| 192 | * If the glock is demotable, then we add it (or move it) to the end | ||
| 193 | * of the glock LRU list. | ||
| 194 | */ | ||
| 195 | |||
| 196 | static void __gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl) | ||
| 197 | { | ||
| 198 | if (demote_ok(gl)) | ||
| 199 | gfs2_glock_add_to_lru(gl); | ||
| 200 | } | ||
| 201 | |||
| 202 | /** | ||
| 203 | * gfs2_glock_put_nolock() - Decrement reference count on glock | 189 | * gfs2_glock_put_nolock() - Decrement reference count on glock |
| 204 | * @gl: The glock to put | 190 | * @gl: The glock to put |
| 205 | * | 191 | * |
| @@ -883,7 +869,14 @@ static int gfs2_glock_demote_wait(void *word) | |||
| 883 | return 0; | 869 | return 0; |
| 884 | } | 870 | } |
| 885 | 871 | ||
| 886 | static void wait_on_holder(struct gfs2_holder *gh) | 872 | /** |
| 873 | * gfs2_glock_wait - wait on a glock acquisition | ||
| 874 | * @gh: the glock holder | ||
| 875 | * | ||
| 876 | * Returns: 0 on success | ||
| 877 | */ | ||
| 878 | |||
| 879 | int gfs2_glock_wait(struct gfs2_holder *gh) | ||
| 887 | { | 880 | { |
| 888 | unsigned long time1 = jiffies; | 881 | unsigned long time1 = jiffies; |
| 889 | 882 | ||
| @@ -894,12 +887,7 @@ static void wait_on_holder(struct gfs2_holder *gh) | |||
| 894 | gh->gh_gl->gl_hold_time = min(gh->gh_gl->gl_hold_time + | 887 | gh->gh_gl->gl_hold_time = min(gh->gh_gl->gl_hold_time + |
| 895 | GL_GLOCK_HOLD_INCR, | 888 | GL_GLOCK_HOLD_INCR, |
| 896 | GL_GLOCK_MAX_HOLD); | 889 | GL_GLOCK_MAX_HOLD); |
| 897 | } | 890 | return gh->gh_error; |
| 898 | |||
| 899 | static void wait_on_demote(struct gfs2_glock *gl) | ||
| 900 | { | ||
| 901 | might_sleep(); | ||
| 902 | wait_on_bit(&gl->gl_flags, GLF_DEMOTE, gfs2_glock_demote_wait, TASK_UNINTERRUPTIBLE); | ||
| 903 | } | 891 | } |
| 904 | 892 | ||
| 905 | /** | 893 | /** |
| @@ -929,19 +917,6 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state, | |||
| 929 | trace_gfs2_demote_rq(gl); | 917 | trace_gfs2_demote_rq(gl); |
| 930 | } | 918 | } |
| 931 | 919 | ||
| 932 | /** | ||
| 933 | * gfs2_glock_wait - wait on a glock acquisition | ||
| 934 | * @gh: the glock holder | ||
| 935 | * | ||
| 936 | * Returns: 0 on success | ||
| 937 | */ | ||
| 938 | |||
| 939 | int gfs2_glock_wait(struct gfs2_holder *gh) | ||
| 940 | { | ||
| 941 | wait_on_holder(gh); | ||
| 942 | return gh->gh_error; | ||
| 943 | } | ||
| 944 | |||
| 945 | void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...) | 920 | void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...) |
| 946 | { | 921 | { |
| 947 | struct va_format vaf; | 922 | struct va_format vaf; |
| @@ -979,7 +954,7 @@ __acquires(&gl->gl_spin) | |||
| 979 | struct gfs2_sbd *sdp = gl->gl_sbd; | 954 | struct gfs2_sbd *sdp = gl->gl_sbd; |
| 980 | struct list_head *insert_pt = NULL; | 955 | struct list_head *insert_pt = NULL; |
| 981 | struct gfs2_holder *gh2; | 956 | struct gfs2_holder *gh2; |
| 982 | int try_lock = 0; | 957 | int try_futile = 0; |
| 983 | 958 | ||
| 984 | BUG_ON(gh->gh_owner_pid == NULL); | 959 | BUG_ON(gh->gh_owner_pid == NULL); |
| 985 | if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags)) | 960 | if (test_and_set_bit(HIF_WAIT, &gh->gh_iflags)) |
| @@ -987,7 +962,7 @@ __acquires(&gl->gl_spin) | |||
| 987 | 962 | ||
| 988 | if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) { | 963 | if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) { |
| 989 | if (test_bit(GLF_LOCK, &gl->gl_flags)) | 964 | if (test_bit(GLF_LOCK, &gl->gl_flags)) |
| 990 | try_lock = 1; | 965 | try_futile = !may_grant(gl, gh); |
| 991 | if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags)) | 966 | if (test_bit(GLF_INVALIDATE_IN_PROGRESS, &gl->gl_flags)) |
| 992 | goto fail; | 967 | goto fail; |
| 993 | } | 968 | } |
| @@ -996,9 +971,8 @@ __acquires(&gl->gl_spin) | |||
| 996 | if (unlikely(gh2->gh_owner_pid == gh->gh_owner_pid && | 971 | if (unlikely(gh2->gh_owner_pid == gh->gh_owner_pid && |
| 997 | (gh->gh_gl->gl_ops->go_type != LM_TYPE_FLOCK))) | 972 | (gh->gh_gl->gl_ops->go_type != LM_TYPE_FLOCK))) |
| 998 | goto trap_recursive; | 973 | goto trap_recursive; |
| 999 | if (try_lock && | 974 | if (try_futile && |
| 1000 | !(gh2->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)) && | 975 | !(gh2->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) { |
| 1001 | !may_grant(gl, gh)) { | ||
| 1002 | fail: | 976 | fail: |
| 1003 | gh->gh_error = GLR_TRYFAILED; | 977 | gh->gh_error = GLR_TRYFAILED; |
| 1004 | gfs2_holder_wake(gh); | 978 | gfs2_holder_wake(gh); |
| @@ -1121,8 +1095,9 @@ void gfs2_glock_dq(struct gfs2_holder *gh) | |||
| 1121 | !test_bit(GLF_DEMOTE, &gl->gl_flags)) | 1095 | !test_bit(GLF_DEMOTE, &gl->gl_flags)) |
| 1122 | fast_path = 1; | 1096 | fast_path = 1; |
| 1123 | } | 1097 | } |
| 1124 | if (!test_bit(GLF_LFLUSH, &gl->gl_flags)) | 1098 | if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl)) |
| 1125 | __gfs2_glock_schedule_for_reclaim(gl); | 1099 | gfs2_glock_add_to_lru(gl); |
| 1100 | |||
| 1126 | trace_gfs2_glock_queue(gh, 0); | 1101 | trace_gfs2_glock_queue(gh, 0); |
| 1127 | spin_unlock(&gl->gl_spin); | 1102 | spin_unlock(&gl->gl_spin); |
| 1128 | if (likely(fast_path)) | 1103 | if (likely(fast_path)) |
| @@ -1141,7 +1116,8 @@ void gfs2_glock_dq_wait(struct gfs2_holder *gh) | |||
| 1141 | { | 1116 | { |
| 1142 | struct gfs2_glock *gl = gh->gh_gl; | 1117 | struct gfs2_glock *gl = gh->gh_gl; |
| 1143 | gfs2_glock_dq(gh); | 1118 | gfs2_glock_dq(gh); |
| 1144 | wait_on_demote(gl); | 1119 | might_sleep(); |
| 1120 | wait_on_bit(&gl->gl_flags, GLF_DEMOTE, gfs2_glock_demote_wait, TASK_UNINTERRUPTIBLE); | ||
| 1145 | } | 1121 | } |
| 1146 | 1122 | ||
| 1147 | /** | 1123 | /** |
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c index 4bdcf3784187..32cc4fde975c 100644 --- a/fs/gfs2/glops.c +++ b/fs/gfs2/glops.c | |||
| @@ -94,6 +94,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl) | |||
| 94 | /* A shortened, inline version of gfs2_trans_begin() */ | 94 | /* A shortened, inline version of gfs2_trans_begin() */ |
| 95 | tr.tr_reserved = 1 + gfs2_struct2blk(sdp, tr.tr_revokes, sizeof(u64)); | 95 | tr.tr_reserved = 1 + gfs2_struct2blk(sdp, tr.tr_revokes, sizeof(u64)); |
| 96 | tr.tr_ip = (unsigned long)__builtin_return_address(0); | 96 | tr.tr_ip = (unsigned long)__builtin_return_address(0); |
| 97 | sb_start_intwrite(sdp->sd_vfs); | ||
| 97 | gfs2_log_reserve(sdp, tr.tr_reserved); | 98 | gfs2_log_reserve(sdp, tr.tr_reserved); |
| 98 | BUG_ON(current->journal_info); | 99 | BUG_ON(current->journal_info); |
| 99 | current->journal_info = &tr; | 100 | current->journal_info = &tr; |
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index aaecc8085fc5..3d469d37345e 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h | |||
| @@ -99,9 +99,26 @@ struct gfs2_rgrpd { | |||
| 99 | #define GFS2_RDF_MASK 0xf0000000 /* mask for internal flags */ | 99 | #define GFS2_RDF_MASK 0xf0000000 /* mask for internal flags */ |
| 100 | spinlock_t rd_rsspin; /* protects reservation related vars */ | 100 | spinlock_t rd_rsspin; /* protects reservation related vars */ |
| 101 | struct rb_root rd_rstree; /* multi-block reservation tree */ | 101 | struct rb_root rd_rstree; /* multi-block reservation tree */ |
| 102 | u32 rd_rs_cnt; /* count of current reservations */ | ||
| 103 | }; | 102 | }; |
| 104 | 103 | ||
| 104 | struct gfs2_rbm { | ||
| 105 | struct gfs2_rgrpd *rgd; | ||
| 106 | struct gfs2_bitmap *bi; /* Bitmap must belong to the rgd */ | ||
| 107 | u32 offset; /* The offset is bitmap relative */ | ||
| 108 | }; | ||
| 109 | |||
| 110 | static inline u64 gfs2_rbm_to_block(const struct gfs2_rbm *rbm) | ||
| 111 | { | ||
| 112 | return rbm->rgd->rd_data0 + (rbm->bi->bi_start * GFS2_NBBY) + rbm->offset; | ||
| 113 | } | ||
| 114 | |||
| 115 | static inline bool gfs2_rbm_eq(const struct gfs2_rbm *rbm1, | ||
| 116 | const struct gfs2_rbm *rbm2) | ||
| 117 | { | ||
| 118 | return (rbm1->rgd == rbm2->rgd) && (rbm1->bi == rbm2->bi) && | ||
| 119 | (rbm1->offset == rbm2->offset); | ||
| 120 | } | ||
| 121 | |||
| 105 | enum gfs2_state_bits { | 122 | enum gfs2_state_bits { |
| 106 | BH_Pinned = BH_PrivateStart, | 123 | BH_Pinned = BH_PrivateStart, |
| 107 | BH_Escaped = BH_PrivateStart + 1, | 124 | BH_Escaped = BH_PrivateStart + 1, |
| @@ -250,18 +267,11 @@ struct gfs2_blkreserv { | |||
| 250 | /* components used during write (step 1): */ | 267 | /* components used during write (step 1): */ |
| 251 | atomic_t rs_sizehint; /* hint of the write size */ | 268 | atomic_t rs_sizehint; /* hint of the write size */ |
| 252 | 269 | ||
| 253 | /* components used during inplace_reserve (step 2): */ | ||
| 254 | u32 rs_requested; /* Filled in by caller of gfs2_inplace_reserve() */ | ||
| 255 | |||
| 256 | /* components used during get_local_rgrp (step 3): */ | ||
| 257 | struct gfs2_rgrpd *rs_rgd; /* pointer to the gfs2_rgrpd */ | ||
| 258 | struct gfs2_holder rs_rgd_gh; /* Filled in by get_local_rgrp */ | 270 | struct gfs2_holder rs_rgd_gh; /* Filled in by get_local_rgrp */ |
| 259 | struct rb_node rs_node; /* link to other block reservations */ | 271 | struct rb_node rs_node; /* link to other block reservations */ |
| 260 | 272 | struct gfs2_rbm rs_rbm; /* Start of reservation */ | |
| 261 | /* components used during block searches and assignments (step 4): */ | ||
| 262 | struct gfs2_bitmap *rs_bi; /* bitmap for the current allocation */ | ||
| 263 | u32 rs_biblk; /* start block relative to the bi */ | ||
| 264 | u32 rs_free; /* how many blocks are still free */ | 273 | u32 rs_free; /* how many blocks are still free */ |
| 274 | u64 rs_inum; /* Inode number for reservation */ | ||
| 265 | 275 | ||
| 266 | /* ancillary quota stuff */ | 276 | /* ancillary quota stuff */ |
| 267 | struct gfs2_quota_data *rs_qa_qd[2 * MAXQUOTAS]; | 277 | struct gfs2_quota_data *rs_qa_qd[2 * MAXQUOTAS]; |
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 753af3d86bbc..381893ceefa4 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c | |||
| @@ -712,14 +712,9 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, | |||
| 712 | if (error) | 712 | if (error) |
| 713 | goto fail_gunlock2; | 713 | goto fail_gunlock2; |
| 714 | 714 | ||
| 715 | /* The newly created inode needs a reservation so it can allocate | 715 | error = gfs2_rs_alloc(ip); |
| 716 | xattrs. At the same time, we want new blocks allocated to the new | 716 | if (error) |
| 717 | dinode to be as contiguous as possible. Since we allocated the | 717 | goto fail_gunlock2; |
| 718 | dinode block under the directory's reservation, we transfer | ||
| 719 | ownership of that reservation to the new inode. The directory | ||
| 720 | doesn't need a reservation unless it needs a new allocation. */ | ||
| 721 | ip->i_res = dip->i_res; | ||
| 722 | dip->i_res = NULL; | ||
| 723 | 718 | ||
| 724 | error = gfs2_acl_create(dip, inode); | 719 | error = gfs2_acl_create(dip, inode); |
| 725 | if (error) | 720 | if (error) |
| @@ -737,10 +732,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, | |||
| 737 | brelse(bh); | 732 | brelse(bh); |
| 738 | 733 | ||
| 739 | gfs2_trans_end(sdp); | 734 | gfs2_trans_end(sdp); |
| 740 | /* Check if we reserved space in the rgrp. Function link_dinode may | 735 | gfs2_inplace_release(dip); |
| 741 | not, depending on whether alloc is required. */ | ||
| 742 | if (gfs2_mb_reserved(dip)) | ||
| 743 | gfs2_inplace_release(dip); | ||
| 744 | gfs2_quota_unlock(dip); | 736 | gfs2_quota_unlock(dip); |
| 745 | mark_inode_dirty(inode); | 737 | mark_inode_dirty(inode); |
| 746 | gfs2_glock_dq_uninit_m(2, ghs); | 738 | gfs2_glock_dq_uninit_m(2, ghs); |
| @@ -897,7 +889,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir, | |||
| 897 | goto out_gunlock_q; | 889 | goto out_gunlock_q; |
| 898 | 890 | ||
| 899 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + | 891 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
| 900 | gfs2_rg_blocks(dip) + | 892 | gfs2_rg_blocks(dip, sdp->sd_max_dirres) + |
| 901 | 2 * RES_DINODE + RES_STATFS + | 893 | 2 * RES_DINODE + RES_STATFS + |
| 902 | RES_QUOTA, 0); | 894 | RES_QUOTA, 0); |
| 903 | if (error) | 895 | if (error) |
| @@ -1378,7 +1370,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, | |||
| 1378 | goto out_gunlock_q; | 1370 | goto out_gunlock_q; |
| 1379 | 1371 | ||
| 1380 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + | 1372 | error = gfs2_trans_begin(sdp, sdp->sd_max_dirres + |
| 1381 | gfs2_rg_blocks(ndip) + | 1373 | gfs2_rg_blocks(ndip, sdp->sd_max_dirres) + |
| 1382 | 4 * RES_DINODE + 4 * RES_LEAF + | 1374 | 4 * RES_DINODE + 4 * RES_LEAF + |
| 1383 | RES_STATFS + RES_QUOTA + 4, 0); | 1375 | RES_STATFS + RES_QUOTA + 4, 0); |
| 1384 | if (error) | 1376 | if (error) |
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index e5af9dc420ef..e443966c8106 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c | |||
| @@ -19,6 +19,7 @@ | |||
| 19 | #include <linux/mount.h> | 19 | #include <linux/mount.h> |
| 20 | #include <linux/gfs2_ondisk.h> | 20 | #include <linux/gfs2_ondisk.h> |
| 21 | #include <linux/quotaops.h> | 21 | #include <linux/quotaops.h> |
| 22 | #include <linux/lockdep.h> | ||
| 22 | 23 | ||
| 23 | #include "gfs2.h" | 24 | #include "gfs2.h" |
| 24 | #include "incore.h" | 25 | #include "incore.h" |
| @@ -766,6 +767,7 @@ fail: | |||
| 766 | return error; | 767 | return error; |
| 767 | } | 768 | } |
| 768 | 769 | ||
| 770 | static struct lock_class_key gfs2_quota_imutex_key; | ||
| 769 | 771 | ||
| 770 | static int init_inodes(struct gfs2_sbd *sdp, int undo) | 772 | static int init_inodes(struct gfs2_sbd *sdp, int undo) |
| 771 | { | 773 | { |
| @@ -803,6 +805,12 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo) | |||
| 803 | fs_err(sdp, "can't get quota file inode: %d\n", error); | 805 | fs_err(sdp, "can't get quota file inode: %d\n", error); |
| 804 | goto fail_rindex; | 806 | goto fail_rindex; |
| 805 | } | 807 | } |
| 808 | /* | ||
| 809 | * i_mutex on quota files is special. Since this inode is hidden system | ||
| 810 | * file, we are safe to define locking ourselves. | ||
| 811 | */ | ||
| 812 | lockdep_set_class(&sdp->sd_quota_inode->i_mutex, | ||
| 813 | &gfs2_quota_imutex_key); | ||
| 806 | 814 | ||
| 807 | error = gfs2_rindex_update(sdp); | 815 | error = gfs2_rindex_update(sdp); |
| 808 | if (error) | 816 | if (error) |
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index a3bde91645c2..4021deca61ef 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c | |||
| @@ -765,6 +765,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) | |||
| 765 | struct gfs2_holder *ghs, i_gh; | 765 | struct gfs2_holder *ghs, i_gh; |
| 766 | unsigned int qx, x; | 766 | unsigned int qx, x; |
| 767 | struct gfs2_quota_data *qd; | 767 | struct gfs2_quota_data *qd; |
| 768 | unsigned reserved; | ||
| 768 | loff_t offset; | 769 | loff_t offset; |
| 769 | unsigned int nalloc = 0, blocks; | 770 | unsigned int nalloc = 0, blocks; |
| 770 | int error; | 771 | int error; |
| @@ -781,7 +782,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) | |||
| 781 | return -ENOMEM; | 782 | return -ENOMEM; |
| 782 | 783 | ||
| 783 | sort(qda, num_qd, sizeof(struct gfs2_quota_data *), sort_qd, NULL); | 784 | sort(qda, num_qd, sizeof(struct gfs2_quota_data *), sort_qd, NULL); |
| 784 | mutex_lock_nested(&ip->i_inode.i_mutex, I_MUTEX_QUOTA); | 785 | mutex_lock(&ip->i_inode.i_mutex); |
| 785 | for (qx = 0; qx < num_qd; qx++) { | 786 | for (qx = 0; qx < num_qd; qx++) { |
| 786 | error = gfs2_glock_nq_init(qda[qx]->qd_gl, LM_ST_EXCLUSIVE, | 787 | error = gfs2_glock_nq_init(qda[qx]->qd_gl, LM_ST_EXCLUSIVE, |
| 787 | GL_NOCACHE, &ghs[qx]); | 788 | GL_NOCACHE, &ghs[qx]); |
| @@ -811,13 +812,13 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) | |||
| 811 | * two blocks need to be updated instead of 1 */ | 812 | * two blocks need to be updated instead of 1 */ |
| 812 | blocks = num_qd * data_blocks + RES_DINODE + num_qd + 3; | 813 | blocks = num_qd * data_blocks + RES_DINODE + num_qd + 3; |
| 813 | 814 | ||
| 814 | error = gfs2_inplace_reserve(ip, 1 + | 815 | reserved = 1 + (nalloc * (data_blocks + ind_blocks)); |
| 815 | (nalloc * (data_blocks + ind_blocks))); | 816 | error = gfs2_inplace_reserve(ip, reserved); |
| 816 | if (error) | 817 | if (error) |
| 817 | goto out_alloc; | 818 | goto out_alloc; |
| 818 | 819 | ||
| 819 | if (nalloc) | 820 | if (nalloc) |
| 820 | blocks += gfs2_rg_blocks(ip) + nalloc * ind_blocks + RES_STATFS; | 821 | blocks += gfs2_rg_blocks(ip, reserved) + nalloc * ind_blocks + RES_STATFS; |
| 821 | 822 | ||
| 822 | error = gfs2_trans_begin(sdp, blocks, 0); | 823 | error = gfs2_trans_begin(sdp, blocks, 0); |
| 823 | if (error) | 824 | if (error) |
| @@ -1598,7 +1599,7 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id, | |||
| 1598 | error = gfs2_inplace_reserve(ip, blocks); | 1599 | error = gfs2_inplace_reserve(ip, blocks); |
| 1599 | if (error) | 1600 | if (error) |
| 1600 | goto out_i; | 1601 | goto out_i; |
| 1601 | blocks += gfs2_rg_blocks(ip); | 1602 | blocks += gfs2_rg_blocks(ip, blocks); |
| 1602 | } | 1603 | } |
| 1603 | 1604 | ||
| 1604 | /* Some quotas span block boundaries and can update two blocks, | 1605 | /* Some quotas span block boundaries and can update two blocks, |
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index c9ed814eeb6f..3cc402ce6fea 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c | |||
| @@ -35,9 +35,6 @@ | |||
| 35 | #define BFITNOENT ((u32)~0) | 35 | #define BFITNOENT ((u32)~0) |
| 36 | #define NO_BLOCK ((u64)~0) | 36 | #define NO_BLOCK ((u64)~0) |
| 37 | 37 | ||
| 38 | #define RSRV_CONTENTION_FACTOR 4 | ||
| 39 | #define RGRP_RSRV_MAX_CONTENDERS 2 | ||
| 40 | |||
| 41 | #if BITS_PER_LONG == 32 | 38 | #if BITS_PER_LONG == 32 |
| 42 | #define LBITMASK (0x55555555UL) | 39 | #define LBITMASK (0x55555555UL) |
| 43 | #define LBITSKIP55 (0x55555555UL) | 40 | #define LBITSKIP55 (0x55555555UL) |
| @@ -67,53 +64,48 @@ static const char valid_change[16] = { | |||
| 67 | 1, 0, 0, 0 | 64 | 1, 0, 0, 0 |
| 68 | }; | 65 | }; |
| 69 | 66 | ||
| 70 | static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, | 67 | static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext, |
| 71 | unsigned char old_state, | 68 | const struct gfs2_inode *ip, bool nowrap); |
| 72 | struct gfs2_bitmap **rbi); | 69 | |
| 73 | 70 | ||
| 74 | /** | 71 | /** |
| 75 | * gfs2_setbit - Set a bit in the bitmaps | 72 | * gfs2_setbit - Set a bit in the bitmaps |
| 76 | * @rgd: the resource group descriptor | 73 | * @rbm: The position of the bit to set |
| 77 | * @buf2: the clone buffer that holds the bitmaps | 74 | * @do_clone: Also set the clone bitmap, if it exists |
| 78 | * @bi: the bitmap structure | ||
| 79 | * @block: the block to set | ||
| 80 | * @new_state: the new state of the block | 75 | * @new_state: the new state of the block |
| 81 | * | 76 | * |
| 82 | */ | 77 | */ |
| 83 | 78 | ||
| 84 | static inline void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buf2, | 79 | static inline void gfs2_setbit(const struct gfs2_rbm *rbm, bool do_clone, |
| 85 | struct gfs2_bitmap *bi, u32 block, | ||
| 86 | unsigned char new_state) | 80 | unsigned char new_state) |
| 87 | { | 81 | { |
| 88 | unsigned char *byte1, *byte2, *end, cur_state; | 82 | unsigned char *byte1, *byte2, *end, cur_state; |
| 89 | unsigned int buflen = bi->bi_len; | 83 | unsigned int buflen = rbm->bi->bi_len; |
| 90 | const unsigned int bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE; | 84 | const unsigned int bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE; |
| 91 | 85 | ||
| 92 | byte1 = bi->bi_bh->b_data + bi->bi_offset + (block / GFS2_NBBY); | 86 | byte1 = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset + (rbm->offset / GFS2_NBBY); |
| 93 | end = bi->bi_bh->b_data + bi->bi_offset + buflen; | 87 | end = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset + buflen; |
| 94 | 88 | ||
| 95 | BUG_ON(byte1 >= end); | 89 | BUG_ON(byte1 >= end); |
| 96 | 90 | ||
| 97 | cur_state = (*byte1 >> bit) & GFS2_BIT_MASK; | 91 | cur_state = (*byte1 >> bit) & GFS2_BIT_MASK; |
| 98 | 92 | ||
| 99 | if (unlikely(!valid_change[new_state * 4 + cur_state])) { | 93 | if (unlikely(!valid_change[new_state * 4 + cur_state])) { |
| 100 | printk(KERN_WARNING "GFS2: buf_blk = 0x%llx old_state=%d, " | 94 | printk(KERN_WARNING "GFS2: buf_blk = 0x%x old_state=%d, " |
| 101 | "new_state=%d\n", | 95 | "new_state=%d\n", rbm->offset, cur_state, new_state); |
| 102 | (unsigned long long)block, cur_state, new_state); | 96 | printk(KERN_WARNING "GFS2: rgrp=0x%llx bi_start=0x%x\n", |
| 103 | printk(KERN_WARNING "GFS2: rgrp=0x%llx bi_start=0x%lx\n", | 97 | (unsigned long long)rbm->rgd->rd_addr, |
| 104 | (unsigned long long)rgd->rd_addr, | 98 | rbm->bi->bi_start); |
| 105 | (unsigned long)bi->bi_start); | 99 | printk(KERN_WARNING "GFS2: bi_offset=0x%x bi_len=0x%x\n", |
| 106 | printk(KERN_WARNING "GFS2: bi_offset=0x%lx bi_len=0x%lx\n", | 100 | rbm->bi->bi_offset, rbm->bi->bi_len); |
| 107 | (unsigned long)bi->bi_offset, | ||
| 108 | (unsigned long)bi->bi_len); | ||
| 109 | dump_stack(); | 101 | dump_stack(); |
| 110 | gfs2_consist_rgrpd(rgd); | 102 | gfs2_consist_rgrpd(rbm->rgd); |
| 111 | return; | 103 | return; |
| 112 | } | 104 | } |
| 113 | *byte1 ^= (cur_state ^ new_state) << bit; | 105 | *byte1 ^= (cur_state ^ new_state) << bit; |
| 114 | 106 | ||
| 115 | if (buf2) { | 107 | if (do_clone && rbm->bi->bi_clone) { |
| 116 | byte2 = buf2 + bi->bi_offset + (block / GFS2_NBBY); | 108 | byte2 = rbm->bi->bi_clone + rbm->bi->bi_offset + (rbm->offset / GFS2_NBBY); |
| 117 | cur_state = (*byte2 >> bit) & GFS2_BIT_MASK; | 109 | cur_state = (*byte2 >> bit) & GFS2_BIT_MASK; |
| 118 | *byte2 ^= (cur_state ^ new_state) << bit; | 110 | *byte2 ^= (cur_state ^ new_state) << bit; |
| 119 | } | 111 | } |
| @@ -121,30 +113,21 @@ static inline void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buf2, | |||
| 121 | 113 | ||
| 122 | /** | 114 | /** |
| 123 | * gfs2_testbit - test a bit in the bitmaps | 115 | * gfs2_testbit - test a bit in the bitmaps |
| 124 | * @rgd: the resource group descriptor | 116 | * @rbm: The bit to test |
| 125 | * @buffer: the buffer that holds the bitmaps | ||
| 126 | * @buflen: the length (in bytes) of the buffer | ||
| 127 | * @block: the block to read | ||
| 128 | * | 117 | * |
| 118 | * Returns: The two bit block state of the requested bit | ||
| 129 | */ | 119 | */ |
| 130 | 120 | ||
| 131 | static inline unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, | 121 | static inline u8 gfs2_testbit(const struct gfs2_rbm *rbm) |
| 132 | const unsigned char *buffer, | ||
| 133 | unsigned int buflen, u32 block) | ||
| 134 | { | 122 | { |
| 135 | const unsigned char *byte, *end; | 123 | const u8 *buffer = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset; |
| 136 | unsigned char cur_state; | 124 | const u8 *byte; |
| 137 | unsigned int bit; | 125 | unsigned int bit; |
| 138 | 126 | ||
| 139 | byte = buffer + (block / GFS2_NBBY); | 127 | byte = buffer + (rbm->offset / GFS2_NBBY); |
| 140 | bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE; | 128 | bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE; |
| 141 | end = buffer + buflen; | ||
| 142 | |||
| 143 | gfs2_assert(rgd->rd_sbd, byte < end); | ||
| 144 | 129 | ||
| 145 | cur_state = (*byte >> bit) & GFS2_BIT_MASK; | 130 | return (*byte >> bit) & GFS2_BIT_MASK; |
| 146 | |||
| 147 | return cur_state; | ||
| 148 | } | 131 | } |
| 149 | 132 | ||
| 150 | /** | 133 | /** |
| @@ -192,7 +175,7 @@ static inline u64 gfs2_bit_search(const __le64 *ptr, u64 mask, u8 state) | |||
| 192 | */ | 175 | */ |
| 193 | static inline int rs_cmp(u64 blk, u32 len, struct gfs2_blkreserv *rs) | 176 | static inline int rs_cmp(u64 blk, u32 len, struct gfs2_blkreserv *rs) |
| 194 | { | 177 | { |
| 195 | u64 startblk = gfs2_rs_startblk(rs); | 178 | u64 startblk = gfs2_rbm_to_block(&rs->rs_rbm); |
| 196 | 179 | ||
| 197 | if (blk >= startblk + rs->rs_free) | 180 | if (blk >= startblk + rs->rs_free) |
| 198 | return 1; | 181 | return 1; |
| @@ -202,36 +185,6 @@ static inline int rs_cmp(u64 blk, u32 len, struct gfs2_blkreserv *rs) | |||
| 202 | } | 185 | } |
| 203 | 186 | ||
| 204 | /** | 187 | /** |
| 205 | * rs_find - Find a rgrp multi-block reservation that contains a given block | ||
| 206 | * @rgd: The rgrp | ||
| 207 | * @rgblk: The block we're looking for, relative to the rgrp | ||
| 208 | */ | ||
| 209 | static struct gfs2_blkreserv *rs_find(struct gfs2_rgrpd *rgd, u32 rgblk) | ||
| 210 | { | ||
| 211 | struct rb_node **newn; | ||
| 212 | int rc; | ||
| 213 | u64 fsblk = rgblk + rgd->rd_data0; | ||
| 214 | |||
| 215 | spin_lock(&rgd->rd_rsspin); | ||
| 216 | newn = &rgd->rd_rstree.rb_node; | ||
| 217 | while (*newn) { | ||
| 218 | struct gfs2_blkreserv *cur = | ||
| 219 | rb_entry(*newn, struct gfs2_blkreserv, rs_node); | ||
| 220 | rc = rs_cmp(fsblk, 1, cur); | ||
| 221 | if (rc < 0) | ||
| 222 | newn = &((*newn)->rb_left); | ||
| 223 | else if (rc > 0) | ||
| 224 | newn = &((*newn)->rb_right); | ||
| 225 | else { | ||
| 226 | spin_unlock(&rgd->rd_rsspin); | ||
| 227 | return cur; | ||
| 228 | } | ||
| 229 | } | ||
| 230 | spin_unlock(&rgd->rd_rsspin); | ||
| 231 | return NULL; | ||
| 232 | } | ||
| 233 | |||
| 234 | /** | ||
| 235 | * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing | 188 | * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing |
| 236 | * a block in a given allocation state. | 189 | * a block in a given allocation state. |
| 237 | * @buf: the buffer that holds the bitmaps | 190 | * @buf: the buffer that holds the bitmaps |
| @@ -262,8 +215,6 @@ static u32 gfs2_bitfit(const u8 *buf, const unsigned int len, | |||
| 262 | u64 mask = 0x5555555555555555ULL; | 215 | u64 mask = 0x5555555555555555ULL; |
| 263 | u32 bit; | 216 | u32 bit; |
| 264 | 217 | ||
| 265 | BUG_ON(state > 3); | ||
| 266 | |||
| 267 | /* Mask off bits we don't care about at the start of the search */ | 218 | /* Mask off bits we don't care about at the start of the search */ |
| 268 | mask <<= spoint; | 219 | mask <<= spoint; |
| 269 | tmp = gfs2_bit_search(ptr, mask, state); | 220 | tmp = gfs2_bit_search(ptr, mask, state); |
| @@ -285,6 +236,131 @@ static u32 gfs2_bitfit(const u8 *buf, const unsigned int len, | |||
| 285 | } | 236 | } |
| 286 | 237 | ||
| 287 | /** | 238 | /** |
| 239 | * gfs2_rbm_from_block - Set the rbm based upon rgd and block number | ||
| 240 | * @rbm: The rbm with rgd already set correctly | ||
| 241 | * @block: The block number (filesystem relative) | ||
| 242 | * | ||
| 243 | * This sets the bi and offset members of an rbm based on a | ||
| 244 | * resource group and a filesystem relative block number. The | ||
| 245 | * resource group must be set in the rbm on entry, the bi and | ||
| 246 | * offset members will be set by this function. | ||
| 247 | * | ||
| 248 | * Returns: 0 on success, or an error code | ||
| 249 | */ | ||
| 250 | |||
| 251 | static int gfs2_rbm_from_block(struct gfs2_rbm *rbm, u64 block) | ||
| 252 | { | ||
| 253 | u64 rblock = block - rbm->rgd->rd_data0; | ||
| 254 | u32 goal = (u32)rblock; | ||
| 255 | int x; | ||
| 256 | |||
| 257 | if (WARN_ON_ONCE(rblock > UINT_MAX)) | ||
| 258 | return -EINVAL; | ||
| 259 | if (block >= rbm->rgd->rd_data0 + rbm->rgd->rd_data) | ||
| 260 | return -E2BIG; | ||
| 261 | |||
| 262 | for (x = 0; x < rbm->rgd->rd_length; x++) { | ||
| 263 | rbm->bi = rbm->rgd->rd_bits + x; | ||
| 264 | if (goal < (rbm->bi->bi_start + rbm->bi->bi_len) * GFS2_NBBY) { | ||
| 265 | rbm->offset = goal - (rbm->bi->bi_start * GFS2_NBBY); | ||
| 266 | break; | ||
| 267 | } | ||
| 268 | } | ||
| 269 | |||
| 270 | return 0; | ||
| 271 | } | ||
| 272 | |||
| 273 | /** | ||
| 274 | * gfs2_unaligned_extlen - Look for free blocks which are not byte aligned | ||
| 275 | * @rbm: Position to search (value/result) | ||
| 276 | * @n_unaligned: Number of unaligned blocks to check | ||
| 277 | * @len: Decremented for each block found (terminate on zero) | ||
| 278 | * | ||
| 279 | * Returns: true if a non-free block is encountered | ||
| 280 | */ | ||
| 281 | |||
| 282 | static bool gfs2_unaligned_extlen(struct gfs2_rbm *rbm, u32 n_unaligned, u32 *len) | ||
| 283 | { | ||
| 284 | u64 block; | ||
| 285 | u32 n; | ||
| 286 | u8 res; | ||
| 287 | |||
| 288 | for (n = 0; n < n_unaligned; n++) { | ||
| 289 | res = gfs2_testbit(rbm); | ||
| 290 | if (res != GFS2_BLKST_FREE) | ||
| 291 | return true; | ||
| 292 | (*len)--; | ||
| 293 | if (*len == 0) | ||
| 294 | return true; | ||
| 295 | block = gfs2_rbm_to_block(rbm); | ||
| 296 | if (gfs2_rbm_from_block(rbm, block + 1)) | ||
| 297 | return true; | ||
| 298 | } | ||
| 299 | |||
| 300 | return false; | ||
| 301 | } | ||
| 302 | |||
| 303 | /** | ||
| 304 | * gfs2_free_extlen - Return extent length of free blocks | ||
| 305 | * @rbm: Starting position | ||
| 306 | * @len: Max length to check | ||
| 307 | * | ||
| 308 | * Starting at the block specified by the rbm, see how many free blocks | ||
| 309 | * there are, not reading more than len blocks ahead. This can be done | ||
| 310 | * using memchr_inv when the blocks are byte aligned, but has to be done | ||
| 311 | * on a block by block basis in case of unaligned blocks. Also this | ||
| 312 | * function can cope with bitmap boundaries (although it must stop on | ||
| 313 | * a resource group boundary) | ||
| 314 | * | ||
| 315 | * Returns: Number of free blocks in the extent | ||
| 316 | */ | ||
| 317 | |||
| 318 | static u32 gfs2_free_extlen(const struct gfs2_rbm *rrbm, u32 len) | ||
| 319 | { | ||
| 320 | struct gfs2_rbm rbm = *rrbm; | ||
| 321 | u32 n_unaligned = rbm.offset & 3; | ||
| 322 | u32 size = len; | ||
| 323 | u32 bytes; | ||
| 324 | u32 chunk_size; | ||
| 325 | u8 *ptr, *start, *end; | ||
| 326 | u64 block; | ||
| 327 | |||
| 328 | if (n_unaligned && | ||
| 329 | gfs2_unaligned_extlen(&rbm, 4 - n_unaligned, &len)) | ||
| 330 | goto out; | ||
| 331 | |||
| 332 | n_unaligned = len & 3; | ||
| 333 | /* Start is now byte aligned */ | ||
| 334 | while (len > 3) { | ||
| 335 | start = rbm.bi->bi_bh->b_data; | ||
| 336 | if (rbm.bi->bi_clone) | ||
| 337 | start = rbm.bi->bi_clone; | ||
| 338 | end = start + rbm.bi->bi_bh->b_size; | ||
| 339 | start += rbm.bi->bi_offset; | ||
| 340 | BUG_ON(rbm.offset & 3); | ||
| 341 | start += (rbm.offset / GFS2_NBBY); | ||
| 342 | bytes = min_t(u32, len / GFS2_NBBY, (end - start)); | ||
| 343 | ptr = memchr_inv(start, 0, bytes); | ||
| 344 | chunk_size = ((ptr == NULL) ? bytes : (ptr - start)); | ||
| 345 | chunk_size *= GFS2_NBBY; | ||
| 346 | BUG_ON(len < chunk_size); | ||
| 347 | len -= chunk_size; | ||
| 348 | block = gfs2_rbm_to_block(&rbm); | ||
| 349 | gfs2_rbm_from_block(&rbm, block + chunk_size); | ||
| 350 | n_unaligned = 3; | ||
| 351 | if (ptr) | ||
| 352 | break; | ||
| 353 | n_unaligned = len & 3; | ||
| 354 | } | ||
| 355 | |||
| 356 | /* Deal with any bits left over at the end */ | ||
| 357 | if (n_unaligned) | ||
| 358 | gfs2_unaligned_extlen(&rbm, n_unaligned, &len); | ||
| 359 | out: | ||
| 360 | return size - len; | ||
| 361 | } | ||
| 362 | |||
| 363 | /** | ||
| 288 | * gfs2_bitcount - count the number of bits in a certain state | 364 | * gfs2_bitcount - count the number of bits in a certain state |
| 289 | * @rgd: the resource group descriptor | 365 | * @rgd: the resource group descriptor |
| 290 | * @buffer: the buffer that holds the bitmaps | 366 | * @buffer: the buffer that holds the bitmaps |
| @@ -487,6 +563,8 @@ int gfs2_rs_alloc(struct gfs2_inode *ip) | |||
| 487 | if (!res) | 563 | if (!res) |
| 488 | error = -ENOMEM; | 564 | error = -ENOMEM; |
| 489 | 565 | ||
| 566 | RB_CLEAR_NODE(&res->rs_node); | ||
| 567 | |||
| 490 | down_write(&ip->i_rw_mutex); | 568 | down_write(&ip->i_rw_mutex); |
| 491 | if (ip->i_res) | 569 | if (ip->i_res) |
| 492 | kmem_cache_free(gfs2_rsrv_cachep, res); | 570 | kmem_cache_free(gfs2_rsrv_cachep, res); |
| @@ -496,11 +574,12 @@ int gfs2_rs_alloc(struct gfs2_inode *ip) | |||
| 496 | return error; | 574 | return error; |
| 497 | } | 575 | } |
| 498 | 576 | ||
| 499 | static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs) | 577 | static void dump_rs(struct seq_file *seq, const struct gfs2_blkreserv *rs) |
| 500 | { | 578 | { |
| 501 | gfs2_print_dbg(seq, " r: %llu s:%llu b:%u f:%u\n", | 579 | gfs2_print_dbg(seq, " B: n:%llu s:%llu b:%u f:%u\n", |
| 502 | rs->rs_rgd->rd_addr, gfs2_rs_startblk(rs), rs->rs_biblk, | 580 | (unsigned long long)rs->rs_inum, |
| 503 | rs->rs_free); | 581 | (unsigned long long)gfs2_rbm_to_block(&rs->rs_rbm), |
| 582 | rs->rs_rbm.offset, rs->rs_free); | ||
| 504 | } | 583 | } |
| 505 | 584 | ||
| 506 | /** | 585 | /** |
| @@ -508,41 +587,26 @@ static void dump_rs(struct seq_file *seq, struct gfs2_blkreserv *rs) | |||
| 508 | * @rs: The reservation to remove | 587 | * @rs: The reservation to remove |
| 509 | * | 588 | * |
| 510 | */ | 589 | */ |
| 511 | static void __rs_deltree(struct gfs2_blkreserv *rs) | 590 | static void __rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs) |
| 512 | { | 591 | { |
| 513 | struct gfs2_rgrpd *rgd; | 592 | struct gfs2_rgrpd *rgd; |
| 514 | 593 | ||
| 515 | if (!gfs2_rs_active(rs)) | 594 | if (!gfs2_rs_active(rs)) |
| 516 | return; | 595 | return; |
| 517 | 596 | ||
| 518 | rgd = rs->rs_rgd; | 597 | rgd = rs->rs_rbm.rgd; |
| 519 | /* We can't do this: The reason is that when the rgrp is invalidated, | 598 | trace_gfs2_rs(rs, TRACE_RS_TREEDEL); |
| 520 | it's in the "middle" of acquiring the glock, but the HOLDER bit | 599 | rb_erase(&rs->rs_node, &rgd->rd_rstree); |
| 521 | isn't set yet: | 600 | RB_CLEAR_NODE(&rs->rs_node); |
| 522 | BUG_ON(!gfs2_glock_is_locked_by_me(rs->rs_rgd->rd_gl));*/ | ||
| 523 | trace_gfs2_rs(NULL, rs, TRACE_RS_TREEDEL); | ||
| 524 | |||
| 525 | if (!RB_EMPTY_ROOT(&rgd->rd_rstree)) | ||
| 526 | rb_erase(&rs->rs_node, &rgd->rd_rstree); | ||
| 527 | BUG_ON(!rgd->rd_rs_cnt); | ||
| 528 | rgd->rd_rs_cnt--; | ||
| 529 | 601 | ||
| 530 | if (rs->rs_free) { | 602 | if (rs->rs_free) { |
| 531 | /* return reserved blocks to the rgrp and the ip */ | 603 | /* return reserved blocks to the rgrp and the ip */ |
| 532 | BUG_ON(rs->rs_rgd->rd_reserved < rs->rs_free); | 604 | BUG_ON(rs->rs_rbm.rgd->rd_reserved < rs->rs_free); |
| 533 | rs->rs_rgd->rd_reserved -= rs->rs_free; | 605 | rs->rs_rbm.rgd->rd_reserved -= rs->rs_free; |
| 534 | rs->rs_free = 0; | 606 | rs->rs_free = 0; |
| 535 | clear_bit(GBF_FULL, &rs->rs_bi->bi_flags); | 607 | clear_bit(GBF_FULL, &rs->rs_rbm.bi->bi_flags); |
| 536 | smp_mb__after_clear_bit(); | 608 | smp_mb__after_clear_bit(); |
| 537 | } | 609 | } |
| 538 | /* We can't change any of the step 1 or step 2 components of the rs. | ||
| 539 | E.g. We can't set rs_rgd to NULL because the rgd glock is held and | ||
| 540 | dequeued through this pointer. | ||
| 541 | Can't: atomic_set(&rs->rs_sizehint, 0); | ||
| 542 | Can't: rs->rs_requested = 0; | ||
| 543 | Can't: rs->rs_rgd = NULL;*/ | ||
| 544 | rs->rs_bi = NULL; | ||
| 545 | rs->rs_biblk = 0; | ||
| 546 | } | 610 | } |
| 547 | 611 | ||
| 548 | /** | 612 | /** |
| @@ -550,17 +614,16 @@ static void __rs_deltree(struct gfs2_blkreserv *rs) | |||
| 550 | * @rs: The reservation to remove | 614 | * @rs: The reservation to remove |
| 551 | * | 615 | * |
| 552 | */ | 616 | */ |
| 553 | void gfs2_rs_deltree(struct gfs2_blkreserv *rs) | 617 | void gfs2_rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs) |
| 554 | { | 618 | { |
| 555 | struct gfs2_rgrpd *rgd; | 619 | struct gfs2_rgrpd *rgd; |
| 556 | 620 | ||
| 557 | if (!gfs2_rs_active(rs)) | 621 | rgd = rs->rs_rbm.rgd; |
| 558 | return; | 622 | if (rgd) { |
| 559 | 623 | spin_lock(&rgd->rd_rsspin); | |
| 560 | rgd = rs->rs_rgd; | 624 | __rs_deltree(ip, rs); |
| 561 | spin_lock(&rgd->rd_rsspin); | 625 | spin_unlock(&rgd->rd_rsspin); |
| 562 | __rs_deltree(rs); | 626 | } |
| 563 | spin_unlock(&rgd->rd_rsspin); | ||
| 564 | } | 627 | } |
| 565 | 628 | ||
| 566 | /** | 629 | /** |
| @@ -572,8 +635,7 @@ void gfs2_rs_delete(struct gfs2_inode *ip) | |||
| 572 | { | 635 | { |
| 573 | down_write(&ip->i_rw_mutex); | 636 | down_write(&ip->i_rw_mutex); |
| 574 | if (ip->i_res) { | 637 | if (ip->i_res) { |
| 575 | gfs2_rs_deltree(ip->i_res); | 638 | gfs2_rs_deltree(ip, ip->i_res); |
| 576 | trace_gfs2_rs(ip, ip->i_res, TRACE_RS_DELETE); | ||
| 577 | BUG_ON(ip->i_res->rs_free); | 639 | BUG_ON(ip->i_res->rs_free); |
| 578 | kmem_cache_free(gfs2_rsrv_cachep, ip->i_res); | 640 | kmem_cache_free(gfs2_rsrv_cachep, ip->i_res); |
| 579 | ip->i_res = NULL; | 641 | ip->i_res = NULL; |
| @@ -597,7 +659,7 @@ static void return_all_reservations(struct gfs2_rgrpd *rgd) | |||
| 597 | spin_lock(&rgd->rd_rsspin); | 659 | spin_lock(&rgd->rd_rsspin); |
| 598 | while ((n = rb_first(&rgd->rd_rstree))) { | 660 | while ((n = rb_first(&rgd->rd_rstree))) { |
| 599 | rs = rb_entry(n, struct gfs2_blkreserv, rs_node); | 661 | rs = rb_entry(n, struct gfs2_blkreserv, rs_node); |
| 600 | __rs_deltree(rs); | 662 | __rs_deltree(NULL, rs); |
| 601 | } | 663 | } |
| 602 | spin_unlock(&rgd->rd_rsspin); | 664 | spin_unlock(&rgd->rd_rsspin); |
| 603 | } | 665 | } |
| @@ -1270,211 +1332,276 @@ out: | |||
| 1270 | 1332 | ||
| 1271 | /** | 1333 | /** |
| 1272 | * rs_insert - insert a new multi-block reservation into the rgrp's rb_tree | 1334 | * rs_insert - insert a new multi-block reservation into the rgrp's rb_tree |
| 1273 | * @bi: the bitmap with the blocks | ||
| 1274 | * @ip: the inode structure | 1335 | * @ip: the inode structure |
| 1275 | * @biblk: the 32-bit block number relative to the start of the bitmap | ||
| 1276 | * @amount: the number of blocks to reserve | ||
| 1277 | * | 1336 | * |
| 1278 | * Returns: NULL - reservation was already taken, so not inserted | ||
| 1279 | * pointer to the inserted reservation | ||
| 1280 | */ | 1337 | */ |
| 1281 | static struct gfs2_blkreserv *rs_insert(struct gfs2_bitmap *bi, | 1338 | static void rs_insert(struct gfs2_inode *ip) |
| 1282 | struct gfs2_inode *ip, u32 biblk, | ||
| 1283 | int amount) | ||
| 1284 | { | 1339 | { |
| 1285 | struct rb_node **newn, *parent = NULL; | 1340 | struct rb_node **newn, *parent = NULL; |
| 1286 | int rc; | 1341 | int rc; |
| 1287 | struct gfs2_blkreserv *rs = ip->i_res; | 1342 | struct gfs2_blkreserv *rs = ip->i_res; |
| 1288 | struct gfs2_rgrpd *rgd = rs->rs_rgd; | 1343 | struct gfs2_rgrpd *rgd = rs->rs_rbm.rgd; |
| 1289 | u64 fsblock = gfs2_bi2rgd_blk(bi, biblk) + rgd->rd_data0; | 1344 | u64 fsblock = gfs2_rbm_to_block(&rs->rs_rbm); |
| 1345 | |||
| 1346 | BUG_ON(gfs2_rs_active(rs)); | ||
| 1290 | 1347 | ||
| 1291 | spin_lock(&rgd->rd_rsspin); | 1348 | spin_lock(&rgd->rd_rsspin); |
| 1292 | newn = &rgd->rd_rstree.rb_node; | 1349 | newn = &rgd->rd_rstree.rb_node; |
| 1293 | BUG_ON(!ip->i_res); | ||
| 1294 | BUG_ON(gfs2_rs_active(rs)); | ||
| 1295 | /* Figure out where to put new node */ | ||
| 1296 | /*BUG_ON(!gfs2_glock_is_locked_by_me(rgd->rd_gl));*/ | ||
| 1297 | while (*newn) { | 1350 | while (*newn) { |
| 1298 | struct gfs2_blkreserv *cur = | 1351 | struct gfs2_blkreserv *cur = |
| 1299 | rb_entry(*newn, struct gfs2_blkreserv, rs_node); | 1352 | rb_entry(*newn, struct gfs2_blkreserv, rs_node); |
| 1300 | 1353 | ||
| 1301 | parent = *newn; | 1354 | parent = *newn; |
| 1302 | rc = rs_cmp(fsblock, amount, cur); | 1355 | rc = rs_cmp(fsblock, rs->rs_free, cur); |
| 1303 | if (rc > 0) | 1356 | if (rc > 0) |
| 1304 | newn = &((*newn)->rb_right); | 1357 | newn = &((*newn)->rb_right); |
| 1305 | else if (rc < 0) | 1358 | else if (rc < 0) |
| 1306 | newn = &((*newn)->rb_left); | 1359 | newn = &((*newn)->rb_left); |
| 1307 | else { | 1360 | else { |
| 1308 | spin_unlock(&rgd->rd_rsspin); | 1361 | spin_unlock(&rgd->rd_rsspin); |
| 1309 | return NULL; /* reservation already in use */ | 1362 | WARN_ON(1); |
| 1363 | return; | ||
| 1310 | } | 1364 | } |
| 1311 | } | 1365 | } |
| 1312 | 1366 | ||
| 1313 | /* Do our reservation work */ | ||
| 1314 | rs = ip->i_res; | ||
| 1315 | rs->rs_free = amount; | ||
| 1316 | rs->rs_biblk = biblk; | ||
| 1317 | rs->rs_bi = bi; | ||
| 1318 | rb_link_node(&rs->rs_node, parent, newn); | 1367 | rb_link_node(&rs->rs_node, parent, newn); |
| 1319 | rb_insert_color(&rs->rs_node, &rgd->rd_rstree); | 1368 | rb_insert_color(&rs->rs_node, &rgd->rd_rstree); |
| 1320 | 1369 | ||
| 1321 | /* Do our inode accounting for the reservation */ | ||
| 1322 | /*BUG_ON(!gfs2_glock_is_locked_by_me(ip->i_gl));*/ | ||
| 1323 | |||
| 1324 | /* Do our rgrp accounting for the reservation */ | 1370 | /* Do our rgrp accounting for the reservation */ |
| 1325 | rgd->rd_reserved += amount; /* blocks reserved */ | 1371 | rgd->rd_reserved += rs->rs_free; /* blocks reserved */ |
| 1326 | rgd->rd_rs_cnt++; /* number of in-tree reservations */ | ||
| 1327 | spin_unlock(&rgd->rd_rsspin); | 1372 | spin_unlock(&rgd->rd_rsspin); |
| 1328 | trace_gfs2_rs(ip, rs, TRACE_RS_INSERT); | 1373 | trace_gfs2_rs(rs, TRACE_RS_INSERT); |
| 1329 | return rs; | ||
| 1330 | } | ||
| 1331 | |||
| 1332 | /** | ||
| 1333 | * unclaimed_blocks - return number of blocks that aren't spoken for | ||
| 1334 | */ | ||
| 1335 | static u32 unclaimed_blocks(struct gfs2_rgrpd *rgd) | ||
| 1336 | { | ||
| 1337 | return rgd->rd_free_clone - rgd->rd_reserved; | ||
| 1338 | } | 1374 | } |
| 1339 | 1375 | ||
| 1340 | /** | 1376 | /** |
| 1341 | * rg_mblk_search - find a group of multiple free blocks | 1377 | * rg_mblk_search - find a group of multiple free blocks to form a reservation |
| 1342 | * @rgd: the resource group descriptor | 1378 | * @rgd: the resource group descriptor |
| 1343 | * @rs: the block reservation | ||
| 1344 | * @ip: pointer to the inode for which we're reserving blocks | 1379 | * @ip: pointer to the inode for which we're reserving blocks |
| 1380 | * @requested: number of blocks required for this allocation | ||
| 1345 | * | 1381 | * |
| 1346 | * This is very similar to rgblk_search, except we're looking for whole | ||
| 1347 | * 64-bit words that represent a chunk of 32 free blocks. I'm only focusing | ||
| 1348 | * on aligned dwords for speed's sake. | ||
| 1349 | * | ||
| 1350 | * Returns: 0 if successful or BFITNOENT if there isn't enough free space | ||
| 1351 | */ | 1382 | */ |
| 1352 | 1383 | ||
| 1353 | static int rg_mblk_search(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) | 1384 | static void rg_mblk_search(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip, |
| 1385 | unsigned requested) | ||
| 1354 | { | 1386 | { |
| 1355 | struct gfs2_bitmap *bi = rgd->rd_bits; | 1387 | struct gfs2_rbm rbm = { .rgd = rgd, }; |
| 1356 | const u32 length = rgd->rd_length; | 1388 | u64 goal; |
| 1357 | u32 blk; | 1389 | struct gfs2_blkreserv *rs = ip->i_res; |
| 1358 | unsigned int buf, x, search_bytes; | 1390 | u32 extlen; |
| 1359 | u8 *buffer = NULL; | 1391 | u32 free_blocks = rgd->rd_free_clone - rgd->rd_reserved; |
| 1360 | u8 *ptr, *end, *nonzero; | 1392 | int ret; |
| 1361 | u32 goal, rsv_bytes; | 1393 | |
| 1362 | struct gfs2_blkreserv *rs; | 1394 | extlen = max_t(u32, atomic_read(&rs->rs_sizehint), requested); |
| 1363 | u32 best_rs_bytes, unclaimed; | 1395 | extlen = clamp(extlen, RGRP_RSRV_MINBLKS, free_blocks); |
| 1364 | int best_rs_blocks; | 1396 | if ((rgd->rd_free_clone < rgd->rd_reserved) || (free_blocks < extlen)) |
| 1397 | return; | ||
| 1365 | 1398 | ||
| 1366 | /* Find bitmap block that contains bits for goal block */ | 1399 | /* Find bitmap block that contains bits for goal block */ |
| 1367 | if (rgrp_contains_block(rgd, ip->i_goal)) | 1400 | if (rgrp_contains_block(rgd, ip->i_goal)) |
| 1368 | goal = ip->i_goal - rgd->rd_data0; | 1401 | goal = ip->i_goal; |
| 1369 | else | 1402 | else |
| 1370 | goal = rgd->rd_last_alloc; | 1403 | goal = rgd->rd_last_alloc + rgd->rd_data0; |
| 1371 | for (buf = 0; buf < length; buf++) { | 1404 | |
| 1372 | bi = rgd->rd_bits + buf; | 1405 | if (WARN_ON(gfs2_rbm_from_block(&rbm, goal))) |
| 1373 | /* Convert scope of "goal" from rgrp-wide to within | 1406 | return; |
| 1374 | found bit block */ | 1407 | |
| 1375 | if (goal < (bi->bi_start + bi->bi_len) * GFS2_NBBY) { | 1408 | ret = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, extlen, ip, true); |
| 1376 | goal -= bi->bi_start * GFS2_NBBY; | 1409 | if (ret == 0) { |
| 1377 | goto do_search; | 1410 | rs->rs_rbm = rbm; |
| 1378 | } | 1411 | rs->rs_free = extlen; |
| 1412 | rs->rs_inum = ip->i_no_addr; | ||
| 1413 | rs_insert(ip); | ||
| 1379 | } | 1414 | } |
| 1380 | buf = 0; | 1415 | } |
| 1381 | goal = 0; | 1416 | |
| 1382 | 1417 | /** | |
| 1383 | do_search: | 1418 | * gfs2_next_unreserved_block - Return next block that is not reserved |
| 1384 | best_rs_blocks = max_t(int, atomic_read(&ip->i_res->rs_sizehint), | 1419 | * @rgd: The resource group |
| 1385 | (RGRP_RSRV_MINBLKS * rgd->rd_length)); | 1420 | * @block: The starting block |
| 1386 | best_rs_bytes = (best_rs_blocks * | 1421 | * @length: The required length |
| 1387 | (1 + (RSRV_CONTENTION_FACTOR * rgd->rd_rs_cnt))) / | 1422 | * @ip: Ignore any reservations for this inode |
| 1388 | GFS2_NBBY; /* 1 + is for our not-yet-created reservation */ | 1423 | * |
| 1389 | best_rs_bytes = ALIGN(best_rs_bytes, sizeof(u64)); | 1424 | * If the block does not appear in any reservation, then return the |
| 1390 | unclaimed = unclaimed_blocks(rgd); | 1425 | * block number unchanged. If it does appear in the reservation, then |
| 1391 | if (best_rs_bytes * GFS2_NBBY > unclaimed) | 1426 | * keep looking through the tree of reservations in order to find the |
| 1392 | best_rs_bytes = unclaimed >> GFS2_BIT_SIZE; | 1427 | * first block number which is not reserved. |
| 1393 | 1428 | */ | |
| 1394 | for (x = 0; x <= length; x++) { | ||
| 1395 | bi = rgd->rd_bits + buf; | ||
| 1396 | 1429 | ||
| 1397 | if (test_bit(GBF_FULL, &bi->bi_flags)) | 1430 | static u64 gfs2_next_unreserved_block(struct gfs2_rgrpd *rgd, u64 block, |
| 1398 | goto skip; | 1431 | u32 length, |
| 1432 | const struct gfs2_inode *ip) | ||
| 1433 | { | ||
| 1434 | struct gfs2_blkreserv *rs; | ||
| 1435 | struct rb_node *n; | ||
| 1436 | int rc; | ||
| 1399 | 1437 | ||
| 1400 | WARN_ON(!buffer_uptodate(bi->bi_bh)); | 1438 | spin_lock(&rgd->rd_rsspin); |
| 1401 | if (bi->bi_clone) | 1439 | n = rgd->rd_rstree.rb_node; |
| 1402 | buffer = bi->bi_clone + bi->bi_offset; | 1440 | while (n) { |
| 1441 | rs = rb_entry(n, struct gfs2_blkreserv, rs_node); | ||
| 1442 | rc = rs_cmp(block, length, rs); | ||
| 1443 | if (rc < 0) | ||
| 1444 | n = n->rb_left; | ||
| 1445 | else if (rc > 0) | ||
| 1446 | n = n->rb_right; | ||
| 1403 | else | 1447 | else |
| 1404 | buffer = bi->bi_bh->b_data + bi->bi_offset; | 1448 | break; |
| 1405 | 1449 | } | |
| 1406 | /* We have to keep the reservations aligned on u64 boundaries | 1450 | |
| 1407 | otherwise we could get situations where a byte can't be | 1451 | if (n) { |
| 1408 | used because it's after a reservation, but a free bit still | 1452 | while ((rs_cmp(block, length, rs) == 0) && (ip->i_res != rs)) { |
| 1409 | is within the reservation's area. */ | 1453 | block = gfs2_rbm_to_block(&rs->rs_rbm) + rs->rs_free; |
| 1410 | ptr = buffer + ALIGN(goal >> GFS2_BIT_SIZE, sizeof(u64)); | 1454 | n = n->rb_right; |
| 1411 | end = (buffer + bi->bi_len); | 1455 | if (n == NULL) |
| 1412 | while (ptr < end) { | 1456 | break; |
| 1413 | rsv_bytes = 0; | 1457 | rs = rb_entry(n, struct gfs2_blkreserv, rs_node); |
| 1414 | if ((ptr + best_rs_bytes) <= end) | ||
| 1415 | search_bytes = best_rs_bytes; | ||
| 1416 | else | ||
| 1417 | search_bytes = end - ptr; | ||
| 1418 | BUG_ON(!search_bytes); | ||
| 1419 | nonzero = memchr_inv(ptr, 0, search_bytes); | ||
| 1420 | /* If the lot is all zeroes, reserve the whole size. If | ||
| 1421 | there's enough zeroes to satisfy the request, use | ||
| 1422 | what we can. If there's not enough, keep looking. */ | ||
| 1423 | if (nonzero == NULL) | ||
| 1424 | rsv_bytes = search_bytes; | ||
| 1425 | else if ((nonzero - ptr) * GFS2_NBBY >= | ||
| 1426 | ip->i_res->rs_requested) | ||
| 1427 | rsv_bytes = (nonzero - ptr); | ||
| 1428 | |||
| 1429 | if (rsv_bytes) { | ||
| 1430 | blk = ((ptr - buffer) * GFS2_NBBY); | ||
| 1431 | BUG_ON(blk >= bi->bi_len * GFS2_NBBY); | ||
| 1432 | rs = rs_insert(bi, ip, blk, | ||
| 1433 | rsv_bytes * GFS2_NBBY); | ||
| 1434 | if (IS_ERR(rs)) | ||
| 1435 | return PTR_ERR(rs); | ||
| 1436 | if (rs) | ||
| 1437 | return 0; | ||
| 1438 | } | ||
| 1439 | ptr += ALIGN(search_bytes, sizeof(u64)); | ||
| 1440 | } | 1458 | } |
| 1441 | skip: | ||
| 1442 | /* Try next bitmap block (wrap back to rgrp header | ||
| 1443 | if at end) */ | ||
| 1444 | buf++; | ||
| 1445 | buf %= length; | ||
| 1446 | goal = 0; | ||
| 1447 | } | 1459 | } |
| 1448 | 1460 | ||
| 1449 | return BFITNOENT; | 1461 | spin_unlock(&rgd->rd_rsspin); |
| 1462 | return block; | ||
| 1450 | } | 1463 | } |
| 1451 | 1464 | ||
| 1452 | /** | 1465 | /** |
| 1453 | * try_rgrp_fit - See if a given reservation will fit in a given RG | 1466 | * gfs2_reservation_check_and_update - Check for reservations during block alloc |
| 1454 | * @rgd: the RG data | 1467 | * @rbm: The current position in the resource group |
| 1455 | * @ip: the inode | 1468 | * @ip: The inode for which we are searching for blocks |
| 1469 | * @minext: The minimum extent length | ||
| 1456 | * | 1470 | * |
| 1457 | * If there's room for the requested blocks to be allocated from the RG: | 1471 | * This checks the current position in the rgrp to see whether there is |
| 1458 | * This will try to get a multi-block reservation first, and if that doesn't | 1472 | * a reservation covering this block. If not then this function is a |
| 1459 | * fit, it will take what it can. | 1473 | * no-op. If there is, then the position is moved to the end of the |
| 1474 | * contiguous reservation(s) so that we are pointing at the first | ||
| 1475 | * non-reserved block. | ||
| 1460 | * | 1476 | * |
| 1461 | * Returns: 1 on success (it fits), 0 on failure (it doesn't fit) | 1477 | * Returns: 0 if no reservation, 1 if @rbm has changed, otherwise an error |
| 1462 | */ | 1478 | */ |
| 1463 | 1479 | ||
| 1464 | static int try_rgrp_fit(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) | 1480 | static int gfs2_reservation_check_and_update(struct gfs2_rbm *rbm, |
| 1481 | const struct gfs2_inode *ip, | ||
| 1482 | u32 minext) | ||
| 1465 | { | 1483 | { |
| 1466 | struct gfs2_blkreserv *rs = ip->i_res; | 1484 | u64 block = gfs2_rbm_to_block(rbm); |
| 1485 | u32 extlen = 1; | ||
| 1486 | u64 nblock; | ||
| 1487 | int ret; | ||
| 1467 | 1488 | ||
| 1468 | if (rgd->rd_flags & (GFS2_RGF_NOALLOC | GFS2_RDF_ERROR)) | 1489 | /* |
| 1490 | * If we have a minimum extent length, then skip over any extent | ||
| 1491 | * which is less than the min extent length in size. | ||
| 1492 | */ | ||
| 1493 | if (minext) { | ||
| 1494 | extlen = gfs2_free_extlen(rbm, minext); | ||
| 1495 | nblock = block + extlen; | ||
| 1496 | if (extlen < minext) | ||
| 1497 | goto fail; | ||
| 1498 | } | ||
| 1499 | |||
| 1500 | /* | ||
| 1501 | * Check the extent which has been found against the reservations | ||
| 1502 | * and skip if parts of it are already reserved | ||
| 1503 | */ | ||
| 1504 | nblock = gfs2_next_unreserved_block(rbm->rgd, block, extlen, ip); | ||
| 1505 | if (nblock == block) | ||
| 1469 | return 0; | 1506 | return 0; |
| 1470 | /* Look for a multi-block reservation. */ | 1507 | fail: |
| 1471 | if (unclaimed_blocks(rgd) >= RGRP_RSRV_MINBLKS && | 1508 | ret = gfs2_rbm_from_block(rbm, nblock); |
| 1472 | rg_mblk_search(rgd, ip) != BFITNOENT) | 1509 | if (ret < 0) |
| 1473 | return 1; | 1510 | return ret; |
| 1474 | if (unclaimed_blocks(rgd) >= rs->rs_requested) | 1511 | return 1; |
| 1475 | return 1; | 1512 | } |
| 1476 | 1513 | ||
| 1477 | return 0; | 1514 | /** |
| 1515 | * gfs2_rbm_find - Look for blocks of a particular state | ||
| 1516 | * @rbm: Value/result starting position and final position | ||
| 1517 | * @state: The state which we want to find | ||
| 1518 | * @minext: The requested extent length (0 for a single block) | ||
| 1519 | * @ip: If set, check for reservations | ||
| 1520 | * @nowrap: Stop looking at the end of the rgrp, rather than wrapping | ||
| 1521 | * around until we've reached the starting point. | ||
| 1522 | * | ||
| 1523 | * Side effects: | ||
| 1524 | * - If looking for free blocks, we set GBF_FULL on each bitmap which | ||
| 1525 | * has no free blocks in it. | ||
| 1526 | * | ||
| 1527 | * Returns: 0 on success, -ENOSPC if there is no block of the requested state | ||
| 1528 | */ | ||
| 1529 | |||
| 1530 | static int gfs2_rbm_find(struct gfs2_rbm *rbm, u8 state, u32 minext, | ||
| 1531 | const struct gfs2_inode *ip, bool nowrap) | ||
| 1532 | { | ||
| 1533 | struct buffer_head *bh; | ||
| 1534 | struct gfs2_bitmap *initial_bi; | ||
| 1535 | u32 initial_offset; | ||
| 1536 | u32 offset; | ||
| 1537 | u8 *buffer; | ||
| 1538 | int index; | ||
| 1539 | int n = 0; | ||
| 1540 | int iters = rbm->rgd->rd_length; | ||
| 1541 | int ret; | ||
| 1542 | |||
| 1543 | /* If we are not starting at the beginning of a bitmap, then we | ||
| 1544 | * need to add one to the bitmap count to ensure that we search | ||
| 1545 | * the starting bitmap twice. | ||
| 1546 | */ | ||
| 1547 | if (rbm->offset != 0) | ||
| 1548 | iters++; | ||
| 1549 | |||
| 1550 | while(1) { | ||
| 1551 | if (test_bit(GBF_FULL, &rbm->bi->bi_flags) && | ||
| 1552 | (state == GFS2_BLKST_FREE)) | ||
| 1553 | goto next_bitmap; | ||
| 1554 | |||
| 1555 | bh = rbm->bi->bi_bh; | ||
| 1556 | buffer = bh->b_data + rbm->bi->bi_offset; | ||
| 1557 | WARN_ON(!buffer_uptodate(bh)); | ||
| 1558 | if (state != GFS2_BLKST_UNLINKED && rbm->bi->bi_clone) | ||
| 1559 | buffer = rbm->bi->bi_clone + rbm->bi->bi_offset; | ||
| 1560 | initial_offset = rbm->offset; | ||
| 1561 | offset = gfs2_bitfit(buffer, rbm->bi->bi_len, rbm->offset, state); | ||
| 1562 | if (offset == BFITNOENT) | ||
| 1563 | goto bitmap_full; | ||
| 1564 | rbm->offset = offset; | ||
| 1565 | if (ip == NULL) | ||
| 1566 | return 0; | ||
| 1567 | |||
| 1568 | initial_bi = rbm->bi; | ||
| 1569 | ret = gfs2_reservation_check_and_update(rbm, ip, minext); | ||
| 1570 | if (ret == 0) | ||
| 1571 | return 0; | ||
| 1572 | if (ret > 0) { | ||
| 1573 | n += (rbm->bi - initial_bi); | ||
| 1574 | goto next_iter; | ||
| 1575 | } | ||
| 1576 | if (ret == -E2BIG) { | ||
| 1577 | index = 0; | ||
| 1578 | rbm->offset = 0; | ||
| 1579 | n += (rbm->bi - initial_bi); | ||
| 1580 | goto res_covered_end_of_rgrp; | ||
| 1581 | } | ||
| 1582 | return ret; | ||
| 1583 | |||
| 1584 | bitmap_full: /* Mark bitmap as full and fall through */ | ||
| 1585 | if ((state == GFS2_BLKST_FREE) && initial_offset == 0) | ||
| 1586 | set_bit(GBF_FULL, &rbm->bi->bi_flags); | ||
| 1587 | |||
| 1588 | next_bitmap: /* Find next bitmap in the rgrp */ | ||
| 1589 | rbm->offset = 0; | ||
| 1590 | index = rbm->bi - rbm->rgd->rd_bits; | ||
| 1591 | index++; | ||
| 1592 | if (index == rbm->rgd->rd_length) | ||
| 1593 | index = 0; | ||
| 1594 | res_covered_end_of_rgrp: | ||
| 1595 | rbm->bi = &rbm->rgd->rd_bits[index]; | ||
| 1596 | if ((index == 0) && nowrap) | ||
| 1597 | break; | ||
| 1598 | n++; | ||
| 1599 | next_iter: | ||
| 1600 | if (n >= iters) | ||
| 1601 | break; | ||
| 1602 | } | ||
| 1603 | |||
| 1604 | return -ENOSPC; | ||
| 1478 | } | 1605 | } |
| 1479 | 1606 | ||
| 1480 | /** | 1607 | /** |
| @@ -1489,34 +1616,33 @@ static int try_rgrp_fit(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip) | |||
| 1489 | 1616 | ||
| 1490 | static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip) | 1617 | static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip) |
| 1491 | { | 1618 | { |
| 1492 | u32 goal = 0, block; | 1619 | u64 block; |
| 1493 | u64 no_addr; | ||
| 1494 | struct gfs2_sbd *sdp = rgd->rd_sbd; | 1620 | struct gfs2_sbd *sdp = rgd->rd_sbd; |
| 1495 | struct gfs2_glock *gl; | 1621 | struct gfs2_glock *gl; |
| 1496 | struct gfs2_inode *ip; | 1622 | struct gfs2_inode *ip; |
| 1497 | int error; | 1623 | int error; |
| 1498 | int found = 0; | 1624 | int found = 0; |
| 1499 | struct gfs2_bitmap *bi; | 1625 | struct gfs2_rbm rbm = { .rgd = rgd, .bi = rgd->rd_bits, .offset = 0 }; |
| 1500 | 1626 | ||
| 1501 | while (goal < rgd->rd_data) { | 1627 | while (1) { |
| 1502 | down_write(&sdp->sd_log_flush_lock); | 1628 | down_write(&sdp->sd_log_flush_lock); |
| 1503 | block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, &bi); | 1629 | error = gfs2_rbm_find(&rbm, GFS2_BLKST_UNLINKED, 0, NULL, true); |
| 1504 | up_write(&sdp->sd_log_flush_lock); | 1630 | up_write(&sdp->sd_log_flush_lock); |
| 1505 | if (block == BFITNOENT) | 1631 | if (error == -ENOSPC) |
| 1632 | break; | ||
| 1633 | if (WARN_ON_ONCE(error)) | ||
| 1506 | break; | 1634 | break; |
| 1507 | 1635 | ||
| 1508 | block = gfs2_bi2rgd_blk(bi, block); | 1636 | block = gfs2_rbm_to_block(&rbm); |
| 1509 | /* rgblk_search can return a block < goal, so we need to | 1637 | if (gfs2_rbm_from_block(&rbm, block + 1)) |
| 1510 | keep it marching forward. */ | 1638 | break; |
| 1511 | no_addr = block + rgd->rd_data0; | 1639 | if (*last_unlinked != NO_BLOCK && block <= *last_unlinked) |
| 1512 | goal = max(block + 1, goal + 1); | ||
| 1513 | if (*last_unlinked != NO_BLOCK && no_addr <= *last_unlinked) | ||
| 1514 | continue; | 1640 | continue; |
| 1515 | if (no_addr == skip) | 1641 | if (block == skip) |
| 1516 | continue; | 1642 | continue; |
| 1517 | *last_unlinked = no_addr; | 1643 | *last_unlinked = block; |
| 1518 | 1644 | ||
| 1519 | error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &gl); | 1645 | error = gfs2_glock_get(sdp, block, &gfs2_inode_glops, CREATE, &gl); |
| 1520 | if (error) | 1646 | if (error) |
| 1521 | continue; | 1647 | continue; |
| 1522 | 1648 | ||
| @@ -1543,6 +1669,19 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip | |||
| 1543 | return; | 1669 | return; |
| 1544 | } | 1670 | } |
| 1545 | 1671 | ||
| 1672 | static bool gfs2_select_rgrp(struct gfs2_rgrpd **pos, const struct gfs2_rgrpd *begin) | ||
| 1673 | { | ||
| 1674 | struct gfs2_rgrpd *rgd = *pos; | ||
| 1675 | |||
| 1676 | rgd = gfs2_rgrpd_get_next(rgd); | ||
| 1677 | if (rgd == NULL) | ||
| 1678 | rgd = gfs2_rgrpd_get_next(NULL); | ||
| 1679 | *pos = rgd; | ||
| 1680 | if (rgd != begin) /* If we didn't wrap */ | ||
| 1681 | return true; | ||
| 1682 | return false; | ||
| 1683 | } | ||
| 1684 | |||
| 1546 | /** | 1685 | /** |
| 1547 | * gfs2_inplace_reserve - Reserve space in the filesystem | 1686 | * gfs2_inplace_reserve - Reserve space in the filesystem |
| 1548 | * @ip: the inode to reserve space for | 1687 | * @ip: the inode to reserve space for |
| @@ -1562,103 +1701,96 @@ int gfs2_inplace_reserve(struct gfs2_inode *ip, u32 requested) | |||
| 1562 | 1701 | ||
| 1563 | if (sdp->sd_args.ar_rgrplvb) | 1702 | if (sdp->sd_args.ar_rgrplvb) |
| 1564 | flags |= GL_SKIP; | 1703 | flags |= GL_SKIP; |
| 1565 | rs->rs_requested = requested; | 1704 | if (gfs2_assert_warn(sdp, requested)) |
| 1566 | if (gfs2_assert_warn(sdp, requested)) { | 1705 | return -EINVAL; |
| 1567 | error = -EINVAL; | ||
| 1568 | goto out; | ||
| 1569 | } | ||
| 1570 | if (gfs2_rs_active(rs)) { | 1706 | if (gfs2_rs_active(rs)) { |
| 1571 | begin = rs->rs_rgd; | 1707 | begin = rs->rs_rbm.rgd; |
| 1572 | flags = 0; /* Yoda: Do or do not. There is no try */ | 1708 | flags = 0; /* Yoda: Do or do not. There is no try */ |
| 1573 | } else if (ip->i_rgd && rgrp_contains_block(ip->i_rgd, ip->i_goal)) { | 1709 | } else if (ip->i_rgd && rgrp_contains_block(ip->i_rgd, ip->i_goal)) { |
| 1574 | rs->rs_rgd = begin = ip->i_rgd; | 1710 | rs->rs_rbm.rgd = begin = ip->i_rgd; |
| 1575 | } else { | 1711 | } else { |
| 1576 | rs->rs_rgd = begin = gfs2_blk2rgrpd(sdp, ip->i_goal, 1); | 1712 | rs->rs_rbm.rgd = begin = gfs2_blk2rgrpd(sdp, ip->i_goal, 1); |
| 1577 | } | 1713 | } |
| 1578 | if (rs->rs_rgd == NULL) | 1714 | if (rs->rs_rbm.rgd == NULL) |
| 1579 | return -EBADSLT; | 1715 | return -EBADSLT; |
| 1580 | 1716 | ||
| 1581 | while (loops < 3) { | 1717 | while (loops < 3) { |
| 1582 | rg_locked = 0; | 1718 | rg_locked = 1; |
| 1583 | 1719 | ||
| 1584 | if (gfs2_glock_is_locked_by_me(rs->rs_rgd->rd_gl)) { | 1720 | if (!gfs2_glock_is_locked_by_me(rs->rs_rbm.rgd->rd_gl)) { |
| 1585 | rg_locked = 1; | 1721 | rg_locked = 0; |
| 1586 | error = 0; | 1722 | error = gfs2_glock_nq_init(rs->rs_rbm.rgd->rd_gl, |
| 1587 | } else if (!loops && !gfs2_rs_active(rs) && | ||
| 1588 | rs->rs_rgd->rd_rs_cnt > RGRP_RSRV_MAX_CONTENDERS) { | ||
| 1589 | /* If the rgrp already is maxed out for contenders, | ||
| 1590 | we can eliminate it as a "first pass" without even | ||
| 1591 | requesting the rgrp glock. */ | ||
| 1592 | error = GLR_TRYFAILED; | ||
| 1593 | } else { | ||
| 1594 | error = gfs2_glock_nq_init(rs->rs_rgd->rd_gl, | ||
| 1595 | LM_ST_EXCLUSIVE, flags, | 1723 | LM_ST_EXCLUSIVE, flags, |
| 1596 | &rs->rs_rgd_gh); | 1724 | &rs->rs_rgd_gh); |
| 1597 | if (!error && sdp->sd_args.ar_rgrplvb) { | 1725 | if (error == GLR_TRYFAILED) |
| 1598 | error = update_rgrp_lvb(rs->rs_rgd); | 1726 | goto next_rgrp; |
| 1599 | if (error) { | 1727 | if (unlikely(error)) |
| 1728 | return error; | ||
| 1729 | if (sdp->sd_args.ar_rgrplvb) { | ||
| 1730 | error = update_rgrp_lvb(rs->rs_rbm.rgd); | ||
| 1731 | if (unlikely(error)) { | ||
| 1600 | gfs2_glock_dq_uninit(&rs->rs_rgd_gh); | 1732 | gfs2_glock_dq_uninit(&rs->rs_rgd_gh); |
| 1601 | return error; | 1733 | return error; |
| 1602 | } | 1734 | } |
| 1603 | } | 1735 | } |
| 1604 | } | 1736 | } |
| 1605 | switch (error) { | ||
| 1606 | case 0: | ||
| 1607 | if (gfs2_rs_active(rs)) { | ||
| 1608 | if (unclaimed_blocks(rs->rs_rgd) + | ||
| 1609 | rs->rs_free >= rs->rs_requested) { | ||
| 1610 | ip->i_rgd = rs->rs_rgd; | ||
| 1611 | return 0; | ||
| 1612 | } | ||
| 1613 | /* We have a multi-block reservation, but the | ||
| 1614 | rgrp doesn't have enough free blocks to | ||
| 1615 | satisfy the request. Free the reservation | ||
| 1616 | and look for a suitable rgrp. */ | ||
| 1617 | gfs2_rs_deltree(rs); | ||
| 1618 | } | ||
| 1619 | if (try_rgrp_fit(rs->rs_rgd, ip)) { | ||
| 1620 | if (sdp->sd_args.ar_rgrplvb) | ||
| 1621 | gfs2_rgrp_bh_get(rs->rs_rgd); | ||
| 1622 | ip->i_rgd = rs->rs_rgd; | ||
| 1623 | return 0; | ||
| 1624 | } | ||
| 1625 | if (rs->rs_rgd->rd_flags & GFS2_RDF_CHECK) { | ||
| 1626 | if (sdp->sd_args.ar_rgrplvb) | ||
| 1627 | gfs2_rgrp_bh_get(rs->rs_rgd); | ||
| 1628 | try_rgrp_unlink(rs->rs_rgd, &last_unlinked, | ||
| 1629 | ip->i_no_addr); | ||
| 1630 | } | ||
| 1631 | if (!rg_locked) | ||
| 1632 | gfs2_glock_dq_uninit(&rs->rs_rgd_gh); | ||
| 1633 | /* fall through */ | ||
| 1634 | case GLR_TRYFAILED: | ||
| 1635 | rs->rs_rgd = gfs2_rgrpd_get_next(rs->rs_rgd); | ||
| 1636 | rs->rs_rgd = rs->rs_rgd ? : begin; /* if NULL, wrap */ | ||
| 1637 | if (rs->rs_rgd != begin) /* If we didn't wrap */ | ||
| 1638 | break; | ||
| 1639 | 1737 | ||
| 1640 | flags &= ~LM_FLAG_TRY; | 1738 | /* Skip unuseable resource groups */ |
| 1641 | loops++; | 1739 | if (rs->rs_rbm.rgd->rd_flags & (GFS2_RGF_NOALLOC | GFS2_RDF_ERROR)) |
| 1642 | /* Check that fs hasn't grown if writing to rindex */ | 1740 | goto skip_rgrp; |
| 1643 | if (ip == GFS2_I(sdp->sd_rindex) && | 1741 | |
| 1644 | !sdp->sd_rindex_uptodate) { | 1742 | if (sdp->sd_args.ar_rgrplvb) |
| 1645 | error = gfs2_ri_update(ip); | 1743 | gfs2_rgrp_bh_get(rs->rs_rbm.rgd); |
| 1646 | if (error) | 1744 | |
| 1647 | goto out; | 1745 | /* Get a reservation if we don't already have one */ |
| 1648 | } else if (loops == 2) | 1746 | if (!gfs2_rs_active(rs)) |
| 1649 | /* Flushing the log may release space */ | 1747 | rg_mblk_search(rs->rs_rbm.rgd, ip, requested); |
| 1650 | gfs2_log_flush(sdp, NULL); | 1748 | |
| 1651 | break; | 1749 | /* Skip rgrps when we can't get a reservation on first pass */ |
| 1652 | default: | 1750 | if (!gfs2_rs_active(rs) && (loops < 1)) |
| 1653 | goto out; | 1751 | goto check_rgrp; |
| 1752 | |||
| 1753 | /* If rgrp has enough free space, use it */ | ||
| 1754 | if (rs->rs_rbm.rgd->rd_free_clone >= requested) { | ||
| 1755 | ip->i_rgd = rs->rs_rbm.rgd; | ||
| 1756 | return 0; | ||
| 1757 | } | ||
| 1758 | |||
| 1759 | /* Drop reservation, if we couldn't use reserved rgrp */ | ||
| 1760 | if (gfs2_rs_active(rs)) | ||
| 1761 | gfs2_rs_deltree(ip, rs); | ||
| 1762 | check_rgrp: | ||
| 1763 | /* Check for unlinked inodes which can be reclaimed */ | ||
| 1764 | if (rs->rs_rbm.rgd->rd_flags & GFS2_RDF_CHECK) | ||
| 1765 | try_rgrp_unlink(rs->rs_rbm.rgd, &last_unlinked, | ||
| 1766 | ip->i_no_addr); | ||
| 1767 | skip_rgrp: | ||
| 1768 | /* Unlock rgrp if required */ | ||
| 1769 | if (!rg_locked) | ||
| 1770 | gfs2_glock_dq_uninit(&rs->rs_rgd_gh); | ||
| 1771 | next_rgrp: | ||
| 1772 | /* Find the next rgrp, and continue looking */ | ||
| 1773 | if (gfs2_select_rgrp(&rs->rs_rbm.rgd, begin)) | ||
| 1774 | continue; | ||
| 1775 | |||
| 1776 | /* If we've scanned all the rgrps, but found no free blocks | ||
| 1777 | * then this checks for some less likely conditions before | ||
| 1778 | * trying again. | ||
| 1779 | */ | ||
| 1780 | flags &= ~LM_FLAG_TRY; | ||
| 1781 | loops++; | ||
| 1782 | /* Check that fs hasn't grown if writing to rindex */ | ||
| 1783 | if (ip == GFS2_I(sdp->sd_rindex) && !sdp->sd_rindex_uptodate) { | ||
| 1784 | error = gfs2_ri_update(ip); | ||
| 1785 | if (error) | ||
| 1786 | return error; | ||
| 1654 | } | 1787 | } |
| 1788 | /* Flushing the log may release space */ | ||
| 1789 | if (loops == 2) | ||
| 1790 | gfs2_log_flush(sdp, NULL); | ||
| 1655 | } | 1791 | } |
| 1656 | error = -ENOSPC; | ||
| 1657 | 1792 | ||
| 1658 | out: | 1793 | return -ENOSPC; |
| 1659 | if (error) | ||
| 1660 | rs->rs_requested = 0; | ||
| 1661 | return error; | ||
| 1662 | } | 1794 | } |
| 1663 | 1795 | ||
| 1664 | /** | 1796 | /** |
| @@ -1672,15 +1804,8 @@ void gfs2_inplace_release(struct gfs2_inode *ip) | |||
| 1672 | { | 1804 | { |
| 1673 | struct gfs2_blkreserv *rs = ip->i_res; | 1805 | struct gfs2_blkreserv *rs = ip->i_res; |
| 1674 | 1806 | ||
| 1675 | if (!rs) | ||
| 1676 | return; | ||
| 1677 | |||
| 1678 | if (!rs->rs_free) | ||
| 1679 | gfs2_rs_deltree(rs); | ||
| 1680 | |||
| 1681 | if (rs->rs_rgd_gh.gh_gl) | 1807 | if (rs->rs_rgd_gh.gh_gl) |
| 1682 | gfs2_glock_dq_uninit(&rs->rs_rgd_gh); | 1808 | gfs2_glock_dq_uninit(&rs->rs_rgd_gh); |
| 1683 | rs->rs_requested = 0; | ||
| 1684 | } | 1809 | } |
| 1685 | 1810 | ||
| 1686 | /** | 1811 | /** |
| @@ -1693,173 +1818,47 @@ void gfs2_inplace_release(struct gfs2_inode *ip) | |||
| 1693 | 1818 | ||
| 1694 | static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block) | 1819 | static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block) |
| 1695 | { | 1820 | { |
| 1696 | struct gfs2_bitmap *bi = NULL; | 1821 | struct gfs2_rbm rbm = { .rgd = rgd, }; |
| 1697 | u32 length, rgrp_block, buf_block; | 1822 | int ret; |
| 1698 | unsigned int buf; | ||
| 1699 | unsigned char type; | ||
| 1700 | |||
| 1701 | length = rgd->rd_length; | ||
| 1702 | rgrp_block = block - rgd->rd_data0; | ||
| 1703 | |||
| 1704 | for (buf = 0; buf < length; buf++) { | ||
| 1705 | bi = rgd->rd_bits + buf; | ||
| 1706 | if (rgrp_block < (bi->bi_start + bi->bi_len) * GFS2_NBBY) | ||
| 1707 | break; | ||
| 1708 | } | ||
| 1709 | |||
| 1710 | gfs2_assert(rgd->rd_sbd, buf < length); | ||
| 1711 | buf_block = rgrp_block - bi->bi_start * GFS2_NBBY; | ||
| 1712 | 1823 | ||
| 1713 | type = gfs2_testbit(rgd, bi->bi_bh->b_data + bi->bi_offset, | 1824 | ret = gfs2_rbm_from_block(&rbm, block); |
| 1714 | bi->bi_len, buf_block); | 1825 | WARN_ON_ONCE(ret != 0); |
| 1715 | 1826 | ||
| 1716 | return type; | 1827 | return gfs2_testbit(&rbm); |
| 1717 | } | 1828 | } |
| 1718 | 1829 | ||
| 1719 | /** | ||
| 1720 | * rgblk_search - find a block in @state | ||
| 1721 | * @rgd: the resource group descriptor | ||
| 1722 | * @goal: the goal block within the RG (start here to search for avail block) | ||
| 1723 | * @state: GFS2_BLKST_XXX the before-allocation state to find | ||
| 1724 | * @rbi: address of the pointer to the bitmap containing the block found | ||
| 1725 | * | ||
| 1726 | * Walk rgrp's bitmap to find bits that represent a block in @state. | ||
| 1727 | * | ||
| 1728 | * This function never fails, because we wouldn't call it unless we | ||
| 1729 | * know (from reservation results, etc.) that a block is available. | ||
| 1730 | * | ||
| 1731 | * Scope of @goal is just within rgrp, not the whole filesystem. | ||
| 1732 | * Scope of @returned block is just within bitmap, not the whole filesystem. | ||
| 1733 | * | ||
| 1734 | * Returns: the block number found relative to the bitmap rbi | ||
| 1735 | */ | ||
| 1736 | |||
| 1737 | static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, unsigned char state, | ||
| 1738 | struct gfs2_bitmap **rbi) | ||
| 1739 | { | ||
| 1740 | struct gfs2_bitmap *bi = NULL; | ||
| 1741 | const u32 length = rgd->rd_length; | ||
| 1742 | u32 biblk = BFITNOENT; | ||
| 1743 | unsigned int buf, x; | ||
| 1744 | const u8 *buffer = NULL; | ||
| 1745 | |||
| 1746 | *rbi = NULL; | ||
| 1747 | /* Find bitmap block that contains bits for goal block */ | ||
| 1748 | for (buf = 0; buf < length; buf++) { | ||
| 1749 | bi = rgd->rd_bits + buf; | ||
| 1750 | /* Convert scope of "goal" from rgrp-wide to within found bit block */ | ||
| 1751 | if (goal < (bi->bi_start + bi->bi_len) * GFS2_NBBY) { | ||
| 1752 | goal -= bi->bi_start * GFS2_NBBY; | ||
| 1753 | goto do_search; | ||
| 1754 | } | ||
| 1755 | } | ||
| 1756 | buf = 0; | ||
| 1757 | goal = 0; | ||
| 1758 | |||
| 1759 | do_search: | ||
| 1760 | /* Search (up to entire) bitmap in this rgrp for allocatable block. | ||
| 1761 | "x <= length", instead of "x < length", because we typically start | ||
| 1762 | the search in the middle of a bit block, but if we can't find an | ||
| 1763 | allocatable block anywhere else, we want to be able wrap around and | ||
| 1764 | search in the first part of our first-searched bit block. */ | ||
| 1765 | for (x = 0; x <= length; x++) { | ||
| 1766 | bi = rgd->rd_bits + buf; | ||
| 1767 | |||
| 1768 | if (test_bit(GBF_FULL, &bi->bi_flags) && | ||
| 1769 | (state == GFS2_BLKST_FREE)) | ||
| 1770 | goto skip; | ||
| 1771 | |||
| 1772 | /* The GFS2_BLKST_UNLINKED state doesn't apply to the clone | ||
| 1773 | bitmaps, so we must search the originals for that. */ | ||
| 1774 | buffer = bi->bi_bh->b_data + bi->bi_offset; | ||
| 1775 | WARN_ON(!buffer_uptodate(bi->bi_bh)); | ||
| 1776 | if (state != GFS2_BLKST_UNLINKED && bi->bi_clone) | ||
| 1777 | buffer = bi->bi_clone + bi->bi_offset; | ||
| 1778 | |||
| 1779 | while (1) { | ||
| 1780 | struct gfs2_blkreserv *rs; | ||
| 1781 | u32 rgblk; | ||
| 1782 | |||
| 1783 | biblk = gfs2_bitfit(buffer, bi->bi_len, goal, state); | ||
| 1784 | if (biblk == BFITNOENT) | ||
| 1785 | break; | ||
| 1786 | /* Check if this block is reserved() */ | ||
| 1787 | rgblk = gfs2_bi2rgd_blk(bi, biblk); | ||
| 1788 | rs = rs_find(rgd, rgblk); | ||
| 1789 | if (rs == NULL) | ||
| 1790 | break; | ||
| 1791 | |||
| 1792 | BUG_ON(rs->rs_bi != bi); | ||
| 1793 | biblk = BFITNOENT; | ||
| 1794 | /* This should jump to the first block after the | ||
| 1795 | reservation. */ | ||
| 1796 | goal = rs->rs_biblk + rs->rs_free; | ||
| 1797 | if (goal >= bi->bi_len * GFS2_NBBY) | ||
| 1798 | break; | ||
| 1799 | } | ||
| 1800 | if (biblk != BFITNOENT) | ||
| 1801 | break; | ||
| 1802 | |||
| 1803 | if ((goal == 0) && (state == GFS2_BLKST_FREE)) | ||
| 1804 | set_bit(GBF_FULL, &bi->bi_flags); | ||
| 1805 | |||
| 1806 | /* Try next bitmap block (wrap back to rgrp header if at end) */ | ||
| 1807 | skip: | ||
| 1808 | buf++; | ||
| 1809 | buf %= length; | ||
| 1810 | goal = 0; | ||
| 1811 | } | ||
| 1812 | |||
| 1813 | if (biblk != BFITNOENT) | ||
| 1814 | *rbi = bi; | ||
| 1815 | |||
| 1816 | return biblk; | ||
| 1817 | } | ||
| 1818 | 1830 | ||
| 1819 | /** | 1831 | /** |
| 1820 | * gfs2_alloc_extent - allocate an extent from a given bitmap | 1832 | * gfs2_alloc_extent - allocate an extent from a given bitmap |
| 1821 | * @rgd: the resource group descriptor | 1833 | * @rbm: the resource group information |
| 1822 | * @bi: the bitmap within the rgrp | ||
| 1823 | * @blk: the block within the bitmap | ||
| 1824 | * @dinode: TRUE if the first block we allocate is for a dinode | 1834 | * @dinode: TRUE if the first block we allocate is for a dinode |
| 1825 | * @n: The extent length | 1835 | * @n: The extent length (value/result) |
| 1826 | * | 1836 | * |
| 1827 | * Add the found bitmap buffer to the transaction. | 1837 | * Add the bitmap buffer to the transaction. |
| 1828 | * Set the found bits to @new_state to change block's allocation state. | 1838 | * Set the found bits to @new_state to change block's allocation state. |
| 1829 | * Returns: starting block number of the extent (fs scope) | ||
| 1830 | */ | 1839 | */ |
| 1831 | static u64 gfs2_alloc_extent(struct gfs2_rgrpd *rgd, struct gfs2_bitmap *bi, | 1840 | static void gfs2_alloc_extent(const struct gfs2_rbm *rbm, bool dinode, |
| 1832 | u32 blk, bool dinode, unsigned int *n) | 1841 | unsigned int *n) |
| 1833 | { | 1842 | { |
| 1843 | struct gfs2_rbm pos = { .rgd = rbm->rgd, }; | ||
| 1834 | const unsigned int elen = *n; | 1844 | const unsigned int elen = *n; |
| 1835 | u32 goal, rgblk; | 1845 | u64 block; |
| 1836 | const u8 *buffer = NULL; | 1846 | int ret; |
| 1837 | struct gfs2_blkreserv *rs; | 1847 | |
| 1838 | 1848 | *n = 1; | |
| 1839 | *n = 0; | 1849 | block = gfs2_rbm_to_block(rbm); |
| 1840 | buffer = bi->bi_bh->b_data + bi->bi_offset; | 1850 | gfs2_trans_add_bh(rbm->rgd->rd_gl, rbm->bi->bi_bh, 1); |
| 1841 | gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); | 1851 | gfs2_setbit(rbm, true, dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); |
| 1842 | gfs2_setbit(rgd, bi->bi_clone, bi, blk, | 1852 | block++; |
| 1843 | dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); | ||
| 1844 | (*n)++; | ||
| 1845 | goal = blk; | ||
| 1846 | while (*n < elen) { | 1853 | while (*n < elen) { |
| 1847 | goal++; | 1854 | ret = gfs2_rbm_from_block(&pos, block); |
| 1848 | if (goal >= (bi->bi_len * GFS2_NBBY)) | 1855 | if (ret || gfs2_testbit(&pos) != GFS2_BLKST_FREE) |
| 1849 | break; | ||
| 1850 | rgblk = gfs2_bi2rgd_blk(bi, goal); | ||
| 1851 | rs = rs_find(rgd, rgblk); | ||
| 1852 | if (rs) /* Oops, we bumped into someone's reservation */ | ||
| 1853 | break; | ||
| 1854 | if (gfs2_testbit(rgd, buffer, bi->bi_len, goal) != | ||
| 1855 | GFS2_BLKST_FREE) | ||
| 1856 | break; | 1856 | break; |
| 1857 | gfs2_setbit(rgd, bi->bi_clone, bi, goal, GFS2_BLKST_USED); | 1857 | gfs2_trans_add_bh(pos.rgd->rd_gl, pos.bi->bi_bh, 1); |
| 1858 | gfs2_setbit(&pos, true, GFS2_BLKST_USED); | ||
| 1858 | (*n)++; | 1859 | (*n)++; |
| 1860 | block++; | ||
| 1859 | } | 1861 | } |
| 1860 | blk = gfs2_bi2rgd_blk(bi, blk); | ||
| 1861 | rgd->rd_last_alloc = blk + *n - 1; | ||
| 1862 | return rgd->rd_data0 + blk; | ||
| 1863 | } | 1862 | } |
| 1864 | 1863 | ||
| 1865 | /** | 1864 | /** |
| @@ -1875,46 +1874,30 @@ static u64 gfs2_alloc_extent(struct gfs2_rgrpd *rgd, struct gfs2_bitmap *bi, | |||
| 1875 | static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart, | 1874 | static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart, |
| 1876 | u32 blen, unsigned char new_state) | 1875 | u32 blen, unsigned char new_state) |
| 1877 | { | 1876 | { |
| 1878 | struct gfs2_rgrpd *rgd; | 1877 | struct gfs2_rbm rbm; |
| 1879 | struct gfs2_bitmap *bi = NULL; | ||
| 1880 | u32 length, rgrp_blk, buf_blk; | ||
| 1881 | unsigned int buf; | ||
| 1882 | 1878 | ||
| 1883 | rgd = gfs2_blk2rgrpd(sdp, bstart, 1); | 1879 | rbm.rgd = gfs2_blk2rgrpd(sdp, bstart, 1); |
| 1884 | if (!rgd) { | 1880 | if (!rbm.rgd) { |
| 1885 | if (gfs2_consist(sdp)) | 1881 | if (gfs2_consist(sdp)) |
| 1886 | fs_err(sdp, "block = %llu\n", (unsigned long long)bstart); | 1882 | fs_err(sdp, "block = %llu\n", (unsigned long long)bstart); |
| 1887 | return NULL; | 1883 | return NULL; |
| 1888 | } | 1884 | } |
| 1889 | 1885 | ||
| 1890 | length = rgd->rd_length; | ||
| 1891 | |||
| 1892 | rgrp_blk = bstart - rgd->rd_data0; | ||
| 1893 | |||
| 1894 | while (blen--) { | 1886 | while (blen--) { |
| 1895 | for (buf = 0; buf < length; buf++) { | 1887 | gfs2_rbm_from_block(&rbm, bstart); |
| 1896 | bi = rgd->rd_bits + buf; | 1888 | bstart++; |
| 1897 | if (rgrp_blk < (bi->bi_start + bi->bi_len) * GFS2_NBBY) | 1889 | if (!rbm.bi->bi_clone) { |
| 1898 | break; | 1890 | rbm.bi->bi_clone = kmalloc(rbm.bi->bi_bh->b_size, |
| 1891 | GFP_NOFS | __GFP_NOFAIL); | ||
| 1892 | memcpy(rbm.bi->bi_clone + rbm.bi->bi_offset, | ||
| 1893 | rbm.bi->bi_bh->b_data + rbm.bi->bi_offset, | ||
| 1894 | rbm.bi->bi_len); | ||
| 1899 | } | 1895 | } |
| 1900 | 1896 | gfs2_trans_add_bh(rbm.rgd->rd_gl, rbm.bi->bi_bh, 1); | |
| 1901 | gfs2_assert(rgd->rd_sbd, buf < length); | 1897 | gfs2_setbit(&rbm, false, new_state); |
| 1902 | |||
| 1903 | buf_blk = rgrp_blk - bi->bi_start * GFS2_NBBY; | ||
| 1904 | rgrp_blk++; | ||
| 1905 | |||
| 1906 | if (!bi->bi_clone) { | ||
| 1907 | bi->bi_clone = kmalloc(bi->bi_bh->b_size, | ||
| 1908 | GFP_NOFS | __GFP_NOFAIL); | ||
| 1909 | memcpy(bi->bi_clone + bi->bi_offset, | ||
| 1910 | bi->bi_bh->b_data + bi->bi_offset, | ||
| 1911 | bi->bi_len); | ||
| 1912 | } | ||
| 1913 | gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); | ||
| 1914 | gfs2_setbit(rgd, NULL, bi, buf_blk, new_state); | ||
| 1915 | } | 1898 | } |
| 1916 | 1899 | ||
| 1917 | return rgd; | 1900 | return rbm.rgd; |
| 1918 | } | 1901 | } |
| 1919 | 1902 | ||
| 1920 | /** | 1903 | /** |
| @@ -1956,46 +1939,41 @@ static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd) | |||
| 1956 | } | 1939 | } |
| 1957 | 1940 | ||
| 1958 | /** | 1941 | /** |
| 1959 | * claim_reserved_blks - Claim previously reserved blocks | 1942 | * gfs2_adjust_reservation - Adjust (or remove) a reservation after allocation |
| 1960 | * @ip: the inode that's claiming the reservation | 1943 | * @ip: The inode we have just allocated blocks for |
| 1961 | * @dinode: 1 if this block is a dinode block, otherwise data block | 1944 | * @rbm: The start of the allocated blocks |
| 1962 | * @nblocks: desired extent length | 1945 | * @len: The extent length |
| 1963 | * | 1946 | * |
| 1964 | * Lay claim to previously reserved blocks. | 1947 | * Adjusts a reservation after an allocation has taken place. If the |
| 1965 | * Returns: Starting block number of the blocks claimed. | 1948 | * reservation does not match the allocation, or if it is now empty |
| 1966 | * Sets *nblocks to the actual extent length allocated. | 1949 | * then it is removed. |
| 1967 | */ | 1950 | */ |
| 1968 | static u64 claim_reserved_blks(struct gfs2_inode *ip, bool dinode, | 1951 | |
| 1969 | unsigned int *nblocks) | 1952 | static void gfs2_adjust_reservation(struct gfs2_inode *ip, |
| 1953 | const struct gfs2_rbm *rbm, unsigned len) | ||
| 1970 | { | 1954 | { |
| 1971 | struct gfs2_blkreserv *rs = ip->i_res; | 1955 | struct gfs2_blkreserv *rs = ip->i_res; |
| 1972 | struct gfs2_rgrpd *rgd = rs->rs_rgd; | 1956 | struct gfs2_rgrpd *rgd = rbm->rgd; |
| 1973 | struct gfs2_bitmap *bi; | 1957 | unsigned rlen; |
| 1974 | u64 start_block = gfs2_rs_startblk(rs); | 1958 | u64 block; |
| 1975 | const unsigned int elen = *nblocks; | 1959 | int ret; |
| 1976 | 1960 | ||
| 1977 | bi = rs->rs_bi; | 1961 | spin_lock(&rgd->rd_rsspin); |
| 1978 | gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); | 1962 | if (gfs2_rs_active(rs)) { |
| 1979 | 1963 | if (gfs2_rbm_eq(&rs->rs_rbm, rbm)) { | |
| 1980 | for (*nblocks = 0; *nblocks < elen && rs->rs_free; (*nblocks)++) { | 1964 | block = gfs2_rbm_to_block(rbm); |
| 1981 | if (gfs2_testbit(rgd, bi->bi_bh->b_data + bi->bi_offset, | 1965 | ret = gfs2_rbm_from_block(&rs->rs_rbm, block + len); |
| 1982 | bi->bi_len, rs->rs_biblk) != GFS2_BLKST_FREE) | 1966 | rlen = min(rs->rs_free, len); |
| 1983 | break; | 1967 | rs->rs_free -= rlen; |
| 1984 | gfs2_setbit(rgd, bi->bi_clone, bi, rs->rs_biblk, | 1968 | rgd->rd_reserved -= rlen; |
| 1985 | dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); | 1969 | trace_gfs2_rs(rs, TRACE_RS_CLAIM); |
| 1986 | rs->rs_biblk++; | 1970 | if (rs->rs_free && !ret) |
| 1987 | rs->rs_free--; | 1971 | goto out; |
| 1988 | 1972 | } | |
| 1989 | BUG_ON(!rgd->rd_reserved); | 1973 | __rs_deltree(ip, rs); |
| 1990 | rgd->rd_reserved--; | ||
| 1991 | dinode = false; | ||
| 1992 | } | 1974 | } |
| 1993 | 1975 | out: | |
| 1994 | trace_gfs2_rs(ip, rs, TRACE_RS_CLAIM); | 1976 | spin_unlock(&rgd->rd_rsspin); |
| 1995 | if (!rs->rs_free || *nblocks != elen) | ||
| 1996 | gfs2_rs_deltree(rs); | ||
| 1997 | |||
| 1998 | return start_block; | ||
| 1999 | } | 1977 | } |
| 2000 | 1978 | ||
| 2001 | /** | 1979 | /** |
| @@ -2014,47 +1992,40 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks, | |||
| 2014 | { | 1992 | { |
| 2015 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | 1993 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
| 2016 | struct buffer_head *dibh; | 1994 | struct buffer_head *dibh; |
| 2017 | struct gfs2_rgrpd *rgd; | 1995 | struct gfs2_rbm rbm = { .rgd = ip->i_rgd, }; |
| 2018 | unsigned int ndata; | 1996 | unsigned int ndata; |
| 2019 | u32 goal, blk; /* block, within the rgrp scope */ | 1997 | u64 goal; |
| 2020 | u64 block; /* block, within the file system scope */ | 1998 | u64 block; /* block, within the file system scope */ |
| 2021 | int error; | 1999 | int error; |
| 2022 | struct gfs2_bitmap *bi; | ||
| 2023 | 2000 | ||
| 2024 | /* Only happens if there is a bug in gfs2, return something distinctive | 2001 | if (gfs2_rs_active(ip->i_res)) |
| 2025 | * to ensure that it is noticed. | 2002 | goal = gfs2_rbm_to_block(&ip->i_res->rs_rbm); |
| 2026 | */ | 2003 | else if (!dinode && rgrp_contains_block(rbm.rgd, ip->i_goal)) |
| 2027 | if (ip->i_res->rs_requested == 0) | 2004 | goal = ip->i_goal; |
| 2028 | return -ECANCELED; | ||
| 2029 | |||
| 2030 | /* If we have a reservation, claim blocks from it. */ | ||
| 2031 | if (gfs2_rs_active(ip->i_res)) { | ||
| 2032 | BUG_ON(!ip->i_res->rs_free); | ||
| 2033 | rgd = ip->i_res->rs_rgd; | ||
| 2034 | block = claim_reserved_blks(ip, dinode, nblocks); | ||
| 2035 | if (*nblocks) | ||
| 2036 | goto found_blocks; | ||
| 2037 | } | ||
| 2038 | |||
| 2039 | rgd = ip->i_rgd; | ||
| 2040 | |||
| 2041 | if (!dinode && rgrp_contains_block(rgd, ip->i_goal)) | ||
| 2042 | goal = ip->i_goal - rgd->rd_data0; | ||
| 2043 | else | 2005 | else |
| 2044 | goal = rgd->rd_last_alloc; | 2006 | goal = rbm.rgd->rd_last_alloc + rbm.rgd->rd_data0; |
| 2045 | 2007 | ||
| 2046 | blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, &bi); | 2008 | gfs2_rbm_from_block(&rbm, goal); |
| 2009 | error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, ip, false); | ||
| 2010 | |||
| 2011 | if (error == -ENOSPC) { | ||
| 2012 | gfs2_rbm_from_block(&rbm, goal); | ||
| 2013 | error = gfs2_rbm_find(&rbm, GFS2_BLKST_FREE, 0, NULL, false); | ||
| 2014 | } | ||
| 2047 | 2015 | ||
| 2048 | /* Since all blocks are reserved in advance, this shouldn't happen */ | 2016 | /* Since all blocks are reserved in advance, this shouldn't happen */ |
| 2049 | if (blk == BFITNOENT) { | 2017 | if (error) { |
| 2050 | printk(KERN_WARNING "BFITNOENT, nblocks=%u\n", *nblocks); | 2018 | fs_warn(sdp, "inum=%llu error=%d, nblocks=%u, full=%d\n", |
| 2051 | printk(KERN_WARNING "FULL=%d\n", | 2019 | (unsigned long long)ip->i_no_addr, error, *nblocks, |
| 2052 | test_bit(GBF_FULL, &rgd->rd_bits->bi_flags)); | 2020 | test_bit(GBF_FULL, &rbm.rgd->rd_bits->bi_flags)); |
| 2053 | goto rgrp_error; | 2021 | goto rgrp_error; |
| 2054 | } | 2022 | } |
| 2055 | 2023 | ||
| 2056 | block = gfs2_alloc_extent(rgd, bi, blk, dinode, nblocks); | 2024 | gfs2_alloc_extent(&rbm, dinode, nblocks); |
| 2057 | found_blocks: | 2025 | block = gfs2_rbm_to_block(&rbm); |
| 2026 | rbm.rgd->rd_last_alloc = block - rbm.rgd->rd_data0; | ||
| 2027 | if (gfs2_rs_active(ip->i_res)) | ||
| 2028 | gfs2_adjust_reservation(ip, &rbm, *nblocks); | ||
| 2058 | ndata = *nblocks; | 2029 | ndata = *nblocks; |
| 2059 | if (dinode) | 2030 | if (dinode) |
| 2060 | ndata--; | 2031 | ndata--; |
| @@ -2071,22 +2042,22 @@ found_blocks: | |||
| 2071 | brelse(dibh); | 2042 | brelse(dibh); |
| 2072 | } | 2043 | } |
| 2073 | } | 2044 | } |
| 2074 | if (rgd->rd_free < *nblocks) { | 2045 | if (rbm.rgd->rd_free < *nblocks) { |
| 2075 | printk(KERN_WARNING "nblocks=%u\n", *nblocks); | 2046 | printk(KERN_WARNING "nblocks=%u\n", *nblocks); |
| 2076 | goto rgrp_error; | 2047 | goto rgrp_error; |
| 2077 | } | 2048 | } |
| 2078 | 2049 | ||
| 2079 | rgd->rd_free -= *nblocks; | 2050 | rbm.rgd->rd_free -= *nblocks; |
| 2080 | if (dinode) { | 2051 | if (dinode) { |
| 2081 | rgd->rd_dinodes++; | 2052 | rbm.rgd->rd_dinodes++; |
| 2082 | *generation = rgd->rd_igeneration++; | 2053 | *generation = rbm.rgd->rd_igeneration++; |
| 2083 | if (*generation == 0) | 2054 | if (*generation == 0) |
| 2084 | *generation = rgd->rd_igeneration++; | 2055 | *generation = rbm.rgd->rd_igeneration++; |
| 2085 | } | 2056 | } |
| 2086 | 2057 | ||
| 2087 | gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); | 2058 | gfs2_trans_add_bh(rbm.rgd->rd_gl, rbm.rgd->rd_bits[0].bi_bh, 1); |
| 2088 | gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); | 2059 | gfs2_rgrp_out(rbm.rgd, rbm.rgd->rd_bits[0].bi_bh->b_data); |
| 2089 | gfs2_rgrp_ondisk2lvb(rgd->rd_rgl, rgd->rd_bits[0].bi_bh->b_data); | 2060 | gfs2_rgrp_ondisk2lvb(rbm.rgd->rd_rgl, rbm.rgd->rd_bits[0].bi_bh->b_data); |
| 2090 | 2061 | ||
| 2091 | gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0); | 2062 | gfs2_statfs_change(sdp, 0, -(s64)*nblocks, dinode ? 1 : 0); |
| 2092 | if (dinode) | 2063 | if (dinode) |
| @@ -2100,14 +2071,14 @@ found_blocks: | |||
| 2100 | gfs2_quota_change(ip, ndata, ip->i_inode.i_uid, | 2071 | gfs2_quota_change(ip, ndata, ip->i_inode.i_uid, |
| 2101 | ip->i_inode.i_gid); | 2072 | ip->i_inode.i_gid); |
| 2102 | 2073 | ||
| 2103 | rgd->rd_free_clone -= *nblocks; | 2074 | rbm.rgd->rd_free_clone -= *nblocks; |
| 2104 | trace_gfs2_block_alloc(ip, rgd, block, *nblocks, | 2075 | trace_gfs2_block_alloc(ip, rbm.rgd, block, *nblocks, |
| 2105 | dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); | 2076 | dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); |
| 2106 | *bn = block; | 2077 | *bn = block; |
| 2107 | return 0; | 2078 | return 0; |
| 2108 | 2079 | ||
| 2109 | rgrp_error: | 2080 | rgrp_error: |
| 2110 | gfs2_rgrp_error(rgd); | 2081 | gfs2_rgrp_error(rbm.rgd); |
| 2111 | return -EIO; | 2082 | return -EIO; |
| 2112 | } | 2083 | } |
| 2113 | 2084 | ||
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h index ca6e26729b86..24077958dcf6 100644 --- a/fs/gfs2/rgrp.h +++ b/fs/gfs2/rgrp.h | |||
| @@ -46,7 +46,7 @@ extern int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *n, | |||
| 46 | bool dinode, u64 *generation); | 46 | bool dinode, u64 *generation); |
| 47 | 47 | ||
| 48 | extern int gfs2_rs_alloc(struct gfs2_inode *ip); | 48 | extern int gfs2_rs_alloc(struct gfs2_inode *ip); |
| 49 | extern void gfs2_rs_deltree(struct gfs2_blkreserv *rs); | 49 | extern void gfs2_rs_deltree(struct gfs2_inode *ip, struct gfs2_blkreserv *rs); |
| 50 | extern void gfs2_rs_delete(struct gfs2_inode *ip); | 50 | extern void gfs2_rs_delete(struct gfs2_inode *ip); |
| 51 | extern void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta); | 51 | extern void __gfs2_free_blocks(struct gfs2_inode *ip, u64 bstart, u32 blen, int meta); |
| 52 | extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen); | 52 | extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen); |
| @@ -73,30 +73,10 @@ extern int gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset, | |||
| 73 | const struct gfs2_bitmap *bi, unsigned minlen, u64 *ptrimmed); | 73 | const struct gfs2_bitmap *bi, unsigned minlen, u64 *ptrimmed); |
| 74 | extern int gfs2_fitrim(struct file *filp, void __user *argp); | 74 | extern int gfs2_fitrim(struct file *filp, void __user *argp); |
| 75 | 75 | ||
| 76 | /* This is how to tell if a multi-block reservation is "inplace" reserved: */ | 76 | /* This is how to tell if a reservation is in the rgrp tree: */ |
| 77 | static inline int gfs2_mb_reserved(struct gfs2_inode *ip) | 77 | static inline bool gfs2_rs_active(struct gfs2_blkreserv *rs) |
| 78 | { | 78 | { |
| 79 | if (ip->i_res && ip->i_res->rs_requested) | 79 | return rs && !RB_EMPTY_NODE(&rs->rs_node); |
| 80 | return 1; | ||
| 81 | return 0; | ||
| 82 | } | ||
| 83 | |||
| 84 | /* This is how to tell if a multi-block reservation is in the rgrp tree: */ | ||
| 85 | static inline int gfs2_rs_active(struct gfs2_blkreserv *rs) | ||
| 86 | { | ||
| 87 | if (rs && rs->rs_bi) | ||
| 88 | return 1; | ||
| 89 | return 0; | ||
| 90 | } | ||
| 91 | |||
| 92 | static inline u32 gfs2_bi2rgd_blk(const struct gfs2_bitmap *bi, u32 blk) | ||
| 93 | { | ||
| 94 | return (bi->bi_start * GFS2_NBBY) + blk; | ||
| 95 | } | ||
| 96 | |||
| 97 | static inline u64 gfs2_rs_startblk(const struct gfs2_blkreserv *rs) | ||
| 98 | { | ||
| 99 | return gfs2_bi2rgd_blk(rs->rs_bi, rs->rs_biblk) + rs->rs_rgd->rd_data0; | ||
| 100 | } | 80 | } |
| 101 | 81 | ||
| 102 | #endif /* __RGRP_DOT_H__ */ | 82 | #endif /* __RGRP_DOT_H__ */ |
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index fc3168f47a14..a8d90f2f576c 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c | |||
| @@ -1366,6 +1366,8 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root) | |||
| 1366 | val = sdp->sd_tune.gt_statfs_quantum; | 1366 | val = sdp->sd_tune.gt_statfs_quantum; |
| 1367 | if (val != 30) | 1367 | if (val != 30) |
| 1368 | seq_printf(s, ",statfs_quantum=%d", val); | 1368 | seq_printf(s, ",statfs_quantum=%d", val); |
| 1369 | else if (sdp->sd_tune.gt_statfs_slow) | ||
| 1370 | seq_puts(s, ",statfs_quantum=0"); | ||
| 1369 | val = sdp->sd_tune.gt_quota_quantum; | 1371 | val = sdp->sd_tune.gt_quota_quantum; |
| 1370 | if (val != 60) | 1372 | if (val != 60) |
| 1371 | seq_printf(s, ",quota_quantum=%d", val); | 1373 | seq_printf(s, ",quota_quantum=%d", val); |
| @@ -1543,6 +1545,11 @@ static void gfs2_evict_inode(struct inode *inode) | |||
| 1543 | 1545 | ||
| 1544 | out_truncate: | 1546 | out_truncate: |
| 1545 | gfs2_log_flush(sdp, ip->i_gl); | 1547 | gfs2_log_flush(sdp, ip->i_gl); |
| 1548 | if (test_bit(GLF_DIRTY, &ip->i_gl->gl_flags)) { | ||
| 1549 | struct address_space *metamapping = gfs2_glock2aspace(ip->i_gl); | ||
| 1550 | filemap_fdatawrite(metamapping); | ||
| 1551 | filemap_fdatawait(metamapping); | ||
| 1552 | } | ||
| 1546 | write_inode_now(inode, 1); | 1553 | write_inode_now(inode, 1); |
| 1547 | gfs2_ail_flush(ip->i_gl, 0); | 1554 | gfs2_ail_flush(ip->i_gl, 0); |
| 1548 | 1555 | ||
| @@ -1557,7 +1564,7 @@ out_truncate: | |||
| 1557 | out_unlock: | 1564 | out_unlock: |
| 1558 | /* Error path for case 1 */ | 1565 | /* Error path for case 1 */ |
| 1559 | if (gfs2_rs_active(ip->i_res)) | 1566 | if (gfs2_rs_active(ip->i_res)) |
| 1560 | gfs2_rs_deltree(ip->i_res); | 1567 | gfs2_rs_deltree(ip, ip->i_res); |
| 1561 | 1568 | ||
| 1562 | if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) | 1569 | if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags)) |
| 1563 | gfs2_glock_dq(&ip->i_iopen_gh); | 1570 | gfs2_glock_dq(&ip->i_iopen_gh); |
diff --git a/fs/gfs2/trace_gfs2.h b/fs/gfs2/trace_gfs2.h index a25c252fe412..bbdc78af60ca 100644 --- a/fs/gfs2/trace_gfs2.h +++ b/fs/gfs2/trace_gfs2.h | |||
| @@ -509,10 +509,9 @@ TRACE_EVENT(gfs2_block_alloc, | |||
| 509 | /* Keep track of multi-block reservations as they are allocated/freed */ | 509 | /* Keep track of multi-block reservations as they are allocated/freed */ |
| 510 | TRACE_EVENT(gfs2_rs, | 510 | TRACE_EVENT(gfs2_rs, |
| 511 | 511 | ||
| 512 | TP_PROTO(const struct gfs2_inode *ip, const struct gfs2_blkreserv *rs, | 512 | TP_PROTO(const struct gfs2_blkreserv *rs, u8 func), |
| 513 | u8 func), | ||
| 514 | 513 | ||
| 515 | TP_ARGS(ip, rs, func), | 514 | TP_ARGS(rs, func), |
| 516 | 515 | ||
| 517 | TP_STRUCT__entry( | 516 | TP_STRUCT__entry( |
| 518 | __field( dev_t, dev ) | 517 | __field( dev_t, dev ) |
| @@ -526,18 +525,17 @@ TRACE_EVENT(gfs2_rs, | |||
| 526 | ), | 525 | ), |
| 527 | 526 | ||
| 528 | TP_fast_assign( | 527 | TP_fast_assign( |
| 529 | __entry->dev = rs->rs_rgd ? rs->rs_rgd->rd_sbd->sd_vfs->s_dev : 0; | 528 | __entry->dev = rs->rs_rbm.rgd->rd_sbd->sd_vfs->s_dev; |
| 530 | __entry->rd_addr = rs->rs_rgd ? rs->rs_rgd->rd_addr : 0; | 529 | __entry->rd_addr = rs->rs_rbm.rgd->rd_addr; |
| 531 | __entry->rd_free_clone = rs->rs_rgd ? rs->rs_rgd->rd_free_clone : 0; | 530 | __entry->rd_free_clone = rs->rs_rbm.rgd->rd_free_clone; |
| 532 | __entry->rd_reserved = rs->rs_rgd ? rs->rs_rgd->rd_reserved : 0; | 531 | __entry->rd_reserved = rs->rs_rbm.rgd->rd_reserved; |
| 533 | __entry->inum = ip ? ip->i_no_addr : 0; | 532 | __entry->inum = rs->rs_inum; |
| 534 | __entry->start = gfs2_rs_startblk(rs); | 533 | __entry->start = gfs2_rbm_to_block(&rs->rs_rbm); |
| 535 | __entry->free = rs->rs_free; | 534 | __entry->free = rs->rs_free; |
| 536 | __entry->func = func; | 535 | __entry->func = func; |
| 537 | ), | 536 | ), |
| 538 | 537 | ||
| 539 | TP_printk("%u,%u bmap %llu resrv %llu rg:%llu rf:%lu rr:%lu %s " | 538 | TP_printk("%u,%u bmap %llu resrv %llu rg:%llu rf:%lu rr:%lu %s f:%lu", |
| 540 | "f:%lu", | ||
| 541 | MAJOR(__entry->dev), MINOR(__entry->dev), | 539 | MAJOR(__entry->dev), MINOR(__entry->dev), |
| 542 | (unsigned long long)__entry->inum, | 540 | (unsigned long long)__entry->inum, |
| 543 | (unsigned long long)__entry->start, | 541 | (unsigned long long)__entry->start, |
diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h index 41f42cdccbb8..bf2ae9aeee7a 100644 --- a/fs/gfs2/trans.h +++ b/fs/gfs2/trans.h | |||
| @@ -28,11 +28,10 @@ struct gfs2_glock; | |||
| 28 | 28 | ||
| 29 | /* reserve either the number of blocks to be allocated plus the rg header | 29 | /* reserve either the number of blocks to be allocated plus the rg header |
| 30 | * block, or all of the blocks in the rg, whichever is smaller */ | 30 | * block, or all of the blocks in the rg, whichever is smaller */ |
| 31 | static inline unsigned int gfs2_rg_blocks(const struct gfs2_inode *ip) | 31 | static inline unsigned int gfs2_rg_blocks(const struct gfs2_inode *ip, unsigned requested) |
| 32 | { | 32 | { |
| 33 | const struct gfs2_blkreserv *rs = ip->i_res; | 33 | if (requested < ip->i_rgd->rd_length) |
| 34 | if (rs && rs->rs_requested < ip->i_rgd->rd_length) | 34 | return requested + 1; |
| 35 | return rs->rs_requested + 1; | ||
| 36 | return ip->i_rgd->rd_length; | 35 | return ip->i_rgd->rd_length; |
| 37 | } | 36 | } |
| 38 | 37 | ||
diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c index 27a0b4a901f5..db330e5518cd 100644 --- a/fs/gfs2/xattr.c +++ b/fs/gfs2/xattr.c | |||
| @@ -448,17 +448,18 @@ ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size) | |||
| 448 | } | 448 | } |
| 449 | 449 | ||
| 450 | /** | 450 | /** |
| 451 | * ea_get_unstuffed - actually copies the unstuffed data into the | 451 | * ea_iter_unstuffed - copies the unstuffed xattr data to/from the |
| 452 | * request buffer | 452 | * request buffer |
| 453 | * @ip: The GFS2 inode | 453 | * @ip: The GFS2 inode |
| 454 | * @ea: The extended attribute header structure | 454 | * @ea: The extended attribute header structure |
| 455 | * @data: The data to be copied | 455 | * @din: The data to be copied in |
| 456 | * @dout: The data to be copied out (one of din,dout will be NULL) | ||
| 456 | * | 457 | * |
| 457 | * Returns: errno | 458 | * Returns: errno |
| 458 | */ | 459 | */ |
| 459 | 460 | ||
| 460 | static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, | 461 | static int gfs2_iter_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, |
| 461 | char *data) | 462 | const char *din, char *dout) |
| 462 | { | 463 | { |
| 463 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | 464 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
| 464 | struct buffer_head **bh; | 465 | struct buffer_head **bh; |
| @@ -467,6 +468,8 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, | |||
| 467 | __be64 *dataptrs = GFS2_EA2DATAPTRS(ea); | 468 | __be64 *dataptrs = GFS2_EA2DATAPTRS(ea); |
| 468 | unsigned int x; | 469 | unsigned int x; |
| 469 | int error = 0; | 470 | int error = 0; |
| 471 | unsigned char *pos; | ||
| 472 | unsigned cp_size; | ||
| 470 | 473 | ||
| 471 | bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS); | 474 | bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS); |
| 472 | if (!bh) | 475 | if (!bh) |
| @@ -497,12 +500,21 @@ static int ea_get_unstuffed(struct gfs2_inode *ip, struct gfs2_ea_header *ea, | |||
| 497 | goto out; | 500 | goto out; |
| 498 | } | 501 | } |
| 499 | 502 | ||
| 500 | memcpy(data, bh[x]->b_data + sizeof(struct gfs2_meta_header), | 503 | pos = bh[x]->b_data + sizeof(struct gfs2_meta_header); |
| 501 | (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); | 504 | cp_size = (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize; |
| 502 | 505 | ||
| 503 | amount -= sdp->sd_jbsize; | 506 | if (dout) { |
| 504 | data += sdp->sd_jbsize; | 507 | memcpy(dout, pos, cp_size); |
| 508 | dout += sdp->sd_jbsize; | ||
| 509 | } | ||
| 510 | |||
| 511 | if (din) { | ||
| 512 | gfs2_trans_add_bh(ip->i_gl, bh[x], 1); | ||
| 513 | memcpy(pos, din, cp_size); | ||
| 514 | din += sdp->sd_jbsize; | ||
| 515 | } | ||
| 505 | 516 | ||
| 517 | amount -= sdp->sd_jbsize; | ||
| 506 | brelse(bh[x]); | 518 | brelse(bh[x]); |
| 507 | } | 519 | } |
| 508 | 520 | ||
| @@ -523,7 +535,7 @@ static int gfs2_ea_get_copy(struct gfs2_inode *ip, struct gfs2_ea_location *el, | |||
| 523 | memcpy(data, GFS2_EA2DATA(el->el_ea), len); | 535 | memcpy(data, GFS2_EA2DATA(el->el_ea), len); |
| 524 | return len; | 536 | return len; |
| 525 | } | 537 | } |
| 526 | ret = ea_get_unstuffed(ip, el->el_ea, data); | 538 | ret = gfs2_iter_unstuffed(ip, el->el_ea, NULL, data); |
| 527 | if (ret < 0) | 539 | if (ret < 0) |
| 528 | return ret; | 540 | return ret; |
| 529 | return len; | 541 | return len; |
| @@ -727,7 +739,7 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er, | |||
| 727 | goto out_gunlock_q; | 739 | goto out_gunlock_q; |
| 728 | 740 | ||
| 729 | error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), | 741 | error = gfs2_trans_begin(GFS2_SB(&ip->i_inode), |
| 730 | blks + gfs2_rg_blocks(ip) + | 742 | blks + gfs2_rg_blocks(ip, blks) + |
| 731 | RES_DINODE + RES_STATFS + RES_QUOTA, 0); | 743 | RES_DINODE + RES_STATFS + RES_QUOTA, 0); |
| 732 | if (error) | 744 | if (error) |
| 733 | goto out_ipres; | 745 | goto out_ipres; |
| @@ -1220,69 +1232,23 @@ static int gfs2_xattr_set(struct dentry *dentry, const char *name, | |||
| 1220 | size, flags, type); | 1232 | size, flags, type); |
| 1221 | } | 1233 | } |
| 1222 | 1234 | ||
| 1235 | |||
| 1223 | static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, | 1236 | static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, |
| 1224 | struct gfs2_ea_header *ea, char *data) | 1237 | struct gfs2_ea_header *ea, char *data) |
| 1225 | { | 1238 | { |
| 1226 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); | 1239 | struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); |
| 1227 | struct buffer_head **bh; | ||
| 1228 | unsigned int amount = GFS2_EA_DATA_LEN(ea); | 1240 | unsigned int amount = GFS2_EA_DATA_LEN(ea); |
| 1229 | unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); | 1241 | unsigned int nptrs = DIV_ROUND_UP(amount, sdp->sd_jbsize); |
| 1230 | __be64 *dataptrs = GFS2_EA2DATAPTRS(ea); | 1242 | int ret; |
| 1231 | unsigned int x; | ||
| 1232 | int error; | ||
| 1233 | |||
| 1234 | bh = kcalloc(nptrs, sizeof(struct buffer_head *), GFP_NOFS); | ||
| 1235 | if (!bh) | ||
| 1236 | return -ENOMEM; | ||
| 1237 | |||
| 1238 | error = gfs2_trans_begin(sdp, nptrs + RES_DINODE, 0); | ||
| 1239 | if (error) | ||
| 1240 | goto out; | ||
| 1241 | |||
| 1242 | for (x = 0; x < nptrs; x++) { | ||
| 1243 | error = gfs2_meta_read(ip->i_gl, be64_to_cpu(*dataptrs), 0, | ||
| 1244 | bh + x); | ||
| 1245 | if (error) { | ||
| 1246 | while (x--) | ||
| 1247 | brelse(bh[x]); | ||
| 1248 | goto fail; | ||
| 1249 | } | ||
| 1250 | dataptrs++; | ||
| 1251 | } | ||
| 1252 | |||
| 1253 | for (x = 0; x < nptrs; x++) { | ||
| 1254 | error = gfs2_meta_wait(sdp, bh[x]); | ||
| 1255 | if (error) { | ||
| 1256 | for (; x < nptrs; x++) | ||
| 1257 | brelse(bh[x]); | ||
| 1258 | goto fail; | ||
| 1259 | } | ||
| 1260 | if (gfs2_metatype_check(sdp, bh[x], GFS2_METATYPE_ED)) { | ||
| 1261 | for (; x < nptrs; x++) | ||
| 1262 | brelse(bh[x]); | ||
| 1263 | error = -EIO; | ||
| 1264 | goto fail; | ||
| 1265 | } | ||
| 1266 | |||
| 1267 | gfs2_trans_add_bh(ip->i_gl, bh[x], 1); | ||
| 1268 | |||
| 1269 | memcpy(bh[x]->b_data + sizeof(struct gfs2_meta_header), data, | ||
| 1270 | (sdp->sd_jbsize > amount) ? amount : sdp->sd_jbsize); | ||
| 1271 | |||
| 1272 | amount -= sdp->sd_jbsize; | ||
| 1273 | data += sdp->sd_jbsize; | ||
| 1274 | |||
| 1275 | brelse(bh[x]); | ||
| 1276 | } | ||
| 1277 | 1243 | ||
| 1278 | out: | 1244 | ret = gfs2_trans_begin(sdp, nptrs + RES_DINODE, 0); |
| 1279 | kfree(bh); | 1245 | if (ret) |
| 1280 | return error; | 1246 | return ret; |
| 1281 | 1247 | ||
| 1282 | fail: | 1248 | ret = gfs2_iter_unstuffed(ip, ea, data, NULL); |
| 1283 | gfs2_trans_end(sdp); | 1249 | gfs2_trans_end(sdp); |
| 1284 | kfree(bh); | 1250 | |
| 1285 | return error; | 1251 | return ret; |
| 1286 | } | 1252 | } |
| 1287 | 1253 | ||
| 1288 | int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data) | 1254 | int gfs2_xattr_acl_chmod(struct gfs2_inode *ip, struct iattr *attr, char *data) |
