diff options
Diffstat (limited to 'fs/ntfs/mft.c')
-rw-r--r-- | fs/ntfs/mft.c | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c index eb3eb143a32c..4e72bc7afdf9 100644 --- a/fs/ntfs/mft.c +++ b/fs/ntfs/mft.c | |||
@@ -105,8 +105,8 @@ err_out: | |||
105 | * map_mft_record - map, pin and lock an mft record | 105 | * map_mft_record - map, pin and lock an mft record |
106 | * @ni: ntfs inode whose MFT record to map | 106 | * @ni: ntfs inode whose MFT record to map |
107 | * | 107 | * |
108 | * First, take the mrec_lock semaphore. We might now be sleeping, while waiting | 108 | * First, take the mrec_lock mutex. We might now be sleeping, while waiting |
109 | * for the semaphore if it was already locked by someone else. | 109 | * for the mutex if it was already locked by someone else. |
110 | * | 110 | * |
111 | * The page of the record is mapped using map_mft_record_page() before being | 111 | * The page of the record is mapped using map_mft_record_page() before being |
112 | * returned to the caller. | 112 | * returned to the caller. |
@@ -136,9 +136,9 @@ err_out: | |||
136 | * So that code will end up having to own the mrec_lock of all mft | 136 | * So that code will end up having to own the mrec_lock of all mft |
137 | * records/inodes present in the page before I/O can proceed. In that case we | 137 | * records/inodes present in the page before I/O can proceed. In that case we |
138 | * wouldn't need to bother with PG_locked and PG_uptodate as nobody will be | 138 | * wouldn't need to bother with PG_locked and PG_uptodate as nobody will be |
139 | * accessing anything without owning the mrec_lock semaphore. But we do need | 139 | * accessing anything without owning the mrec_lock mutex. But we do need to |
140 | * to use them because of the read_cache_page() invocation and the code becomes | 140 | * use them because of the read_cache_page() invocation and the code becomes so |
141 | * so much simpler this way that it is well worth it. | 141 | * much simpler this way that it is well worth it. |
142 | * | 142 | * |
143 | * The mft record is now ours and we return a pointer to it. You need to check | 143 | * The mft record is now ours and we return a pointer to it. You need to check |
144 | * the returned pointer with IS_ERR() and if that is true, PTR_ERR() will return | 144 | * the returned pointer with IS_ERR() and if that is true, PTR_ERR() will return |
@@ -161,13 +161,13 @@ MFT_RECORD *map_mft_record(ntfs_inode *ni) | |||
161 | atomic_inc(&ni->count); | 161 | atomic_inc(&ni->count); |
162 | 162 | ||
163 | /* Serialize access to this mft record. */ | 163 | /* Serialize access to this mft record. */ |
164 | down(&ni->mrec_lock); | 164 | mutex_lock(&ni->mrec_lock); |
165 | 165 | ||
166 | m = map_mft_record_page(ni); | 166 | m = map_mft_record_page(ni); |
167 | if (likely(!IS_ERR(m))) | 167 | if (likely(!IS_ERR(m))) |
168 | return m; | 168 | return m; |
169 | 169 | ||
170 | up(&ni->mrec_lock); | 170 | mutex_unlock(&ni->mrec_lock); |
171 | atomic_dec(&ni->count); | 171 | atomic_dec(&ni->count); |
172 | ntfs_error(ni->vol->sb, "Failed with error code %lu.", -PTR_ERR(m)); | 172 | ntfs_error(ni->vol->sb, "Failed with error code %lu.", -PTR_ERR(m)); |
173 | return m; | 173 | return m; |
@@ -218,7 +218,7 @@ void unmap_mft_record(ntfs_inode *ni) | |||
218 | ntfs_debug("Entering for mft_no 0x%lx.", ni->mft_no); | 218 | ntfs_debug("Entering for mft_no 0x%lx.", ni->mft_no); |
219 | 219 | ||
220 | unmap_mft_record_page(ni); | 220 | unmap_mft_record_page(ni); |
221 | up(&ni->mrec_lock); | 221 | mutex_unlock(&ni->mrec_lock); |
222 | atomic_dec(&ni->count); | 222 | atomic_dec(&ni->count); |
223 | /* | 223 | /* |
224 | * If pure ntfs_inode, i.e. no vfs inode attached, we leave it to | 224 | * If pure ntfs_inode, i.e. no vfs inode attached, we leave it to |
@@ -262,7 +262,7 @@ MFT_RECORD *map_extent_mft_record(ntfs_inode *base_ni, MFT_REF mref, | |||
262 | * in which case just return it. If not found, add it to the base | 262 | * in which case just return it. If not found, add it to the base |
263 | * inode before returning it. | 263 | * inode before returning it. |
264 | */ | 264 | */ |
265 | down(&base_ni->extent_lock); | 265 | mutex_lock(&base_ni->extent_lock); |
266 | if (base_ni->nr_extents > 0) { | 266 | if (base_ni->nr_extents > 0) { |
267 | extent_nis = base_ni->ext.extent_ntfs_inos; | 267 | extent_nis = base_ni->ext.extent_ntfs_inos; |
268 | for (i = 0; i < base_ni->nr_extents; i++) { | 268 | for (i = 0; i < base_ni->nr_extents; i++) { |
@@ -275,7 +275,7 @@ MFT_RECORD *map_extent_mft_record(ntfs_inode *base_ni, MFT_REF mref, | |||
275 | } | 275 | } |
276 | } | 276 | } |
277 | if (likely(ni != NULL)) { | 277 | if (likely(ni != NULL)) { |
278 | up(&base_ni->extent_lock); | 278 | mutex_unlock(&base_ni->extent_lock); |
279 | atomic_dec(&base_ni->count); | 279 | atomic_dec(&base_ni->count); |
280 | /* We found the record; just have to map and return it. */ | 280 | /* We found the record; just have to map and return it. */ |
281 | m = map_mft_record(ni); | 281 | m = map_mft_record(ni); |
@@ -302,7 +302,7 @@ map_err_out: | |||
302 | /* Record wasn't there. Get a new ntfs inode and initialize it. */ | 302 | /* Record wasn't there. Get a new ntfs inode and initialize it. */ |
303 | ni = ntfs_new_extent_inode(base_ni->vol->sb, mft_no); | 303 | ni = ntfs_new_extent_inode(base_ni->vol->sb, mft_no); |
304 | if (unlikely(!ni)) { | 304 | if (unlikely(!ni)) { |
305 | up(&base_ni->extent_lock); | 305 | mutex_unlock(&base_ni->extent_lock); |
306 | atomic_dec(&base_ni->count); | 306 | atomic_dec(&base_ni->count); |
307 | return ERR_PTR(-ENOMEM); | 307 | return ERR_PTR(-ENOMEM); |
308 | } | 308 | } |
@@ -313,7 +313,7 @@ map_err_out: | |||
313 | /* Now map the record. */ | 313 | /* Now map the record. */ |
314 | m = map_mft_record(ni); | 314 | m = map_mft_record(ni); |
315 | if (IS_ERR(m)) { | 315 | if (IS_ERR(m)) { |
316 | up(&base_ni->extent_lock); | 316 | mutex_unlock(&base_ni->extent_lock); |
317 | atomic_dec(&base_ni->count); | 317 | atomic_dec(&base_ni->count); |
318 | ntfs_clear_extent_inode(ni); | 318 | ntfs_clear_extent_inode(ni); |
319 | goto map_err_out; | 319 | goto map_err_out; |
@@ -348,14 +348,14 @@ map_err_out: | |||
348 | base_ni->ext.extent_ntfs_inos = tmp; | 348 | base_ni->ext.extent_ntfs_inos = tmp; |
349 | } | 349 | } |
350 | base_ni->ext.extent_ntfs_inos[base_ni->nr_extents++] = ni; | 350 | base_ni->ext.extent_ntfs_inos[base_ni->nr_extents++] = ni; |
351 | up(&base_ni->extent_lock); | 351 | mutex_unlock(&base_ni->extent_lock); |
352 | atomic_dec(&base_ni->count); | 352 | atomic_dec(&base_ni->count); |
353 | ntfs_debug("Done 2."); | 353 | ntfs_debug("Done 2."); |
354 | *ntfs_ino = ni; | 354 | *ntfs_ino = ni; |
355 | return m; | 355 | return m; |
356 | unm_err_out: | 356 | unm_err_out: |
357 | unmap_mft_record(ni); | 357 | unmap_mft_record(ni); |
358 | up(&base_ni->extent_lock); | 358 | mutex_unlock(&base_ni->extent_lock); |
359 | atomic_dec(&base_ni->count); | 359 | atomic_dec(&base_ni->count); |
360 | /* | 360 | /* |
361 | * If the extent inode was not attached to the base inode we need to | 361 | * If the extent inode was not attached to the base inode we need to |
@@ -400,12 +400,12 @@ void __mark_mft_record_dirty(ntfs_inode *ni) | |||
400 | BUG_ON(NInoAttr(ni)); | 400 | BUG_ON(NInoAttr(ni)); |
401 | mark_ntfs_record_dirty(ni->page, ni->page_ofs); | 401 | mark_ntfs_record_dirty(ni->page, ni->page_ofs); |
402 | /* Determine the base vfs inode and mark it dirty, too. */ | 402 | /* Determine the base vfs inode and mark it dirty, too. */ |
403 | down(&ni->extent_lock); | 403 | mutex_lock(&ni->extent_lock); |
404 | if (likely(ni->nr_extents >= 0)) | 404 | if (likely(ni->nr_extents >= 0)) |
405 | base_ni = ni; | 405 | base_ni = ni; |
406 | else | 406 | else |
407 | base_ni = ni->ext.base_ntfs_ino; | 407 | base_ni = ni->ext.base_ntfs_ino; |
408 | up(&ni->extent_lock); | 408 | mutex_unlock(&ni->extent_lock); |
409 | __mark_inode_dirty(VFS_I(base_ni), I_DIRTY_SYNC | I_DIRTY_DATASYNC); | 409 | __mark_inode_dirty(VFS_I(base_ni), I_DIRTY_SYNC | I_DIRTY_DATASYNC); |
410 | } | 410 | } |
411 | 411 | ||
@@ -981,7 +981,7 @@ BOOL ntfs_may_write_mft_record(ntfs_volume *vol, const unsigned long mft_no, | |||
981 | } | 981 | } |
982 | ntfs_debug("Inode 0x%lx is not dirty.", mft_no); | 982 | ntfs_debug("Inode 0x%lx is not dirty.", mft_no); |
983 | /* The inode is not dirty, try to take the mft record lock. */ | 983 | /* The inode is not dirty, try to take the mft record lock. */ |
984 | if (unlikely(down_trylock(&ni->mrec_lock))) { | 984 | if (unlikely(!mutex_trylock(&ni->mrec_lock))) { |
985 | ntfs_debug("Mft record 0x%lx is already locked, do " | 985 | ntfs_debug("Mft record 0x%lx is already locked, do " |
986 | "not write it.", mft_no); | 986 | "not write it.", mft_no); |
987 | atomic_dec(&ni->count); | 987 | atomic_dec(&ni->count); |
@@ -1041,13 +1041,13 @@ BOOL ntfs_may_write_mft_record(ntfs_volume *vol, const unsigned long mft_no, | |||
1041 | * corresponding to this extent mft record attached. | 1041 | * corresponding to this extent mft record attached. |
1042 | */ | 1042 | */ |
1043 | ni = NTFS_I(vi); | 1043 | ni = NTFS_I(vi); |
1044 | down(&ni->extent_lock); | 1044 | mutex_lock(&ni->extent_lock); |
1045 | if (ni->nr_extents <= 0) { | 1045 | if (ni->nr_extents <= 0) { |
1046 | /* | 1046 | /* |
1047 | * The base inode has no attached extent inodes, write this | 1047 | * The base inode has no attached extent inodes, write this |
1048 | * extent mft record. | 1048 | * extent mft record. |
1049 | */ | 1049 | */ |
1050 | up(&ni->extent_lock); | 1050 | mutex_unlock(&ni->extent_lock); |
1051 | iput(vi); | 1051 | iput(vi); |
1052 | ntfs_debug("Base inode 0x%lx has no attached extent inodes, " | 1052 | ntfs_debug("Base inode 0x%lx has no attached extent inodes, " |
1053 | "write the extent record.", na.mft_no); | 1053 | "write the extent record.", na.mft_no); |
@@ -1070,7 +1070,7 @@ BOOL ntfs_may_write_mft_record(ntfs_volume *vol, const unsigned long mft_no, | |||
1070 | * extent mft record. | 1070 | * extent mft record. |
1071 | */ | 1071 | */ |
1072 | if (!eni) { | 1072 | if (!eni) { |
1073 | up(&ni->extent_lock); | 1073 | mutex_unlock(&ni->extent_lock); |
1074 | iput(vi); | 1074 | iput(vi); |
1075 | ntfs_debug("Extent inode 0x%lx is not attached to its base " | 1075 | ntfs_debug("Extent inode 0x%lx is not attached to its base " |
1076 | "inode 0x%lx, write the extent record.", | 1076 | "inode 0x%lx, write the extent record.", |
@@ -1081,12 +1081,12 @@ BOOL ntfs_may_write_mft_record(ntfs_volume *vol, const unsigned long mft_no, | |||
1081 | mft_no, na.mft_no); | 1081 | mft_no, na.mft_no); |
1082 | /* Take a reference to the extent ntfs inode. */ | 1082 | /* Take a reference to the extent ntfs inode. */ |
1083 | atomic_inc(&eni->count); | 1083 | atomic_inc(&eni->count); |
1084 | up(&ni->extent_lock); | 1084 | mutex_unlock(&ni->extent_lock); |
1085 | /* | 1085 | /* |
1086 | * Found the extent inode coresponding to this extent mft record. | 1086 | * Found the extent inode coresponding to this extent mft record. |
1087 | * Try to take the mft record lock. | 1087 | * Try to take the mft record lock. |
1088 | */ | 1088 | */ |
1089 | if (unlikely(down_trylock(&eni->mrec_lock))) { | 1089 | if (unlikely(!mutex_trylock(&eni->mrec_lock))) { |
1090 | atomic_dec(&eni->count); | 1090 | atomic_dec(&eni->count); |
1091 | iput(vi); | 1091 | iput(vi); |
1092 | ntfs_debug("Extent mft record 0x%lx is already locked, do " | 1092 | ntfs_debug("Extent mft record 0x%lx is already locked, do " |
@@ -2709,7 +2709,7 @@ mft_rec_already_initialized: | |||
2709 | * have its page mapped and it is very easy to do. | 2709 | * have its page mapped and it is very easy to do. |
2710 | */ | 2710 | */ |
2711 | atomic_inc(&ni->count); | 2711 | atomic_inc(&ni->count); |
2712 | down(&ni->mrec_lock); | 2712 | mutex_lock(&ni->mrec_lock); |
2713 | ni->page = page; | 2713 | ni->page = page; |
2714 | ni->page_ofs = ofs; | 2714 | ni->page_ofs = ofs; |
2715 | /* | 2715 | /* |
@@ -2796,22 +2796,22 @@ int ntfs_extent_mft_record_free(ntfs_inode *ni, MFT_RECORD *m) | |||
2796 | BUG_ON(NInoAttr(ni)); | 2796 | BUG_ON(NInoAttr(ni)); |
2797 | BUG_ON(ni->nr_extents != -1); | 2797 | BUG_ON(ni->nr_extents != -1); |
2798 | 2798 | ||
2799 | down(&ni->extent_lock); | 2799 | mutex_lock(&ni->extent_lock); |
2800 | base_ni = ni->ext.base_ntfs_ino; | 2800 | base_ni = ni->ext.base_ntfs_ino; |
2801 | up(&ni->extent_lock); | 2801 | mutex_unlock(&ni->extent_lock); |
2802 | 2802 | ||
2803 | BUG_ON(base_ni->nr_extents <= 0); | 2803 | BUG_ON(base_ni->nr_extents <= 0); |
2804 | 2804 | ||
2805 | ntfs_debug("Entering for extent inode 0x%lx, base inode 0x%lx.\n", | 2805 | ntfs_debug("Entering for extent inode 0x%lx, base inode 0x%lx.\n", |
2806 | mft_no, base_ni->mft_no); | 2806 | mft_no, base_ni->mft_no); |
2807 | 2807 | ||
2808 | down(&base_ni->extent_lock); | 2808 | mutex_lock(&base_ni->extent_lock); |
2809 | 2809 | ||
2810 | /* Make sure we are holding the only reference to the extent inode. */ | 2810 | /* Make sure we are holding the only reference to the extent inode. */ |
2811 | if (atomic_read(&ni->count) > 2) { | 2811 | if (atomic_read(&ni->count) > 2) { |
2812 | ntfs_error(vol->sb, "Tried to free busy extent inode 0x%lx, " | 2812 | ntfs_error(vol->sb, "Tried to free busy extent inode 0x%lx, " |
2813 | "not freeing.", base_ni->mft_no); | 2813 | "not freeing.", base_ni->mft_no); |
2814 | up(&base_ni->extent_lock); | 2814 | mutex_unlock(&base_ni->extent_lock); |
2815 | return -EBUSY; | 2815 | return -EBUSY; |
2816 | } | 2816 | } |
2817 | 2817 | ||
@@ -2829,7 +2829,7 @@ int ntfs_extent_mft_record_free(ntfs_inode *ni, MFT_RECORD *m) | |||
2829 | break; | 2829 | break; |
2830 | } | 2830 | } |
2831 | 2831 | ||
2832 | up(&base_ni->extent_lock); | 2832 | mutex_unlock(&base_ni->extent_lock); |
2833 | 2833 | ||
2834 | if (unlikely(err)) { | 2834 | if (unlikely(err)) { |
2835 | ntfs_error(vol->sb, "Extent inode 0x%lx is not attached to " | 2835 | ntfs_error(vol->sb, "Extent inode 0x%lx is not attached to " |
@@ -2888,7 +2888,7 @@ rollback_error: | |||
2888 | return 0; | 2888 | return 0; |
2889 | rollback: | 2889 | rollback: |
2890 | /* Rollback what we did... */ | 2890 | /* Rollback what we did... */ |
2891 | down(&base_ni->extent_lock); | 2891 | mutex_lock(&base_ni->extent_lock); |
2892 | extent_nis = base_ni->ext.extent_ntfs_inos; | 2892 | extent_nis = base_ni->ext.extent_ntfs_inos; |
2893 | if (!(base_ni->nr_extents & 3)) { | 2893 | if (!(base_ni->nr_extents & 3)) { |
2894 | int new_size = (base_ni->nr_extents + 4) * sizeof(ntfs_inode*); | 2894 | int new_size = (base_ni->nr_extents + 4) * sizeof(ntfs_inode*); |
@@ -2897,7 +2897,7 @@ rollback: | |||
2897 | if (unlikely(!extent_nis)) { | 2897 | if (unlikely(!extent_nis)) { |
2898 | ntfs_error(vol->sb, "Failed to allocate internal " | 2898 | ntfs_error(vol->sb, "Failed to allocate internal " |
2899 | "buffer during rollback.%s", es); | 2899 | "buffer during rollback.%s", es); |
2900 | up(&base_ni->extent_lock); | 2900 | mutex_unlock(&base_ni->extent_lock); |
2901 | NVolSetErrors(vol); | 2901 | NVolSetErrors(vol); |
2902 | goto rollback_error; | 2902 | goto rollback_error; |
2903 | } | 2903 | } |
@@ -2912,7 +2912,7 @@ rollback: | |||
2912 | m->flags |= MFT_RECORD_IN_USE; | 2912 | m->flags |= MFT_RECORD_IN_USE; |
2913 | m->sequence_number = old_seq_no; | 2913 | m->sequence_number = old_seq_no; |
2914 | extent_nis[base_ni->nr_extents++] = ni; | 2914 | extent_nis[base_ni->nr_extents++] = ni; |
2915 | up(&base_ni->extent_lock); | 2915 | mutex_unlock(&base_ni->extent_lock); |
2916 | mark_mft_record_dirty(ni); | 2916 | mark_mft_record_dirty(ni); |
2917 | return err; | 2917 | return err; |
2918 | } | 2918 | } |