diff options
Diffstat (limited to 'fs/ntfs/lcnalloc.c')
| -rw-r--r-- | fs/ntfs/lcnalloc.c | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/fs/ntfs/lcnalloc.c b/fs/ntfs/lcnalloc.c index a4bc07616e5d..7b5934290685 100644 --- a/fs/ntfs/lcnalloc.c +++ b/fs/ntfs/lcnalloc.c | |||
| @@ -54,6 +54,8 @@ int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol, | |||
| 54 | int ret = 0; | 54 | int ret = 0; |
| 55 | 55 | ||
| 56 | ntfs_debug("Entering."); | 56 | ntfs_debug("Entering."); |
| 57 | if (!rl) | ||
| 58 | return 0; | ||
| 57 | for (; rl->length; rl++) { | 59 | for (; rl->length; rl++) { |
| 58 | int err; | 60 | int err; |
| 59 | 61 | ||
| @@ -163,17 +165,9 @@ runlist_element *ntfs_cluster_alloc(ntfs_volume *vol, const VCN start_vcn, | |||
| 163 | BUG_ON(zone < FIRST_ZONE); | 165 | BUG_ON(zone < FIRST_ZONE); |
| 164 | BUG_ON(zone > LAST_ZONE); | 166 | BUG_ON(zone > LAST_ZONE); |
| 165 | 167 | ||
| 166 | /* Return empty runlist if @count == 0 */ | 168 | /* Return NULL if @count is zero. */ |
| 167 | // FIXME: Do we want to just return NULL instead? (AIA) | 169 | if (!count) |
| 168 | if (!count) { | 170 | return NULL; |
| 169 | rl = ntfs_malloc_nofs(PAGE_SIZE); | ||
| 170 | if (!rl) | ||
| 171 | return ERR_PTR(-ENOMEM); | ||
| 172 | rl[0].vcn = start_vcn; | ||
| 173 | rl[0].lcn = LCN_RL_NOT_MAPPED; | ||
| 174 | rl[0].length = 0; | ||
| 175 | return rl; | ||
| 176 | } | ||
| 177 | /* Take the lcnbmp lock for writing. */ | 171 | /* Take the lcnbmp lock for writing. */ |
| 178 | down_write(&vol->lcnbmp_lock); | 172 | down_write(&vol->lcnbmp_lock); |
| 179 | /* | 173 | /* |
| @@ -788,7 +782,8 @@ out: | |||
| 788 | * @vi: vfs inode whose runlist describes the clusters to free | 782 | * @vi: vfs inode whose runlist describes the clusters to free |
| 789 | * @start_vcn: vcn in the runlist of @vi at which to start freeing clusters | 783 | * @start_vcn: vcn in the runlist of @vi at which to start freeing clusters |
| 790 | * @count: number of clusters to free or -1 for all clusters | 784 | * @count: number of clusters to free or -1 for all clusters |
| 791 | * @is_rollback: if TRUE this is a rollback operation | 785 | * @write_locked: true if the runlist is locked for writing |
| 786 | * @is_rollback: true if this is a rollback operation | ||
| 792 | * | 787 | * |
| 793 | * Free @count clusters starting at the cluster @start_vcn in the runlist | 788 | * Free @count clusters starting at the cluster @start_vcn in the runlist |
| 794 | * described by the vfs inode @vi. | 789 | * described by the vfs inode @vi. |
| @@ -806,17 +801,17 @@ out: | |||
| 806 | * Return the number of deallocated clusters (not counting sparse ones) on | 801 | * Return the number of deallocated clusters (not counting sparse ones) on |
| 807 | * success and -errno on error. | 802 | * success and -errno on error. |
| 808 | * | 803 | * |
| 809 | * Locking: - The runlist described by @vi must be unlocked on entry and is | 804 | * Locking: - The runlist described by @vi must be locked on entry and is |
| 810 | * unlocked on return. | 805 | * locked on return. Note if the runlist is locked for reading the |
| 811 | * - This function takes the runlist lock of @vi for reading and | 806 | * lock may be dropped and reacquired. Note the runlist may be |
| 812 | * sometimes for writing and sometimes modifies the runlist. | 807 | * modified when needed runlist fragments need to be mapped. |
| 813 | * - The volume lcn bitmap must be unlocked on entry and is unlocked | 808 | * - The volume lcn bitmap must be unlocked on entry and is unlocked |
| 814 | * on return. | 809 | * on return. |
| 815 | * - This function takes the volume lcn bitmap lock for writing and | 810 | * - This function takes the volume lcn bitmap lock for writing and |
| 816 | * modifies the bitmap contents. | 811 | * modifies the bitmap contents. |
| 817 | */ | 812 | */ |
| 818 | s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count, | 813 | s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count, |
| 819 | const BOOL is_rollback) | 814 | const BOOL write_locked, const BOOL is_rollback) |
| 820 | { | 815 | { |
| 821 | s64 delta, to_free, total_freed, real_freed; | 816 | s64 delta, to_free, total_freed, real_freed; |
| 822 | ntfs_inode *ni; | 817 | ntfs_inode *ni; |
| @@ -848,8 +843,7 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count, | |||
| 848 | 843 | ||
| 849 | total_freed = real_freed = 0; | 844 | total_freed = real_freed = 0; |
| 850 | 845 | ||
| 851 | down_read(&ni->runlist.lock); | 846 | rl = ntfs_attr_find_vcn_nolock(ni, start_vcn, write_locked); |
| 852 | rl = ntfs_attr_find_vcn_nolock(ni, start_vcn, FALSE); | ||
| 853 | if (IS_ERR(rl)) { | 847 | if (IS_ERR(rl)) { |
| 854 | if (!is_rollback) | 848 | if (!is_rollback) |
| 855 | ntfs_error(vol->sb, "Failed to find first runlist " | 849 | ntfs_error(vol->sb, "Failed to find first runlist " |
| @@ -903,7 +897,7 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count, | |||
| 903 | 897 | ||
| 904 | /* Attempt to map runlist. */ | 898 | /* Attempt to map runlist. */ |
| 905 | vcn = rl->vcn; | 899 | vcn = rl->vcn; |
| 906 | rl = ntfs_attr_find_vcn_nolock(ni, vcn, FALSE); | 900 | rl = ntfs_attr_find_vcn_nolock(ni, vcn, write_locked); |
| 907 | if (IS_ERR(rl)) { | 901 | if (IS_ERR(rl)) { |
| 908 | err = PTR_ERR(rl); | 902 | err = PTR_ERR(rl); |
| 909 | if (!is_rollback) | 903 | if (!is_rollback) |
| @@ -950,7 +944,6 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count, | |||
| 950 | /* Update the total done clusters. */ | 944 | /* Update the total done clusters. */ |
| 951 | total_freed += to_free; | 945 | total_freed += to_free; |
| 952 | } | 946 | } |
| 953 | up_read(&ni->runlist.lock); | ||
| 954 | if (likely(!is_rollback)) | 947 | if (likely(!is_rollback)) |
| 955 | up_write(&vol->lcnbmp_lock); | 948 | up_write(&vol->lcnbmp_lock); |
| 956 | 949 | ||
| @@ -960,7 +953,6 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count, | |||
| 960 | ntfs_debug("Done."); | 953 | ntfs_debug("Done."); |
| 961 | return real_freed; | 954 | return real_freed; |
| 962 | err_out: | 955 | err_out: |
| 963 | up_read(&ni->runlist.lock); | ||
| 964 | if (is_rollback) | 956 | if (is_rollback) |
| 965 | return err; | 957 | return err; |
| 966 | /* If no real clusters were freed, no need to rollback. */ | 958 | /* If no real clusters were freed, no need to rollback. */ |
| @@ -973,7 +965,8 @@ err_out: | |||
| 973 | * If rollback fails, set the volume errors flag, emit an error | 965 | * If rollback fails, set the volume errors flag, emit an error |
| 974 | * message, and return the error code. | 966 | * message, and return the error code. |
| 975 | */ | 967 | */ |
| 976 | delta = __ntfs_cluster_free(vi, start_vcn, total_freed, TRUE); | 968 | delta = __ntfs_cluster_free(vi, start_vcn, total_freed, write_locked, |
| 969 | TRUE); | ||
| 977 | if (delta < 0) { | 970 | if (delta < 0) { |
| 978 | ntfs_error(vol->sb, "Failed to rollback (error %i). Leaving " | 971 | ntfs_error(vol->sb, "Failed to rollback (error %i). Leaving " |
| 979 | "inconsistent metadata! Unmount and run " | 972 | "inconsistent metadata! Unmount and run " |
