summaryrefslogtreecommitdiffstats
path: root/fs/xfs/linux-2.6
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2011-07-08 08:36:19 -0400
committerChristoph Hellwig <hch@lst.de>2011-07-08 08:36:19 -0400
commit0c842ad46a51891ac4420b7285613f4134a65ccd (patch)
treecf82cc7853821a21998114d20b1297b14061eade /fs/xfs/linux-2.6
parentbbb4197c73be356a052dac25cce5ed0c157c6c90 (diff)
xfs: clean up buffer locking helpers
Rename xfs_buf_cond_lock and reverse it's return value to fit most other trylock operations in the Kernel and XFS (with the exception of down_trylock, after which xfs_buf_cond_lock was modelled), and replace xfs_buf_lock_val with an xfs_buf_islocked for use in asserts, or and opencoded variant in tracing. remove the XFS_BUF_* wrappers for all the locking helpers. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Alex Elder <aelder@sgi.com> Reviewed-by: Dave Chinner <dchinner@redhat.com>
Diffstat (limited to 'fs/xfs/linux-2.6')
-rw-r--r--fs/xfs/linux-2.6/xfs_buf.c31
-rw-r--r--fs/xfs/linux-2.6/xfs_buf.h9
-rw-r--r--fs/xfs/linux-2.6/xfs_trace.h10
3 files changed, 19 insertions, 31 deletions
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c
index 5e68099db2a5..c77227615403 100644
--- a/fs/xfs/linux-2.6/xfs_buf.c
+++ b/fs/xfs/linux-2.6/xfs_buf.c
@@ -499,16 +499,14 @@ found:
499 spin_unlock(&pag->pag_buf_lock); 499 spin_unlock(&pag->pag_buf_lock);
500 xfs_perag_put(pag); 500 xfs_perag_put(pag);
501 501
502 if (xfs_buf_cond_lock(bp)) { 502 if (!xfs_buf_trylock(bp)) {
503 /* failed, so wait for the lock if requested. */ 503 if (flags & XBF_TRYLOCK) {
504 if (!(flags & XBF_TRYLOCK)) {
505 xfs_buf_lock(bp);
506 XFS_STATS_INC(xb_get_locked_waited);
507 } else {
508 xfs_buf_rele(bp); 504 xfs_buf_rele(bp);
509 XFS_STATS_INC(xb_busy_locked); 505 XFS_STATS_INC(xb_busy_locked);
510 return NULL; 506 return NULL;
511 } 507 }
508 xfs_buf_lock(bp);
509 XFS_STATS_INC(xb_get_locked_waited);
512 } 510 }
513 511
514 /* 512 /*
@@ -896,8 +894,8 @@ xfs_buf_rele(
896 * to push on stale inode buffers. 894 * to push on stale inode buffers.
897 */ 895 */
898int 896int
899xfs_buf_cond_lock( 897xfs_buf_trylock(
900 xfs_buf_t *bp) 898 struct xfs_buf *bp)
901{ 899{
902 int locked; 900 int locked;
903 901
@@ -907,15 +905,8 @@ xfs_buf_cond_lock(
907 else if (atomic_read(&bp->b_pin_count) && (bp->b_flags & XBF_STALE)) 905 else if (atomic_read(&bp->b_pin_count) && (bp->b_flags & XBF_STALE))
908 xfs_log_force(bp->b_target->bt_mount, 0); 906 xfs_log_force(bp->b_target->bt_mount, 0);
909 907
910 trace_xfs_buf_cond_lock(bp, _RET_IP_); 908 trace_xfs_buf_trylock(bp, _RET_IP_);
911 return locked ? 0 : -EBUSY; 909 return locked;
912}
913
914int
915xfs_buf_lock_value(
916 xfs_buf_t *bp)
917{
918 return bp->b_sema.count;
919} 910}
920 911
921/* 912/*
@@ -929,7 +920,7 @@ xfs_buf_lock_value(
929 */ 920 */
930void 921void
931xfs_buf_lock( 922xfs_buf_lock(
932 xfs_buf_t *bp) 923 struct xfs_buf *bp)
933{ 924{
934 trace_xfs_buf_lock(bp, _RET_IP_); 925 trace_xfs_buf_lock(bp, _RET_IP_);
935 926
@@ -950,7 +941,7 @@ xfs_buf_lock(
950 */ 941 */
951void 942void
952xfs_buf_unlock( 943xfs_buf_unlock(
953 xfs_buf_t *bp) 944 struct xfs_buf *bp)
954{ 945{
955 if ((bp->b_flags & (XBF_DELWRI|_XBF_DELWRI_Q)) == XBF_DELWRI) { 946 if ((bp->b_flags & (XBF_DELWRI|_XBF_DELWRI_Q)) == XBF_DELWRI) {
956 atomic_inc(&bp->b_hold); 947 atomic_inc(&bp->b_hold);
@@ -1694,7 +1685,7 @@ xfs_buf_delwri_split(
1694 list_for_each_entry_safe(bp, n, dwq, b_list) { 1685 list_for_each_entry_safe(bp, n, dwq, b_list) {
1695 ASSERT(bp->b_flags & XBF_DELWRI); 1686 ASSERT(bp->b_flags & XBF_DELWRI);
1696 1687
1697 if (!XFS_BUF_ISPINNED(bp) && !xfs_buf_cond_lock(bp)) { 1688 if (!XFS_BUF_ISPINNED(bp) && xfs_buf_trylock(bp)) {
1698 if (!force && 1689 if (!force &&
1699 time_before(jiffies, bp->b_queuetime + age)) { 1690 time_before(jiffies, bp->b_queuetime + age)) {
1700 xfs_buf_unlock(bp); 1691 xfs_buf_unlock(bp);
diff --git a/fs/xfs/linux-2.6/xfs_buf.h b/fs/xfs/linux-2.6/xfs_buf.h
index 6847dc4dceeb..706c40069116 100644
--- a/fs/xfs/linux-2.6/xfs_buf.h
+++ b/fs/xfs/linux-2.6/xfs_buf.h
@@ -187,10 +187,11 @@ extern void xfs_buf_free(xfs_buf_t *);
187extern void xfs_buf_rele(xfs_buf_t *); 187extern void xfs_buf_rele(xfs_buf_t *);
188 188
189/* Locking and Unlocking Buffers */ 189/* Locking and Unlocking Buffers */
190extern int xfs_buf_cond_lock(xfs_buf_t *); 190extern int xfs_buf_trylock(xfs_buf_t *);
191extern int xfs_buf_lock_value(xfs_buf_t *);
192extern void xfs_buf_lock(xfs_buf_t *); 191extern void xfs_buf_lock(xfs_buf_t *);
193extern void xfs_buf_unlock(xfs_buf_t *); 192extern void xfs_buf_unlock(xfs_buf_t *);
193#define xfs_buf_islocked(bp) \
194 ((bp)->b_sema.count <= 0)
194 195
195/* Buffer Read and Write Routines */ 196/* Buffer Read and Write Routines */
196extern int xfs_bwrite(struct xfs_mount *mp, struct xfs_buf *bp); 197extern int xfs_bwrite(struct xfs_mount *mp, struct xfs_buf *bp);
@@ -308,10 +309,6 @@ xfs_buf_set_ref(
308 309
309#define XFS_BUF_ISPINNED(bp) atomic_read(&((bp)->b_pin_count)) 310#define XFS_BUF_ISPINNED(bp) atomic_read(&((bp)->b_pin_count))
310 311
311#define XFS_BUF_VALUSEMA(bp) xfs_buf_lock_value(bp)
312#define XFS_BUF_CPSEMA(bp) (xfs_buf_cond_lock(bp) == 0)
313#define XFS_BUF_VSEMA(bp) xfs_buf_unlock(bp)
314#define XFS_BUF_PSEMA(bp,x) xfs_buf_lock(bp)
315#define XFS_BUF_FINISH_IOWAIT(bp) complete(&bp->b_iowait); 312#define XFS_BUF_FINISH_IOWAIT(bp) complete(&bp->b_iowait);
316 313
317#define XFS_BUF_SET_TARGET(bp, target) ((bp)->b_target = (target)) 314#define XFS_BUF_SET_TARGET(bp, target) ((bp)->b_target = (target))
diff --git a/fs/xfs/linux-2.6/xfs_trace.h b/fs/xfs/linux-2.6/xfs_trace.h
index 4fe53f9f0477..3bdfcb9f52b7 100644
--- a/fs/xfs/linux-2.6/xfs_trace.h
+++ b/fs/xfs/linux-2.6/xfs_trace.h
@@ -293,7 +293,7 @@ DECLARE_EVENT_CLASS(xfs_buf_class,
293 __entry->buffer_length = bp->b_buffer_length; 293 __entry->buffer_length = bp->b_buffer_length;
294 __entry->hold = atomic_read(&bp->b_hold); 294 __entry->hold = atomic_read(&bp->b_hold);
295 __entry->pincount = atomic_read(&bp->b_pin_count); 295 __entry->pincount = atomic_read(&bp->b_pin_count);
296 __entry->lockval = xfs_buf_lock_value(bp); 296 __entry->lockval = bp->b_sema.count;
297 __entry->flags = bp->b_flags; 297 __entry->flags = bp->b_flags;
298 __entry->caller_ip = caller_ip; 298 __entry->caller_ip = caller_ip;
299 ), 299 ),
@@ -323,7 +323,7 @@ DEFINE_BUF_EVENT(xfs_buf_bawrite);
323DEFINE_BUF_EVENT(xfs_buf_bdwrite); 323DEFINE_BUF_EVENT(xfs_buf_bdwrite);
324DEFINE_BUF_EVENT(xfs_buf_lock); 324DEFINE_BUF_EVENT(xfs_buf_lock);
325DEFINE_BUF_EVENT(xfs_buf_lock_done); 325DEFINE_BUF_EVENT(xfs_buf_lock_done);
326DEFINE_BUF_EVENT(xfs_buf_cond_lock); 326DEFINE_BUF_EVENT(xfs_buf_trylock);
327DEFINE_BUF_EVENT(xfs_buf_unlock); 327DEFINE_BUF_EVENT(xfs_buf_unlock);
328DEFINE_BUF_EVENT(xfs_buf_iowait); 328DEFINE_BUF_EVENT(xfs_buf_iowait);
329DEFINE_BUF_EVENT(xfs_buf_iowait_done); 329DEFINE_BUF_EVENT(xfs_buf_iowait_done);
@@ -366,7 +366,7 @@ DECLARE_EVENT_CLASS(xfs_buf_flags_class,
366 __entry->flags = flags; 366 __entry->flags = flags;
367 __entry->hold = atomic_read(&bp->b_hold); 367 __entry->hold = atomic_read(&bp->b_hold);
368 __entry->pincount = atomic_read(&bp->b_pin_count); 368 __entry->pincount = atomic_read(&bp->b_pin_count);
369 __entry->lockval = xfs_buf_lock_value(bp); 369 __entry->lockval = bp->b_sema.count;
370 __entry->caller_ip = caller_ip; 370 __entry->caller_ip = caller_ip;
371 ), 371 ),
372 TP_printk("dev %d:%d bno 0x%llx len 0x%zx hold %d pincount %d " 372 TP_printk("dev %d:%d bno 0x%llx len 0x%zx hold %d pincount %d "
@@ -409,7 +409,7 @@ TRACE_EVENT(xfs_buf_ioerror,
409 __entry->buffer_length = bp->b_buffer_length; 409 __entry->buffer_length = bp->b_buffer_length;
410 __entry->hold = atomic_read(&bp->b_hold); 410 __entry->hold = atomic_read(&bp->b_hold);
411 __entry->pincount = atomic_read(&bp->b_pin_count); 411 __entry->pincount = atomic_read(&bp->b_pin_count);
412 __entry->lockval = xfs_buf_lock_value(bp); 412 __entry->lockval = bp->b_sema.count;
413 __entry->error = error; 413 __entry->error = error;
414 __entry->flags = bp->b_flags; 414 __entry->flags = bp->b_flags;
415 __entry->caller_ip = caller_ip; 415 __entry->caller_ip = caller_ip;
@@ -454,7 +454,7 @@ DECLARE_EVENT_CLASS(xfs_buf_item_class,
454 __entry->buf_flags = bip->bli_buf->b_flags; 454 __entry->buf_flags = bip->bli_buf->b_flags;
455 __entry->buf_hold = atomic_read(&bip->bli_buf->b_hold); 455 __entry->buf_hold = atomic_read(&bip->bli_buf->b_hold);
456 __entry->buf_pincount = atomic_read(&bip->bli_buf->b_pin_count); 456 __entry->buf_pincount = atomic_read(&bip->bli_buf->b_pin_count);
457 __entry->buf_lockval = xfs_buf_lock_value(bip->bli_buf); 457 __entry->buf_lockval = bip->bli_buf->b_sema.count;
458 __entry->li_desc = bip->bli_item.li_desc; 458 __entry->li_desc = bip->bli_item.li_desc;
459 __entry->li_flags = bip->bli_item.li_flags; 459 __entry->li_flags = bip->bli_item.li_flags;
460 ), 460 ),