[Devel] [PATCH 5/8] fuse: Convert fc->attr_version into atomic64_t
Kirill Tkhai
ktkhai at virtuozzo.com
Wed Apr 3 18:37:27 MSK 2019
ms commit 4510d86fbbb3
This patch makes fc->attr_version of atomic64_t type, so fc->lock won't be
needed to read or modify it anymore.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
Signed-off-by: Miklos Szeredi <mszeredi at redhat.com>
---
fs/fuse/dir.c | 19 ++-----------------
fs/fuse/file.c | 8 ++++----
fs/fuse/fuse_i.h | 9 ++++++---
fs/fuse/inode.c | 4 ++--
4 files changed, 14 insertions(+), 26 deletions(-)
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 12fc2dd71a5c..07f2d72bd552 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -163,21 +163,6 @@ static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_req *req,
req->out.args[0].value = outarg;
}
-u64 fuse_get_attr_version(struct fuse_conn *fc)
-{
- u64 curr_version;
-
- /*
- * The spin lock isn't actually needed on 64bit archs, but we
- * don't yet care too much about such optimizations.
- */
- spin_lock(&fc->lock);
- curr_version = fc->attr_version;
- spin_unlock(&fc->lock);
-
- return curr_version;
-}
-
/*
* Check whether the dentry is still valid
*
@@ -748,7 +733,7 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry)
struct fuse_inode *fi = get_fuse_inode(inode);
spin_lock(&fc->lock);
- fi->attr_version = ++fc->attr_version;
+ fi->attr_version = atomic64_inc_return(&fc->attr_version);
/*
* If i_nlink == 0 then unlink doesn't make sense, yet this can
* happen if userspace filesystem is careless. It would be
@@ -918,7 +903,7 @@ static int fuse_link(struct dentry *entry, struct inode *newdir,
struct fuse_inode *fi = get_fuse_inode(inode);
spin_lock(&fc->lock);
- fi->attr_version = ++fc->attr_version;
+ fi->attr_version = atomic64_inc_return(&fc->attr_version);;
inc_nlink(inode);
spin_unlock(&fc->lock);
fuse_invalidate_attr(inode);
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index abeb36e5fe8f..8f80667cb534 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -265,7 +265,7 @@ void fuse_finish_open(struct inode *inode, struct file *file)
struct fuse_inode *fi = get_fuse_inode(inode);
spin_lock(&fc->lock);
- fi->attr_version = ++fc->attr_version;
+ fi->attr_version = atomic64_inc_return(&fc->attr_version);
i_size_write(inode, 0);
spin_unlock(&fc->lock);
fuse_invalidate_attr(inode);
@@ -880,7 +880,7 @@ static void fuse_aio_complete(struct fuse_io_priv *io, int err, ssize_t pos)
struct fuse_inode *fi = get_fuse_inode(inode);
spin_lock(&fc->lock);
- fi->attr_version = ++fc->attr_version;
+ fi->attr_version = atomic64_inc_return(&fc->attr_version);
spin_unlock(&fc->lock);
}
}
@@ -1006,7 +1006,7 @@ static void fuse_read_update_size(struct inode *inode, loff_t size,
spin_lock(&fc->lock);
if (attr_ver == fi->attr_version && size < inode->i_size &&
!test_bit(FUSE_I_SIZE_UNSTABLE, &fi->state)) {
- fi->attr_version = ++fc->attr_version;
+ fi->attr_version = atomic64_inc_return(&fc->attr_version);
i_size_write(inode, size);
}
spin_unlock(&fc->lock);
@@ -1399,7 +1399,7 @@ bool fuse_write_update_size(struct inode *inode, loff_t pos)
bool ret = false;
spin_lock(&fc->lock);
- fi->attr_version = ++fc->attr_version;
+ fi->attr_version = atomic64_inc_return(&fc->attr_version);
if (pos > inode->i_size) {
i_size_write(inode, pos);
ret = true;
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 1597bf3ed1f1..18da854b9e73 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -760,7 +760,7 @@ struct fuse_conn {
struct fuse_req *destroy_req;
/** Version counter for attribute changes */
- u64 attr_version;
+ atomic64_t attr_version;
/** Called on final put */
void (*release)(struct fuse_conn *);
@@ -807,6 +807,11 @@ static inline u64 get_node_id(struct inode *inode)
return get_fuse_inode(inode)->nodeid;
}
+static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
+{
+ return atomic64_read(&fc->attr_version);
+}
+
/** Device operations */
extern const struct file_operations fuse_dev_operations;
@@ -1043,8 +1048,6 @@ void fuse_flush_writepages(struct inode *inode);
void fuse_set_nowrite(struct inode *inode);
void fuse_release_nowrite(struct inode *inode);
-u64 fuse_get_attr_version(struct fuse_conn *fc);
-
/**
* File-system tells the kernel to invalidate cache for the given node id.
*/
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 6a3f1b40e9a1..72dba062f3e8 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -176,7 +176,7 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_inode *fi = get_fuse_inode(inode);
- fi->attr_version = ++fc->attr_version;
+ fi->attr_version = atomic64_inc_return(&fc->attr_version);
fi->i_time = attr_valid;
WRITE_ONCE(fi->inval_atime, 0);
@@ -823,7 +823,7 @@ int fuse_conn_init(struct fuse_conn *fc)
fc->blocked = 0;
fc->initialized = 0;
fc->connected = 1;
- fc->attr_version = 1;
+ atomic64_set(&fc->attr_version, 1);
get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
fc->pid_ns = get_pid_ns(task_active_pid_ns(current));
return 0;
More information about the Devel
mailing list