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;
365 if (sbi->ll_flags & LL_SBI_FLOCK)
366 sbi->ll_fop = &ll_file_operations_flock;
367 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
368 sbi->ll_fop = &ll_file_operations;
370 sbi->ll_fop = &ll_file_operations_noflock;
372 /* always ping even if server suppress_pings */
373 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
374 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
376 obd_connect_set_secctx(data);
377 if (ll_sbi_has_encrypt(sbi))
378 obd_connect_set_enc(data);
380 #if defined(CONFIG_SECURITY)
381 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
384 data->ocd_brw_size = MD_MAX_BRW_SIZE;
386 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
387 &sbi->ll_sb_uuid, data, sbi->ll_cache);
389 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
390 "recovery, of which this client is not a "
391 "part. Please wait for recovery to complete,"
392 " abort, or time out.\n", md);
395 CERROR("cannot connect to %s: rc = %d\n", md, err);
399 sbi->ll_md_exp->exp_connect_data = *data;
401 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
402 LUSTRE_SEQ_METADATA);
404 CERROR("%s: Can't init metadata layer FID infrastructure, "
405 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
409 /* For mount, we only need fs info from MDT0, and also in DNE, it
410 * can make sure the client can be mounted as long as MDT0 is
412 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
413 ktime_get_seconds() - sbi->ll_statfs_max_age,
414 OBD_STATFS_FOR_MDT0);
416 GOTO(out_md_fid, err);
418 /* This needs to be after statfs to ensure connect has finished.
419 * Note that "data" does NOT contain the valid connect reply.
420 * If connecting to a 1.8 server there will be no LMV device, so
421 * we can access the MDC export directly and exp_connect_flags will
422 * be non-zero, but if accessing an upgraded 2.1 server it will
423 * have the correct flags filled in.
424 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
425 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
426 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
427 valid != CLIENT_CONNECT_MDT_REQD) {
430 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
431 obd_connect_flags2str(buf, PAGE_SIZE,
432 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
433 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
434 "feature(s) needed for correct operation "
435 "of this client (%s). Please upgrade "
436 "server or downgrade client.\n",
437 sbi->ll_md_exp->exp_obd->obd_name, buf);
438 OBD_FREE(buf, PAGE_SIZE);
439 GOTO(out_md_fid, err = -EPROTO);
442 size = sizeof(*data);
443 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
444 KEY_CONN_DATA, &size, data);
446 CERROR("%s: Get connect data failed: rc = %d\n",
447 sbi->ll_md_exp->exp_obd->obd_name, err);
448 GOTO(out_md_fid, err);
451 LASSERT(osfs->os_bsize);
452 sb->s_blocksize = osfs->os_bsize;
453 sb->s_blocksize_bits = log2(osfs->os_bsize);
454 sb->s_magic = LL_SUPER_MAGIC;
455 sb->s_maxbytes = MAX_LFS_FILESIZE;
456 sbi->ll_namelen = osfs->os_namelen;
457 sbi->ll_mnt.mnt = current->fs->root.mnt;
459 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
460 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
461 LCONSOLE_INFO("Disabling user_xattr feature because "
462 "it is not supported on the server\n");
463 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
466 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
468 sb->s_flags |= SB_POSIXACL;
470 sbi->ll_flags |= LL_SBI_ACL;
472 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
474 sb->s_flags &= ~SB_POSIXACL;
476 sbi->ll_flags &= ~LL_SBI_ACL;
479 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
480 sbi->ll_flags |= LL_SBI_64BIT_HASH;
482 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
483 sbi->ll_flags |= LL_SBI_LAYOUT_LOCK;
485 if (obd_connect_has_secctx(data))
486 sbi->ll_flags |= LL_SBI_FILE_SECCTX;
488 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
489 if (ll_sbi_has_test_dummy_encryption(sbi))
490 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
492 sbi->ll_md_exp->exp_obd->obd_name);
493 ll_sbi_set_encrypt(sbi, false);
496 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
497 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
498 LCONSOLE_INFO("%s: disabling xattr cache due to "
499 "unknown maximum xattr size.\n", dt);
500 } else if (!sbi->ll_xattr_cache_set) {
501 /* If xattr_cache is already set (no matter 0 or 1)
502 * during processing llog, it won't be enabled here. */
503 sbi->ll_flags |= LL_SBI_XATTR_CACHE;
504 sbi->ll_xattr_cache_enabled = 1;
508 sbi->ll_dt_obd = class_name2obd(dt);
509 if (!sbi->ll_dt_obd) {
510 CERROR("DT %s: not setup or attached\n", dt);
511 GOTO(out_md_fid, err = -ENODEV);
514 /* pass client page size via ocd_grant_blkbits, the server should report
515 * back its backend blocksize for grant calculation purpose */
516 data->ocd_grant_blkbits = PAGE_SHIFT;
518 /* indicate OST features supported by this client */
519 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
520 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
521 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
522 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
523 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
524 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
525 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
526 OBD_CONNECT_EINPROGRESS |
527 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
528 OBD_CONNECT_LAYOUTLOCK |
529 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
530 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
531 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
532 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
533 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK;
535 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
536 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
538 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
539 * disabled by default, because it can still be enabled on the
540 * fly via /sys. As a consequence, we still need to come to an
541 * agreement on the supported algorithms at connect time
543 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
545 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
546 data->ocd_cksum_types = OBD_CKSUM_ADLER;
548 data->ocd_cksum_types = obd_cksum_types_supported_client();
550 #ifdef HAVE_LRU_RESIZE_SUPPORT
551 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
553 /* always ping even if server suppress_pings */
554 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
555 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
557 if (ll_sbi_has_encrypt(sbi))
558 obd_connect_set_enc(data);
560 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
561 "ocd_grant: %d\n", data->ocd_connect_flags,
562 data->ocd_version, data->ocd_grant);
564 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
565 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
567 data->ocd_brw_size = DT_MAX_BRW_SIZE;
569 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
570 &sbi->ll_sb_uuid, data, sbi->ll_cache);
572 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
573 "recovery, of which this client is not a "
574 "part. Please wait for recovery to "
575 "complete, abort, or time out.\n", dt);
578 CERROR("%s: Cannot connect to %s: rc = %d\n",
579 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
583 if (ll_sbi_has_encrypt(sbi) &&
584 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
585 if (ll_sbi_has_test_dummy_encryption(sbi))
586 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
588 ll_sbi_set_encrypt(sbi, false);
589 } else if (ll_sbi_has_test_dummy_encryption(sbi)) {
590 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
593 sbi->ll_dt_exp->exp_connect_data = *data;
595 /* Don't change value if it was specified in the config log */
596 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
597 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
598 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
599 (data->ocd_brw_size >> PAGE_SHIFT));
600 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
601 sbi->ll_ra_info.ra_max_pages_per_file)
602 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
603 sbi->ll_ra_info.ra_max_pages_per_file;
606 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
607 LUSTRE_SEQ_METADATA);
609 CERROR("%s: Can't init data layer FID infrastructure, "
610 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
614 mutex_lock(&sbi->ll_lco.lco_lock);
615 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
616 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
617 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
618 mutex_unlock(&sbi->ll_lco.lco_lock);
620 fid_zero(&sbi->ll_root_fid);
621 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
624 CERROR("cannot mds_connect: rc = %d\n", err);
625 GOTO(out_lock_cn_cb, err);
627 if (!fid_is_sane(&sbi->ll_root_fid)) {
628 CERROR("%s: Invalid root fid "DFID" during mount\n",
629 sbi->ll_md_exp->exp_obd->obd_name,
630 PFID(&sbi->ll_root_fid));
631 GOTO(out_lock_cn_cb, err = -EINVAL);
633 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
635 sb->s_op = &lustre_super_operations;
636 sb->s_xattr = ll_xattr_handlers;
637 #if THREAD_SIZE >= 8192 /*b=17630*/
638 sb->s_export_op = &lustre_export_operations;
640 #ifdef HAVE_LUSTRE_CRYPTO
641 llcrypt_set_ops(sb, &lustre_cryptops);
645 * XXX: move this to after cbd setup? */
646 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
647 if (sbi->ll_flags & LL_SBI_ACL)
648 valid |= OBD_MD_FLACL;
650 OBD_ALLOC_PTR(op_data);
652 GOTO(out_lock_cn_cb, err = -ENOMEM);
654 op_data->op_fid1 = sbi->ll_root_fid;
655 op_data->op_mode = 0;
656 op_data->op_valid = valid;
658 err = md_getattr(sbi->ll_md_exp, op_data, &request);
660 OBD_FREE_PTR(op_data);
662 CERROR("%s: md_getattr failed for root: rc = %d\n",
663 sbi->ll_md_exp->exp_obd->obd_name, err);
664 GOTO(out_lock_cn_cb, err);
667 err = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
668 sbi->ll_md_exp, &lmd);
670 CERROR("failed to understand root inode md: rc = %d\n", err);
671 ptlrpc_req_finished(request);
672 GOTO(out_lock_cn_cb, err);
675 LASSERT(fid_is_sane(&sbi->ll_root_fid));
676 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid,
677 sbi->ll_flags & LL_SBI_32BIT_API),
679 md_free_lustre_md(sbi->ll_md_exp, &lmd);
680 ptlrpc_req_finished(request);
684 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
686 CERROR("%s: bad ll_iget() for root: rc = %d\n",
687 sbi->ll_fsname, err);
691 checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
692 if (sbi->ll_checksum_set) {
693 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
694 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
695 sizeof(checksum), &checksum, NULL);
697 CERROR("%s: Set checksum failed: rc = %d\n",
698 sbi->ll_dt_exp->exp_obd->obd_name, err);
704 sb->s_root = d_make_root(root);
705 if (sb->s_root == NULL) {
707 CERROR("%s: can't make root dentry: rc = %d\n",
708 sbi->ll_fsname, err);
712 sbi->ll_sdev_orig = sb->s_dev;
714 /* We set sb->s_dev equal on all lustre clients in order to support
715 * NFS export clustering. NFSD requires that the FSID be the same
717 /* s_dev is also used in lt_compare() to compare two fs, but that is
718 * only a node-local comparison. */
719 uuid = obd_get_uuid(sbi->ll_md_exp);
721 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
728 if (sbi->ll_dt_obd) {
729 err = sysfs_create_link(&sbi->ll_kset.kobj,
730 &sbi->ll_dt_obd->obd_kset.kobj,
731 sbi->ll_dt_obd->obd_type->typ_name);
733 CERROR("%s: could not register %s in llite: rc = %d\n",
734 dt, sbi->ll_fsname, err);
739 if (sbi->ll_md_obd) {
740 err = sysfs_create_link(&sbi->ll_kset.kobj,
741 &sbi->ll_md_obd->obd_kset.kobj,
742 sbi->ll_md_obd->obd_type->typ_name);
744 CERROR("%s: could not register %s in llite: rc = %d\n",
745 md, sbi->ll_fsname, err);
755 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
757 obd_disconnect(sbi->ll_dt_exp);
758 sbi->ll_dt_exp = NULL;
759 sbi->ll_dt_obd = NULL;
761 obd_fid_fini(sbi->ll_md_exp->exp_obd);
763 obd_disconnect(sbi->ll_md_exp);
764 sbi->ll_md_exp = NULL;
765 sbi->ll_md_obd = NULL;
774 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
778 size = sizeof(*lmmsize);
779 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
780 KEY_MAX_EASIZE, &size, lmmsize);
782 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
783 sbi->ll_dt_exp->exp_obd->obd_name, rc);
787 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
790 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
791 KEY_MAX_EASIZE, &size, lmmsize);
793 CERROR("Get max mdsize error rc %d\n", rc);
795 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
801 * Get the value of the default_easize parameter.
803 * \see client_obd::cl_default_mds_easize
805 * \param[in] sbi superblock info for this filesystem
806 * \param[out] lmmsize pointer to storage location for value
808 * \retval 0 on success
809 * \retval negative negated errno on failure
811 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
816 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
817 KEY_DEFAULT_EASIZE, &size, lmmsize);
819 CERROR("Get default mdsize error rc %d\n", rc);
825 * Set the default_easize parameter to the given value.
827 * \see client_obd::cl_default_mds_easize
829 * \param[in] sbi superblock info for this filesystem
830 * \param[in] lmmsize the size to set
832 * \retval 0 on success
833 * \retval negative negated errno on failure
835 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
839 if (lmmsize < sizeof(struct lov_mds_md) ||
840 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
843 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
844 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
845 sizeof(int), &lmmsize, NULL);
850 static void client_common_put_super(struct super_block *sb)
852 struct ll_sb_info *sbi = ll_s2sbi(sb);
857 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
858 obd_disconnect(sbi->ll_dt_exp);
859 sbi->ll_dt_exp = NULL;
861 ll_debugfs_unregister_super(sb);
863 obd_fid_fini(sbi->ll_md_exp->exp_obd);
864 obd_disconnect(sbi->ll_md_exp);
865 sbi->ll_md_exp = NULL;
870 void ll_kill_super(struct super_block *sb)
872 struct ll_sb_info *sbi;
876 if (!(sb->s_flags & SB_ACTIVE))
880 /* we need restore s_dev from changed for clustred NFS before put_super
881 * because new kernels have cached s_dev and change sb->s_dev in
882 * put_super not affected real removing devices */
884 sb->s_dev = sbi->ll_sdev_orig;
886 /* wait running statahead threads to quit */
887 while (atomic_read(&sbi->ll_sa_running) > 0)
888 schedule_timeout_uninterruptible(
889 cfs_time_seconds(1) >> 3);
895 static inline int ll_set_opt(const char *opt, char *data, int fl)
897 if (strncmp(opt, data, strlen(opt)) != 0)
903 /* non-client-specific mount options are parsed in lmd_parse */
904 static int ll_options(char *options, struct ll_sb_info *sbi)
907 char *s1 = options, *s2;
908 int *flags = &sbi->ll_flags;
914 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
917 CDEBUG(D_SUPER, "next opt=%s\n", s1);
918 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
923 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
925 *flags = (*flags & ~LL_SBI_LOCALFLOCK) | tmp;
928 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
930 *flags = (*flags & ~LL_SBI_FLOCK) | tmp;
933 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
938 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
943 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
948 tmp = ll_set_opt("context", s1, 1);
951 tmp = ll_set_opt("fscontext", s1, 1);
954 tmp = ll_set_opt("defcontext", s1, 1);
957 tmp = ll_set_opt("rootcontext", s1, 1);
960 tmp = ll_set_opt("user_fid2path", s1, LL_SBI_USER_FID2PATH);
965 tmp = ll_set_opt("nouser_fid2path", s1, LL_SBI_USER_FID2PATH);
971 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
974 sbi->ll_checksum_set = 1;
977 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
980 sbi->ll_checksum_set = 1;
983 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
988 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
993 tmp = ll_set_opt("lazystatfs", s1, LL_SBI_LAZYSTATFS);
998 tmp = ll_set_opt("nolazystatfs", s1, LL_SBI_LAZYSTATFS);
1003 tmp = ll_set_opt("32bitapi", s1, LL_SBI_32BIT_API);
1008 tmp = ll_set_opt("verbose", s1, LL_SBI_VERBOSE);
1013 tmp = ll_set_opt("noverbose", s1, LL_SBI_VERBOSE);
1018 tmp = ll_set_opt("always_ping", s1, LL_SBI_ALWAYS_PING);
1023 tmp = ll_set_opt("test_dummy_encryption", s1,
1024 LL_SBI_TEST_DUMMY_ENCRYPTION);
1026 #ifdef HAVE_LUSTRE_CRYPTO
1029 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1033 tmp = ll_set_opt("noencrypt", s1, LL_SBI_ENCRYPT);
1035 #ifdef HAVE_LUSTRE_CRYPTO
1038 LCONSOLE_WARN("noencrypt mount option ignored: encryption not supported\n");
1042 tmp = ll_set_opt("foreign_symlink", s1, LL_SBI_FOREIGN_SYMLINK);
1044 int prefix_pos = sizeof("foreign_symlink=") - 1;
1045 int equal_pos = sizeof("foreign_symlink=") - 2;
1047 /* non-default prefix provided ? */
1048 if (strlen(s1) >= sizeof("foreign_symlink=") &&
1049 *(s1 + equal_pos) == '=') {
1050 char *old = sbi->ll_foreign_symlink_prefix;
1052 sbi->ll_foreign_symlink_prefix_size;
1054 /* path must be absolute */
1055 if (*(s1 + sizeof("foreign_symlink=")
1057 LCONSOLE_ERROR_MSG(0x152,
1058 "foreign prefix '%s' must be an absolute path\n",
1063 s2 = strchrnul(s1 + prefix_pos, ',');
1065 if (sbi->ll_foreign_symlink_prefix) {
1066 sbi->ll_foreign_symlink_prefix = NULL;
1067 sbi->ll_foreign_symlink_prefix_size = 0;
1069 /* alloc for path length and '\0' */
1070 OBD_ALLOC(sbi->ll_foreign_symlink_prefix,
1071 s2 - (s1 + prefix_pos) + 1);
1072 if (!sbi->ll_foreign_symlink_prefix) {
1073 /* restore previous */
1074 sbi->ll_foreign_symlink_prefix = old;
1075 sbi->ll_foreign_symlink_prefix_size =
1080 OBD_FREE(old, old_len);
1081 strncpy(sbi->ll_foreign_symlink_prefix,
1083 s2 - (s1 + prefix_pos));
1084 sbi->ll_foreign_symlink_prefix_size =
1085 s2 - (s1 + prefix_pos) + 1;
1087 LCONSOLE_ERROR_MSG(0x152,
1088 "invalid %s option\n", s1);
1090 /* enable foreign symlink support */
1094 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
1100 s2 = strchr(s1, ',');
1108 void ll_lli_init(struct ll_inode_info *lli)
1110 lli->lli_inode_magic = LLI_INODE_MAGIC;
1112 spin_lock_init(&lli->lli_lock);
1113 lli->lli_posix_acl = NULL;
1114 /* Do not set lli_fid, it has been initialized already. */
1115 fid_zero(&lli->lli_pfid);
1116 lli->lli_mds_read_och = NULL;
1117 lli->lli_mds_write_och = NULL;
1118 lli->lli_mds_exec_och = NULL;
1119 lli->lli_open_fd_read_count = 0;
1120 lli->lli_open_fd_write_count = 0;
1121 lli->lli_open_fd_exec_count = 0;
1122 mutex_init(&lli->lli_och_mutex);
1123 spin_lock_init(&lli->lli_agl_lock);
1124 spin_lock_init(&lli->lli_layout_lock);
1125 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1126 lli->lli_clob = NULL;
1128 init_rwsem(&lli->lli_xattrs_list_rwsem);
1129 mutex_init(&lli->lli_xattrs_enq_lock);
1131 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1132 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1133 lli->lli_opendir_key = NULL;
1134 lli->lli_sai = NULL;
1135 spin_lock_init(&lli->lli_sa_lock);
1136 lli->lli_opendir_pid = 0;
1137 lli->lli_sa_enabled = 0;
1138 init_rwsem(&lli->lli_lsm_sem);
1140 mutex_init(&lli->lli_size_mutex);
1141 mutex_init(&lli->lli_setattr_mutex);
1142 lli->lli_symlink_name = NULL;
1143 ll_trunc_sem_init(&lli->lli_trunc_sem);
1144 range_lock_tree_init(&lli->lli_write_tree);
1145 init_rwsem(&lli->lli_glimpse_sem);
1146 lli->lli_glimpse_time = ktime_set(0, 0);
1147 INIT_LIST_HEAD(&lli->lli_agl_list);
1148 lli->lli_agl_index = 0;
1149 lli->lli_async_rc = 0;
1150 spin_lock_init(&lli->lli_heat_lock);
1151 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1152 lli->lli_heat_flags = 0;
1153 mutex_init(&lli->lli_pcc_lock);
1154 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1155 lli->lli_pcc_inode = NULL;
1156 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1157 lli->lli_pcc_generation = 0;
1158 mutex_init(&lli->lli_group_mutex);
1159 lli->lli_group_users = 0;
1160 lli->lli_group_gid = 0;
1162 mutex_init(&lli->lli_layout_mutex);
1163 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1166 #define MAX_STRING_SIZE 128
1168 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1170 #define LSI_BDI_INITIALIZED 0x00400000
1172 #ifndef HAVE_BDI_CAP_MAP_COPY
1173 # define BDI_CAP_MAP_COPY 0
1176 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1178 struct lustre_sb_info *lsi = s2lsi(sb);
1179 char buf[MAX_STRING_SIZE];
1183 err = bdi_init(&lsi->lsi_bdi);
1187 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1188 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1189 lsi->lsi_bdi.name = "lustre";
1190 va_start(args, fmt);
1191 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1193 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1196 sb->s_bdi = &lsi->lsi_bdi;
1200 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1202 int ll_fill_super(struct super_block *sb)
1204 struct lustre_profile *lprof = NULL;
1205 struct lustre_sb_info *lsi = s2lsi(sb);
1206 struct ll_sb_info *sbi = NULL;
1207 char *dt = NULL, *md = NULL;
1208 char *profilenm = get_profile_name(sb);
1209 struct config_llog_instance *cfg;
1210 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1211 const int instlen = LUSTRE_MAXINSTANCE + 2;
1212 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1213 char name[MAX_STRING_SIZE];
1222 /* for ASLR, to map between cfg_instance and hashed ptr */
1223 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1224 profilenm, cfg_instance, sb);
1228 GOTO(out_free_cfg, err = -ENOMEM);
1230 /* client additional sb info */
1231 lsi->lsi_llsbi = sbi = ll_init_sbi();
1233 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1235 err = ll_options(lsi->lsi_lmd->lmd_opts, sbi);
1237 GOTO(out_free_cfg, err);
1239 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1240 sb->s_d_op = &ll_d_ops;
1243 generate_random_uuid(uuid.b);
1244 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1246 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1249 len = strlen(profilenm);
1250 ptr = strrchr(profilenm, '-');
1251 if (ptr && (strcmp(ptr, "-client") == 0))
1254 if (len > LUSTRE_MAXFSNAME) {
1255 if (unlikely(len >= MAX_STRING_SIZE))
1256 len = MAX_STRING_SIZE - 1;
1257 strncpy(name, profilenm, len);
1259 err = -ENAMETOOLONG;
1260 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1261 name, LUSTRE_MAXFSNAME, err);
1262 GOTO(out_free_cfg, err);
1264 strncpy(sbi->ll_fsname, profilenm, len);
1265 sbi->ll_fsname[len] = '\0';
1268 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1269 profilenm, cfg_instance);
1271 err = super_setup_bdi_name(sb, "%s", name);
1273 GOTO(out_free_cfg, err);
1275 /* Call ll_debugfs_register_super() before lustre_process_log()
1276 * so that "llite.*.*" params can be processed correctly.
1278 err = ll_debugfs_register_super(sb, name);
1280 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1281 sbi->ll_fsname, err);
1285 /* The cfg_instance is a value unique to this super, in case some
1286 * joker tries to mount the same fs at two mount points.
1288 cfg->cfg_instance = cfg_instance;
1289 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1290 cfg->cfg_callback = class_config_llog_handler;
1291 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1292 /* set up client obds */
1293 err = lustre_process_log(sb, profilenm, cfg);
1295 GOTO(out_debugfs, err);
1297 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1298 lprof = class_get_profile(profilenm);
1299 if (lprof == NULL) {
1300 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1301 " read from the MGS. Does that filesystem "
1302 "exist?\n", profilenm);
1303 GOTO(out_debugfs, err = -EINVAL);
1305 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1306 lprof->lp_md, lprof->lp_dt);
1308 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1309 OBD_ALLOC(dt, dt_len);
1311 GOTO(out_profile, err = -ENOMEM);
1312 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1314 md_len = strlen(lprof->lp_md) + instlen + 2;
1315 OBD_ALLOC(md, md_len);
1317 GOTO(out_free_dt, err = -ENOMEM);
1318 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1320 /* connections, registrations, sb setup */
1321 err = client_common_fill_super(sb, md, dt);
1323 GOTO(out_free_md, err);
1325 sbi->ll_client_common_fill_super_succeeded = 1;
1329 OBD_FREE(md, md_len);
1332 OBD_FREE(dt, dt_len);
1335 class_put_profile(lprof);
1338 ll_debugfs_unregister_super(sb);
1345 else if (sbi->ll_flags & LL_SBI_VERBOSE)
1346 LCONSOLE_WARN("Mounted %s\n", profilenm);
1348 } /* ll_fill_super */
1350 void ll_put_super(struct super_block *sb)
1352 struct config_llog_instance cfg, params_cfg;
1353 struct obd_device *obd;
1354 struct lustre_sb_info *lsi = s2lsi(sb);
1355 struct ll_sb_info *sbi = ll_s2sbi(sb);
1356 char *profilenm = get_profile_name(sb);
1357 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1359 int next, force = 1, rc = 0;
1363 GOTO(out_no_sbi, 0);
1365 /* Should replace instance_id with something better for ASLR */
1366 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1367 profilenm, cfg_instance, sb);
1369 cfg.cfg_instance = cfg_instance;
1370 lustre_end_log(sb, profilenm, &cfg);
1372 params_cfg.cfg_instance = cfg_instance;
1373 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1375 if (sbi->ll_md_exp) {
1376 obd = class_exp2obd(sbi->ll_md_exp);
1378 force = obd->obd_force;
1381 /* Wait for unstable pages to be committed to stable storage */
1383 rc = l_wait_event_abortable(
1384 sbi->ll_cache->ccc_unstable_waitq,
1385 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1388 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1389 if (force == 0 && rc != -ERESTARTSYS)
1390 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1392 /* We need to set force before the lov_disconnect in
1393 * lustre_common_put_super, since l_d cleans up osc's as well.
1397 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1399 obd->obd_force = force;
1403 if (sbi->ll_client_common_fill_super_succeeded) {
1404 /* Only if client_common_fill_super succeeded */
1405 client_common_put_super(sb);
1409 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1410 class_manual_cleanup(obd);
1412 if (sbi->ll_flags & LL_SBI_VERBOSE)
1413 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1416 class_del_profile(profilenm);
1418 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1419 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1420 bdi_destroy(&lsi->lsi_bdi);
1421 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1426 lsi->lsi_llsbi = NULL;
1428 lustre_common_put_super(sb);
1430 cl_env_cache_purge(~0);
1432 module_put(THIS_MODULE);
1435 } /* client_put_super */
1437 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1439 struct inode *inode = NULL;
1441 /* NOTE: we depend on atomic igrab() -bzzz */
1442 lock_res_and_lock(lock);
1443 if (lock->l_resource->lr_lvb_inode) {
1444 struct ll_inode_info * lli;
1445 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1446 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1447 inode = igrab(lock->l_resource->lr_lvb_inode);
1449 inode = lock->l_resource->lr_lvb_inode;
1450 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1451 D_WARNING, lock, "lr_lvb_inode %p is "
1452 "bogus: magic %08x",
1453 lock->l_resource->lr_lvb_inode,
1454 lli->lli_inode_magic);
1458 unlock_res_and_lock(lock);
1462 void ll_dir_clear_lsm_md(struct inode *inode)
1464 struct ll_inode_info *lli = ll_i2info(inode);
1466 LASSERT(S_ISDIR(inode->i_mode));
1468 if (lli->lli_lsm_md) {
1469 lmv_free_memmd(lli->lli_lsm_md);
1470 lli->lli_lsm_md = NULL;
1473 if (lli->lli_default_lsm_md) {
1474 lmv_free_memmd(lli->lli_default_lsm_md);
1475 lli->lli_default_lsm_md = NULL;
1479 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1480 const struct lu_fid *fid,
1481 struct lustre_md *md)
1483 struct ll_sb_info *sbi = ll_s2sbi(sb);
1484 struct mdt_body *body = md->body;
1485 struct inode *inode;
1489 ino = cl_fid_build_ino(fid, sbi->ll_flags & LL_SBI_32BIT_API);
1490 inode = iget_locked(sb, ino);
1491 if (inode == NULL) {
1492 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1493 sbi->ll_fsname, PFID(fid));
1494 RETURN(ERR_PTR(-ENOENT));
1497 if (inode->i_state & I_NEW) {
1498 struct ll_inode_info *lli = ll_i2info(inode);
1499 struct lmv_stripe_md *lsm = md->lmv;
1501 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1502 (body->mbo_mode & S_IFMT);
1503 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1506 inode->i_mtime.tv_sec = 0;
1507 inode->i_atime.tv_sec = 0;
1508 inode->i_ctime.tv_sec = 0;
1511 #ifdef HAVE_BACKING_DEV_INFO
1512 /* initializing backing dev info. */
1513 inode->i_mapping->backing_dev_info =
1514 &s2lsi(inode->i_sb)->lsi_bdi;
1516 inode->i_op = &ll_dir_inode_operations;
1517 inode->i_fop = &ll_dir_operations;
1518 lli->lli_fid = *fid;
1521 LASSERT(lsm != NULL);
1522 /* master object FID */
1523 lli->lli_pfid = body->mbo_fid1;
1524 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1525 lli, PFID(fid), PFID(&lli->lli_pfid));
1526 unlock_new_inode(inode);
1532 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1535 struct lmv_stripe_md *lsm = md->lmv;
1536 struct ll_inode_info *lli = ll_i2info(inode);
1539 LASSERT(lsm != NULL);
1541 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1542 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1543 lsm_md_dump(D_INODE, lsm);
1545 if (!lmv_dir_striped(lsm))
1548 /* XXX sigh, this lsm_root initialization should be in
1549 * LMV layer, but it needs ll_iget right now, so we
1550 * put this here right now. */
1551 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1552 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1553 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1555 if (!fid_is_sane(fid))
1558 /* Unfortunately ll_iget will call ll_update_inode,
1559 * where the initialization of slave inode is slightly
1560 * different, so it reset lsm_md to NULL to avoid
1561 * initializing lsm for slave inode. */
1562 lsm->lsm_md_oinfo[i].lmo_root =
1563 ll_iget_anon_dir(inode->i_sb, fid, md);
1564 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1565 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1567 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1569 iput(lsm->lsm_md_oinfo[i].lmo_root);
1570 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1576 lli->lli_lsm_md = lsm;
1581 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1583 struct ll_inode_info *lli = ll_i2info(inode);
1585 if (!md->default_lmv) {
1586 /* clear default lsm */
1587 if (lli->lli_default_lsm_md) {
1588 down_write(&lli->lli_lsm_sem);
1589 if (lli->lli_default_lsm_md) {
1590 lmv_free_memmd(lli->lli_default_lsm_md);
1591 lli->lli_default_lsm_md = NULL;
1593 up_write(&lli->lli_lsm_sem);
1595 } else if (lli->lli_default_lsm_md) {
1596 /* update default lsm if it changes */
1597 down_read(&lli->lli_lsm_sem);
1598 if (lli->lli_default_lsm_md &&
1599 !lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1600 up_read(&lli->lli_lsm_sem);
1601 down_write(&lli->lli_lsm_sem);
1602 if (lli->lli_default_lsm_md)
1603 lmv_free_memmd(lli->lli_default_lsm_md);
1604 lli->lli_default_lsm_md = md->default_lmv;
1605 lsm_md_dump(D_INODE, md->default_lmv);
1606 md->default_lmv = NULL;
1607 up_write(&lli->lli_lsm_sem);
1609 up_read(&lli->lli_lsm_sem);
1612 /* init default lsm */
1613 down_write(&lli->lli_lsm_sem);
1614 lli->lli_default_lsm_md = md->default_lmv;
1615 lsm_md_dump(D_INODE, md->default_lmv);
1616 md->default_lmv = NULL;
1617 up_write(&lli->lli_lsm_sem);
1621 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1623 struct ll_inode_info *lli = ll_i2info(inode);
1624 struct lmv_stripe_md *lsm = md->lmv;
1625 struct cl_attr *attr;
1630 LASSERT(S_ISDIR(inode->i_mode));
1631 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1632 PFID(ll_inode2fid(inode)));
1634 /* update default LMV */
1635 if (md->default_lmv)
1636 ll_update_default_lsm_md(inode, md);
1639 * no striped information from request, lustre_md from req does not
1640 * include stripeEA, see ll_md_setattr()
1646 * normally dir layout doesn't change, only take read lock to check
1647 * that to avoid blocking other MD operations.
1649 down_read(&lli->lli_lsm_sem);
1651 /* some current lookup initialized lsm, and unchanged */
1652 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1653 GOTO(unlock, rc = 0);
1655 /* if dir layout doesn't match, check whether version is increased,
1656 * which means layout is changed, this happens in dir split/merge and
1659 * foreign LMV should not change.
1661 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1662 lsm->lsm_md_layout_version <=
1663 lli->lli_lsm_md->lsm_md_layout_version) {
1664 CERROR("%s: "DFID" dir layout mismatch:\n",
1665 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1666 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1667 lsm_md_dump(D_ERROR, lsm);
1668 GOTO(unlock, rc = -EINVAL);
1671 up_read(&lli->lli_lsm_sem);
1672 down_write(&lli->lli_lsm_sem);
1673 /* clear existing lsm */
1674 if (lli->lli_lsm_md) {
1675 lmv_free_memmd(lli->lli_lsm_md);
1676 lli->lli_lsm_md = NULL;
1679 rc = ll_init_lsm_md(inode, md);
1680 up_write(&lli->lli_lsm_sem);
1685 /* set md->lmv to NULL, so the following free lustre_md will not free
1690 /* md_merge_attr() may take long, since lsm is already set, switch to
1693 down_read(&lli->lli_lsm_sem);
1695 if (!lmv_dir_striped(lli->lli_lsm_md))
1696 GOTO(unlock, rc = 0);
1698 OBD_ALLOC_PTR(attr);
1700 GOTO(unlock, rc = -ENOMEM);
1702 /* validate the lsm */
1703 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1704 ll_md_blocking_ast);
1706 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1707 md->body->mbo_nlink = attr->cat_nlink;
1708 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1709 md->body->mbo_size = attr->cat_size;
1710 if (md->body->mbo_valid & OBD_MD_FLATIME)
1711 md->body->mbo_atime = attr->cat_atime;
1712 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1713 md->body->mbo_ctime = attr->cat_ctime;
1714 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1715 md->body->mbo_mtime = attr->cat_mtime;
1721 up_read(&lli->lli_lsm_sem);
1726 void ll_clear_inode(struct inode *inode)
1728 struct ll_inode_info *lli = ll_i2info(inode);
1729 struct ll_sb_info *sbi = ll_i2sbi(inode);
1733 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1734 PFID(ll_inode2fid(inode)), inode);
1736 if (S_ISDIR(inode->i_mode)) {
1737 /* these should have been cleared in ll_file_release */
1738 LASSERT(lli->lli_opendir_key == NULL);
1739 LASSERT(lli->lli_sai == NULL);
1740 LASSERT(lli->lli_opendir_pid == 0);
1742 pcc_inode_free(inode);
1745 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1747 LASSERT(!lli->lli_open_fd_write_count);
1748 LASSERT(!lli->lli_open_fd_read_count);
1749 LASSERT(!lli->lli_open_fd_exec_count);
1751 if (lli->lli_mds_write_och)
1752 ll_md_real_close(inode, FMODE_WRITE);
1753 if (lli->lli_mds_exec_och)
1754 ll_md_real_close(inode, FMODE_EXEC);
1755 if (lli->lli_mds_read_och)
1756 ll_md_real_close(inode, FMODE_READ);
1758 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1759 OBD_FREE(lli->lli_symlink_name,
1760 strlen(lli->lli_symlink_name) + 1);
1761 lli->lli_symlink_name = NULL;
1764 ll_xattr_cache_destroy(inode);
1766 forget_all_cached_acls(inode);
1768 lli->lli_inode_magic = LLI_INODE_DEAD;
1770 if (S_ISDIR(inode->i_mode))
1771 ll_dir_clear_lsm_md(inode);
1772 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1773 LASSERT(list_empty(&lli->lli_agl_list));
1776 * XXX This has to be done before lsm is freed below, because
1777 * cl_object still uses inode lsm.
1779 cl_inode_fini(inode);
1781 llcrypt_put_encryption_info(inode);
1786 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1788 struct lustre_md md;
1789 struct inode *inode = dentry->d_inode;
1790 struct ll_sb_info *sbi = ll_i2sbi(inode);
1791 struct ptlrpc_request *request = NULL;
1795 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1796 LUSTRE_OPC_ANY, NULL);
1797 if (IS_ERR(op_data))
1798 RETURN(PTR_ERR(op_data));
1800 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1802 ptlrpc_req_finished(request);
1803 if (rc == -ENOENT) {
1805 /* Unlinked special device node? Or just a race?
1806 * Pretend we done everything. */
1807 if (!S_ISREG(inode->i_mode) &&
1808 !S_ISDIR(inode->i_mode)) {
1809 ia_valid = op_data->op_attr.ia_valid;
1810 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1811 rc = simple_setattr(dentry, &op_data->op_attr);
1812 op_data->op_attr.ia_valid = ia_valid;
1814 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1815 CERROR("md_setattr fails: rc = %d\n", rc);
1820 rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
1821 sbi->ll_md_exp, &md);
1823 ptlrpc_req_finished(request);
1827 ia_valid = op_data->op_attr.ia_valid;
1828 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1829 * cache is not cleared yet. */
1830 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1831 if (S_ISREG(inode->i_mode))
1833 rc = simple_setattr(dentry, &op_data->op_attr);
1834 if (S_ISREG(inode->i_mode))
1835 inode_unlock(inode);
1836 op_data->op_attr.ia_valid = ia_valid;
1838 rc = ll_update_inode(inode, &md);
1839 ptlrpc_req_finished(request);
1845 * Zero portion of page that is part of @inode.
1846 * This implies, if necessary:
1847 * - taking cl_lock on range corresponding to concerned page
1848 * - grabbing vm page
1849 * - associating cl_page
1850 * - proceeding to clio read
1851 * - zeroing range in page
1852 * - proceeding to cl_page flush
1853 * - releasing cl_lock
1855 * \param[in] inode inode
1856 * \param[in] index page index
1857 * \param[in] offset offset in page to start zero from
1858 * \param[in] len len to zero
1860 * \retval 0 on success
1861 * \retval negative errno on failure
1863 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
1866 struct ll_inode_info *lli = ll_i2info(inode);
1867 struct cl_object *clob = lli->lli_clob;
1869 struct lu_env *env = NULL;
1870 struct cl_io *io = NULL;
1871 struct cl_page *clpage = NULL;
1872 struct page *vmpage = NULL;
1873 unsigned from = index << PAGE_SHIFT;
1874 struct cl_lock *lock = NULL;
1875 struct cl_lock_descr *descr = NULL;
1876 struct cl_2queue *queue = NULL;
1877 struct cl_sync_io *anchor = NULL;
1878 bool holdinglock = false;
1879 bool lockedbymyself = true;
1884 env = cl_env_get(&refcheck);
1886 RETURN(PTR_ERR(env));
1888 io = vvp_env_thread_io(env);
1890 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
1894 lock = vvp_env_lock(env);
1895 descr = &lock->cll_descr;
1896 descr->cld_obj = io->ci_obj;
1897 descr->cld_start = cl_index(io->ci_obj, from);
1898 descr->cld_end = cl_index(io->ci_obj, from + PAGE_SIZE - 1);
1899 descr->cld_mode = CLM_WRITE;
1900 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
1902 /* request lock for page */
1903 rc = cl_lock_request(env, io, lock);
1904 /* -ECANCELED indicates a matching lock with a different extent
1905 * was already present, and -EEXIST indicates a matching lock
1906 * on exactly the same extent was already present.
1907 * In both cases it means we are covered.
1909 if (rc == -ECANCELED || rc == -EEXIST)
1917 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
1919 GOTO(rellock, rc = -EOPNOTSUPP);
1921 if (!PageDirty(vmpage)) {
1922 /* associate cl_page */
1923 clpage = cl_page_find(env, clob, vmpage->index,
1924 vmpage, CPT_CACHEABLE);
1926 GOTO(pagefini, rc = PTR_ERR(clpage));
1928 cl_page_assume(env, io, clpage);
1931 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
1932 !PageWriteback(vmpage)) {
1934 /* set PagePrivate2 to detect special case of empty page
1935 * in osc_brw_fini_request()
1937 SetPagePrivate2(vmpage);
1938 rc = ll_io_read_page(env, io, clpage, NULL);
1939 if (!PagePrivate2(vmpage))
1940 /* PagePrivate2 was cleared in osc_brw_fini_request()
1941 * meaning we read an empty page. In this case, in order
1942 * to avoid allocating unnecessary block in truncated
1943 * file, we must not zero and write as below. Subsequent
1944 * server-side truncate will handle things correctly.
1946 GOTO(clpfini, rc = 0);
1947 ClearPagePrivate2(vmpage);
1950 lockedbymyself = trylock_page(vmpage);
1951 cl_page_assume(env, io, clpage);
1954 /* zero range in page */
1955 zero_user(vmpage, offset, len);
1957 if (holdinglock && clpage) {
1958 /* explicitly write newly modified page */
1959 queue = &io->ci_queue;
1960 cl_2queue_init(queue);
1961 anchor = &vvp_env_info(env)->vti_anchor;
1962 cl_sync_io_init(anchor, 1);
1963 clpage->cp_sync_io = anchor;
1964 cl_2queue_add(queue, clpage);
1965 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
1967 GOTO(queuefini1, rc);
1968 rc = cl_sync_io_wait(env, anchor, 0);
1970 GOTO(queuefini2, rc);
1971 cl_page_assume(env, io, clpage);
1974 cl_2queue_discard(env, io, queue);
1976 cl_2queue_disown(env, io, queue);
1977 cl_2queue_fini(env, queue);
1982 cl_page_put(env, clpage);
1984 if (lockedbymyself) {
1985 unlock_page(vmpage);
1990 cl_lock_release(env, lock);
1992 cl_io_fini(env, io);
1995 cl_env_put(env, &refcheck);
2000 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2001 * object(s) determine the file size and mtime. Otherwise, the MDS will
2002 * keep these values until such a time that objects are allocated for it.
2003 * We do the MDS operations first, as it is checking permissions for us.
2004 * We don't to the MDS RPC if there is nothing that we want to store there,
2005 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2006 * going to do an RPC anyways.
2008 * If we are doing a truncate, we will send the mtime and ctime updates
2009 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2010 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2013 * In case of HSMimport, we only set attr on MDS.
2015 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2016 enum op_xvalid xvalid, bool hsm_import)
2018 struct inode *inode = dentry->d_inode;
2019 struct ll_inode_info *lli = ll_i2info(inode);
2020 struct md_op_data *op_data = NULL;
2021 ktime_t kstart = ktime_get();
2026 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2027 "valid %x, hsm_import %d\n",
2028 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2029 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2032 if (attr->ia_valid & ATTR_SIZE) {
2033 /* Check new size against VFS/VM file size limit and rlimit */
2034 rc = inode_newsize_ok(inode, attr->ia_size);
2038 /* The maximum Lustre file size is variable, based on the
2039 * OST maximum object size and number of stripes. This
2040 * needs another check in addition to the VFS check above. */
2041 if (attr->ia_size > ll_file_maxbytes(inode)) {
2042 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2043 PFID(&lli->lli_fid), attr->ia_size,
2044 ll_file_maxbytes(inode));
2048 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2051 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2052 if (attr->ia_valid & TIMES_SET_FLAGS) {
2053 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2054 !cfs_capable(CAP_FOWNER))
2058 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2059 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2060 (attr->ia_valid & ATTR_CTIME)) {
2061 attr->ia_ctime = current_time(inode);
2062 xvalid |= OP_XVALID_CTIME_SET;
2064 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2065 (attr->ia_valid & ATTR_ATIME)) {
2066 attr->ia_atime = current_time(inode);
2067 attr->ia_valid |= ATTR_ATIME_SET;
2069 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2070 (attr->ia_valid & ATTR_MTIME)) {
2071 attr->ia_mtime = current_time(inode);
2072 attr->ia_valid |= ATTR_MTIME_SET;
2075 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2076 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2077 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2078 ktime_get_real_seconds());
2080 if (S_ISREG(inode->i_mode))
2081 inode_unlock(inode);
2083 /* We always do an MDS RPC, even if we're only changing the size;
2084 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2086 OBD_ALLOC_PTR(op_data);
2087 if (op_data == NULL)
2088 GOTO(out, rc = -ENOMEM);
2090 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2091 /* If we are changing file size, file content is
2092 * modified, flag it.
2094 xvalid |= OP_XVALID_OWNEROVERRIDE;
2095 op_data->op_bias |= MDS_DATA_MODIFIED;
2096 ll_file_clear_flag(lli, LLIF_DATA_MODIFIED);
2099 if (attr->ia_valid & ATTR_FILE) {
2100 struct ll_file_data *fd = attr->ia_file->private_data;
2102 if (fd->fd_lease_och)
2103 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2106 op_data->op_attr = *attr;
2107 op_data->op_xvalid = xvalid;
2109 rc = ll_md_setattr(dentry, op_data);
2113 if (!S_ISREG(inode->i_mode) || hsm_import)
2116 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2117 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2118 xvalid & OP_XVALID_CTIME_SET) {
2119 bool cached = false;
2121 rc = pcc_inode_setattr(inode, attr, &cached);
2124 CERROR("%s: PCC inode "DFID" setattr failed: "
2126 ll_i2sbi(inode)->ll_fsname,
2127 PFID(&lli->lli_fid), rc);
2131 unsigned int flags = 0;
2133 /* For truncate and utimes sending attributes to OSTs,
2134 * setting mtime/atime to the past will be performed
2135 * under PW [0:EOF] extent lock (new_size:EOF for
2136 * truncate). It may seem excessive to send mtime/atime
2137 * updates to OSTs when not setting times to past, but
2138 * it is necessary due to possible time
2139 * de-synchronization between MDT inode and OST objects
2141 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode) &&
2142 attr->ia_valid & ATTR_SIZE) {
2143 xvalid |= OP_XVALID_FLAGS;
2144 flags = LUSTRE_ENCRYPT_FL;
2145 /* Call to ll_io_zero_page is not necessary if
2146 * truncating on PAGE_SIZE boundary, because
2147 * whole pages will be wiped.
2148 * In case of Direct IO, all we need is to set
2151 if (attr->ia_size & ~PAGE_MASK &&
2152 !(attr->ia_valid & ATTR_FILE &&
2153 attr->ia_file->f_flags & O_DIRECT)) {
2155 attr->ia_size & (PAGE_SIZE - 1);
2157 rc = ll_io_zero_page(inode,
2158 attr->ia_size >> PAGE_SHIFT,
2159 offset, PAGE_SIZE - offset);
2164 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2168 /* If the file was restored, it needs to set dirty flag.
2170 * We've already sent MDS_DATA_MODIFIED flag in
2171 * ll_md_setattr() for truncate. However, the MDT refuses to
2172 * set the HS_DIRTY flag on released files, so we have to set
2173 * it again if the file has been restored. Please check how
2174 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2176 * Please notice that if the file is not released, the previous
2177 * MDS_DATA_MODIFIED has taken effect and usually
2178 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2179 * This way we can save an RPC for common open + trunc
2181 if (ll_file_test_and_clear_flag(lli, LLIF_DATA_MODIFIED)) {
2182 struct hsm_state_set hss = {
2183 .hss_valid = HSS_SETMASK,
2184 .hss_setmask = HS_DIRTY,
2188 rc2 = ll_hsm_state_set(inode, &hss);
2189 /* truncate and write can happen at the same time, so that
2190 * the file can be set modified even though the file is not
2191 * restored from released state, and ll_hsm_state_set() is
2192 * not applicable for the file, and rc2 < 0 is normal in this
2195 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2196 PFID(ll_inode2fid(inode)), rc2);
2201 if (op_data != NULL)
2202 ll_finish_md_op_data(op_data);
2204 if (S_ISREG(inode->i_mode)) {
2206 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2207 inode_dio_wait(inode);
2208 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2209 * flag. ll_update_inode (called from ll_md_setattr), clears
2210 * inode flags, so there is a gap where S_NOSEC is not set.
2211 * This can cause a writer to take the i_mutex unnecessarily,
2212 * but this is safe to do and should be rare. */
2213 inode_has_no_xattr(inode);
2217 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2218 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2219 ktime_us_delta(ktime_get(), kstart));
2224 int ll_setattr(struct dentry *de, struct iattr *attr)
2226 int mode = de->d_inode->i_mode;
2227 enum op_xvalid xvalid = 0;
2230 rc = llcrypt_prepare_setattr(de, attr);
2234 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2235 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2236 xvalid |= OP_XVALID_OWNEROVERRIDE;
2238 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2239 (ATTR_SIZE|ATTR_MODE)) &&
2240 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2241 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2242 !(attr->ia_mode & S_ISGID))))
2243 attr->ia_valid |= ATTR_FORCE;
2245 if ((attr->ia_valid & ATTR_MODE) &&
2247 !(attr->ia_mode & S_ISUID) &&
2248 !(attr->ia_valid & ATTR_KILL_SUID))
2249 attr->ia_valid |= ATTR_KILL_SUID;
2251 if ((attr->ia_valid & ATTR_MODE) &&
2252 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2253 !(attr->ia_mode & S_ISGID) &&
2254 !(attr->ia_valid & ATTR_KILL_SGID))
2255 attr->ia_valid |= ATTR_KILL_SGID;
2257 return ll_setattr_raw(de, attr, xvalid, false);
2260 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2263 struct obd_statfs obd_osfs = { 0 };
2268 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2270 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
2271 flags |= OBD_STATFS_NODELAY;
2273 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2277 osfs->os_type = LL_SUPER_MAGIC;
2279 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2280 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2282 if (osfs->os_state & OS_STATFS_SUM)
2285 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2286 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2289 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2290 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2293 osfs->os_bsize = obd_osfs.os_bsize;
2294 osfs->os_blocks = obd_osfs.os_blocks;
2295 osfs->os_bfree = obd_osfs.os_bfree;
2296 osfs->os_bavail = obd_osfs.os_bavail;
2298 /* If we have _some_ OSTs, but don't have as many free objects on the
2299 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2300 * to compensate, so that the "inodes in use" number is correct.
2301 * This should be kept in sync with lod_statfs() behaviour.
2303 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2304 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2306 osfs->os_ffree = obd_osfs.os_ffree;
2313 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2315 struct if_quotactl qctl = {
2316 .qc_cmd = LUSTRE_Q_GETQUOTA,
2317 .qc_type = PRJQUOTA,
2318 .qc_valid = QC_GENERAL,
2320 u64 limit, curblock;
2323 qctl.qc_id = ll_i2info(inode)->lli_projid;
2324 ret = quotactl_ioctl(ll_i2sbi(inode), &qctl);
2326 /* ignore errors if project ID does not have
2327 * a quota limit or feature unsupported.
2329 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2334 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2335 qctl.qc_dqblk.dqb_bsoftlimit :
2336 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2337 if (limit && sfs->f_blocks > limit) {
2338 curblock = (qctl.qc_dqblk.dqb_curspace +
2339 sfs->f_bsize - 1) / sfs->f_bsize;
2340 sfs->f_blocks = limit;
2341 sfs->f_bfree = sfs->f_bavail =
2342 (sfs->f_blocks > curblock) ?
2343 (sfs->f_blocks - curblock) : 0;
2346 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2347 qctl.qc_dqblk.dqb_isoftlimit :
2348 qctl.qc_dqblk.dqb_ihardlimit;
2349 if (limit && sfs->f_files > limit) {
2350 sfs->f_files = limit;
2351 sfs->f_ffree = (sfs->f_files >
2352 qctl.qc_dqblk.dqb_curinodes) ?
2353 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2359 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2361 struct super_block *sb = de->d_sb;
2362 struct obd_statfs osfs;
2363 __u64 fsid = huge_encode_dev(sb->s_dev);
2364 ktime_t kstart = ktime_get();
2367 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2369 /* Some amount of caching on the client is allowed */
2370 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2374 statfs_unpack(sfs, &osfs);
2376 /* We need to downshift for all 32-bit kernels, because we can't
2377 * tell if the kernel is being called via sys_statfs64() or not.
2378 * Stop before overflowing f_bsize - in which case it is better
2379 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2380 if (sizeof(long) < 8) {
2381 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2384 osfs.os_blocks >>= 1;
2385 osfs.os_bfree >>= 1;
2386 osfs.os_bavail >>= 1;
2390 sfs->f_blocks = osfs.os_blocks;
2391 sfs->f_bfree = osfs.os_bfree;
2392 sfs->f_bavail = osfs.os_bavail;
2393 sfs->f_fsid.val[0] = (__u32)fsid;
2394 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2395 if (ll_i2info(de->d_inode)->lli_projid)
2396 return ll_statfs_project(de->d_inode, sfs);
2398 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2399 ktime_us_delta(ktime_get(), kstart));
2404 void ll_inode_size_lock(struct inode *inode)
2406 struct ll_inode_info *lli;
2408 LASSERT(!S_ISDIR(inode->i_mode));
2410 lli = ll_i2info(inode);
2411 mutex_lock(&lli->lli_size_mutex);
2414 void ll_inode_size_unlock(struct inode *inode)
2416 struct ll_inode_info *lli;
2418 lli = ll_i2info(inode);
2419 mutex_unlock(&lli->lli_size_mutex);
2422 void ll_update_inode_flags(struct inode *inode, int ext_flags)
2424 /* do not clear encryption flag */
2425 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2426 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2427 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2428 ll_file_set_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
2430 ll_file_clear_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
2433 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2435 struct ll_inode_info *lli = ll_i2info(inode);
2436 struct mdt_body *body = md->body;
2437 struct ll_sb_info *sbi = ll_i2sbi(inode);
2440 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2441 rc = cl_file_inode_init(inode, md);
2446 if (S_ISDIR(inode->i_mode)) {
2447 rc = ll_update_lsm_md(inode, md);
2452 if (body->mbo_valid & OBD_MD_FLACL)
2453 lli_replace_acl(lli, md);
2455 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1,
2456 sbi->ll_flags & LL_SBI_32BIT_API);
2457 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2459 if (body->mbo_valid & OBD_MD_FLATIME) {
2460 if (body->mbo_atime > inode->i_atime.tv_sec)
2461 inode->i_atime.tv_sec = body->mbo_atime;
2462 lli->lli_atime = body->mbo_atime;
2465 if (body->mbo_valid & OBD_MD_FLMTIME) {
2466 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2468 "setting ino %lu mtime from %lld to %llu\n",
2469 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2471 inode->i_mtime.tv_sec = body->mbo_mtime;
2473 lli->lli_mtime = body->mbo_mtime;
2476 if (body->mbo_valid & OBD_MD_FLCTIME) {
2477 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2478 inode->i_ctime.tv_sec = body->mbo_ctime;
2479 lli->lli_ctime = body->mbo_ctime;
2482 if (body->mbo_valid & OBD_MD_FLBTIME)
2483 lli->lli_btime = body->mbo_btime;
2485 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2486 if (body->mbo_valid & OBD_MD_FLFLAGS)
2487 ll_update_inode_flags(inode, body->mbo_flags);
2488 if (body->mbo_valid & OBD_MD_FLMODE)
2489 inode->i_mode = (inode->i_mode & S_IFMT) |
2490 (body->mbo_mode & ~S_IFMT);
2492 if (body->mbo_valid & OBD_MD_FLTYPE)
2493 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2494 (body->mbo_mode & S_IFMT);
2496 LASSERT(inode->i_mode != 0);
2497 if (body->mbo_valid & OBD_MD_FLUID)
2498 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2499 if (body->mbo_valid & OBD_MD_FLGID)
2500 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2501 if (body->mbo_valid & OBD_MD_FLPROJID)
2502 lli->lli_projid = body->mbo_projid;
2503 if (body->mbo_valid & OBD_MD_FLNLINK)
2504 set_nlink(inode, body->mbo_nlink);
2505 if (body->mbo_valid & OBD_MD_FLRDEV)
2506 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2508 if (body->mbo_valid & OBD_MD_FLID) {
2509 /* FID shouldn't be changed! */
2510 if (fid_is_sane(&lli->lli_fid)) {
2511 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2512 "Trying to change FID "DFID
2513 " to the "DFID", inode "DFID"(%p)\n",
2514 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2515 PFID(ll_inode2fid(inode)), inode);
2517 lli->lli_fid = body->mbo_fid1;
2521 LASSERT(fid_seq(&lli->lli_fid) != 0);
2523 lli->lli_attr_valid = body->mbo_valid;
2524 if (body->mbo_valid & OBD_MD_FLSIZE) {
2525 i_size_write(inode, body->mbo_size);
2527 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2528 PFID(ll_inode2fid(inode)),
2529 (unsigned long long)body->mbo_size);
2531 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2532 inode->i_blocks = body->mbo_blocks;
2534 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2535 lli->lli_lazysize = body->mbo_size;
2536 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2537 lli->lli_lazyblocks = body->mbo_blocks;
2540 if (body->mbo_valid & OBD_MD_TSTATE) {
2541 /* Set LLIF_FILE_RESTORING if restore ongoing and
2542 * clear it when done to ensure to start again
2543 * glimpsing updated attrs
2545 if (body->mbo_t_state & MS_RESTORE)
2546 ll_file_set_flag(lli, LLIF_FILE_RESTORING);
2548 ll_file_clear_flag(lli, LLIF_FILE_RESTORING);
2554 int ll_read_inode2(struct inode *inode, void *opaque)
2556 struct lustre_md *md = opaque;
2557 struct ll_inode_info *lli = ll_i2info(inode);
2561 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2562 PFID(&lli->lli_fid), inode);
2564 /* Core attributes from the MDS first. This is a new inode, and
2565 * the VFS doesn't zero times in the core inode so we have to do
2566 * it ourselves. They will be overwritten by either MDS or OST
2567 * attributes - we just need to make sure they aren't newer.
2569 inode->i_mtime.tv_sec = 0;
2570 inode->i_atime.tv_sec = 0;
2571 inode->i_ctime.tv_sec = 0;
2573 rc = ll_update_inode(inode, md);
2577 /* OIDEBUG(inode); */
2579 #ifdef HAVE_BACKING_DEV_INFO
2580 /* initializing backing dev info. */
2581 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2583 if (S_ISREG(inode->i_mode)) {
2584 struct ll_sb_info *sbi = ll_i2sbi(inode);
2585 inode->i_op = &ll_file_inode_operations;
2586 inode->i_fop = sbi->ll_fop;
2587 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2589 } else if (S_ISDIR(inode->i_mode)) {
2590 inode->i_op = &ll_dir_inode_operations;
2591 inode->i_fop = &ll_dir_operations;
2593 } else if (S_ISLNK(inode->i_mode)) {
2594 inode->i_op = &ll_fast_symlink_inode_operations;
2597 inode->i_op = &ll_special_inode_operations;
2599 init_special_inode(inode, inode->i_mode,
2608 void ll_delete_inode(struct inode *inode)
2610 struct ll_inode_info *lli = ll_i2info(inode);
2611 struct address_space *mapping = &inode->i_data;
2612 unsigned long nrpages;
2613 unsigned long flags;
2617 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2618 /* It is last chance to write out dirty pages,
2619 * otherwise we may lose data while umount.
2621 * If i_nlink is 0 then just discard data. This is safe because
2622 * local inode gets i_nlink 0 from server only for the last
2623 * unlink, so that file is not opened somewhere else
2625 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2626 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2628 truncate_inode_pages_final(mapping);
2630 /* Workaround for LU-118: Note nrpages may not be totally updated when
2631 * truncate_inode_pages() returns, as there can be a page in the process
2632 * of deletion (inside __delete_from_page_cache()) in the specified
2633 * range. Thus mapping->nrpages can be non-zero when this function
2634 * returns even after truncation of the whole mapping. Only do this if
2635 * npages isn't already zero.
2637 nrpages = mapping->nrpages;
2639 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2640 nrpages = mapping->nrpages;
2641 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2642 } /* Workaround end */
2644 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, "
2645 "see https://jira.whamcloud.com/browse/LU-118\n",
2646 ll_i2sbi(inode)->ll_fsname,
2647 PFID(ll_inode2fid(inode)), inode, nrpages);
2649 ll_clear_inode(inode);
2655 int ll_iocontrol(struct inode *inode, struct file *file,
2656 unsigned int cmd, unsigned long arg)
2658 struct ll_sb_info *sbi = ll_i2sbi(inode);
2659 struct ptlrpc_request *req = NULL;
2664 case FS_IOC_GETFLAGS: {
2665 struct mdt_body *body;
2666 struct md_op_data *op_data;
2668 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2669 0, 0, LUSTRE_OPC_ANY,
2671 if (IS_ERR(op_data))
2672 RETURN(PTR_ERR(op_data));
2674 op_data->op_valid = OBD_MD_FLFLAGS;
2675 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2676 ll_finish_md_op_data(op_data);
2678 CERROR("%s: failure inode "DFID": rc = %d\n",
2679 sbi->ll_md_exp->exp_obd->obd_name,
2680 PFID(ll_inode2fid(inode)), rc);
2684 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2686 flags = body->mbo_flags;
2688 ptlrpc_req_finished(req);
2690 RETURN(put_user(flags, (int __user *)arg));
2692 case FS_IOC_SETFLAGS: {
2694 struct md_op_data *op_data;
2695 struct cl_object *obj;
2696 struct fsxattr fa = { 0 };
2698 if (get_user(flags, (int __user *)arg))
2701 fa.fsx_projid = ll_i2info(inode)->lli_projid;
2702 if (flags & LUSTRE_PROJINHERIT_FL)
2703 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
2705 rc = ll_ioctl_check_project(inode, &fa);
2709 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
2710 LUSTRE_OPC_ANY, NULL);
2711 if (IS_ERR(op_data))
2712 RETURN(PTR_ERR(op_data));
2714 op_data->op_attr_flags = flags;
2715 op_data->op_xvalid |= OP_XVALID_FLAGS;
2716 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
2717 ll_finish_md_op_data(op_data);
2718 ptlrpc_req_finished(req);
2722 ll_update_inode_flags(inode, flags);
2724 obj = ll_i2info(inode)->lli_clob;
2728 OBD_ALLOC_PTR(attr);
2732 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
2744 int ll_flush_ctx(struct inode *inode)
2746 struct ll_sb_info *sbi = ll_i2sbi(inode);
2748 CDEBUG(D_SEC, "flush context for user %d\n",
2749 from_kuid(&init_user_ns, current_uid()));
2751 obd_set_info_async(NULL, sbi->ll_md_exp,
2752 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2754 obd_set_info_async(NULL, sbi->ll_dt_exp,
2755 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2760 /* umount -f client means force down, don't save state */
2761 void ll_umount_begin(struct super_block *sb)
2763 struct ll_sb_info *sbi = ll_s2sbi(sb);
2764 struct obd_device *obd;
2765 struct obd_ioctl_data *ioc_data;
2769 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2770 sb->s_count, atomic_read(&sb->s_active));
2772 obd = class_exp2obd(sbi->ll_md_exp);
2774 CERROR("Invalid MDC connection handle %#llx\n",
2775 sbi->ll_md_exp->exp_handle.h_cookie);
2781 obd = class_exp2obd(sbi->ll_dt_exp);
2783 CERROR("Invalid LOV connection handle %#llx\n",
2784 sbi->ll_dt_exp->exp_handle.h_cookie);
2790 OBD_ALLOC_PTR(ioc_data);
2792 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2793 sizeof *ioc_data, ioc_data, NULL);
2795 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2796 sizeof *ioc_data, ioc_data, NULL);
2798 OBD_FREE_PTR(ioc_data);
2801 /* Really, we'd like to wait until there are no requests outstanding,
2802 * and then continue. For now, we just periodically checking for vfs
2803 * to decrement mnt_cnt and hope to finish it within 10sec.
2807 !may_umount(sbi->ll_mnt.mnt)) {
2815 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2817 struct ll_sb_info *sbi = ll_s2sbi(sb);
2818 char *profilenm = get_profile_name(sb);
2822 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
2823 read_only = *flags & MS_RDONLY;
2824 err = obd_set_info_async(NULL, sbi->ll_md_exp,
2825 sizeof(KEY_READ_ONLY),
2826 KEY_READ_ONLY, sizeof(read_only),
2829 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2830 profilenm, read_only ?
2831 "read-only" : "read-write", err);
2836 sb->s_flags |= SB_RDONLY;
2838 sb->s_flags &= ~SB_RDONLY;
2840 if (sbi->ll_flags & LL_SBI_VERBOSE)
2841 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
2842 read_only ? "read-only" : "read-write");
2848 * Cleanup the open handle that is cached on MDT-side.
2850 * For open case, the client side open handling thread may hit error
2851 * after the MDT grant the open. Under such case, the client should
2852 * send close RPC to the MDT as cleanup; otherwise, the open handle
2853 * on the MDT will be leaked there until the client umount or evicted.
2855 * In further, if someone unlinked the file, because the open handle
2856 * holds the reference on such file/object, then it will block the
2857 * subsequent threads that want to locate such object via FID.
2859 * \param[in] sb super block for this file-system
2860 * \param[in] open_req pointer to the original open request
2862 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
2864 struct mdt_body *body;
2865 struct md_op_data *op_data;
2866 struct ptlrpc_request *close_req = NULL;
2867 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
2870 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
2871 OBD_ALLOC_PTR(op_data);
2872 if (op_data == NULL) {
2873 CWARN("%s: cannot allocate op_data to release open handle for "
2874 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
2879 op_data->op_fid1 = body->mbo_fid1;
2880 op_data->op_open_handle = body->mbo_open_handle;
2881 op_data->op_mod_time = ktime_get_real_seconds();
2882 md_close(exp, op_data, NULL, &close_req);
2883 ptlrpc_req_finished(close_req);
2884 ll_finish_md_op_data(op_data);
2889 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
2890 struct super_block *sb, struct lookup_intent *it)
2892 struct ll_sb_info *sbi = NULL;
2893 struct lustre_md md = { NULL };
2894 bool default_lmv_deleted = false;
2899 LASSERT(*inode || sb);
2900 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2901 rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
2902 sbi->ll_md_exp, &md);
2907 * clear default_lmv only if intent_getattr reply doesn't contain it.
2908 * but it needs to be done after iget, check this early because
2909 * ll_update_lsm_md() may change md.
2911 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
2912 S_ISDIR(md.body->mbo_mode) && !md.default_lmv)
2913 default_lmv_deleted = true;
2916 rc = ll_update_inode(*inode, &md);
2920 LASSERT(sb != NULL);
2923 * At this point server returns to client's same fid as client
2924 * generated for creating. So using ->fid1 is okay here.
2926 if (!fid_is_sane(&md.body->mbo_fid1)) {
2927 CERROR("%s: Fid is insane "DFID"\n",
2929 PFID(&md.body->mbo_fid1));
2930 GOTO(out, rc = -EINVAL);
2933 *inode = ll_iget(sb, cl_fid_build_ino(&md.body->mbo_fid1,
2934 sbi->ll_flags & LL_SBI_32BIT_API),
2936 if (IS_ERR(*inode)) {
2938 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
2940 CERROR("new_inode -fatal: rc %d\n", rc);
2945 /* Handling piggyback layout lock.
2946 * Layout lock can be piggybacked by getattr and open request.
2947 * The lsm can be applied to inode only if it comes with a layout lock
2948 * otherwise correct layout may be overwritten, for example:
2949 * 1. proc1: mdt returns a lsm but not granting layout
2950 * 2. layout was changed by another client
2951 * 3. proc2: refresh layout and layout lock granted
2952 * 4. proc1: to apply a stale layout */
2953 if (it != NULL && it->it_lock_mode != 0) {
2954 struct lustre_handle lockh;
2955 struct ldlm_lock *lock;
2957 lockh.cookie = it->it_lock_handle;
2958 lock = ldlm_handle2lock(&lockh);
2959 LASSERT(lock != NULL);
2960 if (ldlm_has_layout(lock)) {
2961 struct cl_object_conf conf;
2963 memset(&conf, 0, sizeof(conf));
2964 conf.coc_opc = OBJECT_CONF_SET;
2965 conf.coc_inode = *inode;
2966 conf.coc_lock = lock;
2967 conf.u.coc_layout = md.layout;
2968 (void)ll_layout_conf(*inode, &conf);
2970 LDLM_LOCK_PUT(lock);
2973 if (default_lmv_deleted)
2974 ll_update_default_lsm_md(*inode, &md);
2976 /* we may want to apply some policy for foreign file/dir */
2977 if (ll_sbi_has_foreign_symlink(sbi)) {
2978 rc = ll_manage_foreign(*inode, &md);
2986 /* cleanup will be done if necessary */
2987 md_free_lustre_md(sbi->ll_md_exp, &md);
2989 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
2990 ll_intent_drop_lock(it);
2991 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, req);
2997 int ll_obd_statfs(struct inode *inode, void __user *arg)
2999 struct ll_sb_info *sbi = NULL;
3000 struct obd_export *exp;
3002 struct obd_ioctl_data *data = NULL;
3006 if (!inode || !(sbi = ll_i2sbi(inode)))
3007 GOTO(out_statfs, rc = -EINVAL);
3009 rc = obd_ioctl_getdata(&buf, &len, arg);
3011 GOTO(out_statfs, rc);
3014 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3015 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3016 GOTO(out_statfs, rc = -EINVAL);
3018 if (data->ioc_inllen1 != sizeof(__u32) ||
3019 data->ioc_inllen2 != sizeof(__u32) ||
3020 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3021 data->ioc_plen2 != sizeof(struct obd_uuid))
3022 GOTO(out_statfs, rc = -EINVAL);
3024 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3025 if (type & LL_STATFS_LMV)
3026 exp = sbi->ll_md_exp;
3027 else if (type & LL_STATFS_LOV)
3028 exp = sbi->ll_dt_exp;
3030 GOTO(out_statfs, rc = -ENODEV);
3032 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL);
3034 GOTO(out_statfs, rc);
3036 OBD_FREE_LARGE(buf, len);
3041 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3042 * be called early to avoid deadlock.
3044 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3046 if (op_data->op_mea2_sem) {
3047 up_read_non_owner(op_data->op_mea2_sem);
3048 op_data->op_mea2_sem = NULL;
3051 if (op_data->op_mea1_sem) {
3052 up_read_non_owner(op_data->op_mea1_sem);
3053 op_data->op_mea1_sem = NULL;
3057 /* this function prepares md_op_data hint for passing it down to MD stack. */
3058 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3059 struct inode *i1, struct inode *i2,
3060 const char *name, size_t namelen,
3061 __u32 mode, enum md_op_code opc,
3064 LASSERT(i1 != NULL);
3067 /* Do not reuse namelen for something else. */
3069 return ERR_PTR(-EINVAL);
3071 if (namelen > ll_i2sbi(i1)->ll_namelen)
3072 return ERR_PTR(-ENAMETOOLONG);
3074 /* "/" is not valid name, but it's allowed */
3075 if (!lu_name_is_valid_2(name, namelen) &&
3076 strncmp("/", name, namelen) != 0)
3077 return ERR_PTR(-EINVAL);
3080 if (op_data == NULL)
3081 OBD_ALLOC_PTR(op_data);
3083 if (op_data == NULL)
3084 return ERR_PTR(-ENOMEM);
3086 ll_i2gids(op_data->op_suppgids, i1, i2);
3087 op_data->op_fid1 = *ll_inode2fid(i1);
3088 op_data->op_code = opc;
3090 if (S_ISDIR(i1->i_mode)) {
3091 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3092 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3093 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3094 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3098 op_data->op_fid2 = *ll_inode2fid(i2);
3099 if (S_ISDIR(i2->i_mode)) {
3101 /* i2 is typically a child of i1, and MUST be
3102 * further from the root to avoid deadlocks.
3104 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3105 op_data->op_mea2_sem =
3106 &ll_i2info(i2)->lli_lsm_sem;
3108 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3111 fid_zero(&op_data->op_fid2);
3114 if (ll_i2sbi(i1)->ll_flags & LL_SBI_64BIT_HASH)
3115 op_data->op_cli_flags |= CLI_HASH64;
3117 if (ll_need_32bit_api(ll_i2sbi(i1)))
3118 op_data->op_cli_flags |= CLI_API32;
3120 op_data->op_name = name;
3121 op_data->op_namelen = namelen;
3122 op_data->op_mode = mode;
3123 op_data->op_mod_time = ktime_get_real_seconds();
3124 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3125 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3126 op_data->op_cap = cfs_curproc_cap_pack();
3127 op_data->op_mds = 0;
3128 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3129 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3130 op_data->op_bias |= MDS_CREATE_VOLATILE;
3132 op_data->op_data = data;
3137 void ll_finish_md_op_data(struct md_op_data *op_data)
3139 ll_unlock_md_op_lsm(op_data);
3140 security_release_secctx(op_data->op_file_secctx,
3141 op_data->op_file_secctx_size);
3142 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3143 OBD_FREE_PTR(op_data);
3146 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3148 struct ll_sb_info *sbi;
3150 LASSERT(seq && dentry);
3151 sbi = ll_s2sbi(dentry->d_sb);
3153 if (sbi->ll_flags & LL_SBI_NOLCK)
3154 seq_puts(seq, ",nolock");
3156 /* "flock" is the default since 2.13, but it wasn't for many years,
3157 * so it is still useful to print this to show it is enabled.
3158 * Start to print "noflock" so it is now clear when flock is disabled.
3160 if (sbi->ll_flags & LL_SBI_FLOCK)
3161 seq_puts(seq, ",flock");
3162 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
3163 seq_puts(seq, ",localflock");
3165 seq_puts(seq, ",noflock");
3167 if (sbi->ll_flags & LL_SBI_USER_XATTR)
3168 seq_puts(seq, ",user_xattr");
3170 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
3171 seq_puts(seq, ",lazystatfs");
3173 if (sbi->ll_flags & LL_SBI_USER_FID2PATH)
3174 seq_puts(seq, ",user_fid2path");
3176 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
3177 seq_puts(seq, ",always_ping");
3179 if (ll_sbi_has_test_dummy_encryption(sbi))
3180 seq_puts(seq, ",test_dummy_encryption");
3182 if (ll_sbi_has_encrypt(sbi))
3183 seq_puts(seq, ",encrypt");
3185 seq_puts(seq, ",noencrypt");
3187 if (sbi->ll_flags & LL_SBI_FOREIGN_SYMLINK) {
3188 seq_puts(seq, ",foreign_symlink=");
3189 seq_puts(seq, sbi->ll_foreign_symlink_prefix);
3196 * Get obd name by cmd, and copy out to user space
3198 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
3200 struct ll_sb_info *sbi = ll_i2sbi(inode);
3201 struct obd_device *obd;
3204 if (cmd == OBD_IOC_GETDTNAME)
3205 obd = class_exp2obd(sbi->ll_dt_exp);
3206 else if (cmd == OBD_IOC_GETMDNAME)
3207 obd = class_exp2obd(sbi->ll_md_exp);
3214 if (copy_to_user((void __user *)arg, obd->obd_name,
3215 strlen(obd->obd_name) + 1))
3221 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3228 p.mnt = current->fs->root.mnt;
3230 path = d_path(&p, buf, bufsize);
3235 void ll_dirty_page_discard_warn(struct page *page, int ioret)
3237 char *buf, *path = NULL;
3238 struct dentry *dentry = NULL;
3239 struct inode *inode = page->mapping->host;
3241 /* this can be called inside spin lock so use GFP_ATOMIC. */
3242 buf = (char *)__get_free_page(GFP_ATOMIC);
3244 dentry = d_find_alias(page->mapping->host);
3246 path = ll_d_path(dentry, buf, PAGE_SIZE);
3249 /* The below message is checked in recovery-small.sh test_24b */
3251 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3252 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3253 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
3254 PFID(ll_inode2fid(inode)),
3255 (path && !IS_ERR(path)) ? path : "", ioret);
3261 free_page((unsigned long)buf);
3264 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3265 struct lov_user_md **kbuf)
3267 struct lov_user_md lum;
3271 if (copy_from_user(&lum, md, sizeof(lum)))
3274 lum_size = ll_lov_user_md_size(&lum);
3278 OBD_ALLOC_LARGE(*kbuf, lum_size);
3282 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3283 OBD_FREE_LARGE(*kbuf, lum_size);
3291 * Compute llite root squash state after a change of root squash
3292 * configuration setting or add/remove of a lnet nid
3294 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3296 struct root_squash_info *squash = &sbi->ll_squash;
3299 struct lnet_process_id id;
3301 /* Update norootsquash flag */
3302 spin_lock(&squash->rsi_lock);
3303 if (list_empty(&squash->rsi_nosquash_nids))
3304 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
3306 /* Do not apply root squash as soon as one of our NIDs is
3307 * in the nosquash_nids list */
3310 while (LNetGetId(i++, &id) != -ENOENT) {
3311 if (id.nid == LNET_NID_LO_0)
3313 if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) {
3319 sbi->ll_flags |= LL_SBI_NOROOTSQUASH;
3321 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
3323 spin_unlock(&squash->rsi_lock);
3327 * Parse linkea content to extract information about a given hardlink
3329 * \param[in] ldata - Initialized linkea data
3330 * \param[in] linkno - Link identifier
3331 * \param[out] parent_fid - The entry's parent FID
3332 * \param[out] ln - Entry name destination buffer
3334 * \retval 0 on success
3335 * \retval Appropriate negative error code on failure
3337 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3338 struct lu_fid *parent_fid, struct lu_name *ln)
3344 rc = linkea_init_with_rec(ldata);
3348 if (linkno >= ldata->ld_leh->leh_reccount)
3349 /* beyond last link */
3352 linkea_first_entry(ldata);
3353 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3354 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3359 linkea_next_entry(ldata);
3369 * Get parent FID and name of an identified link. Operation is performed for
3370 * a given link number, letting the caller iterate over linkno to list one or
3371 * all links of an entry.
3373 * \param[in] file - File descriptor against which to perform the operation
3374 * \param[in,out] arg - User-filled structure containing the linkno to operate
3375 * on and the available size. It is eventually filled with
3376 * the requested information or left untouched on error
3378 * \retval - 0 on success
3379 * \retval - Appropriate negative error code on failure
3381 int ll_getparent(struct file *file, struct getparent __user *arg)
3383 struct inode *inode = file_inode(file);
3384 struct linkea_data *ldata;
3385 struct lu_buf buf = LU_BUF_NULL;
3387 struct lu_fid parent_fid;
3394 if (!cfs_capable(CAP_DAC_READ_SEARCH) &&
3395 !(ll_i2sbi(inode)->ll_flags & LL_SBI_USER_FID2PATH))
3398 if (get_user(name_size, &arg->gp_name_size))
3401 if (get_user(linkno, &arg->gp_linkno))
3404 if (name_size > PATH_MAX)
3407 OBD_ALLOC(ldata, sizeof(*ldata));
3411 rc = linkea_data_new(ldata, &buf);
3413 GOTO(ldata_free, rc);
3415 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3416 buf.lb_len, OBD_MD_FLXATTR);
3420 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3424 if (ln.ln_namelen >= name_size)
3425 GOTO(lb_free, rc = -EOVERFLOW);
3427 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3428 GOTO(lb_free, rc = -EFAULT);
3430 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3431 GOTO(lb_free, rc = -EFAULT);
3433 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3434 GOTO(lb_free, rc = -EFAULT);
3439 OBD_FREE(ldata, sizeof(*ldata));