1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
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>
9 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
25 #define DEBUG_SUBSYSTEM S_LLITE
27 #include <linux/lustre_dlm.h>
28 #include <linux/lustre_lite.h>
29 #include <linux/obd_lov.h> /* for lov_mds_md_size() in lov_setstripe() */
30 #include <linux/random.h>
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);
35 static int ll_mdc_close(struct lustre_handle *mdc_conn, struct inode *inode,
38 struct ll_file_data *fd = file->private_data;
39 struct ptlrpc_request *req = NULL;
41 struct obd_import *imp;
45 /* Complete the open request and remove it from replay list */
46 rc = mdc_close(&ll_i2sbi(inode)->ll_mdc_conn, inode->i_ino,
47 inode->i_mode, &fd->fd_mdshandle, &req);
49 CERROR("inode %lu close failed: rc = %d\n", inode->i_ino, rc);
51 imp = fd->fd_req->rq_import;
53 spin_lock_irqsave(&imp->imp_lock, flags);
55 DEBUG_REQ(D_HA, fd->fd_req, "matched open req %p", fd->fd_req);
57 /* We held on to the request for replay until we saw a close for that
58 * file. Now that we've closed it, it gets replayed on the basis of
59 * its transno only. */
60 fd->fd_req->rq_flags &= ~PTL_RPC_FL_REPLAY;
62 if (fd->fd_req->rq_transno) {
63 /* This open created a file, so it needs replay as a
64 * normal transaction now. Our reference to it now
65 * effectively owned by the imp_replay_list, and it'll
66 * be committed just like other transno-having
67 * requests from here on out. */
69 /* We now retain this close request, so that it is
70 * replayed if the open is replayed. We duplicate the
71 * transno, so that we get freed at the right time,
72 * and rely on the difference in xid to keep
73 * everything ordered correctly.
75 * But! If this close was already given a transno
76 * (because it caused real unlinking of an
77 * open-unlinked file, f.e.), then we'll be ordered on
78 * the basis of that and we don't need to do anything
80 if (!req->rq_transno) {
81 req->rq_transno = fd->fd_req->rq_transno;
82 ptlrpc_retain_replayable_request(req, imp);
84 spin_unlock_irqrestore(&imp->imp_lock, flags);
86 /* Should we free_committed now? we always free before
87 * replay, so it's probably a wash. We could check to
88 * see if the fd_req should already be committed, in
89 * which case we can avoid the whole retain_replayable
92 /* No transno means that we can just drop our ref. */
93 spin_unlock_irqrestore(&imp->imp_lock, flags);
95 ptlrpc_req_finished(fd->fd_req);
97 /* Do this after the fd_req->rq_transno check, because we don't want
98 * to bounce off zero references. */
99 ptlrpc_req_finished(req);
100 fd->fd_mdshandle.cookie = DEAD_HANDLE_MAGIC;
101 file->private_data = NULL;
102 kmem_cache_free(ll_file_data_slab, fd);
107 /* While this returns an error code, fput() the caller does not, so we need
108 * to make every effort to clean up all of our state here. Also, applications
109 * rarely check close errors and even if an error is returned they will not
110 * re-try the close call.
112 static int ll_file_release(struct inode *inode, struct file *file)
114 struct ll_file_data *fd;
116 struct ll_sb_info *sbi = ll_i2sbi(inode);
117 struct ll_inode_info *lli = ll_i2info(inode);
118 struct lov_stripe_md *lsm = lli->lli_smd;
123 fd = (struct ll_file_data *)file->private_data;
124 if (!fd) /* no process opened the file after an mcreate */
128 memset(&oa, 0, sizeof(oa));
129 oa.o_id = lsm->lsm_object_id;
131 oa.o_valid = OBD_MD_FLTYPE | OBD_MD_FLID;
133 memcpy(&oa.o_inline, fd->fd_ostdata, FD_OSTDATA_SIZE);
134 oa.o_valid |= OBD_MD_FLHANDLE;
136 rc = obd_close(&sbi->ll_osc_conn, &oa, lsm, NULL);
138 CERROR("inode %lu object close failed: rc = %d\n",
142 rc2 = ll_mdc_close(&sbi->ll_mdc_conn, inode, file);
149 static int ll_local_open(struct file *file, struct lookup_intent *it)
151 struct ptlrpc_request *req = it->it_data;
152 struct ll_file_data *fd;
153 struct mds_body *body = lustre_msg_buf(req->rq_repmsg, 1);
156 LASSERT(!file->private_data);
158 fd = kmem_cache_alloc(ll_file_data_slab, SLAB_KERNEL);
159 /* We can't handle this well without reorganizing ll_file_open and
160 * ll_mdc_close, so don't even try right now. */
163 memset(fd, 0, sizeof(*fd));
165 memcpy(&fd->fd_mdshandle, &body->handle, sizeof(body->handle));
166 fd->fd_req = it->it_data;
167 file->private_data = fd;
172 static int ll_osc_open(struct lustre_handle *conn, struct inode *inode,
173 struct file *file, struct lov_stripe_md *lsm)
175 struct ll_file_data *fd = file->private_data;
183 oa->o_id = lsm->lsm_object_id;
184 oa->o_mode = S_IFREG;
185 oa->o_valid = (OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
186 OBD_MD_FLBLOCKS | OBD_MD_FLMTIME | OBD_MD_FLCTIME);
187 rc = obd_open(conn, oa, lsm, NULL);
191 file->f_flags &= ~O_LOV_DELAY_CREATE;
192 obdo_to_inode(inode, oa, (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
193 OBD_MD_FLMTIME | OBD_MD_FLCTIME));
195 if (oa->o_valid |= OBD_MD_FLHANDLE)
196 memcpy(fd->fd_ostdata, obdo_handle(oa), FD_OSTDATA_SIZE);
204 /* Caller must hold lli_open_sem to protect lli->lli_smd from changing and
205 * duplicate objects from being created. We only install lsm to lli_smd if
206 * the mdc open was successful (hence stored stripe MD on MDS), otherwise
207 * other nodes could try to create different objects for the same file.
209 static int ll_create_obj(struct lustre_handle *conn, struct inode *inode,
210 struct file *file, struct lov_stripe_md *lsm)
212 struct ptlrpc_request *req = NULL;
213 struct ll_inode_info *lli = ll_i2info(inode);
214 struct lov_mds_md *lmm = NULL;
217 int rc, err, lmm_size = 0;;
224 oa->o_mode = S_IFREG | 0600;
225 oa->o_id = inode->i_ino;
226 /* Keep these 0 for now, because chown/chgrp does not change the
227 * ownership on the OST, and we don't want to allow BA OST NFS
228 * users to access these objects by mistake.
232 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE |
233 OBD_MD_FLUID | OBD_MD_FLGID;
235 rc = obd_create(conn, oa, &lsm, NULL);
237 CERROR("error creating objects for inode %lu: rc = %d\n",
240 CERROR("obd_create returned invalid rc %d\n", rc);
246 LASSERT(lsm && lsm->lsm_object_id);
247 rc = obd_packmd(conn, &lmm, lsm);
249 GOTO(out_destroy, rc);
253 /* Save the stripe MD with this file on the MDS */
254 memset(&iattr, 0, sizeof(iattr));
255 iattr.ia_valid = ATTR_FROM_OPEN;
256 rc = mdc_setattr(&ll_i2sbi(inode)->ll_mdc_conn, inode, &iattr,
257 lmm, lmm_size, &req);
258 ptlrpc_req_finished(req);
260 obd_free_wiremd(conn, &lmm);
262 /* If we couldn't complete mdc_open() and store the stripe MD on the
263 * MDS, we need to destroy the objects now or they will be leaked.
266 CERROR("error: storing stripe MD for %lu: rc %d\n",
268 GOTO(out_destroy, rc);
278 obdo_from_inode(oa, inode, OBD_MD_FLTYPE);
279 oa->o_id = lsm->lsm_object_id;
280 oa->o_valid |= OBD_MD_FLID;
281 err = obd_destroy(conn, oa, lsm, NULL);
282 obd_free_memmd(conn, &lsm);
284 CERROR("error uncreating inode %lu objects: rc %d\n",
289 /* Open a file, and (for the very first open) create objects on the OSTs at
290 * this time. If opened with O_LOV_DELAY_CREATE, then we don't do the object
291 * creation or open until ll_lov_setstripe() ioctl is called. We grab
292 * lli_open_sem to ensure no other process will create objects, send the
293 * stripe MD to the MDS, or try to destroy the objects if that fails.
295 * If we already have the stripe MD locally then we don't request it in
296 * mdc_open(), by passing a lmm_size = 0.
298 * It is up to the application to ensure no other processes open this file
299 * in the O_LOV_DELAY_CREATE case, or the default striping pattern will be
300 * used. We might be able to avoid races of that sort by getting lli_open_sem
301 * before returning in the O_LOV_DELAY_CREATE case and dropping it here
302 * or in ll_file_release(), but I'm not sure that is desirable/necessary.
304 extern int ll_it_open_error(int phase, struct lookup_intent *it);
306 static int ll_file_open(struct inode *inode, struct file *file)
308 struct ll_sb_info *sbi = ll_i2sbi(inode);
309 struct ll_inode_info *lli = ll_i2info(inode);
310 struct lustre_handle *conn = ll_i2obdconn(inode);
311 struct lookup_intent *it;
312 struct lov_stripe_md *lsm;
316 CDEBUG(D_VFSTRACE, "VFS Op\n");
317 LL_GET_INTENT(file->f_dentry, it);
318 rc = ll_it_open_error(IT_OPEN_OPEN, it);
322 rc = ll_local_open(file, it);
326 mdc_set_open_replay_data((struct ll_file_data *)file->private_data);
330 if (file->f_flags & O_LOV_DELAY_CREATE) {
331 CDEBUG(D_INODE, "delaying object creation\n");
334 down(&lli->lli_open_sem);
336 rc = ll_create_obj(conn, inode, file, NULL);
337 up(&lli->lli_open_sem);
341 CERROR("warning: stripe already set on ino %lu\n",
343 up(&lli->lli_open_sem);
348 rc = ll_osc_open(conn, inode, file, lsm);
354 ll_mdc_close(&sbi->ll_mdc_conn, inode, file);
358 int ll_size_lock(struct inode *inode, struct lov_stripe_md *lsm, obd_off start,
359 int mode, struct lustre_handle *lockh)
361 struct ll_sb_info *sbi = ll_i2sbi(inode);
362 struct ldlm_extent extent;
366 /* XXX phil: can we do this? won't it screw the file size up? */
367 if (sbi->ll_flags & LL_SBI_NOLCK)
370 extent.start = start;
371 extent.end = OBD_OBJECT_EOF;
373 rc = obd_enqueue(&sbi->ll_osc_conn, lsm, NULL, LDLM_EXTENT, &extent,
374 sizeof(extent), mode, &flags, ll_lock_callback,
375 inode, sizeof(*inode), lockh);
379 int ll_size_unlock(struct inode *inode, struct lov_stripe_md *lsm, int mode,
380 struct lustre_handle *lockh)
382 struct ll_sb_info *sbi = ll_i2sbi(inode);
386 /* XXX phil: can we do this? won't it screw the file size up? */
387 if (sbi->ll_flags & LL_SBI_NOLCK)
390 rc = obd_cancel(&sbi->ll_osc_conn, lsm, mode, lockh);
391 if (rc != ELDLM_OK) {
392 CERROR("lock cancel: %d\n", rc);
399 /* This function is solely "sampling" the file size, and does not explicit
400 * locking on the size itself (see ll_size_lock() and ll_size_unlock()).
402 * XXX We need to optimize away the obd_getattr for decent performance here,
403 * by checking if we already have the size lock and considering our size
404 * authoritative in that case. In order to do that either the act of
405 * getting the size lock includes retrieving the file size, or the client
406 * keeps an atomic flag in the inode which indicates whether the size
407 * has been updated (see bug 280).
409 int ll_file_size(struct inode *inode, struct lov_stripe_md *lsm, char *ostdata)
411 struct ll_sb_info *sbi = ll_i2sbi(inode);
419 memset(&oa, 0, sizeof oa);
420 oa.o_id = lsm->lsm_object_id;
422 oa.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLSIZE |
423 OBD_MD_FLBLOCKS | OBD_MD_FLMTIME | OBD_MD_FLCTIME;
425 if (ostdata != NULL) {
426 memcpy(&oa.o_inline, ostdata, FD_OSTDATA_SIZE);
427 oa.o_valid |= OBD_MD_FLHANDLE;
430 rc = obd_getattr(&sbi->ll_osc_conn, &oa, lsm);
432 obdo_to_inode(inode, &oa, OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
433 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
434 CDEBUG(D_INODE, "objid "LPX64" size %Lu/%Lx\n",
435 lsm->lsm_object_id, inode->i_size, inode->i_size);
441 static inline void ll_remove_suid(struct inode *inode)
445 /* set S_IGID if S_IXGRP is set, and always set S_ISUID */
446 mode = (inode->i_mode & S_IXGRP)*(S_ISGID/S_IXGRP) | S_ISUID;
448 /* was any of the uid bits set? */
449 mode &= inode->i_mode;
450 if (mode && !capable(CAP_FSETID)) {
451 inode->i_mode &= ~mode;
452 // XXX careful here - we cannot change the size
456 static void ll_update_atime(struct inode *inode)
461 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
462 attr.ia_atime = CURRENT_TIME;
464 attr.ia_atime = CURRENT_TIME.tv_sec;
466 attr.ia_valid = ATTR_ATIME;
468 if (inode->i_atime == attr.ia_atime) return;
469 if (IS_RDONLY(inode)) return;
470 if (IS_NOATIME(inode)) return;
472 /* ll_inode_setattr() sets inode->i_atime from attr.ia_atime */
473 ll_inode_setattr(inode, &attr, 0);
475 /* update atime, but don't explicitly write it out just this change */
476 inode->i_atime = CURRENT_TIME;
480 int ll_lock_callback(struct ldlm_lock *lock, struct ldlm_lock_desc *new,
481 void *data, int flag)
483 struct inode *inode = data;
484 struct lustre_handle lockh = { 0, 0 };
487 CDEBUG(D_VFSTRACE, "VFS Op\n");
493 case LDLM_CB_BLOCKING:
494 ldlm_lock2handle(lock, &lockh);
495 rc = ldlm_cli_cancel(&lockh);
497 CERROR("ldlm_cli_cancel failed: %d\n", rc);
499 case LDLM_CB_CANCELING:
500 CDEBUG(D_INODE, "invalidating obdo/inode %lu\n", inode->i_ino);
501 /* FIXME: do something better than throwing away everything */
502 //down(&inode->i_sem);
503 ll_invalidate_inode_pages(inode);
513 static ssize_t ll_file_read(struct file *filp, char *buf, size_t count,
516 struct ll_file_data *fd = filp->private_data;
517 struct inode *inode = filp->f_dentry->d_inode;
518 struct ll_sb_info *sbi = ll_i2sbi(inode);
519 struct lustre_handle lockh = { 0, 0 };
520 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
526 CDEBUG(D_VFSTRACE, "VFS Op\n");
527 if (!(fd->fd_flags & LL_FILE_IGNORE_LOCK) &&
528 !(sbi->ll_flags & LL_SBI_NOLCK)) {
529 struct ldlm_extent extent;
530 extent.start = *ppos;
531 extent.end = *ppos + count - 1;
532 CDEBUG(D_INFO, "Locking inode %lu, start "LPU64" end "LPU64"\n",
533 inode->i_ino, extent.start, extent.end);
535 err = obd_enqueue(&sbi->ll_osc_conn, lsm, NULL, LDLM_EXTENT,
536 &extent, sizeof(extent), LCK_PR, &flags,
537 ll_lock_callback, inode, sizeof(*inode),
539 if (err != ELDLM_OK) {
540 CERROR("lock enqueue: err: %d\n", err);
545 /* If we don't refresh the file size, generic_file_read may not even
546 * call ll_readpage */
547 retval = ll_file_size(inode, lsm, fd->fd_ostdata);
549 CERROR("ll_file_size: "LPSZ"\n", retval);
553 CDEBUG(D_INFO, "Reading inode %lu, "LPSZ" bytes, offset %Ld\n",
554 inode->i_ino, count, *ppos);
555 retval = generic_file_read(filp, buf, count, ppos);
558 ll_update_atime(inode);
560 if (!(fd->fd_flags & LL_FILE_IGNORE_LOCK) &&
561 !(sbi->ll_flags & LL_SBI_NOLCK)) {
562 err = obd_cancel(&sbi->ll_osc_conn, lsm, LCK_PR, &lockh);
563 if (err != ELDLM_OK) {
564 CERROR("lock cancel: err: %d\n", err);
573 * Write to a file (through the page cache).
576 ll_file_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
578 struct ll_file_data *fd = file->private_data;
579 struct inode *inode = file->f_dentry->d_inode;
580 struct ll_sb_info *sbi = ll_i2sbi(inode);
581 struct lustre_handle lockh = { 0, 0 }, eof_lockh = { 0, 0 };
582 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
588 /* POSIX, but surprised the VFS doesn't check this already */
592 CDEBUG(D_VFSTRACE, "VFS Op\n");
593 if (!S_ISBLK(inode->i_mode) && file->f_flags & O_APPEND) {
594 err = ll_size_lock(inode, lsm, 0, LCK_PW, &eof_lockh);
598 /* Get size here so we know extent to enqueue write lock on. */
599 retval = ll_file_size(inode, lsm, fd->fd_ostdata);
601 GOTO(out_eof, retval);
603 *ppos = inode->i_size;
606 if (!(fd->fd_flags & LL_FILE_IGNORE_LOCK) &&
607 !(sbi->ll_flags & LL_SBI_NOLCK)) {
608 struct ldlm_extent extent;
609 extent.start = *ppos;
610 extent.end = *ppos + count - 1;
611 CDEBUG(D_INFO, "Locking inode %lu, start "LPU64" end "LPU64"\n",
612 inode->i_ino, extent.start, extent.end);
614 err = obd_enqueue(&sbi->ll_osc_conn, lsm, NULL, LDLM_EXTENT,
615 &extent, sizeof(extent), LCK_PW, &flags,
616 ll_lock_callback, inode, sizeof(*inode),
618 if (err != ELDLM_OK) {
619 CERROR("lock enqueue: err: %d\n", err);
620 GOTO(out_eof, retval = err);
624 CDEBUG(D_INFO, "Writing inode %lu, "LPSZ" bytes, offset %Lu\n",
625 inode->i_ino, count, *ppos);
627 retval = generic_file_write(file, buf, count, ppos);
629 if (!(fd->fd_flags & LL_FILE_IGNORE_LOCK) &&
630 !(sbi->ll_flags & LL_SBI_NOLCK)) {
631 err = obd_cancel(&sbi->ll_osc_conn, lsm, LCK_PW, &lockh);
633 CERROR("lock cancel: err: %d\n", err);
638 if (!S_ISBLK(inode->i_mode) && file->f_flags & O_APPEND) {
639 err = ll_size_unlock(inode, lsm, LCK_PW, &eof_lockh);
641 CERROR("ll_size_unlock: %d\n", err);
647 static int ll_lov_setstripe(struct inode *inode, struct file *file,
650 struct ll_inode_info *lli = ll_i2info(inode);
651 struct lustre_handle *conn = ll_i2obdconn(inode);
652 struct lov_stripe_md *lsm;
656 down(&lli->lli_open_sem);
659 up(&lli->lli_open_sem);
660 CERROR("stripe already set for ino %lu\n", inode->i_ino);
661 /* If we haven't already done the open, do so now */
662 if (file->f_flags & O_LOV_DELAY_CREATE) {
663 int rc2 = ll_osc_open(conn, inode, file, lsm);
671 rc = obd_iocontrol(LL_IOC_LOV_SETSTRIPE, conn, 0, &lsm, (void *)arg);
673 up(&lli->lli_open_sem);
676 rc = ll_create_obj(conn, inode, file, lsm);
677 up(&lli->lli_open_sem);
680 obd_free_memmd(conn, &lsm);
683 rc = ll_osc_open(conn, inode, file, lli->lli_smd);
687 static int ll_lov_getstripe(struct inode *inode, unsigned long arg)
689 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
690 struct lustre_handle *conn = ll_i2obdconn(inode);
695 return obd_iocontrol(LL_IOC_LOV_GETSTRIPE, conn, 0, lsm, (void *)arg);
698 int ll_file_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
701 struct ll_file_data *fd = file->private_data;
702 struct lustre_handle *conn;
705 CDEBUG(D_VFSTRACE, "VFS Op\n");
707 if ((cmd & 0xffffff00) == ((int)'T') << 8) /* tty ioctls */
711 case LL_IOC_GETFLAGS:
712 /* Get the current value of the file flags */
713 return put_user(fd->fd_flags, (int *)arg);
714 case LL_IOC_SETFLAGS:
715 case LL_IOC_CLRFLAGS:
716 /* Set or clear specific file flags */
717 /* XXX This probably needs checks to ensure the flags are
718 * not abused, and to handle any flag side effects.
720 if (get_user(flags, (int *) arg))
723 if (cmd == LL_IOC_SETFLAGS)
724 fd->fd_flags |= flags;
726 fd->fd_flags &= ~flags;
728 case LL_IOC_LOV_SETSTRIPE:
729 return ll_lov_setstripe(inode, file, arg);
730 case LL_IOC_LOV_GETSTRIPE:
731 return ll_lov_getstripe(inode, arg);
733 /* We need to special case any other ioctls we want to handle,
734 * to send them to the MDS/OST as appropriate and to properly
735 * network encode the arg field.
736 case EXT2_IOC_GETFLAGS:
737 case EXT2_IOC_SETFLAGS:
738 case EXT2_IOC_GETVERSION_OLD:
739 case EXT2_IOC_GETVERSION_NEW:
740 case EXT2_IOC_SETVERSION_OLD:
741 case EXT2_IOC_SETVERSION_NEW:
744 conn = ll_i2obdconn(inode);
745 return obd_iocontrol(cmd, conn, 0, NULL, (void *)arg);
749 loff_t ll_file_seek(struct file *file, loff_t offset, int origin)
751 struct inode *inode = file->f_dentry->d_inode;
755 CDEBUG(D_VFSTRACE, "VFS Op\n");
758 struct ll_inode_info *lli = ll_i2info(inode);
759 struct ll_file_data *fd = file->private_data;
761 retval = ll_file_size(inode, lli->lli_smd, fd->fd_ostdata);
765 offset += inode->i_size;
769 offset += file->f_pos;
772 if (offset >= 0 && offset <= inode->i_sb->s_maxbytes) {
773 if (offset != file->f_pos) {
774 file->f_pos = offset;
775 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
777 file->f_version = ++event;
785 /* XXX this does not need to do anything for data, it _does_ need to
787 int ll_fsync(struct file *file, struct dentry *dentry, int data)
792 int ll_inode_revalidate(struct dentry *dentry)
794 struct inode *inode = dentry->d_inode;
795 struct lov_stripe_md *lsm;
798 CDEBUG(D_VFSTRACE, "VFS Op\n");
800 CERROR("REPORT THIS LINE TO PETER\n");
804 /* this is very tricky. it is unsafe to call ll_have_md_lock
805 when we have a referenced lock: because it may cause an RPC
806 below when the lock is marked CB_PENDING. That RPC may not
807 go out because someone else may be in another RPC waiting for
809 if (!(dentry->d_it && dentry->d_it->it_lock_mode) &&
810 !ll_have_md_lock(dentry)) {
811 struct ptlrpc_request *req = NULL;
812 struct ll_sb_info *sbi = ll_i2sbi(dentry->d_inode);
813 struct mds_body *body;
814 unsigned long valid = 0;
817 /* Why don't we update all valid MDS fields here, if we're
818 * doing an RPC anyways? -phil */
819 if (S_ISREG(inode->i_mode)) {
820 datalen = obd_size_wiremd(&sbi->ll_osc_conn, NULL);
821 valid |= OBD_MD_FLEASIZE;
823 rc = mdc_getattr(&sbi->ll_mdc_conn, inode->i_ino,
824 inode->i_mode, valid, datalen, &req);
826 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
827 ptlrpc_req_finished(req);
831 body = lustre_msg_buf(req->rq_repmsg, 0);
833 if (S_ISREG(inode->i_mode) &&
834 body->valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) {
835 CERROR("MDS sent back size for regular file\n");
836 body->valid &= ~(OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
839 if (body->valid & OBD_MD_FLEASIZE)
840 ll_update_inode(inode, body,
841 lustre_msg_buf(req->rq_repmsg, 1));
843 ll_update_inode(inode, body, NULL);
844 ptlrpc_req_finished(req);
847 lsm = ll_i2info(inode)->lli_smd;
848 if (!lsm) /* object not yet allocated, don't validate size */
851 /* XXX this should probably become an unconditional obd_getattr()
852 * so that we update the blocks count and mtime from the OST too.
854 RETURN(ll_file_size(inode, lsm, NULL));
857 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
858 static int ll_getattr(struct vfsmount *mnt, struct dentry *de,
862 struct inode *inode = de->d_inode;
864 res = ll_inode_revalidate(de);
867 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
868 stat->dev = inode->i_dev;
870 stat->ino = inode->i_ino;
871 stat->mode = inode->i_mode;
872 stat->nlink = inode->i_nlink;
873 stat->uid = inode->i_uid;
874 stat->gid = inode->i_gid;
875 stat->rdev = kdev_t_to_nr(inode->i_rdev);
876 stat->atime = inode->i_atime;
877 stat->mtime = inode->i_mtime;
878 stat->ctime = inode->i_ctime;
879 stat->size = inode->i_size;
884 struct file_operations ll_file_operations = {
886 write: ll_file_write,
887 ioctl: ll_file_ioctl,
889 release: ll_file_release,
890 mmap: generic_file_mmap,
891 llseek: ll_file_seek,
895 struct inode_operations ll_file_inode_operations = {
896 setattr_raw: ll_setattr_raw,
898 truncate: ll_truncate,
899 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
902 revalidate: ll_inode_revalidate,
906 struct inode_operations ll_special_inode_operations = {
907 setattr_raw: ll_setattr_raw,
909 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
912 revalidate: ll_inode_revalidate,