1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light Super operations
6 * Copyright (c) 2002-2005 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DEBUG_SUBSYSTEM S_LLITE
26 #include <linux/module.h>
27 #include <linux/types.h>
28 #include <linux/random.h>
29 #include <linux/version.h>
31 #include <lustre_lite.h>
32 #include <lustre_ha.h>
33 #include <lustre_dlm.h>
34 #include <lprocfs_status.h>
35 #include <lustre_disk.h>
36 #include <lustre_param.h>
37 #include <lustre_log.h>
38 #include <obd_cksum.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;
61 OBD_ALLOC(sbi, sizeof(*sbi));
65 spin_lock_init(&sbi->ll_lock);
66 spin_lock_init(&sbi->ll_lco.lco_lock);
67 spin_lock_init(&sbi->ll_pp_extent_lock);
68 spin_lock_init(&sbi->ll_process_lock);
69 sbi->ll_rw_stats_on = 0;
70 INIT_LIST_HEAD(&sbi->ll_pglist);
71 if (num_physpages >> (20 - CFS_PAGE_SHIFT) < 512)
72 sbi->ll_async_page_max = num_physpages / 2;
74 sbi->ll_async_page_max = (num_physpages / 4) * 3;
75 sbi->ll_ra_info.ra_max_pages = min(num_physpages / 8,
76 SBI_DEFAULT_READAHEAD_MAX);
77 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
78 SBI_DEFAULT_READAHEAD_WHOLE_MAX;
79 sbi->ll_contention_time = SBI_DEFAULT_CONTENTION_SECONDS;
80 sbi->ll_lockless_truncate_enable = SBI_DEFAULT_LOCKLESS_TRUNCATE_ENABLE;
81 INIT_LIST_HEAD(&sbi->ll_conn_chain);
82 INIT_LIST_HEAD(&sbi->ll_orphan_dentry_list);
84 ll_generate_random_uuid(uuid);
85 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
86 CDEBUG(D_CONFIG, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
88 spin_lock(&ll_sb_lock);
89 list_add_tail(&sbi->ll_list, &ll_super_blocks);
90 spin_unlock(&ll_sb_lock);
92 #ifdef ENABLE_LLITE_CHECKSUM
93 sbi->ll_flags |= LL_SBI_CHECKSUM;
96 #ifdef HAVE_LRU_RESIZE_SUPPORT
97 sbi->ll_flags |= LL_SBI_LRU_RESIZE;
100 #ifdef HAVE_EXPORT___IGET
101 INIT_LIST_HEAD(&sbi->ll_deathrow);
102 spin_lock_init(&sbi->ll_deathrow_lock);
104 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
105 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_r_hist.oh_lock);
106 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_w_hist.oh_lock);
109 /* metadata statahead is enabled by default */
110 sbi->ll_sa_max = LL_SA_RPC_DEF;
115 void ll_free_sbi(struct super_block *sb)
117 struct ll_sb_info *sbi = ll_s2sbi(sb);
121 spin_lock(&ll_sb_lock);
122 list_del(&sbi->ll_list);
123 spin_unlock(&ll_sb_lock);
124 OBD_FREE(sbi, sizeof(*sbi));
129 static struct dentry_operations ll_d_root_ops = {
130 #ifdef DCACHE_LUSTRE_INVALID
131 .d_compare = ll_dcompare,
135 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
136 * us to make MDS RPCs with large enough reply buffers to hold the
137 * maximum-sized (= maximum striped) EA and cookie without having to
138 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
139 static int ll_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp)
141 struct lov_stripe_md lsm = { .lsm_magic = LOV_MAGIC };
142 __u32 valsize = sizeof(struct lov_desc);
143 int rc, easize, def_easize, cookiesize;
144 struct lov_desc desc;
148 rc = obd_get_info(dt_exp, strlen(KEY_LOVDESC) + 1, KEY_LOVDESC,
153 stripes = min(desc.ld_tgt_count, (__u32)LOV_MAX_STRIPE_COUNT);
154 lsm.lsm_stripe_count = stripes;
155 easize = obd_size_diskmd(dt_exp, &lsm);
157 lsm.lsm_stripe_count = desc.ld_default_stripe_count;
158 def_easize = obd_size_diskmd(dt_exp, &lsm);
160 cookiesize = stripes * sizeof(struct llog_cookie);
162 CDEBUG(D_HA, "updating max_mdsize/max_cookiesize: %d/%d\n",
165 rc = md_init_ea_size(md_exp, easize, def_easize, cookiesize);
169 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
171 struct inode *root = 0;
172 struct ll_sb_info *sbi = ll_s2sbi(sb);
173 struct obd_device *obd;
174 struct lu_fid rootfid;
175 struct obd_capa *oc = NULL;
176 struct obd_statfs osfs;
177 struct ptlrpc_request *request = NULL;
178 struct lustre_handle dt_conn = {0, };
179 struct lustre_handle md_conn = {0, };
180 struct obd_connect_data *data = NULL;
181 struct lustre_md lmd;
183 int size, err, checksum;
186 obd = class_name2obd(md);
188 CERROR("MD %s: not setup or attached\n", md);
196 if (proc_lustre_fs_root) {
197 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
200 CERROR("could not register mount in /proc/lustre");
203 /* indicate the features supported by this client */
204 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
205 OBD_CONNECT_JOIN | OBD_CONNECT_ATTRFID |
206 OBD_CONNECT_VERSION | OBD_CONNECT_MDS_CAPA |
207 OBD_CONNECT_OSS_CAPA | OBD_CONNECT_CANCELSET|
210 #ifdef HAVE_LRU_RESIZE_SUPPORT
211 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
212 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
214 #ifdef CONFIG_FS_POSIX_ACL
215 data->ocd_connect_flags |= OBD_CONNECT_ACL;
217 data->ocd_ibits_known = MDS_INODELOCK_FULL;
218 data->ocd_version = LUSTRE_VERSION_CODE;
220 if (sb->s_flags & MS_RDONLY)
221 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
222 if (sbi->ll_flags & LL_SBI_USER_XATTR)
223 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
225 #ifdef HAVE_MS_FLOCK_LOCK
226 /* force vfs to use lustre handler for flock() calls - bug 10743 */
227 sb->s_flags |= MS_FLOCK_LOCK;
230 if (sbi->ll_flags & LL_SBI_FLOCK)
231 sbi->ll_fop = &ll_file_operations_flock;
232 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
233 sbi->ll_fop = &ll_file_operations;
235 sbi->ll_fop = &ll_file_operations_noflock;
238 data->ocd_connect_flags |= OBD_CONNECT_REAL;
239 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
240 data->ocd_connect_flags &= ~OBD_CONNECT_LCL_CLIENT;
241 data->ocd_connect_flags |= OBD_CONNECT_RMT_CLIENT;
243 data->ocd_connect_flags &= ~OBD_CONNECT_RMT_CLIENT;
244 data->ocd_connect_flags |= OBD_CONNECT_LCL_CLIENT;
247 err = obd_connect(NULL, &md_conn, obd, &sbi->ll_sb_uuid, data, NULL);
249 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
250 "recovery, of which this client is not a "
251 "part. Please wait for recovery to complete,"
252 " abort, or time out.\n", md);
255 CERROR("cannot connect to %s: rc = %d\n", md, err);
258 sbi->ll_md_exp = class_conn2export(&md_conn);
260 err = obd_fid_init(sbi->ll_md_exp);
262 CERROR("Can't init metadata layer FID infrastructure, "
267 err = obd_statfs(obd, &osfs, cfs_time_current_64() - HZ, 0);
269 GOTO(out_md_fid, err);
271 size = sizeof(*data);
272 err = obd_get_info(sbi->ll_md_exp, strlen(KEY_CONN_DATA),
273 KEY_CONN_DATA, &size, data);
275 CERROR("Get connect data failed: %d \n", err);
279 LASSERT(osfs.os_bsize);
280 sb->s_blocksize = osfs.os_bsize;
281 sb->s_blocksize_bits = log2(osfs.os_bsize);
282 sb->s_magic = LL_SUPER_MAGIC;
284 /* for bug 11559. in $LINUX/fs/read_write.c, function do_sendfile():
285 * retval = in_file->f_op->sendfile(...);
287 * retval = -EOVERFLOW;
289 * it will check if *ppos is greater than max. However, max equals to
290 * s_maxbytes, which is a negative integer in a x86_64 box since loff_t
291 * has been defined as a signed long long ineger in linux kernel. */
292 #if BITS_PER_LONG == 64
293 sb->s_maxbytes = PAGE_CACHE_MAXBYTES >> 1;
295 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
297 sbi->ll_namelen = osfs.os_namelen;
298 sbi->ll_max_rw_chunk = LL_DEFAULT_MAX_RW_CHUNK;
300 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
301 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
302 LCONSOLE_INFO("Disabling user_xattr feature because "
303 "it is not supported on the server\n");
304 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
307 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
309 sb->s_flags |= MS_POSIXACL;
311 sbi->ll_flags |= LL_SBI_ACL;
313 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
315 sb->s_flags &= ~MS_POSIXACL;
317 sbi->ll_flags &= ~LL_SBI_ACL;
320 if (data->ocd_connect_flags & OBD_CONNECT_JOIN)
321 sbi->ll_flags |= LL_SBI_JOIN;
323 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
324 if (!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT)) {
325 /* sometimes local client claims to be remote, but mdt
326 * will disagree when client gss not applied. */
327 LCONSOLE_INFO("client claims to be remote, but server "
328 "rejected, forced to be local.\n");
329 sbi->ll_flags &= ~LL_SBI_RMT_CLIENT;
332 if (!(data->ocd_connect_flags & OBD_CONNECT_LCL_CLIENT)) {
333 /* with gss applied, remote client can not claim to be
334 * local, so mdt maybe force client to be remote. */
335 LCONSOLE_INFO("client claims to be local, but server "
336 "rejected, forced to be remote.\n");
337 sbi->ll_flags |= LL_SBI_RMT_CLIENT;
341 if (data->ocd_connect_flags & OBD_CONNECT_MDS_CAPA) {
342 LCONSOLE_INFO("client enabled MDS capability!\n");
343 sbi->ll_flags |= LL_SBI_MDS_CAPA;
346 if (data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA) {
347 LCONSOLE_INFO("client enabled OSS capability!\n");
348 sbi->ll_flags |= LL_SBI_OSS_CAPA;
351 sbi->ll_sdev_orig = sb->s_dev;
352 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
353 /* We set sb->s_dev equal on all lustre clients in order to support
354 * NFS export clustering. NFSD requires that the FSID be the same
356 /* s_dev is also used in lt_compare() to compare two fs, but that is
357 * only a node-local comparison. */
359 /* XXX: this will not work with LMV */
360 sb->s_dev = get_uuid2int(sbi2mdc(sbi)->cl_target_uuid.uuid,
361 strlen(sbi2mdc(sbi)->cl_target_uuid.uuid));
364 obd = class_name2obd(dt);
366 CERROR("DT %s: not setup or attached\n", dt);
367 GOTO(out_md_fid, err = -ENODEV);
370 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
371 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
372 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
373 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK;
374 if (sbi->ll_flags & LL_SBI_OSS_CAPA)
375 data->ocd_connect_flags |= OBD_CONNECT_OSS_CAPA;
377 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_CKSUM)) {
378 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
379 * disabled by default, because it can still be enabled on the
380 * fly via /proc. As a consequence, we still need to come to an
381 * agreement on the supported algorithms at connect time */
382 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
384 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
385 data->ocd_cksum_types = OBD_CKSUM_ADLER;
387 /* send the list of supported checksum types */
388 data->ocd_cksum_types = OBD_CKSUM_ALL;
391 #ifdef HAVE_LRU_RESIZE_SUPPORT
392 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
394 CDEBUG(D_RPCTRACE, "ocd_connect_flags: "LPX64" ocd_version: %d "
395 "ocd_grant: %d\n", data->ocd_connect_flags,
396 data->ocd_version, data->ocd_grant);
398 obd->obd_upcall.onu_owner = &sbi->ll_lco;
399 obd->obd_upcall.onu_upcall = ll_ocd_update;
400 data->ocd_brw_size = PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT;
402 err = obd_connect(NULL, &dt_conn, obd, &sbi->ll_sb_uuid, data, NULL);
404 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
405 "recovery, of which this client is not a "
406 "part. Please wait for recovery to "
407 "complete, abort, or time out.\n", dt);
408 GOTO(out_md_fid, err);
410 CERROR("Cannot connect to %s: rc = %d\n", dt, err);
411 GOTO(out_md_fid, err);
414 sbi->ll_dt_exp = class_conn2export(&dt_conn);
416 err = obd_fid_init(sbi->ll_dt_exp);
418 CERROR("Can't init data layer FID infrastructure, "
423 spin_lock(&sbi->ll_lco.lco_lock);
424 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
425 spin_unlock(&sbi->ll_lco.lco_lock);
427 ll_init_ea_size(sbi->ll_md_exp, sbi->ll_dt_exp);
429 err = obd_prep_async_page(sbi->ll_dt_exp, NULL, NULL, NULL,
430 0, NULL, NULL, NULL);
432 LCONSOLE_ERROR_MSG(0x151, "There are no OST's in this "
433 "filesystem. There must be at least one "
434 "active OST for a client to start.\n");
435 GOTO(out_dt_fid, err);
438 if (!ll_async_page_slab) {
439 ll_async_page_slab_size =
440 size_round(sizeof(struct ll_async_page)) + err;
441 ll_async_page_slab = cfs_mem_cache_create("ll_async_page",
442 ll_async_page_slab_size,
444 if (!ll_async_page_slab)
445 GOTO(out_dt_fid, err = -ENOMEM);
448 err = md_getstatus(sbi->ll_md_exp, &rootfid, &oc);
450 CERROR("cannot mds_connect: rc = %d\n", err);
451 GOTO(out_dt_fid, err);
453 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&rootfid));
454 sbi->ll_root_fid = rootfid;
456 sb->s_op = &lustre_super_operations;
457 sb->s_export_op = &lustre_export_operations;
460 * XXX: move this to after cbd setup? */
461 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMDSCAPA;
462 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
463 valid |= OBD_MD_FLRMTPERM;
464 else if (sbi->ll_flags & LL_SBI_ACL)
465 valid |= OBD_MD_FLACL;
467 err = md_getattr(sbi->ll_md_exp, &rootfid, oc, valid, 0, &request);
471 CERROR("md_getattr failed for root: rc = %d\n", err);
472 GOTO(out_dt_fid, err);
474 memset(&lmd, 0, sizeof(lmd));
475 err = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
476 sbi->ll_md_exp, &lmd);
478 CERROR("failed to understand root inode md: rc = %d\n", err);
479 ptlrpc_req_finished (request);
480 GOTO(out_dt_fid, err);
483 LASSERT(fid_is_sane(&sbi->ll_root_fid));
484 root = ll_iget(sb, ll_fid_build_ino(sbi, &sbi->ll_root_fid), &lmd);
485 md_free_lustre_md(sbi->ll_md_exp, &lmd);
486 ptlrpc_req_finished(request);
488 if (root == NULL || is_bad_inode(root)) {
490 obd_free_memmd(sbi->ll_dt_exp, &lmd.lsm);
491 #ifdef CONFIG_FS_POSIX_ACL
493 posix_acl_release(lmd.posix_acl);
494 lmd.posix_acl = NULL;
497 CERROR("lustre_lite: bad iget4 for root\n");
498 GOTO(out_root, err = -EBADF);
501 err = ll_close_thread_start(&sbi->ll_lcq);
503 CERROR("cannot start close thread: rc %d\n", err);
507 #ifdef CONFIG_FS_POSIX_ACL
508 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
509 rct_init(&sbi->ll_rct);
510 et_init(&sbi->ll_et);
514 checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
515 err = obd_set_info_async(sbi->ll_dt_exp, strlen("checksum"),"checksum",
516 sizeof(checksum), &checksum, NULL);
518 sb->s_root = d_alloc_root(root);
520 OBD_FREE(data, sizeof(*data));
521 sb->s_root->d_op = &ll_d_root_ops;
527 obd_fid_fini(sbi->ll_dt_exp);
529 obd_disconnect(sbi->ll_dt_exp);
530 sbi->ll_dt_exp = NULL;
532 obd_fid_fini(sbi->ll_md_exp);
534 obd_disconnect(sbi->ll_md_exp);
535 sbi->ll_md_exp = NULL;
539 lprocfs_unregister_mountpoint(sbi);
543 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
547 *lmmsize = obd_size_diskmd(sbi->ll_dt_exp, NULL);
549 rc = obd_get_info(sbi->ll_md_exp, strlen("max_easize"), "max_easize",
552 CERROR("Get max mdsize error rc %d \n", rc);
557 void ll_dump_inode(struct inode *inode)
559 struct list_head *tmp;
560 int dentry_count = 0;
562 LASSERT(inode != NULL);
564 list_for_each(tmp, &inode->i_dentry)
567 CERROR("inode %p dump: dev=%s ino=%lu mode=%o count=%u, %d dentries\n",
568 inode, ll_i2mdexp(inode)->exp_obd->obd_name, inode->i_ino,
569 inode->i_mode, atomic_read(&inode->i_count), dentry_count);
572 void lustre_dump_dentry(struct dentry *dentry, int recur)
574 struct list_head *tmp;
577 LASSERT(dentry != NULL);
579 list_for_each(tmp, &dentry->d_subdirs)
582 CERROR("dentry %p dump: name=%.*s parent=%.*s (%p), inode=%p, count=%u,"
583 " flags=0x%x, fsdata=%p, %d subdirs\n", dentry,
584 dentry->d_name.len, dentry->d_name.name,
585 dentry->d_parent->d_name.len, dentry->d_parent->d_name.name,
586 dentry->d_parent, dentry->d_inode, atomic_read(&dentry->d_count),
587 dentry->d_flags, dentry->d_fsdata, subdirs);
588 if (dentry->d_inode != NULL)
589 ll_dump_inode(dentry->d_inode);
594 list_for_each(tmp, &dentry->d_subdirs) {
595 struct dentry *d = list_entry(tmp, struct dentry, d_child);
596 lustre_dump_dentry(d, recur - 1);
600 #ifdef HAVE_EXPORT___IGET
601 static void prune_dir_dentries(struct inode *inode)
603 struct dentry *dentry, *prev = NULL;
605 /* due to lustre specific logic, a directory
606 * can have few dentries - a bug from VFS POV */
608 spin_lock(&dcache_lock);
609 if (!list_empty(&inode->i_dentry)) {
610 dentry = list_entry(inode->i_dentry.prev,
611 struct dentry, d_alias);
612 /* in order to prevent infinite loops we
613 * break if previous dentry is busy */
614 if (dentry != prev) {
617 spin_unlock(&dcache_lock);
619 /* try to kill all child dentries */
621 shrink_dcache_parent(dentry);
622 unlock_dentry(dentry);
625 /* now try to get rid of current dentry */
626 d_prune_aliases(inode);
630 spin_unlock(&dcache_lock);
633 static void prune_deathrow_one(struct ll_inode_info *lli)
635 struct inode *inode = ll_info2i(lli);
637 /* first, try to drop any dentries - they hold a ref on the inode */
638 if (S_ISDIR(inode->i_mode))
639 prune_dir_dentries(inode);
641 d_prune_aliases(inode);
644 /* if somebody still uses it, leave it */
645 LASSERT(atomic_read(&inode->i_count) > 0);
646 if (atomic_read(&inode->i_count) > 1)
649 CDEBUG(D_INODE, "inode %lu/%u(%d) looks a good candidate for prune\n",
650 inode->i_ino,inode->i_generation, atomic_read(&inode->i_count));
652 /* seems nobody uses it anymore */
660 static void prune_deathrow(struct ll_sb_info *sbi, int try)
662 struct ll_inode_info *lli;
666 if (need_resched() && try)
670 if (!spin_trylock(&sbi->ll_deathrow_lock))
673 spin_lock(&sbi->ll_deathrow_lock);
678 if (!list_empty(&sbi->ll_deathrow)) {
679 lli = list_entry(sbi->ll_deathrow.next,
680 struct ll_inode_info,
682 list_del_init(&lli->lli_dead_list);
683 if (!list_empty(&sbi->ll_deathrow))
686 spin_unlock(&sbi->ll_deathrow_lock);
689 prune_deathrow_one(lli);
691 } while (empty == 0);
693 #else /* !HAVE_EXPORT___IGET */
694 #define prune_deathrow(sbi, try) do {} while (0)
695 #endif /* HAVE_EXPORT___IGET */
697 void client_common_put_super(struct super_block *sb)
699 struct ll_sb_info *sbi = ll_s2sbi(sb);
702 #ifdef CONFIG_FS_POSIX_ACL
703 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
704 et_fini(&sbi->ll_et);
705 rct_fini(&sbi->ll_rct);
709 obd_cancel_unused(sbi->ll_dt_exp, NULL, 0, NULL);
711 ll_close_thread_shutdown(sbi->ll_lcq);
713 /* destroy inodes in deathrow */
714 prune_deathrow(sbi, 0);
716 list_del(&sbi->ll_conn_chain);
718 obd_fid_fini(sbi->ll_dt_exp);
719 obd_disconnect(sbi->ll_dt_exp);
720 sbi->ll_dt_exp = NULL;
722 lprocfs_unregister_mountpoint(sbi);
724 obd_fid_fini(sbi->ll_md_exp);
725 obd_disconnect(sbi->ll_md_exp);
726 sbi->ll_md_exp = NULL;
731 void ll_kill_super(struct super_block *sb)
733 struct ll_sb_info *sbi;
738 if (!(sb->s_flags & MS_ACTIVE))
742 /* we need restore s_dev from changed for clustred NFS before put_super
743 * because new kernels have cached s_dev and change sb->s_dev in
744 * put_super not affected real removing devices */
746 sb->s_dev = sbi->ll_sdev_orig;
750 char *ll_read_opt(const char *opt, char *data)
756 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
757 if (strncmp(opt, data, strlen(opt)))
759 if ((value = strchr(data, '=')) == NULL)
763 OBD_ALLOC(retval, strlen(value) + 1);
765 CERROR("out of memory!\n");
769 memcpy(retval, value, strlen(value)+1);
770 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
774 static inline int ll_set_opt(const char *opt, char *data, int fl)
776 if (strncmp(opt, data, strlen(opt)) != 0)
782 /* non-client-specific mount options are parsed in lmd_parse */
783 static int ll_options(char *options, int *flags)
786 char *s1 = options, *s2;
792 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
795 CDEBUG(D_SUPER, "next opt=%s\n", s1);
796 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
801 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
806 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
811 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
816 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
821 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
826 tmp = ll_set_opt("acl", s1, LL_SBI_ACL);
828 /* Ignore deprecated mount option. The client will
829 * always try to mount with ACL support, whether this
830 * is used depends on whether server supports it. */
833 tmp = ll_set_opt("noacl", s1, LL_SBI_ACL);
837 tmp = ll_set_opt("remote_client", s1, LL_SBI_RMT_CLIENT);
843 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
848 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
853 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
858 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
864 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
870 s2 = strchr(s1, ',');
878 void ll_lli_init(struct ll_inode_info *lli)
880 lli->lli_inode_magic = LLI_INODE_MAGIC;
881 sema_init(&lli->lli_size_sem, 1);
882 sema_init(&lli->lli_write_sem, 1);
884 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
885 spin_lock_init(&lli->lli_lock);
886 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
887 INIT_LIST_HEAD(&lli->lli_close_list);
888 lli->lli_inode_magic = LLI_INODE_MAGIC;
889 sema_init(&lli->lli_och_sem, 1);
890 lli->lli_mds_read_och = lli->lli_mds_write_och = NULL;
891 lli->lli_mds_exec_och = NULL;
892 lli->lli_open_fd_read_count = lli->lli_open_fd_write_count = 0;
893 lli->lli_open_fd_exec_count = 0;
894 INIT_LIST_HEAD(&lli->lli_dead_list);
895 lli->lli_remote_perms = NULL;
896 lli->lli_rmtperm_utime = 0;
897 sema_init(&lli->lli_rmtperm_sem, 1);
898 INIT_LIST_HEAD(&lli->lli_oss_capas);
901 int ll_fill_super(struct super_block *sb)
903 struct lustre_profile *lprof;
904 struct lustre_sb_info *lsi = s2lsi(sb);
905 struct ll_sb_info *sbi;
906 char *dt = NULL, *md = NULL;
907 char *profilenm = get_profile_name(sb);
908 struct config_llog_instance cfg = {0, };
909 char ll_instance[sizeof(sb) * 2 + 1];
913 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
917 sb->s_type->fs_flags |= FS_RENAME_DOES_D_MOVE;
918 /* client additional sb info */
919 lsi->lsi_llsbi = sbi = ll_init_sbi();
925 err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
929 /* Generate a string unique to this super, in case some joker tries
930 to mount the same fs at two mount points.
931 Use the address of the super itself.*/
932 sprintf(ll_instance, "%p", sb);
933 cfg.cfg_instance = ll_instance;
934 cfg.cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
936 /* set up client obds */
937 err = lustre_process_log(sb, profilenm, &cfg);
939 CERROR("Unable to process log: %d\n", err);
943 lprof = class_get_profile(profilenm);
945 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
946 " read from the MGS. Does that filesystem "
947 "exist?\n", profilenm);
948 GOTO(out_free, err = -EINVAL);
950 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
951 lprof->lp_md, lprof->lp_dt);
953 OBD_ALLOC(dt, strlen(lprof->lp_dt) +
954 strlen(ll_instance) + 2);
956 GOTO(out_free, err = -ENOMEM);
957 sprintf(dt, "%s-%s", lprof->lp_dt, ll_instance);
959 OBD_ALLOC(md, strlen(lprof->lp_md) +
960 strlen(ll_instance) + 2);
962 GOTO(out_free, err = -ENOMEM);
963 sprintf(md, "%s-%s", lprof->lp_md, ll_instance);
965 /* connections, registrations, sb setup */
966 err = client_common_fill_super(sb, md, dt);
970 OBD_FREE(md, strlen(md) + 1);
972 OBD_FREE(dt, strlen(dt) + 1);
976 LCONSOLE_WARN("Client %s has started\n", profilenm);
979 } /* ll_fill_super */
982 void ll_put_super(struct super_block *sb)
984 struct config_llog_instance cfg;
985 char ll_instance[sizeof(sb) * 2 + 1];
986 struct obd_device *obd;
987 struct lustre_sb_info *lsi = s2lsi(sb);
988 struct ll_sb_info *sbi = ll_s2sbi(sb);
989 char *profilenm = get_profile_name(sb);
993 CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
995 ll_print_capa_stat(sbi);
997 sprintf(ll_instance, "%p", sb);
998 cfg.cfg_instance = ll_instance;
999 lustre_end_log(sb, NULL, &cfg);
1001 if (sbi->ll_md_exp) {
1002 obd = class_exp2obd(sbi->ll_md_exp);
1004 force = obd->obd_force;
1007 /* We need to set force before the lov_disconnect in
1008 lustre_common_put_super, since l_d cleans up osc's as well. */
1011 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1013 obd->obd_force = force;
1018 /* Only if client_common_fill_super succeeded */
1019 client_common_put_super(sb);
1022 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) !=NULL) {
1023 class_manual_cleanup(obd);
1027 class_del_profile(profilenm);
1030 lsi->lsi_llsbi = NULL;
1032 lustre_common_put_super(sb);
1034 LCONSOLE_WARN("client %s umount complete\n", ll_instance);
1039 } /* client_put_super */
1041 #ifdef HAVE_REGISTER_CACHE
1042 #include <linux/cache_def.h>
1043 #ifdef HAVE_CACHE_RETURN_INT
1048 ll_shrink_cache(int priority, unsigned int gfp_mask)
1050 struct ll_sb_info *sbi;
1053 list_for_each_entry(sbi, &ll_super_blocks, ll_list)
1054 count += llap_shrink_cache(sbi, priority);
1056 #ifdef HAVE_CACHE_RETURN_INT
1061 struct cache_definition ll_cache_definition = {
1062 .name = "llap_cache",
1063 .shrink = ll_shrink_cache
1065 #endif /* HAVE_REGISTER_CACHE */
1067 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
1069 struct inode *inode = NULL;
1070 /* NOTE: we depend on atomic igrab() -bzzz */
1071 lock_res_and_lock(lock);
1072 if (lock->l_ast_data) {
1073 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
1074 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1075 inode = igrab(lock->l_ast_data);
1077 inode = lock->l_ast_data;
1078 ldlm_lock_debug(NULL, inode->i_state & I_FREEING ?
1080 lock, __FILE__, __func__, __LINE__,
1081 "l_ast_data %p is bogus: magic %08x",
1082 lock->l_ast_data, lli->lli_inode_magic);
1086 unlock_res_and_lock(lock);
1090 static int null_if_equal(struct ldlm_lock *lock, void *data)
1092 if (data == lock->l_ast_data) {
1093 lock->l_ast_data = NULL;
1095 if (lock->l_req_mode != lock->l_granted_mode)
1096 LDLM_ERROR(lock,"clearing inode with ungranted lock");
1099 return LDLM_ITER_CONTINUE;
1102 void ll_clear_inode(struct inode *inode)
1104 struct ll_inode_info *lli = ll_i2info(inode);
1105 struct ll_sb_info *sbi = ll_i2sbi(inode);
1108 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1109 inode->i_generation, inode);
1111 if (S_ISDIR(inode->i_mode)) {
1112 /* these should have been cleared in ll_file_release */
1113 LASSERT(lli->lli_sai == NULL);
1114 LASSERT(lli->lli_opendir_key == NULL);
1115 LASSERT(lli->lli_opendir_pid == 0);
1118 ll_i2info(inode)->lli_flags &= ~LLIF_MDS_SIZE_LOCK;
1119 md_change_cbdata(sbi->ll_md_exp, ll_inode2fid(inode),
1120 null_if_equal, inode);
1122 LASSERT(!lli->lli_open_fd_write_count);
1123 LASSERT(!lli->lli_open_fd_read_count);
1124 LASSERT(!lli->lli_open_fd_exec_count);
1126 if (lli->lli_mds_write_och)
1127 ll_md_real_close(inode, FMODE_WRITE);
1128 if (lli->lli_mds_exec_och)
1129 ll_md_real_close(inode, FMODE_EXEC);
1130 if (lli->lli_mds_read_och)
1131 ll_md_real_close(inode, FMODE_READ);
1134 obd_change_cbdata(sbi->ll_dt_exp, lli->lli_smd,
1135 null_if_equal, inode);
1137 obd_free_memmd(sbi->ll_dt_exp, &lli->lli_smd);
1138 lli->lli_smd = NULL;
1141 if (lli->lli_symlink_name) {
1142 OBD_FREE(lli->lli_symlink_name,
1143 strlen(lli->lli_symlink_name) + 1);
1144 lli->lli_symlink_name = NULL;
1147 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
1148 LASSERT(lli->lli_posix_acl == NULL);
1149 if (lli->lli_remote_perms) {
1150 free_rmtperm_hash(lli->lli_remote_perms);
1151 lli->lli_remote_perms = NULL;
1154 #ifdef CONFIG_FS_POSIX_ACL
1155 else if (lli->lli_posix_acl) {
1156 LASSERT(atomic_read(&lli->lli_posix_acl->a_refcount) == 1);
1157 LASSERT(lli->lli_remote_perms == NULL);
1158 posix_acl_release(lli->lli_posix_acl);
1159 lli->lli_posix_acl = NULL;
1162 lli->lli_inode_magic = LLI_INODE_DEAD;
1164 #ifdef HAVE_EXPORT___IGET
1165 spin_lock(&sbi->ll_deathrow_lock);
1166 list_del_init(&lli->lli_dead_list);
1167 spin_unlock(&sbi->ll_deathrow_lock);
1169 ll_clear_inode_capas(inode);
1174 int ll_md_setattr(struct inode *inode, struct md_op_data *op_data,
1175 struct md_open_data **mod)
1177 struct lustre_md md;
1178 struct ll_sb_info *sbi = ll_i2sbi(inode);
1179 struct ptlrpc_request *request = NULL;
1183 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1184 LUSTRE_OPC_ANY, NULL);
1185 if (IS_ERR(op_data))
1186 RETURN(PTR_ERR(op_data));
1188 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, NULL, 0,
1191 ptlrpc_req_finished(request);
1192 if (rc == -ENOENT) {
1194 /* Unlinked special device node? Or just a race?
1195 * Pretend we done everything. */
1196 if (!S_ISREG(inode->i_mode) &&
1197 !S_ISDIR(inode->i_mode))
1198 rc = inode_setattr(inode, &op_data->op_attr);
1199 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1200 CERROR("md_setattr fails: rc = %d\n", rc);
1205 rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
1206 sbi->ll_md_exp, &md);
1208 ptlrpc_req_finished(request);
1212 /* We call inode_setattr to adjust timestamps.
1213 * If there is at least some data in file, we cleared ATTR_SIZE
1214 * above to avoid invoking vmtruncate, otherwise it is important
1215 * to call vmtruncate in inode_setattr to update inode->i_size
1217 rc = inode_setattr(inode, &op_data->op_attr);
1219 /* Extract epoch data if obtained. */
1220 op_data->op_handle = md.body->handle;
1221 op_data->op_ioepoch = md.body->ioepoch;
1223 ll_update_inode(inode, &md);
1224 ptlrpc_req_finished(request);
1229 /* Close IO epoch and send Size-on-MDS attribute update. */
1230 static int ll_setattr_done_writing(struct inode *inode,
1231 struct md_op_data *op_data,
1232 struct md_open_data *mod)
1234 struct ll_inode_info *lli = ll_i2info(inode);
1238 LASSERT(op_data != NULL);
1239 if (!S_ISREG(inode->i_mode))
1242 CDEBUG(D_INODE, "Epoch "LPU64" closed on "DFID" for truncate\n",
1243 op_data->op_ioepoch, PFID(&lli->lli_fid));
1245 op_data->op_flags = MF_EPOCH_CLOSE | MF_SOM_CHANGE;
1246 rc = md_done_writing(ll_i2sbi(inode)->ll_md_exp, op_data, mod);
1247 if (rc == -EAGAIN) {
1248 /* MDS has instructed us to obtain Size-on-MDS attribute
1249 * from OSTs and send setattr to back to MDS. */
1250 rc = ll_sizeonmds_update(inode, mod, &op_data->op_handle,
1251 op_data->op_ioepoch);
1253 CERROR("inode %lu mdc truncate failed: rc = %d\n",
1259 static int ll_setattr_do_truncate(struct inode *inode, loff_t new_size)
1261 struct ll_sb_info *sbi = ll_i2sbi(inode);
1262 struct ll_inode_info *lli = ll_i2info(inode);
1263 struct lov_stripe_md *lsm = lli->lli_smd;
1265 ldlm_policy_data_t policy = { .l_extent = {new_size,
1267 struct lustre_handle lockh = { 0 };
1268 int local_lock = 0; /* 0 - no local lock;
1269 * 1 - lock taken by lock_extent;
1270 * 2 - by obd_match*/
1275 UNLOCK_INODE_MUTEX(inode);
1276 UP_WRITE_I_ALLOC_SEM(inode);
1278 if (sbi->ll_lockless_truncate_enable &&
1279 (sbi->ll_lco.lco_flags & OBD_CONNECT_TRUNCLOCK)) {
1280 ast_flags = LDLM_FL_BLOCK_GRANTED;
1281 rc = obd_match(sbi->ll_dt_exp, lsm, LDLM_EXTENT,
1282 &policy, LCK_PW, &ast_flags, inode, &lockh);
1286 } else if (rc == 0) {
1287 rc = ll_file_punch(inode, new_size, 1);
1290 /* XXX when we fix the AST intents to pass the discard-range
1291 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
1293 ast_flags = (new_size == 0) ? LDLM_AST_DISCARD_DATA : 0;
1294 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy,
1296 if (likely(rc == 0))
1300 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1301 DOWN_WRITE_I_ALLOC_SEM(inode);
1302 LOCK_INODE_MUTEX(inode);
1304 LOCK_INODE_MUTEX(inode);
1305 DOWN_WRITE_I_ALLOC_SEM(inode);
1307 if (likely(rc == 0)) {
1308 /* Only ll_inode_size_lock is taken at this level.
1309 * lov_stripe_lock() is grabbed by ll_truncate() only over
1310 * call to obd_adjust_kms(). If vmtruncate returns 0, then
1311 * ll_truncate dropped ll_inode_size_lock() */
1312 ll_inode_size_lock(inode, 0);
1314 spin_lock(&lli->lli_lock);
1315 lli->lli_flags |= LLIF_SRVLOCK;
1316 spin_unlock(&lli->lli_lock);
1318 rc = vmtruncate(inode, new_size);
1320 spin_lock(&lli->lli_lock);
1321 lli->lli_flags &= ~LLIF_SRVLOCK;
1322 spin_unlock(&lli->lli_lock);
1325 LASSERT(atomic_read(&lli->lli_size_sem.count) <= 0);
1326 ll_inode_size_unlock(inode, 0);
1331 if (local_lock == 2)
1332 err = obd_cancel(sbi->ll_dt_exp, lsm, LCK_PW, &lockh);
1334 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
1335 if (unlikely(err != 0)){
1336 CERROR("extent unlock failed: err=%d,"
1337 " unlock method =%d\n", err, local_lock);
1345 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1346 * object(s) determine the file size and mtime. Otherwise, the MDS will
1347 * keep these values until such a time that objects are allocated for it.
1348 * We do the MDS operations first, as it is checking permissions for us.
1349 * We don't to the MDS RPC if there is nothing that we want to store there,
1350 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1351 * going to do an RPC anyways.
1353 * If we are doing a truncate, we will send the mtime and ctime updates
1354 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1355 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1358 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
1360 struct ll_inode_info *lli = ll_i2info(inode);
1361 struct lov_stripe_md *lsm = lli->lli_smd;
1362 struct ll_sb_info *sbi = ll_i2sbi(inode);
1363 struct md_op_data *op_data = NULL;
1364 struct md_open_data *mod = NULL;
1365 int ia_valid = attr->ia_valid;
1366 int rc = 0, rc1 = 0;
1369 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu valid %x\n", inode->i_ino,
1371 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_SETATTR, 1);
1373 if (ia_valid & ATTR_SIZE) {
1374 if (attr->ia_size > ll_file_maxbytes(inode)) {
1375 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
1376 attr->ia_size, ll_file_maxbytes(inode));
1380 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1383 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1384 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
1385 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1389 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1390 if (attr->ia_valid & ATTR_CTIME) {
1391 attr->ia_ctime = CURRENT_TIME;
1392 attr->ia_valid |= ATTR_CTIME_SET;
1394 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
1395 attr->ia_atime = CURRENT_TIME;
1396 attr->ia_valid |= ATTR_ATIME_SET;
1398 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
1399 attr->ia_mtime = CURRENT_TIME;
1400 attr->ia_valid |= ATTR_MTIME_SET;
1402 if ((attr->ia_valid & ATTR_CTIME) && !(attr->ia_valid & ATTR_MTIME)) {
1403 /* To avoid stale mtime on mds, obtain it from ost and send
1405 rc = ll_glimpse_size(inode, 0);
1409 attr->ia_valid |= ATTR_MTIME_SET | ATTR_MTIME;
1410 attr->ia_mtime = inode->i_mtime;
1413 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1414 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
1415 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1416 cfs_time_current_sec());
1418 /* NB: ATTR_SIZE will only be set after this point if the size
1419 * resides on the MDS, ie, this file has no objects. */
1421 attr->ia_valid &= ~ATTR_SIZE;
1423 /* We always do an MDS RPC, even if we're only changing the size;
1424 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
1426 OBD_ALLOC_PTR(op_data);
1427 if (op_data == NULL)
1430 memcpy(&op_data->op_attr, attr, sizeof(*attr));
1432 /* Open epoch for truncate. */
1433 if ((ll_i2mdexp(inode)->exp_connect_flags & OBD_CONNECT_SOM) &&
1434 (ia_valid & ATTR_SIZE))
1435 op_data->op_flags = MF_EPOCH_OPEN;
1437 rc = ll_md_setattr(inode, op_data, &mod);
1441 if (op_data->op_ioepoch)
1442 CDEBUG(D_INODE, "Epoch "LPU64" opened on "DFID" for "
1443 "truncate\n", op_data->op_ioepoch, PFID(&lli->lli_fid));
1445 if (!lsm || !S_ISREG(inode->i_mode)) {
1446 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
1450 /* We really need to get our PW lock before we change inode->i_size.
1451 * If we don't we can race with other i_size updaters on our node, like
1452 * ll_file_read. We can also race with i_size propogation to other
1453 * nodes through dirtying and writeback of final cached pages. This
1454 * last one is especially bad for racing o_append users on other
1456 if (ia_valid & ATTR_SIZE) {
1457 rc = ll_setattr_do_truncate(inode, attr->ia_size);
1458 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
1460 struct obd_info oinfo = { { { 0 } } };
1463 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1464 inode->i_ino, LTIME_S(attr->ia_mtime));
1468 oa->o_id = lsm->lsm_object_id;
1469 oa->o_gr = lsm->lsm_object_gr;
1470 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1472 flags = OBD_MD_FLTYPE | OBD_MD_FLATIME |
1473 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1474 OBD_MD_FLFID | OBD_MD_FLGENER |
1477 obdo_from_inode(oa, inode, flags);
1481 oinfo.oi_capa = ll_mdscapa_get(inode);
1483 /* XXX: this looks unnecessary now. */
1484 rc = obd_setattr_rqset(sbi->ll_dt_exp, &oinfo, NULL);
1485 capa_put(oinfo.oi_capa);
1487 CERROR("obd_setattr_async fails: rc=%d\n", rc);
1496 if (op_data->op_ioepoch)
1497 rc1 = ll_setattr_done_writing(inode, op_data, mod);
1498 ll_finish_md_op_data(op_data);
1500 return rc ? rc : rc1;
1503 int ll_setattr(struct dentry *de, struct iattr *attr)
1505 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1506 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1507 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1509 return ll_setattr_raw(de->d_inode, attr);
1512 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1513 __u64 max_age, __u32 flags)
1515 struct ll_sb_info *sbi = ll_s2sbi(sb);
1516 struct obd_statfs obd_osfs;
1520 rc = obd_statfs(class_exp2obd(sbi->ll_md_exp), osfs, max_age, flags);
1522 CERROR("md_statfs fails: rc = %d\n", rc);
1526 osfs->os_type = sb->s_magic;
1528 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1529 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1531 rc = obd_statfs_rqset(class_exp2obd(sbi->ll_dt_exp),
1532 &obd_osfs, max_age, flags);
1534 CERROR("obd_statfs fails: rc = %d\n", rc);
1538 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1539 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1542 osfs->os_bsize = obd_osfs.os_bsize;
1543 osfs->os_blocks = obd_osfs.os_blocks;
1544 osfs->os_bfree = obd_osfs.os_bfree;
1545 osfs->os_bavail = obd_osfs.os_bavail;
1547 /* If we don't have as many objects free on the OST as inodes
1548 * on the MDS, we reduce the total number of inodes to
1549 * compensate, so that the "inodes in use" number is correct.
1551 if (obd_osfs.os_ffree < osfs->os_ffree) {
1552 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1554 osfs->os_ffree = obd_osfs.os_ffree;
1559 #ifndef HAVE_STATFS_DENTRY_PARAM
1560 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1563 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1565 struct super_block *sb = de->d_sb;
1567 struct obd_statfs osfs;
1570 CDEBUG(D_VFSTRACE, "VFS Op: at "LPU64" jiffies\n", get_jiffies_64());
1571 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1);
1573 /* For now we will always get up-to-date statfs values, but in the
1574 * future we may allow some amount of caching on the client (e.g.
1575 * from QOS or lprocfs updates). */
1576 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - 1, 0);
1580 statfs_unpack(sfs, &osfs);
1582 /* We need to downshift for all 32-bit kernels, because we can't
1583 * tell if the kernel is being called via sys_statfs64() or not.
1584 * Stop before overflowing f_bsize - in which case it is better
1585 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
1586 if (sizeof(long) < 8) {
1587 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1590 osfs.os_blocks >>= 1;
1591 osfs.os_bfree >>= 1;
1592 osfs.os_bavail >>= 1;
1596 sfs->f_blocks = osfs.os_blocks;
1597 sfs->f_bfree = osfs.os_bfree;
1598 sfs->f_bavail = osfs.os_bavail;
1603 void ll_inode_size_lock(struct inode *inode, int lock_lsm)
1605 struct ll_inode_info *lli;
1606 struct lov_stripe_md *lsm;
1608 lli = ll_i2info(inode);
1609 LASSERT(lli->lli_size_sem_owner != current);
1610 down(&lli->lli_size_sem);
1611 LASSERT(lli->lli_size_sem_owner == NULL);
1612 lli->lli_size_sem_owner = current;
1614 LASSERTF(lsm != NULL || lock_lsm == 0, "lsm %p, lock_lsm %d\n",
1617 lov_stripe_lock(lsm);
1620 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm)
1622 struct ll_inode_info *lli;
1623 struct lov_stripe_md *lsm;
1625 lli = ll_i2info(inode);
1627 LASSERTF(lsm != NULL || unlock_lsm == 0, "lsm %p, lock_lsm %d\n",
1630 lov_stripe_unlock(lsm);
1631 LASSERT(lli->lli_size_sem_owner == current);
1632 lli->lli_size_sem_owner = NULL;
1633 up(&lli->lli_size_sem);
1636 static void ll_replace_lsm(struct inode *inode, struct lov_stripe_md *lsm)
1638 struct ll_inode_info *lli = ll_i2info(inode);
1640 dump_lsm(D_INODE, lsm);
1641 dump_lsm(D_INODE, lli->lli_smd);
1642 LASSERTF(lsm->lsm_magic == LOV_MAGIC_JOIN,
1643 "lsm must be joined lsm %p\n", lsm);
1644 obd_free_memmd(ll_i2dtexp(inode), &lli->lli_smd);
1645 CDEBUG(D_INODE, "replace lsm %p to lli_smd %p for inode %lu%u(%p)\n",
1646 lsm, lli->lli_smd, inode->i_ino, inode->i_generation, inode);
1648 lli->lli_maxbytes = lsm->lsm_maxbytes;
1649 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1650 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1653 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1655 struct ll_inode_info *lli = ll_i2info(inode);
1656 struct mdt_body *body = md->body;
1657 struct lov_stripe_md *lsm = md->lsm;
1658 struct ll_sb_info *sbi = ll_i2sbi(inode);
1660 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1662 if (lli->lli_smd == NULL) {
1663 if (lsm->lsm_magic != LOV_MAGIC &&
1664 lsm->lsm_magic != LOV_MAGIC_JOIN) {
1665 dump_lsm(D_ERROR, lsm);
1668 CDEBUG(D_INODE, "adding lsm %p to inode %lu/%u(%p)\n",
1669 lsm, inode->i_ino, inode->i_generation, inode);
1670 /* ll_inode_size_lock() requires it is only called
1671 * with lli_smd != NULL or lock_lsm == 0 or we can
1672 * race between lock/unlock. bug 9547 */
1674 lli->lli_maxbytes = lsm->lsm_maxbytes;
1675 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1676 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1678 if (lli->lli_smd->lsm_magic == lsm->lsm_magic &&
1679 lli->lli_smd->lsm_stripe_count ==
1680 lsm->lsm_stripe_count) {
1681 if (lov_stripe_md_cmp(lli->lli_smd, lsm)) {
1682 CERROR("lsm mismatch for inode %ld\n",
1684 CERROR("lli_smd:\n");
1685 dump_lsm(D_ERROR, lli->lli_smd);
1687 dump_lsm(D_ERROR, lsm);
1691 ll_replace_lsm(inode, lsm);
1693 if (lli->lli_smd != lsm)
1694 obd_free_memmd(ll_i2dtexp(inode), &lsm);
1697 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
1698 if (body->valid & OBD_MD_FLRMTPERM)
1699 ll_update_remote_perm(inode, md->remote_perm);
1701 #ifdef CONFIG_FS_POSIX_ACL
1702 else if (body->valid & OBD_MD_FLACL) {
1703 spin_lock(&lli->lli_lock);
1704 if (lli->lli_posix_acl)
1705 posix_acl_release(lli->lli_posix_acl);
1706 lli->lli_posix_acl = md->posix_acl;
1707 spin_unlock(&lli->lli_lock);
1710 inode->i_ino = ll_fid_build_ino(sbi, &body->fid1);
1712 if (body->valid & OBD_MD_FLATIME &&
1713 body->atime > LTIME_S(inode->i_atime))
1714 LTIME_S(inode->i_atime) = body->atime;
1716 /* mtime is always updated with ctime, but can be set in past.
1717 As write and utime(2) may happen within 1 second, and utime's
1718 mtime has a priority over write's one, so take mtime from mds
1719 for the same ctimes. */
1720 if (body->valid & OBD_MD_FLCTIME &&
1721 body->ctime >= LTIME_S(inode->i_ctime)) {
1722 LTIME_S(inode->i_ctime) = body->ctime;
1723 if (body->valid & OBD_MD_FLMTIME) {
1724 CDEBUG(D_INODE, "setting ino %lu mtime "
1725 "from %lu to "LPU64"\n", inode->i_ino,
1726 LTIME_S(inode->i_mtime), body->mtime);
1727 LTIME_S(inode->i_mtime) = body->mtime;
1730 if (body->valid & OBD_MD_FLMODE)
1731 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1732 if (body->valid & OBD_MD_FLTYPE)
1733 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1734 if (S_ISREG(inode->i_mode)) {
1735 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS + 1, LL_MAX_BLKSIZE_BITS);
1737 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
1739 #ifdef HAVE_INODE_BLKSIZE
1740 inode->i_blksize = 1<<inode->i_blkbits;
1742 if (body->valid & OBD_MD_FLUID)
1743 inode->i_uid = body->uid;
1744 if (body->valid & OBD_MD_FLGID)
1745 inode->i_gid = body->gid;
1746 if (body->valid & OBD_MD_FLFLAGS)
1747 inode->i_flags = ll_ext_to_inode_flags(body->flags);
1748 if (body->valid & OBD_MD_FLNLINK)
1749 inode->i_nlink = body->nlink;
1750 if (body->valid & OBD_MD_FLRDEV)
1751 inode->i_rdev = old_decode_dev(body->rdev);
1753 if (body->valid & OBD_MD_FLID) {
1754 /* FID shouldn't be changed! */
1755 if (fid_is_sane(&lli->lli_fid)) {
1756 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->fid1),
1757 "Trying to change FID "DFID
1758 " to the "DFID", inode %lu/%u(%p)\n",
1759 PFID(&lli->lli_fid), PFID(&body->fid1),
1760 inode->i_ino, inode->i_generation, inode);
1762 lli->lli_fid = body->fid1;
1765 LASSERT(fid_seq(&lli->lli_fid) != 0);
1767 if (body->valid & OBD_MD_FLSIZE) {
1768 if ((ll_i2mdexp(inode)->exp_connect_flags & OBD_CONNECT_SOM) &&
1769 S_ISREG(inode->i_mode) && lli->lli_smd) {
1770 struct lustre_handle lockh;
1773 /* As it is possible a blocking ast has been processed
1774 * by this time, we need to check there is an UPDATE
1775 * lock on the client and set LLIF_MDS_SIZE_LOCK holding
1777 mode = ll_take_md_lock(inode, MDS_INODELOCK_UPDATE,
1780 if (lli->lli_flags & (LLIF_DONE_WRITING |
1781 LLIF_EPOCH_PENDING |
1783 CERROR("ino %lu flags %lu still has "
1784 "size authority! do not trust "
1785 "the size got from MDS\n",
1786 inode->i_ino, lli->lli_flags);
1788 /* Use old size assignment to avoid
1789 * deadlock bz14138 & bz14326 */
1790 inode->i_size = body->size;
1791 lli->lli_flags |= LLIF_MDS_SIZE_LOCK;
1793 ldlm_lock_decref(&lockh, mode);
1796 /* Use old size assignment to avoid
1797 * deadlock bz14138 & bz14326 */
1798 inode->i_size = body->size;
1801 if (body->valid & OBD_MD_FLBLOCKS)
1802 inode->i_blocks = body->blocks;
1805 if (body->valid & OBD_MD_FLMDSCAPA) {
1806 LASSERT(md->mds_capa);
1807 ll_add_capa(inode, md->mds_capa);
1809 if (body->valid & OBD_MD_FLOSSCAPA) {
1810 LASSERT(md->oss_capa);
1811 ll_add_capa(inode, md->oss_capa);
1815 static struct backing_dev_info ll_backing_dev_info = {
1816 .ra_pages = 0, /* No readahead */
1817 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
1818 .capabilities = 0, /* Does contribute to dirty memory */
1820 .memory_backed = 0, /* Does contribute to dirty memory */
1824 void ll_read_inode2(struct inode *inode, void *opaque)
1826 struct lustre_md *md = opaque;
1827 struct ll_inode_info *lli = ll_i2info(inode);
1830 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n",
1831 inode->i_ino, inode->i_generation, inode);
1835 LASSERT(!lli->lli_smd);
1837 /* Core attributes from the MDS first. This is a new inode, and
1838 * the VFS doesn't zero times in the core inode so we have to do
1839 * it ourselves. They will be overwritten by either MDS or OST
1840 * attributes - we just need to make sure they aren't newer. */
1841 LTIME_S(inode->i_mtime) = 0;
1842 LTIME_S(inode->i_atime) = 0;
1843 LTIME_S(inode->i_ctime) = 0;
1845 ll_update_inode(inode, md);
1847 /* OIDEBUG(inode); */
1849 if (S_ISREG(inode->i_mode)) {
1850 struct ll_sb_info *sbi = ll_i2sbi(inode);
1851 inode->i_op = &ll_file_inode_operations;
1852 inode->i_fop = sbi->ll_fop;
1853 inode->i_mapping->a_ops = &ll_aops;
1855 } else if (S_ISDIR(inode->i_mode)) {
1856 inode->i_op = &ll_dir_inode_operations;
1857 inode->i_fop = &ll_dir_operations;
1858 inode->i_mapping->a_ops = &ll_dir_aops;
1860 } else if (S_ISLNK(inode->i_mode)) {
1861 inode->i_op = &ll_fast_symlink_inode_operations;
1864 inode->i_op = &ll_special_inode_operations;
1866 init_special_inode(inode, inode->i_mode,
1867 kdev_t_to_nr(inode->i_rdev));
1869 /* initializing backing dev info. */
1870 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
1876 void ll_delete_inode(struct inode *inode)
1878 struct ll_sb_info *sbi = ll_i2sbi(inode);
1882 rc = obd_fid_delete(sbi->ll_md_exp, ll_inode2fid(inode));
1884 CERROR("fid_delete() failed, rc %d\n", rc);
1886 truncate_inode_pages(&inode->i_data, 0);
1892 int ll_iocontrol(struct inode *inode, struct file *file,
1893 unsigned int cmd, unsigned long arg)
1895 struct ll_sb_info *sbi = ll_i2sbi(inode);
1896 struct ptlrpc_request *req = NULL;
1901 case EXT3_IOC_GETFLAGS: {
1902 struct mdt_body *body;
1903 struct obd_capa *oc;
1905 oc = ll_mdscapa_get(inode);
1906 rc = md_getattr(sbi->ll_md_exp, ll_inode2fid(inode), oc,
1907 OBD_MD_FLFLAGS, 0, &req);
1910 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1914 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1916 flags = body->flags;
1918 ptlrpc_req_finished(req);
1920 RETURN(put_user(flags, (int *)arg));
1922 case EXT3_IOC_SETFLAGS: {
1923 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1924 struct obd_info oinfo = { { { 0 } } };
1925 struct md_op_data *op_data;
1927 if (get_user(flags, (int *)arg))
1931 OBDO_ALLOC(oinfo.oi_oa);
1935 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
1936 LUSTRE_OPC_ANY, NULL);
1937 if (IS_ERR(op_data))
1938 RETURN(PTR_ERR(op_data));
1940 ((struct ll_iattr *)&op_data->op_attr)->ia_attr_flags = flags;
1941 op_data->op_attr.ia_valid |= ATTR_ATTR_FLAG;
1942 rc = md_setattr(sbi->ll_md_exp, op_data,
1943 NULL, 0, NULL, 0, &req, NULL);
1944 ll_finish_md_op_data(op_data);
1945 ptlrpc_req_finished(req);
1946 if (rc || lsm == NULL) {
1947 OBDO_FREE(oinfo.oi_oa);
1951 oinfo.oi_oa->o_id = lsm->lsm_object_id;
1952 oinfo.oi_oa->o_gr = lsm->lsm_object_gr;
1953 oinfo.oi_oa->o_flags = flags;
1954 oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS |
1956 oinfo.oi_capa = ll_mdscapa_get(inode);
1958 obdo_from_inode(oinfo.oi_oa, inode,
1959 OBD_MD_FLFID | OBD_MD_FLGENER);
1960 rc = obd_setattr_rqset(sbi->ll_dt_exp, &oinfo, NULL);
1961 capa_put(oinfo.oi_capa);
1962 OBDO_FREE(oinfo.oi_oa);
1964 if (rc != -EPERM && rc != -EACCES)
1965 CERROR("md_setattr_async fails: rc = %d\n", rc);
1969 inode->i_flags = ll_ext_to_inode_flags(flags |
1970 MDS_BFLAG_EXT_FLAGS);
1980 int ll_flush_ctx(struct inode *inode)
1982 struct ll_sb_info *sbi = ll_i2sbi(inode);
1984 CDEBUG(D_SEC, "flush context for user %d\n", current->uid);
1986 obd_set_info_async(sbi->ll_md_exp,
1987 sizeof(KEY_FLUSH_CTX) - 1, KEY_FLUSH_CTX,
1989 obd_set_info_async(sbi->ll_dt_exp,
1990 sizeof(KEY_FLUSH_CTX) - 1, KEY_FLUSH_CTX,
1995 /* umount -f client means force down, don't save state */
1996 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
1997 void ll_umount_begin(struct vfsmount *vfsmnt, int flags)
1999 struct super_block *sb = vfsmnt->mnt_sb;
2001 void ll_umount_begin(struct super_block *sb)
2004 struct lustre_sb_info *lsi = s2lsi(sb);
2005 struct ll_sb_info *sbi = ll_s2sbi(sb);
2006 struct obd_device *obd;
2007 struct obd_ioctl_data ioc_data = { 0 };
2010 #ifdef HAVE_UMOUNTBEGIN_VFSMOUNT
2011 if (!(flags & MNT_FORCE)) {
2017 /* Tell the MGC we got umount -f */
2018 lsi->lsi_flags |= LSI_UMOUNT_FORCE;
2020 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2021 sb->s_count, atomic_read(&sb->s_active));
2023 obd = class_exp2obd(sbi->ll_md_exp);
2025 CERROR("Invalid MDC connection handle "LPX64"\n",
2026 sbi->ll_md_exp->exp_handle.h_cookie);
2031 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp, sizeof ioc_data,
2034 obd = class_exp2obd(sbi->ll_dt_exp);
2036 CERROR("Invalid LOV connection handle "LPX64"\n",
2037 sbi->ll_dt_exp->exp_handle.h_cookie);
2043 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp, sizeof ioc_data,
2046 /* Really, we'd like to wait until there are no requests outstanding,
2047 * and then continue. For now, we just invalidate the requests,
2048 * schedule, and hope.
2055 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2057 struct ll_sb_info *sbi = ll_s2sbi(sb);
2061 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
2062 read_only = *flags & MS_RDONLY;
2063 err = obd_set_info_async(sbi->ll_md_exp,
2064 sizeof(KEY_READ_ONLY) - 1,
2065 KEY_READ_ONLY, sizeof(read_only),
2068 CERROR("Failed to change the read-only flag during "
2069 "remount: %d\n", err);
2074 sb->s_flags |= MS_RDONLY;
2076 sb->s_flags &= ~MS_RDONLY;
2081 int ll_prep_inode(struct inode **inode,
2082 struct ptlrpc_request *req,
2083 struct super_block *sb)
2085 struct ll_sb_info *sbi = NULL;
2086 struct lustre_md md;
2090 LASSERT(*inode || sb);
2091 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2092 prune_deathrow(sbi, 1);
2093 memset(&md, 0, sizeof(struct lustre_md));
2095 rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
2096 sbi->ll_md_exp, &md);
2101 ll_update_inode(*inode, &md);
2103 LASSERT(sb != NULL);
2106 * At this point server returns to client's same fid as client
2107 * generated for creating. So using ->fid1 is okay here.
2109 LASSERT(fid_is_sane(&md.body->fid1));
2111 *inode = ll_iget(sb, ll_fid_build_ino(sbi, &md.body->fid1), &md);
2112 if (*inode == NULL || is_bad_inode(*inode)) {
2114 obd_free_memmd(sbi->ll_dt_exp, &md.lsm);
2115 #ifdef CONFIG_FS_POSIX_ACL
2117 posix_acl_release(md.posix_acl);
2118 md.posix_acl = NULL;
2122 CERROR("new_inode -fatal: rc %d\n", rc);
2127 rc = obd_checkmd(sbi->ll_dt_exp, sbi->ll_md_exp,
2128 ll_i2info(*inode)->lli_smd);
2130 md_free_lustre_md(sbi->ll_md_exp, &md);
2134 char *llap_origins[] = {
2135 [LLAP_ORIGIN_UNKNOWN] = "--",
2136 [LLAP_ORIGIN_READPAGE] = "rp",
2137 [LLAP_ORIGIN_READAHEAD] = "ra",
2138 [LLAP_ORIGIN_COMMIT_WRITE] = "cw",
2139 [LLAP_ORIGIN_WRITEPAGE] = "wp",
2140 [LLAP_ORIGIN_LOCKLESS_IO] = "ls"
2143 struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
2144 struct list_head *list)
2146 struct ll_async_page *llap;
2147 struct list_head *pos;
2149 list_for_each(pos, list) {
2150 if (pos == &sbi->ll_pglist)
2152 llap = list_entry(pos, struct ll_async_page, llap_pglist_item);
2153 if (llap->llap_page == NULL)
2161 int ll_obd_statfs(struct inode *inode, void *arg)
2163 struct ll_sb_info *sbi = NULL;
2164 struct obd_export *exp;
2166 struct obd_ioctl_data *data = NULL;
2170 if (!inode || !(sbi = ll_i2sbi(inode)))
2171 GOTO(out_statfs, rc = -EINVAL);
2173 rc = obd_ioctl_getdata(&buf, &len, arg);
2175 GOTO(out_statfs, rc);
2178 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2179 !data->ioc_pbuf1 || !data->ioc_pbuf2)
2180 GOTO(out_statfs, rc = -EINVAL);
2182 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2183 if (type == LL_STATFS_MDC)
2184 exp = sbi->ll_md_exp;
2185 else if (type == LL_STATFS_LOV)
2186 exp = sbi->ll_dt_exp;
2188 GOTO(out_statfs, rc = -ENODEV);
2190 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL);
2192 GOTO(out_statfs, rc);
2195 obd_ioctl_freedata(buf, len);
2199 int ll_process_config(struct lustre_cfg *lcfg)
2203 struct lprocfs_static_vars lvars;
2207 lprocfs_llite_init_vars(&lvars);
2209 /* The instance name contains the sb: lustre-client-aacfe000 */
2210 ptr = strrchr(lustre_cfg_string(lcfg, 0), '-');
2211 if (!ptr || !*(++ptr))
2213 if (sscanf(ptr, "%lx", &x) != 1)
2216 /* This better be a real Lustre superblock! */
2217 LASSERT(s2lsi((struct super_block *)sb)->lsi_lmd->lmd_magic == LMD_MAGIC);
2219 /* Note we have not called client_common_fill_super yet, so
2220 proc fns must be able to handle that! */
2221 rc = class_process_proc_param(PARAM_LLITE, lvars.obd_vars,
2226 /* this function prepares md_op_data hint for passing ot down to MD stack. */
2227 struct md_op_data * ll_prep_md_op_data(struct md_op_data *op_data,
2228 struct inode *i1, struct inode *i2,
2229 const char *name, int namelen,
2230 int mode, __u32 opc, void *data)
2232 LASSERT(i1 != NULL);
2234 if (namelen > ll_i2sbi(i1)->ll_namelen)
2235 return ERR_PTR(-ENAMETOOLONG);
2237 if (op_data == NULL)
2238 OBD_ALLOC_PTR(op_data);
2240 if (op_data == NULL)
2241 return ERR_PTR(-ENOMEM);
2243 ll_i2gids(op_data->op_suppgids, i1, i2);
2244 op_data->op_fid1 = *ll_inode2fid(i1);
2245 op_data->op_capa1 = ll_mdscapa_get(i1);
2248 op_data->op_fid2 = *ll_inode2fid(i2);
2249 op_data->op_capa2 = ll_mdscapa_get(i2);
2251 fid_zero(&op_data->op_fid2);
2252 op_data->op_capa2 = NULL;
2255 op_data->op_name = name;
2256 op_data->op_namelen = namelen;
2257 op_data->op_mode = mode;
2258 op_data->op_mod_time = cfs_time_current_sec();
2259 op_data->op_fsuid = current->fsuid;
2260 op_data->op_fsgid = current->fsgid;
2261 op_data->op_cap = current->cap_effective;
2262 op_data->op_bias = MDS_CHECK_SPLIT;
2263 op_data->op_opc = opc;
2264 op_data->op_mds = 0;
2265 op_data->op_data = data;
2270 void ll_finish_md_op_data(struct md_op_data *op_data)
2272 capa_put(op_data->op_capa1);
2273 capa_put(op_data->op_capa2);
2274 OBD_FREE_PTR(op_data);