4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/llite/llite_lib.c
34 * Lustre Light Super operations
37 #define DEBUG_SUBSYSTEM S_LLITE
39 #include <linux/module.h>
40 #include <linux/statfs.h>
41 #include <linux/types.h>
44 #include "../include/lustre_lite.h"
45 #include "../include/lustre_ha.h"
46 #include "../include/lustre_dlm.h"
47 #include "../include/lprocfs_status.h"
48 #include "../include/lustre_disk.h"
49 #include "../include/lustre_param.h"
50 #include "../include/lustre_log.h"
51 #include "../include/cl_object.h"
52 #include "../include/obd_cksum.h"
53 #include "llite_internal.h"
55 struct kmem_cache *ll_file_data_slab;
56 struct dentry *llite_root;
57 struct kset *llite_kset;
60 #define log2(n) ffz(~(n))
63 static struct ll_sb_info *ll_init_sbi(struct super_block *sb)
65 struct ll_sb_info *sbi = NULL;
67 unsigned long lru_page_max;
72 sbi = kzalloc(sizeof(*sbi), GFP_NOFS);
76 spin_lock_init(&sbi->ll_lock);
77 mutex_init(&sbi->ll_lco.lco_lock);
78 spin_lock_init(&sbi->ll_pp_extent_lock);
79 spin_lock_init(&sbi->ll_process_lock);
80 sbi->ll_rw_stats_on = 0;
83 pages = si.totalram - si.totalhigh;
84 lru_page_max = pages / 2;
86 sbi->ll_cache = cl_cache_init(lru_page_max);
92 sbi->ll_ra_info.ra_max_pages_per_file = min(pages / 32,
93 SBI_DEFAULT_READAHEAD_MAX);
94 sbi->ll_ra_info.ra_max_pages = sbi->ll_ra_info.ra_max_pages_per_file;
95 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
96 SBI_DEFAULT_READAHEAD_WHOLE_MAX;
98 ll_generate_random_uuid(uuid);
99 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
100 CDEBUG(D_CONFIG, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
102 sbi->ll_flags |= LL_SBI_VERBOSE;
103 sbi->ll_flags |= LL_SBI_CHECKSUM;
105 sbi->ll_flags |= LL_SBI_LRU_RESIZE;
107 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
108 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
110 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
114 /* metadata statahead is enabled by default */
115 sbi->ll_sa_max = LL_SA_RPC_DEF;
116 atomic_set(&sbi->ll_sa_total, 0);
117 atomic_set(&sbi->ll_sa_wrong, 0);
118 atomic_set(&sbi->ll_agl_total, 0);
119 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
126 static void ll_free_sbi(struct super_block *sb)
128 struct ll_sb_info *sbi = ll_s2sbi(sb);
131 cl_cache_decref(sbi->ll_cache);
132 sbi->ll_cache = NULL;
138 static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
139 struct vfsmount *mnt)
141 struct inode *root = NULL;
142 struct ll_sb_info *sbi = ll_s2sbi(sb);
143 struct obd_device *obd;
144 struct obd_statfs *osfs = NULL;
145 struct ptlrpc_request *request = NULL;
146 struct obd_connect_data *data = NULL;
147 struct obd_uuid *uuid;
148 struct md_op_data *op_data;
149 struct lustre_md lmd;
151 int size, err, checksum;
153 obd = class_name2obd(md);
155 CERROR("MD %s: not setup or attached\n", md);
159 data = kzalloc(sizeof(*data), GFP_NOFS);
163 osfs = kzalloc(sizeof(*osfs), GFP_NOFS);
169 /* indicate the features supported by this client */
170 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
171 OBD_CONNECT_ATTRFID |
172 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
173 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
174 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
175 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
176 OBD_CONNECT_64BITHASH |
177 OBD_CONNECT_EINPROGRESS |
178 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
179 OBD_CONNECT_LAYOUTLOCK |
180 OBD_CONNECT_PINGLESS |
181 OBD_CONNECT_MAX_EASIZE |
182 OBD_CONNECT_FLOCK_DEAD |
183 OBD_CONNECT_DISP_STRIPE;
185 if (sbi->ll_flags & LL_SBI_SOM_PREVIEW)
186 data->ocd_connect_flags |= OBD_CONNECT_SOM;
188 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
189 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
190 #ifdef CONFIG_FS_POSIX_ACL
191 data->ocd_connect_flags |= OBD_CONNECT_ACL | OBD_CONNECT_UMASK;
194 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
195 /* flag mdc connection as lightweight, only used for test
196 * purpose, use with care
198 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
200 data->ocd_ibits_known = MDS_INODELOCK_FULL;
201 data->ocd_version = LUSTRE_VERSION_CODE;
203 if (sb->s_flags & MS_RDONLY)
204 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
205 if (sbi->ll_flags & LL_SBI_USER_XATTR)
206 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
208 if (sbi->ll_flags & LL_SBI_FLOCK)
209 sbi->ll_fop = &ll_file_operations_flock;
210 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
211 sbi->ll_fop = &ll_file_operations;
213 sbi->ll_fop = &ll_file_operations_noflock;
216 data->ocd_connect_flags |= OBD_CONNECT_REAL;
218 data->ocd_brw_size = MD_MAX_BRW_SIZE;
220 err = obd_connect(NULL, &sbi->ll_md_exp, obd, &sbi->ll_sb_uuid,
223 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing recovery, of which this client is not a part. Please wait for recovery to complete, abort, or time out.\n",
227 CERROR("cannot connect to %s: rc = %d\n", md, err);
231 sbi->ll_md_exp->exp_connect_data = *data;
233 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
234 LUSTRE_SEQ_METADATA);
236 CERROR("%s: Can't init metadata layer FID infrastructure, rc = %d\n",
237 sbi->ll_md_exp->exp_obd->obd_name, err);
241 /* For mount, we only need fs info from MDT0, and also in DNE, it
242 * can make sure the client can be mounted as long as MDT0 is
245 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
246 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
247 OBD_STATFS_FOR_MDT0);
251 /* This needs to be after statfs to ensure connect has finished.
252 * Note that "data" does NOT contain the valid connect reply.
253 * If connecting to a 1.8 server there will be no LMV device, so
254 * we can access the MDC export directly and exp_connect_flags will
255 * be non-zero, but if accessing an upgraded 2.1 server it will
256 * have the correct flags filled in.
257 * XXX: fill in the LMV exp_connect_flags from MDC(s).
259 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
260 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
261 valid != CLIENT_CONNECT_MDT_REQD) {
264 buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
269 obd_connect_flags2str(buf, PAGE_SIZE,
270 valid ^ CLIENT_CONNECT_MDT_REQD, ",");
271 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support feature(s) needed for correct operation of this client (%s). Please upgrade server or downgrade client.\n",
272 sbi->ll_md_exp->exp_obd->obd_name, buf);
278 size = sizeof(*data);
279 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
280 KEY_CONN_DATA, &size, data, NULL);
282 CERROR("%s: Get connect data failed: rc = %d\n",
283 sbi->ll_md_exp->exp_obd->obd_name, err);
287 LASSERT(osfs->os_bsize);
288 sb->s_blocksize = osfs->os_bsize;
289 sb->s_blocksize_bits = log2(osfs->os_bsize);
290 sb->s_magic = LL_SUPER_MAGIC;
291 sb->s_maxbytes = MAX_LFS_FILESIZE;
292 sbi->ll_namelen = osfs->os_namelen;
294 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
295 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
296 LCONSOLE_INFO("Disabling user_xattr feature because it is not supported on the server\n");
297 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
300 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
301 sb->s_flags |= MS_POSIXACL;
302 sbi->ll_flags |= LL_SBI_ACL;
304 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
305 sb->s_flags &= ~MS_POSIXACL;
306 sbi->ll_flags &= ~LL_SBI_ACL;
309 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
310 sbi->ll_flags |= LL_SBI_64BIT_HASH;
312 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE)
313 sbi->ll_md_brw_size = data->ocd_brw_size;
315 sbi->ll_md_brw_size = PAGE_SIZE;
317 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
318 sbi->ll_flags |= LL_SBI_LAYOUT_LOCK;
320 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
321 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
323 "%s: disabling xattr cache due to unknown maximum xattr size.\n",
326 sbi->ll_flags |= LL_SBI_XATTR_CACHE;
327 sbi->ll_xattr_cache_enabled = 1;
331 obd = class_name2obd(dt);
333 CERROR("DT %s: not setup or attached\n", dt);
338 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
339 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
340 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
341 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
342 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
343 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
344 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
345 OBD_CONNECT_EINPROGRESS |
346 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
347 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS;
349 if (sbi->ll_flags & LL_SBI_SOM_PREVIEW)
350 data->ocd_connect_flags |= OBD_CONNECT_SOM;
352 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_CKSUM)) {
353 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
354 * disabled by default, because it can still be enabled on the
355 * fly via /sys. As a consequence, we still need to come to an
356 * agreement on the supported algorithms at connect time
358 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
360 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
361 data->ocd_cksum_types = OBD_CKSUM_ADLER;
363 data->ocd_cksum_types = cksum_types_supported_client();
366 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
368 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d ocd_grant: %d\n",
369 data->ocd_connect_flags,
370 data->ocd_version, data->ocd_grant);
372 obd->obd_upcall.onu_owner = &sbi->ll_lco;
373 obd->obd_upcall.onu_upcall = cl_ocd_update;
375 data->ocd_brw_size = DT_MAX_BRW_SIZE;
377 err = obd_connect(NULL, &sbi->ll_dt_exp, obd, &sbi->ll_sb_uuid, data,
380 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing recovery, of which this client is not a part. Please wait for recovery to complete, abort, or time out.\n",
384 CERROR("%s: Cannot connect to %s: rc = %d\n",
385 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
389 sbi->ll_dt_exp->exp_connect_data = *data;
391 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
392 LUSTRE_SEQ_METADATA);
394 CERROR("%s: Can't init data layer FID infrastructure, rc = %d\n",
395 sbi->ll_dt_exp->exp_obd->obd_name, err);
399 mutex_lock(&sbi->ll_lco.lco_lock);
400 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
401 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
402 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
403 mutex_unlock(&sbi->ll_lco.lco_lock);
405 fid_zero(&sbi->ll_root_fid);
406 err = md_getstatus(sbi->ll_md_exp, &sbi->ll_root_fid);
408 CERROR("cannot mds_connect: rc = %d\n", err);
411 if (!fid_is_sane(&sbi->ll_root_fid)) {
412 CERROR("%s: Invalid root fid "DFID" during mount\n",
413 sbi->ll_md_exp->exp_obd->obd_name,
414 PFID(&sbi->ll_root_fid));
418 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
420 sb->s_op = &lustre_super_operations;
421 #if THREAD_SIZE >= 8192 /*b=17630*/
422 sb->s_export_op = &lustre_export_operations;
426 * XXX: move this to after cbd setup?
428 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
429 if (sbi->ll_flags & LL_SBI_ACL)
430 valid |= OBD_MD_FLACL;
432 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
438 op_data->op_fid1 = sbi->ll_root_fid;
439 op_data->op_mode = 0;
440 op_data->op_valid = valid;
442 err = md_getattr(sbi->ll_md_exp, op_data, &request);
445 CERROR("%s: md_getattr failed for root: rc = %d\n",
446 sbi->ll_md_exp->exp_obd->obd_name, err);
450 err = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
451 sbi->ll_md_exp, &lmd);
453 CERROR("failed to understand root inode md: rc = %d\n", err);
454 ptlrpc_req_finished(request);
458 LASSERT(fid_is_sane(&sbi->ll_root_fid));
459 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid,
460 sbi->ll_flags & LL_SBI_32BIT_API),
462 md_free_lustre_md(sbi->ll_md_exp, &lmd);
463 ptlrpc_req_finished(request);
467 obd_free_memmd(sbi->ll_dt_exp, &lmd.lsm);
468 #ifdef CONFIG_FS_POSIX_ACL
470 posix_acl_release(lmd.posix_acl);
471 lmd.posix_acl = NULL;
475 CERROR("lustre_lite: bad iget4 for root\n");
479 err = ll_close_thread_start(&sbi->ll_lcq);
481 CERROR("cannot start close thread: rc %d\n", err);
485 checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
486 err = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
487 KEY_CHECKSUM, sizeof(checksum), &checksum,
491 err = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CACHE_SET),
492 KEY_CACHE_SET, sizeof(*sbi->ll_cache),
493 sbi->ll_cache, NULL);
495 sb->s_root = d_make_root(root);
497 CERROR("%s: can't make root dentry\n",
498 ll_get_fsname(sb, NULL, 0));
503 sbi->ll_sdev_orig = sb->s_dev;
505 /* We set sb->s_dev equal on all lustre clients in order to support
506 * NFS export clustering. NFSD requires that the FSID be the same
509 /* s_dev is also used in lt_compare() to compare two fs, but that is
510 * only a node-local comparison.
512 uuid = obd_get_uuid(sbi->ll_md_exp);
514 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
515 get_uuid2fsid(uuid->uuid, strlen(uuid->uuid), &sbi->ll_fsid);
522 err = ldebugfs_register_mountpoint(llite_root, sb, dt, md);
524 CERROR("%s: could not register mount in debugfs: "
525 "rc = %d\n", ll_get_fsname(sb, NULL, 0), err);
534 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
536 obd_disconnect(sbi->ll_dt_exp);
537 sbi->ll_dt_exp = NULL;
539 obd_fid_fini(sbi->ll_md_exp->exp_obd);
541 obd_disconnect(sbi->ll_md_exp);
542 sbi->ll_md_exp = NULL;
549 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
553 *lmmsize = obd_size_diskmd(sbi->ll_dt_exp, NULL);
555 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
556 KEY_MAX_EASIZE, &size, lmmsize, NULL);
558 CERROR("Get max mdsize error rc %d\n", rc);
563 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
568 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
569 KEY_DEFAULT_EASIZE, &size, lmmsize, NULL);
571 CERROR("Get default mdsize error rc %d\n", rc);
576 static void client_common_put_super(struct super_block *sb)
578 struct ll_sb_info *sbi = ll_s2sbi(sb);
580 ll_close_thread_shutdown(sbi->ll_lcq);
584 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
585 obd_disconnect(sbi->ll_dt_exp);
586 sbi->ll_dt_exp = NULL;
588 ldebugfs_unregister_mountpoint(sbi);
590 obd_fid_fini(sbi->ll_md_exp->exp_obd);
591 obd_disconnect(sbi->ll_md_exp);
592 sbi->ll_md_exp = NULL;
595 void ll_kill_super(struct super_block *sb)
597 struct ll_sb_info *sbi;
600 if (!(sb->s_flags & MS_ACTIVE))
604 /* we need to restore s_dev from changed for clustered NFS before
605 * put_super because new kernels have cached s_dev and change sb->s_dev
606 * in put_super not affected real removing devices
609 sb->s_dev = sbi->ll_sdev_orig;
610 sbi->ll_umounting = 1;
614 static inline int ll_set_opt(const char *opt, char *data, int fl)
616 if (strncmp(opt, data, strlen(opt)) != 0)
622 /* non-client-specific mount options are parsed in lmd_parse */
623 static int ll_options(char *options, int *flags)
626 char *s1 = options, *s2;
631 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
634 CDEBUG(D_SUPER, "next opt=%s\n", s1);
635 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
640 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
645 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
650 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
655 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
660 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
665 tmp = ll_set_opt("user_fid2path", s1, LL_SBI_USER_FID2PATH);
670 tmp = ll_set_opt("nouser_fid2path", s1, LL_SBI_USER_FID2PATH);
676 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
681 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
686 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
691 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
696 tmp = ll_set_opt("lazystatfs", s1, LL_SBI_LAZYSTATFS);
701 tmp = ll_set_opt("nolazystatfs", s1, LL_SBI_LAZYSTATFS);
706 tmp = ll_set_opt("som_preview", s1, LL_SBI_SOM_PREVIEW);
711 tmp = ll_set_opt("32bitapi", s1, LL_SBI_32BIT_API);
716 tmp = ll_set_opt("verbose", s1, LL_SBI_VERBOSE);
721 tmp = ll_set_opt("noverbose", s1, LL_SBI_VERBOSE);
726 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
732 s2 = strchr(s1, ',');
740 void ll_lli_init(struct ll_inode_info *lli)
742 lli->lli_inode_magic = LLI_INODE_MAGIC;
744 lli->lli_ioepoch = 0;
745 lli->lli_maxbytes = MAX_LFS_FILESIZE;
746 spin_lock_init(&lli->lli_lock);
747 lli->lli_posix_acl = NULL;
748 /* Do not set lli_fid, it has been initialized already. */
749 fid_zero(&lli->lli_pfid);
750 INIT_LIST_HEAD(&lli->lli_close_list);
751 lli->lli_pending_och = NULL;
752 lli->lli_mds_read_och = NULL;
753 lli->lli_mds_write_och = NULL;
754 lli->lli_mds_exec_och = NULL;
755 lli->lli_open_fd_read_count = 0;
756 lli->lli_open_fd_write_count = 0;
757 lli->lli_open_fd_exec_count = 0;
758 mutex_init(&lli->lli_och_mutex);
759 spin_lock_init(&lli->lli_agl_lock);
760 lli->lli_has_smd = false;
761 spin_lock_init(&lli->lli_layout_lock);
762 ll_layout_version_set(lli, LL_LAYOUT_GEN_NONE);
763 lli->lli_clob = NULL;
765 init_rwsem(&lli->lli_xattrs_list_rwsem);
766 mutex_init(&lli->lli_xattrs_enq_lock);
768 LASSERT(lli->lli_vfs_inode.i_mode != 0);
769 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
770 mutex_init(&lli->lli_readdir_mutex);
771 lli->lli_opendir_key = NULL;
773 spin_lock_init(&lli->lli_sa_lock);
774 lli->lli_opendir_pid = 0;
776 mutex_init(&lli->lli_size_mutex);
777 lli->lli_symlink_name = NULL;
778 init_rwsem(&lli->lli_trunc_sem);
779 mutex_init(&lli->lli_write_mutex);
780 init_rwsem(&lli->lli_glimpse_sem);
781 lli->lli_glimpse_time = 0;
782 INIT_LIST_HEAD(&lli->lli_agl_list);
783 lli->lli_agl_index = 0;
784 lli->lli_async_rc = 0;
786 mutex_init(&lli->lli_layout_mutex);
789 static inline int ll_bdi_register(struct backing_dev_info *bdi)
791 static atomic_t ll_bdi_num = ATOMIC_INIT(0);
793 bdi->name = "lustre";
794 return bdi_register(bdi, NULL, "lustre-%d",
795 atomic_inc_return(&ll_bdi_num));
798 int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
800 struct lustre_profile *lprof = NULL;
801 struct lustre_sb_info *lsi = s2lsi(sb);
802 struct ll_sb_info *sbi;
803 char *dt = NULL, *md = NULL;
804 char *profilenm = get_profile_name(sb);
805 struct config_llog_instance *cfg;
808 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
810 cfg = kzalloc(sizeof(*cfg), GFP_NOFS);
814 try_module_get(THIS_MODULE);
816 /* client additional sb info */
817 sbi = ll_init_sbi(sb);
818 lsi->lsi_llsbi = sbi;
820 module_put(THIS_MODULE);
825 err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
829 err = bdi_init(&lsi->lsi_bdi);
832 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
833 lsi->lsi_bdi.capabilities = 0;
834 err = ll_bdi_register(&lsi->lsi_bdi);
838 sb->s_bdi = &lsi->lsi_bdi;
839 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
840 sb->s_d_op = &ll_d_ops;
842 /* Generate a string unique to this super, in case some joker tries
843 * to mount the same fs at two mount points.
844 * Use the address of the super itself.
846 cfg->cfg_instance = sb;
847 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
848 cfg->cfg_callback = class_config_llog_handler;
849 /* set up client obds */
850 err = lustre_process_log(sb, profilenm, cfg);
854 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
855 lprof = class_get_profile(profilenm);
857 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be read from the MGS. Does that filesystem exist?\n",
862 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
863 lprof->lp_md, lprof->lp_dt);
865 dt = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
871 md = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_md, cfg->cfg_instance);
877 /* connections, registrations, sb setup */
878 err = client_common_fill_super(sb, md, dt, mnt);
885 else if (sbi->ll_flags & LL_SBI_VERBOSE)
886 LCONSOLE_WARN("Mounted %s\n", profilenm);
890 } /* ll_fill_super */
892 void ll_put_super(struct super_block *sb)
894 struct config_llog_instance cfg, params_cfg;
895 struct obd_device *obd;
896 struct lustre_sb_info *lsi = s2lsi(sb);
897 struct ll_sb_info *sbi = ll_s2sbi(sb);
898 char *profilenm = get_profile_name(sb);
899 int ccc_count, next, force = 1, rc = 0;
901 CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
903 cfg.cfg_instance = sb;
904 lustre_end_log(sb, profilenm, &cfg);
906 params_cfg.cfg_instance = sb;
907 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
909 if (sbi->ll_md_exp) {
910 obd = class_exp2obd(sbi->ll_md_exp);
912 force = obd->obd_force;
915 /* Wait for unstable pages to be committed to stable storage */
917 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
919 rc = l_wait_event(sbi->ll_cache->ccc_unstable_waitq,
920 !atomic_read(&sbi->ll_cache->ccc_unstable_nr),
924 ccc_count = atomic_read(&sbi->ll_cache->ccc_unstable_nr);
925 if (!force && rc != -EINTR)
926 LASSERTF(!ccc_count, "count: %i\n", ccc_count);
928 /* We need to set force before the lov_disconnect in
929 * lustre_common_put_super, since l_d cleans up osc's as well.
933 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
935 obd->obd_force = force;
940 /* Only if client_common_fill_super succeeded */
941 client_common_put_super(sb);
945 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
946 class_manual_cleanup(obd);
948 if (sbi->ll_flags & LL_SBI_VERBOSE)
949 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
952 class_del_profile(profilenm);
954 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
955 bdi_destroy(&lsi->lsi_bdi);
956 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
960 lsi->lsi_llsbi = NULL;
962 lustre_common_put_super(sb);
964 cl_env_cache_purge(~0);
966 module_put(THIS_MODULE);
967 } /* client_put_super */
969 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
971 struct inode *inode = NULL;
973 /* NOTE: we depend on atomic igrab() -bzzz */
974 lock_res_and_lock(lock);
975 if (lock->l_resource->lr_lvb_inode) {
976 struct ll_inode_info *lli;
978 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
979 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
980 inode = igrab(lock->l_resource->lr_lvb_inode);
982 inode = lock->l_resource->lr_lvb_inode;
983 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
984 D_WARNING, lock, "lr_lvb_inode %p is bogus: magic %08x",
985 lock->l_resource->lr_lvb_inode,
986 lli->lli_inode_magic);
990 unlock_res_and_lock(lock);
994 void ll_clear_inode(struct inode *inode)
996 struct ll_inode_info *lli = ll_i2info(inode);
997 struct ll_sb_info *sbi = ll_i2sbi(inode);
999 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1000 PFID(ll_inode2fid(inode)), inode);
1002 if (S_ISDIR(inode->i_mode)) {
1003 /* these should have been cleared in ll_file_release */
1004 LASSERT(!lli->lli_opendir_key);
1005 LASSERT(!lli->lli_sai);
1006 LASSERT(lli->lli_opendir_pid == 0);
1009 spin_lock(&lli->lli_lock);
1010 ll_i2info(inode)->lli_flags &= ~LLIF_MDS_SIZE_LOCK;
1011 spin_unlock(&lli->lli_lock);
1012 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1014 LASSERT(!lli->lli_open_fd_write_count);
1015 LASSERT(!lli->lli_open_fd_read_count);
1016 LASSERT(!lli->lli_open_fd_exec_count);
1018 if (lli->lli_mds_write_och)
1019 ll_md_real_close(inode, FMODE_WRITE);
1020 if (lli->lli_mds_exec_och)
1021 ll_md_real_close(inode, FMODE_EXEC);
1022 if (lli->lli_mds_read_och)
1023 ll_md_real_close(inode, FMODE_READ);
1025 if (S_ISLNK(inode->i_mode)) {
1026 kfree(lli->lli_symlink_name);
1027 lli->lli_symlink_name = NULL;
1030 ll_xattr_cache_destroy(inode);
1032 #ifdef CONFIG_FS_POSIX_ACL
1033 if (lli->lli_posix_acl) {
1034 LASSERT(atomic_read(&lli->lli_posix_acl->a_refcount) == 1);
1035 posix_acl_release(lli->lli_posix_acl);
1036 lli->lli_posix_acl = NULL;
1039 lli->lli_inode_magic = LLI_INODE_DEAD;
1041 if (!S_ISDIR(inode->i_mode))
1042 LASSERT(list_empty(&lli->lli_agl_list));
1045 * XXX This has to be done before lsm is freed below, because
1046 * cl_object still uses inode lsm.
1048 cl_inode_fini(inode);
1049 lli->lli_has_smd = false;
1052 #define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
1054 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data,
1055 struct md_open_data **mod)
1057 struct lustre_md md;
1058 struct inode *inode = d_inode(dentry);
1059 struct ll_sb_info *sbi = ll_i2sbi(inode);
1060 struct ptlrpc_request *request = NULL;
1063 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1064 LUSTRE_OPC_ANY, NULL);
1065 if (IS_ERR(op_data))
1066 return PTR_ERR(op_data);
1068 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, NULL, 0,
1071 ptlrpc_req_finished(request);
1072 if (rc == -ENOENT) {
1074 /* Unlinked special device node? Or just a race?
1075 * Pretend we did everything.
1077 if (!S_ISREG(inode->i_mode) &&
1078 !S_ISDIR(inode->i_mode)) {
1079 ia_valid = op_data->op_attr.ia_valid;
1080 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1081 rc = simple_setattr(dentry, &op_data->op_attr);
1082 op_data->op_attr.ia_valid = ia_valid;
1084 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1085 CERROR("md_setattr fails: rc = %d\n", rc);
1090 rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
1091 sbi->ll_md_exp, &md);
1093 ptlrpc_req_finished(request);
1097 ia_valid = op_data->op_attr.ia_valid;
1098 /* inode size will be in cl_setattr_ost, can't do it now since dirty
1099 * cache is not cleared yet.
1101 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1102 rc = simple_setattr(dentry, &op_data->op_attr);
1103 op_data->op_attr.ia_valid = ia_valid;
1105 /* Extract epoch data if obtained. */
1106 op_data->op_handle = md.body->handle;
1107 op_data->op_ioepoch = md.body->ioepoch;
1109 ll_update_inode(inode, &md);
1110 ptlrpc_req_finished(request);
1115 /* Close IO epoch and send Size-on-MDS attribute update. */
1116 static int ll_setattr_done_writing(struct inode *inode,
1117 struct md_op_data *op_data,
1118 struct md_open_data *mod)
1120 struct ll_inode_info *lli = ll_i2info(inode);
1123 if (!S_ISREG(inode->i_mode))
1126 CDEBUG(D_INODE, "Epoch %llu closed on "DFID" for truncate\n",
1127 op_data->op_ioepoch, PFID(&lli->lli_fid));
1129 op_data->op_flags = MF_EPOCH_CLOSE;
1130 ll_done_writing_attr(inode, op_data);
1131 ll_pack_inode2opdata(inode, op_data, NULL);
1133 rc = md_done_writing(ll_i2sbi(inode)->ll_md_exp, op_data, mod);
1135 /* MDS has instructed us to obtain Size-on-MDS attribute
1136 * from OSTs and send setattr to back to MDS.
1138 rc = ll_som_update(inode, op_data);
1140 CERROR("%s: inode "DFID" mdc truncate failed: rc = %d\n",
1141 ll_i2sbi(inode)->ll_md_exp->exp_obd->obd_name,
1142 PFID(ll_inode2fid(inode)), rc);
1147 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1148 * object(s) determine the file size and mtime. Otherwise, the MDS will
1149 * keep these values until such a time that objects are allocated for it.
1150 * We do the MDS operations first, as it is checking permissions for us.
1151 * We don't to the MDS RPC if there is nothing that we want to store there,
1152 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1153 * going to do an RPC anyways.
1155 * If we are doing a truncate, we will send the mtime and ctime updates
1156 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1157 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1160 * In case of HSMimport, we only set attr on MDS.
1162 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
1164 struct inode *inode = d_inode(dentry);
1165 struct ll_inode_info *lli = ll_i2info(inode);
1166 struct md_op_data *op_data = NULL;
1167 struct md_open_data *mod = NULL;
1168 bool file_is_released = false;
1169 int rc = 0, rc1 = 0;
1171 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, valid %x, hsm_import %d\n",
1172 ll_get_fsname(inode->i_sb, NULL, 0), PFID(&lli->lli_fid), inode,
1173 i_size_read(inode), attr->ia_size, attr->ia_valid, hsm_import);
1175 if (attr->ia_valid & ATTR_SIZE) {
1176 /* Check new size against VFS/VM file size limit and rlimit */
1177 rc = inode_newsize_ok(inode, attr->ia_size);
1181 /* The maximum Lustre file size is variable, based on the
1182 * OST maximum object size and number of stripes. This
1183 * needs another check in addition to the VFS check above.
1185 if (attr->ia_size > ll_file_maxbytes(inode)) {
1186 CDEBUG(D_INODE, "file "DFID" too large %llu > %llu\n",
1187 PFID(&lli->lli_fid), attr->ia_size,
1188 ll_file_maxbytes(inode));
1192 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1195 /* POSIX: check before ATTR_*TIME_SET set (from setattr_prepare) */
1196 if (attr->ia_valid & TIMES_SET_FLAGS) {
1197 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
1198 !capable(CFS_CAP_FOWNER))
1202 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1203 if (attr->ia_valid & ATTR_CTIME) {
1204 attr->ia_ctime = CURRENT_TIME;
1205 attr->ia_valid |= ATTR_CTIME_SET;
1207 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
1208 (attr->ia_valid & ATTR_ATIME)) {
1209 attr->ia_atime = CURRENT_TIME;
1210 attr->ia_valid |= ATTR_ATIME_SET;
1212 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
1213 (attr->ia_valid & ATTR_MTIME)) {
1214 attr->ia_mtime = CURRENT_TIME;
1215 attr->ia_valid |= ATTR_MTIME_SET;
1218 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1219 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %llu\n",
1220 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1221 (s64)ktime_get_real_seconds());
1223 /* We always do an MDS RPC, even if we're only changing the size;
1224 * only the MDS knows whether truncate() should fail with -ETXTBUSY
1227 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
1231 if (!S_ISDIR(inode->i_mode))
1232 inode_unlock(inode);
1234 /* truncate on a released file must failed with -ENODATA,
1235 * so size must not be set on MDS for released file
1236 * but other attributes must be set
1238 if (S_ISREG(inode->i_mode)) {
1239 struct lov_stripe_md *lsm;
1242 ll_layout_refresh(inode, &gen);
1243 lsm = ccc_inode_lsm_get(inode);
1244 if (lsm && lsm->lsm_pattern & LOV_PATTERN_F_RELEASED)
1245 file_is_released = true;
1246 ccc_inode_lsm_put(inode, lsm);
1248 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
1249 if (file_is_released) {
1250 rc = ll_layout_restore(inode, 0, attr->ia_size);
1254 file_is_released = false;
1255 ll_layout_refresh(inode, &gen);
1259 * If we are changing file size, file content is
1260 * modified, flag it.
1262 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1263 spin_lock(&lli->lli_lock);
1264 lli->lli_flags |= LLIF_DATA_MODIFIED;
1265 spin_unlock(&lli->lli_lock);
1266 op_data->op_bias |= MDS_DATA_MODIFIED;
1270 memcpy(&op_data->op_attr, attr, sizeof(*attr));
1272 /* Open epoch for truncate. */
1273 if (exp_connect_som(ll_i2mdexp(inode)) && !hsm_import &&
1274 (attr->ia_valid & (ATTR_SIZE | ATTR_MTIME | ATTR_MTIME_SET)))
1275 op_data->op_flags = MF_EPOCH_OPEN;
1277 rc = ll_md_setattr(dentry, op_data, &mod);
1281 /* RPC to MDT is sent, cancel data modification flag */
1282 if (op_data->op_bias & MDS_DATA_MODIFIED) {
1283 spin_lock(&lli->lli_lock);
1284 lli->lli_flags &= ~LLIF_DATA_MODIFIED;
1285 spin_unlock(&lli->lli_lock);
1288 ll_ioepoch_open(lli, op_data->op_ioepoch);
1289 if (!S_ISREG(inode->i_mode) || file_is_released) {
1294 if (attr->ia_valid & (ATTR_SIZE |
1295 ATTR_ATIME | ATTR_ATIME_SET |
1296 ATTR_MTIME | ATTR_MTIME_SET)) {
1297 /* For truncate and utimes sending attributes to OSTs, setting
1298 * mtime/atime to the past will be performed under PW [0:EOF]
1299 * extent lock (new_size:EOF for truncate). It may seem
1300 * excessive to send mtime/atime updates to OSTs when not
1301 * setting times to past, but it is necessary due to possible
1302 * time de-synchronization between MDT inode and OST objects
1304 if (attr->ia_valid & ATTR_SIZE)
1305 down_write(&lli->lli_trunc_sem);
1306 rc = cl_setattr_ost(inode, attr);
1307 if (attr->ia_valid & ATTR_SIZE)
1308 up_write(&lli->lli_trunc_sem);
1311 if (op_data->op_ioepoch) {
1312 rc1 = ll_setattr_done_writing(inode, op_data, mod);
1316 ll_finish_md_op_data(op_data);
1318 if (!S_ISDIR(inode->i_mode)) {
1320 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
1321 inode_dio_wait(inode);
1324 ll_stats_ops_tally(ll_i2sbi(inode), (attr->ia_valid & ATTR_SIZE) ?
1325 LPROC_LL_TRUNC : LPROC_LL_SETATTR, 1);
1330 int ll_setattr(struct dentry *de, struct iattr *attr)
1332 int mode = d_inode(de)->i_mode;
1334 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1335 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1336 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1338 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
1339 (ATTR_SIZE|ATTR_MODE)) &&
1340 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
1341 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
1342 !(attr->ia_mode & S_ISGID))))
1343 attr->ia_valid |= ATTR_FORCE;
1345 if ((attr->ia_valid & ATTR_MODE) &&
1347 !(attr->ia_mode & S_ISUID) &&
1348 !(attr->ia_valid & ATTR_KILL_SUID))
1349 attr->ia_valid |= ATTR_KILL_SUID;
1351 if ((attr->ia_valid & ATTR_MODE) &&
1352 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
1353 !(attr->ia_mode & S_ISGID) &&
1354 !(attr->ia_valid & ATTR_KILL_SGID))
1355 attr->ia_valid |= ATTR_KILL_SGID;
1357 return ll_setattr_raw(de, attr, false);
1360 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1361 __u64 max_age, __u32 flags)
1363 struct ll_sb_info *sbi = ll_s2sbi(sb);
1364 struct obd_statfs obd_osfs;
1367 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
1369 CERROR("md_statfs fails: rc = %d\n", rc);
1373 osfs->os_type = sb->s_magic;
1375 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
1376 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,
1379 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
1380 flags |= OBD_STATFS_NODELAY;
1382 rc = obd_statfs_rqset(sbi->ll_dt_exp, &obd_osfs, max_age, flags);
1384 CERROR("obd_statfs fails: rc = %d\n", rc);
1388 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
1389 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1392 osfs->os_bsize = obd_osfs.os_bsize;
1393 osfs->os_blocks = obd_osfs.os_blocks;
1394 osfs->os_bfree = obd_osfs.os_bfree;
1395 osfs->os_bavail = obd_osfs.os_bavail;
1397 /* If we don't have as many objects free on the OST as inodes
1398 * on the MDS, we reduce the total number of inodes to
1399 * compensate, so that the "inodes in use" number is correct.
1401 if (obd_osfs.os_ffree < osfs->os_ffree) {
1402 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1404 osfs->os_ffree = obd_osfs.os_ffree;
1410 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1412 struct super_block *sb = de->d_sb;
1413 struct obd_statfs osfs;
1416 CDEBUG(D_VFSTRACE, "VFS Op: at %llu jiffies\n", get_jiffies_64());
1417 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1);
1419 /* Some amount of caching on the client is allowed */
1420 rc = ll_statfs_internal(sb, &osfs,
1421 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1426 statfs_unpack(sfs, &osfs);
1428 /* We need to downshift for all 32-bit kernels, because we can't
1429 * tell if the kernel is being called via sys_statfs64() or not.
1430 * Stop before overflowing f_bsize - in which case it is better
1431 * to just risk EOVERFLOW if caller is using old sys_statfs().
1433 if (sizeof(long) < 8) {
1434 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1437 osfs.os_blocks >>= 1;
1438 osfs.os_bfree >>= 1;
1439 osfs.os_bavail >>= 1;
1443 sfs->f_blocks = osfs.os_blocks;
1444 sfs->f_bfree = osfs.os_bfree;
1445 sfs->f_bavail = osfs.os_bavail;
1446 sfs->f_fsid = ll_s2sbi(sb)->ll_fsid;
1450 void ll_inode_size_lock(struct inode *inode)
1452 struct ll_inode_info *lli;
1454 LASSERT(!S_ISDIR(inode->i_mode));
1456 lli = ll_i2info(inode);
1457 mutex_lock(&lli->lli_size_mutex);
1460 void ll_inode_size_unlock(struct inode *inode)
1462 struct ll_inode_info *lli;
1464 lli = ll_i2info(inode);
1465 mutex_unlock(&lli->lli_size_mutex);
1468 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1470 struct ll_inode_info *lli = ll_i2info(inode);
1471 struct mdt_body *body = md->body;
1472 struct lov_stripe_md *lsm = md->lsm;
1473 struct ll_sb_info *sbi = ll_i2sbi(inode);
1475 LASSERT((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1477 if (!lli->lli_has_smd &&
1478 !(sbi->ll_flags & LL_SBI_LAYOUT_LOCK))
1479 cl_file_inode_init(inode, md);
1481 lli->lli_maxbytes = lsm->lsm_maxbytes;
1482 if (lli->lli_maxbytes > MAX_LFS_FILESIZE)
1483 lli->lli_maxbytes = MAX_LFS_FILESIZE;
1486 #ifdef CONFIG_FS_POSIX_ACL
1487 if (body->valid & OBD_MD_FLACL) {
1488 spin_lock(&lli->lli_lock);
1489 if (lli->lli_posix_acl)
1490 posix_acl_release(lli->lli_posix_acl);
1491 lli->lli_posix_acl = md->posix_acl;
1492 spin_unlock(&lli->lli_lock);
1495 inode->i_ino = cl_fid_build_ino(&body->fid1,
1496 sbi->ll_flags & LL_SBI_32BIT_API);
1497 inode->i_generation = cl_fid_build_gen(&body->fid1);
1499 if (body->valid & OBD_MD_FLATIME) {
1500 if (body->atime > LTIME_S(inode->i_atime))
1501 LTIME_S(inode->i_atime) = body->atime;
1502 lli->lli_atime = body->atime;
1504 if (body->valid & OBD_MD_FLMTIME) {
1505 if (body->mtime > LTIME_S(inode->i_mtime)) {
1506 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %llu\n",
1507 inode->i_ino, LTIME_S(inode->i_mtime),
1509 LTIME_S(inode->i_mtime) = body->mtime;
1511 lli->lli_mtime = body->mtime;
1513 if (body->valid & OBD_MD_FLCTIME) {
1514 if (body->ctime > LTIME_S(inode->i_ctime))
1515 LTIME_S(inode->i_ctime) = body->ctime;
1516 lli->lli_ctime = body->ctime;
1518 if (body->valid & OBD_MD_FLMODE)
1519 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1520 if (body->valid & OBD_MD_FLTYPE)
1521 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1522 LASSERT(inode->i_mode != 0);
1523 if (S_ISREG(inode->i_mode))
1524 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS + 1,
1525 LL_MAX_BLKSIZE_BITS);
1527 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
1528 if (body->valid & OBD_MD_FLUID)
1529 inode->i_uid = make_kuid(&init_user_ns, body->uid);
1530 if (body->valid & OBD_MD_FLGID)
1531 inode->i_gid = make_kgid(&init_user_ns, body->gid);
1532 if (body->valid & OBD_MD_FLFLAGS)
1533 inode->i_flags = ll_ext_to_inode_flags(body->flags);
1534 if (body->valid & OBD_MD_FLNLINK)
1535 set_nlink(inode, body->nlink);
1536 if (body->valid & OBD_MD_FLRDEV)
1537 inode->i_rdev = old_decode_dev(body->rdev);
1539 if (body->valid & OBD_MD_FLID) {
1540 /* FID shouldn't be changed! */
1541 if (fid_is_sane(&lli->lli_fid)) {
1542 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->fid1),
1543 "Trying to change FID "DFID" to the "DFID", inode "DFID"(%p)\n",
1544 PFID(&lli->lli_fid), PFID(&body->fid1),
1545 PFID(ll_inode2fid(inode)), inode);
1547 lli->lli_fid = body->fid1;
1551 LASSERT(fid_seq(&lli->lli_fid) != 0);
1553 if (body->valid & OBD_MD_FLSIZE) {
1554 if (exp_connect_som(ll_i2mdexp(inode)) &&
1555 S_ISREG(inode->i_mode)) {
1556 struct lustre_handle lockh;
1557 enum ldlm_mode mode;
1559 /* As it is possible a blocking ast has been processed
1560 * by this time, we need to check there is an UPDATE
1561 * lock on the client and set LLIF_MDS_SIZE_LOCK holding
1564 mode = ll_take_md_lock(inode, MDS_INODELOCK_UPDATE,
1565 &lockh, LDLM_FL_CBPENDING,
1569 if (lli->lli_flags & (LLIF_DONE_WRITING |
1570 LLIF_EPOCH_PENDING |
1572 CERROR("%s: inode "DFID" flags %u still has size authority! do not trust the size got from MDS\n",
1573 sbi->ll_md_exp->exp_obd->obd_name,
1574 PFID(ll_inode2fid(inode)),
1577 /* Use old size assignment to avoid
1578 * deadlock bz14138 & bz14326
1580 i_size_write(inode, body->size);
1581 spin_lock(&lli->lli_lock);
1582 lli->lli_flags |= LLIF_MDS_SIZE_LOCK;
1583 spin_unlock(&lli->lli_lock);
1585 ldlm_lock_decref(&lockh, mode);
1588 /* Use old size assignment to avoid
1589 * deadlock bz14138 & bz14326
1591 i_size_write(inode, body->size);
1593 CDEBUG(D_VFSTRACE, "inode=%lu, updating i_size %llu\n",
1594 inode->i_ino, (unsigned long long)body->size);
1597 if (body->valid & OBD_MD_FLBLOCKS)
1598 inode->i_blocks = body->blocks;
1601 if (body->valid & OBD_MD_TSTATE) {
1602 if (body->t_state & MS_RESTORE)
1603 lli->lli_flags |= LLIF_FILE_RESTORING;
1607 void ll_read_inode2(struct inode *inode, void *opaque)
1609 struct lustre_md *md = opaque;
1610 struct ll_inode_info *lli = ll_i2info(inode);
1612 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1613 PFID(&lli->lli_fid), inode);
1615 LASSERT(!lli->lli_has_smd);
1617 /* Core attributes from the MDS first. This is a new inode, and
1618 * the VFS doesn't zero times in the core inode so we have to do
1619 * it ourselves. They will be overwritten by either MDS or OST
1620 * attributes - we just need to make sure they aren't newer.
1622 LTIME_S(inode->i_mtime) = 0;
1623 LTIME_S(inode->i_atime) = 0;
1624 LTIME_S(inode->i_ctime) = 0;
1626 ll_update_inode(inode, md);
1628 /* OIDEBUG(inode); */
1630 if (S_ISREG(inode->i_mode)) {
1631 struct ll_sb_info *sbi = ll_i2sbi(inode);
1633 inode->i_op = &ll_file_inode_operations;
1634 inode->i_fop = sbi->ll_fop;
1635 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
1636 } else if (S_ISDIR(inode->i_mode)) {
1637 inode->i_op = &ll_dir_inode_operations;
1638 inode->i_fop = &ll_dir_operations;
1639 } else if (S_ISLNK(inode->i_mode)) {
1640 inode->i_op = &ll_fast_symlink_inode_operations;
1642 inode->i_op = &ll_special_inode_operations;
1644 init_special_inode(inode, inode->i_mode,
1649 void ll_delete_inode(struct inode *inode)
1651 struct ll_inode_info *lli = ll_i2info(inode);
1653 if (S_ISREG(inode->i_mode) && lli->lli_clob)
1654 /* discard all dirty pages before truncating them, required by
1655 * osc_extent implementation at LU-1030.
1657 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF,
1658 CL_FSYNC_DISCARD, 1);
1660 truncate_inode_pages_final(&inode->i_data);
1662 /* Workaround for LU-118 */
1663 if (inode->i_data.nrpages) {
1664 spin_lock_irq(&inode->i_data.tree_lock);
1665 spin_unlock_irq(&inode->i_data.tree_lock);
1666 LASSERTF(inode->i_data.nrpages == 0,
1667 "inode="DFID"(%p) nrpages=%lu, see http://jira.whamcloud.com/browse/LU-118\n",
1668 PFID(ll_inode2fid(inode)), inode,
1669 inode->i_data.nrpages);
1671 /* Workaround end */
1673 ll_clear_inode(inode);
1677 int ll_iocontrol(struct inode *inode, struct file *file,
1678 unsigned int cmd, unsigned long arg)
1680 struct ll_sb_info *sbi = ll_i2sbi(inode);
1681 struct ptlrpc_request *req = NULL;
1685 case FSFILT_IOC_GETFLAGS: {
1686 struct mdt_body *body;
1687 struct md_op_data *op_data;
1689 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
1690 0, 0, LUSTRE_OPC_ANY,
1692 if (IS_ERR(op_data))
1693 return PTR_ERR(op_data);
1695 op_data->op_valid = OBD_MD_FLFLAGS;
1696 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
1697 ll_finish_md_op_data(op_data);
1699 CERROR("%s: failure inode "DFID": rc = %d\n",
1700 sbi->ll_md_exp->exp_obd->obd_name,
1701 PFID(ll_inode2fid(inode)), rc);
1705 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1707 flags = body->flags;
1709 ptlrpc_req_finished(req);
1711 return put_user(flags, (int __user *)arg);
1713 case FSFILT_IOC_SETFLAGS: {
1714 struct lov_stripe_md *lsm;
1715 struct obd_info oinfo = { };
1716 struct md_op_data *op_data;
1718 if (get_user(flags, (int __user *)arg))
1721 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
1722 LUSTRE_OPC_ANY, NULL);
1723 if (IS_ERR(op_data))
1724 return PTR_ERR(op_data);
1726 op_data->op_attr_flags = flags;
1727 op_data->op_attr.ia_valid |= ATTR_ATTR_FLAG;
1728 rc = md_setattr(sbi->ll_md_exp, op_data,
1729 NULL, 0, NULL, 0, &req, NULL);
1730 ll_finish_md_op_data(op_data);
1731 ptlrpc_req_finished(req);
1735 inode->i_flags = ll_ext_to_inode_flags(flags);
1737 lsm = ccc_inode_lsm_get(inode);
1738 if (!lsm_has_objects(lsm)) {
1739 ccc_inode_lsm_put(inode, lsm);
1743 oinfo.oi_oa = kmem_cache_zalloc(obdo_cachep, GFP_NOFS);
1745 ccc_inode_lsm_put(inode, lsm);
1749 oinfo.oi_oa->o_oi = lsm->lsm_oi;
1750 oinfo.oi_oa->o_flags = flags;
1751 oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS |
1753 obdo_set_parent_fid(oinfo.oi_oa, &ll_i2info(inode)->lli_fid);
1754 rc = obd_setattr_rqset(sbi->ll_dt_exp, &oinfo, NULL);
1755 kmem_cache_free(obdo_cachep, oinfo.oi_oa);
1756 ccc_inode_lsm_put(inode, lsm);
1758 if (rc && rc != -EPERM && rc != -EACCES)
1759 CERROR("osc_setattr_async fails: rc = %d\n", rc);
1770 int ll_flush_ctx(struct inode *inode)
1772 struct ll_sb_info *sbi = ll_i2sbi(inode);
1774 CDEBUG(D_SEC, "flush context for user %d\n",
1775 from_kuid(&init_user_ns, current_uid()));
1777 obd_set_info_async(NULL, sbi->ll_md_exp,
1778 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
1780 obd_set_info_async(NULL, sbi->ll_dt_exp,
1781 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
1786 /* umount -f client means force down, don't save state */
1787 void ll_umount_begin(struct super_block *sb)
1789 struct ll_sb_info *sbi = ll_s2sbi(sb);
1790 struct obd_device *obd;
1791 struct obd_ioctl_data *ioc_data;
1793 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
1794 sb->s_count, atomic_read(&sb->s_active));
1796 obd = class_exp2obd(sbi->ll_md_exp);
1798 CERROR("Invalid MDC connection handle %#llx\n",
1799 sbi->ll_md_exp->exp_handle.h_cookie);
1804 obd = class_exp2obd(sbi->ll_dt_exp);
1806 CERROR("Invalid LOV connection handle %#llx\n",
1807 sbi->ll_dt_exp->exp_handle.h_cookie);
1812 ioc_data = kzalloc(sizeof(*ioc_data), GFP_NOFS);
1814 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
1815 sizeof(*ioc_data), ioc_data, NULL);
1817 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
1818 sizeof(*ioc_data), ioc_data, NULL);
1823 /* Really, we'd like to wait until there are no requests outstanding,
1824 * and then continue. For now, we just invalidate the requests,
1825 * schedule() and sleep one second if needed, and hope.
1830 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
1832 struct ll_sb_info *sbi = ll_s2sbi(sb);
1833 char *profilenm = get_profile_name(sb);
1837 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
1838 read_only = *flags & MS_RDONLY;
1839 err = obd_set_info_async(NULL, sbi->ll_md_exp,
1840 sizeof(KEY_READ_ONLY),
1841 KEY_READ_ONLY, sizeof(read_only),
1844 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
1845 profilenm, read_only ?
1846 "read-only" : "read-write", err);
1851 sb->s_flags |= MS_RDONLY;
1853 sb->s_flags &= ~MS_RDONLY;
1855 if (sbi->ll_flags & LL_SBI_VERBOSE)
1856 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
1857 read_only ? "read-only" : "read-write");
1863 * Cleanup the open handle that is cached on MDT-side.
1865 * For open case, the client side open handling thread may hit error
1866 * after the MDT grant the open. Under such case, the client should
1867 * send close RPC to the MDT as cleanup; otherwise, the open handle
1868 * on the MDT will be leaked there until the client umount or evicted.
1870 * In further, if someone unlinked the file, because the open handle
1871 * holds the reference on such file/object, then it will block the
1872 * subsequent threads that want to locate such object via FID.
1874 * \param[in] sb super block for this file-system
1875 * \param[in] open_req pointer to the original open request
1877 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
1879 struct mdt_body *body;
1880 struct md_op_data *op_data;
1881 struct ptlrpc_request *close_req = NULL;
1882 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
1884 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
1885 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
1889 op_data->op_fid1 = body->fid1;
1890 op_data->op_ioepoch = body->ioepoch;
1891 op_data->op_handle = body->handle;
1892 op_data->op_mod_time = get_seconds();
1893 md_close(exp, op_data, NULL, &close_req);
1894 ptlrpc_req_finished(close_req);
1895 ll_finish_md_op_data(op_data);
1898 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
1899 struct super_block *sb, struct lookup_intent *it)
1901 struct ll_sb_info *sbi = NULL;
1902 struct lustre_md md = { NULL };
1905 LASSERT(*inode || sb);
1906 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
1907 rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
1908 sbi->ll_md_exp, &md);
1913 ll_update_inode(*inode, &md);
1918 * At this point server returns to client's same fid as client
1919 * generated for creating. So using ->fid1 is okay here.
1921 if (!fid_is_sane(&md.body->fid1)) {
1922 CERROR("%s: Fid is insane " DFID "\n",
1923 ll_get_fsname(sb, NULL, 0),
1924 PFID(&md.body->fid1));
1929 *inode = ll_iget(sb, cl_fid_build_ino(&md.body->fid1,
1930 sbi->ll_flags & LL_SBI_32BIT_API),
1933 #ifdef CONFIG_FS_POSIX_ACL
1935 posix_acl_release(md.posix_acl);
1936 md.posix_acl = NULL;
1940 CERROR("new_inode -fatal: rc %d\n", rc);
1945 /* Handling piggyback layout lock.
1946 * Layout lock can be piggybacked by getattr and open request.
1947 * The lsm can be applied to inode only if it comes with a layout lock
1948 * otherwise correct layout may be overwritten, for example:
1949 * 1. proc1: mdt returns a lsm but not granting layout
1950 * 2. layout was changed by another client
1951 * 3. proc2: refresh layout and layout lock granted
1952 * 4. proc1: to apply a stale layout
1954 if (it && it->it_lock_mode != 0) {
1955 struct lustre_handle lockh;
1956 struct ldlm_lock *lock;
1958 lockh.cookie = it->it_lock_handle;
1959 lock = ldlm_handle2lock(&lockh);
1961 if (ldlm_has_layout(lock)) {
1962 struct cl_object_conf conf;
1964 memset(&conf, 0, sizeof(conf));
1965 conf.coc_opc = OBJECT_CONF_SET;
1966 conf.coc_inode = *inode;
1967 conf.coc_lock = lock;
1968 conf.u.coc_md = &md;
1969 (void)ll_layout_conf(*inode, &conf);
1971 LDLM_LOCK_PUT(lock);
1976 obd_free_memmd(sbi->ll_dt_exp, &md.lsm);
1977 md_free_lustre_md(sbi->ll_md_exp, &md);
1980 if (rc != 0 && it && it->it_op & IT_OPEN)
1981 ll_open_cleanup(sb ? sb : (*inode)->i_sb, req);
1986 int ll_obd_statfs(struct inode *inode, void __user *arg)
1988 struct ll_sb_info *sbi = NULL;
1989 struct obd_export *exp;
1991 struct obd_ioctl_data *data = NULL;
2000 sbi = ll_i2sbi(inode);
2006 rc = obd_ioctl_getdata(&buf, &len, arg);
2011 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2012 !data->ioc_pbuf1 || !data->ioc_pbuf2) {
2017 if (data->ioc_inllen1 != sizeof(__u32) ||
2018 data->ioc_inllen2 != sizeof(__u32) ||
2019 data->ioc_plen1 != sizeof(struct obd_statfs) ||
2020 data->ioc_plen2 != sizeof(struct obd_uuid)) {
2025 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2026 if (type & LL_STATFS_LMV) {
2027 exp = sbi->ll_md_exp;
2028 } else if (type & LL_STATFS_LOV) {
2029 exp = sbi->ll_dt_exp;
2035 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL);
2040 obd_ioctl_freedata(buf, len);
2044 int ll_process_config(struct lustre_cfg *lcfg)
2048 struct lprocfs_static_vars lvars;
2052 lprocfs_llite_init_vars(&lvars);
2054 /* The instance name contains the sb: lustre-client-aacfe000 */
2055 ptr = strrchr(lustre_cfg_string(lcfg, 0), '-');
2056 if (!ptr || !*(++ptr))
2058 rc = kstrtoul(ptr, 16, &x);
2062 /* This better be a real Lustre superblock! */
2063 LASSERT(s2lsi((struct super_block *)sb)->lsi_lmd->lmd_magic == LMD_MAGIC);
2065 /* Note we have not called client_common_fill_super yet, so
2066 * proc fns must be able to handle that!
2068 rc = class_process_proc_param(PARAM_LLITE, lvars.obd_vars,
2075 /* this function prepares md_op_data hint for passing ot down to MD stack. */
2076 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
2077 struct inode *i1, struct inode *i2,
2078 const char *name, int namelen,
2079 int mode, __u32 opc, void *data)
2081 if (namelen > ll_i2sbi(i1)->ll_namelen)
2082 return ERR_PTR(-ENAMETOOLONG);
2085 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
2088 return ERR_PTR(-ENOMEM);
2090 ll_i2gids(op_data->op_suppgids, i1, i2);
2091 op_data->op_fid1 = *ll_inode2fid(i1);
2094 op_data->op_fid2 = *ll_inode2fid(i2);
2096 fid_zero(&op_data->op_fid2);
2098 op_data->op_name = name;
2099 op_data->op_namelen = namelen;
2100 op_data->op_mode = mode;
2101 op_data->op_mod_time = ktime_get_real_seconds();
2102 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2103 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2104 op_data->op_cap = cfs_curproc_cap_pack();
2105 op_data->op_bias = 0;
2106 op_data->op_cli_flags = 0;
2107 if ((opc == LUSTRE_OPC_CREATE) && name &&
2108 filename_is_volatile(name, namelen, NULL))
2109 op_data->op_bias |= MDS_CREATE_VOLATILE;
2110 op_data->op_opc = opc;
2111 op_data->op_mds = 0;
2112 op_data->op_data = data;
2114 /* If the file is being opened after mknod() (normally due to NFS)
2115 * try to use the default stripe data from parent directory for
2116 * allocating OST objects. Try to pass the parent FID to MDS.
2118 if (opc == LUSTRE_OPC_CREATE && i1 == i2 && S_ISREG(i2->i_mode) &&
2119 !ll_i2info(i2)->lli_has_smd) {
2120 struct ll_inode_info *lli = ll_i2info(i2);
2122 spin_lock(&lli->lli_lock);
2123 if (likely(!lli->lli_has_smd && !fid_is_zero(&lli->lli_pfid)))
2124 op_data->op_fid1 = lli->lli_pfid;
2125 spin_unlock(&lli->lli_lock);
2128 /* When called by ll_setattr_raw, file is i1. */
2129 if (ll_i2info(i1)->lli_flags & LLIF_DATA_MODIFIED)
2130 op_data->op_bias |= MDS_DATA_MODIFIED;
2135 void ll_finish_md_op_data(struct md_op_data *op_data)
2140 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
2142 struct ll_sb_info *sbi;
2144 LASSERT(seq && dentry);
2145 sbi = ll_s2sbi(dentry->d_sb);
2147 if (sbi->ll_flags & LL_SBI_NOLCK)
2148 seq_puts(seq, ",nolock");
2150 if (sbi->ll_flags & LL_SBI_FLOCK)
2151 seq_puts(seq, ",flock");
2153 if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
2154 seq_puts(seq, ",localflock");
2156 if (sbi->ll_flags & LL_SBI_USER_XATTR)
2157 seq_puts(seq, ",user_xattr");
2159 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
2160 seq_puts(seq, ",lazystatfs");
2162 if (sbi->ll_flags & LL_SBI_USER_FID2PATH)
2163 seq_puts(seq, ",user_fid2path");
2169 * Get obd name by cmd, and copy out to user space
2171 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
2173 struct ll_sb_info *sbi = ll_i2sbi(inode);
2174 struct obd_device *obd;
2176 if (cmd == OBD_IOC_GETDTNAME)
2177 obd = class_exp2obd(sbi->ll_dt_exp);
2178 else if (cmd == OBD_IOC_GETMDNAME)
2179 obd = class_exp2obd(sbi->ll_md_exp);
2186 if (copy_to_user((void __user *)arg, obd->obd_name,
2187 strlen(obd->obd_name) + 1))
2194 * Get lustre file system name by \a sbi. If \a buf is provided(non-NULL), the
2195 * fsname will be returned in this buffer; otherwise, a static buffer will be
2196 * used to store the fsname and returned to caller.
2198 char *ll_get_fsname(struct super_block *sb, char *buf, int buflen)
2200 static char fsname_static[MTI_NAME_MAXLEN];
2201 struct lustre_sb_info *lsi = s2lsi(sb);
2206 /* this means the caller wants to use static buffer
2207 * and it doesn't care about race. Usually this is
2208 * in error reporting path
2210 buf = fsname_static;
2211 buflen = sizeof(fsname_static);
2214 len = strlen(lsi->lsi_lmd->lmd_profile);
2215 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
2216 if (ptr && (strcmp(ptr, "-client") == 0))
2219 if (unlikely(len >= buflen))
2221 strncpy(buf, lsi->lsi_lmd->lmd_profile, len);
2227 void ll_dirty_page_discard_warn(struct page *page, int ioret)
2229 char *buf, *path = NULL;
2230 struct dentry *dentry = NULL;
2231 struct vvp_object *obj = cl_inode2vvp(page->mapping->host);
2233 /* this can be called inside spin lock so use GFP_ATOMIC. */
2234 buf = (char *)__get_free_page(GFP_ATOMIC);
2236 dentry = d_find_alias(page->mapping->host);
2238 path = dentry_path_raw(dentry, buf, PAGE_SIZE);
2242 "%s: dirty page discard: %s/fid: " DFID "/%s may get corrupted (rc %d)\n",
2243 ll_get_fsname(page->mapping->host->i_sb, NULL, 0),
2244 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
2245 PFID(&obj->vob_header.coh_lu.loh_fid),
2246 (path && !IS_ERR(path)) ? path : "", ioret);
2252 free_page((unsigned long)buf);