Skip to content

Commit 4e5e529

Browse files
Ingo MolnarAntonAltaparmakov
authored andcommitted
NTFS: Semaphore to mutex conversion.
The conversion was generated via scripts, and the result was validated automatically via a script as well. Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Anton Altaparmakov <aia21@cantab.net>
1 parent 834ba60 commit 4e5e529

8 files changed

Lines changed: 71 additions & 69 deletions

File tree

‎fs/ntfs/ChangeLog‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ ToDo/Notes:
4343
fs/ntfs/inode.c::ntfs_write_inode().
4444
- Handle the recently introduced -ENAMETOOLONG return value from
4545
fs/ntfs/unistr.c::ntfs_nlstoucs() in fs/ntfs/namei.c::ntfs_lookup().
46+
- Semaphore to mutex conversion. (Ingo Molnar)
4647

4748
2.1.26 - Minor bug fixes and updates.
4849

‎fs/ntfs/aops.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,18 +1278,18 @@ static int ntfs_write_mst_block(struct page *page,
12781278

12791279
tni = locked_nis[nr_locked_nis];
12801280
/* Get the base inode. */
1281-
down(&tni->extent_lock);
1281+
mutex_lock(&tni->extent_lock);
12821282
if (tni->nr_extents >= 0)
12831283
base_tni = tni;
12841284
else {
12851285
base_tni = tni->ext.base_ntfs_ino;
12861286
BUG_ON(!base_tni);
12871287
}
1288-
up(&tni->extent_lock);
1288+
mutex_unlock(&tni->extent_lock);
12891289
ntfs_debug("Unlocking %s inode 0x%lx.",
12901290
tni == base_tni ? "base" : "extent",
12911291
tni->mft_no);
1292-
up(&tni->mrec_lock);
1292+
mutex_unlock(&tni->mrec_lock);
12931293
atomic_dec(&tni->count);
12941294
iput(VFS_I(base_tni));
12951295
}

‎fs/ntfs/compress.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static DEFINE_SPINLOCK(ntfs_cb_lock);
6767
/**
6868
* allocate_compression_buffers - allocate the decompression buffers
6969
*
70-
* Caller has to hold the ntfs_lock semaphore.
70+
* Caller has to hold the ntfs_lock mutex.
7171
*
7272
* Return 0 on success or -ENOMEM if the allocations failed.
7373
*/
@@ -84,7 +84,7 @@ int allocate_compression_buffers(void)
8484
/**
8585
* free_compression_buffers - free the decompression buffers
8686
*
87-
* Caller has to hold the ntfs_lock semaphore.
87+
* Caller has to hold the ntfs_lock mutex.
8888
*/
8989
void free_compression_buffers(void)
9090
{

‎fs/ntfs/inode.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ void __ntfs_init_inode(struct super_block *sb, ntfs_inode *ni)
388388
atomic_set(&ni->count, 1);
389389
ni->vol = NTFS_SB(sb);
390390
ntfs_init_runlist(&ni->runlist);
391-
init_MUTEX(&ni->mrec_lock);
391+
mutex_init(&ni->mrec_lock);
392392
ni->page = NULL;
393393
ni->page_ofs = 0;
394394
ni->attr_list_size = 0;
@@ -400,7 +400,7 @@ void __ntfs_init_inode(struct super_block *sb, ntfs_inode *ni)
400400
ni->itype.index.collation_rule = 0;
401401
ni->itype.index.block_size_bits = 0;
402402
ni->itype.index.vcn_size_bits = 0;
403-
init_MUTEX(&ni->extent_lock);
403+
mutex_init(&ni->extent_lock);
404404
ni->nr_extents = 0;
405405
ni->ext.base_ntfs_ino = NULL;
406406
}
@@ -3066,7 +3066,7 @@ int ntfs_write_inode(struct inode *vi, int sync)
30663066
*/
30673067
if (modified) {
30683068
flush_dcache_mft_record_page(ctx->ntfs_ino);
3069-
if (!NInoTestSetDirty(ctx->ntfs_ino)) {
3069+
if (!NInoTestSetDirty(ctx->ntfs_ino))
30703070
mark_ntfs_record_dirty(ctx->ntfs_ino->page,
30713071
ctx->ntfs_ino->page_ofs);
30723072
}
@@ -3075,7 +3075,7 @@ int ntfs_write_inode(struct inode *vi, int sync)
30753075
if (NInoDirty(ni))
30763076
err = write_mft_record(ni, m, sync);
30773077
/* Write all attached extent mft records. */
3078-
down(&ni->extent_lock);
3078+
mutex_lock(&ni->extent_lock);
30793079
if (ni->nr_extents > 0) {
30803080
ntfs_inode **extent_nis = ni->ext.extent_ntfs_inos;
30813081
int i;
@@ -3102,7 +3102,7 @@ int ntfs_write_inode(struct inode *vi, int sync)
31023102
}
31033103
}
31043104
}
3105-
up(&ni->extent_lock);
3105+
mutex_unlock(&ni->extent_lock);
31063106
unmap_mft_record(ni);
31073107
if (unlikely(err))
31083108
goto err_out;

‎fs/ntfs/inode.h‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
#ifndef _LINUX_NTFS_INODE_H
2525
#define _LINUX_NTFS_INODE_H
2626

27-
#include <linux/mm.h>
27+
#include <asm/atomic.h>
28+
2829
#include <linux/fs.h>
29-
#include <linux/seq_file.h>
3030
#include <linux/list.h>
31-
#include <asm/atomic.h>
32-
#include <asm/semaphore.h>
31+
#include <linux/mm.h>
32+
#include <linux/mutex.h>
33+
#include <linux/seq_file.h>
3334

3435
#include "layout.h"
3536
#include "volume.h"
@@ -81,7 +82,7 @@ struct _ntfs_inode {
8182
* The following fields are only valid for real inodes and extent
8283
* inodes.
8384
*/
84-
struct semaphore mrec_lock; /* Lock for serializing access to the
85+
struct mutex mrec_lock; /* Lock for serializing access to the
8586
mft record belonging to this inode. */
8687
struct page *page; /* The page containing the mft record of the
8788
inode. This should only be touched by the
@@ -119,7 +120,7 @@ struct _ntfs_inode {
119120
u8 block_clusters; /* Number of clusters per cb. */
120121
} compressed;
121122
} itype;
122-
struct semaphore extent_lock; /* Lock for accessing/modifying the
123+
struct mutex extent_lock; /* Lock for accessing/modifying the
123124
below . */
124125
s32 nr_extents; /* For a base mft record, the number of attached extent
125126
inodes (0 if none), for extent records and for fake

‎fs/ntfs/mft.c‎

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ static inline MFT_RECORD *map_mft_record_page(ntfs_inode *ni)
105105
* map_mft_record - map, pin and lock an mft record
106106
* @ni: ntfs inode whose MFT record to map
107107
*
108-
* First, take the mrec_lock semaphore. We might now be sleeping, while waiting
109-
* for the semaphore if it was already locked by someone else.
108+
* First, take the mrec_lock mutex. We might now be sleeping, while waiting
109+
* for the mutex if it was already locked by someone else.
110110
*
111111
* The page of the record is mapped using map_mft_record_page() before being
112112
* returned to the caller.
@@ -136,9 +136,9 @@ static inline MFT_RECORD *map_mft_record_page(ntfs_inode *ni)
136136
* So that code will end up having to own the mrec_lock of all mft
137137
* records/inodes present in the page before I/O can proceed. In that case we
138138
* 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
140-
* to use them because of the read_cache_page() invocation and the code becomes
141-
* so much simpler this way that it is well worth it.
139+
* accessing anything without owning the mrec_lock mutex. But we do need to
140+
* use them because of the read_cache_page() invocation and the code becomes so
141+
* much simpler this way that it is well worth it.
142142
*
143143
* The mft record is now ours and we return a pointer to it. You need to check
144144
* 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)
161161
atomic_inc(&ni->count);
162162

163163
/* Serialize access to this mft record. */
164-
down(&ni->mrec_lock);
164+
mutex_lock(&ni->mrec_lock);
165165

166166
m = map_mft_record_page(ni);
167167
if (likely(!IS_ERR(m)))
168168
return m;
169169

170-
up(&ni->mrec_lock);
170+
mutex_unlock(&ni->mrec_lock);
171171
atomic_dec(&ni->count);
172172
ntfs_error(ni->vol->sb, "Failed with error code %lu.", -PTR_ERR(m));
173173
return m;
@@ -218,7 +218,7 @@ void unmap_mft_record(ntfs_inode *ni)
218218
ntfs_debug("Entering for mft_no 0x%lx.", ni->mft_no);
219219

220220
unmap_mft_record_page(ni);
221-
up(&ni->mrec_lock);
221+
mutex_unlock(&ni->mrec_lock);
222222
atomic_dec(&ni->count);
223223
/*
224224
* 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,
262262
* in which case just return it. If not found, add it to the base
263263
* inode before returning it.
264264
*/
265-
down(&base_ni->extent_lock);
265+
mutex_lock(&base_ni->extent_lock);
266266
if (base_ni->nr_extents > 0) {
267267
extent_nis = base_ni->ext.extent_ntfs_inos;
268268
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,
275275
}
276276
}
277277
if (likely(ni != NULL)) {
278-
up(&base_ni->extent_lock);
278+
mutex_unlock(&base_ni->extent_lock);
279279
atomic_dec(&base_ni->count);
280280
/* We found the record; just have to map and return it. */
281281
m = map_mft_record(ni);
@@ -302,7 +302,7 @@ MFT_RECORD *map_extent_mft_record(ntfs_inode *base_ni, MFT_REF mref,
302302
/* Record wasn't there. Get a new ntfs inode and initialize it. */
303303
ni = ntfs_new_extent_inode(base_ni->vol->sb, mft_no);
304304
if (unlikely(!ni)) {
305-
up(&base_ni->extent_lock);
305+
mutex_unlock(&base_ni->extent_lock);
306306
atomic_dec(&base_ni->count);
307307
return ERR_PTR(-ENOMEM);
308308
}
@@ -313,7 +313,7 @@ MFT_RECORD *map_extent_mft_record(ntfs_inode *base_ni, MFT_REF mref,
313313
/* Now map the record. */
314314
m = map_mft_record(ni);
315315
if (IS_ERR(m)) {
316-
up(&base_ni->extent_lock);
316+
mutex_unlock(&base_ni->extent_lock);
317317
atomic_dec(&base_ni->count);
318318
ntfs_clear_extent_inode(ni);
319319
goto map_err_out;
@@ -348,14 +348,14 @@ MFT_RECORD *map_extent_mft_record(ntfs_inode *base_ni, MFT_REF mref,
348348
base_ni->ext.extent_ntfs_inos = tmp;
349349
}
350350
base_ni->ext.extent_ntfs_inos[base_ni->nr_extents++] = ni;
351-
up(&base_ni->extent_lock);
351+
mutex_unlock(&base_ni->extent_lock);
352352
atomic_dec(&base_ni->count);
353353
ntfs_debug("Done 2.");
354354
*ntfs_ino = ni;
355355
return m;
356356
unm_err_out:
357357
unmap_mft_record(ni);
358-
up(&base_ni->extent_lock);
358+
mutex_unlock(&base_ni->extent_lock);
359359
atomic_dec(&base_ni->count);
360360
/*
361361
* 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)
400400
BUG_ON(NInoAttr(ni));
401401
mark_ntfs_record_dirty(ni->page, ni->page_ofs);
402402
/* Determine the base vfs inode and mark it dirty, too. */
403-
down(&ni->extent_lock);
403+
mutex_lock(&ni->extent_lock);
404404
if (likely(ni->nr_extents >= 0))
405405
base_ni = ni;
406406
else
407407
base_ni = ni->ext.base_ntfs_ino;
408-
up(&ni->extent_lock);
408+
mutex_unlock(&ni->extent_lock);
409409
__mark_inode_dirty(VFS_I(base_ni), I_DIRTY_SYNC | I_DIRTY_DATASYNC);
410410
}
411411

@@ -981,7 +981,7 @@ BOOL ntfs_may_write_mft_record(ntfs_volume *vol, const unsigned long mft_no,
981981
}
982982
ntfs_debug("Inode 0x%lx is not dirty.", mft_no);
983983
/* 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))) {
985985
ntfs_debug("Mft record 0x%lx is already locked, do "
986986
"not write it.", mft_no);
987987
atomic_dec(&ni->count);
@@ -1041,13 +1041,13 @@ BOOL ntfs_may_write_mft_record(ntfs_volume *vol, const unsigned long mft_no,
10411041
* corresponding to this extent mft record attached.
10421042
*/
10431043
ni = NTFS_I(vi);
1044-
down(&ni->extent_lock);
1044+
mutex_lock(&ni->extent_lock);
10451045
if (ni->nr_extents <= 0) {
10461046
/*
10471047
* The base inode has no attached extent inodes, write this
10481048
* extent mft record.
10491049
*/
1050-
up(&ni->extent_lock);
1050+
mutex_unlock(&ni->extent_lock);
10511051
iput(vi);
10521052
ntfs_debug("Base inode 0x%lx has no attached extent inodes, "
10531053
"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,
10701070
* extent mft record.
10711071
*/
10721072
if (!eni) {
1073-
up(&ni->extent_lock);
1073+
mutex_unlock(&ni->extent_lock);
10741074
iput(vi);
10751075
ntfs_debug("Extent inode 0x%lx is not attached to its base "
10761076
"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,
10811081
mft_no, na.mft_no);
10821082
/* Take a reference to the extent ntfs inode. */
10831083
atomic_inc(&eni->count);
1084-
up(&ni->extent_lock);
1084+
mutex_unlock(&ni->extent_lock);
10851085
/*
10861086
* Found the extent inode coresponding to this extent mft record.
10871087
* Try to take the mft record lock.
10881088
*/
1089-
if (unlikely(down_trylock(&eni->mrec_lock))) {
1089+
if (unlikely(!mutex_trylock(&eni->mrec_lock))) {
10901090
atomic_dec(&eni->count);
10911091
iput(vi);
10921092
ntfs_debug("Extent mft record 0x%lx is already locked, do "
@@ -2709,7 +2709,7 @@ ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, const int mode,
27092709
* have its page mapped and it is very easy to do.
27102710
*/
27112711
atomic_inc(&ni->count);
2712-
down(&ni->mrec_lock);
2712+
mutex_lock(&ni->mrec_lock);
27132713
ni->page = page;
27142714
ni->page_ofs = ofs;
27152715
/*
@@ -2796,22 +2796,22 @@ int ntfs_extent_mft_record_free(ntfs_inode *ni, MFT_RECORD *m)
27962796
BUG_ON(NInoAttr(ni));
27972797
BUG_ON(ni->nr_extents != -1);
27982798

2799-
down(&ni->extent_lock);
2799+
mutex_lock(&ni->extent_lock);
28002800
base_ni = ni->ext.base_ntfs_ino;
2801-
up(&ni->extent_lock);
2801+
mutex_unlock(&ni->extent_lock);
28022802

28032803
BUG_ON(base_ni->nr_extents <= 0);
28042804

28052805
ntfs_debug("Entering for extent inode 0x%lx, base inode 0x%lx.\n",
28062806
mft_no, base_ni->mft_no);
28072807

2808-
down(&base_ni->extent_lock);
2808+
mutex_lock(&base_ni->extent_lock);
28092809

28102810
/* Make sure we are holding the only reference to the extent inode. */
28112811
if (atomic_read(&ni->count) > 2) {
28122812
ntfs_error(vol->sb, "Tried to free busy extent inode 0x%lx, "
28132813
"not freeing.", base_ni->mft_no);
2814-
up(&base_ni->extent_lock);
2814+
mutex_unlock(&base_ni->extent_lock);
28152815
return -EBUSY;
28162816
}
28172817

@@ -2829,7 +2829,7 @@ int ntfs_extent_mft_record_free(ntfs_inode *ni, MFT_RECORD *m)
28292829
break;
28302830
}
28312831

2832-
up(&base_ni->extent_lock);
2832+
mutex_unlock(&base_ni->extent_lock);
28332833

28342834
if (unlikely(err)) {
28352835
ntfs_error(vol->sb, "Extent inode 0x%lx is not attached to "
@@ -2888,7 +2888,7 @@ int ntfs_extent_mft_record_free(ntfs_inode *ni, MFT_RECORD *m)
28882888
return 0;
28892889
rollback:
28902890
/* Rollback what we did... */
2891-
down(&base_ni->extent_lock);
2891+
mutex_lock(&base_ni->extent_lock);
28922892
extent_nis = base_ni->ext.extent_ntfs_inos;
28932893
if (!(base_ni->nr_extents & 3)) {
28942894
int new_size = (base_ni->nr_extents + 4) * sizeof(ntfs_inode*);
@@ -2897,7 +2897,7 @@ int ntfs_extent_mft_record_free(ntfs_inode *ni, MFT_RECORD *m)
28972897
if (unlikely(!extent_nis)) {
28982898
ntfs_error(vol->sb, "Failed to allocate internal "
28992899
"buffer during rollback.%s", es);
2900-
up(&base_ni->extent_lock);
2900+
mutex_unlock(&base_ni->extent_lock);
29012901
NVolSetErrors(vol);
29022902
goto rollback_error;
29032903
}
@@ -2912,7 +2912,7 @@ int ntfs_extent_mft_record_free(ntfs_inode *ni, MFT_RECORD *m)
29122912
m->flags |= MFT_RECORD_IN_USE;
29132913
m->sequence_number = old_seq_no;
29142914
extent_nis[base_ni->nr_extents++] = ni;
2915-
up(&base_ni->extent_lock);
2915+
mutex_unlock(&base_ni->extent_lock);
29162916
mark_mft_record_dirty(ni);
29172917
return err;
29182918
}

‎fs/ntfs/ntfs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ extern void free_compression_buffers(void);
9191

9292
/* From fs/ntfs/super.c */
9393
#define default_upcase_len 0x10000
94-
extern struct semaphore ntfs_lock;
94+
extern struct mutex ntfs_lock;
9595

9696
typedef struct {
9797
int val;

0 commit comments

Comments
 (0)