diff options
author | Miklos Szeredi <mszeredi@suse.cz> | 2011-11-14 16:28:13 +0100 |
---|---|---|
committer | Miklos Szeredi <mszeredi@suse.cz> | 2011-11-14 16:28:13 +0100 |
commit | f3286cdf8682bff65c73663f55dc67bd316d2de8 (patch) | |
tree | 179b10a3ec1c35362565d68452e8156545eb0296 /sshfs.c | |
parent | 955751ad360352063d376093f7226c6f93419a50 (diff) | |
download | sshfs-f3286cdf8682bff65c73663f55dc67bd316d2de8.tar sshfs-f3286cdf8682bff65c73663f55dc67bd316d2de8.tar.gz sshfs-f3286cdf8682bff65c73663f55dc67bd316d2de8.tar.bz2 sshfs-f3286cdf8682bff65c73663f55dc67bd316d2de8.zip |
Add locking around modifver and connver
Diffstat (limited to 'sshfs.c')
-rw-r--r-- | sshfs.c | 25 |
1 files changed, 21 insertions, 4 deletions
@@ -2144,12 +2144,19 @@ static int sshfs_chown(const char *path, uid_t uid, gid_t gid) static int sshfs_truncate_workaround(const char *path, off_t size, struct fuse_file_info *fi); +static void sshfs_inc_modifver(void) +{ + pthread_mutex_lock(&sshfs.lock); + sshfs.modifver++; + pthread_mutex_unlock(&sshfs.lock); +} + static int sshfs_truncate(const char *path, off_t size) { int err; struct buffer buf; - sshfs.modifver ++; + sshfs_inc_modifver(); if (size == 0 || sshfs.truncate_workaround) return sshfs_truncate_workaround(path, size, NULL); @@ -2178,7 +2185,13 @@ static int sshfs_utime(const char *path, struct utimbuf *ubuf) static inline int sshfs_file_is_conn(struct sshfs_file *sf) { - return sf->connver == sshfs.connver; + int ret; + + pthread_mutex_lock(&sshfs.lock); + ret = (sf->connver == sshfs.connver); + pthread_mutex_unlock(&sshfs.lock); + + return ret; } static int sshfs_open_common(const char *path, mode_t mode, @@ -2221,8 +2234,10 @@ static int sshfs_open_common(const char *path, mode_t mode, sf->is_seq = 0; sf->refs = 1; sf->next_pos = 0; + pthread_mutex_lock(&sshfs.lock); sf->modifver= sshfs.modifver; sf->connver = sshfs.connver; + pthread_mutex_unlock(&sshfs.lock); buf_init(&buf, 0); buf_add_path(&buf, path); buf_add_uint32(&buf, pflags); @@ -2430,7 +2445,9 @@ static void submit_read(struct sshfs_file *sf, size_t size, off_t offset, chunk->offset = offset; chunk->size = size; chunk->refs = 1; + pthread_mutex_lock(&sshfs.lock); chunk->modifver = sshfs.modifver; + pthread_mutex_unlock(&sshfs.lock); sshfs_send_async_read(sf, chunk); pthread_mutex_lock(&sshfs.lock); chunk_put(*chunkp); @@ -2573,7 +2590,7 @@ static int sshfs_write(const char *path, const char *wbuf, size_t size, if (!sshfs_file_is_conn(sf)) return -EIO; - sshfs.modifver ++; + sshfs_inc_modifver(); buf_init(&buf, 0); buf_add_buf(&buf, handle); buf_add_uint64(&buf, offset); @@ -2679,7 +2696,7 @@ static int sshfs_ftruncate(const char *path, off_t size, if (!sshfs_file_is_conn(sf)) return -EIO; - sshfs.modifver ++; + sshfs_inc_modifver(); if (sshfs.truncate_workaround) return sshfs_truncate_workaround(path, size, fi); |