1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light Super operations
6 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DEBUG_SUBSYSTEM S_LLITE
26 #include <linux/module.h>
27 #include <linux/random.h>
28 #include <linux/version.h>
29 #include <linux/lustre_lite.h>
30 #include <linux/lustre_ha.h>
31 #include <linux/lustre_dlm.h>
32 #include <linux/init.h>
34 #include <linux/lprocfs_status.h>
35 #include "llite_internal.h"
37 kmem_cache_t *ll_file_data_slab;
39 extern struct address_space_operations ll_aops;
40 extern struct address_space_operations ll_dir_aops;
41 extern struct super_operations ll_super_operations;
44 #define log2(n) ffz(~(n))
47 char *ll_read_opt(const char *opt, char *data)
53 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
54 if (strncmp(opt, data, strlen(opt)))
56 if ((value = strchr(data, '=')) == NULL)
60 OBD_ALLOC(retval, strlen(value) + 1);
62 CERROR("out of memory!\n");
66 memcpy(retval, value, strlen(value)+1);
67 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
71 int ll_set_opt(const char *opt, char *data, int fl)
75 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
76 if (strncmp(opt, data, strlen(opt)))
82 void ll_options(char *options, char **ost, char **mds, int *flags)
85 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
86 char *opt_ptr = options;
95 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
96 for (this_char = strtok (options, ",");
98 this_char = strtok (NULL, ",")) {
100 while ((this_char = strsep (&opt_ptr, ",")) != NULL) {
102 CDEBUG(D_SUPER, "this_char %s\n", this_char);
103 if ((!*ost && (*ost = ll_read_opt("osc", this_char)))||
104 (!*mds && (*mds = ll_read_opt("mdc", this_char)))||
105 (!(*flags & LL_SBI_NOLCK) &&
106 ((*flags) = (*flags) |
107 ll_set_opt("nolock", this_char, LL_SBI_NOLCK))))
113 void ll_lli_init(struct ll_inode_info *lli)
115 sema_init(&lli->lli_open_sem, 1);
116 spin_lock_init(&lli->lli_read_extent_lock);
117 INIT_LIST_HEAD(&lli->lli_read_extents);
119 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
120 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
121 ll_lldo_init(&lli->lli_dirty);
122 spin_lock_init(&lli->lli_pg_lock);
123 INIT_LIST_HEAD(&lli->lli_lc_item);
124 plist_init(&lli->lli_pl_read);
125 plist_init(&lli->lli_pl_write);
126 atomic_set(&lli->lli_in_writepages, 0);
130 int ll_fill_super(struct super_block *sb, void *data, int silent)
132 struct inode *root = 0;
133 struct obd_device *obd;
134 struct ll_sb_info *sbi;
138 struct ll_fid rootfid;
139 struct obd_statfs osfs;
140 struct ptlrpc_request *request = NULL;
141 struct ptlrpc_connection *mdc_conn;
147 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
148 OBD_ALLOC(sbi, sizeof(*sbi));
152 INIT_LIST_HEAD(&sbi->ll_conn_chain);
153 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
154 INIT_LIST_HEAD(&sbi->ll_orphan_dentry_list);
155 sb->u.generic_sbp = sbi;
157 INIT_HLIST_HEAD(&sbi->ll_orphan_dentry_list);
158 spin_lock_init(&sbi->ll_iostats.fis_lock);
161 generate_random_uuid(uuid);
162 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
164 ll_options(data, &osc, &mdc, &sbi->ll_flags);
168 GOTO(out_free, err = -EINVAL);
173 GOTO(out_free, err = -EINVAL);
176 obd = class_name2obd(mdc);
178 CERROR("MDC %s: not setup or attached\n", mdc);
179 GOTO(out_free, err = -EINVAL);
182 err = obd_connect(&sbi->ll_mdc_conn, obd, &sbi->ll_sb_uuid);
184 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
188 err = obd_statfs(obd, &osfs, jiffies - HZ);
192 LASSERT(osfs.os_bsize);
193 sb->s_blocksize = osfs.os_bsize;
194 sb->s_blocksize_bits = log2(osfs.os_bsize);
195 sb->s_magic = LL_SUPER_MAGIC;
196 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
198 mdc_conn = sbi2mdc(sbi)->cl_import->imp_connection;
200 obd = class_name2obd(osc);
202 CERROR("OSC %s: not setup or attached\n", osc);
206 err = obd_connect(&sbi->ll_osc_conn, obd, &sbi->ll_sb_uuid);
208 CERROR("cannot connect to %s: rc = %d\n", osc, err);
212 err = mdc_getstatus(&sbi->ll_mdc_conn, &rootfid);
214 CERROR("cannot mds_connect: rc = %d\n", err);
217 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
218 sbi->ll_rootino = rootfid.id;
220 sb->s_op = &ll_super_operations;
223 * XXX: move this to after cbd setup? */
224 err = mdc_getattr(&sbi->ll_mdc_conn, &rootfid,
225 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
227 CERROR("mdc_getattr failed for root: rc = %d\n", err);
231 /* initialize committed transaction callback daemon */
232 spin_lock_init(&sbi->ll_commitcbd_lock);
233 init_waitqueue_head(&sbi->ll_commitcbd_waitq);
234 init_waitqueue_head(&sbi->ll_commitcbd_ctl_waitq);
235 sbi->ll_commitcbd_flags = 0;
236 err = ll_commitcbd_setup(sbi);
238 CERROR("failed to start commit callback daemon: rc = %d\n",err);
239 ptlrpc_req_finished (request);
240 GOTO(out_lliod, err);
243 err = mdc_req2lustre_md(request, 0, &sbi->ll_osc_conn, &md);
245 CERROR("failed to understand root inode md: rc = %d\n",err);
246 ptlrpc_req_finished (request);
247 GOTO(out_lliod, err);
250 LASSERT(sbi->ll_rootino != 0);
251 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
252 root = iget4(sb, sbi->ll_rootino, NULL, &md);
254 root = ll_iget(sb, sbi->ll_rootino, &md);
257 ptlrpc_req_finished(request);
259 if (root == NULL || is_bad_inode(root)) {
260 /* XXX might need iput() for bad inode */
261 CERROR("lustre_lite: bad iget4 for root\n");
262 GOTO(out_cbd, err = -EBADF);
265 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
266 /* initialize the pagecache writeback thread */
267 err = lliod_start(sbi, root);
269 CERROR("failed to start lliod: rc = %d\n",err);
270 GOTO(out_root, sb = NULL);
273 sb->s_root = d_alloc_root(root);
275 if (proc_lustre_fs_root) {
276 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
279 CERROR("could not register mount in /proc/lustre");
284 OBD_FREE(mdc, strlen(mdc) + 1);
286 OBD_FREE(osc, strlen(osc) + 1);
290 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
295 ll_commitcbd_cleanup(sbi);
297 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
301 obd_disconnect(&sbi->ll_osc_conn, 0);
303 obd_disconnect(&sbi->ll_mdc_conn, 0);
305 lprocfs_unregister_mountpoint(sbi);
306 OBD_FREE(sbi, sizeof(*sbi));
309 } /* ll_read_super */
311 void ll_put_super(struct super_block *sb)
313 struct ll_sb_info *sbi = ll_s2sbi(sb);
314 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
315 struct obd_device *obd = class_conn2obd(&sbi->ll_mdc_conn);
316 struct list_head *tmp, *next;
318 struct hlist_node *tmp, *next;
320 struct ll_fid rootfid;
323 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
324 list_del(&sbi->ll_conn_chain);
325 ll_commitcbd_cleanup(sbi);
326 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
329 obd_disconnect(&sbi->ll_osc_conn, 0);
331 /* NULL request to force sync on the MDS, and get the last_committed
332 * value to flush remaining RPCs from the sending queue on client.
334 * XXX This should be an mdc_sync() call to sync the whole MDS fs,
335 * which we can call for other reasons as well.
337 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
338 if (!obd->obd_no_recov)
340 mdc_getstatus(&sbi->ll_mdc_conn, &rootfid);
342 lprocfs_unregister_mountpoint(sbi);
343 if (sbi->ll_proc_root) {
344 lprocfs_remove(sbi->ll_proc_root);
345 sbi->ll_proc_root = NULL;
348 obd_disconnect(&sbi->ll_mdc_conn, 0);
350 spin_lock(&dcache_lock);
351 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
352 list_for_each_safe(tmp, next, &sbi->ll_orphan_dentry_list) {
353 struct dentry *dentry = list_entry(tmp, struct dentry, d_hash);
354 shrink_dcache_parent(dentry);
357 hlist_for_each_safe(tmp, next, &sbi->ll_orphan_dentry_list) {
358 struct dentry *dentry = hlist_entry(tmp, struct dentry, d_hash);
359 shrink_dcache_parent(dentry);
362 spin_unlock(&dcache_lock);
364 OBD_FREE(sbi, sizeof(*sbi));
369 void ll_clear_inode(struct inode *inode)
371 struct ll_sb_info *sbi = ll_i2sbi(inode);
372 struct ll_inode_info *lli = ll_i2info(inode);
376 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
377 inode->i_generation, inode);
378 rc = ll_mdc_cancel_unused(&sbi->ll_mdc_conn, inode,
379 LDLM_FL_WARN | LDLM_FL_NO_CALLBACK, inode);
381 CERROR("ll_mdc_cancel_unused: %d\n", rc);
382 /* XXX FIXME do something dramatic */
385 if (atomic_read(&inode->i_count) != 0)
386 CERROR("clearing in-use inode %lu: count = %d\n",
387 inode->i_ino, atomic_read(&inode->i_count));
390 rc = obd_cancel_unused(&sbi->ll_osc_conn, lli->lli_smd,
391 LDLM_FL_WARN, inode);
393 CERROR("obd_cancel_unused: %d\n", rc);
394 /* XXX FIXME do something dramatic */
396 obd_free_memmd(&sbi->ll_osc_conn, &lli->lli_smd);
400 if (lli->lli_symlink_name) {
401 OBD_FREE(lli->lli_symlink_name,
402 strlen(lli->lli_symlink_name) + 1);
403 lli->lli_symlink_name = NULL;
410 static void ll_delete_inode(struct inode *inode)
413 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu(%p)\n", inode->i_ino, inode);
414 if (S_ISREG(inode->i_mode)) {
417 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
419 /* mcreate with no open */
423 if (lsm->lsm_object_id == 0) {
424 CERROR("This really happens\n");
425 /* No obdo was ever created */
433 oa->o_id = lsm->lsm_object_id;
434 oa->o_valid = OBD_MD_FLID;
435 obdo_from_inode(oa, inode, OBD_MD_FLTYPE);
437 err = obd_destroy(ll_i2obdconn(inode), oa, lsm, NULL);
441 "inode %lu obd_destroy objid "LPX64" error %d\n",
442 inode->i_ino, lsm->lsm_object_id, err);
450 /* like inode_setattr, but doesn't mark the inode dirty */
451 int ll_attr2inode(struct inode *inode, struct iattr *attr, int trunc)
453 unsigned int ia_valid = attr->ia_valid;
456 if ((ia_valid & ATTR_SIZE) && trunc) {
457 if (attr->ia_size > ll_file_maxbytes(inode)) {
461 error = vmtruncate(inode, attr->ia_size);
464 } else if (ia_valid & ATTR_SIZE)
465 inode->i_size = attr->ia_size;
467 if (ia_valid & ATTR_UID)
468 inode->i_uid = attr->ia_uid;
469 if (ia_valid & ATTR_GID)
470 inode->i_gid = attr->ia_gid;
471 if (ia_valid & ATTR_ATIME)
472 inode->i_atime = attr->ia_atime;
473 if (ia_valid & ATTR_MTIME)
474 inode->i_mtime = attr->ia_mtime;
475 if (ia_valid & ATTR_CTIME)
476 inode->i_ctime = attr->ia_ctime;
477 if (ia_valid & ATTR_MODE) {
478 inode->i_mode = attr->ia_mode;
479 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
480 inode->i_mode &= ~S_ISGID;
486 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc)
488 struct ptlrpc_request *request = NULL;
489 struct ll_sb_info *sbi = ll_i2sbi(inode);
493 /* change incore inode */
494 err = ll_attr2inode(inode, attr, do_trunc);
498 /* Don't send size changes to MDS to avoid "fast EA" problems, and
499 * also avoid a pointless RPC (we get file size from OST anyways).
501 attr->ia_valid &= ~ATTR_SIZE;
502 if (attr->ia_valid) {
503 struct mdc_op_data op_data;
505 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
506 err = mdc_setattr(&sbi->ll_mdc_conn, &op_data,
507 attr, NULL, 0, NULL, 0, &request);
509 CERROR("mdc_setattr fails: err = %d\n", err);
511 ptlrpc_req_finished(request);
512 if (S_ISREG(inode->i_mode) && attr->ia_valid & ATTR_MTIME_SET) {
513 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
517 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
518 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
519 inode->i_ino, attr->ia_mtime);
520 oa.o_mtime = attr->ia_mtime;
522 CDEBUG(D_INODE, "set mtime on OST inode %lu to "
523 LPU64"\n", inode->i_ino,
524 ll_ts2u64(&attr->ia_mtime));
525 oa.o_mtime = ll_ts2u64(&attr->ia_mtime);
527 oa.o_id = lsm->lsm_object_id;
529 oa.o_valid = OBD_MD_FLID |OBD_MD_FLTYPE |OBD_MD_FLMTIME;
530 err2 = obd_setattr(&sbi->ll_osc_conn, &oa, lsm, NULL);
532 CERROR("obd_setattr fails: rc=%d\n", err);
542 /* If this inode has objects allocated to it (lsm != NULL), then the OST
543 * object(s) determine the file size and mtime. Otherwise, the MDS will
544 * keep these values until such a time that objects are allocated for it.
545 * We do the MDS operations first, as it is checking permissions for us.
546 * We don't to the MDS RPC if there is nothing that we want to store there,
547 * otherwise there is no harm in updating mtime/atime on the MDS if we are
548 * going to do an RPC anyways.
550 * If we are doing a truncate, we will send the mtime and ctime updates
551 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
552 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
555 #define OST_ATTR (ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME | \
556 ATTR_ATIME | ATTR_ATIME_SET | ATTR_SIZE)
557 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
559 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
560 struct ll_sb_info *sbi = ll_i2sbi(inode);
561 struct ptlrpc_request *request = NULL;
562 struct mdc_op_data op_data;
563 time_t now = LTIME_S(CURRENT_TIME);
564 int ia_valid = attr->ia_valid;
568 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", inode->i_ino);
570 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
571 lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_SETATTR);
574 if (ia_valid & ATTR_SIZE) {
575 if (attr->ia_size > ll_file_maxbytes(inode)) {
576 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
577 attr->ia_size, ll_file_maxbytes(inode));
581 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
584 /* We mark all of the fields "set" so MDS/OST does not re-set them */
585 if (attr->ia_valid & ATTR_CTIME) {
586 attr->ia_ctime = now;
587 attr->ia_valid |= ATTR_CTIME_SET;
589 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
590 attr->ia_atime = now;
591 attr->ia_valid |= ATTR_ATIME_SET;
593 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
594 attr->ia_mtime = now;
595 attr->ia_valid |= ATTR_MTIME_SET;
598 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
599 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
600 attr->ia_mtime, attr->ia_ctime, now);
602 attr->ia_valid &= ~ATTR_SIZE;
604 /* If only OST attributes being set on objects, don't do MDS RPC.
605 * In that case, we need to check permissions and update the local
606 * inode ourselves so we can call obdo_from_inode() always. */
607 if (ia_valid & (lsm ? ~(OST_ATTR | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
609 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
611 rc = mdc_setattr(&sbi->ll_mdc_conn, &op_data,
612 attr, NULL, 0, NULL, 0, &request);
615 ptlrpc_req_finished(request);
616 if (rc != -EPERM && rc != -EACCES)
617 CERROR("mdc_setattr fails: rc = %d\n", rc);
621 rc = mdc_req2lustre_md(request, 0, &sbi->ll_osc_conn, &md);
623 ptlrpc_req_finished(request);
626 ll_update_inode(inode, md.body, md.lsm);
627 ptlrpc_req_finished(request);
629 if (!md.lsm || !S_ISREG(inode->i_mode)) {
630 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
634 /* The OST doesn't check permissions, but the alternative is
635 * a gratuitous RPC to the MDS. We already rely on the client
636 * to do read/write/truncate permission checks, so is mtime OK?
638 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
639 /* from sys_utime() */
640 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
641 if (current->fsuid != inode->i_uid &&
642 (rc = permission(inode, MAY_WRITE)) != 0)
645 /* from inode_change_ok() */
646 if (current->fsuid != inode->i_uid &&
647 !capable(CAP_FOWNER))
652 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
653 inode_setattr(inode, attr);
656 if (ia_valid & ATTR_SIZE) {
657 struct ldlm_extent extent = { .start = attr->ia_size,
658 .end = OBD_OBJECT_EOF };
659 struct lustre_handle lockh = { 0 };
662 /* Writeback uses inode->i_size to determine how far out
663 * its cached pages go. ll_truncate gets a PW lock, canceling
664 * our lock, _after_ it has updated i_size. this can confuse
666 * We really need to get our PW lock before we change
667 * inode->i_size. If we don't we can race with other
668 * i_size updaters on our node, like ll_file_read. We
669 * can also race with i_size propogation to other
670 * nodes through dirtying and writeback of final cached
671 * pages. This last one is especially bad for racing
672 * o_append users on other nodes. */
673 /* bug 1639: avoid write/truncate i_sem/DLM deadlock */
674 LASSERT(atomic_read(&inode->i_sem.count) <= 0);
676 rc = ll_extent_lock_no_validate(NULL, inode, lsm, LCK_PW,
679 if (rc != ELDLM_OK) {
685 rc = vmtruncate(inode, attr->ia_size);
687 set_bit(LLI_F_HAVE_SIZE_LOCK,
688 &ll_i2info(inode)->lli_flags);
690 /* unlock now as we don't mind others file lockers racing with
691 * the mds updates below? */
692 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
694 CERROR("ll_extent_unlock failed: %d\n", err);
698 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
701 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
702 inode->i_ino, attr->ia_mtime);
703 oa.o_id = lsm->lsm_object_id;
704 oa.o_valid = OBD_MD_FLID;
705 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
706 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
707 rc = obd_setattr(&sbi->ll_osc_conn, &oa, lsm, NULL);
709 CERROR("obd_setattr fails: rc=%d\n", rc);
714 int ll_setattr(struct dentry *de, struct iattr *attr)
716 int rc = inode_change_ok(de->d_inode, attr);
717 CDEBUG(D_VFSTRACE, "VFS Op:name=%s\n", de->d_name.name);
721 lprocfs_counter_incr(ll_i2sbi(de->d_inode)->ll_stats, LPROC_LL_SETATTR);
722 return ll_inode_setattr(de->d_inode, attr, 1);
725 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
726 unsigned long max_age)
728 struct ll_sb_info *sbi = ll_s2sbi(sb);
729 struct obd_statfs obd_osfs;
733 rc = obd_statfs(class_conn2obd(&sbi->ll_mdc_conn), osfs, max_age);
735 CERROR("mdc_statfs fails: rc = %d\n", rc);
739 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
740 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
742 rc = obd_statfs(class_conn2obd(&sbi->ll_osc_conn), &obd_osfs, max_age);
744 CERROR("obd_statfs fails: rc = %d\n", rc);
748 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
749 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
752 osfs->os_blocks = obd_osfs.os_blocks;
753 osfs->os_bfree = obd_osfs.os_bfree;
754 osfs->os_bavail = obd_osfs.os_bavail;
756 /* If we don't have as many objects free on the OST as inodes
757 * on the MDS, we reduce the total number of inodes to
758 * compensate, so that the "inodes in use" number is correct.
760 if (obd_osfs.os_ffree < osfs->os_ffree) {
761 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
763 osfs->os_ffree = obd_osfs.os_ffree;
769 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
771 struct obd_statfs osfs;
774 CDEBUG(D_VFSTRACE, "VFS Op:\n");
775 lprocfs_counter_incr(ll_s2sbi(sb)->ll_stats, LPROC_LL_STAFS);
777 /* For now we will always get up-to-date statfs values, but in the
778 * future we may allow some amount of caching on the client (e.g.
779 * from QOS or lprocfs updates). */
780 rc = ll_statfs_internal(sb, &osfs, jiffies - 1);
784 statfs_unpack(sfs, &osfs);
786 if (sizeof(sfs->f_blocks) == 4) {
787 while (osfs.os_blocks > ~0UL) {
790 osfs.os_blocks >>= 1;
792 osfs.os_bavail >>= 1;
796 sfs->f_blocks = osfs.os_blocks;
797 sfs->f_bfree = osfs.os_bfree;
798 sfs->f_bavail = osfs.os_bavail;
803 void dump_lsm(int level, struct lov_stripe_md *lsm)
805 CDEBUG(level, "objid "LPX64", maxbytes "LPX64", magic %#08x, "
806 "stripe_size %#08x, offset %u, stripe_count %u\n",
807 lsm->lsm_object_id, lsm->lsm_maxbytes, lsm->lsm_magic,
808 lsm->lsm_stripe_size, lsm->lsm_stripe_offset,
809 lsm->lsm_stripe_count);
812 void ll_update_inode(struct inode *inode, struct mds_body *body,
813 struct lov_stripe_md *lsm)
815 struct ll_inode_info *lli = ll_i2info(inode);
817 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
819 if (lli->lli_smd == NULL) {
821 lli->lli_maxbytes = lsm->lsm_maxbytes;
822 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
823 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
825 if (memcmp(lli->lli_smd, lsm, sizeof(*lsm))) {
826 CERROR("lsm mismatch for inode %ld\n",
828 CERROR("lli_smd:\n");
829 dump_lsm(D_ERROR, lli->lli_smd);
831 dump_lsm(D_ERROR, lsm);
837 if (body->valid & OBD_MD_FLID)
838 inode->i_ino = body->ino;
839 if (body->valid & OBD_MD_FLATIME)
840 LTIME_S(inode->i_atime) = body->atime;
841 if (body->valid & OBD_MD_FLMTIME) {
842 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %u\n",
843 inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
844 LTIME_S(inode->i_mtime) = body->mtime;
846 if (body->valid & OBD_MD_FLCTIME &&
847 body->ctime > LTIME_S(inode->i_ctime))
848 LTIME_S(inode->i_ctime) = body->ctime;
849 if (body->valid & OBD_MD_FLMODE)
850 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
851 if (body->valid & OBD_MD_FLTYPE)
852 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
853 if (body->valid & OBD_MD_FLUID)
854 inode->i_uid = body->uid;
855 if (body->valid & OBD_MD_FLGID)
856 inode->i_gid = body->gid;
857 if (body->valid & OBD_MD_FLFLAGS)
858 inode->i_flags = body->flags;
859 if (body->valid & OBD_MD_FLNLINK)
860 inode->i_nlink = body->nlink;
861 if (body->valid & OBD_MD_FLGENER)
862 inode->i_generation = body->generation;
863 if (body->valid & OBD_MD_FLRDEV)
864 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
865 inode->i_rdev = body->rdev;
867 inode->i_rdev = to_kdev_t(body->rdev);
869 if (body->valid & OBD_MD_FLSIZE)
870 inode->i_size = body->size;
871 if (body->valid & OBD_MD_FLBLOCKS)
872 inode->i_blocks = body->blocks;
875 void ll_read_inode2(struct inode *inode, void *opaque)
877 struct lustre_md *md = opaque;
878 struct ll_inode_info *lli = ll_i2info(inode);
881 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
882 inode->i_generation, inode);
886 LASSERT(!lli->lli_smd);
888 /* Core attributes from the MDS first. This is a new inode, and
889 * the VFS doesn't zero times in the core inode so we have to do
890 * it ourselves. They will be overwritten by either MDS or OST
891 * attributes - we just need to make sure they aren't newer. */
892 LTIME_S(inode->i_mtime) = 0;
893 LTIME_S(inode->i_atime) = 0;
894 LTIME_S(inode->i_ctime) = 0;
895 ll_update_inode(inode, md->body, md->lsm);
897 /* OIDEBUG(inode); */
899 if (S_ISREG(inode->i_mode)) {
900 inode->i_op = &ll_file_inode_operations;
901 inode->i_fop = &ll_file_operations;
902 inode->i_mapping->a_ops = &ll_aops;
904 } else if (S_ISDIR(inode->i_mode)) {
905 inode->i_op = &ll_dir_inode_operations;
906 inode->i_fop = &ll_dir_operations;
907 inode->i_mapping->a_ops = &ll_dir_aops;
909 } else if (S_ISLNK(inode->i_mode)) {
910 inode->i_op = &ll_fast_symlink_inode_operations;
913 inode->i_op = &ll_special_inode_operations;
914 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
915 init_special_inode(inode, inode->i_mode,
916 kdev_t_to_nr(inode->i_rdev));
918 init_special_inode(inode, inode->i_mode, inode->i_rdev);
924 int it_disposition(struct lookup_intent *it, int flag)
926 return it->it_disposition & flag;
929 void it_set_disposition(struct lookup_intent *it, int flag)
931 it->it_disposition |= flag;
934 void ll_umount_begin(struct super_block *sb)
936 struct ll_sb_info *sbi = ll_s2sbi(sb);
937 struct obd_device *obd;
938 struct obd_ioctl_data ioc_data = { 0 };
940 CDEBUG(D_VFSTRACE, "VFS Op:\n");
942 obd = class_conn2obd(&sbi->ll_mdc_conn);
944 CERROR("Invalid MDC connection handle "LPX64"\n",
945 sbi->ll_mdc_conn.cookie);
949 obd->obd_no_recov = 1;
950 obd_iocontrol(IOC_OSC_SET_ACTIVE, &sbi->ll_mdc_conn, sizeof ioc_data,
953 obd = class_conn2obd(&sbi->ll_osc_conn);
954 obd->obd_no_recov = 1;
955 obd_iocontrol(IOC_OSC_SET_ACTIVE, &sbi->ll_osc_conn, sizeof ioc_data,
958 /* Really, we'd like to wait until there are no requests outstanding,
959 * and then continue. For now, we just invalidate the requests,
960 * schedule, and hope.