diff options
author | Tejun Heo <tj@kernel.org> | 2013-10-01 17:41:58 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-10-05 20:15:48 -0400 |
commit | c75ec764cf4746a2406278ffa16f590c5db290a7 (patch) | |
tree | e1d8787906ed20dce25ce1f119c95382d6cdf21e /fs/sysfs/file.c | |
parent | 375b611e60f7c1ce6913417ca254efe5523f1a72 (diff) |
sysfs: add sysfs_open_file_mutex
Add a separate mutex to protect sysfs_open_dirent->buffers list. This
will allow performing sleepable operations while traversing
sysfs_buffers, which will be renamed to sysfs_open_file.
Note that currently sysfs_open_dirent->buffers list isn't being used
for anything and this patch doesn't make any functional difference.
It will be used to merge regular and bin file supports.
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/sysfs/file.c')
-rw-r--r-- | fs/sysfs/file.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 7dfcc3317490..499cff8554fc 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
@@ -25,15 +25,17 @@ | |||
25 | #include "sysfs.h" | 25 | #include "sysfs.h" |
26 | 26 | ||
27 | /* | 27 | /* |
28 | * There's one sysfs_buffer for each open file and one | 28 | * There's one sysfs_buffer for each open file and one sysfs_open_dirent |
29 | * sysfs_open_dirent for each sysfs_dirent with one or more open | 29 | * for each sysfs_dirent with one or more open files. |
30 | * files. | ||
31 | * | 30 | * |
32 | * filp->private_data points to sysfs_buffer and | 31 | * sysfs_dirent->s_attr.open points to sysfs_open_dirent. s_attr.open is |
33 | * sysfs_dirent->s_attr.open points to sysfs_open_dirent. s_attr.open | 32 | * protected by sysfs_open_dirent_lock. |
34 | * is protected by sysfs_open_dirent_lock. | 33 | * |
34 | * filp->private_data points to sysfs_buffer which is chained at | ||
35 | * sysfs_open_dirent->buffers, which is protected by sysfs_open_file_mutex. | ||
35 | */ | 36 | */ |
36 | static DEFINE_SPINLOCK(sysfs_open_dirent_lock); | 37 | static DEFINE_SPINLOCK(sysfs_open_dirent_lock); |
38 | static DEFINE_MUTEX(sysfs_open_file_mutex); | ||
37 | 39 | ||
38 | struct sysfs_open_dirent { | 40 | struct sysfs_open_dirent { |
39 | atomic_t refcnt; | 41 | atomic_t refcnt; |
@@ -272,6 +274,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd, | |||
272 | struct sysfs_open_dirent *od, *new_od = NULL; | 274 | struct sysfs_open_dirent *od, *new_od = NULL; |
273 | 275 | ||
274 | retry: | 276 | retry: |
277 | mutex_lock(&sysfs_open_file_mutex); | ||
275 | spin_lock_irq(&sysfs_open_dirent_lock); | 278 | spin_lock_irq(&sysfs_open_dirent_lock); |
276 | 279 | ||
277 | if (!sd->s_attr.open && new_od) { | 280 | if (!sd->s_attr.open && new_od) { |
@@ -286,6 +289,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd, | |||
286 | } | 289 | } |
287 | 290 | ||
288 | spin_unlock_irq(&sysfs_open_dirent_lock); | 291 | spin_unlock_irq(&sysfs_open_dirent_lock); |
292 | mutex_unlock(&sysfs_open_file_mutex); | ||
289 | 293 | ||
290 | if (od) { | 294 | if (od) { |
291 | kfree(new_od); | 295 | kfree(new_od); |
@@ -321,6 +325,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd, | |||
321 | struct sysfs_open_dirent *od = sd->s_attr.open; | 325 | struct sysfs_open_dirent *od = sd->s_attr.open; |
322 | unsigned long flags; | 326 | unsigned long flags; |
323 | 327 | ||
328 | mutex_lock(&sysfs_open_file_mutex); | ||
324 | spin_lock_irqsave(&sysfs_open_dirent_lock, flags); | 329 | spin_lock_irqsave(&sysfs_open_dirent_lock, flags); |
325 | 330 | ||
326 | list_del(&buffer->list); | 331 | list_del(&buffer->list); |
@@ -330,6 +335,7 @@ static void sysfs_put_open_dirent(struct sysfs_dirent *sd, | |||
330 | od = NULL; | 335 | od = NULL; |
331 | 336 | ||
332 | spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags); | 337 | spin_unlock_irqrestore(&sysfs_open_dirent_lock, flags); |
338 | mutex_unlock(&sysfs_open_file_mutex); | ||
333 | 339 | ||
334 | kfree(od); | 340 | kfree(od); |
335 | } | 341 | } |