nilfs2: fix lock order reversal in nilfs_clean_segments ioctl
[safe/jmp/linux-2.6] / fs / ntfs / compress.c
index 25d2410..9669541 100644 (file)
@@ -67,7 +67,7 @@ static DEFINE_SPINLOCK(ntfs_cb_lock);
 /**
  * allocate_compression_buffers - allocate the decompression buffers
  *
- * Caller has to hold the ntfs_lock semaphore.
+ * Caller has to hold the ntfs_lock mutex.
  *
  * Return 0 on success or -ENOMEM if the allocations failed.
  */
@@ -84,7 +84,7 @@ int allocate_compression_buffers(void)
 /**
  * free_compression_buffers - free the decompression buffers
  *
- * Caller has to hold the ntfs_lock semaphore.
+ * Caller has to hold the ntfs_lock mutex.
  */
 void free_compression_buffers(void)
 {
@@ -561,6 +561,16 @@ int ntfs_read_compressed_block(struct page *page)
        read_unlock_irqrestore(&ni->size_lock, flags);
        max_page = ((i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT) -
                        offset;
+       /* Is the page fully outside i_size? (truncate in progress) */
+       if (xpage >= max_page) {
+               kfree(bhs);
+               kfree(pages);
+               zero_user(page, 0, PAGE_CACHE_SIZE);
+               ntfs_debug("Compressed read outside i_size - truncated?");
+               SetPageUptodate(page);
+               unlock_page(page);
+               return 0;
+       }
        if (nr_pages < max_page)
                max_page = nr_pages;
        for (i = 0; i < max_page; i++, offset++) {
@@ -600,7 +610,7 @@ do_next_cb:
        rl = NULL;
        for (vcn = start_vcn, start_vcn += cb_clusters; vcn < start_vcn;
                        vcn++) {
-               BOOL is_retry = FALSE;
+               bool is_retry = false;
 
                if (!rl) {
 lock_retry_remap:
@@ -626,7 +636,7 @@ lock_retry_remap:
                                break;
                        if (is_retry || lcn != LCN_RL_NOT_MAPPED)
                                goto rl_err;
-                       is_retry = TRUE;
+                       is_retry = true;
                        /*
                         * Attempt to map runlist, dropping lock for the
                         * duration.
@@ -655,7 +665,7 @@ lock_retry_remap:
        for (i = 0; i < nr_bhs; i++) {
                struct buffer_head *tbh = bhs[i];
 
-               if (unlikely(test_set_buffer_locked(tbh)))
+               if (!trylock_buffer(tbh))
                        continue;
                if (unlikely(buffer_uptodate(tbh))) {
                        unlock_buffer(tbh);