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 cfs_mem_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 spin_lock_init(&sbi->ll_pp_extent_lock);
66 spin_lock_init(&sbi->ll_process_lock);
67 sbi->ll_rw_stats_on = 0;
68 INIT_LIST_HEAD(&sbi->ll_pglist);
69 if (num_physpages >> (20 - CFS_PAGE_SHIFT) < 512)
70 sbi->ll_async_page_max = num_physpages / 2;
72 sbi->ll_async_page_max = (num_physpages / 4) * 3;
73 sbi->ll_ra_info.ra_max_pages = min(num_physpages / 8,
74 SBI_DEFAULT_READAHEAD_MAX);
75 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
76 SBI_DEFAULT_READAHEAD_WHOLE_MAX;
77 sbi->ll_contention_time = SBI_DEFAULT_CONTENTION_SECONDS;
78 INIT_LIST_HEAD(&sbi->ll_conn_chain);
79 INIT_LIST_HEAD(&sbi->ll_orphan_dentry_list);
81 ll_generate_random_uuid(uuid);
82 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
83 CDEBUG(D_CONFIG, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
85 spin_lock(&ll_sb_lock);
86 list_add_tail(&sbi->ll_list, &ll_super_blocks);
87 spin_unlock(&ll_sb_lock);
89 #ifdef ENABLE_CHECKSUM
90 sbi->ll_flags |= LL_SBI_CHECKSUM;
93 #ifdef HAVE_EXPORT___IGET
94 INIT_LIST_HEAD(&sbi->ll_deathrow);
95 spin_lock_init(&sbi->ll_deathrow_lock);
97 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
98 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_r_hist.oh_lock);
99 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_w_hist.oh_lock);
102 /* metadata statahead is enabled by default */
103 sbi->ll_sa_max = LL_STATAHEAD_DEF;
108 void ll_free_sbi(struct super_block *sb)
110 struct ll_sb_info *sbi = ll_s2sbi(sb);
114 spin_lock(&ll_sb_lock);
115 list_del(&sbi->ll_list);
116 spin_unlock(&ll_sb_lock);
117 OBD_FREE(sbi, sizeof(*sbi));
122 static struct dentry_operations ll_d_root_ops = {
123 #ifdef DCACHE_LUSTRE_INVALID
124 .d_compare = ll_dcompare,
128 static int client_common_fill_super(struct super_block *sb,
129 char *mdc, char *osc)
131 struct inode *root = 0;
132 struct ll_sb_info *sbi = ll_s2sbi(sb);
133 struct obd_device *obd;
134 struct ll_fid rootfid;
135 struct obd_statfs osfs;
136 struct ptlrpc_request *request = NULL;
137 struct lustre_handle osc_conn = {0, };
138 struct lustre_handle mdc_conn = {0, };
140 struct obd_connect_data *data = NULL;
144 obd = class_name2obd(mdc);
146 CERROR("MDC %s: not setup or attached\n", mdc);
150 OBD_ALLOC(data, sizeof(*data));
154 if (proc_lustre_fs_root) {
155 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
158 CERROR("could not register mount in /proc/lustre");
161 /* indicate the features supported by this client */
162 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_IBITS |
163 OBD_CONNECT_JOIN | OBD_CONNECT_ATTRFID | OBD_CONNECT_NODEVOH |
164 OBD_CONNECT_CANCELSET | OBD_CONNECT_AT;
165 #ifdef CONFIG_FS_POSIX_ACL
166 data->ocd_connect_flags |= OBD_CONNECT_ACL;
168 data->ocd_ibits_known = MDS_INODELOCK_FULL;
169 data->ocd_version = LUSTRE_VERSION_CODE;
171 if (sb->s_flags & MS_RDONLY)
172 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
173 if (sbi->ll_flags & LL_SBI_USER_XATTR)
174 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
176 #ifdef HAVE_MS_FLOCK_LOCK
177 /* force vfs to use lustre handler for flock() calls - bug 10743 */
178 sb->s_flags |= MS_FLOCK_LOCK;
181 if (sbi->ll_flags & LL_SBI_FLOCK)
182 sbi->ll_fop = &ll_file_operations_flock;
183 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
184 sbi->ll_fop = &ll_file_operations;
186 sbi->ll_fop = &ll_file_operations_noflock;
188 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid, data);
190 LCONSOLE_ERROR_MSG(0x14f, "An MDT (mdc %s) is performing "
191 "recovery, of which this client is not a "
192 "part. Please wait for recovery to complete,"
193 " abort, or time out.\n", mdc);
196 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
199 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
201 err = obd_statfs(obd, &osfs, cfs_time_current_64() - HZ);
205 /* MDC connect is surely finished by now because we actually sent
206 * a statfs RPC, otherwise obd_connect() is asynchronous. */
207 *data = class_exp2cliimp(sbi->ll_mdc_exp)->imp_connect_data;
209 LASSERT(osfs.os_bsize);
210 sb->s_blocksize = osfs.os_bsize;
211 sb->s_blocksize_bits = log2(osfs.os_bsize);
212 sb->s_magic = LL_SUPER_MAGIC;
214 /* for bug 11559. in $LINUX/fs/read_write.c, function do_sendfile():
215 * retval = in_file->f_op->sendfile(...);
217 * retval = -EOVERFLOW;
219 * it will check if *ppos is greater than max. However, max equals to
220 * s_maxbytes, which is a negative integer in a x86_64 box since loff_t
221 * has been defined as a signed long long ineger in linux kernel. */
222 #if BITS_PER_LONG == 64
223 sb->s_maxbytes = PAGE_CACHE_MAXBYTES >> 1;
225 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
227 sbi->ll_namelen = osfs.os_namelen;
228 sbi->ll_max_rw_chunk = LL_DEFAULT_MAX_RW_CHUNK;
230 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
231 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
232 LCONSOLE_INFO("Disabling user_xattr feature because "
233 "it is not supported on the server\n");
234 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
237 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
239 sb->s_flags |= MS_POSIXACL;
241 sbi->ll_flags |= LL_SBI_ACL;
243 sbi->ll_flags &= ~LL_SBI_ACL;
245 if (data->ocd_connect_flags & OBD_CONNECT_JOIN)
246 sbi->ll_flags |= LL_SBI_JOIN;
248 sbi->ll_sdev_orig = sb->s_dev;
249 /* We set sb->s_dev equal on all lustre clients in order to support
250 * NFS export clustering. NFSD requires that the FSID be the same
252 /* s_dev is also used in lt_compare() to compare two fs, but that is
253 * only a node-local comparison. */
254 sb->s_dev = get_uuid2int(sbi2mdc(sbi)->cl_target_uuid.uuid,
255 strlen(sbi2mdc(sbi)->cl_target_uuid.uuid));
256 obd = class_name2obd(osc);
258 CERROR("OSC %s: not setup or attached\n", osc);
259 GOTO(out_mdc, err = -ENODEV);
262 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_GRANT |
263 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
264 OBD_CONNECT_SRVLOCK | OBD_CONNECT_CANCELSET | OBD_CONNECT_AT;
266 CDEBUG(D_RPCTRACE, "ocd_connect_flags: "LPX64" ocd_version: %d "
267 "ocd_grant: %d\n", data->ocd_connect_flags,
268 data->ocd_version, data->ocd_grant);
270 obd->obd_upcall.onu_owner = &sbi->ll_lco;
271 obd->obd_upcall.onu_upcall = ll_ocd_update;
272 data->ocd_brw_size = PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT;
275 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid, data);
277 LCONSOLE_ERROR_MSG(0x150, "An OST (osc %s) is performing "
278 "recovery, of which this client is not a "
279 "part. Please wait for recovery to "
280 "complete, abort, or time out.\n", osc);
283 CERROR("cannot connect to %s: rc = %d\n", osc, err);
286 sbi->ll_osc_exp = class_conn2export(&osc_conn);
287 spin_lock(&sbi->ll_lco.lco_lock);
288 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
289 spin_unlock(&sbi->ll_lco.lco_lock);
291 mdc_init_ea_size(sbi->ll_mdc_exp, sbi->ll_osc_exp);
293 err = obd_prep_async_page(sbi->ll_osc_exp, NULL, NULL, NULL,
294 0, NULL, NULL, NULL);
296 LCONSOLE_ERROR_MSG(0x151, "There are no OST's in this "
297 "filesystem. There must be at least one "
298 "active OST for a client to start.\n");
302 if (!ll_async_page_slab) {
303 ll_async_page_slab_size =
304 size_round(sizeof(struct ll_async_page)) + err;
305 ll_async_page_slab = cfs_mem_cache_create("ll_async_page",
306 ll_async_page_slab_size,
308 if (!ll_async_page_slab)
309 GOTO(out_osc, -ENOMEM);
312 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
314 CERROR("cannot mds_connect: rc = %d\n", err);
317 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
318 sbi->ll_rootino = rootfid.id;
320 sb->s_op = &lustre_super_operations;
321 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
322 sb->s_export_op = &lustre_export_operations;
326 * XXX: move this to after cbd setup? */
327 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
328 OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS |
329 (sbi->ll_flags & LL_SBI_ACL ? OBD_MD_FLACL : 0),
332 CERROR("mdc_getattr failed for root: rc = %d\n", err);
336 err = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md);
338 CERROR("failed to understand root inode md: rc = %d\n",err);
339 ptlrpc_req_finished (request);
343 LASSERT(sbi->ll_rootino != 0);
344 root = ll_iget(sb, sbi->ll_rootino, &md);
346 ptlrpc_req_finished(request);
348 if (root == NULL || is_bad_inode(root)) {
349 mdc_free_lustre_md(sbi->ll_osc_exp, &md);
350 CERROR("lustre_lite: bad iget4 for root\n");
351 GOTO(out_root, err = -EBADF);
354 err = ll_close_thread_start(&sbi->ll_lcq);
356 CERROR("cannot start close thread: rc %d\n", err);
360 checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
361 err = obd_set_info_async(sbi->ll_osc_exp, strlen("checksum"),"checksum",
362 sizeof(checksum), &checksum, NULL);
364 /* making vm readahead 0 for 2.4.x. In the case of 2.6.x,
365 backing dev info assigned to inode mapping is used for
366 determining maximal readahead. */
367 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) && \
368 !defined(KERNEL_HAS_AS_MAX_READAHEAD)
369 /* bug 2805 - set VM readahead to zero */
370 vm_max_readahead = vm_min_readahead = 0;
373 sb->s_root = d_alloc_root(root);
375 OBD_FREE(data, sizeof(*data));
376 sb->s_root->d_op = &ll_d_root_ops;
383 obd_disconnect(sbi->ll_osc_exp);
384 sbi->ll_osc_exp = NULL;
386 obd_disconnect(sbi->ll_mdc_exp);
387 sbi->ll_mdc_exp = NULL;
390 OBD_FREE(data, sizeof(*data));
391 lprocfs_unregister_mountpoint(sbi);
395 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
399 *lmmsize = obd_size_diskmd(sbi->ll_osc_exp, NULL);
401 rc = obd_get_info(sbi->ll_mdc_exp, strlen("max_easize"), "max_easize",
404 CERROR("Get max mdsize error rc %d \n", rc);
409 void ll_dump_inode(struct inode *inode)
411 struct list_head *tmp;
412 int dentry_count = 0;
414 LASSERT(inode != NULL);
416 list_for_each(tmp, &inode->i_dentry)
419 CERROR("inode %p dump: dev=%s ino=%lu mode=%o count=%u, %d dentries\n",
420 inode, ll_i2mdcexp(inode)->exp_obd->obd_name, inode->i_ino,
421 inode->i_mode, atomic_read(&inode->i_count), dentry_count);
424 void lustre_dump_dentry(struct dentry *dentry, int recur)
426 struct list_head *tmp;
429 LASSERT(dentry != NULL);
431 list_for_each(tmp, &dentry->d_subdirs)
434 CERROR("dentry %p dump: name=%.*s parent=%.*s (%p), inode=%p, count=%u,"
435 " flags=0x%x, fsdata=%p, %d subdirs\n", dentry,
436 dentry->d_name.len, dentry->d_name.name,
437 dentry->d_parent->d_name.len, dentry->d_parent->d_name.name,
438 dentry->d_parent, dentry->d_inode, atomic_read(&dentry->d_count),
439 dentry->d_flags, dentry->d_fsdata, subdirs);
440 if (dentry->d_inode != NULL)
441 ll_dump_inode(dentry->d_inode);
446 list_for_each(tmp, &dentry->d_subdirs) {
447 struct dentry *d = list_entry(tmp, struct dentry, d_child);
448 lustre_dump_dentry(d, recur - 1);
452 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
453 void lustre_throw_orphan_dentries(struct super_block *sb)
455 struct dentry *dentry, *next;
456 struct ll_sb_info *sbi = ll_s2sbi(sb);
458 /* Do this to get rid of orphaned dentries. That is not really trw. */
459 list_for_each_entry_safe(dentry, next, &sbi->ll_orphan_dentry_list,
461 CWARN("found orphan dentry %.*s (%p->%p) at unmount, dumping "
462 "before and after shrink_dcache_parent\n",
463 dentry->d_name.len, dentry->d_name.name, dentry, next);
464 lustre_dump_dentry(dentry, 1);
465 shrink_dcache_parent(dentry);
466 lustre_dump_dentry(dentry, 1);
470 #define lustre_throw_orphan_dentries(sb)
473 #ifdef HAVE_EXPORT___IGET
474 static void prune_dir_dentries(struct inode *inode)
476 struct dentry *dentry, *prev = NULL;
478 /* due to lustre specific logic, a directory
479 * can have few dentries - a bug from VFS POV */
481 spin_lock(&dcache_lock);
482 if (!list_empty(&inode->i_dentry)) {
483 dentry = list_entry(inode->i_dentry.prev,
484 struct dentry, d_alias);
485 /* in order to prevent infinite loops we
486 * break if previous dentry is busy */
487 if (dentry != prev) {
490 spin_unlock(&dcache_lock);
492 /* try to kill all child dentries */
493 shrink_dcache_parent(dentry);
496 /* now try to get rid of current dentry */
497 d_prune_aliases(inode);
501 spin_unlock(&dcache_lock);
504 static void prune_deathrow_one(struct ll_inode_info *lli)
506 struct inode *inode = ll_info2i(lli);
508 /* first, try to drop any dentries - they hold a ref on the inode */
509 if (S_ISDIR(inode->i_mode))
510 prune_dir_dentries(inode);
512 d_prune_aliases(inode);
515 /* if somebody still uses it, leave it */
516 LASSERT(atomic_read(&inode->i_count) > 0);
517 if (atomic_read(&inode->i_count) > 1)
520 CDEBUG(D_INODE, "inode %lu/%u(%d) looks a good candidate for prune\n",
521 inode->i_ino,inode->i_generation, atomic_read(&inode->i_count));
523 /* seems nobody uses it anymore */
531 static void prune_deathrow(struct ll_sb_info *sbi, int try)
533 struct ll_inode_info *lli;
537 if (need_resched() && try)
541 if (!spin_trylock(&sbi->ll_deathrow_lock))
544 spin_lock(&sbi->ll_deathrow_lock);
549 if (!list_empty(&sbi->ll_deathrow)) {
550 lli = list_entry(sbi->ll_deathrow.next,
551 struct ll_inode_info,
553 list_del_init(&lli->lli_dead_list);
554 if (!list_empty(&sbi->ll_deathrow))
557 spin_unlock(&sbi->ll_deathrow_lock);
560 prune_deathrow_one(lli);
562 } while (empty == 0);
564 #else /* !HAVE_EXPORT___IGET */
565 #define prune_deathrow(sbi, try) do {} while (0)
566 #endif /* HAVE_EXPORT___IGET */
568 void client_common_put_super(struct super_block *sb)
570 struct ll_sb_info *sbi = ll_s2sbi(sb);
573 ll_close_thread_shutdown(sbi->ll_lcq);
575 lprocfs_unregister_mountpoint(sbi);
577 /* destroy inodes in deathrow */
578 prune_deathrow(sbi, 0);
580 list_del(&sbi->ll_conn_chain);
581 obd_disconnect(sbi->ll_osc_exp);
582 sbi->ll_osc_exp = NULL;
584 obd_disconnect(sbi->ll_mdc_exp);
585 sbi->ll_mdc_exp = NULL;
587 lustre_throw_orphan_dentries(sb);
588 /* restore s_dev from changed for clustred NFS*/
589 sb->s_dev = sbi->ll_sdev_orig;
594 char *ll_read_opt(const char *opt, char *data)
600 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
601 if (strncmp(opt, data, strlen(opt)))
603 if ((value = strchr(data, '=')) == NULL)
607 OBD_ALLOC(retval, strlen(value) + 1);
609 CERROR("out of memory!\n");
613 memcpy(retval, value, strlen(value)+1);
614 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
618 static inline int ll_set_opt(const char *opt, char *data, int fl)
620 if (strncmp(opt, data, strlen(opt)) != 0)
626 /* non-client-specific mount options are parsed in lmd_parse */
627 static int ll_options(char *options, int *flags)
630 char *s1 = options, *s2;
636 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
639 CDEBUG(D_SUPER, "next opt=%s\n", s1);
640 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
645 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
650 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
655 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
660 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
665 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
670 tmp = ll_set_opt("acl", s1, LL_SBI_ACL);
672 /* Ignore deprecated mount option. The client will
673 * always try to mount with ACL support, whether this
674 * is used depends on whether server supports it. */
677 tmp = ll_set_opt("noacl", s1, LL_SBI_ACL);
682 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
687 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
693 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
699 s2 = strchr(s1, ',');
707 void ll_lli_init(struct ll_inode_info *lli)
709 lli->lli_inode_magic = LLI_INODE_MAGIC;
710 sema_init(&lli->lli_size_sem, 1);
711 sema_init(&lli->lli_write_sem, 1);
713 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
714 spin_lock_init(&lli->lli_lock);
715 sema_init(&lli->lli_och_sem, 1);
716 lli->lli_mds_read_och = lli->lli_mds_write_och = NULL;
717 lli->lli_mds_exec_och = NULL;
718 lli->lli_open_fd_read_count = lli->lli_open_fd_write_count = 0;
719 lli->lli_open_fd_exec_count = 0;
720 INIT_LIST_HEAD(&lli->lli_dead_list);
721 #ifdef HAVE_CLOSE_THREAD
722 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
727 #define MDCDEV "mdc_dev"
728 static int old_lustre_process_log(struct super_block *sb, char *newprofile,
729 struct config_llog_instance *cfg)
731 struct lustre_sb_info *lsi = s2lsi(sb);
732 struct obd_device *obd;
733 struct lustre_handle mdc_conn = {0, };
734 struct obd_export *exp;
735 char *ptr, *mdt, *profile;
736 char niduuid[10] = "mdtnid0";
738 struct obd_uuid mdc_uuid;
739 struct llog_ctxt *ctxt;
740 struct obd_connect_data ocd = { 0 };
742 int i, rc = 0, recov_bk = 1, failnodes = 0;
745 ll_generate_random_uuid(uuid);
746 class_uuid_unparse(uuid, &mdc_uuid);
747 CDEBUG(D_HA, "generated uuid: %s\n", mdc_uuid.uuid);
749 /* Figure out the old mdt and profile name from new-style profile
750 ("lustre" from "mds/lustre-client") */
752 profile = strchr(mdt, '/');
753 if (profile == NULL) {
754 CDEBUG(D_CONFIG, "Can't find MDT name in %s\n", newprofile);
755 GOTO(out, rc = -EINVAL);
759 ptr = strrchr(profile, '-');
761 CDEBUG(D_CONFIG, "Can't find client name in %s\n", newprofile);
762 GOTO(out, rc = -EINVAL);
766 LCONSOLE_WARN("This looks like an old mount command; I will try to "
767 "contact MDT '%s' for profile '%s'\n", mdt, profile);
769 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
771 ptr = lsi->lsi_lmd->lmd_dev;
772 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
773 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid, 0,0,0);
775 /* Stop at the first failover nid */
780 CERROR("No valid MDT nids found.\n");
781 GOTO(out, rc = -EINVAL);
785 rc = do_lcfg(MDCDEV, 0, LCFG_ATTACH, LUSTRE_MDC_NAME,mdc_uuid.uuid,0,0);
787 GOTO(out_del_uuid, rc);
789 rc = do_lcfg(MDCDEV, 0, LCFG_SETUP, mdt, niduuid, 0, 0);
791 LCONSOLE_ERROR_MSG(0x153, "I couldn't establish a connection "
792 "with the MDT. Check that the MDT host NID "
793 "is correct and the networks are up.\n");
794 GOTO(out_detach, rc);
797 obd = class_name2obd(MDCDEV);
799 GOTO(out_cleanup, rc = -EINVAL);
801 /* Add any failover nids */
802 while (*ptr == ':') {
803 /* New failover node */
804 sprintf(niduuid, "mdtnid%d", failnodes);
806 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
808 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid,0,0,0);
810 CERROR("Add uuid for %s failed %d\n",
811 libcfs_nid2str(nid), rc);
816 rc = do_lcfg(MDCDEV, 0, LCFG_ADD_CONN, niduuid, 0, 0,0);
818 CERROR("Add conn for %s failed %d\n",
819 libcfs_nid2str(nid), rc);
827 /* Try all connections, but only once. */
828 rc = obd_set_info_async(obd->obd_self_export,
829 strlen("init_recov_bk"), "init_recov_bk",
830 sizeof(recov_bk), &recov_bk, NULL);
832 GOTO(out_cleanup, rc);
834 /* If we don't have this then an ACL MDS will refuse the connection */
835 ocd.ocd_connect_flags = OBD_CONNECT_ACL;
837 rc = obd_connect(&mdc_conn, obd, &mdc_uuid, &ocd);
839 CERROR("cannot connect to %s: rc = %d\n", mdt, rc);
840 GOTO(out_cleanup, rc);
843 exp = class_conn2export(&mdc_conn);
845 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
847 cfg->cfg_flags |= CFG_F_COMPAT146;
850 rc = class_config_parse_llog(ctxt, profile, cfg);
853 * For debugging, it's useful to just dump the log
855 rc = class_config_dump_llog(ctxt, profile, cfg);
860 /* Set the caller's profile name to the old-style */
861 memcpy(newprofile, profile, strlen(profile) + 1);
865 LCONSOLE_ERROR_MSG(0x154, "%s: The configuration '%s' could not"
866 " be read from the MDT '%s'. Make sure this"
867 " client and the MDT are running compatible "
868 "versions of Lustre.\n",
869 obd->obd_name, profile, mdt);
872 LCONSOLE_ERROR_MSG(0x155, "%s: The configuration '%s' could not"
873 " be read from the MDT '%s'. This may be "
874 "the result of communication errors between "
875 "the client and the MDT, or if the MDT is "
876 "not running.\n", obd->obd_name, profile,
881 /* We don't so much care about errors in cleaning up the config llog
882 * connection, as we have already read the config by this point. */
886 do_lcfg(MDCDEV, 0, LCFG_CLEANUP, 0, 0, 0, 0);
889 do_lcfg(MDCDEV, 0, LCFG_DETACH, 0, 0, 0, 0);
892 /* class_add_uuid adds a nid even if the same uuid exists; we might
893 delete any copy here. So they all better match. */
894 for (i = 0; i < failnodes; i++) {
895 sprintf(niduuid, "mdtnid%d", i);
896 do_lcfg(MDCDEV, 0, LCFG_DEL_UUID, niduuid, 0, 0, 0);
898 /* class_import_put will get rid of the additional connections */
904 int ll_fill_super(struct super_block *sb)
906 struct lustre_profile *lprof;
907 struct lustre_sb_info *lsi = s2lsi(sb);
908 struct ll_sb_info *sbi;
909 char *osc = NULL, *mdc = NULL;
910 char *profilenm = get_profile_name(sb);
911 struct config_llog_instance cfg = {0, };
912 char ll_instance[sizeof(sb) * 2 + 1];
916 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
920 /* client additional sb info */
921 lsi->lsi_llsbi = sbi = ll_init_sbi();
927 err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
931 /* Generate a string unique to this super, in case some joker tries
932 to mount the same fs at two mount points.
933 Use the address of the super itself.*/
934 sprintf(ll_instance, "%p", sb);
935 cfg.cfg_instance = ll_instance;
936 cfg.cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
938 /* set up client obds */
939 if (strchr(profilenm, '/') != NULL) /* COMPAT_146 */
940 err = -EINVAL; /* skip error messages, use old config code */
942 err = lustre_process_log(sb, profilenm, &cfg);
947 oldnamelen = strlen(profilenm) + 1;
948 /* Temp storage for 1.4.6 profile name */
949 OBD_ALLOC(oldname, oldnamelen);
951 memcpy(oldname, profilenm, oldnamelen);
952 rc = old_lustre_process_log(sb, oldname, &cfg);
954 /* That worked - update the profile name
957 OBD_FREE(lsi->lsi_lmd->lmd_profile,
958 strlen(lsi->lsi_lmd->lmd_profile) + 1);
959 OBD_ALLOC(lsi->lsi_lmd->lmd_profile,
960 strlen(oldname) + 1);
961 if (!lsi->lsi_lmd->lmd_profile) {
962 OBD_FREE(oldname, oldnamelen);
963 GOTO(out_free, err = -ENOMEM);
965 memcpy(lsi->lsi_lmd->lmd_profile, oldname,
966 strlen(oldname) + 1);
967 profilenm = get_profile_name(sb);
968 /* Don't ever try to recover the MGS */
969 rc = ptlrpc_set_import_active(
970 lsi->lsi_mgc->u.cli.cl_import, 0);
972 OBD_FREE(oldname, oldnamelen);
977 CERROR("Unable to process log: %d\n", err);
981 lprof = class_get_profile(profilenm);
983 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
984 " read from the MGS. Does that filesystem "
985 "exist?\n", profilenm);
986 GOTO(out_free, err = -EINVAL);
988 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
989 lprof->lp_mdc, lprof->lp_osc);
991 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
992 strlen(ll_instance) + 2);
994 GOTO(out_free, err = -ENOMEM);
995 sprintf(osc, "%s-%s", lprof->lp_osc, ll_instance);
997 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
998 strlen(ll_instance) + 2);
1000 GOTO(out_free, err = -ENOMEM);
1001 sprintf(mdc, "%s-%s", lprof->lp_mdc, ll_instance);
1003 /* connections, registrations, sb setup */
1004 err = client_common_fill_super(sb, mdc, osc);
1008 OBD_FREE(mdc, strlen(mdc) + 1);
1010 OBD_FREE(osc, strlen(osc) + 1);
1014 LCONSOLE_WARN("Client %s has started\n", profilenm);
1017 } /* ll_fill_super */
1020 void ll_put_super(struct super_block *sb)
1022 struct config_llog_instance cfg;
1023 char ll_instance[sizeof(sb) * 2 + 1];
1024 struct obd_device *obd;
1025 struct lustre_sb_info *lsi = s2lsi(sb);
1026 struct ll_sb_info *sbi = ll_s2sbi(sb);
1027 char *profilenm = get_profile_name(sb);
1028 int force = 1, next;
1031 CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
1033 sprintf(ll_instance, "%p", sb);
1034 cfg.cfg_instance = ll_instance;
1035 lustre_end_log(sb, NULL, &cfg);
1037 if (sbi->ll_mdc_exp) {
1038 obd = class_exp2obd(sbi->ll_mdc_exp);
1040 force = obd->obd_force;
1043 /* We need to set force before the lov_disconnect in
1044 lustre_common_put_super, since l_d cleans up osc's as well. */
1047 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1049 obd->obd_force = force;
1054 /* Only if client_common_fill_super succeeded */
1055 client_common_put_super(sb);
1059 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) !=NULL) {
1060 class_manual_cleanup(obd);
1064 class_del_profile(profilenm);
1067 lsi->lsi_llsbi = NULL;
1069 lustre_common_put_super(sb);
1071 LCONSOLE_WARN("client %s umount complete\n", ll_instance);
1076 } /* client_put_super */
1078 #ifdef HAVE_REGISTER_CACHE
1079 #include <linux/cache_def.h>
1080 #ifdef HAVE_CACHE_RETURN_INT
1085 ll_shrink_cache(int priority, unsigned int gfp_mask)
1087 struct ll_sb_info *sbi;
1090 list_for_each_entry(sbi, &ll_super_blocks, ll_list)
1091 count += llap_shrink_cache(sbi, priority);
1093 #ifdef HAVE_CACHE_RETURN_INT
1098 struct cache_definition ll_cache_definition = {
1099 .name = "llap_cache",
1100 .shrink = ll_shrink_cache
1102 #endif /* HAVE_REGISTER_CACHE */
1104 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
1106 struct inode *inode = NULL;
1107 /* NOTE: we depend on atomic igrab() -bzzz */
1108 lock_res_and_lock(lock);
1109 if (lock->l_ast_data) {
1110 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
1111 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1112 inode = igrab(lock->l_ast_data);
1114 inode = lock->l_ast_data;
1115 ldlm_lock_debug(NULL, inode->i_state & I_FREEING ?
1117 lock, __FILE__, __func__, __LINE__,
1118 "l_ast_data %p is bogus: magic %08x",
1119 lock->l_ast_data, lli->lli_inode_magic);
1123 unlock_res_and_lock(lock);
1127 static int null_if_equal(struct ldlm_lock *lock, void *data)
1129 if (data == lock->l_ast_data) {
1130 lock->l_ast_data = NULL;
1132 if (lock->l_req_mode != lock->l_granted_mode)
1133 LDLM_ERROR(lock,"clearing inode with ungranted lock");
1136 return LDLM_ITER_CONTINUE;
1139 void ll_clear_inode(struct inode *inode)
1142 struct ll_inode_info *lli = ll_i2info(inode);
1143 struct ll_sb_info *sbi = ll_i2sbi(inode);
1146 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1147 inode->i_generation, inode);
1149 if (S_ISDIR(inode->i_mode)) {
1150 /* these should have been cleared in ll_file_release */
1151 LASSERT(lli->lli_sai == NULL);
1152 LASSERT(lli->lli_opendir_pid == 0);
1155 ll_inode2fid(&fid, inode);
1156 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1157 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
1159 LASSERT(!lli->lli_open_fd_write_count);
1160 LASSERT(!lli->lli_open_fd_read_count);
1161 LASSERT(!lli->lli_open_fd_exec_count);
1163 if (lli->lli_mds_write_och)
1164 ll_mdc_real_close(inode, FMODE_WRITE);
1165 if (lli->lli_mds_exec_och) {
1167 CERROR("No FMODE exec, bug exec och is present for "
1168 "inode %ld\n", inode->i_ino);
1169 ll_mdc_real_close(inode, FMODE_EXEC);
1171 if (lli->lli_mds_read_och)
1172 ll_mdc_real_close(inode, FMODE_READ);
1176 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
1177 null_if_equal, inode);
1179 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
1180 lli->lli_smd = NULL;
1183 if (lli->lli_symlink_name) {
1184 OBD_FREE(lli->lli_symlink_name,
1185 strlen(lli->lli_symlink_name) + 1);
1186 lli->lli_symlink_name = NULL;
1189 #ifdef CONFIG_FS_POSIX_ACL
1190 if (lli->lli_posix_acl) {
1191 LASSERT(atomic_read(&lli->lli_posix_acl->a_refcount) == 1);
1192 posix_acl_release(lli->lli_posix_acl);
1193 lli->lli_posix_acl = NULL;
1197 lli->lli_inode_magic = LLI_INODE_DEAD;
1199 #ifdef HAVE_EXPORT___IGET
1200 spin_lock(&sbi->ll_deathrow_lock);
1201 list_del_init(&lli->lli_dead_list);
1202 spin_unlock(&sbi->ll_deathrow_lock);
1208 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1209 * object(s) determine the file size and mtime. Otherwise, the MDS will
1210 * keep these values until such a time that objects are allocated for it.
1211 * We do the MDS operations first, as it is checking permissions for us.
1212 * We don't to the MDS RPC if there is nothing that we want to store there,
1213 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1214 * going to do an RPC anyways.
1216 * If we are doing a truncate, we will send the mtime and ctime updates
1217 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1218 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1221 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
1223 struct ll_inode_info *lli = ll_i2info(inode);
1224 struct lov_stripe_md *lsm = lli->lli_smd;
1225 struct ll_sb_info *sbi = ll_i2sbi(inode);
1226 struct ptlrpc_request *request = NULL;
1227 struct mdc_op_data op_data;
1228 struct lustre_md md;
1229 int ia_valid = attr->ia_valid;
1233 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu valid %x\n", inode->i_ino,
1235 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_SETATTR, 1);
1237 if (ia_valid & ATTR_SIZE) {
1238 if (attr->ia_size > ll_file_maxbytes(inode)) {
1239 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
1240 attr->ia_size, ll_file_maxbytes(inode));
1244 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1247 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1248 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
1249 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1253 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1254 if (attr->ia_valid & ATTR_CTIME) {
1255 attr->ia_ctime = CURRENT_TIME;
1256 attr->ia_valid |= ATTR_CTIME_SET;
1258 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
1259 attr->ia_atime = CURRENT_TIME;
1260 attr->ia_valid |= ATTR_ATIME_SET;
1262 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
1263 attr->ia_mtime = CURRENT_TIME;
1264 attr->ia_valid |= ATTR_MTIME_SET;
1266 if ((attr->ia_valid & ATTR_CTIME) && !(attr->ia_valid & ATTR_MTIME)) {
1267 /* To avoid stale mtime on mds, obtain it from ost and send
1269 rc = ll_glimpse_size(inode, 0);
1273 attr->ia_valid |= ATTR_MTIME_SET | ATTR_MTIME;
1274 attr->ia_mtime = inode->i_mtime;
1277 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1278 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
1279 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1282 /* NB: ATTR_SIZE will only be set after this point if the size
1283 * resides on the MDS, ie, this file has no objects. */
1285 attr->ia_valid &= ~ATTR_SIZE;
1287 /* We always do an MDS RPC, even if we're only changing the size;
1288 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
1289 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0, NULL);
1291 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
1292 attr, NULL, 0, NULL, 0, &request);
1295 ptlrpc_req_finished(request);
1296 if (rc == -ENOENT) {
1298 /* Unlinked special device node? Or just a race?
1299 * Pretend we done everything. */
1300 if (!S_ISREG(inode->i_mode) &&
1301 !S_ISDIR(inode->i_mode))
1302 rc = inode_setattr(inode, attr);
1303 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY)
1304 CERROR("mdc_setattr fails: rc = %d\n", rc);
1308 rc = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md);
1310 ptlrpc_req_finished(request);
1314 /* We call inode_setattr to adjust timestamps.
1315 * If there is at least some data in file, we cleared ATTR_SIZE above to
1316 * avoid invoking vmtruncate, otherwise it is important to call
1317 * vmtruncate in inode_setattr to update inode->i_size (bug 6196) */
1318 rc = inode_setattr(inode, attr);
1320 ll_update_inode(inode, &md);
1321 ptlrpc_req_finished(request);
1323 if (!lsm || !S_ISREG(inode->i_mode)) {
1324 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
1328 /* We really need to get our PW lock before we change inode->i_size.
1329 * If we don't we can race with other i_size updaters on our node, like
1330 * ll_file_read. We can also race with i_size propogation to other
1331 * nodes through dirtying and writeback of final cached pages. This
1332 * last one is especially bad for racing o_append users on other
1334 if (ia_valid & ATTR_SIZE) {
1335 int srvlock = !!(sbi->ll_lco.lco_flags & OBD_CONNECT_TRUNCLOCK);
1336 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
1338 struct lustre_handle lockh = { 0 };
1342 int flags = LDLM_FL_BLOCK_GRANTED;
1344 rc = obd_match(ll_i2sbi(inode)->ll_osc_exp,
1346 &policy, LCK_PW, &flags, inode,
1354 UNLOCK_INODE_MUTEX(inode);
1355 UP_WRITE_I_ALLOC_SEM(inode);
1358 rc = ll_file_punch(inode, attr->ia_size, 1);
1364 /* XXX when we fix the AST intents to pass the discard-range
1365 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
1367 if (attr->ia_size == 0)
1368 ast_flags = LDLM_AST_DISCARD_DATA;
1370 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy,
1376 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1377 DOWN_WRITE_I_ALLOC_SEM(inode);
1378 LOCK_INODE_MUTEX(inode);
1380 LOCK_INODE_MUTEX(inode);
1381 DOWN_WRITE_I_ALLOC_SEM(inode);
1383 /* Only ll_inode_size_lock is taken at this level.
1384 * lov_stripe_lock() is grabbed by ll_truncate() only over
1385 * call to obd_adjust_kms(). If vmtruncate returns 0, then
1386 * ll_truncate dropped ll_inode_size_lock() */
1387 ll_inode_size_lock(inode, 0);
1389 set_bit(LLI_F_SRVLOCK, &lli->lli_flags);
1390 rc = vmtruncate(inode, attr->ia_size);
1391 clear_bit(LLI_F_SRVLOCK, &lli->lli_flags);
1393 LASSERT(atomic_read(&lli->lli_size_sem.count) <= 0);
1394 ll_inode_size_unlock(inode, 0);
1398 err = ll_extent_unlock(NULL, inode, lsm,
1401 CERROR("ll_extent_unlock failed: %d\n", err);
1406 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
1408 struct obd_info oinfo = { { { 0 } } };
1412 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1413 inode->i_ino, LTIME_S(attr->ia_mtime));
1416 oa->o_id = lsm->lsm_object_id;
1417 oa->o_valid = OBD_MD_FLID;
1419 flags = OBD_MD_FLTYPE | OBD_MD_FLATIME |
1420 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1421 OBD_MD_FLFID | OBD_MD_FLGENER;
1423 obdo_from_inode(oa, inode, flags);
1428 rc = obd_setattr_rqset(sbi->ll_osc_exp, &oinfo, NULL);
1430 CERROR("obd_setattr_async fails: rc=%d\n", rc);
1439 int ll_setattr(struct dentry *de, struct iattr *attr)
1441 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1442 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1443 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1445 return ll_setattr_raw(de->d_inode, attr);
1448 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1451 struct ll_sb_info *sbi = ll_s2sbi(sb);
1452 struct obd_statfs obd_osfs;
1456 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
1458 CERROR("mdc_statfs fails: rc = %d\n", rc);
1462 osfs->os_type = sb->s_magic;
1464 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1465 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1467 rc = obd_statfs_rqset(class_exp2obd(sbi->ll_osc_exp),
1468 &obd_osfs, max_age);
1470 CERROR("obd_statfs fails: rc = %d\n", rc);
1474 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1475 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1478 osfs->os_bsize = obd_osfs.os_bsize;
1479 osfs->os_blocks = obd_osfs.os_blocks;
1480 osfs->os_bfree = obd_osfs.os_bfree;
1481 osfs->os_bavail = obd_osfs.os_bavail;
1483 /* If we don't have as many objects free on the OST as inodes
1484 * on the MDS, we reduce the total number of inodes to
1485 * compensate, so that the "inodes in use" number is correct.
1487 if (obd_osfs.os_ffree < osfs->os_ffree) {
1488 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1490 osfs->os_ffree = obd_osfs.os_ffree;
1495 #ifndef HAVE_STATFS_DENTRY_PARAM
1496 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1499 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1501 struct super_block *sb = de->d_sb;
1503 struct obd_statfs osfs;
1506 CDEBUG(D_VFSTRACE, "VFS Op: at "LPU64" jiffies\n", get_jiffies_64());
1507 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1);
1509 /* For now we will always get up-to-date statfs values, but in the
1510 * future we may allow some amount of caching on the client (e.g.
1511 * from QOS or lprocfs updates). */
1512 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - 1);
1516 statfs_unpack(sfs, &osfs);
1518 /* We need to downshift for all 32-bit kernels, because we can't
1519 * tell if the kernel is being called via sys_statfs64() or not.
1520 * Stop before overflowing f_bsize - in which case it is better
1521 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
1522 if (sizeof(long) < 8) {
1523 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1526 osfs.os_blocks >>= 1;
1527 osfs.os_bfree >>= 1;
1528 osfs.os_bavail >>= 1;
1532 sfs->f_blocks = osfs.os_blocks;
1533 sfs->f_bfree = osfs.os_bfree;
1534 sfs->f_bavail = osfs.os_bavail;
1539 void ll_inode_size_lock(struct inode *inode, int lock_lsm)
1541 struct ll_inode_info *lli;
1542 struct lov_stripe_md *lsm;
1544 lli = ll_i2info(inode);
1545 LASSERT(lli->lli_size_sem_owner != current);
1546 down(&lli->lli_size_sem);
1547 LASSERT(lli->lli_size_sem_owner == NULL);
1548 lli->lli_size_sem_owner = current;
1550 LASSERTF(lsm != NULL || lock_lsm == 0, "lsm %p, lock_lsm %d\n",
1553 lov_stripe_lock(lsm);
1556 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm)
1558 struct ll_inode_info *lli;
1559 struct lov_stripe_md *lsm;
1561 lli = ll_i2info(inode);
1563 LASSERTF(lsm != NULL || unlock_lsm == 0, "lsm %p, lock_lsm %d\n",
1566 lov_stripe_unlock(lsm);
1567 LASSERT(lli->lli_size_sem_owner == current);
1568 lli->lli_size_sem_owner = NULL;
1569 up(&lli->lli_size_sem);
1572 static void ll_replace_lsm(struct inode *inode, struct lov_stripe_md *lsm)
1574 struct ll_inode_info *lli = ll_i2info(inode);
1576 dump_lsm(D_INODE, lsm);
1577 dump_lsm(D_INODE, lli->lli_smd);
1578 LASSERTF(lsm->lsm_magic == LOV_MAGIC_JOIN,
1579 "lsm must be joined lsm %p\n", lsm);
1580 obd_free_memmd(ll_i2obdexp(inode), &lli->lli_smd);
1581 CDEBUG(D_INODE, "replace lsm %p to lli_smd %p for inode %lu%u(%p)\n",
1582 lsm, lli->lli_smd, inode->i_ino, inode->i_generation, inode);
1584 lli->lli_maxbytes = lsm->lsm_maxbytes;
1585 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1586 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1589 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1591 struct ll_inode_info *lli = ll_i2info(inode);
1592 struct mds_body *body = md->body;
1593 struct lov_stripe_md *lsm = md->lsm;
1595 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1597 if (lli->lli_smd == NULL) {
1598 if (lsm->lsm_magic != LOV_MAGIC &&
1599 lsm->lsm_magic != LOV_MAGIC_JOIN) {
1600 dump_lsm(D_ERROR, lsm);
1603 CDEBUG(D_INODE, "adding lsm %p to inode %lu/%u(%p)\n",
1604 lsm, inode->i_ino, inode->i_generation, inode);
1605 /* ll_inode_size_lock() requires it is only called
1606 * with lli_smd != NULL or lock_lsm == 0 or we can
1607 * race between lock/unlock. bug 9547 */
1609 lli->lli_maxbytes = lsm->lsm_maxbytes;
1610 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1611 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1613 if (lli->lli_smd->lsm_magic == lsm->lsm_magic &&
1614 lli->lli_smd->lsm_stripe_count ==
1615 lsm->lsm_stripe_count) {
1616 if (lov_stripe_md_cmp(lli->lli_smd, lsm)) {
1617 CERROR("lsm mismatch for inode %ld\n",
1619 CERROR("lli_smd:\n");
1620 dump_lsm(D_ERROR, lli->lli_smd);
1622 dump_lsm(D_ERROR, lsm);
1626 ll_replace_lsm(inode, lsm);
1628 if (lli->lli_smd != lsm)
1629 obd_free_memmd(ll_i2obdexp(inode), &lsm);
1632 #ifdef CONFIG_FS_POSIX_ACL
1633 LASSERT(!md->posix_acl || (body->valid & OBD_MD_FLACL));
1634 if (body->valid & OBD_MD_FLACL) {
1635 spin_lock(&lli->lli_lock);
1636 if (lli->lli_posix_acl)
1637 posix_acl_release(lli->lli_posix_acl);
1638 lli->lli_posix_acl = md->posix_acl;
1639 spin_unlock(&lli->lli_lock);
1643 if (body->valid & OBD_MD_FLID)
1644 inode->i_ino = body->ino;
1645 if (body->valid & OBD_MD_FLATIME &&
1646 body->atime > LTIME_S(inode->i_atime))
1647 LTIME_S(inode->i_atime) = body->atime;
1649 /* mtime is always updated with ctime, but can be set in past.
1650 As write and utime(2) may happen within 1 second, and utime's
1651 mtime has a priority over write's one, so take mtime from mds
1652 for the same ctimes. */
1653 if (body->valid & OBD_MD_FLCTIME &&
1654 body->ctime >= LTIME_S(inode->i_ctime)) {
1655 LTIME_S(inode->i_ctime) = body->ctime;
1656 if (body->valid & OBD_MD_FLMTIME) {
1657 CDEBUG(D_INODE, "setting ino %lu mtime "
1658 "from %lu to "LPU64"\n", inode->i_ino,
1659 LTIME_S(inode->i_mtime), body->mtime);
1660 LTIME_S(inode->i_mtime) = body->mtime;
1663 if (body->valid & OBD_MD_FLMODE)
1664 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1665 if (body->valid & OBD_MD_FLTYPE)
1666 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1667 if (S_ISREG(inode->i_mode)) {
1668 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
1670 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
1672 #ifdef HAVE_INODE_BLKSIZE
1673 inode->i_blksize = 1<<inode->i_blkbits;
1675 if (body->valid & OBD_MD_FLUID)
1676 inode->i_uid = body->uid;
1677 if (body->valid & OBD_MD_FLGID)
1678 inode->i_gid = body->gid;
1679 if (body->valid & OBD_MD_FLFLAGS)
1680 inode->i_flags = ll_ext_to_inode_flags(body->flags);
1681 if (body->valid & OBD_MD_FLNLINK)
1682 inode->i_nlink = body->nlink;
1683 if (body->valid & OBD_MD_FLGENER)
1684 inode->i_generation = body->generation;
1685 if (body->valid & OBD_MD_FLRDEV)
1686 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1687 inode->i_rdev = body->rdev;
1689 inode->i_rdev = old_decode_dev(body->rdev);
1691 if (body->valid & OBD_MD_FLSIZE)
1692 inode->i_size = body->size;
1693 if (body->valid & OBD_MD_FLBLOCKS)
1694 inode->i_blocks = body->blocks;
1696 if (body->valid & OBD_MD_FLSIZE)
1697 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1700 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
1701 static struct backing_dev_info ll_backing_dev_info = {
1702 .ra_pages = 0, /* No readahead */
1703 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
1704 .capabilities = 0, /* Does contribute to dirty memory */
1706 .memory_backed = 0, /* Does contribute to dirty memory */
1711 void ll_read_inode2(struct inode *inode, void *opaque)
1713 struct lustre_md *md = opaque;
1714 struct ll_inode_info *lli = ll_i2info(inode);
1717 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1718 inode->i_generation, inode);
1722 LASSERT(!lli->lli_smd);
1724 /* Core attributes from the MDS first. This is a new inode, and
1725 * the VFS doesn't zero times in the core inode so we have to do
1726 * it ourselves. They will be overwritten by either MDS or OST
1727 * attributes - we just need to make sure they aren't newer. */
1728 LTIME_S(inode->i_mtime) = 0;
1729 LTIME_S(inode->i_atime) = 0;
1730 LTIME_S(inode->i_ctime) = 0;
1732 ll_update_inode(inode, md);
1734 /* OIDEBUG(inode); */
1736 if (S_ISREG(inode->i_mode)) {
1737 struct ll_sb_info *sbi = ll_i2sbi(inode);
1738 inode->i_op = &ll_file_inode_operations;
1739 inode->i_fop = sbi->ll_fop;
1740 inode->i_mapping->a_ops = &ll_aops;
1742 } else if (S_ISDIR(inode->i_mode)) {
1743 inode->i_op = &ll_dir_inode_operations;
1744 inode->i_fop = &ll_dir_operations;
1745 inode->i_mapping->a_ops = &ll_dir_aops;
1747 } else if (S_ISLNK(inode->i_mode)) {
1748 inode->i_op = &ll_fast_symlink_inode_operations;
1751 inode->i_op = &ll_special_inode_operations;
1753 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1754 init_special_inode(inode, inode->i_mode,
1755 kdev_t_to_nr(inode->i_rdev));
1757 /* initializing backing dev info. */
1758 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
1760 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1766 int ll_iocontrol(struct inode *inode, struct file *file,
1767 unsigned int cmd, unsigned long arg)
1769 struct ll_sb_info *sbi = ll_i2sbi(inode);
1770 struct ptlrpc_request *req = NULL;
1775 case EXT3_IOC_GETFLAGS: {
1777 struct mds_body *body;
1779 ll_inode2fid(&fid, inode);
1780 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, OBD_MD_FLFLAGS,0,&req);
1782 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1786 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1789 /* We want to return EXT3_*_FL flags to the caller via this
1790 * ioctl. An older MDS may be sending S_* flags, fix it up. */
1791 flags = ll_inode_to_ext_flags(body->flags,
1792 body->flags & MDS_BFLAG_EXT_FLAGS);
1793 ptlrpc_req_finished (req);
1795 RETURN(put_user(flags, (int *)arg));
1797 case EXT3_IOC_SETFLAGS: {
1798 struct mdc_op_data op_data;
1799 struct ll_iattr_struct attr;
1800 struct obd_info oinfo = { { { 0 } } };
1801 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1803 if (get_user(flags, (int *)arg))
1807 OBDO_ALLOC(oinfo.oi_oa);
1811 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0, NULL);
1813 memset(&attr, 0, sizeof(attr));
1814 attr.ia_attr_flags = flags;
1815 ((struct iattr *)&attr)->ia_valid |= ATTR_ATTR_FLAG;
1817 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
1818 (struct iattr *)&attr, NULL, 0, NULL, 0, &req);
1819 ptlrpc_req_finished(req);
1820 if (rc || lsm == NULL) {
1821 OBDO_FREE(oinfo.oi_oa);
1825 oinfo.oi_oa->o_id = lsm->lsm_object_id;
1826 oinfo.oi_oa->o_flags = flags;
1827 oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS;
1829 obdo_from_inode(oinfo.oi_oa, inode,
1830 OBD_MD_FLFID | OBD_MD_FLGENER);
1831 rc = obd_setattr_rqset(sbi->ll_osc_exp, &oinfo, NULL);
1832 OBDO_FREE(oinfo.oi_oa);
1834 if (rc != -EPERM && rc != -EACCES)
1835 CERROR("mdc_setattr_async fails: rc = %d\n", rc);
1839 inode->i_flags = ll_ext_to_inode_flags(flags |
1840 MDS_BFLAG_EXT_FLAGS);
1850 /* umount -f client means force down, don't save state */
1851 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
1852 void ll_umount_begin(struct vfsmount *vfsmnt, int flags)
1854 struct super_block *sb = vfsmnt->mnt_sb;
1856 void ll_umount_begin(struct super_block *sb)
1859 struct lustre_sb_info *lsi = s2lsi(sb);
1860 struct ll_sb_info *sbi = ll_s2sbi(sb);
1861 struct obd_device *obd;
1862 struct obd_ioctl_data ioc_data = { 0 };
1865 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
1866 if (!(flags & MNT_FORCE)) {
1872 /* Tell the MGC we got umount -f */
1873 lsi->lsi_flags |= LSI_UMOUNT_FORCE;
1875 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
1876 sb->s_count, atomic_read(&sb->s_active));
1878 obd = class_exp2obd(sbi->ll_mdc_exp);
1880 CERROR("Invalid MDC connection handle "LPX64"\n",
1881 sbi->ll_mdc_exp->exp_handle.h_cookie);
1886 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_mdc_exp, sizeof ioc_data,
1889 obd = class_exp2obd(sbi->ll_osc_exp);
1891 CERROR("Invalid LOV connection handle "LPX64"\n",
1892 sbi->ll_osc_exp->exp_handle.h_cookie);
1898 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_osc_exp, sizeof ioc_data,
1901 /* Really, we'd like to wait until there are no requests outstanding,
1902 * and then continue. For now, we just invalidate the requests,
1903 * schedule, and hope.
1910 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
1912 struct ll_sb_info *sbi = ll_s2sbi(sb);
1916 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
1917 read_only = *flags & MS_RDONLY;
1918 err = obd_set_info_async(sbi->ll_mdc_exp, strlen("read-only"),
1919 "read-only", sizeof(read_only),
1922 CERROR("Failed to change the read-only flag during "
1923 "remount: %d\n", err);
1928 sb->s_flags |= MS_RDONLY;
1930 sb->s_flags &= ~MS_RDONLY;
1935 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
1936 struct ptlrpc_request *req, int offset,struct super_block *sb)
1938 struct lustre_md md;
1939 struct ll_sb_info *sbi = NULL;
1943 LASSERT(*inode || sb);
1944 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
1945 prune_deathrow(sbi, 1);
1947 rc = mdc_req2lustre_md(req, offset, exp, &md);
1952 ll_update_inode(*inode, &md);
1955 *inode = ll_iget(sb, md.body->ino, &md);
1956 if (*inode == NULL || is_bad_inode(*inode)) {
1957 mdc_free_lustre_md(exp, &md);
1959 CERROR("new_inode -fatal: rc %d\n", rc);
1964 rc = obd_checkmd(exp, ll_i2mdcexp(*inode),
1965 ll_i2info(*inode)->lli_smd);
1970 char *llap_origins[] = {
1971 [LLAP_ORIGIN_UNKNOWN] = "--",
1972 [LLAP_ORIGIN_READPAGE] = "rp",
1973 [LLAP_ORIGIN_READAHEAD] = "ra",
1974 [LLAP_ORIGIN_COMMIT_WRITE] = "cw",
1975 [LLAP_ORIGIN_WRITEPAGE] = "wp",
1976 [LLAP_ORIGIN_LOCKLESS_IO] = "ls"
1979 struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
1980 struct list_head *list)
1982 struct ll_async_page *llap;
1983 struct list_head *pos;
1985 list_for_each(pos, list) {
1986 if (pos == &sbi->ll_pglist)
1988 llap = list_entry(pos, struct ll_async_page, llap_pglist_item);
1989 if (llap->llap_page == NULL)
1997 int ll_obd_statfs(struct inode *inode, void *arg)
1999 struct ll_sb_info *sbi = NULL;
2000 struct obd_device *client_obd = NULL, *lov_obd = NULL;
2001 struct lov_obd *lov = NULL;
2002 struct obd_statfs stat_buf = {0};
2004 struct obd_ioctl_data *data = NULL;
2008 if (!inode || !(sbi = ll_i2sbi(inode)))
2009 GOTO(out_statfs, rc = -EINVAL);
2011 rc = obd_ioctl_getdata(&buf, &len, arg);
2013 GOTO(out_statfs, rc);
2016 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2017 !data->ioc_pbuf1 || !data->ioc_pbuf2)
2018 GOTO(out_statfs, rc = -EINVAL);
2020 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2021 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
2023 if (type == LL_STATFS_MDC) {
2025 GOTO(out_statfs, rc = -ENODEV);
2026 client_obd = class_exp2obd(sbi->ll_mdc_exp);
2027 } else if (type == LL_STATFS_LOV) {
2028 lov_obd = class_exp2obd(sbi->ll_osc_exp);
2029 lov = &lov_obd->u.lov;
2031 if (index >= lov->desc.ld_tgt_count)
2032 GOTO(out_statfs, rc = -ENODEV);
2034 if (!lov->lov_tgts[index])
2035 /* Try again with the next index */
2036 GOTO(out_statfs, rc = -EAGAIN);
2038 client_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
2039 if (!lov->lov_tgts[index]->ltd_active)
2040 GOTO(out_uuid, rc = -ENODATA);
2044 GOTO(out_statfs, rc = -EINVAL);
2046 rc = obd_statfs(client_obd, &stat_buf, cfs_time_current_64() - 1);
2048 GOTO(out_statfs, rc);
2050 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
2051 GOTO(out_statfs, rc = -EFAULT);
2054 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(client_obd),
2060 obd_ioctl_freedata(buf, len);
2064 int ll_process_config(struct lustre_cfg *lcfg)
2068 struct lprocfs_static_vars lvars;
2072 lprocfs_init_vars(llite, &lvars);
2074 /* The instance name contains the sb: lustre-client-aacfe000 */
2075 ptr = strrchr(lustre_cfg_string(lcfg, 0), '-');
2076 if (!ptr || !*(++ptr))
2078 if (sscanf(ptr, "%lx", &x) != 1)
2081 /* This better be a real Lustre superblock! */
2082 LASSERT(s2lsi((struct super_block *)sb)->lsi_lmd->lmd_magic == LMD_MAGIC);
2084 /* Note we have not called client_common_fill_super yet, so
2085 proc fns must be able to handle that! */
2086 rc = class_process_proc_param(PARAM_LLITE, lvars.obd_vars,