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/
31 * lustre/llite/llite_lib.c
33 * Lustre Light Super operations
36 #define DEBUG_SUBSYSTEM S_LLITE
38 #include <linux/cpu.h>
39 #include <linux/module.h>
40 #include <linux/random.h>
41 #include <linux/statfs.h>
42 #include <linux/time.h>
43 #include <linux/file.h>
44 #include <linux/types.h>
45 #include <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/fs_struct.h>
53 #ifndef HAVE_CPUS_READ_LOCK
54 #include <libcfs/linux/linux-cpu.h>
56 #include <libcfs/linux/linux-misc.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(struct lustre_sb_info *lsi)
91 struct ll_sb_info *sbi = NULL;
93 unsigned long lru_page_max;
101 RETURN(ERR_PTR(-ENOMEM));
103 rc = pcc_super_init(&sbi->ll_pcc_super);
107 spin_lock_init(&sbi->ll_lock);
108 mutex_init(&sbi->ll_lco.lco_lock);
109 spin_lock_init(&sbi->ll_pp_extent_lock);
110 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_secctx_name = NULL;
152 sbi->ll_secctx_name_size = 0;
154 sbi->ll_ra_info.ra_max_pages =
155 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
156 sbi->ll_ra_info.ra_max_pages_per_file =
157 min(sbi->ll_ra_info.ra_max_pages / 4,
158 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
159 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
160 sbi->ll_ra_info.ra_max_pages_per_file;
161 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
162 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
163 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
165 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
166 #ifdef ENABLE_CHECKSUM
167 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
170 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
173 #ifdef HAVE_LRU_RESIZE_SUPPORT
174 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
176 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
178 /* metadata statahead is enabled by default */
179 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
180 sbi->ll_sa_batch_max = LL_SA_BATCH_DEF;
181 sbi->ll_sa_max = LL_SA_RPC_DEF;
182 atomic_set(&sbi->ll_sa_total, 0);
183 atomic_set(&sbi->ll_sa_wrong, 0);
184 atomic_set(&sbi->ll_sa_running, 0);
185 atomic_set(&sbi->ll_agl_total, 0);
186 atomic_set(&sbi->ll_sa_hit_total, 0);
187 atomic_set(&sbi->ll_sa_miss_total, 0);
188 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
189 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
190 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
191 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
192 ll_sbi_set_encrypt(sbi, true);
193 ll_sbi_set_name_encrypt(sbi, true);
196 sbi->ll_squash.rsi_uid = 0;
197 sbi->ll_squash.rsi_gid = 0;
198 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
199 spin_lock_init(&sbi->ll_squash.rsi_lock);
201 /* Per-filesystem file heat */
202 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
203 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
205 /* Per-fs open heat level before requesting open lock */
206 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
207 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
208 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
211 if (sbi->ll_foreign_symlink_prefix)
212 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
214 cl_cache_decref(sbi->ll_cache);
215 sbi->ll_cache = NULL;
217 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
219 pcc_super_fini(&sbi->ll_pcc_super);
225 static void ll_free_sbi(struct super_block *sb)
227 struct ll_sb_info *sbi = ll_s2sbi(sb);
231 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
232 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
233 if (sbi->ll_ra_info.ll_readahead_wq)
234 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
235 if (sbi->ll_cache != NULL) {
236 cl_cache_decref(sbi->ll_cache);
237 sbi->ll_cache = NULL;
239 if (sbi->ll_foreign_symlink_prefix) {
240 OBD_FREE(sbi->ll_foreign_symlink_prefix,
241 sbi->ll_foreign_symlink_prefix_size);
242 sbi->ll_foreign_symlink_prefix = NULL;
244 if (sbi->ll_foreign_symlink_upcall) {
245 OBD_FREE(sbi->ll_foreign_symlink_upcall,
246 strlen(sbi->ll_foreign_symlink_upcall) +
248 sbi->ll_foreign_symlink_upcall = NULL;
250 if (sbi->ll_foreign_symlink_upcall_items) {
252 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
253 struct ll_foreign_symlink_upcall_item *items =
254 sbi->ll_foreign_symlink_upcall_items;
256 for (i = 0 ; i < nb_items; i++)
257 if (items[i].type == STRING_TYPE)
258 OBD_FREE(items[i].string,
261 OBD_FREE_LARGE(items, nb_items *
262 sizeof(struct ll_foreign_symlink_upcall_item));
263 sbi->ll_foreign_symlink_upcall_items = NULL;
265 if (sbi->ll_secctx_name)
266 ll_secctx_name_free(sbi);
268 ll_free_rw_stats_info(sbi);
269 pcc_super_fini(&sbi->ll_pcc_super);
270 OBD_FREE(sbi, sizeof(*sbi));
275 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
277 struct inode *root = NULL;
278 struct ll_sb_info *sbi = ll_s2sbi(sb);
279 struct obd_statfs *osfs = NULL;
280 struct ptlrpc_request *request = NULL;
281 struct obd_connect_data *data = NULL;
282 struct obd_uuid *uuid;
283 struct md_op_data *op_data;
284 struct lustre_md lmd;
286 int size, err, checksum;
292 sbi->ll_md_obd = class_name2obd(md);
293 if (!sbi->ll_md_obd) {
294 CERROR("MD %s: not setup or attached\n", md);
308 /* pass client page size via ocd_grant_blkbits, the server should report
309 * back its backend blocksize for grant calculation purpose */
310 data->ocd_grant_blkbits = PAGE_SHIFT;
312 /* indicate MDT features supported by this client */
313 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
314 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
315 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
316 OBD_CONNECT_SRVLOCK |
317 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
318 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
319 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
320 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
321 OBD_CONNECT_64BITHASH |
322 OBD_CONNECT_EINPROGRESS |
323 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
324 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
325 OBD_CONNECT_MAX_EASIZE |
326 OBD_CONNECT_FLOCK_DEAD |
327 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
328 OBD_CONNECT_OPEN_BY_FID |
329 OBD_CONNECT_DIR_STRIPE |
330 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
331 OBD_CONNECT_SUBTREE |
332 OBD_CONNECT_MULTIMODRPCS |
333 OBD_CONNECT_GRANT_PARAM |
334 OBD_CONNECT_GRANT_SHRINK |
335 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
337 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
338 OBD_CONNECT2_SUM_STATFS |
339 OBD_CONNECT2_OVERSTRIPING |
341 OBD_CONNECT2_LOCK_CONVERT |
342 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
343 OBD_CONNECT2_INC_XID |
345 OBD_CONNECT2_ASYNC_DISCARD |
347 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
348 OBD_CONNECT2_GETATTR_PFID |
349 OBD_CONNECT2_DOM_LVB |
350 OBD_CONNECT2_REP_MBITS |
351 OBD_CONNECT2_ATOMIC_OPEN_LOCK |
352 OBD_CONNECT2_BATCH_RPC;
354 #ifdef HAVE_LRU_RESIZE_SUPPORT
355 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
356 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
358 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
360 data->ocd_cksum_types = obd_cksum_types_supported_client();
362 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
363 /* flag mdc connection as lightweight, only used for test
364 * purpose, use with care */
365 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
367 data->ocd_ibits_known = MDS_INODELOCK_FULL;
368 data->ocd_version = LUSTRE_VERSION_CODE;
370 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
371 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
374 /* Setting this indicates we correctly support S_NOSEC (See kernel
375 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
377 sb->s_flags |= SB_NOSEC;
379 sbi->ll_fop = ll_select_file_operations(sbi);
381 /* always ping even if server suppress_pings */
382 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
383 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
385 obd_connect_set_secctx(data);
386 if (ll_sbi_has_encrypt(sbi)) {
387 obd_connect_set_enc_fid2path(data);
388 obd_connect_set_name_enc(data);
389 obd_connect_set_enc(data);
392 #if defined(CONFIG_SECURITY)
393 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
396 data->ocd_brw_size = MD_MAX_BRW_SIZE;
399 if (sb->s_flags & SB_RDONLY)
400 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
401 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
402 &sbi->ll_sb_uuid, data, sbi->ll_cache);
404 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
405 "recovery, of which this client is not a "
406 "part. Please wait for recovery to complete,"
407 " abort, or time out.\n", md);
410 CERROR("cannot connect to %s: rc = %d\n", md, err);
414 sbi->ll_md_exp->exp_connect_data = *data;
416 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
417 LUSTRE_SEQ_METADATA);
419 CERROR("%s: Can't init metadata layer FID infrastructure, "
420 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
424 /* For mount, we only need fs info from MDT0, and also in DNE, it
425 * can make sure the client can be mounted as long as MDT0 is
427 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
428 ktime_get_seconds() - sbi->ll_statfs_max_age,
429 OBD_STATFS_FOR_MDT0);
430 if (err == -EROFS && !(sb->s_flags & SB_RDONLY)) {
431 /* We got -EROFS from the server, maybe it is imposing
432 * read-only mount. So just retry like this.
434 cfs_tty_write_msg("Forcing read-only mount.\n\r");
435 CERROR("%s: mount failed with %d, forcing read-only mount.\n",
436 sbi->ll_md_exp->exp_obd->obd_name, err);
437 sb->s_flags |= SB_RDONLY;
438 obd_fid_fini(sbi->ll_md_exp->exp_obd);
439 obd_disconnect(sbi->ll_md_exp);
440 GOTO(retry_connect, err);
442 GOTO(out_md_fid, err);
445 /* This needs to be after statfs to ensure connect has finished.
446 * Note that "data" does NOT contain the valid connect reply.
447 * If connecting to a 1.8 server there will be no LMV device, so
448 * we can access the MDC export directly and exp_connect_flags will
449 * be non-zero, but if accessing an upgraded 2.1 server it will
450 * have the correct flags filled in.
451 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
452 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
453 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
454 valid != CLIENT_CONNECT_MDT_REQD) {
457 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
458 obd_connect_flags2str(buf, PAGE_SIZE,
459 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
460 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
461 "feature(s) needed for correct operation "
462 "of this client (%s). Please upgrade "
463 "server or downgrade client.\n",
464 sbi->ll_md_exp->exp_obd->obd_name, buf);
465 OBD_FREE(buf, PAGE_SIZE);
466 GOTO(out_md_fid, err = -EPROTO);
469 size = sizeof(*data);
470 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
471 KEY_CONN_DATA, &size, data);
473 CERROR("%s: Get connect data failed: rc = %d\n",
474 sbi->ll_md_exp->exp_obd->obd_name, err);
475 GOTO(out_md_fid, err);
478 LASSERT(osfs->os_bsize);
479 sb->s_blocksize = osfs->os_bsize;
480 sb->s_blocksize_bits = log2(osfs->os_bsize);
481 sb->s_magic = LL_SUPER_MAGIC;
482 sb->s_maxbytes = MAX_LFS_FILESIZE;
483 sbi->ll_inode_cache_enabled = 1;
484 sbi->ll_namelen = osfs->os_namelen;
485 sbi->ll_mnt.mnt = current->fs->root.mnt;
486 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
488 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
489 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
490 LCONSOLE_INFO("Disabling user_xattr feature because "
491 "it is not supported on the server\n");
492 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
495 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
497 sb->s_flags |= SB_POSIXACL;
499 set_bit(LL_SBI_ACL, sbi->ll_flags);
501 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
503 sb->s_flags &= ~SB_POSIXACL;
505 clear_bit(LL_SBI_ACL, sbi->ll_flags);
508 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
509 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
511 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
512 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
514 if (obd_connect_has_secctx(data))
515 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
517 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
518 if (ll_sb_has_test_dummy_encryption(sb))
519 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
521 sbi->ll_md_exp->exp_obd->obd_name);
522 ll_sbi_set_encrypt(sbi, false);
525 if (ll_sbi_has_name_encrypt(sbi) && !obd_connect_has_name_enc(data)) {
526 struct lustre_sb_info *lsi = s2lsi(sb);
528 if (ll_sb_has_test_dummy_encryption(sb))
529 LCONSOLE_WARN("%s: server %s does not support name encryption, not using it.\n",
531 sbi->ll_md_exp->exp_obd->obd_name);
532 #ifdef CONFIG_LL_ENCRYPTION
533 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
535 lsi->lsi_flags &= ~LSI_FILENAME_ENC_B64_OLD_CLI;
536 ll_sbi_set_name_encrypt(sbi, false);
539 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
540 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
541 LCONSOLE_INFO("%s: disabling xattr cache due to "
542 "unknown maximum xattr size.\n", dt);
543 } else if (!sbi->ll_xattr_cache_set) {
544 /* If xattr_cache is already set (no matter 0 or 1)
545 * during processing llog, it won't be enabled here. */
546 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
547 sbi->ll_xattr_cache_enabled = 1;
551 sbi->ll_dt_obd = class_name2obd(dt);
552 if (!sbi->ll_dt_obd) {
553 CERROR("DT %s: not setup or attached\n", dt);
554 GOTO(out_md_fid, err = -ENODEV);
557 /* pass client page size via ocd_grant_blkbits, the server should report
558 * back its backend blocksize for grant calculation purpose */
559 data->ocd_grant_blkbits = PAGE_SHIFT;
561 /* indicate OST features supported by this client */
562 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
563 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
564 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
565 OBD_CONNECT_SRVLOCK |
566 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
567 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
568 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
569 OBD_CONNECT_EINPROGRESS |
570 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
571 OBD_CONNECT_LAYOUTLOCK |
572 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
573 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
574 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
575 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
576 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
577 OBD_CONNECT2_REP_MBITS;
579 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
580 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
582 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
583 * disabled by default, because it can still be enabled on the
584 * fly via /sys. As a consequence, we still need to come to an
585 * agreement on the supported algorithms at connect time
587 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
589 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
590 data->ocd_cksum_types = OBD_CKSUM_ADLER;
592 data->ocd_cksum_types = obd_cksum_types_supported_client();
594 #ifdef HAVE_LRU_RESIZE_SUPPORT
595 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
597 /* always ping even if server suppress_pings */
598 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
599 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
601 if (ll_sbi_has_encrypt(sbi))
602 obd_connect_set_enc(data);
604 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
605 "ocd_grant: %d\n", data->ocd_connect_flags,
606 data->ocd_version, data->ocd_grant);
608 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
609 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
611 data->ocd_brw_size = DT_MAX_BRW_SIZE;
613 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
614 &sbi->ll_sb_uuid, data, sbi->ll_cache);
616 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
617 "recovery, of which this client is not a "
618 "part. Please wait for recovery to "
619 "complete, abort, or time out.\n", dt);
622 CERROR("%s: Cannot connect to %s: rc = %d\n",
623 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
627 if (ll_sbi_has_encrypt(sbi) &&
628 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
629 if (ll_sb_has_test_dummy_encryption(sb))
630 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
632 ll_sbi_set_encrypt(sbi, false);
633 } else if (ll_sb_has_test_dummy_encryption(sb)) {
634 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
637 sbi->ll_dt_exp->exp_connect_data = *data;
639 /* Don't change value if it was specified in the config log */
640 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
641 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
642 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
643 (data->ocd_brw_size >> PAGE_SHIFT));
644 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
645 sbi->ll_ra_info.ra_max_pages_per_file)
646 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
647 sbi->ll_ra_info.ra_max_pages_per_file;
650 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
651 LUSTRE_SEQ_METADATA);
653 CERROR("%s: Can't init data layer FID infrastructure, "
654 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
658 mutex_lock(&sbi->ll_lco.lco_lock);
659 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
660 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
661 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
662 mutex_unlock(&sbi->ll_lco.lco_lock);
664 fid_zero(&sbi->ll_root_fid);
665 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
668 CERROR("cannot mds_connect: rc = %d\n", err);
669 GOTO(out_lock_cn_cb, err);
671 if (!fid_is_sane(&sbi->ll_root_fid)) {
672 CERROR("%s: Invalid root fid "DFID" during mount\n",
673 sbi->ll_md_exp->exp_obd->obd_name,
674 PFID(&sbi->ll_root_fid));
675 GOTO(out_lock_cn_cb, err = -EINVAL);
677 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
679 sb->s_op = &lustre_super_operations;
680 sb->s_xattr = ll_xattr_handlers;
681 #if THREAD_SIZE >= 8192 /*b=17630*/
682 sb->s_export_op = &lustre_export_operations;
684 #ifdef HAVE_LUSTRE_CRYPTO
685 llcrypt_set_ops(sb, &lustre_cryptops);
689 * XXX: move this to after cbd setup? */
690 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
692 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
693 valid |= OBD_MD_FLACL;
695 OBD_ALLOC_PTR(op_data);
697 GOTO(out_lock_cn_cb, err = -ENOMEM);
699 op_data->op_fid1 = sbi->ll_root_fid;
700 op_data->op_mode = 0;
701 op_data->op_valid = valid;
703 err = md_getattr(sbi->ll_md_exp, op_data, &request);
705 /* We need enc ctx info, so reset it in op_data to
706 * prevent it from being freed.
708 encctx = op_data->op_file_encctx;
709 encctxlen = op_data->op_file_encctx_size;
710 op_data->op_file_encctx = NULL;
711 op_data->op_file_encctx_size = 0;
712 OBD_FREE_PTR(op_data);
714 CERROR("%s: md_getattr failed for root: rc = %d\n",
715 sbi->ll_md_exp->exp_obd->obd_name, err);
716 GOTO(out_lock_cn_cb, err);
719 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
720 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
722 CERROR("failed to understand root inode md: rc = %d\n", err);
723 ptlrpc_req_finished(request);
724 GOTO(out_lock_cn_cb, err);
727 LASSERT(fid_is_sane(&sbi->ll_root_fid));
728 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
729 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
730 md_free_lustre_md(sbi->ll_md_exp, &lmd);
734 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
736 CERROR("%s: bad ll_iget() for root: rc = %d\n",
737 sbi->ll_fsname, err);
738 ptlrpc_req_finished(request);
742 err = ll_secctx_name_store(root);
743 if (err < 0 && ll_security_xattr_wanted(root))
744 CWARN("%s: file security contextes not supported: rc = %d\n",
745 sbi->ll_fsname, err);
750 "server returned encryption ctx for root inode "DFID"\n",
751 PFID(&sbi->ll_root_fid));
752 err = ll_set_encflags(root, encctx, encctxlen, true);
754 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
756 PFID(&sbi->ll_root_fid), err);
758 ptlrpc_req_finished(request);
760 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
761 if (sbi->ll_checksum_set) {
762 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
763 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
764 sizeof(checksum), &checksum, NULL);
766 CERROR("%s: Set checksum failed: rc = %d\n",
767 sbi->ll_dt_exp->exp_obd->obd_name, err);
773 sb->s_root = d_make_root(root);
774 if (sb->s_root == NULL) {
776 CERROR("%s: can't make root dentry: rc = %d\n",
777 sbi->ll_fsname, err);
781 sbi->ll_sdev_orig = sb->s_dev;
783 /* We set sb->s_dev equal on all lustre clients in order to support
784 * NFS export clustering. NFSD requires that the FSID be the same
786 /* s_dev is also used in lt_compare() to compare two fs, but that is
787 * only a node-local comparison. */
788 uuid = obd_get_uuid(sbi->ll_md_exp);
790 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
797 if (sbi->ll_dt_obd) {
798 err = sysfs_create_link(&sbi->ll_kset.kobj,
799 &sbi->ll_dt_obd->obd_kset.kobj,
800 sbi->ll_dt_obd->obd_type->typ_name);
802 CERROR("%s: could not register %s in llite: rc = %d\n",
803 dt, sbi->ll_fsname, err);
808 if (sbi->ll_md_obd) {
809 err = sysfs_create_link(&sbi->ll_kset.kobj,
810 &sbi->ll_md_obd->obd_kset.kobj,
811 sbi->ll_md_obd->obd_type->typ_name);
813 CERROR("%s: could not register %s in llite: rc = %d\n",
814 md, sbi->ll_fsname, err);
823 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
825 obd_disconnect(sbi->ll_dt_exp);
826 sbi->ll_dt_exp = NULL;
827 sbi->ll_dt_obd = NULL;
829 obd_fid_fini(sbi->ll_md_exp->exp_obd);
831 obd_disconnect(sbi->ll_md_exp);
832 sbi->ll_md_exp = NULL;
833 sbi->ll_md_obd = NULL;
842 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
846 size = sizeof(*lmmsize);
847 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
848 KEY_MAX_EASIZE, &size, lmmsize);
850 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
851 sbi->ll_dt_exp->exp_obd->obd_name, rc);
855 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
858 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
859 KEY_MAX_EASIZE, &size, lmmsize);
861 CERROR("Get max mdsize error rc %d\n", rc);
863 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
869 * Get the value of the default_easize parameter.
871 * \see client_obd::cl_default_mds_easize
873 * \param[in] sbi superblock info for this filesystem
874 * \param[out] lmmsize pointer to storage location for value
876 * \retval 0 on success
877 * \retval negative negated errno on failure
879 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
884 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
885 KEY_DEFAULT_EASIZE, &size, lmmsize);
887 CERROR("Get default mdsize error rc %d\n", rc);
893 * Set the default_easize parameter to the given value.
895 * \see client_obd::cl_default_mds_easize
897 * \param[in] sbi superblock info for this filesystem
898 * \param[in] lmmsize the size to set
900 * \retval 0 on success
901 * \retval negative negated errno on failure
903 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
907 if (lmmsize < sizeof(struct lov_mds_md) ||
908 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
911 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
912 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
913 sizeof(int), &lmmsize, NULL);
918 static void client_common_put_super(struct super_block *sb)
920 struct ll_sb_info *sbi = ll_s2sbi(sb);
925 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
926 obd_disconnect(sbi->ll_dt_exp);
927 sbi->ll_dt_exp = NULL;
929 ll_debugfs_unregister_super(sb);
931 obd_fid_fini(sbi->ll_md_exp->exp_obd);
932 obd_disconnect(sbi->ll_md_exp);
933 sbi->ll_md_exp = NULL;
938 void ll_kill_super(struct super_block *sb)
940 struct ll_sb_info *sbi;
944 if (!(sb->s_flags & SB_ACTIVE))
948 /* we need restore s_dev from changed for clustred NFS before put_super
949 * because new kernels have cached s_dev and change sb->s_dev in
950 * put_super not affected real removing devices */
952 sb->s_dev = sbi->ll_sdev_orig;
954 /* wait running statahead threads to quit */
955 while (atomic_read(&sbi->ll_sa_running) > 0)
956 schedule_timeout_uninterruptible(
957 cfs_time_seconds(1) >> 3);
963 /* Since we use this table for ll_sbi_flags_seq_show make
964 * sure what you want displayed for a specific token that
965 * is listed more than once below be listed first. For
966 * example we want "checksum" displayed, not "nochecksum"
969 static const match_table_t ll_sbi_flags_name = {
970 {LL_SBI_NOLCK, "nolock"},
971 {LL_SBI_CHECKSUM, "checksum"},
972 {LL_SBI_CHECKSUM, "nochecksum"},
973 {LL_SBI_LOCALFLOCK, "localflock"},
974 {LL_SBI_FLOCK, "flock"},
975 {LL_SBI_FLOCK, "noflock"},
976 {LL_SBI_USER_XATTR, "user_xattr"},
977 {LL_SBI_USER_XATTR, "nouser_xattr"},
978 {LL_SBI_LRU_RESIZE, "lruresize"},
979 {LL_SBI_LRU_RESIZE, "nolruresize"},
980 {LL_SBI_LAZYSTATFS, "lazystatfs"},
981 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
982 {LL_SBI_32BIT_API, "32bitapi"},
983 {LL_SBI_USER_FID2PATH, "user_fid2path"},
984 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
985 {LL_SBI_VERBOSE, "verbose"},
986 {LL_SBI_VERBOSE, "noverbose"},
987 {LL_SBI_ALWAYS_PING, "always_ping"},
988 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
989 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
990 {LL_SBI_ENCRYPT, "encrypt"},
991 {LL_SBI_ENCRYPT, "noencrypt"},
992 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
993 {LL_SBI_NUM_MOUNT_OPT, NULL},
996 {LL_SBI_AGL_ENABLED, "agl"},
997 {LL_SBI_64BIT_HASH, "64bit_hash"},
998 {LL_SBI_LAYOUT_LOCK, "layout"},
999 {LL_SBI_XATTR_CACHE, "xattr_cache"},
1000 {LL_SBI_NOROOTSQUASH, "norootsquash"},
1001 {LL_SBI_FAST_READ, "fast_read"},
1002 {LL_SBI_FILE_SECCTX, "file_secctx"},
1003 {LL_SBI_TINY_WRITE, "tiny_write"},
1004 {LL_SBI_FILE_HEAT, "file_heat"},
1005 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
1006 {LL_SBI_ENCRYPT_NAME, "name_encrypt"},
1009 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
1011 struct super_block *sb = m->private;
1014 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
1017 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
1020 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
1021 if (ll_sbi_flags_name[j].token == i &&
1022 ll_sbi_flags_name[j].pattern) {
1023 seq_printf(m, "%s ",
1024 ll_sbi_flags_name[j].pattern);
1029 seq_puts(m, "\b\n");
1033 /* non-client-specific mount options are parsed in lmd_parse */
1034 static int ll_options(char *options, struct super_block *sb)
1036 struct ll_sb_info *sbi = ll_s2sbi(sb);
1037 char *s2, *s1, *opts;
1044 /* Don't stomp on lmd_opts */
1045 opts = kstrdup(options, GFP_KERNEL);
1051 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1053 while ((s1 = strsep(&opts, ",")) != NULL) {
1054 substring_t args[MAX_OPT_ARGS];
1055 bool turn_off = false;
1061 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1063 if (strncmp(s1, "no", 2) == 0)
1067 * Initialize args struct so we know whether arg was
1068 * found; some options take optional arguments.
1071 args[0].from = NULL;
1072 token = match_token(s1, ll_sbi_flags_name, args);
1073 if (token == LL_SBI_NUM_MOUNT_OPT) {
1074 if (match_wildcard("context", s1) ||
1075 match_wildcard("fscontext", s1) ||
1076 match_wildcard("defcontext", s1) ||
1077 match_wildcard("rootcontext",s1))
1080 LCONSOLE_ERROR_MSG(0x152,
1081 "Unknown option '%s', won't mount.\n",
1088 case LL_SBI_32BIT_API:
1089 case LL_SBI_64BIT_HASH:
1090 case LL_SBI_ALWAYS_PING:
1091 set_bit(token, sbi->ll_flags);
1095 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1097 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1099 set_bit(token, sbi->ll_flags);
1102 case LL_SBI_LOCALFLOCK:
1103 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1104 set_bit(token, sbi->ll_flags);
1107 case LL_SBI_CHECKSUM:
1108 sbi->ll_checksum_set = 1;
1110 case LL_SBI_USER_XATTR:
1111 case LL_SBI_USER_FID2PATH:
1112 case LL_SBI_LRU_RESIZE:
1113 case LL_SBI_LAZYSTATFS:
1114 case LL_SBI_VERBOSE:
1116 clear_bit(token, sbi->ll_flags);
1118 set_bit(token, sbi->ll_flags);
1120 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1121 #ifdef HAVE_LUSTRE_CRYPTO
1122 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1123 set_bit(token, sbi->ll_flags);
1125 struct lustre_sb_info *lsi = s2lsi(sb);
1127 err = llcrypt_set_test_dummy_encryption(sb,
1128 #ifdef HAVE_FSCRYPT_SET_TEST_DUMMY_ENC_CHAR_ARG
1133 &lsi->lsi_dummy_enc_policy);
1139 "Can't change test_dummy_encryption");
1140 else if (err == -EINVAL)
1142 "Value of option \"%s\" unrecognized",
1146 "Error processing option \"%s\" [%d]",
1151 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1155 case LL_SBI_ENCRYPT:
1156 #ifdef HAVE_LUSTRE_CRYPTO
1158 clear_bit(token, sbi->ll_flags);
1160 set_bit(token, sbi->ll_flags);
1162 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1165 case LL_SBI_FOREIGN_SYMLINK:
1166 /* non-default prefix provided ? */
1171 /* path must be absolute */
1172 if (args->from[0] != '/') {
1173 LCONSOLE_ERROR_MSG(0x152,
1174 "foreign prefix '%s' must be an absolute path\n",
1179 old_len = sbi->ll_foreign_symlink_prefix_size;
1180 old = sbi->ll_foreign_symlink_prefix;
1181 /* alloc for path length and '\0' */
1182 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1183 if (!sbi->ll_foreign_symlink_prefix) {
1184 /* restore previous */
1185 sbi->ll_foreign_symlink_prefix = old;
1186 sbi->ll_foreign_symlink_prefix_size =
1190 sbi->ll_foreign_symlink_prefix_size =
1191 args->to - args->from + 1;
1192 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1193 sbi->ll_foreign_symlink_prefix_size,
1196 OBD_FREE(old, old_len);
1198 /* enable foreign symlink support */
1199 set_bit(token, sbi->ll_flags);
1201 LCONSOLE_ERROR_MSG(0x152,
1202 "invalid %s option\n", s1);
1213 void ll_lli_init(struct ll_inode_info *lli)
1215 lli->lli_inode_magic = LLI_INODE_MAGIC;
1217 rwlock_init(&lli->lli_lock);
1218 lli->lli_posix_acl = NULL;
1219 /* Do not set lli_fid, it has been initialized already. */
1220 fid_zero(&lli->lli_pfid);
1221 lli->lli_mds_read_och = NULL;
1222 lli->lli_mds_write_och = NULL;
1223 lli->lli_mds_exec_och = NULL;
1224 lli->lli_open_fd_read_count = 0;
1225 lli->lli_open_fd_write_count = 0;
1226 lli->lli_open_fd_exec_count = 0;
1227 mutex_init(&lli->lli_och_mutex);
1228 spin_lock_init(&lli->lli_agl_lock);
1229 spin_lock_init(&lli->lli_layout_lock);
1230 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1231 lli->lli_clob = NULL;
1233 init_rwsem(&lli->lli_xattrs_list_rwsem);
1234 mutex_init(&lli->lli_xattrs_enq_lock);
1236 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1237 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1238 lli->lli_opendir_key = NULL;
1239 lli->lli_sai = NULL;
1240 spin_lock_init(&lli->lli_sa_lock);
1241 lli->lli_opendir_pid = 0;
1242 lli->lli_sa_enabled = 0;
1243 init_rwsem(&lli->lli_lsm_sem);
1245 mutex_init(&lli->lli_size_mutex);
1246 mutex_init(&lli->lli_setattr_mutex);
1247 lli->lli_symlink_name = NULL;
1248 ll_trunc_sem_init(&lli->lli_trunc_sem);
1249 range_lock_tree_init(&lli->lli_write_tree);
1250 init_rwsem(&lli->lli_glimpse_sem);
1251 lli->lli_glimpse_time = ktime_set(0, 0);
1252 INIT_LIST_HEAD(&lli->lli_agl_list);
1253 lli->lli_agl_index = 0;
1254 lli->lli_async_rc = 0;
1255 spin_lock_init(&lli->lli_heat_lock);
1256 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1257 lli->lli_heat_flags = 0;
1258 mutex_init(&lli->lli_pcc_lock);
1259 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1260 lli->lli_pcc_inode = NULL;
1261 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1262 lli->lli_pcc_generation = 0;
1263 mutex_init(&lli->lli_group_mutex);
1264 lli->lli_group_users = 0;
1265 lli->lli_group_gid = 0;
1266 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1267 lli->lli_uid = (__u32) -1;
1268 lli->lli_gid = (__u32) -1;
1270 mutex_init(&lli->lli_layout_mutex);
1271 /* ll_cl_context initialize */
1272 INIT_LIST_HEAD(&lli->lli_lccs);
1273 seqlock_init(&lli->lli_page_inv_lock);
1276 #define MAX_STRING_SIZE 128
1278 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1279 #ifndef HAVE_BDI_CAP_MAP_COPY
1280 # define BDI_CAP_MAP_COPY 0
1283 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1285 struct lustre_sb_info *lsi = s2lsi(sb);
1286 char buf[MAX_STRING_SIZE];
1290 err = bdi_init(&lsi->lsi_bdi);
1294 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1295 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1296 lsi->lsi_bdi.name = "lustre";
1297 va_start(args, fmt);
1298 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1300 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1303 sb->s_bdi = &lsi->lsi_bdi;
1307 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1309 int ll_fill_super(struct super_block *sb)
1311 struct lustre_profile *lprof = NULL;
1312 struct lustre_sb_info *lsi = s2lsi(sb);
1313 struct ll_sb_info *sbi = NULL;
1314 char *dt = NULL, *md = NULL;
1315 char *profilenm = get_profile_name(sb);
1316 struct config_llog_instance *cfg;
1317 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1318 const int instlen = LUSTRE_MAXINSTANCE + 2;
1319 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1320 char name[MAX_STRING_SIZE];
1329 /* for ASLR, to map between cfg_instance and hashed ptr */
1330 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1331 profilenm, cfg_instance, sb);
1333 OBD_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1337 GOTO(out_free_cfg, err = -ENOMEM);
1339 /* client additional sb info */
1340 lsi->lsi_llsbi = sbi = ll_init_sbi(lsi);
1342 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1344 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1346 GOTO(out_free_cfg, err);
1348 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1349 #ifdef CONFIG_LL_ENCRYPTION
1350 if (ll_sb_has_test_dummy_encryption(sb))
1351 /* enable filename encryption by default for dummy enc mode */
1352 lsi->lsi_flags |= LSI_FILENAME_ENC;
1354 /* filename encryption is disabled by default */
1355 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1358 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1359 sb->s_d_op = &ll_d_ops;
1362 generate_random_uuid(uuid.b);
1363 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1365 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1368 len = strlen(profilenm);
1369 ptr = strrchr(profilenm, '-');
1370 if (ptr && (strcmp(ptr, "-client") == 0))
1373 if (len > LUSTRE_MAXFSNAME) {
1374 if (unlikely(len >= MAX_STRING_SIZE))
1375 len = MAX_STRING_SIZE - 1;
1376 strncpy(name, profilenm, len);
1378 err = -ENAMETOOLONG;
1379 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1380 name, LUSTRE_MAXFSNAME, err);
1381 GOTO(out_free_cfg, err);
1383 strncpy(sbi->ll_fsname, profilenm, len);
1384 sbi->ll_fsname[len] = '\0';
1387 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1388 profilenm, cfg_instance);
1390 err = super_setup_bdi_name(sb, "%s", name);
1392 GOTO(out_free_cfg, err);
1394 /* disable kernel readahead */
1395 sb->s_bdi->ra_pages = 0;
1396 #ifdef HAVE_BDI_IO_PAGES
1397 sb->s_bdi->io_pages = 0;
1400 /* Call ll_debugfs_register_super() before lustre_process_log()
1401 * so that "llite.*.*" params can be processed correctly.
1403 err = ll_debugfs_register_super(sb, name);
1405 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1406 sbi->ll_fsname, err);
1410 /* The cfg_instance is a value unique to this super, in case some
1411 * joker tries to mount the same fs at two mount points.
1413 cfg->cfg_instance = cfg_instance;
1414 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1415 cfg->cfg_callback = class_config_llog_handler;
1416 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1417 /* set up client obds */
1418 err = lustre_process_log(sb, profilenm, cfg);
1420 GOTO(out_debugfs, err);
1422 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1423 lprof = class_get_profile(profilenm);
1424 if (lprof == NULL) {
1425 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1426 " read from the MGS. Does that filesystem "
1427 "exist?\n", profilenm);
1428 GOTO(out_debugfs, err = -EINVAL);
1430 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1431 lprof->lp_md, lprof->lp_dt);
1433 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1434 OBD_ALLOC(dt, dt_len);
1436 GOTO(out_profile, err = -ENOMEM);
1437 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1439 md_len = strlen(lprof->lp_md) + instlen + 2;
1440 OBD_ALLOC(md, md_len);
1442 GOTO(out_free_dt, err = -ENOMEM);
1443 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1445 /* connections, registrations, sb setup */
1446 err = client_common_fill_super(sb, md, dt);
1448 GOTO(out_free_md, err);
1450 sbi->ll_client_common_fill_super_succeeded = 1;
1454 OBD_FREE(md, md_len);
1457 OBD_FREE(dt, dt_len);
1460 class_put_profile(lprof);
1463 ll_debugfs_unregister_super(sb);
1470 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1471 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1472 sb->s_flags & SB_RDONLY ? " read-only" : "");
1474 } /* ll_fill_super */
1476 void ll_put_super(struct super_block *sb)
1478 struct config_llog_instance cfg, params_cfg;
1479 struct obd_device *obd;
1480 struct lustre_sb_info *lsi = s2lsi(sb);
1481 struct ll_sb_info *sbi = ll_s2sbi(sb);
1482 char *profilenm = get_profile_name(sb);
1483 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1485 int next, force = 1, rc = 0;
1489 GOTO(out_no_sbi, 0);
1491 /* Should replace instance_id with something better for ASLR */
1492 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1493 profilenm, cfg_instance, sb);
1495 cfg.cfg_instance = cfg_instance;
1496 lustre_end_log(sb, profilenm, &cfg);
1498 params_cfg.cfg_instance = cfg_instance;
1499 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1501 if (sbi->ll_md_exp) {
1502 obd = class_exp2obd(sbi->ll_md_exp);
1504 force = obd->obd_force;
1507 /* Wait for unstable pages to be committed to stable storage */
1509 rc = l_wait_event_abortable(
1510 sbi->ll_cache->ccc_unstable_waitq,
1511 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1514 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1515 if (force == 0 && rc != -ERESTARTSYS)
1516 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1518 /* We need to set force before the lov_disconnect in
1519 * lustre_common_put_super, since l_d cleans up osc's as well.
1523 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1525 obd->obd_force = force;
1529 if (sbi->ll_client_common_fill_super_succeeded) {
1530 /* Only if client_common_fill_super succeeded */
1531 client_common_put_super(sb);
1534 /* imitate failed cleanup */
1535 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1539 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1540 class_manual_cleanup(obd);
1543 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1544 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1547 class_del_profile(profilenm);
1549 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1550 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1551 bdi_destroy(&lsi->lsi_bdi);
1552 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1556 llcrypt_free_dummy_policy(&lsi->lsi_dummy_enc_policy);
1558 lsi->lsi_llsbi = NULL;
1560 lustre_common_put_super(sb);
1562 cl_env_cache_purge(~0);
1565 } /* client_put_super */
1567 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1569 struct inode *inode = NULL;
1571 /* NOTE: we depend on atomic igrab() -bzzz */
1572 lock_res_and_lock(lock);
1573 if (lock->l_resource->lr_lvb_inode) {
1574 struct ll_inode_info * lli;
1575 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1576 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1577 inode = igrab(lock->l_resource->lr_lvb_inode);
1579 inode = lock->l_resource->lr_lvb_inode;
1580 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1581 D_WARNING, lock, "lr_lvb_inode %p is "
1582 "bogus: magic %08x",
1583 lock->l_resource->lr_lvb_inode,
1584 lli->lli_inode_magic);
1588 unlock_res_and_lock(lock);
1592 void ll_dir_clear_lsm_md(struct inode *inode)
1594 struct ll_inode_info *lli = ll_i2info(inode);
1596 LASSERT(S_ISDIR(inode->i_mode));
1598 if (lli->lli_lsm_md) {
1599 lmv_free_memmd(lli->lli_lsm_md);
1600 lli->lli_lsm_md = NULL;
1603 if (lli->lli_default_lsm_md) {
1604 lmv_free_memmd(lli->lli_default_lsm_md);
1605 lli->lli_default_lsm_md = NULL;
1609 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1610 const struct lu_fid *fid,
1611 struct lustre_md *md)
1613 struct ll_sb_info *sbi = ll_s2sbi(sb);
1614 struct ll_inode_info *lli;
1615 struct mdt_body *body = md->body;
1616 struct inode *inode;
1622 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1623 inode = iget_locked(sb, ino);
1624 if (inode == NULL) {
1625 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1626 sbi->ll_fsname, PFID(fid));
1627 RETURN(ERR_PTR(-ENOENT));
1630 lli = ll_i2info(inode);
1631 if (inode->i_state & I_NEW) {
1632 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1633 (body->mbo_mode & S_IFMT);
1634 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1637 inode->i_mtime.tv_sec = 0;
1638 inode->i_atime.tv_sec = 0;
1639 inode->i_ctime.tv_sec = 0;
1642 #ifdef HAVE_BACKING_DEV_INFO
1643 /* initializing backing dev info. */
1644 inode->i_mapping->backing_dev_info =
1645 &s2lsi(inode->i_sb)->lsi_bdi;
1647 inode->i_op = &ll_dir_inode_operations;
1648 inode->i_fop = &ll_dir_operations;
1649 lli->lli_fid = *fid;
1652 /* master object FID */
1653 lli->lli_pfid = body->mbo_fid1;
1654 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1655 lli, PFID(fid), PFID(&lli->lli_pfid));
1656 unlock_new_inode(inode);
1658 /* in directory restripe/auto-split, a directory will be
1659 * transformed to a stripe if it's plain, set its pfid here,
1660 * otherwise ll_lock_cancel_bits() can't find the master inode.
1662 lli->lli_pfid = body->mbo_fid1;
1668 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1671 struct lmv_stripe_md *lsm = md->lmv;
1672 struct ll_inode_info *lli = ll_i2info(inode);
1675 LASSERT(lsm != NULL);
1677 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1678 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1679 lsm_md_dump(D_INODE, lsm);
1681 if (!lmv_dir_striped(lsm))
1684 /* XXX sigh, this lsm_root initialization should be in
1685 * LMV layer, but it needs ll_iget right now, so we
1686 * put this here right now. */
1687 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1688 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1689 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1691 if (!fid_is_sane(fid))
1694 /* Unfortunately ll_iget will call ll_update_inode,
1695 * where the initialization of slave inode is slightly
1696 * different, so it reset lsm_md to NULL to avoid
1697 * initializing lsm for slave inode. */
1698 lsm->lsm_md_oinfo[i].lmo_root =
1699 ll_iget_anon_dir(inode->i_sb, fid, md);
1700 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1701 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1703 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1705 iput(lsm->lsm_md_oinfo[i].lmo_root);
1706 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1712 lli->lli_lsm_md = lsm;
1717 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1719 struct ll_inode_info *lli = ll_i2info(inode);
1723 if (!md->default_lmv) {
1724 /* clear default lsm */
1725 if (lli->lli_default_lsm_md) {
1726 down_write(&lli->lli_lsm_sem);
1727 if (lli->lli_default_lsm_md) {
1728 lmv_free_memmd(lli->lli_default_lsm_md);
1729 lli->lli_default_lsm_md = NULL;
1731 lli->lli_inherit_depth = 0;
1732 up_write(&lli->lli_lsm_sem);
1737 if (lli->lli_default_lsm_md) {
1738 /* do nonthing if default lsm isn't changed */
1739 down_read(&lli->lli_lsm_sem);
1740 if (lli->lli_default_lsm_md &&
1741 lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1742 up_read(&lli->lli_lsm_sem);
1745 up_read(&lli->lli_lsm_sem);
1748 down_write(&lli->lli_lsm_sem);
1749 if (lli->lli_default_lsm_md)
1750 lmv_free_memmd(lli->lli_default_lsm_md);
1751 lli->lli_default_lsm_md = md->default_lmv;
1752 lsm_md_dump(D_INODE, md->default_lmv);
1753 md->default_lmv = NULL;
1754 up_write(&lli->lli_lsm_sem);
1758 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1760 struct ll_inode_info *lli = ll_i2info(inode);
1761 struct lmv_stripe_md *lsm = md->lmv;
1762 struct cl_attr *attr;
1767 LASSERT(S_ISDIR(inode->i_mode));
1768 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1769 PFID(ll_inode2fid(inode)));
1771 /* update default LMV */
1772 if (md->default_lmv)
1773 ll_update_default_lsm_md(inode, md);
1775 /* after dir migration/restripe, a stripe may be turned into a
1776 * directory, in this case, zero out its lli_pfid.
1778 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1779 fid_zero(&lli->lli_pfid);
1782 * no striped information from request, lustre_md from req does not
1783 * include stripeEA, see ll_md_setattr()
1789 * normally dir layout doesn't change, only take read lock to check
1790 * that to avoid blocking other MD operations.
1792 down_read(&lli->lli_lsm_sem);
1794 /* some current lookup initialized lsm, and unchanged */
1795 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1796 GOTO(unlock, rc = 0);
1798 /* if dir layout doesn't match, check whether version is increased,
1799 * which means layout is changed, this happens in dir split/merge and
1802 * foreign LMV should not change.
1804 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1805 lsm->lsm_md_layout_version <=
1806 lli->lli_lsm_md->lsm_md_layout_version) {
1807 CERROR("%s: "DFID" dir layout mismatch:\n",
1808 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1809 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1810 lsm_md_dump(D_ERROR, lsm);
1811 GOTO(unlock, rc = -EINVAL);
1814 up_read(&lli->lli_lsm_sem);
1815 down_write(&lli->lli_lsm_sem);
1816 /* clear existing lsm */
1817 if (lli->lli_lsm_md) {
1818 lmv_free_memmd(lli->lli_lsm_md);
1819 lli->lli_lsm_md = NULL;
1822 rc = ll_init_lsm_md(inode, md);
1824 up_write(&lli->lli_lsm_sem);
1828 /* md_merge_attr() may take long, since lsm is already set, switch to
1831 downgrade_write(&lli->lli_lsm_sem);
1833 /* set md->lmv to NULL, so the following free lustre_md will not free
1838 if (!lmv_dir_striped(lli->lli_lsm_md))
1839 GOTO(unlock, rc = 0);
1841 OBD_ALLOC_PTR(attr);
1843 GOTO(unlock, rc = -ENOMEM);
1845 /* validate the lsm */
1846 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1847 ll_md_blocking_ast);
1849 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1850 md->body->mbo_nlink = attr->cat_nlink;
1851 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1852 md->body->mbo_size = attr->cat_size;
1853 if (md->body->mbo_valid & OBD_MD_FLATIME)
1854 md->body->mbo_atime = attr->cat_atime;
1855 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1856 md->body->mbo_ctime = attr->cat_ctime;
1857 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1858 md->body->mbo_mtime = attr->cat_mtime;
1864 up_read(&lli->lli_lsm_sem);
1869 void ll_clear_inode(struct inode *inode)
1871 struct ll_inode_info *lli = ll_i2info(inode);
1872 struct ll_sb_info *sbi = ll_i2sbi(inode);
1876 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1877 PFID(ll_inode2fid(inode)), inode);
1879 if (S_ISDIR(inode->i_mode)) {
1880 /* these should have been cleared in ll_file_release */
1881 LASSERT(lli->lli_opendir_key == NULL);
1882 LASSERT(lli->lli_sai == NULL);
1883 LASSERT(lli->lli_opendir_pid == 0);
1885 pcc_inode_free(inode);
1888 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1890 LASSERT(!lli->lli_open_fd_write_count);
1891 LASSERT(!lli->lli_open_fd_read_count);
1892 LASSERT(!lli->lli_open_fd_exec_count);
1894 if (lli->lli_mds_write_och)
1895 ll_md_real_close(inode, FMODE_WRITE);
1896 if (lli->lli_mds_exec_och)
1897 ll_md_real_close(inode, FMODE_EXEC);
1898 if (lli->lli_mds_read_och)
1899 ll_md_real_close(inode, FMODE_READ);
1901 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1902 OBD_FREE(lli->lli_symlink_name,
1903 strlen(lli->lli_symlink_name) + 1);
1904 lli->lli_symlink_name = NULL;
1907 ll_xattr_cache_destroy(inode);
1909 forget_all_cached_acls(inode);
1911 lli->lli_inode_magic = LLI_INODE_DEAD;
1913 if (S_ISDIR(inode->i_mode))
1914 ll_dir_clear_lsm_md(inode);
1915 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1916 LASSERT(list_empty(&lli->lli_agl_list));
1919 * XXX This has to be done before lsm is freed below, because
1920 * cl_object still uses inode lsm.
1922 cl_inode_fini(inode);
1924 llcrypt_put_encryption_info(inode);
1929 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1931 struct lustre_md md;
1932 struct inode *inode = dentry->d_inode;
1933 struct ll_sb_info *sbi = ll_i2sbi(inode);
1934 struct ptlrpc_request *request = NULL;
1939 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1940 LUSTRE_OPC_ANY, NULL);
1941 if (IS_ERR(op_data))
1942 RETURN(PTR_ERR(op_data));
1944 /* If this is a chgrp of a regular file, we want to reserve enough
1945 * quota to cover the entire file size.
1947 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1948 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1949 from_kgid(&init_user_ns, inode->i_gid)) {
1950 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1951 op_data->op_attr_blocks = inode->i_blocks;
1955 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1957 ptlrpc_req_finished(request);
1958 if (rc == -ENOENT) {
1960 /* Unlinked special device node? Or just a race?
1961 * Pretend we done everything. */
1962 if (!S_ISREG(inode->i_mode) &&
1963 !S_ISDIR(inode->i_mode)) {
1964 ia_valid = op_data->op_attr.ia_valid;
1965 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1966 rc = simple_setattr(&init_user_ns, dentry,
1968 op_data->op_attr.ia_valid = ia_valid;
1970 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1971 CERROR("md_setattr fails: rc = %d\n", rc);
1976 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1977 sbi->ll_md_exp, &md);
1979 ptlrpc_req_finished(request);
1983 ia_valid = op_data->op_attr.ia_valid;
1984 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1985 * cache is not cleared yet. */
1986 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1987 if (S_ISREG(inode->i_mode))
1989 rc = simple_setattr(&init_user_ns, dentry, &op_data->op_attr);
1990 if (S_ISREG(inode->i_mode))
1991 inode_unlock(inode);
1992 op_data->op_attr.ia_valid = ia_valid;
1994 rc = ll_update_inode(inode, &md);
1995 ptlrpc_req_finished(request);
2001 * Zero portion of page that is part of @inode.
2002 * This implies, if necessary:
2003 * - taking cl_lock on range corresponding to concerned page
2004 * - grabbing vm page
2005 * - associating cl_page
2006 * - proceeding to clio read
2007 * - zeroing range in page
2008 * - proceeding to cl_page flush
2009 * - releasing cl_lock
2011 * \param[in] inode inode
2012 * \param[in] index page index
2013 * \param[in] offset offset in page to start zero from
2014 * \param[in] len len to zero
2016 * \retval 0 on success
2017 * \retval negative errno on failure
2019 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
2022 struct ll_inode_info *lli = ll_i2info(inode);
2023 struct cl_object *clob = lli->lli_clob;
2025 struct lu_env *env = NULL;
2026 struct cl_io *io = NULL;
2027 struct cl_page *clpage = NULL;
2028 struct page *vmpage = NULL;
2029 unsigned from = index << PAGE_SHIFT;
2030 struct cl_lock *lock = NULL;
2031 struct cl_lock_descr *descr = NULL;
2032 struct cl_2queue *queue = NULL;
2033 struct cl_sync_io *anchor = NULL;
2034 bool holdinglock = false;
2039 env = cl_env_get(&refcheck);
2041 RETURN(PTR_ERR(env));
2043 io = vvp_env_thread_io(env);
2045 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2049 lock = vvp_env_lock(env);
2050 descr = &lock->cll_descr;
2051 descr->cld_obj = io->ci_obj;
2052 descr->cld_start = cl_index(io->ci_obj, from);
2053 descr->cld_end = cl_index(io->ci_obj, from + PAGE_SIZE - 1);
2054 descr->cld_mode = CLM_WRITE;
2055 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2057 /* request lock for page */
2058 rc = cl_lock_request(env, io, lock);
2059 /* -ECANCELED indicates a matching lock with a different extent
2060 * was already present, and -EEXIST indicates a matching lock
2061 * on exactly the same extent was already present.
2062 * In both cases it means we are covered.
2064 if (rc == -ECANCELED || rc == -EEXIST)
2072 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2074 GOTO(rellock, rc = -EOPNOTSUPP);
2076 if (!PageDirty(vmpage)) {
2077 /* associate cl_page */
2078 clpage = cl_page_find(env, clob, vmpage->index,
2079 vmpage, CPT_CACHEABLE);
2081 GOTO(pagefini, rc = PTR_ERR(clpage));
2083 cl_page_assume(env, io, clpage);
2086 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2087 !PageWriteback(vmpage)) {
2089 /* Set PagePrivate2 to detect special case of empty page
2090 * in osc_brw_fini_request().
2091 * It is also used to tell ll_io_read_page() that we do not
2092 * want the vmpage to be unlocked.
2094 SetPagePrivate2(vmpage);
2095 rc = ll_io_read_page(env, io, clpage, NULL);
2096 if (!PagePrivate2(vmpage)) {
2097 /* PagePrivate2 was cleared in osc_brw_fini_request()
2098 * meaning we read an empty page. In this case, in order
2099 * to avoid allocating unnecessary block in truncated
2100 * file, we must not zero and write as below. Subsequent
2101 * server-side truncate will handle things correctly.
2103 cl_page_unassume(env, io, clpage);
2104 GOTO(clpfini, rc = 0);
2106 ClearPagePrivate2(vmpage);
2111 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2112 * the vmpage, so we are good to proceed and zero range in page.
2114 zero_user(vmpage, offset, len);
2116 if (holdinglock && clpage) {
2117 /* explicitly write newly modified page */
2118 queue = &io->ci_queue;
2119 cl_2queue_init(queue);
2120 anchor = &vvp_env_info(env)->vti_anchor;
2121 cl_sync_io_init(anchor, 1);
2122 clpage->cp_sync_io = anchor;
2123 cl_page_list_add(&queue->c2_qin, clpage, true);
2124 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2126 GOTO(queuefini1, rc);
2127 rc = cl_sync_io_wait(env, anchor, 0);
2129 GOTO(queuefini2, rc);
2130 cl_page_assume(env, io, clpage);
2133 cl_2queue_discard(env, io, queue);
2135 cl_2queue_disown(env, queue);
2136 cl_2queue_fini(env, queue);
2141 cl_page_put(env, clpage);
2143 unlock_page(vmpage);
2147 cl_lock_release(env, lock);
2149 cl_io_fini(env, io);
2152 cl_env_put(env, &refcheck);
2158 * Get reference file from volatile file name.
2159 * Volatile file name may look like:
2160 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2161 * where fd is opened descriptor of reference file.
2163 * \param[in] volatile_name volatile file name
2164 * \param[in] volatile_len volatile file name length
2165 * \param[out] ref_file pointer to struct file of reference file
2167 * \retval 0 on success
2168 * \retval negative errno on failure
2170 int volatile_ref_file(const char *volatile_name, int volatile_len,
2171 struct file **ref_file)
2173 char *p, *q, *fd_str;
2176 p = strnstr(volatile_name, ":fd=", volatile_len);
2177 if (!p || strlen(p + 4) == 0)
2180 q = strchrnul(p + 4, ':');
2181 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2184 rc = kstrtouint(fd_str, 10, &fd);
2189 *ref_file = fget(fd);
2195 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2196 * object(s) determine the file size and mtime. Otherwise, the MDS will
2197 * keep these values until such a time that objects are allocated for it.
2198 * We do the MDS operations first, as it is checking permissions for us.
2199 * We don't to the MDS RPC if there is nothing that we want to store there,
2200 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2201 * going to do an RPC anyways.
2203 * If we are doing a truncate, we will send the mtime and ctime updates
2204 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2205 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2208 * In case of HSMimport, we only set attr on MDS.
2210 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2211 enum op_xvalid xvalid, bool hsm_import)
2213 struct inode *inode = dentry->d_inode;
2214 struct ll_inode_info *lli = ll_i2info(inode);
2215 struct md_op_data *op_data = NULL;
2216 ktime_t kstart = ktime_get();
2221 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2222 "valid %x, hsm_import %d\n",
2223 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2224 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2227 if (attr->ia_valid & ATTR_SIZE) {
2228 /* Check new size against VFS/VM file size limit and rlimit */
2229 rc = inode_newsize_ok(inode, attr->ia_size);
2233 /* The maximum Lustre file size is variable, based on the
2234 * OST maximum object size and number of stripes. This
2235 * needs another check in addition to the VFS check above. */
2236 if (attr->ia_size > ll_file_maxbytes(inode)) {
2237 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2238 PFID(&lli->lli_fid), attr->ia_size,
2239 ll_file_maxbytes(inode));
2243 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2246 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2247 if (attr->ia_valid & TIMES_SET_FLAGS) {
2248 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2249 !capable(CAP_FOWNER))
2253 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2254 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2255 (attr->ia_valid & ATTR_CTIME)) {
2256 attr->ia_ctime = current_time(inode);
2257 xvalid |= OP_XVALID_CTIME_SET;
2259 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2260 (attr->ia_valid & ATTR_ATIME)) {
2261 attr->ia_atime = current_time(inode);
2262 attr->ia_valid |= ATTR_ATIME_SET;
2264 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2265 (attr->ia_valid & ATTR_MTIME)) {
2266 attr->ia_mtime = current_time(inode);
2267 attr->ia_valid |= ATTR_MTIME_SET;
2270 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2271 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2272 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2273 ktime_get_real_seconds());
2275 if (S_ISREG(inode->i_mode))
2276 inode_unlock(inode);
2278 /* We always do an MDS RPC, even if we're only changing the size;
2279 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2281 OBD_ALLOC_PTR(op_data);
2282 if (op_data == NULL)
2283 GOTO(out, rc = -ENOMEM);
2285 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2286 /* If we are changing file size, file content is
2287 * modified, flag it.
2289 xvalid |= OP_XVALID_OWNEROVERRIDE;
2290 op_data->op_bias |= MDS_DATA_MODIFIED;
2291 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2294 if (attr->ia_valid & ATTR_FILE) {
2295 struct ll_file_data *fd = attr->ia_file->private_data;
2297 if (fd->fd_lease_och)
2298 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2301 op_data->op_attr = *attr;
2302 op_data->op_xvalid = xvalid;
2304 rc = ll_md_setattr(dentry, op_data);
2307 lli->lli_synced_to_mds = false;
2309 if (!S_ISREG(inode->i_mode) || hsm_import)
2312 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2313 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2314 xvalid & OP_XVALID_CTIME_SET) {
2315 bool cached = false;
2317 rc = pcc_inode_setattr(inode, attr, &cached);
2320 CERROR("%s: PCC inode "DFID" setattr failed: "
2322 ll_i2sbi(inode)->ll_fsname,
2323 PFID(&lli->lli_fid), rc);
2327 unsigned int flags = 0;
2329 /* For truncate and utimes sending attributes to OSTs,
2330 * setting mtime/atime to the past will be performed
2331 * under PW [0:EOF] extent lock (new_size:EOF for
2332 * truncate). It may seem excessive to send mtime/atime
2333 * updates to OSTs when not setting times to past, but
2334 * it is necessary due to possible time
2335 * de-synchronization between MDT inode and OST objects
2337 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2338 xvalid |= OP_XVALID_FLAGS;
2339 flags = LUSTRE_ENCRYPT_FL;
2340 /* Call to ll_io_zero_page is not necessary if
2341 * truncating on PAGE_SIZE boundary, because
2342 * whole pages will be wiped.
2343 * In case of Direct IO, all we need is to set
2346 if (attr->ia_valid & ATTR_SIZE &&
2347 attr->ia_size & ~PAGE_MASK &&
2348 !(attr->ia_valid & ATTR_FILE &&
2349 attr->ia_file->f_flags & O_DIRECT)) {
2351 attr->ia_size & (PAGE_SIZE - 1);
2353 rc = ll_io_zero_page(inode,
2354 attr->ia_size >> PAGE_SHIFT,
2355 offset, PAGE_SIZE - offset);
2359 /* If encrypted volatile file without the key,
2360 * we need to fetch size from reference file,
2361 * and set it on OST objects. This happens when
2362 * migrating or extending an encrypted file
2365 if (filename_is_volatile(dentry->d_name.name,
2368 llcrypt_require_key(inode) == -ENOKEY) {
2369 struct file *ref_file;
2370 struct inode *ref_inode;
2371 struct ll_inode_info *ref_lli;
2372 struct cl_object *ref_obj;
2373 struct cl_attr ref_attr = { 0 };
2377 rc = volatile_ref_file(
2378 dentry->d_name.name,
2384 ref_inode = file_inode(ref_file);
2387 GOTO(out, rc = -EINVAL);
2390 env = cl_env_get(&refcheck);
2392 GOTO(out, rc = PTR_ERR(env));
2394 ref_lli = ll_i2info(ref_inode);
2395 ref_obj = ref_lli->lli_clob;
2396 cl_object_attr_lock(ref_obj);
2397 rc = cl_object_attr_get(env, ref_obj,
2399 cl_object_attr_unlock(ref_obj);
2400 cl_env_put(env, &refcheck);
2405 attr->ia_valid |= ATTR_SIZE;
2406 attr->ia_size = ref_attr.cat_size;
2409 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2413 /* If the file was restored, it needs to set dirty flag.
2415 * We've already sent MDS_DATA_MODIFIED flag in
2416 * ll_md_setattr() for truncate. However, the MDT refuses to
2417 * set the HS_DIRTY flag on released files, so we have to set
2418 * it again if the file has been restored. Please check how
2419 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2421 * Please notice that if the file is not released, the previous
2422 * MDS_DATA_MODIFIED has taken effect and usually
2423 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2424 * This way we can save an RPC for common open + trunc
2426 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2427 struct hsm_state_set hss = {
2428 .hss_valid = HSS_SETMASK,
2429 .hss_setmask = HS_DIRTY,
2433 rc2 = ll_hsm_state_set(inode, &hss);
2434 /* truncate and write can happen at the same time, so that
2435 * the file can be set modified even though the file is not
2436 * restored from released state, and ll_hsm_state_set() is
2437 * not applicable for the file, and rc2 < 0 is normal in this
2440 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2441 PFID(ll_inode2fid(inode)), rc2);
2446 if (op_data != NULL)
2447 ll_finish_md_op_data(op_data);
2449 if (S_ISREG(inode->i_mode)) {
2451 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2452 inode_dio_wait(inode);
2453 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2454 * flag. ll_update_inode (called from ll_md_setattr), clears
2455 * inode flags, so there is a gap where S_NOSEC is not set.
2456 * This can cause a writer to take the i_mutex unnecessarily,
2457 * but this is safe to do and should be rare. */
2458 inode_has_no_xattr(inode);
2462 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2463 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2464 ktime_us_delta(ktime_get(), kstart));
2469 int ll_setattr(struct user_namespace *mnt_userns, struct dentry *de,
2472 int mode = de->d_inode->i_mode;
2473 enum op_xvalid xvalid = 0;
2476 rc = llcrypt_prepare_setattr(de, attr);
2480 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2481 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2482 xvalid |= OP_XVALID_OWNEROVERRIDE;
2484 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2485 (ATTR_SIZE|ATTR_MODE)) &&
2486 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2487 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2488 !(attr->ia_mode & S_ISGID))))
2489 attr->ia_valid |= ATTR_FORCE;
2491 if ((attr->ia_valid & ATTR_MODE) &&
2493 !(attr->ia_mode & S_ISUID) &&
2494 !(attr->ia_valid & ATTR_KILL_SUID))
2495 attr->ia_valid |= ATTR_KILL_SUID;
2497 if ((attr->ia_valid & ATTR_MODE) &&
2498 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2499 !(attr->ia_mode & S_ISGID) &&
2500 !(attr->ia_valid & ATTR_KILL_SGID))
2501 attr->ia_valid |= ATTR_KILL_SGID;
2503 return ll_setattr_raw(de, attr, xvalid, false);
2506 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2509 struct obd_statfs obd_osfs = { 0 };
2514 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2516 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2517 flags |= OBD_STATFS_NODELAY;
2519 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2523 osfs->os_type = LL_SUPER_MAGIC;
2525 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2526 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2528 if (osfs->os_state & OS_STATFS_SUM)
2531 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2532 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2535 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2536 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2539 osfs->os_bsize = obd_osfs.os_bsize;
2540 osfs->os_blocks = obd_osfs.os_blocks;
2541 osfs->os_bfree = obd_osfs.os_bfree;
2542 osfs->os_bavail = obd_osfs.os_bavail;
2544 /* If we have _some_ OSTs, but don't have as many free objects on the
2545 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2546 * to compensate, so that the "inodes in use" number is correct.
2547 * This should be kept in sync with lod_statfs() behaviour.
2549 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2550 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2552 osfs->os_ffree = obd_osfs.os_ffree;
2559 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2561 struct if_quotactl qctl = {
2562 .qc_cmd = LUSTRE_Q_GETQUOTA,
2563 .qc_type = PRJQUOTA,
2564 .qc_valid = QC_GENERAL,
2566 u64 limit, curblock;
2569 qctl.qc_id = ll_i2info(inode)->lli_projid;
2570 ret = quotactl_ioctl(inode->i_sb, &qctl);
2572 /* ignore errors if project ID does not have
2573 * a quota limit or feature unsupported.
2575 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2580 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2581 qctl.qc_dqblk.dqb_bsoftlimit :
2582 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2583 if (limit && sfs->f_blocks > limit) {
2584 curblock = (qctl.qc_dqblk.dqb_curspace +
2585 sfs->f_bsize - 1) / sfs->f_bsize;
2586 sfs->f_blocks = limit;
2587 sfs->f_bfree = sfs->f_bavail =
2588 (sfs->f_blocks > curblock) ?
2589 (sfs->f_blocks - curblock) : 0;
2592 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2593 qctl.qc_dqblk.dqb_isoftlimit :
2594 qctl.qc_dqblk.dqb_ihardlimit;
2595 if (limit && sfs->f_files > limit) {
2596 sfs->f_files = limit;
2597 sfs->f_ffree = (sfs->f_files >
2598 qctl.qc_dqblk.dqb_curinodes) ?
2599 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2605 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2607 struct super_block *sb = de->d_sb;
2608 struct obd_statfs osfs;
2609 __u64 fsid = huge_encode_dev(sb->s_dev);
2610 ktime_t kstart = ktime_get();
2613 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2615 /* Some amount of caching on the client is allowed */
2616 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2620 statfs_unpack(sfs, &osfs);
2622 /* We need to downshift for all 32-bit kernels, because we can't
2623 * tell if the kernel is being called via sys_statfs64() or not.
2624 * Stop before overflowing f_bsize - in which case it is better
2625 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2626 if (sizeof(long) < 8) {
2627 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2630 osfs.os_blocks >>= 1;
2631 osfs.os_bfree >>= 1;
2632 osfs.os_bavail >>= 1;
2636 sfs->f_blocks = osfs.os_blocks;
2637 sfs->f_bfree = osfs.os_bfree;
2638 sfs->f_bavail = osfs.os_bavail;
2639 sfs->f_fsid.val[0] = (__u32)fsid;
2640 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2641 if (ll_i2info(de->d_inode)->lli_projid &&
2642 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2643 return ll_statfs_project(de->d_inode, sfs);
2645 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2646 ktime_us_delta(ktime_get(), kstart));
2651 void ll_inode_size_lock(struct inode *inode)
2653 struct ll_inode_info *lli;
2655 LASSERT(!S_ISDIR(inode->i_mode));
2657 lli = ll_i2info(inode);
2658 mutex_lock(&lli->lli_size_mutex);
2661 void ll_inode_size_unlock(struct inode *inode)
2663 struct ll_inode_info *lli;
2665 lli = ll_i2info(inode);
2666 mutex_unlock(&lli->lli_size_mutex);
2669 int ll_inode_size_trylock(struct inode *inode)
2671 struct ll_inode_info *lli;
2673 LASSERT(!S_ISDIR(inode->i_mode));
2675 lli = ll_i2info(inode);
2676 return mutex_trylock(&lli->lli_size_mutex);
2679 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2681 /* do not clear encryption flag */
2682 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2683 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2684 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2685 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2687 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2690 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2692 struct ll_inode_info *lli = ll_i2info(inode);
2693 struct mdt_body *body = md->body;
2694 struct ll_sb_info *sbi = ll_i2sbi(inode);
2698 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2699 rc = cl_file_inode_init(inode, md);
2704 if (S_ISDIR(inode->i_mode)) {
2705 rc = ll_update_lsm_md(inode, md);
2710 if (body->mbo_valid & OBD_MD_FLACL)
2711 lli_replace_acl(lli, md);
2713 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2714 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2715 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2717 if (body->mbo_valid & OBD_MD_FLATIME) {
2718 if (body->mbo_atime > inode->i_atime.tv_sec)
2719 inode->i_atime.tv_sec = body->mbo_atime;
2720 lli->lli_atime = body->mbo_atime;
2723 if (body->mbo_valid & OBD_MD_FLMTIME) {
2724 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2726 "setting ino %lu mtime from %lld to %llu\n",
2727 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2729 inode->i_mtime.tv_sec = body->mbo_mtime;
2731 lli->lli_mtime = body->mbo_mtime;
2734 if (body->mbo_valid & OBD_MD_FLCTIME) {
2735 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2736 inode->i_ctime.tv_sec = body->mbo_ctime;
2737 lli->lli_ctime = body->mbo_ctime;
2740 if (body->mbo_valid & OBD_MD_FLBTIME)
2741 lli->lli_btime = body->mbo_btime;
2743 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2744 if (body->mbo_valid & OBD_MD_FLFLAGS)
2745 ll_update_inode_flags(inode, body->mbo_flags);
2746 if (body->mbo_valid & OBD_MD_FLMODE)
2747 inode->i_mode = (inode->i_mode & S_IFMT) |
2748 (body->mbo_mode & ~S_IFMT);
2750 if (body->mbo_valid & OBD_MD_FLTYPE)
2751 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2752 (body->mbo_mode & S_IFMT);
2754 LASSERT(inode->i_mode != 0);
2755 if (body->mbo_valid & OBD_MD_FLUID)
2756 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2757 if (body->mbo_valid & OBD_MD_FLGID)
2758 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2759 if (body->mbo_valid & OBD_MD_FLPROJID)
2760 lli->lli_projid = body->mbo_projid;
2761 if (body->mbo_valid & OBD_MD_FLNLINK) {
2762 spin_lock(&inode->i_lock);
2763 set_nlink(inode, body->mbo_nlink);
2764 spin_unlock(&inode->i_lock);
2766 if (body->mbo_valid & OBD_MD_FLRDEV)
2767 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2769 if (body->mbo_valid & OBD_MD_FLID) {
2770 /* FID shouldn't be changed! */
2771 if (fid_is_sane(&lli->lli_fid)) {
2772 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2773 "Trying to change FID "DFID
2774 " to the "DFID", inode "DFID"(%p)\n",
2775 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2776 PFID(ll_inode2fid(inode)), inode);
2778 lli->lli_fid = body->mbo_fid1;
2782 LASSERT(fid_seq(&lli->lli_fid) != 0);
2784 /* In case of encrypted file without the key, please do not lose
2785 * clear text size stored into lli_lazysize in ll_merge_attr(),
2786 * we will need it in ll_prepare_close().
2788 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2789 llcrypt_require_key(inode) == -ENOKEY)
2790 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2792 lli->lli_attr_valid = body->mbo_valid;
2793 if (body->mbo_valid & OBD_MD_FLSIZE) {
2794 i_size_write(inode, body->mbo_size);
2796 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2797 PFID(ll_inode2fid(inode)),
2798 (unsigned long long)body->mbo_size);
2800 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2801 inode->i_blocks = body->mbo_blocks;
2803 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2804 lli->lli_lazysize = body->mbo_size;
2805 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2806 lli->lli_lazyblocks = body->mbo_blocks;
2809 if (body->mbo_valid & OBD_MD_TSTATE) {
2810 /* Set LLIF_FILE_RESTORING if restore ongoing and
2811 * clear it when done to ensure to start again
2812 * glimpsing updated attrs
2814 if (body->mbo_t_state & MS_RESTORE)
2815 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2817 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2823 /* child default LMV is inherited from parent */
2824 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2825 struct lmv_stripe_md *cdmv)
2830 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2831 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2832 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2833 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2836 if (cdmv->lsm_md_max_inherit !=
2837 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2840 if (cdmv->lsm_md_max_inherit_rr !=
2841 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2847 /* update directory depth to ROOT, called after LOOKUP lock is fetched. */
2848 void ll_update_dir_depth(struct inode *dir, struct inode *inode)
2850 struct ll_inode_info *plli;
2851 struct ll_inode_info *lli;
2853 if (!S_ISDIR(inode->i_mode))
2859 plli = ll_i2info(dir);
2860 lli = ll_i2info(inode);
2861 lli->lli_dir_depth = plli->lli_dir_depth + 1;
2862 if (plli->lli_default_lsm_md && lli->lli_default_lsm_md) {
2863 down_read(&plli->lli_lsm_sem);
2864 down_read(&lli->lli_lsm_sem);
2865 if (ll_default_lmv_inherited(plli->lli_default_lsm_md,
2866 lli->lli_default_lsm_md))
2867 lli->lli_inherit_depth =
2868 plli->lli_inherit_depth + 1;
2870 lli->lli_inherit_depth = 0;
2871 up_read(&lli->lli_lsm_sem);
2872 up_read(&plli->lli_lsm_sem);
2874 lli->lli_inherit_depth = 0;
2877 CDEBUG(D_INODE, DFID" depth %hu default LMV depth %hu\n",
2878 PFID(&lli->lli_fid), lli->lli_dir_depth, lli->lli_inherit_depth);
2881 void ll_truncate_inode_pages_final(struct inode *inode, struct cl_io *io)
2883 struct address_space *mapping = &inode->i_data;
2884 unsigned long nrpages;
2885 unsigned long flags;
2887 LASSERTF(io == NULL || inode_is_locked(inode), "io %p (type %d)\n",
2888 io, io ? io->ci_type : 0);
2890 truncate_inode_pages_final(mapping);
2892 /* Workaround for LU-118: Note nrpages may not be totally updated when
2893 * truncate_inode_pages() returns, as there can be a page in the process
2894 * of deletion (inside __delete_from_page_cache()) in the specified
2895 * range. Thus mapping->nrpages can be non-zero when this function
2896 * returns even after truncation of the whole mapping. Only do this if
2897 * npages isn't already zero.
2899 nrpages = mapping->nrpages;
2901 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2902 nrpages = mapping->nrpages;
2903 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2904 } /* Workaround end */
2906 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu "
2907 "io %p (io_type %d), "
2908 "see https://jira.whamcloud.com/browse/LU-118\n",
2909 ll_i2sbi(inode)->ll_fsname,
2910 PFID(ll_inode2fid(inode)), inode, nrpages,
2911 io, io ? io->ci_type : 0);
2914 int ll_read_inode2(struct inode *inode, void *opaque)
2916 struct lustre_md *md = opaque;
2917 struct ll_inode_info *lli = ll_i2info(inode);
2921 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2922 PFID(&lli->lli_fid), inode);
2924 /* Core attributes from the MDS first. This is a new inode, and
2925 * the VFS doesn't zero times in the core inode so we have to do
2926 * it ourselves. They will be overwritten by either MDS or OST
2927 * attributes - we just need to make sure they aren't newer.
2929 inode->i_mtime.tv_sec = 0;
2930 inode->i_atime.tv_sec = 0;
2931 inode->i_ctime.tv_sec = 0;
2933 rc = ll_update_inode(inode, md);
2937 /* OIDEBUG(inode); */
2939 #ifdef HAVE_BACKING_DEV_INFO
2940 /* initializing backing dev info. */
2941 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2943 if (S_ISREG(inode->i_mode)) {
2944 struct ll_sb_info *sbi = ll_i2sbi(inode);
2945 inode->i_op = &ll_file_inode_operations;
2946 inode->i_fop = sbi->ll_fop;
2947 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2949 } else if (S_ISDIR(inode->i_mode)) {
2950 inode->i_op = &ll_dir_inode_operations;
2951 inode->i_fop = &ll_dir_operations;
2953 } else if (S_ISLNK(inode->i_mode)) {
2954 inode->i_op = &ll_fast_symlink_inode_operations;
2957 inode->i_op = &ll_special_inode_operations;
2959 init_special_inode(inode, inode->i_mode,
2968 void ll_delete_inode(struct inode *inode)
2970 struct ll_inode_info *lli = ll_i2info(inode);
2973 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2974 /* It is last chance to write out dirty pages,
2975 * otherwise we may lose data while umount.
2977 * If i_nlink is 0 then just discard data. This is safe because
2978 * local inode gets i_nlink 0 from server only for the last
2979 * unlink, so that file is not opened somewhere else
2981 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2982 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2985 ll_truncate_inode_pages_final(inode, NULL);
2986 ll_clear_inode(inode);
2992 /* ioctl commands shared between files and directories */
2993 int ll_iocontrol(struct inode *inode, struct file *file,
2994 unsigned int cmd, void __user *uarg)
2996 struct ll_sb_info *sbi = ll_i2sbi(inode);
2997 struct ptlrpc_request *req = NULL;
3003 RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
3004 case FSFILT_IOC_GETVERSION:
3005 case FS_IOC_GETVERSION:
3006 RETURN(put_user(inode->i_generation, (int __user *)uarg));
3007 case FS_IOC_GETFLAGS: {
3008 struct mdt_body *body;
3009 struct md_op_data *op_data;
3011 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3012 LUSTRE_OPC_ANY, NULL);
3013 if (IS_ERR(op_data))
3014 RETURN(PTR_ERR(op_data));
3016 op_data->op_valid = OBD_MD_FLFLAGS;
3017 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
3018 ll_finish_md_op_data(op_data);
3020 CERROR("%s: failure inode "DFID": rc = %d\n",
3021 sbi->ll_md_exp->exp_obd->obd_name,
3022 PFID(ll_inode2fid(inode)), rc);
3026 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3028 flags = body->mbo_flags;
3029 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
3030 * ext4 equivalent to please lsattr and other e2fsprogs tools
3032 if (flags & LUSTRE_ENCRYPT_FL)
3033 flags |= STATX_ATTR_ENCRYPTED;
3035 ptlrpc_req_finished(req);
3037 RETURN(put_user(flags, (int __user *)uarg));
3039 case FS_IOC_SETFLAGS: {
3041 struct md_op_data *op_data;
3042 struct cl_object *obj;
3043 struct fsxattr fa = { 0 };
3045 if (get_user(flags, (int __user *)uarg))
3048 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3049 if (flags & LUSTRE_PROJINHERIT_FL)
3050 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3052 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3057 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3058 LUSTRE_OPC_ANY, NULL);
3059 if (IS_ERR(op_data))
3060 RETURN(PTR_ERR(op_data));
3062 op_data->op_attr_flags = flags;
3063 op_data->op_xvalid |= OP_XVALID_FLAGS;
3064 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3065 ll_finish_md_op_data(op_data);
3066 ptlrpc_req_finished(req);
3070 ll_update_inode_flags(inode, flags);
3072 obj = ll_i2info(inode)->lli_clob;
3076 OBD_ALLOC_PTR(attr);
3080 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3085 case FS_IOC_FSGETXATTR:
3086 RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
3087 case FS_IOC_FSSETXATTR:
3088 RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
3089 case LL_IOC_PROJECT:
3090 RETURN(ll_ioctl_project(file, cmd, uarg));
3091 case IOC_OBD_STATFS:
3092 RETURN(ll_obd_statfs(inode, uarg));
3093 case LL_IOC_GET_MDTIDX: {
3094 rc = ll_get_mdt_idx(inode);
3098 if (put_user(rc, (int __user *)uarg))
3103 case LL_IOC_FLUSHCTX:
3104 RETURN(ll_flush_ctx(inode));
3105 #ifdef HAVE_LUSTRE_CRYPTO
3106 case LL_IOC_ADD_ENCRYPTION_KEY:
3107 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3109 rc = llcrypt_ioctl_add_key(file, uarg);
3110 #ifdef CONFIG_LL_ENCRYPTION
3111 if (!rc && S_ISDIR(inode->i_mode))
3112 sptlrpc_enc_pool_add_user();
3115 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
3116 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3118 RETURN(llcrypt_ioctl_get_key_status(file, uarg));
3119 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
3120 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3122 RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
3123 case LL_IOC_SET_ENCRYPTION_POLICY:
3124 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3126 RETURN(llcrypt_ioctl_set_policy(file, uarg));
3127 case LL_IOC_REMOVE_ENCRYPTION_KEY:
3128 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3130 RETURN(llcrypt_ioctl_remove_key(file, uarg));
3131 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
3132 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3134 RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
3136 case LL_IOC_GETPARENT:
3137 RETURN(ll_getparent(file, uarg));
3138 case LL_IOC_PATH2FID:
3139 if (copy_to_user(uarg, ll_inode2fid(inode),
3140 sizeof(struct lu_fid)))
3143 case LL_IOC_UNLOCK_FOREIGN: {
3144 struct dentry *dentry = file_dentry(file);
3146 /* if not a foreign symlink do nothing */
3147 if (ll_foreign_is_removable(dentry, true)) {
3149 "prevent unlink of non-foreign file ("DFID")\n",
3150 PFID(ll_inode2fid(inode)));
3151 RETURN(-EOPNOTSUPP);
3155 case OBD_IOC_FID2PATH:
3156 RETURN(ll_fid2path(inode, uarg));
3157 case OBD_IOC_GETNAME_OLD:
3158 case OBD_IOC_GETDTNAME:
3159 case OBD_IOC_GETMDNAME:
3160 RETURN(ll_get_obd_name(inode, cmd, uarg));
3168 int ll_flush_ctx(struct inode *inode)
3170 struct ll_sb_info *sbi = ll_i2sbi(inode);
3172 CDEBUG(D_SEC, "flush context for user %d\n",
3173 from_kuid(&init_user_ns, current_uid()));
3175 obd_set_info_async(NULL, sbi->ll_md_exp,
3176 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3178 obd_set_info_async(NULL, sbi->ll_dt_exp,
3179 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3184 /* umount -f client means force down, don't save state */
3185 void ll_umount_begin(struct super_block *sb)
3187 struct ll_sb_info *sbi = ll_s2sbi(sb);
3188 struct obd_device *obd;
3189 struct obd_ioctl_data *ioc_data;
3193 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3194 sb->s_count, atomic_read(&sb->s_active));
3196 obd = class_exp2obd(sbi->ll_md_exp);
3198 CERROR("Invalid MDC connection handle %#llx\n",
3199 sbi->ll_md_exp->exp_handle.h_cookie);
3205 obd = class_exp2obd(sbi->ll_dt_exp);
3207 CERROR("Invalid LOV connection handle %#llx\n",
3208 sbi->ll_dt_exp->exp_handle.h_cookie);
3214 OBD_ALLOC_PTR(ioc_data);
3216 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
3217 sizeof *ioc_data, ioc_data, NULL);
3219 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
3220 sizeof *ioc_data, ioc_data, NULL);
3222 OBD_FREE_PTR(ioc_data);
3225 /* Really, we'd like to wait until there are no requests outstanding,
3226 * and then continue. For now, we just periodically checking for vfs
3227 * to decrement mnt_cnt and hope to finish it within 10sec.
3231 !may_umount(sbi->ll_mnt.mnt)) {
3239 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3241 struct ll_sb_info *sbi = ll_s2sbi(sb);
3242 char *profilenm = get_profile_name(sb);
3246 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3247 read_only = *flags & MS_RDONLY;
3248 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3249 sizeof(KEY_READ_ONLY),
3250 KEY_READ_ONLY, sizeof(read_only),
3253 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3254 profilenm, read_only ?
3255 "read-only" : "read-write", err);
3260 sb->s_flags |= SB_RDONLY;
3262 sb->s_flags &= ~SB_RDONLY;
3264 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3265 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3266 read_only ? "read-only" : "read-write");
3272 * Cleanup the open handle that is cached on MDT-side.
3274 * For open case, the client side open handling thread may hit error
3275 * after the MDT grant the open. Under such case, the client should
3276 * send close RPC to the MDT as cleanup; otherwise, the open handle
3277 * on the MDT will be leaked there until the client umount or evicted.
3279 * In further, if someone unlinked the file, because the open handle
3280 * holds the reference on such file/object, then it will block the
3281 * subsequent threads that want to locate such object via FID.
3283 * \param[in] sb super block for this file-system
3284 * \param[in] open_req pointer to the original open request
3286 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3288 struct mdt_body *body;
3289 struct md_op_data *op_data;
3290 struct ptlrpc_request *close_req = NULL;
3291 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3294 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3295 OBD_ALLOC_PTR(op_data);
3296 if (op_data == NULL) {
3297 CWARN("%s: cannot allocate op_data to release open handle for "
3298 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3303 op_data->op_fid1 = body->mbo_fid1;
3304 op_data->op_open_handle = body->mbo_open_handle;
3305 op_data->op_mod_time = ktime_get_real_seconds();
3306 md_close(exp, op_data, NULL, &close_req);
3307 ptlrpc_req_finished(close_req);
3308 ll_finish_md_op_data(op_data);
3313 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3314 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3315 struct lustre_md *md)
3317 struct ll_sb_info *sbi = ll_i2sbi(inode);
3318 struct ptlrpc_request *req = NULL;
3319 union lmv_mds_md *lmm = NULL;
3323 LASSERT(is_root_inode(inode));
3324 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3325 LASSERT(!md->default_lmv);
3327 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3329 GET_DEFAULT_LAYOUT_ROOT);
3330 if (rc && rc != -ENODATA)
3335 rc = md_unpackmd(sbi->ll_md_exp, &md->default_lmv, lmm, size);
3344 ptlrpc_req_finished(req);
3348 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3349 struct super_block *sb, struct lookup_intent *it)
3351 struct ll_sb_info *sbi = NULL;
3352 struct lustre_md md = { NULL };
3353 bool default_lmv_deleted = false;
3358 LASSERT(*inode || sb);
3359 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3360 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3361 sbi->ll_md_exp, &md);
3366 * clear default_lmv only if intent_getattr reply doesn't contain it.
3367 * but it needs to be done after iget, check this early because
3368 * ll_update_lsm_md() may change md.
3370 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3371 S_ISDIR(md.body->mbo_mode) && !md.default_lmv) {
3372 if (unlikely(*inode && is_root_inode(*inode) &&
3373 !fid_is_root(&sbi->ll_root_fid))) {
3374 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3379 if (!md.default_lmv)
3380 default_lmv_deleted = true;
3384 rc = ll_update_inode(*inode, &md);
3388 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3389 struct lu_fid *fid1 = &md.body->mbo_fid1;
3391 LASSERT(sb != NULL);
3394 * At this point server returns to client's same fid as client
3395 * generated for creating. So using ->fid1 is okay here.
3397 if (!fid_is_sane(fid1)) {
3398 CERROR("%s: Fid is insane "DFID"\n",
3399 sbi->ll_fsname, PFID(fid1));
3400 GOTO(out, rc = -EINVAL);
3403 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3404 if (IS_ERR(*inode)) {
3406 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3408 CERROR("new_inode -fatal: rc %d\n", rc);
3413 /* Handling piggyback layout lock.
3414 * Layout lock can be piggybacked by getattr and open request.
3415 * The lsm can be applied to inode only if it comes with a layout lock
3416 * otherwise correct layout may be overwritten, for example:
3417 * 1. proc1: mdt returns a lsm but not granting layout
3418 * 2. layout was changed by another client
3419 * 3. proc2: refresh layout and layout lock granted
3420 * 4. proc1: to apply a stale layout */
3421 if (it != NULL && it->it_lock_mode != 0) {
3422 struct lustre_handle lockh;
3423 struct ldlm_lock *lock;
3425 lockh.cookie = it->it_lock_handle;
3426 lock = ldlm_handle2lock(&lockh);
3427 LASSERT(lock != NULL);
3428 if (ldlm_has_layout(lock)) {
3429 struct cl_object_conf conf;
3431 memset(&conf, 0, sizeof(conf));
3432 conf.coc_opc = OBJECT_CONF_SET;
3433 conf.coc_inode = *inode;
3434 conf.coc_lock = lock;
3435 conf.u.coc_layout = md.layout;
3436 (void)ll_layout_conf(*inode, &conf);
3438 LDLM_LOCK_PUT(lock);
3441 if (default_lmv_deleted)
3442 ll_update_default_lsm_md(*inode, &md);
3444 /* we may want to apply some policy for foreign file/dir */
3445 if (ll_sbi_has_foreign_symlink(sbi)) {
3446 rc = ll_manage_foreign(*inode, &md);
3454 /* cleanup will be done if necessary */
3455 md_free_lustre_md(sbi->ll_md_exp, &md);
3457 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3458 ll_intent_drop_lock(it);
3459 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3465 int ll_obd_statfs(struct inode *inode, void __user *uarg)
3467 struct ll_sb_info *sbi = NULL;
3468 struct obd_export *exp;
3469 struct obd_ioctl_data *data = NULL;
3474 sbi = ll_i2sbi(inode);
3476 GOTO(out_statfs, rc = -EINVAL);
3478 rc = obd_ioctl_getdata(&data, &len, uarg);
3480 GOTO(out_statfs, rc);
3482 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3483 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3484 GOTO(out_statfs, rc = -EINVAL);
3486 if (data->ioc_inllen1 != sizeof(__u32) ||
3487 data->ioc_inllen2 != sizeof(__u32) ||
3488 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3489 data->ioc_plen2 != sizeof(struct obd_uuid))
3490 GOTO(out_statfs, rc = -EINVAL);
3492 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3493 if (type & LL_STATFS_LMV)
3494 exp = sbi->ll_md_exp;
3495 else if (type & LL_STATFS_LOV)
3496 exp = sbi->ll_dt_exp;
3498 GOTO(out_statfs, rc = -ENODEV);
3500 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3502 GOTO(out_statfs, rc);
3504 OBD_FREE_LARGE(data, len);
3509 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3510 * be called early to avoid deadlock.
3512 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3514 if (op_data->op_mea2_sem) {
3515 up_read_non_owner(op_data->op_mea2_sem);
3516 op_data->op_mea2_sem = NULL;
3519 if (op_data->op_mea1_sem) {
3520 up_read_non_owner(op_data->op_mea1_sem);
3521 op_data->op_mea1_sem = NULL;
3525 /* this function prepares md_op_data hint for passing it down to MD stack. */
3526 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3527 struct inode *i1, struct inode *i2,
3528 const char *name, size_t namelen,
3529 __u32 mode, enum md_op_code opc,
3532 struct llcrypt_name fname = { 0 };
3535 LASSERT(i1 != NULL);
3538 /* Do not reuse namelen for something else. */
3540 return ERR_PTR(-EINVAL);
3542 if ((!IS_ENCRYPTED(i1) ||
3543 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3544 namelen > ll_i2sbi(i1)->ll_namelen)
3545 return ERR_PTR(-ENAMETOOLONG);
3547 /* "/" is not valid name, but it's allowed */
3548 if (!lu_name_is_valid_2(name, namelen) &&
3549 strncmp("/", name, namelen) != 0)
3550 return ERR_PTR(-EINVAL);
3553 if (op_data == NULL)
3554 OBD_ALLOC_PTR(op_data);
3556 if (op_data == NULL)
3557 return ERR_PTR(-ENOMEM);
3559 ll_i2gids(op_data->op_suppgids, i1, i2);
3560 /* If the client is using a subdir mount and looks at what it sees as
3561 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3563 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3564 !fid_is_root(ll_inode2fid(i1)) &&
3565 name && namelen == strlen(dot_fscrypt_name) &&
3566 strncmp(name, dot_fscrypt_name, namelen) == 0))
3567 lu_root_fid(&op_data->op_fid1);
3569 op_data->op_fid1 = *ll_inode2fid(i1);
3571 if (S_ISDIR(i1->i_mode)) {
3572 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3573 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3574 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3575 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3579 op_data->op_fid2 = *ll_inode2fid(i2);
3580 if (S_ISDIR(i2->i_mode)) {
3582 /* i2 is typically a child of i1, and MUST be
3583 * further from the root to avoid deadlocks.
3585 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3586 op_data->op_mea2_sem =
3587 &ll_i2info(i2)->lli_lsm_sem;
3589 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3592 fid_zero(&op_data->op_fid2);
3595 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3596 op_data->op_cli_flags |= CLI_HASH64;
3598 if (ll_need_32bit_api(ll_i2sbi(i1)))
3599 op_data->op_cli_flags |= CLI_API32;
3601 if ((i2 && is_root_inode(i2)) ||
3602 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3603 /* In case of lookup, ll_setup_filename() has already been
3604 * called in ll_lookup_it(), so just take provided name.
3605 * Also take provided name if we are dealing with root inode.
3607 fname.disk_name.name = (unsigned char *)name;
3608 fname.disk_name.len = namelen;
3609 } else if (name && namelen) {
3610 struct qstr dname = QSTR_INIT(name, namelen);
3612 struct lu_fid *pfid = NULL;
3616 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3617 /* special case when called from ll_link() */
3622 lookup = (int)(opc == LUSTRE_OPC_ANY);
3624 if (opc == LUSTRE_OPC_ANY && lookup)
3626 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3628 ll_finish_md_op_data(op_data);
3631 if (pfid && !fid_is_zero(pfid)) {
3633 op_data->op_fid2 = fid;
3634 op_data->op_bias = MDS_FID_OP;
3636 if (fname.disk_name.name &&
3637 fname.disk_name.name != (unsigned char *)name) {
3638 /* op_data->op_name must be freed after use */
3639 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3643 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3644 * are LUSTRE_OPC_ANY
3646 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3647 op_data->op_code = LUSTRE_OPC_ANY;
3649 op_data->op_code = opc;
3650 op_data->op_name = fname.disk_name.name;
3651 op_data->op_namelen = fname.disk_name.len;
3652 op_data->op_mode = mode;
3653 op_data->op_mod_time = ktime_get_real_seconds();
3654 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3655 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3656 op_data->op_cap = current_cap();
3657 op_data->op_mds = 0;
3658 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3659 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3660 op_data->op_bias |= MDS_CREATE_VOLATILE;
3662 op_data->op_data = data;
3667 void ll_finish_md_op_data(struct md_op_data *op_data)
3669 ll_unlock_md_op_lsm(op_data);
3670 ll_security_release_secctx(op_data->op_file_secctx,
3671 op_data->op_file_secctx_size);
3672 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3673 /* allocated via ll_setup_filename called
3674 * from ll_prep_md_op_data
3676 kfree(op_data->op_name);
3677 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3678 OBD_FREE_PTR(op_data);
3681 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3683 struct ll_sb_info *sbi;
3686 LASSERT(seq && dentry);
3687 sbi = ll_s2sbi(dentry->d_sb);
3689 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3690 seq_puts(seq, "nolock");
3692 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3693 /* match_table in some cases has patterns for both enabled and
3694 * disabled cases. Ignore 'no'xxx versions if bit is set.
3696 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3697 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3698 if (ll_sbi_flags_name[i].token ==
3699 LL_SBI_FOREIGN_SYMLINK) {
3700 seq_show_option(seq, "foreign_symlink",
3701 sbi->ll_foreign_symlink_prefix);
3703 seq_printf(seq, ",%s",
3704 ll_sbi_flags_name[i].pattern);
3707 /* You can have either localflock or flock but not
3708 * both. If localflock is set don't print flock or
3711 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3713 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3714 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3715 seq_printf(seq, ",%s",
3716 ll_sbi_flags_name[i].pattern);
3720 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3726 * Get obd name by cmd, and copy out to user space
3728 int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg)
3730 struct ll_sb_info *sbi = ll_i2sbi(inode);
3731 struct obd_device *obd;
3734 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3735 obd = class_exp2obd(sbi->ll_dt_exp);
3736 else if (cmd == OBD_IOC_GETMDNAME)
3737 obd = class_exp2obd(sbi->ll_md_exp);
3744 if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1))
3751 struct work_struct db_work;
3752 struct dentry *db_dentry;
3753 /* Let's hope the path is not too long, 32 bytes for the work struct
3756 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3759 static void ll_dput_later(struct work_struct *work)
3761 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3763 dput(db->db_dentry);
3764 free_page((unsigned long)db);
3767 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3774 p.mnt = current->fs->root.mnt;
3776 path = d_path(&p, buf, bufsize);
3781 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3783 struct dname_buf *db;
3785 struct dentry *dentry = NULL;
3787 /* this can be called inside spin lock so use GFP_ATOMIC. */
3788 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3791 dentry = d_find_alias(inode);
3793 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3796 /* The below message is checked in recovery-small.sh test_24b */
3798 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3799 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3800 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3801 PFID(ll_inode2fid(inode)),
3802 (path && !IS_ERR(path)) ? path : "", ioret);
3804 if (dentry != NULL) {
3805 /* We cannot dput here since if we happen to be the last holder
3806 * then we can end up waiting for page evictions that
3807 * in turn wait for RPCs that need this instance of ptlrpcd
3808 * (callng brw_interpret->*page_completion*->vmpage_error->here)
3811 INIT_WORK(&db->db_work, ll_dput_later);
3812 db->db_dentry = dentry;
3813 schedule_work(&db->db_work);
3816 free_page((unsigned long)db);
3820 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3821 struct lov_user_md **kbuf)
3823 struct lov_user_md lum;
3827 if (copy_from_user(&lum, md, sizeof(lum)))
3830 lum_size = ll_lov_user_md_size(&lum);
3834 OBD_ALLOC_LARGE(*kbuf, lum_size);
3838 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3839 OBD_FREE_LARGE(*kbuf, lum_size);
3847 * Compute llite root squash state after a change of root squash
3848 * configuration setting or add/remove of a lnet nid
3850 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3852 struct root_squash_info *squash = &sbi->ll_squash;
3855 struct lnet_processid id;
3857 /* Update norootsquash flag */
3858 spin_lock(&squash->rsi_lock);
3859 if (list_empty(&squash->rsi_nosquash_nids))
3860 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3862 /* Do not apply root squash as soon as one of our NIDs is
3863 * in the nosquash_nids list */
3866 while (LNetGetId(i++, &id) != -ENOENT) {
3867 if (nid_is_lo0(&id.nid))
3869 if (cfs_match_nid(&id.nid,
3870 &squash->rsi_nosquash_nids)) {
3876 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3878 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3880 spin_unlock(&squash->rsi_lock);
3884 * Parse linkea content to extract information about a given hardlink
3886 * \param[in] ldata - Initialized linkea data
3887 * \param[in] linkno - Link identifier
3888 * \param[out] parent_fid - The entry's parent FID
3889 * \param[out] ln - Entry name destination buffer
3891 * \retval 0 on success
3892 * \retval Appropriate negative error code on failure
3894 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3895 struct lu_fid *parent_fid, struct lu_name *ln)
3901 rc = linkea_init_with_rec(ldata);
3905 if (linkno >= ldata->ld_leh->leh_reccount)
3906 /* beyond last link */
3909 linkea_first_entry(ldata);
3910 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3911 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3916 linkea_next_entry(ldata);
3926 * Get parent FID and name of an identified link. Operation is performed for
3927 * a given link number, letting the caller iterate over linkno to list one or
3928 * all links of an entry.
3930 * \param[in] file - File descriptor against which to perform the operation
3931 * \param[in,out] arg - User-filled structure containing the linkno to operate
3932 * on and the available size. It is eventually filled with
3933 * the requested information or left untouched on error
3935 * \retval - 0 on success
3936 * \retval - Appropriate negative error code on failure
3938 int ll_getparent(struct file *file, struct getparent __user *arg)
3940 struct inode *inode = file_inode(file);
3941 struct linkea_data *ldata;
3942 struct lu_buf buf = LU_BUF_NULL;
3944 struct lu_fid parent_fid;
3951 if (!capable(CAP_DAC_READ_SEARCH) &&
3952 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
3955 if (get_user(name_size, &arg->gp_name_size))
3958 if (get_user(linkno, &arg->gp_linkno))
3961 if (name_size > PATH_MAX)
3964 OBD_ALLOC(ldata, sizeof(*ldata));
3968 rc = linkea_data_new(ldata, &buf);
3970 GOTO(ldata_free, rc);
3972 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3973 buf.lb_len, OBD_MD_FLXATTR);
3977 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3981 if (ln.ln_namelen >= name_size)
3982 GOTO(lb_free, rc = -EOVERFLOW);
3984 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3985 GOTO(lb_free, rc = -EFAULT);
3987 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3988 GOTO(lb_free, rc = -EFAULT);
3990 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3991 GOTO(lb_free, rc = -EFAULT);
3996 OBD_FREE(ldata, sizeof(*ldata));