Skip to content

Commit 84adede

Browse files
Christoph HellwigChristoph Hellwig
authored andcommitted
hfsplus: use atomic bitops for the superblock flags
The flags in the HFS+-specific superlock do get modified during runtime, use atomic bitops to make the modifications SMP safe. Signed-off-by: Christoph Hellwig <hch@tuxera.com>
1 parent 7ac9fb9 commit 84adede

6 files changed

Lines changed: 30 additions & 28 deletions

File tree

‎fs/hfsplus/btree.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id)
6161
if (id == HFSPLUS_EXT_CNID) {
6262
tree->keycmp = hfsplus_ext_cmp_key;
6363
} else if (id == HFSPLUS_CAT_CNID) {
64-
if ((HFSPLUS_SB(sb)->flags & HFSPLUS_SB_HFSX) &&
64+
if (test_bit(HFSPLUS_SB_HFSX, &HFSPLUS_SB(sb)->flags) &&
6565
(head->key_type == HFSPLUS_KEY_BINARY))
6666
tree->keycmp = hfsplus_cat_bin_cmp_key;
6767
else {
6868
tree->keycmp = hfsplus_cat_case_cmp_key;
69-
HFSPLUS_SB(sb)->flags |= HFSPLUS_SB_CASEFOLD;
69+
set_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
7070
}
7171
} else {
7272
printk(KERN_ERR "hfs: unknown B*Tree requested\n");

‎fs/hfsplus/hfsplus_fs.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ struct hfsplus_sb_info {
150150
unsigned long flags;
151151
};
152152

153-
#define HFSPLUS_SB_WRITEBACKUP 0x0001
154-
#define HFSPLUS_SB_NODECOMPOSE 0x0002
155-
#define HFSPLUS_SB_FORCE 0x0004
156-
#define HFSPLUS_SB_HFSX 0x0008
157-
#define HFSPLUS_SB_CASEFOLD 0x0010
153+
#define HFSPLUS_SB_WRITEBACKUP 0
154+
#define HFSPLUS_SB_NODECOMPOSE 1
155+
#define HFSPLUS_SB_FORCE 2
156+
#define HFSPLUS_SB_HFSX 3
157+
#define HFSPLUS_SB_CASEFOLD 4
158158

159159

160160
struct hfsplus_inode_info {

‎fs/hfsplus/options.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi)
143143
kfree(p);
144144
break;
145145
case opt_decompose:
146-
sbi->flags &= ~HFSPLUS_SB_NODECOMPOSE;
146+
clear_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
147147
break;
148148
case opt_nodecompose:
149-
sbi->flags |= HFSPLUS_SB_NODECOMPOSE;
149+
set_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags);
150150
break;
151151
case opt_force:
152-
sbi->flags |= HFSPLUS_SB_FORCE;
152+
set_bit(HFSPLUS_SB_FORCE, &sbi->flags);
153153
break;
154154
default:
155155
return 0;
@@ -184,7 +184,7 @@ int hfsplus_show_options(struct seq_file *seq, struct vfsmount *mnt)
184184
seq_printf(seq, ",session=%u", sbi->session);
185185
if (sbi->nls)
186186
seq_printf(seq, ",nls=%s", sbi->nls->charset);
187-
if (sbi->flags & HFSPLUS_SB_NODECOMPOSE)
187+
if (test_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags))
188188
seq_printf(seq, ",nodecompose");
189189
return 0;
190190
}

‎fs/hfsplus/super.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static int hfsplus_system_write_inode(struct inode *inode)
119119
}
120120

121121
if (fork->total_size != cpu_to_be64(inode->i_size)) {
122-
sbi->flags |= HFSPLUS_SB_WRITEBACKUP;
122+
set_bit(HFSPLUS_SB_WRITEBACKUP, &sbi->flags);
123123
inode->i_sb->s_dirt = 1;
124124
}
125125
hfsplus_inode_write_fork(inode, fork);
@@ -170,7 +170,7 @@ int hfsplus_sync_fs(struct super_block *sb, int wait)
170170
vhdr->file_count = cpu_to_be32(sbi->file_count);
171171

172172
mark_buffer_dirty(sbi->s_vhbh);
173-
if (sbi->flags & HFSPLUS_SB_WRITEBACKUP) {
173+
if (test_and_clear_bit(HFSPLUS_SB_WRITEBACKUP, &sbi->flags)) {
174174
if (sbi->sect_count) {
175175
struct buffer_head *bh;
176176
u32 block, offset;
@@ -192,7 +192,6 @@ int hfsplus_sync_fs(struct super_block *sb, int wait)
192192
printk(KERN_WARNING "hfs: backup not found!\n");
193193
}
194194
}
195-
sbi->flags &= ~HFSPLUS_SB_WRITEBACKUP;
196195
}
197196
mutex_unlock(&sbi->alloc_mutex);
198197
mutex_unlock(&sbi->vh_mutex);
@@ -276,7 +275,7 @@ static int hfsplus_remount(struct super_block *sb, int *flags, char *data)
276275
"running fsck.hfsplus is recommended. leaving read-only.\n");
277276
sb->s_flags |= MS_RDONLY;
278277
*flags |= MS_RDONLY;
279-
} else if (sbi.flags & HFSPLUS_SB_FORCE) {
278+
} else if (test_bit(HFSPLUS_SB_FORCE, &sbi.flags)) {
280279
/* nothing */
281280
} else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
282281
printk(KERN_WARNING "hfs: filesystem is marked locked, leaving read-only.\n");
@@ -376,7 +375,7 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
376375
printk(KERN_WARNING "hfs: Filesystem was not cleanly unmounted, "
377376
"running fsck.hfsplus is recommended. mounting read-only.\n");
378377
sb->s_flags |= MS_RDONLY;
379-
} else if (sbi->flags & HFSPLUS_SB_FORCE) {
378+
} else if (test_and_clear_bit(HFSPLUS_SB_FORCE, &sbi->flags)) {
380379
/* nothing */
381380
} else if (vhdr->attributes & cpu_to_be32(HFSPLUS_VOL_SOFTLOCK)) {
382381
printk(KERN_WARNING "hfs: Filesystem is marked locked, mounting read-only.\n");
@@ -386,7 +385,6 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
386385
"use the force option at your own risk, mounting read-only.\n");
387386
sb->s_flags |= MS_RDONLY;
388387
}
389-
sbi->flags &= ~HFSPLUS_SB_FORCE;
390388

391389
/* Load metadata objects (B*Trees) */
392390
sbi->ext_tree = hfs_btree_open(sb, HFSPLUS_EXT_CNID);

‎fs/hfsplus/unicode.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr, c
132132
ustrlen = be16_to_cpu(ustr->length);
133133
len = *len_p;
134134
ce1 = NULL;
135-
compose = !(HFSPLUS_SB(sb)->flags & HFSPLUS_SB_NODECOMPOSE);
135+
compose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
136136

137137
while (ustrlen > 0) {
138138
c0 = be16_to_cpu(*ip++);
@@ -293,7 +293,7 @@ int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,
293293
u16 *dstr, outlen = 0;
294294
wchar_t c;
295295

296-
decompose = !(HFSPLUS_SB(sb)->flags & HFSPLUS_SB_NODECOMPOSE);
296+
decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
297297
while (outlen < HFSPLUS_MAX_STRLEN && len > 0) {
298298
size = asc2unichar(sb, astr, len, &c);
299299

@@ -330,8 +330,8 @@ int hfsplus_hash_dentry(struct dentry *dentry, struct qstr *str)
330330
wchar_t c;
331331
u16 c2;
332332

333-
casefold = (HFSPLUS_SB(sb)->flags & HFSPLUS_SB_CASEFOLD);
334-
decompose = !(HFSPLUS_SB(sb)->flags & HFSPLUS_SB_NODECOMPOSE);
333+
casefold = test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
334+
decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
335335
hash = init_name_hash();
336336
astr = str->name;
337337
len = str->len;
@@ -373,8 +373,8 @@ int hfsplus_compare_dentry(struct dentry *dentry, struct qstr *s1, struct qstr *
373373
u16 c1, c2;
374374
wchar_t c;
375375

376-
casefold = (HFSPLUS_SB(sb)->flags & HFSPLUS_SB_CASEFOLD);
377-
decompose = !(HFSPLUS_SB(sb)->flags & HFSPLUS_SB_NODECOMPOSE);
376+
casefold = test_bit(HFSPLUS_SB_CASEFOLD, &HFSPLUS_SB(sb)->flags);
377+
decompose = !test_bit(HFSPLUS_SB_NODECOMPOSE, &HFSPLUS_SB(sb)->flags);
378378
astr1 = s1->name;
379379
len1 = s1->len;
380380
astr2 = s2->name;

‎fs/hfsplus/wrapper.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ int hfsplus_read_wrapper(struct super_block *sb)
123123
if (vhdr->signature == cpu_to_be16(HFSPLUS_VOLHEAD_SIG))
124124
break;
125125
if (vhdr->signature == cpu_to_be16(HFSPLUS_VOLHEAD_SIGX)) {
126-
sbi->flags |= HFSPLUS_SB_HFSX;
126+
set_bit(HFSPLUS_SB_HFSX, &sbi->flags);
127127
break;
128128
}
129129
brelse(bh);
@@ -169,10 +169,14 @@ int hfsplus_read_wrapper(struct super_block *sb)
169169
return -EIO;
170170

171171
/* should still be the same... */
172-
if (vhdr->signature != (sbi->flags & HFSPLUS_SB_HFSX ?
173-
cpu_to_be16(HFSPLUS_VOLHEAD_SIGX) :
174-
cpu_to_be16(HFSPLUS_VOLHEAD_SIG)))
175-
goto error;
172+
if (test_bit(HFSPLUS_SB_HFSX, &sbi->flags)) {
173+
if (vhdr->signature != cpu_to_be16(HFSPLUS_VOLHEAD_SIGX))
174+
goto error;
175+
} else {
176+
if (vhdr->signature != cpu_to_be16(HFSPLUS_VOLHEAD_SIG))
177+
goto error;
178+
}
179+
176180
sbi->s_vhbh = bh;
177181
sbi->s_vhdr = vhdr;
178182

0 commit comments

Comments
 (0)