Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kernel: relay: remove relay_file_splice_read dead code, doesn't work

Documentation/filesystems/relay.rst says to use
return debugfs_create_file(filename, mode, parent, buf,
&relay_file_operations);
and this is the only way relay_file_operations is used.

Thus: debugfs_create_file(&relay_file_operations)
-> __debugfs_create_file(&debugfs_full_proxy_file_operations,
&relay_file_operations)
-> dentry{inode: {i_fop: &debugfs_full_proxy_file_operations},
d_fsdata: &relay_file_operations
| DEBUGFS_FSDATA_IS_REAL_FOPS_BIT}

debugfs_full_proxy_file_operations.open is full_proxy_open, which extracts
the &relay_file_operations from the dentry, and allocates via
__full_proxy_fops_init() new fops, with trivial wrappers around release,
llseek, read, write, poll, and unlocked_ioctl, then replaces the fops on
the opened file therewith.

Naturally, all thusly-created debugfs files have .splice_read = NULL.
This was introduced in commit 49d200deaa68 ("debugfs: prevent access to
removed files' private data") from 2016-03-22.

AFAICT, relay_file_operations is the only struct file_operations used for
debugfs which defines a .splice_read callback. Hooking it up with

> diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
> index 5063434be0fc..952fcf5b2afa 100644
> --- a/fs/debugfs/file.c
> +++ b/fs/debugfs/file.c
> @@ -328,6 +328,11 @@ FULL_PROXY_FUNC(write, ssize_t, filp,
> loff_t *ppos),
> ARGS(filp, buf, size, ppos));
>
> +FULL_PROXY_FUNC(splice_read, long, in,
> + PROTO(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe,
> + size_t len, unsigned int flags),
> + ARGS(in, ppos, pipe, len, flags));
> +
> FULL_PROXY_FUNC(unlocked_ioctl, long, filp,
> PROTO(struct file *filp, unsigned int cmd, unsigned long arg),
> ARGS(filp, cmd, arg));
> @@ -382,6 +387,8 @@ static void __full_proxy_fops_init(struct file_operations *proxy_fops,
> proxy_fops->write = full_proxy_write;
> if (real_fops->poll)
> proxy_fops->poll = full_proxy_poll;
> + if (real_fops->splice_read)
> + proxy_fops->splice_read = full_proxy_splice_read;
> if (real_fops->unlocked_ioctl)
> proxy_fops->unlocked_ioctl = full_proxy_unlocked_ioctl;
> }

shows it just doesn't work, and splicing always instantly returns empty
(subsequent reads actually return the contents).

No-one noticed it became dead code in 2016, who knows if it worked back
then. Clearly no-one cares; just delete it.

Link: https://lkml.kernel.org/r/dtexwpw6zcdx7dkx3xj5gyjp5syxmyretdcbcdtvrnukd4vvuh@tarta.nabijaczleweli.xyz
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Li kunyu <kunyu@nfschina.com>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Rafael J. Wysocki <rafael@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Zhang Zhengming <zhang.zhengming@h3c.com>
Cc: Zhao Lei <zhao_lei1@hoperun.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Ahelenia Ziemiańska and committed by
Andrew Morton
d3916156 50bc9832

-162
-162
kernel/relay.c
··· 1073 1073 return written; 1074 1074 } 1075 1075 1076 - static void relay_consume_bytes(struct rchan_buf *rbuf, int bytes_consumed) 1077 - { 1078 - rbuf->bytes_consumed += bytes_consumed; 1079 - 1080 - if (rbuf->bytes_consumed >= rbuf->chan->subbuf_size) { 1081 - relay_subbufs_consumed(rbuf->chan, rbuf->cpu, 1); 1082 - rbuf->bytes_consumed %= rbuf->chan->subbuf_size; 1083 - } 1084 - } 1085 - 1086 - static void relay_pipe_buf_release(struct pipe_inode_info *pipe, 1087 - struct pipe_buffer *buf) 1088 - { 1089 - struct rchan_buf *rbuf; 1090 - 1091 - rbuf = (struct rchan_buf *)page_private(buf->page); 1092 - relay_consume_bytes(rbuf, buf->private); 1093 - } 1094 - 1095 - static const struct pipe_buf_operations relay_pipe_buf_ops = { 1096 - .release = relay_pipe_buf_release, 1097 - .try_steal = generic_pipe_buf_try_steal, 1098 - .get = generic_pipe_buf_get, 1099 - }; 1100 - 1101 - static void relay_page_release(struct splice_pipe_desc *spd, unsigned int i) 1102 - { 1103 - } 1104 - 1105 - /* 1106 - * subbuf_splice_actor - splice up to one subbuf's worth of data 1107 - */ 1108 - static ssize_t subbuf_splice_actor(struct file *in, 1109 - loff_t *ppos, 1110 - struct pipe_inode_info *pipe, 1111 - size_t len, 1112 - unsigned int flags, 1113 - int *nonpad_ret) 1114 - { 1115 - unsigned int pidx, poff, total_len, subbuf_pages, nr_pages; 1116 - struct rchan_buf *rbuf = in->private_data; 1117 - unsigned int subbuf_size = rbuf->chan->subbuf_size; 1118 - uint64_t pos = (uint64_t) *ppos; 1119 - uint32_t alloc_size = (uint32_t) rbuf->chan->alloc_size; 1120 - size_t read_start = (size_t) do_div(pos, alloc_size); 1121 - size_t read_subbuf = read_start / subbuf_size; 1122 - size_t padding = rbuf->padding[read_subbuf]; 1123 - size_t nonpad_end = read_subbuf * subbuf_size + subbuf_size - padding; 1124 - struct page *pages[PIPE_DEF_BUFFERS]; 1125 - struct partial_page partial[PIPE_DEF_BUFFERS]; 1126 - struct splice_pipe_desc spd = { 1127 - .pages = pages, 1128 - .nr_pages = 0, 1129 - .nr_pages_max = PIPE_DEF_BUFFERS, 1130 - .partial = partial, 1131 - .ops = &relay_pipe_buf_ops, 1132 - .spd_release = relay_page_release, 1133 - }; 1134 - ssize_t ret; 1135 - 1136 - if (rbuf->subbufs_produced == rbuf->subbufs_consumed) 1137 - return 0; 1138 - if (splice_grow_spd(pipe, &spd)) 1139 - return -ENOMEM; 1140 - 1141 - /* 1142 - * Adjust read len, if longer than what is available 1143 - */ 1144 - if (len > (subbuf_size - read_start % subbuf_size)) 1145 - len = subbuf_size - read_start % subbuf_size; 1146 - 1147 - subbuf_pages = rbuf->chan->alloc_size >> PAGE_SHIFT; 1148 - pidx = (read_start / PAGE_SIZE) % subbuf_pages; 1149 - poff = read_start & ~PAGE_MASK; 1150 - nr_pages = min_t(unsigned int, subbuf_pages, spd.nr_pages_max); 1151 - 1152 - for (total_len = 0; spd.nr_pages < nr_pages; spd.nr_pages++) { 1153 - unsigned int this_len, this_end, private; 1154 - unsigned int cur_pos = read_start + total_len; 1155 - 1156 - if (!len) 1157 - break; 1158 - 1159 - this_len = min_t(unsigned long, len, PAGE_SIZE - poff); 1160 - private = this_len; 1161 - 1162 - spd.pages[spd.nr_pages] = rbuf->page_array[pidx]; 1163 - spd.partial[spd.nr_pages].offset = poff; 1164 - 1165 - this_end = cur_pos + this_len; 1166 - if (this_end >= nonpad_end) { 1167 - this_len = nonpad_end - cur_pos; 1168 - private = this_len + padding; 1169 - } 1170 - spd.partial[spd.nr_pages].len = this_len; 1171 - spd.partial[spd.nr_pages].private = private; 1172 - 1173 - len -= this_len; 1174 - total_len += this_len; 1175 - poff = 0; 1176 - pidx = (pidx + 1) % subbuf_pages; 1177 - 1178 - if (this_end >= nonpad_end) { 1179 - spd.nr_pages++; 1180 - break; 1181 - } 1182 - } 1183 - 1184 - ret = 0; 1185 - if (!spd.nr_pages) 1186 - goto out; 1187 - 1188 - ret = *nonpad_ret = splice_to_pipe(pipe, &spd); 1189 - if (ret < 0 || ret < total_len) 1190 - goto out; 1191 - 1192 - if (read_start + ret == nonpad_end) 1193 - ret += padding; 1194 - 1195 - out: 1196 - splice_shrink_spd(&spd); 1197 - return ret; 1198 - } 1199 - 1200 - static ssize_t relay_file_splice_read(struct file *in, 1201 - loff_t *ppos, 1202 - struct pipe_inode_info *pipe, 1203 - size_t len, 1204 - unsigned int flags) 1205 - { 1206 - ssize_t spliced; 1207 - int ret; 1208 - int nonpad_ret = 0; 1209 - 1210 - ret = 0; 1211 - spliced = 0; 1212 - 1213 - while (len && !spliced) { 1214 - ret = subbuf_splice_actor(in, ppos, pipe, len, flags, &nonpad_ret); 1215 - if (ret < 0) 1216 - break; 1217 - else if (!ret) { 1218 - if (flags & SPLICE_F_NONBLOCK) 1219 - ret = -EAGAIN; 1220 - break; 1221 - } 1222 - 1223 - *ppos += ret; 1224 - if (ret > len) 1225 - len = 0; 1226 - else 1227 - len -= ret; 1228 - spliced += nonpad_ret; 1229 - nonpad_ret = 0; 1230 - } 1231 - 1232 - if (spliced) 1233 - return spliced; 1234 - 1235 - return ret; 1236 - } 1237 1076 1238 1077 const struct file_operations relay_file_operations = { 1239 1078 .open = relay_file_open, ··· 1081 1242 .read = relay_file_read, 1082 1243 .llseek = no_llseek, 1083 1244 .release = relay_file_release, 1084 - .splice_read = relay_file_splice_read, 1085 1245 }; 1086 1246 EXPORT_SYMBOL_GPL(relay_file_operations);