Whamcloud - gitweb
- Rename the ptlrpc-general reconnection and replay functions, and export them
[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  *  linux/fs/ext2/file.c
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  *
9  * Copyright (C) 1992, 1993, 1994, 1995
10  * Remy Card (card@masi.ibp.fr)
11  * Laboratoire MASI - Institut Blaise Pascal
12  * Universite Pierre et Marie Curie (Paris VI)
13  *
14  *  from
15  *
16  *  linux/fs/minix/file.c
17  *
18  *  Copyright (C) 1991, 1992  Linus Torvalds
19  *
20  *  ext2 fs regular file handling primitives
21  *
22  *  64-bit file support on 64-bit platforms by Jakub Jelinek
23  *      (jj@sunsite.ms.mff.cuni.cz)
24  */
25
26 #define DEBUG_SUBSYSTEM S_LLITE
27
28 #include <linux/lustre_dlm.h>
29 #include <linux/lustre_lite.h>
30 #include <linux/random.h>
31
32 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc);
33 extern int ll_setattr(struct dentry *de, struct iattr *attr);
34
35 static int ll_create_objects(struct inode *inode, struct ll_inode_info *lli)
36 {
37         struct obdo *oa;
38         int rc;
39         ENTRY;
40
41         oa = obdo_alloc();
42         if (!oa)
43                 RETURN(-ENOMEM);
44
45         oa->o_mode = S_IFREG | 0600;
46         oa->o_easize = ll_mds_easize(inode->i_sb);
47         oa->o_id = inode->i_ino;
48         oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE |
49                 OBD_MD_FLMODE | OBD_MD_FLEASIZE;
50         rc = obd_create(ll_i2obdconn(inode), oa, &lli->lli_smd);
51         obdo_free(oa);
52
53         if (!rc)
54                 LASSERT(lli->lli_smd->lsm_object_id);
55         RETURN(rc);
56 }
57
58 static int ll_file_open(struct inode *inode, struct file *file)
59 {
60         struct ptlrpc_request *req = NULL;
61         struct ll_file_data *fd;
62         struct obdo *oa;
63         struct lov_stripe_md *lsm = NULL;
64         struct ll_sb_info *sbi = ll_i2sbi(inode);
65         struct ll_inode_info *lli = ll_i2info(inode);
66         int rc = 0;
67         ENTRY;
68
69         LASSERT(!file->private_data);
70
71         CHECK_MOUNT_EPOCH(inode);
72
73         lsm = lli->lli_smd;
74
75         /*  delayed create of object (intent created inode) */
76         /*  XXX object needs to be cleaned up if mdc_open fails */
77         /*  XXX error handling appropriate here? */
78         if (lsm == NULL) {
79                 if (file->f_flags & O_LOV_DELAY_CREATE) {
80                         CDEBUG(D_INODE, "delaying object creation\n");
81                         RETURN(0);
82                 }
83                 down(&lli->lli_open_sem);
84                 /* Check to see if we lost the race */
85                 if (!lli->lli_smd)
86                         rc = ll_create_objects(inode, lli);
87                 up(&lli->lli_open_sem);
88                 if (rc)
89                         RETURN(rc);
90
91                 lsm = lli->lli_smd;
92         }
93
94         fd = kmem_cache_alloc(ll_file_data_slab, SLAB_KERNEL);
95         if (!fd)
96                 GOTO(out, rc = -ENOMEM);
97         memset(fd, 0, sizeof(*fd));
98
99         fd->fd_mdshandle.addr = (__u64)(unsigned long)file;
100         get_random_bytes(&fd->fd_mdshandle.cookie,
101                          sizeof(fd->fd_mdshandle.cookie));
102         rc = mdc_open(&sbi->ll_mdc_conn, inode->i_ino, S_IFREG | inode->i_mode,
103                       file->f_flags, lsm, &fd->fd_mdshandle, &req);
104         fd->fd_req = req;
105
106         /* We don't call ptlrpc_req_finished here, because the request is
107          * preserved until we see a matching close, at which point it is
108          * released (and likely freed).  (See ll_file_release.)
109          */
110         if (rc)
111                 GOTO(out_req, -abs(rc));
112         if (!fd->fd_mdshandle.addr ||
113             fd->fd_mdshandle.addr == (__u64)(unsigned long)file) {
114                 CERROR("hmm, mdc_open didn't assign fd_mdshandle?\n");
115                 /* XXX handle this how, abort or is it non-fatal? */
116         }
117
118         oa = obdo_alloc();
119         if (!oa)
120                 GOTO(out_mdc, rc = -EINVAL);
121
122         oa->o_id = lsm->lsm_object_id;
123         oa->o_mode = S_IFREG;
124         oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE;
125         rc = obd_open(ll_i2obdconn(inode), oa, lsm);
126
127         obd_oa2handle(&fd->fd_osthandle, oa);
128         obdo_free(oa);
129
130         if (rc)
131                 GOTO(out_mdc, rc = -abs(rc));
132
133         file->private_data = fd;
134
135         RETURN(0);
136 out_mdc:
137         mdc_close(&sbi->ll_mdc_conn, inode->i_ino,
138                   S_IFREG, &fd->fd_mdshandle, &req);
139 out_req:
140         ptlrpc_free_req(req);
141 //out_fd:
142         fd->fd_mdshandle.cookie = DEAD_HANDLE_MAGIC;
143         kmem_cache_free(ll_file_data_slab, fd);
144 out:
145         return rc;
146 }
147
148 int ll_size_lock(struct inode *inode, struct lov_stripe_md *lsm, obd_off start,
149                  int mode, struct lustre_handle **lockhs_p)
150 {
151         struct ll_sb_info *sbi = ll_i2sbi(inode);
152         struct ldlm_extent extent;
153         struct lustre_handle *lockhs = NULL;
154         int rc, flags = 0, stripe_count;
155         ENTRY;
156
157         if (sbi->ll_flags & LL_SBI_NOLCK) {
158                 *lockhs_p = NULL;
159                 RETURN(0);
160         }
161
162         stripe_count = lsm->lsm_stripe_count;
163         if (!stripe_count)
164                 stripe_count = 1;
165
166         OBD_ALLOC(lockhs, stripe_count * sizeof(*lockhs));
167         if (lockhs == NULL)
168                 RETURN(-ENOMEM);
169
170         extent.start = start;
171         extent.end = OBD_OBJECT_EOF;
172
173         rc = obd_enqueue(&sbi->ll_osc_conn, lsm, NULL, LDLM_EXTENT, &extent,
174                          sizeof(extent), mode, &flags, ll_lock_callback,
175                          inode, sizeof(*inode), lockhs);
176         if (rc != ELDLM_OK) {
177                 CERROR("lock enqueue: %d\n", rc);
178                 OBD_FREE(lockhs, stripe_count * sizeof(*lockhs));
179         } else
180                 *lockhs_p = lockhs;
181         RETURN(rc);
182 }
183
184 int ll_size_unlock(struct inode *inode, struct lov_stripe_md *lsm, int mode,
185                    struct lustre_handle *lockhs)
186 {
187         struct ll_sb_info *sbi = ll_i2sbi(inode);
188         int rc, stripe_count;
189         ENTRY;
190
191         if (sbi->ll_flags & LL_SBI_NOLCK)
192                 RETURN(0);
193
194         if (lockhs == NULL) {
195                 LBUG();
196                 RETURN(-EINVAL);
197         }
198
199         rc = obd_cancel(&sbi->ll_osc_conn, lsm, mode, lockhs);
200         if (rc != ELDLM_OK) {
201                 CERROR("lock cancel: %d\n", rc);
202                 LBUG();
203         }
204
205         stripe_count = lsm->lsm_stripe_count;
206         if (!stripe_count)
207                 stripe_count = 1;
208
209         OBD_FREE(lockhs, stripe_count * sizeof(*lockhs));
210         RETURN(rc);
211 }
212
213 int ll_file_size(struct inode *inode, struct lov_stripe_md *lsm)
214 {
215         struct ll_sb_info *sbi = ll_i2sbi(inode);
216         struct lustre_handle *lockhs;
217         struct obdo oa;
218         int err, rc;
219         ENTRY;
220
221         LASSERT(lsm);
222         LASSERT(sbi);
223
224         rc = ll_size_lock(inode, lsm, 0, LCK_PR, &lockhs);
225         if (rc != ELDLM_OK) {
226                 CERROR("lock enqueue: %d\n", rc);
227                 RETURN(rc);
228         }
229
230         oa.o_id = lsm->lsm_object_id;
231         oa.o_mode = S_IFREG;
232         oa.o_valid = OBD_MD_FLID|OBD_MD_FLTYPE|OBD_MD_FLSIZE|OBD_MD_FLBLOCKS;
233         rc = obd_getattr(&sbi->ll_osc_conn, &oa, lsm);
234         if (!rc)
235                 obdo_to_inode(inode, &oa,
236                               oa.o_valid & ~(OBD_MD_FLTYPE | OBD_MD_FLMODE));
237
238         err = ll_size_unlock(inode, lsm, LCK_PR, lockhs);
239         if (err != ELDLM_OK) {
240                 CERROR("lock cancel: %d\n", err);
241                 LBUG();
242         }
243         RETURN(rc);
244 }
245
246 static int ll_file_release(struct inode *inode, struct file *file)
247 {
248         struct ptlrpc_request *req = NULL;
249         struct ll_file_data *fd;
250         struct obdo oa;
251         struct ll_sb_info *sbi = ll_i2sbi(inode);
252         struct ll_inode_info *lli = ll_i2info(inode);
253         struct lov_stripe_md *lsm = lli->lli_smd;
254         int rc, rc2;
255
256         ENTRY;
257
258         CHECK_MOUNT_EPOCH(inode);
259
260         fd = (struct ll_file_data *)file->private_data;
261         if (!fd) {
262                 LBUG();
263                 GOTO(out, rc = -EINVAL);
264         }
265
266         memset(&oa, 0, sizeof(oa));
267         oa.o_id = lsm->lsm_object_id;
268         oa.o_mode = S_IFREG;
269         oa.o_valid = OBD_MD_FLTYPE | OBD_MD_FLID;
270         obd_handle2oa(&oa, &fd->fd_osthandle);
271         rc = obd_close(ll_i2obdconn(inode), &oa, lsm);
272         if (rc)
273                 GOTO(out_mdc, rc = -abs(rc));
274
275         /* If this fails and we goto out_fd, the file size on the MDS is out of
276          * date.  Is that a big deal? */
277         if (file->f_mode & FMODE_WRITE) {
278                 struct lustre_handle *lockhs;
279
280                 rc = ll_size_lock(inode, lsm, 0, LCK_PR, &lockhs);
281                 if (rc)
282                         GOTO(out_mdc, -abs(rc));
283
284                 oa.o_id = lsm->lsm_object_id;
285                 oa.o_mode = S_IFREG;
286                 oa.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
287                         OBD_MD_FLBLOCKS;
288                 rc = obd_getattr(&sbi->ll_osc_conn, &oa, lsm);
289                 if (!rc) {
290                         struct iattr attr;
291                         attr.ia_valid = (ATTR_MTIME | ATTR_CTIME | ATTR_ATIME |
292                                          ATTR_SIZE);
293                         attr.ia_mtime = inode->i_mtime;
294                         attr.ia_ctime = inode->i_ctime;
295                         attr.ia_atime = inode->i_atime;
296                         attr.ia_size = oa.o_size;
297
298                         inode->i_blocks = oa.o_blocks;
299
300                         /* XXX: this introduces a small race that we should
301                          * evaluate */
302                         rc = ll_inode_setattr(inode, &attr, 0);
303                 }
304                 rc2 = ll_size_unlock(inode, lli->lli_smd, LCK_PR, lockhs);
305                 if (rc2) {
306                         CERROR("lock cancel: %d\n", rc);
307                         LBUG();
308                         if (!rc)
309                                 rc = rc2;
310                 }
311         }
312
313 out_mdc:
314         rc2 = mdc_close(&sbi->ll_mdc_conn, inode->i_ino,
315                         S_IFREG, &fd->fd_mdshandle, &req);
316         ptlrpc_req_finished(req);
317         if (rc2) {
318                 if (!rc)
319                         rc = -abs(rc2);
320                 GOTO(out_fd, rc);
321         }
322         /* XXX Mike, we have also done this in ll_file_open? */
323         ptlrpc_req_finished(fd->fd_req);
324
325         rc = obd_cancel_unused(ll_i2obdconn(inode), lsm, 0);
326         if (rc)
327                 CERROR("obd_cancel_unused: %d\n", rc);
328
329         EXIT;
330
331 out_fd:
332         fd->fd_mdshandle.cookie = DEAD_HANDLE_MAGIC;
333         file->private_data = NULL;
334         kmem_cache_free(ll_file_data_slab, fd);
335 out:
336         return rc;
337 }
338
339
340 static inline void ll_remove_suid(struct inode *inode)
341 {
342         unsigned int mode;
343
344         /* set S_IGID if S_IXGRP is set, and always set S_ISUID */
345         mode = (inode->i_mode & S_IXGRP)*(S_ISGID/S_IXGRP) | S_ISUID;
346
347         /* was any of the uid bits set? */
348         mode &= inode->i_mode;
349         if (mode && !capable(CAP_FSETID)) {
350                 inode->i_mode &= ~mode;
351                 // XXX careful here - we cannot change the size
352         }
353 }
354
355 static void ll_update_atime(struct inode *inode)
356 {
357         struct iattr attr;
358
359         attr.ia_atime = CURRENT_TIME;
360         attr.ia_valid = ATTR_ATIME;
361
362         if (inode->i_atime == attr.ia_atime) return;
363         if (IS_RDONLY(inode)) return;
364         if (IS_NOATIME(inode)) return;
365
366         /* ll_inode_setattr() sets inode->i_atime from attr.ia_atime */
367         ll_inode_setattr(inode, &attr, 0);
368 }
369
370 int ll_lock_callback(struct ldlm_lock *lock, struct ldlm_lock_desc *new,
371                      void *data, __u32 data_len, int flag)
372 {
373         struct inode *inode = data;
374         struct lustre_handle lockh;
375         int rc;
376         ENTRY;
377
378         if (data_len != sizeof(struct inode))
379                 LBUG();
380
381         if (inode == NULL)
382                 LBUG();
383
384         switch (flag) {
385         case LDLM_CB_BLOCKING:
386                 ldlm_lock2handle(lock, &lockh);
387                 rc = ldlm_cli_cancel(&lockh);
388                 if (rc != ELDLM_OK)
389                         CERROR("ldlm_cli_cancel failed: %d\n", rc);
390                 break;
391         case LDLM_CB_CANCELING:
392                 CDEBUG(D_INODE, "invalidating obdo/inode %ld\n", inode->i_ino);
393                 /* FIXME: do something better than throwing away everything */
394                 //down(&inode->i_sem);
395                 invalidate_inode_pages(inode);
396                 //up(&inode->i_sem);
397                 break;
398         default:
399                 LBUG();
400         }
401
402         RETURN(0);
403 }
404
405 static ssize_t ll_file_read(struct file *filp, char *buf, size_t count,
406                             loff_t *ppos)
407 {
408         struct ll_file_data *fd = (struct ll_file_data *)filp->private_data;
409         struct inode *inode = filp->f_dentry->d_inode;
410         struct ll_sb_info *sbi = ll_i2sbi(inode);
411         struct ldlm_extent extent;
412         struct lustre_handle *lockhs = NULL;
413         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
414         int flags = 0;
415         ldlm_error_t err;
416         ssize_t retval;
417         ENTRY;
418
419         if (!(fd->fd_flags & LL_FILE_IGNORE_LOCK) &&
420             !(sbi->ll_flags & LL_SBI_NOLCK)) {
421                 OBD_ALLOC(lockhs, lsm->lsm_stripe_count * sizeof(*lockhs));
422                 if (!lockhs)
423                         RETURN(-ENOMEM);
424
425                 extent.start = *ppos;
426                 extent.end = *ppos + count;
427                 CDEBUG(D_INFO, "Locking inode %ld, start "LPU64" end "LPU64"\n",
428                        inode->i_ino, extent.start, extent.end);
429
430                 err = obd_enqueue(&sbi->ll_osc_conn, lsm, NULL, LDLM_EXTENT,
431                                   &extent, sizeof(extent), LCK_PR, &flags,
432                                   ll_lock_callback, inode, sizeof(*inode),
433                                   lockhs);
434                 if (err != ELDLM_OK) {
435                         OBD_FREE(lockhs, lsm->lsm_stripe_count*sizeof(*lockhs));
436                         CERROR("lock enqueue: err: %d\n", err);
437                         RETURN(err);
438                 }
439         }
440
441         CDEBUG(D_INFO, "Reading inode %ld, %d bytes, offset %Ld\n",
442                inode->i_ino, count, *ppos);
443         retval = generic_file_read(filp, buf, count, ppos);
444
445         if (retval > 0)
446                 ll_update_atime(inode);
447
448         if (!(fd->fd_flags & LL_FILE_IGNORE_LOCK) &&
449             !(sbi->ll_flags & LL_SBI_NOLCK)) {
450                 err = obd_cancel(&sbi->ll_osc_conn, lsm, LCK_PR, lockhs);
451                 if (err != ELDLM_OK) {
452                         CERROR("lock cancel: err: %d\n", err);
453                         retval = err;
454                 }
455         }
456
457         if (lockhs)
458                 OBD_FREE(lockhs, lsm->lsm_stripe_count * sizeof(*lockhs));
459         RETURN(retval);
460 }
461
462 /*
463  * Write to a file (through the page cache).
464  */
465 static ssize_t
466 ll_file_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
467 {
468         struct ll_file_data *fd = (struct ll_file_data *)file->private_data;
469         struct inode *inode = file->f_dentry->d_inode;
470         struct ll_sb_info *sbi = ll_i2sbi(inode);
471         struct ldlm_extent extent;
472         struct lustre_handle *lockhs = NULL, *eof_lockhs = NULL;
473         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
474         int flags = 0;
475         ldlm_error_t err;
476         ssize_t retval;
477         ENTRY;
478
479         if (!S_ISBLK(inode->i_mode) && file->f_flags & O_APPEND) {
480                 struct obdo *oa;
481
482                 oa = obdo_alloc();
483                 if (!oa)
484                         RETURN(-ENOMEM);
485
486                 err = ll_size_lock(inode, lsm, 0, LCK_PW, &eof_lockhs);
487                 if (err) {
488                         obdo_free(oa);
489                         RETURN(err);
490                 }
491
492                 oa->o_id = lsm->lsm_object_id;
493                 oa->o_mode = inode->i_mode;
494                 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
495                         OBD_MD_FLBLOCKS;
496                 obd_handle2oa(oa, &fd->fd_osthandle);
497                 retval = obd_getattr(&sbi->ll_osc_conn, oa, lsm);
498                 if (retval) {
499                         obdo_free(oa);
500                         GOTO(out_eof, retval);
501                 }
502
503                 *ppos = oa->o_size;
504                 obdo_to_inode(inode, oa, oa->o_valid);
505                 obdo_free(oa);
506         }
507
508         if (!(fd->fd_flags & LL_FILE_IGNORE_LOCK) ||
509             sbi->ll_flags & LL_SBI_NOLCK) {
510                 OBD_ALLOC(lockhs, lsm->lsm_stripe_count * sizeof(*lockhs));
511                 if (!lockhs)
512                         GOTO(out_eof, retval = -ENOMEM);
513                 extent.start = *ppos;
514                 extent.end = *ppos + count;
515                 CDEBUG(D_INFO, "Locking inode %ld, start "LPU64" end "LPU64"\n",
516                        inode->i_ino, extent.start, extent.end);
517
518                 err = obd_enqueue(&sbi->ll_osc_conn, lsm, NULL, LDLM_EXTENT,
519                                   &extent, sizeof(extent), LCK_PW, &flags,
520                                   ll_lock_callback, inode, sizeof(*inode),
521                                   lockhs);
522                 if (err != ELDLM_OK) {
523                         CERROR("lock enqueue: err: %d\n", err);
524                         GOTO(out_free, retval = err);
525                 }
526         }
527
528         CDEBUG(D_INFO, "Writing inode %ld, %ld bytes, offset "LPD64"\n",
529                inode->i_ino, (long)count, *ppos);
530
531         retval = generic_file_write(file, buf, count, ppos);
532
533         if (!(fd->fd_flags & LL_FILE_IGNORE_LOCK) ||
534             sbi->ll_flags & LL_SBI_NOLCK) {
535                 err = obd_cancel(&sbi->ll_osc_conn, lsm, LCK_PW, lockhs);
536                 if (err != ELDLM_OK) {
537                         CERROR("lock cancel: err: %d\n", err);
538                         GOTO(out_free, retval = err);
539                 }
540         }
541
542         EXIT;
543  out_free:
544         if (lockhs)
545                 OBD_FREE(lockhs, lsm->lsm_stripe_count * sizeof(*lockhs));
546
547  out_eof:
548         if (!S_ISBLK(inode->i_mode) && file->f_flags & O_APPEND) {
549                 err = ll_size_unlock(inode, lsm, LCK_PW, eof_lockhs);
550                 if (err && !retval)
551                         retval = err;
552         }
553
554         return retval;
555 }
556
557 static int ll_lov_setstripe(struct inode *inode, struct file *file,
558                             struct lov_user_md *lum)
559 {
560         struct ll_inode_info *lli = ll_i2info(inode);
561         struct lov_stripe_md *lsm;
562         int size = ll_mds_easize(inode->i_sb);
563         int rc;
564
565         rc = verify_area(VERIFY_READ, lum, sizeof(*lum));
566         if (rc)
567                 RETURN(rc);
568
569         down(&lli->lli_open_sem);
570         if (lli->lli_smd) {
571                 CERROR("striping data already set for %d\n", inode->i_ino);
572                 GOTO(out_lov_up, rc = -EPERM);
573         }
574
575         OBD_ALLOC(lli->lli_smd, size);
576         if (!lli->lli_smd)
577                 GOTO(out_lov_up, rc = -ENOMEM);
578
579         lsm = lli->lli_smd;
580         lsm->lsm_magic = LOV_MAGIC;
581         lsm->lsm_stripe_size = lum->lum_stripe_size;
582         lsm->lsm_stripe_pattern = lum->lum_stripe_pattern;
583         lsm->lsm_stripe_offset = lum->lum_stripe_offset;
584         lsm->lsm_stripe_count = lum->lum_stripe_count;
585         lsm->lsm_mds_easize = size;
586
587         file->f_flags &= ~O_LOV_DELAY_CREATE;
588         rc = ll_create_objects(inode, lli);
589         if (rc)
590                 OBD_FREE(lli->lli_smd, size);
591         else
592                 rc = ll_file_open(inode, file);
593 out_lov_up:
594         up(&lli->lli_open_sem);
595         return rc;
596 }
597
598 int ll_file_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
599                   unsigned long arg)
600 {
601         struct ll_file_data *fd = (struct ll_file_data *)file->private_data;
602         int flags;
603
604         switch(cmd) {
605         case LL_IOC_GETFLAGS:
606                 /* Get the current value of the file flags */
607                 return put_user(fd->fd_flags, (int *)arg);
608         case LL_IOC_SETFLAGS:
609         case LL_IOC_CLRFLAGS:
610                 /* Set or clear specific file flags */
611                 /* XXX This probably needs checks to ensure the flags are
612                  *     not abused, and to handle any flag side effects.
613                  */
614                 if (get_user(flags, (int *) arg))
615                         return -EFAULT;
616
617                 if (cmd == LL_IOC_SETFLAGS)
618                         fd->fd_flags |= flags;
619                 else
620                         fd->fd_flags &= ~flags;
621                 return 0;
622         case LL_IOC_LOV_SETSTRIPE:
623                 return ll_lov_setstripe(inode, file, (struct lov_user_md *)arg);
624
625         /* We need to special case any other ioctls we want to handle,
626          * to send them to the MDS/OST as appropriate and to properly
627          * network encode the arg field.
628         case EXT2_IOC_GETFLAGS:
629         case EXT2_IOC_SETFLAGS:
630         case EXT2_IOC_GETVERSION_OLD:
631         case EXT2_IOC_GETVERSION_NEW:
632         case EXT2_IOC_SETVERSION_OLD:
633         case EXT2_IOC_SETVERSION_NEW:
634         */
635         default:
636                 return -ENOTTY;
637         }
638 }
639
640 loff_t ll_file_seek(struct file *file, loff_t offset, int origin)
641 {
642         struct inode *inode = file->f_dentry->d_inode;
643         long long retval;
644         ENTRY;
645
646         CHECK_MOUNT_EPOCH(inode);
647
648         switch (origin) {
649         case 2: {
650                 struct ll_inode_info *lli = ll_i2info(inode);
651
652                 retval = ll_file_size(inode, lli->lli_smd);
653                 if (retval)
654                         RETURN(retval);
655
656                 offset += inode->i_size;
657                 break;
658         }
659         case 1:
660                 offset += file->f_pos;
661         }
662         retval = -EINVAL;
663         if (offset >= 0 && offset <= inode->i_sb->s_maxbytes) {
664                 if (offset != file->f_pos) {
665                         file->f_pos = offset;
666                         file->f_reada = 0;
667                         file->f_version = ++event;
668                 }
669                 retval = offset;
670         }
671         RETURN(retval);
672 }
673
674 /* XXX this does not need to do anything for data, it _does_ need to
675    call setattr */
676 int ll_fsync(struct file *file, struct dentry *dentry, int data)
677 {
678         return 0;
679 }
680
681 static int ll_inode_revalidate(struct dentry *dentry)
682 {
683         struct inode *inode = dentry->d_inode;
684         struct lov_stripe_md *lsm;
685         ENTRY;
686
687         if (!inode)
688                 RETURN(0);
689
690         lsm = ll_i2info(inode)->lli_smd;
691         if (!lsm)       /* object not yet allocated, don't validate size */
692                 RETURN(0);
693
694         RETURN(ll_file_size(inode, lsm));
695 }
696
697 struct file_operations ll_file_operations = {
698         read:           ll_file_read,
699         write:          ll_file_write,
700         ioctl:          ll_file_ioctl,
701         open:           ll_file_open,
702         release:        ll_file_release,
703         mmap:           generic_file_mmap,
704         llseek:         ll_file_seek,
705         fsync:          NULL
706 };
707
708 struct inode_operations ll_file_inode_operations = {
709         truncate:   ll_truncate,
710         setattr:    ll_setattr,
711         revalidate: ll_inode_revalidate
712 };