Skip to content

Commit

Permalink
Using snap device in cow manager initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexScherba16 committed Jun 18, 2024
1 parent e9e8df1 commit 1921d08
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/bdev_state_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,15 @@ int handle_bdev_mount_event(const char *dir_name, int follow_flags,
if (!(follow_flags & UMOUNT_NOFOLLOW))
lookup_flags |= LOOKUP_FOLLOW;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0)
#if defined HAVE_KERN_PATH
ret = kern_path(dir_name, lookup_flags, &path);
#else
ret = user_path_at(AT_FDCWD, dir_name, lookup_flags, &path);
#endif //LINUX_VERSION_CODE
#endif //HAVE_KERN_PATH
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
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 1921d08

Please sign in to comment.