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