From 3ef2367eb5edaa5a2254ce57b78456a11c768488 Mon Sep 17 00:00:00 2001 From: Aliaksandr Shcherba Date: Tue, 18 Jun 2024 11:44:39 +0200 Subject: [PATCH] Use snap device in cow manager initialization --- dist/dattobd.spec | 4 ++-- src/bdev_state_handler.c | 17 ++++++++++------- src/blkdev.c | 2 +- src/cow_manager.c | 4 +++- src/cow_manager.h | 2 +- src/tracer.c | 9 +++++---- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/dist/dattobd.spec b/dist/dattobd.spec index a2192fd5..7a1f5c04 100644 --- a/dist/dattobd.spec +++ b/dist/dattobd.spec @@ -473,7 +473,7 @@ fi if [ ! -d %{_systemd_services}/reboot.target.wants/ ]; then mkdir -p %{_systemd_services}/reboot.target.wants fi -ln -s %{_systemd_services}/umount-rootfs.service %{_systemd_services}/reboot.target.wants/umount-rootfs.service +ln -fs %{_systemd_services}/umount-rootfs.service %{_systemd_services}/reboot.target.wants/umount-rootfs.service %postun -n %{libname} /sbin/ldconfig @@ -517,7 +517,7 @@ rm -rf %{buildroot} %post -ln -s %{_systemd_services}/umount-rootfs.service %{_systemd_services}/reboot.target.wants/umount-rootfs.service +ln -fs %{_systemd_services}/umount-rootfs.service %{_systemd_services}/reboot.target.wants/umount-rootfs.service %doc README.md doc/STRUCTURE.md %if "%{_vendor}" == "redhat" diff --git a/src/bdev_state_handler.c b/src/bdev_state_handler.c index c492f59a..7e515e62 100644 --- a/src/bdev_state_handler.c +++ b/src/bdev_state_handler.c @@ -28,7 +28,7 @@ void auto_transition_active(unsigned int minor, const char *dir_name) { struct snap_device *dev = snap_devices[minor]; -LOG_DEBUG("ENTER %s minor: %d", __func__, minor); + LOG_DEBUG("ENTER %s minor: %d", __func__, minor); mutex_lock(&ioctl_mutex); if (test_bit(UNVERIFIED, &dev->sd_state)) { @@ -107,8 +107,7 @@ int __handle_bdev_mount_writable(const char *dir_name, struct snap_device *dev; struct block_device *cur_bdev; - LOG_DEBUG("ENTER __handle_bdev_mount_writable"); - + LOG_DEBUG("ENTER %s", __func__); tracer_for_each(dev, i) { if (!dev || test_bit(ACTIVE, &dev->sd_state) || @@ -159,7 +158,7 @@ int __handle_bdev_mount_writable(const char *dir_name, ret = -ENODEV; out: - LOG_DEBUG("EXIT __handle_bdev_mount_writable"); + LOG_DEBUG("EXIT %s", __func__); *idx_out = i; return ret; } @@ -194,6 +193,10 @@ int handle_bdev_mount_event(const char *dir_name, int follow_flags, #else ret = user_path_at(AT_FDCWD, dir_name, lookup_flags, &path); #endif //LINUX_VERSION_CODE + if (ret) { + LOG_DEBUG("error finding path"); + goto out; + } LOG_DEBUG("path->dentry: %s, path->mnt->mnt_root: %s", path.dentry->d_name.name, path.mnt->mnt_root->d_name.name); @@ -245,10 +248,10 @@ void post_umount_check(int dormant_ret, int umount_ret, unsigned int idx, struct snap_device *dev; struct super_block *sb; - //LOG_DEBUG("ENTER %s", __func__); + LOG_DEBUG("ENTER %s", __func__); // if we didn't do anything or failed, just return - if (dormant_ret){ - //LOG_DEBUG("dormant_ret"); + if (dormant_ret) { + LOG_DEBUG("EXIT %s, dormant_ret", __func__); return; } dev = snap_devices[idx]; diff --git a/src/blkdev.c b/src/blkdev.c index 45a9dcd3..f54502f3 100644 --- a/src/blkdev.c +++ b/src/blkdev.c @@ -166,7 +166,7 @@ void dattobd_drop_super(struct super_block *sb) /** * dattobd_blkdev_put() - Releases a reference to a block device. * This function performs the appropriate action based on the available - * kernel functions to release or drop the superblock. + * kernel functions to release block device. * * @bd: block device structure pointer to be released. * diff --git a/src/cow_manager.c b/src/cow_manager.c index 4fbf799a..45ff43a9 100644 --- a/src/cow_manager.c +++ b/src/cow_manager.c @@ -642,6 +642,7 @@ int cow_reload(const char *path, uint64_t elements, unsigned long sect_size, * cow_init() - Allocates a &struct cow_manager object and initializes it. * Also creates the COW backing file on disk and writes a * header into it. + * @dev: The &struct snap_device that keeps snapshot device state. * @path: The path to the COW file. * @elements: typically the number of sectors on the block device. * @sect_size: The basic unit of size that the &struct cow_manager works with. @@ -656,7 +657,7 @@ int cow_reload(const char *path, uint64_t elements, unsigned long sect_size, * * 0 - success * * !0 - errno indicating the error */ -int cow_init(const char *path, uint64_t elements, unsigned long sect_size, +int cow_init(struct snap_device *dev, const char *path, uint64_t elements, unsigned long sect_size, unsigned long cache_size, uint64_t file_max, const uint8_t *uuid, uint64_t seqid, struct cow_manager **cm_out) { @@ -691,6 +692,7 @@ int cow_init(const char *path, uint64_t elements, unsigned long sect_size, __cow_calculate_allowed_sects(cache_size, cm->total_sects); cm->data_offset = COW_HEADER_SIZE + (cm->total_sects * (sect_size * 8)); cm->curr_pos = cm->data_offset / COW_BLOCK_SIZE; + cm->dev = dev; if (uuid) memcpy(cm->uuid, uuid, COW_UUID_SIZE); diff --git a/src/cow_manager.h b/src/cow_manager.h index ddd64716..626b37bd 100644 --- a/src/cow_manager.h +++ b/src/cow_manager.h @@ -81,7 +81,7 @@ int cow_reload(const char *path, uint64_t elements, unsigned long sect_size, unsigned long cache_size, int index_only, struct cow_manager **cm_out); -int cow_init(const char *path, uint64_t elements, unsigned long sect_size, +int cow_init(struct snap_device *dev, const char *path, uint64_t elements, unsigned long sect_size, unsigned long cache_size, uint64_t file_max, const uint8_t *uuid, uint64_t seqid, struct cow_manager **cm_out); diff --git a/src/tracer.c b/src/tracer.c index a22a4334..5dc2dceb 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -646,7 +646,7 @@ static int __tracer_setup_cow(struct snap_device *dev, // create and open the cow manager LOG_DEBUG("creating cow manager"); - ret = cow_init(cow_path, SECTOR_TO_BLOCK(size), + ret = cow_init(dev, cow_path, SECTOR_TO_BLOCK(size), COW_SECTION_SIZE, dev->sd_cache_size, max_file_size, uuid, seqid, &dev->sd_cow); @@ -858,10 +858,11 @@ static void __tracer_copy_cow(const struct snap_device *src, { dest->sd_cow = src->sd_cow; // copy cow file extents and update the device - dest->sd_cow_extents = src->sd_cow_extents; - dest->sd_cow_ext_cnt = src->sd_cow_ext_cnt; - + dest->sd_cow_extents = src->sd_cow_extents; + dest->sd_cow_ext_cnt = src->sd_cow_ext_cnt; dest->sd_cow_inode = src->sd_cow_inode; + dest->sd_cow->dev = dest; + dest->sd_cache_size = src->sd_cache_size; dest->sd_falloc_size = src->sd_falloc_size; }