Skip to content

Commit 7fcc99f

Browse files
Christoph HellwigChristoph Hellwig
authored andcommitted
hfsplus: add missing extent locking in hfsplus_write_inode
Most of the extent handling code already does proper SMP locking, but hfsplus_write_inode was calling into hfsplus_ext_write_extent without taking the extents_lock. Fix this by splitting hfsplus_ext_write_extent into an internal helper that expects the lock, and a public interface that first acquires it. Also add a few locking asserts and document the locking rules in hfsplus_fs.h. Signed-off-by: Christoph Hellwig <hch@tuxera.com>
1 parent 89755dc commit 7fcc99f

2 files changed

Lines changed: 34 additions & 15 deletions

File tree

‎fs/hfsplus/extents.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ static void __hfsplus_ext_write_extent(struct inode *inode, struct hfs_find_data
8888
struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
8989
int res;
9090

91+
WARN_ON(!mutex_is_locked(&hip->extents_lock));
92+
9193
hfsplus_ext_build_key(fd->search_key, inode->i_ino, hip->cached_start,
9294
HFSPLUS_IS_RSRC(inode) ?
9395
HFSPLUS_TYPE_RSRC : HFSPLUS_TYPE_DATA);
@@ -108,7 +110,7 @@ static void __hfsplus_ext_write_extent(struct inode *inode, struct hfs_find_data
108110
}
109111
}
110112

111-
void hfsplus_ext_write_extent(struct inode *inode)
113+
static void hfsplus_ext_write_extent_locked(struct inode *inode)
112114
{
113115
if (HFSPLUS_I(inode)->flags & HFSPLUS_FLG_EXT_DIRTY) {
114116
struct hfs_find_data fd;
@@ -119,6 +121,13 @@ void hfsplus_ext_write_extent(struct inode *inode)
119121
}
120122
}
121123

124+
void hfsplus_ext_write_extent(struct inode *inode)
125+
{
126+
mutex_lock(&HFSPLUS_I(inode)->extents_lock);
127+
hfsplus_ext_write_extent_locked(inode);
128+
mutex_unlock(&HFSPLUS_I(inode)->extents_lock);
129+
}
130+
122131
static inline int __hfsplus_ext_read_extent(struct hfs_find_data *fd,
123132
struct hfsplus_extent *extent,
124133
u32 cnid, u32 block, u8 type)
@@ -144,6 +153,8 @@ static inline int __hfsplus_ext_cache_extent(struct hfs_find_data *fd, struct in
144153
struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
145154
int res;
146155

156+
WARN_ON(!mutex_is_locked(&hip->extents_lock));
157+
147158
if (hip->flags & HFSPLUS_FLG_EXT_DIRTY)
148159
__hfsplus_ext_write_extent(inode, fd);
149160

@@ -433,7 +444,7 @@ int hfsplus_file_extend(struct inode *inode)
433444

434445
insert_extent:
435446
dprint(DBG_EXTENT, "insert new extent\n");
436-
hfsplus_ext_write_extent(inode);
447+
hfsplus_ext_write_extent_locked(inode);
437448

438449
memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
439450
hip->cached_extents[0].start_block = cpu_to_be32(start);

‎fs/hfsplus/hfsplus_fs.h‎

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,28 +158,36 @@ struct hfsplus_sb_info {
158158

159159

160160
struct hfsplus_inode_info {
161-
struct mutex extents_lock;
162-
u32 clump_blocks, alloc_blocks;
163-
sector_t fs_blocks;
164-
/* Allocation extents from catalog record or volume header */
165-
hfsplus_extent_rec first_extents;
166-
u32 first_blocks;
167-
hfsplus_extent_rec cached_extents;
168-
u32 cached_start, cached_blocks;
169161
atomic_t opencnt;
170162

171-
struct inode *rsrc_inode;
163+
/*
164+
* Extent allocation information, protected by extents_lock.
165+
*/
166+
u32 first_blocks;
167+
u32 clump_blocks;
168+
u32 alloc_blocks;
169+
u32 cached_start;
170+
u32 cached_blocks;
171+
hfsplus_extent_rec first_extents;
172+
hfsplus_extent_rec cached_extents;
172173
unsigned long flags;
174+
struct mutex extents_lock;
173175

176+
/*
177+
* Immutable data.
178+
*/
179+
struct inode *rsrc_inode;
174180
__be32 create_date;
175-
/* Device number in hfsplus_permissions in catalog */
176181
u32 dev;
177-
/* BSD system and user file flags */
178-
u8 rootflags;
179-
u8 userflags;
180182

183+
/*
184+
* Protected by i_mutex.
185+
*/
186+
sector_t fs_blocks;
187+
u8 rootflags, userflags; /* BSD system and user file flags */
181188
struct list_head open_dir_list;
182189
loff_t phys_size;
190+
183191
struct inode vfs_inode;
184192
};
185193

0 commit comments

Comments
 (0)