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 sbi->ll_ra_info.ra_max_pages_per_file =
162 min(sbi->ll_ra_info.ra_max_pages / 4,
163 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
164 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
165 sbi->ll_ra_info.ra_max_pages_per_file;
166 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
167 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
168 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
170 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
171 #ifdef CONFIG_ENABLE_CHECKSUM
172 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
174 #ifdef CONFIG_ENABLE_FLOCK
175 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
178 #ifdef HAVE_LRU_RESIZE_SUPPORT
179 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
181 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
183 /* metadata statahead is enabled by default */
184 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
185 sbi->ll_sa_batch_max = LL_SA_BATCH_DEF;
186 sbi->ll_sa_max = LL_SA_RPC_DEF;
187 atomic_set(&sbi->ll_sa_total, 0);
188 atomic_set(&sbi->ll_sa_wrong, 0);
189 atomic_set(&sbi->ll_sa_running, 0);
190 atomic_set(&sbi->ll_agl_total, 0);
191 atomic_set(&sbi->ll_sa_hit_total, 0);
192 atomic_set(&sbi->ll_sa_miss_total, 0);
193 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
194 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
195 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
196 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
197 set_bit(LL_SBI_UNALIGNED_DIO, sbi->ll_flags);
198 ll_sbi_set_encrypt(sbi, true);
199 ll_sbi_set_name_encrypt(sbi, true);
202 sbi->ll_squash.rsi_uid = 0;
203 sbi->ll_squash.rsi_gid = 0;
204 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
205 spin_lock_init(&sbi->ll_squash.rsi_lock);
207 /* Per-filesystem file heat */
208 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
209 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
211 /* Per-fs open heat level before requesting open lock */
212 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
213 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
214 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
217 if (sbi->ll_foreign_symlink_prefix)
218 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
220 cl_cache_decref(sbi->ll_cache);
221 sbi->ll_cache = NULL;
223 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
225 pcc_super_fini(&sbi->ll_pcc_super);
231 static void ll_free_sbi(struct super_block *sb)
233 struct ll_sb_info *sbi = ll_s2sbi(sb);
237 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
238 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
239 if (sbi->ll_ra_info.ll_readahead_wq)
240 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
241 if (sbi->ll_cache != NULL) {
242 cl_cache_decref(sbi->ll_cache);
243 sbi->ll_cache = NULL;
245 if (sbi->ll_foreign_symlink_prefix) {
246 OBD_FREE(sbi->ll_foreign_symlink_prefix,
247 sbi->ll_foreign_symlink_prefix_size);
248 sbi->ll_foreign_symlink_prefix = NULL;
250 if (sbi->ll_foreign_symlink_upcall) {
251 OBD_FREE(sbi->ll_foreign_symlink_upcall,
252 strlen(sbi->ll_foreign_symlink_upcall) +
254 sbi->ll_foreign_symlink_upcall = NULL;
256 if (sbi->ll_foreign_symlink_upcall_items) {
258 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
259 struct ll_foreign_symlink_upcall_item *items =
260 sbi->ll_foreign_symlink_upcall_items;
262 for (i = 0 ; i < nb_items; i++)
263 if (items[i].type == STRING_TYPE)
264 OBD_FREE(items[i].string,
267 OBD_FREE_LARGE(items, nb_items *
268 sizeof(struct ll_foreign_symlink_upcall_item));
269 sbi->ll_foreign_symlink_upcall_items = NULL;
271 if (sbi->ll_secctx_name)
272 ll_secctx_name_free(sbi);
274 ll_free_rw_stats_info(sbi);
275 pcc_super_fini(&sbi->ll_pcc_super);
276 OBD_FREE(sbi, sizeof(*sbi));
281 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
283 struct inode *root = NULL;
284 struct ll_sb_info *sbi = ll_s2sbi(sb);
285 struct obd_statfs *osfs = NULL;
286 struct ptlrpc_request *request = NULL;
287 struct obd_connect_data *data = NULL;
288 struct obd_uuid *uuid;
289 struct md_op_data *op_data;
290 struct lustre_md lmd;
292 int size, err, checksum;
298 sbi->ll_md_obd = class_name2obd(md);
299 if (!sbi->ll_md_obd) {
300 CERROR("MD %s: not setup or attached\n", md);
314 /* pass client page size via ocd_grant_blkbits, the server should report
315 * back its backend blocksize for grant calculation purpose */
316 data->ocd_grant_blkbits = PAGE_SHIFT;
318 /* indicate MDT features supported by this client */
319 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
320 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
321 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
322 OBD_CONNECT_SRVLOCK |
323 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
324 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
325 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
326 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
327 OBD_CONNECT_64BITHASH |
328 OBD_CONNECT_EINPROGRESS |
329 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
330 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
331 OBD_CONNECT_MAX_EASIZE |
332 OBD_CONNECT_FLOCK_DEAD |
333 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
334 OBD_CONNECT_OPEN_BY_FID |
335 OBD_CONNECT_DIR_STRIPE |
336 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
337 OBD_CONNECT_SUBTREE |
338 OBD_CONNECT_MULTIMODRPCS |
339 OBD_CONNECT_GRANT_PARAM |
340 OBD_CONNECT_GRANT_SHRINK |
341 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
343 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
344 OBD_CONNECT2_SUM_STATFS |
345 OBD_CONNECT2_OVERSTRIPING |
347 OBD_CONNECT2_LOCK_CONVERT |
348 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
349 OBD_CONNECT2_INC_XID |
351 OBD_CONNECT2_ASYNC_DISCARD |
353 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
354 OBD_CONNECT2_GETATTR_PFID |
355 OBD_CONNECT2_DOM_LVB |
356 OBD_CONNECT2_REP_MBITS |
357 OBD_CONNECT2_ATOMIC_OPEN_LOCK |
358 OBD_CONNECT2_BATCH_RPC |
359 OBD_CONNECT2_DMV_IMP_INHERIT;
361 #ifdef HAVE_LRU_RESIZE_SUPPORT
362 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
363 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
365 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
367 data->ocd_cksum_types = obd_cksum_types_supported_client();
369 if (CFS_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
370 /* flag mdc connection as lightweight, only used for test
371 * purpose, use with care */
372 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
374 data->ocd_ibits_known = MDS_INODELOCK_FULL;
375 data->ocd_version = LUSTRE_VERSION_CODE;
377 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
378 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
381 /* Setting this indicates we correctly support S_NOSEC (See kernel
382 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
384 sb->s_flags |= SB_NOSEC;
386 sbi->ll_fop = ll_select_file_operations(sbi);
388 /* always ping even if server suppress_pings */
389 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
390 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
392 obd_connect_set_secctx(data);
393 if (ll_sbi_has_encrypt(sbi)) {
394 obd_connect_set_enc_fid2path(data);
395 obd_connect_set_name_enc(data);
396 obd_connect_set_enc(data);
399 #if defined(CONFIG_SECURITY)
400 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
403 data->ocd_brw_size = MD_MAX_BRW_SIZE;
406 if (sb->s_flags & SB_RDONLY)
407 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
408 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
409 &sbi->ll_sb_uuid, data, sbi->ll_cache);
411 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
412 "recovery, of which this client is not a "
413 "part. Please wait for recovery to complete,"
414 " abort, or time out.\n", md);
417 CERROR("cannot connect to %s: rc = %d\n", md, err);
421 sbi->ll_md_exp->exp_connect_data = *data;
423 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
424 LUSTRE_SEQ_METADATA);
426 CERROR("%s: Can't init metadata layer FID infrastructure, "
427 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
431 /* For mount, we only need fs info from MDT0, and also in DNE, it
432 * can make sure the client can be mounted as long as MDT0 is
434 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
435 ktime_get_seconds() - sbi->ll_statfs_max_age,
436 OBD_STATFS_FOR_MDT0);
437 if (err == -EROFS && !(sb->s_flags & SB_RDONLY)) {
438 /* We got -EROFS from the server, maybe it is imposing
439 * read-only mount. So just retry like this.
441 cfs_tty_write_msg("Forcing read-only mount.\n\r");
442 CERROR("%s: mount failed with %d, forcing read-only mount.\n",
443 sbi->ll_md_exp->exp_obd->obd_name, err);
444 sb->s_flags |= SB_RDONLY;
445 obd_fid_fini(sbi->ll_md_exp->exp_obd);
446 obd_disconnect(sbi->ll_md_exp);
447 GOTO(retry_connect, err);
449 GOTO(out_md_fid, err);
452 /* This needs to be after statfs to ensure connect has finished.
453 * Note that "data" does NOT contain the valid connect reply.
454 * If connecting to a 1.8 server there will be no LMV device, so
455 * we can access the MDC export directly and exp_connect_flags will
456 * be non-zero, but if accessing an upgraded 2.1 server it will
457 * have the correct flags filled in.
458 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
459 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
460 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
461 valid != CLIENT_CONNECT_MDT_REQD) {
464 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
465 obd_connect_flags2str(buf, PAGE_SIZE,
466 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
467 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
468 "feature(s) needed for correct operation "
469 "of this client (%s). Please upgrade "
470 "server or downgrade client.\n",
471 sbi->ll_md_exp->exp_obd->obd_name, buf);
472 OBD_FREE(buf, PAGE_SIZE);
473 GOTO(out_md_fid, err = -EPROTO);
476 size = sizeof(*data);
477 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
478 KEY_CONN_DATA, &size, data);
480 CERROR("%s: Get connect data failed: rc = %d\n",
481 sbi->ll_md_exp->exp_obd->obd_name, err);
482 GOTO(out_md_fid, err);
485 LASSERT(osfs->os_bsize);
486 sb->s_blocksize = osfs->os_bsize;
487 sb->s_blocksize_bits = log2(osfs->os_bsize);
488 sb->s_magic = LL_SUPER_MAGIC;
489 sb->s_maxbytes = MAX_LFS_FILESIZE;
490 sbi->ll_inode_cache_enabled = 1;
491 sbi->ll_namelen = osfs->os_namelen;
492 sbi->ll_mnt.mnt = current->fs->root.mnt;
493 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
495 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
496 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
497 LCONSOLE_INFO("Disabling user_xattr feature because "
498 "it is not supported on the server\n");
499 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
502 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
504 sb->s_flags |= SB_POSIXACL;
506 set_bit(LL_SBI_ACL, sbi->ll_flags);
508 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
510 sb->s_flags &= ~SB_POSIXACL;
512 clear_bit(LL_SBI_ACL, sbi->ll_flags);
515 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
516 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
518 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
519 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
521 if (obd_connect_has_secctx(data))
522 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
524 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
525 if (ll_sb_has_test_dummy_encryption(sb))
526 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
528 sbi->ll_md_exp->exp_obd->obd_name);
529 ll_sbi_set_encrypt(sbi, false);
532 if (ll_sbi_has_name_encrypt(sbi) && !obd_connect_has_name_enc(data)) {
533 struct lustre_sb_info *lsi = s2lsi(sb);
535 if (ll_sb_has_test_dummy_encryption(sb))
536 LCONSOLE_WARN("%s: server %s does not support name encryption, not using it.\n",
538 sbi->ll_md_exp->exp_obd->obd_name);
539 #ifdef CONFIG_LL_ENCRYPTION
540 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
542 lsi->lsi_flags &= ~LSI_FILENAME_ENC_B64_OLD_CLI;
543 ll_sbi_set_name_encrypt(sbi, false);
546 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
547 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
548 LCONSOLE_INFO("%s: disabling xattr cache due to "
549 "unknown maximum xattr size.\n", dt);
550 } else if (!sbi->ll_xattr_cache_set) {
551 /* If xattr_cache is already set (no matter 0 or 1)
552 * during processing llog, it won't be enabled here. */
553 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
554 sbi->ll_xattr_cache_enabled = 1;
558 sbi->ll_dt_obd = class_name2obd(dt);
559 if (!sbi->ll_dt_obd) {
560 CERROR("DT %s: not setup or attached\n", dt);
561 GOTO(out_md_fid, err = -ENODEV);
564 /* pass client page size via ocd_grant_blkbits, the server should report
565 * back its backend blocksize for grant calculation purpose */
566 data->ocd_grant_blkbits = PAGE_SHIFT;
568 /* indicate OST features supported by this client */
569 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
570 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
571 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
572 OBD_CONNECT_SRVLOCK |
573 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
574 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
575 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
576 OBD_CONNECT_EINPROGRESS |
577 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
578 OBD_CONNECT_LAYOUTLOCK |
579 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
580 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
581 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
582 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
583 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
584 OBD_CONNECT2_REP_MBITS;
586 if (!CFS_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
587 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
589 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
590 * disabled by default, because it can still be enabled on the
591 * fly via /sys. As a consequence, we still need to come to an
592 * agreement on the supported algorithms at connect time
594 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
596 if (CFS_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
597 data->ocd_cksum_types = OBD_CKSUM_ADLER;
599 data->ocd_cksum_types = obd_cksum_types_supported_client();
601 #ifdef HAVE_LRU_RESIZE_SUPPORT
602 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
604 /* always ping even if server suppress_pings */
605 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
606 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
608 if (ll_sbi_has_encrypt(sbi))
609 obd_connect_set_enc(data);
611 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
612 "ocd_grant: %d\n", data->ocd_connect_flags,
613 data->ocd_version, data->ocd_grant);
615 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
616 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
618 data->ocd_brw_size = DT_MAX_BRW_SIZE;
620 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
621 &sbi->ll_sb_uuid, data, sbi->ll_cache);
623 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
624 "recovery, of which this client is not a "
625 "part. Please wait for recovery to "
626 "complete, abort, or time out.\n", dt);
629 CERROR("%s: Cannot connect to %s: rc = %d\n",
630 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
634 if (ll_sbi_has_encrypt(sbi) &&
635 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
636 if (ll_sb_has_test_dummy_encryption(sb))
637 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
639 ll_sbi_set_encrypt(sbi, false);
640 } else if (ll_sb_has_test_dummy_encryption(sb)) {
641 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
644 sbi->ll_dt_exp->exp_connect_data = *data;
646 /* Don't change value if it was specified in the config log */
647 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
648 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
649 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
650 (data->ocd_brw_size >> PAGE_SHIFT));
651 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
652 sbi->ll_ra_info.ra_max_pages_per_file)
653 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
654 sbi->ll_ra_info.ra_max_pages_per_file;
657 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
658 LUSTRE_SEQ_METADATA);
660 CERROR("%s: Can't init data layer FID infrastructure, "
661 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
665 mutex_lock(&sbi->ll_lco.lco_lock);
666 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
667 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
668 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
669 mutex_unlock(&sbi->ll_lco.lco_lock);
671 fid_zero(&sbi->ll_root_fid);
672 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
675 CERROR("cannot mds_connect: rc = %d\n", err);
676 GOTO(out_lock_cn_cb, err);
678 if (!fid_is_sane(&sbi->ll_root_fid)) {
679 CERROR("%s: Invalid root fid "DFID" during mount\n",
680 sbi->ll_md_exp->exp_obd->obd_name,
681 PFID(&sbi->ll_root_fid));
682 GOTO(out_lock_cn_cb, err = -EINVAL);
684 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
686 sb->s_op = &lustre_super_operations;
687 sb->s_xattr = ll_xattr_handlers;
688 #if THREAD_SIZE >= 8192 /*b=17630*/
689 sb->s_export_op = &lustre_export_operations;
691 #ifdef HAVE_LUSTRE_CRYPTO
692 llcrypt_set_ops(sb, &lustre_cryptops);
696 * XXX: move this to after cbd setup? */
697 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
699 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
700 valid |= OBD_MD_FLACL;
702 OBD_ALLOC_PTR(op_data);
704 GOTO(out_lock_cn_cb, err = -ENOMEM);
706 op_data->op_fid1 = sbi->ll_root_fid;
707 op_data->op_mode = 0;
708 op_data->op_valid = valid;
710 err = md_getattr(sbi->ll_md_exp, op_data, &request);
712 /* We need enc ctx info, so reset it in op_data to
713 * prevent it from being freed.
715 encctx = op_data->op_file_encctx;
716 encctxlen = op_data->op_file_encctx_size;
717 op_data->op_file_encctx = NULL;
718 op_data->op_file_encctx_size = 0;
719 OBD_FREE_PTR(op_data);
721 CERROR("%s: md_getattr failed for root: rc = %d\n",
722 sbi->ll_md_exp->exp_obd->obd_name, err);
723 GOTO(out_lock_cn_cb, err);
726 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
727 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
729 CERROR("failed to understand root inode md: rc = %d\n", err);
730 ptlrpc_req_finished(request);
731 GOTO(out_lock_cn_cb, err);
734 LASSERT(fid_is_sane(&sbi->ll_root_fid));
735 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
736 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
737 md_put_lustre_md(sbi->ll_md_exp, &lmd);
741 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
743 CERROR("%s: bad ll_iget() for root: rc = %d\n",
744 sbi->ll_fsname, err);
745 ptlrpc_req_finished(request);
749 err = ll_secctx_name_store(root);
750 if (err < 0 && ll_security_xattr_wanted(root))
751 CWARN("%s: file security contextes not supported: rc = %d\n",
752 sbi->ll_fsname, err);
757 "server returned encryption ctx for root inode "DFID"\n",
758 PFID(&sbi->ll_root_fid));
759 err = ll_set_encflags(root, encctx, encctxlen, true);
761 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
763 PFID(&sbi->ll_root_fid), err);
765 ptlrpc_req_finished(request);
767 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
768 if (sbi->ll_checksum_set) {
769 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
770 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
771 sizeof(checksum), &checksum, NULL);
773 CERROR("%s: Set checksum failed: rc = %d\n",
774 sbi->ll_dt_exp->exp_obd->obd_name, err);
780 sb->s_root = d_make_root(root);
781 if (sb->s_root == NULL) {
783 CERROR("%s: can't make root dentry: rc = %d\n",
784 sbi->ll_fsname, err);
788 sbi->ll_sdev_orig = sb->s_dev;
790 /* We set sb->s_dev equal on all lustre clients in order to support
791 * NFS export clustering. NFSD requires that the FSID be the same
793 /* s_dev is also used in lt_compare() to compare two fs, but that is
794 * only a node-local comparison. */
795 uuid = obd_get_uuid(sbi->ll_md_exp);
797 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
804 if (sbi->ll_dt_obd) {
805 err = sysfs_create_link(&sbi->ll_kset.kobj,
806 &sbi->ll_dt_obd->obd_kset.kobj,
807 sbi->ll_dt_obd->obd_type->typ_name);
809 CERROR("%s: could not register %s in llite: rc = %d\n",
810 dt, sbi->ll_fsname, err);
815 if (sbi->ll_md_obd) {
816 err = sysfs_create_link(&sbi->ll_kset.kobj,
817 &sbi->ll_md_obd->obd_kset.kobj,
818 sbi->ll_md_obd->obd_type->typ_name);
820 CERROR("%s: could not register %s in llite: rc = %d\n",
821 md, sbi->ll_fsname, err);
830 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
832 obd_disconnect(sbi->ll_dt_exp);
833 sbi->ll_dt_exp = NULL;
834 sbi->ll_dt_obd = NULL;
836 obd_fid_fini(sbi->ll_md_exp->exp_obd);
838 obd_disconnect(sbi->ll_md_exp);
839 sbi->ll_md_exp = NULL;
840 sbi->ll_md_obd = NULL;
849 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
853 size = sizeof(*lmmsize);
854 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
855 KEY_MAX_EASIZE, &size, lmmsize);
857 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
858 sbi->ll_dt_exp->exp_obd->obd_name, rc);
862 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
865 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
866 KEY_MAX_EASIZE, &size, lmmsize);
868 CERROR("Get max mdsize error rc %d\n", rc);
870 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
876 * Get the value of the default_easize parameter.
878 * \see client_obd::cl_default_mds_easize
880 * \param[in] sbi superblock info for this filesystem
881 * \param[out] lmmsize pointer to storage location for value
883 * \retval 0 on success
884 * \retval negative negated errno on failure
886 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
891 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
892 KEY_DEFAULT_EASIZE, &size, lmmsize);
894 CERROR("Get default mdsize error rc %d\n", rc);
900 * Set the default_easize parameter to the given value.
902 * \see client_obd::cl_default_mds_easize
904 * \param[in] sbi superblock info for this filesystem
905 * \param[in] lmmsize the size to set
907 * \retval 0 on success
908 * \retval negative negated errno on failure
910 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
914 if (lmmsize < sizeof(struct lov_mds_md) ||
915 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
918 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
919 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
920 sizeof(int), &lmmsize, NULL);
925 static void client_common_put_super(struct super_block *sb)
927 struct ll_sb_info *sbi = ll_s2sbi(sb);
932 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
933 obd_disconnect(sbi->ll_dt_exp);
934 sbi->ll_dt_exp = NULL;
936 ll_debugfs_unregister_super(sb);
938 obd_fid_fini(sbi->ll_md_exp->exp_obd);
939 obd_disconnect(sbi->ll_md_exp);
940 sbi->ll_md_exp = NULL;
945 void ll_kill_super(struct super_block *sb)
947 struct ll_sb_info *sbi;
951 if (!(sb->s_flags & SB_ACTIVE))
955 /* we need restore s_dev from changed for clustred NFS before put_super
956 * because new kernels have cached s_dev and change sb->s_dev in
957 * put_super not affected real removing devices */
959 sb->s_dev = sbi->ll_sdev_orig;
961 /* wait running statahead threads to quit */
962 while (atomic_read(&sbi->ll_sa_running) > 0)
963 schedule_timeout_uninterruptible(
964 cfs_time_seconds(1) >> 3);
970 /* Since we use this table for ll_sbi_flags_seq_show make
971 * sure what you want displayed for a specific token that
972 * is listed more than once below be listed first. For
973 * example we want "checksum" displayed, not "nochecksum"
976 static const match_table_t ll_sbi_flags_name = {
977 {LL_SBI_NOLCK, "nolock"},
978 {LL_SBI_CHECKSUM, "checksum"},
979 {LL_SBI_CHECKSUM, "nochecksum"},
980 {LL_SBI_LOCALFLOCK, "localflock"},
981 {LL_SBI_FLOCK, "flock"},
982 {LL_SBI_FLOCK, "noflock"},
983 {LL_SBI_USER_XATTR, "user_xattr"},
984 {LL_SBI_USER_XATTR, "nouser_xattr"},
985 {LL_SBI_LRU_RESIZE, "lruresize"},
986 {LL_SBI_LRU_RESIZE, "nolruresize"},
987 {LL_SBI_LAZYSTATFS, "lazystatfs"},
988 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
989 {LL_SBI_32BIT_API, "32bitapi"},
990 {LL_SBI_USER_FID2PATH, "user_fid2path"},
991 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
992 {LL_SBI_VERBOSE, "verbose"},
993 {LL_SBI_VERBOSE, "noverbose"},
994 {LL_SBI_ALWAYS_PING, "always_ping"},
995 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
996 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
997 {LL_SBI_ENCRYPT, "encrypt"},
998 {LL_SBI_ENCRYPT, "noencrypt"},
999 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
1000 {LL_SBI_NUM_MOUNT_OPT, NULL},
1002 {LL_SBI_ACL, "acl"},
1003 {LL_SBI_AGL_ENABLED, "agl"},
1004 {LL_SBI_64BIT_HASH, "64bit_hash"},
1005 {LL_SBI_LAYOUT_LOCK, "layout"},
1006 {LL_SBI_XATTR_CACHE, "xattr_cache"},
1007 {LL_SBI_NOROOTSQUASH, "norootsquash"},
1008 {LL_SBI_FAST_READ, "fast_read"},
1009 {LL_SBI_FILE_SECCTX, "file_secctx"},
1010 {LL_SBI_TINY_WRITE, "tiny_write"},
1011 {LL_SBI_FILE_HEAT, "file_heat"},
1012 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
1013 {LL_SBI_ENCRYPT_NAME, "name_encrypt"},
1014 {LL_SBI_UNALIGNED_DIO, "unaligned_dio"},
1017 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
1019 struct super_block *sb = m->private;
1022 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
1025 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
1028 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
1029 if (ll_sbi_flags_name[j].token == i &&
1030 ll_sbi_flags_name[j].pattern) {
1031 seq_printf(m, "%s ",
1032 ll_sbi_flags_name[j].pattern);
1037 seq_puts(m, "\b\n");
1041 /* non-client-specific mount options are parsed in lmd_parse */
1042 static int ll_options(char *options, struct super_block *sb)
1044 struct ll_sb_info *sbi = ll_s2sbi(sb);
1045 char *s2, *s1, *opts;
1052 /* Don't stomp on lmd_opts */
1053 opts = kstrdup(options, GFP_KERNEL);
1059 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1061 while ((s1 = strsep(&opts, ",")) != NULL) {
1062 substring_t args[MAX_OPT_ARGS];
1063 bool turn_off = false;
1069 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1071 if (strncmp(s1, "no", 2) == 0)
1075 * Initialize args struct so we know whether arg was
1076 * found; some options take optional arguments.
1079 args[0].from = NULL;
1080 token = match_token(s1, ll_sbi_flags_name, args);
1081 if (token == LL_SBI_NUM_MOUNT_OPT) {
1082 if (match_wildcard("context", s1) ||
1083 match_wildcard("fscontext", s1) ||
1084 match_wildcard("defcontext", s1) ||
1085 match_wildcard("rootcontext",s1))
1088 LCONSOLE_ERROR_MSG(0x152,
1089 "Unknown option '%s', won't mount.\n",
1096 case LL_SBI_32BIT_API:
1097 case LL_SBI_64BIT_HASH:
1098 case LL_SBI_ALWAYS_PING:
1099 set_bit(token, sbi->ll_flags);
1103 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1105 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1107 set_bit(token, sbi->ll_flags);
1110 case LL_SBI_LOCALFLOCK:
1111 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1112 set_bit(token, sbi->ll_flags);
1115 case LL_SBI_CHECKSUM:
1116 sbi->ll_checksum_set = 1;
1118 case LL_SBI_USER_XATTR:
1119 case LL_SBI_USER_FID2PATH:
1120 case LL_SBI_LRU_RESIZE:
1121 case LL_SBI_LAZYSTATFS:
1122 case LL_SBI_VERBOSE:
1124 clear_bit(token, sbi->ll_flags);
1126 set_bit(token, sbi->ll_flags);
1128 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1129 #ifdef HAVE_LUSTRE_CRYPTO
1130 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1131 set_bit(token, sbi->ll_flags);
1133 struct lustre_sb_info *lsi = s2lsi(sb);
1135 err = llcrypt_set_test_dummy_encryption(sb,
1136 #ifdef HAVE_FSCRYPT_SET_TEST_DUMMY_ENC_CHAR_ARG
1141 &lsi->lsi_dummy_enc_policy);
1147 "Can't change test_dummy_encryption");
1148 else if (err == -EINVAL)
1150 "Value of option \"%s\" unrecognized",
1154 "Error processing option \"%s\" [%d]",
1159 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1163 case LL_SBI_ENCRYPT:
1164 #ifdef HAVE_LUSTRE_CRYPTO
1166 clear_bit(token, sbi->ll_flags);
1168 set_bit(token, sbi->ll_flags);
1170 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1173 case LL_SBI_FOREIGN_SYMLINK:
1174 /* non-default prefix provided ? */
1179 /* path must be absolute */
1180 if (args->from[0] != '/') {
1181 LCONSOLE_ERROR_MSG(0x152,
1182 "foreign prefix '%s' must be an absolute path\n",
1187 old_len = sbi->ll_foreign_symlink_prefix_size;
1188 old = sbi->ll_foreign_symlink_prefix;
1189 /* alloc for path length and '\0' */
1190 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1191 if (!sbi->ll_foreign_symlink_prefix) {
1192 /* restore previous */
1193 sbi->ll_foreign_symlink_prefix = old;
1194 sbi->ll_foreign_symlink_prefix_size =
1198 sbi->ll_foreign_symlink_prefix_size =
1199 args->to - args->from + 1;
1200 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1201 sbi->ll_foreign_symlink_prefix_size,
1204 OBD_FREE(old, old_len);
1206 /* enable foreign symlink support */
1207 set_bit(token, sbi->ll_flags);
1209 LCONSOLE_ERROR_MSG(0x152,
1210 "invalid %s option\n", s1);
1221 void ll_lli_init(struct ll_inode_info *lli)
1223 lli->lli_inode_magic = LLI_INODE_MAGIC;
1225 rwlock_init(&lli->lli_lock);
1226 lli->lli_posix_acl = NULL;
1227 /* Do not set lli_fid, it has been initialized already. */
1228 fid_zero(&lli->lli_pfid);
1229 lli->lli_mds_read_och = NULL;
1230 lli->lli_mds_write_och = NULL;
1231 lli->lli_mds_exec_och = NULL;
1232 lli->lli_open_fd_read_count = 0;
1233 lli->lli_open_fd_write_count = 0;
1234 lli->lli_open_fd_exec_count = 0;
1235 mutex_init(&lli->lli_och_mutex);
1236 spin_lock_init(&lli->lli_agl_lock);
1237 spin_lock_init(&lli->lli_layout_lock);
1238 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1239 lli->lli_clob = NULL;
1241 init_rwsem(&lli->lli_xattrs_list_rwsem);
1242 mutex_init(&lli->lli_xattrs_enq_lock);
1244 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1245 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1246 lli->lli_opendir_key = NULL;
1247 lli->lli_sai = NULL;
1248 spin_lock_init(&lli->lli_sa_lock);
1249 lli->lli_opendir_pid = 0;
1250 lli->lli_sa_enabled = 0;
1251 init_rwsem(&lli->lli_lsm_sem);
1253 mutex_init(&lli->lli_size_mutex);
1254 mutex_init(&lli->lli_setattr_mutex);
1255 lli->lli_symlink_name = NULL;
1256 ll_trunc_sem_init(&lli->lli_trunc_sem);
1257 range_lock_tree_init(&lli->lli_write_tree);
1258 init_rwsem(&lli->lli_glimpse_sem);
1259 lli->lli_glimpse_time = ktime_set(0, 0);
1260 INIT_LIST_HEAD(&lli->lli_agl_list);
1261 lli->lli_agl_index = 0;
1262 lli->lli_async_rc = 0;
1263 spin_lock_init(&lli->lli_heat_lock);
1264 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1265 lli->lli_heat_flags = 0;
1266 mutex_init(&lli->lli_pcc_lock);
1267 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1268 lli->lli_pcc_inode = NULL;
1269 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1270 lli->lli_pcc_generation = 0;
1271 mutex_init(&lli->lli_group_mutex);
1272 lli->lli_group_users = 0;
1273 lli->lli_group_gid = 0;
1274 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1275 lli->lli_uid = (__u32) -1;
1276 lli->lli_gid = (__u32) -1;
1278 mutex_init(&lli->lli_layout_mutex);
1279 lli->lli_layout_lock_owner = NULL;
1280 /* ll_cl_context initialize */
1281 INIT_LIST_HEAD(&lli->lli_lccs);
1282 seqlock_init(&lli->lli_page_inv_lock);
1283 lli->lli_inode_lock_owner = NULL;
1286 #define MAX_STRING_SIZE 128
1288 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1289 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1291 struct lustre_sb_info *lsi = s2lsi(sb);
1292 char buf[MAX_STRING_SIZE];
1296 err = bdi_init(&lsi->lsi_bdi);
1300 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1301 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1302 lsi->lsi_bdi.name = "lustre";
1303 va_start(args, fmt);
1304 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1306 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1309 sb->s_bdi = &lsi->lsi_bdi;
1313 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1315 int ll_fill_super(struct super_block *sb)
1317 struct lustre_profile *lprof = NULL;
1318 struct lustre_sb_info *lsi = s2lsi(sb);
1319 struct ll_sb_info *sbi = NULL;
1320 char *dt = NULL, *md = NULL;
1321 char *profilenm = get_profile_name(sb);
1322 struct config_llog_instance *cfg;
1323 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1324 const int instlen = LUSTRE_MAXINSTANCE + 2;
1325 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1326 char name[MAX_STRING_SIZE];
1335 /* for ASLR, to map between cfg_instance and hashed ptr */
1336 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1337 profilenm, cfg_instance, sb);
1339 CFS_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1343 GOTO(out_free_cfg, err = -ENOMEM);
1345 /* client additional sb info */
1346 lsi->lsi_llsbi = sbi = ll_init_sbi(lsi);
1348 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1350 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1352 GOTO(out_free_cfg, err);
1354 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1355 #ifdef CONFIG_LL_ENCRYPTION
1356 if (ll_sb_has_test_dummy_encryption(sb))
1357 /* enable filename encryption by default for dummy enc mode */
1358 lsi->lsi_flags |= LSI_FILENAME_ENC;
1360 /* filename encryption is disabled by default */
1361 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1364 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1365 sb->s_d_op = &ll_d_ops;
1368 generate_random_uuid(uuid.b);
1369 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1371 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1374 len = strlen(profilenm);
1375 ptr = strrchr(profilenm, '-');
1376 if (ptr && (strcmp(ptr, "-client") == 0))
1379 if (len > LUSTRE_MAXFSNAME) {
1380 if (unlikely(len >= MAX_STRING_SIZE))
1381 len = MAX_STRING_SIZE - 1;
1382 strncpy(name, profilenm, len);
1384 err = -ENAMETOOLONG;
1385 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1386 name, LUSTRE_MAXFSNAME, err);
1387 GOTO(out_free_cfg, err);
1389 strncpy(sbi->ll_fsname, profilenm, len);
1390 sbi->ll_fsname[len] = '\0';
1393 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1394 profilenm, cfg_instance);
1396 err = super_setup_bdi_name(sb, "%s", name);
1398 GOTO(out_free_cfg, err);
1400 /* disable kernel readahead */
1401 sb->s_bdi->ra_pages = 0;
1402 #ifdef HAVE_BDI_IO_PAGES
1403 sb->s_bdi->io_pages = 0;
1405 sb->s_bdi->capabilities |= LL_BDI_CAP_FLAGS;
1406 #ifdef SB_I_CGROUPWB
1407 sb->s_iflags |= SB_I_CGROUPWB;
1410 /* Call ll_debugfs_register_super() before lustre_process_log()
1411 * so that "llite.*.*" params can be processed correctly.
1413 err = ll_debugfs_register_super(sb, name);
1415 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1416 sbi->ll_fsname, err);
1420 /* The cfg_instance is a value unique to this super, in case some
1421 * joker tries to mount the same fs at two mount points.
1423 cfg->cfg_instance = cfg_instance;
1424 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1425 cfg->cfg_callback = class_config_llog_handler;
1426 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1427 /* set up client obds */
1428 err = lustre_process_log(sb, profilenm, cfg);
1430 GOTO(out_debugfs, err);
1432 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1433 lprof = class_get_profile(profilenm);
1434 if (lprof == NULL) {
1435 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1436 " read from the MGS. Does that filesystem "
1437 "exist?\n", profilenm);
1438 GOTO(out_debugfs, err = -EINVAL);
1440 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1441 lprof->lp_md, lprof->lp_dt);
1443 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1444 OBD_ALLOC(dt, dt_len);
1446 GOTO(out_profile, err = -ENOMEM);
1447 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1449 md_len = strlen(lprof->lp_md) + instlen + 2;
1450 OBD_ALLOC(md, md_len);
1452 GOTO(out_free_dt, err = -ENOMEM);
1453 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1455 /* connections, registrations, sb setup */
1456 err = client_common_fill_super(sb, md, dt);
1458 GOTO(out_free_md, err);
1460 sbi->ll_client_common_fill_super_succeeded = 1;
1464 OBD_FREE(md, md_len);
1467 OBD_FREE(dt, dt_len);
1470 class_put_profile(lprof);
1473 ll_debugfs_unregister_super(sb);
1480 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1481 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1482 sb->s_flags & SB_RDONLY ? " read-only" : "");
1484 } /* ll_fill_super */
1486 static void ll_bdi_device_unregister(struct backing_dev_info *bdi)
1488 if (bdi->dev == NULL)
1491 #if defined(SB_I_CGROUPWB) && !defined(SB_I_PERSB_BDI)
1492 #ifdef HAVE_BDI_DEBUG_STATS
1493 debugfs_remove(bdi->debug_stats);
1494 debugfs_remove(bdi->debug_dir);
1496 debugfs_remove_recursive(bdi->debug_dir);
1498 device_unregister(bdi->dev);
1503 void ll_put_super(struct super_block *sb)
1505 struct config_llog_instance cfg, params_cfg;
1506 struct obd_device *obd;
1507 struct lustre_sb_info *lsi = s2lsi(sb);
1508 struct ll_sb_info *sbi = ll_s2sbi(sb);
1509 unsigned long dev_no = 0;
1510 char *profilenm = get_profile_name(sb);
1511 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1517 GOTO(out_no_sbi, 0);
1519 /* Should replace instance_id with something better for ASLR */
1520 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1521 profilenm, cfg_instance, sb);
1523 cfg.cfg_instance = cfg_instance;
1524 lustre_end_log(sb, profilenm, &cfg);
1526 params_cfg.cfg_instance = cfg_instance;
1527 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1529 if (sbi->ll_md_exp) {
1530 obd = class_exp2obd(sbi->ll_md_exp);
1532 force = obd->obd_force;
1535 /* We need to set force before the lov_disconnect in
1536 * lustre_common_put_super, since l_d cleans up osc's as well.
1540 obd_device_for_each_uuid(dev_no, obd, &sbi->ll_sb_uuid)
1541 obd->obd_force = force;
1542 obd_device_unlock();
1545 if (sbi->ll_client_common_fill_super_succeeded) {
1546 /* Only if client_common_fill_super succeeded */
1547 client_common_put_super(sb);
1550 /* imitate failed cleanup */
1551 if (CFS_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1555 * Cleanup, detach OBD devices, and remove them from Xarray.
1556 * We don't grab the xa_lock() since class_manual_cleanup()
1557 * uses the lock internally.
1559 obd_device_for_each_uuid(dev_no, obd, &sbi->ll_sb_uuid)
1560 class_manual_cleanup(obd);
1563 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1564 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1567 class_del_profile(profilenm);
1569 ll_bdi_device_unregister(sb->s_bdi);
1571 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1572 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1573 bdi_destroy(&lsi->lsi_bdi);
1574 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1578 llcrypt_free_dummy_policy(&lsi->lsi_dummy_enc_policy);
1580 lsi->lsi_llsbi = NULL;
1582 lustre_common_put_super(sb);
1584 cl_env_cache_purge(~0);
1587 } /* client_put_super */
1589 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1591 struct inode *inode = NULL;
1593 /* NOTE: we depend on atomic igrab() -bzzz */
1594 lock_res_and_lock(lock);
1595 if (lock->l_resource->lr_lvb_inode) {
1596 struct ll_inode_info * lli;
1597 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1598 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1599 inode = igrab(lock->l_resource->lr_lvb_inode);
1601 inode = lock->l_resource->lr_lvb_inode;
1602 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1603 D_WARNING, lock, "lr_lvb_inode %p is "
1604 "bogus: magic %08x",
1605 lock->l_resource->lr_lvb_inode,
1606 lli->lli_inode_magic);
1610 unlock_res_and_lock(lock);
1614 void ll_dir_clear_lsm_md(struct inode *inode)
1616 struct ll_inode_info *lli = ll_i2info(inode);
1618 LASSERT(S_ISDIR(inode->i_mode));
1619 down_write(&lli->lli_lsm_sem);
1620 lmv_stripe_object_put(&lli->lli_lsm_obj);
1621 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1622 up_write(&lli->lli_lsm_sem);
1625 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1626 const struct lu_fid *fid,
1627 struct lustre_md *md)
1629 struct ll_sb_info *sbi = ll_s2sbi(sb);
1630 struct ll_inode_info *lli;
1631 struct mdt_body *body = md->body;
1632 struct inode *inode;
1637 LASSERT(md->lsm_obj);
1638 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1639 inode = iget_locked(sb, ino);
1640 if (inode == NULL) {
1641 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1642 sbi->ll_fsname, PFID(fid));
1643 RETURN(ERR_PTR(-ENOENT));
1646 lli = ll_i2info(inode);
1647 if (inode->i_state & I_NEW) {
1648 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1649 (body->mbo_mode & S_IFMT);
1650 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1653 inode->i_mtime.tv_sec = 0;
1654 inode->i_atime.tv_sec = 0;
1655 inode->i_ctime.tv_sec = 0;
1658 #ifdef HAVE_BACKING_DEV_INFO
1659 /* initializing backing dev info. */
1660 inode->i_mapping->backing_dev_info =
1661 &s2lsi(inode->i_sb)->lsi_bdi;
1663 inode->i_op = &ll_dir_inode_operations;
1664 inode->i_fop = &ll_dir_operations;
1665 lli->lli_fid = *fid;
1668 /* master object FID */
1669 lli->lli_pfid = body->mbo_fid1;
1670 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1671 lli, PFID(fid), PFID(&lli->lli_pfid));
1672 unlock_new_inode(inode);
1674 /* in directory restripe/auto-split, a directory will be
1675 * transformed to a stripe if it's plain, set its pfid here,
1676 * otherwise ll_lock_cancel_bits() can't find the master inode.
1678 lli->lli_pfid = body->mbo_fid1;
1684 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1687 struct lmv_stripe_md *lsm;
1688 struct ll_inode_info *lli = ll_i2info(inode);
1691 LASSERT(md->lsm_obj != NULL);
1692 lsm = &md->lsm_obj->lso_lsm;
1694 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1695 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1696 lmv_stripe_object_dump(D_INODE, md->lsm_obj);
1698 if (!lmv_dir_striped(md->lsm_obj))
1701 /* XXX sigh, this lsm_root initialization should be in
1702 * LMV layer, but it needs ll_iget right now, so we
1703 * put this here right now. */
1704 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1705 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1706 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1708 if (!fid_is_sane(fid))
1711 /* Unfortunately ll_iget will call ll_update_inode,
1712 * where the initialization of slave inode is slightly
1713 * different, so it reset lsm_md to NULL to avoid
1714 * initializing lsm for slave inode. */
1715 lsm->lsm_md_oinfo[i].lmo_root =
1716 ll_iget_anon_dir(inode->i_sb, fid, md);
1717 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1718 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1720 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1722 iput(lsm->lsm_md_oinfo[i].lmo_root);
1723 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1729 /* move lsm_obj to lli */
1730 lli->lli_lsm_obj = md->lsm_obj;
1735 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1737 struct ll_inode_info *lli = ll_i2info(inode);
1738 struct lmv_stripe_object *lsm_obj = md->def_lsm_obj;
1742 /* clear default lsm */
1743 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set) {
1744 down_write(&lli->lli_lsm_sem);
1745 if (lli->lli_def_lsm_obj_set) {
1746 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1747 lli->lli_inherit_depth = 0;
1748 lli->lli_def_lsm_obj_set = 0;
1750 up_write(&lli->lli_lsm_sem);
1755 if (lli->lli_def_lsm_obj) {
1756 /* do nonthing if default lsm isn't changed */
1757 down_read(&lli->lli_lsm_sem);
1758 if (lli->lli_def_lsm_obj &&
1759 lsm_md_eq(lli->lli_def_lsm_obj, lsm_obj)) {
1760 up_read(&lli->lli_lsm_sem);
1763 up_read(&lli->lli_lsm_sem);
1765 down_write(&lli->lli_lsm_sem);
1767 /* update default lsm. */
1768 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1769 lli->lli_def_lsm_obj = lsm_obj;
1770 lli->lli_def_lsm_obj_set = 1;
1771 lmv_stripe_object_dump(D_INODE, lsm_obj);
1772 md->def_lsm_obj = NULL;
1773 up_write(&lli->lli_lsm_sem);
1777 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1779 struct ll_inode_info *lli = ll_i2info(inode);
1780 struct lmv_stripe_object *lsm_obj = md->lsm_obj;
1781 struct cl_attr *attr;
1786 LASSERT(S_ISDIR(inode->i_mode));
1787 CDEBUG(D_INODE, "update lsm_obj %p of "DFID"\n", lli->lli_lsm_obj,
1788 PFID(ll_inode2fid(inode)));
1790 /* update default LMV */
1791 if (md->def_lsm_obj)
1792 ll_update_default_lsm_md(inode, md);
1794 /* after dir migration/restripe, a stripe may be turned into a
1795 * directory, in this case, zero out its lli_pfid.
1797 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1798 fid_zero(&lli->lli_pfid);
1801 * no striped information from request, lustre_md from req does not
1802 * include stripeEA, see ll_md_setattr()
1808 * normally dir layout doesn't change, only take read lock to check
1809 * that to avoid blocking other MD operations.
1811 down_read(&lli->lli_lsm_sem);
1813 /* some current lookup initialized lsm, and unchanged */
1814 if (lli->lli_lsm_obj && lsm_md_eq(lli->lli_lsm_obj, lsm_obj)) {
1815 up_read(&lli->lli_lsm_sem);
1819 up_read(&lli->lli_lsm_sem);
1820 down_write(&lli->lli_lsm_sem);
1822 /* check again in case of a race */
1823 if (lli->lli_lsm_obj && lsm_md_eq(lli->lli_lsm_obj, lsm_obj))
1824 GOTO(unlock, rc = 0);
1826 /* if dir layout doesn't match, check whether version is increased,
1827 * which means layout is changed, this happens in dir split/merge and
1830 * foreign LMV should not change.
1832 if (lli->lli_lsm_obj && lmv_dir_striped(lli->lli_lsm_obj) &&
1833 lsm_obj->lso_lsm.lsm_md_layout_version <=
1834 lli->lli_lsm_obj->lso_lsm.lsm_md_layout_version) {
1835 CERROR("%s: "DFID" dir layout mismatch:\n",
1836 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1837 lmv_stripe_object_dump(D_ERROR, lli->lli_lsm_obj);
1838 lmv_stripe_object_dump(D_ERROR, lsm_obj);
1839 GOTO(unlock, rc = -EINVAL);
1842 /* clear existing lsm */
1843 lmv_stripe_object_put(&lli->lli_lsm_obj);
1845 rc = ll_init_lsm_md(inode, md);
1849 if (!lmv_dir_striped(lli->lli_lsm_obj))
1850 GOTO(unlock, rc = 0);
1852 lsm_obj = lmv_stripe_object_get(lli->lli_lsm_obj);
1853 up_write(&lli->lli_lsm_sem);
1855 OBD_ALLOC_PTR(attr);
1857 GOTO(err, rc = -ENOMEM);
1859 /* validate the lsm */
1860 rc = md_merge_attr(ll_i2mdexp(inode), lsm_obj, attr,
1861 ll_md_blocking_ast);
1863 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1864 md->body->mbo_nlink = attr->cat_nlink;
1865 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1866 md->body->mbo_size = attr->cat_size;
1867 if (md->body->mbo_valid & OBD_MD_FLATIME)
1868 md->body->mbo_atime = attr->cat_atime;
1869 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1870 md->body->mbo_ctime = attr->cat_ctime;
1871 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1872 md->body->mbo_mtime = attr->cat_mtime;
1878 lmv_stripe_object_put(&lsm_obj);
1881 up_write(&lli->lli_lsm_sem);
1885 void ll_clear_inode(struct inode *inode)
1887 struct ll_inode_info *lli = ll_i2info(inode);
1888 struct ll_sb_info *sbi = ll_i2sbi(inode);
1892 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1893 PFID(ll_inode2fid(inode)), inode);
1895 if (S_ISDIR(inode->i_mode)) {
1896 /* these should have been cleared in ll_file_release */
1897 LASSERT(lli->lli_opendir_key == NULL);
1898 LASSERT(lli->lli_sai == NULL);
1899 LASSERT(lli->lli_opendir_pid == 0);
1901 pcc_inode_free(inode);
1904 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1906 LASSERT(!lli->lli_open_fd_write_count);
1907 LASSERT(!lli->lli_open_fd_read_count);
1908 LASSERT(!lli->lli_open_fd_exec_count);
1910 if (lli->lli_mds_write_och)
1911 ll_md_real_close(inode, FMODE_WRITE);
1912 if (lli->lli_mds_exec_och)
1913 ll_md_real_close(inode, FMODE_EXEC);
1914 if (lli->lli_mds_read_och)
1915 ll_md_real_close(inode, FMODE_READ);
1917 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1918 OBD_FREE(lli->lli_symlink_name,
1919 strlen(lli->lli_symlink_name) + 1);
1920 lli->lli_symlink_name = NULL;
1923 ll_xattr_cache_destroy(inode);
1925 forget_all_cached_acls(inode);
1927 lli->lli_inode_magic = LLI_INODE_DEAD;
1929 if (S_ISDIR(inode->i_mode))
1930 ll_dir_clear_lsm_md(inode);
1931 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1932 LASSERT(list_empty(&lli->lli_agl_list));
1935 * XXX This has to be done before lsm is freed below, because
1936 * cl_object still uses inode lsm.
1938 cl_inode_fini(inode);
1940 llcrypt_put_encryption_info(inode);
1945 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1947 struct lustre_md md;
1948 struct inode *inode = dentry->d_inode;
1949 struct ll_sb_info *sbi = ll_i2sbi(inode);
1950 struct ptlrpc_request *request = NULL;
1955 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1956 LUSTRE_OPC_ANY, NULL);
1957 if (IS_ERR(op_data))
1958 RETURN(PTR_ERR(op_data));
1960 /* If this is a chgrp of a regular file, we want to reserve enough
1961 * quota to cover the entire file size.
1963 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1964 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1965 from_kgid(&init_user_ns, inode->i_gid)) {
1966 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1967 op_data->op_attr_blocks = inode->i_blocks;
1971 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1973 ptlrpc_req_finished(request);
1974 if (rc == -ENOENT) {
1976 /* Unlinked special device node? Or just a race?
1977 * Pretend we done everything. */
1978 if (!S_ISREG(inode->i_mode) &&
1979 !S_ISDIR(inode->i_mode)) {
1980 ia_valid = op_data->op_attr.ia_valid;
1981 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1982 rc = simple_setattr(&nop_mnt_idmap, dentry,
1984 op_data->op_attr.ia_valid = ia_valid;
1986 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1987 CERROR("md_setattr fails: rc = %d\n", rc);
1992 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1993 sbi->ll_md_exp, &md);
1995 ptlrpc_req_finished(request);
1999 ia_valid = op_data->op_attr.ia_valid;
2000 /* inode size will be in ll_setattr_ost, can't do it now since dirty
2001 * cache is not cleared yet. */
2002 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
2003 if (S_ISREG(inode->i_mode))
2004 ll_inode_lock(inode);
2005 rc = simple_setattr(&nop_mnt_idmap, dentry, &op_data->op_attr);
2006 if (S_ISREG(inode->i_mode))
2007 ll_inode_unlock(inode);
2008 op_data->op_attr.ia_valid = ia_valid;
2010 rc = ll_update_inode(inode, &md);
2011 ptlrpc_req_finished(request);
2012 md_put_lustre_md(sbi->ll_md_exp, &md);
2018 * Zero portion of page that is part of @inode.
2019 * This implies, if necessary:
2020 * - taking cl_lock on range corresponding to concerned page
2021 * - grabbing vm page
2022 * - associating cl_page
2023 * - proceeding to clio read
2024 * - zeroing range in page
2025 * - proceeding to cl_page flush
2026 * - releasing cl_lock
2028 * \param[in] inode inode
2029 * \param[in] index page index
2030 * \param[in] offset offset in page to start zero from
2031 * \param[in] len len to zero
2033 * \retval 0 on success
2034 * \retval negative errno on failure
2036 static int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
2039 struct ll_inode_info *lli = ll_i2info(inode);
2040 struct cl_object *clob = lli->lli_clob;
2042 struct lu_env *env = NULL;
2043 struct cl_io *io = NULL;
2044 struct cl_page *clpage = NULL;
2045 struct page *vmpage = NULL;
2046 unsigned from = index << PAGE_SHIFT;
2047 struct cl_lock *lock = NULL;
2048 struct cl_lock_descr *descr = NULL;
2049 struct cl_2queue *queue = NULL;
2050 struct cl_sync_io *anchor = NULL;
2051 bool holdinglock = false;
2056 env = cl_env_get(&refcheck);
2058 RETURN(PTR_ERR(env));
2060 io = vvp_env_thread_io(env);
2062 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2066 lock = vvp_env_lock(env);
2067 descr = &lock->cll_descr;
2068 descr->cld_obj = io->ci_obj;
2069 descr->cld_start = from >> PAGE_SHIFT;
2070 descr->cld_end = (from + PAGE_SIZE - 1) >> PAGE_SHIFT;
2071 descr->cld_mode = CLM_WRITE;
2072 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2074 /* request lock for page */
2075 rc = cl_lock_request(env, io, lock);
2076 /* -ECANCELED indicates a matching lock with a different extent
2077 * was already present, and -EEXIST indicates a matching lock
2078 * on exactly the same extent was already present.
2079 * In both cases it means we are covered.
2081 if (rc == -ECANCELED || rc == -EEXIST)
2089 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2091 GOTO(rellock, rc = -EOPNOTSUPP);
2093 if (!PageDirty(vmpage)) {
2094 /* associate cl_page */
2095 clpage = cl_page_find(env, clob, vmpage->index,
2096 vmpage, CPT_CACHEABLE);
2098 GOTO(pagefini, rc = PTR_ERR(clpage));
2100 cl_page_assume(env, io, clpage);
2103 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2104 !PageWriteback(vmpage)) {
2106 /* Set PagePrivate2 to detect special case of empty page
2107 * in osc_brw_fini_request().
2108 * It is also used to tell ll_io_read_page() that we do not
2109 * want the vmpage to be unlocked.
2111 SetPagePrivate2(vmpage);
2112 rc = ll_io_read_page(env, io, clpage, NULL);
2113 if (!PagePrivate2(vmpage)) {
2114 /* PagePrivate2 was cleared in osc_brw_fini_request()
2115 * meaning we read an empty page. In this case, in order
2116 * to avoid allocating unnecessary block in truncated
2117 * file, we must not zero and write as below. Subsequent
2118 * server-side truncate will handle things correctly.
2120 cl_page_unassume(env, io, clpage);
2121 GOTO(clpfini, rc = 0);
2123 ClearPagePrivate2(vmpage);
2128 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2129 * the vmpage, so we are good to proceed and zero range in page.
2131 zero_user(vmpage, offset, len);
2133 if (holdinglock && clpage) {
2134 /* explicitly write newly modified page */
2135 queue = &io->ci_queue;
2136 cl_2queue_init(queue);
2137 anchor = &vvp_env_info(env)->vti_anchor;
2138 cl_sync_io_init(anchor, 1);
2139 clpage->cp_sync_io = anchor;
2140 cl_page_list_add(&queue->c2_qin, clpage, true);
2141 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2143 GOTO(queuefini1, rc);
2144 rc = cl_sync_io_wait(env, anchor, 0);
2146 GOTO(queuefini2, rc);
2147 cl_page_assume(env, io, clpage);
2150 cl_2queue_discard(env, io, queue);
2152 cl_2queue_disown(env, queue);
2153 cl_2queue_fini(env, queue);
2158 cl_page_put(env, clpage);
2160 unlock_page(vmpage);
2164 cl_lock_release(env, lock);
2166 cl_io_fini(env, io);
2169 cl_env_put(env, &refcheck);
2175 * Get reference file from volatile file name.
2176 * Volatile file name may look like:
2177 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2178 * where fd is opened descriptor of reference file.
2180 * \param[in] volatile_name volatile file name
2181 * \param[in] volatile_len volatile file name length
2182 * \param[out] ref_file pointer to struct file of reference file
2184 * \retval 0 on success
2185 * \retval negative errno on failure
2187 int volatile_ref_file(const char *volatile_name, int volatile_len,
2188 struct file **ref_file)
2190 char *p, *q, *fd_str;
2193 p = strnstr(volatile_name, ":fd=", volatile_len);
2194 if (!p || strlen(p + 4) == 0)
2197 q = strchrnul(p + 4, ':');
2198 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2201 rc = kstrtouint(fd_str, 10, &fd);
2206 *ref_file = fget(fd);
2212 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2213 * object(s) determine the file size and mtime. Otherwise, the MDS will
2214 * keep these values until such a time that objects are allocated for it.
2215 * We do the MDS operations first, as it is checking permissions for us.
2216 * We don't to the MDS RPC if there is nothing that we want to store there,
2217 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2218 * going to do an RPC anyways.
2220 * If we are doing a truncate, we will send the mtime and ctime updates
2221 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2222 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2225 * In case of HSMimport, we only set attr on MDS.
2227 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2228 enum op_xvalid xvalid, bool hsm_import)
2230 struct inode *inode = dentry->d_inode;
2231 struct ll_inode_info *lli = ll_i2info(inode);
2232 struct md_op_data *op_data = NULL;
2233 ktime_t kstart = ktime_get();
2238 /* VFS has locked the inode before calling this */
2239 ll_set_inode_lock_owner(inode);
2241 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2242 "valid %x, hsm_import %d\n",
2243 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2244 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2247 if (attr->ia_valid & ATTR_SIZE) {
2248 /* Check new size against VFS/VM file size limit and rlimit */
2249 rc = inode_newsize_ok(inode, attr->ia_size);
2253 /* The maximum Lustre file size is variable, based on the
2254 * OST maximum object size and number of stripes. This
2255 * needs another check in addition to the VFS check above. */
2256 if (attr->ia_size > ll_file_maxbytes(inode)) {
2257 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2258 PFID(&lli->lli_fid), attr->ia_size,
2259 ll_file_maxbytes(inode));
2260 GOTO(clear, rc = -EFBIG);
2263 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2266 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2267 if (attr->ia_valid & TIMES_SET_FLAGS) {
2268 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2269 !capable(CAP_FOWNER))
2270 GOTO(clear, rc = -EPERM);
2273 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2274 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2275 (attr->ia_valid & ATTR_CTIME)) {
2276 attr->ia_ctime = current_time(inode);
2277 xvalid |= OP_XVALID_CTIME_SET;
2279 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2280 (attr->ia_valid & ATTR_ATIME)) {
2281 attr->ia_atime = current_time(inode);
2282 attr->ia_valid |= ATTR_ATIME_SET;
2284 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2285 (attr->ia_valid & ATTR_MTIME)) {
2286 attr->ia_mtime = current_time(inode);
2287 attr->ia_valid |= ATTR_MTIME_SET;
2290 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2291 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2292 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2293 ktime_get_real_seconds());
2295 if (S_ISREG(inode->i_mode))
2296 ll_inode_unlock(inode);
2298 /* We always do an MDS RPC, even if we're only changing the size;
2299 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2301 OBD_ALLOC_PTR(op_data);
2302 if (op_data == NULL)
2303 GOTO(out, rc = -ENOMEM);
2305 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2306 /* If we are changing file size, file content is
2307 * modified, flag it.
2309 xvalid |= OP_XVALID_OWNEROVERRIDE;
2310 op_data->op_bias |= MDS_DATA_MODIFIED;
2311 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2314 if (attr->ia_valid & ATTR_FILE) {
2315 struct ll_file_data *fd = attr->ia_file->private_data;
2317 if (fd->fd_lease_och)
2318 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2321 op_data->op_attr = *attr;
2322 op_data->op_xvalid = xvalid;
2324 rc = ll_md_setattr(dentry, op_data);
2327 lli->lli_synced_to_mds = false;
2329 if (!S_ISREG(inode->i_mode) || hsm_import)
2332 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2333 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2334 xvalid & OP_XVALID_CTIME_SET) {
2335 bool cached = false;
2337 rc = pcc_inode_setattr(inode, attr, &cached);
2340 CERROR("%s: PCC inode "DFID" setattr failed: "
2342 ll_i2sbi(inode)->ll_fsname,
2343 PFID(&lli->lli_fid), rc);
2347 unsigned int flags = 0;
2349 /* For truncate and utimes sending attributes to OSTs,
2350 * setting mtime/atime to the past will be performed
2351 * under PW [0:EOF] extent lock (new_size:EOF for
2352 * truncate). It may seem excessive to send mtime/atime
2353 * updates to OSTs when not setting times to past, but
2354 * it is necessary due to possible time
2355 * de-synchronization between MDT inode and OST objects
2357 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2358 xvalid |= OP_XVALID_FLAGS;
2359 flags = LUSTRE_ENCRYPT_FL;
2360 /* Call to ll_io_zero_page is not necessary if
2361 * truncating on PAGE_SIZE boundary, because
2362 * whole pages will be wiped.
2363 * In case of Direct IO, all we need is to set
2366 if (attr->ia_valid & ATTR_SIZE &&
2367 attr->ia_size & ~PAGE_MASK &&
2368 !(attr->ia_valid & ATTR_FILE &&
2369 attr->ia_file->f_flags & O_DIRECT)) {
2371 attr->ia_size & (PAGE_SIZE - 1);
2373 rc = ll_io_zero_page(inode,
2374 attr->ia_size >> PAGE_SHIFT,
2375 offset, PAGE_SIZE - offset);
2379 /* If encrypted volatile file without the key,
2380 * we need to fetch size from reference file,
2381 * and set it on OST objects. This happens when
2382 * migrating or extending an encrypted file
2385 if (filename_is_volatile(dentry->d_name.name,
2388 llcrypt_require_key(inode) == -ENOKEY) {
2389 struct file *ref_file;
2390 struct inode *ref_inode;
2391 struct ll_inode_info *ref_lli;
2392 struct cl_object *ref_obj;
2393 struct cl_attr ref_attr = { 0 };
2397 rc = volatile_ref_file(
2398 dentry->d_name.name,
2404 ref_inode = file_inode(ref_file);
2407 GOTO(out, rc = -EINVAL);
2410 env = cl_env_get(&refcheck);
2412 GOTO(out, rc = PTR_ERR(env));
2414 ref_lli = ll_i2info(ref_inode);
2415 ref_obj = ref_lli->lli_clob;
2416 cl_object_attr_lock(ref_obj);
2417 rc = cl_object_attr_get(env, ref_obj,
2419 cl_object_attr_unlock(ref_obj);
2420 cl_env_put(env, &refcheck);
2425 attr->ia_valid |= ATTR_SIZE;
2426 attr->ia_size = ref_attr.cat_size;
2429 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2433 /* If the file was restored, it needs to set dirty flag.
2435 * We've already sent MDS_DATA_MODIFIED flag in
2436 * ll_md_setattr() for truncate. However, the MDT refuses to
2437 * set the HS_DIRTY flag on released files, so we have to set
2438 * it again if the file has been restored. Please check how
2439 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2441 * Please notice that if the file is not released, the previous
2442 * MDS_DATA_MODIFIED has taken effect and usually
2443 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2444 * This way we can save an RPC for common open + trunc
2446 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2447 struct hsm_state_set hss = {
2448 .hss_valid = HSS_SETMASK,
2449 .hss_setmask = HS_DIRTY,
2453 rc2 = ll_hsm_state_set(inode, &hss);
2454 /* truncate and write can happen at the same time, so that
2455 * the file can be set modified even though the file is not
2456 * restored from released state, and ll_hsm_state_set() is
2457 * not applicable for the file, and rc2 < 0 is normal in this
2460 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2461 PFID(ll_inode2fid(inode)), rc2);
2466 if (op_data != NULL)
2467 ll_finish_md_op_data(op_data);
2469 if (S_ISREG(inode->i_mode)) {
2470 ll_inode_lock(inode);
2471 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2472 inode_dio_wait(inode);
2473 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2474 * flag. ll_update_inode (called from ll_md_setattr), clears
2475 * inode flags, so there is a gap where S_NOSEC is not set.
2476 * This can cause a writer to take the i_mutex unnecessarily,
2477 * but this is safe to do and should be rare. */
2478 inode_has_no_xattr(inode);
2482 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2483 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2484 ktime_us_delta(ktime_get(), kstart));
2486 ll_clear_inode_lock_owner(inode);
2491 int ll_setattr(struct mnt_idmap *map, struct dentry *de, struct iattr *attr)
2493 int mode = de->d_inode->i_mode;
2494 enum op_xvalid xvalid = 0;
2497 rc = llcrypt_prepare_setattr(de, attr);
2501 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2502 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2503 xvalid |= OP_XVALID_OWNEROVERRIDE;
2505 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2506 (ATTR_SIZE|ATTR_MODE)) &&
2507 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2508 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2509 !(attr->ia_mode & S_ISGID))))
2510 attr->ia_valid |= ATTR_FORCE;
2512 if ((attr->ia_valid & ATTR_MODE) &&
2514 !(attr->ia_mode & S_ISUID) &&
2515 !(attr->ia_valid & ATTR_KILL_SUID))
2516 attr->ia_valid |= ATTR_KILL_SUID;
2518 if ((attr->ia_valid & ATTR_MODE) &&
2519 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2520 !(attr->ia_mode & S_ISGID) &&
2521 !(attr->ia_valid & ATTR_KILL_SGID))
2522 attr->ia_valid |= ATTR_KILL_SGID;
2524 return ll_setattr_raw(de, attr, xvalid, false);
2527 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2530 struct obd_statfs obd_osfs = { 0 };
2535 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2537 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2538 flags |= OBD_STATFS_NODELAY;
2540 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2544 osfs->os_type = LL_SUPER_MAGIC;
2546 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2547 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2549 if (osfs->os_state & OS_STATFS_SUM)
2552 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2553 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2556 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2557 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2560 osfs->os_bsize = obd_osfs.os_bsize;
2561 osfs->os_blocks = obd_osfs.os_blocks;
2562 osfs->os_bfree = obd_osfs.os_bfree;
2563 osfs->os_bavail = obd_osfs.os_bavail;
2565 /* If we have _some_ OSTs, but don't have as many free objects on the
2566 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2567 * to compensate, so that the "inodes in use" number is correct.
2568 * This should be kept in sync with lod_statfs() behaviour.
2570 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2571 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2573 osfs->os_ffree = obd_osfs.os_ffree;
2580 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2582 struct if_quotactl qctl = {
2583 .qc_cmd = LUSTRE_Q_GETQUOTA,
2584 .qc_type = PRJQUOTA,
2585 .qc_valid = QC_GENERAL,
2587 u64 limit, curblock;
2590 qctl.qc_id = ll_i2info(inode)->lli_projid;
2591 ret = quotactl_ioctl(inode->i_sb, &qctl);
2593 /* ignore errors if project ID does not have
2594 * a quota limit or feature unsupported.
2596 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2601 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2602 qctl.qc_dqblk.dqb_bsoftlimit :
2603 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2604 if (limit && sfs->f_blocks > limit) {
2605 curblock = (qctl.qc_dqblk.dqb_curspace +
2606 sfs->f_bsize - 1) / sfs->f_bsize;
2607 sfs->f_blocks = limit;
2608 sfs->f_bfree = sfs->f_bavail =
2609 (sfs->f_blocks > curblock) ?
2610 (sfs->f_blocks - curblock) : 0;
2613 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2614 qctl.qc_dqblk.dqb_isoftlimit :
2615 qctl.qc_dqblk.dqb_ihardlimit;
2616 if (limit && sfs->f_files > limit) {
2617 sfs->f_files = limit;
2618 sfs->f_ffree = (sfs->f_files >
2619 qctl.qc_dqblk.dqb_curinodes) ?
2620 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2626 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2628 struct super_block *sb = de->d_sb;
2629 struct obd_statfs osfs;
2630 __u64 fsid = huge_encode_dev(sb->s_dev);
2631 ktime_t kstart = ktime_get();
2634 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2636 /* Some amount of caching on the client is allowed */
2637 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2641 statfs_unpack(sfs, &osfs);
2643 /* We need to downshift for all 32-bit kernels, because we can't
2644 * tell if the kernel is being called via sys_statfs64() or not.
2645 * Stop before overflowing f_bsize - in which case it is better
2646 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2647 if (sizeof(long) < 8) {
2648 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2651 osfs.os_blocks >>= 1;
2652 osfs.os_bfree >>= 1;
2653 osfs.os_bavail >>= 1;
2657 sfs->f_blocks = osfs.os_blocks;
2658 sfs->f_bfree = osfs.os_bfree;
2659 sfs->f_bavail = osfs.os_bavail;
2660 sfs->f_fsid.val[0] = (__u32)fsid;
2661 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2662 if (ll_i2info(de->d_inode)->lli_projid &&
2663 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2664 return ll_statfs_project(de->d_inode, sfs);
2666 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2667 ktime_us_delta(ktime_get(), kstart));
2672 void ll_inode_size_lock(struct inode *inode)
2674 struct ll_inode_info *lli;
2676 LASSERT(!S_ISDIR(inode->i_mode));
2678 lli = ll_i2info(inode);
2679 mutex_lock(&lli->lli_size_mutex);
2680 lli->lli_size_lock_owner = current;
2683 void ll_inode_size_unlock(struct inode *inode)
2685 struct ll_inode_info *lli;
2687 lli = ll_i2info(inode);
2688 lli->lli_size_lock_owner = NULL;
2689 mutex_unlock(&lli->lli_size_mutex);
2692 int ll_inode_size_trylock(struct inode *inode)
2694 struct ll_inode_info *lli;
2696 LASSERT(!S_ISDIR(inode->i_mode));
2698 lli = ll_i2info(inode);
2699 return mutex_trylock(&lli->lli_size_mutex);
2702 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2704 /* do not clear encryption flag */
2705 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2706 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2707 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2708 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2710 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2713 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2715 struct ll_inode_info *lli = ll_i2info(inode);
2716 struct mdt_body *body = md->body;
2717 struct ll_sb_info *sbi = ll_i2sbi(inode);
2721 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2722 rc = cl_file_inode_init(inode, md);
2727 if (S_ISDIR(inode->i_mode)) {
2728 rc = ll_update_lsm_md(inode, md);
2733 if (body->mbo_valid & OBD_MD_FLACL)
2734 lli_replace_acl(lli, md);
2736 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2737 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2738 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2740 if (body->mbo_valid & OBD_MD_FLATIME) {
2741 if (body->mbo_atime > inode->i_atime.tv_sec)
2742 inode->i_atime.tv_sec = body->mbo_atime;
2743 lli->lli_atime = body->mbo_atime;
2746 if (body->mbo_valid & OBD_MD_FLMTIME) {
2747 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2749 "setting ino %lu mtime from %lld to %llu\n",
2750 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2752 inode->i_mtime.tv_sec = body->mbo_mtime;
2754 lli->lli_mtime = body->mbo_mtime;
2757 if (body->mbo_valid & OBD_MD_FLCTIME) {
2758 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2759 inode->i_ctime.tv_sec = body->mbo_ctime;
2760 lli->lli_ctime = body->mbo_ctime;
2763 if (body->mbo_valid & OBD_MD_FLBTIME)
2764 lli->lli_btime = body->mbo_btime;
2766 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2767 if (body->mbo_valid & OBD_MD_FLFLAGS)
2768 ll_update_inode_flags(inode, body->mbo_flags);
2769 if (body->mbo_valid & OBD_MD_FLMODE)
2770 inode->i_mode = (inode->i_mode & S_IFMT) |
2771 (body->mbo_mode & ~S_IFMT);
2773 if (body->mbo_valid & OBD_MD_FLTYPE)
2774 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2775 (body->mbo_mode & S_IFMT);
2777 LASSERT(inode->i_mode != 0);
2778 if (body->mbo_valid & OBD_MD_FLUID)
2779 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2780 if (body->mbo_valid & OBD_MD_FLGID)
2781 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2782 if (body->mbo_valid & OBD_MD_FLPROJID)
2783 lli->lli_projid = body->mbo_projid;
2784 if (body->mbo_valid & OBD_MD_FLNLINK) {
2785 spin_lock(&inode->i_lock);
2786 set_nlink(inode, body->mbo_nlink);
2787 spin_unlock(&inode->i_lock);
2789 if (body->mbo_valid & OBD_MD_FLRDEV)
2790 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2792 if (body->mbo_valid & OBD_MD_FLID) {
2793 /* FID shouldn't be changed! */
2794 if (fid_is_sane(&lli->lli_fid)) {
2795 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2796 "Trying to change FID "DFID
2797 " to the "DFID", inode "DFID"(%p)\n",
2798 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2799 PFID(ll_inode2fid(inode)), inode);
2801 lli->lli_fid = body->mbo_fid1;
2805 LASSERT(fid_seq(&lli->lli_fid) != 0);
2807 /* In case of encrypted file without the key, please do not lose
2808 * clear text size stored into lli_lazysize in ll_merge_attr(),
2809 * we will need it in ll_prepare_close().
2811 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2812 llcrypt_require_key(inode) == -ENOKEY)
2813 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2815 lli->lli_attr_valid = body->mbo_valid;
2816 if (body->mbo_valid & OBD_MD_FLSIZE) {
2817 i_size_write(inode, body->mbo_size);
2819 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2820 PFID(ll_inode2fid(inode)),
2821 (unsigned long long)body->mbo_size);
2823 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2824 inode->i_blocks = body->mbo_blocks;
2826 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2827 lli->lli_lazysize = body->mbo_size;
2828 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2829 lli->lli_lazyblocks = body->mbo_blocks;
2832 if (body->mbo_valid & OBD_MD_TSTATE) {
2833 /* Set LLIF_FILE_RESTORING if restore ongoing and
2834 * clear it when done to ensure to start again
2835 * glimpsing updated attrs
2837 if (body->mbo_t_state & MS_RESTORE)
2838 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2840 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2846 /* child default LMV is inherited from parent */
2847 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2848 struct lmv_stripe_md *cdmv)
2853 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2854 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2855 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2856 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2859 if (cdmv->lsm_md_max_inherit !=
2860 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2863 if (cdmv->lsm_md_max_inherit_rr !=
2864 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2870 /* if default LMV is implicitly inherited, subdir default LMV is maintained on
2873 static int ll_dir_default_lmv_inherit(struct inode *dir, struct inode *inode)
2875 struct ll_inode_info *plli = ll_i2info(dir);
2876 struct ll_inode_info *lli = ll_i2info(inode);
2877 struct lmv_stripe_object *plsm_obj;
2878 struct lmv_stripe_object *lsm_obj;
2883 /* ROOT default LMV is not inherited */
2884 if (is_root_inode(dir) ||
2885 !(exp_connect_flags2(ll_i2mdexp(dir)) &
2886 OBD_CONNECT2_DMV_IMP_INHERIT))
2889 /* nothing to do if no default LMV on both */
2890 if (!plli->lli_def_lsm_obj && !lli->lli_def_lsm_obj)
2893 /* subdir default LMV comes from disk */
2894 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set)
2897 /* delete subdir default LMV if parent's is deleted or becomes
2900 down_read(&plli->lli_lsm_sem);
2901 plsm_obj = plli->lli_def_lsm_obj;
2903 !lmv_is_inheritable(plsm_obj->lso_lsm.lsm_md_max_inherit)) {
2904 if (lli->lli_def_lsm_obj && !lli->lli_def_lsm_obj_set) {
2905 down_write(&lli->lli_lsm_sem);
2906 if (!lli->lli_def_lsm_obj_set) {
2907 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
2908 lli->lli_inherit_depth = 0;
2910 up_write(&lli->lli_lsm_sem);
2912 GOTO(unlock_parent, rc = 0);
2915 /* do nothing if inherited LMV is unchanged */
2916 if (lli->lli_def_lsm_obj) {
2918 down_read(&lli->lli_lsm_sem);
2919 if (!lli->lli_def_lsm_obj_set)
2920 rc = lmv_object_inherited(plsm_obj,
2921 lli->lli_def_lsm_obj);
2922 up_read(&lli->lli_lsm_sem);
2924 GOTO(unlock_parent, rc = 0);
2927 /* inherit default LMV */
2928 down_write(&lli->lli_lsm_sem);
2929 if (lli->lli_def_lsm_obj) {
2930 /* checked above, but in case of race, check again with lock */
2931 if (lli->lli_def_lsm_obj_set)
2932 GOTO(unlock_child, rc = 0);
2933 /* always update subdir default LMV in case parent's changed */
2934 lsm_obj = lli->lli_def_lsm_obj;
2936 lsm_obj = lmv_stripe_object_alloc(LMV_USER_MAGIC, NULL, 0);
2937 if (IS_ERR(lsm_obj))
2938 GOTO(unlock_child, rc = PTR_ERR(lsm_obj));
2939 lli->lli_def_lsm_obj = lsm_obj;
2942 lsm_obj->lso_lsm = plsm_obj->lso_lsm;
2943 lsm_obj->lso_lsm.lsm_md_max_inherit =
2944 lmv_inherit_next(plsm_obj->lso_lsm.lsm_md_max_inherit);
2945 lsm_obj->lso_lsm.lsm_md_max_inherit_rr =
2946 lmv_inherit_rr_next(plsm_obj->lso_lsm.lsm_md_max_inherit_rr);
2947 lli->lli_inherit_depth = plli->lli_inherit_depth + 1;
2949 lmv_stripe_object_dump(D_INODE, lsm_obj);
2953 up_write(&lli->lli_lsm_sem);
2955 up_read(&plli->lli_lsm_sem);
2960 enum lsm_sem_class {
2966 * Update directory depth and default LMV
2968 * Update directory depth to ROOT and inherit default LMV from parent if
2969 * parent's default LMV is inheritable. The default LMV set with command
2970 * "lfs setdirstripe -D ..." is stored on MDT, while the inherited default LMV
2971 * is generated at runtime on client side.
2973 * \param[in] dir parent directory inode
2974 * \param[in] de dentry
2976 void ll_update_dir_depth_dmv(struct inode *dir, struct dentry *de)
2978 struct inode *inode = de->d_inode;
2979 struct ll_inode_info *plli;
2980 struct ll_inode_info *lli;
2982 LASSERT(S_ISDIR(inode->i_mode));
2986 plli = ll_i2info(dir);
2987 lli = ll_i2info(inode);
2988 lli->lli_dir_depth = plli->lli_dir_depth + 1;
2989 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set) {
2990 if (plli->lli_def_lsm_obj) {
2991 down_read_nested(&plli->lli_lsm_sem, LSM_SEM_PARENT);
2992 down_read_nested(&lli->lli_lsm_sem, LSM_SEM_CHILD);
2993 if (lmv_object_inherited(plli->lli_def_lsm_obj,
2994 lli->lli_def_lsm_obj))
2995 lli->lli_inherit_depth =
2996 plli->lli_inherit_depth + 1;
2998 /* in case parent default LMV changed */
2999 lli->lli_inherit_depth = 0;
3000 up_read(&lli->lli_lsm_sem);
3001 up_read(&plli->lli_lsm_sem);
3003 /* in case parent default LMV deleted */
3004 lli->lli_inherit_depth = 0;
3007 ll_dir_default_lmv_inherit(dir, inode);
3010 if (lli->lli_def_lsm_obj)
3012 "%s "DFID" depth %hu %s default LMV inherit depth %hu\n",
3013 de->d_name.name, PFID(&lli->lli_fid), lli->lli_dir_depth,
3014 lli->lli_def_lsm_obj_set ? "server" : "client",
3015 lli->lli_inherit_depth);
3018 void ll_truncate_inode_pages_final(struct inode *inode)
3020 struct address_space *mapping = &inode->i_data;
3021 unsigned long nrpages;
3022 unsigned long flags;
3024 LASSERTF((inode->i_state & I_FREEING) || inode_is_locked(inode),
3025 DFID ":inode %p state %#lx, lli_flags %#lx\n",
3026 PFID(ll_inode2fid(inode)), inode, inode->i_state,
3027 ll_i2info(inode)->lli_flags);
3029 truncate_inode_pages_final(mapping);
3031 /* Workaround for LU-118: Note nrpages may not be totally updated when
3032 * truncate_inode_pages() returns, as there can be a page in the process
3033 * of deletion (inside __delete_from_page_cache()) in the specified
3034 * range. Thus mapping->nrpages can be non-zero when this function
3035 * returns even after truncation of the whole mapping. Only do this if
3036 * npages isn't already zero.
3038 nrpages = mapping->nrpages;
3040 ll_xa_lock_irqsave(&mapping->i_pages, flags);
3041 nrpages = mapping->nrpages;
3042 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
3043 } /* Workaround end */
3045 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu "
3046 "state %#lx, lli_flags %#lx, "
3047 "see https://jira.whamcloud.com/browse/LU-118\n",
3048 ll_i2sbi(inode)->ll_fsname,
3049 PFID(ll_inode2fid(inode)), inode, nrpages,
3050 inode->i_state, ll_i2info(inode)->lli_flags);
3053 int ll_read_inode2(struct inode *inode, void *opaque)
3055 struct lustre_md *md = opaque;
3056 struct ll_inode_info *lli = ll_i2info(inode);
3060 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
3061 PFID(&lli->lli_fid), inode);
3063 /* Core attributes from the MDS first. This is a new inode, and
3064 * the VFS doesn't zero times in the core inode so we have to do
3065 * it ourselves. They will be overwritten by either MDS or OST
3066 * attributes - we just need to make sure they aren't newer.
3068 inode->i_mtime.tv_sec = 0;
3069 inode->i_atime.tv_sec = 0;
3070 inode->i_ctime.tv_sec = 0;
3072 rc = ll_update_inode(inode, md);
3076 /* OIDEBUG(inode); */
3078 #ifdef HAVE_BACKING_DEV_INFO
3079 /* initializing backing dev info. */
3080 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
3082 if (S_ISREG(inode->i_mode)) {
3083 struct ll_sb_info *sbi = ll_i2sbi(inode);
3084 inode->i_op = &ll_file_inode_operations;
3085 inode->i_fop = sbi->ll_fop;
3086 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
3088 } else if (S_ISDIR(inode->i_mode)) {
3089 inode->i_op = &ll_dir_inode_operations;
3090 inode->i_fop = &ll_dir_operations;
3092 } else if (S_ISLNK(inode->i_mode)) {
3093 inode->i_op = &ll_fast_symlink_inode_operations;
3096 inode->i_op = &ll_special_inode_operations;
3098 init_special_inode(inode, inode->i_mode,
3107 void ll_delete_inode(struct inode *inode)
3109 struct ll_inode_info *lli = ll_i2info(inode);
3112 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
3113 /* It is last chance to write out dirty pages,
3114 * otherwise we may lose data while umount.
3116 * If i_nlink is 0 then just discard data. This is safe because
3117 * local inode gets i_nlink 0 from server only for the last
3118 * unlink, so that file is not opened somewhere else
3120 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
3121 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
3124 ll_truncate_inode_pages_final(inode);
3125 ll_clear_inode(inode);
3131 static int fileattr_get(struct inode *inode, int *flags,
3135 struct ll_sb_info *sbi = ll_i2sbi(inode);
3136 struct ptlrpc_request *req = NULL;
3137 struct md_op_data *op_data;
3138 struct mdt_body *body;
3142 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
3143 0, 0, LUSTRE_OPC_ANY,
3145 if (IS_ERR(op_data))
3146 RETURN(PTR_ERR(op_data));
3148 op_data->op_valid = OBD_MD_FLFLAGS;
3149 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
3150 ll_finish_md_op_data(op_data);
3152 CERROR("%s: failure inode "DFID": rc = %d\n",
3153 sbi->ll_md_exp->exp_obd->obd_name,
3154 PFID(ll_inode2fid(inode)), rc);
3158 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3160 *flags = body->mbo_flags;
3161 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
3162 * ext4 equivalent to please lsattr and other e2fsprogs tools
3164 if (*flags & LUSTRE_ENCRYPT_FL)
3165 *flags |= STATX_ATTR_ENCRYPTED;
3167 ptlrpc_req_finished(req);
3169 *xflags = ll_inode_flags_to_xflags(inode->i_flags);
3170 if (test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags))
3171 *xflags |= FS_XFLAG_PROJINHERIT;
3172 *projid = ll_i2info(inode)->lli_projid;
3177 static int fileattr_set(struct inode *inode, int flags)
3179 struct ll_sb_info *sbi = ll_i2sbi(inode);
3180 struct ptlrpc_request *req = NULL;
3181 struct md_op_data *op_data;
3182 struct cl_object *obj;
3183 struct fsxattr fa = { 0 };
3188 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3189 if (flags & LUSTRE_PROJINHERIT_FL)
3190 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3192 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3197 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3198 LUSTRE_OPC_ANY, NULL);
3199 if (IS_ERR(op_data))
3200 RETURN(PTR_ERR(op_data));
3202 op_data->op_attr_flags = flags;
3203 op_data->op_xvalid |= OP_XVALID_FLAGS;
3204 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3205 ll_finish_md_op_data(op_data);
3206 ptlrpc_req_finished(req);
3210 ll_update_inode_flags(inode, flags);
3212 obj = ll_i2info(inode)->lli_clob;
3216 OBD_ALLOC_PTR(attr);
3220 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3226 #ifdef HAVE_FILEATTR_GET
3227 int ll_fileattr_get(struct dentry *dentry, struct fileattr *fa)
3229 return fileattr_get(d_inode(dentry), &fa->flags,
3230 &fa->fsx_xflags, &fa->fsx_projid);
3233 int ll_fileattr_set(struct mnt_idmap *mnt_userns,
3234 struct dentry *dentry, struct fileattr *fa)
3237 return ll_set_project(d_inode(dentry), fa->fsx_xflags,
3240 return fileattr_set(d_inode(dentry), fa->flags);
3242 #endif /* HAVE_FILEATTR_GET */
3244 /* ioctl commands shared between files and directories */
3245 int ll_iocontrol(struct inode *inode, struct file *file,
3246 unsigned int cmd, void __user *uarg)
3253 RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
3254 case LL_IOC_GETVERSION:
3255 case FS_IOC_GETVERSION:
3256 RETURN(put_user(inode->i_generation, (int __user *)uarg));
3258 #ifndef HAVE_FILEATTR_GET
3259 case FS_IOC_GETFLAGS: {
3260 u32 xflags = 0, projid = 0;
3263 if (!ll_access_ok(uarg, sizeof(int)))
3265 rc = fileattr_get(file->f_inode, &flags, &xflags, &projid);
3269 RETURN(put_user(flags, (int __user *)uarg));
3271 case FS_IOC_SETFLAGS: {
3274 if (get_user(flags, (int __user *)uarg))
3277 RETURN(fileattr_set(file->f_inode, flags));
3279 case FS_IOC_FSGETXATTR:
3280 RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
3281 case FS_IOC_FSSETXATTR:
3282 RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
3283 #endif /* HAVE_FILEATTR_GET */
3284 case LL_IOC_PROJECT:
3285 RETURN(ll_ioctl_project(file, cmd, uarg));
3286 case IOC_OBD_STATFS:
3287 RETURN(ll_obd_statfs(inode, uarg));
3288 case LL_IOC_GET_MDTIDX: {
3289 if (!ll_access_ok(uarg, sizeof(rc)))
3292 rc = ll_get_mdt_idx(inode);
3296 if (put_user(rc, (int __user *)uarg))
3301 case LL_IOC_FLUSHCTX:
3302 RETURN(ll_flush_ctx(inode));
3303 #ifdef HAVE_LUSTRE_CRYPTO
3304 case LL_IOC_ADD_ENCRYPTION_KEY:
3305 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3307 rc = llcrypt_ioctl_add_key(file, uarg);
3308 #ifdef CONFIG_LL_ENCRYPTION
3309 if (!rc && S_ISDIR(inode->i_mode))
3310 sptlrpc_enc_pool_add_user();
3313 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
3314 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3316 RETURN(llcrypt_ioctl_get_key_status(file, uarg));
3317 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
3318 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3320 RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
3321 case LL_IOC_SET_ENCRYPTION_POLICY:
3322 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3324 RETURN(llcrypt_ioctl_set_policy(file, uarg));
3325 case LL_IOC_REMOVE_ENCRYPTION_KEY:
3326 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3328 RETURN(llcrypt_ioctl_remove_key(file, uarg));
3329 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
3330 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3332 RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
3334 case LL_IOC_GETPARENT:
3335 RETURN(ll_getparent(file, uarg));
3336 case LL_IOC_PATH2FID:
3337 if (copy_to_user(uarg, ll_inode2fid(inode),
3338 sizeof(struct lu_fid)))
3341 case LL_IOC_UNLOCK_FOREIGN: {
3342 struct dentry *dentry = file_dentry(file);
3344 /* if not a foreign symlink do nothing */
3345 if (ll_foreign_is_removable(dentry, true)) {
3347 "prevent unlink of non-foreign file ("DFID")\n",
3348 PFID(ll_inode2fid(inode)));
3349 RETURN(-EOPNOTSUPP);
3353 case OBD_IOC_FID2PATH:
3354 RETURN(ll_fid2path(inode, uarg));
3355 #ifdef OBD_IOC_GETNAME_OLD
3356 case_OBD_IOC_DEPRECATED_FT(OBD_IOC_GETNAME_OLD,
3357 ll_i2sbi(inode)->ll_md_exp->exp_obd->obd_name,
3360 case OBD_IOC_GETDTNAME:
3361 case OBD_IOC_GETMDNAME:
3362 RETURN(ll_get_obd_name(inode, cmd, uarg));
3370 int ll_flush_ctx(struct inode *inode)
3372 struct ll_sb_info *sbi = ll_i2sbi(inode);
3374 CDEBUG(D_SEC, "flush context for user %d\n",
3375 from_kuid(&init_user_ns, current_uid()));
3377 obd_set_info_async(NULL, sbi->ll_md_exp,
3378 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3380 obd_set_info_async(NULL, sbi->ll_dt_exp,
3381 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3386 /* umount -f client means force down, don't save state */
3387 void ll_umount_begin(struct super_block *sb)
3389 struct ll_sb_info *sbi = ll_s2sbi(sb);
3390 struct obd_device *obd;
3391 struct obd_ioctl_data *ioc_data;
3395 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3396 sb->s_count, atomic_read(&sb->s_active));
3398 obd = class_exp2obd(sbi->ll_md_exp);
3400 CERROR("Invalid MDC connection handle %#llx\n",
3401 sbi->ll_md_exp->exp_handle.h_cookie);
3407 obd = class_exp2obd(sbi->ll_dt_exp);
3409 CERROR("Invalid LOV connection handle %#llx\n",
3410 sbi->ll_dt_exp->exp_handle.h_cookie);
3416 OBD_ALLOC_PTR(ioc_data);
3418 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_md_exp,
3419 sizeof *ioc_data, ioc_data, NULL);
3421 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_dt_exp,
3422 sizeof *ioc_data, ioc_data, NULL);
3424 OBD_FREE_PTR(ioc_data);
3427 /* Really, we'd like to wait until there are no requests outstanding,
3428 * and then continue. For now, we just periodically checking for vfs
3429 * to decrement mnt_cnt and hope to finish it within 10sec.
3433 !may_umount(sbi->ll_mnt.mnt)) {
3441 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3443 struct ll_sb_info *sbi = ll_s2sbi(sb);
3444 char *profilenm = get_profile_name(sb);
3448 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3449 read_only = *flags & MS_RDONLY;
3450 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3451 sizeof(KEY_READ_ONLY),
3452 KEY_READ_ONLY, sizeof(read_only),
3455 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3456 profilenm, read_only ?
3457 "read-only" : "read-write", err);
3462 sb->s_flags |= SB_RDONLY;
3464 sb->s_flags &= ~SB_RDONLY;
3466 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3467 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3468 read_only ? "read-only" : "read-write");
3474 * Cleanup the open handle that is cached on MDT-side.
3476 * For open case, the client side open handling thread may hit error
3477 * after the MDT grant the open. Under such case, the client should
3478 * send close RPC to the MDT as cleanup; otherwise, the open handle
3479 * on the MDT will be leaked there until the client umount or evicted.
3481 * In further, if someone unlinked the file, because the open handle
3482 * holds the reference on such file/object, then it will block the
3483 * subsequent threads that want to locate such object via FID.
3485 * \param[in] sb super block for this file-system
3486 * \param[in] open_req pointer to the original open request
3488 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3490 struct mdt_body *body;
3491 struct md_op_data *op_data;
3492 struct ptlrpc_request *close_req = NULL;
3493 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3496 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3497 OBD_ALLOC_PTR(op_data);
3498 if (op_data == NULL) {
3499 CWARN("%s: cannot allocate op_data to release open handle for "
3500 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3505 op_data->op_fid1 = body->mbo_fid1;
3506 op_data->op_open_handle = body->mbo_open_handle;
3507 op_data->op_mod_time = ktime_get_real_seconds();
3508 md_close(exp, op_data, NULL, &close_req);
3509 ptlrpc_req_finished(close_req);
3510 ll_finish_md_op_data(op_data);
3515 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3516 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3517 struct lustre_md *md)
3519 struct ll_sb_info *sbi = ll_i2sbi(inode);
3520 struct ptlrpc_request *req = NULL;
3521 union lmv_mds_md *lmm = NULL;
3525 LASSERT(is_root_inode(inode));
3526 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3527 LASSERT(!md->def_lsm_obj);
3529 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3531 GET_DEFAULT_LAYOUT_ROOT);
3532 if (rc && rc != -ENODATA)
3537 rc = md_stripe_object_create(sbi->ll_md_exp, &md->def_lsm_obj,
3547 ptlrpc_req_finished(req);
3551 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3552 struct super_block *sb, struct lookup_intent *it)
3554 struct ll_sb_info *sbi = NULL;
3555 struct lustre_md md = { NULL };
3556 bool default_lmv_deleted = false;
3561 LASSERT(*inode || sb);
3562 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3563 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3564 sbi->ll_md_exp, &md);
3569 * clear default_lmv only if intent_getattr reply doesn't contain it.
3570 * but it needs to be done after iget, check this early because
3571 * ll_update_lsm_md() may change md.
3573 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3574 S_ISDIR(md.body->mbo_mode) && !md.def_lsm_obj) {
3575 if (unlikely(*inode && is_root_inode(*inode) &&
3576 !fid_is_root(&sbi->ll_root_fid))) {
3577 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3582 if (!md.def_lsm_obj)
3583 default_lmv_deleted = true;
3587 rc = ll_update_inode(*inode, &md);
3591 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3592 struct lu_fid *fid1 = &md.body->mbo_fid1;
3594 LASSERT(sb != NULL);
3597 * At this point server returns to client's same fid as client
3598 * generated for creating. So using ->fid1 is okay here.
3600 if (!fid_is_sane(fid1)) {
3601 CERROR("%s: Fid is insane "DFID"\n",
3602 sbi->ll_fsname, PFID(fid1));
3603 GOTO(out, rc = -EINVAL);
3606 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3607 if (IS_ERR(*inode)) {
3609 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3611 CERROR("new_inode -fatal: rc %d\n", rc);
3616 /* Handling piggyback layout lock.
3617 * Layout lock can be piggybacked by getattr and open request.
3618 * The lsm can be applied to inode only if it comes with a layout lock
3619 * otherwise correct layout may be overwritten, for example:
3620 * 1. proc1: mdt returns a lsm but not granting layout
3621 * 2. layout was changed by another client
3622 * 3. proc2: refresh layout and layout lock granted
3623 * 4. proc1: to apply a stale layout */
3624 if (it != NULL && it->it_lock_mode != 0) {
3625 struct lustre_handle lockh;
3626 struct ldlm_lock *lock;
3628 lockh.cookie = it->it_lock_handle;
3629 lock = ldlm_handle2lock(&lockh);
3630 LASSERT(lock != NULL);
3631 if (ldlm_has_layout(lock)) {
3632 struct cl_object_conf conf;
3634 memset(&conf, 0, sizeof(conf));
3635 conf.coc_opc = OBJECT_CONF_SET;
3636 conf.coc_inode = *inode;
3637 conf.coc_lock = lock;
3638 conf.coc_try = false;
3639 conf.u.coc_layout = md.layout;
3640 (void)ll_layout_conf(*inode, &conf);
3642 LDLM_LOCK_PUT(lock);
3645 if (default_lmv_deleted)
3646 ll_update_default_lsm_md(*inode, &md);
3648 /* we may want to apply some policy for foreign file/dir */
3649 if (ll_sbi_has_foreign_symlink(sbi)) {
3650 rc = ll_manage_foreign(*inode, &md);
3658 /* cleanup will be done if necessary */
3659 md_put_lustre_md(sbi->ll_md_exp, &md);
3661 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3662 ll_intent_drop_lock(it);
3663 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3669 int ll_obd_statfs(struct inode *inode, void __user *uarg)
3671 struct ll_sb_info *sbi = NULL;
3672 struct obd_export *exp;
3673 struct obd_ioctl_data *data = NULL;
3678 sbi = ll_i2sbi(inode);
3680 GOTO(out_statfs, rc = -EINVAL);
3682 rc = obd_ioctl_getdata(&data, &len, uarg);
3684 GOTO(out_statfs, rc);
3686 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3687 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3688 GOTO(out_statfs, rc = -EINVAL);
3690 if (data->ioc_inllen1 != sizeof(__u32) ||
3691 data->ioc_inllen2 != sizeof(__u32) ||
3692 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3693 data->ioc_plen2 != sizeof(struct obd_uuid))
3694 GOTO(out_statfs, rc = -EINVAL);
3696 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3697 if (type & LL_STATFS_LMV)
3698 exp = sbi->ll_md_exp;
3699 else if (type & LL_STATFS_LOV)
3700 exp = sbi->ll_dt_exp;
3702 GOTO(out_statfs, rc = -ENODEV);
3704 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3706 GOTO(out_statfs, rc);
3708 OBD_FREE_LARGE(data, len);
3713 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3714 * be called early to avoid deadlock.
3716 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3718 lmv_stripe_object_put(&op_data->op_lso2);
3719 lmv_stripe_object_put(&op_data->op_lso1);
3720 lmv_stripe_object_put(&op_data->op_default_lso1);
3723 /* this function prepares md_op_data hint for passing it down to MD stack. */
3724 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3725 struct inode *i1, struct inode *i2,
3726 const char *name, size_t namelen,
3727 __u32 mode, enum md_op_code opc,
3730 struct llcrypt_name fname = { 0 };
3733 LASSERT(i1 != NULL);
3736 /* Do not reuse namelen for something else. */
3738 return ERR_PTR(-EINVAL);
3740 if ((!IS_ENCRYPTED(i1) ||
3741 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3742 namelen > ll_i2sbi(i1)->ll_namelen)
3743 return ERR_PTR(-ENAMETOOLONG);
3745 /* "/" is not valid name, but it's allowed */
3746 if (!lu_name_is_valid_2(name, namelen) &&
3747 strncmp("/", name, namelen) != 0)
3748 return ERR_PTR(-EINVAL);
3751 if (op_data == NULL)
3752 OBD_ALLOC_PTR(op_data);
3754 if (op_data == NULL)
3755 return ERR_PTR(-ENOMEM);
3757 ll_i2gids(op_data->op_suppgids, i1, i2);
3758 /* If the client is using a subdir mount and looks at what it sees as
3759 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3761 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3762 !fid_is_root(ll_inode2fid(i1)) &&
3763 name && namelen == strlen(dot_fscrypt_name) &&
3764 strncmp(name, dot_fscrypt_name, namelen) == 0))
3765 lu_root_fid(&op_data->op_fid1);
3767 op_data->op_fid1 = *ll_inode2fid(i1);
3769 if (S_ISDIR(i1->i_mode)) {
3770 down_read(&ll_i2info(i1)->lli_lsm_sem);
3772 lmv_stripe_object_get(ll_i2info(i1)->lli_lsm_obj);
3773 op_data->op_default_lso1 =
3774 lmv_stripe_object_get(ll_i2info(i1)->lli_def_lsm_obj);
3775 up_read(&ll_i2info(i1)->lli_lsm_sem);
3779 op_data->op_fid2 = *ll_inode2fid(i2);
3780 if (S_ISDIR(i2->i_mode)) {
3781 down_read(&ll_i2info(i2)->lli_lsm_sem);
3783 lmv_stripe_object_get(ll_i2info(i2)->lli_lsm_obj);
3784 up_read(&ll_i2info(i2)->lli_lsm_sem);
3787 fid_zero(&op_data->op_fid2);
3790 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3791 op_data->op_cli_flags |= CLI_HASH64;
3793 if (ll_need_32bit_api(ll_i2sbi(i1)))
3794 op_data->op_cli_flags |= CLI_API32;
3796 if ((i2 && is_root_inode(i2)) ||
3797 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3798 /* In case of lookup, ll_setup_filename() has already been
3799 * called in ll_lookup_it(), so just take provided name.
3800 * Also take provided name if we are dealing with root inode.
3802 fname.disk_name.name = (unsigned char *)name;
3803 fname.disk_name.len = namelen;
3804 } else if (name && namelen) {
3805 struct qstr dname = QSTR_INIT(name, namelen);
3807 struct lu_fid *pfid = NULL;
3811 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3812 /* special case when called from ll_link() */
3817 lookup = (int)(opc == LUSTRE_OPC_ANY);
3819 if (opc == LUSTRE_OPC_ANY && lookup)
3821 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3823 ll_finish_md_op_data(op_data);
3826 if (pfid && !fid_is_zero(pfid)) {
3828 op_data->op_fid2 = fid;
3829 op_data->op_bias = MDS_FID_OP;
3831 if (fname.disk_name.name &&
3832 fname.disk_name.name != (unsigned char *)name) {
3833 /* op_data->op_name must be freed after use */
3834 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3838 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3839 * are LUSTRE_OPC_ANY
3841 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3842 op_data->op_code = LUSTRE_OPC_ANY;
3844 op_data->op_code = opc;
3845 op_data->op_name = fname.disk_name.name;
3846 op_data->op_namelen = fname.disk_name.len;
3847 op_data->op_mode = mode;
3848 op_data->op_mod_time = ktime_get_real_seconds();
3849 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3850 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3851 op_data->op_cap = current_cap();
3852 op_data->op_mds = 0;
3853 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3854 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3855 op_data->op_bias |= MDS_CREATE_VOLATILE;
3857 op_data->op_data = data;
3862 void ll_finish_md_op_data(struct md_op_data *op_data)
3864 ll_unlock_md_op_lsm(op_data);
3865 ll_security_release_secctx(op_data->op_file_secctx,
3866 op_data->op_file_secctx_size,
3867 op_data->op_file_secctx_slot);
3868 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3869 /* allocated via ll_setup_filename called
3870 * from ll_prep_md_op_data
3872 kfree(op_data->op_name);
3873 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3874 OBD_FREE_PTR(op_data);
3877 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3879 struct ll_sb_info *sbi;
3882 LASSERT(seq && dentry);
3883 sbi = ll_s2sbi(dentry->d_sb);
3885 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3886 seq_puts(seq, "nolock");
3888 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3889 /* match_table in some cases has patterns for both enabled and
3890 * disabled cases. Ignore 'no'xxx versions if bit is set.
3892 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3893 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3894 if (ll_sbi_flags_name[i].token ==
3895 LL_SBI_FOREIGN_SYMLINK) {
3896 seq_show_option(seq, "foreign_symlink",
3897 sbi->ll_foreign_symlink_prefix);
3899 seq_printf(seq, ",%s",
3900 ll_sbi_flags_name[i].pattern);
3903 /* You can have either localflock or flock but not
3904 * both. If localflock is set don't print flock or
3907 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3909 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3910 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3911 seq_printf(seq, ",%s",
3912 ll_sbi_flags_name[i].pattern);
3916 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3922 * Get obd name by cmd, and copy out to user space
3924 int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg)
3926 struct ll_sb_info *sbi = ll_i2sbi(inode);
3927 struct obd_device *obd;
3930 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3931 obd = class_exp2obd(sbi->ll_dt_exp);
3932 else if (cmd == OBD_IOC_GETMDNAME)
3933 obd = class_exp2obd(sbi->ll_md_exp);
3940 if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1))
3947 struct work_struct db_work;
3948 struct dentry *db_dentry;
3949 /* Let's hope the path is not too long, 32 bytes for the work struct
3952 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3955 static void ll_dput_later(struct work_struct *work)
3957 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3959 dput(db->db_dentry);
3960 free_page((unsigned long)db);
3963 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3970 p.mnt = current->fs->root.mnt;
3972 path = d_path(&p, buf, bufsize);
3977 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3979 struct dname_buf *db;
3981 struct dentry *dentry = NULL;
3983 /* this can be called inside spin lock so use GFP_ATOMIC. */
3984 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3987 dentry = d_find_alias(inode);
3989 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3992 /* The below message is checked in recovery-small.sh test_24b */
3994 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3995 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3996 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3997 PFID(ll_inode2fid(inode)),
3998 (path && !IS_ERR(path)) ? path : "", ioret);
4000 if (dentry != NULL) {
4001 /* We cannot dput here since if we happen to be the last holder
4002 * then we can end up waiting for page evictions that
4003 * in turn wait for RPCs that need this instance of ptlrpcd
4004 * (callng brw_interpret->*page_completion*->vmpage_error->here)
4007 INIT_WORK(&db->db_work, ll_dput_later);
4008 db->db_dentry = dentry;
4009 schedule_work(&db->db_work);
4012 free_page((unsigned long)db);
4016 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
4017 struct lov_user_md **kbuf)
4019 struct lov_user_md lum;
4023 if (copy_from_user(&lum, md, sizeof(lum)))
4026 lum_size = ll_lov_user_md_size(&lum);
4030 OBD_ALLOC_LARGE(*kbuf, lum_size);
4034 if (copy_from_user(*kbuf, md, lum_size) != 0) {
4035 OBD_FREE_LARGE(*kbuf, lum_size);
4043 * Compute llite root squash state after a change of root squash
4044 * configuration setting or add/remove of a lnet nid
4046 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
4048 struct root_squash_info *squash = &sbi->ll_squash;
4051 struct lnet_processid id;
4053 /* Update norootsquash flag */
4054 spin_lock(&squash->rsi_lock);
4055 if (list_empty(&squash->rsi_nosquash_nids))
4056 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4058 /* Do not apply root squash as soon as one of our NIDs is
4059 * in the nosquash_nids list */
4062 while (LNetGetId(i++, &id, false) != -ENOENT) {
4063 if (nid_is_lo0(&id.nid))
4065 if (cfs_match_nid(&id.nid,
4066 &squash->rsi_nosquash_nids)) {
4072 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4074 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4076 spin_unlock(&squash->rsi_lock);
4080 * Parse linkea content to extract information about a given hardlink
4082 * \param[in] ldata - Initialized linkea data
4083 * \param[in] linkno - Link identifier
4084 * \param[out] parent_fid - The entry's parent FID
4085 * \param[out] ln - Entry name destination buffer
4087 * \retval 0 on success
4088 * \retval Appropriate negative error code on failure
4090 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
4091 struct lu_fid *parent_fid, struct lu_name *ln)
4097 rc = linkea_init_with_rec(ldata);
4101 if (linkno >= ldata->ld_leh->leh_reccount)
4102 /* beyond last link */
4105 linkea_first_entry(ldata);
4106 for (idx = 0; ldata->ld_lee != NULL; idx++) {
4107 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
4112 linkea_next_entry(ldata);
4122 * Get parent FID and name of an identified link. Operation is performed for
4123 * a given link number, letting the caller iterate over linkno to list one or
4124 * all links of an entry.
4126 * \param[in] file - File descriptor against which to perform the operation
4127 * \param[in,out] arg - User-filled structure containing the linkno to operate
4128 * on and the available size. It is eventually filled with
4129 * the requested information or left untouched on error
4131 * \retval - 0 on success
4132 * \retval - Appropriate negative error code on failure
4134 int ll_getparent(struct file *file, struct getparent __user *arg)
4136 struct inode *inode = file_inode(file);
4137 struct linkea_data *ldata;
4138 struct lu_buf buf = LU_BUF_NULL;
4140 struct lu_fid parent_fid;
4147 if (!capable(CAP_DAC_READ_SEARCH) &&
4148 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
4151 if (get_user(name_size, &arg->gp_name_size))
4154 if (get_user(linkno, &arg->gp_linkno))
4157 if (name_size > PATH_MAX)
4160 OBD_ALLOC(ldata, sizeof(*ldata));
4164 rc = linkea_data_new(ldata, &buf);
4166 GOTO(ldata_free, rc);
4168 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
4169 buf.lb_len, OBD_MD_FLXATTR);
4173 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
4177 if (ln.ln_namelen >= name_size)
4178 GOTO(lb_free, rc = -EOVERFLOW);
4180 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
4181 GOTO(lb_free, rc = -EFAULT);
4183 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
4184 GOTO(lb_free, rc = -EFAULT);
4186 if (put_user('\0', arg->gp_name + ln.ln_namelen))
4187 GOTO(lb_free, rc = -EFAULT);
4192 OBD_FREE(ldata, sizeof(*ldata));