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 #include <lustre_ioctl_old.h>
60 #ifdef HAVE_UAPI_LINUX_MOUNT_H
61 #include <uapi/linux/mount.h>
64 #include <lustre_ha.h>
65 #include <lustre_dlm.h>
66 #include <lprocfs_status.h>
67 #include <lustre_disk.h>
68 #include <uapi/linux/lustre/lustre_param.h>
69 #include <lustre_log.h>
70 #include <cl_object.h>
71 #include <obd_cksum.h>
72 #include "llite_internal.h"
74 struct kmem_cache *ll_file_data_slab;
77 #define log2(n) ffz(~(n))
81 * If there is only one number of core visible to Lustre,
82 * async readahead will be disabled, to avoid massive over
83 * subscription, we use 1/2 of active cores as default max
84 * async readahead requests.
86 static inline unsigned int ll_get_ra_async_max_active(void)
88 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
91 static struct ll_sb_info *ll_init_sbi(struct lustre_sb_info *lsi)
93 struct ll_sb_info *sbi = NULL;
95 unsigned long lru_page_max;
103 RETURN(ERR_PTR(-ENOMEM));
105 rc = pcc_super_init(&sbi->ll_pcc_super);
109 spin_lock_init(&sbi->ll_lock);
110 mutex_init(&sbi->ll_lco.lco_lock);
111 spin_lock_init(&sbi->ll_pp_extent_lock);
112 spin_lock_init(&sbi->ll_process_lock);
114 sbi->ll_rw_stats_on = 0;
115 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
118 pages = si.totalram - si.totalhigh;
119 lru_page_max = pages / 2;
121 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
122 sbi->ll_ra_info.ll_readahead_wq =
123 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
125 sbi->ll_ra_info.ra_async_max_active);
126 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
127 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
129 /* initialize ll_cache data */
130 sbi->ll_cache = cl_cache_init(lru_page_max);
131 if (sbi->ll_cache == NULL)
132 GOTO(out_destroy_ra, rc = -ENOMEM);
134 /* initialize foreign symlink prefix path */
135 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
136 if (sbi->ll_foreign_symlink_prefix == NULL)
137 GOTO(out_destroy_ra, rc = -ENOMEM);
138 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
139 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
141 /* initialize foreign symlink upcall path, none by default */
142 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
143 if (sbi->ll_foreign_symlink_upcall == NULL)
144 GOTO(out_destroy_ra, rc = -ENOMEM);
145 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
146 sbi->ll_foreign_symlink_upcall_items = NULL;
147 sbi->ll_foreign_symlink_upcall_nb_items = 0;
148 init_rwsem(&sbi->ll_foreign_symlink_sem);
149 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
150 * not enabled by default
153 sbi->ll_secctx_name = NULL;
154 sbi->ll_secctx_name_size = 0;
156 sbi->ll_ra_info.ra_max_pages =
157 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
158 sbi->ll_ra_info.ra_max_pages_per_file =
159 min(sbi->ll_ra_info.ra_max_pages / 4,
160 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
161 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
162 sbi->ll_ra_info.ra_max_pages_per_file;
163 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
164 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
165 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
167 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
168 #ifdef ENABLE_CHECKSUM
169 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
172 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
175 #ifdef HAVE_LRU_RESIZE_SUPPORT
176 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
178 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
180 /* metadata statahead is enabled by default */
181 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
182 sbi->ll_sa_batch_max = LL_SA_BATCH_DEF;
183 sbi->ll_sa_max = LL_SA_RPC_DEF;
184 atomic_set(&sbi->ll_sa_total, 0);
185 atomic_set(&sbi->ll_sa_wrong, 0);
186 atomic_set(&sbi->ll_sa_running, 0);
187 atomic_set(&sbi->ll_agl_total, 0);
188 atomic_set(&sbi->ll_sa_hit_total, 0);
189 atomic_set(&sbi->ll_sa_miss_total, 0);
190 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
191 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
192 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
193 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
194 ll_sbi_set_encrypt(sbi, true);
195 ll_sbi_set_name_encrypt(sbi, true);
198 sbi->ll_squash.rsi_uid = 0;
199 sbi->ll_squash.rsi_gid = 0;
200 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
201 spin_lock_init(&sbi->ll_squash.rsi_lock);
203 /* Per-filesystem file heat */
204 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
205 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
207 /* Per-fs open heat level before requesting open lock */
208 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
209 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
210 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
213 if (sbi->ll_foreign_symlink_prefix)
214 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
216 cl_cache_decref(sbi->ll_cache);
217 sbi->ll_cache = NULL;
219 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
221 pcc_super_fini(&sbi->ll_pcc_super);
227 static void ll_free_sbi(struct super_block *sb)
229 struct ll_sb_info *sbi = ll_s2sbi(sb);
233 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
234 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
235 if (sbi->ll_ra_info.ll_readahead_wq)
236 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
237 if (sbi->ll_cache != NULL) {
238 cl_cache_decref(sbi->ll_cache);
239 sbi->ll_cache = NULL;
241 if (sbi->ll_foreign_symlink_prefix) {
242 OBD_FREE(sbi->ll_foreign_symlink_prefix,
243 sbi->ll_foreign_symlink_prefix_size);
244 sbi->ll_foreign_symlink_prefix = NULL;
246 if (sbi->ll_foreign_symlink_upcall) {
247 OBD_FREE(sbi->ll_foreign_symlink_upcall,
248 strlen(sbi->ll_foreign_symlink_upcall) +
250 sbi->ll_foreign_symlink_upcall = NULL;
252 if (sbi->ll_foreign_symlink_upcall_items) {
254 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
255 struct ll_foreign_symlink_upcall_item *items =
256 sbi->ll_foreign_symlink_upcall_items;
258 for (i = 0 ; i < nb_items; i++)
259 if (items[i].type == STRING_TYPE)
260 OBD_FREE(items[i].string,
263 OBD_FREE_LARGE(items, nb_items *
264 sizeof(struct ll_foreign_symlink_upcall_item));
265 sbi->ll_foreign_symlink_upcall_items = NULL;
267 if (sbi->ll_secctx_name)
268 ll_secctx_name_free(sbi);
270 ll_free_rw_stats_info(sbi);
271 pcc_super_fini(&sbi->ll_pcc_super);
272 OBD_FREE(sbi, sizeof(*sbi));
277 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
279 struct inode *root = NULL;
280 struct ll_sb_info *sbi = ll_s2sbi(sb);
281 struct obd_statfs *osfs = NULL;
282 struct ptlrpc_request *request = NULL;
283 struct obd_connect_data *data = NULL;
284 struct obd_uuid *uuid;
285 struct md_op_data *op_data;
286 struct lustre_md lmd;
288 int size, err, checksum;
294 sbi->ll_md_obd = class_name2obd(md);
295 if (!sbi->ll_md_obd) {
296 CERROR("MD %s: not setup or attached\n", md);
310 /* pass client page size via ocd_grant_blkbits, the server should report
311 * back its backend blocksize for grant calculation purpose */
312 data->ocd_grant_blkbits = PAGE_SHIFT;
314 /* indicate MDT features supported by this client */
315 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
316 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
317 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
318 OBD_CONNECT_SRVLOCK |
319 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
320 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
321 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
322 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
323 OBD_CONNECT_64BITHASH |
324 OBD_CONNECT_EINPROGRESS |
325 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
326 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
327 OBD_CONNECT_MAX_EASIZE |
328 OBD_CONNECT_FLOCK_DEAD |
329 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
330 OBD_CONNECT_OPEN_BY_FID |
331 OBD_CONNECT_DIR_STRIPE |
332 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
333 OBD_CONNECT_SUBTREE |
334 OBD_CONNECT_MULTIMODRPCS |
335 OBD_CONNECT_GRANT_PARAM |
336 OBD_CONNECT_GRANT_SHRINK |
337 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
339 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
340 OBD_CONNECT2_SUM_STATFS |
341 OBD_CONNECT2_OVERSTRIPING |
343 OBD_CONNECT2_LOCK_CONVERT |
344 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
345 OBD_CONNECT2_INC_XID |
347 OBD_CONNECT2_ASYNC_DISCARD |
349 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
350 OBD_CONNECT2_GETATTR_PFID |
351 OBD_CONNECT2_DOM_LVB |
352 OBD_CONNECT2_REP_MBITS |
353 OBD_CONNECT2_ATOMIC_OPEN_LOCK |
354 OBD_CONNECT2_BATCH_RPC;
356 #ifdef HAVE_LRU_RESIZE_SUPPORT
357 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
358 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
360 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
362 data->ocd_cksum_types = obd_cksum_types_supported_client();
364 if (CFS_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
365 /* flag mdc connection as lightweight, only used for test
366 * purpose, use with care */
367 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
369 data->ocd_ibits_known = MDS_INODELOCK_FULL;
370 data->ocd_version = LUSTRE_VERSION_CODE;
372 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
373 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
376 /* Setting this indicates we correctly support S_NOSEC (See kernel
377 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
379 sb->s_flags |= SB_NOSEC;
381 sbi->ll_fop = ll_select_file_operations(sbi);
383 /* always ping even if server suppress_pings */
384 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
385 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
387 obd_connect_set_secctx(data);
388 if (ll_sbi_has_encrypt(sbi)) {
389 obd_connect_set_enc_fid2path(data);
390 obd_connect_set_name_enc(data);
391 obd_connect_set_enc(data);
394 #if defined(CONFIG_SECURITY)
395 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
398 data->ocd_brw_size = MD_MAX_BRW_SIZE;
401 if (sb->s_flags & SB_RDONLY)
402 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
403 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
404 &sbi->ll_sb_uuid, data, sbi->ll_cache);
406 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
407 "recovery, of which this client is not a "
408 "part. Please wait for recovery to complete,"
409 " abort, or time out.\n", md);
412 CERROR("cannot connect to %s: rc = %d\n", md, err);
416 sbi->ll_md_exp->exp_connect_data = *data;
418 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
419 LUSTRE_SEQ_METADATA);
421 CERROR("%s: Can't init metadata layer FID infrastructure, "
422 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
426 /* For mount, we only need fs info from MDT0, and also in DNE, it
427 * can make sure the client can be mounted as long as MDT0 is
429 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
430 ktime_get_seconds() - sbi->ll_statfs_max_age,
431 OBD_STATFS_FOR_MDT0);
432 if (err == -EROFS && !(sb->s_flags & SB_RDONLY)) {
433 /* We got -EROFS from the server, maybe it is imposing
434 * read-only mount. So just retry like this.
436 cfs_tty_write_msg("Forcing read-only mount.\n\r");
437 CERROR("%s: mount failed with %d, forcing read-only mount.\n",
438 sbi->ll_md_exp->exp_obd->obd_name, err);
439 sb->s_flags |= SB_RDONLY;
440 obd_fid_fini(sbi->ll_md_exp->exp_obd);
441 obd_disconnect(sbi->ll_md_exp);
442 GOTO(retry_connect, err);
444 GOTO(out_md_fid, err);
447 /* This needs to be after statfs to ensure connect has finished.
448 * Note that "data" does NOT contain the valid connect reply.
449 * If connecting to a 1.8 server there will be no LMV device, so
450 * we can access the MDC export directly and exp_connect_flags will
451 * be non-zero, but if accessing an upgraded 2.1 server it will
452 * have the correct flags filled in.
453 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
454 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
455 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
456 valid != CLIENT_CONNECT_MDT_REQD) {
459 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
460 obd_connect_flags2str(buf, PAGE_SIZE,
461 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
462 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
463 "feature(s) needed for correct operation "
464 "of this client (%s). Please upgrade "
465 "server or downgrade client.\n",
466 sbi->ll_md_exp->exp_obd->obd_name, buf);
467 OBD_FREE(buf, PAGE_SIZE);
468 GOTO(out_md_fid, err = -EPROTO);
471 size = sizeof(*data);
472 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
473 KEY_CONN_DATA, &size, data);
475 CERROR("%s: Get connect data failed: rc = %d\n",
476 sbi->ll_md_exp->exp_obd->obd_name, err);
477 GOTO(out_md_fid, err);
480 LASSERT(osfs->os_bsize);
481 sb->s_blocksize = osfs->os_bsize;
482 sb->s_blocksize_bits = log2(osfs->os_bsize);
483 sb->s_magic = LL_SUPER_MAGIC;
484 sb->s_maxbytes = MAX_LFS_FILESIZE;
485 sbi->ll_inode_cache_enabled = 1;
486 sbi->ll_namelen = osfs->os_namelen;
487 sbi->ll_mnt.mnt = current->fs->root.mnt;
488 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
490 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
491 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
492 LCONSOLE_INFO("Disabling user_xattr feature because "
493 "it is not supported on the server\n");
494 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
497 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
499 sb->s_flags |= SB_POSIXACL;
501 set_bit(LL_SBI_ACL, sbi->ll_flags);
503 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
505 sb->s_flags &= ~SB_POSIXACL;
507 clear_bit(LL_SBI_ACL, sbi->ll_flags);
510 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
511 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
513 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
514 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
516 if (obd_connect_has_secctx(data))
517 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
519 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
520 if (ll_sb_has_test_dummy_encryption(sb))
521 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
523 sbi->ll_md_exp->exp_obd->obd_name);
524 ll_sbi_set_encrypt(sbi, false);
527 if (ll_sbi_has_name_encrypt(sbi) && !obd_connect_has_name_enc(data)) {
528 struct lustre_sb_info *lsi = s2lsi(sb);
530 if (ll_sb_has_test_dummy_encryption(sb))
531 LCONSOLE_WARN("%s: server %s does not support name encryption, not using it.\n",
533 sbi->ll_md_exp->exp_obd->obd_name);
534 #ifdef CONFIG_LL_ENCRYPTION
535 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
537 lsi->lsi_flags &= ~LSI_FILENAME_ENC_B64_OLD_CLI;
538 ll_sbi_set_name_encrypt(sbi, false);
541 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
542 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
543 LCONSOLE_INFO("%s: disabling xattr cache due to "
544 "unknown maximum xattr size.\n", dt);
545 } else if (!sbi->ll_xattr_cache_set) {
546 /* If xattr_cache is already set (no matter 0 or 1)
547 * during processing llog, it won't be enabled here. */
548 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
549 sbi->ll_xattr_cache_enabled = 1;
553 sbi->ll_dt_obd = class_name2obd(dt);
554 if (!sbi->ll_dt_obd) {
555 CERROR("DT %s: not setup or attached\n", dt);
556 GOTO(out_md_fid, err = -ENODEV);
559 /* pass client page size via ocd_grant_blkbits, the server should report
560 * back its backend blocksize for grant calculation purpose */
561 data->ocd_grant_blkbits = PAGE_SHIFT;
563 /* indicate OST features supported by this client */
564 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
565 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
566 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
567 OBD_CONNECT_SRVLOCK |
568 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
569 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
570 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
571 OBD_CONNECT_EINPROGRESS |
572 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
573 OBD_CONNECT_LAYOUTLOCK |
574 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
575 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
576 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
577 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
578 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
579 OBD_CONNECT2_REP_MBITS;
581 if (!CFS_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
582 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
584 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
585 * disabled by default, because it can still be enabled on the
586 * fly via /sys. As a consequence, we still need to come to an
587 * agreement on the supported algorithms at connect time
589 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
591 if (CFS_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
592 data->ocd_cksum_types = OBD_CKSUM_ADLER;
594 data->ocd_cksum_types = obd_cksum_types_supported_client();
596 #ifdef HAVE_LRU_RESIZE_SUPPORT
597 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
599 /* always ping even if server suppress_pings */
600 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
601 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
603 if (ll_sbi_has_encrypt(sbi))
604 obd_connect_set_enc(data);
606 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
607 "ocd_grant: %d\n", data->ocd_connect_flags,
608 data->ocd_version, data->ocd_grant);
610 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
611 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
613 data->ocd_brw_size = DT_MAX_BRW_SIZE;
615 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
616 &sbi->ll_sb_uuid, data, sbi->ll_cache);
618 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
619 "recovery, of which this client is not a "
620 "part. Please wait for recovery to "
621 "complete, abort, or time out.\n", dt);
624 CERROR("%s: Cannot connect to %s: rc = %d\n",
625 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
629 if (ll_sbi_has_encrypt(sbi) &&
630 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
631 if (ll_sb_has_test_dummy_encryption(sb))
632 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
634 ll_sbi_set_encrypt(sbi, false);
635 } else if (ll_sb_has_test_dummy_encryption(sb)) {
636 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
639 sbi->ll_dt_exp->exp_connect_data = *data;
641 /* Don't change value if it was specified in the config log */
642 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
643 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
644 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
645 (data->ocd_brw_size >> PAGE_SHIFT));
646 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
647 sbi->ll_ra_info.ra_max_pages_per_file)
648 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
649 sbi->ll_ra_info.ra_max_pages_per_file;
652 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
653 LUSTRE_SEQ_METADATA);
655 CERROR("%s: Can't init data layer FID infrastructure, "
656 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
660 mutex_lock(&sbi->ll_lco.lco_lock);
661 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
662 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
663 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
664 mutex_unlock(&sbi->ll_lco.lco_lock);
666 fid_zero(&sbi->ll_root_fid);
667 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
670 CERROR("cannot mds_connect: rc = %d\n", err);
671 GOTO(out_lock_cn_cb, err);
673 if (!fid_is_sane(&sbi->ll_root_fid)) {
674 CERROR("%s: Invalid root fid "DFID" during mount\n",
675 sbi->ll_md_exp->exp_obd->obd_name,
676 PFID(&sbi->ll_root_fid));
677 GOTO(out_lock_cn_cb, err = -EINVAL);
679 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
681 sb->s_op = &lustre_super_operations;
682 sb->s_xattr = ll_xattr_handlers;
683 #if THREAD_SIZE >= 8192 /*b=17630*/
684 sb->s_export_op = &lustre_export_operations;
686 #ifdef HAVE_LUSTRE_CRYPTO
687 llcrypt_set_ops(sb, &lustre_cryptops);
691 * XXX: move this to after cbd setup? */
692 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
694 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
695 valid |= OBD_MD_FLACL;
697 OBD_ALLOC_PTR(op_data);
699 GOTO(out_lock_cn_cb, err = -ENOMEM);
701 op_data->op_fid1 = sbi->ll_root_fid;
702 op_data->op_mode = 0;
703 op_data->op_valid = valid;
705 err = md_getattr(sbi->ll_md_exp, op_data, &request);
707 /* We need enc ctx info, so reset it in op_data to
708 * prevent it from being freed.
710 encctx = op_data->op_file_encctx;
711 encctxlen = op_data->op_file_encctx_size;
712 op_data->op_file_encctx = NULL;
713 op_data->op_file_encctx_size = 0;
714 OBD_FREE_PTR(op_data);
716 CERROR("%s: md_getattr failed for root: rc = %d\n",
717 sbi->ll_md_exp->exp_obd->obd_name, err);
718 GOTO(out_lock_cn_cb, err);
721 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
722 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
724 CERROR("failed to understand root inode md: rc = %d\n", err);
725 ptlrpc_req_finished(request);
726 GOTO(out_lock_cn_cb, err);
729 LASSERT(fid_is_sane(&sbi->ll_root_fid));
730 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
731 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
732 md_free_lustre_md(sbi->ll_md_exp, &lmd);
736 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
738 CERROR("%s: bad ll_iget() for root: rc = %d\n",
739 sbi->ll_fsname, err);
740 ptlrpc_req_finished(request);
744 err = ll_secctx_name_store(root);
745 if (err < 0 && ll_security_xattr_wanted(root))
746 CWARN("%s: file security contextes not supported: rc = %d\n",
747 sbi->ll_fsname, err);
752 "server returned encryption ctx for root inode "DFID"\n",
753 PFID(&sbi->ll_root_fid));
754 err = ll_set_encflags(root, encctx, encctxlen, true);
756 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
758 PFID(&sbi->ll_root_fid), err);
760 ptlrpc_req_finished(request);
762 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
763 if (sbi->ll_checksum_set) {
764 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
765 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
766 sizeof(checksum), &checksum, NULL);
768 CERROR("%s: Set checksum failed: rc = %d\n",
769 sbi->ll_dt_exp->exp_obd->obd_name, err);
775 sb->s_root = d_make_root(root);
776 if (sb->s_root == NULL) {
778 CERROR("%s: can't make root dentry: rc = %d\n",
779 sbi->ll_fsname, err);
783 sbi->ll_sdev_orig = sb->s_dev;
785 /* We set sb->s_dev equal on all lustre clients in order to support
786 * NFS export clustering. NFSD requires that the FSID be the same
788 /* s_dev is also used in lt_compare() to compare two fs, but that is
789 * only a node-local comparison. */
790 uuid = obd_get_uuid(sbi->ll_md_exp);
792 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
799 if (sbi->ll_dt_obd) {
800 err = sysfs_create_link(&sbi->ll_kset.kobj,
801 &sbi->ll_dt_obd->obd_kset.kobj,
802 sbi->ll_dt_obd->obd_type->typ_name);
804 CERROR("%s: could not register %s in llite: rc = %d\n",
805 dt, sbi->ll_fsname, err);
810 if (sbi->ll_md_obd) {
811 err = sysfs_create_link(&sbi->ll_kset.kobj,
812 &sbi->ll_md_obd->obd_kset.kobj,
813 sbi->ll_md_obd->obd_type->typ_name);
815 CERROR("%s: could not register %s in llite: rc = %d\n",
816 md, sbi->ll_fsname, err);
825 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
827 obd_disconnect(sbi->ll_dt_exp);
828 sbi->ll_dt_exp = NULL;
829 sbi->ll_dt_obd = NULL;
831 obd_fid_fini(sbi->ll_md_exp->exp_obd);
833 obd_disconnect(sbi->ll_md_exp);
834 sbi->ll_md_exp = NULL;
835 sbi->ll_md_obd = NULL;
844 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
848 size = sizeof(*lmmsize);
849 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
850 KEY_MAX_EASIZE, &size, lmmsize);
852 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
853 sbi->ll_dt_exp->exp_obd->obd_name, rc);
857 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
860 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
861 KEY_MAX_EASIZE, &size, lmmsize);
863 CERROR("Get max mdsize error rc %d\n", rc);
865 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
871 * Get the value of the default_easize parameter.
873 * \see client_obd::cl_default_mds_easize
875 * \param[in] sbi superblock info for this filesystem
876 * \param[out] lmmsize pointer to storage location for value
878 * \retval 0 on success
879 * \retval negative negated errno on failure
881 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
886 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
887 KEY_DEFAULT_EASIZE, &size, lmmsize);
889 CERROR("Get default mdsize error rc %d\n", rc);
895 * Set the default_easize parameter to the given value.
897 * \see client_obd::cl_default_mds_easize
899 * \param[in] sbi superblock info for this filesystem
900 * \param[in] lmmsize the size to set
902 * \retval 0 on success
903 * \retval negative negated errno on failure
905 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
909 if (lmmsize < sizeof(struct lov_mds_md) ||
910 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
913 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
914 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
915 sizeof(int), &lmmsize, NULL);
920 static void client_common_put_super(struct super_block *sb)
922 struct ll_sb_info *sbi = ll_s2sbi(sb);
927 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
928 obd_disconnect(sbi->ll_dt_exp);
929 sbi->ll_dt_exp = NULL;
931 ll_debugfs_unregister_super(sb);
933 obd_fid_fini(sbi->ll_md_exp->exp_obd);
934 obd_disconnect(sbi->ll_md_exp);
935 sbi->ll_md_exp = NULL;
940 void ll_kill_super(struct super_block *sb)
942 struct ll_sb_info *sbi;
946 if (!(sb->s_flags & SB_ACTIVE))
950 /* we need restore s_dev from changed for clustred NFS before put_super
951 * because new kernels have cached s_dev and change sb->s_dev in
952 * put_super not affected real removing devices */
954 sb->s_dev = sbi->ll_sdev_orig;
956 /* wait running statahead threads to quit */
957 while (atomic_read(&sbi->ll_sa_running) > 0)
958 schedule_timeout_uninterruptible(
959 cfs_time_seconds(1) >> 3);
965 /* Since we use this table for ll_sbi_flags_seq_show make
966 * sure what you want displayed for a specific token that
967 * is listed more than once below be listed first. For
968 * example we want "checksum" displayed, not "nochecksum"
971 static const match_table_t ll_sbi_flags_name = {
972 {LL_SBI_NOLCK, "nolock"},
973 {LL_SBI_CHECKSUM, "checksum"},
974 {LL_SBI_CHECKSUM, "nochecksum"},
975 {LL_SBI_LOCALFLOCK, "localflock"},
976 {LL_SBI_FLOCK, "flock"},
977 {LL_SBI_FLOCK, "noflock"},
978 {LL_SBI_USER_XATTR, "user_xattr"},
979 {LL_SBI_USER_XATTR, "nouser_xattr"},
980 {LL_SBI_LRU_RESIZE, "lruresize"},
981 {LL_SBI_LRU_RESIZE, "nolruresize"},
982 {LL_SBI_LAZYSTATFS, "lazystatfs"},
983 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
984 {LL_SBI_32BIT_API, "32bitapi"},
985 {LL_SBI_USER_FID2PATH, "user_fid2path"},
986 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
987 {LL_SBI_VERBOSE, "verbose"},
988 {LL_SBI_VERBOSE, "noverbose"},
989 {LL_SBI_ALWAYS_PING, "always_ping"},
990 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
991 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
992 {LL_SBI_ENCRYPT, "encrypt"},
993 {LL_SBI_ENCRYPT, "noencrypt"},
994 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
995 {LL_SBI_NUM_MOUNT_OPT, NULL},
998 {LL_SBI_AGL_ENABLED, "agl"},
999 {LL_SBI_64BIT_HASH, "64bit_hash"},
1000 {LL_SBI_LAYOUT_LOCK, "layout"},
1001 {LL_SBI_XATTR_CACHE, "xattr_cache"},
1002 {LL_SBI_NOROOTSQUASH, "norootsquash"},
1003 {LL_SBI_FAST_READ, "fast_read"},
1004 {LL_SBI_FILE_SECCTX, "file_secctx"},
1005 {LL_SBI_TINY_WRITE, "tiny_write"},
1006 {LL_SBI_FILE_HEAT, "file_heat"},
1007 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
1008 {LL_SBI_ENCRYPT_NAME, "name_encrypt"},
1011 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
1013 struct super_block *sb = m->private;
1016 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
1019 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
1022 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
1023 if (ll_sbi_flags_name[j].token == i &&
1024 ll_sbi_flags_name[j].pattern) {
1025 seq_printf(m, "%s ",
1026 ll_sbi_flags_name[j].pattern);
1031 seq_puts(m, "\b\n");
1035 /* non-client-specific mount options are parsed in lmd_parse */
1036 static int ll_options(char *options, struct super_block *sb)
1038 struct ll_sb_info *sbi = ll_s2sbi(sb);
1039 char *s2, *s1, *opts;
1046 /* Don't stomp on lmd_opts */
1047 opts = kstrdup(options, GFP_KERNEL);
1053 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1055 while ((s1 = strsep(&opts, ",")) != NULL) {
1056 substring_t args[MAX_OPT_ARGS];
1057 bool turn_off = false;
1063 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1065 if (strncmp(s1, "no", 2) == 0)
1069 * Initialize args struct so we know whether arg was
1070 * found; some options take optional arguments.
1073 args[0].from = NULL;
1074 token = match_token(s1, ll_sbi_flags_name, args);
1075 if (token == LL_SBI_NUM_MOUNT_OPT) {
1076 if (match_wildcard("context", s1) ||
1077 match_wildcard("fscontext", s1) ||
1078 match_wildcard("defcontext", s1) ||
1079 match_wildcard("rootcontext",s1))
1082 LCONSOLE_ERROR_MSG(0x152,
1083 "Unknown option '%s', won't mount.\n",
1090 case LL_SBI_32BIT_API:
1091 case LL_SBI_64BIT_HASH:
1092 case LL_SBI_ALWAYS_PING:
1093 set_bit(token, sbi->ll_flags);
1097 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1099 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1101 set_bit(token, sbi->ll_flags);
1104 case LL_SBI_LOCALFLOCK:
1105 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1106 set_bit(token, sbi->ll_flags);
1109 case LL_SBI_CHECKSUM:
1110 sbi->ll_checksum_set = 1;
1112 case LL_SBI_USER_XATTR:
1113 case LL_SBI_USER_FID2PATH:
1114 case LL_SBI_LRU_RESIZE:
1115 case LL_SBI_LAZYSTATFS:
1116 case LL_SBI_VERBOSE:
1118 clear_bit(token, sbi->ll_flags);
1120 set_bit(token, sbi->ll_flags);
1122 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1123 #ifdef HAVE_LUSTRE_CRYPTO
1124 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1125 set_bit(token, sbi->ll_flags);
1127 struct lustre_sb_info *lsi = s2lsi(sb);
1129 err = llcrypt_set_test_dummy_encryption(sb,
1130 #ifdef HAVE_FSCRYPT_SET_TEST_DUMMY_ENC_CHAR_ARG
1135 &lsi->lsi_dummy_enc_policy);
1141 "Can't change test_dummy_encryption");
1142 else if (err == -EINVAL)
1144 "Value of option \"%s\" unrecognized",
1148 "Error processing option \"%s\" [%d]",
1153 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1157 case LL_SBI_ENCRYPT:
1158 #ifdef HAVE_LUSTRE_CRYPTO
1160 clear_bit(token, sbi->ll_flags);
1162 set_bit(token, sbi->ll_flags);
1164 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1167 case LL_SBI_FOREIGN_SYMLINK:
1168 /* non-default prefix provided ? */
1173 /* path must be absolute */
1174 if (args->from[0] != '/') {
1175 LCONSOLE_ERROR_MSG(0x152,
1176 "foreign prefix '%s' must be an absolute path\n",
1181 old_len = sbi->ll_foreign_symlink_prefix_size;
1182 old = sbi->ll_foreign_symlink_prefix;
1183 /* alloc for path length and '\0' */
1184 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1185 if (!sbi->ll_foreign_symlink_prefix) {
1186 /* restore previous */
1187 sbi->ll_foreign_symlink_prefix = old;
1188 sbi->ll_foreign_symlink_prefix_size =
1192 sbi->ll_foreign_symlink_prefix_size =
1193 args->to - args->from + 1;
1194 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1195 sbi->ll_foreign_symlink_prefix_size,
1198 OBD_FREE(old, old_len);
1200 /* enable foreign symlink support */
1201 set_bit(token, sbi->ll_flags);
1203 LCONSOLE_ERROR_MSG(0x152,
1204 "invalid %s option\n", s1);
1215 void ll_lli_init(struct ll_inode_info *lli)
1217 lli->lli_inode_magic = LLI_INODE_MAGIC;
1219 rwlock_init(&lli->lli_lock);
1220 lli->lli_posix_acl = NULL;
1221 /* Do not set lli_fid, it has been initialized already. */
1222 fid_zero(&lli->lli_pfid);
1223 lli->lli_mds_read_och = NULL;
1224 lli->lli_mds_write_och = NULL;
1225 lli->lli_mds_exec_och = NULL;
1226 lli->lli_open_fd_read_count = 0;
1227 lli->lli_open_fd_write_count = 0;
1228 lli->lli_open_fd_exec_count = 0;
1229 mutex_init(&lli->lli_och_mutex);
1230 spin_lock_init(&lli->lli_agl_lock);
1231 spin_lock_init(&lli->lli_layout_lock);
1232 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1233 lli->lli_clob = NULL;
1235 init_rwsem(&lli->lli_xattrs_list_rwsem);
1236 mutex_init(&lli->lli_xattrs_enq_lock);
1238 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1239 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1240 lli->lli_opendir_key = NULL;
1241 lli->lli_sai = NULL;
1242 spin_lock_init(&lli->lli_sa_lock);
1243 lli->lli_opendir_pid = 0;
1244 lli->lli_sa_enabled = 0;
1245 init_rwsem(&lli->lli_lsm_sem);
1247 mutex_init(&lli->lli_size_mutex);
1248 mutex_init(&lli->lli_setattr_mutex);
1249 lli->lli_symlink_name = NULL;
1250 ll_trunc_sem_init(&lli->lli_trunc_sem);
1251 range_lock_tree_init(&lli->lli_write_tree);
1252 init_rwsem(&lli->lli_glimpse_sem);
1253 lli->lli_glimpse_time = ktime_set(0, 0);
1254 INIT_LIST_HEAD(&lli->lli_agl_list);
1255 lli->lli_agl_index = 0;
1256 lli->lli_async_rc = 0;
1257 spin_lock_init(&lli->lli_heat_lock);
1258 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1259 lli->lli_heat_flags = 0;
1260 mutex_init(&lli->lli_pcc_lock);
1261 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1262 lli->lli_pcc_inode = NULL;
1263 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1264 lli->lli_pcc_generation = 0;
1265 mutex_init(&lli->lli_group_mutex);
1266 lli->lli_group_users = 0;
1267 lli->lli_group_gid = 0;
1268 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1269 lli->lli_uid = (__u32) -1;
1270 lli->lli_gid = (__u32) -1;
1272 mutex_init(&lli->lli_layout_mutex);
1273 /* ll_cl_context initialize */
1274 INIT_LIST_HEAD(&lli->lli_lccs);
1275 seqlock_init(&lli->lli_page_inv_lock);
1278 #define MAX_STRING_SIZE 128
1280 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1281 #ifndef HAVE_BDI_CAP_MAP_COPY
1282 # define BDI_CAP_MAP_COPY 0
1285 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1287 struct lustre_sb_info *lsi = s2lsi(sb);
1288 char buf[MAX_STRING_SIZE];
1292 err = bdi_init(&lsi->lsi_bdi);
1296 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1297 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1298 lsi->lsi_bdi.name = "lustre";
1299 va_start(args, fmt);
1300 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1302 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1305 sb->s_bdi = &lsi->lsi_bdi;
1309 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1311 int ll_fill_super(struct super_block *sb)
1313 struct lustre_profile *lprof = NULL;
1314 struct lustre_sb_info *lsi = s2lsi(sb);
1315 struct ll_sb_info *sbi = NULL;
1316 char *dt = NULL, *md = NULL;
1317 char *profilenm = get_profile_name(sb);
1318 struct config_llog_instance *cfg;
1319 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1320 const int instlen = LUSTRE_MAXINSTANCE + 2;
1321 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1322 char name[MAX_STRING_SIZE];
1331 /* for ASLR, to map between cfg_instance and hashed ptr */
1332 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1333 profilenm, cfg_instance, sb);
1335 CFS_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1339 GOTO(out_free_cfg, err = -ENOMEM);
1341 /* client additional sb info */
1342 lsi->lsi_llsbi = sbi = ll_init_sbi(lsi);
1344 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1346 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1348 GOTO(out_free_cfg, err);
1350 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1351 #ifdef CONFIG_LL_ENCRYPTION
1352 if (ll_sb_has_test_dummy_encryption(sb))
1353 /* enable filename encryption by default for dummy enc mode */
1354 lsi->lsi_flags |= LSI_FILENAME_ENC;
1356 /* filename encryption is disabled by default */
1357 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1360 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1361 sb->s_d_op = &ll_d_ops;
1364 generate_random_uuid(uuid.b);
1365 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1367 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1370 len = strlen(profilenm);
1371 ptr = strrchr(profilenm, '-');
1372 if (ptr && (strcmp(ptr, "-client") == 0))
1375 if (len > LUSTRE_MAXFSNAME) {
1376 if (unlikely(len >= MAX_STRING_SIZE))
1377 len = MAX_STRING_SIZE - 1;
1378 strncpy(name, profilenm, len);
1380 err = -ENAMETOOLONG;
1381 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1382 name, LUSTRE_MAXFSNAME, err);
1383 GOTO(out_free_cfg, err);
1385 strncpy(sbi->ll_fsname, profilenm, len);
1386 sbi->ll_fsname[len] = '\0';
1389 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1390 profilenm, cfg_instance);
1392 err = super_setup_bdi_name(sb, "%s", name);
1394 GOTO(out_free_cfg, err);
1396 /* disable kernel readahead */
1397 sb->s_bdi->ra_pages = 0;
1398 #ifdef HAVE_BDI_IO_PAGES
1399 sb->s_bdi->io_pages = 0;
1402 /* Call ll_debugfs_register_super() before lustre_process_log()
1403 * so that "llite.*.*" params can be processed correctly.
1405 err = ll_debugfs_register_super(sb, name);
1407 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1408 sbi->ll_fsname, err);
1412 /* The cfg_instance is a value unique to this super, in case some
1413 * joker tries to mount the same fs at two mount points.
1415 cfg->cfg_instance = cfg_instance;
1416 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1417 cfg->cfg_callback = class_config_llog_handler;
1418 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1419 /* set up client obds */
1420 err = lustre_process_log(sb, profilenm, cfg);
1422 GOTO(out_debugfs, err);
1424 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1425 lprof = class_get_profile(profilenm);
1426 if (lprof == NULL) {
1427 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1428 " read from the MGS. Does that filesystem "
1429 "exist?\n", profilenm);
1430 GOTO(out_debugfs, err = -EINVAL);
1432 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1433 lprof->lp_md, lprof->lp_dt);
1435 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1436 OBD_ALLOC(dt, dt_len);
1438 GOTO(out_profile, err = -ENOMEM);
1439 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1441 md_len = strlen(lprof->lp_md) + instlen + 2;
1442 OBD_ALLOC(md, md_len);
1444 GOTO(out_free_dt, err = -ENOMEM);
1445 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1447 /* connections, registrations, sb setup */
1448 err = client_common_fill_super(sb, md, dt);
1450 GOTO(out_free_md, err);
1452 sbi->ll_client_common_fill_super_succeeded = 1;
1456 OBD_FREE(md, md_len);
1459 OBD_FREE(dt, dt_len);
1462 class_put_profile(lprof);
1465 ll_debugfs_unregister_super(sb);
1472 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1473 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1474 sb->s_flags & SB_RDONLY ? " read-only" : "");
1476 } /* ll_fill_super */
1478 void ll_put_super(struct super_block *sb)
1480 struct config_llog_instance cfg, params_cfg;
1481 struct obd_device *obd;
1482 struct lustre_sb_info *lsi = s2lsi(sb);
1483 struct ll_sb_info *sbi = ll_s2sbi(sb);
1484 char *profilenm = get_profile_name(sb);
1485 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1487 int next, force = 1, rc = 0;
1491 GOTO(out_no_sbi, 0);
1493 /* Should replace instance_id with something better for ASLR */
1494 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1495 profilenm, cfg_instance, sb);
1497 cfg.cfg_instance = cfg_instance;
1498 lustre_end_log(sb, profilenm, &cfg);
1500 params_cfg.cfg_instance = cfg_instance;
1501 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1503 if (sbi->ll_md_exp) {
1504 obd = class_exp2obd(sbi->ll_md_exp);
1506 force = obd->obd_force;
1509 /* Wait for unstable pages to be committed to stable storage */
1511 rc = l_wait_event_abortable(
1512 sbi->ll_cache->ccc_unstable_waitq,
1513 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1516 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1517 if (force == 0 && rc != -ERESTARTSYS)
1518 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1520 /* We need to set force before the lov_disconnect in
1521 * lustre_common_put_super, since l_d cleans up osc's as well.
1525 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1527 obd->obd_force = force;
1531 if (sbi->ll_client_common_fill_super_succeeded) {
1532 /* Only if client_common_fill_super succeeded */
1533 client_common_put_super(sb);
1536 /* imitate failed cleanup */
1537 if (CFS_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1541 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1542 class_manual_cleanup(obd);
1545 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1546 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1549 class_del_profile(profilenm);
1551 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1552 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1553 bdi_destroy(&lsi->lsi_bdi);
1554 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1558 llcrypt_free_dummy_policy(&lsi->lsi_dummy_enc_policy);
1560 lsi->lsi_llsbi = NULL;
1562 lustre_common_put_super(sb);
1564 cl_env_cache_purge(~0);
1567 } /* client_put_super */
1569 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1571 struct inode *inode = NULL;
1573 /* NOTE: we depend on atomic igrab() -bzzz */
1574 lock_res_and_lock(lock);
1575 if (lock->l_resource->lr_lvb_inode) {
1576 struct ll_inode_info * lli;
1577 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1578 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1579 inode = igrab(lock->l_resource->lr_lvb_inode);
1581 inode = lock->l_resource->lr_lvb_inode;
1582 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1583 D_WARNING, lock, "lr_lvb_inode %p is "
1584 "bogus: magic %08x",
1585 lock->l_resource->lr_lvb_inode,
1586 lli->lli_inode_magic);
1590 unlock_res_and_lock(lock);
1594 void ll_dir_clear_lsm_md(struct inode *inode)
1596 struct ll_inode_info *lli = ll_i2info(inode);
1598 LASSERT(S_ISDIR(inode->i_mode));
1600 if (lli->lli_lsm_md) {
1601 lmv_free_memmd(lli->lli_lsm_md);
1602 lli->lli_lsm_md = NULL;
1605 if (lli->lli_default_lsm_md) {
1606 lmv_free_memmd(lli->lli_default_lsm_md);
1607 lli->lli_default_lsm_md = NULL;
1611 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1612 const struct lu_fid *fid,
1613 struct lustre_md *md)
1615 struct ll_sb_info *sbi = ll_s2sbi(sb);
1616 struct ll_inode_info *lli;
1617 struct mdt_body *body = md->body;
1618 struct inode *inode;
1624 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1625 inode = iget_locked(sb, ino);
1626 if (inode == NULL) {
1627 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1628 sbi->ll_fsname, PFID(fid));
1629 RETURN(ERR_PTR(-ENOENT));
1632 lli = ll_i2info(inode);
1633 if (inode->i_state & I_NEW) {
1634 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1635 (body->mbo_mode & S_IFMT);
1636 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1639 inode->i_mtime.tv_sec = 0;
1640 inode->i_atime.tv_sec = 0;
1641 inode->i_ctime.tv_sec = 0;
1644 #ifdef HAVE_BACKING_DEV_INFO
1645 /* initializing backing dev info. */
1646 inode->i_mapping->backing_dev_info =
1647 &s2lsi(inode->i_sb)->lsi_bdi;
1649 inode->i_op = &ll_dir_inode_operations;
1650 inode->i_fop = &ll_dir_operations;
1651 lli->lli_fid = *fid;
1654 /* master object FID */
1655 lli->lli_pfid = body->mbo_fid1;
1656 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1657 lli, PFID(fid), PFID(&lli->lli_pfid));
1658 unlock_new_inode(inode);
1660 /* in directory restripe/auto-split, a directory will be
1661 * transformed to a stripe if it's plain, set its pfid here,
1662 * otherwise ll_lock_cancel_bits() can't find the master inode.
1664 lli->lli_pfid = body->mbo_fid1;
1670 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1673 struct lmv_stripe_md *lsm = md->lmv;
1674 struct ll_inode_info *lli = ll_i2info(inode);
1677 LASSERT(lsm != NULL);
1679 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1680 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1681 lsm_md_dump(D_INODE, lsm);
1683 if (!lmv_dir_striped(lsm))
1686 /* XXX sigh, this lsm_root initialization should be in
1687 * LMV layer, but it needs ll_iget right now, so we
1688 * put this here right now. */
1689 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1690 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1691 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1693 if (!fid_is_sane(fid))
1696 /* Unfortunately ll_iget will call ll_update_inode,
1697 * where the initialization of slave inode is slightly
1698 * different, so it reset lsm_md to NULL to avoid
1699 * initializing lsm for slave inode. */
1700 lsm->lsm_md_oinfo[i].lmo_root =
1701 ll_iget_anon_dir(inode->i_sb, fid, md);
1702 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1703 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1705 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1707 iput(lsm->lsm_md_oinfo[i].lmo_root);
1708 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1714 lli->lli_lsm_md = lsm;
1719 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1721 struct ll_inode_info *lli = ll_i2info(inode);
1725 if (!md->default_lmv) {
1726 /* clear default lsm */
1727 if (lli->lli_default_lsm_md) {
1728 down_write(&lli->lli_lsm_sem);
1729 if (lli->lli_default_lsm_md) {
1730 lmv_free_memmd(lli->lli_default_lsm_md);
1731 lli->lli_default_lsm_md = NULL;
1733 lli->lli_inherit_depth = 0;
1734 up_write(&lli->lli_lsm_sem);
1739 if (lli->lli_default_lsm_md) {
1740 /* do nonthing if default lsm isn't changed */
1741 down_read(&lli->lli_lsm_sem);
1742 if (lli->lli_default_lsm_md &&
1743 lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1744 up_read(&lli->lli_lsm_sem);
1747 up_read(&lli->lli_lsm_sem);
1750 down_write(&lli->lli_lsm_sem);
1751 if (lli->lli_default_lsm_md)
1752 lmv_free_memmd(lli->lli_default_lsm_md);
1753 lli->lli_default_lsm_md = md->default_lmv;
1754 lsm_md_dump(D_INODE, md->default_lmv);
1755 md->default_lmv = NULL;
1756 up_write(&lli->lli_lsm_sem);
1760 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1762 struct ll_inode_info *lli = ll_i2info(inode);
1763 struct lmv_stripe_md *lsm = md->lmv;
1764 struct cl_attr *attr;
1769 LASSERT(S_ISDIR(inode->i_mode));
1770 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1771 PFID(ll_inode2fid(inode)));
1773 /* update default LMV */
1774 if (md->default_lmv)
1775 ll_update_default_lsm_md(inode, md);
1777 /* after dir migration/restripe, a stripe may be turned into a
1778 * directory, in this case, zero out its lli_pfid.
1780 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1781 fid_zero(&lli->lli_pfid);
1784 * no striped information from request, lustre_md from req does not
1785 * include stripeEA, see ll_md_setattr()
1791 * normally dir layout doesn't change, only take read lock to check
1792 * that to avoid blocking other MD operations.
1794 down_read(&lli->lli_lsm_sem);
1796 /* some current lookup initialized lsm, and unchanged */
1797 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1798 GOTO(unlock, rc = 0);
1800 /* if dir layout doesn't match, check whether version is increased,
1801 * which means layout is changed, this happens in dir split/merge and
1804 * foreign LMV should not change.
1806 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1807 lsm->lsm_md_layout_version <=
1808 lli->lli_lsm_md->lsm_md_layout_version) {
1809 CERROR("%s: "DFID" dir layout mismatch:\n",
1810 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1811 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1812 lsm_md_dump(D_ERROR, lsm);
1813 GOTO(unlock, rc = -EINVAL);
1816 up_read(&lli->lli_lsm_sem);
1817 down_write(&lli->lli_lsm_sem);
1818 /* clear existing lsm */
1819 if (lli->lli_lsm_md) {
1820 lmv_free_memmd(lli->lli_lsm_md);
1821 lli->lli_lsm_md = NULL;
1824 rc = ll_init_lsm_md(inode, md);
1826 up_write(&lli->lli_lsm_sem);
1830 /* md_merge_attr() may take long, since lsm is already set, switch to
1833 downgrade_write(&lli->lli_lsm_sem);
1835 /* set md->lmv to NULL, so the following free lustre_md will not free
1840 if (!lmv_dir_striped(lli->lli_lsm_md))
1841 GOTO(unlock, rc = 0);
1843 OBD_ALLOC_PTR(attr);
1845 GOTO(unlock, rc = -ENOMEM);
1847 /* validate the lsm */
1848 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1849 ll_md_blocking_ast);
1851 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1852 md->body->mbo_nlink = attr->cat_nlink;
1853 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1854 md->body->mbo_size = attr->cat_size;
1855 if (md->body->mbo_valid & OBD_MD_FLATIME)
1856 md->body->mbo_atime = attr->cat_atime;
1857 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1858 md->body->mbo_ctime = attr->cat_ctime;
1859 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1860 md->body->mbo_mtime = attr->cat_mtime;
1866 up_read(&lli->lli_lsm_sem);
1871 void ll_clear_inode(struct inode *inode)
1873 struct ll_inode_info *lli = ll_i2info(inode);
1874 struct ll_sb_info *sbi = ll_i2sbi(inode);
1878 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1879 PFID(ll_inode2fid(inode)), inode);
1881 if (S_ISDIR(inode->i_mode)) {
1882 /* these should have been cleared in ll_file_release */
1883 LASSERT(lli->lli_opendir_key == NULL);
1884 LASSERT(lli->lli_sai == NULL);
1885 LASSERT(lli->lli_opendir_pid == 0);
1887 pcc_inode_free(inode);
1890 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1892 LASSERT(!lli->lli_open_fd_write_count);
1893 LASSERT(!lli->lli_open_fd_read_count);
1894 LASSERT(!lli->lli_open_fd_exec_count);
1896 if (lli->lli_mds_write_och)
1897 ll_md_real_close(inode, FMODE_WRITE);
1898 if (lli->lli_mds_exec_och)
1899 ll_md_real_close(inode, FMODE_EXEC);
1900 if (lli->lli_mds_read_och)
1901 ll_md_real_close(inode, FMODE_READ);
1903 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1904 OBD_FREE(lli->lli_symlink_name,
1905 strlen(lli->lli_symlink_name) + 1);
1906 lli->lli_symlink_name = NULL;
1909 ll_xattr_cache_destroy(inode);
1911 forget_all_cached_acls(inode);
1913 lli->lli_inode_magic = LLI_INODE_DEAD;
1915 if (S_ISDIR(inode->i_mode))
1916 ll_dir_clear_lsm_md(inode);
1917 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1918 LASSERT(list_empty(&lli->lli_agl_list));
1921 * XXX This has to be done before lsm is freed below, because
1922 * cl_object still uses inode lsm.
1924 cl_inode_fini(inode);
1926 llcrypt_put_encryption_info(inode);
1931 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1933 struct lustre_md md;
1934 struct inode *inode = dentry->d_inode;
1935 struct ll_sb_info *sbi = ll_i2sbi(inode);
1936 struct ptlrpc_request *request = NULL;
1941 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1942 LUSTRE_OPC_ANY, NULL);
1943 if (IS_ERR(op_data))
1944 RETURN(PTR_ERR(op_data));
1946 /* If this is a chgrp of a regular file, we want to reserve enough
1947 * quota to cover the entire file size.
1949 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1950 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1951 from_kgid(&init_user_ns, inode->i_gid)) {
1952 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1953 op_data->op_attr_blocks = inode->i_blocks;
1957 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1959 ptlrpc_req_finished(request);
1960 if (rc == -ENOENT) {
1962 /* Unlinked special device node? Or just a race?
1963 * Pretend we done everything. */
1964 if (!S_ISREG(inode->i_mode) &&
1965 !S_ISDIR(inode->i_mode)) {
1966 ia_valid = op_data->op_attr.ia_valid;
1967 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1968 rc = simple_setattr(&init_user_ns, dentry,
1970 op_data->op_attr.ia_valid = ia_valid;
1972 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1973 CERROR("md_setattr fails: rc = %d\n", rc);
1978 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1979 sbi->ll_md_exp, &md);
1981 ptlrpc_req_finished(request);
1985 ia_valid = op_data->op_attr.ia_valid;
1986 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1987 * cache is not cleared yet. */
1988 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1989 if (S_ISREG(inode->i_mode))
1991 rc = simple_setattr(&init_user_ns, dentry, &op_data->op_attr);
1992 if (S_ISREG(inode->i_mode))
1993 inode_unlock(inode);
1994 op_data->op_attr.ia_valid = ia_valid;
1996 rc = ll_update_inode(inode, &md);
1997 ptlrpc_req_finished(request);
2003 * Zero portion of page that is part of @inode.
2004 * This implies, if necessary:
2005 * - taking cl_lock on range corresponding to concerned page
2006 * - grabbing vm page
2007 * - associating cl_page
2008 * - proceeding to clio read
2009 * - zeroing range in page
2010 * - proceeding to cl_page flush
2011 * - releasing cl_lock
2013 * \param[in] inode inode
2014 * \param[in] index page index
2015 * \param[in] offset offset in page to start zero from
2016 * \param[in] len len to zero
2018 * \retval 0 on success
2019 * \retval negative errno on failure
2021 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
2024 struct ll_inode_info *lli = ll_i2info(inode);
2025 struct cl_object *clob = lli->lli_clob;
2027 struct lu_env *env = NULL;
2028 struct cl_io *io = NULL;
2029 struct cl_page *clpage = NULL;
2030 struct page *vmpage = NULL;
2031 unsigned from = index << PAGE_SHIFT;
2032 struct cl_lock *lock = NULL;
2033 struct cl_lock_descr *descr = NULL;
2034 struct cl_2queue *queue = NULL;
2035 struct cl_sync_io *anchor = NULL;
2036 bool holdinglock = false;
2041 env = cl_env_get(&refcheck);
2043 RETURN(PTR_ERR(env));
2045 io = vvp_env_thread_io(env);
2047 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2051 lock = vvp_env_lock(env);
2052 descr = &lock->cll_descr;
2053 descr->cld_obj = io->ci_obj;
2054 descr->cld_start = from >> PAGE_SHIFT;
2055 descr->cld_end = (from + PAGE_SIZE - 1) >> PAGE_SHIFT;
2056 descr->cld_mode = CLM_WRITE;
2057 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2059 /* request lock for page */
2060 rc = cl_lock_request(env, io, lock);
2061 /* -ECANCELED indicates a matching lock with a different extent
2062 * was already present, and -EEXIST indicates a matching lock
2063 * on exactly the same extent was already present.
2064 * In both cases it means we are covered.
2066 if (rc == -ECANCELED || rc == -EEXIST)
2074 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2076 GOTO(rellock, rc = -EOPNOTSUPP);
2078 if (!PageDirty(vmpage)) {
2079 /* associate cl_page */
2080 clpage = cl_page_find(env, clob, vmpage->index,
2081 vmpage, CPT_CACHEABLE);
2083 GOTO(pagefini, rc = PTR_ERR(clpage));
2085 cl_page_assume(env, io, clpage);
2088 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2089 !PageWriteback(vmpage)) {
2091 /* Set PagePrivate2 to detect special case of empty page
2092 * in osc_brw_fini_request().
2093 * It is also used to tell ll_io_read_page() that we do not
2094 * want the vmpage to be unlocked.
2096 SetPagePrivate2(vmpage);
2097 rc = ll_io_read_page(env, io, clpage, NULL);
2098 if (!PagePrivate2(vmpage)) {
2099 /* PagePrivate2 was cleared in osc_brw_fini_request()
2100 * meaning we read an empty page. In this case, in order
2101 * to avoid allocating unnecessary block in truncated
2102 * file, we must not zero and write as below. Subsequent
2103 * server-side truncate will handle things correctly.
2105 cl_page_unassume(env, io, clpage);
2106 GOTO(clpfini, rc = 0);
2108 ClearPagePrivate2(vmpage);
2113 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2114 * the vmpage, so we are good to proceed and zero range in page.
2116 zero_user(vmpage, offset, len);
2118 if (holdinglock && clpage) {
2119 /* explicitly write newly modified page */
2120 queue = &io->ci_queue;
2121 cl_2queue_init(queue);
2122 anchor = &vvp_env_info(env)->vti_anchor;
2123 cl_sync_io_init(anchor, 1);
2124 clpage->cp_sync_io = anchor;
2125 cl_page_list_add(&queue->c2_qin, clpage, true);
2126 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2128 GOTO(queuefini1, rc);
2129 rc = cl_sync_io_wait(env, anchor, 0);
2131 GOTO(queuefini2, rc);
2132 cl_page_assume(env, io, clpage);
2135 cl_2queue_discard(env, io, queue);
2137 cl_2queue_disown(env, queue);
2138 cl_2queue_fini(env, queue);
2143 cl_page_put(env, clpage);
2145 unlock_page(vmpage);
2149 cl_lock_release(env, lock);
2151 cl_io_fini(env, io);
2154 cl_env_put(env, &refcheck);
2160 * Get reference file from volatile file name.
2161 * Volatile file name may look like:
2162 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2163 * where fd is opened descriptor of reference file.
2165 * \param[in] volatile_name volatile file name
2166 * \param[in] volatile_len volatile file name length
2167 * \param[out] ref_file pointer to struct file of reference file
2169 * \retval 0 on success
2170 * \retval negative errno on failure
2172 int volatile_ref_file(const char *volatile_name, int volatile_len,
2173 struct file **ref_file)
2175 char *p, *q, *fd_str;
2178 p = strnstr(volatile_name, ":fd=", volatile_len);
2179 if (!p || strlen(p + 4) == 0)
2182 q = strchrnul(p + 4, ':');
2183 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2186 rc = kstrtouint(fd_str, 10, &fd);
2191 *ref_file = fget(fd);
2197 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2198 * object(s) determine the file size and mtime. Otherwise, the MDS will
2199 * keep these values until such a time that objects are allocated for it.
2200 * We do the MDS operations first, as it is checking permissions for us.
2201 * We don't to the MDS RPC if there is nothing that we want to store there,
2202 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2203 * going to do an RPC anyways.
2205 * If we are doing a truncate, we will send the mtime and ctime updates
2206 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2207 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2210 * In case of HSMimport, we only set attr on MDS.
2212 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2213 enum op_xvalid xvalid, bool hsm_import)
2215 struct inode *inode = dentry->d_inode;
2216 struct ll_inode_info *lli = ll_i2info(inode);
2217 struct md_op_data *op_data = NULL;
2218 ktime_t kstart = ktime_get();
2223 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2224 "valid %x, hsm_import %d\n",
2225 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2226 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2229 if (attr->ia_valid & ATTR_SIZE) {
2230 /* Check new size against VFS/VM file size limit and rlimit */
2231 rc = inode_newsize_ok(inode, attr->ia_size);
2235 /* The maximum Lustre file size is variable, based on the
2236 * OST maximum object size and number of stripes. This
2237 * needs another check in addition to the VFS check above. */
2238 if (attr->ia_size > ll_file_maxbytes(inode)) {
2239 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2240 PFID(&lli->lli_fid), attr->ia_size,
2241 ll_file_maxbytes(inode));
2245 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2248 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2249 if (attr->ia_valid & TIMES_SET_FLAGS) {
2250 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2251 !capable(CAP_FOWNER))
2255 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2256 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2257 (attr->ia_valid & ATTR_CTIME)) {
2258 attr->ia_ctime = current_time(inode);
2259 xvalid |= OP_XVALID_CTIME_SET;
2261 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2262 (attr->ia_valid & ATTR_ATIME)) {
2263 attr->ia_atime = current_time(inode);
2264 attr->ia_valid |= ATTR_ATIME_SET;
2266 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2267 (attr->ia_valid & ATTR_MTIME)) {
2268 attr->ia_mtime = current_time(inode);
2269 attr->ia_valid |= ATTR_MTIME_SET;
2272 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2273 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2274 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2275 ktime_get_real_seconds());
2277 if (S_ISREG(inode->i_mode))
2278 inode_unlock(inode);
2280 /* We always do an MDS RPC, even if we're only changing the size;
2281 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2283 OBD_ALLOC_PTR(op_data);
2284 if (op_data == NULL)
2285 GOTO(out, rc = -ENOMEM);
2287 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2288 /* If we are changing file size, file content is
2289 * modified, flag it.
2291 xvalid |= OP_XVALID_OWNEROVERRIDE;
2292 op_data->op_bias |= MDS_DATA_MODIFIED;
2293 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2296 if (attr->ia_valid & ATTR_FILE) {
2297 struct ll_file_data *fd = attr->ia_file->private_data;
2299 if (fd->fd_lease_och)
2300 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2303 op_data->op_attr = *attr;
2304 op_data->op_xvalid = xvalid;
2306 rc = ll_md_setattr(dentry, op_data);
2309 lli->lli_synced_to_mds = false;
2311 if (!S_ISREG(inode->i_mode) || hsm_import)
2314 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2315 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2316 xvalid & OP_XVALID_CTIME_SET) {
2317 bool cached = false;
2319 rc = pcc_inode_setattr(inode, attr, &cached);
2322 CERROR("%s: PCC inode "DFID" setattr failed: "
2324 ll_i2sbi(inode)->ll_fsname,
2325 PFID(&lli->lli_fid), rc);
2329 unsigned int flags = 0;
2331 /* For truncate and utimes sending attributes to OSTs,
2332 * setting mtime/atime to the past will be performed
2333 * under PW [0:EOF] extent lock (new_size:EOF for
2334 * truncate). It may seem excessive to send mtime/atime
2335 * updates to OSTs when not setting times to past, but
2336 * it is necessary due to possible time
2337 * de-synchronization between MDT inode and OST objects
2339 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2340 xvalid |= OP_XVALID_FLAGS;
2341 flags = LUSTRE_ENCRYPT_FL;
2342 /* Call to ll_io_zero_page is not necessary if
2343 * truncating on PAGE_SIZE boundary, because
2344 * whole pages will be wiped.
2345 * In case of Direct IO, all we need is to set
2348 if (attr->ia_valid & ATTR_SIZE &&
2349 attr->ia_size & ~PAGE_MASK &&
2350 !(attr->ia_valid & ATTR_FILE &&
2351 attr->ia_file->f_flags & O_DIRECT)) {
2353 attr->ia_size & (PAGE_SIZE - 1);
2355 rc = ll_io_zero_page(inode,
2356 attr->ia_size >> PAGE_SHIFT,
2357 offset, PAGE_SIZE - offset);
2361 /* If encrypted volatile file without the key,
2362 * we need to fetch size from reference file,
2363 * and set it on OST objects. This happens when
2364 * migrating or extending an encrypted file
2367 if (filename_is_volatile(dentry->d_name.name,
2370 llcrypt_require_key(inode) == -ENOKEY) {
2371 struct file *ref_file;
2372 struct inode *ref_inode;
2373 struct ll_inode_info *ref_lli;
2374 struct cl_object *ref_obj;
2375 struct cl_attr ref_attr = { 0 };
2379 rc = volatile_ref_file(
2380 dentry->d_name.name,
2386 ref_inode = file_inode(ref_file);
2389 GOTO(out, rc = -EINVAL);
2392 env = cl_env_get(&refcheck);
2394 GOTO(out, rc = PTR_ERR(env));
2396 ref_lli = ll_i2info(ref_inode);
2397 ref_obj = ref_lli->lli_clob;
2398 cl_object_attr_lock(ref_obj);
2399 rc = cl_object_attr_get(env, ref_obj,
2401 cl_object_attr_unlock(ref_obj);
2402 cl_env_put(env, &refcheck);
2407 attr->ia_valid |= ATTR_SIZE;
2408 attr->ia_size = ref_attr.cat_size;
2411 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2415 /* If the file was restored, it needs to set dirty flag.
2417 * We've already sent MDS_DATA_MODIFIED flag in
2418 * ll_md_setattr() for truncate. However, the MDT refuses to
2419 * set the HS_DIRTY flag on released files, so we have to set
2420 * it again if the file has been restored. Please check how
2421 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2423 * Please notice that if the file is not released, the previous
2424 * MDS_DATA_MODIFIED has taken effect and usually
2425 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2426 * This way we can save an RPC for common open + trunc
2428 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2429 struct hsm_state_set hss = {
2430 .hss_valid = HSS_SETMASK,
2431 .hss_setmask = HS_DIRTY,
2435 rc2 = ll_hsm_state_set(inode, &hss);
2436 /* truncate and write can happen at the same time, so that
2437 * the file can be set modified even though the file is not
2438 * restored from released state, and ll_hsm_state_set() is
2439 * not applicable for the file, and rc2 < 0 is normal in this
2442 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2443 PFID(ll_inode2fid(inode)), rc2);
2448 if (op_data != NULL)
2449 ll_finish_md_op_data(op_data);
2451 if (S_ISREG(inode->i_mode)) {
2453 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2454 inode_dio_wait(inode);
2455 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2456 * flag. ll_update_inode (called from ll_md_setattr), clears
2457 * inode flags, so there is a gap where S_NOSEC is not set.
2458 * This can cause a writer to take the i_mutex unnecessarily,
2459 * but this is safe to do and should be rare. */
2460 inode_has_no_xattr(inode);
2464 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2465 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2466 ktime_us_delta(ktime_get(), kstart));
2471 int ll_setattr(struct user_namespace *mnt_userns, struct dentry *de,
2474 int mode = de->d_inode->i_mode;
2475 enum op_xvalid xvalid = 0;
2478 rc = llcrypt_prepare_setattr(de, attr);
2482 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2483 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2484 xvalid |= OP_XVALID_OWNEROVERRIDE;
2486 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2487 (ATTR_SIZE|ATTR_MODE)) &&
2488 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2489 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2490 !(attr->ia_mode & S_ISGID))))
2491 attr->ia_valid |= ATTR_FORCE;
2493 if ((attr->ia_valid & ATTR_MODE) &&
2495 !(attr->ia_mode & S_ISUID) &&
2496 !(attr->ia_valid & ATTR_KILL_SUID))
2497 attr->ia_valid |= ATTR_KILL_SUID;
2499 if ((attr->ia_valid & ATTR_MODE) &&
2500 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2501 !(attr->ia_mode & S_ISGID) &&
2502 !(attr->ia_valid & ATTR_KILL_SGID))
2503 attr->ia_valid |= ATTR_KILL_SGID;
2505 return ll_setattr_raw(de, attr, xvalid, false);
2508 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2511 struct obd_statfs obd_osfs = { 0 };
2516 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2518 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2519 flags |= OBD_STATFS_NODELAY;
2521 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2525 osfs->os_type = LL_SUPER_MAGIC;
2527 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2528 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2530 if (osfs->os_state & OS_STATFS_SUM)
2533 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2534 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2537 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2538 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2541 osfs->os_bsize = obd_osfs.os_bsize;
2542 osfs->os_blocks = obd_osfs.os_blocks;
2543 osfs->os_bfree = obd_osfs.os_bfree;
2544 osfs->os_bavail = obd_osfs.os_bavail;
2546 /* If we have _some_ OSTs, but don't have as many free objects on the
2547 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2548 * to compensate, so that the "inodes in use" number is correct.
2549 * This should be kept in sync with lod_statfs() behaviour.
2551 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2552 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2554 osfs->os_ffree = obd_osfs.os_ffree;
2561 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2563 struct if_quotactl qctl = {
2564 .qc_cmd = LUSTRE_Q_GETQUOTA,
2565 .qc_type = PRJQUOTA,
2566 .qc_valid = QC_GENERAL,
2568 u64 limit, curblock;
2571 qctl.qc_id = ll_i2info(inode)->lli_projid;
2572 ret = quotactl_ioctl(inode->i_sb, &qctl);
2574 /* ignore errors if project ID does not have
2575 * a quota limit or feature unsupported.
2577 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2582 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2583 qctl.qc_dqblk.dqb_bsoftlimit :
2584 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2585 if (limit && sfs->f_blocks > limit) {
2586 curblock = (qctl.qc_dqblk.dqb_curspace +
2587 sfs->f_bsize - 1) / sfs->f_bsize;
2588 sfs->f_blocks = limit;
2589 sfs->f_bfree = sfs->f_bavail =
2590 (sfs->f_blocks > curblock) ?
2591 (sfs->f_blocks - curblock) : 0;
2594 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2595 qctl.qc_dqblk.dqb_isoftlimit :
2596 qctl.qc_dqblk.dqb_ihardlimit;
2597 if (limit && sfs->f_files > limit) {
2598 sfs->f_files = limit;
2599 sfs->f_ffree = (sfs->f_files >
2600 qctl.qc_dqblk.dqb_curinodes) ?
2601 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2607 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2609 struct super_block *sb = de->d_sb;
2610 struct obd_statfs osfs;
2611 __u64 fsid = huge_encode_dev(sb->s_dev);
2612 ktime_t kstart = ktime_get();
2615 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2617 /* Some amount of caching on the client is allowed */
2618 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2622 statfs_unpack(sfs, &osfs);
2624 /* We need to downshift for all 32-bit kernels, because we can't
2625 * tell if the kernel is being called via sys_statfs64() or not.
2626 * Stop before overflowing f_bsize - in which case it is better
2627 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2628 if (sizeof(long) < 8) {
2629 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2632 osfs.os_blocks >>= 1;
2633 osfs.os_bfree >>= 1;
2634 osfs.os_bavail >>= 1;
2638 sfs->f_blocks = osfs.os_blocks;
2639 sfs->f_bfree = osfs.os_bfree;
2640 sfs->f_bavail = osfs.os_bavail;
2641 sfs->f_fsid.val[0] = (__u32)fsid;
2642 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2643 if (ll_i2info(de->d_inode)->lli_projid &&
2644 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2645 return ll_statfs_project(de->d_inode, sfs);
2647 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2648 ktime_us_delta(ktime_get(), kstart));
2653 void ll_inode_size_lock(struct inode *inode)
2655 struct ll_inode_info *lli;
2657 LASSERT(!S_ISDIR(inode->i_mode));
2659 lli = ll_i2info(inode);
2660 mutex_lock(&lli->lli_size_mutex);
2663 void ll_inode_size_unlock(struct inode *inode)
2665 struct ll_inode_info *lli;
2667 lli = ll_i2info(inode);
2668 mutex_unlock(&lli->lli_size_mutex);
2671 int ll_inode_size_trylock(struct inode *inode)
2673 struct ll_inode_info *lli;
2675 LASSERT(!S_ISDIR(inode->i_mode));
2677 lli = ll_i2info(inode);
2678 return mutex_trylock(&lli->lli_size_mutex);
2681 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2683 /* do not clear encryption flag */
2684 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2685 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2686 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2687 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2689 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2692 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2694 struct ll_inode_info *lli = ll_i2info(inode);
2695 struct mdt_body *body = md->body;
2696 struct ll_sb_info *sbi = ll_i2sbi(inode);
2700 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2701 rc = cl_file_inode_init(inode, md);
2706 if (S_ISDIR(inode->i_mode)) {
2707 rc = ll_update_lsm_md(inode, md);
2712 if (body->mbo_valid & OBD_MD_FLACL)
2713 lli_replace_acl(lli, md);
2715 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2716 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2717 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2719 if (body->mbo_valid & OBD_MD_FLATIME) {
2720 if (body->mbo_atime > inode->i_atime.tv_sec)
2721 inode->i_atime.tv_sec = body->mbo_atime;
2722 lli->lli_atime = body->mbo_atime;
2725 if (body->mbo_valid & OBD_MD_FLMTIME) {
2726 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2728 "setting ino %lu mtime from %lld to %llu\n",
2729 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2731 inode->i_mtime.tv_sec = body->mbo_mtime;
2733 lli->lli_mtime = body->mbo_mtime;
2736 if (body->mbo_valid & OBD_MD_FLCTIME) {
2737 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2738 inode->i_ctime.tv_sec = body->mbo_ctime;
2739 lli->lli_ctime = body->mbo_ctime;
2742 if (body->mbo_valid & OBD_MD_FLBTIME)
2743 lli->lli_btime = body->mbo_btime;
2745 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2746 if (body->mbo_valid & OBD_MD_FLFLAGS)
2747 ll_update_inode_flags(inode, body->mbo_flags);
2748 if (body->mbo_valid & OBD_MD_FLMODE)
2749 inode->i_mode = (inode->i_mode & S_IFMT) |
2750 (body->mbo_mode & ~S_IFMT);
2752 if (body->mbo_valid & OBD_MD_FLTYPE)
2753 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2754 (body->mbo_mode & S_IFMT);
2756 LASSERT(inode->i_mode != 0);
2757 if (body->mbo_valid & OBD_MD_FLUID)
2758 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2759 if (body->mbo_valid & OBD_MD_FLGID)
2760 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2761 if (body->mbo_valid & OBD_MD_FLPROJID)
2762 lli->lli_projid = body->mbo_projid;
2763 if (body->mbo_valid & OBD_MD_FLNLINK) {
2764 spin_lock(&inode->i_lock);
2765 set_nlink(inode, body->mbo_nlink);
2766 spin_unlock(&inode->i_lock);
2768 if (body->mbo_valid & OBD_MD_FLRDEV)
2769 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2771 if (body->mbo_valid & OBD_MD_FLID) {
2772 /* FID shouldn't be changed! */
2773 if (fid_is_sane(&lli->lli_fid)) {
2774 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2775 "Trying to change FID "DFID
2776 " to the "DFID", inode "DFID"(%p)\n",
2777 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2778 PFID(ll_inode2fid(inode)), inode);
2780 lli->lli_fid = body->mbo_fid1;
2784 LASSERT(fid_seq(&lli->lli_fid) != 0);
2786 /* In case of encrypted file without the key, please do not lose
2787 * clear text size stored into lli_lazysize in ll_merge_attr(),
2788 * we will need it in ll_prepare_close().
2790 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2791 llcrypt_require_key(inode) == -ENOKEY)
2792 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2794 lli->lli_attr_valid = body->mbo_valid;
2795 if (body->mbo_valid & OBD_MD_FLSIZE) {
2796 i_size_write(inode, body->mbo_size);
2798 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2799 PFID(ll_inode2fid(inode)),
2800 (unsigned long long)body->mbo_size);
2802 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2803 inode->i_blocks = body->mbo_blocks;
2805 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2806 lli->lli_lazysize = body->mbo_size;
2807 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2808 lli->lli_lazyblocks = body->mbo_blocks;
2811 if (body->mbo_valid & OBD_MD_TSTATE) {
2812 /* Set LLIF_FILE_RESTORING if restore ongoing and
2813 * clear it when done to ensure to start again
2814 * glimpsing updated attrs
2816 if (body->mbo_t_state & MS_RESTORE)
2817 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2819 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2825 /* child default LMV is inherited from parent */
2826 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2827 struct lmv_stripe_md *cdmv)
2832 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2833 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2834 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2835 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2838 if (cdmv->lsm_md_max_inherit !=
2839 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2842 if (cdmv->lsm_md_max_inherit_rr !=
2843 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2849 /* update directory depth to ROOT, called after LOOKUP lock is fetched. */
2850 void ll_update_dir_depth(struct inode *dir, struct inode *inode)
2852 struct ll_inode_info *plli;
2853 struct ll_inode_info *lli;
2855 if (!S_ISDIR(inode->i_mode))
2861 plli = ll_i2info(dir);
2862 lli = ll_i2info(inode);
2863 lli->lli_dir_depth = plli->lli_dir_depth + 1;
2864 if (plli->lli_default_lsm_md && lli->lli_default_lsm_md) {
2865 down_read(&plli->lli_lsm_sem);
2866 down_read(&lli->lli_lsm_sem);
2867 if (ll_default_lmv_inherited(plli->lli_default_lsm_md,
2868 lli->lli_default_lsm_md))
2869 lli->lli_inherit_depth =
2870 plli->lli_inherit_depth + 1;
2872 lli->lli_inherit_depth = 0;
2873 up_read(&lli->lli_lsm_sem);
2874 up_read(&plli->lli_lsm_sem);
2876 lli->lli_inherit_depth = 0;
2879 CDEBUG(D_INODE, DFID" depth %hu default LMV depth %hu\n",
2880 PFID(&lli->lli_fid), lli->lli_dir_depth, lli->lli_inherit_depth);
2883 void ll_truncate_inode_pages_final(struct inode *inode, struct cl_io *io)
2885 struct address_space *mapping = &inode->i_data;
2886 unsigned long nrpages;
2887 unsigned long flags;
2889 LASSERTF(io == NULL || inode_is_locked(inode), "io %p (type %d)\n",
2890 io, io ? io->ci_type : 0);
2892 truncate_inode_pages_final(mapping);
2894 /* Workaround for LU-118: Note nrpages may not be totally updated when
2895 * truncate_inode_pages() returns, as there can be a page in the process
2896 * of deletion (inside __delete_from_page_cache()) in the specified
2897 * range. Thus mapping->nrpages can be non-zero when this function
2898 * returns even after truncation of the whole mapping. Only do this if
2899 * npages isn't already zero.
2901 nrpages = mapping->nrpages;
2903 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2904 nrpages = mapping->nrpages;
2905 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2906 } /* Workaround end */
2908 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu "
2909 "io %p (io_type %d), "
2910 "see https://jira.whamcloud.com/browse/LU-118\n",
2911 ll_i2sbi(inode)->ll_fsname,
2912 PFID(ll_inode2fid(inode)), inode, nrpages,
2913 io, io ? io->ci_type : 0);
2916 int ll_read_inode2(struct inode *inode, void *opaque)
2918 struct lustre_md *md = opaque;
2919 struct ll_inode_info *lli = ll_i2info(inode);
2923 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2924 PFID(&lli->lli_fid), inode);
2926 /* Core attributes from the MDS first. This is a new inode, and
2927 * the VFS doesn't zero times in the core inode so we have to do
2928 * it ourselves. They will be overwritten by either MDS or OST
2929 * attributes - we just need to make sure they aren't newer.
2931 inode->i_mtime.tv_sec = 0;
2932 inode->i_atime.tv_sec = 0;
2933 inode->i_ctime.tv_sec = 0;
2935 rc = ll_update_inode(inode, md);
2939 /* OIDEBUG(inode); */
2941 #ifdef HAVE_BACKING_DEV_INFO
2942 /* initializing backing dev info. */
2943 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2945 if (S_ISREG(inode->i_mode)) {
2946 struct ll_sb_info *sbi = ll_i2sbi(inode);
2947 inode->i_op = &ll_file_inode_operations;
2948 inode->i_fop = sbi->ll_fop;
2949 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2951 } else if (S_ISDIR(inode->i_mode)) {
2952 inode->i_op = &ll_dir_inode_operations;
2953 inode->i_fop = &ll_dir_operations;
2955 } else if (S_ISLNK(inode->i_mode)) {
2956 inode->i_op = &ll_fast_symlink_inode_operations;
2959 inode->i_op = &ll_special_inode_operations;
2961 init_special_inode(inode, inode->i_mode,
2970 void ll_delete_inode(struct inode *inode)
2972 struct ll_inode_info *lli = ll_i2info(inode);
2975 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2976 /* It is last chance to write out dirty pages,
2977 * otherwise we may lose data while umount.
2979 * If i_nlink is 0 then just discard data. This is safe because
2980 * local inode gets i_nlink 0 from server only for the last
2981 * unlink, so that file is not opened somewhere else
2983 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2984 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2987 ll_truncate_inode_pages_final(inode, NULL);
2988 ll_clear_inode(inode);
2994 /* ioctl commands shared between files and directories */
2995 int ll_iocontrol(struct inode *inode, struct file *file,
2996 unsigned int cmd, void __user *uarg)
2998 struct ll_sb_info *sbi = ll_i2sbi(inode);
2999 struct ptlrpc_request *req = NULL;
3005 RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
3006 case LL_IOC_GETVERSION:
3007 case FS_IOC_GETVERSION:
3008 RETURN(put_user(inode->i_generation, (int __user *)uarg));
3009 case FS_IOC_GETFLAGS: {
3010 struct mdt_body *body;
3011 struct md_op_data *op_data;
3013 if (!ll_access_ok(uarg, sizeof(int)))
3016 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3017 LUSTRE_OPC_ANY, NULL);
3018 if (IS_ERR(op_data))
3019 RETURN(PTR_ERR(op_data));
3021 op_data->op_valid = OBD_MD_FLFLAGS;
3022 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
3023 ll_finish_md_op_data(op_data);
3025 CERROR("%s: failure inode "DFID": rc = %d\n",
3026 sbi->ll_md_exp->exp_obd->obd_name,
3027 PFID(ll_inode2fid(inode)), rc);
3031 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3033 flags = body->mbo_flags;
3034 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
3035 * ext4 equivalent to please lsattr and other e2fsprogs tools
3037 if (flags & LUSTRE_ENCRYPT_FL)
3038 flags |= STATX_ATTR_ENCRYPTED;
3040 ptlrpc_req_finished(req);
3042 RETURN(put_user(flags, (int __user *)uarg));
3044 case FS_IOC_SETFLAGS: {
3046 struct md_op_data *op_data;
3047 struct cl_object *obj;
3048 struct fsxattr fa = { 0 };
3050 if (get_user(flags, (int __user *)uarg))
3053 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3054 if (flags & LUSTRE_PROJINHERIT_FL)
3055 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3057 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3062 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3063 LUSTRE_OPC_ANY, NULL);
3064 if (IS_ERR(op_data))
3065 RETURN(PTR_ERR(op_data));
3067 op_data->op_attr_flags = flags;
3068 op_data->op_xvalid |= OP_XVALID_FLAGS;
3069 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3070 ll_finish_md_op_data(op_data);
3071 ptlrpc_req_finished(req);
3075 ll_update_inode_flags(inode, flags);
3077 obj = ll_i2info(inode)->lli_clob;
3081 OBD_ALLOC_PTR(attr);
3085 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3090 case FS_IOC_FSGETXATTR:
3091 RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
3092 case FS_IOC_FSSETXATTR:
3093 RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
3094 case LL_IOC_PROJECT:
3095 RETURN(ll_ioctl_project(file, cmd, uarg));
3096 case IOC_OBD_STATFS:
3097 RETURN(ll_obd_statfs(inode, uarg));
3098 case LL_IOC_GET_MDTIDX: {
3099 if (!ll_access_ok(uarg, sizeof(rc)))
3102 rc = ll_get_mdt_idx(inode);
3106 if (put_user(rc, (int __user *)uarg))
3111 case LL_IOC_FLUSHCTX:
3112 RETURN(ll_flush_ctx(inode));
3113 #ifdef HAVE_LUSTRE_CRYPTO
3114 case LL_IOC_ADD_ENCRYPTION_KEY:
3115 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3117 rc = llcrypt_ioctl_add_key(file, uarg);
3118 #ifdef CONFIG_LL_ENCRYPTION
3119 if (!rc && S_ISDIR(inode->i_mode))
3120 sptlrpc_enc_pool_add_user();
3123 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
3124 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3126 RETURN(llcrypt_ioctl_get_key_status(file, uarg));
3127 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
3128 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3130 RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
3131 case LL_IOC_SET_ENCRYPTION_POLICY:
3132 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3134 RETURN(llcrypt_ioctl_set_policy(file, uarg));
3135 case LL_IOC_REMOVE_ENCRYPTION_KEY:
3136 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3138 RETURN(llcrypt_ioctl_remove_key(file, uarg));
3139 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
3140 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3142 RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
3144 case LL_IOC_GETPARENT:
3145 RETURN(ll_getparent(file, uarg));
3146 case LL_IOC_PATH2FID:
3147 if (copy_to_user(uarg, ll_inode2fid(inode),
3148 sizeof(struct lu_fid)))
3151 case LL_IOC_UNLOCK_FOREIGN: {
3152 struct dentry *dentry = file_dentry(file);
3154 /* if not a foreign symlink do nothing */
3155 if (ll_foreign_is_removable(dentry, true)) {
3157 "prevent unlink of non-foreign file ("DFID")\n",
3158 PFID(ll_inode2fid(inode)));
3159 RETURN(-EOPNOTSUPP);
3163 case OBD_IOC_FID2PATH:
3164 RETURN(ll_fid2path(inode, uarg));
3165 #ifdef OBD_IOC_GETNAME_OLD
3166 case_OBD_IOC_DEPRECATED_FT(OBD_IOC_GETNAME_OLD,
3167 sbi->ll_md_exp->exp_obd->obd_name, 2, 16);
3169 case OBD_IOC_GETDTNAME:
3170 case OBD_IOC_GETMDNAME:
3171 RETURN(ll_get_obd_name(inode, cmd, uarg));
3179 int ll_flush_ctx(struct inode *inode)
3181 struct ll_sb_info *sbi = ll_i2sbi(inode);
3183 CDEBUG(D_SEC, "flush context for user %d\n",
3184 from_kuid(&init_user_ns, current_uid()));
3186 obd_set_info_async(NULL, sbi->ll_md_exp,
3187 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3189 obd_set_info_async(NULL, sbi->ll_dt_exp,
3190 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3195 /* umount -f client means force down, don't save state */
3196 void ll_umount_begin(struct super_block *sb)
3198 struct ll_sb_info *sbi = ll_s2sbi(sb);
3199 struct obd_device *obd;
3200 struct obd_ioctl_data *ioc_data;
3204 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3205 sb->s_count, atomic_read(&sb->s_active));
3207 obd = class_exp2obd(sbi->ll_md_exp);
3209 CERROR("Invalid MDC connection handle %#llx\n",
3210 sbi->ll_md_exp->exp_handle.h_cookie);
3216 obd = class_exp2obd(sbi->ll_dt_exp);
3218 CERROR("Invalid LOV connection handle %#llx\n",
3219 sbi->ll_dt_exp->exp_handle.h_cookie);
3225 OBD_ALLOC_PTR(ioc_data);
3227 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_md_exp,
3228 sizeof *ioc_data, ioc_data, NULL);
3230 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_dt_exp,
3231 sizeof *ioc_data, ioc_data, NULL);
3233 OBD_FREE_PTR(ioc_data);
3236 /* Really, we'd like to wait until there are no requests outstanding,
3237 * and then continue. For now, we just periodically checking for vfs
3238 * to decrement mnt_cnt and hope to finish it within 10sec.
3242 !may_umount(sbi->ll_mnt.mnt)) {
3250 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3252 struct ll_sb_info *sbi = ll_s2sbi(sb);
3253 char *profilenm = get_profile_name(sb);
3257 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3258 read_only = *flags & MS_RDONLY;
3259 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3260 sizeof(KEY_READ_ONLY),
3261 KEY_READ_ONLY, sizeof(read_only),
3264 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3265 profilenm, read_only ?
3266 "read-only" : "read-write", err);
3271 sb->s_flags |= SB_RDONLY;
3273 sb->s_flags &= ~SB_RDONLY;
3275 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3276 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3277 read_only ? "read-only" : "read-write");
3283 * Cleanup the open handle that is cached on MDT-side.
3285 * For open case, the client side open handling thread may hit error
3286 * after the MDT grant the open. Under such case, the client should
3287 * send close RPC to the MDT as cleanup; otherwise, the open handle
3288 * on the MDT will be leaked there until the client umount or evicted.
3290 * In further, if someone unlinked the file, because the open handle
3291 * holds the reference on such file/object, then it will block the
3292 * subsequent threads that want to locate such object via FID.
3294 * \param[in] sb super block for this file-system
3295 * \param[in] open_req pointer to the original open request
3297 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3299 struct mdt_body *body;
3300 struct md_op_data *op_data;
3301 struct ptlrpc_request *close_req = NULL;
3302 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3305 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3306 OBD_ALLOC_PTR(op_data);
3307 if (op_data == NULL) {
3308 CWARN("%s: cannot allocate op_data to release open handle for "
3309 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3314 op_data->op_fid1 = body->mbo_fid1;
3315 op_data->op_open_handle = body->mbo_open_handle;
3316 op_data->op_mod_time = ktime_get_real_seconds();
3317 md_close(exp, op_data, NULL, &close_req);
3318 ptlrpc_req_finished(close_req);
3319 ll_finish_md_op_data(op_data);
3324 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3325 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3326 struct lustre_md *md)
3328 struct ll_sb_info *sbi = ll_i2sbi(inode);
3329 struct ptlrpc_request *req = NULL;
3330 union lmv_mds_md *lmm = NULL;
3334 LASSERT(is_root_inode(inode));
3335 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3336 LASSERT(!md->default_lmv);
3338 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3340 GET_DEFAULT_LAYOUT_ROOT);
3341 if (rc && rc != -ENODATA)
3346 rc = md_unpackmd(sbi->ll_md_exp, &md->default_lmv, lmm, size);
3355 ptlrpc_req_finished(req);
3359 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3360 struct super_block *sb, struct lookup_intent *it)
3362 struct ll_sb_info *sbi = NULL;
3363 struct lustre_md md = { NULL };
3364 bool default_lmv_deleted = false;
3369 LASSERT(*inode || sb);
3370 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3371 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3372 sbi->ll_md_exp, &md);
3377 * clear default_lmv only if intent_getattr reply doesn't contain it.
3378 * but it needs to be done after iget, check this early because
3379 * ll_update_lsm_md() may change md.
3381 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3382 S_ISDIR(md.body->mbo_mode) && !md.default_lmv) {
3383 if (unlikely(*inode && is_root_inode(*inode) &&
3384 !fid_is_root(&sbi->ll_root_fid))) {
3385 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3390 if (!md.default_lmv)
3391 default_lmv_deleted = true;
3395 rc = ll_update_inode(*inode, &md);
3399 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3400 struct lu_fid *fid1 = &md.body->mbo_fid1;
3402 LASSERT(sb != NULL);
3405 * At this point server returns to client's same fid as client
3406 * generated for creating. So using ->fid1 is okay here.
3408 if (!fid_is_sane(fid1)) {
3409 CERROR("%s: Fid is insane "DFID"\n",
3410 sbi->ll_fsname, PFID(fid1));
3411 GOTO(out, rc = -EINVAL);
3414 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3415 if (IS_ERR(*inode)) {
3417 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3419 CERROR("new_inode -fatal: rc %d\n", rc);
3424 /* Handling piggyback layout lock.
3425 * Layout lock can be piggybacked by getattr and open request.
3426 * The lsm can be applied to inode only if it comes with a layout lock
3427 * otherwise correct layout may be overwritten, for example:
3428 * 1. proc1: mdt returns a lsm but not granting layout
3429 * 2. layout was changed by another client
3430 * 3. proc2: refresh layout and layout lock granted
3431 * 4. proc1: to apply a stale layout */
3432 if (it != NULL && it->it_lock_mode != 0) {
3433 struct lustre_handle lockh;
3434 struct ldlm_lock *lock;
3436 lockh.cookie = it->it_lock_handle;
3437 lock = ldlm_handle2lock(&lockh);
3438 LASSERT(lock != NULL);
3439 if (ldlm_has_layout(lock)) {
3440 struct cl_object_conf conf;
3442 memset(&conf, 0, sizeof(conf));
3443 conf.coc_opc = OBJECT_CONF_SET;
3444 conf.coc_inode = *inode;
3445 conf.coc_lock = lock;
3446 conf.u.coc_layout = md.layout;
3447 (void)ll_layout_conf(*inode, &conf);
3449 LDLM_LOCK_PUT(lock);
3452 if (default_lmv_deleted)
3453 ll_update_default_lsm_md(*inode, &md);
3455 /* we may want to apply some policy for foreign file/dir */
3456 if (ll_sbi_has_foreign_symlink(sbi)) {
3457 rc = ll_manage_foreign(*inode, &md);
3465 /* cleanup will be done if necessary */
3466 md_free_lustre_md(sbi->ll_md_exp, &md);
3468 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3469 ll_intent_drop_lock(it);
3470 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3476 int ll_obd_statfs(struct inode *inode, void __user *uarg)
3478 struct ll_sb_info *sbi = NULL;
3479 struct obd_export *exp;
3480 struct obd_ioctl_data *data = NULL;
3485 sbi = ll_i2sbi(inode);
3487 GOTO(out_statfs, rc = -EINVAL);
3489 rc = obd_ioctl_getdata(&data, &len, uarg);
3491 GOTO(out_statfs, rc);
3493 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3494 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3495 GOTO(out_statfs, rc = -EINVAL);
3497 if (data->ioc_inllen1 != sizeof(__u32) ||
3498 data->ioc_inllen2 != sizeof(__u32) ||
3499 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3500 data->ioc_plen2 != sizeof(struct obd_uuid))
3501 GOTO(out_statfs, rc = -EINVAL);
3503 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3504 if (type & LL_STATFS_LMV)
3505 exp = sbi->ll_md_exp;
3506 else if (type & LL_STATFS_LOV)
3507 exp = sbi->ll_dt_exp;
3509 GOTO(out_statfs, rc = -ENODEV);
3511 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3513 GOTO(out_statfs, rc);
3515 OBD_FREE_LARGE(data, len);
3520 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3521 * be called early to avoid deadlock.
3523 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3525 if (op_data->op_mea2_sem) {
3526 up_read_non_owner(op_data->op_mea2_sem);
3527 op_data->op_mea2_sem = NULL;
3530 if (op_data->op_mea1_sem) {
3531 up_read_non_owner(op_data->op_mea1_sem);
3532 op_data->op_mea1_sem = NULL;
3536 /* this function prepares md_op_data hint for passing it down to MD stack. */
3537 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3538 struct inode *i1, struct inode *i2,
3539 const char *name, size_t namelen,
3540 __u32 mode, enum md_op_code opc,
3543 struct llcrypt_name fname = { 0 };
3546 LASSERT(i1 != NULL);
3549 /* Do not reuse namelen for something else. */
3551 return ERR_PTR(-EINVAL);
3553 if ((!IS_ENCRYPTED(i1) ||
3554 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3555 namelen > ll_i2sbi(i1)->ll_namelen)
3556 return ERR_PTR(-ENAMETOOLONG);
3558 /* "/" is not valid name, but it's allowed */
3559 if (!lu_name_is_valid_2(name, namelen) &&
3560 strncmp("/", name, namelen) != 0)
3561 return ERR_PTR(-EINVAL);
3564 if (op_data == NULL)
3565 OBD_ALLOC_PTR(op_data);
3567 if (op_data == NULL)
3568 return ERR_PTR(-ENOMEM);
3570 ll_i2gids(op_data->op_suppgids, i1, i2);
3571 /* If the client is using a subdir mount and looks at what it sees as
3572 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3574 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3575 !fid_is_root(ll_inode2fid(i1)) &&
3576 name && namelen == strlen(dot_fscrypt_name) &&
3577 strncmp(name, dot_fscrypt_name, namelen) == 0))
3578 lu_root_fid(&op_data->op_fid1);
3580 op_data->op_fid1 = *ll_inode2fid(i1);
3582 if (S_ISDIR(i1->i_mode)) {
3583 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3584 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3585 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3586 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3590 op_data->op_fid2 = *ll_inode2fid(i2);
3591 if (S_ISDIR(i2->i_mode)) {
3593 /* i2 is typically a child of i1, and MUST be
3594 * further from the root to avoid deadlocks.
3596 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3597 op_data->op_mea2_sem =
3598 &ll_i2info(i2)->lli_lsm_sem;
3600 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3603 fid_zero(&op_data->op_fid2);
3606 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3607 op_data->op_cli_flags |= CLI_HASH64;
3609 if (ll_need_32bit_api(ll_i2sbi(i1)))
3610 op_data->op_cli_flags |= CLI_API32;
3612 if ((i2 && is_root_inode(i2)) ||
3613 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3614 /* In case of lookup, ll_setup_filename() has already been
3615 * called in ll_lookup_it(), so just take provided name.
3616 * Also take provided name if we are dealing with root inode.
3618 fname.disk_name.name = (unsigned char *)name;
3619 fname.disk_name.len = namelen;
3620 } else if (name && namelen) {
3621 struct qstr dname = QSTR_INIT(name, namelen);
3623 struct lu_fid *pfid = NULL;
3627 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3628 /* special case when called from ll_link() */
3633 lookup = (int)(opc == LUSTRE_OPC_ANY);
3635 if (opc == LUSTRE_OPC_ANY && lookup)
3637 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3639 ll_finish_md_op_data(op_data);
3642 if (pfid && !fid_is_zero(pfid)) {
3644 op_data->op_fid2 = fid;
3645 op_data->op_bias = MDS_FID_OP;
3647 if (fname.disk_name.name &&
3648 fname.disk_name.name != (unsigned char *)name) {
3649 /* op_data->op_name must be freed after use */
3650 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3654 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3655 * are LUSTRE_OPC_ANY
3657 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3658 op_data->op_code = LUSTRE_OPC_ANY;
3660 op_data->op_code = opc;
3661 op_data->op_name = fname.disk_name.name;
3662 op_data->op_namelen = fname.disk_name.len;
3663 op_data->op_mode = mode;
3664 op_data->op_mod_time = ktime_get_real_seconds();
3665 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3666 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3667 op_data->op_cap = current_cap();
3668 op_data->op_mds = 0;
3669 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3670 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3671 op_data->op_bias |= MDS_CREATE_VOLATILE;
3673 op_data->op_data = data;
3678 void ll_finish_md_op_data(struct md_op_data *op_data)
3680 ll_unlock_md_op_lsm(op_data);
3681 ll_security_release_secctx(op_data->op_file_secctx,
3682 op_data->op_file_secctx_size);
3683 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3684 /* allocated via ll_setup_filename called
3685 * from ll_prep_md_op_data
3687 kfree(op_data->op_name);
3688 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3689 OBD_FREE_PTR(op_data);
3692 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3694 struct ll_sb_info *sbi;
3697 LASSERT(seq && dentry);
3698 sbi = ll_s2sbi(dentry->d_sb);
3700 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3701 seq_puts(seq, "nolock");
3703 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3704 /* match_table in some cases has patterns for both enabled and
3705 * disabled cases. Ignore 'no'xxx versions if bit is set.
3707 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3708 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3709 if (ll_sbi_flags_name[i].token ==
3710 LL_SBI_FOREIGN_SYMLINK) {
3711 seq_show_option(seq, "foreign_symlink",
3712 sbi->ll_foreign_symlink_prefix);
3714 seq_printf(seq, ",%s",
3715 ll_sbi_flags_name[i].pattern);
3718 /* You can have either localflock or flock but not
3719 * both. If localflock is set don't print flock or
3722 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3724 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3725 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3726 seq_printf(seq, ",%s",
3727 ll_sbi_flags_name[i].pattern);
3731 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3737 * Get obd name by cmd, and copy out to user space
3739 int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg)
3741 struct ll_sb_info *sbi = ll_i2sbi(inode);
3742 struct obd_device *obd;
3745 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3746 obd = class_exp2obd(sbi->ll_dt_exp);
3747 else if (cmd == OBD_IOC_GETMDNAME)
3748 obd = class_exp2obd(sbi->ll_md_exp);
3755 if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1))
3762 struct work_struct db_work;
3763 struct dentry *db_dentry;
3764 /* Let's hope the path is not too long, 32 bytes for the work struct
3767 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3770 static void ll_dput_later(struct work_struct *work)
3772 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3774 dput(db->db_dentry);
3775 free_page((unsigned long)db);
3778 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3785 p.mnt = current->fs->root.mnt;
3787 path = d_path(&p, buf, bufsize);
3792 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3794 struct dname_buf *db;
3796 struct dentry *dentry = NULL;
3798 /* this can be called inside spin lock so use GFP_ATOMIC. */
3799 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3802 dentry = d_find_alias(inode);
3804 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3807 /* The below message is checked in recovery-small.sh test_24b */
3809 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3810 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3811 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3812 PFID(ll_inode2fid(inode)),
3813 (path && !IS_ERR(path)) ? path : "", ioret);
3815 if (dentry != NULL) {
3816 /* We cannot dput here since if we happen to be the last holder
3817 * then we can end up waiting for page evictions that
3818 * in turn wait for RPCs that need this instance of ptlrpcd
3819 * (callng brw_interpret->*page_completion*->vmpage_error->here)
3822 INIT_WORK(&db->db_work, ll_dput_later);
3823 db->db_dentry = dentry;
3824 schedule_work(&db->db_work);
3827 free_page((unsigned long)db);
3831 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3832 struct lov_user_md **kbuf)
3834 struct lov_user_md lum;
3838 if (copy_from_user(&lum, md, sizeof(lum)))
3841 lum_size = ll_lov_user_md_size(&lum);
3845 OBD_ALLOC_LARGE(*kbuf, lum_size);
3849 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3850 OBD_FREE_LARGE(*kbuf, lum_size);
3858 * Compute llite root squash state after a change of root squash
3859 * configuration setting or add/remove of a lnet nid
3861 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3863 struct root_squash_info *squash = &sbi->ll_squash;
3866 struct lnet_processid id;
3868 /* Update norootsquash flag */
3869 spin_lock(&squash->rsi_lock);
3870 if (list_empty(&squash->rsi_nosquash_nids))
3871 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3873 /* Do not apply root squash as soon as one of our NIDs is
3874 * in the nosquash_nids list */
3877 while (LNetGetId(i++, &id) != -ENOENT) {
3878 if (nid_is_lo0(&id.nid))
3880 if (cfs_match_nid(&id.nid,
3881 &squash->rsi_nosquash_nids)) {
3887 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3889 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3891 spin_unlock(&squash->rsi_lock);
3895 * Parse linkea content to extract information about a given hardlink
3897 * \param[in] ldata - Initialized linkea data
3898 * \param[in] linkno - Link identifier
3899 * \param[out] parent_fid - The entry's parent FID
3900 * \param[out] ln - Entry name destination buffer
3902 * \retval 0 on success
3903 * \retval Appropriate negative error code on failure
3905 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3906 struct lu_fid *parent_fid, struct lu_name *ln)
3912 rc = linkea_init_with_rec(ldata);
3916 if (linkno >= ldata->ld_leh->leh_reccount)
3917 /* beyond last link */
3920 linkea_first_entry(ldata);
3921 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3922 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3927 linkea_next_entry(ldata);
3937 * Get parent FID and name of an identified link. Operation is performed for
3938 * a given link number, letting the caller iterate over linkno to list one or
3939 * all links of an entry.
3941 * \param[in] file - File descriptor against which to perform the operation
3942 * \param[in,out] arg - User-filled structure containing the linkno to operate
3943 * on and the available size. It is eventually filled with
3944 * the requested information or left untouched on error
3946 * \retval - 0 on success
3947 * \retval - Appropriate negative error code on failure
3949 int ll_getparent(struct file *file, struct getparent __user *arg)
3951 struct inode *inode = file_inode(file);
3952 struct linkea_data *ldata;
3953 struct lu_buf buf = LU_BUF_NULL;
3955 struct lu_fid parent_fid;
3962 if (!capable(CAP_DAC_READ_SEARCH) &&
3963 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
3966 if (get_user(name_size, &arg->gp_name_size))
3969 if (get_user(linkno, &arg->gp_linkno))
3972 if (name_size > PATH_MAX)
3975 OBD_ALLOC(ldata, sizeof(*ldata));
3979 rc = linkea_data_new(ldata, &buf);
3981 GOTO(ldata_free, rc);
3983 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3984 buf.lb_len, OBD_MD_FLXATTR);
3988 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3992 if (ln.ln_namelen >= name_size)
3993 GOTO(lb_free, rc = -EOVERFLOW);
3995 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3996 GOTO(lb_free, rc = -EFAULT);
3998 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3999 GOTO(lb_free, rc = -EFAULT);
4001 if (put_user('\0', arg->gp_name + ln.ln_namelen))
4002 GOTO(lb_free, rc = -EFAULT);
4007 OBD_FREE(ldata, sizeof(*ldata));