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_free_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 /* ll_cl_context initialize */
1278 INIT_LIST_HEAD(&lli->lli_lccs);
1279 seqlock_init(&lli->lli_page_inv_lock);
1280 lli->lli_inode_lock_owner = NULL;
1283 #define MAX_STRING_SIZE 128
1285 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1286 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1288 struct lustre_sb_info *lsi = s2lsi(sb);
1289 char buf[MAX_STRING_SIZE];
1293 err = bdi_init(&lsi->lsi_bdi);
1297 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1298 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1299 lsi->lsi_bdi.name = "lustre";
1300 va_start(args, fmt);
1301 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1303 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1306 sb->s_bdi = &lsi->lsi_bdi;
1310 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1312 int ll_fill_super(struct super_block *sb)
1314 struct lustre_profile *lprof = NULL;
1315 struct lustre_sb_info *lsi = s2lsi(sb);
1316 struct ll_sb_info *sbi = NULL;
1317 char *dt = NULL, *md = NULL;
1318 char *profilenm = get_profile_name(sb);
1319 struct config_llog_instance *cfg;
1320 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1321 const int instlen = LUSTRE_MAXINSTANCE + 2;
1322 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1323 char name[MAX_STRING_SIZE];
1332 /* for ASLR, to map between cfg_instance and hashed ptr */
1333 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1334 profilenm, cfg_instance, sb);
1336 CFS_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1340 GOTO(out_free_cfg, err = -ENOMEM);
1342 /* client additional sb info */
1343 lsi->lsi_llsbi = sbi = ll_init_sbi(lsi);
1345 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1347 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1349 GOTO(out_free_cfg, err);
1351 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1352 #ifdef CONFIG_LL_ENCRYPTION
1353 if (ll_sb_has_test_dummy_encryption(sb))
1354 /* enable filename encryption by default for dummy enc mode */
1355 lsi->lsi_flags |= LSI_FILENAME_ENC;
1357 /* filename encryption is disabled by default */
1358 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1361 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1362 sb->s_d_op = &ll_d_ops;
1365 generate_random_uuid(uuid.b);
1366 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1368 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1371 len = strlen(profilenm);
1372 ptr = strrchr(profilenm, '-');
1373 if (ptr && (strcmp(ptr, "-client") == 0))
1376 if (len > LUSTRE_MAXFSNAME) {
1377 if (unlikely(len >= MAX_STRING_SIZE))
1378 len = MAX_STRING_SIZE - 1;
1379 strncpy(name, profilenm, len);
1381 err = -ENAMETOOLONG;
1382 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1383 name, LUSTRE_MAXFSNAME, err);
1384 GOTO(out_free_cfg, err);
1386 strncpy(sbi->ll_fsname, profilenm, len);
1387 sbi->ll_fsname[len] = '\0';
1390 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1391 profilenm, cfg_instance);
1393 err = super_setup_bdi_name(sb, "%s", name);
1395 GOTO(out_free_cfg, err);
1397 /* disable kernel readahead */
1398 sb->s_bdi->ra_pages = 0;
1399 #ifdef HAVE_BDI_IO_PAGES
1400 sb->s_bdi->io_pages = 0;
1402 sb->s_bdi->capabilities |= LL_BDI_CAP_FLAGS;
1403 #ifdef SB_I_CGROUPWB
1404 sb->s_iflags |= SB_I_CGROUPWB;
1406 /* Call ll_debugfs_register_super() before lustre_process_log()
1407 * so that "llite.*.*" params can be processed correctly.
1409 err = ll_debugfs_register_super(sb, name);
1411 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1412 sbi->ll_fsname, err);
1416 /* The cfg_instance is a value unique to this super, in case some
1417 * joker tries to mount the same fs at two mount points.
1419 cfg->cfg_instance = cfg_instance;
1420 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1421 cfg->cfg_callback = class_config_llog_handler;
1422 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1423 /* set up client obds */
1424 err = lustre_process_log(sb, profilenm, cfg);
1426 GOTO(out_debugfs, err);
1428 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1429 lprof = class_get_profile(profilenm);
1430 if (lprof == NULL) {
1431 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1432 " read from the MGS. Does that filesystem "
1433 "exist?\n", profilenm);
1434 GOTO(out_debugfs, err = -EINVAL);
1436 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1437 lprof->lp_md, lprof->lp_dt);
1439 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1440 OBD_ALLOC(dt, dt_len);
1442 GOTO(out_profile, err = -ENOMEM);
1443 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1445 md_len = strlen(lprof->lp_md) + instlen + 2;
1446 OBD_ALLOC(md, md_len);
1448 GOTO(out_free_dt, err = -ENOMEM);
1449 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1451 /* connections, registrations, sb setup */
1452 err = client_common_fill_super(sb, md, dt);
1454 GOTO(out_free_md, err);
1456 sbi->ll_client_common_fill_super_succeeded = 1;
1460 OBD_FREE(md, md_len);
1463 OBD_FREE(dt, dt_len);
1466 class_put_profile(lprof);
1469 ll_debugfs_unregister_super(sb);
1476 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1477 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1478 sb->s_flags & SB_RDONLY ? " read-only" : "");
1480 } /* ll_fill_super */
1482 void ll_put_super(struct super_block *sb)
1484 struct config_llog_instance cfg, params_cfg;
1485 struct obd_device *obd;
1486 struct lustre_sb_info *lsi = s2lsi(sb);
1487 struct ll_sb_info *sbi = ll_s2sbi(sb);
1488 char *profilenm = get_profile_name(sb);
1489 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1491 int next, force = 1, rc = 0;
1495 GOTO(out_no_sbi, 0);
1497 /* Should replace instance_id with something better for ASLR */
1498 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1499 profilenm, cfg_instance, sb);
1501 cfg.cfg_instance = cfg_instance;
1502 lustre_end_log(sb, profilenm, &cfg);
1504 params_cfg.cfg_instance = cfg_instance;
1505 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1507 if (sbi->ll_md_exp) {
1508 obd = class_exp2obd(sbi->ll_md_exp);
1510 force = obd->obd_force;
1513 /* Wait for unstable pages to be committed to stable storage */
1515 rc = l_wait_event_abortable(
1516 sbi->ll_cache->ccc_unstable_waitq,
1517 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1520 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1521 if (force == 0 && rc != -ERESTARTSYS)
1522 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1524 /* We need to set force before the lov_disconnect in
1525 * lustre_common_put_super, since l_d cleans up osc's as well.
1529 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1531 obd->obd_force = force;
1535 if (sbi->ll_client_common_fill_super_succeeded) {
1536 /* Only if client_common_fill_super succeeded */
1537 client_common_put_super(sb);
1540 /* imitate failed cleanup */
1541 if (CFS_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1545 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1546 class_manual_cleanup(obd);
1549 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1550 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1553 class_del_profile(profilenm);
1555 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1556 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1557 bdi_destroy(&lsi->lsi_bdi);
1558 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1562 llcrypt_free_dummy_policy(&lsi->lsi_dummy_enc_policy);
1564 lsi->lsi_llsbi = NULL;
1566 lustre_common_put_super(sb);
1568 cl_env_cache_purge(~0);
1571 } /* client_put_super */
1573 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1575 struct inode *inode = NULL;
1577 /* NOTE: we depend on atomic igrab() -bzzz */
1578 lock_res_and_lock(lock);
1579 if (lock->l_resource->lr_lvb_inode) {
1580 struct ll_inode_info * lli;
1581 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1582 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1583 inode = igrab(lock->l_resource->lr_lvb_inode);
1585 inode = lock->l_resource->lr_lvb_inode;
1586 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1587 D_WARNING, lock, "lr_lvb_inode %p is "
1588 "bogus: magic %08x",
1589 lock->l_resource->lr_lvb_inode,
1590 lli->lli_inode_magic);
1594 unlock_res_and_lock(lock);
1598 void ll_dir_clear_lsm_md(struct inode *inode)
1600 struct ll_inode_info *lli = ll_i2info(inode);
1602 LASSERT(S_ISDIR(inode->i_mode));
1604 if (lli->lli_lsm_md) {
1605 lmv_free_memmd(lli->lli_lsm_md);
1606 lli->lli_lsm_md = NULL;
1609 if (lli->lli_default_lsm_md) {
1610 lmv_free_memmd(lli->lli_default_lsm_md);
1611 lli->lli_default_lsm_md = NULL;
1615 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1616 const struct lu_fid *fid,
1617 struct lustre_md *md)
1619 struct ll_sb_info *sbi = ll_s2sbi(sb);
1620 struct ll_inode_info *lli;
1621 struct mdt_body *body = md->body;
1622 struct inode *inode;
1628 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1629 inode = iget_locked(sb, ino);
1630 if (inode == NULL) {
1631 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1632 sbi->ll_fsname, PFID(fid));
1633 RETURN(ERR_PTR(-ENOENT));
1636 lli = ll_i2info(inode);
1637 if (inode->i_state & I_NEW) {
1638 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1639 (body->mbo_mode & S_IFMT);
1640 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1643 inode->i_mtime.tv_sec = 0;
1644 inode->i_atime.tv_sec = 0;
1645 inode->i_ctime.tv_sec = 0;
1648 #ifdef HAVE_BACKING_DEV_INFO
1649 /* initializing backing dev info. */
1650 inode->i_mapping->backing_dev_info =
1651 &s2lsi(inode->i_sb)->lsi_bdi;
1653 inode->i_op = &ll_dir_inode_operations;
1654 inode->i_fop = &ll_dir_operations;
1655 lli->lli_fid = *fid;
1658 /* master object FID */
1659 lli->lli_pfid = body->mbo_fid1;
1660 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1661 lli, PFID(fid), PFID(&lli->lli_pfid));
1662 unlock_new_inode(inode);
1664 /* in directory restripe/auto-split, a directory will be
1665 * transformed to a stripe if it's plain, set its pfid here,
1666 * otherwise ll_lock_cancel_bits() can't find the master inode.
1668 lli->lli_pfid = body->mbo_fid1;
1674 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1677 struct lmv_stripe_md *lsm = md->lmv;
1678 struct ll_inode_info *lli = ll_i2info(inode);
1681 LASSERT(lsm != NULL);
1683 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1684 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1685 lsm_md_dump(D_INODE, lsm);
1687 if (!lmv_dir_striped(lsm))
1690 /* XXX sigh, this lsm_root initialization should be in
1691 * LMV layer, but it needs ll_iget right now, so we
1692 * put this here right now. */
1693 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1694 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1695 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1697 if (!fid_is_sane(fid))
1700 /* Unfortunately ll_iget will call ll_update_inode,
1701 * where the initialization of slave inode is slightly
1702 * different, so it reset lsm_md to NULL to avoid
1703 * initializing lsm for slave inode. */
1704 lsm->lsm_md_oinfo[i].lmo_root =
1705 ll_iget_anon_dir(inode->i_sb, fid, md);
1706 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1707 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1709 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1711 iput(lsm->lsm_md_oinfo[i].lmo_root);
1712 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1718 lli->lli_lsm_md = lsm;
1723 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1725 struct ll_inode_info *lli = ll_i2info(inode);
1729 if (!md->default_lmv) {
1730 /* clear default lsm */
1731 if (lli->lli_default_lsm_md && lli->lli_default_lmv_set) {
1732 down_write(&lli->lli_lsm_sem);
1733 if (lli->lli_default_lsm_md &&
1734 lli->lli_default_lmv_set) {
1735 lmv_free_memmd(lli->lli_default_lsm_md);
1736 lli->lli_default_lsm_md = NULL;
1737 lli->lli_inherit_depth = 0;
1738 lli->lli_default_lmv_set = 0;
1740 up_write(&lli->lli_lsm_sem);
1745 if (lli->lli_default_lsm_md) {
1746 /* do nonthing if default lsm isn't changed */
1747 down_read(&lli->lli_lsm_sem);
1748 if (lli->lli_default_lsm_md &&
1749 lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1750 up_read(&lli->lli_lsm_sem);
1753 up_read(&lli->lli_lsm_sem);
1756 down_write(&lli->lli_lsm_sem);
1757 if (lli->lli_default_lsm_md)
1758 lmv_free_memmd(lli->lli_default_lsm_md);
1759 lli->lli_default_lsm_md = md->default_lmv;
1760 lli->lli_default_lmv_set = 1;
1761 lsm_md_dump(D_INODE, md->default_lmv);
1762 md->default_lmv = NULL;
1763 up_write(&lli->lli_lsm_sem);
1767 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1769 struct ll_inode_info *lli = ll_i2info(inode);
1770 struct lmv_stripe_md *lsm = md->lmv;
1771 struct cl_attr *attr;
1776 LASSERT(S_ISDIR(inode->i_mode));
1777 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1778 PFID(ll_inode2fid(inode)));
1780 /* update default LMV */
1781 if (md->default_lmv)
1782 ll_update_default_lsm_md(inode, md);
1784 /* after dir migration/restripe, a stripe may be turned into a
1785 * directory, in this case, zero out its lli_pfid.
1787 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1788 fid_zero(&lli->lli_pfid);
1791 * no striped information from request, lustre_md from req does not
1792 * include stripeEA, see ll_md_setattr()
1798 * normally dir layout doesn't change, only take read lock to check
1799 * that to avoid blocking other MD operations.
1801 down_read(&lli->lli_lsm_sem);
1803 /* some current lookup initialized lsm, and unchanged */
1804 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1805 GOTO(unlock, rc = 0);
1807 /* if dir layout doesn't match, check whether version is increased,
1808 * which means layout is changed, this happens in dir split/merge and
1811 * foreign LMV should not change.
1813 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1814 lsm->lsm_md_layout_version <=
1815 lli->lli_lsm_md->lsm_md_layout_version) {
1816 CERROR("%s: "DFID" dir layout mismatch:\n",
1817 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1818 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1819 lsm_md_dump(D_ERROR, lsm);
1820 GOTO(unlock, rc = -EINVAL);
1823 up_read(&lli->lli_lsm_sem);
1824 down_write(&lli->lli_lsm_sem);
1825 /* clear existing lsm */
1826 if (lli->lli_lsm_md) {
1827 lmv_free_memmd(lli->lli_lsm_md);
1828 lli->lli_lsm_md = NULL;
1831 rc = ll_init_lsm_md(inode, md);
1833 up_write(&lli->lli_lsm_sem);
1837 /* md_merge_attr() may take long, since lsm is already set, switch to
1840 downgrade_write(&lli->lli_lsm_sem);
1842 /* set md->lmv to NULL, so the following free lustre_md will not free
1847 if (!lmv_dir_striped(lli->lli_lsm_md))
1848 GOTO(unlock, rc = 0);
1850 OBD_ALLOC_PTR(attr);
1852 GOTO(unlock, rc = -ENOMEM);
1854 /* validate the lsm */
1855 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1856 ll_md_blocking_ast);
1858 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1859 md->body->mbo_nlink = attr->cat_nlink;
1860 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1861 md->body->mbo_size = attr->cat_size;
1862 if (md->body->mbo_valid & OBD_MD_FLATIME)
1863 md->body->mbo_atime = attr->cat_atime;
1864 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1865 md->body->mbo_ctime = attr->cat_ctime;
1866 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1867 md->body->mbo_mtime = attr->cat_mtime;
1873 up_read(&lli->lli_lsm_sem);
1878 void ll_clear_inode(struct inode *inode)
1880 struct ll_inode_info *lli = ll_i2info(inode);
1881 struct ll_sb_info *sbi = ll_i2sbi(inode);
1885 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1886 PFID(ll_inode2fid(inode)), inode);
1888 if (S_ISDIR(inode->i_mode)) {
1889 /* these should have been cleared in ll_file_release */
1890 LASSERT(lli->lli_opendir_key == NULL);
1891 LASSERT(lli->lli_sai == NULL);
1892 LASSERT(lli->lli_opendir_pid == 0);
1894 pcc_inode_free(inode);
1897 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1899 LASSERT(!lli->lli_open_fd_write_count);
1900 LASSERT(!lli->lli_open_fd_read_count);
1901 LASSERT(!lli->lli_open_fd_exec_count);
1903 if (lli->lli_mds_write_och)
1904 ll_md_real_close(inode, FMODE_WRITE);
1905 if (lli->lli_mds_exec_och)
1906 ll_md_real_close(inode, FMODE_EXEC);
1907 if (lli->lli_mds_read_och)
1908 ll_md_real_close(inode, FMODE_READ);
1910 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1911 OBD_FREE(lli->lli_symlink_name,
1912 strlen(lli->lli_symlink_name) + 1);
1913 lli->lli_symlink_name = NULL;
1916 ll_xattr_cache_destroy(inode);
1918 forget_all_cached_acls(inode);
1920 lli->lli_inode_magic = LLI_INODE_DEAD;
1922 if (S_ISDIR(inode->i_mode))
1923 ll_dir_clear_lsm_md(inode);
1924 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1925 LASSERT(list_empty(&lli->lli_agl_list));
1928 * XXX This has to be done before lsm is freed below, because
1929 * cl_object still uses inode lsm.
1931 cl_inode_fini(inode);
1933 llcrypt_put_encryption_info(inode);
1938 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1940 struct lustre_md md;
1941 struct inode *inode = dentry->d_inode;
1942 struct ll_sb_info *sbi = ll_i2sbi(inode);
1943 struct ptlrpc_request *request = NULL;
1948 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1949 LUSTRE_OPC_ANY, NULL);
1950 if (IS_ERR(op_data))
1951 RETURN(PTR_ERR(op_data));
1953 /* If this is a chgrp of a regular file, we want to reserve enough
1954 * quota to cover the entire file size.
1956 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1957 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1958 from_kgid(&init_user_ns, inode->i_gid)) {
1959 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1960 op_data->op_attr_blocks = inode->i_blocks;
1964 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1966 ptlrpc_req_finished(request);
1967 if (rc == -ENOENT) {
1969 /* Unlinked special device node? Or just a race?
1970 * Pretend we done everything. */
1971 if (!S_ISREG(inode->i_mode) &&
1972 !S_ISDIR(inode->i_mode)) {
1973 ia_valid = op_data->op_attr.ia_valid;
1974 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1975 rc = simple_setattr(&init_user_ns, dentry,
1977 op_data->op_attr.ia_valid = ia_valid;
1979 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1980 CERROR("md_setattr fails: rc = %d\n", rc);
1985 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1986 sbi->ll_md_exp, &md);
1988 ptlrpc_req_finished(request);
1992 ia_valid = op_data->op_attr.ia_valid;
1993 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1994 * cache is not cleared yet. */
1995 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1996 if (S_ISREG(inode->i_mode))
1997 ll_inode_lock(inode);
1998 rc = simple_setattr(&init_user_ns, dentry, &op_data->op_attr);
1999 if (S_ISREG(inode->i_mode))
2000 ll_inode_unlock(inode);
2001 op_data->op_attr.ia_valid = ia_valid;
2003 rc = ll_update_inode(inode, &md);
2004 ptlrpc_req_finished(request);
2010 * Zero portion of page that is part of @inode.
2011 * This implies, if necessary:
2012 * - taking cl_lock on range corresponding to concerned page
2013 * - grabbing vm page
2014 * - associating cl_page
2015 * - proceeding to clio read
2016 * - zeroing range in page
2017 * - proceeding to cl_page flush
2018 * - releasing cl_lock
2020 * \param[in] inode inode
2021 * \param[in] index page index
2022 * \param[in] offset offset in page to start zero from
2023 * \param[in] len len to zero
2025 * \retval 0 on success
2026 * \retval negative errno on failure
2028 static int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
2031 struct ll_inode_info *lli = ll_i2info(inode);
2032 struct cl_object *clob = lli->lli_clob;
2034 struct lu_env *env = NULL;
2035 struct cl_io *io = NULL;
2036 struct cl_page *clpage = NULL;
2037 struct page *vmpage = NULL;
2038 unsigned from = index << PAGE_SHIFT;
2039 struct cl_lock *lock = NULL;
2040 struct cl_lock_descr *descr = NULL;
2041 struct cl_2queue *queue = NULL;
2042 struct cl_sync_io *anchor = NULL;
2043 bool holdinglock = false;
2048 env = cl_env_get(&refcheck);
2050 RETURN(PTR_ERR(env));
2052 io = vvp_env_thread_io(env);
2054 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2058 lock = vvp_env_lock(env);
2059 descr = &lock->cll_descr;
2060 descr->cld_obj = io->ci_obj;
2061 descr->cld_start = from >> PAGE_SHIFT;
2062 descr->cld_end = (from + PAGE_SIZE - 1) >> PAGE_SHIFT;
2063 descr->cld_mode = CLM_WRITE;
2064 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2066 /* request lock for page */
2067 rc = cl_lock_request(env, io, lock);
2068 /* -ECANCELED indicates a matching lock with a different extent
2069 * was already present, and -EEXIST indicates a matching lock
2070 * on exactly the same extent was already present.
2071 * In both cases it means we are covered.
2073 if (rc == -ECANCELED || rc == -EEXIST)
2081 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2083 GOTO(rellock, rc = -EOPNOTSUPP);
2085 if (!PageDirty(vmpage)) {
2086 /* associate cl_page */
2087 clpage = cl_page_find(env, clob, vmpage->index,
2088 vmpage, CPT_CACHEABLE);
2090 GOTO(pagefini, rc = PTR_ERR(clpage));
2092 cl_page_assume(env, io, clpage);
2095 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2096 !PageWriteback(vmpage)) {
2098 /* Set PagePrivate2 to detect special case of empty page
2099 * in osc_brw_fini_request().
2100 * It is also used to tell ll_io_read_page() that we do not
2101 * want the vmpage to be unlocked.
2103 SetPagePrivate2(vmpage);
2104 rc = ll_io_read_page(env, io, clpage, NULL);
2105 if (!PagePrivate2(vmpage)) {
2106 /* PagePrivate2 was cleared in osc_brw_fini_request()
2107 * meaning we read an empty page. In this case, in order
2108 * to avoid allocating unnecessary block in truncated
2109 * file, we must not zero and write as below. Subsequent
2110 * server-side truncate will handle things correctly.
2112 cl_page_unassume(env, io, clpage);
2113 GOTO(clpfini, rc = 0);
2115 ClearPagePrivate2(vmpage);
2120 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2121 * the vmpage, so we are good to proceed and zero range in page.
2123 zero_user(vmpage, offset, len);
2125 if (holdinglock && clpage) {
2126 /* explicitly write newly modified page */
2127 queue = &io->ci_queue;
2128 cl_2queue_init(queue);
2129 anchor = &vvp_env_info(env)->vti_anchor;
2130 cl_sync_io_init(anchor, 1);
2131 clpage->cp_sync_io = anchor;
2132 cl_page_list_add(&queue->c2_qin, clpage, true);
2133 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2135 GOTO(queuefini1, rc);
2136 rc = cl_sync_io_wait(env, anchor, 0);
2138 GOTO(queuefini2, rc);
2139 cl_page_assume(env, io, clpage);
2142 cl_2queue_discard(env, io, queue);
2144 cl_2queue_disown(env, queue);
2145 cl_2queue_fini(env, queue);
2150 cl_page_put(env, clpage);
2152 unlock_page(vmpage);
2156 cl_lock_release(env, lock);
2158 cl_io_fini(env, io);
2161 cl_env_put(env, &refcheck);
2167 * Get reference file from volatile file name.
2168 * Volatile file name may look like:
2169 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2170 * where fd is opened descriptor of reference file.
2172 * \param[in] volatile_name volatile file name
2173 * \param[in] volatile_len volatile file name length
2174 * \param[out] ref_file pointer to struct file of reference file
2176 * \retval 0 on success
2177 * \retval negative errno on failure
2179 int volatile_ref_file(const char *volatile_name, int volatile_len,
2180 struct file **ref_file)
2182 char *p, *q, *fd_str;
2185 p = strnstr(volatile_name, ":fd=", volatile_len);
2186 if (!p || strlen(p + 4) == 0)
2189 q = strchrnul(p + 4, ':');
2190 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2193 rc = kstrtouint(fd_str, 10, &fd);
2198 *ref_file = fget(fd);
2204 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2205 * object(s) determine the file size and mtime. Otherwise, the MDS will
2206 * keep these values until such a time that objects are allocated for it.
2207 * We do the MDS operations first, as it is checking permissions for us.
2208 * We don't to the MDS RPC if there is nothing that we want to store there,
2209 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2210 * going to do an RPC anyways.
2212 * If we are doing a truncate, we will send the mtime and ctime updates
2213 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2214 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2217 * In case of HSMimport, we only set attr on MDS.
2219 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2220 enum op_xvalid xvalid, bool hsm_import)
2222 struct inode *inode = dentry->d_inode;
2223 struct ll_inode_info *lli = ll_i2info(inode);
2224 struct md_op_data *op_data = NULL;
2225 ktime_t kstart = ktime_get();
2230 /* VFS has locked the inode before calling this */
2231 ll_set_inode_lock_owner(inode);
2233 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2234 "valid %x, hsm_import %d\n",
2235 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2236 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2239 if (attr->ia_valid & ATTR_SIZE) {
2240 /* Check new size against VFS/VM file size limit and rlimit */
2241 rc = inode_newsize_ok(inode, attr->ia_size);
2245 /* The maximum Lustre file size is variable, based on the
2246 * OST maximum object size and number of stripes. This
2247 * needs another check in addition to the VFS check above. */
2248 if (attr->ia_size > ll_file_maxbytes(inode)) {
2249 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2250 PFID(&lli->lli_fid), attr->ia_size,
2251 ll_file_maxbytes(inode));
2252 GOTO(clear, rc = -EFBIG);
2255 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2258 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2259 if (attr->ia_valid & TIMES_SET_FLAGS) {
2260 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2261 !capable(CAP_FOWNER))
2262 GOTO(clear, rc = -EPERM);
2265 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2266 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2267 (attr->ia_valid & ATTR_CTIME)) {
2268 attr->ia_ctime = current_time(inode);
2269 xvalid |= OP_XVALID_CTIME_SET;
2271 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2272 (attr->ia_valid & ATTR_ATIME)) {
2273 attr->ia_atime = current_time(inode);
2274 attr->ia_valid |= ATTR_ATIME_SET;
2276 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2277 (attr->ia_valid & ATTR_MTIME)) {
2278 attr->ia_mtime = current_time(inode);
2279 attr->ia_valid |= ATTR_MTIME_SET;
2282 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2283 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2284 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2285 ktime_get_real_seconds());
2287 if (S_ISREG(inode->i_mode))
2288 ll_inode_unlock(inode);
2290 /* We always do an MDS RPC, even if we're only changing the size;
2291 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2293 OBD_ALLOC_PTR(op_data);
2294 if (op_data == NULL)
2295 GOTO(out, rc = -ENOMEM);
2297 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2298 /* If we are changing file size, file content is
2299 * modified, flag it.
2301 xvalid |= OP_XVALID_OWNEROVERRIDE;
2302 op_data->op_bias |= MDS_DATA_MODIFIED;
2303 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2306 if (attr->ia_valid & ATTR_FILE) {
2307 struct ll_file_data *fd = attr->ia_file->private_data;
2309 if (fd->fd_lease_och)
2310 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2313 op_data->op_attr = *attr;
2314 op_data->op_xvalid = xvalid;
2316 rc = ll_md_setattr(dentry, op_data);
2319 lli->lli_synced_to_mds = false;
2321 if (!S_ISREG(inode->i_mode) || hsm_import)
2324 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2325 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2326 xvalid & OP_XVALID_CTIME_SET) {
2327 bool cached = false;
2329 rc = pcc_inode_setattr(inode, attr, &cached);
2332 CERROR("%s: PCC inode "DFID" setattr failed: "
2334 ll_i2sbi(inode)->ll_fsname,
2335 PFID(&lli->lli_fid), rc);
2339 unsigned int flags = 0;
2341 /* For truncate and utimes sending attributes to OSTs,
2342 * setting mtime/atime to the past will be performed
2343 * under PW [0:EOF] extent lock (new_size:EOF for
2344 * truncate). It may seem excessive to send mtime/atime
2345 * updates to OSTs when not setting times to past, but
2346 * it is necessary due to possible time
2347 * de-synchronization between MDT inode and OST objects
2349 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2350 xvalid |= OP_XVALID_FLAGS;
2351 flags = LUSTRE_ENCRYPT_FL;
2352 /* Call to ll_io_zero_page is not necessary if
2353 * truncating on PAGE_SIZE boundary, because
2354 * whole pages will be wiped.
2355 * In case of Direct IO, all we need is to set
2358 if (attr->ia_valid & ATTR_SIZE &&
2359 attr->ia_size & ~PAGE_MASK &&
2360 !(attr->ia_valid & ATTR_FILE &&
2361 attr->ia_file->f_flags & O_DIRECT)) {
2363 attr->ia_size & (PAGE_SIZE - 1);
2365 rc = ll_io_zero_page(inode,
2366 attr->ia_size >> PAGE_SHIFT,
2367 offset, PAGE_SIZE - offset);
2371 /* If encrypted volatile file without the key,
2372 * we need to fetch size from reference file,
2373 * and set it on OST objects. This happens when
2374 * migrating or extending an encrypted file
2377 if (filename_is_volatile(dentry->d_name.name,
2380 llcrypt_require_key(inode) == -ENOKEY) {
2381 struct file *ref_file;
2382 struct inode *ref_inode;
2383 struct ll_inode_info *ref_lli;
2384 struct cl_object *ref_obj;
2385 struct cl_attr ref_attr = { 0 };
2389 rc = volatile_ref_file(
2390 dentry->d_name.name,
2396 ref_inode = file_inode(ref_file);
2399 GOTO(out, rc = -EINVAL);
2402 env = cl_env_get(&refcheck);
2404 GOTO(out, rc = PTR_ERR(env));
2406 ref_lli = ll_i2info(ref_inode);
2407 ref_obj = ref_lli->lli_clob;
2408 cl_object_attr_lock(ref_obj);
2409 rc = cl_object_attr_get(env, ref_obj,
2411 cl_object_attr_unlock(ref_obj);
2412 cl_env_put(env, &refcheck);
2417 attr->ia_valid |= ATTR_SIZE;
2418 attr->ia_size = ref_attr.cat_size;
2421 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2425 /* If the file was restored, it needs to set dirty flag.
2427 * We've already sent MDS_DATA_MODIFIED flag in
2428 * ll_md_setattr() for truncate. However, the MDT refuses to
2429 * set the HS_DIRTY flag on released files, so we have to set
2430 * it again if the file has been restored. Please check how
2431 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2433 * Please notice that if the file is not released, the previous
2434 * MDS_DATA_MODIFIED has taken effect and usually
2435 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2436 * This way we can save an RPC for common open + trunc
2438 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2439 struct hsm_state_set hss = {
2440 .hss_valid = HSS_SETMASK,
2441 .hss_setmask = HS_DIRTY,
2445 rc2 = ll_hsm_state_set(inode, &hss);
2446 /* truncate and write can happen at the same time, so that
2447 * the file can be set modified even though the file is not
2448 * restored from released state, and ll_hsm_state_set() is
2449 * not applicable for the file, and rc2 < 0 is normal in this
2452 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2453 PFID(ll_inode2fid(inode)), rc2);
2458 if (op_data != NULL)
2459 ll_finish_md_op_data(op_data);
2461 if (S_ISREG(inode->i_mode)) {
2462 ll_inode_lock(inode);
2463 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2464 inode_dio_wait(inode);
2465 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2466 * flag. ll_update_inode (called from ll_md_setattr), clears
2467 * inode flags, so there is a gap where S_NOSEC is not set.
2468 * This can cause a writer to take the i_mutex unnecessarily,
2469 * but this is safe to do and should be rare. */
2470 inode_has_no_xattr(inode);
2474 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2475 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2476 ktime_us_delta(ktime_get(), kstart));
2478 ll_clear_inode_lock_owner(inode);
2483 int ll_setattr(struct user_namespace *mnt_userns, struct dentry *de,
2486 int mode = de->d_inode->i_mode;
2487 enum op_xvalid xvalid = 0;
2490 rc = llcrypt_prepare_setattr(de, attr);
2494 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2495 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2496 xvalid |= OP_XVALID_OWNEROVERRIDE;
2498 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2499 (ATTR_SIZE|ATTR_MODE)) &&
2500 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2501 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2502 !(attr->ia_mode & S_ISGID))))
2503 attr->ia_valid |= ATTR_FORCE;
2505 if ((attr->ia_valid & ATTR_MODE) &&
2507 !(attr->ia_mode & S_ISUID) &&
2508 !(attr->ia_valid & ATTR_KILL_SUID))
2509 attr->ia_valid |= ATTR_KILL_SUID;
2511 if ((attr->ia_valid & ATTR_MODE) &&
2512 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2513 !(attr->ia_mode & S_ISGID) &&
2514 !(attr->ia_valid & ATTR_KILL_SGID))
2515 attr->ia_valid |= ATTR_KILL_SGID;
2517 return ll_setattr_raw(de, attr, xvalid, false);
2520 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2523 struct obd_statfs obd_osfs = { 0 };
2528 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2530 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2531 flags |= OBD_STATFS_NODELAY;
2533 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2537 osfs->os_type = LL_SUPER_MAGIC;
2539 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2540 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2542 if (osfs->os_state & OS_STATFS_SUM)
2545 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2546 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2549 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2550 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2553 osfs->os_bsize = obd_osfs.os_bsize;
2554 osfs->os_blocks = obd_osfs.os_blocks;
2555 osfs->os_bfree = obd_osfs.os_bfree;
2556 osfs->os_bavail = obd_osfs.os_bavail;
2558 /* If we have _some_ OSTs, but don't have as many free objects on the
2559 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2560 * to compensate, so that the "inodes in use" number is correct.
2561 * This should be kept in sync with lod_statfs() behaviour.
2563 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2564 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2566 osfs->os_ffree = obd_osfs.os_ffree;
2573 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2575 struct if_quotactl qctl = {
2576 .qc_cmd = LUSTRE_Q_GETQUOTA,
2577 .qc_type = PRJQUOTA,
2578 .qc_valid = QC_GENERAL,
2580 u64 limit, curblock;
2583 qctl.qc_id = ll_i2info(inode)->lli_projid;
2584 ret = quotactl_ioctl(inode->i_sb, &qctl);
2586 /* ignore errors if project ID does not have
2587 * a quota limit or feature unsupported.
2589 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2594 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2595 qctl.qc_dqblk.dqb_bsoftlimit :
2596 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2597 if (limit && sfs->f_blocks > limit) {
2598 curblock = (qctl.qc_dqblk.dqb_curspace +
2599 sfs->f_bsize - 1) / sfs->f_bsize;
2600 sfs->f_blocks = limit;
2601 sfs->f_bfree = sfs->f_bavail =
2602 (sfs->f_blocks > curblock) ?
2603 (sfs->f_blocks - curblock) : 0;
2606 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2607 qctl.qc_dqblk.dqb_isoftlimit :
2608 qctl.qc_dqblk.dqb_ihardlimit;
2609 if (limit && sfs->f_files > limit) {
2610 sfs->f_files = limit;
2611 sfs->f_ffree = (sfs->f_files >
2612 qctl.qc_dqblk.dqb_curinodes) ?
2613 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2619 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2621 struct super_block *sb = de->d_sb;
2622 struct obd_statfs osfs;
2623 __u64 fsid = huge_encode_dev(sb->s_dev);
2624 ktime_t kstart = ktime_get();
2627 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2629 /* Some amount of caching on the client is allowed */
2630 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2634 statfs_unpack(sfs, &osfs);
2636 /* We need to downshift for all 32-bit kernels, because we can't
2637 * tell if the kernel is being called via sys_statfs64() or not.
2638 * Stop before overflowing f_bsize - in which case it is better
2639 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2640 if (sizeof(long) < 8) {
2641 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2644 osfs.os_blocks >>= 1;
2645 osfs.os_bfree >>= 1;
2646 osfs.os_bavail >>= 1;
2650 sfs->f_blocks = osfs.os_blocks;
2651 sfs->f_bfree = osfs.os_bfree;
2652 sfs->f_bavail = osfs.os_bavail;
2653 sfs->f_fsid.val[0] = (__u32)fsid;
2654 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2655 if (ll_i2info(de->d_inode)->lli_projid &&
2656 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2657 return ll_statfs_project(de->d_inode, sfs);
2659 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2660 ktime_us_delta(ktime_get(), kstart));
2665 void ll_inode_size_lock(struct inode *inode)
2667 struct ll_inode_info *lli;
2669 LASSERT(!S_ISDIR(inode->i_mode));
2671 lli = ll_i2info(inode);
2672 mutex_lock(&lli->lli_size_mutex);
2673 lli->lli_size_lock_owner = current;
2676 void ll_inode_size_unlock(struct inode *inode)
2678 struct ll_inode_info *lli;
2680 lli = ll_i2info(inode);
2681 lli->lli_size_lock_owner = NULL;
2682 mutex_unlock(&lli->lli_size_mutex);
2685 int ll_inode_size_trylock(struct inode *inode)
2687 struct ll_inode_info *lli;
2689 LASSERT(!S_ISDIR(inode->i_mode));
2691 lli = ll_i2info(inode);
2692 return mutex_trylock(&lli->lli_size_mutex);
2695 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2697 /* do not clear encryption flag */
2698 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2699 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2700 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2701 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2703 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2706 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2708 struct ll_inode_info *lli = ll_i2info(inode);
2709 struct mdt_body *body = md->body;
2710 struct ll_sb_info *sbi = ll_i2sbi(inode);
2714 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2715 rc = cl_file_inode_init(inode, md);
2720 if (S_ISDIR(inode->i_mode)) {
2721 rc = ll_update_lsm_md(inode, md);
2726 if (body->mbo_valid & OBD_MD_FLACL)
2727 lli_replace_acl(lli, md);
2729 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2730 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2731 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2733 if (body->mbo_valid & OBD_MD_FLATIME) {
2734 if (body->mbo_atime > inode->i_atime.tv_sec)
2735 inode->i_atime.tv_sec = body->mbo_atime;
2736 lli->lli_atime = body->mbo_atime;
2739 if (body->mbo_valid & OBD_MD_FLMTIME) {
2740 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2742 "setting ino %lu mtime from %lld to %llu\n",
2743 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2745 inode->i_mtime.tv_sec = body->mbo_mtime;
2747 lli->lli_mtime = body->mbo_mtime;
2750 if (body->mbo_valid & OBD_MD_FLCTIME) {
2751 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2752 inode->i_ctime.tv_sec = body->mbo_ctime;
2753 lli->lli_ctime = body->mbo_ctime;
2756 if (body->mbo_valid & OBD_MD_FLBTIME)
2757 lli->lli_btime = body->mbo_btime;
2759 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2760 if (body->mbo_valid & OBD_MD_FLFLAGS)
2761 ll_update_inode_flags(inode, body->mbo_flags);
2762 if (body->mbo_valid & OBD_MD_FLMODE)
2763 inode->i_mode = (inode->i_mode & S_IFMT) |
2764 (body->mbo_mode & ~S_IFMT);
2766 if (body->mbo_valid & OBD_MD_FLTYPE)
2767 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2768 (body->mbo_mode & S_IFMT);
2770 LASSERT(inode->i_mode != 0);
2771 if (body->mbo_valid & OBD_MD_FLUID)
2772 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2773 if (body->mbo_valid & OBD_MD_FLGID)
2774 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2775 if (body->mbo_valid & OBD_MD_FLPROJID)
2776 lli->lli_projid = body->mbo_projid;
2777 if (body->mbo_valid & OBD_MD_FLNLINK) {
2778 spin_lock(&inode->i_lock);
2779 set_nlink(inode, body->mbo_nlink);
2780 spin_unlock(&inode->i_lock);
2782 if (body->mbo_valid & OBD_MD_FLRDEV)
2783 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2785 if (body->mbo_valid & OBD_MD_FLID) {
2786 /* FID shouldn't be changed! */
2787 if (fid_is_sane(&lli->lli_fid)) {
2788 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2789 "Trying to change FID "DFID
2790 " to the "DFID", inode "DFID"(%p)\n",
2791 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2792 PFID(ll_inode2fid(inode)), inode);
2794 lli->lli_fid = body->mbo_fid1;
2798 LASSERT(fid_seq(&lli->lli_fid) != 0);
2800 /* In case of encrypted file without the key, please do not lose
2801 * clear text size stored into lli_lazysize in ll_merge_attr(),
2802 * we will need it in ll_prepare_close().
2804 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2805 llcrypt_require_key(inode) == -ENOKEY)
2806 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2808 lli->lli_attr_valid = body->mbo_valid;
2809 if (body->mbo_valid & OBD_MD_FLSIZE) {
2810 i_size_write(inode, body->mbo_size);
2812 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2813 PFID(ll_inode2fid(inode)),
2814 (unsigned long long)body->mbo_size);
2816 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2817 inode->i_blocks = body->mbo_blocks;
2819 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2820 lli->lli_lazysize = body->mbo_size;
2821 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2822 lli->lli_lazyblocks = body->mbo_blocks;
2825 if (body->mbo_valid & OBD_MD_TSTATE) {
2826 /* Set LLIF_FILE_RESTORING if restore ongoing and
2827 * clear it when done to ensure to start again
2828 * glimpsing updated attrs
2830 if (body->mbo_t_state & MS_RESTORE)
2831 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2833 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2839 /* child default LMV is inherited from parent */
2840 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2841 struct lmv_stripe_md *cdmv)
2846 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2847 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2848 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2849 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2852 if (cdmv->lsm_md_max_inherit !=
2853 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2856 if (cdmv->lsm_md_max_inherit_rr !=
2857 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2863 /* if default LMV is implicitly inherited, subdir default LMV is maintained on
2866 static int ll_dir_default_lmv_inherit(struct inode *dir, struct inode *inode)
2868 struct ll_inode_info *plli = ll_i2info(dir);
2869 struct ll_inode_info *lli = ll_i2info(inode);
2870 struct lmv_stripe_md *plsm;
2871 struct lmv_stripe_md *lsm;
2876 /* ROOT default LMV is not inherited */
2877 if (is_root_inode(dir) ||
2878 !(exp_connect_flags2(ll_i2mdexp(dir)) &
2879 OBD_CONNECT2_DMV_IMP_INHERIT))
2882 /* nothing to do if no default LMV on both */
2883 if (!plli->lli_default_lsm_md && !lli->lli_default_lsm_md)
2886 /* subdir default LMV comes from disk */
2887 if (lli->lli_default_lsm_md && lli->lli_default_lmv_set)
2890 /* delete subdir default LMV if parent's is deleted or becomes
2893 down_read(&plli->lli_lsm_sem);
2894 plsm = plli->lli_default_lsm_md;
2895 if (!plsm || !lmv_is_inheritable(plsm->lsm_md_max_inherit)) {
2896 if (lli->lli_default_lsm_md && !lli->lli_default_lmv_set) {
2897 down_write(&lli->lli_lsm_sem);
2898 if (lli->lli_default_lsm_md &&
2899 !lli->lli_default_lmv_set) {
2900 lmv_free_memmd(lli->lli_default_lsm_md);
2901 lli->lli_default_lsm_md = NULL;
2902 lli->lli_inherit_depth = 0;
2904 up_write(&lli->lli_lsm_sem);
2906 GOTO(unlock_parent, rc = 0);
2909 /* do nothing if inherited LMV is unchanged */
2910 if (lli->lli_default_lsm_md) {
2912 down_read(&lli->lli_lsm_sem);
2913 if (!lli->lli_default_lmv_set)
2914 rc = lsm_md_inherited(plsm, lli->lli_default_lsm_md);
2915 up_read(&lli->lli_lsm_sem);
2917 GOTO(unlock_parent, rc = 0);
2920 /* inherit default LMV */
2921 down_write(&lli->lli_lsm_sem);
2922 if (lli->lli_default_lsm_md) {
2923 /* checked above, but in case of race, check again with lock */
2924 if (lli->lli_default_lmv_set)
2925 GOTO(unlock_child, rc = 0);
2926 /* always update subdir default LMV in case parent's changed */
2927 lsm = lli->lli_default_lsm_md;
2931 GOTO(unlock_child, rc = -ENOMEM);
2932 lli->lli_default_lsm_md = lsm;
2936 lsm->lsm_md_max_inherit = lmv_inherit_next(plsm->lsm_md_max_inherit);
2937 lsm->lsm_md_max_inherit_rr =
2938 lmv_inherit_rr_next(plsm->lsm_md_max_inherit_rr);
2939 lli->lli_inherit_depth = plli->lli_inherit_depth + 1;
2941 lsm_md_dump(D_INODE, lsm);
2945 up_write(&lli->lli_lsm_sem);
2947 up_read(&plli->lli_lsm_sem);
2952 enum lsm_sem_class {
2958 * Update directory depth and default LMV
2960 * Update directory depth to ROOT and inherit default LMV from parent if
2961 * parent's default LMV is inheritable. The default LMV set with command
2962 * "lfs setdirstripe -D ..." is stored on MDT, while the inherited default LMV
2963 * is generated at runtime on client side.
2965 * \param[in] dir parent directory inode
2966 * \param[in] de dentry
2968 void ll_update_dir_depth_dmv(struct inode *dir, struct dentry *de)
2970 struct inode *inode = de->d_inode;
2971 struct ll_inode_info *plli;
2972 struct ll_inode_info *lli;
2974 LASSERT(S_ISDIR(inode->i_mode));
2978 plli = ll_i2info(dir);
2979 lli = ll_i2info(inode);
2980 lli->lli_dir_depth = plli->lli_dir_depth + 1;
2981 if (lli->lli_default_lsm_md && lli->lli_default_lmv_set) {
2982 if (plli->lli_default_lsm_md) {
2983 down_read_nested(&plli->lli_lsm_sem, LSM_SEM_PARENT);
2984 down_read_nested(&lli->lli_lsm_sem, LSM_SEM_CHILD);
2985 if (lsm_md_inherited(plli->lli_default_lsm_md,
2986 lli->lli_default_lsm_md))
2987 lli->lli_inherit_depth =
2988 plli->lli_inherit_depth + 1;
2990 /* in case parent default LMV changed */
2991 lli->lli_inherit_depth = 0;
2992 up_read(&lli->lli_lsm_sem);
2993 up_read(&plli->lli_lsm_sem);
2995 /* in case parent default LMV deleted */
2996 lli->lli_inherit_depth = 0;
2999 ll_dir_default_lmv_inherit(dir, inode);
3002 if (lli->lli_default_lsm_md)
3004 "%s "DFID" depth %hu %s default LMV inherit depth %hu\n",
3005 de->d_name.name, PFID(&lli->lli_fid), lli->lli_dir_depth,
3006 lli->lli_default_lmv_set ? "server" : "client",
3007 lli->lli_inherit_depth);
3010 void ll_truncate_inode_pages_final(struct inode *inode)
3012 struct address_space *mapping = &inode->i_data;
3013 unsigned long nrpages;
3014 unsigned long flags;
3016 LASSERTF((inode->i_state & I_FREEING) || inode_is_locked(inode),
3017 DFID ":inode %p state %#lx, lli_flags %#lx\n",
3018 PFID(ll_inode2fid(inode)), inode, inode->i_state,
3019 ll_i2info(inode)->lli_flags);
3021 truncate_inode_pages_final(mapping);
3023 /* Workaround for LU-118: Note nrpages may not be totally updated when
3024 * truncate_inode_pages() returns, as there can be a page in the process
3025 * of deletion (inside __delete_from_page_cache()) in the specified
3026 * range. Thus mapping->nrpages can be non-zero when this function
3027 * returns even after truncation of the whole mapping. Only do this if
3028 * npages isn't already zero.
3030 nrpages = mapping->nrpages;
3032 ll_xa_lock_irqsave(&mapping->i_pages, flags);
3033 nrpages = mapping->nrpages;
3034 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
3035 } /* Workaround end */
3037 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu "
3038 "state %#lx, lli_flags %#lx, "
3039 "see https://jira.whamcloud.com/browse/LU-118\n",
3040 ll_i2sbi(inode)->ll_fsname,
3041 PFID(ll_inode2fid(inode)), inode, nrpages,
3042 inode->i_state, ll_i2info(inode)->lli_flags);
3045 int ll_read_inode2(struct inode *inode, void *opaque)
3047 struct lustre_md *md = opaque;
3048 struct ll_inode_info *lli = ll_i2info(inode);
3052 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
3053 PFID(&lli->lli_fid), inode);
3055 /* Core attributes from the MDS first. This is a new inode, and
3056 * the VFS doesn't zero times in the core inode so we have to do
3057 * it ourselves. They will be overwritten by either MDS or OST
3058 * attributes - we just need to make sure they aren't newer.
3060 inode->i_mtime.tv_sec = 0;
3061 inode->i_atime.tv_sec = 0;
3062 inode->i_ctime.tv_sec = 0;
3064 rc = ll_update_inode(inode, md);
3068 /* OIDEBUG(inode); */
3070 #ifdef HAVE_BACKING_DEV_INFO
3071 /* initializing backing dev info. */
3072 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
3074 if (S_ISREG(inode->i_mode)) {
3075 struct ll_sb_info *sbi = ll_i2sbi(inode);
3076 inode->i_op = &ll_file_inode_operations;
3077 inode->i_fop = sbi->ll_fop;
3078 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
3080 } else if (S_ISDIR(inode->i_mode)) {
3081 inode->i_op = &ll_dir_inode_operations;
3082 inode->i_fop = &ll_dir_operations;
3084 } else if (S_ISLNK(inode->i_mode)) {
3085 inode->i_op = &ll_fast_symlink_inode_operations;
3088 inode->i_op = &ll_special_inode_operations;
3090 init_special_inode(inode, inode->i_mode,
3099 void ll_delete_inode(struct inode *inode)
3101 struct ll_inode_info *lli = ll_i2info(inode);
3104 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
3105 /* It is last chance to write out dirty pages,
3106 * otherwise we may lose data while umount.
3108 * If i_nlink is 0 then just discard data. This is safe because
3109 * local inode gets i_nlink 0 from server only for the last
3110 * unlink, so that file is not opened somewhere else
3112 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
3113 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
3116 ll_truncate_inode_pages_final(inode);
3117 ll_clear_inode(inode);
3123 static int fileattr_get(struct inode *inode, int *flags,
3127 struct ll_sb_info *sbi = ll_i2sbi(inode);
3128 struct ptlrpc_request *req = NULL;
3129 struct md_op_data *op_data;
3130 struct mdt_body *body;
3134 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
3135 0, 0, LUSTRE_OPC_ANY,
3137 if (IS_ERR(op_data))
3138 RETURN(PTR_ERR(op_data));
3140 op_data->op_valid = OBD_MD_FLFLAGS;
3141 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
3142 ll_finish_md_op_data(op_data);
3144 CERROR("%s: failure inode "DFID": rc = %d\n",
3145 sbi->ll_md_exp->exp_obd->obd_name,
3146 PFID(ll_inode2fid(inode)), rc);
3150 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3152 *flags = body->mbo_flags;
3153 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
3154 * ext4 equivalent to please lsattr and other e2fsprogs tools
3156 if (*flags & LUSTRE_ENCRYPT_FL)
3157 *flags |= STATX_ATTR_ENCRYPTED;
3159 ptlrpc_req_finished(req);
3161 *xflags = ll_inode_flags_to_xflags(inode->i_flags);
3162 if (test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags))
3163 *xflags |= FS_XFLAG_PROJINHERIT;
3164 *projid = ll_i2info(inode)->lli_projid;
3169 static int fileattr_set(struct inode *inode, int flags)
3171 struct ll_sb_info *sbi = ll_i2sbi(inode);
3172 struct ptlrpc_request *req = NULL;
3173 struct md_op_data *op_data;
3174 struct cl_object *obj;
3175 struct fsxattr fa = { 0 };
3180 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3181 if (flags & LUSTRE_PROJINHERIT_FL)
3182 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3184 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3189 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3190 LUSTRE_OPC_ANY, NULL);
3191 if (IS_ERR(op_data))
3192 RETURN(PTR_ERR(op_data));
3194 op_data->op_attr_flags = flags;
3195 op_data->op_xvalid |= OP_XVALID_FLAGS;
3196 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3197 ll_finish_md_op_data(op_data);
3198 ptlrpc_req_finished(req);
3202 ll_update_inode_flags(inode, flags);
3204 obj = ll_i2info(inode)->lli_clob;
3208 OBD_ALLOC_PTR(attr);
3212 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3218 #ifdef HAVE_FILEATTR_GET
3219 int ll_fileattr_get(struct dentry *dentry, struct fileattr *fa)
3221 return fileattr_get(d_inode(dentry), &fa->flags,
3222 &fa->fsx_xflags, &fa->fsx_projid);
3225 int ll_fileattr_set(struct user_namespace *mnt_userns,
3226 struct dentry *dentry, struct fileattr *fa)
3229 return ll_set_project(d_inode(dentry), fa->fsx_xflags,
3232 return fileattr_set(d_inode(dentry), fa->flags);
3234 #endif /* HAVE_FILEATTR_GET */
3236 /* ioctl commands shared between files and directories */
3237 int ll_iocontrol(struct inode *inode, struct file *file,
3238 unsigned int cmd, void __user *uarg)
3245 RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
3246 case LL_IOC_GETVERSION:
3247 case FS_IOC_GETVERSION:
3248 RETURN(put_user(inode->i_generation, (int __user *)uarg));
3250 #ifndef HAVE_FILEATTR_GET
3251 case FS_IOC_GETFLAGS: {
3252 u32 xflags = 0, projid = 0;
3255 if (!ll_access_ok(uarg, sizeof(int)))
3257 rc = fileattr_get(file->f_inode, &flags, &xflags, &projid);
3261 RETURN(put_user(flags, (int __user *)uarg));
3263 case FS_IOC_SETFLAGS: {
3266 if (get_user(flags, (int __user *)uarg))
3269 RETURN(fileattr_set(file->f_inode, flags));
3271 case FS_IOC_FSGETXATTR:
3272 RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
3273 case FS_IOC_FSSETXATTR:
3274 RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
3275 #endif /* HAVE_FILEATTR_GET */
3276 case LL_IOC_PROJECT:
3277 RETURN(ll_ioctl_project(file, cmd, uarg));
3278 case IOC_OBD_STATFS:
3279 RETURN(ll_obd_statfs(inode, uarg));
3280 case LL_IOC_GET_MDTIDX: {
3281 if (!ll_access_ok(uarg, sizeof(rc)))
3284 rc = ll_get_mdt_idx(inode);
3288 if (put_user(rc, (int __user *)uarg))
3293 case LL_IOC_FLUSHCTX:
3294 RETURN(ll_flush_ctx(inode));
3295 #ifdef HAVE_LUSTRE_CRYPTO
3296 case LL_IOC_ADD_ENCRYPTION_KEY:
3297 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3299 rc = llcrypt_ioctl_add_key(file, uarg);
3300 #ifdef CONFIG_LL_ENCRYPTION
3301 if (!rc && S_ISDIR(inode->i_mode))
3302 sptlrpc_enc_pool_add_user();
3305 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
3306 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3308 RETURN(llcrypt_ioctl_get_key_status(file, uarg));
3309 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
3310 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3312 RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
3313 case LL_IOC_SET_ENCRYPTION_POLICY:
3314 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3316 RETURN(llcrypt_ioctl_set_policy(file, uarg));
3317 case LL_IOC_REMOVE_ENCRYPTION_KEY:
3318 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3320 RETURN(llcrypt_ioctl_remove_key(file, uarg));
3321 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
3322 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3324 RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
3326 case LL_IOC_GETPARENT:
3327 RETURN(ll_getparent(file, uarg));
3328 case LL_IOC_PATH2FID:
3329 if (copy_to_user(uarg, ll_inode2fid(inode),
3330 sizeof(struct lu_fid)))
3333 case LL_IOC_UNLOCK_FOREIGN: {
3334 struct dentry *dentry = file_dentry(file);
3336 /* if not a foreign symlink do nothing */
3337 if (ll_foreign_is_removable(dentry, true)) {
3339 "prevent unlink of non-foreign file ("DFID")\n",
3340 PFID(ll_inode2fid(inode)));
3341 RETURN(-EOPNOTSUPP);
3345 case OBD_IOC_FID2PATH:
3346 RETURN(ll_fid2path(inode, uarg));
3347 #ifdef OBD_IOC_GETNAME_OLD
3348 case_OBD_IOC_DEPRECATED_FT(OBD_IOC_GETNAME_OLD,
3349 ll_i2sbi(inode)->ll_md_exp->exp_obd->obd_name,
3352 case OBD_IOC_GETDTNAME:
3353 case OBD_IOC_GETMDNAME:
3354 RETURN(ll_get_obd_name(inode, cmd, uarg));
3362 int ll_flush_ctx(struct inode *inode)
3364 struct ll_sb_info *sbi = ll_i2sbi(inode);
3366 CDEBUG(D_SEC, "flush context for user %d\n",
3367 from_kuid(&init_user_ns, current_uid()));
3369 obd_set_info_async(NULL, sbi->ll_md_exp,
3370 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3372 obd_set_info_async(NULL, sbi->ll_dt_exp,
3373 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3378 /* umount -f client means force down, don't save state */
3379 void ll_umount_begin(struct super_block *sb)
3381 struct ll_sb_info *sbi = ll_s2sbi(sb);
3382 struct obd_device *obd;
3383 struct obd_ioctl_data *ioc_data;
3387 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3388 sb->s_count, atomic_read(&sb->s_active));
3390 obd = class_exp2obd(sbi->ll_md_exp);
3392 CERROR("Invalid MDC connection handle %#llx\n",
3393 sbi->ll_md_exp->exp_handle.h_cookie);
3399 obd = class_exp2obd(sbi->ll_dt_exp);
3401 CERROR("Invalid LOV connection handle %#llx\n",
3402 sbi->ll_dt_exp->exp_handle.h_cookie);
3408 OBD_ALLOC_PTR(ioc_data);
3410 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_md_exp,
3411 sizeof *ioc_data, ioc_data, NULL);
3413 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_dt_exp,
3414 sizeof *ioc_data, ioc_data, NULL);
3416 OBD_FREE_PTR(ioc_data);
3419 /* Really, we'd like to wait until there are no requests outstanding,
3420 * and then continue. For now, we just periodically checking for vfs
3421 * to decrement mnt_cnt and hope to finish it within 10sec.
3425 !may_umount(sbi->ll_mnt.mnt)) {
3433 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3435 struct ll_sb_info *sbi = ll_s2sbi(sb);
3436 char *profilenm = get_profile_name(sb);
3440 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3441 read_only = *flags & MS_RDONLY;
3442 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3443 sizeof(KEY_READ_ONLY),
3444 KEY_READ_ONLY, sizeof(read_only),
3447 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3448 profilenm, read_only ?
3449 "read-only" : "read-write", err);
3454 sb->s_flags |= SB_RDONLY;
3456 sb->s_flags &= ~SB_RDONLY;
3458 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3459 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3460 read_only ? "read-only" : "read-write");
3466 * Cleanup the open handle that is cached on MDT-side.
3468 * For open case, the client side open handling thread may hit error
3469 * after the MDT grant the open. Under such case, the client should
3470 * send close RPC to the MDT as cleanup; otherwise, the open handle
3471 * on the MDT will be leaked there until the client umount or evicted.
3473 * In further, if someone unlinked the file, because the open handle
3474 * holds the reference on such file/object, then it will block the
3475 * subsequent threads that want to locate such object via FID.
3477 * \param[in] sb super block for this file-system
3478 * \param[in] open_req pointer to the original open request
3480 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3482 struct mdt_body *body;
3483 struct md_op_data *op_data;
3484 struct ptlrpc_request *close_req = NULL;
3485 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3488 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3489 OBD_ALLOC_PTR(op_data);
3490 if (op_data == NULL) {
3491 CWARN("%s: cannot allocate op_data to release open handle for "
3492 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3497 op_data->op_fid1 = body->mbo_fid1;
3498 op_data->op_open_handle = body->mbo_open_handle;
3499 op_data->op_mod_time = ktime_get_real_seconds();
3500 md_close(exp, op_data, NULL, &close_req);
3501 ptlrpc_req_finished(close_req);
3502 ll_finish_md_op_data(op_data);
3507 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3508 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3509 struct lustre_md *md)
3511 struct ll_sb_info *sbi = ll_i2sbi(inode);
3512 struct ptlrpc_request *req = NULL;
3513 union lmv_mds_md *lmm = NULL;
3517 LASSERT(is_root_inode(inode));
3518 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3519 LASSERT(!md->default_lmv);
3521 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3523 GET_DEFAULT_LAYOUT_ROOT);
3524 if (rc && rc != -ENODATA)
3529 rc = md_unpackmd(sbi->ll_md_exp, &md->default_lmv, lmm, size);
3538 ptlrpc_req_finished(req);
3542 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3543 struct super_block *sb, struct lookup_intent *it)
3545 struct ll_sb_info *sbi = NULL;
3546 struct lustre_md md = { NULL };
3547 bool default_lmv_deleted = false;
3552 LASSERT(*inode || sb);
3553 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3554 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3555 sbi->ll_md_exp, &md);
3560 * clear default_lmv only if intent_getattr reply doesn't contain it.
3561 * but it needs to be done after iget, check this early because
3562 * ll_update_lsm_md() may change md.
3564 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3565 S_ISDIR(md.body->mbo_mode) && !md.default_lmv) {
3566 if (unlikely(*inode && is_root_inode(*inode) &&
3567 !fid_is_root(&sbi->ll_root_fid))) {
3568 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3573 if (!md.default_lmv)
3574 default_lmv_deleted = true;
3578 rc = ll_update_inode(*inode, &md);
3582 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3583 struct lu_fid *fid1 = &md.body->mbo_fid1;
3585 LASSERT(sb != NULL);
3588 * At this point server returns to client's same fid as client
3589 * generated for creating. So using ->fid1 is okay here.
3591 if (!fid_is_sane(fid1)) {
3592 CERROR("%s: Fid is insane "DFID"\n",
3593 sbi->ll_fsname, PFID(fid1));
3594 GOTO(out, rc = -EINVAL);
3597 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3598 if (IS_ERR(*inode)) {
3600 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3602 CERROR("new_inode -fatal: rc %d\n", rc);
3607 /* Handling piggyback layout lock.
3608 * Layout lock can be piggybacked by getattr and open request.
3609 * The lsm can be applied to inode only if it comes with a layout lock
3610 * otherwise correct layout may be overwritten, for example:
3611 * 1. proc1: mdt returns a lsm but not granting layout
3612 * 2. layout was changed by another client
3613 * 3. proc2: refresh layout and layout lock granted
3614 * 4. proc1: to apply a stale layout */
3615 if (it != NULL && it->it_lock_mode != 0) {
3616 struct lustre_handle lockh;
3617 struct ldlm_lock *lock;
3619 lockh.cookie = it->it_lock_handle;
3620 lock = ldlm_handle2lock(&lockh);
3621 LASSERT(lock != NULL);
3622 if (ldlm_has_layout(lock)) {
3623 struct cl_object_conf conf;
3625 memset(&conf, 0, sizeof(conf));
3626 conf.coc_opc = OBJECT_CONF_SET;
3627 conf.coc_inode = *inode;
3628 conf.coc_lock = lock;
3629 conf.u.coc_layout = md.layout;
3630 (void)ll_layout_conf(*inode, &conf);
3632 LDLM_LOCK_PUT(lock);
3635 if (default_lmv_deleted)
3636 ll_update_default_lsm_md(*inode, &md);
3638 /* we may want to apply some policy for foreign file/dir */
3639 if (ll_sbi_has_foreign_symlink(sbi)) {
3640 rc = ll_manage_foreign(*inode, &md);
3648 /* cleanup will be done if necessary */
3649 md_free_lustre_md(sbi->ll_md_exp, &md);
3651 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3652 ll_intent_drop_lock(it);
3653 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3659 int ll_obd_statfs(struct inode *inode, void __user *uarg)
3661 struct ll_sb_info *sbi = NULL;
3662 struct obd_export *exp;
3663 struct obd_ioctl_data *data = NULL;
3668 sbi = ll_i2sbi(inode);
3670 GOTO(out_statfs, rc = -EINVAL);
3672 rc = obd_ioctl_getdata(&data, &len, uarg);
3674 GOTO(out_statfs, rc);
3676 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3677 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3678 GOTO(out_statfs, rc = -EINVAL);
3680 if (data->ioc_inllen1 != sizeof(__u32) ||
3681 data->ioc_inllen2 != sizeof(__u32) ||
3682 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3683 data->ioc_plen2 != sizeof(struct obd_uuid))
3684 GOTO(out_statfs, rc = -EINVAL);
3686 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3687 if (type & LL_STATFS_LMV)
3688 exp = sbi->ll_md_exp;
3689 else if (type & LL_STATFS_LOV)
3690 exp = sbi->ll_dt_exp;
3692 GOTO(out_statfs, rc = -ENODEV);
3694 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3696 GOTO(out_statfs, rc);
3698 OBD_FREE_LARGE(data, len);
3703 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3704 * be called early to avoid deadlock.
3706 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3708 if (op_data->op_mea2_sem) {
3709 up_read_non_owner(op_data->op_mea2_sem);
3710 op_data->op_mea2_sem = NULL;
3713 if (op_data->op_mea1_sem) {
3714 up_read_non_owner(op_data->op_mea1_sem);
3715 op_data->op_mea1_sem = NULL;
3719 /* this function prepares md_op_data hint for passing it down to MD stack. */
3720 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3721 struct inode *i1, struct inode *i2,
3722 const char *name, size_t namelen,
3723 __u32 mode, enum md_op_code opc,
3726 struct llcrypt_name fname = { 0 };
3729 LASSERT(i1 != NULL);
3732 /* Do not reuse namelen for something else. */
3734 return ERR_PTR(-EINVAL);
3736 if ((!IS_ENCRYPTED(i1) ||
3737 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3738 namelen > ll_i2sbi(i1)->ll_namelen)
3739 return ERR_PTR(-ENAMETOOLONG);
3741 /* "/" is not valid name, but it's allowed */
3742 if (!lu_name_is_valid_2(name, namelen) &&
3743 strncmp("/", name, namelen) != 0)
3744 return ERR_PTR(-EINVAL);
3747 if (op_data == NULL)
3748 OBD_ALLOC_PTR(op_data);
3750 if (op_data == NULL)
3751 return ERR_PTR(-ENOMEM);
3753 ll_i2gids(op_data->op_suppgids, i1, i2);
3754 /* If the client is using a subdir mount and looks at what it sees as
3755 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3757 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3758 !fid_is_root(ll_inode2fid(i1)) &&
3759 name && namelen == strlen(dot_fscrypt_name) &&
3760 strncmp(name, dot_fscrypt_name, namelen) == 0))
3761 lu_root_fid(&op_data->op_fid1);
3763 op_data->op_fid1 = *ll_inode2fid(i1);
3765 if (S_ISDIR(i1->i_mode)) {
3766 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3767 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3768 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3769 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3773 op_data->op_fid2 = *ll_inode2fid(i2);
3774 if (S_ISDIR(i2->i_mode)) {
3776 /* i2 is typically a child of i1, and MUST be
3777 * further from the root to avoid deadlocks.
3779 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3780 op_data->op_mea2_sem =
3781 &ll_i2info(i2)->lli_lsm_sem;
3783 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3786 fid_zero(&op_data->op_fid2);
3789 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3790 op_data->op_cli_flags |= CLI_HASH64;
3792 if (ll_need_32bit_api(ll_i2sbi(i1)))
3793 op_data->op_cli_flags |= CLI_API32;
3795 if ((i2 && is_root_inode(i2)) ||
3796 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3797 /* In case of lookup, ll_setup_filename() has already been
3798 * called in ll_lookup_it(), so just take provided name.
3799 * Also take provided name if we are dealing with root inode.
3801 fname.disk_name.name = (unsigned char *)name;
3802 fname.disk_name.len = namelen;
3803 } else if (name && namelen) {
3804 struct qstr dname = QSTR_INIT(name, namelen);
3806 struct lu_fid *pfid = NULL;
3810 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3811 /* special case when called from ll_link() */
3816 lookup = (int)(opc == LUSTRE_OPC_ANY);
3818 if (opc == LUSTRE_OPC_ANY && lookup)
3820 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3822 ll_finish_md_op_data(op_data);
3825 if (pfid && !fid_is_zero(pfid)) {
3827 op_data->op_fid2 = fid;
3828 op_data->op_bias = MDS_FID_OP;
3830 if (fname.disk_name.name &&
3831 fname.disk_name.name != (unsigned char *)name) {
3832 /* op_data->op_name must be freed after use */
3833 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3837 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3838 * are LUSTRE_OPC_ANY
3840 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3841 op_data->op_code = LUSTRE_OPC_ANY;
3843 op_data->op_code = opc;
3844 op_data->op_name = fname.disk_name.name;
3845 op_data->op_namelen = fname.disk_name.len;
3846 op_data->op_mode = mode;
3847 op_data->op_mod_time = ktime_get_real_seconds();
3848 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3849 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3850 op_data->op_cap = current_cap();
3851 op_data->op_mds = 0;
3852 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3853 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3854 op_data->op_bias |= MDS_CREATE_VOLATILE;
3856 op_data->op_data = data;
3861 void ll_finish_md_op_data(struct md_op_data *op_data)
3863 ll_unlock_md_op_lsm(op_data);
3864 ll_security_release_secctx(op_data->op_file_secctx,
3865 op_data->op_file_secctx_size,
3866 op_data->op_file_secctx_slot);
3867 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3868 /* allocated via ll_setup_filename called
3869 * from ll_prep_md_op_data
3871 kfree(op_data->op_name);
3872 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3873 OBD_FREE_PTR(op_data);
3876 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3878 struct ll_sb_info *sbi;
3881 LASSERT(seq && dentry);
3882 sbi = ll_s2sbi(dentry->d_sb);
3884 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3885 seq_puts(seq, "nolock");
3887 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3888 /* match_table in some cases has patterns for both enabled and
3889 * disabled cases. Ignore 'no'xxx versions if bit is set.
3891 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3892 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3893 if (ll_sbi_flags_name[i].token ==
3894 LL_SBI_FOREIGN_SYMLINK) {
3895 seq_show_option(seq, "foreign_symlink",
3896 sbi->ll_foreign_symlink_prefix);
3898 seq_printf(seq, ",%s",
3899 ll_sbi_flags_name[i].pattern);
3902 /* You can have either localflock or flock but not
3903 * both. If localflock is set don't print flock or
3906 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3908 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3909 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3910 seq_printf(seq, ",%s",
3911 ll_sbi_flags_name[i].pattern);
3915 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3921 * Get obd name by cmd, and copy out to user space
3923 int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg)
3925 struct ll_sb_info *sbi = ll_i2sbi(inode);
3926 struct obd_device *obd;
3929 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3930 obd = class_exp2obd(sbi->ll_dt_exp);
3931 else if (cmd == OBD_IOC_GETMDNAME)
3932 obd = class_exp2obd(sbi->ll_md_exp);
3939 if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1))
3946 struct work_struct db_work;
3947 struct dentry *db_dentry;
3948 /* Let's hope the path is not too long, 32 bytes for the work struct
3951 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3954 static void ll_dput_later(struct work_struct *work)
3956 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3958 dput(db->db_dentry);
3959 free_page((unsigned long)db);
3962 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3969 p.mnt = current->fs->root.mnt;
3971 path = d_path(&p, buf, bufsize);
3976 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3978 struct dname_buf *db;
3980 struct dentry *dentry = NULL;
3982 /* this can be called inside spin lock so use GFP_ATOMIC. */
3983 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3986 dentry = d_find_alias(inode);
3988 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3991 /* The below message is checked in recovery-small.sh test_24b */
3993 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3994 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3995 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3996 PFID(ll_inode2fid(inode)),
3997 (path && !IS_ERR(path)) ? path : "", ioret);
3999 if (dentry != NULL) {
4000 /* We cannot dput here since if we happen to be the last holder
4001 * then we can end up waiting for page evictions that
4002 * in turn wait for RPCs that need this instance of ptlrpcd
4003 * (callng brw_interpret->*page_completion*->vmpage_error->here)
4006 INIT_WORK(&db->db_work, ll_dput_later);
4007 db->db_dentry = dentry;
4008 schedule_work(&db->db_work);
4011 free_page((unsigned long)db);
4015 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
4016 struct lov_user_md **kbuf)
4018 struct lov_user_md lum;
4022 if (copy_from_user(&lum, md, sizeof(lum)))
4025 lum_size = ll_lov_user_md_size(&lum);
4029 OBD_ALLOC_LARGE(*kbuf, lum_size);
4033 if (copy_from_user(*kbuf, md, lum_size) != 0) {
4034 OBD_FREE_LARGE(*kbuf, lum_size);
4042 * Compute llite root squash state after a change of root squash
4043 * configuration setting or add/remove of a lnet nid
4045 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
4047 struct root_squash_info *squash = &sbi->ll_squash;
4050 struct lnet_processid id;
4052 /* Update norootsquash flag */
4053 spin_lock(&squash->rsi_lock);
4054 if (list_empty(&squash->rsi_nosquash_nids))
4055 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4057 /* Do not apply root squash as soon as one of our NIDs is
4058 * in the nosquash_nids list */
4061 while (LNetGetId(i++, &id) != -ENOENT) {
4062 if (nid_is_lo0(&id.nid))
4064 if (cfs_match_nid(&id.nid,
4065 &squash->rsi_nosquash_nids)) {
4071 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4073 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4075 spin_unlock(&squash->rsi_lock);
4079 * Parse linkea content to extract information about a given hardlink
4081 * \param[in] ldata - Initialized linkea data
4082 * \param[in] linkno - Link identifier
4083 * \param[out] parent_fid - The entry's parent FID
4084 * \param[out] ln - Entry name destination buffer
4086 * \retval 0 on success
4087 * \retval Appropriate negative error code on failure
4089 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
4090 struct lu_fid *parent_fid, struct lu_name *ln)
4096 rc = linkea_init_with_rec(ldata);
4100 if (linkno >= ldata->ld_leh->leh_reccount)
4101 /* beyond last link */
4104 linkea_first_entry(ldata);
4105 for (idx = 0; ldata->ld_lee != NULL; idx++) {
4106 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
4111 linkea_next_entry(ldata);
4121 * Get parent FID and name of an identified link. Operation is performed for
4122 * a given link number, letting the caller iterate over linkno to list one or
4123 * all links of an entry.
4125 * \param[in] file - File descriptor against which to perform the operation
4126 * \param[in,out] arg - User-filled structure containing the linkno to operate
4127 * on and the available size. It is eventually filled with
4128 * the requested information or left untouched on error
4130 * \retval - 0 on success
4131 * \retval - Appropriate negative error code on failure
4133 int ll_getparent(struct file *file, struct getparent __user *arg)
4135 struct inode *inode = file_inode(file);
4136 struct linkea_data *ldata;
4137 struct lu_buf buf = LU_BUF_NULL;
4139 struct lu_fid parent_fid;
4146 if (!capable(CAP_DAC_READ_SEARCH) &&
4147 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
4150 if (get_user(name_size, &arg->gp_name_size))
4153 if (get_user(linkno, &arg->gp_linkno))
4156 if (name_size > PATH_MAX)
4159 OBD_ALLOC(ldata, sizeof(*ldata));
4163 rc = linkea_data_new(ldata, &buf);
4165 GOTO(ldata_free, rc);
4167 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
4168 buf.lb_len, OBD_MD_FLXATTR);
4172 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
4176 if (ln.ln_namelen >= name_size)
4177 GOTO(lb_free, rc = -EOVERFLOW);
4179 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
4180 GOTO(lb_free, rc = -EFAULT);
4182 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
4183 GOTO(lb_free, rc = -EFAULT);
4185 if (put_user('\0', arg->gp_name + ln.ln_namelen))
4186 GOTO(lb_free, rc = -EFAULT);
4191 OBD_FREE(ldata, sizeof(*ldata));