Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions fs/fuse/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2221,8 +2221,8 @@ static int fuse_get_page_mkwrite_lock(struct file *file, loff_t offset, size_t l
memset(&inarg, 0, sizeof(inarg));
inarg.fh = ff->fh;

inarg.offset = offset;
inarg.size = length;
inarg.start = offset;
inarg.end = offset + length - 1;
inarg.type = FUSE_DLM_PAGE_MKWRITE;

args.opcode = FUSE_DLM_WB_LOCK;
Expand All @@ -2239,10 +2239,13 @@ static int fuse_get_page_mkwrite_lock(struct file *file, loff_t offset, size_t l
err = 0;
}

if (!err && fc->dlm && outarg.locksize < length) {
if (!err &&
fc->dlm &&
(outarg.start > inarg.start ||
outarg.end < inarg.end)) {
/* fuse server is seriously broken */
pr_warn("fuse: dlm lock request for %lu bytes returned %u bytes\n",
length, outarg.locksize);
pr_warn("fuse: dlm lock request for %llu:%llu bytes returned %llu:%llu bytes\n",
inarg.start, inarg.end, outarg.start, outarg.end);
fuse_abort_conn(fc);
err = -EINVAL;
}
Expand Down
67 changes: 37 additions & 30 deletions fs/fuse/fuse_dlm_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ struct fuse_dlm_range {
/* Interval tree node */
struct rb_node rb;
/* Start page offset (inclusive) */
pgoff_t start;
uint64_t start;
/* End page offset (inclusive) */
pgoff_t end;
uint64_t end;
/* Subtree end value for interval tree */
pgoff_t __subtree_end;
uint64_t __subtree_end;
/* Lock mode */
enum fuse_page_lock_mode mode;
/* Temporary list entry for operations */
Expand All @@ -32,19 +32,19 @@ struct fuse_dlm_range {
#define FUSE_PCACHE_LK_WRITE 2 /* Exclusive write lock */

/* Interval tree definitions for page ranges */
static inline pgoff_t fuse_dlm_range_start(struct fuse_dlm_range *range)
static inline uint64_t fuse_dlm_range_start(struct fuse_dlm_range *range)
{
return range->start;
}

static inline pgoff_t fuse_dlm_range_last(struct fuse_dlm_range *range)
static inline uint64_t fuse_dlm_range_last(struct fuse_dlm_range *range)
{
return range->end;
}

INTERVAL_TREE_DEFINE(struct fuse_dlm_range, rb, pgoff_t, __subtree_end,
fuse_dlm_range_start, fuse_dlm_range_last, static,
fuse_page_it);
INTERVAL_TREE_DEFINE(struct fuse_dlm_range, rb, uint64_t, __subtree_end,
fuse_dlm_range_start, fuse_dlm_range_last, static,
fuse_page_it);

/**
* fuse_page_cache_init - Initialize a page cache lock manager
Expand Down Expand Up @@ -101,8 +101,8 @@ void fuse_dlm_cache_release_locks(struct fuse_inode *inode)
* Return: Pointer to the first overlapping range, or NULL if none found
*/
static struct fuse_dlm_range *
fuse_dlm_find_overlapping(struct fuse_dlm_cache *cache, pgoff_t start,
pgoff_t end)
fuse_dlm_find_overlapping(struct fuse_dlm_cache *cache, uint64_t start,
uint64_t end)
{
return fuse_page_it_iter_first(&cache->ranges, start, end);
}
Expand All @@ -116,8 +116,8 @@ fuse_dlm_find_overlapping(struct fuse_dlm_cache *cache, pgoff_t start,
* Attempt to merge ranges within and adjacent to the specified region
* that have the same lock mode.
*/
static void fuse_dlm_try_merge(struct fuse_dlm_cache *cache, pgoff_t start,
pgoff_t end)
static void fuse_dlm_try_merge(struct fuse_dlm_cache *cache, uint64_t start,
uint64_t end)
{
struct fuse_dlm_range *range, *next;
struct rb_node *node;
Expand Down Expand Up @@ -182,16 +182,16 @@ static void fuse_dlm_try_merge(struct fuse_dlm_cache *cache, pgoff_t start,
*
* Return: 0 on success, negative error code on failure
*/
int fuse_dlm_lock_range(struct fuse_inode *inode, pgoff_t start,
pgoff_t end, enum fuse_page_lock_mode mode)
int fuse_dlm_lock_range(struct fuse_inode *inode, uint64_t start,
uint64_t end, enum fuse_page_lock_mode mode)
{
struct fuse_dlm_cache *cache = &inode->dlm_locked_areas;
struct fuse_dlm_range *range, *new_range, *next;
int lock_mode;
int ret = 0;
LIST_HEAD(to_lock);
LIST_HEAD(to_upgrade);
pgoff_t current_start = start;
uint64_t current_start = start;

if (!cache || start > end)
return -EINVAL;
Expand Down Expand Up @@ -304,8 +304,8 @@ int fuse_dlm_lock_range(struct fuse_inode *inode, pgoff_t start,
*
* Return: 0 on success, negative error code on failure
*/
static int fuse_dlm_punch_hole(struct fuse_dlm_cache *cache, pgoff_t start,
pgoff_t end)
static int fuse_dlm_punch_hole(struct fuse_dlm_cache *cache, uint64_t start,
uint64_t end)
{
struct fuse_dlm_range *range, *new_range;
int ret = 0;
Expand Down Expand Up @@ -363,11 +363,12 @@ static int fuse_dlm_punch_hole(struct fuse_dlm_cache *cache, pgoff_t start,
* @end: End page offset
*
* Release locks on the specified range of pages.
* Note that if start and end are set to zero the cache is destroyed.
*
* Return: 0 on success, negative error code on failure
*/
int fuse_dlm_unlock_range(struct fuse_inode *inode,
pgoff_t start, pgoff_t end)
uint64_t start, uint64_t end)
{
struct fuse_dlm_cache *cache = &inode->dlm_locked_areas;
struct fuse_dlm_range *range, *next;
Expand All @@ -376,6 +377,11 @@ int fuse_dlm_unlock_range(struct fuse_inode *inode,
if (!cache)
return -EINVAL;

if (start == 0 && end == 0) {
fuse_dlm_cache_release_locks(inode);
return 0;
}

down_write(&cache->lock);

/* Find all ranges that overlap with [start, end] */
Expand Down Expand Up @@ -424,13 +430,13 @@ int fuse_dlm_unlock_range(struct fuse_inode *inode,
*
* Return: true if the entire range is locked, false otherwise
*/
bool fuse_dlm_range_is_locked(struct fuse_inode *inode, pgoff_t start,
pgoff_t end, enum fuse_page_lock_mode mode)
bool fuse_dlm_range_is_locked(struct fuse_inode *inode, uint64_t start,
uint64_t end, enum fuse_page_lock_mode mode)
{
struct fuse_dlm_cache *cache = &inode->dlm_locked_areas;
struct fuse_dlm_range *range;
int lock_mode = 0;
pgoff_t current_start = start;
uint64_t current_start = start;

if (!cache || start > end)
return false;
Expand Down Expand Up @@ -491,7 +497,7 @@ void fuse_get_dlm_write_lock(struct file *file, loff_t offset,
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_inode *fi = get_fuse_inode(inode);
struct fuse_mount *fm = ff->fm;
loff_t end = (offset + length - 1) | (PAGE_SIZE - 1);
uint64_t end = (offset + length - 1) | (PAGE_SIZE - 1);

/* note that the offset and length don't have to be page aligned here
* but since we only get here on writeback caching we will send out
Expand All @@ -514,8 +520,8 @@ void fuse_get_dlm_write_lock(struct file *file, loff_t offset,
memset(&inarg, 0, sizeof(inarg));
inarg.fh = ff->fh;

inarg.offset = offset;
inarg.size = end - offset + 1;
inarg.start = offset;
inarg.end = end;
inarg.type = FUSE_DLM_LOCK_WRITE;

args.opcode = FUSE_DLM_WB_LOCK;
Expand All @@ -536,16 +542,17 @@ void fuse_get_dlm_write_lock(struct file *file, loff_t offset,
if (err)
return;
else
if (outarg.locksize < end - offset + 1) {
if (inarg.start < outarg.start ||
inarg.end > outarg.end) {
/* fuse server is seriously broken */
pr_warn("fuse: dlm lock request for %llu bytes returned %u bytes\n",
end - offset + 1, outarg.locksize);
pr_warn("fuse: dlm lock request for %llu:%llu returned %llu:%llu bytes\n",
inarg.start, inarg.end, outarg.start, outarg.end);
fuse_abort_conn(fc);
return;
} else {
/* ignore any errors here, there is no way we can react appropriately */
fuse_dlm_lock_range(fi, offset,
offset + outarg.locksize - 1,
FUSE_PAGE_LOCK_WRITE);
fuse_dlm_lock_range(fi, outarg.start,
outarg.end,
FUSE_PAGE_LOCK_WRITE);
}
}
12 changes: 6 additions & 6 deletions fs/fuse/fuse_dlm_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ int fuse_dlm_cache_init(struct fuse_inode *inode);
void fuse_dlm_cache_release_locks(struct fuse_inode *inode);

/* Lock a range of pages */
int fuse_dlm_lock_range(struct fuse_inode *inode, pgoff_t start,
pgoff_t end, enum fuse_page_lock_mode mode);
int fuse_dlm_lock_range(struct fuse_inode *inode, uint64_t start,
uint64_t end, enum fuse_page_lock_mode mode);

/* Unlock a range of pages */
int fuse_dlm_unlock_range(struct fuse_inode *inode, pgoff_t start,
pgoff_t end);
int fuse_dlm_unlock_range(struct fuse_inode *inode, uint64_t start,
uint64_t end);

/* Check if a page range is already locked */
bool fuse_dlm_range_is_locked(struct fuse_inode *inode, pgoff_t start,
pgoff_t end, enum fuse_page_lock_mode mode);
bool fuse_dlm_range_is_locked(struct fuse_inode *inode, uint64_t start,
uint64_t end, enum fuse_page_lock_mode mode);

/* this is the interface to the filesystem */
void fuse_get_dlm_write_lock(struct file *file, loff_t offset,
Expand Down
11 changes: 7 additions & 4 deletions fs/fuse/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,14 @@ int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid,
pg_end = (offset + len - 1) >> PAGE_SHIFT;

if (fc->dlm && fc->writeback_cache)
/* invalidate the range from the beginning of the first page
* in the given range to the last byte of the last page */
/* Invalidate the range exactly as the fuse server requested
* except for the case where it sends -1.
* Note that this can lead to some inconsistencies if
* the fuse server sends unaligned data */
fuse_dlm_unlock_range(fi,
pg_start << PAGE_SHIFT,
(pg_end << PAGE_SHIFT) | (PAGE_SIZE - 1));
offset,
pg_end == -1 ? 0 :
(offset + len - 1));

invalidate_inode_pages2_range(inode->i_mapping,
pg_start, pg_end);
Expand Down
11 changes: 6 additions & 5 deletions include/uapi/linux/fuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -1192,10 +1192,10 @@ enum fuse_dlm_lock_type {
*/
struct fuse_dlm_lock_in {
uint64_t fh;
uint64_t offset;
uint32_t size;
uint64_t start;
uint64_t end;
uint32_t type;
uint64_t reserved;
uint32_t reserved;
};

/**
Expand All @@ -1205,8 +1205,9 @@ struct fuse_dlm_lock_in {
* to reduce number of calls)
*/
struct fuse_dlm_lock_out {
uint32_t locksize;
uint32_t padding;
uint64_t start;
uint64_t end;
uint64_t reserved;
};

/**
Expand Down