Skip to content

Commit b33b792

Browse files
Christoph HellwigChristoph Hellwig
authored andcommitted
hfsplus: split up inode flags
Split the flags field in the hfsplus inode into an extent_state flag that is locked by the extent_lock, and a new flags field that uses atomic bitops. The second will grow more flags in the next patch. Signed-off-by: Christoph Hellwig <hch@tuxera.com>
1 parent eb29d66 commit b33b792

4 files changed

Lines changed: 29 additions & 19 deletions

File tree

‎fs/hfsplus/extents.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,24 @@ static void __hfsplus_ext_write_extent(struct inode *inode, struct hfs_find_data
9595
HFSPLUS_TYPE_RSRC : HFSPLUS_TYPE_DATA);
9696

9797
res = hfs_brec_find(fd);
98-
if (hip->flags & HFSPLUS_FLG_EXT_NEW) {
98+
if (hip->extent_state & HFSPLUS_EXT_NEW) {
9999
if (res != -ENOENT)
100100
return;
101101
hfs_brec_insert(fd, hip->cached_extents,
102102
sizeof(hfsplus_extent_rec));
103-
hip->flags &= ~(HFSPLUS_FLG_EXT_DIRTY | HFSPLUS_FLG_EXT_NEW);
103+
hip->extent_state &= ~(HFSPLUS_EXT_DIRTY | HFSPLUS_EXT_NEW);
104104
} else {
105105
if (res)
106106
return;
107107
hfs_bnode_write(fd->bnode, hip->cached_extents,
108108
fd->entryoffset, fd->entrylength);
109-
hip->flags &= ~HFSPLUS_FLG_EXT_DIRTY;
109+
hip->extent_state &= ~HFSPLUS_EXT_DIRTY;
110110
}
111111
}
112112

113113
static void hfsplus_ext_write_extent_locked(struct inode *inode)
114114
{
115-
if (HFSPLUS_I(inode)->flags & HFSPLUS_FLG_EXT_DIRTY) {
115+
if (HFSPLUS_I(inode)->extent_state & HFSPLUS_EXT_DIRTY) {
116116
struct hfs_find_data fd;
117117

118118
hfs_find_init(HFSPLUS_SB(inode->i_sb)->ext_tree, &fd);
@@ -155,7 +155,7 @@ static inline int __hfsplus_ext_cache_extent(struct hfs_find_data *fd, struct in
155155

156156
WARN_ON(!mutex_is_locked(&hip->extents_lock));
157157

158-
if (hip->flags & HFSPLUS_FLG_EXT_DIRTY)
158+
if (hip->extent_state & HFSPLUS_EXT_DIRTY)
159159
__hfsplus_ext_write_extent(inode, fd);
160160

161161
res = __hfsplus_ext_read_extent(fd, hip->cached_extents, inode->i_ino,
@@ -167,7 +167,7 @@ static inline int __hfsplus_ext_cache_extent(struct hfs_find_data *fd, struct in
167167
hip->cached_blocks = hfsplus_ext_block_count(hip->cached_extents);
168168
} else {
169169
hip->cached_start = hip->cached_blocks = 0;
170-
hip->flags &= ~(HFSPLUS_FLG_EXT_DIRTY | HFSPLUS_FLG_EXT_NEW);
170+
hip->extent_state &= ~(HFSPLUS_EXT_DIRTY | HFSPLUS_EXT_NEW);
171171
}
172172
return res;
173173
}
@@ -429,7 +429,7 @@ int hfsplus_file_extend(struct inode *inode)
429429
start, len);
430430
if (!res) {
431431
hfsplus_dump_extent(hip->cached_extents);
432-
hip->flags |= HFSPLUS_FLG_EXT_DIRTY;
432+
hip->extent_state |= HFSPLUS_EXT_DIRTY;
433433
hip->cached_blocks += len;
434434
} else if (res == -ENOSPC)
435435
goto insert_extent;
@@ -450,7 +450,7 @@ int hfsplus_file_extend(struct inode *inode)
450450
hip->cached_extents[0].start_block = cpu_to_be32(start);
451451
hip->cached_extents[0].block_count = cpu_to_be32(len);
452452
hfsplus_dump_extent(hip->cached_extents);
453-
hip->flags |= HFSPLUS_FLG_EXT_DIRTY | HFSPLUS_FLG_EXT_NEW;
453+
hip->extent_state |= HFSPLUS_EXT_DIRTY | HFSPLUS_EXT_NEW;
454454
hip->cached_start = hip->alloc_blocks;
455455
hip->cached_blocks = len;
456456

@@ -513,12 +513,12 @@ void hfsplus_file_truncate(struct inode *inode)
513513
alloc_cnt - start, alloc_cnt - blk_cnt);
514514
hfsplus_dump_extent(hip->cached_extents);
515515
if (blk_cnt > start) {
516-
hip->flags |= HFSPLUS_FLG_EXT_DIRTY;
516+
hip->extent_state |= HFSPLUS_EXT_DIRTY;
517517
break;
518518
}
519519
alloc_cnt = start;
520520
hip->cached_start = hip->cached_blocks = 0;
521-
hip->flags &= ~(HFSPLUS_FLG_EXT_DIRTY | HFSPLUS_FLG_EXT_NEW);
521+
hip->extent_state &= ~(HFSPLUS_EXT_DIRTY | HFSPLUS_EXT_NEW);
522522
hfs_brec_remove(&fd);
523523
}
524524
hfs_find_exit(&fd);

‎fs/hfsplus/hfsplus_fs.h‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ struct hfsplus_inode_info {
171171
u32 cached_blocks;
172172
hfsplus_extent_rec first_extents;
173173
hfsplus_extent_rec cached_extents;
174-
unsigned long flags;
174+
unsigned int extent_state;
175175
struct mutex extents_lock;
176176

177177
/*
@@ -185,6 +185,11 @@ struct hfsplus_inode_info {
185185
*/
186186
u32 linkid;
187187

188+
/*
189+
* Accessed using atomic bitops.
190+
*/
191+
unsigned long flags;
192+
188193
/*
189194
* Protected by i_mutex.
190195
*/
@@ -196,12 +201,13 @@ struct hfsplus_inode_info {
196201
struct inode vfs_inode;
197202
};
198203

199-
#define HFSPLUS_FLG_RSRC 0x0001
200-
#define HFSPLUS_FLG_EXT_DIRTY 0x0002
201-
#define HFSPLUS_FLG_EXT_NEW 0x0004
204+
#define HFSPLUS_EXT_DIRTY 0x0001
205+
#define HFSPLUS_EXT_NEW 0x0002
206+
207+
#define HFSPLUS_I_RSRC 0 /* represents a resource fork */
202208

203-
#define HFSPLUS_IS_DATA(inode) (!(HFSPLUS_I(inode)->flags & HFSPLUS_FLG_RSRC))
204-
#define HFSPLUS_IS_RSRC(inode) (HFSPLUS_I(inode)->flags & HFSPLUS_FLG_RSRC)
209+
#define HFSPLUS_IS_RSRC(inode) \
210+
test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
205211

206212
struct hfs_find_data {
207213
/* filled by caller */

‎fs/hfsplus/inode.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ static struct dentry *hfsplus_file_lookup(struct inode *dir, struct dentry *dent
190190
inode->i_ino = dir->i_ino;
191191
INIT_LIST_HEAD(&hip->open_dir_list);
192192
mutex_init(&hip->extents_lock);
193-
hip->flags = HFSPLUS_FLG_RSRC;
193+
hip->extent_state = 0;
194+
hip->flags = 0;
195+
set_bit(HFSPLUS_I_RSRC, &hip->flags);
194196

195197
hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd);
196198
err = hfsplus_find_cat(sb, dir->i_ino, &fd);
@@ -369,6 +371,7 @@ struct inode *hfsplus_new_inode(struct super_block *sb, int mode)
369371
INIT_LIST_HEAD(&hip->open_dir_list);
370372
mutex_init(&hip->extents_lock);
371373
atomic_set(&hip->opencnt, 0);
374+
hip->extent_state = 0;
372375
hip->flags = 0;
373376
memset(hip->first_extents, 0, sizeof(hfsplus_extent_rec));
374377
memset(hip->cached_extents, 0, sizeof(hfsplus_extent_rec));
@@ -498,8 +501,8 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
498501
hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
499502
sizeof(struct hfsplus_cat_file));
500503

501-
hfsplus_inode_read_fork(inode, HFSPLUS_IS_DATA(inode) ?
502-
&file->data_fork : &file->rsrc_fork);
504+
hfsplus_inode_read_fork(inode, HFSPLUS_IS_RSRC(inode) ?
505+
&file->rsrc_fork : &file->data_fork);
503506
hfsplus_get_perms(inode, &file->permissions, 0);
504507
inode->i_nlink = 1;
505508
if (S_ISREG(inode->i_mode)) {

‎fs/hfsplus/super.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino)
6666
INIT_LIST_HEAD(&HFSPLUS_I(inode)->open_dir_list);
6767
mutex_init(&HFSPLUS_I(inode)->extents_lock);
6868
HFSPLUS_I(inode)->flags = 0;
69+
HFSPLUS_I(inode)->extent_state = 0;
6970
HFSPLUS_I(inode)->rsrc_inode = NULL;
7071
atomic_set(&HFSPLUS_I(inode)->opencnt, 0);
7172

0 commit comments

Comments
 (0)