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/delay.h>
40 #include <linux/file.h>
41 #include <linux/fs_struct.h>
43 #include <linux/module.h>
44 #include <linux/random.h>
45 #include <linux/statfs.h>
46 #include <linux/time.h>
47 #include <linux/types.h>
48 #include <linux/uaccess.h>
49 #include <linux/uidgid.h>
50 #include <linux/user_namespace.h>
51 #include <linux/uuid.h>
52 #include <linux/version.h>
53 #ifdef HAVE_FILEATTR_GET
54 #include <linux/fileattr.h>
57 #ifndef HAVE_CPUS_READ_LOCK
58 #include <libcfs/linux/linux-cpu.h>
60 #include <libcfs/linux/linux-misc.h>
61 #include <uapi/linux/lustre/lustre_ioctl.h>
62 #ifdef HAVE_UAPI_LINUX_MOUNT_H
63 #include <uapi/linux/mount.h>
66 #include <lustre_ha.h>
67 #include <lustre_dlm.h>
68 #include <lprocfs_status.h>
69 #include <lustre_disk.h>
70 #include <uapi/linux/lustre/lustre_param.h>
71 #include <lustre_log.h>
72 #include <cl_object.h>
73 #include <obd_cksum.h>
74 #include "llite_internal.h"
76 struct kmem_cache *ll_file_data_slab;
79 #define log2(n) ffz(~(n))
83 * If there is only one number of core visible to Lustre,
84 * async readahead will be disabled, to avoid massive over
85 * subscription, we use 1/2 of active cores as default max
86 * async readahead requests.
88 static inline unsigned int ll_get_ra_async_max_active(void)
90 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
93 static struct ll_sb_info *ll_init_sbi(struct lustre_sb_info *lsi)
95 struct ll_sb_info *sbi = NULL;
97 unsigned long lru_page_max;
105 RETURN(ERR_PTR(-ENOMEM));
107 rc = pcc_super_init(&sbi->ll_pcc_super);
111 spin_lock_init(&sbi->ll_lock);
112 mutex_init(&sbi->ll_lco.lco_lock);
113 spin_lock_init(&sbi->ll_pp_extent_lock);
114 spin_lock_init(&sbi->ll_process_lock);
116 sbi->ll_rw_stats_on = 0;
117 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
120 pages = si.totalram - si.totalhigh;
121 lru_page_max = pages / 2;
123 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
124 sbi->ll_ra_info.ll_readahead_wq =
125 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
127 sbi->ll_ra_info.ra_async_max_active);
128 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
129 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
131 /* initialize ll_cache data */
132 sbi->ll_cache = cl_cache_init(lru_page_max);
133 if (sbi->ll_cache == NULL)
134 GOTO(out_destroy_ra, rc = -ENOMEM);
136 /* initialize foreign symlink prefix path */
137 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
138 if (sbi->ll_foreign_symlink_prefix == NULL)
139 GOTO(out_destroy_ra, rc = -ENOMEM);
140 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
141 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
143 /* initialize foreign symlink upcall path, none by default */
144 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
145 if (sbi->ll_foreign_symlink_upcall == NULL)
146 GOTO(out_destroy_ra, rc = -ENOMEM);
147 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
148 sbi->ll_foreign_symlink_upcall_items = NULL;
149 sbi->ll_foreign_symlink_upcall_nb_items = 0;
150 init_rwsem(&sbi->ll_foreign_symlink_sem);
151 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
152 * not enabled by default
155 sbi->ll_secctx_name = NULL;
156 sbi->ll_secctx_name_size = 0;
158 sbi->ll_ra_info.ra_max_pages =
159 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
160 sbi->ll_ra_info.ra_max_pages_per_file =
161 min(sbi->ll_ra_info.ra_max_pages / 4,
162 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
163 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
164 sbi->ll_ra_info.ra_max_pages_per_file;
165 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
166 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
167 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
169 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
170 #ifdef ENABLE_CHECKSUM
171 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
174 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
177 #ifdef HAVE_LRU_RESIZE_SUPPORT
178 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
180 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
182 /* metadata statahead is enabled by default */
183 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
184 sbi->ll_sa_batch_max = LL_SA_BATCH_DEF;
185 sbi->ll_sa_max = LL_SA_RPC_DEF;
186 atomic_set(&sbi->ll_sa_total, 0);
187 atomic_set(&sbi->ll_sa_wrong, 0);
188 atomic_set(&sbi->ll_sa_running, 0);
189 atomic_set(&sbi->ll_agl_total, 0);
190 atomic_set(&sbi->ll_sa_hit_total, 0);
191 atomic_set(&sbi->ll_sa_miss_total, 0);
192 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
193 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
194 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
195 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
196 ll_sbi_set_encrypt(sbi, true);
197 ll_sbi_set_name_encrypt(sbi, true);
200 sbi->ll_squash.rsi_uid = 0;
201 sbi->ll_squash.rsi_gid = 0;
202 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
203 spin_lock_init(&sbi->ll_squash.rsi_lock);
205 /* Per-filesystem file heat */
206 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
207 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
209 /* Per-fs open heat level before requesting open lock */
210 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
211 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
212 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
215 if (sbi->ll_foreign_symlink_prefix)
216 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
218 cl_cache_decref(sbi->ll_cache);
219 sbi->ll_cache = NULL;
221 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
223 pcc_super_fini(&sbi->ll_pcc_super);
229 static void ll_free_sbi(struct super_block *sb)
231 struct ll_sb_info *sbi = ll_s2sbi(sb);
235 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
236 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
237 if (sbi->ll_ra_info.ll_readahead_wq)
238 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
239 if (sbi->ll_cache != NULL) {
240 cl_cache_decref(sbi->ll_cache);
241 sbi->ll_cache = NULL;
243 if (sbi->ll_foreign_symlink_prefix) {
244 OBD_FREE(sbi->ll_foreign_symlink_prefix,
245 sbi->ll_foreign_symlink_prefix_size);
246 sbi->ll_foreign_symlink_prefix = NULL;
248 if (sbi->ll_foreign_symlink_upcall) {
249 OBD_FREE(sbi->ll_foreign_symlink_upcall,
250 strlen(sbi->ll_foreign_symlink_upcall) +
252 sbi->ll_foreign_symlink_upcall = NULL;
254 if (sbi->ll_foreign_symlink_upcall_items) {
256 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
257 struct ll_foreign_symlink_upcall_item *items =
258 sbi->ll_foreign_symlink_upcall_items;
260 for (i = 0 ; i < nb_items; i++)
261 if (items[i].type == STRING_TYPE)
262 OBD_FREE(items[i].string,
265 OBD_FREE_LARGE(items, nb_items *
266 sizeof(struct ll_foreign_symlink_upcall_item));
267 sbi->ll_foreign_symlink_upcall_items = NULL;
269 if (sbi->ll_secctx_name)
270 ll_secctx_name_free(sbi);
272 ll_free_rw_stats_info(sbi);
273 pcc_super_fini(&sbi->ll_pcc_super);
274 OBD_FREE(sbi, sizeof(*sbi));
279 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
281 struct inode *root = NULL;
282 struct ll_sb_info *sbi = ll_s2sbi(sb);
283 struct obd_statfs *osfs = NULL;
284 struct ptlrpc_request *request = NULL;
285 struct obd_connect_data *data = NULL;
286 struct obd_uuid *uuid;
287 struct md_op_data *op_data;
288 struct lustre_md lmd;
290 int size, err, checksum;
296 sbi->ll_md_obd = class_name2obd(md);
297 if (!sbi->ll_md_obd) {
298 CERROR("MD %s: not setup or attached\n", md);
312 /* pass client page size via ocd_grant_blkbits, the server should report
313 * back its backend blocksize for grant calculation purpose */
314 data->ocd_grant_blkbits = PAGE_SHIFT;
316 /* indicate MDT features supported by this client */
317 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
318 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
319 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
320 OBD_CONNECT_SRVLOCK |
321 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
322 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
323 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
324 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
325 OBD_CONNECT_64BITHASH |
326 OBD_CONNECT_EINPROGRESS |
327 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
328 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
329 OBD_CONNECT_MAX_EASIZE |
330 OBD_CONNECT_FLOCK_DEAD |
331 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
332 OBD_CONNECT_OPEN_BY_FID |
333 OBD_CONNECT_DIR_STRIPE |
334 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
335 OBD_CONNECT_SUBTREE |
336 OBD_CONNECT_MULTIMODRPCS |
337 OBD_CONNECT_GRANT_PARAM |
338 OBD_CONNECT_GRANT_SHRINK |
339 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
341 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
342 OBD_CONNECT2_SUM_STATFS |
343 OBD_CONNECT2_OVERSTRIPING |
345 OBD_CONNECT2_LOCK_CONVERT |
346 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
347 OBD_CONNECT2_INC_XID |
349 OBD_CONNECT2_ASYNC_DISCARD |
351 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
352 OBD_CONNECT2_GETATTR_PFID |
353 OBD_CONNECT2_DOM_LVB |
354 OBD_CONNECT2_REP_MBITS |
355 OBD_CONNECT2_ATOMIC_OPEN_LOCK |
356 OBD_CONNECT2_BATCH_RPC;
358 #ifdef HAVE_LRU_RESIZE_SUPPORT
359 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
360 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
362 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
364 data->ocd_cksum_types = obd_cksum_types_supported_client();
366 if (CFS_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
367 /* flag mdc connection as lightweight, only used for test
368 * purpose, use with care */
369 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
371 data->ocd_ibits_known = MDS_INODELOCK_FULL;
372 data->ocd_version = LUSTRE_VERSION_CODE;
374 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
375 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
378 /* Setting this indicates we correctly support S_NOSEC (See kernel
379 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
381 sb->s_flags |= SB_NOSEC;
383 sbi->ll_fop = ll_select_file_operations(sbi);
385 /* always ping even if server suppress_pings */
386 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
387 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
389 obd_connect_set_secctx(data);
390 if (ll_sbi_has_encrypt(sbi)) {
391 obd_connect_set_enc_fid2path(data);
392 obd_connect_set_name_enc(data);
393 obd_connect_set_enc(data);
396 #if defined(CONFIG_SECURITY)
397 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
400 data->ocd_brw_size = MD_MAX_BRW_SIZE;
403 if (sb->s_flags & SB_RDONLY)
404 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
405 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
406 &sbi->ll_sb_uuid, data, sbi->ll_cache);
408 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
409 "recovery, of which this client is not a "
410 "part. Please wait for recovery to complete,"
411 " abort, or time out.\n", md);
414 CERROR("cannot connect to %s: rc = %d\n", md, err);
418 sbi->ll_md_exp->exp_connect_data = *data;
420 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
421 LUSTRE_SEQ_METADATA);
423 CERROR("%s: Can't init metadata layer FID infrastructure, "
424 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
428 /* For mount, we only need fs info from MDT0, and also in DNE, it
429 * can make sure the client can be mounted as long as MDT0 is
431 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
432 ktime_get_seconds() - sbi->ll_statfs_max_age,
433 OBD_STATFS_FOR_MDT0);
434 if (err == -EROFS && !(sb->s_flags & SB_RDONLY)) {
435 /* We got -EROFS from the server, maybe it is imposing
436 * read-only mount. So just retry like this.
438 cfs_tty_write_msg("Forcing read-only mount.\n\r");
439 CERROR("%s: mount failed with %d, forcing read-only mount.\n",
440 sbi->ll_md_exp->exp_obd->obd_name, err);
441 sb->s_flags |= SB_RDONLY;
442 obd_fid_fini(sbi->ll_md_exp->exp_obd);
443 obd_disconnect(sbi->ll_md_exp);
444 GOTO(retry_connect, err);
446 GOTO(out_md_fid, err);
449 /* This needs to be after statfs to ensure connect has finished.
450 * Note that "data" does NOT contain the valid connect reply.
451 * If connecting to a 1.8 server there will be no LMV device, so
452 * we can access the MDC export directly and exp_connect_flags will
453 * be non-zero, but if accessing an upgraded 2.1 server it will
454 * have the correct flags filled in.
455 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
456 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
457 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
458 valid != CLIENT_CONNECT_MDT_REQD) {
461 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
462 obd_connect_flags2str(buf, PAGE_SIZE,
463 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
464 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
465 "feature(s) needed for correct operation "
466 "of this client (%s). Please upgrade "
467 "server or downgrade client.\n",
468 sbi->ll_md_exp->exp_obd->obd_name, buf);
469 OBD_FREE(buf, PAGE_SIZE);
470 GOTO(out_md_fid, err = -EPROTO);
473 size = sizeof(*data);
474 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
475 KEY_CONN_DATA, &size, data);
477 CERROR("%s: Get connect data failed: rc = %d\n",
478 sbi->ll_md_exp->exp_obd->obd_name, err);
479 GOTO(out_md_fid, err);
482 LASSERT(osfs->os_bsize);
483 sb->s_blocksize = osfs->os_bsize;
484 sb->s_blocksize_bits = log2(osfs->os_bsize);
485 sb->s_magic = LL_SUPER_MAGIC;
486 sb->s_maxbytes = MAX_LFS_FILESIZE;
487 sbi->ll_inode_cache_enabled = 1;
488 sbi->ll_namelen = osfs->os_namelen;
489 sbi->ll_mnt.mnt = current->fs->root.mnt;
490 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
492 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
493 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
494 LCONSOLE_INFO("Disabling user_xattr feature because "
495 "it is not supported on the server\n");
496 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
499 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
501 sb->s_flags |= SB_POSIXACL;
503 set_bit(LL_SBI_ACL, sbi->ll_flags);
505 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
507 sb->s_flags &= ~SB_POSIXACL;
509 clear_bit(LL_SBI_ACL, sbi->ll_flags);
512 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
513 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
515 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
516 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
518 if (obd_connect_has_secctx(data))
519 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
521 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
522 if (ll_sb_has_test_dummy_encryption(sb))
523 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
525 sbi->ll_md_exp->exp_obd->obd_name);
526 ll_sbi_set_encrypt(sbi, false);
529 if (ll_sbi_has_name_encrypt(sbi) && !obd_connect_has_name_enc(data)) {
530 struct lustre_sb_info *lsi = s2lsi(sb);
532 if (ll_sb_has_test_dummy_encryption(sb))
533 LCONSOLE_WARN("%s: server %s does not support name encryption, not using it.\n",
535 sbi->ll_md_exp->exp_obd->obd_name);
536 #ifdef CONFIG_LL_ENCRYPTION
537 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
539 lsi->lsi_flags &= ~LSI_FILENAME_ENC_B64_OLD_CLI;
540 ll_sbi_set_name_encrypt(sbi, false);
543 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
544 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
545 LCONSOLE_INFO("%s: disabling xattr cache due to "
546 "unknown maximum xattr size.\n", dt);
547 } else if (!sbi->ll_xattr_cache_set) {
548 /* If xattr_cache is already set (no matter 0 or 1)
549 * during processing llog, it won't be enabled here. */
550 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
551 sbi->ll_xattr_cache_enabled = 1;
555 sbi->ll_dt_obd = class_name2obd(dt);
556 if (!sbi->ll_dt_obd) {
557 CERROR("DT %s: not setup or attached\n", dt);
558 GOTO(out_md_fid, err = -ENODEV);
561 /* pass client page size via ocd_grant_blkbits, the server should report
562 * back its backend blocksize for grant calculation purpose */
563 data->ocd_grant_blkbits = PAGE_SHIFT;
565 /* indicate OST features supported by this client */
566 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
567 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
568 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
569 OBD_CONNECT_SRVLOCK |
570 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
571 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
572 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
573 OBD_CONNECT_EINPROGRESS |
574 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
575 OBD_CONNECT_LAYOUTLOCK |
576 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
577 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
578 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
579 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
580 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
581 OBD_CONNECT2_REP_MBITS;
583 if (!CFS_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
584 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
586 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
587 * disabled by default, because it can still be enabled on the
588 * fly via /sys. As a consequence, we still need to come to an
589 * agreement on the supported algorithms at connect time
591 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
593 if (CFS_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
594 data->ocd_cksum_types = OBD_CKSUM_ADLER;
596 data->ocd_cksum_types = obd_cksum_types_supported_client();
598 #ifdef HAVE_LRU_RESIZE_SUPPORT
599 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
601 /* always ping even if server suppress_pings */
602 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
603 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
605 if (ll_sbi_has_encrypt(sbi))
606 obd_connect_set_enc(data);
608 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
609 "ocd_grant: %d\n", data->ocd_connect_flags,
610 data->ocd_version, data->ocd_grant);
612 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
613 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
615 data->ocd_brw_size = DT_MAX_BRW_SIZE;
617 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
618 &sbi->ll_sb_uuid, data, sbi->ll_cache);
620 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
621 "recovery, of which this client is not a "
622 "part. Please wait for recovery to "
623 "complete, abort, or time out.\n", dt);
626 CERROR("%s: Cannot connect to %s: rc = %d\n",
627 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
631 if (ll_sbi_has_encrypt(sbi) &&
632 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
633 if (ll_sb_has_test_dummy_encryption(sb))
634 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
636 ll_sbi_set_encrypt(sbi, false);
637 } else if (ll_sb_has_test_dummy_encryption(sb)) {
638 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
641 sbi->ll_dt_exp->exp_connect_data = *data;
643 /* Don't change value if it was specified in the config log */
644 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
645 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
646 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
647 (data->ocd_brw_size >> PAGE_SHIFT));
648 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
649 sbi->ll_ra_info.ra_max_pages_per_file)
650 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
651 sbi->ll_ra_info.ra_max_pages_per_file;
654 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
655 LUSTRE_SEQ_METADATA);
657 CERROR("%s: Can't init data layer FID infrastructure, "
658 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
662 mutex_lock(&sbi->ll_lco.lco_lock);
663 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
664 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
665 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
666 mutex_unlock(&sbi->ll_lco.lco_lock);
668 fid_zero(&sbi->ll_root_fid);
669 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
672 CERROR("cannot mds_connect: rc = %d\n", err);
673 GOTO(out_lock_cn_cb, err);
675 if (!fid_is_sane(&sbi->ll_root_fid)) {
676 CERROR("%s: Invalid root fid "DFID" during mount\n",
677 sbi->ll_md_exp->exp_obd->obd_name,
678 PFID(&sbi->ll_root_fid));
679 GOTO(out_lock_cn_cb, err = -EINVAL);
681 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
683 sb->s_op = &lustre_super_operations;
684 sb->s_xattr = ll_xattr_handlers;
685 #if THREAD_SIZE >= 8192 /*b=17630*/
686 sb->s_export_op = &lustre_export_operations;
688 #ifdef HAVE_LUSTRE_CRYPTO
689 llcrypt_set_ops(sb, &lustre_cryptops);
693 * XXX: move this to after cbd setup? */
694 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
696 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
697 valid |= OBD_MD_FLACL;
699 OBD_ALLOC_PTR(op_data);
701 GOTO(out_lock_cn_cb, err = -ENOMEM);
703 op_data->op_fid1 = sbi->ll_root_fid;
704 op_data->op_mode = 0;
705 op_data->op_valid = valid;
707 err = md_getattr(sbi->ll_md_exp, op_data, &request);
709 /* We need enc ctx info, so reset it in op_data to
710 * prevent it from being freed.
712 encctx = op_data->op_file_encctx;
713 encctxlen = op_data->op_file_encctx_size;
714 op_data->op_file_encctx = NULL;
715 op_data->op_file_encctx_size = 0;
716 OBD_FREE_PTR(op_data);
718 CERROR("%s: md_getattr failed for root: rc = %d\n",
719 sbi->ll_md_exp->exp_obd->obd_name, err);
720 GOTO(out_lock_cn_cb, err);
723 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
724 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
726 CERROR("failed to understand root inode md: rc = %d\n", err);
727 ptlrpc_req_finished(request);
728 GOTO(out_lock_cn_cb, err);
731 LASSERT(fid_is_sane(&sbi->ll_root_fid));
732 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
733 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
734 md_free_lustre_md(sbi->ll_md_exp, &lmd);
738 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
740 CERROR("%s: bad ll_iget() for root: rc = %d\n",
741 sbi->ll_fsname, err);
742 ptlrpc_req_finished(request);
746 err = ll_secctx_name_store(root);
747 if (err < 0 && ll_security_xattr_wanted(root))
748 CWARN("%s: file security contextes not supported: rc = %d\n",
749 sbi->ll_fsname, err);
754 "server returned encryption ctx for root inode "DFID"\n",
755 PFID(&sbi->ll_root_fid));
756 err = ll_set_encflags(root, encctx, encctxlen, true);
758 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
760 PFID(&sbi->ll_root_fid), err);
762 ptlrpc_req_finished(request);
764 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
765 if (sbi->ll_checksum_set) {
766 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
767 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
768 sizeof(checksum), &checksum, NULL);
770 CERROR("%s: Set checksum failed: rc = %d\n",
771 sbi->ll_dt_exp->exp_obd->obd_name, err);
777 sb->s_root = d_make_root(root);
778 if (sb->s_root == NULL) {
780 CERROR("%s: can't make root dentry: rc = %d\n",
781 sbi->ll_fsname, err);
785 sbi->ll_sdev_orig = sb->s_dev;
787 /* We set sb->s_dev equal on all lustre clients in order to support
788 * NFS export clustering. NFSD requires that the FSID be the same
790 /* s_dev is also used in lt_compare() to compare two fs, but that is
791 * only a node-local comparison. */
792 uuid = obd_get_uuid(sbi->ll_md_exp);
794 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
801 if (sbi->ll_dt_obd) {
802 err = sysfs_create_link(&sbi->ll_kset.kobj,
803 &sbi->ll_dt_obd->obd_kset.kobj,
804 sbi->ll_dt_obd->obd_type->typ_name);
806 CERROR("%s: could not register %s in llite: rc = %d\n",
807 dt, sbi->ll_fsname, err);
812 if (sbi->ll_md_obd) {
813 err = sysfs_create_link(&sbi->ll_kset.kobj,
814 &sbi->ll_md_obd->obd_kset.kobj,
815 sbi->ll_md_obd->obd_type->typ_name);
817 CERROR("%s: could not register %s in llite: rc = %d\n",
818 md, sbi->ll_fsname, err);
827 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
829 obd_disconnect(sbi->ll_dt_exp);
830 sbi->ll_dt_exp = NULL;
831 sbi->ll_dt_obd = NULL;
833 obd_fid_fini(sbi->ll_md_exp->exp_obd);
835 obd_disconnect(sbi->ll_md_exp);
836 sbi->ll_md_exp = NULL;
837 sbi->ll_md_obd = NULL;
846 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
850 size = sizeof(*lmmsize);
851 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
852 KEY_MAX_EASIZE, &size, lmmsize);
854 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
855 sbi->ll_dt_exp->exp_obd->obd_name, rc);
859 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
862 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
863 KEY_MAX_EASIZE, &size, lmmsize);
865 CERROR("Get max mdsize error rc %d\n", rc);
867 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
873 * Get the value of the default_easize parameter.
875 * \see client_obd::cl_default_mds_easize
877 * \param[in] sbi superblock info for this filesystem
878 * \param[out] lmmsize pointer to storage location for value
880 * \retval 0 on success
881 * \retval negative negated errno on failure
883 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
888 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
889 KEY_DEFAULT_EASIZE, &size, lmmsize);
891 CERROR("Get default mdsize error rc %d\n", rc);
897 * Set the default_easize parameter to the given value.
899 * \see client_obd::cl_default_mds_easize
901 * \param[in] sbi superblock info for this filesystem
902 * \param[in] lmmsize the size to set
904 * \retval 0 on success
905 * \retval negative negated errno on failure
907 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
911 if (lmmsize < sizeof(struct lov_mds_md) ||
912 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
915 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
916 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
917 sizeof(int), &lmmsize, NULL);
922 static void client_common_put_super(struct super_block *sb)
924 struct ll_sb_info *sbi = ll_s2sbi(sb);
929 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
930 obd_disconnect(sbi->ll_dt_exp);
931 sbi->ll_dt_exp = NULL;
933 ll_debugfs_unregister_super(sb);
935 obd_fid_fini(sbi->ll_md_exp->exp_obd);
936 obd_disconnect(sbi->ll_md_exp);
937 sbi->ll_md_exp = NULL;
942 void ll_kill_super(struct super_block *sb)
944 struct ll_sb_info *sbi;
948 if (!(sb->s_flags & SB_ACTIVE))
952 /* we need restore s_dev from changed for clustred NFS before put_super
953 * because new kernels have cached s_dev and change sb->s_dev in
954 * put_super not affected real removing devices */
956 sb->s_dev = sbi->ll_sdev_orig;
958 /* wait running statahead threads to quit */
959 while (atomic_read(&sbi->ll_sa_running) > 0)
960 schedule_timeout_uninterruptible(
961 cfs_time_seconds(1) >> 3);
967 /* Since we use this table for ll_sbi_flags_seq_show make
968 * sure what you want displayed for a specific token that
969 * is listed more than once below be listed first. For
970 * example we want "checksum" displayed, not "nochecksum"
973 static const match_table_t ll_sbi_flags_name = {
974 {LL_SBI_NOLCK, "nolock"},
975 {LL_SBI_CHECKSUM, "checksum"},
976 {LL_SBI_CHECKSUM, "nochecksum"},
977 {LL_SBI_LOCALFLOCK, "localflock"},
978 {LL_SBI_FLOCK, "flock"},
979 {LL_SBI_FLOCK, "noflock"},
980 {LL_SBI_USER_XATTR, "user_xattr"},
981 {LL_SBI_USER_XATTR, "nouser_xattr"},
982 {LL_SBI_LRU_RESIZE, "lruresize"},
983 {LL_SBI_LRU_RESIZE, "nolruresize"},
984 {LL_SBI_LAZYSTATFS, "lazystatfs"},
985 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
986 {LL_SBI_32BIT_API, "32bitapi"},
987 {LL_SBI_USER_FID2PATH, "user_fid2path"},
988 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
989 {LL_SBI_VERBOSE, "verbose"},
990 {LL_SBI_VERBOSE, "noverbose"},
991 {LL_SBI_ALWAYS_PING, "always_ping"},
992 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
993 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
994 {LL_SBI_ENCRYPT, "encrypt"},
995 {LL_SBI_ENCRYPT, "noencrypt"},
996 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
997 {LL_SBI_NUM_MOUNT_OPT, NULL},
1000 {LL_SBI_AGL_ENABLED, "agl"},
1001 {LL_SBI_64BIT_HASH, "64bit_hash"},
1002 {LL_SBI_LAYOUT_LOCK, "layout"},
1003 {LL_SBI_XATTR_CACHE, "xattr_cache"},
1004 {LL_SBI_NOROOTSQUASH, "norootsquash"},
1005 {LL_SBI_FAST_READ, "fast_read"},
1006 {LL_SBI_FILE_SECCTX, "file_secctx"},
1007 {LL_SBI_TINY_WRITE, "tiny_write"},
1008 {LL_SBI_FILE_HEAT, "file_heat"},
1009 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
1010 {LL_SBI_ENCRYPT_NAME, "name_encrypt"},
1013 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
1015 struct super_block *sb = m->private;
1018 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
1021 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
1024 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
1025 if (ll_sbi_flags_name[j].token == i &&
1026 ll_sbi_flags_name[j].pattern) {
1027 seq_printf(m, "%s ",
1028 ll_sbi_flags_name[j].pattern);
1033 seq_puts(m, "\b\n");
1037 /* non-client-specific mount options are parsed in lmd_parse */
1038 static int ll_options(char *options, struct super_block *sb)
1040 struct ll_sb_info *sbi = ll_s2sbi(sb);
1041 char *s2, *s1, *opts;
1048 /* Don't stomp on lmd_opts */
1049 opts = kstrdup(options, GFP_KERNEL);
1055 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1057 while ((s1 = strsep(&opts, ",")) != NULL) {
1058 substring_t args[MAX_OPT_ARGS];
1059 bool turn_off = false;
1065 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1067 if (strncmp(s1, "no", 2) == 0)
1071 * Initialize args struct so we know whether arg was
1072 * found; some options take optional arguments.
1075 args[0].from = NULL;
1076 token = match_token(s1, ll_sbi_flags_name, args);
1077 if (token == LL_SBI_NUM_MOUNT_OPT) {
1078 if (match_wildcard("context", s1) ||
1079 match_wildcard("fscontext", s1) ||
1080 match_wildcard("defcontext", s1) ||
1081 match_wildcard("rootcontext",s1))
1084 LCONSOLE_ERROR_MSG(0x152,
1085 "Unknown option '%s', won't mount.\n",
1092 case LL_SBI_32BIT_API:
1093 case LL_SBI_64BIT_HASH:
1094 case LL_SBI_ALWAYS_PING:
1095 set_bit(token, sbi->ll_flags);
1099 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1101 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1103 set_bit(token, sbi->ll_flags);
1106 case LL_SBI_LOCALFLOCK:
1107 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1108 set_bit(token, sbi->ll_flags);
1111 case LL_SBI_CHECKSUM:
1112 sbi->ll_checksum_set = 1;
1114 case LL_SBI_USER_XATTR:
1115 case LL_SBI_USER_FID2PATH:
1116 case LL_SBI_LRU_RESIZE:
1117 case LL_SBI_LAZYSTATFS:
1118 case LL_SBI_VERBOSE:
1120 clear_bit(token, sbi->ll_flags);
1122 set_bit(token, sbi->ll_flags);
1124 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1125 #ifdef HAVE_LUSTRE_CRYPTO
1126 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1127 set_bit(token, sbi->ll_flags);
1129 struct lustre_sb_info *lsi = s2lsi(sb);
1131 err = llcrypt_set_test_dummy_encryption(sb,
1132 #ifdef HAVE_FSCRYPT_SET_TEST_DUMMY_ENC_CHAR_ARG
1137 &lsi->lsi_dummy_enc_policy);
1143 "Can't change test_dummy_encryption");
1144 else if (err == -EINVAL)
1146 "Value of option \"%s\" unrecognized",
1150 "Error processing option \"%s\" [%d]",
1155 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1159 case LL_SBI_ENCRYPT:
1160 #ifdef HAVE_LUSTRE_CRYPTO
1162 clear_bit(token, sbi->ll_flags);
1164 set_bit(token, sbi->ll_flags);
1166 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1169 case LL_SBI_FOREIGN_SYMLINK:
1170 /* non-default prefix provided ? */
1175 /* path must be absolute */
1176 if (args->from[0] != '/') {
1177 LCONSOLE_ERROR_MSG(0x152,
1178 "foreign prefix '%s' must be an absolute path\n",
1183 old_len = sbi->ll_foreign_symlink_prefix_size;
1184 old = sbi->ll_foreign_symlink_prefix;
1185 /* alloc for path length and '\0' */
1186 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1187 if (!sbi->ll_foreign_symlink_prefix) {
1188 /* restore previous */
1189 sbi->ll_foreign_symlink_prefix = old;
1190 sbi->ll_foreign_symlink_prefix_size =
1194 sbi->ll_foreign_symlink_prefix_size =
1195 args->to - args->from + 1;
1196 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1197 sbi->ll_foreign_symlink_prefix_size,
1200 OBD_FREE(old, old_len);
1202 /* enable foreign symlink support */
1203 set_bit(token, sbi->ll_flags);
1205 LCONSOLE_ERROR_MSG(0x152,
1206 "invalid %s option\n", s1);
1217 void ll_lli_init(struct ll_inode_info *lli)
1219 lli->lli_inode_magic = LLI_INODE_MAGIC;
1221 rwlock_init(&lli->lli_lock);
1222 lli->lli_posix_acl = NULL;
1223 /* Do not set lli_fid, it has been initialized already. */
1224 fid_zero(&lli->lli_pfid);
1225 lli->lli_mds_read_och = NULL;
1226 lli->lli_mds_write_och = NULL;
1227 lli->lli_mds_exec_och = NULL;
1228 lli->lli_open_fd_read_count = 0;
1229 lli->lli_open_fd_write_count = 0;
1230 lli->lli_open_fd_exec_count = 0;
1231 mutex_init(&lli->lli_och_mutex);
1232 spin_lock_init(&lli->lli_agl_lock);
1233 spin_lock_init(&lli->lli_layout_lock);
1234 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1235 lli->lli_clob = NULL;
1237 init_rwsem(&lli->lli_xattrs_list_rwsem);
1238 mutex_init(&lli->lli_xattrs_enq_lock);
1240 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1241 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1242 lli->lli_opendir_key = NULL;
1243 lli->lli_sai = NULL;
1244 spin_lock_init(&lli->lli_sa_lock);
1245 lli->lli_opendir_pid = 0;
1246 lli->lli_sa_enabled = 0;
1247 init_rwsem(&lli->lli_lsm_sem);
1249 mutex_init(&lli->lli_size_mutex);
1250 mutex_init(&lli->lli_setattr_mutex);
1251 lli->lli_symlink_name = NULL;
1252 ll_trunc_sem_init(&lli->lli_trunc_sem);
1253 range_lock_tree_init(&lli->lli_write_tree);
1254 init_rwsem(&lli->lli_glimpse_sem);
1255 lli->lli_glimpse_time = ktime_set(0, 0);
1256 INIT_LIST_HEAD(&lli->lli_agl_list);
1257 lli->lli_agl_index = 0;
1258 lli->lli_async_rc = 0;
1259 spin_lock_init(&lli->lli_heat_lock);
1260 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1261 lli->lli_heat_flags = 0;
1262 mutex_init(&lli->lli_pcc_lock);
1263 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1264 lli->lli_pcc_inode = NULL;
1265 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1266 lli->lli_pcc_generation = 0;
1267 mutex_init(&lli->lli_group_mutex);
1268 lli->lli_group_users = 0;
1269 lli->lli_group_gid = 0;
1270 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1271 lli->lli_uid = (__u32) -1;
1272 lli->lli_gid = (__u32) -1;
1274 mutex_init(&lli->lli_layout_mutex);
1275 /* ll_cl_context initialize */
1276 INIT_LIST_HEAD(&lli->lli_lccs);
1277 seqlock_init(&lli->lli_page_inv_lock);
1280 #define MAX_STRING_SIZE 128
1282 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1283 #ifndef HAVE_BDI_CAP_MAP_COPY
1284 # define BDI_CAP_MAP_COPY 0
1287 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1289 struct lustre_sb_info *lsi = s2lsi(sb);
1290 char buf[MAX_STRING_SIZE];
1294 err = bdi_init(&lsi->lsi_bdi);
1298 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1299 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1300 lsi->lsi_bdi.name = "lustre";
1301 va_start(args, fmt);
1302 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1304 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1307 sb->s_bdi = &lsi->lsi_bdi;
1311 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1313 int ll_fill_super(struct super_block *sb)
1315 struct lustre_profile *lprof = NULL;
1316 struct lustre_sb_info *lsi = s2lsi(sb);
1317 struct ll_sb_info *sbi = NULL;
1318 char *dt = NULL, *md = NULL;
1319 char *profilenm = get_profile_name(sb);
1320 struct config_llog_instance *cfg;
1321 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1322 const int instlen = LUSTRE_MAXINSTANCE + 2;
1323 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1324 char name[MAX_STRING_SIZE];
1333 /* for ASLR, to map between cfg_instance and hashed ptr */
1334 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1335 profilenm, cfg_instance, sb);
1337 CFS_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1341 GOTO(out_free_cfg, err = -ENOMEM);
1343 /* client additional sb info */
1344 lsi->lsi_llsbi = sbi = ll_init_sbi(lsi);
1346 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1348 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1350 GOTO(out_free_cfg, err);
1352 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1353 #ifdef CONFIG_LL_ENCRYPTION
1354 if (ll_sb_has_test_dummy_encryption(sb))
1355 /* enable filename encryption by default for dummy enc mode */
1356 lsi->lsi_flags |= LSI_FILENAME_ENC;
1358 /* filename encryption is disabled by default */
1359 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1362 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1363 sb->s_d_op = &ll_d_ops;
1366 generate_random_uuid(uuid.b);
1367 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1369 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1372 len = strlen(profilenm);
1373 ptr = strrchr(profilenm, '-');
1374 if (ptr && (strcmp(ptr, "-client") == 0))
1377 if (len > LUSTRE_MAXFSNAME) {
1378 if (unlikely(len >= MAX_STRING_SIZE))
1379 len = MAX_STRING_SIZE - 1;
1380 strncpy(name, profilenm, len);
1382 err = -ENAMETOOLONG;
1383 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1384 name, LUSTRE_MAXFSNAME, err);
1385 GOTO(out_free_cfg, err);
1387 strncpy(sbi->ll_fsname, profilenm, len);
1388 sbi->ll_fsname[len] = '\0';
1391 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1392 profilenm, cfg_instance);
1394 err = super_setup_bdi_name(sb, "%s", name);
1396 GOTO(out_free_cfg, err);
1398 /* disable kernel readahead */
1399 sb->s_bdi->ra_pages = 0;
1400 #ifdef HAVE_BDI_IO_PAGES
1401 sb->s_bdi->io_pages = 0;
1404 /* Call ll_debugfs_register_super() before lustre_process_log()
1405 * so that "llite.*.*" params can be processed correctly.
1407 err = ll_debugfs_register_super(sb, name);
1409 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1410 sbi->ll_fsname, err);
1414 /* The cfg_instance is a value unique to this super, in case some
1415 * joker tries to mount the same fs at two mount points.
1417 cfg->cfg_instance = cfg_instance;
1418 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1419 cfg->cfg_callback = class_config_llog_handler;
1420 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1421 /* set up client obds */
1422 err = lustre_process_log(sb, profilenm, cfg);
1424 GOTO(out_debugfs, err);
1426 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1427 lprof = class_get_profile(profilenm);
1428 if (lprof == NULL) {
1429 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1430 " read from the MGS. Does that filesystem "
1431 "exist?\n", profilenm);
1432 GOTO(out_debugfs, err = -EINVAL);
1434 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1435 lprof->lp_md, lprof->lp_dt);
1437 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1438 OBD_ALLOC(dt, dt_len);
1440 GOTO(out_profile, err = -ENOMEM);
1441 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1443 md_len = strlen(lprof->lp_md) + instlen + 2;
1444 OBD_ALLOC(md, md_len);
1446 GOTO(out_free_dt, err = -ENOMEM);
1447 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1449 /* connections, registrations, sb setup */
1450 err = client_common_fill_super(sb, md, dt);
1452 GOTO(out_free_md, err);
1454 sbi->ll_client_common_fill_super_succeeded = 1;
1458 OBD_FREE(md, md_len);
1461 OBD_FREE(dt, dt_len);
1464 class_put_profile(lprof);
1467 ll_debugfs_unregister_super(sb);
1474 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1475 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1476 sb->s_flags & SB_RDONLY ? " read-only" : "");
1478 } /* ll_fill_super */
1480 void ll_put_super(struct super_block *sb)
1482 struct config_llog_instance cfg, params_cfg;
1483 struct obd_device *obd;
1484 struct lustre_sb_info *lsi = s2lsi(sb);
1485 struct ll_sb_info *sbi = ll_s2sbi(sb);
1486 char *profilenm = get_profile_name(sb);
1487 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1489 int next, force = 1, rc = 0;
1493 GOTO(out_no_sbi, 0);
1495 /* Should replace instance_id with something better for ASLR */
1496 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1497 profilenm, cfg_instance, sb);
1499 cfg.cfg_instance = cfg_instance;
1500 lustre_end_log(sb, profilenm, &cfg);
1502 params_cfg.cfg_instance = cfg_instance;
1503 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1505 if (sbi->ll_md_exp) {
1506 obd = class_exp2obd(sbi->ll_md_exp);
1508 force = obd->obd_force;
1511 /* Wait for unstable pages to be committed to stable storage */
1513 rc = l_wait_event_abortable(
1514 sbi->ll_cache->ccc_unstable_waitq,
1515 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1518 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1519 if (force == 0 && rc != -ERESTARTSYS)
1520 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1522 /* We need to set force before the lov_disconnect in
1523 * lustre_common_put_super, since l_d cleans up osc's as well.
1527 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1529 obd->obd_force = force;
1533 if (sbi->ll_client_common_fill_super_succeeded) {
1534 /* Only if client_common_fill_super succeeded */
1535 client_common_put_super(sb);
1538 /* imitate failed cleanup */
1539 if (CFS_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1543 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1544 class_manual_cleanup(obd);
1547 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1548 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1551 class_del_profile(profilenm);
1553 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1554 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1555 bdi_destroy(&lsi->lsi_bdi);
1556 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1560 llcrypt_free_dummy_policy(&lsi->lsi_dummy_enc_policy);
1562 lsi->lsi_llsbi = NULL;
1564 lustre_common_put_super(sb);
1566 cl_env_cache_purge(~0);
1569 } /* client_put_super */
1571 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1573 struct inode *inode = NULL;
1575 /* NOTE: we depend on atomic igrab() -bzzz */
1576 lock_res_and_lock(lock);
1577 if (lock->l_resource->lr_lvb_inode) {
1578 struct ll_inode_info * lli;
1579 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1580 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1581 inode = igrab(lock->l_resource->lr_lvb_inode);
1583 inode = lock->l_resource->lr_lvb_inode;
1584 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1585 D_WARNING, lock, "lr_lvb_inode %p is "
1586 "bogus: magic %08x",
1587 lock->l_resource->lr_lvb_inode,
1588 lli->lli_inode_magic);
1592 unlock_res_and_lock(lock);
1596 void ll_dir_clear_lsm_md(struct inode *inode)
1598 struct ll_inode_info *lli = ll_i2info(inode);
1600 LASSERT(S_ISDIR(inode->i_mode));
1602 if (lli->lli_lsm_md) {
1603 lmv_free_memmd(lli->lli_lsm_md);
1604 lli->lli_lsm_md = NULL;
1607 if (lli->lli_default_lsm_md) {
1608 lmv_free_memmd(lli->lli_default_lsm_md);
1609 lli->lli_default_lsm_md = NULL;
1613 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1614 const struct lu_fid *fid,
1615 struct lustre_md *md)
1617 struct ll_sb_info *sbi = ll_s2sbi(sb);
1618 struct ll_inode_info *lli;
1619 struct mdt_body *body = md->body;
1620 struct inode *inode;
1626 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1627 inode = iget_locked(sb, ino);
1628 if (inode == NULL) {
1629 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1630 sbi->ll_fsname, PFID(fid));
1631 RETURN(ERR_PTR(-ENOENT));
1634 lli = ll_i2info(inode);
1635 if (inode->i_state & I_NEW) {
1636 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1637 (body->mbo_mode & S_IFMT);
1638 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1641 inode->i_mtime.tv_sec = 0;
1642 inode->i_atime.tv_sec = 0;
1643 inode->i_ctime.tv_sec = 0;
1646 #ifdef HAVE_BACKING_DEV_INFO
1647 /* initializing backing dev info. */
1648 inode->i_mapping->backing_dev_info =
1649 &s2lsi(inode->i_sb)->lsi_bdi;
1651 inode->i_op = &ll_dir_inode_operations;
1652 inode->i_fop = &ll_dir_operations;
1653 lli->lli_fid = *fid;
1656 /* master object FID */
1657 lli->lli_pfid = body->mbo_fid1;
1658 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1659 lli, PFID(fid), PFID(&lli->lli_pfid));
1660 unlock_new_inode(inode);
1662 /* in directory restripe/auto-split, a directory will be
1663 * transformed to a stripe if it's plain, set its pfid here,
1664 * otherwise ll_lock_cancel_bits() can't find the master inode.
1666 lli->lli_pfid = body->mbo_fid1;
1672 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1675 struct lmv_stripe_md *lsm = md->lmv;
1676 struct ll_inode_info *lli = ll_i2info(inode);
1679 LASSERT(lsm != NULL);
1681 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1682 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1683 lsm_md_dump(D_INODE, lsm);
1685 if (!lmv_dir_striped(lsm))
1688 /* XXX sigh, this lsm_root initialization should be in
1689 * LMV layer, but it needs ll_iget right now, so we
1690 * put this here right now. */
1691 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1692 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1693 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1695 if (!fid_is_sane(fid))
1698 /* Unfortunately ll_iget will call ll_update_inode,
1699 * where the initialization of slave inode is slightly
1700 * different, so it reset lsm_md to NULL to avoid
1701 * initializing lsm for slave inode. */
1702 lsm->lsm_md_oinfo[i].lmo_root =
1703 ll_iget_anon_dir(inode->i_sb, fid, md);
1704 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1705 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1707 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1709 iput(lsm->lsm_md_oinfo[i].lmo_root);
1710 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1716 lli->lli_lsm_md = lsm;
1721 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1723 struct ll_inode_info *lli = ll_i2info(inode);
1727 if (!md->default_lmv) {
1728 /* clear default lsm */
1729 if (lli->lli_default_lsm_md) {
1730 down_write(&lli->lli_lsm_sem);
1731 if (lli->lli_default_lsm_md) {
1732 lmv_free_memmd(lli->lli_default_lsm_md);
1733 lli->lli_default_lsm_md = NULL;
1735 lli->lli_inherit_depth = 0;
1736 up_write(&lli->lli_lsm_sem);
1741 if (lli->lli_default_lsm_md) {
1742 /* do nonthing if default lsm isn't changed */
1743 down_read(&lli->lli_lsm_sem);
1744 if (lli->lli_default_lsm_md &&
1745 lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1746 up_read(&lli->lli_lsm_sem);
1749 up_read(&lli->lli_lsm_sem);
1752 down_write(&lli->lli_lsm_sem);
1753 if (lli->lli_default_lsm_md)
1754 lmv_free_memmd(lli->lli_default_lsm_md);
1755 lli->lli_default_lsm_md = md->default_lmv;
1756 lsm_md_dump(D_INODE, md->default_lmv);
1757 md->default_lmv = NULL;
1758 up_write(&lli->lli_lsm_sem);
1762 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1764 struct ll_inode_info *lli = ll_i2info(inode);
1765 struct lmv_stripe_md *lsm = md->lmv;
1766 struct cl_attr *attr;
1771 LASSERT(S_ISDIR(inode->i_mode));
1772 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1773 PFID(ll_inode2fid(inode)));
1775 /* update default LMV */
1776 if (md->default_lmv)
1777 ll_update_default_lsm_md(inode, md);
1779 /* after dir migration/restripe, a stripe may be turned into a
1780 * directory, in this case, zero out its lli_pfid.
1782 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1783 fid_zero(&lli->lli_pfid);
1786 * no striped information from request, lustre_md from req does not
1787 * include stripeEA, see ll_md_setattr()
1793 * normally dir layout doesn't change, only take read lock to check
1794 * that to avoid blocking other MD operations.
1796 down_read(&lli->lli_lsm_sem);
1798 /* some current lookup initialized lsm, and unchanged */
1799 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1800 GOTO(unlock, rc = 0);
1802 /* if dir layout doesn't match, check whether version is increased,
1803 * which means layout is changed, this happens in dir split/merge and
1806 * foreign LMV should not change.
1808 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1809 lsm->lsm_md_layout_version <=
1810 lli->lli_lsm_md->lsm_md_layout_version) {
1811 CERROR("%s: "DFID" dir layout mismatch:\n",
1812 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1813 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1814 lsm_md_dump(D_ERROR, lsm);
1815 GOTO(unlock, rc = -EINVAL);
1818 up_read(&lli->lli_lsm_sem);
1819 down_write(&lli->lli_lsm_sem);
1820 /* clear existing lsm */
1821 if (lli->lli_lsm_md) {
1822 lmv_free_memmd(lli->lli_lsm_md);
1823 lli->lli_lsm_md = NULL;
1826 rc = ll_init_lsm_md(inode, md);
1828 up_write(&lli->lli_lsm_sem);
1832 /* md_merge_attr() may take long, since lsm is already set, switch to
1835 downgrade_write(&lli->lli_lsm_sem);
1837 /* set md->lmv to NULL, so the following free lustre_md will not free
1842 if (!lmv_dir_striped(lli->lli_lsm_md))
1843 GOTO(unlock, rc = 0);
1845 OBD_ALLOC_PTR(attr);
1847 GOTO(unlock, rc = -ENOMEM);
1849 /* validate the lsm */
1850 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1851 ll_md_blocking_ast);
1853 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1854 md->body->mbo_nlink = attr->cat_nlink;
1855 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1856 md->body->mbo_size = attr->cat_size;
1857 if (md->body->mbo_valid & OBD_MD_FLATIME)
1858 md->body->mbo_atime = attr->cat_atime;
1859 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1860 md->body->mbo_ctime = attr->cat_ctime;
1861 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1862 md->body->mbo_mtime = attr->cat_mtime;
1868 up_read(&lli->lli_lsm_sem);
1873 void ll_clear_inode(struct inode *inode)
1875 struct ll_inode_info *lli = ll_i2info(inode);
1876 struct ll_sb_info *sbi = ll_i2sbi(inode);
1880 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1881 PFID(ll_inode2fid(inode)), inode);
1883 if (S_ISDIR(inode->i_mode)) {
1884 /* these should have been cleared in ll_file_release */
1885 LASSERT(lli->lli_opendir_key == NULL);
1886 LASSERT(lli->lli_sai == NULL);
1887 LASSERT(lli->lli_opendir_pid == 0);
1889 pcc_inode_free(inode);
1892 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1894 LASSERT(!lli->lli_open_fd_write_count);
1895 LASSERT(!lli->lli_open_fd_read_count);
1896 LASSERT(!lli->lli_open_fd_exec_count);
1898 if (lli->lli_mds_write_och)
1899 ll_md_real_close(inode, FMODE_WRITE);
1900 if (lli->lli_mds_exec_och)
1901 ll_md_real_close(inode, FMODE_EXEC);
1902 if (lli->lli_mds_read_och)
1903 ll_md_real_close(inode, FMODE_READ);
1905 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1906 OBD_FREE(lli->lli_symlink_name,
1907 strlen(lli->lli_symlink_name) + 1);
1908 lli->lli_symlink_name = NULL;
1911 ll_xattr_cache_destroy(inode);
1913 forget_all_cached_acls(inode);
1915 lli->lli_inode_magic = LLI_INODE_DEAD;
1917 if (S_ISDIR(inode->i_mode))
1918 ll_dir_clear_lsm_md(inode);
1919 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1920 LASSERT(list_empty(&lli->lli_agl_list));
1923 * XXX This has to be done before lsm is freed below, because
1924 * cl_object still uses inode lsm.
1926 cl_inode_fini(inode);
1928 llcrypt_put_encryption_info(inode);
1933 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1935 struct lustre_md md;
1936 struct inode *inode = dentry->d_inode;
1937 struct ll_sb_info *sbi = ll_i2sbi(inode);
1938 struct ptlrpc_request *request = NULL;
1943 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1944 LUSTRE_OPC_ANY, NULL);
1945 if (IS_ERR(op_data))
1946 RETURN(PTR_ERR(op_data));
1948 /* If this is a chgrp of a regular file, we want to reserve enough
1949 * quota to cover the entire file size.
1951 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1952 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1953 from_kgid(&init_user_ns, inode->i_gid)) {
1954 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1955 op_data->op_attr_blocks = inode->i_blocks;
1959 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1961 ptlrpc_req_finished(request);
1962 if (rc == -ENOENT) {
1964 /* Unlinked special device node? Or just a race?
1965 * Pretend we done everything. */
1966 if (!S_ISREG(inode->i_mode) &&
1967 !S_ISDIR(inode->i_mode)) {
1968 ia_valid = op_data->op_attr.ia_valid;
1969 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1970 rc = simple_setattr(&init_user_ns, dentry,
1972 op_data->op_attr.ia_valid = ia_valid;
1974 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1975 CERROR("md_setattr fails: rc = %d\n", rc);
1980 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1981 sbi->ll_md_exp, &md);
1983 ptlrpc_req_finished(request);
1987 ia_valid = op_data->op_attr.ia_valid;
1988 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1989 * cache is not cleared yet. */
1990 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1991 if (S_ISREG(inode->i_mode))
1993 rc = simple_setattr(&init_user_ns, dentry, &op_data->op_attr);
1994 if (S_ISREG(inode->i_mode))
1995 inode_unlock(inode);
1996 op_data->op_attr.ia_valid = ia_valid;
1998 rc = ll_update_inode(inode, &md);
1999 ptlrpc_req_finished(request);
2005 * Zero portion of page that is part of @inode.
2006 * This implies, if necessary:
2007 * - taking cl_lock on range corresponding to concerned page
2008 * - grabbing vm page
2009 * - associating cl_page
2010 * - proceeding to clio read
2011 * - zeroing range in page
2012 * - proceeding to cl_page flush
2013 * - releasing cl_lock
2015 * \param[in] inode inode
2016 * \param[in] index page index
2017 * \param[in] offset offset in page to start zero from
2018 * \param[in] len len to zero
2020 * \retval 0 on success
2021 * \retval negative errno on failure
2023 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
2026 struct ll_inode_info *lli = ll_i2info(inode);
2027 struct cl_object *clob = lli->lli_clob;
2029 struct lu_env *env = NULL;
2030 struct cl_io *io = NULL;
2031 struct cl_page *clpage = NULL;
2032 struct page *vmpage = NULL;
2033 unsigned from = index << PAGE_SHIFT;
2034 struct cl_lock *lock = NULL;
2035 struct cl_lock_descr *descr = NULL;
2036 struct cl_2queue *queue = NULL;
2037 struct cl_sync_io *anchor = NULL;
2038 bool holdinglock = false;
2043 env = cl_env_get(&refcheck);
2045 RETURN(PTR_ERR(env));
2047 io = vvp_env_thread_io(env);
2049 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2053 lock = vvp_env_lock(env);
2054 descr = &lock->cll_descr;
2055 descr->cld_obj = io->ci_obj;
2056 descr->cld_start = from >> PAGE_SHIFT;
2057 descr->cld_end = (from + PAGE_SIZE - 1) >> PAGE_SHIFT;
2058 descr->cld_mode = CLM_WRITE;
2059 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2061 /* request lock for page */
2062 rc = cl_lock_request(env, io, lock);
2063 /* -ECANCELED indicates a matching lock with a different extent
2064 * was already present, and -EEXIST indicates a matching lock
2065 * on exactly the same extent was already present.
2066 * In both cases it means we are covered.
2068 if (rc == -ECANCELED || rc == -EEXIST)
2076 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2078 GOTO(rellock, rc = -EOPNOTSUPP);
2080 if (!PageDirty(vmpage)) {
2081 /* associate cl_page */
2082 clpage = cl_page_find(env, clob, vmpage->index,
2083 vmpage, CPT_CACHEABLE);
2085 GOTO(pagefini, rc = PTR_ERR(clpage));
2087 cl_page_assume(env, io, clpage);
2090 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2091 !PageWriteback(vmpage)) {
2093 /* Set PagePrivate2 to detect special case of empty page
2094 * in osc_brw_fini_request().
2095 * It is also used to tell ll_io_read_page() that we do not
2096 * want the vmpage to be unlocked.
2098 SetPagePrivate2(vmpage);
2099 rc = ll_io_read_page(env, io, clpage, NULL);
2100 if (!PagePrivate2(vmpage)) {
2101 /* PagePrivate2 was cleared in osc_brw_fini_request()
2102 * meaning we read an empty page. In this case, in order
2103 * to avoid allocating unnecessary block in truncated
2104 * file, we must not zero and write as below. Subsequent
2105 * server-side truncate will handle things correctly.
2107 cl_page_unassume(env, io, clpage);
2108 GOTO(clpfini, rc = 0);
2110 ClearPagePrivate2(vmpage);
2115 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2116 * the vmpage, so we are good to proceed and zero range in page.
2118 zero_user(vmpage, offset, len);
2120 if (holdinglock && clpage) {
2121 /* explicitly write newly modified page */
2122 queue = &io->ci_queue;
2123 cl_2queue_init(queue);
2124 anchor = &vvp_env_info(env)->vti_anchor;
2125 cl_sync_io_init(anchor, 1);
2126 clpage->cp_sync_io = anchor;
2127 cl_page_list_add(&queue->c2_qin, clpage, true);
2128 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2130 GOTO(queuefini1, rc);
2131 rc = cl_sync_io_wait(env, anchor, 0);
2133 GOTO(queuefini2, rc);
2134 cl_page_assume(env, io, clpage);
2137 cl_2queue_discard(env, io, queue);
2139 cl_2queue_disown(env, queue);
2140 cl_2queue_fini(env, queue);
2145 cl_page_put(env, clpage);
2147 unlock_page(vmpage);
2151 cl_lock_release(env, lock);
2153 cl_io_fini(env, io);
2156 cl_env_put(env, &refcheck);
2162 * Get reference file from volatile file name.
2163 * Volatile file name may look like:
2164 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2165 * where fd is opened descriptor of reference file.
2167 * \param[in] volatile_name volatile file name
2168 * \param[in] volatile_len volatile file name length
2169 * \param[out] ref_file pointer to struct file of reference file
2171 * \retval 0 on success
2172 * \retval negative errno on failure
2174 int volatile_ref_file(const char *volatile_name, int volatile_len,
2175 struct file **ref_file)
2177 char *p, *q, *fd_str;
2180 p = strnstr(volatile_name, ":fd=", volatile_len);
2181 if (!p || strlen(p + 4) == 0)
2184 q = strchrnul(p + 4, ':');
2185 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2188 rc = kstrtouint(fd_str, 10, &fd);
2193 *ref_file = fget(fd);
2199 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2200 * object(s) determine the file size and mtime. Otherwise, the MDS will
2201 * keep these values until such a time that objects are allocated for it.
2202 * We do the MDS operations first, as it is checking permissions for us.
2203 * We don't to the MDS RPC if there is nothing that we want to store there,
2204 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2205 * going to do an RPC anyways.
2207 * If we are doing a truncate, we will send the mtime and ctime updates
2208 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2209 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2212 * In case of HSMimport, we only set attr on MDS.
2214 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2215 enum op_xvalid xvalid, bool hsm_import)
2217 struct inode *inode = dentry->d_inode;
2218 struct ll_inode_info *lli = ll_i2info(inode);
2219 struct md_op_data *op_data = NULL;
2220 ktime_t kstart = ktime_get();
2225 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2226 "valid %x, hsm_import %d\n",
2227 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2228 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2231 if (attr->ia_valid & ATTR_SIZE) {
2232 /* Check new size against VFS/VM file size limit and rlimit */
2233 rc = inode_newsize_ok(inode, attr->ia_size);
2237 /* The maximum Lustre file size is variable, based on the
2238 * OST maximum object size and number of stripes. This
2239 * needs another check in addition to the VFS check above. */
2240 if (attr->ia_size > ll_file_maxbytes(inode)) {
2241 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2242 PFID(&lli->lli_fid), attr->ia_size,
2243 ll_file_maxbytes(inode));
2247 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2250 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2251 if (attr->ia_valid & TIMES_SET_FLAGS) {
2252 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2253 !capable(CAP_FOWNER))
2257 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2258 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2259 (attr->ia_valid & ATTR_CTIME)) {
2260 attr->ia_ctime = current_time(inode);
2261 xvalid |= OP_XVALID_CTIME_SET;
2263 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2264 (attr->ia_valid & ATTR_ATIME)) {
2265 attr->ia_atime = current_time(inode);
2266 attr->ia_valid |= ATTR_ATIME_SET;
2268 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2269 (attr->ia_valid & ATTR_MTIME)) {
2270 attr->ia_mtime = current_time(inode);
2271 attr->ia_valid |= ATTR_MTIME_SET;
2274 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2275 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2276 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2277 ktime_get_real_seconds());
2279 if (S_ISREG(inode->i_mode))
2280 inode_unlock(inode);
2282 /* We always do an MDS RPC, even if we're only changing the size;
2283 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2285 OBD_ALLOC_PTR(op_data);
2286 if (op_data == NULL)
2287 GOTO(out, rc = -ENOMEM);
2289 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2290 /* If we are changing file size, file content is
2291 * modified, flag it.
2293 xvalid |= OP_XVALID_OWNEROVERRIDE;
2294 op_data->op_bias |= MDS_DATA_MODIFIED;
2295 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2298 if (attr->ia_valid & ATTR_FILE) {
2299 struct ll_file_data *fd = attr->ia_file->private_data;
2301 if (fd->fd_lease_och)
2302 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2305 op_data->op_attr = *attr;
2306 op_data->op_xvalid = xvalid;
2308 rc = ll_md_setattr(dentry, op_data);
2311 lli->lli_synced_to_mds = false;
2313 if (!S_ISREG(inode->i_mode) || hsm_import)
2316 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2317 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2318 xvalid & OP_XVALID_CTIME_SET) {
2319 bool cached = false;
2321 rc = pcc_inode_setattr(inode, attr, &cached);
2324 CERROR("%s: PCC inode "DFID" setattr failed: "
2326 ll_i2sbi(inode)->ll_fsname,
2327 PFID(&lli->lli_fid), rc);
2331 unsigned int flags = 0;
2333 /* For truncate and utimes sending attributes to OSTs,
2334 * setting mtime/atime to the past will be performed
2335 * under PW [0:EOF] extent lock (new_size:EOF for
2336 * truncate). It may seem excessive to send mtime/atime
2337 * updates to OSTs when not setting times to past, but
2338 * it is necessary due to possible time
2339 * de-synchronization between MDT inode and OST objects
2341 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2342 xvalid |= OP_XVALID_FLAGS;
2343 flags = LUSTRE_ENCRYPT_FL;
2344 /* Call to ll_io_zero_page is not necessary if
2345 * truncating on PAGE_SIZE boundary, because
2346 * whole pages will be wiped.
2347 * In case of Direct IO, all we need is to set
2350 if (attr->ia_valid & ATTR_SIZE &&
2351 attr->ia_size & ~PAGE_MASK &&
2352 !(attr->ia_valid & ATTR_FILE &&
2353 attr->ia_file->f_flags & O_DIRECT)) {
2355 attr->ia_size & (PAGE_SIZE - 1);
2357 rc = ll_io_zero_page(inode,
2358 attr->ia_size >> PAGE_SHIFT,
2359 offset, PAGE_SIZE - offset);
2363 /* If encrypted volatile file without the key,
2364 * we need to fetch size from reference file,
2365 * and set it on OST objects. This happens when
2366 * migrating or extending an encrypted file
2369 if (filename_is_volatile(dentry->d_name.name,
2372 llcrypt_require_key(inode) == -ENOKEY) {
2373 struct file *ref_file;
2374 struct inode *ref_inode;
2375 struct ll_inode_info *ref_lli;
2376 struct cl_object *ref_obj;
2377 struct cl_attr ref_attr = { 0 };
2381 rc = volatile_ref_file(
2382 dentry->d_name.name,
2388 ref_inode = file_inode(ref_file);
2391 GOTO(out, rc = -EINVAL);
2394 env = cl_env_get(&refcheck);
2396 GOTO(out, rc = PTR_ERR(env));
2398 ref_lli = ll_i2info(ref_inode);
2399 ref_obj = ref_lli->lli_clob;
2400 cl_object_attr_lock(ref_obj);
2401 rc = cl_object_attr_get(env, ref_obj,
2403 cl_object_attr_unlock(ref_obj);
2404 cl_env_put(env, &refcheck);
2409 attr->ia_valid |= ATTR_SIZE;
2410 attr->ia_size = ref_attr.cat_size;
2413 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2417 /* If the file was restored, it needs to set dirty flag.
2419 * We've already sent MDS_DATA_MODIFIED flag in
2420 * ll_md_setattr() for truncate. However, the MDT refuses to
2421 * set the HS_DIRTY flag on released files, so we have to set
2422 * it again if the file has been restored. Please check how
2423 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2425 * Please notice that if the file is not released, the previous
2426 * MDS_DATA_MODIFIED has taken effect and usually
2427 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2428 * This way we can save an RPC for common open + trunc
2430 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2431 struct hsm_state_set hss = {
2432 .hss_valid = HSS_SETMASK,
2433 .hss_setmask = HS_DIRTY,
2437 rc2 = ll_hsm_state_set(inode, &hss);
2438 /* truncate and write can happen at the same time, so that
2439 * the file can be set modified even though the file is not
2440 * restored from released state, and ll_hsm_state_set() is
2441 * not applicable for the file, and rc2 < 0 is normal in this
2444 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2445 PFID(ll_inode2fid(inode)), rc2);
2450 if (op_data != NULL)
2451 ll_finish_md_op_data(op_data);
2453 if (S_ISREG(inode->i_mode)) {
2455 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2456 inode_dio_wait(inode);
2457 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2458 * flag. ll_update_inode (called from ll_md_setattr), clears
2459 * inode flags, so there is a gap where S_NOSEC is not set.
2460 * This can cause a writer to take the i_mutex unnecessarily,
2461 * but this is safe to do and should be rare. */
2462 inode_has_no_xattr(inode);
2466 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2467 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2468 ktime_us_delta(ktime_get(), kstart));
2473 int ll_setattr(struct user_namespace *mnt_userns, struct dentry *de,
2476 int mode = de->d_inode->i_mode;
2477 enum op_xvalid xvalid = 0;
2480 rc = llcrypt_prepare_setattr(de, attr);
2484 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2485 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2486 xvalid |= OP_XVALID_OWNEROVERRIDE;
2488 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2489 (ATTR_SIZE|ATTR_MODE)) &&
2490 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2491 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2492 !(attr->ia_mode & S_ISGID))))
2493 attr->ia_valid |= ATTR_FORCE;
2495 if ((attr->ia_valid & ATTR_MODE) &&
2497 !(attr->ia_mode & S_ISUID) &&
2498 !(attr->ia_valid & ATTR_KILL_SUID))
2499 attr->ia_valid |= ATTR_KILL_SUID;
2501 if ((attr->ia_valid & ATTR_MODE) &&
2502 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2503 !(attr->ia_mode & S_ISGID) &&
2504 !(attr->ia_valid & ATTR_KILL_SGID))
2505 attr->ia_valid |= ATTR_KILL_SGID;
2507 return ll_setattr_raw(de, attr, xvalid, false);
2510 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2513 struct obd_statfs obd_osfs = { 0 };
2518 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2520 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2521 flags |= OBD_STATFS_NODELAY;
2523 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2527 osfs->os_type = LL_SUPER_MAGIC;
2529 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2530 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2532 if (osfs->os_state & OS_STATFS_SUM)
2535 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2536 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2539 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2540 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2543 osfs->os_bsize = obd_osfs.os_bsize;
2544 osfs->os_blocks = obd_osfs.os_blocks;
2545 osfs->os_bfree = obd_osfs.os_bfree;
2546 osfs->os_bavail = obd_osfs.os_bavail;
2548 /* If we have _some_ OSTs, but don't have as many free objects on the
2549 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2550 * to compensate, so that the "inodes in use" number is correct.
2551 * This should be kept in sync with lod_statfs() behaviour.
2553 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2554 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2556 osfs->os_ffree = obd_osfs.os_ffree;
2563 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2565 struct if_quotactl qctl = {
2566 .qc_cmd = LUSTRE_Q_GETQUOTA,
2567 .qc_type = PRJQUOTA,
2568 .qc_valid = QC_GENERAL,
2570 u64 limit, curblock;
2573 qctl.qc_id = ll_i2info(inode)->lli_projid;
2574 ret = quotactl_ioctl(inode->i_sb, &qctl);
2576 /* ignore errors if project ID does not have
2577 * a quota limit or feature unsupported.
2579 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2584 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2585 qctl.qc_dqblk.dqb_bsoftlimit :
2586 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2587 if (limit && sfs->f_blocks > limit) {
2588 curblock = (qctl.qc_dqblk.dqb_curspace +
2589 sfs->f_bsize - 1) / sfs->f_bsize;
2590 sfs->f_blocks = limit;
2591 sfs->f_bfree = sfs->f_bavail =
2592 (sfs->f_blocks > curblock) ?
2593 (sfs->f_blocks - curblock) : 0;
2596 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2597 qctl.qc_dqblk.dqb_isoftlimit :
2598 qctl.qc_dqblk.dqb_ihardlimit;
2599 if (limit && sfs->f_files > limit) {
2600 sfs->f_files = limit;
2601 sfs->f_ffree = (sfs->f_files >
2602 qctl.qc_dqblk.dqb_curinodes) ?
2603 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2609 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2611 struct super_block *sb = de->d_sb;
2612 struct obd_statfs osfs;
2613 __u64 fsid = huge_encode_dev(sb->s_dev);
2614 ktime_t kstart = ktime_get();
2617 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2619 /* Some amount of caching on the client is allowed */
2620 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2624 statfs_unpack(sfs, &osfs);
2626 /* We need to downshift for all 32-bit kernels, because we can't
2627 * tell if the kernel is being called via sys_statfs64() or not.
2628 * Stop before overflowing f_bsize - in which case it is better
2629 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2630 if (sizeof(long) < 8) {
2631 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2634 osfs.os_blocks >>= 1;
2635 osfs.os_bfree >>= 1;
2636 osfs.os_bavail >>= 1;
2640 sfs->f_blocks = osfs.os_blocks;
2641 sfs->f_bfree = osfs.os_bfree;
2642 sfs->f_bavail = osfs.os_bavail;
2643 sfs->f_fsid.val[0] = (__u32)fsid;
2644 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2645 if (ll_i2info(de->d_inode)->lli_projid &&
2646 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2647 return ll_statfs_project(de->d_inode, sfs);
2649 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2650 ktime_us_delta(ktime_get(), kstart));
2655 void ll_inode_size_lock(struct inode *inode)
2657 struct ll_inode_info *lli;
2659 LASSERT(!S_ISDIR(inode->i_mode));
2661 lli = ll_i2info(inode);
2662 mutex_lock(&lli->lli_size_mutex);
2665 void ll_inode_size_unlock(struct inode *inode)
2667 struct ll_inode_info *lli;
2669 lli = ll_i2info(inode);
2670 mutex_unlock(&lli->lli_size_mutex);
2673 int ll_inode_size_trylock(struct inode *inode)
2675 struct ll_inode_info *lli;
2677 LASSERT(!S_ISDIR(inode->i_mode));
2679 lli = ll_i2info(inode);
2680 return mutex_trylock(&lli->lli_size_mutex);
2683 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2685 /* do not clear encryption flag */
2686 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2687 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2688 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2689 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2691 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2694 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2696 struct ll_inode_info *lli = ll_i2info(inode);
2697 struct mdt_body *body = md->body;
2698 struct ll_sb_info *sbi = ll_i2sbi(inode);
2702 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2703 rc = cl_file_inode_init(inode, md);
2708 if (S_ISDIR(inode->i_mode)) {
2709 rc = ll_update_lsm_md(inode, md);
2714 if (body->mbo_valid & OBD_MD_FLACL)
2715 lli_replace_acl(lli, md);
2717 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2718 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2719 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2721 if (body->mbo_valid & OBD_MD_FLATIME) {
2722 if (body->mbo_atime > inode->i_atime.tv_sec)
2723 inode->i_atime.tv_sec = body->mbo_atime;
2724 lli->lli_atime = body->mbo_atime;
2727 if (body->mbo_valid & OBD_MD_FLMTIME) {
2728 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2730 "setting ino %lu mtime from %lld to %llu\n",
2731 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2733 inode->i_mtime.tv_sec = body->mbo_mtime;
2735 lli->lli_mtime = body->mbo_mtime;
2738 if (body->mbo_valid & OBD_MD_FLCTIME) {
2739 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2740 inode->i_ctime.tv_sec = body->mbo_ctime;
2741 lli->lli_ctime = body->mbo_ctime;
2744 if (body->mbo_valid & OBD_MD_FLBTIME)
2745 lli->lli_btime = body->mbo_btime;
2747 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2748 if (body->mbo_valid & OBD_MD_FLFLAGS)
2749 ll_update_inode_flags(inode, body->mbo_flags);
2750 if (body->mbo_valid & OBD_MD_FLMODE)
2751 inode->i_mode = (inode->i_mode & S_IFMT) |
2752 (body->mbo_mode & ~S_IFMT);
2754 if (body->mbo_valid & OBD_MD_FLTYPE)
2755 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2756 (body->mbo_mode & S_IFMT);
2758 LASSERT(inode->i_mode != 0);
2759 if (body->mbo_valid & OBD_MD_FLUID)
2760 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2761 if (body->mbo_valid & OBD_MD_FLGID)
2762 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2763 if (body->mbo_valid & OBD_MD_FLPROJID)
2764 lli->lli_projid = body->mbo_projid;
2765 if (body->mbo_valid & OBD_MD_FLNLINK) {
2766 spin_lock(&inode->i_lock);
2767 set_nlink(inode, body->mbo_nlink);
2768 spin_unlock(&inode->i_lock);
2770 if (body->mbo_valid & OBD_MD_FLRDEV)
2771 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2773 if (body->mbo_valid & OBD_MD_FLID) {
2774 /* FID shouldn't be changed! */
2775 if (fid_is_sane(&lli->lli_fid)) {
2776 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2777 "Trying to change FID "DFID
2778 " to the "DFID", inode "DFID"(%p)\n",
2779 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2780 PFID(ll_inode2fid(inode)), inode);
2782 lli->lli_fid = body->mbo_fid1;
2786 LASSERT(fid_seq(&lli->lli_fid) != 0);
2788 /* In case of encrypted file without the key, please do not lose
2789 * clear text size stored into lli_lazysize in ll_merge_attr(),
2790 * we will need it in ll_prepare_close().
2792 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2793 llcrypt_require_key(inode) == -ENOKEY)
2794 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2796 lli->lli_attr_valid = body->mbo_valid;
2797 if (body->mbo_valid & OBD_MD_FLSIZE) {
2798 i_size_write(inode, body->mbo_size);
2800 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2801 PFID(ll_inode2fid(inode)),
2802 (unsigned long long)body->mbo_size);
2804 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2805 inode->i_blocks = body->mbo_blocks;
2807 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2808 lli->lli_lazysize = body->mbo_size;
2809 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2810 lli->lli_lazyblocks = body->mbo_blocks;
2813 if (body->mbo_valid & OBD_MD_TSTATE) {
2814 /* Set LLIF_FILE_RESTORING if restore ongoing and
2815 * clear it when done to ensure to start again
2816 * glimpsing updated attrs
2818 if (body->mbo_t_state & MS_RESTORE)
2819 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2821 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2827 /* child default LMV is inherited from parent */
2828 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2829 struct lmv_stripe_md *cdmv)
2834 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2835 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2836 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2837 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2840 if (cdmv->lsm_md_max_inherit !=
2841 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2844 if (cdmv->lsm_md_max_inherit_rr !=
2845 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2851 /* update directory depth to ROOT, called after LOOKUP lock is fetched. */
2852 void ll_update_dir_depth(struct inode *dir, struct inode *inode)
2854 struct ll_inode_info *plli;
2855 struct ll_inode_info *lli;
2857 if (!S_ISDIR(inode->i_mode))
2863 plli = ll_i2info(dir);
2864 lli = ll_i2info(inode);
2865 lli->lli_dir_depth = plli->lli_dir_depth + 1;
2866 if (plli->lli_default_lsm_md && lli->lli_default_lsm_md) {
2867 down_read(&plli->lli_lsm_sem);
2868 down_read(&lli->lli_lsm_sem);
2869 if (ll_default_lmv_inherited(plli->lli_default_lsm_md,
2870 lli->lli_default_lsm_md))
2871 lli->lli_inherit_depth =
2872 plli->lli_inherit_depth + 1;
2874 lli->lli_inherit_depth = 0;
2875 up_read(&lli->lli_lsm_sem);
2876 up_read(&plli->lli_lsm_sem);
2878 lli->lli_inherit_depth = 0;
2881 CDEBUG(D_INODE, DFID" depth %hu default LMV depth %hu\n",
2882 PFID(&lli->lli_fid), lli->lli_dir_depth, lli->lli_inherit_depth);
2885 void ll_truncate_inode_pages_final(struct inode *inode, struct cl_io *io)
2887 struct address_space *mapping = &inode->i_data;
2888 unsigned long nrpages;
2889 unsigned long flags;
2891 LASSERTF(io == NULL || inode_is_locked(inode), "io %p (type %d)\n",
2892 io, io ? io->ci_type : 0);
2894 truncate_inode_pages_final(mapping);
2896 /* Workaround for LU-118: Note nrpages may not be totally updated when
2897 * truncate_inode_pages() returns, as there can be a page in the process
2898 * of deletion (inside __delete_from_page_cache()) in the specified
2899 * range. Thus mapping->nrpages can be non-zero when this function
2900 * returns even after truncation of the whole mapping. Only do this if
2901 * npages isn't already zero.
2903 nrpages = mapping->nrpages;
2905 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2906 nrpages = mapping->nrpages;
2907 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2908 } /* Workaround end */
2910 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu "
2911 "io %p (io_type %d), "
2912 "see https://jira.whamcloud.com/browse/LU-118\n",
2913 ll_i2sbi(inode)->ll_fsname,
2914 PFID(ll_inode2fid(inode)), inode, nrpages,
2915 io, io ? io->ci_type : 0);
2918 int ll_read_inode2(struct inode *inode, void *opaque)
2920 struct lustre_md *md = opaque;
2921 struct ll_inode_info *lli = ll_i2info(inode);
2925 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2926 PFID(&lli->lli_fid), inode);
2928 /* Core attributes from the MDS first. This is a new inode, and
2929 * the VFS doesn't zero times in the core inode so we have to do
2930 * it ourselves. They will be overwritten by either MDS or OST
2931 * attributes - we just need to make sure they aren't newer.
2933 inode->i_mtime.tv_sec = 0;
2934 inode->i_atime.tv_sec = 0;
2935 inode->i_ctime.tv_sec = 0;
2937 rc = ll_update_inode(inode, md);
2941 /* OIDEBUG(inode); */
2943 #ifdef HAVE_BACKING_DEV_INFO
2944 /* initializing backing dev info. */
2945 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2947 if (S_ISREG(inode->i_mode)) {
2948 struct ll_sb_info *sbi = ll_i2sbi(inode);
2949 inode->i_op = &ll_file_inode_operations;
2950 inode->i_fop = sbi->ll_fop;
2951 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2953 } else if (S_ISDIR(inode->i_mode)) {
2954 inode->i_op = &ll_dir_inode_operations;
2955 inode->i_fop = &ll_dir_operations;
2957 } else if (S_ISLNK(inode->i_mode)) {
2958 inode->i_op = &ll_fast_symlink_inode_operations;
2961 inode->i_op = &ll_special_inode_operations;
2963 init_special_inode(inode, inode->i_mode,
2972 void ll_delete_inode(struct inode *inode)
2974 struct ll_inode_info *lli = ll_i2info(inode);
2977 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2978 /* It is last chance to write out dirty pages,
2979 * otherwise we may lose data while umount.
2981 * If i_nlink is 0 then just discard data. This is safe because
2982 * local inode gets i_nlink 0 from server only for the last
2983 * unlink, so that file is not opened somewhere else
2985 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2986 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2989 ll_truncate_inode_pages_final(inode, NULL);
2990 ll_clear_inode(inode);
2996 static int fileattr_get(struct inode *inode, int *flags,
3000 struct ll_sb_info *sbi = ll_i2sbi(inode);
3001 struct ptlrpc_request *req = NULL;
3002 struct md_op_data *op_data;
3003 struct mdt_body *body;
3007 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
3008 0, 0, LUSTRE_OPC_ANY,
3010 if (IS_ERR(op_data))
3011 RETURN(PTR_ERR(op_data));
3013 op_data->op_valid = OBD_MD_FLFLAGS;
3014 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
3015 ll_finish_md_op_data(op_data);
3017 CERROR("%s: failure inode "DFID": rc = %d\n",
3018 sbi->ll_md_exp->exp_obd->obd_name,
3019 PFID(ll_inode2fid(inode)), rc);
3023 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3025 *flags = body->mbo_flags;
3026 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
3027 * ext4 equivalent to please lsattr and other e2fsprogs tools
3029 if (*flags & LUSTRE_ENCRYPT_FL)
3030 *flags |= STATX_ATTR_ENCRYPTED;
3032 ptlrpc_req_finished(req);
3034 *xflags = ll_inode_flags_to_xflags(inode->i_flags);
3035 if (test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags))
3036 *xflags |= FS_XFLAG_PROJINHERIT;
3037 *projid = ll_i2info(inode)->lli_projid;
3042 static int fileattr_set(struct inode *inode, int flags)
3044 struct ll_sb_info *sbi = ll_i2sbi(inode);
3045 struct ptlrpc_request *req = NULL;
3046 struct md_op_data *op_data;
3047 struct cl_object *obj;
3048 struct fsxattr fa = { 0 };
3053 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3054 if (flags & LUSTRE_PROJINHERIT_FL)
3055 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3057 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3062 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3063 LUSTRE_OPC_ANY, NULL);
3064 if (IS_ERR(op_data))
3065 RETURN(PTR_ERR(op_data));
3067 op_data->op_attr_flags = flags;
3068 op_data->op_xvalid |= OP_XVALID_FLAGS;
3069 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3070 ll_finish_md_op_data(op_data);
3071 ptlrpc_req_finished(req);
3075 ll_update_inode_flags(inode, flags);
3077 obj = ll_i2info(inode)->lli_clob;
3081 OBD_ALLOC_PTR(attr);
3085 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3091 #ifdef HAVE_FILEATTR_GET
3092 int ll_fileattr_get(struct dentry *dentry, struct fileattr *fa)
3094 return fileattr_get(d_inode(dentry), &fa->flags,
3095 &fa->fsx_xflags, &fa->fsx_projid);
3098 int ll_fileattr_set(struct user_namespace *mnt_userns,
3099 struct dentry *dentry, struct fileattr *fa)
3102 return ll_set_project(d_inode(dentry), fa->fsx_xflags,
3105 return fileattr_set(d_inode(dentry), fa->flags);
3107 #endif /* HAVE_FILEATTR_GET */
3109 /* ioctl commands shared between files and directories */
3110 int ll_iocontrol(struct inode *inode, struct file *file,
3111 unsigned int cmd, void __user *uarg)
3118 RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
3119 case LL_IOC_GETVERSION:
3120 case FS_IOC_GETVERSION:
3121 RETURN(put_user(inode->i_generation, (int __user *)uarg));
3123 #ifndef HAVE_FILEATTR_GET
3124 case FS_IOC_GETFLAGS: {
3125 u32 xflags = 0, projid = 0;
3128 if (!ll_access_ok(uarg, sizeof(int)))
3130 rc = fileattr_get(file->f_inode, &flags, &xflags, &projid);
3134 RETURN(put_user(flags, (int __user *)uarg));
3136 case FS_IOC_SETFLAGS: {
3139 if (get_user(flags, (int __user *)uarg))
3142 RETURN(fileattr_set(file->f_inode, flags));
3144 case FS_IOC_FSGETXATTR:
3145 RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
3146 case FS_IOC_FSSETXATTR:
3147 RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
3148 #endif /* HAVE_FILEATTR_GET */
3149 case LL_IOC_PROJECT:
3150 RETURN(ll_ioctl_project(file, cmd, uarg));
3151 case IOC_OBD_STATFS:
3152 RETURN(ll_obd_statfs(inode, uarg));
3153 case LL_IOC_GET_MDTIDX: {
3154 if (!ll_access_ok(uarg, sizeof(rc)))
3157 rc = ll_get_mdt_idx(inode);
3161 if (put_user(rc, (int __user *)uarg))
3166 case LL_IOC_FLUSHCTX:
3167 RETURN(ll_flush_ctx(inode));
3168 #ifdef HAVE_LUSTRE_CRYPTO
3169 case LL_IOC_ADD_ENCRYPTION_KEY:
3170 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3172 rc = llcrypt_ioctl_add_key(file, uarg);
3173 #ifdef CONFIG_LL_ENCRYPTION
3174 if (!rc && S_ISDIR(inode->i_mode))
3175 sptlrpc_enc_pool_add_user();
3178 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
3179 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3181 RETURN(llcrypt_ioctl_get_key_status(file, uarg));
3182 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
3183 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3185 RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
3186 case LL_IOC_SET_ENCRYPTION_POLICY:
3187 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3189 RETURN(llcrypt_ioctl_set_policy(file, uarg));
3190 case LL_IOC_REMOVE_ENCRYPTION_KEY:
3191 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3193 RETURN(llcrypt_ioctl_remove_key(file, uarg));
3194 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
3195 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3197 RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
3199 case LL_IOC_GETPARENT:
3200 RETURN(ll_getparent(file, uarg));
3201 case LL_IOC_PATH2FID:
3202 if (copy_to_user(uarg, ll_inode2fid(inode),
3203 sizeof(struct lu_fid)))
3206 case LL_IOC_UNLOCK_FOREIGN: {
3207 struct dentry *dentry = file_dentry(file);
3209 /* if not a foreign symlink do nothing */
3210 if (ll_foreign_is_removable(dentry, true)) {
3212 "prevent unlink of non-foreign file ("DFID")\n",
3213 PFID(ll_inode2fid(inode)));
3214 RETURN(-EOPNOTSUPP);
3218 case OBD_IOC_FID2PATH:
3219 RETURN(ll_fid2path(inode, uarg));
3220 case OBD_IOC_GETNAME_OLD:
3221 case OBD_IOC_GETDTNAME:
3222 case OBD_IOC_GETMDNAME:
3223 RETURN(ll_get_obd_name(inode, cmd, uarg));
3231 int ll_flush_ctx(struct inode *inode)
3233 struct ll_sb_info *sbi = ll_i2sbi(inode);
3235 CDEBUG(D_SEC, "flush context for user %d\n",
3236 from_kuid(&init_user_ns, current_uid()));
3238 obd_set_info_async(NULL, sbi->ll_md_exp,
3239 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3241 obd_set_info_async(NULL, sbi->ll_dt_exp,
3242 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3247 /* umount -f client means force down, don't save state */
3248 void ll_umount_begin(struct super_block *sb)
3250 struct ll_sb_info *sbi = ll_s2sbi(sb);
3251 struct obd_device *obd;
3252 struct obd_ioctl_data *ioc_data;
3256 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3257 sb->s_count, atomic_read(&sb->s_active));
3259 obd = class_exp2obd(sbi->ll_md_exp);
3261 CERROR("Invalid MDC connection handle %#llx\n",
3262 sbi->ll_md_exp->exp_handle.h_cookie);
3268 obd = class_exp2obd(sbi->ll_dt_exp);
3270 CERROR("Invalid LOV connection handle %#llx\n",
3271 sbi->ll_dt_exp->exp_handle.h_cookie);
3277 OBD_ALLOC_PTR(ioc_data);
3279 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
3280 sizeof *ioc_data, ioc_data, NULL);
3282 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
3283 sizeof *ioc_data, ioc_data, NULL);
3285 OBD_FREE_PTR(ioc_data);
3288 /* Really, we'd like to wait until there are no requests outstanding,
3289 * and then continue. For now, we just periodically checking for vfs
3290 * to decrement mnt_cnt and hope to finish it within 10sec.
3294 !may_umount(sbi->ll_mnt.mnt)) {
3302 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3304 struct ll_sb_info *sbi = ll_s2sbi(sb);
3305 char *profilenm = get_profile_name(sb);
3309 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3310 read_only = *flags & MS_RDONLY;
3311 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3312 sizeof(KEY_READ_ONLY),
3313 KEY_READ_ONLY, sizeof(read_only),
3316 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3317 profilenm, read_only ?
3318 "read-only" : "read-write", err);
3323 sb->s_flags |= SB_RDONLY;
3325 sb->s_flags &= ~SB_RDONLY;
3327 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3328 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3329 read_only ? "read-only" : "read-write");
3335 * Cleanup the open handle that is cached on MDT-side.
3337 * For open case, the client side open handling thread may hit error
3338 * after the MDT grant the open. Under such case, the client should
3339 * send close RPC to the MDT as cleanup; otherwise, the open handle
3340 * on the MDT will be leaked there until the client umount or evicted.
3342 * In further, if someone unlinked the file, because the open handle
3343 * holds the reference on such file/object, then it will block the
3344 * subsequent threads that want to locate such object via FID.
3346 * \param[in] sb super block for this file-system
3347 * \param[in] open_req pointer to the original open request
3349 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3351 struct mdt_body *body;
3352 struct md_op_data *op_data;
3353 struct ptlrpc_request *close_req = NULL;
3354 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3357 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3358 OBD_ALLOC_PTR(op_data);
3359 if (op_data == NULL) {
3360 CWARN("%s: cannot allocate op_data to release open handle for "
3361 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3366 op_data->op_fid1 = body->mbo_fid1;
3367 op_data->op_open_handle = body->mbo_open_handle;
3368 op_data->op_mod_time = ktime_get_real_seconds();
3369 md_close(exp, op_data, NULL, &close_req);
3370 ptlrpc_req_finished(close_req);
3371 ll_finish_md_op_data(op_data);
3376 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3377 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3378 struct lustre_md *md)
3380 struct ll_sb_info *sbi = ll_i2sbi(inode);
3381 struct ptlrpc_request *req = NULL;
3382 union lmv_mds_md *lmm = NULL;
3386 LASSERT(is_root_inode(inode));
3387 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3388 LASSERT(!md->default_lmv);
3390 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3392 GET_DEFAULT_LAYOUT_ROOT);
3393 if (rc && rc != -ENODATA)
3398 rc = md_unpackmd(sbi->ll_md_exp, &md->default_lmv, lmm, size);
3407 ptlrpc_req_finished(req);
3411 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3412 struct super_block *sb, struct lookup_intent *it)
3414 struct ll_sb_info *sbi = NULL;
3415 struct lustre_md md = { NULL };
3416 bool default_lmv_deleted = false;
3421 LASSERT(*inode || sb);
3422 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3423 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3424 sbi->ll_md_exp, &md);
3429 * clear default_lmv only if intent_getattr reply doesn't contain it.
3430 * but it needs to be done after iget, check this early because
3431 * ll_update_lsm_md() may change md.
3433 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3434 S_ISDIR(md.body->mbo_mode) && !md.default_lmv) {
3435 if (unlikely(*inode && is_root_inode(*inode) &&
3436 !fid_is_root(&sbi->ll_root_fid))) {
3437 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3442 if (!md.default_lmv)
3443 default_lmv_deleted = true;
3447 rc = ll_update_inode(*inode, &md);
3451 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3452 struct lu_fid *fid1 = &md.body->mbo_fid1;
3454 LASSERT(sb != NULL);
3457 * At this point server returns to client's same fid as client
3458 * generated for creating. So using ->fid1 is okay here.
3460 if (!fid_is_sane(fid1)) {
3461 CERROR("%s: Fid is insane "DFID"\n",
3462 sbi->ll_fsname, PFID(fid1));
3463 GOTO(out, rc = -EINVAL);
3466 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3467 if (IS_ERR(*inode)) {
3469 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3471 CERROR("new_inode -fatal: rc %d\n", rc);
3476 /* Handling piggyback layout lock.
3477 * Layout lock can be piggybacked by getattr and open request.
3478 * The lsm can be applied to inode only if it comes with a layout lock
3479 * otherwise correct layout may be overwritten, for example:
3480 * 1. proc1: mdt returns a lsm but not granting layout
3481 * 2. layout was changed by another client
3482 * 3. proc2: refresh layout and layout lock granted
3483 * 4. proc1: to apply a stale layout */
3484 if (it != NULL && it->it_lock_mode != 0) {
3485 struct lustre_handle lockh;
3486 struct ldlm_lock *lock;
3488 lockh.cookie = it->it_lock_handle;
3489 lock = ldlm_handle2lock(&lockh);
3490 LASSERT(lock != NULL);
3491 if (ldlm_has_layout(lock)) {
3492 struct cl_object_conf conf;
3494 memset(&conf, 0, sizeof(conf));
3495 conf.coc_opc = OBJECT_CONF_SET;
3496 conf.coc_inode = *inode;
3497 conf.coc_lock = lock;
3498 conf.u.coc_layout = md.layout;
3499 (void)ll_layout_conf(*inode, &conf);
3501 LDLM_LOCK_PUT(lock);
3504 if (default_lmv_deleted)
3505 ll_update_default_lsm_md(*inode, &md);
3507 /* we may want to apply some policy for foreign file/dir */
3508 if (ll_sbi_has_foreign_symlink(sbi)) {
3509 rc = ll_manage_foreign(*inode, &md);
3517 /* cleanup will be done if necessary */
3518 md_free_lustre_md(sbi->ll_md_exp, &md);
3520 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3521 ll_intent_drop_lock(it);
3522 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3528 int ll_obd_statfs(struct inode *inode, void __user *uarg)
3530 struct ll_sb_info *sbi = NULL;
3531 struct obd_export *exp;
3532 struct obd_ioctl_data *data = NULL;
3537 sbi = ll_i2sbi(inode);
3539 GOTO(out_statfs, rc = -EINVAL);
3541 rc = obd_ioctl_getdata(&data, &len, uarg);
3543 GOTO(out_statfs, rc);
3545 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3546 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3547 GOTO(out_statfs, rc = -EINVAL);
3549 if (data->ioc_inllen1 != sizeof(__u32) ||
3550 data->ioc_inllen2 != sizeof(__u32) ||
3551 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3552 data->ioc_plen2 != sizeof(struct obd_uuid))
3553 GOTO(out_statfs, rc = -EINVAL);
3555 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3556 if (type & LL_STATFS_LMV)
3557 exp = sbi->ll_md_exp;
3558 else if (type & LL_STATFS_LOV)
3559 exp = sbi->ll_dt_exp;
3561 GOTO(out_statfs, rc = -ENODEV);
3563 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3565 GOTO(out_statfs, rc);
3567 OBD_FREE_LARGE(data, len);
3572 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3573 * be called early to avoid deadlock.
3575 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3577 if (op_data->op_mea2_sem) {
3578 up_read_non_owner(op_data->op_mea2_sem);
3579 op_data->op_mea2_sem = NULL;
3582 if (op_data->op_mea1_sem) {
3583 up_read_non_owner(op_data->op_mea1_sem);
3584 op_data->op_mea1_sem = NULL;
3588 /* this function prepares md_op_data hint for passing it down to MD stack. */
3589 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3590 struct inode *i1, struct inode *i2,
3591 const char *name, size_t namelen,
3592 __u32 mode, enum md_op_code opc,
3595 struct llcrypt_name fname = { 0 };
3598 LASSERT(i1 != NULL);
3601 /* Do not reuse namelen for something else. */
3603 return ERR_PTR(-EINVAL);
3605 if ((!IS_ENCRYPTED(i1) ||
3606 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3607 namelen > ll_i2sbi(i1)->ll_namelen)
3608 return ERR_PTR(-ENAMETOOLONG);
3610 /* "/" is not valid name, but it's allowed */
3611 if (!lu_name_is_valid_2(name, namelen) &&
3612 strncmp("/", name, namelen) != 0)
3613 return ERR_PTR(-EINVAL);
3616 if (op_data == NULL)
3617 OBD_ALLOC_PTR(op_data);
3619 if (op_data == NULL)
3620 return ERR_PTR(-ENOMEM);
3622 ll_i2gids(op_data->op_suppgids, i1, i2);
3623 /* If the client is using a subdir mount and looks at what it sees as
3624 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3626 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3627 !fid_is_root(ll_inode2fid(i1)) &&
3628 name && namelen == strlen(dot_fscrypt_name) &&
3629 strncmp(name, dot_fscrypt_name, namelen) == 0))
3630 lu_root_fid(&op_data->op_fid1);
3632 op_data->op_fid1 = *ll_inode2fid(i1);
3634 if (S_ISDIR(i1->i_mode)) {
3635 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3636 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3637 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3638 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3642 op_data->op_fid2 = *ll_inode2fid(i2);
3643 if (S_ISDIR(i2->i_mode)) {
3645 /* i2 is typically a child of i1, and MUST be
3646 * further from the root to avoid deadlocks.
3648 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3649 op_data->op_mea2_sem =
3650 &ll_i2info(i2)->lli_lsm_sem;
3652 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3655 fid_zero(&op_data->op_fid2);
3658 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3659 op_data->op_cli_flags |= CLI_HASH64;
3661 if (ll_need_32bit_api(ll_i2sbi(i1)))
3662 op_data->op_cli_flags |= CLI_API32;
3664 if ((i2 && is_root_inode(i2)) ||
3665 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3666 /* In case of lookup, ll_setup_filename() has already been
3667 * called in ll_lookup_it(), so just take provided name.
3668 * Also take provided name if we are dealing with root inode.
3670 fname.disk_name.name = (unsigned char *)name;
3671 fname.disk_name.len = namelen;
3672 } else if (name && namelen) {
3673 struct qstr dname = QSTR_INIT(name, namelen);
3675 struct lu_fid *pfid = NULL;
3679 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3680 /* special case when called from ll_link() */
3685 lookup = (int)(opc == LUSTRE_OPC_ANY);
3687 if (opc == LUSTRE_OPC_ANY && lookup)
3689 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3691 ll_finish_md_op_data(op_data);
3694 if (pfid && !fid_is_zero(pfid)) {
3696 op_data->op_fid2 = fid;
3697 op_data->op_bias = MDS_FID_OP;
3699 if (fname.disk_name.name &&
3700 fname.disk_name.name != (unsigned char *)name) {
3701 /* op_data->op_name must be freed after use */
3702 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3706 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3707 * are LUSTRE_OPC_ANY
3709 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3710 op_data->op_code = LUSTRE_OPC_ANY;
3712 op_data->op_code = opc;
3713 op_data->op_name = fname.disk_name.name;
3714 op_data->op_namelen = fname.disk_name.len;
3715 op_data->op_mode = mode;
3716 op_data->op_mod_time = ktime_get_real_seconds();
3717 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3718 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3719 op_data->op_cap = current_cap();
3720 op_data->op_mds = 0;
3721 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3722 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3723 op_data->op_bias |= MDS_CREATE_VOLATILE;
3725 op_data->op_data = data;
3730 void ll_finish_md_op_data(struct md_op_data *op_data)
3732 ll_unlock_md_op_lsm(op_data);
3733 ll_security_release_secctx(op_data->op_file_secctx,
3734 op_data->op_file_secctx_size);
3735 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3736 /* allocated via ll_setup_filename called
3737 * from ll_prep_md_op_data
3739 kfree(op_data->op_name);
3740 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3741 OBD_FREE_PTR(op_data);
3744 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3746 struct ll_sb_info *sbi;
3749 LASSERT(seq && dentry);
3750 sbi = ll_s2sbi(dentry->d_sb);
3752 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3753 seq_puts(seq, "nolock");
3755 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3756 /* match_table in some cases has patterns for both enabled and
3757 * disabled cases. Ignore 'no'xxx versions if bit is set.
3759 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3760 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3761 if (ll_sbi_flags_name[i].token ==
3762 LL_SBI_FOREIGN_SYMLINK) {
3763 seq_show_option(seq, "foreign_symlink",
3764 sbi->ll_foreign_symlink_prefix);
3766 seq_printf(seq, ",%s",
3767 ll_sbi_flags_name[i].pattern);
3770 /* You can have either localflock or flock but not
3771 * both. If localflock is set don't print flock or
3774 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3776 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3777 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3778 seq_printf(seq, ",%s",
3779 ll_sbi_flags_name[i].pattern);
3783 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3789 * Get obd name by cmd, and copy out to user space
3791 int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg)
3793 struct ll_sb_info *sbi = ll_i2sbi(inode);
3794 struct obd_device *obd;
3797 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3798 obd = class_exp2obd(sbi->ll_dt_exp);
3799 else if (cmd == OBD_IOC_GETMDNAME)
3800 obd = class_exp2obd(sbi->ll_md_exp);
3807 if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1))
3814 struct work_struct db_work;
3815 struct dentry *db_dentry;
3816 /* Let's hope the path is not too long, 32 bytes for the work struct
3819 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3822 static void ll_dput_later(struct work_struct *work)
3824 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3826 dput(db->db_dentry);
3827 free_page((unsigned long)db);
3830 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3837 p.mnt = current->fs->root.mnt;
3839 path = d_path(&p, buf, bufsize);
3844 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3846 struct dname_buf *db;
3848 struct dentry *dentry = NULL;
3850 /* this can be called inside spin lock so use GFP_ATOMIC. */
3851 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3854 dentry = d_find_alias(inode);
3856 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3859 /* The below message is checked in recovery-small.sh test_24b */
3861 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3862 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3863 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3864 PFID(ll_inode2fid(inode)),
3865 (path && !IS_ERR(path)) ? path : "", ioret);
3867 if (dentry != NULL) {
3868 /* We cannot dput here since if we happen to be the last holder
3869 * then we can end up waiting for page evictions that
3870 * in turn wait for RPCs that need this instance of ptlrpcd
3871 * (callng brw_interpret->*page_completion*->vmpage_error->here)
3874 INIT_WORK(&db->db_work, ll_dput_later);
3875 db->db_dentry = dentry;
3876 schedule_work(&db->db_work);
3879 free_page((unsigned long)db);
3883 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3884 struct lov_user_md **kbuf)
3886 struct lov_user_md lum;
3890 if (copy_from_user(&lum, md, sizeof(lum)))
3893 lum_size = ll_lov_user_md_size(&lum);
3897 OBD_ALLOC_LARGE(*kbuf, lum_size);
3901 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3902 OBD_FREE_LARGE(*kbuf, lum_size);
3910 * Compute llite root squash state after a change of root squash
3911 * configuration setting or add/remove of a lnet nid
3913 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3915 struct root_squash_info *squash = &sbi->ll_squash;
3918 struct lnet_processid id;
3920 /* Update norootsquash flag */
3921 spin_lock(&squash->rsi_lock);
3922 if (list_empty(&squash->rsi_nosquash_nids))
3923 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3925 /* Do not apply root squash as soon as one of our NIDs is
3926 * in the nosquash_nids list */
3929 while (LNetGetId(i++, &id) != -ENOENT) {
3930 if (nid_is_lo0(&id.nid))
3932 if (cfs_match_nid(&id.nid,
3933 &squash->rsi_nosquash_nids)) {
3939 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3941 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3943 spin_unlock(&squash->rsi_lock);
3947 * Parse linkea content to extract information about a given hardlink
3949 * \param[in] ldata - Initialized linkea data
3950 * \param[in] linkno - Link identifier
3951 * \param[out] parent_fid - The entry's parent FID
3952 * \param[out] ln - Entry name destination buffer
3954 * \retval 0 on success
3955 * \retval Appropriate negative error code on failure
3957 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3958 struct lu_fid *parent_fid, struct lu_name *ln)
3964 rc = linkea_init_with_rec(ldata);
3968 if (linkno >= ldata->ld_leh->leh_reccount)
3969 /* beyond last link */
3972 linkea_first_entry(ldata);
3973 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3974 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3979 linkea_next_entry(ldata);
3989 * Get parent FID and name of an identified link. Operation is performed for
3990 * a given link number, letting the caller iterate over linkno to list one or
3991 * all links of an entry.
3993 * \param[in] file - File descriptor against which to perform the operation
3994 * \param[in,out] arg - User-filled structure containing the linkno to operate
3995 * on and the available size. It is eventually filled with
3996 * the requested information or left untouched on error
3998 * \retval - 0 on success
3999 * \retval - Appropriate negative error code on failure
4001 int ll_getparent(struct file *file, struct getparent __user *arg)
4003 struct inode *inode = file_inode(file);
4004 struct linkea_data *ldata;
4005 struct lu_buf buf = LU_BUF_NULL;
4007 struct lu_fid parent_fid;
4014 if (!capable(CAP_DAC_READ_SEARCH) &&
4015 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
4018 if (get_user(name_size, &arg->gp_name_size))
4021 if (get_user(linkno, &arg->gp_linkno))
4024 if (name_size > PATH_MAX)
4027 OBD_ALLOC(ldata, sizeof(*ldata));
4031 rc = linkea_data_new(ldata, &buf);
4033 GOTO(ldata_free, rc);
4035 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
4036 buf.lb_len, OBD_MD_FLXATTR);
4040 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
4044 if (ln.ln_namelen >= name_size)
4045 GOTO(lb_free, rc = -EOVERFLOW);
4047 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
4048 GOTO(lb_free, rc = -EFAULT);
4050 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
4051 GOTO(lb_free, rc = -EFAULT);
4053 if (put_user('\0', arg->gp_name + ln.ln_namelen))
4054 GOTO(lb_free, rc = -EFAULT);
4059 OBD_FREE(ldata, sizeof(*ldata));