]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/xfs/xfs_log.c
[SCSI] scsi_dh: create lookup cache
[linux-2.6-omap-h63xx.git] / fs / xfs / xfs_log.c
index afaee301b0ee1fa2e1c491f5bd2109ed277fabf1..ad3d26ddfe3160739908362ab2f2054d0bfb530e 100644 (file)
@@ -2427,13 +2427,20 @@ restart:
        if (iclog->ic_size - iclog->ic_offset < 2*sizeof(xlog_op_header_t)) {
                xlog_state_switch_iclogs(log, iclog, iclog->ic_size);
 
-               /* If I'm the only one writing to this iclog, sync it to disk */
-               if (atomic_read(&iclog->ic_refcnt) == 1) {
+               /*
+                * If I'm the only one writing to this iclog, sync it to disk.
+                * We need to do an atomic compare and decrement here to avoid
+                * racing with concurrent atomic_dec_and_lock() calls in
+                * xlog_state_release_iclog() when there is more than one
+                * reference to the iclog.
+                */
+               if (!atomic_add_unless(&iclog->ic_refcnt, -1, 1)) {
+                       /* we are the only one */
                        spin_unlock(&log->l_icloglock);
-                       if ((error = xlog_state_release_iclog(log, iclog)))
+                       error = xlog_state_release_iclog(log, iclog);
+                       if (error)
                                return error;
                } else {
-                       atomic_dec(&iclog->ic_refcnt);
                        spin_unlock(&log->l_icloglock);
                }
                goto restart;