]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Factor alignment logic out of bcachefs_fuse_read.
authorJustin Husted <sigstop@gmail.com>
Tue, 8 Oct 2019 04:21:18 +0000 (21:21 -0700)
committerKent Overstreet <kent.overstreet@gmail.com>
Fri, 18 Oct 2019 20:23:39 +0000 (16:23 -0400)
cmd_fusemount.c

index 059583c80ce313d57d766381d4ff99da7c054cf9..d4f1fbc92c64a88bd2d0d627510cccbd534b8288 100644 (file)
@@ -377,6 +377,27 @@ static void bcachefs_fuse_read_endio(struct bio *bio)
        closure_put(bio->bi_private);
 }
 
+struct fuse_align_io {
+       off_t           start;
+       unsigned        offset;
+       off_t           end;
+       size_t          size;
+};
+
+/* Handle unaligned start and end */
+/* TODO: align to block_bytes, sector size, or page size? */
+static void align_io(struct fuse_align_io *align, const struct bch_fs *c,
+                    size_t size, off_t offset)
+{
+       BUG_ON(offset < 0);
+
+       align->start = round_down(offset, block_bytes(c));
+       align->offset = offset - align->start;
+
+       align->end = round_up(offset + size, block_bytes(c));
+       align->size = align->end - align->start;
+}
+
 static int read_aligned(struct bch_fs *c, fuse_ino_t inum, size_t aligned_size,
                        off_t aligned_offset, void *buf)
 {
@@ -412,26 +433,20 @@ static void bcachefs_fuse_read(fuse_req_t req, fuse_ino_t inum,
                               struct fuse_file_info *fi)
 {
        struct bch_fs *c = fuse_req_userdata(req);
+       struct fuse_align_io align;
 
-       /* Handle unaligned start and end */
-       /* TODO: align to block_bytes, sector size, or page size? */
-       BUG_ON(offset < 0);
-       off_t aligned_start = round_down(offset, block_bytes(c));
-       unsigned aligned_offset = offset - aligned_start;
-
-       off_t aligned_end = round_up(offset + size, block_bytes(c));
-       size_t aligned_size = aligned_end - aligned_start;
+       align_io(&align, c, size, offset);
 
-       void *buf = aligned_alloc(PAGE_SIZE, aligned_size);
+       void *buf = aligned_alloc(PAGE_SIZE, align.size);
        if (!buf) {
                fuse_reply_err(req, ENOMEM);
                return;
        }
 
-       int ret = read_aligned(c, inum, aligned_size, aligned_start, buf);
+       int ret = read_aligned(c, inum, align.size, align.start, buf);
 
        if (likely(!ret))
-               fuse_reply_buf(req, buf + aligned_offset, size);
+               fuse_reply_buf(req, buf + align.offset, size);
        else
                fuse_reply_err(req, -ret);