.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* -*- mode: c; c-basic-offset: 8; -*- |
---|
2 | 3 | * vim: noexpandtab sw=8 ts=8 sts=0: |
---|
3 | 4 | * |
---|
.. | .. |
---|
9 | 10 | * which was a template for the fs side of this module. |
---|
10 | 11 | * |
---|
11 | 12 | * Copyright (C) 2003, 2004 Oracle. All rights reserved. |
---|
12 | | - * |
---|
13 | | - * This program is free software; you can redistribute it and/or |
---|
14 | | - * modify it under the terms of the GNU General Public |
---|
15 | | - * License as published by the Free Software Foundation; either |
---|
16 | | - * version 2 of the License, or (at your option) any later version. |
---|
17 | | - * |
---|
18 | | - * This program is distributed in the hope that it will be useful, |
---|
19 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
21 | | - * General Public License for more details. |
---|
22 | | - * |
---|
23 | | - * You should have received a copy of the GNU General Public |
---|
24 | | - * License along with this program; if not, write to the |
---|
25 | | - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
26 | | - * Boston, MA 021110-1307, USA. |
---|
27 | 13 | */ |
---|
28 | 14 | |
---|
29 | 15 | /* Simple VFS hooks based on: */ |
---|
.. | .. |
---|
47 | 33 | |
---|
48 | 34 | #include <linux/uaccess.h> |
---|
49 | 35 | |
---|
50 | | -#include "stackglue.h" |
---|
| 36 | +#include "../stackglue.h" |
---|
51 | 37 | #include "userdlm.h" |
---|
52 | 38 | |
---|
53 | 39 | #define MLOG_MASK_PREFIX ML_DLMFS |
---|
54 | | -#include "cluster/masklog.h" |
---|
| 40 | +#include "../cluster/masklog.h" |
---|
55 | 41 | |
---|
56 | 42 | |
---|
57 | 43 | static const struct super_operations dlmfs_ops; |
---|
.. | .. |
---|
179 | 165 | static int dlmfs_file_release(struct inode *inode, |
---|
180 | 166 | struct file *file) |
---|
181 | 167 | { |
---|
182 | | - int level, status; |
---|
| 168 | + int level; |
---|
183 | 169 | struct dlmfs_inode_private *ip = DLMFS_I(inode); |
---|
184 | 170 | struct dlmfs_filp_private *fp = file->private_data; |
---|
185 | 171 | |
---|
.. | .. |
---|
188 | 174 | |
---|
189 | 175 | mlog(0, "close called on inode %lu\n", inode->i_ino); |
---|
190 | 176 | |
---|
191 | | - status = 0; |
---|
192 | 177 | if (fp) { |
---|
193 | 178 | level = fp->fp_lock_level; |
---|
194 | 179 | if (level != DLM_LOCK_IV) |
---|
.. | .. |
---|
236 | 221 | return event; |
---|
237 | 222 | } |
---|
238 | 223 | |
---|
239 | | -static ssize_t dlmfs_file_read(struct file *filp, |
---|
| 224 | +static ssize_t dlmfs_file_read(struct file *file, |
---|
240 | 225 | char __user *buf, |
---|
241 | 226 | size_t count, |
---|
242 | 227 | loff_t *ppos) |
---|
243 | 228 | { |
---|
244 | | - int bytes_left; |
---|
245 | | - ssize_t readlen, got; |
---|
246 | | - char *lvb_buf; |
---|
247 | | - struct inode *inode = file_inode(filp); |
---|
| 229 | + char lvb[DLM_LVB_LEN]; |
---|
248 | 230 | |
---|
249 | | - mlog(0, "inode %lu, count = %zu, *ppos = %llu\n", |
---|
250 | | - inode->i_ino, count, *ppos); |
---|
251 | | - |
---|
252 | | - if (*ppos >= i_size_read(inode)) |
---|
| 231 | + if (!user_dlm_read_lvb(file_inode(file), lvb)) |
---|
253 | 232 | return 0; |
---|
254 | 233 | |
---|
255 | | - if (!count) |
---|
256 | | - return 0; |
---|
257 | | - |
---|
258 | | - if (!access_ok(VERIFY_WRITE, buf, count)) |
---|
259 | | - return -EFAULT; |
---|
260 | | - |
---|
261 | | - /* don't read past the lvb */ |
---|
262 | | - if ((count + *ppos) > i_size_read(inode)) |
---|
263 | | - readlen = i_size_read(inode) - *ppos; |
---|
264 | | - else |
---|
265 | | - readlen = count; |
---|
266 | | - |
---|
267 | | - lvb_buf = kmalloc(readlen, GFP_NOFS); |
---|
268 | | - if (!lvb_buf) |
---|
269 | | - return -ENOMEM; |
---|
270 | | - |
---|
271 | | - got = user_dlm_read_lvb(inode, lvb_buf, readlen); |
---|
272 | | - if (got) { |
---|
273 | | - BUG_ON(got != readlen); |
---|
274 | | - bytes_left = __copy_to_user(buf, lvb_buf, readlen); |
---|
275 | | - readlen -= bytes_left; |
---|
276 | | - } else |
---|
277 | | - readlen = 0; |
---|
278 | | - |
---|
279 | | - kfree(lvb_buf); |
---|
280 | | - |
---|
281 | | - *ppos = *ppos + readlen; |
---|
282 | | - |
---|
283 | | - mlog(0, "read %zd bytes\n", readlen); |
---|
284 | | - return readlen; |
---|
| 234 | + return simple_read_from_buffer(buf, count, ppos, lvb, sizeof(lvb)); |
---|
285 | 235 | } |
---|
286 | 236 | |
---|
287 | 237 | static ssize_t dlmfs_file_write(struct file *filp, |
---|
.. | .. |
---|
289 | 239 | size_t count, |
---|
290 | 240 | loff_t *ppos) |
---|
291 | 241 | { |
---|
| 242 | + char lvb_buf[DLM_LVB_LEN]; |
---|
292 | 243 | int bytes_left; |
---|
293 | | - ssize_t writelen; |
---|
294 | | - char *lvb_buf; |
---|
295 | 244 | struct inode *inode = file_inode(filp); |
---|
296 | 245 | |
---|
297 | 246 | mlog(0, "inode %lu, count = %zu, *ppos = %llu\n", |
---|
298 | 247 | inode->i_ino, count, *ppos); |
---|
299 | 248 | |
---|
300 | | - if (*ppos >= i_size_read(inode)) |
---|
| 249 | + if (*ppos >= DLM_LVB_LEN) |
---|
301 | 250 | return -ENOSPC; |
---|
| 251 | + |
---|
| 252 | + /* don't write past the lvb */ |
---|
| 253 | + if (count > DLM_LVB_LEN - *ppos) |
---|
| 254 | + count = DLM_LVB_LEN - *ppos; |
---|
302 | 255 | |
---|
303 | 256 | if (!count) |
---|
304 | 257 | return 0; |
---|
305 | 258 | |
---|
306 | | - if (!access_ok(VERIFY_READ, buf, count)) |
---|
307 | | - return -EFAULT; |
---|
| 259 | + bytes_left = copy_from_user(lvb_buf, buf, count); |
---|
| 260 | + count -= bytes_left; |
---|
| 261 | + if (count) |
---|
| 262 | + user_dlm_write_lvb(inode, lvb_buf, count); |
---|
308 | 263 | |
---|
309 | | - /* don't write past the lvb */ |
---|
310 | | - if ((count + *ppos) > i_size_read(inode)) |
---|
311 | | - writelen = i_size_read(inode) - *ppos; |
---|
312 | | - else |
---|
313 | | - writelen = count - *ppos; |
---|
314 | | - |
---|
315 | | - lvb_buf = kmalloc(writelen, GFP_NOFS); |
---|
316 | | - if (!lvb_buf) |
---|
317 | | - return -ENOMEM; |
---|
318 | | - |
---|
319 | | - bytes_left = copy_from_user(lvb_buf, buf, writelen); |
---|
320 | | - writelen -= bytes_left; |
---|
321 | | - if (writelen) |
---|
322 | | - user_dlm_write_lvb(inode, lvb_buf, writelen); |
---|
323 | | - |
---|
324 | | - kfree(lvb_buf); |
---|
325 | | - |
---|
326 | | - *ppos = *ppos + writelen; |
---|
327 | | - mlog(0, "wrote %zd bytes\n", writelen); |
---|
328 | | - return writelen; |
---|
| 264 | + *ppos = *ppos + count; |
---|
| 265 | + mlog(0, "wrote %zu bytes\n", count); |
---|
| 266 | + return count; |
---|
329 | 267 | } |
---|
330 | 268 | |
---|
331 | 269 | static void dlmfs_init_once(void *foo) |
---|
.. | .. |
---|
350 | 288 | return &ip->ip_vfs_inode; |
---|
351 | 289 | } |
---|
352 | 290 | |
---|
353 | | -static void dlmfs_i_callback(struct rcu_head *head) |
---|
| 291 | +static void dlmfs_free_inode(struct inode *inode) |
---|
354 | 292 | { |
---|
355 | | - struct inode *inode = container_of(head, struct inode, i_rcu); |
---|
356 | 293 | kmem_cache_free(dlmfs_inode_cache, DLMFS_I(inode)); |
---|
357 | | -} |
---|
358 | | - |
---|
359 | | -static void dlmfs_destroy_inode(struct inode *inode) |
---|
360 | | -{ |
---|
361 | | - call_rcu(&inode->i_rcu, dlmfs_i_callback); |
---|
362 | 294 | } |
---|
363 | 295 | |
---|
364 | 296 | static void dlmfs_evict_inode(struct inode *inode) |
---|
.. | .. |
---|
606 | 538 | static const struct super_operations dlmfs_ops = { |
---|
607 | 539 | .statfs = simple_statfs, |
---|
608 | 540 | .alloc_inode = dlmfs_alloc_inode, |
---|
609 | | - .destroy_inode = dlmfs_destroy_inode, |
---|
| 541 | + .free_inode = dlmfs_free_inode, |
---|
610 | 542 | .evict_inode = dlmfs_evict_inode, |
---|
611 | 543 | .drop_inode = generic_delete_inode, |
---|
612 | 544 | }; |
---|
.. | .. |
---|
683 | 615 | |
---|
684 | 616 | MODULE_AUTHOR("Oracle"); |
---|
685 | 617 | MODULE_LICENSE("GPL"); |
---|
| 618 | +MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY); |
---|
686 | 619 | MODULE_DESCRIPTION("OCFS2 DLM-Filesystem"); |
---|
687 | 620 | |
---|
688 | 621 | module_init(init_dlmfs_fs) |
---|