1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * File open, close, extend, truncate
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 021110-1307, USA.
26 #include <linux/capability.h>
28 #include <linux/types.h>
29 #include <linux/slab.h>
30 #include <linux/highmem.h>
31 #include <linux/pagemap.h>
32 #include <linux/uio.h>
33 #include <linux/sched.h>
34 #include <linux/splice.h>
35 #include <linux/mount.h>
36 #include <linux/writeback.h>
37 #include <linux/falloc.h>
38 #include <linux/quotaops.h>
39 #include <linux/blkdev.h>
40 #include <linux/backing-dev.h>
42 #include <cluster/masklog.h>
50 #include "extent_map.h"
63 #include "refcounttree.h"
64 #include "ocfs2_trace.h"
66 #include "buffer_head_io.h"
68 static int ocfs2_init_file_private(struct inode
*inode
, struct file
*file
)
70 struct ocfs2_file_private
*fp
;
72 fp
= kzalloc(sizeof(struct ocfs2_file_private
), GFP_KERNEL
);
77 mutex_init(&fp
->fp_mutex
);
78 ocfs2_file_lock_res_init(&fp
->fp_flock
, fp
);
79 file
->private_data
= fp
;
84 static void ocfs2_free_file_private(struct inode
*inode
, struct file
*file
)
86 struct ocfs2_file_private
*fp
= file
->private_data
;
87 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
90 ocfs2_simple_drop_lockres(osb
, &fp
->fp_flock
);
91 ocfs2_lock_res_free(&fp
->fp_flock
);
93 file
->private_data
= NULL
;
97 static int ocfs2_file_open(struct inode
*inode
, struct file
*file
)
100 int mode
= file
->f_flags
;
101 struct ocfs2_inode_info
*oi
= OCFS2_I(inode
);
103 trace_ocfs2_file_open(inode
, file
, file
->f_path
.dentry
,
104 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
105 file
->f_path
.dentry
->d_name
.len
,
106 file
->f_path
.dentry
->d_name
.name
, mode
);
108 if (file
->f_mode
& FMODE_WRITE
)
109 dquot_initialize(inode
);
111 spin_lock(&oi
->ip_lock
);
113 /* Check that the inode hasn't been wiped from disk by another
114 * node. If it hasn't then we're safe as long as we hold the
115 * spin lock until our increment of open count. */
116 if (OCFS2_I(inode
)->ip_flags
& OCFS2_INODE_DELETED
) {
117 spin_unlock(&oi
->ip_lock
);
124 oi
->ip_flags
|= OCFS2_INODE_OPEN_DIRECT
;
127 spin_unlock(&oi
->ip_lock
);
129 status
= ocfs2_init_file_private(inode
, file
);
132 * We want to set open count back if we're failing the
135 spin_lock(&oi
->ip_lock
);
137 spin_unlock(&oi
->ip_lock
);
144 static int ocfs2_file_release(struct inode
*inode
, struct file
*file
)
146 struct ocfs2_inode_info
*oi
= OCFS2_I(inode
);
148 spin_lock(&oi
->ip_lock
);
149 if (!--oi
->ip_open_count
)
150 oi
->ip_flags
&= ~OCFS2_INODE_OPEN_DIRECT
;
152 trace_ocfs2_file_release(inode
, file
, file
->f_path
.dentry
,
154 file
->f_path
.dentry
->d_name
.len
,
155 file
->f_path
.dentry
->d_name
.name
,
157 spin_unlock(&oi
->ip_lock
);
159 ocfs2_free_file_private(inode
, file
);
164 static int ocfs2_dir_open(struct inode
*inode
, struct file
*file
)
166 return ocfs2_init_file_private(inode
, file
);
169 static int ocfs2_dir_release(struct inode
*inode
, struct file
*file
)
171 ocfs2_free_file_private(inode
, file
);
175 static int ocfs2_sync_file(struct file
*file
, loff_t start
, loff_t end
,
179 struct inode
*inode
= file
->f_mapping
->host
;
180 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
181 struct ocfs2_inode_info
*oi
= OCFS2_I(inode
);
182 journal_t
*journal
= osb
->journal
->j_journal
;
185 bool needs_barrier
= false;
187 trace_ocfs2_sync_file(inode
, file
, file
->f_path
.dentry
,
188 OCFS2_I(inode
)->ip_blkno
,
189 file
->f_path
.dentry
->d_name
.len
,
190 file
->f_path
.dentry
->d_name
.name
,
191 (unsigned long long)datasync
);
193 if (ocfs2_is_hard_readonly(osb
) || ocfs2_is_soft_readonly(osb
))
196 err
= filemap_write_and_wait_range(inode
->i_mapping
, start
, end
);
200 commit_tid
= datasync
? oi
->i_datasync_tid
: oi
->i_sync_tid
;
201 if (journal
->j_flags
& JBD2_BARRIER
&&
202 !jbd2_trans_will_send_data_barrier(journal
, commit_tid
))
203 needs_barrier
= true;
204 err
= jbd2_complete_transaction(journal
, commit_tid
);
206 ret
= blkdev_issue_flush(inode
->i_sb
->s_bdev
, GFP_KERNEL
, NULL
);
214 return (err
< 0) ? -EIO
: 0;
217 int ocfs2_should_update_atime(struct inode
*inode
,
218 struct vfsmount
*vfsmnt
)
221 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
223 if (ocfs2_is_hard_readonly(osb
) || ocfs2_is_soft_readonly(osb
))
226 if ((inode
->i_flags
& S_NOATIME
) ||
227 ((inode
->i_sb
->s_flags
& MS_NODIRATIME
) && S_ISDIR(inode
->i_mode
)))
231 * We can be called with no vfsmnt structure - NFSD will
234 * Note that our action here is different than touch_atime() -
235 * if we can't tell whether this is a noatime mount, then we
236 * don't know whether to trust the value of s_atime_quantum.
241 if ((vfsmnt
->mnt_flags
& MNT_NOATIME
) ||
242 ((vfsmnt
->mnt_flags
& MNT_NODIRATIME
) && S_ISDIR(inode
->i_mode
)))
245 if (vfsmnt
->mnt_flags
& MNT_RELATIME
) {
246 if ((timespec_compare(&inode
->i_atime
, &inode
->i_mtime
) <= 0) ||
247 (timespec_compare(&inode
->i_atime
, &inode
->i_ctime
) <= 0))
254 if ((now
.tv_sec
- inode
->i_atime
.tv_sec
<= osb
->s_atime_quantum
))
260 int ocfs2_update_inode_atime(struct inode
*inode
,
261 struct buffer_head
*bh
)
264 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
266 struct ocfs2_dinode
*di
= (struct ocfs2_dinode
*) bh
->b_data
;
268 handle
= ocfs2_start_trans(osb
, OCFS2_INODE_UPDATE_CREDITS
);
269 if (IS_ERR(handle
)) {
270 ret
= PTR_ERR(handle
);
275 ret
= ocfs2_journal_access_di(handle
, INODE_CACHE(inode
), bh
,
276 OCFS2_JOURNAL_ACCESS_WRITE
);
283 * Don't use ocfs2_mark_inode_dirty() here as we don't always
284 * have i_mutex to guard against concurrent changes to other
287 inode
->i_atime
= CURRENT_TIME
;
288 di
->i_atime
= cpu_to_le64(inode
->i_atime
.tv_sec
);
289 di
->i_atime_nsec
= cpu_to_le32(inode
->i_atime
.tv_nsec
);
290 ocfs2_update_inode_fsync_trans(handle
, inode
, 0);
291 ocfs2_journal_dirty(handle
, bh
);
294 ocfs2_commit_trans(OCFS2_SB(inode
->i_sb
), handle
);
299 int ocfs2_set_inode_size(handle_t
*handle
,
301 struct buffer_head
*fe_bh
,
306 i_size_write(inode
, new_i_size
);
307 inode
->i_blocks
= ocfs2_inode_sector_count(inode
);
308 inode
->i_ctime
= inode
->i_mtime
= CURRENT_TIME
;
310 status
= ocfs2_mark_inode_dirty(handle
, inode
, fe_bh
);
320 int ocfs2_simple_size_update(struct inode
*inode
,
321 struct buffer_head
*di_bh
,
325 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
326 handle_t
*handle
= NULL
;
328 handle
= ocfs2_start_trans(osb
, OCFS2_INODE_UPDATE_CREDITS
);
329 if (IS_ERR(handle
)) {
330 ret
= PTR_ERR(handle
);
335 ret
= ocfs2_set_inode_size(handle
, inode
, di_bh
,
340 ocfs2_update_inode_fsync_trans(handle
, inode
, 0);
341 ocfs2_commit_trans(osb
, handle
);
346 static int ocfs2_cow_file_pos(struct inode
*inode
,
347 struct buffer_head
*fe_bh
,
351 u32 phys
, cpos
= offset
>> OCFS2_SB(inode
->i_sb
)->s_clustersize_bits
;
352 unsigned int num_clusters
= 0;
353 unsigned int ext_flags
= 0;
356 * If the new offset is aligned to the range of the cluster, there is
357 * no space for ocfs2_zero_range_for_truncate to fill, so no need to
360 if ((offset
& (OCFS2_SB(inode
->i_sb
)->s_clustersize
- 1)) == 0)
363 status
= ocfs2_get_clusters(inode
, cpos
, &phys
,
364 &num_clusters
, &ext_flags
);
370 if (!(ext_flags
& OCFS2_EXT_REFCOUNTED
))
373 return ocfs2_refcount_cow(inode
, fe_bh
, cpos
, 1, cpos
+1);
379 static int ocfs2_orphan_for_truncate(struct ocfs2_super
*osb
,
381 struct buffer_head
*fe_bh
,
386 struct ocfs2_dinode
*di
;
390 * We need to CoW the cluster contains the offset if it is reflinked
391 * since we will call ocfs2_zero_range_for_truncate later which will
392 * write "0" from offset to the end of the cluster.
394 status
= ocfs2_cow_file_pos(inode
, fe_bh
, new_i_size
);
400 /* TODO: This needs to actually orphan the inode in this
403 handle
= ocfs2_start_trans(osb
, OCFS2_INODE_UPDATE_CREDITS
);
404 if (IS_ERR(handle
)) {
405 status
= PTR_ERR(handle
);
410 status
= ocfs2_journal_access_di(handle
, INODE_CACHE(inode
), fe_bh
,
411 OCFS2_JOURNAL_ACCESS_WRITE
);
418 * Do this before setting i_size.
420 cluster_bytes
= ocfs2_align_bytes_to_clusters(inode
->i_sb
, new_i_size
);
421 status
= ocfs2_zero_range_for_truncate(inode
, handle
, new_i_size
,
428 i_size_write(inode
, new_i_size
);
429 inode
->i_ctime
= inode
->i_mtime
= CURRENT_TIME
;
431 di
= (struct ocfs2_dinode
*) fe_bh
->b_data
;
432 di
->i_size
= cpu_to_le64(new_i_size
);
433 di
->i_ctime
= di
->i_mtime
= cpu_to_le64(inode
->i_ctime
.tv_sec
);
434 di
->i_ctime_nsec
= di
->i_mtime_nsec
= cpu_to_le32(inode
->i_ctime
.tv_nsec
);
435 ocfs2_update_inode_fsync_trans(handle
, inode
, 0);
437 ocfs2_journal_dirty(handle
, fe_bh
);
440 ocfs2_commit_trans(osb
, handle
);
445 int ocfs2_truncate_file(struct inode
*inode
,
446 struct buffer_head
*di_bh
,
450 struct ocfs2_dinode
*fe
= NULL
;
451 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
453 /* We trust di_bh because it comes from ocfs2_inode_lock(), which
454 * already validated it */
455 fe
= (struct ocfs2_dinode
*) di_bh
->b_data
;
457 trace_ocfs2_truncate_file((unsigned long long)OCFS2_I(inode
)->ip_blkno
,
458 (unsigned long long)le64_to_cpu(fe
->i_size
),
459 (unsigned long long)new_i_size
);
461 mlog_bug_on_msg(le64_to_cpu(fe
->i_size
) != i_size_read(inode
),
462 "Inode %llu, inode i_size = %lld != di "
463 "i_size = %llu, i_flags = 0x%x\n",
464 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
466 (unsigned long long)le64_to_cpu(fe
->i_size
),
467 le32_to_cpu(fe
->i_flags
));
469 if (new_i_size
> le64_to_cpu(fe
->i_size
)) {
470 trace_ocfs2_truncate_file_error(
471 (unsigned long long)le64_to_cpu(fe
->i_size
),
472 (unsigned long long)new_i_size
);
478 down_write(&OCFS2_I(inode
)->ip_alloc_sem
);
480 ocfs2_resv_discard(&osb
->osb_la_resmap
,
481 &OCFS2_I(inode
)->ip_la_data_resv
);
484 * The inode lock forced other nodes to sync and drop their
485 * pages, which (correctly) happens even if we have a truncate
486 * without allocation change - ocfs2 cluster sizes can be much
487 * greater than page size, so we have to truncate them
490 unmap_mapping_range(inode
->i_mapping
, new_i_size
+ PAGE_SIZE
- 1, 0, 1);
491 truncate_inode_pages(inode
->i_mapping
, new_i_size
);
493 if (OCFS2_I(inode
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
) {
494 status
= ocfs2_truncate_inline(inode
, di_bh
, new_i_size
,
495 i_size_read(inode
), 1);
499 goto bail_unlock_sem
;
502 /* alright, we're going to need to do a full blown alloc size
503 * change. Orphan the inode so that recovery can complete the
504 * truncate if necessary. This does the task of marking
506 status
= ocfs2_orphan_for_truncate(osb
, inode
, di_bh
, new_i_size
);
509 goto bail_unlock_sem
;
512 status
= ocfs2_commit_truncate(osb
, inode
, di_bh
);
515 goto bail_unlock_sem
;
518 /* TODO: orphan dir cleanup here. */
520 up_write(&OCFS2_I(inode
)->ip_alloc_sem
);
523 if (!status
&& OCFS2_I(inode
)->ip_clusters
== 0)
524 status
= ocfs2_try_remove_refcount_tree(inode
, di_bh
);
530 * extend file allocation only here.
531 * we'll update all the disk stuff, and oip->alloc_size
533 * expect stuff to be locked, a transaction started and enough data /
534 * metadata reservations in the contexts.
536 * Will return -EAGAIN, and a reason if a restart is needed.
537 * If passed in, *reason will always be set, even in error.
539 int ocfs2_add_inode_data(struct ocfs2_super
*osb
,
544 struct buffer_head
*fe_bh
,
546 struct ocfs2_alloc_context
*data_ac
,
547 struct ocfs2_alloc_context
*meta_ac
,
548 enum ocfs2_alloc_restarted
*reason_ret
)
551 struct ocfs2_extent_tree et
;
553 ocfs2_init_dinode_extent_tree(&et
, INODE_CACHE(inode
), fe_bh
);
554 ret
= ocfs2_add_clusters_in_btree(handle
, &et
, logical_offset
,
555 clusters_to_add
, mark_unwritten
,
556 data_ac
, meta_ac
, reason_ret
);
561 static int __ocfs2_extend_allocation(struct inode
*inode
, u32 logical_start
,
562 u32 clusters_to_add
, int mark_unwritten
)
565 int restart_func
= 0;
568 struct buffer_head
*bh
= NULL
;
569 struct ocfs2_dinode
*fe
= NULL
;
570 handle_t
*handle
= NULL
;
571 struct ocfs2_alloc_context
*data_ac
= NULL
;
572 struct ocfs2_alloc_context
*meta_ac
= NULL
;
573 enum ocfs2_alloc_restarted why
= RESTART_NONE
;
574 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
575 struct ocfs2_extent_tree et
;
579 * Unwritten extent only exists for file systems which
582 BUG_ON(mark_unwritten
&& !ocfs2_sparse_alloc(osb
));
584 status
= ocfs2_read_inode_block(inode
, &bh
);
589 fe
= (struct ocfs2_dinode
*) bh
->b_data
;
592 BUG_ON(le32_to_cpu(fe
->i_clusters
) != OCFS2_I(inode
)->ip_clusters
);
594 ocfs2_init_dinode_extent_tree(&et
, INODE_CACHE(inode
), bh
);
595 status
= ocfs2_lock_allocators(inode
, &et
, clusters_to_add
, 0,
602 credits
= ocfs2_calc_extend_credits(osb
->sb
, &fe
->id2
.i_list
);
603 handle
= ocfs2_start_trans(osb
, credits
);
604 if (IS_ERR(handle
)) {
605 status
= PTR_ERR(handle
);
611 restarted_transaction
:
612 trace_ocfs2_extend_allocation(
613 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
614 (unsigned long long)i_size_read(inode
),
615 le32_to_cpu(fe
->i_clusters
), clusters_to_add
,
618 status
= dquot_alloc_space_nodirty(inode
,
619 ocfs2_clusters_to_bytes(osb
->sb
, clusters_to_add
));
624 /* reserve a write to the file entry early on - that we if we
625 * run out of credits in the allocation path, we can still
627 status
= ocfs2_journal_access_di(handle
, INODE_CACHE(inode
), bh
,
628 OCFS2_JOURNAL_ACCESS_WRITE
);
634 prev_clusters
= OCFS2_I(inode
)->ip_clusters
;
636 status
= ocfs2_add_inode_data(osb
,
646 if ((status
< 0) && (status
!= -EAGAIN
)) {
647 if (status
!= -ENOSPC
)
651 ocfs2_update_inode_fsync_trans(handle
, inode
, 1);
652 ocfs2_journal_dirty(handle
, bh
);
654 spin_lock(&OCFS2_I(inode
)->ip_lock
);
655 clusters_to_add
-= (OCFS2_I(inode
)->ip_clusters
- prev_clusters
);
656 spin_unlock(&OCFS2_I(inode
)->ip_lock
);
657 /* Release unused quota reservation */
658 dquot_free_space(inode
,
659 ocfs2_clusters_to_bytes(osb
->sb
, clusters_to_add
));
662 if (why
!= RESTART_NONE
&& clusters_to_add
) {
663 if (why
== RESTART_META
) {
667 BUG_ON(why
!= RESTART_TRANS
);
669 status
= ocfs2_allocate_extend_trans(handle
, 1);
671 /* handle still has to be committed at
677 goto restarted_transaction
;
681 trace_ocfs2_extend_allocation_end(OCFS2_I(inode
)->ip_blkno
,
682 le32_to_cpu(fe
->i_clusters
),
683 (unsigned long long)le64_to_cpu(fe
->i_size
),
684 OCFS2_I(inode
)->ip_clusters
,
685 (unsigned long long)i_size_read(inode
));
688 if (status
< 0 && did_quota
)
689 dquot_free_space(inode
,
690 ocfs2_clusters_to_bytes(osb
->sb
, clusters_to_add
));
692 ocfs2_commit_trans(osb
, handle
);
696 ocfs2_free_alloc_context(data_ac
);
700 ocfs2_free_alloc_context(meta_ac
);
703 if ((!status
) && restart_func
) {
713 int ocfs2_extend_allocation(struct inode
*inode
, u32 logical_start
,
714 u32 clusters_to_add
, int mark_unwritten
)
716 return __ocfs2_extend_allocation(inode
, logical_start
,
717 clusters_to_add
, mark_unwritten
);
721 * While a write will already be ordering the data, a truncate will not.
722 * Thus, we need to explicitly order the zeroed pages.
724 static handle_t
*ocfs2_zero_start_ordered_transaction(struct inode
*inode
,
725 struct buffer_head
*di_bh
)
727 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
728 handle_t
*handle
= NULL
;
731 if (!ocfs2_should_order_data(inode
))
734 handle
= ocfs2_start_trans(osb
, OCFS2_INODE_UPDATE_CREDITS
);
735 if (IS_ERR(handle
)) {
741 ret
= ocfs2_jbd2_file_inode(handle
, inode
);
747 ret
= ocfs2_journal_access_di(handle
, INODE_CACHE(inode
), di_bh
,
748 OCFS2_JOURNAL_ACCESS_WRITE
);
751 ocfs2_update_inode_fsync_trans(handle
, inode
, 1);
756 ocfs2_commit_trans(osb
, handle
);
757 handle
= ERR_PTR(ret
);
762 /* Some parts of this taken from generic_cont_expand, which turned out
763 * to be too fragile to do exactly what we need without us having to
764 * worry about recursive locking in ->write_begin() and ->write_end(). */
765 static int ocfs2_write_zero_page(struct inode
*inode
, u64 abs_from
,
766 u64 abs_to
, struct buffer_head
*di_bh
)
768 struct address_space
*mapping
= inode
->i_mapping
;
770 unsigned long index
= abs_from
>> PAGE_CACHE_SHIFT
;
773 unsigned zero_from
, zero_to
, block_start
, block_end
;
774 struct ocfs2_dinode
*di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
776 BUG_ON(abs_from
>= abs_to
);
777 BUG_ON(abs_to
> (((u64
)index
+ 1) << PAGE_CACHE_SHIFT
));
778 BUG_ON(abs_from
& (inode
->i_blkbits
- 1));
780 handle
= ocfs2_zero_start_ordered_transaction(inode
, di_bh
);
781 if (IS_ERR(handle
)) {
782 ret
= PTR_ERR(handle
);
786 page
= find_or_create_page(mapping
, index
, GFP_NOFS
);
790 goto out_commit_trans
;
793 /* Get the offsets within the page that we want to zero */
794 zero_from
= abs_from
& (PAGE_CACHE_SIZE
- 1);
795 zero_to
= abs_to
& (PAGE_CACHE_SIZE
- 1);
797 zero_to
= PAGE_CACHE_SIZE
;
799 trace_ocfs2_write_zero_page(
800 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
801 (unsigned long long)abs_from
,
802 (unsigned long long)abs_to
,
803 index
, zero_from
, zero_to
);
805 /* We know that zero_from is block aligned */
806 for (block_start
= zero_from
; block_start
< zero_to
;
807 block_start
= block_end
) {
808 block_end
= block_start
+ (1 << inode
->i_blkbits
);
811 * block_start is block-aligned. Bump it by one to force
812 * __block_write_begin and block_commit_write to zero the
815 ret
= __block_write_begin(page
, block_start
+ 1, 0,
823 /* must not update i_size! */
824 ret
= block_commit_write(page
, block_start
+ 1,
833 * fs-writeback will release the dirty pages without page lock
834 * whose offset are over inode size, the release happens at
835 * block_write_full_page().
837 i_size_write(inode
, abs_to
);
838 inode
->i_blocks
= ocfs2_inode_sector_count(inode
);
839 di
->i_size
= cpu_to_le64((u64
)i_size_read(inode
));
840 inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
841 di
->i_mtime
= di
->i_ctime
= cpu_to_le64(inode
->i_mtime
.tv_sec
);
842 di
->i_ctime_nsec
= cpu_to_le32(inode
->i_mtime
.tv_nsec
);
843 di
->i_mtime_nsec
= di
->i_ctime_nsec
;
845 ocfs2_journal_dirty(handle
, di_bh
);
846 ocfs2_update_inode_fsync_trans(handle
, inode
, 1);
851 page_cache_release(page
);
854 ocfs2_commit_trans(OCFS2_SB(inode
->i_sb
), handle
);
860 * Find the next range to zero. We do this in terms of bytes because
861 * that's what ocfs2_zero_extend() wants, and it is dealing with the
862 * pagecache. We may return multiple extents.
864 * zero_start and zero_end are ocfs2_zero_extend()s current idea of what
865 * needs to be zeroed. range_start and range_end return the next zeroing
866 * range. A subsequent call should pass the previous range_end as its
867 * zero_start. If range_end is 0, there's nothing to do.
869 * Unwritten extents are skipped over. Refcounted extents are CoWd.
871 static int ocfs2_zero_extend_get_range(struct inode
*inode
,
872 struct buffer_head
*di_bh
,
873 u64 zero_start
, u64 zero_end
,
874 u64
*range_start
, u64
*range_end
)
876 int rc
= 0, needs_cow
= 0;
877 u32 p_cpos
, zero_clusters
= 0;
879 zero_start
>> OCFS2_SB(inode
->i_sb
)->s_clustersize_bits
;
880 u32 last_cpos
= ocfs2_clusters_for_bytes(inode
->i_sb
, zero_end
);
881 unsigned int num_clusters
= 0;
882 unsigned int ext_flags
= 0;
884 while (zero_cpos
< last_cpos
) {
885 rc
= ocfs2_get_clusters(inode
, zero_cpos
, &p_cpos
,
886 &num_clusters
, &ext_flags
);
892 if (p_cpos
&& !(ext_flags
& OCFS2_EXT_UNWRITTEN
)) {
893 zero_clusters
= num_clusters
;
894 if (ext_flags
& OCFS2_EXT_REFCOUNTED
)
899 zero_cpos
+= num_clusters
;
901 if (!zero_clusters
) {
906 while ((zero_cpos
+ zero_clusters
) < last_cpos
) {
907 rc
= ocfs2_get_clusters(inode
, zero_cpos
+ zero_clusters
,
908 &p_cpos
, &num_clusters
,
915 if (!p_cpos
|| (ext_flags
& OCFS2_EXT_UNWRITTEN
))
917 if (ext_flags
& OCFS2_EXT_REFCOUNTED
)
919 zero_clusters
+= num_clusters
;
921 if ((zero_cpos
+ zero_clusters
) > last_cpos
)
922 zero_clusters
= last_cpos
- zero_cpos
;
925 rc
= ocfs2_refcount_cow(inode
, di_bh
, zero_cpos
,
926 zero_clusters
, UINT_MAX
);
933 *range_start
= ocfs2_clusters_to_bytes(inode
->i_sb
, zero_cpos
);
934 *range_end
= ocfs2_clusters_to_bytes(inode
->i_sb
,
935 zero_cpos
+ zero_clusters
);
942 * Zero one range returned from ocfs2_zero_extend_get_range(). The caller
943 * has made sure that the entire range needs zeroing.
945 static int ocfs2_zero_extend_range(struct inode
*inode
, u64 range_start
,
946 u64 range_end
, struct buffer_head
*di_bh
)
950 u64 zero_pos
= range_start
;
952 trace_ocfs2_zero_extend_range(
953 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
954 (unsigned long long)range_start
,
955 (unsigned long long)range_end
);
956 BUG_ON(range_start
>= range_end
);
958 while (zero_pos
< range_end
) {
959 next_pos
= (zero_pos
& PAGE_CACHE_MASK
) + PAGE_CACHE_SIZE
;
960 if (next_pos
> range_end
)
961 next_pos
= range_end
;
962 rc
= ocfs2_write_zero_page(inode
, zero_pos
, next_pos
, di_bh
);
970 * Very large extends have the potential to lock up
971 * the cpu for extended periods of time.
979 int ocfs2_zero_extend(struct inode
*inode
, struct buffer_head
*di_bh
,
983 u64 zero_start
, range_start
= 0, range_end
= 0;
984 struct super_block
*sb
= inode
->i_sb
;
986 zero_start
= ocfs2_align_bytes_to_blocks(sb
, i_size_read(inode
));
987 trace_ocfs2_zero_extend((unsigned long long)OCFS2_I(inode
)->ip_blkno
,
988 (unsigned long long)zero_start
,
989 (unsigned long long)i_size_read(inode
));
990 while (zero_start
< zero_to_size
) {
991 ret
= ocfs2_zero_extend_get_range(inode
, di_bh
, zero_start
,
1002 if (range_start
< zero_start
)
1003 range_start
= zero_start
;
1004 if (range_end
> zero_to_size
)
1005 range_end
= zero_to_size
;
1007 ret
= ocfs2_zero_extend_range(inode
, range_start
,
1013 zero_start
= range_end
;
1019 int ocfs2_extend_no_holes(struct inode
*inode
, struct buffer_head
*di_bh
,
1020 u64 new_i_size
, u64 zero_to
)
1023 u32 clusters_to_add
;
1024 struct ocfs2_inode_info
*oi
= OCFS2_I(inode
);
1027 * Only quota files call this without a bh, and they can't be
1030 BUG_ON(!di_bh
&& (oi
->ip_dyn_features
& OCFS2_HAS_REFCOUNT_FL
));
1031 BUG_ON(!di_bh
&& !(oi
->ip_flags
& OCFS2_INODE_SYSTEM_FILE
));
1033 clusters_to_add
= ocfs2_clusters_for_bytes(inode
->i_sb
, new_i_size
);
1034 if (clusters_to_add
< oi
->ip_clusters
)
1035 clusters_to_add
= 0;
1037 clusters_to_add
-= oi
->ip_clusters
;
1039 if (clusters_to_add
) {
1040 ret
= __ocfs2_extend_allocation(inode
, oi
->ip_clusters
,
1041 clusters_to_add
, 0);
1049 * Call this even if we don't add any clusters to the tree. We
1050 * still need to zero the area between the old i_size and the
1053 ret
= ocfs2_zero_extend(inode
, di_bh
, zero_to
);
1061 static int ocfs2_extend_file(struct inode
*inode
,
1062 struct buffer_head
*di_bh
,
1066 struct ocfs2_inode_info
*oi
= OCFS2_I(inode
);
1070 /* setattr sometimes calls us like this. */
1071 if (new_i_size
== 0)
1074 if (i_size_read(inode
) == new_i_size
)
1076 BUG_ON(new_i_size
< i_size_read(inode
));
1079 * The alloc sem blocks people in read/write from reading our
1080 * allocation until we're done changing it. We depend on
1081 * i_mutex to block other extend/truncate calls while we're
1082 * here. We even have to hold it for sparse files because there
1083 * might be some tail zeroing.
1085 down_write(&oi
->ip_alloc_sem
);
1087 if (oi
->ip_dyn_features
& OCFS2_INLINE_DATA_FL
) {
1089 * We can optimize small extends by keeping the inodes
1092 if (ocfs2_size_fits_inline_data(di_bh
, new_i_size
)) {
1093 up_write(&oi
->ip_alloc_sem
);
1094 goto out_update_size
;
1097 ret
= ocfs2_convert_inline_data_to_extents(inode
, di_bh
);
1099 up_write(&oi
->ip_alloc_sem
);
1105 if (ocfs2_sparse_alloc(OCFS2_SB(inode
->i_sb
)))
1106 ret
= ocfs2_zero_extend(inode
, di_bh
, new_i_size
);
1108 ret
= ocfs2_extend_no_holes(inode
, di_bh
, new_i_size
,
1111 up_write(&oi
->ip_alloc_sem
);
1119 ret
= ocfs2_simple_size_update(inode
, di_bh
, new_i_size
);
1127 int ocfs2_setattr(struct dentry
*dentry
, struct iattr
*attr
)
1129 int status
= 0, size_change
;
1130 struct inode
*inode
= d_inode(dentry
);
1131 struct super_block
*sb
= inode
->i_sb
;
1132 struct ocfs2_super
*osb
= OCFS2_SB(sb
);
1133 struct buffer_head
*bh
= NULL
;
1134 handle_t
*handle
= NULL
;
1135 struct dquot
*transfer_to
[MAXQUOTAS
] = { };
1138 trace_ocfs2_setattr(inode
, dentry
,
1139 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
1140 dentry
->d_name
.len
, dentry
->d_name
.name
,
1141 attr
->ia_valid
, attr
->ia_mode
,
1142 from_kuid(&init_user_ns
, attr
->ia_uid
),
1143 from_kgid(&init_user_ns
, attr
->ia_gid
));
1145 /* ensuring we don't even attempt to truncate a symlink */
1146 if (S_ISLNK(inode
->i_mode
))
1147 attr
->ia_valid
&= ~ATTR_SIZE
;
1149 #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
1150 | ATTR_GID | ATTR_UID | ATTR_MODE)
1151 if (!(attr
->ia_valid
& OCFS2_VALID_ATTRS
))
1154 status
= inode_change_ok(inode
, attr
);
1158 if (is_quota_modification(inode
, attr
))
1159 dquot_initialize(inode
);
1160 size_change
= S_ISREG(inode
->i_mode
) && attr
->ia_valid
& ATTR_SIZE
;
1162 status
= ocfs2_rw_lock(inode
, 1);
1169 status
= ocfs2_inode_lock(inode
, &bh
, 1);
1171 if (status
!= -ENOENT
)
1173 goto bail_unlock_rw
;
1177 status
= inode_newsize_ok(inode
, attr
->ia_size
);
1181 inode_dio_wait(inode
);
1183 if (i_size_read(inode
) >= attr
->ia_size
) {
1184 if (ocfs2_should_order_data(inode
)) {
1185 status
= ocfs2_begin_ordered_truncate(inode
,
1190 status
= ocfs2_truncate_file(inode
, bh
, attr
->ia_size
);
1192 status
= ocfs2_extend_file(inode
, bh
, attr
->ia_size
);
1194 if (status
!= -ENOSPC
)
1201 if ((attr
->ia_valid
& ATTR_UID
&& !uid_eq(attr
->ia_uid
, inode
->i_uid
)) ||
1202 (attr
->ia_valid
& ATTR_GID
&& !gid_eq(attr
->ia_gid
, inode
->i_gid
))) {
1204 * Gather pointers to quota structures so that allocation /
1205 * freeing of quota structures happens here and not inside
1206 * dquot_transfer() where we have problems with lock ordering
1208 if (attr
->ia_valid
& ATTR_UID
&& !uid_eq(attr
->ia_uid
, inode
->i_uid
)
1209 && OCFS2_HAS_RO_COMPAT_FEATURE(sb
,
1210 OCFS2_FEATURE_RO_COMPAT_USRQUOTA
)) {
1211 transfer_to
[USRQUOTA
] = dqget(sb
, make_kqid_uid(attr
->ia_uid
));
1212 if (!transfer_to
[USRQUOTA
]) {
1217 if (attr
->ia_valid
& ATTR_GID
&& !gid_eq(attr
->ia_gid
, inode
->i_gid
)
1218 && OCFS2_HAS_RO_COMPAT_FEATURE(sb
,
1219 OCFS2_FEATURE_RO_COMPAT_GRPQUOTA
)) {
1220 transfer_to
[GRPQUOTA
] = dqget(sb
, make_kqid_gid(attr
->ia_gid
));
1221 if (!transfer_to
[GRPQUOTA
]) {
1226 handle
= ocfs2_start_trans(osb
, OCFS2_INODE_UPDATE_CREDITS
+
1227 2 * ocfs2_quota_trans_credits(sb
));
1228 if (IS_ERR(handle
)) {
1229 status
= PTR_ERR(handle
);
1233 status
= __dquot_transfer(inode
, transfer_to
);
1237 handle
= ocfs2_start_trans(osb
, OCFS2_INODE_UPDATE_CREDITS
);
1238 if (IS_ERR(handle
)) {
1239 status
= PTR_ERR(handle
);
1245 setattr_copy(inode
, attr
);
1246 mark_inode_dirty(inode
);
1248 status
= ocfs2_mark_inode_dirty(handle
, inode
, bh
);
1253 ocfs2_commit_trans(osb
, handle
);
1255 ocfs2_inode_unlock(inode
, 1);
1258 ocfs2_rw_unlock(inode
, 1);
1262 /* Release quota pointers in case we acquired them */
1263 for (qtype
= 0; qtype
< OCFS2_MAXQUOTAS
; qtype
++)
1264 dqput(transfer_to
[qtype
]);
1266 if (!status
&& attr
->ia_valid
& ATTR_MODE
) {
1267 status
= posix_acl_chmod(inode
, inode
->i_mode
);
1275 int ocfs2_getattr(struct vfsmount
*mnt
,
1276 struct dentry
*dentry
,
1279 struct inode
*inode
= d_inode(dentry
);
1280 struct super_block
*sb
= d_inode(dentry
)->i_sb
;
1281 struct ocfs2_super
*osb
= sb
->s_fs_info
;
1284 err
= ocfs2_inode_revalidate(dentry
);
1291 generic_fillattr(inode
, stat
);
1293 /* We set the blksize from the cluster size for performance */
1294 stat
->blksize
= osb
->s_clustersize
;
1300 int ocfs2_permission(struct inode
*inode
, int mask
)
1304 if (mask
& MAY_NOT_BLOCK
)
1307 ret
= ocfs2_inode_lock(inode
, NULL
, 0);
1314 ret
= generic_permission(inode
, mask
);
1316 ocfs2_inode_unlock(inode
, 0);
1321 static int __ocfs2_write_remove_suid(struct inode
*inode
,
1322 struct buffer_head
*bh
)
1326 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
1327 struct ocfs2_dinode
*di
;
1329 trace_ocfs2_write_remove_suid(
1330 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
1333 handle
= ocfs2_start_trans(osb
, OCFS2_INODE_UPDATE_CREDITS
);
1334 if (IS_ERR(handle
)) {
1335 ret
= PTR_ERR(handle
);
1340 ret
= ocfs2_journal_access_di(handle
, INODE_CACHE(inode
), bh
,
1341 OCFS2_JOURNAL_ACCESS_WRITE
);
1347 inode
->i_mode
&= ~S_ISUID
;
1348 if ((inode
->i_mode
& S_ISGID
) && (inode
->i_mode
& S_IXGRP
))
1349 inode
->i_mode
&= ~S_ISGID
;
1351 di
= (struct ocfs2_dinode
*) bh
->b_data
;
1352 di
->i_mode
= cpu_to_le16(inode
->i_mode
);
1353 ocfs2_update_inode_fsync_trans(handle
, inode
, 0);
1355 ocfs2_journal_dirty(handle
, bh
);
1358 ocfs2_commit_trans(osb
, handle
);
1364 * Will look for holes and unwritten extents in the range starting at
1365 * pos for count bytes (inclusive).
1367 static int ocfs2_check_range_for_holes(struct inode
*inode
, loff_t pos
,
1371 unsigned int extent_flags
;
1372 u32 cpos
, clusters
, extent_len
, phys_cpos
;
1373 struct super_block
*sb
= inode
->i_sb
;
1375 cpos
= pos
>> OCFS2_SB(sb
)->s_clustersize_bits
;
1376 clusters
= ocfs2_clusters_for_bytes(sb
, pos
+ count
) - cpos
;
1379 ret
= ocfs2_get_clusters(inode
, cpos
, &phys_cpos
, &extent_len
,
1386 if (phys_cpos
== 0 || (extent_flags
& OCFS2_EXT_UNWRITTEN
)) {
1391 if (extent_len
> clusters
)
1392 extent_len
= clusters
;
1394 clusters
-= extent_len
;
1401 static int ocfs2_write_remove_suid(struct inode
*inode
)
1404 struct buffer_head
*bh
= NULL
;
1406 ret
= ocfs2_read_inode_block(inode
, &bh
);
1412 ret
= __ocfs2_write_remove_suid(inode
, bh
);
1419 * Allocate enough extents to cover the region starting at byte offset
1420 * start for len bytes. Existing extents are skipped, any extents
1421 * added are marked as "unwritten".
1423 static int ocfs2_allocate_unwritten_extents(struct inode
*inode
,
1427 u32 cpos
, phys_cpos
, clusters
, alloc_size
;
1428 u64 end
= start
+ len
;
1429 struct buffer_head
*di_bh
= NULL
;
1431 if (OCFS2_I(inode
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
) {
1432 ret
= ocfs2_read_inode_block(inode
, &di_bh
);
1439 * Nothing to do if the requested reservation range
1440 * fits within the inode.
1442 if (ocfs2_size_fits_inline_data(di_bh
, end
))
1445 ret
= ocfs2_convert_inline_data_to_extents(inode
, di_bh
);
1453 * We consider both start and len to be inclusive.
1455 cpos
= start
>> OCFS2_SB(inode
->i_sb
)->s_clustersize_bits
;
1456 clusters
= ocfs2_clusters_for_bytes(inode
->i_sb
, start
+ len
);
1460 ret
= ocfs2_get_clusters(inode
, cpos
, &phys_cpos
,
1468 * Hole or existing extent len can be arbitrary, so
1469 * cap it to our own allocation request.
1471 if (alloc_size
> clusters
)
1472 alloc_size
= clusters
;
1476 * We already have an allocation at this
1477 * region so we can safely skip it.
1482 ret
= __ocfs2_extend_allocation(inode
, cpos
, alloc_size
, 1);
1491 clusters
-= alloc_size
;
1502 * Truncate a byte range, avoiding pages within partial clusters. This
1503 * preserves those pages for the zeroing code to write to.
1505 static void ocfs2_truncate_cluster_pages(struct inode
*inode
, u64 byte_start
,
1508 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
1510 struct address_space
*mapping
= inode
->i_mapping
;
1512 start
= (loff_t
)ocfs2_align_bytes_to_clusters(inode
->i_sb
, byte_start
);
1513 end
= byte_start
+ byte_len
;
1514 end
= end
& ~(osb
->s_clustersize
- 1);
1517 unmap_mapping_range(mapping
, start
, end
- start
, 0);
1518 truncate_inode_pages_range(mapping
, start
, end
- 1);
1522 static int ocfs2_zero_partial_clusters(struct inode
*inode
,
1526 u64 tmpend
, end
= start
+ len
;
1527 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
1528 unsigned int csize
= osb
->s_clustersize
;
1532 * The "start" and "end" values are NOT necessarily part of
1533 * the range whose allocation is being deleted. Rather, this
1534 * is what the user passed in with the request. We must zero
1535 * partial clusters here. There's no need to worry about
1536 * physical allocation - the zeroing code knows to skip holes.
1538 trace_ocfs2_zero_partial_clusters(
1539 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
1540 (unsigned long long)start
, (unsigned long long)end
);
1543 * If both edges are on a cluster boundary then there's no
1544 * zeroing required as the region is part of the allocation to
1547 if ((start
& (csize
- 1)) == 0 && (end
& (csize
- 1)) == 0)
1550 handle
= ocfs2_start_trans(osb
, OCFS2_INODE_UPDATE_CREDITS
);
1551 if (IS_ERR(handle
)) {
1552 ret
= PTR_ERR(handle
);
1558 * We want to get the byte offset of the end of the 1st cluster.
1560 tmpend
= (u64
)osb
->s_clustersize
+ (start
& ~(osb
->s_clustersize
- 1));
1564 trace_ocfs2_zero_partial_clusters_range1((unsigned long long)start
,
1565 (unsigned long long)tmpend
);
1567 ret
= ocfs2_zero_range_for_truncate(inode
, handle
, start
, tmpend
);
1573 * This may make start and end equal, but the zeroing
1574 * code will skip any work in that case so there's no
1575 * need to catch it up here.
1577 start
= end
& ~(osb
->s_clustersize
- 1);
1579 trace_ocfs2_zero_partial_clusters_range2(
1580 (unsigned long long)start
, (unsigned long long)end
);
1582 ret
= ocfs2_zero_range_for_truncate(inode
, handle
, start
, end
);
1586 ocfs2_update_inode_fsync_trans(handle
, inode
, 1);
1588 ocfs2_commit_trans(osb
, handle
);
1593 static int ocfs2_find_rec(struct ocfs2_extent_list
*el
, u32 pos
)
1596 struct ocfs2_extent_rec
*rec
= NULL
;
1598 for (i
= le16_to_cpu(el
->l_next_free_rec
) - 1; i
>= 0; i
--) {
1600 rec
= &el
->l_recs
[i
];
1602 if (le32_to_cpu(rec
->e_cpos
) < pos
)
1610 * Helper to calculate the punching pos and length in one run, we handle the
1611 * following three cases in order:
1613 * - remove the entire record
1614 * - remove a partial record
1615 * - no record needs to be removed (hole-punching completed)
1617 static void ocfs2_calc_trunc_pos(struct inode
*inode
,
1618 struct ocfs2_extent_list
*el
,
1619 struct ocfs2_extent_rec
*rec
,
1620 u32 trunc_start
, u32
*trunc_cpos
,
1621 u32
*trunc_len
, u32
*trunc_end
,
1622 u64
*blkno
, int *done
)
1627 range
= le32_to_cpu(rec
->e_cpos
) + ocfs2_rec_clusters(el
, rec
);
1629 if (le32_to_cpu(rec
->e_cpos
) >= trunc_start
) {
1631 * remove an entire extent record.
1633 *trunc_cpos
= le32_to_cpu(rec
->e_cpos
);
1635 * Skip holes if any.
1637 if (range
< *trunc_end
)
1639 *trunc_len
= *trunc_end
- le32_to_cpu(rec
->e_cpos
);
1640 *blkno
= le64_to_cpu(rec
->e_blkno
);
1641 *trunc_end
= le32_to_cpu(rec
->e_cpos
);
1642 } else if (range
> trunc_start
) {
1644 * remove a partial extent record, which means we're
1645 * removing the last extent record.
1647 *trunc_cpos
= trunc_start
;
1651 if (range
< *trunc_end
)
1653 *trunc_len
= *trunc_end
- trunc_start
;
1654 coff
= trunc_start
- le32_to_cpu(rec
->e_cpos
);
1655 *blkno
= le64_to_cpu(rec
->e_blkno
) +
1656 ocfs2_clusters_to_blocks(inode
->i_sb
, coff
);
1657 *trunc_end
= trunc_start
;
1660 * It may have two following possibilities:
1662 * - last record has been removed
1663 * - trunc_start was within a hole
1665 * both two cases mean the completion of hole punching.
1673 static int ocfs2_remove_inode_range(struct inode
*inode
,
1674 struct buffer_head
*di_bh
, u64 byte_start
,
1677 int ret
= 0, flags
= 0, done
= 0, i
;
1678 u32 trunc_start
, trunc_len
, trunc_end
, trunc_cpos
, phys_cpos
;
1680 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
1681 struct ocfs2_cached_dealloc_ctxt dealloc
;
1682 struct address_space
*mapping
= inode
->i_mapping
;
1683 struct ocfs2_extent_tree et
;
1684 struct ocfs2_path
*path
= NULL
;
1685 struct ocfs2_extent_list
*el
= NULL
;
1686 struct ocfs2_extent_rec
*rec
= NULL
;
1687 struct ocfs2_dinode
*di
= (struct ocfs2_dinode
*)di_bh
->b_data
;
1688 u64 blkno
, refcount_loc
= le64_to_cpu(di
->i_refcount_loc
);
1690 ocfs2_init_dinode_extent_tree(&et
, INODE_CACHE(inode
), di_bh
);
1691 ocfs2_init_dealloc_ctxt(&dealloc
);
1693 trace_ocfs2_remove_inode_range(
1694 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
1695 (unsigned long long)byte_start
,
1696 (unsigned long long)byte_len
);
1701 if (OCFS2_I(inode
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
) {
1702 ret
= ocfs2_truncate_inline(inode
, di_bh
, byte_start
,
1703 byte_start
+ byte_len
, 0);
1709 * There's no need to get fancy with the page cache
1710 * truncate of an inline-data inode. We're talking
1711 * about less than a page here, which will be cached
1712 * in the dinode buffer anyway.
1714 unmap_mapping_range(mapping
, 0, 0, 0);
1715 truncate_inode_pages(mapping
, 0);
1720 * For reflinks, we may need to CoW 2 clusters which might be
1721 * partially zero'd later, if hole's start and end offset were
1722 * within one cluster(means is not exactly aligned to clustersize).
1725 if (OCFS2_I(inode
)->ip_dyn_features
& OCFS2_HAS_REFCOUNT_FL
) {
1727 ret
= ocfs2_cow_file_pos(inode
, di_bh
, byte_start
);
1733 ret
= ocfs2_cow_file_pos(inode
, di_bh
, byte_start
+ byte_len
);
1740 trunc_start
= ocfs2_clusters_for_bytes(osb
->sb
, byte_start
);
1741 trunc_end
= (byte_start
+ byte_len
) >> osb
->s_clustersize_bits
;
1742 cluster_in_el
= trunc_end
;
1744 ret
= ocfs2_zero_partial_clusters(inode
, byte_start
, byte_len
);
1750 path
= ocfs2_new_path_from_et(&et
);
1757 while (trunc_end
> trunc_start
) {
1759 ret
= ocfs2_find_path(INODE_CACHE(inode
), path
,
1766 el
= path_leaf_el(path
);
1768 i
= ocfs2_find_rec(el
, trunc_end
);
1770 * Need to go to previous extent block.
1773 if (path
->p_tree_depth
== 0)
1776 ret
= ocfs2_find_cpos_for_left_leaf(inode
->i_sb
,
1785 * We've reached the leftmost extent block,
1786 * it's safe to leave.
1788 if (cluster_in_el
== 0)
1792 * The 'pos' searched for previous extent block is
1793 * always one cluster less than actual trunc_end.
1795 trunc_end
= cluster_in_el
+ 1;
1797 ocfs2_reinit_path(path
, 1);
1802 rec
= &el
->l_recs
[i
];
1804 ocfs2_calc_trunc_pos(inode
, el
, rec
, trunc_start
, &trunc_cpos
,
1805 &trunc_len
, &trunc_end
, &blkno
, &done
);
1809 flags
= rec
->e_flags
;
1810 phys_cpos
= ocfs2_blocks_to_clusters(inode
->i_sb
, blkno
);
1812 ret
= ocfs2_remove_btree_range(inode
, &et
, trunc_cpos
,
1813 phys_cpos
, trunc_len
, flags
,
1814 &dealloc
, refcount_loc
, false);
1820 cluster_in_el
= trunc_end
;
1822 ocfs2_reinit_path(path
, 1);
1825 ocfs2_truncate_cluster_pages(inode
, byte_start
, byte_len
);
1828 ocfs2_free_path(path
);
1829 ocfs2_schedule_truncate_log_flush(osb
, 1);
1830 ocfs2_run_deallocs(osb
, &dealloc
);
1836 * Parts of this function taken from xfs_change_file_space()
1838 static int __ocfs2_change_file_space(struct file
*file
, struct inode
*inode
,
1839 loff_t f_pos
, unsigned int cmd
,
1840 struct ocfs2_space_resv
*sr
,
1846 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
1847 struct buffer_head
*di_bh
= NULL
;
1849 unsigned long long max_off
= inode
->i_sb
->s_maxbytes
;
1851 if (ocfs2_is_hard_readonly(osb
) || ocfs2_is_soft_readonly(osb
))
1854 mutex_lock(&inode
->i_mutex
);
1857 * This prevents concurrent writes on other nodes
1859 ret
= ocfs2_rw_lock(inode
, 1);
1865 ret
= ocfs2_inode_lock(inode
, &di_bh
, 1);
1871 if (inode
->i_flags
& (S_IMMUTABLE
|S_APPEND
)) {
1873 goto out_inode_unlock
;
1876 switch (sr
->l_whence
) {
1877 case 0: /*SEEK_SET*/
1879 case 1: /*SEEK_CUR*/
1880 sr
->l_start
+= f_pos
;
1882 case 2: /*SEEK_END*/
1883 sr
->l_start
+= i_size_read(inode
);
1887 goto out_inode_unlock
;
1891 llen
= sr
->l_len
> 0 ? sr
->l_len
- 1 : sr
->l_len
;
1894 || sr
->l_start
> max_off
1895 || (sr
->l_start
+ llen
) < 0
1896 || (sr
->l_start
+ llen
) > max_off
) {
1898 goto out_inode_unlock
;
1900 size
= sr
->l_start
+ sr
->l_len
;
1902 if (cmd
== OCFS2_IOC_RESVSP
|| cmd
== OCFS2_IOC_RESVSP64
||
1903 cmd
== OCFS2_IOC_UNRESVSP
|| cmd
== OCFS2_IOC_UNRESVSP64
) {
1904 if (sr
->l_len
<= 0) {
1906 goto out_inode_unlock
;
1910 if (file
&& should_remove_suid(file
->f_path
.dentry
)) {
1911 ret
= __ocfs2_write_remove_suid(inode
, di_bh
);
1914 goto out_inode_unlock
;
1918 down_write(&OCFS2_I(inode
)->ip_alloc_sem
);
1920 case OCFS2_IOC_RESVSP
:
1921 case OCFS2_IOC_RESVSP64
:
1923 * This takes unsigned offsets, but the signed ones we
1924 * pass have been checked against overflow above.
1926 ret
= ocfs2_allocate_unwritten_extents(inode
, sr
->l_start
,
1929 case OCFS2_IOC_UNRESVSP
:
1930 case OCFS2_IOC_UNRESVSP64
:
1931 ret
= ocfs2_remove_inode_range(inode
, di_bh
, sr
->l_start
,
1937 up_write(&OCFS2_I(inode
)->ip_alloc_sem
);
1940 goto out_inode_unlock
;
1944 * We update c/mtime for these changes
1946 handle
= ocfs2_start_trans(osb
, OCFS2_INODE_UPDATE_CREDITS
);
1947 if (IS_ERR(handle
)) {
1948 ret
= PTR_ERR(handle
);
1950 goto out_inode_unlock
;
1953 if (change_size
&& i_size_read(inode
) < size
)
1954 i_size_write(inode
, size
);
1956 inode
->i_ctime
= inode
->i_mtime
= CURRENT_TIME
;
1957 ret
= ocfs2_mark_inode_dirty(handle
, inode
, di_bh
);
1961 if (file
&& (file
->f_flags
& O_SYNC
))
1964 ocfs2_commit_trans(osb
, handle
);
1968 ocfs2_inode_unlock(inode
, 1);
1970 ocfs2_rw_unlock(inode
, 1);
1973 mutex_unlock(&inode
->i_mutex
);
1977 int ocfs2_change_file_space(struct file
*file
, unsigned int cmd
,
1978 struct ocfs2_space_resv
*sr
)
1980 struct inode
*inode
= file_inode(file
);
1981 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
1984 if ((cmd
== OCFS2_IOC_RESVSP
|| cmd
== OCFS2_IOC_RESVSP64
) &&
1985 !ocfs2_writes_unwritten_extents(osb
))
1987 else if ((cmd
== OCFS2_IOC_UNRESVSP
|| cmd
== OCFS2_IOC_UNRESVSP64
) &&
1988 !ocfs2_sparse_alloc(osb
))
1991 if (!S_ISREG(inode
->i_mode
))
1994 if (!(file
->f_mode
& FMODE_WRITE
))
1997 ret
= mnt_want_write_file(file
);
2000 ret
= __ocfs2_change_file_space(file
, inode
, file
->f_pos
, cmd
, sr
, 0);
2001 mnt_drop_write_file(file
);
2005 static long ocfs2_fallocate(struct file
*file
, int mode
, loff_t offset
,
2008 struct inode
*inode
= file_inode(file
);
2009 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
2010 struct ocfs2_space_resv sr
;
2011 int change_size
= 1;
2012 int cmd
= OCFS2_IOC_RESVSP64
;
2014 if (mode
& ~(FALLOC_FL_KEEP_SIZE
| FALLOC_FL_PUNCH_HOLE
))
2016 if (!ocfs2_writes_unwritten_extents(osb
))
2019 if (mode
& FALLOC_FL_KEEP_SIZE
)
2022 if (mode
& FALLOC_FL_PUNCH_HOLE
)
2023 cmd
= OCFS2_IOC_UNRESVSP64
;
2026 sr
.l_start
= (s64
)offset
;
2027 sr
.l_len
= (s64
)len
;
2029 return __ocfs2_change_file_space(NULL
, inode
, offset
, cmd
, &sr
,
2033 int ocfs2_check_range_for_refcount(struct inode
*inode
, loff_t pos
,
2037 unsigned int extent_flags
;
2038 u32 cpos
, clusters
, extent_len
, phys_cpos
;
2039 struct super_block
*sb
= inode
->i_sb
;
2041 if (!ocfs2_refcount_tree(OCFS2_SB(inode
->i_sb
)) ||
2042 !(OCFS2_I(inode
)->ip_dyn_features
& OCFS2_HAS_REFCOUNT_FL
) ||
2043 OCFS2_I(inode
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
)
2046 cpos
= pos
>> OCFS2_SB(sb
)->s_clustersize_bits
;
2047 clusters
= ocfs2_clusters_for_bytes(sb
, pos
+ count
) - cpos
;
2050 ret
= ocfs2_get_clusters(inode
, cpos
, &phys_cpos
, &extent_len
,
2057 if (phys_cpos
&& (extent_flags
& OCFS2_EXT_REFCOUNTED
)) {
2062 if (extent_len
> clusters
)
2063 extent_len
= clusters
;
2065 clusters
-= extent_len
;
2072 static int ocfs2_is_io_unaligned(struct inode
*inode
, size_t count
, loff_t pos
)
2074 int blockmask
= inode
->i_sb
->s_blocksize
- 1;
2075 loff_t final_size
= pos
+ count
;
2077 if ((pos
& blockmask
) || (final_size
& blockmask
))
2082 static int ocfs2_prepare_inode_for_refcount(struct inode
*inode
,
2084 loff_t pos
, size_t count
,
2088 struct buffer_head
*di_bh
= NULL
;
2089 u32 cpos
= pos
>> OCFS2_SB(inode
->i_sb
)->s_clustersize_bits
;
2091 ocfs2_clusters_for_bytes(inode
->i_sb
, pos
+ count
) - cpos
;
2093 ret
= ocfs2_inode_lock(inode
, &di_bh
, 1);
2101 ret
= ocfs2_refcount_cow(inode
, di_bh
, cpos
, clusters
, UINT_MAX
);
2109 static int ocfs2_prepare_inode_for_write(struct file
*file
,
2116 int ret
= 0, meta_level
= 0;
2117 struct dentry
*dentry
= file
->f_path
.dentry
;
2118 struct inode
*inode
= d_inode(dentry
);
2120 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
2121 int full_coherency
= !(osb
->s_mount_opt
&
2122 OCFS2_MOUNT_COHERENCY_BUFFERED
);
2125 * We start with a read level meta lock and only jump to an ex
2126 * if we need to make modifications here.
2129 ret
= ocfs2_inode_lock(inode
, NULL
, meta_level
);
2136 /* Clear suid / sgid if necessary. We do this here
2137 * instead of later in the write path because
2138 * remove_suid() calls ->setattr without any hint that
2139 * we may have already done our cluster locking. Since
2140 * ocfs2_setattr() *must* take cluster locks to
2141 * proceed, this will lead us to recursively lock the
2142 * inode. There's also the dinode i_size state which
2143 * can be lost via setattr during extending writes (we
2144 * set inode->i_size at the end of a write. */
2145 if (should_remove_suid(dentry
)) {
2146 if (meta_level
== 0) {
2147 ocfs2_inode_unlock(inode
, meta_level
);
2152 ret
= ocfs2_write_remove_suid(inode
);
2161 ret
= ocfs2_check_range_for_refcount(inode
, pos
, count
);
2163 ocfs2_inode_unlock(inode
, meta_level
);
2166 ret
= ocfs2_prepare_inode_for_refcount(inode
,
2183 * Skip the O_DIRECT checks if we don't need
2186 if (!direct_io
|| !(*direct_io
))
2190 * There's no sane way to do direct writes to an inode
2193 if (OCFS2_I(inode
)->ip_dyn_features
& OCFS2_INLINE_DATA_FL
) {
2199 * Allowing concurrent direct writes means
2200 * i_size changes wouldn't be synchronized, so
2201 * one node could wind up truncating another
2204 if (end
> i_size_read(inode
) && !full_coherency
) {
2210 * Fallback to old way if the feature bit is not set.
2212 if (end
> i_size_read(inode
) &&
2213 !ocfs2_supports_append_dio(osb
)) {
2219 * We don't fill holes during direct io, so
2220 * check for them here. If any are found, the
2221 * caller will have to retake some cluster
2222 * locks and initiate the io as buffered.
2224 ret
= ocfs2_check_range_for_holes(inode
, pos
, count
);
2227 * Fallback to old way if the feature bit is not set.
2228 * Otherwise try dio first and then complete the rest
2229 * request through buffer io.
2231 if (!ocfs2_supports_append_dio(osb
))
2240 trace_ocfs2_prepare_inode_for_write(OCFS2_I(inode
)->ip_blkno
,
2241 pos
, appending
, count
,
2242 direct_io
, has_refcount
);
2244 if (meta_level
>= 0)
2245 ocfs2_inode_unlock(inode
, meta_level
);
2251 static ssize_t
ocfs2_file_write_iter(struct kiocb
*iocb
,
2252 struct iov_iter
*from
)
2254 int direct_io
, appending
, rw_level
;
2255 int can_do_direct
, has_refcount
= 0;
2256 ssize_t written
= 0;
2258 size_t count
= iov_iter_count(from
), orig_count
;
2261 struct file
*file
= iocb
->ki_filp
;
2262 struct inode
*inode
= file_inode(file
);
2263 struct ocfs2_super
*osb
= OCFS2_SB(inode
->i_sb
);
2264 int full_coherency
= !(osb
->s_mount_opt
&
2265 OCFS2_MOUNT_COHERENCY_BUFFERED
);
2266 int unaligned_dio
= 0;
2267 int dropped_dio
= 0;
2269 trace_ocfs2_file_aio_write(inode
, file
, file
->f_path
.dentry
,
2270 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
2271 file
->f_path
.dentry
->d_name
.len
,
2272 file
->f_path
.dentry
->d_name
.name
,
2273 (unsigned int)from
->nr_segs
); /* GRRRRR */
2278 appending
= iocb
->ki_flags
& IOCB_APPEND
? 1 : 0;
2279 direct_io
= iocb
->ki_flags
& IOCB_DIRECT
? 1 : 0;
2281 mutex_lock(&inode
->i_mutex
);
2285 * Concurrent O_DIRECT writes are allowed with
2286 * mount_option "coherency=buffered".
2288 rw_level
= (!direct_io
|| full_coherency
);
2290 ret
= ocfs2_rw_lock(inode
, rw_level
);
2297 * O_DIRECT writes with "coherency=full" need to take EX cluster
2298 * inode_lock to guarantee coherency.
2300 if (direct_io
&& full_coherency
) {
2302 * We need to take and drop the inode lock to force
2303 * other nodes to drop their caches. Buffered I/O
2304 * already does this in write_begin().
2306 ret
= ocfs2_inode_lock(inode
, NULL
, 1);
2312 ocfs2_inode_unlock(inode
, 1);
2315 orig_count
= iov_iter_count(from
);
2316 ret
= generic_write_checks(iocb
, from
);
2324 can_do_direct
= direct_io
;
2325 ret
= ocfs2_prepare_inode_for_write(file
, iocb
->ki_pos
, count
, appending
,
2326 &can_do_direct
, &has_refcount
);
2332 if (direct_io
&& !is_sync_kiocb(iocb
))
2333 unaligned_dio
= ocfs2_is_io_unaligned(inode
, count
, iocb
->ki_pos
);
2336 * We can't complete the direct I/O as requested, fall back to
2339 if (direct_io
&& !can_do_direct
) {
2340 ocfs2_rw_unlock(inode
, rw_level
);
2345 iocb
->ki_flags
&= ~IOCB_DIRECT
;
2346 iov_iter_reexpand(from
, orig_count
);
2351 if (unaligned_dio
) {
2353 * Wait on previous unaligned aio to complete before
2356 mutex_lock(&OCFS2_I(inode
)->ip_unaligned_aio
);
2357 /* Mark the iocb as needing an unlock in ocfs2_dio_end_io */
2358 ocfs2_iocb_set_unaligned_aio(iocb
);
2362 * To later detect whether a journal commit for sync writes is
2363 * necessary, we sample i_size, and cluster count here.
2365 old_size
= i_size_read(inode
);
2366 old_clusters
= OCFS2_I(inode
)->ip_clusters
;
2368 /* communicate with ocfs2_dio_end_io */
2369 ocfs2_iocb_set_rw_locked(iocb
, rw_level
);
2371 written
= __generic_file_write_iter(iocb
, from
);
2372 /* buffered aio wouldn't have proper lock coverage today */
2373 BUG_ON(written
== -EIOCBQUEUED
&& !(iocb
->ki_flags
& IOCB_DIRECT
));
2376 * deep in g_f_a_w_n()->ocfs2_direct_IO we pass in a ocfs2_dio_end_io
2377 * function pointer which is called when o_direct io completes so that
2378 * it can unlock our rw lock.
2379 * Unfortunately there are error cases which call end_io and others
2380 * that don't. so we don't have to unlock the rw_lock if either an
2381 * async dio is going to do it in the future or an end_io after an
2382 * error has already done it.
2384 if ((written
== -EIOCBQUEUED
) || (!ocfs2_iocb_is_rw_locked(iocb
))) {
2389 if (unlikely(written
<= 0))
2392 if (((file
->f_flags
& O_DSYNC
) && !direct_io
) ||
2393 IS_SYNC(inode
) || dropped_dio
) {
2394 ret
= filemap_fdatawrite_range(file
->f_mapping
,
2395 iocb
->ki_pos
- written
,
2401 ret
= jbd2_journal_force_commit(osb
->journal
->j_journal
);
2407 ret
= filemap_fdatawait_range(file
->f_mapping
,
2408 iocb
->ki_pos
- written
,
2413 if (unaligned_dio
) {
2414 ocfs2_iocb_clear_unaligned_aio(iocb
);
2415 mutex_unlock(&OCFS2_I(inode
)->ip_unaligned_aio
);
2420 ocfs2_rw_unlock(inode
, rw_level
);
2423 mutex_unlock(&inode
->i_mutex
);
2430 static ssize_t
ocfs2_file_splice_read(struct file
*in
,
2432 struct pipe_inode_info
*pipe
,
2436 int ret
= 0, lock_level
= 0;
2437 struct inode
*inode
= file_inode(in
);
2439 trace_ocfs2_file_splice_read(inode
, in
, in
->f_path
.dentry
,
2440 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
2441 in
->f_path
.dentry
->d_name
.len
,
2442 in
->f_path
.dentry
->d_name
.name
, len
);
2445 * See the comment in ocfs2_file_read_iter()
2447 ret
= ocfs2_inode_lock_atime(inode
, in
->f_path
.mnt
, &lock_level
);
2452 ocfs2_inode_unlock(inode
, lock_level
);
2454 ret
= generic_file_splice_read(in
, ppos
, pipe
, len
, flags
);
2460 static ssize_t
ocfs2_file_read_iter(struct kiocb
*iocb
,
2461 struct iov_iter
*to
)
2463 int ret
= 0, rw_level
= -1, lock_level
= 0;
2464 struct file
*filp
= iocb
->ki_filp
;
2465 struct inode
*inode
= file_inode(filp
);
2467 trace_ocfs2_file_aio_read(inode
, filp
, filp
->f_path
.dentry
,
2468 (unsigned long long)OCFS2_I(inode
)->ip_blkno
,
2469 filp
->f_path
.dentry
->d_name
.len
,
2470 filp
->f_path
.dentry
->d_name
.name
,
2471 to
->nr_segs
); /* GRRRRR */
2481 * buffered reads protect themselves in ->readpage(). O_DIRECT reads
2482 * need locks to protect pending reads from racing with truncate.
2484 if (iocb
->ki_flags
& IOCB_DIRECT
) {
2485 ret
= ocfs2_rw_lock(inode
, 0);
2491 /* communicate with ocfs2_dio_end_io */
2492 ocfs2_iocb_set_rw_locked(iocb
, rw_level
);
2496 * We're fine letting folks race truncates and extending
2497 * writes with read across the cluster, just like they can
2498 * locally. Hence no rw_lock during read.
2500 * Take and drop the meta data lock to update inode fields
2501 * like i_size. This allows the checks down below
2502 * generic_file_aio_read() a chance of actually working.
2504 ret
= ocfs2_inode_lock_atime(inode
, filp
->f_path
.mnt
, &lock_level
);
2509 ocfs2_inode_unlock(inode
, lock_level
);
2511 ret
= generic_file_read_iter(iocb
, to
);
2512 trace_generic_file_aio_read_ret(ret
);
2514 /* buffered aio wouldn't have proper lock coverage today */
2515 BUG_ON(ret
== -EIOCBQUEUED
&& !(iocb
->ki_flags
& IOCB_DIRECT
));
2517 /* see ocfs2_file_write_iter */
2518 if (ret
== -EIOCBQUEUED
|| !ocfs2_iocb_is_rw_locked(iocb
)) {
2524 ocfs2_rw_unlock(inode
, rw_level
);
2529 /* Refer generic_file_llseek_unlocked() */
2530 static loff_t
ocfs2_file_llseek(struct file
*file
, loff_t offset
, int whence
)
2532 struct inode
*inode
= file
->f_mapping
->host
;
2535 mutex_lock(&inode
->i_mutex
);
2541 /* SEEK_END requires the OCFS2 inode lock for the file
2542 * because it references the file's size.
2544 ret
= ocfs2_inode_lock(inode
, NULL
, 0);
2549 offset
+= i_size_read(inode
);
2550 ocfs2_inode_unlock(inode
, 0);
2554 offset
= file
->f_pos
;
2557 offset
+= file
->f_pos
;
2561 ret
= ocfs2_seek_data_hole_offset(file
, &offset
, whence
);
2570 offset
= vfs_setpos(file
, offset
, inode
->i_sb
->s_maxbytes
);
2573 mutex_unlock(&inode
->i_mutex
);
2579 const struct inode_operations ocfs2_file_iops
= {
2580 .setattr
= ocfs2_setattr
,
2581 .getattr
= ocfs2_getattr
,
2582 .permission
= ocfs2_permission
,
2583 .setxattr
= generic_setxattr
,
2584 .getxattr
= generic_getxattr
,
2585 .listxattr
= ocfs2_listxattr
,
2586 .removexattr
= generic_removexattr
,
2587 .fiemap
= ocfs2_fiemap
,
2588 .get_acl
= ocfs2_iop_get_acl
,
2589 .set_acl
= ocfs2_iop_set_acl
,
2592 const struct inode_operations ocfs2_special_file_iops
= {
2593 .setattr
= ocfs2_setattr
,
2594 .getattr
= ocfs2_getattr
,
2595 .permission
= ocfs2_permission
,
2596 .get_acl
= ocfs2_iop_get_acl
,
2597 .set_acl
= ocfs2_iop_set_acl
,
2601 * Other than ->lock, keep ocfs2_fops and ocfs2_dops in sync with
2602 * ocfs2_fops_no_plocks and ocfs2_dops_no_plocks!
2604 const struct file_operations ocfs2_fops
= {
2605 .llseek
= ocfs2_file_llseek
,
2607 .fsync
= ocfs2_sync_file
,
2608 .release
= ocfs2_file_release
,
2609 .open
= ocfs2_file_open
,
2610 .read_iter
= ocfs2_file_read_iter
,
2611 .write_iter
= ocfs2_file_write_iter
,
2612 .unlocked_ioctl
= ocfs2_ioctl
,
2613 #ifdef CONFIG_COMPAT
2614 .compat_ioctl
= ocfs2_compat_ioctl
,
2617 .flock
= ocfs2_flock
,
2618 .splice_read
= ocfs2_file_splice_read
,
2619 .splice_write
= iter_file_splice_write
,
2620 .fallocate
= ocfs2_fallocate
,
2623 const struct file_operations ocfs2_dops
= {
2624 .llseek
= generic_file_llseek
,
2625 .read
= generic_read_dir
,
2626 .iterate
= ocfs2_readdir
,
2627 .fsync
= ocfs2_sync_file
,
2628 .release
= ocfs2_dir_release
,
2629 .open
= ocfs2_dir_open
,
2630 .unlocked_ioctl
= ocfs2_ioctl
,
2631 #ifdef CONFIG_COMPAT
2632 .compat_ioctl
= ocfs2_compat_ioctl
,
2635 .flock
= ocfs2_flock
,
2639 * POSIX-lockless variants of our file_operations.
2641 * These will be used if the underlying cluster stack does not support
2642 * posix file locking, if the user passes the "localflocks" mount
2643 * option, or if we have a local-only fs.
2645 * ocfs2_flock is in here because all stacks handle UNIX file locks,
2646 * so we still want it in the case of no stack support for
2647 * plocks. Internally, it will do the right thing when asked to ignore
2650 const struct file_operations ocfs2_fops_no_plocks
= {
2651 .llseek
= ocfs2_file_llseek
,
2653 .fsync
= ocfs2_sync_file
,
2654 .release
= ocfs2_file_release
,
2655 .open
= ocfs2_file_open
,
2656 .read_iter
= ocfs2_file_read_iter
,
2657 .write_iter
= ocfs2_file_write_iter
,
2658 .unlocked_ioctl
= ocfs2_ioctl
,
2659 #ifdef CONFIG_COMPAT
2660 .compat_ioctl
= ocfs2_compat_ioctl
,
2662 .flock
= ocfs2_flock
,
2663 .splice_read
= ocfs2_file_splice_read
,
2664 .splice_write
= iter_file_splice_write
,
2665 .fallocate
= ocfs2_fallocate
,
2668 const struct file_operations ocfs2_dops_no_plocks
= {
2669 .llseek
= generic_file_llseek
,
2670 .read
= generic_read_dir
,
2671 .iterate
= ocfs2_readdir
,
2672 .fsync
= ocfs2_sync_file
,
2673 .release
= ocfs2_dir_release
,
2674 .open
= ocfs2_dir_open
,
2675 .unlocked_ioctl
= ocfs2_ioctl
,
2676 #ifdef CONFIG_COMPAT
2677 .compat_ioctl
= ocfs2_compat_ioctl
,
2679 .flock
= ocfs2_flock
,