Skip to content
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

cleaning-code #366

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/cow_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#define get_zeroed_pages(flags, order) \
__get_free_pages(((flags) | __GFP_ZERO), order)


static unsigned long dattobd_cow_ext_buf_size = sizeof(struct fiemap_extent) * 1024;

/**
* __cow_free_section() - Frees the memory used to track the section at
* offset @sect_idx and marks the array entry as unused.
Expand Down Expand Up @@ -99,8 +102,8 @@ int __cow_load_section(struct cow_manager *cm, unsigned long sect_idx)
int mapping_offset = (COW_BLOCK_SIZE / sizeof(cm->sects[sect_idx].mappings[0])) * i;
int cow_file_offset = COW_BLOCK_SIZE * i;

ret = file_read(cm->filp, cm->dev, cm->sects[sect_idx].mappings,
cm->sect_size * sect_idx * 8 + COW_HEADER_SIZE,
ret = file_read(cm->filp, cm->dev, cm->sects[sect_idx].mappings+ mapping_offset,
cm->sect_size * sect_idx * 8 + COW_HEADER_SIZE+ cow_file_offset,
cm->sect_size * 8);
if (ret)
goto error;
Expand Down Expand Up @@ -133,8 +136,8 @@ int __cow_write_section(struct cow_manager *cm, unsigned long sect_idx)
int mapping_offset = (COW_BLOCK_SIZE / sizeof(cm->sects[sect_idx].mappings[0])) * i;
int cow_file_offset = COW_BLOCK_SIZE * i;

ret = file_write(cm->filp, cm->dev, cm->sects[sect_idx].mappings,
cm->sect_size * sect_idx * 8 + COW_HEADER_SIZE,
ret = file_write(cm->filp, cm->dev, cm->sects[sect_idx].mappings+ mapping_offset,
cm->sect_size * sect_idx * 8 + COW_HEADER_SIZE+ cow_file_offset,
cm->sect_size * 8);
if (ret) {
LOG_ERROR(ret, "error writing cow manager section to file");
Expand Down Expand Up @@ -958,7 +961,7 @@ int cow_write_current(struct cow_manager *cm, uint64_t block, void *buf)
goto error;

// write the data
ret = __cow_write_data(cm, buf);
ret = __cow_write_data(cm, buf); //cow file max size exceeded, "error writing cow data"
if (ret)
goto error;

Expand Down Expand Up @@ -1000,6 +1003,13 @@ int cow_read_data(struct cow_manager *cm, void *buf, uint64_t block_pos,
return 0;
}

/**
* cow_get_file_extents- EXT and XFS tries to avoid fragmentation by prealocating more data than currently neededfro the file. We had and issue with modyfing extends during maintanance operations
* processed on XFS. This function checks locations of extents, accesses this memory (and protects it from being allocated) and links snap_device to this.
*
* @dev: snap device
* @filp: file
*/
int cow_get_file_extents(struct snap_device* dev, struct file* filp)
{
int ret;
Expand Down
1 change: 0 additions & 1 deletion src/cow_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#define COW_SECTION_SIZE 4096

#define cow_write_filler_mapping(cm, pos) __cow_write_mapping(cm, pos, 1)
static unsigned long dattobd_cow_ext_buf_size = sizeof(struct fiemap_extent) * 1024;

/**
* struct cow_section - maintains data and usage statistics for a cow section.
Expand Down
69 changes: 37 additions & 32 deletions src/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ static ssize_t dattobd_kernel_read(struct file *filp, struct snap_device* dev, v
* dattobd_kernel_write() - This is a wrapper around kernel_write enhanced for
* systems that don't support it.
* @filp: A &struct file object.
* @dev: a snap device
* @buf: A buffer with at least @count entries.
* @count: The number of bytes to write to @filp.
* @pos: Set to the offset into @filp identifying the first sequential access.
Expand Down Expand Up @@ -125,6 +126,7 @@ static ssize_t dattobd_kernel_write(struct file *filp,struct snap_device* dev, c
* file_io() - Reads or writes to the supplied file.
*
* @cm: A pointer to the cow manager
* @dev: a snap device
* @is_write: An integer encoded bool indicating a write or read operation.
* @buf: Input/output buffer for write/read, respectively.
* @offset: Byte offset of the first sequential access within @filp.
Expand Down Expand Up @@ -161,36 +163,6 @@ int file_io(struct file *filp, struct snap_device* dev, int is_write, void *buf,
return 0;
}

/**
* file_write() - Writes @len bytes of data to offset @offset within @filp from
* @buf.
*
* @cm: A pointer to the cow manager object.
* @buf: Input buffer for write.
* @offset: Byte offset of the first sequential access within @filp.
* @len: The number of bytes in the transfer.
*
* Return:
* * 0 - success
* * !0 - errno indicating the error
*/
//#define file_write(filp, dev, buf, offset, len) file_io(filp, dev, 1, buf, offset, len)

/**
* file_read() - Store @len bytes of data from offset @offset within @filp into
* @buf.
*
* @cm: A pointer to the cow manager object.
* @buf: Output buffer for read.
* @offset: Byte offset of the first sequential access within @filp.
* @len: The number of bytes in the transfer.
*
* Return:
* * 0 - success
* * !0 - errno indicating the error
*/
//#define file_read(filp, dev, buf, offset, len) file_io(filp, dev, 0, buf, offset, len)

/**
* file_close() - Closes the file object.
*
Expand Down Expand Up @@ -795,6 +767,7 @@ static int real_fallocate(struct file *f, uint64_t offset, uint64_t length)
* @real_fallocate with a fallback of writing zeroes if that fails.
*
* @cm: A &struct cow_manager object.
* @dev: A snap device
* @offset: The offset into @f indicating the start of the allocation.
* @length: The number of byte to allocate starting at @offset.
*
Expand Down Expand Up @@ -842,7 +815,6 @@ int file_allocate(struct file *filp, struct snap_device* dev, uint64_t offset,
}
file_lock(filp);

out:
if (page_buf)
free_page((unsigned long)page_buf);
if (abs_path)
Expand Down Expand Up @@ -1005,6 +977,10 @@ void dattobd_inode_unlock(struct inode *inode)
struct kmem_cache **vm_area_cache = (VM_AREA_CACHEP_ADDR != 0) ?
(struct kmem_cache **) (VM_AREA_CACHEP_ADDR + (long long)(((void *)kfree) - (void *)KFREE_ADDR)) : NULL;

/**
* dattobd_vm_area_allocate- alocates virtual memory
* @mm: memory address space data
*/
struct vm_area_struct* dattobd_vm_area_allocate(struct mm_struct* mm)
{
struct vm_area_struct *vma;
Expand All @@ -1026,11 +1002,19 @@ struct vm_area_struct* dattobd_vm_area_allocate(struct mm_struct* mm)
return vma;
}

/**
* dattobd_vm_area_free- frees vm cache
* @mm: memory address space data
*/
void dattobd_vm_area_free(struct vm_area_struct *vma)
{
kmem_cache_free(*vm_area_cache, vma);
}

/**
* dattobd_mm_lock- frees vm cache
* @mm: memory address space data
*/
void dattobd_mm_lock(struct mm_struct* mm)
{
#ifdef HAVE_MMAP_WRITE_LOCK
Expand Down Expand Up @@ -1071,6 +1055,14 @@ void file_switch_lock(struct file* filp, bool lock, bool mark_dirty)
iput(inode);
}

/**
* file_write_block- writes block to the memory
*
* @dev: snap device
* @block: block we want to save
* @offset: current file offset
* @len: block length
*/
int file_write_block(struct snap_device* dev, const void* block, size_t offset, size_t len)
{
int ret;
Expand Down Expand Up @@ -1111,7 +1103,6 @@ int file_write_block(struct snap_device* dev, const void* block, size_t offset,

dattobd_bio_set_dev(new_bio, bdev);
dattobd_set_bio_ops(new_bio, REQ_OP_READ, 0);
//from bio_helper.h
bio_sector(new_bio) = start_sect;
bio_idx(new_bio) = 0;

Expand Down Expand Up @@ -1172,6 +1163,14 @@ int file_write_block(struct snap_device* dev, const void* block, size_t offset,
return ret;
}

/**
* file_read_block
*
* @dev: snap device
* @block: block we want to save
* @offset: current file offset
* @len: length
*/
int file_read_block(struct snap_device* dev, void* block, size_t offset, size_t len)
{
int ret;
Expand Down Expand Up @@ -1290,6 +1289,12 @@ WARN_ON(len > SECTORS_PER_BLOCK);
return ret;
}

/**
* sector_by_offset- get the specified sector
*
* @dev: snap device
* @offset:
*/
sector_t sector_by_offset(struct snap_device*dev, size_t offset)
{
unsigned int i;
Expand Down
2 changes: 1 addition & 1 deletion src/snap_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ int snap_handle_write_bio(const struct snap_device *dev, struct bio *bio)
// to be block aligned)
const unsigned long long number_of_blocks=bio_size(bio);
unsigned long long saved_blocks=0;

#ifdef HAVE_BVEC_ITER_ALL
bio_for_each_segment_all(bvec, bio, iter) {
#else
Expand Down
2 changes: 1 addition & 1 deletion src/tracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1559,9 +1559,9 @@ static int __tracer_should_reset_mrf(const struct snap_device *dev)
{
int i;
struct snap_device *cur_dev;
struct request_queue *q = bdev_get_queue(dev->sd_base_dev);

#ifndef USE_BDOPS_SUBMIT_BIO
struct request_queue *q = bdev_get_queue(dev->sd_base_dev);
if (GET_BIO_REQUEST_TRACKING_PTR(dev->sd_base_dev) != tracing_fn) return 0;
#else
struct block_device_operations* ops=dattobd_get_bd_ops(dev->sd_base_dev);
Expand Down