From 6226c77c445af64d46fca3c88beabe659978b6d4 Mon Sep 17 00:00:00 2001 From: Swistusmen Date: Thu, 17 Aug 2023 11:11:49 +0200 Subject: [PATCH 01/11] change-function-call --- .gitlab-ci.yml | 0 src/tracer.c | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 00000000..e69de29b diff --git a/src/tracer.c b/src/tracer.c index 5df1a56b..03412666 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -936,7 +936,7 @@ static void __tracer_destroy_snap(struct snap_device *dev) #ifdef HAVE_BLK_CLEANUP_QUEUE blk_cleanup_queue(dev->sd_queue); #else - blk_mq_destroy_queue(dev->sd_queue); + blk_put_queue(dev->sd_queue); #endif dev->sd_queue = NULL; } From 88c110bb887d54f4db1b244542715afa3ff31c4a Mon Sep 17 00:00:00 2001 From: Swistusmen Date: Tue, 22 Aug 2023 15:40:05 +0200 Subject: [PATCH 02/11] logs --- .gitlab-ci.yml | 0 src/bdev_state_handler.c | 12 +++++++----- src/dattobd.h | 2 +- src/module_control.c | 2 +- src/tracer.c | 2 ++ 5 files changed, 11 insertions(+), 7 deletions(-) delete mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index e69de29b..00000000 diff --git a/src/bdev_state_handler.c b/src/bdev_state_handler.c index c29b48df..5a1416e0 100644 --- a/src/bdev_state_handler.c +++ b/src/bdev_state_handler.c @@ -61,7 +61,7 @@ int __handle_bdev_mount_nowrite(const struct vfsmount *mnt, int ret; unsigned int i; struct snap_device *dev; - + LOG_DEBUG("__handle_bdev_mount_nowrite"); tracer_for_each(dev, i) { if (!dev || !test_bit(ACTIVE, &dev->sd_state) || @@ -82,6 +82,7 @@ int __handle_bdev_mount_nowrite(const struct vfsmount *mnt, } i = 0; ret = -ENODEV; + LOG_DEBUG("block device umount has not been detected for device"); out: *idx_out = i; return ret; @@ -185,18 +186,19 @@ int handle_bdev_mount_event(const char *dir_name, int follow_flags, struct path path; struct block_device *bdev; - //LOG_DEBUG("ENTER %s", __func__); + LOG_DEBUG("ENTER %s", __func__); if (!(follow_flags & UMOUNT_NOFOLLOW)) lookup_flags |= LOOKUP_FOLLOW; #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0) - ret = kern_path(dir_name, lookup_flags, &path); + ret = kern_path(dir_name, LOOKUP_FOLLOW, &path); + LOG_DEBUG("kern_path"); #else ret = user_path_at(AT_FDCWD, dir_name, lookup_flags, &path); #endif //LINUX_VERSION_CODE - //LOG_DEBUG("path->dentry: %s, path->mnt->mnt_root: %s", path.dentry->d_name.name, path.mnt->mnt_root->d_name.name); + LOG_DEBUG("path->dentry: %s, path->mnt->mnt_root: %s", path.dentry->d_name.name, path.mnt->mnt_root->d_name.name); if (path.dentry != path.mnt->mnt_root) { // path specified isn't a mount point @@ -208,7 +210,7 @@ int handle_bdev_mount_event(const char *dir_name, int follow_flags, bdev = path.mnt->mnt_sb->s_bdev; if (!bdev) { - //LOG_DEBUG("path specified isn't mounted on a block device"); + LOG_DEBUG("path specified isn't mounted on a block device"); ret = -ENODEV; goto out; } diff --git a/src/dattobd.h b/src/dattobd.h index 54d66013..6fdf46b1 100644 --- a/src/dattobd.h +++ b/src/dattobd.h @@ -15,7 +15,7 @@ #include #include -#define DATTOBD_VERSION "0.11.3" +#define DATTOBD_VERSION "0.11.4" #define DATTO_IOCTL_MAGIC 0x91 struct setup_params { diff --git a/src/module_control.c b/src/module_control.c index 802ef7d1..2ba25469 100644 --- a/src/module_control.c +++ b/src/module_control.c @@ -42,7 +42,7 @@ int dattobd_may_hook_syscalls = 1; unsigned long dattobd_cow_max_memory_default = (300 * 1024 * 1024); unsigned int dattobd_cow_fallocate_percentage_default = 10; unsigned int dattobd_max_snap_devices = DATTOBD_DEFAULT_SNAP_DEVICES; -int dattobd_debug = 0; +int dattobd_debug = 1; module_param_named(may_hook_syscalls, dattobd_may_hook_syscalls, int, S_IRUGO); MODULE_PARM_DESC(may_hook_syscalls, diff --git a/src/tracer.c b/src/tracer.c index 03412666..9fc007eb 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -913,6 +913,7 @@ static void __tracer_bioset_exit(struct snap_device *dev) */ static void __tracer_destroy_snap(struct snap_device *dev) { + LOG_DEBUG("tracer_destroy_snap"); if (dev->sd_mrf_thread) { LOG_DEBUG("stopping mrf thread"); kthread_stop(dev->sd_mrf_thread); @@ -936,6 +937,7 @@ static void __tracer_destroy_snap(struct snap_device *dev) #ifdef HAVE_BLK_CLEANUP_QUEUE blk_cleanup_queue(dev->sd_queue); #else + blk_mq_destroy_queue(dev->sd_queue); blk_put_queue(dev->sd_queue); #endif dev->sd_queue = NULL; From 2ad1df56f7d9b275de3a9da27e2e1191b5dedcd6 Mon Sep 17 00:00:00 2001 From: Swistusmen Date: Tue, 22 Aug 2023 16:10:10 +0200 Subject: [PATCH 03/11] fix --- src/bdev_state_handler.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/bdev_state_handler.c b/src/bdev_state_handler.c index 5a1416e0..d3e737de 100644 --- a/src/bdev_state_handler.c +++ b/src/bdev_state_handler.c @@ -69,16 +69,11 @@ int __handle_bdev_mount_nowrite(const struct vfsmount *mnt, dev->sd_base_dev != mnt->mnt_sb->s_bdev) continue; - // if we are unmounting the vfsmount we are using go to dormant - // state - if (mnt == dattobd_get_mnt(dev->sd_cow->filp)) { - LOG_DEBUG("block device umount detected for device %d", - i); auto_transition_dormant(i); ret = 0; goto out; - } + } i = 0; ret = -ENODEV; From 3f18ed975fcf0e179db93d4a139194932977fd84 Mon Sep 17 00:00:00 2001 From: Swistusmen Date: Tue, 22 Aug 2023 17:24:35 +0200 Subject: [PATCH 04/11] testing --- src/tracer.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tracer.c b/src/tracer.c index 9fc007eb..957a1149 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -937,7 +937,6 @@ static void __tracer_destroy_snap(struct snap_device *dev) #ifdef HAVE_BLK_CLEANUP_QUEUE blk_cleanup_queue(dev->sd_queue); #else - blk_mq_destroy_queue(dev->sd_queue); blk_put_queue(dev->sd_queue); #endif dev->sd_queue = NULL; From 59b6aeb7c288d3cf6e5c384176b362ea1febf51a Mon Sep 17 00:00:00 2001 From: Swistusmen Date: Wed, 23 Aug 2023 08:49:27 +0200 Subject: [PATCH 05/11] blk_mq_destroy_queue --- src/tracer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tracer.c b/src/tracer.c index 957a1149..33019b1c 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -937,7 +937,7 @@ static void __tracer_destroy_snap(struct snap_device *dev) #ifdef HAVE_BLK_CLEANUP_QUEUE blk_cleanup_queue(dev->sd_queue); #else - blk_put_queue(dev->sd_queue); + blk_mq_destroy_queue(dev->sd_queue); #endif dev->sd_queue = NULL; } From 5a3e4fb6e8cf804e7f24b6e9896a1edf75b6b185 Mon Sep 17 00:00:00 2001 From: Swistusmen Date: Wed, 23 Aug 2023 10:50:35 +0200 Subject: [PATCH 06/11] new-flags --- src/bio_helper.c | 2 ++ src/tracer.c | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/bio_helper.c b/src/bio_helper.c index bacca4ca..6c3d4a6b 100644 --- a/src/bio_helper.c +++ b/src/bio_helper.c @@ -734,6 +734,8 @@ int bio_make_read_clone(struct bio_set *bs, struct tracing_params *tp, new_bio->bi_blkg = orig_bio->bi_blkg; } #endif + bio_set_flag(new_bio, BIO_REMAPPED); + bio_set_flag(new_bio, BIO_THROTTLED); // fill the bio with pages for (i = 0; i < actual_pages; i++) { diff --git a/src/tracer.c b/src/tracer.c index 33019b1c..c7007060 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -172,6 +172,7 @@ void dattobd_free_request_tracking_ptr(struct snap_device *dev) */ static int snap_trace_bio(struct snap_device *dev, struct bio *bio) { + LOG_DEBUG("snap_trace_bio"); int ret; struct bio *new_bio = NULL; struct tracing_params *tp = NULL; @@ -1601,7 +1602,6 @@ int __tracer_setup_tracing(struct snap_device *dev, unsigned int minor) ret = dattobd_find_orig_mrf(dev->sd_base_dev, &dev->sd_orig_request_fn); if (ret) goto error; -#endif ret = __tracer_transition_tracing( dev, dev->sd_base_dev, @@ -1609,6 +1609,30 @@ int __tracer_setup_tracing(struct snap_device *dev, unsigned int minor) &snap_devices[minor]); if (ret) goto error; +#else + if (!dev->sd_tracing_ops) { + // Multiple devices on the same disk are sharing block_device_operations struct. + // The next call will set a pointer to the dev->sd_tracing_ops if some device at the same disk is + // already tracked by the driver. And we'll reuse the existing struct in this case. + ret = find_orig_fops(dev->sd_base_dev, &dev->sd_orig_ops, &dev->sd_orig_mrf, &dev->sd_tracing_ops); + if(ret) goto error; + + if (!dev->sd_tracing_ops) { + LOG_DEBUG("allocating tracing ops for device with minor %i", minor); + ret = tracing_ops_alloc(dev); + if (ret) goto error; + } + else { + LOG_DEBUG("using already existing tracing ops for device with minor %i", minor); + } + + ret = __tracer_transition_tracing(dev, dev->sd_base_dev, dev->sd_tracing_ops->bd_ops, &snap_devices[minor]); + } + else { + LOG_DEBUG("device with minor %i already has sd_tracing_ops", minor); + } +#endif + return 0; error: From 39aa615662244b17a7e7b27c9cf73b2c6ecfb1d5 Mon Sep 17 00:00:00 2001 From: Swistusmen Date: Wed, 23 Aug 2023 10:58:55 +0200 Subject: [PATCH 07/11] new-flags --- src/tracer.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/src/tracer.c b/src/tracer.c index c7007060..45feb534 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -1602,6 +1602,7 @@ int __tracer_setup_tracing(struct snap_device *dev, unsigned int minor) ret = dattobd_find_orig_mrf(dev->sd_base_dev, &dev->sd_orig_request_fn); if (ret) goto error; +#endif ret = __tracer_transition_tracing( dev, dev->sd_base_dev, @@ -1609,30 +1610,6 @@ int __tracer_setup_tracing(struct snap_device *dev, unsigned int minor) &snap_devices[minor]); if (ret) goto error; -#else - if (!dev->sd_tracing_ops) { - // Multiple devices on the same disk are sharing block_device_operations struct. - // The next call will set a pointer to the dev->sd_tracing_ops if some device at the same disk is - // already tracked by the driver. And we'll reuse the existing struct in this case. - ret = find_orig_fops(dev->sd_base_dev, &dev->sd_orig_ops, &dev->sd_orig_mrf, &dev->sd_tracing_ops); - if(ret) goto error; - - if (!dev->sd_tracing_ops) { - LOG_DEBUG("allocating tracing ops for device with minor %i", minor); - ret = tracing_ops_alloc(dev); - if (ret) goto error; - } - else { - LOG_DEBUG("using already existing tracing ops for device with minor %i", minor); - } - - ret = __tracer_transition_tracing(dev, dev->sd_base_dev, dev->sd_tracing_ops->bd_ops, &snap_devices[minor]); - } - else { - LOG_DEBUG("device with minor %i already has sd_tracing_ops", minor); - } -#endif - return 0; error: From 69928dcf0322680b389e12b9985c820630b73d76 Mon Sep 17 00:00:00 2001 From: Swistusmen Date: Wed, 23 Aug 2023 11:01:31 +0200 Subject: [PATCH 08/11] new-flags --- src/bio_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bio_helper.c b/src/bio_helper.c index 6c3d4a6b..8930d273 100644 --- a/src/bio_helper.c +++ b/src/bio_helper.c @@ -735,7 +735,7 @@ int bio_make_read_clone(struct bio_set *bs, struct tracing_params *tp, } #endif bio_set_flag(new_bio, BIO_REMAPPED); - bio_set_flag(new_bio, BIO_THROTTLED); + bio_set_flag(new_bio, BIO_QOS_THROTTLED); // fill the bio with pages for (i = 0; i < actual_pages; i++) { From 324c1c678ba62860382716cc6a7616e6ce7fc32a Mon Sep 17 00:00:00 2001 From: Swistusmen Date: Wed, 23 Aug 2023 11:30:25 +0200 Subject: [PATCH 09/11] fixing-flags --- src/bio_helper.c | 1 + src/tracer.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bio_helper.c b/src/bio_helper.c index 8930d273..f21d55ce 100644 --- a/src/bio_helper.c +++ b/src/bio_helper.c @@ -736,6 +736,7 @@ int bio_make_read_clone(struct bio_set *bs, struct tracing_params *tp, #endif bio_set_flag(new_bio, BIO_REMAPPED); bio_set_flag(new_bio, BIO_QOS_THROTTLED); + bio_set_flag(new_bio, BIO_CLONED); // fill the bio with pages for (i = 0; i < actual_pages; i++) { diff --git a/src/tracer.c b/src/tracer.c index 45feb534..295b0745 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -938,7 +938,8 @@ static void __tracer_destroy_snap(struct snap_device *dev) #ifdef HAVE_BLK_CLEANUP_QUEUE blk_cleanup_queue(dev->sd_queue); #else - blk_mq_destroy_queue(dev->sd_queue); + blk_put_queue(dev->sd_queue); + //blk_mq_destroy_queue(dev->sd_queue); #endif dev->sd_queue = NULL; } From dd041ac05ac8f80d728f7561b61b408195620e3a Mon Sep 17 00:00:00 2001 From: Swistusmen Date: Wed, 23 Aug 2023 13:10:09 +0200 Subject: [PATCH 10/11] removing-not-needed-logs --- src/bdev_state_handler.c | 2 -- src/dattobd.h | 2 +- src/module_control.c | 2 +- src/tracer.c | 2 -- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/bdev_state_handler.c b/src/bdev_state_handler.c index d3e737de..e62a34be 100644 --- a/src/bdev_state_handler.c +++ b/src/bdev_state_handler.c @@ -61,7 +61,6 @@ int __handle_bdev_mount_nowrite(const struct vfsmount *mnt, int ret; unsigned int i; struct snap_device *dev; - LOG_DEBUG("__handle_bdev_mount_nowrite"); tracer_for_each(dev, i) { if (!dev || !test_bit(ACTIVE, &dev->sd_state) || @@ -188,7 +187,6 @@ int handle_bdev_mount_event(const char *dir_name, int follow_flags, #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0) ret = kern_path(dir_name, LOOKUP_FOLLOW, &path); - LOG_DEBUG("kern_path"); #else ret = user_path_at(AT_FDCWD, dir_name, lookup_flags, &path); #endif //LINUX_VERSION_CODE diff --git a/src/dattobd.h b/src/dattobd.h index 6fdf46b1..54d66013 100644 --- a/src/dattobd.h +++ b/src/dattobd.h @@ -15,7 +15,7 @@ #include #include -#define DATTOBD_VERSION "0.11.4" +#define DATTOBD_VERSION "0.11.3" #define DATTO_IOCTL_MAGIC 0x91 struct setup_params { diff --git a/src/module_control.c b/src/module_control.c index 2ba25469..802ef7d1 100644 --- a/src/module_control.c +++ b/src/module_control.c @@ -42,7 +42,7 @@ int dattobd_may_hook_syscalls = 1; unsigned long dattobd_cow_max_memory_default = (300 * 1024 * 1024); unsigned int dattobd_cow_fallocate_percentage_default = 10; unsigned int dattobd_max_snap_devices = DATTOBD_DEFAULT_SNAP_DEVICES; -int dattobd_debug = 1; +int dattobd_debug = 0; module_param_named(may_hook_syscalls, dattobd_may_hook_syscalls, int, S_IRUGO); MODULE_PARM_DESC(may_hook_syscalls, diff --git a/src/tracer.c b/src/tracer.c index 295b0745..957a1149 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -172,7 +172,6 @@ void dattobd_free_request_tracking_ptr(struct snap_device *dev) */ static int snap_trace_bio(struct snap_device *dev, struct bio *bio) { - LOG_DEBUG("snap_trace_bio"); int ret; struct bio *new_bio = NULL; struct tracing_params *tp = NULL; @@ -939,7 +938,6 @@ static void __tracer_destroy_snap(struct snap_device *dev) blk_cleanup_queue(dev->sd_queue); #else blk_put_queue(dev->sd_queue); - //blk_mq_destroy_queue(dev->sd_queue); #endif dev->sd_queue = NULL; } From 60ff9b725bd29a7357fd658846602ec1ad310a74 Mon Sep 17 00:00:00 2001 From: Natalia Zelazna Date: Thu, 7 Sep 2023 16:39:23 +0200 Subject: [PATCH 11/11] ifdefs needed for older kernels/distros build --- src/bio_helper.c | 5 +++++ .../feature-tests/bio_qos_throttled.c | 14 ++++++++++++++ src/configure-tests/feature-tests/bio_remapped.c | 14 ++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/configure-tests/feature-tests/bio_qos_throttled.c create mode 100644 src/configure-tests/feature-tests/bio_remapped.c diff --git a/src/bio_helper.c b/src/bio_helper.c index f21d55ce..d40d5099 100644 --- a/src/bio_helper.c +++ b/src/bio_helper.c @@ -734,8 +734,13 @@ int bio_make_read_clone(struct bio_set *bs, struct tracing_params *tp, new_bio->bi_blkg = orig_bio->bi_blkg; } #endif +#ifdef HAVE_BIO_REMAPPED bio_set_flag(new_bio, BIO_REMAPPED); +#endif +#ifdef HAVE_BIO_QOS_THROTTLED bio_set_flag(new_bio, BIO_QOS_THROTTLED); +#endif + bio_set_flag(new_bio, BIO_CLONED); // fill the bio with pages diff --git a/src/configure-tests/feature-tests/bio_qos_throttled.c b/src/configure-tests/feature-tests/bio_qos_throttled.c new file mode 100644 index 00000000..038ac908 --- /dev/null +++ b/src/configure-tests/feature-tests/bio_qos_throttled.c @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Copyright (C) 2015 Datto Inc. + */ + +#include "includes.h" + +MODULE_LICENSE("GPL"); + +static inline void dummy(void){ + struct bio *new_bio = NULL; + bio_set_flag(new_bio, BIO_QOS_THROTTLED); +} \ No newline at end of file diff --git a/src/configure-tests/feature-tests/bio_remapped.c b/src/configure-tests/feature-tests/bio_remapped.c new file mode 100644 index 00000000..9674c276 --- /dev/null +++ b/src/configure-tests/feature-tests/bio_remapped.c @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Copyright (C) 2015 Datto Inc. + */ + +#include "includes.h" + +MODULE_LICENSE("GPL"); + +static inline void dummy(void){ + struct bio *new_bio = NULL; + bio_set_flag(new_bio, BIO_REMAPPED); +} \ No newline at end of file