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 ll_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 #ifdef HAVE_EXPORT___IGET
87 INIT_LIST_HEAD(&sbi->ll_deathrow);
88 spin_lock_init(&sbi->ll_deathrow_lock);
90 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
91 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_r_hist.oh_lock);
92 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_w_hist.oh_lock);
98 void ll_free_sbi(struct super_block *sb)
100 struct ll_sb_info *sbi = ll_s2sbi(sb);
104 spin_lock(&ll_sb_lock);
105 list_del(&sbi->ll_list);
106 spin_unlock(&ll_sb_lock);
107 OBD_FREE(sbi, sizeof(*sbi));
112 static struct dentry_operations ll_d_root_ops = {
113 #ifdef LUSTRE_KERNEL_VERSION
114 .d_compare = ll_dcompare,
118 static int client_common_fill_super(struct super_block *sb,
119 char *mdc, char *osc)
121 struct inode *root = 0;
122 struct ll_sb_info *sbi = ll_s2sbi(sb);
123 struct obd_device *obd;
124 struct ll_fid rootfid;
125 struct obd_statfs osfs;
126 struct ptlrpc_request *request = NULL;
127 struct lustre_handle osc_conn = {0, };
128 struct lustre_handle mdc_conn = {0, };
130 struct obd_connect_data *data = NULL;
134 obd = class_name2obd(mdc);
136 CERROR("MDC %s: not setup or attached\n", mdc);
140 OBD_ALLOC(data, sizeof(*data));
144 if (proc_lustre_fs_root) {
145 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
148 CERROR("could not register mount in /proc/lustre");
151 /* indicate the features supported by this client */
152 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
154 OBD_CONNECT_ATTRFID | OBD_CONNECT_VERSION;
155 #ifdef CONFIG_FS_POSIX_ACL
156 data->ocd_connect_flags |= OBD_CONNECT_ACL;
158 data->ocd_ibits_known = MDS_INODELOCK_FULL;
159 data->ocd_version = LUSTRE_VERSION_CODE;
161 if (sb->s_flags & MS_RDONLY)
162 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
163 if (sbi->ll_flags & LL_SBI_USER_XATTR)
164 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
166 #ifdef HAVE_MS_FLOCK_LOCK
167 /* force vfs to use lustre handler for flock() calls - bug 10743 */
168 sb->s_flags |= MS_FLOCK_LOCK;
171 if (sbi->ll_flags & LL_SBI_FLOCK)
172 sbi->ll_fop = &ll_file_operations_flock;
174 sbi->ll_fop = &ll_file_operations;
176 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid, data);
178 LCONSOLE_ERROR("An MDT (mdc %s) is performing recovery, of "
179 "which this client is not a part. Please wait "
180 "for recovery to complete, abort, or "
184 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
187 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
189 err = obd_statfs(obd, &osfs, cfs_time_current_64() - HZ);
193 /* MDC connect is surely finished by now because we actually sent
194 * a statfs RPC, otherwise obd_connect() is asynchronous. */
195 *data = class_exp2cliimp(sbi->ll_mdc_exp)->imp_connect_data;
197 LASSERT(osfs.os_bsize);
198 sb->s_blocksize = osfs.os_bsize;
199 sb->s_blocksize_bits = log2(osfs.os_bsize);
200 sb->s_magic = LL_SUPER_MAGIC;
202 /* for bug 11559. in $LINUX/fs/read_write.c, function do_sendfile():
203 * retval = in_file->f_op->sendfile(...);
205 * retval = -EOVERFLOW;
207 * it will check if *ppos is greater than max. However, max equals to
208 * s_maxbytes, which is a negative integer in a x86_64 box since loff_t
209 * has been defined as a signed long long ineger in linux kernel. */
210 #if BITS_PER_LONG == 64
211 sb->s_maxbytes = PAGE_CACHE_MAXBYTES >> 1;
213 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
215 sbi->ll_namelen = osfs.os_namelen;
216 sbi->ll_max_rw_chunk = LL_DEFAULT_MAX_RW_CHUNK;
218 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
219 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
220 LCONSOLE_INFO("Disabling user_xattr feature because "
221 "it is not supported on the server\n");
222 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
225 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
227 sb->s_flags |= MS_POSIXACL;
229 sbi->ll_flags |= LL_SBI_ACL;
231 sbi->ll_flags &= ~LL_SBI_ACL;
233 if (data->ocd_connect_flags & OBD_CONNECT_JOIN)
234 sbi->ll_flags |= LL_SBI_JOIN;
236 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
237 /* We set sb->s_dev equal on all lustre clients in order to support
238 * NFS export clustering. NFSD requires that the FSID be the same
240 /* s_dev is also used in lt_compare() to compare two fs, but that is
241 * only a node-local comparison. */
242 sb->s_dev = get_uuid2int(sbi2mdc(sbi)->cl_target_uuid.uuid,
243 strlen(sbi2mdc(sbi)->cl_target_uuid.uuid));
246 obd = class_name2obd(osc);
248 CERROR("OSC %s: not setup or attached\n", osc);
249 GOTO(out_mdc, err = -ENODEV);
252 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
253 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE;
255 CDEBUG(D_RPCTRACE, "ocd_connect_flags: "LPX64" ocd_version: %d "
256 "ocd_grant: %d\n", data->ocd_connect_flags,
257 data->ocd_version, data->ocd_grant);
259 obd->obd_upcall.onu_owner = &sbi->ll_lco;
260 obd->obd_upcall.onu_upcall = ll_ocd_update;
261 data->ocd_brw_size = PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT;
264 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid, data);
266 LCONSOLE_ERROR("An OST (osc %s) is performing recovery, of "
267 "which this client is not a part. Please wait "
268 "for recovery to complete, abort, or "
272 CERROR("cannot connect to %s: rc = %d\n", osc, err);
275 sbi->ll_osc_exp = class_conn2export(&osc_conn);
276 spin_lock(&sbi->ll_lco.lco_lock);
277 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
278 spin_unlock(&sbi->ll_lco.lco_lock);
280 mdc_init_ea_size(sbi->ll_mdc_exp, sbi->ll_osc_exp);
282 err = obd_prep_async_page(sbi->ll_osc_exp, NULL, NULL, NULL,
283 0, NULL, NULL, NULL);
285 LCONSOLE_ERROR("There are no OST's in this filesystem. "
286 "There must be at least one active OST for "
287 "a client to start.\n");
291 if (!ll_async_page_slab) {
292 ll_async_page_slab_size =
293 size_round(sizeof(struct ll_async_page)) + err;
294 ll_async_page_slab = kmem_cache_create("ll_async_page",
295 ll_async_page_slab_size,
297 if (!ll_async_page_slab)
298 GOTO(out_osc, -ENOMEM);
301 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
303 CERROR("cannot mds_connect: rc = %d\n", err);
306 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
307 sbi->ll_rootino = rootfid.id;
309 sb->s_op = &lustre_super_operations;
310 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
311 sb->s_export_op = &lustre_export_operations;
315 * XXX: move this to after cbd setup? */
316 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
317 OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS |
318 (sbi->ll_flags & LL_SBI_ACL ? OBD_MD_FLACL : 0),
321 CERROR("mdc_getattr failed for root: rc = %d\n", err);
325 err = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md);
327 CERROR("failed to understand root inode md: rc = %d\n",err);
328 ptlrpc_req_finished (request);
332 LASSERT(sbi->ll_rootino != 0);
333 root = ll_iget(sb, sbi->ll_rootino, &md);
335 ptlrpc_req_finished(request);
337 if (root == NULL || is_bad_inode(root)) {
338 mdc_free_lustre_md(sbi->ll_osc_exp, &md);
339 CERROR("lustre_lite: bad iget4 for root\n");
340 GOTO(out_root, err = -EBADF);
343 err = ll_close_thread_start(&sbi->ll_lcq);
345 CERROR("cannot start close thread: rc %d\n", err);
349 /* making vm readahead 0 for 2.4.x. In the case of 2.6.x,
350 backing dev info assigned to inode mapping is used for
351 determining maximal readahead. */
352 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) && \
353 !defined(KERNEL_HAS_AS_MAX_READAHEAD)
354 /* bug 2805 - set VM readahead to zero */
355 vm_max_readahead = vm_min_readahead = 0;
358 sb->s_root = d_alloc_root(root);
360 OBD_FREE(data, sizeof(*data));
361 sb->s_root->d_op = &ll_d_root_ops;
368 obd_disconnect(sbi->ll_osc_exp);
369 sbi->ll_osc_exp = NULL;
371 obd_disconnect(sbi->ll_mdc_exp);
372 sbi->ll_mdc_exp = NULL;
375 OBD_FREE(data, sizeof(*data));
376 lprocfs_unregister_mountpoint(sbi);
380 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
384 *lmmsize = obd_size_diskmd(sbi->ll_osc_exp, NULL);
386 rc = obd_get_info(sbi->ll_mdc_exp, strlen("max_easize"), "max_easize",
389 CERROR("Get max mdsize error rc %d \n", rc);
394 void ll_dump_inode(struct inode *inode)
396 struct list_head *tmp;
397 int dentry_count = 0;
399 LASSERT(inode != NULL);
401 list_for_each(tmp, &inode->i_dentry)
404 CERROR("inode %p dump: dev=%s ino=%lu mode=%o count=%u, %d dentries\n",
405 inode, ll_i2mdcexp(inode)->exp_obd->obd_name, inode->i_ino,
406 inode->i_mode, atomic_read(&inode->i_count), dentry_count);
409 void lustre_dump_dentry(struct dentry *dentry, int recur)
411 struct list_head *tmp;
414 LASSERT(dentry != NULL);
416 list_for_each(tmp, &dentry->d_subdirs)
419 CERROR("dentry %p dump: name=%.*s parent=%.*s (%p), inode=%p, count=%u,"
420 " flags=0x%x, fsdata=%p, %d subdirs\n", dentry,
421 dentry->d_name.len, dentry->d_name.name,
422 dentry->d_parent->d_name.len, dentry->d_parent->d_name.name,
423 dentry->d_parent, dentry->d_inode, atomic_read(&dentry->d_count),
424 dentry->d_flags, dentry->d_fsdata, subdirs);
425 if (dentry->d_inode != NULL)
426 ll_dump_inode(dentry->d_inode);
431 list_for_each(tmp, &dentry->d_subdirs) {
432 struct dentry *d = list_entry(tmp, struct dentry, d_child);
433 lustre_dump_dentry(d, recur - 1);
437 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
438 void lustre_throw_orphan_dentries(struct super_block *sb)
440 struct dentry *dentry, *next;
441 struct ll_sb_info *sbi = ll_s2sbi(sb);
443 /* Do this to get rid of orphaned dentries. That is not really trw. */
444 list_for_each_entry_safe(dentry, next, &sbi->ll_orphan_dentry_list,
446 CWARN("found orphan dentry %.*s (%p->%p) at unmount, dumping "
447 "before and after shrink_dcache_parent\n",
448 dentry->d_name.len, dentry->d_name.name, dentry, next);
449 lustre_dump_dentry(dentry, 1);
450 shrink_dcache_parent(dentry);
451 lustre_dump_dentry(dentry, 1);
455 #define lustre_throw_orphan_dentries(sb)
458 #ifdef HAVE_EXPORT___IGET
459 static void prune_dir_dentries(struct inode *inode)
461 struct dentry *dentry, *prev = NULL;
463 /* due to lustre specific logic, a directory
464 * can have few dentries - a bug from VFS POV */
466 spin_lock(&dcache_lock);
467 if (!list_empty(&inode->i_dentry)) {
468 dentry = list_entry(inode->i_dentry.prev,
469 struct dentry, d_alias);
470 /* in order to prevent infinite loops we
471 * break if previous dentry is busy */
472 if (dentry != prev) {
475 spin_unlock(&dcache_lock);
477 /* try to kill all child dentries */
479 shrink_dcache_parent(dentry);
480 unlock_dentry(dentry);
483 /* now try to get rid of current dentry */
484 d_prune_aliases(inode);
488 spin_unlock(&dcache_lock);
491 static void prune_deathrow_one(struct ll_inode_info *lli)
493 struct inode *inode = ll_info2i(lli);
495 /* first, try to drop any dentries - they hold a ref on the inode */
496 if (S_ISDIR(inode->i_mode))
497 prune_dir_dentries(inode);
499 d_prune_aliases(inode);
502 /* if somebody still uses it, leave it */
503 LASSERT(atomic_read(&inode->i_count) > 0);
504 if (atomic_read(&inode->i_count) > 1)
507 CDEBUG(D_INODE, "inode %lu/%u(%d) looks a good candidate for prune\n",
508 inode->i_ino,inode->i_generation, atomic_read(&inode->i_count));
510 /* seems nobody uses it anymore */
518 static void prune_deathrow(struct ll_sb_info *sbi, int try)
520 struct ll_inode_info *lli;
524 if (need_resched() && try)
528 if (!spin_trylock(&sbi->ll_deathrow_lock))
531 spin_lock(&sbi->ll_deathrow_lock);
536 if (!list_empty(&sbi->ll_deathrow)) {
537 lli = list_entry(sbi->ll_deathrow.next,
538 struct ll_inode_info,
540 list_del_init(&lli->lli_dead_list);
541 if (!list_empty(&sbi->ll_deathrow))
544 spin_unlock(&sbi->ll_deathrow_lock);
547 prune_deathrow_one(lli);
549 } while (empty == 0);
551 #else /* !HAVE_EXPORT___IGET */
552 #define prune_deathrow(sbi, try) do {} while (0)
553 #endif /* HAVE_EXPORT___IGET */
555 void client_common_put_super(struct super_block *sb)
557 struct ll_sb_info *sbi = ll_s2sbi(sb);
560 ll_close_thread_shutdown(sbi->ll_lcq);
562 lprocfs_unregister_mountpoint(sbi);
564 /* destroy inodes in deathrow */
565 prune_deathrow(sbi, 0);
567 list_del(&sbi->ll_conn_chain);
568 obd_disconnect(sbi->ll_osc_exp);
569 sbi->ll_osc_exp = NULL;
571 obd_disconnect(sbi->ll_mdc_exp);
572 sbi->ll_mdc_exp = NULL;
574 lustre_throw_orphan_dentries(sb);
578 char *ll_read_opt(const char *opt, char *data)
584 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
585 if (strncmp(opt, data, strlen(opt)))
587 if ((value = strchr(data, '=')) == NULL)
591 OBD_ALLOC(retval, strlen(value) + 1);
593 CERROR("out of memory!\n");
597 memcpy(retval, value, strlen(value)+1);
598 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
602 static inline int ll_set_opt(const char *opt, char *data, int fl)
604 if (strncmp(opt, data, strlen(opt)) != 0)
610 /* non-client-specific mount options are parsed in lmd_parse */
611 static int ll_options(char *options, int *flags)
614 char *s1 = options, *s2;
620 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
623 CDEBUG(D_SUPER, "next opt=%s\n", s1);
624 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
629 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
634 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK);
639 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
644 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
649 tmp = ll_set_opt("acl", s1, LL_SBI_ACL);
651 /* Ignore deprecated mount option. The client will
652 * always try to mount with ACL support, whether this
653 * is used depends on whether server supports it. */
656 tmp = ll_set_opt("noacl", s1, LL_SBI_ACL);
661 LCONSOLE_ERROR("Unknown option '%s', won't mount.\n", s1);
666 s2 = strchr(s1, ',');
674 void ll_lli_init(struct ll_inode_info *lli)
676 sema_init(&lli->lli_open_sem, 1);
677 sema_init(&lli->lli_size_sem, 1);
678 sema_init(&lli->lli_write_sem, 1);
680 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
681 spin_lock_init(&lli->lli_lock);
682 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
683 lli->lli_inode_magic = LLI_INODE_MAGIC;
684 sema_init(&lli->lli_och_sem, 1);
685 lli->lli_mds_read_och = lli->lli_mds_write_och = NULL;
686 lli->lli_mds_exec_och = NULL;
687 lli->lli_open_fd_read_count = lli->lli_open_fd_write_count = 0;
688 lli->lli_open_fd_exec_count = 0;
689 INIT_LIST_HEAD(&lli->lli_dead_list);
693 #define MDCDEV "mdc_dev"
694 static int old_lustre_process_log(struct super_block *sb, char *newprofile,
695 struct config_llog_instance *cfg)
697 struct lustre_sb_info *lsi = s2lsi(sb);
698 struct obd_device *obd;
699 struct lustre_handle mdc_conn = {0, };
700 struct obd_export *exp;
701 char *ptr, *mdt, *profile;
702 char niduuid[10] = "mdtnid0";
704 struct obd_uuid mdc_uuid;
705 struct llog_ctxt *ctxt;
706 struct obd_connect_data ocd = { 0 };
708 int i, rc = 0, recov_bk = 1, failnodes = 0;
711 ll_generate_random_uuid(uuid);
712 class_uuid_unparse(uuid, &mdc_uuid);
713 CDEBUG(D_HA, "generated uuid: %s\n", mdc_uuid.uuid);
715 /* Figure out the old mdt and profile name from new-style profile
716 ("lustre" from "mds/lustre-client") */
718 profile = strchr(mdt, '/');
719 if (profile == NULL) {
720 CDEBUG(D_CONFIG, "Can't find MDT name in %s\n", newprofile);
721 GOTO(out, rc = -EINVAL);
725 ptr = strrchr(profile, '-');
727 CDEBUG(D_CONFIG, "Can't find client name in %s\n", newprofile);
728 GOTO(out, rc = -EINVAL);
732 LCONSOLE_WARN("This looks like an old mount command; I will try to "
733 "contact MDT '%s' for profile '%s'\n", mdt, profile);
735 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
737 ptr = lsi->lsi_lmd->lmd_dev;
738 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
739 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid, 0,0,0);
741 /* Stop at the first failover nid */
746 CERROR("No valid MDT nids found.\n");
747 GOTO(out, rc = -EINVAL);
751 rc = do_lcfg(MDCDEV, 0, LCFG_ATTACH, LUSTRE_MDC_NAME,mdc_uuid.uuid,0,0);
753 GOTO(out_del_uuid, rc);
755 rc = do_lcfg(MDCDEV, 0, LCFG_SETUP, mdt, niduuid, 0, 0);
757 LCONSOLE_ERROR("I couldn't establish a connection with the MDT."
758 " Check that the MDT host NID is correct and the"
759 " networks are up.\n");
760 GOTO(out_detach, rc);
763 obd = class_name2obd(MDCDEV);
765 GOTO(out_cleanup, rc = -EINVAL);
767 /* Add any failover nids */
768 while (*ptr == ':') {
769 /* New failover node */
770 sprintf(niduuid, "mdtnid%d", failnodes);
772 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
774 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid,0,0,0);
776 CERROR("Add uuid for %s failed %d\n",
777 libcfs_nid2str(nid), rc);
782 rc = do_lcfg(MDCDEV, 0, LCFG_ADD_CONN, niduuid, 0, 0,0);
784 CERROR("Add conn for %s failed %d\n",
785 libcfs_nid2str(nid), rc);
793 /* Try all connections, but only once. */
794 rc = obd_set_info_async(obd->obd_self_export,
795 strlen("init_recov_bk"), "init_recov_bk",
796 sizeof(recov_bk), &recov_bk, NULL);
798 GOTO(out_cleanup, rc);
800 /* If we don't have this then an ACL MDS will refuse the connection */
801 ocd.ocd_connect_flags = OBD_CONNECT_ACL;
803 rc = obd_connect(&mdc_conn, obd, &mdc_uuid, &ocd);
805 CERROR("cannot connect to %s: rc = %d\n", mdt, rc);
806 GOTO(out_cleanup, rc);
809 exp = class_conn2export(&mdc_conn);
811 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
813 cfg->cfg_flags |= CFG_F_COMPAT146;
816 rc = class_config_parse_llog(ctxt, profile, cfg);
819 * For debugging, it's useful to just dump the log
821 rc = class_config_dump_llog(ctxt, profile, cfg);
825 /* Set the caller's profile name to the old-style */
826 memcpy(newprofile, profile, strlen(profile) + 1);
830 LCONSOLE_ERROR("%s: The configuration '%s' could not be read "
831 "from the MDT '%s'. Make sure this client and "
832 "the MDT are running compatible versions of "
834 obd->obd_name, profile, mdt);
837 LCONSOLE_ERROR("%s: The configuration '%s' could not be read "
838 "from the MDT '%s'. This may be the result of "
839 "communication errors between the client and "
840 "the MDT, or if the MDT is not running.\n",
841 obd->obd_name, profile, mdt);
845 /* We don't so much care about errors in cleaning up the config llog
846 * connection, as we have already read the config by this point. */
850 do_lcfg(MDCDEV, 0, LCFG_CLEANUP, 0, 0, 0, 0);
853 do_lcfg(MDCDEV, 0, LCFG_DETACH, 0, 0, 0, 0);
856 /* class_add_uuid adds a nid even if the same uuid exists; we might
857 delete any copy here. So they all better match. */
858 for (i = 0; i < failnodes; i++) {
859 sprintf(niduuid, "mdtnid%d", i);
860 do_lcfg(MDCDEV, 0, LCFG_DEL_UUID, niduuid, 0, 0, 0);
862 /* class_import_put will get rid of the additional connections */
868 int ll_fill_super(struct super_block *sb)
870 struct lustre_profile *lprof;
871 struct lustre_sb_info *lsi = s2lsi(sb);
872 struct ll_sb_info *sbi;
873 char *osc = NULL, *mdc = NULL;
874 char *profilenm = get_profile_name(sb);
875 struct config_llog_instance cfg = {0, };
876 char ll_instance[sizeof(sb) * 2 + 1];
880 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
884 /* client additional sb info */
885 lsi->lsi_llsbi = sbi = ll_init_sbi();
891 err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
895 /* Generate a string unique to this super, in case some joker tries
896 to mount the same fs at two mount points.
897 Use the address of the super itself.*/
898 sprintf(ll_instance, "%p", sb);
899 cfg.cfg_instance = ll_instance;
900 cfg.cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
902 /* set up client obds */
903 err = lustre_process_log(sb, profilenm, &cfg);
908 oldnamelen = strlen(profilenm) + 1;
909 /* Temp storage for 1.4.6 profile name */
910 OBD_ALLOC(oldname, oldnamelen);
912 memcpy(oldname, profilenm, oldnamelen);
913 rc = old_lustre_process_log(sb, oldname, &cfg);
915 /* That worked - update the profile name
918 OBD_FREE(lsi->lsi_lmd->lmd_profile,
919 strlen(lsi->lsi_lmd->lmd_profile) + 1);
920 OBD_ALLOC(lsi->lsi_lmd->lmd_profile,
921 strlen(oldname) + 1);
922 if (!lsi->lsi_lmd->lmd_profile) {
923 OBD_FREE(oldname, oldnamelen);
924 GOTO(out_free, err = -ENOMEM);
926 memcpy(lsi->lsi_lmd->lmd_profile, oldname,
927 strlen(oldname) + 1);
928 profilenm = get_profile_name(sb);
929 cfg.cfg_flags |= CFG_F_SERVER146;
931 OBD_FREE(oldname, oldnamelen);
936 CERROR("Unable to process log: %d\n", err);
940 lprof = class_get_profile(profilenm);
942 LCONSOLE_ERROR("The client profile '%s' could not be read "
943 "from the MGS. Does that filesystem exist?\n",
945 GOTO(out_free, err = -EINVAL);
947 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
948 lprof->lp_mdc, lprof->lp_osc);
950 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
951 strlen(ll_instance) + 2);
953 GOTO(out_free, err = -ENOMEM);
954 sprintf(osc, "%s-%s", lprof->lp_osc, ll_instance);
956 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
957 strlen(ll_instance) + 2);
959 GOTO(out_free, err = -ENOMEM);
960 sprintf(mdc, "%s-%s", lprof->lp_mdc, ll_instance);
962 /* connections, registrations, sb setup */
963 err = client_common_fill_super(sb, mdc, osc);
967 OBD_FREE(mdc, strlen(mdc) + 1);
969 OBD_FREE(osc, strlen(osc) + 1);
973 LCONSOLE_WARN("Client %s has started\n", profilenm);
976 } /* ll_fill_super */
979 void ll_put_super(struct super_block *sb)
981 struct config_llog_instance cfg;
982 char ll_instance[sizeof(sb) * 2 + 1];
983 struct obd_device *obd;
984 struct lustre_sb_info *lsi = s2lsi(sb);
985 struct ll_sb_info *sbi = ll_s2sbi(sb);
986 char *profilenm = get_profile_name(sb);
990 CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
992 sprintf(ll_instance, "%p", sb);
993 cfg.cfg_instance = ll_instance;
994 lustre_end_log(sb, NULL, &cfg);
996 if (sbi->ll_mdc_exp) {
997 obd = class_exp2obd(sbi->ll_mdc_exp);
999 force = obd->obd_no_recov;
1002 /* We need to set force before the lov_disconnect in
1003 lustre_common_put_super, since l_d cleans up osc's as well. */
1006 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1008 obd->obd_force = force;
1013 /* Only if client_common_fill_super succeeded */
1014 client_common_put_super(sb);
1018 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) !=NULL) {
1019 class_manual_cleanup(obd);
1023 class_del_profile(profilenm);
1026 lsi->lsi_llsbi = NULL;
1028 lustre_common_put_super(sb);
1030 LCONSOLE_WARN("client %s umount complete\n", ll_instance);
1035 } /* client_put_super */
1037 #ifdef HAVE_REGISTER_CACHE
1038 #include <linux/cache_def.h>
1039 #ifdef HAVE_CACHE_RETURN_INT
1044 ll_shrink_cache(int priority, unsigned int gfp_mask)
1046 struct ll_sb_info *sbi;
1049 list_for_each_entry(sbi, &ll_super_blocks, ll_list)
1050 count += llap_shrink_cache(sbi, priority);
1052 #ifdef HAVE_CACHE_RETURN_INT
1057 struct cache_definition ll_cache_definition = {
1058 .name = "llap_cache",
1059 .shrink = ll_shrink_cache
1061 #endif /* HAVE_REGISTER_CACHE */
1063 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
1065 struct inode *inode = NULL;
1066 /* NOTE: we depend on atomic igrab() -bzzz */
1067 lock_res_and_lock(lock);
1068 if (lock->l_ast_data) {
1069 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
1070 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1071 inode = igrab(lock->l_ast_data);
1073 inode = lock->l_ast_data;
1074 ldlm_lock_debug(NULL, inode->i_state & I_FREEING ?
1076 lock, __FILE__, __func__, __LINE__,
1077 "l_ast_data %p is bogus: magic %08x",
1078 lock->l_ast_data, lli->lli_inode_magic);
1082 unlock_res_and_lock(lock);
1086 static int null_if_equal(struct ldlm_lock *lock, void *data)
1088 if (data == lock->l_ast_data) {
1089 lock->l_ast_data = NULL;
1091 if (lock->l_req_mode != lock->l_granted_mode)
1092 LDLM_ERROR(lock,"clearing inode with ungranted lock");
1095 return LDLM_ITER_CONTINUE;
1098 void ll_clear_inode(struct inode *inode)
1101 struct ll_inode_info *lli = ll_i2info(inode);
1102 struct ll_sb_info *sbi = ll_i2sbi(inode);
1105 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1106 inode->i_generation, inode);
1108 ll_inode2fid(&fid, inode);
1109 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1110 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
1112 LASSERT(!lli->lli_open_fd_write_count);
1113 LASSERT(!lli->lli_open_fd_read_count);
1114 LASSERT(!lli->lli_open_fd_exec_count);
1116 if (lli->lli_mds_write_och)
1117 ll_mdc_real_close(inode, FMODE_WRITE);
1118 if (lli->lli_mds_exec_och) {
1120 CERROR("No FMODE exec, bug exec och is present for "
1121 "inode %ld\n", inode->i_ino);
1122 ll_mdc_real_close(inode, FMODE_EXEC);
1124 if (lli->lli_mds_read_och)
1125 ll_mdc_real_close(inode, FMODE_READ);
1129 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
1130 null_if_equal, inode);
1132 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
1133 lli->lli_smd = NULL;
1136 if (lli->lli_symlink_name) {
1137 OBD_FREE(lli->lli_symlink_name,
1138 strlen(lli->lli_symlink_name) + 1);
1139 lli->lli_symlink_name = NULL;
1142 #ifdef CONFIG_FS_POSIX_ACL
1143 if (lli->lli_posix_acl) {
1144 LASSERT(atomic_read(&lli->lli_posix_acl->a_refcount) == 1);
1145 posix_acl_release(lli->lli_posix_acl);
1146 lli->lli_posix_acl = NULL;
1150 lli->lli_inode_magic = LLI_INODE_DEAD;
1152 #ifdef HAVE_EXPORT___IGET
1153 spin_lock(&sbi->ll_deathrow_lock);
1154 list_del_init(&lli->lli_dead_list);
1155 spin_unlock(&sbi->ll_deathrow_lock);
1161 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1162 * object(s) determine the file size and mtime. Otherwise, the MDS will
1163 * keep these values until such a time that objects are allocated for it.
1164 * We do the MDS operations first, as it is checking permissions for us.
1165 * We don't to the MDS RPC if there is nothing that we want to store there,
1166 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1167 * going to do an RPC anyways.
1169 * If we are doing a truncate, we will send the mtime and ctime updates
1170 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1171 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1174 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
1176 struct ll_inode_info *lli = ll_i2info(inode);
1177 struct lov_stripe_md *lsm = lli->lli_smd;
1178 struct ll_sb_info *sbi = ll_i2sbi(inode);
1179 struct ptlrpc_request *request = NULL;
1180 struct mdc_op_data op_data;
1181 struct lustre_md md;
1182 int ia_valid = attr->ia_valid;
1186 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu valid %x\n", inode->i_ino,
1188 lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_SETATTR);
1190 if (ia_valid & ATTR_SIZE) {
1191 if (attr->ia_size > ll_file_maxbytes(inode)) {
1192 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
1193 attr->ia_size, ll_file_maxbytes(inode));
1197 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1200 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1201 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
1202 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1206 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1207 if (attr->ia_valid & ATTR_CTIME) {
1208 attr->ia_ctime = CURRENT_TIME;
1209 attr->ia_valid |= ATTR_CTIME_SET;
1211 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
1212 attr->ia_atime = CURRENT_TIME;
1213 attr->ia_valid |= ATTR_ATIME_SET;
1215 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
1216 attr->ia_mtime = CURRENT_TIME;
1217 attr->ia_valid |= ATTR_MTIME_SET;
1219 if ((attr->ia_valid & ATTR_CTIME) && !(attr->ia_valid & ATTR_MTIME)) {
1220 /* To avoid stale mtime on mds, obtain it from ost and send
1222 rc = ll_glimpse_size(inode, 0);
1226 attr->ia_valid |= ATTR_MTIME_SET | ATTR_MTIME;
1227 attr->ia_mtime = inode->i_mtime;
1230 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1231 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
1232 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1235 /* NB: ATTR_SIZE will only be set after this point if the size
1236 * resides on the MDS, ie, this file has no objects. */
1238 attr->ia_valid &= ~ATTR_SIZE;
1240 /* We always do an MDS RPC, even if we're only changing the size;
1241 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
1242 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
1244 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
1245 attr, NULL, 0, NULL, 0, &request);
1248 ptlrpc_req_finished(request);
1249 if (rc == -ENOENT) {
1251 /* Unlinked special device node? Or just a race?
1252 * Pretend we done everything. */
1253 if (!S_ISREG(inode->i_mode) &&
1254 !S_ISDIR(inode->i_mode))
1255 rc = inode_setattr(inode, attr);
1256 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY)
1257 CERROR("mdc_setattr fails: rc = %d\n", rc);
1261 rc = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md);
1263 ptlrpc_req_finished(request);
1267 /* We call inode_setattr to adjust timestamps.
1268 * If there is at least some data in file, we cleared ATTR_SIZE above to
1269 * avoid invoking vmtruncate, otherwise it is important to call
1270 * vmtruncate in inode_setattr to update inode->i_size (bug 6196) */
1271 rc = inode_setattr(inode, attr);
1273 ll_update_inode(inode, &md);
1274 ptlrpc_req_finished(request);
1276 if (!lsm || !S_ISREG(inode->i_mode)) {
1277 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
1281 /* We really need to get our PW lock before we change inode->i_size.
1282 * If we don't we can race with other i_size updaters on our node, like
1283 * ll_file_read. We can also race with i_size propogation to other
1284 * nodes through dirtying and writeback of final cached pages. This
1285 * last one is especially bad for racing o_append users on other
1287 if (ia_valid & ATTR_SIZE) {
1288 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
1290 struct lustre_handle lockh = { 0 };
1291 int err, ast_flags = 0;
1292 /* XXX when we fix the AST intents to pass the discard-range
1293 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
1295 if (attr->ia_size == 0)
1296 ast_flags = LDLM_AST_DISCARD_DATA;
1298 UNLOCK_INODE_MUTEX(inode);
1299 UP_WRITE_I_ALLOC_SEM(inode);
1300 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy, &lockh,
1302 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1303 DOWN_WRITE_I_ALLOC_SEM(inode);
1304 LOCK_INODE_MUTEX(inode);
1306 LOCK_INODE_MUTEX(inode);
1307 DOWN_WRITE_I_ALLOC_SEM(inode);
1312 /* Only ll_inode_size_lock is taken at this level.
1313 * lov_stripe_lock() is grabbed by ll_truncate() only over
1314 * call to obd_adjust_kms(). If vmtruncate returns 0, then
1315 * ll_truncate dropped ll_inode_size_lock() */
1316 ll_inode_size_lock(inode, 0);
1317 rc = vmtruncate(inode, attr->ia_size);
1319 LASSERT(atomic_read(&lli->lli_size_sem.count) <= 0);
1320 ll_inode_size_unlock(inode, 0);
1323 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
1325 CERROR("ll_extent_unlock failed: %d\n", err);
1329 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
1331 struct obd_info oinfo = { { { 0 } } };
1332 struct obdo *oa = obdo_alloc();
1334 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1335 inode->i_ino, LTIME_S(attr->ia_mtime));
1338 oa->o_id = lsm->lsm_object_id;
1339 oa->o_valid = OBD_MD_FLID;
1341 flags = OBD_MD_FLTYPE | OBD_MD_FLATIME |
1342 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1343 OBD_MD_FLFID | OBD_MD_FLGENER;
1345 obdo_from_inode(oa, inode, flags);
1350 rc = obd_setattr_rqset(sbi->ll_osc_exp, &oinfo, NULL);
1352 CERROR("obd_setattr_async fails: rc=%d\n", rc);
1361 int ll_setattr(struct dentry *de, struct iattr *attr)
1363 ll_vfs_ops_tally(ll_i2sbi(de->d_inode), VFS_OPS_SETATTR);
1365 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1366 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1367 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1369 return ll_setattr_raw(de->d_inode, attr);
1372 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1375 struct ll_sb_info *sbi = ll_s2sbi(sb);
1376 struct obd_statfs obd_osfs;
1380 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1382 CERROR("mdc_statfs fails: rc = %d\n", rc);
1386 osfs->os_type = sb->s_magic;
1388 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1389 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1391 rc = obd_statfs_rqset(class_exp2obd(sbi->ll_osc_exp),
1392 &obd_osfs, max_age);
1394 CERROR("obd_statfs fails: rc = %d\n", rc);
1398 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1399 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1402 osfs->os_blocks = obd_osfs.os_blocks;
1403 osfs->os_bfree = obd_osfs.os_bfree;
1404 osfs->os_bavail = obd_osfs.os_bavail;
1406 /* If we don't have as many objects free on the OST as inodes
1407 * on the MDS, we reduce the total number of inodes to
1408 * compensate, so that the "inodes in use" number is correct.
1410 if (obd_osfs.os_ffree < osfs->os_ffree) {
1411 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1413 osfs->os_ffree = obd_osfs.os_ffree;
1418 #ifndef HAVE_STATFS_DENTRY_PARAM
1419 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1422 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1424 struct super_block *sb = de->d_sb;
1426 struct obd_statfs osfs;
1429 CDEBUG(D_VFSTRACE, "VFS Op: at "LPU64" jiffies\n", get_jiffies_64());
1430 lprocfs_counter_incr(ll_s2sbi(sb)->ll_stats, LPROC_LL_STAFS);
1432 /* For now we will always get up-to-date statfs values, but in the
1433 * future we may allow some amount of caching on the client (e.g.
1434 * from QOS or lprocfs updates). */
1435 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - 1);
1439 statfs_unpack(sfs, &osfs);
1441 /* We need to downshift for all 32-bit kernels, because we can't
1442 * tell if the kernel is being called via sys_statfs64() or not.
1443 * Stop before overflowing f_bsize - in which case it is better
1444 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
1445 if (sizeof(long) < 8) {
1446 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1449 osfs.os_blocks >>= 1;
1450 osfs.os_bfree >>= 1;
1451 osfs.os_bavail >>= 1;
1455 sfs->f_blocks = osfs.os_blocks;
1456 sfs->f_bfree = osfs.os_bfree;
1457 sfs->f_bavail = osfs.os_bavail;
1462 void ll_inode_size_lock(struct inode *inode, int lock_lsm)
1464 struct ll_inode_info *lli;
1465 struct lov_stripe_md *lsm;
1467 lli = ll_i2info(inode);
1468 LASSERT(lli->lli_size_sem_owner != current);
1469 down(&lli->lli_size_sem);
1470 LASSERT(lli->lli_size_sem_owner == NULL);
1471 lli->lli_size_sem_owner = current;
1473 LASSERTF(lsm != NULL || lock_lsm == 0, "lsm %p, lock_lsm %d\n",
1476 lov_stripe_lock(lsm);
1479 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm)
1481 struct ll_inode_info *lli;
1482 struct lov_stripe_md *lsm;
1484 lli = ll_i2info(inode);
1486 LASSERTF(lsm != NULL || unlock_lsm == 0, "lsm %p, lock_lsm %d\n",
1489 lov_stripe_unlock(lsm);
1490 LASSERT(lli->lli_size_sem_owner == current);
1491 lli->lli_size_sem_owner = NULL;
1492 up(&lli->lli_size_sem);
1495 static void ll_replace_lsm(struct inode *inode, struct lov_stripe_md *lsm)
1497 struct ll_inode_info *lli = ll_i2info(inode);
1499 dump_lsm(D_INODE, lsm);
1500 dump_lsm(D_INODE, lli->lli_smd);
1501 LASSERTF(lsm->lsm_magic == LOV_MAGIC_JOIN,
1502 "lsm must be joined lsm %p\n", lsm);
1503 obd_free_memmd(ll_i2obdexp(inode), &lli->lli_smd);
1504 CDEBUG(D_INODE, "replace lsm %p to lli_smd %p for inode %lu%u(%p)\n",
1505 lsm, lli->lli_smd, inode->i_ino, inode->i_generation, inode);
1507 lli->lli_maxbytes = lsm->lsm_maxbytes;
1508 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1509 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1512 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1514 struct ll_inode_info *lli = ll_i2info(inode);
1515 struct mds_body *body = md->body;
1516 struct lov_stripe_md *lsm = md->lsm;
1518 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1520 if (lli->lli_smd == NULL) {
1521 if (lsm->lsm_magic != LOV_MAGIC &&
1522 lsm->lsm_magic != LOV_MAGIC_JOIN) {
1523 dump_lsm(D_ERROR, lsm);
1526 CDEBUG(D_INODE, "adding lsm %p to inode %lu/%u(%p)\n",
1527 lsm, inode->i_ino, inode->i_generation, inode);
1528 /* ll_inode_size_lock() requires it is only called
1529 * with lli_smd != NULL or lock_lsm == 0 or we can
1530 * race between lock/unlock. bug 9547 */
1532 lli->lli_maxbytes = lsm->lsm_maxbytes;
1533 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1534 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1536 if (lli->lli_smd->lsm_magic == lsm->lsm_magic &&
1537 lli->lli_smd->lsm_stripe_count ==
1538 lsm->lsm_stripe_count) {
1539 if (lov_stripe_md_cmp(lli->lli_smd, lsm)) {
1540 CERROR("lsm mismatch for inode %ld\n",
1542 CERROR("lli_smd:\n");
1543 dump_lsm(D_ERROR, lli->lli_smd);
1545 dump_lsm(D_ERROR, lsm);
1549 ll_replace_lsm(inode, lsm);
1551 if (lli->lli_smd != lsm)
1552 obd_free_memmd(ll_i2obdexp(inode), &lsm);
1555 #ifdef CONFIG_FS_POSIX_ACL
1556 LASSERT(!md->posix_acl || (body->valid & OBD_MD_FLACL));
1557 if (body->valid & OBD_MD_FLACL) {
1558 spin_lock(&lli->lli_lock);
1559 if (lli->lli_posix_acl)
1560 posix_acl_release(lli->lli_posix_acl);
1561 lli->lli_posix_acl = md->posix_acl;
1562 spin_unlock(&lli->lli_lock);
1566 if (body->valid & OBD_MD_FLID)
1567 inode->i_ino = body->ino;
1568 if (body->valid & OBD_MD_FLATIME &&
1569 body->atime > LTIME_S(inode->i_atime))
1570 LTIME_S(inode->i_atime) = body->atime;
1572 /* mtime is always updated with ctime, but can be set in past.
1573 As write and utime(2) may happen within 1 second, and utime's
1574 mtime has a priority over write's one, so take mtime from mds
1575 for the same ctimes. */
1576 if (body->valid & OBD_MD_FLCTIME &&
1577 body->ctime >= LTIME_S(inode->i_ctime)) {
1578 LTIME_S(inode->i_ctime) = body->ctime;
1579 if (body->valid & OBD_MD_FLMTIME) {
1580 CDEBUG(D_INODE, "setting ino %lu mtime "
1581 "from %lu to "LPU64"\n", inode->i_ino,
1582 LTIME_S(inode->i_mtime), body->mtime);
1583 LTIME_S(inode->i_mtime) = body->mtime;
1586 if (body->valid & OBD_MD_FLMODE)
1587 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1588 if (body->valid & OBD_MD_FLTYPE)
1589 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1590 if (S_ISREG(inode->i_mode)) {
1591 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
1593 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
1595 #ifdef HAVE_INODE_BLKSIZE
1596 inode->i_blksize = 1<<inode->i_blkbits;
1598 if (body->valid & OBD_MD_FLUID)
1599 inode->i_uid = body->uid;
1600 if (body->valid & OBD_MD_FLGID)
1601 inode->i_gid = body->gid;
1602 if (body->valid & OBD_MD_FLFLAGS)
1603 inode->i_flags = ll_ext_to_inode_flags(body->flags);
1604 if (body->valid & OBD_MD_FLNLINK)
1605 inode->i_nlink = body->nlink;
1606 if (body->valid & OBD_MD_FLGENER)
1607 inode->i_generation = body->generation;
1608 if (body->valid & OBD_MD_FLRDEV)
1609 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1610 inode->i_rdev = body->rdev;
1612 inode->i_rdev = old_decode_dev(body->rdev);
1614 if (body->valid & OBD_MD_FLSIZE)
1615 inode->i_size = body->size;
1616 if (body->valid & OBD_MD_FLBLOCKS)
1617 inode->i_blocks = body->blocks;
1619 if (body->valid & OBD_MD_FLSIZE)
1620 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1623 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
1624 static struct backing_dev_info ll_backing_dev_info = {
1625 .ra_pages = 0, /* No readahead */
1626 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
1627 .capabilities = 0, /* Does contribute to dirty memory */
1629 .memory_backed = 0, /* Does contribute to dirty memory */
1634 void ll_read_inode2(struct inode *inode, void *opaque)
1636 struct lustre_md *md = opaque;
1637 struct ll_inode_info *lli = ll_i2info(inode);
1640 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1641 inode->i_generation, inode);
1645 LASSERT(!lli->lli_smd);
1647 /* Core attributes from the MDS first. This is a new inode, and
1648 * the VFS doesn't zero times in the core inode so we have to do
1649 * it ourselves. They will be overwritten by either MDS or OST
1650 * attributes - we just need to make sure they aren't newer. */
1651 LTIME_S(inode->i_mtime) = 0;
1652 LTIME_S(inode->i_atime) = 0;
1653 LTIME_S(inode->i_ctime) = 0;
1655 ll_update_inode(inode, md);
1657 /* OIDEBUG(inode); */
1659 if (S_ISREG(inode->i_mode)) {
1660 struct ll_sb_info *sbi = ll_i2sbi(inode);
1661 inode->i_op = &ll_file_inode_operations;
1662 inode->i_fop = sbi->ll_fop;
1663 inode->i_mapping->a_ops = &ll_aops;
1665 } else if (S_ISDIR(inode->i_mode)) {
1666 inode->i_op = &ll_dir_inode_operations;
1667 inode->i_fop = &ll_dir_operations;
1668 inode->i_mapping->a_ops = &ll_dir_aops;
1670 } else if (S_ISLNK(inode->i_mode)) {
1671 inode->i_op = &ll_fast_symlink_inode_operations;
1674 inode->i_op = &ll_special_inode_operations;
1676 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1677 init_special_inode(inode, inode->i_mode,
1678 kdev_t_to_nr(inode->i_rdev));
1680 /* initializing backing dev info. */
1681 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
1683 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1689 int ll_iocontrol(struct inode *inode, struct file *file,
1690 unsigned int cmd, unsigned long arg)
1692 struct ll_sb_info *sbi = ll_i2sbi(inode);
1693 struct ptlrpc_request *req = NULL;
1698 case EXT3_IOC_GETFLAGS: {
1700 struct mds_body *body;
1702 ll_inode2fid(&fid, inode);
1703 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, OBD_MD_FLFLAGS,0,&req);
1705 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1709 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1712 /* We want to return EXT3_*_FL flags to the caller via this
1713 * ioctl. An older MDS may be sending S_* flags, fix it up. */
1714 flags = ll_inode_to_ext_flags(body->flags, body->flags);
1715 ptlrpc_req_finished (req);
1717 RETURN(put_user(flags, (int *)arg));
1719 case EXT3_IOC_SETFLAGS: {
1720 struct mdc_op_data op_data;
1721 struct ll_iattr_struct attr;
1722 struct obd_info oinfo = { { { 0 } } };
1723 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1725 if (get_user(flags, (int *)arg))
1729 oinfo.oi_oa = obdo_alloc();
1733 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
1735 memset(&attr, 0, sizeof(attr));
1736 attr.ia_attr_flags = flags;
1737 ((struct iattr *)&attr)->ia_valid |= ATTR_ATTR_FLAG;
1739 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
1740 (struct iattr *)&attr, NULL, 0, NULL, 0, &req);
1741 ptlrpc_req_finished(req);
1742 if (rc || lsm == NULL) {
1743 obdo_free(oinfo.oi_oa);
1747 oinfo.oi_oa->o_id = lsm->lsm_object_id;
1748 oinfo.oi_oa->o_flags = flags;
1749 oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS;
1751 obdo_from_inode(oinfo.oi_oa, inode,
1752 OBD_MD_FLFID | OBD_MD_FLGENER);
1753 rc = obd_setattr_rqset(sbi->ll_osc_exp, &oinfo, NULL);
1754 obdo_free(oinfo.oi_oa);
1756 if (rc != -EPERM && rc != -EACCES)
1757 CERROR("mdc_setattr_async fails: rc = %d\n", rc);
1761 inode->i_flags = ll_ext_to_inode_flags(flags |
1762 MDS_BFLAG_EXT_FLAGS);
1772 /* umount -f client means force down, don't save state */
1773 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
1774 void ll_umount_begin(struct vfsmount *vfsmnt, int flags)
1776 struct super_block *sb = vfsmnt->mnt_sb;
1778 void ll_umount_begin(struct super_block *sb)
1781 struct lustre_sb_info *lsi = s2lsi(sb);
1782 struct ll_sb_info *sbi = ll_s2sbi(sb);
1783 struct obd_device *obd;
1784 struct obd_ioctl_data ioc_data = { 0 };
1787 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
1788 if (!(flags & MNT_FORCE)) {
1794 /* Tell the MGC we got umount -f */
1795 lsi->lsi_flags |= LSI_UMOUNT_FORCE;
1797 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
1798 sb->s_count, atomic_read(&sb->s_active));
1800 obd = class_exp2obd(sbi->ll_mdc_exp);
1802 CERROR("Invalid MDC connection handle "LPX64"\n",
1803 sbi->ll_mdc_exp->exp_handle.h_cookie);
1807 obd->obd_no_recov = 1;
1808 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_mdc_exp, sizeof ioc_data,
1811 obd = class_exp2obd(sbi->ll_osc_exp);
1813 CERROR("Invalid LOV connection handle "LPX64"\n",
1814 sbi->ll_osc_exp->exp_handle.h_cookie);
1819 obd->obd_no_recov = 1;
1820 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_osc_exp, sizeof ioc_data,
1823 /* Really, we'd like to wait until there are no requests outstanding,
1824 * and then continue. For now, we just invalidate the requests,
1825 * schedule, and hope.
1832 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
1834 struct ll_sb_info *sbi = ll_s2sbi(sb);
1838 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
1839 read_only = *flags & MS_RDONLY;
1840 err = obd_set_info_async(sbi->ll_mdc_exp, strlen("read-only"),
1841 "read-only", sizeof(read_only),
1844 CERROR("Failed to change the read-only flag during "
1845 "remount: %d\n", err);
1850 sb->s_flags |= MS_RDONLY;
1852 sb->s_flags &= ~MS_RDONLY;
1857 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
1858 struct ptlrpc_request *req, int offset,struct super_block *sb)
1860 struct lustre_md md;
1861 struct ll_sb_info *sbi = NULL;
1865 LASSERT(*inode || sb);
1866 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
1867 prune_deathrow(sbi, 1);
1869 rc = mdc_req2lustre_md(req, offset, exp, &md);
1874 ll_update_inode(*inode, &md);
1877 *inode = ll_iget(sb, md.body->ino, &md);
1878 if (*inode == NULL || is_bad_inode(*inode)) {
1879 mdc_free_lustre_md(exp, &md);
1881 CERROR("new_inode -fatal: rc %d\n", rc);
1886 rc = obd_checkmd(exp, ll_i2mdcexp(*inode),
1887 ll_i2info(*inode)->lli_smd);
1892 char *llap_origins[] = {
1893 [LLAP_ORIGIN_UNKNOWN] = "--",
1894 [LLAP_ORIGIN_READPAGE] = "rp",
1895 [LLAP_ORIGIN_READAHEAD] = "ra",
1896 [LLAP_ORIGIN_COMMIT_WRITE] = "cw",
1897 [LLAP_ORIGIN_WRITEPAGE] = "wp",
1900 struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
1901 struct list_head *list)
1903 struct ll_async_page *llap;
1904 struct list_head *pos;
1906 list_for_each(pos, list) {
1907 if (pos == &sbi->ll_pglist)
1909 llap = list_entry(pos, struct ll_async_page, llap_pglist_item);
1910 if (llap->llap_page == NULL)
1918 int ll_obd_statfs(struct inode *inode, void *arg)
1920 struct ll_sb_info *sbi = NULL;
1921 struct obd_device *client_obd = NULL, *lov_obd = NULL;
1922 struct lov_obd *lov = NULL;
1923 struct obd_statfs stat_buf = {0};
1925 struct obd_ioctl_data *data = NULL;
1929 if (!inode || !(sbi = ll_i2sbi(inode)))
1930 GOTO(out_statfs, rc = -EINVAL);
1932 rc = obd_ioctl_getdata(&buf, &len, arg);
1934 GOTO(out_statfs, rc);
1937 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
1938 !data->ioc_pbuf1 || !data->ioc_pbuf2)
1939 GOTO(out_statfs, rc = -EINVAL);
1941 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
1942 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
1944 if (type == LL_STATFS_MDC) {
1946 GOTO(out_statfs, rc = -ENODEV);
1947 client_obd = class_exp2obd(sbi->ll_mdc_exp);
1948 } else if (type == LL_STATFS_LOV) {
1949 lov_obd = class_exp2obd(sbi->ll_osc_exp);
1950 lov = &lov_obd->u.lov;
1952 if (index >= lov->desc.ld_tgt_count)
1953 GOTO(out_statfs, rc = -ENODEV);
1955 if (!lov->lov_tgts[index])
1956 /* Try again with the next index */
1957 GOTO(out_statfs, rc = -EAGAIN);
1959 client_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
1960 if (!lov->lov_tgts[index]->ltd_active)
1961 GOTO(out_uuid, rc = -ENODATA);
1965 GOTO(out_statfs, rc = -EINVAL);
1967 rc = obd_statfs(client_obd, &stat_buf, cfs_time_current_64() - 1);
1969 GOTO(out_statfs, rc);
1971 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
1972 GOTO(out_statfs, rc = -EFAULT);
1975 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(client_obd),
1981 obd_ioctl_freedata(buf, len);
1985 int ll_process_config(struct lustre_cfg *lcfg)
1989 struct lprocfs_static_vars lvars;
1993 lprocfs_init_vars(llite, &lvars);
1995 /* The instance name contains the sb: lustre-client-aacfe000 */
1996 ptr = strrchr(lustre_cfg_string(lcfg, 0), '-');
1997 if (!ptr || !*(++ptr))
1999 if (sscanf(ptr, "%lx", &x) != 1)
2002 /* This better be a real Lustre superblock! */
2003 LASSERT(s2lsi((struct super_block *)sb)->lsi_lmd->lmd_magic == LMD_MAGIC);
2005 /* Note we have not called client_common_fill_super yet, so
2006 proc fns must be able to handle that! */
2007 rc = class_process_proc_param(PARAM_LLITE, lvars.obd_vars,