4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/llite/llite_lib.c
33 * Lustre Light Super operations
36 #define DEBUG_SUBSYSTEM S_LLITE
38 #include <linux/cpu.h>
39 #include <linux/delay.h>
40 #include <linux/file.h>
41 #include <linux/fs_struct.h>
43 #include <linux/module.h>
44 #include <linux/random.h>
45 #include <linux/statfs.h>
46 #include <linux/time.h>
47 #include <linux/types.h>
48 #include <linux/uaccess.h>
49 #include <linux/uidgid.h>
50 #include <linux/user_namespace.h>
51 #include <linux/uuid.h>
52 #include <linux/version.h>
54 #ifndef HAVE_CPUS_READ_LOCK
55 #include <libcfs/linux/linux-cpu.h>
57 #include <libcfs/linux/linux-misc.h>
58 #include <uapi/linux/lustre/lustre_ioctl.h>
59 #ifdef HAVE_UAPI_LINUX_MOUNT_H
60 #include <uapi/linux/mount.h>
63 #include <lustre_ha.h>
64 #include <lustre_dlm.h>
65 #include <lprocfs_status.h>
66 #include <lustre_disk.h>
67 #include <uapi/linux/lustre/lustre_param.h>
68 #include <lustre_log.h>
69 #include <cl_object.h>
70 #include <obd_cksum.h>
71 #include "llite_internal.h"
73 struct kmem_cache *ll_file_data_slab;
76 #define log2(n) ffz(~(n))
80 * If there is only one number of core visible to Lustre,
81 * async readahead will be disabled, to avoid massive over
82 * subscription, we use 1/2 of active cores as default max
83 * async readahead requests.
85 static inline unsigned int ll_get_ra_async_max_active(void)
87 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
90 static struct ll_sb_info *ll_init_sbi(struct lustre_sb_info *lsi)
92 struct ll_sb_info *sbi = NULL;
94 unsigned long lru_page_max;
102 RETURN(ERR_PTR(-ENOMEM));
104 rc = pcc_super_init(&sbi->ll_pcc_super);
108 spin_lock_init(&sbi->ll_lock);
109 mutex_init(&sbi->ll_lco.lco_lock);
110 spin_lock_init(&sbi->ll_pp_extent_lock);
111 spin_lock_init(&sbi->ll_process_lock);
113 sbi->ll_rw_stats_on = 0;
114 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
117 pages = si.totalram - si.totalhigh;
118 lru_page_max = pages / 2;
120 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
121 sbi->ll_ra_info.ll_readahead_wq =
122 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
124 sbi->ll_ra_info.ra_async_max_active);
125 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
126 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
128 /* initialize ll_cache data */
129 sbi->ll_cache = cl_cache_init(lru_page_max);
130 if (sbi->ll_cache == NULL)
131 GOTO(out_destroy_ra, rc = -ENOMEM);
133 /* initialize foreign symlink prefix path */
134 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
135 if (sbi->ll_foreign_symlink_prefix == NULL)
136 GOTO(out_destroy_ra, rc = -ENOMEM);
137 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
138 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
140 /* initialize foreign symlink upcall path, none by default */
141 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
142 if (sbi->ll_foreign_symlink_upcall == NULL)
143 GOTO(out_destroy_ra, rc = -ENOMEM);
144 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
145 sbi->ll_foreign_symlink_upcall_items = NULL;
146 sbi->ll_foreign_symlink_upcall_nb_items = 0;
147 init_rwsem(&sbi->ll_foreign_symlink_sem);
148 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
149 * not enabled by default
152 sbi->ll_secctx_name = NULL;
153 sbi->ll_secctx_name_size = 0;
155 sbi->ll_ra_info.ra_max_pages =
156 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
157 sbi->ll_ra_info.ra_max_pages_per_file =
158 min(sbi->ll_ra_info.ra_max_pages / 4,
159 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
160 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
161 sbi->ll_ra_info.ra_max_pages_per_file;
162 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
163 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
164 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
166 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
167 #ifdef ENABLE_CHECKSUM
168 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
171 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
174 #ifdef HAVE_LRU_RESIZE_SUPPORT
175 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
177 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
179 /* metadata statahead is enabled by default */
180 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
181 sbi->ll_sa_batch_max = LL_SA_BATCH_DEF;
182 sbi->ll_sa_max = LL_SA_RPC_DEF;
183 atomic_set(&sbi->ll_sa_total, 0);
184 atomic_set(&sbi->ll_sa_wrong, 0);
185 atomic_set(&sbi->ll_sa_running, 0);
186 atomic_set(&sbi->ll_agl_total, 0);
187 atomic_set(&sbi->ll_sa_hit_total, 0);
188 atomic_set(&sbi->ll_sa_miss_total, 0);
189 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
190 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
191 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
192 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
193 ll_sbi_set_encrypt(sbi, true);
194 ll_sbi_set_name_encrypt(sbi, true);
197 sbi->ll_squash.rsi_uid = 0;
198 sbi->ll_squash.rsi_gid = 0;
199 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
200 spin_lock_init(&sbi->ll_squash.rsi_lock);
202 /* Per-filesystem file heat */
203 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
204 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
206 /* Per-fs open heat level before requesting open lock */
207 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
208 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
209 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
212 if (sbi->ll_foreign_symlink_prefix)
213 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
215 cl_cache_decref(sbi->ll_cache);
216 sbi->ll_cache = NULL;
218 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
220 pcc_super_fini(&sbi->ll_pcc_super);
226 static void ll_free_sbi(struct super_block *sb)
228 struct ll_sb_info *sbi = ll_s2sbi(sb);
232 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
233 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
234 if (sbi->ll_ra_info.ll_readahead_wq)
235 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
236 if (sbi->ll_cache != NULL) {
237 cl_cache_decref(sbi->ll_cache);
238 sbi->ll_cache = NULL;
240 if (sbi->ll_foreign_symlink_prefix) {
241 OBD_FREE(sbi->ll_foreign_symlink_prefix,
242 sbi->ll_foreign_symlink_prefix_size);
243 sbi->ll_foreign_symlink_prefix = NULL;
245 if (sbi->ll_foreign_symlink_upcall) {
246 OBD_FREE(sbi->ll_foreign_symlink_upcall,
247 strlen(sbi->ll_foreign_symlink_upcall) +
249 sbi->ll_foreign_symlink_upcall = NULL;
251 if (sbi->ll_foreign_symlink_upcall_items) {
253 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
254 struct ll_foreign_symlink_upcall_item *items =
255 sbi->ll_foreign_symlink_upcall_items;
257 for (i = 0 ; i < nb_items; i++)
258 if (items[i].type == STRING_TYPE)
259 OBD_FREE(items[i].string,
262 OBD_FREE_LARGE(items, nb_items *
263 sizeof(struct ll_foreign_symlink_upcall_item));
264 sbi->ll_foreign_symlink_upcall_items = NULL;
266 if (sbi->ll_secctx_name)
267 ll_secctx_name_free(sbi);
269 ll_free_rw_stats_info(sbi);
270 pcc_super_fini(&sbi->ll_pcc_super);
271 OBD_FREE(sbi, sizeof(*sbi));
276 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
278 struct inode *root = NULL;
279 struct ll_sb_info *sbi = ll_s2sbi(sb);
280 struct obd_statfs *osfs = NULL;
281 struct ptlrpc_request *request = NULL;
282 struct obd_connect_data *data = NULL;
283 struct obd_uuid *uuid;
284 struct md_op_data *op_data;
285 struct lustre_md lmd;
287 int size, err, checksum;
293 sbi->ll_md_obd = class_name2obd(md);
294 if (!sbi->ll_md_obd) {
295 CERROR("MD %s: not setup or attached\n", md);
309 /* pass client page size via ocd_grant_blkbits, the server should report
310 * back its backend blocksize for grant calculation purpose */
311 data->ocd_grant_blkbits = PAGE_SHIFT;
313 /* indicate MDT features supported by this client */
314 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
315 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
316 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
317 OBD_CONNECT_SRVLOCK |
318 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
319 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
320 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
321 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
322 OBD_CONNECT_64BITHASH |
323 OBD_CONNECT_EINPROGRESS |
324 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
325 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
326 OBD_CONNECT_MAX_EASIZE |
327 OBD_CONNECT_FLOCK_DEAD |
328 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
329 OBD_CONNECT_OPEN_BY_FID |
330 OBD_CONNECT_DIR_STRIPE |
331 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
332 OBD_CONNECT_SUBTREE |
333 OBD_CONNECT_MULTIMODRPCS |
334 OBD_CONNECT_GRANT_PARAM |
335 OBD_CONNECT_GRANT_SHRINK |
336 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
338 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
339 OBD_CONNECT2_SUM_STATFS |
340 OBD_CONNECT2_OVERSTRIPING |
342 OBD_CONNECT2_LOCK_CONVERT |
343 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
344 OBD_CONNECT2_INC_XID |
346 OBD_CONNECT2_ASYNC_DISCARD |
348 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
349 OBD_CONNECT2_GETATTR_PFID |
350 OBD_CONNECT2_DOM_LVB |
351 OBD_CONNECT2_REP_MBITS |
352 OBD_CONNECT2_ATOMIC_OPEN_LOCK |
353 OBD_CONNECT2_BATCH_RPC;
355 #ifdef HAVE_LRU_RESIZE_SUPPORT
356 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
357 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
359 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
361 data->ocd_cksum_types = obd_cksum_types_supported_client();
363 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
364 /* flag mdc connection as lightweight, only used for test
365 * purpose, use with care */
366 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
368 data->ocd_ibits_known = MDS_INODELOCK_FULL;
369 data->ocd_version = LUSTRE_VERSION_CODE;
371 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
372 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
375 /* Setting this indicates we correctly support S_NOSEC (See kernel
376 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
378 sb->s_flags |= SB_NOSEC;
380 sbi->ll_fop = ll_select_file_operations(sbi);
382 /* always ping even if server suppress_pings */
383 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
384 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
386 obd_connect_set_secctx(data);
387 if (ll_sbi_has_encrypt(sbi)) {
388 obd_connect_set_enc_fid2path(data);
389 obd_connect_set_name_enc(data);
390 obd_connect_set_enc(data);
393 #if defined(CONFIG_SECURITY)
394 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
397 data->ocd_brw_size = MD_MAX_BRW_SIZE;
400 if (sb->s_flags & SB_RDONLY)
401 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
402 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
403 &sbi->ll_sb_uuid, data, sbi->ll_cache);
405 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
406 "recovery, of which this client is not a "
407 "part. Please wait for recovery to complete,"
408 " abort, or time out.\n", md);
411 CERROR("cannot connect to %s: rc = %d\n", md, err);
415 sbi->ll_md_exp->exp_connect_data = *data;
417 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
418 LUSTRE_SEQ_METADATA);
420 CERROR("%s: Can't init metadata layer FID infrastructure, "
421 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
425 /* For mount, we only need fs info from MDT0, and also in DNE, it
426 * can make sure the client can be mounted as long as MDT0 is
428 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
429 ktime_get_seconds() - sbi->ll_statfs_max_age,
430 OBD_STATFS_FOR_MDT0);
431 if (err == -EROFS && !(sb->s_flags & SB_RDONLY)) {
432 /* We got -EROFS from the server, maybe it is imposing
433 * read-only mount. So just retry like this.
435 cfs_tty_write_msg("Forcing read-only mount.\n\r");
436 CERROR("%s: mount failed with %d, forcing read-only mount.\n",
437 sbi->ll_md_exp->exp_obd->obd_name, err);
438 sb->s_flags |= SB_RDONLY;
439 obd_fid_fini(sbi->ll_md_exp->exp_obd);
440 obd_disconnect(sbi->ll_md_exp);
441 GOTO(retry_connect, err);
443 GOTO(out_md_fid, err);
446 /* This needs to be after statfs to ensure connect has finished.
447 * Note that "data" does NOT contain the valid connect reply.
448 * If connecting to a 1.8 server there will be no LMV device, so
449 * we can access the MDC export directly and exp_connect_flags will
450 * be non-zero, but if accessing an upgraded 2.1 server it will
451 * have the correct flags filled in.
452 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
453 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
454 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
455 valid != CLIENT_CONNECT_MDT_REQD) {
458 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
459 obd_connect_flags2str(buf, PAGE_SIZE,
460 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
461 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
462 "feature(s) needed for correct operation "
463 "of this client (%s). Please upgrade "
464 "server or downgrade client.\n",
465 sbi->ll_md_exp->exp_obd->obd_name, buf);
466 OBD_FREE(buf, PAGE_SIZE);
467 GOTO(out_md_fid, err = -EPROTO);
470 size = sizeof(*data);
471 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
472 KEY_CONN_DATA, &size, data);
474 CERROR("%s: Get connect data failed: rc = %d\n",
475 sbi->ll_md_exp->exp_obd->obd_name, err);
476 GOTO(out_md_fid, err);
479 LASSERT(osfs->os_bsize);
480 sb->s_blocksize = osfs->os_bsize;
481 sb->s_blocksize_bits = log2(osfs->os_bsize);
482 sb->s_magic = LL_SUPER_MAGIC;
483 sb->s_maxbytes = MAX_LFS_FILESIZE;
484 sbi->ll_inode_cache_enabled = 1;
485 sbi->ll_namelen = osfs->os_namelen;
486 sbi->ll_mnt.mnt = current->fs->root.mnt;
487 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
489 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
490 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
491 LCONSOLE_INFO("Disabling user_xattr feature because "
492 "it is not supported on the server\n");
493 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
496 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
498 sb->s_flags |= SB_POSIXACL;
500 set_bit(LL_SBI_ACL, sbi->ll_flags);
502 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
504 sb->s_flags &= ~SB_POSIXACL;
506 clear_bit(LL_SBI_ACL, sbi->ll_flags);
509 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
510 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
512 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
513 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
515 if (obd_connect_has_secctx(data))
516 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
518 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
519 if (ll_sb_has_test_dummy_encryption(sb))
520 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
522 sbi->ll_md_exp->exp_obd->obd_name);
523 ll_sbi_set_encrypt(sbi, false);
526 if (ll_sbi_has_name_encrypt(sbi) && !obd_connect_has_name_enc(data)) {
527 struct lustre_sb_info *lsi = s2lsi(sb);
529 if (ll_sb_has_test_dummy_encryption(sb))
530 LCONSOLE_WARN("%s: server %s does not support name encryption, not using it.\n",
532 sbi->ll_md_exp->exp_obd->obd_name);
533 #ifdef CONFIG_LL_ENCRYPTION
534 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
536 lsi->lsi_flags &= ~LSI_FILENAME_ENC_B64_OLD_CLI;
537 ll_sbi_set_name_encrypt(sbi, false);
540 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
541 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
542 LCONSOLE_INFO("%s: disabling xattr cache due to "
543 "unknown maximum xattr size.\n", dt);
544 } else if (!sbi->ll_xattr_cache_set) {
545 /* If xattr_cache is already set (no matter 0 or 1)
546 * during processing llog, it won't be enabled here. */
547 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
548 sbi->ll_xattr_cache_enabled = 1;
552 sbi->ll_dt_obd = class_name2obd(dt);
553 if (!sbi->ll_dt_obd) {
554 CERROR("DT %s: not setup or attached\n", dt);
555 GOTO(out_md_fid, err = -ENODEV);
558 /* pass client page size via ocd_grant_blkbits, the server should report
559 * back its backend blocksize for grant calculation purpose */
560 data->ocd_grant_blkbits = PAGE_SHIFT;
562 /* indicate OST features supported by this client */
563 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
564 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
565 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
566 OBD_CONNECT_SRVLOCK |
567 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
568 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
569 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
570 OBD_CONNECT_EINPROGRESS |
571 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
572 OBD_CONNECT_LAYOUTLOCK |
573 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
574 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
575 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
576 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
577 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
578 OBD_CONNECT2_REP_MBITS;
580 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
581 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
583 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
584 * disabled by default, because it can still be enabled on the
585 * fly via /sys. As a consequence, we still need to come to an
586 * agreement on the supported algorithms at connect time
588 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
590 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
591 data->ocd_cksum_types = OBD_CKSUM_ADLER;
593 data->ocd_cksum_types = obd_cksum_types_supported_client();
595 #ifdef HAVE_LRU_RESIZE_SUPPORT
596 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
598 /* always ping even if server suppress_pings */
599 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
600 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
602 if (ll_sbi_has_encrypt(sbi))
603 obd_connect_set_enc(data);
605 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
606 "ocd_grant: %d\n", data->ocd_connect_flags,
607 data->ocd_version, data->ocd_grant);
609 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
610 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
612 data->ocd_brw_size = DT_MAX_BRW_SIZE;
614 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
615 &sbi->ll_sb_uuid, data, sbi->ll_cache);
617 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
618 "recovery, of which this client is not a "
619 "part. Please wait for recovery to "
620 "complete, abort, or time out.\n", dt);
623 CERROR("%s: Cannot connect to %s: rc = %d\n",
624 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
628 if (ll_sbi_has_encrypt(sbi) &&
629 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
630 if (ll_sb_has_test_dummy_encryption(sb))
631 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
633 ll_sbi_set_encrypt(sbi, false);
634 } else if (ll_sb_has_test_dummy_encryption(sb)) {
635 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
638 sbi->ll_dt_exp->exp_connect_data = *data;
640 /* Don't change value if it was specified in the config log */
641 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
642 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
643 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
644 (data->ocd_brw_size >> PAGE_SHIFT));
645 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
646 sbi->ll_ra_info.ra_max_pages_per_file)
647 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
648 sbi->ll_ra_info.ra_max_pages_per_file;
651 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
652 LUSTRE_SEQ_METADATA);
654 CERROR("%s: Can't init data layer FID infrastructure, "
655 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
659 mutex_lock(&sbi->ll_lco.lco_lock);
660 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
661 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
662 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
663 mutex_unlock(&sbi->ll_lco.lco_lock);
665 fid_zero(&sbi->ll_root_fid);
666 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
669 CERROR("cannot mds_connect: rc = %d\n", err);
670 GOTO(out_lock_cn_cb, err);
672 if (!fid_is_sane(&sbi->ll_root_fid)) {
673 CERROR("%s: Invalid root fid "DFID" during mount\n",
674 sbi->ll_md_exp->exp_obd->obd_name,
675 PFID(&sbi->ll_root_fid));
676 GOTO(out_lock_cn_cb, err = -EINVAL);
678 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
680 sb->s_op = &lustre_super_operations;
681 sb->s_xattr = ll_xattr_handlers;
682 #if THREAD_SIZE >= 8192 /*b=17630*/
683 sb->s_export_op = &lustre_export_operations;
685 #ifdef HAVE_LUSTRE_CRYPTO
686 llcrypt_set_ops(sb, &lustre_cryptops);
690 * XXX: move this to after cbd setup? */
691 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
693 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
694 valid |= OBD_MD_FLACL;
696 OBD_ALLOC_PTR(op_data);
698 GOTO(out_lock_cn_cb, err = -ENOMEM);
700 op_data->op_fid1 = sbi->ll_root_fid;
701 op_data->op_mode = 0;
702 op_data->op_valid = valid;
704 err = md_getattr(sbi->ll_md_exp, op_data, &request);
706 /* We need enc ctx info, so reset it in op_data to
707 * prevent it from being freed.
709 encctx = op_data->op_file_encctx;
710 encctxlen = op_data->op_file_encctx_size;
711 op_data->op_file_encctx = NULL;
712 op_data->op_file_encctx_size = 0;
713 OBD_FREE_PTR(op_data);
715 CERROR("%s: md_getattr failed for root: rc = %d\n",
716 sbi->ll_md_exp->exp_obd->obd_name, err);
717 GOTO(out_lock_cn_cb, err);
720 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
721 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
723 CERROR("failed to understand root inode md: rc = %d\n", err);
724 ptlrpc_req_finished(request);
725 GOTO(out_lock_cn_cb, err);
728 LASSERT(fid_is_sane(&sbi->ll_root_fid));
729 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
730 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
731 md_free_lustre_md(sbi->ll_md_exp, &lmd);
735 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
737 CERROR("%s: bad ll_iget() for root: rc = %d\n",
738 sbi->ll_fsname, err);
739 ptlrpc_req_finished(request);
743 err = ll_secctx_name_store(root);
744 if (err < 0 && ll_security_xattr_wanted(root))
745 CWARN("%s: file security contextes not supported: rc = %d\n",
746 sbi->ll_fsname, err);
751 "server returned encryption ctx for root inode "DFID"\n",
752 PFID(&sbi->ll_root_fid));
753 err = ll_set_encflags(root, encctx, encctxlen, true);
755 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
757 PFID(&sbi->ll_root_fid), err);
759 ptlrpc_req_finished(request);
761 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
762 if (sbi->ll_checksum_set) {
763 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
764 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
765 sizeof(checksum), &checksum, NULL);
767 CERROR("%s: Set checksum failed: rc = %d\n",
768 sbi->ll_dt_exp->exp_obd->obd_name, err);
774 sb->s_root = d_make_root(root);
775 if (sb->s_root == NULL) {
777 CERROR("%s: can't make root dentry: rc = %d\n",
778 sbi->ll_fsname, err);
782 sbi->ll_sdev_orig = sb->s_dev;
784 /* We set sb->s_dev equal on all lustre clients in order to support
785 * NFS export clustering. NFSD requires that the FSID be the same
787 /* s_dev is also used in lt_compare() to compare two fs, but that is
788 * only a node-local comparison. */
789 uuid = obd_get_uuid(sbi->ll_md_exp);
791 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
798 if (sbi->ll_dt_obd) {
799 err = sysfs_create_link(&sbi->ll_kset.kobj,
800 &sbi->ll_dt_obd->obd_kset.kobj,
801 sbi->ll_dt_obd->obd_type->typ_name);
803 CERROR("%s: could not register %s in llite: rc = %d\n",
804 dt, sbi->ll_fsname, err);
809 if (sbi->ll_md_obd) {
810 err = sysfs_create_link(&sbi->ll_kset.kobj,
811 &sbi->ll_md_obd->obd_kset.kobj,
812 sbi->ll_md_obd->obd_type->typ_name);
814 CERROR("%s: could not register %s in llite: rc = %d\n",
815 md, sbi->ll_fsname, err);
824 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
826 obd_disconnect(sbi->ll_dt_exp);
827 sbi->ll_dt_exp = NULL;
828 sbi->ll_dt_obd = NULL;
830 obd_fid_fini(sbi->ll_md_exp->exp_obd);
832 obd_disconnect(sbi->ll_md_exp);
833 sbi->ll_md_exp = NULL;
834 sbi->ll_md_obd = NULL;
843 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
847 size = sizeof(*lmmsize);
848 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
849 KEY_MAX_EASIZE, &size, lmmsize);
851 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
852 sbi->ll_dt_exp->exp_obd->obd_name, rc);
856 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
859 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
860 KEY_MAX_EASIZE, &size, lmmsize);
862 CERROR("Get max mdsize error rc %d\n", rc);
864 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
870 * Get the value of the default_easize parameter.
872 * \see client_obd::cl_default_mds_easize
874 * \param[in] sbi superblock info for this filesystem
875 * \param[out] lmmsize pointer to storage location for value
877 * \retval 0 on success
878 * \retval negative negated errno on failure
880 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
885 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
886 KEY_DEFAULT_EASIZE, &size, lmmsize);
888 CERROR("Get default mdsize error rc %d\n", rc);
894 * Set the default_easize parameter to the given value.
896 * \see client_obd::cl_default_mds_easize
898 * \param[in] sbi superblock info for this filesystem
899 * \param[in] lmmsize the size to set
901 * \retval 0 on success
902 * \retval negative negated errno on failure
904 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
908 if (lmmsize < sizeof(struct lov_mds_md) ||
909 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
912 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
913 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
914 sizeof(int), &lmmsize, NULL);
919 static void client_common_put_super(struct super_block *sb)
921 struct ll_sb_info *sbi = ll_s2sbi(sb);
926 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
927 obd_disconnect(sbi->ll_dt_exp);
928 sbi->ll_dt_exp = NULL;
930 ll_debugfs_unregister_super(sb);
932 obd_fid_fini(sbi->ll_md_exp->exp_obd);
933 obd_disconnect(sbi->ll_md_exp);
934 sbi->ll_md_exp = NULL;
939 void ll_kill_super(struct super_block *sb)
941 struct ll_sb_info *sbi;
945 if (!(sb->s_flags & SB_ACTIVE))
949 /* we need restore s_dev from changed for clustred NFS before put_super
950 * because new kernels have cached s_dev and change sb->s_dev in
951 * put_super not affected real removing devices */
953 sb->s_dev = sbi->ll_sdev_orig;
955 /* wait running statahead threads to quit */
956 while (atomic_read(&sbi->ll_sa_running) > 0)
957 schedule_timeout_uninterruptible(
958 cfs_time_seconds(1) >> 3);
964 /* Since we use this table for ll_sbi_flags_seq_show make
965 * sure what you want displayed for a specific token that
966 * is listed more than once below be listed first. For
967 * example we want "checksum" displayed, not "nochecksum"
970 static const match_table_t ll_sbi_flags_name = {
971 {LL_SBI_NOLCK, "nolock"},
972 {LL_SBI_CHECKSUM, "checksum"},
973 {LL_SBI_CHECKSUM, "nochecksum"},
974 {LL_SBI_LOCALFLOCK, "localflock"},
975 {LL_SBI_FLOCK, "flock"},
976 {LL_SBI_FLOCK, "noflock"},
977 {LL_SBI_USER_XATTR, "user_xattr"},
978 {LL_SBI_USER_XATTR, "nouser_xattr"},
979 {LL_SBI_LRU_RESIZE, "lruresize"},
980 {LL_SBI_LRU_RESIZE, "nolruresize"},
981 {LL_SBI_LAZYSTATFS, "lazystatfs"},
982 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
983 {LL_SBI_32BIT_API, "32bitapi"},
984 {LL_SBI_USER_FID2PATH, "user_fid2path"},
985 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
986 {LL_SBI_VERBOSE, "verbose"},
987 {LL_SBI_VERBOSE, "noverbose"},
988 {LL_SBI_ALWAYS_PING, "always_ping"},
989 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
990 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
991 {LL_SBI_ENCRYPT, "encrypt"},
992 {LL_SBI_ENCRYPT, "noencrypt"},
993 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
994 {LL_SBI_NUM_MOUNT_OPT, NULL},
997 {LL_SBI_AGL_ENABLED, "agl"},
998 {LL_SBI_64BIT_HASH, "64bit_hash"},
999 {LL_SBI_LAYOUT_LOCK, "layout"},
1000 {LL_SBI_XATTR_CACHE, "xattr_cache"},
1001 {LL_SBI_NOROOTSQUASH, "norootsquash"},
1002 {LL_SBI_FAST_READ, "fast_read"},
1003 {LL_SBI_FILE_SECCTX, "file_secctx"},
1004 {LL_SBI_TINY_WRITE, "tiny_write"},
1005 {LL_SBI_FILE_HEAT, "file_heat"},
1006 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
1007 {LL_SBI_ENCRYPT_NAME, "name_encrypt"},
1010 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
1012 struct super_block *sb = m->private;
1015 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
1018 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
1021 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
1022 if (ll_sbi_flags_name[j].token == i &&
1023 ll_sbi_flags_name[j].pattern) {
1024 seq_printf(m, "%s ",
1025 ll_sbi_flags_name[j].pattern);
1030 seq_puts(m, "\b\n");
1034 /* non-client-specific mount options are parsed in lmd_parse */
1035 static int ll_options(char *options, struct super_block *sb)
1037 struct ll_sb_info *sbi = ll_s2sbi(sb);
1038 char *s2, *s1, *opts;
1045 /* Don't stomp on lmd_opts */
1046 opts = kstrdup(options, GFP_KERNEL);
1052 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1054 while ((s1 = strsep(&opts, ",")) != NULL) {
1055 substring_t args[MAX_OPT_ARGS];
1056 bool turn_off = false;
1062 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1064 if (strncmp(s1, "no", 2) == 0)
1068 * Initialize args struct so we know whether arg was
1069 * found; some options take optional arguments.
1072 args[0].from = NULL;
1073 token = match_token(s1, ll_sbi_flags_name, args);
1074 if (token == LL_SBI_NUM_MOUNT_OPT) {
1075 if (match_wildcard("context", s1) ||
1076 match_wildcard("fscontext", s1) ||
1077 match_wildcard("defcontext", s1) ||
1078 match_wildcard("rootcontext",s1))
1081 LCONSOLE_ERROR_MSG(0x152,
1082 "Unknown option '%s', won't mount.\n",
1089 case LL_SBI_32BIT_API:
1090 case LL_SBI_64BIT_HASH:
1091 case LL_SBI_ALWAYS_PING:
1092 set_bit(token, sbi->ll_flags);
1096 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1098 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1100 set_bit(token, sbi->ll_flags);
1103 case LL_SBI_LOCALFLOCK:
1104 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1105 set_bit(token, sbi->ll_flags);
1108 case LL_SBI_CHECKSUM:
1109 sbi->ll_checksum_set = 1;
1111 case LL_SBI_USER_XATTR:
1112 case LL_SBI_USER_FID2PATH:
1113 case LL_SBI_LRU_RESIZE:
1114 case LL_SBI_LAZYSTATFS:
1115 case LL_SBI_VERBOSE:
1117 clear_bit(token, sbi->ll_flags);
1119 set_bit(token, sbi->ll_flags);
1121 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1122 #ifdef HAVE_LUSTRE_CRYPTO
1123 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1124 set_bit(token, sbi->ll_flags);
1126 struct lustre_sb_info *lsi = s2lsi(sb);
1128 err = llcrypt_set_test_dummy_encryption(sb,
1129 #ifdef HAVE_FSCRYPT_SET_TEST_DUMMY_ENC_CHAR_ARG
1134 &lsi->lsi_dummy_enc_policy);
1140 "Can't change test_dummy_encryption");
1141 else if (err == -EINVAL)
1143 "Value of option \"%s\" unrecognized",
1147 "Error processing option \"%s\" [%d]",
1152 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1156 case LL_SBI_ENCRYPT:
1157 #ifdef HAVE_LUSTRE_CRYPTO
1159 clear_bit(token, sbi->ll_flags);
1161 set_bit(token, sbi->ll_flags);
1163 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1166 case LL_SBI_FOREIGN_SYMLINK:
1167 /* non-default prefix provided ? */
1172 /* path must be absolute */
1173 if (args->from[0] != '/') {
1174 LCONSOLE_ERROR_MSG(0x152,
1175 "foreign prefix '%s' must be an absolute path\n",
1180 old_len = sbi->ll_foreign_symlink_prefix_size;
1181 old = sbi->ll_foreign_symlink_prefix;
1182 /* alloc for path length and '\0' */
1183 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1184 if (!sbi->ll_foreign_symlink_prefix) {
1185 /* restore previous */
1186 sbi->ll_foreign_symlink_prefix = old;
1187 sbi->ll_foreign_symlink_prefix_size =
1191 sbi->ll_foreign_symlink_prefix_size =
1192 args->to - args->from + 1;
1193 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1194 sbi->ll_foreign_symlink_prefix_size,
1197 OBD_FREE(old, old_len);
1199 /* enable foreign symlink support */
1200 set_bit(token, sbi->ll_flags);
1202 LCONSOLE_ERROR_MSG(0x152,
1203 "invalid %s option\n", s1);
1214 void ll_lli_init(struct ll_inode_info *lli)
1216 lli->lli_inode_magic = LLI_INODE_MAGIC;
1218 rwlock_init(&lli->lli_lock);
1219 lli->lli_posix_acl = NULL;
1220 /* Do not set lli_fid, it has been initialized already. */
1221 fid_zero(&lli->lli_pfid);
1222 lli->lli_mds_read_och = NULL;
1223 lli->lli_mds_write_och = NULL;
1224 lli->lli_mds_exec_och = NULL;
1225 lli->lli_open_fd_read_count = 0;
1226 lli->lli_open_fd_write_count = 0;
1227 lli->lli_open_fd_exec_count = 0;
1228 mutex_init(&lli->lli_och_mutex);
1229 spin_lock_init(&lli->lli_agl_lock);
1230 spin_lock_init(&lli->lli_layout_lock);
1231 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1232 lli->lli_clob = NULL;
1234 init_rwsem(&lli->lli_xattrs_list_rwsem);
1235 mutex_init(&lli->lli_xattrs_enq_lock);
1237 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1238 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1239 lli->lli_opendir_key = NULL;
1240 lli->lli_sai = NULL;
1241 spin_lock_init(&lli->lli_sa_lock);
1242 lli->lli_opendir_pid = 0;
1243 lli->lli_sa_enabled = 0;
1244 init_rwsem(&lli->lli_lsm_sem);
1246 mutex_init(&lli->lli_size_mutex);
1247 mutex_init(&lli->lli_setattr_mutex);
1248 lli->lli_symlink_name = NULL;
1249 ll_trunc_sem_init(&lli->lli_trunc_sem);
1250 range_lock_tree_init(&lli->lli_write_tree);
1251 init_rwsem(&lli->lli_glimpse_sem);
1252 lli->lli_glimpse_time = ktime_set(0, 0);
1253 INIT_LIST_HEAD(&lli->lli_agl_list);
1254 lli->lli_agl_index = 0;
1255 lli->lli_async_rc = 0;
1256 spin_lock_init(&lli->lli_heat_lock);
1257 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1258 lli->lli_heat_flags = 0;
1259 mutex_init(&lli->lli_pcc_lock);
1260 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1261 lli->lli_pcc_inode = NULL;
1262 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1263 lli->lli_pcc_generation = 0;
1264 mutex_init(&lli->lli_group_mutex);
1265 lli->lli_group_users = 0;
1266 lli->lli_group_gid = 0;
1267 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1268 lli->lli_uid = (__u32) -1;
1269 lli->lli_gid = (__u32) -1;
1271 mutex_init(&lli->lli_layout_mutex);
1272 /* ll_cl_context initialize */
1273 INIT_LIST_HEAD(&lli->lli_lccs);
1274 seqlock_init(&lli->lli_page_inv_lock);
1277 #define MAX_STRING_SIZE 128
1279 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1280 #ifndef HAVE_BDI_CAP_MAP_COPY
1281 # define BDI_CAP_MAP_COPY 0
1284 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1286 struct lustre_sb_info *lsi = s2lsi(sb);
1287 char buf[MAX_STRING_SIZE];
1291 err = bdi_init(&lsi->lsi_bdi);
1295 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1296 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1297 lsi->lsi_bdi.name = "lustre";
1298 va_start(args, fmt);
1299 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1301 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1304 sb->s_bdi = &lsi->lsi_bdi;
1308 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1310 int ll_fill_super(struct super_block *sb)
1312 struct lustre_profile *lprof = NULL;
1313 struct lustre_sb_info *lsi = s2lsi(sb);
1314 struct ll_sb_info *sbi = NULL;
1315 char *dt = NULL, *md = NULL;
1316 char *profilenm = get_profile_name(sb);
1317 struct config_llog_instance *cfg;
1318 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1319 const int instlen = LUSTRE_MAXINSTANCE + 2;
1320 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1321 char name[MAX_STRING_SIZE];
1330 /* for ASLR, to map between cfg_instance and hashed ptr */
1331 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1332 profilenm, cfg_instance, sb);
1334 OBD_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1338 GOTO(out_free_cfg, err = -ENOMEM);
1340 /* client additional sb info */
1341 lsi->lsi_llsbi = sbi = ll_init_sbi(lsi);
1343 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1345 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1347 GOTO(out_free_cfg, err);
1349 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1350 #ifdef CONFIG_LL_ENCRYPTION
1351 if (ll_sb_has_test_dummy_encryption(sb))
1352 /* enable filename encryption by default for dummy enc mode */
1353 lsi->lsi_flags |= LSI_FILENAME_ENC;
1355 /* filename encryption is disabled by default */
1356 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1359 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1360 sb->s_d_op = &ll_d_ops;
1363 generate_random_uuid(uuid.b);
1364 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1366 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1369 len = strlen(profilenm);
1370 ptr = strrchr(profilenm, '-');
1371 if (ptr && (strcmp(ptr, "-client") == 0))
1374 if (len > LUSTRE_MAXFSNAME) {
1375 if (unlikely(len >= MAX_STRING_SIZE))
1376 len = MAX_STRING_SIZE - 1;
1377 strncpy(name, profilenm, len);
1379 err = -ENAMETOOLONG;
1380 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1381 name, LUSTRE_MAXFSNAME, err);
1382 GOTO(out_free_cfg, err);
1384 strncpy(sbi->ll_fsname, profilenm, len);
1385 sbi->ll_fsname[len] = '\0';
1388 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1389 profilenm, cfg_instance);
1391 err = super_setup_bdi_name(sb, "%s", name);
1393 GOTO(out_free_cfg, err);
1395 /* disable kernel readahead */
1396 sb->s_bdi->ra_pages = 0;
1397 #ifdef HAVE_BDI_IO_PAGES
1398 sb->s_bdi->io_pages = 0;
1401 /* Call ll_debugfs_register_super() before lustre_process_log()
1402 * so that "llite.*.*" params can be processed correctly.
1404 err = ll_debugfs_register_super(sb, name);
1406 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1407 sbi->ll_fsname, err);
1411 /* The cfg_instance is a value unique to this super, in case some
1412 * joker tries to mount the same fs at two mount points.
1414 cfg->cfg_instance = cfg_instance;
1415 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1416 cfg->cfg_callback = class_config_llog_handler;
1417 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1418 /* set up client obds */
1419 err = lustre_process_log(sb, profilenm, cfg);
1421 GOTO(out_debugfs, err);
1423 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1424 lprof = class_get_profile(profilenm);
1425 if (lprof == NULL) {
1426 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1427 " read from the MGS. Does that filesystem "
1428 "exist?\n", profilenm);
1429 GOTO(out_debugfs, err = -EINVAL);
1431 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1432 lprof->lp_md, lprof->lp_dt);
1434 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1435 OBD_ALLOC(dt, dt_len);
1437 GOTO(out_profile, err = -ENOMEM);
1438 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1440 md_len = strlen(lprof->lp_md) + instlen + 2;
1441 OBD_ALLOC(md, md_len);
1443 GOTO(out_free_dt, err = -ENOMEM);
1444 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1446 /* connections, registrations, sb setup */
1447 err = client_common_fill_super(sb, md, dt);
1449 GOTO(out_free_md, err);
1451 sbi->ll_client_common_fill_super_succeeded = 1;
1455 OBD_FREE(md, md_len);
1458 OBD_FREE(dt, dt_len);
1461 class_put_profile(lprof);
1464 ll_debugfs_unregister_super(sb);
1471 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1472 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1473 sb->s_flags & SB_RDONLY ? " read-only" : "");
1475 } /* ll_fill_super */
1477 void ll_put_super(struct super_block *sb)
1479 struct config_llog_instance cfg, params_cfg;
1480 struct obd_device *obd;
1481 struct lustre_sb_info *lsi = s2lsi(sb);
1482 struct ll_sb_info *sbi = ll_s2sbi(sb);
1483 char *profilenm = get_profile_name(sb);
1484 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1486 int next, force = 1, rc = 0;
1490 GOTO(out_no_sbi, 0);
1492 /* Should replace instance_id with something better for ASLR */
1493 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1494 profilenm, cfg_instance, sb);
1496 cfg.cfg_instance = cfg_instance;
1497 lustre_end_log(sb, profilenm, &cfg);
1499 params_cfg.cfg_instance = cfg_instance;
1500 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1502 if (sbi->ll_md_exp) {
1503 obd = class_exp2obd(sbi->ll_md_exp);
1505 force = obd->obd_force;
1508 /* Wait for unstable pages to be committed to stable storage */
1510 rc = l_wait_event_abortable(
1511 sbi->ll_cache->ccc_unstable_waitq,
1512 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1515 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1516 if (force == 0 && rc != -ERESTARTSYS)
1517 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1519 /* We need to set force before the lov_disconnect in
1520 * lustre_common_put_super, since l_d cleans up osc's as well.
1524 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1526 obd->obd_force = force;
1530 if (sbi->ll_client_common_fill_super_succeeded) {
1531 /* Only if client_common_fill_super succeeded */
1532 client_common_put_super(sb);
1535 /* imitate failed cleanup */
1536 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1540 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1541 class_manual_cleanup(obd);
1544 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1545 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1548 class_del_profile(profilenm);
1550 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1551 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1552 bdi_destroy(&lsi->lsi_bdi);
1553 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1557 llcrypt_free_dummy_policy(&lsi->lsi_dummy_enc_policy);
1559 lsi->lsi_llsbi = NULL;
1561 lustre_common_put_super(sb);
1563 cl_env_cache_purge(~0);
1566 } /* client_put_super */
1568 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1570 struct inode *inode = NULL;
1572 /* NOTE: we depend on atomic igrab() -bzzz */
1573 lock_res_and_lock(lock);
1574 if (lock->l_resource->lr_lvb_inode) {
1575 struct ll_inode_info * lli;
1576 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1577 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1578 inode = igrab(lock->l_resource->lr_lvb_inode);
1580 inode = lock->l_resource->lr_lvb_inode;
1581 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1582 D_WARNING, lock, "lr_lvb_inode %p is "
1583 "bogus: magic %08x",
1584 lock->l_resource->lr_lvb_inode,
1585 lli->lli_inode_magic);
1589 unlock_res_and_lock(lock);
1593 void ll_dir_clear_lsm_md(struct inode *inode)
1595 struct ll_inode_info *lli = ll_i2info(inode);
1597 LASSERT(S_ISDIR(inode->i_mode));
1599 if (lli->lli_lsm_md) {
1600 lmv_free_memmd(lli->lli_lsm_md);
1601 lli->lli_lsm_md = NULL;
1604 if (lli->lli_default_lsm_md) {
1605 lmv_free_memmd(lli->lli_default_lsm_md);
1606 lli->lli_default_lsm_md = NULL;
1610 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1611 const struct lu_fid *fid,
1612 struct lustre_md *md)
1614 struct ll_sb_info *sbi = ll_s2sbi(sb);
1615 struct ll_inode_info *lli;
1616 struct mdt_body *body = md->body;
1617 struct inode *inode;
1623 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1624 inode = iget_locked(sb, ino);
1625 if (inode == NULL) {
1626 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1627 sbi->ll_fsname, PFID(fid));
1628 RETURN(ERR_PTR(-ENOENT));
1631 lli = ll_i2info(inode);
1632 if (inode->i_state & I_NEW) {
1633 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1634 (body->mbo_mode & S_IFMT);
1635 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1638 inode->i_mtime.tv_sec = 0;
1639 inode->i_atime.tv_sec = 0;
1640 inode->i_ctime.tv_sec = 0;
1643 #ifdef HAVE_BACKING_DEV_INFO
1644 /* initializing backing dev info. */
1645 inode->i_mapping->backing_dev_info =
1646 &s2lsi(inode->i_sb)->lsi_bdi;
1648 inode->i_op = &ll_dir_inode_operations;
1649 inode->i_fop = &ll_dir_operations;
1650 lli->lli_fid = *fid;
1653 /* master object FID */
1654 lli->lli_pfid = body->mbo_fid1;
1655 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1656 lli, PFID(fid), PFID(&lli->lli_pfid));
1657 unlock_new_inode(inode);
1659 /* in directory restripe/auto-split, a directory will be
1660 * transformed to a stripe if it's plain, set its pfid here,
1661 * otherwise ll_lock_cancel_bits() can't find the master inode.
1663 lli->lli_pfid = body->mbo_fid1;
1669 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1672 struct lmv_stripe_md *lsm = md->lmv;
1673 struct ll_inode_info *lli = ll_i2info(inode);
1676 LASSERT(lsm != NULL);
1678 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1679 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1680 lsm_md_dump(D_INODE, lsm);
1682 if (!lmv_dir_striped(lsm))
1685 /* XXX sigh, this lsm_root initialization should be in
1686 * LMV layer, but it needs ll_iget right now, so we
1687 * put this here right now. */
1688 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1689 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1690 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1692 if (!fid_is_sane(fid))
1695 /* Unfortunately ll_iget will call ll_update_inode,
1696 * where the initialization of slave inode is slightly
1697 * different, so it reset lsm_md to NULL to avoid
1698 * initializing lsm for slave inode. */
1699 lsm->lsm_md_oinfo[i].lmo_root =
1700 ll_iget_anon_dir(inode->i_sb, fid, md);
1701 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1702 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1704 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1706 iput(lsm->lsm_md_oinfo[i].lmo_root);
1707 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1713 lli->lli_lsm_md = lsm;
1718 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1720 struct ll_inode_info *lli = ll_i2info(inode);
1724 if (!md->default_lmv) {
1725 /* clear default lsm */
1726 if (lli->lli_default_lsm_md) {
1727 down_write(&lli->lli_lsm_sem);
1728 if (lli->lli_default_lsm_md) {
1729 lmv_free_memmd(lli->lli_default_lsm_md);
1730 lli->lli_default_lsm_md = NULL;
1732 lli->lli_inherit_depth = 0;
1733 up_write(&lli->lli_lsm_sem);
1738 if (lli->lli_default_lsm_md) {
1739 /* do nonthing if default lsm isn't changed */
1740 down_read(&lli->lli_lsm_sem);
1741 if (lli->lli_default_lsm_md &&
1742 lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1743 up_read(&lli->lli_lsm_sem);
1746 up_read(&lli->lli_lsm_sem);
1749 down_write(&lli->lli_lsm_sem);
1750 if (lli->lli_default_lsm_md)
1751 lmv_free_memmd(lli->lli_default_lsm_md);
1752 lli->lli_default_lsm_md = md->default_lmv;
1753 lsm_md_dump(D_INODE, md->default_lmv);
1754 md->default_lmv = NULL;
1755 up_write(&lli->lli_lsm_sem);
1759 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1761 struct ll_inode_info *lli = ll_i2info(inode);
1762 struct lmv_stripe_md *lsm = md->lmv;
1763 struct cl_attr *attr;
1768 LASSERT(S_ISDIR(inode->i_mode));
1769 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1770 PFID(ll_inode2fid(inode)));
1772 /* update default LMV */
1773 if (md->default_lmv)
1774 ll_update_default_lsm_md(inode, md);
1776 /* after dir migration/restripe, a stripe may be turned into a
1777 * directory, in this case, zero out its lli_pfid.
1779 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1780 fid_zero(&lli->lli_pfid);
1783 * no striped information from request, lustre_md from req does not
1784 * include stripeEA, see ll_md_setattr()
1790 * normally dir layout doesn't change, only take read lock to check
1791 * that to avoid blocking other MD operations.
1793 down_read(&lli->lli_lsm_sem);
1795 /* some current lookup initialized lsm, and unchanged */
1796 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1797 GOTO(unlock, rc = 0);
1799 /* if dir layout doesn't match, check whether version is increased,
1800 * which means layout is changed, this happens in dir split/merge and
1803 * foreign LMV should not change.
1805 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1806 lsm->lsm_md_layout_version <=
1807 lli->lli_lsm_md->lsm_md_layout_version) {
1808 CERROR("%s: "DFID" dir layout mismatch:\n",
1809 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1810 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1811 lsm_md_dump(D_ERROR, lsm);
1812 GOTO(unlock, rc = -EINVAL);
1815 up_read(&lli->lli_lsm_sem);
1816 down_write(&lli->lli_lsm_sem);
1817 /* clear existing lsm */
1818 if (lli->lli_lsm_md) {
1819 lmv_free_memmd(lli->lli_lsm_md);
1820 lli->lli_lsm_md = NULL;
1823 rc = ll_init_lsm_md(inode, md);
1825 up_write(&lli->lli_lsm_sem);
1829 /* md_merge_attr() may take long, since lsm is already set, switch to
1832 downgrade_write(&lli->lli_lsm_sem);
1834 /* set md->lmv to NULL, so the following free lustre_md will not free
1839 if (!lmv_dir_striped(lli->lli_lsm_md))
1840 GOTO(unlock, rc = 0);
1842 OBD_ALLOC_PTR(attr);
1844 GOTO(unlock, rc = -ENOMEM);
1846 /* validate the lsm */
1847 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1848 ll_md_blocking_ast);
1850 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1851 md->body->mbo_nlink = attr->cat_nlink;
1852 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1853 md->body->mbo_size = attr->cat_size;
1854 if (md->body->mbo_valid & OBD_MD_FLATIME)
1855 md->body->mbo_atime = attr->cat_atime;
1856 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1857 md->body->mbo_ctime = attr->cat_ctime;
1858 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1859 md->body->mbo_mtime = attr->cat_mtime;
1865 up_read(&lli->lli_lsm_sem);
1870 void ll_clear_inode(struct inode *inode)
1872 struct ll_inode_info *lli = ll_i2info(inode);
1873 struct ll_sb_info *sbi = ll_i2sbi(inode);
1877 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1878 PFID(ll_inode2fid(inode)), inode);
1880 if (S_ISDIR(inode->i_mode)) {
1881 /* these should have been cleared in ll_file_release */
1882 LASSERT(lli->lli_opendir_key == NULL);
1883 LASSERT(lli->lli_sai == NULL);
1884 LASSERT(lli->lli_opendir_pid == 0);
1886 pcc_inode_free(inode);
1889 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1891 LASSERT(!lli->lli_open_fd_write_count);
1892 LASSERT(!lli->lli_open_fd_read_count);
1893 LASSERT(!lli->lli_open_fd_exec_count);
1895 if (lli->lli_mds_write_och)
1896 ll_md_real_close(inode, FMODE_WRITE);
1897 if (lli->lli_mds_exec_och)
1898 ll_md_real_close(inode, FMODE_EXEC);
1899 if (lli->lli_mds_read_och)
1900 ll_md_real_close(inode, FMODE_READ);
1902 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1903 OBD_FREE(lli->lli_symlink_name,
1904 strlen(lli->lli_symlink_name) + 1);
1905 lli->lli_symlink_name = NULL;
1908 ll_xattr_cache_destroy(inode);
1910 forget_all_cached_acls(inode);
1912 lli->lli_inode_magic = LLI_INODE_DEAD;
1914 if (S_ISDIR(inode->i_mode))
1915 ll_dir_clear_lsm_md(inode);
1916 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1917 LASSERT(list_empty(&lli->lli_agl_list));
1920 * XXX This has to be done before lsm is freed below, because
1921 * cl_object still uses inode lsm.
1923 cl_inode_fini(inode);
1925 llcrypt_put_encryption_info(inode);
1930 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1932 struct lustre_md md;
1933 struct inode *inode = dentry->d_inode;
1934 struct ll_sb_info *sbi = ll_i2sbi(inode);
1935 struct ptlrpc_request *request = NULL;
1940 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1941 LUSTRE_OPC_ANY, NULL);
1942 if (IS_ERR(op_data))
1943 RETURN(PTR_ERR(op_data));
1945 /* If this is a chgrp of a regular file, we want to reserve enough
1946 * quota to cover the entire file size.
1948 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1949 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1950 from_kgid(&init_user_ns, inode->i_gid)) {
1951 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1952 op_data->op_attr_blocks = inode->i_blocks;
1956 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1958 ptlrpc_req_finished(request);
1959 if (rc == -ENOENT) {
1961 /* Unlinked special device node? Or just a race?
1962 * Pretend we done everything. */
1963 if (!S_ISREG(inode->i_mode) &&
1964 !S_ISDIR(inode->i_mode)) {
1965 ia_valid = op_data->op_attr.ia_valid;
1966 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1967 rc = simple_setattr(&init_user_ns, dentry,
1969 op_data->op_attr.ia_valid = ia_valid;
1971 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1972 CERROR("md_setattr fails: rc = %d\n", rc);
1977 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1978 sbi->ll_md_exp, &md);
1980 ptlrpc_req_finished(request);
1984 ia_valid = op_data->op_attr.ia_valid;
1985 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1986 * cache is not cleared yet. */
1987 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1988 if (S_ISREG(inode->i_mode))
1990 rc = simple_setattr(&init_user_ns, dentry, &op_data->op_attr);
1991 if (S_ISREG(inode->i_mode))
1992 inode_unlock(inode);
1993 op_data->op_attr.ia_valid = ia_valid;
1995 rc = ll_update_inode(inode, &md);
1996 ptlrpc_req_finished(request);
2002 * Zero portion of page that is part of @inode.
2003 * This implies, if necessary:
2004 * - taking cl_lock on range corresponding to concerned page
2005 * - grabbing vm page
2006 * - associating cl_page
2007 * - proceeding to clio read
2008 * - zeroing range in page
2009 * - proceeding to cl_page flush
2010 * - releasing cl_lock
2012 * \param[in] inode inode
2013 * \param[in] index page index
2014 * \param[in] offset offset in page to start zero from
2015 * \param[in] len len to zero
2017 * \retval 0 on success
2018 * \retval negative errno on failure
2020 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
2023 struct ll_inode_info *lli = ll_i2info(inode);
2024 struct cl_object *clob = lli->lli_clob;
2026 struct lu_env *env = NULL;
2027 struct cl_io *io = NULL;
2028 struct cl_page *clpage = NULL;
2029 struct page *vmpage = NULL;
2030 unsigned from = index << PAGE_SHIFT;
2031 struct cl_lock *lock = NULL;
2032 struct cl_lock_descr *descr = NULL;
2033 struct cl_2queue *queue = NULL;
2034 struct cl_sync_io *anchor = NULL;
2035 bool holdinglock = false;
2040 env = cl_env_get(&refcheck);
2042 RETURN(PTR_ERR(env));
2044 io = vvp_env_thread_io(env);
2046 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2050 lock = vvp_env_lock(env);
2051 descr = &lock->cll_descr;
2052 descr->cld_obj = io->ci_obj;
2053 descr->cld_start = from >> PAGE_SHIFT;
2054 descr->cld_end = (from + PAGE_SIZE - 1) >> PAGE_SHIFT;
2055 descr->cld_mode = CLM_WRITE;
2056 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2058 /* request lock for page */
2059 rc = cl_lock_request(env, io, lock);
2060 /* -ECANCELED indicates a matching lock with a different extent
2061 * was already present, and -EEXIST indicates a matching lock
2062 * on exactly the same extent was already present.
2063 * In both cases it means we are covered.
2065 if (rc == -ECANCELED || rc == -EEXIST)
2073 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2075 GOTO(rellock, rc = -EOPNOTSUPP);
2077 if (!PageDirty(vmpage)) {
2078 /* associate cl_page */
2079 clpage = cl_page_find(env, clob, vmpage->index,
2080 vmpage, CPT_CACHEABLE);
2082 GOTO(pagefini, rc = PTR_ERR(clpage));
2084 cl_page_assume(env, io, clpage);
2087 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2088 !PageWriteback(vmpage)) {
2090 /* Set PagePrivate2 to detect special case of empty page
2091 * in osc_brw_fini_request().
2092 * It is also used to tell ll_io_read_page() that we do not
2093 * want the vmpage to be unlocked.
2095 SetPagePrivate2(vmpage);
2096 rc = ll_io_read_page(env, io, clpage, NULL);
2097 if (!PagePrivate2(vmpage)) {
2098 /* PagePrivate2 was cleared in osc_brw_fini_request()
2099 * meaning we read an empty page. In this case, in order
2100 * to avoid allocating unnecessary block in truncated
2101 * file, we must not zero and write as below. Subsequent
2102 * server-side truncate will handle things correctly.
2104 cl_page_unassume(env, io, clpage);
2105 GOTO(clpfini, rc = 0);
2107 ClearPagePrivate2(vmpage);
2112 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2113 * the vmpage, so we are good to proceed and zero range in page.
2115 zero_user(vmpage, offset, len);
2117 if (holdinglock && clpage) {
2118 /* explicitly write newly modified page */
2119 queue = &io->ci_queue;
2120 cl_2queue_init(queue);
2121 anchor = &vvp_env_info(env)->vti_anchor;
2122 cl_sync_io_init(anchor, 1);
2123 clpage->cp_sync_io = anchor;
2124 cl_page_list_add(&queue->c2_qin, clpage, true);
2125 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2127 GOTO(queuefini1, rc);
2128 rc = cl_sync_io_wait(env, anchor, 0);
2130 GOTO(queuefini2, rc);
2131 cl_page_assume(env, io, clpage);
2134 cl_2queue_discard(env, io, queue);
2136 cl_2queue_disown(env, queue);
2137 cl_2queue_fini(env, queue);
2142 cl_page_put(env, clpage);
2144 unlock_page(vmpage);
2148 cl_lock_release(env, lock);
2150 cl_io_fini(env, io);
2153 cl_env_put(env, &refcheck);
2159 * Get reference file from volatile file name.
2160 * Volatile file name may look like:
2161 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2162 * where fd is opened descriptor of reference file.
2164 * \param[in] volatile_name volatile file name
2165 * \param[in] volatile_len volatile file name length
2166 * \param[out] ref_file pointer to struct file of reference file
2168 * \retval 0 on success
2169 * \retval negative errno on failure
2171 int volatile_ref_file(const char *volatile_name, int volatile_len,
2172 struct file **ref_file)
2174 char *p, *q, *fd_str;
2177 p = strnstr(volatile_name, ":fd=", volatile_len);
2178 if (!p || strlen(p + 4) == 0)
2181 q = strchrnul(p + 4, ':');
2182 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2185 rc = kstrtouint(fd_str, 10, &fd);
2190 *ref_file = fget(fd);
2196 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2197 * object(s) determine the file size and mtime. Otherwise, the MDS will
2198 * keep these values until such a time that objects are allocated for it.
2199 * We do the MDS operations first, as it is checking permissions for us.
2200 * We don't to the MDS RPC if there is nothing that we want to store there,
2201 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2202 * going to do an RPC anyways.
2204 * If we are doing a truncate, we will send the mtime and ctime updates
2205 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2206 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2209 * In case of HSMimport, we only set attr on MDS.
2211 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2212 enum op_xvalid xvalid, bool hsm_import)
2214 struct inode *inode = dentry->d_inode;
2215 struct ll_inode_info *lli = ll_i2info(inode);
2216 struct md_op_data *op_data = NULL;
2217 ktime_t kstart = ktime_get();
2222 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2223 "valid %x, hsm_import %d\n",
2224 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2225 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2228 if (attr->ia_valid & ATTR_SIZE) {
2229 /* Check new size against VFS/VM file size limit and rlimit */
2230 rc = inode_newsize_ok(inode, attr->ia_size);
2234 /* The maximum Lustre file size is variable, based on the
2235 * OST maximum object size and number of stripes. This
2236 * needs another check in addition to the VFS check above. */
2237 if (attr->ia_size > ll_file_maxbytes(inode)) {
2238 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2239 PFID(&lli->lli_fid), attr->ia_size,
2240 ll_file_maxbytes(inode));
2244 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2247 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2248 if (attr->ia_valid & TIMES_SET_FLAGS) {
2249 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2250 !capable(CAP_FOWNER))
2254 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2255 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2256 (attr->ia_valid & ATTR_CTIME)) {
2257 attr->ia_ctime = current_time(inode);
2258 xvalid |= OP_XVALID_CTIME_SET;
2260 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2261 (attr->ia_valid & ATTR_ATIME)) {
2262 attr->ia_atime = current_time(inode);
2263 attr->ia_valid |= ATTR_ATIME_SET;
2265 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2266 (attr->ia_valid & ATTR_MTIME)) {
2267 attr->ia_mtime = current_time(inode);
2268 attr->ia_valid |= ATTR_MTIME_SET;
2271 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2272 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2273 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2274 ktime_get_real_seconds());
2276 if (S_ISREG(inode->i_mode))
2277 inode_unlock(inode);
2279 /* We always do an MDS RPC, even if we're only changing the size;
2280 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2282 OBD_ALLOC_PTR(op_data);
2283 if (op_data == NULL)
2284 GOTO(out, rc = -ENOMEM);
2286 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2287 /* If we are changing file size, file content is
2288 * modified, flag it.
2290 xvalid |= OP_XVALID_OWNEROVERRIDE;
2291 op_data->op_bias |= MDS_DATA_MODIFIED;
2292 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2295 if (attr->ia_valid & ATTR_FILE) {
2296 struct ll_file_data *fd = attr->ia_file->private_data;
2298 if (fd->fd_lease_och)
2299 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2302 op_data->op_attr = *attr;
2303 op_data->op_xvalid = xvalid;
2305 rc = ll_md_setattr(dentry, op_data);
2308 lli->lli_synced_to_mds = false;
2310 if (!S_ISREG(inode->i_mode) || hsm_import)
2313 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2314 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2315 xvalid & OP_XVALID_CTIME_SET) {
2316 bool cached = false;
2318 rc = pcc_inode_setattr(inode, attr, &cached);
2321 CERROR("%s: PCC inode "DFID" setattr failed: "
2323 ll_i2sbi(inode)->ll_fsname,
2324 PFID(&lli->lli_fid), rc);
2328 unsigned int flags = 0;
2330 /* For truncate and utimes sending attributes to OSTs,
2331 * setting mtime/atime to the past will be performed
2332 * under PW [0:EOF] extent lock (new_size:EOF for
2333 * truncate). It may seem excessive to send mtime/atime
2334 * updates to OSTs when not setting times to past, but
2335 * it is necessary due to possible time
2336 * de-synchronization between MDT inode and OST objects
2338 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2339 xvalid |= OP_XVALID_FLAGS;
2340 flags = LUSTRE_ENCRYPT_FL;
2341 /* Call to ll_io_zero_page is not necessary if
2342 * truncating on PAGE_SIZE boundary, because
2343 * whole pages will be wiped.
2344 * In case of Direct IO, all we need is to set
2347 if (attr->ia_valid & ATTR_SIZE &&
2348 attr->ia_size & ~PAGE_MASK &&
2349 !(attr->ia_valid & ATTR_FILE &&
2350 attr->ia_file->f_flags & O_DIRECT)) {
2352 attr->ia_size & (PAGE_SIZE - 1);
2354 rc = ll_io_zero_page(inode,
2355 attr->ia_size >> PAGE_SHIFT,
2356 offset, PAGE_SIZE - offset);
2360 /* If encrypted volatile file without the key,
2361 * we need to fetch size from reference file,
2362 * and set it on OST objects. This happens when
2363 * migrating or extending an encrypted file
2366 if (filename_is_volatile(dentry->d_name.name,
2369 llcrypt_require_key(inode) == -ENOKEY) {
2370 struct file *ref_file;
2371 struct inode *ref_inode;
2372 struct ll_inode_info *ref_lli;
2373 struct cl_object *ref_obj;
2374 struct cl_attr ref_attr = { 0 };
2378 rc = volatile_ref_file(
2379 dentry->d_name.name,
2385 ref_inode = file_inode(ref_file);
2388 GOTO(out, rc = -EINVAL);
2391 env = cl_env_get(&refcheck);
2393 GOTO(out, rc = PTR_ERR(env));
2395 ref_lli = ll_i2info(ref_inode);
2396 ref_obj = ref_lli->lli_clob;
2397 cl_object_attr_lock(ref_obj);
2398 rc = cl_object_attr_get(env, ref_obj,
2400 cl_object_attr_unlock(ref_obj);
2401 cl_env_put(env, &refcheck);
2406 attr->ia_valid |= ATTR_SIZE;
2407 attr->ia_size = ref_attr.cat_size;
2410 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2414 /* If the file was restored, it needs to set dirty flag.
2416 * We've already sent MDS_DATA_MODIFIED flag in
2417 * ll_md_setattr() for truncate. However, the MDT refuses to
2418 * set the HS_DIRTY flag on released files, so we have to set
2419 * it again if the file has been restored. Please check how
2420 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2422 * Please notice that if the file is not released, the previous
2423 * MDS_DATA_MODIFIED has taken effect and usually
2424 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2425 * This way we can save an RPC for common open + trunc
2427 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2428 struct hsm_state_set hss = {
2429 .hss_valid = HSS_SETMASK,
2430 .hss_setmask = HS_DIRTY,
2434 rc2 = ll_hsm_state_set(inode, &hss);
2435 /* truncate and write can happen at the same time, so that
2436 * the file can be set modified even though the file is not
2437 * restored from released state, and ll_hsm_state_set() is
2438 * not applicable for the file, and rc2 < 0 is normal in this
2441 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2442 PFID(ll_inode2fid(inode)), rc2);
2447 if (op_data != NULL)
2448 ll_finish_md_op_data(op_data);
2450 if (S_ISREG(inode->i_mode)) {
2452 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2453 inode_dio_wait(inode);
2454 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2455 * flag. ll_update_inode (called from ll_md_setattr), clears
2456 * inode flags, so there is a gap where S_NOSEC is not set.
2457 * This can cause a writer to take the i_mutex unnecessarily,
2458 * but this is safe to do and should be rare. */
2459 inode_has_no_xattr(inode);
2463 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2464 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2465 ktime_us_delta(ktime_get(), kstart));
2470 int ll_setattr(struct user_namespace *mnt_userns, struct dentry *de,
2473 int mode = de->d_inode->i_mode;
2474 enum op_xvalid xvalid = 0;
2477 rc = llcrypt_prepare_setattr(de, attr);
2481 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2482 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2483 xvalid |= OP_XVALID_OWNEROVERRIDE;
2485 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2486 (ATTR_SIZE|ATTR_MODE)) &&
2487 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2488 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2489 !(attr->ia_mode & S_ISGID))))
2490 attr->ia_valid |= ATTR_FORCE;
2492 if ((attr->ia_valid & ATTR_MODE) &&
2494 !(attr->ia_mode & S_ISUID) &&
2495 !(attr->ia_valid & ATTR_KILL_SUID))
2496 attr->ia_valid |= ATTR_KILL_SUID;
2498 if ((attr->ia_valid & ATTR_MODE) &&
2499 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2500 !(attr->ia_mode & S_ISGID) &&
2501 !(attr->ia_valid & ATTR_KILL_SGID))
2502 attr->ia_valid |= ATTR_KILL_SGID;
2504 return ll_setattr_raw(de, attr, xvalid, false);
2507 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2510 struct obd_statfs obd_osfs = { 0 };
2515 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2517 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2518 flags |= OBD_STATFS_NODELAY;
2520 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2524 osfs->os_type = LL_SUPER_MAGIC;
2526 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2527 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2529 if (osfs->os_state & OS_STATFS_SUM)
2532 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2533 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2536 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2537 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2540 osfs->os_bsize = obd_osfs.os_bsize;
2541 osfs->os_blocks = obd_osfs.os_blocks;
2542 osfs->os_bfree = obd_osfs.os_bfree;
2543 osfs->os_bavail = obd_osfs.os_bavail;
2545 /* If we have _some_ OSTs, but don't have as many free objects on the
2546 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2547 * to compensate, so that the "inodes in use" number is correct.
2548 * This should be kept in sync with lod_statfs() behaviour.
2550 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2551 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2553 osfs->os_ffree = obd_osfs.os_ffree;
2560 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2562 struct if_quotactl qctl = {
2563 .qc_cmd = LUSTRE_Q_GETQUOTA,
2564 .qc_type = PRJQUOTA,
2565 .qc_valid = QC_GENERAL,
2567 u64 limit, curblock;
2570 qctl.qc_id = ll_i2info(inode)->lli_projid;
2571 ret = quotactl_ioctl(inode->i_sb, &qctl);
2573 /* ignore errors if project ID does not have
2574 * a quota limit or feature unsupported.
2576 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2581 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2582 qctl.qc_dqblk.dqb_bsoftlimit :
2583 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2584 if (limit && sfs->f_blocks > limit) {
2585 curblock = (qctl.qc_dqblk.dqb_curspace +
2586 sfs->f_bsize - 1) / sfs->f_bsize;
2587 sfs->f_blocks = limit;
2588 sfs->f_bfree = sfs->f_bavail =
2589 (sfs->f_blocks > curblock) ?
2590 (sfs->f_blocks - curblock) : 0;
2593 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2594 qctl.qc_dqblk.dqb_isoftlimit :
2595 qctl.qc_dqblk.dqb_ihardlimit;
2596 if (limit && sfs->f_files > limit) {
2597 sfs->f_files = limit;
2598 sfs->f_ffree = (sfs->f_files >
2599 qctl.qc_dqblk.dqb_curinodes) ?
2600 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2606 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2608 struct super_block *sb = de->d_sb;
2609 struct obd_statfs osfs;
2610 __u64 fsid = huge_encode_dev(sb->s_dev);
2611 ktime_t kstart = ktime_get();
2614 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2616 /* Some amount of caching on the client is allowed */
2617 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2621 statfs_unpack(sfs, &osfs);
2623 /* We need to downshift for all 32-bit kernels, because we can't
2624 * tell if the kernel is being called via sys_statfs64() or not.
2625 * Stop before overflowing f_bsize - in which case it is better
2626 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2627 if (sizeof(long) < 8) {
2628 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2631 osfs.os_blocks >>= 1;
2632 osfs.os_bfree >>= 1;
2633 osfs.os_bavail >>= 1;
2637 sfs->f_blocks = osfs.os_blocks;
2638 sfs->f_bfree = osfs.os_bfree;
2639 sfs->f_bavail = osfs.os_bavail;
2640 sfs->f_fsid.val[0] = (__u32)fsid;
2641 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2642 if (ll_i2info(de->d_inode)->lli_projid &&
2643 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2644 return ll_statfs_project(de->d_inode, sfs);
2646 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2647 ktime_us_delta(ktime_get(), kstart));
2652 void ll_inode_size_lock(struct inode *inode)
2654 struct ll_inode_info *lli;
2656 LASSERT(!S_ISDIR(inode->i_mode));
2658 lli = ll_i2info(inode);
2659 mutex_lock(&lli->lli_size_mutex);
2662 void ll_inode_size_unlock(struct inode *inode)
2664 struct ll_inode_info *lli;
2666 lli = ll_i2info(inode);
2667 mutex_unlock(&lli->lli_size_mutex);
2670 int ll_inode_size_trylock(struct inode *inode)
2672 struct ll_inode_info *lli;
2674 LASSERT(!S_ISDIR(inode->i_mode));
2676 lli = ll_i2info(inode);
2677 return mutex_trylock(&lli->lli_size_mutex);
2680 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2682 /* do not clear encryption flag */
2683 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2684 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2685 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2686 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2688 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2691 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2693 struct ll_inode_info *lli = ll_i2info(inode);
2694 struct mdt_body *body = md->body;
2695 struct ll_sb_info *sbi = ll_i2sbi(inode);
2699 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2700 rc = cl_file_inode_init(inode, md);
2705 if (S_ISDIR(inode->i_mode)) {
2706 rc = ll_update_lsm_md(inode, md);
2711 if (body->mbo_valid & OBD_MD_FLACL)
2712 lli_replace_acl(lli, md);
2714 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2715 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2716 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2718 if (body->mbo_valid & OBD_MD_FLATIME) {
2719 if (body->mbo_atime > inode->i_atime.tv_sec)
2720 inode->i_atime.tv_sec = body->mbo_atime;
2721 lli->lli_atime = body->mbo_atime;
2724 if (body->mbo_valid & OBD_MD_FLMTIME) {
2725 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2727 "setting ino %lu mtime from %lld to %llu\n",
2728 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2730 inode->i_mtime.tv_sec = body->mbo_mtime;
2732 lli->lli_mtime = body->mbo_mtime;
2735 if (body->mbo_valid & OBD_MD_FLCTIME) {
2736 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2737 inode->i_ctime.tv_sec = body->mbo_ctime;
2738 lli->lli_ctime = body->mbo_ctime;
2741 if (body->mbo_valid & OBD_MD_FLBTIME)
2742 lli->lli_btime = body->mbo_btime;
2744 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2745 if (body->mbo_valid & OBD_MD_FLFLAGS)
2746 ll_update_inode_flags(inode, body->mbo_flags);
2747 if (body->mbo_valid & OBD_MD_FLMODE)
2748 inode->i_mode = (inode->i_mode & S_IFMT) |
2749 (body->mbo_mode & ~S_IFMT);
2751 if (body->mbo_valid & OBD_MD_FLTYPE)
2752 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2753 (body->mbo_mode & S_IFMT);
2755 LASSERT(inode->i_mode != 0);
2756 if (body->mbo_valid & OBD_MD_FLUID)
2757 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2758 if (body->mbo_valid & OBD_MD_FLGID)
2759 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2760 if (body->mbo_valid & OBD_MD_FLPROJID)
2761 lli->lli_projid = body->mbo_projid;
2762 if (body->mbo_valid & OBD_MD_FLNLINK) {
2763 spin_lock(&inode->i_lock);
2764 set_nlink(inode, body->mbo_nlink);
2765 spin_unlock(&inode->i_lock);
2767 if (body->mbo_valid & OBD_MD_FLRDEV)
2768 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2770 if (body->mbo_valid & OBD_MD_FLID) {
2771 /* FID shouldn't be changed! */
2772 if (fid_is_sane(&lli->lli_fid)) {
2773 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2774 "Trying to change FID "DFID
2775 " to the "DFID", inode "DFID"(%p)\n",
2776 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2777 PFID(ll_inode2fid(inode)), inode);
2779 lli->lli_fid = body->mbo_fid1;
2783 LASSERT(fid_seq(&lli->lli_fid) != 0);
2785 /* In case of encrypted file without the key, please do not lose
2786 * clear text size stored into lli_lazysize in ll_merge_attr(),
2787 * we will need it in ll_prepare_close().
2789 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2790 llcrypt_require_key(inode) == -ENOKEY)
2791 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2793 lli->lli_attr_valid = body->mbo_valid;
2794 if (body->mbo_valid & OBD_MD_FLSIZE) {
2795 i_size_write(inode, body->mbo_size);
2797 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2798 PFID(ll_inode2fid(inode)),
2799 (unsigned long long)body->mbo_size);
2801 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2802 inode->i_blocks = body->mbo_blocks;
2804 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2805 lli->lli_lazysize = body->mbo_size;
2806 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2807 lli->lli_lazyblocks = body->mbo_blocks;
2810 if (body->mbo_valid & OBD_MD_TSTATE) {
2811 /* Set LLIF_FILE_RESTORING if restore ongoing and
2812 * clear it when done to ensure to start again
2813 * glimpsing updated attrs
2815 if (body->mbo_t_state & MS_RESTORE)
2816 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2818 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2824 /* child default LMV is inherited from parent */
2825 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2826 struct lmv_stripe_md *cdmv)
2831 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2832 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2833 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2834 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2837 if (cdmv->lsm_md_max_inherit !=
2838 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2841 if (cdmv->lsm_md_max_inherit_rr !=
2842 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2848 /* update directory depth to ROOT, called after LOOKUP lock is fetched. */
2849 void ll_update_dir_depth(struct inode *dir, struct inode *inode)
2851 struct ll_inode_info *plli;
2852 struct ll_inode_info *lli;
2854 if (!S_ISDIR(inode->i_mode))
2860 plli = ll_i2info(dir);
2861 lli = ll_i2info(inode);
2862 lli->lli_dir_depth = plli->lli_dir_depth + 1;
2863 if (plli->lli_default_lsm_md && lli->lli_default_lsm_md) {
2864 down_read(&plli->lli_lsm_sem);
2865 down_read(&lli->lli_lsm_sem);
2866 if (ll_default_lmv_inherited(plli->lli_default_lsm_md,
2867 lli->lli_default_lsm_md))
2868 lli->lli_inherit_depth =
2869 plli->lli_inherit_depth + 1;
2871 lli->lli_inherit_depth = 0;
2872 up_read(&lli->lli_lsm_sem);
2873 up_read(&plli->lli_lsm_sem);
2875 lli->lli_inherit_depth = 0;
2878 CDEBUG(D_INODE, DFID" depth %hu default LMV depth %hu\n",
2879 PFID(&lli->lli_fid), lli->lli_dir_depth, lli->lli_inherit_depth);
2882 void ll_truncate_inode_pages_final(struct inode *inode, struct cl_io *io)
2884 struct address_space *mapping = &inode->i_data;
2885 unsigned long nrpages;
2886 unsigned long flags;
2888 LASSERTF(io == NULL || inode_is_locked(inode), "io %p (type %d)\n",
2889 io, io ? io->ci_type : 0);
2891 truncate_inode_pages_final(mapping);
2893 /* Workaround for LU-118: Note nrpages may not be totally updated when
2894 * truncate_inode_pages() returns, as there can be a page in the process
2895 * of deletion (inside __delete_from_page_cache()) in the specified
2896 * range. Thus mapping->nrpages can be non-zero when this function
2897 * returns even after truncation of the whole mapping. Only do this if
2898 * npages isn't already zero.
2900 nrpages = mapping->nrpages;
2902 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2903 nrpages = mapping->nrpages;
2904 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2905 } /* Workaround end */
2907 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu "
2908 "io %p (io_type %d), "
2909 "see https://jira.whamcloud.com/browse/LU-118\n",
2910 ll_i2sbi(inode)->ll_fsname,
2911 PFID(ll_inode2fid(inode)), inode, nrpages,
2912 io, io ? io->ci_type : 0);
2915 int ll_read_inode2(struct inode *inode, void *opaque)
2917 struct lustre_md *md = opaque;
2918 struct ll_inode_info *lli = ll_i2info(inode);
2922 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2923 PFID(&lli->lli_fid), inode);
2925 /* Core attributes from the MDS first. This is a new inode, and
2926 * the VFS doesn't zero times in the core inode so we have to do
2927 * it ourselves. They will be overwritten by either MDS or OST
2928 * attributes - we just need to make sure they aren't newer.
2930 inode->i_mtime.tv_sec = 0;
2931 inode->i_atime.tv_sec = 0;
2932 inode->i_ctime.tv_sec = 0;
2934 rc = ll_update_inode(inode, md);
2938 /* OIDEBUG(inode); */
2940 #ifdef HAVE_BACKING_DEV_INFO
2941 /* initializing backing dev info. */
2942 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2944 if (S_ISREG(inode->i_mode)) {
2945 struct ll_sb_info *sbi = ll_i2sbi(inode);
2946 inode->i_op = &ll_file_inode_operations;
2947 inode->i_fop = sbi->ll_fop;
2948 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2950 } else if (S_ISDIR(inode->i_mode)) {
2951 inode->i_op = &ll_dir_inode_operations;
2952 inode->i_fop = &ll_dir_operations;
2954 } else if (S_ISLNK(inode->i_mode)) {
2955 inode->i_op = &ll_fast_symlink_inode_operations;
2958 inode->i_op = &ll_special_inode_operations;
2960 init_special_inode(inode, inode->i_mode,
2969 void ll_delete_inode(struct inode *inode)
2971 struct ll_inode_info *lli = ll_i2info(inode);
2974 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2975 /* It is last chance to write out dirty pages,
2976 * otherwise we may lose data while umount.
2978 * If i_nlink is 0 then just discard data. This is safe because
2979 * local inode gets i_nlink 0 from server only for the last
2980 * unlink, so that file is not opened somewhere else
2982 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2983 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2986 ll_truncate_inode_pages_final(inode, NULL);
2987 ll_clear_inode(inode);
2993 /* ioctl commands shared between files and directories */
2994 int ll_iocontrol(struct inode *inode, struct file *file,
2995 unsigned int cmd, void __user *uarg)
2997 struct ll_sb_info *sbi = ll_i2sbi(inode);
2998 struct ptlrpc_request *req = NULL;
3004 RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
3005 case LL_IOC_GETVERSION:
3006 case FS_IOC_GETVERSION:
3007 RETURN(put_user(inode->i_generation, (int __user *)uarg));
3008 case FS_IOC_GETFLAGS: {
3009 struct mdt_body *body;
3010 struct md_op_data *op_data;
3012 if (!ll_access_ok(uarg, sizeof(int)))
3015 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3016 LUSTRE_OPC_ANY, NULL);
3017 if (IS_ERR(op_data))
3018 RETURN(PTR_ERR(op_data));
3020 op_data->op_valid = OBD_MD_FLFLAGS;
3021 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
3022 ll_finish_md_op_data(op_data);
3024 CERROR("%s: failure inode "DFID": rc = %d\n",
3025 sbi->ll_md_exp->exp_obd->obd_name,
3026 PFID(ll_inode2fid(inode)), rc);
3030 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3032 flags = body->mbo_flags;
3033 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
3034 * ext4 equivalent to please lsattr and other e2fsprogs tools
3036 if (flags & LUSTRE_ENCRYPT_FL)
3037 flags |= STATX_ATTR_ENCRYPTED;
3039 ptlrpc_req_finished(req);
3041 RETURN(put_user(flags, (int __user *)uarg));
3043 case FS_IOC_SETFLAGS: {
3045 struct md_op_data *op_data;
3046 struct cl_object *obj;
3047 struct fsxattr fa = { 0 };
3049 if (get_user(flags, (int __user *)uarg))
3052 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3053 if (flags & LUSTRE_PROJINHERIT_FL)
3054 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3056 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3061 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3062 LUSTRE_OPC_ANY, NULL);
3063 if (IS_ERR(op_data))
3064 RETURN(PTR_ERR(op_data));
3066 op_data->op_attr_flags = flags;
3067 op_data->op_xvalid |= OP_XVALID_FLAGS;
3068 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3069 ll_finish_md_op_data(op_data);
3070 ptlrpc_req_finished(req);
3074 ll_update_inode_flags(inode, flags);
3076 obj = ll_i2info(inode)->lli_clob;
3080 OBD_ALLOC_PTR(attr);
3084 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3089 case FS_IOC_FSGETXATTR:
3090 RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
3091 case FS_IOC_FSSETXATTR:
3092 RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
3093 case LL_IOC_PROJECT:
3094 RETURN(ll_ioctl_project(file, cmd, uarg));
3095 case IOC_OBD_STATFS:
3096 RETURN(ll_obd_statfs(inode, uarg));
3097 case LL_IOC_GET_MDTIDX: {
3098 if (!ll_access_ok(uarg, sizeof(rc)))
3101 rc = ll_get_mdt_idx(inode);
3105 if (put_user(rc, (int __user *)uarg))
3110 case LL_IOC_FLUSHCTX:
3111 RETURN(ll_flush_ctx(inode));
3112 #ifdef HAVE_LUSTRE_CRYPTO
3113 case LL_IOC_ADD_ENCRYPTION_KEY:
3114 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3116 rc = llcrypt_ioctl_add_key(file, uarg);
3117 #ifdef CONFIG_LL_ENCRYPTION
3118 if (!rc && S_ISDIR(inode->i_mode))
3119 sptlrpc_enc_pool_add_user();
3122 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
3123 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3125 RETURN(llcrypt_ioctl_get_key_status(file, uarg));
3126 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
3127 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3129 RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
3130 case LL_IOC_SET_ENCRYPTION_POLICY:
3131 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3133 RETURN(llcrypt_ioctl_set_policy(file, uarg));
3134 case LL_IOC_REMOVE_ENCRYPTION_KEY:
3135 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3137 RETURN(llcrypt_ioctl_remove_key(file, uarg));
3138 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
3139 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3141 RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
3143 case LL_IOC_GETPARENT:
3144 RETURN(ll_getparent(file, uarg));
3145 case LL_IOC_PATH2FID:
3146 if (copy_to_user(uarg, ll_inode2fid(inode),
3147 sizeof(struct lu_fid)))
3150 case LL_IOC_UNLOCK_FOREIGN: {
3151 struct dentry *dentry = file_dentry(file);
3153 /* if not a foreign symlink do nothing */
3154 if (ll_foreign_is_removable(dentry, true)) {
3156 "prevent unlink of non-foreign file ("DFID")\n",
3157 PFID(ll_inode2fid(inode)));
3158 RETURN(-EOPNOTSUPP);
3162 case OBD_IOC_FID2PATH:
3163 RETURN(ll_fid2path(inode, uarg));
3164 case OBD_IOC_GETNAME_OLD:
3165 case OBD_IOC_GETDTNAME:
3166 case OBD_IOC_GETMDNAME:
3167 RETURN(ll_get_obd_name(inode, cmd, uarg));
3175 int ll_flush_ctx(struct inode *inode)
3177 struct ll_sb_info *sbi = ll_i2sbi(inode);
3179 CDEBUG(D_SEC, "flush context for user %d\n",
3180 from_kuid(&init_user_ns, current_uid()));
3182 obd_set_info_async(NULL, sbi->ll_md_exp,
3183 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3185 obd_set_info_async(NULL, sbi->ll_dt_exp,
3186 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3191 /* umount -f client means force down, don't save state */
3192 void ll_umount_begin(struct super_block *sb)
3194 struct ll_sb_info *sbi = ll_s2sbi(sb);
3195 struct obd_device *obd;
3196 struct obd_ioctl_data *ioc_data;
3200 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3201 sb->s_count, atomic_read(&sb->s_active));
3203 obd = class_exp2obd(sbi->ll_md_exp);
3205 CERROR("Invalid MDC connection handle %#llx\n",
3206 sbi->ll_md_exp->exp_handle.h_cookie);
3212 obd = class_exp2obd(sbi->ll_dt_exp);
3214 CERROR("Invalid LOV connection handle %#llx\n",
3215 sbi->ll_dt_exp->exp_handle.h_cookie);
3221 OBD_ALLOC_PTR(ioc_data);
3223 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
3224 sizeof *ioc_data, ioc_data, NULL);
3226 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
3227 sizeof *ioc_data, ioc_data, NULL);
3229 OBD_FREE_PTR(ioc_data);
3232 /* Really, we'd like to wait until there are no requests outstanding,
3233 * and then continue. For now, we just periodically checking for vfs
3234 * to decrement mnt_cnt and hope to finish it within 10sec.
3238 !may_umount(sbi->ll_mnt.mnt)) {
3246 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3248 struct ll_sb_info *sbi = ll_s2sbi(sb);
3249 char *profilenm = get_profile_name(sb);
3253 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3254 read_only = *flags & MS_RDONLY;
3255 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3256 sizeof(KEY_READ_ONLY),
3257 KEY_READ_ONLY, sizeof(read_only),
3260 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3261 profilenm, read_only ?
3262 "read-only" : "read-write", err);
3267 sb->s_flags |= SB_RDONLY;
3269 sb->s_flags &= ~SB_RDONLY;
3271 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3272 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3273 read_only ? "read-only" : "read-write");
3279 * Cleanup the open handle that is cached on MDT-side.
3281 * For open case, the client side open handling thread may hit error
3282 * after the MDT grant the open. Under such case, the client should
3283 * send close RPC to the MDT as cleanup; otherwise, the open handle
3284 * on the MDT will be leaked there until the client umount or evicted.
3286 * In further, if someone unlinked the file, because the open handle
3287 * holds the reference on such file/object, then it will block the
3288 * subsequent threads that want to locate such object via FID.
3290 * \param[in] sb super block for this file-system
3291 * \param[in] open_req pointer to the original open request
3293 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3295 struct mdt_body *body;
3296 struct md_op_data *op_data;
3297 struct ptlrpc_request *close_req = NULL;
3298 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3301 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3302 OBD_ALLOC_PTR(op_data);
3303 if (op_data == NULL) {
3304 CWARN("%s: cannot allocate op_data to release open handle for "
3305 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3310 op_data->op_fid1 = body->mbo_fid1;
3311 op_data->op_open_handle = body->mbo_open_handle;
3312 op_data->op_mod_time = ktime_get_real_seconds();
3313 md_close(exp, op_data, NULL, &close_req);
3314 ptlrpc_req_finished(close_req);
3315 ll_finish_md_op_data(op_data);
3320 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3321 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3322 struct lustre_md *md)
3324 struct ll_sb_info *sbi = ll_i2sbi(inode);
3325 struct ptlrpc_request *req = NULL;
3326 union lmv_mds_md *lmm = NULL;
3330 LASSERT(is_root_inode(inode));
3331 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3332 LASSERT(!md->default_lmv);
3334 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3336 GET_DEFAULT_LAYOUT_ROOT);
3337 if (rc && rc != -ENODATA)
3342 rc = md_unpackmd(sbi->ll_md_exp, &md->default_lmv, lmm, size);
3351 ptlrpc_req_finished(req);
3355 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3356 struct super_block *sb, struct lookup_intent *it)
3358 struct ll_sb_info *sbi = NULL;
3359 struct lustre_md md = { NULL };
3360 bool default_lmv_deleted = false;
3365 LASSERT(*inode || sb);
3366 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3367 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3368 sbi->ll_md_exp, &md);
3373 * clear default_lmv only if intent_getattr reply doesn't contain it.
3374 * but it needs to be done after iget, check this early because
3375 * ll_update_lsm_md() may change md.
3377 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3378 S_ISDIR(md.body->mbo_mode) && !md.default_lmv) {
3379 if (unlikely(*inode && is_root_inode(*inode) &&
3380 !fid_is_root(&sbi->ll_root_fid))) {
3381 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3386 if (!md.default_lmv)
3387 default_lmv_deleted = true;
3391 rc = ll_update_inode(*inode, &md);
3395 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3396 struct lu_fid *fid1 = &md.body->mbo_fid1;
3398 LASSERT(sb != NULL);
3401 * At this point server returns to client's same fid as client
3402 * generated for creating. So using ->fid1 is okay here.
3404 if (!fid_is_sane(fid1)) {
3405 CERROR("%s: Fid is insane "DFID"\n",
3406 sbi->ll_fsname, PFID(fid1));
3407 GOTO(out, rc = -EINVAL);
3410 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3411 if (IS_ERR(*inode)) {
3413 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3415 CERROR("new_inode -fatal: rc %d\n", rc);
3420 /* Handling piggyback layout lock.
3421 * Layout lock can be piggybacked by getattr and open request.
3422 * The lsm can be applied to inode only if it comes with a layout lock
3423 * otherwise correct layout may be overwritten, for example:
3424 * 1. proc1: mdt returns a lsm but not granting layout
3425 * 2. layout was changed by another client
3426 * 3. proc2: refresh layout and layout lock granted
3427 * 4. proc1: to apply a stale layout */
3428 if (it != NULL && it->it_lock_mode != 0) {
3429 struct lustre_handle lockh;
3430 struct ldlm_lock *lock;
3432 lockh.cookie = it->it_lock_handle;
3433 lock = ldlm_handle2lock(&lockh);
3434 LASSERT(lock != NULL);
3435 if (ldlm_has_layout(lock)) {
3436 struct cl_object_conf conf;
3438 memset(&conf, 0, sizeof(conf));
3439 conf.coc_opc = OBJECT_CONF_SET;
3440 conf.coc_inode = *inode;
3441 conf.coc_lock = lock;
3442 conf.u.coc_layout = md.layout;
3443 (void)ll_layout_conf(*inode, &conf);
3445 LDLM_LOCK_PUT(lock);
3448 if (default_lmv_deleted)
3449 ll_update_default_lsm_md(*inode, &md);
3451 /* we may want to apply some policy for foreign file/dir */
3452 if (ll_sbi_has_foreign_symlink(sbi)) {
3453 rc = ll_manage_foreign(*inode, &md);
3461 /* cleanup will be done if necessary */
3462 md_free_lustre_md(sbi->ll_md_exp, &md);
3464 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3465 ll_intent_drop_lock(it);
3466 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3472 int ll_obd_statfs(struct inode *inode, void __user *uarg)
3474 struct ll_sb_info *sbi = NULL;
3475 struct obd_export *exp;
3476 struct obd_ioctl_data *data = NULL;
3481 sbi = ll_i2sbi(inode);
3483 GOTO(out_statfs, rc = -EINVAL);
3485 rc = obd_ioctl_getdata(&data, &len, uarg);
3487 GOTO(out_statfs, rc);
3489 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3490 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3491 GOTO(out_statfs, rc = -EINVAL);
3493 if (data->ioc_inllen1 != sizeof(__u32) ||
3494 data->ioc_inllen2 != sizeof(__u32) ||
3495 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3496 data->ioc_plen2 != sizeof(struct obd_uuid))
3497 GOTO(out_statfs, rc = -EINVAL);
3499 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3500 if (type & LL_STATFS_LMV)
3501 exp = sbi->ll_md_exp;
3502 else if (type & LL_STATFS_LOV)
3503 exp = sbi->ll_dt_exp;
3505 GOTO(out_statfs, rc = -ENODEV);
3507 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3509 GOTO(out_statfs, rc);
3511 OBD_FREE_LARGE(data, len);
3516 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3517 * be called early to avoid deadlock.
3519 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3521 if (op_data->op_mea2_sem) {
3522 up_read_non_owner(op_data->op_mea2_sem);
3523 op_data->op_mea2_sem = NULL;
3526 if (op_data->op_mea1_sem) {
3527 up_read_non_owner(op_data->op_mea1_sem);
3528 op_data->op_mea1_sem = NULL;
3532 /* this function prepares md_op_data hint for passing it down to MD stack. */
3533 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3534 struct inode *i1, struct inode *i2,
3535 const char *name, size_t namelen,
3536 __u32 mode, enum md_op_code opc,
3539 struct llcrypt_name fname = { 0 };
3542 LASSERT(i1 != NULL);
3545 /* Do not reuse namelen for something else. */
3547 return ERR_PTR(-EINVAL);
3549 if ((!IS_ENCRYPTED(i1) ||
3550 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3551 namelen > ll_i2sbi(i1)->ll_namelen)
3552 return ERR_PTR(-ENAMETOOLONG);
3554 /* "/" is not valid name, but it's allowed */
3555 if (!lu_name_is_valid_2(name, namelen) &&
3556 strncmp("/", name, namelen) != 0)
3557 return ERR_PTR(-EINVAL);
3560 if (op_data == NULL)
3561 OBD_ALLOC_PTR(op_data);
3563 if (op_data == NULL)
3564 return ERR_PTR(-ENOMEM);
3566 ll_i2gids(op_data->op_suppgids, i1, i2);
3567 /* If the client is using a subdir mount and looks at what it sees as
3568 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3570 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3571 !fid_is_root(ll_inode2fid(i1)) &&
3572 name && namelen == strlen(dot_fscrypt_name) &&
3573 strncmp(name, dot_fscrypt_name, namelen) == 0))
3574 lu_root_fid(&op_data->op_fid1);
3576 op_data->op_fid1 = *ll_inode2fid(i1);
3578 if (S_ISDIR(i1->i_mode)) {
3579 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3580 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3581 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3582 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3586 op_data->op_fid2 = *ll_inode2fid(i2);
3587 if (S_ISDIR(i2->i_mode)) {
3589 /* i2 is typically a child of i1, and MUST be
3590 * further from the root to avoid deadlocks.
3592 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3593 op_data->op_mea2_sem =
3594 &ll_i2info(i2)->lli_lsm_sem;
3596 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3599 fid_zero(&op_data->op_fid2);
3602 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3603 op_data->op_cli_flags |= CLI_HASH64;
3605 if (ll_need_32bit_api(ll_i2sbi(i1)))
3606 op_data->op_cli_flags |= CLI_API32;
3608 if ((i2 && is_root_inode(i2)) ||
3609 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3610 /* In case of lookup, ll_setup_filename() has already been
3611 * called in ll_lookup_it(), so just take provided name.
3612 * Also take provided name if we are dealing with root inode.
3614 fname.disk_name.name = (unsigned char *)name;
3615 fname.disk_name.len = namelen;
3616 } else if (name && namelen) {
3617 struct qstr dname = QSTR_INIT(name, namelen);
3619 struct lu_fid *pfid = NULL;
3623 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3624 /* special case when called from ll_link() */
3629 lookup = (int)(opc == LUSTRE_OPC_ANY);
3631 if (opc == LUSTRE_OPC_ANY && lookup)
3633 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3635 ll_finish_md_op_data(op_data);
3638 if (pfid && !fid_is_zero(pfid)) {
3640 op_data->op_fid2 = fid;
3641 op_data->op_bias = MDS_FID_OP;
3643 if (fname.disk_name.name &&
3644 fname.disk_name.name != (unsigned char *)name) {
3645 /* op_data->op_name must be freed after use */
3646 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3650 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3651 * are LUSTRE_OPC_ANY
3653 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3654 op_data->op_code = LUSTRE_OPC_ANY;
3656 op_data->op_code = opc;
3657 op_data->op_name = fname.disk_name.name;
3658 op_data->op_namelen = fname.disk_name.len;
3659 op_data->op_mode = mode;
3660 op_data->op_mod_time = ktime_get_real_seconds();
3661 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3662 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3663 op_data->op_cap = current_cap();
3664 op_data->op_mds = 0;
3665 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3666 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3667 op_data->op_bias |= MDS_CREATE_VOLATILE;
3669 op_data->op_data = data;
3674 void ll_finish_md_op_data(struct md_op_data *op_data)
3676 ll_unlock_md_op_lsm(op_data);
3677 ll_security_release_secctx(op_data->op_file_secctx,
3678 op_data->op_file_secctx_size);
3679 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3680 /* allocated via ll_setup_filename called
3681 * from ll_prep_md_op_data
3683 kfree(op_data->op_name);
3684 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3685 OBD_FREE_PTR(op_data);
3688 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3690 struct ll_sb_info *sbi;
3693 LASSERT(seq && dentry);
3694 sbi = ll_s2sbi(dentry->d_sb);
3696 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3697 seq_puts(seq, "nolock");
3699 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3700 /* match_table in some cases has patterns for both enabled and
3701 * disabled cases. Ignore 'no'xxx versions if bit is set.
3703 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3704 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3705 if (ll_sbi_flags_name[i].token ==
3706 LL_SBI_FOREIGN_SYMLINK) {
3707 seq_show_option(seq, "foreign_symlink",
3708 sbi->ll_foreign_symlink_prefix);
3710 seq_printf(seq, ",%s",
3711 ll_sbi_flags_name[i].pattern);
3714 /* You can have either localflock or flock but not
3715 * both. If localflock is set don't print flock or
3718 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3720 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3721 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3722 seq_printf(seq, ",%s",
3723 ll_sbi_flags_name[i].pattern);
3727 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3733 * Get obd name by cmd, and copy out to user space
3735 int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg)
3737 struct ll_sb_info *sbi = ll_i2sbi(inode);
3738 struct obd_device *obd;
3741 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3742 obd = class_exp2obd(sbi->ll_dt_exp);
3743 else if (cmd == OBD_IOC_GETMDNAME)
3744 obd = class_exp2obd(sbi->ll_md_exp);
3751 if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1))
3758 struct work_struct db_work;
3759 struct dentry *db_dentry;
3760 /* Let's hope the path is not too long, 32 bytes for the work struct
3763 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3766 static void ll_dput_later(struct work_struct *work)
3768 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3770 dput(db->db_dentry);
3771 free_page((unsigned long)db);
3774 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3781 p.mnt = current->fs->root.mnt;
3783 path = d_path(&p, buf, bufsize);
3788 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3790 struct dname_buf *db;
3792 struct dentry *dentry = NULL;
3794 /* this can be called inside spin lock so use GFP_ATOMIC. */
3795 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3798 dentry = d_find_alias(inode);
3800 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3803 /* The below message is checked in recovery-small.sh test_24b */
3805 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3806 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3807 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3808 PFID(ll_inode2fid(inode)),
3809 (path && !IS_ERR(path)) ? path : "", ioret);
3811 if (dentry != NULL) {
3812 /* We cannot dput here since if we happen to be the last holder
3813 * then we can end up waiting for page evictions that
3814 * in turn wait for RPCs that need this instance of ptlrpcd
3815 * (callng brw_interpret->*page_completion*->vmpage_error->here)
3818 INIT_WORK(&db->db_work, ll_dput_later);
3819 db->db_dentry = dentry;
3820 schedule_work(&db->db_work);
3823 free_page((unsigned long)db);
3827 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3828 struct lov_user_md **kbuf)
3830 struct lov_user_md lum;
3834 if (copy_from_user(&lum, md, sizeof(lum)))
3837 lum_size = ll_lov_user_md_size(&lum);
3841 OBD_ALLOC_LARGE(*kbuf, lum_size);
3845 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3846 OBD_FREE_LARGE(*kbuf, lum_size);
3854 * Compute llite root squash state after a change of root squash
3855 * configuration setting or add/remove of a lnet nid
3857 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3859 struct root_squash_info *squash = &sbi->ll_squash;
3862 struct lnet_processid id;
3864 /* Update norootsquash flag */
3865 spin_lock(&squash->rsi_lock);
3866 if (list_empty(&squash->rsi_nosquash_nids))
3867 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3869 /* Do not apply root squash as soon as one of our NIDs is
3870 * in the nosquash_nids list */
3873 while (LNetGetId(i++, &id) != -ENOENT) {
3874 if (nid_is_lo0(&id.nid))
3876 if (cfs_match_nid(&id.nid,
3877 &squash->rsi_nosquash_nids)) {
3883 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3885 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3887 spin_unlock(&squash->rsi_lock);
3891 * Parse linkea content to extract information about a given hardlink
3893 * \param[in] ldata - Initialized linkea data
3894 * \param[in] linkno - Link identifier
3895 * \param[out] parent_fid - The entry's parent FID
3896 * \param[out] ln - Entry name destination buffer
3898 * \retval 0 on success
3899 * \retval Appropriate negative error code on failure
3901 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3902 struct lu_fid *parent_fid, struct lu_name *ln)
3908 rc = linkea_init_with_rec(ldata);
3912 if (linkno >= ldata->ld_leh->leh_reccount)
3913 /* beyond last link */
3916 linkea_first_entry(ldata);
3917 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3918 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3923 linkea_next_entry(ldata);
3933 * Get parent FID and name of an identified link. Operation is performed for
3934 * a given link number, letting the caller iterate over linkno to list one or
3935 * all links of an entry.
3937 * \param[in] file - File descriptor against which to perform the operation
3938 * \param[in,out] arg - User-filled structure containing the linkno to operate
3939 * on and the available size. It is eventually filled with
3940 * the requested information or left untouched on error
3942 * \retval - 0 on success
3943 * \retval - Appropriate negative error code on failure
3945 int ll_getparent(struct file *file, struct getparent __user *arg)
3947 struct inode *inode = file_inode(file);
3948 struct linkea_data *ldata;
3949 struct lu_buf buf = LU_BUF_NULL;
3951 struct lu_fid parent_fid;
3958 if (!capable(CAP_DAC_READ_SEARCH) &&
3959 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
3962 if (get_user(name_size, &arg->gp_name_size))
3965 if (get_user(linkno, &arg->gp_linkno))
3968 if (name_size > PATH_MAX)
3971 OBD_ALLOC(ldata, sizeof(*ldata));
3975 rc = linkea_data_new(ldata, &buf);
3977 GOTO(ldata_free, rc);
3979 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3980 buf.lb_len, OBD_MD_FLXATTR);
3984 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3988 if (ln.ln_namelen >= name_size)
3989 GOTO(lb_free, rc = -EOVERFLOW);
3991 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3992 GOTO(lb_free, rc = -EFAULT);
3994 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3995 GOTO(lb_free, rc = -EFAULT);
3997 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3998 GOTO(lb_free, rc = -EFAULT);
4003 OBD_FREE(ldata, sizeof(*ldata));