4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/llite/llite_lib.c
33 * Lustre Light Super operations
36 #define DEBUG_SUBSYSTEM S_LLITE
38 #include <linux/cpu.h>
39 #include <linux/module.h>
40 #include <linux/random.h>
41 #include <linux/statfs.h>
42 #include <linux/time.h>
43 #include <linux/file.h>
44 #include <linux/types.h>
45 #include <libcfs/linux/linux-uuid.h>
46 #include <linux/version.h>
48 #include <linux/user_namespace.h>
49 #include <linux/delay.h>
50 #include <linux/uidgid.h>
51 #include <linux/fs_struct.h>
53 #ifndef HAVE_CPUS_READ_LOCK
54 #include <libcfs/linux/linux-cpu.h>
56 #include <libcfs/linux/linux-misc.h>
57 #include <uapi/linux/lustre/lustre_ioctl.h>
58 #ifdef HAVE_UAPI_LINUX_MOUNT_H
59 #include <uapi/linux/mount.h>
62 #include <lustre_ha.h>
63 #include <lustre_dlm.h>
64 #include <lprocfs_status.h>
65 #include <lustre_disk.h>
66 #include <uapi/linux/lustre/lustre_param.h>
67 #include <lustre_log.h>
68 #include <cl_object.h>
69 #include <obd_cksum.h>
70 #include "llite_internal.h"
72 struct kmem_cache *ll_file_data_slab;
75 #define log2(n) ffz(~(n))
79 * If there is only one number of core visible to Lustre,
80 * async readahead will be disabled, to avoid massive over
81 * subscription, we use 1/2 of active cores as default max
82 * async readahead requests.
84 static inline unsigned int ll_get_ra_async_max_active(void)
86 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
89 static struct ll_sb_info *ll_init_sbi(struct lustre_sb_info *lsi)
91 struct ll_sb_info *sbi = NULL;
93 unsigned long lru_page_max;
101 RETURN(ERR_PTR(-ENOMEM));
103 rc = pcc_super_init(&sbi->ll_pcc_super);
107 spin_lock_init(&sbi->ll_lock);
108 mutex_init(&sbi->ll_lco.lco_lock);
109 spin_lock_init(&sbi->ll_pp_extent_lock);
110 spin_lock_init(&sbi->ll_process_lock);
112 sbi->ll_rw_stats_on = 0;
113 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
116 pages = si.totalram - si.totalhigh;
117 lru_page_max = pages / 2;
119 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
120 sbi->ll_ra_info.ll_readahead_wq =
121 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
123 sbi->ll_ra_info.ra_async_max_active);
124 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
125 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
127 /* initialize ll_cache data */
128 sbi->ll_cache = cl_cache_init(lru_page_max);
129 if (sbi->ll_cache == NULL)
130 GOTO(out_destroy_ra, rc = -ENOMEM);
132 /* initialize foreign symlink prefix path */
133 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
134 if (sbi->ll_foreign_symlink_prefix == NULL)
135 GOTO(out_destroy_ra, rc = -ENOMEM);
136 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
137 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
139 /* initialize foreign symlink upcall path, none by default */
140 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
141 if (sbi->ll_foreign_symlink_upcall == NULL)
142 GOTO(out_destroy_ra, rc = -ENOMEM);
143 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
144 sbi->ll_foreign_symlink_upcall_items = NULL;
145 sbi->ll_foreign_symlink_upcall_nb_items = 0;
146 init_rwsem(&sbi->ll_foreign_symlink_sem);
147 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
148 * not enabled by default
151 sbi->ll_secctx_name = NULL;
152 sbi->ll_secctx_name_size = 0;
154 sbi->ll_ra_info.ra_max_pages =
155 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
156 sbi->ll_ra_info.ra_max_pages_per_file =
157 min(sbi->ll_ra_info.ra_max_pages / 4,
158 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
159 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
160 sbi->ll_ra_info.ra_max_pages_per_file;
161 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
162 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
163 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
165 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
166 #ifdef ENABLE_CHECKSUM
167 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
170 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
173 #ifdef HAVE_LRU_RESIZE_SUPPORT
174 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
176 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
178 /* metadata statahead is enabled by default */
179 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
180 sbi->ll_sa_max = LL_SA_RPC_DEF;
181 atomic_set(&sbi->ll_sa_total, 0);
182 atomic_set(&sbi->ll_sa_wrong, 0);
183 atomic_set(&sbi->ll_sa_running, 0);
184 atomic_set(&sbi->ll_agl_total, 0);
185 atomic_set(&sbi->ll_sa_hit_total, 0);
186 atomic_set(&sbi->ll_sa_miss_total, 0);
187 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
188 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
189 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
190 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
191 ll_sbi_set_encrypt(sbi, true);
192 ll_sbi_set_name_encrypt(sbi, true);
195 sbi->ll_squash.rsi_uid = 0;
196 sbi->ll_squash.rsi_gid = 0;
197 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
198 spin_lock_init(&sbi->ll_squash.rsi_lock);
200 /* Per-filesystem file heat */
201 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
202 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
204 /* Per-fs open heat level before requesting open lock */
205 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
206 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
207 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
210 if (sbi->ll_foreign_symlink_prefix)
211 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
213 cl_cache_decref(sbi->ll_cache);
214 sbi->ll_cache = NULL;
216 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
218 pcc_super_fini(&sbi->ll_pcc_super);
224 static void ll_free_sbi(struct super_block *sb)
226 struct ll_sb_info *sbi = ll_s2sbi(sb);
230 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
231 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
232 if (sbi->ll_ra_info.ll_readahead_wq)
233 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
234 if (sbi->ll_cache != NULL) {
235 cl_cache_decref(sbi->ll_cache);
236 sbi->ll_cache = NULL;
238 if (sbi->ll_foreign_symlink_prefix) {
239 OBD_FREE(sbi->ll_foreign_symlink_prefix,
240 sbi->ll_foreign_symlink_prefix_size);
241 sbi->ll_foreign_symlink_prefix = NULL;
243 if (sbi->ll_foreign_symlink_upcall) {
244 OBD_FREE(sbi->ll_foreign_symlink_upcall,
245 strlen(sbi->ll_foreign_symlink_upcall) +
247 sbi->ll_foreign_symlink_upcall = NULL;
249 if (sbi->ll_foreign_symlink_upcall_items) {
251 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
252 struct ll_foreign_symlink_upcall_item *items =
253 sbi->ll_foreign_symlink_upcall_items;
255 for (i = 0 ; i < nb_items; i++)
256 if (items[i].type == STRING_TYPE)
257 OBD_FREE(items[i].string,
260 OBD_FREE_LARGE(items, nb_items *
261 sizeof(struct ll_foreign_symlink_upcall_item));
262 sbi->ll_foreign_symlink_upcall_items = NULL;
264 if (sbi->ll_secctx_name)
265 ll_secctx_name_free(sbi);
267 ll_free_rw_stats_info(sbi);
268 pcc_super_fini(&sbi->ll_pcc_super);
269 OBD_FREE(sbi, sizeof(*sbi));
274 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
276 struct inode *root = NULL;
277 struct ll_sb_info *sbi = ll_s2sbi(sb);
278 struct obd_statfs *osfs = NULL;
279 struct ptlrpc_request *request = NULL;
280 struct obd_connect_data *data = NULL;
281 struct obd_uuid *uuid;
282 struct md_op_data *op_data;
283 struct lustre_md lmd;
285 int size, err, checksum;
291 sbi->ll_md_obd = class_name2obd(md);
292 if (!sbi->ll_md_obd) {
293 CERROR("MD %s: not setup or attached\n", md);
307 /* pass client page size via ocd_grant_blkbits, the server should report
308 * back its backend blocksize for grant calculation purpose */
309 data->ocd_grant_blkbits = PAGE_SHIFT;
311 /* indicate MDT features supported by this client */
312 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
313 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
314 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
315 OBD_CONNECT_SRVLOCK |
316 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
317 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
318 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
319 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
320 OBD_CONNECT_64BITHASH |
321 OBD_CONNECT_EINPROGRESS |
322 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
323 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
324 OBD_CONNECT_MAX_EASIZE |
325 OBD_CONNECT_FLOCK_DEAD |
326 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
327 OBD_CONNECT_OPEN_BY_FID |
328 OBD_CONNECT_DIR_STRIPE |
329 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
330 OBD_CONNECT_SUBTREE |
331 OBD_CONNECT_MULTIMODRPCS |
332 OBD_CONNECT_GRANT_PARAM |
333 OBD_CONNECT_GRANT_SHRINK |
334 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
336 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
337 OBD_CONNECT2_SUM_STATFS |
338 OBD_CONNECT2_OVERSTRIPING |
340 OBD_CONNECT2_LOCK_CONVERT |
341 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
342 OBD_CONNECT2_INC_XID |
344 OBD_CONNECT2_ASYNC_DISCARD |
346 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
347 OBD_CONNECT2_GETATTR_PFID |
348 OBD_CONNECT2_DOM_LVB |
349 OBD_CONNECT2_REP_MBITS |
350 OBD_CONNECT2_ATOMIC_OPEN_LOCK;
352 #ifdef HAVE_LRU_RESIZE_SUPPORT
353 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
354 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
356 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
358 data->ocd_cksum_types = obd_cksum_types_supported_client();
360 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
361 /* flag mdc connection as lightweight, only used for test
362 * purpose, use with care */
363 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
365 data->ocd_ibits_known = MDS_INODELOCK_FULL;
366 data->ocd_version = LUSTRE_VERSION_CODE;
368 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
369 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
372 /* Setting this indicates we correctly support S_NOSEC (See kernel
373 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
375 sb->s_flags |= SB_NOSEC;
377 sbi->ll_fop = ll_select_file_operations(sbi);
379 /* always ping even if server suppress_pings */
380 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
381 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
383 obd_connect_set_secctx(data);
384 if (ll_sbi_has_encrypt(sbi)) {
385 obd_connect_set_enc_fid2path(data);
386 obd_connect_set_name_enc(data);
387 obd_connect_set_enc(data);
390 #if defined(CONFIG_SECURITY)
391 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
394 data->ocd_brw_size = MD_MAX_BRW_SIZE;
397 if (sb->s_flags & SB_RDONLY)
398 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
399 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
400 &sbi->ll_sb_uuid, data, sbi->ll_cache);
402 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
403 "recovery, of which this client is not a "
404 "part. Please wait for recovery to complete,"
405 " abort, or time out.\n", md);
408 CERROR("cannot connect to %s: rc = %d\n", md, err);
412 sbi->ll_md_exp->exp_connect_data = *data;
414 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
415 LUSTRE_SEQ_METADATA);
417 CERROR("%s: Can't init metadata layer FID infrastructure, "
418 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
422 /* For mount, we only need fs info from MDT0, and also in DNE, it
423 * can make sure the client can be mounted as long as MDT0 is
425 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
426 ktime_get_seconds() - sbi->ll_statfs_max_age,
427 OBD_STATFS_FOR_MDT0);
428 if (err == -EROFS && !(sb->s_flags & SB_RDONLY)) {
429 /* We got -EROFS from the server, maybe it is imposing
430 * read-only mount. So just retry like this.
432 cfs_tty_write_msg("Forcing read-only mount.\n\r");
433 CERROR("%s: mount failed with %d, forcing read-only mount.\n",
434 sbi->ll_md_exp->exp_obd->obd_name, err);
435 sb->s_flags |= SB_RDONLY;
436 obd_fid_fini(sbi->ll_md_exp->exp_obd);
437 obd_disconnect(sbi->ll_md_exp);
438 GOTO(retry_connect, err);
440 GOTO(out_md_fid, err);
443 /* This needs to be after statfs to ensure connect has finished.
444 * Note that "data" does NOT contain the valid connect reply.
445 * If connecting to a 1.8 server there will be no LMV device, so
446 * we can access the MDC export directly and exp_connect_flags will
447 * be non-zero, but if accessing an upgraded 2.1 server it will
448 * have the correct flags filled in.
449 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
450 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
451 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
452 valid != CLIENT_CONNECT_MDT_REQD) {
455 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
456 obd_connect_flags2str(buf, PAGE_SIZE,
457 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
458 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
459 "feature(s) needed for correct operation "
460 "of this client (%s). Please upgrade "
461 "server or downgrade client.\n",
462 sbi->ll_md_exp->exp_obd->obd_name, buf);
463 OBD_FREE(buf, PAGE_SIZE);
464 GOTO(out_md_fid, err = -EPROTO);
467 size = sizeof(*data);
468 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
469 KEY_CONN_DATA, &size, data);
471 CERROR("%s: Get connect data failed: rc = %d\n",
472 sbi->ll_md_exp->exp_obd->obd_name, err);
473 GOTO(out_md_fid, err);
476 LASSERT(osfs->os_bsize);
477 sb->s_blocksize = osfs->os_bsize;
478 sb->s_blocksize_bits = log2(osfs->os_bsize);
479 sb->s_magic = LL_SUPER_MAGIC;
480 sb->s_maxbytes = MAX_LFS_FILESIZE;
481 sbi->ll_inode_cache_enabled = 1;
482 sbi->ll_namelen = osfs->os_namelen;
483 sbi->ll_mnt.mnt = current->fs->root.mnt;
484 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
486 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
487 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
488 LCONSOLE_INFO("Disabling user_xattr feature because "
489 "it is not supported on the server\n");
490 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
493 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
495 sb->s_flags |= SB_POSIXACL;
497 set_bit(LL_SBI_ACL, sbi->ll_flags);
499 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
501 sb->s_flags &= ~SB_POSIXACL;
503 clear_bit(LL_SBI_ACL, sbi->ll_flags);
506 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
507 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
509 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
510 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
512 if (obd_connect_has_secctx(data))
513 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
515 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
516 if (ll_sb_has_test_dummy_encryption(sb))
517 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
519 sbi->ll_md_exp->exp_obd->obd_name);
520 ll_sbi_set_encrypt(sbi, false);
523 if (ll_sbi_has_name_encrypt(sbi) && !obd_connect_has_name_enc(data)) {
524 struct lustre_sb_info *lsi = s2lsi(sb);
526 if (ll_sb_has_test_dummy_encryption(sb))
527 LCONSOLE_WARN("%s: server %s does not support name encryption, not using it.\n",
529 sbi->ll_md_exp->exp_obd->obd_name);
530 #ifdef CONFIG_LL_ENCRYPTION
531 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
533 lsi->lsi_flags &= ~LSI_FILENAME_ENC_B64_OLD_CLI;
534 ll_sbi_set_name_encrypt(sbi, false);
537 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
538 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
539 LCONSOLE_INFO("%s: disabling xattr cache due to "
540 "unknown maximum xattr size.\n", dt);
541 } else if (!sbi->ll_xattr_cache_set) {
542 /* If xattr_cache is already set (no matter 0 or 1)
543 * during processing llog, it won't be enabled here. */
544 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
545 sbi->ll_xattr_cache_enabled = 1;
549 sbi->ll_dt_obd = class_name2obd(dt);
550 if (!sbi->ll_dt_obd) {
551 CERROR("DT %s: not setup or attached\n", dt);
552 GOTO(out_md_fid, err = -ENODEV);
555 /* pass client page size via ocd_grant_blkbits, the server should report
556 * back its backend blocksize for grant calculation purpose */
557 data->ocd_grant_blkbits = PAGE_SHIFT;
559 /* indicate OST features supported by this client */
560 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
561 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
562 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
563 OBD_CONNECT_SRVLOCK |
564 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
565 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
566 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
567 OBD_CONNECT_EINPROGRESS |
568 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
569 OBD_CONNECT_LAYOUTLOCK |
570 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
571 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
572 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
573 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
574 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
575 OBD_CONNECT2_REP_MBITS;
577 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
578 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
580 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
581 * disabled by default, because it can still be enabled on the
582 * fly via /sys. As a consequence, we still need to come to an
583 * agreement on the supported algorithms at connect time
585 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
587 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
588 data->ocd_cksum_types = OBD_CKSUM_ADLER;
590 data->ocd_cksum_types = obd_cksum_types_supported_client();
592 #ifdef HAVE_LRU_RESIZE_SUPPORT
593 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
595 /* always ping even if server suppress_pings */
596 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
597 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
599 if (ll_sbi_has_encrypt(sbi))
600 obd_connect_set_enc(data);
602 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
603 "ocd_grant: %d\n", data->ocd_connect_flags,
604 data->ocd_version, data->ocd_grant);
606 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
607 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
609 data->ocd_brw_size = DT_MAX_BRW_SIZE;
611 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
612 &sbi->ll_sb_uuid, data, sbi->ll_cache);
614 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
615 "recovery, of which this client is not a "
616 "part. Please wait for recovery to "
617 "complete, abort, or time out.\n", dt);
620 CERROR("%s: Cannot connect to %s: rc = %d\n",
621 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
625 if (ll_sbi_has_encrypt(sbi) &&
626 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
627 if (ll_sb_has_test_dummy_encryption(sb))
628 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
630 ll_sbi_set_encrypt(sbi, false);
631 } else if (ll_sb_has_test_dummy_encryption(sb)) {
632 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
635 sbi->ll_dt_exp->exp_connect_data = *data;
637 /* Don't change value if it was specified in the config log */
638 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
639 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
640 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
641 (data->ocd_brw_size >> PAGE_SHIFT));
642 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
643 sbi->ll_ra_info.ra_max_pages_per_file)
644 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
645 sbi->ll_ra_info.ra_max_pages_per_file;
648 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
649 LUSTRE_SEQ_METADATA);
651 CERROR("%s: Can't init data layer FID infrastructure, "
652 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
656 mutex_lock(&sbi->ll_lco.lco_lock);
657 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
658 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
659 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
660 mutex_unlock(&sbi->ll_lco.lco_lock);
662 fid_zero(&sbi->ll_root_fid);
663 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
666 CERROR("cannot mds_connect: rc = %d\n", err);
667 GOTO(out_lock_cn_cb, err);
669 if (!fid_is_sane(&sbi->ll_root_fid)) {
670 CERROR("%s: Invalid root fid "DFID" during mount\n",
671 sbi->ll_md_exp->exp_obd->obd_name,
672 PFID(&sbi->ll_root_fid));
673 GOTO(out_lock_cn_cb, err = -EINVAL);
675 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
677 sb->s_op = &lustre_super_operations;
678 sb->s_xattr = ll_xattr_handlers;
679 #if THREAD_SIZE >= 8192 /*b=17630*/
680 sb->s_export_op = &lustre_export_operations;
682 #ifdef HAVE_LUSTRE_CRYPTO
683 llcrypt_set_ops(sb, &lustre_cryptops);
687 * XXX: move this to after cbd setup? */
688 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
690 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
691 valid |= OBD_MD_FLACL;
693 OBD_ALLOC_PTR(op_data);
695 GOTO(out_lock_cn_cb, err = -ENOMEM);
697 op_data->op_fid1 = sbi->ll_root_fid;
698 op_data->op_mode = 0;
699 op_data->op_valid = valid;
701 err = md_getattr(sbi->ll_md_exp, op_data, &request);
703 /* We need enc ctx info, so reset it in op_data to
704 * prevent it from being freed.
706 encctx = op_data->op_file_encctx;
707 encctxlen = op_data->op_file_encctx_size;
708 op_data->op_file_encctx = NULL;
709 op_data->op_file_encctx_size = 0;
710 OBD_FREE_PTR(op_data);
712 CERROR("%s: md_getattr failed for root: rc = %d\n",
713 sbi->ll_md_exp->exp_obd->obd_name, err);
714 GOTO(out_lock_cn_cb, err);
717 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
718 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
720 CERROR("failed to understand root inode md: rc = %d\n", err);
721 ptlrpc_req_finished(request);
722 GOTO(out_lock_cn_cb, err);
725 LASSERT(fid_is_sane(&sbi->ll_root_fid));
726 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
727 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
728 md_free_lustre_md(sbi->ll_md_exp, &lmd);
732 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
734 CERROR("%s: bad ll_iget() for root: rc = %d\n",
735 sbi->ll_fsname, err);
736 ptlrpc_req_finished(request);
740 err = ll_secctx_name_store(root);
741 if (err < 0 && ll_security_xattr_wanted(root))
742 CWARN("%s: file security contextes not supported: rc = %d\n",
743 sbi->ll_fsname, err);
748 "server returned encryption ctx for root inode "DFID"\n",
749 PFID(&sbi->ll_root_fid));
750 err = ll_set_encflags(root, encctx, encctxlen, true);
752 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
754 PFID(&sbi->ll_root_fid), err);
756 ptlrpc_req_finished(request);
758 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
759 if (sbi->ll_checksum_set) {
760 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
761 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
762 sizeof(checksum), &checksum, NULL);
764 CERROR("%s: Set checksum failed: rc = %d\n",
765 sbi->ll_dt_exp->exp_obd->obd_name, err);
771 sb->s_root = d_make_root(root);
772 if (sb->s_root == NULL) {
774 CERROR("%s: can't make root dentry: rc = %d\n",
775 sbi->ll_fsname, err);
779 sbi->ll_sdev_orig = sb->s_dev;
781 /* We set sb->s_dev equal on all lustre clients in order to support
782 * NFS export clustering. NFSD requires that the FSID be the same
784 /* s_dev is also used in lt_compare() to compare two fs, but that is
785 * only a node-local comparison. */
786 uuid = obd_get_uuid(sbi->ll_md_exp);
788 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
795 if (sbi->ll_dt_obd) {
796 err = sysfs_create_link(&sbi->ll_kset.kobj,
797 &sbi->ll_dt_obd->obd_kset.kobj,
798 sbi->ll_dt_obd->obd_type->typ_name);
800 CERROR("%s: could not register %s in llite: rc = %d\n",
801 dt, sbi->ll_fsname, err);
806 if (sbi->ll_md_obd) {
807 err = sysfs_create_link(&sbi->ll_kset.kobj,
808 &sbi->ll_md_obd->obd_kset.kobj,
809 sbi->ll_md_obd->obd_type->typ_name);
811 CERROR("%s: could not register %s in llite: rc = %d\n",
812 md, sbi->ll_fsname, err);
821 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
823 obd_disconnect(sbi->ll_dt_exp);
824 sbi->ll_dt_exp = NULL;
825 sbi->ll_dt_obd = NULL;
827 obd_fid_fini(sbi->ll_md_exp->exp_obd);
829 obd_disconnect(sbi->ll_md_exp);
830 sbi->ll_md_exp = NULL;
831 sbi->ll_md_obd = NULL;
840 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
844 size = sizeof(*lmmsize);
845 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
846 KEY_MAX_EASIZE, &size, lmmsize);
848 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
849 sbi->ll_dt_exp->exp_obd->obd_name, rc);
853 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
856 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
857 KEY_MAX_EASIZE, &size, lmmsize);
859 CERROR("Get max mdsize error rc %d\n", rc);
861 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
867 * Get the value of the default_easize parameter.
869 * \see client_obd::cl_default_mds_easize
871 * \param[in] sbi superblock info for this filesystem
872 * \param[out] lmmsize pointer to storage location for value
874 * \retval 0 on success
875 * \retval negative negated errno on failure
877 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
882 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
883 KEY_DEFAULT_EASIZE, &size, lmmsize);
885 CERROR("Get default mdsize error rc %d\n", rc);
891 * Set the default_easize parameter to the given value.
893 * \see client_obd::cl_default_mds_easize
895 * \param[in] sbi superblock info for this filesystem
896 * \param[in] lmmsize the size to set
898 * \retval 0 on success
899 * \retval negative negated errno on failure
901 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
905 if (lmmsize < sizeof(struct lov_mds_md) ||
906 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
909 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
910 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
911 sizeof(int), &lmmsize, NULL);
916 static void client_common_put_super(struct super_block *sb)
918 struct ll_sb_info *sbi = ll_s2sbi(sb);
923 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
924 obd_disconnect(sbi->ll_dt_exp);
925 sbi->ll_dt_exp = NULL;
927 ll_debugfs_unregister_super(sb);
929 obd_fid_fini(sbi->ll_md_exp->exp_obd);
930 obd_disconnect(sbi->ll_md_exp);
931 sbi->ll_md_exp = NULL;
936 void ll_kill_super(struct super_block *sb)
938 struct ll_sb_info *sbi;
942 if (!(sb->s_flags & SB_ACTIVE))
946 /* we need restore s_dev from changed for clustred NFS before put_super
947 * because new kernels have cached s_dev and change sb->s_dev in
948 * put_super not affected real removing devices */
950 sb->s_dev = sbi->ll_sdev_orig;
952 /* wait running statahead threads to quit */
953 while (atomic_read(&sbi->ll_sa_running) > 0)
954 schedule_timeout_uninterruptible(
955 cfs_time_seconds(1) >> 3);
961 /* Since we use this table for ll_sbi_flags_seq_show make
962 * sure what you want displayed for a specific token that
963 * is listed more than once below be listed first. For
964 * example we want "checksum" displayed, not "nochecksum"
967 static const match_table_t ll_sbi_flags_name = {
968 {LL_SBI_NOLCK, "nolock"},
969 {LL_SBI_CHECKSUM, "checksum"},
970 {LL_SBI_CHECKSUM, "nochecksum"},
971 {LL_SBI_LOCALFLOCK, "localflock"},
972 {LL_SBI_FLOCK, "flock"},
973 {LL_SBI_FLOCK, "noflock"},
974 {LL_SBI_USER_XATTR, "user_xattr"},
975 {LL_SBI_USER_XATTR, "nouser_xattr"},
976 {LL_SBI_LRU_RESIZE, "lruresize"},
977 {LL_SBI_LRU_RESIZE, "nolruresize"},
978 {LL_SBI_LAZYSTATFS, "lazystatfs"},
979 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
980 {LL_SBI_32BIT_API, "32bitapi"},
981 {LL_SBI_USER_FID2PATH, "user_fid2path"},
982 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
983 {LL_SBI_VERBOSE, "verbose"},
984 {LL_SBI_VERBOSE, "noverbose"},
985 {LL_SBI_ALWAYS_PING, "always_ping"},
986 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
987 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
988 {LL_SBI_ENCRYPT, "encrypt"},
989 {LL_SBI_ENCRYPT, "noencrypt"},
990 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
991 {LL_SBI_NUM_MOUNT_OPT, NULL},
994 {LL_SBI_AGL_ENABLED, "agl"},
995 {LL_SBI_64BIT_HASH, "64bit_hash"},
996 {LL_SBI_LAYOUT_LOCK, "layout"},
997 {LL_SBI_XATTR_CACHE, "xattr_cache"},
998 {LL_SBI_NOROOTSQUASH, "norootsquash"},
999 {LL_SBI_FAST_READ, "fast_read"},
1000 {LL_SBI_FILE_SECCTX, "file_secctx"},
1001 {LL_SBI_TINY_WRITE, "tiny_write"},
1002 {LL_SBI_FILE_HEAT, "file_heat"},
1003 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
1004 {LL_SBI_ENCRYPT_NAME, "name_encrypt"},
1007 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
1009 struct super_block *sb = m->private;
1012 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
1015 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
1018 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
1019 if (ll_sbi_flags_name[j].token == i &&
1020 ll_sbi_flags_name[j].pattern) {
1021 seq_printf(m, "%s ",
1022 ll_sbi_flags_name[j].pattern);
1027 seq_puts(m, "\b\n");
1031 /* non-client-specific mount options are parsed in lmd_parse */
1032 static int ll_options(char *options, struct super_block *sb)
1034 struct ll_sb_info *sbi = ll_s2sbi(sb);
1035 char *s2, *s1, *opts;
1042 /* Don't stomp on lmd_opts */
1043 opts = kstrdup(options, GFP_KERNEL);
1049 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1051 while ((s1 = strsep(&opts, ",")) != NULL) {
1052 substring_t args[MAX_OPT_ARGS];
1053 bool turn_off = false;
1059 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1061 if (strncmp(s1, "no", 2) == 0)
1065 * Initialize args struct so we know whether arg was
1066 * found; some options take optional arguments.
1069 args[0].from = NULL;
1070 token = match_token(s1, ll_sbi_flags_name, args);
1071 if (token == LL_SBI_NUM_MOUNT_OPT) {
1072 if (match_wildcard("context", s1) ||
1073 match_wildcard("fscontext", s1) ||
1074 match_wildcard("defcontext", s1) ||
1075 match_wildcard("rootcontext",s1))
1078 LCONSOLE_ERROR_MSG(0x152,
1079 "Unknown option '%s', won't mount.\n",
1086 case LL_SBI_32BIT_API:
1087 case LL_SBI_64BIT_HASH:
1088 case LL_SBI_ALWAYS_PING:
1089 set_bit(token, sbi->ll_flags);
1093 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1095 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1097 set_bit(token, sbi->ll_flags);
1100 case LL_SBI_LOCALFLOCK:
1101 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1102 set_bit(token, sbi->ll_flags);
1105 case LL_SBI_CHECKSUM:
1106 sbi->ll_checksum_set = 1;
1108 case LL_SBI_USER_XATTR:
1109 case LL_SBI_USER_FID2PATH:
1110 case LL_SBI_LRU_RESIZE:
1111 case LL_SBI_LAZYSTATFS:
1112 case LL_SBI_VERBOSE:
1114 clear_bit(token, sbi->ll_flags);
1116 set_bit(token, sbi->ll_flags);
1118 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1119 #ifdef HAVE_LUSTRE_CRYPTO
1120 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1121 set_bit(token, sbi->ll_flags);
1123 struct lustre_sb_info *lsi = s2lsi(sb);
1125 err = llcrypt_set_test_dummy_encryption(sb,
1126 #ifdef HAVE_FSCRYPT_SET_TEST_DUMMY_ENC_CHAR_ARG
1131 &lsi->lsi_dummy_enc_policy);
1137 "Can't change test_dummy_encryption");
1138 else if (err == -EINVAL)
1140 "Value of option \"%s\" unrecognized",
1144 "Error processing option \"%s\" [%d]",
1149 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1153 case LL_SBI_ENCRYPT:
1154 #ifdef HAVE_LUSTRE_CRYPTO
1156 clear_bit(token, sbi->ll_flags);
1158 set_bit(token, sbi->ll_flags);
1160 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1163 case LL_SBI_FOREIGN_SYMLINK:
1164 /* non-default prefix provided ? */
1169 /* path must be absolute */
1170 if (args->from[0] != '/') {
1171 LCONSOLE_ERROR_MSG(0x152,
1172 "foreign prefix '%s' must be an absolute path\n",
1177 old_len = sbi->ll_foreign_symlink_prefix_size;
1178 old = sbi->ll_foreign_symlink_prefix;
1179 /* alloc for path length and '\0' */
1180 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1181 if (!sbi->ll_foreign_symlink_prefix) {
1182 /* restore previous */
1183 sbi->ll_foreign_symlink_prefix = old;
1184 sbi->ll_foreign_symlink_prefix_size =
1188 sbi->ll_foreign_symlink_prefix_size =
1189 args->to - args->from + 1;
1190 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1191 sbi->ll_foreign_symlink_prefix_size,
1194 OBD_FREE(old, old_len);
1196 /* enable foreign symlink support */
1197 set_bit(token, sbi->ll_flags);
1199 LCONSOLE_ERROR_MSG(0x152,
1200 "invalid %s option\n", s1);
1211 void ll_lli_init(struct ll_inode_info *lli)
1213 lli->lli_inode_magic = LLI_INODE_MAGIC;
1215 rwlock_init(&lli->lli_lock);
1216 lli->lli_posix_acl = NULL;
1217 /* Do not set lli_fid, it has been initialized already. */
1218 fid_zero(&lli->lli_pfid);
1219 lli->lli_mds_read_och = NULL;
1220 lli->lli_mds_write_och = NULL;
1221 lli->lli_mds_exec_och = NULL;
1222 lli->lli_open_fd_read_count = 0;
1223 lli->lli_open_fd_write_count = 0;
1224 lli->lli_open_fd_exec_count = 0;
1225 mutex_init(&lli->lli_och_mutex);
1226 spin_lock_init(&lli->lli_agl_lock);
1227 spin_lock_init(&lli->lli_layout_lock);
1228 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1229 lli->lli_clob = NULL;
1231 init_rwsem(&lli->lli_xattrs_list_rwsem);
1232 mutex_init(&lli->lli_xattrs_enq_lock);
1234 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1235 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1236 lli->lli_opendir_key = NULL;
1237 lli->lli_sai = NULL;
1238 spin_lock_init(&lli->lli_sa_lock);
1239 lli->lli_opendir_pid = 0;
1240 lli->lli_sa_enabled = 0;
1241 init_rwsem(&lli->lli_lsm_sem);
1243 mutex_init(&lli->lli_size_mutex);
1244 mutex_init(&lli->lli_setattr_mutex);
1245 lli->lli_symlink_name = NULL;
1246 ll_trunc_sem_init(&lli->lli_trunc_sem);
1247 range_lock_tree_init(&lli->lli_write_tree);
1248 init_rwsem(&lli->lli_glimpse_sem);
1249 lli->lli_glimpse_time = ktime_set(0, 0);
1250 INIT_LIST_HEAD(&lli->lli_agl_list);
1251 lli->lli_agl_index = 0;
1252 lli->lli_async_rc = 0;
1253 spin_lock_init(&lli->lli_heat_lock);
1254 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1255 lli->lli_heat_flags = 0;
1256 mutex_init(&lli->lli_pcc_lock);
1257 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1258 lli->lli_pcc_inode = NULL;
1259 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1260 lli->lli_pcc_generation = 0;
1261 mutex_init(&lli->lli_group_mutex);
1262 lli->lli_group_users = 0;
1263 lli->lli_group_gid = 0;
1265 mutex_init(&lli->lli_layout_mutex);
1266 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1267 /* ll_cl_context initialize */
1268 INIT_LIST_HEAD(&lli->lli_lccs);
1269 seqlock_init(&lli->lli_page_inv_lock);
1272 #define MAX_STRING_SIZE 128
1274 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1275 #ifndef HAVE_BDI_CAP_MAP_COPY
1276 # define BDI_CAP_MAP_COPY 0
1279 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1281 struct lustre_sb_info *lsi = s2lsi(sb);
1282 char buf[MAX_STRING_SIZE];
1286 err = bdi_init(&lsi->lsi_bdi);
1290 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1291 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1292 lsi->lsi_bdi.name = "lustre";
1293 va_start(args, fmt);
1294 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1296 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1299 sb->s_bdi = &lsi->lsi_bdi;
1303 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1305 int ll_fill_super(struct super_block *sb)
1307 struct lustre_profile *lprof = NULL;
1308 struct lustre_sb_info *lsi = s2lsi(sb);
1309 struct ll_sb_info *sbi = NULL;
1310 char *dt = NULL, *md = NULL;
1311 char *profilenm = get_profile_name(sb);
1312 struct config_llog_instance *cfg;
1313 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1314 const int instlen = LUSTRE_MAXINSTANCE + 2;
1315 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1316 char name[MAX_STRING_SIZE];
1325 /* for ASLR, to map between cfg_instance and hashed ptr */
1326 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1327 profilenm, cfg_instance, sb);
1329 OBD_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1333 GOTO(out_free_cfg, err = -ENOMEM);
1335 /* client additional sb info */
1336 lsi->lsi_llsbi = sbi = ll_init_sbi(lsi);
1338 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1340 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1342 GOTO(out_free_cfg, err);
1344 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1345 #ifdef CONFIG_LL_ENCRYPTION
1346 if (ll_sb_has_test_dummy_encryption(sb))
1347 /* enable filename encryption by default for dummy enc mode */
1348 lsi->lsi_flags |= LSI_FILENAME_ENC;
1350 /* filename encryption is disabled by default */
1351 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1354 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1355 sb->s_d_op = &ll_d_ops;
1358 generate_random_uuid(uuid.b);
1359 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1361 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1364 len = strlen(profilenm);
1365 ptr = strrchr(profilenm, '-');
1366 if (ptr && (strcmp(ptr, "-client") == 0))
1369 if (len > LUSTRE_MAXFSNAME) {
1370 if (unlikely(len >= MAX_STRING_SIZE))
1371 len = MAX_STRING_SIZE - 1;
1372 strncpy(name, profilenm, len);
1374 err = -ENAMETOOLONG;
1375 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1376 name, LUSTRE_MAXFSNAME, err);
1377 GOTO(out_free_cfg, err);
1379 strncpy(sbi->ll_fsname, profilenm, len);
1380 sbi->ll_fsname[len] = '\0';
1383 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1384 profilenm, cfg_instance);
1386 err = super_setup_bdi_name(sb, "%s", name);
1388 GOTO(out_free_cfg, err);
1390 /* disable kernel readahead */
1391 sb->s_bdi->ra_pages = 0;
1392 #ifdef HAVE_BDI_IO_PAGES
1393 sb->s_bdi->io_pages = 0;
1396 /* Call ll_debugfs_register_super() before lustre_process_log()
1397 * so that "llite.*.*" params can be processed correctly.
1399 err = ll_debugfs_register_super(sb, name);
1401 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1402 sbi->ll_fsname, err);
1406 /* The cfg_instance is a value unique to this super, in case some
1407 * joker tries to mount the same fs at two mount points.
1409 cfg->cfg_instance = cfg_instance;
1410 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1411 cfg->cfg_callback = class_config_llog_handler;
1412 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1413 /* set up client obds */
1414 err = lustre_process_log(sb, profilenm, cfg);
1416 GOTO(out_debugfs, err);
1418 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1419 lprof = class_get_profile(profilenm);
1420 if (lprof == NULL) {
1421 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1422 " read from the MGS. Does that filesystem "
1423 "exist?\n", profilenm);
1424 GOTO(out_debugfs, err = -EINVAL);
1426 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1427 lprof->lp_md, lprof->lp_dt);
1429 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1430 OBD_ALLOC(dt, dt_len);
1432 GOTO(out_profile, err = -ENOMEM);
1433 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1435 md_len = strlen(lprof->lp_md) + instlen + 2;
1436 OBD_ALLOC(md, md_len);
1438 GOTO(out_free_dt, err = -ENOMEM);
1439 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1441 /* connections, registrations, sb setup */
1442 err = client_common_fill_super(sb, md, dt);
1444 GOTO(out_free_md, err);
1446 sbi->ll_client_common_fill_super_succeeded = 1;
1450 OBD_FREE(md, md_len);
1453 OBD_FREE(dt, dt_len);
1456 class_put_profile(lprof);
1459 ll_debugfs_unregister_super(sb);
1466 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1467 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1468 sb->s_flags & SB_RDONLY ? " read-only" : "");
1470 } /* ll_fill_super */
1472 void ll_put_super(struct super_block *sb)
1474 struct config_llog_instance cfg, params_cfg;
1475 struct obd_device *obd;
1476 struct lustre_sb_info *lsi = s2lsi(sb);
1477 struct ll_sb_info *sbi = ll_s2sbi(sb);
1478 char *profilenm = get_profile_name(sb);
1479 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1481 int next, force = 1, rc = 0;
1485 GOTO(out_no_sbi, 0);
1487 /* Should replace instance_id with something better for ASLR */
1488 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1489 profilenm, cfg_instance, sb);
1491 cfg.cfg_instance = cfg_instance;
1492 lustre_end_log(sb, profilenm, &cfg);
1494 params_cfg.cfg_instance = cfg_instance;
1495 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1497 if (sbi->ll_md_exp) {
1498 obd = class_exp2obd(sbi->ll_md_exp);
1500 force = obd->obd_force;
1503 /* Wait for unstable pages to be committed to stable storage */
1505 rc = l_wait_event_abortable(
1506 sbi->ll_cache->ccc_unstable_waitq,
1507 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1510 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1511 if (force == 0 && rc != -ERESTARTSYS)
1512 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1514 /* We need to set force before the lov_disconnect in
1515 * lustre_common_put_super, since l_d cleans up osc's as well.
1519 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1521 obd->obd_force = force;
1525 if (sbi->ll_client_common_fill_super_succeeded) {
1526 /* Only if client_common_fill_super succeeded */
1527 client_common_put_super(sb);
1530 /* imitate failed cleanup */
1531 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1535 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1536 class_manual_cleanup(obd);
1539 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1540 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1543 class_del_profile(profilenm);
1545 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1546 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1547 bdi_destroy(&lsi->lsi_bdi);
1548 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1552 llcrypt_free_dummy_policy(&lsi->lsi_dummy_enc_policy);
1554 lsi->lsi_llsbi = NULL;
1556 lustre_common_put_super(sb);
1558 cl_env_cache_purge(~0);
1561 } /* client_put_super */
1563 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1565 struct inode *inode = NULL;
1567 /* NOTE: we depend on atomic igrab() -bzzz */
1568 lock_res_and_lock(lock);
1569 if (lock->l_resource->lr_lvb_inode) {
1570 struct ll_inode_info * lli;
1571 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1572 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1573 inode = igrab(lock->l_resource->lr_lvb_inode);
1575 inode = lock->l_resource->lr_lvb_inode;
1576 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1577 D_WARNING, lock, "lr_lvb_inode %p is "
1578 "bogus: magic %08x",
1579 lock->l_resource->lr_lvb_inode,
1580 lli->lli_inode_magic);
1584 unlock_res_and_lock(lock);
1588 void ll_dir_clear_lsm_md(struct inode *inode)
1590 struct ll_inode_info *lli = ll_i2info(inode);
1592 LASSERT(S_ISDIR(inode->i_mode));
1594 if (lli->lli_lsm_md) {
1595 lmv_free_memmd(lli->lli_lsm_md);
1596 lli->lli_lsm_md = NULL;
1599 if (lli->lli_default_lsm_md) {
1600 lmv_free_memmd(lli->lli_default_lsm_md);
1601 lli->lli_default_lsm_md = NULL;
1605 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1606 const struct lu_fid *fid,
1607 struct lustre_md *md)
1609 struct ll_sb_info *sbi = ll_s2sbi(sb);
1610 struct ll_inode_info *lli;
1611 struct mdt_body *body = md->body;
1612 struct inode *inode;
1618 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1619 inode = iget_locked(sb, ino);
1620 if (inode == NULL) {
1621 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1622 sbi->ll_fsname, PFID(fid));
1623 RETURN(ERR_PTR(-ENOENT));
1626 lli = ll_i2info(inode);
1627 if (inode->i_state & I_NEW) {
1628 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1629 (body->mbo_mode & S_IFMT);
1630 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1633 inode->i_mtime.tv_sec = 0;
1634 inode->i_atime.tv_sec = 0;
1635 inode->i_ctime.tv_sec = 0;
1638 #ifdef HAVE_BACKING_DEV_INFO
1639 /* initializing backing dev info. */
1640 inode->i_mapping->backing_dev_info =
1641 &s2lsi(inode->i_sb)->lsi_bdi;
1643 inode->i_op = &ll_dir_inode_operations;
1644 inode->i_fop = &ll_dir_operations;
1645 lli->lli_fid = *fid;
1648 /* master object FID */
1649 lli->lli_pfid = body->mbo_fid1;
1650 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1651 lli, PFID(fid), PFID(&lli->lli_pfid));
1652 unlock_new_inode(inode);
1654 /* in directory restripe/auto-split, a directory will be
1655 * transformed to a stripe if it's plain, set its pfid here,
1656 * otherwise ll_lock_cancel_bits() can't find the master inode.
1658 lli->lli_pfid = body->mbo_fid1;
1664 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1667 struct lmv_stripe_md *lsm = md->lmv;
1668 struct ll_inode_info *lli = ll_i2info(inode);
1671 LASSERT(lsm != NULL);
1673 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1674 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1675 lsm_md_dump(D_INODE, lsm);
1677 if (!lmv_dir_striped(lsm))
1680 /* XXX sigh, this lsm_root initialization should be in
1681 * LMV layer, but it needs ll_iget right now, so we
1682 * put this here right now. */
1683 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1684 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1685 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1687 if (!fid_is_sane(fid))
1690 /* Unfortunately ll_iget will call ll_update_inode,
1691 * where the initialization of slave inode is slightly
1692 * different, so it reset lsm_md to NULL to avoid
1693 * initializing lsm for slave inode. */
1694 lsm->lsm_md_oinfo[i].lmo_root =
1695 ll_iget_anon_dir(inode->i_sb, fid, md);
1696 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1697 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1699 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1701 iput(lsm->lsm_md_oinfo[i].lmo_root);
1702 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1708 lli->lli_lsm_md = lsm;
1713 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1715 struct ll_inode_info *lli = ll_i2info(inode);
1719 if (!md->default_lmv) {
1720 /* clear default lsm */
1721 if (lli->lli_default_lsm_md) {
1722 down_write(&lli->lli_lsm_sem);
1723 if (lli->lli_default_lsm_md) {
1724 lmv_free_memmd(lli->lli_default_lsm_md);
1725 lli->lli_default_lsm_md = NULL;
1727 lli->lli_inherit_depth = 0;
1728 up_write(&lli->lli_lsm_sem);
1733 if (lli->lli_default_lsm_md) {
1734 /* do nonthing if default lsm isn't changed */
1735 down_read(&lli->lli_lsm_sem);
1736 if (lli->lli_default_lsm_md &&
1737 lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1738 up_read(&lli->lli_lsm_sem);
1741 up_read(&lli->lli_lsm_sem);
1744 down_write(&lli->lli_lsm_sem);
1745 if (lli->lli_default_lsm_md)
1746 lmv_free_memmd(lli->lli_default_lsm_md);
1747 lli->lli_default_lsm_md = md->default_lmv;
1748 lsm_md_dump(D_INODE, md->default_lmv);
1749 md->default_lmv = NULL;
1750 up_write(&lli->lli_lsm_sem);
1754 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1756 struct ll_inode_info *lli = ll_i2info(inode);
1757 struct lmv_stripe_md *lsm = md->lmv;
1758 struct cl_attr *attr;
1763 LASSERT(S_ISDIR(inode->i_mode));
1764 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1765 PFID(ll_inode2fid(inode)));
1767 /* update default LMV */
1768 if (md->default_lmv)
1769 ll_update_default_lsm_md(inode, md);
1771 /* after dir migration/restripe, a stripe may be turned into a
1772 * directory, in this case, zero out its lli_pfid.
1774 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1775 fid_zero(&lli->lli_pfid);
1778 * no striped information from request, lustre_md from req does not
1779 * include stripeEA, see ll_md_setattr()
1785 * normally dir layout doesn't change, only take read lock to check
1786 * that to avoid blocking other MD operations.
1788 down_read(&lli->lli_lsm_sem);
1790 /* some current lookup initialized lsm, and unchanged */
1791 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1792 GOTO(unlock, rc = 0);
1794 /* if dir layout doesn't match, check whether version is increased,
1795 * which means layout is changed, this happens in dir split/merge and
1798 * foreign LMV should not change.
1800 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1801 lsm->lsm_md_layout_version <=
1802 lli->lli_lsm_md->lsm_md_layout_version) {
1803 CERROR("%s: "DFID" dir layout mismatch:\n",
1804 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1805 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1806 lsm_md_dump(D_ERROR, lsm);
1807 GOTO(unlock, rc = -EINVAL);
1810 up_read(&lli->lli_lsm_sem);
1811 down_write(&lli->lli_lsm_sem);
1812 /* clear existing lsm */
1813 if (lli->lli_lsm_md) {
1814 lmv_free_memmd(lli->lli_lsm_md);
1815 lli->lli_lsm_md = NULL;
1818 rc = ll_init_lsm_md(inode, md);
1820 up_write(&lli->lli_lsm_sem);
1824 /* md_merge_attr() may take long, since lsm is already set, switch to
1827 downgrade_write(&lli->lli_lsm_sem);
1829 /* set md->lmv to NULL, so the following free lustre_md will not free
1834 if (!lmv_dir_striped(lli->lli_lsm_md))
1835 GOTO(unlock, rc = 0);
1837 OBD_ALLOC_PTR(attr);
1839 GOTO(unlock, rc = -ENOMEM);
1841 /* validate the lsm */
1842 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1843 ll_md_blocking_ast);
1845 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1846 md->body->mbo_nlink = attr->cat_nlink;
1847 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1848 md->body->mbo_size = attr->cat_size;
1849 if (md->body->mbo_valid & OBD_MD_FLATIME)
1850 md->body->mbo_atime = attr->cat_atime;
1851 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1852 md->body->mbo_ctime = attr->cat_ctime;
1853 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1854 md->body->mbo_mtime = attr->cat_mtime;
1860 up_read(&lli->lli_lsm_sem);
1865 void ll_clear_inode(struct inode *inode)
1867 struct ll_inode_info *lli = ll_i2info(inode);
1868 struct ll_sb_info *sbi = ll_i2sbi(inode);
1872 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1873 PFID(ll_inode2fid(inode)), inode);
1875 if (S_ISDIR(inode->i_mode)) {
1876 /* these should have been cleared in ll_file_release */
1877 LASSERT(lli->lli_opendir_key == NULL);
1878 LASSERT(lli->lli_sai == NULL);
1879 LASSERT(lli->lli_opendir_pid == 0);
1881 pcc_inode_free(inode);
1884 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1886 LASSERT(!lli->lli_open_fd_write_count);
1887 LASSERT(!lli->lli_open_fd_read_count);
1888 LASSERT(!lli->lli_open_fd_exec_count);
1890 if (lli->lli_mds_write_och)
1891 ll_md_real_close(inode, FMODE_WRITE);
1892 if (lli->lli_mds_exec_och)
1893 ll_md_real_close(inode, FMODE_EXEC);
1894 if (lli->lli_mds_read_och)
1895 ll_md_real_close(inode, FMODE_READ);
1897 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1898 OBD_FREE(lli->lli_symlink_name,
1899 strlen(lli->lli_symlink_name) + 1);
1900 lli->lli_symlink_name = NULL;
1903 ll_xattr_cache_destroy(inode);
1905 forget_all_cached_acls(inode);
1907 lli->lli_inode_magic = LLI_INODE_DEAD;
1909 if (S_ISDIR(inode->i_mode))
1910 ll_dir_clear_lsm_md(inode);
1911 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1912 LASSERT(list_empty(&lli->lli_agl_list));
1915 * XXX This has to be done before lsm is freed below, because
1916 * cl_object still uses inode lsm.
1918 cl_inode_fini(inode);
1920 llcrypt_put_encryption_info(inode);
1925 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1927 struct lustre_md md;
1928 struct inode *inode = dentry->d_inode;
1929 struct ll_sb_info *sbi = ll_i2sbi(inode);
1930 struct ptlrpc_request *request = NULL;
1935 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1936 LUSTRE_OPC_ANY, NULL);
1937 if (IS_ERR(op_data))
1938 RETURN(PTR_ERR(op_data));
1940 /* If this is a chgrp of a regular file, we want to reserve enough
1941 * quota to cover the entire file size.
1943 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1944 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1945 from_kgid(&init_user_ns, inode->i_gid)) {
1946 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1947 op_data->op_attr_blocks = inode->i_blocks;
1951 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1953 ptlrpc_req_finished(request);
1954 if (rc == -ENOENT) {
1956 /* Unlinked special device node? Or just a race?
1957 * Pretend we done everything. */
1958 if (!S_ISREG(inode->i_mode) &&
1959 !S_ISDIR(inode->i_mode)) {
1960 ia_valid = op_data->op_attr.ia_valid;
1961 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1962 rc = simple_setattr(&init_user_ns, dentry,
1964 op_data->op_attr.ia_valid = ia_valid;
1966 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1967 CERROR("md_setattr fails: rc = %d\n", rc);
1972 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1973 sbi->ll_md_exp, &md);
1975 ptlrpc_req_finished(request);
1979 ia_valid = op_data->op_attr.ia_valid;
1980 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1981 * cache is not cleared yet. */
1982 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1983 if (S_ISREG(inode->i_mode))
1985 rc = simple_setattr(&init_user_ns, dentry, &op_data->op_attr);
1986 if (S_ISREG(inode->i_mode))
1987 inode_unlock(inode);
1988 op_data->op_attr.ia_valid = ia_valid;
1990 rc = ll_update_inode(inode, &md);
1991 ptlrpc_req_finished(request);
1997 * Zero portion of page that is part of @inode.
1998 * This implies, if necessary:
1999 * - taking cl_lock on range corresponding to concerned page
2000 * - grabbing vm page
2001 * - associating cl_page
2002 * - proceeding to clio read
2003 * - zeroing range in page
2004 * - proceeding to cl_page flush
2005 * - releasing cl_lock
2007 * \param[in] inode inode
2008 * \param[in] index page index
2009 * \param[in] offset offset in page to start zero from
2010 * \param[in] len len to zero
2012 * \retval 0 on success
2013 * \retval negative errno on failure
2015 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
2018 struct ll_inode_info *lli = ll_i2info(inode);
2019 struct cl_object *clob = lli->lli_clob;
2021 struct lu_env *env = NULL;
2022 struct cl_io *io = NULL;
2023 struct cl_page *clpage = NULL;
2024 struct page *vmpage = NULL;
2025 unsigned from = index << PAGE_SHIFT;
2026 struct cl_lock *lock = NULL;
2027 struct cl_lock_descr *descr = NULL;
2028 struct cl_2queue *queue = NULL;
2029 struct cl_sync_io *anchor = NULL;
2030 bool holdinglock = false;
2035 env = cl_env_get(&refcheck);
2037 RETURN(PTR_ERR(env));
2039 io = vvp_env_thread_io(env);
2041 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2045 lock = vvp_env_lock(env);
2046 descr = &lock->cll_descr;
2047 descr->cld_obj = io->ci_obj;
2048 descr->cld_start = cl_index(io->ci_obj, from);
2049 descr->cld_end = cl_index(io->ci_obj, from + PAGE_SIZE - 1);
2050 descr->cld_mode = CLM_WRITE;
2051 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2053 /* request lock for page */
2054 rc = cl_lock_request(env, io, lock);
2055 /* -ECANCELED indicates a matching lock with a different extent
2056 * was already present, and -EEXIST indicates a matching lock
2057 * on exactly the same extent was already present.
2058 * In both cases it means we are covered.
2060 if (rc == -ECANCELED || rc == -EEXIST)
2068 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2070 GOTO(rellock, rc = -EOPNOTSUPP);
2072 if (!PageDirty(vmpage)) {
2073 /* associate cl_page */
2074 clpage = cl_page_find(env, clob, vmpage->index,
2075 vmpage, CPT_CACHEABLE);
2077 GOTO(pagefini, rc = PTR_ERR(clpage));
2079 cl_page_assume(env, io, clpage);
2082 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2083 !PageWriteback(vmpage)) {
2085 /* Set PagePrivate2 to detect special case of empty page
2086 * in osc_brw_fini_request().
2087 * It is also used to tell ll_io_read_page() that we do not
2088 * want the vmpage to be unlocked.
2090 SetPagePrivate2(vmpage);
2091 rc = ll_io_read_page(env, io, clpage, NULL);
2092 if (!PagePrivate2(vmpage)) {
2093 /* PagePrivate2 was cleared in osc_brw_fini_request()
2094 * meaning we read an empty page. In this case, in order
2095 * to avoid allocating unnecessary block in truncated
2096 * file, we must not zero and write as below. Subsequent
2097 * server-side truncate will handle things correctly.
2099 cl_page_unassume(env, io, clpage);
2100 GOTO(clpfini, rc = 0);
2102 ClearPagePrivate2(vmpage);
2107 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2108 * the vmpage, so we are good to proceed and zero range in page.
2110 zero_user(vmpage, offset, len);
2112 if (holdinglock && clpage) {
2113 /* explicitly write newly modified page */
2114 queue = &io->ci_queue;
2115 cl_2queue_init(queue);
2116 anchor = &vvp_env_info(env)->vti_anchor;
2117 cl_sync_io_init(anchor, 1);
2118 clpage->cp_sync_io = anchor;
2119 cl_page_list_add(&queue->c2_qin, clpage, true);
2120 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2122 GOTO(queuefini1, rc);
2123 rc = cl_sync_io_wait(env, anchor, 0);
2125 GOTO(queuefini2, rc);
2126 cl_page_assume(env, io, clpage);
2129 cl_2queue_discard(env, io, queue);
2131 cl_2queue_disown(env, queue);
2132 cl_2queue_fini(env, queue);
2137 cl_page_put(env, clpage);
2139 unlock_page(vmpage);
2143 cl_lock_release(env, lock);
2145 cl_io_fini(env, io);
2148 cl_env_put(env, &refcheck);
2154 * Get reference file from volatile file name.
2155 * Volatile file name may look like:
2156 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2157 * where fd is opened descriptor of reference file.
2159 * \param[in] volatile_name volatile file name
2160 * \param[in] volatile_len volatile file name length
2161 * \param[out] ref_file pointer to struct file of reference file
2163 * \retval 0 on success
2164 * \retval negative errno on failure
2166 int volatile_ref_file(const char *volatile_name, int volatile_len,
2167 struct file **ref_file)
2169 char *p, *q, *fd_str;
2172 p = strnstr(volatile_name, ":fd=", volatile_len);
2173 if (!p || strlen(p + 4) == 0)
2176 q = strchrnul(p + 4, ':');
2177 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2180 rc = kstrtouint(fd_str, 10, &fd);
2185 *ref_file = fget(fd);
2191 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2192 * object(s) determine the file size and mtime. Otherwise, the MDS will
2193 * keep these values until such a time that objects are allocated for it.
2194 * We do the MDS operations first, as it is checking permissions for us.
2195 * We don't to the MDS RPC if there is nothing that we want to store there,
2196 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2197 * going to do an RPC anyways.
2199 * If we are doing a truncate, we will send the mtime and ctime updates
2200 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2201 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2204 * In case of HSMimport, we only set attr on MDS.
2206 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2207 enum op_xvalid xvalid, bool hsm_import)
2209 struct inode *inode = dentry->d_inode;
2210 struct ll_inode_info *lli = ll_i2info(inode);
2211 struct md_op_data *op_data = NULL;
2212 ktime_t kstart = ktime_get();
2217 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2218 "valid %x, hsm_import %d\n",
2219 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2220 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2223 if (attr->ia_valid & ATTR_SIZE) {
2224 /* Check new size against VFS/VM file size limit and rlimit */
2225 rc = inode_newsize_ok(inode, attr->ia_size);
2229 /* The maximum Lustre file size is variable, based on the
2230 * OST maximum object size and number of stripes. This
2231 * needs another check in addition to the VFS check above. */
2232 if (attr->ia_size > ll_file_maxbytes(inode)) {
2233 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2234 PFID(&lli->lli_fid), attr->ia_size,
2235 ll_file_maxbytes(inode));
2239 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2242 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2243 if (attr->ia_valid & TIMES_SET_FLAGS) {
2244 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2245 !capable(CAP_FOWNER))
2249 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2250 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2251 (attr->ia_valid & ATTR_CTIME)) {
2252 attr->ia_ctime = current_time(inode);
2253 xvalid |= OP_XVALID_CTIME_SET;
2255 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2256 (attr->ia_valid & ATTR_ATIME)) {
2257 attr->ia_atime = current_time(inode);
2258 attr->ia_valid |= ATTR_ATIME_SET;
2260 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2261 (attr->ia_valid & ATTR_MTIME)) {
2262 attr->ia_mtime = current_time(inode);
2263 attr->ia_valid |= ATTR_MTIME_SET;
2266 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2267 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2268 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2269 ktime_get_real_seconds());
2271 if (S_ISREG(inode->i_mode))
2272 inode_unlock(inode);
2274 /* We always do an MDS RPC, even if we're only changing the size;
2275 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2277 OBD_ALLOC_PTR(op_data);
2278 if (op_data == NULL)
2279 GOTO(out, rc = -ENOMEM);
2281 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2282 /* If we are changing file size, file content is
2283 * modified, flag it.
2285 xvalid |= OP_XVALID_OWNEROVERRIDE;
2286 op_data->op_bias |= MDS_DATA_MODIFIED;
2287 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2290 if (attr->ia_valid & ATTR_FILE) {
2291 struct ll_file_data *fd = attr->ia_file->private_data;
2293 if (fd->fd_lease_och)
2294 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2297 op_data->op_attr = *attr;
2298 op_data->op_xvalid = xvalid;
2300 rc = ll_md_setattr(dentry, op_data);
2303 lli->lli_synced_to_mds = false;
2305 if (!S_ISREG(inode->i_mode) || hsm_import)
2308 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2309 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2310 xvalid & OP_XVALID_CTIME_SET) {
2311 bool cached = false;
2313 rc = pcc_inode_setattr(inode, attr, &cached);
2316 CERROR("%s: PCC inode "DFID" setattr failed: "
2318 ll_i2sbi(inode)->ll_fsname,
2319 PFID(&lli->lli_fid), rc);
2323 unsigned int flags = 0;
2325 /* For truncate and utimes sending attributes to OSTs,
2326 * setting mtime/atime to the past will be performed
2327 * under PW [0:EOF] extent lock (new_size:EOF for
2328 * truncate). It may seem excessive to send mtime/atime
2329 * updates to OSTs when not setting times to past, but
2330 * it is necessary due to possible time
2331 * de-synchronization between MDT inode and OST objects
2333 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2334 xvalid |= OP_XVALID_FLAGS;
2335 flags = LUSTRE_ENCRYPT_FL;
2336 /* Call to ll_io_zero_page is not necessary if
2337 * truncating on PAGE_SIZE boundary, because
2338 * whole pages will be wiped.
2339 * In case of Direct IO, all we need is to set
2342 if (attr->ia_valid & ATTR_SIZE &&
2343 attr->ia_size & ~PAGE_MASK &&
2344 !(attr->ia_valid & ATTR_FILE &&
2345 attr->ia_file->f_flags & O_DIRECT)) {
2347 attr->ia_size & (PAGE_SIZE - 1);
2349 rc = ll_io_zero_page(inode,
2350 attr->ia_size >> PAGE_SHIFT,
2351 offset, PAGE_SIZE - offset);
2355 /* If encrypted volatile file without the key,
2356 * we need to fetch size from reference file,
2357 * and set it on OST objects. This happens when
2358 * migrating or extending an encrypted file
2361 if (filename_is_volatile(dentry->d_name.name,
2364 llcrypt_require_key(inode) == -ENOKEY) {
2365 struct file *ref_file;
2366 struct inode *ref_inode;
2367 struct ll_inode_info *ref_lli;
2368 struct cl_object *ref_obj;
2369 struct cl_attr ref_attr = { 0 };
2373 rc = volatile_ref_file(
2374 dentry->d_name.name,
2380 ref_inode = file_inode(ref_file);
2383 GOTO(out, rc = -EINVAL);
2386 env = cl_env_get(&refcheck);
2388 GOTO(out, rc = PTR_ERR(env));
2390 ref_lli = ll_i2info(ref_inode);
2391 ref_obj = ref_lli->lli_clob;
2392 cl_object_attr_lock(ref_obj);
2393 rc = cl_object_attr_get(env, ref_obj,
2395 cl_object_attr_unlock(ref_obj);
2396 cl_env_put(env, &refcheck);
2401 attr->ia_valid |= ATTR_SIZE;
2402 attr->ia_size = ref_attr.cat_size;
2405 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2409 /* If the file was restored, it needs to set dirty flag.
2411 * We've already sent MDS_DATA_MODIFIED flag in
2412 * ll_md_setattr() for truncate. However, the MDT refuses to
2413 * set the HS_DIRTY flag on released files, so we have to set
2414 * it again if the file has been restored. Please check how
2415 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2417 * Please notice that if the file is not released, the previous
2418 * MDS_DATA_MODIFIED has taken effect and usually
2419 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2420 * This way we can save an RPC for common open + trunc
2422 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2423 struct hsm_state_set hss = {
2424 .hss_valid = HSS_SETMASK,
2425 .hss_setmask = HS_DIRTY,
2429 rc2 = ll_hsm_state_set(inode, &hss);
2430 /* truncate and write can happen at the same time, so that
2431 * the file can be set modified even though the file is not
2432 * restored from released state, and ll_hsm_state_set() is
2433 * not applicable for the file, and rc2 < 0 is normal in this
2436 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2437 PFID(ll_inode2fid(inode)), rc2);
2442 if (op_data != NULL)
2443 ll_finish_md_op_data(op_data);
2445 if (S_ISREG(inode->i_mode)) {
2447 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2448 inode_dio_wait(inode);
2449 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2450 * flag. ll_update_inode (called from ll_md_setattr), clears
2451 * inode flags, so there is a gap where S_NOSEC is not set.
2452 * This can cause a writer to take the i_mutex unnecessarily,
2453 * but this is safe to do and should be rare. */
2454 inode_has_no_xattr(inode);
2458 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2459 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2460 ktime_us_delta(ktime_get(), kstart));
2465 int ll_setattr(struct user_namespace *mnt_userns, struct dentry *de,
2468 int mode = de->d_inode->i_mode;
2469 enum op_xvalid xvalid = 0;
2472 rc = llcrypt_prepare_setattr(de, attr);
2476 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2477 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2478 xvalid |= OP_XVALID_OWNEROVERRIDE;
2480 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2481 (ATTR_SIZE|ATTR_MODE)) &&
2482 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2483 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2484 !(attr->ia_mode & S_ISGID))))
2485 attr->ia_valid |= ATTR_FORCE;
2487 if ((attr->ia_valid & ATTR_MODE) &&
2489 !(attr->ia_mode & S_ISUID) &&
2490 !(attr->ia_valid & ATTR_KILL_SUID))
2491 attr->ia_valid |= ATTR_KILL_SUID;
2493 if ((attr->ia_valid & ATTR_MODE) &&
2494 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2495 !(attr->ia_mode & S_ISGID) &&
2496 !(attr->ia_valid & ATTR_KILL_SGID))
2497 attr->ia_valid |= ATTR_KILL_SGID;
2499 return ll_setattr_raw(de, attr, xvalid, false);
2502 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2505 struct obd_statfs obd_osfs = { 0 };
2510 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2512 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2513 flags |= OBD_STATFS_NODELAY;
2515 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2519 osfs->os_type = LL_SUPER_MAGIC;
2521 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2522 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2524 if (osfs->os_state & OS_STATFS_SUM)
2527 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2528 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2531 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2532 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2535 osfs->os_bsize = obd_osfs.os_bsize;
2536 osfs->os_blocks = obd_osfs.os_blocks;
2537 osfs->os_bfree = obd_osfs.os_bfree;
2538 osfs->os_bavail = obd_osfs.os_bavail;
2540 /* If we have _some_ OSTs, but don't have as many free objects on the
2541 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2542 * to compensate, so that the "inodes in use" number is correct.
2543 * This should be kept in sync with lod_statfs() behaviour.
2545 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2546 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2548 osfs->os_ffree = obd_osfs.os_ffree;
2555 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2557 struct if_quotactl qctl = {
2558 .qc_cmd = LUSTRE_Q_GETQUOTA,
2559 .qc_type = PRJQUOTA,
2560 .qc_valid = QC_GENERAL,
2562 u64 limit, curblock;
2565 qctl.qc_id = ll_i2info(inode)->lli_projid;
2566 ret = quotactl_ioctl(inode->i_sb, &qctl);
2568 /* ignore errors if project ID does not have
2569 * a quota limit or feature unsupported.
2571 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2576 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2577 qctl.qc_dqblk.dqb_bsoftlimit :
2578 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2579 if (limit && sfs->f_blocks > limit) {
2580 curblock = (qctl.qc_dqblk.dqb_curspace +
2581 sfs->f_bsize - 1) / sfs->f_bsize;
2582 sfs->f_blocks = limit;
2583 sfs->f_bfree = sfs->f_bavail =
2584 (sfs->f_blocks > curblock) ?
2585 (sfs->f_blocks - curblock) : 0;
2588 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2589 qctl.qc_dqblk.dqb_isoftlimit :
2590 qctl.qc_dqblk.dqb_ihardlimit;
2591 if (limit && sfs->f_files > limit) {
2592 sfs->f_files = limit;
2593 sfs->f_ffree = (sfs->f_files >
2594 qctl.qc_dqblk.dqb_curinodes) ?
2595 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2601 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2603 struct super_block *sb = de->d_sb;
2604 struct obd_statfs osfs;
2605 __u64 fsid = huge_encode_dev(sb->s_dev);
2606 ktime_t kstart = ktime_get();
2609 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2611 /* Some amount of caching on the client is allowed */
2612 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2616 statfs_unpack(sfs, &osfs);
2618 /* We need to downshift for all 32-bit kernels, because we can't
2619 * tell if the kernel is being called via sys_statfs64() or not.
2620 * Stop before overflowing f_bsize - in which case it is better
2621 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2622 if (sizeof(long) < 8) {
2623 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2626 osfs.os_blocks >>= 1;
2627 osfs.os_bfree >>= 1;
2628 osfs.os_bavail >>= 1;
2632 sfs->f_blocks = osfs.os_blocks;
2633 sfs->f_bfree = osfs.os_bfree;
2634 sfs->f_bavail = osfs.os_bavail;
2635 sfs->f_fsid.val[0] = (__u32)fsid;
2636 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2637 if (ll_i2info(de->d_inode)->lli_projid &&
2638 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2639 return ll_statfs_project(de->d_inode, sfs);
2641 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2642 ktime_us_delta(ktime_get(), kstart));
2647 void ll_inode_size_lock(struct inode *inode)
2649 struct ll_inode_info *lli;
2651 LASSERT(!S_ISDIR(inode->i_mode));
2653 lli = ll_i2info(inode);
2654 mutex_lock(&lli->lli_size_mutex);
2657 void ll_inode_size_unlock(struct inode *inode)
2659 struct ll_inode_info *lli;
2661 lli = ll_i2info(inode);
2662 mutex_unlock(&lli->lli_size_mutex);
2665 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2667 /* do not clear encryption flag */
2668 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2669 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2670 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2671 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2673 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2676 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2678 struct ll_inode_info *lli = ll_i2info(inode);
2679 struct mdt_body *body = md->body;
2680 struct ll_sb_info *sbi = ll_i2sbi(inode);
2684 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2685 rc = cl_file_inode_init(inode, md);
2690 if (S_ISDIR(inode->i_mode)) {
2691 rc = ll_update_lsm_md(inode, md);
2696 if (body->mbo_valid & OBD_MD_FLACL)
2697 lli_replace_acl(lli, md);
2699 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2700 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2701 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2703 if (body->mbo_valid & OBD_MD_FLATIME) {
2704 if (body->mbo_atime > inode->i_atime.tv_sec)
2705 inode->i_atime.tv_sec = body->mbo_atime;
2706 lli->lli_atime = body->mbo_atime;
2709 if (body->mbo_valid & OBD_MD_FLMTIME) {
2710 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2712 "setting ino %lu mtime from %lld to %llu\n",
2713 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2715 inode->i_mtime.tv_sec = body->mbo_mtime;
2717 lli->lli_mtime = body->mbo_mtime;
2720 if (body->mbo_valid & OBD_MD_FLCTIME) {
2721 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2722 inode->i_ctime.tv_sec = body->mbo_ctime;
2723 lli->lli_ctime = body->mbo_ctime;
2726 if (body->mbo_valid & OBD_MD_FLBTIME)
2727 lli->lli_btime = body->mbo_btime;
2729 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2730 if (body->mbo_valid & OBD_MD_FLFLAGS)
2731 ll_update_inode_flags(inode, body->mbo_flags);
2732 if (body->mbo_valid & OBD_MD_FLMODE)
2733 inode->i_mode = (inode->i_mode & S_IFMT) |
2734 (body->mbo_mode & ~S_IFMT);
2736 if (body->mbo_valid & OBD_MD_FLTYPE)
2737 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2738 (body->mbo_mode & S_IFMT);
2740 LASSERT(inode->i_mode != 0);
2741 if (body->mbo_valid & OBD_MD_FLUID)
2742 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2743 if (body->mbo_valid & OBD_MD_FLGID)
2744 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2745 if (body->mbo_valid & OBD_MD_FLPROJID)
2746 lli->lli_projid = body->mbo_projid;
2747 if (body->mbo_valid & OBD_MD_FLNLINK) {
2748 spin_lock(&inode->i_lock);
2749 set_nlink(inode, body->mbo_nlink);
2750 spin_unlock(&inode->i_lock);
2752 if (body->mbo_valid & OBD_MD_FLRDEV)
2753 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2755 if (body->mbo_valid & OBD_MD_FLID) {
2756 /* FID shouldn't be changed! */
2757 if (fid_is_sane(&lli->lli_fid)) {
2758 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2759 "Trying to change FID "DFID
2760 " to the "DFID", inode "DFID"(%p)\n",
2761 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2762 PFID(ll_inode2fid(inode)), inode);
2764 lli->lli_fid = body->mbo_fid1;
2768 LASSERT(fid_seq(&lli->lli_fid) != 0);
2770 /* In case of encrypted file without the key, please do not lose
2771 * clear text size stored into lli_lazysize in ll_merge_attr(),
2772 * we will need it in ll_prepare_close().
2774 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2775 llcrypt_require_key(inode) == -ENOKEY)
2776 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2778 lli->lli_attr_valid = body->mbo_valid;
2779 if (body->mbo_valid & OBD_MD_FLSIZE) {
2780 i_size_write(inode, body->mbo_size);
2782 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2783 PFID(ll_inode2fid(inode)),
2784 (unsigned long long)body->mbo_size);
2786 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2787 inode->i_blocks = body->mbo_blocks;
2789 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2790 lli->lli_lazysize = body->mbo_size;
2791 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2792 lli->lli_lazyblocks = body->mbo_blocks;
2795 if (body->mbo_valid & OBD_MD_TSTATE) {
2796 /* Set LLIF_FILE_RESTORING if restore ongoing and
2797 * clear it when done to ensure to start again
2798 * glimpsing updated attrs
2800 if (body->mbo_t_state & MS_RESTORE)
2801 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2803 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2809 /* child default LMV is inherited from parent */
2810 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2811 struct lmv_stripe_md *cdmv)
2816 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2817 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2818 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2819 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2822 if (cdmv->lsm_md_max_inherit !=
2823 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2826 if (cdmv->lsm_md_max_inherit_rr !=
2827 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2833 /* update directory depth to ROOT, called after LOOKUP lock is fetched. */
2834 void ll_update_dir_depth(struct inode *dir, struct inode *inode)
2836 struct ll_inode_info *plli;
2837 struct ll_inode_info *lli;
2839 if (!S_ISDIR(inode->i_mode))
2845 plli = ll_i2info(dir);
2846 lli = ll_i2info(inode);
2847 lli->lli_dir_depth = plli->lli_dir_depth + 1;
2848 if (plli->lli_default_lsm_md && lli->lli_default_lsm_md) {
2849 down_read(&plli->lli_lsm_sem);
2850 down_read(&lli->lli_lsm_sem);
2851 if (ll_default_lmv_inherited(plli->lli_default_lsm_md,
2852 lli->lli_default_lsm_md))
2853 lli->lli_inherit_depth =
2854 plli->lli_inherit_depth + 1;
2856 lli->lli_inherit_depth = 0;
2857 up_read(&lli->lli_lsm_sem);
2858 up_read(&plli->lli_lsm_sem);
2860 lli->lli_inherit_depth = 0;
2863 CDEBUG(D_INODE, DFID" depth %hu default LMV depth %hu\n",
2864 PFID(&lli->lli_fid), lli->lli_dir_depth, lli->lli_inherit_depth);
2867 void ll_truncate_inode_pages_final(struct inode *inode, struct cl_io *io)
2869 struct address_space *mapping = &inode->i_data;
2870 unsigned long nrpages;
2871 unsigned long flags;
2873 LASSERTF(io == NULL || inode_is_locked(inode), "io %p (type %d)\n",
2874 io, io ? io->ci_type : 0);
2876 truncate_inode_pages_final(mapping);
2878 /* Workaround for LU-118: Note nrpages may not be totally updated when
2879 * truncate_inode_pages() returns, as there can be a page in the process
2880 * of deletion (inside __delete_from_page_cache()) in the specified
2881 * range. Thus mapping->nrpages can be non-zero when this function
2882 * returns even after truncation of the whole mapping. Only do this if
2883 * npages isn't already zero.
2885 nrpages = mapping->nrpages;
2887 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2888 nrpages = mapping->nrpages;
2889 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2890 } /* Workaround end */
2892 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu "
2893 "io %p (io_type %d), "
2894 "see https://jira.whamcloud.com/browse/LU-118\n",
2895 ll_i2sbi(inode)->ll_fsname,
2896 PFID(ll_inode2fid(inode)), inode, nrpages,
2897 io, io ? io->ci_type : 0);
2900 int ll_read_inode2(struct inode *inode, void *opaque)
2902 struct lustre_md *md = opaque;
2903 struct ll_inode_info *lli = ll_i2info(inode);
2907 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2908 PFID(&lli->lli_fid), inode);
2910 /* Core attributes from the MDS first. This is a new inode, and
2911 * the VFS doesn't zero times in the core inode so we have to do
2912 * it ourselves. They will be overwritten by either MDS or OST
2913 * attributes - we just need to make sure they aren't newer.
2915 inode->i_mtime.tv_sec = 0;
2916 inode->i_atime.tv_sec = 0;
2917 inode->i_ctime.tv_sec = 0;
2919 rc = ll_update_inode(inode, md);
2923 /* OIDEBUG(inode); */
2925 #ifdef HAVE_BACKING_DEV_INFO
2926 /* initializing backing dev info. */
2927 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2929 if (S_ISREG(inode->i_mode)) {
2930 struct ll_sb_info *sbi = ll_i2sbi(inode);
2931 inode->i_op = &ll_file_inode_operations;
2932 inode->i_fop = sbi->ll_fop;
2933 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2935 } else if (S_ISDIR(inode->i_mode)) {
2936 inode->i_op = &ll_dir_inode_operations;
2937 inode->i_fop = &ll_dir_operations;
2939 } else if (S_ISLNK(inode->i_mode)) {
2940 inode->i_op = &ll_fast_symlink_inode_operations;
2943 inode->i_op = &ll_special_inode_operations;
2945 init_special_inode(inode, inode->i_mode,
2954 void ll_delete_inode(struct inode *inode)
2956 struct ll_inode_info *lli = ll_i2info(inode);
2959 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2960 /* It is last chance to write out dirty pages,
2961 * otherwise we may lose data while umount.
2963 * If i_nlink is 0 then just discard data. This is safe because
2964 * local inode gets i_nlink 0 from server only for the last
2965 * unlink, so that file is not opened somewhere else
2967 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2968 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2971 ll_truncate_inode_pages_final(inode, NULL);
2972 ll_clear_inode(inode);
2978 /* ioctl commands shared between files and directories */
2979 int ll_iocontrol(struct inode *inode, struct file *file,
2980 unsigned int cmd, void __user *uarg)
2982 struct ll_sb_info *sbi = ll_i2sbi(inode);
2983 struct ptlrpc_request *req = NULL;
2989 RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
2990 case FSFILT_IOC_GETVERSION:
2991 case FS_IOC_GETVERSION:
2992 RETURN(put_user(inode->i_generation, (int __user *)uarg));
2993 case FS_IOC_GETFLAGS: {
2994 struct mdt_body *body;
2995 struct md_op_data *op_data;
2997 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
2998 LUSTRE_OPC_ANY, NULL);
2999 if (IS_ERR(op_data))
3000 RETURN(PTR_ERR(op_data));
3002 op_data->op_valid = OBD_MD_FLFLAGS;
3003 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
3004 ll_finish_md_op_data(op_data);
3006 CERROR("%s: failure inode "DFID": rc = %d\n",
3007 sbi->ll_md_exp->exp_obd->obd_name,
3008 PFID(ll_inode2fid(inode)), rc);
3012 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3014 flags = body->mbo_flags;
3015 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
3016 * ext4 equivalent to please lsattr and other e2fsprogs tools
3018 if (flags & LUSTRE_ENCRYPT_FL)
3019 flags |= STATX_ATTR_ENCRYPTED;
3021 ptlrpc_req_finished(req);
3023 RETURN(put_user(flags, (int __user *)uarg));
3025 case FS_IOC_SETFLAGS: {
3027 struct md_op_data *op_data;
3028 struct cl_object *obj;
3029 struct fsxattr fa = { 0 };
3031 if (get_user(flags, (int __user *)uarg))
3034 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3035 if (flags & LUSTRE_PROJINHERIT_FL)
3036 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3038 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3043 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3044 LUSTRE_OPC_ANY, NULL);
3045 if (IS_ERR(op_data))
3046 RETURN(PTR_ERR(op_data));
3048 op_data->op_attr_flags = flags;
3049 op_data->op_xvalid |= OP_XVALID_FLAGS;
3050 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3051 ll_finish_md_op_data(op_data);
3052 ptlrpc_req_finished(req);
3056 ll_update_inode_flags(inode, flags);
3058 obj = ll_i2info(inode)->lli_clob;
3062 OBD_ALLOC_PTR(attr);
3066 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3071 case FS_IOC_FSGETXATTR:
3072 RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
3073 case FS_IOC_FSSETXATTR:
3074 RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
3075 case LL_IOC_PROJECT:
3076 RETURN(ll_ioctl_project(file, cmd, uarg));
3077 case IOC_OBD_STATFS:
3078 RETURN(ll_obd_statfs(inode, uarg));
3079 case LL_IOC_GET_MDTIDX: {
3080 rc = ll_get_mdt_idx(inode);
3084 if (put_user(rc, (int __user *)uarg))
3089 case LL_IOC_FLUSHCTX:
3090 RETURN(ll_flush_ctx(inode));
3091 #ifdef HAVE_LUSTRE_CRYPTO
3092 case LL_IOC_ADD_ENCRYPTION_KEY:
3093 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3095 rc = llcrypt_ioctl_add_key(file, uarg);
3096 #ifdef CONFIG_LL_ENCRYPTION
3097 if (!rc && S_ISDIR(inode->i_mode))
3098 sptlrpc_enc_pool_add_user();
3101 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
3102 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3104 RETURN(llcrypt_ioctl_get_key_status(file, uarg));
3105 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
3106 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3108 RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
3109 case LL_IOC_SET_ENCRYPTION_POLICY:
3110 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3112 RETURN(llcrypt_ioctl_set_policy(file, uarg));
3113 case LL_IOC_REMOVE_ENCRYPTION_KEY:
3114 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3116 RETURN(llcrypt_ioctl_remove_key(file, uarg));
3117 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
3118 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3120 RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
3122 case LL_IOC_GETPARENT:
3123 RETURN(ll_getparent(file, uarg));
3124 case LL_IOC_PATH2FID:
3125 if (copy_to_user(uarg, ll_inode2fid(inode),
3126 sizeof(struct lu_fid)))
3129 case LL_IOC_UNLOCK_FOREIGN: {
3130 struct dentry *dentry = file_dentry(file);
3132 /* if not a foreign symlink do nothing */
3133 if (ll_foreign_is_removable(dentry, true)) {
3135 "prevent unlink of non-foreign file ("DFID")\n",
3136 PFID(ll_inode2fid(inode)));
3137 RETURN(-EOPNOTSUPP);
3141 case OBD_IOC_FID2PATH:
3142 RETURN(ll_fid2path(inode, uarg));
3143 case OBD_IOC_GETNAME_OLD:
3144 case OBD_IOC_GETDTNAME:
3145 case OBD_IOC_GETMDNAME:
3146 RETURN(ll_get_obd_name(inode, cmd, uarg));
3154 int ll_flush_ctx(struct inode *inode)
3156 struct ll_sb_info *sbi = ll_i2sbi(inode);
3158 CDEBUG(D_SEC, "flush context for user %d\n",
3159 from_kuid(&init_user_ns, current_uid()));
3161 obd_set_info_async(NULL, sbi->ll_md_exp,
3162 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3164 obd_set_info_async(NULL, sbi->ll_dt_exp,
3165 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3170 /* umount -f client means force down, don't save state */
3171 void ll_umount_begin(struct super_block *sb)
3173 struct ll_sb_info *sbi = ll_s2sbi(sb);
3174 struct obd_device *obd;
3175 struct obd_ioctl_data *ioc_data;
3179 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3180 sb->s_count, atomic_read(&sb->s_active));
3182 obd = class_exp2obd(sbi->ll_md_exp);
3184 CERROR("Invalid MDC connection handle %#llx\n",
3185 sbi->ll_md_exp->exp_handle.h_cookie);
3191 obd = class_exp2obd(sbi->ll_dt_exp);
3193 CERROR("Invalid LOV connection handle %#llx\n",
3194 sbi->ll_dt_exp->exp_handle.h_cookie);
3200 OBD_ALLOC_PTR(ioc_data);
3202 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
3203 sizeof *ioc_data, ioc_data, NULL);
3205 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
3206 sizeof *ioc_data, ioc_data, NULL);
3208 OBD_FREE_PTR(ioc_data);
3211 /* Really, we'd like to wait until there are no requests outstanding,
3212 * and then continue. For now, we just periodically checking for vfs
3213 * to decrement mnt_cnt and hope to finish it within 10sec.
3217 !may_umount(sbi->ll_mnt.mnt)) {
3225 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3227 struct ll_sb_info *sbi = ll_s2sbi(sb);
3228 char *profilenm = get_profile_name(sb);
3232 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3233 read_only = *flags & MS_RDONLY;
3234 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3235 sizeof(KEY_READ_ONLY),
3236 KEY_READ_ONLY, sizeof(read_only),
3239 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3240 profilenm, read_only ?
3241 "read-only" : "read-write", err);
3246 sb->s_flags |= SB_RDONLY;
3248 sb->s_flags &= ~SB_RDONLY;
3250 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3251 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3252 read_only ? "read-only" : "read-write");
3258 * Cleanup the open handle that is cached on MDT-side.
3260 * For open case, the client side open handling thread may hit error
3261 * after the MDT grant the open. Under such case, the client should
3262 * send close RPC to the MDT as cleanup; otherwise, the open handle
3263 * on the MDT will be leaked there until the client umount or evicted.
3265 * In further, if someone unlinked the file, because the open handle
3266 * holds the reference on such file/object, then it will block the
3267 * subsequent threads that want to locate such object via FID.
3269 * \param[in] sb super block for this file-system
3270 * \param[in] open_req pointer to the original open request
3272 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3274 struct mdt_body *body;
3275 struct md_op_data *op_data;
3276 struct ptlrpc_request *close_req = NULL;
3277 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3280 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3281 OBD_ALLOC_PTR(op_data);
3282 if (op_data == NULL) {
3283 CWARN("%s: cannot allocate op_data to release open handle for "
3284 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3289 op_data->op_fid1 = body->mbo_fid1;
3290 op_data->op_open_handle = body->mbo_open_handle;
3291 op_data->op_mod_time = ktime_get_real_seconds();
3292 md_close(exp, op_data, NULL, &close_req);
3293 ptlrpc_req_finished(close_req);
3294 ll_finish_md_op_data(op_data);
3299 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3300 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3301 struct lustre_md *md)
3303 struct ll_sb_info *sbi = ll_i2sbi(inode);
3304 struct ptlrpc_request *req = NULL;
3305 union lmv_mds_md *lmm = NULL;
3309 LASSERT(is_root_inode(inode));
3310 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3311 LASSERT(!md->default_lmv);
3313 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3315 GET_DEFAULT_LAYOUT_ROOT);
3316 if (rc && rc != -ENODATA)
3321 rc = md_unpackmd(sbi->ll_md_exp, &md->default_lmv, lmm, size);
3330 ptlrpc_req_finished(req);
3334 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3335 struct super_block *sb, struct lookup_intent *it)
3337 struct ll_sb_info *sbi = NULL;
3338 struct lustre_md md = { NULL };
3339 bool default_lmv_deleted = false;
3344 LASSERT(*inode || sb);
3345 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3346 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3347 sbi->ll_md_exp, &md);
3352 * clear default_lmv only if intent_getattr reply doesn't contain it.
3353 * but it needs to be done after iget, check this early because
3354 * ll_update_lsm_md() may change md.
3356 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3357 S_ISDIR(md.body->mbo_mode) && !md.default_lmv) {
3358 if (unlikely(*inode && is_root_inode(*inode) &&
3359 !fid_is_root(&sbi->ll_root_fid))) {
3360 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3365 if (!md.default_lmv)
3366 default_lmv_deleted = true;
3370 rc = ll_update_inode(*inode, &md);
3374 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3375 struct lu_fid *fid1 = &md.body->mbo_fid1;
3377 LASSERT(sb != NULL);
3380 * At this point server returns to client's same fid as client
3381 * generated for creating. So using ->fid1 is okay here.
3383 if (!fid_is_sane(fid1)) {
3384 CERROR("%s: Fid is insane "DFID"\n",
3385 sbi->ll_fsname, PFID(fid1));
3386 GOTO(out, rc = -EINVAL);
3389 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3390 if (IS_ERR(*inode)) {
3392 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3394 CERROR("new_inode -fatal: rc %d\n", rc);
3399 /* Handling piggyback layout lock.
3400 * Layout lock can be piggybacked by getattr and open request.
3401 * The lsm can be applied to inode only if it comes with a layout lock
3402 * otherwise correct layout may be overwritten, for example:
3403 * 1. proc1: mdt returns a lsm but not granting layout
3404 * 2. layout was changed by another client
3405 * 3. proc2: refresh layout and layout lock granted
3406 * 4. proc1: to apply a stale layout */
3407 if (it != NULL && it->it_lock_mode != 0) {
3408 struct lustre_handle lockh;
3409 struct ldlm_lock *lock;
3411 lockh.cookie = it->it_lock_handle;
3412 lock = ldlm_handle2lock(&lockh);
3413 LASSERT(lock != NULL);
3414 if (ldlm_has_layout(lock)) {
3415 struct cl_object_conf conf;
3417 memset(&conf, 0, sizeof(conf));
3418 conf.coc_opc = OBJECT_CONF_SET;
3419 conf.coc_inode = *inode;
3420 conf.coc_lock = lock;
3421 conf.u.coc_layout = md.layout;
3422 (void)ll_layout_conf(*inode, &conf);
3424 LDLM_LOCK_PUT(lock);
3427 if (default_lmv_deleted)
3428 ll_update_default_lsm_md(*inode, &md);
3430 /* we may want to apply some policy for foreign file/dir */
3431 if (ll_sbi_has_foreign_symlink(sbi)) {
3432 rc = ll_manage_foreign(*inode, &md);
3440 /* cleanup will be done if necessary */
3441 md_free_lustre_md(sbi->ll_md_exp, &md);
3443 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3444 ll_intent_drop_lock(it);
3445 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3451 int ll_obd_statfs(struct inode *inode, void __user *uarg)
3453 struct ll_sb_info *sbi = NULL;
3454 struct obd_export *exp;
3455 struct obd_ioctl_data *data = NULL;
3460 sbi = ll_i2sbi(inode);
3462 GOTO(out_statfs, rc = -EINVAL);
3464 rc = obd_ioctl_getdata(&data, &len, uarg);
3466 GOTO(out_statfs, rc);
3468 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3469 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3470 GOTO(out_statfs, rc = -EINVAL);
3472 if (data->ioc_inllen1 != sizeof(__u32) ||
3473 data->ioc_inllen2 != sizeof(__u32) ||
3474 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3475 data->ioc_plen2 != sizeof(struct obd_uuid))
3476 GOTO(out_statfs, rc = -EINVAL);
3478 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3479 if (type & LL_STATFS_LMV)
3480 exp = sbi->ll_md_exp;
3481 else if (type & LL_STATFS_LOV)
3482 exp = sbi->ll_dt_exp;
3484 GOTO(out_statfs, rc = -ENODEV);
3486 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3488 GOTO(out_statfs, rc);
3490 OBD_FREE_LARGE(data, len);
3495 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3496 * be called early to avoid deadlock.
3498 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3500 if (op_data->op_mea2_sem) {
3501 up_read_non_owner(op_data->op_mea2_sem);
3502 op_data->op_mea2_sem = NULL;
3505 if (op_data->op_mea1_sem) {
3506 up_read_non_owner(op_data->op_mea1_sem);
3507 op_data->op_mea1_sem = NULL;
3511 /* this function prepares md_op_data hint for passing it down to MD stack. */
3512 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3513 struct inode *i1, struct inode *i2,
3514 const char *name, size_t namelen,
3515 __u32 mode, enum md_op_code opc,
3518 struct llcrypt_name fname = { 0 };
3521 LASSERT(i1 != NULL);
3524 /* Do not reuse namelen for something else. */
3526 return ERR_PTR(-EINVAL);
3528 if ((!IS_ENCRYPTED(i1) ||
3529 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3530 namelen > ll_i2sbi(i1)->ll_namelen)
3531 return ERR_PTR(-ENAMETOOLONG);
3533 /* "/" is not valid name, but it's allowed */
3534 if (!lu_name_is_valid_2(name, namelen) &&
3535 strncmp("/", name, namelen) != 0)
3536 return ERR_PTR(-EINVAL);
3539 if (op_data == NULL)
3540 OBD_ALLOC_PTR(op_data);
3542 if (op_data == NULL)
3543 return ERR_PTR(-ENOMEM);
3545 ll_i2gids(op_data->op_suppgids, i1, i2);
3546 /* If the client is using a subdir mount and looks at what it sees as
3547 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3549 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3550 !fid_is_root(ll_inode2fid(i1)) &&
3551 name && namelen == strlen(dot_fscrypt_name) &&
3552 strncmp(name, dot_fscrypt_name, namelen) == 0))
3553 lu_root_fid(&op_data->op_fid1);
3555 op_data->op_fid1 = *ll_inode2fid(i1);
3557 if (S_ISDIR(i1->i_mode)) {
3558 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3559 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3560 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3561 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3565 op_data->op_fid2 = *ll_inode2fid(i2);
3566 if (S_ISDIR(i2->i_mode)) {
3568 /* i2 is typically a child of i1, and MUST be
3569 * further from the root to avoid deadlocks.
3571 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3572 op_data->op_mea2_sem =
3573 &ll_i2info(i2)->lli_lsm_sem;
3575 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3578 fid_zero(&op_data->op_fid2);
3581 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3582 op_data->op_cli_flags |= CLI_HASH64;
3584 if (ll_need_32bit_api(ll_i2sbi(i1)))
3585 op_data->op_cli_flags |= CLI_API32;
3587 if ((i2 && is_root_inode(i2)) ||
3588 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3589 /* In case of lookup, ll_setup_filename() has already been
3590 * called in ll_lookup_it(), so just take provided name.
3591 * Also take provided name if we are dealing with root inode.
3593 fname.disk_name.name = (unsigned char *)name;
3594 fname.disk_name.len = namelen;
3595 } else if (name && namelen) {
3596 struct qstr dname = QSTR_INIT(name, namelen);
3598 struct lu_fid *pfid = NULL;
3602 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3603 /* special case when called from ll_link() */
3608 lookup = (int)(opc == LUSTRE_OPC_ANY);
3610 if (opc == LUSTRE_OPC_ANY && lookup)
3612 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3614 ll_finish_md_op_data(op_data);
3617 if (pfid && !fid_is_zero(pfid)) {
3619 op_data->op_fid2 = fid;
3620 op_data->op_bias = MDS_FID_OP;
3622 if (fname.disk_name.name &&
3623 fname.disk_name.name != (unsigned char *)name) {
3624 /* op_data->op_name must be freed after use */
3625 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3629 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3630 * are LUSTRE_OPC_ANY
3632 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3633 op_data->op_code = LUSTRE_OPC_ANY;
3635 op_data->op_code = opc;
3636 op_data->op_name = fname.disk_name.name;
3637 op_data->op_namelen = fname.disk_name.len;
3638 op_data->op_mode = mode;
3639 op_data->op_mod_time = ktime_get_real_seconds();
3640 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3641 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3642 op_data->op_cap = current_cap();
3643 op_data->op_mds = 0;
3644 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3645 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3646 op_data->op_bias |= MDS_CREATE_VOLATILE;
3648 op_data->op_data = data;
3653 void ll_finish_md_op_data(struct md_op_data *op_data)
3655 ll_unlock_md_op_lsm(op_data);
3656 ll_security_release_secctx(op_data->op_file_secctx,
3657 op_data->op_file_secctx_size);
3658 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3659 /* allocated via ll_setup_filename called
3660 * from ll_prep_md_op_data
3662 kfree(op_data->op_name);
3663 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3664 OBD_FREE_PTR(op_data);
3667 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3669 struct ll_sb_info *sbi;
3672 LASSERT(seq && dentry);
3673 sbi = ll_s2sbi(dentry->d_sb);
3675 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3676 seq_puts(seq, "nolock");
3678 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3679 /* match_table in some cases has patterns for both enabled and
3680 * disabled cases. Ignore 'no'xxx versions if bit is set.
3682 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3683 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3684 if (ll_sbi_flags_name[i].token ==
3685 LL_SBI_FOREIGN_SYMLINK) {
3686 seq_show_option(seq, "foreign_symlink",
3687 sbi->ll_foreign_symlink_prefix);
3689 seq_printf(seq, ",%s",
3690 ll_sbi_flags_name[i].pattern);
3693 /* You can have either localflock or flock but not
3694 * both. If localflock is set don't print flock or
3697 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3699 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3700 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3701 seq_printf(seq, ",%s",
3702 ll_sbi_flags_name[i].pattern);
3706 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3712 * Get obd name by cmd, and copy out to user space
3714 int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg)
3716 struct ll_sb_info *sbi = ll_i2sbi(inode);
3717 struct obd_device *obd;
3720 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3721 obd = class_exp2obd(sbi->ll_dt_exp);
3722 else if (cmd == OBD_IOC_GETMDNAME)
3723 obd = class_exp2obd(sbi->ll_md_exp);
3730 if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1))
3737 struct work_struct db_work;
3738 struct dentry *db_dentry;
3739 /* Let's hope the path is not too long, 32 bytes for the work struct
3742 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3745 static void ll_dput_later(struct work_struct *work)
3747 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3749 dput(db->db_dentry);
3750 free_page((unsigned long)db);
3753 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3760 p.mnt = current->fs->root.mnt;
3762 path = d_path(&p, buf, bufsize);
3767 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3769 struct dname_buf *db;
3771 struct dentry *dentry = NULL;
3773 /* this can be called inside spin lock so use GFP_ATOMIC. */
3774 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3777 dentry = d_find_alias(inode);
3779 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3782 /* The below message is checked in recovery-small.sh test_24b */
3784 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3785 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3786 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3787 PFID(ll_inode2fid(inode)),
3788 (path && !IS_ERR(path)) ? path : "", ioret);
3790 if (dentry != NULL) {
3791 /* We cannot dput here since if we happen to be the last holder
3792 * then we can end up waiting for page evictions that
3793 * in turn wait for RPCs that need this instance of ptlrpcd
3794 * (callng brw_interpret->*page_completion*->vmpage_error->here)
3797 INIT_WORK(&db->db_work, ll_dput_later);
3798 db->db_dentry = dentry;
3799 schedule_work(&db->db_work);
3802 free_page((unsigned long)db);
3806 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3807 struct lov_user_md **kbuf)
3809 struct lov_user_md lum;
3813 if (copy_from_user(&lum, md, sizeof(lum)))
3816 lum_size = ll_lov_user_md_size(&lum);
3820 OBD_ALLOC_LARGE(*kbuf, lum_size);
3824 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3825 OBD_FREE_LARGE(*kbuf, lum_size);
3833 * Compute llite root squash state after a change of root squash
3834 * configuration setting or add/remove of a lnet nid
3836 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3838 struct root_squash_info *squash = &sbi->ll_squash;
3841 struct lnet_processid id;
3843 /* Update norootsquash flag */
3844 spin_lock(&squash->rsi_lock);
3845 if (list_empty(&squash->rsi_nosquash_nids))
3846 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3848 /* Do not apply root squash as soon as one of our NIDs is
3849 * in the nosquash_nids list */
3852 while (LNetGetId(i++, &id) != -ENOENT) {
3853 if (nid_is_lo0(&id.nid))
3855 if (cfs_match_nid(lnet_nid_to_nid4(&id.nid),
3856 &squash->rsi_nosquash_nids)) {
3862 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3864 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3866 spin_unlock(&squash->rsi_lock);
3870 * Parse linkea content to extract information about a given hardlink
3872 * \param[in] ldata - Initialized linkea data
3873 * \param[in] linkno - Link identifier
3874 * \param[out] parent_fid - The entry's parent FID
3875 * \param[out] ln - Entry name destination buffer
3877 * \retval 0 on success
3878 * \retval Appropriate negative error code on failure
3880 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3881 struct lu_fid *parent_fid, struct lu_name *ln)
3887 rc = linkea_init_with_rec(ldata);
3891 if (linkno >= ldata->ld_leh->leh_reccount)
3892 /* beyond last link */
3895 linkea_first_entry(ldata);
3896 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3897 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3902 linkea_next_entry(ldata);
3912 * Get parent FID and name of an identified link. Operation is performed for
3913 * a given link number, letting the caller iterate over linkno to list one or
3914 * all links of an entry.
3916 * \param[in] file - File descriptor against which to perform the operation
3917 * \param[in,out] arg - User-filled structure containing the linkno to operate
3918 * on and the available size. It is eventually filled with
3919 * the requested information or left untouched on error
3921 * \retval - 0 on success
3922 * \retval - Appropriate negative error code on failure
3924 int ll_getparent(struct file *file, struct getparent __user *arg)
3926 struct inode *inode = file_inode(file);
3927 struct linkea_data *ldata;
3928 struct lu_buf buf = LU_BUF_NULL;
3930 struct lu_fid parent_fid;
3937 if (!capable(CAP_DAC_READ_SEARCH) &&
3938 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
3941 if (get_user(name_size, &arg->gp_name_size))
3944 if (get_user(linkno, &arg->gp_linkno))
3947 if (name_size > PATH_MAX)
3950 OBD_ALLOC(ldata, sizeof(*ldata));
3954 rc = linkea_data_new(ldata, &buf);
3956 GOTO(ldata_free, rc);
3958 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3959 buf.lb_len, OBD_MD_FLXATTR);
3963 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3967 if (ln.ln_namelen >= name_size)
3968 GOTO(lb_free, rc = -EOVERFLOW);
3970 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3971 GOTO(lb_free, rc = -EFAULT);
3973 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3974 GOTO(lb_free, rc = -EFAULT);
3976 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3977 GOTO(lb_free, rc = -EFAULT);
3982 OBD_FREE(ldata, sizeof(*ldata));