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 #include <lustre_ioctl_old.h>
63 #ifdef HAVE_UAPI_LINUX_MOUNT_H
64 #include <uapi/linux/mount.h>
67 #include <lustre_ha.h>
68 #include <lustre_dlm.h>
69 #include <lprocfs_status.h>
70 #include <lustre_disk.h>
71 #include <uapi/linux/lustre/lustre_param.h>
72 #include <lustre_log.h>
73 #include <cl_object.h>
74 #include <obd_cksum.h>
75 #include "llite_internal.h"
77 struct kmem_cache *ll_file_data_slab;
80 #define log2(n) ffz(~(n))
84 * If there is only one number of core visible to Lustre,
85 * async readahead will be disabled, to avoid massive over
86 * subscription, we use 1/2 of active cores as default max
87 * async readahead requests.
89 static inline unsigned int ll_get_ra_async_max_active(void)
91 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
94 static struct ll_sb_info *ll_init_sbi(struct lustre_sb_info *lsi)
96 struct ll_sb_info *sbi = NULL;
98 unsigned long lru_page_max;
106 RETURN(ERR_PTR(-ENOMEM));
108 rc = pcc_super_init(&sbi->ll_pcc_super);
112 spin_lock_init(&sbi->ll_lock);
113 mutex_init(&sbi->ll_lco.lco_lock);
114 spin_lock_init(&sbi->ll_pp_extent_lock);
115 spin_lock_init(&sbi->ll_process_lock);
117 sbi->ll_rw_stats_on = 0;
118 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
121 pages = si.totalram - si.totalhigh;
122 lru_page_max = pages / 2;
124 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
125 sbi->ll_ra_info.ll_readahead_wq =
126 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
128 sbi->ll_ra_info.ra_async_max_active);
129 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
130 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
132 /* initialize ll_cache data */
133 sbi->ll_cache = cl_cache_init(lru_page_max);
134 if (sbi->ll_cache == NULL)
135 GOTO(out_destroy_ra, rc = -ENOMEM);
137 /* initialize foreign symlink prefix path */
138 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
139 if (sbi->ll_foreign_symlink_prefix == NULL)
140 GOTO(out_destroy_ra, rc = -ENOMEM);
141 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
142 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
144 /* initialize foreign symlink upcall path, none by default */
145 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
146 if (sbi->ll_foreign_symlink_upcall == NULL)
147 GOTO(out_destroy_ra, rc = -ENOMEM);
148 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
149 sbi->ll_foreign_symlink_upcall_items = NULL;
150 sbi->ll_foreign_symlink_upcall_nb_items = 0;
151 init_rwsem(&sbi->ll_foreign_symlink_sem);
152 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
153 * not enabled by default
156 sbi->ll_secctx_name = NULL;
157 sbi->ll_secctx_name_size = 0;
159 sbi->ll_ra_info.ra_max_pages =
160 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
161 /* on very small nodes (ie, testing VMs), we need a minimum readahead
162 * size to get sane testing behavior, so we try to enforce this
163 * minimum. This only kicks in at small RAM sizes, so generally won't
164 * affect real clients
166 if (sbi->ll_ra_info.ra_max_pages < SBI_DEFAULT_READ_AHEAD_MIN)
167 sbi->ll_ra_info.ra_max_pages =
168 min(pages / 2, SBI_DEFAULT_READ_AHEAD_MIN);
169 sbi->ll_ra_info.ra_max_pages_per_file =
170 min(sbi->ll_ra_info.ra_max_pages / 4,
171 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
172 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
173 sbi->ll_ra_info.ra_max_pages_per_file;
174 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
175 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
176 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
178 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
179 #ifdef CONFIG_ENABLE_CHECKSUM
180 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
182 #ifdef CONFIG_ENABLE_FLOCK
183 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
186 #ifdef HAVE_LRU_RESIZE_SUPPORT
187 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
189 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
191 /* metadata statahead is enabled by default */
192 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
193 sbi->ll_sa_batch_max = LL_SA_BATCH_DEF;
194 sbi->ll_sa_max = LL_SA_REQ_MAX_DEF;
195 sbi->ll_sa_min = LL_SA_REQ_MIN_DEF;
196 sbi->ll_sa_timeout = LL_SA_TIMEOUT_DEF;
197 atomic_set(&sbi->ll_sa_total, 0);
198 atomic_set(&sbi->ll_sa_wrong, 0);
199 atomic_set(&sbi->ll_sa_running, 0);
200 atomic_set(&sbi->ll_agl_total, 0);
201 atomic_set(&sbi->ll_sa_hit_total, 0);
202 atomic_set(&sbi->ll_sa_miss_total, 0);
203 atomic_set(&sbi->ll_sa_list_total, 0);
204 atomic_set(&sbi->ll_sa_fname_total, 0);
205 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
206 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
207 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
208 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
209 set_bit(LL_SBI_UNALIGNED_DIO, sbi->ll_flags);
210 set_bit(LL_SBI_STATFS_PROJECT, sbi->ll_flags);
211 ll_sbi_set_encrypt(sbi, true);
212 ll_sbi_set_name_encrypt(sbi, true);
213 set_bit(LL_SBI_HYBRID_IO, sbi->ll_flags);
216 sbi->ll_squash.rsi_uid = 0;
217 sbi->ll_squash.rsi_gid = 0;
218 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
219 spin_lock_init(&sbi->ll_squash.rsi_lock);
221 /* Per-filesystem file heat */
222 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
223 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
225 /* Per-fs open heat level before requesting open lock */
226 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
227 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
228 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
230 INIT_LIST_HEAD(&sbi->ll_all_quota_list);
233 if (sbi->ll_foreign_symlink_prefix)
234 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
236 cl_cache_decref(sbi->ll_cache);
237 sbi->ll_cache = NULL;
239 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
241 pcc_super_fini(&sbi->ll_pcc_super);
247 static void ll_free_sbi(struct super_block *sb)
249 struct ll_sb_info *sbi = ll_s2sbi(sb);
253 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
254 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
255 if (sbi->ll_ra_info.ll_readahead_wq)
256 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
257 if (sbi->ll_cache != NULL) {
258 cl_cache_decref(sbi->ll_cache);
259 sbi->ll_cache = NULL;
261 if (sbi->ll_foreign_symlink_prefix) {
262 OBD_FREE(sbi->ll_foreign_symlink_prefix,
263 sbi->ll_foreign_symlink_prefix_size);
264 sbi->ll_foreign_symlink_prefix = NULL;
266 if (sbi->ll_foreign_symlink_upcall) {
267 OBD_FREE(sbi->ll_foreign_symlink_upcall,
268 strlen(sbi->ll_foreign_symlink_upcall) +
270 sbi->ll_foreign_symlink_upcall = NULL;
272 if (sbi->ll_foreign_symlink_upcall_items) {
274 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
275 struct ll_foreign_symlink_upcall_item *items =
276 sbi->ll_foreign_symlink_upcall_items;
278 for (i = 0 ; i < nb_items; i++)
279 if (items[i].type == STRING_TYPE)
280 OBD_FREE(items[i].string,
283 OBD_FREE_LARGE(items, nb_items *
284 sizeof(struct ll_foreign_symlink_upcall_item));
285 sbi->ll_foreign_symlink_upcall_items = NULL;
287 if (sbi->ll_secctx_name)
288 ll_secctx_name_free(sbi);
290 ll_free_rw_stats_info(sbi);
291 pcc_super_fini(&sbi->ll_pcc_super);
292 OBD_FREE(sbi, sizeof(*sbi));
297 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
299 struct inode *root = NULL;
300 struct ll_sb_info *sbi = ll_s2sbi(sb);
301 struct obd_statfs *osfs = NULL;
302 struct ptlrpc_request *request = NULL;
303 struct obd_connect_data *data = NULL;
304 struct obd_uuid *uuid;
305 struct md_op_data *op_data;
306 struct lustre_md lmd;
308 int size, err, checksum;
314 sbi->ll_md_obd = class_name2obd(md);
315 if (!sbi->ll_md_obd) {
316 CERROR("MD %s: not setup or attached\n", md);
330 /* pass client page size via ocd_grant_blkbits, the server should report
331 * back its backend blocksize for grant calculation purpose */
332 data->ocd_grant_blkbits = PAGE_SHIFT;
334 /* indicate MDT features supported by this client */
335 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
336 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
337 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
338 OBD_CONNECT_SRVLOCK |
339 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
340 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
341 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
342 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
343 OBD_CONNECT_64BITHASH |
344 OBD_CONNECT_EINPROGRESS |
345 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
346 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
347 OBD_CONNECT_MAX_EASIZE |
348 OBD_CONNECT_FLOCK_DEAD |
349 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
350 OBD_CONNECT_OPEN_BY_FID |
351 OBD_CONNECT_DIR_STRIPE |
352 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
353 OBD_CONNECT_SUBTREE |
354 OBD_CONNECT_MULTIMODRPCS |
355 OBD_CONNECT_GRANT_PARAM |
356 OBD_CONNECT_GRANT_SHRINK |
357 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
359 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
360 OBD_CONNECT2_SUM_STATFS |
361 OBD_CONNECT2_OVERSTRIPING |
363 OBD_CONNECT2_LOCK_CONVERT |
364 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
365 OBD_CONNECT2_INC_XID |
367 OBD_CONNECT2_ASYNC_DISCARD |
369 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
370 OBD_CONNECT2_GETATTR_PFID |
371 OBD_CONNECT2_DOM_LVB |
372 OBD_CONNECT2_REP_MBITS |
373 OBD_CONNECT2_ATOMIC_OPEN_LOCK |
374 OBD_CONNECT2_BATCH_RPC |
375 OBD_CONNECT2_DMV_IMP_INHERIT |
376 OBD_CONNECT2_UNALIGNED_DIO;
378 #ifdef HAVE_LRU_RESIZE_SUPPORT
379 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
380 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
382 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
384 data->ocd_cksum_types = obd_cksum_types_supported_client();
386 if (CFS_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
387 /* flag mdc connection as lightweight, only used for test
388 * purpose, use with care */
389 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
391 data->ocd_ibits_known = MDS_INODELOCK_FULL;
392 data->ocd_version = LUSTRE_VERSION_CODE;
394 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
395 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
398 /* Setting this indicates we correctly support S_NOSEC (See kernel
399 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
401 sb->s_flags |= SB_NOSEC;
403 sbi->ll_fop = ll_select_file_operations(sbi);
405 /* always ping even if server suppress_pings */
406 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
407 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
409 obd_connect_set_secctx(data);
410 if (ll_sbi_has_encrypt(sbi)) {
411 obd_connect_set_enc_fid2path(data);
412 obd_connect_set_name_enc(data);
413 obd_connect_set_enc(data);
416 #if defined(CONFIG_SECURITY)
417 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
420 data->ocd_brw_size = MD_MAX_BRW_SIZE;
423 if (sb->s_flags & SB_RDONLY)
424 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
425 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
426 &sbi->ll_sb_uuid, data, sbi->ll_cache);
428 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
429 "recovery, of which this client is not a "
430 "part. Please wait for recovery to complete,"
431 " abort, or time out.\n", md);
434 CERROR("cannot connect to %s: rc = %d\n", md, err);
438 sbi->ll_md_exp->exp_connect_data = *data;
440 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
441 LUSTRE_SEQ_METADATA);
443 CERROR("%s: Can't init metadata layer FID infrastructure, "
444 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
448 /* For mount, we only need fs info from MDT0, and also in DNE, it
449 * can make sure the client can be mounted as long as MDT0 is
451 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
452 ktime_get_seconds() - sbi->ll_statfs_max_age,
453 OBD_STATFS_FOR_MDT0);
454 if (err == -EROFS && !(sb->s_flags & SB_RDONLY)) {
455 /* We got -EROFS from the server, maybe it is imposing
456 * read-only mount. So just retry like this.
458 cfs_tty_write_msg("Forcing read-only mount.\n\r");
459 CERROR("%s: mount failed with %d, forcing read-only mount.\n",
460 sbi->ll_md_exp->exp_obd->obd_name, err);
461 sb->s_flags |= SB_RDONLY;
462 obd_fid_fini(sbi->ll_md_exp->exp_obd);
463 obd_disconnect(sbi->ll_md_exp);
464 GOTO(retry_connect, err);
466 GOTO(out_md_fid, err);
469 /* This needs to be after statfs to ensure connect has finished.
470 * Note that "data" does NOT contain the valid connect reply.
471 * If connecting to a 1.8 server there will be no LMV device, so
472 * we can access the MDC export directly and exp_connect_flags will
473 * be non-zero, but if accessing an upgraded 2.1 server it will
474 * have the correct flags filled in.
475 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
476 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
477 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
478 valid != CLIENT_CONNECT_MDT_REQD) {
481 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
482 obd_connect_flags2str(buf, PAGE_SIZE,
483 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
484 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
485 "feature(s) needed for correct operation "
486 "of this client (%s). Please upgrade "
487 "server or downgrade client.\n",
488 sbi->ll_md_exp->exp_obd->obd_name, buf);
489 OBD_FREE(buf, PAGE_SIZE);
490 GOTO(out_md_fid, err = -EPROTO);
493 size = sizeof(*data);
494 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
495 KEY_CONN_DATA, &size, data);
497 CERROR("%s: Get connect data failed: rc = %d\n",
498 sbi->ll_md_exp->exp_obd->obd_name, err);
499 GOTO(out_md_fid, err);
502 LASSERT(osfs->os_bsize);
503 sb->s_blocksize = osfs->os_bsize;
504 sb->s_blocksize_bits = log2(osfs->os_bsize);
505 sb->s_magic = LL_SUPER_MAGIC;
506 sb->s_maxbytes = MAX_LFS_FILESIZE;
507 sbi->ll_inode_cache_enabled = 1;
508 sbi->ll_namelen = osfs->os_namelen;
509 sbi->ll_mnt.mnt = current->fs->root.mnt;
510 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
512 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
513 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
514 LCONSOLE_INFO("Disabling user_xattr feature because "
515 "it is not supported on the server\n");
516 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
519 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
521 sb->s_flags |= SB_POSIXACL;
523 set_bit(LL_SBI_ACL, sbi->ll_flags);
525 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
527 sb->s_flags &= ~SB_POSIXACL;
529 clear_bit(LL_SBI_ACL, sbi->ll_flags);
532 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
533 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
535 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
536 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
538 if (obd_connect_has_secctx(data))
539 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
541 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
542 if (ll_sb_has_test_dummy_encryption(sb))
543 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
545 sbi->ll_md_exp->exp_obd->obd_name);
546 ll_sbi_set_encrypt(sbi, false);
549 if (ll_sbi_has_name_encrypt(sbi) && !obd_connect_has_name_enc(data)) {
550 struct lustre_sb_info *lsi = s2lsi(sb);
552 if (ll_sb_has_test_dummy_encryption(sb))
553 LCONSOLE_WARN("%s: server %s does not support name encryption, not using it.\n",
555 sbi->ll_md_exp->exp_obd->obd_name);
556 #ifdef CONFIG_LL_ENCRYPTION
557 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
559 lsi->lsi_flags &= ~LSI_FILENAME_ENC_B64_OLD_CLI;
560 ll_sbi_set_name_encrypt(sbi, false);
563 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
564 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
565 LCONSOLE_INFO("%s: disabling xattr cache due to "
566 "unknown maximum xattr size.\n", dt);
567 } else if (!sbi->ll_xattr_cache_set) {
568 /* If xattr_cache is already set (no matter 0 or 1)
569 * during processing llog, it won't be enabled here. */
570 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
571 sbi->ll_xattr_cache_enabled = 1;
575 sbi->ll_dt_obd = class_name2obd(dt);
576 if (!sbi->ll_dt_obd) {
577 CERROR("DT %s: not setup or attached\n", dt);
578 GOTO(out_md_fid, err = -ENODEV);
581 /* pass client page size via ocd_grant_blkbits, the server should report
582 * back its backend blocksize for grant calculation purpose */
583 data->ocd_grant_blkbits = PAGE_SHIFT;
585 /* indicate OST features supported by this client */
586 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
587 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
588 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
589 OBD_CONNECT_SRVLOCK |
590 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
591 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
592 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
593 OBD_CONNECT_EINPROGRESS |
594 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
595 OBD_CONNECT_LAYOUTLOCK |
596 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
597 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
598 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
599 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
600 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
601 OBD_CONNECT2_REP_MBITS |
602 OBD_CONNECT2_UNALIGNED_DIO;
604 if (!CFS_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
605 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
607 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
608 * disabled by default, because it can still be enabled on the
609 * fly via /sys. As a consequence, we still need to come to an
610 * agreement on the supported algorithms at connect time
612 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
614 if (CFS_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
615 data->ocd_cksum_types = OBD_CKSUM_ADLER;
617 data->ocd_cksum_types = obd_cksum_types_supported_client();
619 #ifdef HAVE_LRU_RESIZE_SUPPORT
620 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
622 /* always ping even if server suppress_pings */
623 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
624 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
626 if (ll_sbi_has_encrypt(sbi))
627 obd_connect_set_enc(data);
629 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
630 "ocd_grant: %d\n", data->ocd_connect_flags,
631 data->ocd_version, data->ocd_grant);
633 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
634 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
636 data->ocd_brw_size = DT_MAX_BRW_SIZE;
638 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
639 &sbi->ll_sb_uuid, data, sbi->ll_cache);
641 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
642 "recovery, of which this client is not a "
643 "part. Please wait for recovery to "
644 "complete, abort, or time out.\n", dt);
647 CERROR("%s: Cannot connect to %s: rc = %d\n",
648 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
652 if (ll_sbi_has_encrypt(sbi) &&
653 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
654 if (ll_sb_has_test_dummy_encryption(sb))
655 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
657 ll_sbi_set_encrypt(sbi, false);
658 } else if (ll_sb_has_test_dummy_encryption(sb)) {
659 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
662 /* If unaligned DIO is not supported, hybrid IO will result in EINVAL,
663 * so turn hybrid IO off by default. If the user turns it back on, they
664 * will get EINVAL, but should be able to figure out the cause.
666 if (test_bit(LL_SBI_HYBRID_IO, sbi->ll_flags) &&
667 !obd_connect_has_unaligned_dio(&sbi->ll_dt_obd->u.lov.lov_ocd))
668 clear_bit(LL_SBI_HYBRID_IO, sbi->ll_flags);
670 sbi->ll_dt_exp->exp_connect_data = *data;
672 /* Don't change value if it was specified in the config log */
673 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
674 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
675 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
676 (data->ocd_brw_size >> PAGE_SHIFT));
677 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
678 sbi->ll_ra_info.ra_max_pages_per_file)
679 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
680 sbi->ll_ra_info.ra_max_pages_per_file;
683 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
684 LUSTRE_SEQ_METADATA);
686 CERROR("%s: Can't init data layer FID infrastructure, "
687 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
691 mutex_lock(&sbi->ll_lco.lco_lock);
692 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
693 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
694 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
695 mutex_unlock(&sbi->ll_lco.lco_lock);
697 fid_zero(&sbi->ll_root_fid);
698 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
701 CERROR("cannot mds_connect: rc = %d\n", err);
702 GOTO(out_lock_cn_cb, err);
704 if (!fid_is_sane(&sbi->ll_root_fid)) {
705 CERROR("%s: Invalid root fid "DFID" during mount\n",
706 sbi->ll_md_exp->exp_obd->obd_name,
707 PFID(&sbi->ll_root_fid));
708 GOTO(out_lock_cn_cb, err = -EINVAL);
710 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
712 sb->s_op = &lustre_super_operations;
713 sb->s_xattr = ll_xattr_handlers;
714 #if THREAD_SIZE >= 8192 /*b=17630*/
715 sb->s_export_op = &lustre_export_operations;
717 #ifdef HAVE_LUSTRE_CRYPTO
718 llcrypt_set_ops(sb, &lustre_cryptops);
722 * XXX: move this to after cbd setup? */
723 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
725 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
726 valid |= OBD_MD_FLACL;
728 OBD_ALLOC_PTR(op_data);
730 GOTO(out_lock_cn_cb, err = -ENOMEM);
732 op_data->op_fid1 = sbi->ll_root_fid;
733 op_data->op_mode = 0;
734 op_data->op_valid = valid;
736 err = md_getattr(sbi->ll_md_exp, op_data, &request);
738 /* We need enc ctx info, so reset it in op_data to
739 * prevent it from being freed.
741 encctx = op_data->op_file_encctx;
742 encctxlen = op_data->op_file_encctx_size;
743 op_data->op_file_encctx = NULL;
744 op_data->op_file_encctx_size = 0;
745 OBD_FREE_PTR(op_data);
747 CERROR("%s: md_getattr failed for root: rc = %d\n",
748 sbi->ll_md_exp->exp_obd->obd_name, err);
749 GOTO(out_lock_cn_cb, err);
752 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
753 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
755 CERROR("failed to understand root inode md: rc = %d\n", err);
756 ptlrpc_req_finished(request);
757 GOTO(out_lock_cn_cb, err);
760 LASSERT(fid_is_sane(&sbi->ll_root_fid));
761 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
762 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
763 md_put_lustre_md(sbi->ll_md_exp, &lmd);
767 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
769 CERROR("%s: bad ll_iget() for root: rc = %d\n",
770 sbi->ll_fsname, err);
771 ptlrpc_req_finished(request);
775 err = ll_secctx_name_store(root);
776 if (err < 0 && ll_security_xattr_wanted(root))
777 CWARN("%s: file security contextes not supported: rc = %d\n",
778 sbi->ll_fsname, err);
783 "server returned encryption ctx for root inode "DFID"\n",
784 PFID(&sbi->ll_root_fid));
785 err = ll_set_encflags(root, encctx, encctxlen, true);
787 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
789 PFID(&sbi->ll_root_fid), err);
791 ptlrpc_req_finished(request);
793 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
794 if (sbi->ll_checksum_set) {
795 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
796 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
797 sizeof(checksum), &checksum, NULL);
799 CERROR("%s: Set checksum failed: rc = %d\n",
800 sbi->ll_dt_exp->exp_obd->obd_name, err);
806 sb->s_root = d_make_root(root);
807 if (sb->s_root == NULL) {
809 CERROR("%s: can't make root dentry: rc = %d\n",
810 sbi->ll_fsname, err);
814 sbi->ll_sdev_orig = sb->s_dev;
816 /* We set sb->s_dev equal on all lustre clients in order to support
817 * NFS export clustering. NFSD requires that the FSID be the same
819 /* s_dev is also used in lt_compare() to compare two fs, but that is
820 * only a node-local comparison. */
821 uuid = obd_get_uuid(sbi->ll_md_exp);
823 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
830 if (sbi->ll_dt_obd) {
831 err = sysfs_create_link(&sbi->ll_kset.kobj,
832 &sbi->ll_dt_obd->obd_kset.kobj,
833 sbi->ll_dt_obd->obd_type->typ_name);
835 CERROR("%s: could not register %s in llite: rc = %d\n",
836 dt, sbi->ll_fsname, err);
841 if (sbi->ll_md_obd) {
842 err = sysfs_create_link(&sbi->ll_kset.kobj,
843 &sbi->ll_md_obd->obd_kset.kobj,
844 sbi->ll_md_obd->obd_type->typ_name);
846 CERROR("%s: could not register %s in llite: rc = %d\n",
847 md, sbi->ll_fsname, err);
856 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
858 obd_disconnect(sbi->ll_dt_exp);
859 sbi->ll_dt_exp = NULL;
860 sbi->ll_dt_obd = NULL;
862 obd_fid_fini(sbi->ll_md_exp->exp_obd);
864 obd_disconnect(sbi->ll_md_exp);
865 sbi->ll_md_exp = NULL;
866 sbi->ll_md_obd = NULL;
875 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
879 size = sizeof(*lmmsize);
880 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
881 KEY_MAX_EASIZE, &size, lmmsize);
883 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
884 sbi->ll_dt_exp->exp_obd->obd_name, rc);
888 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
891 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
892 KEY_MAX_EASIZE, &size, lmmsize);
894 CERROR("Get max mdsize error rc %d\n", rc);
896 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
902 * Get the value of the default_easize parameter.
904 * \see client_obd::cl_default_mds_easize
906 * \param[in] sbi superblock info for this filesystem
907 * \param[out] lmmsize pointer to storage location for value
909 * \retval 0 on success
910 * \retval negative negated errno on failure
912 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
917 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
918 KEY_DEFAULT_EASIZE, &size, lmmsize);
920 CERROR("Get default mdsize error rc %d\n", rc);
926 * Set the default_easize parameter to the given value.
928 * \see client_obd::cl_default_mds_easize
930 * \param[in] sbi superblock info for this filesystem
931 * \param[in] lmmsize the size to set
933 * \retval 0 on success
934 * \retval negative negated errno on failure
936 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
940 if (lmmsize < sizeof(struct lov_mds_md) ||
941 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
944 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
945 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
946 sizeof(int), &lmmsize, NULL);
951 static void client_common_put_super(struct super_block *sb)
953 struct ll_sb_info *sbi = ll_s2sbi(sb);
958 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
959 obd_disconnect(sbi->ll_dt_exp);
960 sbi->ll_dt_exp = NULL;
962 ll_debugfs_unregister_super(sb);
964 obd_fid_fini(sbi->ll_md_exp->exp_obd);
965 obd_disconnect(sbi->ll_md_exp);
966 sbi->ll_md_exp = NULL;
971 void ll_kill_super(struct super_block *sb)
973 struct ll_sb_info *sbi;
977 if (!(sb->s_flags & SB_ACTIVE))
981 /* we need restore s_dev from changed for clustred NFS before put_super
982 * because new kernels have cached s_dev and change sb->s_dev in
983 * put_super not affected real removing devices */
985 sb->s_dev = sbi->ll_sdev_orig;
987 /* wait running statahead threads to quit */
988 while (atomic_read(&sbi->ll_sa_running) > 0)
989 schedule_timeout_uninterruptible(
990 cfs_time_seconds(1) >> 3);
996 /* Since we use this table for ll_sbi_flags_seq_show make
997 * sure what you want displayed for a specific token that
998 * is listed more than once below be listed first. For
999 * example we want "checksum" displayed, not "nochecksum"
1000 * for the sbi_flags.
1002 static const match_table_t ll_sbi_flags_name = {
1003 {LL_SBI_NOLCK, "nolock"},
1004 {LL_SBI_CHECKSUM, "checksum"},
1005 {LL_SBI_CHECKSUM, "nochecksum"},
1006 {LL_SBI_LOCALFLOCK, "localflock"},
1007 {LL_SBI_FLOCK, "flock"},
1008 {LL_SBI_FLOCK, "noflock"},
1009 {LL_SBI_USER_XATTR, "user_xattr"},
1010 {LL_SBI_USER_XATTR, "nouser_xattr"},
1011 {LL_SBI_LRU_RESIZE, "lruresize"},
1012 {LL_SBI_LRU_RESIZE, "nolruresize"},
1013 {LL_SBI_LAZYSTATFS, "lazystatfs"},
1014 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
1015 {LL_SBI_32BIT_API, "32bitapi"},
1016 {LL_SBI_USER_FID2PATH, "user_fid2path"},
1017 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
1018 {LL_SBI_VERBOSE, "verbose"},
1019 {LL_SBI_VERBOSE, "noverbose"},
1020 {LL_SBI_ALWAYS_PING, "always_ping"},
1021 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
1022 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
1023 {LL_SBI_ENCRYPT, "encrypt"},
1024 {LL_SBI_ENCRYPT, "noencrypt"},
1025 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
1026 {LL_SBI_STATFS_PROJECT, "statfs_project"},
1027 {LL_SBI_STATFS_PROJECT, "nostatfs_project"},
1028 {LL_SBI_NUM_MOUNT_OPT, NULL},
1030 {LL_SBI_ACL, "acl"},
1031 {LL_SBI_AGL_ENABLED, "agl"},
1032 {LL_SBI_64BIT_HASH, "64bit_hash"},
1033 {LL_SBI_LAYOUT_LOCK, "layout"},
1034 {LL_SBI_XATTR_CACHE, "xattr_cache"},
1035 {LL_SBI_NOROOTSQUASH, "norootsquash"},
1036 {LL_SBI_FAST_READ, "fast_read"},
1037 {LL_SBI_FILE_SECCTX, "file_secctx"},
1038 {LL_SBI_TINY_WRITE, "tiny_write"},
1039 {LL_SBI_FILE_HEAT, "file_heat"},
1040 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
1041 {LL_SBI_HYBRID_IO, "hybrid_io"},
1042 {LL_SBI_ENCRYPT_NAME, "name_encrypt"},
1043 {LL_SBI_UNALIGNED_DIO, "unaligned_dio"},
1046 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
1048 struct super_block *sb = m->private;
1051 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
1054 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
1057 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
1058 if (ll_sbi_flags_name[j].token == i &&
1059 ll_sbi_flags_name[j].pattern) {
1060 seq_printf(m, "%s ",
1061 ll_sbi_flags_name[j].pattern);
1066 seq_puts(m, "\b\n");
1070 /* non-client-specific mount options are parsed in lmd_parse */
1071 static int ll_options(char *options, struct super_block *sb)
1073 struct ll_sb_info *sbi = ll_s2sbi(sb);
1074 char *s2, *s1, *opts, *orig_opts;
1081 /* Don't stomp on lmd_opts */
1082 orig_opts = opts = kstrdup(options, GFP_KERNEL);
1088 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1090 while ((s1 = strsep(&opts, ",")) != NULL) {
1091 substring_t args[MAX_OPT_ARGS];
1092 bool turn_off = false;
1098 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1100 if (strncmp(s1, "no", 2) == 0)
1104 * Initialize args struct so we know whether arg was
1105 * found; some options take optional arguments.
1108 args[0].from = NULL;
1109 token = match_token(s1, ll_sbi_flags_name, args);
1110 if (token == LL_SBI_NUM_MOUNT_OPT) {
1111 if (match_wildcard("context", s1) ||
1112 match_wildcard("fscontext", s1) ||
1113 match_wildcard("defcontext", s1) ||
1114 match_wildcard("rootcontext",s1))
1117 LCONSOLE_ERROR_MSG(0x152,
1118 "Unknown option '%s', won't mount.\n",
1125 case LL_SBI_32BIT_API:
1126 case LL_SBI_64BIT_HASH:
1127 case LL_SBI_ALWAYS_PING:
1128 set_bit(token, sbi->ll_flags);
1132 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1134 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1136 set_bit(token, sbi->ll_flags);
1139 case LL_SBI_LOCALFLOCK:
1140 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1141 set_bit(token, sbi->ll_flags);
1144 case LL_SBI_CHECKSUM:
1145 sbi->ll_checksum_set = 1;
1147 case LL_SBI_USER_XATTR:
1148 case LL_SBI_USER_FID2PATH:
1149 case LL_SBI_LRU_RESIZE:
1150 case LL_SBI_LAZYSTATFS:
1151 case LL_SBI_VERBOSE:
1152 case LL_SBI_STATFS_PROJECT:
1154 clear_bit(token, sbi->ll_flags);
1156 set_bit(token, sbi->ll_flags);
1158 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1159 #ifdef HAVE_LUSTRE_CRYPTO
1160 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1161 set_bit(token, sbi->ll_flags);
1163 struct lustre_sb_info *lsi = s2lsi(sb);
1165 err = llcrypt_set_test_dummy_encryption(sb,
1166 #ifdef HAVE_FSCRYPT_SET_TEST_DUMMY_ENC_CHAR_ARG
1171 &lsi->lsi_dummy_enc_policy);
1177 "Can't change test_dummy_encryption");
1178 else if (err == -EINVAL)
1180 "Value of option \"%s\" unrecognized",
1184 "Error processing option \"%s\" [%d]",
1189 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1193 case LL_SBI_ENCRYPT:
1194 #ifdef HAVE_LUSTRE_CRYPTO
1196 clear_bit(token, sbi->ll_flags);
1198 set_bit(token, sbi->ll_flags);
1200 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1203 case LL_SBI_FOREIGN_SYMLINK:
1204 /* non-default prefix provided ? */
1209 /* path must be absolute */
1210 if (args->from[0] != '/') {
1211 LCONSOLE_ERROR_MSG(0x152,
1212 "foreign prefix '%s' must be an absolute path\n",
1217 old_len = sbi->ll_foreign_symlink_prefix_size;
1218 old = sbi->ll_foreign_symlink_prefix;
1219 /* alloc for path length and '\0' */
1220 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1221 if (!sbi->ll_foreign_symlink_prefix) {
1222 /* restore previous */
1223 sbi->ll_foreign_symlink_prefix = old;
1224 sbi->ll_foreign_symlink_prefix_size =
1228 sbi->ll_foreign_symlink_prefix_size =
1229 args->to - args->from + 1;
1230 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1231 sbi->ll_foreign_symlink_prefix_size,
1234 OBD_FREE(old, old_len);
1236 /* enable foreign symlink support */
1237 set_bit(token, sbi->ll_flags);
1239 LCONSOLE_ERROR_MSG(0x152,
1240 "invalid %s option\n", s1);
1251 void ll_lli_init(struct ll_inode_info *lli)
1253 lli->lli_inode_magic = LLI_INODE_MAGIC;
1255 rwlock_init(&lli->lli_lock);
1256 lli->lli_posix_acl = NULL;
1257 /* Do not set lli_fid, it has been initialized already. */
1258 fid_zero(&lli->lli_pfid);
1259 lli->lli_mds_read_och = NULL;
1260 lli->lli_mds_write_och = NULL;
1261 lli->lli_mds_exec_och = NULL;
1262 lli->lli_open_fd_read_count = 0;
1263 lli->lli_open_fd_write_count = 0;
1264 lli->lli_open_fd_exec_count = 0;
1265 mutex_init(&lli->lli_och_mutex);
1266 spin_lock_init(&lli->lli_agl_lock);
1267 spin_lock_init(&lli->lli_layout_lock);
1268 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1269 lli->lli_clob = NULL;
1271 init_rwsem(&lli->lli_xattrs_list_rwsem);
1272 mutex_init(&lli->lli_xattrs_enq_lock);
1274 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1275 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1276 lli->lli_opendir_key = NULL;
1277 lli->lli_sai = NULL;
1278 spin_lock_init(&lli->lli_sa_lock);
1279 lli->lli_opendir_pid = 0;
1280 lli->lli_sa_enabled = 0;
1281 init_rwsem(&lli->lli_lsm_sem);
1283 mutex_init(&lli->lli_size_mutex);
1284 mutex_init(&lli->lli_setattr_mutex);
1285 lli->lli_symlink_name = NULL;
1286 ll_trunc_sem_init(&lli->lli_trunc_sem);
1287 range_lock_tree_init(&lli->lli_write_tree);
1288 init_rwsem(&lli->lli_glimpse_sem);
1289 lli->lli_glimpse_time = ktime_set(0, 0);
1290 INIT_LIST_HEAD(&lli->lli_agl_list);
1291 lli->lli_agl_index = 0;
1292 lli->lli_async_rc = 0;
1293 spin_lock_init(&lli->lli_heat_lock);
1294 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1295 lli->lli_heat_flags = 0;
1296 mutex_init(&lli->lli_pcc_lock);
1297 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1298 lli->lli_pcc_inode = NULL;
1299 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1300 lli->lli_pcc_generation = 0;
1301 mutex_init(&lli->lli_group_mutex);
1302 lli->lli_group_users = 0;
1303 lli->lli_group_gid = 0;
1304 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1305 lli->lli_uid = (__u32) -1;
1306 lli->lli_gid = (__u32) -1;
1308 mutex_init(&lli->lli_layout_mutex);
1309 lli->lli_layout_lock_owner = NULL;
1310 /* ll_cl_context initialize */
1311 INIT_LIST_HEAD(&lli->lli_lccs);
1312 seqlock_init(&lli->lli_page_inv_lock);
1313 lli->lli_inode_lock_owner = NULL;
1316 #define MAX_STRING_SIZE 128
1318 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1319 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1321 struct lustre_sb_info *lsi = s2lsi(sb);
1322 char buf[MAX_STRING_SIZE];
1326 err = bdi_init(&lsi->lsi_bdi);
1330 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1331 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1332 lsi->lsi_bdi.name = "lustre";
1333 va_start(args, fmt);
1334 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1336 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1339 sb->s_bdi = &lsi->lsi_bdi;
1343 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1345 int ll_fill_super(struct super_block *sb)
1347 struct lustre_profile *lprof = NULL;
1348 struct lustre_sb_info *lsi = s2lsi(sb);
1349 struct ll_sb_info *sbi = NULL;
1350 char *dt = NULL, *md = NULL;
1351 char *profilenm = get_profile_name(sb);
1352 struct config_llog_instance *cfg;
1353 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1354 const int instlen = LUSTRE_MAXINSTANCE + 2;
1355 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1356 char name[MAX_STRING_SIZE];
1365 /* for ASLR, to map between cfg_instance and hashed ptr */
1366 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1367 profilenm, cfg_instance, sb);
1369 CFS_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1373 GOTO(out_free_cfg, err = -ENOMEM);
1375 /* client additional sb info */
1376 lsi->lsi_llsbi = sbi = ll_init_sbi(lsi);
1378 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1380 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1382 GOTO(out_free_cfg, err);
1384 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1385 #ifdef CONFIG_LL_ENCRYPTION
1386 if (ll_sb_has_test_dummy_encryption(sb))
1387 /* enable filename encryption by default for dummy enc mode */
1388 lsi->lsi_flags |= LSI_FILENAME_ENC;
1390 /* filename encryption is disabled by default */
1391 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1394 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1395 sb->s_d_op = &ll_d_ops;
1398 generate_random_uuid(uuid.b);
1399 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1401 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1404 len = strlen(profilenm);
1405 ptr = strrchr(profilenm, '-');
1406 if (ptr && (strcmp(ptr, "-client") == 0))
1409 if (len > LUSTRE_MAXFSNAME) {
1410 if (unlikely(len >= MAX_STRING_SIZE))
1411 len = MAX_STRING_SIZE - 1;
1412 strncpy(name, profilenm, len);
1414 err = -ENAMETOOLONG;
1415 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1416 name, LUSTRE_MAXFSNAME, err);
1417 GOTO(out_free_cfg, err);
1419 strncpy(sbi->ll_fsname, profilenm, len);
1420 sbi->ll_fsname[len] = '\0';
1423 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1424 profilenm, cfg_instance);
1426 err = super_setup_bdi_name(sb, "%s", name);
1428 GOTO(out_free_cfg, err);
1430 /* disable kernel readahead */
1431 sb->s_bdi->ra_pages = 0;
1432 #ifdef HAVE_BDI_IO_PAGES
1433 sb->s_bdi->io_pages = 0;
1435 sb->s_bdi->capabilities |= LL_BDI_CAP_FLAGS;
1436 #ifdef SB_I_CGROUPWB
1437 sb->s_iflags |= SB_I_CGROUPWB;
1440 /* Call ll_debugfs_register_super() before lustre_process_log()
1441 * so that "llite.*.*" params can be processed correctly.
1443 err = ll_debugfs_register_super(sb, name);
1445 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1446 sbi->ll_fsname, err);
1450 /* The cfg_instance is a value unique to this super, in case some
1451 * joker tries to mount the same fs at two mount points.
1453 cfg->cfg_instance = cfg_instance;
1454 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1455 cfg->cfg_callback = class_config_llog_handler;
1456 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1457 /* set up client obds */
1458 err = lustre_process_log(sb, profilenm, cfg);
1460 GOTO(out_debugfs, err);
1462 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1463 lprof = class_get_profile(profilenm);
1464 if (lprof == NULL) {
1465 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1466 " read from the MGS. Does that filesystem "
1467 "exist?\n", profilenm);
1468 GOTO(out_debugfs, err = -EINVAL);
1470 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1471 lprof->lp_md, lprof->lp_dt);
1473 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1474 OBD_ALLOC(dt, dt_len);
1476 GOTO(out_profile, err = -ENOMEM);
1477 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1479 md_len = strlen(lprof->lp_md) + instlen + 2;
1480 OBD_ALLOC(md, md_len);
1482 GOTO(out_free_dt, err = -ENOMEM);
1483 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1485 /* connections, registrations, sb setup */
1486 err = client_common_fill_super(sb, md, dt);
1488 GOTO(out_free_md, err);
1490 sbi->ll_client_common_fill_super_succeeded = 1;
1494 OBD_FREE(md, md_len);
1497 OBD_FREE(dt, dt_len);
1500 class_put_profile(lprof);
1503 ll_debugfs_unregister_super(sb);
1510 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1511 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1512 sb->s_flags & SB_RDONLY ? " read-only" : "");
1514 } /* ll_fill_super */
1516 static void ll_bdi_device_unregister(struct backing_dev_info *bdi)
1518 if (bdi->dev == NULL)
1521 #if defined(SB_I_CGROUPWB) && !defined(SB_I_PERSB_BDI)
1522 #ifdef HAVE_BDI_DEBUG_STATS
1523 debugfs_remove(bdi->debug_stats);
1524 debugfs_remove(bdi->debug_dir);
1526 debugfs_remove_recursive(bdi->debug_dir);
1528 device_unregister(bdi->dev);
1533 void ll_put_super(struct super_block *sb)
1535 struct config_llog_instance cfg, params_cfg;
1536 struct obd_device *obd;
1537 struct lustre_sb_info *lsi = s2lsi(sb);
1538 struct ll_sb_info *sbi = ll_s2sbi(sb);
1539 unsigned long dev_no = 0;
1540 char *profilenm = get_profile_name(sb);
1541 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1547 GOTO(out_no_sbi, 0);
1549 /* Should replace instance_id with something better for ASLR */
1550 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1551 profilenm, cfg_instance, sb);
1553 ll_quota_iter_check_and_cleanup(sbi, false);
1555 cfg.cfg_instance = cfg_instance;
1556 lustre_end_log(sb, profilenm, &cfg);
1558 params_cfg.cfg_instance = cfg_instance;
1559 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1561 if (sbi->ll_md_exp) {
1562 obd = class_exp2obd(sbi->ll_md_exp);
1564 force = obd->obd_force;
1567 /* We need to set force before the lov_disconnect in
1568 * lustre_common_put_super, since l_d cleans up osc's as well.
1572 obd_device_for_each_uuid(dev_no, obd, &sbi->ll_sb_uuid)
1573 obd->obd_force = force;
1574 obd_device_unlock();
1577 if (sbi->ll_client_common_fill_super_succeeded) {
1578 /* Only if client_common_fill_super succeeded */
1579 client_common_put_super(sb);
1582 /* imitate failed cleanup */
1583 if (CFS_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1587 * Cleanup, detach OBD devices, and remove them from Xarray.
1588 * We don't grab the xa_lock() since class_manual_cleanup()
1589 * uses the lock internally.
1591 obd_device_for_each_uuid(dev_no, obd, &sbi->ll_sb_uuid)
1592 class_manual_cleanup(obd);
1595 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1596 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1599 class_del_profile(profilenm);
1601 ll_bdi_device_unregister(sb->s_bdi);
1603 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1604 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1605 bdi_destroy(&lsi->lsi_bdi);
1606 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1610 llcrypt_free_dummy_policy(&lsi->lsi_dummy_enc_policy);
1612 lsi->lsi_llsbi = NULL;
1614 lustre_common_put_super(sb);
1616 cl_env_cache_purge(~0);
1619 } /* client_put_super */
1621 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1623 struct inode *inode = NULL;
1625 /* NOTE: we depend on atomic igrab() -bzzz */
1626 lock_res_and_lock(lock);
1627 if (lock->l_resource->lr_lvb_inode) {
1628 struct ll_inode_info * lli;
1629 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1630 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1631 inode = igrab(lock->l_resource->lr_lvb_inode);
1633 inode = lock->l_resource->lr_lvb_inode;
1634 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1635 D_WARNING, lock, "lr_lvb_inode %p is "
1636 "bogus: magic %08x",
1637 lock->l_resource->lr_lvb_inode,
1638 lli->lli_inode_magic);
1642 unlock_res_and_lock(lock);
1646 void ll_dir_clear_lsm_md(struct inode *inode)
1648 struct ll_inode_info *lli = ll_i2info(inode);
1650 LASSERT(S_ISDIR(inode->i_mode));
1651 down_write(&lli->lli_lsm_sem);
1652 lmv_stripe_object_put(&lli->lli_lsm_obj);
1653 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1654 up_write(&lli->lli_lsm_sem);
1657 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1658 const struct lu_fid *fid,
1659 struct lustre_md *md)
1661 struct ll_sb_info *sbi = ll_s2sbi(sb);
1662 struct ll_inode_info *lli;
1663 struct mdt_body *body = md->body;
1664 struct inode *inode;
1669 LASSERT(md->lsm_obj);
1670 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1671 inode = iget_locked(sb, ino);
1672 if (inode == NULL) {
1673 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1674 sbi->ll_fsname, PFID(fid));
1675 RETURN(ERR_PTR(-ENOENT));
1678 lli = ll_i2info(inode);
1679 if (inode->i_state & I_NEW) {
1680 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1681 (body->mbo_mode & S_IFMT);
1682 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1685 inode_set_mtime(inode, 0, 0);
1686 inode_set_atime(inode, 0, 0);
1687 inode_set_ctime(inode, 0, 0);
1690 #ifdef HAVE_BACKING_DEV_INFO
1691 /* initializing backing dev info. */
1692 inode->i_mapping->backing_dev_info =
1693 &s2lsi(inode->i_sb)->lsi_bdi;
1695 inode->i_op = &ll_dir_inode_operations;
1696 inode->i_fop = &ll_dir_operations;
1697 lli->lli_fid = *fid;
1700 /* master object FID */
1701 lli->lli_pfid = body->mbo_fid1;
1702 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1703 lli, PFID(fid), PFID(&lli->lli_pfid));
1704 unlock_new_inode(inode);
1706 /* in directory restripe/auto-split, a directory will be
1707 * transformed to a stripe if it's plain, set its pfid here,
1708 * otherwise ll_lock_cancel_bits() can't find the master inode.
1710 lli->lli_pfid = body->mbo_fid1;
1716 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1719 struct lmv_stripe_md *lsm;
1720 struct ll_inode_info *lli = ll_i2info(inode);
1723 LASSERT(md->lsm_obj != NULL);
1724 lsm = &md->lsm_obj->lso_lsm;
1726 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1727 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1728 lmv_stripe_object_dump(D_INODE, md->lsm_obj);
1730 if (!lmv_dir_striped(md->lsm_obj))
1733 /* XXX sigh, this lsm_root initialization should be in
1734 * LMV layer, but it needs ll_iget right now, so we
1735 * put this here right now. */
1736 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1737 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1738 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1740 if (!fid_is_sane(fid))
1743 /* Unfortunately ll_iget will call ll_update_inode,
1744 * where the initialization of slave inode is slightly
1745 * different, so it reset lsm_md to NULL to avoid
1746 * initializing lsm for slave inode. */
1747 lsm->lsm_md_oinfo[i].lmo_root =
1748 ll_iget_anon_dir(inode->i_sb, fid, md);
1749 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1750 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1752 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1754 iput(lsm->lsm_md_oinfo[i].lmo_root);
1755 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1761 /* move lsm_obj to lli */
1762 lli->lli_lsm_obj = md->lsm_obj;
1767 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1769 struct ll_inode_info *lli = ll_i2info(inode);
1770 struct lmv_stripe_object *lsm_obj = md->def_lsm_obj;
1774 /* clear default lsm */
1775 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set) {
1776 down_write(&lli->lli_lsm_sem);
1777 if (lli->lli_def_lsm_obj_set) {
1778 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1779 lli->lli_inherit_depth = 0;
1780 lli->lli_def_lsm_obj_set = 0;
1782 up_write(&lli->lli_lsm_sem);
1787 if (lli->lli_def_lsm_obj) {
1788 /* do nonthing if default lsm isn't changed */
1789 down_read(&lli->lli_lsm_sem);
1790 if (lli->lli_def_lsm_obj &&
1791 lsm_md_eq(lli->lli_def_lsm_obj, lsm_obj)) {
1792 up_read(&lli->lli_lsm_sem);
1795 up_read(&lli->lli_lsm_sem);
1797 down_write(&lli->lli_lsm_sem);
1799 /* update default lsm. */
1800 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1801 lli->lli_def_lsm_obj = lsm_obj;
1802 lli->lli_def_lsm_obj_set = 1;
1803 lmv_stripe_object_dump(D_INODE, lsm_obj);
1804 md->def_lsm_obj = NULL;
1805 up_write(&lli->lli_lsm_sem);
1809 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1811 struct ll_inode_info *lli = ll_i2info(inode);
1812 struct lmv_stripe_object *lsm_obj = md->lsm_obj;
1813 struct cl_attr *attr;
1818 LASSERT(S_ISDIR(inode->i_mode));
1819 CDEBUG(D_INODE, "update lsm_obj %p of "DFID"\n", lli->lli_lsm_obj,
1820 PFID(ll_inode2fid(inode)));
1822 /* update default LMV */
1823 if (md->def_lsm_obj)
1824 ll_update_default_lsm_md(inode, md);
1826 /* after dir migration/restripe, a stripe may be turned into a
1827 * directory, in this case, zero out its lli_pfid.
1829 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1830 fid_zero(&lli->lli_pfid);
1833 * no striped information from request, lustre_md from req does not
1834 * include stripeEA, see ll_md_setattr()
1840 * normally dir layout doesn't change, only take read lock to check
1841 * that to avoid blocking other MD operations.
1843 down_read(&lli->lli_lsm_sem);
1845 /* some current lookup initialized lsm, and unchanged */
1846 if (lli->lli_lsm_obj && lsm_md_eq(lli->lli_lsm_obj, lsm_obj)) {
1847 up_read(&lli->lli_lsm_sem);
1851 up_read(&lli->lli_lsm_sem);
1852 down_write(&lli->lli_lsm_sem);
1854 /* check again in case of a race */
1855 if (lli->lli_lsm_obj && lsm_md_eq(lli->lli_lsm_obj, lsm_obj))
1856 GOTO(unlock, rc = 0);
1858 /* if dir layout doesn't match, check whether version is increased,
1859 * which means layout is changed, this happens in dir split/merge and
1862 * foreign LMV should not change.
1864 if (lli->lli_lsm_obj && lmv_dir_striped(lli->lli_lsm_obj) &&
1865 lsm_obj->lso_lsm.lsm_md_layout_version <=
1866 lli->lli_lsm_obj->lso_lsm.lsm_md_layout_version) {
1867 CERROR("%s: "DFID" dir layout mismatch:\n",
1868 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1869 lmv_stripe_object_dump(D_ERROR, lli->lli_lsm_obj);
1870 lmv_stripe_object_dump(D_ERROR, lsm_obj);
1871 GOTO(unlock, rc = -EINVAL);
1874 /* clear existing lsm */
1875 lmv_stripe_object_put(&lli->lli_lsm_obj);
1877 rc = ll_init_lsm_md(inode, md);
1881 if (!lmv_dir_striped(lli->lli_lsm_obj))
1882 GOTO(unlock, rc = 0);
1884 lsm_obj = lmv_stripe_object_get(lli->lli_lsm_obj);
1885 up_write(&lli->lli_lsm_sem);
1887 OBD_ALLOC_PTR(attr);
1889 GOTO(err, rc = -ENOMEM);
1891 /* validate the lsm */
1892 rc = md_merge_attr(ll_i2mdexp(inode), lsm_obj, attr,
1893 ll_md_blocking_ast);
1895 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1896 md->body->mbo_nlink = attr->cat_nlink;
1897 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1898 md->body->mbo_size = attr->cat_size;
1899 if (md->body->mbo_valid & OBD_MD_FLATIME)
1900 md->body->mbo_atime = attr->cat_atime;
1901 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1902 md->body->mbo_ctime = attr->cat_ctime;
1903 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1904 md->body->mbo_mtime = attr->cat_mtime;
1910 lmv_stripe_object_put(&lsm_obj);
1913 up_write(&lli->lli_lsm_sem);
1917 void ll_clear_inode(struct inode *inode)
1919 struct ll_inode_info *lli = ll_i2info(inode);
1920 struct ll_sb_info *sbi = ll_i2sbi(inode);
1924 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1925 PFID(ll_inode2fid(inode)), inode);
1927 if (S_ISDIR(inode->i_mode)) {
1928 /* these should have been cleared in ll_file_release */
1929 LASSERT(lli->lli_opendir_key == NULL);
1930 LASSERT(lli->lli_sai == NULL);
1931 LASSERT(lli->lli_opendir_pid == 0);
1933 pcc_inode_free(inode);
1936 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1938 LASSERT(!lli->lli_open_fd_write_count);
1939 LASSERT(!lli->lli_open_fd_read_count);
1940 LASSERT(!lli->lli_open_fd_exec_count);
1942 if (lli->lli_mds_write_och)
1943 ll_md_real_close(inode, FMODE_WRITE);
1944 if (lli->lli_mds_exec_och)
1945 ll_md_real_close(inode, FMODE_EXEC);
1946 if (lli->lli_mds_read_och)
1947 ll_md_real_close(inode, FMODE_READ);
1949 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1950 OBD_FREE(lli->lli_symlink_name,
1951 strlen(lli->lli_symlink_name) + 1);
1952 lli->lli_symlink_name = NULL;
1955 ll_xattr_cache_destroy(inode);
1957 forget_all_cached_acls(inode);
1959 lli->lli_inode_magic = LLI_INODE_DEAD;
1961 if (S_ISDIR(inode->i_mode))
1962 ll_dir_clear_lsm_md(inode);
1963 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1964 LASSERT(list_empty(&lli->lli_agl_list));
1967 * XXX This has to be done before lsm is freed below, because
1968 * cl_object still uses inode lsm.
1970 cl_inode_fini(inode);
1972 llcrypt_put_encryption_info(inode);
1977 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1979 struct lustre_md md;
1980 struct inode *inode = dentry->d_inode;
1981 struct ll_sb_info *sbi = ll_i2sbi(inode);
1982 struct ptlrpc_request *request = NULL;
1987 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1988 LUSTRE_OPC_ANY, NULL);
1989 if (IS_ERR(op_data))
1990 RETURN(PTR_ERR(op_data));
1992 /* If this is a chgrp of a regular file, we want to reserve enough
1993 * quota to cover the entire file size.
1995 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1996 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1997 from_kgid(&init_user_ns, inode->i_gid)) {
1998 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1999 op_data->op_attr_blocks = inode->i_blocks;
2003 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
2005 ptlrpc_req_finished(request);
2006 if (rc == -ENOENT) {
2008 /* Unlinked special device node? Or just a race?
2009 * Pretend we done everything. */
2010 if (!S_ISREG(inode->i_mode) &&
2011 !S_ISDIR(inode->i_mode)) {
2012 ia_valid = op_data->op_attr.ia_valid;
2013 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
2014 rc = simple_setattr(&nop_mnt_idmap, dentry,
2016 op_data->op_attr.ia_valid = ia_valid;
2018 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
2019 CERROR("md_setattr fails: rc = %d\n", rc);
2024 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
2025 sbi->ll_md_exp, &md);
2027 ptlrpc_req_finished(request);
2031 ia_valid = op_data->op_attr.ia_valid;
2032 /* inode size will be in ll_setattr_ost, can't do it now since dirty
2033 * cache is not cleared yet. */
2034 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
2035 if (S_ISREG(inode->i_mode))
2036 ll_inode_lock(inode);
2037 rc = simple_setattr(&nop_mnt_idmap, dentry, &op_data->op_attr);
2038 if (S_ISREG(inode->i_mode))
2039 ll_inode_unlock(inode);
2040 op_data->op_attr.ia_valid = ia_valid;
2042 rc = ll_update_inode(inode, &md);
2043 ptlrpc_req_finished(request);
2044 md_put_lustre_md(sbi->ll_md_exp, &md);
2050 * Zero portion of page that is part of @inode.
2051 * This implies, if necessary:
2052 * - taking cl_lock on range corresponding to concerned page
2053 * - grabbing vm page
2054 * - associating cl_page
2055 * - proceeding to clio read
2056 * - zeroing range in page
2057 * - proceeding to cl_page flush
2058 * - releasing cl_lock
2060 * \param[in] inode inode
2061 * \param[in] index page index
2062 * \param[in] offset offset in page to start zero from
2063 * \param[in] len len to zero
2065 * \retval 0 on success
2066 * \retval negative errno on failure
2068 static int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
2071 struct ll_inode_info *lli = ll_i2info(inode);
2072 struct cl_object *clob = lli->lli_clob;
2074 struct lu_env *env = NULL;
2075 struct cl_io *io = NULL;
2076 struct cl_page *clpage = NULL;
2077 struct page *vmpage = NULL;
2078 unsigned from = index << PAGE_SHIFT;
2079 struct cl_lock *lock = NULL;
2080 struct cl_lock_descr *descr = NULL;
2081 struct cl_2queue *queue = NULL;
2082 struct cl_sync_io *anchor = NULL;
2083 bool holdinglock = false;
2088 env = cl_env_get(&refcheck);
2090 RETURN(PTR_ERR(env));
2092 io = vvp_env_thread_io(env);
2094 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2098 lock = vvp_env_lock(env);
2099 descr = &lock->cll_descr;
2100 descr->cld_obj = io->ci_obj;
2101 descr->cld_start = from >> PAGE_SHIFT;
2102 descr->cld_end = (from + PAGE_SIZE - 1) >> PAGE_SHIFT;
2103 descr->cld_mode = CLM_WRITE;
2104 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2106 /* request lock for page */
2107 rc = cl_lock_request(env, io, lock);
2108 /* -ECANCELED indicates a matching lock with a different extent
2109 * was already present, and -EEXIST indicates a matching lock
2110 * on exactly the same extent was already present.
2111 * In both cases it means we are covered.
2113 if (rc == -ECANCELED || rc == -EEXIST)
2121 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2123 GOTO(rellock, rc = -EOPNOTSUPP);
2125 if (!PageDirty(vmpage)) {
2126 /* associate cl_page */
2127 clpage = cl_page_find(env, clob, vmpage->index,
2128 vmpage, CPT_CACHEABLE);
2130 GOTO(pagefini, rc = PTR_ERR(clpage));
2132 cl_page_assume(env, io, clpage);
2135 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2136 !PageWriteback(vmpage)) {
2138 /* Set PagePrivate2 to detect special case of empty page
2139 * in osc_brw_fini_request().
2140 * It is also used to tell ll_io_read_page() that we do not
2141 * want the vmpage to be unlocked.
2143 SetPagePrivate2(vmpage);
2144 rc = ll_io_read_page(env, io, clpage, NULL);
2145 if (!PagePrivate2(vmpage)) {
2146 /* PagePrivate2 was cleared in osc_brw_fini_request()
2147 * meaning we read an empty page. In this case, in order
2148 * to avoid allocating unnecessary block in truncated
2149 * file, we must not zero and write as below. Subsequent
2150 * server-side truncate will handle things correctly.
2152 cl_page_unassume(env, io, clpage);
2153 GOTO(clpfini, rc = 0);
2155 ClearPagePrivate2(vmpage);
2160 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2161 * the vmpage, so we are good to proceed and zero range in page.
2163 zero_user(vmpage, offset, len);
2165 if (holdinglock && clpage) {
2166 /* explicitly write newly modified page */
2167 queue = &io->ci_queue;
2168 cl_2queue_init(queue);
2169 anchor = &vvp_env_info(env)->vti_anchor;
2170 cl_sync_io_init(anchor, 1);
2171 clpage->cp_sync_io = anchor;
2172 cl_page_list_add(&queue->c2_qin, clpage, true);
2173 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2175 GOTO(queuefini1, rc);
2176 rc = cl_sync_io_wait(env, anchor, 0);
2178 GOTO(queuefini2, rc);
2179 cl_page_assume(env, io, clpage);
2182 cl_2queue_discard(env, io, queue);
2184 cl_2queue_disown(env, queue);
2185 cl_2queue_fini(env, queue);
2190 cl_page_put(env, clpage);
2192 unlock_page(vmpage);
2196 cl_lock_release(env, lock);
2198 cl_io_fini(env, io);
2201 cl_env_put(env, &refcheck);
2207 * Get reference file from volatile file name.
2208 * Volatile file name may look like:
2209 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2210 * where fd is opened descriptor of reference file.
2212 * \param[in] volatile_name volatile file name
2213 * \param[in] volatile_len volatile file name length
2214 * \param[out] ref_file pointer to struct file of reference file
2216 * \retval 0 on success
2217 * \retval negative errno on failure
2219 int volatile_ref_file(const char *volatile_name, int volatile_len,
2220 struct file **ref_file)
2222 char *p, *q, *fd_str;
2225 p = strnstr(volatile_name, ":fd=", volatile_len);
2226 if (!p || strlen(p + 4) == 0)
2229 q = strchrnul(p + 4, ':');
2230 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2233 rc = kstrtouint(fd_str, 10, &fd);
2238 *ref_file = fget(fd);
2244 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2245 * object(s) determine the file size and mtime. Otherwise, the MDS will
2246 * keep these values until such a time that objects are allocated for it.
2247 * We do the MDS operations first, as it is checking permissions for us.
2248 * We don't to the MDS RPC if there is nothing that we want to store there,
2249 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2250 * going to do an RPC anyways.
2252 * If we are doing a truncate, we will send the mtime and ctime updates
2253 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2254 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2257 * In case of HSMimport, we only set attr on MDS.
2259 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2260 enum op_xvalid xvalid, bool hsm_import)
2262 struct inode *inode = dentry->d_inode;
2263 struct ll_inode_info *lli = ll_i2info(inode);
2264 struct md_op_data *op_data = NULL;
2265 ktime_t kstart = ktime_get();
2270 /* VFS has locked the inode before calling this */
2271 ll_set_inode_lock_owner(inode);
2273 CDEBUG(D_VFSTRACE|D_IOTRACE,
2274 "START file %s:"DFID"(%p) current size %llu, valid attrs %x, mode %x, uid %d, gid %d, new size %llu, atime %lld.%.9ld, mtime %lld.%.9ld, ctime %lld.%.9ld\n",
2275 dentry->d_name.name, PFID(ll_inode2fid(inode)), inode,
2276 i_size_read(inode), attr->ia_valid, attr->ia_mode,
2277 attr->ia_uid.val, attr->ia_gid.val, attr->ia_size,
2278 (long long) attr->ia_atime.tv_sec, attr->ia_atime.tv_nsec,
2279 (long long) attr->ia_mtime.tv_sec, attr->ia_mtime.tv_nsec,
2280 (long long) attr->ia_ctime.tv_sec, attr->ia_ctime.tv_nsec);
2283 if (attr->ia_valid & ATTR_SIZE) {
2284 /* Check new size against VFS/VM file size limit and rlimit */
2285 rc = inode_newsize_ok(inode, attr->ia_size);
2289 /* The maximum Lustre file size is variable, based on the
2290 * OST maximum object size and number of stripes. This
2291 * needs another check in addition to the VFS check above. */
2292 if (attr->ia_size > ll_file_maxbytes(inode)) {
2293 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2294 PFID(&lli->lli_fid), attr->ia_size,
2295 ll_file_maxbytes(inode));
2296 GOTO(clear, rc = -EFBIG);
2299 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2302 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2303 if (attr->ia_valid & TIMES_SET_FLAGS) {
2304 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2305 !capable(CAP_FOWNER))
2306 GOTO(clear, rc = -EPERM);
2309 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2310 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2311 (attr->ia_valid & ATTR_CTIME)) {
2312 attr->ia_ctime = current_time(inode);
2313 xvalid |= OP_XVALID_CTIME_SET;
2315 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2316 (attr->ia_valid & ATTR_ATIME)) {
2317 attr->ia_atime = current_time(inode);
2318 attr->ia_valid |= ATTR_ATIME_SET;
2320 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2321 (attr->ia_valid & ATTR_MTIME)) {
2322 attr->ia_mtime = current_time(inode);
2323 attr->ia_valid |= ATTR_MTIME_SET;
2326 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2327 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2328 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2329 ktime_get_real_seconds());
2331 if (S_ISREG(inode->i_mode))
2332 ll_inode_unlock(inode);
2334 /* We always do an MDS RPC, even if we're only changing the size;
2335 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2337 OBD_ALLOC_PTR(op_data);
2338 if (op_data == NULL)
2339 GOTO(out, rc = -ENOMEM);
2341 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2342 /* If we are changing file size, file content is
2343 * modified, flag it.
2345 xvalid |= OP_XVALID_OWNEROVERRIDE;
2346 op_data->op_bias |= MDS_DATA_MODIFIED;
2347 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2350 if (attr->ia_valid & ATTR_FILE) {
2351 struct ll_file_data *fd = attr->ia_file->private_data;
2353 if (fd->fd_lease_och)
2354 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2357 op_data->op_attr = *attr;
2358 op_data->op_xvalid = xvalid;
2360 rc = ll_md_setattr(dentry, op_data);
2363 lli->lli_synced_to_mds = false;
2365 if (!S_ISREG(inode->i_mode) || hsm_import)
2368 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2369 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2370 xvalid & OP_XVALID_CTIME_SET) {
2371 bool cached = false;
2373 rc = pcc_inode_setattr(inode, attr, &cached);
2376 CERROR("%s: PCC inode "DFID" setattr failed: "
2378 ll_i2sbi(inode)->ll_fsname,
2379 PFID(&lli->lli_fid), rc);
2383 unsigned int flags = 0;
2385 /* For truncate and utimes sending attributes to OSTs,
2386 * setting mtime/atime to the past will be performed
2387 * under PW [0:EOF] extent lock (new_size:EOF for
2388 * truncate). It may seem excessive to send mtime/atime
2389 * updates to OSTs when not setting times to past, but
2390 * it is necessary due to possible time
2391 * de-synchronization between MDT inode and OST objects
2393 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2394 xvalid |= OP_XVALID_FLAGS;
2395 flags = LUSTRE_ENCRYPT_FL;
2396 /* Call to ll_io_zero_page is not necessary if
2397 * truncating on PAGE_SIZE boundary, because
2398 * whole pages will be wiped.
2400 * an exception is when working with the
2401 * raw ciphertext - in that case, we need to
2402 * encrypt those zeroes
2404 if (attr->ia_valid & ATTR_SIZE &&
2405 attr->ia_size & ~PAGE_MASK &&
2406 !(attr->ia_valid & ATTR_FILE &&
2407 attr->ia_file->f_flags & O_CIPHERTEXT)) {
2409 attr->ia_size & (PAGE_SIZE - 1);
2411 rc = ll_io_zero_page(inode,
2412 attr->ia_size >> PAGE_SHIFT,
2413 offset, PAGE_SIZE - offset);
2417 /* If encrypted volatile file without the key,
2418 * we need to fetch size from reference file,
2419 * and set it on OST objects. This happens when
2420 * migrating or extending an encrypted file
2423 if (filename_is_volatile(dentry->d_name.name,
2426 llcrypt_require_key(inode) == -ENOKEY) {
2427 struct file *ref_file;
2428 struct inode *ref_inode;
2429 struct ll_inode_info *ref_lli;
2430 struct cl_object *ref_obj;
2431 struct cl_attr ref_attr = { 0 };
2435 rc = volatile_ref_file(
2436 dentry->d_name.name,
2442 ref_inode = file_inode(ref_file);
2445 GOTO(out, rc = -EINVAL);
2448 env = cl_env_get(&refcheck);
2450 GOTO(out, rc = PTR_ERR(env));
2452 ref_lli = ll_i2info(ref_inode);
2453 ref_obj = ref_lli->lli_clob;
2454 cl_object_attr_lock(ref_obj);
2455 rc = cl_object_attr_get(env, ref_obj,
2457 cl_object_attr_unlock(ref_obj);
2458 cl_env_put(env, &refcheck);
2463 attr->ia_valid |= ATTR_SIZE;
2464 attr->ia_size = ref_attr.cat_size;
2467 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2471 /* If the file was restored, it needs to set dirty flag.
2473 * We've already sent MDS_DATA_MODIFIED flag in
2474 * ll_md_setattr() for truncate. However, the MDT refuses to
2475 * set the HS_DIRTY flag on released files, so we have to set
2476 * it again if the file has been restored. Please check how
2477 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2479 * Please notice that if the file is not released, the previous
2480 * MDS_DATA_MODIFIED has taken effect and usually
2481 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2482 * This way we can save an RPC for common open + trunc
2484 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2485 struct hsm_state_set hss = {
2486 .hss_valid = HSS_SETMASK,
2487 .hss_setmask = HS_DIRTY,
2491 rc2 = ll_hsm_state_set(inode, &hss);
2492 /* truncate and write can happen at the same time, so that
2493 * the file can be set modified even though the file is not
2494 * restored from released state, and ll_hsm_state_set() is
2495 * not applicable for the file, and rc2 < 0 is normal in this
2498 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2499 PFID(ll_inode2fid(inode)), rc2);
2504 if (op_data != NULL)
2505 ll_finish_md_op_data(op_data);
2507 if (S_ISREG(inode->i_mode)) {
2508 ll_inode_lock(inode);
2509 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2510 inode_dio_wait(inode);
2511 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2512 * flag. ll_update_inode (called from ll_md_setattr), clears
2513 * inode flags, so there is a gap where S_NOSEC is not set.
2514 * This can cause a writer to take the i_mutex unnecessarily,
2515 * but this is safe to do and should be rare. */
2516 inode_has_no_xattr(inode);
2520 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2521 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2522 ktime_us_delta(ktime_get(), kstart));
2524 CDEBUG(D_VFSTRACE|D_IOTRACE,
2525 "COMPLETED file %s:"DFID"(%p) current size %llu, valid attrs %x, mode %x, uid %d, gid %d, new size %llu, atime %lld.%.9ld, mtime %lld.%.9ld, ctime %lld.%.9ld, rc %d\n",
2526 dentry->d_name.name, PFID(ll_inode2fid(inode)), inode,
2527 i_size_read(inode), attr->ia_valid, attr->ia_mode,
2528 attr->ia_uid.val, attr->ia_gid.val, attr->ia_size,
2529 (long long) attr->ia_atime.tv_sec, attr->ia_atime.tv_nsec,
2530 (long long) attr->ia_mtime.tv_sec, attr->ia_mtime.tv_nsec,
2531 (long long) attr->ia_ctime.tv_sec, attr->ia_ctime.tv_nsec, rc);
2533 ll_clear_inode_lock_owner(inode);
2538 int ll_setattr(struct mnt_idmap *map, struct dentry *de, struct iattr *attr)
2540 int mode = de->d_inode->i_mode;
2541 enum op_xvalid xvalid = 0;
2544 rc = setattr_prepare(map, de, attr);
2548 rc = llcrypt_prepare_setattr(de, attr);
2552 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2553 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2554 xvalid |= OP_XVALID_OWNEROVERRIDE;
2556 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2557 (ATTR_SIZE|ATTR_MODE)) &&
2558 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2559 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2560 !(attr->ia_mode & S_ISGID))))
2561 attr->ia_valid |= ATTR_FORCE;
2563 if ((attr->ia_valid & ATTR_MODE) &&
2565 !(attr->ia_mode & S_ISUID) &&
2566 !(attr->ia_valid & ATTR_KILL_SUID))
2567 attr->ia_valid |= ATTR_KILL_SUID;
2569 if ((attr->ia_valid & ATTR_MODE) &&
2570 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2571 !(attr->ia_mode & S_ISGID) &&
2572 !(attr->ia_valid & ATTR_KILL_SGID))
2573 attr->ia_valid |= ATTR_KILL_SGID;
2575 return ll_setattr_raw(de, attr, xvalid, false);
2578 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2581 struct obd_statfs obd_osfs = { 0 };
2586 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2588 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2589 flags |= OBD_STATFS_NODELAY;
2591 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2595 osfs->os_type = LL_SUPER_MAGIC;
2597 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2598 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2600 if (osfs->os_state & OS_STATFS_SUM)
2603 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2604 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2607 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2608 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2611 osfs->os_bsize = obd_osfs.os_bsize;
2612 osfs->os_blocks = obd_osfs.os_blocks;
2613 osfs->os_bfree = obd_osfs.os_bfree;
2614 osfs->os_bavail = obd_osfs.os_bavail;
2616 /* If we have _some_ OSTs, but don't have as many free objects on the
2617 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2618 * to compensate, so that the "inodes in use" number is correct.
2619 * This should be kept in sync with lod_statfs() behaviour.
2621 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2622 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2624 osfs->os_ffree = obd_osfs.os_ffree;
2631 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2633 struct if_quotactl qctl = {
2634 .qc_cmd = LUSTRE_Q_GETQUOTA,
2635 .qc_type = PRJQUOTA,
2636 .qc_valid = QC_GENERAL,
2638 u64 limit, curblock;
2641 qctl.qc_id = ll_i2info(inode)->lli_projid;
2642 ret = quotactl_ioctl(inode->i_sb, &qctl);
2644 /* ignore errors if project ID does not have
2645 * a quota limit or feature unsupported.
2647 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2652 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2653 qctl.qc_dqblk.dqb_bsoftlimit :
2654 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2655 if (limit && sfs->f_blocks > limit) {
2656 curblock = (qctl.qc_dqblk.dqb_curspace +
2657 sfs->f_bsize - 1) / sfs->f_bsize;
2658 sfs->f_blocks = limit;
2659 sfs->f_bfree = sfs->f_bavail =
2660 (sfs->f_blocks > curblock) ?
2661 (sfs->f_blocks - curblock) : 0;
2664 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2665 qctl.qc_dqblk.dqb_isoftlimit :
2666 qctl.qc_dqblk.dqb_ihardlimit;
2667 if (limit && sfs->f_files > limit) {
2668 sfs->f_files = limit;
2669 sfs->f_ffree = (sfs->f_files >
2670 qctl.qc_dqblk.dqb_curinodes) ?
2671 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2677 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2679 struct super_block *sb = de->d_sb;
2680 struct ll_sb_info *sbi = ll_s2sbi(sb);
2681 struct obd_statfs osfs;
2682 __u64 fsid = huge_encode_dev(sb->s_dev);
2683 ktime_t kstart = ktime_get();
2686 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2688 /* Some amount of caching on the client is allowed */
2689 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_SUM);
2693 statfs_unpack(sfs, &osfs);
2695 /* We need to downshift for all 32-bit kernels, because we can't
2696 * tell if the kernel is being called via sys_statfs64() or not.
2697 * Stop before overflowing f_bsize - in which case it is better
2698 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2699 if (sizeof(long) < 8) {
2700 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2703 osfs.os_blocks >>= 1;
2704 osfs.os_bfree >>= 1;
2705 osfs.os_bavail >>= 1;
2709 sfs->f_blocks = osfs.os_blocks;
2710 sfs->f_bfree = osfs.os_bfree;
2711 sfs->f_bavail = osfs.os_bavail;
2712 sfs->f_fsid.val[0] = (__u32)fsid;
2713 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2714 if (ll_i2info(de->d_inode)->lli_projid &&
2715 test_bit(LL_SBI_STATFS_PROJECT, sbi->ll_flags) &&
2716 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2717 return ll_statfs_project(de->d_inode, sfs);
2719 ll_stats_ops_tally(sbi, LPROC_LL_STATFS,
2720 ktime_us_delta(ktime_get(), kstart));
2725 void ll_inode_size_lock(struct inode *inode)
2727 struct ll_inode_info *lli;
2729 LASSERT(!S_ISDIR(inode->i_mode));
2731 lli = ll_i2info(inode);
2732 mutex_lock(&lli->lli_size_mutex);
2733 lli->lli_size_lock_owner = current;
2736 void ll_inode_size_unlock(struct inode *inode)
2738 struct ll_inode_info *lli;
2740 lli = ll_i2info(inode);
2741 lli->lli_size_lock_owner = NULL;
2742 mutex_unlock(&lli->lli_size_mutex);
2745 int ll_inode_size_trylock(struct inode *inode)
2747 struct ll_inode_info *lli;
2749 LASSERT(!S_ISDIR(inode->i_mode));
2751 lli = ll_i2info(inode);
2752 return mutex_trylock(&lli->lli_size_mutex);
2755 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2757 /* do not clear encryption flag */
2758 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2759 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2760 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2761 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2763 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2766 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2768 struct ll_inode_info *lli = ll_i2info(inode);
2769 struct mdt_body *body = md->body;
2770 struct ll_sb_info *sbi = ll_i2sbi(inode);
2774 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2775 rc = cl_file_inode_init(inode, md);
2780 if (S_ISDIR(inode->i_mode)) {
2781 rc = ll_update_lsm_md(inode, md);
2786 if (body->mbo_valid & OBD_MD_FLACL)
2787 lli_replace_acl(lli, md);
2789 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2790 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2791 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2793 if (body->mbo_valid & OBD_MD_FLATIME) {
2794 if (body->mbo_atime > inode_get_atime_sec(inode))
2795 inode_set_atime(inode, body->mbo_atime, 0);
2796 lli->lli_atime = body->mbo_atime;
2799 if (body->mbo_valid & OBD_MD_FLMTIME) {
2800 if (body->mbo_mtime > inode_get_mtime_sec(inode)) {
2802 "setting ino %lu mtime from %lld to %llu\n",
2803 inode->i_ino, (s64) inode_get_mtime_sec(inode),
2805 inode_set_mtime(inode, body->mbo_mtime, 0);
2807 lli->lli_mtime = body->mbo_mtime;
2810 if (body->mbo_valid & OBD_MD_FLCTIME) {
2811 if (body->mbo_ctime > inode_get_ctime_sec(inode))
2812 inode_set_ctime(inode, body->mbo_ctime, 0);
2813 lli->lli_ctime = body->mbo_ctime;
2816 if (body->mbo_valid & OBD_MD_FLBTIME)
2817 lli->lli_btime = body->mbo_btime;
2819 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2820 if (body->mbo_valid & OBD_MD_FLFLAGS)
2821 ll_update_inode_flags(inode, body->mbo_flags);
2822 if (body->mbo_valid & OBD_MD_FLMODE)
2823 inode->i_mode = (inode->i_mode & S_IFMT) |
2824 (body->mbo_mode & ~S_IFMT);
2826 if (body->mbo_valid & OBD_MD_FLTYPE)
2827 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2828 (body->mbo_mode & S_IFMT);
2830 LASSERT(inode->i_mode != 0);
2831 if (body->mbo_valid & OBD_MD_FLUID)
2832 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2833 if (body->mbo_valid & OBD_MD_FLGID)
2834 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2835 if (body->mbo_valid & OBD_MD_FLPROJID)
2836 lli->lli_projid = body->mbo_projid;
2837 if (body->mbo_valid & OBD_MD_FLNLINK) {
2838 spin_lock(&inode->i_lock);
2839 set_nlink(inode, body->mbo_nlink);
2840 spin_unlock(&inode->i_lock);
2842 if (body->mbo_valid & OBD_MD_FLRDEV)
2843 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2845 if (body->mbo_valid & OBD_MD_FLID) {
2846 /* FID shouldn't be changed! */
2847 if (fid_is_sane(&lli->lli_fid)) {
2848 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2849 "Trying to change FID "DFID" to the "DFID", inode "DFID"(%px)\n",
2850 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2851 PFID(ll_inode2fid(inode)), inode);
2853 lli->lli_fid = body->mbo_fid1;
2857 LASSERT(fid_seq(&lli->lli_fid) != 0);
2859 /* In case of encrypted file without the key, please do not lose
2860 * clear text size stored into lli_lazysize in ll_merge_attr(),
2861 * we will need it in ll_prepare_close().
2863 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2864 llcrypt_require_key(inode) == -ENOKEY)
2865 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2867 lli->lli_attr_valid = body->mbo_valid;
2868 if (body->mbo_valid & OBD_MD_FLSIZE) {
2869 i_size_write(inode, body->mbo_size);
2871 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2872 PFID(ll_inode2fid(inode)),
2873 (unsigned long long)body->mbo_size);
2875 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2876 inode->i_blocks = body->mbo_blocks;
2878 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2879 lli->lli_lazysize = body->mbo_size;
2880 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2881 lli->lli_lazyblocks = body->mbo_blocks;
2884 if (body->mbo_valid & OBD_MD_TSTATE) {
2885 /* Set LLIF_FILE_RESTORING if restore ongoing and
2886 * clear it when done to ensure to start again
2887 * glimpsing updated attrs
2889 if (body->mbo_t_state & MS_RESTORE)
2890 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2892 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2898 /* child default LMV is inherited from parent */
2899 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2900 struct lmv_stripe_md *cdmv)
2905 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2906 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2907 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2908 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2911 if (cdmv->lsm_md_max_inherit !=
2912 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2915 if (cdmv->lsm_md_max_inherit_rr !=
2916 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2922 /* if default LMV is implicitly inherited, subdir default LMV is maintained on
2925 static int ll_dir_default_lmv_inherit(struct inode *dir, struct inode *inode)
2927 struct ll_inode_info *plli = ll_i2info(dir);
2928 struct ll_inode_info *lli = ll_i2info(inode);
2929 struct lmv_stripe_object *plsm_obj;
2930 struct lmv_stripe_object *lsm_obj;
2935 /* ROOT default LMV is not inherited */
2936 if (is_root_inode(dir) ||
2937 !(exp_connect_flags2(ll_i2mdexp(dir)) &
2938 OBD_CONNECT2_DMV_IMP_INHERIT))
2941 /* nothing to do if no default LMV on both */
2942 if (!plli->lli_def_lsm_obj && !lli->lli_def_lsm_obj)
2945 /* subdir default LMV comes from disk */
2946 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set)
2949 /* delete subdir default LMV if parent's is deleted or becomes
2952 down_read(&plli->lli_lsm_sem);
2953 plsm_obj = plli->lli_def_lsm_obj;
2955 !lmv_is_inheritable(plsm_obj->lso_lsm.lsm_md_max_inherit)) {
2956 if (lli->lli_def_lsm_obj && !lli->lli_def_lsm_obj_set) {
2957 down_write(&lli->lli_lsm_sem);
2958 if (!lli->lli_def_lsm_obj_set) {
2959 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
2960 lli->lli_inherit_depth = 0;
2962 up_write(&lli->lli_lsm_sem);
2964 GOTO(unlock_parent, rc = 0);
2967 /* do nothing if inherited LMV is unchanged */
2968 if (lli->lli_def_lsm_obj) {
2970 down_read(&lli->lli_lsm_sem);
2971 if (!lli->lli_def_lsm_obj_set)
2972 rc = lmv_object_inherited(plsm_obj,
2973 lli->lli_def_lsm_obj);
2974 up_read(&lli->lli_lsm_sem);
2976 GOTO(unlock_parent, rc = 0);
2979 /* inherit default LMV */
2980 down_write(&lli->lli_lsm_sem);
2981 if (lli->lli_def_lsm_obj) {
2982 /* checked above, but in case of race, check again with lock */
2983 if (lli->lli_def_lsm_obj_set)
2984 GOTO(unlock_child, rc = 0);
2985 /* always update subdir default LMV in case parent's changed */
2986 lsm_obj = lli->lli_def_lsm_obj;
2988 lsm_obj = lmv_stripe_object_alloc(LMV_USER_MAGIC, NULL, 0);
2989 if (IS_ERR(lsm_obj))
2990 GOTO(unlock_child, rc = PTR_ERR(lsm_obj));
2991 lli->lli_def_lsm_obj = lsm_obj;
2994 lsm_obj->lso_lsm = plsm_obj->lso_lsm;
2995 lsm_obj->lso_lsm.lsm_md_max_inherit =
2996 lmv_inherit_next(plsm_obj->lso_lsm.lsm_md_max_inherit);
2997 lsm_obj->lso_lsm.lsm_md_max_inherit_rr =
2998 lmv_inherit_rr_next(plsm_obj->lso_lsm.lsm_md_max_inherit_rr);
2999 lli->lli_inherit_depth = plli->lli_inherit_depth + 1;
3001 lmv_stripe_object_dump(D_INODE, lsm_obj);
3005 up_write(&lli->lli_lsm_sem);
3007 up_read(&plli->lli_lsm_sem);
3012 enum lsm_sem_class {
3018 * Update directory depth and default LMV
3020 * Update directory depth to ROOT and inherit default LMV from parent if
3021 * parent's default LMV is inheritable. The default LMV set with command
3022 * "lfs setdirstripe -D ..." is stored on MDT, while the inherited default LMV
3023 * is generated at runtime on client side.
3025 * \param[in] dir parent directory inode
3026 * \param[in] de dentry
3028 void ll_update_dir_depth_dmv(struct inode *dir, struct dentry *de)
3030 struct inode *inode = de->d_inode;
3031 struct ll_inode_info *plli;
3032 struct ll_inode_info *lli;
3034 LASSERT(S_ISDIR(inode->i_mode));
3038 plli = ll_i2info(dir);
3039 lli = ll_i2info(inode);
3040 lli->lli_dir_depth = plli->lli_dir_depth + 1;
3041 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set) {
3042 if (plli->lli_def_lsm_obj) {
3043 down_read_nested(&plli->lli_lsm_sem, LSM_SEM_PARENT);
3044 down_read_nested(&lli->lli_lsm_sem, LSM_SEM_CHILD);
3045 if (lmv_object_inherited(plli->lli_def_lsm_obj,
3046 lli->lli_def_lsm_obj))
3047 lli->lli_inherit_depth =
3048 plli->lli_inherit_depth + 1;
3050 /* in case parent default LMV changed */
3051 lli->lli_inherit_depth = 0;
3052 up_read(&lli->lli_lsm_sem);
3053 up_read(&plli->lli_lsm_sem);
3055 /* in case parent default LMV deleted */
3056 lli->lli_inherit_depth = 0;
3059 ll_dir_default_lmv_inherit(dir, inode);
3062 if (lli->lli_def_lsm_obj)
3064 "%s "DFID" depth %hu %s default LMV inherit depth %hu\n",
3065 de->d_name.name, PFID(&lli->lli_fid), lli->lli_dir_depth,
3066 lli->lli_def_lsm_obj_set ? "server" : "client",
3067 lli->lli_inherit_depth);
3070 void ll_truncate_inode_pages_final(struct inode *inode)
3072 struct address_space *mapping = &inode->i_data;
3073 unsigned long nrpages;
3074 unsigned long flags;
3076 LASSERTF((inode->i_state & I_FREEING) || inode_is_locked(inode),
3077 DFID ":inode %px state %#lx, lli_flags %#lx\n",
3078 PFID(ll_inode2fid(inode)), inode, inode->i_state,
3079 ll_i2info(inode)->lli_flags);
3081 truncate_inode_pages_final(mapping);
3083 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_DELAY_TRUNCATE, 5);
3085 /* Workaround for LU-118: Note nrpages may not be totally updated when
3086 * truncate_inode_pages() returns, as there can be a page in the process
3087 * of deletion (inside __delete_from_page_cache()) in the specified
3088 * range. Thus mapping->nrpages can be non-zero when this function
3089 * returns even after truncation of the whole mapping. Only do this if
3090 * npages isn't already zero.
3092 nrpages = mapping->nrpages;
3094 ll_xa_lock_irqsave(&mapping->i_pages, flags);
3095 nrpages = mapping->nrpages;
3096 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
3097 } /* Workaround end */
3100 #ifdef HAVE_XARRAY_SUPPORT
3101 XA_STATE(xas, &mapping->i_pages, 0);
3104 CWARN("%s: inode="DFID"(%p) nrpages=%lu "
3105 "state %#lx, lli_flags %#lx, "
3106 "see https://jira.whamcloud.com/browse/LU-118\n",
3107 ll_i2sbi(inode)->ll_fsname,
3108 PFID(ll_inode2fid(inode)), inode, nrpages,
3109 inode->i_state, ll_i2info(inode)->lli_flags);
3110 #ifdef HAVE_XARRAY_SUPPORT
3112 xas_for_each(&xas, page, ULONG_MAX) {
3113 if (xas_retry(&xas, page))
3116 if (xa_is_value(page))
3120 * We can only have non-uptodate pages
3121 * without internal state at this point
3123 LASSERTF(!PageUptodate(page) &&
3133 int ll_read_inode2(struct inode *inode, void *opaque)
3135 struct lustre_md *md = opaque;
3136 struct ll_inode_info *lli = ll_i2info(inode);
3140 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
3141 PFID(&lli->lli_fid), inode);
3143 /* Core attributes from the MDS first. This is a new inode, and
3144 * the VFS doesn't zero times in the core inode so we have to do
3145 * it ourselves. They will be overwritten by either MDS or OST
3146 * attributes - we just need to make sure they aren't newer.
3148 inode_set_mtime(inode, 0, 0);
3149 inode_set_atime(inode, 0, 0);
3150 inode_set_ctime(inode, 0, 0);
3152 rc = ll_update_inode(inode, md);
3156 /* OIDEBUG(inode); */
3158 #ifdef HAVE_BACKING_DEV_INFO
3159 /* initializing backing dev info. */
3160 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
3162 if (S_ISREG(inode->i_mode)) {
3163 struct ll_sb_info *sbi = ll_i2sbi(inode);
3164 inode->i_op = &ll_file_inode_operations;
3165 inode->i_fop = sbi->ll_fop;
3166 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
3168 } else if (S_ISDIR(inode->i_mode)) {
3169 inode->i_op = &ll_dir_inode_operations;
3170 inode->i_fop = &ll_dir_operations;
3172 } else if (S_ISLNK(inode->i_mode)) {
3173 inode->i_op = &ll_fast_symlink_inode_operations;
3176 inode->i_op = &ll_special_inode_operations;
3178 init_special_inode(inode, inode->i_mode,
3187 void ll_delete_inode(struct inode *inode)
3189 struct ll_inode_info *lli = ll_i2info(inode);
3192 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
3193 /* It is last chance to write out dirty pages,
3194 * otherwise we may lose data while umount.
3196 * If i_nlink is 0 then just discard data. This is safe because
3197 * local inode gets i_nlink 0 from server only for the last
3198 * unlink, so that file is not opened somewhere else
3200 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
3201 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
3204 ll_truncate_inode_pages_final(inode);
3205 ll_clear_inode(inode);
3211 static int fileattr_get(struct inode *inode, int *flags,
3215 struct ll_sb_info *sbi = ll_i2sbi(inode);
3216 struct ptlrpc_request *req = NULL;
3217 struct md_op_data *op_data;
3218 struct mdt_body *body;
3222 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
3223 0, 0, LUSTRE_OPC_ANY,
3225 if (IS_ERR(op_data))
3226 RETURN(PTR_ERR(op_data));
3228 op_data->op_valid = OBD_MD_FLFLAGS;
3229 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
3230 ll_finish_md_op_data(op_data);
3232 CERROR("%s: failure inode "DFID": rc = %d\n",
3233 sbi->ll_md_exp->exp_obd->obd_name,
3234 PFID(ll_inode2fid(inode)), rc);
3238 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3240 *flags = body->mbo_flags;
3241 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
3242 * ext4 equivalent to please lsattr and other e2fsprogs tools
3244 if (*flags & LUSTRE_ENCRYPT_FL)
3245 *flags |= STATX_ATTR_ENCRYPTED;
3247 ptlrpc_req_finished(req);
3249 *xflags = ll_inode_flags_to_xflags(inode->i_flags);
3250 if (test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags))
3251 *xflags |= FS_XFLAG_PROJINHERIT;
3252 *projid = ll_i2info(inode)->lli_projid;
3257 static int fileattr_set(struct inode *inode, int flags)
3259 struct ll_sb_info *sbi = ll_i2sbi(inode);
3260 struct ptlrpc_request *req = NULL;
3261 struct md_op_data *op_data;
3262 struct cl_object *obj;
3263 struct fsxattr fa = { 0 };
3268 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3269 if (flags & LUSTRE_PROJINHERIT_FL)
3270 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3272 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3277 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3278 LUSTRE_OPC_ANY, NULL);
3279 if (IS_ERR(op_data))
3280 RETURN(PTR_ERR(op_data));
3282 op_data->op_attr_flags = flags;
3283 op_data->op_xvalid |= OP_XVALID_FLAGS;
3284 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3285 ll_finish_md_op_data(op_data);
3286 ptlrpc_req_finished(req);
3290 ll_update_inode_flags(inode, flags);
3292 obj = ll_i2info(inode)->lli_clob;
3296 OBD_ALLOC_PTR(attr);
3300 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3306 #ifdef HAVE_FILEATTR_GET
3307 int ll_fileattr_get(struct dentry *dentry, struct fileattr *fa)
3309 return fileattr_get(d_inode(dentry), &fa->flags,
3310 &fa->fsx_xflags, &fa->fsx_projid);
3313 int ll_fileattr_set(struct mnt_idmap *mnt_userns,
3314 struct dentry *dentry, struct fileattr *fa)
3317 return ll_set_project(d_inode(dentry), fa->fsx_xflags,
3320 return fileattr_set(d_inode(dentry), fa->flags);
3322 #endif /* HAVE_FILEATTR_GET */
3324 /* ioctl commands shared between files and directories */
3325 int ll_iocontrol(struct inode *inode, struct file *file,
3326 unsigned int cmd, void __user *uarg)
3333 RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
3334 case LL_IOC_GETVERSION:
3335 case FS_IOC_GETVERSION:
3336 RETURN(put_user(inode->i_generation, (int __user *)uarg));
3338 #ifndef HAVE_FILEATTR_GET
3339 case FS_IOC_GETFLAGS: {
3340 u32 xflags = 0, projid = 0;
3343 if (!ll_access_ok(uarg, sizeof(int)))
3345 rc = fileattr_get(file->f_inode, &flags, &xflags, &projid);
3349 RETURN(put_user(flags, (int __user *)uarg));
3351 case FS_IOC_SETFLAGS: {
3354 if (get_user(flags, (int __user *)uarg))
3357 RETURN(fileattr_set(file->f_inode, flags));
3359 case FS_IOC_FSGETXATTR:
3360 RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
3361 case FS_IOC_FSSETXATTR:
3362 RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
3363 #endif /* HAVE_FILEATTR_GET */
3364 case LL_IOC_PROJECT:
3365 RETURN(ll_ioctl_project(file, cmd, uarg));
3366 case IOC_OBD_STATFS:
3367 RETURN(ll_obd_statfs(inode, uarg));
3368 case LL_IOC_GET_MDTIDX: {
3369 if (!ll_access_ok(uarg, sizeof(rc)))
3372 rc = ll_get_mdt_idx(inode);
3376 if (put_user(rc, (int __user *)uarg))
3381 case LL_IOC_FLUSHCTX:
3382 RETURN(ll_flush_ctx(inode));
3383 #ifdef HAVE_LUSTRE_CRYPTO
3384 case LL_IOC_ADD_ENCRYPTION_KEY:
3385 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3387 rc = llcrypt_ioctl_add_key(file, uarg);
3388 #ifdef CONFIG_LL_ENCRYPTION
3389 if (!rc && S_ISDIR(inode->i_mode))
3390 sptlrpc_pool_add_user();
3393 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
3394 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3396 RETURN(llcrypt_ioctl_get_key_status(file, uarg));
3397 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
3398 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3400 RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
3401 case LL_IOC_SET_ENCRYPTION_POLICY:
3402 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3404 RETURN(llcrypt_ioctl_set_policy(file, uarg));
3405 case LL_IOC_REMOVE_ENCRYPTION_KEY:
3406 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3408 RETURN(llcrypt_ioctl_remove_key(file, uarg));
3409 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
3410 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3412 RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
3414 case LL_IOC_GETPARENT:
3415 RETURN(ll_getparent(file, uarg));
3416 case LL_IOC_PATH2FID:
3417 if (copy_to_user(uarg, ll_inode2fid(inode),
3418 sizeof(struct lu_fid)))
3421 case LL_IOC_UNLOCK_FOREIGN: {
3422 struct dentry *dentry = file_dentry(file);
3424 /* if not a foreign symlink do nothing */
3425 if (ll_foreign_is_removable(dentry, true)) {
3427 "prevent unlink of non-foreign file ("DFID")\n",
3428 PFID(ll_inode2fid(inode)));
3429 RETURN(-EOPNOTSUPP);
3433 case OBD_IOC_FID2PATH:
3434 RETURN(ll_fid2path(inode, uarg));
3435 #ifdef OBD_IOC_GETNAME_OLD
3436 case_OBD_IOC_DEPRECATED_FT(OBD_IOC_GETNAME_OLD,
3437 ll_i2sbi(inode)->ll_md_exp->exp_obd->obd_name,
3440 case OBD_IOC_GETDTNAME:
3441 case OBD_IOC_GETMDNAME:
3442 RETURN(ll_get_obd_name(inode, cmd, uarg));
3450 int ll_flush_ctx(struct inode *inode)
3452 struct ll_sb_info *sbi = ll_i2sbi(inode);
3454 CDEBUG(D_SEC, "flush context for user %d\n",
3455 from_kuid(&init_user_ns, current_uid()));
3457 obd_set_info_async(NULL, sbi->ll_md_exp,
3458 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3460 obd_set_info_async(NULL, sbi->ll_dt_exp,
3461 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3466 /* umount -f client means force down, don't save state */
3467 void ll_umount_begin(struct super_block *sb)
3469 struct ll_sb_info *sbi = ll_s2sbi(sb);
3470 struct obd_device *obd;
3471 struct obd_ioctl_data *ioc_data;
3475 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3476 sb->s_count, atomic_read(&sb->s_active));
3478 obd = class_exp2obd(sbi->ll_md_exp);
3480 CERROR("Invalid MDC connection handle %#llx\n",
3481 sbi->ll_md_exp->exp_handle.h_cookie);
3487 obd = class_exp2obd(sbi->ll_dt_exp);
3489 CERROR("Invalid LOV connection handle %#llx\n",
3490 sbi->ll_dt_exp->exp_handle.h_cookie);
3496 OBD_ALLOC_PTR(ioc_data);
3498 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_md_exp,
3499 sizeof *ioc_data, ioc_data, NULL);
3501 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_dt_exp,
3502 sizeof *ioc_data, ioc_data, NULL);
3504 OBD_FREE_PTR(ioc_data);
3507 /* Really, we'd like to wait until there are no requests outstanding,
3508 * and then continue. For now, we just periodically checking for vfs
3509 * to decrement mnt_cnt and hope to finish it within 10sec.
3513 !may_umount(sbi->ll_mnt.mnt)) {
3521 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3523 struct ll_sb_info *sbi = ll_s2sbi(sb);
3524 char *profilenm = get_profile_name(sb);
3528 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3529 read_only = *flags & MS_RDONLY;
3530 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3531 sizeof(KEY_READ_ONLY),
3532 KEY_READ_ONLY, sizeof(read_only),
3535 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3536 profilenm, read_only ?
3537 "read-only" : "read-write", err);
3542 sb->s_flags |= SB_RDONLY;
3544 sb->s_flags &= ~SB_RDONLY;
3546 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3547 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3548 read_only ? "read-only" : "read-write");
3554 * Cleanup the open handle that is cached on MDT-side.
3556 * For open case, the client side open handling thread may hit error
3557 * after the MDT grant the open. Under such case, the client should
3558 * send close RPC to the MDT as cleanup; otherwise, the open handle
3559 * on the MDT will be leaked there until the client umount or evicted.
3561 * In further, if someone unlinked the file, because the open handle
3562 * holds the reference on such file/object, then it will block the
3563 * subsequent threads that want to locate such object via FID.
3565 * \param[in] sb super block for this file-system
3566 * \param[in] open_req pointer to the original open request
3568 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3570 struct mdt_body *body;
3571 struct md_op_data *op_data;
3572 struct ptlrpc_request *close_req = NULL;
3573 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3576 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3577 OBD_ALLOC_PTR(op_data);
3578 if (op_data == NULL) {
3579 CWARN("%s: cannot allocate op_data to release open handle for "
3580 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3585 op_data->op_fid1 = body->mbo_fid1;
3586 op_data->op_open_handle = body->mbo_open_handle;
3587 op_data->op_mod_time = ktime_get_real_seconds();
3588 md_close(exp, op_data, NULL, &close_req);
3589 ptlrpc_req_finished(close_req);
3590 ll_finish_md_op_data(op_data);
3595 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3596 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3597 struct lustre_md *md)
3599 struct ll_sb_info *sbi = ll_i2sbi(inode);
3600 struct ptlrpc_request *req = NULL;
3601 union lmv_mds_md *lmm = NULL;
3605 LASSERT(is_root_inode(inode));
3606 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3607 LASSERT(!md->def_lsm_obj);
3609 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3611 GET_DEFAULT_LAYOUT_ROOT);
3612 if (rc && rc != -ENODATA)
3617 rc = md_stripe_object_create(sbi->ll_md_exp, &md->def_lsm_obj,
3627 ptlrpc_req_finished(req);
3631 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3632 struct super_block *sb, struct lookup_intent *it)
3634 struct ll_sb_info *sbi = NULL;
3635 struct lustre_md md = { NULL };
3636 bool default_lmv_deleted = false;
3641 LASSERT(*inode || sb);
3642 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3643 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3644 sbi->ll_md_exp, &md);
3649 * clear default_lmv only if intent_getattr reply doesn't contain it.
3650 * but it needs to be done after iget, check this early because
3651 * ll_update_lsm_md() may change md.
3653 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3654 S_ISDIR(md.body->mbo_mode) && !md.def_lsm_obj) {
3655 if (unlikely(*inode && is_root_inode(*inode) &&
3656 !fid_is_root(&sbi->ll_root_fid))) {
3657 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3662 if (!md.def_lsm_obj)
3663 default_lmv_deleted = true;
3667 rc = ll_update_inode(*inode, &md);
3671 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3672 struct lu_fid *fid1 = &md.body->mbo_fid1;
3674 LASSERT(sb != NULL);
3677 * At this point server returns to client's same fid as client
3678 * generated for creating. So using ->fid1 is okay here.
3680 if (!fid_is_sane(fid1)) {
3681 CERROR("%s: Fid is insane "DFID"\n",
3682 sbi->ll_fsname, PFID(fid1));
3683 GOTO(out, rc = -EINVAL);
3686 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3687 if (IS_ERR(*inode)) {
3689 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3691 CERROR("new_inode -fatal: rc %d\n", rc);
3696 /* Handling piggyback layout lock.
3697 * Layout lock can be piggybacked by getattr and open request.
3698 * The lsm can be applied to inode only if it comes with a layout lock
3699 * otherwise correct layout may be overwritten, for example:
3700 * 1. proc1: mdt returns a lsm but not granting layout
3701 * 2. layout was changed by another client
3702 * 3. proc2: refresh layout and layout lock granted
3703 * 4. proc1: to apply a stale layout */
3704 if (it != NULL && it->it_lock_mode != 0) {
3705 struct lustre_handle lockh;
3706 struct ldlm_lock *lock;
3708 lockh.cookie = it->it_lock_handle;
3709 lock = ldlm_handle2lock(&lockh);
3710 LASSERT(lock != NULL);
3711 if (ldlm_has_layout(lock)) {
3712 struct cl_object_conf conf;
3714 memset(&conf, 0, sizeof(conf));
3715 conf.coc_opc = OBJECT_CONF_SET;
3716 conf.coc_inode = *inode;
3717 conf.coc_lock = lock;
3718 conf.coc_try = false;
3719 conf.u.coc_layout = md.layout;
3720 (void)ll_layout_conf(*inode, &conf);
3722 LDLM_LOCK_PUT(lock);
3725 if (default_lmv_deleted)
3726 ll_update_default_lsm_md(*inode, &md);
3728 /* we may want to apply some policy for foreign file/dir */
3729 if (ll_sbi_has_foreign_symlink(sbi)) {
3730 rc = ll_manage_foreign(*inode, &md);
3738 /* cleanup will be done if necessary */
3739 md_put_lustre_md(sbi->ll_md_exp, &md);
3741 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3742 ll_intent_drop_lock(it);
3743 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3749 int ll_obd_statfs(struct inode *inode, void __user *uarg)
3751 struct ll_sb_info *sbi = NULL;
3752 struct obd_export *exp;
3753 struct obd_ioctl_data *data = NULL;
3758 sbi = ll_i2sbi(inode);
3760 GOTO(out_statfs, rc = -EINVAL);
3762 rc = obd_ioctl_getdata(&data, &len, uarg);
3764 GOTO(out_statfs, rc);
3766 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3767 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3768 GOTO(out_statfs, rc = -EINVAL);
3770 if (data->ioc_inllen1 != sizeof(__u32) ||
3771 data->ioc_inllen2 != sizeof(__u32) ||
3772 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3773 data->ioc_plen2 != sizeof(struct obd_uuid))
3774 GOTO(out_statfs, rc = -EINVAL);
3776 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3777 if (type & LL_STATFS_LMV)
3778 exp = sbi->ll_md_exp;
3779 else if (type & LL_STATFS_LOV)
3780 exp = sbi->ll_dt_exp;
3782 GOTO(out_statfs, rc = -ENODEV);
3784 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3786 GOTO(out_statfs, rc);
3788 OBD_FREE_LARGE(data, len);
3793 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3794 * be called early to avoid deadlock.
3796 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3798 lmv_stripe_object_put(&op_data->op_lso2);
3799 lmv_stripe_object_put(&op_data->op_lso1);
3800 lmv_stripe_object_put(&op_data->op_default_lso1);
3803 /* this function prepares md_op_data hint for passing it down to MD stack. */
3804 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3805 struct inode *i1, struct inode *i2,
3806 const char *name, size_t namelen,
3807 __u32 mode, enum md_op_code opc,
3810 struct llcrypt_name fname = { 0 };
3813 LASSERT(i1 != NULL);
3816 /* Do not reuse namelen for something else. */
3818 return ERR_PTR(-EINVAL);
3820 if ((!IS_ENCRYPTED(i1) ||
3821 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3822 namelen > ll_i2sbi(i1)->ll_namelen)
3823 return ERR_PTR(-ENAMETOOLONG);
3825 /* "/" is not valid name, but it's allowed */
3826 if (!lu_name_is_valid_2(name, namelen) &&
3827 strncmp("/", name, namelen) != 0)
3828 return ERR_PTR(-EINVAL);
3831 if (op_data == NULL)
3832 OBD_ALLOC_PTR(op_data);
3834 if (op_data == NULL)
3835 return ERR_PTR(-ENOMEM);
3837 ll_i2gids(op_data->op_suppgids, i1, i2);
3838 /* If the client is using a subdir mount and looks at what it sees as
3839 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3841 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3842 !fid_is_root(ll_inode2fid(i1)) &&
3843 name && namelen == strlen(dot_fscrypt_name) &&
3844 strncmp(name, dot_fscrypt_name, namelen) == 0))
3845 lu_root_fid(&op_data->op_fid1);
3847 op_data->op_fid1 = *ll_inode2fid(i1);
3849 if (S_ISDIR(i1->i_mode)) {
3850 down_read(&ll_i2info(i1)->lli_lsm_sem);
3852 lmv_stripe_object_get(ll_i2info(i1)->lli_lsm_obj);
3853 op_data->op_default_lso1 =
3854 lmv_stripe_object_get(ll_i2info(i1)->lli_def_lsm_obj);
3855 up_read(&ll_i2info(i1)->lli_lsm_sem);
3859 op_data->op_fid2 = *ll_inode2fid(i2);
3860 if (S_ISDIR(i2->i_mode)) {
3861 down_read(&ll_i2info(i2)->lli_lsm_sem);
3863 lmv_stripe_object_get(ll_i2info(i2)->lli_lsm_obj);
3864 up_read(&ll_i2info(i2)->lli_lsm_sem);
3867 fid_zero(&op_data->op_fid2);
3870 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3871 op_data->op_cli_flags |= CLI_HASH64;
3873 if (ll_need_32bit_api(ll_i2sbi(i1)))
3874 op_data->op_cli_flags |= CLI_API32;
3876 if ((i2 && is_root_inode(i2)) ||
3877 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3878 /* In case of lookup, ll_setup_filename() has already been
3879 * called in ll_lookup_it(), so just take provided name.
3880 * Also take provided name if we are dealing with root inode.
3882 fname.disk_name.name = (unsigned char *)name;
3883 fname.disk_name.len = namelen;
3884 } else if (name && namelen) {
3885 struct qstr dname = QSTR_INIT(name, namelen);
3887 struct lu_fid *pfid = NULL;
3891 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3892 /* special case when called from ll_link() */
3897 lookup = (int)(opc == LUSTRE_OPC_ANY);
3899 if (opc == LUSTRE_OPC_ANY && lookup)
3901 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3903 ll_finish_md_op_data(op_data);
3906 if (pfid && !fid_is_zero(pfid)) {
3908 op_data->op_fid2 = fid;
3909 op_data->op_bias = MDS_FID_OP;
3911 if (fname.disk_name.name &&
3912 fname.disk_name.name != (unsigned char *)name) {
3913 /* op_data->op_name must be freed after use */
3914 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3918 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3919 * are LUSTRE_OPC_ANY
3921 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3922 op_data->op_code = LUSTRE_OPC_ANY;
3924 op_data->op_code = opc;
3925 op_data->op_name = fname.disk_name.name;
3926 op_data->op_namelen = fname.disk_name.len;
3927 op_data->op_mode = mode;
3928 op_data->op_mod_time = ktime_get_real_seconds();
3929 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3930 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3931 op_data->op_cap = current_cap();
3932 op_data->op_mds = 0;
3933 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3934 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3935 op_data->op_bias |= MDS_CREATE_VOLATILE;
3937 op_data->op_data = data;
3942 void ll_finish_md_op_data(struct md_op_data *op_data)
3944 ll_unlock_md_op_lsm(op_data);
3945 ll_security_release_secctx(op_data->op_file_secctx,
3946 op_data->op_file_secctx_size,
3947 op_data->op_file_secctx_slot);
3948 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3949 /* allocated via ll_setup_filename called
3950 * from ll_prep_md_op_data
3952 kfree(op_data->op_name);
3953 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3954 OBD_FREE_PTR(op_data);
3957 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3959 struct ll_sb_info *sbi;
3962 LASSERT(seq && dentry);
3963 sbi = ll_s2sbi(dentry->d_sb);
3965 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3966 seq_puts(seq, "nolock");
3968 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3969 /* match_table in some cases has patterns for both enabled and
3970 * disabled cases. Ignore 'no'xxx versions if bit is set.
3972 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3973 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3974 if (ll_sbi_flags_name[i].token ==
3975 LL_SBI_FOREIGN_SYMLINK) {
3976 seq_show_option(seq, "foreign_symlink",
3977 sbi->ll_foreign_symlink_prefix);
3979 seq_printf(seq, ",%s",
3980 ll_sbi_flags_name[i].pattern);
3983 /* You can have either localflock or flock but not
3984 * both. If localflock is set don't print flock or
3987 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3989 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3990 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3991 seq_printf(seq, ",%s",
3992 ll_sbi_flags_name[i].pattern);
3996 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
4002 * Get obd name by cmd, and copy out to user space
4004 int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg)
4006 struct ll_sb_info *sbi = ll_i2sbi(inode);
4007 struct obd_device *obd;
4010 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
4011 obd = class_exp2obd(sbi->ll_dt_exp);
4012 else if (cmd == OBD_IOC_GETMDNAME)
4013 obd = class_exp2obd(sbi->ll_md_exp);
4020 if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1))
4027 struct work_struct db_work;
4028 struct dentry *db_dentry;
4029 /* Let's hope the path is not too long, 32 bytes for the work struct
4032 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
4035 static void ll_dput_later(struct work_struct *work)
4037 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
4039 dput(db->db_dentry);
4040 free_page((unsigned long)db);
4043 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
4050 p.mnt = current->fs->root.mnt;
4052 path = d_path(&p, buf, bufsize);
4057 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
4059 struct dname_buf *db;
4061 struct dentry *dentry = NULL;
4063 /* this can be called inside spin lock so use GFP_ATOMIC. */
4064 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
4067 dentry = d_find_alias(inode);
4069 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
4072 /* The below message is checked in recovery-small.sh test_24b */
4074 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
4075 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
4076 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
4077 PFID(ll_inode2fid(inode)),
4078 (path && !IS_ERR(path)) ? path : "", ioret);
4080 if (dentry != NULL) {
4081 /* We cannot dput here since if we happen to be the last holder
4082 * then we can end up waiting for page evictions that
4083 * in turn wait for RPCs that need this instance of ptlrpcd
4084 * (callng brw_interpret->*page_completion*->vmpage_error->here)
4087 INIT_WORK(&db->db_work, ll_dput_later);
4088 db->db_dentry = dentry;
4089 schedule_work(&db->db_work);
4092 free_page((unsigned long)db);
4096 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
4097 struct lov_user_md **kbuf)
4099 struct lov_user_md lum;
4103 if (copy_from_user(&lum, md, sizeof(lum)))
4106 lum_size = ll_lov_user_md_size(&lum);
4110 OBD_ALLOC_LARGE(*kbuf, lum_size);
4114 if (copy_from_user(*kbuf, md, lum_size) != 0) {
4115 OBD_FREE_LARGE(*kbuf, lum_size);
4123 * Compute llite root squash state after a change of root squash
4124 * configuration setting or add/remove of a lnet nid
4126 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
4128 struct root_squash_info *squash = &sbi->ll_squash;
4131 struct lnet_processid id;
4133 /* Update norootsquash flag */
4134 spin_lock(&squash->rsi_lock);
4135 if (list_empty(&squash->rsi_nosquash_nids))
4136 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4138 /* Do not apply root squash as soon as one of our NIDs is
4139 * in the nosquash_nids list
4141 struct lustre_sb_info *lsi = sbi->lsi;
4142 bool large_nid = false;
4144 if (exp_connect_flags2(lsi->lsi_mgc->u.cli.cl_mgc_mgsexp) &
4145 OBD_CONNECT2_LARGE_NID)
4150 while (LNetGetId(i++, &id, large_nid) != -ENOENT) {
4151 if (nid_is_lo0(&id.nid))
4153 if (cfs_match_nid(&id.nid,
4154 &squash->rsi_nosquash_nids)) {
4160 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4162 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4164 spin_unlock(&squash->rsi_lock);
4168 * Parse linkea content to extract information about a given hardlink
4170 * \param[in] ldata - Initialized linkea data
4171 * \param[in] linkno - Link identifier
4172 * \param[out] parent_fid - The entry's parent FID
4173 * \param[out] ln - Entry name destination buffer
4175 * \retval 0 on success
4176 * \retval Appropriate negative error code on failure
4178 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
4179 struct lu_fid *parent_fid, struct lu_name *ln)
4185 rc = linkea_init_with_rec(ldata);
4189 if (linkno >= ldata->ld_leh->leh_reccount)
4190 /* beyond last link */
4193 linkea_first_entry(ldata);
4194 for (idx = 0; ldata->ld_lee != NULL; idx++) {
4195 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
4200 linkea_next_entry(ldata);
4210 * Get parent FID and name of an identified link. Operation is performed for
4211 * a given link number, letting the caller iterate over linkno to list one or
4212 * all links of an entry.
4214 * \param[in] file - File descriptor against which to perform the operation
4215 * \param[in,out] arg - User-filled structure containing the linkno to operate
4216 * on and the available size. It is eventually filled with
4217 * the requested information or left untouched on error
4219 * \retval - 0 on success
4220 * \retval - Appropriate negative error code on failure
4222 int ll_getparent(struct file *file, struct getparent __user *arg)
4224 struct inode *inode = file_inode(file);
4225 struct linkea_data *ldata;
4226 struct lu_buf buf = LU_BUF_NULL;
4228 struct lu_fid parent_fid;
4235 if (!capable(CAP_DAC_READ_SEARCH) &&
4236 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
4239 if (get_user(name_size, &arg->gp_name_size))
4242 if (get_user(linkno, &arg->gp_linkno))
4245 if (name_size > PATH_MAX)
4248 OBD_ALLOC(ldata, sizeof(*ldata));
4252 rc = linkea_data_new(ldata, &buf);
4254 GOTO(ldata_free, rc);
4256 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
4257 buf.lb_len, OBD_MD_FLXATTR);
4261 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
4265 if (ln.ln_namelen >= name_size)
4266 GOTO(lb_free, rc = -EOVERFLOW);
4268 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
4269 GOTO(lb_free, rc = -EFAULT);
4271 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
4272 GOTO(lb_free, rc = -EFAULT);
4274 if (put_user('\0', arg->gp_name + ln.ln_namelen))
4275 GOTO(lb_free, rc = -EFAULT);
4280 OBD_FREE(ldata, sizeof(*ldata));