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 "llite_internal.h"
40 kmem_cache_t *ll_file_data_slab;
42 LIST_HEAD(ll_super_blocks);
43 spinlock_t ll_sb_lock = SPIN_LOCK_UNLOCKED;
45 extern struct address_space_operations ll_aops;
46 extern struct address_space_operations ll_dir_aops;
49 #define log2(n) ffz(~(n))
53 static struct ll_sb_info *ll_init_sbi(void)
55 struct ll_sb_info *sbi = NULL;
60 OBD_ALLOC(sbi, sizeof(*sbi));
64 spin_lock_init(&sbi->ll_lock);
65 spin_lock_init(&sbi->ll_lco.lco_lock);
66 INIT_LIST_HEAD(&sbi->ll_pglist);
67 if (num_physpages >> (20 - PAGE_SHIFT) < 512)
68 sbi->ll_async_page_max = num_physpages / 2;
70 sbi->ll_async_page_max = (num_physpages / 4) * 3;
71 sbi->ll_ra_info.ra_max_pages = min(num_physpages / 8,
72 SBI_DEFAULT_READAHEAD_MAX);
73 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
74 SBI_DEFAULT_READAHEAD_WHOLE_MAX;
76 INIT_LIST_HEAD(&sbi->ll_conn_chain);
77 INIT_LIST_HEAD(&sbi->ll_orphan_dentry_list);
79 class_generate_random_uuid(uuid);
80 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
81 CDEBUG(D_HA, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
83 spin_lock(&ll_sb_lock);
84 list_add_tail(&sbi->ll_list, &ll_super_blocks);
85 spin_unlock(&ll_sb_lock);
87 INIT_LIST_HEAD(&sbi->ll_deathrow);
88 spin_lock_init(&sbi->ll_deathrow_lock);
89 for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
90 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_r_hist.oh_lock);
91 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].pp_w_hist.oh_lock);
97 void ll_free_sbi(struct super_block *sb)
99 struct ll_sb_info *sbi = ll_s2sbi(sb);
103 spin_lock(&ll_sb_lock);
104 list_del(&sbi->ll_list);
105 spin_unlock(&ll_sb_lock);
106 OBD_FREE(sbi, sizeof(*sbi));
111 static struct dentry_operations ll_d_root_ops = {
112 #ifdef LUSTRE_KERNEL_VERSION
113 .d_compare = ll_dcompare,
117 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
118 * us to make MDS RPCs with large enough reply buffers to hold the
119 * maximum-sized (= maximum striped) EA and cookie without having to
120 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
121 static int ll_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp)
123 struct lov_stripe_md lsm = { .lsm_magic = LOV_MAGIC };
124 __u32 valsize = sizeof(struct lov_desc);
125 int rc, easize, def_easize, cookiesize;
126 struct lov_desc desc;
130 rc = obd_get_info(dt_exp, strlen(KEY_LOVDESC) + 1, KEY_LOVDESC,
135 stripes = min(desc.ld_tgt_count, (__u32)LOV_MAX_STRIPE_COUNT);
136 lsm.lsm_stripe_count = stripes;
137 easize = obd_size_diskmd(dt_exp, &lsm);
139 lsm.lsm_stripe_count = desc.ld_default_stripe_count;
140 def_easize = obd_size_diskmd(dt_exp, &lsm);
142 cookiesize = stripes * sizeof(struct llog_cookie);
144 CDEBUG(D_HA, "updating max_mdsize/max_cookiesize: %d/%d\n",
147 rc = md_init_ea_size(md_exp, easize, def_easize, cookiesize);
151 static int client_common_fill_super(struct super_block *sb,
153 uid_t nllu, gid_t nllg)
155 struct inode *root = 0;
156 struct ll_sb_info *sbi = ll_s2sbi(sb);
157 struct obd_device *obd;
158 struct lu_fid rootfid;
159 struct obd_capa *oc = NULL;
160 struct obd_statfs osfs;
161 struct ptlrpc_request *request = NULL;
162 struct lustre_handle dt_conn = {0, };
163 struct lustre_handle md_conn = {0, };
164 struct obd_connect_data *data = NULL;
165 struct lustre_md lmd;
170 obd = class_name2obd(md);
172 CERROR("MD %s: not setup or attached\n", md);
180 if (proc_lustre_fs_root) {
181 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
184 CERROR("could not register mount in /proc/lustre");
187 /* indicate the features supported by this client */
188 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
189 OBD_CONNECT_ACL | OBD_CONNECT_JOIN |
190 OBD_CONNECT_ATTRFID | OBD_CONNECT_VERSION |
191 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA;
192 data->ocd_ibits_known = MDS_INODELOCK_FULL;
193 data->ocd_version = LUSTRE_VERSION_CODE;
195 if (sb->s_flags & MS_RDONLY)
196 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
197 if (sbi->ll_flags & LL_SBI_USER_XATTR)
198 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
200 if (sbi->ll_flags & LL_SBI_FLOCK)
201 sbi->ll_fop = &ll_file_operations_flock;
203 sbi->ll_fop = &ll_file_operations;
206 data->ocd_connect_flags |= OBD_CONNECT_REAL;
207 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
208 data->ocd_connect_flags &= ~OBD_CONNECT_LCL_CLIENT;
209 data->ocd_connect_flags |= OBD_CONNECT_RMT_CLIENT;
210 data->ocd_nllu = nllu;
211 data->ocd_nllg = nllg;
213 data->ocd_connect_flags &= ~OBD_CONNECT_RMT_CLIENT;
214 data->ocd_connect_flags |= OBD_CONNECT_LCL_CLIENT;
217 err = obd_connect(NULL, &md_conn, obd, &sbi->ll_sb_uuid, data);
219 LCONSOLE_ERROR("An MDT (md %s) is performing recovery, of "
220 "which this client is not a part. Please wait "
221 "for recovery to complete, abort, or "
225 CERROR("cannot connect to %s: rc = %d\n", md, err);
228 sbi->ll_md_exp = class_conn2export(&md_conn);
230 err = obd_statfs(obd, &osfs, cfs_time_current_64() - HZ);
234 size = sizeof(*data);
235 err = obd_get_info(sbi->ll_md_exp, strlen(KEY_CONN_DATA), KEY_CONN_DATA,
238 CERROR("Get connect data failed: %d \n", err);
242 LASSERT(osfs.os_bsize);
243 sb->s_blocksize = osfs.os_bsize;
244 sb->s_blocksize_bits = log2(osfs.os_bsize);
245 sb->s_magic = LL_SUPER_MAGIC;
246 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
247 sbi->ll_namelen = osfs.os_namelen;
248 sbi->ll_max_rw_chunk = LL_DEFAULT_MAX_RW_CHUNK;
250 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
251 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
252 LCONSOLE_INFO("Disabling user_xattr feature because "
253 "it is not supported on the server\n");
254 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
257 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
259 sb->s_flags |= MS_POSIXACL;
261 sbi->ll_flags |= LL_SBI_ACL;
262 } else if (sbi->ll_flags & LL_SBI_ACL) {
263 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
264 sbi->ll_flags &= ~LL_SBI_ACL;
267 if (data->ocd_connect_flags & OBD_CONNECT_JOIN)
268 sbi->ll_flags |= LL_SBI_JOIN;
270 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
271 if (!(data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT)) {
272 /* sometimes local client claims to be remote, but mdt
273 * will disagree when client gss not applied. */
274 LCONSOLE_INFO("client claims to be remote, but server "
275 "rejected, forced to be local.\n");
276 sbi->ll_flags &= ~LL_SBI_RMT_CLIENT;
279 if (!(data->ocd_connect_flags & OBD_CONNECT_LCL_CLIENT)) {
280 /* with gss applied, remote client can not claim to be
281 * local, so mdt maybe force client to be remote. */
282 LCONSOLE_INFO("client claims to be local, but server "
283 "rejected, forced to be remote.\n");
284 sbi->ll_flags |= LL_SBI_RMT_CLIENT;
288 if (data->ocd_connect_flags & OBD_CONNECT_MDS_CAPA) {
289 LCONSOLE_INFO("client enabled MDS capability!\n");
290 sbi->ll_flags |= LL_SBI_MDS_CAPA;
293 if (data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA) {
294 LCONSOLE_INFO("client enabled OSS capability!\n");
295 sbi->ll_flags |= LL_SBI_OSS_CAPA;
298 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
299 /* We set sb->s_dev equal on all lustre clients in order to support
300 * NFS export clustering. NFSD requires that the FSID be the same
302 /* s_dev is also used in lt_compare() to compare two fs, but that is
303 * only a node-local comparison. */
305 /* XXX: this will not work with LMV */
306 sb->s_dev = get_uuid2int(sbi2mdc(sbi)->cl_target_uuid.uuid,
307 strlen(sbi2mdc(sbi)->cl_target_uuid.uuid));
310 /* init FIDs framework */
311 err = ll_fid_md_init(sbi);
313 CERROR("can't init FIDs framework, rc %d\n", err);
317 obd = class_name2obd(dt);
319 CERROR("DT %s: not setup or attached\n", dt);
320 GOTO(out_md_fid, err = -ENODEV);
323 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
324 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE;
325 if (sbi->ll_flags & LL_SBI_OSS_CAPA)
326 data->ocd_connect_flags |= OBD_CONNECT_OSS_CAPA;
328 CDEBUG(D_RPCTRACE, "ocd_connect_flags: "LPX64" ocd_version: %d "
329 "ocd_grant: %d\n", data->ocd_connect_flags,
330 data->ocd_version, data->ocd_grant);
332 obd->obd_upcall.onu_owner = &sbi->ll_lco;
333 obd->obd_upcall.onu_upcall = ll_ocd_update;
334 data->ocd_brw_size = PTLRPC_MAX_BRW_PAGES << PAGE_SHIFT;
336 err = obd_connect(NULL, &dt_conn, obd, &sbi->ll_sb_uuid, data);
338 LCONSOLE_ERROR("An OST (dt %s) is performing recovery, of which this"
339 " client is not a part. Please wait for recovery to "
340 "complete, abort, or time out.\n", dt);
343 CERROR("cannot connect to %s: rc = %d\n", dt, err);
347 sbi->ll_dt_exp = class_conn2export(&dt_conn);
349 spin_lock(&sbi->ll_lco.lco_lock);
350 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
351 spin_unlock(&sbi->ll_lco.lco_lock);
353 ll_init_ea_size(sbi->ll_md_exp, sbi->ll_dt_exp);
355 err = obd_prep_async_page(sbi->ll_dt_exp, NULL, NULL, NULL,
356 0, NULL, NULL, NULL);
358 LCONSOLE_ERROR("There are no OST's in this filesystem. "
359 "There must be at least one active OST for "
360 "a client to start.\n");
364 if (!ll_async_page_slab) {
365 ll_async_page_slab_size =
366 size_round(sizeof(struct ll_async_page)) + err;
367 ll_async_page_slab = kmem_cache_create("ll_async_page",
368 ll_async_page_slab_size,
370 if (!ll_async_page_slab)
371 GOTO(out_dt, -ENOMEM);
374 /* init FIDs framework */
375 err = ll_fid_dt_init(sbi);
377 CERROR("can't init FIDs framework, rc %d\n", err);
381 err = md_getstatus(sbi->ll_md_exp, &rootfid, &oc);
383 CERROR("cannot mds_connect: rc = %d\n", err);
384 GOTO(out_dt_fid, err);
386 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&rootfid));
387 sbi->ll_root_fid = rootfid;
389 sb->s_op = &lustre_super_operations;
390 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
391 sb->s_export_op = &lustre_export_operations;
395 * XXX: move this to after cbd setup? */
396 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMDSCAPA;
397 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
398 valid |= OBD_MD_FLRMTPERM;
399 else if (sbi->ll_flags & LL_SBI_ACL)
400 valid |= OBD_MD_FLACL;
402 err = md_getattr(sbi->ll_md_exp, &rootfid, oc, valid, 0, &request);
406 CERROR("md_getattr failed for root: rc = %d\n", err);
410 err = md_get_lustre_md(sbi->ll_md_exp, request,
411 REPLY_REC_OFF, sbi->ll_dt_exp, sbi->ll_md_exp,
414 CERROR("failed to understand root inode md: rc = %d\n", err);
415 ptlrpc_req_finished (request);
420 obd_capa_set_root(lmd.mds_capa);
421 LASSERT(fid_is_sane(&sbi->ll_root_fid));
422 root = ll_iget(sb, ll_fid_build_ino(sbi, &sbi->ll_root_fid), &lmd);
423 ptlrpc_req_finished(request);
425 if (root == NULL || is_bad_inode(root)) {
426 md_free_lustre_md(sbi->ll_dt_exp, &lmd);
427 CERROR("lustre_lite: bad iget4 for root\n");
428 GOTO(out_root, err = -EBADF);
431 err = ll_close_thread_start(&sbi->ll_lcq);
433 CERROR("cannot start close thread: rc %d\n", err);
437 /* making vm readahead 0 for 2.4.x. In the case of 2.6.x,
438 backing dev info assigned to inode mapping is used for
439 determining maximal readahead. */
440 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) && \
441 !defined(KERNEL_HAS_AS_MAX_READAHEAD)
442 /* bug 2805 - set VM readahead to zero */
443 vm_max_readahead = vm_min_readahead = 0;
446 sb->s_root = d_alloc_root(root);
448 OBD_FREE(data, sizeof(*data));
449 sb->s_root->d_op = &ll_d_root_ops;
456 obd_fid_fini(sbi->ll_dt_exp);
458 obd_disconnect(sbi->ll_dt_exp);
459 sbi->ll_dt_exp = NULL;
461 obd_fid_fini(sbi->ll_md_exp);
463 obd_disconnect(sbi->ll_md_exp);
464 sbi->ll_md_exp = NULL;
468 lprocfs_unregister_mountpoint(sbi);
472 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
476 *lmmsize = obd_size_diskmd(sbi->ll_dt_exp, NULL);
478 rc = obd_get_info(sbi->ll_md_exp, strlen("max_easize"), "max_easize",
481 CERROR("Get max mdsize error rc %d \n", rc);
486 void ll_dump_inode(struct inode *inode)
488 struct list_head *tmp;
489 int dentry_count = 0;
491 LASSERT(inode != NULL);
493 list_for_each(tmp, &inode->i_dentry)
496 CERROR("inode %p dump: dev=%s ino=%lu mode=%o count=%u, %d dentries\n",
497 inode, ll_i2mdexp(inode)->exp_obd->obd_name, inode->i_ino,
498 inode->i_mode, atomic_read(&inode->i_count), dentry_count);
501 void lustre_dump_dentry(struct dentry *dentry, int recur)
503 struct list_head *tmp;
506 LASSERT(dentry != NULL);
508 list_for_each(tmp, &dentry->d_subdirs)
511 CERROR("dentry %p dump: name=%.*s parent=%.*s (%p), inode=%p, count=%u,"
512 " flags=0x%x, fsdata=%p, %d subdirs\n", dentry,
513 dentry->d_name.len, dentry->d_name.name,
514 dentry->d_parent->d_name.len, dentry->d_parent->d_name.name,
515 dentry->d_parent, dentry->d_inode, atomic_read(&dentry->d_count),
516 dentry->d_flags, dentry->d_fsdata, subdirs);
517 if (dentry->d_inode != NULL)
518 ll_dump_inode(dentry->d_inode);
523 list_for_each(tmp, &dentry->d_subdirs) {
524 struct dentry *d = list_entry(tmp, struct dentry, d_child);
525 lustre_dump_dentry(d, recur - 1);
529 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
530 void lustre_throw_orphan_dentries(struct super_block *sb)
532 struct dentry *dentry, *next;
533 struct ll_sb_info *sbi = ll_s2sbi(sb);
535 /* Do this to get rid of orphaned dentries. That is not really trw. */
536 list_for_each_entry_safe(dentry, next, &sbi->ll_orphan_dentry_list,
538 CWARN("found orphan dentry %.*s (%p->%p) at unmount, dumping "
539 "before and after shrink_dcache_parent\n",
540 dentry->d_name.len, dentry->d_name.name, dentry, next);
541 lustre_dump_dentry(dentry, 1);
542 shrink_dcache_parent(dentry);
543 lustre_dump_dentry(dentry, 1);
547 #define lustre_throw_orphan_dentries(sb)
550 static void prune_dir_dentries(struct inode *inode)
552 struct dentry *dentry, *prev = NULL;
554 /* due to lustre specific logic, a directory
555 * can have few dentries - a bug from VFS POV */
557 spin_lock(&dcache_lock);
558 if (!list_empty(&inode->i_dentry)) {
559 dentry = list_entry(inode->i_dentry.prev,
560 struct dentry, d_alias);
561 /* in order to prevent infinite loops we
562 * break if previous dentry is busy */
563 if (dentry != prev) {
566 spin_unlock(&dcache_lock);
568 /* try to kill all child dentries */
570 shrink_dcache_parent(dentry);
571 unlock_dentry(dentry);
574 /* now try to get rid of current dentry */
575 d_prune_aliases(inode);
579 spin_unlock(&dcache_lock);
582 static void prune_deathrow_one(struct ll_inode_info *lli)
584 struct inode *inode = ll_info2i(lli);
586 /* first, try to drop any dentries - they hold a ref on the inode */
587 if (S_ISDIR(inode->i_mode))
588 prune_dir_dentries(inode);
590 d_prune_aliases(inode);
593 /* if somebody still uses it, leave it */
594 LASSERT(atomic_read(&inode->i_count) > 0);
595 if (atomic_read(&inode->i_count) > 1)
598 CDEBUG(D_INODE, "inode %lu/%u(%d) looks a good candidate for prune\n",
599 inode->i_ino,inode->i_generation, atomic_read(&inode->i_count));
601 /* seems nobody uses it anymore */
609 static void prune_deathrow(struct ll_sb_info *sbi, int try)
611 struct ll_inode_info *lli;
615 if (need_resched() && try)
619 if (!spin_trylock(&sbi->ll_deathrow_lock))
622 spin_lock(&sbi->ll_deathrow_lock);
627 if (!list_empty(&sbi->ll_deathrow)) {
628 lli = list_entry(sbi->ll_deathrow.next,
629 struct ll_inode_info,
631 list_del_init(&lli->lli_dead_list);
632 if (!list_empty(&sbi->ll_deathrow))
635 spin_unlock(&sbi->ll_deathrow_lock);
638 prune_deathrow_one(lli);
640 } while (empty == 0);
643 void client_common_put_super(struct super_block *sb)
645 struct ll_sb_info *sbi = ll_s2sbi(sb);
648 ll_close_thread_shutdown(sbi->ll_lcq);
650 /* destroy inodes in deathrow */
651 prune_deathrow(sbi, 0);
653 list_del(&sbi->ll_conn_chain);
655 obd_disconnect(sbi->ll_dt_exp);
656 sbi->ll_dt_exp = NULL;
658 lprocfs_unregister_mountpoint(sbi);
661 obd_disconnect(sbi->ll_md_exp);
662 sbi->ll_md_exp = NULL;
664 lustre_throw_orphan_dentries(sb);
668 char *ll_read_opt(const char *opt, char *data)
674 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
675 if (strncmp(opt, data, strlen(opt)))
677 if ((value = strchr(data, '=')) == NULL)
681 OBD_ALLOC(retval, strlen(value) + 1);
683 CERROR("out of memory!\n");
687 memcpy(retval, value, strlen(value)+1);
688 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
692 static inline int ll_set_opt(const char *opt, char *data, int fl)
694 if (strncmp(opt, data, strlen(opt)) != 0)
700 /* non-client-specific mount options are parsed in lmd_parse */
701 static int ll_options(char *options, int *flags)
704 char *s1 = options, *s2;
710 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
713 CDEBUG(D_SUPER, "next opt=%s\n", s1);
714 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
719 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
724 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK);
729 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
734 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
739 tmp = ll_set_opt("acl", s1, LL_SBI_ACL);
741 /* Ignore deprecated mount option. The client will
742 * always try to mount with ACL support, whether this
743 * is used depends on whether server supports it. */
746 tmp = ll_set_opt("noacl", s1, LL_SBI_ACL);
750 tmp = ll_set_opt("remote_client", s1, LL_SBI_RMT_CLIENT);
756 LCONSOLE_ERROR("Unknown option '%s', won't mount.\n", s1);
761 s2 = strchr(s1, ',');
769 void ll_lli_init(struct ll_inode_info *lli)
771 sema_init(&lli->lli_open_sem, 1);
772 sema_init(&lli->lli_size_sem, 1);
773 sema_init(&lli->lli_write_sem, 1);
775 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
776 spin_lock_init(&lli->lli_lock);
777 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
778 INIT_LIST_HEAD(&lli->lli_close_list);
779 lli->lli_inode_magic = LLI_INODE_MAGIC;
780 sema_init(&lli->lli_och_sem, 1);
781 lli->lli_mds_read_och = lli->lli_mds_write_och = NULL;
782 lli->lli_mds_exec_och = NULL;
783 lli->lli_open_fd_read_count = lli->lli_open_fd_write_count = 0;
784 lli->lli_open_fd_exec_count = 0;
785 INIT_LIST_HEAD(&lli->lli_dead_list);
786 INIT_LIST_HEAD(&lli->lli_oss_capas);
787 lli->lli_remote_perms = NULL;
788 sema_init(&lli->lli_rmtperm_sem, 1);
792 #define MDCDEV "mdc_dev"
793 static int old_lustre_process_log(struct super_block *sb, char *newprofile,
794 struct config_llog_instance *cfg)
796 struct lustre_sb_info *lsi = s2lsi(sb);
797 struct obd_device *obd;
798 struct lustre_handle mdc_conn = {0, };
799 struct obd_export *exp;
800 char *ptr, *mdt, *profile;
801 char niduuid[10] = "mdtnid0";
803 struct obd_uuid mdc_uuid;
804 struct llog_ctxt *ctxt;
805 struct obd_connect_data ocd = { 0 };
807 int i, rc = 0, recov_bk = 1, failnodes = 0;
810 class_generate_random_uuid(uuid);
811 class_uuid_unparse(uuid, &mdc_uuid);
812 CDEBUG(D_HA, "generated uuid: %s\n", mdc_uuid.uuid);
814 /* Figure out the old mdt and profile name from new-style profile
815 ("lustre" from "mds/lustre-client") */
817 profile = strchr(mdt, '/');
818 if (profile == NULL) {
819 CDEBUG(D_CONFIG, "Can't find MDT name in %s\n", newprofile);
820 GOTO(out, rc = -EINVAL);
824 ptr = strrchr(profile, '-');
826 CDEBUG(D_CONFIG, "Can't find client name in %s\n", newprofile);
827 GOTO(out, rc = -EINVAL);
831 LCONSOLE_WARN("This looks like an old mount command; I will try to "
832 "contact MDT '%s' for profile '%s'\n", mdt, profile);
834 /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
836 ptr = lsi->lsi_lmd->lmd_dev;
837 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
838 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid, 0,0,0);
840 /* Stop at the first failover nid */
845 CERROR("No valid MDT nids found.\n");
846 GOTO(out, rc = -EINVAL);
850 rc = do_lcfg(MDCDEV, 0, LCFG_ATTACH, LUSTRE_MDC_NAME, mdc_uuid.uuid, 0, 0);
852 GOTO(out_del_uuid, rc);
854 rc = do_lcfg(MDCDEV, 0, LCFG_SETUP, mdt, niduuid, 0, 0);
856 LCONSOLE_ERROR("I couldn't establish a connection with the MDT."
857 " Check that the MDT host NID is correct and the"
858 " networks are up.\n");
859 GOTO(out_detach, rc);
862 obd = class_name2obd(MDCDEV);
864 GOTO(out_cleanup, rc = -EINVAL);
866 /* Add any failover nids */
867 while (*ptr == ':') {
868 /* New failover node */
869 sprintf(niduuid, "mdtnid%d", failnodes);
871 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
873 rc = do_lcfg(MDCDEV, nid, LCFG_ADD_UUID, niduuid,0,0,0);
875 CERROR("Add uuid for %s failed %d\n",
876 libcfs_nid2str(nid), rc);
881 rc = do_lcfg(MDCDEV, 0, LCFG_ADD_CONN, niduuid, 0, 0,0);
883 CERROR("Add conn for %s failed %d\n",
884 libcfs_nid2str(nid), rc);
892 /* Try all connections, but only once. */
893 rc = obd_set_info_async(obd->obd_self_export,
894 strlen("init_recov_bk"), "init_recov_bk",
895 sizeof(recov_bk), &recov_bk, NULL);
897 GOTO(out_cleanup, rc);
899 /* If we don't have this then an ACL MDS will refuse the connection */
900 ocd.ocd_connect_flags = OBD_CONNECT_ACL;
902 rc = obd_connect(NULL, &mdc_conn, obd, &mdc_uuid, &ocd);
904 CERROR("cannot connect to %s: rc = %d\n", mdt, rc);
905 GOTO(out_cleanup, rc);
908 exp = class_conn2export(&mdc_conn);
910 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
912 cfg->cfg_flags |= CFG_F_COMPAT146;
915 rc = class_config_parse_llog(ctxt, profile, cfg);
918 * For debugging, it's useful to just dump the log
920 rc = class_config_dump_llog(ctxt, profile, cfg);
924 /* Set the caller's profile name to the old-style */
925 memcpy(newprofile, profile, strlen(profile) + 1);
929 LCONSOLE_ERROR("%s: The configuration '%s' could not be read "
930 "from the MDT '%s'. Make sure this client and "
931 "the MDT are running compatible versions of "
933 obd->obd_name, profile, mdt);
936 LCONSOLE_ERROR("%s: The configuration '%s' could not be read "
937 "from the MDT '%s'. This may be the result of "
938 "communication errors between the client and "
939 "the MDT, or if the MDT is not running.\n",
940 obd->obd_name, profile, mdt);
944 /* We don't so much care about errors in cleaning up the config llog
945 * connection, as we have already read the config by this point. */
949 do_lcfg(MDCDEV, 0, LCFG_CLEANUP, 0, 0, 0, 0);
952 do_lcfg(MDCDEV, 0, LCFG_DETACH, 0, 0, 0, 0);
955 /* class_add_uuid adds a nid even if the same uuid exists; we might
956 delete any copy here. So they all better match. */
957 for (i = 0; i < failnodes; i++) {
958 sprintf(niduuid, "mdtnid%d", i);
959 do_lcfg(MDCDEV, 0, LCFG_DEL_UUID, niduuid, 0, 0, 0);
961 /* class_import_put will get rid of the additional connections */
967 int ll_fill_super(struct super_block *sb)
969 struct lustre_profile *lprof;
970 struct lustre_sb_info *lsi = s2lsi(sb);
971 struct ll_sb_info *sbi;
972 char *dt = NULL, *md = NULL;
973 char *profilenm = get_profile_name(sb);
974 struct config_llog_instance cfg;
975 char ll_instance[sizeof(sb) * 2 + 1];
979 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
983 /* client additional sb info */
984 lsi->lsi_llsbi = sbi = ll_init_sbi();
990 err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
994 /* Generate a string unique to this super, in case some joker tries
995 to mount the same fs at two mount points.
996 Use the address of the super itself.*/
997 sprintf(ll_instance, "%p", sb);
998 cfg.cfg_instance = ll_instance;
999 cfg.cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1000 cfg.cfg_last_idx = 0;
1002 /* set up client obds */
1003 err = lustre_process_log(sb, profilenm, &cfg);
1008 oldnamelen = strlen(profilenm) + 1;
1009 /* Temp storage for 1.4.6 profile name */
1010 OBD_ALLOC(oldname, oldnamelen);
1012 memcpy(oldname, profilenm, oldnamelen);
1013 rc = old_lustre_process_log(sb, oldname, &cfg);
1015 /* That worked - update the profile name
1018 OBD_FREE(lsi->lsi_lmd->lmd_profile,
1019 strlen(lsi->lsi_lmd->lmd_profile) + 1);
1020 OBD_ALLOC(lsi->lsi_lmd->lmd_profile,
1021 strlen(oldname) + 1);
1022 if (!lsi->lsi_lmd->lmd_profile) {
1023 OBD_FREE(oldname, oldnamelen);
1024 GOTO(out_free, err = -ENOMEM);
1026 memcpy(lsi->lsi_lmd->lmd_profile, oldname,
1027 strlen(oldname) + 1);
1028 profilenm = get_profile_name(sb);
1030 OBD_FREE(oldname, oldnamelen);
1033 /* end COMPAT_146 */
1035 CERROR("Unable to process log: %d\n", err);
1036 GOTO(out_free, err);
1039 lprof = class_get_profile(profilenm);
1040 if (lprof == NULL) {
1041 LCONSOLE_ERROR("The client profile '%s' could not be read "
1042 "from the MGS. Does that filesystem exist?\n",
1044 GOTO(out_free, err = -EINVAL);
1046 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1047 lprof->lp_md, lprof->lp_dt);
1049 OBD_ALLOC(dt, strlen(lprof->lp_dt) +
1050 strlen(ll_instance) + 2);
1052 GOTO(out_free, err = -ENOMEM);
1053 sprintf(dt, "%s-%s", lprof->lp_dt, ll_instance);
1055 OBD_ALLOC(md, strlen(lprof->lp_md) +
1056 strlen(ll_instance) + 2);
1058 GOTO(out_free, err = -ENOMEM);
1059 sprintf(md, "%s-%s", lprof->lp_md, ll_instance);
1061 /* connections, registrations, sb setup */
1062 err = client_common_fill_super(sb, md, dt,
1063 lsi->lsi_lmd->lmd_nllu,
1064 lsi->lsi_lmd->lmd_nllg);
1068 OBD_FREE(md, strlen(md) + 1);
1070 OBD_FREE(dt, strlen(dt) + 1);
1074 } /* ll_fill_super */
1077 void ll_put_super(struct super_block *sb)
1079 struct config_llog_instance cfg;
1080 char ll_instance[sizeof(sb) * 2 + 1];
1081 struct obd_device *obd;
1082 struct lustre_sb_info *lsi = s2lsi(sb);
1083 struct ll_sb_info *sbi = ll_s2sbi(sb);
1084 char *profilenm = get_profile_name(sb);
1085 int force = 1, next;
1088 CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
1090 sprintf(ll_instance, "%p", sb);
1091 cfg.cfg_instance = ll_instance;
1092 lustre_end_log(sb, NULL, &cfg);
1094 if (sbi->ll_md_exp) {
1095 obd = class_exp2obd(sbi->ll_md_exp);
1097 force = obd->obd_no_recov;
1100 /* We need to set force before the lov_disconnect in
1101 lustre_common_put_super, since l_d cleans up osc's as well. */
1104 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1106 obd->obd_force = force;
1111 /* Only if client_common_fill_super succeeded */
1112 client_common_put_super(sb);
1115 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) !=NULL) {
1116 class_manual_cleanup(obd);
1120 class_del_profile(profilenm);
1123 lsi->lsi_llsbi = NULL;
1125 lustre_common_put_super(sb);
1127 LCONSOLE_WARN("client %s umount complete\n", ll_instance);
1132 } /* client_put_super */
1134 #ifdef HAVE_REGISTER_CACHE
1135 #include <linux/cache_def.h>
1136 #ifdef HAVE_CACHE_RETURN_INT
1141 ll_shrink_cache(int priority, unsigned int gfp_mask)
1143 struct ll_sb_info *sbi;
1146 list_for_each_entry(sbi, &ll_super_blocks, ll_list)
1147 count += llap_shrink_cache(sbi, priority);
1149 #ifdef HAVE_CACHE_RETURN_INT
1154 struct cache_definition ll_cache_definition = {
1155 .name = "llap_cache",
1156 .shrink = ll_shrink_cache
1158 #endif /* HAVE_REGISTER_CACHE */
1160 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
1162 struct inode *inode = NULL;
1163 /* NOTE: we depend on atomic igrab() -bzzz */
1164 lock_res_and_lock(lock);
1165 if (lock->l_ast_data) {
1166 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
1167 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1168 inode = igrab(lock->l_ast_data);
1170 inode = lock->l_ast_data;
1171 ldlm_lock_debug(NULL, inode->i_state & I_FREEING ?
1173 lock, __FILE__, __func__, __LINE__,
1174 "l_ast_data %p is bogus: magic %08x",
1175 lock->l_ast_data, lli->lli_inode_magic);
1179 unlock_res_and_lock(lock);
1183 static int null_if_equal(struct ldlm_lock *lock, void *data)
1185 if (data == lock->l_ast_data) {
1186 lock->l_ast_data = NULL;
1188 if (lock->l_req_mode != lock->l_granted_mode)
1189 LDLM_ERROR(lock,"clearing inode with ungranted lock");
1192 return LDLM_ITER_CONTINUE;
1195 void ll_clear_inode(struct inode *inode)
1197 struct ll_inode_info *lli = ll_i2info(inode);
1198 struct ll_sb_info *sbi = ll_i2sbi(inode);
1201 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1202 inode->i_generation, inode);
1204 ll_i2info(inode)->lli_flags &= ~LLIF_MDS_SIZE_LOCK;
1205 md_change_cbdata(sbi->ll_md_exp, ll_inode2fid(inode),
1206 null_if_equal, inode);
1208 LASSERT(!lli->lli_open_fd_write_count);
1209 LASSERT(!lli->lli_open_fd_read_count);
1210 LASSERT(!lli->lli_open_fd_exec_count);
1212 if (lli->lli_mds_write_och)
1213 ll_md_real_close(inode, FMODE_WRITE);
1214 if (lli->lli_mds_exec_och) {
1216 CERROR("No FMODE exec, bug exec och is present for "
1217 "inode %ld\n", inode->i_ino);
1218 ll_md_real_close(inode, FMODE_EXEC);
1220 if (lli->lli_mds_read_och)
1221 ll_md_real_close(inode, FMODE_READ);
1224 obd_change_cbdata(sbi->ll_dt_exp, lli->lli_smd,
1225 null_if_equal, inode);
1227 obd_free_memmd(sbi->ll_dt_exp, &lli->lli_smd);
1228 lli->lli_smd = NULL;
1231 if (lli->lli_symlink_name) {
1232 OBD_FREE(lli->lli_symlink_name,
1233 strlen(lli->lli_symlink_name) + 1);
1234 lli->lli_symlink_name = NULL;
1237 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
1238 LASSERT(lli->lli_posix_acl == NULL);
1239 if (lli->lli_remote_perms) {
1240 free_rmtperm_hash(lli->lli_remote_perms);
1241 lli->lli_remote_perms = NULL;
1244 #ifdef CONFIG_FS_POSIX_ACL
1245 else if (lli->lli_posix_acl) {
1246 LASSERT(atomic_read(&lli->lli_posix_acl->a_refcount) == 1);
1247 LASSERT(lli->lli_remote_perms == NULL);
1248 posix_acl_release(lli->lli_posix_acl);
1249 lli->lli_posix_acl = NULL;
1252 lli->lli_inode_magic = LLI_INODE_DEAD;
1254 spin_lock(&sbi->ll_deathrow_lock);
1255 list_del_init(&lli->lli_dead_list);
1256 spin_unlock(&sbi->ll_deathrow_lock);
1258 ll_clear_inode_capas(inode);
1263 int ll_md_setattr(struct inode *inode, struct md_op_data *op_data)
1265 struct lustre_md md;
1266 struct ll_sb_info *sbi = ll_i2sbi(inode);
1267 struct ptlrpc_request *request = NULL;
1271 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0);
1272 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, NULL, 0, &request);
1274 ptlrpc_req_finished(request);
1275 if (rc == -ENOENT) {
1277 /* Unlinked special device node? Or just a race?
1278 * Pretend we done everything. */
1279 if (!S_ISREG(inode->i_mode) &&
1280 !S_ISDIR(inode->i_mode))
1281 rc = inode_setattr(inode, &op_data->attr);
1282 } else if (rc != -EPERM && rc != -EACCES) {
1283 CERROR("md_setattr fails: rc = %d\n", rc);
1288 rc = md_get_lustre_md(sbi->ll_md_exp, request, REPLY_REC_OFF,
1289 sbi->ll_dt_exp, sbi->ll_md_exp, &md);
1291 ptlrpc_req_finished(request);
1295 /* We call inode_setattr to adjust timestamps.
1296 * If there is at least some data in file, we cleared ATTR_SIZE
1297 * above to avoid invoking vmtruncate, otherwise it is important
1298 * to call vmtruncate in inode_setattr to update inode->i_size
1300 rc = inode_setattr(inode, &op_data->attr);
1302 /* Extract epoch data if obtained. */
1303 memcpy(&op_data->handle, &md.body->handle, sizeof(op_data->handle));
1304 op_data->ioepoch = md.body->ioepoch;
1306 ll_update_inode(inode, &md);
1307 ptlrpc_req_finished(request);
1312 /* Close IO epoch and send Size-on-MDS attribute update. */
1313 static int ll_setattr_done_writing(struct inode *inode,
1314 struct md_op_data *op_data)
1316 struct ll_inode_info *lli = ll_i2info(inode);
1320 LASSERT(op_data != NULL);
1321 if (!S_ISREG(inode->i_mode))
1324 CDEBUG(D_INODE, "Epoch "LPU64" closed on "DFID" for truncate\n",
1325 op_data->ioepoch, PFID(&lli->lli_fid));
1327 op_data->flags = MF_EPOCH_CLOSE | MF_SOM_CHANGE;
1328 /* XXX: pass och here for the recovery purpose. */
1329 rc = md_done_writing(ll_i2sbi(inode)->ll_md_exp, op_data, NULL);
1330 if (rc == -EAGAIN) {
1331 /* MDS has instructed us to obtain Size-on-MDS attribute
1332 * from OSTs and send setattr to back to MDS. */
1333 rc = ll_sizeonmds_update(inode, &op_data->handle);
1335 CERROR("inode %lu mdc truncate failed: rc = %d\n",
1341 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1342 * object(s) determine the file size and mtime. Otherwise, the MDS will
1343 * keep these values until such a time that objects are allocated for it.
1344 * We do the MDS operations first, as it is checking permissions for us.
1345 * We don't to the MDS RPC if there is nothing that we want to store there,
1346 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1347 * going to do an RPC anyways.
1349 * If we are doing a truncate, we will send the mtime and ctime updates
1350 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1351 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1354 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
1356 struct ll_inode_info *lli = ll_i2info(inode);
1357 struct lov_stripe_md *lsm = lli->lli_smd;
1358 struct ll_sb_info *sbi = ll_i2sbi(inode);
1359 struct md_op_data *op_data = NULL;
1360 int ia_valid = attr->ia_valid;
1361 int rc = 0, rc1 = 0;
1364 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu valid %x\n", inode->i_ino,
1366 lprocfs_counter_incr(sbi->ll_stats, LPROC_LL_SETATTR);
1368 if (ia_valid & ATTR_SIZE) {
1369 if (attr->ia_size > ll_file_maxbytes(inode)) {
1370 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
1371 attr->ia_size, ll_file_maxbytes(inode));
1375 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1378 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1379 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
1380 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1384 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1385 if (attr->ia_valid & ATTR_CTIME) {
1386 attr->ia_ctime = CURRENT_TIME;
1387 attr->ia_valid |= ATTR_CTIME_SET;
1389 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
1390 attr->ia_atime = CURRENT_TIME;
1391 attr->ia_valid |= ATTR_ATIME_SET;
1393 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
1394 attr->ia_mtime = CURRENT_TIME;
1395 attr->ia_valid |= ATTR_MTIME_SET;
1397 if ((attr->ia_valid & ATTR_CTIME) && !(attr->ia_valid & ATTR_MTIME)) {
1398 /* To avoid stale mtime on mds, obtain it from ost and send
1400 rc = ll_glimpse_size(inode, 0);
1404 attr->ia_valid |= ATTR_MTIME_SET | ATTR_MTIME;
1405 attr->ia_mtime = inode->i_mtime;
1408 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1409 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
1410 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1413 /* NB: ATTR_SIZE will only be set after this point if the size
1414 * resides on the MDS, ie, this file has no objects. */
1416 attr->ia_valid &= ~ATTR_SIZE;
1418 /* If only OST attributes being set on objects, don't do MDS RPC.
1419 * In that case, we need to check permissions and update the local
1420 * inode ourselves so we can call obdo_from_inode() always. */
1421 if (ia_valid & (lsm ? ~(ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
1422 OBD_ALLOC_PTR(op_data);
1423 if (op_data == NULL)
1426 memcpy(&op_data->attr, attr, sizeof(*attr));
1428 /* Open epoch for truncate. */
1429 if (ia_valid & ATTR_SIZE)
1430 op_data->flags = MF_EPOCH_OPEN;
1431 rc = ll_md_setattr(inode, op_data);
1435 CDEBUG(D_INODE, "Epoch "LPU64" opened on "DFID" for truncate\n",
1436 op_data->ioepoch, PFID(&lli->lli_fid));
1438 if (!lsm || !S_ISREG(inode->i_mode)) {
1439 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
1443 /* The OST doesn't check permissions, but the alternative is
1444 * a gratuitous RPC to the MDS. We already rely on the client
1445 * to do read/write/truncate permission checks, so is mtime OK?
1447 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
1448 /* from sys_utime() */
1449 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
1450 if (current->fsuid != inode->i_uid &&
1451 (rc=ll_permission(inode,MAY_WRITE,NULL))!=0)
1454 /* from inode_change_ok() */
1455 if (current->fsuid != inode->i_uid &&
1456 !capable(CAP_FOWNER))
1461 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
1462 rc = inode_setattr(inode, attr);
1465 /* We really need to get our PW lock before we change inode->i_size.
1466 * If we don't we can race with other i_size updaters on our node, like
1467 * ll_file_read. We can also race with i_size propogation to other
1468 * nodes through dirtying and writeback of final cached pages. This
1469 * last one is especially bad for racing o_append users on other
1471 if (ia_valid & ATTR_SIZE) {
1472 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
1474 struct lustre_handle lockh = { 0 };
1475 int err, ast_flags = 0;
1476 /* XXX when we fix the AST intents to pass the discard-range
1477 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
1479 if (attr->ia_size == 0)
1480 ast_flags = LDLM_AST_DISCARD_DATA;
1482 UNLOCK_INODE_MUTEX(inode);
1483 UP_WRITE_I_ALLOC_SEM(inode);
1484 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy, &lockh,
1486 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1487 DOWN_WRITE_I_ALLOC_SEM(inode);
1488 LOCK_INODE_MUTEX(inode);
1490 LOCK_INODE_MUTEX(inode);
1491 DOWN_WRITE_I_ALLOC_SEM(inode);
1496 /* Only ll_inode_size_lock is taken at this level.
1497 * lov_stripe_lock() is grabbed by ll_truncate() only over
1498 * call to obd_adjust_kms(). If vmtruncate returns 0, then
1499 * ll_truncate dropped ll_inode_size_lock() */
1500 ll_inode_size_lock(inode, 0);
1501 rc = vmtruncate(inode, attr->ia_size);
1503 LASSERT(atomic_read(&lli->lli_size_sem.count) <= 0);
1504 ll_inode_size_unlock(inode, 0);
1507 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
1509 CERROR("ll_extent_unlock failed: %d\n", err);
1513 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
1515 struct obd_info oinfo = { { { 0 } } };
1516 struct obdo *oa = obdo_alloc();
1518 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1519 inode->i_ino, LTIME_S(attr->ia_mtime));
1522 oa->o_id = lsm->lsm_object_id;
1523 oa->o_gr = lsm->lsm_object_gr;
1524 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1526 flags = OBD_MD_FLTYPE | OBD_MD_FLATIME |
1527 OBD_MD_FLMTIME | OBD_MD_FLCTIME |
1528 OBD_MD_FLFID | OBD_MD_FLGENER |
1531 obdo_from_inode(oa, inode, flags);
1536 /* XXX: this looks unnecessary now. */
1537 rc = obd_setattr_rqset(sbi->ll_dt_exp, &oinfo, NULL);
1539 CERROR("obd_setattr_async fails: rc=%d\n", rc);
1548 if (op_data->ioepoch) {
1549 rc1 = ll_setattr_done_writing(inode, op_data);
1551 ll_finish_md_op_data(op_data);
1553 return rc ? rc : rc1;
1556 int ll_setattr(struct dentry *de, struct iattr *attr)
1558 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1559 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1560 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1562 return ll_setattr_raw(de->d_inode, attr);
1565 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1568 struct ll_sb_info *sbi = ll_s2sbi(sb);
1569 struct obd_statfs obd_osfs;
1573 rc = obd_statfs(class_exp2obd(sbi->ll_md_exp), osfs, max_age);
1575 CERROR("md_statfs fails: rc = %d\n", rc);
1579 osfs->os_type = sb->s_magic;
1581 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1582 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1584 rc = obd_statfs_rqset(class_exp2obd(sbi->ll_dt_exp),
1585 &obd_osfs, max_age);
1587 CERROR("obd_statfs fails: rc = %d\n", rc);
1591 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1592 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1595 osfs->os_blocks = obd_osfs.os_blocks;
1596 osfs->os_bfree = obd_osfs.os_bfree;
1597 osfs->os_bavail = obd_osfs.os_bavail;
1599 /* If we don't have as many objects free on the OST as inodes
1600 * on the MDS, we reduce the total number of inodes to
1601 * compensate, so that the "inodes in use" number is correct.
1603 if (obd_osfs.os_ffree < osfs->os_ffree) {
1604 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1606 osfs->os_ffree = obd_osfs.os_ffree;
1612 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1614 struct obd_statfs osfs;
1617 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1618 lprocfs_counter_incr(ll_s2sbi(sb)->ll_stats, LPROC_LL_STAFS);
1620 /* For now we will always get up-to-date statfs values, but in the
1621 * future we may allow some amount of caching on the client (e.g.
1622 * from QOS or lprocfs updates). */
1623 rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - 1);
1627 statfs_unpack(sfs, &osfs);
1629 /* We need to downshift for all 32-bit kernels, because we can't
1630 * tell if the kernel is being called via sys_statfs64() or not.
1631 * Stop before overflowing f_bsize - in which case it is better
1632 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
1633 if (sizeof(long) < 8) {
1634 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1637 osfs.os_blocks >>= 1;
1638 osfs.os_bfree >>= 1;
1639 osfs.os_bavail >>= 1;
1643 sfs->f_blocks = osfs.os_blocks;
1644 sfs->f_bfree = osfs.os_bfree;
1645 sfs->f_bavail = osfs.os_bavail;
1650 void ll_inode_size_lock(struct inode *inode, int lock_lsm)
1652 struct ll_inode_info *lli;
1653 struct lov_stripe_md *lsm;
1655 lli = ll_i2info(inode);
1656 LASSERT(lli->lli_size_sem_owner != current);
1657 down(&lli->lli_size_sem);
1658 LASSERT(lli->lli_size_sem_owner == NULL);
1659 lli->lli_size_sem_owner = current;
1661 LASSERTF(lsm != NULL || lock_lsm == 0, "lsm %p, lock_lsm %d\n",
1664 lov_stripe_lock(lsm);
1667 void ll_inode_size_unlock(struct inode *inode, int unlock_lsm)
1669 struct ll_inode_info *lli;
1670 struct lov_stripe_md *lsm;
1672 lli = ll_i2info(inode);
1674 LASSERTF(lsm != NULL || unlock_lsm == 0, "lsm %p, lock_lsm %d\n",
1677 lov_stripe_unlock(lsm);
1678 LASSERT(lli->lli_size_sem_owner == current);
1679 lli->lli_size_sem_owner = NULL;
1680 up(&lli->lli_size_sem);
1683 static void ll_replace_lsm(struct inode *inode, struct lov_stripe_md *lsm)
1685 struct ll_inode_info *lli = ll_i2info(inode);
1687 dump_lsm(D_INODE, lsm);
1688 dump_lsm(D_INODE, lli->lli_smd);
1689 LASSERTF(lsm->lsm_magic == LOV_MAGIC_JOIN,
1690 "lsm must be joined lsm %p\n", lsm);
1691 obd_free_memmd(ll_i2dtexp(inode), &lli->lli_smd);
1692 CDEBUG(D_INODE, "replace lsm %p to lli_smd %p for inode %lu%u(%p)\n",
1693 lsm, lli->lli_smd, inode->i_ino, inode->i_generation, inode);
1695 lli->lli_maxbytes = lsm->lsm_maxbytes;
1696 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1697 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1700 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1702 struct ll_inode_info *lli = ll_i2info(inode);
1703 struct mdt_body *body = md->body;
1704 struct lov_stripe_md *lsm = md->lsm;
1705 struct ll_sb_info *sbi = ll_i2sbi(inode);
1707 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1709 if (lli->lli_smd == NULL) {
1710 if (lsm->lsm_magic != LOV_MAGIC &&
1711 lsm->lsm_magic != LOV_MAGIC_JOIN) {
1712 dump_lsm(D_ERROR, lsm);
1715 CDEBUG(D_INODE, "adding lsm %p to inode %lu/%u(%p)\n",
1716 lsm, inode->i_ino, inode->i_generation, inode);
1717 /* ll_inode_size_lock() requires it is only called
1718 * with lli_smd != NULL or lock_lsm == 0 or we can
1719 * race between lock/unlock. bug 9547 */
1721 lli->lli_maxbytes = lsm->lsm_maxbytes;
1722 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1723 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1725 if (lli->lli_smd->lsm_magic == lsm->lsm_magic &&
1726 lli->lli_smd->lsm_stripe_count ==
1727 lsm->lsm_stripe_count) {
1728 if (lov_stripe_md_cmp(lli->lli_smd, lsm)) {
1729 CERROR("lsm mismatch for inode %ld\n",
1731 CERROR("lli_smd:\n");
1732 dump_lsm(D_ERROR, lli->lli_smd);
1734 dump_lsm(D_ERROR, lsm);
1738 ll_replace_lsm(inode, lsm);
1740 if (lli->lli_smd != lsm)
1741 obd_free_memmd(ll_i2dtexp(inode), &lsm);
1744 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
1745 if (body->valid & OBD_MD_FLRMTPERM)
1746 ll_update_remote_perm(inode, md->remote_perm);
1748 #ifdef CONFIG_FS_POSIX_ACL
1749 else if (body->valid & OBD_MD_FLACL) {
1750 spin_lock(&lli->lli_lock);
1751 if (lli->lli_posix_acl)
1752 posix_acl_release(lli->lli_posix_acl);
1753 lli->lli_posix_acl = md->posix_acl;
1754 spin_unlock(&lli->lli_lock);
1757 if (body->valid & OBD_MD_FLATIME &&
1758 body->atime > LTIME_S(inode->i_atime))
1759 LTIME_S(inode->i_atime) = body->atime;
1761 /* mtime is always updated with ctime, but can be set in past.
1762 As write and utime(2) may happen within 1 second, and utime's
1763 mtime has a priority over write's one, so take mtime from mds
1764 for the same ctimes. */
1765 if (body->valid & OBD_MD_FLCTIME &&
1766 body->ctime >= LTIME_S(inode->i_ctime)) {
1767 LTIME_S(inode->i_ctime) = body->ctime;
1768 if (body->valid & OBD_MD_FLMTIME) {
1769 CDEBUG(D_INODE, "setting ino %lu mtime "
1770 "from %lu to "LPU64"\n", inode->i_ino,
1771 LTIME_S(inode->i_mtime), body->mtime);
1772 LTIME_S(inode->i_mtime) = body->mtime;
1775 if (body->valid & OBD_MD_FLMODE)
1776 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1777 if (body->valid & OBD_MD_FLTYPE)
1778 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1779 if (S_ISREG(inode->i_mode))
1780 inode->i_blksize = min(2UL*PTLRPC_MAX_BRW_SIZE, LL_MAX_BLKSIZE);
1782 inode->i_blksize = inode->i_sb->s_blocksize;
1783 if (body->valid & OBD_MD_FLUID)
1784 inode->i_uid = body->uid;
1785 if (body->valid & OBD_MD_FLGID)
1786 inode->i_gid = body->gid;
1787 if (body->valid & OBD_MD_FLFLAGS)
1788 inode->i_flags = ll_ext_to_inode_flags(body->flags);
1789 if (body->valid & OBD_MD_FLNLINK)
1790 inode->i_nlink = body->nlink;
1791 if (body->valid & OBD_MD_FLRDEV)
1792 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1793 inode->i_rdev = body->rdev;
1795 inode->i_rdev = old_decode_dev(body->rdev);
1797 if (body->valid & OBD_MD_FLSIZE) {
1798 inode->i_size = body->size;
1800 if (body->valid & OBD_MD_FLBLOCKS)
1801 inode->i_blocks = body->blocks;
1803 lli->lli_flags |= LLIF_MDS_SIZE_LOCK;
1806 if (body->valid & OBD_MD_FLID) {
1807 /* FID shouldn't be changed! */
1808 if (fid_is_sane(&lli->lli_fid)) {
1809 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->fid1),
1810 "Trying to change FID "DFID
1811 " to the "DFID", inode %lu/%u(%p)\n",
1812 PFID(&lli->lli_fid), PFID(&body->fid1),
1813 inode->i_ino, inode->i_generation, inode);
1815 lli->lli_fid = body->fid1;
1818 LASSERT(fid_seq(&lli->lli_fid) != 0);
1820 if (body->valid & OBD_MD_FLMDSCAPA) {
1821 LASSERT(md->mds_capa);
1822 ll_add_capa(inode, md->mds_capa);
1824 if (body->valid & OBD_MD_FLOSSCAPA) {
1825 LASSERT(md->oss_capa);
1826 ll_add_capa(inode, md->oss_capa);
1830 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
1831 static struct backing_dev_info ll_backing_dev_info = {
1832 .ra_pages = 0, /* No readahead */
1833 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12))
1834 .capabilities = 0, /* Does contribute to dirty memory */
1836 .memory_backed = 0, /* Does contribute to dirty memory */
1841 void ll_read_inode2(struct inode *inode, void *opaque)
1843 struct lustre_md *md = opaque;
1844 struct ll_inode_info *lli = ll_i2info(inode);
1847 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n",
1848 inode->i_ino, inode->i_generation, inode);
1852 LASSERT(!lli->lli_smd);
1854 /* Core attributes from the MDS first. This is a new inode, and
1855 * the VFS doesn't zero times in the core inode so we have to do
1856 * it ourselves. They will be overwritten by either MDS or OST
1857 * attributes - we just need to make sure they aren't newer. */
1858 LTIME_S(inode->i_mtime) = 0;
1859 LTIME_S(inode->i_atime) = 0;
1860 LTIME_S(inode->i_ctime) = 0;
1862 ll_update_inode(inode, md);
1864 /* OIDEBUG(inode); */
1866 if (S_ISREG(inode->i_mode)) {
1867 struct ll_sb_info *sbi = ll_i2sbi(inode);
1868 inode->i_op = &ll_file_inode_operations;
1869 inode->i_fop = sbi->ll_fop;
1870 inode->i_mapping->a_ops = &ll_aops;
1872 } else if (S_ISDIR(inode->i_mode)) {
1873 inode->i_op = &ll_dir_inode_operations;
1874 inode->i_fop = &ll_dir_operations;
1875 inode->i_mapping->a_ops = &ll_dir_aops;
1877 } else if (S_ISLNK(inode->i_mode)) {
1878 inode->i_op = &ll_fast_symlink_inode_operations;
1881 inode->i_op = &ll_special_inode_operations;
1883 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1884 init_special_inode(inode, inode->i_mode,
1885 kdev_t_to_nr(inode->i_rdev));
1887 /* initializing backing dev info. */
1888 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
1890 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1896 void ll_delete_inode(struct inode *inode)
1898 struct ll_sb_info *sbi = ll_i2sbi(inode);
1902 rc = obd_fid_delete(sbi->ll_md_exp, ll_inode2fid(inode));
1904 CERROR("fid_delete() failed, rc %d\n", rc);
1911 int ll_iocontrol(struct inode *inode, struct file *file,
1912 unsigned int cmd, unsigned long arg)
1914 struct ll_sb_info *sbi = ll_i2sbi(inode);
1915 struct ptlrpc_request *req = NULL;
1920 case EXT3_IOC_GETFLAGS: {
1921 struct mdt_body *body;
1922 struct obd_capa *oc;
1924 oc = ll_i2mdscapa(inode);
1925 rc = md_getattr(sbi->ll_md_exp, ll_inode2fid(inode), oc,
1926 OBD_MD_FLFLAGS, 0, &req);
1929 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1933 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1936 /*Now the ext3 will be packed directly back to client,
1937 *no need convert here*/
1938 flags = body->flags;
1940 ptlrpc_req_finished (req);
1942 RETURN(put_user(flags, (int *)arg));
1944 case EXT3_IOC_SETFLAGS: {
1945 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1946 struct obd_info oinfo = { { { 0 } } };
1947 struct md_op_data *op_data;
1949 if (get_user(flags, (int *)arg))
1953 oinfo.oi_oa = obdo_alloc();
1957 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0);
1958 if (op_data == NULL)
1961 ((struct ll_iattr *)&op_data->attr)->ia_attr_flags = flags;
1962 op_data->attr.ia_valid |= ATTR_ATTR_FLAG;
1963 rc = md_setattr(sbi->ll_md_exp, op_data,
1964 NULL, 0, NULL, 0, &req);
1965 ll_finish_md_op_data(op_data);
1966 ptlrpc_req_finished(req);
1967 if (rc || lsm == NULL) {
1968 obdo_free(oinfo.oi_oa);
1972 oinfo.oi_oa->o_id = lsm->lsm_object_id;
1973 oinfo.oi_oa->o_gr = lsm->lsm_object_gr;
1974 oinfo.oi_oa->o_flags = flags;
1975 oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS |
1978 obdo_from_inode(oinfo.oi_oa, inode,
1979 OBD_MD_FLFID | OBD_MD_FLGENER);
1980 rc = obd_setattr_rqset(sbi->ll_dt_exp, &oinfo, NULL);
1981 obdo_free(oinfo.oi_oa);
1983 if (rc != -EPERM && rc != -EACCES)
1984 CERROR("md_setattr_async fails: rc = %d\n", rc);
1988 inode->i_flags = ll_ext_to_inode_flags(flags |
1989 MDS_BFLAG_EXT_FLAGS);
1999 int ll_flush_ctx(struct inode *inode)
2001 struct ll_sb_info *sbi = ll_i2sbi(inode);
2003 CDEBUG(D_SEC, "flush context for user %d\n", current->uid);
2005 obd_set_info_async(sbi->ll_md_exp,
2006 sizeof(KEY_FLUSH_CTX) - 1, KEY_FLUSH_CTX,
2008 obd_set_info_async(sbi->ll_dt_exp,
2009 sizeof(KEY_FLUSH_CTX) - 1, KEY_FLUSH_CTX,
2014 /* umount -f client means force down, don't save state */
2015 void ll_umount_begin(struct super_block *sb)
2017 struct lustre_sb_info *lsi = s2lsi(sb);
2018 struct ll_sb_info *sbi = ll_s2sbi(sb);
2019 struct obd_device *obd;
2020 struct obd_ioctl_data ioc_data = { 0 };
2023 /* Tell the MGC we got umount -f */
2024 lsi->lsi_flags |= LSI_UMOUNT_FORCE;
2026 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2027 sb->s_count, atomic_read(&sb->s_active));
2029 obd = class_exp2obd(sbi->ll_md_exp);
2031 CERROR("Invalid MDC connection handle "LPX64"\n",
2032 sbi->ll_md_exp->exp_handle.h_cookie);
2036 obd->obd_no_recov = 1;
2037 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp, sizeof ioc_data,
2040 obd = class_exp2obd(sbi->ll_dt_exp);
2042 CERROR("Invalid LOV connection handle "LPX64"\n",
2043 sbi->ll_dt_exp->exp_handle.h_cookie);
2048 obd->obd_no_recov = 1;
2049 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp, sizeof ioc_data,
2052 /* Really, we'd like to wait until there are no requests outstanding,
2053 * and then continue. For now, we just invalidate the requests,
2054 * schedule, and hope.
2061 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2063 struct ll_sb_info *sbi = ll_s2sbi(sb);
2067 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
2068 read_only = *flags & MS_RDONLY;
2069 err = obd_set_info_async(sbi->ll_md_exp, strlen("read-only"),
2070 "read-only", sizeof(read_only),
2073 CERROR("Failed to change the read-only flag during "
2074 "remount: %d\n", err);
2079 sb->s_flags |= MS_RDONLY;
2081 sb->s_flags &= ~MS_RDONLY;
2086 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
2087 int offset, struct super_block *sb)
2089 struct ll_sb_info *sbi = NULL;
2090 struct lustre_md md;
2094 LASSERT(*inode || sb);
2095 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2096 prune_deathrow(sbi, 1);
2098 rc = md_get_lustre_md(sbi->ll_md_exp, req, offset,
2099 sbi->ll_dt_exp, sbi->ll_md_exp, &md);
2104 ll_update_inode(*inode, &md);
2106 LASSERT(sb != NULL);
2108 /* at this point server answers to client's RPC with same fid as
2109 * client generated for creating some inode. So using ->fid1 is
2111 LASSERT(fid_is_sane(&md.body->fid1));
2113 *inode = ll_iget(sb, ll_fid_build_ino(sbi, &md.body->fid1), &md);
2114 if (*inode == NULL || is_bad_inode(*inode)) {
2115 md_free_lustre_md(sbi->ll_dt_exp, &md);
2117 CERROR("new_inode -fatal: rc %d\n", rc);
2122 rc = obd_checkmd(sbi->ll_dt_exp, sbi->ll_md_exp,
2123 ll_i2info(*inode)->lli_smd);
2128 char *llap_origins[] = {
2129 [LLAP_ORIGIN_UNKNOWN] = "--",
2130 [LLAP_ORIGIN_READPAGE] = "rp",
2131 [LLAP_ORIGIN_READAHEAD] = "ra",
2132 [LLAP_ORIGIN_COMMIT_WRITE] = "cw",
2133 [LLAP_ORIGIN_WRITEPAGE] = "wp",
2136 struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
2137 struct list_head *list)
2139 struct ll_async_page *llap;
2140 struct list_head *pos;
2142 list_for_each(pos, list) {
2143 if (pos == &sbi->ll_pglist)
2145 llap = list_entry(pos, struct ll_async_page, llap_pglist_item);
2146 if (llap->llap_page == NULL)
2154 int ll_obd_statfs(struct inode *inode, void *arg)
2156 struct ll_sb_info *sbi = NULL;
2157 struct obd_device *client_obd = NULL, *lov_obd = NULL;
2158 struct lov_obd *lov = NULL;
2159 struct obd_statfs stat_buf = {0};
2161 struct obd_ioctl_data *data = NULL;
2165 if (!inode || !(sbi = ll_i2sbi(inode)))
2166 GOTO(out_statfs, rc = -EINVAL);
2168 rc = obd_ioctl_getdata(&buf, &len, arg);
2170 GOTO(out_statfs, rc);
2173 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2174 !data->ioc_pbuf1 || !data->ioc_pbuf2)
2175 GOTO(out_statfs, rc = -EINVAL);
2177 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2178 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
2180 if (type == LL_STATFS_MDC) {
2182 GOTO(out_statfs, rc = -ENODEV);
2183 client_obd = class_exp2obd(sbi->ll_md_exp);
2184 } else if (type == LL_STATFS_LOV) {
2185 lov_obd = class_exp2obd(sbi->ll_dt_exp);
2186 lov = &lov_obd->u.lov;
2188 if ((index >= lov->desc.ld_tgt_count) ||
2189 !lov->lov_tgts[index])
2190 GOTO(out_statfs, rc = -ENODEV);
2192 client_obd = class_exp2obd(lov->lov_tgts[index]->ltd_exp);
2193 if (!lov->lov_tgts[index]->ltd_active)
2194 GOTO(out_uuid, rc = -ENODATA);
2198 GOTO(out_statfs, rc = -EINVAL);
2200 rc = obd_statfs(client_obd, &stat_buf, cfs_time_current_64() - 1);
2202 GOTO(out_statfs, rc);
2204 if (copy_to_user(data->ioc_pbuf1, &stat_buf, data->ioc_plen1))
2205 GOTO(out_statfs, rc = -EFAULT);
2208 if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(client_obd),
2214 obd_ioctl_freedata(buf, len);
2218 int ll_process_config(struct lustre_cfg *lcfg)
2222 struct lprocfs_static_vars lvars;
2226 lprocfs_init_vars(llite, &lvars);
2228 /* The instance name contains the sb: lustre-client-aacfe000 */
2229 ptr = strrchr(lustre_cfg_string(lcfg, 0), '-');
2230 if (!ptr || !*(++ptr))
2232 if (sscanf(ptr, "%lx", &x) != 1)
2235 /* This better be a real Lustre superblock! */
2236 LASSERT(s2lsi((struct super_block *)sb)->lsi_lmd->lmd_magic == LMD_MAGIC);
2238 /* Note we have not called client_common_fill_super yet, so
2239 proc fns must be able to handle that! */
2240 rc = class_process_proc_param(PARAM_LLITE, lvars.obd_vars,
2245 /* this function prepares md_op_data hint for passing ot down to MD stack. */
2247 ll_prep_md_op_data(struct md_op_data *op_data, struct inode *i1,
2248 struct inode *i2, const char *name, int namelen, int mode)
2250 LASSERT(i1 != NULL);
2253 OBD_ALLOC_PTR(op_data);
2257 ll_i2gids(op_data->suppgids, i1, i2);
2258 op_data->fid1 = ll_i2info(i1)->lli_fid;
2259 op_data->mod_capa1 = ll_i2mdscapa(i1);
2261 /* @i2 may be NULL. In this case caller itself has to initialize ->fid2
2264 op_data->fid2 = *ll_inode2fid(i2);
2265 op_data->mod_capa2 = ll_i2mdscapa(i2);
2268 op_data->name = name;
2269 op_data->namelen = namelen;
2270 op_data->mode = mode;
2271 op_data->mod_time = CURRENT_SECONDS;
2272 op_data->fsuid = current->fsuid;
2273 op_data->fsgid = current->fsgid;
2274 op_data->cap = current->cap_effective;
2279 void ll_finish_md_op_data(struct md_op_data *op_data)
2281 capa_put(op_data->mod_capa1);
2282 capa_put(op_data->mod_capa2);
2283 OBD_FREE_PTR(op_data);
2286 int ll_ioctl_getfacl(struct inode *inode, struct rmtacl_ioctl_data *ioc)
2288 struct ptlrpc_request *req = NULL;
2289 struct mdt_body *body;
2291 struct obd_capa *oc;
2295 LASSERT(ioc->cmd && ioc->cmd_len && ioc->res && ioc->res_len);
2297 OBD_ALLOC(cmd, ioc->cmd_len);
2300 if (copy_from_user(cmd, ioc->cmd, ioc->cmd_len))
2301 GOTO(out, rc = -EFAULT);
2303 oc = ll_i2mdscapa(inode);
2304 rc = md_getxattr(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode), oc,
2305 OBD_MD_FLXATTR, XATTR_NAME_LUSTRE_ACL, cmd,
2306 ioc->cmd_len, ioc->res_len, 0, &req);
2309 CERROR("mdc_getxattr %s [%s] failed: %d\n",
2310 XATTR_NAME_LUSTRE_ACL, cmd, rc);
2314 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*body));
2317 buflen = lustre_msg_buflen(req->rq_repmsg, REPLY_REC_OFF);
2318 LASSERT(buflen <= ioc->res_len);
2319 buf = lustre_msg_string(req->rq_repmsg, REPLY_REC_OFF + 1, ioc->res_len);
2321 if (copy_to_user(ioc->res, buf, buflen))
2322 GOTO(out, rc = -EFAULT);
2326 ptlrpc_req_finished(req);
2327 OBD_FREE(cmd, ioc->cmd_len);
2331 int ll_ioctl_setfacl(struct inode *inode, struct rmtacl_ioctl_data *ioc)
2333 struct ptlrpc_request *req = NULL;
2335 struct obd_capa *oc;
2339 LASSERT(ioc->cmd && ioc->cmd_len && ioc->res && ioc->res_len);
2341 OBD_ALLOC(cmd, ioc->cmd_len);
2344 if (copy_from_user(cmd, ioc->cmd, ioc->cmd_len))
2345 GOTO(out, rc = -EFAULT);
2347 oc = ll_i2mdscapa(inode);
2348 rc = md_setxattr(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode), oc,
2349 OBD_MD_FLXATTR, XATTR_NAME_LUSTRE_ACL, cmd,
2350 ioc->cmd_len, ioc->res_len, 0, &req);
2353 CERROR("mdc_setxattr %s [%s] failed: %d\n",
2354 XATTR_NAME_LUSTRE_ACL, cmd, rc);
2358 buflen = lustre_msg_buflen(req->rq_repmsg, REPLY_REC_OFF);
2359 LASSERT(buflen <= ioc->res_len);
2360 buf = lustre_msg_string(req->rq_repmsg, REPLY_REC_OFF, ioc->res_len);
2362 if (copy_to_user(ioc->res, buf, buflen))
2363 GOTO(out, rc = -EFAULT);
2367 ptlrpc_req_finished(req);
2368 OBD_FREE(cmd, ioc->cmd_len);