Skip to content

Commit

Permalink
Use snap device in cow manager initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexScherba16 committed Jul 24, 2024
1 parent b64bfac commit 3ef2367
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions dist/dattobd.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
17 changes: 10 additions & 7 deletions src/bdev_state_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) ||
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/blkdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 3 additions & 1 deletion src/cow_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/cow_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 5 additions & 4 deletions src/tracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3ef2367

Please sign in to comment.