-
Notifications
You must be signed in to change notification settings - Fork 136
Non-resident COW files #273
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
base: main
Are you sure you want to change the base?
Changes from 2 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 |
|---|---|---|
|
|
@@ -24,6 +24,9 @@ | |
| #include <linux/percpu-refcount.h> | ||
| #endif | ||
|
|
||
| #define FUSEBLK_MNT_NAME "fuseblk" | ||
| #define FUSEBLK_MNT_LEN 7 | ||
|
|
||
| #if !defined(HAVE_BDEV_STACK_LIMITS) && !defined(HAVE_BLK_SET_DEFAULT_LIMITS) | ||
| //#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) | ||
|
|
||
|
|
@@ -159,7 +162,7 @@ static int snap_trace_bio(struct snap_device *dev, struct bio *bio) | |
| unsigned int bytes, pages; | ||
|
|
||
| // if we don't need to cow this bio just call the real mrf normally | ||
| if (!bio_needs_cow(bio, dev->sd_cow_inode)) | ||
| if (!bio_needs_cow(bio, dev)) | ||
| return dattobd_call_mrf(dev->sd_orig_mrf, | ||
| dattobd_bio_get_queue(bio), bio); | ||
|
|
||
|
|
@@ -255,6 +258,14 @@ static int inc_trace_bio(struct snap_device *dev, struct bio *bio) | |
| bio_iter_t iter; | ||
| bio_iter_bvec_t bvec; | ||
|
|
||
| if (!test_bit(SD_FLAG_COW_RESIDENT, &dev->sd_flags)) { | ||
| // if the cow is non-resident, then we don't need to check if | ||
| // the bio is for the cow file. | ||
| ret = inc_make_sset(dev, bio_sector(bio), | ||
| bio_size(bio) / SECTOR_SIZE); | ||
| goto out; | ||
| } | ||
|
|
||
| #ifdef HAVE_ENUM_REQ_OPF | ||
| //#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0) | ||
| if (bio_op(bio) == REQ_OP_WRITE_ZEROES) { | ||
|
|
@@ -406,10 +417,7 @@ static int __tracer_destroy_cow(struct snap_device *dev, int close_method) | |
| if (dev->sd_cow) { | ||
| LOG_DEBUG("destroying cow manager"); | ||
|
|
||
| if (close_method == 0) { | ||
| cow_free(dev->sd_cow); | ||
| dev->sd_cow = NULL; | ||
| } else if (close_method == 1) { | ||
| if (close_method == 0 || close_method == 1) { | ||
| ret = cow_sync_and_free(dev->sd_cow); | ||
| dev->sd_cow = NULL; | ||
| } else if (close_method == 2) { | ||
|
|
@@ -430,6 +438,7 @@ static int __tracer_setup_cow(struct snap_device *dev, | |
| int ret; | ||
| uint64_t max_file_size; | ||
| char bdev_name[BDEVNAME_SIZE]; | ||
| char fuseblk_name[] = FUSEBLK_MNT_NAME; | ||
|
|
||
| bdevname(bdev, bdev_name); | ||
|
|
||
|
|
@@ -483,11 +492,23 @@ static int __tracer_setup_cow(struct snap_device *dev, | |
| } | ||
| } | ||
|
|
||
| // verify that file is on block device | ||
| if (!file_is_on_bdev(dev->sd_cow->filp, bdev)) { | ||
| ret = -EINVAL; | ||
| LOG_ERROR(ret, "'%s' is not on '%s'", cow_path, bdev_name); | ||
| goto error; | ||
| if (file_is_on_bdev(dev->sd_cow->filp, bdev)) { | ||
| set_bit(SD_FLAG_COW_RESIDENT, &dev->sd_flags); | ||
| /* Cow file should not be on the same device as a fuse fs. | ||
| * This is because the typical setup for a fuse device involves | ||
| * calling mount() and /then/ setting its ioctl callbacks (open | ||
| * is of specific interest). Dormant- or unverified-to-active | ||
| * transitions cause a deadlock because open will be called in | ||
| * the mount syscall where the fuse device's callbacks won't | ||
| * have been set yet. We prevent this from happening by not | ||
| * allowing it in the first place. */ | ||
| if (0 == strncmp(bdev->bd_super->s_type->name, fuseblk_name, | ||
| FUSEBLK_MNT_LEN)) { | ||
| ret = -EDEADLOCK; | ||
| LOG_ERROR(ret, "Cow file cannot be on same volume for" | ||
|
Contributor
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. Feel free to ignore but as a user of this driver would it be helpful to know slightly more about why the cow file cannot be on the same block device without having to consult the code? The comment above is great. I'm just thinking about having a bit more information so that I could at least google an answer to why dattobd is telling me I cannot do what I want to do. We should probably consider adding enough information in our log messages so that steps to correct are at least Googleable. As I said, feel free to ignore, I'm just thinking about the experience of trying to figure out why something, that seems on the surface to be sane, does not work. |
||
| " fuse filesystems"); | ||
| return ret; | ||
| } | ||
| } | ||
|
|
||
| // find the cow file's inode number | ||
|
|
@@ -627,6 +648,12 @@ static void __tracer_destroy_cow_path(struct snap_device *dev) | |
| kfree(dev->sd_cow_path); | ||
| dev->sd_cow_path = NULL; | ||
| } | ||
|
|
||
| if (dev->sd_cow_full_path) { | ||
| LOG_DEBUG("freeing full cow path"); | ||
| kfree(dev->sd_cow_full_path); | ||
| dev->sd_cow_full_path = NULL; | ||
| } | ||
| } | ||
|
|
||
| static int __tracer_setup_cow_path(struct snap_device *dev, | ||
|
|
@@ -635,6 +662,11 @@ static int __tracer_setup_cow_path(struct snap_device *dev, | |
| int ret; | ||
|
|
||
| // get the pathname of the cow file (relative to the mountpoint) | ||
| LOG_DEBUG("getting absolute pathname of cow file"); | ||
| ret = file_get_absolute_pathname(cow_file, &dev->sd_cow_full_path, NULL); | ||
| if (ret) | ||
| goto error; | ||
|
|
||
| LOG_DEBUG("getting relative pathname of cow file"); | ||
| ret = dentry_get_relative_pathname(dattobd_get_dentry(cow_file), | ||
| &dev->sd_cow_path, NULL); | ||
|
|
@@ -1579,14 +1611,17 @@ void __tracer_dormant_to_active(struct snap_device *dev, | |
| const char __user *user_mount_path) | ||
| { | ||
| int ret; | ||
| char *resident_cow_path; | ||
| char *cow_path; | ||
|
|
||
| // generate the full pathname | ||
| ret = user_mount_pathname_concat(user_mount_path, dev->sd_cow_path, | ||
| &cow_path); | ||
| &resident_cow_path); | ||
| if (ret) | ||
| goto error; | ||
|
|
||
| cow_path = test_bit(SD_FLAG_COW_RESIDENT, &dev->sd_flags) ? resident_cow_path : dev->sd_cow_full_path; | ||
|
|
||
| // setup the cow manager | ||
| ret = __tracer_setup_cow_reopen(dev, dev->sd_base_dev, cow_path); | ||
| if (ret) | ||
|
|
@@ -1608,13 +1643,13 @@ void __tracer_dormant_to_active(struct snap_device *dev, | |
| set_bit(ACTIVE, &dev->sd_state); | ||
| clear_bit(UNVERIFIED, &dev->sd_state); | ||
|
|
||
| kfree(cow_path); | ||
| kfree(resident_cow_path); | ||
|
Contributor
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. Can this be freed immediately after __tracer_setup_cow_reopen() and then the extra test/free in the error: case could be removed? |
||
|
|
||
| return; | ||
|
|
||
| error: | ||
| LOG_ERROR(ret, "error transitioning tracer to active state"); | ||
| if (cow_path) | ||
| kfree(cow_path); | ||
| if (resident_cow_path) | ||
| kfree(resident_cow_path); | ||
| tracer_set_fail_state(dev, ret); | ||
| } | ||
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.
Should this be marked as deprecated in a comment?