ocfs2: teach extend/truncate about sparse files
[safe/jmp/linux-2.6] / fs / ocfs2 / file.c
1 /* -*- mode: c; c-basic-offset: 8; -*-
2  * vim: noexpandtab sw=8 ts=8 sts=0:
3  *
4  * file.c
5  *
6  * File open, close, extend, truncate
7  *
8  * Copyright (C) 2002, 2004 Oracle.  All rights reserved.
9  *
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.
14  *
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.
19  *
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.
24  */
25
26 #include <linux/capability.h>
27 #include <linux/fs.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/pipe_fs_i.h>
35 #include <linux/mount.h>
36
37 #define MLOG_MASK_PREFIX ML_INODE
38 #include <cluster/masklog.h>
39
40 #include "ocfs2.h"
41
42 #include "alloc.h"
43 #include "aops.h"
44 #include "dir.h"
45 #include "dlmglue.h"
46 #include "extent_map.h"
47 #include "file.h"
48 #include "sysfile.h"
49 #include "inode.h"
50 #include "ioctl.h"
51 #include "journal.h"
52 #include "mmap.h"
53 #include "suballoc.h"
54 #include "super.h"
55
56 #include "buffer_head_io.h"
57
58 static int ocfs2_sync_inode(struct inode *inode)
59 {
60         filemap_fdatawrite(inode->i_mapping);
61         return sync_mapping_buffers(inode->i_mapping);
62 }
63
64 static int ocfs2_file_open(struct inode *inode, struct file *file)
65 {
66         int status;
67         int mode = file->f_flags;
68         struct ocfs2_inode_info *oi = OCFS2_I(inode);
69
70         mlog_entry("(0x%p, 0x%p, '%.*s')\n", inode, file,
71                    file->f_path.dentry->d_name.len, file->f_path.dentry->d_name.name);
72
73         spin_lock(&oi->ip_lock);
74
75         /* Check that the inode hasn't been wiped from disk by another
76          * node. If it hasn't then we're safe as long as we hold the
77          * spin lock until our increment of open count. */
78         if (OCFS2_I(inode)->ip_flags & OCFS2_INODE_DELETED) {
79                 spin_unlock(&oi->ip_lock);
80
81                 status = -ENOENT;
82                 goto leave;
83         }
84
85         if (mode & O_DIRECT)
86                 oi->ip_flags |= OCFS2_INODE_OPEN_DIRECT;
87
88         oi->ip_open_count++;
89         spin_unlock(&oi->ip_lock);
90         status = 0;
91 leave:
92         mlog_exit(status);
93         return status;
94 }
95
96 static int ocfs2_file_release(struct inode *inode, struct file *file)
97 {
98         struct ocfs2_inode_info *oi = OCFS2_I(inode);
99
100         mlog_entry("(0x%p, 0x%p, '%.*s')\n", inode, file,
101                        file->f_path.dentry->d_name.len,
102                        file->f_path.dentry->d_name.name);
103
104         spin_lock(&oi->ip_lock);
105         if (!--oi->ip_open_count)
106                 oi->ip_flags &= ~OCFS2_INODE_OPEN_DIRECT;
107         spin_unlock(&oi->ip_lock);
108
109         mlog_exit(0);
110
111         return 0;
112 }
113
114 static int ocfs2_sync_file(struct file *file,
115                            struct dentry *dentry,
116                            int datasync)
117 {
118         int err = 0;
119         journal_t *journal;
120         struct inode *inode = dentry->d_inode;
121         struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
122
123         mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", file, dentry, datasync,
124                    dentry->d_name.len, dentry->d_name.name);
125
126         err = ocfs2_sync_inode(dentry->d_inode);
127         if (err)
128                 goto bail;
129
130         journal = osb->journal->j_journal;
131         err = journal_force_commit(journal);
132
133 bail:
134         mlog_exit(err);
135
136         return (err < 0) ? -EIO : 0;
137 }
138
139 int ocfs2_should_update_atime(struct inode *inode,
140                               struct vfsmount *vfsmnt)
141 {
142         struct timespec now;
143         struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
144
145         if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
146                 return 0;
147
148         if ((inode->i_flags & S_NOATIME) ||
149             ((inode->i_sb->s_flags & MS_NODIRATIME) && S_ISDIR(inode->i_mode)))
150                 return 0;
151
152         /*
153          * We can be called with no vfsmnt structure - NFSD will
154          * sometimes do this.
155          *
156          * Note that our action here is different than touch_atime() -
157          * if we can't tell whether this is a noatime mount, then we
158          * don't know whether to trust the value of s_atime_quantum.
159          */
160         if (vfsmnt == NULL)
161                 return 0;
162
163         if ((vfsmnt->mnt_flags & MNT_NOATIME) ||
164             ((vfsmnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
165                 return 0;
166
167         if (vfsmnt->mnt_flags & MNT_RELATIME) {
168                 if ((timespec_compare(&inode->i_atime, &inode->i_mtime) <= 0) ||
169                     (timespec_compare(&inode->i_atime, &inode->i_ctime) <= 0))
170                         return 1;
171
172                 return 0;
173         }
174
175         now = CURRENT_TIME;
176         if ((now.tv_sec - inode->i_atime.tv_sec <= osb->s_atime_quantum))
177                 return 0;
178         else
179                 return 1;
180 }
181
182 int ocfs2_update_inode_atime(struct inode *inode,
183                              struct buffer_head *bh)
184 {
185         int ret;
186         struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
187         handle_t *handle;
188
189         mlog_entry_void();
190
191         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
192         if (handle == NULL) {
193                 ret = -ENOMEM;
194                 mlog_errno(ret);
195                 goto out;
196         }
197
198         inode->i_atime = CURRENT_TIME;
199         ret = ocfs2_mark_inode_dirty(handle, inode, bh);
200         if (ret < 0)
201                 mlog_errno(ret);
202
203         ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
204 out:
205         mlog_exit(ret);
206         return ret;
207 }
208
209 int ocfs2_set_inode_size(handle_t *handle,
210                          struct inode *inode,
211                          struct buffer_head *fe_bh,
212                          u64 new_i_size)
213 {
214         int status;
215
216         mlog_entry_void();
217         i_size_write(inode, new_i_size);
218         inode->i_blocks = ocfs2_align_bytes_to_sectors(new_i_size);
219         inode->i_ctime = inode->i_mtime = CURRENT_TIME;
220
221         status = ocfs2_mark_inode_dirty(handle, inode, fe_bh);
222         if (status < 0) {
223                 mlog_errno(status);
224                 goto bail;
225         }
226
227 bail:
228         mlog_exit(status);
229         return status;
230 }
231
232 static int ocfs2_simple_size_update(struct inode *inode,
233                                     struct buffer_head *di_bh,
234                                     u64 new_i_size)
235 {
236         int ret;
237         struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
238         handle_t *handle = NULL;
239
240         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
241         if (handle == NULL) {
242                 ret = -ENOMEM;
243                 mlog_errno(ret);
244                 goto out;
245         }
246
247         ret = ocfs2_set_inode_size(handle, inode, di_bh,
248                                    new_i_size);
249         if (ret < 0)
250                 mlog_errno(ret);
251
252         ocfs2_commit_trans(osb, handle);
253 out:
254         return ret;
255 }
256
257 static int ocfs2_orphan_for_truncate(struct ocfs2_super *osb,
258                                      struct inode *inode,
259                                      struct buffer_head *fe_bh,
260                                      u64 new_i_size)
261 {
262         int status;
263         handle_t *handle;
264
265         mlog_entry_void();
266
267         /* TODO: This needs to actually orphan the inode in this
268          * transaction. */
269
270         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
271         if (IS_ERR(handle)) {
272                 status = PTR_ERR(handle);
273                 mlog_errno(status);
274                 goto out;
275         }
276
277         status = ocfs2_set_inode_size(handle, inode, fe_bh, new_i_size);
278         if (status < 0)
279                 mlog_errno(status);
280
281         ocfs2_commit_trans(osb, handle);
282 out:
283         mlog_exit(status);
284         return status;
285 }
286
287 static int ocfs2_truncate_file(struct inode *inode,
288                                struct buffer_head *di_bh,
289                                u64 new_i_size)
290 {
291         int status = 0;
292         struct ocfs2_dinode *fe = NULL;
293         struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
294         struct ocfs2_truncate_context *tc = NULL;
295
296         mlog_entry("(inode = %llu, new_i_size = %llu\n",
297                    (unsigned long long)OCFS2_I(inode)->ip_blkno,
298                    (unsigned long long)new_i_size);
299
300         truncate_inode_pages(inode->i_mapping, new_i_size);
301
302         fe = (struct ocfs2_dinode *) di_bh->b_data;
303         if (!OCFS2_IS_VALID_DINODE(fe)) {
304                 OCFS2_RO_ON_INVALID_DINODE(inode->i_sb, fe);
305                 status = -EIO;
306                 goto bail;
307         }
308
309         mlog_bug_on_msg(le64_to_cpu(fe->i_size) != i_size_read(inode),
310                         "Inode %llu, inode i_size = %lld != di "
311                         "i_size = %llu, i_flags = 0x%x\n",
312                         (unsigned long long)OCFS2_I(inode)->ip_blkno,
313                         i_size_read(inode),
314                         (unsigned long long)le64_to_cpu(fe->i_size),
315                         le32_to_cpu(fe->i_flags));
316
317         if (new_i_size > le64_to_cpu(fe->i_size)) {
318                 mlog(0, "asked to truncate file with size (%llu) to size (%llu)!\n",
319                      (unsigned long long)le64_to_cpu(fe->i_size),
320                      (unsigned long long)new_i_size);
321                 status = -EINVAL;
322                 mlog_errno(status);
323                 goto bail;
324         }
325
326         mlog(0, "inode %llu, i_size = %llu, new_i_size = %llu\n",
327              (unsigned long long)le64_to_cpu(fe->i_blkno),
328              (unsigned long long)le64_to_cpu(fe->i_size),
329              (unsigned long long)new_i_size);
330
331         /* lets handle the simple truncate cases before doing any more
332          * cluster locking. */
333         if (new_i_size == le64_to_cpu(fe->i_size))
334                 goto bail;
335
336         /* This forces other nodes to sync and drop their pages. Do
337          * this even if we have a truncate without allocation change -
338          * ocfs2 cluster sizes can be much greater than page size, so
339          * we have to truncate them anyway.  */
340         status = ocfs2_data_lock(inode, 1);
341         if (status < 0) {
342                 mlog_errno(status);
343                 goto bail;
344         }
345         ocfs2_data_unlock(inode, 1);
346
347         /* alright, we're going to need to do a full blown alloc size
348          * change. Orphan the inode so that recovery can complete the
349          * truncate if necessary. This does the task of marking
350          * i_size. */
351         status = ocfs2_orphan_for_truncate(osb, inode, di_bh, new_i_size);
352         if (status < 0) {
353                 mlog_errno(status);
354                 goto bail;
355         }
356
357         status = ocfs2_prepare_truncate(osb, inode, di_bh, &tc);
358         if (status < 0) {
359                 mlog_errno(status);
360                 goto bail;
361         }
362
363         status = ocfs2_commit_truncate(osb, inode, di_bh, tc);
364         if (status < 0) {
365                 mlog_errno(status);
366                 goto bail;
367         }
368
369         /* TODO: orphan dir cleanup here. */
370 bail:
371
372         mlog_exit(status);
373         return status;
374 }
375
376 /*
377  * extend allocation only here.
378  * we'll update all the disk stuff, and oip->alloc_size
379  *
380  * expect stuff to be locked, a transaction started and enough data /
381  * metadata reservations in the contexts.
382  *
383  * Will return -EAGAIN, and a reason if a restart is needed.
384  * If passed in, *reason will always be set, even in error.
385  */
386 int ocfs2_do_extend_allocation(struct ocfs2_super *osb,
387                                struct inode *inode,
388                                u32 *logical_offset,
389                                u32 clusters_to_add,
390                                struct buffer_head *fe_bh,
391                                handle_t *handle,
392                                struct ocfs2_alloc_context *data_ac,
393                                struct ocfs2_alloc_context *meta_ac,
394                                enum ocfs2_alloc_restarted *reason_ret)
395 {
396         int status = 0;
397         int free_extents;
398         struct ocfs2_dinode *fe = (struct ocfs2_dinode *) fe_bh->b_data;
399         enum ocfs2_alloc_restarted reason = RESTART_NONE;
400         u32 bit_off, num_bits;
401         u64 block;
402
403         BUG_ON(!clusters_to_add);
404
405         free_extents = ocfs2_num_free_extents(osb, inode, fe);
406         if (free_extents < 0) {
407                 status = free_extents;
408                 mlog_errno(status);
409                 goto leave;
410         }
411
412         /* there are two cases which could cause us to EAGAIN in the
413          * we-need-more-metadata case:
414          * 1) we haven't reserved *any*
415          * 2) we are so fragmented, we've needed to add metadata too
416          *    many times. */
417         if (!free_extents && !meta_ac) {
418                 mlog(0, "we haven't reserved any metadata!\n");
419                 status = -EAGAIN;
420                 reason = RESTART_META;
421                 goto leave;
422         } else if ((!free_extents)
423                    && (ocfs2_alloc_context_bits_left(meta_ac)
424                        < ocfs2_extend_meta_needed(fe))) {
425                 mlog(0, "filesystem is really fragmented...\n");
426                 status = -EAGAIN;
427                 reason = RESTART_META;
428                 goto leave;
429         }
430
431         status = ocfs2_claim_clusters(osb, handle, data_ac, 1,
432                                       &bit_off, &num_bits);
433         if (status < 0) {
434                 if (status != -ENOSPC)
435                         mlog_errno(status);
436                 goto leave;
437         }
438
439         BUG_ON(num_bits > clusters_to_add);
440
441         /* reserve our write early -- insert_extent may update the inode */
442         status = ocfs2_journal_access(handle, inode, fe_bh,
443                                       OCFS2_JOURNAL_ACCESS_WRITE);
444         if (status < 0) {
445                 mlog_errno(status);
446                 goto leave;
447         }
448
449         block = ocfs2_clusters_to_blocks(osb->sb, bit_off);
450         mlog(0, "Allocating %u clusters at block %u for inode %llu\n",
451              num_bits, bit_off, (unsigned long long)OCFS2_I(inode)->ip_blkno);
452         status = ocfs2_insert_extent(osb, handle, inode, fe_bh,
453                                      *logical_offset, block, num_bits,
454                                      meta_ac);
455         if (status < 0) {
456                 mlog_errno(status);
457                 goto leave;
458         }
459
460         status = ocfs2_journal_dirty(handle, fe_bh);
461         if (status < 0) {
462                 mlog_errno(status);
463                 goto leave;
464         }
465
466         clusters_to_add -= num_bits;
467         *logical_offset += num_bits;
468
469         if (clusters_to_add) {
470                 mlog(0, "need to alloc once more, clusters = %u, wanted = "
471                      "%u\n", fe->i_clusters, clusters_to_add);
472                 status = -EAGAIN;
473                 reason = RESTART_TRANS;
474         }
475
476 leave:
477         mlog_exit(status);
478         if (reason_ret)
479                 *reason_ret = reason;
480         return status;
481 }
482
483 static int ocfs2_extend_allocation(struct inode *inode,
484                                    u32 clusters_to_add)
485 {
486         int status = 0;
487         int restart_func = 0;
488         int drop_alloc_sem = 0;
489         int credits, num_free_extents;
490         u32 prev_clusters, logical_start;
491         struct buffer_head *bh = NULL;
492         struct ocfs2_dinode *fe = NULL;
493         handle_t *handle = NULL;
494         struct ocfs2_alloc_context *data_ac = NULL;
495         struct ocfs2_alloc_context *meta_ac = NULL;
496         enum ocfs2_alloc_restarted why;
497         struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
498
499         mlog_entry("(clusters_to_add = %u)\n", clusters_to_add);
500
501         /*
502          * This function only exists for file systems which don't
503          * support holes.
504          */
505         BUG_ON(ocfs2_sparse_alloc(osb));
506
507         status = ocfs2_read_block(osb, OCFS2_I(inode)->ip_blkno, &bh,
508                                   OCFS2_BH_CACHED, inode);
509         if (status < 0) {
510                 mlog_errno(status);
511                 goto leave;
512         }
513
514         fe = (struct ocfs2_dinode *) bh->b_data;
515         if (!OCFS2_IS_VALID_DINODE(fe)) {
516                 OCFS2_RO_ON_INVALID_DINODE(inode->i_sb, fe);
517                 status = -EIO;
518                 goto leave;
519         }
520
521         logical_start = OCFS2_I(inode)->ip_clusters;
522
523 restart_all:
524         BUG_ON(le32_to_cpu(fe->i_clusters) != OCFS2_I(inode)->ip_clusters);
525
526         mlog(0, "extend inode %llu, i_size = %lld, fe->i_clusters = %u, "
527              "clusters_to_add = %u\n",
528              (unsigned long long)OCFS2_I(inode)->ip_blkno, i_size_read(inode),
529              fe->i_clusters, clusters_to_add);
530
531         num_free_extents = ocfs2_num_free_extents(osb,
532                                                   inode,
533                                                   fe);
534         if (num_free_extents < 0) {
535                 status = num_free_extents;
536                 mlog_errno(status);
537                 goto leave;
538         }
539
540         if (!num_free_extents) {
541                 status = ocfs2_reserve_new_metadata(osb, fe, &meta_ac);
542                 if (status < 0) {
543                         if (status != -ENOSPC)
544                                 mlog_errno(status);
545                         goto leave;
546                 }
547         }
548
549         status = ocfs2_reserve_clusters(osb, clusters_to_add, &data_ac);
550         if (status < 0) {
551                 if (status != -ENOSPC)
552                         mlog_errno(status);
553                 goto leave;
554         }
555
556         /* blocks peope in read/write from reading our allocation
557          * until we're done changing it. We depend on i_mutex to block
558          * other extend/truncate calls while we're here. Ordering wrt
559          * start_trans is important here -- always do it before! */
560         down_write(&OCFS2_I(inode)->ip_alloc_sem);
561         drop_alloc_sem = 1;
562
563         credits = ocfs2_calc_extend_credits(osb->sb, fe, clusters_to_add);
564         handle = ocfs2_start_trans(osb, credits);
565         if (IS_ERR(handle)) {
566                 status = PTR_ERR(handle);
567                 handle = NULL;
568                 mlog_errno(status);
569                 goto leave;
570         }
571
572 restarted_transaction:
573         /* reserve a write to the file entry early on - that we if we
574          * run out of credits in the allocation path, we can still
575          * update i_size. */
576         status = ocfs2_journal_access(handle, inode, bh,
577                                       OCFS2_JOURNAL_ACCESS_WRITE);
578         if (status < 0) {
579                 mlog_errno(status);
580                 goto leave;
581         }
582
583         prev_clusters = OCFS2_I(inode)->ip_clusters;
584
585         status = ocfs2_do_extend_allocation(osb,
586                                             inode,
587                                             &logical_start,
588                                             clusters_to_add,
589                                             bh,
590                                             handle,
591                                             data_ac,
592                                             meta_ac,
593                                             &why);
594         if ((status < 0) && (status != -EAGAIN)) {
595                 if (status != -ENOSPC)
596                         mlog_errno(status);
597                 goto leave;
598         }
599
600         status = ocfs2_journal_dirty(handle, bh);
601         if (status < 0) {
602                 mlog_errno(status);
603                 goto leave;
604         }
605
606         spin_lock(&OCFS2_I(inode)->ip_lock);
607         clusters_to_add -= (OCFS2_I(inode)->ip_clusters - prev_clusters);
608         spin_unlock(&OCFS2_I(inode)->ip_lock);
609
610         if (why != RESTART_NONE && clusters_to_add) {
611                 if (why == RESTART_META) {
612                         mlog(0, "restarting function.\n");
613                         restart_func = 1;
614                 } else {
615                         BUG_ON(why != RESTART_TRANS);
616
617                         mlog(0, "restarting transaction.\n");
618                         /* TODO: This can be more intelligent. */
619                         credits = ocfs2_calc_extend_credits(osb->sb,
620                                                             fe,
621                                                             clusters_to_add);
622                         status = ocfs2_extend_trans(handle, credits);
623                         if (status < 0) {
624                                 /* handle still has to be committed at
625                                  * this point. */
626                                 status = -ENOMEM;
627                                 mlog_errno(status);
628                                 goto leave;
629                         }
630                         goto restarted_transaction;
631                 }
632         }
633
634         mlog(0, "fe: i_clusters = %u, i_size=%llu\n",
635              fe->i_clusters, (unsigned long long)fe->i_size);
636         mlog(0, "inode: ip_clusters=%u, i_size=%lld\n",
637              OCFS2_I(inode)->ip_clusters, i_size_read(inode));
638
639 leave:
640         if (drop_alloc_sem) {
641                 up_write(&OCFS2_I(inode)->ip_alloc_sem);
642                 drop_alloc_sem = 0;
643         }
644         if (handle) {
645                 ocfs2_commit_trans(osb, handle);
646                 handle = NULL;
647         }
648         if (data_ac) {
649                 ocfs2_free_alloc_context(data_ac);
650                 data_ac = NULL;
651         }
652         if (meta_ac) {
653                 ocfs2_free_alloc_context(meta_ac);
654                 meta_ac = NULL;
655         }
656         if ((!status) && restart_func) {
657                 restart_func = 0;
658                 goto restart_all;
659         }
660         if (bh) {
661                 brelse(bh);
662                 bh = NULL;
663         }
664
665         mlog_exit(status);
666         return status;
667 }
668
669 /* Some parts of this taken from generic_cont_expand, which turned out
670  * to be too fragile to do exactly what we need without us having to
671  * worry about recursive locking in ->prepare_write() and
672  * ->commit_write(). */
673 static int ocfs2_write_zero_page(struct inode *inode,
674                                  u64 size)
675 {
676         struct address_space *mapping = inode->i_mapping;
677         struct page *page;
678         unsigned long index;
679         unsigned int offset;
680         handle_t *handle = NULL;
681         int ret;
682
683         offset = (size & (PAGE_CACHE_SIZE-1)); /* Within page */
684         /* ugh.  in prepare/commit_write, if from==to==start of block, we 
685         ** skip the prepare.  make sure we never send an offset for the start
686         ** of a block
687         */
688         if ((offset & (inode->i_sb->s_blocksize - 1)) == 0) {
689                 offset++;
690         }
691         index = size >> PAGE_CACHE_SHIFT;
692
693         page = grab_cache_page(mapping, index);
694         if (!page) {
695                 ret = -ENOMEM;
696                 mlog_errno(ret);
697                 goto out;
698         }
699
700         ret = ocfs2_prepare_write_nolock(inode, page, offset, offset);
701         if (ret < 0) {
702                 mlog_errno(ret);
703                 goto out_unlock;
704         }
705
706         if (ocfs2_should_order_data(inode)) {
707                 handle = ocfs2_start_walk_page_trans(inode, page, offset,
708                                                      offset);
709                 if (IS_ERR(handle)) {
710                         ret = PTR_ERR(handle);
711                         handle = NULL;
712                         goto out_unlock;
713                 }
714         }
715
716         /* must not update i_size! */
717         ret = block_commit_write(page, offset, offset);
718         if (ret < 0)
719                 mlog_errno(ret);
720         else
721                 ret = 0;
722
723         if (handle)
724                 ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
725 out_unlock:
726         unlock_page(page);
727         page_cache_release(page);
728 out:
729         return ret;
730 }
731
732 static int ocfs2_zero_extend(struct inode *inode,
733                              u64 zero_to_size)
734 {
735         int ret = 0;
736         u64 start_off;
737         struct super_block *sb = inode->i_sb;
738
739         start_off = ocfs2_align_bytes_to_blocks(sb, i_size_read(inode));
740         while (start_off < zero_to_size) {
741                 ret = ocfs2_write_zero_page(inode, start_off);
742                 if (ret < 0) {
743                         mlog_errno(ret);
744                         goto out;
745                 }
746
747                 start_off += sb->s_blocksize;
748
749                 /*
750                  * Very large extends have the potential to lock up
751                  * the cpu for extended periods of time.
752                  */
753                 cond_resched();
754         }
755
756 out:
757         return ret;
758 }
759
760 /* 
761  * A tail_to_skip value > 0 indicates that we're being called from
762  * ocfs2_file_aio_write(). This has the following implications:
763  *
764  * - we don't want to update i_size
765  * - di_bh will be NULL, which is fine because it's only used in the
766  *   case where we want to update i_size.
767  * - ocfs2_zero_extend() will then only be filling the hole created
768  *   between i_size and the start of the write.
769  */
770 static int ocfs2_extend_file(struct inode *inode,
771                              struct buffer_head *di_bh,
772                              u64 new_i_size,
773                              size_t tail_to_skip)
774 {
775         int ret = 0;
776         u32 clusters_to_add = 0;
777
778         BUG_ON(!tail_to_skip && !di_bh);
779
780         /* setattr sometimes calls us like this. */
781         if (new_i_size == 0)
782                 goto out;
783
784         if (i_size_read(inode) == new_i_size)
785                 goto out;
786         BUG_ON(new_i_size < i_size_read(inode));
787
788         if (ocfs2_sparse_alloc(OCFS2_SB(inode->i_sb))) {
789                 BUG_ON(tail_to_skip != 0);
790                 goto out_update_size;
791         }
792
793         clusters_to_add = ocfs2_clusters_for_bytes(inode->i_sb, new_i_size) - 
794                 OCFS2_I(inode)->ip_clusters;
795
796         /* 
797          * protect the pages that ocfs2_zero_extend is going to be
798          * pulling into the page cache.. we do this before the
799          * metadata extend so that we don't get into the situation
800          * where we've extended the metadata but can't get the data
801          * lock to zero.
802          */
803         ret = ocfs2_data_lock(inode, 1);
804         if (ret < 0) {
805                 mlog_errno(ret);
806                 goto out;
807         }
808
809         if (clusters_to_add) {
810                 ret = ocfs2_extend_allocation(inode, clusters_to_add);
811                 if (ret < 0) {
812                         mlog_errno(ret);
813                         goto out_unlock;
814                 }
815         }
816
817         /*
818          * Call this even if we don't add any clusters to the tree. We
819          * still need to zero the area between the old i_size and the
820          * new i_size.
821          */
822         ret = ocfs2_zero_extend(inode, (u64)new_i_size - tail_to_skip);
823         if (ret < 0) {
824                 mlog_errno(ret);
825                 goto out_unlock;
826         }
827
828 out_update_size:
829         if (!tail_to_skip) {
830                 /* We're being called from ocfs2_setattr() which wants
831                  * us to update i_size */
832                 ret = ocfs2_simple_size_update(inode, di_bh, new_i_size);
833                 if (ret < 0)
834                         mlog_errno(ret);
835         }
836
837 out_unlock:
838         if (!ocfs2_sparse_alloc(OCFS2_SB(inode->i_sb)))
839                 ocfs2_data_unlock(inode, 1);
840
841 out:
842         return ret;
843 }
844
845 int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
846 {
847         int status = 0, size_change;
848         struct inode *inode = dentry->d_inode;
849         struct super_block *sb = inode->i_sb;
850         struct ocfs2_super *osb = OCFS2_SB(sb);
851         struct buffer_head *bh = NULL;
852         handle_t *handle = NULL;
853
854         mlog_entry("(0x%p, '%.*s')\n", dentry,
855                    dentry->d_name.len, dentry->d_name.name);
856
857         if (attr->ia_valid & ATTR_MODE)
858                 mlog(0, "mode change: %d\n", attr->ia_mode);
859         if (attr->ia_valid & ATTR_UID)
860                 mlog(0, "uid change: %d\n", attr->ia_uid);
861         if (attr->ia_valid & ATTR_GID)
862                 mlog(0, "gid change: %d\n", attr->ia_gid);
863         if (attr->ia_valid & ATTR_SIZE)
864                 mlog(0, "size change...\n");
865         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
866                 mlog(0, "time change...\n");
867
868 #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
869                            | ATTR_GID | ATTR_UID | ATTR_MODE)
870         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
871                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
872                 return 0;
873         }
874
875         status = inode_change_ok(inode, attr);
876         if (status)
877                 return status;
878
879         size_change = S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_SIZE;
880         if (size_change) {
881                 status = ocfs2_rw_lock(inode, 1);
882                 if (status < 0) {
883                         mlog_errno(status);
884                         goto bail;
885                 }
886         }
887
888         status = ocfs2_meta_lock(inode, &bh, 1);
889         if (status < 0) {
890                 if (status != -ENOENT)
891                         mlog_errno(status);
892                 goto bail_unlock_rw;
893         }
894
895         if (size_change && attr->ia_size != i_size_read(inode)) {
896                 if (i_size_read(inode) > attr->ia_size)
897                         status = ocfs2_truncate_file(inode, bh, attr->ia_size);
898                 else
899                         status = ocfs2_extend_file(inode, bh, attr->ia_size, 0);
900                 if (status < 0) {
901                         if (status != -ENOSPC)
902                                 mlog_errno(status);
903                         status = -ENOSPC;
904                         goto bail_unlock;
905                 }
906         }
907
908         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
909         if (IS_ERR(handle)) {
910                 status = PTR_ERR(handle);
911                 mlog_errno(status);
912                 goto bail_unlock;
913         }
914
915         status = inode_setattr(inode, attr);
916         if (status < 0) {
917                 mlog_errno(status);
918                 goto bail_commit;
919         }
920
921         status = ocfs2_mark_inode_dirty(handle, inode, bh);
922         if (status < 0)
923                 mlog_errno(status);
924
925 bail_commit:
926         ocfs2_commit_trans(osb, handle);
927 bail_unlock:
928         ocfs2_meta_unlock(inode, 1);
929 bail_unlock_rw:
930         if (size_change)
931                 ocfs2_rw_unlock(inode, 1);
932 bail:
933         if (bh)
934                 brelse(bh);
935
936         mlog_exit(status);
937         return status;
938 }
939
940 int ocfs2_getattr(struct vfsmount *mnt,
941                   struct dentry *dentry,
942                   struct kstat *stat)
943 {
944         struct inode *inode = dentry->d_inode;
945         struct super_block *sb = dentry->d_inode->i_sb;
946         struct ocfs2_super *osb = sb->s_fs_info;
947         int err;
948
949         mlog_entry_void();
950
951         err = ocfs2_inode_revalidate(dentry);
952         if (err) {
953                 if (err != -ENOENT)
954                         mlog_errno(err);
955                 goto bail;
956         }
957
958         generic_fillattr(inode, stat);
959
960         /* We set the blksize from the cluster size for performance */
961         stat->blksize = osb->s_clustersize;
962
963 bail:
964         mlog_exit(err);
965
966         return err;
967 }
968
969 int ocfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
970 {
971         int ret;
972
973         mlog_entry_void();
974
975         ret = ocfs2_meta_lock(inode, NULL, 0);
976         if (ret) {
977                 if (ret != -ENOENT)
978                         mlog_errno(ret);
979                 goto out;
980         }
981
982         ret = generic_permission(inode, mask, NULL);
983
984         ocfs2_meta_unlock(inode, 0);
985 out:
986         mlog_exit(ret);
987         return ret;
988 }
989
990 static int ocfs2_write_remove_suid(struct inode *inode)
991 {
992         int ret;
993         struct buffer_head *bh = NULL;
994         struct ocfs2_inode_info *oi = OCFS2_I(inode);
995         handle_t *handle;
996         struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
997         struct ocfs2_dinode *di;
998
999         mlog_entry("(Inode %llu, mode 0%o)\n",
1000                    (unsigned long long)oi->ip_blkno, inode->i_mode);
1001
1002         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
1003         if (handle == NULL) {
1004                 ret = -ENOMEM;
1005                 mlog_errno(ret);
1006                 goto out;
1007         }
1008
1009         ret = ocfs2_read_block(osb, oi->ip_blkno, &bh, OCFS2_BH_CACHED, inode);
1010         if (ret < 0) {
1011                 mlog_errno(ret);
1012                 goto out_trans;
1013         }
1014
1015         ret = ocfs2_journal_access(handle, inode, bh,
1016                                    OCFS2_JOURNAL_ACCESS_WRITE);
1017         if (ret < 0) {
1018                 mlog_errno(ret);
1019                 goto out_bh;
1020         }
1021
1022         inode->i_mode &= ~S_ISUID;
1023         if ((inode->i_mode & S_ISGID) && (inode->i_mode & S_IXGRP))
1024                 inode->i_mode &= ~S_ISGID;
1025
1026         di = (struct ocfs2_dinode *) bh->b_data;
1027         di->i_mode = cpu_to_le16(inode->i_mode);
1028
1029         ret = ocfs2_journal_dirty(handle, bh);
1030         if (ret < 0)
1031                 mlog_errno(ret);
1032 out_bh:
1033         brelse(bh);
1034 out_trans:
1035         ocfs2_commit_trans(osb, handle);
1036 out:
1037         mlog_exit(ret);
1038         return ret;
1039 }
1040
1041 static int ocfs2_prepare_inode_for_write(struct dentry *dentry,
1042                                          loff_t *ppos,
1043                                          size_t count,
1044                                          int appending)
1045 {
1046         int ret = 0, meta_level = appending;
1047         struct inode *inode = dentry->d_inode;
1048         u32 clusters;
1049         loff_t newsize, saved_pos;
1050
1051         /* 
1052          * We sample i_size under a read level meta lock to see if our write
1053          * is extending the file, if it is we back off and get a write level
1054          * meta lock.
1055          */
1056         for(;;) {
1057                 ret = ocfs2_meta_lock(inode, NULL, meta_level);
1058                 if (ret < 0) {
1059                         meta_level = -1;
1060                         mlog_errno(ret);
1061                         goto out;
1062                 }
1063
1064                 /* Clear suid / sgid if necessary. We do this here
1065                  * instead of later in the write path because
1066                  * remove_suid() calls ->setattr without any hint that
1067                  * we may have already done our cluster locking. Since
1068                  * ocfs2_setattr() *must* take cluster locks to
1069                  * proceeed, this will lead us to recursively lock the
1070                  * inode. There's also the dinode i_size state which
1071                  * can be lost via setattr during extending writes (we
1072                  * set inode->i_size at the end of a write. */
1073                 if (should_remove_suid(dentry)) {
1074                         if (meta_level == 0) {
1075                                 ocfs2_meta_unlock(inode, meta_level);
1076                                 meta_level = 1;
1077                                 continue;
1078                         }
1079
1080                         ret = ocfs2_write_remove_suid(inode);
1081                         if (ret < 0) {
1082                                 mlog_errno(ret);
1083                                 goto out_unlock;
1084                         }
1085                 }
1086
1087                 /* work on a copy of ppos until we're sure that we won't have
1088                  * to recalculate it due to relocking. */
1089                 if (appending) {
1090                         saved_pos = i_size_read(inode);
1091                         mlog(0, "O_APPEND: inode->i_size=%llu\n", saved_pos);
1092                 } else {
1093                         saved_pos = *ppos;
1094                 }
1095
1096                 /*
1097                  * The rest of this loop is concerned with legacy file
1098                  * systems which don't support sparse files.
1099                  */
1100                 if (ocfs2_sparse_alloc(OCFS2_SB(inode->i_sb)))
1101                         break;
1102
1103                 newsize = count + saved_pos;
1104
1105                 mlog(0, "pos=%lld newsize=%lld cursize=%lld\n",
1106                      (long long) saved_pos, (long long) newsize,
1107                      (long long) i_size_read(inode));
1108
1109                 /* No need for a higher level metadata lock if we're
1110                  * never going past i_size. */
1111                 if (newsize <= i_size_read(inode))
1112                         break;
1113
1114                 if (meta_level == 0) {
1115                         ocfs2_meta_unlock(inode, meta_level);
1116                         meta_level = 1;
1117                         continue;
1118                 }
1119
1120                 spin_lock(&OCFS2_I(inode)->ip_lock);
1121                 clusters = ocfs2_clusters_for_bytes(inode->i_sb, newsize) -
1122                         OCFS2_I(inode)->ip_clusters;
1123                 spin_unlock(&OCFS2_I(inode)->ip_lock);
1124
1125                 mlog(0, "Writing at EOF, may need more allocation: "
1126                      "i_size = %lld, newsize = %lld, need %u clusters\n",
1127                      (long long) i_size_read(inode), (long long) newsize,
1128                      clusters);
1129
1130                 /* We only want to continue the rest of this loop if
1131                  * our extend will actually require more
1132                  * allocation. */
1133                 if (!clusters)
1134                         break;
1135
1136                 ret = ocfs2_extend_file(inode, NULL, newsize, count);
1137                 if (ret < 0) {
1138                         if (ret != -ENOSPC)
1139                                 mlog_errno(ret);
1140                         goto out_unlock;
1141                 }
1142                 break;
1143         }
1144
1145         if (appending)
1146                 *ppos = saved_pos;
1147
1148 out_unlock:
1149         ocfs2_meta_unlock(inode, meta_level);
1150
1151 out:
1152         return ret;
1153 }
1154
1155 static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
1156                                     const struct iovec *iov,
1157                                     unsigned long nr_segs,
1158                                     loff_t pos)
1159 {
1160         int ret, rw_level, have_alloc_sem = 0;
1161         struct file *filp = iocb->ki_filp;
1162         struct inode *inode = filp->f_path.dentry->d_inode;
1163         int appending = filp->f_flags & O_APPEND ? 1 : 0;
1164
1165         mlog_entry("(0x%p, %u, '%.*s')\n", filp,
1166                    (unsigned int)nr_segs,
1167                    filp->f_path.dentry->d_name.len,
1168                    filp->f_path.dentry->d_name.name);
1169
1170         /* happy write of zero bytes */
1171         if (iocb->ki_left == 0)
1172                 return 0;
1173
1174         mutex_lock(&inode->i_mutex);
1175         /* to match setattr's i_mutex -> i_alloc_sem -> rw_lock ordering */
1176         if (filp->f_flags & O_DIRECT) {
1177                 have_alloc_sem = 1;
1178                 down_read(&inode->i_alloc_sem);
1179         }
1180
1181         /* concurrent O_DIRECT writes are allowed */
1182         rw_level = (filp->f_flags & O_DIRECT) ? 0 : 1;
1183         ret = ocfs2_rw_lock(inode, rw_level);
1184         if (ret < 0) {
1185                 rw_level = -1;
1186                 mlog_errno(ret);
1187                 goto out;
1188         }
1189
1190         ret = ocfs2_prepare_inode_for_write(filp->f_path.dentry, &iocb->ki_pos,
1191                                             iocb->ki_left, appending);
1192         if (ret < 0) {
1193                 mlog_errno(ret);
1194                 goto out;
1195         }
1196
1197         /* communicate with ocfs2_dio_end_io */
1198         ocfs2_iocb_set_rw_locked(iocb);
1199
1200         ret = generic_file_aio_write_nolock(iocb, iov, nr_segs, iocb->ki_pos);
1201
1202         /* buffered aio wouldn't have proper lock coverage today */
1203         BUG_ON(ret == -EIOCBQUEUED && !(filp->f_flags & O_DIRECT));
1204
1205         /* 
1206          * deep in g_f_a_w_n()->ocfs2_direct_IO we pass in a ocfs2_dio_end_io
1207          * function pointer which is called when o_direct io completes so that
1208          * it can unlock our rw lock.  (it's the clustered equivalent of
1209          * i_alloc_sem; protects truncate from racing with pending ios).
1210          * Unfortunately there are error cases which call end_io and others
1211          * that don't.  so we don't have to unlock the rw_lock if either an
1212          * async dio is going to do it in the future or an end_io after an
1213          * error has already done it.
1214          */
1215         if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) {
1216                 rw_level = -1;
1217                 have_alloc_sem = 0;
1218         }
1219
1220 out:
1221         if (have_alloc_sem)
1222                 up_read(&inode->i_alloc_sem);
1223         if (rw_level != -1) 
1224                 ocfs2_rw_unlock(inode, rw_level);
1225         mutex_unlock(&inode->i_mutex);
1226
1227         mlog_exit(ret);
1228         return ret;
1229 }
1230
1231 static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe,
1232                                        struct file *out,
1233                                        loff_t *ppos,
1234                                        size_t len,
1235                                        unsigned int flags)
1236 {
1237         int ret;
1238         struct inode *inode = out->f_path.dentry->d_inode;
1239
1240         mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", out, pipe,
1241                    (unsigned int)len,
1242                    out->f_path.dentry->d_name.len,
1243                    out->f_path.dentry->d_name.name);
1244
1245         inode_double_lock(inode, pipe->inode);
1246
1247         ret = ocfs2_rw_lock(inode, 1);
1248         if (ret < 0) {
1249                 mlog_errno(ret);
1250                 goto out;
1251         }
1252
1253         ret = ocfs2_prepare_inode_for_write(out->f_path.dentry, ppos, len, 0);
1254         if (ret < 0) {
1255                 mlog_errno(ret);
1256                 goto out_unlock;
1257         }
1258
1259         /* ok, we're done with i_size and alloc work */
1260         ret = generic_file_splice_write_nolock(pipe, out, ppos, len, flags);
1261
1262 out_unlock:
1263         ocfs2_rw_unlock(inode, 1);
1264 out:
1265         inode_double_unlock(inode, pipe->inode);
1266
1267         mlog_exit(ret);
1268         return ret;
1269 }
1270
1271 static ssize_t ocfs2_file_splice_read(struct file *in,
1272                                       loff_t *ppos,
1273                                       struct pipe_inode_info *pipe,
1274                                       size_t len,
1275                                       unsigned int flags)
1276 {
1277         int ret = 0;
1278         struct inode *inode = in->f_path.dentry->d_inode;
1279
1280         mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", in, pipe,
1281                    (unsigned int)len,
1282                    in->f_path.dentry->d_name.len,
1283                    in->f_path.dentry->d_name.name);
1284
1285         /*
1286          * See the comment in ocfs2_file_aio_read()
1287          */
1288         ret = ocfs2_meta_lock(inode, NULL, 0);
1289         if (ret < 0) {
1290                 mlog_errno(ret);
1291                 goto bail;
1292         }
1293         ocfs2_meta_unlock(inode, 0);
1294
1295         ret = generic_file_splice_read(in, ppos, pipe, len, flags);
1296
1297 bail:
1298         mlog_exit(ret);
1299         return ret;
1300 }
1301
1302 static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
1303                                    const struct iovec *iov,
1304                                    unsigned long nr_segs,
1305                                    loff_t pos)
1306 {
1307         int ret = 0, rw_level = -1, have_alloc_sem = 0, lock_level = 0;
1308         struct file *filp = iocb->ki_filp;
1309         struct inode *inode = filp->f_path.dentry->d_inode;
1310
1311         mlog_entry("(0x%p, %u, '%.*s')\n", filp,
1312                    (unsigned int)nr_segs,
1313                    filp->f_path.dentry->d_name.len,
1314                    filp->f_path.dentry->d_name.name);
1315
1316         if (!inode) {
1317                 ret = -EINVAL;
1318                 mlog_errno(ret);
1319                 goto bail;
1320         }
1321
1322         /* 
1323          * buffered reads protect themselves in ->readpage().  O_DIRECT reads
1324          * need locks to protect pending reads from racing with truncate.
1325          */
1326         if (filp->f_flags & O_DIRECT) {
1327                 down_read(&inode->i_alloc_sem);
1328                 have_alloc_sem = 1;
1329
1330                 ret = ocfs2_rw_lock(inode, 0);
1331                 if (ret < 0) {
1332                         mlog_errno(ret);
1333                         goto bail;
1334                 }
1335                 rw_level = 0;
1336                 /* communicate with ocfs2_dio_end_io */
1337                 ocfs2_iocb_set_rw_locked(iocb);
1338         }
1339
1340         /*
1341          * We're fine letting folks race truncates and extending
1342          * writes with read across the cluster, just like they can
1343          * locally. Hence no rw_lock during read.
1344          * 
1345          * Take and drop the meta data lock to update inode fields
1346          * like i_size. This allows the checks down below
1347          * generic_file_aio_read() a chance of actually working. 
1348          */
1349         ret = ocfs2_meta_lock_atime(inode, filp->f_vfsmnt, &lock_level);
1350         if (ret < 0) {
1351                 mlog_errno(ret);
1352                 goto bail;
1353         }
1354         ocfs2_meta_unlock(inode, lock_level);
1355
1356         ret = generic_file_aio_read(iocb, iov, nr_segs, iocb->ki_pos);
1357         if (ret == -EINVAL)
1358                 mlog(ML_ERROR, "generic_file_aio_read returned -EINVAL\n");
1359
1360         /* buffered aio wouldn't have proper lock coverage today */
1361         BUG_ON(ret == -EIOCBQUEUED && !(filp->f_flags & O_DIRECT));
1362
1363         /* see ocfs2_file_aio_write */
1364         if (ret == -EIOCBQUEUED || !ocfs2_iocb_is_rw_locked(iocb)) {
1365                 rw_level = -1;
1366                 have_alloc_sem = 0;
1367         }
1368
1369 bail:
1370         if (have_alloc_sem)
1371                 up_read(&inode->i_alloc_sem);
1372         if (rw_level != -1) 
1373                 ocfs2_rw_unlock(inode, rw_level);
1374         mlog_exit(ret);
1375
1376         return ret;
1377 }
1378
1379 const struct inode_operations ocfs2_file_iops = {
1380         .setattr        = ocfs2_setattr,
1381         .getattr        = ocfs2_getattr,
1382         .permission     = ocfs2_permission,
1383 };
1384
1385 const struct inode_operations ocfs2_special_file_iops = {
1386         .setattr        = ocfs2_setattr,
1387         .getattr        = ocfs2_getattr,
1388         .permission     = ocfs2_permission,
1389 };
1390
1391 const struct file_operations ocfs2_fops = {
1392         .read           = do_sync_read,
1393         .write          = do_sync_write,
1394         .sendfile       = generic_file_sendfile,
1395         .mmap           = ocfs2_mmap,
1396         .fsync          = ocfs2_sync_file,
1397         .release        = ocfs2_file_release,
1398         .open           = ocfs2_file_open,
1399         .aio_read       = ocfs2_file_aio_read,
1400         .aio_write      = ocfs2_file_aio_write,
1401         .ioctl          = ocfs2_ioctl,
1402         .splice_read    = ocfs2_file_splice_read,
1403         .splice_write   = ocfs2_file_splice_write,
1404 };
1405
1406 const struct file_operations ocfs2_dops = {
1407         .read           = generic_read_dir,
1408         .readdir        = ocfs2_readdir,
1409         .fsync          = ocfs2_sync_file,
1410         .ioctl          = ocfs2_ioctl,
1411 };