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 <lustre_cache.h>
38 #include "llite_internal.h"
40 cfs_mem_cache_t *ll_file_data_slab;
42 LIST_HEAD(ll_super_blocks);
43 spinlock_t ll_sb_lock = SPIN_LOCK_UNLOCKED;
45 extern struct address_space_operations ll_aops;
46 extern struct address_space_operations ll_dir_aops;
49 #define log2(n) ffz(~(n))
53 static struct ll_sb_info *ll_init_sbi(void)
55 struct ll_sb_info *sbi = NULL;
60 OBD_ALLOC(sbi, sizeof(*sbi));
64 spin_lock_init(&sbi->ll_lock);
65 spin_lock_init(&sbi->ll_lco.lco_lock);
66 spin_lock_init(&sbi->ll_pp_extent_lock);
67 spin_lock_init(&sbi->ll_process_lock);
68 sbi->ll_rw_stats_on = 0;
69 INIT_LIST_HEAD(&sbi->ll_pglist);
70 if (num_physpages >> (20 - CFS_PAGE_SHIFT) < 512)
71 sbi->ll_async_page_max = num_physpages / 2;
73 sbi->ll_async_page_max = (num_physpages / 4) * 3;
74 sbi->ll_ra_info.ra_max_pages = min(num_physpages / 8,
75 SBI_DEFAULT_READAHEAD_MAX);
76 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
77 SBI_DEFAULT_READAHEAD_WHOLE_MAX;
78 sbi->ll_contention_time = SBI_DEFAULT_CONTENTION_SECONDS;
79 sbi->ll_lockless_truncate_enable = SBI_DEFAULT_LOCKLESS_TRUNCATE_ENABLE;
80 INIT_LIST_HEAD(&sbi->ll_conn_chain);
81 INIT_LIST_HEAD(&sbi->ll_orphan_dentry_list);
83 ll_generate_random_uuid(uuid);
84 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
85 CDEBUG(D_CONFIG, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
87 spin_lock(&ll_sb_lock);
88 list_add_tail(&sbi->ll_list, &ll_super_blocks);
89 spin_unlock(&ll_sb_lock);
91 #ifdef ENABLE_CHECKSUM
92 sbi->ll_flags |= LL_SBI_DATA_CHECKSUM;
94 #ifdef ENABLE_LLITE_CHECKSUM
95 sbi->ll_flags |= LL_SBI_LLITE_CHECKSUM;
98 #ifdef HAVE_LRU_RESIZE_SUPPORT
99 sbi->ll_flags |= LL_SBI_LRU_RESIZE;
102 #ifdef HAVE_EXPORT___IGET
103 INIT_LIST_HEAD(&sbi->ll_deathrow);
104 spin_lock_init(&sbi->ll_deathrow_lock);
106 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
107 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_r_hist.oh_lock);
108 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_w_hist.oh_lock);
111 /* metadata statahead is enabled by default */
112 sbi->ll_sa_max = LL_SA_RPC_DEF;
117 void ll_free_sbi(struct super_block *sb)
119 struct ll_sb_info *sbi = ll_s2sbi(sb);
123 spin_lock(&ll_sb_lock);
124 list_del(&sbi->ll_list);
125 spin_unlock(&ll_sb_lock);
126 OBD_FREE(sbi, sizeof(*sbi));
131 static struct dentry_operations ll_d_root_ops = {
132 #ifdef DCACHE_LUSTRE_INVALID
133 .d_compare = ll_dcompare,
137 static int client_common_fill_super(struct super_block *sb,
138 char *mdc, char *osc)
140 struct inode *root = 0;
141 struct ll_sb_info *sbi = ll_s2sbi(sb);
142 struct obd_device *obd;
143 struct ll_fid rootfid;
144 struct obd_statfs osfs;
145 struct ptlrpc_request *request = NULL;
146 struct lustre_handle osc_conn = {0, };
147 struct lustre_handle mdc_conn = {0, };
149 struct obd_connect_data *data = NULL;
153 obd = class_name2obd(mdc);
155 CERROR("MDC %s: not setup or attached\n", mdc);
159 OBD_ALLOC(data, sizeof(*data));
163 if (proc_lustre_fs_root) {
164 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
167 CERROR("could not register mount in /proc/fs/lustre\n");
170 /* indicate the features supported by this client */
171 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_IBITS |
172 OBD_CONNECT_JOIN | OBD_CONNECT_ATTRFID | OBD_CONNECT_NODEVOH |
173 OBD_CONNECT_CANCELSET | OBD_CONNECT_AT;
174 #ifdef HAVE_LRU_RESIZE_SUPPORT
175 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
176 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
178 #ifdef CONFIG_FS_POSIX_ACL
179 data->ocd_connect_flags |= OBD_CONNECT_ACL;
181 data->ocd_ibits_known = MDS_INODELOCK_FULL;
182 data->ocd_version = LUSTRE_VERSION_CODE;
184 if (sb->s_flags & MS_RDONLY)
185 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
186 if (sbi->ll_flags & LL_SBI_USER_XATTR)
187 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
189 #ifdef HAVE_MS_FLOCK_LOCK
190 /* force vfs to use lustre handler for flock() calls - bug 10743 */
191 sb->s_flags |= MS_FLOCK_LOCK;
194 if (sbi->ll_flags & LL_SBI_FLOCK)
195 sbi->ll_fop = &ll_file_operations_flock;
196 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
197 sbi->ll_fop = &ll_file_operations;
199 sbi->ll_fop = &ll_file_operations_noflock;
201 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid, data, NULL);
203 LCONSOLE_ERROR_MSG(0x14f, "An MDT (mdc %s) is performing "
204 "recovery, of which this client is not a "
205 "part. Please wait for recovery to complete,"
206 " abort, or time out.\n", mdc);
209 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
212 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
214 err = obd_statfs(obd, &osfs, cfs_time_current_64() - HZ, 0);
218 /* MDC connect is surely finished by now because we actually sent
219 * a statfs RPC, otherwise obd_connect() is asynchronous. */
220 *data = class_exp2cliimp(sbi->ll_mdc_exp)->imp_connect_data;
222 LASSERT(osfs.os_bsize);
223 sb->s_blocksize = osfs.os_bsize;
224 sb->s_blocksize_bits = log2(osfs.os_bsize);
225 sb->s_magic = LL_SUPER_MAGIC;
227 /* for bug 11559. in $LINUX/fs/read_write.c, function do_sendfile():
228 * retval = in_file->f_op->sendfile(...);
230 * retval = -EOVERFLOW;
232 * it will check if *ppos is greater than max. However, max equals to
233 * s_maxbytes, which is a negative integer in a x86_64 box since loff_t
234 * has been defined as a signed long long ineger in linux kernel. */
235 #if BITS_PER_LONG == 64
236 sb->s_maxbytes = PAGE_CACHE_MAXBYTES >> 1;
238 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
240 sbi->ll_namelen = osfs.os_namelen;
241 sbi->ll_max_rw_chunk = LL_DEFAULT_MAX_RW_CHUNK;
243 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
244 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
245 LCONSOLE_INFO("Disabling user_xattr feature because "
246 "it is not supported on the server\n");
247 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
250 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
252 sb->s_flags |= MS_POSIXACL;
254 sbi->ll_flags |= LL_SBI_ACL;
256 sbi->ll_flags &= ~LL_SBI_ACL;
258 if (data->ocd_connect_flags & OBD_CONNECT_JOIN)
259 sbi->ll_flags |= LL_SBI_JOIN;
261 sbi->ll_sdev_orig = sb->s_dev;
262 /* We set sb->s_dev equal on all lustre clients in order to support
263 * NFS export clustering. NFSD requires that the FSID be the same
265 /* s_dev is also used in lt_compare() to compare two fs, but that is
266 * only a node-local comparison. */
267 sb->s_dev = get_uuid2int(sbi2mdc(sbi)->cl_target_uuid.uuid,
268 strlen(sbi2mdc(sbi)->cl_target_uuid.uuid));
269 obd = class_name2obd(osc);
271 CERROR("OSC %s: not setup or attached\n", osc);
272 GOTO(out_mdc, err = -ENODEV);
275 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_GRANT |
276 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
277 OBD_CONNECT_SRVLOCK | OBD_CONNECT_CANCELSET | OBD_CONNECT_AT |
278 OBD_CONNECT_TRUNCLOCK;
280 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_CKSUM)) {
281 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
282 * disabled by default, because it can still be enabled on the
283 * fly via /proc. As a consequence, we still need to come to an
284 * agreement on the supported algorithms at connect time */
285 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
287 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
288 data->ocd_cksum_types = OBD_CKSUM_ADLER;
290 /* send the list of supported checksum types */
291 data->ocd_cksum_types = OBD_CKSUM_ALL;
294 #ifdef HAVE_LRU_RESIZE_SUPPORT
295 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
296 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
299 CDEBUG(D_RPCTRACE, "ocd_connect_flags: "LPX64" ocd_version: %d "
300 "ocd_grant: %d\n", data->ocd_connect_flags,
301 data->ocd_version, data->ocd_grant);
303 obd->obd_upcall.onu_owner = &sbi->ll_lco;
304 obd->obd_upcall.onu_upcall = ll_ocd_update;
305 data->ocd_brw_size = PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT;
307 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid, data, NULL);
309 LCONSOLE_ERROR_MSG(0x150, "An OST (osc %s) is performing "
310 "recovery, of which this client is not a "
311 "part. Please wait for recovery to "
312 "complete, abort, or time out.\n", osc);
315 CERROR("cannot connect to %s: rc = %d\n", osc, err);
318 sbi->ll_osc_exp = class_conn2export(&osc_conn);
319 spin_lock(&sbi->ll_lco.lco_lock);
320 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
321 spin_unlock(&sbi->ll_lco.lco_lock);
323 err = obd_register_page_removal_cb(sbi->ll_osc_exp,
327 CERROR("cannot register page removal callback: rc = %d\n",err);
330 err = obd_register_lock_cancel_cb(sbi->ll_osc_exp,
331 ll_extent_lock_cancel_cb);
333 CERROR("cannot register lock cancel callback: rc = %d\n", err);
334 GOTO(out_page_rm_cb, err);
337 err = mdc_init_ea_size(sbi->ll_mdc_exp, sbi->ll_osc_exp);
339 CERROR("cannot set max EA and cookie sizes: rc = %d\n", err);
340 GOTO(out_lock_cn_cb, err);
343 err = obd_prep_async_page(sbi->ll_osc_exp, NULL, NULL, NULL,
344 0, NULL, NULL, NULL, 0, NULL);
346 LCONSOLE_ERROR_MSG(0x151, "There are no OST's in this "
347 "filesystem. There must be at least one "
348 "active OST for a client to start.\n");
349 GOTO(out_lock_cn_cb, err);
352 if (!ll_async_page_slab) {
353 ll_async_page_slab_size =
354 size_round(sizeof(struct ll_async_page)) + err;
355 ll_async_page_slab = cfs_mem_cache_create("ll_async_page",
356 ll_async_page_slab_size,
358 if (!ll_async_page_slab)
359 GOTO(out_lock_cn_cb, -ENOMEM);
362 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
364 CERROR("cannot mds_connect: rc = %d\n", err);
365 GOTO(out_lock_cn_cb, err);
367 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
368 sbi->ll_rootino = rootfid.id;
370 sb->s_op = &lustre_super_operations;
371 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
372 sb->s_export_op = &lustre_export_operations;
376 * XXX: move this to after cbd setup? */
377 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
378 OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS |
379 (sbi->ll_flags & LL_SBI_ACL ? OBD_MD_FLACL : 0),
382 CERROR("mdc_getattr failed for root: rc = %d\n", err);
383 GOTO(out_lock_cn_cb, err);
386 err = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md);
388 CERROR("failed to understand root inode md: rc = %d\n",err);
389 ptlrpc_req_finished (request);
390 GOTO(out_lock_cn_cb, err);
393 LASSERT(sbi->ll_rootino != 0);
394 root = ll_iget(sb, sbi->ll_rootino, &md);
396 ptlrpc_req_finished(request);
398 if (root == NULL || is_bad_inode(root)) {
399 mdc_free_lustre_md(sbi->ll_osc_exp, &md);
400 CERROR("lustre_lite: bad iget4 for root\n");
401 GOTO(out_root, err = -EBADF);
404 err = ll_close_thread_start(&sbi->ll_lcq);
406 CERROR("cannot start close thread: rc %d\n", err);
410 checksum = sbi->ll_flags & LL_SBI_DATA_CHECKSUM;
411 err = obd_set_info_async(sbi->ll_osc_exp, sizeof(KEY_CHECKSUM),
412 KEY_CHECKSUM, sizeof(checksum),
415 /* making vm readahead 0 for 2.4.x. In the case of 2.6.x,
416 backing dev info assigned to inode mapping is used for
417 determining maximal readahead. */
418 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) && \
419 !defined(KERNEL_HAS_AS_MAX_READAHEAD)
420 /* bug 2805 - set VM readahead to zero */
421 vm_max_readahead = vm_min_readahead = 0;
424 sb->s_root = d_alloc_root(root);
426 OBD_FREE(data, sizeof(*data));
427 sb->s_root->d_op = &ll_d_root_ops;
434 obd_unregister_lock_cancel_cb(sbi->ll_osc_exp,
435 ll_extent_lock_cancel_cb);
437 obd_unregister_page_removal_cb(sbi->ll_osc_exp,
440 obd_disconnect(sbi->ll_osc_exp);
441 sbi->ll_osc_exp = NULL;
443 obd_disconnect(sbi->ll_mdc_exp);
444 sbi->ll_mdc_exp = NULL;
447 OBD_FREE(data, sizeof(*data));
448 lprocfs_unregister_mountpoint(sbi);
452 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
456 *lmmsize = obd_size_diskmd(sbi->ll_osc_exp, NULL);
458 rc = obd_get_info(sbi->ll_mdc_exp, sizeof(KEY_MAX_EASIZE),
459 KEY_MAX_EASIZE, &size, lmmsize);
461 CERROR("Get max mdsize error rc %d \n", rc);
466 void ll_dump_inode(struct inode *inode)
468 struct list_head *tmp;
469 int dentry_count = 0;
471 LASSERT(inode != NULL);
473 list_for_each(tmp, &inode->i_dentry)
476 CERROR("inode %p dump: dev=%s ino=%lu mode=%o count=%u, %d dentries\n",
477 inode, ll_i2mdcexp(inode)->exp_obd->obd_name, inode->i_ino,
478 inode->i_mode, atomic_read(&inode->i_count), dentry_count);
481 void lustre_dump_dentry(struct dentry *dentry, int recur)
483 struct list_head *tmp;
486 LASSERT(dentry != NULL);
488 list_for_each(tmp, &dentry->d_subdirs)
491 CERROR("dentry %p dump: name=%.*s parent=%.*s (%p), inode=%p, count=%u,"
492 " flags=0x%x, fsdata=%p, %d subdirs\n", dentry,
493 dentry->d_name.len, dentry->d_name.name,
494 dentry->d_parent->d_name.len, dentry->d_parent->d_name.name,
495 dentry->d_parent, dentry->d_inode, atomic_read(&dentry->d_count),
496 dentry->d_flags, dentry->d_fsdata, subdirs);
497 if (dentry->d_inode != NULL)
498 ll_dump_inode(dentry->d_inode);
503 list_for_each(tmp, &dentry->d_subdirs) {
504 struct dentry *d = list_entry(tmp, struct dentry, d_child);
505 lustre_dump_dentry(d, recur - 1);
509 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
510 void lustre_throw_orphan_dentries(struct super_block *sb)
512 struct dentry *dentry, *next;
513 struct ll_sb_info *sbi = ll_s2sbi(sb);
515 /* Do this to get rid of orphaned dentries. That is not really trw. */
516 list_for_each_entry_safe(dentry, next, &sbi->ll_orphan_dentry_list,
518 CWARN("found orphan dentry %.*s (%p->%p) at unmount, dumping "
519 "before and after shrink_dcache_parent\n",
520 dentry->d_name.len, dentry->d_name.name, dentry, next);
521 lustre_dump_dentry(dentry, 1);
522 shrink_dcache_parent(dentry);
523 lustre_dump_dentry(dentry, 1);
527 #define lustre_throw_orphan_dentries(sb)
530 #ifdef HAVE_EXPORT___IGET
531 static void prune_dir_dentries(struct inode *inode)
533 struct dentry *dentry, *prev = NULL;
535 /* due to lustre specific logic, a directory
536 * can have few dentries - a bug from VFS POV */
538 spin_lock(&dcache_lock);
539 if (!list_empty(&inode->i_dentry)) {
540 dentry = list_entry(inode->i_dentry.prev,
541 struct dentry, d_alias);
542 /* in order to prevent infinite loops we
543 * break if previous dentry is busy */
544 if (dentry != prev) {
547 spin_unlock(&dcache_lock);
549 /* try to kill all child dentries */
550 shrink_dcache_parent(dentry);
553 /* now try to get rid of current dentry */
554 d_prune_aliases(inode);
558 spin_unlock(&dcache_lock);
561 static void prune_deathrow_one(struct ll_inode_info *lli)
563 struct inode *inode = ll_info2i(lli);
565 /* first, try to drop any dentries - they hold a ref on the inode */
566 if (S_ISDIR(inode->i_mode))
567 prune_dir_dentries(inode);
569 d_prune_aliases(inode);
572 /* if somebody still uses it, leave it */
573 LASSERT(atomic_read(&inode->i_count) > 0);
574 if (atomic_read(&inode->i_count) > 1)
577 CDEBUG(D_INODE, "inode %lu/%u(%d) looks a good candidate for prune\n",
578 inode->i_ino,inode->i_generation, atomic_read(&inode->i_count));
580 /* seems nobody uses it anymore */
588 static void prune_deathrow(struct ll_sb_info *sbi, int try)
590 struct ll_inode_info *lli;
594 if (need_resched() && try)
598 if (!spin_trylock(&sbi->ll_deathrow_lock))
601 spin_lock(&sbi->ll_deathrow_lock);
606 if (!list_empty(&sbi->ll_deathrow)) {
607 lli = list_entry(sbi->ll_deathrow.next,
608 struct ll_inode_info,
610 list_del_init(&lli->lli_dead_list);
611 if (!list_empty(&sbi->ll_deathrow))
614 spin_unlock(&sbi->ll_deathrow_lock);
617 prune_deathrow_one(lli);
619 } while (empty == 0);
621 #else /* !HAVE_EXPORT___IGET */
622 #define prune_deathrow(sbi, try) do {} while (0)
623 #endif /* HAVE_EXPORT___IGET */
625 void client_common_put_super(struct super_block *sb)
627 struct ll_sb_info *sbi = ll_s2sbi(sb);
630 ll_close_thread_shutdown(sbi->ll_lcq);
632 lprocfs_unregister_mountpoint(sbi);
634 /* destroy inodes in deathrow */
635 prune_deathrow(sbi, 0);
637 list_del(&sbi->ll_conn_chain);
639 /* callbacks is cleared after disconnect each target */
640 obd_disconnect(sbi->ll_osc_exp);
641 sbi->ll_osc_exp = NULL;
643 obd_disconnect(sbi->ll_mdc_exp);
644 sbi->ll_mdc_exp = NULL;
646 lustre_throw_orphan_dentries(sb);
651 void ll_kill_super(struct super_block *sb)
653 struct ll_sb_info *sbi;
658 if (!(sb->s_flags & MS_ACTIVE))
662 /* we need restore s_dev from changed for clustred NFS before put_super
663 * because new kernels have cached s_dev and change sb->s_dev in
664 * put_super not affected real removing devices */
666 sb->s_dev = sbi->ll_sdev_orig;
670 char *ll_read_opt(const char *opt, char *data)
676 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
677 if (strncmp(opt, data, strlen(opt)))
679 if ((value = strchr(data, '=')) == NULL)
683 OBD_ALLOC(retval, strlen(value) + 1);
685 CERROR("out of memory!\n");
689 memcpy(retval, value, strlen(value)+1);
690 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
694 static inline int ll_set_opt(const char *opt, char *data, int fl)
696 if (strncmp(opt, data, strlen(opt)) != 0)
702 /* non-client-specific mount options are parsed in lmd_parse */
703 static int ll_options(char *options, int *flags)
706 char *s1 = options, *s2;
712 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
715 CDEBUG(D_SUPER, "next opt=%s\n", s1);
716 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
721 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
726 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
731 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
736 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
741 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
746 tmp = ll_set_opt("acl", s1, LL_SBI_ACL);
748 /* Ignore deprecated mount option. The client will
749 * always try to mount with ACL support, whether this
750 * is used depends on whether server supports it. */
753 tmp = ll_set_opt("noacl", s1, LL_SBI_ACL);
758 tmp = ll_set_opt("checksum", s1, LL_SBI_DATA_CHECKSUM);
763 tmp = ll_set_opt("nochecksum", s1, LL_SBI_DATA_CHECKSUM);
769 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
774 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
779 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
785 s2 = strchr(s1, ',');
793 void ll_lli_init(struct ll_inode_info *lli)
795 lli->lli_inode_magic = LLI_INODE_MAGIC;
796 sema_init(&lli->lli_size_sem, 1);
797 sema_init(&lli->lli_write_sem, 1);
799 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
800 spin_lock_init(&lli->lli_lock);
801 sema_init(&lli->lli_och_sem, 1);
802 lli->lli_mds_read_och = lli->lli_mds_write_och = NULL;
803 lli->lli_mds_exec_och = NULL;
804 lli->lli_open_fd_read_count = lli->lli_open_fd_write_count = 0;
805 lli->lli_open_fd_exec_count = 0;
806 INIT_LIST_HEAD(&lli->lli_dead_list);
807 #ifdef HAVE_CLOSE_THREAD
808 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
813 #define MDCDEV "mdc_dev"
814 static int old_lustre_process_log(struct super_block *sb, char *newprofile,
815 struct config_llog_instance *cfg)
817 struct lustre_sb_info *lsi = s2lsi(sb);
818 struct obd_device *obd;
819 struct lustre_handle mdc_conn = {0, };
820 struct obd_export *exp;
821 char *ptr, *mdt, *profile;
822 char niduuid[10] = "mdtnid0";
824 struct obd_uuid mdc_uuid;
825 struct llog_ctxt *ctxt;
826 struct obd_connect_data ocd = { 0 };
828 int i, rc = 0, recov_bk = 1, failnodes = 0;
831 ll_generate_random_uuid(uuid);
832 class_uuid_unparse(uuid, &mdc_uuid);
833 CDEBUG(D_HA, "generated uuid: %s\n", mdc_uuid.uuid);
835 /* Figure out the old mdt and profile name from new-style profile
836 ("lustre" from "mds/lustre-client") */
838 profile = strchr(mdt, '/');
839 if (profile == NULL) {
840 CDEBUG(D_CONFIG, "Can't find MDT name in %s\n", newprofile);
841 GOTO(out, rc = -EINVAL);
845 ptr = strrchr(profile, '-');
847 CDEBUG(D_CONFIG, "Can't find client name in %s\n", newprofile);
848 GOTO(out, rc = -EINVAL);
852 LCONSOLE_WARN("This looks like an old mount command; I will try to "
853 "contact MDT '%s' for profile '%s'\n", mdt, profile);
855 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
857 ptr = lsi->lsi_lmd->lmd_dev;
858 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
859 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid, 0,0,0);
861 /* Stop at the first failover nid */
866 CERROR("No valid MDT nids found.\n");
867 GOTO(out, rc = -EINVAL);
871 rc = do_lcfg(MDCDEV, 0, LCFG_ATTACH, LUSTRE_MDC_NAME,mdc_uuid.uuid,0,0);
873 GOTO(out_del_uuid, rc);
875 rc = do_lcfg(MDCDEV, 0, LCFG_SETUP, mdt, niduuid, 0, 0);
877 LCONSOLE_ERROR_MSG(0x153, "I couldn't establish a connection "
878 "with the MDT. Check that the MDT host NID "
879 "is correct and the networks are up.\n");
880 GOTO(out_detach, rc);
883 obd = class_name2obd(MDCDEV);
885 GOTO(out_cleanup, rc = -EINVAL);
887 /* Add any failover nids */
888 while (*ptr == ':') {
889 /* New failover node */
890 sprintf(niduuid, "mdtnid%d", failnodes);
892 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
894 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid,0,0,0);
896 CERROR("Add uuid for %s failed %d\n",
897 libcfs_nid2str(nid), rc);
902 rc = do_lcfg(MDCDEV, 0, LCFG_ADD_CONN, niduuid, 0, 0,0);
904 CERROR("Add conn for %s failed %d\n",
905 libcfs_nid2str(nid), rc);
913 /* Try all connections, but only once. */
914 rc = obd_set_info_async(obd->obd_self_export,
915 sizeof(KEY_INIT_RECOV_BACKUP), KEY_INIT_RECOV_BACKUP,
916 sizeof(recov_bk), &recov_bk, NULL);
918 GOTO(out_cleanup, rc);
920 /* If we don't have this then an ACL MDS will refuse the connection */
921 ocd.ocd_connect_flags = OBD_CONNECT_ACL;
923 rc = obd_connect(&mdc_conn, obd, &mdc_uuid, &ocd, NULL);
925 CERROR("cannot connect to %s: rc = %d\n", mdt, rc);
926 GOTO(out_cleanup, rc);
929 exp = class_conn2export(&mdc_conn);
931 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
933 cfg->cfg_flags |= CFG_F_COMPAT146;
936 rc = class_config_parse_llog(ctxt, profile, cfg);
939 * For debugging, it's useful to just dump the log
941 rc = class_config_dump_llog(ctxt, profile, cfg);
946 /* Set the caller's profile name to the old-style */
947 memcpy(newprofile, profile, strlen(profile) + 1);
951 LCONSOLE_ERROR_MSG(0x154, "%s: The configuration '%s' could not"
952 " be read from the MDT '%s'. Make sure this"
953 " client and the MDT are running compatible "
954 "versions of Lustre.\n",
955 obd->obd_name, profile, mdt);
958 LCONSOLE_ERROR_MSG(0x155, "%s: The configuration '%s' could not"
959 " be read from the MDT '%s'. This may be "
960 "the result of communication errors between "
961 "the client and the MDT, or if the MDT is "
962 "not running.\n", obd->obd_name, profile,
967 /* We don't so much care about errors in cleaning up the config llog
968 * connection, as we have already read the config by this point. */
972 do_lcfg(MDCDEV, 0, LCFG_CLEANUP, 0, 0, 0, 0);
975 do_lcfg(MDCDEV, 0, LCFG_DETACH, 0, 0, 0, 0);
978 /* class_add_uuid adds a nid even if the same uuid exists; we might
979 delete any copy here. So they all better match. */
980 for (i = 0; i < failnodes; i++) {
981 sprintf(niduuid, "mdtnid%d", i);
982 do_lcfg(MDCDEV, 0, LCFG_DEL_UUID, niduuid, 0, 0, 0);
984 /* class_import_put will get rid of the additional connections */
990 int ll_fill_super(struct super_block *sb)
992 struct lustre_profile *lprof;
993 struct lustre_sb_info *lsi = s2lsi(sb);
994 struct ll_sb_info *sbi;
995 char *osc = NULL, *mdc = NULL;
996 char *profilenm = get_profile_name(sb);
997 struct config_llog_instance cfg = {0, };
998 char ll_instance[sizeof(sb) * 2 + 1];
1002 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
1006 /* client additional sb info */
1007 lsi->lsi_llsbi = sbi = ll_init_sbi();
1013 err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
1015 GOTO(out_free, err);
1017 /* Generate a string unique to this super, in case some joker tries
1018 to mount the same fs at two mount points.
1019 Use the address of the super itself.*/
1020 sprintf(ll_instance, "%p", sb);
1021 cfg.cfg_instance = ll_instance;
1022 cfg.cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1024 /* set up client obds */
1025 if (strchr(profilenm, '/') != NULL) /* COMPAT_146 */
1026 err = -EINVAL; /* skip error messages, use old config code */
1028 err = lustre_process_log(sb, profilenm, &cfg);
1033 oldnamelen = strlen(profilenm) + 1;
1034 /* Temp storage for 1.4.6 profile name */
1035 OBD_ALLOC(oldname, oldnamelen);
1037 memcpy(oldname, profilenm, oldnamelen);
1038 rc = old_lustre_process_log(sb, oldname, &cfg);
1040 /* That worked - update the profile name
1043 OBD_FREE(lsi->lsi_lmd->lmd_profile,
1044 strlen(lsi->lsi_lmd->lmd_profile) + 1);
1045 OBD_ALLOC(lsi->lsi_lmd->lmd_profile,
1046 strlen(oldname) + 1);
1047 if (!lsi->lsi_lmd->lmd_profile) {
1048 OBD_FREE(oldname, oldnamelen);
1049 GOTO(out_free, err = -ENOMEM);
1051 memcpy(lsi->lsi_lmd->lmd_profile, oldname,
1052 strlen(oldname) + 1);
1053 profilenm = get_profile_name(sb);
1054 /* Don't ever try to recover the MGS */
1055 rc = ptlrpc_set_import_active(
1056 lsi->lsi_mgc->u.cli.cl_import, 0);
1058 OBD_FREE(oldname, oldnamelen);
1061 /* end COMPAT_146 */
1063 CERROR("Unable to process log: %d\n", err);
1064 GOTO(out_free, err);
1067 lprof = class_get_profile(profilenm);
1068 if (lprof == NULL) {
1069 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1070 " read from the MGS. Does that filesystem "
1071 "exist?\n", profilenm);
1072 GOTO(out_free, err = -EINVAL);
1074 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1075 lprof->lp_mdc, lprof->lp_osc);
1077 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
1078 strlen(ll_instance) + 2);
1080 GOTO(out_free, err = -ENOMEM);
1081 sprintf(osc, "%s-%s", lprof->lp_osc, ll_instance);
1083 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
1084 strlen(ll_instance) + 2);
1086 GOTO(out_free, err = -ENOMEM);
1087 sprintf(mdc, "%s-%s", lprof->lp_mdc, ll_instance);
1089 /* connections, registrations, sb setup */
1090 err = client_common_fill_super(sb, mdc, osc);
1094 OBD_FREE(mdc, strlen(mdc) + 1);
1096 OBD_FREE(osc, strlen(osc) + 1);
1100 LCONSOLE_WARN("Client %s has started\n", profilenm);
1103 } /* ll_fill_super */
1106 void ll_put_super(struct super_block *sb)
1108 struct config_llog_instance cfg;
1109 char ll_instance[sizeof(sb) * 2 + 1];
1110 struct obd_device *obd;
1111 struct lustre_sb_info *lsi = s2lsi(sb);
1112 struct ll_sb_info *sbi = ll_s2sbi(sb);
1113 char *profilenm = get_profile_name(sb);
1114 int force = 1, next;
1117 CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
1119 sprintf(ll_instance, "%p", sb);
1120 cfg.cfg_instance = ll_instance;
1121 lustre_end_log(sb, NULL, &cfg);
1123 if (sbi->ll_mdc_exp) {
1124 obd = class_exp2obd(sbi->ll_mdc_exp);
1126 force = obd->obd_force;
1129 /* We need to set force before the lov_disconnect in
1130 lustre_common_put_super, since l_d cleans up osc's as well. */
1133 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1135 obd->obd_force = force;
1140 /* Only if client_common_fill_super succeeded */
1141 client_common_put_super(sb);
1145 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) !=NULL) {
1146 class_manual_cleanup(obd);
1150 class_del_profile(profilenm);
1153 lsi->lsi_llsbi = NULL;
1155 lustre_common_put_super(sb);
1157 LCONSOLE_WARN("client %s umount complete\n", ll_instance);
1162 } /* client_put_super */
1164 #ifdef HAVE_REGISTER_CACHE
1165 #include <linux/cache_def.h>
1166 #ifdef HAVE_CACHE_RETURN_INT
1171 ll_shrink_cache(int priority, unsigned int gfp_mask)
1173 struct ll_sb_info *sbi;
1176 list_for_each_entry(sbi, &ll_super_blocks, ll_list)
1177 count += llap_shrink_cache(sbi, priority);
1179 #ifdef HAVE_CACHE_RETURN_INT
1184 struct cache_definition ll_cache_definition = {
1185 .name = "llap_cache",
1186 .shrink = ll_shrink_cache
1188 #endif /* HAVE_REGISTER_CACHE */
1190 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
1192 struct inode *inode = NULL;
1193 /* NOTE: we depend on atomic igrab() -bzzz */
1194 lock_res_and_lock(lock);
1195 if (lock->l_ast_data) {
1196 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
1197 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1198 inode = igrab(lock->l_ast_data);
1200 inode = lock->l_ast_data;
1201 ldlm_lock_debug(NULL, inode->i_state & I_FREEING ?
1203 lock, __FILE__, __func__, __LINE__,
1204 "l_ast_data %p is bogus: magic %08x",
1205 lock->l_ast_data, lli->lli_inode_magic);
1209 unlock_res_and_lock(lock);
1213 static int null_if_equal(struct ldlm_lock *lock, void *data)
1215 if (data == lock->l_ast_data) {
1216 lock->l_ast_data = NULL;
1218 if (lock->l_req_mode != lock->l_granted_mode)
1219 LDLM_ERROR(lock,"clearing inode with ungranted lock");
1222 return LDLM_ITER_CONTINUE;
1225 void ll_clear_inode(struct inode *inode)
1228 struct ll_inode_info *lli = ll_i2info(inode);
1229 struct ll_sb_info *sbi = ll_i2sbi(inode);
1232 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1233 inode->i_generation, inode);
1235 if (S_ISDIR(inode->i_mode)) {
1236 /* these should have been cleared in ll_file_release */
1237 LASSERT(lli->lli_sai == NULL);
1238 LASSERT(lli->lli_opendir_key == NULL);
1239 LASSERT(lli->lli_opendir_pid == 0);
1242 ll_inode2fid(&fid, inode);
1243 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1244 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
1246 LASSERT(!lli->lli_open_fd_write_count);
1247 LASSERT(!lli->lli_open_fd_read_count);
1248 LASSERT(!lli->lli_open_fd_exec_count);
1250 if (lli->lli_mds_write_och)
1251 ll_mdc_real_close(inode, FMODE_WRITE);
1252 if (lli->lli_mds_exec_och) {
1254 CERROR("No FMODE exec, bug exec och is present for "
1255 "inode %ld\n", inode->i_ino);
1256 ll_mdc_real_close(inode, FMODE_EXEC);
1258 if (lli->lli_mds_read_och)
1259 ll_mdc_real_close(inode, FMODE_READ);
1263 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
1264 null_if_equal, inode);
1266 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
1267 lli->lli_smd = NULL;
1270 if (lli->lli_symlink_name) {
1271 OBD_FREE(lli->lli_symlink_name,
1272 strlen(lli->lli_symlink_name) + 1);
1273 lli->lli_symlink_name = NULL;
1276 #ifdef CONFIG_FS_POSIX_ACL
1277 if (lli->lli_posix_acl) {
1278 LASSERT(atomic_read(&lli->lli_posix_acl->a_refcount) == 1);
1279 posix_acl_release(lli->lli_posix_acl);
1280 lli->lli_posix_acl = NULL;
1284 lli->lli_inode_magic = LLI_INODE_DEAD;
1286 #ifdef HAVE_EXPORT___IGET
1287 spin_lock(&sbi->ll_deathrow_lock);
1288 list_del_init(&lli->lli_dead_list);
1289 spin_unlock(&sbi->ll_deathrow_lock);
1294 static int ll_setattr_do_truncate(struct inode *inode, loff_t new_size)
1296 struct ll_sb_info *sbi = ll_i2sbi(inode);
1297 struct ll_inode_info *lli = ll_i2info(inode);
1298 struct lov_stripe_md *lsm = lli->lli_smd;
1300 ldlm_policy_data_t policy = { .l_extent = {new_size,
1302 struct lustre_handle lockh = { 0 };
1303 int local_lock = 0; /* 0 - no local lock;
1304 * 1 - lock taken by lock_extent;
1305 * 2 - by obd_match*/
1310 UNLOCK_INODE_MUTEX(inode);
1311 UP_WRITE_I_ALLOC_SEM(inode);
1313 if (sbi->ll_lockless_truncate_enable &&
1314 (sbi->ll_lco.lco_flags & OBD_CONNECT_TRUNCLOCK)) {
1315 ast_flags = LDLM_FL_BLOCK_GRANTED;
1316 rc = obd_match(sbi->ll_osc_exp, lsm, LDLM_EXTENT,
1317 &policy, LCK_PW, &ast_flags, inode, &lockh);
1321 } else if (rc == 0) {
1322 rc = ll_file_punch(inode, new_size, 1);
1325 /* XXX when we fix the AST intents to pass the discard-range
1326 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
1328 ast_flags = (new_size == 0) ? LDLM_AST_DISCARD_DATA : 0;
1329 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy,
1331 if (likely(rc == 0))
1335 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1336 DOWN_WRITE_I_ALLOC_SEM(inode);
1337 LOCK_INODE_MUTEX(inode);
1339 LOCK_INODE_MUTEX(inode);
1340 DOWN_WRITE_I_ALLOC_SEM(inode);
1342 if (likely(rc == 0)) {
1343 /* Only ll_inode_size_lock is taken at this level.
1344 * lov_stripe_lock() is grabbed by ll_truncate() only over
1345 * call to obd_adjust_kms(). If vmtruncate returns 0, then
1346 * ll_truncate dropped ll_inode_size_lock() */
1347 ll_inode_size_lock(inode, 0);
1349 set_bit(LLI_F_SRVLOCK, &lli->lli_flags);
1350 rc = vmtruncate(inode, new_size);
1351 clear_bit(LLI_F_SRVLOCK, &lli->lli_flags);
1353 LASSERT(atomic_read(&lli->lli_size_sem.count) <= 0);
1354 ll_inode_size_unlock(inode, 0);
1358 if (local_lock == 2)
1359 err = obd_cancel(sbi->ll_osc_exp, lsm, LCK_PW, &lockh);
1361 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
1362 if (unlikely(err != 0)){
1363 CERROR("extent unlock failed: err=%d,"
1364 " unlock method =%d\n", err, local_lock);
1372 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1373 * object(s) determine the file size and mtime. Otherwise, the MDS will
1374 * keep these values until such a time that objects are allocated for it.
1375 * We do the MDS operations first, as it is checking permissions for us.
1376 * We don't to the MDS RPC if there is nothing that we want to store there,
1377 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1378 * going to do an RPC anyways.
1380 * If we are doing a truncate, we will send the mtime and ctime updates
1381 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1382 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1385 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
1387 struct ll_inode_info *lli = ll_i2info(inode);
1388 struct lov_stripe_md *lsm = lli->lli_smd;
1389 struct ll_sb_info *sbi = ll_i2sbi(inode);
1390 struct ptlrpc_request *request = NULL;
1391 struct mdc_op_data op_data;
1392 struct lustre_md md;
1393 int ia_valid = attr->ia_valid;
1397 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu valid %x\n", inode->i_ino,
1399 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_SETATTR, 1);
1401 if (ia_valid & ATTR_SIZE) {
1402 if (attr->ia_size > ll_file_maxbytes(inode)) {
1403 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
1404 attr->ia_size, ll_file_maxbytes(inode));
1408 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1411 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1412 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
1413 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1417 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1418 if (attr->ia_valid & ATTR_CTIME) {
1419 attr->ia_ctime = CURRENT_TIME;
1420 attr->ia_valid |= ATTR_CTIME_SET;
1422 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
1423 attr->ia_atime = CURRENT_TIME;
1424 attr->ia_valid |= ATTR_ATIME_SET;
1426 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
1427 attr->ia_mtime = CURRENT_TIME;
1428 attr->ia_valid |= ATTR_MTIME_SET;
1430 if ((attr->ia_valid & ATTR_CTIME) && !(attr->ia_valid & ATTR_MTIME)) {
1431 /* To avoid stale mtime on mds, obtain it from ost and send
1433 rc = ll_glimpse_size(inode, 0);
1437 attr->ia_valid |= ATTR_MTIME_SET | ATTR_MTIME;
1438 attr->ia_mtime = inode->i_mtime;
1441 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1442 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
1443 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1446 /* NB: ATTR_SIZE will only be set after this point if the size
1447 * resides on the MDS, ie, this file has no objects. */
1449 attr->ia_valid &= ~ATTR_SIZE;
1451 /* We always do an MDS RPC, even if we're only changing the size;
1452 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
1453 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0, NULL);
1455 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
1456 attr, NULL, 0, NULL, 0, &request);
1459 ptlrpc_req_finished(request);
1460 if (rc == -ENOENT) {
1462 /* Unlinked special device node? Or just a race?
1463 * Pretend we done everything. */
1464 if (!S_ISREG(inode->i_mode) &&
1465 !S_ISDIR(inode->i_mode))
1466 rc = inode_setattr(inode, attr);
1467 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY)
1468 CERROR("mdc_setattr fails: rc = %d\n", rc);
1472 rc = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md);
1474 ptlrpc_req_finished(request);
1478 /* We call inode_setattr to adjust timestamps.
1479 * If there is at least some data in file, we cleared ATTR_SIZE above to
1480 * avoid invoking vmtruncate, otherwise it is important to call
1481 * vmtruncate in inode_setattr to update inode->i_size (bug 6196) */
1482 rc = inode_setattr(inode, attr);
1484 ll_update_inode(inode, &md);
1485 ptlrpc_req_finished(request);
1487 if (!lsm || !S_ISREG(inode->i_mode)) {
1488 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
1492 /* We really need to get our PW lock before we change inode->i_size.
1493 * If we don't we can race with other i_size updaters on our node, like
1494 * ll_file_read. We can also race with i_size propogation to other
1495 * nodes through dirtying and writeback of final cached pages. This
1496 * last one is especially bad for racing o_append users on other
1498 if (ia_valid & ATTR_SIZE) {
1499 rc = ll_setattr_do_truncate(inode, attr->ia_size);
1500 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
1502 struct obd_info oinfo = { { { 0 } } };
1506 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1507 inode->i_ino, LTIME_S(attr->ia_mtime));
1510 oa->o_id = lsm->lsm_object_id;
1511 oa->o_valid = OBD_MD_FLID;
1513 flags = OBD_MD_FLTYPE | OBD_MD_FLATIME |
1514 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1515 OBD_MD_FLFID | OBD_MD_FLGENER;
1517 obdo_from_inode(oa, inode, flags);
1522 rc = obd_setattr_rqset(sbi->ll_osc_exp, &oinfo, NULL);
1524 CERROR("obd_setattr_async fails: rc=%d\n", rc);
1533 int ll_setattr(struct dentry *de, struct iattr *attr)
1537 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1538 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1539 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1540 if ((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
1541 (ATTR_SIZE|ATTR_MODE)) {
1542 mode = de->d_inode->i_mode;
1543 if (((mode & S_ISUID) && (!(attr->ia_mode & S_ISUID))) ||
1544 ((mode & S_ISGID) && (mode & S_IXGRP) &&
1545 (!(attr->ia_mode & S_ISGID))))
1546 attr->ia_valid |= ATTR_FORCE;
1549 return ll_setattr_raw(de->d_inode, attr);
1552 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1553 __u64 max_age, __u32 flags)
1555 struct ll_sb_info *sbi = ll_s2sbi(sb);
1556 struct obd_statfs obd_osfs;
1560 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age, flags);
1562 CERROR("mdc_statfs fails: rc = %d\n", rc);
1566 osfs->os_type = sb->s_magic;
1568 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1569 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1571 rc = obd_statfs_rqset(class_exp2obd(sbi->ll_osc_exp),
1572 &obd_osfs, max_age, flags);
1574 CERROR("obd_statfs fails: rc = %d\n", rc);
1578 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1579 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1582 osfs->os_bsize = obd_osfs.os_bsize;
1583 osfs->os_blocks = obd_osfs.os_blocks;
1584 osfs->os_bfree = obd_osfs.os_bfree;
1585 osfs->os_bavail = obd_osfs.os_bavail;
1587 /* If we don't have as many objects free on the OST as inodes
1588 * on the MDS, we reduce the total number of inodes to
1589 * compensate, so that the "inodes in use" number is correct.
1591 if (obd_osfs.os_ffree < osfs->os_ffree) {
1592 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1594 osfs->os_ffree = obd_osfs.os_ffree;
1599 #ifndef HAVE_STATFS_DENTRY_PARAM
1600 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1603 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1605 struct super_block *sb = de->d_sb;
1607 struct obd_statfs osfs;
1610 CDEBUG(D_VFSTRACE, "VFS Op: at "LPU64" jiffies\n", get_jiffies_64());
1611 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1);
1613 /* For now we will always get up-to-date statfs values, but in the
1614 * future we may allow some amount of caching on the client (e.g.
1615 * from QOS or lprocfs updates). */
1616 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - 1, 0);
1620 statfs_unpack(sfs, &osfs);
1622 /* We need to downshift for all 32-bit kernels, because we can't
1623 * tell if the kernel is being called via sys_statfs64() or not.
1624 * Stop before overflowing f_bsize - in which case it is better
1625 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
1626 if (sizeof(long) < 8) {
1627 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1630 osfs.os_blocks >>= 1;
1631 osfs.os_bfree >>= 1;
1632 osfs.os_bavail >>= 1;
1636 sfs->f_blocks = osfs.os_blocks;
1637 sfs->f_bfree = osfs.os_bfree;
1638 sfs->f_bavail = osfs.os_bavail;
1643 void ll_inode_size_lock(struct inode *inode, int lock_lsm)
1645 struct ll_inode_info *lli;
1646 struct lov_stripe_md *lsm;
1648 lli = ll_i2info(inode);
1649 LASSERT(lli->lli_size_sem_owner != current);
1650 down(&lli->lli_size_sem);
1651 LASSERT(lli->lli_size_sem_owner == NULL);
1652 lli->lli_size_sem_owner = current;
1654 LASSERTF(lsm != NULL || lock_lsm == 0, "lsm %p, lock_lsm %d\n",
1657 lov_stripe_lock(lsm);
1660 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm)
1662 struct ll_inode_info *lli;
1663 struct lov_stripe_md *lsm;
1665 lli = ll_i2info(inode);
1667 LASSERTF(lsm != NULL || unlock_lsm == 0, "lsm %p, lock_lsm %d\n",
1670 lov_stripe_unlock(lsm);
1671 LASSERT(lli->lli_size_sem_owner == current);
1672 lli->lli_size_sem_owner = NULL;
1673 up(&lli->lli_size_sem);
1676 static void ll_replace_lsm(struct inode *inode, struct lov_stripe_md *lsm)
1678 struct ll_inode_info *lli = ll_i2info(inode);
1680 dump_lsm(D_INODE, lsm);
1681 dump_lsm(D_INODE, lli->lli_smd);
1682 LASSERTF(lsm->lsm_magic == LOV_MAGIC_JOIN,
1683 "lsm must be joined lsm %p\n", lsm);
1684 obd_free_memmd(ll_i2obdexp(inode), &lli->lli_smd);
1685 CDEBUG(D_INODE, "replace lsm %p to lli_smd %p for inode %lu%u(%p)\n",
1686 lsm, lli->lli_smd, inode->i_ino, inode->i_generation, inode);
1688 lli->lli_maxbytes = lsm->lsm_maxbytes;
1689 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1690 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1693 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1695 struct ll_inode_info *lli = ll_i2info(inode);
1696 struct mds_body *body = md->body;
1697 struct lov_stripe_md *lsm = md->lsm;
1699 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1701 if (lli->lli_smd == NULL) {
1702 if (lsm->lsm_magic != LOV_MAGIC &&
1703 lsm->lsm_magic != LOV_MAGIC_JOIN) {
1704 dump_lsm(D_ERROR, lsm);
1707 CDEBUG(D_INODE, "adding lsm %p to inode %lu/%u(%p)\n",
1708 lsm, inode->i_ino, inode->i_generation, inode);
1709 /* ll_inode_size_lock() requires it is only called
1710 * with lli_smd != NULL or lock_lsm == 0 or we can
1711 * race between lock/unlock. bug 9547 */
1713 lli->lli_maxbytes = lsm->lsm_maxbytes;
1714 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1715 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1717 if (lli->lli_smd->lsm_magic == lsm->lsm_magic &&
1718 lli->lli_smd->lsm_stripe_count ==
1719 lsm->lsm_stripe_count) {
1720 if (lov_stripe_md_cmp(lli->lli_smd, lsm)) {
1721 CERROR("lsm mismatch for inode %ld\n",
1723 CERROR("lli_smd:\n");
1724 dump_lsm(D_ERROR, lli->lli_smd);
1726 dump_lsm(D_ERROR, lsm);
1730 ll_replace_lsm(inode, lsm);
1732 if (lli->lli_smd != lsm)
1733 obd_free_memmd(ll_i2obdexp(inode), &lsm);
1736 #ifdef CONFIG_FS_POSIX_ACL
1737 LASSERT(!md->posix_acl || (body->valid & OBD_MD_FLACL));
1738 if (body->valid & OBD_MD_FLACL) {
1739 spin_lock(&lli->lli_lock);
1740 if (lli->lli_posix_acl)
1741 posix_acl_release(lli->lli_posix_acl);
1742 lli->lli_posix_acl = md->posix_acl;
1743 spin_unlock(&lli->lli_lock);
1747 if (body->valid & OBD_MD_FLID)
1748 inode->i_ino = body->ino;
1749 if (body->valid & OBD_MD_FLATIME &&
1750 body->atime > LTIME_S(inode->i_atime))
1751 LTIME_S(inode->i_atime) = body->atime;
1753 /* mtime is always updated with ctime, but can be set in past.
1754 As write and utime(2) may happen within 1 second, and utime's
1755 mtime has a priority over write's one, so take mtime from mds
1756 for the same ctimes. */
1757 if (body->valid & OBD_MD_FLCTIME &&
1758 body->ctime >= LTIME_S(inode->i_ctime)) {
1759 LTIME_S(inode->i_ctime) = body->ctime;
1760 if (body->valid & OBD_MD_FLMTIME) {
1761 CDEBUG(D_INODE, "setting ino %lu mtime "
1762 "from %lu to "LPU64"\n", inode->i_ino,
1763 LTIME_S(inode->i_mtime), body->mtime);
1764 LTIME_S(inode->i_mtime) = body->mtime;
1767 if (body->valid & OBD_MD_FLMODE)
1768 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1769 if (body->valid & OBD_MD_FLTYPE)
1770 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1771 if (S_ISREG(inode->i_mode)) {
1772 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
1774 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
1776 #ifdef HAVE_INODE_BLKSIZE
1777 inode->i_blksize = 1<<inode->i_blkbits;
1779 if (body->valid & OBD_MD_FLUID)
1780 inode->i_uid = body->uid;
1781 if (body->valid & OBD_MD_FLGID)
1782 inode->i_gid = body->gid;
1783 if (body->valid & OBD_MD_FLFLAGS)
1784 inode->i_flags = ll_ext_to_inode_flags(body->flags);
1785 if (body->valid & OBD_MD_FLNLINK)
1786 inode->i_nlink = body->nlink;
1787 if (body->valid & OBD_MD_FLGENER)
1788 inode->i_generation = body->generation;
1789 if (body->valid & OBD_MD_FLRDEV)
1790 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1791 inode->i_rdev = body->rdev;
1793 inode->i_rdev = old_decode_dev(body->rdev);
1795 if (body->valid & OBD_MD_FLSIZE) {
1796 #if 0 /* Can't block ll_test_inode->ll_update_inode, b=14326*/
1797 ll_inode_size_lock(inode, 0);
1798 i_size_write(inode, body->size);
1799 ll_inode_size_unlock(inode, 0);
1801 inode->i_size = body->size;
1804 if (body->valid & OBD_MD_FLBLOCKS)
1805 inode->i_blocks = body->blocks;
1807 if (body->valid & OBD_MD_FLSIZE)
1808 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1811 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
1812 static struct backing_dev_info ll_backing_dev_info = {
1813 .ra_pages = 0, /* No readahead */
1814 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
1815 .capabilities = 0, /* Does contribute to dirty memory */
1817 .memory_backed = 0, /* Does contribute to dirty memory */
1822 void ll_read_inode2(struct inode *inode, void *opaque)
1824 struct lustre_md *md = opaque;
1825 struct ll_inode_info *lli = ll_i2info(inode);
1828 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1829 inode->i_generation, inode);
1833 LASSERT(!lli->lli_smd);
1835 /* Core attributes from the MDS first. This is a new inode, and
1836 * the VFS doesn't zero times in the core inode so we have to do
1837 * it ourselves. They will be overwritten by either MDS or OST
1838 * attributes - we just need to make sure they aren't newer. */
1839 LTIME_S(inode->i_mtime) = 0;
1840 LTIME_S(inode->i_atime) = 0;
1841 LTIME_S(inode->i_ctime) = 0;
1843 ll_update_inode(inode, md);
1845 /* OIDEBUG(inode); */
1847 if (S_ISREG(inode->i_mode)) {
1848 struct ll_sb_info *sbi = ll_i2sbi(inode);
1849 inode->i_op = &ll_file_inode_operations;
1850 inode->i_fop = sbi->ll_fop;
1851 inode->i_mapping->a_ops = &ll_aops;
1853 } else if (S_ISDIR(inode->i_mode)) {
1854 inode->i_op = &ll_dir_inode_operations;
1855 inode->i_fop = &ll_dir_operations;
1856 inode->i_mapping->a_ops = &ll_dir_aops;
1858 } else if (S_ISLNK(inode->i_mode)) {
1859 inode->i_op = &ll_fast_symlink_inode_operations;
1862 inode->i_op = &ll_special_inode_operations;
1864 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1865 init_special_inode(inode, inode->i_mode,
1866 kdev_t_to_nr(inode->i_rdev));
1868 /* initializing backing dev info. */
1869 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
1871 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1877 int ll_iocontrol(struct inode *inode, struct file *file,
1878 unsigned int cmd, unsigned long arg)
1880 struct ll_sb_info *sbi = ll_i2sbi(inode);
1881 struct ptlrpc_request *req = NULL;
1886 case EXT3_IOC_GETFLAGS: {
1888 struct mds_body *body;
1890 ll_inode2fid(&fid, inode);
1891 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, OBD_MD_FLFLAGS,0,&req);
1893 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1897 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1900 /* We want to return EXT3_*_FL flags to the caller via this
1901 * ioctl. An older MDS may be sending S_* flags, fix it up. */
1902 flags = ll_inode_to_ext_flags(body->flags,
1903 body->flags &MDS_BFLAG_EXT_FLAGS);
1904 ptlrpc_req_finished (req);
1906 RETURN(put_user(flags, (int *)arg));
1908 case EXT3_IOC_SETFLAGS: {
1909 struct mdc_op_data op_data;
1910 struct ll_iattr_struct attr;
1911 struct obd_info oinfo = { { { 0 } } };
1912 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1914 if (get_user(flags, (int *)arg))
1918 OBDO_ALLOC(oinfo.oi_oa);
1922 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0, NULL);
1924 memset(&attr, 0, sizeof(attr));
1925 attr.ia_attr_flags = flags;
1926 ((struct iattr *)&attr)->ia_valid |= ATTR_ATTR_FLAG;
1928 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
1929 (struct iattr *)&attr, NULL, 0, NULL, 0, &req);
1930 ptlrpc_req_finished(req);
1931 if (rc || lsm == NULL) {
1932 OBDO_FREE(oinfo.oi_oa);
1936 oinfo.oi_oa->o_id = lsm->lsm_object_id;
1937 oinfo.oi_oa->o_flags = flags;
1938 oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS;
1940 obdo_from_inode(oinfo.oi_oa, inode,
1941 OBD_MD_FLFID | OBD_MD_FLGENER);
1942 rc = obd_setattr_rqset(sbi->ll_osc_exp, &oinfo, NULL);
1943 OBDO_FREE(oinfo.oi_oa);
1945 if (rc != -EPERM && rc != -EACCES)
1946 CERROR("mdc_setattr_async fails: rc = %d\n", rc);
1950 inode->i_flags = ll_ext_to_inode_flags(flags |
1951 MDS_BFLAG_EXT_FLAGS);
1961 /* umount -f client means force down, don't save state */
1962 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
1963 void ll_umount_begin(struct vfsmount *vfsmnt, int flags)
1965 struct super_block *sb = vfsmnt->mnt_sb;
1967 void ll_umount_begin(struct super_block *sb)
1970 struct lustre_sb_info *lsi = s2lsi(sb);
1971 struct ll_sb_info *sbi = ll_s2sbi(sb);
1972 struct obd_device *obd;
1973 struct obd_ioctl_data ioc_data = { 0 };
1976 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
1977 if (!(flags & MNT_FORCE)) {
1983 /* Tell the MGC we got umount -f */
1984 lsi->lsi_flags |= LSI_UMOUNT_FORCE;
1986 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
1987 sb->s_count, atomic_read(&sb->s_active));
1989 obd = class_exp2obd(sbi->ll_mdc_exp);
1991 CERROR("Invalid MDC connection handle "LPX64"\n",
1992 sbi->ll_mdc_exp->exp_handle.h_cookie);
1997 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_mdc_exp, sizeof ioc_data,
2000 obd = class_exp2obd(sbi->ll_osc_exp);
2002 CERROR("Invalid LOV connection handle "LPX64"\n",
2003 sbi->ll_osc_exp->exp_handle.h_cookie);
2009 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_osc_exp, sizeof ioc_data,
2012 /* Really, we'd like to wait until there are no requests outstanding,
2013 * and then continue. For now, we just invalidate the requests,
2014 * schedule, and hope.
2021 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2023 struct ll_sb_info *sbi = ll_s2sbi(sb);
2027 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
2028 read_only = *flags & MS_RDONLY;
2029 err = obd_set_info_async(sbi->ll_mdc_exp, sizeof(KEY_READONLY),
2030 KEY_READONLY, sizeof(read_only),
2033 CERROR("Failed to change the read-only flag during "
2034 "remount: %d\n", err);
2039 sb->s_flags |= MS_RDONLY;
2041 sb->s_flags &= ~MS_RDONLY;
2046 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
2047 struct ptlrpc_request *req, int offset,struct super_block *sb)
2049 struct lustre_md md;
2050 struct ll_sb_info *sbi = NULL;
2054 LASSERT(*inode || sb);
2055 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2056 prune_deathrow(sbi, 1);
2058 rc = mdc_req2lustre_md(req, offset, exp, &md);
2063 ll_update_inode(*inode, &md);
2066 *inode = ll_iget(sb, md.body->ino, &md);
2067 if (*inode == NULL || is_bad_inode(*inode)) {
2068 mdc_free_lustre_md(exp, &md);
2070 CERROR("new_inode -fatal: rc %d\n", rc);
2075 rc = obd_checkmd(exp, ll_i2mdcexp(*inode),
2076 ll_i2info(*inode)->lli_smd);
2081 char *llap_origins[] = {
2082 [LLAP_ORIGIN_UNKNOWN] = "--",
2083 [LLAP_ORIGIN_READPAGE] = "rp",
2084 [LLAP_ORIGIN_READAHEAD] = "ra",
2085 [LLAP_ORIGIN_COMMIT_WRITE] = "cw",
2086 [LLAP_ORIGIN_WRITEPAGE] = "wp",
2087 [LLAP_ORIGIN_LOCKLESS_IO] = "ls"
2090 struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
2091 struct list_head *list)
2093 struct ll_async_page *llap;
2094 struct list_head *pos;
2096 list_for_each(pos, list) {
2097 if (pos == &sbi->ll_pglist)
2099 llap = list_entry(pos, struct ll_async_page, llap_pglist_item);
2100 if (llap->llap_page == NULL)
2108 int ll_obd_statfs(struct inode *inode, void *arg)
2110 struct ll_sb_info *sbi = NULL;
2111 struct obd_device *client_obd = NULL, *lov_obd = NULL;
2112 struct lov_obd *lov = NULL;
2113 struct obd_statfs stat_buf = {0};
2115 struct obd_ioctl_data *data = NULL;
2119 if (!inode || !(sbi = ll_i2sbi(inode)))
2120 GOTO(out_statfs, rc = -EINVAL);
2122 rc = obd_ioctl_getdata(&buf, &len, arg);
2124 GOTO(out_statfs, rc);
2127 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2128 !data->ioc_pbuf1 || !data->ioc_pbuf2)
2129 GOTO(out_statfs, rc = -EINVAL);
2131 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2132 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
2134 if (type == LL_STATFS_MDC) {
2136 GOTO(out_statfs, rc = -ENODEV);
2137 client_obd = class_exp2obd(sbi->ll_mdc_exp);
2138 } else if (type == LL_STATFS_LOV) {
2139 lov_obd = class_exp2obd(sbi->ll_osc_exp);
2140 lov = &lov_obd->u.lov;
2142 if (index >= lov->desc.ld_tgt_count)
2143 GOTO(out_statfs, rc = -ENODEV);
2145 if (!lov->lov_tgts[index])
2146 /* Try again with the next index */
2147 GOTO(out_statfs, rc = -EAGAIN);
2149 client_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
2150 if (!lov->lov_tgts[index]->ltd_active)
2151 GOTO(out_uuid, rc = -ENODATA);
2155 GOTO(out_statfs, rc = -EINVAL);
2157 rc = obd_statfs(client_obd, &stat_buf, cfs_time_current_64() - HZ, 1);
2159 GOTO(out_statfs, rc);
2161 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
2162 GOTO(out_statfs, rc = -EFAULT);
2165 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(client_obd),
2171 obd_ioctl_freedata(buf, len);
2175 int ll_process_config(struct lustre_cfg *lcfg)
2179 struct lprocfs_static_vars lvars;
2183 lprocfs_llite_init_vars(&lvars);
2185 /* The instance name contains the sb: lustre-client-aacfe000 */
2186 ptr = strrchr(lustre_cfg_string(lcfg, 0), '-');
2187 if (!ptr || !*(++ptr))
2189 if (sscanf(ptr, "%lx", &x) != 1)
2192 /* This better be a real Lustre superblock! */
2193 LASSERT(s2lsi((struct super_block *)sb)->lsi_lmd->lmd_magic == LMD_MAGIC);
2195 /* Note we have not called client_common_fill_super yet, so
2196 proc fns must be able to handle that! */
2197 rc = class_process_proc_param(PARAM_LLITE, lvars.obd_vars,