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>
52 #include <linux/fs_struct.h>
54 #ifndef HAVE_CPUS_READ_LOCK
55 #include <libcfs/linux/linux-cpu.h>
57 #include <uapi/linux/lustre/lustre_ioctl.h>
58 #ifdef HAVE_UAPI_LINUX_MOUNT_H
59 #include <uapi/linux/mount.h>
62 #include <lustre_ha.h>
63 #include <lustre_dlm.h>
64 #include <lprocfs_status.h>
65 #include <lustre_disk.h>
66 #include <uapi/linux/lustre/lustre_param.h>
67 #include <lustre_log.h>
68 #include <cl_object.h>
69 #include <obd_cksum.h>
70 #include "llite_internal.h"
72 struct kmem_cache *ll_file_data_slab;
75 #define log2(n) ffz(~(n))
79 * If there is only one number of core visible to Lustre,
80 * async readahead will be disabled, to avoid massive over
81 * subscription, we use 1/2 of active cores as default max
82 * async readahead requests.
84 static inline unsigned int ll_get_ra_async_max_active(void)
86 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
89 static struct ll_sb_info *ll_init_sbi(void)
91 struct ll_sb_info *sbi = NULL;
93 unsigned long lru_page_max;
102 RETURN(ERR_PTR(-ENOMEM));
104 rc = pcc_super_init(&sbi->ll_pcc_super);
108 spin_lock_init(&sbi->ll_lock);
109 mutex_init(&sbi->ll_lco.lco_lock);
110 spin_lock_init(&sbi->ll_pp_extent_lock);
111 spin_lock_init(&sbi->ll_process_lock);
112 sbi->ll_rw_stats_on = 0;
113 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
116 pages = si.totalram - si.totalhigh;
117 lru_page_max = pages / 2;
119 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
120 sbi->ll_ra_info.ll_readahead_wq =
121 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
123 sbi->ll_ra_info.ra_async_max_active);
124 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
125 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
127 /* initialize ll_cache data */
128 sbi->ll_cache = cl_cache_init(lru_page_max);
129 if (sbi->ll_cache == NULL)
130 GOTO(out_destroy_ra, rc = -ENOMEM);
132 /* initialize foreign symlink prefix path */
133 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
134 if (sbi->ll_foreign_symlink_prefix == NULL)
135 GOTO(out_destroy_ra, rc = -ENOMEM);
136 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
137 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
139 /* initialize foreign symlink upcall path, none by default */
140 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
141 if (sbi->ll_foreign_symlink_upcall == NULL)
142 GOTO(out_destroy_ra, rc = -ENOMEM);
143 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
144 sbi->ll_foreign_symlink_upcall_items = NULL;
145 sbi->ll_foreign_symlink_upcall_nb_items = 0;
146 init_rwsem(&sbi->ll_foreign_symlink_sem);
147 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
148 * not enabled by default
151 sbi->ll_ra_info.ra_max_pages =
152 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
153 sbi->ll_ra_info.ra_max_pages_per_file =
154 min(sbi->ll_ra_info.ra_max_pages / 4,
155 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
156 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
157 sbi->ll_ra_info.ra_max_pages_per_file;
158 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
159 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
160 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
162 sbi->ll_flags |= LL_SBI_VERBOSE;
163 #ifdef ENABLE_CHECKSUM
164 sbi->ll_flags |= LL_SBI_CHECKSUM;
167 sbi->ll_flags |= LL_SBI_FLOCK;
170 #ifdef HAVE_LRU_RESIZE_SUPPORT
171 sbi->ll_flags |= LL_SBI_LRU_RESIZE;
173 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
175 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
176 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
178 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
182 /* metadata statahead is enabled by default */
183 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
184 sbi->ll_sa_max = LL_SA_RPC_DEF;
185 atomic_set(&sbi->ll_sa_total, 0);
186 atomic_set(&sbi->ll_sa_wrong, 0);
187 atomic_set(&sbi->ll_sa_running, 0);
188 atomic_set(&sbi->ll_agl_total, 0);
189 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
190 sbi->ll_flags |= LL_SBI_FAST_READ;
191 sbi->ll_flags |= LL_SBI_TINY_WRITE;
192 ll_sbi_set_encrypt(sbi, true);
195 sbi->ll_squash.rsi_uid = 0;
196 sbi->ll_squash.rsi_gid = 0;
197 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
198 spin_lock_init(&sbi->ll_squash.rsi_lock);
200 /* Per-filesystem file heat */
201 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
202 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
205 if (sbi->ll_foreign_symlink_prefix)
206 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
208 cl_cache_decref(sbi->ll_cache);
209 sbi->ll_cache = NULL;
211 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
213 pcc_super_fini(&sbi->ll_pcc_super);
219 static void ll_free_sbi(struct super_block *sb)
221 struct ll_sb_info *sbi = ll_s2sbi(sb);
225 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
226 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
227 if (sbi->ll_ra_info.ll_readahead_wq)
228 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
229 if (sbi->ll_cache != NULL) {
230 cl_cache_decref(sbi->ll_cache);
231 sbi->ll_cache = NULL;
233 if (sbi->ll_foreign_symlink_prefix) {
234 OBD_FREE(sbi->ll_foreign_symlink_prefix,
235 sbi->ll_foreign_symlink_prefix_size);
236 sbi->ll_foreign_symlink_prefix = NULL;
238 if (sbi->ll_foreign_symlink_upcall) {
239 OBD_FREE(sbi->ll_foreign_symlink_upcall,
240 strlen(sbi->ll_foreign_symlink_upcall) +
242 sbi->ll_foreign_symlink_upcall = NULL;
244 if (sbi->ll_foreign_symlink_upcall_items) {
246 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
247 struct ll_foreign_symlink_upcall_item *items =
248 sbi->ll_foreign_symlink_upcall_items;
250 for (i = 0 ; i < nb_items; i++)
251 if (items[i].type == STRING_TYPE)
252 OBD_FREE(items[i].string,
255 OBD_FREE_LARGE(items, nb_items *
256 sizeof(struct ll_foreign_symlink_upcall_item));
257 sbi->ll_foreign_symlink_upcall_items = NULL;
259 pcc_super_fini(&sbi->ll_pcc_super);
260 OBD_FREE(sbi, sizeof(*sbi));
265 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
267 struct inode *root = NULL;
268 struct ll_sb_info *sbi = ll_s2sbi(sb);
269 struct obd_statfs *osfs = NULL;
270 struct ptlrpc_request *request = NULL;
271 struct obd_connect_data *data = NULL;
272 struct obd_uuid *uuid;
273 struct md_op_data *op_data;
274 struct lustre_md lmd;
276 int size, err, checksum;
279 sbi->ll_md_obd = class_name2obd(md);
280 if (!sbi->ll_md_obd) {
281 CERROR("MD %s: not setup or attached\n", md);
295 /* pass client page size via ocd_grant_blkbits, the server should report
296 * back its backend blocksize for grant calculation purpose */
297 data->ocd_grant_blkbits = PAGE_SHIFT;
299 /* indicate MDT features supported by this client */
300 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
301 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
302 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
303 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
304 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
305 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
306 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
307 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
308 OBD_CONNECT_64BITHASH |
309 OBD_CONNECT_EINPROGRESS |
310 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
311 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
312 OBD_CONNECT_MAX_EASIZE |
313 OBD_CONNECT_FLOCK_DEAD |
314 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
315 OBD_CONNECT_OPEN_BY_FID |
316 OBD_CONNECT_DIR_STRIPE |
317 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
318 OBD_CONNECT_SUBTREE |
319 OBD_CONNECT_MULTIMODRPCS |
320 OBD_CONNECT_GRANT_PARAM |
321 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
323 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
324 OBD_CONNECT2_SUM_STATFS |
325 OBD_CONNECT2_OVERSTRIPING |
327 OBD_CONNECT2_LOCK_CONVERT |
328 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
329 OBD_CONNECT2_INC_XID |
331 OBD_CONNECT2_ASYNC_DISCARD |
333 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
334 OBD_CONNECT2_GETATTR_PFID |
335 OBD_CONNECT2_DOM_LVB;
337 #ifdef HAVE_LRU_RESIZE_SUPPORT
338 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
339 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
341 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
343 data->ocd_cksum_types = obd_cksum_types_supported_client();
345 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
346 /* flag mdc connection as lightweight, only used for test
347 * purpose, use with care */
348 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
350 data->ocd_ibits_known = MDS_INODELOCK_FULL;
351 data->ocd_version = LUSTRE_VERSION_CODE;
353 if (sb->s_flags & SB_RDONLY)
354 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
355 if (sbi->ll_flags & LL_SBI_USER_XATTR)
356 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
359 /* Setting this indicates we correctly support S_NOSEC (See kernel
360 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
362 sb->s_flags |= SB_NOSEC;
364 sbi->ll_fop = ll_select_file_operations(sbi);
366 /* always ping even if server suppress_pings */
367 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
368 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
370 obd_connect_set_secctx(data);
371 if (ll_sbi_has_encrypt(sbi))
372 obd_connect_set_enc(data);
374 #if defined(CONFIG_SECURITY)
375 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
378 data->ocd_brw_size = MD_MAX_BRW_SIZE;
380 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
381 &sbi->ll_sb_uuid, data, sbi->ll_cache);
383 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
384 "recovery, of which this client is not a "
385 "part. Please wait for recovery to complete,"
386 " abort, or time out.\n", md);
389 CERROR("cannot connect to %s: rc = %d\n", md, err);
393 sbi->ll_md_exp->exp_connect_data = *data;
395 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
396 LUSTRE_SEQ_METADATA);
398 CERROR("%s: Can't init metadata layer FID infrastructure, "
399 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
403 /* For mount, we only need fs info from MDT0, and also in DNE, it
404 * can make sure the client can be mounted as long as MDT0 is
406 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
407 ktime_get_seconds() - sbi->ll_statfs_max_age,
408 OBD_STATFS_FOR_MDT0);
410 GOTO(out_md_fid, err);
412 /* This needs to be after statfs to ensure connect has finished.
413 * Note that "data" does NOT contain the valid connect reply.
414 * If connecting to a 1.8 server there will be no LMV device, so
415 * we can access the MDC export directly and exp_connect_flags will
416 * be non-zero, but if accessing an upgraded 2.1 server it will
417 * have the correct flags filled in.
418 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
419 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
420 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
421 valid != CLIENT_CONNECT_MDT_REQD) {
424 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
425 obd_connect_flags2str(buf, PAGE_SIZE,
426 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
427 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
428 "feature(s) needed for correct operation "
429 "of this client (%s). Please upgrade "
430 "server or downgrade client.\n",
431 sbi->ll_md_exp->exp_obd->obd_name, buf);
432 OBD_FREE(buf, PAGE_SIZE);
433 GOTO(out_md_fid, err = -EPROTO);
436 size = sizeof(*data);
437 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
438 KEY_CONN_DATA, &size, data);
440 CERROR("%s: Get connect data failed: rc = %d\n",
441 sbi->ll_md_exp->exp_obd->obd_name, err);
442 GOTO(out_md_fid, err);
445 LASSERT(osfs->os_bsize);
446 sb->s_blocksize = osfs->os_bsize;
447 sb->s_blocksize_bits = log2(osfs->os_bsize);
448 sb->s_magic = LL_SUPER_MAGIC;
449 sb->s_maxbytes = MAX_LFS_FILESIZE;
450 sbi->ll_namelen = osfs->os_namelen;
451 sbi->ll_mnt.mnt = current->fs->root.mnt;
453 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
454 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
455 LCONSOLE_INFO("Disabling user_xattr feature because "
456 "it is not supported on the server\n");
457 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
460 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
462 sb->s_flags |= SB_POSIXACL;
464 sbi->ll_flags |= LL_SBI_ACL;
466 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
468 sb->s_flags &= ~SB_POSIXACL;
470 sbi->ll_flags &= ~LL_SBI_ACL;
473 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
474 sbi->ll_flags |= LL_SBI_64BIT_HASH;
476 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
477 sbi->ll_flags |= LL_SBI_LAYOUT_LOCK;
479 if (obd_connect_has_secctx(data))
480 sbi->ll_flags |= LL_SBI_FILE_SECCTX;
482 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
483 if (ll_sbi_has_test_dummy_encryption(sbi))
484 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
486 sbi->ll_md_exp->exp_obd->obd_name);
487 ll_sbi_set_encrypt(sbi, false);
490 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
491 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
492 LCONSOLE_INFO("%s: disabling xattr cache due to "
493 "unknown maximum xattr size.\n", dt);
494 } else if (!sbi->ll_xattr_cache_set) {
495 /* If xattr_cache is already set (no matter 0 or 1)
496 * during processing llog, it won't be enabled here. */
497 sbi->ll_flags |= LL_SBI_XATTR_CACHE;
498 sbi->ll_xattr_cache_enabled = 1;
502 sbi->ll_dt_obd = class_name2obd(dt);
503 if (!sbi->ll_dt_obd) {
504 CERROR("DT %s: not setup or attached\n", dt);
505 GOTO(out_md_fid, err = -ENODEV);
508 /* pass client page size via ocd_grant_blkbits, the server should report
509 * back its backend blocksize for grant calculation purpose */
510 data->ocd_grant_blkbits = PAGE_SHIFT;
512 /* indicate OST features supported by this client */
513 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
514 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
515 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
516 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
517 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
518 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
519 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
520 OBD_CONNECT_EINPROGRESS |
521 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
522 OBD_CONNECT_LAYOUTLOCK |
523 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
524 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
525 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
526 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
527 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK;
529 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
530 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
532 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
533 * disabled by default, because it can still be enabled on the
534 * fly via /sys. As a consequence, we still need to come to an
535 * agreement on the supported algorithms at connect time
537 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
539 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
540 data->ocd_cksum_types = OBD_CKSUM_ADLER;
542 data->ocd_cksum_types = obd_cksum_types_supported_client();
544 #ifdef HAVE_LRU_RESIZE_SUPPORT
545 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
547 /* always ping even if server suppress_pings */
548 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
549 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
551 if (ll_sbi_has_encrypt(sbi))
552 obd_connect_set_enc(data);
554 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
555 "ocd_grant: %d\n", data->ocd_connect_flags,
556 data->ocd_version, data->ocd_grant);
558 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
559 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
561 data->ocd_brw_size = DT_MAX_BRW_SIZE;
563 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
564 &sbi->ll_sb_uuid, data, sbi->ll_cache);
566 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
567 "recovery, of which this client is not a "
568 "part. Please wait for recovery to "
569 "complete, abort, or time out.\n", dt);
572 CERROR("%s: Cannot connect to %s: rc = %d\n",
573 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
577 if (ll_sbi_has_encrypt(sbi) &&
578 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
579 if (ll_sbi_has_test_dummy_encryption(sbi))
580 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
582 ll_sbi_set_encrypt(sbi, false);
583 } else if (ll_sbi_has_test_dummy_encryption(sbi)) {
584 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
587 sbi->ll_dt_exp->exp_connect_data = *data;
589 /* Don't change value if it was specified in the config log */
590 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
591 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
592 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
593 (data->ocd_brw_size >> PAGE_SHIFT));
594 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
595 sbi->ll_ra_info.ra_max_pages_per_file)
596 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
597 sbi->ll_ra_info.ra_max_pages_per_file;
600 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
601 LUSTRE_SEQ_METADATA);
603 CERROR("%s: Can't init data layer FID infrastructure, "
604 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
608 mutex_lock(&sbi->ll_lco.lco_lock);
609 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
610 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
611 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
612 mutex_unlock(&sbi->ll_lco.lco_lock);
614 fid_zero(&sbi->ll_root_fid);
615 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
618 CERROR("cannot mds_connect: rc = %d\n", err);
619 GOTO(out_lock_cn_cb, err);
621 if (!fid_is_sane(&sbi->ll_root_fid)) {
622 CERROR("%s: Invalid root fid "DFID" during mount\n",
623 sbi->ll_md_exp->exp_obd->obd_name,
624 PFID(&sbi->ll_root_fid));
625 GOTO(out_lock_cn_cb, err = -EINVAL);
627 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
629 sb->s_op = &lustre_super_operations;
630 sb->s_xattr = ll_xattr_handlers;
631 #if THREAD_SIZE >= 8192 /*b=17630*/
632 sb->s_export_op = &lustre_export_operations;
634 #ifdef HAVE_LUSTRE_CRYPTO
635 llcrypt_set_ops(sb, &lustre_cryptops);
639 * XXX: move this to after cbd setup? */
640 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
641 if (sbi->ll_flags & LL_SBI_ACL)
642 valid |= OBD_MD_FLACL;
644 OBD_ALLOC_PTR(op_data);
646 GOTO(out_lock_cn_cb, err = -ENOMEM);
648 op_data->op_fid1 = sbi->ll_root_fid;
649 op_data->op_mode = 0;
650 op_data->op_valid = valid;
652 err = md_getattr(sbi->ll_md_exp, op_data, &request);
654 OBD_FREE_PTR(op_data);
656 CERROR("%s: md_getattr failed for root: rc = %d\n",
657 sbi->ll_md_exp->exp_obd->obd_name, err);
658 GOTO(out_lock_cn_cb, err);
661 err = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
662 sbi->ll_md_exp, &lmd);
664 CERROR("failed to understand root inode md: rc = %d\n", err);
665 ptlrpc_req_finished(request);
666 GOTO(out_lock_cn_cb, err);
669 LASSERT(fid_is_sane(&sbi->ll_root_fid));
670 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid,
671 sbi->ll_flags & LL_SBI_32BIT_API),
673 md_free_lustre_md(sbi->ll_md_exp, &lmd);
674 ptlrpc_req_finished(request);
678 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
680 CERROR("%s: bad ll_iget() for root: rc = %d\n",
681 sbi->ll_fsname, err);
685 checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
686 if (sbi->ll_checksum_set) {
687 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
688 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
689 sizeof(checksum), &checksum, NULL);
691 CERROR("%s: Set checksum failed: rc = %d\n",
692 sbi->ll_dt_exp->exp_obd->obd_name, err);
698 sb->s_root = d_make_root(root);
699 if (sb->s_root == NULL) {
701 CERROR("%s: can't make root dentry: rc = %d\n",
702 sbi->ll_fsname, err);
706 sbi->ll_sdev_orig = sb->s_dev;
708 /* We set sb->s_dev equal on all lustre clients in order to support
709 * NFS export clustering. NFSD requires that the FSID be the same
711 /* s_dev is also used in lt_compare() to compare two fs, but that is
712 * only a node-local comparison. */
713 uuid = obd_get_uuid(sbi->ll_md_exp);
715 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
722 if (sbi->ll_dt_obd) {
723 err = sysfs_create_link(&sbi->ll_kset.kobj,
724 &sbi->ll_dt_obd->obd_kset.kobj,
725 sbi->ll_dt_obd->obd_type->typ_name);
727 CERROR("%s: could not register %s in llite: rc = %d\n",
728 dt, sbi->ll_fsname, err);
733 if (sbi->ll_md_obd) {
734 err = sysfs_create_link(&sbi->ll_kset.kobj,
735 &sbi->ll_md_obd->obd_kset.kobj,
736 sbi->ll_md_obd->obd_type->typ_name);
738 CERROR("%s: could not register %s in llite: rc = %d\n",
739 md, sbi->ll_fsname, err);
748 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
750 obd_disconnect(sbi->ll_dt_exp);
751 sbi->ll_dt_exp = NULL;
752 sbi->ll_dt_obd = NULL;
754 obd_fid_fini(sbi->ll_md_exp->exp_obd);
756 obd_disconnect(sbi->ll_md_exp);
757 sbi->ll_md_exp = NULL;
758 sbi->ll_md_obd = NULL;
767 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
771 size = sizeof(*lmmsize);
772 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
773 KEY_MAX_EASIZE, &size, lmmsize);
775 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
776 sbi->ll_dt_exp->exp_obd->obd_name, rc);
780 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
783 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
784 KEY_MAX_EASIZE, &size, lmmsize);
786 CERROR("Get max mdsize error rc %d\n", rc);
788 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
794 * Get the value of the default_easize parameter.
796 * \see client_obd::cl_default_mds_easize
798 * \param[in] sbi superblock info for this filesystem
799 * \param[out] lmmsize pointer to storage location for value
801 * \retval 0 on success
802 * \retval negative negated errno on failure
804 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
809 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
810 KEY_DEFAULT_EASIZE, &size, lmmsize);
812 CERROR("Get default mdsize error rc %d\n", rc);
818 * Set the default_easize parameter to the given value.
820 * \see client_obd::cl_default_mds_easize
822 * \param[in] sbi superblock info for this filesystem
823 * \param[in] lmmsize the size to set
825 * \retval 0 on success
826 * \retval negative negated errno on failure
828 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
832 if (lmmsize < sizeof(struct lov_mds_md) ||
833 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
836 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
837 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
838 sizeof(int), &lmmsize, NULL);
843 static void client_common_put_super(struct super_block *sb)
845 struct ll_sb_info *sbi = ll_s2sbi(sb);
850 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
851 obd_disconnect(sbi->ll_dt_exp);
852 sbi->ll_dt_exp = NULL;
854 ll_debugfs_unregister_super(sb);
856 obd_fid_fini(sbi->ll_md_exp->exp_obd);
857 obd_disconnect(sbi->ll_md_exp);
858 sbi->ll_md_exp = NULL;
863 void ll_kill_super(struct super_block *sb)
865 struct ll_sb_info *sbi;
869 if (!(sb->s_flags & SB_ACTIVE))
873 /* we need restore s_dev from changed for clustred NFS before put_super
874 * because new kernels have cached s_dev and change sb->s_dev in
875 * put_super not affected real removing devices */
877 sb->s_dev = sbi->ll_sdev_orig;
879 /* wait running statahead threads to quit */
880 while (atomic_read(&sbi->ll_sa_running) > 0)
881 schedule_timeout_uninterruptible(
882 cfs_time_seconds(1) >> 3);
888 static inline int ll_set_opt(const char *opt, char *data, int fl)
890 if (strncmp(opt, data, strlen(opt)) != 0)
896 /* non-client-specific mount options are parsed in lmd_parse */
897 static int ll_options(char *options, struct ll_sb_info *sbi)
900 char *s1 = options, *s2;
901 int *flags = &sbi->ll_flags;
907 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
910 CDEBUG(D_SUPER, "next opt=%s\n", s1);
911 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
916 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
918 *flags = (*flags & ~LL_SBI_LOCALFLOCK) | tmp;
921 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
923 *flags = (*flags & ~LL_SBI_FLOCK) | tmp;
926 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
931 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
936 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
941 tmp = ll_set_opt("context", s1, 1);
944 tmp = ll_set_opt("fscontext", s1, 1);
947 tmp = ll_set_opt("defcontext", s1, 1);
950 tmp = ll_set_opt("rootcontext", s1, 1);
953 tmp = ll_set_opt("user_fid2path", s1, LL_SBI_USER_FID2PATH);
958 tmp = ll_set_opt("nouser_fid2path", s1, LL_SBI_USER_FID2PATH);
964 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
967 sbi->ll_checksum_set = 1;
970 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
973 sbi->ll_checksum_set = 1;
976 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
981 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
986 tmp = ll_set_opt("lazystatfs", s1, LL_SBI_LAZYSTATFS);
991 tmp = ll_set_opt("nolazystatfs", s1, LL_SBI_LAZYSTATFS);
996 tmp = ll_set_opt("32bitapi", s1, LL_SBI_32BIT_API);
1001 tmp = ll_set_opt("verbose", s1, LL_SBI_VERBOSE);
1006 tmp = ll_set_opt("noverbose", s1, LL_SBI_VERBOSE);
1011 tmp = ll_set_opt("always_ping", s1, LL_SBI_ALWAYS_PING);
1016 tmp = ll_set_opt("test_dummy_encryption", s1,
1017 LL_SBI_TEST_DUMMY_ENCRYPTION);
1019 #ifdef HAVE_LUSTRE_CRYPTO
1022 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1026 tmp = ll_set_opt("noencrypt", s1, LL_SBI_ENCRYPT);
1028 #ifdef HAVE_LUSTRE_CRYPTO
1031 LCONSOLE_WARN("noencrypt mount option ignored: encryption not supported\n");
1035 tmp = ll_set_opt("foreign_symlink", s1, LL_SBI_FOREIGN_SYMLINK);
1037 int prefix_pos = sizeof("foreign_symlink=") - 1;
1038 int equal_pos = sizeof("foreign_symlink=") - 2;
1040 /* non-default prefix provided ? */
1041 if (strlen(s1) >= sizeof("foreign_symlink=") &&
1042 *(s1 + equal_pos) == '=') {
1043 char *old = sbi->ll_foreign_symlink_prefix;
1045 sbi->ll_foreign_symlink_prefix_size;
1047 /* path must be absolute */
1048 if (*(s1 + sizeof("foreign_symlink=")
1050 LCONSOLE_ERROR_MSG(0x152,
1051 "foreign prefix '%s' must be an absolute path\n",
1056 s2 = strchrnul(s1 + prefix_pos, ',');
1058 if (sbi->ll_foreign_symlink_prefix) {
1059 sbi->ll_foreign_symlink_prefix = NULL;
1060 sbi->ll_foreign_symlink_prefix_size = 0;
1062 /* alloc for path length and '\0' */
1063 OBD_ALLOC(sbi->ll_foreign_symlink_prefix,
1064 s2 - (s1 + prefix_pos) + 1);
1065 if (!sbi->ll_foreign_symlink_prefix) {
1066 /* restore previous */
1067 sbi->ll_foreign_symlink_prefix = old;
1068 sbi->ll_foreign_symlink_prefix_size =
1073 OBD_FREE(old, old_len);
1074 strncpy(sbi->ll_foreign_symlink_prefix,
1076 s2 - (s1 + prefix_pos));
1077 sbi->ll_foreign_symlink_prefix_size =
1078 s2 - (s1 + prefix_pos) + 1;
1080 LCONSOLE_ERROR_MSG(0x152,
1081 "invalid %s option\n", s1);
1083 /* enable foreign symlink support */
1087 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
1093 s2 = strchr(s1, ',');
1101 void ll_lli_init(struct ll_inode_info *lli)
1103 lli->lli_inode_magic = LLI_INODE_MAGIC;
1105 spin_lock_init(&lli->lli_lock);
1106 lli->lli_posix_acl = NULL;
1107 /* Do not set lli_fid, it has been initialized already. */
1108 fid_zero(&lli->lli_pfid);
1109 lli->lli_mds_read_och = NULL;
1110 lli->lli_mds_write_och = NULL;
1111 lli->lli_mds_exec_och = NULL;
1112 lli->lli_open_fd_read_count = 0;
1113 lli->lli_open_fd_write_count = 0;
1114 lli->lli_open_fd_exec_count = 0;
1115 mutex_init(&lli->lli_och_mutex);
1116 spin_lock_init(&lli->lli_agl_lock);
1117 spin_lock_init(&lli->lli_layout_lock);
1118 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1119 lli->lli_clob = NULL;
1121 init_rwsem(&lli->lli_xattrs_list_rwsem);
1122 mutex_init(&lli->lli_xattrs_enq_lock);
1124 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1125 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1126 lli->lli_opendir_key = NULL;
1127 lli->lli_sai = NULL;
1128 spin_lock_init(&lli->lli_sa_lock);
1129 lli->lli_opendir_pid = 0;
1130 lli->lli_sa_enabled = 0;
1131 init_rwsem(&lli->lli_lsm_sem);
1133 mutex_init(&lli->lli_size_mutex);
1134 mutex_init(&lli->lli_setattr_mutex);
1135 lli->lli_symlink_name = NULL;
1136 ll_trunc_sem_init(&lli->lli_trunc_sem);
1137 range_lock_tree_init(&lli->lli_write_tree);
1138 init_rwsem(&lli->lli_glimpse_sem);
1139 lli->lli_glimpse_time = ktime_set(0, 0);
1140 INIT_LIST_HEAD(&lli->lli_agl_list);
1141 lli->lli_agl_index = 0;
1142 lli->lli_async_rc = 0;
1143 spin_lock_init(&lli->lli_heat_lock);
1144 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1145 lli->lli_heat_flags = 0;
1146 mutex_init(&lli->lli_pcc_lock);
1147 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1148 lli->lli_pcc_inode = NULL;
1149 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1150 lli->lli_pcc_generation = 0;
1151 mutex_init(&lli->lli_group_mutex);
1152 lli->lli_group_users = 0;
1153 lli->lli_group_gid = 0;
1155 mutex_init(&lli->lli_layout_mutex);
1156 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1159 #define MAX_STRING_SIZE 128
1161 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1163 #define LSI_BDI_INITIALIZED 0x00400000
1165 #ifndef HAVE_BDI_CAP_MAP_COPY
1166 # define BDI_CAP_MAP_COPY 0
1169 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1171 struct lustre_sb_info *lsi = s2lsi(sb);
1172 char buf[MAX_STRING_SIZE];
1176 err = bdi_init(&lsi->lsi_bdi);
1180 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1181 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1182 lsi->lsi_bdi.name = "lustre";
1183 va_start(args, fmt);
1184 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1186 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1189 sb->s_bdi = &lsi->lsi_bdi;
1193 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1195 int ll_fill_super(struct super_block *sb)
1197 struct lustre_profile *lprof = NULL;
1198 struct lustre_sb_info *lsi = s2lsi(sb);
1199 struct ll_sb_info *sbi = NULL;
1200 char *dt = NULL, *md = NULL;
1201 char *profilenm = get_profile_name(sb);
1202 struct config_llog_instance *cfg;
1203 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1204 const int instlen = LUSTRE_MAXINSTANCE + 2;
1205 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1206 char name[MAX_STRING_SIZE];
1215 /* for ASLR, to map between cfg_instance and hashed ptr */
1216 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1217 profilenm, cfg_instance, sb);
1221 GOTO(out_free_cfg, err = -ENOMEM);
1223 /* client additional sb info */
1224 lsi->lsi_llsbi = sbi = ll_init_sbi();
1226 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1228 err = ll_options(lsi->lsi_lmd->lmd_opts, sbi);
1230 GOTO(out_free_cfg, err);
1232 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1233 sb->s_d_op = &ll_d_ops;
1236 generate_random_uuid(uuid.b);
1237 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1239 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1242 len = strlen(profilenm);
1243 ptr = strrchr(profilenm, '-');
1244 if (ptr && (strcmp(ptr, "-client") == 0))
1247 if (len > LUSTRE_MAXFSNAME) {
1248 if (unlikely(len >= MAX_STRING_SIZE))
1249 len = MAX_STRING_SIZE - 1;
1250 strncpy(name, profilenm, len);
1252 err = -ENAMETOOLONG;
1253 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1254 name, LUSTRE_MAXFSNAME, err);
1255 GOTO(out_free_cfg, err);
1257 strncpy(sbi->ll_fsname, profilenm, len);
1258 sbi->ll_fsname[len] = '\0';
1261 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1262 profilenm, cfg_instance);
1264 err = super_setup_bdi_name(sb, "%s", name);
1266 GOTO(out_free_cfg, err);
1268 /* Call ll_debugfs_register_super() before lustre_process_log()
1269 * so that "llite.*.*" params can be processed correctly.
1271 err = ll_debugfs_register_super(sb, name);
1273 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1274 sbi->ll_fsname, err);
1278 /* The cfg_instance is a value unique to this super, in case some
1279 * joker tries to mount the same fs at two mount points.
1281 cfg->cfg_instance = cfg_instance;
1282 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1283 cfg->cfg_callback = class_config_llog_handler;
1284 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1285 /* set up client obds */
1286 err = lustre_process_log(sb, profilenm, cfg);
1288 GOTO(out_debugfs, err);
1290 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1291 lprof = class_get_profile(profilenm);
1292 if (lprof == NULL) {
1293 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1294 " read from the MGS. Does that filesystem "
1295 "exist?\n", profilenm);
1296 GOTO(out_debugfs, err = -EINVAL);
1298 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1299 lprof->lp_md, lprof->lp_dt);
1301 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1302 OBD_ALLOC(dt, dt_len);
1304 GOTO(out_profile, err = -ENOMEM);
1305 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1307 md_len = strlen(lprof->lp_md) + instlen + 2;
1308 OBD_ALLOC(md, md_len);
1310 GOTO(out_free_dt, err = -ENOMEM);
1311 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1313 /* connections, registrations, sb setup */
1314 err = client_common_fill_super(sb, md, dt);
1316 GOTO(out_free_md, err);
1318 sbi->ll_client_common_fill_super_succeeded = 1;
1322 OBD_FREE(md, md_len);
1325 OBD_FREE(dt, dt_len);
1328 class_put_profile(lprof);
1331 ll_debugfs_unregister_super(sb);
1338 else if (sbi->ll_flags & LL_SBI_VERBOSE)
1339 LCONSOLE_WARN("Mounted %s\n", profilenm);
1341 } /* ll_fill_super */
1343 void ll_put_super(struct super_block *sb)
1345 struct config_llog_instance cfg, params_cfg;
1346 struct obd_device *obd;
1347 struct lustre_sb_info *lsi = s2lsi(sb);
1348 struct ll_sb_info *sbi = ll_s2sbi(sb);
1349 char *profilenm = get_profile_name(sb);
1350 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1352 int next, force = 1, rc = 0;
1356 GOTO(out_no_sbi, 0);
1358 /* Should replace instance_id with something better for ASLR */
1359 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1360 profilenm, cfg_instance, sb);
1362 cfg.cfg_instance = cfg_instance;
1363 lustre_end_log(sb, profilenm, &cfg);
1365 params_cfg.cfg_instance = cfg_instance;
1366 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1368 if (sbi->ll_md_exp) {
1369 obd = class_exp2obd(sbi->ll_md_exp);
1371 force = obd->obd_force;
1374 /* Wait for unstable pages to be committed to stable storage */
1376 rc = l_wait_event_abortable(
1377 sbi->ll_cache->ccc_unstable_waitq,
1378 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1381 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1382 if (force == 0 && rc != -ERESTARTSYS)
1383 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1385 /* We need to set force before the lov_disconnect in
1386 * lustre_common_put_super, since l_d cleans up osc's as well.
1390 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1392 obd->obd_force = force;
1396 if (sbi->ll_client_common_fill_super_succeeded) {
1397 /* Only if client_common_fill_super succeeded */
1398 client_common_put_super(sb);
1402 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1403 class_manual_cleanup(obd);
1405 if (sbi->ll_flags & LL_SBI_VERBOSE)
1406 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1409 class_del_profile(profilenm);
1411 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1412 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1413 bdi_destroy(&lsi->lsi_bdi);
1414 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1419 lsi->lsi_llsbi = NULL;
1421 lustre_common_put_super(sb);
1423 cl_env_cache_purge(~0);
1426 } /* client_put_super */
1428 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1430 struct inode *inode = NULL;
1432 /* NOTE: we depend on atomic igrab() -bzzz */
1433 lock_res_and_lock(lock);
1434 if (lock->l_resource->lr_lvb_inode) {
1435 struct ll_inode_info * lli;
1436 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1437 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1438 inode = igrab(lock->l_resource->lr_lvb_inode);
1440 inode = lock->l_resource->lr_lvb_inode;
1441 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1442 D_WARNING, lock, "lr_lvb_inode %p is "
1443 "bogus: magic %08x",
1444 lock->l_resource->lr_lvb_inode,
1445 lli->lli_inode_magic);
1449 unlock_res_and_lock(lock);
1453 void ll_dir_clear_lsm_md(struct inode *inode)
1455 struct ll_inode_info *lli = ll_i2info(inode);
1457 LASSERT(S_ISDIR(inode->i_mode));
1459 if (lli->lli_lsm_md) {
1460 lmv_free_memmd(lli->lli_lsm_md);
1461 lli->lli_lsm_md = NULL;
1464 if (lli->lli_default_lsm_md) {
1465 lmv_free_memmd(lli->lli_default_lsm_md);
1466 lli->lli_default_lsm_md = NULL;
1470 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1471 const struct lu_fid *fid,
1472 struct lustre_md *md)
1474 struct ll_sb_info *sbi = ll_s2sbi(sb);
1475 struct mdt_body *body = md->body;
1476 struct inode *inode;
1480 ino = cl_fid_build_ino(fid, sbi->ll_flags & LL_SBI_32BIT_API);
1481 inode = iget_locked(sb, ino);
1482 if (inode == NULL) {
1483 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1484 sbi->ll_fsname, PFID(fid));
1485 RETURN(ERR_PTR(-ENOENT));
1488 if (inode->i_state & I_NEW) {
1489 struct ll_inode_info *lli = ll_i2info(inode);
1490 struct lmv_stripe_md *lsm = md->lmv;
1492 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1493 (body->mbo_mode & S_IFMT);
1494 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1497 inode->i_mtime.tv_sec = 0;
1498 inode->i_atime.tv_sec = 0;
1499 inode->i_ctime.tv_sec = 0;
1502 #ifdef HAVE_BACKING_DEV_INFO
1503 /* initializing backing dev info. */
1504 inode->i_mapping->backing_dev_info =
1505 &s2lsi(inode->i_sb)->lsi_bdi;
1507 inode->i_op = &ll_dir_inode_operations;
1508 inode->i_fop = &ll_dir_operations;
1509 lli->lli_fid = *fid;
1512 LASSERT(lsm != NULL);
1513 /* master object FID */
1514 lli->lli_pfid = body->mbo_fid1;
1515 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1516 lli, PFID(fid), PFID(&lli->lli_pfid));
1517 unlock_new_inode(inode);
1523 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1526 struct lmv_stripe_md *lsm = md->lmv;
1527 struct ll_inode_info *lli = ll_i2info(inode);
1530 LASSERT(lsm != NULL);
1532 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1533 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1534 lsm_md_dump(D_INODE, lsm);
1536 if (!lmv_dir_striped(lsm))
1539 /* XXX sigh, this lsm_root initialization should be in
1540 * LMV layer, but it needs ll_iget right now, so we
1541 * put this here right now. */
1542 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1543 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1544 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1546 if (!fid_is_sane(fid))
1549 /* Unfortunately ll_iget will call ll_update_inode,
1550 * where the initialization of slave inode is slightly
1551 * different, so it reset lsm_md to NULL to avoid
1552 * initializing lsm for slave inode. */
1553 lsm->lsm_md_oinfo[i].lmo_root =
1554 ll_iget_anon_dir(inode->i_sb, fid, md);
1555 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1556 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1558 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1560 iput(lsm->lsm_md_oinfo[i].lmo_root);
1561 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1567 lli->lli_lsm_md = lsm;
1572 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1574 struct ll_inode_info *lli = ll_i2info(inode);
1576 if (!md->default_lmv) {
1577 /* clear default lsm */
1578 if (lli->lli_default_lsm_md) {
1579 down_write(&lli->lli_lsm_sem);
1580 if (lli->lli_default_lsm_md) {
1581 lmv_free_memmd(lli->lli_default_lsm_md);
1582 lli->lli_default_lsm_md = NULL;
1584 up_write(&lli->lli_lsm_sem);
1586 } else if (lli->lli_default_lsm_md) {
1587 /* update default lsm if it changes */
1588 down_read(&lli->lli_lsm_sem);
1589 if (lli->lli_default_lsm_md &&
1590 !lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1591 up_read(&lli->lli_lsm_sem);
1592 down_write(&lli->lli_lsm_sem);
1593 if (lli->lli_default_lsm_md)
1594 lmv_free_memmd(lli->lli_default_lsm_md);
1595 lli->lli_default_lsm_md = md->default_lmv;
1596 lsm_md_dump(D_INODE, md->default_lmv);
1597 md->default_lmv = NULL;
1598 up_write(&lli->lli_lsm_sem);
1600 up_read(&lli->lli_lsm_sem);
1603 /* init default lsm */
1604 down_write(&lli->lli_lsm_sem);
1605 lli->lli_default_lsm_md = md->default_lmv;
1606 lsm_md_dump(D_INODE, md->default_lmv);
1607 md->default_lmv = NULL;
1608 up_write(&lli->lli_lsm_sem);
1612 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1614 struct ll_inode_info *lli = ll_i2info(inode);
1615 struct lmv_stripe_md *lsm = md->lmv;
1616 struct cl_attr *attr;
1621 LASSERT(S_ISDIR(inode->i_mode));
1622 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1623 PFID(ll_inode2fid(inode)));
1625 /* update default LMV */
1626 if (md->default_lmv)
1627 ll_update_default_lsm_md(inode, md);
1630 * no striped information from request, lustre_md from req does not
1631 * include stripeEA, see ll_md_setattr()
1637 * normally dir layout doesn't change, only take read lock to check
1638 * that to avoid blocking other MD operations.
1640 down_read(&lli->lli_lsm_sem);
1642 /* some current lookup initialized lsm, and unchanged */
1643 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1644 GOTO(unlock, rc = 0);
1646 /* if dir layout doesn't match, check whether version is increased,
1647 * which means layout is changed, this happens in dir split/merge and
1650 * foreign LMV should not change.
1652 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1653 lsm->lsm_md_layout_version <=
1654 lli->lli_lsm_md->lsm_md_layout_version) {
1655 CERROR("%s: "DFID" dir layout mismatch:\n",
1656 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1657 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1658 lsm_md_dump(D_ERROR, lsm);
1659 GOTO(unlock, rc = -EINVAL);
1662 up_read(&lli->lli_lsm_sem);
1663 down_write(&lli->lli_lsm_sem);
1664 /* clear existing lsm */
1665 if (lli->lli_lsm_md) {
1666 lmv_free_memmd(lli->lli_lsm_md);
1667 lli->lli_lsm_md = NULL;
1670 rc = ll_init_lsm_md(inode, md);
1671 up_write(&lli->lli_lsm_sem);
1676 /* set md->lmv to NULL, so the following free lustre_md will not free
1681 /* md_merge_attr() may take long, since lsm is already set, switch to
1684 down_read(&lli->lli_lsm_sem);
1686 if (!lmv_dir_striped(lli->lli_lsm_md))
1687 GOTO(unlock, rc = 0);
1689 OBD_ALLOC_PTR(attr);
1691 GOTO(unlock, rc = -ENOMEM);
1693 /* validate the lsm */
1694 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1695 ll_md_blocking_ast);
1697 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1698 md->body->mbo_nlink = attr->cat_nlink;
1699 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1700 md->body->mbo_size = attr->cat_size;
1701 if (md->body->mbo_valid & OBD_MD_FLATIME)
1702 md->body->mbo_atime = attr->cat_atime;
1703 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1704 md->body->mbo_ctime = attr->cat_ctime;
1705 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1706 md->body->mbo_mtime = attr->cat_mtime;
1712 up_read(&lli->lli_lsm_sem);
1717 void ll_clear_inode(struct inode *inode)
1719 struct ll_inode_info *lli = ll_i2info(inode);
1720 struct ll_sb_info *sbi = ll_i2sbi(inode);
1724 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1725 PFID(ll_inode2fid(inode)), inode);
1727 if (S_ISDIR(inode->i_mode)) {
1728 /* these should have been cleared in ll_file_release */
1729 LASSERT(lli->lli_opendir_key == NULL);
1730 LASSERT(lli->lli_sai == NULL);
1731 LASSERT(lli->lli_opendir_pid == 0);
1733 pcc_inode_free(inode);
1736 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1738 LASSERT(!lli->lli_open_fd_write_count);
1739 LASSERT(!lli->lli_open_fd_read_count);
1740 LASSERT(!lli->lli_open_fd_exec_count);
1742 if (lli->lli_mds_write_och)
1743 ll_md_real_close(inode, FMODE_WRITE);
1744 if (lli->lli_mds_exec_och)
1745 ll_md_real_close(inode, FMODE_EXEC);
1746 if (lli->lli_mds_read_och)
1747 ll_md_real_close(inode, FMODE_READ);
1749 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1750 OBD_FREE(lli->lli_symlink_name,
1751 strlen(lli->lli_symlink_name) + 1);
1752 lli->lli_symlink_name = NULL;
1755 ll_xattr_cache_destroy(inode);
1757 forget_all_cached_acls(inode);
1759 lli->lli_inode_magic = LLI_INODE_DEAD;
1761 if (S_ISDIR(inode->i_mode))
1762 ll_dir_clear_lsm_md(inode);
1763 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1764 LASSERT(list_empty(&lli->lli_agl_list));
1767 * XXX This has to be done before lsm is freed below, because
1768 * cl_object still uses inode lsm.
1770 cl_inode_fini(inode);
1772 llcrypt_put_encryption_info(inode);
1777 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1779 struct lustre_md md;
1780 struct inode *inode = dentry->d_inode;
1781 struct ll_sb_info *sbi = ll_i2sbi(inode);
1782 struct ptlrpc_request *request = NULL;
1786 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1787 LUSTRE_OPC_ANY, NULL);
1788 if (IS_ERR(op_data))
1789 RETURN(PTR_ERR(op_data));
1791 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1793 ptlrpc_req_finished(request);
1794 if (rc == -ENOENT) {
1796 /* Unlinked special device node? Or just a race?
1797 * Pretend we done everything. */
1798 if (!S_ISREG(inode->i_mode) &&
1799 !S_ISDIR(inode->i_mode)) {
1800 ia_valid = op_data->op_attr.ia_valid;
1801 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1802 rc = simple_setattr(dentry, &op_data->op_attr);
1803 op_data->op_attr.ia_valid = ia_valid;
1805 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1806 CERROR("md_setattr fails: rc = %d\n", rc);
1811 rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
1812 sbi->ll_md_exp, &md);
1814 ptlrpc_req_finished(request);
1818 ia_valid = op_data->op_attr.ia_valid;
1819 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1820 * cache is not cleared yet. */
1821 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1822 if (S_ISREG(inode->i_mode))
1824 rc = simple_setattr(dentry, &op_data->op_attr);
1825 if (S_ISREG(inode->i_mode))
1826 inode_unlock(inode);
1827 op_data->op_attr.ia_valid = ia_valid;
1829 rc = ll_update_inode(inode, &md);
1830 ptlrpc_req_finished(request);
1836 * Zero portion of page that is part of @inode.
1837 * This implies, if necessary:
1838 * - taking cl_lock on range corresponding to concerned page
1839 * - grabbing vm page
1840 * - associating cl_page
1841 * - proceeding to clio read
1842 * - zeroing range in page
1843 * - proceeding to cl_page flush
1844 * - releasing cl_lock
1846 * \param[in] inode inode
1847 * \param[in] index page index
1848 * \param[in] offset offset in page to start zero from
1849 * \param[in] len len to zero
1851 * \retval 0 on success
1852 * \retval negative errno on failure
1854 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
1857 struct ll_inode_info *lli = ll_i2info(inode);
1858 struct cl_object *clob = lli->lli_clob;
1860 struct lu_env *env = NULL;
1861 struct cl_io *io = NULL;
1862 struct cl_page *clpage = NULL;
1863 struct page *vmpage = NULL;
1864 unsigned from = index << PAGE_SHIFT;
1865 struct cl_lock *lock = NULL;
1866 struct cl_lock_descr *descr = NULL;
1867 struct cl_2queue *queue = NULL;
1868 struct cl_sync_io *anchor = NULL;
1869 bool holdinglock = false;
1870 bool lockedbymyself = true;
1875 env = cl_env_get(&refcheck);
1877 RETURN(PTR_ERR(env));
1879 io = vvp_env_thread_io(env);
1881 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
1885 lock = vvp_env_lock(env);
1886 descr = &lock->cll_descr;
1887 descr->cld_obj = io->ci_obj;
1888 descr->cld_start = cl_index(io->ci_obj, from);
1889 descr->cld_end = cl_index(io->ci_obj, from + PAGE_SIZE - 1);
1890 descr->cld_mode = CLM_WRITE;
1891 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
1893 /* request lock for page */
1894 rc = cl_lock_request(env, io, lock);
1895 /* -ECANCELED indicates a matching lock with a different extent
1896 * was already present, and -EEXIST indicates a matching lock
1897 * on exactly the same extent was already present.
1898 * In both cases it means we are covered.
1900 if (rc == -ECANCELED || rc == -EEXIST)
1908 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
1910 GOTO(rellock, rc = -EOPNOTSUPP);
1912 if (!PageDirty(vmpage)) {
1913 /* associate cl_page */
1914 clpage = cl_page_find(env, clob, vmpage->index,
1915 vmpage, CPT_CACHEABLE);
1917 GOTO(pagefini, rc = PTR_ERR(clpage));
1919 cl_page_assume(env, io, clpage);
1922 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
1923 !PageWriteback(vmpage)) {
1925 /* set PagePrivate2 to detect special case of empty page
1926 * in osc_brw_fini_request()
1928 SetPagePrivate2(vmpage);
1929 rc = ll_io_read_page(env, io, clpage, NULL);
1930 if (!PagePrivate2(vmpage))
1931 /* PagePrivate2 was cleared in osc_brw_fini_request()
1932 * meaning we read an empty page. In this case, in order
1933 * to avoid allocating unnecessary block in truncated
1934 * file, we must not zero and write as below. Subsequent
1935 * server-side truncate will handle things correctly.
1937 GOTO(clpfini, rc = 0);
1938 ClearPagePrivate2(vmpage);
1941 lockedbymyself = trylock_page(vmpage);
1942 cl_page_assume(env, io, clpage);
1945 /* zero range in page */
1946 zero_user(vmpage, offset, len);
1948 if (holdinglock && clpage) {
1949 /* explicitly write newly modified page */
1950 queue = &io->ci_queue;
1951 cl_2queue_init(queue);
1952 anchor = &vvp_env_info(env)->vti_anchor;
1953 cl_sync_io_init(anchor, 1);
1954 clpage->cp_sync_io = anchor;
1955 cl_2queue_add(queue, clpage);
1956 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
1958 GOTO(queuefini1, rc);
1959 rc = cl_sync_io_wait(env, anchor, 0);
1961 GOTO(queuefini2, rc);
1962 cl_page_assume(env, io, clpage);
1965 cl_2queue_discard(env, io, queue);
1967 cl_2queue_disown(env, io, queue);
1968 cl_2queue_fini(env, queue);
1973 cl_page_put(env, clpage);
1975 if (lockedbymyself) {
1976 unlock_page(vmpage);
1981 cl_lock_release(env, lock);
1983 cl_io_fini(env, io);
1986 cl_env_put(env, &refcheck);
1991 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1992 * object(s) determine the file size and mtime. Otherwise, the MDS will
1993 * keep these values until such a time that objects are allocated for it.
1994 * We do the MDS operations first, as it is checking permissions for us.
1995 * We don't to the MDS RPC if there is nothing that we want to store there,
1996 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1997 * going to do an RPC anyways.
1999 * If we are doing a truncate, we will send the mtime and ctime updates
2000 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2001 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2004 * In case of HSMimport, we only set attr on MDS.
2006 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2007 enum op_xvalid xvalid, bool hsm_import)
2009 struct inode *inode = dentry->d_inode;
2010 struct ll_inode_info *lli = ll_i2info(inode);
2011 struct md_op_data *op_data = NULL;
2012 ktime_t kstart = ktime_get();
2017 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2018 "valid %x, hsm_import %d\n",
2019 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2020 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2023 if (attr->ia_valid & ATTR_SIZE) {
2024 /* Check new size against VFS/VM file size limit and rlimit */
2025 rc = inode_newsize_ok(inode, attr->ia_size);
2029 /* The maximum Lustre file size is variable, based on the
2030 * OST maximum object size and number of stripes. This
2031 * needs another check in addition to the VFS check above. */
2032 if (attr->ia_size > ll_file_maxbytes(inode)) {
2033 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2034 PFID(&lli->lli_fid), attr->ia_size,
2035 ll_file_maxbytes(inode));
2039 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2042 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2043 if (attr->ia_valid & TIMES_SET_FLAGS) {
2044 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2045 !capable(CAP_FOWNER))
2049 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2050 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2051 (attr->ia_valid & ATTR_CTIME)) {
2052 attr->ia_ctime = current_time(inode);
2053 xvalid |= OP_XVALID_CTIME_SET;
2055 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2056 (attr->ia_valid & ATTR_ATIME)) {
2057 attr->ia_atime = current_time(inode);
2058 attr->ia_valid |= ATTR_ATIME_SET;
2060 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2061 (attr->ia_valid & ATTR_MTIME)) {
2062 attr->ia_mtime = current_time(inode);
2063 attr->ia_valid |= ATTR_MTIME_SET;
2066 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2067 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2068 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2069 ktime_get_real_seconds());
2071 if (S_ISREG(inode->i_mode))
2072 inode_unlock(inode);
2074 /* We always do an MDS RPC, even if we're only changing the size;
2075 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2077 OBD_ALLOC_PTR(op_data);
2078 if (op_data == NULL)
2079 GOTO(out, rc = -ENOMEM);
2081 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2082 /* If we are changing file size, file content is
2083 * modified, flag it.
2085 xvalid |= OP_XVALID_OWNEROVERRIDE;
2086 op_data->op_bias |= MDS_DATA_MODIFIED;
2087 ll_file_clear_flag(lli, LLIF_DATA_MODIFIED);
2090 if (attr->ia_valid & ATTR_FILE) {
2091 struct ll_file_data *fd = attr->ia_file->private_data;
2093 if (fd->fd_lease_och)
2094 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2097 op_data->op_attr = *attr;
2098 op_data->op_xvalid = xvalid;
2100 rc = ll_md_setattr(dentry, op_data);
2104 if (!S_ISREG(inode->i_mode) || hsm_import)
2107 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2108 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2109 xvalid & OP_XVALID_CTIME_SET) {
2110 bool cached = false;
2112 rc = pcc_inode_setattr(inode, attr, &cached);
2115 CERROR("%s: PCC inode "DFID" setattr failed: "
2117 ll_i2sbi(inode)->ll_fsname,
2118 PFID(&lli->lli_fid), rc);
2122 unsigned int flags = 0;
2124 /* For truncate and utimes sending attributes to OSTs,
2125 * setting mtime/atime to the past will be performed
2126 * under PW [0:EOF] extent lock (new_size:EOF for
2127 * truncate). It may seem excessive to send mtime/atime
2128 * updates to OSTs when not setting times to past, but
2129 * it is necessary due to possible time
2130 * de-synchronization between MDT inode and OST objects
2132 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode) &&
2133 attr->ia_valid & ATTR_SIZE) {
2134 xvalid |= OP_XVALID_FLAGS;
2135 flags = LUSTRE_ENCRYPT_FL;
2136 /* Call to ll_io_zero_page is not necessary if
2137 * truncating on PAGE_SIZE boundary, because
2138 * whole pages will be wiped.
2139 * In case of Direct IO, all we need is to set
2142 if (attr->ia_size & ~PAGE_MASK &&
2143 !(attr->ia_valid & ATTR_FILE &&
2144 attr->ia_file->f_flags & O_DIRECT)) {
2146 attr->ia_size & (PAGE_SIZE - 1);
2148 rc = ll_io_zero_page(inode,
2149 attr->ia_size >> PAGE_SHIFT,
2150 offset, PAGE_SIZE - offset);
2155 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2159 /* If the file was restored, it needs to set dirty flag.
2161 * We've already sent MDS_DATA_MODIFIED flag in
2162 * ll_md_setattr() for truncate. However, the MDT refuses to
2163 * set the HS_DIRTY flag on released files, so we have to set
2164 * it again if the file has been restored. Please check how
2165 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2167 * Please notice that if the file is not released, the previous
2168 * MDS_DATA_MODIFIED has taken effect and usually
2169 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2170 * This way we can save an RPC for common open + trunc
2172 if (ll_file_test_and_clear_flag(lli, LLIF_DATA_MODIFIED)) {
2173 struct hsm_state_set hss = {
2174 .hss_valid = HSS_SETMASK,
2175 .hss_setmask = HS_DIRTY,
2179 rc2 = ll_hsm_state_set(inode, &hss);
2180 /* truncate and write can happen at the same time, so that
2181 * the file can be set modified even though the file is not
2182 * restored from released state, and ll_hsm_state_set() is
2183 * not applicable for the file, and rc2 < 0 is normal in this
2186 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2187 PFID(ll_inode2fid(inode)), rc2);
2192 if (op_data != NULL)
2193 ll_finish_md_op_data(op_data);
2195 if (S_ISREG(inode->i_mode)) {
2197 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2198 inode_dio_wait(inode);
2199 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2200 * flag. ll_update_inode (called from ll_md_setattr), clears
2201 * inode flags, so there is a gap where S_NOSEC is not set.
2202 * This can cause a writer to take the i_mutex unnecessarily,
2203 * but this is safe to do and should be rare. */
2204 inode_has_no_xattr(inode);
2208 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2209 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2210 ktime_us_delta(ktime_get(), kstart));
2215 int ll_setattr(struct dentry *de, struct iattr *attr)
2217 int mode = de->d_inode->i_mode;
2218 enum op_xvalid xvalid = 0;
2221 rc = llcrypt_prepare_setattr(de, attr);
2225 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2226 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2227 xvalid |= OP_XVALID_OWNEROVERRIDE;
2229 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2230 (ATTR_SIZE|ATTR_MODE)) &&
2231 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2232 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2233 !(attr->ia_mode & S_ISGID))))
2234 attr->ia_valid |= ATTR_FORCE;
2236 if ((attr->ia_valid & ATTR_MODE) &&
2238 !(attr->ia_mode & S_ISUID) &&
2239 !(attr->ia_valid & ATTR_KILL_SUID))
2240 attr->ia_valid |= ATTR_KILL_SUID;
2242 if ((attr->ia_valid & ATTR_MODE) &&
2243 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2244 !(attr->ia_mode & S_ISGID) &&
2245 !(attr->ia_valid & ATTR_KILL_SGID))
2246 attr->ia_valid |= ATTR_KILL_SGID;
2248 return ll_setattr_raw(de, attr, xvalid, false);
2251 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2254 struct obd_statfs obd_osfs = { 0 };
2259 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2261 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
2262 flags |= OBD_STATFS_NODELAY;
2264 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2268 osfs->os_type = LL_SUPER_MAGIC;
2270 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2271 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2273 if (osfs->os_state & OS_STATFS_SUM)
2276 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2277 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2280 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2281 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2284 osfs->os_bsize = obd_osfs.os_bsize;
2285 osfs->os_blocks = obd_osfs.os_blocks;
2286 osfs->os_bfree = obd_osfs.os_bfree;
2287 osfs->os_bavail = obd_osfs.os_bavail;
2289 /* If we have _some_ OSTs, but don't have as many free objects on the
2290 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2291 * to compensate, so that the "inodes in use" number is correct.
2292 * This should be kept in sync with lod_statfs() behaviour.
2294 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2295 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2297 osfs->os_ffree = obd_osfs.os_ffree;
2304 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2306 struct if_quotactl qctl = {
2307 .qc_cmd = LUSTRE_Q_GETQUOTA,
2308 .qc_type = PRJQUOTA,
2309 .qc_valid = QC_GENERAL,
2311 u64 limit, curblock;
2314 qctl.qc_id = ll_i2info(inode)->lli_projid;
2315 ret = quotactl_ioctl(ll_i2sbi(inode), &qctl);
2317 /* ignore errors if project ID does not have
2318 * a quota limit or feature unsupported.
2320 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2325 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2326 qctl.qc_dqblk.dqb_bsoftlimit :
2327 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2328 if (limit && sfs->f_blocks > limit) {
2329 curblock = (qctl.qc_dqblk.dqb_curspace +
2330 sfs->f_bsize - 1) / sfs->f_bsize;
2331 sfs->f_blocks = limit;
2332 sfs->f_bfree = sfs->f_bavail =
2333 (sfs->f_blocks > curblock) ?
2334 (sfs->f_blocks - curblock) : 0;
2337 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2338 qctl.qc_dqblk.dqb_isoftlimit :
2339 qctl.qc_dqblk.dqb_ihardlimit;
2340 if (limit && sfs->f_files > limit) {
2341 sfs->f_files = limit;
2342 sfs->f_ffree = (sfs->f_files >
2343 qctl.qc_dqblk.dqb_curinodes) ?
2344 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2350 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2352 struct super_block *sb = de->d_sb;
2353 struct obd_statfs osfs;
2354 __u64 fsid = huge_encode_dev(sb->s_dev);
2355 ktime_t kstart = ktime_get();
2358 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2360 /* Some amount of caching on the client is allowed */
2361 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2365 statfs_unpack(sfs, &osfs);
2367 /* We need to downshift for all 32-bit kernels, because we can't
2368 * tell if the kernel is being called via sys_statfs64() or not.
2369 * Stop before overflowing f_bsize - in which case it is better
2370 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2371 if (sizeof(long) < 8) {
2372 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2375 osfs.os_blocks >>= 1;
2376 osfs.os_bfree >>= 1;
2377 osfs.os_bavail >>= 1;
2381 sfs->f_blocks = osfs.os_blocks;
2382 sfs->f_bfree = osfs.os_bfree;
2383 sfs->f_bavail = osfs.os_bavail;
2384 sfs->f_fsid.val[0] = (__u32)fsid;
2385 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2386 if (ll_i2info(de->d_inode)->lli_projid)
2387 return ll_statfs_project(de->d_inode, sfs);
2389 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2390 ktime_us_delta(ktime_get(), kstart));
2395 void ll_inode_size_lock(struct inode *inode)
2397 struct ll_inode_info *lli;
2399 LASSERT(!S_ISDIR(inode->i_mode));
2401 lli = ll_i2info(inode);
2402 mutex_lock(&lli->lli_size_mutex);
2405 void ll_inode_size_unlock(struct inode *inode)
2407 struct ll_inode_info *lli;
2409 lli = ll_i2info(inode);
2410 mutex_unlock(&lli->lli_size_mutex);
2413 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2415 /* do not clear encryption flag */
2416 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2417 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2418 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2419 ll_file_set_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
2421 ll_file_clear_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
2424 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2426 struct ll_inode_info *lli = ll_i2info(inode);
2427 struct mdt_body *body = md->body;
2428 struct ll_sb_info *sbi = ll_i2sbi(inode);
2431 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2432 rc = cl_file_inode_init(inode, md);
2437 if (S_ISDIR(inode->i_mode)) {
2438 rc = ll_update_lsm_md(inode, md);
2443 if (body->mbo_valid & OBD_MD_FLACL)
2444 lli_replace_acl(lli, md);
2446 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1,
2447 sbi->ll_flags & LL_SBI_32BIT_API);
2448 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2450 if (body->mbo_valid & OBD_MD_FLATIME) {
2451 if (body->mbo_atime > inode->i_atime.tv_sec)
2452 inode->i_atime.tv_sec = body->mbo_atime;
2453 lli->lli_atime = body->mbo_atime;
2456 if (body->mbo_valid & OBD_MD_FLMTIME) {
2457 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2459 "setting ino %lu mtime from %lld to %llu\n",
2460 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2462 inode->i_mtime.tv_sec = body->mbo_mtime;
2464 lli->lli_mtime = body->mbo_mtime;
2467 if (body->mbo_valid & OBD_MD_FLCTIME) {
2468 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2469 inode->i_ctime.tv_sec = body->mbo_ctime;
2470 lli->lli_ctime = body->mbo_ctime;
2473 if (body->mbo_valid & OBD_MD_FLBTIME)
2474 lli->lli_btime = body->mbo_btime;
2476 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2477 if (body->mbo_valid & OBD_MD_FLFLAGS)
2478 ll_update_inode_flags(inode, body->mbo_flags);
2479 if (body->mbo_valid & OBD_MD_FLMODE)
2480 inode->i_mode = (inode->i_mode & S_IFMT) |
2481 (body->mbo_mode & ~S_IFMT);
2483 if (body->mbo_valid & OBD_MD_FLTYPE)
2484 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2485 (body->mbo_mode & S_IFMT);
2487 LASSERT(inode->i_mode != 0);
2488 if (body->mbo_valid & OBD_MD_FLUID)
2489 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2490 if (body->mbo_valid & OBD_MD_FLGID)
2491 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2492 if (body->mbo_valid & OBD_MD_FLPROJID)
2493 lli->lli_projid = body->mbo_projid;
2494 if (body->mbo_valid & OBD_MD_FLNLINK)
2495 set_nlink(inode, body->mbo_nlink);
2496 if (body->mbo_valid & OBD_MD_FLRDEV)
2497 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2499 if (body->mbo_valid & OBD_MD_FLID) {
2500 /* FID shouldn't be changed! */
2501 if (fid_is_sane(&lli->lli_fid)) {
2502 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2503 "Trying to change FID "DFID
2504 " to the "DFID", inode "DFID"(%p)\n",
2505 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2506 PFID(ll_inode2fid(inode)), inode);
2508 lli->lli_fid = body->mbo_fid1;
2512 LASSERT(fid_seq(&lli->lli_fid) != 0);
2514 lli->lli_attr_valid = body->mbo_valid;
2515 if (body->mbo_valid & OBD_MD_FLSIZE) {
2516 i_size_write(inode, body->mbo_size);
2518 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2519 PFID(ll_inode2fid(inode)),
2520 (unsigned long long)body->mbo_size);
2522 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2523 inode->i_blocks = body->mbo_blocks;
2525 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2526 lli->lli_lazysize = body->mbo_size;
2527 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2528 lli->lli_lazyblocks = body->mbo_blocks;
2531 if (body->mbo_valid & OBD_MD_TSTATE) {
2532 /* Set LLIF_FILE_RESTORING if restore ongoing and
2533 * clear it when done to ensure to start again
2534 * glimpsing updated attrs
2536 if (body->mbo_t_state & MS_RESTORE)
2537 ll_file_set_flag(lli, LLIF_FILE_RESTORING);
2539 ll_file_clear_flag(lli, LLIF_FILE_RESTORING);
2545 int ll_read_inode2(struct inode *inode, void *opaque)
2547 struct lustre_md *md = opaque;
2548 struct ll_inode_info *lli = ll_i2info(inode);
2552 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2553 PFID(&lli->lli_fid), inode);
2555 /* Core attributes from the MDS first. This is a new inode, and
2556 * the VFS doesn't zero times in the core inode so we have to do
2557 * it ourselves. They will be overwritten by either MDS or OST
2558 * attributes - we just need to make sure they aren't newer.
2560 inode->i_mtime.tv_sec = 0;
2561 inode->i_atime.tv_sec = 0;
2562 inode->i_ctime.tv_sec = 0;
2564 rc = ll_update_inode(inode, md);
2568 /* OIDEBUG(inode); */
2570 #ifdef HAVE_BACKING_DEV_INFO
2571 /* initializing backing dev info. */
2572 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2574 if (S_ISREG(inode->i_mode)) {
2575 struct ll_sb_info *sbi = ll_i2sbi(inode);
2576 inode->i_op = &ll_file_inode_operations;
2577 inode->i_fop = sbi->ll_fop;
2578 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2580 } else if (S_ISDIR(inode->i_mode)) {
2581 inode->i_op = &ll_dir_inode_operations;
2582 inode->i_fop = &ll_dir_operations;
2584 } else if (S_ISLNK(inode->i_mode)) {
2585 inode->i_op = &ll_fast_symlink_inode_operations;
2588 inode->i_op = &ll_special_inode_operations;
2590 init_special_inode(inode, inode->i_mode,
2599 void ll_delete_inode(struct inode *inode)
2601 struct ll_inode_info *lli = ll_i2info(inode);
2602 struct address_space *mapping = &inode->i_data;
2603 unsigned long nrpages;
2604 unsigned long flags;
2608 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2609 /* It is last chance to write out dirty pages,
2610 * otherwise we may lose data while umount.
2612 * If i_nlink is 0 then just discard data. This is safe because
2613 * local inode gets i_nlink 0 from server only for the last
2614 * unlink, so that file is not opened somewhere else
2616 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2617 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2619 truncate_inode_pages_final(mapping);
2621 /* Workaround for LU-118: Note nrpages may not be totally updated when
2622 * truncate_inode_pages() returns, as there can be a page in the process
2623 * of deletion (inside __delete_from_page_cache()) in the specified
2624 * range. Thus mapping->nrpages can be non-zero when this function
2625 * returns even after truncation of the whole mapping. Only do this if
2626 * npages isn't already zero.
2628 nrpages = mapping->nrpages;
2630 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2631 nrpages = mapping->nrpages;
2632 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2633 } /* Workaround end */
2635 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, "
2636 "see https://jira.whamcloud.com/browse/LU-118\n",
2637 ll_i2sbi(inode)->ll_fsname,
2638 PFID(ll_inode2fid(inode)), inode, nrpages);
2640 ll_clear_inode(inode);
2646 int ll_iocontrol(struct inode *inode, struct file *file,
2647 unsigned int cmd, unsigned long arg)
2649 struct ll_sb_info *sbi = ll_i2sbi(inode);
2650 struct ptlrpc_request *req = NULL;
2655 case FS_IOC_GETFLAGS: {
2656 struct mdt_body *body;
2657 struct md_op_data *op_data;
2659 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2660 0, 0, LUSTRE_OPC_ANY,
2662 if (IS_ERR(op_data))
2663 RETURN(PTR_ERR(op_data));
2665 op_data->op_valid = OBD_MD_FLFLAGS;
2666 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2667 ll_finish_md_op_data(op_data);
2669 CERROR("%s: failure inode "DFID": rc = %d\n",
2670 sbi->ll_md_exp->exp_obd->obd_name,
2671 PFID(ll_inode2fid(inode)), rc);
2675 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2677 flags = body->mbo_flags;
2679 ptlrpc_req_finished(req);
2681 RETURN(put_user(flags, (int __user *)arg));
2683 case FS_IOC_SETFLAGS: {
2685 struct md_op_data *op_data;
2686 struct cl_object *obj;
2687 struct fsxattr fa = { 0 };
2689 if (get_user(flags, (int __user *)arg))
2692 fa.fsx_projid = ll_i2info(inode)->lli_projid;
2693 if (flags & LUSTRE_PROJINHERIT_FL)
2694 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
2696 rc = ll_ioctl_check_project(inode, &fa);
2700 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
2701 LUSTRE_OPC_ANY, NULL);
2702 if (IS_ERR(op_data))
2703 RETURN(PTR_ERR(op_data));
2705 op_data->op_attr_flags = flags;
2706 op_data->op_xvalid |= OP_XVALID_FLAGS;
2707 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
2708 ll_finish_md_op_data(op_data);
2709 ptlrpc_req_finished(req);
2713 ll_update_inode_flags(inode, flags);
2715 obj = ll_i2info(inode)->lli_clob;
2719 OBD_ALLOC_PTR(attr);
2723 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
2735 int ll_flush_ctx(struct inode *inode)
2737 struct ll_sb_info *sbi = ll_i2sbi(inode);
2739 CDEBUG(D_SEC, "flush context for user %d\n",
2740 from_kuid(&init_user_ns, current_uid()));
2742 obd_set_info_async(NULL, sbi->ll_md_exp,
2743 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2745 obd_set_info_async(NULL, sbi->ll_dt_exp,
2746 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2751 /* umount -f client means force down, don't save state */
2752 void ll_umount_begin(struct super_block *sb)
2754 struct ll_sb_info *sbi = ll_s2sbi(sb);
2755 struct obd_device *obd;
2756 struct obd_ioctl_data *ioc_data;
2760 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2761 sb->s_count, atomic_read(&sb->s_active));
2763 obd = class_exp2obd(sbi->ll_md_exp);
2765 CERROR("Invalid MDC connection handle %#llx\n",
2766 sbi->ll_md_exp->exp_handle.h_cookie);
2772 obd = class_exp2obd(sbi->ll_dt_exp);
2774 CERROR("Invalid LOV connection handle %#llx\n",
2775 sbi->ll_dt_exp->exp_handle.h_cookie);
2781 OBD_ALLOC_PTR(ioc_data);
2783 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2784 sizeof *ioc_data, ioc_data, NULL);
2786 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2787 sizeof *ioc_data, ioc_data, NULL);
2789 OBD_FREE_PTR(ioc_data);
2792 /* Really, we'd like to wait until there are no requests outstanding,
2793 * and then continue. For now, we just periodically checking for vfs
2794 * to decrement mnt_cnt and hope to finish it within 10sec.
2798 !may_umount(sbi->ll_mnt.mnt)) {
2806 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2808 struct ll_sb_info *sbi = ll_s2sbi(sb);
2809 char *profilenm = get_profile_name(sb);
2813 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
2814 read_only = *flags & MS_RDONLY;
2815 err = obd_set_info_async(NULL, sbi->ll_md_exp,
2816 sizeof(KEY_READ_ONLY),
2817 KEY_READ_ONLY, sizeof(read_only),
2820 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2821 profilenm, read_only ?
2822 "read-only" : "read-write", err);
2827 sb->s_flags |= SB_RDONLY;
2829 sb->s_flags &= ~SB_RDONLY;
2831 if (sbi->ll_flags & LL_SBI_VERBOSE)
2832 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
2833 read_only ? "read-only" : "read-write");
2839 * Cleanup the open handle that is cached on MDT-side.
2841 * For open case, the client side open handling thread may hit error
2842 * after the MDT grant the open. Under such case, the client should
2843 * send close RPC to the MDT as cleanup; otherwise, the open handle
2844 * on the MDT will be leaked there until the client umount or evicted.
2846 * In further, if someone unlinked the file, because the open handle
2847 * holds the reference on such file/object, then it will block the
2848 * subsequent threads that want to locate such object via FID.
2850 * \param[in] sb super block for this file-system
2851 * \param[in] open_req pointer to the original open request
2853 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
2855 struct mdt_body *body;
2856 struct md_op_data *op_data;
2857 struct ptlrpc_request *close_req = NULL;
2858 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
2861 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
2862 OBD_ALLOC_PTR(op_data);
2863 if (op_data == NULL) {
2864 CWARN("%s: cannot allocate op_data to release open handle for "
2865 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
2870 op_data->op_fid1 = body->mbo_fid1;
2871 op_data->op_open_handle = body->mbo_open_handle;
2872 op_data->op_mod_time = ktime_get_real_seconds();
2873 md_close(exp, op_data, NULL, &close_req);
2874 ptlrpc_req_finished(close_req);
2875 ll_finish_md_op_data(op_data);
2880 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
2881 struct super_block *sb, struct lookup_intent *it)
2883 struct ll_sb_info *sbi = NULL;
2884 struct lustre_md md = { NULL };
2885 bool default_lmv_deleted = false;
2890 LASSERT(*inode || sb);
2891 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2892 rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
2893 sbi->ll_md_exp, &md);
2898 * clear default_lmv only if intent_getattr reply doesn't contain it.
2899 * but it needs to be done after iget, check this early because
2900 * ll_update_lsm_md() may change md.
2902 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
2903 S_ISDIR(md.body->mbo_mode) && !md.default_lmv)
2904 default_lmv_deleted = true;
2907 rc = ll_update_inode(*inode, &md);
2911 LASSERT(sb != NULL);
2914 * At this point server returns to client's same fid as client
2915 * generated for creating. So using ->fid1 is okay here.
2917 if (!fid_is_sane(&md.body->mbo_fid1)) {
2918 CERROR("%s: Fid is insane "DFID"\n",
2920 PFID(&md.body->mbo_fid1));
2921 GOTO(out, rc = -EINVAL);
2924 *inode = ll_iget(sb, cl_fid_build_ino(&md.body->mbo_fid1,
2925 sbi->ll_flags & LL_SBI_32BIT_API),
2927 if (IS_ERR(*inode)) {
2929 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
2931 CERROR("new_inode -fatal: rc %d\n", rc);
2936 /* Handling piggyback layout lock.
2937 * Layout lock can be piggybacked by getattr and open request.
2938 * The lsm can be applied to inode only if it comes with a layout lock
2939 * otherwise correct layout may be overwritten, for example:
2940 * 1. proc1: mdt returns a lsm but not granting layout
2941 * 2. layout was changed by another client
2942 * 3. proc2: refresh layout and layout lock granted
2943 * 4. proc1: to apply a stale layout */
2944 if (it != NULL && it->it_lock_mode != 0) {
2945 struct lustre_handle lockh;
2946 struct ldlm_lock *lock;
2948 lockh.cookie = it->it_lock_handle;
2949 lock = ldlm_handle2lock(&lockh);
2950 LASSERT(lock != NULL);
2951 if (ldlm_has_layout(lock)) {
2952 struct cl_object_conf conf;
2954 memset(&conf, 0, sizeof(conf));
2955 conf.coc_opc = OBJECT_CONF_SET;
2956 conf.coc_inode = *inode;
2957 conf.coc_lock = lock;
2958 conf.u.coc_layout = md.layout;
2959 (void)ll_layout_conf(*inode, &conf);
2961 LDLM_LOCK_PUT(lock);
2964 if (default_lmv_deleted)
2965 ll_update_default_lsm_md(*inode, &md);
2967 /* we may want to apply some policy for foreign file/dir */
2968 if (ll_sbi_has_foreign_symlink(sbi)) {
2969 rc = ll_manage_foreign(*inode, &md);
2977 /* cleanup will be done if necessary */
2978 md_free_lustre_md(sbi->ll_md_exp, &md);
2980 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
2981 ll_intent_drop_lock(it);
2982 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, req);
2988 int ll_obd_statfs(struct inode *inode, void __user *arg)
2990 struct ll_sb_info *sbi = NULL;
2991 struct obd_export *exp;
2992 struct obd_ioctl_data *data = NULL;
2997 sbi = ll_i2sbi(inode);
2999 GOTO(out_statfs, rc = -EINVAL);
3001 rc = obd_ioctl_getdata(&data, &len, arg);
3003 GOTO(out_statfs, rc);
3005 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3006 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3007 GOTO(out_statfs, rc = -EINVAL);
3009 if (data->ioc_inllen1 != sizeof(__u32) ||
3010 data->ioc_inllen2 != sizeof(__u32) ||
3011 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3012 data->ioc_plen2 != sizeof(struct obd_uuid))
3013 GOTO(out_statfs, rc = -EINVAL);
3015 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3016 if (type & LL_STATFS_LMV)
3017 exp = sbi->ll_md_exp;
3018 else if (type & LL_STATFS_LOV)
3019 exp = sbi->ll_dt_exp;
3021 GOTO(out_statfs, rc = -ENODEV);
3023 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3025 GOTO(out_statfs, rc);
3027 OBD_FREE_LARGE(data, len);
3032 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3033 * be called early to avoid deadlock.
3035 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3037 if (op_data->op_mea2_sem) {
3038 up_read_non_owner(op_data->op_mea2_sem);
3039 op_data->op_mea2_sem = NULL;
3042 if (op_data->op_mea1_sem) {
3043 up_read_non_owner(op_data->op_mea1_sem);
3044 op_data->op_mea1_sem = NULL;
3048 /* this function prepares md_op_data hint for passing it down to MD stack. */
3049 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3050 struct inode *i1, struct inode *i2,
3051 const char *name, size_t namelen,
3052 __u32 mode, enum md_op_code opc,
3055 LASSERT(i1 != NULL);
3058 /* Do not reuse namelen for something else. */
3060 return ERR_PTR(-EINVAL);
3062 if (namelen > ll_i2sbi(i1)->ll_namelen)
3063 return ERR_PTR(-ENAMETOOLONG);
3065 /* "/" is not valid name, but it's allowed */
3066 if (!lu_name_is_valid_2(name, namelen) &&
3067 strncmp("/", name, namelen) != 0)
3068 return ERR_PTR(-EINVAL);
3071 if (op_data == NULL)
3072 OBD_ALLOC_PTR(op_data);
3074 if (op_data == NULL)
3075 return ERR_PTR(-ENOMEM);
3077 ll_i2gids(op_data->op_suppgids, i1, i2);
3078 op_data->op_fid1 = *ll_inode2fid(i1);
3079 op_data->op_code = opc;
3081 if (S_ISDIR(i1->i_mode)) {
3082 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3083 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3084 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3085 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3089 op_data->op_fid2 = *ll_inode2fid(i2);
3090 if (S_ISDIR(i2->i_mode)) {
3092 /* i2 is typically a child of i1, and MUST be
3093 * further from the root to avoid deadlocks.
3095 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3096 op_data->op_mea2_sem =
3097 &ll_i2info(i2)->lli_lsm_sem;
3099 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3102 fid_zero(&op_data->op_fid2);
3105 if (ll_i2sbi(i1)->ll_flags & LL_SBI_64BIT_HASH)
3106 op_data->op_cli_flags |= CLI_HASH64;
3108 if (ll_need_32bit_api(ll_i2sbi(i1)))
3109 op_data->op_cli_flags |= CLI_API32;
3111 op_data->op_name = name;
3112 op_data->op_namelen = namelen;
3113 op_data->op_mode = mode;
3114 op_data->op_mod_time = ktime_get_real_seconds();
3115 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3116 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3117 op_data->op_cap = cfs_curproc_cap_pack();
3118 op_data->op_mds = 0;
3119 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3120 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3121 op_data->op_bias |= MDS_CREATE_VOLATILE;
3123 op_data->op_data = data;
3128 void ll_finish_md_op_data(struct md_op_data *op_data)
3130 ll_unlock_md_op_lsm(op_data);
3131 security_release_secctx(op_data->op_file_secctx,
3132 op_data->op_file_secctx_size);
3133 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3134 OBD_FREE_PTR(op_data);
3137 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3139 struct ll_sb_info *sbi;
3141 LASSERT(seq && dentry);
3142 sbi = ll_s2sbi(dentry->d_sb);
3144 if (sbi->ll_flags & LL_SBI_NOLCK)
3145 seq_puts(seq, ",nolock");
3147 /* "flock" is the default since 2.13, but it wasn't for many years,
3148 * so it is still useful to print this to show it is enabled.
3149 * Start to print "noflock" so it is now clear when flock is disabled.
3151 if (sbi->ll_flags & LL_SBI_FLOCK)
3152 seq_puts(seq, ",flock");
3153 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
3154 seq_puts(seq, ",localflock");
3156 seq_puts(seq, ",noflock");
3158 if (sbi->ll_flags & LL_SBI_USER_XATTR)
3159 seq_puts(seq, ",user_xattr");
3161 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
3162 seq_puts(seq, ",lazystatfs");
3164 if (sbi->ll_flags & LL_SBI_USER_FID2PATH)
3165 seq_puts(seq, ",user_fid2path");
3167 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
3168 seq_puts(seq, ",always_ping");
3170 if (ll_sbi_has_test_dummy_encryption(sbi))
3171 seq_puts(seq, ",test_dummy_encryption");
3173 if (ll_sbi_has_encrypt(sbi))
3174 seq_puts(seq, ",encrypt");
3176 seq_puts(seq, ",noencrypt");
3178 if (sbi->ll_flags & LL_SBI_FOREIGN_SYMLINK) {
3179 seq_puts(seq, ",foreign_symlink=");
3180 seq_puts(seq, sbi->ll_foreign_symlink_prefix);
3187 * Get obd name by cmd, and copy out to user space
3189 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
3191 struct ll_sb_info *sbi = ll_i2sbi(inode);
3192 struct obd_device *obd;
3195 if (cmd == OBD_IOC_GETDTNAME)
3196 obd = class_exp2obd(sbi->ll_dt_exp);
3197 else if (cmd == OBD_IOC_GETMDNAME)
3198 obd = class_exp2obd(sbi->ll_md_exp);
3205 if (copy_to_user((void __user *)arg, obd->obd_name,
3206 strlen(obd->obd_name) + 1))
3212 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3219 p.mnt = current->fs->root.mnt;
3221 path = d_path(&p, buf, bufsize);
3226 void ll_dirty_page_discard_warn(struct page *page, int ioret)
3228 char *buf, *path = NULL;
3229 struct dentry *dentry = NULL;
3230 struct inode *inode = page->mapping->host;
3232 /* this can be called inside spin lock so use GFP_ATOMIC. */
3233 buf = (char *)__get_free_page(GFP_ATOMIC);
3235 dentry = d_find_alias(page->mapping->host);
3237 path = ll_d_path(dentry, buf, PAGE_SIZE);
3240 /* The below message is checked in recovery-small.sh test_24b */
3242 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3243 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3244 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
3245 PFID(ll_inode2fid(inode)),
3246 (path && !IS_ERR(path)) ? path : "", ioret);
3252 free_page((unsigned long)buf);
3255 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3256 struct lov_user_md **kbuf)
3258 struct lov_user_md lum;
3262 if (copy_from_user(&lum, md, sizeof(lum)))
3265 lum_size = ll_lov_user_md_size(&lum);
3269 OBD_ALLOC_LARGE(*kbuf, lum_size);
3273 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3274 OBD_FREE_LARGE(*kbuf, lum_size);
3282 * Compute llite root squash state after a change of root squash
3283 * configuration setting or add/remove of a lnet nid
3285 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3287 struct root_squash_info *squash = &sbi->ll_squash;
3290 struct lnet_process_id id;
3292 /* Update norootsquash flag */
3293 spin_lock(&squash->rsi_lock);
3294 if (list_empty(&squash->rsi_nosquash_nids))
3295 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
3297 /* Do not apply root squash as soon as one of our NIDs is
3298 * in the nosquash_nids list */
3301 while (LNetGetId(i++, &id) != -ENOENT) {
3302 if (id.nid == LNET_NID_LO_0)
3304 if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) {
3310 sbi->ll_flags |= LL_SBI_NOROOTSQUASH;
3312 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
3314 spin_unlock(&squash->rsi_lock);
3318 * Parse linkea content to extract information about a given hardlink
3320 * \param[in] ldata - Initialized linkea data
3321 * \param[in] linkno - Link identifier
3322 * \param[out] parent_fid - The entry's parent FID
3323 * \param[out] ln - Entry name destination buffer
3325 * \retval 0 on success
3326 * \retval Appropriate negative error code on failure
3328 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3329 struct lu_fid *parent_fid, struct lu_name *ln)
3335 rc = linkea_init_with_rec(ldata);
3339 if (linkno >= ldata->ld_leh->leh_reccount)
3340 /* beyond last link */
3343 linkea_first_entry(ldata);
3344 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3345 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3350 linkea_next_entry(ldata);
3360 * Get parent FID and name of an identified link. Operation is performed for
3361 * a given link number, letting the caller iterate over linkno to list one or
3362 * all links of an entry.
3364 * \param[in] file - File descriptor against which to perform the operation
3365 * \param[in,out] arg - User-filled structure containing the linkno to operate
3366 * on and the available size. It is eventually filled with
3367 * the requested information or left untouched on error
3369 * \retval - 0 on success
3370 * \retval - Appropriate negative error code on failure
3372 int ll_getparent(struct file *file, struct getparent __user *arg)
3374 struct inode *inode = file_inode(file);
3375 struct linkea_data *ldata;
3376 struct lu_buf buf = LU_BUF_NULL;
3378 struct lu_fid parent_fid;
3385 if (!capable(CAP_DAC_READ_SEARCH) &&
3386 !(ll_i2sbi(inode)->ll_flags & LL_SBI_USER_FID2PATH))
3389 if (get_user(name_size, &arg->gp_name_size))
3392 if (get_user(linkno, &arg->gp_linkno))
3395 if (name_size > PATH_MAX)
3398 OBD_ALLOC(ldata, sizeof(*ldata));
3402 rc = linkea_data_new(ldata, &buf);
3404 GOTO(ldata_free, rc);
3406 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3407 buf.lb_len, OBD_MD_FLXATTR);
3411 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3415 if (ln.ln_namelen >= name_size)
3416 GOTO(lb_free, rc = -EOVERFLOW);
3418 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3419 GOTO(lb_free, rc = -EFAULT);
3421 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3422 GOTO(lb_free, rc = -EFAULT);
3424 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3425 GOTO(lb_free, rc = -EFAULT);
3430 OBD_FREE(ldata, sizeof(*ldata));