Whamcloud - gitweb
85e5cdc156c039748fdffea0f7f4d2f4fc0f09dd
[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 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
370                         truncate_complete_page(page);
371 #else
372                         truncate_complete_page(page->mapping, page);
373 #endif
374                 }
375                 unlock_page(page);
376                 page_cache_release(page);
377         }
378
379         if (test_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags)) {
380                 rc = obd_lock_contains(exp, lsm, lock, inode->i_size - 1);
381                 if (rc != 0) {
382                         if (rc < 0)
383                                 CERROR("obd_lock_contains: rc = %d\n", rc);
384                         clear_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags);
385                 }
386         }
387
388         EXIT;
389 }
390
391 static int ll_extent_lock_callback(struct ldlm_lock *lock,
392                                    struct ldlm_lock_desc *new, void *data,
393                                    int flag)
394 {
395         struct lustre_handle lockh = { 0 };
396         int rc;
397         ENTRY;
398
399
400         if ((unsigned long)data > 0 && (unsigned long)data < 0x1000) {
401                 LDLM_ERROR(lock, "cancelling lock with bad data %p", data);
402                 LBUG();
403         }
404
405         switch (flag) {
406         case LDLM_CB_BLOCKING:
407                 ldlm_lock2handle(lock, &lockh);
408                 rc = ldlm_cli_cancel(&lockh);
409                 if (rc != ELDLM_OK)
410                         CERROR("ldlm_cli_cancel failed: %d\n", rc);
411                 break;
412         case LDLM_CB_CANCELING: {
413                 struct inode *inode = ll_inode_from_lock(lock);
414                 struct ll_inode_info *lli;
415
416                 if (!inode)
417                         RETURN(0);
418                 lli= ll_i2info(inode);
419                 if (!lli)
420                         RETURN(0);
421                 if (!lli->lli_smd)
422                         RETURN(0);
423
424                 ll_pgcache_remove_extent(inode, lli->lli_smd, lock);
425                 //ll_try_done_writing(inode);
426                 iput(inode);
427                 break;
428         }
429         default:
430                 LBUG();
431         }
432
433         RETURN(0);
434 }
435
436 /*
437  * some callers, notably truncate, really don't want i_size set based
438  * on the the size returned by the getattr, or lock acquisition in
439  * the future.
440  */
441 int ll_extent_lock_no_validate(struct ll_file_data *fd, struct inode *inode,
442                    struct lov_stripe_md *lsm,
443                    int mode, struct ldlm_extent *extent,
444                    struct lustre_handle *lockh, int ast_flags)
445 {
446         struct ll_sb_info *sbi = ll_i2sbi(inode);
447         int rc;
448         ENTRY;
449
450         LASSERT(lockh->cookie == 0);
451
452         /* XXX phil: can we do this?  won't it screw the file size up? */
453         if ((fd && (fd->fd_flags & LL_FILE_IGNORE_LOCK)) ||
454             (sbi->ll_flags & LL_SBI_NOLCK))
455                 RETURN(0);
456
457         CDEBUG(D_DLMTRACE, "Locking inode %lu, start "LPU64" end "LPU64"\n",
458                inode->i_ino, extent->start, extent->end);
459
460         rc = obd_enqueue(sbi->ll_osc_exp, lsm, NULL, LDLM_EXTENT, extent,
461                          sizeof(extent), mode, &ast_flags,
462                          ll_extent_lock_callback, inode, lockh);
463         if (rc > 0)
464                 rc = -EIO;
465         RETURN(rc);
466 }
467
468 /*
469  * this grabs a lock and manually implements behaviour that makes it look like
470  * the OST is returning the file size with each lock acquisition.
471  */
472 int ll_extent_lock(struct ll_file_data *fd, struct inode *inode,
473                    struct lov_stripe_md *lsm, int mode,
474                    struct ldlm_extent *extent, struct lustre_handle *lockh)
475 {
476         struct ll_inode_info *lli = ll_i2info(inode);
477         struct obd_export *exp = ll_i2obdexp(inode);
478         struct ldlm_extent size_lock;
479         struct lustre_handle match_lockh = {0};
480         struct obdo oa;
481         obd_flag refresh_valid;
482         int flags, rc, matched;
483         ENTRY;
484
485         rc = ll_extent_lock_no_validate(fd, inode, lsm, mode, extent, lockh, 0);
486         if (rc != ELDLM_OK)
487                 RETURN(rc);
488
489         if (test_bit(LLI_F_HAVE_OST_SIZE_LOCK, &lli->lli_flags))
490                 RETURN(0);
491
492         rc = ll_lsm_getattr(exp, lsm, &oa);
493         if (rc) 
494                 GOTO(out, rc);
495
496         /* We set this flag in commit write as we extend the file size.  When
497          * the bit is set and the lock is canceled that covers the file size,
498          * we clear the bit.  This is enough to protect the window where our
499          * local size extension is needed for writeback.  However, it relies on
500          * behaviour that won't be true in the near future.  This assumes that
501          * all getattr callers get extent locks, which they currnetly do.  It
502          * also assumes that we only send discarding asts for {0,eof} truncates
503          * as is currently the case.  This will have to be replaced by the
504          * proper eoc communication between clients and the ost, which is on
505          * its way. */
506         refresh_valid = (OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ | OBD_MD_FLMTIME | 
507                          OBD_MD_FLCTIME | OBD_MD_FLSIZE);
508         if (test_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags)) {
509                 if (oa.o_size < inode->i_size)
510                         refresh_valid &= ~OBD_MD_FLSIZE;
511                 else 
512                         clear_bit(LLI_F_PREFER_EXTENDED_SIZE, &lli->lli_flags);
513         }
514         obdo_refresh_inode(inode, &oa, refresh_valid);
515
516         CDEBUG(D_INODE, "objid "LPX64" size %Lu, blocks %lu, blksize %lu\n",
517                lsm->lsm_object_id, inode->i_size, inode->i_blocks,
518                inode->i_blksize);
519
520         size_lock.start = inode->i_size;
521         size_lock.end = OBD_OBJECT_EOF;
522
523         /* XXX I bet we should be checking the lock ignore flags.. */
524         flags = LDLM_FL_CBPENDING | LDLM_FL_BLOCK_GRANTED;
525         matched = obd_match(exp, lsm, LDLM_EXTENT, &size_lock,
526                             sizeof(size_lock), LCK_PR, &flags, inode,
527                             &match_lockh);
528         if (matched < 0)
529                 GOTO(out, rc = matched);
530
531         /* hey, alright, we hold a size lock that covers the size we
532          * just found, its not going to change for a while.. */
533         if (matched == 1) {
534                 set_bit(LLI_F_HAVE_OST_SIZE_LOCK, &lli->lli_flags);
535                 obd_cancel(exp, lsm, LCK_PR, &match_lockh);
536         }
537
538         rc = 0;
539 out:
540         if (rc)
541                 ll_extent_unlock(fd, inode, lsm, mode, lockh);
542         RETURN(rc);
543 }
544
545 int ll_extent_unlock(struct ll_file_data *fd, struct inode *inode,
546                      struct lov_stripe_md *lsm, int mode,
547                      struct lustre_handle *lockh)
548 {
549         struct ll_sb_info *sbi = ll_i2sbi(inode);
550         int rc;
551         ENTRY;
552
553         /* XXX phil: can we do this?  won't it screw the file size up? */
554         if ((fd && (fd->fd_flags & LL_FILE_IGNORE_LOCK)) ||
555             (sbi->ll_flags & LL_SBI_NOLCK))
556                 RETURN(0);
557
558         rc = obd_cancel(sbi->ll_osc_exp, lsm, mode, lockh);
559
560         RETURN(rc);
561 }
562
563 static ssize_t ll_file_read(struct file *filp, char *buf, size_t count,
564                             loff_t *ppos)
565 {
566         struct ll_file_data *fd = filp->private_data;
567         struct inode *inode = filp->f_dentry->d_inode;
568         struct ll_inode_info *lli = ll_i2info(inode);
569         struct lov_stripe_md *lsm = lli->lli_smd;
570         struct lustre_handle lockh = { 0 };
571         struct ldlm_extent extent;
572         ldlm_error_t err;
573         ssize_t retval;
574         ENTRY;
575         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),size="LPSZ",offset=%Ld\n",
576                inode->i_ino, inode->i_generation, inode, count, *ppos);
577
578         /* "If nbyte is 0, read() will return 0 and have no other results."
579          *                      -- Single Unix Spec */
580         if (count == 0)
581                 RETURN(0);
582
583         lprocfs_counter_add(ll_i2sbi(inode)->ll_stats, LPROC_LL_READ_BYTES,
584                             count);
585
586         if (!lsm)
587                 RETURN(0);
588
589         /* grab a -> eof extent to push extending writes out of node's caches
590          * so we can see them at the getattr after lock acquisition.  this will
591          * turn into a seperate [*ppos + count, EOF] 'size intent' lock attempt
592          * in the future. */
593         extent.start = *ppos;
594         extent.end = OBD_OBJECT_EOF;
595
596         err = ll_extent_lock(fd, inode, lsm, LCK_PR, &extent, &lockh);
597         if (err != ELDLM_OK)
598                 RETURN(err);
599
600
601         CDEBUG(D_INFO, "Reading inode %lu, "LPSZ" bytes, offset %Ld\n",
602                inode->i_ino, count, *ppos);
603
604         /* turn off the kernel's read-ahead */
605 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
606         filp->f_ramax = 0;
607 #else
608         filp->f_ra.ra_pages = 0;
609 #endif
610         retval = generic_file_read(filp, buf, count, ppos);
611
612         /* XXX errors? */
613         ll_extent_unlock(fd, inode, lsm, LCK_PR, &lockh);
614         RETURN(retval);
615 }
616
617 /*
618  * Write to a file (through the page cache).
619  */
620 static ssize_t ll_file_write(struct file *file, const char *buf, size_t count,
621                              loff_t *ppos)
622 {
623         struct ll_file_data *fd = file->private_data;
624         struct inode *inode = file->f_dentry->d_inode;
625         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
626         struct lustre_handle lockh = { 0 };
627         struct ldlm_extent extent;
628         loff_t maxbytes = ll_file_maxbytes(inode);
629         ldlm_error_t err;
630         ssize_t retval;
631         char should_validate = 1;
632         ENTRY;
633         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),size="LPSZ",offset=%Ld\n",
634                inode->i_ino, inode->i_generation, inode, count, *ppos);
635
636         SIGNAL_MASK_ASSERT(); /* XXX BUG 1511 */
637
638         /* POSIX, but surprised the VFS doesn't check this already */
639         if (count == 0)
640                 RETURN(0);
641
642         LASSERT(lsm);
643
644         if (file->f_flags & O_APPEND) {
645                 extent.start = 0;
646                 extent.end = OBD_OBJECT_EOF;
647         } else  {
648                 extent.start = *ppos;
649                 extent.end = *ppos + count - 1;
650                 /* we really don't care what i_size is if we're doing
651                  * fully page aligned writes */
652                 if ((*ppos & ~PAGE_CACHE_MASK) == 0 &&
653                     (count & ~PAGE_CACHE_MASK) == 0)
654                         should_validate = 0;
655         }
656
657         if (should_validate)
658                 err = ll_extent_lock(fd, inode, lsm, LCK_PW, &extent, &lockh);
659         else
660                 err = ll_extent_lock_no_validate(fd, inode, lsm, LCK_PW,
661                                                  &extent, &lockh, 0);
662         if (err != ELDLM_OK)
663                 RETURN(err);
664
665         /* this is ok, g_f_w will overwrite this under i_sem if it races
666          * with a local truncate, it just makes our maxbyte checking easier */
667         if (file->f_flags & O_APPEND)
668                 *ppos = inode->i_size;
669
670         if (*ppos >= maxbytes) {
671                 if (count || *ppos > maxbytes) {
672                         send_sig(SIGXFSZ, current, 0);
673                         GOTO(out, retval = -EFBIG);
674                 }
675         }
676         if (*ppos + count > maxbytes)
677                 count = maxbytes - *ppos;
678
679         CDEBUG(D_INFO, "Writing inode %lu, "LPSZ" bytes, offset %Lu\n",
680                inode->i_ino, count, *ppos);
681
682         /* generic_file_write handles O_APPEND after getting i_sem */
683         retval = generic_file_write(file, buf, count, ppos);
684
685 out:
686         /* XXX errors? */
687         lprocfs_counter_add(ll_i2sbi(inode)->ll_stats, LPROC_LL_WRITE_BYTES,
688                             retval);
689         ll_extent_unlock(fd, inode, lsm, LCK_PW, &lockh);
690         RETURN(retval);
691 }
692
693 static int ll_lov_recreate_obj(struct inode *inode, struct file *file,
694                                unsigned long arg)
695 {
696         struct ll_inode_info *lli = ll_i2info(inode);
697         struct obd_export *exp = ll_i2obdexp(inode);
698         struct ll_recreate_obj ucreatp;
699         struct obd_trans_info oti = { 0 };
700         struct obdo *oa = NULL;
701         int lsm_size;
702         int rc = 0;
703         struct lov_stripe_md *lsm, *lsm2;
704         ENTRY;
705
706         if (!capable (CAP_SYS_ADMIN))
707                 RETURN(-EPERM);
708
709         rc = copy_from_user(&ucreatp, (struct ll_recreate_obj *)arg, 
710                             sizeof(struct ll_recreate_obj));
711         if (rc) {
712                 RETURN(-EFAULT);
713         }
714         oa = obdo_alloc();
715         if (oa == NULL) {
716                 RETURN(-ENOMEM);
717         }
718
719         down(&lli->lli_open_sem);
720         lsm = lli->lli_smd;
721         if (lsm == NULL) {
722                 up(&lli->lli_open_sem);
723                 obdo_free(oa);
724                 RETURN (-ENOENT);
725         }
726         lsm_size = sizeof(*lsm) + (sizeof(struct lov_oinfo) *
727                    (lsm->lsm_stripe_count));
728
729         OBD_ALLOC(lsm2, lsm_size);
730         if (lsm2 == NULL) {
731                 up(&lli->lli_open_sem);
732                 obdo_free(oa);
733                 RETURN(-ENOMEM);
734         }
735
736         oa->o_id = ucreatp.lrc_id; 
737         oa->o_nlink = ucreatp.lrc_ost_idx;
738         oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS;
739         oa->o_flags |= OBD_FL_RECREATE_OBJS;
740         obdo_from_inode(oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
741                                    OBD_MD_FLMTIME | OBD_MD_FLCTIME);
742
743         oti.oti_objid = NULL;
744         memcpy(lsm2, lsm, lsm_size);
745         rc = obd_create(exp, oa, &lsm2, &oti);
746
747         up(&lli->lli_open_sem);
748         OBD_FREE(lsm2, lsm_size);
749         obdo_free(oa);
750         RETURN (rc);
751 }
752
753 static int ll_lov_setstripe_ea_info(struct inode *inode, struct file *file,
754                                     int flags, struct lov_user_md *lum, int lum_size)
755 {
756         struct ll_inode_info *lli = ll_i2info(inode);
757         struct file *f;
758         struct obd_export *exp = ll_i2obdexp(inode);
759         struct lov_stripe_md *lsm;
760         struct lookup_intent oit = {.it_op = IT_OPEN, .it_flags = flags};
761         struct ptlrpc_request *req = NULL;
762         int rc = 0;
763         struct lustre_md md;
764         ENTRY;
765
766         down(&lli->lli_open_sem);
767         lsm = lli->lli_smd;
768         if (lsm) {
769                 up(&lli->lli_open_sem);
770                 CDEBUG(D_IOCTL, "stripe already exists for ino %lu\n",
771                        inode->i_ino);
772                 RETURN(-EEXIST);
773         }
774
775         f = get_empty_filp();
776         if (!f)
777                 GOTO(out, -ENOMEM);
778
779         f->f_dentry = file->f_dentry;
780         f->f_vfsmnt = file->f_vfsmnt;
781
782         rc = ll_intent_file_open(f, lum, lum_size, &oit);
783         if (rc)
784                 GOTO(out, rc);
785         if (it_disposition(&oit, DISP_LOOKUP_NEG))
786                 GOTO(out, -ENOENT);
787         req = oit.d.lustre.it_data;
788         rc = oit.d.lustre.it_status;
789
790         if (rc < 0)
791                 GOTO(out, rc);
792
793         rc = mdc_req2lustre_md(req, 1, exp, &md);
794         if (rc)
795                 GOTO(out, rc);
796         ll_update_inode(f->f_dentry->d_inode, md.body, md.lsm);
797
798         rc = ll_local_open(f, &oit);
799         if (rc)
800                 GOTO(out, rc);
801         ll_intent_release(&oit);
802
803         rc = ll_file_release(f->f_dentry->d_inode, f);
804
805  out:
806         if (f)
807                 put_filp(f);
808         up(&lli->lli_open_sem);
809         if (req != NULL)
810                 ptlrpc_req_finished(req);
811         RETURN(rc);
812 }
813
814 static int ll_lov_setea(struct inode *inode, struct file *file,
815                             unsigned long arg)
816 {
817         int flags = MDS_OPEN_HAS_OBJS | FMODE_WRITE;
818         struct lov_user_md  *lump;
819         int lum_size = sizeof(struct lov_user_md) + 
820                        sizeof(struct lov_user_ost_data);
821         int rc;
822         ENTRY;
823
824         if (!capable (CAP_SYS_ADMIN))
825                 RETURN(-EPERM);
826
827         OBD_ALLOC(lump, lum_size);
828         if (lump == NULL) {
829                 RETURN(-ENOMEM);
830         }
831         rc = copy_from_user(lump, (struct lov_user_md  *)arg, 
832                             lum_size);
833         if (rc) {
834                 OBD_FREE(lump, lum_size);
835                 RETURN(-EFAULT);
836         }
837
838         rc = ll_lov_setstripe_ea_info(inode, file, flags, lump, lum_size);
839
840         OBD_FREE(lump, lum_size);
841         RETURN(rc);
842 }
843
844 static int ll_lov_setstripe(struct inode *inode, struct file *file,
845                             unsigned long arg)
846 {
847         struct lov_user_md lum, *lump = (struct lov_user_md *)arg;
848         int rc;
849         int flags = FMODE_WRITE;
850         ENTRY;
851
852         /* Bug 1152: copy properly when this is no longer true */
853         LASSERT(sizeof(lum) == sizeof(*lump));
854         LASSERT(sizeof(lum.lmm_objects[0]) == sizeof(lump->lmm_objects[0]));
855         rc = copy_from_user(&lum, lump, sizeof(lum));
856         if (rc)
857                 RETURN(-EFAULT);
858
859         rc = ll_lov_setstripe_ea_info(inode, file, flags, &lum, sizeof(lum));
860         RETURN(rc);
861 }
862
863 static int ll_lov_getstripe(struct inode *inode, unsigned long arg)
864 {
865         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
866
867         if (!lsm)
868                 RETURN(-ENODATA);
869
870         return obd_iocontrol(LL_IOC_LOV_GETSTRIPE, ll_i2obdexp(inode), 0, lsm,
871                             (void *)arg);
872 }
873
874 int ll_file_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
875                   unsigned long arg)
876 {
877         struct ll_file_data *fd = file->private_data;
878         int flags;
879         ENTRY;
880
881         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),cmd=%x\n", inode->i_ino,
882                inode->i_generation, inode, cmd);
883
884         if (_IOC_TYPE(cmd) == 'T') /* tty ioctls */
885                 RETURN(-ENOTTY);
886
887         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_IOCTL);
888         switch(cmd) {
889         case LL_IOC_GETFLAGS:
890                 /* Get the current value of the file flags */
891                 return put_user(fd->fd_flags, (int *)arg);
892         case LL_IOC_SETFLAGS:
893         case LL_IOC_CLRFLAGS:
894                 /* Set or clear specific file flags */
895                 /* XXX This probably needs checks to ensure the flags are
896                  *     not abused, and to handle any flag side effects.
897                  */
898                 if (get_user(flags, (int *) arg))
899                         RETURN(-EFAULT);
900
901                 if (cmd == LL_IOC_SETFLAGS)
902                         fd->fd_flags |= flags;
903                 else
904                         fd->fd_flags &= ~flags;
905                 RETURN(0);
906         case LL_IOC_LOV_SETSTRIPE:
907                 RETURN(ll_lov_setstripe(inode, file, arg));
908         case LL_IOC_LOV_SETEA:
909                 RETURN( ll_lov_setea(inode, file, arg) ); 
910         case LL_IOC_LOV_GETSTRIPE:
911                 RETURN(ll_lov_getstripe(inode, arg));
912         case LL_IOC_RECREATE_OBJ:
913                 RETURN(ll_lov_recreate_obj(inode, file, arg));
914         case EXT3_IOC_GETFLAGS:
915         case EXT3_IOC_SETFLAGS:
916                 RETURN( ll_iocontrol(inode, file, cmd, arg) );
917         /* We need to special case any other ioctls we want to handle,
918          * to send them to the MDS/OST as appropriate and to properly
919          * network encode the arg field.
920         case EXT2_IOC_GETVERSION_OLD:
921         case EXT2_IOC_GETVERSION_NEW:
922         case EXT2_IOC_SETVERSION_OLD:
923         case EXT2_IOC_SETVERSION_NEW:
924         */
925         default:
926                 RETURN( obd_iocontrol(cmd, ll_i2obdexp(inode), 0, NULL,
927                                       (void *)arg) );
928         }
929 }
930
931 loff_t ll_file_seek(struct file *file, loff_t offset, int origin)
932 {
933         struct inode *inode = file->f_dentry->d_inode;
934         struct ll_file_data *fd = file->private_data;
935         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
936         struct lustre_handle lockh = {0};
937         loff_t retval;
938         ENTRY;
939         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),to=%llu\n", inode->i_ino,
940                inode->i_generation, inode,
941                offset + ((origin==2) ? inode->i_size : file->f_pos));
942
943         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_LLSEEK);
944         if (origin == 2) { /* SEEK_END */
945                 ldlm_error_t err;
946                 struct ldlm_extent extent = {0, OBD_OBJECT_EOF};
947                 err = ll_extent_lock(fd, inode, lsm, LCK_PR, &extent, &lockh);
948                 if (err != ELDLM_OK)
949                         RETURN(err);
950
951                 offset += inode->i_size;
952         } else if (origin == 1) { /* SEEK_CUR */
953                 offset += file->f_pos;
954         }
955
956         retval = -EINVAL;
957         if (offset >= 0 && offset <= ll_file_maxbytes(inode)) {
958                 if (offset != file->f_pos) {
959                         file->f_pos = offset;
960 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
961                         file->f_reada = 0;
962                         file->f_version = ++event;
963 #endif
964                 }
965                 retval = offset;
966         }
967
968         if (origin == 2)
969                 ll_extent_unlock(fd, inode, lsm, LCK_PR, &lockh);
970         RETURN(retval);
971 }
972
973 int ll_fsync(struct file *file, struct dentry *dentry, int data)
974 {
975         struct inode *inode = dentry->d_inode;
976         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
977         struct ll_fid fid;
978         struct ptlrpc_request *req;
979         int rc, err;
980         ENTRY;
981         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
982                inode->i_generation, inode);
983
984         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_FSYNC);
985
986         /* fsync's caller has already called _fdata{sync,write}, we want
987          * that IO to finish before calling the osc and mdc sync methods */
988         rc = filemap_fdatawait(inode->i_mapping);
989
990         ll_inode2fid(&fid, inode);
991         err = mdc_sync(ll_i2sbi(inode)->ll_mdc_exp, &fid, &req);
992         if (!rc)
993                 rc = err;
994         if (!err)
995                 ptlrpc_req_finished(req);
996
997         if (data && lsm) {
998                 struct obdo *oa = obdo_alloc();
999
1000                 if (!oa)
1001                         RETURN(rc ? rc : -ENOMEM);
1002
1003                 oa->o_id = lsm->lsm_object_id;
1004                 oa->o_valid = OBD_MD_FLID;
1005                 obdo_from_inode(oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
1006                                            OBD_MD_FLMTIME | OBD_MD_FLCTIME);
1007
1008                 err = obd_sync(ll_i2sbi(inode)->ll_osc_exp, oa, lsm,
1009                                0, OBD_OBJECT_EOF);
1010                 if (!rc)
1011                         rc = err;
1012                 obdo_free(oa);
1013         }
1014
1015         RETURN(rc);
1016 }
1017
1018 int ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
1019 {
1020         struct inode *inode = file->f_dentry->d_inode;
1021         struct ll_sb_info *sbi = ll_i2sbi(inode);
1022         struct obd_device *obddev;
1023         struct ldlm_res_id res_id =
1024                     { .name = {inode->i_ino, inode->i_generation, LDLM_FLOCK} };
1025         struct lustre_handle lockh = {0};
1026         struct ldlm_flock flock;
1027         ldlm_mode_t mode = 0;
1028         int flags = 0;
1029         int rc;
1030         ENTRY;
1031
1032         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu file_lock=%p\n",
1033                inode->i_ino, file_lock);
1034
1035         flock.pid = file_lock->fl_pid;
1036         flock.start = file_lock->fl_start;
1037         flock.end = file_lock->fl_end;
1038
1039         switch (file_lock->fl_type) {
1040         case F_RDLCK:
1041                 mode = LCK_PR;
1042                 break;
1043         case F_UNLCK:
1044                 /* An unlock request may or may not have any relation to
1045                  * existing locks so we may not be able to pass a lock handle
1046                  * via a normal ldlm_lock_cancel() request. The request may even
1047                  * unlock a byte range in the middle of an existing lock. In
1048                  * order to process an unlock request we need all of the same
1049                  * information that is given with a normal read or write record
1050                  * lock request. To avoid creating another ldlm unlock (cancel)
1051                  * message we'll treat a LCK_NL flock request as an unlock. */
1052                 mode = LCK_NL;
1053                 break;
1054         case F_WRLCK:
1055                 mode = LCK_PW;
1056                 break;
1057         default:
1058                 CERROR("unknown fcntl lock type: %d\n", file_lock->fl_type);
1059                 LBUG();
1060         }
1061
1062         switch (cmd) {
1063         case F_SETLKW:
1064                 flags = 0;
1065                 break;
1066         case F_SETLK:
1067                 flags = LDLM_FL_BLOCK_NOWAIT;
1068                 break;
1069         case F_GETLK:
1070                 flags = LDLM_FL_TEST_LOCK;
1071                 /* Save the old mode so that if the mode in the lock changes we
1072                  * can decrement the appropriate reader or writer refcount. */
1073                 file_lock->fl_type = mode;
1074                 break;
1075         default:
1076                 CERROR("unknown fcntl lock command: %d\n", cmd);
1077                 LBUG();
1078         }
1079
1080         CDEBUG(D_DLMTRACE, "inode=%lu, pid=%u, flags=%#x, mode=%u, "
1081                "start="LPU64", end="LPU64"\n", inode->i_ino, flock.pid,
1082                flags, mode, flock.start, flock.end);
1083
1084         obddev = sbi->ll_mdc_exp->exp_obd;
1085         rc = ldlm_cli_enqueue(sbi->ll_mdc_exp, NULL, obddev->obd_namespace,
1086                               NULL, res_id, LDLM_FLOCK, &flock, sizeof(flock),
1087                               mode, &flags, ldlm_flock_completion_ast, NULL,
1088                               file_lock, &lockh);
1089         RETURN(rc);
1090 }
1091
1092 static int ll_have_md_lock(struct dentry *de)
1093 {
1094         struct ll_sb_info *sbi = ll_s2sbi(de->d_sb);
1095         struct lustre_handle lockh;
1096         struct ldlm_res_id res_id = { .name = {0} };
1097         struct obd_device *obddev;
1098         int flags;
1099         ENTRY;
1100
1101         if (!de->d_inode)
1102                RETURN(0);
1103
1104         obddev = sbi->ll_mdc_exp->exp_obd;
1105         res_id.name[0] = de->d_inode->i_ino;
1106         res_id.name[1] = de->d_inode->i_generation;
1107
1108         CDEBUG(D_INFO, "trying to match res "LPU64"\n", res_id.name[0]);
1109
1110         flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING;
1111         if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_PLAIN,
1112                             NULL, 0, LCK_PR, &lockh)) {
1113                 ldlm_lock_decref(&lockh, LCK_PR);
1114                 RETURN(1);
1115         }
1116
1117         if (ldlm_lock_match(obddev->obd_namespace, flags, &res_id, LDLM_PLAIN,
1118                             NULL, 0, LCK_PW, &lockh)) {
1119                 ldlm_lock_decref(&lockh, LCK_PW);
1120                 RETURN(1);
1121         }
1122         RETURN(0);
1123 }
1124
1125 int ll_inode_revalidate_it(struct dentry *dentry, struct lookup_intent *it)
1126 {
1127         struct inode *inode = dentry->d_inode;
1128         struct lov_stripe_md *lsm;
1129         ENTRY;
1130
1131         if (!inode) {
1132                 CERROR("REPORT THIS LINE TO PETER\n");
1133                 RETURN(0);
1134         }
1135         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),name=%s\n",
1136                inode->i_ino, inode->i_generation, inode, dentry->d_name.name);
1137 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0))
1138         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_REVALIDATE);
1139 #endif
1140
1141         if (!ll_have_md_lock(dentry)) {
1142                 struct ptlrpc_request *req = NULL;
1143                 struct ll_sb_info *sbi = ll_i2sbi(dentry->d_inode);
1144                 struct ll_fid fid;
1145                 unsigned long valid = 0;
1146                 int rc, ealen = 0;
1147
1148                 if (S_ISREG(inode->i_mode)) {
1149                         ealen = obd_size_diskmd(sbi->ll_osc_exp, NULL);
1150                         valid |= OBD_MD_FLEASIZE;
1151                 }
1152                 ll_inode2fid(&fid, inode);
1153                 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, valid, ealen, &req);
1154                 if (rc) {
1155                         CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1156                         RETURN(-abs(rc));
1157                 }
1158                 rc = ll_prep_inode(sbi->ll_osc_exp, &inode, req, 0, NULL);
1159                 if (rc) {
1160                         ptlrpc_req_finished(req);
1161                         RETURN(rc);
1162                 }
1163                 ptlrpc_req_finished(req);
1164         }
1165
1166 #if 0
1167         if (ll_have_md_lock(dentry) &&
1168             test_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &ll_i2info(inode)->lli_flags))
1169                 RETURN(0);
1170 #endif
1171
1172         lsm = ll_i2info(inode)->lli_smd;
1173         if (!lsm)       /* object not yet allocated, don't validate size */
1174                 RETURN(0);
1175
1176         /* unfortunately stat comes in through revalidate and we don't
1177          * differentiate this use from initial instantiation.  we're
1178          * also being wildly conservative and flushing write caches
1179          * so that stat really returns the proper size. */
1180         {
1181                 struct ldlm_extent extent = {0, OBD_OBJECT_EOF};
1182                 struct lustre_handle lockh = {0};
1183                 ldlm_error_t err;
1184
1185                 err = ll_extent_lock(NULL, inode, lsm, LCK_PR, &extent, &lockh);
1186                 if (err != ELDLM_OK)
1187                         RETURN(err);
1188
1189                 ll_extent_unlock(NULL, inode, lsm, LCK_PR, &lockh);
1190         }
1191         RETURN(0);
1192 }
1193
1194 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1195 int ll_getattr(struct vfsmount *mnt, struct dentry *de,
1196                struct lookup_intent *it, struct kstat *stat)
1197 {
1198         int res = 0;
1199         struct inode *inode = de->d_inode;
1200
1201         res = ll_inode_revalidate_it(de, it);
1202         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_GETATTR);
1203
1204         if (res)
1205                 return res;
1206
1207         stat->dev = inode->i_sb->s_dev;
1208         stat->ino = inode->i_ino;
1209         stat->mode = inode->i_mode;
1210         stat->nlink = inode->i_nlink;
1211         stat->uid = inode->i_uid;
1212         stat->gid = inode->i_gid;
1213         stat->rdev = kdev_t_to_nr(inode->i_rdev);
1214         stat->atime = inode->i_atime;
1215         stat->mtime = inode->i_mtime;
1216         stat->ctime = inode->i_ctime;
1217         stat->size = inode->i_size;
1218         stat->blksize = inode->i_blksize;
1219         stat->blocks = inode->i_blocks;
1220         return 0;
1221 }
1222 #endif
1223
1224 struct file_operations ll_file_operations = {
1225         read:           ll_file_read,
1226         write:          ll_file_write,
1227         ioctl:          ll_file_ioctl,
1228         open:           ll_file_open,
1229         release:        ll_file_release,
1230         mmap:           generic_file_mmap,
1231         llseek:         ll_file_seek,
1232         fsync:          ll_fsync,
1233         //lock:           ll_file_flock
1234 };
1235
1236 struct inode_operations ll_file_inode_operations = {
1237         setattr_raw:    ll_setattr_raw,
1238         setattr:        ll_setattr,
1239         truncate:       ll_truncate,
1240 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1241         getattr_it:     ll_getattr,
1242 #else
1243         revalidate_it:  ll_inode_revalidate_it,
1244 #endif
1245 };
1246
1247 struct inode_operations ll_special_inode_operations = {
1248         setattr_raw:    ll_setattr_raw,
1249         setattr:        ll_setattr,
1250 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1251         getattr_it:     ll_getattr,
1252 #else
1253         revalidate_it:  ll_inode_revalidate_it,
1254 #endif
1255 };