4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/llite/llite_lib.c
33 * Lustre Light Super operations
36 #define DEBUG_SUBSYSTEM S_LLITE
38 #include <linux/cpu.h>
39 #include <linux/delay.h>
40 #include <linux/file.h>
41 #include <linux/fs_struct.h>
43 #include <linux/module.h>
44 #include <linux/random.h>
45 #include <linux/statfs.h>
46 #include <linux/time.h>
47 #include <linux/types.h>
48 #include <linux/uaccess.h>
49 #include <linux/uidgid.h>
50 #include <linux/user_namespace.h>
51 #include <linux/uuid.h>
52 #include <linux/version.h>
53 #ifdef HAVE_FILEATTR_GET
54 #include <linux/fileattr.h>
57 #ifndef HAVE_CPUS_READ_LOCK
58 #include <libcfs/linux/linux-cpu.h>
60 #include <libcfs/linux/linux-misc.h>
61 #include <uapi/linux/lustre/lustre_ioctl.h>
62 #include <lustre_ioctl_old.h>
63 #ifdef HAVE_UAPI_LINUX_MOUNT_H
64 #include <uapi/linux/mount.h>
67 #include <lustre_ha.h>
68 #include <lustre_dlm.h>
69 #include <lprocfs_status.h>
70 #include <lustre_disk.h>
71 #include <uapi/linux/lustre/lustre_param.h>
72 #include <lustre_log.h>
73 #include <cl_object.h>
74 #include <obd_cksum.h>
75 #include "llite_internal.h"
77 struct kmem_cache *ll_file_data_slab;
80 #define log2(n) ffz(~(n))
84 * If there is only one number of core visible to Lustre,
85 * async readahead will be disabled, to avoid massive over
86 * subscription, we use 1/2 of active cores as default max
87 * async readahead requests.
89 static inline unsigned int ll_get_ra_async_max_active(void)
91 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
94 static struct ll_sb_info *ll_init_sbi(struct lustre_sb_info *lsi)
96 struct ll_sb_info *sbi = NULL;
98 unsigned long lru_page_max;
106 RETURN(ERR_PTR(-ENOMEM));
108 rc = pcc_super_init(&sbi->ll_pcc_super);
112 spin_lock_init(&sbi->ll_lock);
113 mutex_init(&sbi->ll_lco.lco_lock);
114 spin_lock_init(&sbi->ll_pp_extent_lock);
115 spin_lock_init(&sbi->ll_process_lock);
117 sbi->ll_rw_stats_on = 0;
118 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
121 pages = si.totalram - si.totalhigh;
122 lru_page_max = pages / 2;
124 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
125 sbi->ll_ra_info.ll_readahead_wq =
126 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
128 sbi->ll_ra_info.ra_async_max_active);
129 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
130 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
132 /* initialize ll_cache data */
133 sbi->ll_cache = cl_cache_init(lru_page_max);
134 if (sbi->ll_cache == NULL)
135 GOTO(out_destroy_ra, rc = -ENOMEM);
137 /* initialize foreign symlink prefix path */
138 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
139 if (sbi->ll_foreign_symlink_prefix == NULL)
140 GOTO(out_destroy_ra, rc = -ENOMEM);
141 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
142 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
144 /* initialize foreign symlink upcall path, none by default */
145 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
146 if (sbi->ll_foreign_symlink_upcall == NULL)
147 GOTO(out_destroy_ra, rc = -ENOMEM);
148 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
149 sbi->ll_foreign_symlink_upcall_items = NULL;
150 sbi->ll_foreign_symlink_upcall_nb_items = 0;
151 init_rwsem(&sbi->ll_foreign_symlink_sem);
152 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
153 * not enabled by default
156 sbi->ll_secctx_name = NULL;
157 sbi->ll_secctx_name_size = 0;
159 sbi->ll_ra_info.ra_max_pages =
160 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
161 sbi->ll_ra_info.ra_max_pages_per_file =
162 min(sbi->ll_ra_info.ra_max_pages / 4,
163 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
164 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
165 sbi->ll_ra_info.ra_max_pages_per_file;
166 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
167 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
168 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
170 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
171 #ifdef CONFIG_ENABLE_CHECKSUM
172 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
174 #ifdef CONFIG_ENABLE_FLOCK
175 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
178 #ifdef HAVE_LRU_RESIZE_SUPPORT
179 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
181 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
183 /* metadata statahead is enabled by default */
184 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
185 sbi->ll_sa_batch_max = LL_SA_BATCH_DEF;
186 sbi->ll_sa_max = LL_SA_RPC_DEF;
187 atomic_set(&sbi->ll_sa_total, 0);
188 atomic_set(&sbi->ll_sa_wrong, 0);
189 atomic_set(&sbi->ll_sa_running, 0);
190 atomic_set(&sbi->ll_agl_total, 0);
191 atomic_set(&sbi->ll_sa_hit_total, 0);
192 atomic_set(&sbi->ll_sa_miss_total, 0);
193 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
194 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
195 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
196 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
197 ll_sbi_set_encrypt(sbi, true);
198 ll_sbi_set_name_encrypt(sbi, true);
201 sbi->ll_squash.rsi_uid = 0;
202 sbi->ll_squash.rsi_gid = 0;
203 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
204 spin_lock_init(&sbi->ll_squash.rsi_lock);
206 /* Per-filesystem file heat */
207 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
208 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
210 /* Per-fs open heat level before requesting open lock */
211 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
212 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
213 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
216 if (sbi->ll_foreign_symlink_prefix)
217 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
219 cl_cache_decref(sbi->ll_cache);
220 sbi->ll_cache = NULL;
222 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
224 pcc_super_fini(&sbi->ll_pcc_super);
230 static void ll_free_sbi(struct super_block *sb)
232 struct ll_sb_info *sbi = ll_s2sbi(sb);
236 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
237 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
238 if (sbi->ll_ra_info.ll_readahead_wq)
239 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
240 if (sbi->ll_cache != NULL) {
241 cl_cache_decref(sbi->ll_cache);
242 sbi->ll_cache = NULL;
244 if (sbi->ll_foreign_symlink_prefix) {
245 OBD_FREE(sbi->ll_foreign_symlink_prefix,
246 sbi->ll_foreign_symlink_prefix_size);
247 sbi->ll_foreign_symlink_prefix = NULL;
249 if (sbi->ll_foreign_symlink_upcall) {
250 OBD_FREE(sbi->ll_foreign_symlink_upcall,
251 strlen(sbi->ll_foreign_symlink_upcall) +
253 sbi->ll_foreign_symlink_upcall = NULL;
255 if (sbi->ll_foreign_symlink_upcall_items) {
257 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
258 struct ll_foreign_symlink_upcall_item *items =
259 sbi->ll_foreign_symlink_upcall_items;
261 for (i = 0 ; i < nb_items; i++)
262 if (items[i].type == STRING_TYPE)
263 OBD_FREE(items[i].string,
266 OBD_FREE_LARGE(items, nb_items *
267 sizeof(struct ll_foreign_symlink_upcall_item));
268 sbi->ll_foreign_symlink_upcall_items = NULL;
270 if (sbi->ll_secctx_name)
271 ll_secctx_name_free(sbi);
273 ll_free_rw_stats_info(sbi);
274 pcc_super_fini(&sbi->ll_pcc_super);
275 OBD_FREE(sbi, sizeof(*sbi));
280 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
282 struct inode *root = NULL;
283 struct ll_sb_info *sbi = ll_s2sbi(sb);
284 struct obd_statfs *osfs = NULL;
285 struct ptlrpc_request *request = NULL;
286 struct obd_connect_data *data = NULL;
287 struct obd_uuid *uuid;
288 struct md_op_data *op_data;
289 struct lustre_md lmd;
291 int size, err, checksum;
297 sbi->ll_md_obd = class_name2obd(md);
298 if (!sbi->ll_md_obd) {
299 CERROR("MD %s: not setup or attached\n", md);
313 /* pass client page size via ocd_grant_blkbits, the server should report
314 * back its backend blocksize for grant calculation purpose */
315 data->ocd_grant_blkbits = PAGE_SHIFT;
317 /* indicate MDT features supported by this client */
318 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
319 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
320 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
321 OBD_CONNECT_SRVLOCK |
322 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
323 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
324 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
325 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
326 OBD_CONNECT_64BITHASH |
327 OBD_CONNECT_EINPROGRESS |
328 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
329 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
330 OBD_CONNECT_MAX_EASIZE |
331 OBD_CONNECT_FLOCK_DEAD |
332 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
333 OBD_CONNECT_OPEN_BY_FID |
334 OBD_CONNECT_DIR_STRIPE |
335 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
336 OBD_CONNECT_SUBTREE |
337 OBD_CONNECT_MULTIMODRPCS |
338 OBD_CONNECT_GRANT_PARAM |
339 OBD_CONNECT_GRANT_SHRINK |
340 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
342 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
343 OBD_CONNECT2_SUM_STATFS |
344 OBD_CONNECT2_OVERSTRIPING |
346 OBD_CONNECT2_LOCK_CONVERT |
347 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
348 OBD_CONNECT2_INC_XID |
350 OBD_CONNECT2_ASYNC_DISCARD |
352 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
353 OBD_CONNECT2_GETATTR_PFID |
354 OBD_CONNECT2_DOM_LVB |
355 OBD_CONNECT2_REP_MBITS |
356 OBD_CONNECT2_ATOMIC_OPEN_LOCK |
357 OBD_CONNECT2_BATCH_RPC |
358 OBD_CONNECT2_DMV_IMP_INHERIT;
360 #ifdef HAVE_LRU_RESIZE_SUPPORT
361 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
362 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
364 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
366 data->ocd_cksum_types = obd_cksum_types_supported_client();
368 if (CFS_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
369 /* flag mdc connection as lightweight, only used for test
370 * purpose, use with care */
371 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
373 data->ocd_ibits_known = MDS_INODELOCK_FULL;
374 data->ocd_version = LUSTRE_VERSION_CODE;
376 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
377 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
380 /* Setting this indicates we correctly support S_NOSEC (See kernel
381 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
383 sb->s_flags |= SB_NOSEC;
385 sbi->ll_fop = ll_select_file_operations(sbi);
387 /* always ping even if server suppress_pings */
388 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
389 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
391 obd_connect_set_secctx(data);
392 if (ll_sbi_has_encrypt(sbi)) {
393 obd_connect_set_enc_fid2path(data);
394 obd_connect_set_name_enc(data);
395 obd_connect_set_enc(data);
398 #if defined(CONFIG_SECURITY)
399 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
402 data->ocd_brw_size = MD_MAX_BRW_SIZE;
405 if (sb->s_flags & SB_RDONLY)
406 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
407 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
408 &sbi->ll_sb_uuid, data, sbi->ll_cache);
410 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
411 "recovery, of which this client is not a "
412 "part. Please wait for recovery to complete,"
413 " abort, or time out.\n", md);
416 CERROR("cannot connect to %s: rc = %d\n", md, err);
420 sbi->ll_md_exp->exp_connect_data = *data;
422 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
423 LUSTRE_SEQ_METADATA);
425 CERROR("%s: Can't init metadata layer FID infrastructure, "
426 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
430 /* For mount, we only need fs info from MDT0, and also in DNE, it
431 * can make sure the client can be mounted as long as MDT0 is
433 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
434 ktime_get_seconds() - sbi->ll_statfs_max_age,
435 OBD_STATFS_FOR_MDT0);
436 if (err == -EROFS && !(sb->s_flags & SB_RDONLY)) {
437 /* We got -EROFS from the server, maybe it is imposing
438 * read-only mount. So just retry like this.
440 cfs_tty_write_msg("Forcing read-only mount.\n\r");
441 CERROR("%s: mount failed with %d, forcing read-only mount.\n",
442 sbi->ll_md_exp->exp_obd->obd_name, err);
443 sb->s_flags |= SB_RDONLY;
444 obd_fid_fini(sbi->ll_md_exp->exp_obd);
445 obd_disconnect(sbi->ll_md_exp);
446 GOTO(retry_connect, err);
448 GOTO(out_md_fid, err);
451 /* This needs to be after statfs to ensure connect has finished.
452 * Note that "data" does NOT contain the valid connect reply.
453 * If connecting to a 1.8 server there will be no LMV device, so
454 * we can access the MDC export directly and exp_connect_flags will
455 * be non-zero, but if accessing an upgraded 2.1 server it will
456 * have the correct flags filled in.
457 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
458 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
459 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
460 valid != CLIENT_CONNECT_MDT_REQD) {
463 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
464 obd_connect_flags2str(buf, PAGE_SIZE,
465 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
466 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
467 "feature(s) needed for correct operation "
468 "of this client (%s). Please upgrade "
469 "server or downgrade client.\n",
470 sbi->ll_md_exp->exp_obd->obd_name, buf);
471 OBD_FREE(buf, PAGE_SIZE);
472 GOTO(out_md_fid, err = -EPROTO);
475 size = sizeof(*data);
476 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
477 KEY_CONN_DATA, &size, data);
479 CERROR("%s: Get connect data failed: rc = %d\n",
480 sbi->ll_md_exp->exp_obd->obd_name, err);
481 GOTO(out_md_fid, err);
484 LASSERT(osfs->os_bsize);
485 sb->s_blocksize = osfs->os_bsize;
486 sb->s_blocksize_bits = log2(osfs->os_bsize);
487 sb->s_magic = LL_SUPER_MAGIC;
488 sb->s_maxbytes = MAX_LFS_FILESIZE;
489 sbi->ll_inode_cache_enabled = 1;
490 sbi->ll_namelen = osfs->os_namelen;
491 sbi->ll_mnt.mnt = current->fs->root.mnt;
492 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
494 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
495 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
496 LCONSOLE_INFO("Disabling user_xattr feature because "
497 "it is not supported on the server\n");
498 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
501 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
503 sb->s_flags |= SB_POSIXACL;
505 set_bit(LL_SBI_ACL, sbi->ll_flags);
507 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
509 sb->s_flags &= ~SB_POSIXACL;
511 clear_bit(LL_SBI_ACL, sbi->ll_flags);
514 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
515 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
517 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
518 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
520 if (obd_connect_has_secctx(data))
521 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
523 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
524 if (ll_sb_has_test_dummy_encryption(sb))
525 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
527 sbi->ll_md_exp->exp_obd->obd_name);
528 ll_sbi_set_encrypt(sbi, false);
531 if (ll_sbi_has_name_encrypt(sbi) && !obd_connect_has_name_enc(data)) {
532 struct lustre_sb_info *lsi = s2lsi(sb);
534 if (ll_sb_has_test_dummy_encryption(sb))
535 LCONSOLE_WARN("%s: server %s does not support name encryption, not using it.\n",
537 sbi->ll_md_exp->exp_obd->obd_name);
538 #ifdef CONFIG_LL_ENCRYPTION
539 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
541 lsi->lsi_flags &= ~LSI_FILENAME_ENC_B64_OLD_CLI;
542 ll_sbi_set_name_encrypt(sbi, false);
545 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
546 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
547 LCONSOLE_INFO("%s: disabling xattr cache due to "
548 "unknown maximum xattr size.\n", dt);
549 } else if (!sbi->ll_xattr_cache_set) {
550 /* If xattr_cache is already set (no matter 0 or 1)
551 * during processing llog, it won't be enabled here. */
552 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
553 sbi->ll_xattr_cache_enabled = 1;
557 sbi->ll_dt_obd = class_name2obd(dt);
558 if (!sbi->ll_dt_obd) {
559 CERROR("DT %s: not setup or attached\n", dt);
560 GOTO(out_md_fid, err = -ENODEV);
563 /* pass client page size via ocd_grant_blkbits, the server should report
564 * back its backend blocksize for grant calculation purpose */
565 data->ocd_grant_blkbits = PAGE_SHIFT;
567 /* indicate OST features supported by this client */
568 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
569 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
570 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
571 OBD_CONNECT_SRVLOCK |
572 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
573 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
574 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
575 OBD_CONNECT_EINPROGRESS |
576 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
577 OBD_CONNECT_LAYOUTLOCK |
578 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
579 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
580 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
581 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
582 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
583 OBD_CONNECT2_REP_MBITS;
585 if (!CFS_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
586 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
588 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
589 * disabled by default, because it can still be enabled on the
590 * fly via /sys. As a consequence, we still need to come to an
591 * agreement on the supported algorithms at connect time
593 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
595 if (CFS_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
596 data->ocd_cksum_types = OBD_CKSUM_ADLER;
598 data->ocd_cksum_types = obd_cksum_types_supported_client();
600 #ifdef HAVE_LRU_RESIZE_SUPPORT
601 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
603 /* always ping even if server suppress_pings */
604 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
605 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
607 if (ll_sbi_has_encrypt(sbi))
608 obd_connect_set_enc(data);
610 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
611 "ocd_grant: %d\n", data->ocd_connect_flags,
612 data->ocd_version, data->ocd_grant);
614 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
615 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
617 data->ocd_brw_size = DT_MAX_BRW_SIZE;
619 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
620 &sbi->ll_sb_uuid, data, sbi->ll_cache);
622 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
623 "recovery, of which this client is not a "
624 "part. Please wait for recovery to "
625 "complete, abort, or time out.\n", dt);
628 CERROR("%s: Cannot connect to %s: rc = %d\n",
629 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
633 if (ll_sbi_has_encrypt(sbi) &&
634 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
635 if (ll_sb_has_test_dummy_encryption(sb))
636 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
638 ll_sbi_set_encrypt(sbi, false);
639 } else if (ll_sb_has_test_dummy_encryption(sb)) {
640 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
643 sbi->ll_dt_exp->exp_connect_data = *data;
645 /* Don't change value if it was specified in the config log */
646 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
647 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
648 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
649 (data->ocd_brw_size >> PAGE_SHIFT));
650 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
651 sbi->ll_ra_info.ra_max_pages_per_file)
652 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
653 sbi->ll_ra_info.ra_max_pages_per_file;
656 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
657 LUSTRE_SEQ_METADATA);
659 CERROR("%s: Can't init data layer FID infrastructure, "
660 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
664 mutex_lock(&sbi->ll_lco.lco_lock);
665 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
666 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
667 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
668 mutex_unlock(&sbi->ll_lco.lco_lock);
670 fid_zero(&sbi->ll_root_fid);
671 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
674 CERROR("cannot mds_connect: rc = %d\n", err);
675 GOTO(out_lock_cn_cb, err);
677 if (!fid_is_sane(&sbi->ll_root_fid)) {
678 CERROR("%s: Invalid root fid "DFID" during mount\n",
679 sbi->ll_md_exp->exp_obd->obd_name,
680 PFID(&sbi->ll_root_fid));
681 GOTO(out_lock_cn_cb, err = -EINVAL);
683 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
685 sb->s_op = &lustre_super_operations;
686 sb->s_xattr = ll_xattr_handlers;
687 #if THREAD_SIZE >= 8192 /*b=17630*/
688 sb->s_export_op = &lustre_export_operations;
690 #ifdef HAVE_LUSTRE_CRYPTO
691 llcrypt_set_ops(sb, &lustre_cryptops);
695 * XXX: move this to after cbd setup? */
696 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
698 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
699 valid |= OBD_MD_FLACL;
701 OBD_ALLOC_PTR(op_data);
703 GOTO(out_lock_cn_cb, err = -ENOMEM);
705 op_data->op_fid1 = sbi->ll_root_fid;
706 op_data->op_mode = 0;
707 op_data->op_valid = valid;
709 err = md_getattr(sbi->ll_md_exp, op_data, &request);
711 /* We need enc ctx info, so reset it in op_data to
712 * prevent it from being freed.
714 encctx = op_data->op_file_encctx;
715 encctxlen = op_data->op_file_encctx_size;
716 op_data->op_file_encctx = NULL;
717 op_data->op_file_encctx_size = 0;
718 OBD_FREE_PTR(op_data);
720 CERROR("%s: md_getattr failed for root: rc = %d\n",
721 sbi->ll_md_exp->exp_obd->obd_name, err);
722 GOTO(out_lock_cn_cb, err);
725 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
726 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
728 CERROR("failed to understand root inode md: rc = %d\n", err);
729 ptlrpc_req_finished(request);
730 GOTO(out_lock_cn_cb, err);
733 LASSERT(fid_is_sane(&sbi->ll_root_fid));
734 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
735 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
736 md_put_lustre_md(sbi->ll_md_exp, &lmd);
740 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
742 CERROR("%s: bad ll_iget() for root: rc = %d\n",
743 sbi->ll_fsname, err);
744 ptlrpc_req_finished(request);
748 err = ll_secctx_name_store(root);
749 if (err < 0 && ll_security_xattr_wanted(root))
750 CWARN("%s: file security contextes not supported: rc = %d\n",
751 sbi->ll_fsname, err);
756 "server returned encryption ctx for root inode "DFID"\n",
757 PFID(&sbi->ll_root_fid));
758 err = ll_set_encflags(root, encctx, encctxlen, true);
760 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
762 PFID(&sbi->ll_root_fid), err);
764 ptlrpc_req_finished(request);
766 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
767 if (sbi->ll_checksum_set) {
768 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
769 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
770 sizeof(checksum), &checksum, NULL);
772 CERROR("%s: Set checksum failed: rc = %d\n",
773 sbi->ll_dt_exp->exp_obd->obd_name, err);
779 sb->s_root = d_make_root(root);
780 if (sb->s_root == NULL) {
782 CERROR("%s: can't make root dentry: rc = %d\n",
783 sbi->ll_fsname, err);
787 sbi->ll_sdev_orig = sb->s_dev;
789 /* We set sb->s_dev equal on all lustre clients in order to support
790 * NFS export clustering. NFSD requires that the FSID be the same
792 /* s_dev is also used in lt_compare() to compare two fs, but that is
793 * only a node-local comparison. */
794 uuid = obd_get_uuid(sbi->ll_md_exp);
796 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
803 if (sbi->ll_dt_obd) {
804 err = sysfs_create_link(&sbi->ll_kset.kobj,
805 &sbi->ll_dt_obd->obd_kset.kobj,
806 sbi->ll_dt_obd->obd_type->typ_name);
808 CERROR("%s: could not register %s in llite: rc = %d\n",
809 dt, sbi->ll_fsname, err);
814 if (sbi->ll_md_obd) {
815 err = sysfs_create_link(&sbi->ll_kset.kobj,
816 &sbi->ll_md_obd->obd_kset.kobj,
817 sbi->ll_md_obd->obd_type->typ_name);
819 CERROR("%s: could not register %s in llite: rc = %d\n",
820 md, sbi->ll_fsname, err);
829 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
831 obd_disconnect(sbi->ll_dt_exp);
832 sbi->ll_dt_exp = NULL;
833 sbi->ll_dt_obd = NULL;
835 obd_fid_fini(sbi->ll_md_exp->exp_obd);
837 obd_disconnect(sbi->ll_md_exp);
838 sbi->ll_md_exp = NULL;
839 sbi->ll_md_obd = NULL;
848 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
852 size = sizeof(*lmmsize);
853 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
854 KEY_MAX_EASIZE, &size, lmmsize);
856 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
857 sbi->ll_dt_exp->exp_obd->obd_name, rc);
861 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
864 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
865 KEY_MAX_EASIZE, &size, lmmsize);
867 CERROR("Get max mdsize error rc %d\n", rc);
869 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
875 * Get the value of the default_easize parameter.
877 * \see client_obd::cl_default_mds_easize
879 * \param[in] sbi superblock info for this filesystem
880 * \param[out] lmmsize pointer to storage location for value
882 * \retval 0 on success
883 * \retval negative negated errno on failure
885 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
890 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
891 KEY_DEFAULT_EASIZE, &size, lmmsize);
893 CERROR("Get default mdsize error rc %d\n", rc);
899 * Set the default_easize parameter to the given value.
901 * \see client_obd::cl_default_mds_easize
903 * \param[in] sbi superblock info for this filesystem
904 * \param[in] lmmsize the size to set
906 * \retval 0 on success
907 * \retval negative negated errno on failure
909 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
913 if (lmmsize < sizeof(struct lov_mds_md) ||
914 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
917 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
918 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
919 sizeof(int), &lmmsize, NULL);
924 static void client_common_put_super(struct super_block *sb)
926 struct ll_sb_info *sbi = ll_s2sbi(sb);
931 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
932 obd_disconnect(sbi->ll_dt_exp);
933 sbi->ll_dt_exp = NULL;
935 ll_debugfs_unregister_super(sb);
937 obd_fid_fini(sbi->ll_md_exp->exp_obd);
938 obd_disconnect(sbi->ll_md_exp);
939 sbi->ll_md_exp = NULL;
944 void ll_kill_super(struct super_block *sb)
946 struct ll_sb_info *sbi;
950 if (!(sb->s_flags & SB_ACTIVE))
954 /* we need restore s_dev from changed for clustred NFS before put_super
955 * because new kernels have cached s_dev and change sb->s_dev in
956 * put_super not affected real removing devices */
958 sb->s_dev = sbi->ll_sdev_orig;
960 /* wait running statahead threads to quit */
961 while (atomic_read(&sbi->ll_sa_running) > 0)
962 schedule_timeout_uninterruptible(
963 cfs_time_seconds(1) >> 3);
969 /* Since we use this table for ll_sbi_flags_seq_show make
970 * sure what you want displayed for a specific token that
971 * is listed more than once below be listed first. For
972 * example we want "checksum" displayed, not "nochecksum"
975 static const match_table_t ll_sbi_flags_name = {
976 {LL_SBI_NOLCK, "nolock"},
977 {LL_SBI_CHECKSUM, "checksum"},
978 {LL_SBI_CHECKSUM, "nochecksum"},
979 {LL_SBI_LOCALFLOCK, "localflock"},
980 {LL_SBI_FLOCK, "flock"},
981 {LL_SBI_FLOCK, "noflock"},
982 {LL_SBI_USER_XATTR, "user_xattr"},
983 {LL_SBI_USER_XATTR, "nouser_xattr"},
984 {LL_SBI_LRU_RESIZE, "lruresize"},
985 {LL_SBI_LRU_RESIZE, "nolruresize"},
986 {LL_SBI_LAZYSTATFS, "lazystatfs"},
987 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
988 {LL_SBI_32BIT_API, "32bitapi"},
989 {LL_SBI_USER_FID2PATH, "user_fid2path"},
990 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
991 {LL_SBI_VERBOSE, "verbose"},
992 {LL_SBI_VERBOSE, "noverbose"},
993 {LL_SBI_ALWAYS_PING, "always_ping"},
994 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
995 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
996 {LL_SBI_ENCRYPT, "encrypt"},
997 {LL_SBI_ENCRYPT, "noencrypt"},
998 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
999 {LL_SBI_NUM_MOUNT_OPT, NULL},
1001 {LL_SBI_ACL, "acl"},
1002 {LL_SBI_AGL_ENABLED, "agl"},
1003 {LL_SBI_64BIT_HASH, "64bit_hash"},
1004 {LL_SBI_LAYOUT_LOCK, "layout"},
1005 {LL_SBI_XATTR_CACHE, "xattr_cache"},
1006 {LL_SBI_NOROOTSQUASH, "norootsquash"},
1007 {LL_SBI_FAST_READ, "fast_read"},
1008 {LL_SBI_FILE_SECCTX, "file_secctx"},
1009 {LL_SBI_TINY_WRITE, "tiny_write"},
1010 {LL_SBI_FILE_HEAT, "file_heat"},
1011 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
1012 {LL_SBI_ENCRYPT_NAME, "name_encrypt"},
1015 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
1017 struct super_block *sb = m->private;
1020 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
1023 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
1026 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
1027 if (ll_sbi_flags_name[j].token == i &&
1028 ll_sbi_flags_name[j].pattern) {
1029 seq_printf(m, "%s ",
1030 ll_sbi_flags_name[j].pattern);
1035 seq_puts(m, "\b\n");
1039 /* non-client-specific mount options are parsed in lmd_parse */
1040 static int ll_options(char *options, struct super_block *sb)
1042 struct ll_sb_info *sbi = ll_s2sbi(sb);
1043 char *s2, *s1, *opts;
1050 /* Don't stomp on lmd_opts */
1051 opts = kstrdup(options, GFP_KERNEL);
1057 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1059 while ((s1 = strsep(&opts, ",")) != NULL) {
1060 substring_t args[MAX_OPT_ARGS];
1061 bool turn_off = false;
1067 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1069 if (strncmp(s1, "no", 2) == 0)
1073 * Initialize args struct so we know whether arg was
1074 * found; some options take optional arguments.
1077 args[0].from = NULL;
1078 token = match_token(s1, ll_sbi_flags_name, args);
1079 if (token == LL_SBI_NUM_MOUNT_OPT) {
1080 if (match_wildcard("context", s1) ||
1081 match_wildcard("fscontext", s1) ||
1082 match_wildcard("defcontext", s1) ||
1083 match_wildcard("rootcontext",s1))
1086 LCONSOLE_ERROR_MSG(0x152,
1087 "Unknown option '%s', won't mount.\n",
1094 case LL_SBI_32BIT_API:
1095 case LL_SBI_64BIT_HASH:
1096 case LL_SBI_ALWAYS_PING:
1097 set_bit(token, sbi->ll_flags);
1101 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1103 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1105 set_bit(token, sbi->ll_flags);
1108 case LL_SBI_LOCALFLOCK:
1109 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1110 set_bit(token, sbi->ll_flags);
1113 case LL_SBI_CHECKSUM:
1114 sbi->ll_checksum_set = 1;
1116 case LL_SBI_USER_XATTR:
1117 case LL_SBI_USER_FID2PATH:
1118 case LL_SBI_LRU_RESIZE:
1119 case LL_SBI_LAZYSTATFS:
1120 case LL_SBI_VERBOSE:
1122 clear_bit(token, sbi->ll_flags);
1124 set_bit(token, sbi->ll_flags);
1126 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1127 #ifdef HAVE_LUSTRE_CRYPTO
1128 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1129 set_bit(token, sbi->ll_flags);
1131 struct lustre_sb_info *lsi = s2lsi(sb);
1133 err = llcrypt_set_test_dummy_encryption(sb,
1134 #ifdef HAVE_FSCRYPT_SET_TEST_DUMMY_ENC_CHAR_ARG
1139 &lsi->lsi_dummy_enc_policy);
1145 "Can't change test_dummy_encryption");
1146 else if (err == -EINVAL)
1148 "Value of option \"%s\" unrecognized",
1152 "Error processing option \"%s\" [%d]",
1157 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1161 case LL_SBI_ENCRYPT:
1162 #ifdef HAVE_LUSTRE_CRYPTO
1164 clear_bit(token, sbi->ll_flags);
1166 set_bit(token, sbi->ll_flags);
1168 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1171 case LL_SBI_FOREIGN_SYMLINK:
1172 /* non-default prefix provided ? */
1177 /* path must be absolute */
1178 if (args->from[0] != '/') {
1179 LCONSOLE_ERROR_MSG(0x152,
1180 "foreign prefix '%s' must be an absolute path\n",
1185 old_len = sbi->ll_foreign_symlink_prefix_size;
1186 old = sbi->ll_foreign_symlink_prefix;
1187 /* alloc for path length and '\0' */
1188 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1189 if (!sbi->ll_foreign_symlink_prefix) {
1190 /* restore previous */
1191 sbi->ll_foreign_symlink_prefix = old;
1192 sbi->ll_foreign_symlink_prefix_size =
1196 sbi->ll_foreign_symlink_prefix_size =
1197 args->to - args->from + 1;
1198 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1199 sbi->ll_foreign_symlink_prefix_size,
1202 OBD_FREE(old, old_len);
1204 /* enable foreign symlink support */
1205 set_bit(token, sbi->ll_flags);
1207 LCONSOLE_ERROR_MSG(0x152,
1208 "invalid %s option\n", s1);
1219 void ll_lli_init(struct ll_inode_info *lli)
1221 lli->lli_inode_magic = LLI_INODE_MAGIC;
1223 rwlock_init(&lli->lli_lock);
1224 lli->lli_posix_acl = NULL;
1225 /* Do not set lli_fid, it has been initialized already. */
1226 fid_zero(&lli->lli_pfid);
1227 lli->lli_mds_read_och = NULL;
1228 lli->lli_mds_write_och = NULL;
1229 lli->lli_mds_exec_och = NULL;
1230 lli->lli_open_fd_read_count = 0;
1231 lli->lli_open_fd_write_count = 0;
1232 lli->lli_open_fd_exec_count = 0;
1233 mutex_init(&lli->lli_och_mutex);
1234 spin_lock_init(&lli->lli_agl_lock);
1235 spin_lock_init(&lli->lli_layout_lock);
1236 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1237 lli->lli_clob = NULL;
1239 init_rwsem(&lli->lli_xattrs_list_rwsem);
1240 mutex_init(&lli->lli_xattrs_enq_lock);
1242 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1243 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1244 lli->lli_opendir_key = NULL;
1245 lli->lli_sai = NULL;
1246 spin_lock_init(&lli->lli_sa_lock);
1247 lli->lli_opendir_pid = 0;
1248 lli->lli_sa_enabled = 0;
1249 init_rwsem(&lli->lli_lsm_sem);
1251 mutex_init(&lli->lli_size_mutex);
1252 mutex_init(&lli->lli_setattr_mutex);
1253 lli->lli_symlink_name = NULL;
1254 ll_trunc_sem_init(&lli->lli_trunc_sem);
1255 range_lock_tree_init(&lli->lli_write_tree);
1256 init_rwsem(&lli->lli_glimpse_sem);
1257 lli->lli_glimpse_time = ktime_set(0, 0);
1258 INIT_LIST_HEAD(&lli->lli_agl_list);
1259 lli->lli_agl_index = 0;
1260 lli->lli_async_rc = 0;
1261 spin_lock_init(&lli->lli_heat_lock);
1262 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1263 lli->lli_heat_flags = 0;
1264 mutex_init(&lli->lli_pcc_lock);
1265 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1266 lli->lli_pcc_inode = NULL;
1267 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1268 lli->lli_pcc_generation = 0;
1269 mutex_init(&lli->lli_group_mutex);
1270 lli->lli_group_users = 0;
1271 lli->lli_group_gid = 0;
1272 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1273 lli->lli_uid = (__u32) -1;
1274 lli->lli_gid = (__u32) -1;
1276 mutex_init(&lli->lli_layout_mutex);
1277 lli->lli_layout_lock_owner = NULL;
1278 /* ll_cl_context initialize */
1279 INIT_LIST_HEAD(&lli->lli_lccs);
1280 seqlock_init(&lli->lli_page_inv_lock);
1281 lli->lli_inode_lock_owner = NULL;
1284 #define MAX_STRING_SIZE 128
1286 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1287 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1289 struct lustre_sb_info *lsi = s2lsi(sb);
1290 char buf[MAX_STRING_SIZE];
1294 err = bdi_init(&lsi->lsi_bdi);
1298 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1299 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1300 lsi->lsi_bdi.name = "lustre";
1301 va_start(args, fmt);
1302 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1304 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1307 sb->s_bdi = &lsi->lsi_bdi;
1311 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1313 int ll_fill_super(struct super_block *sb)
1315 struct lustre_profile *lprof = NULL;
1316 struct lustre_sb_info *lsi = s2lsi(sb);
1317 struct ll_sb_info *sbi = NULL;
1318 char *dt = NULL, *md = NULL;
1319 char *profilenm = get_profile_name(sb);
1320 struct config_llog_instance *cfg;
1321 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1322 const int instlen = LUSTRE_MAXINSTANCE + 2;
1323 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1324 char name[MAX_STRING_SIZE];
1333 /* for ASLR, to map between cfg_instance and hashed ptr */
1334 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1335 profilenm, cfg_instance, sb);
1337 CFS_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1341 GOTO(out_free_cfg, err = -ENOMEM);
1343 /* client additional sb info */
1344 lsi->lsi_llsbi = sbi = ll_init_sbi(lsi);
1346 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1348 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1350 GOTO(out_free_cfg, err);
1352 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1353 #ifdef CONFIG_LL_ENCRYPTION
1354 if (ll_sb_has_test_dummy_encryption(sb))
1355 /* enable filename encryption by default for dummy enc mode */
1356 lsi->lsi_flags |= LSI_FILENAME_ENC;
1358 /* filename encryption is disabled by default */
1359 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1362 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1363 sb->s_d_op = &ll_d_ops;
1366 generate_random_uuid(uuid.b);
1367 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1369 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1372 len = strlen(profilenm);
1373 ptr = strrchr(profilenm, '-');
1374 if (ptr && (strcmp(ptr, "-client") == 0))
1377 if (len > LUSTRE_MAXFSNAME) {
1378 if (unlikely(len >= MAX_STRING_SIZE))
1379 len = MAX_STRING_SIZE - 1;
1380 strncpy(name, profilenm, len);
1382 err = -ENAMETOOLONG;
1383 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1384 name, LUSTRE_MAXFSNAME, err);
1385 GOTO(out_free_cfg, err);
1387 strncpy(sbi->ll_fsname, profilenm, len);
1388 sbi->ll_fsname[len] = '\0';
1391 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1392 profilenm, cfg_instance);
1394 err = super_setup_bdi_name(sb, "%s", name);
1396 GOTO(out_free_cfg, err);
1398 /* disable kernel readahead */
1399 sb->s_bdi->ra_pages = 0;
1400 #ifdef HAVE_BDI_IO_PAGES
1401 sb->s_bdi->io_pages = 0;
1403 sb->s_bdi->capabilities |= LL_BDI_CAP_FLAGS;
1404 #ifdef SB_I_CGROUPWB
1405 sb->s_iflags |= SB_I_CGROUPWB;
1408 /* Call ll_debugfs_register_super() before lustre_process_log()
1409 * so that "llite.*.*" params can be processed correctly.
1411 err = ll_debugfs_register_super(sb, name);
1413 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1414 sbi->ll_fsname, err);
1418 /* The cfg_instance is a value unique to this super, in case some
1419 * joker tries to mount the same fs at two mount points.
1421 cfg->cfg_instance = cfg_instance;
1422 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1423 cfg->cfg_callback = class_config_llog_handler;
1424 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1425 /* set up client obds */
1426 err = lustre_process_log(sb, profilenm, cfg);
1428 GOTO(out_debugfs, err);
1430 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1431 lprof = class_get_profile(profilenm);
1432 if (lprof == NULL) {
1433 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1434 " read from the MGS. Does that filesystem "
1435 "exist?\n", profilenm);
1436 GOTO(out_debugfs, err = -EINVAL);
1438 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1439 lprof->lp_md, lprof->lp_dt);
1441 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1442 OBD_ALLOC(dt, dt_len);
1444 GOTO(out_profile, err = -ENOMEM);
1445 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1447 md_len = strlen(lprof->lp_md) + instlen + 2;
1448 OBD_ALLOC(md, md_len);
1450 GOTO(out_free_dt, err = -ENOMEM);
1451 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1453 /* connections, registrations, sb setup */
1454 err = client_common_fill_super(sb, md, dt);
1456 GOTO(out_free_md, err);
1458 sbi->ll_client_common_fill_super_succeeded = 1;
1462 OBD_FREE(md, md_len);
1465 OBD_FREE(dt, dt_len);
1468 class_put_profile(lprof);
1471 ll_debugfs_unregister_super(sb);
1478 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1479 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1480 sb->s_flags & SB_RDONLY ? " read-only" : "");
1482 } /* ll_fill_super */
1484 static void ll_bdi_device_unregister(struct backing_dev_info *bdi)
1486 if (bdi->dev == NULL)
1489 #if defined(SB_I_CGROUPWB) && !defined(SB_I_PERSB_BDI)
1490 #ifdef HAVE_BDI_DEBUG_STATS
1491 debugfs_remove(bdi->debug_stats);
1492 debugfs_remove(bdi->debug_dir);
1494 debugfs_remove_recursive(bdi->debug_dir);
1496 device_unregister(bdi->dev);
1501 void ll_put_super(struct super_block *sb)
1503 struct config_llog_instance cfg, params_cfg;
1504 struct obd_device *obd;
1505 struct lustre_sb_info *lsi = s2lsi(sb);
1506 struct ll_sb_info *sbi = ll_s2sbi(sb);
1507 char *profilenm = get_profile_name(sb);
1508 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1509 int next, force = 1;
1514 GOTO(out_no_sbi, 0);
1516 /* Should replace instance_id with something better for ASLR */
1517 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1518 profilenm, cfg_instance, sb);
1520 cfg.cfg_instance = cfg_instance;
1521 lustre_end_log(sb, profilenm, &cfg);
1523 params_cfg.cfg_instance = cfg_instance;
1524 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1526 if (sbi->ll_md_exp) {
1527 obd = class_exp2obd(sbi->ll_md_exp);
1529 force = obd->obd_force;
1532 /* We need to set force before the lov_disconnect in
1533 * lustre_common_put_super, since l_d cleans up osc's as well.
1537 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1539 obd->obd_force = force;
1543 if (sbi->ll_client_common_fill_super_succeeded) {
1544 /* Only if client_common_fill_super succeeded */
1545 client_common_put_super(sb);
1548 /* imitate failed cleanup */
1549 if (CFS_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1553 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1554 class_manual_cleanup(obd);
1557 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1558 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1561 class_del_profile(profilenm);
1563 ll_bdi_device_unregister(sb->s_bdi);
1565 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1566 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1567 bdi_destroy(&lsi->lsi_bdi);
1568 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1572 llcrypt_free_dummy_policy(&lsi->lsi_dummy_enc_policy);
1574 lsi->lsi_llsbi = NULL;
1576 lustre_common_put_super(sb);
1578 cl_env_cache_purge(~0);
1581 } /* client_put_super */
1583 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1585 struct inode *inode = NULL;
1587 /* NOTE: we depend on atomic igrab() -bzzz */
1588 lock_res_and_lock(lock);
1589 if (lock->l_resource->lr_lvb_inode) {
1590 struct ll_inode_info * lli;
1591 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1592 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1593 inode = igrab(lock->l_resource->lr_lvb_inode);
1595 inode = lock->l_resource->lr_lvb_inode;
1596 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1597 D_WARNING, lock, "lr_lvb_inode %p is "
1598 "bogus: magic %08x",
1599 lock->l_resource->lr_lvb_inode,
1600 lli->lli_inode_magic);
1604 unlock_res_and_lock(lock);
1608 void ll_dir_clear_lsm_md(struct inode *inode)
1610 struct ll_inode_info *lli = ll_i2info(inode);
1612 LASSERT(S_ISDIR(inode->i_mode));
1613 down_write(&lli->lli_lsm_sem);
1614 lmv_stripe_object_put(&lli->lli_lsm_obj);
1615 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1616 up_write(&lli->lli_lsm_sem);
1619 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1620 const struct lu_fid *fid,
1621 struct lustre_md *md)
1623 struct ll_sb_info *sbi = ll_s2sbi(sb);
1624 struct ll_inode_info *lli;
1625 struct mdt_body *body = md->body;
1626 struct inode *inode;
1631 LASSERT(md->lsm_obj);
1632 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1633 inode = iget_locked(sb, ino);
1634 if (inode == NULL) {
1635 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1636 sbi->ll_fsname, PFID(fid));
1637 RETURN(ERR_PTR(-ENOENT));
1640 lli = ll_i2info(inode);
1641 if (inode->i_state & I_NEW) {
1642 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1643 (body->mbo_mode & S_IFMT);
1644 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1647 inode->i_mtime.tv_sec = 0;
1648 inode->i_atime.tv_sec = 0;
1649 inode->i_ctime.tv_sec = 0;
1652 #ifdef HAVE_BACKING_DEV_INFO
1653 /* initializing backing dev info. */
1654 inode->i_mapping->backing_dev_info =
1655 &s2lsi(inode->i_sb)->lsi_bdi;
1657 inode->i_op = &ll_dir_inode_operations;
1658 inode->i_fop = &ll_dir_operations;
1659 lli->lli_fid = *fid;
1662 /* master object FID */
1663 lli->lli_pfid = body->mbo_fid1;
1664 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1665 lli, PFID(fid), PFID(&lli->lli_pfid));
1666 unlock_new_inode(inode);
1668 /* in directory restripe/auto-split, a directory will be
1669 * transformed to a stripe if it's plain, set its pfid here,
1670 * otherwise ll_lock_cancel_bits() can't find the master inode.
1672 lli->lli_pfid = body->mbo_fid1;
1678 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1681 struct lmv_stripe_md *lsm;
1682 struct ll_inode_info *lli = ll_i2info(inode);
1685 LASSERT(md->lsm_obj != NULL);
1686 lsm = &md->lsm_obj->lso_lsm;
1688 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1689 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1690 lmv_stripe_object_dump(D_INODE, md->lsm_obj);
1692 if (!lmv_dir_striped(md->lsm_obj))
1695 /* XXX sigh, this lsm_root initialization should be in
1696 * LMV layer, but it needs ll_iget right now, so we
1697 * put this here right now. */
1698 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1699 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1700 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1702 if (!fid_is_sane(fid))
1705 /* Unfortunately ll_iget will call ll_update_inode,
1706 * where the initialization of slave inode is slightly
1707 * different, so it reset lsm_md to NULL to avoid
1708 * initializing lsm for slave inode. */
1709 lsm->lsm_md_oinfo[i].lmo_root =
1710 ll_iget_anon_dir(inode->i_sb, fid, md);
1711 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1712 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1714 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1716 iput(lsm->lsm_md_oinfo[i].lmo_root);
1717 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1723 /* move lsm_obj to lli */
1724 lli->lli_lsm_obj = md->lsm_obj;
1729 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1731 struct ll_inode_info *lli = ll_i2info(inode);
1732 struct lmv_stripe_object *lsm_obj = md->def_lsm_obj;
1736 /* clear default lsm */
1737 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set) {
1738 down_write(&lli->lli_lsm_sem);
1739 if (lli->lli_def_lsm_obj_set) {
1740 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1741 lli->lli_inherit_depth = 0;
1742 lli->lli_def_lsm_obj_set = 0;
1744 up_write(&lli->lli_lsm_sem);
1749 if (lli->lli_def_lsm_obj) {
1750 /* do nonthing if default lsm isn't changed */
1751 down_read(&lli->lli_lsm_sem);
1752 if (lli->lli_def_lsm_obj &&
1753 lsm_md_eq(lli->lli_def_lsm_obj, lsm_obj)) {
1754 up_read(&lli->lli_lsm_sem);
1757 up_read(&lli->lli_lsm_sem);
1759 down_write(&lli->lli_lsm_sem);
1761 /* update default lsm. */
1762 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1763 lli->lli_def_lsm_obj = lsm_obj;
1764 lli->lli_def_lsm_obj_set = 1;
1765 lmv_stripe_object_dump(D_INODE, lsm_obj);
1766 md->def_lsm_obj = NULL;
1767 up_write(&lli->lli_lsm_sem);
1771 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1773 struct ll_inode_info *lli = ll_i2info(inode);
1774 struct lmv_stripe_object *lsm_obj = md->lsm_obj;
1775 struct cl_attr *attr;
1780 LASSERT(S_ISDIR(inode->i_mode));
1781 CDEBUG(D_INODE, "update lsm_obj %p of "DFID"\n", lli->lli_lsm_obj,
1782 PFID(ll_inode2fid(inode)));
1784 /* update default LMV */
1785 if (md->def_lsm_obj)
1786 ll_update_default_lsm_md(inode, md);
1788 /* after dir migration/restripe, a stripe may be turned into a
1789 * directory, in this case, zero out its lli_pfid.
1791 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1792 fid_zero(&lli->lli_pfid);
1795 * no striped information from request, lustre_md from req does not
1796 * include stripeEA, see ll_md_setattr()
1802 * normally dir layout doesn't change, only take read lock to check
1803 * that to avoid blocking other MD operations.
1805 down_read(&lli->lli_lsm_sem);
1807 /* some current lookup initialized lsm, and unchanged */
1808 if (lli->lli_lsm_obj && lsm_md_eq(lli->lli_lsm_obj, lsm_obj)) {
1809 up_read(&lli->lli_lsm_sem);
1813 up_read(&lli->lli_lsm_sem);
1814 down_write(&lli->lli_lsm_sem);
1816 /* check again in case of a race */
1817 if (lli->lli_lsm_obj && lsm_md_eq(lli->lli_lsm_obj, lsm_obj))
1818 GOTO(unlock, rc = 0);
1820 /* if dir layout doesn't match, check whether version is increased,
1821 * which means layout is changed, this happens in dir split/merge and
1824 * foreign LMV should not change.
1826 if (lli->lli_lsm_obj && lmv_dir_striped(lli->lli_lsm_obj) &&
1827 lsm_obj->lso_lsm.lsm_md_layout_version <=
1828 lli->lli_lsm_obj->lso_lsm.lsm_md_layout_version) {
1829 CERROR("%s: "DFID" dir layout mismatch:\n",
1830 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1831 lmv_stripe_object_dump(D_ERROR, lli->lli_lsm_obj);
1832 lmv_stripe_object_dump(D_ERROR, lsm_obj);
1833 GOTO(unlock, rc = -EINVAL);
1836 /* clear existing lsm */
1837 lmv_stripe_object_put(&lli->lli_lsm_obj);
1839 rc = ll_init_lsm_md(inode, md);
1843 if (!lmv_dir_striped(lli->lli_lsm_obj))
1844 GOTO(unlock, rc = 0);
1846 lsm_obj = lmv_stripe_object_get(lli->lli_lsm_obj);
1847 up_write(&lli->lli_lsm_sem);
1849 OBD_ALLOC_PTR(attr);
1851 GOTO(err, rc = -ENOMEM);
1853 /* validate the lsm */
1854 rc = md_merge_attr(ll_i2mdexp(inode), lsm_obj, attr,
1855 ll_md_blocking_ast);
1857 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1858 md->body->mbo_nlink = attr->cat_nlink;
1859 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1860 md->body->mbo_size = attr->cat_size;
1861 if (md->body->mbo_valid & OBD_MD_FLATIME)
1862 md->body->mbo_atime = attr->cat_atime;
1863 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1864 md->body->mbo_ctime = attr->cat_ctime;
1865 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1866 md->body->mbo_mtime = attr->cat_mtime;
1872 lmv_stripe_object_put(&lsm_obj);
1875 up_write(&lli->lli_lsm_sem);
1879 void ll_clear_inode(struct inode *inode)
1881 struct ll_inode_info *lli = ll_i2info(inode);
1882 struct ll_sb_info *sbi = ll_i2sbi(inode);
1886 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1887 PFID(ll_inode2fid(inode)), inode);
1889 if (S_ISDIR(inode->i_mode)) {
1890 /* these should have been cleared in ll_file_release */
1891 LASSERT(lli->lli_opendir_key == NULL);
1892 LASSERT(lli->lli_sai == NULL);
1893 LASSERT(lli->lli_opendir_pid == 0);
1895 pcc_inode_free(inode);
1898 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1900 LASSERT(!lli->lli_open_fd_write_count);
1901 LASSERT(!lli->lli_open_fd_read_count);
1902 LASSERT(!lli->lli_open_fd_exec_count);
1904 if (lli->lli_mds_write_och)
1905 ll_md_real_close(inode, FMODE_WRITE);
1906 if (lli->lli_mds_exec_och)
1907 ll_md_real_close(inode, FMODE_EXEC);
1908 if (lli->lli_mds_read_och)
1909 ll_md_real_close(inode, FMODE_READ);
1911 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1912 OBD_FREE(lli->lli_symlink_name,
1913 strlen(lli->lli_symlink_name) + 1);
1914 lli->lli_symlink_name = NULL;
1917 ll_xattr_cache_destroy(inode);
1919 forget_all_cached_acls(inode);
1921 lli->lli_inode_magic = LLI_INODE_DEAD;
1923 if (S_ISDIR(inode->i_mode))
1924 ll_dir_clear_lsm_md(inode);
1925 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1926 LASSERT(list_empty(&lli->lli_agl_list));
1929 * XXX This has to be done before lsm is freed below, because
1930 * cl_object still uses inode lsm.
1932 cl_inode_fini(inode);
1934 llcrypt_put_encryption_info(inode);
1939 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1941 struct lustre_md md;
1942 struct inode *inode = dentry->d_inode;
1943 struct ll_sb_info *sbi = ll_i2sbi(inode);
1944 struct ptlrpc_request *request = NULL;
1949 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1950 LUSTRE_OPC_ANY, NULL);
1951 if (IS_ERR(op_data))
1952 RETURN(PTR_ERR(op_data));
1954 /* If this is a chgrp of a regular file, we want to reserve enough
1955 * quota to cover the entire file size.
1957 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1958 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1959 from_kgid(&init_user_ns, inode->i_gid)) {
1960 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1961 op_data->op_attr_blocks = inode->i_blocks;
1965 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1967 ptlrpc_req_finished(request);
1968 if (rc == -ENOENT) {
1970 /* Unlinked special device node? Or just a race?
1971 * Pretend we done everything. */
1972 if (!S_ISREG(inode->i_mode) &&
1973 !S_ISDIR(inode->i_mode)) {
1974 ia_valid = op_data->op_attr.ia_valid;
1975 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1976 rc = simple_setattr(&nop_mnt_idmap, dentry,
1978 op_data->op_attr.ia_valid = ia_valid;
1980 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1981 CERROR("md_setattr fails: rc = %d\n", rc);
1986 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1987 sbi->ll_md_exp, &md);
1989 ptlrpc_req_finished(request);
1993 ia_valid = op_data->op_attr.ia_valid;
1994 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1995 * cache is not cleared yet. */
1996 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1997 if (S_ISREG(inode->i_mode))
1998 ll_inode_lock(inode);
1999 rc = simple_setattr(&nop_mnt_idmap, dentry, &op_data->op_attr);
2000 if (S_ISREG(inode->i_mode))
2001 ll_inode_unlock(inode);
2002 op_data->op_attr.ia_valid = ia_valid;
2004 rc = ll_update_inode(inode, &md);
2005 ptlrpc_req_finished(request);
2006 md_put_lustre_md(sbi->ll_md_exp, &md);
2012 * Zero portion of page that is part of @inode.
2013 * This implies, if necessary:
2014 * - taking cl_lock on range corresponding to concerned page
2015 * - grabbing vm page
2016 * - associating cl_page
2017 * - proceeding to clio read
2018 * - zeroing range in page
2019 * - proceeding to cl_page flush
2020 * - releasing cl_lock
2022 * \param[in] inode inode
2023 * \param[in] index page index
2024 * \param[in] offset offset in page to start zero from
2025 * \param[in] len len to zero
2027 * \retval 0 on success
2028 * \retval negative errno on failure
2030 static int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
2033 struct ll_inode_info *lli = ll_i2info(inode);
2034 struct cl_object *clob = lli->lli_clob;
2036 struct lu_env *env = NULL;
2037 struct cl_io *io = NULL;
2038 struct cl_page *clpage = NULL;
2039 struct page *vmpage = NULL;
2040 unsigned from = index << PAGE_SHIFT;
2041 struct cl_lock *lock = NULL;
2042 struct cl_lock_descr *descr = NULL;
2043 struct cl_2queue *queue = NULL;
2044 struct cl_sync_io *anchor = NULL;
2045 bool holdinglock = false;
2050 env = cl_env_get(&refcheck);
2052 RETURN(PTR_ERR(env));
2054 io = vvp_env_thread_io(env);
2056 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2060 lock = vvp_env_lock(env);
2061 descr = &lock->cll_descr;
2062 descr->cld_obj = io->ci_obj;
2063 descr->cld_start = from >> PAGE_SHIFT;
2064 descr->cld_end = (from + PAGE_SIZE - 1) >> PAGE_SHIFT;
2065 descr->cld_mode = CLM_WRITE;
2066 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2068 /* request lock for page */
2069 rc = cl_lock_request(env, io, lock);
2070 /* -ECANCELED indicates a matching lock with a different extent
2071 * was already present, and -EEXIST indicates a matching lock
2072 * on exactly the same extent was already present.
2073 * In both cases it means we are covered.
2075 if (rc == -ECANCELED || rc == -EEXIST)
2083 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2085 GOTO(rellock, rc = -EOPNOTSUPP);
2087 if (!PageDirty(vmpage)) {
2088 /* associate cl_page */
2089 clpage = cl_page_find(env, clob, vmpage->index,
2090 vmpage, CPT_CACHEABLE);
2092 GOTO(pagefini, rc = PTR_ERR(clpage));
2094 cl_page_assume(env, io, clpage);
2097 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2098 !PageWriteback(vmpage)) {
2100 /* Set PagePrivate2 to detect special case of empty page
2101 * in osc_brw_fini_request().
2102 * It is also used to tell ll_io_read_page() that we do not
2103 * want the vmpage to be unlocked.
2105 SetPagePrivate2(vmpage);
2106 rc = ll_io_read_page(env, io, clpage, NULL);
2107 if (!PagePrivate2(vmpage)) {
2108 /* PagePrivate2 was cleared in osc_brw_fini_request()
2109 * meaning we read an empty page. In this case, in order
2110 * to avoid allocating unnecessary block in truncated
2111 * file, we must not zero and write as below. Subsequent
2112 * server-side truncate will handle things correctly.
2114 cl_page_unassume(env, io, clpage);
2115 GOTO(clpfini, rc = 0);
2117 ClearPagePrivate2(vmpage);
2122 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2123 * the vmpage, so we are good to proceed and zero range in page.
2125 zero_user(vmpage, offset, len);
2127 if (holdinglock && clpage) {
2128 /* explicitly write newly modified page */
2129 queue = &io->ci_queue;
2130 cl_2queue_init(queue);
2131 anchor = &vvp_env_info(env)->vti_anchor;
2132 cl_sync_io_init(anchor, 1);
2133 clpage->cp_sync_io = anchor;
2134 cl_page_list_add(&queue->c2_qin, clpage, true);
2135 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2137 GOTO(queuefini1, rc);
2138 rc = cl_sync_io_wait(env, anchor, 0);
2140 GOTO(queuefini2, rc);
2141 cl_page_assume(env, io, clpage);
2144 cl_2queue_discard(env, io, queue);
2146 cl_2queue_disown(env, queue);
2147 cl_2queue_fini(env, queue);
2152 cl_page_put(env, clpage);
2154 unlock_page(vmpage);
2158 cl_lock_release(env, lock);
2160 cl_io_fini(env, io);
2163 cl_env_put(env, &refcheck);
2169 * Get reference file from volatile file name.
2170 * Volatile file name may look like:
2171 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2172 * where fd is opened descriptor of reference file.
2174 * \param[in] volatile_name volatile file name
2175 * \param[in] volatile_len volatile file name length
2176 * \param[out] ref_file pointer to struct file of reference file
2178 * \retval 0 on success
2179 * \retval negative errno on failure
2181 int volatile_ref_file(const char *volatile_name, int volatile_len,
2182 struct file **ref_file)
2184 char *p, *q, *fd_str;
2187 p = strnstr(volatile_name, ":fd=", volatile_len);
2188 if (!p || strlen(p + 4) == 0)
2191 q = strchrnul(p + 4, ':');
2192 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2195 rc = kstrtouint(fd_str, 10, &fd);
2200 *ref_file = fget(fd);
2206 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2207 * object(s) determine the file size and mtime. Otherwise, the MDS will
2208 * keep these values until such a time that objects are allocated for it.
2209 * We do the MDS operations first, as it is checking permissions for us.
2210 * We don't to the MDS RPC if there is nothing that we want to store there,
2211 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2212 * going to do an RPC anyways.
2214 * If we are doing a truncate, we will send the mtime and ctime updates
2215 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2216 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2219 * In case of HSMimport, we only set attr on MDS.
2221 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2222 enum op_xvalid xvalid, bool hsm_import)
2224 struct inode *inode = dentry->d_inode;
2225 struct ll_inode_info *lli = ll_i2info(inode);
2226 struct md_op_data *op_data = NULL;
2227 ktime_t kstart = ktime_get();
2232 /* VFS has locked the inode before calling this */
2233 ll_set_inode_lock_owner(inode);
2235 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2236 "valid %x, hsm_import %d\n",
2237 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2238 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2241 if (attr->ia_valid & ATTR_SIZE) {
2242 /* Check new size against VFS/VM file size limit and rlimit */
2243 rc = inode_newsize_ok(inode, attr->ia_size);
2247 /* The maximum Lustre file size is variable, based on the
2248 * OST maximum object size and number of stripes. This
2249 * needs another check in addition to the VFS check above. */
2250 if (attr->ia_size > ll_file_maxbytes(inode)) {
2251 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2252 PFID(&lli->lli_fid), attr->ia_size,
2253 ll_file_maxbytes(inode));
2254 GOTO(clear, rc = -EFBIG);
2257 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2260 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2261 if (attr->ia_valid & TIMES_SET_FLAGS) {
2262 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2263 !capable(CAP_FOWNER))
2264 GOTO(clear, rc = -EPERM);
2267 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2268 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2269 (attr->ia_valid & ATTR_CTIME)) {
2270 attr->ia_ctime = current_time(inode);
2271 xvalid |= OP_XVALID_CTIME_SET;
2273 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2274 (attr->ia_valid & ATTR_ATIME)) {
2275 attr->ia_atime = current_time(inode);
2276 attr->ia_valid |= ATTR_ATIME_SET;
2278 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2279 (attr->ia_valid & ATTR_MTIME)) {
2280 attr->ia_mtime = current_time(inode);
2281 attr->ia_valid |= ATTR_MTIME_SET;
2284 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2285 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2286 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2287 ktime_get_real_seconds());
2289 if (S_ISREG(inode->i_mode))
2290 ll_inode_unlock(inode);
2292 /* We always do an MDS RPC, even if we're only changing the size;
2293 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2295 OBD_ALLOC_PTR(op_data);
2296 if (op_data == NULL)
2297 GOTO(out, rc = -ENOMEM);
2299 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2300 /* If we are changing file size, file content is
2301 * modified, flag it.
2303 xvalid |= OP_XVALID_OWNEROVERRIDE;
2304 op_data->op_bias |= MDS_DATA_MODIFIED;
2305 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2308 if (attr->ia_valid & ATTR_FILE) {
2309 struct ll_file_data *fd = attr->ia_file->private_data;
2311 if (fd->fd_lease_och)
2312 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2315 op_data->op_attr = *attr;
2316 op_data->op_xvalid = xvalid;
2318 rc = ll_md_setattr(dentry, op_data);
2321 lli->lli_synced_to_mds = false;
2323 if (!S_ISREG(inode->i_mode) || hsm_import)
2326 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2327 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2328 xvalid & OP_XVALID_CTIME_SET) {
2329 bool cached = false;
2331 rc = pcc_inode_setattr(inode, attr, &cached);
2334 CERROR("%s: PCC inode "DFID" setattr failed: "
2336 ll_i2sbi(inode)->ll_fsname,
2337 PFID(&lli->lli_fid), rc);
2341 unsigned int flags = 0;
2343 /* For truncate and utimes sending attributes to OSTs,
2344 * setting mtime/atime to the past will be performed
2345 * under PW [0:EOF] extent lock (new_size:EOF for
2346 * truncate). It may seem excessive to send mtime/atime
2347 * updates to OSTs when not setting times to past, but
2348 * it is necessary due to possible time
2349 * de-synchronization between MDT inode and OST objects
2351 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2352 xvalid |= OP_XVALID_FLAGS;
2353 flags = LUSTRE_ENCRYPT_FL;
2354 /* Call to ll_io_zero_page is not necessary if
2355 * truncating on PAGE_SIZE boundary, because
2356 * whole pages will be wiped.
2357 * In case of Direct IO, all we need is to set
2360 if (attr->ia_valid & ATTR_SIZE &&
2361 attr->ia_size & ~PAGE_MASK &&
2362 !(attr->ia_valid & ATTR_FILE &&
2363 attr->ia_file->f_flags & O_DIRECT)) {
2365 attr->ia_size & (PAGE_SIZE - 1);
2367 rc = ll_io_zero_page(inode,
2368 attr->ia_size >> PAGE_SHIFT,
2369 offset, PAGE_SIZE - offset);
2373 /* If encrypted volatile file without the key,
2374 * we need to fetch size from reference file,
2375 * and set it on OST objects. This happens when
2376 * migrating or extending an encrypted file
2379 if (filename_is_volatile(dentry->d_name.name,
2382 llcrypt_require_key(inode) == -ENOKEY) {
2383 struct file *ref_file;
2384 struct inode *ref_inode;
2385 struct ll_inode_info *ref_lli;
2386 struct cl_object *ref_obj;
2387 struct cl_attr ref_attr = { 0 };
2391 rc = volatile_ref_file(
2392 dentry->d_name.name,
2398 ref_inode = file_inode(ref_file);
2401 GOTO(out, rc = -EINVAL);
2404 env = cl_env_get(&refcheck);
2406 GOTO(out, rc = PTR_ERR(env));
2408 ref_lli = ll_i2info(ref_inode);
2409 ref_obj = ref_lli->lli_clob;
2410 cl_object_attr_lock(ref_obj);
2411 rc = cl_object_attr_get(env, ref_obj,
2413 cl_object_attr_unlock(ref_obj);
2414 cl_env_put(env, &refcheck);
2419 attr->ia_valid |= ATTR_SIZE;
2420 attr->ia_size = ref_attr.cat_size;
2423 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2427 /* If the file was restored, it needs to set dirty flag.
2429 * We've already sent MDS_DATA_MODIFIED flag in
2430 * ll_md_setattr() for truncate. However, the MDT refuses to
2431 * set the HS_DIRTY flag on released files, so we have to set
2432 * it again if the file has been restored. Please check how
2433 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2435 * Please notice that if the file is not released, the previous
2436 * MDS_DATA_MODIFIED has taken effect and usually
2437 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2438 * This way we can save an RPC for common open + trunc
2440 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2441 struct hsm_state_set hss = {
2442 .hss_valid = HSS_SETMASK,
2443 .hss_setmask = HS_DIRTY,
2447 rc2 = ll_hsm_state_set(inode, &hss);
2448 /* truncate and write can happen at the same time, so that
2449 * the file can be set modified even though the file is not
2450 * restored from released state, and ll_hsm_state_set() is
2451 * not applicable for the file, and rc2 < 0 is normal in this
2454 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2455 PFID(ll_inode2fid(inode)), rc2);
2460 if (op_data != NULL)
2461 ll_finish_md_op_data(op_data);
2463 if (S_ISREG(inode->i_mode)) {
2464 ll_inode_lock(inode);
2465 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2466 inode_dio_wait(inode);
2467 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2468 * flag. ll_update_inode (called from ll_md_setattr), clears
2469 * inode flags, so there is a gap where S_NOSEC is not set.
2470 * This can cause a writer to take the i_mutex unnecessarily,
2471 * but this is safe to do and should be rare. */
2472 inode_has_no_xattr(inode);
2476 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2477 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2478 ktime_us_delta(ktime_get(), kstart));
2480 ll_clear_inode_lock_owner(inode);
2485 int ll_setattr(struct mnt_idmap *map, struct dentry *de, struct iattr *attr)
2487 int mode = de->d_inode->i_mode;
2488 enum op_xvalid xvalid = 0;
2491 rc = llcrypt_prepare_setattr(de, attr);
2495 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2496 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2497 xvalid |= OP_XVALID_OWNEROVERRIDE;
2499 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2500 (ATTR_SIZE|ATTR_MODE)) &&
2501 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2502 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2503 !(attr->ia_mode & S_ISGID))))
2504 attr->ia_valid |= ATTR_FORCE;
2506 if ((attr->ia_valid & ATTR_MODE) &&
2508 !(attr->ia_mode & S_ISUID) &&
2509 !(attr->ia_valid & ATTR_KILL_SUID))
2510 attr->ia_valid |= ATTR_KILL_SUID;
2512 if ((attr->ia_valid & ATTR_MODE) &&
2513 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2514 !(attr->ia_mode & S_ISGID) &&
2515 !(attr->ia_valid & ATTR_KILL_SGID))
2516 attr->ia_valid |= ATTR_KILL_SGID;
2518 return ll_setattr_raw(de, attr, xvalid, false);
2521 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2524 struct obd_statfs obd_osfs = { 0 };
2529 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2531 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2532 flags |= OBD_STATFS_NODELAY;
2534 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2538 osfs->os_type = LL_SUPER_MAGIC;
2540 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2541 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2543 if (osfs->os_state & OS_STATFS_SUM)
2546 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2547 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2550 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2551 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2554 osfs->os_bsize = obd_osfs.os_bsize;
2555 osfs->os_blocks = obd_osfs.os_blocks;
2556 osfs->os_bfree = obd_osfs.os_bfree;
2557 osfs->os_bavail = obd_osfs.os_bavail;
2559 /* If we have _some_ OSTs, but don't have as many free objects on the
2560 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2561 * to compensate, so that the "inodes in use" number is correct.
2562 * This should be kept in sync with lod_statfs() behaviour.
2564 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2565 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2567 osfs->os_ffree = obd_osfs.os_ffree;
2574 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2576 struct if_quotactl qctl = {
2577 .qc_cmd = LUSTRE_Q_GETQUOTA,
2578 .qc_type = PRJQUOTA,
2579 .qc_valid = QC_GENERAL,
2581 u64 limit, curblock;
2584 qctl.qc_id = ll_i2info(inode)->lli_projid;
2585 ret = quotactl_ioctl(inode->i_sb, &qctl);
2587 /* ignore errors if project ID does not have
2588 * a quota limit or feature unsupported.
2590 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2595 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2596 qctl.qc_dqblk.dqb_bsoftlimit :
2597 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2598 if (limit && sfs->f_blocks > limit) {
2599 curblock = (qctl.qc_dqblk.dqb_curspace +
2600 sfs->f_bsize - 1) / sfs->f_bsize;
2601 sfs->f_blocks = limit;
2602 sfs->f_bfree = sfs->f_bavail =
2603 (sfs->f_blocks > curblock) ?
2604 (sfs->f_blocks - curblock) : 0;
2607 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2608 qctl.qc_dqblk.dqb_isoftlimit :
2609 qctl.qc_dqblk.dqb_ihardlimit;
2610 if (limit && sfs->f_files > limit) {
2611 sfs->f_files = limit;
2612 sfs->f_ffree = (sfs->f_files >
2613 qctl.qc_dqblk.dqb_curinodes) ?
2614 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2620 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2622 struct super_block *sb = de->d_sb;
2623 struct obd_statfs osfs;
2624 __u64 fsid = huge_encode_dev(sb->s_dev);
2625 ktime_t kstart = ktime_get();
2628 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2630 /* Some amount of caching on the client is allowed */
2631 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2635 statfs_unpack(sfs, &osfs);
2637 /* We need to downshift for all 32-bit kernels, because we can't
2638 * tell if the kernel is being called via sys_statfs64() or not.
2639 * Stop before overflowing f_bsize - in which case it is better
2640 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2641 if (sizeof(long) < 8) {
2642 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2645 osfs.os_blocks >>= 1;
2646 osfs.os_bfree >>= 1;
2647 osfs.os_bavail >>= 1;
2651 sfs->f_blocks = osfs.os_blocks;
2652 sfs->f_bfree = osfs.os_bfree;
2653 sfs->f_bavail = osfs.os_bavail;
2654 sfs->f_fsid.val[0] = (__u32)fsid;
2655 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2656 if (ll_i2info(de->d_inode)->lli_projid &&
2657 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2658 return ll_statfs_project(de->d_inode, sfs);
2660 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2661 ktime_us_delta(ktime_get(), kstart));
2666 void ll_inode_size_lock(struct inode *inode)
2668 struct ll_inode_info *lli;
2670 LASSERT(!S_ISDIR(inode->i_mode));
2672 lli = ll_i2info(inode);
2673 mutex_lock(&lli->lli_size_mutex);
2674 lli->lli_size_lock_owner = current;
2677 void ll_inode_size_unlock(struct inode *inode)
2679 struct ll_inode_info *lli;
2681 lli = ll_i2info(inode);
2682 lli->lli_size_lock_owner = NULL;
2683 mutex_unlock(&lli->lli_size_mutex);
2686 int ll_inode_size_trylock(struct inode *inode)
2688 struct ll_inode_info *lli;
2690 LASSERT(!S_ISDIR(inode->i_mode));
2692 lli = ll_i2info(inode);
2693 return mutex_trylock(&lli->lli_size_mutex);
2696 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2698 /* do not clear encryption flag */
2699 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2700 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2701 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2702 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2704 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2707 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2709 struct ll_inode_info *lli = ll_i2info(inode);
2710 struct mdt_body *body = md->body;
2711 struct ll_sb_info *sbi = ll_i2sbi(inode);
2715 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2716 rc = cl_file_inode_init(inode, md);
2721 if (S_ISDIR(inode->i_mode)) {
2722 rc = ll_update_lsm_md(inode, md);
2727 if (body->mbo_valid & OBD_MD_FLACL)
2728 lli_replace_acl(lli, md);
2730 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2731 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2732 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2734 if (body->mbo_valid & OBD_MD_FLATIME) {
2735 if (body->mbo_atime > inode->i_atime.tv_sec)
2736 inode->i_atime.tv_sec = body->mbo_atime;
2737 lli->lli_atime = body->mbo_atime;
2740 if (body->mbo_valid & OBD_MD_FLMTIME) {
2741 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2743 "setting ino %lu mtime from %lld to %llu\n",
2744 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2746 inode->i_mtime.tv_sec = body->mbo_mtime;
2748 lli->lli_mtime = body->mbo_mtime;
2751 if (body->mbo_valid & OBD_MD_FLCTIME) {
2752 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2753 inode->i_ctime.tv_sec = body->mbo_ctime;
2754 lli->lli_ctime = body->mbo_ctime;
2757 if (body->mbo_valid & OBD_MD_FLBTIME)
2758 lli->lli_btime = body->mbo_btime;
2760 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2761 if (body->mbo_valid & OBD_MD_FLFLAGS)
2762 ll_update_inode_flags(inode, body->mbo_flags);
2763 if (body->mbo_valid & OBD_MD_FLMODE)
2764 inode->i_mode = (inode->i_mode & S_IFMT) |
2765 (body->mbo_mode & ~S_IFMT);
2767 if (body->mbo_valid & OBD_MD_FLTYPE)
2768 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2769 (body->mbo_mode & S_IFMT);
2771 LASSERT(inode->i_mode != 0);
2772 if (body->mbo_valid & OBD_MD_FLUID)
2773 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2774 if (body->mbo_valid & OBD_MD_FLGID)
2775 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2776 if (body->mbo_valid & OBD_MD_FLPROJID)
2777 lli->lli_projid = body->mbo_projid;
2778 if (body->mbo_valid & OBD_MD_FLNLINK) {
2779 spin_lock(&inode->i_lock);
2780 set_nlink(inode, body->mbo_nlink);
2781 spin_unlock(&inode->i_lock);
2783 if (body->mbo_valid & OBD_MD_FLRDEV)
2784 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2786 if (body->mbo_valid & OBD_MD_FLID) {
2787 /* FID shouldn't be changed! */
2788 if (fid_is_sane(&lli->lli_fid)) {
2789 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2790 "Trying to change FID "DFID
2791 " to the "DFID", inode "DFID"(%p)\n",
2792 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2793 PFID(ll_inode2fid(inode)), inode);
2795 lli->lli_fid = body->mbo_fid1;
2799 LASSERT(fid_seq(&lli->lli_fid) != 0);
2801 /* In case of encrypted file without the key, please do not lose
2802 * clear text size stored into lli_lazysize in ll_merge_attr(),
2803 * we will need it in ll_prepare_close().
2805 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2806 llcrypt_require_key(inode) == -ENOKEY)
2807 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2809 lli->lli_attr_valid = body->mbo_valid;
2810 if (body->mbo_valid & OBD_MD_FLSIZE) {
2811 i_size_write(inode, body->mbo_size);
2813 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2814 PFID(ll_inode2fid(inode)),
2815 (unsigned long long)body->mbo_size);
2817 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2818 inode->i_blocks = body->mbo_blocks;
2820 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2821 lli->lli_lazysize = body->mbo_size;
2822 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2823 lli->lli_lazyblocks = body->mbo_blocks;
2826 if (body->mbo_valid & OBD_MD_TSTATE) {
2827 /* Set LLIF_FILE_RESTORING if restore ongoing and
2828 * clear it when done to ensure to start again
2829 * glimpsing updated attrs
2831 if (body->mbo_t_state & MS_RESTORE)
2832 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2834 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2840 /* child default LMV is inherited from parent */
2841 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2842 struct lmv_stripe_md *cdmv)
2847 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2848 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2849 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2850 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2853 if (cdmv->lsm_md_max_inherit !=
2854 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2857 if (cdmv->lsm_md_max_inherit_rr !=
2858 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2864 /* if default LMV is implicitly inherited, subdir default LMV is maintained on
2867 static int ll_dir_default_lmv_inherit(struct inode *dir, struct inode *inode)
2869 struct ll_inode_info *plli = ll_i2info(dir);
2870 struct ll_inode_info *lli = ll_i2info(inode);
2871 struct lmv_stripe_object *plsm_obj;
2872 struct lmv_stripe_object *lsm_obj;
2877 /* ROOT default LMV is not inherited */
2878 if (is_root_inode(dir) ||
2879 !(exp_connect_flags2(ll_i2mdexp(dir)) &
2880 OBD_CONNECT2_DMV_IMP_INHERIT))
2883 /* nothing to do if no default LMV on both */
2884 if (!plli->lli_def_lsm_obj && !lli->lli_def_lsm_obj)
2887 /* subdir default LMV comes from disk */
2888 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set)
2891 /* delete subdir default LMV if parent's is deleted or becomes
2894 down_read(&plli->lli_lsm_sem);
2895 plsm_obj = plli->lli_def_lsm_obj;
2897 !lmv_is_inheritable(plsm_obj->lso_lsm.lsm_md_max_inherit)) {
2898 if (lli->lli_def_lsm_obj && !lli->lli_def_lsm_obj_set) {
2899 down_write(&lli->lli_lsm_sem);
2900 if (!lli->lli_def_lsm_obj_set) {
2901 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
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_def_lsm_obj) {
2912 down_read(&lli->lli_lsm_sem);
2913 if (!lli->lli_def_lsm_obj_set)
2914 rc = lmv_object_inherited(plsm_obj,
2915 lli->lli_def_lsm_obj);
2916 up_read(&lli->lli_lsm_sem);
2918 GOTO(unlock_parent, rc = 0);
2921 /* inherit default LMV */
2922 down_write(&lli->lli_lsm_sem);
2923 if (lli->lli_def_lsm_obj) {
2924 /* checked above, but in case of race, check again with lock */
2925 if (lli->lli_def_lsm_obj_set)
2926 GOTO(unlock_child, rc = 0);
2927 /* always update subdir default LMV in case parent's changed */
2928 lsm_obj = lli->lli_def_lsm_obj;
2930 lsm_obj = lmv_stripe_object_alloc(LMV_USER_MAGIC, NULL, 0);
2931 if (IS_ERR(lsm_obj))
2932 GOTO(unlock_child, rc = PTR_ERR(lsm_obj));
2933 lli->lli_def_lsm_obj = lsm_obj;
2936 lsm_obj->lso_lsm = plsm_obj->lso_lsm;
2937 lsm_obj->lso_lsm.lsm_md_max_inherit =
2938 lmv_inherit_next(plsm_obj->lso_lsm.lsm_md_max_inherit);
2939 lsm_obj->lso_lsm.lsm_md_max_inherit_rr =
2940 lmv_inherit_rr_next(plsm_obj->lso_lsm.lsm_md_max_inherit_rr);
2941 lli->lli_inherit_depth = plli->lli_inherit_depth + 1;
2943 lmv_stripe_object_dump(D_INODE, lsm_obj);
2947 up_write(&lli->lli_lsm_sem);
2949 up_read(&plli->lli_lsm_sem);
2954 enum lsm_sem_class {
2960 * Update directory depth and default LMV
2962 * Update directory depth to ROOT and inherit default LMV from parent if
2963 * parent's default LMV is inheritable. The default LMV set with command
2964 * "lfs setdirstripe -D ..." is stored on MDT, while the inherited default LMV
2965 * is generated at runtime on client side.
2967 * \param[in] dir parent directory inode
2968 * \param[in] de dentry
2970 void ll_update_dir_depth_dmv(struct inode *dir, struct dentry *de)
2972 struct inode *inode = de->d_inode;
2973 struct ll_inode_info *plli;
2974 struct ll_inode_info *lli;
2976 LASSERT(S_ISDIR(inode->i_mode));
2980 plli = ll_i2info(dir);
2981 lli = ll_i2info(inode);
2982 lli->lli_dir_depth = plli->lli_dir_depth + 1;
2983 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set) {
2984 if (plli->lli_def_lsm_obj) {
2985 down_read_nested(&plli->lli_lsm_sem, LSM_SEM_PARENT);
2986 down_read_nested(&lli->lli_lsm_sem, LSM_SEM_CHILD);
2987 if (lmv_object_inherited(plli->lli_def_lsm_obj,
2988 lli->lli_def_lsm_obj))
2989 lli->lli_inherit_depth =
2990 plli->lli_inherit_depth + 1;
2992 /* in case parent default LMV changed */
2993 lli->lli_inherit_depth = 0;
2994 up_read(&lli->lli_lsm_sem);
2995 up_read(&plli->lli_lsm_sem);
2997 /* in case parent default LMV deleted */
2998 lli->lli_inherit_depth = 0;
3001 ll_dir_default_lmv_inherit(dir, inode);
3004 if (lli->lli_def_lsm_obj)
3006 "%s "DFID" depth %hu %s default LMV inherit depth %hu\n",
3007 de->d_name.name, PFID(&lli->lli_fid), lli->lli_dir_depth,
3008 lli->lli_def_lsm_obj_set ? "server" : "client",
3009 lli->lli_inherit_depth);
3012 void ll_truncate_inode_pages_final(struct inode *inode)
3014 struct address_space *mapping = &inode->i_data;
3015 unsigned long nrpages;
3016 unsigned long flags;
3018 LASSERTF((inode->i_state & I_FREEING) || inode_is_locked(inode),
3019 DFID ":inode %p state %#lx, lli_flags %#lx\n",
3020 PFID(ll_inode2fid(inode)), inode, inode->i_state,
3021 ll_i2info(inode)->lli_flags);
3023 truncate_inode_pages_final(mapping);
3025 /* Workaround for LU-118: Note nrpages may not be totally updated when
3026 * truncate_inode_pages() returns, as there can be a page in the process
3027 * of deletion (inside __delete_from_page_cache()) in the specified
3028 * range. Thus mapping->nrpages can be non-zero when this function
3029 * returns even after truncation of the whole mapping. Only do this if
3030 * npages isn't already zero.
3032 nrpages = mapping->nrpages;
3034 ll_xa_lock_irqsave(&mapping->i_pages, flags);
3035 nrpages = mapping->nrpages;
3036 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
3037 } /* Workaround end */
3039 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu "
3040 "state %#lx, lli_flags %#lx, "
3041 "see https://jira.whamcloud.com/browse/LU-118\n",
3042 ll_i2sbi(inode)->ll_fsname,
3043 PFID(ll_inode2fid(inode)), inode, nrpages,
3044 inode->i_state, ll_i2info(inode)->lli_flags);
3047 int ll_read_inode2(struct inode *inode, void *opaque)
3049 struct lustre_md *md = opaque;
3050 struct ll_inode_info *lli = ll_i2info(inode);
3054 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
3055 PFID(&lli->lli_fid), inode);
3057 /* Core attributes from the MDS first. This is a new inode, and
3058 * the VFS doesn't zero times in the core inode so we have to do
3059 * it ourselves. They will be overwritten by either MDS or OST
3060 * attributes - we just need to make sure they aren't newer.
3062 inode->i_mtime.tv_sec = 0;
3063 inode->i_atime.tv_sec = 0;
3064 inode->i_ctime.tv_sec = 0;
3066 rc = ll_update_inode(inode, md);
3070 /* OIDEBUG(inode); */
3072 #ifdef HAVE_BACKING_DEV_INFO
3073 /* initializing backing dev info. */
3074 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
3076 if (S_ISREG(inode->i_mode)) {
3077 struct ll_sb_info *sbi = ll_i2sbi(inode);
3078 inode->i_op = &ll_file_inode_operations;
3079 inode->i_fop = sbi->ll_fop;
3080 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
3082 } else if (S_ISDIR(inode->i_mode)) {
3083 inode->i_op = &ll_dir_inode_operations;
3084 inode->i_fop = &ll_dir_operations;
3086 } else if (S_ISLNK(inode->i_mode)) {
3087 inode->i_op = &ll_fast_symlink_inode_operations;
3090 inode->i_op = &ll_special_inode_operations;
3092 init_special_inode(inode, inode->i_mode,
3101 void ll_delete_inode(struct inode *inode)
3103 struct ll_inode_info *lli = ll_i2info(inode);
3106 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
3107 /* It is last chance to write out dirty pages,
3108 * otherwise we may lose data while umount.
3110 * If i_nlink is 0 then just discard data. This is safe because
3111 * local inode gets i_nlink 0 from server only for the last
3112 * unlink, so that file is not opened somewhere else
3114 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
3115 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
3118 ll_truncate_inode_pages_final(inode);
3119 ll_clear_inode(inode);
3125 static int fileattr_get(struct inode *inode, int *flags,
3129 struct ll_sb_info *sbi = ll_i2sbi(inode);
3130 struct ptlrpc_request *req = NULL;
3131 struct md_op_data *op_data;
3132 struct mdt_body *body;
3136 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
3137 0, 0, LUSTRE_OPC_ANY,
3139 if (IS_ERR(op_data))
3140 RETURN(PTR_ERR(op_data));
3142 op_data->op_valid = OBD_MD_FLFLAGS;
3143 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
3144 ll_finish_md_op_data(op_data);
3146 CERROR("%s: failure inode "DFID": rc = %d\n",
3147 sbi->ll_md_exp->exp_obd->obd_name,
3148 PFID(ll_inode2fid(inode)), rc);
3152 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3154 *flags = body->mbo_flags;
3155 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
3156 * ext4 equivalent to please lsattr and other e2fsprogs tools
3158 if (*flags & LUSTRE_ENCRYPT_FL)
3159 *flags |= STATX_ATTR_ENCRYPTED;
3161 ptlrpc_req_finished(req);
3163 *xflags = ll_inode_flags_to_xflags(inode->i_flags);
3164 if (test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags))
3165 *xflags |= FS_XFLAG_PROJINHERIT;
3166 *projid = ll_i2info(inode)->lli_projid;
3171 static int fileattr_set(struct inode *inode, int flags)
3173 struct ll_sb_info *sbi = ll_i2sbi(inode);
3174 struct ptlrpc_request *req = NULL;
3175 struct md_op_data *op_data;
3176 struct cl_object *obj;
3177 struct fsxattr fa = { 0 };
3182 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3183 if (flags & LUSTRE_PROJINHERIT_FL)
3184 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3186 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3191 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3192 LUSTRE_OPC_ANY, NULL);
3193 if (IS_ERR(op_data))
3194 RETURN(PTR_ERR(op_data));
3196 op_data->op_attr_flags = flags;
3197 op_data->op_xvalid |= OP_XVALID_FLAGS;
3198 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3199 ll_finish_md_op_data(op_data);
3200 ptlrpc_req_finished(req);
3204 ll_update_inode_flags(inode, flags);
3206 obj = ll_i2info(inode)->lli_clob;
3210 OBD_ALLOC_PTR(attr);
3214 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3220 #ifdef HAVE_FILEATTR_GET
3221 int ll_fileattr_get(struct dentry *dentry, struct fileattr *fa)
3223 return fileattr_get(d_inode(dentry), &fa->flags,
3224 &fa->fsx_xflags, &fa->fsx_projid);
3227 int ll_fileattr_set(struct mnt_idmap *mnt_userns,
3228 struct dentry *dentry, struct fileattr *fa)
3231 return ll_set_project(d_inode(dentry), fa->fsx_xflags,
3234 return fileattr_set(d_inode(dentry), fa->flags);
3236 #endif /* HAVE_FILEATTR_GET */
3238 /* ioctl commands shared between files and directories */
3239 int ll_iocontrol(struct inode *inode, struct file *file,
3240 unsigned int cmd, void __user *uarg)
3247 RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
3248 case LL_IOC_GETVERSION:
3249 case FS_IOC_GETVERSION:
3250 RETURN(put_user(inode->i_generation, (int __user *)uarg));
3252 #ifndef HAVE_FILEATTR_GET
3253 case FS_IOC_GETFLAGS: {
3254 u32 xflags = 0, projid = 0;
3257 if (!ll_access_ok(uarg, sizeof(int)))
3259 rc = fileattr_get(file->f_inode, &flags, &xflags, &projid);
3263 RETURN(put_user(flags, (int __user *)uarg));
3265 case FS_IOC_SETFLAGS: {
3268 if (get_user(flags, (int __user *)uarg))
3271 RETURN(fileattr_set(file->f_inode, flags));
3273 case FS_IOC_FSGETXATTR:
3274 RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
3275 case FS_IOC_FSSETXATTR:
3276 RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
3277 #endif /* HAVE_FILEATTR_GET */
3278 case LL_IOC_PROJECT:
3279 RETURN(ll_ioctl_project(file, cmd, uarg));
3280 case IOC_OBD_STATFS:
3281 RETURN(ll_obd_statfs(inode, uarg));
3282 case LL_IOC_GET_MDTIDX: {
3283 if (!ll_access_ok(uarg, sizeof(rc)))
3286 rc = ll_get_mdt_idx(inode);
3290 if (put_user(rc, (int __user *)uarg))
3295 case LL_IOC_FLUSHCTX:
3296 RETURN(ll_flush_ctx(inode));
3297 #ifdef HAVE_LUSTRE_CRYPTO
3298 case LL_IOC_ADD_ENCRYPTION_KEY:
3299 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3301 rc = llcrypt_ioctl_add_key(file, uarg);
3302 #ifdef CONFIG_LL_ENCRYPTION
3303 if (!rc && S_ISDIR(inode->i_mode))
3304 sptlrpc_enc_pool_add_user();
3307 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
3308 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3310 RETURN(llcrypt_ioctl_get_key_status(file, uarg));
3311 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
3312 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3314 RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
3315 case LL_IOC_SET_ENCRYPTION_POLICY:
3316 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3318 RETURN(llcrypt_ioctl_set_policy(file, uarg));
3319 case LL_IOC_REMOVE_ENCRYPTION_KEY:
3320 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3322 RETURN(llcrypt_ioctl_remove_key(file, uarg));
3323 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
3324 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3326 RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
3328 case LL_IOC_GETPARENT:
3329 RETURN(ll_getparent(file, uarg));
3330 case LL_IOC_PATH2FID:
3331 if (copy_to_user(uarg, ll_inode2fid(inode),
3332 sizeof(struct lu_fid)))
3335 case LL_IOC_UNLOCK_FOREIGN: {
3336 struct dentry *dentry = file_dentry(file);
3338 /* if not a foreign symlink do nothing */
3339 if (ll_foreign_is_removable(dentry, true)) {
3341 "prevent unlink of non-foreign file ("DFID")\n",
3342 PFID(ll_inode2fid(inode)));
3343 RETURN(-EOPNOTSUPP);
3347 case OBD_IOC_FID2PATH:
3348 RETURN(ll_fid2path(inode, uarg));
3349 #ifdef OBD_IOC_GETNAME_OLD
3350 case_OBD_IOC_DEPRECATED_FT(OBD_IOC_GETNAME_OLD,
3351 ll_i2sbi(inode)->ll_md_exp->exp_obd->obd_name,
3354 case OBD_IOC_GETDTNAME:
3355 case OBD_IOC_GETMDNAME:
3356 RETURN(ll_get_obd_name(inode, cmd, uarg));
3364 int ll_flush_ctx(struct inode *inode)
3366 struct ll_sb_info *sbi = ll_i2sbi(inode);
3368 CDEBUG(D_SEC, "flush context for user %d\n",
3369 from_kuid(&init_user_ns, current_uid()));
3371 obd_set_info_async(NULL, sbi->ll_md_exp,
3372 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3374 obd_set_info_async(NULL, sbi->ll_dt_exp,
3375 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3380 /* umount -f client means force down, don't save state */
3381 void ll_umount_begin(struct super_block *sb)
3383 struct ll_sb_info *sbi = ll_s2sbi(sb);
3384 struct obd_device *obd;
3385 struct obd_ioctl_data *ioc_data;
3389 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3390 sb->s_count, atomic_read(&sb->s_active));
3392 obd = class_exp2obd(sbi->ll_md_exp);
3394 CERROR("Invalid MDC connection handle %#llx\n",
3395 sbi->ll_md_exp->exp_handle.h_cookie);
3401 obd = class_exp2obd(sbi->ll_dt_exp);
3403 CERROR("Invalid LOV connection handle %#llx\n",
3404 sbi->ll_dt_exp->exp_handle.h_cookie);
3410 OBD_ALLOC_PTR(ioc_data);
3412 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_md_exp,
3413 sizeof *ioc_data, ioc_data, NULL);
3415 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_dt_exp,
3416 sizeof *ioc_data, ioc_data, NULL);
3418 OBD_FREE_PTR(ioc_data);
3421 /* Really, we'd like to wait until there are no requests outstanding,
3422 * and then continue. For now, we just periodically checking for vfs
3423 * to decrement mnt_cnt and hope to finish it within 10sec.
3427 !may_umount(sbi->ll_mnt.mnt)) {
3435 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3437 struct ll_sb_info *sbi = ll_s2sbi(sb);
3438 char *profilenm = get_profile_name(sb);
3442 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3443 read_only = *flags & MS_RDONLY;
3444 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3445 sizeof(KEY_READ_ONLY),
3446 KEY_READ_ONLY, sizeof(read_only),
3449 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3450 profilenm, read_only ?
3451 "read-only" : "read-write", err);
3456 sb->s_flags |= SB_RDONLY;
3458 sb->s_flags &= ~SB_RDONLY;
3460 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3461 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3462 read_only ? "read-only" : "read-write");
3468 * Cleanup the open handle that is cached on MDT-side.
3470 * For open case, the client side open handling thread may hit error
3471 * after the MDT grant the open. Under such case, the client should
3472 * send close RPC to the MDT as cleanup; otherwise, the open handle
3473 * on the MDT will be leaked there until the client umount or evicted.
3475 * In further, if someone unlinked the file, because the open handle
3476 * holds the reference on such file/object, then it will block the
3477 * subsequent threads that want to locate such object via FID.
3479 * \param[in] sb super block for this file-system
3480 * \param[in] open_req pointer to the original open request
3482 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3484 struct mdt_body *body;
3485 struct md_op_data *op_data;
3486 struct ptlrpc_request *close_req = NULL;
3487 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3490 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3491 OBD_ALLOC_PTR(op_data);
3492 if (op_data == NULL) {
3493 CWARN("%s: cannot allocate op_data to release open handle for "
3494 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3499 op_data->op_fid1 = body->mbo_fid1;
3500 op_data->op_open_handle = body->mbo_open_handle;
3501 op_data->op_mod_time = ktime_get_real_seconds();
3502 md_close(exp, op_data, NULL, &close_req);
3503 ptlrpc_req_finished(close_req);
3504 ll_finish_md_op_data(op_data);
3509 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3510 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3511 struct lustre_md *md)
3513 struct ll_sb_info *sbi = ll_i2sbi(inode);
3514 struct ptlrpc_request *req = NULL;
3515 union lmv_mds_md *lmm = NULL;
3519 LASSERT(is_root_inode(inode));
3520 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3521 LASSERT(!md->def_lsm_obj);
3523 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3525 GET_DEFAULT_LAYOUT_ROOT);
3526 if (rc && rc != -ENODATA)
3531 rc = md_stripe_object_create(sbi->ll_md_exp, &md->def_lsm_obj,
3541 ptlrpc_req_finished(req);
3545 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3546 struct super_block *sb, struct lookup_intent *it)
3548 struct ll_sb_info *sbi = NULL;
3549 struct lustre_md md = { NULL };
3550 bool default_lmv_deleted = false;
3555 LASSERT(*inode || sb);
3556 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3557 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3558 sbi->ll_md_exp, &md);
3563 * clear default_lmv only if intent_getattr reply doesn't contain it.
3564 * but it needs to be done after iget, check this early because
3565 * ll_update_lsm_md() may change md.
3567 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3568 S_ISDIR(md.body->mbo_mode) && !md.def_lsm_obj) {
3569 if (unlikely(*inode && is_root_inode(*inode) &&
3570 !fid_is_root(&sbi->ll_root_fid))) {
3571 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3576 if (!md.def_lsm_obj)
3577 default_lmv_deleted = true;
3581 rc = ll_update_inode(*inode, &md);
3585 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3586 struct lu_fid *fid1 = &md.body->mbo_fid1;
3588 LASSERT(sb != NULL);
3591 * At this point server returns to client's same fid as client
3592 * generated for creating. So using ->fid1 is okay here.
3594 if (!fid_is_sane(fid1)) {
3595 CERROR("%s: Fid is insane "DFID"\n",
3596 sbi->ll_fsname, PFID(fid1));
3597 GOTO(out, rc = -EINVAL);
3600 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3601 if (IS_ERR(*inode)) {
3603 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3605 CERROR("new_inode -fatal: rc %d\n", rc);
3610 /* Handling piggyback layout lock.
3611 * Layout lock can be piggybacked by getattr and open request.
3612 * The lsm can be applied to inode only if it comes with a layout lock
3613 * otherwise correct layout may be overwritten, for example:
3614 * 1. proc1: mdt returns a lsm but not granting layout
3615 * 2. layout was changed by another client
3616 * 3. proc2: refresh layout and layout lock granted
3617 * 4. proc1: to apply a stale layout */
3618 if (it != NULL && it->it_lock_mode != 0) {
3619 struct lustre_handle lockh;
3620 struct ldlm_lock *lock;
3622 lockh.cookie = it->it_lock_handle;
3623 lock = ldlm_handle2lock(&lockh);
3624 LASSERT(lock != NULL);
3625 if (ldlm_has_layout(lock)) {
3626 struct cl_object_conf conf;
3628 memset(&conf, 0, sizeof(conf));
3629 conf.coc_opc = OBJECT_CONF_SET;
3630 conf.coc_inode = *inode;
3631 conf.coc_lock = lock;
3632 conf.coc_try = false;
3633 conf.u.coc_layout = md.layout;
3634 (void)ll_layout_conf(*inode, &conf);
3636 LDLM_LOCK_PUT(lock);
3639 if (default_lmv_deleted)
3640 ll_update_default_lsm_md(*inode, &md);
3642 /* we may want to apply some policy for foreign file/dir */
3643 if (ll_sbi_has_foreign_symlink(sbi)) {
3644 rc = ll_manage_foreign(*inode, &md);
3652 /* cleanup will be done if necessary */
3653 md_put_lustre_md(sbi->ll_md_exp, &md);
3655 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3656 ll_intent_drop_lock(it);
3657 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3663 int ll_obd_statfs(struct inode *inode, void __user *uarg)
3665 struct ll_sb_info *sbi = NULL;
3666 struct obd_export *exp;
3667 struct obd_ioctl_data *data = NULL;
3672 sbi = ll_i2sbi(inode);
3674 GOTO(out_statfs, rc = -EINVAL);
3676 rc = obd_ioctl_getdata(&data, &len, uarg);
3678 GOTO(out_statfs, rc);
3680 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3681 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3682 GOTO(out_statfs, rc = -EINVAL);
3684 if (data->ioc_inllen1 != sizeof(__u32) ||
3685 data->ioc_inllen2 != sizeof(__u32) ||
3686 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3687 data->ioc_plen2 != sizeof(struct obd_uuid))
3688 GOTO(out_statfs, rc = -EINVAL);
3690 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3691 if (type & LL_STATFS_LMV)
3692 exp = sbi->ll_md_exp;
3693 else if (type & LL_STATFS_LOV)
3694 exp = sbi->ll_dt_exp;
3696 GOTO(out_statfs, rc = -ENODEV);
3698 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3700 GOTO(out_statfs, rc);
3702 OBD_FREE_LARGE(data, len);
3707 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3708 * be called early to avoid deadlock.
3710 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3712 lmv_stripe_object_put(&op_data->op_lso2);
3713 lmv_stripe_object_put(&op_data->op_lso1);
3714 lmv_stripe_object_put(&op_data->op_default_lso1);
3717 /* this function prepares md_op_data hint for passing it down to MD stack. */
3718 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3719 struct inode *i1, struct inode *i2,
3720 const char *name, size_t namelen,
3721 __u32 mode, enum md_op_code opc,
3724 struct llcrypt_name fname = { 0 };
3727 LASSERT(i1 != NULL);
3730 /* Do not reuse namelen for something else. */
3732 return ERR_PTR(-EINVAL);
3734 if ((!IS_ENCRYPTED(i1) ||
3735 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3736 namelen > ll_i2sbi(i1)->ll_namelen)
3737 return ERR_PTR(-ENAMETOOLONG);
3739 /* "/" is not valid name, but it's allowed */
3740 if (!lu_name_is_valid_2(name, namelen) &&
3741 strncmp("/", name, namelen) != 0)
3742 return ERR_PTR(-EINVAL);
3745 if (op_data == NULL)
3746 OBD_ALLOC_PTR(op_data);
3748 if (op_data == NULL)
3749 return ERR_PTR(-ENOMEM);
3751 ll_i2gids(op_data->op_suppgids, i1, i2);
3752 /* If the client is using a subdir mount and looks at what it sees as
3753 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3755 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3756 !fid_is_root(ll_inode2fid(i1)) &&
3757 name && namelen == strlen(dot_fscrypt_name) &&
3758 strncmp(name, dot_fscrypt_name, namelen) == 0))
3759 lu_root_fid(&op_data->op_fid1);
3761 op_data->op_fid1 = *ll_inode2fid(i1);
3763 if (S_ISDIR(i1->i_mode)) {
3764 down_read(&ll_i2info(i1)->lli_lsm_sem);
3766 lmv_stripe_object_get(ll_i2info(i1)->lli_lsm_obj);
3767 op_data->op_default_lso1 =
3768 lmv_stripe_object_get(ll_i2info(i1)->lli_def_lsm_obj);
3769 up_read(&ll_i2info(i1)->lli_lsm_sem);
3773 op_data->op_fid2 = *ll_inode2fid(i2);
3774 if (S_ISDIR(i2->i_mode)) {
3775 down_read(&ll_i2info(i2)->lli_lsm_sem);
3777 lmv_stripe_object_get(ll_i2info(i2)->lli_lsm_obj);
3778 up_read(&ll_i2info(i2)->lli_lsm_sem);
3781 fid_zero(&op_data->op_fid2);
3784 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3785 op_data->op_cli_flags |= CLI_HASH64;
3787 if (ll_need_32bit_api(ll_i2sbi(i1)))
3788 op_data->op_cli_flags |= CLI_API32;
3790 if ((i2 && is_root_inode(i2)) ||
3791 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3792 /* In case of lookup, ll_setup_filename() has already been
3793 * called in ll_lookup_it(), so just take provided name.
3794 * Also take provided name if we are dealing with root inode.
3796 fname.disk_name.name = (unsigned char *)name;
3797 fname.disk_name.len = namelen;
3798 } else if (name && namelen) {
3799 struct qstr dname = QSTR_INIT(name, namelen);
3801 struct lu_fid *pfid = NULL;
3805 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3806 /* special case when called from ll_link() */
3811 lookup = (int)(opc == LUSTRE_OPC_ANY);
3813 if (opc == LUSTRE_OPC_ANY && lookup)
3815 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3817 ll_finish_md_op_data(op_data);
3820 if (pfid && !fid_is_zero(pfid)) {
3822 op_data->op_fid2 = fid;
3823 op_data->op_bias = MDS_FID_OP;
3825 if (fname.disk_name.name &&
3826 fname.disk_name.name != (unsigned char *)name) {
3827 /* op_data->op_name must be freed after use */
3828 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3832 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3833 * are LUSTRE_OPC_ANY
3835 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3836 op_data->op_code = LUSTRE_OPC_ANY;
3838 op_data->op_code = opc;
3839 op_data->op_name = fname.disk_name.name;
3840 op_data->op_namelen = fname.disk_name.len;
3841 op_data->op_mode = mode;
3842 op_data->op_mod_time = ktime_get_real_seconds();
3843 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3844 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3845 op_data->op_cap = current_cap();
3846 op_data->op_mds = 0;
3847 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3848 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3849 op_data->op_bias |= MDS_CREATE_VOLATILE;
3851 op_data->op_data = data;
3856 void ll_finish_md_op_data(struct md_op_data *op_data)
3858 ll_unlock_md_op_lsm(op_data);
3859 ll_security_release_secctx(op_data->op_file_secctx,
3860 op_data->op_file_secctx_size,
3861 op_data->op_file_secctx_slot);
3862 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3863 /* allocated via ll_setup_filename called
3864 * from ll_prep_md_op_data
3866 kfree(op_data->op_name);
3867 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3868 OBD_FREE_PTR(op_data);
3871 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3873 struct ll_sb_info *sbi;
3876 LASSERT(seq && dentry);
3877 sbi = ll_s2sbi(dentry->d_sb);
3879 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3880 seq_puts(seq, "nolock");
3882 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3883 /* match_table in some cases has patterns for both enabled and
3884 * disabled cases. Ignore 'no'xxx versions if bit is set.
3886 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3887 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3888 if (ll_sbi_flags_name[i].token ==
3889 LL_SBI_FOREIGN_SYMLINK) {
3890 seq_show_option(seq, "foreign_symlink",
3891 sbi->ll_foreign_symlink_prefix);
3893 seq_printf(seq, ",%s",
3894 ll_sbi_flags_name[i].pattern);
3897 /* You can have either localflock or flock but not
3898 * both. If localflock is set don't print flock or
3901 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3903 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3904 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3905 seq_printf(seq, ",%s",
3906 ll_sbi_flags_name[i].pattern);
3910 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3916 * Get obd name by cmd, and copy out to user space
3918 int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg)
3920 struct ll_sb_info *sbi = ll_i2sbi(inode);
3921 struct obd_device *obd;
3924 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3925 obd = class_exp2obd(sbi->ll_dt_exp);
3926 else if (cmd == OBD_IOC_GETMDNAME)
3927 obd = class_exp2obd(sbi->ll_md_exp);
3934 if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1))
3941 struct work_struct db_work;
3942 struct dentry *db_dentry;
3943 /* Let's hope the path is not too long, 32 bytes for the work struct
3946 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3949 static void ll_dput_later(struct work_struct *work)
3951 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3953 dput(db->db_dentry);
3954 free_page((unsigned long)db);
3957 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3964 p.mnt = current->fs->root.mnt;
3966 path = d_path(&p, buf, bufsize);
3971 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3973 struct dname_buf *db;
3975 struct dentry *dentry = NULL;
3977 /* this can be called inside spin lock so use GFP_ATOMIC. */
3978 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3981 dentry = d_find_alias(inode);
3983 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3986 /* The below message is checked in recovery-small.sh test_24b */
3988 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3989 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3990 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3991 PFID(ll_inode2fid(inode)),
3992 (path && !IS_ERR(path)) ? path : "", ioret);
3994 if (dentry != NULL) {
3995 /* We cannot dput here since if we happen to be the last holder
3996 * then we can end up waiting for page evictions that
3997 * in turn wait for RPCs that need this instance of ptlrpcd
3998 * (callng brw_interpret->*page_completion*->vmpage_error->here)
4001 INIT_WORK(&db->db_work, ll_dput_later);
4002 db->db_dentry = dentry;
4003 schedule_work(&db->db_work);
4006 free_page((unsigned long)db);
4010 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
4011 struct lov_user_md **kbuf)
4013 struct lov_user_md lum;
4017 if (copy_from_user(&lum, md, sizeof(lum)))
4020 lum_size = ll_lov_user_md_size(&lum);
4024 OBD_ALLOC_LARGE(*kbuf, lum_size);
4028 if (copy_from_user(*kbuf, md, lum_size) != 0) {
4029 OBD_FREE_LARGE(*kbuf, lum_size);
4037 * Compute llite root squash state after a change of root squash
4038 * configuration setting or add/remove of a lnet nid
4040 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
4042 struct root_squash_info *squash = &sbi->ll_squash;
4045 struct lnet_processid id;
4047 /* Update norootsquash flag */
4048 spin_lock(&squash->rsi_lock);
4049 if (list_empty(&squash->rsi_nosquash_nids))
4050 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4052 /* Do not apply root squash as soon as one of our NIDs is
4053 * in the nosquash_nids list */
4056 while (LNetGetId(i++, &id, false) != -ENOENT) {
4057 if (nid_is_lo0(&id.nid))
4059 if (cfs_match_nid(&id.nid,
4060 &squash->rsi_nosquash_nids)) {
4066 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4068 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4070 spin_unlock(&squash->rsi_lock);
4074 * Parse linkea content to extract information about a given hardlink
4076 * \param[in] ldata - Initialized linkea data
4077 * \param[in] linkno - Link identifier
4078 * \param[out] parent_fid - The entry's parent FID
4079 * \param[out] ln - Entry name destination buffer
4081 * \retval 0 on success
4082 * \retval Appropriate negative error code on failure
4084 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
4085 struct lu_fid *parent_fid, struct lu_name *ln)
4091 rc = linkea_init_with_rec(ldata);
4095 if (linkno >= ldata->ld_leh->leh_reccount)
4096 /* beyond last link */
4099 linkea_first_entry(ldata);
4100 for (idx = 0; ldata->ld_lee != NULL; idx++) {
4101 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
4106 linkea_next_entry(ldata);
4116 * Get parent FID and name of an identified link. Operation is performed for
4117 * a given link number, letting the caller iterate over linkno to list one or
4118 * all links of an entry.
4120 * \param[in] file - File descriptor against which to perform the operation
4121 * \param[in,out] arg - User-filled structure containing the linkno to operate
4122 * on and the available size. It is eventually filled with
4123 * the requested information or left untouched on error
4125 * \retval - 0 on success
4126 * \retval - Appropriate negative error code on failure
4128 int ll_getparent(struct file *file, struct getparent __user *arg)
4130 struct inode *inode = file_inode(file);
4131 struct linkea_data *ldata;
4132 struct lu_buf buf = LU_BUF_NULL;
4134 struct lu_fid parent_fid;
4141 if (!capable(CAP_DAC_READ_SEARCH) &&
4142 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
4145 if (get_user(name_size, &arg->gp_name_size))
4148 if (get_user(linkno, &arg->gp_linkno))
4151 if (name_size > PATH_MAX)
4154 OBD_ALLOC(ldata, sizeof(*ldata));
4158 rc = linkea_data_new(ldata, &buf);
4160 GOTO(ldata_free, rc);
4162 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
4163 buf.lb_len, OBD_MD_FLXATTR);
4167 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
4171 if (ln.ln_namelen >= name_size)
4172 GOTO(lb_free, rc = -EOVERFLOW);
4174 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
4175 GOTO(lb_free, rc = -EFAULT);
4177 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
4178 GOTO(lb_free, rc = -EFAULT);
4180 if (put_user('\0', arg->gp_name + ln.ln_namelen))
4181 GOTO(lb_free, rc = -EFAULT);
4186 OBD_FREE(ldata, sizeof(*ldata));