4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/llite/llite_lib.c
33 * Lustre Light Super operations
36 #define DEBUG_SUBSYSTEM S_LLITE
38 #include <linux/cpu.h>
39 #include <linux/module.h>
40 #include <linux/random.h>
41 #include <linux/statfs.h>
42 #include <linux/time.h>
43 #include <linux/file.h>
44 #include <linux/types.h>
45 #include <libcfs/linux/linux-uuid.h>
46 #include <linux/version.h>
48 #include <linux/user_namespace.h>
49 #include <linux/delay.h>
50 #include <linux/uidgid.h>
51 #include <linux/fs_struct.h>
53 #ifndef HAVE_CPUS_READ_LOCK
54 #include <libcfs/linux/linux-cpu.h>
56 #include <libcfs/linux/linux-misc.h>
57 #include <uapi/linux/lustre/lustre_ioctl.h>
58 #ifdef HAVE_UAPI_LINUX_MOUNT_H
59 #include <uapi/linux/mount.h>
62 #include <lustre_ha.h>
63 #include <lustre_dlm.h>
64 #include <lprocfs_status.h>
65 #include <lustre_disk.h>
66 #include <uapi/linux/lustre/lustre_param.h>
67 #include <lustre_log.h>
68 #include <cl_object.h>
69 #include <obd_cksum.h>
70 #include "llite_internal.h"
72 struct kmem_cache *ll_file_data_slab;
75 #define log2(n) ffz(~(n))
79 * If there is only one number of core visible to Lustre,
80 * async readahead will be disabled, to avoid massive over
81 * subscription, we use 1/2 of active cores as default max
82 * async readahead requests.
84 static inline unsigned int ll_get_ra_async_max_active(void)
86 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
89 static struct ll_sb_info *ll_init_sbi(void)
91 struct ll_sb_info *sbi = NULL;
93 unsigned long lru_page_max;
101 RETURN(ERR_PTR(-ENOMEM));
103 rc = pcc_super_init(&sbi->ll_pcc_super);
107 spin_lock_init(&sbi->ll_lock);
108 mutex_init(&sbi->ll_lco.lco_lock);
109 spin_lock_init(&sbi->ll_pp_extent_lock);
110 spin_lock_init(&sbi->ll_process_lock);
111 sbi->ll_rw_stats_on = 0;
112 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
115 pages = si.totalram - si.totalhigh;
116 lru_page_max = pages / 2;
118 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
119 sbi->ll_ra_info.ll_readahead_wq =
120 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
122 sbi->ll_ra_info.ra_async_max_active);
123 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
124 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
126 /* initialize ll_cache data */
127 sbi->ll_cache = cl_cache_init(lru_page_max);
128 if (sbi->ll_cache == NULL)
129 GOTO(out_destroy_ra, rc = -ENOMEM);
131 /* initialize foreign symlink prefix path */
132 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
133 if (sbi->ll_foreign_symlink_prefix == NULL)
134 GOTO(out_destroy_ra, rc = -ENOMEM);
135 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
136 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
138 /* initialize foreign symlink upcall path, none by default */
139 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
140 if (sbi->ll_foreign_symlink_upcall == NULL)
141 GOTO(out_destroy_ra, rc = -ENOMEM);
142 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
143 sbi->ll_foreign_symlink_upcall_items = NULL;
144 sbi->ll_foreign_symlink_upcall_nb_items = 0;
145 init_rwsem(&sbi->ll_foreign_symlink_sem);
146 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
147 * not enabled by default
150 sbi->ll_ra_info.ra_max_pages =
151 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
152 sbi->ll_ra_info.ra_max_pages_per_file =
153 min(sbi->ll_ra_info.ra_max_pages / 4,
154 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
155 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
156 sbi->ll_ra_info.ra_max_pages_per_file;
157 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
158 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
159 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
161 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
162 #ifdef ENABLE_CHECKSUM
163 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
166 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
169 #ifdef HAVE_LRU_RESIZE_SUPPORT
170 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
172 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
174 /* metadata statahead is enabled by default */
175 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
176 sbi->ll_sa_max = LL_SA_RPC_DEF;
177 atomic_set(&sbi->ll_sa_total, 0);
178 atomic_set(&sbi->ll_sa_wrong, 0);
179 atomic_set(&sbi->ll_sa_running, 0);
180 atomic_set(&sbi->ll_agl_total, 0);
181 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
182 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
183 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
184 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
185 ll_sbi_set_encrypt(sbi, true);
188 sbi->ll_squash.rsi_uid = 0;
189 sbi->ll_squash.rsi_gid = 0;
190 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
191 spin_lock_init(&sbi->ll_squash.rsi_lock);
193 /* Per-filesystem file heat */
194 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
195 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
197 /* Per-fs open heat level before requesting open lock */
198 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
199 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
200 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
203 if (sbi->ll_foreign_symlink_prefix)
204 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
206 cl_cache_decref(sbi->ll_cache);
207 sbi->ll_cache = NULL;
209 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
211 pcc_super_fini(&sbi->ll_pcc_super);
217 static void ll_free_sbi(struct super_block *sb)
219 struct ll_sb_info *sbi = ll_s2sbi(sb);
223 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
224 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
225 if (sbi->ll_ra_info.ll_readahead_wq)
226 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
227 if (sbi->ll_cache != NULL) {
228 cl_cache_decref(sbi->ll_cache);
229 sbi->ll_cache = NULL;
231 if (sbi->ll_foreign_symlink_prefix) {
232 OBD_FREE(sbi->ll_foreign_symlink_prefix,
233 sbi->ll_foreign_symlink_prefix_size);
234 sbi->ll_foreign_symlink_prefix = NULL;
236 if (sbi->ll_foreign_symlink_upcall) {
237 OBD_FREE(sbi->ll_foreign_symlink_upcall,
238 strlen(sbi->ll_foreign_symlink_upcall) +
240 sbi->ll_foreign_symlink_upcall = NULL;
242 if (sbi->ll_foreign_symlink_upcall_items) {
244 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
245 struct ll_foreign_symlink_upcall_item *items =
246 sbi->ll_foreign_symlink_upcall_items;
248 for (i = 0 ; i < nb_items; i++)
249 if (items[i].type == STRING_TYPE)
250 OBD_FREE(items[i].string,
253 OBD_FREE_LARGE(items, nb_items *
254 sizeof(struct ll_foreign_symlink_upcall_item));
255 sbi->ll_foreign_symlink_upcall_items = NULL;
257 ll_free_rw_stats_info(sbi);
258 pcc_super_fini(&sbi->ll_pcc_super);
259 OBD_FREE(sbi, sizeof(*sbi));
264 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
266 struct inode *root = NULL;
267 struct ll_sb_info *sbi = ll_s2sbi(sb);
268 struct obd_statfs *osfs = NULL;
269 struct ptlrpc_request *request = NULL;
270 struct obd_connect_data *data = NULL;
271 struct obd_uuid *uuid;
272 struct md_op_data *op_data;
273 struct lustre_md lmd;
275 int size, err, checksum;
279 sbi->ll_md_obd = class_name2obd(md);
280 if (!sbi->ll_md_obd) {
281 CERROR("MD %s: not setup or attached\n", md);
295 /* pass client page size via ocd_grant_blkbits, the server should report
296 * back its backend blocksize for grant calculation purpose */
297 data->ocd_grant_blkbits = PAGE_SHIFT;
299 /* indicate MDT features supported by this client */
300 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
301 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
302 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
303 OBD_CONNECT_SRVLOCK |
304 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
305 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
306 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
307 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
308 OBD_CONNECT_64BITHASH |
309 OBD_CONNECT_EINPROGRESS |
310 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
311 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
312 OBD_CONNECT_MAX_EASIZE |
313 OBD_CONNECT_FLOCK_DEAD |
314 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
315 OBD_CONNECT_OPEN_BY_FID |
316 OBD_CONNECT_DIR_STRIPE |
317 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
318 OBD_CONNECT_SUBTREE |
319 OBD_CONNECT_MULTIMODRPCS |
320 OBD_CONNECT_GRANT_PARAM |
321 OBD_CONNECT_GRANT_SHRINK |
322 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
324 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
325 OBD_CONNECT2_SUM_STATFS |
326 OBD_CONNECT2_OVERSTRIPING |
328 OBD_CONNECT2_LOCK_CONVERT |
329 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
330 OBD_CONNECT2_INC_XID |
332 OBD_CONNECT2_ASYNC_DISCARD |
334 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
335 OBD_CONNECT2_GETATTR_PFID |
336 OBD_CONNECT2_DOM_LVB |
337 OBD_CONNECT2_REP_MBITS |
338 OBD_CONNECT2_ATOMIC_OPEN_LOCK;
340 #ifdef HAVE_LRU_RESIZE_SUPPORT
341 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
342 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
344 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
346 data->ocd_cksum_types = obd_cksum_types_supported_client();
348 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
349 /* flag mdc connection as lightweight, only used for test
350 * purpose, use with care */
351 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
353 data->ocd_ibits_known = MDS_INODELOCK_FULL;
354 data->ocd_version = LUSTRE_VERSION_CODE;
356 if (sb->s_flags & SB_RDONLY)
357 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
358 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
359 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
362 /* Setting this indicates we correctly support S_NOSEC (See kernel
363 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
365 sb->s_flags |= SB_NOSEC;
367 sbi->ll_fop = ll_select_file_operations(sbi);
369 /* always ping even if server suppress_pings */
370 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
371 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
373 obd_connect_set_secctx(data);
374 if (ll_sbi_has_encrypt(sbi))
375 obd_connect_set_enc(data);
377 #if defined(CONFIG_SECURITY)
378 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
381 data->ocd_brw_size = MD_MAX_BRW_SIZE;
383 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
384 &sbi->ll_sb_uuid, data, sbi->ll_cache);
386 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
387 "recovery, of which this client is not a "
388 "part. Please wait for recovery to complete,"
389 " abort, or time out.\n", md);
392 CERROR("cannot connect to %s: rc = %d\n", md, err);
396 sbi->ll_md_exp->exp_connect_data = *data;
398 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
399 LUSTRE_SEQ_METADATA);
401 CERROR("%s: Can't init metadata layer FID infrastructure, "
402 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
406 /* For mount, we only need fs info from MDT0, and also in DNE, it
407 * can make sure the client can be mounted as long as MDT0 is
409 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
410 ktime_get_seconds() - sbi->ll_statfs_max_age,
411 OBD_STATFS_FOR_MDT0);
413 GOTO(out_md_fid, err);
415 /* This needs to be after statfs to ensure connect has finished.
416 * Note that "data" does NOT contain the valid connect reply.
417 * If connecting to a 1.8 server there will be no LMV device, so
418 * we can access the MDC export directly and exp_connect_flags will
419 * be non-zero, but if accessing an upgraded 2.1 server it will
420 * have the correct flags filled in.
421 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
422 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
423 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
424 valid != CLIENT_CONNECT_MDT_REQD) {
427 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
428 obd_connect_flags2str(buf, PAGE_SIZE,
429 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
430 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
431 "feature(s) needed for correct operation "
432 "of this client (%s). Please upgrade "
433 "server or downgrade client.\n",
434 sbi->ll_md_exp->exp_obd->obd_name, buf);
435 OBD_FREE(buf, PAGE_SIZE);
436 GOTO(out_md_fid, err = -EPROTO);
439 size = sizeof(*data);
440 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
441 KEY_CONN_DATA, &size, data);
443 CERROR("%s: Get connect data failed: rc = %d\n",
444 sbi->ll_md_exp->exp_obd->obd_name, err);
445 GOTO(out_md_fid, err);
448 LASSERT(osfs->os_bsize);
449 sb->s_blocksize = osfs->os_bsize;
450 sb->s_blocksize_bits = log2(osfs->os_bsize);
451 sb->s_magic = LL_SUPER_MAGIC;
452 sb->s_maxbytes = MAX_LFS_FILESIZE;
453 sbi->ll_namelen = osfs->os_namelen;
454 sbi->ll_mnt.mnt = current->fs->root.mnt;
455 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
457 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
458 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
459 LCONSOLE_INFO("Disabling user_xattr feature because "
460 "it is not supported on the server\n");
461 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
464 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
466 sb->s_flags |= SB_POSIXACL;
468 set_bit(LL_SBI_ACL, sbi->ll_flags);
470 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
472 sb->s_flags &= ~SB_POSIXACL;
474 clear_bit(LL_SBI_ACL, sbi->ll_flags);
477 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
478 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
480 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
481 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
483 if (obd_connect_has_secctx(data))
484 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
486 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
487 if (ll_sbi_has_test_dummy_encryption(sbi))
488 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
490 sbi->ll_md_exp->exp_obd->obd_name);
491 ll_sbi_set_encrypt(sbi, false);
494 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
495 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
496 LCONSOLE_INFO("%s: disabling xattr cache due to "
497 "unknown maximum xattr size.\n", dt);
498 } else if (!sbi->ll_xattr_cache_set) {
499 /* If xattr_cache is already set (no matter 0 or 1)
500 * during processing llog, it won't be enabled here. */
501 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
502 sbi->ll_xattr_cache_enabled = 1;
506 sbi->ll_dt_obd = class_name2obd(dt);
507 if (!sbi->ll_dt_obd) {
508 CERROR("DT %s: not setup or attached\n", dt);
509 GOTO(out_md_fid, err = -ENODEV);
512 /* pass client page size via ocd_grant_blkbits, the server should report
513 * back its backend blocksize for grant calculation purpose */
514 data->ocd_grant_blkbits = PAGE_SHIFT;
516 /* indicate OST features supported by this client */
517 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
518 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
519 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
520 OBD_CONNECT_SRVLOCK |
521 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
522 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
523 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
524 OBD_CONNECT_EINPROGRESS |
525 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
526 OBD_CONNECT_LAYOUTLOCK |
527 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
528 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
529 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
530 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
531 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
532 OBD_CONNECT2_REP_MBITS;
534 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
535 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
537 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
538 * disabled by default, because it can still be enabled on the
539 * fly via /sys. As a consequence, we still need to come to an
540 * agreement on the supported algorithms at connect time
542 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
544 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
545 data->ocd_cksum_types = OBD_CKSUM_ADLER;
547 data->ocd_cksum_types = obd_cksum_types_supported_client();
549 #ifdef HAVE_LRU_RESIZE_SUPPORT
550 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
552 /* always ping even if server suppress_pings */
553 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
554 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
556 if (ll_sbi_has_encrypt(sbi))
557 obd_connect_set_enc(data);
559 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
560 "ocd_grant: %d\n", data->ocd_connect_flags,
561 data->ocd_version, data->ocd_grant);
563 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
564 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
566 data->ocd_brw_size = DT_MAX_BRW_SIZE;
568 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
569 &sbi->ll_sb_uuid, data, sbi->ll_cache);
571 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
572 "recovery, of which this client is not a "
573 "part. Please wait for recovery to "
574 "complete, abort, or time out.\n", dt);
577 CERROR("%s: Cannot connect to %s: rc = %d\n",
578 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
582 if (ll_sbi_has_encrypt(sbi) &&
583 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
584 if (ll_sbi_has_test_dummy_encryption(sbi))
585 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
587 ll_sbi_set_encrypt(sbi, false);
588 } else if (ll_sbi_has_test_dummy_encryption(sbi)) {
589 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
592 sbi->ll_dt_exp->exp_connect_data = *data;
594 /* Don't change value if it was specified in the config log */
595 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
596 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
597 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
598 (data->ocd_brw_size >> PAGE_SHIFT));
599 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
600 sbi->ll_ra_info.ra_max_pages_per_file)
601 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
602 sbi->ll_ra_info.ra_max_pages_per_file;
605 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
606 LUSTRE_SEQ_METADATA);
608 CERROR("%s: Can't init data layer FID infrastructure, "
609 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
613 mutex_lock(&sbi->ll_lco.lco_lock);
614 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
615 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
616 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
617 mutex_unlock(&sbi->ll_lco.lco_lock);
619 fid_zero(&sbi->ll_root_fid);
620 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
623 CERROR("cannot mds_connect: rc = %d\n", err);
624 GOTO(out_lock_cn_cb, err);
626 if (!fid_is_sane(&sbi->ll_root_fid)) {
627 CERROR("%s: Invalid root fid "DFID" during mount\n",
628 sbi->ll_md_exp->exp_obd->obd_name,
629 PFID(&sbi->ll_root_fid));
630 GOTO(out_lock_cn_cb, err = -EINVAL);
632 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
634 sb->s_op = &lustre_super_operations;
635 sb->s_xattr = ll_xattr_handlers;
636 #if THREAD_SIZE >= 8192 /*b=17630*/
637 sb->s_export_op = &lustre_export_operations;
639 #ifdef HAVE_LUSTRE_CRYPTO
640 llcrypt_set_ops(sb, &lustre_cryptops);
644 * XXX: move this to after cbd setup? */
645 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
646 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
647 valid |= OBD_MD_FLACL;
649 OBD_ALLOC_PTR(op_data);
651 GOTO(out_lock_cn_cb, err = -ENOMEM);
653 op_data->op_fid1 = sbi->ll_root_fid;
654 op_data->op_mode = 0;
655 op_data->op_valid = valid;
657 err = md_getattr(sbi->ll_md_exp, op_data, &request);
659 OBD_FREE_PTR(op_data);
661 CERROR("%s: md_getattr failed for root: rc = %d\n",
662 sbi->ll_md_exp->exp_obd->obd_name, err);
663 GOTO(out_lock_cn_cb, err);
666 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
667 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
669 CERROR("failed to understand root inode md: rc = %d\n", err);
670 ptlrpc_req_finished(request);
671 GOTO(out_lock_cn_cb, err);
674 LASSERT(fid_is_sane(&sbi->ll_root_fid));
675 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
676 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
677 md_free_lustre_md(sbi->ll_md_exp, &lmd);
678 ptlrpc_req_finished(request);
682 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
684 CERROR("%s: bad ll_iget() for root: rc = %d\n",
685 sbi->ll_fsname, err);
689 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
690 if (sbi->ll_checksum_set) {
691 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
692 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
693 sizeof(checksum), &checksum, NULL);
695 CERROR("%s: Set checksum failed: rc = %d\n",
696 sbi->ll_dt_exp->exp_obd->obd_name, err);
702 sb->s_root = d_make_root(root);
703 if (sb->s_root == NULL) {
705 CERROR("%s: can't make root dentry: rc = %d\n",
706 sbi->ll_fsname, err);
710 sbi->ll_sdev_orig = sb->s_dev;
712 /* We set sb->s_dev equal on all lustre clients in order to support
713 * NFS export clustering. NFSD requires that the FSID be the same
715 /* s_dev is also used in lt_compare() to compare two fs, but that is
716 * only a node-local comparison. */
717 uuid = obd_get_uuid(sbi->ll_md_exp);
719 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
726 if (sbi->ll_dt_obd) {
727 err = sysfs_create_link(&sbi->ll_kset.kobj,
728 &sbi->ll_dt_obd->obd_kset.kobj,
729 sbi->ll_dt_obd->obd_type->typ_name);
731 CERROR("%s: could not register %s in llite: rc = %d\n",
732 dt, sbi->ll_fsname, err);
737 if (sbi->ll_md_obd) {
738 err = sysfs_create_link(&sbi->ll_kset.kobj,
739 &sbi->ll_md_obd->obd_kset.kobj,
740 sbi->ll_md_obd->obd_type->typ_name);
742 CERROR("%s: could not register %s in llite: rc = %d\n",
743 md, sbi->ll_fsname, err);
752 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
754 obd_disconnect(sbi->ll_dt_exp);
755 sbi->ll_dt_exp = NULL;
756 sbi->ll_dt_obd = NULL;
758 obd_fid_fini(sbi->ll_md_exp->exp_obd);
760 obd_disconnect(sbi->ll_md_exp);
761 sbi->ll_md_exp = NULL;
762 sbi->ll_md_obd = NULL;
771 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
775 size = sizeof(*lmmsize);
776 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
777 KEY_MAX_EASIZE, &size, lmmsize);
779 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
780 sbi->ll_dt_exp->exp_obd->obd_name, rc);
784 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
787 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
788 KEY_MAX_EASIZE, &size, lmmsize);
790 CERROR("Get max mdsize error rc %d\n", rc);
792 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
798 * Get the value of the default_easize parameter.
800 * \see client_obd::cl_default_mds_easize
802 * \param[in] sbi superblock info for this filesystem
803 * \param[out] lmmsize pointer to storage location for value
805 * \retval 0 on success
806 * \retval negative negated errno on failure
808 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
813 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
814 KEY_DEFAULT_EASIZE, &size, lmmsize);
816 CERROR("Get default mdsize error rc %d\n", rc);
822 * Set the default_easize parameter to the given value.
824 * \see client_obd::cl_default_mds_easize
826 * \param[in] sbi superblock info for this filesystem
827 * \param[in] lmmsize the size to set
829 * \retval 0 on success
830 * \retval negative negated errno on failure
832 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
836 if (lmmsize < sizeof(struct lov_mds_md) ||
837 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
840 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
841 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
842 sizeof(int), &lmmsize, NULL);
847 static void client_common_put_super(struct super_block *sb)
849 struct ll_sb_info *sbi = ll_s2sbi(sb);
854 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
855 obd_disconnect(sbi->ll_dt_exp);
856 sbi->ll_dt_exp = NULL;
858 ll_debugfs_unregister_super(sb);
860 obd_fid_fini(sbi->ll_md_exp->exp_obd);
861 obd_disconnect(sbi->ll_md_exp);
862 sbi->ll_md_exp = NULL;
867 void ll_kill_super(struct super_block *sb)
869 struct ll_sb_info *sbi;
873 if (!(sb->s_flags & SB_ACTIVE))
877 /* we need restore s_dev from changed for clustred NFS before put_super
878 * because new kernels have cached s_dev and change sb->s_dev in
879 * put_super not affected real removing devices */
881 sb->s_dev = sbi->ll_sdev_orig;
883 /* wait running statahead threads to quit */
884 while (atomic_read(&sbi->ll_sa_running) > 0)
885 schedule_timeout_uninterruptible(
886 cfs_time_seconds(1) >> 3);
892 /* Since we use this table for ll_sbi_flags_seq_show make
893 * sure what you want displayed for a specific token that
894 * is listed more than once below be listed first. For
895 * example we want "checksum" displayed, not "nochecksum"
898 static const match_table_t ll_sbi_flags_name = {
899 {LL_SBI_NOLCK, "nolock"},
900 {LL_SBI_CHECKSUM, "checksum"},
901 {LL_SBI_CHECKSUM, "nochecksum"},
902 {LL_SBI_LOCALFLOCK, "localflock"},
903 {LL_SBI_FLOCK, "flock"},
904 {LL_SBI_FLOCK, "noflock"},
905 {LL_SBI_USER_XATTR, "user_xattr"},
906 {LL_SBI_USER_XATTR, "nouser_xattr"},
907 {LL_SBI_LRU_RESIZE, "lruresize"},
908 {LL_SBI_LRU_RESIZE, "nolruresize"},
909 {LL_SBI_LAZYSTATFS, "lazystatfs"},
910 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
911 {LL_SBI_32BIT_API, "32bitapi"},
912 {LL_SBI_USER_FID2PATH, "user_fid2path"},
913 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
914 {LL_SBI_VERBOSE, "verbose"},
915 {LL_SBI_VERBOSE, "noverbose"},
916 {LL_SBI_ALWAYS_PING, "always_ping"},
917 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
918 {LL_SBI_ENCRYPT, "encrypt"},
919 {LL_SBI_ENCRYPT, "noencrypt"},
920 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
921 {LL_SBI_NUM_MOUNT_OPT, NULL},
924 {LL_SBI_AGL_ENABLED, "agl"},
925 {LL_SBI_64BIT_HASH, "64bit_hash"},
926 {LL_SBI_LAYOUT_LOCK, "layout"},
927 {LL_SBI_XATTR_CACHE, "xattr_cache"},
928 {LL_SBI_NOROOTSQUASH, "norootsquash"},
929 {LL_SBI_FAST_READ, "fast_read"},
930 {LL_SBI_FILE_SECCTX, "file_secctx"},
931 {LL_SBI_TINY_WRITE, "tiny_write"},
932 {LL_SBI_FILE_HEAT, "file_heat"},
933 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
936 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
938 struct super_block *sb = m->private;
941 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
944 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
947 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
948 if (ll_sbi_flags_name[j].token == i &&
949 ll_sbi_flags_name[j].pattern) {
951 ll_sbi_flags_name[j].pattern);
960 /* non-client-specific mount options are parsed in lmd_parse */
961 static int ll_options(char *options, struct super_block *sb)
963 struct ll_sb_info *sbi = ll_s2sbi(sb);
964 char *s2, *s1, *opts;
970 /* Don't stomp on lmd_opts */
971 opts = kstrdup(options, GFP_KERNEL);
977 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
979 while ((s1 = strsep(&opts, ",")) != NULL) {
980 substring_t args[MAX_OPT_ARGS];
981 bool turn_off = false;
987 CDEBUG(D_SUPER, "next opt=%s\n", s1);
989 if (strncmp(s1, "no", 2) == 0)
993 * Initialize args struct so we know whether arg was
994 * found; some options take optional arguments.
998 token = match_token(s1, ll_sbi_flags_name, args);
999 if (token == LL_SBI_NUM_MOUNT_OPT) {
1000 if (match_wildcard("context", s1) ||
1001 match_wildcard("fscontext", s1) ||
1002 match_wildcard("defcontext", s1) ||
1003 match_wildcard("rootcontext",s1))
1006 LCONSOLE_ERROR_MSG(0x152,
1007 "Unknown option '%s', won't mount.\n",
1014 case LL_SBI_32BIT_API:
1015 case LL_SBI_64BIT_HASH:
1016 case LL_SBI_ALWAYS_PING:
1017 set_bit(token, sbi->ll_flags);
1021 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1023 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1025 set_bit(token, sbi->ll_flags);
1028 case LL_SBI_LOCALFLOCK:
1029 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1030 set_bit(token, sbi->ll_flags);
1033 case LL_SBI_CHECKSUM:
1034 sbi->ll_checksum_set = 1;
1036 case LL_SBI_USER_XATTR:
1037 case LL_SBI_USER_FID2PATH:
1038 case LL_SBI_LRU_RESIZE:
1039 case LL_SBI_LAZYSTATFS:
1040 case LL_SBI_VERBOSE:
1042 clear_bit(token, sbi->ll_flags);
1044 set_bit(token, sbi->ll_flags);
1046 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1047 #ifdef HAVE_LUSTRE_CRYPTO
1048 set_bit(token, sbi->ll_flags);
1050 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1054 case LL_SBI_ENCRYPT:
1055 #ifdef HAVE_LUSTRE_CRYPTO
1057 clear_bit(token, sbi->ll_flags);
1059 set_bit(token, sbi->ll_flags);
1061 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1064 case LL_SBI_FOREIGN_SYMLINK:
1065 /* non-default prefix provided ? */
1070 /* path must be absolute */
1071 if (args->from[0] != '/') {
1072 LCONSOLE_ERROR_MSG(0x152,
1073 "foreign prefix '%s' must be an absolute path\n",
1078 old_len = sbi->ll_foreign_symlink_prefix_size;
1079 old = sbi->ll_foreign_symlink_prefix;
1080 /* alloc for path length and '\0' */
1081 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1082 if (!sbi->ll_foreign_symlink_prefix) {
1083 /* restore previous */
1084 sbi->ll_foreign_symlink_prefix = old;
1085 sbi->ll_foreign_symlink_prefix_size =
1089 sbi->ll_foreign_symlink_prefix_size =
1090 args->to - args->from + 1;
1091 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1092 sbi->ll_foreign_symlink_prefix_size,
1095 OBD_FREE(old, old_len);
1097 /* enable foreign symlink support */
1098 set_bit(token, sbi->ll_flags);
1100 LCONSOLE_ERROR_MSG(0x152,
1101 "invalid %s option\n", s1);
1112 void ll_lli_init(struct ll_inode_info *lli)
1114 lli->lli_inode_magic = LLI_INODE_MAGIC;
1116 rwlock_init(&lli->lli_lock);
1117 lli->lli_posix_acl = NULL;
1118 /* Do not set lli_fid, it has been initialized already. */
1119 fid_zero(&lli->lli_pfid);
1120 lli->lli_mds_read_och = NULL;
1121 lli->lli_mds_write_och = NULL;
1122 lli->lli_mds_exec_och = NULL;
1123 lli->lli_open_fd_read_count = 0;
1124 lli->lli_open_fd_write_count = 0;
1125 lli->lli_open_fd_exec_count = 0;
1126 mutex_init(&lli->lli_och_mutex);
1127 spin_lock_init(&lli->lli_agl_lock);
1128 spin_lock_init(&lli->lli_layout_lock);
1129 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1130 lli->lli_clob = NULL;
1132 init_rwsem(&lli->lli_xattrs_list_rwsem);
1133 mutex_init(&lli->lli_xattrs_enq_lock);
1135 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1136 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1137 lli->lli_opendir_key = NULL;
1138 lli->lli_sai = NULL;
1139 spin_lock_init(&lli->lli_sa_lock);
1140 lli->lli_opendir_pid = 0;
1141 lli->lli_sa_enabled = 0;
1142 init_rwsem(&lli->lli_lsm_sem);
1144 mutex_init(&lli->lli_size_mutex);
1145 mutex_init(&lli->lli_setattr_mutex);
1146 lli->lli_symlink_name = NULL;
1147 ll_trunc_sem_init(&lli->lli_trunc_sem);
1148 range_lock_tree_init(&lli->lli_write_tree);
1149 init_rwsem(&lli->lli_glimpse_sem);
1150 lli->lli_glimpse_time = ktime_set(0, 0);
1151 INIT_LIST_HEAD(&lli->lli_agl_list);
1152 lli->lli_agl_index = 0;
1153 lli->lli_async_rc = 0;
1154 spin_lock_init(&lli->lli_heat_lock);
1155 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1156 lli->lli_heat_flags = 0;
1157 mutex_init(&lli->lli_pcc_lock);
1158 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1159 lli->lli_pcc_inode = NULL;
1160 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1161 lli->lli_pcc_generation = 0;
1162 mutex_init(&lli->lli_group_mutex);
1163 lli->lli_group_users = 0;
1164 lli->lli_group_gid = 0;
1166 mutex_init(&lli->lli_layout_mutex);
1167 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1168 /* ll_cl_context initialize */
1169 INIT_LIST_HEAD(&lli->lli_lccs);
1172 #define MAX_STRING_SIZE 128
1174 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1176 #define LSI_BDI_INITIALIZED 0x00400000
1178 #ifndef HAVE_BDI_CAP_MAP_COPY
1179 # define BDI_CAP_MAP_COPY 0
1182 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1184 struct lustre_sb_info *lsi = s2lsi(sb);
1185 char buf[MAX_STRING_SIZE];
1189 err = bdi_init(&lsi->lsi_bdi);
1193 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1194 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1195 lsi->lsi_bdi.name = "lustre";
1196 va_start(args, fmt);
1197 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1199 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1202 sb->s_bdi = &lsi->lsi_bdi;
1206 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1208 int ll_fill_super(struct super_block *sb)
1210 struct lustre_profile *lprof = NULL;
1211 struct lustre_sb_info *lsi = s2lsi(sb);
1212 struct ll_sb_info *sbi = NULL;
1213 char *dt = NULL, *md = NULL;
1214 char *profilenm = get_profile_name(sb);
1215 struct config_llog_instance *cfg;
1216 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1217 const int instlen = LUSTRE_MAXINSTANCE + 2;
1218 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1219 char name[MAX_STRING_SIZE];
1228 /* for ASLR, to map between cfg_instance and hashed ptr */
1229 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1230 profilenm, cfg_instance, sb);
1232 OBD_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1236 GOTO(out_free_cfg, err = -ENOMEM);
1238 /* client additional sb info */
1239 lsi->lsi_llsbi = sbi = ll_init_sbi();
1241 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1243 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1245 GOTO(out_free_cfg, err);
1247 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1248 sb->s_d_op = &ll_d_ops;
1251 generate_random_uuid(uuid.b);
1252 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1254 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1257 len = strlen(profilenm);
1258 ptr = strrchr(profilenm, '-');
1259 if (ptr && (strcmp(ptr, "-client") == 0))
1262 if (len > LUSTRE_MAXFSNAME) {
1263 if (unlikely(len >= MAX_STRING_SIZE))
1264 len = MAX_STRING_SIZE - 1;
1265 strncpy(name, profilenm, len);
1267 err = -ENAMETOOLONG;
1268 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1269 name, LUSTRE_MAXFSNAME, err);
1270 GOTO(out_free_cfg, err);
1272 strncpy(sbi->ll_fsname, profilenm, len);
1273 sbi->ll_fsname[len] = '\0';
1276 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1277 profilenm, cfg_instance);
1279 err = super_setup_bdi_name(sb, "%s", name);
1281 GOTO(out_free_cfg, err);
1283 /* disable kernel readahead */
1284 sb->s_bdi->ra_pages = 0;
1286 /* Call ll_debugfs_register_super() before lustre_process_log()
1287 * so that "llite.*.*" params can be processed correctly.
1289 err = ll_debugfs_register_super(sb, name);
1291 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1292 sbi->ll_fsname, err);
1296 /* The cfg_instance is a value unique to this super, in case some
1297 * joker tries to mount the same fs at two mount points.
1299 cfg->cfg_instance = cfg_instance;
1300 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1301 cfg->cfg_callback = class_config_llog_handler;
1302 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1303 /* set up client obds */
1304 err = lustre_process_log(sb, profilenm, cfg);
1306 GOTO(out_debugfs, err);
1308 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1309 lprof = class_get_profile(profilenm);
1310 if (lprof == NULL) {
1311 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1312 " read from the MGS. Does that filesystem "
1313 "exist?\n", profilenm);
1314 GOTO(out_debugfs, err = -EINVAL);
1316 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1317 lprof->lp_md, lprof->lp_dt);
1319 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1320 OBD_ALLOC(dt, dt_len);
1322 GOTO(out_profile, err = -ENOMEM);
1323 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1325 md_len = strlen(lprof->lp_md) + instlen + 2;
1326 OBD_ALLOC(md, md_len);
1328 GOTO(out_free_dt, err = -ENOMEM);
1329 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1331 /* connections, registrations, sb setup */
1332 err = client_common_fill_super(sb, md, dt);
1334 GOTO(out_free_md, err);
1336 sbi->ll_client_common_fill_super_succeeded = 1;
1340 OBD_FREE(md, md_len);
1343 OBD_FREE(dt, dt_len);
1346 class_put_profile(lprof);
1349 ll_debugfs_unregister_super(sb);
1356 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1357 LCONSOLE_WARN("Mounted %s\n", profilenm);
1359 } /* ll_fill_super */
1361 void ll_put_super(struct super_block *sb)
1363 struct config_llog_instance cfg, params_cfg;
1364 struct obd_device *obd;
1365 struct lustre_sb_info *lsi = s2lsi(sb);
1366 struct ll_sb_info *sbi = ll_s2sbi(sb);
1367 char *profilenm = get_profile_name(sb);
1368 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1370 int next, force = 1, rc = 0;
1374 GOTO(out_no_sbi, 0);
1376 /* Should replace instance_id with something better for ASLR */
1377 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1378 profilenm, cfg_instance, sb);
1380 cfg.cfg_instance = cfg_instance;
1381 lustre_end_log(sb, profilenm, &cfg);
1383 params_cfg.cfg_instance = cfg_instance;
1384 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1386 if (sbi->ll_md_exp) {
1387 obd = class_exp2obd(sbi->ll_md_exp);
1389 force = obd->obd_force;
1392 /* Wait for unstable pages to be committed to stable storage */
1394 rc = l_wait_event_abortable(
1395 sbi->ll_cache->ccc_unstable_waitq,
1396 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1399 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1400 if (force == 0 && rc != -ERESTARTSYS)
1401 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1403 /* We need to set force before the lov_disconnect in
1404 * lustre_common_put_super, since l_d cleans up osc's as well.
1408 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1410 obd->obd_force = force;
1414 if (sbi->ll_client_common_fill_super_succeeded) {
1415 /* Only if client_common_fill_super succeeded */
1416 client_common_put_super(sb);
1420 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1421 class_manual_cleanup(obd);
1423 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1424 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1427 class_del_profile(profilenm);
1429 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1430 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1431 bdi_destroy(&lsi->lsi_bdi);
1432 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1437 lsi->lsi_llsbi = NULL;
1439 lustre_common_put_super(sb);
1441 cl_env_cache_purge(~0);
1444 } /* client_put_super */
1446 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1448 struct inode *inode = NULL;
1450 /* NOTE: we depend on atomic igrab() -bzzz */
1451 lock_res_and_lock(lock);
1452 if (lock->l_resource->lr_lvb_inode) {
1453 struct ll_inode_info * lli;
1454 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1455 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1456 inode = igrab(lock->l_resource->lr_lvb_inode);
1458 inode = lock->l_resource->lr_lvb_inode;
1459 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1460 D_WARNING, lock, "lr_lvb_inode %p is "
1461 "bogus: magic %08x",
1462 lock->l_resource->lr_lvb_inode,
1463 lli->lli_inode_magic);
1467 unlock_res_and_lock(lock);
1471 void ll_dir_clear_lsm_md(struct inode *inode)
1473 struct ll_inode_info *lli = ll_i2info(inode);
1475 LASSERT(S_ISDIR(inode->i_mode));
1477 if (lli->lli_lsm_md) {
1478 lmv_free_memmd(lli->lli_lsm_md);
1479 lli->lli_lsm_md = NULL;
1482 if (lli->lli_default_lsm_md) {
1483 lmv_free_memmd(lli->lli_default_lsm_md);
1484 lli->lli_default_lsm_md = NULL;
1488 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1489 const struct lu_fid *fid,
1490 struct lustre_md *md)
1492 struct ll_sb_info *sbi = ll_s2sbi(sb);
1493 struct ll_inode_info *lli;
1494 struct mdt_body *body = md->body;
1495 struct inode *inode;
1501 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1502 inode = iget_locked(sb, ino);
1503 if (inode == NULL) {
1504 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1505 sbi->ll_fsname, PFID(fid));
1506 RETURN(ERR_PTR(-ENOENT));
1509 lli = ll_i2info(inode);
1510 if (inode->i_state & I_NEW) {
1511 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1512 (body->mbo_mode & S_IFMT);
1513 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1516 inode->i_mtime.tv_sec = 0;
1517 inode->i_atime.tv_sec = 0;
1518 inode->i_ctime.tv_sec = 0;
1521 #ifdef HAVE_BACKING_DEV_INFO
1522 /* initializing backing dev info. */
1523 inode->i_mapping->backing_dev_info =
1524 &s2lsi(inode->i_sb)->lsi_bdi;
1526 inode->i_op = &ll_dir_inode_operations;
1527 inode->i_fop = &ll_dir_operations;
1528 lli->lli_fid = *fid;
1531 /* master object FID */
1532 lli->lli_pfid = body->mbo_fid1;
1533 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1534 lli, PFID(fid), PFID(&lli->lli_pfid));
1535 unlock_new_inode(inode);
1537 /* in directory restripe/auto-split, a directory will be
1538 * transformed to a stripe if it's plain, set its pfid here,
1539 * otherwise ll_lock_cancel_bits() can't find the master inode.
1541 lli->lli_pfid = body->mbo_fid1;
1547 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1550 struct lmv_stripe_md *lsm = md->lmv;
1551 struct ll_inode_info *lli = ll_i2info(inode);
1554 LASSERT(lsm != NULL);
1556 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1557 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1558 lsm_md_dump(D_INODE, lsm);
1560 if (!lmv_dir_striped(lsm))
1563 /* XXX sigh, this lsm_root initialization should be in
1564 * LMV layer, but it needs ll_iget right now, so we
1565 * put this here right now. */
1566 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1567 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1568 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1570 if (!fid_is_sane(fid))
1573 /* Unfortunately ll_iget will call ll_update_inode,
1574 * where the initialization of slave inode is slightly
1575 * different, so it reset lsm_md to NULL to avoid
1576 * initializing lsm for slave inode. */
1577 lsm->lsm_md_oinfo[i].lmo_root =
1578 ll_iget_anon_dir(inode->i_sb, fid, md);
1579 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1580 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1582 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1584 iput(lsm->lsm_md_oinfo[i].lmo_root);
1585 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1591 lli->lli_lsm_md = lsm;
1596 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1598 struct ll_inode_info *lli = ll_i2info(inode);
1602 if (!md->default_lmv) {
1603 /* clear default lsm */
1604 if (lli->lli_default_lsm_md) {
1605 down_write(&lli->lli_lsm_sem);
1606 if (lli->lli_default_lsm_md) {
1607 lmv_free_memmd(lli->lli_default_lsm_md);
1608 lli->lli_default_lsm_md = NULL;
1610 up_write(&lli->lli_lsm_sem);
1615 if (lli->lli_default_lsm_md) {
1616 /* do nonthing if default lsm isn't changed */
1617 down_read(&lli->lli_lsm_sem);
1618 if (lli->lli_default_lsm_md &&
1619 lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1620 up_read(&lli->lli_lsm_sem);
1623 up_read(&lli->lli_lsm_sem);
1626 down_write(&lli->lli_lsm_sem);
1627 if (lli->lli_default_lsm_md)
1628 lmv_free_memmd(lli->lli_default_lsm_md);
1629 lli->lli_default_lsm_md = md->default_lmv;
1630 lsm_md_dump(D_INODE, md->default_lmv);
1631 md->default_lmv = NULL;
1632 up_write(&lli->lli_lsm_sem);
1636 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1638 struct ll_inode_info *lli = ll_i2info(inode);
1639 struct lmv_stripe_md *lsm = md->lmv;
1640 struct cl_attr *attr;
1645 LASSERT(S_ISDIR(inode->i_mode));
1646 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1647 PFID(ll_inode2fid(inode)));
1649 /* update default LMV */
1650 if (md->default_lmv)
1651 ll_update_default_lsm_md(inode, md);
1653 /* after dir migration/restripe, a stripe may be turned into a
1654 * directory, in this case, zero out its lli_pfid.
1656 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1657 fid_zero(&lli->lli_pfid);
1660 * no striped information from request, lustre_md from req does not
1661 * include stripeEA, see ll_md_setattr()
1667 * normally dir layout doesn't change, only take read lock to check
1668 * that to avoid blocking other MD operations.
1670 down_read(&lli->lli_lsm_sem);
1672 /* some current lookup initialized lsm, and unchanged */
1673 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1674 GOTO(unlock, rc = 0);
1676 /* if dir layout doesn't match, check whether version is increased,
1677 * which means layout is changed, this happens in dir split/merge and
1680 * foreign LMV should not change.
1682 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1683 lsm->lsm_md_layout_version <=
1684 lli->lli_lsm_md->lsm_md_layout_version) {
1685 CERROR("%s: "DFID" dir layout mismatch:\n",
1686 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1687 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1688 lsm_md_dump(D_ERROR, lsm);
1689 GOTO(unlock, rc = -EINVAL);
1692 up_read(&lli->lli_lsm_sem);
1693 down_write(&lli->lli_lsm_sem);
1694 /* clear existing lsm */
1695 if (lli->lli_lsm_md) {
1696 lmv_free_memmd(lli->lli_lsm_md);
1697 lli->lli_lsm_md = NULL;
1700 rc = ll_init_lsm_md(inode, md);
1701 up_write(&lli->lli_lsm_sem);
1706 /* set md->lmv to NULL, so the following free lustre_md will not free
1711 /* md_merge_attr() may take long, since lsm is already set, switch to
1714 down_read(&lli->lli_lsm_sem);
1716 if (!lmv_dir_striped(lli->lli_lsm_md))
1717 GOTO(unlock, rc = 0);
1719 OBD_ALLOC_PTR(attr);
1721 GOTO(unlock, rc = -ENOMEM);
1723 /* validate the lsm */
1724 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1725 ll_md_blocking_ast);
1727 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1728 md->body->mbo_nlink = attr->cat_nlink;
1729 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1730 md->body->mbo_size = attr->cat_size;
1731 if (md->body->mbo_valid & OBD_MD_FLATIME)
1732 md->body->mbo_atime = attr->cat_atime;
1733 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1734 md->body->mbo_ctime = attr->cat_ctime;
1735 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1736 md->body->mbo_mtime = attr->cat_mtime;
1742 up_read(&lli->lli_lsm_sem);
1747 void ll_clear_inode(struct inode *inode)
1749 struct ll_inode_info *lli = ll_i2info(inode);
1750 struct ll_sb_info *sbi = ll_i2sbi(inode);
1754 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1755 PFID(ll_inode2fid(inode)), inode);
1757 if (S_ISDIR(inode->i_mode)) {
1758 /* these should have been cleared in ll_file_release */
1759 LASSERT(lli->lli_opendir_key == NULL);
1760 LASSERT(lli->lli_sai == NULL);
1761 LASSERT(lli->lli_opendir_pid == 0);
1763 pcc_inode_free(inode);
1766 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1768 LASSERT(!lli->lli_open_fd_write_count);
1769 LASSERT(!lli->lli_open_fd_read_count);
1770 LASSERT(!lli->lli_open_fd_exec_count);
1772 if (lli->lli_mds_write_och)
1773 ll_md_real_close(inode, FMODE_WRITE);
1774 if (lli->lli_mds_exec_och)
1775 ll_md_real_close(inode, FMODE_EXEC);
1776 if (lli->lli_mds_read_och)
1777 ll_md_real_close(inode, FMODE_READ);
1779 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1780 OBD_FREE(lli->lli_symlink_name,
1781 strlen(lli->lli_symlink_name) + 1);
1782 lli->lli_symlink_name = NULL;
1785 ll_xattr_cache_destroy(inode);
1787 forget_all_cached_acls(inode);
1789 lli->lli_inode_magic = LLI_INODE_DEAD;
1791 if (S_ISDIR(inode->i_mode))
1792 ll_dir_clear_lsm_md(inode);
1793 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1794 LASSERT(list_empty(&lli->lli_agl_list));
1797 * XXX This has to be done before lsm is freed below, because
1798 * cl_object still uses inode lsm.
1800 cl_inode_fini(inode);
1802 llcrypt_put_encryption_info(inode);
1807 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1809 struct lustre_md md;
1810 struct inode *inode = dentry->d_inode;
1811 struct ll_sb_info *sbi = ll_i2sbi(inode);
1812 struct ptlrpc_request *request = NULL;
1817 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1818 LUSTRE_OPC_ANY, NULL);
1819 if (IS_ERR(op_data))
1820 RETURN(PTR_ERR(op_data));
1822 /* If this is a chgrp of a regular file, we want to reserve enough
1823 * quota to cover the entire file size.
1825 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1826 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1827 from_kgid(&init_user_ns, inode->i_gid)) {
1828 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1829 op_data->op_attr_blocks = inode->i_blocks;
1833 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1835 ptlrpc_req_finished(request);
1836 if (rc == -ENOENT) {
1838 /* Unlinked special device node? Or just a race?
1839 * Pretend we done everything. */
1840 if (!S_ISREG(inode->i_mode) &&
1841 !S_ISDIR(inode->i_mode)) {
1842 ia_valid = op_data->op_attr.ia_valid;
1843 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1844 rc = simple_setattr(dentry, &op_data->op_attr);
1845 op_data->op_attr.ia_valid = ia_valid;
1847 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1848 CERROR("md_setattr fails: rc = %d\n", rc);
1853 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1854 sbi->ll_md_exp, &md);
1856 ptlrpc_req_finished(request);
1860 ia_valid = op_data->op_attr.ia_valid;
1861 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1862 * cache is not cleared yet. */
1863 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1864 if (S_ISREG(inode->i_mode))
1866 rc = simple_setattr(dentry, &op_data->op_attr);
1867 if (S_ISREG(inode->i_mode))
1868 inode_unlock(inode);
1869 op_data->op_attr.ia_valid = ia_valid;
1871 rc = ll_update_inode(inode, &md);
1872 ptlrpc_req_finished(request);
1878 * Zero portion of page that is part of @inode.
1879 * This implies, if necessary:
1880 * - taking cl_lock on range corresponding to concerned page
1881 * - grabbing vm page
1882 * - associating cl_page
1883 * - proceeding to clio read
1884 * - zeroing range in page
1885 * - proceeding to cl_page flush
1886 * - releasing cl_lock
1888 * \param[in] inode inode
1889 * \param[in] index page index
1890 * \param[in] offset offset in page to start zero from
1891 * \param[in] len len to zero
1893 * \retval 0 on success
1894 * \retval negative errno on failure
1896 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
1899 struct ll_inode_info *lli = ll_i2info(inode);
1900 struct cl_object *clob = lli->lli_clob;
1902 struct lu_env *env = NULL;
1903 struct cl_io *io = NULL;
1904 struct cl_page *clpage = NULL;
1905 struct page *vmpage = NULL;
1906 unsigned from = index << PAGE_SHIFT;
1907 struct cl_lock *lock = NULL;
1908 struct cl_lock_descr *descr = NULL;
1909 struct cl_2queue *queue = NULL;
1910 struct cl_sync_io *anchor = NULL;
1911 bool holdinglock = false;
1912 bool lockedbymyself = true;
1917 env = cl_env_get(&refcheck);
1919 RETURN(PTR_ERR(env));
1921 io = vvp_env_thread_io(env);
1923 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
1927 lock = vvp_env_lock(env);
1928 descr = &lock->cll_descr;
1929 descr->cld_obj = io->ci_obj;
1930 descr->cld_start = cl_index(io->ci_obj, from);
1931 descr->cld_end = cl_index(io->ci_obj, from + PAGE_SIZE - 1);
1932 descr->cld_mode = CLM_WRITE;
1933 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
1935 /* request lock for page */
1936 rc = cl_lock_request(env, io, lock);
1937 /* -ECANCELED indicates a matching lock with a different extent
1938 * was already present, and -EEXIST indicates a matching lock
1939 * on exactly the same extent was already present.
1940 * In both cases it means we are covered.
1942 if (rc == -ECANCELED || rc == -EEXIST)
1950 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
1952 GOTO(rellock, rc = -EOPNOTSUPP);
1954 if (!PageDirty(vmpage)) {
1955 /* associate cl_page */
1956 clpage = cl_page_find(env, clob, vmpage->index,
1957 vmpage, CPT_CACHEABLE);
1959 GOTO(pagefini, rc = PTR_ERR(clpage));
1961 cl_page_assume(env, io, clpage);
1964 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
1965 !PageWriteback(vmpage)) {
1967 /* set PagePrivate2 to detect special case of empty page
1968 * in osc_brw_fini_request()
1970 SetPagePrivate2(vmpage);
1971 rc = ll_io_read_page(env, io, clpage, NULL);
1972 if (!PagePrivate2(vmpage))
1973 /* PagePrivate2 was cleared in osc_brw_fini_request()
1974 * meaning we read an empty page. In this case, in order
1975 * to avoid allocating unnecessary block in truncated
1976 * file, we must not zero and write as below. Subsequent
1977 * server-side truncate will handle things correctly.
1979 GOTO(clpfini, rc = 0);
1980 ClearPagePrivate2(vmpage);
1983 lockedbymyself = trylock_page(vmpage);
1984 cl_page_assume(env, io, clpage);
1987 /* zero range in page */
1988 zero_user(vmpage, offset, len);
1990 if (holdinglock && clpage) {
1991 /* explicitly write newly modified page */
1992 queue = &io->ci_queue;
1993 cl_2queue_init(queue);
1994 anchor = &vvp_env_info(env)->vti_anchor;
1995 cl_sync_io_init(anchor, 1);
1996 clpage->cp_sync_io = anchor;
1997 cl_2queue_add(queue, clpage, true);
1998 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2000 GOTO(queuefini1, rc);
2001 rc = cl_sync_io_wait(env, anchor, 0);
2003 GOTO(queuefini2, rc);
2004 cl_page_assume(env, io, clpage);
2007 cl_2queue_discard(env, io, queue);
2009 cl_2queue_disown(env, io, queue);
2010 cl_2queue_fini(env, queue);
2015 cl_page_put(env, clpage);
2017 if (lockedbymyself) {
2018 unlock_page(vmpage);
2023 cl_lock_release(env, lock);
2025 cl_io_fini(env, io);
2028 cl_env_put(env, &refcheck);
2034 * Get reference file from volatile file name.
2035 * Volatile file name may look like:
2036 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2037 * where fd is opened descriptor of reference file.
2039 * \param[in] volatile_name volatile file name
2040 * \param[in] volatile_len volatile file name length
2041 * \param[out] ref_file pointer to struct file of reference file
2043 * \retval 0 on success
2044 * \retval negative errno on failure
2046 int volatile_ref_file(const char *volatile_name, int volatile_len,
2047 struct file **ref_file)
2049 char *p, *q, *fd_str;
2052 p = strnstr(volatile_name, ":fd=", volatile_len);
2053 if (!p || strlen(p + 4) == 0)
2056 q = strchrnul(p + 4, ':');
2057 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2060 rc = kstrtouint(fd_str, 10, &fd);
2065 *ref_file = fget(fd);
2071 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2072 * object(s) determine the file size and mtime. Otherwise, the MDS will
2073 * keep these values until such a time that objects are allocated for it.
2074 * We do the MDS operations first, as it is checking permissions for us.
2075 * We don't to the MDS RPC if there is nothing that we want to store there,
2076 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2077 * going to do an RPC anyways.
2079 * If we are doing a truncate, we will send the mtime and ctime updates
2080 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2081 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2084 * In case of HSMimport, we only set attr on MDS.
2086 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2087 enum op_xvalid xvalid, bool hsm_import)
2089 struct inode *inode = dentry->d_inode;
2090 struct ll_inode_info *lli = ll_i2info(inode);
2091 struct md_op_data *op_data = NULL;
2092 ktime_t kstart = ktime_get();
2097 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2098 "valid %x, hsm_import %d\n",
2099 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2100 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2103 if (attr->ia_valid & ATTR_SIZE) {
2104 /* Check new size against VFS/VM file size limit and rlimit */
2105 rc = inode_newsize_ok(inode, attr->ia_size);
2109 /* The maximum Lustre file size is variable, based on the
2110 * OST maximum object size and number of stripes. This
2111 * needs another check in addition to the VFS check above. */
2112 if (attr->ia_size > ll_file_maxbytes(inode)) {
2113 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2114 PFID(&lli->lli_fid), attr->ia_size,
2115 ll_file_maxbytes(inode));
2119 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2122 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2123 if (attr->ia_valid & TIMES_SET_FLAGS) {
2124 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2125 !capable(CAP_FOWNER))
2129 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2130 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2131 (attr->ia_valid & ATTR_CTIME)) {
2132 attr->ia_ctime = current_time(inode);
2133 xvalid |= OP_XVALID_CTIME_SET;
2135 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2136 (attr->ia_valid & ATTR_ATIME)) {
2137 attr->ia_atime = current_time(inode);
2138 attr->ia_valid |= ATTR_ATIME_SET;
2140 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2141 (attr->ia_valid & ATTR_MTIME)) {
2142 attr->ia_mtime = current_time(inode);
2143 attr->ia_valid |= ATTR_MTIME_SET;
2146 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2147 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2148 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2149 ktime_get_real_seconds());
2151 if (S_ISREG(inode->i_mode))
2152 inode_unlock(inode);
2154 /* We always do an MDS RPC, even if we're only changing the size;
2155 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2157 OBD_ALLOC_PTR(op_data);
2158 if (op_data == NULL)
2159 GOTO(out, rc = -ENOMEM);
2161 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2162 /* If we are changing file size, file content is
2163 * modified, flag it.
2165 xvalid |= OP_XVALID_OWNEROVERRIDE;
2166 op_data->op_bias |= MDS_DATA_MODIFIED;
2167 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2170 if (attr->ia_valid & ATTR_FILE) {
2171 struct ll_file_data *fd = attr->ia_file->private_data;
2173 if (fd->fd_lease_och)
2174 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2177 op_data->op_attr = *attr;
2178 op_data->op_xvalid = xvalid;
2180 rc = ll_md_setattr(dentry, op_data);
2184 if (!S_ISREG(inode->i_mode) || hsm_import)
2187 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2188 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2189 xvalid & OP_XVALID_CTIME_SET) {
2190 bool cached = false;
2192 rc = pcc_inode_setattr(inode, attr, &cached);
2195 CERROR("%s: PCC inode "DFID" setattr failed: "
2197 ll_i2sbi(inode)->ll_fsname,
2198 PFID(&lli->lli_fid), rc);
2202 unsigned int flags = 0;
2204 /* For truncate and utimes sending attributes to OSTs,
2205 * setting mtime/atime to the past will be performed
2206 * under PW [0:EOF] extent lock (new_size:EOF for
2207 * truncate). It may seem excessive to send mtime/atime
2208 * updates to OSTs when not setting times to past, but
2209 * it is necessary due to possible time
2210 * de-synchronization between MDT inode and OST objects
2212 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2213 xvalid |= OP_XVALID_FLAGS;
2214 flags = LUSTRE_ENCRYPT_FL;
2215 /* Call to ll_io_zero_page is not necessary if
2216 * truncating on PAGE_SIZE boundary, because
2217 * whole pages will be wiped.
2218 * In case of Direct IO, all we need is to set
2221 if (attr->ia_valid & ATTR_SIZE &&
2222 attr->ia_size & ~PAGE_MASK &&
2223 !(attr->ia_valid & ATTR_FILE &&
2224 attr->ia_file->f_flags & O_DIRECT)) {
2226 attr->ia_size & (PAGE_SIZE - 1);
2228 rc = ll_io_zero_page(inode,
2229 attr->ia_size >> PAGE_SHIFT,
2230 offset, PAGE_SIZE - offset);
2234 /* If encrypted volatile file without the key,
2235 * we need to fetch size from reference file,
2236 * and set it on OST objects. This happens when
2237 * migrating or extending an encrypted file
2240 if (filename_is_volatile(dentry->d_name.name,
2243 llcrypt_require_key(inode) == -ENOKEY) {
2244 struct file *ref_file;
2245 struct inode *ref_inode;
2246 struct ll_inode_info *ref_lli;
2247 struct cl_object *ref_obj;
2248 struct cl_attr ref_attr = { 0 };
2252 rc = volatile_ref_file(
2253 dentry->d_name.name,
2259 ref_inode = file_inode(ref_file);
2262 GOTO(out, rc = -EINVAL);
2265 env = cl_env_get(&refcheck);
2267 GOTO(out, rc = PTR_ERR(env));
2269 ref_lli = ll_i2info(ref_inode);
2270 ref_obj = ref_lli->lli_clob;
2271 cl_object_attr_lock(ref_obj);
2272 rc = cl_object_attr_get(env, ref_obj,
2274 cl_object_attr_unlock(ref_obj);
2275 cl_env_put(env, &refcheck);
2280 attr->ia_valid |= ATTR_SIZE;
2281 attr->ia_size = ref_attr.cat_size;
2284 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2288 /* If the file was restored, it needs to set dirty flag.
2290 * We've already sent MDS_DATA_MODIFIED flag in
2291 * ll_md_setattr() for truncate. However, the MDT refuses to
2292 * set the HS_DIRTY flag on released files, so we have to set
2293 * it again if the file has been restored. Please check how
2294 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2296 * Please notice that if the file is not released, the previous
2297 * MDS_DATA_MODIFIED has taken effect and usually
2298 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2299 * This way we can save an RPC for common open + trunc
2301 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2302 struct hsm_state_set hss = {
2303 .hss_valid = HSS_SETMASK,
2304 .hss_setmask = HS_DIRTY,
2308 rc2 = ll_hsm_state_set(inode, &hss);
2309 /* truncate and write can happen at the same time, so that
2310 * the file can be set modified even though the file is not
2311 * restored from released state, and ll_hsm_state_set() is
2312 * not applicable for the file, and rc2 < 0 is normal in this
2315 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2316 PFID(ll_inode2fid(inode)), rc2);
2321 if (op_data != NULL)
2322 ll_finish_md_op_data(op_data);
2324 if (S_ISREG(inode->i_mode)) {
2326 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2327 inode_dio_wait(inode);
2328 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2329 * flag. ll_update_inode (called from ll_md_setattr), clears
2330 * inode flags, so there is a gap where S_NOSEC is not set.
2331 * This can cause a writer to take the i_mutex unnecessarily,
2332 * but this is safe to do and should be rare. */
2333 inode_has_no_xattr(inode);
2337 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2338 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2339 ktime_us_delta(ktime_get(), kstart));
2344 int ll_setattr(struct dentry *de, struct iattr *attr)
2346 int mode = de->d_inode->i_mode;
2347 enum op_xvalid xvalid = 0;
2350 rc = llcrypt_prepare_setattr(de, attr);
2354 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2355 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2356 xvalid |= OP_XVALID_OWNEROVERRIDE;
2358 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2359 (ATTR_SIZE|ATTR_MODE)) &&
2360 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2361 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2362 !(attr->ia_mode & S_ISGID))))
2363 attr->ia_valid |= ATTR_FORCE;
2365 if ((attr->ia_valid & ATTR_MODE) &&
2367 !(attr->ia_mode & S_ISUID) &&
2368 !(attr->ia_valid & ATTR_KILL_SUID))
2369 attr->ia_valid |= ATTR_KILL_SUID;
2371 if ((attr->ia_valid & ATTR_MODE) &&
2372 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2373 !(attr->ia_mode & S_ISGID) &&
2374 !(attr->ia_valid & ATTR_KILL_SGID))
2375 attr->ia_valid |= ATTR_KILL_SGID;
2377 return ll_setattr_raw(de, attr, xvalid, false);
2380 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2383 struct obd_statfs obd_osfs = { 0 };
2388 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2390 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2391 flags |= OBD_STATFS_NODELAY;
2393 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2397 osfs->os_type = LL_SUPER_MAGIC;
2399 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2400 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2402 if (osfs->os_state & OS_STATFS_SUM)
2405 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2406 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2409 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2410 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2413 osfs->os_bsize = obd_osfs.os_bsize;
2414 osfs->os_blocks = obd_osfs.os_blocks;
2415 osfs->os_bfree = obd_osfs.os_bfree;
2416 osfs->os_bavail = obd_osfs.os_bavail;
2418 /* If we have _some_ OSTs, but don't have as many free objects on the
2419 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2420 * to compensate, so that the "inodes in use" number is correct.
2421 * This should be kept in sync with lod_statfs() behaviour.
2423 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2424 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2426 osfs->os_ffree = obd_osfs.os_ffree;
2433 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2435 struct if_quotactl qctl = {
2436 .qc_cmd = LUSTRE_Q_GETQUOTA,
2437 .qc_type = PRJQUOTA,
2438 .qc_valid = QC_GENERAL,
2440 u64 limit, curblock;
2443 qctl.qc_id = ll_i2info(inode)->lli_projid;
2444 ret = quotactl_ioctl(inode->i_sb, &qctl);
2446 /* ignore errors if project ID does not have
2447 * a quota limit or feature unsupported.
2449 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2454 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2455 qctl.qc_dqblk.dqb_bsoftlimit :
2456 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2457 if (limit && sfs->f_blocks > limit) {
2458 curblock = (qctl.qc_dqblk.dqb_curspace +
2459 sfs->f_bsize - 1) / sfs->f_bsize;
2460 sfs->f_blocks = limit;
2461 sfs->f_bfree = sfs->f_bavail =
2462 (sfs->f_blocks > curblock) ?
2463 (sfs->f_blocks - curblock) : 0;
2466 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2467 qctl.qc_dqblk.dqb_isoftlimit :
2468 qctl.qc_dqblk.dqb_ihardlimit;
2469 if (limit && sfs->f_files > limit) {
2470 sfs->f_files = limit;
2471 sfs->f_ffree = (sfs->f_files >
2472 qctl.qc_dqblk.dqb_curinodes) ?
2473 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2479 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2481 struct super_block *sb = de->d_sb;
2482 struct obd_statfs osfs;
2483 __u64 fsid = huge_encode_dev(sb->s_dev);
2484 ktime_t kstart = ktime_get();
2487 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2489 /* Some amount of caching on the client is allowed */
2490 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2494 statfs_unpack(sfs, &osfs);
2496 /* We need to downshift for all 32-bit kernels, because we can't
2497 * tell if the kernel is being called via sys_statfs64() or not.
2498 * Stop before overflowing f_bsize - in which case it is better
2499 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2500 if (sizeof(long) < 8) {
2501 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2504 osfs.os_blocks >>= 1;
2505 osfs.os_bfree >>= 1;
2506 osfs.os_bavail >>= 1;
2510 sfs->f_blocks = osfs.os_blocks;
2511 sfs->f_bfree = osfs.os_bfree;
2512 sfs->f_bavail = osfs.os_bavail;
2513 sfs->f_fsid.val[0] = (__u32)fsid;
2514 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2515 if (ll_i2info(de->d_inode)->lli_projid)
2516 return ll_statfs_project(de->d_inode, sfs);
2518 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2519 ktime_us_delta(ktime_get(), kstart));
2524 void ll_inode_size_lock(struct inode *inode)
2526 struct ll_inode_info *lli;
2528 LASSERT(!S_ISDIR(inode->i_mode));
2530 lli = ll_i2info(inode);
2531 mutex_lock(&lli->lli_size_mutex);
2534 void ll_inode_size_unlock(struct inode *inode)
2536 struct ll_inode_info *lli;
2538 lli = ll_i2info(inode);
2539 mutex_unlock(&lli->lli_size_mutex);
2542 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2544 /* do not clear encryption flag */
2545 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2546 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2547 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2548 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2550 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2553 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2555 struct ll_inode_info *lli = ll_i2info(inode);
2556 struct mdt_body *body = md->body;
2557 struct ll_sb_info *sbi = ll_i2sbi(inode);
2561 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2562 rc = cl_file_inode_init(inode, md);
2567 if (S_ISDIR(inode->i_mode)) {
2568 rc = ll_update_lsm_md(inode, md);
2573 if (body->mbo_valid & OBD_MD_FLACL)
2574 lli_replace_acl(lli, md);
2576 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2577 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2578 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2580 if (body->mbo_valid & OBD_MD_FLATIME) {
2581 if (body->mbo_atime > inode->i_atime.tv_sec)
2582 inode->i_atime.tv_sec = body->mbo_atime;
2583 lli->lli_atime = body->mbo_atime;
2586 if (body->mbo_valid & OBD_MD_FLMTIME) {
2587 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2589 "setting ino %lu mtime from %lld to %llu\n",
2590 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2592 inode->i_mtime.tv_sec = body->mbo_mtime;
2594 lli->lli_mtime = body->mbo_mtime;
2597 if (body->mbo_valid & OBD_MD_FLCTIME) {
2598 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2599 inode->i_ctime.tv_sec = body->mbo_ctime;
2600 lli->lli_ctime = body->mbo_ctime;
2603 if (body->mbo_valid & OBD_MD_FLBTIME)
2604 lli->lli_btime = body->mbo_btime;
2606 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2607 if (body->mbo_valid & OBD_MD_FLFLAGS)
2608 ll_update_inode_flags(inode, body->mbo_flags);
2609 if (body->mbo_valid & OBD_MD_FLMODE)
2610 inode->i_mode = (inode->i_mode & S_IFMT) |
2611 (body->mbo_mode & ~S_IFMT);
2613 if (body->mbo_valid & OBD_MD_FLTYPE)
2614 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2615 (body->mbo_mode & S_IFMT);
2617 LASSERT(inode->i_mode != 0);
2618 if (body->mbo_valid & OBD_MD_FLUID)
2619 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2620 if (body->mbo_valid & OBD_MD_FLGID)
2621 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2622 if (body->mbo_valid & OBD_MD_FLPROJID)
2623 lli->lli_projid = body->mbo_projid;
2624 if (body->mbo_valid & OBD_MD_FLNLINK) {
2625 spin_lock(&inode->i_lock);
2626 set_nlink(inode, body->mbo_nlink);
2627 spin_unlock(&inode->i_lock);
2629 if (body->mbo_valid & OBD_MD_FLRDEV)
2630 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2632 if (body->mbo_valid & OBD_MD_FLID) {
2633 /* FID shouldn't be changed! */
2634 if (fid_is_sane(&lli->lli_fid)) {
2635 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2636 "Trying to change FID "DFID
2637 " to the "DFID", inode "DFID"(%p)\n",
2638 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2639 PFID(ll_inode2fid(inode)), inode);
2641 lli->lli_fid = body->mbo_fid1;
2645 LASSERT(fid_seq(&lli->lli_fid) != 0);
2647 /* In case of encrypted file without the key, please do not lose
2648 * clear text size stored into lli_lazysize in ll_merge_attr(),
2649 * we will need it in ll_prepare_close().
2651 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2652 llcrypt_require_key(inode) == -ENOKEY)
2653 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2655 lli->lli_attr_valid = body->mbo_valid;
2656 if (body->mbo_valid & OBD_MD_FLSIZE) {
2657 i_size_write(inode, body->mbo_size);
2659 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2660 PFID(ll_inode2fid(inode)),
2661 (unsigned long long)body->mbo_size);
2663 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2664 inode->i_blocks = body->mbo_blocks;
2666 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2667 lli->lli_lazysize = body->mbo_size;
2668 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2669 lli->lli_lazyblocks = body->mbo_blocks;
2672 if (body->mbo_valid & OBD_MD_TSTATE) {
2673 /* Set LLIF_FILE_RESTORING if restore ongoing and
2674 * clear it when done to ensure to start again
2675 * glimpsing updated attrs
2677 if (body->mbo_t_state & MS_RESTORE)
2678 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2680 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2686 /* update directory depth to ROOT, called after LOOKUP lock is fetched. */
2687 void ll_update_dir_depth(struct inode *dir, struct inode *inode)
2689 struct ll_inode_info *lli;
2691 if (!S_ISDIR(inode->i_mode))
2697 lli = ll_i2info(inode);
2698 lli->lli_dir_depth = ll_i2info(dir)->lli_dir_depth + 1;
2699 CDEBUG(D_INODE, DFID" depth %hu\n",
2700 PFID(&lli->lli_fid), lli->lli_dir_depth);
2703 void ll_truncate_inode_pages_final(struct inode *inode)
2705 struct address_space *mapping = &inode->i_data;
2706 unsigned long nrpages;
2707 unsigned long flags;
2709 truncate_inode_pages_final(mapping);
2711 /* Workaround for LU-118: Note nrpages may not be totally updated when
2712 * truncate_inode_pages() returns, as there can be a page in the process
2713 * of deletion (inside __delete_from_page_cache()) in the specified
2714 * range. Thus mapping->nrpages can be non-zero when this function
2715 * returns even after truncation of the whole mapping. Only do this if
2716 * npages isn't already zero.
2718 nrpages = mapping->nrpages;
2720 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2721 nrpages = mapping->nrpages;
2722 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2723 } /* Workaround end */
2725 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, "
2726 "see https://jira.whamcloud.com/browse/LU-118\n",
2727 ll_i2sbi(inode)->ll_fsname,
2728 PFID(ll_inode2fid(inode)), inode, nrpages);
2731 int ll_read_inode2(struct inode *inode, void *opaque)
2733 struct lustre_md *md = opaque;
2734 struct ll_inode_info *lli = ll_i2info(inode);
2738 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2739 PFID(&lli->lli_fid), inode);
2741 /* Core attributes from the MDS first. This is a new inode, and
2742 * the VFS doesn't zero times in the core inode so we have to do
2743 * it ourselves. They will be overwritten by either MDS or OST
2744 * attributes - we just need to make sure they aren't newer.
2746 inode->i_mtime.tv_sec = 0;
2747 inode->i_atime.tv_sec = 0;
2748 inode->i_ctime.tv_sec = 0;
2750 rc = ll_update_inode(inode, md);
2754 /* OIDEBUG(inode); */
2756 #ifdef HAVE_BACKING_DEV_INFO
2757 /* initializing backing dev info. */
2758 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2760 if (S_ISREG(inode->i_mode)) {
2761 struct ll_sb_info *sbi = ll_i2sbi(inode);
2762 inode->i_op = &ll_file_inode_operations;
2763 inode->i_fop = sbi->ll_fop;
2764 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2766 } else if (S_ISDIR(inode->i_mode)) {
2767 inode->i_op = &ll_dir_inode_operations;
2768 inode->i_fop = &ll_dir_operations;
2770 } else if (S_ISLNK(inode->i_mode)) {
2771 inode->i_op = &ll_fast_symlink_inode_operations;
2774 inode->i_op = &ll_special_inode_operations;
2776 init_special_inode(inode, inode->i_mode,
2785 void ll_delete_inode(struct inode *inode)
2787 struct ll_inode_info *lli = ll_i2info(inode);
2790 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2791 /* It is last chance to write out dirty pages,
2792 * otherwise we may lose data while umount.
2794 * If i_nlink is 0 then just discard data. This is safe because
2795 * local inode gets i_nlink 0 from server only for the last
2796 * unlink, so that file is not opened somewhere else
2798 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2799 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2802 ll_truncate_inode_pages_final(inode);
2803 ll_clear_inode(inode);
2809 int ll_iocontrol(struct inode *inode, struct file *file,
2810 unsigned int cmd, unsigned long arg)
2812 struct ll_sb_info *sbi = ll_i2sbi(inode);
2813 struct ptlrpc_request *req = NULL;
2818 case FS_IOC_GETFLAGS: {
2819 struct mdt_body *body;
2820 struct md_op_data *op_data;
2822 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2823 0, 0, LUSTRE_OPC_ANY,
2825 if (IS_ERR(op_data))
2826 RETURN(PTR_ERR(op_data));
2828 op_data->op_valid = OBD_MD_FLFLAGS;
2829 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2830 ll_finish_md_op_data(op_data);
2832 CERROR("%s: failure inode "DFID": rc = %d\n",
2833 sbi->ll_md_exp->exp_obd->obd_name,
2834 PFID(ll_inode2fid(inode)), rc);
2838 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2840 flags = body->mbo_flags;
2842 ptlrpc_req_finished(req);
2844 RETURN(put_user(flags, (int __user *)arg));
2846 case FS_IOC_SETFLAGS: {
2848 struct md_op_data *op_data;
2849 struct cl_object *obj;
2850 struct fsxattr fa = { 0 };
2852 if (get_user(flags, (int __user *)arg))
2855 fa.fsx_projid = ll_i2info(inode)->lli_projid;
2856 if (flags & LUSTRE_PROJINHERIT_FL)
2857 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
2859 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
2864 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
2865 LUSTRE_OPC_ANY, NULL);
2866 if (IS_ERR(op_data))
2867 RETURN(PTR_ERR(op_data));
2869 op_data->op_attr_flags = flags;
2870 op_data->op_xvalid |= OP_XVALID_FLAGS;
2871 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
2872 ll_finish_md_op_data(op_data);
2873 ptlrpc_req_finished(req);
2877 ll_update_inode_flags(inode, flags);
2879 obj = ll_i2info(inode)->lli_clob;
2883 OBD_ALLOC_PTR(attr);
2887 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
2899 int ll_flush_ctx(struct inode *inode)
2901 struct ll_sb_info *sbi = ll_i2sbi(inode);
2903 CDEBUG(D_SEC, "flush context for user %d\n",
2904 from_kuid(&init_user_ns, current_uid()));
2906 obd_set_info_async(NULL, sbi->ll_md_exp,
2907 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2909 obd_set_info_async(NULL, sbi->ll_dt_exp,
2910 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2915 /* umount -f client means force down, don't save state */
2916 void ll_umount_begin(struct super_block *sb)
2918 struct ll_sb_info *sbi = ll_s2sbi(sb);
2919 struct obd_device *obd;
2920 struct obd_ioctl_data *ioc_data;
2924 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2925 sb->s_count, atomic_read(&sb->s_active));
2927 obd = class_exp2obd(sbi->ll_md_exp);
2929 CERROR("Invalid MDC connection handle %#llx\n",
2930 sbi->ll_md_exp->exp_handle.h_cookie);
2936 obd = class_exp2obd(sbi->ll_dt_exp);
2938 CERROR("Invalid LOV connection handle %#llx\n",
2939 sbi->ll_dt_exp->exp_handle.h_cookie);
2945 OBD_ALLOC_PTR(ioc_data);
2947 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2948 sizeof *ioc_data, ioc_data, NULL);
2950 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2951 sizeof *ioc_data, ioc_data, NULL);
2953 OBD_FREE_PTR(ioc_data);
2956 /* Really, we'd like to wait until there are no requests outstanding,
2957 * and then continue. For now, we just periodically checking for vfs
2958 * to decrement mnt_cnt and hope to finish it within 10sec.
2962 !may_umount(sbi->ll_mnt.mnt)) {
2970 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2972 struct ll_sb_info *sbi = ll_s2sbi(sb);
2973 char *profilenm = get_profile_name(sb);
2977 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
2978 read_only = *flags & MS_RDONLY;
2979 err = obd_set_info_async(NULL, sbi->ll_md_exp,
2980 sizeof(KEY_READ_ONLY),
2981 KEY_READ_ONLY, sizeof(read_only),
2984 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2985 profilenm, read_only ?
2986 "read-only" : "read-write", err);
2991 sb->s_flags |= SB_RDONLY;
2993 sb->s_flags &= ~SB_RDONLY;
2995 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
2996 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
2997 read_only ? "read-only" : "read-write");
3003 * Cleanup the open handle that is cached on MDT-side.
3005 * For open case, the client side open handling thread may hit error
3006 * after the MDT grant the open. Under such case, the client should
3007 * send close RPC to the MDT as cleanup; otherwise, the open handle
3008 * on the MDT will be leaked there until the client umount or evicted.
3010 * In further, if someone unlinked the file, because the open handle
3011 * holds the reference on such file/object, then it will block the
3012 * subsequent threads that want to locate such object via FID.
3014 * \param[in] sb super block for this file-system
3015 * \param[in] open_req pointer to the original open request
3017 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3019 struct mdt_body *body;
3020 struct md_op_data *op_data;
3021 struct ptlrpc_request *close_req = NULL;
3022 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3025 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3026 OBD_ALLOC_PTR(op_data);
3027 if (op_data == NULL) {
3028 CWARN("%s: cannot allocate op_data to release open handle for "
3029 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3034 op_data->op_fid1 = body->mbo_fid1;
3035 op_data->op_open_handle = body->mbo_open_handle;
3036 op_data->op_mod_time = ktime_get_real_seconds();
3037 md_close(exp, op_data, NULL, &close_req);
3038 ptlrpc_req_finished(close_req);
3039 ll_finish_md_op_data(op_data);
3044 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3045 struct super_block *sb, struct lookup_intent *it)
3047 struct ll_sb_info *sbi = NULL;
3048 struct lustre_md md = { NULL };
3049 bool default_lmv_deleted = false;
3054 LASSERT(*inode || sb);
3055 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3056 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3057 sbi->ll_md_exp, &md);
3062 * clear default_lmv only if intent_getattr reply doesn't contain it.
3063 * but it needs to be done after iget, check this early because
3064 * ll_update_lsm_md() may change md.
3066 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3067 S_ISDIR(md.body->mbo_mode) && !md.default_lmv)
3068 default_lmv_deleted = true;
3071 rc = ll_update_inode(*inode, &md);
3075 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3076 struct lu_fid *fid1 = &md.body->mbo_fid1;
3078 LASSERT(sb != NULL);
3081 * At this point server returns to client's same fid as client
3082 * generated for creating. So using ->fid1 is okay here.
3084 if (!fid_is_sane(fid1)) {
3085 CERROR("%s: Fid is insane "DFID"\n",
3086 sbi->ll_fsname, PFID(fid1));
3087 GOTO(out, rc = -EINVAL);
3090 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3091 if (IS_ERR(*inode)) {
3093 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3095 CERROR("new_inode -fatal: rc %d\n", rc);
3100 /* Handling piggyback layout lock.
3101 * Layout lock can be piggybacked by getattr and open request.
3102 * The lsm can be applied to inode only if it comes with a layout lock
3103 * otherwise correct layout may be overwritten, for example:
3104 * 1. proc1: mdt returns a lsm but not granting layout
3105 * 2. layout was changed by another client
3106 * 3. proc2: refresh layout and layout lock granted
3107 * 4. proc1: to apply a stale layout */
3108 if (it != NULL && it->it_lock_mode != 0) {
3109 struct lustre_handle lockh;
3110 struct ldlm_lock *lock;
3112 lockh.cookie = it->it_lock_handle;
3113 lock = ldlm_handle2lock(&lockh);
3114 LASSERT(lock != NULL);
3115 if (ldlm_has_layout(lock)) {
3116 struct cl_object_conf conf;
3118 memset(&conf, 0, sizeof(conf));
3119 conf.coc_opc = OBJECT_CONF_SET;
3120 conf.coc_inode = *inode;
3121 conf.coc_lock = lock;
3122 conf.u.coc_layout = md.layout;
3123 (void)ll_layout_conf(*inode, &conf);
3125 LDLM_LOCK_PUT(lock);
3128 if (default_lmv_deleted)
3129 ll_update_default_lsm_md(*inode, &md);
3131 /* we may want to apply some policy for foreign file/dir */
3132 if (ll_sbi_has_foreign_symlink(sbi)) {
3133 rc = ll_manage_foreign(*inode, &md);
3141 /* cleanup will be done if necessary */
3142 md_free_lustre_md(sbi->ll_md_exp, &md);
3144 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3145 ll_intent_drop_lock(it);
3146 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3152 int ll_obd_statfs(struct inode *inode, void __user *arg)
3154 struct ll_sb_info *sbi = NULL;
3155 struct obd_export *exp;
3156 struct obd_ioctl_data *data = NULL;
3161 sbi = ll_i2sbi(inode);
3163 GOTO(out_statfs, rc = -EINVAL);
3165 rc = obd_ioctl_getdata(&data, &len, arg);
3167 GOTO(out_statfs, rc);
3169 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3170 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3171 GOTO(out_statfs, rc = -EINVAL);
3173 if (data->ioc_inllen1 != sizeof(__u32) ||
3174 data->ioc_inllen2 != sizeof(__u32) ||
3175 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3176 data->ioc_plen2 != sizeof(struct obd_uuid))
3177 GOTO(out_statfs, rc = -EINVAL);
3179 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3180 if (type & LL_STATFS_LMV)
3181 exp = sbi->ll_md_exp;
3182 else if (type & LL_STATFS_LOV)
3183 exp = sbi->ll_dt_exp;
3185 GOTO(out_statfs, rc = -ENODEV);
3187 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3189 GOTO(out_statfs, rc);
3191 OBD_FREE_LARGE(data, len);
3196 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3197 * be called early to avoid deadlock.
3199 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3201 if (op_data->op_mea2_sem) {
3202 up_read_non_owner(op_data->op_mea2_sem);
3203 op_data->op_mea2_sem = NULL;
3206 if (op_data->op_mea1_sem) {
3207 up_read_non_owner(op_data->op_mea1_sem);
3208 op_data->op_mea1_sem = NULL;
3212 /* this function prepares md_op_data hint for passing it down to MD stack. */
3213 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3214 struct inode *i1, struct inode *i2,
3215 const char *name, size_t namelen,
3216 __u32 mode, enum md_op_code opc,
3219 struct llcrypt_name fname = { 0 };
3222 LASSERT(i1 != NULL);
3225 /* Do not reuse namelen for something else. */
3227 return ERR_PTR(-EINVAL);
3229 if ((!IS_ENCRYPTED(i1) ||
3230 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3231 namelen > ll_i2sbi(i1)->ll_namelen)
3232 return ERR_PTR(-ENAMETOOLONG);
3234 /* "/" is not valid name, but it's allowed */
3235 if (!lu_name_is_valid_2(name, namelen) &&
3236 strncmp("/", name, namelen) != 0)
3237 return ERR_PTR(-EINVAL);
3240 if (op_data == NULL)
3241 OBD_ALLOC_PTR(op_data);
3243 if (op_data == NULL)
3244 return ERR_PTR(-ENOMEM);
3246 ll_i2gids(op_data->op_suppgids, i1, i2);
3247 op_data->op_fid1 = *ll_inode2fid(i1);
3249 if (S_ISDIR(i1->i_mode)) {
3250 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3251 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3252 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3253 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3257 op_data->op_fid2 = *ll_inode2fid(i2);
3258 if (S_ISDIR(i2->i_mode)) {
3260 /* i2 is typically a child of i1, and MUST be
3261 * further from the root to avoid deadlocks.
3263 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3264 op_data->op_mea2_sem =
3265 &ll_i2info(i2)->lli_lsm_sem;
3267 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3270 fid_zero(&op_data->op_fid2);
3273 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3274 op_data->op_cli_flags |= CLI_HASH64;
3276 if (ll_need_32bit_api(ll_i2sbi(i1)))
3277 op_data->op_cli_flags |= CLI_API32;
3279 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3280 /* In case of lookup, ll_setup_filename() has already been
3281 * called in ll_lookup_it(), so just take provided name.
3283 fname.disk_name.name = (unsigned char *)name;
3284 fname.disk_name.len = namelen;
3285 } else if (name && namelen) {
3286 struct qstr dname = QSTR_INIT(name, namelen);
3288 struct lu_fid *pfid = NULL;
3292 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3293 /* special case when called from ll_link() */
3298 lookup = (int)(opc == LUSTRE_OPC_ANY);
3300 if (opc == LUSTRE_OPC_ANY && lookup)
3302 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3304 ll_finish_md_op_data(op_data);
3307 if (pfid && !fid_is_zero(pfid)) {
3309 op_data->op_fid2 = fid;
3310 op_data->op_bias = MDS_FID_OP;
3312 if (fname.disk_name.name &&
3313 fname.disk_name.name != (unsigned char *)name)
3314 /* op_data->op_name must be freed after use */
3315 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3318 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3319 * are LUSTRE_OPC_ANY
3321 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3322 op_data->op_code = LUSTRE_OPC_ANY;
3324 op_data->op_code = opc;
3325 op_data->op_name = fname.disk_name.name;
3326 op_data->op_namelen = fname.disk_name.len;
3327 op_data->op_mode = mode;
3328 op_data->op_mod_time = ktime_get_real_seconds();
3329 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3330 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3331 op_data->op_cap = current_cap();
3332 op_data->op_mds = 0;
3333 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3334 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3335 op_data->op_bias |= MDS_CREATE_VOLATILE;
3337 op_data->op_data = data;
3342 void ll_finish_md_op_data(struct md_op_data *op_data)
3344 ll_unlock_md_op_lsm(op_data);
3345 ll_security_release_secctx(op_data->op_file_secctx,
3346 op_data->op_file_secctx_size);
3347 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3348 /* allocated via ll_setup_filename called
3349 * from ll_prep_md_op_data
3351 kfree(op_data->op_name);
3352 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3353 OBD_FREE_PTR(op_data);
3356 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3358 struct ll_sb_info *sbi;
3361 LASSERT(seq && dentry);
3362 sbi = ll_s2sbi(dentry->d_sb);
3364 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3365 seq_puts(seq, "nolock");
3367 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3368 /* match_table in some cases has patterns for both enabled and
3369 * disabled cases. Ignore 'no'xxx versions if bit is set.
3371 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3372 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3373 if (ll_sbi_flags_name[i].token ==
3374 LL_SBI_FOREIGN_SYMLINK) {
3375 seq_show_option(seq, "foreign_symlink",
3376 sbi->ll_foreign_symlink_prefix);
3378 seq_printf(seq, ",%s",
3379 ll_sbi_flags_name[i].pattern);
3382 /* You can have either localflock or flock but not
3383 * both. If localflock is set don't print flock or
3386 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3388 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3389 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3390 seq_printf(seq, ",%s",
3391 ll_sbi_flags_name[i].pattern);
3399 * Get obd name by cmd, and copy out to user space
3401 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
3403 struct ll_sb_info *sbi = ll_i2sbi(inode);
3404 struct obd_device *obd;
3407 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3408 obd = class_exp2obd(sbi->ll_dt_exp);
3409 else if (cmd == OBD_IOC_GETMDNAME)
3410 obd = class_exp2obd(sbi->ll_md_exp);
3417 if (copy_to_user((void __user *)arg, obd->obd_name,
3418 strlen(obd->obd_name) + 1))
3424 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3431 p.mnt = current->fs->root.mnt;
3433 path = d_path(&p, buf, bufsize);
3438 void ll_dirty_page_discard_warn(struct page *page, int ioret)
3440 char *buf, *path = NULL;
3441 struct dentry *dentry = NULL;
3442 struct inode *inode = page->mapping->host;
3444 /* this can be called inside spin lock so use GFP_ATOMIC. */
3445 buf = (char *)__get_free_page(GFP_ATOMIC);
3447 dentry = d_find_alias(page->mapping->host);
3449 path = ll_d_path(dentry, buf, PAGE_SIZE);
3452 /* The below message is checked in recovery-small.sh test_24b */
3454 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3455 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3456 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
3457 PFID(ll_inode2fid(inode)),
3458 (path && !IS_ERR(path)) ? path : "", ioret);
3464 free_page((unsigned long)buf);
3467 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3468 struct lov_user_md **kbuf)
3470 struct lov_user_md lum;
3474 if (copy_from_user(&lum, md, sizeof(lum)))
3477 lum_size = ll_lov_user_md_size(&lum);
3481 OBD_ALLOC_LARGE(*kbuf, lum_size);
3485 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3486 OBD_FREE_LARGE(*kbuf, lum_size);
3494 * Compute llite root squash state after a change of root squash
3495 * configuration setting or add/remove of a lnet nid
3497 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3499 struct root_squash_info *squash = &sbi->ll_squash;
3502 struct lnet_process_id id;
3504 /* Update norootsquash flag */
3505 spin_lock(&squash->rsi_lock);
3506 if (list_empty(&squash->rsi_nosquash_nids))
3507 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3509 /* Do not apply root squash as soon as one of our NIDs is
3510 * in the nosquash_nids list */
3513 while (LNetGetId(i++, &id) != -ENOENT) {
3514 if (id.nid == LNET_NID_LO_0)
3516 if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) {
3522 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3524 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3526 spin_unlock(&squash->rsi_lock);
3530 * Parse linkea content to extract information about a given hardlink
3532 * \param[in] ldata - Initialized linkea data
3533 * \param[in] linkno - Link identifier
3534 * \param[out] parent_fid - The entry's parent FID
3535 * \param[out] ln - Entry name destination buffer
3537 * \retval 0 on success
3538 * \retval Appropriate negative error code on failure
3540 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3541 struct lu_fid *parent_fid, struct lu_name *ln)
3547 rc = linkea_init_with_rec(ldata);
3551 if (linkno >= ldata->ld_leh->leh_reccount)
3552 /* beyond last link */
3555 linkea_first_entry(ldata);
3556 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3557 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3562 linkea_next_entry(ldata);
3572 * Get parent FID and name of an identified link. Operation is performed for
3573 * a given link number, letting the caller iterate over linkno to list one or
3574 * all links of an entry.
3576 * \param[in] file - File descriptor against which to perform the operation
3577 * \param[in,out] arg - User-filled structure containing the linkno to operate
3578 * on and the available size. It is eventually filled with
3579 * the requested information or left untouched on error
3581 * \retval - 0 on success
3582 * \retval - Appropriate negative error code on failure
3584 int ll_getparent(struct file *file, struct getparent __user *arg)
3586 struct inode *inode = file_inode(file);
3587 struct linkea_data *ldata;
3588 struct lu_buf buf = LU_BUF_NULL;
3590 struct lu_fid parent_fid;
3597 if (!capable(CAP_DAC_READ_SEARCH) &&
3598 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
3601 if (get_user(name_size, &arg->gp_name_size))
3604 if (get_user(linkno, &arg->gp_linkno))
3607 if (name_size > PATH_MAX)
3610 OBD_ALLOC(ldata, sizeof(*ldata));
3614 rc = linkea_data_new(ldata, &buf);
3616 GOTO(ldata_free, rc);
3618 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3619 buf.lb_len, OBD_MD_FLXATTR);
3623 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3627 if (ln.ln_namelen >= name_size)
3628 GOTO(lb_free, rc = -EOVERFLOW);
3630 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3631 GOTO(lb_free, rc = -EFAULT);
3633 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3634 GOTO(lb_free, rc = -EFAULT);
3636 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3637 GOTO(lb_free, rc = -EFAULT);
3642 OBD_FREE(ldata, sizeof(*ldata));