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/delay.h>
40 #include <linux/file.h>
41 #include <linux/fs_struct.h>
43 #include <linux/module.h>
44 #include <linux/random.h>
45 #include <linux/statfs.h>
46 #include <linux/time.h>
47 #include <linux/types.h>
48 #include <linux/uaccess.h>
49 #include <linux/uidgid.h>
50 #include <linux/user_namespace.h>
51 #include <linux/uuid.h>
52 #include <linux/version.h>
53 #ifdef HAVE_FILEATTR_GET
54 #include <linux/fileattr.h>
57 #ifndef HAVE_CPUS_READ_LOCK
58 #include <libcfs/linux/linux-cpu.h>
60 #include <libcfs/linux/linux-misc.h>
61 #include <uapi/linux/lustre/lustre_ioctl.h>
62 #include <lustre_ioctl_old.h>
63 #ifdef HAVE_UAPI_LINUX_MOUNT_H
64 #include <uapi/linux/mount.h>
67 #include <lustre_ha.h>
68 #include <lustre_dlm.h>
69 #include <lprocfs_status.h>
70 #include <lustre_disk.h>
71 #include <uapi/linux/lustre/lustre_param.h>
72 #include <lustre_log.h>
73 #include <cl_object.h>
74 #include <obd_cksum.h>
75 #include "llite_internal.h"
77 struct kmem_cache *ll_file_data_slab;
80 #define log2(n) ffz(~(n))
84 * If there is only one number of core visible to Lustre,
85 * async readahead will be disabled, to avoid massive over
86 * subscription, we use 1/2 of active cores as default max
87 * async readahead requests.
89 static inline unsigned int ll_get_ra_async_max_active(void)
91 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
94 static struct ll_sb_info *ll_init_sbi(struct lustre_sb_info *lsi)
96 struct ll_sb_info *sbi = NULL;
98 unsigned long lru_page_max;
106 RETURN(ERR_PTR(-ENOMEM));
108 rc = pcc_super_init(&sbi->ll_pcc_super);
112 spin_lock_init(&sbi->ll_lock);
113 mutex_init(&sbi->ll_lco.lco_lock);
114 spin_lock_init(&sbi->ll_pp_extent_lock);
115 spin_lock_init(&sbi->ll_process_lock);
117 sbi->ll_rw_stats_on = 0;
118 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
121 pages = si.totalram - si.totalhigh;
122 lru_page_max = pages / 2;
124 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
125 sbi->ll_ra_info.ll_readahead_wq =
126 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
128 sbi->ll_ra_info.ra_async_max_active);
129 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
130 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
132 /* initialize ll_cache data */
133 sbi->ll_cache = cl_cache_init(lru_page_max);
134 if (sbi->ll_cache == NULL)
135 GOTO(out_destroy_ra, rc = -ENOMEM);
137 /* initialize foreign symlink prefix path */
138 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
139 if (sbi->ll_foreign_symlink_prefix == NULL)
140 GOTO(out_destroy_ra, rc = -ENOMEM);
141 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
142 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
144 /* initialize foreign symlink upcall path, none by default */
145 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
146 if (sbi->ll_foreign_symlink_upcall == NULL)
147 GOTO(out_destroy_ra, rc = -ENOMEM);
148 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
149 sbi->ll_foreign_symlink_upcall_items = NULL;
150 sbi->ll_foreign_symlink_upcall_nb_items = 0;
151 init_rwsem(&sbi->ll_foreign_symlink_sem);
152 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
153 * not enabled by default
156 sbi->ll_secctx_name = NULL;
157 sbi->ll_secctx_name_size = 0;
159 sbi->ll_ra_info.ra_max_pages =
160 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
161 sbi->ll_ra_info.ra_max_pages_per_file =
162 min(sbi->ll_ra_info.ra_max_pages / 4,
163 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
164 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
165 sbi->ll_ra_info.ra_max_pages_per_file;
166 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
167 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
168 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
170 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
171 #ifdef CONFIG_ENABLE_CHECKSUM
172 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
174 #ifdef CONFIG_ENABLE_FLOCK
175 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
178 #ifdef HAVE_LRU_RESIZE_SUPPORT
179 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
181 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
183 /* metadata statahead is enabled by default */
184 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
185 sbi->ll_sa_batch_max = LL_SA_BATCH_DEF;
186 sbi->ll_sa_max = LL_SA_RPC_DEF;
187 atomic_set(&sbi->ll_sa_total, 0);
188 atomic_set(&sbi->ll_sa_wrong, 0);
189 atomic_set(&sbi->ll_sa_running, 0);
190 atomic_set(&sbi->ll_agl_total, 0);
191 atomic_set(&sbi->ll_sa_hit_total, 0);
192 atomic_set(&sbi->ll_sa_miss_total, 0);
193 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
194 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
195 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
196 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
197 ll_sbi_set_encrypt(sbi, true);
198 ll_sbi_set_name_encrypt(sbi, true);
201 sbi->ll_squash.rsi_uid = 0;
202 sbi->ll_squash.rsi_gid = 0;
203 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
204 spin_lock_init(&sbi->ll_squash.rsi_lock);
206 /* Per-filesystem file heat */
207 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
208 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
210 /* Per-fs open heat level before requesting open lock */
211 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
212 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
213 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
216 if (sbi->ll_foreign_symlink_prefix)
217 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
219 cl_cache_decref(sbi->ll_cache);
220 sbi->ll_cache = NULL;
222 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
224 pcc_super_fini(&sbi->ll_pcc_super);
230 static void ll_free_sbi(struct super_block *sb)
232 struct ll_sb_info *sbi = ll_s2sbi(sb);
236 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
237 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
238 if (sbi->ll_ra_info.ll_readahead_wq)
239 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
240 if (sbi->ll_cache != NULL) {
241 cl_cache_decref(sbi->ll_cache);
242 sbi->ll_cache = NULL;
244 if (sbi->ll_foreign_symlink_prefix) {
245 OBD_FREE(sbi->ll_foreign_symlink_prefix,
246 sbi->ll_foreign_symlink_prefix_size);
247 sbi->ll_foreign_symlink_prefix = NULL;
249 if (sbi->ll_foreign_symlink_upcall) {
250 OBD_FREE(sbi->ll_foreign_symlink_upcall,
251 strlen(sbi->ll_foreign_symlink_upcall) +
253 sbi->ll_foreign_symlink_upcall = NULL;
255 if (sbi->ll_foreign_symlink_upcall_items) {
257 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
258 struct ll_foreign_symlink_upcall_item *items =
259 sbi->ll_foreign_symlink_upcall_items;
261 for (i = 0 ; i < nb_items; i++)
262 if (items[i].type == STRING_TYPE)
263 OBD_FREE(items[i].string,
266 OBD_FREE_LARGE(items, nb_items *
267 sizeof(struct ll_foreign_symlink_upcall_item));
268 sbi->ll_foreign_symlink_upcall_items = NULL;
270 if (sbi->ll_secctx_name)
271 ll_secctx_name_free(sbi);
273 ll_free_rw_stats_info(sbi);
274 pcc_super_fini(&sbi->ll_pcc_super);
275 OBD_FREE(sbi, sizeof(*sbi));
280 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
282 struct inode *root = NULL;
283 struct ll_sb_info *sbi = ll_s2sbi(sb);
284 struct obd_statfs *osfs = NULL;
285 struct ptlrpc_request *request = NULL;
286 struct obd_connect_data *data = NULL;
287 struct obd_uuid *uuid;
288 struct md_op_data *op_data;
289 struct lustre_md lmd;
291 int size, err, checksum;
297 sbi->ll_md_obd = class_name2obd(md);
298 if (!sbi->ll_md_obd) {
299 CERROR("MD %s: not setup or attached\n", md);
313 /* pass client page size via ocd_grant_blkbits, the server should report
314 * back its backend blocksize for grant calculation purpose */
315 data->ocd_grant_blkbits = PAGE_SHIFT;
317 /* indicate MDT features supported by this client */
318 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
319 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
320 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
321 OBD_CONNECT_SRVLOCK |
322 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
323 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
324 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
325 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
326 OBD_CONNECT_64BITHASH |
327 OBD_CONNECT_EINPROGRESS |
328 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
329 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
330 OBD_CONNECT_MAX_EASIZE |
331 OBD_CONNECT_FLOCK_DEAD |
332 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
333 OBD_CONNECT_OPEN_BY_FID |
334 OBD_CONNECT_DIR_STRIPE |
335 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
336 OBD_CONNECT_SUBTREE |
337 OBD_CONNECT_MULTIMODRPCS |
338 OBD_CONNECT_GRANT_PARAM |
339 OBD_CONNECT_GRANT_SHRINK |
340 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
342 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
343 OBD_CONNECT2_SUM_STATFS |
344 OBD_CONNECT2_OVERSTRIPING |
346 OBD_CONNECT2_LOCK_CONVERT |
347 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
348 OBD_CONNECT2_INC_XID |
350 OBD_CONNECT2_ASYNC_DISCARD |
352 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
353 OBD_CONNECT2_GETATTR_PFID |
354 OBD_CONNECT2_DOM_LVB |
355 OBD_CONNECT2_REP_MBITS |
356 OBD_CONNECT2_ATOMIC_OPEN_LOCK |
357 OBD_CONNECT2_BATCH_RPC |
358 OBD_CONNECT2_DMV_IMP_INHERIT;
360 #ifdef HAVE_LRU_RESIZE_SUPPORT
361 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
362 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
364 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
366 data->ocd_cksum_types = obd_cksum_types_supported_client();
368 if (CFS_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
369 /* flag mdc connection as lightweight, only used for test
370 * purpose, use with care */
371 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
373 data->ocd_ibits_known = MDS_INODELOCK_FULL;
374 data->ocd_version = LUSTRE_VERSION_CODE;
376 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
377 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
380 /* Setting this indicates we correctly support S_NOSEC (See kernel
381 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
383 sb->s_flags |= SB_NOSEC;
385 sbi->ll_fop = ll_select_file_operations(sbi);
387 /* always ping even if server suppress_pings */
388 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
389 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
391 obd_connect_set_secctx(data);
392 if (ll_sbi_has_encrypt(sbi)) {
393 obd_connect_set_enc_fid2path(data);
394 obd_connect_set_name_enc(data);
395 obd_connect_set_enc(data);
398 #if defined(CONFIG_SECURITY)
399 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
402 data->ocd_brw_size = MD_MAX_BRW_SIZE;
405 if (sb->s_flags & SB_RDONLY)
406 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
407 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
408 &sbi->ll_sb_uuid, data, sbi->ll_cache);
410 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
411 "recovery, of which this client is not a "
412 "part. Please wait for recovery to complete,"
413 " abort, or time out.\n", md);
416 CERROR("cannot connect to %s: rc = %d\n", md, err);
420 sbi->ll_md_exp->exp_connect_data = *data;
422 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
423 LUSTRE_SEQ_METADATA);
425 CERROR("%s: Can't init metadata layer FID infrastructure, "
426 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
430 /* For mount, we only need fs info from MDT0, and also in DNE, it
431 * can make sure the client can be mounted as long as MDT0 is
433 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
434 ktime_get_seconds() - sbi->ll_statfs_max_age,
435 OBD_STATFS_FOR_MDT0);
436 if (err == -EROFS && !(sb->s_flags & SB_RDONLY)) {
437 /* We got -EROFS from the server, maybe it is imposing
438 * read-only mount. So just retry like this.
440 cfs_tty_write_msg("Forcing read-only mount.\n\r");
441 CERROR("%s: mount failed with %d, forcing read-only mount.\n",
442 sbi->ll_md_exp->exp_obd->obd_name, err);
443 sb->s_flags |= SB_RDONLY;
444 obd_fid_fini(sbi->ll_md_exp->exp_obd);
445 obd_disconnect(sbi->ll_md_exp);
446 GOTO(retry_connect, err);
448 GOTO(out_md_fid, err);
451 /* This needs to be after statfs to ensure connect has finished.
452 * Note that "data" does NOT contain the valid connect reply.
453 * If connecting to a 1.8 server there will be no LMV device, so
454 * we can access the MDC export directly and exp_connect_flags will
455 * be non-zero, but if accessing an upgraded 2.1 server it will
456 * have the correct flags filled in.
457 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
458 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
459 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
460 valid != CLIENT_CONNECT_MDT_REQD) {
463 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
464 obd_connect_flags2str(buf, PAGE_SIZE,
465 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
466 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
467 "feature(s) needed for correct operation "
468 "of this client (%s). Please upgrade "
469 "server or downgrade client.\n",
470 sbi->ll_md_exp->exp_obd->obd_name, buf);
471 OBD_FREE(buf, PAGE_SIZE);
472 GOTO(out_md_fid, err = -EPROTO);
475 size = sizeof(*data);
476 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
477 KEY_CONN_DATA, &size, data);
479 CERROR("%s: Get connect data failed: rc = %d\n",
480 sbi->ll_md_exp->exp_obd->obd_name, err);
481 GOTO(out_md_fid, err);
484 LASSERT(osfs->os_bsize);
485 sb->s_blocksize = osfs->os_bsize;
486 sb->s_blocksize_bits = log2(osfs->os_bsize);
487 sb->s_magic = LL_SUPER_MAGIC;
488 sb->s_maxbytes = MAX_LFS_FILESIZE;
489 sbi->ll_inode_cache_enabled = 1;
490 sbi->ll_namelen = osfs->os_namelen;
491 sbi->ll_mnt.mnt = current->fs->root.mnt;
492 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
494 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
495 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
496 LCONSOLE_INFO("Disabling user_xattr feature because "
497 "it is not supported on the server\n");
498 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
501 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
503 sb->s_flags |= SB_POSIXACL;
505 set_bit(LL_SBI_ACL, sbi->ll_flags);
507 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
509 sb->s_flags &= ~SB_POSIXACL;
511 clear_bit(LL_SBI_ACL, sbi->ll_flags);
514 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
515 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
517 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
518 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
520 if (obd_connect_has_secctx(data))
521 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
523 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
524 if (ll_sb_has_test_dummy_encryption(sb))
525 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
527 sbi->ll_md_exp->exp_obd->obd_name);
528 ll_sbi_set_encrypt(sbi, false);
531 if (ll_sbi_has_name_encrypt(sbi) && !obd_connect_has_name_enc(data)) {
532 struct lustre_sb_info *lsi = s2lsi(sb);
534 if (ll_sb_has_test_dummy_encryption(sb))
535 LCONSOLE_WARN("%s: server %s does not support name encryption, not using it.\n",
537 sbi->ll_md_exp->exp_obd->obd_name);
538 #ifdef CONFIG_LL_ENCRYPTION
539 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
541 lsi->lsi_flags &= ~LSI_FILENAME_ENC_B64_OLD_CLI;
542 ll_sbi_set_name_encrypt(sbi, false);
545 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
546 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
547 LCONSOLE_INFO("%s: disabling xattr cache due to "
548 "unknown maximum xattr size.\n", dt);
549 } else if (!sbi->ll_xattr_cache_set) {
550 /* If xattr_cache is already set (no matter 0 or 1)
551 * during processing llog, it won't be enabled here. */
552 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
553 sbi->ll_xattr_cache_enabled = 1;
557 sbi->ll_dt_obd = class_name2obd(dt);
558 if (!sbi->ll_dt_obd) {
559 CERROR("DT %s: not setup or attached\n", dt);
560 GOTO(out_md_fid, err = -ENODEV);
563 /* pass client page size via ocd_grant_blkbits, the server should report
564 * back its backend blocksize for grant calculation purpose */
565 data->ocd_grant_blkbits = PAGE_SHIFT;
567 /* indicate OST features supported by this client */
568 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
569 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
570 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
571 OBD_CONNECT_SRVLOCK |
572 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
573 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
574 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
575 OBD_CONNECT_EINPROGRESS |
576 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
577 OBD_CONNECT_LAYOUTLOCK |
578 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
579 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
580 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
581 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
582 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
583 OBD_CONNECT2_REP_MBITS;
585 if (!CFS_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
586 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
588 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
589 * disabled by default, because it can still be enabled on the
590 * fly via /sys. As a consequence, we still need to come to an
591 * agreement on the supported algorithms at connect time
593 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
595 if (CFS_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
596 data->ocd_cksum_types = OBD_CKSUM_ADLER;
598 data->ocd_cksum_types = obd_cksum_types_supported_client();
600 #ifdef HAVE_LRU_RESIZE_SUPPORT
601 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
603 /* always ping even if server suppress_pings */
604 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
605 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
607 if (ll_sbi_has_encrypt(sbi))
608 obd_connect_set_enc(data);
610 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
611 "ocd_grant: %d\n", data->ocd_connect_flags,
612 data->ocd_version, data->ocd_grant);
614 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
615 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
617 data->ocd_brw_size = DT_MAX_BRW_SIZE;
619 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
620 &sbi->ll_sb_uuid, data, sbi->ll_cache);
622 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
623 "recovery, of which this client is not a "
624 "part. Please wait for recovery to "
625 "complete, abort, or time out.\n", dt);
628 CERROR("%s: Cannot connect to %s: rc = %d\n",
629 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
633 if (ll_sbi_has_encrypt(sbi) &&
634 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
635 if (ll_sb_has_test_dummy_encryption(sb))
636 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
638 ll_sbi_set_encrypt(sbi, false);
639 } else if (ll_sb_has_test_dummy_encryption(sb)) {
640 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
643 sbi->ll_dt_exp->exp_connect_data = *data;
645 /* Don't change value if it was specified in the config log */
646 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
647 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
648 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
649 (data->ocd_brw_size >> PAGE_SHIFT));
650 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
651 sbi->ll_ra_info.ra_max_pages_per_file)
652 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
653 sbi->ll_ra_info.ra_max_pages_per_file;
656 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
657 LUSTRE_SEQ_METADATA);
659 CERROR("%s: Can't init data layer FID infrastructure, "
660 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
664 mutex_lock(&sbi->ll_lco.lco_lock);
665 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
666 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
667 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
668 mutex_unlock(&sbi->ll_lco.lco_lock);
670 fid_zero(&sbi->ll_root_fid);
671 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
674 CERROR("cannot mds_connect: rc = %d\n", err);
675 GOTO(out_lock_cn_cb, err);
677 if (!fid_is_sane(&sbi->ll_root_fid)) {
678 CERROR("%s: Invalid root fid "DFID" during mount\n",
679 sbi->ll_md_exp->exp_obd->obd_name,
680 PFID(&sbi->ll_root_fid));
681 GOTO(out_lock_cn_cb, err = -EINVAL);
683 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
685 sb->s_op = &lustre_super_operations;
686 sb->s_xattr = ll_xattr_handlers;
687 #if THREAD_SIZE >= 8192 /*b=17630*/
688 sb->s_export_op = &lustre_export_operations;
690 #ifdef HAVE_LUSTRE_CRYPTO
691 llcrypt_set_ops(sb, &lustre_cryptops);
695 * XXX: move this to after cbd setup? */
696 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
698 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
699 valid |= OBD_MD_FLACL;
701 OBD_ALLOC_PTR(op_data);
703 GOTO(out_lock_cn_cb, err = -ENOMEM);
705 op_data->op_fid1 = sbi->ll_root_fid;
706 op_data->op_mode = 0;
707 op_data->op_valid = valid;
709 err = md_getattr(sbi->ll_md_exp, op_data, &request);
711 /* We need enc ctx info, so reset it in op_data to
712 * prevent it from being freed.
714 encctx = op_data->op_file_encctx;
715 encctxlen = op_data->op_file_encctx_size;
716 op_data->op_file_encctx = NULL;
717 op_data->op_file_encctx_size = 0;
718 OBD_FREE_PTR(op_data);
720 CERROR("%s: md_getattr failed for root: rc = %d\n",
721 sbi->ll_md_exp->exp_obd->obd_name, err);
722 GOTO(out_lock_cn_cb, err);
725 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
726 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
728 CERROR("failed to understand root inode md: rc = %d\n", err);
729 ptlrpc_req_finished(request);
730 GOTO(out_lock_cn_cb, err);
733 LASSERT(fid_is_sane(&sbi->ll_root_fid));
734 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
735 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
736 md_put_lustre_md(sbi->ll_md_exp, &lmd);
740 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
742 CERROR("%s: bad ll_iget() for root: rc = %d\n",
743 sbi->ll_fsname, err);
744 ptlrpc_req_finished(request);
748 err = ll_secctx_name_store(root);
749 if (err < 0 && ll_security_xattr_wanted(root))
750 CWARN("%s: file security contextes not supported: rc = %d\n",
751 sbi->ll_fsname, err);
756 "server returned encryption ctx for root inode "DFID"\n",
757 PFID(&sbi->ll_root_fid));
758 err = ll_set_encflags(root, encctx, encctxlen, true);
760 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
762 PFID(&sbi->ll_root_fid), err);
764 ptlrpc_req_finished(request);
766 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
767 if (sbi->ll_checksum_set) {
768 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
769 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
770 sizeof(checksum), &checksum, NULL);
772 CERROR("%s: Set checksum failed: rc = %d\n",
773 sbi->ll_dt_exp->exp_obd->obd_name, err);
779 sb->s_root = d_make_root(root);
780 if (sb->s_root == NULL) {
782 CERROR("%s: can't make root dentry: rc = %d\n",
783 sbi->ll_fsname, err);
787 sbi->ll_sdev_orig = sb->s_dev;
789 /* We set sb->s_dev equal on all lustre clients in order to support
790 * NFS export clustering. NFSD requires that the FSID be the same
792 /* s_dev is also used in lt_compare() to compare two fs, but that is
793 * only a node-local comparison. */
794 uuid = obd_get_uuid(sbi->ll_md_exp);
796 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
803 if (sbi->ll_dt_obd) {
804 err = sysfs_create_link(&sbi->ll_kset.kobj,
805 &sbi->ll_dt_obd->obd_kset.kobj,
806 sbi->ll_dt_obd->obd_type->typ_name);
808 CERROR("%s: could not register %s in llite: rc = %d\n",
809 dt, sbi->ll_fsname, err);
814 if (sbi->ll_md_obd) {
815 err = sysfs_create_link(&sbi->ll_kset.kobj,
816 &sbi->ll_md_obd->obd_kset.kobj,
817 sbi->ll_md_obd->obd_type->typ_name);
819 CERROR("%s: could not register %s in llite: rc = %d\n",
820 md, sbi->ll_fsname, err);
829 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
831 obd_disconnect(sbi->ll_dt_exp);
832 sbi->ll_dt_exp = NULL;
833 sbi->ll_dt_obd = NULL;
835 obd_fid_fini(sbi->ll_md_exp->exp_obd);
837 obd_disconnect(sbi->ll_md_exp);
838 sbi->ll_md_exp = NULL;
839 sbi->ll_md_obd = NULL;
848 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
852 size = sizeof(*lmmsize);
853 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
854 KEY_MAX_EASIZE, &size, lmmsize);
856 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
857 sbi->ll_dt_exp->exp_obd->obd_name, rc);
861 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
864 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
865 KEY_MAX_EASIZE, &size, lmmsize);
867 CERROR("Get max mdsize error rc %d\n", rc);
869 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
875 * Get the value of the default_easize parameter.
877 * \see client_obd::cl_default_mds_easize
879 * \param[in] sbi superblock info for this filesystem
880 * \param[out] lmmsize pointer to storage location for value
882 * \retval 0 on success
883 * \retval negative negated errno on failure
885 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
890 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
891 KEY_DEFAULT_EASIZE, &size, lmmsize);
893 CERROR("Get default mdsize error rc %d\n", rc);
899 * Set the default_easize parameter to the given value.
901 * \see client_obd::cl_default_mds_easize
903 * \param[in] sbi superblock info for this filesystem
904 * \param[in] lmmsize the size to set
906 * \retval 0 on success
907 * \retval negative negated errno on failure
909 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
913 if (lmmsize < sizeof(struct lov_mds_md) ||
914 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
917 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
918 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
919 sizeof(int), &lmmsize, NULL);
924 static void client_common_put_super(struct super_block *sb)
926 struct ll_sb_info *sbi = ll_s2sbi(sb);
931 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
932 obd_disconnect(sbi->ll_dt_exp);
933 sbi->ll_dt_exp = NULL;
935 ll_debugfs_unregister_super(sb);
937 obd_fid_fini(sbi->ll_md_exp->exp_obd);
938 obd_disconnect(sbi->ll_md_exp);
939 sbi->ll_md_exp = NULL;
944 void ll_kill_super(struct super_block *sb)
946 struct ll_sb_info *sbi;
950 if (!(sb->s_flags & SB_ACTIVE))
954 /* we need restore s_dev from changed for clustred NFS before put_super
955 * because new kernels have cached s_dev and change sb->s_dev in
956 * put_super not affected real removing devices */
958 sb->s_dev = sbi->ll_sdev_orig;
960 /* wait running statahead threads to quit */
961 while (atomic_read(&sbi->ll_sa_running) > 0)
962 schedule_timeout_uninterruptible(
963 cfs_time_seconds(1) >> 3);
969 /* Since we use this table for ll_sbi_flags_seq_show make
970 * sure what you want displayed for a specific token that
971 * is listed more than once below be listed first. For
972 * example we want "checksum" displayed, not "nochecksum"
975 static const match_table_t ll_sbi_flags_name = {
976 {LL_SBI_NOLCK, "nolock"},
977 {LL_SBI_CHECKSUM, "checksum"},
978 {LL_SBI_CHECKSUM, "nochecksum"},
979 {LL_SBI_LOCALFLOCK, "localflock"},
980 {LL_SBI_FLOCK, "flock"},
981 {LL_SBI_FLOCK, "noflock"},
982 {LL_SBI_USER_XATTR, "user_xattr"},
983 {LL_SBI_USER_XATTR, "nouser_xattr"},
984 {LL_SBI_LRU_RESIZE, "lruresize"},
985 {LL_SBI_LRU_RESIZE, "nolruresize"},
986 {LL_SBI_LAZYSTATFS, "lazystatfs"},
987 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
988 {LL_SBI_32BIT_API, "32bitapi"},
989 {LL_SBI_USER_FID2PATH, "user_fid2path"},
990 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
991 {LL_SBI_VERBOSE, "verbose"},
992 {LL_SBI_VERBOSE, "noverbose"},
993 {LL_SBI_ALWAYS_PING, "always_ping"},
994 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
995 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
996 {LL_SBI_ENCRYPT, "encrypt"},
997 {LL_SBI_ENCRYPT, "noencrypt"},
998 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
999 {LL_SBI_NUM_MOUNT_OPT, NULL},
1001 {LL_SBI_ACL, "acl"},
1002 {LL_SBI_AGL_ENABLED, "agl"},
1003 {LL_SBI_64BIT_HASH, "64bit_hash"},
1004 {LL_SBI_LAYOUT_LOCK, "layout"},
1005 {LL_SBI_XATTR_CACHE, "xattr_cache"},
1006 {LL_SBI_NOROOTSQUASH, "norootsquash"},
1007 {LL_SBI_FAST_READ, "fast_read"},
1008 {LL_SBI_FILE_SECCTX, "file_secctx"},
1009 {LL_SBI_TINY_WRITE, "tiny_write"},
1010 {LL_SBI_FILE_HEAT, "file_heat"},
1011 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
1012 {LL_SBI_ENCRYPT_NAME, "name_encrypt"},
1015 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
1017 struct super_block *sb = m->private;
1020 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
1023 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
1026 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
1027 if (ll_sbi_flags_name[j].token == i &&
1028 ll_sbi_flags_name[j].pattern) {
1029 seq_printf(m, "%s ",
1030 ll_sbi_flags_name[j].pattern);
1035 seq_puts(m, "\b\n");
1039 /* non-client-specific mount options are parsed in lmd_parse */
1040 static int ll_options(char *options, struct super_block *sb)
1042 struct ll_sb_info *sbi = ll_s2sbi(sb);
1043 char *s2, *s1, *opts;
1050 /* Don't stomp on lmd_opts */
1051 opts = kstrdup(options, GFP_KERNEL);
1057 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1059 while ((s1 = strsep(&opts, ",")) != NULL) {
1060 substring_t args[MAX_OPT_ARGS];
1061 bool turn_off = false;
1067 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1069 if (strncmp(s1, "no", 2) == 0)
1073 * Initialize args struct so we know whether arg was
1074 * found; some options take optional arguments.
1077 args[0].from = NULL;
1078 token = match_token(s1, ll_sbi_flags_name, args);
1079 if (token == LL_SBI_NUM_MOUNT_OPT) {
1080 if (match_wildcard("context", s1) ||
1081 match_wildcard("fscontext", s1) ||
1082 match_wildcard("defcontext", s1) ||
1083 match_wildcard("rootcontext",s1))
1086 LCONSOLE_ERROR_MSG(0x152,
1087 "Unknown option '%s', won't mount.\n",
1094 case LL_SBI_32BIT_API:
1095 case LL_SBI_64BIT_HASH:
1096 case LL_SBI_ALWAYS_PING:
1097 set_bit(token, sbi->ll_flags);
1101 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1103 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1105 set_bit(token, sbi->ll_flags);
1108 case LL_SBI_LOCALFLOCK:
1109 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1110 set_bit(token, sbi->ll_flags);
1113 case LL_SBI_CHECKSUM:
1114 sbi->ll_checksum_set = 1;
1116 case LL_SBI_USER_XATTR:
1117 case LL_SBI_USER_FID2PATH:
1118 case LL_SBI_LRU_RESIZE:
1119 case LL_SBI_LAZYSTATFS:
1120 case LL_SBI_VERBOSE:
1122 clear_bit(token, sbi->ll_flags);
1124 set_bit(token, sbi->ll_flags);
1126 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1127 #ifdef HAVE_LUSTRE_CRYPTO
1128 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1129 set_bit(token, sbi->ll_flags);
1131 struct lustre_sb_info *lsi = s2lsi(sb);
1133 err = llcrypt_set_test_dummy_encryption(sb,
1134 #ifdef HAVE_FSCRYPT_SET_TEST_DUMMY_ENC_CHAR_ARG
1139 &lsi->lsi_dummy_enc_policy);
1145 "Can't change test_dummy_encryption");
1146 else if (err == -EINVAL)
1148 "Value of option \"%s\" unrecognized",
1152 "Error processing option \"%s\" [%d]",
1157 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1161 case LL_SBI_ENCRYPT:
1162 #ifdef HAVE_LUSTRE_CRYPTO
1164 clear_bit(token, sbi->ll_flags);
1166 set_bit(token, sbi->ll_flags);
1168 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1171 case LL_SBI_FOREIGN_SYMLINK:
1172 /* non-default prefix provided ? */
1177 /* path must be absolute */
1178 if (args->from[0] != '/') {
1179 LCONSOLE_ERROR_MSG(0x152,
1180 "foreign prefix '%s' must be an absolute path\n",
1185 old_len = sbi->ll_foreign_symlink_prefix_size;
1186 old = sbi->ll_foreign_symlink_prefix;
1187 /* alloc for path length and '\0' */
1188 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1189 if (!sbi->ll_foreign_symlink_prefix) {
1190 /* restore previous */
1191 sbi->ll_foreign_symlink_prefix = old;
1192 sbi->ll_foreign_symlink_prefix_size =
1196 sbi->ll_foreign_symlink_prefix_size =
1197 args->to - args->from + 1;
1198 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1199 sbi->ll_foreign_symlink_prefix_size,
1202 OBD_FREE(old, old_len);
1204 /* enable foreign symlink support */
1205 set_bit(token, sbi->ll_flags);
1207 LCONSOLE_ERROR_MSG(0x152,
1208 "invalid %s option\n", s1);
1219 void ll_lli_init(struct ll_inode_info *lli)
1221 lli->lli_inode_magic = LLI_INODE_MAGIC;
1223 rwlock_init(&lli->lli_lock);
1224 lli->lli_posix_acl = NULL;
1225 /* Do not set lli_fid, it has been initialized already. */
1226 fid_zero(&lli->lli_pfid);
1227 lli->lli_mds_read_och = NULL;
1228 lli->lli_mds_write_och = NULL;
1229 lli->lli_mds_exec_och = NULL;
1230 lli->lli_open_fd_read_count = 0;
1231 lli->lli_open_fd_write_count = 0;
1232 lli->lli_open_fd_exec_count = 0;
1233 mutex_init(&lli->lli_och_mutex);
1234 spin_lock_init(&lli->lli_agl_lock);
1235 spin_lock_init(&lli->lli_layout_lock);
1236 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1237 lli->lli_clob = NULL;
1239 init_rwsem(&lli->lli_xattrs_list_rwsem);
1240 mutex_init(&lli->lli_xattrs_enq_lock);
1242 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1243 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1244 lli->lli_opendir_key = NULL;
1245 lli->lli_sai = NULL;
1246 spin_lock_init(&lli->lli_sa_lock);
1247 lli->lli_opendir_pid = 0;
1248 lli->lli_sa_enabled = 0;
1249 init_rwsem(&lli->lli_lsm_sem);
1251 mutex_init(&lli->lli_size_mutex);
1252 mutex_init(&lli->lli_setattr_mutex);
1253 lli->lli_symlink_name = NULL;
1254 ll_trunc_sem_init(&lli->lli_trunc_sem);
1255 range_lock_tree_init(&lli->lli_write_tree);
1256 init_rwsem(&lli->lli_glimpse_sem);
1257 lli->lli_glimpse_time = ktime_set(0, 0);
1258 INIT_LIST_HEAD(&lli->lli_agl_list);
1259 lli->lli_agl_index = 0;
1260 lli->lli_async_rc = 0;
1261 spin_lock_init(&lli->lli_heat_lock);
1262 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1263 lli->lli_heat_flags = 0;
1264 mutex_init(&lli->lli_pcc_lock);
1265 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1266 lli->lli_pcc_inode = NULL;
1267 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1268 lli->lli_pcc_generation = 0;
1269 mutex_init(&lli->lli_group_mutex);
1270 lli->lli_group_users = 0;
1271 lli->lli_group_gid = 0;
1272 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1273 lli->lli_uid = (__u32) -1;
1274 lli->lli_gid = (__u32) -1;
1276 mutex_init(&lli->lli_layout_mutex);
1277 lli->lli_layout_lock_owner = NULL;
1278 /* ll_cl_context initialize */
1279 INIT_LIST_HEAD(&lli->lli_lccs);
1280 seqlock_init(&lli->lli_page_inv_lock);
1281 lli->lli_inode_lock_owner = NULL;
1284 #define MAX_STRING_SIZE 128
1286 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1287 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1289 struct lustre_sb_info *lsi = s2lsi(sb);
1290 char buf[MAX_STRING_SIZE];
1294 err = bdi_init(&lsi->lsi_bdi);
1298 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1299 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1300 lsi->lsi_bdi.name = "lustre";
1301 va_start(args, fmt);
1302 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1304 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1307 sb->s_bdi = &lsi->lsi_bdi;
1311 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1313 int ll_fill_super(struct super_block *sb)
1315 struct lustre_profile *lprof = NULL;
1316 struct lustre_sb_info *lsi = s2lsi(sb);
1317 struct ll_sb_info *sbi = NULL;
1318 char *dt = NULL, *md = NULL;
1319 char *profilenm = get_profile_name(sb);
1320 struct config_llog_instance *cfg;
1321 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1322 const int instlen = LUSTRE_MAXINSTANCE + 2;
1323 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1324 char name[MAX_STRING_SIZE];
1333 /* for ASLR, to map between cfg_instance and hashed ptr */
1334 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1335 profilenm, cfg_instance, sb);
1337 CFS_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1341 GOTO(out_free_cfg, err = -ENOMEM);
1343 /* client additional sb info */
1344 lsi->lsi_llsbi = sbi = ll_init_sbi(lsi);
1346 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1348 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1350 GOTO(out_free_cfg, err);
1352 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1353 #ifdef CONFIG_LL_ENCRYPTION
1354 if (ll_sb_has_test_dummy_encryption(sb))
1355 /* enable filename encryption by default for dummy enc mode */
1356 lsi->lsi_flags |= LSI_FILENAME_ENC;
1358 /* filename encryption is disabled by default */
1359 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1362 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1363 sb->s_d_op = &ll_d_ops;
1366 generate_random_uuid(uuid.b);
1367 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1369 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1372 len = strlen(profilenm);
1373 ptr = strrchr(profilenm, '-');
1374 if (ptr && (strcmp(ptr, "-client") == 0))
1377 if (len > LUSTRE_MAXFSNAME) {
1378 if (unlikely(len >= MAX_STRING_SIZE))
1379 len = MAX_STRING_SIZE - 1;
1380 strncpy(name, profilenm, len);
1382 err = -ENAMETOOLONG;
1383 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1384 name, LUSTRE_MAXFSNAME, err);
1385 GOTO(out_free_cfg, err);
1387 strncpy(sbi->ll_fsname, profilenm, len);
1388 sbi->ll_fsname[len] = '\0';
1391 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1392 profilenm, cfg_instance);
1394 err = super_setup_bdi_name(sb, "%s", name);
1396 GOTO(out_free_cfg, err);
1398 /* disable kernel readahead */
1399 sb->s_bdi->ra_pages = 0;
1400 #ifdef HAVE_BDI_IO_PAGES
1401 sb->s_bdi->io_pages = 0;
1403 sb->s_bdi->capabilities |= LL_BDI_CAP_FLAGS;
1405 /* Call ll_debugfs_register_super() before lustre_process_log()
1406 * so that "llite.*.*" params can be processed correctly.
1408 err = ll_debugfs_register_super(sb, name);
1410 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1411 sbi->ll_fsname, err);
1415 /* The cfg_instance is a value unique to this super, in case some
1416 * joker tries to mount the same fs at two mount points.
1418 cfg->cfg_instance = cfg_instance;
1419 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1420 cfg->cfg_callback = class_config_llog_handler;
1421 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1422 /* set up client obds */
1423 err = lustre_process_log(sb, profilenm, cfg);
1425 GOTO(out_debugfs, err);
1427 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1428 lprof = class_get_profile(profilenm);
1429 if (lprof == NULL) {
1430 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1431 " read from the MGS. Does that filesystem "
1432 "exist?\n", profilenm);
1433 GOTO(out_debugfs, err = -EINVAL);
1435 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1436 lprof->lp_md, lprof->lp_dt);
1438 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1439 OBD_ALLOC(dt, dt_len);
1441 GOTO(out_profile, err = -ENOMEM);
1442 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1444 md_len = strlen(lprof->lp_md) + instlen + 2;
1445 OBD_ALLOC(md, md_len);
1447 GOTO(out_free_dt, err = -ENOMEM);
1448 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1450 /* connections, registrations, sb setup */
1451 err = client_common_fill_super(sb, md, dt);
1453 GOTO(out_free_md, err);
1455 sbi->ll_client_common_fill_super_succeeded = 1;
1459 OBD_FREE(md, md_len);
1462 OBD_FREE(dt, dt_len);
1465 class_put_profile(lprof);
1468 ll_debugfs_unregister_super(sb);
1475 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1476 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1477 sb->s_flags & SB_RDONLY ? " read-only" : "");
1479 } /* ll_fill_super */
1481 void ll_put_super(struct super_block *sb)
1483 struct config_llog_instance cfg, params_cfg;
1484 struct obd_device *obd;
1485 struct lustre_sb_info *lsi = s2lsi(sb);
1486 struct ll_sb_info *sbi = ll_s2sbi(sb);
1487 char *profilenm = get_profile_name(sb);
1488 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1489 int next, force = 1;
1494 GOTO(out_no_sbi, 0);
1496 /* Should replace instance_id with something better for ASLR */
1497 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1498 profilenm, cfg_instance, sb);
1500 cfg.cfg_instance = cfg_instance;
1501 lustre_end_log(sb, profilenm, &cfg);
1503 params_cfg.cfg_instance = cfg_instance;
1504 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1506 if (sbi->ll_md_exp) {
1507 obd = class_exp2obd(sbi->ll_md_exp);
1509 force = obd->obd_force;
1512 /* We need to set force before the lov_disconnect in
1513 * lustre_common_put_super, since l_d cleans up osc's as well.
1517 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1519 obd->obd_force = force;
1523 if (sbi->ll_client_common_fill_super_succeeded) {
1524 /* Only if client_common_fill_super succeeded */
1525 client_common_put_super(sb);
1528 /* imitate failed cleanup */
1529 if (CFS_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1533 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1534 class_manual_cleanup(obd);
1537 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1538 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1541 class_del_profile(profilenm);
1543 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1544 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1545 bdi_destroy(&lsi->lsi_bdi);
1546 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1550 llcrypt_free_dummy_policy(&lsi->lsi_dummy_enc_policy);
1552 lsi->lsi_llsbi = NULL;
1554 lustre_common_put_super(sb);
1556 cl_env_cache_purge(~0);
1559 } /* client_put_super */
1561 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1563 struct inode *inode = NULL;
1565 /* NOTE: we depend on atomic igrab() -bzzz */
1566 lock_res_and_lock(lock);
1567 if (lock->l_resource->lr_lvb_inode) {
1568 struct ll_inode_info * lli;
1569 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1570 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1571 inode = igrab(lock->l_resource->lr_lvb_inode);
1573 inode = lock->l_resource->lr_lvb_inode;
1574 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1575 D_WARNING, lock, "lr_lvb_inode %p is "
1576 "bogus: magic %08x",
1577 lock->l_resource->lr_lvb_inode,
1578 lli->lli_inode_magic);
1582 unlock_res_and_lock(lock);
1586 void ll_dir_clear_lsm_md(struct inode *inode)
1588 struct ll_inode_info *lli = ll_i2info(inode);
1590 LASSERT(S_ISDIR(inode->i_mode));
1591 down_write(&lli->lli_lsm_sem);
1592 lmv_stripe_object_put(&lli->lli_lsm_obj);
1593 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1594 up_write(&lli->lli_lsm_sem);
1597 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1598 const struct lu_fid *fid,
1599 struct lustre_md *md)
1601 struct ll_sb_info *sbi = ll_s2sbi(sb);
1602 struct ll_inode_info *lli;
1603 struct mdt_body *body = md->body;
1604 struct inode *inode;
1609 LASSERT(md->lsm_obj);
1610 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1611 inode = iget_locked(sb, ino);
1612 if (inode == NULL) {
1613 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1614 sbi->ll_fsname, PFID(fid));
1615 RETURN(ERR_PTR(-ENOENT));
1618 lli = ll_i2info(inode);
1619 if (inode->i_state & I_NEW) {
1620 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1621 (body->mbo_mode & S_IFMT);
1622 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1625 inode->i_mtime.tv_sec = 0;
1626 inode->i_atime.tv_sec = 0;
1627 inode->i_ctime.tv_sec = 0;
1630 #ifdef HAVE_BACKING_DEV_INFO
1631 /* initializing backing dev info. */
1632 inode->i_mapping->backing_dev_info =
1633 &s2lsi(inode->i_sb)->lsi_bdi;
1635 inode->i_op = &ll_dir_inode_operations;
1636 inode->i_fop = &ll_dir_operations;
1637 lli->lli_fid = *fid;
1640 /* master object FID */
1641 lli->lli_pfid = body->mbo_fid1;
1642 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1643 lli, PFID(fid), PFID(&lli->lli_pfid));
1644 unlock_new_inode(inode);
1646 /* in directory restripe/auto-split, a directory will be
1647 * transformed to a stripe if it's plain, set its pfid here,
1648 * otherwise ll_lock_cancel_bits() can't find the master inode.
1650 lli->lli_pfid = body->mbo_fid1;
1656 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1659 struct lmv_stripe_md *lsm;
1660 struct ll_inode_info *lli = ll_i2info(inode);
1663 LASSERT(md->lsm_obj != NULL);
1664 lsm = &md->lsm_obj->lso_lsm;
1666 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1667 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1668 lmv_stripe_object_dump(D_INODE, md->lsm_obj);
1670 if (!lmv_dir_striped(md->lsm_obj))
1673 /* XXX sigh, this lsm_root initialization should be in
1674 * LMV layer, but it needs ll_iget right now, so we
1675 * put this here right now. */
1676 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1677 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1678 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1680 if (!fid_is_sane(fid))
1683 /* Unfortunately ll_iget will call ll_update_inode,
1684 * where the initialization of slave inode is slightly
1685 * different, so it reset lsm_md to NULL to avoid
1686 * initializing lsm for slave inode. */
1687 lsm->lsm_md_oinfo[i].lmo_root =
1688 ll_iget_anon_dir(inode->i_sb, fid, md);
1689 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1690 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1692 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1694 iput(lsm->lsm_md_oinfo[i].lmo_root);
1695 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1701 /* move lsm_obj to lli */
1702 lli->lli_lsm_obj = md->lsm_obj;
1707 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1709 struct ll_inode_info *lli = ll_i2info(inode);
1710 struct lmv_stripe_object *lsm_obj = md->def_lsm_obj;
1714 /* clear default lsm */
1715 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set) {
1716 down_write(&lli->lli_lsm_sem);
1717 if (lli->lli_def_lsm_obj_set) {
1718 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1719 lli->lli_inherit_depth = 0;
1720 lli->lli_def_lsm_obj_set = 0;
1722 up_write(&lli->lli_lsm_sem);
1727 if (lli->lli_def_lsm_obj) {
1728 /* do nonthing if default lsm isn't changed */
1729 down_read(&lli->lli_lsm_sem);
1730 if (lli->lli_def_lsm_obj &&
1731 lsm_md_eq(lli->lli_def_lsm_obj, lsm_obj)) {
1732 up_read(&lli->lli_lsm_sem);
1735 up_read(&lli->lli_lsm_sem);
1737 down_write(&lli->lli_lsm_sem);
1739 /* update default lsm. */
1740 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1741 lli->lli_def_lsm_obj = lsm_obj;
1742 lli->lli_def_lsm_obj_set = 1;
1743 lmv_stripe_object_dump(D_INODE, lsm_obj);
1744 md->def_lsm_obj = NULL;
1745 up_write(&lli->lli_lsm_sem);
1749 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1751 struct ll_inode_info *lli = ll_i2info(inode);
1752 struct lmv_stripe_object *lsm_obj = md->lsm_obj;
1753 struct cl_attr *attr;
1758 LASSERT(S_ISDIR(inode->i_mode));
1759 CDEBUG(D_INODE, "update lsm_obj %p of "DFID"\n", lli->lli_lsm_obj,
1760 PFID(ll_inode2fid(inode)));
1762 /* update default LMV */
1763 if (md->def_lsm_obj)
1764 ll_update_default_lsm_md(inode, md);
1766 /* after dir migration/restripe, a stripe may be turned into a
1767 * directory, in this case, zero out its lli_pfid.
1769 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1770 fid_zero(&lli->lli_pfid);
1773 * no striped information from request, lustre_md from req does not
1774 * include stripeEA, see ll_md_setattr()
1780 * normally dir layout doesn't change, only take read lock to check
1781 * that to avoid blocking other MD operations.
1783 down_read(&lli->lli_lsm_sem);
1785 /* some current lookup initialized lsm, and unchanged */
1786 if (lli->lli_lsm_obj && lsm_md_eq(lli->lli_lsm_obj, lsm_obj)) {
1787 up_read(&lli->lli_lsm_sem);
1791 up_read(&lli->lli_lsm_sem);
1792 down_write(&lli->lli_lsm_sem);
1794 /* check again in case of a race */
1795 if (lli->lli_lsm_obj && lsm_md_eq(lli->lli_lsm_obj, lsm_obj))
1796 GOTO(unlock, rc = 0);
1798 /* if dir layout doesn't match, check whether version is increased,
1799 * which means layout is changed, this happens in dir split/merge and
1802 * foreign LMV should not change.
1804 if (lli->lli_lsm_obj && lmv_dir_striped(lli->lli_lsm_obj) &&
1805 lsm_obj->lso_lsm.lsm_md_layout_version <=
1806 lli->lli_lsm_obj->lso_lsm.lsm_md_layout_version) {
1807 CERROR("%s: "DFID" dir layout mismatch:\n",
1808 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1809 lmv_stripe_object_dump(D_ERROR, lli->lli_lsm_obj);
1810 lmv_stripe_object_dump(D_ERROR, lsm_obj);
1811 GOTO(unlock, rc = -EINVAL);
1814 /* clear existing lsm */
1815 lmv_stripe_object_put(&lli->lli_lsm_obj);
1817 rc = ll_init_lsm_md(inode, md);
1821 if (!lmv_dir_striped(lli->lli_lsm_obj))
1822 GOTO(unlock, rc = 0);
1824 lsm_obj = lmv_stripe_object_get(lli->lli_lsm_obj);
1825 up_write(&lli->lli_lsm_sem);
1827 OBD_ALLOC_PTR(attr);
1829 GOTO(err, rc = -ENOMEM);
1831 /* validate the lsm */
1832 rc = md_merge_attr(ll_i2mdexp(inode), lsm_obj, attr,
1833 ll_md_blocking_ast);
1835 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1836 md->body->mbo_nlink = attr->cat_nlink;
1837 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1838 md->body->mbo_size = attr->cat_size;
1839 if (md->body->mbo_valid & OBD_MD_FLATIME)
1840 md->body->mbo_atime = attr->cat_atime;
1841 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1842 md->body->mbo_ctime = attr->cat_ctime;
1843 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1844 md->body->mbo_mtime = attr->cat_mtime;
1850 lmv_stripe_object_put(&lsm_obj);
1853 up_write(&lli->lli_lsm_sem);
1857 void ll_clear_inode(struct inode *inode)
1859 struct ll_inode_info *lli = ll_i2info(inode);
1860 struct ll_sb_info *sbi = ll_i2sbi(inode);
1864 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1865 PFID(ll_inode2fid(inode)), inode);
1867 if (S_ISDIR(inode->i_mode)) {
1868 /* these should have been cleared in ll_file_release */
1869 LASSERT(lli->lli_opendir_key == NULL);
1870 LASSERT(lli->lli_sai == NULL);
1871 LASSERT(lli->lli_opendir_pid == 0);
1873 pcc_inode_free(inode);
1876 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1878 LASSERT(!lli->lli_open_fd_write_count);
1879 LASSERT(!lli->lli_open_fd_read_count);
1880 LASSERT(!lli->lli_open_fd_exec_count);
1882 if (lli->lli_mds_write_och)
1883 ll_md_real_close(inode, FMODE_WRITE);
1884 if (lli->lli_mds_exec_och)
1885 ll_md_real_close(inode, FMODE_EXEC);
1886 if (lli->lli_mds_read_och)
1887 ll_md_real_close(inode, FMODE_READ);
1889 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1890 OBD_FREE(lli->lli_symlink_name,
1891 strlen(lli->lli_symlink_name) + 1);
1892 lli->lli_symlink_name = NULL;
1895 ll_xattr_cache_destroy(inode);
1897 forget_all_cached_acls(inode);
1899 lli->lli_inode_magic = LLI_INODE_DEAD;
1901 if (S_ISDIR(inode->i_mode))
1902 ll_dir_clear_lsm_md(inode);
1903 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1904 LASSERT(list_empty(&lli->lli_agl_list));
1907 * XXX This has to be done before lsm is freed below, because
1908 * cl_object still uses inode lsm.
1910 cl_inode_fini(inode);
1912 llcrypt_put_encryption_info(inode);
1917 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1919 struct lustre_md md;
1920 struct inode *inode = dentry->d_inode;
1921 struct ll_sb_info *sbi = ll_i2sbi(inode);
1922 struct ptlrpc_request *request = NULL;
1927 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1928 LUSTRE_OPC_ANY, NULL);
1929 if (IS_ERR(op_data))
1930 RETURN(PTR_ERR(op_data));
1932 /* If this is a chgrp of a regular file, we want to reserve enough
1933 * quota to cover the entire file size.
1935 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1936 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1937 from_kgid(&init_user_ns, inode->i_gid)) {
1938 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1939 op_data->op_attr_blocks = inode->i_blocks;
1943 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1945 ptlrpc_req_finished(request);
1946 if (rc == -ENOENT) {
1948 /* Unlinked special device node? Or just a race?
1949 * Pretend we done everything. */
1950 if (!S_ISREG(inode->i_mode) &&
1951 !S_ISDIR(inode->i_mode)) {
1952 ia_valid = op_data->op_attr.ia_valid;
1953 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1954 rc = simple_setattr(&nop_mnt_idmap, dentry,
1956 op_data->op_attr.ia_valid = ia_valid;
1958 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1959 CERROR("md_setattr fails: rc = %d\n", rc);
1964 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1965 sbi->ll_md_exp, &md);
1967 ptlrpc_req_finished(request);
1971 ia_valid = op_data->op_attr.ia_valid;
1972 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1973 * cache is not cleared yet. */
1974 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1975 if (S_ISREG(inode->i_mode))
1976 ll_inode_lock(inode);
1977 rc = simple_setattr(&nop_mnt_idmap, dentry, &op_data->op_attr);
1978 if (S_ISREG(inode->i_mode))
1979 ll_inode_unlock(inode);
1980 op_data->op_attr.ia_valid = ia_valid;
1982 rc = ll_update_inode(inode, &md);
1983 ptlrpc_req_finished(request);
1984 md_put_lustre_md(sbi->ll_md_exp, &md);
1990 * Zero portion of page that is part of @inode.
1991 * This implies, if necessary:
1992 * - taking cl_lock on range corresponding to concerned page
1993 * - grabbing vm page
1994 * - associating cl_page
1995 * - proceeding to clio read
1996 * - zeroing range in page
1997 * - proceeding to cl_page flush
1998 * - releasing cl_lock
2000 * \param[in] inode inode
2001 * \param[in] index page index
2002 * \param[in] offset offset in page to start zero from
2003 * \param[in] len len to zero
2005 * \retval 0 on success
2006 * \retval negative errno on failure
2008 static int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
2011 struct ll_inode_info *lli = ll_i2info(inode);
2012 struct cl_object *clob = lli->lli_clob;
2014 struct lu_env *env = NULL;
2015 struct cl_io *io = NULL;
2016 struct cl_page *clpage = NULL;
2017 struct page *vmpage = NULL;
2018 unsigned from = index << PAGE_SHIFT;
2019 struct cl_lock *lock = NULL;
2020 struct cl_lock_descr *descr = NULL;
2021 struct cl_2queue *queue = NULL;
2022 struct cl_sync_io *anchor = NULL;
2023 bool holdinglock = false;
2028 env = cl_env_get(&refcheck);
2030 RETURN(PTR_ERR(env));
2032 io = vvp_env_thread_io(env);
2034 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2038 lock = vvp_env_lock(env);
2039 descr = &lock->cll_descr;
2040 descr->cld_obj = io->ci_obj;
2041 descr->cld_start = from >> PAGE_SHIFT;
2042 descr->cld_end = (from + PAGE_SIZE - 1) >> PAGE_SHIFT;
2043 descr->cld_mode = CLM_WRITE;
2044 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2046 /* request lock for page */
2047 rc = cl_lock_request(env, io, lock);
2048 /* -ECANCELED indicates a matching lock with a different extent
2049 * was already present, and -EEXIST indicates a matching lock
2050 * on exactly the same extent was already present.
2051 * In both cases it means we are covered.
2053 if (rc == -ECANCELED || rc == -EEXIST)
2061 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2063 GOTO(rellock, rc = -EOPNOTSUPP);
2065 if (!PageDirty(vmpage)) {
2066 /* associate cl_page */
2067 clpage = cl_page_find(env, clob, vmpage->index,
2068 vmpage, CPT_CACHEABLE);
2070 GOTO(pagefini, rc = PTR_ERR(clpage));
2072 cl_page_assume(env, io, clpage);
2075 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2076 !PageWriteback(vmpage)) {
2078 /* Set PagePrivate2 to detect special case of empty page
2079 * in osc_brw_fini_request().
2080 * It is also used to tell ll_io_read_page() that we do not
2081 * want the vmpage to be unlocked.
2083 SetPagePrivate2(vmpage);
2084 rc = ll_io_read_page(env, io, clpage, NULL);
2085 if (!PagePrivate2(vmpage)) {
2086 /* PagePrivate2 was cleared in osc_brw_fini_request()
2087 * meaning we read an empty page. In this case, in order
2088 * to avoid allocating unnecessary block in truncated
2089 * file, we must not zero and write as below. Subsequent
2090 * server-side truncate will handle things correctly.
2092 cl_page_unassume(env, io, clpage);
2093 GOTO(clpfini, rc = 0);
2095 ClearPagePrivate2(vmpage);
2100 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2101 * the vmpage, so we are good to proceed and zero range in page.
2103 zero_user(vmpage, offset, len);
2105 if (holdinglock && clpage) {
2106 /* explicitly write newly modified page */
2107 queue = &io->ci_queue;
2108 cl_2queue_init(queue);
2109 anchor = &vvp_env_info(env)->vti_anchor;
2110 cl_sync_io_init(anchor, 1);
2111 clpage->cp_sync_io = anchor;
2112 cl_page_list_add(&queue->c2_qin, clpage, true);
2113 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2115 GOTO(queuefini1, rc);
2116 rc = cl_sync_io_wait(env, anchor, 0);
2118 GOTO(queuefini2, rc);
2119 cl_page_assume(env, io, clpage);
2122 cl_2queue_discard(env, io, queue);
2124 cl_2queue_disown(env, queue);
2125 cl_2queue_fini(env, queue);
2130 cl_page_put(env, clpage);
2132 unlock_page(vmpage);
2136 cl_lock_release(env, lock);
2138 cl_io_fini(env, io);
2141 cl_env_put(env, &refcheck);
2147 * Get reference file from volatile file name.
2148 * Volatile file name may look like:
2149 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2150 * where fd is opened descriptor of reference file.
2152 * \param[in] volatile_name volatile file name
2153 * \param[in] volatile_len volatile file name length
2154 * \param[out] ref_file pointer to struct file of reference file
2156 * \retval 0 on success
2157 * \retval negative errno on failure
2159 int volatile_ref_file(const char *volatile_name, int volatile_len,
2160 struct file **ref_file)
2162 char *p, *q, *fd_str;
2165 p = strnstr(volatile_name, ":fd=", volatile_len);
2166 if (!p || strlen(p + 4) == 0)
2169 q = strchrnul(p + 4, ':');
2170 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2173 rc = kstrtouint(fd_str, 10, &fd);
2178 *ref_file = fget(fd);
2184 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2185 * object(s) determine the file size and mtime. Otherwise, the MDS will
2186 * keep these values until such a time that objects are allocated for it.
2187 * We do the MDS operations first, as it is checking permissions for us.
2188 * We don't to the MDS RPC if there is nothing that we want to store there,
2189 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2190 * going to do an RPC anyways.
2192 * If we are doing a truncate, we will send the mtime and ctime updates
2193 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2194 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2197 * In case of HSMimport, we only set attr on MDS.
2199 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2200 enum op_xvalid xvalid, bool hsm_import)
2202 struct inode *inode = dentry->d_inode;
2203 struct ll_inode_info *lli = ll_i2info(inode);
2204 struct md_op_data *op_data = NULL;
2205 ktime_t kstart = ktime_get();
2210 /* VFS has locked the inode before calling this */
2211 ll_set_inode_lock_owner(inode);
2213 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2214 "valid %x, hsm_import %d\n",
2215 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2216 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2219 if (attr->ia_valid & ATTR_SIZE) {
2220 /* Check new size against VFS/VM file size limit and rlimit */
2221 rc = inode_newsize_ok(inode, attr->ia_size);
2225 /* The maximum Lustre file size is variable, based on the
2226 * OST maximum object size and number of stripes. This
2227 * needs another check in addition to the VFS check above. */
2228 if (attr->ia_size > ll_file_maxbytes(inode)) {
2229 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2230 PFID(&lli->lli_fid), attr->ia_size,
2231 ll_file_maxbytes(inode));
2232 GOTO(clear, rc = -EFBIG);
2235 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2238 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2239 if (attr->ia_valid & TIMES_SET_FLAGS) {
2240 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2241 !capable(CAP_FOWNER))
2242 GOTO(clear, rc = -EPERM);
2245 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2246 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2247 (attr->ia_valid & ATTR_CTIME)) {
2248 attr->ia_ctime = current_time(inode);
2249 xvalid |= OP_XVALID_CTIME_SET;
2251 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2252 (attr->ia_valid & ATTR_ATIME)) {
2253 attr->ia_atime = current_time(inode);
2254 attr->ia_valid |= ATTR_ATIME_SET;
2256 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2257 (attr->ia_valid & ATTR_MTIME)) {
2258 attr->ia_mtime = current_time(inode);
2259 attr->ia_valid |= ATTR_MTIME_SET;
2262 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2263 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2264 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2265 ktime_get_real_seconds());
2267 if (S_ISREG(inode->i_mode))
2268 ll_inode_unlock(inode);
2270 /* We always do an MDS RPC, even if we're only changing the size;
2271 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2273 OBD_ALLOC_PTR(op_data);
2274 if (op_data == NULL)
2275 GOTO(out, rc = -ENOMEM);
2277 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2278 /* If we are changing file size, file content is
2279 * modified, flag it.
2281 xvalid |= OP_XVALID_OWNEROVERRIDE;
2282 op_data->op_bias |= MDS_DATA_MODIFIED;
2283 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2286 if (attr->ia_valid & ATTR_FILE) {
2287 struct ll_file_data *fd = attr->ia_file->private_data;
2289 if (fd->fd_lease_och)
2290 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2293 op_data->op_attr = *attr;
2294 op_data->op_xvalid = xvalid;
2296 rc = ll_md_setattr(dentry, op_data);
2299 lli->lli_synced_to_mds = false;
2301 if (!S_ISREG(inode->i_mode) || hsm_import)
2304 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2305 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2306 xvalid & OP_XVALID_CTIME_SET) {
2307 bool cached = false;
2309 rc = pcc_inode_setattr(inode, attr, &cached);
2312 CERROR("%s: PCC inode "DFID" setattr failed: "
2314 ll_i2sbi(inode)->ll_fsname,
2315 PFID(&lli->lli_fid), rc);
2319 unsigned int flags = 0;
2321 /* For truncate and utimes sending attributes to OSTs,
2322 * setting mtime/atime to the past will be performed
2323 * under PW [0:EOF] extent lock (new_size:EOF for
2324 * truncate). It may seem excessive to send mtime/atime
2325 * updates to OSTs when not setting times to past, but
2326 * it is necessary due to possible time
2327 * de-synchronization between MDT inode and OST objects
2329 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2330 xvalid |= OP_XVALID_FLAGS;
2331 flags = LUSTRE_ENCRYPT_FL;
2332 /* Call to ll_io_zero_page is not necessary if
2333 * truncating on PAGE_SIZE boundary, because
2334 * whole pages will be wiped.
2335 * In case of Direct IO, all we need is to set
2338 if (attr->ia_valid & ATTR_SIZE &&
2339 attr->ia_size & ~PAGE_MASK &&
2340 !(attr->ia_valid & ATTR_FILE &&
2341 attr->ia_file->f_flags & O_DIRECT)) {
2343 attr->ia_size & (PAGE_SIZE - 1);
2345 rc = ll_io_zero_page(inode,
2346 attr->ia_size >> PAGE_SHIFT,
2347 offset, PAGE_SIZE - offset);
2351 /* If encrypted volatile file without the key,
2352 * we need to fetch size from reference file,
2353 * and set it on OST objects. This happens when
2354 * migrating or extending an encrypted file
2357 if (filename_is_volatile(dentry->d_name.name,
2360 llcrypt_require_key(inode) == -ENOKEY) {
2361 struct file *ref_file;
2362 struct inode *ref_inode;
2363 struct ll_inode_info *ref_lli;
2364 struct cl_object *ref_obj;
2365 struct cl_attr ref_attr = { 0 };
2369 rc = volatile_ref_file(
2370 dentry->d_name.name,
2376 ref_inode = file_inode(ref_file);
2379 GOTO(out, rc = -EINVAL);
2382 env = cl_env_get(&refcheck);
2384 GOTO(out, rc = PTR_ERR(env));
2386 ref_lli = ll_i2info(ref_inode);
2387 ref_obj = ref_lli->lli_clob;
2388 cl_object_attr_lock(ref_obj);
2389 rc = cl_object_attr_get(env, ref_obj,
2391 cl_object_attr_unlock(ref_obj);
2392 cl_env_put(env, &refcheck);
2397 attr->ia_valid |= ATTR_SIZE;
2398 attr->ia_size = ref_attr.cat_size;
2401 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2405 /* If the file was restored, it needs to set dirty flag.
2407 * We've already sent MDS_DATA_MODIFIED flag in
2408 * ll_md_setattr() for truncate. However, the MDT refuses to
2409 * set the HS_DIRTY flag on released files, so we have to set
2410 * it again if the file has been restored. Please check how
2411 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2413 * Please notice that if the file is not released, the previous
2414 * MDS_DATA_MODIFIED has taken effect and usually
2415 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2416 * This way we can save an RPC for common open + trunc
2418 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2419 struct hsm_state_set hss = {
2420 .hss_valid = HSS_SETMASK,
2421 .hss_setmask = HS_DIRTY,
2425 rc2 = ll_hsm_state_set(inode, &hss);
2426 /* truncate and write can happen at the same time, so that
2427 * the file can be set modified even though the file is not
2428 * restored from released state, and ll_hsm_state_set() is
2429 * not applicable for the file, and rc2 < 0 is normal in this
2432 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2433 PFID(ll_inode2fid(inode)), rc2);
2438 if (op_data != NULL)
2439 ll_finish_md_op_data(op_data);
2441 if (S_ISREG(inode->i_mode)) {
2442 ll_inode_lock(inode);
2443 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2444 inode_dio_wait(inode);
2445 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2446 * flag. ll_update_inode (called from ll_md_setattr), clears
2447 * inode flags, so there is a gap where S_NOSEC is not set.
2448 * This can cause a writer to take the i_mutex unnecessarily,
2449 * but this is safe to do and should be rare. */
2450 inode_has_no_xattr(inode);
2454 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2455 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2456 ktime_us_delta(ktime_get(), kstart));
2458 ll_clear_inode_lock_owner(inode);
2463 int ll_setattr(struct mnt_idmap *map, struct dentry *de, struct iattr *attr)
2465 int mode = de->d_inode->i_mode;
2466 enum op_xvalid xvalid = 0;
2469 rc = llcrypt_prepare_setattr(de, attr);
2473 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2474 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2475 xvalid |= OP_XVALID_OWNEROVERRIDE;
2477 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2478 (ATTR_SIZE|ATTR_MODE)) &&
2479 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2480 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2481 !(attr->ia_mode & S_ISGID))))
2482 attr->ia_valid |= ATTR_FORCE;
2484 if ((attr->ia_valid & ATTR_MODE) &&
2486 !(attr->ia_mode & S_ISUID) &&
2487 !(attr->ia_valid & ATTR_KILL_SUID))
2488 attr->ia_valid |= ATTR_KILL_SUID;
2490 if ((attr->ia_valid & ATTR_MODE) &&
2491 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2492 !(attr->ia_mode & S_ISGID) &&
2493 !(attr->ia_valid & ATTR_KILL_SGID))
2494 attr->ia_valid |= ATTR_KILL_SGID;
2496 return ll_setattr_raw(de, attr, xvalid, false);
2499 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2502 struct obd_statfs obd_osfs = { 0 };
2507 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2509 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2510 flags |= OBD_STATFS_NODELAY;
2512 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2516 osfs->os_type = LL_SUPER_MAGIC;
2518 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2519 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2521 if (osfs->os_state & OS_STATFS_SUM)
2524 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2525 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2528 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2529 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2532 osfs->os_bsize = obd_osfs.os_bsize;
2533 osfs->os_blocks = obd_osfs.os_blocks;
2534 osfs->os_bfree = obd_osfs.os_bfree;
2535 osfs->os_bavail = obd_osfs.os_bavail;
2537 /* If we have _some_ OSTs, but don't have as many free objects on the
2538 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2539 * to compensate, so that the "inodes in use" number is correct.
2540 * This should be kept in sync with lod_statfs() behaviour.
2542 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2543 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2545 osfs->os_ffree = obd_osfs.os_ffree;
2552 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2554 struct if_quotactl qctl = {
2555 .qc_cmd = LUSTRE_Q_GETQUOTA,
2556 .qc_type = PRJQUOTA,
2557 .qc_valid = QC_GENERAL,
2559 u64 limit, curblock;
2562 qctl.qc_id = ll_i2info(inode)->lli_projid;
2563 ret = quotactl_ioctl(inode->i_sb, &qctl);
2565 /* ignore errors if project ID does not have
2566 * a quota limit or feature unsupported.
2568 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2573 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2574 qctl.qc_dqblk.dqb_bsoftlimit :
2575 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2576 if (limit && sfs->f_blocks > limit) {
2577 curblock = (qctl.qc_dqblk.dqb_curspace +
2578 sfs->f_bsize - 1) / sfs->f_bsize;
2579 sfs->f_blocks = limit;
2580 sfs->f_bfree = sfs->f_bavail =
2581 (sfs->f_blocks > curblock) ?
2582 (sfs->f_blocks - curblock) : 0;
2585 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2586 qctl.qc_dqblk.dqb_isoftlimit :
2587 qctl.qc_dqblk.dqb_ihardlimit;
2588 if (limit && sfs->f_files > limit) {
2589 sfs->f_files = limit;
2590 sfs->f_ffree = (sfs->f_files >
2591 qctl.qc_dqblk.dqb_curinodes) ?
2592 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2598 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2600 struct super_block *sb = de->d_sb;
2601 struct obd_statfs osfs;
2602 __u64 fsid = huge_encode_dev(sb->s_dev);
2603 ktime_t kstart = ktime_get();
2606 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2608 /* Some amount of caching on the client is allowed */
2609 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2613 statfs_unpack(sfs, &osfs);
2615 /* We need to downshift for all 32-bit kernels, because we can't
2616 * tell if the kernel is being called via sys_statfs64() or not.
2617 * Stop before overflowing f_bsize - in which case it is better
2618 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2619 if (sizeof(long) < 8) {
2620 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2623 osfs.os_blocks >>= 1;
2624 osfs.os_bfree >>= 1;
2625 osfs.os_bavail >>= 1;
2629 sfs->f_blocks = osfs.os_blocks;
2630 sfs->f_bfree = osfs.os_bfree;
2631 sfs->f_bavail = osfs.os_bavail;
2632 sfs->f_fsid.val[0] = (__u32)fsid;
2633 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2634 if (ll_i2info(de->d_inode)->lli_projid &&
2635 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2636 return ll_statfs_project(de->d_inode, sfs);
2638 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2639 ktime_us_delta(ktime_get(), kstart));
2644 void ll_inode_size_lock(struct inode *inode)
2646 struct ll_inode_info *lli;
2648 LASSERT(!S_ISDIR(inode->i_mode));
2650 lli = ll_i2info(inode);
2651 mutex_lock(&lli->lli_size_mutex);
2652 lli->lli_size_lock_owner = current;
2655 void ll_inode_size_unlock(struct inode *inode)
2657 struct ll_inode_info *lli;
2659 lli = ll_i2info(inode);
2660 lli->lli_size_lock_owner = NULL;
2661 mutex_unlock(&lli->lli_size_mutex);
2664 int ll_inode_size_trylock(struct inode *inode)
2666 struct ll_inode_info *lli;
2668 LASSERT(!S_ISDIR(inode->i_mode));
2670 lli = ll_i2info(inode);
2671 return mutex_trylock(&lli->lli_size_mutex);
2674 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2676 /* do not clear encryption flag */
2677 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2678 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2679 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2680 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2682 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2685 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2687 struct ll_inode_info *lli = ll_i2info(inode);
2688 struct mdt_body *body = md->body;
2689 struct ll_sb_info *sbi = ll_i2sbi(inode);
2693 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2694 rc = cl_file_inode_init(inode, md);
2699 if (S_ISDIR(inode->i_mode)) {
2700 rc = ll_update_lsm_md(inode, md);
2705 if (body->mbo_valid & OBD_MD_FLACL)
2706 lli_replace_acl(lli, md);
2708 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2709 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2710 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2712 if (body->mbo_valid & OBD_MD_FLATIME) {
2713 if (body->mbo_atime > inode->i_atime.tv_sec)
2714 inode->i_atime.tv_sec = body->mbo_atime;
2715 lli->lli_atime = body->mbo_atime;
2718 if (body->mbo_valid & OBD_MD_FLMTIME) {
2719 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2721 "setting ino %lu mtime from %lld to %llu\n",
2722 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2724 inode->i_mtime.tv_sec = body->mbo_mtime;
2726 lli->lli_mtime = body->mbo_mtime;
2729 if (body->mbo_valid & OBD_MD_FLCTIME) {
2730 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2731 inode->i_ctime.tv_sec = body->mbo_ctime;
2732 lli->lli_ctime = body->mbo_ctime;
2735 if (body->mbo_valid & OBD_MD_FLBTIME)
2736 lli->lli_btime = body->mbo_btime;
2738 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2739 if (body->mbo_valid & OBD_MD_FLFLAGS)
2740 ll_update_inode_flags(inode, body->mbo_flags);
2741 if (body->mbo_valid & OBD_MD_FLMODE)
2742 inode->i_mode = (inode->i_mode & S_IFMT) |
2743 (body->mbo_mode & ~S_IFMT);
2745 if (body->mbo_valid & OBD_MD_FLTYPE)
2746 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2747 (body->mbo_mode & S_IFMT);
2749 LASSERT(inode->i_mode != 0);
2750 if (body->mbo_valid & OBD_MD_FLUID)
2751 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2752 if (body->mbo_valid & OBD_MD_FLGID)
2753 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2754 if (body->mbo_valid & OBD_MD_FLPROJID)
2755 lli->lli_projid = body->mbo_projid;
2756 if (body->mbo_valid & OBD_MD_FLNLINK) {
2757 spin_lock(&inode->i_lock);
2758 set_nlink(inode, body->mbo_nlink);
2759 spin_unlock(&inode->i_lock);
2761 if (body->mbo_valid & OBD_MD_FLRDEV)
2762 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2764 if (body->mbo_valid & OBD_MD_FLID) {
2765 /* FID shouldn't be changed! */
2766 if (fid_is_sane(&lli->lli_fid)) {
2767 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2768 "Trying to change FID "DFID
2769 " to the "DFID", inode "DFID"(%p)\n",
2770 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2771 PFID(ll_inode2fid(inode)), inode);
2773 lli->lli_fid = body->mbo_fid1;
2777 LASSERT(fid_seq(&lli->lli_fid) != 0);
2779 /* In case of encrypted file without the key, please do not lose
2780 * clear text size stored into lli_lazysize in ll_merge_attr(),
2781 * we will need it in ll_prepare_close().
2783 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2784 llcrypt_require_key(inode) == -ENOKEY)
2785 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2787 lli->lli_attr_valid = body->mbo_valid;
2788 if (body->mbo_valid & OBD_MD_FLSIZE) {
2789 i_size_write(inode, body->mbo_size);
2791 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2792 PFID(ll_inode2fid(inode)),
2793 (unsigned long long)body->mbo_size);
2795 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2796 inode->i_blocks = body->mbo_blocks;
2798 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2799 lli->lli_lazysize = body->mbo_size;
2800 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2801 lli->lli_lazyblocks = body->mbo_blocks;
2804 if (body->mbo_valid & OBD_MD_TSTATE) {
2805 /* Set LLIF_FILE_RESTORING if restore ongoing and
2806 * clear it when done to ensure to start again
2807 * glimpsing updated attrs
2809 if (body->mbo_t_state & MS_RESTORE)
2810 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2812 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2818 /* child default LMV is inherited from parent */
2819 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2820 struct lmv_stripe_md *cdmv)
2825 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2826 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2827 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2828 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2831 if (cdmv->lsm_md_max_inherit !=
2832 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2835 if (cdmv->lsm_md_max_inherit_rr !=
2836 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2842 /* if default LMV is implicitly inherited, subdir default LMV is maintained on
2845 static int ll_dir_default_lmv_inherit(struct inode *dir, struct inode *inode)
2847 struct ll_inode_info *plli = ll_i2info(dir);
2848 struct ll_inode_info *lli = ll_i2info(inode);
2849 struct lmv_stripe_object *plsm_obj;
2850 struct lmv_stripe_object *lsm_obj;
2855 /* ROOT default LMV is not inherited */
2856 if (is_root_inode(dir) ||
2857 !(exp_connect_flags2(ll_i2mdexp(dir)) &
2858 OBD_CONNECT2_DMV_IMP_INHERIT))
2861 /* nothing to do if no default LMV on both */
2862 if (!plli->lli_def_lsm_obj && !lli->lli_def_lsm_obj)
2865 /* subdir default LMV comes from disk */
2866 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set)
2869 /* delete subdir default LMV if parent's is deleted or becomes
2872 down_read(&plli->lli_lsm_sem);
2873 plsm_obj = plli->lli_def_lsm_obj;
2875 !lmv_is_inheritable(plsm_obj->lso_lsm.lsm_md_max_inherit)) {
2876 if (lli->lli_def_lsm_obj && !lli->lli_def_lsm_obj_set) {
2877 down_write(&lli->lli_lsm_sem);
2878 if (!lli->lli_def_lsm_obj_set) {
2879 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
2880 lli->lli_inherit_depth = 0;
2882 up_write(&lli->lli_lsm_sem);
2884 GOTO(unlock_parent, rc = 0);
2887 /* do nothing if inherited LMV is unchanged */
2888 if (lli->lli_def_lsm_obj) {
2890 down_read(&lli->lli_lsm_sem);
2891 if (!lli->lli_def_lsm_obj_set)
2892 rc = lmv_object_inherited(plsm_obj,
2893 lli->lli_def_lsm_obj);
2894 up_read(&lli->lli_lsm_sem);
2896 GOTO(unlock_parent, rc = 0);
2899 /* inherit default LMV */
2900 down_write(&lli->lli_lsm_sem);
2901 if (lli->lli_def_lsm_obj) {
2902 /* checked above, but in case of race, check again with lock */
2903 if (lli->lli_def_lsm_obj_set)
2904 GOTO(unlock_child, rc = 0);
2905 /* always update subdir default LMV in case parent's changed */
2906 lsm_obj = lli->lli_def_lsm_obj;
2908 lsm_obj = lmv_stripe_object_alloc(LMV_USER_MAGIC, NULL, 0);
2909 if (IS_ERR(lsm_obj))
2910 GOTO(unlock_child, rc = PTR_ERR(lsm_obj));
2911 lli->lli_def_lsm_obj = lsm_obj;
2914 lsm_obj->lso_lsm = plsm_obj->lso_lsm;
2915 lsm_obj->lso_lsm.lsm_md_max_inherit =
2916 lmv_inherit_next(plsm_obj->lso_lsm.lsm_md_max_inherit);
2917 lsm_obj->lso_lsm.lsm_md_max_inherit_rr =
2918 lmv_inherit_rr_next(plsm_obj->lso_lsm.lsm_md_max_inherit_rr);
2919 lli->lli_inherit_depth = plli->lli_inherit_depth + 1;
2921 lmv_stripe_object_dump(D_INODE, lsm_obj);
2925 up_write(&lli->lli_lsm_sem);
2927 up_read(&plli->lli_lsm_sem);
2932 enum lsm_sem_class {
2938 * Update directory depth and default LMV
2940 * Update directory depth to ROOT and inherit default LMV from parent if
2941 * parent's default LMV is inheritable. The default LMV set with command
2942 * "lfs setdirstripe -D ..." is stored on MDT, while the inherited default LMV
2943 * is generated at runtime on client side.
2945 * \param[in] dir parent directory inode
2946 * \param[in] de dentry
2948 void ll_update_dir_depth_dmv(struct inode *dir, struct dentry *de)
2950 struct inode *inode = de->d_inode;
2951 struct ll_inode_info *plli;
2952 struct ll_inode_info *lli;
2954 LASSERT(S_ISDIR(inode->i_mode));
2958 plli = ll_i2info(dir);
2959 lli = ll_i2info(inode);
2960 lli->lli_dir_depth = plli->lli_dir_depth + 1;
2961 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set) {
2962 if (plli->lli_def_lsm_obj) {
2963 down_read_nested(&plli->lli_lsm_sem, LSM_SEM_PARENT);
2964 down_read_nested(&lli->lli_lsm_sem, LSM_SEM_CHILD);
2965 if (lmv_object_inherited(plli->lli_def_lsm_obj,
2966 lli->lli_def_lsm_obj))
2967 lli->lli_inherit_depth =
2968 plli->lli_inherit_depth + 1;
2970 /* in case parent default LMV changed */
2971 lli->lli_inherit_depth = 0;
2972 up_read(&lli->lli_lsm_sem);
2973 up_read(&plli->lli_lsm_sem);
2975 /* in case parent default LMV deleted */
2976 lli->lli_inherit_depth = 0;
2979 ll_dir_default_lmv_inherit(dir, inode);
2982 if (lli->lli_def_lsm_obj)
2984 "%s "DFID" depth %hu %s default LMV inherit depth %hu\n",
2985 de->d_name.name, PFID(&lli->lli_fid), lli->lli_dir_depth,
2986 lli->lli_def_lsm_obj_set ? "server" : "client",
2987 lli->lli_inherit_depth);
2990 void ll_truncate_inode_pages_final(struct inode *inode)
2992 struct address_space *mapping = &inode->i_data;
2993 unsigned long nrpages;
2994 unsigned long flags;
2996 LASSERTF((inode->i_state & I_FREEING) || inode_is_locked(inode),
2997 DFID ":inode %p state %#lx, lli_flags %#lx\n",
2998 PFID(ll_inode2fid(inode)), inode, inode->i_state,
2999 ll_i2info(inode)->lli_flags);
3001 truncate_inode_pages_final(mapping);
3003 /* Workaround for LU-118: Note nrpages may not be totally updated when
3004 * truncate_inode_pages() returns, as there can be a page in the process
3005 * of deletion (inside __delete_from_page_cache()) in the specified
3006 * range. Thus mapping->nrpages can be non-zero when this function
3007 * returns even after truncation of the whole mapping. Only do this if
3008 * npages isn't already zero.
3010 nrpages = mapping->nrpages;
3012 ll_xa_lock_irqsave(&mapping->i_pages, flags);
3013 nrpages = mapping->nrpages;
3014 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
3015 } /* Workaround end */
3017 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu "
3018 "state %#lx, lli_flags %#lx, "
3019 "see https://jira.whamcloud.com/browse/LU-118\n",
3020 ll_i2sbi(inode)->ll_fsname,
3021 PFID(ll_inode2fid(inode)), inode, nrpages,
3022 inode->i_state, ll_i2info(inode)->lli_flags);
3025 int ll_read_inode2(struct inode *inode, void *opaque)
3027 struct lustre_md *md = opaque;
3028 struct ll_inode_info *lli = ll_i2info(inode);
3032 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
3033 PFID(&lli->lli_fid), inode);
3035 /* Core attributes from the MDS first. This is a new inode, and
3036 * the VFS doesn't zero times in the core inode so we have to do
3037 * it ourselves. They will be overwritten by either MDS or OST
3038 * attributes - we just need to make sure they aren't newer.
3040 inode->i_mtime.tv_sec = 0;
3041 inode->i_atime.tv_sec = 0;
3042 inode->i_ctime.tv_sec = 0;
3044 rc = ll_update_inode(inode, md);
3048 /* OIDEBUG(inode); */
3050 #ifdef HAVE_BACKING_DEV_INFO
3051 /* initializing backing dev info. */
3052 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
3054 if (S_ISREG(inode->i_mode)) {
3055 struct ll_sb_info *sbi = ll_i2sbi(inode);
3056 inode->i_op = &ll_file_inode_operations;
3057 inode->i_fop = sbi->ll_fop;
3058 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
3060 } else if (S_ISDIR(inode->i_mode)) {
3061 inode->i_op = &ll_dir_inode_operations;
3062 inode->i_fop = &ll_dir_operations;
3064 } else if (S_ISLNK(inode->i_mode)) {
3065 inode->i_op = &ll_fast_symlink_inode_operations;
3068 inode->i_op = &ll_special_inode_operations;
3070 init_special_inode(inode, inode->i_mode,
3079 void ll_delete_inode(struct inode *inode)
3081 struct ll_inode_info *lli = ll_i2info(inode);
3084 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
3085 /* It is last chance to write out dirty pages,
3086 * otherwise we may lose data while umount.
3088 * If i_nlink is 0 then just discard data. This is safe because
3089 * local inode gets i_nlink 0 from server only for the last
3090 * unlink, so that file is not opened somewhere else
3092 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
3093 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
3096 ll_truncate_inode_pages_final(inode);
3097 ll_clear_inode(inode);
3103 static int fileattr_get(struct inode *inode, int *flags,
3107 struct ll_sb_info *sbi = ll_i2sbi(inode);
3108 struct ptlrpc_request *req = NULL;
3109 struct md_op_data *op_data;
3110 struct mdt_body *body;
3114 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
3115 0, 0, LUSTRE_OPC_ANY,
3117 if (IS_ERR(op_data))
3118 RETURN(PTR_ERR(op_data));
3120 op_data->op_valid = OBD_MD_FLFLAGS;
3121 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
3122 ll_finish_md_op_data(op_data);
3124 CERROR("%s: failure inode "DFID": rc = %d\n",
3125 sbi->ll_md_exp->exp_obd->obd_name,
3126 PFID(ll_inode2fid(inode)), rc);
3130 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3132 *flags = body->mbo_flags;
3133 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
3134 * ext4 equivalent to please lsattr and other e2fsprogs tools
3136 if (*flags & LUSTRE_ENCRYPT_FL)
3137 *flags |= STATX_ATTR_ENCRYPTED;
3139 ptlrpc_req_finished(req);
3141 *xflags = ll_inode_flags_to_xflags(inode->i_flags);
3142 if (test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags))
3143 *xflags |= FS_XFLAG_PROJINHERIT;
3144 *projid = ll_i2info(inode)->lli_projid;
3149 static int fileattr_set(struct inode *inode, int flags)
3151 struct ll_sb_info *sbi = ll_i2sbi(inode);
3152 struct ptlrpc_request *req = NULL;
3153 struct md_op_data *op_data;
3154 struct cl_object *obj;
3155 struct fsxattr fa = { 0 };
3160 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3161 if (flags & LUSTRE_PROJINHERIT_FL)
3162 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3164 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3169 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3170 LUSTRE_OPC_ANY, NULL);
3171 if (IS_ERR(op_data))
3172 RETURN(PTR_ERR(op_data));
3174 op_data->op_attr_flags = flags;
3175 op_data->op_xvalid |= OP_XVALID_FLAGS;
3176 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3177 ll_finish_md_op_data(op_data);
3178 ptlrpc_req_finished(req);
3182 ll_update_inode_flags(inode, flags);
3184 obj = ll_i2info(inode)->lli_clob;
3188 OBD_ALLOC_PTR(attr);
3192 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3198 #ifdef HAVE_FILEATTR_GET
3199 int ll_fileattr_get(struct dentry *dentry, struct fileattr *fa)
3201 return fileattr_get(d_inode(dentry), &fa->flags,
3202 &fa->fsx_xflags, &fa->fsx_projid);
3205 int ll_fileattr_set(struct mnt_idmap *mnt_userns,
3206 struct dentry *dentry, struct fileattr *fa)
3209 return ll_set_project(d_inode(dentry), fa->fsx_xflags,
3212 return fileattr_set(d_inode(dentry), fa->flags);
3214 #endif /* HAVE_FILEATTR_GET */
3216 /* ioctl commands shared between files and directories */
3217 int ll_iocontrol(struct inode *inode, struct file *file,
3218 unsigned int cmd, void __user *uarg)
3225 RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
3226 case LL_IOC_GETVERSION:
3227 case FS_IOC_GETVERSION:
3228 RETURN(put_user(inode->i_generation, (int __user *)uarg));
3230 #ifndef HAVE_FILEATTR_GET
3231 case FS_IOC_GETFLAGS: {
3232 u32 xflags = 0, projid = 0;
3235 if (!ll_access_ok(uarg, sizeof(int)))
3237 rc = fileattr_get(file->f_inode, &flags, &xflags, &projid);
3241 RETURN(put_user(flags, (int __user *)uarg));
3243 case FS_IOC_SETFLAGS: {
3246 if (get_user(flags, (int __user *)uarg))
3249 RETURN(fileattr_set(file->f_inode, flags));
3251 case FS_IOC_FSGETXATTR:
3252 RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
3253 case FS_IOC_FSSETXATTR:
3254 RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
3255 #endif /* HAVE_FILEATTR_GET */
3256 case LL_IOC_PROJECT:
3257 RETURN(ll_ioctl_project(file, cmd, uarg));
3258 case IOC_OBD_STATFS:
3259 RETURN(ll_obd_statfs(inode, uarg));
3260 case LL_IOC_GET_MDTIDX: {
3261 if (!ll_access_ok(uarg, sizeof(rc)))
3264 rc = ll_get_mdt_idx(inode);
3268 if (put_user(rc, (int __user *)uarg))
3273 case LL_IOC_FLUSHCTX:
3274 RETURN(ll_flush_ctx(inode));
3275 #ifdef HAVE_LUSTRE_CRYPTO
3276 case LL_IOC_ADD_ENCRYPTION_KEY:
3277 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3279 rc = llcrypt_ioctl_add_key(file, uarg);
3280 #ifdef CONFIG_LL_ENCRYPTION
3281 if (!rc && S_ISDIR(inode->i_mode))
3282 sptlrpc_enc_pool_add_user();
3285 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
3286 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3288 RETURN(llcrypt_ioctl_get_key_status(file, uarg));
3289 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
3290 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3292 RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
3293 case LL_IOC_SET_ENCRYPTION_POLICY:
3294 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3296 RETURN(llcrypt_ioctl_set_policy(file, uarg));
3297 case LL_IOC_REMOVE_ENCRYPTION_KEY:
3298 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3300 RETURN(llcrypt_ioctl_remove_key(file, uarg));
3301 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
3302 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3304 RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
3306 case LL_IOC_GETPARENT:
3307 RETURN(ll_getparent(file, uarg));
3308 case LL_IOC_PATH2FID:
3309 if (copy_to_user(uarg, ll_inode2fid(inode),
3310 sizeof(struct lu_fid)))
3313 case LL_IOC_UNLOCK_FOREIGN: {
3314 struct dentry *dentry = file_dentry(file);
3316 /* if not a foreign symlink do nothing */
3317 if (ll_foreign_is_removable(dentry, true)) {
3319 "prevent unlink of non-foreign file ("DFID")\n",
3320 PFID(ll_inode2fid(inode)));
3321 RETURN(-EOPNOTSUPP);
3325 case OBD_IOC_FID2PATH:
3326 RETURN(ll_fid2path(inode, uarg));
3327 #ifdef OBD_IOC_GETNAME_OLD
3328 case_OBD_IOC_DEPRECATED_FT(OBD_IOC_GETNAME_OLD,
3329 ll_i2sbi(inode)->ll_md_exp->exp_obd->obd_name,
3332 case OBD_IOC_GETDTNAME:
3333 case OBD_IOC_GETMDNAME:
3334 RETURN(ll_get_obd_name(inode, cmd, uarg));
3342 int ll_flush_ctx(struct inode *inode)
3344 struct ll_sb_info *sbi = ll_i2sbi(inode);
3346 CDEBUG(D_SEC, "flush context for user %d\n",
3347 from_kuid(&init_user_ns, current_uid()));
3349 obd_set_info_async(NULL, sbi->ll_md_exp,
3350 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3352 obd_set_info_async(NULL, sbi->ll_dt_exp,
3353 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3358 /* umount -f client means force down, don't save state */
3359 void ll_umount_begin(struct super_block *sb)
3361 struct ll_sb_info *sbi = ll_s2sbi(sb);
3362 struct obd_device *obd;
3363 struct obd_ioctl_data *ioc_data;
3367 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3368 sb->s_count, atomic_read(&sb->s_active));
3370 obd = class_exp2obd(sbi->ll_md_exp);
3372 CERROR("Invalid MDC connection handle %#llx\n",
3373 sbi->ll_md_exp->exp_handle.h_cookie);
3379 obd = class_exp2obd(sbi->ll_dt_exp);
3381 CERROR("Invalid LOV connection handle %#llx\n",
3382 sbi->ll_dt_exp->exp_handle.h_cookie);
3388 OBD_ALLOC_PTR(ioc_data);
3390 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_md_exp,
3391 sizeof *ioc_data, ioc_data, NULL);
3393 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_dt_exp,
3394 sizeof *ioc_data, ioc_data, NULL);
3396 OBD_FREE_PTR(ioc_data);
3399 /* Really, we'd like to wait until there are no requests outstanding,
3400 * and then continue. For now, we just periodically checking for vfs
3401 * to decrement mnt_cnt and hope to finish it within 10sec.
3405 !may_umount(sbi->ll_mnt.mnt)) {
3413 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3415 struct ll_sb_info *sbi = ll_s2sbi(sb);
3416 char *profilenm = get_profile_name(sb);
3420 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3421 read_only = *flags & MS_RDONLY;
3422 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3423 sizeof(KEY_READ_ONLY),
3424 KEY_READ_ONLY, sizeof(read_only),
3427 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3428 profilenm, read_only ?
3429 "read-only" : "read-write", err);
3434 sb->s_flags |= SB_RDONLY;
3436 sb->s_flags &= ~SB_RDONLY;
3438 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3439 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3440 read_only ? "read-only" : "read-write");
3446 * Cleanup the open handle that is cached on MDT-side.
3448 * For open case, the client side open handling thread may hit error
3449 * after the MDT grant the open. Under such case, the client should
3450 * send close RPC to the MDT as cleanup; otherwise, the open handle
3451 * on the MDT will be leaked there until the client umount or evicted.
3453 * In further, if someone unlinked the file, because the open handle
3454 * holds the reference on such file/object, then it will block the
3455 * subsequent threads that want to locate such object via FID.
3457 * \param[in] sb super block for this file-system
3458 * \param[in] open_req pointer to the original open request
3460 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3462 struct mdt_body *body;
3463 struct md_op_data *op_data;
3464 struct ptlrpc_request *close_req = NULL;
3465 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3468 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3469 OBD_ALLOC_PTR(op_data);
3470 if (op_data == NULL) {
3471 CWARN("%s: cannot allocate op_data to release open handle for "
3472 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3477 op_data->op_fid1 = body->mbo_fid1;
3478 op_data->op_open_handle = body->mbo_open_handle;
3479 op_data->op_mod_time = ktime_get_real_seconds();
3480 md_close(exp, op_data, NULL, &close_req);
3481 ptlrpc_req_finished(close_req);
3482 ll_finish_md_op_data(op_data);
3487 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3488 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3489 struct lustre_md *md)
3491 struct ll_sb_info *sbi = ll_i2sbi(inode);
3492 struct ptlrpc_request *req = NULL;
3493 union lmv_mds_md *lmm = NULL;
3497 LASSERT(is_root_inode(inode));
3498 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3499 LASSERT(!md->def_lsm_obj);
3501 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3503 GET_DEFAULT_LAYOUT_ROOT);
3504 if (rc && rc != -ENODATA)
3509 rc = md_stripe_object_create(sbi->ll_md_exp, &md->def_lsm_obj,
3519 ptlrpc_req_finished(req);
3523 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3524 struct super_block *sb, struct lookup_intent *it)
3526 struct ll_sb_info *sbi = NULL;
3527 struct lustre_md md = { NULL };
3528 bool default_lmv_deleted = false;
3533 LASSERT(*inode || sb);
3534 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3535 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3536 sbi->ll_md_exp, &md);
3541 * clear default_lmv only if intent_getattr reply doesn't contain it.
3542 * but it needs to be done after iget, check this early because
3543 * ll_update_lsm_md() may change md.
3545 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3546 S_ISDIR(md.body->mbo_mode) && !md.def_lsm_obj) {
3547 if (unlikely(*inode && is_root_inode(*inode) &&
3548 !fid_is_root(&sbi->ll_root_fid))) {
3549 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3554 if (!md.def_lsm_obj)
3555 default_lmv_deleted = true;
3559 rc = ll_update_inode(*inode, &md);
3563 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3564 struct lu_fid *fid1 = &md.body->mbo_fid1;
3566 LASSERT(sb != NULL);
3569 * At this point server returns to client's same fid as client
3570 * generated for creating. So using ->fid1 is okay here.
3572 if (!fid_is_sane(fid1)) {
3573 CERROR("%s: Fid is insane "DFID"\n",
3574 sbi->ll_fsname, PFID(fid1));
3575 GOTO(out, rc = -EINVAL);
3578 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3579 if (IS_ERR(*inode)) {
3581 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3583 CERROR("new_inode -fatal: rc %d\n", rc);
3588 /* Handling piggyback layout lock.
3589 * Layout lock can be piggybacked by getattr and open request.
3590 * The lsm can be applied to inode only if it comes with a layout lock
3591 * otherwise correct layout may be overwritten, for example:
3592 * 1. proc1: mdt returns a lsm but not granting layout
3593 * 2. layout was changed by another client
3594 * 3. proc2: refresh layout and layout lock granted
3595 * 4. proc1: to apply a stale layout */
3596 if (it != NULL && it->it_lock_mode != 0) {
3597 struct lustre_handle lockh;
3598 struct ldlm_lock *lock;
3600 lockh.cookie = it->it_lock_handle;
3601 lock = ldlm_handle2lock(&lockh);
3602 LASSERT(lock != NULL);
3603 if (ldlm_has_layout(lock)) {
3604 struct cl_object_conf conf;
3606 memset(&conf, 0, sizeof(conf));
3607 conf.coc_opc = OBJECT_CONF_SET;
3608 conf.coc_inode = *inode;
3609 conf.coc_lock = lock;
3610 conf.coc_try = false;
3611 conf.u.coc_layout = md.layout;
3612 (void)ll_layout_conf(*inode, &conf);
3614 LDLM_LOCK_PUT(lock);
3617 if (default_lmv_deleted)
3618 ll_update_default_lsm_md(*inode, &md);
3620 /* we may want to apply some policy for foreign file/dir */
3621 if (ll_sbi_has_foreign_symlink(sbi)) {
3622 rc = ll_manage_foreign(*inode, &md);
3630 /* cleanup will be done if necessary */
3631 md_put_lustre_md(sbi->ll_md_exp, &md);
3633 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3634 ll_intent_drop_lock(it);
3635 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3641 int ll_obd_statfs(struct inode *inode, void __user *uarg)
3643 struct ll_sb_info *sbi = NULL;
3644 struct obd_export *exp;
3645 struct obd_ioctl_data *data = NULL;
3650 sbi = ll_i2sbi(inode);
3652 GOTO(out_statfs, rc = -EINVAL);
3654 rc = obd_ioctl_getdata(&data, &len, uarg);
3656 GOTO(out_statfs, rc);
3658 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3659 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3660 GOTO(out_statfs, rc = -EINVAL);
3662 if (data->ioc_inllen1 != sizeof(__u32) ||
3663 data->ioc_inllen2 != sizeof(__u32) ||
3664 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3665 data->ioc_plen2 != sizeof(struct obd_uuid))
3666 GOTO(out_statfs, rc = -EINVAL);
3668 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3669 if (type & LL_STATFS_LMV)
3670 exp = sbi->ll_md_exp;
3671 else if (type & LL_STATFS_LOV)
3672 exp = sbi->ll_dt_exp;
3674 GOTO(out_statfs, rc = -ENODEV);
3676 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3678 GOTO(out_statfs, rc);
3680 OBD_FREE_LARGE(data, len);
3685 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3686 * be called early to avoid deadlock.
3688 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3690 lmv_stripe_object_put(&op_data->op_lso2);
3691 lmv_stripe_object_put(&op_data->op_lso1);
3692 lmv_stripe_object_put(&op_data->op_default_lso1);
3695 /* this function prepares md_op_data hint for passing it down to MD stack. */
3696 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3697 struct inode *i1, struct inode *i2,
3698 const char *name, size_t namelen,
3699 __u32 mode, enum md_op_code opc,
3702 struct llcrypt_name fname = { 0 };
3705 LASSERT(i1 != NULL);
3708 /* Do not reuse namelen for something else. */
3710 return ERR_PTR(-EINVAL);
3712 if ((!IS_ENCRYPTED(i1) ||
3713 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3714 namelen > ll_i2sbi(i1)->ll_namelen)
3715 return ERR_PTR(-ENAMETOOLONG);
3717 /* "/" is not valid name, but it's allowed */
3718 if (!lu_name_is_valid_2(name, namelen) &&
3719 strncmp("/", name, namelen) != 0)
3720 return ERR_PTR(-EINVAL);
3723 if (op_data == NULL)
3724 OBD_ALLOC_PTR(op_data);
3726 if (op_data == NULL)
3727 return ERR_PTR(-ENOMEM);
3729 ll_i2gids(op_data->op_suppgids, i1, i2);
3730 /* If the client is using a subdir mount and looks at what it sees as
3731 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3733 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3734 !fid_is_root(ll_inode2fid(i1)) &&
3735 name && namelen == strlen(dot_fscrypt_name) &&
3736 strncmp(name, dot_fscrypt_name, namelen) == 0))
3737 lu_root_fid(&op_data->op_fid1);
3739 op_data->op_fid1 = *ll_inode2fid(i1);
3741 if (S_ISDIR(i1->i_mode)) {
3742 down_read(&ll_i2info(i1)->lli_lsm_sem);
3744 lmv_stripe_object_get(ll_i2info(i1)->lli_lsm_obj);
3745 op_data->op_default_lso1 =
3746 lmv_stripe_object_get(ll_i2info(i1)->lli_def_lsm_obj);
3747 up_read(&ll_i2info(i1)->lli_lsm_sem);
3751 op_data->op_fid2 = *ll_inode2fid(i2);
3752 if (S_ISDIR(i2->i_mode)) {
3753 down_read(&ll_i2info(i2)->lli_lsm_sem);
3755 lmv_stripe_object_get(ll_i2info(i2)->lli_lsm_obj);
3756 up_read(&ll_i2info(i2)->lli_lsm_sem);
3759 fid_zero(&op_data->op_fid2);
3762 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3763 op_data->op_cli_flags |= CLI_HASH64;
3765 if (ll_need_32bit_api(ll_i2sbi(i1)))
3766 op_data->op_cli_flags |= CLI_API32;
3768 if ((i2 && is_root_inode(i2)) ||
3769 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3770 /* In case of lookup, ll_setup_filename() has already been
3771 * called in ll_lookup_it(), so just take provided name.
3772 * Also take provided name if we are dealing with root inode.
3774 fname.disk_name.name = (unsigned char *)name;
3775 fname.disk_name.len = namelen;
3776 } else if (name && namelen) {
3777 struct qstr dname = QSTR_INIT(name, namelen);
3779 struct lu_fid *pfid = NULL;
3783 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3784 /* special case when called from ll_link() */
3789 lookup = (int)(opc == LUSTRE_OPC_ANY);
3791 if (opc == LUSTRE_OPC_ANY && lookup)
3793 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3795 ll_finish_md_op_data(op_data);
3798 if (pfid && !fid_is_zero(pfid)) {
3800 op_data->op_fid2 = fid;
3801 op_data->op_bias = MDS_FID_OP;
3803 if (fname.disk_name.name &&
3804 fname.disk_name.name != (unsigned char *)name) {
3805 /* op_data->op_name must be freed after use */
3806 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3810 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3811 * are LUSTRE_OPC_ANY
3813 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3814 op_data->op_code = LUSTRE_OPC_ANY;
3816 op_data->op_code = opc;
3817 op_data->op_name = fname.disk_name.name;
3818 op_data->op_namelen = fname.disk_name.len;
3819 op_data->op_mode = mode;
3820 op_data->op_mod_time = ktime_get_real_seconds();
3821 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3822 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3823 op_data->op_cap = current_cap();
3824 op_data->op_mds = 0;
3825 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3826 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3827 op_data->op_bias |= MDS_CREATE_VOLATILE;
3829 op_data->op_data = data;
3834 void ll_finish_md_op_data(struct md_op_data *op_data)
3836 ll_unlock_md_op_lsm(op_data);
3837 ll_security_release_secctx(op_data->op_file_secctx,
3838 op_data->op_file_secctx_size,
3839 op_data->op_file_secctx_slot);
3840 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3841 /* allocated via ll_setup_filename called
3842 * from ll_prep_md_op_data
3844 kfree(op_data->op_name);
3845 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3846 OBD_FREE_PTR(op_data);
3849 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3851 struct ll_sb_info *sbi;
3854 LASSERT(seq && dentry);
3855 sbi = ll_s2sbi(dentry->d_sb);
3857 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3858 seq_puts(seq, "nolock");
3860 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3861 /* match_table in some cases has patterns for both enabled and
3862 * disabled cases. Ignore 'no'xxx versions if bit is set.
3864 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3865 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3866 if (ll_sbi_flags_name[i].token ==
3867 LL_SBI_FOREIGN_SYMLINK) {
3868 seq_show_option(seq, "foreign_symlink",
3869 sbi->ll_foreign_symlink_prefix);
3871 seq_printf(seq, ",%s",
3872 ll_sbi_flags_name[i].pattern);
3875 /* You can have either localflock or flock but not
3876 * both. If localflock is set don't print flock or
3879 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3881 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3882 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3883 seq_printf(seq, ",%s",
3884 ll_sbi_flags_name[i].pattern);
3888 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3894 * Get obd name by cmd, and copy out to user space
3896 int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg)
3898 struct ll_sb_info *sbi = ll_i2sbi(inode);
3899 struct obd_device *obd;
3902 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3903 obd = class_exp2obd(sbi->ll_dt_exp);
3904 else if (cmd == OBD_IOC_GETMDNAME)
3905 obd = class_exp2obd(sbi->ll_md_exp);
3912 if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1))
3919 struct work_struct db_work;
3920 struct dentry *db_dentry;
3921 /* Let's hope the path is not too long, 32 bytes for the work struct
3924 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3927 static void ll_dput_later(struct work_struct *work)
3929 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3931 dput(db->db_dentry);
3932 free_page((unsigned long)db);
3935 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3942 p.mnt = current->fs->root.mnt;
3944 path = d_path(&p, buf, bufsize);
3949 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3951 struct dname_buf *db;
3953 struct dentry *dentry = NULL;
3955 /* this can be called inside spin lock so use GFP_ATOMIC. */
3956 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3959 dentry = d_find_alias(inode);
3961 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3964 /* The below message is checked in recovery-small.sh test_24b */
3966 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3967 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3968 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3969 PFID(ll_inode2fid(inode)),
3970 (path && !IS_ERR(path)) ? path : "", ioret);
3972 if (dentry != NULL) {
3973 /* We cannot dput here since if we happen to be the last holder
3974 * then we can end up waiting for page evictions that
3975 * in turn wait for RPCs that need this instance of ptlrpcd
3976 * (callng brw_interpret->*page_completion*->vmpage_error->here)
3979 INIT_WORK(&db->db_work, ll_dput_later);
3980 db->db_dentry = dentry;
3981 schedule_work(&db->db_work);
3984 free_page((unsigned long)db);
3988 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3989 struct lov_user_md **kbuf)
3991 struct lov_user_md lum;
3995 if (copy_from_user(&lum, md, sizeof(lum)))
3998 lum_size = ll_lov_user_md_size(&lum);
4002 OBD_ALLOC_LARGE(*kbuf, lum_size);
4006 if (copy_from_user(*kbuf, md, lum_size) != 0) {
4007 OBD_FREE_LARGE(*kbuf, lum_size);
4015 * Compute llite root squash state after a change of root squash
4016 * configuration setting or add/remove of a lnet nid
4018 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
4020 struct root_squash_info *squash = &sbi->ll_squash;
4023 struct lnet_processid id;
4025 /* Update norootsquash flag */
4026 spin_lock(&squash->rsi_lock);
4027 if (list_empty(&squash->rsi_nosquash_nids))
4028 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4030 /* Do not apply root squash as soon as one of our NIDs is
4031 * in the nosquash_nids list */
4034 while (LNetGetId(i++, &id, false) != -ENOENT) {
4035 if (nid_is_lo0(&id.nid))
4037 if (cfs_match_nid(&id.nid,
4038 &squash->rsi_nosquash_nids)) {
4044 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4046 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4048 spin_unlock(&squash->rsi_lock);
4052 * Parse linkea content to extract information about a given hardlink
4054 * \param[in] ldata - Initialized linkea data
4055 * \param[in] linkno - Link identifier
4056 * \param[out] parent_fid - The entry's parent FID
4057 * \param[out] ln - Entry name destination buffer
4059 * \retval 0 on success
4060 * \retval Appropriate negative error code on failure
4062 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
4063 struct lu_fid *parent_fid, struct lu_name *ln)
4069 rc = linkea_init_with_rec(ldata);
4073 if (linkno >= ldata->ld_leh->leh_reccount)
4074 /* beyond last link */
4077 linkea_first_entry(ldata);
4078 for (idx = 0; ldata->ld_lee != NULL; idx++) {
4079 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
4084 linkea_next_entry(ldata);
4094 * Get parent FID and name of an identified link. Operation is performed for
4095 * a given link number, letting the caller iterate over linkno to list one or
4096 * all links of an entry.
4098 * \param[in] file - File descriptor against which to perform the operation
4099 * \param[in,out] arg - User-filled structure containing the linkno to operate
4100 * on and the available size. It is eventually filled with
4101 * the requested information or left untouched on error
4103 * \retval - 0 on success
4104 * \retval - Appropriate negative error code on failure
4106 int ll_getparent(struct file *file, struct getparent __user *arg)
4108 struct inode *inode = file_inode(file);
4109 struct linkea_data *ldata;
4110 struct lu_buf buf = LU_BUF_NULL;
4112 struct lu_fid parent_fid;
4119 if (!capable(CAP_DAC_READ_SEARCH) &&
4120 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
4123 if (get_user(name_size, &arg->gp_name_size))
4126 if (get_user(linkno, &arg->gp_linkno))
4129 if (name_size > PATH_MAX)
4132 OBD_ALLOC(ldata, sizeof(*ldata));
4136 rc = linkea_data_new(ldata, &buf);
4138 GOTO(ldata_free, rc);
4140 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
4141 buf.lb_len, OBD_MD_FLXATTR);
4145 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
4149 if (ln.ln_namelen >= name_size)
4150 GOTO(lb_free, rc = -EOVERFLOW);
4152 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
4153 GOTO(lb_free, rc = -EFAULT);
4155 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
4156 GOTO(lb_free, rc = -EFAULT);
4158 if (put_user('\0', arg->gp_name + ln.ln_namelen))
4159 GOTO(lb_free, rc = -EFAULT);
4164 OBD_FREE(ldata, sizeof(*ldata));