blob: 22c1b29c055117ad09880ebcfcbf8a7d4d741d45 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
4 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
5 */
6
7#include <linux/slab.h>
8#include <linux/spinlock.h>
9#include <linux/compat.h>
10#include <linux/completion.h>
11#include <linux/buffer_head.h>
12#include <linux/pagemap.h>
13#include <linux/uio.h>
14#include <linux/blkdev.h>
15#include <linux/mm.h>
16#include <linux/mount.h>
17#include <linux/fs.h>
18#include <linux/gfs2_ondisk.h>
19#include <linux/falloc.h>
20#include <linux/swap.h>
21#include <linux/crc32.h>
22#include <linux/writeback.h>
23#include <linux/uaccess.h>
24#include <linux/dlm.h>
25#include <linux/dlm_plock.h>
26#include <linux/delay.h>
27#include <linux/backing-dev.h>
28
29#include "gfs2.h"
30#include "incore.h"
31#include "bmap.h"
32#include "aops.h"
33#include "dir.h"
34#include "glock.h"
35#include "glops.h"
36#include "inode.h"
37#include "log.h"
38#include "meta_io.h"
39#include "quota.h"
40#include "rgrp.h"
41#include "trans.h"
42#include "util.h"
43
44/**
45 * gfs2_llseek - seek to a location in a file
46 * @file: the file
47 * @offset: the offset
48 * @whence: Where to seek from (SEEK_SET, SEEK_CUR, or SEEK_END)
49 *
50 * SEEK_END requires the glock for the file because it references the
51 * file's size.
52 *
53 * Returns: The new offset, or errno
54 */
55
56static loff_t gfs2_llseek(struct file *file, loff_t offset, int whence)
57{
58 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
59 struct gfs2_holder i_gh;
60 loff_t error;
61
62 switch (whence) {
63 case SEEK_END:
64 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY,
65 &i_gh);
66 if (!error) {
67 error = generic_file_llseek(file, offset, whence);
68 gfs2_glock_dq_uninit(&i_gh);
69 }
70 break;
71
72 case SEEK_DATA:
73 error = gfs2_seek_data(file, offset);
74 break;
75
76 case SEEK_HOLE:
77 error = gfs2_seek_hole(file, offset);
78 break;
79
80 case SEEK_CUR:
81 case SEEK_SET:
82 /*
83 * These don't reference inode->i_size and don't depend on the
84 * block mapping, so we don't need the glock.
85 */
86 error = generic_file_llseek(file, offset, whence);
87 break;
88 default:
89 error = -EINVAL;
90 }
91
92 return error;
93}
94
95/**
96 * gfs2_readdir - Iterator for a directory
97 * @file: The directory to read from
98 * @ctx: What to feed directory entries to
99 *
100 * Returns: errno
101 */
102
103static int gfs2_readdir(struct file *file, struct dir_context *ctx)
104{
105 struct inode *dir = file->f_mapping->host;
106 struct gfs2_inode *dip = GFS2_I(dir);
107 struct gfs2_holder d_gh;
108 int error;
109
110 error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
111 if (error)
112 return error;
113
114 error = gfs2_dir_read(dir, ctx, &file->f_ra);
115
116 gfs2_glock_dq_uninit(&d_gh);
117
118 return error;
119}
120
121/**
122 * fsflag_gfs2flag
123 *
124 * The FS_JOURNAL_DATA_FL flag maps to GFS2_DIF_INHERIT_JDATA for directories,
125 * and to GFS2_DIF_JDATA for non-directories.
126 */
127static struct {
128 u32 fsflag;
129 u32 gfsflag;
130} fsflag_gfs2flag[] = {
131 {FS_SYNC_FL, GFS2_DIF_SYNC},
132 {FS_IMMUTABLE_FL, GFS2_DIF_IMMUTABLE},
133 {FS_APPEND_FL, GFS2_DIF_APPENDONLY},
134 {FS_NOATIME_FL, GFS2_DIF_NOATIME},
135 {FS_INDEX_FL, GFS2_DIF_EXHASH},
136 {FS_TOPDIR_FL, GFS2_DIF_TOPDIR},
137 {FS_JOURNAL_DATA_FL, GFS2_DIF_JDATA | GFS2_DIF_INHERIT_JDATA},
138};
139
140static inline u32 gfs2_gfsflags_to_fsflags(struct inode *inode, u32 gfsflags)
141{
142 int i;
143 u32 fsflags = 0;
144
145 if (S_ISDIR(inode->i_mode))
146 gfsflags &= ~GFS2_DIF_JDATA;
147 else
148 gfsflags &= ~GFS2_DIF_INHERIT_JDATA;
149
150 for (i = 0; i < ARRAY_SIZE(fsflag_gfs2flag); i++)
151 if (gfsflags & fsflag_gfs2flag[i].gfsflag)
152 fsflags |= fsflag_gfs2flag[i].fsflag;
153 return fsflags;
154}
155
156static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
157{
158 struct inode *inode = file_inode(filp);
159 struct gfs2_inode *ip = GFS2_I(inode);
160 struct gfs2_holder gh;
161 int error;
162 u32 fsflags;
163
164 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
165 error = gfs2_glock_nq(&gh);
166 if (error)
167 goto out_uninit;
168
169 fsflags = gfs2_gfsflags_to_fsflags(inode, ip->i_diskflags);
170
171 if (put_user(fsflags, ptr))
172 error = -EFAULT;
173
174 gfs2_glock_dq(&gh);
175out_uninit:
176 gfs2_holder_uninit(&gh);
177 return error;
178}
179
180void gfs2_set_inode_flags(struct inode *inode)
181{
182 struct gfs2_inode *ip = GFS2_I(inode);
183 unsigned int flags = inode->i_flags;
184
185 flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
186 if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
187 flags |= S_NOSEC;
188 if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
189 flags |= S_IMMUTABLE;
190 if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
191 flags |= S_APPEND;
192 if (ip->i_diskflags & GFS2_DIF_NOATIME)
193 flags |= S_NOATIME;
194 if (ip->i_diskflags & GFS2_DIF_SYNC)
195 flags |= S_SYNC;
196 inode->i_flags = flags;
197}
198
199/* Flags that can be set by user space */
200#define GFS2_FLAGS_USER_SET (GFS2_DIF_JDATA| \
201 GFS2_DIF_IMMUTABLE| \
202 GFS2_DIF_APPENDONLY| \
203 GFS2_DIF_NOATIME| \
204 GFS2_DIF_SYNC| \
205 GFS2_DIF_TOPDIR| \
206 GFS2_DIF_INHERIT_JDATA)
207
208/**
209 * do_gfs2_set_flags - set flags on an inode
210 * @filp: file pointer
211 * @reqflags: The flags to set
212 * @mask: Indicates which flags are valid
213 * @fsflags: The FS_* inode flags passed in
214 *
215 */
216static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask,
217 const u32 fsflags)
218{
219 struct inode *inode = file_inode(filp);
220 struct gfs2_inode *ip = GFS2_I(inode);
221 struct gfs2_sbd *sdp = GFS2_SB(inode);
222 struct buffer_head *bh;
223 struct gfs2_holder gh;
224 int error;
225 u32 new_flags, flags, oldflags;
226
227 error = mnt_want_write_file(filp);
228 if (error)
229 return error;
230
231 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
232 if (error)
233 goto out_drop_write;
234
235 oldflags = gfs2_gfsflags_to_fsflags(inode, ip->i_diskflags);
236 error = vfs_ioc_setflags_prepare(inode, oldflags, fsflags);
237 if (error)
238 goto out;
239
240 error = -EACCES;
241 if (!inode_owner_or_capable(inode))
242 goto out;
243
244 error = 0;
245 flags = ip->i_diskflags;
246 new_flags = (flags & ~mask) | (reqflags & mask);
247 if ((new_flags ^ flags) == 0)
248 goto out;
249
250 error = -EPERM;
251 if (IS_IMMUTABLE(inode) && (new_flags & GFS2_DIF_IMMUTABLE))
252 goto out;
253 if (IS_APPEND(inode) && (new_flags & GFS2_DIF_APPENDONLY))
254 goto out;
255 if (((new_flags ^ flags) & GFS2_DIF_IMMUTABLE) &&
256 !capable(CAP_LINUX_IMMUTABLE))
257 goto out;
258 if (!IS_IMMUTABLE(inode)) {
259 error = gfs2_permission(inode, MAY_WRITE);
260 if (error)
261 goto out;
262 }
263 if ((flags ^ new_flags) & GFS2_DIF_JDATA) {
264 if (new_flags & GFS2_DIF_JDATA)
265 gfs2_log_flush(sdp, ip->i_gl,
266 GFS2_LOG_HEAD_FLUSH_NORMAL |
267 GFS2_LFC_SET_FLAGS);
268 error = filemap_fdatawrite(inode->i_mapping);
269 if (error)
270 goto out;
271 error = filemap_fdatawait(inode->i_mapping);
272 if (error)
273 goto out;
274 truncate_inode_pages(inode->i_mapping, 0);
275 if (new_flags & GFS2_DIF_JDATA)
276 gfs2_ordered_del_inode(ip);
277 }
278 error = gfs2_trans_begin(sdp, RES_DINODE, 0);
279 if (error)
280 goto out;
281 error = gfs2_meta_inode_buffer(ip, &bh);
282 if (error)
283 goto out_trans_end;
284 inode->i_ctime = current_time(inode);
285 gfs2_trans_add_meta(ip->i_gl, bh);
286 ip->i_diskflags = new_flags;
287 gfs2_dinode_out(ip, bh->b_data);
288 brelse(bh);
289 gfs2_set_inode_flags(inode);
290 gfs2_set_aops(inode);
291out_trans_end:
292 gfs2_trans_end(sdp);
293out:
294 gfs2_glock_dq_uninit(&gh);
295out_drop_write:
296 mnt_drop_write_file(filp);
297 return error;
298}
299
300static int gfs2_set_flags(struct file *filp, u32 __user *ptr)
301{
302 struct inode *inode = file_inode(filp);
303 u32 fsflags, gfsflags = 0;
304 u32 mask;
305 int i;
306
307 if (get_user(fsflags, ptr))
308 return -EFAULT;
309
310 for (i = 0; i < ARRAY_SIZE(fsflag_gfs2flag); i++) {
311 if (fsflags & fsflag_gfs2flag[i].fsflag) {
312 fsflags &= ~fsflag_gfs2flag[i].fsflag;
313 gfsflags |= fsflag_gfs2flag[i].gfsflag;
314 }
315 }
316 if (fsflags || gfsflags & ~GFS2_FLAGS_USER_SET)
317 return -EINVAL;
318
319 mask = GFS2_FLAGS_USER_SET;
320 if (S_ISDIR(inode->i_mode)) {
321 mask &= ~GFS2_DIF_JDATA;
322 } else {
323 /* The GFS2_DIF_TOPDIR flag is only valid for directories. */
324 if (gfsflags & GFS2_DIF_TOPDIR)
325 return -EINVAL;
326 mask &= ~(GFS2_DIF_TOPDIR | GFS2_DIF_INHERIT_JDATA);
327 }
328
329 return do_gfs2_set_flags(filp, gfsflags, mask, fsflags);
330}
331
332static int gfs2_getlabel(struct file *filp, char __user *label)
333{
334 struct inode *inode = file_inode(filp);
335 struct gfs2_sbd *sdp = GFS2_SB(inode);
336
337 if (copy_to_user(label, sdp->sd_sb.sb_locktable, GFS2_LOCKNAME_LEN))
338 return -EFAULT;
339
340 return 0;
341}
342
343static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
344{
345 switch(cmd) {
346 case FS_IOC_GETFLAGS:
347 return gfs2_get_flags(filp, (u32 __user *)arg);
348 case FS_IOC_SETFLAGS:
349 return gfs2_set_flags(filp, (u32 __user *)arg);
350 case FITRIM:
351 return gfs2_fitrim(filp, (void __user *)arg);
352 case FS_IOC_GETFSLABEL:
353 return gfs2_getlabel(filp, (char __user *)arg);
354 }
355
356 return -ENOTTY;
357}
358
359#ifdef CONFIG_COMPAT
360static long gfs2_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
361{
362 switch(cmd) {
363 /* These are just misnamed, they actually get/put from/to user an int */
364 case FS_IOC32_GETFLAGS:
365 cmd = FS_IOC_GETFLAGS;
366 break;
367 case FS_IOC32_SETFLAGS:
368 cmd = FS_IOC_SETFLAGS;
369 break;
370 /* Keep this list in sync with gfs2_ioctl */
371 case FITRIM:
372 case FS_IOC_GETFSLABEL:
373 break;
374 default:
375 return -ENOIOCTLCMD;
376 }
377
378 return gfs2_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
379}
380#else
381#define gfs2_compat_ioctl NULL
382#endif
383
384/**
385 * gfs2_size_hint - Give a hint to the size of a write request
386 * @filep: The struct file
387 * @offset: The file offset of the write
388 * @size: The length of the write
389 *
390 * When we are about to do a write, this function records the total
391 * write size in order to provide a suitable hint to the lower layers
392 * about how many blocks will be required.
393 *
394 */
395
396static void gfs2_size_hint(struct file *filep, loff_t offset, size_t size)
397{
398 struct inode *inode = file_inode(filep);
399 struct gfs2_sbd *sdp = GFS2_SB(inode);
400 struct gfs2_inode *ip = GFS2_I(inode);
401 size_t blks = (size + sdp->sd_sb.sb_bsize - 1) >> sdp->sd_sb.sb_bsize_shift;
402 int hint = min_t(size_t, INT_MAX, blks);
403
404 if (hint > atomic_read(&ip->i_sizehint))
405 atomic_set(&ip->i_sizehint, hint);
406}
407
408/**
409 * gfs2_allocate_page_backing - Allocate blocks for a write fault
410 * @page: The (locked) page to allocate backing for
411 * @length: Size of the allocation
412 *
413 * We try to allocate all the blocks required for the page in one go. This
414 * might fail for various reasons, so we keep trying until all the blocks to
415 * back this page are allocated. If some of the blocks are already allocated,
416 * that is ok too.
417 */
418static int gfs2_allocate_page_backing(struct page *page, unsigned int length)
419{
420 u64 pos = page_offset(page);
421
422 do {
423 struct iomap iomap = { };
424
425 if (gfs2_iomap_get_alloc(page->mapping->host, pos, length, &iomap))
426 return -EIO;
427
428 if (length < iomap.length)
429 iomap.length = length;
430 length -= iomap.length;
431 pos += iomap.length;
432 } while (length > 0);
433
434 return 0;
435}
436
437/**
438 * gfs2_page_mkwrite - Make a shared, mmap()ed, page writable
439 * @vma: The virtual memory area
440 * @vmf: The virtual memory fault containing the page to become writable
441 *
442 * When the page becomes writable, we need to ensure that we have
443 * blocks allocated on disk to back that page.
444 */
445
446static vm_fault_t gfs2_page_mkwrite(struct vm_fault *vmf)
447{
448 struct page *page = vmf->page;
449 struct inode *inode = file_inode(vmf->vma->vm_file);
450 struct gfs2_inode *ip = GFS2_I(inode);
451 struct gfs2_sbd *sdp = GFS2_SB(inode);
452 struct gfs2_alloc_parms ap = { .aflags = 0, };
453 unsigned long last_index;
454 u64 pos = page_offset(page);
455 unsigned int data_blocks, ind_blocks, rblocks;
456 struct gfs2_holder gh;
457 loff_t size;
458 int ret;
459
460 sb_start_pagefault(inode->i_sb);
461
462 ret = gfs2_rsqa_alloc(ip);
463 if (ret)
464 goto out;
465
466 gfs2_size_hint(vmf->vma->vm_file, pos, PAGE_SIZE);
467
468 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
469 ret = gfs2_glock_nq(&gh);
470 if (ret)
471 goto out_uninit;
472
473 /* Update file times before taking page lock */
474 file_update_time(vmf->vma->vm_file);
475
476 set_bit(GLF_DIRTY, &ip->i_gl->gl_flags);
477 set_bit(GIF_SW_PAGED, &ip->i_flags);
478
479 if (!gfs2_write_alloc_required(ip, pos, PAGE_SIZE)) {
480 lock_page(page);
481 if (!PageUptodate(page) || page->mapping != inode->i_mapping) {
482 ret = -EAGAIN;
483 unlock_page(page);
484 }
485 goto out_unlock;
486 }
487
488 ret = gfs2_rindex_update(sdp);
489 if (ret)
490 goto out_unlock;
491
492 gfs2_write_calc_reserv(ip, PAGE_SIZE, &data_blocks, &ind_blocks);
493 ap.target = data_blocks + ind_blocks;
494 ret = gfs2_quota_lock_check(ip, &ap);
495 if (ret)
496 goto out_unlock;
497 ret = gfs2_inplace_reserve(ip, &ap);
498 if (ret)
499 goto out_quota_unlock;
500
501 rblocks = RES_DINODE + ind_blocks;
502 if (gfs2_is_jdata(ip))
503 rblocks += data_blocks ? data_blocks : 1;
504 if (ind_blocks || data_blocks) {
505 rblocks += RES_STATFS + RES_QUOTA;
506 rblocks += gfs2_rg_blocks(ip, data_blocks + ind_blocks);
507 }
508 ret = gfs2_trans_begin(sdp, rblocks, 0);
509 if (ret)
510 goto out_trans_fail;
511
512 lock_page(page);
513 ret = -EINVAL;
514 size = i_size_read(inode);
515 last_index = (size - 1) >> PAGE_SHIFT;
516 /* Check page index against inode size */
517 if (size == 0 || (page->index > last_index))
518 goto out_trans_end;
519
520 ret = -EAGAIN;
521 /* If truncated, we must retry the operation, we may have raced
522 * with the glock demotion code.
523 */
524 if (!PageUptodate(page) || page->mapping != inode->i_mapping)
525 goto out_trans_end;
526
527 /* Unstuff, if required, and allocate backing blocks for page */
528 ret = 0;
529 if (gfs2_is_stuffed(ip))
530 ret = gfs2_unstuff_dinode(ip, page);
531 if (ret == 0)
532 ret = gfs2_allocate_page_backing(page, PAGE_SIZE);
533
534out_trans_end:
535 if (ret)
536 unlock_page(page);
537 gfs2_trans_end(sdp);
538out_trans_fail:
539 gfs2_inplace_release(ip);
540out_quota_unlock:
541 gfs2_quota_unlock(ip);
542out_unlock:
543 gfs2_glock_dq(&gh);
544out_uninit:
545 gfs2_holder_uninit(&gh);
546 if (ret == 0) {
547 set_page_dirty(page);
548 wait_for_stable_page(page);
549 }
550out:
551 sb_end_pagefault(inode->i_sb);
552 return block_page_mkwrite_return(ret);
553}
554
555static const struct vm_operations_struct gfs2_vm_ops = {
556 .fault = filemap_fault,
557 .map_pages = filemap_map_pages,
558 .page_mkwrite = gfs2_page_mkwrite,
559};
560
561/**
562 * gfs2_mmap -
563 * @file: The file to map
564 * @vma: The VMA which described the mapping
565 *
566 * There is no need to get a lock here unless we should be updating
567 * atime. We ignore any locking errors since the only consequence is
568 * a missed atime update (which will just be deferred until later).
569 *
570 * Returns: 0
571 */
572
573static int gfs2_mmap(struct file *file, struct vm_area_struct *vma)
574{
575 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
576
577 if (!(file->f_flags & O_NOATIME) &&
578 !IS_NOATIME(&ip->i_inode)) {
579 struct gfs2_holder i_gh;
580 int error;
581
582 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY,
583 &i_gh);
584 if (error)
585 return error;
586 /* grab lock to update inode */
587 gfs2_glock_dq_uninit(&i_gh);
588 file_accessed(file);
589 }
590 vma->vm_ops = &gfs2_vm_ops;
591
592 return 0;
593}
594
595/**
596 * gfs2_open_common - This is common to open and atomic_open
597 * @inode: The inode being opened
598 * @file: The file being opened
599 *
600 * This maybe called under a glock or not depending upon how it has
601 * been called. We must always be called under a glock for regular
602 * files, however. For other file types, it does not matter whether
603 * we hold the glock or not.
604 *
605 * Returns: Error code or 0 for success
606 */
607
608int gfs2_open_common(struct inode *inode, struct file *file)
609{
610 struct gfs2_file *fp;
611 int ret;
612
613 if (S_ISREG(inode->i_mode)) {
614 ret = generic_file_open(inode, file);
615 if (ret)
616 return ret;
617 }
618
619 fp = kzalloc(sizeof(struct gfs2_file), GFP_NOFS);
620 if (!fp)
621 return -ENOMEM;
622
623 mutex_init(&fp->f_fl_mutex);
624
625 gfs2_assert_warn(GFS2_SB(inode), !file->private_data);
626 file->private_data = fp;
627 return 0;
628}
629
630/**
631 * gfs2_open - open a file
632 * @inode: the inode to open
633 * @file: the struct file for this opening
634 *
635 * After atomic_open, this function is only used for opening files
636 * which are already cached. We must still get the glock for regular
637 * files to ensure that we have the file size uptodate for the large
638 * file check which is in the common code. That is only an issue for
639 * regular files though.
640 *
641 * Returns: errno
642 */
643
644static int gfs2_open(struct inode *inode, struct file *file)
645{
646 struct gfs2_inode *ip = GFS2_I(inode);
647 struct gfs2_holder i_gh;
648 int error;
649 bool need_unlock = false;
650
651 if (S_ISREG(ip->i_inode.i_mode)) {
652 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY,
653 &i_gh);
654 if (error)
655 return error;
656 need_unlock = true;
657 }
658
659 error = gfs2_open_common(inode, file);
660
661 if (need_unlock)
662 gfs2_glock_dq_uninit(&i_gh);
663
664 return error;
665}
666
667/**
668 * gfs2_release - called to close a struct file
669 * @inode: the inode the struct file belongs to
670 * @file: the struct file being closed
671 *
672 * Returns: errno
673 */
674
675static int gfs2_release(struct inode *inode, struct file *file)
676{
677 struct gfs2_inode *ip = GFS2_I(inode);
678
679 kfree(file->private_data);
680 file->private_data = NULL;
681
682 if (!(file->f_mode & FMODE_WRITE))
683 return 0;
684
685 gfs2_rsqa_delete(ip, &inode->i_writecount);
686 return 0;
687}
688
689/**
690 * gfs2_fsync - sync the dirty data for a file (across the cluster)
691 * @file: the file that points to the dentry
692 * @start: the start position in the file to sync
693 * @end: the end position in the file to sync
694 * @datasync: set if we can ignore timestamp changes
695 *
696 * We split the data flushing here so that we don't wait for the data
697 * until after we've also sent the metadata to disk. Note that for
698 * data=ordered, we will write & wait for the data at the log flush
699 * stage anyway, so this is unlikely to make much of a difference
700 * except in the data=writeback case.
701 *
702 * If the fdatawrite fails due to any reason except -EIO, we will
703 * continue the remainder of the fsync, although we'll still report
704 * the error at the end. This is to match filemap_write_and_wait_range()
705 * behaviour.
706 *
707 * Returns: errno
708 */
709
710static int gfs2_fsync(struct file *file, loff_t start, loff_t end,
711 int datasync)
712{
713 struct address_space *mapping = file->f_mapping;
714 struct inode *inode = mapping->host;
715 int sync_state = inode->i_state & I_DIRTY_ALL;
716 struct gfs2_inode *ip = GFS2_I(inode);
717 int ret = 0, ret1 = 0;
718
719 if (mapping->nrpages) {
720 ret1 = filemap_fdatawrite_range(mapping, start, end);
721 if (ret1 == -EIO)
722 return ret1;
723 }
724
725 if (!gfs2_is_jdata(ip))
726 sync_state &= ~I_DIRTY_PAGES;
727 if (datasync)
728 sync_state &= ~(I_DIRTY_SYNC | I_DIRTY_TIME);
729
730 if (sync_state) {
731 ret = sync_inode_metadata(inode, 1);
732 if (ret)
733 return ret;
734 if (gfs2_is_jdata(ip))
735 ret = file_write_and_wait(file);
736 if (ret)
737 return ret;
738 gfs2_ail_flush(ip->i_gl, 1);
739 }
740
741 if (mapping->nrpages)
742 ret = file_fdatawait_range(file, start, end);
743
744 return ret ? ret : ret1;
745}
746
747static ssize_t gfs2_file_direct_read(struct kiocb *iocb, struct iov_iter *to)
748{
749 struct file *file = iocb->ki_filp;
750 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
751 size_t count = iov_iter_count(to);
752 struct gfs2_holder gh;
753 ssize_t ret;
754
755 if (!count)
756 return 0; /* skip atime */
757
758 gfs2_holder_init(ip->i_gl, LM_ST_DEFERRED, 0, &gh);
759 ret = gfs2_glock_nq(&gh);
760 if (ret)
761 goto out_uninit;
762
763 ret = iomap_dio_rw(iocb, to, &gfs2_iomap_ops, NULL);
764
765 gfs2_glock_dq(&gh);
766out_uninit:
767 gfs2_holder_uninit(&gh);
768 return ret;
769}
770
771static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from)
772{
773 struct file *file = iocb->ki_filp;
774 struct inode *inode = file->f_mapping->host;
775 struct gfs2_inode *ip = GFS2_I(inode);
776 size_t len = iov_iter_count(from);
777 loff_t offset = iocb->ki_pos;
778 struct gfs2_holder gh;
779 ssize_t ret;
780
781 /*
782 * Deferred lock, even if its a write, since we do no allocation on
783 * this path. All we need to change is the atime, and this lock mode
784 * ensures that other nodes have flushed their buffered read caches
785 * (i.e. their page cache entries for this inode). We do not,
786 * unfortunately, have the option of only flushing a range like the
787 * VFS does.
788 */
789 gfs2_holder_init(ip->i_gl, LM_ST_DEFERRED, 0, &gh);
790 ret = gfs2_glock_nq(&gh);
791 if (ret)
792 goto out_uninit;
793
794 /* Silently fall back to buffered I/O when writing beyond EOF */
795 if (offset + len > i_size_read(&ip->i_inode))
796 goto out;
797
798 ret = iomap_dio_rw(iocb, from, &gfs2_iomap_ops, NULL);
799
800out:
801 gfs2_glock_dq(&gh);
802out_uninit:
803 gfs2_holder_uninit(&gh);
804 return ret;
805}
806
807static ssize_t gfs2_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
808{
809 ssize_t ret;
810
811 if (iocb->ki_flags & IOCB_DIRECT) {
812 ret = gfs2_file_direct_read(iocb, to);
813 if (likely(ret != -ENOTBLK))
814 return ret;
815 iocb->ki_flags &= ~IOCB_DIRECT;
816 }
817 return generic_file_read_iter(iocb, to);
818}
819
820/**
821 * gfs2_file_write_iter - Perform a write to a file
822 * @iocb: The io context
823 * @from: The data to write
824 *
825 * We have to do a lock/unlock here to refresh the inode size for
826 * O_APPEND writes, otherwise we can land up writing at the wrong
827 * offset. There is still a race, but provided the app is using its
828 * own file locking, this will make O_APPEND work as expected.
829 *
830 */
831
832static ssize_t gfs2_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
833{
834 struct file *file = iocb->ki_filp;
835 struct inode *inode = file_inode(file);
836 struct gfs2_inode *ip = GFS2_I(inode);
837 ssize_t ret;
838
839 ret = gfs2_rsqa_alloc(ip);
840 if (ret)
841 return ret;
842
843 gfs2_size_hint(file, iocb->ki_pos, iov_iter_count(from));
844
845 if (iocb->ki_flags & IOCB_APPEND) {
846 struct gfs2_holder gh;
847
848 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
849 if (ret)
850 return ret;
851 gfs2_glock_dq_uninit(&gh);
852 }
853
854 inode_lock(inode);
855 ret = generic_write_checks(iocb, from);
856 if (ret <= 0)
857 goto out_unlock;
858
859 ret = file_remove_privs(file);
860 if (ret)
861 goto out_unlock;
862
863 ret = file_update_time(file);
864 if (ret)
865 goto out_unlock;
866
867 if (iocb->ki_flags & IOCB_DIRECT) {
868 struct address_space *mapping = file->f_mapping;
869 ssize_t buffered, ret2;
870
871 ret = gfs2_file_direct_write(iocb, from);
872 if (ret < 0 || !iov_iter_count(from))
873 goto out_unlock;
874
875 iocb->ki_flags |= IOCB_DSYNC;
876 current->backing_dev_info = inode_to_bdi(inode);
877 buffered = iomap_file_buffered_write(iocb, from, &gfs2_iomap_ops);
878 current->backing_dev_info = NULL;
879 if (unlikely(buffered <= 0)) {
880 if (!ret)
881 ret = buffered;
882 goto out_unlock;
883 }
884
885 /*
886 * We need to ensure that the page cache pages are written to
887 * disk and invalidated to preserve the expected O_DIRECT
888 * semantics. If the writeback or invalidate fails, only report
889 * the direct I/O range as we don't know if the buffered pages
890 * made it to disk.
891 */
892 iocb->ki_pos += buffered;
893 ret2 = generic_write_sync(iocb, buffered);
894 invalidate_mapping_pages(mapping,
895 (iocb->ki_pos - buffered) >> PAGE_SHIFT,
896 (iocb->ki_pos - 1) >> PAGE_SHIFT);
897 if (!ret || ret2 > 0)
898 ret += ret2;
899 } else {
900 current->backing_dev_info = inode_to_bdi(inode);
901 ret = iomap_file_buffered_write(iocb, from, &gfs2_iomap_ops);
902 current->backing_dev_info = NULL;
903 if (likely(ret > 0)) {
904 iocb->ki_pos += ret;
905 ret = generic_write_sync(iocb, ret);
906 }
907 }
908
909out_unlock:
910 inode_unlock(inode);
911 return ret;
912}
913
914static int fallocate_chunk(struct inode *inode, loff_t offset, loff_t len,
915 int mode)
916{
917 struct super_block *sb = inode->i_sb;
918 struct gfs2_inode *ip = GFS2_I(inode);
919 loff_t end = offset + len;
920 struct buffer_head *dibh;
921 int error;
922
923 error = gfs2_meta_inode_buffer(ip, &dibh);
924 if (unlikely(error))
925 return error;
926
927 gfs2_trans_add_meta(ip->i_gl, dibh);
928
929 if (gfs2_is_stuffed(ip)) {
930 error = gfs2_unstuff_dinode(ip, NULL);
931 if (unlikely(error))
932 goto out;
933 }
934
935 while (offset < end) {
936 struct iomap iomap = { };
937
938 error = gfs2_iomap_get_alloc(inode, offset, end - offset,
939 &iomap);
940 if (error)
941 goto out;
942 offset = iomap.offset + iomap.length;
943 if (!(iomap.flags & IOMAP_F_NEW))
944 continue;
945 error = sb_issue_zeroout(sb, iomap.addr >> inode->i_blkbits,
946 iomap.length >> inode->i_blkbits,
947 GFP_NOFS);
948 if (error) {
949 fs_err(GFS2_SB(inode), "Failed to zero data buffers\n");
950 goto out;
951 }
952 }
953out:
954 brelse(dibh);
955 return error;
956}
957/**
958 * calc_max_reserv() - Reverse of write_calc_reserv. Given a number of
959 * blocks, determine how many bytes can be written.
960 * @ip: The inode in question.
961 * @len: Max cap of bytes. What we return in *len must be <= this.
962 * @data_blocks: Compute and return the number of data blocks needed
963 * @ind_blocks: Compute and return the number of indirect blocks needed
964 * @max_blocks: The total blocks available to work with.
965 *
966 * Returns: void, but @len, @data_blocks and @ind_blocks are filled in.
967 */
968static void calc_max_reserv(struct gfs2_inode *ip, loff_t *len,
969 unsigned int *data_blocks, unsigned int *ind_blocks,
970 unsigned int max_blocks)
971{
972 loff_t max = *len;
973 const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
974 unsigned int tmp, max_data = max_blocks - 3 * (sdp->sd_max_height - 1);
975
976 for (tmp = max_data; tmp > sdp->sd_diptrs;) {
977 tmp = DIV_ROUND_UP(tmp, sdp->sd_inptrs);
978 max_data -= tmp;
979 }
980
981 *data_blocks = max_data;
982 *ind_blocks = max_blocks - max_data;
983 *len = ((loff_t)max_data - 3) << sdp->sd_sb.sb_bsize_shift;
984 if (*len > max) {
985 *len = max;
986 gfs2_write_calc_reserv(ip, max, data_blocks, ind_blocks);
987 }
988}
989
990static long __gfs2_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
991{
992 struct inode *inode = file_inode(file);
993 struct gfs2_sbd *sdp = GFS2_SB(inode);
994 struct gfs2_inode *ip = GFS2_I(inode);
995 struct gfs2_alloc_parms ap = { .aflags = 0, };
996 unsigned int data_blocks = 0, ind_blocks = 0, rblocks;
997 loff_t bytes, max_bytes, max_blks;
998 int error;
999 const loff_t pos = offset;
1000 const loff_t count = len;
1001 loff_t bsize_mask = ~((loff_t)sdp->sd_sb.sb_bsize - 1);
1002 loff_t next = (offset + len - 1) >> sdp->sd_sb.sb_bsize_shift;
1003 loff_t max_chunk_size = UINT_MAX & bsize_mask;
1004
1005 next = (next + 1) << sdp->sd_sb.sb_bsize_shift;
1006
1007 offset &= bsize_mask;
1008
1009 len = next - offset;
1010 bytes = sdp->sd_max_rg_data * sdp->sd_sb.sb_bsize / 2;
1011 if (!bytes)
1012 bytes = UINT_MAX;
1013 bytes &= bsize_mask;
1014 if (bytes == 0)
1015 bytes = sdp->sd_sb.sb_bsize;
1016
1017 gfs2_size_hint(file, offset, len);
1018
1019 gfs2_write_calc_reserv(ip, PAGE_SIZE, &data_blocks, &ind_blocks);
1020 ap.min_target = data_blocks + ind_blocks;
1021
1022 while (len > 0) {
1023 if (len < bytes)
1024 bytes = len;
1025 if (!gfs2_write_alloc_required(ip, offset, bytes)) {
1026 len -= bytes;
1027 offset += bytes;
1028 continue;
1029 }
1030
1031 /* We need to determine how many bytes we can actually
1032 * fallocate without exceeding quota or going over the
1033 * end of the fs. We start off optimistically by assuming
1034 * we can write max_bytes */
1035 max_bytes = (len > max_chunk_size) ? max_chunk_size : len;
1036
1037 /* Since max_bytes is most likely a theoretical max, we
1038 * calculate a more realistic 'bytes' to serve as a good
1039 * starting point for the number of bytes we may be able
1040 * to write */
1041 gfs2_write_calc_reserv(ip, bytes, &data_blocks, &ind_blocks);
1042 ap.target = data_blocks + ind_blocks;
1043
1044 error = gfs2_quota_lock_check(ip, &ap);
1045 if (error)
1046 return error;
1047 /* ap.allowed tells us how many blocks quota will allow
1048 * us to write. Check if this reduces max_blks */
1049 max_blks = UINT_MAX;
1050 if (ap.allowed)
1051 max_blks = ap.allowed;
1052
1053 error = gfs2_inplace_reserve(ip, &ap);
1054 if (error)
1055 goto out_qunlock;
1056
1057 /* check if the selected rgrp limits our max_blks further */
1058 if (ap.allowed && ap.allowed < max_blks)
1059 max_blks = ap.allowed;
1060
1061 /* Almost done. Calculate bytes that can be written using
1062 * max_blks. We also recompute max_bytes, data_blocks and
1063 * ind_blocks */
1064 calc_max_reserv(ip, &max_bytes, &data_blocks,
1065 &ind_blocks, max_blks);
1066
1067 rblocks = RES_DINODE + ind_blocks + RES_STATFS + RES_QUOTA +
1068 RES_RG_HDR + gfs2_rg_blocks(ip, data_blocks + ind_blocks);
1069 if (gfs2_is_jdata(ip))
1070 rblocks += data_blocks ? data_blocks : 1;
1071
1072 error = gfs2_trans_begin(sdp, rblocks,
1073 PAGE_SIZE >> inode->i_blkbits);
1074 if (error)
1075 goto out_trans_fail;
1076
1077 error = fallocate_chunk(inode, offset, max_bytes, mode);
1078 gfs2_trans_end(sdp);
1079
1080 if (error)
1081 goto out_trans_fail;
1082
1083 len -= max_bytes;
1084 offset += max_bytes;
1085 gfs2_inplace_release(ip);
1086 gfs2_quota_unlock(ip);
1087 }
1088
1089 if (!(mode & FALLOC_FL_KEEP_SIZE) && (pos + count) > inode->i_size)
1090 i_size_write(inode, pos + count);
1091 file_update_time(file);
1092 mark_inode_dirty(inode);
1093
1094 if ((file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host))
1095 return vfs_fsync_range(file, pos, pos + count - 1,
1096 (file->f_flags & __O_SYNC) ? 0 : 1);
1097 return 0;
1098
1099out_trans_fail:
1100 gfs2_inplace_release(ip);
1101out_qunlock:
1102 gfs2_quota_unlock(ip);
1103 return error;
1104}
1105
1106static long gfs2_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
1107{
1108 struct inode *inode = file_inode(file);
1109 struct gfs2_sbd *sdp = GFS2_SB(inode);
1110 struct gfs2_inode *ip = GFS2_I(inode);
1111 struct gfs2_holder gh;
1112 int ret;
1113
1114 if (mode & ~(FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE))
1115 return -EOPNOTSUPP;
1116 /* fallocate is needed by gfs2_grow to reserve space in the rindex */
1117 if (gfs2_is_jdata(ip) && inode != sdp->sd_rindex)
1118 return -EOPNOTSUPP;
1119
1120 inode_lock(inode);
1121
1122 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
1123 ret = gfs2_glock_nq(&gh);
1124 if (ret)
1125 goto out_uninit;
1126
1127 if (!(mode & FALLOC_FL_KEEP_SIZE) &&
1128 (offset + len) > inode->i_size) {
1129 ret = inode_newsize_ok(inode, offset + len);
1130 if (ret)
1131 goto out_unlock;
1132 }
1133
1134 ret = get_write_access(inode);
1135 if (ret)
1136 goto out_unlock;
1137
1138 if (mode & FALLOC_FL_PUNCH_HOLE) {
1139 ret = __gfs2_punch_hole(file, offset, len);
1140 } else {
1141 ret = gfs2_rsqa_alloc(ip);
1142 if (ret)
1143 goto out_putw;
1144
1145 ret = __gfs2_fallocate(file, mode, offset, len);
1146
1147 if (ret)
1148 gfs2_rs_deltree(&ip->i_res);
1149 }
1150
1151out_putw:
1152 put_write_access(inode);
1153out_unlock:
1154 gfs2_glock_dq(&gh);
1155out_uninit:
1156 gfs2_holder_uninit(&gh);
1157 inode_unlock(inode);
1158 return ret;
1159}
1160
1161static ssize_t gfs2_file_splice_write(struct pipe_inode_info *pipe,
1162 struct file *out, loff_t *ppos,
1163 size_t len, unsigned int flags)
1164{
1165 int error;
1166 struct gfs2_inode *ip = GFS2_I(out->f_mapping->host);
1167
1168 error = gfs2_rsqa_alloc(ip);
1169 if (error)
1170 return (ssize_t)error;
1171
1172 gfs2_size_hint(out, *ppos, len);
1173
1174 return iter_file_splice_write(pipe, out, ppos, len, flags);
1175}
1176
1177#ifdef CONFIG_GFS2_FS_LOCKING_DLM
1178
1179/**
1180 * gfs2_lock - acquire/release a posix lock on a file
1181 * @file: the file pointer
1182 * @cmd: either modify or retrieve lock state, possibly wait
1183 * @fl: type and range of lock
1184 *
1185 * Returns: errno
1186 */
1187
1188static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
1189{
1190 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
1191 struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host);
1192 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
1193
1194 if (!(fl->fl_flags & FL_POSIX))
1195 return -ENOLCK;
1196 if (__mandatory_lock(&ip->i_inode) && fl->fl_type != F_UNLCK)
1197 return -ENOLCK;
1198
1199 if (cmd == F_CANCELLK) {
1200 /* Hack: */
1201 cmd = F_SETLK;
1202 fl->fl_type = F_UNLCK;
1203 }
1204 if (unlikely(test_bit(SDF_WITHDRAWN, &sdp->sd_flags))) {
1205 if (fl->fl_type == F_UNLCK)
1206 locks_lock_file_wait(file, fl);
1207 return -EIO;
1208 }
1209 if (IS_GETLK(cmd))
1210 return dlm_posix_get(ls->ls_dlm, ip->i_no_addr, file, fl);
1211 else if (fl->fl_type == F_UNLCK)
1212 return dlm_posix_unlock(ls->ls_dlm, ip->i_no_addr, file, fl);
1213 else
1214 return dlm_posix_lock(ls->ls_dlm, ip->i_no_addr, file, cmd, fl);
1215}
1216
1217static int do_flock(struct file *file, int cmd, struct file_lock *fl)
1218{
1219 struct gfs2_file *fp = file->private_data;
1220 struct gfs2_holder *fl_gh = &fp->f_fl_gh;
1221 struct gfs2_inode *ip = GFS2_I(file_inode(file));
1222 struct gfs2_glock *gl;
1223 unsigned int state;
1224 u16 flags;
1225 int error = 0;
1226 int sleeptime;
1227
1228 state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED;
1229 flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY_1CB) | GL_EXACT;
1230
1231 mutex_lock(&fp->f_fl_mutex);
1232
1233 if (gfs2_holder_initialized(fl_gh)) {
1234 struct file_lock request;
1235 if (fl_gh->gh_state == state)
1236 goto out;
1237 locks_init_lock(&request);
1238 request.fl_type = F_UNLCK;
1239 request.fl_flags = FL_FLOCK;
1240 locks_lock_file_wait(file, &request);
1241 gfs2_glock_dq(fl_gh);
1242 gfs2_holder_reinit(state, flags, fl_gh);
1243 } else {
1244 error = gfs2_glock_get(GFS2_SB(&ip->i_inode), ip->i_no_addr,
1245 &gfs2_flock_glops, CREATE, &gl);
1246 if (error)
1247 goto out;
1248 gfs2_holder_init(gl, state, flags, fl_gh);
1249 gfs2_glock_put(gl);
1250 }
1251 for (sleeptime = 1; sleeptime <= 4; sleeptime <<= 1) {
1252 error = gfs2_glock_nq(fl_gh);
1253 if (error != GLR_TRYFAILED)
1254 break;
1255 fl_gh->gh_flags = LM_FLAG_TRY | GL_EXACT;
1256 fl_gh->gh_error = 0;
1257 msleep(sleeptime);
1258 }
1259 if (error) {
1260 gfs2_holder_uninit(fl_gh);
1261 if (error == GLR_TRYFAILED)
1262 error = -EAGAIN;
1263 } else {
1264 error = locks_lock_file_wait(file, fl);
1265 gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error);
1266 }
1267
1268out:
1269 mutex_unlock(&fp->f_fl_mutex);
1270 return error;
1271}
1272
1273static void do_unflock(struct file *file, struct file_lock *fl)
1274{
1275 struct gfs2_file *fp = file->private_data;
1276 struct gfs2_holder *fl_gh = &fp->f_fl_gh;
1277
1278 mutex_lock(&fp->f_fl_mutex);
1279 locks_lock_file_wait(file, fl);
1280 if (gfs2_holder_initialized(fl_gh)) {
1281 gfs2_glock_dq(fl_gh);
1282 gfs2_holder_uninit(fl_gh);
1283 }
1284 mutex_unlock(&fp->f_fl_mutex);
1285}
1286
1287/**
1288 * gfs2_flock - acquire/release a flock lock on a file
1289 * @file: the file pointer
1290 * @cmd: either modify or retrieve lock state, possibly wait
1291 * @fl: type and range of lock
1292 *
1293 * Returns: errno
1294 */
1295
1296static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl)
1297{
1298 if (!(fl->fl_flags & FL_FLOCK))
1299 return -ENOLCK;
1300 if (fl->fl_type & LOCK_MAND)
1301 return -EOPNOTSUPP;
1302
1303 if (fl->fl_type == F_UNLCK) {
1304 do_unflock(file, fl);
1305 return 0;
1306 } else {
1307 return do_flock(file, cmd, fl);
1308 }
1309}
1310
1311const struct file_operations gfs2_file_fops = {
1312 .llseek = gfs2_llseek,
1313 .read_iter = gfs2_file_read_iter,
1314 .write_iter = gfs2_file_write_iter,
1315 .iopoll = iomap_dio_iopoll,
1316 .unlocked_ioctl = gfs2_ioctl,
1317 .compat_ioctl = gfs2_compat_ioctl,
1318 .mmap = gfs2_mmap,
1319 .open = gfs2_open,
1320 .release = gfs2_release,
1321 .fsync = gfs2_fsync,
1322 .lock = gfs2_lock,
1323 .flock = gfs2_flock,
1324 .splice_read = generic_file_splice_read,
1325 .splice_write = gfs2_file_splice_write,
1326 .setlease = simple_nosetlease,
1327 .fallocate = gfs2_fallocate,
1328};
1329
1330const struct file_operations gfs2_dir_fops = {
1331 .iterate_shared = gfs2_readdir,
1332 .unlocked_ioctl = gfs2_ioctl,
1333 .compat_ioctl = gfs2_compat_ioctl,
1334 .open = gfs2_open,
1335 .release = gfs2_release,
1336 .fsync = gfs2_fsync,
1337 .lock = gfs2_lock,
1338 .flock = gfs2_flock,
1339 .llseek = default_llseek,
1340};
1341
1342#endif /* CONFIG_GFS2_FS_LOCKING_DLM */
1343
1344const struct file_operations gfs2_file_fops_nolock = {
1345 .llseek = gfs2_llseek,
1346 .read_iter = gfs2_file_read_iter,
1347 .write_iter = gfs2_file_write_iter,
1348 .iopoll = iomap_dio_iopoll,
1349 .unlocked_ioctl = gfs2_ioctl,
1350 .compat_ioctl = gfs2_compat_ioctl,
1351 .mmap = gfs2_mmap,
1352 .open = gfs2_open,
1353 .release = gfs2_release,
1354 .fsync = gfs2_fsync,
1355 .splice_read = generic_file_splice_read,
1356 .splice_write = gfs2_file_splice_write,
1357 .setlease = generic_setlease,
1358 .fallocate = gfs2_fallocate,
1359};
1360
1361const struct file_operations gfs2_dir_fops_nolock = {
1362 .iterate_shared = gfs2_readdir,
1363 .unlocked_ioctl = gfs2_ioctl,
1364 .compat_ioctl = gfs2_compat_ioctl,
1365 .open = gfs2_open,
1366 .release = gfs2_release,
1367 .fsync = gfs2_fsync,
1368 .llseek = default_llseek,
1369};
1370