@@ -180,25 +180,21 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
180
180
{
181
181
struct pstore_private * p = d_inode (dentry )-> i_private ;
182
182
struct pstore_record * record = p -> record ;
183
- int rc = 0 ;
184
183
185
184
if (!record -> psi -> erase )
186
185
return - EPERM ;
187
186
188
187
/* Make sure we can't race while removing this file. */
189
- mutex_lock (& records_list_lock );
190
- if (!list_empty (& p -> list ))
191
- list_del_init (& p -> list );
192
- else
193
- rc = - ENOENT ;
194
- p -> dentry = NULL ;
195
- mutex_unlock (& records_list_lock );
196
- if (rc )
197
- return rc ;
198
-
199
- mutex_lock (& record -> psi -> read_mutex );
200
- record -> psi -> erase (record );
201
- mutex_unlock (& record -> psi -> read_mutex );
188
+ scoped_guard (mutex , & records_list_lock ) {
189
+ if (!list_empty (& p -> list ))
190
+ list_del_init (& p -> list );
191
+ else
192
+ return - ENOENT ;
193
+ p -> dentry = NULL ;
194
+ }
195
+
196
+ scoped_guard (mutex , & record -> psi -> read_mutex )
197
+ record -> psi -> erase (record );
202
198
203
199
return simple_unlink (dir , dentry );
204
200
}
@@ -290,19 +286,16 @@ static struct dentry *psinfo_lock_root(void)
290
286
{
291
287
struct dentry * root ;
292
288
293
- mutex_lock (& pstore_sb_lock );
289
+ guard ( mutex ) (& pstore_sb_lock );
294
290
/*
295
291
* Having no backend is fine -- no records appear.
296
292
* Not being mounted is fine -- nothing to do.
297
293
*/
298
- if (!psinfo || !pstore_sb ) {
299
- mutex_unlock (& pstore_sb_lock );
294
+ if (!psinfo || !pstore_sb )
300
295
return NULL ;
301
- }
302
296
303
297
root = pstore_sb -> s_root ;
304
298
inode_lock (d_inode (root ));
305
- mutex_unlock (& pstore_sb_lock );
306
299
307
300
return root ;
308
301
}
@@ -317,19 +310,19 @@ int pstore_put_backend_records(struct pstore_info *psi)
317
310
if (!root )
318
311
return 0 ;
319
312
320
- mutex_lock (& records_list_lock );
321
- list_for_each_entry_safe (pos , tmp , & records_list , list ) {
322
- if (pos -> record -> psi == psi ) {
323
- list_del_init (& pos -> list );
324
- rc = simple_unlink (d_inode (root ), pos -> dentry );
325
- if (WARN_ON (rc ))
326
- break ;
327
- d_drop (pos -> dentry );
328
- dput (pos -> dentry );
329
- pos -> dentry = NULL ;
313
+ scoped_guard (mutex , & records_list_lock ) {
314
+ list_for_each_entry_safe (pos , tmp , & records_list , list ) {
315
+ if (pos -> record -> psi == psi ) {
316
+ list_del_init (& pos -> list );
317
+ rc = simple_unlink (d_inode (root ), pos -> dentry );
318
+ if (WARN_ON (rc ))
319
+ break ;
320
+ d_drop (pos -> dentry );
321
+ dput (pos -> dentry );
322
+ pos -> dentry = NULL ;
323
+ }
330
324
}
331
325
}
332
- mutex_unlock (& records_list_lock );
333
326
334
327
inode_unlock (d_inode (root ));
335
328
@@ -353,20 +346,20 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
353
346
if (WARN_ON (!inode_is_locked (d_inode (root ))))
354
347
return - EINVAL ;
355
348
356
- rc = - EEXIST ;
349
+ guard (mutex )(& records_list_lock );
350
+
357
351
/* Skip records that are already present in the filesystem. */
358
- mutex_lock (& records_list_lock );
359
352
list_for_each_entry (pos , & records_list , list ) {
360
353
if (pos -> record -> type == record -> type &&
361
354
pos -> record -> id == record -> id &&
362
355
pos -> record -> psi == record -> psi )
363
- goto fail ;
356
+ return - EEXIST ;
364
357
}
365
358
366
359
rc = - ENOMEM ;
367
360
inode = pstore_get_inode (root -> d_sb );
368
361
if (!inode )
369
- goto fail ;
362
+ return - ENOMEM ;
370
363
inode -> i_mode = S_IFREG | 0444 ;
371
364
inode -> i_fop = & pstore_file_operations ;
372
365
scnprintf (name , sizeof (name ), "%s-%s-%llu%s" ,
@@ -394,16 +387,13 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
394
387
d_add (dentry , inode );
395
388
396
389
list_add (& private -> list , & records_list );
397
- mutex_unlock (& records_list_lock );
398
390
399
391
return 0 ;
400
392
401
393
fail_private :
402
394
free_pstore_private (private );
403
395
fail_inode :
404
396
iput (inode );
405
- fail :
406
- mutex_unlock (& records_list_lock );
407
397
return rc ;
408
398
}
409
399
@@ -449,9 +439,8 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent)
449
439
if (!sb -> s_root )
450
440
return - ENOMEM ;
451
441
452
- mutex_lock (& pstore_sb_lock );
453
- pstore_sb = sb ;
454
- mutex_unlock (& pstore_sb_lock );
442
+ scoped_guard (mutex , & pstore_sb_lock )
443
+ pstore_sb = sb ;
455
444
456
445
pstore_get_records (0 );
457
446
@@ -466,17 +455,14 @@ static struct dentry *pstore_mount(struct file_system_type *fs_type,
466
455
467
456
static void pstore_kill_sb (struct super_block * sb )
468
457
{
469
- mutex_lock (& pstore_sb_lock );
458
+ guard ( mutex ) (& pstore_sb_lock );
470
459
WARN_ON (pstore_sb && pstore_sb != sb );
471
460
472
461
kill_litter_super (sb );
473
462
pstore_sb = NULL ;
474
463
475
- mutex_lock (& records_list_lock );
464
+ guard ( mutex ) (& records_list_lock );
476
465
INIT_LIST_HEAD (& records_list );
477
- mutex_unlock (& records_list_lock );
478
-
479
- mutex_unlock (& pstore_sb_lock );
480
466
}
481
467
482
468
static struct file_system_type pstore_fs_type = {
0 commit comments