4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/llite/llite_lib.c
33 * Lustre Light Super operations
36 #define DEBUG_SUBSYSTEM S_LLITE
38 #include <linux/cpu.h>
39 #include <linux/module.h>
40 #include <linux/random.h>
41 #include <linux/statfs.h>
42 #include <linux/time.h>
43 #include <linux/file.h>
44 #include <linux/types.h>
45 #include <libcfs/linux/linux-uuid.h>
46 #include <linux/version.h>
48 #include <linux/user_namespace.h>
49 #include <linux/delay.h>
50 #include <linux/uidgid.h>
51 #include <linux/fs_struct.h>
53 #ifndef HAVE_CPUS_READ_LOCK
54 #include <libcfs/linux/linux-cpu.h>
56 #include <libcfs/linux/linux-misc.h>
57 #include <uapi/linux/lustre/lustre_ioctl.h>
58 #ifdef HAVE_UAPI_LINUX_MOUNT_H
59 #include <uapi/linux/mount.h>
62 #include <lustre_ha.h>
63 #include <lustre_dlm.h>
64 #include <lprocfs_status.h>
65 #include <lustre_disk.h>
66 #include <uapi/linux/lustre/lustre_param.h>
67 #include <lustre_log.h>
68 #include <cl_object.h>
69 #include <obd_cksum.h>
70 #include "llite_internal.h"
72 struct kmem_cache *ll_file_data_slab;
75 #define log2(n) ffz(~(n))
79 * If there is only one number of core visible to Lustre,
80 * async readahead will be disabled, to avoid massive over
81 * subscription, we use 1/2 of active cores as default max
82 * async readahead requests.
84 static inline unsigned int ll_get_ra_async_max_active(void)
86 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
89 static struct ll_sb_info *ll_init_sbi(void)
91 struct ll_sb_info *sbi = NULL;
93 unsigned long lru_page_max;
101 RETURN(ERR_PTR(-ENOMEM));
103 rc = pcc_super_init(&sbi->ll_pcc_super);
107 spin_lock_init(&sbi->ll_lock);
108 mutex_init(&sbi->ll_lco.lco_lock);
109 spin_lock_init(&sbi->ll_pp_extent_lock);
110 spin_lock_init(&sbi->ll_process_lock);
111 sbi->ll_rw_stats_on = 0;
112 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
115 pages = si.totalram - si.totalhigh;
116 lru_page_max = pages / 2;
118 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
119 sbi->ll_ra_info.ll_readahead_wq =
120 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
122 sbi->ll_ra_info.ra_async_max_active);
123 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
124 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
126 /* initialize ll_cache data */
127 sbi->ll_cache = cl_cache_init(lru_page_max);
128 if (sbi->ll_cache == NULL)
129 GOTO(out_destroy_ra, rc = -ENOMEM);
131 /* initialize foreign symlink prefix path */
132 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
133 if (sbi->ll_foreign_symlink_prefix == NULL)
134 GOTO(out_destroy_ra, rc = -ENOMEM);
135 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
136 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
138 /* initialize foreign symlink upcall path, none by default */
139 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
140 if (sbi->ll_foreign_symlink_upcall == NULL)
141 GOTO(out_destroy_ra, rc = -ENOMEM);
142 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
143 sbi->ll_foreign_symlink_upcall_items = NULL;
144 sbi->ll_foreign_symlink_upcall_nb_items = 0;
145 init_rwsem(&sbi->ll_foreign_symlink_sem);
146 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
147 * not enabled by default
150 sbi->ll_ra_info.ra_max_pages =
151 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
152 sbi->ll_ra_info.ra_max_pages_per_file =
153 min(sbi->ll_ra_info.ra_max_pages / 4,
154 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
155 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
156 sbi->ll_ra_info.ra_max_pages_per_file;
157 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
158 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
159 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
161 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
162 #ifdef ENABLE_CHECKSUM
163 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
166 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
169 #ifdef HAVE_LRU_RESIZE_SUPPORT
170 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
172 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
174 /* metadata statahead is enabled by default */
175 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
176 sbi->ll_sa_max = LL_SA_RPC_DEF;
177 atomic_set(&sbi->ll_sa_total, 0);
178 atomic_set(&sbi->ll_sa_wrong, 0);
179 atomic_set(&sbi->ll_sa_running, 0);
180 atomic_set(&sbi->ll_agl_total, 0);
181 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
182 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
183 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
184 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
185 ll_sbi_set_encrypt(sbi, true);
188 sbi->ll_squash.rsi_uid = 0;
189 sbi->ll_squash.rsi_gid = 0;
190 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
191 spin_lock_init(&sbi->ll_squash.rsi_lock);
193 /* Per-filesystem file heat */
194 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
195 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
197 /* Per-fs open heat level before requesting open lock */
198 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
199 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
200 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
203 if (sbi->ll_foreign_symlink_prefix)
204 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
206 cl_cache_decref(sbi->ll_cache);
207 sbi->ll_cache = NULL;
209 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
211 pcc_super_fini(&sbi->ll_pcc_super);
217 static void ll_free_sbi(struct super_block *sb)
219 struct ll_sb_info *sbi = ll_s2sbi(sb);
223 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
224 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
225 if (sbi->ll_ra_info.ll_readahead_wq)
226 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
227 if (sbi->ll_cache != NULL) {
228 cl_cache_decref(sbi->ll_cache);
229 sbi->ll_cache = NULL;
231 if (sbi->ll_foreign_symlink_prefix) {
232 OBD_FREE(sbi->ll_foreign_symlink_prefix,
233 sbi->ll_foreign_symlink_prefix_size);
234 sbi->ll_foreign_symlink_prefix = NULL;
236 if (sbi->ll_foreign_symlink_upcall) {
237 OBD_FREE(sbi->ll_foreign_symlink_upcall,
238 strlen(sbi->ll_foreign_symlink_upcall) +
240 sbi->ll_foreign_symlink_upcall = NULL;
242 if (sbi->ll_foreign_symlink_upcall_items) {
244 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
245 struct ll_foreign_symlink_upcall_item *items =
246 sbi->ll_foreign_symlink_upcall_items;
248 for (i = 0 ; i < nb_items; i++)
249 if (items[i].type == STRING_TYPE)
250 OBD_FREE(items[i].string,
253 OBD_FREE_LARGE(items, nb_items *
254 sizeof(struct ll_foreign_symlink_upcall_item));
255 sbi->ll_foreign_symlink_upcall_items = NULL;
257 ll_free_rw_stats_info(sbi);
258 pcc_super_fini(&sbi->ll_pcc_super);
259 OBD_FREE(sbi, sizeof(*sbi));
264 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
266 struct inode *root = NULL;
267 struct ll_sb_info *sbi = ll_s2sbi(sb);
268 struct obd_statfs *osfs = NULL;
269 struct ptlrpc_request *request = NULL;
270 struct obd_connect_data *data = NULL;
271 struct obd_uuid *uuid;
272 struct md_op_data *op_data;
273 struct lustre_md lmd;
275 int size, err, checksum;
279 sbi->ll_md_obd = class_name2obd(md);
280 if (!sbi->ll_md_obd) {
281 CERROR("MD %s: not setup or attached\n", md);
295 /* pass client page size via ocd_grant_blkbits, the server should report
296 * back its backend blocksize for grant calculation purpose */
297 data->ocd_grant_blkbits = PAGE_SHIFT;
299 /* indicate MDT features supported by this client */
300 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
301 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
302 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
303 OBD_CONNECT_SRVLOCK |
304 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
305 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
306 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
307 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
308 OBD_CONNECT_64BITHASH |
309 OBD_CONNECT_EINPROGRESS |
310 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
311 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
312 OBD_CONNECT_MAX_EASIZE |
313 OBD_CONNECT_FLOCK_DEAD |
314 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
315 OBD_CONNECT_OPEN_BY_FID |
316 OBD_CONNECT_DIR_STRIPE |
317 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
318 OBD_CONNECT_SUBTREE |
319 OBD_CONNECT_MULTIMODRPCS |
320 OBD_CONNECT_GRANT_PARAM |
321 OBD_CONNECT_GRANT_SHRINK |
322 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
324 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
325 OBD_CONNECT2_SUM_STATFS |
326 OBD_CONNECT2_OVERSTRIPING |
328 OBD_CONNECT2_LOCK_CONVERT |
329 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
330 OBD_CONNECT2_INC_XID |
332 OBD_CONNECT2_ASYNC_DISCARD |
334 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
335 OBD_CONNECT2_GETATTR_PFID |
336 OBD_CONNECT2_DOM_LVB |
337 OBD_CONNECT2_REP_MBITS |
338 OBD_CONNECT2_ATOMIC_OPEN_LOCK;
340 #ifdef HAVE_LRU_RESIZE_SUPPORT
341 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
342 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
344 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
346 data->ocd_cksum_types = obd_cksum_types_supported_client();
348 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
349 /* flag mdc connection as lightweight, only used for test
350 * purpose, use with care */
351 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
353 data->ocd_ibits_known = MDS_INODELOCK_FULL;
354 data->ocd_version = LUSTRE_VERSION_CODE;
356 if (sb->s_flags & SB_RDONLY)
357 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
358 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
359 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
362 /* Setting this indicates we correctly support S_NOSEC (See kernel
363 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
365 sb->s_flags |= SB_NOSEC;
367 sbi->ll_fop = ll_select_file_operations(sbi);
369 /* always ping even if server suppress_pings */
370 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
371 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
373 obd_connect_set_secctx(data);
374 if (ll_sbi_has_encrypt(sbi))
375 obd_connect_set_enc(data);
377 #if defined(CONFIG_SECURITY)
378 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
381 data->ocd_brw_size = MD_MAX_BRW_SIZE;
383 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
384 &sbi->ll_sb_uuid, data, sbi->ll_cache);
386 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
387 "recovery, of which this client is not a "
388 "part. Please wait for recovery to complete,"
389 " abort, or time out.\n", md);
392 CERROR("cannot connect to %s: rc = %d\n", md, err);
396 sbi->ll_md_exp->exp_connect_data = *data;
398 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
399 LUSTRE_SEQ_METADATA);
401 CERROR("%s: Can't init metadata layer FID infrastructure, "
402 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
406 /* For mount, we only need fs info from MDT0, and also in DNE, it
407 * can make sure the client can be mounted as long as MDT0 is
409 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
410 ktime_get_seconds() - sbi->ll_statfs_max_age,
411 OBD_STATFS_FOR_MDT0);
413 GOTO(out_md_fid, err);
415 /* This needs to be after statfs to ensure connect has finished.
416 * Note that "data" does NOT contain the valid connect reply.
417 * If connecting to a 1.8 server there will be no LMV device, so
418 * we can access the MDC export directly and exp_connect_flags will
419 * be non-zero, but if accessing an upgraded 2.1 server it will
420 * have the correct flags filled in.
421 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
422 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
423 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
424 valid != CLIENT_CONNECT_MDT_REQD) {
427 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
428 obd_connect_flags2str(buf, PAGE_SIZE,
429 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
430 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
431 "feature(s) needed for correct operation "
432 "of this client (%s). Please upgrade "
433 "server or downgrade client.\n",
434 sbi->ll_md_exp->exp_obd->obd_name, buf);
435 OBD_FREE(buf, PAGE_SIZE);
436 GOTO(out_md_fid, err = -EPROTO);
439 size = sizeof(*data);
440 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
441 KEY_CONN_DATA, &size, data);
443 CERROR("%s: Get connect data failed: rc = %d\n",
444 sbi->ll_md_exp->exp_obd->obd_name, err);
445 GOTO(out_md_fid, err);
448 LASSERT(osfs->os_bsize);
449 sb->s_blocksize = osfs->os_bsize;
450 sb->s_blocksize_bits = log2(osfs->os_bsize);
451 sb->s_magic = LL_SUPER_MAGIC;
452 sb->s_maxbytes = MAX_LFS_FILESIZE;
453 sbi->ll_namelen = osfs->os_namelen;
454 sbi->ll_mnt.mnt = current->fs->root.mnt;
456 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
457 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
458 LCONSOLE_INFO("Disabling user_xattr feature because "
459 "it is not supported on the server\n");
460 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
463 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
465 sb->s_flags |= SB_POSIXACL;
467 set_bit(LL_SBI_ACL, sbi->ll_flags);
469 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
471 sb->s_flags &= ~SB_POSIXACL;
473 clear_bit(LL_SBI_ACL, sbi->ll_flags);
476 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
477 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
479 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
480 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
482 if (obd_connect_has_secctx(data))
483 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
485 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
486 if (ll_sbi_has_test_dummy_encryption(sbi))
487 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
489 sbi->ll_md_exp->exp_obd->obd_name);
490 ll_sbi_set_encrypt(sbi, false);
493 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
494 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
495 LCONSOLE_INFO("%s: disabling xattr cache due to "
496 "unknown maximum xattr size.\n", dt);
497 } else if (!sbi->ll_xattr_cache_set) {
498 /* If xattr_cache is already set (no matter 0 or 1)
499 * during processing llog, it won't be enabled here. */
500 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
501 sbi->ll_xattr_cache_enabled = 1;
505 sbi->ll_dt_obd = class_name2obd(dt);
506 if (!sbi->ll_dt_obd) {
507 CERROR("DT %s: not setup or attached\n", dt);
508 GOTO(out_md_fid, err = -ENODEV);
511 /* pass client page size via ocd_grant_blkbits, the server should report
512 * back its backend blocksize for grant calculation purpose */
513 data->ocd_grant_blkbits = PAGE_SHIFT;
515 /* indicate OST features supported by this client */
516 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
517 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
518 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
519 OBD_CONNECT_SRVLOCK |
520 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
521 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
522 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
523 OBD_CONNECT_EINPROGRESS |
524 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
525 OBD_CONNECT_LAYOUTLOCK |
526 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
527 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
528 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
529 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
530 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
531 OBD_CONNECT2_REP_MBITS;
533 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
534 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
536 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
537 * disabled by default, because it can still be enabled on the
538 * fly via /sys. As a consequence, we still need to come to an
539 * agreement on the supported algorithms at connect time
541 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
543 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
544 data->ocd_cksum_types = OBD_CKSUM_ADLER;
546 data->ocd_cksum_types = obd_cksum_types_supported_client();
548 #ifdef HAVE_LRU_RESIZE_SUPPORT
549 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
551 /* always ping even if server suppress_pings */
552 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
553 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
555 if (ll_sbi_has_encrypt(sbi))
556 obd_connect_set_enc(data);
558 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
559 "ocd_grant: %d\n", data->ocd_connect_flags,
560 data->ocd_version, data->ocd_grant);
562 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
563 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
565 data->ocd_brw_size = DT_MAX_BRW_SIZE;
567 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
568 &sbi->ll_sb_uuid, data, sbi->ll_cache);
570 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
571 "recovery, of which this client is not a "
572 "part. Please wait for recovery to "
573 "complete, abort, or time out.\n", dt);
576 CERROR("%s: Cannot connect to %s: rc = %d\n",
577 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
581 if (ll_sbi_has_encrypt(sbi) &&
582 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
583 if (ll_sbi_has_test_dummy_encryption(sbi))
584 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
586 ll_sbi_set_encrypt(sbi, false);
587 } else if (ll_sbi_has_test_dummy_encryption(sbi)) {
588 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
591 sbi->ll_dt_exp->exp_connect_data = *data;
593 /* Don't change value if it was specified in the config log */
594 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
595 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
596 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
597 (data->ocd_brw_size >> PAGE_SHIFT));
598 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
599 sbi->ll_ra_info.ra_max_pages_per_file)
600 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
601 sbi->ll_ra_info.ra_max_pages_per_file;
604 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
605 LUSTRE_SEQ_METADATA);
607 CERROR("%s: Can't init data layer FID infrastructure, "
608 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
612 mutex_lock(&sbi->ll_lco.lco_lock);
613 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
614 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
615 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
616 mutex_unlock(&sbi->ll_lco.lco_lock);
618 fid_zero(&sbi->ll_root_fid);
619 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
622 CERROR("cannot mds_connect: rc = %d\n", err);
623 GOTO(out_lock_cn_cb, err);
625 if (!fid_is_sane(&sbi->ll_root_fid)) {
626 CERROR("%s: Invalid root fid "DFID" during mount\n",
627 sbi->ll_md_exp->exp_obd->obd_name,
628 PFID(&sbi->ll_root_fid));
629 GOTO(out_lock_cn_cb, err = -EINVAL);
631 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
633 sb->s_op = &lustre_super_operations;
634 sb->s_xattr = ll_xattr_handlers;
635 #if THREAD_SIZE >= 8192 /*b=17630*/
636 sb->s_export_op = &lustre_export_operations;
638 #ifdef HAVE_LUSTRE_CRYPTO
639 llcrypt_set_ops(sb, &lustre_cryptops);
643 * XXX: move this to after cbd setup? */
644 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
645 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
646 valid |= OBD_MD_FLACL;
648 OBD_ALLOC_PTR(op_data);
650 GOTO(out_lock_cn_cb, err = -ENOMEM);
652 op_data->op_fid1 = sbi->ll_root_fid;
653 op_data->op_mode = 0;
654 op_data->op_valid = valid;
656 err = md_getattr(sbi->ll_md_exp, op_data, &request);
658 OBD_FREE_PTR(op_data);
660 CERROR("%s: md_getattr failed for root: rc = %d\n",
661 sbi->ll_md_exp->exp_obd->obd_name, err);
662 GOTO(out_lock_cn_cb, err);
665 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
666 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
668 CERROR("failed to understand root inode md: rc = %d\n", err);
669 ptlrpc_req_finished(request);
670 GOTO(out_lock_cn_cb, err);
673 LASSERT(fid_is_sane(&sbi->ll_root_fid));
674 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
675 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
676 md_free_lustre_md(sbi->ll_md_exp, &lmd);
677 ptlrpc_req_finished(request);
681 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
683 CERROR("%s: bad ll_iget() for root: rc = %d\n",
684 sbi->ll_fsname, err);
688 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
689 if (sbi->ll_checksum_set) {
690 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
691 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
692 sizeof(checksum), &checksum, NULL);
694 CERROR("%s: Set checksum failed: rc = %d\n",
695 sbi->ll_dt_exp->exp_obd->obd_name, err);
701 sb->s_root = d_make_root(root);
702 if (sb->s_root == NULL) {
704 CERROR("%s: can't make root dentry: rc = %d\n",
705 sbi->ll_fsname, err);
709 sbi->ll_sdev_orig = sb->s_dev;
711 /* We set sb->s_dev equal on all lustre clients in order to support
712 * NFS export clustering. NFSD requires that the FSID be the same
714 /* s_dev is also used in lt_compare() to compare two fs, but that is
715 * only a node-local comparison. */
716 uuid = obd_get_uuid(sbi->ll_md_exp);
718 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
725 if (sbi->ll_dt_obd) {
726 err = sysfs_create_link(&sbi->ll_kset.kobj,
727 &sbi->ll_dt_obd->obd_kset.kobj,
728 sbi->ll_dt_obd->obd_type->typ_name);
730 CERROR("%s: could not register %s in llite: rc = %d\n",
731 dt, sbi->ll_fsname, err);
736 if (sbi->ll_md_obd) {
737 err = sysfs_create_link(&sbi->ll_kset.kobj,
738 &sbi->ll_md_obd->obd_kset.kobj,
739 sbi->ll_md_obd->obd_type->typ_name);
741 CERROR("%s: could not register %s in llite: rc = %d\n",
742 md, sbi->ll_fsname, err);
751 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
753 obd_disconnect(sbi->ll_dt_exp);
754 sbi->ll_dt_exp = NULL;
755 sbi->ll_dt_obd = NULL;
757 obd_fid_fini(sbi->ll_md_exp->exp_obd);
759 obd_disconnect(sbi->ll_md_exp);
760 sbi->ll_md_exp = NULL;
761 sbi->ll_md_obd = NULL;
770 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
774 size = sizeof(*lmmsize);
775 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
776 KEY_MAX_EASIZE, &size, lmmsize);
778 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
779 sbi->ll_dt_exp->exp_obd->obd_name, rc);
783 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
786 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
787 KEY_MAX_EASIZE, &size, lmmsize);
789 CERROR("Get max mdsize error rc %d\n", rc);
791 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
797 * Get the value of the default_easize parameter.
799 * \see client_obd::cl_default_mds_easize
801 * \param[in] sbi superblock info for this filesystem
802 * \param[out] lmmsize pointer to storage location for value
804 * \retval 0 on success
805 * \retval negative negated errno on failure
807 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
812 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
813 KEY_DEFAULT_EASIZE, &size, lmmsize);
815 CERROR("Get default mdsize error rc %d\n", rc);
821 * Set the default_easize parameter to the given value.
823 * \see client_obd::cl_default_mds_easize
825 * \param[in] sbi superblock info for this filesystem
826 * \param[in] lmmsize the size to set
828 * \retval 0 on success
829 * \retval negative negated errno on failure
831 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
835 if (lmmsize < sizeof(struct lov_mds_md) ||
836 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
839 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
840 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
841 sizeof(int), &lmmsize, NULL);
846 static void client_common_put_super(struct super_block *sb)
848 struct ll_sb_info *sbi = ll_s2sbi(sb);
853 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
854 obd_disconnect(sbi->ll_dt_exp);
855 sbi->ll_dt_exp = NULL;
857 ll_debugfs_unregister_super(sb);
859 obd_fid_fini(sbi->ll_md_exp->exp_obd);
860 obd_disconnect(sbi->ll_md_exp);
861 sbi->ll_md_exp = NULL;
866 void ll_kill_super(struct super_block *sb)
868 struct ll_sb_info *sbi;
872 if (!(sb->s_flags & SB_ACTIVE))
876 /* we need restore s_dev from changed for clustred NFS before put_super
877 * because new kernels have cached s_dev and change sb->s_dev in
878 * put_super not affected real removing devices */
880 sb->s_dev = sbi->ll_sdev_orig;
882 /* wait running statahead threads to quit */
883 while (atomic_read(&sbi->ll_sa_running) > 0)
884 schedule_timeout_uninterruptible(
885 cfs_time_seconds(1) >> 3);
891 /* Since we use this table for ll_sbi_flags_seq_show make
892 * sure what you want displayed for a specific token that
893 * is listed more than once below be listed first. For
894 * example we want "checksum" displayed, not "nochecksum"
897 static const match_table_t ll_sbi_flags_name = {
898 {LL_SBI_NOLCK, "nolock"},
899 {LL_SBI_CHECKSUM, "checksum"},
900 {LL_SBI_CHECKSUM, "nochecksum"},
901 {LL_SBI_LOCALFLOCK, "localflock"},
902 {LL_SBI_FLOCK, "flock"},
903 {LL_SBI_FLOCK, "noflock"},
904 {LL_SBI_USER_XATTR, "user_xattr"},
905 {LL_SBI_USER_XATTR, "nouser_xattr"},
906 {LL_SBI_LRU_RESIZE, "lruresize"},
907 {LL_SBI_LRU_RESIZE, "nolruresize"},
908 {LL_SBI_LAZYSTATFS, "lazystatfs"},
909 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
910 {LL_SBI_32BIT_API, "32bitapi"},
911 {LL_SBI_USER_FID2PATH, "user_fid2path"},
912 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
913 {LL_SBI_VERBOSE, "verbose"},
914 {LL_SBI_VERBOSE, "noverbose"},
915 {LL_SBI_ALWAYS_PING, "always_ping"},
916 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
917 {LL_SBI_ENCRYPT, "encrypt"},
918 {LL_SBI_ENCRYPT, "noencrypt"},
919 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
920 {LL_SBI_NUM_MOUNT_OPT, NULL},
923 {LL_SBI_AGL_ENABLED, "agl"},
924 {LL_SBI_64BIT_HASH, "64bit_hash"},
925 {LL_SBI_LAYOUT_LOCK, "layout"},
926 {LL_SBI_XATTR_CACHE, "xattr_cache"},
927 {LL_SBI_NOROOTSQUASH, "norootsquash"},
928 {LL_SBI_FAST_READ, "fast_read"},
929 {LL_SBI_FILE_SECCTX, "file_secctx"},
930 {LL_SBI_TINY_WRITE, "tiny_write"},
931 {LL_SBI_FILE_HEAT, "file_heat"},
932 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
935 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
937 struct super_block *sb = m->private;
940 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
943 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
946 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
947 if (ll_sbi_flags_name[j].token == i &&
948 ll_sbi_flags_name[j].pattern) {
950 ll_sbi_flags_name[j].pattern);
959 /* non-client-specific mount options are parsed in lmd_parse */
960 static int ll_options(char *options, struct super_block *sb)
962 struct ll_sb_info *sbi = ll_s2sbi(sb);
963 char *s2, *s1, *opts;
969 /* Don't stomp on lmd_opts */
970 opts = kstrdup(options, GFP_KERNEL);
976 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
978 while ((s1 = strsep(&opts, ",")) != NULL) {
979 substring_t args[MAX_OPT_ARGS];
980 bool turn_off = false;
986 CDEBUG(D_SUPER, "next opt=%s\n", s1);
988 if (strncmp(s1, "no", 2) == 0)
992 * Initialize args struct so we know whether arg was
993 * found; some options take optional arguments.
997 token = match_token(s1, ll_sbi_flags_name, args);
998 if (token == LL_SBI_NUM_MOUNT_OPT) {
999 if (match_wildcard("context", s1) ||
1000 match_wildcard("fscontext", s1) ||
1001 match_wildcard("defcontext", s1) ||
1002 match_wildcard("rootcontext",s1))
1005 LCONSOLE_ERROR_MSG(0x152,
1006 "Unknown option '%s', won't mount.\n",
1013 case LL_SBI_32BIT_API:
1014 case LL_SBI_64BIT_HASH:
1015 case LL_SBI_ALWAYS_PING:
1016 set_bit(token, sbi->ll_flags);
1020 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1022 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1024 set_bit(token, sbi->ll_flags);
1027 case LL_SBI_LOCALFLOCK:
1028 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1029 set_bit(token, sbi->ll_flags);
1032 case LL_SBI_CHECKSUM:
1033 sbi->ll_checksum_set = 1;
1035 case LL_SBI_USER_XATTR:
1036 case LL_SBI_USER_FID2PATH:
1037 case LL_SBI_LRU_RESIZE:
1038 case LL_SBI_LAZYSTATFS:
1039 case LL_SBI_VERBOSE:
1041 clear_bit(token, sbi->ll_flags);
1043 set_bit(token, sbi->ll_flags);
1045 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1046 #ifdef HAVE_LUSTRE_CRYPTO
1047 set_bit(token, sbi->ll_flags);
1049 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1053 case LL_SBI_ENCRYPT:
1054 #ifdef HAVE_LUSTRE_CRYPTO
1056 clear_bit(token, sbi->ll_flags);
1058 set_bit(token, sbi->ll_flags);
1060 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1063 case LL_SBI_FOREIGN_SYMLINK:
1064 /* non-default prefix provided ? */
1069 /* path must be absolute */
1070 if (args->from[0] != '/') {
1071 LCONSOLE_ERROR_MSG(0x152,
1072 "foreign prefix '%s' must be an absolute path\n",
1077 old_len = sbi->ll_foreign_symlink_prefix_size;
1078 old = sbi->ll_foreign_symlink_prefix;
1079 /* alloc for path length and '\0' */
1080 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1081 if (!sbi->ll_foreign_symlink_prefix) {
1082 /* restore previous */
1083 sbi->ll_foreign_symlink_prefix = old;
1084 sbi->ll_foreign_symlink_prefix_size =
1088 sbi->ll_foreign_symlink_prefix_size =
1089 args->to - args->from + 1;
1090 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1091 sbi->ll_foreign_symlink_prefix_size,
1094 OBD_FREE(old, old_len);
1096 /* enable foreign symlink support */
1097 set_bit(token, sbi->ll_flags);
1099 LCONSOLE_ERROR_MSG(0x152,
1100 "invalid %s option\n", s1);
1111 void ll_lli_init(struct ll_inode_info *lli)
1113 lli->lli_inode_magic = LLI_INODE_MAGIC;
1115 rwlock_init(&lli->lli_lock);
1116 lli->lli_posix_acl = NULL;
1117 /* Do not set lli_fid, it has been initialized already. */
1118 fid_zero(&lli->lli_pfid);
1119 lli->lli_mds_read_och = NULL;
1120 lli->lli_mds_write_och = NULL;
1121 lli->lli_mds_exec_och = NULL;
1122 lli->lli_open_fd_read_count = 0;
1123 lli->lli_open_fd_write_count = 0;
1124 lli->lli_open_fd_exec_count = 0;
1125 mutex_init(&lli->lli_och_mutex);
1126 spin_lock_init(&lli->lli_agl_lock);
1127 spin_lock_init(&lli->lli_layout_lock);
1128 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1129 lli->lli_clob = NULL;
1131 init_rwsem(&lli->lli_xattrs_list_rwsem);
1132 mutex_init(&lli->lli_xattrs_enq_lock);
1134 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1135 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1136 lli->lli_opendir_key = NULL;
1137 lli->lli_sai = NULL;
1138 spin_lock_init(&lli->lli_sa_lock);
1139 lli->lli_opendir_pid = 0;
1140 lli->lli_sa_enabled = 0;
1141 init_rwsem(&lli->lli_lsm_sem);
1143 mutex_init(&lli->lli_size_mutex);
1144 mutex_init(&lli->lli_setattr_mutex);
1145 lli->lli_symlink_name = NULL;
1146 ll_trunc_sem_init(&lli->lli_trunc_sem);
1147 range_lock_tree_init(&lli->lli_write_tree);
1148 init_rwsem(&lli->lli_glimpse_sem);
1149 lli->lli_glimpse_time = ktime_set(0, 0);
1150 INIT_LIST_HEAD(&lli->lli_agl_list);
1151 lli->lli_agl_index = 0;
1152 lli->lli_async_rc = 0;
1153 spin_lock_init(&lli->lli_heat_lock);
1154 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1155 lli->lli_heat_flags = 0;
1156 mutex_init(&lli->lli_pcc_lock);
1157 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1158 lli->lli_pcc_inode = NULL;
1159 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1160 lli->lli_pcc_generation = 0;
1161 mutex_init(&lli->lli_group_mutex);
1162 lli->lli_group_users = 0;
1163 lli->lli_group_gid = 0;
1165 mutex_init(&lli->lli_layout_mutex);
1166 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1167 /* ll_cl_context initialize */
1168 INIT_LIST_HEAD(&lli->lli_lccs);
1171 #define MAX_STRING_SIZE 128
1173 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1175 #define LSI_BDI_INITIALIZED 0x00400000
1177 #ifndef HAVE_BDI_CAP_MAP_COPY
1178 # define BDI_CAP_MAP_COPY 0
1181 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1183 struct lustre_sb_info *lsi = s2lsi(sb);
1184 char buf[MAX_STRING_SIZE];
1188 err = bdi_init(&lsi->lsi_bdi);
1192 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1193 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1194 lsi->lsi_bdi.name = "lustre";
1195 va_start(args, fmt);
1196 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1198 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1201 sb->s_bdi = &lsi->lsi_bdi;
1205 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1207 int ll_fill_super(struct super_block *sb)
1209 struct lustre_profile *lprof = NULL;
1210 struct lustre_sb_info *lsi = s2lsi(sb);
1211 struct ll_sb_info *sbi = NULL;
1212 char *dt = NULL, *md = NULL;
1213 char *profilenm = get_profile_name(sb);
1214 struct config_llog_instance *cfg;
1215 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1216 const int instlen = LUSTRE_MAXINSTANCE + 2;
1217 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1218 char name[MAX_STRING_SIZE];
1227 /* for ASLR, to map between cfg_instance and hashed ptr */
1228 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1229 profilenm, cfg_instance, sb);
1231 OBD_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1235 GOTO(out_free_cfg, err = -ENOMEM);
1237 /* client additional sb info */
1238 lsi->lsi_llsbi = sbi = ll_init_sbi();
1240 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1242 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1244 GOTO(out_free_cfg, err);
1246 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1247 sb->s_d_op = &ll_d_ops;
1250 generate_random_uuid(uuid.b);
1251 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1253 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1256 len = strlen(profilenm);
1257 ptr = strrchr(profilenm, '-');
1258 if (ptr && (strcmp(ptr, "-client") == 0))
1261 if (len > LUSTRE_MAXFSNAME) {
1262 if (unlikely(len >= MAX_STRING_SIZE))
1263 len = MAX_STRING_SIZE - 1;
1264 strncpy(name, profilenm, len);
1266 err = -ENAMETOOLONG;
1267 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1268 name, LUSTRE_MAXFSNAME, err);
1269 GOTO(out_free_cfg, err);
1271 strncpy(sbi->ll_fsname, profilenm, len);
1272 sbi->ll_fsname[len] = '\0';
1275 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1276 profilenm, cfg_instance);
1278 err = super_setup_bdi_name(sb, "%s", name);
1280 GOTO(out_free_cfg, err);
1282 /* disable kernel readahead */
1283 sb->s_bdi->ra_pages = 0;
1285 /* Call ll_debugfs_register_super() before lustre_process_log()
1286 * so that "llite.*.*" params can be processed correctly.
1288 err = ll_debugfs_register_super(sb, name);
1290 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1291 sbi->ll_fsname, err);
1295 /* The cfg_instance is a value unique to this super, in case some
1296 * joker tries to mount the same fs at two mount points.
1298 cfg->cfg_instance = cfg_instance;
1299 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1300 cfg->cfg_callback = class_config_llog_handler;
1301 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1302 /* set up client obds */
1303 err = lustre_process_log(sb, profilenm, cfg);
1305 GOTO(out_debugfs, err);
1307 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1308 lprof = class_get_profile(profilenm);
1309 if (lprof == NULL) {
1310 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1311 " read from the MGS. Does that filesystem "
1312 "exist?\n", profilenm);
1313 GOTO(out_debugfs, err = -EINVAL);
1315 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1316 lprof->lp_md, lprof->lp_dt);
1318 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1319 OBD_ALLOC(dt, dt_len);
1321 GOTO(out_profile, err = -ENOMEM);
1322 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1324 md_len = strlen(lprof->lp_md) + instlen + 2;
1325 OBD_ALLOC(md, md_len);
1327 GOTO(out_free_dt, err = -ENOMEM);
1328 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1330 /* connections, registrations, sb setup */
1331 err = client_common_fill_super(sb, md, dt);
1333 GOTO(out_free_md, err);
1335 sbi->ll_client_common_fill_super_succeeded = 1;
1339 OBD_FREE(md, md_len);
1342 OBD_FREE(dt, dt_len);
1345 class_put_profile(lprof);
1348 ll_debugfs_unregister_super(sb);
1355 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1356 LCONSOLE_WARN("Mounted %s\n", profilenm);
1358 } /* ll_fill_super */
1360 void ll_put_super(struct super_block *sb)
1362 struct config_llog_instance cfg, params_cfg;
1363 struct obd_device *obd;
1364 struct lustre_sb_info *lsi = s2lsi(sb);
1365 struct ll_sb_info *sbi = ll_s2sbi(sb);
1366 char *profilenm = get_profile_name(sb);
1367 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1369 int next, force = 1, rc = 0;
1373 GOTO(out_no_sbi, 0);
1375 /* Should replace instance_id with something better for ASLR */
1376 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1377 profilenm, cfg_instance, sb);
1379 cfg.cfg_instance = cfg_instance;
1380 lustre_end_log(sb, profilenm, &cfg);
1382 params_cfg.cfg_instance = cfg_instance;
1383 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1385 if (sbi->ll_md_exp) {
1386 obd = class_exp2obd(sbi->ll_md_exp);
1388 force = obd->obd_force;
1391 /* Wait for unstable pages to be committed to stable storage */
1393 rc = l_wait_event_abortable(
1394 sbi->ll_cache->ccc_unstable_waitq,
1395 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1398 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1399 if (force == 0 && rc != -ERESTARTSYS)
1400 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1402 /* We need to set force before the lov_disconnect in
1403 * lustre_common_put_super, since l_d cleans up osc's as well.
1407 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1409 obd->obd_force = force;
1413 if (sbi->ll_client_common_fill_super_succeeded) {
1414 /* Only if client_common_fill_super succeeded */
1415 client_common_put_super(sb);
1419 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1420 class_manual_cleanup(obd);
1422 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1423 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1426 class_del_profile(profilenm);
1428 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1429 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1430 bdi_destroy(&lsi->lsi_bdi);
1431 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1436 lsi->lsi_llsbi = NULL;
1438 lustre_common_put_super(sb);
1440 cl_env_cache_purge(~0);
1443 } /* client_put_super */
1445 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1447 struct inode *inode = NULL;
1449 /* NOTE: we depend on atomic igrab() -bzzz */
1450 lock_res_and_lock(lock);
1451 if (lock->l_resource->lr_lvb_inode) {
1452 struct ll_inode_info * lli;
1453 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1454 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1455 inode = igrab(lock->l_resource->lr_lvb_inode);
1457 inode = lock->l_resource->lr_lvb_inode;
1458 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1459 D_WARNING, lock, "lr_lvb_inode %p is "
1460 "bogus: magic %08x",
1461 lock->l_resource->lr_lvb_inode,
1462 lli->lli_inode_magic);
1466 unlock_res_and_lock(lock);
1470 void ll_dir_clear_lsm_md(struct inode *inode)
1472 struct ll_inode_info *lli = ll_i2info(inode);
1474 LASSERT(S_ISDIR(inode->i_mode));
1476 if (lli->lli_lsm_md) {
1477 lmv_free_memmd(lli->lli_lsm_md);
1478 lli->lli_lsm_md = NULL;
1481 if (lli->lli_default_lsm_md) {
1482 lmv_free_memmd(lli->lli_default_lsm_md);
1483 lli->lli_default_lsm_md = NULL;
1487 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1488 const struct lu_fid *fid,
1489 struct lustre_md *md)
1491 struct ll_sb_info *sbi = ll_s2sbi(sb);
1492 struct ll_inode_info *lli;
1493 struct mdt_body *body = md->body;
1494 struct inode *inode;
1500 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1501 inode = iget_locked(sb, ino);
1502 if (inode == NULL) {
1503 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1504 sbi->ll_fsname, PFID(fid));
1505 RETURN(ERR_PTR(-ENOENT));
1508 lli = ll_i2info(inode);
1509 if (inode->i_state & I_NEW) {
1510 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1511 (body->mbo_mode & S_IFMT);
1512 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1515 inode->i_mtime.tv_sec = 0;
1516 inode->i_atime.tv_sec = 0;
1517 inode->i_ctime.tv_sec = 0;
1520 #ifdef HAVE_BACKING_DEV_INFO
1521 /* initializing backing dev info. */
1522 inode->i_mapping->backing_dev_info =
1523 &s2lsi(inode->i_sb)->lsi_bdi;
1525 inode->i_op = &ll_dir_inode_operations;
1526 inode->i_fop = &ll_dir_operations;
1527 lli->lli_fid = *fid;
1530 /* master object FID */
1531 lli->lli_pfid = body->mbo_fid1;
1532 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1533 lli, PFID(fid), PFID(&lli->lli_pfid));
1534 unlock_new_inode(inode);
1536 /* in directory restripe/auto-split, a directory will be
1537 * transformed to a stripe if it's plain, set its pfid here,
1538 * otherwise ll_lock_cancel_bits() can't find the master inode.
1540 lli->lli_pfid = body->mbo_fid1;
1546 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1549 struct lmv_stripe_md *lsm = md->lmv;
1550 struct ll_inode_info *lli = ll_i2info(inode);
1553 LASSERT(lsm != NULL);
1555 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1556 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1557 lsm_md_dump(D_INODE, lsm);
1559 if (!lmv_dir_striped(lsm))
1562 /* XXX sigh, this lsm_root initialization should be in
1563 * LMV layer, but it needs ll_iget right now, so we
1564 * put this here right now. */
1565 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1566 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1567 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1569 if (!fid_is_sane(fid))
1572 /* Unfortunately ll_iget will call ll_update_inode,
1573 * where the initialization of slave inode is slightly
1574 * different, so it reset lsm_md to NULL to avoid
1575 * initializing lsm for slave inode. */
1576 lsm->lsm_md_oinfo[i].lmo_root =
1577 ll_iget_anon_dir(inode->i_sb, fid, md);
1578 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1579 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1581 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1583 iput(lsm->lsm_md_oinfo[i].lmo_root);
1584 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1590 lli->lli_lsm_md = lsm;
1595 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1597 struct ll_inode_info *lli = ll_i2info(inode);
1601 if (!md->default_lmv) {
1602 /* clear default lsm */
1603 if (lli->lli_default_lsm_md) {
1604 down_write(&lli->lli_lsm_sem);
1605 if (lli->lli_default_lsm_md) {
1606 lmv_free_memmd(lli->lli_default_lsm_md);
1607 lli->lli_default_lsm_md = NULL;
1609 up_write(&lli->lli_lsm_sem);
1614 if (lli->lli_default_lsm_md) {
1615 /* do nonthing if default lsm isn't changed */
1616 down_read(&lli->lli_lsm_sem);
1617 if (lli->lli_default_lsm_md &&
1618 lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1619 up_read(&lli->lli_lsm_sem);
1622 up_read(&lli->lli_lsm_sem);
1625 down_write(&lli->lli_lsm_sem);
1626 if (lli->lli_default_lsm_md)
1627 lmv_free_memmd(lli->lli_default_lsm_md);
1628 lli->lli_default_lsm_md = md->default_lmv;
1629 lsm_md_dump(D_INODE, md->default_lmv);
1630 md->default_lmv = NULL;
1631 up_write(&lli->lli_lsm_sem);
1635 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1637 struct ll_inode_info *lli = ll_i2info(inode);
1638 struct lmv_stripe_md *lsm = md->lmv;
1639 struct cl_attr *attr;
1644 LASSERT(S_ISDIR(inode->i_mode));
1645 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1646 PFID(ll_inode2fid(inode)));
1648 /* update default LMV */
1649 if (md->default_lmv)
1650 ll_update_default_lsm_md(inode, md);
1652 /* after dir migration/restripe, a stripe may be turned into a
1653 * directory, in this case, zero out its lli_pfid.
1655 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1656 fid_zero(&lli->lli_pfid);
1659 * no striped information from request, lustre_md from req does not
1660 * include stripeEA, see ll_md_setattr()
1666 * normally dir layout doesn't change, only take read lock to check
1667 * that to avoid blocking other MD operations.
1669 down_read(&lli->lli_lsm_sem);
1671 /* some current lookup initialized lsm, and unchanged */
1672 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1673 GOTO(unlock, rc = 0);
1675 /* if dir layout doesn't match, check whether version is increased,
1676 * which means layout is changed, this happens in dir split/merge and
1679 * foreign LMV should not change.
1681 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1682 lsm->lsm_md_layout_version <=
1683 lli->lli_lsm_md->lsm_md_layout_version) {
1684 CERROR("%s: "DFID" dir layout mismatch:\n",
1685 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1686 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1687 lsm_md_dump(D_ERROR, lsm);
1688 GOTO(unlock, rc = -EINVAL);
1691 up_read(&lli->lli_lsm_sem);
1692 down_write(&lli->lli_lsm_sem);
1693 /* clear existing lsm */
1694 if (lli->lli_lsm_md) {
1695 lmv_free_memmd(lli->lli_lsm_md);
1696 lli->lli_lsm_md = NULL;
1699 rc = ll_init_lsm_md(inode, md);
1700 up_write(&lli->lli_lsm_sem);
1705 /* set md->lmv to NULL, so the following free lustre_md will not free
1710 /* md_merge_attr() may take long, since lsm is already set, switch to
1713 down_read(&lli->lli_lsm_sem);
1715 if (!lmv_dir_striped(lli->lli_lsm_md))
1716 GOTO(unlock, rc = 0);
1718 OBD_ALLOC_PTR(attr);
1720 GOTO(unlock, rc = -ENOMEM);
1722 /* validate the lsm */
1723 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1724 ll_md_blocking_ast);
1726 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1727 md->body->mbo_nlink = attr->cat_nlink;
1728 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1729 md->body->mbo_size = attr->cat_size;
1730 if (md->body->mbo_valid & OBD_MD_FLATIME)
1731 md->body->mbo_atime = attr->cat_atime;
1732 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1733 md->body->mbo_ctime = attr->cat_ctime;
1734 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1735 md->body->mbo_mtime = attr->cat_mtime;
1741 up_read(&lli->lli_lsm_sem);
1746 void ll_clear_inode(struct inode *inode)
1748 struct ll_inode_info *lli = ll_i2info(inode);
1749 struct ll_sb_info *sbi = ll_i2sbi(inode);
1753 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1754 PFID(ll_inode2fid(inode)), inode);
1756 if (S_ISDIR(inode->i_mode)) {
1757 /* these should have been cleared in ll_file_release */
1758 LASSERT(lli->lli_opendir_key == NULL);
1759 LASSERT(lli->lli_sai == NULL);
1760 LASSERT(lli->lli_opendir_pid == 0);
1762 pcc_inode_free(inode);
1765 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1767 LASSERT(!lli->lli_open_fd_write_count);
1768 LASSERT(!lli->lli_open_fd_read_count);
1769 LASSERT(!lli->lli_open_fd_exec_count);
1771 if (lli->lli_mds_write_och)
1772 ll_md_real_close(inode, FMODE_WRITE);
1773 if (lli->lli_mds_exec_och)
1774 ll_md_real_close(inode, FMODE_EXEC);
1775 if (lli->lli_mds_read_och)
1776 ll_md_real_close(inode, FMODE_READ);
1778 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1779 OBD_FREE(lli->lli_symlink_name,
1780 strlen(lli->lli_symlink_name) + 1);
1781 lli->lli_symlink_name = NULL;
1784 ll_xattr_cache_destroy(inode);
1786 forget_all_cached_acls(inode);
1788 lli->lli_inode_magic = LLI_INODE_DEAD;
1790 if (S_ISDIR(inode->i_mode))
1791 ll_dir_clear_lsm_md(inode);
1792 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1793 LASSERT(list_empty(&lli->lli_agl_list));
1796 * XXX This has to be done before lsm is freed below, because
1797 * cl_object still uses inode lsm.
1799 cl_inode_fini(inode);
1801 llcrypt_put_encryption_info(inode);
1806 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1808 struct lustre_md md;
1809 struct inode *inode = dentry->d_inode;
1810 struct ll_sb_info *sbi = ll_i2sbi(inode);
1811 struct ptlrpc_request *request = NULL;
1816 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1817 LUSTRE_OPC_ANY, NULL);
1818 if (IS_ERR(op_data))
1819 RETURN(PTR_ERR(op_data));
1821 /* If this is a chgrp of a regular file, we want to reserve enough
1822 * quota to cover the entire file size.
1824 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1825 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1826 from_kgid(&init_user_ns, inode->i_gid)) {
1827 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1828 op_data->op_attr_blocks = inode->i_blocks;
1832 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1834 ptlrpc_req_finished(request);
1835 if (rc == -ENOENT) {
1837 /* Unlinked special device node? Or just a race?
1838 * Pretend we done everything. */
1839 if (!S_ISREG(inode->i_mode) &&
1840 !S_ISDIR(inode->i_mode)) {
1841 ia_valid = op_data->op_attr.ia_valid;
1842 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1843 rc = simple_setattr(dentry, &op_data->op_attr);
1844 op_data->op_attr.ia_valid = ia_valid;
1846 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1847 CERROR("md_setattr fails: rc = %d\n", rc);
1852 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1853 sbi->ll_md_exp, &md);
1855 ptlrpc_req_finished(request);
1859 ia_valid = op_data->op_attr.ia_valid;
1860 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1861 * cache is not cleared yet. */
1862 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1863 if (S_ISREG(inode->i_mode))
1865 rc = simple_setattr(dentry, &op_data->op_attr);
1866 if (S_ISREG(inode->i_mode))
1867 inode_unlock(inode);
1868 op_data->op_attr.ia_valid = ia_valid;
1870 rc = ll_update_inode(inode, &md);
1871 ptlrpc_req_finished(request);
1877 * Zero portion of page that is part of @inode.
1878 * This implies, if necessary:
1879 * - taking cl_lock on range corresponding to concerned page
1880 * - grabbing vm page
1881 * - associating cl_page
1882 * - proceeding to clio read
1883 * - zeroing range in page
1884 * - proceeding to cl_page flush
1885 * - releasing cl_lock
1887 * \param[in] inode inode
1888 * \param[in] index page index
1889 * \param[in] offset offset in page to start zero from
1890 * \param[in] len len to zero
1892 * \retval 0 on success
1893 * \retval negative errno on failure
1895 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
1898 struct ll_inode_info *lli = ll_i2info(inode);
1899 struct cl_object *clob = lli->lli_clob;
1901 struct lu_env *env = NULL;
1902 struct cl_io *io = NULL;
1903 struct cl_page *clpage = NULL;
1904 struct page *vmpage = NULL;
1905 unsigned from = index << PAGE_SHIFT;
1906 struct cl_lock *lock = NULL;
1907 struct cl_lock_descr *descr = NULL;
1908 struct cl_2queue *queue = NULL;
1909 struct cl_sync_io *anchor = NULL;
1910 bool holdinglock = false;
1911 bool lockedbymyself = true;
1916 env = cl_env_get(&refcheck);
1918 RETURN(PTR_ERR(env));
1920 io = vvp_env_thread_io(env);
1922 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
1926 lock = vvp_env_lock(env);
1927 descr = &lock->cll_descr;
1928 descr->cld_obj = io->ci_obj;
1929 descr->cld_start = cl_index(io->ci_obj, from);
1930 descr->cld_end = cl_index(io->ci_obj, from + PAGE_SIZE - 1);
1931 descr->cld_mode = CLM_WRITE;
1932 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
1934 /* request lock for page */
1935 rc = cl_lock_request(env, io, lock);
1936 /* -ECANCELED indicates a matching lock with a different extent
1937 * was already present, and -EEXIST indicates a matching lock
1938 * on exactly the same extent was already present.
1939 * In both cases it means we are covered.
1941 if (rc == -ECANCELED || rc == -EEXIST)
1949 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
1951 GOTO(rellock, rc = -EOPNOTSUPP);
1953 if (!PageDirty(vmpage)) {
1954 /* associate cl_page */
1955 clpage = cl_page_find(env, clob, vmpage->index,
1956 vmpage, CPT_CACHEABLE);
1958 GOTO(pagefini, rc = PTR_ERR(clpage));
1960 cl_page_assume(env, io, clpage);
1963 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
1964 !PageWriteback(vmpage)) {
1966 /* set PagePrivate2 to detect special case of empty page
1967 * in osc_brw_fini_request()
1969 SetPagePrivate2(vmpage);
1970 rc = ll_io_read_page(env, io, clpage, NULL);
1971 if (!PagePrivate2(vmpage))
1972 /* PagePrivate2 was cleared in osc_brw_fini_request()
1973 * meaning we read an empty page. In this case, in order
1974 * to avoid allocating unnecessary block in truncated
1975 * file, we must not zero and write as below. Subsequent
1976 * server-side truncate will handle things correctly.
1978 GOTO(clpfini, rc = 0);
1979 ClearPagePrivate2(vmpage);
1982 lockedbymyself = trylock_page(vmpage);
1983 cl_page_assume(env, io, clpage);
1986 /* zero range in page */
1987 zero_user(vmpage, offset, len);
1989 if (holdinglock && clpage) {
1990 /* explicitly write newly modified page */
1991 queue = &io->ci_queue;
1992 cl_2queue_init(queue);
1993 anchor = &vvp_env_info(env)->vti_anchor;
1994 cl_sync_io_init(anchor, 1);
1995 clpage->cp_sync_io = anchor;
1996 cl_2queue_add(queue, clpage, true);
1997 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
1999 GOTO(queuefini1, rc);
2000 rc = cl_sync_io_wait(env, anchor, 0);
2002 GOTO(queuefini2, rc);
2003 cl_page_assume(env, io, clpage);
2006 cl_2queue_discard(env, io, queue);
2008 cl_2queue_disown(env, io, queue);
2009 cl_2queue_fini(env, queue);
2014 cl_page_put(env, clpage);
2016 if (lockedbymyself) {
2017 unlock_page(vmpage);
2022 cl_lock_release(env, lock);
2024 cl_io_fini(env, io);
2027 cl_env_put(env, &refcheck);
2033 * Get reference file from volatile file name.
2034 * Volatile file name may look like:
2035 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2036 * where fd is opened descriptor of reference file.
2038 * \param[in] volatile_name volatile file name
2039 * \param[in] volatile_len volatile file name length
2040 * \param[out] ref_file pointer to struct file of reference file
2042 * \retval 0 on success
2043 * \retval negative errno on failure
2045 int volatile_ref_file(const char *volatile_name, int volatile_len,
2046 struct file **ref_file)
2048 char *p, *q, *fd_str;
2051 p = strnstr(volatile_name, ":fd=", volatile_len);
2052 if (!p || strlen(p + 4) == 0)
2055 q = strchrnul(p + 4, ':');
2056 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2059 rc = kstrtouint(fd_str, 10, &fd);
2064 *ref_file = fget(fd);
2070 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2071 * object(s) determine the file size and mtime. Otherwise, the MDS will
2072 * keep these values until such a time that objects are allocated for it.
2073 * We do the MDS operations first, as it is checking permissions for us.
2074 * We don't to the MDS RPC if there is nothing that we want to store there,
2075 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2076 * going to do an RPC anyways.
2078 * If we are doing a truncate, we will send the mtime and ctime updates
2079 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2080 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2083 * In case of HSMimport, we only set attr on MDS.
2085 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2086 enum op_xvalid xvalid, bool hsm_import)
2088 struct inode *inode = dentry->d_inode;
2089 struct ll_inode_info *lli = ll_i2info(inode);
2090 struct md_op_data *op_data = NULL;
2091 ktime_t kstart = ktime_get();
2096 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2097 "valid %x, hsm_import %d\n",
2098 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2099 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2102 if (attr->ia_valid & ATTR_SIZE) {
2103 /* Check new size against VFS/VM file size limit and rlimit */
2104 rc = inode_newsize_ok(inode, attr->ia_size);
2108 /* The maximum Lustre file size is variable, based on the
2109 * OST maximum object size and number of stripes. This
2110 * needs another check in addition to the VFS check above. */
2111 if (attr->ia_size > ll_file_maxbytes(inode)) {
2112 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2113 PFID(&lli->lli_fid), attr->ia_size,
2114 ll_file_maxbytes(inode));
2118 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2121 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2122 if (attr->ia_valid & TIMES_SET_FLAGS) {
2123 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2124 !capable(CAP_FOWNER))
2128 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2129 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2130 (attr->ia_valid & ATTR_CTIME)) {
2131 attr->ia_ctime = current_time(inode);
2132 xvalid |= OP_XVALID_CTIME_SET;
2134 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2135 (attr->ia_valid & ATTR_ATIME)) {
2136 attr->ia_atime = current_time(inode);
2137 attr->ia_valid |= ATTR_ATIME_SET;
2139 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2140 (attr->ia_valid & ATTR_MTIME)) {
2141 attr->ia_mtime = current_time(inode);
2142 attr->ia_valid |= ATTR_MTIME_SET;
2145 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2146 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2147 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2148 ktime_get_real_seconds());
2150 if (S_ISREG(inode->i_mode))
2151 inode_unlock(inode);
2153 /* We always do an MDS RPC, even if we're only changing the size;
2154 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2156 OBD_ALLOC_PTR(op_data);
2157 if (op_data == NULL)
2158 GOTO(out, rc = -ENOMEM);
2160 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2161 /* If we are changing file size, file content is
2162 * modified, flag it.
2164 xvalid |= OP_XVALID_OWNEROVERRIDE;
2165 op_data->op_bias |= MDS_DATA_MODIFIED;
2166 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2169 if (attr->ia_valid & ATTR_FILE) {
2170 struct ll_file_data *fd = attr->ia_file->private_data;
2172 if (fd->fd_lease_och)
2173 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2176 op_data->op_attr = *attr;
2177 op_data->op_xvalid = xvalid;
2179 rc = ll_md_setattr(dentry, op_data);
2183 if (!S_ISREG(inode->i_mode) || hsm_import)
2186 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2187 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2188 xvalid & OP_XVALID_CTIME_SET) {
2189 bool cached = false;
2191 rc = pcc_inode_setattr(inode, attr, &cached);
2194 CERROR("%s: PCC inode "DFID" setattr failed: "
2196 ll_i2sbi(inode)->ll_fsname,
2197 PFID(&lli->lli_fid), rc);
2201 unsigned int flags = 0;
2203 /* For truncate and utimes sending attributes to OSTs,
2204 * setting mtime/atime to the past will be performed
2205 * under PW [0:EOF] extent lock (new_size:EOF for
2206 * truncate). It may seem excessive to send mtime/atime
2207 * updates to OSTs when not setting times to past, but
2208 * it is necessary due to possible time
2209 * de-synchronization between MDT inode and OST objects
2211 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2212 xvalid |= OP_XVALID_FLAGS;
2213 flags = LUSTRE_ENCRYPT_FL;
2214 /* Call to ll_io_zero_page is not necessary if
2215 * truncating on PAGE_SIZE boundary, because
2216 * whole pages will be wiped.
2217 * In case of Direct IO, all we need is to set
2220 if (attr->ia_valid & ATTR_SIZE &&
2221 attr->ia_size & ~PAGE_MASK &&
2222 !(attr->ia_valid & ATTR_FILE &&
2223 attr->ia_file->f_flags & O_DIRECT)) {
2225 attr->ia_size & (PAGE_SIZE - 1);
2227 rc = ll_io_zero_page(inode,
2228 attr->ia_size >> PAGE_SHIFT,
2229 offset, PAGE_SIZE - offset);
2233 /* If encrypted volatile file without the key,
2234 * we need to fetch size from reference file,
2235 * and set it on OST objects. This happens when
2236 * migrating or extending an encrypted file
2239 if (filename_is_volatile(dentry->d_name.name,
2242 llcrypt_require_key(inode) == -ENOKEY) {
2243 struct file *ref_file;
2244 struct inode *ref_inode;
2245 struct ll_inode_info *ref_lli;
2246 struct cl_object *ref_obj;
2247 struct cl_attr ref_attr = { 0 };
2251 rc = volatile_ref_file(
2252 dentry->d_name.name,
2258 ref_inode = file_inode(ref_file);
2261 GOTO(out, rc = -EINVAL);
2264 env = cl_env_get(&refcheck);
2266 GOTO(out, rc = PTR_ERR(env));
2268 ref_lli = ll_i2info(ref_inode);
2269 ref_obj = ref_lli->lli_clob;
2270 cl_object_attr_lock(ref_obj);
2271 rc = cl_object_attr_get(env, ref_obj,
2273 cl_object_attr_unlock(ref_obj);
2274 cl_env_put(env, &refcheck);
2279 attr->ia_valid |= ATTR_SIZE;
2280 attr->ia_size = ref_attr.cat_size;
2283 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2287 /* If the file was restored, it needs to set dirty flag.
2289 * We've already sent MDS_DATA_MODIFIED flag in
2290 * ll_md_setattr() for truncate. However, the MDT refuses to
2291 * set the HS_DIRTY flag on released files, so we have to set
2292 * it again if the file has been restored. Please check how
2293 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2295 * Please notice that if the file is not released, the previous
2296 * MDS_DATA_MODIFIED has taken effect and usually
2297 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2298 * This way we can save an RPC for common open + trunc
2300 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2301 struct hsm_state_set hss = {
2302 .hss_valid = HSS_SETMASK,
2303 .hss_setmask = HS_DIRTY,
2307 rc2 = ll_hsm_state_set(inode, &hss);
2308 /* truncate and write can happen at the same time, so that
2309 * the file can be set modified even though the file is not
2310 * restored from released state, and ll_hsm_state_set() is
2311 * not applicable for the file, and rc2 < 0 is normal in this
2314 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2315 PFID(ll_inode2fid(inode)), rc2);
2320 if (op_data != NULL)
2321 ll_finish_md_op_data(op_data);
2323 if (S_ISREG(inode->i_mode)) {
2325 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2326 inode_dio_wait(inode);
2327 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2328 * flag. ll_update_inode (called from ll_md_setattr), clears
2329 * inode flags, so there is a gap where S_NOSEC is not set.
2330 * This can cause a writer to take the i_mutex unnecessarily,
2331 * but this is safe to do and should be rare. */
2332 inode_has_no_xattr(inode);
2336 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2337 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2338 ktime_us_delta(ktime_get(), kstart));
2343 int ll_setattr(struct dentry *de, struct iattr *attr)
2345 int mode = de->d_inode->i_mode;
2346 enum op_xvalid xvalid = 0;
2349 rc = llcrypt_prepare_setattr(de, attr);
2353 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2354 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2355 xvalid |= OP_XVALID_OWNEROVERRIDE;
2357 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2358 (ATTR_SIZE|ATTR_MODE)) &&
2359 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2360 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2361 !(attr->ia_mode & S_ISGID))))
2362 attr->ia_valid |= ATTR_FORCE;
2364 if ((attr->ia_valid & ATTR_MODE) &&
2366 !(attr->ia_mode & S_ISUID) &&
2367 !(attr->ia_valid & ATTR_KILL_SUID))
2368 attr->ia_valid |= ATTR_KILL_SUID;
2370 if ((attr->ia_valid & ATTR_MODE) &&
2371 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2372 !(attr->ia_mode & S_ISGID) &&
2373 !(attr->ia_valid & ATTR_KILL_SGID))
2374 attr->ia_valid |= ATTR_KILL_SGID;
2376 return ll_setattr_raw(de, attr, xvalid, false);
2379 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2382 struct obd_statfs obd_osfs = { 0 };
2387 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2389 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2390 flags |= OBD_STATFS_NODELAY;
2392 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2396 osfs->os_type = LL_SUPER_MAGIC;
2398 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2399 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2401 if (osfs->os_state & OS_STATFS_SUM)
2404 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2405 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2408 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2409 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2412 osfs->os_bsize = obd_osfs.os_bsize;
2413 osfs->os_blocks = obd_osfs.os_blocks;
2414 osfs->os_bfree = obd_osfs.os_bfree;
2415 osfs->os_bavail = obd_osfs.os_bavail;
2417 /* If we have _some_ OSTs, but don't have as many free objects on the
2418 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2419 * to compensate, so that the "inodes in use" number is correct.
2420 * This should be kept in sync with lod_statfs() behaviour.
2422 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2423 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2425 osfs->os_ffree = obd_osfs.os_ffree;
2432 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2434 struct if_quotactl qctl = {
2435 .qc_cmd = LUSTRE_Q_GETQUOTA,
2436 .qc_type = PRJQUOTA,
2437 .qc_valid = QC_GENERAL,
2439 u64 limit, curblock;
2442 qctl.qc_id = ll_i2info(inode)->lli_projid;
2443 ret = quotactl_ioctl(inode->i_sb, &qctl);
2445 /* ignore errors if project ID does not have
2446 * a quota limit or feature unsupported.
2448 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2453 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2454 qctl.qc_dqblk.dqb_bsoftlimit :
2455 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2456 if (limit && sfs->f_blocks > limit) {
2457 curblock = (qctl.qc_dqblk.dqb_curspace +
2458 sfs->f_bsize - 1) / sfs->f_bsize;
2459 sfs->f_blocks = limit;
2460 sfs->f_bfree = sfs->f_bavail =
2461 (sfs->f_blocks > curblock) ?
2462 (sfs->f_blocks - curblock) : 0;
2465 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2466 qctl.qc_dqblk.dqb_isoftlimit :
2467 qctl.qc_dqblk.dqb_ihardlimit;
2468 if (limit && sfs->f_files > limit) {
2469 sfs->f_files = limit;
2470 sfs->f_ffree = (sfs->f_files >
2471 qctl.qc_dqblk.dqb_curinodes) ?
2472 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2478 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2480 struct super_block *sb = de->d_sb;
2481 struct obd_statfs osfs;
2482 __u64 fsid = huge_encode_dev(sb->s_dev);
2483 ktime_t kstart = ktime_get();
2486 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2488 /* Some amount of caching on the client is allowed */
2489 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2493 statfs_unpack(sfs, &osfs);
2495 /* We need to downshift for all 32-bit kernels, because we can't
2496 * tell if the kernel is being called via sys_statfs64() or not.
2497 * Stop before overflowing f_bsize - in which case it is better
2498 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2499 if (sizeof(long) < 8) {
2500 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2503 osfs.os_blocks >>= 1;
2504 osfs.os_bfree >>= 1;
2505 osfs.os_bavail >>= 1;
2509 sfs->f_blocks = osfs.os_blocks;
2510 sfs->f_bfree = osfs.os_bfree;
2511 sfs->f_bavail = osfs.os_bavail;
2512 sfs->f_fsid.val[0] = (__u32)fsid;
2513 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2514 if (ll_i2info(de->d_inode)->lli_projid)
2515 return ll_statfs_project(de->d_inode, sfs);
2517 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2518 ktime_us_delta(ktime_get(), kstart));
2523 void ll_inode_size_lock(struct inode *inode)
2525 struct ll_inode_info *lli;
2527 LASSERT(!S_ISDIR(inode->i_mode));
2529 lli = ll_i2info(inode);
2530 mutex_lock(&lli->lli_size_mutex);
2533 void ll_inode_size_unlock(struct inode *inode)
2535 struct ll_inode_info *lli;
2537 lli = ll_i2info(inode);
2538 mutex_unlock(&lli->lli_size_mutex);
2541 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2543 /* do not clear encryption flag */
2544 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2545 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2546 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2547 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2549 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2552 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2554 struct ll_inode_info *lli = ll_i2info(inode);
2555 struct mdt_body *body = md->body;
2556 struct ll_sb_info *sbi = ll_i2sbi(inode);
2560 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2561 rc = cl_file_inode_init(inode, md);
2566 if (S_ISDIR(inode->i_mode)) {
2567 rc = ll_update_lsm_md(inode, md);
2572 if (body->mbo_valid & OBD_MD_FLACL)
2573 lli_replace_acl(lli, md);
2575 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2576 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2577 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2579 if (body->mbo_valid & OBD_MD_FLATIME) {
2580 if (body->mbo_atime > inode->i_atime.tv_sec)
2581 inode->i_atime.tv_sec = body->mbo_atime;
2582 lli->lli_atime = body->mbo_atime;
2585 if (body->mbo_valid & OBD_MD_FLMTIME) {
2586 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2588 "setting ino %lu mtime from %lld to %llu\n",
2589 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2591 inode->i_mtime.tv_sec = body->mbo_mtime;
2593 lli->lli_mtime = body->mbo_mtime;
2596 if (body->mbo_valid & OBD_MD_FLCTIME) {
2597 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2598 inode->i_ctime.tv_sec = body->mbo_ctime;
2599 lli->lli_ctime = body->mbo_ctime;
2602 if (body->mbo_valid & OBD_MD_FLBTIME)
2603 lli->lli_btime = body->mbo_btime;
2605 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2606 if (body->mbo_valid & OBD_MD_FLFLAGS)
2607 ll_update_inode_flags(inode, body->mbo_flags);
2608 if (body->mbo_valid & OBD_MD_FLMODE)
2609 inode->i_mode = (inode->i_mode & S_IFMT) |
2610 (body->mbo_mode & ~S_IFMT);
2612 if (body->mbo_valid & OBD_MD_FLTYPE)
2613 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2614 (body->mbo_mode & S_IFMT);
2616 LASSERT(inode->i_mode != 0);
2617 if (body->mbo_valid & OBD_MD_FLUID)
2618 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2619 if (body->mbo_valid & OBD_MD_FLGID)
2620 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2621 if (body->mbo_valid & OBD_MD_FLPROJID)
2622 lli->lli_projid = body->mbo_projid;
2623 if (body->mbo_valid & OBD_MD_FLNLINK) {
2624 spin_lock(&inode->i_lock);
2625 set_nlink(inode, body->mbo_nlink);
2626 spin_unlock(&inode->i_lock);
2628 if (body->mbo_valid & OBD_MD_FLRDEV)
2629 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2631 if (body->mbo_valid & OBD_MD_FLID) {
2632 /* FID shouldn't be changed! */
2633 if (fid_is_sane(&lli->lli_fid)) {
2634 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2635 "Trying to change FID "DFID
2636 " to the "DFID", inode "DFID"(%p)\n",
2637 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2638 PFID(ll_inode2fid(inode)), inode);
2640 lli->lli_fid = body->mbo_fid1;
2644 LASSERT(fid_seq(&lli->lli_fid) != 0);
2646 /* In case of encrypted file without the key, please do not lose
2647 * clear text size stored into lli_lazysize in ll_merge_attr(),
2648 * we will need it in ll_prepare_close().
2650 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2651 llcrypt_require_key(inode) == -ENOKEY)
2652 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2654 lli->lli_attr_valid = body->mbo_valid;
2655 if (body->mbo_valid & OBD_MD_FLSIZE) {
2656 i_size_write(inode, body->mbo_size);
2658 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2659 PFID(ll_inode2fid(inode)),
2660 (unsigned long long)body->mbo_size);
2662 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2663 inode->i_blocks = body->mbo_blocks;
2665 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2666 lli->lli_lazysize = body->mbo_size;
2667 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2668 lli->lli_lazyblocks = body->mbo_blocks;
2671 if (body->mbo_valid & OBD_MD_TSTATE) {
2672 /* Set LLIF_FILE_RESTORING if restore ongoing and
2673 * clear it when done to ensure to start again
2674 * glimpsing updated attrs
2676 if (body->mbo_t_state & MS_RESTORE)
2677 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2679 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2685 /* update directory depth to ROOT, called after LOOKUP lock is fetched. */
2686 void ll_update_dir_depth(struct inode *dir, struct inode *inode)
2688 struct ll_inode_info *lli;
2690 if (!S_ISDIR(inode->i_mode))
2696 lli = ll_i2info(inode);
2697 lli->lli_depth = ll_i2info(dir)->lli_depth + 1;
2698 CDEBUG(D_INODE, DFID" depth %hu\n", PFID(&lli->lli_fid), lli->lli_depth);
2701 void ll_truncate_inode_pages_final(struct inode *inode)
2703 struct address_space *mapping = &inode->i_data;
2704 unsigned long nrpages;
2705 unsigned long flags;
2707 truncate_inode_pages_final(mapping);
2709 /* Workaround for LU-118: Note nrpages may not be totally updated when
2710 * truncate_inode_pages() returns, as there can be a page in the process
2711 * of deletion (inside __delete_from_page_cache()) in the specified
2712 * range. Thus mapping->nrpages can be non-zero when this function
2713 * returns even after truncation of the whole mapping. Only do this if
2714 * npages isn't already zero.
2716 nrpages = mapping->nrpages;
2718 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2719 nrpages = mapping->nrpages;
2720 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2721 } /* Workaround end */
2723 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, "
2724 "see https://jira.whamcloud.com/browse/LU-118\n",
2725 ll_i2sbi(inode)->ll_fsname,
2726 PFID(ll_inode2fid(inode)), inode, nrpages);
2729 int ll_read_inode2(struct inode *inode, void *opaque)
2731 struct lustre_md *md = opaque;
2732 struct ll_inode_info *lli = ll_i2info(inode);
2736 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2737 PFID(&lli->lli_fid), inode);
2739 /* Core attributes from the MDS first. This is a new inode, and
2740 * the VFS doesn't zero times in the core inode so we have to do
2741 * it ourselves. They will be overwritten by either MDS or OST
2742 * attributes - we just need to make sure they aren't newer.
2744 inode->i_mtime.tv_sec = 0;
2745 inode->i_atime.tv_sec = 0;
2746 inode->i_ctime.tv_sec = 0;
2748 rc = ll_update_inode(inode, md);
2752 /* OIDEBUG(inode); */
2754 #ifdef HAVE_BACKING_DEV_INFO
2755 /* initializing backing dev info. */
2756 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2758 if (S_ISREG(inode->i_mode)) {
2759 struct ll_sb_info *sbi = ll_i2sbi(inode);
2760 inode->i_op = &ll_file_inode_operations;
2761 inode->i_fop = sbi->ll_fop;
2762 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2764 } else if (S_ISDIR(inode->i_mode)) {
2765 inode->i_op = &ll_dir_inode_operations;
2766 inode->i_fop = &ll_dir_operations;
2768 } else if (S_ISLNK(inode->i_mode)) {
2769 inode->i_op = &ll_fast_symlink_inode_operations;
2772 inode->i_op = &ll_special_inode_operations;
2774 init_special_inode(inode, inode->i_mode,
2783 void ll_delete_inode(struct inode *inode)
2785 struct ll_inode_info *lli = ll_i2info(inode);
2788 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2789 /* It is last chance to write out dirty pages,
2790 * otherwise we may lose data while umount.
2792 * If i_nlink is 0 then just discard data. This is safe because
2793 * local inode gets i_nlink 0 from server only for the last
2794 * unlink, so that file is not opened somewhere else
2796 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2797 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2800 ll_truncate_inode_pages_final(inode);
2801 ll_clear_inode(inode);
2807 int ll_iocontrol(struct inode *inode, struct file *file,
2808 unsigned int cmd, unsigned long arg)
2810 struct ll_sb_info *sbi = ll_i2sbi(inode);
2811 struct ptlrpc_request *req = NULL;
2816 case FS_IOC_GETFLAGS: {
2817 struct mdt_body *body;
2818 struct md_op_data *op_data;
2820 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2821 0, 0, LUSTRE_OPC_ANY,
2823 if (IS_ERR(op_data))
2824 RETURN(PTR_ERR(op_data));
2826 op_data->op_valid = OBD_MD_FLFLAGS;
2827 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2828 ll_finish_md_op_data(op_data);
2830 CERROR("%s: failure inode "DFID": rc = %d\n",
2831 sbi->ll_md_exp->exp_obd->obd_name,
2832 PFID(ll_inode2fid(inode)), rc);
2836 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2838 flags = body->mbo_flags;
2840 ptlrpc_req_finished(req);
2842 RETURN(put_user(flags, (int __user *)arg));
2844 case FS_IOC_SETFLAGS: {
2846 struct md_op_data *op_data;
2847 struct cl_object *obj;
2848 struct fsxattr fa = { 0 };
2850 if (get_user(flags, (int __user *)arg))
2853 fa.fsx_projid = ll_i2info(inode)->lli_projid;
2854 if (flags & LUSTRE_PROJINHERIT_FL)
2855 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
2857 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
2862 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
2863 LUSTRE_OPC_ANY, NULL);
2864 if (IS_ERR(op_data))
2865 RETURN(PTR_ERR(op_data));
2867 op_data->op_attr_flags = flags;
2868 op_data->op_xvalid |= OP_XVALID_FLAGS;
2869 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
2870 ll_finish_md_op_data(op_data);
2871 ptlrpc_req_finished(req);
2875 ll_update_inode_flags(inode, flags);
2877 obj = ll_i2info(inode)->lli_clob;
2881 OBD_ALLOC_PTR(attr);
2885 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
2897 int ll_flush_ctx(struct inode *inode)
2899 struct ll_sb_info *sbi = ll_i2sbi(inode);
2901 CDEBUG(D_SEC, "flush context for user %d\n",
2902 from_kuid(&init_user_ns, current_uid()));
2904 obd_set_info_async(NULL, sbi->ll_md_exp,
2905 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2907 obd_set_info_async(NULL, sbi->ll_dt_exp,
2908 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2913 /* umount -f client means force down, don't save state */
2914 void ll_umount_begin(struct super_block *sb)
2916 struct ll_sb_info *sbi = ll_s2sbi(sb);
2917 struct obd_device *obd;
2918 struct obd_ioctl_data *ioc_data;
2922 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2923 sb->s_count, atomic_read(&sb->s_active));
2925 obd = class_exp2obd(sbi->ll_md_exp);
2927 CERROR("Invalid MDC connection handle %#llx\n",
2928 sbi->ll_md_exp->exp_handle.h_cookie);
2934 obd = class_exp2obd(sbi->ll_dt_exp);
2936 CERROR("Invalid LOV connection handle %#llx\n",
2937 sbi->ll_dt_exp->exp_handle.h_cookie);
2943 OBD_ALLOC_PTR(ioc_data);
2945 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2946 sizeof *ioc_data, ioc_data, NULL);
2948 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2949 sizeof *ioc_data, ioc_data, NULL);
2951 OBD_FREE_PTR(ioc_data);
2954 /* Really, we'd like to wait until there are no requests outstanding,
2955 * and then continue. For now, we just periodically checking for vfs
2956 * to decrement mnt_cnt and hope to finish it within 10sec.
2960 !may_umount(sbi->ll_mnt.mnt)) {
2968 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2970 struct ll_sb_info *sbi = ll_s2sbi(sb);
2971 char *profilenm = get_profile_name(sb);
2975 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
2976 read_only = *flags & MS_RDONLY;
2977 err = obd_set_info_async(NULL, sbi->ll_md_exp,
2978 sizeof(KEY_READ_ONLY),
2979 KEY_READ_ONLY, sizeof(read_only),
2982 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2983 profilenm, read_only ?
2984 "read-only" : "read-write", err);
2989 sb->s_flags |= SB_RDONLY;
2991 sb->s_flags &= ~SB_RDONLY;
2993 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
2994 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
2995 read_only ? "read-only" : "read-write");
3001 * Cleanup the open handle that is cached on MDT-side.
3003 * For open case, the client side open handling thread may hit error
3004 * after the MDT grant the open. Under such case, the client should
3005 * send close RPC to the MDT as cleanup; otherwise, the open handle
3006 * on the MDT will be leaked there until the client umount or evicted.
3008 * In further, if someone unlinked the file, because the open handle
3009 * holds the reference on such file/object, then it will block the
3010 * subsequent threads that want to locate such object via FID.
3012 * \param[in] sb super block for this file-system
3013 * \param[in] open_req pointer to the original open request
3015 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3017 struct mdt_body *body;
3018 struct md_op_data *op_data;
3019 struct ptlrpc_request *close_req = NULL;
3020 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3023 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3024 OBD_ALLOC_PTR(op_data);
3025 if (op_data == NULL) {
3026 CWARN("%s: cannot allocate op_data to release open handle for "
3027 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3032 op_data->op_fid1 = body->mbo_fid1;
3033 op_data->op_open_handle = body->mbo_open_handle;
3034 op_data->op_mod_time = ktime_get_real_seconds();
3035 md_close(exp, op_data, NULL, &close_req);
3036 ptlrpc_req_finished(close_req);
3037 ll_finish_md_op_data(op_data);
3042 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3043 struct super_block *sb, struct lookup_intent *it)
3045 struct ll_sb_info *sbi = NULL;
3046 struct lustre_md md = { NULL };
3047 bool default_lmv_deleted = false;
3052 LASSERT(*inode || sb);
3053 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3054 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3055 sbi->ll_md_exp, &md);
3060 * clear default_lmv only if intent_getattr reply doesn't contain it.
3061 * but it needs to be done after iget, check this early because
3062 * ll_update_lsm_md() may change md.
3064 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3065 S_ISDIR(md.body->mbo_mode) && !md.default_lmv)
3066 default_lmv_deleted = true;
3069 rc = ll_update_inode(*inode, &md);
3073 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3074 struct lu_fid *fid1 = &md.body->mbo_fid1;
3076 LASSERT(sb != NULL);
3079 * At this point server returns to client's same fid as client
3080 * generated for creating. So using ->fid1 is okay here.
3082 if (!fid_is_sane(fid1)) {
3083 CERROR("%s: Fid is insane "DFID"\n",
3084 sbi->ll_fsname, PFID(fid1));
3085 GOTO(out, rc = -EINVAL);
3088 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3089 if (IS_ERR(*inode)) {
3091 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3093 CERROR("new_inode -fatal: rc %d\n", rc);
3098 /* Handling piggyback layout lock.
3099 * Layout lock can be piggybacked by getattr and open request.
3100 * The lsm can be applied to inode only if it comes with a layout lock
3101 * otherwise correct layout may be overwritten, for example:
3102 * 1. proc1: mdt returns a lsm but not granting layout
3103 * 2. layout was changed by another client
3104 * 3. proc2: refresh layout and layout lock granted
3105 * 4. proc1: to apply a stale layout */
3106 if (it != NULL && it->it_lock_mode != 0) {
3107 struct lustre_handle lockh;
3108 struct ldlm_lock *lock;
3110 lockh.cookie = it->it_lock_handle;
3111 lock = ldlm_handle2lock(&lockh);
3112 LASSERT(lock != NULL);
3113 if (ldlm_has_layout(lock)) {
3114 struct cl_object_conf conf;
3116 memset(&conf, 0, sizeof(conf));
3117 conf.coc_opc = OBJECT_CONF_SET;
3118 conf.coc_inode = *inode;
3119 conf.coc_lock = lock;
3120 conf.u.coc_layout = md.layout;
3121 (void)ll_layout_conf(*inode, &conf);
3123 LDLM_LOCK_PUT(lock);
3126 if (default_lmv_deleted)
3127 ll_update_default_lsm_md(*inode, &md);
3129 /* we may want to apply some policy for foreign file/dir */
3130 if (ll_sbi_has_foreign_symlink(sbi)) {
3131 rc = ll_manage_foreign(*inode, &md);
3139 /* cleanup will be done if necessary */
3140 md_free_lustre_md(sbi->ll_md_exp, &md);
3142 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3143 ll_intent_drop_lock(it);
3144 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3150 int ll_obd_statfs(struct inode *inode, void __user *arg)
3152 struct ll_sb_info *sbi = NULL;
3153 struct obd_export *exp;
3154 struct obd_ioctl_data *data = NULL;
3159 sbi = ll_i2sbi(inode);
3161 GOTO(out_statfs, rc = -EINVAL);
3163 rc = obd_ioctl_getdata(&data, &len, arg);
3165 GOTO(out_statfs, rc);
3167 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3168 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3169 GOTO(out_statfs, rc = -EINVAL);
3171 if (data->ioc_inllen1 != sizeof(__u32) ||
3172 data->ioc_inllen2 != sizeof(__u32) ||
3173 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3174 data->ioc_plen2 != sizeof(struct obd_uuid))
3175 GOTO(out_statfs, rc = -EINVAL);
3177 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3178 if (type & LL_STATFS_LMV)
3179 exp = sbi->ll_md_exp;
3180 else if (type & LL_STATFS_LOV)
3181 exp = sbi->ll_dt_exp;
3183 GOTO(out_statfs, rc = -ENODEV);
3185 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3187 GOTO(out_statfs, rc);
3189 OBD_FREE_LARGE(data, len);
3194 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3195 * be called early to avoid deadlock.
3197 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3199 if (op_data->op_mea2_sem) {
3200 up_read_non_owner(op_data->op_mea2_sem);
3201 op_data->op_mea2_sem = NULL;
3204 if (op_data->op_mea1_sem) {
3205 up_read_non_owner(op_data->op_mea1_sem);
3206 op_data->op_mea1_sem = NULL;
3210 /* this function prepares md_op_data hint for passing it down to MD stack. */
3211 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3212 struct inode *i1, struct inode *i2,
3213 const char *name, size_t namelen,
3214 __u32 mode, enum md_op_code opc,
3217 struct llcrypt_name fname = { 0 };
3220 LASSERT(i1 != NULL);
3223 /* Do not reuse namelen for something else. */
3225 return ERR_PTR(-EINVAL);
3227 if ((!IS_ENCRYPTED(i1) ||
3228 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3229 namelen > ll_i2sbi(i1)->ll_namelen)
3230 return ERR_PTR(-ENAMETOOLONG);
3232 /* "/" is not valid name, but it's allowed */
3233 if (!lu_name_is_valid_2(name, namelen) &&
3234 strncmp("/", name, namelen) != 0)
3235 return ERR_PTR(-EINVAL);
3238 if (op_data == NULL)
3239 OBD_ALLOC_PTR(op_data);
3241 if (op_data == NULL)
3242 return ERR_PTR(-ENOMEM);
3244 ll_i2gids(op_data->op_suppgids, i1, i2);
3245 op_data->op_fid1 = *ll_inode2fid(i1);
3247 if (S_ISDIR(i1->i_mode)) {
3248 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3249 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3250 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3251 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3255 op_data->op_fid2 = *ll_inode2fid(i2);
3256 if (S_ISDIR(i2->i_mode)) {
3258 /* i2 is typically a child of i1, and MUST be
3259 * further from the root to avoid deadlocks.
3261 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3262 op_data->op_mea2_sem =
3263 &ll_i2info(i2)->lli_lsm_sem;
3265 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3268 fid_zero(&op_data->op_fid2);
3271 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3272 op_data->op_cli_flags |= CLI_HASH64;
3274 if (ll_need_32bit_api(ll_i2sbi(i1)))
3275 op_data->op_cli_flags |= CLI_API32;
3277 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3278 /* In case of lookup, ll_setup_filename() has already been
3279 * called in ll_lookup_it(), so just take provided name.
3281 fname.disk_name.name = (unsigned char *)name;
3282 fname.disk_name.len = namelen;
3283 } else if (name && namelen) {
3284 struct qstr dname = QSTR_INIT(name, namelen);
3286 struct lu_fid *pfid = NULL;
3290 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3291 /* special case when called from ll_link() */
3296 lookup = (int)(opc == LUSTRE_OPC_ANY);
3298 if (opc == LUSTRE_OPC_ANY && lookup)
3300 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3302 ll_finish_md_op_data(op_data);
3305 if (pfid && !fid_is_zero(pfid)) {
3307 op_data->op_fid2 = fid;
3308 op_data->op_bias = MDS_FID_OP;
3310 if (fname.disk_name.name &&
3311 fname.disk_name.name != (unsigned char *)name)
3312 /* op_data->op_name must be freed after use */
3313 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3316 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3317 * are LUSTRE_OPC_ANY
3319 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3320 op_data->op_code = LUSTRE_OPC_ANY;
3322 op_data->op_code = opc;
3323 op_data->op_name = fname.disk_name.name;
3324 op_data->op_namelen = fname.disk_name.len;
3325 op_data->op_mode = mode;
3326 op_data->op_mod_time = ktime_get_real_seconds();
3327 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3328 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3329 op_data->op_cap = current_cap();
3330 op_data->op_mds = 0;
3331 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3332 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3333 op_data->op_bias |= MDS_CREATE_VOLATILE;
3335 op_data->op_data = data;
3340 void ll_finish_md_op_data(struct md_op_data *op_data)
3342 ll_unlock_md_op_lsm(op_data);
3343 ll_security_release_secctx(op_data->op_file_secctx,
3344 op_data->op_file_secctx_size);
3345 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3346 /* allocated via ll_setup_filename called
3347 * from ll_prep_md_op_data
3349 kfree(op_data->op_name);
3350 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3351 OBD_FREE_PTR(op_data);
3354 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3356 struct ll_sb_info *sbi;
3359 LASSERT(seq && dentry);
3360 sbi = ll_s2sbi(dentry->d_sb);
3362 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3363 seq_puts(seq, "nolock");
3365 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3366 /* match_table in some cases has patterns for both enabled and
3367 * disabled cases. Ignore 'no'xxx versions if bit is set.
3369 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3370 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3371 if (ll_sbi_flags_name[i].token ==
3372 LL_SBI_FOREIGN_SYMLINK) {
3373 seq_show_option(seq, "foreign_symlink",
3374 sbi->ll_foreign_symlink_prefix);
3376 seq_printf(seq, ",%s",
3377 ll_sbi_flags_name[i].pattern);
3380 /* You can have either localflock or flock but not
3381 * both. If localflock is set don't print flock or
3384 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3386 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3387 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3388 seq_printf(seq, ",%s",
3389 ll_sbi_flags_name[i].pattern);
3397 * Get obd name by cmd, and copy out to user space
3399 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
3401 struct ll_sb_info *sbi = ll_i2sbi(inode);
3402 struct obd_device *obd;
3405 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3406 obd = class_exp2obd(sbi->ll_dt_exp);
3407 else if (cmd == OBD_IOC_GETMDNAME)
3408 obd = class_exp2obd(sbi->ll_md_exp);
3415 if (copy_to_user((void __user *)arg, obd->obd_name,
3416 strlen(obd->obd_name) + 1))
3422 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3429 p.mnt = current->fs->root.mnt;
3431 path = d_path(&p, buf, bufsize);
3436 void ll_dirty_page_discard_warn(struct page *page, int ioret)
3438 char *buf, *path = NULL;
3439 struct dentry *dentry = NULL;
3440 struct inode *inode = page->mapping->host;
3442 /* this can be called inside spin lock so use GFP_ATOMIC. */
3443 buf = (char *)__get_free_page(GFP_ATOMIC);
3445 dentry = d_find_alias(page->mapping->host);
3447 path = ll_d_path(dentry, buf, PAGE_SIZE);
3450 /* The below message is checked in recovery-small.sh test_24b */
3452 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3453 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3454 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
3455 PFID(ll_inode2fid(inode)),
3456 (path && !IS_ERR(path)) ? path : "", ioret);
3462 free_page((unsigned long)buf);
3465 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3466 struct lov_user_md **kbuf)
3468 struct lov_user_md lum;
3472 if (copy_from_user(&lum, md, sizeof(lum)))
3475 lum_size = ll_lov_user_md_size(&lum);
3479 OBD_ALLOC_LARGE(*kbuf, lum_size);
3483 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3484 OBD_FREE_LARGE(*kbuf, lum_size);
3492 * Compute llite root squash state after a change of root squash
3493 * configuration setting or add/remove of a lnet nid
3495 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3497 struct root_squash_info *squash = &sbi->ll_squash;
3500 struct lnet_process_id id;
3502 /* Update norootsquash flag */
3503 spin_lock(&squash->rsi_lock);
3504 if (list_empty(&squash->rsi_nosquash_nids))
3505 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3507 /* Do not apply root squash as soon as one of our NIDs is
3508 * in the nosquash_nids list */
3511 while (LNetGetId(i++, &id) != -ENOENT) {
3512 if (id.nid == LNET_NID_LO_0)
3514 if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) {
3520 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3522 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3524 spin_unlock(&squash->rsi_lock);
3528 * Parse linkea content to extract information about a given hardlink
3530 * \param[in] ldata - Initialized linkea data
3531 * \param[in] linkno - Link identifier
3532 * \param[out] parent_fid - The entry's parent FID
3533 * \param[out] ln - Entry name destination buffer
3535 * \retval 0 on success
3536 * \retval Appropriate negative error code on failure
3538 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3539 struct lu_fid *parent_fid, struct lu_name *ln)
3545 rc = linkea_init_with_rec(ldata);
3549 if (linkno >= ldata->ld_leh->leh_reccount)
3550 /* beyond last link */
3553 linkea_first_entry(ldata);
3554 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3555 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3560 linkea_next_entry(ldata);
3570 * Get parent FID and name of an identified link. Operation is performed for
3571 * a given link number, letting the caller iterate over linkno to list one or
3572 * all links of an entry.
3574 * \param[in] file - File descriptor against which to perform the operation
3575 * \param[in,out] arg - User-filled structure containing the linkno to operate
3576 * on and the available size. It is eventually filled with
3577 * the requested information or left untouched on error
3579 * \retval - 0 on success
3580 * \retval - Appropriate negative error code on failure
3582 int ll_getparent(struct file *file, struct getparent __user *arg)
3584 struct inode *inode = file_inode(file);
3585 struct linkea_data *ldata;
3586 struct lu_buf buf = LU_BUF_NULL;
3588 struct lu_fid parent_fid;
3595 if (!capable(CAP_DAC_READ_SEARCH) &&
3596 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
3599 if (get_user(name_size, &arg->gp_name_size))
3602 if (get_user(linkno, &arg->gp_linkno))
3605 if (name_size > PATH_MAX)
3608 OBD_ALLOC(ldata, sizeof(*ldata));
3612 rc = linkea_data_new(ldata, &buf);
3614 GOTO(ldata_free, rc);
3616 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3617 buf.lb_len, OBD_MD_FLXATTR);
3621 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3625 if (ln.ln_namelen >= name_size)
3626 GOTO(lb_free, rc = -EOVERFLOW);
3628 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3629 GOTO(lb_free, rc = -EFAULT);
3631 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3632 GOTO(lb_free, rc = -EFAULT);
3634 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3635 GOTO(lb_free, rc = -EFAULT);
3640 OBD_FREE(ldata, sizeof(*ldata));