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-2005 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/types.h>
28 #include <linux/random.h>
29 #include <linux/version.h>
31 #include <linux/lustre_idl.h>
32 #include <linux/lustre_lite.h>
33 #include <linux/lustre_ha.h>
34 #include <linux/lustre_ver.h>
35 #include <linux/lustre_dlm.h>
36 #include <linux/lprocfs_status.h>
37 #include <linux/lustre_disk.h>
38 #include "llite_internal.h"
40 kmem_cache_t *ll_file_data_slab;
42 LIST_HEAD(ll_super_blocks);
43 spinlock_t ll_sb_lock = SPIN_LOCK_UNLOCKED;
45 extern struct address_space_operations ll_aops;
46 extern struct address_space_operations ll_dir_aops;
49 #define log2(n) ffz(~(n))
53 struct ll_sb_info *ll_init_sbi(void)
55 struct ll_sb_info *sbi = NULL;
59 OBD_ALLOC(sbi, sizeof(*sbi));
63 spin_lock_init(&sbi->ll_lock);
64 spin_lock_init(&sbi->ll_lco.lco_lock);
65 INIT_LIST_HEAD(&sbi->ll_pglist);
66 sbi->ll_pglist_gen = 0;
67 if (num_physpages >> (20 - PAGE_SHIFT) < 512)
68 sbi->ll_async_page_max = num_physpages / 2;
70 sbi->ll_async_page_max = (num_physpages / 4) * 3;
71 sbi->ll_ra_info.ra_max_pages = min(num_physpages / 8,
72 SBI_DEFAULT_READAHEAD_MAX);
74 INIT_LIST_HEAD(&sbi->ll_conn_chain);
75 INIT_HLIST_HEAD(&sbi->ll_orphan_dentry_list);
77 class_generate_random_uuid(uuid);
78 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
79 CDEBUG(D_HA, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
81 spin_lock(&ll_sb_lock);
82 list_add_tail(&sbi->ll_list, &ll_super_blocks);
83 spin_unlock(&ll_sb_lock);
85 INIT_LIST_HEAD(&sbi->ll_deathrow);
86 spin_lock_init(&sbi->ll_deathrow_lock);
90 void ll_free_sbi(struct super_block *sb)
92 struct ll_sb_info *sbi = ll_s2sbi(sb);
96 spin_lock(&ll_sb_lock);
97 list_del(&sbi->ll_list);
98 spin_unlock(&ll_sb_lock);
99 OBD_FREE(sbi, sizeof(*sbi));
104 static struct dentry_operations ll_d_root_ops = {
105 .d_compare = ll_dcompare,
108 int client_common_fill_super(struct super_block *sb, char *mdc, char *osc)
110 struct inode *root = 0;
111 struct ll_sb_info *sbi = ll_s2sbi(sb);
112 struct obd_device *obd;
113 struct lu_fid rootfid;
114 struct obd_statfs osfs;
115 struct ptlrpc_request *request = NULL;
116 struct lustre_handle osc_conn = {0, };
117 struct lustre_handle mdc_conn = {0, };
119 struct obd_connect_data *data = NULL;
123 obd = class_name2obd(mdc);
125 CERROR("MDC %s: not setup or attached\n", mdc);
129 OBD_ALLOC(data, sizeof(*data));
133 if (proc_lustre_fs_root) {
134 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
137 CERROR("could not register mount in /proc/lustre");
140 /* indicate that inodebits locking is supported by this client */
141 data->ocd_connect_flags |= OBD_CONNECT_IBITS;
142 data->ocd_ibits_known = MDS_INODELOCK_FULL;
144 if (sb->s_flags & MS_RDONLY)
145 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
146 if (sbi->ll_flags & LL_SBI_USER_XATTR)
147 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
148 data->ocd_connect_flags |= OBD_CONNECT_ACL | OBD_CONNECT_JOIN;
150 if (sbi->ll_flags & LL_SBI_FLOCK) {
151 sbi->ll_fop = &ll_file_operations_flock;
153 sbi->ll_fop = &ll_file_operations;
156 data->ocd_connect_flags |= OBD_CONNECT_VERSION;
157 data->ocd_version = LUSTRE_VERSION_CODE;
159 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid, data);
161 CERROR("An MDT (mdc %s) is performing recovery, of which this"
162 " client is not a part. Please wait for recovery to "
163 "complete, abort, or time out.\n", mdc);
166 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
169 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
171 err = obd_statfs(obd, &osfs, jiffies - HZ);
175 /* async connect is surely finished by now */
176 *data = class_exp2cliimp(sbi->ll_mdc_exp)->imp_connect_data;
178 LASSERT(osfs.os_bsize);
179 sb->s_blocksize = osfs.os_bsize;
180 sb->s_blocksize_bits = log2(osfs.os_bsize);
181 sb->s_magic = LL_SUPER_MAGIC;
182 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
183 sbi->ll_namelen = osfs.os_namelen;
185 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
186 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
187 LCONSOLE_INFO("Disabling user_xattr feature because "
188 "it is not supported on the server\n");
189 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
192 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
194 sb->s_flags |= MS_POSIXACL;
196 sbi->ll_flags |= LL_SBI_ACL;
198 sbi->ll_flags &= ~LL_SBI_ACL;
200 if (data->ocd_connect_flags & OBD_CONNECT_JOIN)
201 sbi->ll_flags |= LL_SBI_JOIN;
203 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
204 /* We set sb->s_dev equal on all lustre clients in order to support
205 * NFS export clustering. NFSD requires that the FSID be the same
207 /* s_dev is also used in lt_compare() to compare two fs, but that is
208 * only a node-local comparison. */
209 sb->s_dev = get_uuid2int(sbi2mdc(sbi)->cl_import->imp_target_uuid.uuid,
210 strlen(sbi2mdc(sbi)->cl_import->imp_target_uuid.uuid));
213 obd = class_name2obd(osc);
215 CERROR("OSC %s: not setup or attached\n", osc);
219 data->ocd_connect_flags =
220 OBD_CONNECT_GRANT|OBD_CONNECT_VERSION|OBD_CONNECT_REQPORTAL;
222 CDEBUG(D_RPCTRACE, "ocd_connect_flags: "LPX64" ocd_version: %d "
223 "ocd_grant: %d\n", data->ocd_connect_flags,
224 data->ocd_version, data->ocd_grant);
226 obd->obd_upcall.onu_owner = &sbi->ll_lco;
227 obd->obd_upcall.onu_upcall = ll_ocd_update;
229 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid, data);
231 CERROR("An OST (osc %s) is performing recovery, of which this"
232 " client is not a part. Please wait for recovery to "
233 "complete, abort, or time out.\n", osc);
236 CERROR("cannot connect to %s: rc = %d\n", osc, err);
239 sbi->ll_osc_exp = class_conn2export(&osc_conn);
240 spin_lock(&sbi->ll_lco.lco_lock);
241 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
242 spin_unlock(&sbi->ll_lco.lco_lock);
244 mdc_init_ea_size(sbi->ll_mdc_exp, sbi->ll_osc_exp);
246 err = obd_prep_async_page(sbi->ll_osc_exp, NULL, NULL, NULL,
247 0, NULL, NULL, NULL);
249 LCONSOLE_ERROR("There are no OST's in this filesystem. "
250 "There must be at least one active OST for "
251 "a client to start.\n");
255 if (!ll_async_page_slab) {
256 ll_async_page_slab_size =
257 size_round(sizeof(struct ll_async_page)) + err;
258 ll_async_page_slab = kmem_cache_create("ll_async_page",
259 ll_async_page_slab_size,
261 if (!ll_async_page_slab)
262 GOTO(out_osc, -ENOMEM);
265 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
267 CERROR("cannot mds_connect: rc = %d\n", err);
270 CDEBUG(D_SUPER, "rootfid "DFID3"\n", PFID3(&rootfid));
271 sbi->ll_root_fid = rootfid;
273 sb->s_op = &lustre_super_operations;
276 * XXX: move this to after cbd setup? */
277 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
278 OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS |
279 (sbi->ll_flags & LL_SBI_ACL ? OBD_MD_FLACL : 0),
282 CERROR("mdc_getattr failed for root: rc = %d\n", err);
286 err = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
288 CERROR("failed to understand root inode md: rc = %d\n", err);
289 ptlrpc_req_finished (request);
293 LASSERT(fid_oid(&sbi->ll_root_fid) != 0);
294 root = ll_iget(sb, ll_fid2ino(sbi, &sbi->ll_root_fid), &md);
295 ll_i2info(root)->lli_fid = sbi->ll_root_fid;
296 ptlrpc_req_finished(request);
298 if (root == NULL || is_bad_inode(root)) {
299 mdc_free_lustre_md(sbi->ll_osc_exp, &md);
300 CERROR("lustre_lite: bad iget4 for root\n");
301 GOTO(out_root, err = -EBADF);
304 err = ll_close_thread_start(&sbi->ll_lcq);
306 CERROR("cannot start close thread: rc %d\n", err);
310 /* making vm readahead 0 for 2.4.x. In the case of 2.6.x,
311 backing dev info assigned to inode mapping is used for
312 determining maximal readahead. */
313 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) && \
314 !defined(KERNEL_HAS_AS_MAX_READAHEAD)
315 /* bug 2805 - set VM readahead to zero */
316 vm_max_readahead = vm_min_readahead = 0;
319 sb->s_root = d_alloc_root(root);
321 OBD_FREE(data, sizeof(*data));
322 sb->s_root->d_op = &ll_d_root_ops;
329 obd_disconnect(sbi->ll_osc_exp);
331 obd_disconnect(sbi->ll_mdc_exp);
334 OBD_FREE(data, sizeof(*data));
335 lprocfs_unregister_mountpoint(sbi);
339 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
343 *lmmsize = obd_size_diskmd(sbi->ll_osc_exp, NULL);
345 rc = obd_get_info(sbi->ll_mdc_exp, strlen("max_easize"), "max_easize",
348 CERROR("Get max mdsize error rc %d \n", rc);
353 void ll_dump_inode(struct inode *inode)
355 struct list_head *tmp;
356 int dentry_count = 0;
358 LASSERT(inode != NULL);
360 list_for_each(tmp, &inode->i_dentry)
363 CERROR("inode %p dump: dev=%s ino=%lu mode=%o count=%u, %d dentries\n",
364 inode, ll_i2mdcexp(inode)->exp_obd->obd_name, inode->i_ino,
365 inode->i_mode, atomic_read(&inode->i_count), dentry_count);
368 void lustre_dump_dentry(struct dentry *dentry, int recur)
370 struct list_head *tmp;
373 LASSERT(dentry != NULL);
375 list_for_each(tmp, &dentry->d_subdirs)
378 CERROR("dentry %p dump: name=%.*s parent=%.*s (%p), inode=%p, count=%u,"
379 " flags=0x%x, fsdata=%p, %d subdirs\n", dentry,
380 dentry->d_name.len, dentry->d_name.name,
381 dentry->d_parent->d_name.len, dentry->d_parent->d_name.name,
382 dentry->d_parent, dentry->d_inode, atomic_read(&dentry->d_count),
383 dentry->d_flags, dentry->d_fsdata, subdirs);
384 if (dentry->d_inode != NULL)
385 ll_dump_inode(dentry->d_inode);
390 list_for_each(tmp, &dentry->d_subdirs) {
391 struct dentry *d = list_entry(tmp, struct dentry, d_child);
392 lustre_dump_dentry(d, recur - 1);
396 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
397 void lustre_throw_orphan_dentries(struct super_block *sb)
399 struct hlist_node *tmp, *next;
400 struct ll_sb_info *sbi = ll_s2sbi(sb);
402 /* Do this to get rid of orphaned dentries. That is not really trw. */
403 hlist_for_each_safe(tmp, next, &sbi->ll_orphan_dentry_list) {
404 struct dentry *dentry = hlist_entry(tmp, struct dentry, d_hash);
405 CWARN("found orphan dentry %.*s (%p->%p) at unmount, dumping "
406 "before and after shrink_dcache_parent\n",
407 dentry->d_name.len, dentry->d_name.name, dentry, next);
408 lustre_dump_dentry(dentry, 1);
409 shrink_dcache_parent(dentry);
410 lustre_dump_dentry(dentry, 1);
414 #define lustre_throw_orphan_dentries(sb)
417 static void prune_deathrow(struct ll_sb_info *sbi, int try)
419 LIST_HEAD(throw_away);
424 locked = spin_trylock(&sbi->ll_deathrow_lock);
426 spin_lock(&sbi->ll_deathrow_lock);
435 list_splice_init(&sbi->ll_deathrow, &throw_away);
436 spin_unlock(&sbi->ll_deathrow_lock);
438 while (!list_empty(&throw_away)) {
439 struct ll_inode_info *lli;
442 lli = list_entry(throw_away.next, struct ll_inode_info,
444 list_del_init(&lli->lli_dead_list);
446 inode = ll_info2i(lli);
447 d_prune_aliases(inode);
449 CDEBUG(D_INODE, "prune duplicate inode %p inum %lu count %u\n",
450 inode, inode->i_ino, atomic_read(&inode->i_count));
456 void client_common_put_super(struct super_block *sb)
458 struct ll_sb_info *sbi = ll_s2sbi(sb);
461 ll_close_thread_shutdown(sbi->ll_lcq);
463 /* destroy inodes in deathrow */
464 prune_deathrow(sbi, 0);
466 list_del(&sbi->ll_conn_chain);
467 obd_disconnect(sbi->ll_osc_exp);
469 lprocfs_unregister_mountpoint(sbi);
470 if (sbi->ll_proc_root) {
471 lprocfs_remove(sbi->ll_proc_root);
472 sbi->ll_proc_root = NULL;
475 obd_disconnect(sbi->ll_mdc_exp);
477 lustre_throw_orphan_dentries(sb);
481 char *ll_read_opt(const char *opt, char *data)
487 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
488 if (strncmp(opt, data, strlen(opt)))
490 if ((value = strchr(data, '=')) == NULL)
494 OBD_ALLOC(retval, strlen(value) + 1);
496 CERROR("out of memory!\n");
500 memcpy(retval, value, strlen(value)+1);
501 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
505 static inline int ll_set_opt(const char *opt, char *data, int fl)
507 if (strncmp(opt, data, strlen(opt)) != 0)
513 /* non-client-specific mount options are parsed in lmd_parse */
514 void ll_options(char *options, int *flags)
517 char *s1 = options, *s2;
525 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
528 CDEBUG(D_SUPER, "next opt=%s\n", s1);
529 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
534 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
539 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK);
544 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
549 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
554 tmp = ll_set_opt("acl", s1, LL_SBI_ACL);
556 /* Ignore deprecated mount option. The client will
557 * always try to mount with ACL support, whether this
558 * is used depends on whether server supports it. */
561 tmp = ll_set_opt("noacl", s1, LL_SBI_ACL);
568 s2 = strchr(s1, ',');
576 void ll_lli_init(struct ll_inode_info *lli)
578 sema_init(&lli->lli_open_sem, 1);
579 sema_init(&lli->lli_size_sem, 1);
581 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
582 spin_lock_init(&lli->lli_lock);
583 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
584 lli->lli_inode_magic = LLI_INODE_MAGIC;
585 INIT_LIST_HEAD(&lli->lli_dead_list);
588 int ll_fill_super(struct super_block *sb)
590 struct lustre_profile *lprof;
591 struct lustre_sb_info *lsi = s2lsi(sb);
592 struct ll_sb_info *sbi;
595 char *profilenm = get_profile_name(sb);
596 struct config_llog_instance cfg;
597 char ll_instance[sizeof(sb) * 2 + 1];
601 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
603 /* client additional sb info */
604 lsi->lsi_llsbi = sbi = ll_init_sbi();
608 ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
610 /* Generate a string unique to this super, in case some joker tries
611 to mount the same fs at two mount points.
612 Use the address of the super itself.*/
613 sprintf(ll_instance, "%p", sb);
614 cfg.cfg_instance = ll_instance;
615 cfg.cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
616 cfg.cfg_last_idx = 0;
618 /* set up client obds */
619 err = lustre_process_log(sb, profilenm, &cfg);
621 CERROR("Unable to process log: %d\n", err);
625 lprof = class_get_profile(profilenm);
627 CERROR("No profile found: %s\n", profilenm);
628 GOTO(out_free, err = -EINVAL);
630 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
631 lprof->lp_mdc, lprof->lp_osc);
633 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
634 strlen(ll_instance) + 2);
636 GOTO(out_free, err = -ENOMEM);
637 sprintf(osc, "%s-%s", lprof->lp_osc, ll_instance);
639 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
640 strlen(ll_instance) + 2);
642 GOTO(out_free, err = -ENOMEM);
643 sprintf(mdc, "%s-%s", lprof->lp_mdc, ll_instance);
645 /* connections, registrations, sb setup */
646 err = client_common_fill_super(sb, mdc, osc);
650 OBD_FREE(mdc, strlen(mdc) + 1);
652 OBD_FREE(osc, strlen(osc) + 1);
654 struct obd_device *obd;
656 /* like client_put_super below */
657 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next))
659 class_manual_cleanup(obd);
661 class_del_profile(profilenm);
663 lsi->lsi_llsbi = NULL;
666 } /* ll_fill_super */
669 void ll_put_super(struct super_block *sb)
671 struct config_llog_instance cfg;
672 char ll_instance[sizeof(sb) * 2 + 1];
673 struct obd_device *obd;
674 struct lustre_sb_info *lsi = s2lsi(sb);
675 struct ll_sb_info *sbi = ll_s2sbi(sb);
676 char *profilenm = get_profile_name(sb);
680 CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
682 sprintf(ll_instance, "%p", sb);
683 cfg.cfg_instance = ll_instance;
684 lustre_end_log(sb, NULL, &cfg);
686 obd = class_exp2obd(sbi->ll_mdc_exp);
689 int force = obd->obd_no_recov;
690 /* We need to set force before the lov_disconnect in
691 lustre_common_put_super, since l_d cleans up osc's as well. */
692 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next))
694 obd->obd_force = force;
698 client_common_put_super(sb);
700 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) !=NULL) {
701 class_manual_cleanup(obd);
705 class_del_profile(profilenm);
708 lsi->lsi_llsbi = NULL;
710 lustre_common_put_super(sb);
712 CDEBUG(D_WARNING, "client umount done\n");
714 } /* client_put_super */
716 #ifdef HAVE_REGISTER_CACHE
717 #include <linux/cache_def.h>
718 #ifdef HAVE_CACHE_RETURN_INT
723 ll_shrink_cache(int priority, unsigned int gfp_mask)
725 struct ll_sb_info *sbi;
728 list_for_each_entry(sbi, &ll_super_blocks, ll_list)
729 count += llap_shrink_cache(sbi, priority);
731 #ifdef HAVE_CACHE_RETURN_INT
736 struct cache_definition ll_cache_definition = {
737 .name = "llap_cache",
738 .shrink = ll_shrink_cache
740 #endif /* HAVE_REGISTER_CACHE */
742 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
744 struct inode *inode = NULL;
745 l_lock(&lock->l_resource->lr_namespace->ns_lock);
746 if (lock->l_ast_data) {
747 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
748 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
749 inode = igrab(lock->l_ast_data);
751 inode = lock->l_ast_data;
752 __LDLM_DEBUG(inode->i_state & I_FREEING ?
753 D_INFO : D_WARNING, lock,
754 "l_ast_data %p is bogus: magic %08x",
755 lock->l_ast_data, lli->lli_inode_magic);
759 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
763 static int null_if_equal(struct ldlm_lock *lock, void *data)
765 if (data == lock->l_ast_data) {
766 lock->l_ast_data = NULL;
768 if (lock->l_req_mode != lock->l_granted_mode)
769 LDLM_ERROR(lock,"clearing inode with ungranted lock");
772 return LDLM_ITER_CONTINUE;
775 void ll_clear_inode(struct inode *inode)
778 struct ll_inode_info *lli = ll_i2info(inode);
779 struct ll_sb_info *sbi = ll_i2sbi(inode);
782 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
783 inode->i_generation, inode);
785 ll_inode2fid(&fid, inode);
786 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(ll_i2info(inode)->lli_flags));
787 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
790 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
791 null_if_equal, inode);
793 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
797 if (lli->lli_symlink_name) {
798 OBD_FREE(lli->lli_symlink_name,
799 strlen(lli->lli_symlink_name) + 1);
800 lli->lli_symlink_name = NULL;
803 #ifdef CONFIG_FS_POSIX_ACL
804 if (lli->lli_posix_acl) {
805 LASSERT(atomic_read(&lli->lli_posix_acl->a_refcount) == 1);
806 posix_acl_release(lli->lli_posix_acl);
807 lli->lli_posix_acl = NULL;
811 lli->lli_inode_magic = LLI_INODE_DEAD;
813 spin_lock(&sbi->ll_deathrow_lock);
814 list_del_init(&lli->lli_dead_list);
815 spin_unlock(&sbi->ll_deathrow_lock);
820 /* If this inode has objects allocated to it (lsm != NULL), then the OST
821 * object(s) determine the file size and mtime. Otherwise, the MDS will
822 * keep these values until such a time that objects are allocated for it.
823 * We do the MDS operations first, as it is checking permissions for us.
824 * We don't to the MDS RPC if there is nothing that we want to store there,
825 * otherwise there is no harm in updating mtime/atime on the MDS if we are
826 * going to do an RPC anyways.
828 * If we are doing a truncate, we will send the mtime and ctime updates
829 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
830 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
833 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
835 struct ll_inode_info *lli = ll_i2info(inode);
836 struct lov_stripe_md *lsm = lli->lli_smd;
837 struct ll_sb_info *sbi = ll_i2sbi(inode);
838 struct ptlrpc_request *request = NULL;
839 struct mdc_op_data op_data;
840 int ia_valid = attr->ia_valid;
844 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu valid %x\n", inode->i_ino,
846 lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_SETATTR);
848 if (ia_valid & ATTR_SIZE) {
849 if (attr->ia_size > ll_file_maxbytes(inode)) {
850 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
851 attr->ia_size, ll_file_maxbytes(inode));
855 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
858 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
859 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
860 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
864 /* We mark all of the fields "set" so MDS/OST does not re-set them */
865 if (attr->ia_valid & ATTR_CTIME) {
866 attr->ia_ctime = CURRENT_TIME;
867 attr->ia_valid |= ATTR_CTIME_SET;
869 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
870 attr->ia_atime = CURRENT_TIME;
871 attr->ia_valid |= ATTR_ATIME_SET;
873 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
874 attr->ia_mtime = CURRENT_TIME;
875 attr->ia_valid |= ATTR_MTIME_SET;
878 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
879 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
880 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
884 /* NB: ATTR_SIZE will only be set after this point if the size
885 * resides on the MDS, ie, this file has no objects. */
887 attr->ia_valid &= ~ATTR_SIZE;
889 /* If only OST attributes being set on objects, don't do MDS RPC.
890 * In that case, we need to check permissions and update the local
891 * inode ourselves so we can call obdo_from_inode() always. */
892 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
894 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
896 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
897 attr, NULL, 0, NULL, 0, &request);
900 ptlrpc_req_finished(request);
901 if (rc != -EPERM && rc != -EACCES)
902 CERROR("mdc_setattr fails: rc = %d\n", rc);
906 rc = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
908 ptlrpc_req_finished(request);
912 /* We call inode_setattr to adjust timestamps.
913 * If there is at least some data in file, we cleared ATTR_SIZE
914 * above to avoid invoking vmtruncate, otherwise it is important
915 * to call vmtruncate in inode_setattr to update inode->i_size
917 rc = inode_setattr(inode, attr);
919 ll_update_inode(inode, &md);
920 ptlrpc_req_finished(request);
922 if (!lsm || !S_ISREG(inode->i_mode)) {
923 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
927 /* The OST doesn't check permissions, but the alternative is
928 * a gratuitous RPC to the MDS. We already rely on the client
929 * to do read/write/truncate permission checks, so is mtime OK?
931 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
932 /* from sys_utime() */
933 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
934 if (current->fsuid != inode->i_uid &&
935 (rc=ll_permission(inode,MAY_WRITE,NULL))!=0)
938 /* from inode_change_ok() */
939 if (current->fsuid != inode->i_uid &&
940 !capable(CAP_FOWNER))
945 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
946 rc = inode_setattr(inode, attr);
949 /* We really need to get our PW lock before we change inode->i_size.
950 * If we don't we can race with other i_size updaters on our node, like
951 * ll_file_read. We can also race with i_size propogation to other
952 * nodes through dirtying and writeback of final cached pages. This
953 * last one is especially bad for racing o_append users on other
955 if (ia_valid & ATTR_SIZE) {
956 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
958 struct lustre_handle lockh = { 0 };
959 int err, ast_flags = 0;
960 /* XXX when we fix the AST intents to pass the discard-range
961 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
963 if (attr->ia_size == 0)
964 ast_flags = LDLM_AST_DISCARD_DATA;
967 UP_WRITE_I_ALLOC_SEM(inode);
968 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy, &lockh,
970 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
971 DOWN_WRITE_I_ALLOC_SEM(inode);
975 DOWN_WRITE_I_ALLOC_SEM(inode);
980 /* Only ll_inode_size_lock is taken at this level.
981 * lov_stripe_lock() is grabbed by ll_truncate() only over
982 * call to obd_adjust_kms(). If vmtruncate returns 0, then
983 * ll_truncate dropped ll_inode_size_lock() */
984 ll_inode_size_lock(inode, 0);
985 rc = vmtruncate(inode, attr->ia_size);
987 LASSERT(atomic_read(&lli->lli_size_sem.count) <= 0);
988 ll_inode_size_unlock(inode, 0);
991 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
993 CERROR("ll_extent_unlock failed: %d\n", err);
997 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
1001 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1002 inode->i_ino, LTIME_S(attr->ia_mtime));
1004 oa.o_id = lsm->lsm_object_id;
1005 oa.o_valid = OBD_MD_FLID;
1007 flags = OBD_MD_FLTYPE | OBD_MD_FLATIME |
1008 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1009 OBD_MD_FLFID | OBD_MD_FLGENER;
1011 obdo_from_inode(&oa, inode, flags);
1012 rc = obd_setattr(sbi->ll_osc_exp, &oa, lsm, NULL);
1014 CERROR("obd_setattr fails: rc=%d\n", rc);
1019 int ll_setattr(struct dentry *de, struct iattr *attr)
1021 LBUG(); /* code is unused, but leave this in case of VFS changes */
1025 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1026 unsigned long max_age)
1028 struct ll_sb_info *sbi = ll_s2sbi(sb);
1029 struct obd_statfs obd_osfs;
1033 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1035 CERROR("mdc_statfs fails: rc = %d\n", rc);
1039 osfs->os_type = sb->s_magic;
1041 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1042 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1044 rc = obd_statfs(class_exp2obd(sbi->ll_osc_exp), &obd_osfs, max_age);
1046 CERROR("obd_statfs fails: rc = %d\n", rc);
1050 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1051 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1054 osfs->os_blocks = obd_osfs.os_blocks;
1055 osfs->os_bfree = obd_osfs.os_bfree;
1056 osfs->os_bavail = obd_osfs.os_bavail;
1058 /* If we don't have as many objects free on the OST as inodes
1059 * on the MDS, we reduce the total number of inodes to
1060 * compensate, so that the "inodes in use" number is correct.
1062 if (obd_osfs.os_ffree < osfs->os_ffree) {
1063 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1065 osfs->os_ffree = obd_osfs.os_ffree;
1071 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1073 struct obd_statfs osfs;
1076 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1077 lprocfs_counter_incr(ll_s2sbi(sb)->ll_stats, LPROC_LL_STAFS);
1079 /* For now we will always get up-to-date statfs values, but in the
1080 * future we may allow some amount of caching on the client (e.g.
1081 * from QOS or lprocfs updates). */
1082 rc = ll_statfs_internal(sb, &osfs, jiffies - 1);
1086 statfs_unpack(sfs, &osfs);
1088 if (sizeof(sfs->f_blocks) == 4) {
1089 while (osfs.os_blocks > ~0UL) {
1092 osfs.os_blocks >>= 1;
1093 osfs.os_bfree >>= 1;
1094 osfs.os_bavail >>= 1;
1098 sfs->f_blocks = osfs.os_blocks;
1099 sfs->f_bfree = osfs.os_bfree;
1100 sfs->f_bavail = osfs.os_bavail;
1105 void ll_inode_size_lock(struct inode *inode, int lock_lsm)
1107 struct ll_inode_info *lli;
1108 struct lov_stripe_md *lsm;
1110 lli = ll_i2info(inode);
1111 LASSERT(lli->lli_size_sem_owner != current);
1112 down(&lli->lli_size_sem);
1113 LASSERT(lli->lli_size_sem_owner == NULL);
1114 lli->lli_size_sem_owner = current;
1116 LASSERTF(lsm != NULL || lock_lsm == 0, "lsm %p, lock_lsm %d\n",
1119 lov_stripe_lock(lsm);
1122 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm)
1124 struct ll_inode_info *lli;
1125 struct lov_stripe_md *lsm;
1127 lli = ll_i2info(inode);
1129 LASSERTF(lsm != NULL || unlock_lsm == 0, "lsm %p, lock_lsm %d\n",
1132 lov_stripe_unlock(lsm);
1133 LASSERT(lli->lli_size_sem_owner == current);
1134 lli->lli_size_sem_owner = NULL;
1135 up(&lli->lli_size_sem);
1138 static void ll_replace_lsm(struct inode *inode, struct lov_stripe_md *lsm)
1140 struct ll_inode_info *lli = ll_i2info(inode);
1142 dump_lsm(D_INODE, lsm);
1143 dump_lsm(D_INODE, lli->lli_smd);
1144 LASSERTF(lsm->lsm_magic == LOV_MAGIC_JOIN,
1145 "lsm must be joined lsm %p\n", lsm);
1146 obd_free_memmd(ll_i2obdexp(inode), &lli->lli_smd);
1147 CDEBUG(D_INODE, "replace lsm %p to lli_smd %p for inode %lu%u(%p)\n",
1148 lsm, lli->lli_smd, inode->i_ino, inode->i_generation, inode);
1150 lli->lli_maxbytes = lsm->lsm_maxbytes;
1151 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1152 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1155 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1157 struct ll_inode_info *lli = ll_i2info(inode);
1158 struct mdt_body *body = md->body;
1159 struct lov_stripe_md *lsm = md->lsm;
1161 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1163 if (lli->lli_smd == NULL) {
1164 if (lsm->lsm_magic != LOV_MAGIC &&
1165 lsm->lsm_magic != LOV_MAGIC_JOIN) {
1166 dump_lsm(D_ERROR, lsm);
1169 CDEBUG(D_INODE, "adding lsm %p to inode %lu/%u(%p)\n",
1170 lsm, inode->i_ino, inode->i_generation, inode);
1171 /* ll_inode_size_lock() requires it is only called
1172 * with lli_smd != NULL or lock_lsm == 0 or we can
1173 * race between lock/unlock. bug 9547 */
1175 lli->lli_maxbytes = lsm->lsm_maxbytes;
1176 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1177 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1179 if (lli->lli_smd->lsm_magic == lsm->lsm_magic &&
1180 lli->lli_smd->lsm_stripe_count ==
1181 lsm->lsm_stripe_count) {
1182 if (lov_stripe_md_cmp(lli->lli_smd, lsm)) {
1183 CERROR("lsm mismatch for inode %ld\n",
1185 CERROR("lli_smd:\n");
1186 dump_lsm(D_ERROR, lli->lli_smd);
1188 dump_lsm(D_ERROR, lsm);
1192 ll_replace_lsm(inode, lsm);
1194 /* bug 2844 - limit i_blksize for broken user-space apps */
1195 LASSERTF(lsm->lsm_xfersize != 0, "%lu\n", lsm->lsm_xfersize);
1196 inode->i_blksize = min(lsm->lsm_xfersize, LL_MAX_BLKSIZE);
1197 if (lli->lli_smd != lsm)
1198 obd_free_memmd(ll_i2obdexp(inode), &lsm);
1200 inode->i_blksize = max(inode->i_blksize,
1201 inode->i_sb->s_blocksize);
1204 #ifdef CONFIG_FS_POSIX_ACL
1205 LASSERT(!md->posix_acl || (body->valid & OBD_MD_FLACL));
1206 if (body->valid & OBD_MD_FLACL) {
1207 spin_lock(&lli->lli_lock);
1208 if (lli->lli_posix_acl)
1209 posix_acl_release(lli->lli_posix_acl);
1210 lli->lli_posix_acl = md->posix_acl;
1211 spin_unlock(&lli->lli_lock);
1215 if (body->valid & OBD_MD_FLID)
1216 inode->i_ino = body->ino;
1217 if (body->valid & OBD_MD_FLATIME &&
1218 body->atime > LTIME_S(inode->i_atime))
1219 LTIME_S(inode->i_atime) = body->atime;
1220 if (body->valid & OBD_MD_FLMTIME &&
1221 body->mtime > LTIME_S(inode->i_mtime)) {
1222 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to "LPU64"\n",
1223 inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
1224 LTIME_S(inode->i_mtime) = body->mtime;
1226 if (body->valid & OBD_MD_FLCTIME &&
1227 body->ctime > LTIME_S(inode->i_ctime))
1228 LTIME_S(inode->i_ctime) = body->ctime;
1229 if (body->valid & OBD_MD_FLMODE)
1230 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1231 if (body->valid & OBD_MD_FLTYPE)
1232 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1233 if (body->valid & OBD_MD_FLUID)
1234 inode->i_uid = body->uid;
1235 if (body->valid & OBD_MD_FLGID)
1236 inode->i_gid = body->gid;
1237 if (body->valid & OBD_MD_FLFLAGS)
1238 inode->i_flags = body->flags;
1239 if (body->valid & OBD_MD_FLNLINK)
1240 inode->i_nlink = body->nlink;
1241 if (body->valid & OBD_MD_FLGENER)
1242 inode->i_generation = body->generation;
1243 if (body->valid & OBD_MD_FLRDEV)
1244 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1245 inode->i_rdev = body->rdev;
1247 inode->i_rdev = old_decode_dev(body->rdev);
1249 if (body->valid & OBD_MD_FLSIZE)
1250 inode->i_size = body->size;
1251 if (body->valid & OBD_MD_FLBLOCKS)
1252 inode->i_blocks = body->blocks;
1254 if (body->valid & OBD_MD_FLSIZE)
1255 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1258 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
1259 static struct backing_dev_info ll_backing_dev_info = {
1260 .ra_pages = 0, /* No readahead */
1261 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
1262 .capabilities = 0, /* Does contribute to dirty memory */
1264 .memory_backed = 0, /* Does contribute to dirty memory */
1269 void ll_read_inode2(struct inode *inode, void *opaque)
1271 struct lustre_md *md = opaque;
1272 struct ll_inode_info *lli = ll_i2info(inode);
1275 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1276 inode->i_generation, inode);
1280 LASSERT(!lli->lli_smd);
1282 /* Core attributes from the MDS first. This is a new inode, and
1283 * the VFS doesn't zero times in the core inode so we have to do
1284 * it ourselves. They will be overwritten by either MDS or OST
1285 * attributes - we just need to make sure they aren't newer. */
1286 LTIME_S(inode->i_mtime) = 0;
1287 LTIME_S(inode->i_atime) = 0;
1288 LTIME_S(inode->i_ctime) = 0;
1290 ll_update_inode(inode, md);
1292 /* OIDEBUG(inode); */
1294 if (S_ISREG(inode->i_mode)) {
1295 struct ll_sb_info *sbi = ll_i2sbi(inode);
1296 inode->i_op = &ll_file_inode_operations;
1297 inode->i_fop = sbi->ll_fop;
1298 inode->i_mapping->a_ops = &ll_aops;
1300 } else if (S_ISDIR(inode->i_mode)) {
1301 inode->i_op = &ll_dir_inode_operations;
1302 inode->i_fop = &ll_dir_operations;
1303 inode->i_mapping->a_ops = &ll_dir_aops;
1305 } else if (S_ISLNK(inode->i_mode)) {
1306 inode->i_op = &ll_fast_symlink_inode_operations;
1309 inode->i_op = &ll_special_inode_operations;
1311 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1312 init_special_inode(inode, inode->i_mode,
1313 kdev_t_to_nr(inode->i_rdev));
1315 /* initializing backing dev info. */
1316 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
1318 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1320 lli->ll_save_ifop = inode->i_fop;
1322 if (S_ISCHR(inode->i_mode))
1323 inode->i_fop = &ll_special_chr_inode_fops;
1324 else if (S_ISBLK(inode->i_mode))
1325 inode->i_fop = &ll_special_blk_inode_fops;
1326 else if (S_ISFIFO(inode->i_mode))
1327 inode->i_fop = &ll_special_fifo_inode_fops;
1328 else if (S_ISSOCK(inode->i_mode))
1329 inode->i_fop = &ll_special_sock_inode_fops;
1334 int ll_iocontrol(struct inode *inode, struct file *file,
1335 unsigned int cmd, unsigned long arg)
1337 struct ll_sb_info *sbi = ll_i2sbi(inode);
1338 struct ptlrpc_request *req = NULL;
1343 case EXT3_IOC_GETFLAGS: {
1345 struct mdt_body *body;
1347 ll_inode2fid(&fid, inode);
1348 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, OBD_MD_FLFLAGS,0,&req);
1350 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1354 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
1356 if (body->flags & S_APPEND)
1357 flags |= EXT3_APPEND_FL;
1358 if (body->flags & S_IMMUTABLE)
1359 flags |= EXT3_IMMUTABLE_FL;
1360 if (body->flags & S_NOATIME)
1361 flags |= EXT3_NOATIME_FL;
1363 ptlrpc_req_finished (req);
1365 RETURN(put_user(flags, (int *)arg));
1367 case EXT3_IOC_SETFLAGS: {
1368 struct mdc_op_data op_data;
1371 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1373 if (get_user(flags, (int *)arg))
1380 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
1382 memset(&attr, 0x0, sizeof(attr));
1383 attr.ia_attr_flags = flags;
1384 attr.ia_valid |= ATTR_ATTR_FLAG;
1386 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
1387 &attr, NULL, 0, NULL, 0, &req);
1389 ptlrpc_req_finished(req);
1390 if (rc != -EPERM && rc != -EACCES)
1391 CERROR("mdc_setattr fails: rc = %d\n", rc);
1395 ptlrpc_req_finished(req);
1397 oa->o_id = lsm->lsm_object_id;
1398 oa->o_flags = flags;
1399 oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS;
1401 obdo_from_inode(oa, inode, OBD_MD_FLFID | OBD_MD_FLGENER);
1402 rc = obd_setattr(sbi->ll_osc_exp, oa, lsm, NULL);
1405 if (rc != -EPERM && rc != -EACCES)
1406 CERROR("mdc_setattr fails: rc = %d\n", rc);
1410 if (flags & EXT3_APPEND_FL)
1411 inode->i_flags |= S_APPEND;
1413 inode->i_flags &= ~S_APPEND;
1414 if (flags & EXT3_IMMUTABLE_FL)
1415 inode->i_flags |= S_IMMUTABLE;
1417 inode->i_flags &= ~S_IMMUTABLE;
1418 if (flags & EXT3_NOATIME_FL)
1419 inode->i_flags |= S_NOATIME;
1421 inode->i_flags &= ~S_NOATIME;
1432 /* umount -f client means force down, don't save state */
1433 void ll_umount_begin(struct super_block *sb)
1435 struct lustre_sb_info *lsi = s2lsi(sb);
1436 struct ll_sb_info *sbi = ll_s2sbi(sb);
1437 struct obd_device *obd;
1438 struct obd_ioctl_data ioc_data = { 0 };
1441 /* Tell the MGC we got umount -f */
1442 lsi->lsi_flags |= LSI_UMOUNT_FORCE;
1444 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
1445 sb->s_count, atomic_read(&sb->s_active));
1447 obd = class_exp2obd(sbi->ll_mdc_exp);
1449 CERROR("Invalid MDC connection handle "LPX64"\n",
1450 sbi->ll_mdc_exp->exp_handle.h_cookie);
1454 obd->obd_no_recov = 1;
1455 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_mdc_exp, sizeof ioc_data,
1458 obd = class_exp2obd(sbi->ll_osc_exp);
1460 CERROR("Invalid LOV connection handle "LPX64"\n",
1461 sbi->ll_osc_exp->exp_handle.h_cookie);
1465 obd->obd_no_recov = 1;
1466 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_osc_exp, sizeof ioc_data,
1469 /* Really, we'd like to wait until there are no requests outstanding,
1470 * and then continue. For now, we just invalidate the requests,
1471 * schedule, and hope.
1478 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
1480 struct ll_sb_info *sbi = ll_s2sbi(sb);
1484 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
1485 read_only = *flags & MS_RDONLY;
1486 err = obd_set_info(sbi->ll_mdc_exp, strlen("read-only"),
1487 "read-only", sizeof(read_only), &read_only);
1489 CERROR("Failed to change the read-only flag during "
1490 "remount: %d\n", err);
1495 sb->s_flags |= MS_RDONLY;
1497 sb->s_flags &= ~MS_RDONLY;
1502 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
1503 struct ptlrpc_request *req, int offset,
1504 struct super_block *sb)
1506 struct ll_sb_info *sbi = NULL;
1507 struct lustre_md md;
1511 LASSERT(*inode || sb);
1512 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
1513 prune_deathrow(sbi, 1);
1515 rc = mdc_req2lustre_md(req, offset, exp, &md);
1520 ll_update_inode(*inode, &md);
1524 LASSERT(sb != NULL);
1526 rc = ll_fid_alloc(sbi, &fid);
1528 CERROR("cannot allocate new fid, rc %d\n",
1530 mdc_free_lustre_md(exp, &md);
1534 *inode = ll_iget(sb, ll_fid2ino(sbi, &fid), &md);
1535 if (*inode == NULL || is_bad_inode(*inode)) {
1536 mdc_free_lustre_md(exp, &md);
1538 CERROR("new_inode -fatal: rc %d\n", rc);
1541 ll_i2info(*inode)->lli_fid = fid;
1544 rc = obd_checkmd(exp, ll_i2mdcexp(*inode),
1545 ll_i2info(*inode)->lli_smd);
1550 char *llap_origins[] = {
1551 [LLAP_ORIGIN_UNKNOWN] = "--",
1552 [LLAP_ORIGIN_READPAGE] = "rp",
1553 [LLAP_ORIGIN_READAHEAD] = "ra",
1554 [LLAP_ORIGIN_COMMIT_WRITE] = "cw",
1555 [LLAP_ORIGIN_WRITEPAGE] = "wp",
1558 struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
1559 struct list_head *list)
1561 struct ll_async_page *llap;
1562 struct list_head *pos;
1564 list_for_each(pos, list) {
1565 if (pos == &sbi->ll_pglist)
1567 llap = list_entry(pos, struct ll_async_page, llap_pglist_item);
1568 if (llap->llap_page == NULL)
1576 int ll_obd_statfs(struct inode *inode, void *arg)
1578 struct ll_sb_info *sbi = NULL;
1579 struct obd_device *client_obd = NULL, *lov_obd = NULL;
1580 struct lov_obd *lov = NULL;
1581 struct obd_import *client_imp = NULL;
1582 struct obd_statfs stat_buf = {0};
1584 struct obd_ioctl_data *data = NULL;
1588 if (!inode || !(sbi = ll_i2sbi(inode)))
1589 GOTO(out_statfs, rc = -EINVAL);
1591 rc = obd_ioctl_getdata(&buf, &len, arg);
1593 GOTO(out_statfs, rc);
1596 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
1597 !data->ioc_pbuf1 || !data->ioc_pbuf2)
1598 GOTO(out_statfs, rc = -EINVAL);
1600 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
1601 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
1603 if (type == LL_STATFS_MDC) {
1605 GOTO(out_statfs, rc = -ENODEV);
1606 client_obd = class_exp2obd(sbi->ll_mdc_exp);
1607 client_imp = class_exp2cliimp(sbi->ll_mdc_exp);
1608 } else if (type == LL_STATFS_LOV) {
1609 lov_obd = class_exp2obd(sbi->ll_osc_exp);
1610 lov = &lov_obd->u.lov;
1612 if (index >= lov->desc.ld_tgt_count)
1613 GOTO(out_statfs, rc = -ENODEV);
1615 client_obd = class_exp2obd(lov->tgts[index].ltd_exp);
1616 client_imp = class_exp2cliimp(lov->tgts[index].ltd_exp);
1617 if (!lov->tgts[index].active)
1618 GOTO(out_uuid, rc = -ENODATA);
1621 if (!client_obd || !client_imp)
1622 GOTO(out_statfs, rc = -EINVAL);
1624 rc = obd_statfs(client_obd, &stat_buf, jiffies - 1);
1626 GOTO(out_statfs, rc);
1628 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
1629 GOTO(out_statfs, rc = -EFAULT);
1632 if (copy_to_user(data->ioc_pbuf2, &client_imp->imp_target_uuid,
1638 obd_ioctl_freedata(buf, len);
1642 EXPORT_SYMBOL(ll_fill_super);
1643 EXPORT_SYMBOL(ll_put_super);
1644 EXPORT_SYMBOL(ll_remount_fs);
1645 EXPORT_SYMBOL(ll_umount_begin);