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, 2017, 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/random.h>
41 #include <linux/statfs.h>
42 #include <linux/time.h>
43 #include <linux/types.h>
44 #include <libcfs/linux/linux-uuid.h>
45 #include <linux/version.h>
47 #include <linux/user_namespace.h>
48 #ifdef HAVE_UIDGID_HEADER
49 # include <linux/uidgid.h>
51 #include <linux/security.h>
53 #include <uapi/linux/lustre/lustre_ioctl.h>
54 #include <lustre_ha.h>
55 #include <lustre_dlm.h>
56 #include <lprocfs_status.h>
57 #include <lustre_disk.h>
58 #include <uapi/linux/lustre/lustre_param.h>
59 #include <lustre_log.h>
60 #include <cl_object.h>
61 #include <obd_cksum.h>
62 #include "llite_internal.h"
64 struct kmem_cache *ll_file_data_slab;
67 #define log2(n) ffz(~(n))
70 static struct ll_sb_info *ll_init_sbi(void)
72 struct ll_sb_info *sbi = NULL;
74 unsigned long lru_page_max;
83 spin_lock_init(&sbi->ll_lock);
84 mutex_init(&sbi->ll_lco.lco_lock);
85 spin_lock_init(&sbi->ll_pp_extent_lock);
86 spin_lock_init(&sbi->ll_process_lock);
87 sbi->ll_rw_stats_on = 0;
90 pages = si.totalram - si.totalhigh;
91 lru_page_max = pages / 2;
93 /* initialize ll_cache data */
94 sbi->ll_cache = cl_cache_init(lru_page_max);
95 if (sbi->ll_cache == NULL) {
96 OBD_FREE(sbi, sizeof(*sbi));
100 sbi->ll_ra_info.ra_max_pages_per_file = min(pages / 32,
101 SBI_DEFAULT_READAHEAD_MAX);
102 sbi->ll_ra_info.ra_max_pages = sbi->ll_ra_info.ra_max_pages_per_file;
103 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
105 sbi->ll_flags |= LL_SBI_VERBOSE;
106 #ifdef ENABLE_CHECKSUM
107 sbi->ll_flags |= LL_SBI_CHECKSUM;
110 sbi->ll_flags |= LL_SBI_FLOCK;
113 #ifdef HAVE_LRU_RESIZE_SUPPORT
114 sbi->ll_flags |= LL_SBI_LRU_RESIZE;
116 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
118 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
119 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
121 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
125 /* metadata statahead is enabled by default */
126 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
127 sbi->ll_sa_max = LL_SA_RPC_DEF;
128 atomic_set(&sbi->ll_sa_total, 0);
129 atomic_set(&sbi->ll_sa_wrong, 0);
130 atomic_set(&sbi->ll_sa_running, 0);
131 atomic_set(&sbi->ll_agl_total, 0);
132 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
133 sbi->ll_flags |= LL_SBI_FAST_READ;
134 sbi->ll_flags |= LL_SBI_TINY_WRITE;
137 sbi->ll_squash.rsi_uid = 0;
138 sbi->ll_squash.rsi_gid = 0;
139 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
140 init_rwsem(&sbi->ll_squash.rsi_sem);
141 pcc_super_init(&sbi->ll_pcc_super);
143 /* Per-filesystem file heat */
144 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
145 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
149 static void ll_free_sbi(struct super_block *sb)
151 struct ll_sb_info *sbi = ll_s2sbi(sb);
155 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
156 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
157 if (sbi->ll_cache != NULL) {
158 cl_cache_decref(sbi->ll_cache);
159 sbi->ll_cache = NULL;
161 pcc_super_fini(&sbi->ll_pcc_super);
162 OBD_FREE(sbi, sizeof(*sbi));
167 static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
168 struct vfsmount *mnt)
170 struct inode *root = NULL;
171 struct ll_sb_info *sbi = ll_s2sbi(sb);
172 struct obd_statfs *osfs = NULL;
173 struct ptlrpc_request *request = NULL;
174 struct obd_connect_data *data = NULL;
175 struct obd_uuid *uuid;
176 struct md_op_data *op_data;
177 struct lustre_md lmd;
179 int size, err, checksum;
182 sbi->ll_md_obd = class_name2obd(md);
183 if (!sbi->ll_md_obd) {
184 CERROR("MD %s: not setup or attached\n", md);
198 /* pass client page size via ocd_grant_blkbits, the server should report
199 * back its backend blocksize for grant calculation purpose */
200 data->ocd_grant_blkbits = PAGE_SHIFT;
202 /* indicate MDT features supported by this client */
203 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
204 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
205 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
206 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
207 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
208 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
209 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
210 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
211 OBD_CONNECT_64BITHASH |
212 OBD_CONNECT_EINPROGRESS |
213 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
214 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
215 OBD_CONNECT_MAX_EASIZE |
216 OBD_CONNECT_FLOCK_DEAD |
217 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
218 OBD_CONNECT_OPEN_BY_FID |
219 OBD_CONNECT_DIR_STRIPE |
220 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
221 OBD_CONNECT_SUBTREE |
222 OBD_CONNECT_MULTIMODRPCS |
223 OBD_CONNECT_GRANT_PARAM |
224 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
226 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
227 OBD_CONNECT2_SUM_STATFS |
228 OBD_CONNECT2_OVERSTRIPING |
230 OBD_CONNECT2_LOCK_CONVERT |
231 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
233 OBD_CONNECT2_ASYNC_DISCARD |
236 #ifdef HAVE_LRU_RESIZE_SUPPORT
237 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
238 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
240 #ifdef CONFIG_FS_POSIX_ACL
241 data->ocd_connect_flags |= OBD_CONNECT_ACL | OBD_CONNECT_UMASK |
242 OBD_CONNECT_LARGE_ACL;
245 data->ocd_cksum_types = obd_cksum_types_supported_client();
247 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
248 /* flag mdc connection as lightweight, only used for test
249 * purpose, use with care */
250 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
252 data->ocd_ibits_known = MDS_INODELOCK_FULL;
253 data->ocd_version = LUSTRE_VERSION_CODE;
255 if (sb->s_flags & MS_RDONLY)
256 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
257 if (sbi->ll_flags & LL_SBI_USER_XATTR)
258 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
261 /* Setting this indicates we correctly support S_NOSEC (See kernel
262 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
264 sb->s_flags |= MS_NOSEC;
267 if (sbi->ll_flags & LL_SBI_FLOCK)
268 sbi->ll_fop = &ll_file_operations_flock;
269 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
270 sbi->ll_fop = &ll_file_operations;
272 sbi->ll_fop = &ll_file_operations_noflock;
274 /* always ping even if server suppress_pings */
275 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
276 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
278 obd_connect_set_secctx(data);
280 #if defined(CONFIG_SECURITY)
281 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
284 data->ocd_brw_size = MD_MAX_BRW_SIZE;
286 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
287 &sbi->ll_sb_uuid, data, sbi->ll_cache);
289 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
290 "recovery, of which this client is not a "
291 "part. Please wait for recovery to complete,"
292 " abort, or time out.\n", md);
295 CERROR("cannot connect to %s: rc = %d\n", md, err);
299 sbi->ll_md_exp->exp_connect_data = *data;
301 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
302 LUSTRE_SEQ_METADATA);
304 CERROR("%s: Can't init metadata layer FID infrastructure, "
305 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
309 /* For mount, we only need fs info from MDT0, and also in DNE, it
310 * can make sure the client can be mounted as long as MDT0 is
312 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
313 ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS,
314 OBD_STATFS_FOR_MDT0);
316 GOTO(out_md_fid, err);
318 /* This needs to be after statfs to ensure connect has finished.
319 * Note that "data" does NOT contain the valid connect reply.
320 * If connecting to a 1.8 server there will be no LMV device, so
321 * we can access the MDC export directly and exp_connect_flags will
322 * be non-zero, but if accessing an upgraded 2.1 server it will
323 * have the correct flags filled in.
324 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
325 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
326 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
327 valid != CLIENT_CONNECT_MDT_REQD) {
330 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
331 obd_connect_flags2str(buf, PAGE_SIZE,
332 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
333 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
334 "feature(s) needed for correct operation "
335 "of this client (%s). Please upgrade "
336 "server or downgrade client.\n",
337 sbi->ll_md_exp->exp_obd->obd_name, buf);
338 OBD_FREE(buf, PAGE_SIZE);
339 GOTO(out_md_fid, err = -EPROTO);
342 size = sizeof(*data);
343 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
344 KEY_CONN_DATA, &size, data);
346 CERROR("%s: Get connect data failed: rc = %d\n",
347 sbi->ll_md_exp->exp_obd->obd_name, err);
348 GOTO(out_md_fid, err);
351 LASSERT(osfs->os_bsize);
352 sb->s_blocksize = osfs->os_bsize;
353 sb->s_blocksize_bits = log2(osfs->os_bsize);
354 sb->s_magic = LL_SUPER_MAGIC;
355 sb->s_maxbytes = MAX_LFS_FILESIZE;
356 sbi->ll_namelen = osfs->os_namelen;
357 sbi->ll_mnt.mnt = current->fs->root.mnt;
359 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
360 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
361 LCONSOLE_INFO("Disabling user_xattr feature because "
362 "it is not supported on the server\n");
363 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
366 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
368 sb->s_flags |= MS_POSIXACL;
370 sbi->ll_flags |= LL_SBI_ACL;
372 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
374 sb->s_flags &= ~MS_POSIXACL;
376 sbi->ll_flags &= ~LL_SBI_ACL;
379 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
380 sbi->ll_flags |= LL_SBI_64BIT_HASH;
382 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
383 sbi->ll_flags |= LL_SBI_LAYOUT_LOCK;
385 if (obd_connect_has_secctx(data))
386 sbi->ll_flags |= LL_SBI_FILE_SECCTX;
388 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
389 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
390 LCONSOLE_INFO("%s: disabling xattr cache due to "
391 "unknown maximum xattr size.\n", dt);
392 } else if (!sbi->ll_xattr_cache_set) {
393 /* If xattr_cache is already set (no matter 0 or 1)
394 * during processing llog, it won't be enabled here. */
395 sbi->ll_flags |= LL_SBI_XATTR_CACHE;
396 sbi->ll_xattr_cache_enabled = 1;
400 sbi->ll_dt_obd = class_name2obd(dt);
401 if (!sbi->ll_dt_obd) {
402 CERROR("DT %s: not setup or attached\n", dt);
403 GOTO(out_md_fid, err = -ENODEV);
406 /* pass client page size via ocd_grant_blkbits, the server should report
407 * back its backend blocksize for grant calculation purpose */
408 data->ocd_grant_blkbits = PAGE_SHIFT;
410 /* indicate OST features supported by this client */
411 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
412 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
413 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
414 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
415 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
416 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
417 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
418 OBD_CONNECT_EINPROGRESS |
419 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
420 OBD_CONNECT_LAYOUTLOCK |
421 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
422 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
423 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
425 /* The client currently advertises support for OBD_CONNECT_LOCKAHEAD_OLD so it
426 * can interoperate with an older version of lockahead which was released prior
427 * to landing in master. This support will be dropped when 2.13 development
428 * starts. At the point, we should not just drop the connect flag (below), we
429 * should also remove the support in the code.
431 * Removing it means a few things:
432 * 1. Remove this section here
433 * 2. Remove CEF_NONBLOCK in ll_file_lockahead()
434 * 3. Remove function exp_connect_lockahead_old
435 * 4. Remove LDLM_FL_LOCKAHEAD_OLD_RESERVED in lustre_dlm_flags.h
437 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 12, 50, 0)
438 data->ocd_connect_flags |= OBD_CONNECT_LOCKAHEAD_OLD;
441 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD;
443 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
444 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
446 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
447 * disabled by default, because it can still be enabled on the
448 * fly via /sys. As a consequence, we still need to come to an
449 * agreement on the supported algorithms at connect time
451 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
453 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
454 data->ocd_cksum_types = OBD_CKSUM_ADLER;
456 data->ocd_cksum_types = obd_cksum_types_supported_client();
458 #ifdef HAVE_LRU_RESIZE_SUPPORT
459 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
461 /* always ping even if server suppress_pings */
462 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
463 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
465 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
466 "ocd_grant: %d\n", data->ocd_connect_flags,
467 data->ocd_version, data->ocd_grant);
469 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
470 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
472 data->ocd_brw_size = DT_MAX_BRW_SIZE;
474 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
475 &sbi->ll_sb_uuid, data, sbi->ll_cache);
477 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
478 "recovery, of which this client is not a "
479 "part. Please wait for recovery to "
480 "complete, abort, or time out.\n", dt);
483 CERROR("%s: Cannot connect to %s: rc = %d\n",
484 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
488 sbi->ll_dt_exp->exp_connect_data = *data;
490 /* Don't change value if it was specified in the config log */
491 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
492 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
493 max_t(unsigned long, SBI_DEFAULT_READAHEAD_WHOLE_MAX,
494 (data->ocd_brw_size >> PAGE_SHIFT));
495 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
496 sbi->ll_ra_info.ra_max_pages_per_file)
497 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
498 sbi->ll_ra_info.ra_max_pages_per_file;
501 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
502 LUSTRE_SEQ_METADATA);
504 CERROR("%s: Can't init data layer FID infrastructure, "
505 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
509 mutex_lock(&sbi->ll_lco.lco_lock);
510 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
511 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
512 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
513 mutex_unlock(&sbi->ll_lco.lco_lock);
515 fid_zero(&sbi->ll_root_fid);
516 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
519 CERROR("cannot mds_connect: rc = %d\n", err);
520 GOTO(out_lock_cn_cb, err);
522 if (!fid_is_sane(&sbi->ll_root_fid)) {
523 CERROR("%s: Invalid root fid "DFID" during mount\n",
524 sbi->ll_md_exp->exp_obd->obd_name,
525 PFID(&sbi->ll_root_fid));
526 GOTO(out_lock_cn_cb, err = -EINVAL);
528 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
530 sb->s_op = &lustre_super_operations;
531 #ifdef HAVE_XATTR_HANDLER_FLAGS
532 sb->s_xattr = ll_xattr_handlers;
534 #if THREAD_SIZE >= 8192 /*b=17630*/
535 sb->s_export_op = &lustre_export_operations;
539 * XXX: move this to after cbd setup? */
540 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
541 if (sbi->ll_flags & LL_SBI_ACL)
542 valid |= OBD_MD_FLACL;
544 OBD_ALLOC_PTR(op_data);
546 GOTO(out_lock_cn_cb, err = -ENOMEM);
548 op_data->op_fid1 = sbi->ll_root_fid;
549 op_data->op_mode = 0;
550 op_data->op_valid = valid;
552 err = md_getattr(sbi->ll_md_exp, op_data, &request);
554 OBD_FREE_PTR(op_data);
556 CERROR("%s: md_getattr failed for root: rc = %d\n",
557 sbi->ll_md_exp->exp_obd->obd_name, err);
558 GOTO(out_lock_cn_cb, err);
561 err = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
562 sbi->ll_md_exp, &lmd);
564 CERROR("failed to understand root inode md: rc = %d\n", err);
565 ptlrpc_req_finished(request);
566 GOTO(out_lock_cn_cb, err);
569 LASSERT(fid_is_sane(&sbi->ll_root_fid));
570 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid,
571 sbi->ll_flags & LL_SBI_32BIT_API),
573 md_free_lustre_md(sbi->ll_md_exp, &lmd);
574 ptlrpc_req_finished(request);
577 #ifdef CONFIG_FS_POSIX_ACL
579 posix_acl_release(lmd.posix_acl);
580 lmd.posix_acl = NULL;
583 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
585 CERROR("lustre_lite: bad iget4 for root\n");
589 checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
590 if (sbi->ll_checksum_set) {
591 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
592 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
593 sizeof(checksum), &checksum, NULL);
595 CERROR("%s: Set checksum failed: rc = %d\n",
596 sbi->ll_dt_exp->exp_obd->obd_name, err);
602 sb->s_root = d_make_root(root);
603 if (sb->s_root == NULL) {
605 CERROR("%s: can't make root dentry: rc = %d\n",
606 sbi->ll_fsname, err);
609 #ifdef HAVE_DCACHE_LOCK
610 sb->s_root->d_op = &ll_d_ops;
613 sbi->ll_sdev_orig = sb->s_dev;
615 /* We set sb->s_dev equal on all lustre clients in order to support
616 * NFS export clustering. NFSD requires that the FSID be the same
618 /* s_dev is also used in lt_compare() to compare two fs, but that is
619 * only a node-local comparison. */
620 uuid = obd_get_uuid(sbi->ll_md_exp);
622 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
629 if (sbi->ll_dt_obd) {
630 err = sysfs_create_link(&sbi->ll_kset.kobj,
631 &sbi->ll_dt_obd->obd_kset.kobj,
632 sbi->ll_dt_obd->obd_type->typ_name);
634 CERROR("%s: could not register %s in llite: rc = %d\n",
635 dt, sbi->ll_fsname, err);
640 if (sbi->ll_md_obd) {
641 err = sysfs_create_link(&sbi->ll_kset.kobj,
642 &sbi->ll_md_obd->obd_kset.kobj,
643 sbi->ll_md_obd->obd_type->typ_name);
645 CERROR("%s: could not register %s in llite: rc = %d\n",
646 md, sbi->ll_fsname, err);
656 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
658 obd_disconnect(sbi->ll_dt_exp);
659 sbi->ll_dt_exp = NULL;
660 sbi->ll_dt_obd = NULL;
662 obd_fid_fini(sbi->ll_md_exp->exp_obd);
664 obd_disconnect(sbi->ll_md_exp);
665 sbi->ll_md_exp = NULL;
666 sbi->ll_md_obd = NULL;
675 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
679 size = sizeof(*lmmsize);
680 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
681 KEY_MAX_EASIZE, &size, lmmsize);
683 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
684 sbi->ll_dt_exp->exp_obd->obd_name, rc);
688 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
691 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
692 KEY_MAX_EASIZE, &size, lmmsize);
694 CERROR("Get max mdsize error rc %d\n", rc);
696 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
702 * Get the value of the default_easize parameter.
704 * \see client_obd::cl_default_mds_easize
706 * \param[in] sbi superblock info for this filesystem
707 * \param[out] lmmsize pointer to storage location for value
709 * \retval 0 on success
710 * \retval negative negated errno on failure
712 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
717 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
718 KEY_DEFAULT_EASIZE, &size, lmmsize);
720 CERROR("Get default mdsize error rc %d\n", rc);
726 * Set the default_easize parameter to the given value.
728 * \see client_obd::cl_default_mds_easize
730 * \param[in] sbi superblock info for this filesystem
731 * \param[in] lmmsize the size to set
733 * \retval 0 on success
734 * \retval negative negated errno on failure
736 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
740 if (lmmsize < sizeof(struct lov_mds_md) ||
741 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
744 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
745 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
746 sizeof(int), &lmmsize, NULL);
751 static void client_common_put_super(struct super_block *sb)
753 struct ll_sb_info *sbi = ll_s2sbi(sb);
758 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
759 obd_disconnect(sbi->ll_dt_exp);
760 sbi->ll_dt_exp = NULL;
762 ll_debugfs_unregister_super(sb);
764 obd_fid_fini(sbi->ll_md_exp->exp_obd);
765 obd_disconnect(sbi->ll_md_exp);
766 sbi->ll_md_exp = NULL;
771 void ll_kill_super(struct super_block *sb)
773 struct ll_sb_info *sbi;
777 if (!(sb->s_flags & MS_ACTIVE))
781 /* we need restore s_dev from changed for clustred NFS before put_super
782 * because new kernels have cached s_dev and change sb->s_dev in
783 * put_super not affected real removing devices */
785 sb->s_dev = sbi->ll_sdev_orig;
786 sbi->ll_umounting = 1;
788 /* wait running statahead threads to quit */
789 while (atomic_read(&sbi->ll_sa_running) > 0) {
790 set_current_state(TASK_UNINTERRUPTIBLE);
791 schedule_timeout(msecs_to_jiffies(MSEC_PER_SEC >> 3));
798 static inline int ll_set_opt(const char *opt, char *data, int fl)
800 if (strncmp(opt, data, strlen(opt)) != 0)
806 /* non-client-specific mount options are parsed in lmd_parse */
807 static int ll_options(char *options, struct ll_sb_info *sbi)
810 char *s1 = options, *s2;
811 int *flags = &sbi->ll_flags;
817 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
820 CDEBUG(D_SUPER, "next opt=%s\n", s1);
821 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
826 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
831 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
836 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
841 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
846 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
851 tmp = ll_set_opt("context", s1, 1);
854 tmp = ll_set_opt("fscontext", s1, 1);
857 tmp = ll_set_opt("defcontext", s1, 1);
860 tmp = ll_set_opt("rootcontext", s1, 1);
863 tmp = ll_set_opt("user_fid2path", s1, LL_SBI_USER_FID2PATH);
868 tmp = ll_set_opt("nouser_fid2path", s1, LL_SBI_USER_FID2PATH);
874 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
877 sbi->ll_checksum_set = 1;
880 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
883 sbi->ll_checksum_set = 1;
886 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
891 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
896 tmp = ll_set_opt("lazystatfs", s1, LL_SBI_LAZYSTATFS);
901 tmp = ll_set_opt("nolazystatfs", s1, LL_SBI_LAZYSTATFS);
906 tmp = ll_set_opt("32bitapi", s1, LL_SBI_32BIT_API);
911 tmp = ll_set_opt("verbose", s1, LL_SBI_VERBOSE);
916 tmp = ll_set_opt("noverbose", s1, LL_SBI_VERBOSE);
921 tmp = ll_set_opt("always_ping", s1, LL_SBI_ALWAYS_PING);
926 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
932 s2 = strchr(s1, ',');
940 void ll_lli_init(struct ll_inode_info *lli)
942 lli->lli_inode_magic = LLI_INODE_MAGIC;
944 spin_lock_init(&lli->lli_lock);
945 lli->lli_posix_acl = NULL;
946 /* Do not set lli_fid, it has been initialized already. */
947 fid_zero(&lli->lli_pfid);
948 lli->lli_mds_read_och = NULL;
949 lli->lli_mds_write_och = NULL;
950 lli->lli_mds_exec_och = NULL;
951 lli->lli_open_fd_read_count = 0;
952 lli->lli_open_fd_write_count = 0;
953 lli->lli_open_fd_exec_count = 0;
954 mutex_init(&lli->lli_och_mutex);
955 spin_lock_init(&lli->lli_agl_lock);
956 spin_lock_init(&lli->lli_layout_lock);
957 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
958 lli->lli_clob = NULL;
960 init_rwsem(&lli->lli_xattrs_list_rwsem);
961 mutex_init(&lli->lli_xattrs_enq_lock);
963 LASSERT(lli->lli_vfs_inode.i_mode != 0);
964 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
965 mutex_init(&lli->lli_readdir_mutex);
966 lli->lli_opendir_key = NULL;
968 spin_lock_init(&lli->lli_sa_lock);
969 lli->lli_opendir_pid = 0;
970 lli->lli_sa_enabled = 0;
971 lli->lli_def_stripe_offset = -1;
972 init_rwsem(&lli->lli_lsm_sem);
974 mutex_init(&lli->lli_size_mutex);
975 lli->lli_symlink_name = NULL;
976 init_rwsem(&lli->lli_trunc_sem);
977 range_lock_tree_init(&lli->lli_write_tree);
978 init_rwsem(&lli->lli_glimpse_sem);
979 lli->lli_glimpse_time = ktime_set(0, 0);
980 INIT_LIST_HEAD(&lli->lli_agl_list);
981 lli->lli_agl_index = 0;
982 lli->lli_async_rc = 0;
983 spin_lock_init(&lli->lli_heat_lock);
984 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
985 lli->lli_heat_flags = 0;
986 mutex_init(&lli->lli_pcc_lock);
987 lli->lli_pcc_state = PCC_STATE_FL_NONE;
988 lli->lli_pcc_inode = NULL;
990 mutex_init(&lli->lli_layout_mutex);
991 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
994 #define MAX_STRING_SIZE 128
996 #ifndef HAVE_SUPER_SETUP_BDI_NAME
998 #define LSI_BDI_INITIALIZED 0x00400000
1000 #ifndef HAVE_BDI_CAP_MAP_COPY
1001 # define BDI_CAP_MAP_COPY 0
1004 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1006 struct lustre_sb_info *lsi = s2lsi(sb);
1007 char buf[MAX_STRING_SIZE];
1011 err = bdi_init(&lsi->lsi_bdi);
1015 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1016 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1017 lsi->lsi_bdi.name = "lustre";
1018 va_start(args, fmt);
1019 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1021 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1024 sb->s_bdi = &lsi->lsi_bdi;
1028 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1030 int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
1032 struct lustre_profile *lprof = NULL;
1033 struct lustre_sb_info *lsi = s2lsi(sb);
1034 struct ll_sb_info *sbi = NULL;
1035 char *dt = NULL, *md = NULL;
1036 char *profilenm = get_profile_name(sb);
1037 struct config_llog_instance *cfg;
1038 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1039 const int instlen = 16 + 2;
1040 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1041 char name[MAX_STRING_SIZE];
1050 /* for ASLR, to map between cfg_instance and hashed ptr */
1051 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1052 profilenm, cfg_instance, sb);
1054 try_module_get(THIS_MODULE);
1058 GOTO(out_free_cfg, err = -ENOMEM);
1060 /* client additional sb info */
1061 lsi->lsi_llsbi = sbi = ll_init_sbi();
1063 GOTO(out_free_cfg, err = -ENOMEM);
1065 err = ll_options(lsi->lsi_lmd->lmd_opts, sbi);
1067 GOTO(out_free_cfg, err);
1069 #ifndef HAVE_DCACHE_LOCK
1070 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1071 sb->s_d_op = &ll_d_ops;
1074 generate_random_uuid(uuid.b);
1075 snprintf(sbi->ll_sb_uuid.uuid, UUID_SIZE, "%pU", uuid.b);
1077 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1080 len = strlen(profilenm);
1081 ptr = strrchr(profilenm, '-');
1082 if (ptr && (strcmp(ptr, "-client") == 0))
1085 if (len > LUSTRE_MAXFSNAME) {
1086 if (unlikely(len >= MAX_STRING_SIZE))
1087 len = MAX_STRING_SIZE - 1;
1088 strncpy(name, profilenm, len);
1090 err = -ENAMETOOLONG;
1091 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1092 name, LUSTRE_MAXFSNAME, err);
1093 GOTO(out_free_cfg, err);
1095 strncpy(sbi->ll_fsname, profilenm, len);
1096 sbi->ll_fsname[len] = '\0';
1099 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1100 profilenm, cfg_instance);
1102 err = super_setup_bdi_name(sb, "%s", name);
1104 GOTO(out_free_cfg, err);
1106 /* Call ll_debugfs_register_super() before lustre_process_log()
1107 * so that "llite.*.*" params can be processed correctly.
1109 err = ll_debugfs_register_super(sb, name);
1111 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1112 sbi->ll_fsname, err);
1116 /* The cfg_instance is a value unique to this super, in case some
1117 * joker tries to mount the same fs at two mount points.
1119 cfg->cfg_instance = cfg_instance;
1120 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1121 cfg->cfg_callback = class_config_llog_handler;
1122 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1123 /* set up client obds */
1124 err = lustre_process_log(sb, profilenm, cfg);
1126 GOTO(out_debugfs, err);
1128 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1129 lprof = class_get_profile(profilenm);
1130 if (lprof == NULL) {
1131 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1132 " read from the MGS. Does that filesystem "
1133 "exist?\n", profilenm);
1134 GOTO(out_debugfs, err = -EINVAL);
1136 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1137 lprof->lp_md, lprof->lp_dt);
1139 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1140 OBD_ALLOC(dt, dt_len);
1142 GOTO(out_profile, err = -ENOMEM);
1143 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1145 md_len = strlen(lprof->lp_md) + instlen + 2;
1146 OBD_ALLOC(md, md_len);
1148 GOTO(out_free_dt, err = -ENOMEM);
1149 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1151 /* connections, registrations, sb setup */
1152 err = client_common_fill_super(sb, md, dt, mnt);
1154 GOTO(out_free_md, err);
1156 sbi->ll_client_common_fill_super_succeeded = 1;
1160 OBD_FREE(md, md_len);
1163 OBD_FREE(dt, dt_len);
1166 class_put_profile(lprof);
1169 ll_debugfs_unregister_super(sb);
1176 else if (sbi->ll_flags & LL_SBI_VERBOSE)
1177 LCONSOLE_WARN("Mounted %s\n", profilenm);
1179 } /* ll_fill_super */
1181 void ll_put_super(struct super_block *sb)
1183 struct config_llog_instance cfg, params_cfg;
1184 struct obd_device *obd;
1185 struct lustre_sb_info *lsi = s2lsi(sb);
1186 struct ll_sb_info *sbi = ll_s2sbi(sb);
1187 char *profilenm = get_profile_name(sb);
1188 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1190 int next, force = 1, rc = 0;
1194 GOTO(out_no_sbi, 0);
1196 /* Should replace instance_id with something better for ASLR */
1197 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1198 profilenm, cfg_instance, sb);
1200 cfg.cfg_instance = cfg_instance;
1201 lustre_end_log(sb, profilenm, &cfg);
1203 params_cfg.cfg_instance = cfg_instance;
1204 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1206 if (sbi->ll_md_exp) {
1207 obd = class_exp2obd(sbi->ll_md_exp);
1209 force = obd->obd_force;
1212 /* Wait for unstable pages to be committed to stable storage */
1214 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
1215 rc = l_wait_event(sbi->ll_cache->ccc_unstable_waitq,
1216 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0,
1220 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1221 if (force == 0 && rc != -EINTR)
1222 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1224 /* We need to set force before the lov_disconnect in
1225 lustre_common_put_super, since l_d cleans up osc's as well. */
1228 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1230 obd->obd_force = force;
1234 if (sbi->ll_client_common_fill_super_succeeded) {
1235 /* Only if client_common_fill_super succeeded */
1236 client_common_put_super(sb);
1240 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) !=NULL) {
1241 class_manual_cleanup(obd);
1244 if (sbi->ll_flags & LL_SBI_VERBOSE)
1245 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1248 class_del_profile(profilenm);
1250 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1251 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1252 bdi_destroy(&lsi->lsi_bdi);
1253 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1258 lsi->lsi_llsbi = NULL;
1260 lustre_common_put_super(sb);
1262 cl_env_cache_purge(~0);
1264 module_put(THIS_MODULE);
1267 } /* client_put_super */
1269 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1271 struct inode *inode = NULL;
1273 /* NOTE: we depend on atomic igrab() -bzzz */
1274 lock_res_and_lock(lock);
1275 if (lock->l_resource->lr_lvb_inode) {
1276 struct ll_inode_info * lli;
1277 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1278 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1279 inode = igrab(lock->l_resource->lr_lvb_inode);
1281 inode = lock->l_resource->lr_lvb_inode;
1282 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1283 D_WARNING, lock, "lr_lvb_inode %p is "
1284 "bogus: magic %08x",
1285 lock->l_resource->lr_lvb_inode,
1286 lli->lli_inode_magic);
1290 unlock_res_and_lock(lock);
1294 void ll_dir_clear_lsm_md(struct inode *inode)
1296 struct ll_inode_info *lli = ll_i2info(inode);
1298 LASSERT(S_ISDIR(inode->i_mode));
1300 if (lli->lli_lsm_md != NULL) {
1301 lmv_free_memmd(lli->lli_lsm_md);
1302 lli->lli_lsm_md = NULL;
1306 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1307 const struct lu_fid *fid,
1308 struct lustre_md *md)
1310 struct ll_sb_info *sbi = ll_s2sbi(sb);
1311 struct mdt_body *body = md->body;
1312 struct inode *inode;
1316 ino = cl_fid_build_ino(fid, sbi->ll_flags & LL_SBI_32BIT_API);
1317 inode = iget_locked(sb, ino);
1318 if (inode == NULL) {
1319 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1320 sbi->ll_fsname, PFID(fid));
1321 RETURN(ERR_PTR(-ENOENT));
1324 if (inode->i_state & I_NEW) {
1325 struct ll_inode_info *lli = ll_i2info(inode);
1326 struct lmv_stripe_md *lsm = md->lmv;
1328 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1329 (body->mbo_mode & S_IFMT);
1330 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1333 inode->i_mtime.tv_sec = 0;
1334 inode->i_atime.tv_sec = 0;
1335 inode->i_ctime.tv_sec = 0;
1338 #ifdef HAVE_BACKING_DEV_INFO
1339 /* initializing backing dev info. */
1340 inode->i_mapping->backing_dev_info =
1341 &s2lsi(inode->i_sb)->lsi_bdi;
1343 inode->i_op = &ll_dir_inode_operations;
1344 inode->i_fop = &ll_dir_operations;
1345 lli->lli_fid = *fid;
1348 LASSERT(lsm != NULL);
1349 /* master object FID */
1350 lli->lli_pfid = body->mbo_fid1;
1351 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1352 lli, PFID(fid), PFID(&lli->lli_pfid));
1353 unlock_new_inode(inode);
1359 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1362 struct lmv_stripe_md *lsm = md->lmv;
1363 struct ll_inode_info *lli = ll_i2info(inode);
1366 LASSERT(lsm != NULL);
1368 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1369 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1370 lsm_md_dump(D_INODE, lsm);
1372 /* XXX sigh, this lsm_root initialization should be in
1373 * LMV layer, but it needs ll_iget right now, so we
1374 * put this here right now. */
1375 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1376 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1377 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1379 if (!fid_is_sane(fid))
1382 /* Unfortunately ll_iget will call ll_update_inode,
1383 * where the initialization of slave inode is slightly
1384 * different, so it reset lsm_md to NULL to avoid
1385 * initializing lsm for slave inode. */
1386 lsm->lsm_md_oinfo[i].lmo_root =
1387 ll_iget_anon_dir(inode->i_sb, fid, md);
1388 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1389 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1391 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1393 iput(lsm->lsm_md_oinfo[i].lmo_root);
1394 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1400 lli->lli_lsm_md = lsm;
1405 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1407 struct ll_inode_info *lli = ll_i2info(inode);
1408 struct lmv_stripe_md *lsm = md->lmv;
1413 LASSERT(S_ISDIR(inode->i_mode));
1414 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1415 PFID(ll_inode2fid(inode)));
1418 * no striped information from request, lustre_md from req does not
1419 * include stripeEA, see ll_md_setattr()
1425 * normally dir layout doesn't change, only take read lock to check
1426 * that to avoid blocking other MD operations.
1428 if (lli->lli_lsm_md)
1429 down_read(&lli->lli_lsm_sem);
1431 down_write(&lli->lli_lsm_sem);
1434 * if dir layout mismatch, check whether version is increased, which
1435 * means layout is changed, this happens in dir migration and lfsck.
1437 * foreign LMV should not change.
1439 if (lli->lli_lsm_md &&
1440 lli->lli_lsm_md->lsm_md_magic != LMV_MAGIC_FOREIGN &&
1441 !lsm_md_eq(lli->lli_lsm_md, lsm)) {
1442 if (lsm->lsm_md_layout_version <=
1443 lli->lli_lsm_md->lsm_md_layout_version) {
1444 CERROR("%s: "DFID" dir layout mismatch:\n",
1445 ll_i2sbi(inode)->ll_fsname,
1446 PFID(&lli->lli_fid));
1447 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1448 lsm_md_dump(D_ERROR, lsm);
1449 GOTO(unlock, rc = -EINVAL);
1452 /* layout changed, switch to write lock */
1453 up_read(&lli->lli_lsm_sem);
1454 down_write(&lli->lli_lsm_sem);
1455 ll_dir_clear_lsm_md(inode);
1458 /* set directory layout */
1459 if (!lli->lli_lsm_md) {
1460 struct cl_attr *attr;
1462 if (lsm->lsm_md_magic == LMV_MAGIC_FOREIGN) {
1463 /* set md->lmv to NULL, so the following free lustre_md
1464 * will not free this lsm */
1466 lli->lli_lsm_md = lsm;
1467 up_write(&lli->lli_lsm_sem);
1471 rc = ll_init_lsm_md(inode, md);
1472 up_write(&lli->lli_lsm_sem);
1476 /* set md->lmv to NULL, so the following free lustre_md
1477 * will not free this lsm */
1481 * md_merge_attr() may take long, since lsm is already set,
1482 * switch to read lock.
1484 down_read(&lli->lli_lsm_sem);
1486 OBD_ALLOC_PTR(attr);
1488 GOTO(unlock, rc = -ENOMEM);
1490 /* validate the lsm */
1491 rc = md_merge_attr(ll_i2mdexp(inode), lsm, attr,
1492 ll_md_blocking_ast);
1498 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1499 md->body->mbo_nlink = attr->cat_nlink;
1500 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1501 md->body->mbo_size = attr->cat_size;
1502 if (md->body->mbo_valid & OBD_MD_FLATIME)
1503 md->body->mbo_atime = attr->cat_atime;
1504 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1505 md->body->mbo_ctime = attr->cat_ctime;
1506 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1507 md->body->mbo_mtime = attr->cat_mtime;
1512 up_read(&lli->lli_lsm_sem);
1517 void ll_clear_inode(struct inode *inode)
1519 struct ll_inode_info *lli = ll_i2info(inode);
1520 struct ll_sb_info *sbi = ll_i2sbi(inode);
1524 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1525 PFID(ll_inode2fid(inode)), inode);
1527 if (S_ISDIR(inode->i_mode)) {
1528 /* these should have been cleared in ll_file_release */
1529 LASSERT(lli->lli_opendir_key == NULL);
1530 LASSERT(lli->lli_sai == NULL);
1531 LASSERT(lli->lli_opendir_pid == 0);
1533 pcc_inode_free(inode);
1536 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1538 LASSERT(!lli->lli_open_fd_write_count);
1539 LASSERT(!lli->lli_open_fd_read_count);
1540 LASSERT(!lli->lli_open_fd_exec_count);
1542 if (lli->lli_mds_write_och)
1543 ll_md_real_close(inode, FMODE_WRITE);
1544 if (lli->lli_mds_exec_och)
1545 ll_md_real_close(inode, FMODE_EXEC);
1546 if (lli->lli_mds_read_och)
1547 ll_md_real_close(inode, FMODE_READ);
1549 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1550 OBD_FREE(lli->lli_symlink_name,
1551 strlen(lli->lli_symlink_name) + 1);
1552 lli->lli_symlink_name = NULL;
1555 ll_xattr_cache_destroy(inode);
1557 #ifdef CONFIG_FS_POSIX_ACL
1558 forget_all_cached_acls(inode);
1559 if (lli->lli_posix_acl) {
1560 posix_acl_release(lli->lli_posix_acl);
1561 lli->lli_posix_acl = NULL;
1564 lli->lli_inode_magic = LLI_INODE_DEAD;
1566 if (S_ISDIR(inode->i_mode))
1567 ll_dir_clear_lsm_md(inode);
1568 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1569 LASSERT(list_empty(&lli->lli_agl_list));
1572 * XXX This has to be done before lsm is freed below, because
1573 * cl_object still uses inode lsm.
1575 cl_inode_fini(inode);
1580 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1582 struct lustre_md md;
1583 struct inode *inode = dentry->d_inode;
1584 struct ll_sb_info *sbi = ll_i2sbi(inode);
1585 struct ptlrpc_request *request = NULL;
1589 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1590 LUSTRE_OPC_ANY, NULL);
1591 if (IS_ERR(op_data))
1592 RETURN(PTR_ERR(op_data));
1594 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1596 ptlrpc_req_finished(request);
1597 if (rc == -ENOENT) {
1599 /* Unlinked special device node? Or just a race?
1600 * Pretend we done everything. */
1601 if (!S_ISREG(inode->i_mode) &&
1602 !S_ISDIR(inode->i_mode)) {
1603 ia_valid = op_data->op_attr.ia_valid;
1604 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1605 rc = simple_setattr(dentry, &op_data->op_attr);
1606 op_data->op_attr.ia_valid = ia_valid;
1608 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1609 CERROR("md_setattr fails: rc = %d\n", rc);
1614 rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
1615 sbi->ll_md_exp, &md);
1617 ptlrpc_req_finished(request);
1621 ia_valid = op_data->op_attr.ia_valid;
1622 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1623 * cache is not cleared yet. */
1624 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1625 if (S_ISREG(inode->i_mode))
1627 rc = simple_setattr(dentry, &op_data->op_attr);
1628 if (S_ISREG(inode->i_mode))
1629 inode_unlock(inode);
1630 op_data->op_attr.ia_valid = ia_valid;
1632 rc = ll_update_inode(inode, &md);
1633 ptlrpc_req_finished(request);
1638 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1639 * object(s) determine the file size and mtime. Otherwise, the MDS will
1640 * keep these values until such a time that objects are allocated for it.
1641 * We do the MDS operations first, as it is checking permissions for us.
1642 * We don't to the MDS RPC if there is nothing that we want to store there,
1643 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1644 * going to do an RPC anyways.
1646 * If we are doing a truncate, we will send the mtime and ctime updates
1647 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1648 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1651 * In case of HSMimport, we only set attr on MDS.
1653 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
1654 enum op_xvalid xvalid, bool hsm_import)
1656 struct inode *inode = dentry->d_inode;
1657 struct ll_inode_info *lli = ll_i2info(inode);
1658 struct md_op_data *op_data = NULL;
1663 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
1664 "valid %x, hsm_import %d\n",
1665 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
1666 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
1669 if (attr->ia_valid & ATTR_SIZE) {
1670 /* Check new size against VFS/VM file size limit and rlimit */
1671 rc = inode_newsize_ok(inode, attr->ia_size);
1675 /* The maximum Lustre file size is variable, based on the
1676 * OST maximum object size and number of stripes. This
1677 * needs another check in addition to the VFS check above. */
1678 if (attr->ia_size > ll_file_maxbytes(inode)) {
1679 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
1680 PFID(&lli->lli_fid), attr->ia_size,
1681 ll_file_maxbytes(inode));
1685 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1688 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1689 if (attr->ia_valid & TIMES_SET_FLAGS) {
1690 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
1691 !cfs_capable(CFS_CAP_FOWNER))
1695 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1696 if (!(xvalid & OP_XVALID_CTIME_SET) &&
1697 (attr->ia_valid & ATTR_CTIME)) {
1698 attr->ia_ctime = current_time(inode);
1699 xvalid |= OP_XVALID_CTIME_SET;
1701 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
1702 (attr->ia_valid & ATTR_ATIME)) {
1703 attr->ia_atime = current_time(inode);
1704 attr->ia_valid |= ATTR_ATIME_SET;
1706 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
1707 (attr->ia_valid & ATTR_MTIME)) {
1708 attr->ia_mtime = current_time(inode);
1709 attr->ia_valid |= ATTR_MTIME_SET;
1712 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1713 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
1714 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
1715 ktime_get_real_seconds());
1717 if (S_ISREG(inode->i_mode)) {
1718 if (attr->ia_valid & ATTR_SIZE)
1719 inode_dio_write_done(inode);
1720 inode_unlock(inode);
1723 /* We always do an MDS RPC, even if we're only changing the size;
1724 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
1726 OBD_ALLOC_PTR(op_data);
1727 if (op_data == NULL)
1728 GOTO(out, rc = -ENOMEM);
1730 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
1731 /* If we are changing file size, file content is
1732 * modified, flag it.
1734 xvalid |= OP_XVALID_OWNEROVERRIDE;
1735 op_data->op_bias |= MDS_DATA_MODIFIED;
1736 ll_file_clear_flag(lli, LLIF_DATA_MODIFIED);
1739 if (attr->ia_valid & ATTR_FILE) {
1740 struct ll_file_data *fd = LUSTRE_FPRIVATE(attr->ia_file);
1742 if (fd->fd_lease_och)
1743 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
1746 op_data->op_attr = *attr;
1747 op_data->op_xvalid = xvalid;
1749 rc = ll_md_setattr(dentry, op_data);
1753 if (!S_ISREG(inode->i_mode) || hsm_import)
1756 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
1757 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
1758 xvalid & OP_XVALID_CTIME_SET) {
1759 bool cached = false;
1761 rc = pcc_inode_setattr(inode, attr, &cached);
1764 CERROR("%s: PCC inode "DFID" setattr failed: "
1766 ll_i2sbi(inode)->ll_fsname,
1767 PFID(&lli->lli_fid), rc);
1771 /* For truncate and utimes sending attributes to OSTs,
1772 * setting mtime/atime to the past will be performed
1773 * under PW [0:EOF] extent lock (new_size:EOF for
1774 * truncate). It may seem excessive to send mtime/atime
1775 * updates to OSTs when not setting times to past, but
1776 * it is necessary due to possible time
1777 * de-synchronization between MDT inode and OST objects
1779 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, 0);
1783 /* If the file was restored, it needs to set dirty flag.
1785 * We've already sent MDS_DATA_MODIFIED flag in
1786 * ll_md_setattr() for truncate. However, the MDT refuses to
1787 * set the HS_DIRTY flag on released files, so we have to set
1788 * it again if the file has been restored. Please check how
1789 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
1791 * Please notice that if the file is not released, the previous
1792 * MDS_DATA_MODIFIED has taken effect and usually
1793 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
1794 * This way we can save an RPC for common open + trunc
1796 if (ll_file_test_and_clear_flag(lli, LLIF_DATA_MODIFIED)) {
1797 struct hsm_state_set hss = {
1798 .hss_valid = HSS_SETMASK,
1799 .hss_setmask = HS_DIRTY,
1803 rc2 = ll_hsm_state_set(inode, &hss);
1804 /* truncate and write can happen at the same time, so that
1805 * the file can be set modified even though the file is not
1806 * restored from released state, and ll_hsm_state_set() is
1807 * not applicable for the file, and rc2 < 0 is normal in this
1810 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
1811 PFID(ll_inode2fid(inode)), rc2);
1816 if (op_data != NULL)
1817 ll_finish_md_op_data(op_data);
1819 if (S_ISREG(inode->i_mode)) {
1821 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
1822 inode_dio_wait(inode);
1823 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
1824 * flag. ll_update_inode (called from ll_md_setattr), clears
1825 * inode flags, so there is a gap where S_NOSEC is not set.
1826 * This can cause a writer to take the i_mutex unnecessarily,
1827 * but this is safe to do and should be rare. */
1828 inode_has_no_xattr(inode);
1831 ll_stats_ops_tally(ll_i2sbi(inode), (attr->ia_valid & ATTR_SIZE) ?
1832 LPROC_LL_TRUNC : LPROC_LL_SETATTR, 1);
1837 int ll_setattr(struct dentry *de, struct iattr *attr)
1839 int mode = de->d_inode->i_mode;
1840 enum op_xvalid xvalid = 0;
1842 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1843 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1844 xvalid |= OP_XVALID_OWNEROVERRIDE;
1846 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
1847 (ATTR_SIZE|ATTR_MODE)) &&
1848 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
1849 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
1850 !(attr->ia_mode & S_ISGID))))
1851 attr->ia_valid |= ATTR_FORCE;
1853 if ((attr->ia_valid & ATTR_MODE) &&
1855 !(attr->ia_mode & S_ISUID) &&
1856 !(attr->ia_valid & ATTR_KILL_SUID))
1857 attr->ia_valid |= ATTR_KILL_SUID;
1859 if ((attr->ia_valid & ATTR_MODE) &&
1860 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
1861 !(attr->ia_mode & S_ISGID) &&
1862 !(attr->ia_valid & ATTR_KILL_SGID))
1863 attr->ia_valid |= ATTR_KILL_SGID;
1865 return ll_setattr_raw(de, attr, xvalid, false);
1868 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
1871 struct obd_statfs obd_osfs = { 0 };
1876 max_age = ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS;
1878 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
1882 osfs->os_type = LL_SUPER_MAGIC;
1884 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
1885 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
1887 if (osfs->os_state & OS_STATE_SUM)
1890 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
1891 flags |= OBD_STATFS_NODELAY;
1893 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
1894 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
1897 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
1898 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1901 osfs->os_bsize = obd_osfs.os_bsize;
1902 osfs->os_blocks = obd_osfs.os_blocks;
1903 osfs->os_bfree = obd_osfs.os_bfree;
1904 osfs->os_bavail = obd_osfs.os_bavail;
1906 /* If we have _some_ OSTs, but don't have as many free objects on the
1907 * OSTs as inodes on the MDTs, reduce the reported number of inodes
1908 * to compensate, so that the "inodes in use" number is correct.
1909 * This should be kept in sync with lod_statfs() behaviour.
1911 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
1912 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1914 osfs->os_ffree = obd_osfs.os_ffree;
1920 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1922 struct super_block *sb = de->d_sb;
1923 struct obd_statfs osfs;
1924 __u64 fsid = huge_encode_dev(sb->s_dev);
1927 CDEBUG(D_VFSTRACE, "VFS Op: at %llu jiffies\n", get_jiffies_64());
1928 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1);
1930 /* Some amount of caching on the client is allowed */
1931 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
1935 statfs_unpack(sfs, &osfs);
1937 /* We need to downshift for all 32-bit kernels, because we can't
1938 * tell if the kernel is being called via sys_statfs64() or not.
1939 * Stop before overflowing f_bsize - in which case it is better
1940 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
1941 if (sizeof(long) < 8) {
1942 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1945 osfs.os_blocks >>= 1;
1946 osfs.os_bfree >>= 1;
1947 osfs.os_bavail >>= 1;
1951 sfs->f_blocks = osfs.os_blocks;
1952 sfs->f_bfree = osfs.os_bfree;
1953 sfs->f_bavail = osfs.os_bavail;
1954 sfs->f_fsid.val[0] = (__u32)fsid;
1955 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
1959 void ll_inode_size_lock(struct inode *inode)
1961 struct ll_inode_info *lli;
1963 LASSERT(!S_ISDIR(inode->i_mode));
1965 lli = ll_i2info(inode);
1966 mutex_lock(&lli->lli_size_mutex);
1969 void ll_inode_size_unlock(struct inode *inode)
1971 struct ll_inode_info *lli;
1973 lli = ll_i2info(inode);
1974 mutex_unlock(&lli->lli_size_mutex);
1977 void ll_update_inode_flags(struct inode *inode, int ext_flags)
1979 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
1980 if (ext_flags & LUSTRE_PROJINHERIT_FL)
1981 ll_file_set_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
1983 ll_file_clear_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
1986 int ll_update_inode(struct inode *inode, struct lustre_md *md)
1988 struct ll_inode_info *lli = ll_i2info(inode);
1989 struct mdt_body *body = md->body;
1990 struct ll_sb_info *sbi = ll_i2sbi(inode);
1993 if (body->mbo_valid & OBD_MD_FLEASIZE) {
1994 rc = cl_file_inode_init(inode, md);
1999 if (S_ISDIR(inode->i_mode)) {
2000 rc = ll_update_lsm_md(inode, md);
2005 #ifdef CONFIG_FS_POSIX_ACL
2006 if (body->mbo_valid & OBD_MD_FLACL) {
2007 spin_lock(&lli->lli_lock);
2008 if (lli->lli_posix_acl)
2009 posix_acl_release(lli->lli_posix_acl);
2010 lli->lli_posix_acl = md->posix_acl;
2011 spin_unlock(&lli->lli_lock);
2014 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1,
2015 sbi->ll_flags & LL_SBI_32BIT_API);
2016 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2018 if (body->mbo_valid & OBD_MD_FLATIME) {
2019 if (body->mbo_atime > inode->i_atime.tv_sec)
2020 inode->i_atime.tv_sec = body->mbo_atime;
2021 lli->lli_atime = body->mbo_atime;
2024 if (body->mbo_valid & OBD_MD_FLMTIME) {
2025 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2027 "setting ino %lu mtime from %lld to %llu\n",
2028 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2030 inode->i_mtime.tv_sec = body->mbo_mtime;
2032 lli->lli_mtime = body->mbo_mtime;
2035 if (body->mbo_valid & OBD_MD_FLCTIME) {
2036 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2037 inode->i_ctime.tv_sec = body->mbo_ctime;
2038 lli->lli_ctime = body->mbo_ctime;
2041 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2042 if (body->mbo_valid & OBD_MD_FLFLAGS)
2043 ll_update_inode_flags(inode, body->mbo_flags);
2044 if (body->mbo_valid & OBD_MD_FLMODE)
2045 inode->i_mode = (inode->i_mode & S_IFMT) |
2046 (body->mbo_mode & ~S_IFMT);
2048 if (body->mbo_valid & OBD_MD_FLTYPE)
2049 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2050 (body->mbo_mode & S_IFMT);
2052 LASSERT(inode->i_mode != 0);
2053 if (S_ISREG(inode->i_mode))
2054 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS + 1,
2055 LL_MAX_BLKSIZE_BITS);
2057 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
2059 if (body->mbo_valid & OBD_MD_FLUID)
2060 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2061 if (body->mbo_valid & OBD_MD_FLGID)
2062 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2063 if (body->mbo_valid & OBD_MD_FLPROJID)
2064 lli->lli_projid = body->mbo_projid;
2065 if (body->mbo_valid & OBD_MD_FLNLINK)
2066 set_nlink(inode, body->mbo_nlink);
2067 if (body->mbo_valid & OBD_MD_FLRDEV)
2068 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2070 if (body->mbo_valid & OBD_MD_FLID) {
2071 /* FID shouldn't be changed! */
2072 if (fid_is_sane(&lli->lli_fid)) {
2073 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2074 "Trying to change FID "DFID
2075 " to the "DFID", inode "DFID"(%p)\n",
2076 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2077 PFID(ll_inode2fid(inode)), inode);
2079 lli->lli_fid = body->mbo_fid1;
2083 LASSERT(fid_seq(&lli->lli_fid) != 0);
2085 if (body->mbo_valid & OBD_MD_FLSIZE) {
2086 i_size_write(inode, body->mbo_size);
2088 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2089 PFID(ll_inode2fid(inode)),
2090 (unsigned long long)body->mbo_size);
2092 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2093 inode->i_blocks = body->mbo_blocks;
2096 if (body->mbo_valid & OBD_MD_TSTATE) {
2097 /* Set LLIF_FILE_RESTORING if restore ongoing and
2098 * clear it when done to ensure to start again
2099 * glimpsing updated attrs
2101 if (body->mbo_t_state & MS_RESTORE)
2102 ll_file_set_flag(lli, LLIF_FILE_RESTORING);
2104 ll_file_clear_flag(lli, LLIF_FILE_RESTORING);
2110 int ll_read_inode2(struct inode *inode, void *opaque)
2112 struct lustre_md *md = opaque;
2113 struct ll_inode_info *lli = ll_i2info(inode);
2117 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2118 PFID(&lli->lli_fid), inode);
2120 /* Core attributes from the MDS first. This is a new inode, and
2121 * the VFS doesn't zero times in the core inode so we have to do
2122 * it ourselves. They will be overwritten by either MDS or OST
2123 * attributes - we just need to make sure they aren't newer.
2125 inode->i_mtime.tv_sec = 0;
2126 inode->i_atime.tv_sec = 0;
2127 inode->i_ctime.tv_sec = 0;
2129 rc = ll_update_inode(inode, md);
2133 /* OIDEBUG(inode); */
2135 #ifdef HAVE_BACKING_DEV_INFO
2136 /* initializing backing dev info. */
2137 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2139 if (S_ISREG(inode->i_mode)) {
2140 struct ll_sb_info *sbi = ll_i2sbi(inode);
2141 inode->i_op = &ll_file_inode_operations;
2142 inode->i_fop = sbi->ll_fop;
2143 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2145 } else if (S_ISDIR(inode->i_mode)) {
2146 inode->i_op = &ll_dir_inode_operations;
2147 inode->i_fop = &ll_dir_operations;
2149 } else if (S_ISLNK(inode->i_mode)) {
2150 inode->i_op = &ll_fast_symlink_inode_operations;
2153 inode->i_op = &ll_special_inode_operations;
2155 init_special_inode(inode, inode->i_mode,
2164 void ll_delete_inode(struct inode *inode)
2166 struct ll_inode_info *lli = ll_i2info(inode);
2167 struct address_space *mapping = &inode->i_data;
2168 unsigned long nrpages;
2171 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2172 /* It is last chance to write out dirty pages,
2173 * otherwise we may lose data while umount.
2175 * If i_nlink is 0 then just discard data. This is safe because
2176 * local inode gets i_nlink 0 from server only for the last
2177 * unlink, so that file is not opened somewhere else
2179 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2180 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2182 truncate_inode_pages_final(mapping);
2184 /* Workaround for LU-118: Note nrpages may not be totally updated when
2185 * truncate_inode_pages() returns, as there can be a page in the process
2186 * of deletion (inside __delete_from_page_cache()) in the specified
2187 * range. Thus mapping->nrpages can be non-zero when this function
2188 * returns even after truncation of the whole mapping. Only do this if
2189 * npages isn't already zero.
2191 nrpages = mapping->nrpages;
2193 xa_lock_irq(&mapping->i_pages);
2194 nrpages = mapping->nrpages;
2195 xa_unlock_irq(&mapping->i_pages);
2196 } /* Workaround end */
2198 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, "
2199 "see https://jira.whamcloud.com/browse/LU-118\n",
2200 ll_i2sbi(inode)->ll_fsname,
2201 PFID(ll_inode2fid(inode)), inode, nrpages);
2203 #ifdef HAVE_SBOPS_EVICT_INODE
2204 ll_clear_inode(inode);
2211 int ll_iocontrol(struct inode *inode, struct file *file,
2212 unsigned int cmd, unsigned long arg)
2214 struct ll_sb_info *sbi = ll_i2sbi(inode);
2215 struct ptlrpc_request *req = NULL;
2220 case FS_IOC_GETFLAGS: {
2221 struct mdt_body *body;
2222 struct md_op_data *op_data;
2224 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2225 0, 0, LUSTRE_OPC_ANY,
2227 if (IS_ERR(op_data))
2228 RETURN(PTR_ERR(op_data));
2230 op_data->op_valid = OBD_MD_FLFLAGS;
2231 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2232 ll_finish_md_op_data(op_data);
2234 CERROR("%s: failure inode "DFID": rc = %d\n",
2235 sbi->ll_md_exp->exp_obd->obd_name,
2236 PFID(ll_inode2fid(inode)), rc);
2240 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2242 flags = body->mbo_flags;
2244 ptlrpc_req_finished(req);
2246 RETURN(put_user(flags, (int __user *)arg));
2248 case FS_IOC_SETFLAGS: {
2250 struct md_op_data *op_data;
2251 struct cl_object *obj;
2252 struct fsxattr fa = { 0 };
2254 if (get_user(flags, (int __user *)arg))
2257 fa.fsx_projid = ll_i2info(inode)->lli_projid;
2258 if (flags & LUSTRE_PROJINHERIT_FL)
2259 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
2261 rc = ll_ioctl_check_project(inode, &fa);
2265 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
2266 LUSTRE_OPC_ANY, NULL);
2267 if (IS_ERR(op_data))
2268 RETURN(PTR_ERR(op_data));
2270 op_data->op_attr_flags = flags;
2271 op_data->op_xvalid |= OP_XVALID_FLAGS;
2272 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
2273 ll_finish_md_op_data(op_data);
2274 ptlrpc_req_finished(req);
2278 ll_update_inode_flags(inode, flags);
2280 obj = ll_i2info(inode)->lli_clob;
2284 OBD_ALLOC_PTR(attr);
2288 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
2300 int ll_flush_ctx(struct inode *inode)
2302 struct ll_sb_info *sbi = ll_i2sbi(inode);
2304 CDEBUG(D_SEC, "flush context for user %d\n",
2305 from_kuid(&init_user_ns, current_uid()));
2307 obd_set_info_async(NULL, sbi->ll_md_exp,
2308 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2310 obd_set_info_async(NULL, sbi->ll_dt_exp,
2311 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2316 /* umount -f client means force down, don't save state */
2317 void ll_umount_begin(struct super_block *sb)
2319 struct ll_sb_info *sbi = ll_s2sbi(sb);
2320 struct obd_device *obd;
2321 struct obd_ioctl_data *ioc_data;
2322 struct l_wait_info lwi;
2323 wait_queue_head_t waitq;
2326 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2327 sb->s_count, atomic_read(&sb->s_active));
2329 obd = class_exp2obd(sbi->ll_md_exp);
2331 CERROR("Invalid MDC connection handle %#llx\n",
2332 sbi->ll_md_exp->exp_handle.h_cookie);
2338 obd = class_exp2obd(sbi->ll_dt_exp);
2340 CERROR("Invalid LOV connection handle %#llx\n",
2341 sbi->ll_dt_exp->exp_handle.h_cookie);
2347 OBD_ALLOC_PTR(ioc_data);
2349 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2350 sizeof *ioc_data, ioc_data, NULL);
2352 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2353 sizeof *ioc_data, ioc_data, NULL);
2355 OBD_FREE_PTR(ioc_data);
2358 /* Really, we'd like to wait until there are no requests outstanding,
2359 * and then continue. For now, we just periodically checking for vfs
2360 * to decrement mnt_cnt and hope to finish it within 10sec.
2362 init_waitqueue_head(&waitq);
2363 lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(10),
2364 cfs_time_seconds(1), NULL, NULL);
2365 l_wait_event(waitq, may_umount(sbi->ll_mnt.mnt), &lwi);
2370 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2372 struct ll_sb_info *sbi = ll_s2sbi(sb);
2373 char *profilenm = get_profile_name(sb);
2377 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
2378 read_only = *flags & MS_RDONLY;
2379 err = obd_set_info_async(NULL, sbi->ll_md_exp,
2380 sizeof(KEY_READ_ONLY),
2381 KEY_READ_ONLY, sizeof(read_only),
2384 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2385 profilenm, read_only ?
2386 "read-only" : "read-write", err);
2391 sb->s_flags |= MS_RDONLY;
2393 sb->s_flags &= ~MS_RDONLY;
2395 if (sbi->ll_flags & LL_SBI_VERBOSE)
2396 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
2397 read_only ? "read-only" : "read-write");
2403 * Cleanup the open handle that is cached on MDT-side.
2405 * For open case, the client side open handling thread may hit error
2406 * after the MDT grant the open. Under such case, the client should
2407 * send close RPC to the MDT as cleanup; otherwise, the open handle
2408 * on the MDT will be leaked there until the client umount or evicted.
2410 * In further, if someone unlinked the file, because the open handle
2411 * holds the reference on such file/object, then it will block the
2412 * subsequent threads that want to locate such object via FID.
2414 * \param[in] sb super block for this file-system
2415 * \param[in] open_req pointer to the original open request
2417 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
2419 struct mdt_body *body;
2420 struct md_op_data *op_data;
2421 struct ptlrpc_request *close_req = NULL;
2422 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
2425 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
2426 OBD_ALLOC_PTR(op_data);
2427 if (op_data == NULL) {
2428 CWARN("%s: cannot allocate op_data to release open handle for "
2429 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
2434 op_data->op_fid1 = body->mbo_fid1;
2435 op_data->op_open_handle = body->mbo_open_handle;
2436 op_data->op_mod_time = ktime_get_real_seconds();
2437 md_close(exp, op_data, NULL, &close_req);
2438 ptlrpc_req_finished(close_req);
2439 ll_finish_md_op_data(op_data);
2444 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
2445 struct super_block *sb, struct lookup_intent *it)
2447 struct ll_sb_info *sbi = NULL;
2448 struct lustre_md md = { NULL };
2452 LASSERT(*inode || sb);
2453 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2454 rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
2455 sbi->ll_md_exp, &md);
2460 rc = ll_update_inode(*inode, &md);
2464 LASSERT(sb != NULL);
2467 * At this point server returns to client's same fid as client
2468 * generated for creating. So using ->fid1 is okay here.
2470 if (!fid_is_sane(&md.body->mbo_fid1)) {
2471 CERROR("%s: Fid is insane "DFID"\n",
2473 PFID(&md.body->mbo_fid1));
2474 GOTO(out, rc = -EINVAL);
2477 *inode = ll_iget(sb, cl_fid_build_ino(&md.body->mbo_fid1,
2478 sbi->ll_flags & LL_SBI_32BIT_API),
2480 if (IS_ERR(*inode)) {
2481 #ifdef CONFIG_FS_POSIX_ACL
2483 posix_acl_release(md.posix_acl);
2484 md.posix_acl = NULL;
2487 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
2489 CERROR("new_inode -fatal: rc %d\n", rc);
2494 /* Handling piggyback layout lock.
2495 * Layout lock can be piggybacked by getattr and open request.
2496 * The lsm can be applied to inode only if it comes with a layout lock
2497 * otherwise correct layout may be overwritten, for example:
2498 * 1. proc1: mdt returns a lsm but not granting layout
2499 * 2. layout was changed by another client
2500 * 3. proc2: refresh layout and layout lock granted
2501 * 4. proc1: to apply a stale layout */
2502 if (it != NULL && it->it_lock_mode != 0) {
2503 struct lustre_handle lockh;
2504 struct ldlm_lock *lock;
2506 lockh.cookie = it->it_lock_handle;
2507 lock = ldlm_handle2lock(&lockh);
2508 LASSERT(lock != NULL);
2509 if (ldlm_has_layout(lock)) {
2510 struct cl_object_conf conf;
2512 memset(&conf, 0, sizeof(conf));
2513 conf.coc_opc = OBJECT_CONF_SET;
2514 conf.coc_inode = *inode;
2515 conf.coc_lock = lock;
2516 conf.u.coc_layout = md.layout;
2517 (void)ll_layout_conf(*inode, &conf);
2519 LDLM_LOCK_PUT(lock);
2525 /* cleanup will be done if necessary */
2526 md_free_lustre_md(sbi->ll_md_exp, &md);
2528 if (rc != 0 && it != NULL && it->it_op & IT_OPEN)
2529 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, req);
2534 int ll_obd_statfs(struct inode *inode, void __user *arg)
2536 struct ll_sb_info *sbi = NULL;
2537 struct obd_export *exp;
2539 struct obd_ioctl_data *data = NULL;
2543 if (!inode || !(sbi = ll_i2sbi(inode)))
2544 GOTO(out_statfs, rc = -EINVAL);
2546 rc = obd_ioctl_getdata(&buf, &len, arg);
2548 GOTO(out_statfs, rc);
2551 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2552 !data->ioc_pbuf1 || !data->ioc_pbuf2)
2553 GOTO(out_statfs, rc = -EINVAL);
2555 if (data->ioc_inllen1 != sizeof(__u32) ||
2556 data->ioc_inllen2 != sizeof(__u32) ||
2557 data->ioc_plen1 != sizeof(struct obd_statfs) ||
2558 data->ioc_plen2 != sizeof(struct obd_uuid))
2559 GOTO(out_statfs, rc = -EINVAL);
2561 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2562 if (type & LL_STATFS_LMV)
2563 exp = sbi->ll_md_exp;
2564 else if (type & LL_STATFS_LOV)
2565 exp = sbi->ll_dt_exp;
2567 GOTO(out_statfs, rc = -ENODEV);
2569 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL);
2571 GOTO(out_statfs, rc);
2573 OBD_FREE_LARGE(buf, len);
2578 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
2579 * be called early to avoid deadlock.
2581 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
2583 if (op_data->op_mea2_sem) {
2584 up_read(op_data->op_mea2_sem);
2585 op_data->op_mea2_sem = NULL;
2588 if (op_data->op_mea1_sem) {
2589 up_read(op_data->op_mea1_sem);
2590 op_data->op_mea1_sem = NULL;
2594 /* this function prepares md_op_data hint for passing it down to MD stack. */
2595 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
2596 struct inode *i1, struct inode *i2,
2597 const char *name, size_t namelen,
2598 __u32 mode, __u32 opc, void *data)
2600 LASSERT(i1 != NULL);
2603 /* Do not reuse namelen for something else. */
2605 return ERR_PTR(-EINVAL);
2607 if (namelen > ll_i2sbi(i1)->ll_namelen)
2608 return ERR_PTR(-ENAMETOOLONG);
2610 if (!lu_name_is_valid_2(name, namelen))
2611 return ERR_PTR(-EINVAL);
2614 if (op_data == NULL)
2615 OBD_ALLOC_PTR(op_data);
2617 if (op_data == NULL)
2618 return ERR_PTR(-ENOMEM);
2620 ll_i2gids(op_data->op_suppgids, i1, i2);
2621 op_data->op_fid1 = *ll_inode2fid(i1);
2622 op_data->op_default_stripe_offset = -1;
2624 if (S_ISDIR(i1->i_mode)) {
2625 down_read(&ll_i2info(i1)->lli_lsm_sem);
2626 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
2627 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
2628 if (opc == LUSTRE_OPC_MKDIR)
2629 op_data->op_default_stripe_offset =
2630 ll_i2info(i1)->lli_def_stripe_offset;
2634 op_data->op_fid2 = *ll_inode2fid(i2);
2635 if (S_ISDIR(i2->i_mode)) {
2637 down_read(&ll_i2info(i2)->lli_lsm_sem);
2638 op_data->op_mea2_sem =
2639 &ll_i2info(i2)->lli_lsm_sem;
2641 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
2644 fid_zero(&op_data->op_fid2);
2647 if (ll_i2sbi(i1)->ll_flags & LL_SBI_64BIT_HASH)
2648 op_data->op_cli_flags |= CLI_HASH64;
2650 if (ll_need_32bit_api(ll_i2sbi(i1)))
2651 op_data->op_cli_flags |= CLI_API32;
2653 op_data->op_name = name;
2654 op_data->op_namelen = namelen;
2655 op_data->op_mode = mode;
2656 op_data->op_mod_time = ktime_get_real_seconds();
2657 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2658 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2659 op_data->op_cap = cfs_curproc_cap_pack();
2660 op_data->op_mds = 0;
2661 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
2662 filename_is_volatile(name, namelen, &op_data->op_mds)) {
2663 op_data->op_bias |= MDS_CREATE_VOLATILE;
2665 op_data->op_data = data;
2670 void ll_finish_md_op_data(struct md_op_data *op_data)
2672 ll_unlock_md_op_lsm(op_data);
2673 security_release_secctx(op_data->op_file_secctx,
2674 op_data->op_file_secctx_size);
2675 OBD_FREE_PTR(op_data);
2678 #ifdef HAVE_SUPEROPS_USE_DENTRY
2679 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
2681 int ll_show_options(struct seq_file *seq, struct vfsmount *vfs)
2684 struct ll_sb_info *sbi;
2686 #ifdef HAVE_SUPEROPS_USE_DENTRY
2687 LASSERT((seq != NULL) && (dentry != NULL));
2688 sbi = ll_s2sbi(dentry->d_sb);
2690 LASSERT((seq != NULL) && (vfs != NULL));
2691 sbi = ll_s2sbi(vfs->mnt_sb);
2694 if (sbi->ll_flags & LL_SBI_NOLCK)
2695 seq_puts(seq, ",nolock");
2697 if (sbi->ll_flags & LL_SBI_FLOCK)
2698 seq_puts(seq, ",flock");
2700 if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
2701 seq_puts(seq, ",localflock");
2703 if (sbi->ll_flags & LL_SBI_USER_XATTR)
2704 seq_puts(seq, ",user_xattr");
2706 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
2707 seq_puts(seq, ",lazystatfs");
2709 if (sbi->ll_flags & LL_SBI_USER_FID2PATH)
2710 seq_puts(seq, ",user_fid2path");
2712 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
2713 seq_puts(seq, ",always_ping");
2719 * Get obd name by cmd, and copy out to user space
2721 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
2723 struct ll_sb_info *sbi = ll_i2sbi(inode);
2724 struct obd_device *obd;
2727 if (cmd == OBD_IOC_GETDTNAME)
2728 obd = class_exp2obd(sbi->ll_dt_exp);
2729 else if (cmd == OBD_IOC_GETMDNAME)
2730 obd = class_exp2obd(sbi->ll_md_exp);
2737 if (copy_to_user((void __user *)arg, obd->obd_name,
2738 strlen(obd->obd_name) + 1))
2744 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
2751 p.mnt = current->fs->root.mnt;
2753 path = d_path(&p, buf, bufsize);
2758 void ll_dirty_page_discard_warn(struct page *page, int ioret)
2760 char *buf, *path = NULL;
2761 struct dentry *dentry = NULL;
2762 struct inode *inode = page->mapping->host;
2764 /* this can be called inside spin lock so use GFP_ATOMIC. */
2765 buf = (char *)__get_free_page(GFP_ATOMIC);
2767 dentry = d_find_alias(page->mapping->host);
2769 path = ll_d_path(dentry, buf, PAGE_SIZE);
2773 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
2774 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
2775 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
2776 PFID(ll_inode2fid(inode)),
2777 (path && !IS_ERR(path)) ? path : "", ioret);
2783 free_page((unsigned long)buf);
2786 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
2787 struct lov_user_md **kbuf)
2789 struct lov_user_md lum;
2793 if (copy_from_user(&lum, md, sizeof(lum)))
2796 lum_size = ll_lov_user_md_size(&lum);
2800 OBD_ALLOC(*kbuf, lum_size);
2804 if (copy_from_user(*kbuf, md, lum_size) != 0) {
2805 OBD_FREE(*kbuf, lum_size);
2813 * Compute llite root squash state after a change of root squash
2814 * configuration setting or add/remove of a lnet nid
2816 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
2818 struct root_squash_info *squash = &sbi->ll_squash;
2821 struct lnet_process_id id;
2823 /* Update norootsquash flag */
2824 down_write(&squash->rsi_sem);
2825 if (list_empty(&squash->rsi_nosquash_nids))
2826 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
2828 /* Do not apply root squash as soon as one of our NIDs is
2829 * in the nosquash_nids list */
2832 while (LNetGetId(i++, &id) != -ENOENT) {
2833 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
2835 if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) {
2841 sbi->ll_flags |= LL_SBI_NOROOTSQUASH;
2843 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
2845 up_write(&squash->rsi_sem);
2849 * Parse linkea content to extract information about a given hardlink
2851 * \param[in] ldata - Initialized linkea data
2852 * \param[in] linkno - Link identifier
2853 * \param[out] parent_fid - The entry's parent FID
2854 * \param[out] ln - Entry name destination buffer
2856 * \retval 0 on success
2857 * \retval Appropriate negative error code on failure
2859 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
2860 struct lu_fid *parent_fid, struct lu_name *ln)
2866 rc = linkea_init_with_rec(ldata);
2870 if (linkno >= ldata->ld_leh->leh_reccount)
2871 /* beyond last link */
2874 linkea_first_entry(ldata);
2875 for (idx = 0; ldata->ld_lee != NULL; idx++) {
2876 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
2881 linkea_next_entry(ldata);
2891 * Get parent FID and name of an identified link. Operation is performed for
2892 * a given link number, letting the caller iterate over linkno to list one or
2893 * all links of an entry.
2895 * \param[in] file - File descriptor against which to perform the operation
2896 * \param[in,out] arg - User-filled structure containing the linkno to operate
2897 * on and the available size. It is eventually filled with
2898 * the requested information or left untouched on error
2900 * \retval - 0 on success
2901 * \retval - Appropriate negative error code on failure
2903 int ll_getparent(struct file *file, struct getparent __user *arg)
2905 struct inode *inode = file_inode(file);
2906 struct linkea_data *ldata;
2907 struct lu_buf buf = LU_BUF_NULL;
2909 struct lu_fid parent_fid;
2916 if (!cfs_capable(CFS_CAP_DAC_READ_SEARCH) &&
2917 !(ll_i2sbi(inode)->ll_flags & LL_SBI_USER_FID2PATH))
2920 if (get_user(name_size, &arg->gp_name_size))
2923 if (get_user(linkno, &arg->gp_linkno))
2926 if (name_size > PATH_MAX)
2929 OBD_ALLOC(ldata, sizeof(*ldata));
2933 rc = linkea_data_new(ldata, &buf);
2935 GOTO(ldata_free, rc);
2937 #ifdef HAVE_XATTR_HANDLER_FLAGS
2938 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
2939 buf.lb_len, OBD_MD_FLXATTR);
2941 rc = ll_getxattr(file_dentry(file), XATTR_NAME_LINK, buf.lb_buf,
2943 #endif /* HAVE_XATTR_HANDLER_FLAGS */
2947 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
2951 if (ln.ln_namelen >= name_size)
2952 GOTO(lb_free, rc = -EOVERFLOW);
2954 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
2955 GOTO(lb_free, rc = -EFAULT);
2957 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
2958 GOTO(lb_free, rc = -EFAULT);
2960 if (put_user('\0', arg->gp_name + ln.ln_namelen))
2961 GOTO(lb_free, rc = -EFAULT);
2966 OBD_FREE(ldata, sizeof(*ldata));