@@ -151,13 +151,14 @@ int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain,
151
151
return 0 ;
152
152
}
153
153
154
- int exfat_free_cluster (struct inode * inode , struct exfat_chain * p_chain )
154
+ /* This function must be called with bitmap_lock held */
155
+ static int __exfat_free_cluster (struct inode * inode , struct exfat_chain * p_chain )
155
156
{
156
- unsigned int num_clusters = 0 ;
157
- unsigned int clu ;
158
157
struct super_block * sb = inode -> i_sb ;
159
158
struct exfat_sb_info * sbi = EXFAT_SB (sb );
160
159
int cur_cmap_i , next_cmap_i ;
160
+ unsigned int num_clusters = 0 ;
161
+ unsigned int clu ;
161
162
162
163
/* invalid cluster number */
163
164
if (p_chain -> dir == EXFAT_FREE_CLUSTER ||
@@ -230,6 +231,17 @@ int exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain)
230
231
return 0 ;
231
232
}
232
233
234
+ int exfat_free_cluster (struct inode * inode , struct exfat_chain * p_chain )
235
+ {
236
+ int ret = 0 ;
237
+
238
+ mutex_lock (& EXFAT_SB (inode -> i_sb )-> bitmap_lock );
239
+ ret = __exfat_free_cluster (inode , p_chain );
240
+ mutex_unlock (& EXFAT_SB (inode -> i_sb )-> bitmap_lock );
241
+
242
+ return ret ;
243
+ }
244
+
233
245
int exfat_find_last_cluster (struct super_block * sb , struct exfat_chain * p_chain ,
234
246
unsigned int * ret_clu )
235
247
{
@@ -328,6 +340,8 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
328
340
if (num_alloc > total_cnt - sbi -> used_clusters )
329
341
return - ENOSPC ;
330
342
343
+ mutex_lock (& sbi -> bitmap_lock );
344
+
331
345
hint_clu = p_chain -> dir ;
332
346
/* find new cluster */
333
347
if (hint_clu == EXFAT_EOF_CLUSTER ) {
@@ -338,8 +352,10 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
338
352
}
339
353
340
354
hint_clu = exfat_find_free_bitmap (sb , sbi -> clu_srch_ptr );
341
- if (hint_clu == EXFAT_EOF_CLUSTER )
342
- return - ENOSPC ;
355
+ if (hint_clu == EXFAT_EOF_CLUSTER ) {
356
+ ret = - ENOSPC ;
357
+ goto unlock ;
358
+ }
343
359
}
344
360
345
361
/* check cluster validation */
@@ -349,8 +365,10 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
349
365
hint_clu = EXFAT_FIRST_CLUSTER ;
350
366
if (p_chain -> flags == ALLOC_NO_FAT_CHAIN ) {
351
367
if (exfat_chain_cont_cluster (sb , p_chain -> dir ,
352
- num_clusters ))
353
- return - EIO ;
368
+ num_clusters )) {
369
+ ret = - EIO ;
370
+ goto unlock ;
371
+ }
354
372
p_chain -> flags = ALLOC_FAT_CHAIN ;
355
373
}
356
374
}
@@ -400,6 +418,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
400
418
sbi -> used_clusters += num_clusters ;
401
419
402
420
p_chain -> size += num_clusters ;
421
+ mutex_unlock (& sbi -> bitmap_lock );
403
422
return 0 ;
404
423
}
405
424
@@ -419,7 +438,9 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
419
438
}
420
439
free_cluster :
421
440
if (num_clusters )
422
- exfat_free_cluster (inode , p_chain );
441
+ __exfat_free_cluster (inode , p_chain );
442
+ unlock :
443
+ mutex_unlock (& sbi -> bitmap_lock );
423
444
return ret ;
424
445
}
425
446
0 commit comments