4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/llite/llite_lib.c
33 * Lustre Light Super operations
36 #define DEBUG_SUBSYSTEM S_LLITE
38 #include <linux/cpu.h>
39 #include <linux/module.h>
40 #include <linux/random.h>
41 #include <linux/statfs.h>
42 #include <linux/time.h>
43 #include <linux/file.h>
44 #include <linux/types.h>
45 #include <libcfs/linux/linux-uuid.h>
46 #include <linux/version.h>
48 #include <linux/user_namespace.h>
49 #include <linux/delay.h>
50 #include <linux/uidgid.h>
51 #include <linux/fs_struct.h>
53 #ifndef HAVE_CPUS_READ_LOCK
54 #include <libcfs/linux/linux-cpu.h>
56 #include <libcfs/linux/linux-misc.h>
57 #include <uapi/linux/lustre/lustre_ioctl.h>
58 #ifdef HAVE_UAPI_LINUX_MOUNT_H
59 #include <uapi/linux/mount.h>
62 #include <lustre_ha.h>
63 #include <lustre_dlm.h>
64 #include <lprocfs_status.h>
65 #include <lustre_disk.h>
66 #include <uapi/linux/lustre/lustre_param.h>
67 #include <lustre_log.h>
68 #include <cl_object.h>
69 #include <obd_cksum.h>
70 #include "llite_internal.h"
72 struct kmem_cache *ll_file_data_slab;
75 #define log2(n) ffz(~(n))
79 * If there is only one number of core visible to Lustre,
80 * async readahead will be disabled, to avoid massive over
81 * subscription, we use 1/2 of active cores as default max
82 * async readahead requests.
84 static inline unsigned int ll_get_ra_async_max_active(void)
86 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
89 static struct ll_sb_info *ll_init_sbi(void)
91 struct ll_sb_info *sbi = NULL;
93 unsigned long lru_page_max;
101 RETURN(ERR_PTR(-ENOMEM));
103 rc = pcc_super_init(&sbi->ll_pcc_super);
107 spin_lock_init(&sbi->ll_lock);
108 mutex_init(&sbi->ll_lco.lco_lock);
109 spin_lock_init(&sbi->ll_pp_extent_lock);
110 spin_lock_init(&sbi->ll_process_lock);
111 sbi->ll_rw_stats_on = 0;
112 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
115 pages = si.totalram - si.totalhigh;
116 lru_page_max = pages / 2;
118 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
119 sbi->ll_ra_info.ll_readahead_wq =
120 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
122 sbi->ll_ra_info.ra_async_max_active);
123 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
124 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
126 /* initialize ll_cache data */
127 sbi->ll_cache = cl_cache_init(lru_page_max);
128 if (sbi->ll_cache == NULL)
129 GOTO(out_destroy_ra, rc = -ENOMEM);
131 /* initialize foreign symlink prefix path */
132 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
133 if (sbi->ll_foreign_symlink_prefix == NULL)
134 GOTO(out_destroy_ra, rc = -ENOMEM);
135 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
136 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
138 /* initialize foreign symlink upcall path, none by default */
139 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
140 if (sbi->ll_foreign_symlink_upcall == NULL)
141 GOTO(out_destroy_ra, rc = -ENOMEM);
142 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
143 sbi->ll_foreign_symlink_upcall_items = NULL;
144 sbi->ll_foreign_symlink_upcall_nb_items = 0;
145 init_rwsem(&sbi->ll_foreign_symlink_sem);
146 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
147 * not enabled by default
150 sbi->ll_ra_info.ra_max_pages =
151 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
152 sbi->ll_ra_info.ra_max_pages_per_file =
153 min(sbi->ll_ra_info.ra_max_pages / 4,
154 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
155 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
156 sbi->ll_ra_info.ra_max_pages_per_file;
157 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
158 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
159 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
161 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
162 #ifdef ENABLE_CHECKSUM
163 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
166 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
169 #ifdef HAVE_LRU_RESIZE_SUPPORT
170 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
172 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
174 /* metadata statahead is enabled by default */
175 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
176 sbi->ll_sa_max = LL_SA_RPC_DEF;
177 atomic_set(&sbi->ll_sa_total, 0);
178 atomic_set(&sbi->ll_sa_wrong, 0);
179 atomic_set(&sbi->ll_sa_running, 0);
180 atomic_set(&sbi->ll_agl_total, 0);
181 atomic_set(&sbi->ll_sa_hit_total, 0);
182 atomic_set(&sbi->ll_sa_miss_total, 0);
183 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
184 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
185 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
186 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
187 ll_sbi_set_encrypt(sbi, true);
188 ll_sbi_set_name_encrypt(sbi, true);
191 sbi->ll_squash.rsi_uid = 0;
192 sbi->ll_squash.rsi_gid = 0;
193 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
194 spin_lock_init(&sbi->ll_squash.rsi_lock);
196 /* Per-filesystem file heat */
197 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
198 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
200 /* Per-fs open heat level before requesting open lock */
201 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
202 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
203 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
206 if (sbi->ll_foreign_symlink_prefix)
207 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
209 cl_cache_decref(sbi->ll_cache);
210 sbi->ll_cache = NULL;
212 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
214 pcc_super_fini(&sbi->ll_pcc_super);
220 static void ll_free_sbi(struct super_block *sb)
222 struct ll_sb_info *sbi = ll_s2sbi(sb);
226 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
227 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
228 if (sbi->ll_ra_info.ll_readahead_wq)
229 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
230 if (sbi->ll_cache != NULL) {
231 cl_cache_decref(sbi->ll_cache);
232 sbi->ll_cache = NULL;
234 if (sbi->ll_foreign_symlink_prefix) {
235 OBD_FREE(sbi->ll_foreign_symlink_prefix,
236 sbi->ll_foreign_symlink_prefix_size);
237 sbi->ll_foreign_symlink_prefix = NULL;
239 if (sbi->ll_foreign_symlink_upcall) {
240 OBD_FREE(sbi->ll_foreign_symlink_upcall,
241 strlen(sbi->ll_foreign_symlink_upcall) +
243 sbi->ll_foreign_symlink_upcall = NULL;
245 if (sbi->ll_foreign_symlink_upcall_items) {
247 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
248 struct ll_foreign_symlink_upcall_item *items =
249 sbi->ll_foreign_symlink_upcall_items;
251 for (i = 0 ; i < nb_items; i++)
252 if (items[i].type == STRING_TYPE)
253 OBD_FREE(items[i].string,
256 OBD_FREE_LARGE(items, nb_items *
257 sizeof(struct ll_foreign_symlink_upcall_item));
258 sbi->ll_foreign_symlink_upcall_items = NULL;
260 ll_free_rw_stats_info(sbi);
261 pcc_super_fini(&sbi->ll_pcc_super);
262 OBD_FREE(sbi, sizeof(*sbi));
267 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
269 struct inode *root = NULL;
270 struct ll_sb_info *sbi = ll_s2sbi(sb);
271 struct obd_statfs *osfs = NULL;
272 struct ptlrpc_request *request = NULL;
273 struct obd_connect_data *data = NULL;
274 struct obd_uuid *uuid;
275 struct md_op_data *op_data;
276 struct lustre_md lmd;
278 int size, err, checksum;
284 sbi->ll_md_obd = class_name2obd(md);
285 if (!sbi->ll_md_obd) {
286 CERROR("MD %s: not setup or attached\n", md);
300 /* pass client page size via ocd_grant_blkbits, the server should report
301 * back its backend blocksize for grant calculation purpose */
302 data->ocd_grant_blkbits = PAGE_SHIFT;
304 /* indicate MDT features supported by this client */
305 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
306 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
307 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
308 OBD_CONNECT_SRVLOCK |
309 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
310 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
311 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
312 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
313 OBD_CONNECT_64BITHASH |
314 OBD_CONNECT_EINPROGRESS |
315 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
316 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
317 OBD_CONNECT_MAX_EASIZE |
318 OBD_CONNECT_FLOCK_DEAD |
319 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
320 OBD_CONNECT_OPEN_BY_FID |
321 OBD_CONNECT_DIR_STRIPE |
322 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
323 OBD_CONNECT_SUBTREE |
324 OBD_CONNECT_MULTIMODRPCS |
325 OBD_CONNECT_GRANT_PARAM |
326 OBD_CONNECT_GRANT_SHRINK |
327 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
329 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
330 OBD_CONNECT2_SUM_STATFS |
331 OBD_CONNECT2_OVERSTRIPING |
333 OBD_CONNECT2_LOCK_CONVERT |
334 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
335 OBD_CONNECT2_INC_XID |
337 OBD_CONNECT2_ASYNC_DISCARD |
339 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
340 OBD_CONNECT2_GETATTR_PFID |
341 OBD_CONNECT2_DOM_LVB |
342 OBD_CONNECT2_REP_MBITS |
343 OBD_CONNECT2_ATOMIC_OPEN_LOCK;
345 #ifdef HAVE_LRU_RESIZE_SUPPORT
346 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
347 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
349 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
351 data->ocd_cksum_types = obd_cksum_types_supported_client();
353 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
354 /* flag mdc connection as lightweight, only used for test
355 * purpose, use with care */
356 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
358 data->ocd_ibits_known = MDS_INODELOCK_FULL;
359 data->ocd_version = LUSTRE_VERSION_CODE;
361 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
362 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
365 /* Setting this indicates we correctly support S_NOSEC (See kernel
366 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
368 sb->s_flags |= SB_NOSEC;
370 sbi->ll_fop = ll_select_file_operations(sbi);
372 /* always ping even if server suppress_pings */
373 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
374 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
376 obd_connect_set_secctx(data);
377 if (ll_sbi_has_encrypt(sbi)) {
378 obd_connect_set_name_enc(data);
379 obd_connect_set_enc(data);
382 #if defined(CONFIG_SECURITY)
383 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
386 data->ocd_brw_size = MD_MAX_BRW_SIZE;
389 if (sb->s_flags & SB_RDONLY)
390 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
391 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
392 &sbi->ll_sb_uuid, data, sbi->ll_cache);
394 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
395 "recovery, of which this client is not a "
396 "part. Please wait for recovery to complete,"
397 " abort, or time out.\n", md);
400 CERROR("cannot connect to %s: rc = %d\n", md, err);
404 sbi->ll_md_exp->exp_connect_data = *data;
406 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
407 LUSTRE_SEQ_METADATA);
409 CERROR("%s: Can't init metadata layer FID infrastructure, "
410 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
414 /* For mount, we only need fs info from MDT0, and also in DNE, it
415 * can make sure the client can be mounted as long as MDT0 is
417 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
418 ktime_get_seconds() - sbi->ll_statfs_max_age,
419 OBD_STATFS_FOR_MDT0);
420 if (err == -EROFS && !(sb->s_flags & SB_RDONLY)) {
421 /* We got -EROFS from the server, maybe it is imposing
422 * read-only mount. So just retry like this.
424 cfs_tty_write_msg("Forcing read-only mount.\n\r");
425 CERROR("%s: mount failed with %d, forcing read-only mount.\n",
426 sbi->ll_md_exp->exp_obd->obd_name, err);
427 sb->s_flags |= SB_RDONLY;
428 obd_fid_fini(sbi->ll_md_exp->exp_obd);
429 obd_disconnect(sbi->ll_md_exp);
430 GOTO(retry_connect, err);
432 GOTO(out_md_fid, err);
435 /* This needs to be after statfs to ensure connect has finished.
436 * Note that "data" does NOT contain the valid connect reply.
437 * If connecting to a 1.8 server there will be no LMV device, so
438 * we can access the MDC export directly and exp_connect_flags will
439 * be non-zero, but if accessing an upgraded 2.1 server it will
440 * have the correct flags filled in.
441 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
442 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
443 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
444 valid != CLIENT_CONNECT_MDT_REQD) {
447 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
448 obd_connect_flags2str(buf, PAGE_SIZE,
449 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
450 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
451 "feature(s) needed for correct operation "
452 "of this client (%s). Please upgrade "
453 "server or downgrade client.\n",
454 sbi->ll_md_exp->exp_obd->obd_name, buf);
455 OBD_FREE(buf, PAGE_SIZE);
456 GOTO(out_md_fid, err = -EPROTO);
459 size = sizeof(*data);
460 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
461 KEY_CONN_DATA, &size, data);
463 CERROR("%s: Get connect data failed: rc = %d\n",
464 sbi->ll_md_exp->exp_obd->obd_name, err);
465 GOTO(out_md_fid, err);
468 LASSERT(osfs->os_bsize);
469 sb->s_blocksize = osfs->os_bsize;
470 sb->s_blocksize_bits = log2(osfs->os_bsize);
471 sb->s_magic = LL_SUPER_MAGIC;
472 sb->s_maxbytes = MAX_LFS_FILESIZE;
473 sbi->ll_inode_cache_enabled = 1;
474 sbi->ll_namelen = osfs->os_namelen;
475 sbi->ll_mnt.mnt = current->fs->root.mnt;
476 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
478 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
479 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
480 LCONSOLE_INFO("Disabling user_xattr feature because "
481 "it is not supported on the server\n");
482 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
485 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
487 sb->s_flags |= SB_POSIXACL;
489 set_bit(LL_SBI_ACL, sbi->ll_flags);
491 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
493 sb->s_flags &= ~SB_POSIXACL;
495 clear_bit(LL_SBI_ACL, sbi->ll_flags);
498 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
499 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
501 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
502 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
504 if (obd_connect_has_secctx(data))
505 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
507 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
508 if (ll_sb_has_test_dummy_encryption(sb))
509 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
511 sbi->ll_md_exp->exp_obd->obd_name);
512 ll_sbi_set_encrypt(sbi, false);
515 if (ll_sbi_has_name_encrypt(sbi) && !obd_connect_has_name_enc(data)) {
516 struct lustre_sb_info *lsi = s2lsi(sb);
518 if (ll_sb_has_test_dummy_encryption(sb))
519 LCONSOLE_WARN("%s: server %s does not support name encryption, not using it.\n",
521 sbi->ll_md_exp->exp_obd->obd_name);
522 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
523 ll_sbi_set_name_encrypt(sbi, false);
526 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
527 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
528 LCONSOLE_INFO("%s: disabling xattr cache due to "
529 "unknown maximum xattr size.\n", dt);
530 } else if (!sbi->ll_xattr_cache_set) {
531 /* If xattr_cache is already set (no matter 0 or 1)
532 * during processing llog, it won't be enabled here. */
533 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
534 sbi->ll_xattr_cache_enabled = 1;
538 sbi->ll_dt_obd = class_name2obd(dt);
539 if (!sbi->ll_dt_obd) {
540 CERROR("DT %s: not setup or attached\n", dt);
541 GOTO(out_md_fid, err = -ENODEV);
544 /* pass client page size via ocd_grant_blkbits, the server should report
545 * back its backend blocksize for grant calculation purpose */
546 data->ocd_grant_blkbits = PAGE_SHIFT;
548 /* indicate OST features supported by this client */
549 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
550 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
551 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
552 OBD_CONNECT_SRVLOCK |
553 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
554 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
555 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
556 OBD_CONNECT_EINPROGRESS |
557 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
558 OBD_CONNECT_LAYOUTLOCK |
559 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
560 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
561 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
562 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
563 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
564 OBD_CONNECT2_REP_MBITS;
566 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
567 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
569 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
570 * disabled by default, because it can still be enabled on the
571 * fly via /sys. As a consequence, we still need to come to an
572 * agreement on the supported algorithms at connect time
574 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
576 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
577 data->ocd_cksum_types = OBD_CKSUM_ADLER;
579 data->ocd_cksum_types = obd_cksum_types_supported_client();
581 #ifdef HAVE_LRU_RESIZE_SUPPORT
582 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
584 /* always ping even if server suppress_pings */
585 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
586 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
588 if (ll_sbi_has_encrypt(sbi))
589 obd_connect_set_enc(data);
591 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
592 "ocd_grant: %d\n", data->ocd_connect_flags,
593 data->ocd_version, data->ocd_grant);
595 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
596 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
598 data->ocd_brw_size = DT_MAX_BRW_SIZE;
600 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
601 &sbi->ll_sb_uuid, data, sbi->ll_cache);
603 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
604 "recovery, of which this client is not a "
605 "part. Please wait for recovery to "
606 "complete, abort, or time out.\n", dt);
609 CERROR("%s: Cannot connect to %s: rc = %d\n",
610 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
614 if (ll_sbi_has_encrypt(sbi) &&
615 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
616 if (ll_sb_has_test_dummy_encryption(sb))
617 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
619 ll_sbi_set_encrypt(sbi, false);
620 } else if (ll_sb_has_test_dummy_encryption(sb)) {
621 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
624 sbi->ll_dt_exp->exp_connect_data = *data;
626 /* Don't change value if it was specified in the config log */
627 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
628 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
629 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
630 (data->ocd_brw_size >> PAGE_SHIFT));
631 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
632 sbi->ll_ra_info.ra_max_pages_per_file)
633 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
634 sbi->ll_ra_info.ra_max_pages_per_file;
637 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
638 LUSTRE_SEQ_METADATA);
640 CERROR("%s: Can't init data layer FID infrastructure, "
641 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
645 mutex_lock(&sbi->ll_lco.lco_lock);
646 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
647 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
648 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
649 mutex_unlock(&sbi->ll_lco.lco_lock);
651 fid_zero(&sbi->ll_root_fid);
652 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
655 CERROR("cannot mds_connect: rc = %d\n", err);
656 GOTO(out_lock_cn_cb, err);
658 if (!fid_is_sane(&sbi->ll_root_fid)) {
659 CERROR("%s: Invalid root fid "DFID" during mount\n",
660 sbi->ll_md_exp->exp_obd->obd_name,
661 PFID(&sbi->ll_root_fid));
662 GOTO(out_lock_cn_cb, err = -EINVAL);
664 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
666 sb->s_op = &lustre_super_operations;
667 sb->s_xattr = ll_xattr_handlers;
668 #if THREAD_SIZE >= 8192 /*b=17630*/
669 sb->s_export_op = &lustre_export_operations;
671 #ifdef HAVE_LUSTRE_CRYPTO
672 llcrypt_set_ops(sb, &lustre_cryptops);
676 * XXX: move this to after cbd setup? */
677 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
679 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
680 valid |= OBD_MD_FLACL;
682 OBD_ALLOC_PTR(op_data);
684 GOTO(out_lock_cn_cb, err = -ENOMEM);
686 op_data->op_fid1 = sbi->ll_root_fid;
687 op_data->op_mode = 0;
688 op_data->op_valid = valid;
690 err = md_getattr(sbi->ll_md_exp, op_data, &request);
692 /* We need enc ctx info, so reset it in op_data to
693 * prevent it from being freed.
695 encctx = op_data->op_file_encctx;
696 encctxlen = op_data->op_file_encctx_size;
697 op_data->op_file_encctx = NULL;
698 op_data->op_file_encctx_size = 0;
699 OBD_FREE_PTR(op_data);
701 CERROR("%s: md_getattr failed for root: rc = %d\n",
702 sbi->ll_md_exp->exp_obd->obd_name, err);
703 GOTO(out_lock_cn_cb, err);
706 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
707 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
709 CERROR("failed to understand root inode md: rc = %d\n", err);
710 ptlrpc_req_finished(request);
711 GOTO(out_lock_cn_cb, err);
714 LASSERT(fid_is_sane(&sbi->ll_root_fid));
715 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
716 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
717 md_free_lustre_md(sbi->ll_md_exp, &lmd);
721 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
723 CERROR("%s: bad ll_iget() for root: rc = %d\n",
724 sbi->ll_fsname, err);
725 ptlrpc_req_finished(request);
731 "server returned encryption ctx for root inode "DFID"\n",
732 PFID(&sbi->ll_root_fid));
733 err = ll_set_encflags(root, encctx, encctxlen, true);
735 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
737 PFID(&sbi->ll_root_fid), err);
739 ptlrpc_req_finished(request);
741 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
742 if (sbi->ll_checksum_set) {
743 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
744 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
745 sizeof(checksum), &checksum, NULL);
747 CERROR("%s: Set checksum failed: rc = %d\n",
748 sbi->ll_dt_exp->exp_obd->obd_name, err);
754 sb->s_root = d_make_root(root);
755 if (sb->s_root == NULL) {
757 CERROR("%s: can't make root dentry: rc = %d\n",
758 sbi->ll_fsname, err);
762 sbi->ll_sdev_orig = sb->s_dev;
764 /* We set sb->s_dev equal on all lustre clients in order to support
765 * NFS export clustering. NFSD requires that the FSID be the same
767 /* s_dev is also used in lt_compare() to compare two fs, but that is
768 * only a node-local comparison. */
769 uuid = obd_get_uuid(sbi->ll_md_exp);
771 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
778 if (sbi->ll_dt_obd) {
779 err = sysfs_create_link(&sbi->ll_kset.kobj,
780 &sbi->ll_dt_obd->obd_kset.kobj,
781 sbi->ll_dt_obd->obd_type->typ_name);
783 CERROR("%s: could not register %s in llite: rc = %d\n",
784 dt, sbi->ll_fsname, err);
789 if (sbi->ll_md_obd) {
790 err = sysfs_create_link(&sbi->ll_kset.kobj,
791 &sbi->ll_md_obd->obd_kset.kobj,
792 sbi->ll_md_obd->obd_type->typ_name);
794 CERROR("%s: could not register %s in llite: rc = %d\n",
795 md, sbi->ll_fsname, err);
804 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
806 obd_disconnect(sbi->ll_dt_exp);
807 sbi->ll_dt_exp = NULL;
808 sbi->ll_dt_obd = NULL;
810 obd_fid_fini(sbi->ll_md_exp->exp_obd);
812 obd_disconnect(sbi->ll_md_exp);
813 sbi->ll_md_exp = NULL;
814 sbi->ll_md_obd = NULL;
823 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
827 size = sizeof(*lmmsize);
828 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
829 KEY_MAX_EASIZE, &size, lmmsize);
831 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
832 sbi->ll_dt_exp->exp_obd->obd_name, rc);
836 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
839 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
840 KEY_MAX_EASIZE, &size, lmmsize);
842 CERROR("Get max mdsize error rc %d\n", rc);
844 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
850 * Get the value of the default_easize parameter.
852 * \see client_obd::cl_default_mds_easize
854 * \param[in] sbi superblock info for this filesystem
855 * \param[out] lmmsize pointer to storage location for value
857 * \retval 0 on success
858 * \retval negative negated errno on failure
860 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
865 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
866 KEY_DEFAULT_EASIZE, &size, lmmsize);
868 CERROR("Get default mdsize error rc %d\n", rc);
874 * Set the default_easize parameter to the given value.
876 * \see client_obd::cl_default_mds_easize
878 * \param[in] sbi superblock info for this filesystem
879 * \param[in] lmmsize the size to set
881 * \retval 0 on success
882 * \retval negative negated errno on failure
884 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
888 if (lmmsize < sizeof(struct lov_mds_md) ||
889 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
892 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
893 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
894 sizeof(int), &lmmsize, NULL);
899 static void client_common_put_super(struct super_block *sb)
901 struct ll_sb_info *sbi = ll_s2sbi(sb);
906 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
907 obd_disconnect(sbi->ll_dt_exp);
908 sbi->ll_dt_exp = NULL;
910 ll_debugfs_unregister_super(sb);
912 obd_fid_fini(sbi->ll_md_exp->exp_obd);
913 obd_disconnect(sbi->ll_md_exp);
914 sbi->ll_md_exp = NULL;
919 void ll_kill_super(struct super_block *sb)
921 struct ll_sb_info *sbi;
925 if (!(sb->s_flags & SB_ACTIVE))
929 /* we need restore s_dev from changed for clustred NFS before put_super
930 * because new kernels have cached s_dev and change sb->s_dev in
931 * put_super not affected real removing devices */
933 sb->s_dev = sbi->ll_sdev_orig;
935 /* wait running statahead threads to quit */
936 while (atomic_read(&sbi->ll_sa_running) > 0)
937 schedule_timeout_uninterruptible(
938 cfs_time_seconds(1) >> 3);
944 /* Since we use this table for ll_sbi_flags_seq_show make
945 * sure what you want displayed for a specific token that
946 * is listed more than once below be listed first. For
947 * example we want "checksum" displayed, not "nochecksum"
950 static const match_table_t ll_sbi_flags_name = {
951 {LL_SBI_NOLCK, "nolock"},
952 {LL_SBI_CHECKSUM, "checksum"},
953 {LL_SBI_CHECKSUM, "nochecksum"},
954 {LL_SBI_LOCALFLOCK, "localflock"},
955 {LL_SBI_FLOCK, "flock"},
956 {LL_SBI_FLOCK, "noflock"},
957 {LL_SBI_USER_XATTR, "user_xattr"},
958 {LL_SBI_USER_XATTR, "nouser_xattr"},
959 {LL_SBI_LRU_RESIZE, "lruresize"},
960 {LL_SBI_LRU_RESIZE, "nolruresize"},
961 {LL_SBI_LAZYSTATFS, "lazystatfs"},
962 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
963 {LL_SBI_32BIT_API, "32bitapi"},
964 {LL_SBI_USER_FID2PATH, "user_fid2path"},
965 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
966 {LL_SBI_VERBOSE, "verbose"},
967 {LL_SBI_VERBOSE, "noverbose"},
968 {LL_SBI_ALWAYS_PING, "always_ping"},
969 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
970 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
971 {LL_SBI_ENCRYPT, "encrypt"},
972 {LL_SBI_ENCRYPT, "noencrypt"},
973 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
974 {LL_SBI_NUM_MOUNT_OPT, NULL},
977 {LL_SBI_AGL_ENABLED, "agl"},
978 {LL_SBI_64BIT_HASH, "64bit_hash"},
979 {LL_SBI_LAYOUT_LOCK, "layout"},
980 {LL_SBI_XATTR_CACHE, "xattr_cache"},
981 {LL_SBI_NOROOTSQUASH, "norootsquash"},
982 {LL_SBI_FAST_READ, "fast_read"},
983 {LL_SBI_FILE_SECCTX, "file_secctx"},
984 {LL_SBI_TINY_WRITE, "tiny_write"},
985 {LL_SBI_FILE_HEAT, "file_heat"},
986 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
987 {LL_SBI_ENCRYPT_NAME, "name_encrypt"},
990 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
992 struct super_block *sb = m->private;
995 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
998 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
1001 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
1002 if (ll_sbi_flags_name[j].token == i &&
1003 ll_sbi_flags_name[j].pattern) {
1004 seq_printf(m, "%s ",
1005 ll_sbi_flags_name[j].pattern);
1010 seq_puts(m, "\b\n");
1014 /* non-client-specific mount options are parsed in lmd_parse */
1015 static int ll_options(char *options, struct super_block *sb)
1017 struct ll_sb_info *sbi = ll_s2sbi(sb);
1018 char *s2, *s1, *opts;
1025 /* Don't stomp on lmd_opts */
1026 opts = kstrdup(options, GFP_KERNEL);
1032 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1034 while ((s1 = strsep(&opts, ",")) != NULL) {
1035 substring_t args[MAX_OPT_ARGS];
1036 bool turn_off = false;
1042 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1044 if (strncmp(s1, "no", 2) == 0)
1048 * Initialize args struct so we know whether arg was
1049 * found; some options take optional arguments.
1052 args[0].from = NULL;
1053 token = match_token(s1, ll_sbi_flags_name, args);
1054 if (token == LL_SBI_NUM_MOUNT_OPT) {
1055 if (match_wildcard("context", s1) ||
1056 match_wildcard("fscontext", s1) ||
1057 match_wildcard("defcontext", s1) ||
1058 match_wildcard("rootcontext",s1))
1061 LCONSOLE_ERROR_MSG(0x152,
1062 "Unknown option '%s', won't mount.\n",
1069 case LL_SBI_32BIT_API:
1070 case LL_SBI_64BIT_HASH:
1071 case LL_SBI_ALWAYS_PING:
1072 set_bit(token, sbi->ll_flags);
1076 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1078 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1080 set_bit(token, sbi->ll_flags);
1083 case LL_SBI_LOCALFLOCK:
1084 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1085 set_bit(token, sbi->ll_flags);
1088 case LL_SBI_CHECKSUM:
1089 sbi->ll_checksum_set = 1;
1091 case LL_SBI_USER_XATTR:
1092 case LL_SBI_USER_FID2PATH:
1093 case LL_SBI_LRU_RESIZE:
1094 case LL_SBI_LAZYSTATFS:
1095 case LL_SBI_VERBOSE:
1097 clear_bit(token, sbi->ll_flags);
1099 set_bit(token, sbi->ll_flags);
1101 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1102 #ifdef HAVE_LUSTRE_CRYPTO
1103 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1104 set_bit(token, sbi->ll_flags);
1106 struct lustre_sb_info *lsi = s2lsi(sb);
1108 err = llcrypt_set_test_dummy_encryption(sb, &args[0],
1109 &lsi->lsi_dummy_enc_ctx);
1115 "Can't change test_dummy_encryption");
1116 else if (err == -EINVAL)
1118 "Value of option \"%s\" unrecognized",
1122 "Error processing option \"%s\" [%d]",
1127 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1131 case LL_SBI_ENCRYPT:
1132 #ifdef HAVE_LUSTRE_CRYPTO
1134 clear_bit(token, sbi->ll_flags);
1136 set_bit(token, sbi->ll_flags);
1138 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1141 case LL_SBI_FOREIGN_SYMLINK:
1142 /* non-default prefix provided ? */
1147 /* path must be absolute */
1148 if (args->from[0] != '/') {
1149 LCONSOLE_ERROR_MSG(0x152,
1150 "foreign prefix '%s' must be an absolute path\n",
1155 old_len = sbi->ll_foreign_symlink_prefix_size;
1156 old = sbi->ll_foreign_symlink_prefix;
1157 /* alloc for path length and '\0' */
1158 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1159 if (!sbi->ll_foreign_symlink_prefix) {
1160 /* restore previous */
1161 sbi->ll_foreign_symlink_prefix = old;
1162 sbi->ll_foreign_symlink_prefix_size =
1166 sbi->ll_foreign_symlink_prefix_size =
1167 args->to - args->from + 1;
1168 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1169 sbi->ll_foreign_symlink_prefix_size,
1172 OBD_FREE(old, old_len);
1174 /* enable foreign symlink support */
1175 set_bit(token, sbi->ll_flags);
1177 LCONSOLE_ERROR_MSG(0x152,
1178 "invalid %s option\n", s1);
1189 void ll_lli_init(struct ll_inode_info *lli)
1191 lli->lli_inode_magic = LLI_INODE_MAGIC;
1193 rwlock_init(&lli->lli_lock);
1194 lli->lli_posix_acl = NULL;
1195 /* Do not set lli_fid, it has been initialized already. */
1196 fid_zero(&lli->lli_pfid);
1197 lli->lli_mds_read_och = NULL;
1198 lli->lli_mds_write_och = NULL;
1199 lli->lli_mds_exec_och = NULL;
1200 lli->lli_open_fd_read_count = 0;
1201 lli->lli_open_fd_write_count = 0;
1202 lli->lli_open_fd_exec_count = 0;
1203 mutex_init(&lli->lli_och_mutex);
1204 spin_lock_init(&lli->lli_agl_lock);
1205 spin_lock_init(&lli->lli_layout_lock);
1206 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1207 lli->lli_clob = NULL;
1209 init_rwsem(&lli->lli_xattrs_list_rwsem);
1210 mutex_init(&lli->lli_xattrs_enq_lock);
1212 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1213 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1214 lli->lli_opendir_key = NULL;
1215 lli->lli_sai = NULL;
1216 spin_lock_init(&lli->lli_sa_lock);
1217 lli->lli_opendir_pid = 0;
1218 lli->lli_sa_enabled = 0;
1219 init_rwsem(&lli->lli_lsm_sem);
1221 mutex_init(&lli->lli_size_mutex);
1222 mutex_init(&lli->lli_setattr_mutex);
1223 lli->lli_symlink_name = NULL;
1224 ll_trunc_sem_init(&lli->lli_trunc_sem);
1225 range_lock_tree_init(&lli->lli_write_tree);
1226 init_rwsem(&lli->lli_glimpse_sem);
1227 lli->lli_glimpse_time = ktime_set(0, 0);
1228 INIT_LIST_HEAD(&lli->lli_agl_list);
1229 lli->lli_agl_index = 0;
1230 lli->lli_async_rc = 0;
1231 spin_lock_init(&lli->lli_heat_lock);
1232 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1233 lli->lli_heat_flags = 0;
1234 mutex_init(&lli->lli_pcc_lock);
1235 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1236 lli->lli_pcc_inode = NULL;
1237 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1238 lli->lli_pcc_generation = 0;
1240 mutex_init(&lli->lli_layout_mutex);
1241 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1242 /* ll_cl_context initialize */
1243 INIT_LIST_HEAD(&lli->lli_lccs);
1246 #define MAX_STRING_SIZE 128
1248 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1249 #ifndef HAVE_BDI_CAP_MAP_COPY
1250 # define BDI_CAP_MAP_COPY 0
1253 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1255 struct lustre_sb_info *lsi = s2lsi(sb);
1256 char buf[MAX_STRING_SIZE];
1260 err = bdi_init(&lsi->lsi_bdi);
1264 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1265 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1266 lsi->lsi_bdi.name = "lustre";
1267 va_start(args, fmt);
1268 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1270 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1273 sb->s_bdi = &lsi->lsi_bdi;
1277 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1279 int ll_fill_super(struct super_block *sb)
1281 struct lustre_profile *lprof = NULL;
1282 struct lustre_sb_info *lsi = s2lsi(sb);
1283 struct ll_sb_info *sbi = NULL;
1284 char *dt = NULL, *md = NULL;
1285 char *profilenm = get_profile_name(sb);
1286 struct config_llog_instance *cfg;
1287 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1288 const int instlen = LUSTRE_MAXINSTANCE + 2;
1289 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1290 char name[MAX_STRING_SIZE];
1299 /* for ASLR, to map between cfg_instance and hashed ptr */
1300 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1301 profilenm, cfg_instance, sb);
1303 OBD_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1307 GOTO(out_free_cfg, err = -ENOMEM);
1309 /* client additional sb info */
1310 lsi->lsi_llsbi = sbi = ll_init_sbi();
1312 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1314 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1316 GOTO(out_free_cfg, err);
1318 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1319 #ifdef CONFIG_LL_ENCRYPTION
1320 if (ll_sb_has_test_dummy_encryption(sb))
1321 /* enable filename encryption by default for dummy enc mode */
1322 lsi->lsi_flags |= LSI_FILENAME_ENC;
1324 /* filename encryption is disabled by default */
1325 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1328 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1329 sb->s_d_op = &ll_d_ops;
1332 generate_random_uuid(uuid.b);
1333 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1335 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1338 len = strlen(profilenm);
1339 ptr = strrchr(profilenm, '-');
1340 if (ptr && (strcmp(ptr, "-client") == 0))
1343 if (len > LUSTRE_MAXFSNAME) {
1344 if (unlikely(len >= MAX_STRING_SIZE))
1345 len = MAX_STRING_SIZE - 1;
1346 strncpy(name, profilenm, len);
1348 err = -ENAMETOOLONG;
1349 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1350 name, LUSTRE_MAXFSNAME, err);
1351 GOTO(out_free_cfg, err);
1353 strncpy(sbi->ll_fsname, profilenm, len);
1354 sbi->ll_fsname[len] = '\0';
1357 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1358 profilenm, cfg_instance);
1360 err = super_setup_bdi_name(sb, "%s", name);
1362 GOTO(out_free_cfg, err);
1364 /* disable kernel readahead */
1365 sb->s_bdi->ra_pages = 0;
1366 #ifdef HAVE_BDI_IO_PAGES
1367 sb->s_bdi->io_pages = 0;
1370 /* Call ll_debugfs_register_super() before lustre_process_log()
1371 * so that "llite.*.*" params can be processed correctly.
1373 err = ll_debugfs_register_super(sb, name);
1375 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1376 sbi->ll_fsname, err);
1380 /* The cfg_instance is a value unique to this super, in case some
1381 * joker tries to mount the same fs at two mount points.
1383 cfg->cfg_instance = cfg_instance;
1384 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1385 cfg->cfg_callback = class_config_llog_handler;
1386 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1387 /* set up client obds */
1388 err = lustre_process_log(sb, profilenm, cfg);
1390 GOTO(out_debugfs, err);
1392 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1393 lprof = class_get_profile(profilenm);
1394 if (lprof == NULL) {
1395 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1396 " read from the MGS. Does that filesystem "
1397 "exist?\n", profilenm);
1398 GOTO(out_debugfs, err = -EINVAL);
1400 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1401 lprof->lp_md, lprof->lp_dt);
1403 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1404 OBD_ALLOC(dt, dt_len);
1406 GOTO(out_profile, err = -ENOMEM);
1407 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1409 md_len = strlen(lprof->lp_md) + instlen + 2;
1410 OBD_ALLOC(md, md_len);
1412 GOTO(out_free_dt, err = -ENOMEM);
1413 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1415 /* connections, registrations, sb setup */
1416 err = client_common_fill_super(sb, md, dt);
1418 GOTO(out_free_md, err);
1420 sbi->ll_client_common_fill_super_succeeded = 1;
1424 OBD_FREE(md, md_len);
1427 OBD_FREE(dt, dt_len);
1430 class_put_profile(lprof);
1433 ll_debugfs_unregister_super(sb);
1440 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1441 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1442 sb->s_flags & SB_RDONLY ? " read-only" : "");
1444 } /* ll_fill_super */
1446 void ll_put_super(struct super_block *sb)
1448 struct config_llog_instance cfg, params_cfg;
1449 struct obd_device *obd;
1450 struct lustre_sb_info *lsi = s2lsi(sb);
1451 struct ll_sb_info *sbi = ll_s2sbi(sb);
1452 char *profilenm = get_profile_name(sb);
1453 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1455 int next, force = 1, rc = 0;
1459 GOTO(out_no_sbi, 0);
1461 /* Should replace instance_id with something better for ASLR */
1462 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1463 profilenm, cfg_instance, sb);
1465 cfg.cfg_instance = cfg_instance;
1466 lustre_end_log(sb, profilenm, &cfg);
1468 params_cfg.cfg_instance = cfg_instance;
1469 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1471 if (sbi->ll_md_exp) {
1472 obd = class_exp2obd(sbi->ll_md_exp);
1474 force = obd->obd_force;
1477 /* Wait for unstable pages to be committed to stable storage */
1479 rc = l_wait_event_abortable(
1480 sbi->ll_cache->ccc_unstable_waitq,
1481 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1484 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1485 if (force == 0 && rc != -ERESTARTSYS)
1486 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1488 /* We need to set force before the lov_disconnect in
1489 * lustre_common_put_super, since l_d cleans up osc's as well.
1493 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1495 obd->obd_force = force;
1499 if (sbi->ll_client_common_fill_super_succeeded) {
1500 /* Only if client_common_fill_super succeeded */
1501 client_common_put_super(sb);
1504 /* imitate failed cleanup */
1505 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1509 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1510 class_manual_cleanup(obd);
1513 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1514 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1517 class_del_profile(profilenm);
1519 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1520 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1521 bdi_destroy(&lsi->lsi_bdi);
1522 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1526 llcrypt_free_dummy_context(&lsi->lsi_dummy_enc_ctx);
1528 lsi->lsi_llsbi = NULL;
1530 lustre_common_put_super(sb);
1532 cl_env_cache_purge(~0);
1535 } /* client_put_super */
1537 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1539 struct inode *inode = NULL;
1541 /* NOTE: we depend on atomic igrab() -bzzz */
1542 lock_res_and_lock(lock);
1543 if (lock->l_resource->lr_lvb_inode) {
1544 struct ll_inode_info * lli;
1545 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1546 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1547 inode = igrab(lock->l_resource->lr_lvb_inode);
1549 inode = lock->l_resource->lr_lvb_inode;
1550 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1551 D_WARNING, lock, "lr_lvb_inode %p is "
1552 "bogus: magic %08x",
1553 lock->l_resource->lr_lvb_inode,
1554 lli->lli_inode_magic);
1558 unlock_res_and_lock(lock);
1562 void ll_dir_clear_lsm_md(struct inode *inode)
1564 struct ll_inode_info *lli = ll_i2info(inode);
1566 LASSERT(S_ISDIR(inode->i_mode));
1568 if (lli->lli_lsm_md) {
1569 lmv_free_memmd(lli->lli_lsm_md);
1570 lli->lli_lsm_md = NULL;
1573 if (lli->lli_default_lsm_md) {
1574 lmv_free_memmd(lli->lli_default_lsm_md);
1575 lli->lli_default_lsm_md = NULL;
1579 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1580 const struct lu_fid *fid,
1581 struct lustre_md *md)
1583 struct ll_sb_info *sbi = ll_s2sbi(sb);
1584 struct ll_inode_info *lli;
1585 struct mdt_body *body = md->body;
1586 struct inode *inode;
1592 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1593 inode = iget_locked(sb, ino);
1594 if (inode == NULL) {
1595 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1596 sbi->ll_fsname, PFID(fid));
1597 RETURN(ERR_PTR(-ENOENT));
1600 lli = ll_i2info(inode);
1601 if (inode->i_state & I_NEW) {
1602 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1603 (body->mbo_mode & S_IFMT);
1604 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1607 inode->i_mtime.tv_sec = 0;
1608 inode->i_atime.tv_sec = 0;
1609 inode->i_ctime.tv_sec = 0;
1612 #ifdef HAVE_BACKING_DEV_INFO
1613 /* initializing backing dev info. */
1614 inode->i_mapping->backing_dev_info =
1615 &s2lsi(inode->i_sb)->lsi_bdi;
1617 inode->i_op = &ll_dir_inode_operations;
1618 inode->i_fop = &ll_dir_operations;
1619 lli->lli_fid = *fid;
1622 /* master object FID */
1623 lli->lli_pfid = body->mbo_fid1;
1624 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1625 lli, PFID(fid), PFID(&lli->lli_pfid));
1626 unlock_new_inode(inode);
1628 /* in directory restripe/auto-split, a directory will be
1629 * transformed to a stripe if it's plain, set its pfid here,
1630 * otherwise ll_lock_cancel_bits() can't find the master inode.
1632 lli->lli_pfid = body->mbo_fid1;
1638 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1641 struct lmv_stripe_md *lsm = md->lmv;
1642 struct ll_inode_info *lli = ll_i2info(inode);
1645 LASSERT(lsm != NULL);
1647 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1648 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1649 lsm_md_dump(D_INODE, lsm);
1651 if (!lmv_dir_striped(lsm))
1654 /* XXX sigh, this lsm_root initialization should be in
1655 * LMV layer, but it needs ll_iget right now, so we
1656 * put this here right now. */
1657 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1658 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1659 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1661 if (!fid_is_sane(fid))
1664 /* Unfortunately ll_iget will call ll_update_inode,
1665 * where the initialization of slave inode is slightly
1666 * different, so it reset lsm_md to NULL to avoid
1667 * initializing lsm for slave inode. */
1668 lsm->lsm_md_oinfo[i].lmo_root =
1669 ll_iget_anon_dir(inode->i_sb, fid, md);
1670 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1671 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1673 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1675 iput(lsm->lsm_md_oinfo[i].lmo_root);
1676 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1682 lli->lli_lsm_md = lsm;
1687 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1689 struct ll_inode_info *lli = ll_i2info(inode);
1693 if (!md->default_lmv) {
1694 /* clear default lsm */
1695 if (lli->lli_default_lsm_md) {
1696 down_write(&lli->lli_lsm_sem);
1697 if (lli->lli_default_lsm_md) {
1698 lmv_free_memmd(lli->lli_default_lsm_md);
1699 lli->lli_default_lsm_md = NULL;
1701 lli->lli_inherit_depth = 0;
1702 up_write(&lli->lli_lsm_sem);
1707 if (lli->lli_default_lsm_md) {
1708 /* do nonthing if default lsm isn't changed */
1709 down_read(&lli->lli_lsm_sem);
1710 if (lli->lli_default_lsm_md &&
1711 lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1712 up_read(&lli->lli_lsm_sem);
1715 up_read(&lli->lli_lsm_sem);
1718 down_write(&lli->lli_lsm_sem);
1719 if (lli->lli_default_lsm_md)
1720 lmv_free_memmd(lli->lli_default_lsm_md);
1721 lli->lli_default_lsm_md = md->default_lmv;
1722 lsm_md_dump(D_INODE, md->default_lmv);
1723 md->default_lmv = NULL;
1724 up_write(&lli->lli_lsm_sem);
1728 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1730 struct ll_inode_info *lli = ll_i2info(inode);
1731 struct lmv_stripe_md *lsm = md->lmv;
1732 struct cl_attr *attr;
1737 LASSERT(S_ISDIR(inode->i_mode));
1738 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1739 PFID(ll_inode2fid(inode)));
1741 /* update default LMV */
1742 if (md->default_lmv)
1743 ll_update_default_lsm_md(inode, md);
1745 /* after dir migration/restripe, a stripe may be turned into a
1746 * directory, in this case, zero out its lli_pfid.
1748 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1749 fid_zero(&lli->lli_pfid);
1752 * no striped information from request, lustre_md from req does not
1753 * include stripeEA, see ll_md_setattr()
1759 * normally dir layout doesn't change, only take read lock to check
1760 * that to avoid blocking other MD operations.
1762 down_read(&lli->lli_lsm_sem);
1764 /* some current lookup initialized lsm, and unchanged */
1765 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1766 GOTO(unlock, rc = 0);
1768 /* if dir layout doesn't match, check whether version is increased,
1769 * which means layout is changed, this happens in dir split/merge and
1772 * foreign LMV should not change.
1774 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1775 lsm->lsm_md_layout_version <=
1776 lli->lli_lsm_md->lsm_md_layout_version) {
1777 CERROR("%s: "DFID" dir layout mismatch:\n",
1778 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1779 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1780 lsm_md_dump(D_ERROR, lsm);
1781 GOTO(unlock, rc = -EINVAL);
1784 up_read(&lli->lli_lsm_sem);
1785 down_write(&lli->lli_lsm_sem);
1786 /* clear existing lsm */
1787 if (lli->lli_lsm_md) {
1788 lmv_free_memmd(lli->lli_lsm_md);
1789 lli->lli_lsm_md = NULL;
1792 rc = ll_init_lsm_md(inode, md);
1794 up_write(&lli->lli_lsm_sem);
1798 /* md_merge_attr() may take long, since lsm is already set, switch to
1801 downgrade_write(&lli->lli_lsm_sem);
1803 /* set md->lmv to NULL, so the following free lustre_md will not free
1808 if (!lmv_dir_striped(lli->lli_lsm_md))
1809 GOTO(unlock, rc = 0);
1811 OBD_ALLOC_PTR(attr);
1813 GOTO(unlock, rc = -ENOMEM);
1815 /* validate the lsm */
1816 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1817 ll_md_blocking_ast);
1819 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1820 md->body->mbo_nlink = attr->cat_nlink;
1821 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1822 md->body->mbo_size = attr->cat_size;
1823 if (md->body->mbo_valid & OBD_MD_FLATIME)
1824 md->body->mbo_atime = attr->cat_atime;
1825 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1826 md->body->mbo_ctime = attr->cat_ctime;
1827 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1828 md->body->mbo_mtime = attr->cat_mtime;
1834 up_read(&lli->lli_lsm_sem);
1839 void ll_clear_inode(struct inode *inode)
1841 struct ll_inode_info *lli = ll_i2info(inode);
1842 struct ll_sb_info *sbi = ll_i2sbi(inode);
1846 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1847 PFID(ll_inode2fid(inode)), inode);
1849 if (S_ISDIR(inode->i_mode)) {
1850 /* these should have been cleared in ll_file_release */
1851 LASSERT(lli->lli_opendir_key == NULL);
1852 LASSERT(lli->lli_sai == NULL);
1853 LASSERT(lli->lli_opendir_pid == 0);
1855 pcc_inode_free(inode);
1858 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1860 LASSERT(!lli->lli_open_fd_write_count);
1861 LASSERT(!lli->lli_open_fd_read_count);
1862 LASSERT(!lli->lli_open_fd_exec_count);
1864 if (lli->lli_mds_write_och)
1865 ll_md_real_close(inode, FMODE_WRITE);
1866 if (lli->lli_mds_exec_och)
1867 ll_md_real_close(inode, FMODE_EXEC);
1868 if (lli->lli_mds_read_och)
1869 ll_md_real_close(inode, FMODE_READ);
1871 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1872 OBD_FREE(lli->lli_symlink_name,
1873 strlen(lli->lli_symlink_name) + 1);
1874 lli->lli_symlink_name = NULL;
1877 ll_xattr_cache_destroy(inode);
1879 forget_all_cached_acls(inode);
1881 lli->lli_inode_magic = LLI_INODE_DEAD;
1883 if (S_ISDIR(inode->i_mode))
1884 ll_dir_clear_lsm_md(inode);
1885 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1886 LASSERT(list_empty(&lli->lli_agl_list));
1889 * XXX This has to be done before lsm is freed below, because
1890 * cl_object still uses inode lsm.
1892 cl_inode_fini(inode);
1894 llcrypt_put_encryption_info(inode);
1899 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1901 struct lustre_md md;
1902 struct inode *inode = dentry->d_inode;
1903 struct ll_sb_info *sbi = ll_i2sbi(inode);
1904 struct ptlrpc_request *request = NULL;
1909 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1910 LUSTRE_OPC_ANY, NULL);
1911 if (IS_ERR(op_data))
1912 RETURN(PTR_ERR(op_data));
1914 /* If this is a chgrp of a regular file, we want to reserve enough
1915 * quota to cover the entire file size.
1917 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1918 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1919 from_kgid(&init_user_ns, inode->i_gid)) {
1920 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1921 op_data->op_attr_blocks = inode->i_blocks;
1925 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1927 ptlrpc_req_finished(request);
1928 if (rc == -ENOENT) {
1930 /* Unlinked special device node? Or just a race?
1931 * Pretend we done everything. */
1932 if (!S_ISREG(inode->i_mode) &&
1933 !S_ISDIR(inode->i_mode)) {
1934 ia_valid = op_data->op_attr.ia_valid;
1935 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1936 rc = simple_setattr(&init_user_ns, dentry,
1938 op_data->op_attr.ia_valid = ia_valid;
1940 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1941 CERROR("md_setattr fails: rc = %d\n", rc);
1946 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1947 sbi->ll_md_exp, &md);
1949 ptlrpc_req_finished(request);
1953 ia_valid = op_data->op_attr.ia_valid;
1954 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1955 * cache is not cleared yet. */
1956 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1957 if (S_ISREG(inode->i_mode))
1959 rc = simple_setattr(&init_user_ns, dentry, &op_data->op_attr);
1960 if (S_ISREG(inode->i_mode))
1961 inode_unlock(inode);
1962 op_data->op_attr.ia_valid = ia_valid;
1964 rc = ll_update_inode(inode, &md);
1965 ptlrpc_req_finished(request);
1971 * Zero portion of page that is part of @inode.
1972 * This implies, if necessary:
1973 * - taking cl_lock on range corresponding to concerned page
1974 * - grabbing vm page
1975 * - associating cl_page
1976 * - proceeding to clio read
1977 * - zeroing range in page
1978 * - proceeding to cl_page flush
1979 * - releasing cl_lock
1981 * \param[in] inode inode
1982 * \param[in] index page index
1983 * \param[in] offset offset in page to start zero from
1984 * \param[in] len len to zero
1986 * \retval 0 on success
1987 * \retval negative errno on failure
1989 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
1992 struct ll_inode_info *lli = ll_i2info(inode);
1993 struct cl_object *clob = lli->lli_clob;
1995 struct lu_env *env = NULL;
1996 struct cl_io *io = NULL;
1997 struct cl_page *clpage = NULL;
1998 struct page *vmpage = NULL;
1999 unsigned from = index << PAGE_SHIFT;
2000 struct cl_lock *lock = NULL;
2001 struct cl_lock_descr *descr = NULL;
2002 struct cl_2queue *queue = NULL;
2003 struct cl_sync_io *anchor = NULL;
2004 bool holdinglock = false;
2009 env = cl_env_get(&refcheck);
2011 RETURN(PTR_ERR(env));
2013 io = vvp_env_thread_io(env);
2015 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2019 lock = vvp_env_lock(env);
2020 descr = &lock->cll_descr;
2021 descr->cld_obj = io->ci_obj;
2022 descr->cld_start = cl_index(io->ci_obj, from);
2023 descr->cld_end = cl_index(io->ci_obj, from + PAGE_SIZE - 1);
2024 descr->cld_mode = CLM_WRITE;
2025 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2027 /* request lock for page */
2028 rc = cl_lock_request(env, io, lock);
2029 /* -ECANCELED indicates a matching lock with a different extent
2030 * was already present, and -EEXIST indicates a matching lock
2031 * on exactly the same extent was already present.
2032 * In both cases it means we are covered.
2034 if (rc == -ECANCELED || rc == -EEXIST)
2042 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2044 GOTO(rellock, rc = -EOPNOTSUPP);
2046 if (!PageDirty(vmpage)) {
2047 /* associate cl_page */
2048 clpage = cl_page_find(env, clob, vmpage->index,
2049 vmpage, CPT_CACHEABLE);
2051 GOTO(pagefini, rc = PTR_ERR(clpage));
2053 cl_page_assume(env, io, clpage);
2056 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2057 !PageWriteback(vmpage)) {
2059 /* Set PagePrivate2 to detect special case of empty page
2060 * in osc_brw_fini_request().
2061 * It is also used to tell ll_io_read_page() that we do not
2062 * want the vmpage to be unlocked.
2064 SetPagePrivate2(vmpage);
2065 rc = ll_io_read_page(env, io, clpage, NULL);
2066 if (!PagePrivate2(vmpage)) {
2067 /* PagePrivate2 was cleared in osc_brw_fini_request()
2068 * meaning we read an empty page. In this case, in order
2069 * to avoid allocating unnecessary block in truncated
2070 * file, we must not zero and write as below. Subsequent
2071 * server-side truncate will handle things correctly.
2073 cl_page_unassume(env, io, clpage);
2074 GOTO(clpfini, rc = 0);
2076 ClearPagePrivate2(vmpage);
2081 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2082 * the vmpage, so we are good to proceed and zero range in page.
2084 zero_user(vmpage, offset, len);
2086 if (holdinglock && clpage) {
2087 /* explicitly write newly modified page */
2088 queue = &io->ci_queue;
2089 cl_2queue_init(queue);
2090 anchor = &vvp_env_info(env)->vti_anchor;
2091 cl_sync_io_init(anchor, 1);
2092 clpage->cp_sync_io = anchor;
2093 cl_page_list_add(&queue->c2_qin, clpage, true);
2094 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2096 GOTO(queuefini1, rc);
2097 rc = cl_sync_io_wait(env, anchor, 0);
2099 GOTO(queuefini2, rc);
2100 cl_page_assume(env, io, clpage);
2103 cl_2queue_discard(env, io, queue);
2105 cl_2queue_disown(env, queue);
2106 cl_2queue_fini(env, queue);
2111 cl_page_put(env, clpage);
2113 unlock_page(vmpage);
2117 cl_lock_release(env, lock);
2119 cl_io_fini(env, io);
2122 cl_env_put(env, &refcheck);
2128 * Get reference file from volatile file name.
2129 * Volatile file name may look like:
2130 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2131 * where fd is opened descriptor of reference file.
2133 * \param[in] volatile_name volatile file name
2134 * \param[in] volatile_len volatile file name length
2135 * \param[out] ref_file pointer to struct file of reference file
2137 * \retval 0 on success
2138 * \retval negative errno on failure
2140 int volatile_ref_file(const char *volatile_name, int volatile_len,
2141 struct file **ref_file)
2143 char *p, *q, *fd_str;
2146 p = strnstr(volatile_name, ":fd=", volatile_len);
2147 if (!p || strlen(p + 4) == 0)
2150 q = strchrnul(p + 4, ':');
2151 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2154 rc = kstrtouint(fd_str, 10, &fd);
2159 *ref_file = fget(fd);
2165 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2166 * object(s) determine the file size and mtime. Otherwise, the MDS will
2167 * keep these values until such a time that objects are allocated for it.
2168 * We do the MDS operations first, as it is checking permissions for us.
2169 * We don't to the MDS RPC if there is nothing that we want to store there,
2170 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2171 * going to do an RPC anyways.
2173 * If we are doing a truncate, we will send the mtime and ctime updates
2174 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2175 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2178 * In case of HSMimport, we only set attr on MDS.
2180 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2181 enum op_xvalid xvalid, bool hsm_import)
2183 struct inode *inode = dentry->d_inode;
2184 struct ll_inode_info *lli = ll_i2info(inode);
2185 struct md_op_data *op_data = NULL;
2186 ktime_t kstart = ktime_get();
2191 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2192 "valid %x, hsm_import %d\n",
2193 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2194 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2197 if (attr->ia_valid & ATTR_SIZE) {
2198 /* Check new size against VFS/VM file size limit and rlimit */
2199 rc = inode_newsize_ok(inode, attr->ia_size);
2203 /* The maximum Lustre file size is variable, based on the
2204 * OST maximum object size and number of stripes. This
2205 * needs another check in addition to the VFS check above. */
2206 if (attr->ia_size > ll_file_maxbytes(inode)) {
2207 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2208 PFID(&lli->lli_fid), attr->ia_size,
2209 ll_file_maxbytes(inode));
2213 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2216 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2217 if (attr->ia_valid & TIMES_SET_FLAGS) {
2218 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2219 !capable(CAP_FOWNER))
2223 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2224 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2225 (attr->ia_valid & ATTR_CTIME)) {
2226 attr->ia_ctime = current_time(inode);
2227 xvalid |= OP_XVALID_CTIME_SET;
2229 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2230 (attr->ia_valid & ATTR_ATIME)) {
2231 attr->ia_atime = current_time(inode);
2232 attr->ia_valid |= ATTR_ATIME_SET;
2234 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2235 (attr->ia_valid & ATTR_MTIME)) {
2236 attr->ia_mtime = current_time(inode);
2237 attr->ia_valid |= ATTR_MTIME_SET;
2240 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2241 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2242 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2243 ktime_get_real_seconds());
2245 if (S_ISREG(inode->i_mode))
2246 inode_unlock(inode);
2248 /* We always do an MDS RPC, even if we're only changing the size;
2249 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2251 OBD_ALLOC_PTR(op_data);
2252 if (op_data == NULL)
2253 GOTO(out, rc = -ENOMEM);
2255 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2256 /* If we are changing file size, file content is
2257 * modified, flag it.
2259 xvalid |= OP_XVALID_OWNEROVERRIDE;
2260 op_data->op_bias |= MDS_DATA_MODIFIED;
2261 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2264 if (attr->ia_valid & ATTR_FILE) {
2265 struct ll_file_data *fd = attr->ia_file->private_data;
2267 if (fd->fd_lease_och)
2268 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2271 op_data->op_attr = *attr;
2272 op_data->op_xvalid = xvalid;
2274 rc = ll_md_setattr(dentry, op_data);
2278 if (!S_ISREG(inode->i_mode) || hsm_import)
2281 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2282 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2283 xvalid & OP_XVALID_CTIME_SET) {
2284 bool cached = false;
2286 rc = pcc_inode_setattr(inode, attr, &cached);
2289 CERROR("%s: PCC inode "DFID" setattr failed: "
2291 ll_i2sbi(inode)->ll_fsname,
2292 PFID(&lli->lli_fid), rc);
2296 unsigned int flags = 0;
2298 /* For truncate and utimes sending attributes to OSTs,
2299 * setting mtime/atime to the past will be performed
2300 * under PW [0:EOF] extent lock (new_size:EOF for
2301 * truncate). It may seem excessive to send mtime/atime
2302 * updates to OSTs when not setting times to past, but
2303 * it is necessary due to possible time
2304 * de-synchronization between MDT inode and OST objects
2306 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2307 xvalid |= OP_XVALID_FLAGS;
2308 flags = LUSTRE_ENCRYPT_FL;
2309 /* Call to ll_io_zero_page is not necessary if
2310 * truncating on PAGE_SIZE boundary, because
2311 * whole pages will be wiped.
2312 * In case of Direct IO, all we need is to set
2315 if (attr->ia_valid & ATTR_SIZE &&
2316 attr->ia_size & ~PAGE_MASK &&
2317 !(attr->ia_valid & ATTR_FILE &&
2318 attr->ia_file->f_flags & O_DIRECT)) {
2320 attr->ia_size & (PAGE_SIZE - 1);
2322 rc = ll_io_zero_page(inode,
2323 attr->ia_size >> PAGE_SHIFT,
2324 offset, PAGE_SIZE - offset);
2328 /* If encrypted volatile file without the key,
2329 * we need to fetch size from reference file,
2330 * and set it on OST objects. This happens when
2331 * migrating or extending an encrypted file
2334 if (filename_is_volatile(dentry->d_name.name,
2337 llcrypt_require_key(inode) == -ENOKEY) {
2338 struct file *ref_file;
2339 struct inode *ref_inode;
2340 struct ll_inode_info *ref_lli;
2341 struct cl_object *ref_obj;
2342 struct cl_attr ref_attr = { 0 };
2346 rc = volatile_ref_file(
2347 dentry->d_name.name,
2353 ref_inode = file_inode(ref_file);
2356 GOTO(out, rc = -EINVAL);
2359 env = cl_env_get(&refcheck);
2361 GOTO(out, rc = PTR_ERR(env));
2363 ref_lli = ll_i2info(ref_inode);
2364 ref_obj = ref_lli->lli_clob;
2365 cl_object_attr_lock(ref_obj);
2366 rc = cl_object_attr_get(env, ref_obj,
2368 cl_object_attr_unlock(ref_obj);
2369 cl_env_put(env, &refcheck);
2374 attr->ia_valid |= ATTR_SIZE;
2375 attr->ia_size = ref_attr.cat_size;
2378 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2382 /* If the file was restored, it needs to set dirty flag.
2384 * We've already sent MDS_DATA_MODIFIED flag in
2385 * ll_md_setattr() for truncate. However, the MDT refuses to
2386 * set the HS_DIRTY flag on released files, so we have to set
2387 * it again if the file has been restored. Please check how
2388 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2390 * Please notice that if the file is not released, the previous
2391 * MDS_DATA_MODIFIED has taken effect and usually
2392 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2393 * This way we can save an RPC for common open + trunc
2395 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2396 struct hsm_state_set hss = {
2397 .hss_valid = HSS_SETMASK,
2398 .hss_setmask = HS_DIRTY,
2402 rc2 = ll_hsm_state_set(inode, &hss);
2403 /* truncate and write can happen at the same time, so that
2404 * the file can be set modified even though the file is not
2405 * restored from released state, and ll_hsm_state_set() is
2406 * not applicable for the file, and rc2 < 0 is normal in this
2409 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2410 PFID(ll_inode2fid(inode)), rc2);
2415 if (op_data != NULL)
2416 ll_finish_md_op_data(op_data);
2418 if (S_ISREG(inode->i_mode)) {
2420 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2421 inode_dio_wait(inode);
2422 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2423 * flag. ll_update_inode (called from ll_md_setattr), clears
2424 * inode flags, so there is a gap where S_NOSEC is not set.
2425 * This can cause a writer to take the i_mutex unnecessarily,
2426 * but this is safe to do and should be rare. */
2427 inode_has_no_xattr(inode);
2431 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2432 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2433 ktime_us_delta(ktime_get(), kstart));
2438 int ll_setattr(struct user_namespace *mnt_userns, struct dentry *de,
2441 int mode = de->d_inode->i_mode;
2442 enum op_xvalid xvalid = 0;
2445 rc = llcrypt_prepare_setattr(de, attr);
2449 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2450 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2451 xvalid |= OP_XVALID_OWNEROVERRIDE;
2453 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2454 (ATTR_SIZE|ATTR_MODE)) &&
2455 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2456 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2457 !(attr->ia_mode & S_ISGID))))
2458 attr->ia_valid |= ATTR_FORCE;
2460 if ((attr->ia_valid & ATTR_MODE) &&
2462 !(attr->ia_mode & S_ISUID) &&
2463 !(attr->ia_valid & ATTR_KILL_SUID))
2464 attr->ia_valid |= ATTR_KILL_SUID;
2466 if ((attr->ia_valid & ATTR_MODE) &&
2467 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2468 !(attr->ia_mode & S_ISGID) &&
2469 !(attr->ia_valid & ATTR_KILL_SGID))
2470 attr->ia_valid |= ATTR_KILL_SGID;
2472 return ll_setattr_raw(de, attr, xvalid, false);
2475 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2478 struct obd_statfs obd_osfs = { 0 };
2483 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2485 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2486 flags |= OBD_STATFS_NODELAY;
2488 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2492 osfs->os_type = LL_SUPER_MAGIC;
2494 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2495 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2497 if (osfs->os_state & OS_STATFS_SUM)
2500 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2501 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2504 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2505 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2508 osfs->os_bsize = obd_osfs.os_bsize;
2509 osfs->os_blocks = obd_osfs.os_blocks;
2510 osfs->os_bfree = obd_osfs.os_bfree;
2511 osfs->os_bavail = obd_osfs.os_bavail;
2513 /* If we have _some_ OSTs, but don't have as many free objects on the
2514 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2515 * to compensate, so that the "inodes in use" number is correct.
2516 * This should be kept in sync with lod_statfs() behaviour.
2518 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2519 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2521 osfs->os_ffree = obd_osfs.os_ffree;
2528 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2530 struct if_quotactl qctl = {
2531 .qc_cmd = LUSTRE_Q_GETQUOTA,
2532 .qc_type = PRJQUOTA,
2533 .qc_valid = QC_GENERAL,
2535 u64 limit, curblock;
2538 qctl.qc_id = ll_i2info(inode)->lli_projid;
2539 ret = quotactl_ioctl(inode->i_sb, &qctl);
2541 /* ignore errors if project ID does not have
2542 * a quota limit or feature unsupported.
2544 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2549 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2550 qctl.qc_dqblk.dqb_bsoftlimit :
2551 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2552 if (limit && sfs->f_blocks > limit) {
2553 curblock = (qctl.qc_dqblk.dqb_curspace +
2554 sfs->f_bsize - 1) / sfs->f_bsize;
2555 sfs->f_blocks = limit;
2556 sfs->f_bfree = sfs->f_bavail =
2557 (sfs->f_blocks > curblock) ?
2558 (sfs->f_blocks - curblock) : 0;
2561 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2562 qctl.qc_dqblk.dqb_isoftlimit :
2563 qctl.qc_dqblk.dqb_ihardlimit;
2564 if (limit && sfs->f_files > limit) {
2565 sfs->f_files = limit;
2566 sfs->f_ffree = (sfs->f_files >
2567 qctl.qc_dqblk.dqb_curinodes) ?
2568 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2574 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2576 struct super_block *sb = de->d_sb;
2577 struct obd_statfs osfs;
2578 __u64 fsid = huge_encode_dev(sb->s_dev);
2579 ktime_t kstart = ktime_get();
2582 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2584 /* Some amount of caching on the client is allowed */
2585 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2589 statfs_unpack(sfs, &osfs);
2591 /* We need to downshift for all 32-bit kernels, because we can't
2592 * tell if the kernel is being called via sys_statfs64() or not.
2593 * Stop before overflowing f_bsize - in which case it is better
2594 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2595 if (sizeof(long) < 8) {
2596 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2599 osfs.os_blocks >>= 1;
2600 osfs.os_bfree >>= 1;
2601 osfs.os_bavail >>= 1;
2605 sfs->f_blocks = osfs.os_blocks;
2606 sfs->f_bfree = osfs.os_bfree;
2607 sfs->f_bavail = osfs.os_bavail;
2608 sfs->f_fsid.val[0] = (__u32)fsid;
2609 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2610 if (ll_i2info(de->d_inode)->lli_projid &&
2611 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2612 return ll_statfs_project(de->d_inode, sfs);
2614 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2615 ktime_us_delta(ktime_get(), kstart));
2620 void ll_inode_size_lock(struct inode *inode)
2622 struct ll_inode_info *lli;
2624 LASSERT(!S_ISDIR(inode->i_mode));
2626 lli = ll_i2info(inode);
2627 mutex_lock(&lli->lli_size_mutex);
2630 void ll_inode_size_unlock(struct inode *inode)
2632 struct ll_inode_info *lli;
2634 lli = ll_i2info(inode);
2635 mutex_unlock(&lli->lli_size_mutex);
2638 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2640 /* do not clear encryption flag */
2641 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2642 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2643 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2644 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2646 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2649 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2651 struct ll_inode_info *lli = ll_i2info(inode);
2652 struct mdt_body *body = md->body;
2653 struct ll_sb_info *sbi = ll_i2sbi(inode);
2657 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2658 rc = cl_file_inode_init(inode, md);
2663 if (S_ISDIR(inode->i_mode)) {
2664 rc = ll_update_lsm_md(inode, md);
2669 if (body->mbo_valid & OBD_MD_FLACL)
2670 lli_replace_acl(lli, md);
2672 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2673 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2674 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2676 if (body->mbo_valid & OBD_MD_FLATIME) {
2677 if (body->mbo_atime > inode->i_atime.tv_sec)
2678 inode->i_atime.tv_sec = body->mbo_atime;
2679 lli->lli_atime = body->mbo_atime;
2682 if (body->mbo_valid & OBD_MD_FLMTIME) {
2683 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2685 "setting ino %lu mtime from %lld to %llu\n",
2686 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2688 inode->i_mtime.tv_sec = body->mbo_mtime;
2690 lli->lli_mtime = body->mbo_mtime;
2693 if (body->mbo_valid & OBD_MD_FLCTIME) {
2694 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2695 inode->i_ctime.tv_sec = body->mbo_ctime;
2696 lli->lli_ctime = body->mbo_ctime;
2699 if (body->mbo_valid & OBD_MD_FLBTIME)
2700 lli->lli_btime = body->mbo_btime;
2702 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2703 if (body->mbo_valid & OBD_MD_FLFLAGS)
2704 ll_update_inode_flags(inode, body->mbo_flags);
2705 if (body->mbo_valid & OBD_MD_FLMODE)
2706 inode->i_mode = (inode->i_mode & S_IFMT) |
2707 (body->mbo_mode & ~S_IFMT);
2709 if (body->mbo_valid & OBD_MD_FLTYPE)
2710 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2711 (body->mbo_mode & S_IFMT);
2713 LASSERT(inode->i_mode != 0);
2714 if (body->mbo_valid & OBD_MD_FLUID)
2715 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2716 if (body->mbo_valid & OBD_MD_FLGID)
2717 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2718 if (body->mbo_valid & OBD_MD_FLPROJID)
2719 lli->lli_projid = body->mbo_projid;
2720 if (body->mbo_valid & OBD_MD_FLNLINK) {
2721 spin_lock(&inode->i_lock);
2722 set_nlink(inode, body->mbo_nlink);
2723 spin_unlock(&inode->i_lock);
2725 if (body->mbo_valid & OBD_MD_FLRDEV)
2726 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2728 if (body->mbo_valid & OBD_MD_FLID) {
2729 /* FID shouldn't be changed! */
2730 if (fid_is_sane(&lli->lli_fid)) {
2731 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2732 "Trying to change FID "DFID
2733 " to the "DFID", inode "DFID"(%p)\n",
2734 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2735 PFID(ll_inode2fid(inode)), inode);
2737 lli->lli_fid = body->mbo_fid1;
2741 LASSERT(fid_seq(&lli->lli_fid) != 0);
2743 /* In case of encrypted file without the key, please do not lose
2744 * clear text size stored into lli_lazysize in ll_merge_attr(),
2745 * we will need it in ll_prepare_close().
2747 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2748 llcrypt_require_key(inode) == -ENOKEY)
2749 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2751 lli->lli_attr_valid = body->mbo_valid;
2752 if (body->mbo_valid & OBD_MD_FLSIZE) {
2753 i_size_write(inode, body->mbo_size);
2755 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2756 PFID(ll_inode2fid(inode)),
2757 (unsigned long long)body->mbo_size);
2759 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2760 inode->i_blocks = body->mbo_blocks;
2762 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2763 lli->lli_lazysize = body->mbo_size;
2764 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2765 lli->lli_lazyblocks = body->mbo_blocks;
2768 if (body->mbo_valid & OBD_MD_TSTATE) {
2769 /* Set LLIF_FILE_RESTORING if restore ongoing and
2770 * clear it when done to ensure to start again
2771 * glimpsing updated attrs
2773 if (body->mbo_t_state & MS_RESTORE)
2774 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2776 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2782 /* child default LMV is inherited from parent */
2783 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2784 struct lmv_stripe_md *cdmv)
2789 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2790 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2791 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2792 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2795 if (cdmv->lsm_md_max_inherit !=
2796 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2799 if (cdmv->lsm_md_max_inherit_rr !=
2800 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2806 /* update directory depth to ROOT, called after LOOKUP lock is fetched. */
2807 void ll_update_dir_depth(struct inode *dir, struct inode *inode)
2809 struct ll_inode_info *plli;
2810 struct ll_inode_info *lli;
2812 if (!S_ISDIR(inode->i_mode))
2818 plli = ll_i2info(dir);
2819 lli = ll_i2info(inode);
2820 lli->lli_dir_depth = plli->lli_dir_depth + 1;
2821 if (plli->lli_default_lsm_md && lli->lli_default_lsm_md) {
2822 down_read(&plli->lli_lsm_sem);
2823 down_read(&lli->lli_lsm_sem);
2824 if (ll_default_lmv_inherited(plli->lli_default_lsm_md,
2825 lli->lli_default_lsm_md))
2826 lli->lli_inherit_depth =
2827 plli->lli_inherit_depth + 1;
2829 lli->lli_inherit_depth = 0;
2830 up_read(&lli->lli_lsm_sem);
2831 up_read(&plli->lli_lsm_sem);
2833 lli->lli_inherit_depth = 0;
2836 CDEBUG(D_INODE, DFID" depth %hu default LMV depth %hu\n",
2837 PFID(&lli->lli_fid), lli->lli_dir_depth, lli->lli_inherit_depth);
2840 void ll_truncate_inode_pages_final(struct inode *inode)
2842 struct address_space *mapping = &inode->i_data;
2843 unsigned long nrpages;
2844 unsigned long flags;
2846 truncate_inode_pages_final(mapping);
2848 /* Workaround for LU-118: Note nrpages may not be totally updated when
2849 * truncate_inode_pages() returns, as there can be a page in the process
2850 * of deletion (inside __delete_from_page_cache()) in the specified
2851 * range. Thus mapping->nrpages can be non-zero when this function
2852 * returns even after truncation of the whole mapping. Only do this if
2853 * npages isn't already zero.
2855 nrpages = mapping->nrpages;
2857 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2858 nrpages = mapping->nrpages;
2859 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2860 } /* Workaround end */
2862 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, "
2863 "see https://jira.whamcloud.com/browse/LU-118\n",
2864 ll_i2sbi(inode)->ll_fsname,
2865 PFID(ll_inode2fid(inode)), inode, nrpages);
2868 int ll_read_inode2(struct inode *inode, void *opaque)
2870 struct lustre_md *md = opaque;
2871 struct ll_inode_info *lli = ll_i2info(inode);
2875 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2876 PFID(&lli->lli_fid), inode);
2878 /* Core attributes from the MDS first. This is a new inode, and
2879 * the VFS doesn't zero times in the core inode so we have to do
2880 * it ourselves. They will be overwritten by either MDS or OST
2881 * attributes - we just need to make sure they aren't newer.
2883 inode->i_mtime.tv_sec = 0;
2884 inode->i_atime.tv_sec = 0;
2885 inode->i_ctime.tv_sec = 0;
2887 rc = ll_update_inode(inode, md);
2891 /* OIDEBUG(inode); */
2893 #ifdef HAVE_BACKING_DEV_INFO
2894 /* initializing backing dev info. */
2895 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2897 if (S_ISREG(inode->i_mode)) {
2898 struct ll_sb_info *sbi = ll_i2sbi(inode);
2899 inode->i_op = &ll_file_inode_operations;
2900 inode->i_fop = sbi->ll_fop;
2901 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2903 } else if (S_ISDIR(inode->i_mode)) {
2904 inode->i_op = &ll_dir_inode_operations;
2905 inode->i_fop = &ll_dir_operations;
2907 } else if (S_ISLNK(inode->i_mode)) {
2908 inode->i_op = &ll_fast_symlink_inode_operations;
2911 inode->i_op = &ll_special_inode_operations;
2913 init_special_inode(inode, inode->i_mode,
2922 void ll_delete_inode(struct inode *inode)
2924 struct ll_inode_info *lli = ll_i2info(inode);
2927 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2928 /* It is last chance to write out dirty pages,
2929 * otherwise we may lose data while umount.
2931 * If i_nlink is 0 then just discard data. This is safe because
2932 * local inode gets i_nlink 0 from server only for the last
2933 * unlink, so that file is not opened somewhere else
2935 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2936 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2939 ll_truncate_inode_pages_final(inode);
2940 ll_clear_inode(inode);
2946 int ll_iocontrol(struct inode *inode, struct file *file,
2947 unsigned int cmd, unsigned long arg)
2949 struct ll_sb_info *sbi = ll_i2sbi(inode);
2950 struct ptlrpc_request *req = NULL;
2955 case FS_IOC_GETFLAGS: {
2956 struct mdt_body *body;
2957 struct md_op_data *op_data;
2959 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2960 0, 0, LUSTRE_OPC_ANY,
2962 if (IS_ERR(op_data))
2963 RETURN(PTR_ERR(op_data));
2965 op_data->op_valid = OBD_MD_FLFLAGS;
2966 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2967 ll_finish_md_op_data(op_data);
2969 CERROR("%s: failure inode "DFID": rc = %d\n",
2970 sbi->ll_md_exp->exp_obd->obd_name,
2971 PFID(ll_inode2fid(inode)), rc);
2975 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2977 flags = body->mbo_flags;
2979 ptlrpc_req_finished(req);
2981 RETURN(put_user(flags, (int __user *)arg));
2983 case FS_IOC_SETFLAGS: {
2985 struct md_op_data *op_data;
2986 struct cl_object *obj;
2987 struct fsxattr fa = { 0 };
2989 if (get_user(flags, (int __user *)arg))
2992 fa.fsx_projid = ll_i2info(inode)->lli_projid;
2993 if (flags & LUSTRE_PROJINHERIT_FL)
2994 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
2996 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3001 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3002 LUSTRE_OPC_ANY, NULL);
3003 if (IS_ERR(op_data))
3004 RETURN(PTR_ERR(op_data));
3006 op_data->op_attr_flags = flags;
3007 op_data->op_xvalid |= OP_XVALID_FLAGS;
3008 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3009 ll_finish_md_op_data(op_data);
3010 ptlrpc_req_finished(req);
3014 ll_update_inode_flags(inode, flags);
3016 obj = ll_i2info(inode)->lli_clob;
3020 OBD_ALLOC_PTR(attr);
3024 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3036 int ll_flush_ctx(struct inode *inode)
3038 struct ll_sb_info *sbi = ll_i2sbi(inode);
3040 CDEBUG(D_SEC, "flush context for user %d\n",
3041 from_kuid(&init_user_ns, current_uid()));
3043 obd_set_info_async(NULL, sbi->ll_md_exp,
3044 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3046 obd_set_info_async(NULL, sbi->ll_dt_exp,
3047 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3052 /* umount -f client means force down, don't save state */
3053 void ll_umount_begin(struct super_block *sb)
3055 struct ll_sb_info *sbi = ll_s2sbi(sb);
3056 struct obd_device *obd;
3057 struct obd_ioctl_data *ioc_data;
3061 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3062 sb->s_count, atomic_read(&sb->s_active));
3064 obd = class_exp2obd(sbi->ll_md_exp);
3066 CERROR("Invalid MDC connection handle %#llx\n",
3067 sbi->ll_md_exp->exp_handle.h_cookie);
3073 obd = class_exp2obd(sbi->ll_dt_exp);
3075 CERROR("Invalid LOV connection handle %#llx\n",
3076 sbi->ll_dt_exp->exp_handle.h_cookie);
3082 OBD_ALLOC_PTR(ioc_data);
3084 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
3085 sizeof *ioc_data, ioc_data, NULL);
3087 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
3088 sizeof *ioc_data, ioc_data, NULL);
3090 OBD_FREE_PTR(ioc_data);
3093 /* Really, we'd like to wait until there are no requests outstanding,
3094 * and then continue. For now, we just periodically checking for vfs
3095 * to decrement mnt_cnt and hope to finish it within 10sec.
3099 !may_umount(sbi->ll_mnt.mnt)) {
3107 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3109 struct ll_sb_info *sbi = ll_s2sbi(sb);
3110 char *profilenm = get_profile_name(sb);
3114 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3115 read_only = *flags & MS_RDONLY;
3116 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3117 sizeof(KEY_READ_ONLY),
3118 KEY_READ_ONLY, sizeof(read_only),
3121 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3122 profilenm, read_only ?
3123 "read-only" : "read-write", err);
3128 sb->s_flags |= SB_RDONLY;
3130 sb->s_flags &= ~SB_RDONLY;
3132 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3133 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3134 read_only ? "read-only" : "read-write");
3140 * Cleanup the open handle that is cached on MDT-side.
3142 * For open case, the client side open handling thread may hit error
3143 * after the MDT grant the open. Under such case, the client should
3144 * send close RPC to the MDT as cleanup; otherwise, the open handle
3145 * on the MDT will be leaked there until the client umount or evicted.
3147 * In further, if someone unlinked the file, because the open handle
3148 * holds the reference on such file/object, then it will block the
3149 * subsequent threads that want to locate such object via FID.
3151 * \param[in] sb super block for this file-system
3152 * \param[in] open_req pointer to the original open request
3154 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3156 struct mdt_body *body;
3157 struct md_op_data *op_data;
3158 struct ptlrpc_request *close_req = NULL;
3159 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3162 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3163 OBD_ALLOC_PTR(op_data);
3164 if (op_data == NULL) {
3165 CWARN("%s: cannot allocate op_data to release open handle for "
3166 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3171 op_data->op_fid1 = body->mbo_fid1;
3172 op_data->op_open_handle = body->mbo_open_handle;
3173 op_data->op_mod_time = ktime_get_real_seconds();
3174 md_close(exp, op_data, NULL, &close_req);
3175 ptlrpc_req_finished(close_req);
3176 ll_finish_md_op_data(op_data);
3181 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3182 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3183 struct lustre_md *md)
3185 struct ll_sb_info *sbi = ll_i2sbi(inode);
3186 struct ptlrpc_request *req = NULL;
3187 union lmv_mds_md *lmm = NULL;
3191 LASSERT(is_root_inode(inode));
3192 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3193 LASSERT(!md->default_lmv);
3195 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3197 GET_DEFAULT_LAYOUT_ROOT);
3198 if (rc && rc != -ENODATA)
3203 rc = md_unpackmd(sbi->ll_md_exp, &md->default_lmv, lmm, size);
3212 ptlrpc_req_finished(req);
3216 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3217 struct super_block *sb, struct lookup_intent *it)
3219 struct ll_sb_info *sbi = NULL;
3220 struct lustre_md md = { NULL };
3221 bool default_lmv_deleted = false;
3226 LASSERT(*inode || sb);
3227 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3228 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3229 sbi->ll_md_exp, &md);
3233 if (S_ISDIR(md.body->mbo_mode) && md.lmv && lmv_dir_striped(md.lmv) &&
3234 it && it->it_extra_rpc_check) {
3235 /* TODO: Check @lsm unchanged via @lsm_md_eq. */
3236 it->it_extra_rpc_need = 1;
3237 GOTO(out, rc = -EAGAIN);
3241 * clear default_lmv only if intent_getattr reply doesn't contain it.
3242 * but it needs to be done after iget, check this early because
3243 * ll_update_lsm_md() may change md.
3245 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3246 S_ISDIR(md.body->mbo_mode) && !md.default_lmv) {
3247 if (unlikely(*inode && is_root_inode(*inode) &&
3248 !fid_is_root(&sbi->ll_root_fid))) {
3249 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3254 if (!md.default_lmv)
3255 default_lmv_deleted = true;
3259 rc = ll_update_inode(*inode, &md);
3263 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3264 struct lu_fid *fid1 = &md.body->mbo_fid1;
3266 LASSERT(sb != NULL);
3269 * At this point server returns to client's same fid as client
3270 * generated for creating. So using ->fid1 is okay here.
3272 if (!fid_is_sane(fid1)) {
3273 CERROR("%s: Fid is insane "DFID"\n",
3274 sbi->ll_fsname, PFID(fid1));
3275 GOTO(out, rc = -EINVAL);
3278 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3279 if (IS_ERR(*inode)) {
3281 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3283 CERROR("new_inode -fatal: rc %d\n", rc);
3288 /* Handling piggyback layout lock.
3289 * Layout lock can be piggybacked by getattr and open request.
3290 * The lsm can be applied to inode only if it comes with a layout lock
3291 * otherwise correct layout may be overwritten, for example:
3292 * 1. proc1: mdt returns a lsm but not granting layout
3293 * 2. layout was changed by another client
3294 * 3. proc2: refresh layout and layout lock granted
3295 * 4. proc1: to apply a stale layout */
3296 if (it != NULL && it->it_lock_mode != 0) {
3297 struct lustre_handle lockh;
3298 struct ldlm_lock *lock;
3300 lockh.cookie = it->it_lock_handle;
3301 lock = ldlm_handle2lock(&lockh);
3302 LASSERT(lock != NULL);
3303 if (ldlm_has_layout(lock)) {
3304 struct cl_object_conf conf;
3306 memset(&conf, 0, sizeof(conf));
3307 conf.coc_opc = OBJECT_CONF_SET;
3308 conf.coc_inode = *inode;
3309 conf.coc_lock = lock;
3310 conf.u.coc_layout = md.layout;
3311 (void)ll_layout_conf(*inode, &conf);
3313 LDLM_LOCK_PUT(lock);
3316 if (default_lmv_deleted)
3317 ll_update_default_lsm_md(*inode, &md);
3319 /* we may want to apply some policy for foreign file/dir */
3320 if (ll_sbi_has_foreign_symlink(sbi)) {
3321 rc = ll_manage_foreign(*inode, &md);
3329 /* cleanup will be done if necessary */
3330 md_free_lustre_md(sbi->ll_md_exp, &md);
3332 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3333 ll_intent_drop_lock(it);
3334 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3340 int ll_obd_statfs(struct inode *inode, void __user *arg)
3342 struct ll_sb_info *sbi = NULL;
3343 struct obd_export *exp;
3344 struct obd_ioctl_data *data = NULL;
3349 sbi = ll_i2sbi(inode);
3351 GOTO(out_statfs, rc = -EINVAL);
3353 rc = obd_ioctl_getdata(&data, &len, arg);
3355 GOTO(out_statfs, rc);
3357 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3358 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3359 GOTO(out_statfs, rc = -EINVAL);
3361 if (data->ioc_inllen1 != sizeof(__u32) ||
3362 data->ioc_inllen2 != sizeof(__u32) ||
3363 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3364 data->ioc_plen2 != sizeof(struct obd_uuid))
3365 GOTO(out_statfs, rc = -EINVAL);
3367 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3368 if (type & LL_STATFS_LMV)
3369 exp = sbi->ll_md_exp;
3370 else if (type & LL_STATFS_LOV)
3371 exp = sbi->ll_dt_exp;
3373 GOTO(out_statfs, rc = -ENODEV);
3375 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3377 GOTO(out_statfs, rc);
3379 OBD_FREE_LARGE(data, len);
3384 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3385 * be called early to avoid deadlock.
3387 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3389 if (op_data->op_mea2_sem) {
3390 up_read_non_owner(op_data->op_mea2_sem);
3391 op_data->op_mea2_sem = NULL;
3394 if (op_data->op_mea1_sem) {
3395 up_read_non_owner(op_data->op_mea1_sem);
3396 op_data->op_mea1_sem = NULL;
3400 /* this function prepares md_op_data hint for passing it down to MD stack. */
3401 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3402 struct inode *i1, struct inode *i2,
3403 const char *name, size_t namelen,
3404 __u32 mode, enum md_op_code opc,
3407 struct llcrypt_name fname = { 0 };
3410 LASSERT(i1 != NULL);
3413 /* Do not reuse namelen for something else. */
3415 return ERR_PTR(-EINVAL);
3417 if ((!IS_ENCRYPTED(i1) ||
3418 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3419 namelen > ll_i2sbi(i1)->ll_namelen)
3420 return ERR_PTR(-ENAMETOOLONG);
3422 /* "/" is not valid name, but it's allowed */
3423 if (!lu_name_is_valid_2(name, namelen) &&
3424 strncmp("/", name, namelen) != 0)
3425 return ERR_PTR(-EINVAL);
3428 if (op_data == NULL)
3429 OBD_ALLOC_PTR(op_data);
3431 if (op_data == NULL)
3432 return ERR_PTR(-ENOMEM);
3434 ll_i2gids(op_data->op_suppgids, i1, i2);
3435 /* If the client is using a subdir mount and looks at what it sees as
3436 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3438 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3439 !fid_is_root(ll_inode2fid(i1)) &&
3440 name && namelen == strlen(dot_fscrypt_name) &&
3441 strncmp(name, dot_fscrypt_name, namelen) == 0))
3442 lu_root_fid(&op_data->op_fid1);
3444 op_data->op_fid1 = *ll_inode2fid(i1);
3446 if (S_ISDIR(i1->i_mode)) {
3447 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3448 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3449 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3450 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3454 op_data->op_fid2 = *ll_inode2fid(i2);
3455 if (S_ISDIR(i2->i_mode)) {
3457 /* i2 is typically a child of i1, and MUST be
3458 * further from the root to avoid deadlocks.
3460 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3461 op_data->op_mea2_sem =
3462 &ll_i2info(i2)->lli_lsm_sem;
3464 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3467 fid_zero(&op_data->op_fid2);
3470 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3471 op_data->op_cli_flags |= CLI_HASH64;
3473 if (ll_need_32bit_api(ll_i2sbi(i1)))
3474 op_data->op_cli_flags |= CLI_API32;
3476 if ((i2 && is_root_inode(i2)) ||
3477 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3478 /* In case of lookup, ll_setup_filename() has already been
3479 * called in ll_lookup_it(), so just take provided name.
3480 * Also take provided name if we are dealing with root inode.
3482 fname.disk_name.name = (unsigned char *)name;
3483 fname.disk_name.len = namelen;
3484 } else if (name && namelen) {
3485 struct qstr dname = QSTR_INIT(name, namelen);
3487 struct lu_fid *pfid = NULL;
3491 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3492 /* special case when called from ll_link() */
3497 lookup = (int)(opc == LUSTRE_OPC_ANY);
3499 if (opc == LUSTRE_OPC_ANY && lookup)
3501 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3503 ll_finish_md_op_data(op_data);
3506 if (pfid && !fid_is_zero(pfid)) {
3508 op_data->op_fid2 = fid;
3509 op_data->op_bias = MDS_FID_OP;
3511 if (fname.disk_name.name &&
3512 fname.disk_name.name != (unsigned char *)name) {
3513 /* op_data->op_name must be freed after use */
3514 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3518 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3519 * are LUSTRE_OPC_ANY
3521 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3522 op_data->op_code = LUSTRE_OPC_ANY;
3524 op_data->op_code = opc;
3525 op_data->op_name = fname.disk_name.name;
3526 op_data->op_namelen = fname.disk_name.len;
3527 op_data->op_mode = mode;
3528 op_data->op_mod_time = ktime_get_real_seconds();
3529 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3530 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3531 op_data->op_cap = current_cap();
3532 op_data->op_mds = 0;
3533 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3534 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3535 op_data->op_bias |= MDS_CREATE_VOLATILE;
3537 op_data->op_data = data;
3542 void ll_finish_md_op_data(struct md_op_data *op_data)
3544 ll_unlock_md_op_lsm(op_data);
3545 ll_security_release_secctx(op_data->op_file_secctx,
3546 op_data->op_file_secctx_size);
3547 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3548 /* allocated via ll_setup_filename called
3549 * from ll_prep_md_op_data
3551 kfree(op_data->op_name);
3552 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3553 OBD_FREE_PTR(op_data);
3556 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3558 struct ll_sb_info *sbi;
3561 LASSERT(seq && dentry);
3562 sbi = ll_s2sbi(dentry->d_sb);
3564 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3565 seq_puts(seq, "nolock");
3567 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3568 /* match_table in some cases has patterns for both enabled and
3569 * disabled cases. Ignore 'no'xxx versions if bit is set.
3571 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3572 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3573 if (ll_sbi_flags_name[i].token ==
3574 LL_SBI_FOREIGN_SYMLINK) {
3575 seq_show_option(seq, "foreign_symlink",
3576 sbi->ll_foreign_symlink_prefix);
3578 seq_printf(seq, ",%s",
3579 ll_sbi_flags_name[i].pattern);
3582 /* You can have either localflock or flock but not
3583 * both. If localflock is set don't print flock or
3586 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3588 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3589 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3590 seq_printf(seq, ",%s",
3591 ll_sbi_flags_name[i].pattern);
3595 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3601 * Get obd name by cmd, and copy out to user space
3603 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
3605 struct ll_sb_info *sbi = ll_i2sbi(inode);
3606 struct obd_device *obd;
3609 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3610 obd = class_exp2obd(sbi->ll_dt_exp);
3611 else if (cmd == OBD_IOC_GETMDNAME)
3612 obd = class_exp2obd(sbi->ll_md_exp);
3619 if (copy_to_user((void __user *)arg, obd->obd_name,
3620 strlen(obd->obd_name) + 1))
3627 struct work_struct db_work;
3628 struct dentry *db_dentry;
3629 /* Let's hope the path is not too long, 32 bytes for the work struct
3632 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3635 static void ll_dput_later(struct work_struct *work)
3637 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3639 dput(db->db_dentry);
3640 free_page((unsigned long)db);
3643 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3650 p.mnt = current->fs->root.mnt;
3652 path = d_path(&p, buf, bufsize);
3657 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3659 struct dname_buf *db;
3661 struct dentry *dentry = NULL;
3663 /* this can be called inside spin lock so use GFP_ATOMIC. */
3664 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3667 dentry = d_find_alias(inode);
3669 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3672 /* The below message is checked in recovery-small.sh test_24b */
3674 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3675 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3676 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3677 PFID(ll_inode2fid(inode)),
3678 (path && !IS_ERR(path)) ? path : "", ioret);
3680 if (dentry != NULL) {
3681 /* We cannot dput here since if we happen to be the last holder
3682 * then we can end up waiting for page evictions that
3683 * in turn wait for RPCs that need this instance of ptlrpcd
3684 * (callng brw_interpret->*page_completion*->vmpage_error->here)
3687 INIT_WORK(&db->db_work, ll_dput_later);
3688 db->db_dentry = dentry;
3689 schedule_work(&db->db_work);
3692 free_page((unsigned long)db);
3696 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3697 struct lov_user_md **kbuf)
3699 struct lov_user_md lum;
3703 if (copy_from_user(&lum, md, sizeof(lum)))
3706 lum_size = ll_lov_user_md_size(&lum);
3710 OBD_ALLOC_LARGE(*kbuf, lum_size);
3714 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3715 OBD_FREE_LARGE(*kbuf, lum_size);
3723 * Compute llite root squash state after a change of root squash
3724 * configuration setting or add/remove of a lnet nid
3726 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3728 struct root_squash_info *squash = &sbi->ll_squash;
3731 struct lnet_processid id;
3733 /* Update norootsquash flag */
3734 spin_lock(&squash->rsi_lock);
3735 if (list_empty(&squash->rsi_nosquash_nids))
3736 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3738 /* Do not apply root squash as soon as one of our NIDs is
3739 * in the nosquash_nids list */
3742 while (LNetGetId(i++, &id) != -ENOENT) {
3743 if (nid_is_lo0(&id.nid))
3745 if (cfs_match_nid(lnet_nid_to_nid4(&id.nid),
3746 &squash->rsi_nosquash_nids)) {
3752 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3754 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3756 spin_unlock(&squash->rsi_lock);
3760 * Parse linkea content to extract information about a given hardlink
3762 * \param[in] ldata - Initialized linkea data
3763 * \param[in] linkno - Link identifier
3764 * \param[out] parent_fid - The entry's parent FID
3765 * \param[out] ln - Entry name destination buffer
3767 * \retval 0 on success
3768 * \retval Appropriate negative error code on failure
3770 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3771 struct lu_fid *parent_fid, struct lu_name *ln)
3777 rc = linkea_init_with_rec(ldata);
3781 if (linkno >= ldata->ld_leh->leh_reccount)
3782 /* beyond last link */
3785 linkea_first_entry(ldata);
3786 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3787 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3792 linkea_next_entry(ldata);
3802 * Get parent FID and name of an identified link. Operation is performed for
3803 * a given link number, letting the caller iterate over linkno to list one or
3804 * all links of an entry.
3806 * \param[in] file - File descriptor against which to perform the operation
3807 * \param[in,out] arg - User-filled structure containing the linkno to operate
3808 * on and the available size. It is eventually filled with
3809 * the requested information or left untouched on error
3811 * \retval - 0 on success
3812 * \retval - Appropriate negative error code on failure
3814 int ll_getparent(struct file *file, struct getparent __user *arg)
3816 struct inode *inode = file_inode(file);
3817 struct linkea_data *ldata;
3818 struct lu_buf buf = LU_BUF_NULL;
3820 struct lu_fid parent_fid;
3827 if (!capable(CAP_DAC_READ_SEARCH) &&
3828 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
3831 if (get_user(name_size, &arg->gp_name_size))
3834 if (get_user(linkno, &arg->gp_linkno))
3837 if (name_size > PATH_MAX)
3840 OBD_ALLOC(ldata, sizeof(*ldata));
3844 rc = linkea_data_new(ldata, &buf);
3846 GOTO(ldata_free, rc);
3848 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3849 buf.lb_len, OBD_MD_FLXATTR);
3853 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3857 if (ln.ln_namelen >= name_size)
3858 GOTO(lb_free, rc = -EOVERFLOW);
3860 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3861 GOTO(lb_free, rc = -EFAULT);
3863 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3864 GOTO(lb_free, rc = -EFAULT);
3866 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3867 GOTO(lb_free, rc = -EFAULT);
3872 OBD_FREE(ldata, sizeof(*ldata));