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/cpu.h>
40 #include <linux/module.h>
41 #include <linux/random.h>
42 #include <linux/statfs.h>
43 #include <linux/time.h>
44 #include <linux/types.h>
45 #include <libcfs/linux/linux-uuid.h>
46 #include <linux/version.h>
48 #include <linux/user_namespace.h>
49 #include <linux/delay.h>
50 #include <linux/uidgid.h>
51 #include <linux/security.h>
53 #ifndef HAVE_CPUS_READ_LOCK
54 #include <libcfs/linux/linux-cpu.h>
56 #include <uapi/linux/lustre/lustre_ioctl.h>
57 #ifdef HAVE_UAPI_LINUX_MOUNT_H
58 #include <uapi/linux/mount.h>
61 #include <lustre_ha.h>
62 #include <lustre_dlm.h>
63 #include <lprocfs_status.h>
64 #include <lustre_disk.h>
65 #include <uapi/linux/lustre/lustre_param.h>
66 #include <lustre_log.h>
67 #include <cl_object.h>
68 #include <obd_cksum.h>
69 #include "llite_internal.h"
71 struct kmem_cache *ll_file_data_slab;
74 #define log2(n) ffz(~(n))
78 * If there is only one number of core visible to Lustre,
79 * async readahead will be disabled, to avoid massive over
80 * subscription, we use 1/2 of active cores as default max
81 * async readahead requests.
83 static inline unsigned int ll_get_ra_async_max_active(void)
85 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
88 static struct ll_sb_info *ll_init_sbi(void)
90 struct workqueue_attrs attrs = { };
92 struct ll_sb_info *sbi = NULL;
94 unsigned long lru_page_max;
103 RETURN(ERR_PTR(-ENOMEM));
105 rc = pcc_super_init(&sbi->ll_pcc_super);
109 spin_lock_init(&sbi->ll_lock);
110 mutex_init(&sbi->ll_lco.lco_lock);
111 spin_lock_init(&sbi->ll_pp_extent_lock);
112 spin_lock_init(&sbi->ll_process_lock);
113 sbi->ll_rw_stats_on = 0;
114 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
117 pages = si.totalram - si.totalhigh;
118 lru_page_max = pages / 2;
120 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
121 sbi->ll_ra_info.ll_readahead_wq =
122 alloc_workqueue("ll-readahead-wq", WQ_UNBOUND,
123 sbi->ll_ra_info.ra_async_max_active);
124 if (!sbi->ll_ra_info.ll_readahead_wq)
125 GOTO(out_pcc, rc = -ENOMEM);
127 mask = cfs_cpt_cpumask(cfs_cpt_tab, CFS_CPT_ANY);
128 if (mask && alloc_cpumask_var(&attrs.cpumask, GFP_KERNEL)) {
129 cpumask_copy(attrs.cpumask, *mask);
131 cfs_apply_workqueue_attrs(sbi->ll_ra_info.ll_readahead_wq,
134 free_cpumask_var(attrs.cpumask);
137 /* initialize ll_cache data */
138 sbi->ll_cache = cl_cache_init(lru_page_max);
139 if (sbi->ll_cache == NULL)
140 GOTO(out_destroy_ra, rc = -ENOMEM);
142 sbi->ll_ra_info.ra_max_pages_per_file = min(pages / 32,
143 SBI_DEFAULT_READ_AHEAD_MAX);
144 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
145 sbi->ll_ra_info.ra_max_pages_per_file;
146 sbi->ll_ra_info.ra_max_pages = sbi->ll_ra_info.ra_max_pages_per_file;
147 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
148 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
150 sbi->ll_flags |= LL_SBI_VERBOSE;
151 #ifdef ENABLE_CHECKSUM
152 sbi->ll_flags |= LL_SBI_CHECKSUM;
155 sbi->ll_flags |= LL_SBI_FLOCK;
158 #ifdef HAVE_LRU_RESIZE_SUPPORT
159 sbi->ll_flags |= LL_SBI_LRU_RESIZE;
161 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
163 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
164 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
166 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
170 /* metadata statahead is enabled by default */
171 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
172 sbi->ll_sa_max = LL_SA_RPC_DEF;
173 atomic_set(&sbi->ll_sa_total, 0);
174 atomic_set(&sbi->ll_sa_wrong, 0);
175 atomic_set(&sbi->ll_sa_running, 0);
176 atomic_set(&sbi->ll_agl_total, 0);
177 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
178 sbi->ll_flags |= LL_SBI_FAST_READ;
179 sbi->ll_flags |= LL_SBI_TINY_WRITE;
182 sbi->ll_squash.rsi_uid = 0;
183 sbi->ll_squash.rsi_gid = 0;
184 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
185 spin_lock_init(&sbi->ll_squash.rsi_lock);
187 /* Per-filesystem file heat */
188 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
189 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
192 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
194 pcc_super_fini(&sbi->ll_pcc_super);
200 static void ll_free_sbi(struct super_block *sb)
202 struct ll_sb_info *sbi = ll_s2sbi(sb);
206 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
207 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
208 if (sbi->ll_ra_info.ll_readahead_wq)
209 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
210 if (sbi->ll_cache != NULL) {
211 cl_cache_decref(sbi->ll_cache);
212 sbi->ll_cache = NULL;
214 pcc_super_fini(&sbi->ll_pcc_super);
215 OBD_FREE(sbi, sizeof(*sbi));
220 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
222 struct inode *root = NULL;
223 struct ll_sb_info *sbi = ll_s2sbi(sb);
224 struct obd_statfs *osfs = NULL;
225 struct ptlrpc_request *request = NULL;
226 struct obd_connect_data *data = NULL;
227 struct obd_uuid *uuid;
228 struct md_op_data *op_data;
229 struct lustre_md lmd;
231 int size, err, checksum;
234 sbi->ll_md_obd = class_name2obd(md);
235 if (!sbi->ll_md_obd) {
236 CERROR("MD %s: not setup or attached\n", md);
250 /* pass client page size via ocd_grant_blkbits, the server should report
251 * back its backend blocksize for grant calculation purpose */
252 data->ocd_grant_blkbits = PAGE_SHIFT;
254 /* indicate MDT features supported by this client */
255 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
256 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
257 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
258 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
259 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
260 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
261 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
262 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
263 OBD_CONNECT_64BITHASH |
264 OBD_CONNECT_EINPROGRESS |
265 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
266 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
267 OBD_CONNECT_MAX_EASIZE |
268 OBD_CONNECT_FLOCK_DEAD |
269 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
270 OBD_CONNECT_OPEN_BY_FID |
271 OBD_CONNECT_DIR_STRIPE |
272 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
273 OBD_CONNECT_SUBTREE |
274 OBD_CONNECT_MULTIMODRPCS |
275 OBD_CONNECT_GRANT_PARAM |
276 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
278 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
279 OBD_CONNECT2_SUM_STATFS |
280 OBD_CONNECT2_OVERSTRIPING |
282 OBD_CONNECT2_LOCK_CONVERT |
283 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
284 OBD_CONNECT2_INC_XID |
286 OBD_CONNECT2_ASYNC_DISCARD |
290 #ifdef HAVE_LRU_RESIZE_SUPPORT
291 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
292 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
294 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
295 data->ocd_connect_flags |= OBD_CONNECT_ACL | OBD_CONNECT_UMASK |
296 OBD_CONNECT_LARGE_ACL;
299 data->ocd_cksum_types = obd_cksum_types_supported_client();
301 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
302 /* flag mdc connection as lightweight, only used for test
303 * purpose, use with care */
304 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
306 data->ocd_ibits_known = MDS_INODELOCK_FULL;
307 data->ocd_version = LUSTRE_VERSION_CODE;
309 if (sb->s_flags & SB_RDONLY)
310 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
311 if (sbi->ll_flags & LL_SBI_USER_XATTR)
312 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
315 /* Setting this indicates we correctly support S_NOSEC (See kernel
316 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
318 sb->s_flags |= SB_NOSEC;
321 if (sbi->ll_flags & LL_SBI_FLOCK)
322 sbi->ll_fop = &ll_file_operations_flock;
323 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
324 sbi->ll_fop = &ll_file_operations;
326 sbi->ll_fop = &ll_file_operations_noflock;
328 /* always ping even if server suppress_pings */
329 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
330 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
332 obd_connect_set_secctx(data);
334 #if defined(CONFIG_SECURITY)
335 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
338 data->ocd_brw_size = MD_MAX_BRW_SIZE;
340 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
341 &sbi->ll_sb_uuid, data, sbi->ll_cache);
343 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
344 "recovery, of which this client is not a "
345 "part. Please wait for recovery to complete,"
346 " abort, or time out.\n", md);
349 CERROR("cannot connect to %s: rc = %d\n", md, err);
353 sbi->ll_md_exp->exp_connect_data = *data;
355 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
356 LUSTRE_SEQ_METADATA);
358 CERROR("%s: Can't init metadata layer FID infrastructure, "
359 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
363 /* For mount, we only need fs info from MDT0, and also in DNE, it
364 * can make sure the client can be mounted as long as MDT0 is
366 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
367 ktime_get_seconds() - sbi->ll_statfs_max_age,
368 OBD_STATFS_FOR_MDT0);
370 GOTO(out_md_fid, err);
372 /* This needs to be after statfs to ensure connect has finished.
373 * Note that "data" does NOT contain the valid connect reply.
374 * If connecting to a 1.8 server there will be no LMV device, so
375 * we can access the MDC export directly and exp_connect_flags will
376 * be non-zero, but if accessing an upgraded 2.1 server it will
377 * have the correct flags filled in.
378 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
379 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
380 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
381 valid != CLIENT_CONNECT_MDT_REQD) {
384 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
385 obd_connect_flags2str(buf, PAGE_SIZE,
386 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
387 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
388 "feature(s) needed for correct operation "
389 "of this client (%s). Please upgrade "
390 "server or downgrade client.\n",
391 sbi->ll_md_exp->exp_obd->obd_name, buf);
392 OBD_FREE(buf, PAGE_SIZE);
393 GOTO(out_md_fid, err = -EPROTO);
396 size = sizeof(*data);
397 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
398 KEY_CONN_DATA, &size, data);
400 CERROR("%s: Get connect data failed: rc = %d\n",
401 sbi->ll_md_exp->exp_obd->obd_name, err);
402 GOTO(out_md_fid, err);
405 LASSERT(osfs->os_bsize);
406 sb->s_blocksize = osfs->os_bsize;
407 sb->s_blocksize_bits = log2(osfs->os_bsize);
408 sb->s_magic = LL_SUPER_MAGIC;
409 sb->s_maxbytes = MAX_LFS_FILESIZE;
410 sbi->ll_namelen = osfs->os_namelen;
411 sbi->ll_mnt.mnt = current->fs->root.mnt;
413 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
414 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
415 LCONSOLE_INFO("Disabling user_xattr feature because "
416 "it is not supported on the server\n");
417 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
420 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
422 sb->s_flags |= SB_POSIXACL;
424 sbi->ll_flags |= LL_SBI_ACL;
426 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
428 sb->s_flags &= ~SB_POSIXACL;
430 sbi->ll_flags &= ~LL_SBI_ACL;
433 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
434 sbi->ll_flags |= LL_SBI_64BIT_HASH;
436 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
437 sbi->ll_flags |= LL_SBI_LAYOUT_LOCK;
439 if (obd_connect_has_secctx(data))
440 sbi->ll_flags |= LL_SBI_FILE_SECCTX;
442 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
443 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
444 LCONSOLE_INFO("%s: disabling xattr cache due to "
445 "unknown maximum xattr size.\n", dt);
446 } else if (!sbi->ll_xattr_cache_set) {
447 /* If xattr_cache is already set (no matter 0 or 1)
448 * during processing llog, it won't be enabled here. */
449 sbi->ll_flags |= LL_SBI_XATTR_CACHE;
450 sbi->ll_xattr_cache_enabled = 1;
454 sbi->ll_dt_obd = class_name2obd(dt);
455 if (!sbi->ll_dt_obd) {
456 CERROR("DT %s: not setup or attached\n", dt);
457 GOTO(out_md_fid, err = -ENODEV);
460 /* pass client page size via ocd_grant_blkbits, the server should report
461 * back its backend blocksize for grant calculation purpose */
462 data->ocd_grant_blkbits = PAGE_SHIFT;
464 /* indicate OST features supported by this client */
465 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
466 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
467 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
468 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
469 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
470 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
471 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
472 OBD_CONNECT_EINPROGRESS |
473 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
474 OBD_CONNECT_LAYOUTLOCK |
475 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
476 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
477 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
478 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
479 OBD_CONNECT2_INC_XID;
481 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
482 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
484 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
485 * disabled by default, because it can still be enabled on the
486 * fly via /sys. As a consequence, we still need to come to an
487 * agreement on the supported algorithms at connect time
489 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
491 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
492 data->ocd_cksum_types = OBD_CKSUM_ADLER;
494 data->ocd_cksum_types = obd_cksum_types_supported_client();
496 #ifdef HAVE_LRU_RESIZE_SUPPORT
497 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
499 /* always ping even if server suppress_pings */
500 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
501 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
503 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
504 "ocd_grant: %d\n", data->ocd_connect_flags,
505 data->ocd_version, data->ocd_grant);
507 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
508 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
510 data->ocd_brw_size = DT_MAX_BRW_SIZE;
512 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
513 &sbi->ll_sb_uuid, data, sbi->ll_cache);
515 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
516 "recovery, of which this client is not a "
517 "part. Please wait for recovery to "
518 "complete, abort, or time out.\n", dt);
521 CERROR("%s: Cannot connect to %s: rc = %d\n",
522 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
526 sbi->ll_dt_exp->exp_connect_data = *data;
528 /* Don't change value if it was specified in the config log */
529 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
530 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
531 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
532 (data->ocd_brw_size >> PAGE_SHIFT));
533 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
534 sbi->ll_ra_info.ra_max_pages_per_file)
535 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
536 sbi->ll_ra_info.ra_max_pages_per_file;
539 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
540 LUSTRE_SEQ_METADATA);
542 CERROR("%s: Can't init data layer FID infrastructure, "
543 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
547 mutex_lock(&sbi->ll_lco.lco_lock);
548 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
549 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
550 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
551 mutex_unlock(&sbi->ll_lco.lco_lock);
553 fid_zero(&sbi->ll_root_fid);
554 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
557 CERROR("cannot mds_connect: rc = %d\n", err);
558 GOTO(out_lock_cn_cb, err);
560 if (!fid_is_sane(&sbi->ll_root_fid)) {
561 CERROR("%s: Invalid root fid "DFID" during mount\n",
562 sbi->ll_md_exp->exp_obd->obd_name,
563 PFID(&sbi->ll_root_fid));
564 GOTO(out_lock_cn_cb, err = -EINVAL);
566 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
568 sb->s_op = &lustre_super_operations;
569 sb->s_xattr = ll_xattr_handlers;
570 #if THREAD_SIZE >= 8192 /*b=17630*/
571 sb->s_export_op = &lustre_export_operations;
575 * XXX: move this to after cbd setup? */
576 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
577 if (sbi->ll_flags & LL_SBI_ACL)
578 valid |= OBD_MD_FLACL;
580 OBD_ALLOC_PTR(op_data);
582 GOTO(out_lock_cn_cb, err = -ENOMEM);
584 op_data->op_fid1 = sbi->ll_root_fid;
585 op_data->op_mode = 0;
586 op_data->op_valid = valid;
588 err = md_getattr(sbi->ll_md_exp, op_data, &request);
590 OBD_FREE_PTR(op_data);
592 CERROR("%s: md_getattr failed for root: rc = %d\n",
593 sbi->ll_md_exp->exp_obd->obd_name, err);
594 GOTO(out_lock_cn_cb, err);
597 err = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
598 sbi->ll_md_exp, &lmd);
600 CERROR("failed to understand root inode md: rc = %d\n", err);
601 ptlrpc_req_finished(request);
602 GOTO(out_lock_cn_cb, err);
605 LASSERT(fid_is_sane(&sbi->ll_root_fid));
606 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid,
607 sbi->ll_flags & LL_SBI_32BIT_API),
609 md_free_lustre_md(sbi->ll_md_exp, &lmd);
610 ptlrpc_req_finished(request);
613 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
615 posix_acl_release(lmd.posix_acl);
616 lmd.posix_acl = NULL;
619 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
621 CERROR("%s: bad ll_iget() for root: rc = %d\n",
622 sbi->ll_fsname, err);
626 checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
627 if (sbi->ll_checksum_set) {
628 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
629 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
630 sizeof(checksum), &checksum, NULL);
632 CERROR("%s: Set checksum failed: rc = %d\n",
633 sbi->ll_dt_exp->exp_obd->obd_name, err);
639 sb->s_root = d_make_root(root);
640 if (sb->s_root == NULL) {
642 CERROR("%s: can't make root dentry: rc = %d\n",
643 sbi->ll_fsname, err);
647 sbi->ll_sdev_orig = sb->s_dev;
649 /* We set sb->s_dev equal on all lustre clients in order to support
650 * NFS export clustering. NFSD requires that the FSID be the same
652 /* s_dev is also used in lt_compare() to compare two fs, but that is
653 * only a node-local comparison. */
654 uuid = obd_get_uuid(sbi->ll_md_exp);
656 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
663 if (sbi->ll_dt_obd) {
664 err = sysfs_create_link(&sbi->ll_kset.kobj,
665 &sbi->ll_dt_obd->obd_kset.kobj,
666 sbi->ll_dt_obd->obd_type->typ_name);
668 CERROR("%s: could not register %s in llite: rc = %d\n",
669 dt, sbi->ll_fsname, err);
674 if (sbi->ll_md_obd) {
675 err = sysfs_create_link(&sbi->ll_kset.kobj,
676 &sbi->ll_md_obd->obd_kset.kobj,
677 sbi->ll_md_obd->obd_type->typ_name);
679 CERROR("%s: could not register %s in llite: rc = %d\n",
680 md, sbi->ll_fsname, err);
690 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
692 obd_disconnect(sbi->ll_dt_exp);
693 sbi->ll_dt_exp = NULL;
694 sbi->ll_dt_obd = NULL;
696 obd_fid_fini(sbi->ll_md_exp->exp_obd);
698 obd_disconnect(sbi->ll_md_exp);
699 sbi->ll_md_exp = NULL;
700 sbi->ll_md_obd = NULL;
709 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
713 size = sizeof(*lmmsize);
714 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
715 KEY_MAX_EASIZE, &size, lmmsize);
717 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
718 sbi->ll_dt_exp->exp_obd->obd_name, rc);
722 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
725 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
726 KEY_MAX_EASIZE, &size, lmmsize);
728 CERROR("Get max mdsize error rc %d\n", rc);
730 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
736 * Get the value of the default_easize parameter.
738 * \see client_obd::cl_default_mds_easize
740 * \param[in] sbi superblock info for this filesystem
741 * \param[out] lmmsize pointer to storage location for value
743 * \retval 0 on success
744 * \retval negative negated errno on failure
746 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
751 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
752 KEY_DEFAULT_EASIZE, &size, lmmsize);
754 CERROR("Get default mdsize error rc %d\n", rc);
760 * Set the default_easize parameter to the given value.
762 * \see client_obd::cl_default_mds_easize
764 * \param[in] sbi superblock info for this filesystem
765 * \param[in] lmmsize the size to set
767 * \retval 0 on success
768 * \retval negative negated errno on failure
770 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
774 if (lmmsize < sizeof(struct lov_mds_md) ||
775 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
778 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
779 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
780 sizeof(int), &lmmsize, NULL);
785 static void client_common_put_super(struct super_block *sb)
787 struct ll_sb_info *sbi = ll_s2sbi(sb);
792 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
793 obd_disconnect(sbi->ll_dt_exp);
794 sbi->ll_dt_exp = NULL;
796 ll_debugfs_unregister_super(sb);
798 obd_fid_fini(sbi->ll_md_exp->exp_obd);
799 obd_disconnect(sbi->ll_md_exp);
800 sbi->ll_md_exp = NULL;
805 void ll_kill_super(struct super_block *sb)
807 struct ll_sb_info *sbi;
811 if (!(sb->s_flags & SB_ACTIVE))
815 /* we need restore s_dev from changed for clustred NFS before put_super
816 * because new kernels have cached s_dev and change sb->s_dev in
817 * put_super not affected real removing devices */
819 sb->s_dev = sbi->ll_sdev_orig;
821 /* wait running statahead threads to quit */
822 while (atomic_read(&sbi->ll_sa_running) > 0)
823 schedule_timeout_uninterruptible(
824 cfs_time_seconds(1) >> 3);
830 static inline int ll_set_opt(const char *opt, char *data, int fl)
832 if (strncmp(opt, data, strlen(opt)) != 0)
838 /* non-client-specific mount options are parsed in lmd_parse */
839 static int ll_options(char *options, struct ll_sb_info *sbi)
842 char *s1 = options, *s2;
843 int *flags = &sbi->ll_flags;
849 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
852 CDEBUG(D_SUPER, "next opt=%s\n", s1);
853 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
858 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
860 *flags = (*flags & ~LL_SBI_LOCALFLOCK) | tmp;
863 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
865 *flags = (*flags & ~LL_SBI_FLOCK) | tmp;
868 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
873 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
878 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
883 tmp = ll_set_opt("context", s1, 1);
886 tmp = ll_set_opt("fscontext", s1, 1);
889 tmp = ll_set_opt("defcontext", s1, 1);
892 tmp = ll_set_opt("rootcontext", s1, 1);
895 tmp = ll_set_opt("user_fid2path", s1, LL_SBI_USER_FID2PATH);
900 tmp = ll_set_opt("nouser_fid2path", s1, LL_SBI_USER_FID2PATH);
906 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
909 sbi->ll_checksum_set = 1;
912 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
915 sbi->ll_checksum_set = 1;
918 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
923 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
928 tmp = ll_set_opt("lazystatfs", s1, LL_SBI_LAZYSTATFS);
933 tmp = ll_set_opt("nolazystatfs", s1, LL_SBI_LAZYSTATFS);
938 tmp = ll_set_opt("32bitapi", s1, LL_SBI_32BIT_API);
943 tmp = ll_set_opt("verbose", s1, LL_SBI_VERBOSE);
948 tmp = ll_set_opt("noverbose", s1, LL_SBI_VERBOSE);
953 tmp = ll_set_opt("always_ping", s1, LL_SBI_ALWAYS_PING);
958 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
964 s2 = strchr(s1, ',');
972 void ll_lli_init(struct ll_inode_info *lli)
974 lli->lli_inode_magic = LLI_INODE_MAGIC;
976 spin_lock_init(&lli->lli_lock);
977 lli->lli_posix_acl = NULL;
978 /* Do not set lli_fid, it has been initialized already. */
979 fid_zero(&lli->lli_pfid);
980 lli->lli_mds_read_och = NULL;
981 lli->lli_mds_write_och = NULL;
982 lli->lli_mds_exec_och = NULL;
983 lli->lli_open_fd_read_count = 0;
984 lli->lli_open_fd_write_count = 0;
985 lli->lli_open_fd_exec_count = 0;
986 mutex_init(&lli->lli_och_mutex);
987 spin_lock_init(&lli->lli_agl_lock);
988 spin_lock_init(&lli->lli_layout_lock);
989 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
990 lli->lli_clob = NULL;
992 init_rwsem(&lli->lli_xattrs_list_rwsem);
993 mutex_init(&lli->lli_xattrs_enq_lock);
995 LASSERT(lli->lli_vfs_inode.i_mode != 0);
996 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
997 lli->lli_opendir_key = NULL;
999 spin_lock_init(&lli->lli_sa_lock);
1000 lli->lli_opendir_pid = 0;
1001 lli->lli_sa_enabled = 0;
1002 init_rwsem(&lli->lli_lsm_sem);
1004 mutex_init(&lli->lli_size_mutex);
1005 lli->lli_symlink_name = NULL;
1006 ll_trunc_sem_init(&lli->lli_trunc_sem);
1007 range_lock_tree_init(&lli->lli_write_tree);
1008 init_rwsem(&lli->lli_glimpse_sem);
1009 lli->lli_glimpse_time = ktime_set(0, 0);
1010 INIT_LIST_HEAD(&lli->lli_agl_list);
1011 lli->lli_agl_index = 0;
1012 lli->lli_async_rc = 0;
1013 spin_lock_init(&lli->lli_heat_lock);
1014 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1015 lli->lli_heat_flags = 0;
1016 mutex_init(&lli->lli_pcc_lock);
1017 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1018 lli->lli_pcc_inode = NULL;
1019 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1020 lli->lli_pcc_generation = 0;
1021 mutex_init(&lli->lli_group_mutex);
1022 lli->lli_group_users = 0;
1023 lli->lli_group_gid = 0;
1025 mutex_init(&lli->lli_layout_mutex);
1026 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1029 #define MAX_STRING_SIZE 128
1031 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1033 #define LSI_BDI_INITIALIZED 0x00400000
1035 #ifndef HAVE_BDI_CAP_MAP_COPY
1036 # define BDI_CAP_MAP_COPY 0
1039 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1041 struct lustre_sb_info *lsi = s2lsi(sb);
1042 char buf[MAX_STRING_SIZE];
1046 err = bdi_init(&lsi->lsi_bdi);
1050 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1051 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1052 lsi->lsi_bdi.name = "lustre";
1053 va_start(args, fmt);
1054 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1056 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1059 sb->s_bdi = &lsi->lsi_bdi;
1063 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1065 int ll_fill_super(struct super_block *sb)
1067 struct lustre_profile *lprof = NULL;
1068 struct lustre_sb_info *lsi = s2lsi(sb);
1069 struct ll_sb_info *sbi = NULL;
1070 char *dt = NULL, *md = NULL;
1071 char *profilenm = get_profile_name(sb);
1072 struct config_llog_instance *cfg;
1073 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1074 const int instlen = LUSTRE_MAXINSTANCE + 2;
1075 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1076 char name[MAX_STRING_SIZE];
1085 /* for ASLR, to map between cfg_instance and hashed ptr */
1086 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1087 profilenm, cfg_instance, sb);
1091 GOTO(out_free_cfg, err = -ENOMEM);
1093 /* client additional sb info */
1094 lsi->lsi_llsbi = sbi = ll_init_sbi();
1096 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1098 err = ll_options(lsi->lsi_lmd->lmd_opts, sbi);
1100 GOTO(out_free_cfg, err);
1102 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1103 sb->s_d_op = &ll_d_ops;
1106 generate_random_uuid(uuid.b);
1107 snprintf(sbi->ll_sb_uuid.uuid, UUID_SIZE, "%pU", uuid.b);
1109 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1112 len = strlen(profilenm);
1113 ptr = strrchr(profilenm, '-');
1114 if (ptr && (strcmp(ptr, "-client") == 0))
1117 if (len > LUSTRE_MAXFSNAME) {
1118 if (unlikely(len >= MAX_STRING_SIZE))
1119 len = MAX_STRING_SIZE - 1;
1120 strncpy(name, profilenm, len);
1122 err = -ENAMETOOLONG;
1123 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1124 name, LUSTRE_MAXFSNAME, err);
1125 GOTO(out_free_cfg, err);
1127 strncpy(sbi->ll_fsname, profilenm, len);
1128 sbi->ll_fsname[len] = '\0';
1131 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1132 profilenm, cfg_instance);
1134 err = super_setup_bdi_name(sb, "%s", name);
1136 GOTO(out_free_cfg, err);
1138 /* Call ll_debugfs_register_super() before lustre_process_log()
1139 * so that "llite.*.*" params can be processed correctly.
1141 err = ll_debugfs_register_super(sb, name);
1143 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1144 sbi->ll_fsname, err);
1148 /* The cfg_instance is a value unique to this super, in case some
1149 * joker tries to mount the same fs at two mount points.
1151 cfg->cfg_instance = cfg_instance;
1152 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1153 cfg->cfg_callback = class_config_llog_handler;
1154 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1155 /* set up client obds */
1156 err = lustre_process_log(sb, profilenm, cfg);
1158 GOTO(out_debugfs, err);
1160 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1161 lprof = class_get_profile(profilenm);
1162 if (lprof == NULL) {
1163 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1164 " read from the MGS. Does that filesystem "
1165 "exist?\n", profilenm);
1166 GOTO(out_debugfs, err = -EINVAL);
1168 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1169 lprof->lp_md, lprof->lp_dt);
1171 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1172 OBD_ALLOC(dt, dt_len);
1174 GOTO(out_profile, err = -ENOMEM);
1175 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1177 md_len = strlen(lprof->lp_md) + instlen + 2;
1178 OBD_ALLOC(md, md_len);
1180 GOTO(out_free_dt, err = -ENOMEM);
1181 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1183 /* connections, registrations, sb setup */
1184 err = client_common_fill_super(sb, md, dt);
1186 GOTO(out_free_md, err);
1188 sbi->ll_client_common_fill_super_succeeded = 1;
1192 OBD_FREE(md, md_len);
1195 OBD_FREE(dt, dt_len);
1198 class_put_profile(lprof);
1201 ll_debugfs_unregister_super(sb);
1208 else if (sbi->ll_flags & LL_SBI_VERBOSE)
1209 LCONSOLE_WARN("Mounted %s\n", profilenm);
1211 } /* ll_fill_super */
1213 void ll_put_super(struct super_block *sb)
1215 struct config_llog_instance cfg, params_cfg;
1216 struct obd_device *obd;
1217 struct lustre_sb_info *lsi = s2lsi(sb);
1218 struct ll_sb_info *sbi = ll_s2sbi(sb);
1219 char *profilenm = get_profile_name(sb);
1220 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1222 int next, force = 1, rc = 0;
1226 GOTO(out_no_sbi, 0);
1228 /* Should replace instance_id with something better for ASLR */
1229 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1230 profilenm, cfg_instance, sb);
1232 cfg.cfg_instance = cfg_instance;
1233 lustre_end_log(sb, profilenm, &cfg);
1235 params_cfg.cfg_instance = cfg_instance;
1236 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1238 if (sbi->ll_md_exp) {
1239 obd = class_exp2obd(sbi->ll_md_exp);
1241 force = obd->obd_force;
1244 /* Wait for unstable pages to be committed to stable storage */
1246 rc = l_wait_event_abortable(
1247 sbi->ll_cache->ccc_unstable_waitq,
1248 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1251 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1252 if (force == 0 && rc != -ERESTARTSYS)
1253 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1255 /* We need to set force before the lov_disconnect in
1256 * lustre_common_put_super, since l_d cleans up osc's as well.
1260 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1262 obd->obd_force = force;
1266 if (sbi->ll_client_common_fill_super_succeeded) {
1267 /* Only if client_common_fill_super succeeded */
1268 client_common_put_super(sb);
1272 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1273 class_manual_cleanup(obd);
1275 if (sbi->ll_flags & LL_SBI_VERBOSE)
1276 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1279 class_del_profile(profilenm);
1281 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1282 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1283 bdi_destroy(&lsi->lsi_bdi);
1284 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1289 lsi->lsi_llsbi = NULL;
1291 lustre_common_put_super(sb);
1293 cl_env_cache_purge(~0);
1295 module_put(THIS_MODULE);
1298 } /* client_put_super */
1300 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1302 struct inode *inode = NULL;
1304 /* NOTE: we depend on atomic igrab() -bzzz */
1305 lock_res_and_lock(lock);
1306 if (lock->l_resource->lr_lvb_inode) {
1307 struct ll_inode_info * lli;
1308 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1309 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1310 inode = igrab(lock->l_resource->lr_lvb_inode);
1312 inode = lock->l_resource->lr_lvb_inode;
1313 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1314 D_WARNING, lock, "lr_lvb_inode %p is "
1315 "bogus: magic %08x",
1316 lock->l_resource->lr_lvb_inode,
1317 lli->lli_inode_magic);
1321 unlock_res_and_lock(lock);
1325 void ll_dir_clear_lsm_md(struct inode *inode)
1327 struct ll_inode_info *lli = ll_i2info(inode);
1329 LASSERT(S_ISDIR(inode->i_mode));
1331 if (lli->lli_lsm_md) {
1332 lmv_free_memmd(lli->lli_lsm_md);
1333 lli->lli_lsm_md = NULL;
1336 if (lli->lli_default_lsm_md) {
1337 lmv_free_memmd(lli->lli_default_lsm_md);
1338 lli->lli_default_lsm_md = NULL;
1342 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1343 const struct lu_fid *fid,
1344 struct lustre_md *md)
1346 struct ll_sb_info *sbi = ll_s2sbi(sb);
1347 struct mdt_body *body = md->body;
1348 struct inode *inode;
1352 ino = cl_fid_build_ino(fid, sbi->ll_flags & LL_SBI_32BIT_API);
1353 inode = iget_locked(sb, ino);
1354 if (inode == NULL) {
1355 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1356 sbi->ll_fsname, PFID(fid));
1357 RETURN(ERR_PTR(-ENOENT));
1360 if (inode->i_state & I_NEW) {
1361 struct ll_inode_info *lli = ll_i2info(inode);
1362 struct lmv_stripe_md *lsm = md->lmv;
1364 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1365 (body->mbo_mode & S_IFMT);
1366 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1369 inode->i_mtime.tv_sec = 0;
1370 inode->i_atime.tv_sec = 0;
1371 inode->i_ctime.tv_sec = 0;
1374 #ifdef HAVE_BACKING_DEV_INFO
1375 /* initializing backing dev info. */
1376 inode->i_mapping->backing_dev_info =
1377 &s2lsi(inode->i_sb)->lsi_bdi;
1379 inode->i_op = &ll_dir_inode_operations;
1380 inode->i_fop = &ll_dir_operations;
1381 lli->lli_fid = *fid;
1384 LASSERT(lsm != NULL);
1385 /* master object FID */
1386 lli->lli_pfid = body->mbo_fid1;
1387 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1388 lli, PFID(fid), PFID(&lli->lli_pfid));
1389 unlock_new_inode(inode);
1395 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1398 struct lmv_stripe_md *lsm = md->lmv;
1399 struct ll_inode_info *lli = ll_i2info(inode);
1402 LASSERT(lsm != NULL);
1404 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1405 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1406 lsm_md_dump(D_INODE, lsm);
1408 if (!lmv_dir_striped(lsm))
1411 /* XXX sigh, this lsm_root initialization should be in
1412 * LMV layer, but it needs ll_iget right now, so we
1413 * put this here right now. */
1414 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1415 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1416 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1418 if (!fid_is_sane(fid))
1421 /* Unfortunately ll_iget will call ll_update_inode,
1422 * where the initialization of slave inode is slightly
1423 * different, so it reset lsm_md to NULL to avoid
1424 * initializing lsm for slave inode. */
1425 lsm->lsm_md_oinfo[i].lmo_root =
1426 ll_iget_anon_dir(inode->i_sb, fid, md);
1427 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1428 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1430 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1432 iput(lsm->lsm_md_oinfo[i].lmo_root);
1433 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1439 lli->lli_lsm_md = lsm;
1444 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1446 struct ll_inode_info *lli = ll_i2info(inode);
1448 if (!md->default_lmv) {
1449 /* clear default lsm */
1450 if (lli->lli_default_lsm_md) {
1451 down_write(&lli->lli_lsm_sem);
1452 if (lli->lli_default_lsm_md) {
1453 lmv_free_memmd(lli->lli_default_lsm_md);
1454 lli->lli_default_lsm_md = NULL;
1456 up_write(&lli->lli_lsm_sem);
1458 } else if (lli->lli_default_lsm_md) {
1459 /* update default lsm if it changes */
1460 down_read(&lli->lli_lsm_sem);
1461 if (lli->lli_default_lsm_md &&
1462 !lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1463 up_read(&lli->lli_lsm_sem);
1464 down_write(&lli->lli_lsm_sem);
1465 if (lli->lli_default_lsm_md)
1466 lmv_free_memmd(lli->lli_default_lsm_md);
1467 lli->lli_default_lsm_md = md->default_lmv;
1468 lsm_md_dump(D_INODE, md->default_lmv);
1469 md->default_lmv = NULL;
1470 up_write(&lli->lli_lsm_sem);
1472 up_read(&lli->lli_lsm_sem);
1475 /* init default lsm */
1476 down_write(&lli->lli_lsm_sem);
1477 lli->lli_default_lsm_md = md->default_lmv;
1478 lsm_md_dump(D_INODE, md->default_lmv);
1479 md->default_lmv = NULL;
1480 up_write(&lli->lli_lsm_sem);
1484 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1486 struct ll_inode_info *lli = ll_i2info(inode);
1487 struct lmv_stripe_md *lsm = md->lmv;
1488 struct cl_attr *attr;
1493 LASSERT(S_ISDIR(inode->i_mode));
1494 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1495 PFID(ll_inode2fid(inode)));
1497 /* update default LMV */
1498 if (md->default_lmv)
1499 ll_update_default_lsm_md(inode, md);
1502 * no striped information from request, lustre_md from req does not
1503 * include stripeEA, see ll_md_setattr()
1509 * normally dir layout doesn't change, only take read lock to check
1510 * that to avoid blocking other MD operations.
1512 down_read(&lli->lli_lsm_sem);
1514 /* some current lookup initialized lsm, and unchanged */
1515 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1516 GOTO(unlock, rc = 0);
1518 /* if dir layout doesn't match, check whether version is increased,
1519 * which means layout is changed, this happens in dir split/merge and
1522 * foreign LMV should not change.
1524 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1525 lsm->lsm_md_layout_version <=
1526 lli->lli_lsm_md->lsm_md_layout_version) {
1527 CERROR("%s: "DFID" dir layout mismatch:\n",
1528 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1529 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1530 lsm_md_dump(D_ERROR, lsm);
1531 GOTO(unlock, rc = -EINVAL);
1534 up_read(&lli->lli_lsm_sem);
1535 down_write(&lli->lli_lsm_sem);
1536 /* clear existing lsm */
1537 if (lli->lli_lsm_md) {
1538 lmv_free_memmd(lli->lli_lsm_md);
1539 lli->lli_lsm_md = NULL;
1542 rc = ll_init_lsm_md(inode, md);
1543 up_write(&lli->lli_lsm_sem);
1548 /* set md->lmv to NULL, so the following free lustre_md will not free
1553 /* md_merge_attr() may take long, since lsm is already set, switch to
1556 down_read(&lli->lli_lsm_sem);
1558 if (!lmv_dir_striped(lli->lli_lsm_md))
1559 GOTO(unlock, rc = 0);
1561 OBD_ALLOC_PTR(attr);
1563 GOTO(unlock, rc = -ENOMEM);
1565 /* validate the lsm */
1566 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1567 ll_md_blocking_ast);
1569 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1570 md->body->mbo_nlink = attr->cat_nlink;
1571 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1572 md->body->mbo_size = attr->cat_size;
1573 if (md->body->mbo_valid & OBD_MD_FLATIME)
1574 md->body->mbo_atime = attr->cat_atime;
1575 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1576 md->body->mbo_ctime = attr->cat_ctime;
1577 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1578 md->body->mbo_mtime = attr->cat_mtime;
1584 up_read(&lli->lli_lsm_sem);
1589 void ll_clear_inode(struct inode *inode)
1591 struct ll_inode_info *lli = ll_i2info(inode);
1592 struct ll_sb_info *sbi = ll_i2sbi(inode);
1596 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1597 PFID(ll_inode2fid(inode)), inode);
1599 if (S_ISDIR(inode->i_mode)) {
1600 /* these should have been cleared in ll_file_release */
1601 LASSERT(lli->lli_opendir_key == NULL);
1602 LASSERT(lli->lli_sai == NULL);
1603 LASSERT(lli->lli_opendir_pid == 0);
1605 pcc_inode_free(inode);
1608 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1610 LASSERT(!lli->lli_open_fd_write_count);
1611 LASSERT(!lli->lli_open_fd_read_count);
1612 LASSERT(!lli->lli_open_fd_exec_count);
1614 if (lli->lli_mds_write_och)
1615 ll_md_real_close(inode, FMODE_WRITE);
1616 if (lli->lli_mds_exec_och)
1617 ll_md_real_close(inode, FMODE_EXEC);
1618 if (lli->lli_mds_read_och)
1619 ll_md_real_close(inode, FMODE_READ);
1621 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1622 OBD_FREE(lli->lli_symlink_name,
1623 strlen(lli->lli_symlink_name) + 1);
1624 lli->lli_symlink_name = NULL;
1627 ll_xattr_cache_destroy(inode);
1629 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
1630 forget_all_cached_acls(inode);
1631 if (lli->lli_posix_acl) {
1632 posix_acl_release(lli->lli_posix_acl);
1633 lli->lli_posix_acl = NULL;
1636 lli->lli_inode_magic = LLI_INODE_DEAD;
1638 if (S_ISDIR(inode->i_mode))
1639 ll_dir_clear_lsm_md(inode);
1640 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1641 LASSERT(list_empty(&lli->lli_agl_list));
1644 * XXX This has to be done before lsm is freed below, because
1645 * cl_object still uses inode lsm.
1647 cl_inode_fini(inode);
1652 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1654 struct lustre_md md;
1655 struct inode *inode = dentry->d_inode;
1656 struct ll_sb_info *sbi = ll_i2sbi(inode);
1657 struct ptlrpc_request *request = NULL;
1661 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1662 LUSTRE_OPC_ANY, NULL);
1663 if (IS_ERR(op_data))
1664 RETURN(PTR_ERR(op_data));
1666 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1668 ptlrpc_req_finished(request);
1669 if (rc == -ENOENT) {
1671 /* Unlinked special device node? Or just a race?
1672 * Pretend we done everything. */
1673 if (!S_ISREG(inode->i_mode) &&
1674 !S_ISDIR(inode->i_mode)) {
1675 ia_valid = op_data->op_attr.ia_valid;
1676 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1677 rc = simple_setattr(dentry, &op_data->op_attr);
1678 op_data->op_attr.ia_valid = ia_valid;
1680 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1681 CERROR("md_setattr fails: rc = %d\n", rc);
1686 rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
1687 sbi->ll_md_exp, &md);
1689 ptlrpc_req_finished(request);
1693 ia_valid = op_data->op_attr.ia_valid;
1694 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1695 * cache is not cleared yet. */
1696 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1697 if (S_ISREG(inode->i_mode))
1699 rc = simple_setattr(dentry, &op_data->op_attr);
1700 if (S_ISREG(inode->i_mode))
1701 inode_unlock(inode);
1702 op_data->op_attr.ia_valid = ia_valid;
1704 rc = ll_update_inode(inode, &md);
1705 ptlrpc_req_finished(request);
1710 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1711 * object(s) determine the file size and mtime. Otherwise, the MDS will
1712 * keep these values until such a time that objects are allocated for it.
1713 * We do the MDS operations first, as it is checking permissions for us.
1714 * We don't to the MDS RPC if there is nothing that we want to store there,
1715 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1716 * going to do an RPC anyways.
1718 * If we are doing a truncate, we will send the mtime and ctime updates
1719 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1720 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1723 * In case of HSMimport, we only set attr on MDS.
1725 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
1726 enum op_xvalid xvalid, bool hsm_import)
1728 struct inode *inode = dentry->d_inode;
1729 struct ll_inode_info *lli = ll_i2info(inode);
1730 struct md_op_data *op_data = NULL;
1731 ktime_t kstart = ktime_get();
1736 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
1737 "valid %x, hsm_import %d\n",
1738 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
1739 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
1742 if (attr->ia_valid & ATTR_SIZE) {
1743 /* Check new size against VFS/VM file size limit and rlimit */
1744 rc = inode_newsize_ok(inode, attr->ia_size);
1748 /* The maximum Lustre file size is variable, based on the
1749 * OST maximum object size and number of stripes. This
1750 * needs another check in addition to the VFS check above. */
1751 if (attr->ia_size > ll_file_maxbytes(inode)) {
1752 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
1753 PFID(&lli->lli_fid), attr->ia_size,
1754 ll_file_maxbytes(inode));
1758 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1761 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1762 if (attr->ia_valid & TIMES_SET_FLAGS) {
1763 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
1764 !cfs_capable(CFS_CAP_FOWNER))
1768 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1769 if (!(xvalid & OP_XVALID_CTIME_SET) &&
1770 (attr->ia_valid & ATTR_CTIME)) {
1771 attr->ia_ctime = current_time(inode);
1772 xvalid |= OP_XVALID_CTIME_SET;
1774 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
1775 (attr->ia_valid & ATTR_ATIME)) {
1776 attr->ia_atime = current_time(inode);
1777 attr->ia_valid |= ATTR_ATIME_SET;
1779 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
1780 (attr->ia_valid & ATTR_MTIME)) {
1781 attr->ia_mtime = current_time(inode);
1782 attr->ia_valid |= ATTR_MTIME_SET;
1785 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1786 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
1787 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
1788 ktime_get_real_seconds());
1790 if (S_ISREG(inode->i_mode))
1791 inode_unlock(inode);
1793 /* We always do an MDS RPC, even if we're only changing the size;
1794 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
1796 OBD_ALLOC_PTR(op_data);
1797 if (op_data == NULL)
1798 GOTO(out, rc = -ENOMEM);
1800 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
1801 /* If we are changing file size, file content is
1802 * modified, flag it.
1804 xvalid |= OP_XVALID_OWNEROVERRIDE;
1805 op_data->op_bias |= MDS_DATA_MODIFIED;
1806 ll_file_clear_flag(lli, LLIF_DATA_MODIFIED);
1809 if (attr->ia_valid & ATTR_FILE) {
1810 struct ll_file_data *fd = attr->ia_file->private_data;
1812 if (fd->fd_lease_och)
1813 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
1816 op_data->op_attr = *attr;
1817 op_data->op_xvalid = xvalid;
1819 rc = ll_md_setattr(dentry, op_data);
1823 if (!S_ISREG(inode->i_mode) || hsm_import)
1826 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
1827 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
1828 xvalid & OP_XVALID_CTIME_SET) {
1829 bool cached = false;
1831 rc = pcc_inode_setattr(inode, attr, &cached);
1834 CERROR("%s: PCC inode "DFID" setattr failed: "
1836 ll_i2sbi(inode)->ll_fsname,
1837 PFID(&lli->lli_fid), rc);
1841 /* For truncate and utimes sending attributes to OSTs,
1842 * setting mtime/atime to the past will be performed
1843 * under PW [0:EOF] extent lock (new_size:EOF for
1844 * truncate). It may seem excessive to send mtime/atime
1845 * updates to OSTs when not setting times to past, but
1846 * it is necessary due to possible time
1847 * de-synchronization between MDT inode and OST objects
1849 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, 0);
1853 /* If the file was restored, it needs to set dirty flag.
1855 * We've already sent MDS_DATA_MODIFIED flag in
1856 * ll_md_setattr() for truncate. However, the MDT refuses to
1857 * set the HS_DIRTY flag on released files, so we have to set
1858 * it again if the file has been restored. Please check how
1859 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
1861 * Please notice that if the file is not released, the previous
1862 * MDS_DATA_MODIFIED has taken effect and usually
1863 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
1864 * This way we can save an RPC for common open + trunc
1866 if (ll_file_test_and_clear_flag(lli, LLIF_DATA_MODIFIED)) {
1867 struct hsm_state_set hss = {
1868 .hss_valid = HSS_SETMASK,
1869 .hss_setmask = HS_DIRTY,
1873 rc2 = ll_hsm_state_set(inode, &hss);
1874 /* truncate and write can happen at the same time, so that
1875 * the file can be set modified even though the file is not
1876 * restored from released state, and ll_hsm_state_set() is
1877 * not applicable for the file, and rc2 < 0 is normal in this
1880 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
1881 PFID(ll_inode2fid(inode)), rc2);
1886 if (op_data != NULL)
1887 ll_finish_md_op_data(op_data);
1889 if (S_ISREG(inode->i_mode)) {
1891 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
1892 inode_dio_wait(inode);
1893 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
1894 * flag. ll_update_inode (called from ll_md_setattr), clears
1895 * inode flags, so there is a gap where S_NOSEC is not set.
1896 * This can cause a writer to take the i_mutex unnecessarily,
1897 * but this is safe to do and should be rare. */
1898 inode_has_no_xattr(inode);
1902 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
1903 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
1904 ktime_us_delta(ktime_get(), kstart));
1909 int ll_setattr(struct dentry *de, struct iattr *attr)
1911 int mode = de->d_inode->i_mode;
1912 enum op_xvalid xvalid = 0;
1914 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1915 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1916 xvalid |= OP_XVALID_OWNEROVERRIDE;
1918 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
1919 (ATTR_SIZE|ATTR_MODE)) &&
1920 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
1921 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
1922 !(attr->ia_mode & S_ISGID))))
1923 attr->ia_valid |= ATTR_FORCE;
1925 if ((attr->ia_valid & ATTR_MODE) &&
1927 !(attr->ia_mode & S_ISUID) &&
1928 !(attr->ia_valid & ATTR_KILL_SUID))
1929 attr->ia_valid |= ATTR_KILL_SUID;
1931 if ((attr->ia_valid & ATTR_MODE) &&
1932 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
1933 !(attr->ia_mode & S_ISGID) &&
1934 !(attr->ia_valid & ATTR_KILL_SGID))
1935 attr->ia_valid |= ATTR_KILL_SGID;
1937 return ll_setattr_raw(de, attr, xvalid, false);
1940 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
1943 struct obd_statfs obd_osfs = { 0 };
1948 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
1950 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
1951 flags |= OBD_STATFS_NODELAY;
1953 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
1957 osfs->os_type = LL_SUPER_MAGIC;
1959 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
1960 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
1962 if (osfs->os_state & OS_STATE_SUM)
1965 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
1966 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
1969 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
1970 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1973 osfs->os_bsize = obd_osfs.os_bsize;
1974 osfs->os_blocks = obd_osfs.os_blocks;
1975 osfs->os_bfree = obd_osfs.os_bfree;
1976 osfs->os_bavail = obd_osfs.os_bavail;
1978 /* If we have _some_ OSTs, but don't have as many free objects on the
1979 * OSTs as inodes on the MDTs, reduce the reported number of inodes
1980 * to compensate, so that the "inodes in use" number is correct.
1981 * This should be kept in sync with lod_statfs() behaviour.
1983 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
1984 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1986 osfs->os_ffree = obd_osfs.os_ffree;
1993 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1995 struct super_block *sb = de->d_sb;
1996 struct obd_statfs osfs;
1997 __u64 fsid = huge_encode_dev(sb->s_dev);
1998 ktime_t kstart = ktime_get();
2001 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2003 /* Some amount of caching on the client is allowed */
2004 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2008 statfs_unpack(sfs, &osfs);
2010 /* We need to downshift for all 32-bit kernels, because we can't
2011 * tell if the kernel is being called via sys_statfs64() or not.
2012 * Stop before overflowing f_bsize - in which case it is better
2013 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2014 if (sizeof(long) < 8) {
2015 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2018 osfs.os_blocks >>= 1;
2019 osfs.os_bfree >>= 1;
2020 osfs.os_bavail >>= 1;
2024 sfs->f_blocks = osfs.os_blocks;
2025 sfs->f_bfree = osfs.os_bfree;
2026 sfs->f_bavail = osfs.os_bavail;
2027 sfs->f_fsid.val[0] = (__u32)fsid;
2028 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2030 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2031 ktime_us_delta(ktime_get(), kstart));
2036 void ll_inode_size_lock(struct inode *inode)
2038 struct ll_inode_info *lli;
2040 LASSERT(!S_ISDIR(inode->i_mode));
2042 lli = ll_i2info(inode);
2043 mutex_lock(&lli->lli_size_mutex);
2046 void ll_inode_size_unlock(struct inode *inode)
2048 struct ll_inode_info *lli;
2050 lli = ll_i2info(inode);
2051 mutex_unlock(&lli->lli_size_mutex);
2054 void ll_update_inode_flags(struct inode *inode, int ext_flags)
2056 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2057 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2058 ll_file_set_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
2060 ll_file_clear_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
2063 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2065 struct ll_inode_info *lli = ll_i2info(inode);
2066 struct mdt_body *body = md->body;
2067 struct ll_sb_info *sbi = ll_i2sbi(inode);
2070 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2071 rc = cl_file_inode_init(inode, md);
2076 if (S_ISDIR(inode->i_mode)) {
2077 rc = ll_update_lsm_md(inode, md);
2082 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
2083 if (body->mbo_valid & OBD_MD_FLACL) {
2084 spin_lock(&lli->lli_lock);
2085 if (lli->lli_posix_acl)
2086 posix_acl_release(lli->lli_posix_acl);
2087 lli->lli_posix_acl = md->posix_acl;
2088 spin_unlock(&lli->lli_lock);
2091 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1,
2092 sbi->ll_flags & LL_SBI_32BIT_API);
2093 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2095 if (body->mbo_valid & OBD_MD_FLATIME) {
2096 if (body->mbo_atime > inode->i_atime.tv_sec)
2097 inode->i_atime.tv_sec = body->mbo_atime;
2098 lli->lli_atime = body->mbo_atime;
2101 if (body->mbo_valid & OBD_MD_FLMTIME) {
2102 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2104 "setting ino %lu mtime from %lld to %llu\n",
2105 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2107 inode->i_mtime.tv_sec = body->mbo_mtime;
2109 lli->lli_mtime = body->mbo_mtime;
2112 if (body->mbo_valid & OBD_MD_FLCTIME) {
2113 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2114 inode->i_ctime.tv_sec = body->mbo_ctime;
2115 lli->lli_ctime = body->mbo_ctime;
2118 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2119 if (body->mbo_valid & OBD_MD_FLFLAGS)
2120 ll_update_inode_flags(inode, body->mbo_flags);
2121 if (body->mbo_valid & OBD_MD_FLMODE)
2122 inode->i_mode = (inode->i_mode & S_IFMT) |
2123 (body->mbo_mode & ~S_IFMT);
2125 if (body->mbo_valid & OBD_MD_FLTYPE)
2126 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2127 (body->mbo_mode & S_IFMT);
2129 LASSERT(inode->i_mode != 0);
2130 if (body->mbo_valid & OBD_MD_FLUID)
2131 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2132 if (body->mbo_valid & OBD_MD_FLGID)
2133 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2134 if (body->mbo_valid & OBD_MD_FLPROJID)
2135 lli->lli_projid = body->mbo_projid;
2136 if (body->mbo_valid & OBD_MD_FLNLINK)
2137 set_nlink(inode, body->mbo_nlink);
2138 if (body->mbo_valid & OBD_MD_FLRDEV)
2139 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2141 if (body->mbo_valid & OBD_MD_FLID) {
2142 /* FID shouldn't be changed! */
2143 if (fid_is_sane(&lli->lli_fid)) {
2144 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2145 "Trying to change FID "DFID
2146 " to the "DFID", inode "DFID"(%p)\n",
2147 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2148 PFID(ll_inode2fid(inode)), inode);
2150 lli->lli_fid = body->mbo_fid1;
2154 LASSERT(fid_seq(&lli->lli_fid) != 0);
2156 if (body->mbo_valid & OBD_MD_FLSIZE) {
2157 i_size_write(inode, body->mbo_size);
2159 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2160 PFID(ll_inode2fid(inode)),
2161 (unsigned long long)body->mbo_size);
2163 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2164 inode->i_blocks = body->mbo_blocks;
2167 if (body->mbo_valid & OBD_MD_TSTATE) {
2168 /* Set LLIF_FILE_RESTORING if restore ongoing and
2169 * clear it when done to ensure to start again
2170 * glimpsing updated attrs
2172 if (body->mbo_t_state & MS_RESTORE)
2173 ll_file_set_flag(lli, LLIF_FILE_RESTORING);
2175 ll_file_clear_flag(lli, LLIF_FILE_RESTORING);
2181 int ll_read_inode2(struct inode *inode, void *opaque)
2183 struct lustre_md *md = opaque;
2184 struct ll_inode_info *lli = ll_i2info(inode);
2188 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2189 PFID(&lli->lli_fid), inode);
2191 /* Core attributes from the MDS first. This is a new inode, and
2192 * the VFS doesn't zero times in the core inode so we have to do
2193 * it ourselves. They will be overwritten by either MDS or OST
2194 * attributes - we just need to make sure they aren't newer.
2196 inode->i_mtime.tv_sec = 0;
2197 inode->i_atime.tv_sec = 0;
2198 inode->i_ctime.tv_sec = 0;
2200 rc = ll_update_inode(inode, md);
2204 /* OIDEBUG(inode); */
2206 #ifdef HAVE_BACKING_DEV_INFO
2207 /* initializing backing dev info. */
2208 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2210 if (S_ISREG(inode->i_mode)) {
2211 struct ll_sb_info *sbi = ll_i2sbi(inode);
2212 inode->i_op = &ll_file_inode_operations;
2213 inode->i_fop = sbi->ll_fop;
2214 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2216 } else if (S_ISDIR(inode->i_mode)) {
2217 inode->i_op = &ll_dir_inode_operations;
2218 inode->i_fop = &ll_dir_operations;
2220 } else if (S_ISLNK(inode->i_mode)) {
2221 inode->i_op = &ll_fast_symlink_inode_operations;
2224 inode->i_op = &ll_special_inode_operations;
2226 init_special_inode(inode, inode->i_mode,
2235 void ll_delete_inode(struct inode *inode)
2237 struct ll_inode_info *lli = ll_i2info(inode);
2238 struct address_space *mapping = &inode->i_data;
2239 unsigned long nrpages;
2240 unsigned long flags;
2244 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2245 /* It is last chance to write out dirty pages,
2246 * otherwise we may lose data while umount.
2248 * If i_nlink is 0 then just discard data. This is safe because
2249 * local inode gets i_nlink 0 from server only for the last
2250 * unlink, so that file is not opened somewhere else
2252 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2253 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2255 truncate_inode_pages_final(mapping);
2257 /* Workaround for LU-118: Note nrpages may not be totally updated when
2258 * truncate_inode_pages() returns, as there can be a page in the process
2259 * of deletion (inside __delete_from_page_cache()) in the specified
2260 * range. Thus mapping->nrpages can be non-zero when this function
2261 * returns even after truncation of the whole mapping. Only do this if
2262 * npages isn't already zero.
2264 nrpages = mapping->nrpages;
2266 xa_lock_irqsave(&mapping->i_pages, flags);
2267 nrpages = mapping->nrpages;
2268 xa_unlock_irqrestore(&mapping->i_pages, flags);
2269 } /* Workaround end */
2271 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, "
2272 "see https://jira.whamcloud.com/browse/LU-118\n",
2273 ll_i2sbi(inode)->ll_fsname,
2274 PFID(ll_inode2fid(inode)), inode, nrpages);
2276 ll_clear_inode(inode);
2282 int ll_iocontrol(struct inode *inode, struct file *file,
2283 unsigned int cmd, unsigned long arg)
2285 struct ll_sb_info *sbi = ll_i2sbi(inode);
2286 struct ptlrpc_request *req = NULL;
2291 case FS_IOC_GETFLAGS: {
2292 struct mdt_body *body;
2293 struct md_op_data *op_data;
2295 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2296 0, 0, LUSTRE_OPC_ANY,
2298 if (IS_ERR(op_data))
2299 RETURN(PTR_ERR(op_data));
2301 op_data->op_valid = OBD_MD_FLFLAGS;
2302 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2303 ll_finish_md_op_data(op_data);
2305 CERROR("%s: failure inode "DFID": rc = %d\n",
2306 sbi->ll_md_exp->exp_obd->obd_name,
2307 PFID(ll_inode2fid(inode)), rc);
2311 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2313 flags = body->mbo_flags;
2315 ptlrpc_req_finished(req);
2317 RETURN(put_user(flags, (int __user *)arg));
2319 case FS_IOC_SETFLAGS: {
2321 struct md_op_data *op_data;
2322 struct cl_object *obj;
2323 struct fsxattr fa = { 0 };
2325 if (get_user(flags, (int __user *)arg))
2328 fa.fsx_projid = ll_i2info(inode)->lli_projid;
2329 if (flags & LUSTRE_PROJINHERIT_FL)
2330 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
2332 rc = ll_ioctl_check_project(inode, &fa);
2336 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
2337 LUSTRE_OPC_ANY, NULL);
2338 if (IS_ERR(op_data))
2339 RETURN(PTR_ERR(op_data));
2341 op_data->op_attr_flags = flags;
2342 op_data->op_xvalid |= OP_XVALID_FLAGS;
2343 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
2344 ll_finish_md_op_data(op_data);
2345 ptlrpc_req_finished(req);
2349 ll_update_inode_flags(inode, flags);
2351 obj = ll_i2info(inode)->lli_clob;
2355 OBD_ALLOC_PTR(attr);
2359 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
2371 int ll_flush_ctx(struct inode *inode)
2373 struct ll_sb_info *sbi = ll_i2sbi(inode);
2375 CDEBUG(D_SEC, "flush context for user %d\n",
2376 from_kuid(&init_user_ns, current_uid()));
2378 obd_set_info_async(NULL, sbi->ll_md_exp,
2379 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2381 obd_set_info_async(NULL, sbi->ll_dt_exp,
2382 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2387 /* umount -f client means force down, don't save state */
2388 void ll_umount_begin(struct super_block *sb)
2390 struct ll_sb_info *sbi = ll_s2sbi(sb);
2391 struct obd_device *obd;
2392 struct obd_ioctl_data *ioc_data;
2396 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2397 sb->s_count, atomic_read(&sb->s_active));
2399 obd = class_exp2obd(sbi->ll_md_exp);
2401 CERROR("Invalid MDC connection handle %#llx\n",
2402 sbi->ll_md_exp->exp_handle.h_cookie);
2408 obd = class_exp2obd(sbi->ll_dt_exp);
2410 CERROR("Invalid LOV connection handle %#llx\n",
2411 sbi->ll_dt_exp->exp_handle.h_cookie);
2417 OBD_ALLOC_PTR(ioc_data);
2419 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2420 sizeof *ioc_data, ioc_data, NULL);
2422 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2423 sizeof *ioc_data, ioc_data, NULL);
2425 OBD_FREE_PTR(ioc_data);
2428 /* Really, we'd like to wait until there are no requests outstanding,
2429 * and then continue. For now, we just periodically checking for vfs
2430 * to decrement mnt_cnt and hope to finish it within 10sec.
2434 !may_umount(sbi->ll_mnt.mnt)) {
2442 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2444 struct ll_sb_info *sbi = ll_s2sbi(sb);
2445 char *profilenm = get_profile_name(sb);
2449 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
2450 read_only = *flags & MS_RDONLY;
2451 err = obd_set_info_async(NULL, sbi->ll_md_exp,
2452 sizeof(KEY_READ_ONLY),
2453 KEY_READ_ONLY, sizeof(read_only),
2456 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2457 profilenm, read_only ?
2458 "read-only" : "read-write", err);
2463 sb->s_flags |= SB_RDONLY;
2465 sb->s_flags &= ~SB_RDONLY;
2467 if (sbi->ll_flags & LL_SBI_VERBOSE)
2468 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
2469 read_only ? "read-only" : "read-write");
2475 * Cleanup the open handle that is cached on MDT-side.
2477 * For open case, the client side open handling thread may hit error
2478 * after the MDT grant the open. Under such case, the client should
2479 * send close RPC to the MDT as cleanup; otherwise, the open handle
2480 * on the MDT will be leaked there until the client umount or evicted.
2482 * In further, if someone unlinked the file, because the open handle
2483 * holds the reference on such file/object, then it will block the
2484 * subsequent threads that want to locate such object via FID.
2486 * \param[in] sb super block for this file-system
2487 * \param[in] open_req pointer to the original open request
2489 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
2491 struct mdt_body *body;
2492 struct md_op_data *op_data;
2493 struct ptlrpc_request *close_req = NULL;
2494 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
2497 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
2498 OBD_ALLOC_PTR(op_data);
2499 if (op_data == NULL) {
2500 CWARN("%s: cannot allocate op_data to release open handle for "
2501 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
2506 op_data->op_fid1 = body->mbo_fid1;
2507 op_data->op_open_handle = body->mbo_open_handle;
2508 op_data->op_mod_time = ktime_get_real_seconds();
2509 md_close(exp, op_data, NULL, &close_req);
2510 ptlrpc_req_finished(close_req);
2511 ll_finish_md_op_data(op_data);
2516 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
2517 struct super_block *sb, struct lookup_intent *it)
2519 struct ll_sb_info *sbi = NULL;
2520 struct lustre_md md = { NULL };
2521 bool default_lmv_deleted = false;
2526 LASSERT(*inode || sb);
2527 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2528 rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
2529 sbi->ll_md_exp, &md);
2534 * clear default_lmv only if intent_getattr reply doesn't contain it.
2535 * but it needs to be done after iget, check this early because
2536 * ll_update_lsm_md() may change md.
2538 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
2539 S_ISDIR(md.body->mbo_mode) && !md.default_lmv)
2540 default_lmv_deleted = true;
2543 rc = ll_update_inode(*inode, &md);
2547 LASSERT(sb != NULL);
2550 * At this point server returns to client's same fid as client
2551 * generated for creating. So using ->fid1 is okay here.
2553 if (!fid_is_sane(&md.body->mbo_fid1)) {
2554 CERROR("%s: Fid is insane "DFID"\n",
2556 PFID(&md.body->mbo_fid1));
2557 GOTO(out, rc = -EINVAL);
2560 *inode = ll_iget(sb, cl_fid_build_ino(&md.body->mbo_fid1,
2561 sbi->ll_flags & LL_SBI_32BIT_API),
2563 if (IS_ERR(*inode)) {
2564 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
2566 posix_acl_release(md.posix_acl);
2567 md.posix_acl = NULL;
2570 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
2572 CERROR("new_inode -fatal: rc %d\n", rc);
2577 /* Handling piggyback layout lock.
2578 * Layout lock can be piggybacked by getattr and open request.
2579 * The lsm can be applied to inode only if it comes with a layout lock
2580 * otherwise correct layout may be overwritten, for example:
2581 * 1. proc1: mdt returns a lsm but not granting layout
2582 * 2. layout was changed by another client
2583 * 3. proc2: refresh layout and layout lock granted
2584 * 4. proc1: to apply a stale layout */
2585 if (it != NULL && it->it_lock_mode != 0) {
2586 struct lustre_handle lockh;
2587 struct ldlm_lock *lock;
2589 lockh.cookie = it->it_lock_handle;
2590 lock = ldlm_handle2lock(&lockh);
2591 LASSERT(lock != NULL);
2592 if (ldlm_has_layout(lock)) {
2593 struct cl_object_conf conf;
2595 memset(&conf, 0, sizeof(conf));
2596 conf.coc_opc = OBJECT_CONF_SET;
2597 conf.coc_inode = *inode;
2598 conf.coc_lock = lock;
2599 conf.u.coc_layout = md.layout;
2600 (void)ll_layout_conf(*inode, &conf);
2602 LDLM_LOCK_PUT(lock);
2605 if (default_lmv_deleted)
2606 ll_update_default_lsm_md(*inode, &md);
2611 /* cleanup will be done if necessary */
2612 md_free_lustre_md(sbi->ll_md_exp, &md);
2614 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
2615 ll_intent_drop_lock(it);
2616 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, req);
2622 int ll_obd_statfs(struct inode *inode, void __user *arg)
2624 struct ll_sb_info *sbi = NULL;
2625 struct obd_export *exp;
2627 struct obd_ioctl_data *data = NULL;
2631 if (!inode || !(sbi = ll_i2sbi(inode)))
2632 GOTO(out_statfs, rc = -EINVAL);
2634 rc = obd_ioctl_getdata(&buf, &len, arg);
2636 GOTO(out_statfs, rc);
2639 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2640 !data->ioc_pbuf1 || !data->ioc_pbuf2)
2641 GOTO(out_statfs, rc = -EINVAL);
2643 if (data->ioc_inllen1 != sizeof(__u32) ||
2644 data->ioc_inllen2 != sizeof(__u32) ||
2645 data->ioc_plen1 != sizeof(struct obd_statfs) ||
2646 data->ioc_plen2 != sizeof(struct obd_uuid))
2647 GOTO(out_statfs, rc = -EINVAL);
2649 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2650 if (type & LL_STATFS_LMV)
2651 exp = sbi->ll_md_exp;
2652 else if (type & LL_STATFS_LOV)
2653 exp = sbi->ll_dt_exp;
2655 GOTO(out_statfs, rc = -ENODEV);
2657 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL);
2659 GOTO(out_statfs, rc);
2661 OBD_FREE_LARGE(buf, len);
2666 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
2667 * be called early to avoid deadlock.
2669 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
2671 if (op_data->op_mea2_sem) {
2672 up_read(op_data->op_mea2_sem);
2673 op_data->op_mea2_sem = NULL;
2676 if (op_data->op_mea1_sem) {
2677 up_read(op_data->op_mea1_sem);
2678 op_data->op_mea1_sem = NULL;
2682 /* this function prepares md_op_data hint for passing it down to MD stack. */
2683 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
2684 struct inode *i1, struct inode *i2,
2685 const char *name, size_t namelen,
2686 __u32 mode, enum md_op_code opc,
2689 LASSERT(i1 != NULL);
2692 /* Do not reuse namelen for something else. */
2694 return ERR_PTR(-EINVAL);
2696 if (namelen > ll_i2sbi(i1)->ll_namelen)
2697 return ERR_PTR(-ENAMETOOLONG);
2699 if (!lu_name_is_valid_2(name, namelen))
2700 return ERR_PTR(-EINVAL);
2703 if (op_data == NULL)
2704 OBD_ALLOC_PTR(op_data);
2706 if (op_data == NULL)
2707 return ERR_PTR(-ENOMEM);
2709 ll_i2gids(op_data->op_suppgids, i1, i2);
2710 op_data->op_fid1 = *ll_inode2fid(i1);
2711 op_data->op_code = opc;
2713 if (S_ISDIR(i1->i_mode)) {
2714 down_read(&ll_i2info(i1)->lli_lsm_sem);
2715 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
2716 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
2717 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
2721 op_data->op_fid2 = *ll_inode2fid(i2);
2722 if (S_ISDIR(i2->i_mode)) {
2724 down_read(&ll_i2info(i2)->lli_lsm_sem);
2725 op_data->op_mea2_sem =
2726 &ll_i2info(i2)->lli_lsm_sem;
2728 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
2731 fid_zero(&op_data->op_fid2);
2734 if (ll_i2sbi(i1)->ll_flags & LL_SBI_64BIT_HASH)
2735 op_data->op_cli_flags |= CLI_HASH64;
2737 if (ll_need_32bit_api(ll_i2sbi(i1)))
2738 op_data->op_cli_flags |= CLI_API32;
2740 op_data->op_name = name;
2741 op_data->op_namelen = namelen;
2742 op_data->op_mode = mode;
2743 op_data->op_mod_time = ktime_get_real_seconds();
2744 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2745 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2746 op_data->op_cap = cfs_curproc_cap_pack();
2747 op_data->op_mds = 0;
2748 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
2749 filename_is_volatile(name, namelen, &op_data->op_mds)) {
2750 op_data->op_bias |= MDS_CREATE_VOLATILE;
2752 op_data->op_data = data;
2757 void ll_finish_md_op_data(struct md_op_data *op_data)
2759 ll_unlock_md_op_lsm(op_data);
2760 security_release_secctx(op_data->op_file_secctx,
2761 op_data->op_file_secctx_size);
2762 OBD_FREE_PTR(op_data);
2765 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
2767 struct ll_sb_info *sbi;
2769 LASSERT(seq && dentry);
2770 sbi = ll_s2sbi(dentry->d_sb);
2772 if (sbi->ll_flags & LL_SBI_NOLCK)
2773 seq_puts(seq, ",nolock");
2775 /* "flock" is the default since 2.13, but it wasn't for many years,
2776 * so it is still useful to print this to show it is enabled.
2777 * Start to print "noflock" so it is now clear when flock is disabled.
2779 if (sbi->ll_flags & LL_SBI_FLOCK)
2780 seq_puts(seq, ",flock");
2781 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
2782 seq_puts(seq, ",localflock");
2784 seq_puts(seq, ",noflock");
2786 if (sbi->ll_flags & LL_SBI_USER_XATTR)
2787 seq_puts(seq, ",user_xattr");
2789 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
2790 seq_puts(seq, ",lazystatfs");
2792 if (sbi->ll_flags & LL_SBI_USER_FID2PATH)
2793 seq_puts(seq, ",user_fid2path");
2795 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
2796 seq_puts(seq, ",always_ping");
2802 * Get obd name by cmd, and copy out to user space
2804 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
2806 struct ll_sb_info *sbi = ll_i2sbi(inode);
2807 struct obd_device *obd;
2810 if (cmd == OBD_IOC_GETDTNAME)
2811 obd = class_exp2obd(sbi->ll_dt_exp);
2812 else if (cmd == OBD_IOC_GETMDNAME)
2813 obd = class_exp2obd(sbi->ll_md_exp);
2820 if (copy_to_user((void __user *)arg, obd->obd_name,
2821 strlen(obd->obd_name) + 1))
2827 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
2834 p.mnt = current->fs->root.mnt;
2836 path = d_path(&p, buf, bufsize);
2841 void ll_dirty_page_discard_warn(struct page *page, int ioret)
2843 char *buf, *path = NULL;
2844 struct dentry *dentry = NULL;
2845 struct inode *inode = page->mapping->host;
2847 /* this can be called inside spin lock so use GFP_ATOMIC. */
2848 buf = (char *)__get_free_page(GFP_ATOMIC);
2850 dentry = d_find_alias(page->mapping->host);
2852 path = ll_d_path(dentry, buf, PAGE_SIZE);
2855 /* The below message is checked in recovery-small.sh test_24b */
2857 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
2858 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
2859 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
2860 PFID(ll_inode2fid(inode)),
2861 (path && !IS_ERR(path)) ? path : "", ioret);
2867 free_page((unsigned long)buf);
2870 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
2871 struct lov_user_md **kbuf)
2873 struct lov_user_md lum;
2877 if (copy_from_user(&lum, md, sizeof(lum)))
2880 lum_size = ll_lov_user_md_size(&lum);
2884 OBD_ALLOC_LARGE(*kbuf, lum_size);
2888 if (copy_from_user(*kbuf, md, lum_size) != 0) {
2889 OBD_FREE_LARGE(*kbuf, lum_size);
2897 * Compute llite root squash state after a change of root squash
2898 * configuration setting or add/remove of a lnet nid
2900 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
2902 struct root_squash_info *squash = &sbi->ll_squash;
2905 struct lnet_process_id id;
2907 /* Update norootsquash flag */
2908 spin_lock(&squash->rsi_lock);
2909 if (list_empty(&squash->rsi_nosquash_nids))
2910 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
2912 /* Do not apply root squash as soon as one of our NIDs is
2913 * in the nosquash_nids list */
2916 while (LNetGetId(i++, &id) != -ENOENT) {
2917 if (id.nid == LNET_NID_LO_0)
2919 if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) {
2925 sbi->ll_flags |= LL_SBI_NOROOTSQUASH;
2927 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
2929 spin_unlock(&squash->rsi_lock);
2933 * Parse linkea content to extract information about a given hardlink
2935 * \param[in] ldata - Initialized linkea data
2936 * \param[in] linkno - Link identifier
2937 * \param[out] parent_fid - The entry's parent FID
2938 * \param[out] ln - Entry name destination buffer
2940 * \retval 0 on success
2941 * \retval Appropriate negative error code on failure
2943 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
2944 struct lu_fid *parent_fid, struct lu_name *ln)
2950 rc = linkea_init_with_rec(ldata);
2954 if (linkno >= ldata->ld_leh->leh_reccount)
2955 /* beyond last link */
2958 linkea_first_entry(ldata);
2959 for (idx = 0; ldata->ld_lee != NULL; idx++) {
2960 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
2965 linkea_next_entry(ldata);
2975 * Get parent FID and name of an identified link. Operation is performed for
2976 * a given link number, letting the caller iterate over linkno to list one or
2977 * all links of an entry.
2979 * \param[in] file - File descriptor against which to perform the operation
2980 * \param[in,out] arg - User-filled structure containing the linkno to operate
2981 * on and the available size. It is eventually filled with
2982 * the requested information or left untouched on error
2984 * \retval - 0 on success
2985 * \retval - Appropriate negative error code on failure
2987 int ll_getparent(struct file *file, struct getparent __user *arg)
2989 struct inode *inode = file_inode(file);
2990 struct linkea_data *ldata;
2991 struct lu_buf buf = LU_BUF_NULL;
2993 struct lu_fid parent_fid;
3000 if (!cfs_capable(CFS_CAP_DAC_READ_SEARCH) &&
3001 !(ll_i2sbi(inode)->ll_flags & LL_SBI_USER_FID2PATH))
3004 if (get_user(name_size, &arg->gp_name_size))
3007 if (get_user(linkno, &arg->gp_linkno))
3010 if (name_size > PATH_MAX)
3013 OBD_ALLOC(ldata, sizeof(*ldata));
3017 rc = linkea_data_new(ldata, &buf);
3019 GOTO(ldata_free, rc);
3021 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3022 buf.lb_len, OBD_MD_FLXATTR);
3026 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3030 if (ln.ln_namelen >= name_size)
3031 GOTO(lb_free, rc = -EOVERFLOW);
3033 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3034 GOTO(lb_free, rc = -EFAULT);
3036 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3037 GOTO(lb_free, rc = -EFAULT);
3039 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3040 GOTO(lb_free, rc = -EFAULT);
3045 OBD_FREE(ldata, sizeof(*ldata));