|
| 1 | +From 37b164bedccd9c5abb0ba8ffbceac405ac331569 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Alessio Balsini <balsini@google.com> |
| 3 | +Date: Wed, 1 Jul 2020 14:14:28 +0100 |
| 4 | +Subject: [PATCH 1/5] DO NOT MERGE Enable passthrough mode for read/write |
| 5 | + operations |
| 6 | + |
| 7 | +Add support for filesystem passthrough read/write of files. |
| 8 | + |
| 9 | +When the FUSE_PASSTHROUGH capability is enabled, the FUSE daemon may |
| 10 | +decide while handling the "open" or "create" operation, if the given |
| 11 | +file can be accessed by that process in "passthrough" mode, meaning that |
| 12 | +all the further read and write operations would be forwarded by the |
| 13 | +kernel directly to the lower filesystem rather than to the FUSE daemon. |
| 14 | +All requests that aren't read or write are still handled by the |
| 15 | +userspace code. |
| 16 | + |
| 17 | +This allows for an improved performance on reads and writes, especially |
| 18 | +in the case of reads at random offsets, for which no (readahead) |
| 19 | +caching mechanism would help, reducing the performance gap between FUSE |
| 20 | +and native filesystem access. |
| 21 | + |
| 22 | +Extend also the passthrough_hp example with the new passthrough feature. |
| 23 | + |
| 24 | +Bug: 174548608 |
| 25 | +Test: atest ScopedStorageTest |
| 26 | +Signed-off-by: Alessio Balsini <balsini@android.com> |
| 27 | +Change-Id: I38aff0cf7198b7cd92eccc97547d47f4e1132b00 |
| 28 | +--- |
| 29 | + include/fuse_common.h | 17 +++++++++++++++++ |
| 30 | + include/fuse_kernel.h | 13 +++++++++++-- |
| 31 | + include/fuse_lowlevel.h | 2 ++ |
| 32 | + lib/fuse_lowlevel.c | 19 +++++++++++++++++++ |
| 33 | + lib/fuse_versionscript | 1 + |
| 34 | + 5 files changed, 50 insertions(+), 2 deletions(-) |
| 35 | + |
| 36 | +diff --git a/include/fuse_common.h b/include/fuse_common.h |
| 37 | +index 2d686b2..7ac28d7 100644 |
| 38 | +--- a/include/fuse_common.h |
| 39 | ++++ b/include/fuse_common.h |
| 40 | +@@ -92,6 +92,11 @@ struct fuse_file_info { |
| 41 | + * same file handle. */ |
| 42 | + uint64_t fh; |
| 43 | + |
| 44 | ++ /** Passthrough file handle id. May be filled in by filesystem in |
| 45 | ++ * create and open. It is used to create a passthrough connection |
| 46 | ++ * between FUSE file and lower file system file. */ |
| 47 | ++ uint32_t passthrough_fh; |
| 48 | ++ |
| 49 | + /** Lock owner id. Available in locking operations and flush */ |
| 50 | + uint64_t lock_owner; |
| 51 | + |
| 52 | +@@ -358,6 +363,18 @@ struct fuse_loop_config { |
| 53 | + */ |
| 54 | + #define FUSE_CAP_NO_OPENDIR_SUPPORT (1 << 24) |
| 55 | + |
| 56 | ++/** |
| 57 | ++ * Indicates support for passthrough mode access for read/write operations. |
| 58 | ++ * |
| 59 | ++ * If this flag is set in the `capable` field of the `fuse_conn_info` |
| 60 | ++ * structure, then the FUSE kernel module supports redirecting read/write |
| 61 | ++ * operations to the lower file system instead of letting them to be handled |
| 62 | ++ * by the FUSE daemon. |
| 63 | ++ * |
| 64 | ++ * This feature is disabled by default. |
| 65 | ++ */ |
| 66 | ++#define FUSE_CAP_PASSTHROUGH (1 << 31) |
| 67 | ++ |
| 68 | + /** |
| 69 | + * Ioctl flags |
| 70 | + * |
| 71 | +diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h |
| 72 | +index 8a45f42..8bd7f0d 100644 |
| 73 | +--- a/include/fuse_kernel.h |
| 74 | ++++ b/include/fuse_kernel.h |
| 75 | +@@ -301,6 +301,7 @@ struct fuse_file_lock { |
| 76 | + #define FUSE_CACHE_SYMLINKS (1 << 23) |
| 77 | + #define FUSE_NO_OPENDIR_SUPPORT (1 << 24) |
| 78 | + #define FUSE_EXPLICIT_INVAL_DATA (1 << 25) |
| 79 | ++#define FUSE_PASSTHROUGH (1 << 31) |
| 80 | + |
| 81 | + /** |
| 82 | + * CUSE INIT request/reply flags |
| 83 | +@@ -547,7 +548,7 @@ struct fuse_create_in { |
| 84 | + struct fuse_open_out { |
| 85 | + uint64_t fh; |
| 86 | + uint32_t open_flags; |
| 87 | +- uint32_t padding; |
| 88 | ++ uint32_t passthrough_fh; |
| 89 | + }; |
| 90 | + |
| 91 | + struct fuse_release_in { |
| 92 | +@@ -574,6 +575,13 @@ struct fuse_read_in { |
| 93 | + uint32_t padding; |
| 94 | + }; |
| 95 | + |
| 96 | ++struct fuse_passthrough_out { |
| 97 | ++ uint32_t fd; |
| 98 | ++ /* For future implementation */ |
| 99 | ++ uint32_t len; |
| 100 | ++ void * vec; |
| 101 | ++}; |
| 102 | ++ |
| 103 | + #define FUSE_COMPAT_WRITE_IN_SIZE 24 |
| 104 | + |
| 105 | + struct fuse_write_in { |
| 106 | +@@ -825,7 +833,8 @@ struct fuse_notify_retrieve_in { |
| 107 | + }; |
| 108 | + |
| 109 | + /* Device ioctls: */ |
| 110 | +-#define FUSE_DEV_IOC_CLONE _IOR(229, 0, uint32_t) |
| 111 | ++#define FUSE_DEV_IOC_CLONE _IOR(229, 0, uint32_t) |
| 112 | ++#define FUSE_DEV_IOC_PASSTHROUGH_OPEN _IOW(229, 1, struct fuse_passthrough_out) |
| 113 | + |
| 114 | + struct fuse_lseek_in { |
| 115 | + uint64_t fh; |
| 116 | +diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h |
| 117 | +index e81c282..e916112 100644 |
| 118 | +--- a/include/fuse_lowlevel.h |
| 119 | ++++ b/include/fuse_lowlevel.h |
| 120 | +@@ -1349,6 +1349,8 @@ int fuse_reply_attr(fuse_req_t req, const struct stat *attr, |
| 121 | + */ |
| 122 | + int fuse_reply_readlink(fuse_req_t req, const char *link); |
| 123 | + |
| 124 | ++int fuse_passthrough_enable(fuse_req_t req, unsigned int fd); |
| 125 | ++ |
| 126 | + /** |
| 127 | + * Reply with the canonical path for inotify |
| 128 | + * |
| 129 | +diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c |
| 130 | +index fc76b7c..c7efc3d 100644 |
| 131 | +--- a/lib/fuse_lowlevel.c |
| 132 | ++++ b/lib/fuse_lowlevel.c |
| 133 | +@@ -27,6 +27,7 @@ |
| 134 | + #include <errno.h> |
| 135 | + #include <assert.h> |
| 136 | + #include <sys/file.h> |
| 137 | ++#include <sys/ioctl.h> |
| 138 | + |
| 139 | + #ifndef F_LINUX_SPECIFIC_BASE |
| 140 | + #define F_LINUX_SPECIFIC_BASE 1024 |
| 141 | +@@ -388,6 +389,7 @@ static void fill_open(struct fuse_open_out *arg, |
| 142 | + const struct fuse_file_info *f) |
| 143 | + { |
| 144 | + arg->fh = f->fh; |
| 145 | ++ arg->passthrough_fh = f->passthrough_fh; |
| 146 | + if (f->direct_io) |
| 147 | + arg->open_flags |= FOPEN_DIRECT_IO; |
| 148 | + if (f->keep_cache) |
| 149 | +@@ -457,6 +459,19 @@ int fuse_reply_canonical_path(fuse_req_t req, const char *path) |
| 150 | + return send_reply_ok(req, path, strlen(path) + 1); |
| 151 | + } |
| 152 | + |
| 153 | ++int fuse_passthrough_enable(fuse_req_t req, unsigned int fd) { |
| 154 | ++ struct fuse_passthrough_out out = {}; |
| 155 | ++ int ret; |
| 156 | ++ |
| 157 | ++ out.fd = fd; |
| 158 | ++ |
| 159 | ++ ret = ioctl(req->se->fd, FUSE_DEV_IOC_PASSTHROUGH_OPEN, &out); |
| 160 | ++ if (ret <= 0) |
| 161 | ++ fuse_log(FUSE_LOG_ERR, "fuse: passthrough_enable: %s\n", strerror(errno)); |
| 162 | ++ |
| 163 | ++ return ret; |
| 164 | ++} |
| 165 | ++ |
| 166 | + int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *f) |
| 167 | + { |
| 168 | + struct fuse_open_out arg; |
| 169 | +@@ -1990,6 +2005,8 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) |
| 170 | + bufsize = max_bufsize; |
| 171 | + } |
| 172 | + } |
| 173 | ++ if (arg->flags & FUSE_PASSTHROUGH) |
| 174 | ++ se->conn.capable |= FUSE_PASSTHROUGH; |
| 175 | + } else { |
| 176 | + se->conn.max_readahead = 0; |
| 177 | + } |
| 178 | +@@ -2102,6 +2119,8 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) |
| 179 | + outarg.flags |= FUSE_WRITEBACK_CACHE; |
| 180 | + if (se->conn.want & FUSE_CAP_POSIX_ACL) |
| 181 | + outarg.flags |= FUSE_POSIX_ACL; |
| 182 | ++ if (se->conn.want & FUSE_CAP_PASSTHROUGH) |
| 183 | ++ outarg.flags |= FUSE_PASSTHROUGH; |
| 184 | + outarg.max_readahead = se->conn.max_readahead; |
| 185 | + outarg.max_write = se->conn.max_write; |
| 186 | + if (se->conn.proto_minor >= 13) { |
| 187 | +diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript |
| 188 | +index 4c075a3..b01699a 100644 |
| 189 | +--- a/lib/fuse_versionscript |
| 190 | ++++ b/lib/fuse_versionscript |
| 191 | +@@ -163,6 +163,7 @@ FUSE_3.7 { |
| 192 | + global: |
| 193 | + fuse_set_log_func; |
| 194 | + fuse_log; |
| 195 | ++ fuse_passthrough_enable; |
| 196 | + fuse_reply_canonical_path; |
| 197 | + } FUSE_3.3; |
| 198 | + |
| 199 | +-- |
| 200 | +2.48.1 |
| 201 | + |
0 commit comments