[Devel] [PATCH RHEL7 COMMIT] fuse: Refactor fuse_open_common()
Konstantin Khorenko
khorenko at virtuozzo.com
Fri Jul 6 12:41:48 MSK 2018
The commit is pushed to "branch-rh7-3.10.0-862.3.2.vz7.61.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-862.3.2.vz7.61.15
------>
commit c27d883edbae9041e8145b82112a26b92f3e4a05
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date: Fri Jul 6 12:41:48 2018 +0300
fuse: Refactor fuse_open_common()
Make this function to lock and unlock in only place.
Improve its readability.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
Acked-by: Alexey Kuznetsov <kuznet at virtuozzo.com>
---
fs/fuse/file.c | 30 ++++++++++++------------------
1 file changed, 12 insertions(+), 18 deletions(-)
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index e870697be5ee..313f81191ada 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -302,33 +302,27 @@ int fuse_open_common(struct inode *inode, struct file *file, bool isdir)
u64 size;
mutex_lock(&inode->i_mutex);
-
spin_lock(&fc->lock);
- atomic_inc(&fi->num_openers);
- if (atomic_read(&fi->num_openers) == 1) {
+ if (atomic_inc_return(&fi->num_openers) == 1) {
fi->i_size_unstable = 1;
spin_unlock(&fc->lock);
err = fuse_getattr_size(inode, file, &size);
- if (err) {
- spin_lock(&fc->lock);
- atomic_dec(&fi->num_openers);
- fi->i_size_unstable = 0;
- spin_unlock(&fc->lock);
-
- mutex_unlock(&inode->i_mutex);
- fuse_release_common(file, FUSE_RELEASE);
- return err;
- }
-
spin_lock(&fc->lock);
- i_size_write(inode, size);
fi->i_size_unstable = 0;
- spin_unlock(&fc->lock);
- } else
- spin_unlock(&fc->lock);
+ if (err)
+ atomic_dec(&fi->num_openers);
+ else
+ i_size_write(inode, size);
+ }
+ spin_unlock(&fc->lock);
mutex_unlock(&inode->i_mutex);
+
+ if (err) {
+ fuse_release_common(file, FUSE_RELEASE);
+ return err;
+ }
}
fuse_finish_open(inode, file);
More information about the Devel
mailing list