hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/ocfs2/dlmfs/dlmfs.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* -*- mode: c; c-basic-offset: 8; -*-
23 * vim: noexpandtab sw=8 ts=8 sts=0:
34 *
....@@ -9,21 +10,6 @@
910 * which was a template for the fs side of this module.
1011 *
1112 * 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.
2713 */
2814
2915 /* Simple VFS hooks based on: */
....@@ -47,11 +33,11 @@
4733
4834 #include <linux/uaccess.h>
4935
50
-#include "stackglue.h"
36
+#include "../stackglue.h"
5137 #include "userdlm.h"
5238
5339 #define MLOG_MASK_PREFIX ML_DLMFS
54
-#include "cluster/masklog.h"
40
+#include "../cluster/masklog.h"
5541
5642
5743 static const struct super_operations dlmfs_ops;
....@@ -179,7 +165,7 @@
179165 static int dlmfs_file_release(struct inode *inode,
180166 struct file *file)
181167 {
182
- int level, status;
168
+ int level;
183169 struct dlmfs_inode_private *ip = DLMFS_I(inode);
184170 struct dlmfs_filp_private *fp = file->private_data;
185171
....@@ -188,7 +174,6 @@
188174
189175 mlog(0, "close called on inode %lu\n", inode->i_ino);
190176
191
- status = 0;
192177 if (fp) {
193178 level = fp->fp_lock_level;
194179 if (level != DLM_LOCK_IV)
....@@ -236,52 +221,17 @@
236221 return event;
237222 }
238223
239
-static ssize_t dlmfs_file_read(struct file *filp,
224
+static ssize_t dlmfs_file_read(struct file *file,
240225 char __user *buf,
241226 size_t count,
242227 loff_t *ppos)
243228 {
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];
248230
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))
253232 return 0;
254233
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));
285235 }
286236
287237 static ssize_t dlmfs_file_write(struct file *filp,
....@@ -289,43 +239,31 @@
289239 size_t count,
290240 loff_t *ppos)
291241 {
242
+ char lvb_buf[DLM_LVB_LEN];
292243 int bytes_left;
293
- ssize_t writelen;
294
- char *lvb_buf;
295244 struct inode *inode = file_inode(filp);
296245
297246 mlog(0, "inode %lu, count = %zu, *ppos = %llu\n",
298247 inode->i_ino, count, *ppos);
299248
300
- if (*ppos >= i_size_read(inode))
249
+ if (*ppos >= DLM_LVB_LEN)
301250 return -ENOSPC;
251
+
252
+ /* don't write past the lvb */
253
+ if (count > DLM_LVB_LEN - *ppos)
254
+ count = DLM_LVB_LEN - *ppos;
302255
303256 if (!count)
304257 return 0;
305258
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);
308263
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;
329267 }
330268
331269 static void dlmfs_init_once(void *foo)
....@@ -350,15 +288,9 @@
350288 return &ip->ip_vfs_inode;
351289 }
352290
353
-static void dlmfs_i_callback(struct rcu_head *head)
291
+static void dlmfs_free_inode(struct inode *inode)
354292 {
355
- struct inode *inode = container_of(head, struct inode, i_rcu);
356293 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);
362294 }
363295
364296 static void dlmfs_evict_inode(struct inode *inode)
....@@ -606,7 +538,7 @@
606538 static const struct super_operations dlmfs_ops = {
607539 .statfs = simple_statfs,
608540 .alloc_inode = dlmfs_alloc_inode,
609
- .destroy_inode = dlmfs_destroy_inode,
541
+ .free_inode = dlmfs_free_inode,
610542 .evict_inode = dlmfs_evict_inode,
611543 .drop_inode = generic_delete_inode,
612544 };
....@@ -683,6 +615,7 @@
683615
684616 MODULE_AUTHOR("Oracle");
685617 MODULE_LICENSE("GPL");
618
+MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
686619 MODULE_DESCRIPTION("OCFS2 DLM-Filesystem");
687620
688621 module_init(init_dlmfs_fs)