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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/llite/llite_lib.c
34 * Lustre Light Super operations
37 #define DEBUG_SUBSYSTEM S_LLITE
39 #include <linux/cpu.h>
40 #include <linux/module.h>
41 #include <linux/random.h>
42 #include <linux/statfs.h>
43 #include <linux/time.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/security.h>
52 #include <linux/fs_struct.h>
54 #ifndef HAVE_CPUS_READ_LOCK
55 #include <libcfs/linux/linux-cpu.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;
102 RETURN(ERR_PTR(-ENOMEM));
104 rc = pcc_super_init(&sbi->ll_pcc_super);
108 spin_lock_init(&sbi->ll_lock);
109 mutex_init(&sbi->ll_lco.lco_lock);
110 spin_lock_init(&sbi->ll_pp_extent_lock);
111 spin_lock_init(&sbi->ll_process_lock);
112 sbi->ll_rw_stats_on = 0;
113 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
116 pages = si.totalram - si.totalhigh;
117 lru_page_max = pages / 2;
119 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
120 sbi->ll_ra_info.ll_readahead_wq =
121 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
123 sbi->ll_ra_info.ra_async_max_active);
124 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
125 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
127 /* initialize ll_cache data */
128 sbi->ll_cache = cl_cache_init(lru_page_max);
129 if (sbi->ll_cache == NULL)
130 GOTO(out_destroy_ra, rc = -ENOMEM);
132 /* initialize foreign symlink prefix path */
133 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
134 if (sbi->ll_foreign_symlink_prefix == NULL)
135 GOTO(out_destroy_ra, rc = -ENOMEM);
136 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
137 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
139 /* initialize foreign symlink upcall path, none by default */
140 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
141 if (sbi->ll_foreign_symlink_upcall == NULL)
142 GOTO(out_destroy_ra, rc = -ENOMEM);
143 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
144 sbi->ll_foreign_symlink_upcall_items = NULL;
145 sbi->ll_foreign_symlink_upcall_nb_items = 0;
146 init_rwsem(&sbi->ll_foreign_symlink_sem);
147 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
148 * not enabled by default
151 sbi->ll_ra_info.ra_max_pages =
152 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
153 sbi->ll_ra_info.ra_max_pages_per_file =
154 min(sbi->ll_ra_info.ra_max_pages / 4,
155 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
156 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
157 sbi->ll_ra_info.ra_max_pages_per_file;
158 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
159 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
160 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
162 sbi->ll_flags |= LL_SBI_VERBOSE;
163 #ifdef ENABLE_CHECKSUM
164 sbi->ll_flags |= LL_SBI_CHECKSUM;
167 sbi->ll_flags |= LL_SBI_FLOCK;
170 #ifdef HAVE_LRU_RESIZE_SUPPORT
171 sbi->ll_flags |= LL_SBI_LRU_RESIZE;
173 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
175 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
176 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
178 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
182 /* metadata statahead is enabled by default */
183 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
184 sbi->ll_sa_max = LL_SA_RPC_DEF;
185 atomic_set(&sbi->ll_sa_total, 0);
186 atomic_set(&sbi->ll_sa_wrong, 0);
187 atomic_set(&sbi->ll_sa_running, 0);
188 atomic_set(&sbi->ll_agl_total, 0);
189 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
190 sbi->ll_flags |= LL_SBI_FAST_READ;
191 sbi->ll_flags |= LL_SBI_TINY_WRITE;
192 ll_sbi_set_encrypt(sbi, true);
195 sbi->ll_squash.rsi_uid = 0;
196 sbi->ll_squash.rsi_gid = 0;
197 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
198 spin_lock_init(&sbi->ll_squash.rsi_lock);
200 /* Per-filesystem file heat */
201 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
202 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
205 if (sbi->ll_foreign_symlink_prefix)
206 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
208 cl_cache_decref(sbi->ll_cache);
209 sbi->ll_cache = NULL;
211 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
213 pcc_super_fini(&sbi->ll_pcc_super);
219 static void ll_free_sbi(struct super_block *sb)
221 struct ll_sb_info *sbi = ll_s2sbi(sb);
225 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
226 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
227 if (sbi->ll_ra_info.ll_readahead_wq)
228 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
229 if (sbi->ll_cache != NULL) {
230 cl_cache_decref(sbi->ll_cache);
231 sbi->ll_cache = NULL;
233 if (sbi->ll_foreign_symlink_prefix) {
234 OBD_FREE(sbi->ll_foreign_symlink_prefix,
235 sbi->ll_foreign_symlink_prefix_size);
236 sbi->ll_foreign_symlink_prefix = NULL;
238 if (sbi->ll_foreign_symlink_upcall) {
239 OBD_FREE(sbi->ll_foreign_symlink_upcall,
240 strlen(sbi->ll_foreign_symlink_upcall) +
242 sbi->ll_foreign_symlink_upcall = NULL;
244 if (sbi->ll_foreign_symlink_upcall_items) {
246 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
247 struct ll_foreign_symlink_upcall_item *items =
248 sbi->ll_foreign_symlink_upcall_items;
250 for (i = 0 ; i < nb_items; i++)
251 if (items[i].type == STRING_TYPE)
252 OBD_FREE(items[i].string,
255 OBD_FREE_LARGE(items, nb_items *
256 sizeof(struct ll_foreign_symlink_upcall_item));
257 sbi->ll_foreign_symlink_upcall_items = NULL;
259 pcc_super_fini(&sbi->ll_pcc_super);
260 OBD_FREE(sbi, sizeof(*sbi));
265 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
267 struct inode *root = NULL;
268 struct ll_sb_info *sbi = ll_s2sbi(sb);
269 struct obd_statfs *osfs = NULL;
270 struct ptlrpc_request *request = NULL;
271 struct obd_connect_data *data = NULL;
272 struct obd_uuid *uuid;
273 struct md_op_data *op_data;
274 struct lustre_md lmd;
276 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 | OBD_CONNECT_TRUNCLOCK|
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_SHORTIO | OBD_CONNECT_FLAGS2;
323 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
324 OBD_CONNECT2_SUM_STATFS |
325 OBD_CONNECT2_OVERSTRIPING |
327 OBD_CONNECT2_LOCK_CONVERT |
328 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
329 OBD_CONNECT2_INC_XID |
331 OBD_CONNECT2_ASYNC_DISCARD |
333 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
334 OBD_CONNECT2_GETATTR_PFID |
335 OBD_CONNECT2_DOM_LVB;
337 #ifdef HAVE_LRU_RESIZE_SUPPORT
338 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
339 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
341 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
343 data->ocd_cksum_types = obd_cksum_types_supported_client();
345 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
346 /* flag mdc connection as lightweight, only used for test
347 * purpose, use with care */
348 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
350 data->ocd_ibits_known = MDS_INODELOCK_FULL;
351 data->ocd_version = LUSTRE_VERSION_CODE;
353 if (sb->s_flags & SB_RDONLY)
354 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
355 if (sbi->ll_flags & LL_SBI_USER_XATTR)
356 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
359 /* Setting this indicates we correctly support S_NOSEC (See kernel
360 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
362 sb->s_flags |= SB_NOSEC;
364 sbi->ll_fop = ll_select_file_operations(sbi);
366 /* always ping even if server suppress_pings */
367 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
368 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
370 obd_connect_set_secctx(data);
371 if (ll_sbi_has_encrypt(sbi))
372 obd_connect_set_enc(data);
374 #if defined(CONFIG_SECURITY)
375 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
378 data->ocd_brw_size = MD_MAX_BRW_SIZE;
380 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
381 &sbi->ll_sb_uuid, data, sbi->ll_cache);
383 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
384 "recovery, of which this client is not a "
385 "part. Please wait for recovery to complete,"
386 " abort, or time out.\n", md);
389 CERROR("cannot connect to %s: rc = %d\n", md, err);
393 sbi->ll_md_exp->exp_connect_data = *data;
395 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
396 LUSTRE_SEQ_METADATA);
398 CERROR("%s: Can't init metadata layer FID infrastructure, "
399 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
403 /* For mount, we only need fs info from MDT0, and also in DNE, it
404 * can make sure the client can be mounted as long as MDT0 is
406 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
407 ktime_get_seconds() - sbi->ll_statfs_max_age,
408 OBD_STATFS_FOR_MDT0);
410 GOTO(out_md_fid, err);
412 /* This needs to be after statfs to ensure connect has finished.
413 * Note that "data" does NOT contain the valid connect reply.
414 * If connecting to a 1.8 server there will be no LMV device, so
415 * we can access the MDC export directly and exp_connect_flags will
416 * be non-zero, but if accessing an upgraded 2.1 server it will
417 * have the correct flags filled in.
418 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
419 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
420 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
421 valid != CLIENT_CONNECT_MDT_REQD) {
424 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
425 obd_connect_flags2str(buf, PAGE_SIZE,
426 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
427 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
428 "feature(s) needed for correct operation "
429 "of this client (%s). Please upgrade "
430 "server or downgrade client.\n",
431 sbi->ll_md_exp->exp_obd->obd_name, buf);
432 OBD_FREE(buf, PAGE_SIZE);
433 GOTO(out_md_fid, err = -EPROTO);
436 size = sizeof(*data);
437 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
438 KEY_CONN_DATA, &size, data);
440 CERROR("%s: Get connect data failed: rc = %d\n",
441 sbi->ll_md_exp->exp_obd->obd_name, err);
442 GOTO(out_md_fid, err);
445 LASSERT(osfs->os_bsize);
446 sb->s_blocksize = osfs->os_bsize;
447 sb->s_blocksize_bits = log2(osfs->os_bsize);
448 sb->s_magic = LL_SUPER_MAGIC;
449 sb->s_maxbytes = MAX_LFS_FILESIZE;
450 sbi->ll_namelen = osfs->os_namelen;
451 sbi->ll_mnt.mnt = current->fs->root.mnt;
453 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
454 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
455 LCONSOLE_INFO("Disabling user_xattr feature because "
456 "it is not supported on the server\n");
457 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
460 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
462 sb->s_flags |= SB_POSIXACL;
464 sbi->ll_flags |= LL_SBI_ACL;
466 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
468 sb->s_flags &= ~SB_POSIXACL;
470 sbi->ll_flags &= ~LL_SBI_ACL;
473 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
474 sbi->ll_flags |= LL_SBI_64BIT_HASH;
476 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
477 sbi->ll_flags |= LL_SBI_LAYOUT_LOCK;
479 if (obd_connect_has_secctx(data))
480 sbi->ll_flags |= LL_SBI_FILE_SECCTX;
482 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
483 if (ll_sbi_has_test_dummy_encryption(sbi))
484 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
486 sbi->ll_md_exp->exp_obd->obd_name);
487 ll_sbi_set_encrypt(sbi, false);
490 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
491 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
492 LCONSOLE_INFO("%s: disabling xattr cache due to "
493 "unknown maximum xattr size.\n", dt);
494 } else if (!sbi->ll_xattr_cache_set) {
495 /* If xattr_cache is already set (no matter 0 or 1)
496 * during processing llog, it won't be enabled here. */
497 sbi->ll_flags |= LL_SBI_XATTR_CACHE;
498 sbi->ll_xattr_cache_enabled = 1;
502 sbi->ll_dt_obd = class_name2obd(dt);
503 if (!sbi->ll_dt_obd) {
504 CERROR("DT %s: not setup or attached\n", dt);
505 GOTO(out_md_fid, err = -ENODEV);
508 /* pass client page size via ocd_grant_blkbits, the server should report
509 * back its backend blocksize for grant calculation purpose */
510 data->ocd_grant_blkbits = PAGE_SHIFT;
512 /* indicate OST features supported by this client */
513 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
514 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
515 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
516 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
517 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
518 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
519 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
520 OBD_CONNECT_EINPROGRESS |
521 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
522 OBD_CONNECT_LAYOUTLOCK |
523 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
524 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
525 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
526 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
527 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK;
529 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
530 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
532 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
533 * disabled by default, because it can still be enabled on the
534 * fly via /sys. As a consequence, we still need to come to an
535 * agreement on the supported algorithms at connect time
537 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
539 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
540 data->ocd_cksum_types = OBD_CKSUM_ADLER;
542 data->ocd_cksum_types = obd_cksum_types_supported_client();
544 #ifdef HAVE_LRU_RESIZE_SUPPORT
545 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
547 /* always ping even if server suppress_pings */
548 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
549 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
551 if (ll_sbi_has_encrypt(sbi))
552 obd_connect_set_enc(data);
554 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
555 "ocd_grant: %d\n", data->ocd_connect_flags,
556 data->ocd_version, data->ocd_grant);
558 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
559 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
561 data->ocd_brw_size = DT_MAX_BRW_SIZE;
563 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
564 &sbi->ll_sb_uuid, data, sbi->ll_cache);
566 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
567 "recovery, of which this client is not a "
568 "part. Please wait for recovery to "
569 "complete, abort, or time out.\n", dt);
572 CERROR("%s: Cannot connect to %s: rc = %d\n",
573 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
577 if (ll_sbi_has_encrypt(sbi) &&
578 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
579 if (ll_sbi_has_test_dummy_encryption(sbi))
580 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
582 ll_sbi_set_encrypt(sbi, false);
583 } else if (ll_sbi_has_test_dummy_encryption(sbi)) {
584 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
587 sbi->ll_dt_exp->exp_connect_data = *data;
589 /* Don't change value if it was specified in the config log */
590 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
591 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
592 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
593 (data->ocd_brw_size >> PAGE_SHIFT));
594 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
595 sbi->ll_ra_info.ra_max_pages_per_file)
596 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
597 sbi->ll_ra_info.ra_max_pages_per_file;
600 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
601 LUSTRE_SEQ_METADATA);
603 CERROR("%s: Can't init data layer FID infrastructure, "
604 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
608 mutex_lock(&sbi->ll_lco.lco_lock);
609 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
610 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
611 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
612 mutex_unlock(&sbi->ll_lco.lco_lock);
614 fid_zero(&sbi->ll_root_fid);
615 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
618 CERROR("cannot mds_connect: rc = %d\n", err);
619 GOTO(out_lock_cn_cb, err);
621 if (!fid_is_sane(&sbi->ll_root_fid)) {
622 CERROR("%s: Invalid root fid "DFID" during mount\n",
623 sbi->ll_md_exp->exp_obd->obd_name,
624 PFID(&sbi->ll_root_fid));
625 GOTO(out_lock_cn_cb, err = -EINVAL);
627 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
629 sb->s_op = &lustre_super_operations;
630 sb->s_xattr = ll_xattr_handlers;
631 #if THREAD_SIZE >= 8192 /*b=17630*/
632 sb->s_export_op = &lustre_export_operations;
634 #ifdef HAVE_LUSTRE_CRYPTO
635 llcrypt_set_ops(sb, &lustre_cryptops);
639 * XXX: move this to after cbd setup? */
640 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
641 if (sbi->ll_flags & LL_SBI_ACL)
642 valid |= OBD_MD_FLACL;
644 OBD_ALLOC_PTR(op_data);
646 GOTO(out_lock_cn_cb, err = -ENOMEM);
648 op_data->op_fid1 = sbi->ll_root_fid;
649 op_data->op_mode = 0;
650 op_data->op_valid = valid;
652 err = md_getattr(sbi->ll_md_exp, op_data, &request);
654 OBD_FREE_PTR(op_data);
656 CERROR("%s: md_getattr failed for root: rc = %d\n",
657 sbi->ll_md_exp->exp_obd->obd_name, err);
658 GOTO(out_lock_cn_cb, err);
661 err = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
662 sbi->ll_md_exp, &lmd);
664 CERROR("failed to understand root inode md: rc = %d\n", err);
665 ptlrpc_req_finished(request);
666 GOTO(out_lock_cn_cb, err);
669 LASSERT(fid_is_sane(&sbi->ll_root_fid));
670 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid,
671 sbi->ll_flags & LL_SBI_32BIT_API),
673 md_free_lustre_md(sbi->ll_md_exp, &lmd);
674 ptlrpc_req_finished(request);
678 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
680 CERROR("%s: bad ll_iget() for root: rc = %d\n",
681 sbi->ll_fsname, err);
685 checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
686 if (sbi->ll_checksum_set) {
687 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
688 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
689 sizeof(checksum), &checksum, NULL);
691 CERROR("%s: Set checksum failed: rc = %d\n",
692 sbi->ll_dt_exp->exp_obd->obd_name, err);
698 sb->s_root = d_make_root(root);
699 if (sb->s_root == NULL) {
701 CERROR("%s: can't make root dentry: rc = %d\n",
702 sbi->ll_fsname, err);
706 sbi->ll_sdev_orig = sb->s_dev;
708 /* We set sb->s_dev equal on all lustre clients in order to support
709 * NFS export clustering. NFSD requires that the FSID be the same
711 /* s_dev is also used in lt_compare() to compare two fs, but that is
712 * only a node-local comparison. */
713 uuid = obd_get_uuid(sbi->ll_md_exp);
715 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
722 if (sbi->ll_dt_obd) {
723 err = sysfs_create_link(&sbi->ll_kset.kobj,
724 &sbi->ll_dt_obd->obd_kset.kobj,
725 sbi->ll_dt_obd->obd_type->typ_name);
727 CERROR("%s: could not register %s in llite: rc = %d\n",
728 dt, sbi->ll_fsname, err);
733 if (sbi->ll_md_obd) {
734 err = sysfs_create_link(&sbi->ll_kset.kobj,
735 &sbi->ll_md_obd->obd_kset.kobj,
736 sbi->ll_md_obd->obd_type->typ_name);
738 CERROR("%s: could not register %s in llite: rc = %d\n",
739 md, sbi->ll_fsname, err);
748 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
750 obd_disconnect(sbi->ll_dt_exp);
751 sbi->ll_dt_exp = NULL;
752 sbi->ll_dt_obd = NULL;
754 obd_fid_fini(sbi->ll_md_exp->exp_obd);
756 obd_disconnect(sbi->ll_md_exp);
757 sbi->ll_md_exp = NULL;
758 sbi->ll_md_obd = NULL;
767 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
771 size = sizeof(*lmmsize);
772 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
773 KEY_MAX_EASIZE, &size, lmmsize);
775 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
776 sbi->ll_dt_exp->exp_obd->obd_name, rc);
780 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
783 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
784 KEY_MAX_EASIZE, &size, lmmsize);
786 CERROR("Get max mdsize error rc %d\n", rc);
788 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
794 * Get the value of the default_easize parameter.
796 * \see client_obd::cl_default_mds_easize
798 * \param[in] sbi superblock info for this filesystem
799 * \param[out] lmmsize pointer to storage location for value
801 * \retval 0 on success
802 * \retval negative negated errno on failure
804 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
809 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
810 KEY_DEFAULT_EASIZE, &size, lmmsize);
812 CERROR("Get default mdsize error rc %d\n", rc);
818 * Set the default_easize parameter to the given value.
820 * \see client_obd::cl_default_mds_easize
822 * \param[in] sbi superblock info for this filesystem
823 * \param[in] lmmsize the size to set
825 * \retval 0 on success
826 * \retval negative negated errno on failure
828 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
832 if (lmmsize < sizeof(struct lov_mds_md) ||
833 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
836 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
837 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
838 sizeof(int), &lmmsize, NULL);
843 static void client_common_put_super(struct super_block *sb)
845 struct ll_sb_info *sbi = ll_s2sbi(sb);
850 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
851 obd_disconnect(sbi->ll_dt_exp);
852 sbi->ll_dt_exp = NULL;
854 ll_debugfs_unregister_super(sb);
856 obd_fid_fini(sbi->ll_md_exp->exp_obd);
857 obd_disconnect(sbi->ll_md_exp);
858 sbi->ll_md_exp = NULL;
863 void ll_kill_super(struct super_block *sb)
865 struct ll_sb_info *sbi;
869 if (!(sb->s_flags & SB_ACTIVE))
873 /* we need restore s_dev from changed for clustred NFS before put_super
874 * because new kernels have cached s_dev and change sb->s_dev in
875 * put_super not affected real removing devices */
877 sb->s_dev = sbi->ll_sdev_orig;
879 /* wait running statahead threads to quit */
880 while (atomic_read(&sbi->ll_sa_running) > 0)
881 schedule_timeout_uninterruptible(
882 cfs_time_seconds(1) >> 3);
888 static inline int ll_set_opt(const char *opt, char *data, int fl)
890 if (strncmp(opt, data, strlen(opt)) != 0)
896 /* non-client-specific mount options are parsed in lmd_parse */
897 static int ll_options(char *options, struct ll_sb_info *sbi)
900 char *s1 = options, *s2;
901 int *flags = &sbi->ll_flags;
907 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
910 CDEBUG(D_SUPER, "next opt=%s\n", s1);
911 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
916 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
918 *flags = (*flags & ~LL_SBI_LOCALFLOCK) | tmp;
921 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
923 *flags = (*flags & ~LL_SBI_FLOCK) | tmp;
926 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
931 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
936 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
941 tmp = ll_set_opt("context", s1, 1);
944 tmp = ll_set_opt("fscontext", s1, 1);
947 tmp = ll_set_opt("defcontext", s1, 1);
950 tmp = ll_set_opt("rootcontext", s1, 1);
953 tmp = ll_set_opt("user_fid2path", s1, LL_SBI_USER_FID2PATH);
958 tmp = ll_set_opt("nouser_fid2path", s1, LL_SBI_USER_FID2PATH);
964 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
967 sbi->ll_checksum_set = 1;
970 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
973 sbi->ll_checksum_set = 1;
976 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
981 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
986 tmp = ll_set_opt("lazystatfs", s1, LL_SBI_LAZYSTATFS);
991 tmp = ll_set_opt("nolazystatfs", s1, LL_SBI_LAZYSTATFS);
996 tmp = ll_set_opt("32bitapi", s1, LL_SBI_32BIT_API);
1001 tmp = ll_set_opt("verbose", s1, LL_SBI_VERBOSE);
1006 tmp = ll_set_opt("noverbose", s1, LL_SBI_VERBOSE);
1011 tmp = ll_set_opt("always_ping", s1, LL_SBI_ALWAYS_PING);
1016 tmp = ll_set_opt("test_dummy_encryption", s1,
1017 LL_SBI_TEST_DUMMY_ENCRYPTION);
1019 #ifdef HAVE_LUSTRE_CRYPTO
1022 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1026 tmp = ll_set_opt("noencrypt", s1, LL_SBI_ENCRYPT);
1028 #ifdef HAVE_LUSTRE_CRYPTO
1031 LCONSOLE_WARN("noencrypt mount option ignored: encryption not supported\n");
1035 tmp = ll_set_opt("foreign_symlink", s1, LL_SBI_FOREIGN_SYMLINK);
1037 int prefix_pos = sizeof("foreign_symlink=") - 1;
1038 int equal_pos = sizeof("foreign_symlink=") - 2;
1040 /* non-default prefix provided ? */
1041 if (strlen(s1) >= sizeof("foreign_symlink=") &&
1042 *(s1 + equal_pos) == '=') {
1043 char *old = sbi->ll_foreign_symlink_prefix;
1045 sbi->ll_foreign_symlink_prefix_size;
1047 /* path must be absolute */
1048 if (*(s1 + sizeof("foreign_symlink=")
1050 LCONSOLE_ERROR_MSG(0x152,
1051 "foreign prefix '%s' must be an absolute path\n",
1056 s2 = strchrnul(s1 + prefix_pos, ',');
1058 if (sbi->ll_foreign_symlink_prefix) {
1059 sbi->ll_foreign_symlink_prefix = NULL;
1060 sbi->ll_foreign_symlink_prefix_size = 0;
1062 /* alloc for path length and '\0' */
1063 OBD_ALLOC(sbi->ll_foreign_symlink_prefix,
1064 s2 - (s1 + prefix_pos) + 1);
1065 if (!sbi->ll_foreign_symlink_prefix) {
1066 /* restore previous */
1067 sbi->ll_foreign_symlink_prefix = old;
1068 sbi->ll_foreign_symlink_prefix_size =
1073 OBD_FREE(old, old_len);
1074 strncpy(sbi->ll_foreign_symlink_prefix,
1076 s2 - (s1 + prefix_pos));
1077 sbi->ll_foreign_symlink_prefix_size =
1078 s2 - (s1 + prefix_pos) + 1;
1080 LCONSOLE_ERROR_MSG(0x152,
1081 "invalid %s option\n", s1);
1083 /* enable foreign symlink support */
1087 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
1093 s2 = strchr(s1, ',');
1101 void ll_lli_init(struct ll_inode_info *lli)
1103 lli->lli_inode_magic = LLI_INODE_MAGIC;
1105 spin_lock_init(&lli->lli_lock);
1106 lli->lli_posix_acl = NULL;
1107 /* Do not set lli_fid, it has been initialized already. */
1108 fid_zero(&lli->lli_pfid);
1109 lli->lli_mds_read_och = NULL;
1110 lli->lli_mds_write_och = NULL;
1111 lli->lli_mds_exec_och = NULL;
1112 lli->lli_open_fd_read_count = 0;
1113 lli->lli_open_fd_write_count = 0;
1114 lli->lli_open_fd_exec_count = 0;
1115 mutex_init(&lli->lli_och_mutex);
1116 spin_lock_init(&lli->lli_agl_lock);
1117 spin_lock_init(&lli->lli_layout_lock);
1118 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1119 lli->lli_clob = NULL;
1121 init_rwsem(&lli->lli_xattrs_list_rwsem);
1122 mutex_init(&lli->lli_xattrs_enq_lock);
1124 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1125 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1126 lli->lli_opendir_key = NULL;
1127 lli->lli_sai = NULL;
1128 spin_lock_init(&lli->lli_sa_lock);
1129 lli->lli_opendir_pid = 0;
1130 lli->lli_sa_enabled = 0;
1131 init_rwsem(&lli->lli_lsm_sem);
1133 mutex_init(&lli->lli_size_mutex);
1134 mutex_init(&lli->lli_setattr_mutex);
1135 lli->lli_symlink_name = NULL;
1136 ll_trunc_sem_init(&lli->lli_trunc_sem);
1137 range_lock_tree_init(&lli->lli_write_tree);
1138 init_rwsem(&lli->lli_glimpse_sem);
1139 lli->lli_glimpse_time = ktime_set(0, 0);
1140 INIT_LIST_HEAD(&lli->lli_agl_list);
1141 lli->lli_agl_index = 0;
1142 lli->lli_async_rc = 0;
1143 spin_lock_init(&lli->lli_heat_lock);
1144 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1145 lli->lli_heat_flags = 0;
1146 mutex_init(&lli->lli_pcc_lock);
1147 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1148 lli->lli_pcc_inode = NULL;
1149 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1150 lli->lli_pcc_generation = 0;
1151 mutex_init(&lli->lli_group_mutex);
1152 lli->lli_group_users = 0;
1153 lli->lli_group_gid = 0;
1155 mutex_init(&lli->lli_layout_mutex);
1156 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1159 #define MAX_STRING_SIZE 128
1161 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1163 #define LSI_BDI_INITIALIZED 0x00400000
1165 #ifndef HAVE_BDI_CAP_MAP_COPY
1166 # define BDI_CAP_MAP_COPY 0
1169 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1171 struct lustre_sb_info *lsi = s2lsi(sb);
1172 char buf[MAX_STRING_SIZE];
1176 err = bdi_init(&lsi->lsi_bdi);
1180 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1181 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1182 lsi->lsi_bdi.name = "lustre";
1183 va_start(args, fmt);
1184 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1186 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1189 sb->s_bdi = &lsi->lsi_bdi;
1193 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1195 int ll_fill_super(struct super_block *sb)
1197 struct lustre_profile *lprof = NULL;
1198 struct lustre_sb_info *lsi = s2lsi(sb);
1199 struct ll_sb_info *sbi = NULL;
1200 char *dt = NULL, *md = NULL;
1201 char *profilenm = get_profile_name(sb);
1202 struct config_llog_instance *cfg;
1203 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1204 const int instlen = LUSTRE_MAXINSTANCE + 2;
1205 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1206 char name[MAX_STRING_SIZE];
1215 /* for ASLR, to map between cfg_instance and hashed ptr */
1216 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1217 profilenm, cfg_instance, sb);
1219 OBD_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1223 GOTO(out_free_cfg, err = -ENOMEM);
1225 /* client additional sb info */
1226 lsi->lsi_llsbi = sbi = ll_init_sbi();
1228 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1230 err = ll_options(lsi->lsi_lmd->lmd_opts, sbi);
1232 GOTO(out_free_cfg, err);
1234 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1235 sb->s_d_op = &ll_d_ops;
1238 generate_random_uuid(uuid.b);
1239 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1241 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1244 len = strlen(profilenm);
1245 ptr = strrchr(profilenm, '-');
1246 if (ptr && (strcmp(ptr, "-client") == 0))
1249 if (len > LUSTRE_MAXFSNAME) {
1250 if (unlikely(len >= MAX_STRING_SIZE))
1251 len = MAX_STRING_SIZE - 1;
1252 strncpy(name, profilenm, len);
1254 err = -ENAMETOOLONG;
1255 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1256 name, LUSTRE_MAXFSNAME, err);
1257 GOTO(out_free_cfg, err);
1259 strncpy(sbi->ll_fsname, profilenm, len);
1260 sbi->ll_fsname[len] = '\0';
1263 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1264 profilenm, cfg_instance);
1266 err = super_setup_bdi_name(sb, "%s", name);
1268 GOTO(out_free_cfg, err);
1270 /* Call ll_debugfs_register_super() before lustre_process_log()
1271 * so that "llite.*.*" params can be processed correctly.
1273 err = ll_debugfs_register_super(sb, name);
1275 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1276 sbi->ll_fsname, err);
1280 /* The cfg_instance is a value unique to this super, in case some
1281 * joker tries to mount the same fs at two mount points.
1283 cfg->cfg_instance = cfg_instance;
1284 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1285 cfg->cfg_callback = class_config_llog_handler;
1286 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1287 /* set up client obds */
1288 err = lustre_process_log(sb, profilenm, cfg);
1290 GOTO(out_debugfs, err);
1292 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1293 lprof = class_get_profile(profilenm);
1294 if (lprof == NULL) {
1295 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1296 " read from the MGS. Does that filesystem "
1297 "exist?\n", profilenm);
1298 GOTO(out_debugfs, err = -EINVAL);
1300 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1301 lprof->lp_md, lprof->lp_dt);
1303 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1304 OBD_ALLOC(dt, dt_len);
1306 GOTO(out_profile, err = -ENOMEM);
1307 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1309 md_len = strlen(lprof->lp_md) + instlen + 2;
1310 OBD_ALLOC(md, md_len);
1312 GOTO(out_free_dt, err = -ENOMEM);
1313 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1315 /* connections, registrations, sb setup */
1316 err = client_common_fill_super(sb, md, dt);
1318 GOTO(out_free_md, err);
1320 sbi->ll_client_common_fill_super_succeeded = 1;
1324 OBD_FREE(md, md_len);
1327 OBD_FREE(dt, dt_len);
1330 class_put_profile(lprof);
1333 ll_debugfs_unregister_super(sb);
1340 else if (sbi->ll_flags & LL_SBI_VERBOSE)
1341 LCONSOLE_WARN("Mounted %s\n", profilenm);
1343 } /* ll_fill_super */
1345 void ll_put_super(struct super_block *sb)
1347 struct config_llog_instance cfg, params_cfg;
1348 struct obd_device *obd;
1349 struct lustre_sb_info *lsi = s2lsi(sb);
1350 struct ll_sb_info *sbi = ll_s2sbi(sb);
1351 char *profilenm = get_profile_name(sb);
1352 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1354 int next, force = 1, rc = 0;
1358 GOTO(out_no_sbi, 0);
1360 /* Should replace instance_id with something better for ASLR */
1361 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1362 profilenm, cfg_instance, sb);
1364 cfg.cfg_instance = cfg_instance;
1365 lustre_end_log(sb, profilenm, &cfg);
1367 params_cfg.cfg_instance = cfg_instance;
1368 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1370 if (sbi->ll_md_exp) {
1371 obd = class_exp2obd(sbi->ll_md_exp);
1373 force = obd->obd_force;
1376 /* Wait for unstable pages to be committed to stable storage */
1378 rc = l_wait_event_abortable(
1379 sbi->ll_cache->ccc_unstable_waitq,
1380 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1383 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1384 if (force == 0 && rc != -ERESTARTSYS)
1385 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1387 /* We need to set force before the lov_disconnect in
1388 * lustre_common_put_super, since l_d cleans up osc's as well.
1392 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1394 obd->obd_force = force;
1398 if (sbi->ll_client_common_fill_super_succeeded) {
1399 /* Only if client_common_fill_super succeeded */
1400 client_common_put_super(sb);
1404 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1405 class_manual_cleanup(obd);
1407 if (sbi->ll_flags & LL_SBI_VERBOSE)
1408 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1411 class_del_profile(profilenm);
1413 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1414 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1415 bdi_destroy(&lsi->lsi_bdi);
1416 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1421 lsi->lsi_llsbi = NULL;
1423 lustre_common_put_super(sb);
1425 cl_env_cache_purge(~0);
1428 } /* client_put_super */
1430 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1432 struct inode *inode = NULL;
1434 /* NOTE: we depend on atomic igrab() -bzzz */
1435 lock_res_and_lock(lock);
1436 if (lock->l_resource->lr_lvb_inode) {
1437 struct ll_inode_info * lli;
1438 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1439 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1440 inode = igrab(lock->l_resource->lr_lvb_inode);
1442 inode = lock->l_resource->lr_lvb_inode;
1443 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1444 D_WARNING, lock, "lr_lvb_inode %p is "
1445 "bogus: magic %08x",
1446 lock->l_resource->lr_lvb_inode,
1447 lli->lli_inode_magic);
1451 unlock_res_and_lock(lock);
1455 void ll_dir_clear_lsm_md(struct inode *inode)
1457 struct ll_inode_info *lli = ll_i2info(inode);
1459 LASSERT(S_ISDIR(inode->i_mode));
1461 if (lli->lli_lsm_md) {
1462 lmv_free_memmd(lli->lli_lsm_md);
1463 lli->lli_lsm_md = NULL;
1466 if (lli->lli_default_lsm_md) {
1467 lmv_free_memmd(lli->lli_default_lsm_md);
1468 lli->lli_default_lsm_md = NULL;
1472 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1473 const struct lu_fid *fid,
1474 struct lustre_md *md)
1476 struct ll_sb_info *sbi = ll_s2sbi(sb);
1477 struct mdt_body *body = md->body;
1478 struct inode *inode;
1482 ino = cl_fid_build_ino(fid, sbi->ll_flags & LL_SBI_32BIT_API);
1483 inode = iget_locked(sb, ino);
1484 if (inode == NULL) {
1485 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1486 sbi->ll_fsname, PFID(fid));
1487 RETURN(ERR_PTR(-ENOENT));
1490 if (inode->i_state & I_NEW) {
1491 struct ll_inode_info *lli = ll_i2info(inode);
1492 struct lmv_stripe_md *lsm = md->lmv;
1494 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1495 (body->mbo_mode & S_IFMT);
1496 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1499 inode->i_mtime.tv_sec = 0;
1500 inode->i_atime.tv_sec = 0;
1501 inode->i_ctime.tv_sec = 0;
1504 #ifdef HAVE_BACKING_DEV_INFO
1505 /* initializing backing dev info. */
1506 inode->i_mapping->backing_dev_info =
1507 &s2lsi(inode->i_sb)->lsi_bdi;
1509 inode->i_op = &ll_dir_inode_operations;
1510 inode->i_fop = &ll_dir_operations;
1511 lli->lli_fid = *fid;
1514 LASSERT(lsm != NULL);
1515 /* master object FID */
1516 lli->lli_pfid = body->mbo_fid1;
1517 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1518 lli, PFID(fid), PFID(&lli->lli_pfid));
1519 unlock_new_inode(inode);
1525 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1528 struct lmv_stripe_md *lsm = md->lmv;
1529 struct ll_inode_info *lli = ll_i2info(inode);
1532 LASSERT(lsm != NULL);
1534 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1535 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1536 lsm_md_dump(D_INODE, lsm);
1538 if (!lmv_dir_striped(lsm))
1541 /* XXX sigh, this lsm_root initialization should be in
1542 * LMV layer, but it needs ll_iget right now, so we
1543 * put this here right now. */
1544 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1545 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1546 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1548 if (!fid_is_sane(fid))
1551 /* Unfortunately ll_iget will call ll_update_inode,
1552 * where the initialization of slave inode is slightly
1553 * different, so it reset lsm_md to NULL to avoid
1554 * initializing lsm for slave inode. */
1555 lsm->lsm_md_oinfo[i].lmo_root =
1556 ll_iget_anon_dir(inode->i_sb, fid, md);
1557 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1558 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1560 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1562 iput(lsm->lsm_md_oinfo[i].lmo_root);
1563 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1569 lli->lli_lsm_md = lsm;
1574 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1576 struct ll_inode_info *lli = ll_i2info(inode);
1578 if (!md->default_lmv) {
1579 /* clear default lsm */
1580 if (lli->lli_default_lsm_md) {
1581 down_write(&lli->lli_lsm_sem);
1582 if (lli->lli_default_lsm_md) {
1583 lmv_free_memmd(lli->lli_default_lsm_md);
1584 lli->lli_default_lsm_md = NULL;
1586 up_write(&lli->lli_lsm_sem);
1588 } else if (lli->lli_default_lsm_md) {
1589 /* update default lsm if it changes */
1590 down_read(&lli->lli_lsm_sem);
1591 if (lli->lli_default_lsm_md &&
1592 !lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1593 up_read(&lli->lli_lsm_sem);
1594 down_write(&lli->lli_lsm_sem);
1595 if (lli->lli_default_lsm_md)
1596 lmv_free_memmd(lli->lli_default_lsm_md);
1597 lli->lli_default_lsm_md = md->default_lmv;
1598 lsm_md_dump(D_INODE, md->default_lmv);
1599 md->default_lmv = NULL;
1600 up_write(&lli->lli_lsm_sem);
1602 up_read(&lli->lli_lsm_sem);
1605 /* init default lsm */
1606 down_write(&lli->lli_lsm_sem);
1607 lli->lli_default_lsm_md = md->default_lmv;
1608 lsm_md_dump(D_INODE, md->default_lmv);
1609 md->default_lmv = NULL;
1610 up_write(&lli->lli_lsm_sem);
1614 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1616 struct ll_inode_info *lli = ll_i2info(inode);
1617 struct lmv_stripe_md *lsm = md->lmv;
1618 struct cl_attr *attr;
1623 LASSERT(S_ISDIR(inode->i_mode));
1624 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1625 PFID(ll_inode2fid(inode)));
1627 /* update default LMV */
1628 if (md->default_lmv)
1629 ll_update_default_lsm_md(inode, md);
1632 * no striped information from request, lustre_md from req does not
1633 * include stripeEA, see ll_md_setattr()
1639 * normally dir layout doesn't change, only take read lock to check
1640 * that to avoid blocking other MD operations.
1642 down_read(&lli->lli_lsm_sem);
1644 /* some current lookup initialized lsm, and unchanged */
1645 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1646 GOTO(unlock, rc = 0);
1648 /* if dir layout doesn't match, check whether version is increased,
1649 * which means layout is changed, this happens in dir split/merge and
1652 * foreign LMV should not change.
1654 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1655 lsm->lsm_md_layout_version <=
1656 lli->lli_lsm_md->lsm_md_layout_version) {
1657 CERROR("%s: "DFID" dir layout mismatch:\n",
1658 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1659 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1660 lsm_md_dump(D_ERROR, lsm);
1661 GOTO(unlock, rc = -EINVAL);
1664 up_read(&lli->lli_lsm_sem);
1665 down_write(&lli->lli_lsm_sem);
1666 /* clear existing lsm */
1667 if (lli->lli_lsm_md) {
1668 lmv_free_memmd(lli->lli_lsm_md);
1669 lli->lli_lsm_md = NULL;
1672 rc = ll_init_lsm_md(inode, md);
1673 up_write(&lli->lli_lsm_sem);
1678 /* set md->lmv to NULL, so the following free lustre_md will not free
1683 /* md_merge_attr() may take long, since lsm is already set, switch to
1686 down_read(&lli->lli_lsm_sem);
1688 if (!lmv_dir_striped(lli->lli_lsm_md))
1689 GOTO(unlock, rc = 0);
1691 OBD_ALLOC_PTR(attr);
1693 GOTO(unlock, rc = -ENOMEM);
1695 /* validate the lsm */
1696 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1697 ll_md_blocking_ast);
1699 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1700 md->body->mbo_nlink = attr->cat_nlink;
1701 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1702 md->body->mbo_size = attr->cat_size;
1703 if (md->body->mbo_valid & OBD_MD_FLATIME)
1704 md->body->mbo_atime = attr->cat_atime;
1705 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1706 md->body->mbo_ctime = attr->cat_ctime;
1707 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1708 md->body->mbo_mtime = attr->cat_mtime;
1714 up_read(&lli->lli_lsm_sem);
1719 void ll_clear_inode(struct inode *inode)
1721 struct ll_inode_info *lli = ll_i2info(inode);
1722 struct ll_sb_info *sbi = ll_i2sbi(inode);
1726 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1727 PFID(ll_inode2fid(inode)), inode);
1729 if (S_ISDIR(inode->i_mode)) {
1730 /* these should have been cleared in ll_file_release */
1731 LASSERT(lli->lli_opendir_key == NULL);
1732 LASSERT(lli->lli_sai == NULL);
1733 LASSERT(lli->lli_opendir_pid == 0);
1735 pcc_inode_free(inode);
1738 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1740 LASSERT(!lli->lli_open_fd_write_count);
1741 LASSERT(!lli->lli_open_fd_read_count);
1742 LASSERT(!lli->lli_open_fd_exec_count);
1744 if (lli->lli_mds_write_och)
1745 ll_md_real_close(inode, FMODE_WRITE);
1746 if (lli->lli_mds_exec_och)
1747 ll_md_real_close(inode, FMODE_EXEC);
1748 if (lli->lli_mds_read_och)
1749 ll_md_real_close(inode, FMODE_READ);
1751 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1752 OBD_FREE(lli->lli_symlink_name,
1753 strlen(lli->lli_symlink_name) + 1);
1754 lli->lli_symlink_name = NULL;
1757 ll_xattr_cache_destroy(inode);
1759 forget_all_cached_acls(inode);
1761 lli->lli_inode_magic = LLI_INODE_DEAD;
1763 if (S_ISDIR(inode->i_mode))
1764 ll_dir_clear_lsm_md(inode);
1765 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1766 LASSERT(list_empty(&lli->lli_agl_list));
1769 * XXX This has to be done before lsm is freed below, because
1770 * cl_object still uses inode lsm.
1772 cl_inode_fini(inode);
1774 llcrypt_put_encryption_info(inode);
1779 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1781 struct lustre_md md;
1782 struct inode *inode = dentry->d_inode;
1783 struct ll_sb_info *sbi = ll_i2sbi(inode);
1784 struct ptlrpc_request *request = NULL;
1788 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1789 LUSTRE_OPC_ANY, NULL);
1790 if (IS_ERR(op_data))
1791 RETURN(PTR_ERR(op_data));
1793 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1795 ptlrpc_req_finished(request);
1796 if (rc == -ENOENT) {
1798 /* Unlinked special device node? Or just a race?
1799 * Pretend we done everything. */
1800 if (!S_ISREG(inode->i_mode) &&
1801 !S_ISDIR(inode->i_mode)) {
1802 ia_valid = op_data->op_attr.ia_valid;
1803 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1804 rc = simple_setattr(dentry, &op_data->op_attr);
1805 op_data->op_attr.ia_valid = ia_valid;
1807 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1808 CERROR("md_setattr fails: rc = %d\n", rc);
1813 rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
1814 sbi->ll_md_exp, &md);
1816 ptlrpc_req_finished(request);
1820 ia_valid = op_data->op_attr.ia_valid;
1821 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1822 * cache is not cleared yet. */
1823 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1824 if (S_ISREG(inode->i_mode))
1826 rc = simple_setattr(dentry, &op_data->op_attr);
1827 if (S_ISREG(inode->i_mode))
1828 inode_unlock(inode);
1829 op_data->op_attr.ia_valid = ia_valid;
1831 rc = ll_update_inode(inode, &md);
1832 ptlrpc_req_finished(request);
1838 * Zero portion of page that is part of @inode.
1839 * This implies, if necessary:
1840 * - taking cl_lock on range corresponding to concerned page
1841 * - grabbing vm page
1842 * - associating cl_page
1843 * - proceeding to clio read
1844 * - zeroing range in page
1845 * - proceeding to cl_page flush
1846 * - releasing cl_lock
1848 * \param[in] inode inode
1849 * \param[in] index page index
1850 * \param[in] offset offset in page to start zero from
1851 * \param[in] len len to zero
1853 * \retval 0 on success
1854 * \retval negative errno on failure
1856 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
1859 struct ll_inode_info *lli = ll_i2info(inode);
1860 struct cl_object *clob = lli->lli_clob;
1862 struct lu_env *env = NULL;
1863 struct cl_io *io = NULL;
1864 struct cl_page *clpage = NULL;
1865 struct page *vmpage = NULL;
1866 unsigned from = index << PAGE_SHIFT;
1867 struct cl_lock *lock = NULL;
1868 struct cl_lock_descr *descr = NULL;
1869 struct cl_2queue *queue = NULL;
1870 struct cl_sync_io *anchor = NULL;
1871 bool holdinglock = false;
1872 bool lockedbymyself = true;
1877 env = cl_env_get(&refcheck);
1879 RETURN(PTR_ERR(env));
1881 io = vvp_env_thread_io(env);
1883 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
1887 lock = vvp_env_lock(env);
1888 descr = &lock->cll_descr;
1889 descr->cld_obj = io->ci_obj;
1890 descr->cld_start = cl_index(io->ci_obj, from);
1891 descr->cld_end = cl_index(io->ci_obj, from + PAGE_SIZE - 1);
1892 descr->cld_mode = CLM_WRITE;
1893 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
1895 /* request lock for page */
1896 rc = cl_lock_request(env, io, lock);
1897 /* -ECANCELED indicates a matching lock with a different extent
1898 * was already present, and -EEXIST indicates a matching lock
1899 * on exactly the same extent was already present.
1900 * In both cases it means we are covered.
1902 if (rc == -ECANCELED || rc == -EEXIST)
1910 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
1912 GOTO(rellock, rc = -EOPNOTSUPP);
1914 if (!PageDirty(vmpage)) {
1915 /* associate cl_page */
1916 clpage = cl_page_find(env, clob, vmpage->index,
1917 vmpage, CPT_CACHEABLE);
1919 GOTO(pagefini, rc = PTR_ERR(clpage));
1921 cl_page_assume(env, io, clpage);
1924 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
1925 !PageWriteback(vmpage)) {
1927 /* set PagePrivate2 to detect special case of empty page
1928 * in osc_brw_fini_request()
1930 SetPagePrivate2(vmpage);
1931 rc = ll_io_read_page(env, io, clpage, NULL);
1932 if (!PagePrivate2(vmpage))
1933 /* PagePrivate2 was cleared in osc_brw_fini_request()
1934 * meaning we read an empty page. In this case, in order
1935 * to avoid allocating unnecessary block in truncated
1936 * file, we must not zero and write as below. Subsequent
1937 * server-side truncate will handle things correctly.
1939 GOTO(clpfini, rc = 0);
1940 ClearPagePrivate2(vmpage);
1943 lockedbymyself = trylock_page(vmpage);
1944 cl_page_assume(env, io, clpage);
1947 /* zero range in page */
1948 zero_user(vmpage, offset, len);
1950 if (holdinglock && clpage) {
1951 /* explicitly write newly modified page */
1952 queue = &io->ci_queue;
1953 cl_2queue_init(queue);
1954 anchor = &vvp_env_info(env)->vti_anchor;
1955 cl_sync_io_init(anchor, 1);
1956 clpage->cp_sync_io = anchor;
1957 cl_2queue_add(queue, clpage);
1958 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
1960 GOTO(queuefini1, rc);
1961 rc = cl_sync_io_wait(env, anchor, 0);
1963 GOTO(queuefini2, rc);
1964 cl_page_assume(env, io, clpage);
1967 cl_2queue_discard(env, io, queue);
1969 cl_2queue_disown(env, io, queue);
1970 cl_2queue_fini(env, queue);
1975 cl_page_put(env, clpage);
1977 if (lockedbymyself) {
1978 unlock_page(vmpage);
1983 cl_lock_release(env, lock);
1985 cl_io_fini(env, io);
1988 cl_env_put(env, &refcheck);
1993 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1994 * object(s) determine the file size and mtime. Otherwise, the MDS will
1995 * keep these values until such a time that objects are allocated for it.
1996 * We do the MDS operations first, as it is checking permissions for us.
1997 * We don't to the MDS RPC if there is nothing that we want to store there,
1998 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1999 * going to do an RPC anyways.
2001 * If we are doing a truncate, we will send the mtime and ctime updates
2002 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2003 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2006 * In case of HSMimport, we only set attr on MDS.
2008 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2009 enum op_xvalid xvalid, bool hsm_import)
2011 struct inode *inode = dentry->d_inode;
2012 struct ll_inode_info *lli = ll_i2info(inode);
2013 struct md_op_data *op_data = NULL;
2014 ktime_t kstart = ktime_get();
2019 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2020 "valid %x, hsm_import %d\n",
2021 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2022 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2025 if (attr->ia_valid & ATTR_SIZE) {
2026 /* Check new size against VFS/VM file size limit and rlimit */
2027 rc = inode_newsize_ok(inode, attr->ia_size);
2031 /* The maximum Lustre file size is variable, based on the
2032 * OST maximum object size and number of stripes. This
2033 * needs another check in addition to the VFS check above. */
2034 if (attr->ia_size > ll_file_maxbytes(inode)) {
2035 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2036 PFID(&lli->lli_fid), attr->ia_size,
2037 ll_file_maxbytes(inode));
2041 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2044 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2045 if (attr->ia_valid & TIMES_SET_FLAGS) {
2046 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2047 !capable(CAP_FOWNER))
2051 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2052 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2053 (attr->ia_valid & ATTR_CTIME)) {
2054 attr->ia_ctime = current_time(inode);
2055 xvalid |= OP_XVALID_CTIME_SET;
2057 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2058 (attr->ia_valid & ATTR_ATIME)) {
2059 attr->ia_atime = current_time(inode);
2060 attr->ia_valid |= ATTR_ATIME_SET;
2062 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2063 (attr->ia_valid & ATTR_MTIME)) {
2064 attr->ia_mtime = current_time(inode);
2065 attr->ia_valid |= ATTR_MTIME_SET;
2068 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2069 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2070 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2071 ktime_get_real_seconds());
2073 if (S_ISREG(inode->i_mode))
2074 inode_unlock(inode);
2076 /* We always do an MDS RPC, even if we're only changing the size;
2077 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2079 OBD_ALLOC_PTR(op_data);
2080 if (op_data == NULL)
2081 GOTO(out, rc = -ENOMEM);
2083 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2084 /* If we are changing file size, file content is
2085 * modified, flag it.
2087 xvalid |= OP_XVALID_OWNEROVERRIDE;
2088 op_data->op_bias |= MDS_DATA_MODIFIED;
2089 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2092 if (attr->ia_valid & ATTR_FILE) {
2093 struct ll_file_data *fd = attr->ia_file->private_data;
2095 if (fd->fd_lease_och)
2096 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2099 op_data->op_attr = *attr;
2100 op_data->op_xvalid = xvalid;
2102 rc = ll_md_setattr(dentry, op_data);
2106 if (!S_ISREG(inode->i_mode) || hsm_import)
2109 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2110 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2111 xvalid & OP_XVALID_CTIME_SET) {
2112 bool cached = false;
2114 rc = pcc_inode_setattr(inode, attr, &cached);
2117 CERROR("%s: PCC inode "DFID" setattr failed: "
2119 ll_i2sbi(inode)->ll_fsname,
2120 PFID(&lli->lli_fid), rc);
2124 unsigned int flags = 0;
2126 /* For truncate and utimes sending attributes to OSTs,
2127 * setting mtime/atime to the past will be performed
2128 * under PW [0:EOF] extent lock (new_size:EOF for
2129 * truncate). It may seem excessive to send mtime/atime
2130 * updates to OSTs when not setting times to past, but
2131 * it is necessary due to possible time
2132 * de-synchronization between MDT inode and OST objects
2134 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode) &&
2135 attr->ia_valid & ATTR_SIZE) {
2136 xvalid |= OP_XVALID_FLAGS;
2137 flags = LUSTRE_ENCRYPT_FL;
2138 /* Call to ll_io_zero_page is not necessary if
2139 * truncating on PAGE_SIZE boundary, because
2140 * whole pages will be wiped.
2141 * In case of Direct IO, all we need is to set
2144 if (attr->ia_size & ~PAGE_MASK &&
2145 !(attr->ia_valid & ATTR_FILE &&
2146 attr->ia_file->f_flags & O_DIRECT)) {
2148 attr->ia_size & (PAGE_SIZE - 1);
2150 rc = ll_io_zero_page(inode,
2151 attr->ia_size >> PAGE_SHIFT,
2152 offset, PAGE_SIZE - offset);
2157 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2161 /* If the file was restored, it needs to set dirty flag.
2163 * We've already sent MDS_DATA_MODIFIED flag in
2164 * ll_md_setattr() for truncate. However, the MDT refuses to
2165 * set the HS_DIRTY flag on released files, so we have to set
2166 * it again if the file has been restored. Please check how
2167 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2169 * Please notice that if the file is not released, the previous
2170 * MDS_DATA_MODIFIED has taken effect and usually
2171 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2172 * This way we can save an RPC for common open + trunc
2174 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2175 struct hsm_state_set hss = {
2176 .hss_valid = HSS_SETMASK,
2177 .hss_setmask = HS_DIRTY,
2181 rc2 = ll_hsm_state_set(inode, &hss);
2182 /* truncate and write can happen at the same time, so that
2183 * the file can be set modified even though the file is not
2184 * restored from released state, and ll_hsm_state_set() is
2185 * not applicable for the file, and rc2 < 0 is normal in this
2188 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2189 PFID(ll_inode2fid(inode)), rc2);
2194 if (op_data != NULL)
2195 ll_finish_md_op_data(op_data);
2197 if (S_ISREG(inode->i_mode)) {
2199 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2200 inode_dio_wait(inode);
2201 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2202 * flag. ll_update_inode (called from ll_md_setattr), clears
2203 * inode flags, so there is a gap where S_NOSEC is not set.
2204 * This can cause a writer to take the i_mutex unnecessarily,
2205 * but this is safe to do and should be rare. */
2206 inode_has_no_xattr(inode);
2210 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2211 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2212 ktime_us_delta(ktime_get(), kstart));
2217 int ll_setattr(struct dentry *de, struct iattr *attr)
2219 int mode = de->d_inode->i_mode;
2220 enum op_xvalid xvalid = 0;
2223 rc = llcrypt_prepare_setattr(de, attr);
2227 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2228 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2229 xvalid |= OP_XVALID_OWNEROVERRIDE;
2231 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2232 (ATTR_SIZE|ATTR_MODE)) &&
2233 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2234 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2235 !(attr->ia_mode & S_ISGID))))
2236 attr->ia_valid |= ATTR_FORCE;
2238 if ((attr->ia_valid & ATTR_MODE) &&
2240 !(attr->ia_mode & S_ISUID) &&
2241 !(attr->ia_valid & ATTR_KILL_SUID))
2242 attr->ia_valid |= ATTR_KILL_SUID;
2244 if ((attr->ia_valid & ATTR_MODE) &&
2245 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2246 !(attr->ia_mode & S_ISGID) &&
2247 !(attr->ia_valid & ATTR_KILL_SGID))
2248 attr->ia_valid |= ATTR_KILL_SGID;
2250 return ll_setattr_raw(de, attr, xvalid, false);
2253 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2256 struct obd_statfs obd_osfs = { 0 };
2261 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2263 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
2264 flags |= OBD_STATFS_NODELAY;
2266 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2270 osfs->os_type = LL_SUPER_MAGIC;
2272 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2273 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2275 if (osfs->os_state & OS_STATFS_SUM)
2278 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2279 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2282 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2283 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2286 osfs->os_bsize = obd_osfs.os_bsize;
2287 osfs->os_blocks = obd_osfs.os_blocks;
2288 osfs->os_bfree = obd_osfs.os_bfree;
2289 osfs->os_bavail = obd_osfs.os_bavail;
2291 /* If we have _some_ OSTs, but don't have as many free objects on the
2292 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2293 * to compensate, so that the "inodes in use" number is correct.
2294 * This should be kept in sync with lod_statfs() behaviour.
2296 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2297 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2299 osfs->os_ffree = obd_osfs.os_ffree;
2306 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2308 struct if_quotactl qctl = {
2309 .qc_cmd = LUSTRE_Q_GETQUOTA,
2310 .qc_type = PRJQUOTA,
2311 .qc_valid = QC_GENERAL,
2313 u64 limit, curblock;
2316 qctl.qc_id = ll_i2info(inode)->lli_projid;
2317 ret = quotactl_ioctl(ll_i2sbi(inode), &qctl);
2319 /* ignore errors if project ID does not have
2320 * a quota limit or feature unsupported.
2322 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2327 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2328 qctl.qc_dqblk.dqb_bsoftlimit :
2329 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2330 if (limit && sfs->f_blocks > limit) {
2331 curblock = (qctl.qc_dqblk.dqb_curspace +
2332 sfs->f_bsize - 1) / sfs->f_bsize;
2333 sfs->f_blocks = limit;
2334 sfs->f_bfree = sfs->f_bavail =
2335 (sfs->f_blocks > curblock) ?
2336 (sfs->f_blocks - curblock) : 0;
2339 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2340 qctl.qc_dqblk.dqb_isoftlimit :
2341 qctl.qc_dqblk.dqb_ihardlimit;
2342 if (limit && sfs->f_files > limit) {
2343 sfs->f_files = limit;
2344 sfs->f_ffree = (sfs->f_files >
2345 qctl.qc_dqblk.dqb_curinodes) ?
2346 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2352 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2354 struct super_block *sb = de->d_sb;
2355 struct obd_statfs osfs;
2356 __u64 fsid = huge_encode_dev(sb->s_dev);
2357 ktime_t kstart = ktime_get();
2360 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2362 /* Some amount of caching on the client is allowed */
2363 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2367 statfs_unpack(sfs, &osfs);
2369 /* We need to downshift for all 32-bit kernels, because we can't
2370 * tell if the kernel is being called via sys_statfs64() or not.
2371 * Stop before overflowing f_bsize - in which case it is better
2372 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2373 if (sizeof(long) < 8) {
2374 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2377 osfs.os_blocks >>= 1;
2378 osfs.os_bfree >>= 1;
2379 osfs.os_bavail >>= 1;
2383 sfs->f_blocks = osfs.os_blocks;
2384 sfs->f_bfree = osfs.os_bfree;
2385 sfs->f_bavail = osfs.os_bavail;
2386 sfs->f_fsid.val[0] = (__u32)fsid;
2387 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2388 if (ll_i2info(de->d_inode)->lli_projid)
2389 return ll_statfs_project(de->d_inode, sfs);
2391 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2392 ktime_us_delta(ktime_get(), kstart));
2397 void ll_inode_size_lock(struct inode *inode)
2399 struct ll_inode_info *lli;
2401 LASSERT(!S_ISDIR(inode->i_mode));
2403 lli = ll_i2info(inode);
2404 mutex_lock(&lli->lli_size_mutex);
2407 void ll_inode_size_unlock(struct inode *inode)
2409 struct ll_inode_info *lli;
2411 lli = ll_i2info(inode);
2412 mutex_unlock(&lli->lli_size_mutex);
2415 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2417 /* do not clear encryption flag */
2418 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2419 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2420 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2421 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2423 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2426 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2428 struct ll_inode_info *lli = ll_i2info(inode);
2429 struct mdt_body *body = md->body;
2430 struct ll_sb_info *sbi = ll_i2sbi(inode);
2433 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2434 rc = cl_file_inode_init(inode, md);
2439 if (S_ISDIR(inode->i_mode)) {
2440 rc = ll_update_lsm_md(inode, md);
2445 if (body->mbo_valid & OBD_MD_FLACL)
2446 lli_replace_acl(lli, md);
2448 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1,
2449 sbi->ll_flags & LL_SBI_32BIT_API);
2450 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2452 if (body->mbo_valid & OBD_MD_FLATIME) {
2453 if (body->mbo_atime > inode->i_atime.tv_sec)
2454 inode->i_atime.tv_sec = body->mbo_atime;
2455 lli->lli_atime = body->mbo_atime;
2458 if (body->mbo_valid & OBD_MD_FLMTIME) {
2459 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2461 "setting ino %lu mtime from %lld to %llu\n",
2462 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2464 inode->i_mtime.tv_sec = body->mbo_mtime;
2466 lli->lli_mtime = body->mbo_mtime;
2469 if (body->mbo_valid & OBD_MD_FLCTIME) {
2470 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2471 inode->i_ctime.tv_sec = body->mbo_ctime;
2472 lli->lli_ctime = body->mbo_ctime;
2475 if (body->mbo_valid & OBD_MD_FLBTIME)
2476 lli->lli_btime = body->mbo_btime;
2478 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2479 if (body->mbo_valid & OBD_MD_FLFLAGS)
2480 ll_update_inode_flags(inode, body->mbo_flags);
2481 if (body->mbo_valid & OBD_MD_FLMODE)
2482 inode->i_mode = (inode->i_mode & S_IFMT) |
2483 (body->mbo_mode & ~S_IFMT);
2485 if (body->mbo_valid & OBD_MD_FLTYPE)
2486 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2487 (body->mbo_mode & S_IFMT);
2489 LASSERT(inode->i_mode != 0);
2490 if (body->mbo_valid & OBD_MD_FLUID)
2491 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2492 if (body->mbo_valid & OBD_MD_FLGID)
2493 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2494 if (body->mbo_valid & OBD_MD_FLPROJID)
2495 lli->lli_projid = body->mbo_projid;
2496 if (body->mbo_valid & OBD_MD_FLNLINK)
2497 set_nlink(inode, body->mbo_nlink);
2498 if (body->mbo_valid & OBD_MD_FLRDEV)
2499 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2501 if (body->mbo_valid & OBD_MD_FLID) {
2502 /* FID shouldn't be changed! */
2503 if (fid_is_sane(&lli->lli_fid)) {
2504 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2505 "Trying to change FID "DFID
2506 " to the "DFID", inode "DFID"(%p)\n",
2507 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2508 PFID(ll_inode2fid(inode)), inode);
2510 lli->lli_fid = body->mbo_fid1;
2514 LASSERT(fid_seq(&lli->lli_fid) != 0);
2516 lli->lli_attr_valid = body->mbo_valid;
2517 if (body->mbo_valid & OBD_MD_FLSIZE) {
2518 i_size_write(inode, body->mbo_size);
2520 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2521 PFID(ll_inode2fid(inode)),
2522 (unsigned long long)body->mbo_size);
2524 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2525 inode->i_blocks = body->mbo_blocks;
2527 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2528 lli->lli_lazysize = body->mbo_size;
2529 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2530 lli->lli_lazyblocks = body->mbo_blocks;
2533 if (body->mbo_valid & OBD_MD_TSTATE) {
2534 /* Set LLIF_FILE_RESTORING if restore ongoing and
2535 * clear it when done to ensure to start again
2536 * glimpsing updated attrs
2538 if (body->mbo_t_state & MS_RESTORE)
2539 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2541 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2547 int ll_read_inode2(struct inode *inode, void *opaque)
2549 struct lustre_md *md = opaque;
2550 struct ll_inode_info *lli = ll_i2info(inode);
2554 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2555 PFID(&lli->lli_fid), inode);
2557 /* Core attributes from the MDS first. This is a new inode, and
2558 * the VFS doesn't zero times in the core inode so we have to do
2559 * it ourselves. They will be overwritten by either MDS or OST
2560 * attributes - we just need to make sure they aren't newer.
2562 inode->i_mtime.tv_sec = 0;
2563 inode->i_atime.tv_sec = 0;
2564 inode->i_ctime.tv_sec = 0;
2566 rc = ll_update_inode(inode, md);
2570 /* OIDEBUG(inode); */
2572 #ifdef HAVE_BACKING_DEV_INFO
2573 /* initializing backing dev info. */
2574 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2576 if (S_ISREG(inode->i_mode)) {
2577 struct ll_sb_info *sbi = ll_i2sbi(inode);
2578 inode->i_op = &ll_file_inode_operations;
2579 inode->i_fop = sbi->ll_fop;
2580 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2582 } else if (S_ISDIR(inode->i_mode)) {
2583 inode->i_op = &ll_dir_inode_operations;
2584 inode->i_fop = &ll_dir_operations;
2586 } else if (S_ISLNK(inode->i_mode)) {
2587 inode->i_op = &ll_fast_symlink_inode_operations;
2590 inode->i_op = &ll_special_inode_operations;
2592 init_special_inode(inode, inode->i_mode,
2601 void ll_delete_inode(struct inode *inode)
2603 struct ll_inode_info *lli = ll_i2info(inode);
2604 struct address_space *mapping = &inode->i_data;
2605 unsigned long nrpages;
2606 unsigned long flags;
2610 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2611 /* It is last chance to write out dirty pages,
2612 * otherwise we may lose data while umount.
2614 * If i_nlink is 0 then just discard data. This is safe because
2615 * local inode gets i_nlink 0 from server only for the last
2616 * unlink, so that file is not opened somewhere else
2618 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2619 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2621 truncate_inode_pages_final(mapping);
2623 /* Workaround for LU-118: Note nrpages may not be totally updated when
2624 * truncate_inode_pages() returns, as there can be a page in the process
2625 * of deletion (inside __delete_from_page_cache()) in the specified
2626 * range. Thus mapping->nrpages can be non-zero when this function
2627 * returns even after truncation of the whole mapping. Only do this if
2628 * npages isn't already zero.
2630 nrpages = mapping->nrpages;
2632 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2633 nrpages = mapping->nrpages;
2634 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2635 } /* Workaround end */
2637 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, "
2638 "see https://jira.whamcloud.com/browse/LU-118\n",
2639 ll_i2sbi(inode)->ll_fsname,
2640 PFID(ll_inode2fid(inode)), inode, nrpages);
2642 ll_clear_inode(inode);
2648 int ll_iocontrol(struct inode *inode, struct file *file,
2649 unsigned int cmd, unsigned long arg)
2651 struct ll_sb_info *sbi = ll_i2sbi(inode);
2652 struct ptlrpc_request *req = NULL;
2657 case FS_IOC_GETFLAGS: {
2658 struct mdt_body *body;
2659 struct md_op_data *op_data;
2661 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2662 0, 0, LUSTRE_OPC_ANY,
2664 if (IS_ERR(op_data))
2665 RETURN(PTR_ERR(op_data));
2667 op_data->op_valid = OBD_MD_FLFLAGS;
2668 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2669 ll_finish_md_op_data(op_data);
2671 CERROR("%s: failure inode "DFID": rc = %d\n",
2672 sbi->ll_md_exp->exp_obd->obd_name,
2673 PFID(ll_inode2fid(inode)), rc);
2677 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2679 flags = body->mbo_flags;
2681 ptlrpc_req_finished(req);
2683 RETURN(put_user(flags, (int __user *)arg));
2685 case FS_IOC_SETFLAGS: {
2687 struct md_op_data *op_data;
2688 struct cl_object *obj;
2689 struct fsxattr fa = { 0 };
2691 if (get_user(flags, (int __user *)arg))
2694 fa.fsx_projid = ll_i2info(inode)->lli_projid;
2695 if (flags & LUSTRE_PROJINHERIT_FL)
2696 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
2698 rc = ll_ioctl_check_project(inode, &fa);
2702 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
2703 LUSTRE_OPC_ANY, NULL);
2704 if (IS_ERR(op_data))
2705 RETURN(PTR_ERR(op_data));
2707 op_data->op_attr_flags = flags;
2708 op_data->op_xvalid |= OP_XVALID_FLAGS;
2709 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
2710 ll_finish_md_op_data(op_data);
2711 ptlrpc_req_finished(req);
2715 ll_update_inode_flags(inode, flags);
2717 obj = ll_i2info(inode)->lli_clob;
2721 OBD_ALLOC_PTR(attr);
2725 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
2737 int ll_flush_ctx(struct inode *inode)
2739 struct ll_sb_info *sbi = ll_i2sbi(inode);
2741 CDEBUG(D_SEC, "flush context for user %d\n",
2742 from_kuid(&init_user_ns, current_uid()));
2744 obd_set_info_async(NULL, sbi->ll_md_exp,
2745 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2747 obd_set_info_async(NULL, sbi->ll_dt_exp,
2748 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2753 /* umount -f client means force down, don't save state */
2754 void ll_umount_begin(struct super_block *sb)
2756 struct ll_sb_info *sbi = ll_s2sbi(sb);
2757 struct obd_device *obd;
2758 struct obd_ioctl_data *ioc_data;
2762 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2763 sb->s_count, atomic_read(&sb->s_active));
2765 obd = class_exp2obd(sbi->ll_md_exp);
2767 CERROR("Invalid MDC connection handle %#llx\n",
2768 sbi->ll_md_exp->exp_handle.h_cookie);
2774 obd = class_exp2obd(sbi->ll_dt_exp);
2776 CERROR("Invalid LOV connection handle %#llx\n",
2777 sbi->ll_dt_exp->exp_handle.h_cookie);
2783 OBD_ALLOC_PTR(ioc_data);
2785 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2786 sizeof *ioc_data, ioc_data, NULL);
2788 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2789 sizeof *ioc_data, ioc_data, NULL);
2791 OBD_FREE_PTR(ioc_data);
2794 /* Really, we'd like to wait until there are no requests outstanding,
2795 * and then continue. For now, we just periodically checking for vfs
2796 * to decrement mnt_cnt and hope to finish it within 10sec.
2800 !may_umount(sbi->ll_mnt.mnt)) {
2808 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2810 struct ll_sb_info *sbi = ll_s2sbi(sb);
2811 char *profilenm = get_profile_name(sb);
2815 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
2816 read_only = *flags & MS_RDONLY;
2817 err = obd_set_info_async(NULL, sbi->ll_md_exp,
2818 sizeof(KEY_READ_ONLY),
2819 KEY_READ_ONLY, sizeof(read_only),
2822 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2823 profilenm, read_only ?
2824 "read-only" : "read-write", err);
2829 sb->s_flags |= SB_RDONLY;
2831 sb->s_flags &= ~SB_RDONLY;
2833 if (sbi->ll_flags & LL_SBI_VERBOSE)
2834 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
2835 read_only ? "read-only" : "read-write");
2841 * Cleanup the open handle that is cached on MDT-side.
2843 * For open case, the client side open handling thread may hit error
2844 * after the MDT grant the open. Under such case, the client should
2845 * send close RPC to the MDT as cleanup; otherwise, the open handle
2846 * on the MDT will be leaked there until the client umount or evicted.
2848 * In further, if someone unlinked the file, because the open handle
2849 * holds the reference on such file/object, then it will block the
2850 * subsequent threads that want to locate such object via FID.
2852 * \param[in] sb super block for this file-system
2853 * \param[in] open_req pointer to the original open request
2855 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
2857 struct mdt_body *body;
2858 struct md_op_data *op_data;
2859 struct ptlrpc_request *close_req = NULL;
2860 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
2863 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
2864 OBD_ALLOC_PTR(op_data);
2865 if (op_data == NULL) {
2866 CWARN("%s: cannot allocate op_data to release open handle for "
2867 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
2872 op_data->op_fid1 = body->mbo_fid1;
2873 op_data->op_open_handle = body->mbo_open_handle;
2874 op_data->op_mod_time = ktime_get_real_seconds();
2875 md_close(exp, op_data, NULL, &close_req);
2876 ptlrpc_req_finished(close_req);
2877 ll_finish_md_op_data(op_data);
2882 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
2883 struct super_block *sb, struct lookup_intent *it)
2885 struct ll_sb_info *sbi = NULL;
2886 struct lustre_md md = { NULL };
2887 bool default_lmv_deleted = false;
2892 LASSERT(*inode || sb);
2893 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2894 rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
2895 sbi->ll_md_exp, &md);
2900 * clear default_lmv only if intent_getattr reply doesn't contain it.
2901 * but it needs to be done after iget, check this early because
2902 * ll_update_lsm_md() may change md.
2904 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
2905 S_ISDIR(md.body->mbo_mode) && !md.default_lmv)
2906 default_lmv_deleted = true;
2909 rc = ll_update_inode(*inode, &md);
2913 LASSERT(sb != NULL);
2916 * At this point server returns to client's same fid as client
2917 * generated for creating. So using ->fid1 is okay here.
2919 if (!fid_is_sane(&md.body->mbo_fid1)) {
2920 CERROR("%s: Fid is insane "DFID"\n",
2922 PFID(&md.body->mbo_fid1));
2923 GOTO(out, rc = -EINVAL);
2926 *inode = ll_iget(sb, cl_fid_build_ino(&md.body->mbo_fid1,
2927 sbi->ll_flags & LL_SBI_32BIT_API),
2929 if (IS_ERR(*inode)) {
2931 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
2933 CERROR("new_inode -fatal: rc %d\n", rc);
2938 /* Handling piggyback layout lock.
2939 * Layout lock can be piggybacked by getattr and open request.
2940 * The lsm can be applied to inode only if it comes with a layout lock
2941 * otherwise correct layout may be overwritten, for example:
2942 * 1. proc1: mdt returns a lsm but not granting layout
2943 * 2. layout was changed by another client
2944 * 3. proc2: refresh layout and layout lock granted
2945 * 4. proc1: to apply a stale layout */
2946 if (it != NULL && it->it_lock_mode != 0) {
2947 struct lustre_handle lockh;
2948 struct ldlm_lock *lock;
2950 lockh.cookie = it->it_lock_handle;
2951 lock = ldlm_handle2lock(&lockh);
2952 LASSERT(lock != NULL);
2953 if (ldlm_has_layout(lock)) {
2954 struct cl_object_conf conf;
2956 memset(&conf, 0, sizeof(conf));
2957 conf.coc_opc = OBJECT_CONF_SET;
2958 conf.coc_inode = *inode;
2959 conf.coc_lock = lock;
2960 conf.u.coc_layout = md.layout;
2961 (void)ll_layout_conf(*inode, &conf);
2963 LDLM_LOCK_PUT(lock);
2966 if (default_lmv_deleted)
2967 ll_update_default_lsm_md(*inode, &md);
2969 /* we may want to apply some policy for foreign file/dir */
2970 if (ll_sbi_has_foreign_symlink(sbi)) {
2971 rc = ll_manage_foreign(*inode, &md);
2979 /* cleanup will be done if necessary */
2980 md_free_lustre_md(sbi->ll_md_exp, &md);
2982 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
2983 ll_intent_drop_lock(it);
2984 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, req);
2990 int ll_obd_statfs(struct inode *inode, void __user *arg)
2992 struct ll_sb_info *sbi = NULL;
2993 struct obd_export *exp;
2994 struct obd_ioctl_data *data = NULL;
2999 sbi = ll_i2sbi(inode);
3001 GOTO(out_statfs, rc = -EINVAL);
3003 rc = obd_ioctl_getdata(&data, &len, arg);
3005 GOTO(out_statfs, rc);
3007 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3008 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3009 GOTO(out_statfs, rc = -EINVAL);
3011 if (data->ioc_inllen1 != sizeof(__u32) ||
3012 data->ioc_inllen2 != sizeof(__u32) ||
3013 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3014 data->ioc_plen2 != sizeof(struct obd_uuid))
3015 GOTO(out_statfs, rc = -EINVAL);
3017 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3018 if (type & LL_STATFS_LMV)
3019 exp = sbi->ll_md_exp;
3020 else if (type & LL_STATFS_LOV)
3021 exp = sbi->ll_dt_exp;
3023 GOTO(out_statfs, rc = -ENODEV);
3025 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3027 GOTO(out_statfs, rc);
3029 OBD_FREE_LARGE(data, len);
3034 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3035 * be called early to avoid deadlock.
3037 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3039 if (op_data->op_mea2_sem) {
3040 up_read_non_owner(op_data->op_mea2_sem);
3041 op_data->op_mea2_sem = NULL;
3044 if (op_data->op_mea1_sem) {
3045 up_read_non_owner(op_data->op_mea1_sem);
3046 op_data->op_mea1_sem = NULL;
3050 /* this function prepares md_op_data hint for passing it down to MD stack. */
3051 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3052 struct inode *i1, struct inode *i2,
3053 const char *name, size_t namelen,
3054 __u32 mode, enum md_op_code opc,
3057 LASSERT(i1 != NULL);
3060 /* Do not reuse namelen for something else. */
3062 return ERR_PTR(-EINVAL);
3064 if (namelen > ll_i2sbi(i1)->ll_namelen)
3065 return ERR_PTR(-ENAMETOOLONG);
3067 /* "/" is not valid name, but it's allowed */
3068 if (!lu_name_is_valid_2(name, namelen) &&
3069 strncmp("/", name, namelen) != 0)
3070 return ERR_PTR(-EINVAL);
3073 if (op_data == NULL)
3074 OBD_ALLOC_PTR(op_data);
3076 if (op_data == NULL)
3077 return ERR_PTR(-ENOMEM);
3079 ll_i2gids(op_data->op_suppgids, i1, i2);
3080 op_data->op_fid1 = *ll_inode2fid(i1);
3081 op_data->op_code = opc;
3083 if (S_ISDIR(i1->i_mode)) {
3084 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3085 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3086 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3087 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3091 op_data->op_fid2 = *ll_inode2fid(i2);
3092 if (S_ISDIR(i2->i_mode)) {
3094 /* i2 is typically a child of i1, and MUST be
3095 * further from the root to avoid deadlocks.
3097 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3098 op_data->op_mea2_sem =
3099 &ll_i2info(i2)->lli_lsm_sem;
3101 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3104 fid_zero(&op_data->op_fid2);
3107 if (ll_i2sbi(i1)->ll_flags & LL_SBI_64BIT_HASH)
3108 op_data->op_cli_flags |= CLI_HASH64;
3110 if (ll_need_32bit_api(ll_i2sbi(i1)))
3111 op_data->op_cli_flags |= CLI_API32;
3113 op_data->op_name = name;
3114 op_data->op_namelen = namelen;
3115 op_data->op_mode = mode;
3116 op_data->op_mod_time = ktime_get_real_seconds();
3117 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3118 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3119 op_data->op_cap = cfs_curproc_cap_pack();
3120 op_data->op_mds = 0;
3121 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3122 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3123 op_data->op_bias |= MDS_CREATE_VOLATILE;
3125 op_data->op_data = data;
3130 void ll_finish_md_op_data(struct md_op_data *op_data)
3132 ll_unlock_md_op_lsm(op_data);
3133 security_release_secctx(op_data->op_file_secctx,
3134 op_data->op_file_secctx_size);
3135 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3136 OBD_FREE_PTR(op_data);
3139 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3141 struct ll_sb_info *sbi;
3143 LASSERT(seq && dentry);
3144 sbi = ll_s2sbi(dentry->d_sb);
3146 if (sbi->ll_flags & LL_SBI_NOLCK)
3147 seq_puts(seq, ",nolock");
3149 /* "flock" is the default since 2.13, but it wasn't for many years,
3150 * so it is still useful to print this to show it is enabled.
3151 * Start to print "noflock" so it is now clear when flock is disabled.
3153 if (sbi->ll_flags & LL_SBI_FLOCK)
3154 seq_puts(seq, ",flock");
3155 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
3156 seq_puts(seq, ",localflock");
3158 seq_puts(seq, ",noflock");
3160 if (sbi->ll_flags & LL_SBI_USER_XATTR)
3161 seq_puts(seq, ",user_xattr");
3163 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
3164 seq_puts(seq, ",lazystatfs");
3166 if (sbi->ll_flags & LL_SBI_USER_FID2PATH)
3167 seq_puts(seq, ",user_fid2path");
3169 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
3170 seq_puts(seq, ",always_ping");
3172 if (ll_sbi_has_test_dummy_encryption(sbi))
3173 seq_puts(seq, ",test_dummy_encryption");
3175 if (ll_sbi_has_encrypt(sbi))
3176 seq_puts(seq, ",encrypt");
3178 seq_puts(seq, ",noencrypt");
3180 if (sbi->ll_flags & LL_SBI_FOREIGN_SYMLINK) {
3181 seq_puts(seq, ",foreign_symlink=");
3182 seq_puts(seq, sbi->ll_foreign_symlink_prefix);
3189 * Get obd name by cmd, and copy out to user space
3191 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
3193 struct ll_sb_info *sbi = ll_i2sbi(inode);
3194 struct obd_device *obd;
3197 if (cmd == OBD_IOC_GETDTNAME)
3198 obd = class_exp2obd(sbi->ll_dt_exp);
3199 else if (cmd == OBD_IOC_GETMDNAME)
3200 obd = class_exp2obd(sbi->ll_md_exp);
3207 if (copy_to_user((void __user *)arg, obd->obd_name,
3208 strlen(obd->obd_name) + 1))
3214 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3221 p.mnt = current->fs->root.mnt;
3223 path = d_path(&p, buf, bufsize);
3228 void ll_dirty_page_discard_warn(struct page *page, int ioret)
3230 char *buf, *path = NULL;
3231 struct dentry *dentry = NULL;
3232 struct inode *inode = page->mapping->host;
3234 /* this can be called inside spin lock so use GFP_ATOMIC. */
3235 buf = (char *)__get_free_page(GFP_ATOMIC);
3237 dentry = d_find_alias(page->mapping->host);
3239 path = ll_d_path(dentry, buf, PAGE_SIZE);
3242 /* The below message is checked in recovery-small.sh test_24b */
3244 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3245 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3246 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
3247 PFID(ll_inode2fid(inode)),
3248 (path && !IS_ERR(path)) ? path : "", ioret);
3254 free_page((unsigned long)buf);
3257 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3258 struct lov_user_md **kbuf)
3260 struct lov_user_md lum;
3264 if (copy_from_user(&lum, md, sizeof(lum)))
3267 lum_size = ll_lov_user_md_size(&lum);
3271 OBD_ALLOC_LARGE(*kbuf, lum_size);
3275 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3276 OBD_FREE_LARGE(*kbuf, lum_size);
3284 * Compute llite root squash state after a change of root squash
3285 * configuration setting or add/remove of a lnet nid
3287 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3289 struct root_squash_info *squash = &sbi->ll_squash;
3292 struct lnet_process_id id;
3294 /* Update norootsquash flag */
3295 spin_lock(&squash->rsi_lock);
3296 if (list_empty(&squash->rsi_nosquash_nids))
3297 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
3299 /* Do not apply root squash as soon as one of our NIDs is
3300 * in the nosquash_nids list */
3303 while (LNetGetId(i++, &id) != -ENOENT) {
3304 if (id.nid == LNET_NID_LO_0)
3306 if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) {
3312 sbi->ll_flags |= LL_SBI_NOROOTSQUASH;
3314 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
3316 spin_unlock(&squash->rsi_lock);
3320 * Parse linkea content to extract information about a given hardlink
3322 * \param[in] ldata - Initialized linkea data
3323 * \param[in] linkno - Link identifier
3324 * \param[out] parent_fid - The entry's parent FID
3325 * \param[out] ln - Entry name destination buffer
3327 * \retval 0 on success
3328 * \retval Appropriate negative error code on failure
3330 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3331 struct lu_fid *parent_fid, struct lu_name *ln)
3337 rc = linkea_init_with_rec(ldata);
3341 if (linkno >= ldata->ld_leh->leh_reccount)
3342 /* beyond last link */
3345 linkea_first_entry(ldata);
3346 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3347 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3352 linkea_next_entry(ldata);
3362 * Get parent FID and name of an identified link. Operation is performed for
3363 * a given link number, letting the caller iterate over linkno to list one or
3364 * all links of an entry.
3366 * \param[in] file - File descriptor against which to perform the operation
3367 * \param[in,out] arg - User-filled structure containing the linkno to operate
3368 * on and the available size. It is eventually filled with
3369 * the requested information or left untouched on error
3371 * \retval - 0 on success
3372 * \retval - Appropriate negative error code on failure
3374 int ll_getparent(struct file *file, struct getparent __user *arg)
3376 struct inode *inode = file_inode(file);
3377 struct linkea_data *ldata;
3378 struct lu_buf buf = LU_BUF_NULL;
3380 struct lu_fid parent_fid;
3387 if (!capable(CAP_DAC_READ_SEARCH) &&
3388 !(ll_i2sbi(inode)->ll_flags & LL_SBI_USER_FID2PATH))
3391 if (get_user(name_size, &arg->gp_name_size))
3394 if (get_user(linkno, &arg->gp_linkno))
3397 if (name_size > PATH_MAX)
3400 OBD_ALLOC(ldata, sizeof(*ldata));
3404 rc = linkea_data_new(ldata, &buf);
3406 GOTO(ldata_free, rc);
3408 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3409 buf.lb_len, OBD_MD_FLXATTR);
3413 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3417 if (ln.ln_namelen >= name_size)
3418 GOTO(lb_free, rc = -EOVERFLOW);
3420 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3421 GOTO(lb_free, rc = -EFAULT);
3423 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3424 GOTO(lb_free, rc = -EFAULT);
3426 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3427 GOTO(lb_free, rc = -EFAULT);
3432 OBD_FREE(ldata, sizeof(*ldata));