Repository navigation
Increase dlm locksize and change DLM lock request and return to start and end values, rather than offset and length as a preparation for byte range locks #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 */ | ||
|
|
@@ -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 | ||
|
|
@@ -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); | ||
| } | ||
|
|
@@ -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; | ||
|
|
@@ -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, | ||
|
bsbernd marked this conversation as resolved.
Resolved
|
||
| 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; | ||
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
@@ -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; | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code treat [0,0] special and release all locks, but in your code, [0,0] is a valid lock range which means one byte range lock starts with 0. How a user release a normal [0,0] lock?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in fuse_reverse_inval_inode() I send this 0:0 since we cannot send -1 when the fuse server sends 0,-1. To me a 0,0 lock does not exist ... actually we could write some code to protect us from that, but I think it is just unnecessarry since we cannot lock less than a page anyway.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I forgot your fuse_get_dlm_write_lock() expanded range to page alignment always.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well it's even worse. If you send a request and you get back a range that is smaller than the request, you will get your connection closed. [0,0] is very unlikely, that it can ever happen to be a valid lock.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hbirth in the byte-range lock design, it guarantees the returning range is at least covering the requested range.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, and we check for that ... perfect then. |
||
|
|
||
| down_write(&cache->lock); | ||
|
|
||
| /* Find all ranges that overlap with [start, end] */ | ||
|
|
@@ -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; | ||
|
|
@@ -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 | ||
|
|
@@ -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; | ||
|
|
@@ -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); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indent looks strange to me, could we make these lines aligned? Maybe this is a github display issue for
tabindent?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a display issue, they looked fine to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fc->dlm should be on the same line as
if (!err &&, but I'm going to ignore that for now. The upstream patch needs anyway to get updated.