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>
32 #include <lustre_lite.h>
33 #include <lustre_ha.h>
34 #include <lustre_dlm.h>
35 #include <lprocfs_status.h>
36 #include <lustre_disk.h>
37 #include <lustre_param.h>
38 #include <lustre_cache.h>
39 #include "llite_internal.h"
41 cfs_mem_cache_t *ll_file_data_slab;
43 LIST_HEAD(ll_super_blocks);
44 spinlock_t ll_sb_lock = SPIN_LOCK_UNLOCKED;
46 extern struct address_space_operations ll_aops;
47 extern struct address_space_operations ll_dir_aops;
50 #define log2(n) ffz(~(n))
54 static struct ll_sb_info *ll_init_sbi(void)
56 struct ll_sb_info *sbi = NULL;
63 OBD_ALLOC(sbi, sizeof(*sbi));
67 spin_lock_init(&sbi->ll_lock);
68 spin_lock_init(&sbi->ll_lco.lco_lock);
69 spin_lock_init(&sbi->ll_pp_extent_lock);
70 spin_lock_init(&sbi->ll_process_lock);
71 sbi->ll_rw_stats_on = 0;
72 INIT_LIST_HEAD(&sbi->ll_pglist);
75 pages = si.totalram - si.totalhigh;
76 if (pages >> (20 - CFS_PAGE_SHIFT) < 512)
77 sbi->ll_async_page_max = pages / 2;
79 sbi->ll_async_page_max = (pages / 4) * 3;
80 sbi->ll_ra_info.ra_max_pages = min(num_physpages / 8,
81 SBI_DEFAULT_READAHEAD_MAX);
82 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
83 SBI_DEFAULT_READAHEAD_WHOLE_MAX;
84 sbi->ll_contention_time = SBI_DEFAULT_CONTENTION_SECONDS;
85 sbi->ll_lockless_truncate_enable = SBI_DEFAULT_LOCKLESS_TRUNCATE_ENABLE;
86 INIT_LIST_HEAD(&sbi->ll_conn_chain);
87 INIT_LIST_HEAD(&sbi->ll_orphan_dentry_list);
89 ll_generate_random_uuid(uuid);
90 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
91 CDEBUG(D_CONFIG, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
93 spin_lock(&ll_sb_lock);
94 list_add_tail(&sbi->ll_list, &ll_super_blocks);
95 spin_unlock(&ll_sb_lock);
97 #ifdef ENABLE_CHECKSUM
98 sbi->ll_flags |= LL_SBI_DATA_CHECKSUM;
100 #ifdef ENABLE_LLITE_CHECKSUM
101 sbi->ll_flags |= LL_SBI_LLITE_CHECKSUM;
104 #ifdef HAVE_LRU_RESIZE_SUPPORT
105 sbi->ll_flags |= LL_SBI_LRU_RESIZE;
108 #ifdef HAVE_EXPORT___IGET
109 INIT_LIST_HEAD(&sbi->ll_deathrow);
110 spin_lock_init(&sbi->ll_deathrow_lock);
112 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
113 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_r_hist.oh_lock);
114 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_w_hist.oh_lock);
117 /* metadata statahead is enabled by default */
118 sbi->ll_sa_max = LL_SA_RPC_DEF;
123 void ll_free_sbi(struct super_block *sb)
125 struct ll_sb_info *sbi = ll_s2sbi(sb);
129 spin_lock(&ll_sb_lock);
130 list_del(&sbi->ll_list);
131 spin_unlock(&ll_sb_lock);
132 OBD_FREE(sbi, sizeof(*sbi));
137 static struct dentry_operations ll_d_root_ops = {
138 #ifdef DCACHE_LUSTRE_INVALID
139 .d_compare = ll_dcompare,
143 static int client_common_fill_super(struct super_block *sb,
144 char *mdc, char *osc)
146 struct inode *root = 0;
147 struct ll_sb_info *sbi = ll_s2sbi(sb);
148 struct obd_device *obd;
149 struct ll_fid rootfid;
150 struct obd_statfs osfs;
151 struct ptlrpc_request *request = NULL;
152 struct lustre_handle osc_conn = {0, };
153 struct lustre_handle mdc_conn = {0, };
155 struct obd_connect_data *data = NULL;
159 obd = class_name2obd(mdc);
161 CERROR("MDC %s: not setup or attached\n", mdc);
165 OBD_ALLOC(data, sizeof(*data));
169 if (proc_lustre_fs_root) {
170 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
173 CERROR("could not register mount in /proc/fs/lustre\n");
176 /* indicate the features supported by this client */
177 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_IBITS |
178 OBD_CONNECT_JOIN | OBD_CONNECT_ATTRFID | OBD_CONNECT_NODEVOH |
179 OBD_CONNECT_CANCELSET | OBD_CONNECT_AT;
180 #ifdef HAVE_LRU_RESIZE_SUPPORT
181 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
182 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
184 #ifdef CONFIG_FS_POSIX_ACL
185 data->ocd_connect_flags |= OBD_CONNECT_ACL;
187 data->ocd_ibits_known = MDS_INODELOCK_FULL;
188 data->ocd_version = LUSTRE_VERSION_CODE;
190 if (sb->s_flags & MS_RDONLY)
191 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
192 if (sbi->ll_flags & LL_SBI_USER_XATTR)
193 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
195 #ifdef HAVE_MS_FLOCK_LOCK
196 /* force vfs to use lustre handler for flock() calls - bug 10743 */
197 sb->s_flags |= MS_FLOCK_LOCK;
200 if (sbi->ll_flags & LL_SBI_FLOCK)
201 sbi->ll_fop = &ll_file_operations_flock;
202 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
203 sbi->ll_fop = &ll_file_operations;
205 sbi->ll_fop = &ll_file_operations_noflock;
207 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid, data, NULL);
209 LCONSOLE_ERROR_MSG(0x14f, "An MDT (mdc %s) is performing "
210 "recovery, of which this client is not a "
211 "part. Please wait for recovery to complete,"
212 " abort, or time out.\n", mdc);
215 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
218 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
220 err = obd_statfs(obd, &osfs, cfs_time_current_64() - HZ, 0);
224 /* MDC connect is surely finished by now because we actually sent
225 * a statfs RPC, otherwise obd_connect() is asynchronous. */
226 *data = class_exp2cliimp(sbi->ll_mdc_exp)->imp_connect_data;
228 LASSERT(osfs.os_bsize);
229 sb->s_blocksize = osfs.os_bsize;
230 sb->s_blocksize_bits = log2(osfs.os_bsize);
231 sb->s_magic = LL_SUPER_MAGIC;
233 /* for bug 11559. in $LINUX/fs/read_write.c, function do_sendfile():
234 * retval = in_file->f_op->sendfile(...);
236 * retval = -EOVERFLOW;
238 * it will check if *ppos is greater than max. However, max equals to
239 * s_maxbytes, which is a negative integer in a x86_64 box since loff_t
240 * has been defined as a signed long long ineger in linux kernel. */
241 #if BITS_PER_LONG == 64
242 sb->s_maxbytes = PAGE_CACHE_MAXBYTES >> 1;
244 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
246 sbi->ll_namelen = osfs.os_namelen;
247 sbi->ll_max_rw_chunk = LL_DEFAULT_MAX_RW_CHUNK;
249 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
250 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
251 LCONSOLE_INFO("Disabling user_xattr feature because "
252 "it is not supported on the server\n");
253 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
256 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
258 sb->s_flags |= MS_POSIXACL;
260 sbi->ll_flags |= LL_SBI_ACL;
262 sbi->ll_flags &= ~LL_SBI_ACL;
264 if (data->ocd_connect_flags & OBD_CONNECT_JOIN)
265 sbi->ll_flags |= LL_SBI_JOIN;
267 sbi->ll_sdev_orig = sb->s_dev;
268 /* We set sb->s_dev equal on all lustre clients in order to support
269 * NFS export clustering. NFSD requires that the FSID be the same
271 /* s_dev is also used in lt_compare() to compare two fs, but that is
272 * only a node-local comparison. */
273 sb->s_dev = get_uuid2int(sbi2mdc(sbi)->cl_target_uuid.uuid,
274 strlen(sbi2mdc(sbi)->cl_target_uuid.uuid));
275 obd = class_name2obd(osc);
277 CERROR("OSC %s: not setup or attached\n", osc);
278 GOTO(out_mdc, err = -ENODEV);
281 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_GRANT |
282 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
283 OBD_CONNECT_SRVLOCK | OBD_CONNECT_CANCELSET | OBD_CONNECT_AT |
284 OBD_CONNECT_TRUNCLOCK;
286 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_CKSUM)) {
287 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
288 * disabled by default, because it can still be enabled on the
289 * fly via /proc. As a consequence, we still need to come to an
290 * agreement on the supported algorithms at connect time */
291 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
293 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
294 data->ocd_cksum_types = OBD_CKSUM_ADLER;
296 /* send the list of supported checksum types */
297 data->ocd_cksum_types = OBD_CKSUM_ALL;
300 #ifdef HAVE_LRU_RESIZE_SUPPORT
301 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
302 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
305 CDEBUG(D_RPCTRACE, "ocd_connect_flags: "LPX64" ocd_version: %d "
306 "ocd_grant: %d\n", data->ocd_connect_flags,
307 data->ocd_version, data->ocd_grant);
309 obd->obd_upcall.onu_owner = &sbi->ll_lco;
310 obd->obd_upcall.onu_upcall = ll_ocd_update;
311 data->ocd_brw_size = PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT;
313 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid, data, NULL);
315 LCONSOLE_ERROR_MSG(0x150, "An OST (osc %s) is performing "
316 "recovery, of which this client is not a "
317 "part. Please wait for recovery to "
318 "complete, abort, or time out.\n", osc);
321 CERROR("cannot connect to %s: rc = %d\n", osc, err);
324 sbi->ll_osc_exp = class_conn2export(&osc_conn);
325 spin_lock(&sbi->ll_lco.lco_lock);
326 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
327 spin_unlock(&sbi->ll_lco.lco_lock);
329 err = obd_register_page_removal_cb(sbi->ll_osc_exp,
333 CERROR("cannot register page removal callback: rc = %d\n",err);
336 err = obd_register_lock_cancel_cb(sbi->ll_osc_exp,
337 ll_extent_lock_cancel_cb);
339 CERROR("cannot register lock cancel callback: rc = %d\n", err);
340 GOTO(out_page_rm_cb, err);
343 err = mdc_init_ea_size(sbi->ll_mdc_exp, sbi->ll_osc_exp);
345 CERROR("cannot set max EA and cookie sizes: rc = %d\n", err);
346 GOTO(out_lock_cn_cb, err);
349 err = obd_prep_async_page(sbi->ll_osc_exp, NULL, NULL, NULL,
350 0, NULL, NULL, NULL, 0, NULL);
352 LCONSOLE_ERROR_MSG(0x151, "There are no OST's in this "
353 "filesystem. There must be at least one "
354 "active OST for a client to start.\n");
355 GOTO(out_lock_cn_cb, err);
358 if (!ll_async_page_slab) {
359 ll_async_page_slab_size =
360 size_round(sizeof(struct ll_async_page)) + err;
361 ll_async_page_slab = cfs_mem_cache_create("ll_async_page",
362 ll_async_page_slab_size,
364 if (!ll_async_page_slab)
365 GOTO(out_lock_cn_cb, -ENOMEM);
368 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
370 CERROR("cannot mds_connect: rc = %d\n", err);
371 GOTO(out_lock_cn_cb, err);
373 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
374 sbi->ll_rootino = rootfid.id;
376 sb->s_op = &lustre_super_operations;
377 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
378 sb->s_export_op = &lustre_export_operations;
382 * XXX: move this to after cbd setup? */
383 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
384 OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS |
385 (sbi->ll_flags & LL_SBI_ACL ? OBD_MD_FLACL : 0),
388 CERROR("mdc_getattr failed for root: rc = %d\n", err);
389 GOTO(out_lock_cn_cb, err);
392 err = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md);
394 CERROR("failed to understand root inode md: rc = %d\n",err);
395 ptlrpc_req_finished (request);
396 GOTO(out_lock_cn_cb, err);
399 LASSERT(sbi->ll_rootino != 0);
400 root = ll_iget(sb, sbi->ll_rootino, &md);
402 ptlrpc_req_finished(request);
404 if (root == NULL || is_bad_inode(root)) {
405 mdc_free_lustre_md(sbi->ll_osc_exp, &md);
406 CERROR("lustre_lite: bad iget4 for root\n");
407 GOTO(out_root, err = -EBADF);
410 err = ll_close_thread_start(&sbi->ll_lcq);
412 CERROR("cannot start close thread: rc %d\n", err);
416 checksum = sbi->ll_flags & LL_SBI_DATA_CHECKSUM;
417 err = obd_set_info_async(sbi->ll_osc_exp, sizeof(KEY_CHECKSUM),
418 KEY_CHECKSUM, sizeof(checksum),
421 /* making vm readahead 0 for 2.4.x. In the case of 2.6.x,
422 backing dev info assigned to inode mapping is used for
423 determining maximal readahead. */
424 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) && \
425 !defined(KERNEL_HAS_AS_MAX_READAHEAD)
426 /* bug 2805 - set VM readahead to zero */
427 vm_max_readahead = vm_min_readahead = 0;
430 sb->s_root = d_alloc_root(root);
432 OBD_FREE(data, sizeof(*data));
433 sb->s_root->d_op = &ll_d_root_ops;
440 obd_unregister_lock_cancel_cb(sbi->ll_osc_exp,
441 ll_extent_lock_cancel_cb);
443 obd_unregister_page_removal_cb(sbi->ll_osc_exp,
446 obd_disconnect(sbi->ll_osc_exp);
447 sbi->ll_osc_exp = NULL;
449 obd_disconnect(sbi->ll_mdc_exp);
450 sbi->ll_mdc_exp = NULL;
453 OBD_FREE(data, sizeof(*data));
454 lprocfs_unregister_mountpoint(sbi);
458 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
462 *lmmsize = obd_size_diskmd(sbi->ll_osc_exp, NULL);
464 rc = obd_get_info(sbi->ll_mdc_exp, sizeof(KEY_MAX_EASIZE),
465 KEY_MAX_EASIZE, &size, lmmsize);
467 CERROR("Get max mdsize error rc %d \n", rc);
472 void ll_dump_inode(struct inode *inode)
474 struct list_head *tmp;
475 int dentry_count = 0;
477 LASSERT(inode != NULL);
479 list_for_each(tmp, &inode->i_dentry)
482 CERROR("inode %p dump: dev=%s ino=%lu mode=%o count=%u, %d dentries\n",
483 inode, ll_i2mdcexp(inode)->exp_obd->obd_name, inode->i_ino,
484 inode->i_mode, atomic_read(&inode->i_count), dentry_count);
487 void lustre_dump_dentry(struct dentry *dentry, int recur)
489 struct list_head *tmp;
492 LASSERT(dentry != NULL);
494 list_for_each(tmp, &dentry->d_subdirs)
497 CERROR("dentry %p dump: name=%.*s parent=%.*s (%p), inode=%p, count=%u,"
498 " flags=0x%x, fsdata=%p, %d subdirs\n", dentry,
499 dentry->d_name.len, dentry->d_name.name,
500 dentry->d_parent->d_name.len, dentry->d_parent->d_name.name,
501 dentry->d_parent, dentry->d_inode, atomic_read(&dentry->d_count),
502 dentry->d_flags, dentry->d_fsdata, subdirs);
503 if (dentry->d_inode != NULL)
504 ll_dump_inode(dentry->d_inode);
509 list_for_each(tmp, &dentry->d_subdirs) {
510 struct dentry *d = list_entry(tmp, struct dentry, d_child);
511 lustre_dump_dentry(d, recur - 1);
515 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
516 void lustre_throw_orphan_dentries(struct super_block *sb)
518 struct dentry *dentry, *next;
519 struct ll_sb_info *sbi = ll_s2sbi(sb);
521 /* Do this to get rid of orphaned dentries. That is not really trw. */
522 list_for_each_entry_safe(dentry, next, &sbi->ll_orphan_dentry_list,
524 CWARN("found orphan dentry %.*s (%p->%p) at unmount, dumping "
525 "before and after shrink_dcache_parent\n",
526 dentry->d_name.len, dentry->d_name.name, dentry, next);
527 lustre_dump_dentry(dentry, 1);
528 shrink_dcache_parent(dentry);
529 lustre_dump_dentry(dentry, 1);
533 #define lustre_throw_orphan_dentries(sb)
536 #ifdef HAVE_EXPORT___IGET
537 static void prune_dir_dentries(struct inode *inode)
539 struct dentry *dentry, *prev = NULL;
541 /* due to lustre specific logic, a directory
542 * can have few dentries - a bug from VFS POV */
544 spin_lock(&dcache_lock);
545 if (!list_empty(&inode->i_dentry)) {
546 dentry = list_entry(inode->i_dentry.prev,
547 struct dentry, d_alias);
548 /* in order to prevent infinite loops we
549 * break if previous dentry is busy */
550 if (dentry != prev) {
553 spin_unlock(&dcache_lock);
555 /* try to kill all child dentries */
556 shrink_dcache_parent(dentry);
559 /* now try to get rid of current dentry */
560 d_prune_aliases(inode);
564 spin_unlock(&dcache_lock);
567 static void prune_deathrow_one(struct ll_inode_info *lli)
569 struct inode *inode = ll_info2i(lli);
571 /* first, try to drop any dentries - they hold a ref on the inode */
572 if (S_ISDIR(inode->i_mode))
573 prune_dir_dentries(inode);
575 d_prune_aliases(inode);
578 /* if somebody still uses it, leave it */
579 LASSERT(atomic_read(&inode->i_count) > 0);
580 if (atomic_read(&inode->i_count) > 1)
583 CDEBUG(D_INODE, "inode %lu/%u(%d) looks a good candidate for prune\n",
584 inode->i_ino,inode->i_generation, atomic_read(&inode->i_count));
586 /* seems nobody uses it anymore */
594 static void prune_deathrow(struct ll_sb_info *sbi, int try)
596 struct ll_inode_info *lli;
600 if (need_resched() && try)
604 if (!spin_trylock(&sbi->ll_deathrow_lock))
607 spin_lock(&sbi->ll_deathrow_lock);
612 if (!list_empty(&sbi->ll_deathrow)) {
613 lli = list_entry(sbi->ll_deathrow.next,
614 struct ll_inode_info,
616 list_del_init(&lli->lli_dead_list);
617 if (!list_empty(&sbi->ll_deathrow))
620 spin_unlock(&sbi->ll_deathrow_lock);
623 prune_deathrow_one(lli);
625 } while (empty == 0);
627 #else /* !HAVE_EXPORT___IGET */
628 #define prune_deathrow(sbi, try) do {} while (0)
629 #endif /* HAVE_EXPORT___IGET */
631 void client_common_put_super(struct super_block *sb)
633 struct ll_sb_info *sbi = ll_s2sbi(sb);
636 ll_close_thread_shutdown(sbi->ll_lcq);
638 lprocfs_unregister_mountpoint(sbi);
640 /* destroy inodes in deathrow */
641 prune_deathrow(sbi, 0);
643 list_del(&sbi->ll_conn_chain);
645 /* callbacks is cleared after disconnect each target */
646 obd_disconnect(sbi->ll_osc_exp);
647 sbi->ll_osc_exp = NULL;
649 obd_disconnect(sbi->ll_mdc_exp);
650 sbi->ll_mdc_exp = NULL;
652 lustre_throw_orphan_dentries(sb);
657 void ll_kill_super(struct super_block *sb)
659 struct ll_sb_info *sbi;
664 if (!(sb->s_flags & MS_ACTIVE))
668 /* we need restore s_dev from changed for clustred NFS before put_super
669 * because new kernels have cached s_dev and change sb->s_dev in
670 * put_super not affected real removing devices */
672 sb->s_dev = sbi->ll_sdev_orig;
676 char *ll_read_opt(const char *opt, char *data)
682 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
683 if (strncmp(opt, data, strlen(opt)))
685 if ((value = strchr(data, '=')) == NULL)
689 OBD_ALLOC(retval, strlen(value) + 1);
691 CERROR("out of memory!\n");
695 memcpy(retval, value, strlen(value)+1);
696 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
700 static inline int ll_set_opt(const char *opt, char *data, int fl)
702 if (strncmp(opt, data, strlen(opt)) != 0)
708 /* non-client-specific mount options are parsed in lmd_parse */
709 static int ll_options(char *options, int *flags)
712 char *s1 = options, *s2;
718 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
721 CDEBUG(D_SUPER, "next opt=%s\n", s1);
722 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
727 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
732 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
737 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
742 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
747 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
752 tmp = ll_set_opt("acl", s1, LL_SBI_ACL);
754 /* Ignore deprecated mount option. The client will
755 * always try to mount with ACL support, whether this
756 * is used depends on whether server supports it. */
759 tmp = ll_set_opt("noacl", s1, LL_SBI_ACL);
764 tmp = ll_set_opt("checksum", s1, LL_SBI_DATA_CHECKSUM);
769 tmp = ll_set_opt("nochecksum", s1, LL_SBI_DATA_CHECKSUM);
775 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
780 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
785 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
791 s2 = strchr(s1, ',');
799 void ll_lli_init(struct ll_inode_info *lli)
801 lli->lli_inode_magic = LLI_INODE_MAGIC;
802 sema_init(&lli->lli_size_sem, 1);
803 sema_init(&lli->lli_write_sem, 1);
805 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
806 spin_lock_init(&lli->lli_lock);
807 sema_init(&lli->lli_och_sem, 1);
808 lli->lli_mds_read_och = lli->lli_mds_write_och = NULL;
809 lli->lli_mds_exec_och = NULL;
810 lli->lli_open_fd_read_count = lli->lli_open_fd_write_count = 0;
811 lli->lli_open_fd_exec_count = 0;
812 INIT_LIST_HEAD(&lli->lli_dead_list);
813 #ifdef HAVE_CLOSE_THREAD
814 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
819 #define MDCDEV "mdc_dev"
820 static int old_lustre_process_log(struct super_block *sb, char *newprofile,
821 struct config_llog_instance *cfg)
823 struct lustre_sb_info *lsi = s2lsi(sb);
824 struct obd_device *obd;
825 struct lustre_handle mdc_conn = {0, };
826 struct obd_export *exp;
827 char *ptr, *mdt, *profile;
828 char niduuid[10] = "mdtnid0";
830 struct obd_uuid mdc_uuid;
831 struct llog_ctxt *ctxt;
832 struct obd_connect_data ocd = { 0 };
834 int i, rc = 0, recov_bk = 1, failnodes = 0;
837 ll_generate_random_uuid(uuid);
838 class_uuid_unparse(uuid, &mdc_uuid);
839 CDEBUG(D_HA, "generated uuid: %s\n", mdc_uuid.uuid);
841 /* Figure out the old mdt and profile name from new-style profile
842 ("lustre" from "mds/lustre-client") */
844 profile = strchr(mdt, '/');
845 if (profile == NULL) {
846 CDEBUG(D_CONFIG, "Can't find MDT name in %s\n", newprofile);
847 GOTO(out, rc = -EINVAL);
851 ptr = strrchr(profile, '-');
853 CDEBUG(D_CONFIG, "Can't find client name in %s\n", newprofile);
854 GOTO(out, rc = -EINVAL);
858 LCONSOLE_WARN("This looks like an old mount command; I will try to "
859 "contact MDT '%s' for profile '%s'\n", mdt, profile);
861 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
863 ptr = lsi->lsi_lmd->lmd_dev;
864 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
865 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid, 0,0,0);
867 /* Stop at the first failover nid */
872 CERROR("No valid MDT nids found.\n");
873 GOTO(out, rc = -EINVAL);
877 rc = do_lcfg(MDCDEV, 0, LCFG_ATTACH, LUSTRE_MDC_NAME,mdc_uuid.uuid,0,0);
879 GOTO(out_del_uuid, rc);
881 rc = do_lcfg(MDCDEV, 0, LCFG_SETUP, mdt, niduuid, 0, 0);
883 LCONSOLE_ERROR_MSG(0x153, "I couldn't establish a connection "
884 "with the MDT. Check that the MDT host NID "
885 "is correct and the networks are up.\n");
886 GOTO(out_detach, rc);
889 obd = class_name2obd(MDCDEV);
891 GOTO(out_cleanup, rc = -EINVAL);
893 /* Add any failover nids */
894 while (*ptr == ':') {
895 /* New failover node */
896 sprintf(niduuid, "mdtnid%d", failnodes);
898 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
900 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid,0,0,0);
902 CERROR("Add uuid for %s failed %d\n",
903 libcfs_nid2str(nid), rc);
908 rc = do_lcfg(MDCDEV, 0, LCFG_ADD_CONN, niduuid, 0, 0,0);
910 CERROR("Add conn for %s failed %d\n",
911 libcfs_nid2str(nid), rc);
919 /* Try all connections, but only once. */
920 rc = obd_set_info_async(obd->obd_self_export,
921 sizeof(KEY_INIT_RECOV_BACKUP), KEY_INIT_RECOV_BACKUP,
922 sizeof(recov_bk), &recov_bk, NULL);
924 GOTO(out_cleanup, rc);
926 /* If we don't have this then an ACL MDS will refuse the connection */
927 ocd.ocd_connect_flags = OBD_CONNECT_ACL;
929 rc = obd_connect(&mdc_conn, obd, &mdc_uuid, &ocd, NULL);
931 CERROR("cannot connect to %s: rc = %d\n", mdt, rc);
932 GOTO(out_cleanup, rc);
935 exp = class_conn2export(&mdc_conn);
937 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
939 cfg->cfg_flags |= CFG_F_COMPAT146;
942 rc = class_config_parse_llog(ctxt, profile, cfg);
945 * For debugging, it's useful to just dump the log
947 rc = class_config_dump_llog(ctxt, profile, cfg);
952 /* Set the caller's profile name to the old-style */
953 memcpy(newprofile, profile, strlen(profile) + 1);
957 LCONSOLE_ERROR_MSG(0x154, "%s: The configuration '%s' could not"
958 " be read from the MDT '%s'. Make sure this"
959 " client and the MDT are running compatible "
960 "versions of Lustre.\n",
961 obd->obd_name, profile, mdt);
964 LCONSOLE_ERROR_MSG(0x155, "%s: The configuration '%s' could not"
965 " be read from the MDT '%s'. This may be "
966 "the result of communication errors between "
967 "the client and the MDT, or if the MDT is "
968 "not running.\n", obd->obd_name, profile,
973 /* We don't so much care about errors in cleaning up the config llog
974 * connection, as we have already read the config by this point. */
978 do_lcfg(MDCDEV, 0, LCFG_CLEANUP, 0, 0, 0, 0);
981 do_lcfg(MDCDEV, 0, LCFG_DETACH, 0, 0, 0, 0);
984 /* class_add_uuid adds a nid even if the same uuid exists; we might
985 delete any copy here. So they all better match. */
986 for (i = 0; i < failnodes; i++) {
987 sprintf(niduuid, "mdtnid%d", i);
988 do_lcfg(MDCDEV, 0, LCFG_DEL_UUID, niduuid, 0, 0, 0);
990 /* class_import_put will get rid of the additional connections */
996 int ll_fill_super(struct super_block *sb)
998 struct lustre_profile *lprof;
999 struct lustre_sb_info *lsi = s2lsi(sb);
1000 struct ll_sb_info *sbi;
1001 char *osc = NULL, *mdc = NULL;
1002 char *profilenm = get_profile_name(sb);
1003 struct config_llog_instance cfg = {0, };
1004 char ll_instance[sizeof(sb) * 2 + 1];
1008 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
1012 /* client additional sb info */
1013 lsi->lsi_llsbi = sbi = ll_init_sbi();
1019 err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
1021 GOTO(out_free, err);
1023 /* Generate a string unique to this super, in case some joker tries
1024 to mount the same fs at two mount points.
1025 Use the address of the super itself.*/
1026 sprintf(ll_instance, "%p", sb);
1027 cfg.cfg_instance = ll_instance;
1028 cfg.cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1030 /* set up client obds */
1031 if (strchr(profilenm, '/') != NULL) /* COMPAT_146 */
1032 err = -EINVAL; /* skip error messages, use old config code */
1034 err = lustre_process_log(sb, profilenm, &cfg);
1039 oldnamelen = strlen(profilenm) + 1;
1040 /* Temp storage for 1.4.6 profile name */
1041 OBD_ALLOC(oldname, oldnamelen);
1043 memcpy(oldname, profilenm, oldnamelen);
1044 rc = old_lustre_process_log(sb, oldname, &cfg);
1046 /* That worked - update the profile name
1049 OBD_FREE(lsi->lsi_lmd->lmd_profile,
1050 strlen(lsi->lsi_lmd->lmd_profile) + 1);
1051 OBD_ALLOC(lsi->lsi_lmd->lmd_profile,
1052 strlen(oldname) + 1);
1053 if (!lsi->lsi_lmd->lmd_profile) {
1054 OBD_FREE(oldname, oldnamelen);
1055 GOTO(out_free, err = -ENOMEM);
1057 memcpy(lsi->lsi_lmd->lmd_profile, oldname,
1058 strlen(oldname) + 1);
1059 profilenm = get_profile_name(sb);
1060 /* Don't ever try to recover the MGS */
1061 rc = ptlrpc_set_import_active(
1062 lsi->lsi_mgc->u.cli.cl_import, 0);
1064 OBD_FREE(oldname, oldnamelen);
1067 /* end COMPAT_146 */
1069 CERROR("Unable to process log: %d\n", err);
1070 GOTO(out_free, err);
1073 lprof = class_get_profile(profilenm);
1074 if (lprof == NULL) {
1075 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1076 " read from the MGS. Does that filesystem "
1077 "exist?\n", profilenm);
1078 GOTO(out_free, err = -EINVAL);
1080 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1081 lprof->lp_mdc, lprof->lp_osc);
1083 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
1084 strlen(ll_instance) + 2);
1086 GOTO(out_free, err = -ENOMEM);
1087 sprintf(osc, "%s-%s", lprof->lp_osc, ll_instance);
1089 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
1090 strlen(ll_instance) + 2);
1092 GOTO(out_free, err = -ENOMEM);
1093 sprintf(mdc, "%s-%s", lprof->lp_mdc, ll_instance);
1095 /* connections, registrations, sb setup */
1096 err = client_common_fill_super(sb, mdc, osc);
1100 OBD_FREE(mdc, strlen(mdc) + 1);
1102 OBD_FREE(osc, strlen(osc) + 1);
1106 LCONSOLE_WARN("Client %s has started\n", profilenm);
1109 } /* ll_fill_super */
1112 void ll_put_super(struct super_block *sb)
1114 struct config_llog_instance cfg;
1115 char ll_instance[sizeof(sb) * 2 + 1];
1116 struct obd_device *obd;
1117 struct lustre_sb_info *lsi = s2lsi(sb);
1118 struct ll_sb_info *sbi = ll_s2sbi(sb);
1119 char *profilenm = get_profile_name(sb);
1120 int force = 1, next;
1123 CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
1125 sprintf(ll_instance, "%p", sb);
1126 cfg.cfg_instance = ll_instance;
1127 lustre_end_log(sb, NULL, &cfg);
1129 if (sbi->ll_mdc_exp) {
1130 obd = class_exp2obd(sbi->ll_mdc_exp);
1132 force = obd->obd_force;
1135 /* We need to set force before the lov_disconnect in
1136 lustre_common_put_super, since l_d cleans up osc's as well. */
1139 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1141 obd->obd_force = force;
1146 /* Only if client_common_fill_super succeeded */
1147 client_common_put_super(sb);
1151 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) !=NULL) {
1152 class_manual_cleanup(obd);
1156 class_del_profile(profilenm);
1159 lsi->lsi_llsbi = NULL;
1161 lustre_common_put_super(sb);
1163 LCONSOLE_WARN("client %s umount complete\n", ll_instance);
1168 } /* client_put_super */
1170 #ifdef HAVE_REGISTER_CACHE
1171 #include <linux/cache_def.h>
1172 #ifdef HAVE_CACHE_RETURN_INT
1177 ll_shrink_cache(int priority, unsigned int gfp_mask)
1179 struct ll_sb_info *sbi;
1182 list_for_each_entry(sbi, &ll_super_blocks, ll_list)
1183 count += llap_shrink_cache(sbi, priority);
1185 #ifdef HAVE_CACHE_RETURN_INT
1190 struct cache_definition ll_cache_definition = {
1191 .name = "llap_cache",
1192 .shrink = ll_shrink_cache
1194 #endif /* HAVE_REGISTER_CACHE */
1196 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
1198 struct inode *inode = NULL;
1199 /* NOTE: we depend on atomic igrab() -bzzz */
1200 lock_res_and_lock(lock);
1201 if (lock->l_ast_data) {
1202 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
1203 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1204 inode = igrab(lock->l_ast_data);
1206 inode = lock->l_ast_data;
1207 ldlm_lock_debug(NULL, inode->i_state & I_FREEING ?
1209 lock, __FILE__, __func__, __LINE__,
1210 "l_ast_data %p is bogus: magic %08x",
1211 lock->l_ast_data, lli->lli_inode_magic);
1215 unlock_res_and_lock(lock);
1219 static int null_if_equal(struct ldlm_lock *lock, void *data)
1221 if (data == lock->l_ast_data) {
1222 lock->l_ast_data = NULL;
1224 if (lock->l_req_mode != lock->l_granted_mode)
1225 LDLM_ERROR(lock,"clearing inode with ungranted lock");
1228 return LDLM_ITER_CONTINUE;
1231 void ll_clear_inode(struct inode *inode)
1234 struct ll_inode_info *lli = ll_i2info(inode);
1235 struct ll_sb_info *sbi = ll_i2sbi(inode);
1238 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1239 inode->i_generation, inode);
1241 if (S_ISDIR(inode->i_mode)) {
1242 /* these should have been cleared in ll_file_release */
1243 LASSERT(lli->lli_sai == NULL);
1244 LASSERT(lli->lli_opendir_key == NULL);
1245 LASSERT(lli->lli_opendir_pid == 0);
1248 ll_inode2fid(&fid, inode);
1249 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1250 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
1252 LASSERT(!lli->lli_open_fd_write_count);
1253 LASSERT(!lli->lli_open_fd_read_count);
1254 LASSERT(!lli->lli_open_fd_exec_count);
1256 if (lli->lli_mds_write_och)
1257 ll_mdc_real_close(inode, FMODE_WRITE);
1258 if (lli->lli_mds_exec_och) {
1260 CERROR("No FMODE exec, bug exec och is present for "
1261 "inode %ld\n", inode->i_ino);
1262 ll_mdc_real_close(inode, FMODE_EXEC);
1264 if (lli->lli_mds_read_och)
1265 ll_mdc_real_close(inode, FMODE_READ);
1269 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
1270 null_if_equal, inode);
1272 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
1273 lli->lli_smd = NULL;
1276 if (lli->lli_symlink_name) {
1277 OBD_FREE(lli->lli_symlink_name,
1278 strlen(lli->lli_symlink_name) + 1);
1279 lli->lli_symlink_name = NULL;
1282 #ifdef CONFIG_FS_POSIX_ACL
1283 if (lli->lli_posix_acl) {
1284 LASSERT(atomic_read(&lli->lli_posix_acl->a_refcount) == 1);
1285 posix_acl_release(lli->lli_posix_acl);
1286 lli->lli_posix_acl = NULL;
1290 lli->lli_inode_magic = LLI_INODE_DEAD;
1292 #ifdef HAVE_EXPORT___IGET
1293 spin_lock(&sbi->ll_deathrow_lock);
1294 list_del_init(&lli->lli_dead_list);
1295 spin_unlock(&sbi->ll_deathrow_lock);
1300 static int ll_setattr_do_truncate(struct inode *inode, loff_t new_size)
1302 struct ll_sb_info *sbi = ll_i2sbi(inode);
1303 struct ll_inode_info *lli = ll_i2info(inode);
1304 struct lov_stripe_md *lsm = lli->lli_smd;
1306 ldlm_policy_data_t policy = { .l_extent = {new_size,
1308 struct lustre_handle lockh = { 0 };
1309 int local_lock = 0; /* 0 - no local lock;
1310 * 1 - lock taken by lock_extent;
1311 * 2 - by obd_match*/
1316 UNLOCK_INODE_MUTEX(inode);
1317 UP_WRITE_I_ALLOC_SEM(inode);
1319 if (sbi->ll_lockless_truncate_enable &&
1320 (sbi->ll_lco.lco_flags & OBD_CONNECT_TRUNCLOCK)) {
1321 ast_flags = LDLM_FL_BLOCK_GRANTED;
1322 rc = obd_match(sbi->ll_osc_exp, lsm, LDLM_EXTENT,
1323 &policy, LCK_PW, &ast_flags, inode, &lockh);
1327 } else if (rc == 0) {
1328 rc = ll_file_punch(inode, new_size, 1);
1331 /* XXX when we fix the AST intents to pass the discard-range
1332 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
1334 ast_flags = (new_size == 0) ? LDLM_AST_DISCARD_DATA : 0;
1335 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy,
1337 if (likely(rc == 0))
1341 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1342 DOWN_WRITE_I_ALLOC_SEM(inode);
1343 LOCK_INODE_MUTEX(inode);
1345 LOCK_INODE_MUTEX(inode);
1346 DOWN_WRITE_I_ALLOC_SEM(inode);
1348 if (likely(rc == 0)) {
1349 /* Only ll_inode_size_lock is taken at this level.
1350 * lov_stripe_lock() is grabbed by ll_truncate() only over
1351 * call to obd_adjust_kms(). If vmtruncate returns 0, then
1352 * ll_truncate dropped ll_inode_size_lock() */
1353 ll_inode_size_lock(inode, 0);
1355 set_bit(LLI_F_SRVLOCK, &lli->lli_flags);
1356 rc = vmtruncate(inode, new_size);
1357 clear_bit(LLI_F_SRVLOCK, &lli->lli_flags);
1359 LASSERT(atomic_read(&lli->lli_size_sem.count) <= 0);
1360 ll_inode_size_unlock(inode, 0);
1364 if (local_lock == 2)
1365 err = obd_cancel(sbi->ll_osc_exp, lsm, LCK_PW, &lockh);
1367 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
1368 if (unlikely(err != 0)){
1369 CERROR("extent unlock failed: err=%d,"
1370 " unlock method =%d\n", err, local_lock);
1378 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1379 * object(s) determine the file size and mtime. Otherwise, the MDS will
1380 * keep these values until such a time that objects are allocated for it.
1381 * We do the MDS operations first, as it is checking permissions for us.
1382 * We don't to the MDS RPC if there is nothing that we want to store there,
1383 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1384 * going to do an RPC anyways.
1386 * If we are doing a truncate, we will send the mtime and ctime updates
1387 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1388 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1391 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
1393 struct ll_inode_info *lli = ll_i2info(inode);
1394 struct lov_stripe_md *lsm = lli->lli_smd;
1395 struct ll_sb_info *sbi = ll_i2sbi(inode);
1396 struct ptlrpc_request *request = NULL;
1397 struct mdc_op_data op_data;
1398 struct lustre_md md;
1399 int ia_valid = attr->ia_valid;
1403 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu valid %x\n", inode->i_ino,
1405 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_SETATTR, 1);
1407 if (ia_valid & ATTR_SIZE) {
1408 if (attr->ia_size > ll_file_maxbytes(inode)) {
1409 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
1410 attr->ia_size, ll_file_maxbytes(inode));
1414 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1417 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1418 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
1419 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1423 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1424 if (attr->ia_valid & ATTR_CTIME) {
1425 attr->ia_ctime = CURRENT_TIME;
1426 attr->ia_valid |= ATTR_CTIME_SET;
1428 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
1429 attr->ia_atime = CURRENT_TIME;
1430 attr->ia_valid |= ATTR_ATIME_SET;
1432 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
1433 attr->ia_mtime = CURRENT_TIME;
1434 attr->ia_valid |= ATTR_MTIME_SET;
1436 if ((attr->ia_valid & ATTR_CTIME) && !(attr->ia_valid & ATTR_MTIME)) {
1437 /* To avoid stale mtime on mds, obtain it from ost and send
1439 rc = ll_glimpse_size(inode, 0);
1443 attr->ia_valid |= ATTR_MTIME_SET | ATTR_MTIME;
1444 attr->ia_mtime = inode->i_mtime;
1447 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1448 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
1449 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1452 /* NB: ATTR_SIZE will only be set after this point if the size
1453 * resides on the MDS, ie, this file has no objects. */
1455 attr->ia_valid &= ~ATTR_SIZE;
1457 /* We always do an MDS RPC, even if we're only changing the size;
1458 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
1459 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0, NULL);
1461 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
1462 attr, NULL, 0, NULL, 0, &request);
1465 ptlrpc_req_finished(request);
1466 if (rc == -ENOENT) {
1468 /* Unlinked special device node? Or just a race?
1469 * Pretend we done everything. */
1470 if (!S_ISREG(inode->i_mode) &&
1471 !S_ISDIR(inode->i_mode))
1472 rc = inode_setattr(inode, attr);
1473 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY)
1474 CERROR("mdc_setattr fails: rc = %d\n", rc);
1478 rc = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md);
1480 ptlrpc_req_finished(request);
1484 /* We call inode_setattr to adjust timestamps.
1485 * If there is at least some data in file, we cleared ATTR_SIZE above to
1486 * avoid invoking vmtruncate, otherwise it is important to call
1487 * vmtruncate in inode_setattr to update inode->i_size (bug 6196) */
1488 rc = inode_setattr(inode, attr);
1490 ll_update_inode(inode, &md);
1491 ptlrpc_req_finished(request);
1493 if (!lsm || !S_ISREG(inode->i_mode)) {
1494 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
1498 /* We really need to get our PW lock before we change inode->i_size.
1499 * If we don't we can race with other i_size updaters on our node, like
1500 * ll_file_read. We can also race with i_size propogation to other
1501 * nodes through dirtying and writeback of final cached pages. This
1502 * last one is especially bad for racing o_append users on other
1504 if (ia_valid & ATTR_SIZE) {
1505 rc = ll_setattr_do_truncate(inode, attr->ia_size);
1506 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
1508 struct obd_info oinfo = { { { 0 } } };
1512 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1513 inode->i_ino, LTIME_S(attr->ia_mtime));
1516 oa->o_id = lsm->lsm_object_id;
1517 oa->o_valid = OBD_MD_FLID;
1519 flags = OBD_MD_FLTYPE | OBD_MD_FLATIME |
1520 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1521 OBD_MD_FLFID | OBD_MD_FLGENER;
1523 obdo_from_inode(oa, inode, flags);
1528 rc = obd_setattr_rqset(sbi->ll_osc_exp, &oinfo, NULL);
1530 CERROR("obd_setattr_async fails: rc=%d\n", rc);
1539 int ll_setattr(struct dentry *de, struct iattr *attr)
1543 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1544 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1545 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1546 if ((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
1547 (ATTR_SIZE|ATTR_MODE)) {
1548 mode = de->d_inode->i_mode;
1549 if (((mode & S_ISUID) && (!(attr->ia_mode & S_ISUID))) ||
1550 ((mode & S_ISGID) && (mode & S_IXGRP) &&
1551 (!(attr->ia_mode & S_ISGID))))
1552 attr->ia_valid |= ATTR_FORCE;
1555 return ll_setattr_raw(de->d_inode, attr);
1558 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1559 __u64 max_age, __u32 flags)
1561 struct ll_sb_info *sbi = ll_s2sbi(sb);
1562 struct obd_statfs obd_osfs;
1566 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age, flags);
1568 CERROR("mdc_statfs fails: rc = %d\n", rc);
1572 osfs->os_type = sb->s_magic;
1574 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1575 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1577 rc = obd_statfs_rqset(class_exp2obd(sbi->ll_osc_exp),
1578 &obd_osfs, max_age, flags);
1580 CERROR("obd_statfs fails: rc = %d\n", rc);
1584 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1585 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1588 osfs->os_bsize = obd_osfs.os_bsize;
1589 osfs->os_blocks = obd_osfs.os_blocks;
1590 osfs->os_bfree = obd_osfs.os_bfree;
1591 osfs->os_bavail = obd_osfs.os_bavail;
1593 /* If we don't have as many objects free on the OST as inodes
1594 * on the MDS, we reduce the total number of inodes to
1595 * compensate, so that the "inodes in use" number is correct.
1597 if (obd_osfs.os_ffree < osfs->os_ffree) {
1598 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1600 osfs->os_ffree = obd_osfs.os_ffree;
1605 #ifndef HAVE_STATFS_DENTRY_PARAM
1606 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1609 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1611 struct super_block *sb = de->d_sb;
1613 struct obd_statfs osfs;
1616 CDEBUG(D_VFSTRACE, "VFS Op: at "LPU64" jiffies\n", get_jiffies_64());
1617 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1);
1619 /* For now we will always get up-to-date statfs values, but in the
1620 * future we may allow some amount of caching on the client (e.g.
1621 * from QOS or lprocfs updates). */
1622 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - 1, 0);
1626 statfs_unpack(sfs, &osfs);
1628 /* We need to downshift for all 32-bit kernels, because we can't
1629 * tell if the kernel is being called via sys_statfs64() or not.
1630 * Stop before overflowing f_bsize - in which case it is better
1631 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
1632 if (sizeof(long) < 8) {
1633 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1636 osfs.os_blocks >>= 1;
1637 osfs.os_bfree >>= 1;
1638 osfs.os_bavail >>= 1;
1642 sfs->f_blocks = osfs.os_blocks;
1643 sfs->f_bfree = osfs.os_bfree;
1644 sfs->f_bavail = osfs.os_bavail;
1649 void ll_inode_size_lock(struct inode *inode, int lock_lsm)
1651 struct ll_inode_info *lli;
1652 struct lov_stripe_md *lsm;
1654 lli = ll_i2info(inode);
1655 LASSERT(lli->lli_size_sem_owner != current);
1656 down(&lli->lli_size_sem);
1657 LASSERT(lli->lli_size_sem_owner == NULL);
1658 lli->lli_size_sem_owner = current;
1660 LASSERTF(lsm != NULL || lock_lsm == 0, "lsm %p, lock_lsm %d\n",
1663 lov_stripe_lock(lsm);
1666 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm)
1668 struct ll_inode_info *lli;
1669 struct lov_stripe_md *lsm;
1671 lli = ll_i2info(inode);
1673 LASSERTF(lsm != NULL || unlock_lsm == 0, "lsm %p, lock_lsm %d\n",
1676 lov_stripe_unlock(lsm);
1677 LASSERT(lli->lli_size_sem_owner == current);
1678 lli->lli_size_sem_owner = NULL;
1679 up(&lli->lli_size_sem);
1682 static void ll_replace_lsm(struct inode *inode, struct lov_stripe_md *lsm)
1684 struct ll_inode_info *lli = ll_i2info(inode);
1686 dump_lsm(D_INODE, lsm);
1687 dump_lsm(D_INODE, lli->lli_smd);
1688 LASSERTF(lsm->lsm_magic == LOV_MAGIC_JOIN,
1689 "lsm must be joined lsm %p\n", lsm);
1690 obd_free_memmd(ll_i2obdexp(inode), &lli->lli_smd);
1691 CDEBUG(D_INODE, "replace lsm %p to lli_smd %p for inode %lu%u(%p)\n",
1692 lsm, lli->lli_smd, inode->i_ino, inode->i_generation, inode);
1694 lli->lli_maxbytes = lsm->lsm_maxbytes;
1695 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1696 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1699 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1701 struct ll_inode_info *lli = ll_i2info(inode);
1702 struct mds_body *body = md->body;
1703 struct lov_stripe_md *lsm = md->lsm;
1705 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1707 if (lli->lli_smd == NULL) {
1708 if (lsm->lsm_magic != LOV_MAGIC &&
1709 lsm->lsm_magic != LOV_MAGIC_JOIN) {
1710 dump_lsm(D_ERROR, lsm);
1713 CDEBUG(D_INODE, "adding lsm %p to inode %lu/%u(%p)\n",
1714 lsm, inode->i_ino, inode->i_generation, inode);
1715 /* ll_inode_size_lock() requires it is only called
1716 * with lli_smd != NULL or lock_lsm == 0 or we can
1717 * race between lock/unlock. bug 9547 */
1719 lli->lli_maxbytes = lsm->lsm_maxbytes;
1720 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1721 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1723 if (lli->lli_smd->lsm_magic == lsm->lsm_magic &&
1724 lli->lli_smd->lsm_stripe_count ==
1725 lsm->lsm_stripe_count) {
1726 if (lov_stripe_md_cmp(lli->lli_smd, lsm)) {
1727 CERROR("lsm mismatch for inode %ld\n",
1729 CERROR("lli_smd:\n");
1730 dump_lsm(D_ERROR, lli->lli_smd);
1732 dump_lsm(D_ERROR, lsm);
1736 ll_replace_lsm(inode, lsm);
1738 if (lli->lli_smd != lsm)
1739 obd_free_memmd(ll_i2obdexp(inode), &lsm);
1742 #ifdef CONFIG_FS_POSIX_ACL
1743 LASSERT(!md->posix_acl || (body->valid & OBD_MD_FLACL));
1744 if (body->valid & OBD_MD_FLACL) {
1745 spin_lock(&lli->lli_lock);
1746 if (lli->lli_posix_acl)
1747 posix_acl_release(lli->lli_posix_acl);
1748 lli->lli_posix_acl = md->posix_acl;
1749 spin_unlock(&lli->lli_lock);
1753 if (body->valid & OBD_MD_FLID)
1754 inode->i_ino = body->ino;
1755 if (body->valid & OBD_MD_FLATIME &&
1756 body->atime > LTIME_S(inode->i_atime))
1757 LTIME_S(inode->i_atime) = body->atime;
1759 /* mtime is always updated with ctime, but can be set in past.
1760 As write and utime(2) may happen within 1 second, and utime's
1761 mtime has a priority over write's one, so take mtime from mds
1762 for the same ctimes. */
1763 if (body->valid & OBD_MD_FLCTIME &&
1764 body->ctime >= LTIME_S(inode->i_ctime)) {
1765 LTIME_S(inode->i_ctime) = body->ctime;
1766 if (body->valid & OBD_MD_FLMTIME) {
1767 CDEBUG(D_INODE, "setting ino %lu mtime "
1768 "from %lu to "LPU64"\n", inode->i_ino,
1769 LTIME_S(inode->i_mtime), body->mtime);
1770 LTIME_S(inode->i_mtime) = body->mtime;
1773 if (body->valid & OBD_MD_FLMODE)
1774 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1775 if (body->valid & OBD_MD_FLTYPE)
1776 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1777 if (S_ISREG(inode->i_mode)) {
1778 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
1780 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
1782 #ifdef HAVE_INODE_BLKSIZE
1783 inode->i_blksize = 1<<inode->i_blkbits;
1785 if (body->valid & OBD_MD_FLUID)
1786 inode->i_uid = body->uid;
1787 if (body->valid & OBD_MD_FLGID)
1788 inode->i_gid = body->gid;
1789 if (body->valid & OBD_MD_FLFLAGS)
1790 inode->i_flags = ll_ext_to_inode_flags(body->flags);
1791 if (body->valid & OBD_MD_FLNLINK)
1792 inode->i_nlink = body->nlink;
1793 if (body->valid & OBD_MD_FLGENER)
1794 inode->i_generation = body->generation;
1795 if (body->valid & OBD_MD_FLRDEV)
1796 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1797 inode->i_rdev = body->rdev;
1799 inode->i_rdev = old_decode_dev(body->rdev);
1801 if (body->valid & OBD_MD_FLSIZE) {
1802 #if 0 /* Can't block ll_test_inode->ll_update_inode, b=14326*/
1803 ll_inode_size_lock(inode, 0);
1804 i_size_write(inode, body->size);
1805 ll_inode_size_unlock(inode, 0);
1807 inode->i_size = body->size;
1810 if (body->valid & OBD_MD_FLBLOCKS)
1811 inode->i_blocks = body->blocks;
1813 if (body->valid & OBD_MD_FLSIZE)
1814 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1817 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
1818 static struct backing_dev_info ll_backing_dev_info = {
1819 .ra_pages = 0, /* No readahead */
1820 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
1821 .capabilities = 0, /* Does contribute to dirty memory */
1823 .memory_backed = 0, /* Does contribute to dirty memory */
1828 void ll_read_inode2(struct inode *inode, void *opaque)
1830 struct lustre_md *md = opaque;
1831 struct ll_inode_info *lli = ll_i2info(inode);
1834 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1835 inode->i_generation, inode);
1839 LASSERT(!lli->lli_smd);
1841 /* Core attributes from the MDS first. This is a new inode, and
1842 * the VFS doesn't zero times in the core inode so we have to do
1843 * it ourselves. They will be overwritten by either MDS or OST
1844 * attributes - we just need to make sure they aren't newer. */
1845 LTIME_S(inode->i_mtime) = 0;
1846 LTIME_S(inode->i_atime) = 0;
1847 LTIME_S(inode->i_ctime) = 0;
1849 ll_update_inode(inode, md);
1851 /* OIDEBUG(inode); */
1853 if (S_ISREG(inode->i_mode)) {
1854 struct ll_sb_info *sbi = ll_i2sbi(inode);
1855 inode->i_op = &ll_file_inode_operations;
1856 inode->i_fop = sbi->ll_fop;
1857 inode->i_mapping->a_ops = &ll_aops;
1859 } else if (S_ISDIR(inode->i_mode)) {
1860 inode->i_op = &ll_dir_inode_operations;
1861 inode->i_fop = &ll_dir_operations;
1862 inode->i_mapping->a_ops = &ll_dir_aops;
1864 } else if (S_ISLNK(inode->i_mode)) {
1865 inode->i_op = &ll_fast_symlink_inode_operations;
1868 inode->i_op = &ll_special_inode_operations;
1870 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1871 init_special_inode(inode, inode->i_mode,
1872 kdev_t_to_nr(inode->i_rdev));
1874 /* initializing backing dev info. */
1875 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
1877 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1883 int ll_iocontrol(struct inode *inode, struct file *file,
1884 unsigned int cmd, unsigned long arg)
1886 struct ll_sb_info *sbi = ll_i2sbi(inode);
1887 struct ptlrpc_request *req = NULL;
1892 case EXT3_IOC_GETFLAGS: {
1894 struct mds_body *body;
1896 ll_inode2fid(&fid, inode);
1897 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, OBD_MD_FLFLAGS,0,&req);
1899 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1903 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1906 /* We want to return EXT3_*_FL flags to the caller via this
1907 * ioctl. An older MDS may be sending S_* flags, fix it up. */
1908 flags = ll_inode_to_ext_flags(body->flags,
1909 body->flags &MDS_BFLAG_EXT_FLAGS);
1910 ptlrpc_req_finished (req);
1912 RETURN(put_user(flags, (int *)arg));
1914 case EXT3_IOC_SETFLAGS: {
1915 struct mdc_op_data op_data;
1916 struct ll_iattr_struct attr;
1917 struct obd_info oinfo = { { { 0 } } };
1918 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1920 if (get_user(flags, (int *)arg))
1924 OBDO_ALLOC(oinfo.oi_oa);
1928 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0, NULL);
1930 memset(&attr, 0, sizeof(attr));
1931 attr.ia_attr_flags = flags;
1932 ((struct iattr *)&attr)->ia_valid |= ATTR_ATTR_FLAG;
1934 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
1935 (struct iattr *)&attr, NULL, 0, NULL, 0, &req);
1936 ptlrpc_req_finished(req);
1937 if (rc || lsm == NULL) {
1938 OBDO_FREE(oinfo.oi_oa);
1942 oinfo.oi_oa->o_id = lsm->lsm_object_id;
1943 oinfo.oi_oa->o_flags = flags;
1944 oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS;
1946 obdo_from_inode(oinfo.oi_oa, inode,
1947 OBD_MD_FLFID | OBD_MD_FLGENER);
1948 rc = obd_setattr_rqset(sbi->ll_osc_exp, &oinfo, NULL);
1949 OBDO_FREE(oinfo.oi_oa);
1951 if (rc != -EPERM && rc != -EACCES)
1952 CERROR("mdc_setattr_async fails: rc = %d\n", rc);
1956 inode->i_flags = ll_ext_to_inode_flags(flags |
1957 MDS_BFLAG_EXT_FLAGS);
1967 /* umount -f client means force down, don't save state */
1968 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
1969 void ll_umount_begin(struct vfsmount *vfsmnt, int flags)
1971 struct super_block *sb = vfsmnt->mnt_sb;
1973 void ll_umount_begin(struct super_block *sb)
1976 struct lustre_sb_info *lsi = s2lsi(sb);
1977 struct ll_sb_info *sbi = ll_s2sbi(sb);
1978 struct obd_device *obd;
1979 struct obd_ioctl_data ioc_data = { 0 };
1982 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
1983 if (!(flags & MNT_FORCE)) {
1989 /* Tell the MGC we got umount -f */
1990 lsi->lsi_flags |= LSI_UMOUNT_FORCE;
1992 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
1993 sb->s_count, atomic_read(&sb->s_active));
1995 obd = class_exp2obd(sbi->ll_mdc_exp);
1997 CERROR("Invalid MDC connection handle "LPX64"\n",
1998 sbi->ll_mdc_exp->exp_handle.h_cookie);
2003 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_mdc_exp, sizeof ioc_data,
2006 obd = class_exp2obd(sbi->ll_osc_exp);
2008 CERROR("Invalid LOV connection handle "LPX64"\n",
2009 sbi->ll_osc_exp->exp_handle.h_cookie);
2015 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_osc_exp, sizeof ioc_data,
2018 /* Really, we'd like to wait until there are no requests outstanding,
2019 * and then continue. For now, we just invalidate the requests,
2020 * schedule, and hope.
2027 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2029 struct ll_sb_info *sbi = ll_s2sbi(sb);
2033 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
2034 read_only = *flags & MS_RDONLY;
2035 err = obd_set_info_async(sbi->ll_mdc_exp, sizeof(KEY_READONLY),
2036 KEY_READONLY, sizeof(read_only),
2039 CERROR("Failed to change the read-only flag during "
2040 "remount: %d\n", err);
2045 sb->s_flags |= MS_RDONLY;
2047 sb->s_flags &= ~MS_RDONLY;
2052 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
2053 struct ptlrpc_request *req, int offset,struct super_block *sb)
2055 struct lustre_md md;
2056 struct ll_sb_info *sbi = NULL;
2060 LASSERT(*inode || sb);
2061 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2062 prune_deathrow(sbi, 1);
2064 rc = mdc_req2lustre_md(req, offset, exp, &md);
2069 ll_update_inode(*inode, &md);
2072 *inode = ll_iget(sb, md.body->ino, &md);
2073 if (*inode == NULL || is_bad_inode(*inode)) {
2074 mdc_free_lustre_md(exp, &md);
2076 CERROR("new_inode -fatal: rc %d\n", rc);
2081 rc = obd_checkmd(exp, ll_i2mdcexp(*inode),
2082 ll_i2info(*inode)->lli_smd);
2087 char *llap_origins[] = {
2088 [LLAP_ORIGIN_UNKNOWN] = "--",
2089 [LLAP_ORIGIN_READPAGE] = "rp",
2090 [LLAP_ORIGIN_READAHEAD] = "ra",
2091 [LLAP_ORIGIN_COMMIT_WRITE] = "cw",
2092 [LLAP_ORIGIN_WRITEPAGE] = "wp",
2093 [LLAP_ORIGIN_LOCKLESS_IO] = "ls"
2096 struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
2097 struct list_head *list)
2099 struct ll_async_page *llap;
2100 struct list_head *pos;
2102 list_for_each(pos, list) {
2103 if (pos == &sbi->ll_pglist)
2105 llap = list_entry(pos, struct ll_async_page, llap_pglist_item);
2106 if (llap->llap_page == NULL)
2114 int ll_obd_statfs(struct inode *inode, void *arg)
2116 struct ll_sb_info *sbi = NULL;
2117 struct obd_device *client_obd = NULL, *lov_obd = NULL;
2118 struct lov_obd *lov = NULL;
2119 struct obd_statfs stat_buf = {0};
2121 struct obd_ioctl_data *data = NULL;
2125 if (!inode || !(sbi = ll_i2sbi(inode)))
2126 GOTO(out_statfs, rc = -EINVAL);
2128 rc = obd_ioctl_getdata(&buf, &len, arg);
2130 GOTO(out_statfs, rc);
2133 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2134 !data->ioc_pbuf1 || !data->ioc_pbuf2)
2135 GOTO(out_statfs, rc = -EINVAL);
2137 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2138 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
2140 if (type == LL_STATFS_MDC) {
2142 GOTO(out_statfs, rc = -ENODEV);
2143 client_obd = class_exp2obd(sbi->ll_mdc_exp);
2144 } else if (type == LL_STATFS_LOV) {
2145 lov_obd = class_exp2obd(sbi->ll_osc_exp);
2146 lov = &lov_obd->u.lov;
2148 if (index >= lov->desc.ld_tgt_count)
2149 GOTO(out_statfs, rc = -ENODEV);
2151 if (!lov->lov_tgts[index])
2152 /* Try again with the next index */
2153 GOTO(out_statfs, rc = -EAGAIN);
2155 client_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
2156 if (!lov->lov_tgts[index]->ltd_active)
2157 GOTO(out_uuid, rc = -ENODATA);
2161 GOTO(out_statfs, rc = -EINVAL);
2163 rc = obd_statfs(client_obd, &stat_buf, cfs_time_current_64() - HZ, 1);
2165 GOTO(out_statfs, rc);
2167 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
2168 GOTO(out_statfs, rc = -EFAULT);
2171 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(client_obd),
2177 obd_ioctl_freedata(buf, len);
2181 int ll_process_config(struct lustre_cfg *lcfg)
2185 struct lprocfs_static_vars lvars;
2189 lprocfs_llite_init_vars(&lvars);
2191 /* The instance name contains the sb: lustre-client-aacfe000 */
2192 ptr = strrchr(lustre_cfg_string(lcfg, 0), '-');
2193 if (!ptr || !*(++ptr))
2195 if (sscanf(ptr, "%lx", &x) != 1)
2198 /* This better be a real Lustre superblock! */
2199 LASSERT(s2lsi((struct super_block *)sb)->lsi_lmd->lmd_magic == LMD_MAGIC);
2201 /* Note we have not called client_common_fill_super yet, so
2202 proc fns must be able to handle that! */
2203 rc = class_process_proc_param(PARAM_LLITE, lvars.obd_vars,