mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-03-10 00:00:04 +03:00
Prettify the align_io function by returning by value.
This commit is contained in:
parent
de151b0659
commit
fd0b8fe7f0
@ -375,19 +375,23 @@ struct fuse_align_io {
|
|||||||
|
|
||||||
/* Handle unaligned start and end */
|
/* Handle unaligned start and end */
|
||||||
/* TODO: align to block_bytes, sector size, or page size? */
|
/* TODO: align to block_bytes, sector size, or page size? */
|
||||||
static void align_io(struct fuse_align_io *align, const struct bch_fs *c,
|
static struct fuse_align_io align_io(const struct bch_fs *c, size_t size,
|
||||||
size_t size, off_t offset)
|
off_t offset)
|
||||||
{
|
{
|
||||||
|
struct fuse_align_io align;
|
||||||
|
|
||||||
BUG_ON(offset < 0);
|
BUG_ON(offset < 0);
|
||||||
|
|
||||||
align->start = round_down(offset, block_bytes(c));
|
align.start = round_down(offset, block_bytes(c));
|
||||||
align->pad_start = offset - align->start;
|
align.pad_start = offset - align.start;
|
||||||
|
|
||||||
off_t end = offset + size;
|
off_t end = offset + size;
|
||||||
align->end = round_up(end, block_bytes(c));
|
align.end = round_up(end, block_bytes(c));
|
||||||
align->pad_end = align->end - end;
|
align.pad_end = align.end - end;
|
||||||
|
|
||||||
align->size = align->end - align->start;
|
align.size = align.end - align.start;
|
||||||
|
|
||||||
|
return align;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -445,7 +449,6 @@ static void bcachefs_fuse_read(fuse_req_t req, fuse_ino_t inum,
|
|||||||
struct fuse_file_info *fi)
|
struct fuse_file_info *fi)
|
||||||
{
|
{
|
||||||
struct bch_fs *c = fuse_req_userdata(req);
|
struct bch_fs *c = fuse_req_userdata(req);
|
||||||
struct fuse_align_io align;
|
|
||||||
|
|
||||||
fuse_log(FUSE_LOG_DEBUG, "bcachefs_fuse_read(%llu, %zd, %lld)\n",
|
fuse_log(FUSE_LOG_DEBUG, "bcachefs_fuse_read(%llu, %zd, %lld)\n",
|
||||||
inum, size, offset);
|
inum, size, offset);
|
||||||
@ -465,7 +468,7 @@ static void bcachefs_fuse_read(fuse_req_t req, fuse_ino_t inum,
|
|||||||
}
|
}
|
||||||
size = end - offset;
|
size = end - offset;
|
||||||
|
|
||||||
align_io(&align, c, size, offset);
|
struct fuse_align_io align = align_io(c, size, offset);
|
||||||
|
|
||||||
void *buf = aligned_alloc(PAGE_SIZE, align.size);
|
void *buf = aligned_alloc(PAGE_SIZE, align.size);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
@ -567,14 +570,13 @@ static void bcachefs_fuse_write(fuse_req_t req, fuse_ino_t inum,
|
|||||||
{
|
{
|
||||||
struct bch_fs *c = fuse_req_userdata(req);
|
struct bch_fs *c = fuse_req_userdata(req);
|
||||||
struct bch_io_opts io_opts;
|
struct bch_io_opts io_opts;
|
||||||
struct fuse_align_io align;
|
|
||||||
size_t aligned_written;
|
size_t aligned_written;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
fuse_log(FUSE_LOG_DEBUG, "bcachefs_fuse_write(%llu, %zd, %lld)\n",
|
fuse_log(FUSE_LOG_DEBUG, "bcachefs_fuse_write(%llu, %zd, %lld)\n",
|
||||||
inum, size, offset);
|
inum, size, offset);
|
||||||
|
|
||||||
align_io(&align, c, size, offset);
|
struct fuse_align_io align = align_io(c, size, offset);
|
||||||
|
|
||||||
if (get_inode_io_opts(c, inum, &io_opts)) {
|
if (get_inode_io_opts(c, inum, &io_opts)) {
|
||||||
ret = -ENOENT;
|
ret = -ENOENT;
|
||||||
@ -664,8 +666,7 @@ static void bcachefs_fuse_symlink(fuse_req_t req, const char *link,
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
struct fuse_align_io align;
|
struct fuse_align_io align = align_io(c, link_len + 1, 0);
|
||||||
align_io(&align, c, link_len + 1, 0);
|
|
||||||
|
|
||||||
void *aligned_buf = aligned_alloc(PAGE_SIZE, align.size);
|
void *aligned_buf = aligned_alloc(PAGE_SIZE, align.size);
|
||||||
memset(aligned_buf, 0, align.size);
|
memset(aligned_buf, 0, align.size);
|
||||||
@ -706,8 +707,7 @@ static void bcachefs_fuse_readlink(fuse_req_t req, fuse_ino_t inum)
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
struct fuse_align_io align;
|
struct fuse_align_io align = align_io(c, bi.bi_size, 0);
|
||||||
align_io(&align, c, bi.bi_size, 0);
|
|
||||||
|
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
buf = aligned_alloc(PAGE_SIZE, align.size);
|
buf = aligned_alloc(PAGE_SIZE, align.size);
|
||||||
|
Loading…
Reference in New Issue
Block a user