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 <uapi/linux/lustre/lustre_ioctl.h>
45 #include <lustre_ha.h>
46 #include <lustre_dlm.h>
47 #include <lprocfs_status.h>
48 #include <lustre_disk.h>
49 #include <uapi/linux/lustre/lustre_param.h>
50 #include <lustre_log.h>
51 #include <cl_object.h>
52 #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;
106 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
108 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
109 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
111 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
115 /* metadata statahead is enabled by default */
116 sbi->ll_sa_max = LL_SA_RPC_DEF;
117 atomic_set(&sbi->ll_sa_total, 0);
118 atomic_set(&sbi->ll_sa_wrong, 0);
119 atomic_set(&sbi->ll_sa_running, 0);
120 atomic_set(&sbi->ll_agl_total, 0);
121 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
124 sbi->ll_squash.rsi_uid = 0;
125 sbi->ll_squash.rsi_gid = 0;
126 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
127 init_rwsem(&sbi->ll_squash.rsi_sem);
134 static void ll_free_sbi(struct super_block *sb)
136 struct ll_sb_info *sbi = ll_s2sbi(sb);
139 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
140 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
141 cl_cache_decref(sbi->ll_cache);
142 sbi->ll_cache = NULL;
148 static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
149 struct vfsmount *mnt)
151 struct inode *root = NULL;
152 struct ll_sb_info *sbi = ll_s2sbi(sb);
153 struct obd_device *obd;
154 struct obd_statfs *osfs = NULL;
155 struct ptlrpc_request *request = NULL;
156 struct obd_connect_data *data = NULL;
157 struct obd_uuid *uuid;
158 struct md_op_data *op_data;
159 struct lustre_md lmd;
161 int size, err, checksum;
163 obd = class_name2obd(md);
165 CERROR("MD %s: not setup or attached\n", md);
169 data = kzalloc(sizeof(*data), GFP_NOFS);
173 osfs = kzalloc(sizeof(*osfs), GFP_NOFS);
179 /* indicate the features supported by this client */
180 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
181 OBD_CONNECT_ATTRFID |
182 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
183 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
184 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
185 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
186 OBD_CONNECT_64BITHASH |
187 OBD_CONNECT_EINPROGRESS |
188 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
189 OBD_CONNECT_LAYOUTLOCK |
190 OBD_CONNECT_PINGLESS |
191 OBD_CONNECT_MAX_EASIZE |
192 OBD_CONNECT_FLOCK_DEAD |
193 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
194 OBD_CONNECT_OPEN_BY_FID |
195 OBD_CONNECT_DIR_STRIPE |
196 OBD_CONNECT_BULK_MBITS;
198 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
199 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
200 #ifdef CONFIG_FS_POSIX_ACL
201 data->ocd_connect_flags |= OBD_CONNECT_ACL | OBD_CONNECT_UMASK;
204 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
205 /* flag mdc connection as lightweight, only used for test
206 * purpose, use with care
208 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
210 data->ocd_ibits_known = MDS_INODELOCK_FULL;
211 data->ocd_version = LUSTRE_VERSION_CODE;
214 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
215 if (sbi->ll_flags & LL_SBI_USER_XATTR)
216 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
218 if (sbi->ll_flags & LL_SBI_FLOCK)
219 sbi->ll_fop = &ll_file_operations_flock;
220 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
221 sbi->ll_fop = &ll_file_operations;
223 sbi->ll_fop = &ll_file_operations_noflock;
225 /* always ping even if server suppress_pings */
226 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
227 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
229 data->ocd_brw_size = MD_MAX_BRW_SIZE;
231 err = obd_connect(NULL, &sbi->ll_md_exp, obd, &sbi->ll_sb_uuid,
234 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",
238 CERROR("cannot connect to %s: rc = %d\n", md, err);
242 sbi->ll_md_exp->exp_connect_data = *data;
244 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
245 LUSTRE_SEQ_METADATA);
247 CERROR("%s: Can't init metadata layer FID infrastructure, rc = %d\n",
248 sbi->ll_md_exp->exp_obd->obd_name, err);
252 /* For mount, we only need fs info from MDT0, and also in DNE, it
253 * can make sure the client can be mounted as long as MDT0 is
256 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
257 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
258 OBD_STATFS_FOR_MDT0);
262 /* This needs to be after statfs to ensure connect has finished.
263 * Note that "data" does NOT contain the valid connect reply.
264 * If connecting to a 1.8 server there will be no LMV device, so
265 * we can access the MDC export directly and exp_connect_flags will
266 * be non-zero, but if accessing an upgraded 2.1 server it will
267 * have the correct flags filled in.
268 * XXX: fill in the LMV exp_connect_flags from MDC(s).
270 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
271 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
272 valid != CLIENT_CONNECT_MDT_REQD) {
275 buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
280 obd_connect_flags2str(buf, PAGE_SIZE,
281 valid ^ CLIENT_CONNECT_MDT_REQD, ",");
282 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",
283 sbi->ll_md_exp->exp_obd->obd_name, buf);
289 size = sizeof(*data);
290 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
291 KEY_CONN_DATA, &size, data);
293 CERROR("%s: Get connect data failed: rc = %d\n",
294 sbi->ll_md_exp->exp_obd->obd_name, err);
298 LASSERT(osfs->os_bsize);
299 sb->s_blocksize = osfs->os_bsize;
300 sb->s_blocksize_bits = log2(osfs->os_bsize);
301 sb->s_magic = LL_SUPER_MAGIC;
302 sb->s_maxbytes = MAX_LFS_FILESIZE;
303 sbi->ll_namelen = osfs->os_namelen;
304 sbi->ll_mnt.mnt = current->fs->root.mnt;
306 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
307 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
308 LCONSOLE_INFO("Disabling user_xattr feature because it is not supported on the server\n");
309 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
312 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
313 sb->s_flags |= MS_POSIXACL;
314 sbi->ll_flags |= LL_SBI_ACL;
316 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
317 sb->s_flags &= ~MS_POSIXACL;
318 sbi->ll_flags &= ~LL_SBI_ACL;
321 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
322 sbi->ll_flags |= LL_SBI_64BIT_HASH;
324 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE)
325 sbi->ll_md_brw_pages = data->ocd_brw_size >> PAGE_SHIFT;
327 sbi->ll_md_brw_pages = 1;
329 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
330 sbi->ll_flags |= LL_SBI_LAYOUT_LOCK;
332 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
333 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
335 "%s: disabling xattr cache due to unknown maximum xattr size.\n",
338 sbi->ll_flags |= LL_SBI_XATTR_CACHE;
339 sbi->ll_xattr_cache_enabled = 1;
343 obd = class_name2obd(dt);
345 CERROR("DT %s: not setup or attached\n", dt);
350 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
351 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
352 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
353 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
354 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
355 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
356 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
357 OBD_CONNECT_EINPROGRESS |
358 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
359 OBD_CONNECT_LAYOUTLOCK |
360 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
361 OBD_CONNECT_BULK_MBITS;
363 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_CKSUM)) {
364 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
365 * disabled by default, because it can still be enabled on the
366 * fly via /sys. As a consequence, we still need to come to an
367 * agreement on the supported algorithms at connect time
369 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
371 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
372 data->ocd_cksum_types = OBD_CKSUM_ADLER;
374 data->ocd_cksum_types = cksum_types_supported_client();
377 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
379 /* always ping even if server suppress_pings */
380 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
381 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
383 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d ocd_grant: %d\n",
384 data->ocd_connect_flags,
385 data->ocd_version, data->ocd_grant);
387 obd->obd_upcall.onu_owner = &sbi->ll_lco;
388 obd->obd_upcall.onu_upcall = cl_ocd_update;
390 data->ocd_brw_size = DT_MAX_BRW_SIZE;
392 err = obd_connect(NULL, &sbi->ll_dt_exp, obd, &sbi->ll_sb_uuid, data,
395 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",
399 CERROR("%s: Cannot connect to %s: rc = %d\n",
400 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
404 sbi->ll_dt_exp->exp_connect_data = *data;
406 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
407 LUSTRE_SEQ_METADATA);
409 CERROR("%s: Can't init data layer FID infrastructure, rc = %d\n",
410 sbi->ll_dt_exp->exp_obd->obd_name, err);
414 mutex_lock(&sbi->ll_lco.lco_lock);
415 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
416 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
417 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
418 mutex_unlock(&sbi->ll_lco.lco_lock);
420 fid_zero(&sbi->ll_root_fid);
421 err = md_getstatus(sbi->ll_md_exp, &sbi->ll_root_fid);
423 CERROR("cannot mds_connect: rc = %d\n", err);
426 if (!fid_is_sane(&sbi->ll_root_fid)) {
427 CERROR("%s: Invalid root fid " DFID " during mount\n",
428 sbi->ll_md_exp->exp_obd->obd_name,
429 PFID(&sbi->ll_root_fid));
433 CDEBUG(D_SUPER, "rootfid " DFID "\n", PFID(&sbi->ll_root_fid));
435 sb->s_op = &lustre_super_operations;
436 sb->s_xattr = ll_xattr_handlers;
437 #if THREAD_SIZE >= 8192 /*b=17630*/
438 sb->s_export_op = &lustre_export_operations;
442 * XXX: move this to after cbd setup?
444 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
445 if (sbi->ll_flags & LL_SBI_ACL)
446 valid |= OBD_MD_FLACL;
448 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
454 op_data->op_fid1 = sbi->ll_root_fid;
455 op_data->op_mode = 0;
456 op_data->op_valid = valid;
458 err = md_getattr(sbi->ll_md_exp, op_data, &request);
461 CERROR("%s: md_getattr failed for root: rc = %d\n",
462 sbi->ll_md_exp->exp_obd->obd_name, err);
466 err = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
467 sbi->ll_md_exp, &lmd);
469 CERROR("failed to understand root inode md: rc = %d\n", err);
470 ptlrpc_req_finished(request);
474 LASSERT(fid_is_sane(&sbi->ll_root_fid));
475 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid,
476 sbi->ll_flags & LL_SBI_32BIT_API),
478 md_free_lustre_md(sbi->ll_md_exp, &lmd);
479 ptlrpc_req_finished(request);
482 #ifdef CONFIG_FS_POSIX_ACL
484 posix_acl_release(lmd.posix_acl);
485 lmd.posix_acl = NULL;
489 CERROR("lustre_lite: bad iget4 for root\n");
493 checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
494 err = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
495 KEY_CHECKSUM, sizeof(checksum), &checksum,
498 CERROR("%s: Set checksum failed: rc = %d\n",
499 sbi->ll_dt_exp->exp_obd->obd_name, err);
504 err = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CACHE_SET),
505 KEY_CACHE_SET, sizeof(*sbi->ll_cache),
506 sbi->ll_cache, NULL);
508 CERROR("%s: Set cache_set failed: rc = %d\n",
509 sbi->ll_dt_exp->exp_obd->obd_name, err);
513 sb->s_root = d_make_root(root);
515 CERROR("%s: can't make root dentry\n",
516 ll_get_fsname(sb, NULL, 0));
521 sbi->ll_sdev_orig = sb->s_dev;
523 /* We set sb->s_dev equal on all lustre clients in order to support
524 * NFS export clustering. NFSD requires that the FSID be the same
527 /* s_dev is also used in lt_compare() to compare two fs, but that is
528 * only a node-local comparison.
530 uuid = obd_get_uuid(sbi->ll_md_exp);
532 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
533 get_uuid2fsid(uuid->uuid, strlen(uuid->uuid), &sbi->ll_fsid);
540 err = ldebugfs_register_mountpoint(llite_root, sb, dt, md);
542 CERROR("%s: could not register mount in debugfs: "
543 "rc = %d\n", ll_get_fsname(sb, NULL, 0), err);
552 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
554 obd_disconnect(sbi->ll_dt_exp);
555 sbi->ll_dt_exp = NULL;
557 obd_fid_fini(sbi->ll_md_exp->exp_obd);
559 obd_disconnect(sbi->ll_md_exp);
560 sbi->ll_md_exp = NULL;
567 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
571 size = sizeof(*lmmsize);
572 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
573 KEY_MAX_EASIZE, &size, lmmsize);
575 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
576 sbi->ll_dt_exp->exp_obd->obd_name, rc);
581 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
582 KEY_MAX_EASIZE, &size, lmmsize);
584 CERROR("Get max mdsize error rc %d\n", rc);
590 * Get the value of the default_easize parameter.
592 * \see client_obd::cl_default_mds_easize
594 * \param[in] sbi superblock info for this filesystem
595 * \param[out] lmmsize pointer to storage location for value
597 * \retval 0 on success
598 * \retval negative negated errno on failure
600 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
605 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
606 KEY_DEFAULT_EASIZE, &size, lmmsize);
608 CERROR("Get default mdsize error rc %d\n", rc);
614 * Set the default_easize parameter to the given value.
616 * \see client_obd::cl_default_mds_easize
618 * \param[in] sbi superblock info for this filesystem
619 * \param[in] lmmsize the size to set
621 * \retval 0 on success
622 * \retval negative negated errno on failure
624 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
626 if (lmmsize < sizeof(struct lov_mds_md) ||
627 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
630 return obd_set_info_async(NULL, sbi->ll_md_exp,
631 sizeof(KEY_DEFAULT_EASIZE),
633 sizeof(int), &lmmsize, NULL);
636 static void client_common_put_super(struct super_block *sb)
638 struct ll_sb_info *sbi = ll_s2sbi(sb);
642 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
643 obd_disconnect(sbi->ll_dt_exp);
644 sbi->ll_dt_exp = NULL;
646 ldebugfs_unregister_mountpoint(sbi);
648 obd_fid_fini(sbi->ll_md_exp->exp_obd);
649 obd_disconnect(sbi->ll_md_exp);
650 sbi->ll_md_exp = NULL;
653 void ll_kill_super(struct super_block *sb)
655 struct ll_sb_info *sbi;
658 if (!(sb->s_flags & MS_ACTIVE))
662 /* we need to restore s_dev from changed for clustered NFS before
663 * put_super because new kernels have cached s_dev and change sb->s_dev
664 * in put_super not affected real removing devices
667 sb->s_dev = sbi->ll_sdev_orig;
668 sbi->ll_umounting = 1;
670 /* wait running statahead threads to quit */
671 while (atomic_read(&sbi->ll_sa_running) > 0) {
672 set_current_state(TASK_UNINTERRUPTIBLE);
673 schedule_timeout(msecs_to_jiffies(MSEC_PER_SEC >> 3));
678 static inline int ll_set_opt(const char *opt, char *data, int fl)
680 if (strncmp(opt, data, strlen(opt)) != 0)
686 /* non-client-specific mount options are parsed in lmd_parse */
687 static int ll_options(char *options, int *flags)
690 char *s1 = options, *s2;
695 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
698 CDEBUG(D_SUPER, "next opt=%s\n", s1);
699 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
704 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
709 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
714 tmp = ll_set_opt("noflock", s1,
715 LL_SBI_FLOCK | LL_SBI_LOCALFLOCK);
720 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
725 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
730 tmp = ll_set_opt("context", s1, 1);
733 tmp = ll_set_opt("fscontext", s1, 1);
736 tmp = ll_set_opt("defcontext", s1, 1);
739 tmp = ll_set_opt("rootcontext", s1, 1);
742 tmp = ll_set_opt("user_fid2path", s1, LL_SBI_USER_FID2PATH);
747 tmp = ll_set_opt("nouser_fid2path", s1, LL_SBI_USER_FID2PATH);
753 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
758 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
763 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
768 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
773 tmp = ll_set_opt("lazystatfs", s1, LL_SBI_LAZYSTATFS);
778 tmp = ll_set_opt("nolazystatfs", s1, LL_SBI_LAZYSTATFS);
783 tmp = ll_set_opt("32bitapi", s1, LL_SBI_32BIT_API);
788 tmp = ll_set_opt("verbose", s1, LL_SBI_VERBOSE);
793 tmp = ll_set_opt("noverbose", s1, LL_SBI_VERBOSE);
798 tmp = ll_set_opt("always_ping", s1, LL_SBI_ALWAYS_PING);
803 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
809 s2 = strchr(s1, ',');
817 void ll_lli_init(struct ll_inode_info *lli)
819 lli->lli_inode_magic = LLI_INODE_MAGIC;
821 spin_lock_init(&lli->lli_lock);
822 lli->lli_posix_acl = NULL;
823 /* Do not set lli_fid, it has been initialized already. */
824 fid_zero(&lli->lli_pfid);
825 lli->lli_mds_read_och = NULL;
826 lli->lli_mds_write_och = NULL;
827 lli->lli_mds_exec_och = NULL;
828 lli->lli_open_fd_read_count = 0;
829 lli->lli_open_fd_write_count = 0;
830 lli->lli_open_fd_exec_count = 0;
831 mutex_init(&lli->lli_och_mutex);
832 spin_lock_init(&lli->lli_agl_lock);
833 spin_lock_init(&lli->lli_layout_lock);
834 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
835 lli->lli_clob = NULL;
837 init_rwsem(&lli->lli_xattrs_list_rwsem);
838 mutex_init(&lli->lli_xattrs_enq_lock);
840 LASSERT(lli->lli_vfs_inode.i_mode != 0);
841 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
842 mutex_init(&lli->lli_readdir_mutex);
843 lli->lli_opendir_key = NULL;
845 spin_lock_init(&lli->lli_sa_lock);
846 lli->lli_opendir_pid = 0;
847 lli->lli_sa_enabled = 0;
848 lli->lli_def_stripe_offset = -1;
850 mutex_init(&lli->lli_size_mutex);
851 lli->lli_symlink_name = NULL;
852 init_rwsem(&lli->lli_trunc_sem);
853 range_lock_tree_init(&lli->lli_write_tree);
854 init_rwsem(&lli->lli_glimpse_sem);
855 lli->lli_glimpse_time = 0;
856 INIT_LIST_HEAD(&lli->lli_agl_list);
857 lli->lli_agl_index = 0;
858 lli->lli_async_rc = 0;
860 mutex_init(&lli->lli_layout_mutex);
863 int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
865 struct lustre_profile *lprof = NULL;
866 struct lustre_sb_info *lsi = s2lsi(sb);
867 struct ll_sb_info *sbi;
868 char *dt = NULL, *md = NULL;
869 char *profilenm = get_profile_name(sb);
870 struct config_llog_instance *cfg;
872 static atomic_t ll_bdi_num = ATOMIC_INIT(0);
874 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
876 cfg = kzalloc(sizeof(*cfg), GFP_NOFS);
880 try_module_get(THIS_MODULE);
882 /* client additional sb info */
883 sbi = ll_init_sbi(sb);
884 lsi->lsi_llsbi = sbi;
886 module_put(THIS_MODULE);
891 err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
895 err = super_setup_bdi_name(sb, "lustre-%d",
896 atomic_inc_return(&ll_bdi_num));
900 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
901 sb->s_d_op = &ll_d_ops;
903 /* Generate a string unique to this super, in case some joker tries
904 * to mount the same fs at two mount points.
905 * Use the address of the super itself.
907 cfg->cfg_instance = sb;
908 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
909 cfg->cfg_callback = class_config_llog_handler;
910 /* set up client obds */
911 err = lustre_process_log(sb, profilenm, cfg);
915 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
916 lprof = class_get_profile(profilenm);
918 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be read from the MGS. Does that filesystem exist?\n",
923 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
924 lprof->lp_md, lprof->lp_dt);
926 dt = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
932 md = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_md, cfg->cfg_instance);
938 /* connections, registrations, sb setup */
939 err = client_common_fill_super(sb, md, dt, mnt);
941 sbi->ll_client_common_fill_super_succeeded = 1;
947 class_put_profile(lprof);
950 else if (sbi->ll_flags & LL_SBI_VERBOSE)
951 LCONSOLE_WARN("Mounted %s\n", profilenm);
955 } /* ll_fill_super */
957 void ll_put_super(struct super_block *sb)
959 struct config_llog_instance cfg, params_cfg;
960 struct obd_device *obd;
961 struct lustre_sb_info *lsi = s2lsi(sb);
962 struct ll_sb_info *sbi = ll_s2sbi(sb);
963 char *profilenm = get_profile_name(sb);
964 int next, force = 1, rc = 0;
967 CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
969 cfg.cfg_instance = sb;
970 lustre_end_log(sb, profilenm, &cfg);
972 params_cfg.cfg_instance = sb;
973 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
975 if (sbi->ll_md_exp) {
976 obd = class_exp2obd(sbi->ll_md_exp);
978 force = obd->obd_force;
981 /* Wait for unstable pages to be committed to stable storage */
983 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
985 rc = l_wait_event(sbi->ll_cache->ccc_unstable_waitq,
986 !atomic_long_read(&sbi->ll_cache->ccc_unstable_nr),
990 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
991 if (!force && rc != -EINTR)
992 LASSERTF(!ccc_count, "count: %li\n", ccc_count);
994 /* We need to set force before the lov_disconnect in
995 * lustre_common_put_super, since l_d cleans up osc's as well.
999 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1001 obd->obd_force = force;
1005 if (sbi->ll_client_common_fill_super_succeeded) {
1006 /* Only if client_common_fill_super succeeded */
1007 client_common_put_super(sb);
1011 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1012 class_manual_cleanup(obd);
1014 if (sbi->ll_flags & LL_SBI_VERBOSE)
1015 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1018 class_del_profile(profilenm);
1021 lsi->lsi_llsbi = NULL;
1023 lustre_common_put_super(sb);
1025 cl_env_cache_purge(~0);
1027 module_put(THIS_MODULE);
1028 } /* client_put_super */
1030 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1032 struct inode *inode = NULL;
1034 /* NOTE: we depend on atomic igrab() -bzzz */
1035 lock_res_and_lock(lock);
1036 if (lock->l_resource->lr_lvb_inode) {
1037 struct ll_inode_info *lli;
1039 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1040 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1041 inode = igrab(lock->l_resource->lr_lvb_inode);
1043 inode = lock->l_resource->lr_lvb_inode;
1044 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1045 D_WARNING, lock, "lr_lvb_inode %p is bogus: magic %08x",
1046 lock->l_resource->lr_lvb_inode,
1047 lli->lli_inode_magic);
1051 unlock_res_and_lock(lock);
1055 void ll_dir_clear_lsm_md(struct inode *inode)
1057 struct ll_inode_info *lli = ll_i2info(inode);
1059 LASSERT(S_ISDIR(inode->i_mode));
1061 if (lli->lli_lsm_md) {
1062 lmv_free_memmd(lli->lli_lsm_md);
1063 lli->lli_lsm_md = NULL;
1067 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1068 const struct lu_fid *fid,
1069 struct lustre_md *md)
1071 struct ll_sb_info *sbi = ll_s2sbi(sb);
1072 struct mdt_body *body = md->body;
1073 struct inode *inode;
1076 ino = cl_fid_build_ino(fid, sbi->ll_flags & LL_SBI_32BIT_API);
1077 inode = iget_locked(sb, ino);
1079 CERROR("%s: failed get simple inode " DFID ": rc = -ENOENT\n",
1080 ll_get_fsname(sb, NULL, 0), PFID(fid));
1081 return ERR_PTR(-ENOENT);
1084 if (inode->i_state & I_NEW) {
1085 struct ll_inode_info *lli = ll_i2info(inode);
1086 struct lmv_stripe_md *lsm = md->lmv;
1088 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1089 (body->mbo_mode & S_IFMT);
1090 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode " DFID "\n",
1093 LTIME_S(inode->i_mtime) = 0;
1094 LTIME_S(inode->i_atime) = 0;
1095 LTIME_S(inode->i_ctime) = 0;
1098 inode->i_op = &ll_dir_inode_operations;
1099 inode->i_fop = &ll_dir_operations;
1100 lli->lli_fid = *fid;
1104 /* master object FID */
1105 lli->lli_pfid = body->mbo_fid1;
1106 CDEBUG(D_INODE, "lli %p slave " DFID " master " DFID "\n",
1107 lli, PFID(fid), PFID(&lli->lli_pfid));
1108 unlock_new_inode(inode);
1114 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1116 struct lmv_stripe_md *lsm = md->lmv;
1122 * XXX sigh, this lsm_root initialization should be in
1123 * LMV layer, but it needs ll_iget right now, so we
1124 * put this here right now.
1126 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1127 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1128 LASSERT(!lsm->lsm_md_oinfo[i].lmo_root);
1129 /* Unfortunately ll_iget will call ll_update_inode,
1130 * where the initialization of slave inode is slightly
1131 * different, so it reset lsm_md to NULL to avoid
1132 * initializing lsm for slave inode.
1134 /* For migrating inode, master stripe and master object will
1135 * be same, so we only need assign this inode
1137 if (lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION && !i)
1138 lsm->lsm_md_oinfo[i].lmo_root = inode;
1140 lsm->lsm_md_oinfo[i].lmo_root =
1141 ll_iget_anon_dir(inode->i_sb, fid, md);
1142 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1143 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1145 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1153 static inline int lli_lsm_md_eq(const struct lmv_stripe_md *lsm_md1,
1154 const struct lmv_stripe_md *lsm_md2)
1156 return lsm_md1->lsm_md_magic == lsm_md2->lsm_md_magic &&
1157 lsm_md1->lsm_md_stripe_count == lsm_md2->lsm_md_stripe_count &&
1158 lsm_md1->lsm_md_master_mdt_index ==
1159 lsm_md2->lsm_md_master_mdt_index &&
1160 lsm_md1->lsm_md_hash_type == lsm_md2->lsm_md_hash_type &&
1161 lsm_md1->lsm_md_layout_version ==
1162 lsm_md2->lsm_md_layout_version &&
1163 !strcmp(lsm_md1->lsm_md_pool_name,
1164 lsm_md2->lsm_md_pool_name);
1167 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1169 struct ll_inode_info *lli = ll_i2info(inode);
1170 struct lmv_stripe_md *lsm = md->lmv;
1173 LASSERT(S_ISDIR(inode->i_mode));
1174 CDEBUG(D_INODE, "update lsm %p of " DFID "\n", lli->lli_lsm_md,
1175 PFID(ll_inode2fid(inode)));
1177 /* no striped information from request. */
1179 if (!lli->lli_lsm_md) {
1181 } else if (lli->lli_lsm_md->lsm_md_hash_type &
1182 LMV_HASH_FLAG_MIGRATION) {
1184 * migration is done, the temporay MIGRATE layout has
1187 CDEBUG(D_INODE, DFID " finish migration.\n",
1188 PFID(ll_inode2fid(inode)));
1189 lmv_free_memmd(lli->lli_lsm_md);
1190 lli->lli_lsm_md = NULL;
1194 * The lustre_md from req does not include stripeEA,
1201 /* set the directory layout */
1202 if (!lli->lli_lsm_md) {
1203 struct cl_attr *attr;
1205 rc = ll_init_lsm_md(inode, md);
1210 * set lsm_md to NULL, so the following free lustre_md
1211 * will not free this lsm
1214 lli->lli_lsm_md = lsm;
1216 attr = kzalloc(sizeof(*attr), GFP_NOFS);
1220 /* validate the lsm */
1221 rc = md_merge_attr(ll_i2mdexp(inode), lsm, attr,
1222 ll_md_blocking_ast);
1228 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1229 md->body->mbo_nlink = attr->cat_nlink;
1230 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1231 md->body->mbo_size = attr->cat_size;
1232 if (md->body->mbo_valid & OBD_MD_FLATIME)
1233 md->body->mbo_atime = attr->cat_atime;
1234 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1235 md->body->mbo_ctime = attr->cat_ctime;
1236 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1237 md->body->mbo_mtime = attr->cat_mtime;
1241 CDEBUG(D_INODE, "Set lsm %p magic %x to " DFID "\n", lsm,
1242 lsm->lsm_md_magic, PFID(ll_inode2fid(inode)));
1246 /* Compare the old and new stripe information */
1247 if (!lsm_md_eq(lli->lli_lsm_md, lsm)) {
1248 struct lmv_stripe_md *old_lsm = lli->lli_lsm_md;
1251 CERROR("%s: inode " DFID "(%p)'s lmv layout mismatch (%p)/(%p) magic:0x%x/0x%x stripe count: %d/%d master_mdt: %d/%d hash_type:0x%x/0x%x layout: 0x%x/0x%x pool:%s/%s\n",
1252 ll_get_fsname(inode->i_sb, NULL, 0), PFID(&lli->lli_fid),
1253 inode, lsm, old_lsm,
1254 lsm->lsm_md_magic, old_lsm->lsm_md_magic,
1255 lsm->lsm_md_stripe_count,
1256 old_lsm->lsm_md_stripe_count,
1257 lsm->lsm_md_master_mdt_index,
1258 old_lsm->lsm_md_master_mdt_index,
1259 lsm->lsm_md_hash_type, old_lsm->lsm_md_hash_type,
1260 lsm->lsm_md_layout_version,
1261 old_lsm->lsm_md_layout_version,
1262 lsm->lsm_md_pool_name,
1263 old_lsm->lsm_md_pool_name);
1265 for (idx = 0; idx < old_lsm->lsm_md_stripe_count; idx++) {
1266 CERROR("%s: sub FIDs in old lsm idx %d, old: " DFID "\n",
1267 ll_get_fsname(inode->i_sb, NULL, 0), idx,
1268 PFID(&old_lsm->lsm_md_oinfo[idx].lmo_fid));
1271 for (idx = 0; idx < lsm->lsm_md_stripe_count; idx++) {
1272 CERROR("%s: sub FIDs in new lsm idx %d, new: " DFID "\n",
1273 ll_get_fsname(inode->i_sb, NULL, 0), idx,
1274 PFID(&lsm->lsm_md_oinfo[idx].lmo_fid));
1283 void ll_clear_inode(struct inode *inode)
1285 struct ll_inode_info *lli = ll_i2info(inode);
1286 struct ll_sb_info *sbi = ll_i2sbi(inode);
1288 CDEBUG(D_VFSTRACE, "VFS Op:inode=" DFID "(%p)\n",
1289 PFID(ll_inode2fid(inode)), inode);
1291 if (S_ISDIR(inode->i_mode)) {
1292 /* these should have been cleared in ll_file_release */
1293 LASSERT(!lli->lli_opendir_key);
1294 LASSERT(!lli->lli_sai);
1295 LASSERT(lli->lli_opendir_pid == 0);
1298 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1300 LASSERT(!lli->lli_open_fd_write_count);
1301 LASSERT(!lli->lli_open_fd_read_count);
1302 LASSERT(!lli->lli_open_fd_exec_count);
1304 if (lli->lli_mds_write_och)
1305 ll_md_real_close(inode, FMODE_WRITE);
1306 if (lli->lli_mds_exec_och)
1307 ll_md_real_close(inode, FMODE_EXEC);
1308 if (lli->lli_mds_read_och)
1309 ll_md_real_close(inode, FMODE_READ);
1311 if (S_ISLNK(inode->i_mode)) {
1312 kfree(lli->lli_symlink_name);
1313 lli->lli_symlink_name = NULL;
1316 ll_xattr_cache_destroy(inode);
1318 #ifdef CONFIG_FS_POSIX_ACL
1319 forget_all_cached_acls(inode);
1320 if (lli->lli_posix_acl) {
1321 posix_acl_release(lli->lli_posix_acl);
1322 lli->lli_posix_acl = NULL;
1325 lli->lli_inode_magic = LLI_INODE_DEAD;
1327 if (S_ISDIR(inode->i_mode))
1328 ll_dir_clear_lsm_md(inode);
1329 if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1330 LASSERT(list_empty(&lli->lli_agl_list));
1333 * XXX This has to be done before lsm is freed below, because
1334 * cl_object still uses inode lsm.
1336 cl_inode_fini(inode);
1339 #define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
1341 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1343 struct lustre_md md;
1344 struct inode *inode = d_inode(dentry);
1345 struct ll_sb_info *sbi = ll_i2sbi(inode);
1346 struct ptlrpc_request *request = NULL;
1349 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1350 LUSTRE_OPC_ANY, NULL);
1351 if (IS_ERR(op_data))
1352 return PTR_ERR(op_data);
1354 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1356 ptlrpc_req_finished(request);
1357 if (rc == -ENOENT) {
1359 /* Unlinked special device node? Or just a race?
1360 * Pretend we did everything.
1362 if (!S_ISREG(inode->i_mode) &&
1363 !S_ISDIR(inode->i_mode)) {
1364 ia_valid = op_data->op_attr.ia_valid;
1365 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1366 rc = simple_setattr(dentry, &op_data->op_attr);
1367 op_data->op_attr.ia_valid = ia_valid;
1369 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1370 CERROR("md_setattr fails: rc = %d\n", rc);
1375 rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
1376 sbi->ll_md_exp, &md);
1378 ptlrpc_req_finished(request);
1382 ia_valid = op_data->op_attr.ia_valid;
1383 /* inode size will be in cl_setattr_ost, can't do it now since dirty
1384 * cache is not cleared yet.
1386 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1387 if (S_ISREG(inode->i_mode))
1389 rc = simple_setattr(dentry, &op_data->op_attr);
1390 if (S_ISREG(inode->i_mode))
1391 inode_unlock(inode);
1392 op_data->op_attr.ia_valid = ia_valid;
1394 rc = ll_update_inode(inode, &md);
1395 ptlrpc_req_finished(request);
1400 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1401 * object(s) determine the file size and mtime. Otherwise, the MDS will
1402 * keep these values until such a time that objects are allocated for it.
1403 * We do the MDS operations first, as it is checking permissions for us.
1404 * We don't to the MDS RPC if there is nothing that we want to store there,
1405 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1406 * going to do an RPC anyways.
1408 * If we are doing a truncate, we will send the mtime and ctime updates
1409 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1410 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1413 * In case of HSMimport, we only set attr on MDS.
1415 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
1417 struct inode *inode = d_inode(dentry);
1418 struct ll_inode_info *lli = ll_i2info(inode);
1419 struct md_op_data *op_data = NULL;
1422 CDEBUG(D_VFSTRACE, "%s: setattr inode " DFID "(%p) from %llu to %llu, valid %x, hsm_import %d\n",
1423 ll_get_fsname(inode->i_sb, NULL, 0), PFID(&lli->lli_fid), inode,
1424 i_size_read(inode), attr->ia_size, attr->ia_valid, hsm_import);
1426 if (attr->ia_valid & ATTR_SIZE) {
1427 /* Check new size against VFS/VM file size limit and rlimit */
1428 rc = inode_newsize_ok(inode, attr->ia_size);
1432 /* The maximum Lustre file size is variable, based on the
1433 * OST maximum object size and number of stripes. This
1434 * needs another check in addition to the VFS check above.
1436 if (attr->ia_size > ll_file_maxbytes(inode)) {
1437 CDEBUG(D_INODE, "file " DFID " too large %llu > %llu\n",
1438 PFID(&lli->lli_fid), attr->ia_size,
1439 ll_file_maxbytes(inode));
1443 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1446 /* POSIX: check before ATTR_*TIME_SET set (from setattr_prepare) */
1447 if (attr->ia_valid & TIMES_SET_FLAGS) {
1448 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
1449 !capable(CFS_CAP_FOWNER))
1453 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1454 if (attr->ia_valid & ATTR_CTIME) {
1455 attr->ia_ctime = current_time(inode);
1456 attr->ia_valid |= ATTR_CTIME_SET;
1458 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
1459 (attr->ia_valid & ATTR_ATIME)) {
1460 attr->ia_atime = current_time(inode);
1461 attr->ia_valid |= ATTR_ATIME_SET;
1463 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
1464 (attr->ia_valid & ATTR_MTIME)) {
1465 attr->ia_mtime = current_time(inode);
1466 attr->ia_valid |= ATTR_MTIME_SET;
1469 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1470 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %llu\n",
1471 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1472 (s64)ktime_get_real_seconds());
1474 if (S_ISREG(inode->i_mode))
1475 inode_unlock(inode);
1478 * We always do an MDS RPC, even if we're only changing the size;
1479 * only the MDS knows whether truncate() should fail with -ETXTBUSY
1481 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
1487 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
1489 * If we are changing file size, file content is
1490 * modified, flag it.
1492 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1493 op_data->op_bias |= MDS_DATA_MODIFIED;
1494 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
1497 op_data->op_attr = *attr;
1499 rc = ll_md_setattr(dentry, op_data);
1503 if (!S_ISREG(inode->i_mode) || hsm_import) {
1508 if (attr->ia_valid & (ATTR_SIZE |
1509 ATTR_ATIME | ATTR_ATIME_SET |
1510 ATTR_MTIME | ATTR_MTIME_SET)) {
1511 /* For truncate and utimes sending attributes to OSTs, setting
1512 * mtime/atime to the past will be performed under PW [0:EOF]
1513 * extent lock (new_size:EOF for truncate). It may seem
1514 * excessive to send mtime/atime updates to OSTs when not
1515 * setting times to past, but it is necessary due to possible
1516 * time de-synchronization between MDT inode and OST objects
1518 rc = cl_setattr_ost(ll_i2info(inode)->lli_clob, attr, 0);
1522 * If the file was restored, it needs to set dirty flag.
1524 * We've already sent MDS_DATA_MODIFIED flag in
1525 * ll_md_setattr() for truncate. However, the MDT refuses to
1526 * set the HS_DIRTY flag on released files, so we have to set
1527 * it again if the file has been restored. Please check how
1528 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
1530 * Please notice that if the file is not released, the previous
1531 * MDS_DATA_MODIFIED has taken effect and usually
1532 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
1533 * This way we can save an RPC for common open + trunc
1536 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
1537 struct hsm_state_set hss = {
1538 .hss_valid = HSS_SETMASK,
1539 .hss_setmask = HS_DIRTY,
1543 rc2 = ll_hsm_state_set(inode, &hss);
1545 * truncate and write can happen at the same time, so that
1546 * the file can be set modified even though the file is not
1547 * restored from released state, and ll_hsm_state_set() is
1548 * not applicable for the file, and rc2 < 0 is normal in this
1552 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
1553 PFID(ll_inode2fid(inode)), rc2);
1558 ll_finish_md_op_data(op_data);
1560 if (S_ISREG(inode->i_mode)) {
1562 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
1563 inode_dio_wait(inode);
1566 ll_stats_ops_tally(ll_i2sbi(inode), (attr->ia_valid & ATTR_SIZE) ?
1567 LPROC_LL_TRUNC : LPROC_LL_SETATTR, 1);
1572 int ll_setattr(struct dentry *de, struct iattr *attr)
1574 int mode = d_inode(de)->i_mode;
1576 if ((attr->ia_valid & (ATTR_CTIME | ATTR_SIZE | ATTR_MODE)) ==
1577 (ATTR_CTIME | ATTR_SIZE | ATTR_MODE))
1578 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1580 if (((attr->ia_valid & (ATTR_MODE | ATTR_FORCE | ATTR_SIZE)) ==
1581 (ATTR_SIZE | ATTR_MODE)) &&
1582 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
1583 (((mode & (S_ISGID | 0010)) == (S_ISGID | 0010)) &&
1584 !(attr->ia_mode & S_ISGID))))
1585 attr->ia_valid |= ATTR_FORCE;
1587 if ((attr->ia_valid & ATTR_MODE) &&
1589 !(attr->ia_mode & S_ISUID) &&
1590 !(attr->ia_valid & ATTR_KILL_SUID))
1591 attr->ia_valid |= ATTR_KILL_SUID;
1593 if ((attr->ia_valid & ATTR_MODE) &&
1594 ((mode & (S_ISGID | 0010)) == (S_ISGID | 0010)) &&
1595 !(attr->ia_mode & S_ISGID) &&
1596 !(attr->ia_valid & ATTR_KILL_SGID))
1597 attr->ia_valid |= ATTR_KILL_SGID;
1599 return ll_setattr_raw(de, attr, false);
1602 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1603 __u64 max_age, __u32 flags)
1605 struct ll_sb_info *sbi = ll_s2sbi(sb);
1606 struct obd_statfs obd_osfs;
1609 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
1611 CERROR("md_statfs fails: rc = %d\n", rc);
1615 osfs->os_type = sb->s_magic;
1617 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
1618 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,
1621 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
1622 flags |= OBD_STATFS_NODELAY;
1624 rc = obd_statfs_rqset(sbi->ll_dt_exp, &obd_osfs, max_age, flags);
1626 CERROR("obd_statfs fails: rc = %d\n", rc);
1630 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
1631 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1634 osfs->os_bsize = obd_osfs.os_bsize;
1635 osfs->os_blocks = obd_osfs.os_blocks;
1636 osfs->os_bfree = obd_osfs.os_bfree;
1637 osfs->os_bavail = obd_osfs.os_bavail;
1639 /* If we don't have as many objects free on the OST as inodes
1640 * on the MDS, we reduce the total number of inodes to
1641 * compensate, so that the "inodes in use" number is correct.
1643 if (obd_osfs.os_ffree < osfs->os_ffree) {
1644 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1646 osfs->os_ffree = obd_osfs.os_ffree;
1652 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1654 struct super_block *sb = de->d_sb;
1655 struct obd_statfs osfs;
1658 CDEBUG(D_VFSTRACE, "VFS Op: at %llu jiffies\n", get_jiffies_64());
1659 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1);
1661 /* Some amount of caching on the client is allowed */
1662 rc = ll_statfs_internal(sb, &osfs,
1663 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1668 statfs_unpack(sfs, &osfs);
1670 /* We need to downshift for all 32-bit kernels, because we can't
1671 * tell if the kernel is being called via sys_statfs64() or not.
1672 * Stop before overflowing f_bsize - in which case it is better
1673 * to just risk EOVERFLOW if caller is using old sys_statfs().
1675 if (sizeof(long) < 8) {
1676 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1679 osfs.os_blocks >>= 1;
1680 osfs.os_bfree >>= 1;
1681 osfs.os_bavail >>= 1;
1685 sfs->f_blocks = osfs.os_blocks;
1686 sfs->f_bfree = osfs.os_bfree;
1687 sfs->f_bavail = osfs.os_bavail;
1688 sfs->f_fsid = ll_s2sbi(sb)->ll_fsid;
1692 void ll_inode_size_lock(struct inode *inode)
1694 struct ll_inode_info *lli;
1696 LASSERT(!S_ISDIR(inode->i_mode));
1698 lli = ll_i2info(inode);
1699 mutex_lock(&lli->lli_size_mutex);
1702 void ll_inode_size_unlock(struct inode *inode)
1704 struct ll_inode_info *lli;
1706 lli = ll_i2info(inode);
1707 mutex_unlock(&lli->lli_size_mutex);
1710 int ll_update_inode(struct inode *inode, struct lustre_md *md)
1712 struct ll_inode_info *lli = ll_i2info(inode);
1713 struct mdt_body *body = md->body;
1714 struct ll_sb_info *sbi = ll_i2sbi(inode);
1716 if (body->mbo_valid & OBD_MD_FLEASIZE)
1717 cl_file_inode_init(inode, md);
1719 if (S_ISDIR(inode->i_mode)) {
1722 rc = ll_update_lsm_md(inode, md);
1727 #ifdef CONFIG_FS_POSIX_ACL
1728 if (body->mbo_valid & OBD_MD_FLACL) {
1729 spin_lock(&lli->lli_lock);
1730 if (lli->lli_posix_acl)
1731 posix_acl_release(lli->lli_posix_acl);
1732 lli->lli_posix_acl = md->posix_acl;
1733 spin_unlock(&lli->lli_lock);
1736 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1,
1737 sbi->ll_flags & LL_SBI_32BIT_API);
1738 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
1740 if (body->mbo_valid & OBD_MD_FLATIME) {
1741 if (body->mbo_atime > LTIME_S(inode->i_atime))
1742 LTIME_S(inode->i_atime) = body->mbo_atime;
1743 lli->lli_atime = body->mbo_atime;
1745 if (body->mbo_valid & OBD_MD_FLMTIME) {
1746 if (body->mbo_mtime > LTIME_S(inode->i_mtime)) {
1747 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %llu\n",
1748 inode->i_ino, LTIME_S(inode->i_mtime),
1750 LTIME_S(inode->i_mtime) = body->mbo_mtime;
1752 lli->lli_mtime = body->mbo_mtime;
1754 if (body->mbo_valid & OBD_MD_FLCTIME) {
1755 if (body->mbo_ctime > LTIME_S(inode->i_ctime))
1756 LTIME_S(inode->i_ctime) = body->mbo_ctime;
1757 lli->lli_ctime = body->mbo_ctime;
1759 if (body->mbo_valid & OBD_MD_FLMODE)
1760 inode->i_mode = (inode->i_mode & S_IFMT) |
1761 (body->mbo_mode & ~S_IFMT);
1762 if (body->mbo_valid & OBD_MD_FLTYPE)
1763 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1764 (body->mbo_mode & S_IFMT);
1765 LASSERT(inode->i_mode != 0);
1766 if (S_ISREG(inode->i_mode))
1767 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS + 1,
1768 LL_MAX_BLKSIZE_BITS);
1770 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
1771 if (body->mbo_valid & OBD_MD_FLUID)
1772 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
1773 if (body->mbo_valid & OBD_MD_FLGID)
1774 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
1775 if (body->mbo_valid & OBD_MD_FLFLAGS)
1776 inode->i_flags = ll_ext_to_inode_flags(body->mbo_flags);
1777 if (body->mbo_valid & OBD_MD_FLNLINK)
1778 set_nlink(inode, body->mbo_nlink);
1779 if (body->mbo_valid & OBD_MD_FLRDEV)
1780 inode->i_rdev = old_decode_dev(body->mbo_rdev);
1782 if (body->mbo_valid & OBD_MD_FLID) {
1783 /* FID shouldn't be changed! */
1784 if (fid_is_sane(&lli->lli_fid)) {
1785 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
1786 "Trying to change FID " DFID " to the " DFID ", inode " DFID "(%p)\n",
1787 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
1788 PFID(ll_inode2fid(inode)), inode);
1790 lli->lli_fid = body->mbo_fid1;
1794 LASSERT(fid_seq(&lli->lli_fid) != 0);
1796 if (body->mbo_valid & OBD_MD_FLSIZE) {
1797 i_size_write(inode, body->mbo_size);
1799 CDEBUG(D_VFSTRACE, "inode=" DFID ", updating i_size %llu\n",
1800 PFID(ll_inode2fid(inode)),
1801 (unsigned long long)body->mbo_size);
1803 if (body->mbo_valid & OBD_MD_FLBLOCKS)
1804 inode->i_blocks = body->mbo_blocks;
1807 if (body->mbo_valid & OBD_MD_TSTATE) {
1808 if (body->mbo_t_state & MS_RESTORE)
1809 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
1815 int ll_read_inode2(struct inode *inode, void *opaque)
1817 struct lustre_md *md = opaque;
1818 struct ll_inode_info *lli = ll_i2info(inode);
1821 CDEBUG(D_VFSTRACE, "VFS Op:inode=" DFID "(%p)\n",
1822 PFID(&lli->lli_fid), inode);
1824 /* Core attributes from the MDS first. This is a new inode, and
1825 * the VFS doesn't zero times in the core inode so we have to do
1826 * it ourselves. They will be overwritten by either MDS or OST
1827 * attributes - we just need to make sure they aren't newer.
1829 LTIME_S(inode->i_mtime) = 0;
1830 LTIME_S(inode->i_atime) = 0;
1831 LTIME_S(inode->i_ctime) = 0;
1833 rc = ll_update_inode(inode, md);
1837 /* OIDEBUG(inode); */
1839 if (S_ISREG(inode->i_mode)) {
1840 struct ll_sb_info *sbi = ll_i2sbi(inode);
1842 inode->i_op = &ll_file_inode_operations;
1843 inode->i_fop = sbi->ll_fop;
1844 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
1845 } else if (S_ISDIR(inode->i_mode)) {
1846 inode->i_op = &ll_dir_inode_operations;
1847 inode->i_fop = &ll_dir_operations;
1848 } else if (S_ISLNK(inode->i_mode)) {
1849 inode->i_op = &ll_fast_symlink_inode_operations;
1851 inode->i_op = &ll_special_inode_operations;
1853 init_special_inode(inode, inode->i_mode,
1860 void ll_delete_inode(struct inode *inode)
1862 struct ll_inode_info *lli = ll_i2info(inode);
1864 if (S_ISREG(inode->i_mode) && lli->lli_clob)
1865 /* discard all dirty pages before truncating them, required by
1866 * osc_extent implementation at LU-1030.
1868 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF,
1871 truncate_inode_pages_final(&inode->i_data);
1873 LASSERTF(!inode->i_data.nrpages,
1874 "inode=" DFID "(%p) nrpages=%lu, see http://jira.whamcloud.com/browse/LU-118\n",
1875 PFID(ll_inode2fid(inode)), inode, inode->i_data.nrpages);
1877 ll_clear_inode(inode);
1881 int ll_iocontrol(struct inode *inode, struct file *file,
1882 unsigned int cmd, unsigned long arg)
1884 struct ll_sb_info *sbi = ll_i2sbi(inode);
1885 struct ptlrpc_request *req = NULL;
1889 case FSFILT_IOC_GETFLAGS: {
1890 struct mdt_body *body;
1891 struct md_op_data *op_data;
1893 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
1894 0, 0, LUSTRE_OPC_ANY,
1896 if (IS_ERR(op_data))
1897 return PTR_ERR(op_data);
1899 op_data->op_valid = OBD_MD_FLFLAGS;
1900 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
1901 ll_finish_md_op_data(op_data);
1903 CERROR("%s: failure inode " DFID ": rc = %d\n",
1904 sbi->ll_md_exp->exp_obd->obd_name,
1905 PFID(ll_inode2fid(inode)), rc);
1909 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1911 flags = body->mbo_flags;
1913 ptlrpc_req_finished(req);
1915 return put_user(flags, (int __user *)arg);
1917 case FSFILT_IOC_SETFLAGS: {
1918 struct md_op_data *op_data;
1919 struct cl_object *obj;
1922 if (get_user(flags, (int __user *)arg))
1925 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
1926 LUSTRE_OPC_ANY, NULL);
1927 if (IS_ERR(op_data))
1928 return PTR_ERR(op_data);
1930 op_data->op_attr_flags = flags;
1931 op_data->op_attr.ia_valid |= ATTR_ATTR_FLAG;
1932 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
1933 ll_finish_md_op_data(op_data);
1934 ptlrpc_req_finished(req);
1938 inode->i_flags = ll_ext_to_inode_flags(flags);
1940 obj = ll_i2info(inode)->lli_clob;
1944 attr = kzalloc(sizeof(*attr), GFP_NOFS);
1948 attr->ia_valid = ATTR_ATTR_FLAG;
1949 rc = cl_setattr_ost(obj, attr, flags);
1960 int ll_flush_ctx(struct inode *inode)
1962 struct ll_sb_info *sbi = ll_i2sbi(inode);
1964 CDEBUG(D_SEC, "flush context for user %d\n",
1965 from_kuid(&init_user_ns, current_uid()));
1967 obd_set_info_async(NULL, sbi->ll_md_exp,
1968 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
1970 obd_set_info_async(NULL, sbi->ll_dt_exp,
1971 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
1976 /* umount -f client means force down, don't save state */
1977 void ll_umount_begin(struct super_block *sb)
1979 struct ll_sb_info *sbi = ll_s2sbi(sb);
1980 struct obd_device *obd;
1981 struct obd_ioctl_data *ioc_data;
1982 wait_queue_head_t waitq;
1983 struct l_wait_info lwi;
1985 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
1986 sb->s_count, atomic_read(&sb->s_active));
1988 obd = class_exp2obd(sbi->ll_md_exp);
1990 CERROR("Invalid MDC connection handle %#llx\n",
1991 sbi->ll_md_exp->exp_handle.h_cookie);
1996 obd = class_exp2obd(sbi->ll_dt_exp);
1998 CERROR("Invalid LOV connection handle %#llx\n",
1999 sbi->ll_dt_exp->exp_handle.h_cookie);
2004 ioc_data = kzalloc(sizeof(*ioc_data), GFP_NOFS);
2006 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2007 sizeof(*ioc_data), ioc_data, NULL);
2009 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2010 sizeof(*ioc_data), ioc_data, NULL);
2015 /* Really, we'd like to wait until there are no requests outstanding,
2016 * and then continue. For now, we just periodically checking for vfs
2017 * to decrement mnt_cnt and hope to finish it within 10sec.
2019 init_waitqueue_head(&waitq);
2020 lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(10),
2021 cfs_time_seconds(1), NULL, NULL);
2022 l_wait_event(waitq, may_umount(sbi->ll_mnt.mnt), &lwi);
2027 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2029 struct ll_sb_info *sbi = ll_s2sbi(sb);
2030 char *profilenm = get_profile_name(sb);
2034 if ((bool)(*flags & MS_RDONLY) != sb_rdonly(sb)) {
2035 read_only = *flags & MS_RDONLY;
2036 err = obd_set_info_async(NULL, sbi->ll_md_exp,
2037 sizeof(KEY_READ_ONLY),
2038 KEY_READ_ONLY, sizeof(read_only),
2041 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2042 profilenm, read_only ?
2043 "read-only" : "read-write", err);
2048 sb->s_flags |= MS_RDONLY;
2050 sb->s_flags &= ~MS_RDONLY;
2052 if (sbi->ll_flags & LL_SBI_VERBOSE)
2053 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
2054 read_only ? "read-only" : "read-write");
2060 * Cleanup the open handle that is cached on MDT-side.
2062 * For open case, the client side open handling thread may hit error
2063 * after the MDT grant the open. Under such case, the client should
2064 * send close RPC to the MDT as cleanup; otherwise, the open handle
2065 * on the MDT will be leaked there until the client umount or evicted.
2067 * In further, if someone unlinked the file, because the open handle
2068 * holds the reference on such file/object, then it will block the
2069 * subsequent threads that want to locate such object via FID.
2071 * \param[in] sb super block for this file-system
2072 * \param[in] open_req pointer to the original open request
2074 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
2076 struct mdt_body *body;
2077 struct md_op_data *op_data;
2078 struct ptlrpc_request *close_req = NULL;
2079 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
2081 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
2082 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
2086 op_data->op_fid1 = body->mbo_fid1;
2087 op_data->op_handle = body->mbo_handle;
2088 op_data->op_mod_time = get_seconds();
2089 md_close(exp, op_data, NULL, &close_req);
2090 ptlrpc_req_finished(close_req);
2091 ll_finish_md_op_data(op_data);
2094 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
2095 struct super_block *sb, struct lookup_intent *it)
2097 struct ll_sb_info *sbi = NULL;
2098 struct lustre_md md = { NULL };
2101 LASSERT(*inode || sb);
2102 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2103 rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
2104 sbi->ll_md_exp, &md);
2109 rc = ll_update_inode(*inode, &md);
2116 * At this point server returns to client's same fid as client
2117 * generated for creating. So using ->fid1 is okay here.
2119 if (!fid_is_sane(&md.body->mbo_fid1)) {
2120 CERROR("%s: Fid is insane " DFID "\n",
2121 ll_get_fsname(sb, NULL, 0),
2122 PFID(&md.body->mbo_fid1));
2127 *inode = ll_iget(sb, cl_fid_build_ino(&md.body->mbo_fid1,
2128 sbi->ll_flags & LL_SBI_32BIT_API),
2130 if (IS_ERR(*inode)) {
2131 #ifdef CONFIG_FS_POSIX_ACL
2133 posix_acl_release(md.posix_acl);
2134 md.posix_acl = NULL;
2138 CERROR("new_inode -fatal: rc %d\n", rc);
2143 /* Handling piggyback layout lock.
2144 * Layout lock can be piggybacked by getattr and open request.
2145 * The lsm can be applied to inode only if it comes with a layout lock
2146 * otherwise correct layout may be overwritten, for example:
2147 * 1. proc1: mdt returns a lsm but not granting layout
2148 * 2. layout was changed by another client
2149 * 3. proc2: refresh layout and layout lock granted
2150 * 4. proc1: to apply a stale layout
2152 if (it && it->it_lock_mode != 0) {
2153 struct lustre_handle lockh;
2154 struct ldlm_lock *lock;
2156 lockh.cookie = it->it_lock_handle;
2157 lock = ldlm_handle2lock(&lockh);
2159 if (ldlm_has_layout(lock)) {
2160 struct cl_object_conf conf;
2162 memset(&conf, 0, sizeof(conf));
2163 conf.coc_opc = OBJECT_CONF_SET;
2164 conf.coc_inode = *inode;
2165 conf.coc_lock = lock;
2166 conf.u.coc_layout = md.layout;
2167 (void)ll_layout_conf(*inode, &conf);
2169 LDLM_LOCK_PUT(lock);
2173 md_free_lustre_md(sbi->ll_md_exp, &md);
2175 if (rc != 0 && it && it->it_op & IT_OPEN)
2176 ll_open_cleanup(sb ? sb : (*inode)->i_sb, req);
2181 int ll_obd_statfs(struct inode *inode, void __user *arg)
2183 struct ll_sb_info *sbi = NULL;
2184 struct obd_export *exp;
2186 struct obd_ioctl_data *data = NULL;
2195 sbi = ll_i2sbi(inode);
2201 rc = obd_ioctl_getdata(&buf, &len, arg);
2206 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2207 !data->ioc_pbuf1 || !data->ioc_pbuf2) {
2212 if (data->ioc_inllen1 != sizeof(__u32) ||
2213 data->ioc_inllen2 != sizeof(__u32) ||
2214 data->ioc_plen1 != sizeof(struct obd_statfs) ||
2215 data->ioc_plen2 != sizeof(struct obd_uuid)) {
2220 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2221 if (type & LL_STATFS_LMV) {
2222 exp = sbi->ll_md_exp;
2223 } else if (type & LL_STATFS_LOV) {
2224 exp = sbi->ll_dt_exp;
2230 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL);
2238 int ll_process_config(struct lustre_cfg *lcfg)
2242 struct lprocfs_static_vars lvars;
2246 lprocfs_llite_init_vars(&lvars);
2248 /* The instance name contains the sb: lustre-client-aacfe000 */
2249 ptr = strrchr(lustre_cfg_string(lcfg, 0), '-');
2250 if (!ptr || !*(++ptr))
2252 rc = kstrtoul(ptr, 16, &x);
2256 /* This better be a real Lustre superblock! */
2257 LASSERT(s2lsi((struct super_block *)sb)->lsi_lmd->lmd_magic == LMD_MAGIC);
2259 /* Note we have not called client_common_fill_super yet, so
2260 * proc fns must be able to handle that!
2262 rc = class_process_proc_param(PARAM_LLITE, lvars.obd_vars,
2269 /* this function prepares md_op_data hint for passing ot down to MD stack. */
2270 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
2271 struct inode *i1, struct inode *i2,
2272 const char *name, size_t namelen,
2273 u32 mode, __u32 opc, void *data)
2276 /* Do not reuse namelen for something else. */
2278 return ERR_PTR(-EINVAL);
2280 if (namelen > ll_i2sbi(i1)->ll_namelen)
2281 return ERR_PTR(-ENAMETOOLONG);
2283 if (!lu_name_is_valid_2(name, namelen))
2284 return ERR_PTR(-EINVAL);
2288 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
2291 return ERR_PTR(-ENOMEM);
2293 ll_i2gids(op_data->op_suppgids, i1, i2);
2294 op_data->op_fid1 = *ll_inode2fid(i1);
2295 op_data->op_default_stripe_offset = -1;
2296 if (S_ISDIR(i1->i_mode)) {
2297 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
2298 if (opc == LUSTRE_OPC_MKDIR)
2299 op_data->op_default_stripe_offset =
2300 ll_i2info(i1)->lli_def_stripe_offset;
2304 op_data->op_fid2 = *ll_inode2fid(i2);
2305 if (S_ISDIR(i2->i_mode))
2306 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
2308 fid_zero(&op_data->op_fid2);
2311 if (ll_i2sbi(i1)->ll_flags & LL_SBI_64BIT_HASH)
2312 op_data->op_cli_flags |= CLI_HASH64;
2314 if (ll_need_32bit_api(ll_i2sbi(i1)))
2315 op_data->op_cli_flags |= CLI_API32;
2317 op_data->op_name = name;
2318 op_data->op_namelen = namelen;
2319 op_data->op_mode = mode;
2320 op_data->op_mod_time = ktime_get_real_seconds();
2321 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2322 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2323 op_data->op_cap = cfs_curproc_cap_pack();
2324 if ((opc == LUSTRE_OPC_CREATE) && name &&
2325 filename_is_volatile(name, namelen, &op_data->op_mds))
2326 op_data->op_bias |= MDS_CREATE_VOLATILE;
2328 op_data->op_mds = 0;
2329 op_data->op_data = data;
2334 void ll_finish_md_op_data(struct md_op_data *op_data)
2339 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
2341 struct ll_sb_info *sbi;
2343 LASSERT(seq && dentry);
2344 sbi = ll_s2sbi(dentry->d_sb);
2346 if (sbi->ll_flags & LL_SBI_NOLCK)
2347 seq_puts(seq, ",nolock");
2349 if (sbi->ll_flags & LL_SBI_FLOCK)
2350 seq_puts(seq, ",flock");
2352 if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
2353 seq_puts(seq, ",localflock");
2355 if (sbi->ll_flags & LL_SBI_USER_XATTR)
2356 seq_puts(seq, ",user_xattr");
2358 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
2359 seq_puts(seq, ",lazystatfs");
2361 if (sbi->ll_flags & LL_SBI_USER_FID2PATH)
2362 seq_puts(seq, ",user_fid2path");
2364 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
2365 seq_puts(seq, ",always_ping");
2371 * Get obd name by cmd, and copy out to user space
2373 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
2375 struct ll_sb_info *sbi = ll_i2sbi(inode);
2376 struct obd_device *obd;
2378 if (cmd == OBD_IOC_GETDTNAME)
2379 obd = class_exp2obd(sbi->ll_dt_exp);
2380 else if (cmd == OBD_IOC_GETMDNAME)
2381 obd = class_exp2obd(sbi->ll_md_exp);
2388 if (copy_to_user((void __user *)arg, obd->obd_name,
2389 strlen(obd->obd_name) + 1))
2396 * Get lustre file system name by \a sbi. If \a buf is provided(non-NULL), the
2397 * fsname will be returned in this buffer; otherwise, a static buffer will be
2398 * used to store the fsname and returned to caller.
2400 char *ll_get_fsname(struct super_block *sb, char *buf, int buflen)
2402 static char fsname_static[MTI_NAME_MAXLEN];
2403 struct lustre_sb_info *lsi = s2lsi(sb);
2408 /* this means the caller wants to use static buffer
2409 * and it doesn't care about race. Usually this is
2410 * in error reporting path
2412 buf = fsname_static;
2413 buflen = sizeof(fsname_static);
2416 len = strlen(lsi->lsi_lmd->lmd_profile);
2417 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
2418 if (ptr && (strcmp(ptr, "-client") == 0))
2421 if (unlikely(len >= buflen))
2423 strncpy(buf, lsi->lsi_lmd->lmd_profile, len);
2429 void ll_dirty_page_discard_warn(struct page *page, int ioret)
2431 char *buf, *path = NULL;
2432 struct dentry *dentry = NULL;
2433 struct vvp_object *obj = cl_inode2vvp(page->mapping->host);
2435 /* this can be called inside spin lock so use GFP_ATOMIC. */
2436 buf = (char *)__get_free_page(GFP_ATOMIC);
2438 dentry = d_find_alias(page->mapping->host);
2440 path = dentry_path_raw(dentry, buf, PAGE_SIZE);
2444 "%s: dirty page discard: %s/fid: " DFID "/%s may get corrupted (rc %d)\n",
2445 ll_get_fsname(page->mapping->host->i_sb, NULL, 0),
2446 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
2447 PFID(&obj->vob_header.coh_lu.loh_fid),
2448 (path && !IS_ERR(path)) ? path : "", ioret);
2454 free_page((unsigned long)buf);
2457 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
2458 struct lov_user_md **kbuf)
2460 struct lov_user_md lum;
2463 if (copy_from_user(&lum, md, sizeof(lum))) {
2468 lum_size = ll_lov_user_md_size(&lum);
2472 *kbuf = kzalloc(lum_size, GFP_NOFS);
2478 if (copy_from_user(*kbuf, md, lum_size) != 0) {
2488 * Compute llite root squash state after a change of root squash
2489 * configuration setting or add/remove of a lnet nid
2491 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
2493 struct root_squash_info *squash = &sbi->ll_squash;
2494 struct lnet_process_id id;
2498 /* Update norootsquash flag */
2499 down_write(&squash->rsi_sem);
2500 if (list_empty(&squash->rsi_nosquash_nids)) {
2501 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
2504 * Do not apply root squash as soon as one of our NIDs is
2505 * in the nosquash_nids list
2510 while (LNetGetId(i++, &id) != -ENOENT) {
2511 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
2513 if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) {
2519 sbi->ll_flags |= LL_SBI_NOROOTSQUASH;
2521 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
2523 up_write(&squash->rsi_sem);
2527 * Parse linkea content to extract information about a given hardlink
2529 * \param[in] ldata - Initialized linkea data
2530 * \param[in] linkno - Link identifier
2531 * \param[out] parent_fid - The entry's parent FID
2532 * \param[in] size - Entry name destination buffer
2534 * \retval 0 on success
2535 * \retval Appropriate negative error code on failure
2537 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
2538 struct lu_fid *parent_fid, struct lu_name *ln)
2543 rc = linkea_init_with_rec(ldata);
2547 if (linkno >= ldata->ld_leh->leh_reccount)
2548 /* beyond last link */
2551 linkea_first_entry(ldata);
2552 for (idx = 0; ldata->ld_lee; idx++) {
2553 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
2558 linkea_next_entry(ldata);
2568 * Get parent FID and name of an identified link. Operation is performed for
2569 * a given link number, letting the caller iterate over linkno to list one or
2570 * all links of an entry.
2572 * \param[in] file - File descriptor against which to perform the operation
2573 * \param[in,out] arg - User-filled structure containing the linkno to operate
2574 * on and the available size. It is eventually filled with
2575 * the requested information or left untouched on error
2577 * \retval - 0 on success
2578 * \retval - Appropriate negative error code on failure
2580 int ll_getparent(struct file *file, struct getparent __user *arg)
2582 struct inode *inode = file_inode(file);
2583 struct linkea_data *ldata;
2584 struct lu_fid parent_fid;
2585 struct lu_buf buf = {
2594 if (!capable(CFS_CAP_DAC_READ_SEARCH) &&
2595 !(ll_i2sbi(inode)->ll_flags & LL_SBI_USER_FID2PATH))
2598 if (get_user(name_size, &arg->gp_name_size))
2601 if (get_user(linkno, &arg->gp_linkno))
2604 if (name_size > PATH_MAX)
2607 ldata = kzalloc(sizeof(*ldata), GFP_NOFS);
2611 rc = linkea_data_new(ldata, &buf);
2615 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
2616 buf.lb_len, OBD_MD_FLXATTR);
2620 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
2624 if (ln.ln_namelen >= name_size) {
2629 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid))) {
2634 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen)) {
2639 if (put_user('\0', arg->gp_name + ln.ln_namelen)) {