1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/llite/llite_lib.c
38 * Lustre Light Super operations
41 #define DEBUG_SUBSYSTEM S_LLITE
43 #include <linux/module.h>
44 #include <linux/types.h>
45 #include <linux/random.h>
46 #include <linux/version.h>
48 #include <lustre_lite.h>
49 #include <lustre_ha.h>
50 #include <lustre_dlm.h>
51 #include <lprocfs_status.h>
52 #include <lustre_disk.h>
53 #include <lustre_param.h>
54 #include <lustre_cache.h>
55 #include <obd_support.h>
56 #include "llite_internal.h"
58 cfs_mem_cache_t *ll_file_data_slab;
60 LIST_HEAD(ll_super_blocks);
61 struct rw_semaphore ll_sb_sem;
63 extern struct address_space_operations ll_aops;
64 extern struct address_space_operations ll_dir_aops;
67 #define log2(n) ffz(~(n))
70 static void ll_pglist_fini(struct ll_sb_info *sbi)
75 if (sbi->ll_pglist == NULL)
78 for_each_possible_cpu(i) {
79 page = sbi->ll_pglist[i]->llpd_page;
81 sbi->ll_pglist[i] = NULL;
86 OBD_FREE(sbi->ll_pglist, sizeof(void *)*num_possible_cpus());
87 sbi->ll_pglist = NULL;
90 static int ll_pglist_init(struct ll_sb_info *sbi)
92 struct ll_pglist_data *pd;
97 OBD_ALLOC(sbi->ll_pglist, sizeof(void *) * num_possible_cpus());
98 if (sbi->ll_pglist == NULL)
101 budget = sbi->ll_async_page_max / num_online_cpus();
102 for_each_possible_cpu(i) {
103 struct page *page = alloc_pages_node(cpu_to_node(i),
110 if (color + L1_CACHE_ALIGN(sizeof(*pd)) > PAGE_SIZE)
113 pd = (struct ll_pglist_data *)(page_address(page) + color);
114 memset(pd, 0, sizeof(*pd));
115 spin_lock_init(&pd->llpd_lock);
116 INIT_LIST_HEAD(&pd->llpd_list);
118 pd->llpd_budget = budget;
120 pd->llpd_page = page;
121 atomic_set(&pd->llpd_sample_count, 0);
122 sbi->ll_pglist[i] = pd;
123 color += L1_CACHE_ALIGN(sizeof(*pd));
129 static struct ll_sb_info *ll_init_sbi(void)
131 struct ll_sb_info *sbi = NULL;
138 OBD_ALLOC(sbi, sizeof(*sbi));
142 OBD_ALLOC(sbi->ll_async_page_sample, sizeof(long)*num_possible_cpus());
143 if (sbi->ll_async_page_sample == NULL)
146 spin_lock_init(&sbi->ll_lock);
147 init_mutex(&sbi->ll_lco.lco_lock);
148 spin_lock_init(&sbi->ll_pp_extent_lock);
149 spin_lock_init(&sbi->ll_process_lock);
150 sbi->ll_rw_stats_on = 0;
153 pages = si.totalram - si.totalhigh;
154 if (pages >> (20 - CFS_PAGE_SHIFT) < 512) {
155 #ifdef HAVE_BGL_SUPPORT
156 sbi->ll_async_page_max = pages / 4;
158 sbi->ll_async_page_max = pages / 2;
161 sbi->ll_async_page_max = (pages / 4) * 3;
164 lcounter_init(&sbi->ll_async_page_count);
165 spin_lock_init(&sbi->ll_async_page_reblnc_lock);
166 sbi->ll_async_page_sample_max = 64 * num_online_cpus();
167 sbi->ll_async_page_reblnc_count = 0;
168 sbi->ll_async_page_clock_hand = 0;
169 if (ll_pglist_init(sbi))
172 sbi->ll_ra_info.ra_max_pages_per_file = min(pages / 32,
173 SBI_DEFAULT_READAHEAD_MAX);
174 sbi->ll_ra_info.ra_max_pages = sbi->ll_ra_info.ra_max_pages_per_file;
175 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
176 SBI_DEFAULT_READAHEAD_WHOLE_MAX;
177 sbi->ll_contention_time = SBI_DEFAULT_CONTENTION_SECONDS;
178 sbi->ll_lockless_truncate_enable = SBI_DEFAULT_LOCKLESS_TRUNCATE_ENABLE;
179 sbi->ll_direct_io_default = SBI_DEFAULT_DIRECT_IO_DEFAULT;
180 INIT_LIST_HEAD(&sbi->ll_conn_chain);
181 INIT_LIST_HEAD(&sbi->ll_orphan_dentry_list);
183 ll_generate_random_uuid(uuid);
184 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
185 CDEBUG(D_CONFIG, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
187 down_write(&ll_sb_sem);
188 list_add_tail(&sbi->ll_list, &ll_super_blocks);
189 up_write(&ll_sb_sem);
191 #ifdef ENABLE_CHECKSUM
192 sbi->ll_flags |= LL_SBI_DATA_CHECKSUM;
194 #ifdef ENABLE_LLITE_CHECKSUM
195 sbi->ll_flags |= LL_SBI_LLITE_CHECKSUM;
198 #ifdef HAVE_LRU_RESIZE_SUPPORT
199 sbi->ll_flags |= LL_SBI_LRU_RESIZE;
202 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
203 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_r_hist.oh_lock);
204 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_w_hist.oh_lock);
207 /* metadata statahead is enabled by default */
208 sbi->ll_sa_max = LL_SA_RPC_DEF;
213 if (sbi->ll_async_page_sample)
214 OBD_FREE(sbi->ll_async_page_sample,
215 sizeof(long) * num_possible_cpus());
217 OBD_FREE(sbi, sizeof(*sbi));
221 void ll_free_sbi(struct super_block *sb)
223 struct ll_sb_info *sbi = ll_s2sbi(sb);
227 down_write(&ll_sb_sem);
228 list_del(&sbi->ll_list);
229 up_write(&ll_sb_sem);
230 /* dont allow find cache via sb list first */
232 lcounter_destroy(&sbi->ll_async_page_count);
233 OBD_FREE(sbi->ll_async_page_sample,
234 sizeof(long) * num_possible_cpus());
235 OBD_FREE(sbi, sizeof(*sbi));
240 static struct dentry_operations ll_d_root_ops = {
241 .d_compare = ll_dcompare,
242 .d_revalidate = ll_revalidate_nd,
245 static int client_common_fill_super(struct super_block *sb,
246 char *mdc, char *osc)
248 struct inode *root = 0;
249 struct ll_sb_info *sbi = ll_s2sbi(sb);
250 struct obd_device *obd;
251 struct ll_fid rootfid;
252 struct obd_statfs osfs;
253 struct ptlrpc_request *request = NULL;
254 struct lustre_handle osc_conn = {0, };
255 struct lustre_handle mdc_conn = {0, };
257 struct obd_connect_data *data = NULL;
261 obd = class_name2obd(mdc);
263 CERROR("MDC %s: not setup or attached\n", mdc);
267 OBD_ALLOC(data, sizeof(*data));
271 if (proc_lustre_fs_root) {
272 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
275 CERROR("could not register mount in /proc/fs/lustre\n");
278 /* indicate the features supported by this client */
279 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_IBITS |
280 OBD_CONNECT_JOIN | OBD_CONNECT_ATTRFID |
281 OBD_CONNECT_NODEVOH | OBD_CONNECT_CANCELSET |
282 OBD_CONNECT_AT | OBD_CONNECT_FID |
283 OBD_CONNECT_VBR | OBD_CONNECT_LOV_V3;
284 #ifdef HAVE_LRU_RESIZE_SUPPORT
285 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
286 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
288 #ifdef CONFIG_FS_POSIX_ACL
289 data->ocd_connect_flags |= OBD_CONNECT_ACL;
291 data->ocd_ibits_known = MDS_INODELOCK_FULL;
292 data->ocd_version = LUSTRE_VERSION_CODE;
294 if (sb->s_flags & MS_RDONLY)
295 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
296 if (sbi->ll_flags & LL_SBI_USER_XATTR)
297 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
299 #ifdef HAVE_MS_FLOCK_LOCK
300 /* force vfs to use lustre handler for flock() calls - bug 10743 */
301 sb->s_flags |= MS_FLOCK_LOCK;
304 if (sbi->ll_flags & LL_SBI_FLOCK)
305 sbi->ll_fop = &ll_file_operations_flock;
306 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
307 sbi->ll_fop = &ll_file_operations;
309 sbi->ll_fop = &ll_file_operations_noflock;
312 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid, data, &sbi->ll_mdc_exp);
314 LCONSOLE_ERROR_MSG(0x14f, "An MDT (mdc %s) is performing "
315 "recovery, of which this client is not a "
316 "part. Please wait for recovery to complete,"
317 " abort, or time out.\n", mdc);
320 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
324 err = obd_fid_init(sbi->ll_mdc_exp);
328 err = obd_statfs(obd, &osfs,
329 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), 0);
333 /* MDC connect is surely finished by now because we actually sent
334 * a statfs RPC, otherwise obd_connect() is asynchronous. */
335 *data = class_exp2cliimp(sbi->ll_mdc_exp)->imp_connect_data;
337 LASSERT(osfs.os_bsize);
338 sb->s_blocksize = osfs.os_bsize;
339 sb->s_blocksize_bits = log2(osfs.os_bsize);
340 sb->s_magic = LL_SUPER_MAGIC;
342 /* for bug 11559. in $LINUX/fs/read_write.c, function do_sendfile():
343 * retval = in_file->f_op->sendfile(...);
345 * retval = -EOVERFLOW;
347 * it will check if *ppos is greater than max. However, max equals to
348 * s_maxbytes, which is a negative integer in a x86_64 box since loff_t
349 * has been defined as a signed long long ineger in linux kernel. */
350 #if BITS_PER_LONG == 64
351 sb->s_maxbytes = PAGE_CACHE_MAXBYTES >> 1;
353 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
355 sbi->ll_namelen = osfs.os_namelen;
356 sbi->ll_max_rw_chunk = LL_DEFAULT_MAX_RW_CHUNK;
358 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
359 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
360 LCONSOLE_INFO("Disabling user_xattr feature because "
361 "it is not supported on the server\n");
362 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
365 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
367 sb->s_flags |= MS_POSIXACL;
369 sbi->ll_flags |= LL_SBI_ACL;
371 sbi->ll_flags &= ~LL_SBI_ACL;
373 if (data->ocd_connect_flags & OBD_CONNECT_JOIN)
374 sbi->ll_flags |= LL_SBI_JOIN;
376 obd = class_name2obd(osc);
378 CERROR("OSC %s: not setup or attached\n", osc);
379 GOTO(out_mdc, err = -ENODEV);
382 data->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_GRANT |
383 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
384 OBD_CONNECT_SRVLOCK | OBD_CONNECT_CANCELSET|
385 OBD_CONNECT_AT | OBD_CONNECT_FID |
386 OBD_CONNECT_VBR | OBD_CONNECT_TRUNCLOCK;
388 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_CKSUM)) {
389 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
390 * disabled by default, because it can still be enabled on the
391 * fly via /proc. As a consequence, we still need to come to an
392 * agreement on the supported algorithms at connect time */
393 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
395 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
396 data->ocd_cksum_types = OBD_CKSUM_ADLER;
398 /* send the list of supported checksum types */
399 data->ocd_cksum_types = OBD_CKSUM_ALL;
402 #ifdef HAVE_LRU_RESIZE_SUPPORT
403 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
404 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
407 CDEBUG(D_RPCTRACE, "ocd_connect_flags: "LPX64" ocd_version: %d "
408 "ocd_grant: %d\n", data->ocd_connect_flags,
409 data->ocd_version, data->ocd_grant);
411 obd->obd_upcall.onu_owner = &sbi->ll_lco;
412 obd->obd_upcall.onu_upcall = ll_ocd_update;
413 data->ocd_brw_size = PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT;
415 /* ask lov to generate OBD_NOTIFY_CREATE events for already registered
417 obd_notify(obd, NULL, OBD_NOTIFY_CREATE, NULL);
419 obd_register_lock_cancel_cb(obd, ll_extent_lock_cancel_cb);
420 obd_register_page_removal_cb(obd, ll_page_removal_cb, ll_pin_extent_cb);
422 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid, data, &sbi->ll_osc_exp);
424 LCONSOLE_ERROR_MSG(0x150, "An OST (osc %s) is performing "
425 "recovery, of which this client is not a "
426 "part. Please wait for recovery to "
427 "complete, abort, or time out.\n", osc);
430 CERROR("cannot connect to %s: rc = %d\n", osc, err);
434 mutex_down(&sbi->ll_lco.lco_lock);
435 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
436 sbi->ll_lco.lco_mdc_exp = sbi->ll_mdc_exp;
437 sbi->ll_lco.lco_osc_exp = sbi->ll_osc_exp;
438 mutex_up(&sbi->ll_lco.lco_lock);
440 err = mdc_init_ea_size(sbi->ll_mdc_exp, sbi->ll_osc_exp);
442 CERROR("cannot set max EA and cookie sizes: rc = %d\n", err);
446 err = obd_prep_async_page(sbi->ll_osc_exp, NULL, NULL, NULL,
447 0, NULL, NULL, NULL, 0, NULL);
449 LCONSOLE_ERROR_MSG(0x151, "There are no OST's in this "
450 "filesystem. There must be at least one "
451 "active OST for a client to start.\n");
455 if (!ll_async_page_slab) {
456 ll_async_page_slab_size =
457 size_round(sizeof(struct ll_async_page)) + err;
458 ll_async_page_slab = cfs_mem_cache_create("ll_async_page",
459 ll_async_page_slab_size,
461 if (!ll_async_page_slab)
462 GOTO(out_osc, err = -ENOMEM);
465 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
467 CERROR("cannot mds_connect: rc = %d\n", err);
470 CDEBUG(D_SUPER, "rootfid "LPU64":"DFID"\n", rootfid.id,
471 PFID((struct lu_fid*)&rootfid));
472 sbi->ll_rootino = rootfid.id;
474 sb->s_op = &lustre_super_operations;
475 #if THREAD_SIZE >= 8192
476 /* Disable the NFS export because of stack overflow
477 * when THREAD_SIZE < 8192. Please refer to 17630. */
478 sb->s_export_op = &lustre_export_operations;
482 * XXX: move this to after cbd setup? */
483 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
484 OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS |
485 (sbi->ll_flags & LL_SBI_ACL ? OBD_MD_FLACL : 0),
488 CERROR("mdc_getattr failed for root: rc = %d\n", err);
492 err = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md);
494 CERROR("failed to understand root inode md: rc = %d\n",err);
495 ptlrpc_req_finished (request);
499 LASSERT(sbi->ll_rootino != 0);
500 root = ll_iget(sb, ll_fid_build_ino(sbi, &rootfid), &md);
502 ptlrpc_req_finished(request);
504 if (root == NULL || is_bad_inode(root)) {
505 mdc_free_lustre_md(sbi->ll_osc_exp, &md);
506 CERROR("lustre_lite: bad iget4 for root\n");
507 GOTO(out_root, err = -EBADF);
510 err = ll_close_thread_start(&sbi->ll_lcq);
512 CERROR("cannot start close thread: rc %d\n", err);
516 checksum = sbi->ll_flags & LL_SBI_DATA_CHECKSUM;
517 err = obd_set_info_async(sbi->ll_osc_exp, sizeof(KEY_CHECKSUM),
518 KEY_CHECKSUM, sizeof(checksum),
521 /* making vm readahead 0 for 2.4.x. In the case of 2.6.x,
522 backing dev info assigned to inode mapping is used for
523 determining maximal readahead. */
524 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) && \
525 !defined(KERNEL_HAS_AS_MAX_READAHEAD)
526 /* bug 2805 - set VM readahead to zero */
527 vm_max_readahead = vm_min_readahead = 0;
530 sb->s_root = d_alloc_root(root);
532 OBD_FREE(data, sizeof(*data));
533 sb->s_root->d_op = &ll_d_root_ops;
535 sbi->ll_sdev_orig = sb->s_dev;
536 /* We set sb->s_dev equal on all lustre clients in order to support
537 * NFS export clustering. NFSD requires that the FSID be the same
539 /* s_dev is also used in lt_compare() to compare two fs, but that is
540 * only a node-local comparison. */
541 sb->s_dev = get_uuid2int(sbi2mdc(sbi)->cl_target_uuid.uuid,
542 strlen(sbi2mdc(sbi)->cl_target_uuid.uuid));
550 obd_disconnect(sbi->ll_osc_exp);
551 sbi->ll_osc_exp = NULL;
553 obd = class_name2obd(osc);
554 obd_unregister_lock_cancel_cb(obd, ll_extent_lock_cancel_cb);
555 obd_unregister_page_removal_cb(obd, ll_page_removal_cb);
557 obd_fid_fini(sbi->ll_mdc_exp);
558 obd_disconnect(sbi->ll_mdc_exp);
559 sbi->ll_mdc_exp = NULL;
562 OBD_FREE(data, sizeof(*data));
563 lprocfs_unregister_mountpoint(sbi);
567 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
571 *lmmsize = obd_size_diskmd(sbi->ll_osc_exp, NULL);
573 rc = obd_get_info(sbi->ll_mdc_exp, sizeof(KEY_MAX_EASIZE),
574 KEY_MAX_EASIZE, &size, lmmsize, NULL);
576 CERROR("Get max mdsize error rc %d \n", rc);
581 void ll_dump_inode(struct inode *inode)
583 struct list_head *tmp;
584 int dentry_count = 0;
586 LASSERT(inode != NULL);
588 list_for_each(tmp, &inode->i_dentry)
591 CERROR("inode %p dump: dev=%s ino=%lu mode=%o count=%u, %d dentries\n",
592 inode, ll_i2mdcexp(inode)->exp_obd->obd_name, inode->i_ino,
593 inode->i_mode, atomic_read(&inode->i_count), dentry_count);
596 void lustre_dump_dentry(struct dentry *dentry, int recur)
598 struct list_head *tmp;
601 LASSERT(dentry != NULL);
603 list_for_each(tmp, &dentry->d_subdirs)
606 CERROR("dentry %p dump: name=%.*s parent=%.*s (%p), inode=%p, count=%u,"
607 " flags=0x%x, fsdata=%p, %d subdirs\n", dentry,
608 dentry->d_name.len, dentry->d_name.name,
609 dentry->d_parent->d_name.len, dentry->d_parent->d_name.name,
610 dentry->d_parent, dentry->d_inode, atomic_read(&dentry->d_count),
611 dentry->d_flags, dentry->d_fsdata, subdirs);
612 if (dentry->d_inode != NULL)
613 ll_dump_inode(dentry->d_inode);
618 list_for_each(tmp, &dentry->d_subdirs) {
619 struct dentry *d = list_entry(tmp, struct dentry, d_child);
620 lustre_dump_dentry(d, recur - 1);
624 void client_common_put_super(struct super_block *sb)
626 struct ll_sb_info *sbi = ll_s2sbi(sb);
629 ll_close_thread_shutdown(sbi->ll_lcq);
631 lprocfs_unregister_mountpoint(sbi);
633 list_del(&sbi->ll_conn_chain);
635 /* callbacks is cleared after disconnect each target */
636 obd_disconnect(sbi->ll_osc_exp);
637 sbi->ll_osc_exp = NULL;
639 obd_fid_fini(sbi->ll_mdc_exp);
640 obd_disconnect(sbi->ll_mdc_exp);
641 sbi->ll_mdc_exp = NULL;
646 void ll_kill_super(struct super_block *sb)
648 struct ll_sb_info *sbi;
653 if (!(sb->s_flags & MS_ACTIVE))
657 /* we need restore s_dev from changed for clustred NFS before put_super
658 * because new kernels have cached s_dev and change sb->s_dev in
659 * put_super not affected real removing devices */
661 sb->s_dev = sbi->ll_sdev_orig;
665 char *ll_read_opt(const char *opt, char *data)
671 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
672 if (strncmp(opt, data, strlen(opt)))
674 if ((value = strchr(data, '=')) == NULL)
678 OBD_ALLOC(retval, strlen(value) + 1);
680 CERROR("out of memory!\n");
684 memcpy(retval, value, strlen(value)+1);
685 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
689 static inline int ll_set_opt(const char *opt, char *data, int fl)
691 if (strncmp(opt, data, strlen(opt)) != 0)
697 /* non-client-specific mount options are parsed in lmd_parse */
698 static int ll_options(char *options, int *flags)
701 char *s1 = options, *s2;
707 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
710 CDEBUG(D_SUPER, "next opt=%s\n", s1);
711 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
716 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
721 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
726 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
731 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
736 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
741 tmp = ll_set_opt("acl", s1, LL_SBI_ACL);
743 /* Ignore deprecated mount option. The client will
744 * always try to mount with ACL support, whether this
745 * is used depends on whether server supports it. */
746 LCONSOLE_ERROR_MSG(0x152, "Ignoring deprecated "
747 "mount option 'acl'.\n");
750 tmp = ll_set_opt("noacl", s1, LL_SBI_ACL);
752 LCONSOLE_ERROR_MSG(0x152, "Ignoring deprecated "
753 "mount option 'noacl'.\n");
757 tmp = ll_set_opt("checksum", s1, LL_SBI_DATA_CHECKSUM);
762 tmp = ll_set_opt("nochecksum", s1, LL_SBI_DATA_CHECKSUM);
768 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
773 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
778 tmp = ll_set_opt("lazystatfs", s1, LL_SBI_LAZYSTATFS);
783 tmp = ll_set_opt("nolazystatfs", s1, LL_SBI_LAZYSTATFS);
788 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
794 s2 = strchr(s1, ',');
802 void ll_lli_init(struct ll_inode_info *lli)
804 lli->lli_inode_magic = LLI_INODE_MAGIC;
805 sema_init(&lli->lli_size_sem, 1);
806 sema_init(&lli->lli_write_sem, 1);
808 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
809 spin_lock_init(&lli->lli_lock);
810 sema_init(&lli->lli_och_sem, 1);
811 lli->lli_mds_read_och = lli->lli_mds_write_och = NULL;
812 lli->lli_mds_exec_och = NULL;
813 lli->lli_open_fd_read_count = lli->lli_open_fd_write_count = 0;
814 lli->lli_open_fd_exec_count = 0;
815 INIT_LIST_HEAD(&lli->lli_dead_list);
816 #ifdef HAVE_CLOSE_THREAD
817 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
819 init_rwsem(&lli->lli_truncate_rwsem);
823 #define MDCDEV "mdc_dev"
824 static int old_lustre_process_log(struct super_block *sb, char *newprofile,
825 struct config_llog_instance *cfg)
827 struct lustre_sb_info *lsi = s2lsi(sb);
828 struct obd_device *obd;
829 struct lustre_handle mdc_conn = {0, };
830 struct obd_export *exp;
831 char *ptr, *mdt, *profile;
832 char niduuid[10] = "mdtnid0";
834 struct obd_uuid mdc_uuid;
835 struct llog_ctxt *ctxt;
836 struct obd_connect_data ocd = { 0 };
838 int i, rc = 0, recov_bk = 1, failnodes = 0;
841 ll_generate_random_uuid(uuid);
842 class_uuid_unparse(uuid, &mdc_uuid);
843 CDEBUG(D_HA, "generated uuid: %s\n", mdc_uuid.uuid);
845 /* Figure out the old mdt and profile name from new-style profile
846 ("lustre" from "mds/lustre-client") */
848 profile = strchr(mdt, '/');
849 if (profile == NULL) {
850 CDEBUG(D_CONFIG, "Can't find MDT name in %s\n", newprofile);
851 GOTO(out, rc = -EINVAL);
855 ptr = strrchr(profile, '-');
857 CDEBUG(D_CONFIG, "Can't find client name in %s\n", newprofile);
858 GOTO(out, rc = -EINVAL);
862 LCONSOLE_WARN("This looks like an old mount command; I will try to "
863 "contact MDT '%s' for profile '%s'\n", mdt, profile);
865 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
867 ptr = lsi->lsi_lmd->lmd_dev;
868 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
869 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid, 0,0,0);
871 /* Stop at the first failover nid */
876 CERROR("No valid MDT nids found.\n");
877 GOTO(out, rc = -EINVAL);
881 rc = do_lcfg(MDCDEV, 0, LCFG_ATTACH, LUSTRE_MDC_NAME,mdc_uuid.uuid,0,0);
883 GOTO(out_del_uuid, rc);
885 rc = do_lcfg(MDCDEV, 0, LCFG_SETUP, mdt, niduuid, 0, 0);
887 LCONSOLE_ERROR_MSG(0x153, "I couldn't establish a connection "
888 "with the MDT. Check that the MDT host NID "
889 "is correct and the networks are up.\n");
890 GOTO(out_detach, rc);
893 obd = class_name2obd(MDCDEV);
895 GOTO(out_cleanup, rc = -EINVAL);
897 /* Add any failover nids */
898 while (*ptr == ':') {
899 /* New failover node */
900 sprintf(niduuid, "mdtnid%d", failnodes);
902 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
904 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid,0,0,0);
906 CERROR("Add uuid for %s failed %d\n",
907 libcfs_nid2str(nid), rc);
912 rc = do_lcfg(MDCDEV, 0, LCFG_ADD_CONN, niduuid, 0, 0,0);
914 CERROR("Add conn for %s failed %d\n",
915 libcfs_nid2str(nid), rc);
923 /* Try all connections, but only once. */
924 rc = obd_set_info_async(obd->obd_self_export,
925 sizeof(KEY_INIT_RECOV_BACKUP), KEY_INIT_RECOV_BACKUP,
926 sizeof(recov_bk), &recov_bk, NULL);
928 GOTO(out_cleanup, rc);
930 /* If we don't have this then an ACL MDS will refuse the connection */
931 ocd.ocd_connect_flags = OBD_CONNECT_ACL;
933 rc = obd_connect(&mdc_conn, obd, &mdc_uuid, &ocd, &exp);
935 CERROR("cannot connect to %s: rc = %d\n", mdt, rc);
936 GOTO(out_cleanup, rc);
939 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
941 cfg->cfg_flags |= CFG_F_COMPAT146;
944 rc = class_config_parse_llog(ctxt, profile, cfg);
947 * For debugging, it's useful to just dump the log
949 rc = class_config_dump_llog(ctxt, profile, cfg);
954 /* Set the caller's profile name to the old-style */
955 memcpy(newprofile, profile, strlen(profile) + 1);
959 LCONSOLE_ERROR_MSG(0x154, "%s: The configuration '%s' could not"
960 " be read from the MDT '%s'. Make sure this"
961 " client and the MDT are running compatible "
962 "versions of Lustre.\n",
963 obd->obd_name, profile, mdt);
966 LCONSOLE_ERROR_MSG(0x155, "%s: The configuration '%s' could not"
967 " be read from the MDT '%s'. This may be "
968 "the result of communication errors between "
969 "the client and the MDT, or if the MDT is "
970 "not running.\n", obd->obd_name, profile,
975 /* We don't so much care about errors in cleaning up the config llog
976 * connection, as we have already read the config by this point. */
980 do_lcfg(MDCDEV, 0, LCFG_CLEANUP, 0, 0, 0, 0);
983 do_lcfg(MDCDEV, 0, LCFG_DETACH, 0, 0, 0, 0);
986 /* class_add_uuid adds a nid even if the same uuid exists; we might
987 delete any copy here. So they all better match. */
988 for (i = 0; i < failnodes; i++) {
989 sprintf(niduuid, "mdtnid%d", i);
990 do_lcfg(MDCDEV, 0, LCFG_DEL_UUID, niduuid, 0, 0, 0);
992 /* class_import_put will get rid of the additional connections */
998 int ll_fill_super(struct super_block *sb)
1000 struct lustre_profile *lprof = NULL;
1001 struct lustre_sb_info *lsi = s2lsi(sb);
1002 struct ll_sb_info *sbi;
1003 char *osc = NULL, *mdc = NULL;
1004 char *profilenm = get_profile_name(sb);
1005 struct config_llog_instance cfg = {0, };
1006 char ll_instance[sizeof(sb) * 2 + 1];
1009 char pseudo[32] = { 0 };
1012 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
1016 /* client additional sb info */
1017 lsi->lsi_llsbi = sbi = ll_init_sbi();
1023 err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
1025 GOTO(out_free, err);
1027 /* Generate a string unique to this super, in case some joker tries
1028 to mount the same fs at two mount points.
1029 Use the address of the super itself.*/
1030 sprintf(ll_instance, "%p", sb);
1031 cfg.cfg_instance = ll_instance;
1032 cfg.cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1035 /* set up client obds */
1036 if (strchr(profilenm, '/') != NULL) /* COMPAT_146 */
1037 err = -EINVAL; /* skip error messages, use old config code */
1039 err = lustre_process_log(sb, profilenm, &cfg);
1044 oldnamelen = strlen(profilenm) + 1;
1045 /* Temp storage for 1.4.6 profile name */
1046 OBD_ALLOC(oldname, oldnamelen);
1048 memcpy(oldname, profilenm, oldnamelen);
1049 rc = old_lustre_process_log(sb, oldname, &cfg);
1051 /* That worked - update the profile name
1054 OBD_FREE(lsi->lsi_lmd->lmd_profile,
1055 strlen(lsi->lsi_lmd->lmd_profile) + 1);
1056 OBD_ALLOC(lsi->lsi_lmd->lmd_profile,
1057 strlen(oldname) + 1);
1058 if (!lsi->lsi_lmd->lmd_profile) {
1059 OBD_FREE(oldname, oldnamelen);
1060 GOTO(out_free, err = -ENOMEM);
1062 memcpy(lsi->lsi_lmd->lmd_profile, oldname,
1063 strlen(oldname) + 1);
1064 profilenm = get_profile_name(sb);
1065 /* Don't ever try to recover the MGS */
1066 rc = ptlrpc_set_import_active(
1067 lsi->lsi_mgc->u.cli.cl_import, 0);
1069 OBD_FREE(oldname, oldnamelen);
1072 /* end COMPAT_146 */
1074 CERROR("Unable to process log: %d\n", err);
1075 GOTO(out_free, err);
1078 lprof = class_get_profile(profilenm);
1079 if (lprof == NULL) {
1080 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1081 " read from the MGS. Does that filesystem "
1082 "exist?\n", profilenm);
1083 GOTO(out_free, err = -EINVAL);
1087 * The configuration for 1.8 client and 2.0 client are different.
1088 * 2.0 introduces lmv, but 1.8 directly uses mdc.
1089 * Here, we will hack to use proper name for mdc if needed.
1095 save = lprof->lp_mdc;
1096 fsname_end = strrchr(save, '-');
1098 namelen = fsname_end - save;
1099 if (strcmp(fsname_end, "-clilmv") == 0) {
1100 strncpy(pseudo, save, namelen);
1101 strcat(pseudo, "-MDT0000-mdc");
1102 lprof->lp_mdc = pseudo;
1103 CDEBUG(D_INFO, "1.8.x connecting to 2.0: lmv=%s"
1104 " new mdc=%s\n", save, pseudo);
1109 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1110 lprof->lp_mdc, lprof->lp_osc);
1112 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
1113 strlen(ll_instance) + 2);
1115 GOTO(out_free, err = -ENOMEM);
1116 sprintf(osc, "%s-%s", lprof->lp_osc, ll_instance);
1118 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
1119 strlen(ll_instance) + 2);
1121 GOTO(out_free, err = -ENOMEM);
1122 sprintf(mdc, "%s-%s", lprof->lp_mdc, ll_instance);
1124 /* connections, registrations, sb setup */
1125 err = client_common_fill_super(sb, mdc, osc);
1129 lprof->lp_mdc = save;
1131 OBD_FREE(mdc, strlen(mdc) + 1);
1133 OBD_FREE(osc, strlen(osc) + 1);
1137 LCONSOLE_WARN("Client %s has started\n", profilenm);
1140 } /* ll_fill_super */
1143 void ll_put_super(struct super_block *sb)
1145 struct config_llog_instance cfg;
1146 char ll_instance[sizeof(sb) * 2 + 1];
1147 struct obd_device *obd;
1148 struct lustre_sb_info *lsi = s2lsi(sb);
1149 struct ll_sb_info *sbi = ll_s2sbi(sb);
1150 char *profilenm = get_profile_name(sb);
1151 int force = 1, next;
1154 CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
1156 sprintf(ll_instance, "%p", sb);
1157 cfg.cfg_instance = ll_instance;
1158 lustre_end_log(sb, NULL, &cfg);
1160 if (sbi->ll_mdc_exp) {
1161 obd = class_exp2obd(sbi->ll_mdc_exp);
1163 force = obd->obd_force;
1166 /* We need to set force before the lov_disconnect in
1167 lustre_common_put_super, since l_d cleans up osc's as well. */
1170 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1172 obd->obd_force = force;
1177 /* Only if client_common_fill_super succeeded */
1178 client_common_put_super(sb);
1182 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) !=NULL) {
1183 class_manual_cleanup(obd);
1187 class_del_profile(profilenm);
1190 lsi->lsi_llsbi = NULL;
1192 lustre_common_put_super(sb);
1194 LCONSOLE_WARN("client %s umount complete\n", ll_instance);
1199 } /* client_put_super */
1201 int ll_shrink_cache(int nr_to_scan, SHRINKER_MASK_T gfp_mask)
1203 struct ll_sb_info *sbi;
1206 if ((nr_to_scan != 0) && !(gfp_mask & __GFP_FS))
1209 /* don't race with umount */
1210 down_read(&ll_sb_sem);
1211 list_for_each_entry(sbi, &ll_super_blocks, ll_list)
1212 count += llap_shrink_cache(sbi, nr_to_scan);
1213 up_read(&ll_sb_sem);
1218 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
1220 struct inode *inode = NULL;
1221 /* NOTE: we depend on atomic igrab() -bzzz */
1222 lock_res_and_lock(lock);
1223 if (lock->l_ast_data) {
1224 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
1225 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1226 inode = igrab(lock->l_ast_data);
1228 inode = lock->l_ast_data;
1229 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1230 D_WARNING, lock, "l_ast_data %p is "
1231 "bogus: magic %08x", lock->l_ast_data,
1232 lli->lli_inode_magic);
1236 unlock_res_and_lock(lock);
1240 static int null_if_equal(struct ldlm_lock *lock, void *data)
1242 if (data == lock->l_ast_data) {
1243 lock->l_ast_data = NULL;
1245 if (lock->l_req_mode != lock->l_granted_mode)
1246 LDLM_ERROR(lock,"clearing inode with ungranted lock");
1249 return LDLM_ITER_CONTINUE;
1252 void ll_clear_inode(struct inode *inode)
1255 struct ll_inode_info *lli = ll_i2info(inode);
1256 struct ll_sb_info *sbi = ll_i2sbi(inode);
1259 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1260 inode->i_generation, inode);
1262 if (S_ISDIR(inode->i_mode)) {
1263 /* these should have been cleared in ll_file_release */
1264 LASSERT(lli->lli_sai == NULL);
1265 LASSERT(lli->lli_opendir_key == NULL);
1266 LASSERT(lli->lli_opendir_pid == 0);
1269 ll_inode2fid(&fid, inode);
1270 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1271 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
1273 LASSERT(!lli->lli_open_fd_write_count);
1274 LASSERT(!lli->lli_open_fd_read_count);
1275 LASSERT(!lli->lli_open_fd_exec_count);
1277 if (lli->lli_mds_write_och)
1278 ll_mdc_real_close(inode, FMODE_WRITE);
1279 if (lli->lli_mds_exec_och) {
1281 CERROR("No FMODE exec, bug exec och is present for "
1282 "inode %ld\n", inode->i_ino);
1283 ll_mdc_real_close(inode, FMODE_EXEC);
1285 if (lli->lli_mds_read_och)
1286 ll_mdc_real_close(inode, FMODE_READ);
1290 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
1291 null_if_equal, inode);
1293 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
1294 lli->lli_smd = NULL;
1297 if (lli->lli_symlink_name) {
1298 OBD_FREE(lli->lli_symlink_name,
1299 strlen(lli->lli_symlink_name) + 1);
1300 lli->lli_symlink_name = NULL;
1303 #ifdef CONFIG_FS_POSIX_ACL
1304 if (lli->lli_posix_acl) {
1305 LASSERT(atomic_read(&lli->lli_posix_acl->a_refcount) == 1);
1306 posix_acl_release(lli->lli_posix_acl);
1307 lli->lli_posix_acl = NULL;
1311 lli->lli_inode_magic = LLI_INODE_DEAD;
1315 static int ll_setattr_do_truncate(struct inode *inode, loff_t new_size)
1317 struct ll_sb_info *sbi = ll_i2sbi(inode);
1318 struct ll_inode_info *lli = ll_i2info(inode);
1319 struct lov_stripe_md *lsm = lli->lli_smd;
1321 ldlm_policy_data_t policy = { .l_extent = {new_size,
1323 struct lustre_handle lockh = { 0 };
1324 int local_lock = 1; /* 0 - no local lock;
1325 * 1 - lock taken by lock_extent;
1326 * 2 - by obd_match*/
1330 UNLOCK_INODE_MUTEX(inode);
1331 UP_WRITE_I_ALLOC_SEM(inode);
1333 down_write(&lli->lli_truncate_rwsem);
1334 if (sbi->ll_lockless_truncate_enable &&
1335 (sbi->ll_lco.lco_flags & OBD_CONNECT_TRUNCLOCK)) {
1338 ast_flags = LDLM_FL_BLOCK_GRANTED;
1339 rc = obd_match(sbi->ll_osc_exp, lsm, LDLM_EXTENT,
1340 &policy, LCK_PW, &ast_flags, inode, &lockh,
1346 /* clear the lock handle as it not cleared
1347 * by obd_match if no matched lock found */
1349 if (rc == 0 && n_matches == 0) {
1351 rc = ll_file_punch(inode, new_size, 1);
1355 if (local_lock == 1) {
1356 /* XXX when we fix the AST intents to pass the discard-range
1357 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
1359 ast_flags = (new_size == 0) ? LDLM_AST_DISCARD_DATA : 0;
1360 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy,
1362 if (unlikely(rc != 0))
1366 LOCK_INODE_MUTEX(inode);
1367 DOWN_WRITE_I_ALLOC_SEM(inode);
1368 if (likely(rc == 0)) {
1369 /* Only ll_inode_size_lock is taken at this level.
1370 * lov_stripe_lock() is grabbed by ll_truncate() only over
1371 * call to obd_adjust_kms(). If vmtruncate returns 0, then
1372 * ll_truncate dropped ll_inode_size_lock() */
1373 ll_inode_size_lock(inode, 0);
1375 set_bit(LLI_F_SRVLOCK, &lli->lli_flags);
1376 rc = vmtruncate(inode, new_size);
1377 clear_bit(LLI_F_SRVLOCK, &lli->lli_flags);
1379 LASSERT(SEM_COUNT(&lli->lli_size_sem) <= 0);
1380 ll_inode_size_unlock(inode, 0);
1386 err = (local_lock == 2) ?
1387 obd_cancel(sbi->ll_osc_exp, lsm, LCK_PW, &lockh, 0, 0):
1388 ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
1389 if (unlikely(err != 0)){
1390 CERROR("extent unlock failed: err=%d,"
1391 " unlock method =%d\n", err, local_lock);
1396 up_write(&lli->lli_truncate_rwsem);
1400 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1401 * object(s) determine the file size and mtime. Otherwise, the MDS will
1402 * keep these values until such a time that objects are allocated for it.
1403 * We do the MDS operations first, as it is checking permissions for us.
1404 * We don't to the MDS RPC if there is nothing that we want to store there,
1405 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1406 * going to do an RPC anyways.
1408 * If we are doing a truncate, we will send the mtime and ctime updates
1409 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1410 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1413 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
1415 struct ll_inode_info *lli = ll_i2info(inode);
1416 struct lov_stripe_md *lsm = lli->lli_smd;
1417 struct ll_sb_info *sbi = ll_i2sbi(inode);
1418 struct ptlrpc_request *request = NULL;
1419 struct mdc_op_data *op_data;
1420 struct lustre_md md;
1421 int ia_valid = attr->ia_valid;
1425 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu valid %x\n", inode->i_ino,
1427 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_SETATTR, 1);
1429 if (ia_valid & ATTR_SIZE) {
1430 if (attr->ia_size > ll_file_maxbytes(inode)) {
1431 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
1432 attr->ia_size, ll_file_maxbytes(inode));
1436 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1439 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1440 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
1441 if (cfs_curproc_fsuid() != inode->i_uid &&
1442 !cfs_capable(CFS_CAP_FOWNER))
1446 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1447 if (attr->ia_valid & ATTR_CTIME) {
1448 attr->ia_ctime = CURRENT_TIME;
1449 attr->ia_valid |= ATTR_CTIME_SET;
1451 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
1452 attr->ia_atime = CURRENT_TIME;
1453 attr->ia_valid |= ATTR_ATIME_SET;
1455 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
1456 attr->ia_mtime = CURRENT_TIME;
1457 attr->ia_valid |= ATTR_MTIME_SET;
1460 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1461 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
1462 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1465 /* NB: ATTR_SIZE will only be set after this point if the size
1466 * resides on the MDS, ie, this file has no objects. */
1468 attr->ia_valid &= ~ATTR_SIZE;
1470 OBD_ALLOC_PTR(op_data);
1471 if (NULL == op_data)
1473 /* We always do an MDS RPC, even if we're only changing the size;
1474 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
1475 ll_prepare_mdc_op_data(op_data, inode, NULL, NULL, 0, 0, NULL);
1477 rc = mdc_setattr(sbi->ll_mdc_exp, op_data,
1478 attr, NULL, 0, NULL, 0, &request);
1481 ptlrpc_req_finished(request);
1482 if (rc == -ENOENT) {
1484 /* Unlinked special device node? Or just a race?
1485 * Pretend we done everything. */
1486 if (!S_ISREG(inode->i_mode) &&
1487 !S_ISDIR(inode->i_mode))
1488 rc = inode_setattr(inode, attr);
1489 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY)
1490 CERROR("mdc_setattr fails: rc = %d\n", rc);
1491 OBD_FREE_PTR(op_data);
1494 OBD_FREE_PTR(op_data);
1496 rc = mdc_req2lustre_md(request, REPLY_REC_OFF, sbi->ll_osc_exp, &md);
1498 ptlrpc_req_finished(request);
1502 /* We call inode_setattr to adjust timestamps.
1503 * If there is at least some data in file, we cleared ATTR_SIZE above to
1504 * avoid invoking vmtruncate, otherwise it is important to call
1505 * vmtruncate in inode_setattr to update inode->i_size (bug 6196) */
1506 rc = inode_setattr(inode, attr);
1508 ll_update_inode(inode, &md);
1509 ptlrpc_req_finished(request);
1511 if (!lsm || !S_ISREG(inode->i_mode)) {
1512 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
1516 /* We really need to get our PW lock before we change inode->i_size.
1517 * If we don't we can race with other i_size updaters on our node, like
1518 * ll_file_read. We can also race with i_size propogation to other
1519 * nodes through dirtying and writeback of final cached pages. This
1520 * last one is especially bad for racing o_append users on other
1522 if (ia_valid & ATTR_SIZE) {
1523 rc = ll_setattr_do_truncate(inode, attr->ia_size);
1524 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
1525 struct obd_info *oinfo;
1527 struct lustre_handle lockh = { 0 };
1530 OBD_ALLOC_PTR(oinfo);
1534 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1535 inode->i_ino, LTIME_S(attr->ia_mtime));
1539 oa->o_id = lsm->lsm_object_id;
1540 oa->o_gr = lsm->lsm_object_gr;
1541 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1543 valid = OBD_MD_FLTYPE | OBD_MD_FLFID | OBD_MD_FLGENER;
1545 if (LTIME_S(attr->ia_mtime) < LTIME_S(attr->ia_ctime)){
1546 struct ost_lvb xtimes;
1548 UNLOCK_INODE_MUTEX(inode);
1549 /* setting mtime to past is performed under PW
1550 * EOF extent lock */
1551 oinfo->oi_policy.l_extent.start = 0;
1552 oinfo->oi_policy.l_extent.end = OBD_OBJECT_EOF;
1553 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW,
1556 LOCK_INODE_MUTEX(inode);
1558 OBD_FREE_PTR(oinfo);
1562 /* setattr under locks
1564 * 1. restore inode's timestamps which
1565 * are about to be set as long as
1566 * concurrent stat (via
1567 * ll_glimpse_size) might bring
1570 * 2. update lsm so that next stat
1571 * (via ll_glimpse_size) could get
1572 * correct values in lsm */
1573 lov_stripe_lock(lli->lli_smd);
1574 if (ia_valid & ATTR_ATIME) {
1575 LTIME_S(inode->i_atime) =
1577 LTIME_S(attr->ia_atime);
1578 valid |= OBD_MD_FLATIME;
1580 if (ia_valid & ATTR_MTIME) {
1581 LTIME_S(inode->i_mtime) =
1583 LTIME_S(attr->ia_mtime);
1584 valid |= OBD_MD_FLMTIME;
1586 if (ia_valid & ATTR_CTIME) {
1587 LTIME_S(inode->i_ctime) =
1589 LTIME_S(attr->ia_ctime);
1590 valid |= OBD_MD_FLCTIME;
1593 obd_update_lvb(ll_i2obdexp(inode), lli->lli_smd,
1595 lov_stripe_unlock(lli->lli_smd);
1599 * 1. do not use inode's timestamps
1600 * because concurrent stat might fill
1601 * the inode with out-of-date times,
1602 * send values from attr instead
1604 * 2.do no update lsm, as long as stat
1605 * (via ll_glimpse_size) will bring
1606 * attributes from osts anyway */
1607 if (ia_valid & ATTR_ATIME) {
1608 oa->o_atime = LTIME_S(attr->ia_atime);
1609 oa->o_valid |= OBD_MD_FLATIME;
1611 if (ia_valid & ATTR_MTIME) {
1612 oa->o_mtime = LTIME_S(attr->ia_mtime);
1613 oa->o_valid |= OBD_MD_FLMTIME;
1615 if (ia_valid & ATTR_CTIME) {
1616 oa->o_ctime = LTIME_S(attr->ia_ctime);
1617 oa->o_valid |= OBD_MD_FLCTIME;
1621 obdo_from_inode(oa, inode, valid);
1626 rc = obd_setattr_rqset(sbi->ll_osc_exp, oinfo, NULL);
1628 CERROR("obd_setattr_async fails: rc=%d\n", rc);
1630 if (LTIME_S(attr->ia_mtime) < LTIME_S(attr->ia_ctime)){
1633 err = ll_extent_unlock(NULL, inode, lsm,
1635 if (unlikely(err != 0)) {
1636 CERROR("extent unlock failed: "
1646 OBD_FREE_PTR(oinfo);
1651 int ll_setattr(struct dentry *de, struct iattr *attr)
1653 int mode = de->d_inode->i_mode;
1655 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1656 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1657 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1658 if ((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
1659 (ATTR_SIZE|ATTR_MODE)) {
1660 if (((mode & S_ISUID) && (!(attr->ia_mode & S_ISUID))) ||
1661 ((mode & S_ISGID) && (mode & S_IXGRP) &&
1662 (!(attr->ia_mode & S_ISGID))))
1663 attr->ia_valid |= ATTR_FORCE;
1666 if ((mode & S_ISUID) && S_ISREG(mode) &&
1667 !(attr->ia_mode & S_ISUID))
1668 attr->ia_valid |= ATTR_KILL_SUID;
1670 if (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
1671 S_ISREG(mode) && !(attr->ia_mode & S_ISGID))
1672 attr->ia_valid |= ATTR_KILL_SGID;
1674 return ll_setattr_raw(de->d_inode, attr);
1677 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1678 __u64 max_age, __u32 flags)
1680 struct ll_sb_info *sbi = ll_s2sbi(sb);
1681 struct obd_statfs obd_osfs;
1685 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age, flags);
1687 CERROR("mdc_statfs fails: rc = %d\n", rc);
1691 osfs->os_type = sb->s_magic;
1693 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1694 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1696 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
1697 flags |= OBD_STATFS_NODELAY;
1699 rc = obd_statfs_rqset(class_exp2obd(sbi->ll_osc_exp),
1700 &obd_osfs, max_age, flags);
1702 CERROR("obd_statfs fails: rc = %d\n", rc);
1706 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1707 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1710 osfs->os_bsize = obd_osfs.os_bsize;
1711 osfs->os_blocks = obd_osfs.os_blocks;
1712 osfs->os_bfree = obd_osfs.os_bfree;
1713 osfs->os_bavail = obd_osfs.os_bavail;
1715 /* If we don't have as many objects free on the OST as inodes
1716 * on the MDS, we reduce the total number of inodes to
1717 * compensate, so that the "inodes in use" number is correct.
1719 if (obd_osfs.os_ffree < osfs->os_ffree) {
1720 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1722 osfs->os_ffree = obd_osfs.os_ffree;
1727 #ifndef HAVE_STATFS_DENTRY_PARAM
1728 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1731 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1733 struct super_block *sb = de->d_sb;
1735 struct obd_statfs osfs;
1738 CDEBUG(D_VFSTRACE, "VFS Op: at "LPU64" jiffies\n", get_jiffies_64());
1739 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1);
1741 /* Some amount of caching on the client is allowed */
1742 rc = ll_statfs_internal(sb, &osfs,
1743 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1748 statfs_unpack(sfs, &osfs);
1750 /* We need to downshift for all 32-bit kernels, because we can't
1751 * tell if the kernel is being called via sys_statfs64() or not.
1752 * Stop before overflowing f_bsize - in which case it is better
1753 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
1754 if (sizeof(long) < 8) {
1755 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1758 osfs.os_blocks >>= 1;
1759 osfs.os_bfree >>= 1;
1760 osfs.os_bavail >>= 1;
1764 sfs->f_blocks = osfs.os_blocks;
1765 sfs->f_bfree = osfs.os_bfree;
1766 sfs->f_bavail = osfs.os_bavail;
1771 void ll_inode_size_lock(struct inode *inode, int lock_lsm)
1773 struct ll_inode_info *lli;
1774 struct lov_stripe_md *lsm;
1776 lli = ll_i2info(inode);
1777 LASSERT(lli->lli_size_sem_owner != current);
1778 down(&lli->lli_size_sem);
1779 LASSERT(lli->lli_size_sem_owner == NULL);
1780 lli->lli_size_sem_owner = current;
1782 LASSERTF(lsm != NULL || lock_lsm == 0, "lsm %p, lock_lsm %d\n",
1785 lov_stripe_lock(lsm);
1788 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm)
1790 struct ll_inode_info *lli;
1791 struct lov_stripe_md *lsm;
1793 lli = ll_i2info(inode);
1795 LASSERTF(lsm != NULL || unlock_lsm == 0, "lsm %p, lock_lsm %d\n",
1798 lov_stripe_unlock(lsm);
1799 LASSERT(lli->lli_size_sem_owner == current);
1800 lli->lli_size_sem_owner = NULL;
1801 up(&lli->lli_size_sem);
1804 static void ll_replace_lsm(struct inode *inode, struct lov_stripe_md *lsm)
1806 struct ll_inode_info *lli = ll_i2info(inode);
1808 dump_lsm(D_INODE, lsm);
1809 dump_lsm(D_INODE, lli->lli_smd);
1810 LASSERTF(lsm->lsm_magic == LOV_MAGIC_JOIN,
1811 "lsm must be joined lsm %p\n", lsm);
1812 obd_free_memmd(ll_i2obdexp(inode), &lli->lli_smd);
1813 CDEBUG(D_INODE, "replace lsm %p to lli_smd %p for inode %lu%u(%p)\n",
1814 lsm, lli->lli_smd, inode->i_ino, inode->i_generation, inode);
1816 lli->lli_maxbytes = lsm->lsm_maxbytes;
1817 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1818 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1821 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1823 struct ll_inode_info *lli = ll_i2info(inode);
1824 struct mds_body *body = md->body;
1825 struct lov_stripe_md *lsm = md->lsm;
1826 struct ll_sb_info *sbi = ll_i2sbi(inode);
1829 CDEBUG(D_INODE, "body->valid = "LPX64"\n", body->valid);
1831 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1833 spin_lock(&lli->lli_lock);
1834 if (lli->lli_smd == NULL) {
1835 if (lsm->lsm_magic != LOV_MAGIC_V1 &&
1836 lsm->lsm_magic != LOV_MAGIC_V3 &&
1837 lsm->lsm_magic != LOV_MAGIC_JOIN) {
1838 dump_lsm(D_ERROR, lsm);
1841 CDEBUG(D_INODE, "adding lsm %p to inode %lu/%u(%p)\n",
1842 lsm, inode->i_ino, inode->i_generation, inode);
1843 /* ll_inode_size_lock() requires it is only called
1844 * with lli_smd != NULL or lock_lsm == 0 or we can
1845 * race between lock/unlock. bug 9547 */
1847 spin_unlock(&lli->lli_lock);
1848 lli->lli_maxbytes = lsm->lsm_maxbytes;
1849 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1850 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1852 spin_unlock(&lli->lli_lock);
1853 if ((lli->lli_smd->lsm_magic == lsm->lsm_magic ||
1854 (lli->lli_smd->lsm_magic == LOV_MAGIC_V3 &&
1855 lsm->lsm_magic == LOV_MAGIC_V1) ||
1856 (lli->lli_smd->lsm_magic == LOV_MAGIC_V1 &&
1857 lsm->lsm_magic == LOV_MAGIC_V3)) &&
1858 lli->lli_smd->lsm_stripe_count ==
1859 lsm->lsm_stripe_count) {
1860 /* The MDS can suddenly change the magic to
1861 * v1/v3 if it has been upgraded/downgraded to a
1862 * version that does/doesn't support OST pools.
1863 * In this case, we consider that the cached lsm
1864 * is equivalent to the new one and keep it in
1865 * place until the inode is evicted from the
1867 if (lov_stripe_md_cmp(lli->lli_smd, lsm)) {
1868 CERROR("lsm mismatch for inode %ld\n",
1870 CERROR("lli_smd:\n");
1871 dump_lsm(D_ERROR, lli->lli_smd);
1873 dump_lsm(D_ERROR, lsm);
1877 ll_replace_lsm(inode, lsm);
1879 if (lli->lli_smd != lsm)
1880 obd_free_memmd(ll_i2obdexp(inode), &lsm);
1883 #ifdef CONFIG_FS_POSIX_ACL
1884 LASSERT(!md->posix_acl || (body->valid & OBD_MD_FLACL));
1885 if (body->valid & OBD_MD_FLACL) {
1886 spin_lock(&lli->lli_lock);
1887 if (lli->lli_posix_acl)
1888 posix_acl_release(lli->lli_posix_acl);
1889 lli->lli_posix_acl = md->posix_acl;
1890 spin_unlock(&lli->lli_lock);
1894 inode->i_ino = ll_fid_build_ino(sbi, &body->fid1);
1895 inode->i_generation = ll_fid_build_gen(sbi, &body->fid1);
1896 *ll_inode_lu_fid(inode) = *((struct lu_fid*)&md->body->fid1);
1898 if (body->valid & OBD_MD_FLATIME) {
1899 if (body->atime > LTIME_S(inode->i_atime))
1900 LTIME_S(inode->i_atime) = body->atime;
1901 lli->lli_lvb.lvb_atime = body->atime;
1903 if (body->valid & OBD_MD_FLMTIME) {
1904 if (body->mtime > LTIME_S(inode->i_mtime)) {
1905 CDEBUG(D_INODE, "setting ino %lu mtime from %lu "
1906 "to "LPU64"\n", inode->i_ino,
1907 LTIME_S(inode->i_mtime), body->mtime);
1908 LTIME_S(inode->i_mtime) = body->mtime;
1910 lli->lli_lvb.lvb_mtime = body->mtime;
1912 if (body->valid & OBD_MD_FLCTIME) {
1913 if (body->ctime > LTIME_S(inode->i_ctime))
1914 LTIME_S(inode->i_ctime) = body->ctime;
1915 lli->lli_lvb.lvb_ctime = body->ctime;
1917 if (body->valid & OBD_MD_FLMODE)
1918 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1919 if (body->valid & OBD_MD_FLTYPE)
1920 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1921 if (S_ISREG(inode->i_mode)) {
1922 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS+1, LL_MAX_BLKSIZE_BITS);
1924 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
1926 #ifdef HAVE_INODE_BLKSIZE
1927 inode->i_blksize = 1<<inode->i_blkbits;
1929 if (body->valid & OBD_MD_FLUID)
1930 inode->i_uid = body->uid;
1931 if (body->valid & OBD_MD_FLGID)
1932 inode->i_gid = body->gid;
1933 if (body->valid & OBD_MD_FLFLAGS)
1934 inode->i_flags = ll_ext_to_inode_flags(body->flags |
1935 MDS_BFLAG_EXT_FLAGS);
1936 if (body->valid & OBD_MD_FLNLINK)
1937 inode->i_nlink = body->nlink;
1939 if (body->valid & OBD_MD_FLRDEV)
1940 inode->i_rdev = old_decode_dev(body->rdev);
1941 if (body->valid & OBD_MD_FLSIZE) {
1942 #if 0 /* Can't block ll_test_inode->ll_update_inode, b=14326*/
1943 ll_inode_size_lock(inode, 0);
1944 i_size_write(inode, body->size);
1945 ll_inode_size_unlock(inode, 0);
1947 inode->i_size = body->size;
1950 if (body->valid & OBD_MD_FLBLOCKS)
1951 inode->i_blocks = body->blocks;
1953 if (body->valid & OBD_MD_FLSIZE)
1954 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1958 static struct backing_dev_info ll_backing_dev_info = {
1959 .ra_pages = 0, /* No readahead */
1960 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
1961 .capabilities = 0, /* Does contribute to dirty memory */
1963 .memory_backed = 0, /* Does contribute to dirty memory */
1967 void ll_read_inode2(struct inode *inode, void *opaque)
1969 struct lustre_md *md = opaque;
1970 struct ll_inode_info *lli = ll_i2info(inode);
1973 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1974 inode->i_generation, inode);
1978 LASSERT(!lli->lli_smd);
1980 /* Core attributes from the MDS first. This is a new inode, and
1981 * the VFS doesn't zero times in the core inode so we have to do
1982 * it ourselves. They will be overwritten by either MDS or OST
1983 * attributes - we just need to make sure they aren't newer. */
1984 LTIME_S(inode->i_mtime) = 0;
1985 LTIME_S(inode->i_atime) = 0;
1986 LTIME_S(inode->i_ctime) = 0;
1988 ll_update_inode(inode, md);
1990 /* OIDEBUG(inode); */
1992 if (S_ISREG(inode->i_mode)) {
1993 struct ll_sb_info *sbi = ll_i2sbi(inode);
1994 inode->i_op = &ll_file_inode_operations;
1995 inode->i_fop = sbi->ll_fop;
1996 inode->i_mapping->a_ops = &ll_aops;
1998 } else if (S_ISDIR(inode->i_mode)) {
1999 inode->i_op = &ll_dir_inode_operations;
2000 inode->i_fop = &ll_dir_operations;
2001 inode->i_mapping->a_ops = &ll_dir_aops;
2003 } else if (S_ISLNK(inode->i_mode)) {
2004 inode->i_op = &ll_fast_symlink_inode_operations;
2007 inode->i_op = &ll_special_inode_operations;
2008 init_special_inode(inode, inode->i_mode,
2009 kdev_t_to_nr(inode->i_rdev));
2010 /* initializing backing dev info. */
2011 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
2016 int ll_iocontrol(struct inode *inode, struct file *file,
2017 unsigned int cmd, unsigned long arg)
2019 struct ll_sb_info *sbi = ll_i2sbi(inode);
2020 struct ptlrpc_request *req = NULL;
2025 case FSFILT_IOC_GETFLAGS: {
2027 struct mds_body *body;
2029 ll_inode2fid(&fid, inode);
2030 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, OBD_MD_FLFLAGS,0,&req);
2032 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
2036 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
2039 /* We want to return EXT3_*_FL flags to the caller via this
2040 * ioctl. An older MDS may be sending S_* flags, fix it up. */
2041 flags = ll_inode_to_ext_flags(body->flags,
2042 MDS_BFLAG_EXT_FLAGS);
2043 ptlrpc_req_finished (req);
2045 RETURN(put_user(flags, (int *)arg));
2047 case FSFILT_IOC_SETFLAGS: {
2048 struct mdc_op_data op_data = { { 0 } };
2049 struct ll_iattr_struct attr;
2050 struct obd_info oinfo = { { { 0 } } };
2051 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
2053 if (get_user(flags, (int *)arg))
2057 OBDO_ALLOC(oinfo.oi_oa);
2061 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0, NULL);
2063 memset(&attr, 0, sizeof(attr));
2064 attr.ia_attr_flags = flags;
2065 ((struct iattr *)&attr)->ia_valid |= ATTR_ATTR_FLAG;
2067 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
2068 (struct iattr *)&attr, NULL, 0, NULL, 0, &req);
2069 ptlrpc_req_finished(req);
2071 OBDO_FREE(oinfo.oi_oa);
2076 OBDO_FREE(oinfo.oi_oa);
2077 GOTO(update_cache, rc);
2080 oinfo.oi_oa->o_id = lsm->lsm_object_id;
2081 oinfo.oi_oa->o_gr = lsm->lsm_object_gr;
2082 oinfo.oi_oa->o_flags = flags;
2083 oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP |
2086 obdo_from_inode(oinfo.oi_oa, inode,
2087 OBD_MD_FLFID | OBD_MD_FLGENER);
2088 rc = obd_setattr_rqset(sbi->ll_osc_exp, &oinfo, NULL);
2089 OBDO_FREE(oinfo.oi_oa);
2091 if (rc != -EPERM && rc != -EACCES)
2092 CERROR("osc_setattr_async fails: rc = %d\n",rc);
2098 inode->i_flags = ll_ext_to_inode_flags(flags |
2099 MDS_BFLAG_EXT_FLAGS);
2109 /* umount -f client means force down, don't save state */
2110 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
2111 void ll_umount_begin(struct vfsmount *vfsmnt, int flags)
2113 struct super_block *sb = vfsmnt->mnt_sb;
2115 void ll_umount_begin(struct super_block *sb)
2118 struct lustre_sb_info *lsi = s2lsi(sb);
2119 struct ll_sb_info *sbi = ll_s2sbi(sb);
2120 struct obd_device *obd;
2121 struct obd_ioctl_data ioc_data = { 0 };
2124 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
2125 if (!(flags & MNT_FORCE)) {
2131 /* Tell the MGC we got umount -f */
2132 lsi->lsi_flags |= LSI_UMOUNT_FORCE;
2134 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2135 sb->s_count, atomic_read(&sb->s_active));
2137 obd = class_exp2obd(sbi->ll_mdc_exp);
2139 CERROR("Invalid MDC connection handle "LPX64"\n",
2140 sbi->ll_mdc_exp->exp_handle.h_cookie);
2145 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_mdc_exp, sizeof ioc_data,
2148 obd = class_exp2obd(sbi->ll_osc_exp);
2150 CERROR("Invalid LOV connection handle "LPX64"\n",
2151 sbi->ll_osc_exp->exp_handle.h_cookie);
2157 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_osc_exp, sizeof ioc_data,
2160 /* Really, we'd like to wait until there are no requests outstanding,
2161 * and then continue. For now, we just invalidate the requests,
2162 * schedule() and sleep one second if needed, and hope.
2165 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
2166 if (atomic_read(&vfsmnt->mnt_count) > 2) {
2167 cfs_schedule_timeout(CFS_TASK_INTERRUPTIBLE,
2168 cfs_time_seconds(1));
2169 if (atomic_read(&vfsmnt->mnt_count) > 2)
2170 LCONSOLE_WARN("Mount still busy with %d refs! You "
2171 "may try to umount it a bit later\n",
2172 atomic_read(&vfsmnt->mnt_count));
2179 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2181 struct ll_sb_info *sbi = ll_s2sbi(sb);
2185 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
2186 read_only = *flags & MS_RDONLY;
2187 err = obd_set_info_async(sbi->ll_mdc_exp, sizeof(KEY_READONLY),
2188 KEY_READONLY, sizeof(read_only),
2191 /* MDS might have expected a different ro key value, b=17493 */
2192 if (err == -EINVAL) {
2193 CDEBUG(D_CONFIG, "Retrying remount with 1.6.6 ro key\n");
2194 err = obd_set_info_async(sbi->ll_mdc_exp,
2195 sizeof(KEY_READONLY_166COMPAT),
2196 KEY_READONLY_166COMPAT,
2202 CERROR("Failed to change the read-only flag during "
2203 "remount: %d\n", err);
2208 sb->s_flags |= MS_RDONLY;
2210 sb->s_flags &= ~MS_RDONLY;
2215 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
2216 struct ptlrpc_request *req, int offset,struct super_block *sb)
2218 struct lustre_md md;
2219 struct ll_sb_info *sbi = NULL;
2223 LASSERT(*inode || sb);
2224 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2226 rc = mdc_req2lustre_md(req, offset, exp, &md);
2231 ll_update_inode(*inode, &md);
2234 /** hashing VFS inode by FIDs.
2235 * IGIF will be used for for compatibility if needed.
2237 *inode =ll_iget(sb, ll_fid_build_ino(sbi, &md.body->fid1), &md);
2238 if (*inode == NULL || is_bad_inode(*inode)) {
2239 mdc_free_lustre_md(exp, &md);
2241 CERROR("new_inode -fatal: rc %d\n", rc);
2246 rc = obd_checkmd(exp, ll_i2mdcexp(*inode),
2247 ll_i2info(*inode)->lli_smd);
2252 char *llap_origins[] = {
2253 [LLAP_ORIGIN_UNKNOWN] = "--",
2254 [LLAP_ORIGIN_READPAGE] = "rp",
2255 [LLAP_ORIGIN_READAHEAD] = "ra",
2256 [LLAP_ORIGIN_COMMIT_WRITE] = "cw",
2257 [LLAP_ORIGIN_WRITEPAGE] = "wp"
2260 struct ll_async_page *llite_pglist_next_llap(struct list_head *head,
2261 struct list_head *list)
2263 struct ll_async_page *llap;
2264 struct list_head *pos;
2266 list_for_each(pos, list) {
2269 llap = list_entry(pos, struct ll_async_page, llap_pglist_item);
2270 if (llap->llap_page == NULL)
2278 int ll_obd_statfs(struct inode *inode, void *arg)
2280 struct ll_sb_info *sbi = NULL;
2281 struct obd_device *client_obd = NULL, *lov_obd = NULL;
2282 struct lov_obd *lov = NULL;
2283 struct obd_statfs stat_buf = {0};
2285 struct obd_ioctl_data *data = NULL;
2289 if (!inode || !(sbi = ll_i2sbi(inode)))
2290 GOTO(out_statfs, rc = -EINVAL);
2292 rc = obd_ioctl_getdata(&buf, &len, arg);
2294 GOTO(out_statfs, rc);
2297 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2298 !data->ioc_pbuf1 || !data->ioc_pbuf2)
2299 GOTO(out_statfs, rc = -EINVAL);
2301 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2302 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
2304 if (type == LL_STATFS_MDC) {
2306 GOTO(out_statfs, rc = -ENODEV);
2307 client_obd = class_exp2obd(sbi->ll_mdc_exp);
2308 } else if (type == LL_STATFS_LOV) {
2309 lov_obd = class_exp2obd(sbi->ll_osc_exp);
2310 lov = &lov_obd->u.lov;
2312 if (index >= lov->desc.ld_tgt_count)
2313 GOTO(out_statfs, rc = -ENODEV);
2315 if (!lov->lov_tgts[index])
2316 /* Try again with the next index */
2317 GOTO(out_statfs, rc = -EAGAIN);
2319 client_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
2320 if (!lov->lov_tgts[index]->ltd_active)
2321 GOTO(out_uuid, rc = -ENODATA);
2325 GOTO(out_statfs, rc = -EINVAL);
2327 rc = obd_statfs(client_obd, &stat_buf,
2328 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), 1);
2332 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
2333 GOTO(out_statfs, rc = -EFAULT);
2337 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(client_obd),
2341 if (copy_to_user(data->ioc_pbuf2, "Unknown UUID",
2342 sizeof("Unknown UUID") + 1))
2348 obd_ioctl_freedata(buf, len);
2352 int ll_process_config(struct lustre_cfg *lcfg)
2356 struct lprocfs_static_vars lvars;
2360 lprocfs_llite_init_vars(&lvars);
2362 /* The instance name contains the sb: lustre-client-aacfe000 */
2363 ptr = strrchr(lustre_cfg_string(lcfg, 0), '-');
2364 if (!ptr || !*(++ptr))
2366 if (sscanf(ptr, "%lx", &x) != 1)
2369 /* This better be a real Lustre superblock! */
2370 LASSERT(s2lsi((struct super_block *)sb)->lsi_lmd->lmd_magic == LMD_MAGIC);
2372 /* Note we have not called client_common_fill_super yet, so
2373 proc fns must be able to handle that! */
2374 rc = class_process_proc_param(PARAM_LLITE, lvars.obd_vars,
2379 int ll_show_options(struct seq_file *seq, struct vfsmount *vfs)
2381 struct ll_sb_info *sbi;
2383 LASSERT((seq != NULL) && (vfs != NULL));
2384 sbi = ll_s2sbi(vfs->mnt_sb);
2386 if (sbi->ll_flags & LL_SBI_NOLCK)
2387 seq_puts(seq, ",nolock");
2389 if (sbi->ll_flags & LL_SBI_FLOCK)
2390 seq_puts(seq, ",flock");
2392 if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
2393 seq_puts(seq, ",localflock");
2395 if (sbi->ll_flags & LL_SBI_USER_XATTR)
2396 seq_puts(seq, ",user_xattr");
2398 if (sbi->ll_flags & LL_SBI_ACL)
2399 seq_puts(seq, ",acl");
2401 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
2402 seq_puts(seq, ",lazystatfs");