Whamcloud - gitweb
487c6c2982d0095eadcc6b459b99cca7c5c4d27f
[fs/lustre-release.git] / lustre / llite / file.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
5  *   Author: Peter Braam <braam@clusterfs.com>
6  *   Author: Phil Schwan <phil@clusterfs.com>
7  *   Author: Andreas Dilger <adilger@clusterfs.com>
8  *
9  *   This file is part of Lustre, http://www.lustre.org.
10  *
11  *   Lustre is free software; you can redistribute it and/or
12  *   modify it under the terms of version 2 of the GNU General Public
13  *   License as published by the Free Software Foundation.
14  *
15  *   Lustre 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
18  *   GNU General Public License for more details.
19  *
20  *   You should have received a copy of the GNU General Public License
21  *   along with Lustre; if not, write to the Free Software
22  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25 #define DEBUG_SUBSYSTEM S_LLITE
26 #include <linux/lustre_dlm.h>
27 #include <linux/lustre_lite.h>
28 #include <linux/pagemap.h>
29 #include <linux/file.h>
30 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
31 #include <linux/lustre_compat25.h>
32 #endif
33
34 #include "llite_internal.h"
35
36 static int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
37                         struct file *file)
38 {
39         struct ll_file_data *fd = file->private_data;
40         struct ptlrpc_request *req = NULL;
41         struct obd_client_handle *och = &fd->fd_mds_och;
42         struct ll_inode_info *lli = ll_i2info(inode);
43         struct obdo obdo;
44         int rc, valid;
45         ENTRY;
46
47         valid = OBD_MD_FLID;
48         if (test_bit(LLI_F_HAVE_OST_SIZE_LOCK, &lli->lli_flags))
49                 valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
50
51         memset(&obdo, 0, sizeof(obdo));
52         obdo.o_id = inode->i_ino;
53         obdo.o_mode = inode->i_mode;
54         obdo.o_size = inode->i_size;
55         obdo.o_blocks = inode->i_blocks;
56         if (0 /* ll_is_inode_dirty(inode) */) {
57                 obdo.o_flags = MDS_BFLAG_UNCOMMITTED_WRITES;
58                 valid |= OBD_MD_FLFLAGS;
59         }
60         obdo.o_valid = valid;
61         rc = mdc_close(mdc_exp, &obdo, och, &req);
62         if (rc == EAGAIN) {
63                 /* We are the last writer, so the MDS has instructed us to get
64                  * the file size and any write cookies, then close again. */
65                 //ll_queue_done_writing(inode);
66                 rc = 0;
67         } else if (rc) {
68                 CERROR("inode %lu mdc close failed: rc = %d\n",
69                        inode->i_ino, rc);
70         }
71         if (rc == 0) {
72                 rc = ll_objects_destroy(req, file->f_dentry->d_inode);
73                 if (rc)
74                         CERROR("inode %lu ll_objects destroy: rc = %d\n",
75                                inode->i_ino, rc);
76         }
77
78         mdc_clear_open_replay_data(och);
79         ptlrpc_req_finished(req);
80         och->och_fh.cookie = DEAD_HANDLE_MAGIC;
81         file->private_data = NULL;
82         OBD_SLAB_FREE(fd, ll_file_data_slab, sizeof *fd);
83
84         RETURN(rc);
85 }
86
87 /* While this returns an error code, fput() the caller does not, so we need
88  * to make every effort to clean up all of our state here.  Also, applications
89  * rarely check close errors and even if an error is returned they will not
90  * re-try the close call.
91  */
92 int ll_file_release(struct inode *inode, struct file *file)
93 {
94         struct ll_file_data *fd;
95         struct ll_sb_info *sbi = ll_i2sbi(inode);
96         int rc;
97
98         ENTRY;
99         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
100                inode->i_generation, inode);
101
102         /* don't do anything for / */
103         if (inode->i_sb->s_root == file->f_dentry)
104                 RETURN(0);
105
106         lprocfs_counter_incr(sbi->ll_stats, LPROC_LL_RELEASE);
107         fd = (struct ll_file_data *)file->private_data;
108         LASSERT(fd != NULL);
109
110         rc = ll_mdc_close(sbi->ll_mdc_exp, inode, file);
111         RETURN(rc);
112 }
113
114 static int ll_intent_file_open(struct file *file, void *lmm,
115                                int lmmsize, struct lookup_intent *itp)
116 {
117         struct ll_sb_info *sbi = ll_i2sbi(file->f_dentry->d_inode);
118         struct lustre_handle lockh;
119         struct mdc_op_data data;
120         struct dentry *parent = file->f_dentry->d_parent;
121         const char *name = file->f_dentry->d_name.name;
122         const int len = file->f_dentry->d_name.len;
123         int rc;
124
125         if (!parent)
126                 RETURN(-ENOENT);
127
128         ll_prepare_mdc_op_data(&data, parent->d_inode, NULL, name, len, O_RDWR);
129
130         rc = mdc_enqueue(sbi->ll_mdc_exp, LDLM_PLAIN, itp, LCK_PR, &data,
131                          &lockh, lmm, lmmsize, ldlm_completion_ast,
132                          ll_mdc_blocking_ast, parent->d_inode);
133         if (rc < 0)
134                 CERROR("lock enqueue: err: %d\n", rc);
135         RETURN(rc);
136 }
137
138 static int ll_local_open(struct file *file, struct lookup_intent *it)
139 {
140         struct ptlrpc_request *req = it->d.lustre.it_data;
141         struct ll_inode_info *lli = ll_i2info(file->f_dentry->d_inode);
142         struct ll_file_data *fd;
143         struct mds_body *body;
144         ENTRY;
145
146         body = lustre_msg_buf (req->rq_repmsg, 1, sizeof (*body));
147         LASSERT (body != NULL);                 /* reply already checked out */
148         LASSERT_REPSWABBED (req, 1);            /* and swabbed down */
149
150         LASSERT(!file->private_data);
151
152         OBD_SLAB_ALLOC(fd, ll_file_data_slab, SLAB_KERNEL, sizeof *fd);
153         /* We can't handle this well without reorganizing ll_file_open and
154          * ll_mdc_close, so don't even try right now. */
155         LASSERT(fd != NULL);
156
157         memcpy(&fd->fd_mds_och.och_fh, &body->handle, sizeof(body->handle));
158         fd->fd_mds_och.och_magic = OBD_CLIENT_HANDLE_MAGIC;
159         file->private_data = fd;
160         ll_readahead_init(&fd->fd_ras);
161
162         lli->lli_io_epoch = body->io_epoch;
163
164         mdc_set_open_replay_data(&fd->fd_mds_och, it->d.lustre.it_data);
165
166         RETURN(0);
167 }
168
169 /* Open a file, and (for the very first open) create objects on the OSTs at
170  * this time.  If opened with O_LOV_DELAY_CREATE, then we don't do the object
171  * creation or open until ll_lov_setstripe() ioctl is called.  We grab
172  * lli_open_sem to ensure no other process will create objects, send the
173  * stripe MD to the MDS, or try to destroy the objects if that fails.
174  *
175  * If we already have the stripe MD locally then we don't request it in
176  * mdc_open(), by passing a lmm_size = 0.
177  *
178  * It is up to the application to ensure no other processes open this file
179  * in the O_LOV_DELAY_CREATE case, or the default striping pattern will be
180  * used.  We might be able to avoid races of that sort by getting lli_open_sem
181  * before returning in the O_LOV_DELAY_CREATE case and dropping it here
182  * or in ll_file_release(), but I'm not sure that is desirable/necessary.
183  */
184 int ll_file_open(struct inode *inode, struct file *file)
185 {
186         struct ll_inode_info *lli = ll_i2info(inode);
187         struct lookup_intent *it;
188         struct lov_stripe_md *lsm;
189         struct ptlrpc_request *req;
190         int rc = 0;
191         ENTRY;
192
193         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
194                inode->i_generation, inode);
195
196         /* don't do anything for / */
197         if (inode->i_sb->s_root == file->f_dentry)
198                 RETURN(0);
199
200         it = file->f_it;
201
202         if (!it->d.lustre.it_disposition) {
203                 struct lookup_intent oit = { .it_op = IT_OPEN,
204                                              .it_flags = file->f_flags };
205                 it = &oit;
206                 rc = ll_intent_file_open(file, NULL, 0, it);
207                 if (rc)
208                         GOTO(out, rc);
209         }
210
211         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_OPEN);
212         rc = it_open_error(DISP_OPEN_OPEN, it);
213         if (rc)
214                 GOTO(out, rc);
215
216         rc = ll_local_open(file, it);
217         if (rc)
218                 LBUG();
219
220         if (!S_ISREG(inode->i_mode))
221                 GOTO(out, rc);
222
223         lsm = lli->lli_smd;
224         if (lsm == NULL) {
225                 if (file->f_flags & O_LOV_DELAY_CREATE ||
226                     !(file->f_mode & FMODE_WRITE)) {
227                         CDEBUG(D_INODE, "object creation was delayed\n");
228                         GOTO(out, rc);
229                 }
230         }
231         file->f_flags &= ~O_LOV_DELAY_CREATE;
232         GOTO(out, rc);
233  out:
234         req = it->d.lustre.it_data;
235         ptlrpc_req_finished(req);
236         if (rc == 0)
237                 ll_open_complete(inode);
238         return rc;
239 }
240
241 /* Fills the obdo with the attributes for the inode defined by lsm */
242 int ll_lsm_getattr(struct obd_export *exp, struct lov_stripe_md *lsm,
243                    struct obdo *oa)
244 {
245         struct ptlrpc_request_set *set;
246         int rc;
247         ENTRY;
248
249         LASSERT(lsm != NULL);
250
251         memset(oa, 0, sizeof *oa);
252         oa->o_id = lsm->lsm_object_id;
253         oa->o_mode = S_IFREG;
254         oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
255                 OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME |
256                 OBD_MD_FLCTIME;
257
258         set = ptlrpc_prep_set();
259         if (set == NULL) {
260                 CERROR ("ENOMEM allocing request set\n");
261                 rc = -ENOMEM;
262         } else {
263                 rc = obd_getattr_async(exp, oa, lsm, set);
264                 if (rc == 0)
265                         rc = ptlrpc_set_wait(set);
266                 ptlrpc_set_destroy(set);
267         }
268         if (rc)
269                 RETURN(rc);
270
271         oa->o_valid &= (OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME | 
272                         OBD_MD_FLCTIME | OBD_MD_FLSIZE);
273         RETURN(0);
274 }
275
276 static inline void ll_remove_suid(struct inode *inode)
277 {
278         unsigned int mode;
279
280         /* set S_IGID if S_IXGRP is set, and always set S_ISUID */
281         mode = (inode->i_mode & S_IXGRP)*(S_ISGID/S_IXGRP) | S_ISUID;
282
283         /* was any of the uid bits set? */
284         mode &= inode->i_mode;
285         if (mode && !capable(CAP_FSETID)) {
286                 inode->i_mode &= ~mode;
287                 // XXX careful here - we cannot change the size
288         }
289 }
290
291 /* Flush the page cache for an extent as its canceled.  No one can dirty the
292  * extent until we've finished our work and they can enqueue another lock.
293  * The DLM protects us from ll_file_read/write here, but other kernel actors
294  * could have pages locked */
295 void ll_pgcache_remove_extent(struct inode *inode, struct lov_stripe_md *lsm,
296                               struct ldlm_lock *lock)
297 {
298         struct ldlm_extent *extent = &lock->l_policy_data.l_extent;
299         struct obd_export *exp = ll_i2obdexp(inode);
300         struct ll_inode_info *lli = ll_i2info(inode);
301         unsigned long start, end, i;
302         struct page *page;
303         int rc, discard = lock->l_flags & LDLM_FL_DISCARD_DATA;
304         ENTRY;
305
306         CDEBUG(D_INODE, "obdo %lu inode %p ["LPU64"->"LPU64"] size: %llu\n",
307                inode->i_ino, inode, extent->start, extent->end, inode->i_size);
308
309         start = extent->start >> PAGE_CACHE_SHIFT;
310         end = (extent->end >> PAGE_CACHE_SHIFT) + 1;
311         if ((end << PAGE_CACHE_SHIFT) < extent->end)
312                 end = ~0;
313
314         i = (inode->i_size + PAGE_CACHE_SIZE-1) >> PAGE_CACHE_SHIFT;
315         if (end >= i)
316                 clear_bit(LLI_F_HAVE_OST_SIZE_LOCK,
317                           &(ll_i2info(inode)->lli_flags));
318         if (i < end)
319                 end = i;
320
321         CDEBUG(D_INODE, "walking page indices start: %lu end: %lu\n", start,
322                end);
323
324         for (i = start; i < end; i++) {
325                 ll_pgcache_lock(inode->i_mapping);
326                 if (list_empty(&inode->i_mapping->dirty_pages) &&
327                      list_empty(&inode->i_mapping->clean_pages) &&
328                      list_empty(&inode->i_mapping->locked_pages)) {
329                         CDEBUG(D_INODE, "nothing left\n");
330                         ll_pgcache_unlock(inode->i_mapping);
331                         break;
332                 }
333                 ll_pgcache_unlock(inode->i_mapping);
334
335                 conditional_schedule();
336
337                 page = find_get_page(inode->i_mapping, i);
338                 if (page == NULL)
339                         continue;
340
341                 LL_CDEBUG_PAGE(page, "locking\n");
342                 lock_page(page);
343
344                 /* page->mapping to check with racing against teardown */
345                 if (page->mapping && PageDirty(page) && !discard) {
346                         ClearPageDirty(page);
347                         LL_CDEBUG_PAGE(page, "found dirty\n");
348                         ll_pgcache_lock(inode->i_mapping);
349                         list_del(&page->list);
350                         list_add(&page->list, &inode->i_mapping->locked_pages);
351                         ll_pgcache_unlock(inode->i_mapping);
352
353 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
354                         rc = inode->i_mapping->a_ops->writepage(page);
355 #else
356                         rc = inode->i_mapping->a_ops->writepage(page, NULL);
357 #endif
358                         if (rc != 0)
359                                 CERROR("writepage of page %p failed: %d\n",
360                                        page, rc);
361                         /* either waiting for io to complete or reacquiring
362                          * the lock that the failed writepage released */
363                         lock_page(page);
364                 }
365
366                 /* checking again to account for writeback's lock_page() */
367                 if (page->mapping != NULL) {
368                         LL_CDEBUG_PAGE(page, "truncating\n");
369                         ll_truncate_complete_page(page);
370                 }
371                 unlock_page(page);
372                 page_cache_release(page);
373         }
374
375         if (test_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags)) {
376                 rc = obd_lock_contains(exp, lsm, lock, inode->i_size - 1);
377                 if (rc != 0) {
378                         if (rc < 0)
379                                 CERROR("obd_lock_contains: rc = %d\n", rc);
380                         clear_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags);
381                 }
382         }
383
384         EXIT;
385 }
386
387 static int ll_extent_lock_callback(struct ldlm_lock *lock,
388                                    struct ldlm_lock_desc *new, void *data,
389                                    int flag)
390 {
391         struct lustre_handle lockh = { 0 };
392         int rc;
393         ENTRY;
394
395
396         if ((unsigned long)data > 0 && (unsigned long)data < 0x1000) {
397                 LDLM_ERROR(lock, "cancelling lock with bad data %p", data);
398                 LBUG();
399         }
400
401         switch (flag) {
402         case LDLM_CB_BLOCKING:
403                 ldlm_lock2handle(lock, &lockh);
404                 rc = ldlm_cli_cancel(&lockh);
405                 if (rc != ELDLM_OK)
406                         CERROR("ldlm_cli_cancel failed: %d\n", rc);
407                 break;
408         case LDLM_CB_CANCELING: {
409                 struct inode *inode = ll_inode_from_lock(lock);
410                 struct ll_inode_info *lli;
411
412                 if (!inode)
413                         RETURN(0);
414                 lli= ll_i2info(inode);
415                 if (!lli)
416                         RETURN(0);
417                 if (!lli->lli_smd)
418                         RETURN(0);
419
420                 ll_pgcache_remove_extent(inode, lli->lli_smd, lock);
421                 //ll_try_done_writing(inode);
422                 iput(inode);
423                 break;
424         }
425         default:
426                 LBUG();
427         }
428
429         RETURN(0);
430 }
431
432 /*
433  * some callers, notably truncate, really don't want i_size set based
434  * on the the size returned by the getattr, or lock acquisition in
435  * the future.
436  */
437 int ll_extent_lock_no_validate(struct ll_file_data *fd, struct inode *inode,
438                    struct lov_stripe_md *lsm,
439                    int mode, struct ldlm_extent *extent,
440                    struct lustre_handle *lockh, int ast_flags)
441 {
442         struct ll_sb_info *sbi = ll_i2sbi(inode);
443         int rc;
444         ENTRY;
445
446         LASSERT(lockh->cookie == 0);
447
448         /* XXX phil: can we do this?  won't it screw the file size up? */
449         if ((fd && (fd->fd_flags & LL_FILE_IGNORE_LOCK)) ||
450             (sbi->ll_flags & LL_SBI_NOLCK))
451                 RETURN(0);
452
453         CDEBUG(D_DLMTRACE, "Locking inode %lu, start "LPU64" end "LPU64"\n",
454                inode->i_ino, extent->start, extent->end);
455
456         rc = obd_enqueue(sbi->ll_osc_exp, lsm, NULL, LDLM_EXTENT, extent,
457                          sizeof(extent), mode, &ast_flags,
458                          ll_extent_lock_callback, inode, lockh);
459         if (rc > 0)
460                 rc = -EIO;
461         RETURN(rc);
462 }
463
464 /*
465  * this grabs a lock and manually implements behaviour that makes it look like
466  * the OST is returning the file size with each lock acquisition.
467  */
468 int ll_extent_lock(struct ll_file_data *fd, struct inode *inode,
469                    struct lov_stripe_md *lsm, int mode,
470                    struct ldlm_extent *extent, struct lustre_handle *lockh)
471 {
472         struct ll_inode_info *lli = ll_i2info(inode);
473         struct obd_export *exp = ll_i2obdexp(inode);
474         struct ldlm_extent size_lock;
475         struct lustre_handle match_lockh = {0};
476         struct obdo oa;
477         obd_flag refresh_valid;
478         int flags, rc, matched;
479         ENTRY;
480
481         rc = ll_extent_lock_no_validate(fd, inode, lsm, mode, extent, lockh, 0);
482         if (rc != ELDLM_OK)
483                 RETURN(rc);
484
485         if (test_bit(LLI_F_HAVE_OST_SIZE_LOCK, &lli->lli_flags))
486                 RETURN(0);
487
488         rc = ll_lsm_getattr(exp, lsm, &oa);
489         if (rc) 
490                 GOTO(out, rc);
491
492         /* We set this flag in commit write as we extend the file size.  When
493          * the bit is set and the lock is canceled that covers the file size,
494          * we clear the bit.  This is enough to protect the window where our
495          * local size extension is needed for writeback.  However, it relies on
496          * behaviour that won't be true in the near future.  This assumes that
497          * all getattr callers get extent locks, which they currnetly do.  It
498          * also assumes that we only send discarding asts for {0,eof} truncates
499          * as is currently the case.  This will have to be replaced by the
500          * proper eoc communication between clients and the ost, which is on
501          * its way. */
502         refresh_valid = (OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME | 
503                          OBD_MD_FLCTIME | OBD_MD_FLSIZE);
504         if (test_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags)) {
505                 if (oa.o_size < inode->i_size)
506                         refresh_valid &= ~OBD_MD_FLSIZE;
507                 else 
508                         clear_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags);
509         }
510         obdo_refresh_inode(inode, &oa, refresh_valid);
511
512         CDEBUG(D_INODE, "objid "LPX64" size %Lu, blocks %lu, blksize %lu\n",
513                lsm->lsm_object_id, inode->i_size, inode->i_blocks,
514                inode->i_blksize);
515
516         size_lock.start = inode->i_size;
517         size_lock.end = OBD_OBJECT_EOF;
518
519         /* XXX I bet we should be checking the lock ignore flags.. */
520         flags = LDLM_FL_CBPENDING | LDLM_FL_BLOCK_GRANTED;
521         matched = obd_match(exp, lsm, LDLM_EXTENT, &size_lock,
522                             sizeof(size_lock), LCK_PR, &flags, inode,
523                             &match_lockh);
524         if (matched < 0)
525                 GOTO(out, rc = matched);
526
527         /* hey, alright, we hold a size lock that covers the size we
528          * just found, its not going to change for a while.. */
529         if (matched == 1) {
530                 set_bit(LLI_F_HAVE_OST_SIZE_LOCK, &lli->lli_flags);
531                 obd_cancel(exp, lsm, LCK_PR, &match_lockh);
532         }
533
534         rc = 0;
535 out:
536         if (rc)
537                 ll_extent_unlock(fd, inode, lsm, mode, lockh);
538         RETURN(rc);
539 }
540
541 int ll_extent_unlock(struct ll_file_data *fd, struct inode *inode,
542                      struct lov_stripe_md *lsm, int mode,
543                      struct lustre_handle *lockh)
544 {
545         struct ll_sb_info *sbi = ll_i2sbi(inode);
546         int rc;
547         ENTRY;
548
549         /* XXX phil: can we do this?  won't it screw the file size up? */
550         if ((fd && (fd->fd_flags & LL_FILE_IGNORE_LOCK)) ||
551             (sbi->ll_flags & LL_SBI_NOLCK))
552                 RETURN(0);
553
554         rc = obd_cancel(sbi->ll_osc_exp, lsm, mode, lockh);
555
556         RETURN(rc);
557 }
558
559 static ssize_t ll_file_read(struct file *filp, char *buf, size_t count,
560                             loff_t *ppos)
561 {
562         struct ll_file_data *fd = filp->private_data;
563         struct inode *inode = filp->f_dentry->d_inode;
564         struct ll_inode_info *lli = ll_i2info(inode);
565         struct lov_stripe_md *lsm = lli->lli_smd;
566         struct lustre_handle lockh = { 0 };
567         struct ldlm_extent extent;
568         ldlm_error_t err;
569         ssize_t retval;
570         ENTRY;
571         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),size="LPSZ",offset=%Ld\n",
572                inode->i_ino, inode->i_generation, inode, count, *ppos);
573
574         /* "If nbyte is 0, read() will return 0 and have no other results."
575          *                      -- Single Unix Spec */
576         if (count == 0)
577                 RETURN(0);
578
579         lprocfs_counter_add(ll_i2sbi(inode)->ll_stats, LPROC_LL_READ_BYTES,
580                             count);
581
582         if (!lsm)
583                 RETURN(0);
584
585         /* grab a -> eof extent to push extending writes out of node's caches
586          * so we can see them at the getattr after lock acquisition.  this will
587          * turn into a seperate [*ppos + count, EOF] 'size intent' lock attempt
588          * in the future. */
589         extent.start = *ppos;
590         extent.end = OBD_OBJECT_EOF;
591
592         err = ll_extent_lock(fd, inode, lsm, LCK_PR, &extent, &lockh);
593         if (err != ELDLM_OK)
594                 RETURN(err);
595
596
597         CDEBUG(D_INFO, "Reading inode %lu, "LPSZ" bytes, offset %Ld\n",
598                inode->i_ino, count, *ppos);
599
600         /* turn off the kernel's read-ahead */
601 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
602         filp->f_ramax = 0;
603 #else
604         filp->f_ra.ra_pages = 0;
605 #endif
606         retval = generic_file_read(filp, buf, count, ppos);
607
608         /* XXX errors? */
609         ll_extent_unlock(fd, inode, lsm, LCK_PR, &lockh);
610         RETURN(retval);
611 }
612
613 /*
614  * Write to a file (through the page cache).
615  */
616 static ssize_t ll_file_write(struct file *file, const char *buf, size_t count,
617                              loff_t *ppos)
618 {
619         struct ll_file_data *fd = file->private_data;
620         struct inode *inode = file->f_dentry->d_inode;
621         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
622         struct lustre_handle lockh = { 0 };
623         struct ldlm_extent extent;
624         loff_t maxbytes = ll_file_maxbytes(inode);
625         ldlm_error_t err;
626         ssize_t retval;
627         char should_validate = 1;
628         ENTRY;
629         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),size="LPSZ",offset=%Ld\n",
630                inode->i_ino, inode->i_generation, inode, count, *ppos);
631
632         SIGNAL_MASK_ASSERT(); /* XXX BUG 1511 */
633
634         /* POSIX, but surprised the VFS doesn't check this already */
635         if (count == 0)
636                 RETURN(0);
637
638         LASSERT(lsm);
639
640         if (file->f_flags & O_APPEND) {
641                 extent.start = 0;
642                 extent.end = OBD_OBJECT_EOF;
643         } else  {
644                 extent.start = *ppos;
645                 extent.end = *ppos + count - 1;
646                 /* we really don't care what i_size is if we're doing
647                  * fully page aligned writes */
648                 if ((*ppos & ~PAGE_CACHE_MASK) == 0 &&
649                     (count & ~PAGE_CACHE_MASK) == 0)
650                         should_validate = 0;
651         }
652
653         if (should_validate)
654                 err = ll_extent_lock(fd, inode, lsm, LCK_PW, &extent, &lockh);
655         else
656                 err = ll_extent_lock_no_validate(fd, inode, lsm, LCK_PW,
657                                                  &extent, &lockh, 0);
658         if (err != ELDLM_OK)
659                 RETURN(err);
660
661         /* this is ok, g_f_w will overwrite this under i_sem if it races
662          * with a local truncate, it just makes our maxbyte checking easier */
663         if (file->f_flags & O_APPEND)
664                 *ppos = inode->i_size;
665
666         if (*ppos >= maxbytes) {
667                 if (count || *ppos > maxbytes) {
668                         send_sig(SIGXFSZ, current, 0);
669                         GOTO(out, retval = -EFBIG);
670                 }
671         }
672         if (*ppos + count > maxbytes)
673                 count = maxbytes - *ppos;
674
675         CDEBUG(D_INFO, "Writing inode %lu, "LPSZ" bytes, offset %Lu\n",
676                inode->i_ino, count, *ppos);
677
678         /* generic_file_write handles O_APPEND after getting i_sem */
679         retval = generic_file_write(file, buf, count, ppos);
680
681 out:
682         /* XXX errors? */
683         lprocfs_counter_add(ll_i2sbi(inode)->ll_stats, LPROC_LL_WRITE_BYTES,
684                             retval);
685         ll_extent_unlock(fd, inode, lsm, LCK_PW, &lockh);
686         RETURN(retval);
687 }
688
689 static int ll_lov_recreate_obj(struct inode *inode, struct file *file,
690                                unsigned long arg)
691 {
692         struct ll_inode_info *lli = ll_i2info(inode);
693         struct obd_export *exp = ll_i2obdexp(inode);
694         struct ll_recreate_obj ucreatp;
695         struct obd_trans_info oti = { 0 };
696         struct obdo *oa = NULL;
697         int lsm_size;
698         int rc = 0;
699         struct lov_stripe_md *lsm, *lsm2;
700         ENTRY;
701
702         if (!capable (CAP_SYS_ADMIN))
703                 RETURN(-EPERM);
704
705         rc = copy_from_user(&ucreatp, (struct ll_recreate_obj *)arg, 
706                             sizeof(struct ll_recreate_obj));
707         if (rc) {
708                 RETURN(-EFAULT);
709         }
710         oa = obdo_alloc();
711         if (oa == NULL) {
712                 RETURN(-ENOMEM);
713         }
714
715         down(&lli->lli_open_sem);
716         lsm = lli->lli_smd;
717         if (lsm == NULL) {
718                 up(&lli->lli_open_sem);
719                 obdo_free(oa);
720                 RETURN (-ENOENT);
721         }
722         lsm_size = sizeof(*lsm) + (sizeof(struct lov_oinfo) *
723                    (lsm->lsm_stripe_count));
724
725         OBD_ALLOC(lsm2, lsm_size);
726         if (lsm2 == NULL) {
727                 up(&lli->lli_open_sem);
728                 obdo_free(oa);
729                 RETURN(-ENOMEM);
730         }
731
732         oa->o_id = ucreatp.lrc_id; 
733         oa->o_nlink = ucreatp.lrc_ost_idx;
734         oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS;
735         oa->o_flags |= OBD_FL_RECREATE_OBJS;
736         obdo_from_inode(oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
737                                    OBD_MD_FLMTIME | OBD_MD_FLCTIME);
738
739         oti.oti_objid = NULL;
740         memcpy(lsm2, lsm, lsm_size);
741         rc = obd_create(exp, oa, &lsm2, &oti);
742
743         up(&lli->lli_open_sem);
744         OBD_FREE(lsm2, lsm_size);
745         obdo_free(oa);
746         RETURN (rc);
747 }
748
749 static int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
750                                     int flags, struct lov_user_md *lum, int lum_size)
751 {
752         struct ll_inode_info *lli = ll_i2info(inode);
753         struct file *f;
754         struct obd_export *exp = ll_i2obdexp(inode);
755         struct lov_stripe_md *lsm;
756         struct lookup_intent oit = {.it_op = IT_OPEN, .it_flags = flags};
757         struct ptlrpc_request *req = NULL;
758         int rc = 0;
759         struct lustre_md md;
760         ENTRY;
761
762         down(&lli->lli_open_sem);
763         lsm = lli->lli_smd;
764         if (lsm) {
765                 up(&lli->lli_open_sem);
766                 CDEBUG(D_IOCTL, "stripe already exists for ino %lu\n",
767                        inode->i_ino);
768                 RETURN(-EEXIST);
769         }
770
771         f = get_empty_filp();
772         if (!f)
773                 GOTO(out, -ENOMEM);
774
775         f->f_dentry = file->f_dentry;
776         f->f_vfsmnt = file->f_vfsmnt;
777
778         rc = ll_intent_file_open(f, lum, lum_size, &oit);
779         if (rc)
780                 GOTO(out, rc);
781         if (it_disposition(&oit, DISP_LOOKUP_NEG))
782                 GOTO(out, -ENOENT);
783         req = oit.d.lustre.it_data;
784         rc = oit.d.lustre.it_status;
785
786         if (rc < 0)
787                 GOTO(out, rc);
788
789         rc = mdc_req2lustre_md(req, 1, exp, &md);
790         if (rc)
791                 GOTO(out, rc);
792         ll_update_inode(f->f_dentry->d_inode, md.body, md.lsm);
793
794         rc = ll_local_open(f, &oit);
795         if (rc)
796                 GOTO(out, rc);
797         ll_intent_release(&oit);
798
799         rc = ll_file_release(f->f_dentry->d_inode, f);
800
801  out:
802         if (f)
803                 put_filp(f);
804         up(&lli->lli_open_sem);
805         if (req != NULL)
806                 ptlrpc_req_finished(req);
807         RETURN(rc);
808 }
809
810 static int ll_lov_setea(struct inode *inode, struct file *file,
811                             unsigned long arg)
812 {
813         int flags = MDS_OPEN_HAS_OBJS | FMODE_WRITE;
814         struct lov_user_md  *lump;
815         int lum_size = sizeof(struct lov_user_md) + 
816                        sizeof(struct lov_user_ost_data);
817         int rc;
818         ENTRY;
819
820         if (!capable (CAP_SYS_ADMIN))
821                 RETURN(-EPERM);
822
823         OBD_ALLOC(lump, lum_size);
824         if (lump == NULL) {
825                 RETURN(-ENOMEM);
826         }
827         rc = copy_from_user(lump, (struct lov_user_md  *)arg, 
828                             lum_size);
829         if (rc) {
830                 OBD_FREE(lump, lum_size);
831                 RETURN(-EFAULT);
832         }
833
834         rc = ll_lov_setstripe_ea_info(inode, file, flags, lump, lum_size);
835
836         OBD_FREE(lump, lum_size);
837         RETURN(rc);
838 }
839
840 static int ll_lov_setstripe(struct inode *inode, struct file *file,
841                             unsigned long arg)
842 {
843         struct lov_user_md lum, *lump = (struct lov_user_md *)arg;
844         int rc;
845         int flags = FMODE_WRITE;
846         ENTRY;
847
848         /* Bug 1152: copy properly when this is no longer true */
849         LASSERT(sizeof(lum) == sizeof(*lump));
850         LASSERT(sizeof(lum.lmm_objects[0]) == sizeof(lump->lmm_objects[0]));
851         rc = copy_from_user(&lum, lump, sizeof(lum));
852         if (rc)
853                 RETURN(-EFAULT);
854
855         rc = ll_lov_setstripe_ea_info(inode, file, flags, &lum, sizeof(lum));
856         RETURN(rc);
857 }
858
859 static int ll_lov_getstripe(struct inode *inode, unsigned long arg)
860 {
861         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
862
863         if (!lsm)
864                 RETURN(-ENODATA);
865
866         return obd_iocontrol(LL_IOC_LOV_GETSTRIPE, ll_i2obdexp(inode), 0, lsm,
867                             (void *)arg);
868 }
869
870 int ll_file_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
871                   unsigned long arg)
872 {
873         struct ll_file_data *fd = file->private_data;
874         int flags;
875         ENTRY;
876
877         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),cmd=%x\n", inode->i_ino,
878                inode->i_generation, inode, cmd);
879
880         if (_IOC_TYPE(cmd) == 'T') /* tty ioctls */
881                 RETURN(-ENOTTY);
882
883         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_IOCTL);
884         switch(cmd) {
885         case LL_IOC_GETFLAGS:
886                 /* Get the current value of the file flags */
887                 return put_user(fd->fd_flags, (int *)arg);
888         case LL_IOC_SETFLAGS:
889         case LL_IOC_CLRFLAGS:
890                 /* Set or clear specific file flags */
891                 /* XXX This probably needs checks to ensure the flags are
892                  *     not abused, and to handle any flag side effects.
893                  */
894                 if (get_user(flags, (int *) arg))
895                         RETURN(-EFAULT);
896
897                 if (cmd == LL_IOC_SETFLAGS)
898                         fd->fd_flags |= flags;
899                 else
900                         fd->fd_flags &= ~flags;
901                 RETURN(0);
902         case LL_IOC_LOV_SETSTRIPE:
903                 RETURN(ll_lov_setstripe(inode, file, arg));
904         case LL_IOC_LOV_SETEA:
905                 RETURN( ll_lov_setea(inode, file, arg) ); 
906         case LL_IOC_LOV_GETSTRIPE:
907                 RETURN(ll_lov_getstripe(inode, arg));
908         case LL_IOC_RECREATE_OBJ:
909                 RETURN(ll_lov_recreate_obj(inode, file, arg));
910         case EXT3_IOC_GETFLAGS:
911         case EXT3_IOC_SETFLAGS:
912                 RETURN( ll_iocontrol(inode, file, cmd, arg) );
913         /* We need to special case any other ioctls we want to handle,
914          * to send them to the MDS/OST as appropriate and to properly
915          * network encode the arg field.
916         case EXT2_IOC_GETVERSION_OLD:
917         case EXT2_IOC_GETVERSION_NEW:
918         case EXT2_IOC_SETVERSION_OLD:
919         case EXT2_IOC_SETVERSION_NEW:
920         */
921         default:
922                 RETURN( obd_iocontrol(cmd, ll_i2obdexp(inode), 0, NULL,
923                                       (void *)arg) );
924         }
925 }
926
927 loff_t ll_file_seek(struct file *file, loff_t offset, int origin)
928 {
929         struct inode *inode = file->f_dentry->d_inode;
930         struct ll_file_data *fd = file->private_data;
931         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
932         struct lustre_handle lockh = {0};
933         loff_t retval;
934         ENTRY;
935         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),to=%llu\n", inode->i_ino,
936                inode->i_generation, inode,
937                offset + ((origin==2) ? inode->i_size : file->f_pos));
938
939         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_LLSEEK);
940         if (origin == 2) { /* SEEK_END */
941                 ldlm_error_t err;
942                 struct ldlm_extent extent = {0, OBD_OBJECT_EOF};
943                 err = ll_extent_lock(fd, inode, lsm, LCK_PR, &extent, &lockh);
944                 if (err != ELDLM_OK)
945                         RETURN(err);
946
947                 offset += inode->i_size;
948         } else if (origin == 1) { /* SEEK_CUR */
949                 offset += file->f_pos;
950         }
951
952         retval = -EINVAL;
953         if (offset >= 0 && offset <= ll_file_maxbytes(inode)) {
954                 if (offset != file->f_pos) {
955                         file->f_pos = offset;
956 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
957                         file->f_reada = 0;
958                         file->f_version = ++event;
959 #endif
960                 }
961                 retval = offset;
962         }
963
964         if (origin == 2)
965                 ll_extent_unlock(fd, inode, lsm, LCK_PR, &lockh);
966         RETURN(retval);
967 }
968
969 int ll_fsync(struct file *file, struct dentry *dentry, int data)
970 {
971         struct inode *inode = dentry->d_inode;
972         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
973         struct ll_fid fid;
974         struct ptlrpc_request *req;
975         int rc, err;
976         ENTRY;
977         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
978                inode->i_generation, inode);
979
980         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_FSYNC);
981
982         /* fsync's caller has already called _fdata{sync,write}, we want
983          * that IO to finish before calling the osc and mdc sync methods */
984         rc = filemap_fdatawait(inode->i_mapping);
985
986         ll_inode2fid(&fid, inode);
987         err = mdc_sync(ll_i2sbi(inode)->ll_mdc_exp, &fid, &req);
988         if (!rc)
989                 rc = err;
990         if (!err)
991                 ptlrpc_req_finished(req);
992
993         if (data && lsm) {
994                 struct obdo *oa = obdo_alloc();
995
996                 if (!oa)
997                         RETURN(rc ? rc : -ENOMEM);
998
999                 oa->o_id = lsm->lsm_object_id;
1000                 oa->o_valid = OBD_MD_FLID;
1001                 obdo_from_inode(oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
1002                                            OBD_MD_FLMTIME | OBD_MD_FLCTIME);
1003
1004                 err = obd_sync(ll_i2sbi(inode)->ll_osc_exp, oa, lsm,
1005                                0, OBD_OBJECT_EOF);
1006                 if (!rc)
1007                         rc = err;
1008                 obdo_free(oa);
1009         }
1010
1011         RETURN(rc);
1012 }
1013
1014 int ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
1015 {
1016         struct inode *inode = file->f_dentry->d_inode;
1017         struct ll_sb_info *sbi = ll_i2sbi(inode);
1018         struct obd_device *obddev;
1019         struct ldlm_res_id res_id =
1020                     { .name = {inode->i_ino, inode->i_generation, LDLM_FLOCK} };
1021         struct lustre_handle lockh = {0};
1022         struct ldlm_flock flock;
1023         ldlm_mode_t mode = 0;
1024         int flags = 0;
1025         int rc;
1026         ENTRY;
1027
1028         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu file_lock=%p\n",
1029                inode->i_ino, file_lock);
1030
1031         flock.pid = file_lock->fl_pid;
1032         flock.start = file_lock->fl_start;
1033         flock.end = file_lock->fl_end;
1034
1035         switch (file_lock->fl_type) {
1036         case F_RDLCK:
1037                 mode = LCK_PR;
1038                 break;
1039         case F_UNLCK:
1040                 /* An unlock request may or may not have any relation to
1041                  * existing locks so we may not be able to pass a lock handle
1042                  * via a normal ldlm_lock_cancel() request. The request may even
1043                  * unlock a byte range in the middle of an existing lock. In
1044                  * order to process an unlock request we need all of the same
1045                  * information that is given with a normal read or write record
1046                  * lock request. To avoid creating another ldlm unlock (cancel)
1047                  * message we'll treat a LCK_NL flock request as an unlock. */
1048                 mode = LCK_NL;
1049                 break;
1050         case F_WRLCK:
1051                 mode = LCK_PW;
1052                 break;
1053         default:
1054                 CERROR("unknown fcntl lock type: %d\n", file_lock->fl_type);
1055                 LBUG();
1056         }
1057
1058         switch (cmd) {
1059         case F_SETLKW:
1060                 flags = 0;
1061                 break;
1062         case F_SETLK:
1063                 flags = LDLM_FL_BLOCK_NOWAIT;
1064                 break;
1065         case F_GETLK:
1066                 flags = LDLM_FL_TEST_LOCK;
1067                 /* Save the old mode so that if the mode in the lock changes we
1068                  * can decrement the appropriate reader or writer refcount. */
1069                 file_lock->fl_type = mode;
1070                 break;
1071         default:
1072                 CERROR("unknown fcntl lock command: %d\n", cmd);
1073                 LBUG();
1074         }
1075
1076         CDEBUG(D_DLMTRACE, "inode=%lu, pid=%u, flags=%#x, mode=%u, "
1077                "start="LPU64", end="LPU64"\n", inode->i_ino, flock.pid,
1078                flags, mode, flock.start, flock.end);
1079
1080         obddev = sbi->ll_mdc_exp->exp_obd;
1081         rc = ldlm_cli_enqueue(sbi->ll_mdc_exp, NULL, obddev->obd_namespace,
1082                               NULL, res_id, LDLM_FLOCK, &flock, sizeof(flock),
1083                               mode, &flags, ldlm_flock_completion_ast, NULL,
1084                               file_lock, &lockh);
1085         RETURN(rc);
1086 }
1087
1088 static int ll_have_md_lock(struct dentry *de)
1089 {
1090         struct ll_sb_info *sbi = ll_s2sbi(de->d_sb);
1091         struct lustre_handle lockh;
1092         struct ldlm_res_id res_id = { .name = {0} };
1093         struct obd_device *obddev;
1094         int flags;
1095         ENTRY;
1096
1097         if (!de->d_inode)
1098                RETURN(0);
1099
1100         obddev = sbi->ll_mdc_exp->exp_obd;
1101         res_id.name[0] = de->d_inode->i_ino;
1102         res_id.name[1] = de->d_inode->i_generation;
1103
1104         CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
1105
1106         flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
1107         if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_PLAIN,
1108                             NULL, 0, LCK_PR, &lockh)) {
1109                 ldlm_lock_decref(&lockh, LCK_PR);
1110                 RETURN(1);
1111         }
1112
1113         if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_PLAIN,
1114                             NULL, 0, LCK_PW, &lockh)) {
1115                 ldlm_lock_decref(&lockh, LCK_PW);
1116                 RETURN(1);
1117         }
1118         RETURN(0);
1119 }
1120
1121 int ll_inode_revalidate_it(struct dentry *dentry, struct lookup_intent *it)
1122 {
1123         struct inode *inode = dentry->d_inode;
1124         struct lov_stripe_md *lsm;
1125         ENTRY;
1126
1127         if (!inode) {
1128                 CERROR("REPORT THIS LINE TO PETER\n");
1129                 RETURN(0);
1130         }
1131         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),name=%s\n",
1132                inode->i_ino, inode->i_generation, inode, dentry->d_name.name);
1133 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0))
1134         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_REVALIDATE);
1135 #endif
1136
1137         if (!ll_have_md_lock(dentry)) {
1138                 struct ptlrpc_request *req = NULL;
1139                 struct ll_sb_info *sbi = ll_i2sbi(dentry->d_inode);
1140                 struct ll_fid fid;
1141                 unsigned long valid = 0;
1142                 int rc, ealen = 0;
1143
1144                 if (S_ISREG(inode->i_mode)) {
1145                         ealen = obd_size_diskmd(sbi->ll_osc_exp, NULL);
1146                         valid |= OBD_MD_FLEASIZE;
1147                 }
1148                 ll_inode2fid(&fid, inode);
1149                 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, valid, ealen, &req);
1150                 if (rc) {
1151                         CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1152                         RETURN(-abs(rc));
1153                 }
1154                 rc = ll_prep_inode(sbi->ll_osc_exp, &inode, req, 0, NULL);
1155                 if (rc) {
1156                         ptlrpc_req_finished(req);
1157                         RETURN(rc);
1158                 }
1159                 ptlrpc_req_finished(req);
1160         }
1161
1162 #if 0
1163         if (ll_have_md_lock(dentry) &&
1164             test_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &ll_i2info(inode)->lli_flags))
1165                 RETURN(0);
1166 #endif
1167
1168         lsm = ll_i2info(inode)->lli_smd;
1169         if (!lsm)       /* object not yet allocated, don't validate size */
1170                 RETURN(0);
1171
1172         /* unfortunately stat comes in through revalidate and we don't
1173          * differentiate this use from initial instantiation.  we're
1174          * also being wildly conservative and flushing write caches
1175          * so that stat really returns the proper size. */
1176         {
1177                 struct ldlm_extent extent = {0, OBD_OBJECT_EOF};
1178                 struct lustre_handle lockh = {0};
1179                 ldlm_error_t err;
1180
1181                 err = ll_extent_lock(NULL, inode, lsm, LCK_PR, &extent, &lockh);
1182                 if (err != ELDLM_OK)
1183                         RETURN(err);
1184
1185                 ll_extent_unlock(NULL, inode, lsm, LCK_PR, &lockh);
1186         }
1187         RETURN(0);
1188 }
1189
1190 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1191 int ll_getattr(struct vfsmount *mnt, struct dentry *de,
1192                struct lookup_intent *it, struct kstat *stat)
1193 {
1194         int res = 0;
1195         struct inode *inode = de->d_inode;
1196
1197         res = ll_inode_revalidate_it(de, it);
1198         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_GETATTR);
1199
1200         if (res)
1201                 return res;
1202
1203         stat->dev = inode->i_sb->s_dev;
1204         stat->ino = inode->i_ino;
1205         stat->mode = inode->i_mode;
1206         stat->nlink = inode->i_nlink;
1207         stat->uid = inode->i_uid;
1208         stat->gid = inode->i_gid;
1209         stat->rdev = kdev_t_to_nr(inode->i_rdev);
1210         stat->atime = inode->i_atime;
1211         stat->mtime = inode->i_mtime;
1212         stat->ctime = inode->i_ctime;
1213         stat->size = inode->i_size;
1214         stat->blksize = inode->i_blksize;
1215         stat->blocks = inode->i_blocks;
1216         return 0;
1217 }
1218 #endif
1219
1220 struct file_operations ll_file_operations = {
1221         read:           ll_file_read,
1222         write:          ll_file_write,
1223         ioctl:          ll_file_ioctl,
1224         open:           ll_file_open,
1225         release:        ll_file_release,
1226         mmap:           generic_file_mmap,
1227         llseek:         ll_file_seek,
1228         fsync:          ll_fsync,
1229         //lock:           ll_file_flock
1230 };
1231
1232 struct inode_operations ll_file_inode_operations = {
1233         setattr_raw:    ll_setattr_raw,
1234         setattr:        ll_setattr,
1235         truncate:       ll_truncate,
1236 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1237         getattr_it:     ll_getattr,
1238 #else
1239         revalidate_it:  ll_inode_revalidate_it,
1240 #endif
1241 };
1242
1243 struct inode_operations ll_special_inode_operations = {
1244         setattr_raw:    ll_setattr_raw,
1245         setattr:        ll_setattr,
1246 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1247         getattr_it:     ll_getattr,
1248 #else
1249         revalidate_it:  ll_inode_revalidate_it,
1250 #endif
1251 };