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 <lustre_lite.h>
32 #include <lustre_ha.h>
33 #include <lustre_dlm.h>
34 #include <lprocfs_status.h>
35 #include <lustre_disk.h>
36 #include <lustre_param.h>
37 #include "llite_internal.h"
39 kmem_cache_t *ll_file_data_slab;
41 LIST_HEAD(ll_super_blocks);
42 spinlock_t ll_sb_lock = SPIN_LOCK_UNLOCKED;
44 extern struct address_space_operations ll_aops;
45 extern struct address_space_operations ll_dir_aops;
48 #define log2(n) ffz(~(n))
52 static struct ll_sb_info *ll_init_sbi(void)
54 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 if (num_physpages >> (20 - CFS_PAGE_SHIFT) < 512)
67 sbi->ll_async_page_max = num_physpages / 2;
69 sbi->ll_async_page_max = (num_physpages / 4) * 3;
70 sbi->ll_ra_info.ra_max_pages = min(num_physpages / 8,
71 SBI_DEFAULT_READAHEAD_MAX);
72 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
73 SBI_DEFAULT_READAHEAD_WHOLE_MAX;
75 INIT_LIST_HEAD(&sbi->ll_conn_chain);
76 INIT_LIST_HEAD(&sbi->ll_orphan_dentry_list);
78 class_generate_random_uuid(uuid);
79 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
80 CDEBUG(D_HA, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
82 spin_lock(&ll_sb_lock);
83 list_add_tail(&sbi->ll_list, &ll_super_blocks);
84 spin_unlock(&ll_sb_lock);
86 INIT_LIST_HEAD(&sbi->ll_deathrow);
87 spin_lock_init(&sbi->ll_deathrow_lock);
88 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
89 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_r_hist.oh_lock);
90 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_w_hist.oh_lock);
96 void ll_free_sbi(struct super_block *sb)
98 struct ll_sb_info *sbi = ll_s2sbi(sb);
102 spin_lock(&ll_sb_lock);
103 list_del(&sbi->ll_list);
104 spin_unlock(&ll_sb_lock);
105 OBD_FREE(sbi, sizeof(*sbi));
110 static struct dentry_operations ll_d_root_ops = {
111 #ifdef LUSTRE_KERNEL_VERSION
112 .d_compare = ll_dcompare,
116 static int client_common_fill_super(struct super_block *sb,
117 char *mdc, char *osc)
119 struct inode *root = 0;
120 struct ll_sb_info *sbi = ll_s2sbi(sb);
121 struct obd_device *obd;
122 struct ll_fid rootfid;
123 struct obd_statfs osfs;
124 struct ptlrpc_request *request = NULL;
125 struct lustre_handle osc_conn = {0, };
126 struct lustre_handle mdc_conn = {0, };
128 struct obd_connect_data *data = NULL;
132 obd = class_name2obd(mdc);
134 CERROR("MDC %s: not setup or attached\n", mdc);
138 OBD_ALLOC(data, sizeof(*data));
142 if (proc_lustre_fs_root) {
143 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
146 CERROR("could not register mount in /proc/lustre");
149 /* indicate the features supported by this client */
150 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
152 OBD_CONNECT_ATTRFID | OBD_CONNECT_VERSION;
153 #ifdef CONFIG_FS_POSIX_ACL
154 data->ocd_connect_flags |= OBD_CONNECT_ACL;
156 data->ocd_ibits_known = MDS_INODELOCK_FULL;
157 data->ocd_version = LUSTRE_VERSION_CODE;
159 if (sb->s_flags & MS_RDONLY)
160 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
161 if (sbi->ll_flags & LL_SBI_USER_XATTR)
162 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
164 #ifdef HAVE_MS_FLOCK_LOCK
165 /* force vfs to use lustre handler for flock() calls - bug 10743 */
166 sb->s_flags |= MS_FLOCK_LOCK;
169 if (sbi->ll_flags & LL_SBI_FLOCK)
170 sbi->ll_fop = &ll_file_operations_flock;
172 sbi->ll_fop = &ll_file_operations;
174 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid, data);
176 LCONSOLE_ERROR("An MDT (mdc %s) is performing recovery, of "
177 "which this client is not a part. Please wait "
178 "for recovery to complete, abort, or "
182 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
185 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
187 err = obd_statfs(obd, &osfs, cfs_time_current_64() - HZ);
191 /* MDC connect is surely finished by now because we actually sent
192 * a statfs RPC, otherwise obd_connect() is asynchronous. */
193 *data = class_exp2cliimp(sbi->ll_mdc_exp)->imp_connect_data;
195 LASSERT(osfs.os_bsize);
196 sb->s_blocksize = osfs.os_bsize;
197 sb->s_blocksize_bits = log2(osfs.os_bsize);
198 sb->s_magic = LL_SUPER_MAGIC;
200 /* for bug 11559. in $LINUX/fs/read_write.c, function do_sendfile():
201 * retval = in_file->f_op->sendfile(...);
203 * retval = -EOVERFLOW;
205 * it will check if *ppos is greater than max. However, max equals to
206 * s_maxbytes, which is a negative integer in a x86_64 box since loff_t
207 * has been defined as a signed long long ineger in linux kernel. */
208 #if BITS_PER_LONG == 64
209 sb->s_maxbytes = PAGE_CACHE_MAXBYTES >> 1;
211 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
213 sbi->ll_namelen = osfs.os_namelen;
214 sbi->ll_max_rw_chunk = LL_DEFAULT_MAX_RW_CHUNK;
216 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
217 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
218 LCONSOLE_INFO("Disabling user_xattr feature because "
219 "it is not supported on the server\n");
220 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
223 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
225 sb->s_flags |= MS_POSIXACL;
227 sbi->ll_flags |= LL_SBI_ACL;
229 sbi->ll_flags &= ~LL_SBI_ACL;
231 if (data->ocd_connect_flags & OBD_CONNECT_JOIN)
232 sbi->ll_flags |= LL_SBI_JOIN;
234 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
235 /* We set sb->s_dev equal on all lustre clients in order to support
236 * NFS export clustering. NFSD requires that the FSID be the same
238 /* s_dev is also used in lt_compare() to compare two fs, but that is
239 * only a node-local comparison. */
240 sb->s_dev = get_uuid2int(sbi2mdc(sbi)->cl_target_uuid.uuid,
241 strlen(sbi2mdc(sbi)->cl_target_uuid.uuid));
244 obd = class_name2obd(osc);
246 CERROR("OSC %s: not setup or attached\n", osc);
247 GOTO(out_mdc, err = -ENODEV);
250 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
251 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE;
253 CDEBUG(D_RPCTRACE, "ocd_connect_flags: "LPX64" ocd_version: %d "
254 "ocd_grant: %d\n", data->ocd_connect_flags,
255 data->ocd_version, data->ocd_grant);
257 obd->obd_upcall.onu_owner = &sbi->ll_lco;
258 obd->obd_upcall.onu_upcall = ll_ocd_update;
259 data->ocd_brw_size = PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT;
262 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid, data);
264 LCONSOLE_ERROR("An OST (osc %s) is performing recovery, of "
265 "which this client is not a part. Please wait "
266 "for recovery to complete, abort, or "
270 CERROR("cannot connect to %s: rc = %d\n", osc, err);
273 sbi->ll_osc_exp = class_conn2export(&osc_conn);
274 spin_lock(&sbi->ll_lco.lco_lock);
275 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
276 spin_unlock(&sbi->ll_lco.lco_lock);
278 mdc_init_ea_size(sbi->ll_mdc_exp, sbi->ll_osc_exp);
280 err = obd_prep_async_page(sbi->ll_osc_exp, NULL, NULL, NULL,
281 0, NULL, NULL, NULL);
283 LCONSOLE_ERROR("There are no OST's in this filesystem. "
284 "There must be at least one active OST for "
285 "a client to start.\n");
289 if (!ll_async_page_slab) {
290 ll_async_page_slab_size =
291 size_round(sizeof(struct ll_async_page)) + err;
292 ll_async_page_slab = kmem_cache_create("ll_async_page",
293 ll_async_page_slab_size,
295 if (!ll_async_page_slab)
296 GOTO(out_osc, -ENOMEM);
299 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
301 CERROR("cannot mds_connect: rc = %d\n", err);
304 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
305 sbi->ll_rootino = rootfid.id;
307 sb->s_op = &lustre_super_operations;
308 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
309 sb->s_export_op = &lustre_export_operations;
313 * XXX: move this to after cbd setup? */
314 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
315 OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS |
316 (sbi->ll_flags & LL_SBI_ACL ? OBD_MD_FLACL : 0),
319 CERROR("mdc_getattr failed for root: rc = %d\n", err);
323 err = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md);
325 CERROR("failed to understand root inode md: rc = %d\n",err);
326 ptlrpc_req_finished (request);
330 LASSERT(sbi->ll_rootino != 0);
331 root = ll_iget(sb, sbi->ll_rootino, &md);
333 ptlrpc_req_finished(request);
335 if (root == NULL || is_bad_inode(root)) {
336 mdc_free_lustre_md(sbi->ll_osc_exp, &md);
337 CERROR("lustre_lite: bad iget4 for root\n");
338 GOTO(out_root, err = -EBADF);
341 err = ll_close_thread_start(&sbi->ll_lcq);
343 CERROR("cannot start close thread: rc %d\n", err);
347 /* making vm readahead 0 for 2.4.x. In the case of 2.6.x,
348 backing dev info assigned to inode mapping is used for
349 determining maximal readahead. */
350 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) && \
351 !defined(KERNEL_HAS_AS_MAX_READAHEAD)
352 /* bug 2805 - set VM readahead to zero */
353 vm_max_readahead = vm_min_readahead = 0;
356 sb->s_root = d_alloc_root(root);
358 OBD_FREE(data, sizeof(*data));
359 sb->s_root->d_op = &ll_d_root_ops;
366 obd_disconnect(sbi->ll_osc_exp);
367 sbi->ll_osc_exp = NULL;
369 obd_disconnect(sbi->ll_mdc_exp);
370 sbi->ll_mdc_exp = NULL;
373 OBD_FREE(data, sizeof(*data));
374 lprocfs_unregister_mountpoint(sbi);
378 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
382 *lmmsize = obd_size_diskmd(sbi->ll_osc_exp, NULL);
384 rc = obd_get_info(sbi->ll_mdc_exp, strlen("max_easize"), "max_easize",
387 CERROR("Get max mdsize error rc %d \n", rc);
392 void ll_dump_inode(struct inode *inode)
394 struct list_head *tmp;
395 int dentry_count = 0;
397 LASSERT(inode != NULL);
399 list_for_each(tmp, &inode->i_dentry)
402 CERROR("inode %p dump: dev=%s ino=%lu mode=%o count=%u, %d dentries\n",
403 inode, ll_i2mdcexp(inode)->exp_obd->obd_name, inode->i_ino,
404 inode->i_mode, atomic_read(&inode->i_count), dentry_count);
407 void lustre_dump_dentry(struct dentry *dentry, int recur)
409 struct list_head *tmp;
412 LASSERT(dentry != NULL);
414 list_for_each(tmp, &dentry->d_subdirs)
417 CERROR("dentry %p dump: name=%.*s parent=%.*s (%p), inode=%p, count=%u,"
418 " flags=0x%x, fsdata=%p, %d subdirs\n", dentry,
419 dentry->d_name.len, dentry->d_name.name,
420 dentry->d_parent->d_name.len, dentry->d_parent->d_name.name,
421 dentry->d_parent, dentry->d_inode, atomic_read(&dentry->d_count),
422 dentry->d_flags, dentry->d_fsdata, subdirs);
423 if (dentry->d_inode != NULL)
424 ll_dump_inode(dentry->d_inode);
429 list_for_each(tmp, &dentry->d_subdirs) {
430 struct dentry *d = list_entry(tmp, struct dentry, d_child);
431 lustre_dump_dentry(d, recur - 1);
435 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
436 void lustre_throw_orphan_dentries(struct super_block *sb)
438 struct dentry *dentry, *next;
439 struct ll_sb_info *sbi = ll_s2sbi(sb);
441 /* Do this to get rid of orphaned dentries. That is not really trw. */
442 list_for_each_entry_safe(dentry, next, &sbi->ll_orphan_dentry_list,
444 CWARN("found orphan dentry %.*s (%p->%p) at unmount, dumping "
445 "before and after shrink_dcache_parent\n",
446 dentry->d_name.len, dentry->d_name.name, dentry, next);
447 lustre_dump_dentry(dentry, 1);
448 shrink_dcache_parent(dentry);
449 lustre_dump_dentry(dentry, 1);
453 #define lustre_throw_orphan_dentries(sb)
456 static void prune_dir_dentries(struct inode *inode)
458 struct dentry *dentry, *prev = NULL;
460 /* due to lustre specific logic, a directory
461 * can have few dentries - a bug from VFS POV */
463 spin_lock(&dcache_lock);
464 if (!list_empty(&inode->i_dentry)) {
465 dentry = list_entry(inode->i_dentry.prev,
466 struct dentry, d_alias);
467 /* in order to prevent infinite loops we
468 * break if previous dentry is busy */
469 if (dentry != prev) {
472 spin_unlock(&dcache_lock);
474 /* try to kill all child dentries */
476 shrink_dcache_parent(dentry);
477 unlock_dentry(dentry);
480 /* now try to get rid of current dentry */
481 d_prune_aliases(inode);
485 spin_unlock(&dcache_lock);
488 static void prune_deathrow_one(struct ll_inode_info *lli)
490 struct inode *inode = ll_info2i(lli);
492 /* first, try to drop any dentries - they hold a ref on the inode */
493 if (S_ISDIR(inode->i_mode))
494 prune_dir_dentries(inode);
496 d_prune_aliases(inode);
499 /* if somebody still uses it, leave it */
500 LASSERT(atomic_read(&inode->i_count) > 0);
501 if (atomic_read(&inode->i_count) > 1)
504 CDEBUG(D_INODE, "inode %lu/%u(%d) looks a good candidate for prune\n",
505 inode->i_ino,inode->i_generation, atomic_read(&inode->i_count));
507 /* seems nobody uses it anymore */
515 static void prune_deathrow(struct ll_sb_info *sbi, int try)
517 struct ll_inode_info *lli;
521 if (need_resched() && try)
525 if (!spin_trylock(&sbi->ll_deathrow_lock))
528 spin_lock(&sbi->ll_deathrow_lock);
533 if (!list_empty(&sbi->ll_deathrow)) {
534 lli = list_entry(sbi->ll_deathrow.next,
535 struct ll_inode_info,
537 list_del_init(&lli->lli_dead_list);
538 if (!list_empty(&sbi->ll_deathrow))
541 spin_unlock(&sbi->ll_deathrow_lock);
544 prune_deathrow_one(lli);
546 } while (empty == 0);
549 void client_common_put_super(struct super_block *sb)
551 struct ll_sb_info *sbi = ll_s2sbi(sb);
554 ll_close_thread_shutdown(sbi->ll_lcq);
556 lprocfs_unregister_mountpoint(sbi);
558 /* destroy inodes in deathrow */
559 prune_deathrow(sbi, 0);
561 list_del(&sbi->ll_conn_chain);
562 obd_disconnect(sbi->ll_osc_exp);
563 sbi->ll_osc_exp = NULL;
565 obd_disconnect(sbi->ll_mdc_exp);
566 sbi->ll_mdc_exp = NULL;
568 lustre_throw_orphan_dentries(sb);
572 char *ll_read_opt(const char *opt, char *data)
578 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
579 if (strncmp(opt, data, strlen(opt)))
581 if ((value = strchr(data, '=')) == NULL)
585 OBD_ALLOC(retval, strlen(value) + 1);
587 CERROR("out of memory!\n");
591 memcpy(retval, value, strlen(value)+1);
592 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
596 static inline int ll_set_opt(const char *opt, char *data, int fl)
598 if (strncmp(opt, data, strlen(opt)) != 0)
604 /* non-client-specific mount options are parsed in lmd_parse */
605 static int ll_options(char *options, int *flags)
608 char *s1 = options, *s2;
614 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
617 CDEBUG(D_SUPER, "next opt=%s\n", s1);
618 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
623 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
628 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK);
633 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
638 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
643 tmp = ll_set_opt("acl", s1, LL_SBI_ACL);
645 /* Ignore deprecated mount option. The client will
646 * always try to mount with ACL support, whether this
647 * is used depends on whether server supports it. */
650 tmp = ll_set_opt("noacl", s1, LL_SBI_ACL);
655 LCONSOLE_ERROR("Unknown option '%s', won't mount.\n", s1);
660 s2 = strchr(s1, ',');
668 void ll_lli_init(struct ll_inode_info *lli)
670 sema_init(&lli->lli_open_sem, 1);
671 sema_init(&lli->lli_size_sem, 1);
672 sema_init(&lli->lli_write_sem, 1);
674 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
675 spin_lock_init(&lli->lli_lock);
676 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
677 lli->lli_inode_magic = LLI_INODE_MAGIC;
678 sema_init(&lli->lli_och_sem, 1);
679 lli->lli_mds_read_och = lli->lli_mds_write_och = NULL;
680 lli->lli_mds_exec_och = NULL;
681 lli->lli_open_fd_read_count = lli->lli_open_fd_write_count = 0;
682 lli->lli_open_fd_exec_count = 0;
683 INIT_LIST_HEAD(&lli->lli_dead_list);
687 #define MDCDEV "mdc_dev"
688 static int old_lustre_process_log(struct super_block *sb, char *newprofile,
689 struct config_llog_instance *cfg)
691 struct lustre_sb_info *lsi = s2lsi(sb);
692 struct obd_device *obd;
693 struct lustre_handle mdc_conn = {0, };
694 struct obd_export *exp;
695 char *ptr, *mdt, *profile;
696 char niduuid[10] = "mdtnid0";
698 struct obd_uuid mdc_uuid;
699 struct llog_ctxt *ctxt;
700 struct obd_connect_data ocd = { 0 };
702 int i, rc = 0, recov_bk = 1, failnodes = 0;
705 class_generate_random_uuid(uuid);
706 class_uuid_unparse(uuid, &mdc_uuid);
707 CDEBUG(D_HA, "generated uuid: %s\n", mdc_uuid.uuid);
709 /* Figure out the old mdt and profile name from new-style profile
710 ("lustre" from "mds/lustre-client") */
712 profile = strchr(mdt, '/');
713 if (profile == NULL) {
714 CDEBUG(D_CONFIG, "Can't find MDT name in %s\n", newprofile);
715 GOTO(out, rc = -EINVAL);
719 ptr = strrchr(profile, '-');
721 CDEBUG(D_CONFIG, "Can't find client name in %s\n", newprofile);
722 GOTO(out, rc = -EINVAL);
726 LCONSOLE_WARN("This looks like an old mount command; I will try to "
727 "contact MDT '%s' for profile '%s'\n", mdt, profile);
729 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
731 ptr = lsi->lsi_lmd->lmd_dev;
732 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
733 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid, 0,0,0);
735 /* Stop at the first failover nid */
740 CERROR("No valid MDT nids found.\n");
741 GOTO(out, rc = -EINVAL);
745 rc = do_lcfg(MDCDEV, 0, LCFG_ATTACH, LUSTRE_MDC_NAME,mdc_uuid.uuid,0,0);
747 GOTO(out_del_uuid, rc);
749 rc = do_lcfg(MDCDEV, 0, LCFG_SETUP, mdt, niduuid, 0, 0);
751 LCONSOLE_ERROR("I couldn't establish a connection with the MDT."
752 " Check that the MDT host NID is correct and the"
753 " networks are up.\n");
754 GOTO(out_detach, rc);
757 obd = class_name2obd(MDCDEV);
759 GOTO(out_cleanup, rc = -EINVAL);
761 /* Add any failover nids */
762 while (*ptr == ':') {
763 /* New failover node */
764 sprintf(niduuid, "mdtnid%d", failnodes);
766 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
768 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid,0,0,0);
770 CERROR("Add uuid for %s failed %d\n",
771 libcfs_nid2str(nid), rc);
776 rc = do_lcfg(MDCDEV, 0, LCFG_ADD_CONN, niduuid, 0, 0,0);
778 CERROR("Add conn for %s failed %d\n",
779 libcfs_nid2str(nid), rc);
787 /* Try all connections, but only once. */
788 rc = obd_set_info_async(obd->obd_self_export,
789 strlen("init_recov_bk"), "init_recov_bk",
790 sizeof(recov_bk), &recov_bk, NULL);
792 GOTO(out_cleanup, rc);
794 /* If we don't have this then an ACL MDS will refuse the connection */
795 ocd.ocd_connect_flags = OBD_CONNECT_ACL;
797 rc = obd_connect(&mdc_conn, obd, &mdc_uuid, &ocd);
799 CERROR("cannot connect to %s: rc = %d\n", mdt, rc);
800 GOTO(out_cleanup, rc);
803 exp = class_conn2export(&mdc_conn);
805 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
807 cfg->cfg_flags |= CFG_F_COMPAT146;
810 rc = class_config_parse_llog(ctxt, profile, cfg);
813 * For debugging, it's useful to just dump the log
815 rc = class_config_dump_llog(ctxt, profile, cfg);
819 /* Set the caller's profile name to the old-style */
820 memcpy(newprofile, profile, strlen(profile) + 1);
824 LCONSOLE_ERROR("%s: The configuration '%s' could not be read "
825 "from the MDT '%s'. Make sure this client and "
826 "the MDT are running compatible versions of "
828 obd->obd_name, profile, mdt);
831 LCONSOLE_ERROR("%s: The configuration '%s' could not be read "
832 "from the MDT '%s'. This may be the result of "
833 "communication errors between the client and "
834 "the MDT, or if the MDT is not running.\n",
835 obd->obd_name, profile, mdt);
839 /* We don't so much care about errors in cleaning up the config llog
840 * connection, as we have already read the config by this point. */
844 do_lcfg(MDCDEV, 0, LCFG_CLEANUP, 0, 0, 0, 0);
847 do_lcfg(MDCDEV, 0, LCFG_DETACH, 0, 0, 0, 0);
850 /* class_add_uuid adds a nid even if the same uuid exists; we might
851 delete any copy here. So they all better match. */
852 for (i = 0; i < failnodes; i++) {
853 sprintf(niduuid, "mdtnid%d", i);
854 do_lcfg(MDCDEV, 0, LCFG_DEL_UUID, niduuid, 0, 0, 0);
856 /* class_import_put will get rid of the additional connections */
862 int ll_fill_super(struct super_block *sb)
864 struct lustre_profile *lprof;
865 struct lustre_sb_info *lsi = s2lsi(sb);
866 struct ll_sb_info *sbi;
867 char *osc = NULL, *mdc = NULL;
868 char *profilenm = get_profile_name(sb);
869 struct config_llog_instance cfg;
870 char ll_instance[sizeof(sb) * 2 + 1];
874 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
878 /* client additional sb info */
879 lsi->lsi_llsbi = sbi = ll_init_sbi();
885 err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
889 /* Generate a string unique to this super, in case some joker tries
890 to mount the same fs at two mount points.
891 Use the address of the super itself.*/
892 sprintf(ll_instance, "%p", sb);
893 cfg.cfg_instance = ll_instance;
894 cfg.cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
895 cfg.cfg_last_idx = 0;
897 /* set up client obds */
898 err = lustre_process_log(sb, profilenm, &cfg);
903 oldnamelen = strlen(profilenm) + 1;
904 /* Temp storage for 1.4.6 profile name */
905 OBD_ALLOC(oldname, oldnamelen);
907 memcpy(oldname, profilenm, oldnamelen);
908 rc = old_lustre_process_log(sb, oldname, &cfg);
910 /* That worked - update the profile name
913 OBD_FREE(lsi->lsi_lmd->lmd_profile,
914 strlen(lsi->lsi_lmd->lmd_profile) + 1);
915 OBD_ALLOC(lsi->lsi_lmd->lmd_profile,
916 strlen(oldname) + 1);
917 if (!lsi->lsi_lmd->lmd_profile) {
918 OBD_FREE(oldname, oldnamelen);
919 GOTO(out_free, err = -ENOMEM);
921 memcpy(lsi->lsi_lmd->lmd_profile, oldname,
922 strlen(oldname) + 1);
923 profilenm = get_profile_name(sb);
924 cfg.cfg_flags |= CFG_F_SERVER146;
926 OBD_FREE(oldname, oldnamelen);
931 CERROR("Unable to process log: %d\n", err);
935 lprof = class_get_profile(profilenm);
937 LCONSOLE_ERROR("The client profile '%s' could not be read "
938 "from the MGS. Does that filesystem exist?\n",
940 GOTO(out_free, err = -EINVAL);
942 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
943 lprof->lp_mdc, lprof->lp_osc);
945 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
946 strlen(ll_instance) + 2);
948 GOTO(out_free, err = -ENOMEM);
949 sprintf(osc, "%s-%s", lprof->lp_osc, ll_instance);
951 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
952 strlen(ll_instance) + 2);
954 GOTO(out_free, err = -ENOMEM);
955 sprintf(mdc, "%s-%s", lprof->lp_mdc, ll_instance);
957 /* connections, registrations, sb setup */
958 err = client_common_fill_super(sb, mdc, osc);
962 OBD_FREE(mdc, strlen(mdc) + 1);
964 OBD_FREE(osc, strlen(osc) + 1);
968 LCONSOLE_WARN("Client %s has started\n", profilenm);
971 } /* ll_fill_super */
974 void ll_put_super(struct super_block *sb)
976 struct config_llog_instance cfg;
977 char ll_instance[sizeof(sb) * 2 + 1];
978 struct obd_device *obd;
979 struct lustre_sb_info *lsi = s2lsi(sb);
980 struct ll_sb_info *sbi = ll_s2sbi(sb);
981 char *profilenm = get_profile_name(sb);
985 CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
987 sprintf(ll_instance, "%p", sb);
988 cfg.cfg_instance = ll_instance;
989 lustre_end_log(sb, NULL, &cfg);
991 if (sbi->ll_mdc_exp) {
992 obd = class_exp2obd(sbi->ll_mdc_exp);
994 force = obd->obd_no_recov;
997 /* We need to set force before the lov_disconnect in
998 lustre_common_put_super, since l_d cleans up osc's as well. */
1001 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1003 obd->obd_force = force;
1008 /* Only if client_common_fill_super succeeded */
1009 client_common_put_super(sb);
1013 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) !=NULL) {
1014 class_manual_cleanup(obd);
1018 class_del_profile(profilenm);
1021 lsi->lsi_llsbi = NULL;
1023 lustre_common_put_super(sb);
1025 LCONSOLE_WARN("client %s umount complete\n", ll_instance);
1030 } /* client_put_super */
1032 #ifdef HAVE_REGISTER_CACHE
1033 #include <linux/cache_def.h>
1034 #ifdef HAVE_CACHE_RETURN_INT
1039 ll_shrink_cache(int priority, unsigned int gfp_mask)
1041 struct ll_sb_info *sbi;
1044 list_for_each_entry(sbi, &ll_super_blocks, ll_list)
1045 count += llap_shrink_cache(sbi, priority);
1047 #ifdef HAVE_CACHE_RETURN_INT
1052 struct cache_definition ll_cache_definition = {
1053 .name = "llap_cache",
1054 .shrink = ll_shrink_cache
1056 #endif /* HAVE_REGISTER_CACHE */
1058 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
1060 struct inode *inode = NULL;
1061 /* NOTE: we depend on atomic igrab() -bzzz */
1062 lock_res_and_lock(lock);
1063 if (lock->l_ast_data) {
1064 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
1065 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1066 inode = igrab(lock->l_ast_data);
1068 inode = lock->l_ast_data;
1069 ldlm_lock_debug(NULL, inode->i_state & I_FREEING ?
1071 lock, __FILE__, __func__, __LINE__,
1072 "l_ast_data %p is bogus: magic %08x",
1073 lock->l_ast_data, lli->lli_inode_magic);
1077 unlock_res_and_lock(lock);
1081 static int null_if_equal(struct ldlm_lock *lock, void *data)
1083 if (data == lock->l_ast_data) {
1084 lock->l_ast_data = NULL;
1086 if (lock->l_req_mode != lock->l_granted_mode)
1087 LDLM_ERROR(lock,"clearing inode with ungranted lock");
1090 return LDLM_ITER_CONTINUE;
1093 void ll_clear_inode(struct inode *inode)
1096 struct ll_inode_info *lli = ll_i2info(inode);
1097 struct ll_sb_info *sbi = ll_i2sbi(inode);
1100 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1101 inode->i_generation, inode);
1103 ll_inode2fid(&fid, inode);
1104 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1105 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
1107 LASSERT(!lli->lli_open_fd_write_count);
1108 LASSERT(!lli->lli_open_fd_read_count);
1109 LASSERT(!lli->lli_open_fd_exec_count);
1111 if (lli->lli_mds_write_och)
1112 ll_mdc_real_close(inode, FMODE_WRITE);
1113 if (lli->lli_mds_exec_och) {
1115 CERROR("No FMODE exec, bug exec och is present for "
1116 "inode %ld\n", inode->i_ino);
1117 ll_mdc_real_close(inode, FMODE_EXEC);
1119 if (lli->lli_mds_read_och)
1120 ll_mdc_real_close(inode, FMODE_READ);
1124 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
1125 null_if_equal, inode);
1127 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
1128 lli->lli_smd = NULL;
1131 if (lli->lli_symlink_name) {
1132 OBD_FREE(lli->lli_symlink_name,
1133 strlen(lli->lli_symlink_name) + 1);
1134 lli->lli_symlink_name = NULL;
1137 #ifdef CONFIG_FS_POSIX_ACL
1138 if (lli->lli_posix_acl) {
1139 LASSERT(atomic_read(&lli->lli_posix_acl->a_refcount) == 1);
1140 posix_acl_release(lli->lli_posix_acl);
1141 lli->lli_posix_acl = NULL;
1145 lli->lli_inode_magic = LLI_INODE_DEAD;
1147 spin_lock(&sbi->ll_deathrow_lock);
1148 list_del_init(&lli->lli_dead_list);
1149 spin_unlock(&sbi->ll_deathrow_lock);
1154 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1155 * object(s) determine the file size and mtime. Otherwise, the MDS will
1156 * keep these values until such a time that objects are allocated for it.
1157 * We do the MDS operations first, as it is checking permissions for us.
1158 * We don't to the MDS RPC if there is nothing that we want to store there,
1159 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1160 * going to do an RPC anyways.
1162 * If we are doing a truncate, we will send the mtime and ctime updates
1163 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1164 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1167 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
1169 struct ll_inode_info *lli = ll_i2info(inode);
1170 struct lov_stripe_md *lsm = lli->lli_smd;
1171 struct ll_sb_info *sbi = ll_i2sbi(inode);
1172 struct ptlrpc_request *request = NULL;
1173 struct mdc_op_data op_data;
1174 struct lustre_md md;
1175 int ia_valid = attr->ia_valid;
1179 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu valid %x\n", inode->i_ino,
1181 lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_SETATTR);
1183 if (ia_valid & ATTR_SIZE) {
1184 if (attr->ia_size > ll_file_maxbytes(inode)) {
1185 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
1186 attr->ia_size, ll_file_maxbytes(inode));
1190 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1193 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1194 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
1195 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1199 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1200 if (attr->ia_valid & ATTR_CTIME) {
1201 attr->ia_ctime = CURRENT_TIME;
1202 attr->ia_valid |= ATTR_CTIME_SET;
1204 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
1205 attr->ia_atime = CURRENT_TIME;
1206 attr->ia_valid |= ATTR_ATIME_SET;
1208 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
1209 attr->ia_mtime = CURRENT_TIME;
1210 attr->ia_valid |= ATTR_MTIME_SET;
1212 if ((attr->ia_valid & ATTR_CTIME) && !(attr->ia_valid & ATTR_MTIME)) {
1213 /* To avoid stale mtime on mds, obtain it from ost and send
1215 rc = ll_glimpse_size(inode, 0);
1219 attr->ia_valid |= ATTR_MTIME_SET | ATTR_MTIME;
1220 attr->ia_mtime = inode->i_mtime;
1223 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1224 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
1225 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1228 /* NB: ATTR_SIZE will only be set after this point if the size
1229 * resides on the MDS, ie, this file has no objects. */
1231 attr->ia_valid &= ~ATTR_SIZE;
1233 /* We always do an MDS RPC, even if we're only changing the size;
1234 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
1235 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
1237 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
1238 attr, NULL, 0, NULL, 0, &request);
1241 ptlrpc_req_finished(request);
1242 if (rc == -ENOENT) {
1244 /* Unlinked special device node? Or just a race?
1245 * Pretend we done everything. */
1246 if (!S_ISREG(inode->i_mode) &&
1247 !S_ISDIR(inode->i_mode))
1248 rc = inode_setattr(inode, attr);
1249 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY)
1250 CERROR("mdc_setattr fails: rc = %d\n", rc);
1254 rc = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md);
1256 ptlrpc_req_finished(request);
1260 /* We call inode_setattr to adjust timestamps.
1261 * If there is at least some data in file, we cleared ATTR_SIZE above to
1262 * avoid invoking vmtruncate, otherwise it is important to call
1263 * vmtruncate in inode_setattr to update inode->i_size (bug 6196) */
1264 rc = inode_setattr(inode, attr);
1266 ll_update_inode(inode, &md);
1267 ptlrpc_req_finished(request);
1269 if (!lsm || !S_ISREG(inode->i_mode)) {
1270 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
1274 /* We really need to get our PW lock before we change inode->i_size.
1275 * If we don't we can race with other i_size updaters on our node, like
1276 * ll_file_read. We can also race with i_size propogation to other
1277 * nodes through dirtying and writeback of final cached pages. This
1278 * last one is especially bad for racing o_append users on other
1280 if (ia_valid & ATTR_SIZE) {
1281 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
1283 struct lustre_handle lockh = { 0 };
1284 int err, ast_flags = 0;
1285 /* XXX when we fix the AST intents to pass the discard-range
1286 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
1288 if (attr->ia_size == 0)
1289 ast_flags = LDLM_AST_DISCARD_DATA;
1291 UNLOCK_INODE_MUTEX(inode);
1292 UP_WRITE_I_ALLOC_SEM(inode);
1293 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy, &lockh,
1295 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1296 DOWN_WRITE_I_ALLOC_SEM(inode);
1297 LOCK_INODE_MUTEX(inode);
1299 LOCK_INODE_MUTEX(inode);
1300 DOWN_WRITE_I_ALLOC_SEM(inode);
1305 /* Only ll_inode_size_lock is taken at this level.
1306 * lov_stripe_lock() is grabbed by ll_truncate() only over
1307 * call to obd_adjust_kms(). If vmtruncate returns 0, then
1308 * ll_truncate dropped ll_inode_size_lock() */
1309 ll_inode_size_lock(inode, 0);
1310 rc = vmtruncate(inode, attr->ia_size);
1312 LASSERT(atomic_read(&lli->lli_size_sem.count) <= 0);
1313 ll_inode_size_unlock(inode, 0);
1316 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
1318 CERROR("ll_extent_unlock failed: %d\n", err);
1322 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
1324 struct obd_info oinfo = { { { 0 } } };
1325 struct obdo *oa = obdo_alloc();
1327 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1328 inode->i_ino, LTIME_S(attr->ia_mtime));
1331 oa->o_id = lsm->lsm_object_id;
1332 oa->o_valid = OBD_MD_FLID;
1334 flags = OBD_MD_FLTYPE | OBD_MD_FLATIME |
1335 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1336 OBD_MD_FLFID | OBD_MD_FLGENER;
1338 obdo_from_inode(oa, inode, flags);
1343 rc = obd_setattr_rqset(sbi->ll_osc_exp, &oinfo, NULL);
1345 CERROR("obd_setattr_async fails: rc=%d\n", rc);
1354 int ll_setattr(struct dentry *de, struct iattr *attr)
1356 ll_vfs_ops_tally(ll_i2sbi(de->d_inode), VFS_OPS_SETATTR);
1358 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1359 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1360 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1362 return ll_setattr_raw(de->d_inode, attr);
1365 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1368 struct ll_sb_info *sbi = ll_s2sbi(sb);
1369 struct obd_statfs obd_osfs;
1373 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1375 CERROR("mdc_statfs fails: rc = %d\n", rc);
1379 osfs->os_type = sb->s_magic;
1381 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1382 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1384 rc = obd_statfs_rqset(class_exp2obd(sbi->ll_osc_exp),
1385 &obd_osfs, max_age);
1387 CERROR("obd_statfs fails: rc = %d\n", rc);
1391 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1392 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1395 osfs->os_blocks = obd_osfs.os_blocks;
1396 osfs->os_bfree = obd_osfs.os_bfree;
1397 osfs->os_bavail = obd_osfs.os_bavail;
1399 /* If we don't have as many objects free on the OST as inodes
1400 * on the MDS, we reduce the total number of inodes to
1401 * compensate, so that the "inodes in use" number is correct.
1403 if (obd_osfs.os_ffree < osfs->os_ffree) {
1404 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1406 osfs->os_ffree = obd_osfs.os_ffree;
1411 #ifndef HAVE_STATFS_DENTRY_PARAM
1412 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1415 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1417 struct super_block *sb = de->d_sb;
1419 struct obd_statfs osfs;
1422 CDEBUG(D_VFSTRACE, "VFS Op: at "LPU64" jiffies\n", get_jiffies_64());
1423 lprocfs_counter_incr(ll_s2sbi(sb)->ll_stats, LPROC_LL_STAFS);
1425 /* For now we will always get up-to-date statfs values, but in the
1426 * future we may allow some amount of caching on the client (e.g.
1427 * from QOS or lprocfs updates). */
1428 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - 1);
1432 statfs_unpack(sfs, &osfs);
1434 /* We need to downshift for all 32-bit kernels, because we can't
1435 * tell if the kernel is being called via sys_statfs64() or not.
1436 * Stop before overflowing f_bsize - in which case it is better
1437 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
1438 if (sizeof(long) < 8) {
1439 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1442 osfs.os_blocks >>= 1;
1443 osfs.os_bfree >>= 1;
1444 osfs.os_bavail >>= 1;
1448 sfs->f_blocks = osfs.os_blocks;
1449 sfs->f_bfree = osfs.os_bfree;
1450 sfs->f_bavail = osfs.os_bavail;
1455 void ll_inode_size_lock(struct inode *inode, int lock_lsm)
1457 struct ll_inode_info *lli;
1458 struct lov_stripe_md *lsm;
1460 lli = ll_i2info(inode);
1461 LASSERT(lli->lli_size_sem_owner != current);
1462 down(&lli->lli_size_sem);
1463 LASSERT(lli->lli_size_sem_owner == NULL);
1464 lli->lli_size_sem_owner = current;
1466 LASSERTF(lsm != NULL || lock_lsm == 0, "lsm %p, lock_lsm %d\n",
1469 lov_stripe_lock(lsm);
1472 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm)
1474 struct ll_inode_info *lli;
1475 struct lov_stripe_md *lsm;
1477 lli = ll_i2info(inode);
1479 LASSERTF(lsm != NULL || unlock_lsm == 0, "lsm %p, lock_lsm %d\n",
1482 lov_stripe_unlock(lsm);
1483 LASSERT(lli->lli_size_sem_owner == current);
1484 lli->lli_size_sem_owner = NULL;
1485 up(&lli->lli_size_sem);
1488 static void ll_replace_lsm(struct inode *inode, struct lov_stripe_md *lsm)
1490 struct ll_inode_info *lli = ll_i2info(inode);
1492 dump_lsm(D_INODE, lsm);
1493 dump_lsm(D_INODE, lli->lli_smd);
1494 LASSERTF(lsm->lsm_magic == LOV_MAGIC_JOIN,
1495 "lsm must be joined lsm %p\n", lsm);
1496 obd_free_memmd(ll_i2obdexp(inode), &lli->lli_smd);
1497 CDEBUG(D_INODE, "replace lsm %p to lli_smd %p for inode %lu%u(%p)\n",
1498 lsm, lli->lli_smd, inode->i_ino, inode->i_generation, inode);
1500 lli->lli_maxbytes = lsm->lsm_maxbytes;
1501 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1502 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1505 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1507 struct ll_inode_info *lli = ll_i2info(inode);
1508 struct mds_body *body = md->body;
1509 struct lov_stripe_md *lsm = md->lsm;
1511 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1513 if (lli->lli_smd == NULL) {
1514 if (lsm->lsm_magic != LOV_MAGIC &&
1515 lsm->lsm_magic != LOV_MAGIC_JOIN) {
1516 dump_lsm(D_ERROR, lsm);
1519 CDEBUG(D_INODE, "adding lsm %p to inode %lu/%u(%p)\n",
1520 lsm, inode->i_ino, inode->i_generation, inode);
1521 /* ll_inode_size_lock() requires it is only called
1522 * with lli_smd != NULL or lock_lsm == 0 or we can
1523 * race between lock/unlock. bug 9547 */
1525 lli->lli_maxbytes = lsm->lsm_maxbytes;
1526 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1527 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1529 if (lli->lli_smd->lsm_magic == lsm->lsm_magic &&
1530 lli->lli_smd->lsm_stripe_count ==
1531 lsm->lsm_stripe_count) {
1532 if (lov_stripe_md_cmp(lli->lli_smd, lsm)) {
1533 CERROR("lsm mismatch for inode %ld\n",
1535 CERROR("lli_smd:\n");
1536 dump_lsm(D_ERROR, lli->lli_smd);
1538 dump_lsm(D_ERROR, lsm);
1542 ll_replace_lsm(inode, lsm);
1544 if (lli->lli_smd != lsm)
1545 obd_free_memmd(ll_i2obdexp(inode), &lsm);
1548 #ifdef CONFIG_FS_POSIX_ACL
1549 LASSERT(!md->posix_acl || (body->valid & OBD_MD_FLACL));
1550 if (body->valid & OBD_MD_FLACL) {
1551 spin_lock(&lli->lli_lock);
1552 if (lli->lli_posix_acl)
1553 posix_acl_release(lli->lli_posix_acl);
1554 lli->lli_posix_acl = md->posix_acl;
1555 spin_unlock(&lli->lli_lock);
1559 if (body->valid & OBD_MD_FLID)
1560 inode->i_ino = body->ino;
1561 if (body->valid & OBD_MD_FLATIME &&
1562 body->atime > LTIME_S(inode->i_atime))
1563 LTIME_S(inode->i_atime) = body->atime;
1565 /* mtime is always updated with ctime, but can be set in past.
1566 As write and utime(2) may happen within 1 second, and utime's
1567 mtime has a priority over write's one, so take mtime from mds
1568 for the same ctimes. */
1569 if (body->valid & OBD_MD_FLCTIME &&
1570 body->ctime >= LTIME_S(inode->i_ctime)) {
1571 LTIME_S(inode->i_ctime) = body->ctime;
1572 if (body->valid & OBD_MD_FLMTIME) {
1573 CDEBUG(D_INODE, "setting ino %lu mtime "
1574 "from %lu to "LPU64"\n", inode->i_ino,
1575 LTIME_S(inode->i_mtime), body->mtime);
1576 LTIME_S(inode->i_mtime) = body->mtime;
1579 if (body->valid & OBD_MD_FLMODE)
1580 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1581 if (body->valid & OBD_MD_FLTYPE)
1582 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1583 if (S_ISREG(inode->i_mode)) {
1584 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
1586 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
1588 #ifdef HAVE_INODE_BLKSIZE
1589 inode->i_blksize = 1<<inode->i_blkbits;
1591 if (body->valid & OBD_MD_FLUID)
1592 inode->i_uid = body->uid;
1593 if (body->valid & OBD_MD_FLGID)
1594 inode->i_gid = body->gid;
1595 if (body->valid & OBD_MD_FLFLAGS)
1596 inode->i_flags = ll_ext_to_inode_flags(body->flags);
1597 if (body->valid & OBD_MD_FLNLINK)
1598 inode->i_nlink = body->nlink;
1599 if (body->valid & OBD_MD_FLGENER)
1600 inode->i_generation = body->generation;
1601 if (body->valid & OBD_MD_FLRDEV)
1602 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1603 inode->i_rdev = body->rdev;
1605 inode->i_rdev = old_decode_dev(body->rdev);
1607 if (body->valid & OBD_MD_FLSIZE)
1608 inode->i_size = body->size;
1609 if (body->valid & OBD_MD_FLBLOCKS)
1610 inode->i_blocks = body->blocks;
1612 if (body->valid & OBD_MD_FLSIZE)
1613 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1616 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
1617 static struct backing_dev_info ll_backing_dev_info = {
1618 .ra_pages = 0, /* No readahead */
1619 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
1620 .capabilities = 0, /* Does contribute to dirty memory */
1622 .memory_backed = 0, /* Does contribute to dirty memory */
1627 void ll_read_inode2(struct inode *inode, void *opaque)
1629 struct lustre_md *md = opaque;
1630 struct ll_inode_info *lli = ll_i2info(inode);
1633 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1634 inode->i_generation, inode);
1638 LASSERT(!lli->lli_smd);
1640 /* Core attributes from the MDS first. This is a new inode, and
1641 * the VFS doesn't zero times in the core inode so we have to do
1642 * it ourselves. They will be overwritten by either MDS or OST
1643 * attributes - we just need to make sure they aren't newer. */
1644 LTIME_S(inode->i_mtime) = 0;
1645 LTIME_S(inode->i_atime) = 0;
1646 LTIME_S(inode->i_ctime) = 0;
1648 ll_update_inode(inode, md);
1650 /* OIDEBUG(inode); */
1652 if (S_ISREG(inode->i_mode)) {
1653 struct ll_sb_info *sbi = ll_i2sbi(inode);
1654 inode->i_op = &ll_file_inode_operations;
1655 inode->i_fop = sbi->ll_fop;
1656 inode->i_mapping->a_ops = &ll_aops;
1658 } else if (S_ISDIR(inode->i_mode)) {
1659 inode->i_op = &ll_dir_inode_operations;
1660 inode->i_fop = &ll_dir_operations;
1661 inode->i_mapping->a_ops = &ll_dir_aops;
1663 } else if (S_ISLNK(inode->i_mode)) {
1664 inode->i_op = &ll_fast_symlink_inode_operations;
1667 inode->i_op = &ll_special_inode_operations;
1669 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1670 init_special_inode(inode, inode->i_mode,
1671 kdev_t_to_nr(inode->i_rdev));
1673 /* initializing backing dev info. */
1674 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
1676 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1682 int ll_iocontrol(struct inode *inode, struct file *file,
1683 unsigned int cmd, unsigned long arg)
1685 struct ll_sb_info *sbi = ll_i2sbi(inode);
1686 struct ptlrpc_request *req = NULL;
1691 case EXT3_IOC_GETFLAGS: {
1693 struct mds_body *body;
1695 ll_inode2fid(&fid, inode);
1696 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, OBD_MD_FLFLAGS,0,&req);
1698 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1702 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1705 /* We want to return EXT3_*_FL flags to the caller via this
1706 * ioctl. An older MDS may be sending S_* flags, fix it up. */
1707 flags = ll_inode_to_ext_flags(body->flags, body->flags);
1708 ptlrpc_req_finished (req);
1710 RETURN(put_user(flags, (int *)arg));
1712 case EXT3_IOC_SETFLAGS: {
1713 struct mdc_op_data op_data;
1714 struct ll_iattr_struct attr;
1715 struct obd_info oinfo = { { { 0 } } };
1716 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1718 if (get_user(flags, (int *)arg))
1722 oinfo.oi_oa = obdo_alloc();
1726 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
1728 memset(&attr, 0, sizeof(attr));
1729 attr.ia_attr_flags = flags;
1730 ((struct iattr *)&attr)->ia_valid |= ATTR_ATTR_FLAG;
1732 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
1733 (struct iattr *)&attr, NULL, 0, NULL, 0, &req);
1734 ptlrpc_req_finished(req);
1735 if (rc || lsm == NULL) {
1736 obdo_free(oinfo.oi_oa);
1740 oinfo.oi_oa->o_id = lsm->lsm_object_id;
1741 oinfo.oi_oa->o_flags = flags;
1742 oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS;
1744 obdo_from_inode(oinfo.oi_oa, inode,
1745 OBD_MD_FLFID | OBD_MD_FLGENER);
1746 rc = obd_setattr_rqset(sbi->ll_osc_exp, &oinfo, NULL);
1747 obdo_free(oinfo.oi_oa);
1749 if (rc != -EPERM && rc != -EACCES)
1750 CERROR("mdc_setattr_async fails: rc = %d\n", rc);
1754 inode->i_flags = ll_ext_to_inode_flags(flags |
1755 MDS_BFLAG_EXT_FLAGS);
1765 /* umount -f client means force down, don't save state */
1766 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
1767 void ll_umount_begin(struct vfsmount *vfsmnt, int flags)
1769 struct super_block *sb = vfsmnt->mnt_sb;
1771 void ll_umount_begin(struct super_block *sb)
1774 struct lustre_sb_info *lsi = s2lsi(sb);
1775 struct ll_sb_info *sbi = ll_s2sbi(sb);
1776 struct obd_device *obd;
1777 struct obd_ioctl_data ioc_data = { 0 };
1780 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
1781 if (!(flags & MNT_FORCE)) {
1787 /* Tell the MGC we got umount -f */
1788 lsi->lsi_flags |= LSI_UMOUNT_FORCE;
1790 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
1791 sb->s_count, atomic_read(&sb->s_active));
1793 obd = class_exp2obd(sbi->ll_mdc_exp);
1795 CERROR("Invalid MDC connection handle "LPX64"\n",
1796 sbi->ll_mdc_exp->exp_handle.h_cookie);
1800 obd->obd_no_recov = 1;
1801 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_mdc_exp, sizeof ioc_data,
1804 obd = class_exp2obd(sbi->ll_osc_exp);
1806 CERROR("Invalid LOV connection handle "LPX64"\n",
1807 sbi->ll_osc_exp->exp_handle.h_cookie);
1812 obd->obd_no_recov = 1;
1813 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_osc_exp, sizeof ioc_data,
1816 /* Really, we'd like to wait until there are no requests outstanding,
1817 * and then continue. For now, we just invalidate the requests,
1818 * schedule, and hope.
1825 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
1827 struct ll_sb_info *sbi = ll_s2sbi(sb);
1831 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
1832 read_only = *flags & MS_RDONLY;
1833 err = obd_set_info_async(sbi->ll_mdc_exp, strlen("read-only"),
1834 "read-only", sizeof(read_only),
1837 CERROR("Failed to change the read-only flag during "
1838 "remount: %d\n", err);
1843 sb->s_flags |= MS_RDONLY;
1845 sb->s_flags &= ~MS_RDONLY;
1850 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
1851 struct ptlrpc_request *req, int offset,struct super_block *sb)
1853 struct lustre_md md;
1854 struct ll_sb_info *sbi = NULL;
1858 LASSERT(*inode || sb);
1859 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
1860 prune_deathrow(sbi, 1);
1862 rc = mdc_req2lustre_md(req, offset, exp, &md);
1867 ll_update_inode(*inode, &md);
1870 *inode = ll_iget(sb, md.body->ino, &md);
1871 if (*inode == NULL || is_bad_inode(*inode)) {
1872 mdc_free_lustre_md(exp, &md);
1874 CERROR("new_inode -fatal: rc %d\n", rc);
1879 rc = obd_checkmd(exp, ll_i2mdcexp(*inode),
1880 ll_i2info(*inode)->lli_smd);
1885 char *llap_origins[] = {
1886 [LLAP_ORIGIN_UNKNOWN] = "--",
1887 [LLAP_ORIGIN_READPAGE] = "rp",
1888 [LLAP_ORIGIN_READAHEAD] = "ra",
1889 [LLAP_ORIGIN_COMMIT_WRITE] = "cw",
1890 [LLAP_ORIGIN_WRITEPAGE] = "wp",
1893 struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
1894 struct list_head *list)
1896 struct ll_async_page *llap;
1897 struct list_head *pos;
1899 list_for_each(pos, list) {
1900 if (pos == &sbi->ll_pglist)
1902 llap = list_entry(pos, struct ll_async_page, llap_pglist_item);
1903 if (llap->llap_page == NULL)
1911 int ll_obd_statfs(struct inode *inode, void *arg)
1913 struct ll_sb_info *sbi = NULL;
1914 struct obd_device *client_obd = NULL, *lov_obd = NULL;
1915 struct lov_obd *lov = NULL;
1916 struct obd_statfs stat_buf = {0};
1918 struct obd_ioctl_data *data = NULL;
1922 if (!inode || !(sbi = ll_i2sbi(inode)))
1923 GOTO(out_statfs, rc = -EINVAL);
1925 rc = obd_ioctl_getdata(&buf, &len, arg);
1927 GOTO(out_statfs, rc);
1930 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
1931 !data->ioc_pbuf1 || !data->ioc_pbuf2)
1932 GOTO(out_statfs, rc = -EINVAL);
1934 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
1935 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
1937 if (type == LL_STATFS_MDC) {
1939 GOTO(out_statfs, rc = -ENODEV);
1940 client_obd = class_exp2obd(sbi->ll_mdc_exp);
1941 } else if (type == LL_STATFS_LOV) {
1942 lov_obd = class_exp2obd(sbi->ll_osc_exp);
1943 lov = &lov_obd->u.lov;
1945 if (index >= lov->desc.ld_tgt_count)
1946 GOTO(out_statfs, rc = -ENODEV);
1948 if (!lov->lov_tgts[index])
1949 /* Try again with the next index */
1950 GOTO(out_statfs, rc = -EAGAIN);
1952 client_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
1953 if (!lov->lov_tgts[index]->ltd_active)
1954 GOTO(out_uuid, rc = -ENODATA);
1958 GOTO(out_statfs, rc = -EINVAL);
1960 rc = obd_statfs(client_obd, &stat_buf, cfs_time_current_64() - 1);
1962 GOTO(out_statfs, rc);
1964 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
1965 GOTO(out_statfs, rc = -EFAULT);
1968 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(client_obd),
1974 obd_ioctl_freedata(buf, len);
1978 int ll_process_config(struct lustre_cfg *lcfg)
1982 struct lprocfs_static_vars lvars;
1986 lprocfs_init_vars(llite, &lvars);
1988 /* The instance name contains the sb: lustre-client-aacfe000 */
1989 ptr = strrchr(lustre_cfg_string(lcfg, 0), '-');
1990 if (!ptr || !*(++ptr))
1992 if (sscanf(ptr, "%lx", &x) != 1)
1995 /* This better be a real Lustre superblock! */
1996 LASSERT(s2lsi((struct super_block *)sb)->lsi_lmd->lmd_magic == LMD_MAGIC);
1998 /* Note we have not called client_common_fill_super yet, so
1999 proc fns must be able to handle that! */
2000 rc = class_process_proc_param(PARAM_LLITE, lvars.obd_vars,