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_secctx_name = NULL;
151 sbi->ll_secctx_name_size = 0;
153 sbi->ll_ra_info.ra_max_pages =
154 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
155 sbi->ll_ra_info.ra_max_pages_per_file =
156 min(sbi->ll_ra_info.ra_max_pages / 4,
157 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
158 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
159 sbi->ll_ra_info.ra_max_pages_per_file;
160 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
161 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
162 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
164 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
165 #ifdef ENABLE_CHECKSUM
166 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
169 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
172 #ifdef HAVE_LRU_RESIZE_SUPPORT
173 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
175 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
177 /* metadata statahead is enabled by default */
178 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
179 sbi->ll_sa_max = LL_SA_RPC_DEF;
180 atomic_set(&sbi->ll_sa_total, 0);
181 atomic_set(&sbi->ll_sa_wrong, 0);
182 atomic_set(&sbi->ll_sa_running, 0);
183 atomic_set(&sbi->ll_agl_total, 0);
184 atomic_set(&sbi->ll_sa_hit_total, 0);
185 atomic_set(&sbi->ll_sa_miss_total, 0);
186 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
187 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
188 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
189 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
190 ll_sbi_set_encrypt(sbi, true);
191 ll_sbi_set_name_encrypt(sbi, true);
194 sbi->ll_squash.rsi_uid = 0;
195 sbi->ll_squash.rsi_gid = 0;
196 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
197 spin_lock_init(&sbi->ll_squash.rsi_lock);
199 /* Per-filesystem file heat */
200 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
201 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
203 /* Per-fs open heat level before requesting open lock */
204 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
205 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
206 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
209 if (sbi->ll_foreign_symlink_prefix)
210 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
212 cl_cache_decref(sbi->ll_cache);
213 sbi->ll_cache = NULL;
215 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
217 pcc_super_fini(&sbi->ll_pcc_super);
223 static void ll_free_sbi(struct super_block *sb)
225 struct ll_sb_info *sbi = ll_s2sbi(sb);
229 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
230 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
231 if (sbi->ll_ra_info.ll_readahead_wq)
232 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
233 if (sbi->ll_cache != NULL) {
234 cl_cache_decref(sbi->ll_cache);
235 sbi->ll_cache = NULL;
237 if (sbi->ll_foreign_symlink_prefix) {
238 OBD_FREE(sbi->ll_foreign_symlink_prefix,
239 sbi->ll_foreign_symlink_prefix_size);
240 sbi->ll_foreign_symlink_prefix = NULL;
242 if (sbi->ll_foreign_symlink_upcall) {
243 OBD_FREE(sbi->ll_foreign_symlink_upcall,
244 strlen(sbi->ll_foreign_symlink_upcall) +
246 sbi->ll_foreign_symlink_upcall = NULL;
248 if (sbi->ll_foreign_symlink_upcall_items) {
250 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
251 struct ll_foreign_symlink_upcall_item *items =
252 sbi->ll_foreign_symlink_upcall_items;
254 for (i = 0 ; i < nb_items; i++)
255 if (items[i].type == STRING_TYPE)
256 OBD_FREE(items[i].string,
259 OBD_FREE_LARGE(items, nb_items *
260 sizeof(struct ll_foreign_symlink_upcall_item));
261 sbi->ll_foreign_symlink_upcall_items = NULL;
263 if (sbi->ll_secctx_name)
264 ll_secctx_name_free(sbi);
266 ll_free_rw_stats_info(sbi);
267 pcc_super_fini(&sbi->ll_pcc_super);
268 OBD_FREE(sbi, sizeof(*sbi));
273 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
275 struct inode *root = NULL;
276 struct ll_sb_info *sbi = ll_s2sbi(sb);
277 struct obd_statfs *osfs = NULL;
278 struct ptlrpc_request *request = NULL;
279 struct obd_connect_data *data = NULL;
280 struct obd_uuid *uuid;
281 struct md_op_data *op_data;
282 struct lustre_md lmd;
284 int size, err, checksum;
290 sbi->ll_md_obd = class_name2obd(md);
291 if (!sbi->ll_md_obd) {
292 CERROR("MD %s: not setup or attached\n", md);
306 /* pass client page size via ocd_grant_blkbits, the server should report
307 * back its backend blocksize for grant calculation purpose */
308 data->ocd_grant_blkbits = PAGE_SHIFT;
310 /* indicate MDT features supported by this client */
311 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
312 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
313 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
314 OBD_CONNECT_SRVLOCK |
315 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
316 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
317 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
318 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
319 OBD_CONNECT_64BITHASH |
320 OBD_CONNECT_EINPROGRESS |
321 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
322 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
323 OBD_CONNECT_MAX_EASIZE |
324 OBD_CONNECT_FLOCK_DEAD |
325 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
326 OBD_CONNECT_OPEN_BY_FID |
327 OBD_CONNECT_DIR_STRIPE |
328 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
329 OBD_CONNECT_SUBTREE |
330 OBD_CONNECT_MULTIMODRPCS |
331 OBD_CONNECT_GRANT_PARAM |
332 OBD_CONNECT_GRANT_SHRINK |
333 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
335 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
336 OBD_CONNECT2_SUM_STATFS |
337 OBD_CONNECT2_OVERSTRIPING |
339 OBD_CONNECT2_LOCK_CONVERT |
340 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
341 OBD_CONNECT2_INC_XID |
343 OBD_CONNECT2_ASYNC_DISCARD |
345 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
346 OBD_CONNECT2_GETATTR_PFID |
347 OBD_CONNECT2_DOM_LVB |
348 OBD_CONNECT2_REP_MBITS |
349 OBD_CONNECT2_ATOMIC_OPEN_LOCK;
351 #ifdef HAVE_LRU_RESIZE_SUPPORT
352 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
353 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
355 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
357 data->ocd_cksum_types = obd_cksum_types_supported_client();
359 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
360 /* flag mdc connection as lightweight, only used for test
361 * purpose, use with care */
362 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
364 data->ocd_ibits_known = MDS_INODELOCK_FULL;
365 data->ocd_version = LUSTRE_VERSION_CODE;
367 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
368 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
371 /* Setting this indicates we correctly support S_NOSEC (See kernel
372 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
374 sb->s_flags |= SB_NOSEC;
376 sbi->ll_fop = ll_select_file_operations(sbi);
378 /* always ping even if server suppress_pings */
379 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
380 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
382 obd_connect_set_secctx(data);
383 if (ll_sbi_has_encrypt(sbi)) {
384 obd_connect_set_name_enc(data);
385 obd_connect_set_enc(data);
388 #if defined(CONFIG_SECURITY)
389 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
392 data->ocd_brw_size = MD_MAX_BRW_SIZE;
395 if (sb->s_flags & SB_RDONLY)
396 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
397 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
398 &sbi->ll_sb_uuid, data, sbi->ll_cache);
400 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
401 "recovery, of which this client is not a "
402 "part. Please wait for recovery to complete,"
403 " abort, or time out.\n", md);
406 CERROR("cannot connect to %s: rc = %d\n", md, err);
410 sbi->ll_md_exp->exp_connect_data = *data;
412 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
413 LUSTRE_SEQ_METADATA);
415 CERROR("%s: Can't init metadata layer FID infrastructure, "
416 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
420 /* For mount, we only need fs info from MDT0, and also in DNE, it
421 * can make sure the client can be mounted as long as MDT0 is
423 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
424 ktime_get_seconds() - sbi->ll_statfs_max_age,
425 OBD_STATFS_FOR_MDT0);
426 if (err == -EROFS && !(sb->s_flags & SB_RDONLY)) {
427 /* We got -EROFS from the server, maybe it is imposing
428 * read-only mount. So just retry like this.
430 cfs_tty_write_msg("Forcing read-only mount.\n\r");
431 CERROR("%s: mount failed with %d, forcing read-only mount.\n",
432 sbi->ll_md_exp->exp_obd->obd_name, err);
433 sb->s_flags |= SB_RDONLY;
434 obd_fid_fini(sbi->ll_md_exp->exp_obd);
435 obd_disconnect(sbi->ll_md_exp);
436 GOTO(retry_connect, err);
438 GOTO(out_md_fid, err);
441 /* This needs to be after statfs to ensure connect has finished.
442 * Note that "data" does NOT contain the valid connect reply.
443 * If connecting to a 1.8 server there will be no LMV device, so
444 * we can access the MDC export directly and exp_connect_flags will
445 * be non-zero, but if accessing an upgraded 2.1 server it will
446 * have the correct flags filled in.
447 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
448 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
449 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
450 valid != CLIENT_CONNECT_MDT_REQD) {
453 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
454 obd_connect_flags2str(buf, PAGE_SIZE,
455 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
456 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
457 "feature(s) needed for correct operation "
458 "of this client (%s). Please upgrade "
459 "server or downgrade client.\n",
460 sbi->ll_md_exp->exp_obd->obd_name, buf);
461 OBD_FREE(buf, PAGE_SIZE);
462 GOTO(out_md_fid, err = -EPROTO);
465 size = sizeof(*data);
466 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
467 KEY_CONN_DATA, &size, data);
469 CERROR("%s: Get connect data failed: rc = %d\n",
470 sbi->ll_md_exp->exp_obd->obd_name, err);
471 GOTO(out_md_fid, err);
474 LASSERT(osfs->os_bsize);
475 sb->s_blocksize = osfs->os_bsize;
476 sb->s_blocksize_bits = log2(osfs->os_bsize);
477 sb->s_magic = LL_SUPER_MAGIC;
478 sb->s_maxbytes = MAX_LFS_FILESIZE;
479 sbi->ll_inode_cache_enabled = 1;
480 sbi->ll_namelen = osfs->os_namelen;
481 sbi->ll_mnt.mnt = current->fs->root.mnt;
482 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
484 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
485 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
486 LCONSOLE_INFO("Disabling user_xattr feature because "
487 "it is not supported on the server\n");
488 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
491 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
493 sb->s_flags |= SB_POSIXACL;
495 set_bit(LL_SBI_ACL, sbi->ll_flags);
497 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
499 sb->s_flags &= ~SB_POSIXACL;
501 clear_bit(LL_SBI_ACL, sbi->ll_flags);
504 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
505 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
507 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
508 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
510 if (obd_connect_has_secctx(data))
511 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
513 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
514 if (ll_sb_has_test_dummy_encryption(sb))
515 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
517 sbi->ll_md_exp->exp_obd->obd_name);
518 ll_sbi_set_encrypt(sbi, false);
521 if (ll_sbi_has_name_encrypt(sbi) && !obd_connect_has_name_enc(data)) {
522 struct lustre_sb_info *lsi = s2lsi(sb);
524 if (ll_sb_has_test_dummy_encryption(sb))
525 LCONSOLE_WARN("%s: server %s does not support name encryption, not using it.\n",
527 sbi->ll_md_exp->exp_obd->obd_name);
528 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
529 lsi->lsi_flags &= ~LSI_FILENAME_ENC_B64_OLD_CLI;
530 ll_sbi_set_name_encrypt(sbi, false);
533 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
534 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
535 LCONSOLE_INFO("%s: disabling xattr cache due to "
536 "unknown maximum xattr size.\n", dt);
537 } else if (!sbi->ll_xattr_cache_set) {
538 /* If xattr_cache is already set (no matter 0 or 1)
539 * during processing llog, it won't be enabled here. */
540 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
541 sbi->ll_xattr_cache_enabled = 1;
545 sbi->ll_dt_obd = class_name2obd(dt);
546 if (!sbi->ll_dt_obd) {
547 CERROR("DT %s: not setup or attached\n", dt);
548 GOTO(out_md_fid, err = -ENODEV);
551 /* pass client page size via ocd_grant_blkbits, the server should report
552 * back its backend blocksize for grant calculation purpose */
553 data->ocd_grant_blkbits = PAGE_SHIFT;
555 /* indicate OST features supported by this client */
556 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
557 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
558 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
559 OBD_CONNECT_SRVLOCK |
560 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
561 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
562 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
563 OBD_CONNECT_EINPROGRESS |
564 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
565 OBD_CONNECT_LAYOUTLOCK |
566 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
567 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
568 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
569 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
570 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
571 OBD_CONNECT2_REP_MBITS;
573 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
574 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
576 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
577 * disabled by default, because it can still be enabled on the
578 * fly via /sys. As a consequence, we still need to come to an
579 * agreement on the supported algorithms at connect time
581 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
583 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
584 data->ocd_cksum_types = OBD_CKSUM_ADLER;
586 data->ocd_cksum_types = obd_cksum_types_supported_client();
588 #ifdef HAVE_LRU_RESIZE_SUPPORT
589 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
591 /* always ping even if server suppress_pings */
592 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
593 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
595 if (ll_sbi_has_encrypt(sbi))
596 obd_connect_set_enc(data);
598 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
599 "ocd_grant: %d\n", data->ocd_connect_flags,
600 data->ocd_version, data->ocd_grant);
602 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
603 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
605 data->ocd_brw_size = DT_MAX_BRW_SIZE;
607 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
608 &sbi->ll_sb_uuid, data, sbi->ll_cache);
610 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
611 "recovery, of which this client is not a "
612 "part. Please wait for recovery to "
613 "complete, abort, or time out.\n", dt);
616 CERROR("%s: Cannot connect to %s: rc = %d\n",
617 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
621 if (ll_sbi_has_encrypt(sbi) &&
622 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
623 if (ll_sb_has_test_dummy_encryption(sb))
624 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
626 ll_sbi_set_encrypt(sbi, false);
627 } else if (ll_sb_has_test_dummy_encryption(sb)) {
628 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
631 sbi->ll_dt_exp->exp_connect_data = *data;
633 /* Don't change value if it was specified in the config log */
634 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
635 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
636 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
637 (data->ocd_brw_size >> PAGE_SHIFT));
638 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
639 sbi->ll_ra_info.ra_max_pages_per_file)
640 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
641 sbi->ll_ra_info.ra_max_pages_per_file;
644 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
645 LUSTRE_SEQ_METADATA);
647 CERROR("%s: Can't init data layer FID infrastructure, "
648 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
652 mutex_lock(&sbi->ll_lco.lco_lock);
653 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
654 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
655 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
656 mutex_unlock(&sbi->ll_lco.lco_lock);
658 fid_zero(&sbi->ll_root_fid);
659 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
662 CERROR("cannot mds_connect: rc = %d\n", err);
663 GOTO(out_lock_cn_cb, err);
665 if (!fid_is_sane(&sbi->ll_root_fid)) {
666 CERROR("%s: Invalid root fid "DFID" during mount\n",
667 sbi->ll_md_exp->exp_obd->obd_name,
668 PFID(&sbi->ll_root_fid));
669 GOTO(out_lock_cn_cb, err = -EINVAL);
671 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
673 sb->s_op = &lustre_super_operations;
674 sb->s_xattr = ll_xattr_handlers;
675 #if THREAD_SIZE >= 8192 /*b=17630*/
676 sb->s_export_op = &lustre_export_operations;
678 #ifdef HAVE_LUSTRE_CRYPTO
679 llcrypt_set_ops(sb, &lustre_cryptops);
683 * XXX: move this to after cbd setup? */
684 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
686 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
687 valid |= OBD_MD_FLACL;
689 OBD_ALLOC_PTR(op_data);
691 GOTO(out_lock_cn_cb, err = -ENOMEM);
693 op_data->op_fid1 = sbi->ll_root_fid;
694 op_data->op_mode = 0;
695 op_data->op_valid = valid;
697 err = md_getattr(sbi->ll_md_exp, op_data, &request);
699 /* We need enc ctx info, so reset it in op_data to
700 * prevent it from being freed.
702 encctx = op_data->op_file_encctx;
703 encctxlen = op_data->op_file_encctx_size;
704 op_data->op_file_encctx = NULL;
705 op_data->op_file_encctx_size = 0;
706 OBD_FREE_PTR(op_data);
708 CERROR("%s: md_getattr failed for root: rc = %d\n",
709 sbi->ll_md_exp->exp_obd->obd_name, err);
710 GOTO(out_lock_cn_cb, err);
713 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
714 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
716 CERROR("failed to understand root inode md: rc = %d\n", err);
717 ptlrpc_req_finished(request);
718 GOTO(out_lock_cn_cb, err);
721 LASSERT(fid_is_sane(&sbi->ll_root_fid));
722 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
723 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
724 md_free_lustre_md(sbi->ll_md_exp, &lmd);
728 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
730 CERROR("%s: bad ll_iget() for root: rc = %d\n",
731 sbi->ll_fsname, err);
732 ptlrpc_req_finished(request);
736 err = ll_secctx_name_store(root);
737 if (err < 0 && ll_security_xattr_wanted(root))
738 CWARN("%s: file security contextes not supported: rc = %d\n",
739 sbi->ll_fsname, err);
744 "server returned encryption ctx for root inode "DFID"\n",
745 PFID(&sbi->ll_root_fid));
746 err = ll_set_encflags(root, encctx, encctxlen, true);
748 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
750 PFID(&sbi->ll_root_fid), err);
752 ptlrpc_req_finished(request);
754 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
755 if (sbi->ll_checksum_set) {
756 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
757 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
758 sizeof(checksum), &checksum, NULL);
760 CERROR("%s: Set checksum failed: rc = %d\n",
761 sbi->ll_dt_exp->exp_obd->obd_name, err);
767 sb->s_root = d_make_root(root);
768 if (sb->s_root == NULL) {
770 CERROR("%s: can't make root dentry: rc = %d\n",
771 sbi->ll_fsname, err);
775 sbi->ll_sdev_orig = sb->s_dev;
777 /* We set sb->s_dev equal on all lustre clients in order to support
778 * NFS export clustering. NFSD requires that the FSID be the same
780 /* s_dev is also used in lt_compare() to compare two fs, but that is
781 * only a node-local comparison. */
782 uuid = obd_get_uuid(sbi->ll_md_exp);
784 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
791 if (sbi->ll_dt_obd) {
792 err = sysfs_create_link(&sbi->ll_kset.kobj,
793 &sbi->ll_dt_obd->obd_kset.kobj,
794 sbi->ll_dt_obd->obd_type->typ_name);
796 CERROR("%s: could not register %s in llite: rc = %d\n",
797 dt, sbi->ll_fsname, err);
802 if (sbi->ll_md_obd) {
803 err = sysfs_create_link(&sbi->ll_kset.kobj,
804 &sbi->ll_md_obd->obd_kset.kobj,
805 sbi->ll_md_obd->obd_type->typ_name);
807 CERROR("%s: could not register %s in llite: rc = %d\n",
808 md, sbi->ll_fsname, err);
817 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
819 obd_disconnect(sbi->ll_dt_exp);
820 sbi->ll_dt_exp = NULL;
821 sbi->ll_dt_obd = NULL;
823 obd_fid_fini(sbi->ll_md_exp->exp_obd);
825 obd_disconnect(sbi->ll_md_exp);
826 sbi->ll_md_exp = NULL;
827 sbi->ll_md_obd = NULL;
836 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
840 size = sizeof(*lmmsize);
841 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
842 KEY_MAX_EASIZE, &size, lmmsize);
844 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
845 sbi->ll_dt_exp->exp_obd->obd_name, rc);
849 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
852 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
853 KEY_MAX_EASIZE, &size, lmmsize);
855 CERROR("Get max mdsize error rc %d\n", rc);
857 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
863 * Get the value of the default_easize parameter.
865 * \see client_obd::cl_default_mds_easize
867 * \param[in] sbi superblock info for this filesystem
868 * \param[out] lmmsize pointer to storage location for value
870 * \retval 0 on success
871 * \retval negative negated errno on failure
873 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
878 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
879 KEY_DEFAULT_EASIZE, &size, lmmsize);
881 CERROR("Get default mdsize error rc %d\n", rc);
887 * Set the default_easize parameter to the given value.
889 * \see client_obd::cl_default_mds_easize
891 * \param[in] sbi superblock info for this filesystem
892 * \param[in] lmmsize the size to set
894 * \retval 0 on success
895 * \retval negative negated errno on failure
897 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
901 if (lmmsize < sizeof(struct lov_mds_md) ||
902 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
905 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
906 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
907 sizeof(int), &lmmsize, NULL);
912 static void client_common_put_super(struct super_block *sb)
914 struct ll_sb_info *sbi = ll_s2sbi(sb);
919 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
920 obd_disconnect(sbi->ll_dt_exp);
921 sbi->ll_dt_exp = NULL;
923 ll_debugfs_unregister_super(sb);
925 obd_fid_fini(sbi->ll_md_exp->exp_obd);
926 obd_disconnect(sbi->ll_md_exp);
927 sbi->ll_md_exp = NULL;
932 void ll_kill_super(struct super_block *sb)
934 struct ll_sb_info *sbi;
938 if (!(sb->s_flags & SB_ACTIVE))
942 /* we need restore s_dev from changed for clustred NFS before put_super
943 * because new kernels have cached s_dev and change sb->s_dev in
944 * put_super not affected real removing devices */
946 sb->s_dev = sbi->ll_sdev_orig;
948 /* wait running statahead threads to quit */
949 while (atomic_read(&sbi->ll_sa_running) > 0)
950 schedule_timeout_uninterruptible(
951 cfs_time_seconds(1) >> 3);
957 /* Since we use this table for ll_sbi_flags_seq_show make
958 * sure what you want displayed for a specific token that
959 * is listed more than once below be listed first. For
960 * example we want "checksum" displayed, not "nochecksum"
963 static const match_table_t ll_sbi_flags_name = {
964 {LL_SBI_NOLCK, "nolock"},
965 {LL_SBI_CHECKSUM, "checksum"},
966 {LL_SBI_CHECKSUM, "nochecksum"},
967 {LL_SBI_LOCALFLOCK, "localflock"},
968 {LL_SBI_FLOCK, "flock"},
969 {LL_SBI_FLOCK, "noflock"},
970 {LL_SBI_USER_XATTR, "user_xattr"},
971 {LL_SBI_USER_XATTR, "nouser_xattr"},
972 {LL_SBI_LRU_RESIZE, "lruresize"},
973 {LL_SBI_LRU_RESIZE, "nolruresize"},
974 {LL_SBI_LAZYSTATFS, "lazystatfs"},
975 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
976 {LL_SBI_32BIT_API, "32bitapi"},
977 {LL_SBI_USER_FID2PATH, "user_fid2path"},
978 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
979 {LL_SBI_VERBOSE, "verbose"},
980 {LL_SBI_VERBOSE, "noverbose"},
981 {LL_SBI_ALWAYS_PING, "always_ping"},
982 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
983 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
984 {LL_SBI_ENCRYPT, "encrypt"},
985 {LL_SBI_ENCRYPT, "noencrypt"},
986 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
987 {LL_SBI_NUM_MOUNT_OPT, NULL},
990 {LL_SBI_AGL_ENABLED, "agl"},
991 {LL_SBI_64BIT_HASH, "64bit_hash"},
992 {LL_SBI_LAYOUT_LOCK, "layout"},
993 {LL_SBI_XATTR_CACHE, "xattr_cache"},
994 {LL_SBI_NOROOTSQUASH, "norootsquash"},
995 {LL_SBI_FAST_READ, "fast_read"},
996 {LL_SBI_FILE_SECCTX, "file_secctx"},
997 {LL_SBI_TINY_WRITE, "tiny_write"},
998 {LL_SBI_FILE_HEAT, "file_heat"},
999 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
1000 {LL_SBI_ENCRYPT_NAME, "name_encrypt"},
1003 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
1005 struct super_block *sb = m->private;
1008 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
1011 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
1014 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
1015 if (ll_sbi_flags_name[j].token == i &&
1016 ll_sbi_flags_name[j].pattern) {
1017 seq_printf(m, "%s ",
1018 ll_sbi_flags_name[j].pattern);
1023 seq_puts(m, "\b\n");
1027 /* non-client-specific mount options are parsed in lmd_parse */
1028 static int ll_options(char *options, struct super_block *sb)
1030 struct ll_sb_info *sbi = ll_s2sbi(sb);
1031 char *s2, *s1, *opts;
1038 /* Don't stomp on lmd_opts */
1039 opts = kstrdup(options, GFP_KERNEL);
1045 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1047 while ((s1 = strsep(&opts, ",")) != NULL) {
1048 substring_t args[MAX_OPT_ARGS];
1049 bool turn_off = false;
1055 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1057 if (strncmp(s1, "no", 2) == 0)
1061 * Initialize args struct so we know whether arg was
1062 * found; some options take optional arguments.
1065 args[0].from = NULL;
1066 token = match_token(s1, ll_sbi_flags_name, args);
1067 if (token == LL_SBI_NUM_MOUNT_OPT) {
1068 if (match_wildcard("context", s1) ||
1069 match_wildcard("fscontext", s1) ||
1070 match_wildcard("defcontext", s1) ||
1071 match_wildcard("rootcontext",s1))
1074 LCONSOLE_ERROR_MSG(0x152,
1075 "Unknown option '%s', won't mount.\n",
1082 case LL_SBI_32BIT_API:
1083 case LL_SBI_64BIT_HASH:
1084 case LL_SBI_ALWAYS_PING:
1085 set_bit(token, sbi->ll_flags);
1089 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1091 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1093 set_bit(token, sbi->ll_flags);
1096 case LL_SBI_LOCALFLOCK:
1097 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1098 set_bit(token, sbi->ll_flags);
1101 case LL_SBI_CHECKSUM:
1102 sbi->ll_checksum_set = 1;
1104 case LL_SBI_USER_XATTR:
1105 case LL_SBI_USER_FID2PATH:
1106 case LL_SBI_LRU_RESIZE:
1107 case LL_SBI_LAZYSTATFS:
1108 case LL_SBI_VERBOSE:
1110 clear_bit(token, sbi->ll_flags);
1112 set_bit(token, sbi->ll_flags);
1114 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1115 #ifdef HAVE_LUSTRE_CRYPTO
1116 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1117 set_bit(token, sbi->ll_flags);
1119 struct lustre_sb_info *lsi = s2lsi(sb);
1121 err = llcrypt_set_test_dummy_encryption(sb, &args[0],
1122 &lsi->lsi_dummy_enc_ctx);
1128 "Can't change test_dummy_encryption");
1129 else if (err == -EINVAL)
1131 "Value of option \"%s\" unrecognized",
1135 "Error processing option \"%s\" [%d]",
1140 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1144 case LL_SBI_ENCRYPT:
1145 #ifdef HAVE_LUSTRE_CRYPTO
1147 clear_bit(token, sbi->ll_flags);
1149 set_bit(token, sbi->ll_flags);
1151 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1154 case LL_SBI_FOREIGN_SYMLINK:
1155 /* non-default prefix provided ? */
1160 /* path must be absolute */
1161 if (args->from[0] != '/') {
1162 LCONSOLE_ERROR_MSG(0x152,
1163 "foreign prefix '%s' must be an absolute path\n",
1168 old_len = sbi->ll_foreign_symlink_prefix_size;
1169 old = sbi->ll_foreign_symlink_prefix;
1170 /* alloc for path length and '\0' */
1171 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1172 if (!sbi->ll_foreign_symlink_prefix) {
1173 /* restore previous */
1174 sbi->ll_foreign_symlink_prefix = old;
1175 sbi->ll_foreign_symlink_prefix_size =
1179 sbi->ll_foreign_symlink_prefix_size =
1180 args->to - args->from + 1;
1181 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1182 sbi->ll_foreign_symlink_prefix_size,
1185 OBD_FREE(old, old_len);
1187 /* enable foreign symlink support */
1188 set_bit(token, sbi->ll_flags);
1190 LCONSOLE_ERROR_MSG(0x152,
1191 "invalid %s option\n", s1);
1202 void ll_lli_init(struct ll_inode_info *lli)
1204 lli->lli_inode_magic = LLI_INODE_MAGIC;
1206 rwlock_init(&lli->lli_lock);
1207 lli->lli_posix_acl = NULL;
1208 /* Do not set lli_fid, it has been initialized already. */
1209 fid_zero(&lli->lli_pfid);
1210 lli->lli_mds_read_och = NULL;
1211 lli->lli_mds_write_och = NULL;
1212 lli->lli_mds_exec_och = NULL;
1213 lli->lli_open_fd_read_count = 0;
1214 lli->lli_open_fd_write_count = 0;
1215 lli->lli_open_fd_exec_count = 0;
1216 mutex_init(&lli->lli_och_mutex);
1217 spin_lock_init(&lli->lli_agl_lock);
1218 spin_lock_init(&lli->lli_layout_lock);
1219 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1220 lli->lli_clob = NULL;
1222 init_rwsem(&lli->lli_xattrs_list_rwsem);
1223 mutex_init(&lli->lli_xattrs_enq_lock);
1225 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1226 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1227 lli->lli_opendir_key = NULL;
1228 lli->lli_sai = NULL;
1229 spin_lock_init(&lli->lli_sa_lock);
1230 lli->lli_opendir_pid = 0;
1231 lli->lli_sa_enabled = 0;
1232 init_rwsem(&lli->lli_lsm_sem);
1234 mutex_init(&lli->lli_size_mutex);
1235 mutex_init(&lli->lli_setattr_mutex);
1236 lli->lli_symlink_name = NULL;
1237 ll_trunc_sem_init(&lli->lli_trunc_sem);
1238 range_lock_tree_init(&lli->lli_write_tree);
1239 init_rwsem(&lli->lli_glimpse_sem);
1240 lli->lli_glimpse_time = ktime_set(0, 0);
1241 INIT_LIST_HEAD(&lli->lli_agl_list);
1242 lli->lli_agl_index = 0;
1243 lli->lli_async_rc = 0;
1244 spin_lock_init(&lli->lli_heat_lock);
1245 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1246 lli->lli_heat_flags = 0;
1247 mutex_init(&lli->lli_pcc_lock);
1248 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1249 lli->lli_pcc_inode = NULL;
1250 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1251 lli->lli_pcc_generation = 0;
1252 mutex_init(&lli->lli_group_mutex);
1253 lli->lli_group_users = 0;
1254 lli->lli_group_gid = 0;
1256 mutex_init(&lli->lli_layout_mutex);
1257 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1258 /* ll_cl_context initialize */
1259 INIT_LIST_HEAD(&lli->lli_lccs);
1260 seqlock_init(&lli->lli_page_inv_lock);
1263 #define MAX_STRING_SIZE 128
1265 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1266 #ifndef HAVE_BDI_CAP_MAP_COPY
1267 # define BDI_CAP_MAP_COPY 0
1270 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1272 struct lustre_sb_info *lsi = s2lsi(sb);
1273 char buf[MAX_STRING_SIZE];
1277 err = bdi_init(&lsi->lsi_bdi);
1281 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1282 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1283 lsi->lsi_bdi.name = "lustre";
1284 va_start(args, fmt);
1285 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1287 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1290 sb->s_bdi = &lsi->lsi_bdi;
1294 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1296 int ll_fill_super(struct super_block *sb)
1298 struct lustre_profile *lprof = NULL;
1299 struct lustre_sb_info *lsi = s2lsi(sb);
1300 struct ll_sb_info *sbi = NULL;
1301 char *dt = NULL, *md = NULL;
1302 char *profilenm = get_profile_name(sb);
1303 struct config_llog_instance *cfg;
1304 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1305 const int instlen = LUSTRE_MAXINSTANCE + 2;
1306 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1307 char name[MAX_STRING_SIZE];
1316 /* for ASLR, to map between cfg_instance and hashed ptr */
1317 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1318 profilenm, cfg_instance, sb);
1320 OBD_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1324 GOTO(out_free_cfg, err = -ENOMEM);
1326 /* client additional sb info */
1327 lsi->lsi_llsbi = sbi = ll_init_sbi();
1329 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1331 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1333 GOTO(out_free_cfg, err);
1335 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1336 #ifdef CONFIG_LL_ENCRYPTION
1337 if (ll_sb_has_test_dummy_encryption(sb))
1338 /* enable filename encryption by default for dummy enc mode */
1339 lsi->lsi_flags |= LSI_FILENAME_ENC;
1341 /* filename encryption is disabled by default */
1342 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1345 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1346 sb->s_d_op = &ll_d_ops;
1349 generate_random_uuid(uuid.b);
1350 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1352 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1355 len = strlen(profilenm);
1356 ptr = strrchr(profilenm, '-');
1357 if (ptr && (strcmp(ptr, "-client") == 0))
1360 if (len > LUSTRE_MAXFSNAME) {
1361 if (unlikely(len >= MAX_STRING_SIZE))
1362 len = MAX_STRING_SIZE - 1;
1363 strncpy(name, profilenm, len);
1365 err = -ENAMETOOLONG;
1366 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1367 name, LUSTRE_MAXFSNAME, err);
1368 GOTO(out_free_cfg, err);
1370 strncpy(sbi->ll_fsname, profilenm, len);
1371 sbi->ll_fsname[len] = '\0';
1374 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1375 profilenm, cfg_instance);
1377 err = super_setup_bdi_name(sb, "%s", name);
1379 GOTO(out_free_cfg, err);
1381 /* disable kernel readahead */
1382 sb->s_bdi->ra_pages = 0;
1383 #ifdef HAVE_BDI_IO_PAGES
1384 sb->s_bdi->io_pages = 0;
1387 /* Call ll_debugfs_register_super() before lustre_process_log()
1388 * so that "llite.*.*" params can be processed correctly.
1390 err = ll_debugfs_register_super(sb, name);
1392 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1393 sbi->ll_fsname, err);
1397 /* The cfg_instance is a value unique to this super, in case some
1398 * joker tries to mount the same fs at two mount points.
1400 cfg->cfg_instance = cfg_instance;
1401 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1402 cfg->cfg_callback = class_config_llog_handler;
1403 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1404 /* set up client obds */
1405 err = lustre_process_log(sb, profilenm, cfg);
1407 GOTO(out_debugfs, err);
1409 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1410 lprof = class_get_profile(profilenm);
1411 if (lprof == NULL) {
1412 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1413 " read from the MGS. Does that filesystem "
1414 "exist?\n", profilenm);
1415 GOTO(out_debugfs, err = -EINVAL);
1417 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1418 lprof->lp_md, lprof->lp_dt);
1420 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1421 OBD_ALLOC(dt, dt_len);
1423 GOTO(out_profile, err = -ENOMEM);
1424 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1426 md_len = strlen(lprof->lp_md) + instlen + 2;
1427 OBD_ALLOC(md, md_len);
1429 GOTO(out_free_dt, err = -ENOMEM);
1430 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1432 /* connections, registrations, sb setup */
1433 err = client_common_fill_super(sb, md, dt);
1435 GOTO(out_free_md, err);
1437 sbi->ll_client_common_fill_super_succeeded = 1;
1441 OBD_FREE(md, md_len);
1444 OBD_FREE(dt, dt_len);
1447 class_put_profile(lprof);
1450 ll_debugfs_unregister_super(sb);
1457 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1458 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1459 sb->s_flags & SB_RDONLY ? " read-only" : "");
1461 } /* ll_fill_super */
1463 void ll_put_super(struct super_block *sb)
1465 struct config_llog_instance cfg, params_cfg;
1466 struct obd_device *obd;
1467 struct lustre_sb_info *lsi = s2lsi(sb);
1468 struct ll_sb_info *sbi = ll_s2sbi(sb);
1469 char *profilenm = get_profile_name(sb);
1470 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1472 int next, force = 1, rc = 0;
1476 GOTO(out_no_sbi, 0);
1478 /* Should replace instance_id with something better for ASLR */
1479 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1480 profilenm, cfg_instance, sb);
1482 cfg.cfg_instance = cfg_instance;
1483 lustre_end_log(sb, profilenm, &cfg);
1485 params_cfg.cfg_instance = cfg_instance;
1486 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1488 if (sbi->ll_md_exp) {
1489 obd = class_exp2obd(sbi->ll_md_exp);
1491 force = obd->obd_force;
1494 /* Wait for unstable pages to be committed to stable storage */
1496 rc = l_wait_event_abortable(
1497 sbi->ll_cache->ccc_unstable_waitq,
1498 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1501 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1502 if (force == 0 && rc != -ERESTARTSYS)
1503 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1505 /* We need to set force before the lov_disconnect in
1506 * lustre_common_put_super, since l_d cleans up osc's as well.
1510 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1512 obd->obd_force = force;
1516 if (sbi->ll_client_common_fill_super_succeeded) {
1517 /* Only if client_common_fill_super succeeded */
1518 client_common_put_super(sb);
1521 /* imitate failed cleanup */
1522 if (OBD_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1526 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1527 class_manual_cleanup(obd);
1530 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1531 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1534 class_del_profile(profilenm);
1536 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1537 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1538 bdi_destroy(&lsi->lsi_bdi);
1539 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1543 llcrypt_free_dummy_context(&lsi->lsi_dummy_enc_ctx);
1545 lsi->lsi_llsbi = NULL;
1547 lustre_common_put_super(sb);
1549 cl_env_cache_purge(~0);
1552 } /* client_put_super */
1554 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1556 struct inode *inode = NULL;
1558 /* NOTE: we depend on atomic igrab() -bzzz */
1559 lock_res_and_lock(lock);
1560 if (lock->l_resource->lr_lvb_inode) {
1561 struct ll_inode_info * lli;
1562 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1563 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1564 inode = igrab(lock->l_resource->lr_lvb_inode);
1566 inode = lock->l_resource->lr_lvb_inode;
1567 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1568 D_WARNING, lock, "lr_lvb_inode %p is "
1569 "bogus: magic %08x",
1570 lock->l_resource->lr_lvb_inode,
1571 lli->lli_inode_magic);
1575 unlock_res_and_lock(lock);
1579 void ll_dir_clear_lsm_md(struct inode *inode)
1581 struct ll_inode_info *lli = ll_i2info(inode);
1583 LASSERT(S_ISDIR(inode->i_mode));
1585 if (lli->lli_lsm_md) {
1586 lmv_free_memmd(lli->lli_lsm_md);
1587 lli->lli_lsm_md = NULL;
1590 if (lli->lli_default_lsm_md) {
1591 lmv_free_memmd(lli->lli_default_lsm_md);
1592 lli->lli_default_lsm_md = NULL;
1596 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1597 const struct lu_fid *fid,
1598 struct lustre_md *md)
1600 struct ll_sb_info *sbi = ll_s2sbi(sb);
1601 struct ll_inode_info *lli;
1602 struct mdt_body *body = md->body;
1603 struct inode *inode;
1609 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1610 inode = iget_locked(sb, ino);
1611 if (inode == NULL) {
1612 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1613 sbi->ll_fsname, PFID(fid));
1614 RETURN(ERR_PTR(-ENOENT));
1617 lli = ll_i2info(inode);
1618 if (inode->i_state & I_NEW) {
1619 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1620 (body->mbo_mode & S_IFMT);
1621 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1624 inode->i_mtime.tv_sec = 0;
1625 inode->i_atime.tv_sec = 0;
1626 inode->i_ctime.tv_sec = 0;
1629 #ifdef HAVE_BACKING_DEV_INFO
1630 /* initializing backing dev info. */
1631 inode->i_mapping->backing_dev_info =
1632 &s2lsi(inode->i_sb)->lsi_bdi;
1634 inode->i_op = &ll_dir_inode_operations;
1635 inode->i_fop = &ll_dir_operations;
1636 lli->lli_fid = *fid;
1639 /* master object FID */
1640 lli->lli_pfid = body->mbo_fid1;
1641 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1642 lli, PFID(fid), PFID(&lli->lli_pfid));
1643 unlock_new_inode(inode);
1645 /* in directory restripe/auto-split, a directory will be
1646 * transformed to a stripe if it's plain, set its pfid here,
1647 * otherwise ll_lock_cancel_bits() can't find the master inode.
1649 lli->lli_pfid = body->mbo_fid1;
1655 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1658 struct lmv_stripe_md *lsm = md->lmv;
1659 struct ll_inode_info *lli = ll_i2info(inode);
1662 LASSERT(lsm != NULL);
1664 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1665 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1666 lsm_md_dump(D_INODE, lsm);
1668 if (!lmv_dir_striped(lsm))
1671 /* XXX sigh, this lsm_root initialization should be in
1672 * LMV layer, but it needs ll_iget right now, so we
1673 * put this here right now. */
1674 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1675 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1676 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1678 if (!fid_is_sane(fid))
1681 /* Unfortunately ll_iget will call ll_update_inode,
1682 * where the initialization of slave inode is slightly
1683 * different, so it reset lsm_md to NULL to avoid
1684 * initializing lsm for slave inode. */
1685 lsm->lsm_md_oinfo[i].lmo_root =
1686 ll_iget_anon_dir(inode->i_sb, fid, md);
1687 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1688 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1690 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1692 iput(lsm->lsm_md_oinfo[i].lmo_root);
1693 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1699 lli->lli_lsm_md = lsm;
1704 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1706 struct ll_inode_info *lli = ll_i2info(inode);
1710 if (!md->default_lmv) {
1711 /* clear default lsm */
1712 if (lli->lli_default_lsm_md) {
1713 down_write(&lli->lli_lsm_sem);
1714 if (lli->lli_default_lsm_md) {
1715 lmv_free_memmd(lli->lli_default_lsm_md);
1716 lli->lli_default_lsm_md = NULL;
1718 lli->lli_inherit_depth = 0;
1719 up_write(&lli->lli_lsm_sem);
1724 if (lli->lli_default_lsm_md) {
1725 /* do nonthing if default lsm isn't changed */
1726 down_read(&lli->lli_lsm_sem);
1727 if (lli->lli_default_lsm_md &&
1728 lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1729 up_read(&lli->lli_lsm_sem);
1732 up_read(&lli->lli_lsm_sem);
1735 down_write(&lli->lli_lsm_sem);
1736 if (lli->lli_default_lsm_md)
1737 lmv_free_memmd(lli->lli_default_lsm_md);
1738 lli->lli_default_lsm_md = md->default_lmv;
1739 lsm_md_dump(D_INODE, md->default_lmv);
1740 md->default_lmv = NULL;
1741 up_write(&lli->lli_lsm_sem);
1745 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1747 struct ll_inode_info *lli = ll_i2info(inode);
1748 struct lmv_stripe_md *lsm = md->lmv;
1749 struct cl_attr *attr;
1754 LASSERT(S_ISDIR(inode->i_mode));
1755 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1756 PFID(ll_inode2fid(inode)));
1758 /* update default LMV */
1759 if (md->default_lmv)
1760 ll_update_default_lsm_md(inode, md);
1762 /* after dir migration/restripe, a stripe may be turned into a
1763 * directory, in this case, zero out its lli_pfid.
1765 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1766 fid_zero(&lli->lli_pfid);
1769 * no striped information from request, lustre_md from req does not
1770 * include stripeEA, see ll_md_setattr()
1776 * normally dir layout doesn't change, only take read lock to check
1777 * that to avoid blocking other MD operations.
1779 down_read(&lli->lli_lsm_sem);
1781 /* some current lookup initialized lsm, and unchanged */
1782 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1783 GOTO(unlock, rc = 0);
1785 /* if dir layout doesn't match, check whether version is increased,
1786 * which means layout is changed, this happens in dir split/merge and
1789 * foreign LMV should not change.
1791 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1792 lsm->lsm_md_layout_version <=
1793 lli->lli_lsm_md->lsm_md_layout_version) {
1794 CERROR("%s: "DFID" dir layout mismatch:\n",
1795 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1796 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1797 lsm_md_dump(D_ERROR, lsm);
1798 GOTO(unlock, rc = -EINVAL);
1801 up_read(&lli->lli_lsm_sem);
1802 down_write(&lli->lli_lsm_sem);
1803 /* clear existing lsm */
1804 if (lli->lli_lsm_md) {
1805 lmv_free_memmd(lli->lli_lsm_md);
1806 lli->lli_lsm_md = NULL;
1809 rc = ll_init_lsm_md(inode, md);
1811 up_write(&lli->lli_lsm_sem);
1815 /* md_merge_attr() may take long, since lsm is already set, switch to
1818 downgrade_write(&lli->lli_lsm_sem);
1820 /* set md->lmv to NULL, so the following free lustre_md will not free
1825 if (!lmv_dir_striped(lli->lli_lsm_md))
1826 GOTO(unlock, rc = 0);
1828 OBD_ALLOC_PTR(attr);
1830 GOTO(unlock, rc = -ENOMEM);
1832 /* validate the lsm */
1833 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1834 ll_md_blocking_ast);
1836 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1837 md->body->mbo_nlink = attr->cat_nlink;
1838 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1839 md->body->mbo_size = attr->cat_size;
1840 if (md->body->mbo_valid & OBD_MD_FLATIME)
1841 md->body->mbo_atime = attr->cat_atime;
1842 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1843 md->body->mbo_ctime = attr->cat_ctime;
1844 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1845 md->body->mbo_mtime = attr->cat_mtime;
1851 up_read(&lli->lli_lsm_sem);
1856 void ll_clear_inode(struct inode *inode)
1858 struct ll_inode_info *lli = ll_i2info(inode);
1859 struct ll_sb_info *sbi = ll_i2sbi(inode);
1863 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1864 PFID(ll_inode2fid(inode)), inode);
1866 if (S_ISDIR(inode->i_mode)) {
1867 /* these should have been cleared in ll_file_release */
1868 LASSERT(lli->lli_opendir_key == NULL);
1869 LASSERT(lli->lli_sai == NULL);
1870 LASSERT(lli->lli_opendir_pid == 0);
1872 pcc_inode_free(inode);
1875 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1877 LASSERT(!lli->lli_open_fd_write_count);
1878 LASSERT(!lli->lli_open_fd_read_count);
1879 LASSERT(!lli->lli_open_fd_exec_count);
1881 if (lli->lli_mds_write_och)
1882 ll_md_real_close(inode, FMODE_WRITE);
1883 if (lli->lli_mds_exec_och)
1884 ll_md_real_close(inode, FMODE_EXEC);
1885 if (lli->lli_mds_read_och)
1886 ll_md_real_close(inode, FMODE_READ);
1888 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1889 OBD_FREE(lli->lli_symlink_name,
1890 strlen(lli->lli_symlink_name) + 1);
1891 lli->lli_symlink_name = NULL;
1894 ll_xattr_cache_destroy(inode);
1896 forget_all_cached_acls(inode);
1898 lli->lli_inode_magic = LLI_INODE_DEAD;
1900 if (S_ISDIR(inode->i_mode))
1901 ll_dir_clear_lsm_md(inode);
1902 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1903 LASSERT(list_empty(&lli->lli_agl_list));
1906 * XXX This has to be done before lsm is freed below, because
1907 * cl_object still uses inode lsm.
1909 cl_inode_fini(inode);
1911 llcrypt_put_encryption_info(inode);
1916 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1918 struct lustre_md md;
1919 struct inode *inode = dentry->d_inode;
1920 struct ll_sb_info *sbi = ll_i2sbi(inode);
1921 struct ptlrpc_request *request = NULL;
1926 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1927 LUSTRE_OPC_ANY, NULL);
1928 if (IS_ERR(op_data))
1929 RETURN(PTR_ERR(op_data));
1931 /* If this is a chgrp of a regular file, we want to reserve enough
1932 * quota to cover the entire file size.
1934 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1935 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1936 from_kgid(&init_user_ns, inode->i_gid)) {
1937 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1938 op_data->op_attr_blocks = inode->i_blocks;
1942 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1944 ptlrpc_req_finished(request);
1945 if (rc == -ENOENT) {
1947 /* Unlinked special device node? Or just a race?
1948 * Pretend we done everything. */
1949 if (!S_ISREG(inode->i_mode) &&
1950 !S_ISDIR(inode->i_mode)) {
1951 ia_valid = op_data->op_attr.ia_valid;
1952 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1953 rc = simple_setattr(&init_user_ns, dentry,
1955 op_data->op_attr.ia_valid = ia_valid;
1957 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1958 CERROR("md_setattr fails: rc = %d\n", rc);
1963 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1964 sbi->ll_md_exp, &md);
1966 ptlrpc_req_finished(request);
1970 ia_valid = op_data->op_attr.ia_valid;
1971 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1972 * cache is not cleared yet. */
1973 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1974 if (S_ISREG(inode->i_mode))
1976 rc = simple_setattr(&init_user_ns, dentry, &op_data->op_attr);
1977 if (S_ISREG(inode->i_mode))
1978 inode_unlock(inode);
1979 op_data->op_attr.ia_valid = ia_valid;
1981 rc = ll_update_inode(inode, &md);
1982 ptlrpc_req_finished(request);
1988 * Zero portion of page that is part of @inode.
1989 * This implies, if necessary:
1990 * - taking cl_lock on range corresponding to concerned page
1991 * - grabbing vm page
1992 * - associating cl_page
1993 * - proceeding to clio read
1994 * - zeroing range in page
1995 * - proceeding to cl_page flush
1996 * - releasing cl_lock
1998 * \param[in] inode inode
1999 * \param[in] index page index
2000 * \param[in] offset offset in page to start zero from
2001 * \param[in] len len to zero
2003 * \retval 0 on success
2004 * \retval negative errno on failure
2006 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
2009 struct ll_inode_info *lli = ll_i2info(inode);
2010 struct cl_object *clob = lli->lli_clob;
2012 struct lu_env *env = NULL;
2013 struct cl_io *io = NULL;
2014 struct cl_page *clpage = NULL;
2015 struct page *vmpage = NULL;
2016 unsigned from = index << PAGE_SHIFT;
2017 struct cl_lock *lock = NULL;
2018 struct cl_lock_descr *descr = NULL;
2019 struct cl_2queue *queue = NULL;
2020 struct cl_sync_io *anchor = NULL;
2021 bool holdinglock = false;
2026 env = cl_env_get(&refcheck);
2028 RETURN(PTR_ERR(env));
2030 io = vvp_env_thread_io(env);
2032 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2036 lock = vvp_env_lock(env);
2037 descr = &lock->cll_descr;
2038 descr->cld_obj = io->ci_obj;
2039 descr->cld_start = cl_index(io->ci_obj, from);
2040 descr->cld_end = cl_index(io->ci_obj, from + PAGE_SIZE - 1);
2041 descr->cld_mode = CLM_WRITE;
2042 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2044 /* request lock for page */
2045 rc = cl_lock_request(env, io, lock);
2046 /* -ECANCELED indicates a matching lock with a different extent
2047 * was already present, and -EEXIST indicates a matching lock
2048 * on exactly the same extent was already present.
2049 * In both cases it means we are covered.
2051 if (rc == -ECANCELED || rc == -EEXIST)
2059 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2061 GOTO(rellock, rc = -EOPNOTSUPP);
2063 if (!PageDirty(vmpage)) {
2064 /* associate cl_page */
2065 clpage = cl_page_find(env, clob, vmpage->index,
2066 vmpage, CPT_CACHEABLE);
2068 GOTO(pagefini, rc = PTR_ERR(clpage));
2070 cl_page_assume(env, io, clpage);
2073 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2074 !PageWriteback(vmpage)) {
2076 /* Set PagePrivate2 to detect special case of empty page
2077 * in osc_brw_fini_request().
2078 * It is also used to tell ll_io_read_page() that we do not
2079 * want the vmpage to be unlocked.
2081 SetPagePrivate2(vmpage);
2082 rc = ll_io_read_page(env, io, clpage, NULL);
2083 if (!PagePrivate2(vmpage)) {
2084 /* PagePrivate2 was cleared in osc_brw_fini_request()
2085 * meaning we read an empty page. In this case, in order
2086 * to avoid allocating unnecessary block in truncated
2087 * file, we must not zero and write as below. Subsequent
2088 * server-side truncate will handle things correctly.
2090 cl_page_unassume(env, io, clpage);
2091 GOTO(clpfini, rc = 0);
2093 ClearPagePrivate2(vmpage);
2098 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2099 * the vmpage, so we are good to proceed and zero range in page.
2101 zero_user(vmpage, offset, len);
2103 if (holdinglock && clpage) {
2104 /* explicitly write newly modified page */
2105 queue = &io->ci_queue;
2106 cl_2queue_init(queue);
2107 anchor = &vvp_env_info(env)->vti_anchor;
2108 cl_sync_io_init(anchor, 1);
2109 clpage->cp_sync_io = anchor;
2110 cl_page_list_add(&queue->c2_qin, clpage, true);
2111 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2113 GOTO(queuefini1, rc);
2114 rc = cl_sync_io_wait(env, anchor, 0);
2116 GOTO(queuefini2, rc);
2117 cl_page_assume(env, io, clpage);
2120 cl_2queue_discard(env, io, queue);
2122 cl_2queue_disown(env, queue);
2123 cl_2queue_fini(env, queue);
2128 cl_page_put(env, clpage);
2130 unlock_page(vmpage);
2134 cl_lock_release(env, lock);
2136 cl_io_fini(env, io);
2139 cl_env_put(env, &refcheck);
2145 * Get reference file from volatile file name.
2146 * Volatile file name may look like:
2147 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2148 * where fd is opened descriptor of reference file.
2150 * \param[in] volatile_name volatile file name
2151 * \param[in] volatile_len volatile file name length
2152 * \param[out] ref_file pointer to struct file of reference file
2154 * \retval 0 on success
2155 * \retval negative errno on failure
2157 int volatile_ref_file(const char *volatile_name, int volatile_len,
2158 struct file **ref_file)
2160 char *p, *q, *fd_str;
2163 p = strnstr(volatile_name, ":fd=", volatile_len);
2164 if (!p || strlen(p + 4) == 0)
2167 q = strchrnul(p + 4, ':');
2168 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2171 rc = kstrtouint(fd_str, 10, &fd);
2176 *ref_file = fget(fd);
2182 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2183 * object(s) determine the file size and mtime. Otherwise, the MDS will
2184 * keep these values until such a time that objects are allocated for it.
2185 * We do the MDS operations first, as it is checking permissions for us.
2186 * We don't to the MDS RPC if there is nothing that we want to store there,
2187 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2188 * going to do an RPC anyways.
2190 * If we are doing a truncate, we will send the mtime and ctime updates
2191 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2192 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2195 * In case of HSMimport, we only set attr on MDS.
2197 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2198 enum op_xvalid xvalid, bool hsm_import)
2200 struct inode *inode = dentry->d_inode;
2201 struct ll_inode_info *lli = ll_i2info(inode);
2202 struct md_op_data *op_data = NULL;
2203 ktime_t kstart = ktime_get();
2208 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2209 "valid %x, hsm_import %d\n",
2210 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2211 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2214 if (attr->ia_valid & ATTR_SIZE) {
2215 /* Check new size against VFS/VM file size limit and rlimit */
2216 rc = inode_newsize_ok(inode, attr->ia_size);
2220 /* The maximum Lustre file size is variable, based on the
2221 * OST maximum object size and number of stripes. This
2222 * needs another check in addition to the VFS check above. */
2223 if (attr->ia_size > ll_file_maxbytes(inode)) {
2224 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2225 PFID(&lli->lli_fid), attr->ia_size,
2226 ll_file_maxbytes(inode));
2230 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2233 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2234 if (attr->ia_valid & TIMES_SET_FLAGS) {
2235 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2236 !capable(CAP_FOWNER))
2240 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2241 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2242 (attr->ia_valid & ATTR_CTIME)) {
2243 attr->ia_ctime = current_time(inode);
2244 xvalid |= OP_XVALID_CTIME_SET;
2246 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2247 (attr->ia_valid & ATTR_ATIME)) {
2248 attr->ia_atime = current_time(inode);
2249 attr->ia_valid |= ATTR_ATIME_SET;
2251 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2252 (attr->ia_valid & ATTR_MTIME)) {
2253 attr->ia_mtime = current_time(inode);
2254 attr->ia_valid |= ATTR_MTIME_SET;
2257 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2258 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2259 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2260 ktime_get_real_seconds());
2262 if (S_ISREG(inode->i_mode))
2263 inode_unlock(inode);
2265 /* We always do an MDS RPC, even if we're only changing the size;
2266 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2268 OBD_ALLOC_PTR(op_data);
2269 if (op_data == NULL)
2270 GOTO(out, rc = -ENOMEM);
2272 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2273 /* If we are changing file size, file content is
2274 * modified, flag it.
2276 xvalid |= OP_XVALID_OWNEROVERRIDE;
2277 op_data->op_bias |= MDS_DATA_MODIFIED;
2278 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2281 if (attr->ia_valid & ATTR_FILE) {
2282 struct ll_file_data *fd = attr->ia_file->private_data;
2284 if (fd->fd_lease_och)
2285 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2288 op_data->op_attr = *attr;
2289 op_data->op_xvalid = xvalid;
2291 rc = ll_md_setattr(dentry, op_data);
2295 if (!S_ISREG(inode->i_mode) || hsm_import)
2298 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2299 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2300 xvalid & OP_XVALID_CTIME_SET) {
2301 bool cached = false;
2303 rc = pcc_inode_setattr(inode, attr, &cached);
2306 CERROR("%s: PCC inode "DFID" setattr failed: "
2308 ll_i2sbi(inode)->ll_fsname,
2309 PFID(&lli->lli_fid), rc);
2313 unsigned int flags = 0;
2315 /* For truncate and utimes sending attributes to OSTs,
2316 * setting mtime/atime to the past will be performed
2317 * under PW [0:EOF] extent lock (new_size:EOF for
2318 * truncate). It may seem excessive to send mtime/atime
2319 * updates to OSTs when not setting times to past, but
2320 * it is necessary due to possible time
2321 * de-synchronization between MDT inode and OST objects
2323 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2324 xvalid |= OP_XVALID_FLAGS;
2325 flags = LUSTRE_ENCRYPT_FL;
2326 /* Call to ll_io_zero_page is not necessary if
2327 * truncating on PAGE_SIZE boundary, because
2328 * whole pages will be wiped.
2329 * In case of Direct IO, all we need is to set
2332 if (attr->ia_valid & ATTR_SIZE &&
2333 attr->ia_size & ~PAGE_MASK &&
2334 !(attr->ia_valid & ATTR_FILE &&
2335 attr->ia_file->f_flags & O_DIRECT)) {
2337 attr->ia_size & (PAGE_SIZE - 1);
2339 rc = ll_io_zero_page(inode,
2340 attr->ia_size >> PAGE_SHIFT,
2341 offset, PAGE_SIZE - offset);
2345 /* If encrypted volatile file without the key,
2346 * we need to fetch size from reference file,
2347 * and set it on OST objects. This happens when
2348 * migrating or extending an encrypted file
2351 if (filename_is_volatile(dentry->d_name.name,
2354 llcrypt_require_key(inode) == -ENOKEY) {
2355 struct file *ref_file;
2356 struct inode *ref_inode;
2357 struct ll_inode_info *ref_lli;
2358 struct cl_object *ref_obj;
2359 struct cl_attr ref_attr = { 0 };
2363 rc = volatile_ref_file(
2364 dentry->d_name.name,
2370 ref_inode = file_inode(ref_file);
2373 GOTO(out, rc = -EINVAL);
2376 env = cl_env_get(&refcheck);
2378 GOTO(out, rc = PTR_ERR(env));
2380 ref_lli = ll_i2info(ref_inode);
2381 ref_obj = ref_lli->lli_clob;
2382 cl_object_attr_lock(ref_obj);
2383 rc = cl_object_attr_get(env, ref_obj,
2385 cl_object_attr_unlock(ref_obj);
2386 cl_env_put(env, &refcheck);
2391 attr->ia_valid |= ATTR_SIZE;
2392 attr->ia_size = ref_attr.cat_size;
2395 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2399 /* If the file was restored, it needs to set dirty flag.
2401 * We've already sent MDS_DATA_MODIFIED flag in
2402 * ll_md_setattr() for truncate. However, the MDT refuses to
2403 * set the HS_DIRTY flag on released files, so we have to set
2404 * it again if the file has been restored. Please check how
2405 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2407 * Please notice that if the file is not released, the previous
2408 * MDS_DATA_MODIFIED has taken effect and usually
2409 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2410 * This way we can save an RPC for common open + trunc
2412 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2413 struct hsm_state_set hss = {
2414 .hss_valid = HSS_SETMASK,
2415 .hss_setmask = HS_DIRTY,
2419 rc2 = ll_hsm_state_set(inode, &hss);
2420 /* truncate and write can happen at the same time, so that
2421 * the file can be set modified even though the file is not
2422 * restored from released state, and ll_hsm_state_set() is
2423 * not applicable for the file, and rc2 < 0 is normal in this
2426 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2427 PFID(ll_inode2fid(inode)), rc2);
2432 if (op_data != NULL)
2433 ll_finish_md_op_data(op_data);
2435 if (S_ISREG(inode->i_mode)) {
2437 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2438 inode_dio_wait(inode);
2439 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2440 * flag. ll_update_inode (called from ll_md_setattr), clears
2441 * inode flags, so there is a gap where S_NOSEC is not set.
2442 * This can cause a writer to take the i_mutex unnecessarily,
2443 * but this is safe to do and should be rare. */
2444 inode_has_no_xattr(inode);
2448 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2449 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2450 ktime_us_delta(ktime_get(), kstart));
2455 int ll_setattr(struct user_namespace *mnt_userns, struct dentry *de,
2458 int mode = de->d_inode->i_mode;
2459 enum op_xvalid xvalid = 0;
2462 rc = llcrypt_prepare_setattr(de, attr);
2466 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2467 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2468 xvalid |= OP_XVALID_OWNEROVERRIDE;
2470 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2471 (ATTR_SIZE|ATTR_MODE)) &&
2472 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2473 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2474 !(attr->ia_mode & S_ISGID))))
2475 attr->ia_valid |= ATTR_FORCE;
2477 if ((attr->ia_valid & ATTR_MODE) &&
2479 !(attr->ia_mode & S_ISUID) &&
2480 !(attr->ia_valid & ATTR_KILL_SUID))
2481 attr->ia_valid |= ATTR_KILL_SUID;
2483 if ((attr->ia_valid & ATTR_MODE) &&
2484 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2485 !(attr->ia_mode & S_ISGID) &&
2486 !(attr->ia_valid & ATTR_KILL_SGID))
2487 attr->ia_valid |= ATTR_KILL_SGID;
2489 return ll_setattr_raw(de, attr, xvalid, false);
2492 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2495 struct obd_statfs obd_osfs = { 0 };
2500 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2502 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2503 flags |= OBD_STATFS_NODELAY;
2505 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2509 osfs->os_type = LL_SUPER_MAGIC;
2511 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2512 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2514 if (osfs->os_state & OS_STATFS_SUM)
2517 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2518 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2521 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2522 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2525 osfs->os_bsize = obd_osfs.os_bsize;
2526 osfs->os_blocks = obd_osfs.os_blocks;
2527 osfs->os_bfree = obd_osfs.os_bfree;
2528 osfs->os_bavail = obd_osfs.os_bavail;
2530 /* If we have _some_ OSTs, but don't have as many free objects on the
2531 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2532 * to compensate, so that the "inodes in use" number is correct.
2533 * This should be kept in sync with lod_statfs() behaviour.
2535 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2536 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2538 osfs->os_ffree = obd_osfs.os_ffree;
2545 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2547 struct if_quotactl qctl = {
2548 .qc_cmd = LUSTRE_Q_GETQUOTA,
2549 .qc_type = PRJQUOTA,
2550 .qc_valid = QC_GENERAL,
2552 u64 limit, curblock;
2555 qctl.qc_id = ll_i2info(inode)->lli_projid;
2556 ret = quotactl_ioctl(inode->i_sb, &qctl);
2558 /* ignore errors if project ID does not have
2559 * a quota limit or feature unsupported.
2561 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2566 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2567 qctl.qc_dqblk.dqb_bsoftlimit :
2568 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2569 if (limit && sfs->f_blocks > limit) {
2570 curblock = (qctl.qc_dqblk.dqb_curspace +
2571 sfs->f_bsize - 1) / sfs->f_bsize;
2572 sfs->f_blocks = limit;
2573 sfs->f_bfree = sfs->f_bavail =
2574 (sfs->f_blocks > curblock) ?
2575 (sfs->f_blocks - curblock) : 0;
2578 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2579 qctl.qc_dqblk.dqb_isoftlimit :
2580 qctl.qc_dqblk.dqb_ihardlimit;
2581 if (limit && sfs->f_files > limit) {
2582 sfs->f_files = limit;
2583 sfs->f_ffree = (sfs->f_files >
2584 qctl.qc_dqblk.dqb_curinodes) ?
2585 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2591 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2593 struct super_block *sb = de->d_sb;
2594 struct obd_statfs osfs;
2595 __u64 fsid = huge_encode_dev(sb->s_dev);
2596 ktime_t kstart = ktime_get();
2599 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2601 /* Some amount of caching on the client is allowed */
2602 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2606 statfs_unpack(sfs, &osfs);
2608 /* We need to downshift for all 32-bit kernels, because we can't
2609 * tell if the kernel is being called via sys_statfs64() or not.
2610 * Stop before overflowing f_bsize - in which case it is better
2611 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2612 if (sizeof(long) < 8) {
2613 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2616 osfs.os_blocks >>= 1;
2617 osfs.os_bfree >>= 1;
2618 osfs.os_bavail >>= 1;
2622 sfs->f_blocks = osfs.os_blocks;
2623 sfs->f_bfree = osfs.os_bfree;
2624 sfs->f_bavail = osfs.os_bavail;
2625 sfs->f_fsid.val[0] = (__u32)fsid;
2626 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2627 if (ll_i2info(de->d_inode)->lli_projid &&
2628 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2629 return ll_statfs_project(de->d_inode, sfs);
2631 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2632 ktime_us_delta(ktime_get(), kstart));
2637 void ll_inode_size_lock(struct inode *inode)
2639 struct ll_inode_info *lli;
2641 LASSERT(!S_ISDIR(inode->i_mode));
2643 lli = ll_i2info(inode);
2644 mutex_lock(&lli->lli_size_mutex);
2647 void ll_inode_size_unlock(struct inode *inode)
2649 struct ll_inode_info *lli;
2651 lli = ll_i2info(inode);
2652 mutex_unlock(&lli->lli_size_mutex);
2655 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2657 /* do not clear encryption flag */
2658 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2659 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2660 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2661 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2663 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2666 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2668 struct ll_inode_info *lli = ll_i2info(inode);
2669 struct mdt_body *body = md->body;
2670 struct ll_sb_info *sbi = ll_i2sbi(inode);
2674 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2675 rc = cl_file_inode_init(inode, md);
2680 if (S_ISDIR(inode->i_mode)) {
2681 rc = ll_update_lsm_md(inode, md);
2686 if (body->mbo_valid & OBD_MD_FLACL)
2687 lli_replace_acl(lli, md);
2689 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2690 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2691 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2693 if (body->mbo_valid & OBD_MD_FLATIME) {
2694 if (body->mbo_atime > inode->i_atime.tv_sec)
2695 inode->i_atime.tv_sec = body->mbo_atime;
2696 lli->lli_atime = body->mbo_atime;
2699 if (body->mbo_valid & OBD_MD_FLMTIME) {
2700 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2702 "setting ino %lu mtime from %lld to %llu\n",
2703 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2705 inode->i_mtime.tv_sec = body->mbo_mtime;
2707 lli->lli_mtime = body->mbo_mtime;
2710 if (body->mbo_valid & OBD_MD_FLCTIME) {
2711 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2712 inode->i_ctime.tv_sec = body->mbo_ctime;
2713 lli->lli_ctime = body->mbo_ctime;
2716 if (body->mbo_valid & OBD_MD_FLBTIME)
2717 lli->lli_btime = body->mbo_btime;
2719 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2720 if (body->mbo_valid & OBD_MD_FLFLAGS)
2721 ll_update_inode_flags(inode, body->mbo_flags);
2722 if (body->mbo_valid & OBD_MD_FLMODE)
2723 inode->i_mode = (inode->i_mode & S_IFMT) |
2724 (body->mbo_mode & ~S_IFMT);
2726 if (body->mbo_valid & OBD_MD_FLTYPE)
2727 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2728 (body->mbo_mode & S_IFMT);
2730 LASSERT(inode->i_mode != 0);
2731 if (body->mbo_valid & OBD_MD_FLUID)
2732 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2733 if (body->mbo_valid & OBD_MD_FLGID)
2734 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2735 if (body->mbo_valid & OBD_MD_FLPROJID)
2736 lli->lli_projid = body->mbo_projid;
2737 if (body->mbo_valid & OBD_MD_FLNLINK) {
2738 spin_lock(&inode->i_lock);
2739 set_nlink(inode, body->mbo_nlink);
2740 spin_unlock(&inode->i_lock);
2742 if (body->mbo_valid & OBD_MD_FLRDEV)
2743 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2745 if (body->mbo_valid & OBD_MD_FLID) {
2746 /* FID shouldn't be changed! */
2747 if (fid_is_sane(&lli->lli_fid)) {
2748 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2749 "Trying to change FID "DFID
2750 " to the "DFID", inode "DFID"(%p)\n",
2751 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2752 PFID(ll_inode2fid(inode)), inode);
2754 lli->lli_fid = body->mbo_fid1;
2758 LASSERT(fid_seq(&lli->lli_fid) != 0);
2760 /* In case of encrypted file without the key, please do not lose
2761 * clear text size stored into lli_lazysize in ll_merge_attr(),
2762 * we will need it in ll_prepare_close().
2764 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2765 llcrypt_require_key(inode) == -ENOKEY)
2766 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2768 lli->lli_attr_valid = body->mbo_valid;
2769 if (body->mbo_valid & OBD_MD_FLSIZE) {
2770 i_size_write(inode, body->mbo_size);
2772 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2773 PFID(ll_inode2fid(inode)),
2774 (unsigned long long)body->mbo_size);
2776 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2777 inode->i_blocks = body->mbo_blocks;
2779 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2780 lli->lli_lazysize = body->mbo_size;
2781 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2782 lli->lli_lazyblocks = body->mbo_blocks;
2785 if (body->mbo_valid & OBD_MD_TSTATE) {
2786 /* Set LLIF_FILE_RESTORING if restore ongoing and
2787 * clear it when done to ensure to start again
2788 * glimpsing updated attrs
2790 if (body->mbo_t_state & MS_RESTORE)
2791 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2793 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2799 /* child default LMV is inherited from parent */
2800 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2801 struct lmv_stripe_md *cdmv)
2806 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2807 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2808 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2809 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2812 if (cdmv->lsm_md_max_inherit !=
2813 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2816 if (cdmv->lsm_md_max_inherit_rr !=
2817 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2823 /* update directory depth to ROOT, called after LOOKUP lock is fetched. */
2824 void ll_update_dir_depth(struct inode *dir, struct inode *inode)
2826 struct ll_inode_info *plli;
2827 struct ll_inode_info *lli;
2829 if (!S_ISDIR(inode->i_mode))
2835 plli = ll_i2info(dir);
2836 lli = ll_i2info(inode);
2837 lli->lli_dir_depth = plli->lli_dir_depth + 1;
2838 if (plli->lli_default_lsm_md && lli->lli_default_lsm_md) {
2839 down_read(&plli->lli_lsm_sem);
2840 down_read(&lli->lli_lsm_sem);
2841 if (ll_default_lmv_inherited(plli->lli_default_lsm_md,
2842 lli->lli_default_lsm_md))
2843 lli->lli_inherit_depth =
2844 plli->lli_inherit_depth + 1;
2846 lli->lli_inherit_depth = 0;
2847 up_read(&lli->lli_lsm_sem);
2848 up_read(&plli->lli_lsm_sem);
2850 lli->lli_inherit_depth = 0;
2853 CDEBUG(D_INODE, DFID" depth %hu default LMV depth %hu\n",
2854 PFID(&lli->lli_fid), lli->lli_dir_depth, lli->lli_inherit_depth);
2857 void ll_truncate_inode_pages_final(struct inode *inode)
2859 struct address_space *mapping = &inode->i_data;
2860 unsigned long nrpages;
2861 unsigned long flags;
2863 truncate_inode_pages_final(mapping);
2865 /* Workaround for LU-118: Note nrpages may not be totally updated when
2866 * truncate_inode_pages() returns, as there can be a page in the process
2867 * of deletion (inside __delete_from_page_cache()) in the specified
2868 * range. Thus mapping->nrpages can be non-zero when this function
2869 * returns even after truncation of the whole mapping. Only do this if
2870 * npages isn't already zero.
2872 nrpages = mapping->nrpages;
2874 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2875 nrpages = mapping->nrpages;
2876 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2877 } /* Workaround end */
2879 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, "
2880 "see https://jira.whamcloud.com/browse/LU-118\n",
2881 ll_i2sbi(inode)->ll_fsname,
2882 PFID(ll_inode2fid(inode)), inode, nrpages);
2885 int ll_read_inode2(struct inode *inode, void *opaque)
2887 struct lustre_md *md = opaque;
2888 struct ll_inode_info *lli = ll_i2info(inode);
2892 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2893 PFID(&lli->lli_fid), inode);
2895 /* Core attributes from the MDS first. This is a new inode, and
2896 * the VFS doesn't zero times in the core inode so we have to do
2897 * it ourselves. They will be overwritten by either MDS or OST
2898 * attributes - we just need to make sure they aren't newer.
2900 inode->i_mtime.tv_sec = 0;
2901 inode->i_atime.tv_sec = 0;
2902 inode->i_ctime.tv_sec = 0;
2904 rc = ll_update_inode(inode, md);
2908 /* OIDEBUG(inode); */
2910 #ifdef HAVE_BACKING_DEV_INFO
2911 /* initializing backing dev info. */
2912 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2914 if (S_ISREG(inode->i_mode)) {
2915 struct ll_sb_info *sbi = ll_i2sbi(inode);
2916 inode->i_op = &ll_file_inode_operations;
2917 inode->i_fop = sbi->ll_fop;
2918 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2920 } else if (S_ISDIR(inode->i_mode)) {
2921 inode->i_op = &ll_dir_inode_operations;
2922 inode->i_fop = &ll_dir_operations;
2924 } else if (S_ISLNK(inode->i_mode)) {
2925 inode->i_op = &ll_fast_symlink_inode_operations;
2928 inode->i_op = &ll_special_inode_operations;
2930 init_special_inode(inode, inode->i_mode,
2939 void ll_delete_inode(struct inode *inode)
2941 struct ll_inode_info *lli = ll_i2info(inode);
2944 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2945 /* It is last chance to write out dirty pages,
2946 * otherwise we may lose data while umount.
2948 * If i_nlink is 0 then just discard data. This is safe because
2949 * local inode gets i_nlink 0 from server only for the last
2950 * unlink, so that file is not opened somewhere else
2952 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2953 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2956 ll_truncate_inode_pages_final(inode);
2957 ll_clear_inode(inode);
2963 int ll_iocontrol(struct inode *inode, struct file *file,
2964 unsigned int cmd, unsigned long arg)
2966 struct ll_sb_info *sbi = ll_i2sbi(inode);
2967 struct ptlrpc_request *req = NULL;
2972 case FS_IOC_GETFLAGS: {
2973 struct mdt_body *body;
2974 struct md_op_data *op_data;
2976 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2977 0, 0, LUSTRE_OPC_ANY,
2979 if (IS_ERR(op_data))
2980 RETURN(PTR_ERR(op_data));
2982 op_data->op_valid = OBD_MD_FLFLAGS;
2983 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2984 ll_finish_md_op_data(op_data);
2986 CERROR("%s: failure inode "DFID": rc = %d\n",
2987 sbi->ll_md_exp->exp_obd->obd_name,
2988 PFID(ll_inode2fid(inode)), rc);
2992 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2994 flags = body->mbo_flags;
2995 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
2996 * ext4 equivalent to please lsattr and other e2fsprogs tools
2998 if (flags & LUSTRE_ENCRYPT_FL)
2999 flags |= STATX_ATTR_ENCRYPTED;
3001 ptlrpc_req_finished(req);
3003 RETURN(put_user(flags, (int __user *)arg));
3005 case FS_IOC_SETFLAGS: {
3007 struct md_op_data *op_data;
3008 struct cl_object *obj;
3009 struct fsxattr fa = { 0 };
3011 if (get_user(flags, (int __user *)arg))
3014 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3015 if (flags & LUSTRE_PROJINHERIT_FL)
3016 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3018 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3023 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3024 LUSTRE_OPC_ANY, NULL);
3025 if (IS_ERR(op_data))
3026 RETURN(PTR_ERR(op_data));
3028 op_data->op_attr_flags = flags;
3029 op_data->op_xvalid |= OP_XVALID_FLAGS;
3030 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3031 ll_finish_md_op_data(op_data);
3032 ptlrpc_req_finished(req);
3036 ll_update_inode_flags(inode, flags);
3038 obj = ll_i2info(inode)->lli_clob;
3042 OBD_ALLOC_PTR(attr);
3046 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3058 int ll_flush_ctx(struct inode *inode)
3060 struct ll_sb_info *sbi = ll_i2sbi(inode);
3062 CDEBUG(D_SEC, "flush context for user %d\n",
3063 from_kuid(&init_user_ns, current_uid()));
3065 obd_set_info_async(NULL, sbi->ll_md_exp,
3066 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3068 obd_set_info_async(NULL, sbi->ll_dt_exp,
3069 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3074 /* umount -f client means force down, don't save state */
3075 void ll_umount_begin(struct super_block *sb)
3077 struct ll_sb_info *sbi = ll_s2sbi(sb);
3078 struct obd_device *obd;
3079 struct obd_ioctl_data *ioc_data;
3083 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3084 sb->s_count, atomic_read(&sb->s_active));
3086 obd = class_exp2obd(sbi->ll_md_exp);
3088 CERROR("Invalid MDC connection handle %#llx\n",
3089 sbi->ll_md_exp->exp_handle.h_cookie);
3095 obd = class_exp2obd(sbi->ll_dt_exp);
3097 CERROR("Invalid LOV connection handle %#llx\n",
3098 sbi->ll_dt_exp->exp_handle.h_cookie);
3104 OBD_ALLOC_PTR(ioc_data);
3106 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
3107 sizeof *ioc_data, ioc_data, NULL);
3109 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
3110 sizeof *ioc_data, ioc_data, NULL);
3112 OBD_FREE_PTR(ioc_data);
3115 /* Really, we'd like to wait until there are no requests outstanding,
3116 * and then continue. For now, we just periodically checking for vfs
3117 * to decrement mnt_cnt and hope to finish it within 10sec.
3121 !may_umount(sbi->ll_mnt.mnt)) {
3129 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3131 struct ll_sb_info *sbi = ll_s2sbi(sb);
3132 char *profilenm = get_profile_name(sb);
3136 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3137 read_only = *flags & MS_RDONLY;
3138 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3139 sizeof(KEY_READ_ONLY),
3140 KEY_READ_ONLY, sizeof(read_only),
3143 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3144 profilenm, read_only ?
3145 "read-only" : "read-write", err);
3150 sb->s_flags |= SB_RDONLY;
3152 sb->s_flags &= ~SB_RDONLY;
3154 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3155 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3156 read_only ? "read-only" : "read-write");
3162 * Cleanup the open handle that is cached on MDT-side.
3164 * For open case, the client side open handling thread may hit error
3165 * after the MDT grant the open. Under such case, the client should
3166 * send close RPC to the MDT as cleanup; otherwise, the open handle
3167 * on the MDT will be leaked there until the client umount or evicted.
3169 * In further, if someone unlinked the file, because the open handle
3170 * holds the reference on such file/object, then it will block the
3171 * subsequent threads that want to locate such object via FID.
3173 * \param[in] sb super block for this file-system
3174 * \param[in] open_req pointer to the original open request
3176 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3178 struct mdt_body *body;
3179 struct md_op_data *op_data;
3180 struct ptlrpc_request *close_req = NULL;
3181 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3184 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3185 OBD_ALLOC_PTR(op_data);
3186 if (op_data == NULL) {
3187 CWARN("%s: cannot allocate op_data to release open handle for "
3188 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3193 op_data->op_fid1 = body->mbo_fid1;
3194 op_data->op_open_handle = body->mbo_open_handle;
3195 op_data->op_mod_time = ktime_get_real_seconds();
3196 md_close(exp, op_data, NULL, &close_req);
3197 ptlrpc_req_finished(close_req);
3198 ll_finish_md_op_data(op_data);
3203 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3204 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3205 struct lustre_md *md)
3207 struct ll_sb_info *sbi = ll_i2sbi(inode);
3208 struct ptlrpc_request *req = NULL;
3209 union lmv_mds_md *lmm = NULL;
3213 LASSERT(is_root_inode(inode));
3214 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3215 LASSERT(!md->default_lmv);
3217 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3219 GET_DEFAULT_LAYOUT_ROOT);
3220 if (rc && rc != -ENODATA)
3225 rc = md_unpackmd(sbi->ll_md_exp, &md->default_lmv, lmm, size);
3234 ptlrpc_req_finished(req);
3238 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3239 struct super_block *sb, struct lookup_intent *it)
3241 struct ll_sb_info *sbi = NULL;
3242 struct lustre_md md = { NULL };
3243 bool default_lmv_deleted = false;
3248 LASSERT(*inode || sb);
3249 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3250 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3251 sbi->ll_md_exp, &md);
3256 * clear default_lmv only if intent_getattr reply doesn't contain it.
3257 * but it needs to be done after iget, check this early because
3258 * ll_update_lsm_md() may change md.
3260 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3261 S_ISDIR(md.body->mbo_mode) && !md.default_lmv) {
3262 if (unlikely(*inode && is_root_inode(*inode) &&
3263 !fid_is_root(&sbi->ll_root_fid))) {
3264 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3269 if (!md.default_lmv)
3270 default_lmv_deleted = true;
3274 rc = ll_update_inode(*inode, &md);
3278 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3279 struct lu_fid *fid1 = &md.body->mbo_fid1;
3281 LASSERT(sb != NULL);
3284 * At this point server returns to client's same fid as client
3285 * generated for creating. So using ->fid1 is okay here.
3287 if (!fid_is_sane(fid1)) {
3288 CERROR("%s: Fid is insane "DFID"\n",
3289 sbi->ll_fsname, PFID(fid1));
3290 GOTO(out, rc = -EINVAL);
3293 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3294 if (IS_ERR(*inode)) {
3296 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3298 CERROR("new_inode -fatal: rc %d\n", rc);
3303 /* Handling piggyback layout lock.
3304 * Layout lock can be piggybacked by getattr and open request.
3305 * The lsm can be applied to inode only if it comes with a layout lock
3306 * otherwise correct layout may be overwritten, for example:
3307 * 1. proc1: mdt returns a lsm but not granting layout
3308 * 2. layout was changed by another client
3309 * 3. proc2: refresh layout and layout lock granted
3310 * 4. proc1: to apply a stale layout */
3311 if (it != NULL && it->it_lock_mode != 0) {
3312 struct lustre_handle lockh;
3313 struct ldlm_lock *lock;
3315 lockh.cookie = it->it_lock_handle;
3316 lock = ldlm_handle2lock(&lockh);
3317 LASSERT(lock != NULL);
3318 if (ldlm_has_layout(lock)) {
3319 struct cl_object_conf conf;
3321 memset(&conf, 0, sizeof(conf));
3322 conf.coc_opc = OBJECT_CONF_SET;
3323 conf.coc_inode = *inode;
3324 conf.coc_lock = lock;
3325 conf.u.coc_layout = md.layout;
3326 (void)ll_layout_conf(*inode, &conf);
3328 LDLM_LOCK_PUT(lock);
3331 if (default_lmv_deleted)
3332 ll_update_default_lsm_md(*inode, &md);
3334 /* we may want to apply some policy for foreign file/dir */
3335 if (ll_sbi_has_foreign_symlink(sbi)) {
3336 rc = ll_manage_foreign(*inode, &md);
3344 /* cleanup will be done if necessary */
3345 md_free_lustre_md(sbi->ll_md_exp, &md);
3347 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3348 ll_intent_drop_lock(it);
3349 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3355 int ll_obd_statfs(struct inode *inode, void __user *arg)
3357 struct ll_sb_info *sbi = NULL;
3358 struct obd_export *exp;
3359 struct obd_ioctl_data *data = NULL;
3364 sbi = ll_i2sbi(inode);
3366 GOTO(out_statfs, rc = -EINVAL);
3368 rc = obd_ioctl_getdata(&data, &len, arg);
3370 GOTO(out_statfs, rc);
3372 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3373 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3374 GOTO(out_statfs, rc = -EINVAL);
3376 if (data->ioc_inllen1 != sizeof(__u32) ||
3377 data->ioc_inllen2 != sizeof(__u32) ||
3378 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3379 data->ioc_plen2 != sizeof(struct obd_uuid))
3380 GOTO(out_statfs, rc = -EINVAL);
3382 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3383 if (type & LL_STATFS_LMV)
3384 exp = sbi->ll_md_exp;
3385 else if (type & LL_STATFS_LOV)
3386 exp = sbi->ll_dt_exp;
3388 GOTO(out_statfs, rc = -ENODEV);
3390 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3392 GOTO(out_statfs, rc);
3394 OBD_FREE_LARGE(data, len);
3399 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3400 * be called early to avoid deadlock.
3402 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3404 if (op_data->op_mea2_sem) {
3405 up_read_non_owner(op_data->op_mea2_sem);
3406 op_data->op_mea2_sem = NULL;
3409 if (op_data->op_mea1_sem) {
3410 up_read_non_owner(op_data->op_mea1_sem);
3411 op_data->op_mea1_sem = NULL;
3415 /* this function prepares md_op_data hint for passing it down to MD stack. */
3416 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3417 struct inode *i1, struct inode *i2,
3418 const char *name, size_t namelen,
3419 __u32 mode, enum md_op_code opc,
3422 struct llcrypt_name fname = { 0 };
3425 LASSERT(i1 != NULL);
3428 /* Do not reuse namelen for something else. */
3430 return ERR_PTR(-EINVAL);
3432 if ((!IS_ENCRYPTED(i1) ||
3433 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3434 namelen > ll_i2sbi(i1)->ll_namelen)
3435 return ERR_PTR(-ENAMETOOLONG);
3437 /* "/" is not valid name, but it's allowed */
3438 if (!lu_name_is_valid_2(name, namelen) &&
3439 strncmp("/", name, namelen) != 0)
3440 return ERR_PTR(-EINVAL);
3443 if (op_data == NULL)
3444 OBD_ALLOC_PTR(op_data);
3446 if (op_data == NULL)
3447 return ERR_PTR(-ENOMEM);
3449 ll_i2gids(op_data->op_suppgids, i1, i2);
3450 /* If the client is using a subdir mount and looks at what it sees as
3451 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3453 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3454 !fid_is_root(ll_inode2fid(i1)) &&
3455 name && namelen == strlen(dot_fscrypt_name) &&
3456 strncmp(name, dot_fscrypt_name, namelen) == 0))
3457 lu_root_fid(&op_data->op_fid1);
3459 op_data->op_fid1 = *ll_inode2fid(i1);
3461 if (S_ISDIR(i1->i_mode)) {
3462 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3463 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3464 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3465 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3469 op_data->op_fid2 = *ll_inode2fid(i2);
3470 if (S_ISDIR(i2->i_mode)) {
3472 /* i2 is typically a child of i1, and MUST be
3473 * further from the root to avoid deadlocks.
3475 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3476 op_data->op_mea2_sem =
3477 &ll_i2info(i2)->lli_lsm_sem;
3479 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3482 fid_zero(&op_data->op_fid2);
3485 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3486 op_data->op_cli_flags |= CLI_HASH64;
3488 if (ll_need_32bit_api(ll_i2sbi(i1)))
3489 op_data->op_cli_flags |= CLI_API32;
3491 if ((i2 && is_root_inode(i2)) ||
3492 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3493 /* In case of lookup, ll_setup_filename() has already been
3494 * called in ll_lookup_it(), so just take provided name.
3495 * Also take provided name if we are dealing with root inode.
3497 fname.disk_name.name = (unsigned char *)name;
3498 fname.disk_name.len = namelen;
3499 } else if (name && namelen) {
3500 struct qstr dname = QSTR_INIT(name, namelen);
3502 struct lu_fid *pfid = NULL;
3506 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3507 /* special case when called from ll_link() */
3512 lookup = (int)(opc == LUSTRE_OPC_ANY);
3514 if (opc == LUSTRE_OPC_ANY && lookup)
3516 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3518 ll_finish_md_op_data(op_data);
3521 if (pfid && !fid_is_zero(pfid)) {
3523 op_data->op_fid2 = fid;
3524 op_data->op_bias = MDS_FID_OP;
3526 if (fname.disk_name.name &&
3527 fname.disk_name.name != (unsigned char *)name) {
3528 /* op_data->op_name must be freed after use */
3529 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3533 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3534 * are LUSTRE_OPC_ANY
3536 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3537 op_data->op_code = LUSTRE_OPC_ANY;
3539 op_data->op_code = opc;
3540 op_data->op_name = fname.disk_name.name;
3541 op_data->op_namelen = fname.disk_name.len;
3542 op_data->op_mode = mode;
3543 op_data->op_mod_time = ktime_get_real_seconds();
3544 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3545 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3546 op_data->op_cap = current_cap();
3547 op_data->op_mds = 0;
3548 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3549 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3550 op_data->op_bias |= MDS_CREATE_VOLATILE;
3552 op_data->op_data = data;
3557 void ll_finish_md_op_data(struct md_op_data *op_data)
3559 ll_unlock_md_op_lsm(op_data);
3560 ll_security_release_secctx(op_data->op_file_secctx,
3561 op_data->op_file_secctx_size);
3562 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3563 /* allocated via ll_setup_filename called
3564 * from ll_prep_md_op_data
3566 kfree(op_data->op_name);
3567 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3568 OBD_FREE_PTR(op_data);
3571 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3573 struct ll_sb_info *sbi;
3576 LASSERT(seq && dentry);
3577 sbi = ll_s2sbi(dentry->d_sb);
3579 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3580 seq_puts(seq, "nolock");
3582 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3583 /* match_table in some cases has patterns for both enabled and
3584 * disabled cases. Ignore 'no'xxx versions if bit is set.
3586 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3587 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3588 if (ll_sbi_flags_name[i].token ==
3589 LL_SBI_FOREIGN_SYMLINK) {
3590 seq_show_option(seq, "foreign_symlink",
3591 sbi->ll_foreign_symlink_prefix);
3593 seq_printf(seq, ",%s",
3594 ll_sbi_flags_name[i].pattern);
3597 /* You can have either localflock or flock but not
3598 * both. If localflock is set don't print flock or
3601 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3603 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3604 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3605 seq_printf(seq, ",%s",
3606 ll_sbi_flags_name[i].pattern);
3610 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3616 * Get obd name by cmd, and copy out to user space
3618 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
3620 struct ll_sb_info *sbi = ll_i2sbi(inode);
3621 struct obd_device *obd;
3624 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3625 obd = class_exp2obd(sbi->ll_dt_exp);
3626 else if (cmd == OBD_IOC_GETMDNAME)
3627 obd = class_exp2obd(sbi->ll_md_exp);
3634 if (copy_to_user((void __user *)arg, obd->obd_name,
3635 strlen(obd->obd_name) + 1))
3642 struct work_struct db_work;
3643 struct dentry *db_dentry;
3644 /* Let's hope the path is not too long, 32 bytes for the work struct
3647 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3650 static void ll_dput_later(struct work_struct *work)
3652 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3654 dput(db->db_dentry);
3655 free_page((unsigned long)db);
3658 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3665 p.mnt = current->fs->root.mnt;
3667 path = d_path(&p, buf, bufsize);
3672 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3674 struct dname_buf *db;
3676 struct dentry *dentry = NULL;
3678 /* this can be called inside spin lock so use GFP_ATOMIC. */
3679 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3682 dentry = d_find_alias(inode);
3684 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3687 /* The below message is checked in recovery-small.sh test_24b */
3689 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3690 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3691 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3692 PFID(ll_inode2fid(inode)),
3693 (path && !IS_ERR(path)) ? path : "", ioret);
3695 if (dentry != NULL) {
3696 /* We cannot dput here since if we happen to be the last holder
3697 * then we can end up waiting for page evictions that
3698 * in turn wait for RPCs that need this instance of ptlrpcd
3699 * (callng brw_interpret->*page_completion*->vmpage_error->here)
3702 INIT_WORK(&db->db_work, ll_dput_later);
3703 db->db_dentry = dentry;
3704 schedule_work(&db->db_work);
3707 free_page((unsigned long)db);
3711 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3712 struct lov_user_md **kbuf)
3714 struct lov_user_md lum;
3718 if (copy_from_user(&lum, md, sizeof(lum)))
3721 lum_size = ll_lov_user_md_size(&lum);
3725 OBD_ALLOC_LARGE(*kbuf, lum_size);
3729 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3730 OBD_FREE_LARGE(*kbuf, lum_size);
3738 * Compute llite root squash state after a change of root squash
3739 * configuration setting or add/remove of a lnet nid
3741 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3743 struct root_squash_info *squash = &sbi->ll_squash;
3746 struct lnet_processid id;
3748 /* Update norootsquash flag */
3749 spin_lock(&squash->rsi_lock);
3750 if (list_empty(&squash->rsi_nosquash_nids))
3751 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3753 /* Do not apply root squash as soon as one of our NIDs is
3754 * in the nosquash_nids list */
3757 while (LNetGetId(i++, &id) != -ENOENT) {
3758 if (nid_is_lo0(&id.nid))
3760 if (cfs_match_nid(lnet_nid_to_nid4(&id.nid),
3761 &squash->rsi_nosquash_nids)) {
3767 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3769 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3771 spin_unlock(&squash->rsi_lock);
3775 * Parse linkea content to extract information about a given hardlink
3777 * \param[in] ldata - Initialized linkea data
3778 * \param[in] linkno - Link identifier
3779 * \param[out] parent_fid - The entry's parent FID
3780 * \param[out] ln - Entry name destination buffer
3782 * \retval 0 on success
3783 * \retval Appropriate negative error code on failure
3785 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3786 struct lu_fid *parent_fid, struct lu_name *ln)
3792 rc = linkea_init_with_rec(ldata);
3796 if (linkno >= ldata->ld_leh->leh_reccount)
3797 /* beyond last link */
3800 linkea_first_entry(ldata);
3801 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3802 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3807 linkea_next_entry(ldata);
3817 * Get parent FID and name of an identified link. Operation is performed for
3818 * a given link number, letting the caller iterate over linkno to list one or
3819 * all links of an entry.
3821 * \param[in] file - File descriptor against which to perform the operation
3822 * \param[in,out] arg - User-filled structure containing the linkno to operate
3823 * on and the available size. It is eventually filled with
3824 * the requested information or left untouched on error
3826 * \retval - 0 on success
3827 * \retval - Appropriate negative error code on failure
3829 int ll_getparent(struct file *file, struct getparent __user *arg)
3831 struct inode *inode = file_inode(file);
3832 struct linkea_data *ldata;
3833 struct lu_buf buf = LU_BUF_NULL;
3835 struct lu_fid parent_fid;
3842 if (!capable(CAP_DAC_READ_SEARCH) &&
3843 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
3846 if (get_user(name_size, &arg->gp_name_size))
3849 if (get_user(linkno, &arg->gp_linkno))
3852 if (name_size > PATH_MAX)
3855 OBD_ALLOC(ldata, sizeof(*ldata));
3859 rc = linkea_data_new(ldata, &buf);
3861 GOTO(ldata_free, rc);
3863 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3864 buf.lb_len, OBD_MD_FLXATTR);
3868 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3872 if (ln.ln_namelen >= name_size)
3873 GOTO(lb_free, rc = -EOVERFLOW);
3875 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3876 GOTO(lb_free, rc = -EFAULT);
3878 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3879 GOTO(lb_free, rc = -EFAULT);
3881 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3882 GOTO(lb_free, rc = -EFAULT);
3887 OBD_FREE(ldata, sizeof(*ldata));