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_REQ_MAX_DEF;
187 sbi->ll_sa_min = LL_SA_REQ_MIN_DEF;
188 sbi->ll_sa_timeout = LL_SA_TIMEOUT_DEF;
189 atomic_set(&sbi->ll_sa_total, 0);
190 atomic_set(&sbi->ll_sa_wrong, 0);
191 atomic_set(&sbi->ll_sa_running, 0);
192 atomic_set(&sbi->ll_agl_total, 0);
193 atomic_set(&sbi->ll_sa_hit_total, 0);
194 atomic_set(&sbi->ll_sa_miss_total, 0);
195 atomic_set(&sbi->ll_sa_list_total, 0);
196 atomic_set(&sbi->ll_sa_fname_total, 0);
197 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
198 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
199 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
200 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
201 set_bit(LL_SBI_UNALIGNED_DIO, sbi->ll_flags);
202 set_bit(LL_SBI_STATFS_PROJECT, sbi->ll_flags);
203 ll_sbi_set_encrypt(sbi, true);
204 ll_sbi_set_name_encrypt(sbi, true);
207 sbi->ll_squash.rsi_uid = 0;
208 sbi->ll_squash.rsi_gid = 0;
209 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
210 spin_lock_init(&sbi->ll_squash.rsi_lock);
212 /* Per-filesystem file heat */
213 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
214 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
216 /* Per-fs open heat level before requesting open lock */
217 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
218 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
219 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
222 if (sbi->ll_foreign_symlink_prefix)
223 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
225 cl_cache_decref(sbi->ll_cache);
226 sbi->ll_cache = NULL;
228 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
230 pcc_super_fini(&sbi->ll_pcc_super);
236 static void ll_free_sbi(struct super_block *sb)
238 struct ll_sb_info *sbi = ll_s2sbi(sb);
242 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
243 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
244 if (sbi->ll_ra_info.ll_readahead_wq)
245 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
246 if (sbi->ll_cache != NULL) {
247 cl_cache_decref(sbi->ll_cache);
248 sbi->ll_cache = NULL;
250 if (sbi->ll_foreign_symlink_prefix) {
251 OBD_FREE(sbi->ll_foreign_symlink_prefix,
252 sbi->ll_foreign_symlink_prefix_size);
253 sbi->ll_foreign_symlink_prefix = NULL;
255 if (sbi->ll_foreign_symlink_upcall) {
256 OBD_FREE(sbi->ll_foreign_symlink_upcall,
257 strlen(sbi->ll_foreign_symlink_upcall) +
259 sbi->ll_foreign_symlink_upcall = NULL;
261 if (sbi->ll_foreign_symlink_upcall_items) {
263 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
264 struct ll_foreign_symlink_upcall_item *items =
265 sbi->ll_foreign_symlink_upcall_items;
267 for (i = 0 ; i < nb_items; i++)
268 if (items[i].type == STRING_TYPE)
269 OBD_FREE(items[i].string,
272 OBD_FREE_LARGE(items, nb_items *
273 sizeof(struct ll_foreign_symlink_upcall_item));
274 sbi->ll_foreign_symlink_upcall_items = NULL;
276 if (sbi->ll_secctx_name)
277 ll_secctx_name_free(sbi);
279 ll_free_rw_stats_info(sbi);
280 pcc_super_fini(&sbi->ll_pcc_super);
281 OBD_FREE(sbi, sizeof(*sbi));
286 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
288 struct inode *root = NULL;
289 struct ll_sb_info *sbi = ll_s2sbi(sb);
290 struct obd_statfs *osfs = NULL;
291 struct ptlrpc_request *request = NULL;
292 struct obd_connect_data *data = NULL;
293 struct obd_uuid *uuid;
294 struct md_op_data *op_data;
295 struct lustre_md lmd;
297 int size, err, checksum;
303 sbi->ll_md_obd = class_name2obd(md);
304 if (!sbi->ll_md_obd) {
305 CERROR("MD %s: not setup or attached\n", md);
319 /* pass client page size via ocd_grant_blkbits, the server should report
320 * back its backend blocksize for grant calculation purpose */
321 data->ocd_grant_blkbits = PAGE_SHIFT;
323 /* indicate MDT features supported by this client */
324 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
325 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
326 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
327 OBD_CONNECT_SRVLOCK |
328 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
329 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
330 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
331 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
332 OBD_CONNECT_64BITHASH |
333 OBD_CONNECT_EINPROGRESS |
334 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
335 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
336 OBD_CONNECT_MAX_EASIZE |
337 OBD_CONNECT_FLOCK_DEAD |
338 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
339 OBD_CONNECT_OPEN_BY_FID |
340 OBD_CONNECT_DIR_STRIPE |
341 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
342 OBD_CONNECT_SUBTREE |
343 OBD_CONNECT_MULTIMODRPCS |
344 OBD_CONNECT_GRANT_PARAM |
345 OBD_CONNECT_GRANT_SHRINK |
346 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
348 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
349 OBD_CONNECT2_SUM_STATFS |
350 OBD_CONNECT2_OVERSTRIPING |
352 OBD_CONNECT2_LOCK_CONVERT |
353 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
354 OBD_CONNECT2_INC_XID |
356 OBD_CONNECT2_ASYNC_DISCARD |
358 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
359 OBD_CONNECT2_GETATTR_PFID |
360 OBD_CONNECT2_DOM_LVB |
361 OBD_CONNECT2_REP_MBITS |
362 OBD_CONNECT2_ATOMIC_OPEN_LOCK |
363 OBD_CONNECT2_BATCH_RPC |
364 OBD_CONNECT2_DMV_IMP_INHERIT |
365 OBD_CONNECT2_UNALIGNED_DIO;
367 #ifdef HAVE_LRU_RESIZE_SUPPORT
368 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
369 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
371 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
373 data->ocd_cksum_types = obd_cksum_types_supported_client();
375 if (CFS_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
376 /* flag mdc connection as lightweight, only used for test
377 * purpose, use with care */
378 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
380 data->ocd_ibits_known = MDS_INODELOCK_FULL;
381 data->ocd_version = LUSTRE_VERSION_CODE;
383 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
384 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
387 /* Setting this indicates we correctly support S_NOSEC (See kernel
388 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
390 sb->s_flags |= SB_NOSEC;
392 sbi->ll_fop = ll_select_file_operations(sbi);
394 /* always ping even if server suppress_pings */
395 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
396 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
398 obd_connect_set_secctx(data);
399 if (ll_sbi_has_encrypt(sbi)) {
400 obd_connect_set_enc_fid2path(data);
401 obd_connect_set_name_enc(data);
402 obd_connect_set_enc(data);
405 #if defined(CONFIG_SECURITY)
406 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
409 data->ocd_brw_size = MD_MAX_BRW_SIZE;
412 if (sb->s_flags & SB_RDONLY)
413 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
414 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
415 &sbi->ll_sb_uuid, data, sbi->ll_cache);
417 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
418 "recovery, of which this client is not a "
419 "part. Please wait for recovery to complete,"
420 " abort, or time out.\n", md);
423 CERROR("cannot connect to %s: rc = %d\n", md, err);
427 sbi->ll_md_exp->exp_connect_data = *data;
429 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
430 LUSTRE_SEQ_METADATA);
432 CERROR("%s: Can't init metadata layer FID infrastructure, "
433 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
437 /* For mount, we only need fs info from MDT0, and also in DNE, it
438 * can make sure the client can be mounted as long as MDT0 is
440 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
441 ktime_get_seconds() - sbi->ll_statfs_max_age,
442 OBD_STATFS_FOR_MDT0);
443 if (err == -EROFS && !(sb->s_flags & SB_RDONLY)) {
444 /* We got -EROFS from the server, maybe it is imposing
445 * read-only mount. So just retry like this.
447 cfs_tty_write_msg("Forcing read-only mount.\n\r");
448 CERROR("%s: mount failed with %d, forcing read-only mount.\n",
449 sbi->ll_md_exp->exp_obd->obd_name, err);
450 sb->s_flags |= SB_RDONLY;
451 obd_fid_fini(sbi->ll_md_exp->exp_obd);
452 obd_disconnect(sbi->ll_md_exp);
453 GOTO(retry_connect, err);
455 GOTO(out_md_fid, err);
458 /* This needs to be after statfs to ensure connect has finished.
459 * Note that "data" does NOT contain the valid connect reply.
460 * If connecting to a 1.8 server there will be no LMV device, so
461 * we can access the MDC export directly and exp_connect_flags will
462 * be non-zero, but if accessing an upgraded 2.1 server it will
463 * have the correct flags filled in.
464 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
465 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
466 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
467 valid != CLIENT_CONNECT_MDT_REQD) {
470 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
471 obd_connect_flags2str(buf, PAGE_SIZE,
472 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
473 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
474 "feature(s) needed for correct operation "
475 "of this client (%s). Please upgrade "
476 "server or downgrade client.\n",
477 sbi->ll_md_exp->exp_obd->obd_name, buf);
478 OBD_FREE(buf, PAGE_SIZE);
479 GOTO(out_md_fid, err = -EPROTO);
482 size = sizeof(*data);
483 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
484 KEY_CONN_DATA, &size, data);
486 CERROR("%s: Get connect data failed: rc = %d\n",
487 sbi->ll_md_exp->exp_obd->obd_name, err);
488 GOTO(out_md_fid, err);
491 LASSERT(osfs->os_bsize);
492 sb->s_blocksize = osfs->os_bsize;
493 sb->s_blocksize_bits = log2(osfs->os_bsize);
494 sb->s_magic = LL_SUPER_MAGIC;
495 sb->s_maxbytes = MAX_LFS_FILESIZE;
496 sbi->ll_inode_cache_enabled = 1;
497 sbi->ll_namelen = osfs->os_namelen;
498 sbi->ll_mnt.mnt = current->fs->root.mnt;
499 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
501 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
502 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
503 LCONSOLE_INFO("Disabling user_xattr feature because "
504 "it is not supported on the server\n");
505 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
508 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
510 sb->s_flags |= SB_POSIXACL;
512 set_bit(LL_SBI_ACL, sbi->ll_flags);
514 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
516 sb->s_flags &= ~SB_POSIXACL;
518 clear_bit(LL_SBI_ACL, sbi->ll_flags);
521 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
522 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
524 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
525 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
527 if (obd_connect_has_secctx(data))
528 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
530 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
531 if (ll_sb_has_test_dummy_encryption(sb))
532 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
534 sbi->ll_md_exp->exp_obd->obd_name);
535 ll_sbi_set_encrypt(sbi, false);
538 if (ll_sbi_has_name_encrypt(sbi) && !obd_connect_has_name_enc(data)) {
539 struct lustre_sb_info *lsi = s2lsi(sb);
541 if (ll_sb_has_test_dummy_encryption(sb))
542 LCONSOLE_WARN("%s: server %s does not support name encryption, not using it.\n",
544 sbi->ll_md_exp->exp_obd->obd_name);
545 #ifdef CONFIG_LL_ENCRYPTION
546 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
548 lsi->lsi_flags &= ~LSI_FILENAME_ENC_B64_OLD_CLI;
549 ll_sbi_set_name_encrypt(sbi, false);
552 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
553 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
554 LCONSOLE_INFO("%s: disabling xattr cache due to "
555 "unknown maximum xattr size.\n", dt);
556 } else if (!sbi->ll_xattr_cache_set) {
557 /* If xattr_cache is already set (no matter 0 or 1)
558 * during processing llog, it won't be enabled here. */
559 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
560 sbi->ll_xattr_cache_enabled = 1;
564 sbi->ll_dt_obd = class_name2obd(dt);
565 if (!sbi->ll_dt_obd) {
566 CERROR("DT %s: not setup or attached\n", dt);
567 GOTO(out_md_fid, err = -ENODEV);
570 /* pass client page size via ocd_grant_blkbits, the server should report
571 * back its backend blocksize for grant calculation purpose */
572 data->ocd_grant_blkbits = PAGE_SHIFT;
574 /* indicate OST features supported by this client */
575 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
576 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
577 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
578 OBD_CONNECT_SRVLOCK |
579 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
580 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
581 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
582 OBD_CONNECT_EINPROGRESS |
583 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
584 OBD_CONNECT_LAYOUTLOCK |
585 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
586 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
587 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
588 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
589 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
590 OBD_CONNECT2_REP_MBITS |
591 OBD_CONNECT2_UNALIGNED_DIO;
593 if (!CFS_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
594 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
596 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
597 * disabled by default, because it can still be enabled on the
598 * fly via /sys. As a consequence, we still need to come to an
599 * agreement on the supported algorithms at connect time
601 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
603 if (CFS_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
604 data->ocd_cksum_types = OBD_CKSUM_ADLER;
606 data->ocd_cksum_types = obd_cksum_types_supported_client();
608 #ifdef HAVE_LRU_RESIZE_SUPPORT
609 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
611 /* always ping even if server suppress_pings */
612 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
613 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
615 if (ll_sbi_has_encrypt(sbi))
616 obd_connect_set_enc(data);
618 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
619 "ocd_grant: %d\n", data->ocd_connect_flags,
620 data->ocd_version, data->ocd_grant);
622 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
623 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
625 data->ocd_brw_size = DT_MAX_BRW_SIZE;
627 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
628 &sbi->ll_sb_uuid, data, sbi->ll_cache);
630 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
631 "recovery, of which this client is not a "
632 "part. Please wait for recovery to "
633 "complete, abort, or time out.\n", dt);
636 CERROR("%s: Cannot connect to %s: rc = %d\n",
637 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
641 if (ll_sbi_has_encrypt(sbi) &&
642 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
643 if (ll_sb_has_test_dummy_encryption(sb))
644 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
646 ll_sbi_set_encrypt(sbi, false);
647 } else if (ll_sb_has_test_dummy_encryption(sb)) {
648 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
651 sbi->ll_dt_exp->exp_connect_data = *data;
653 /* Don't change value if it was specified in the config log */
654 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
655 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
656 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
657 (data->ocd_brw_size >> PAGE_SHIFT));
658 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
659 sbi->ll_ra_info.ra_max_pages_per_file)
660 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
661 sbi->ll_ra_info.ra_max_pages_per_file;
664 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
665 LUSTRE_SEQ_METADATA);
667 CERROR("%s: Can't init data layer FID infrastructure, "
668 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
672 mutex_lock(&sbi->ll_lco.lco_lock);
673 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
674 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
675 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
676 mutex_unlock(&sbi->ll_lco.lco_lock);
678 fid_zero(&sbi->ll_root_fid);
679 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
682 CERROR("cannot mds_connect: rc = %d\n", err);
683 GOTO(out_lock_cn_cb, err);
685 if (!fid_is_sane(&sbi->ll_root_fid)) {
686 CERROR("%s: Invalid root fid "DFID" during mount\n",
687 sbi->ll_md_exp->exp_obd->obd_name,
688 PFID(&sbi->ll_root_fid));
689 GOTO(out_lock_cn_cb, err = -EINVAL);
691 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
693 sb->s_op = &lustre_super_operations;
694 sb->s_xattr = ll_xattr_handlers;
695 #if THREAD_SIZE >= 8192 /*b=17630*/
696 sb->s_export_op = &lustre_export_operations;
698 #ifdef HAVE_LUSTRE_CRYPTO
699 llcrypt_set_ops(sb, &lustre_cryptops);
703 * XXX: move this to after cbd setup? */
704 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
706 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
707 valid |= OBD_MD_FLACL;
709 OBD_ALLOC_PTR(op_data);
711 GOTO(out_lock_cn_cb, err = -ENOMEM);
713 op_data->op_fid1 = sbi->ll_root_fid;
714 op_data->op_mode = 0;
715 op_data->op_valid = valid;
717 err = md_getattr(sbi->ll_md_exp, op_data, &request);
719 /* We need enc ctx info, so reset it in op_data to
720 * prevent it from being freed.
722 encctx = op_data->op_file_encctx;
723 encctxlen = op_data->op_file_encctx_size;
724 op_data->op_file_encctx = NULL;
725 op_data->op_file_encctx_size = 0;
726 OBD_FREE_PTR(op_data);
728 CERROR("%s: md_getattr failed for root: rc = %d\n",
729 sbi->ll_md_exp->exp_obd->obd_name, err);
730 GOTO(out_lock_cn_cb, err);
733 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
734 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
736 CERROR("failed to understand root inode md: rc = %d\n", err);
737 ptlrpc_req_finished(request);
738 GOTO(out_lock_cn_cb, err);
741 LASSERT(fid_is_sane(&sbi->ll_root_fid));
742 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
743 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
744 md_put_lustre_md(sbi->ll_md_exp, &lmd);
748 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
750 CERROR("%s: bad ll_iget() for root: rc = %d\n",
751 sbi->ll_fsname, err);
752 ptlrpc_req_finished(request);
756 err = ll_secctx_name_store(root);
757 if (err < 0 && ll_security_xattr_wanted(root))
758 CWARN("%s: file security contextes not supported: rc = %d\n",
759 sbi->ll_fsname, err);
764 "server returned encryption ctx for root inode "DFID"\n",
765 PFID(&sbi->ll_root_fid));
766 err = ll_set_encflags(root, encctx, encctxlen, true);
768 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
770 PFID(&sbi->ll_root_fid), err);
772 ptlrpc_req_finished(request);
774 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
775 if (sbi->ll_checksum_set) {
776 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
777 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
778 sizeof(checksum), &checksum, NULL);
780 CERROR("%s: Set checksum failed: rc = %d\n",
781 sbi->ll_dt_exp->exp_obd->obd_name, err);
787 sb->s_root = d_make_root(root);
788 if (sb->s_root == NULL) {
790 CERROR("%s: can't make root dentry: rc = %d\n",
791 sbi->ll_fsname, err);
795 sbi->ll_sdev_orig = sb->s_dev;
797 /* We set sb->s_dev equal on all lustre clients in order to support
798 * NFS export clustering. NFSD requires that the FSID be the same
800 /* s_dev is also used in lt_compare() to compare two fs, but that is
801 * only a node-local comparison. */
802 uuid = obd_get_uuid(sbi->ll_md_exp);
804 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
811 if (sbi->ll_dt_obd) {
812 err = sysfs_create_link(&sbi->ll_kset.kobj,
813 &sbi->ll_dt_obd->obd_kset.kobj,
814 sbi->ll_dt_obd->obd_type->typ_name);
816 CERROR("%s: could not register %s in llite: rc = %d\n",
817 dt, sbi->ll_fsname, err);
822 if (sbi->ll_md_obd) {
823 err = sysfs_create_link(&sbi->ll_kset.kobj,
824 &sbi->ll_md_obd->obd_kset.kobj,
825 sbi->ll_md_obd->obd_type->typ_name);
827 CERROR("%s: could not register %s in llite: rc = %d\n",
828 md, sbi->ll_fsname, err);
837 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
839 obd_disconnect(sbi->ll_dt_exp);
840 sbi->ll_dt_exp = NULL;
841 sbi->ll_dt_obd = NULL;
843 obd_fid_fini(sbi->ll_md_exp->exp_obd);
845 obd_disconnect(sbi->ll_md_exp);
846 sbi->ll_md_exp = NULL;
847 sbi->ll_md_obd = NULL;
856 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
860 size = sizeof(*lmmsize);
861 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
862 KEY_MAX_EASIZE, &size, lmmsize);
864 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
865 sbi->ll_dt_exp->exp_obd->obd_name, rc);
869 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
872 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
873 KEY_MAX_EASIZE, &size, lmmsize);
875 CERROR("Get max mdsize error rc %d\n", rc);
877 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
883 * Get the value of the default_easize parameter.
885 * \see client_obd::cl_default_mds_easize
887 * \param[in] sbi superblock info for this filesystem
888 * \param[out] lmmsize pointer to storage location for value
890 * \retval 0 on success
891 * \retval negative negated errno on failure
893 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
898 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
899 KEY_DEFAULT_EASIZE, &size, lmmsize);
901 CERROR("Get default mdsize error rc %d\n", rc);
907 * Set the default_easize parameter to the given value.
909 * \see client_obd::cl_default_mds_easize
911 * \param[in] sbi superblock info for this filesystem
912 * \param[in] lmmsize the size to set
914 * \retval 0 on success
915 * \retval negative negated errno on failure
917 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
921 if (lmmsize < sizeof(struct lov_mds_md) ||
922 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
925 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
926 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
927 sizeof(int), &lmmsize, NULL);
932 static void client_common_put_super(struct super_block *sb)
934 struct ll_sb_info *sbi = ll_s2sbi(sb);
939 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
940 obd_disconnect(sbi->ll_dt_exp);
941 sbi->ll_dt_exp = NULL;
943 ll_debugfs_unregister_super(sb);
945 obd_fid_fini(sbi->ll_md_exp->exp_obd);
946 obd_disconnect(sbi->ll_md_exp);
947 sbi->ll_md_exp = NULL;
952 void ll_kill_super(struct super_block *sb)
954 struct ll_sb_info *sbi;
958 if (!(sb->s_flags & SB_ACTIVE))
962 /* we need restore s_dev from changed for clustred NFS before put_super
963 * because new kernels have cached s_dev and change sb->s_dev in
964 * put_super not affected real removing devices */
966 sb->s_dev = sbi->ll_sdev_orig;
968 /* wait running statahead threads to quit */
969 while (atomic_read(&sbi->ll_sa_running) > 0)
970 schedule_timeout_uninterruptible(
971 cfs_time_seconds(1) >> 3);
977 /* Since we use this table for ll_sbi_flags_seq_show make
978 * sure what you want displayed for a specific token that
979 * is listed more than once below be listed first. For
980 * example we want "checksum" displayed, not "nochecksum"
983 static const match_table_t ll_sbi_flags_name = {
984 {LL_SBI_NOLCK, "nolock"},
985 {LL_SBI_CHECKSUM, "checksum"},
986 {LL_SBI_CHECKSUM, "nochecksum"},
987 {LL_SBI_LOCALFLOCK, "localflock"},
988 {LL_SBI_FLOCK, "flock"},
989 {LL_SBI_FLOCK, "noflock"},
990 {LL_SBI_USER_XATTR, "user_xattr"},
991 {LL_SBI_USER_XATTR, "nouser_xattr"},
992 {LL_SBI_LRU_RESIZE, "lruresize"},
993 {LL_SBI_LRU_RESIZE, "nolruresize"},
994 {LL_SBI_LAZYSTATFS, "lazystatfs"},
995 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
996 {LL_SBI_32BIT_API, "32bitapi"},
997 {LL_SBI_USER_FID2PATH, "user_fid2path"},
998 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
999 {LL_SBI_VERBOSE, "verbose"},
1000 {LL_SBI_VERBOSE, "noverbose"},
1001 {LL_SBI_ALWAYS_PING, "always_ping"},
1002 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
1003 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
1004 {LL_SBI_ENCRYPT, "encrypt"},
1005 {LL_SBI_ENCRYPT, "noencrypt"},
1006 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
1007 {LL_SBI_STATFS_PROJECT, "statfs_project"},
1008 {LL_SBI_STATFS_PROJECT, "nostatfs_project"},
1009 {LL_SBI_NUM_MOUNT_OPT, NULL},
1011 {LL_SBI_ACL, "acl"},
1012 {LL_SBI_AGL_ENABLED, "agl"},
1013 {LL_SBI_64BIT_HASH, "64bit_hash"},
1014 {LL_SBI_LAYOUT_LOCK, "layout"},
1015 {LL_SBI_XATTR_CACHE, "xattr_cache"},
1016 {LL_SBI_NOROOTSQUASH, "norootsquash"},
1017 {LL_SBI_FAST_READ, "fast_read"},
1018 {LL_SBI_FILE_SECCTX, "file_secctx"},
1019 {LL_SBI_TINY_WRITE, "tiny_write"},
1020 {LL_SBI_FILE_HEAT, "file_heat"},
1021 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
1022 {LL_SBI_ENCRYPT_NAME, "name_encrypt"},
1023 {LL_SBI_UNALIGNED_DIO, "unaligned_dio"},
1026 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
1028 struct super_block *sb = m->private;
1031 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
1034 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
1037 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
1038 if (ll_sbi_flags_name[j].token == i &&
1039 ll_sbi_flags_name[j].pattern) {
1040 seq_printf(m, "%s ",
1041 ll_sbi_flags_name[j].pattern);
1046 seq_puts(m, "\b\n");
1050 /* non-client-specific mount options are parsed in lmd_parse */
1051 static int ll_options(char *options, struct super_block *sb)
1053 struct ll_sb_info *sbi = ll_s2sbi(sb);
1054 char *s2, *s1, *opts;
1061 /* Don't stomp on lmd_opts */
1062 opts = kstrdup(options, GFP_KERNEL);
1068 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1070 while ((s1 = strsep(&opts, ",")) != NULL) {
1071 substring_t args[MAX_OPT_ARGS];
1072 bool turn_off = false;
1078 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1080 if (strncmp(s1, "no", 2) == 0)
1084 * Initialize args struct so we know whether arg was
1085 * found; some options take optional arguments.
1088 args[0].from = NULL;
1089 token = match_token(s1, ll_sbi_flags_name, args);
1090 if (token == LL_SBI_NUM_MOUNT_OPT) {
1091 if (match_wildcard("context", s1) ||
1092 match_wildcard("fscontext", s1) ||
1093 match_wildcard("defcontext", s1) ||
1094 match_wildcard("rootcontext",s1))
1097 LCONSOLE_ERROR_MSG(0x152,
1098 "Unknown option '%s', won't mount.\n",
1105 case LL_SBI_32BIT_API:
1106 case LL_SBI_64BIT_HASH:
1107 case LL_SBI_ALWAYS_PING:
1108 set_bit(token, sbi->ll_flags);
1112 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1114 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1116 set_bit(token, sbi->ll_flags);
1119 case LL_SBI_LOCALFLOCK:
1120 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1121 set_bit(token, sbi->ll_flags);
1124 case LL_SBI_CHECKSUM:
1125 sbi->ll_checksum_set = 1;
1127 case LL_SBI_USER_XATTR:
1128 case LL_SBI_USER_FID2PATH:
1129 case LL_SBI_LRU_RESIZE:
1130 case LL_SBI_LAZYSTATFS:
1131 case LL_SBI_VERBOSE:
1132 case LL_SBI_STATFS_PROJECT:
1134 clear_bit(token, sbi->ll_flags);
1136 set_bit(token, sbi->ll_flags);
1138 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1139 #ifdef HAVE_LUSTRE_CRYPTO
1140 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1141 set_bit(token, sbi->ll_flags);
1143 struct lustre_sb_info *lsi = s2lsi(sb);
1145 err = llcrypt_set_test_dummy_encryption(sb,
1146 #ifdef HAVE_FSCRYPT_SET_TEST_DUMMY_ENC_CHAR_ARG
1151 &lsi->lsi_dummy_enc_policy);
1157 "Can't change test_dummy_encryption");
1158 else if (err == -EINVAL)
1160 "Value of option \"%s\" unrecognized",
1164 "Error processing option \"%s\" [%d]",
1169 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1173 case LL_SBI_ENCRYPT:
1174 #ifdef HAVE_LUSTRE_CRYPTO
1176 clear_bit(token, sbi->ll_flags);
1178 set_bit(token, sbi->ll_flags);
1180 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1183 case LL_SBI_FOREIGN_SYMLINK:
1184 /* non-default prefix provided ? */
1189 /* path must be absolute */
1190 if (args->from[0] != '/') {
1191 LCONSOLE_ERROR_MSG(0x152,
1192 "foreign prefix '%s' must be an absolute path\n",
1197 old_len = sbi->ll_foreign_symlink_prefix_size;
1198 old = sbi->ll_foreign_symlink_prefix;
1199 /* alloc for path length and '\0' */
1200 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1201 if (!sbi->ll_foreign_symlink_prefix) {
1202 /* restore previous */
1203 sbi->ll_foreign_symlink_prefix = old;
1204 sbi->ll_foreign_symlink_prefix_size =
1208 sbi->ll_foreign_symlink_prefix_size =
1209 args->to - args->from + 1;
1210 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1211 sbi->ll_foreign_symlink_prefix_size,
1214 OBD_FREE(old, old_len);
1216 /* enable foreign symlink support */
1217 set_bit(token, sbi->ll_flags);
1219 LCONSOLE_ERROR_MSG(0x152,
1220 "invalid %s option\n", s1);
1231 void ll_lli_init(struct ll_inode_info *lli)
1233 lli->lli_inode_magic = LLI_INODE_MAGIC;
1235 rwlock_init(&lli->lli_lock);
1236 lli->lli_posix_acl = NULL;
1237 /* Do not set lli_fid, it has been initialized already. */
1238 fid_zero(&lli->lli_pfid);
1239 lli->lli_mds_read_och = NULL;
1240 lli->lli_mds_write_och = NULL;
1241 lli->lli_mds_exec_och = NULL;
1242 lli->lli_open_fd_read_count = 0;
1243 lli->lli_open_fd_write_count = 0;
1244 lli->lli_open_fd_exec_count = 0;
1245 mutex_init(&lli->lli_och_mutex);
1246 spin_lock_init(&lli->lli_agl_lock);
1247 spin_lock_init(&lli->lli_layout_lock);
1248 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1249 lli->lli_clob = NULL;
1251 init_rwsem(&lli->lli_xattrs_list_rwsem);
1252 mutex_init(&lli->lli_xattrs_enq_lock);
1254 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1255 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1256 lli->lli_opendir_key = NULL;
1257 lli->lli_sai = NULL;
1258 spin_lock_init(&lli->lli_sa_lock);
1259 lli->lli_opendir_pid = 0;
1260 lli->lli_sa_enabled = 0;
1261 init_rwsem(&lli->lli_lsm_sem);
1263 mutex_init(&lli->lli_size_mutex);
1264 mutex_init(&lli->lli_setattr_mutex);
1265 lli->lli_symlink_name = NULL;
1266 ll_trunc_sem_init(&lli->lli_trunc_sem);
1267 range_lock_tree_init(&lli->lli_write_tree);
1268 init_rwsem(&lli->lli_glimpse_sem);
1269 lli->lli_glimpse_time = ktime_set(0, 0);
1270 INIT_LIST_HEAD(&lli->lli_agl_list);
1271 lli->lli_agl_index = 0;
1272 lli->lli_async_rc = 0;
1273 spin_lock_init(&lli->lli_heat_lock);
1274 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1275 lli->lli_heat_flags = 0;
1276 mutex_init(&lli->lli_pcc_lock);
1277 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1278 lli->lli_pcc_inode = NULL;
1279 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1280 lli->lli_pcc_generation = 0;
1281 mutex_init(&lli->lli_group_mutex);
1282 lli->lli_group_users = 0;
1283 lli->lli_group_gid = 0;
1284 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1285 lli->lli_uid = (__u32) -1;
1286 lli->lli_gid = (__u32) -1;
1288 mutex_init(&lli->lli_layout_mutex);
1289 lli->lli_layout_lock_owner = NULL;
1290 /* ll_cl_context initialize */
1291 INIT_LIST_HEAD(&lli->lli_lccs);
1292 seqlock_init(&lli->lli_page_inv_lock);
1293 lli->lli_inode_lock_owner = NULL;
1296 #define MAX_STRING_SIZE 128
1298 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1299 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1301 struct lustre_sb_info *lsi = s2lsi(sb);
1302 char buf[MAX_STRING_SIZE];
1306 err = bdi_init(&lsi->lsi_bdi);
1310 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1311 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1312 lsi->lsi_bdi.name = "lustre";
1313 va_start(args, fmt);
1314 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1316 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1319 sb->s_bdi = &lsi->lsi_bdi;
1323 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1325 int ll_fill_super(struct super_block *sb)
1327 struct lustre_profile *lprof = NULL;
1328 struct lustre_sb_info *lsi = s2lsi(sb);
1329 struct ll_sb_info *sbi = NULL;
1330 char *dt = NULL, *md = NULL;
1331 char *profilenm = get_profile_name(sb);
1332 struct config_llog_instance *cfg;
1333 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1334 const int instlen = LUSTRE_MAXINSTANCE + 2;
1335 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1336 char name[MAX_STRING_SIZE];
1345 /* for ASLR, to map between cfg_instance and hashed ptr */
1346 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1347 profilenm, cfg_instance, sb);
1349 CFS_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1353 GOTO(out_free_cfg, err = -ENOMEM);
1355 /* client additional sb info */
1356 lsi->lsi_llsbi = sbi = ll_init_sbi(lsi);
1358 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1360 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1362 GOTO(out_free_cfg, err);
1364 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1365 #ifdef CONFIG_LL_ENCRYPTION
1366 if (ll_sb_has_test_dummy_encryption(sb))
1367 /* enable filename encryption by default for dummy enc mode */
1368 lsi->lsi_flags |= LSI_FILENAME_ENC;
1370 /* filename encryption is disabled by default */
1371 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1374 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1375 sb->s_d_op = &ll_d_ops;
1378 generate_random_uuid(uuid.b);
1379 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1381 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1384 len = strlen(profilenm);
1385 ptr = strrchr(profilenm, '-');
1386 if (ptr && (strcmp(ptr, "-client") == 0))
1389 if (len > LUSTRE_MAXFSNAME) {
1390 if (unlikely(len >= MAX_STRING_SIZE))
1391 len = MAX_STRING_SIZE - 1;
1392 strncpy(name, profilenm, len);
1394 err = -ENAMETOOLONG;
1395 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1396 name, LUSTRE_MAXFSNAME, err);
1397 GOTO(out_free_cfg, err);
1399 strncpy(sbi->ll_fsname, profilenm, len);
1400 sbi->ll_fsname[len] = '\0';
1403 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1404 profilenm, cfg_instance);
1406 err = super_setup_bdi_name(sb, "%s", name);
1408 GOTO(out_free_cfg, err);
1410 /* disable kernel readahead */
1411 sb->s_bdi->ra_pages = 0;
1412 #ifdef HAVE_BDI_IO_PAGES
1413 sb->s_bdi->io_pages = 0;
1415 sb->s_bdi->capabilities |= LL_BDI_CAP_FLAGS;
1416 #ifdef SB_I_CGROUPWB
1417 sb->s_iflags |= SB_I_CGROUPWB;
1420 /* Call ll_debugfs_register_super() before lustre_process_log()
1421 * so that "llite.*.*" params can be processed correctly.
1423 err = ll_debugfs_register_super(sb, name);
1425 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1426 sbi->ll_fsname, err);
1430 /* The cfg_instance is a value unique to this super, in case some
1431 * joker tries to mount the same fs at two mount points.
1433 cfg->cfg_instance = cfg_instance;
1434 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1435 cfg->cfg_callback = class_config_llog_handler;
1436 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1437 /* set up client obds */
1438 err = lustre_process_log(sb, profilenm, cfg);
1440 GOTO(out_debugfs, err);
1442 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1443 lprof = class_get_profile(profilenm);
1444 if (lprof == NULL) {
1445 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1446 " read from the MGS. Does that filesystem "
1447 "exist?\n", profilenm);
1448 GOTO(out_debugfs, err = -EINVAL);
1450 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1451 lprof->lp_md, lprof->lp_dt);
1453 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1454 OBD_ALLOC(dt, dt_len);
1456 GOTO(out_profile, err = -ENOMEM);
1457 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1459 md_len = strlen(lprof->lp_md) + instlen + 2;
1460 OBD_ALLOC(md, md_len);
1462 GOTO(out_free_dt, err = -ENOMEM);
1463 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1465 /* connections, registrations, sb setup */
1466 err = client_common_fill_super(sb, md, dt);
1468 GOTO(out_free_md, err);
1470 sbi->ll_client_common_fill_super_succeeded = 1;
1474 OBD_FREE(md, md_len);
1477 OBD_FREE(dt, dt_len);
1480 class_put_profile(lprof);
1483 ll_debugfs_unregister_super(sb);
1490 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1491 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1492 sb->s_flags & SB_RDONLY ? " read-only" : "");
1494 } /* ll_fill_super */
1496 static void ll_bdi_device_unregister(struct backing_dev_info *bdi)
1498 if (bdi->dev == NULL)
1501 #if defined(SB_I_CGROUPWB) && !defined(SB_I_PERSB_BDI)
1502 #ifdef HAVE_BDI_DEBUG_STATS
1503 debugfs_remove(bdi->debug_stats);
1504 debugfs_remove(bdi->debug_dir);
1506 debugfs_remove_recursive(bdi->debug_dir);
1508 device_unregister(bdi->dev);
1513 void ll_put_super(struct super_block *sb)
1515 struct config_llog_instance cfg, params_cfg;
1516 struct obd_device *obd;
1517 struct lustre_sb_info *lsi = s2lsi(sb);
1518 struct ll_sb_info *sbi = ll_s2sbi(sb);
1519 unsigned long dev_no = 0;
1520 char *profilenm = get_profile_name(sb);
1521 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1527 GOTO(out_no_sbi, 0);
1529 /* Should replace instance_id with something better for ASLR */
1530 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1531 profilenm, cfg_instance, sb);
1533 cfg.cfg_instance = cfg_instance;
1534 lustre_end_log(sb, profilenm, &cfg);
1536 params_cfg.cfg_instance = cfg_instance;
1537 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1539 if (sbi->ll_md_exp) {
1540 obd = class_exp2obd(sbi->ll_md_exp);
1542 force = obd->obd_force;
1545 /* We need to set force before the lov_disconnect in
1546 * lustre_common_put_super, since l_d cleans up osc's as well.
1550 obd_device_for_each_uuid(dev_no, obd, &sbi->ll_sb_uuid)
1551 obd->obd_force = force;
1552 obd_device_unlock();
1555 if (sbi->ll_client_common_fill_super_succeeded) {
1556 /* Only if client_common_fill_super succeeded */
1557 client_common_put_super(sb);
1560 /* imitate failed cleanup */
1561 if (CFS_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1565 * Cleanup, detach OBD devices, and remove them from Xarray.
1566 * We don't grab the xa_lock() since class_manual_cleanup()
1567 * uses the lock internally.
1569 obd_device_for_each_uuid(dev_no, obd, &sbi->ll_sb_uuid)
1570 class_manual_cleanup(obd);
1573 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1574 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1577 class_del_profile(profilenm);
1579 ll_bdi_device_unregister(sb->s_bdi);
1581 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1582 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1583 bdi_destroy(&lsi->lsi_bdi);
1584 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1588 llcrypt_free_dummy_policy(&lsi->lsi_dummy_enc_policy);
1590 lsi->lsi_llsbi = NULL;
1592 lustre_common_put_super(sb);
1594 cl_env_cache_purge(~0);
1597 } /* client_put_super */
1599 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1601 struct inode *inode = NULL;
1603 /* NOTE: we depend on atomic igrab() -bzzz */
1604 lock_res_and_lock(lock);
1605 if (lock->l_resource->lr_lvb_inode) {
1606 struct ll_inode_info * lli;
1607 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1608 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1609 inode = igrab(lock->l_resource->lr_lvb_inode);
1611 inode = lock->l_resource->lr_lvb_inode;
1612 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1613 D_WARNING, lock, "lr_lvb_inode %p is "
1614 "bogus: magic %08x",
1615 lock->l_resource->lr_lvb_inode,
1616 lli->lli_inode_magic);
1620 unlock_res_and_lock(lock);
1624 void ll_dir_clear_lsm_md(struct inode *inode)
1626 struct ll_inode_info *lli = ll_i2info(inode);
1628 LASSERT(S_ISDIR(inode->i_mode));
1629 down_write(&lli->lli_lsm_sem);
1630 lmv_stripe_object_put(&lli->lli_lsm_obj);
1631 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1632 up_write(&lli->lli_lsm_sem);
1635 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1636 const struct lu_fid *fid,
1637 struct lustre_md *md)
1639 struct ll_sb_info *sbi = ll_s2sbi(sb);
1640 struct ll_inode_info *lli;
1641 struct mdt_body *body = md->body;
1642 struct inode *inode;
1647 LASSERT(md->lsm_obj);
1648 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1649 inode = iget_locked(sb, ino);
1650 if (inode == NULL) {
1651 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1652 sbi->ll_fsname, PFID(fid));
1653 RETURN(ERR_PTR(-ENOENT));
1656 lli = ll_i2info(inode);
1657 if (inode->i_state & I_NEW) {
1658 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1659 (body->mbo_mode & S_IFMT);
1660 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1663 inode->i_mtime.tv_sec = 0;
1664 inode->i_atime.tv_sec = 0;
1665 inode->i_ctime.tv_sec = 0;
1668 #ifdef HAVE_BACKING_DEV_INFO
1669 /* initializing backing dev info. */
1670 inode->i_mapping->backing_dev_info =
1671 &s2lsi(inode->i_sb)->lsi_bdi;
1673 inode->i_op = &ll_dir_inode_operations;
1674 inode->i_fop = &ll_dir_operations;
1675 lli->lli_fid = *fid;
1678 /* master object FID */
1679 lli->lli_pfid = body->mbo_fid1;
1680 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1681 lli, PFID(fid), PFID(&lli->lli_pfid));
1682 unlock_new_inode(inode);
1684 /* in directory restripe/auto-split, a directory will be
1685 * transformed to a stripe if it's plain, set its pfid here,
1686 * otherwise ll_lock_cancel_bits() can't find the master inode.
1688 lli->lli_pfid = body->mbo_fid1;
1694 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1697 struct lmv_stripe_md *lsm;
1698 struct ll_inode_info *lli = ll_i2info(inode);
1701 LASSERT(md->lsm_obj != NULL);
1702 lsm = &md->lsm_obj->lso_lsm;
1704 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1705 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1706 lmv_stripe_object_dump(D_INODE, md->lsm_obj);
1708 if (!lmv_dir_striped(md->lsm_obj))
1711 /* XXX sigh, this lsm_root initialization should be in
1712 * LMV layer, but it needs ll_iget right now, so we
1713 * put this here right now. */
1714 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1715 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1716 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1718 if (!fid_is_sane(fid))
1721 /* Unfortunately ll_iget will call ll_update_inode,
1722 * where the initialization of slave inode is slightly
1723 * different, so it reset lsm_md to NULL to avoid
1724 * initializing lsm for slave inode. */
1725 lsm->lsm_md_oinfo[i].lmo_root =
1726 ll_iget_anon_dir(inode->i_sb, fid, md);
1727 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1728 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1730 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1732 iput(lsm->lsm_md_oinfo[i].lmo_root);
1733 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1739 /* move lsm_obj to lli */
1740 lli->lli_lsm_obj = md->lsm_obj;
1745 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1747 struct ll_inode_info *lli = ll_i2info(inode);
1748 struct lmv_stripe_object *lsm_obj = md->def_lsm_obj;
1752 /* clear default lsm */
1753 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set) {
1754 down_write(&lli->lli_lsm_sem);
1755 if (lli->lli_def_lsm_obj_set) {
1756 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1757 lli->lli_inherit_depth = 0;
1758 lli->lli_def_lsm_obj_set = 0;
1760 up_write(&lli->lli_lsm_sem);
1765 if (lli->lli_def_lsm_obj) {
1766 /* do nonthing if default lsm isn't changed */
1767 down_read(&lli->lli_lsm_sem);
1768 if (lli->lli_def_lsm_obj &&
1769 lsm_md_eq(lli->lli_def_lsm_obj, lsm_obj)) {
1770 up_read(&lli->lli_lsm_sem);
1773 up_read(&lli->lli_lsm_sem);
1775 down_write(&lli->lli_lsm_sem);
1777 /* update default lsm. */
1778 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
1779 lli->lli_def_lsm_obj = lsm_obj;
1780 lli->lli_def_lsm_obj_set = 1;
1781 lmv_stripe_object_dump(D_INODE, lsm_obj);
1782 md->def_lsm_obj = NULL;
1783 up_write(&lli->lli_lsm_sem);
1787 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1789 struct ll_inode_info *lli = ll_i2info(inode);
1790 struct lmv_stripe_object *lsm_obj = md->lsm_obj;
1791 struct cl_attr *attr;
1796 LASSERT(S_ISDIR(inode->i_mode));
1797 CDEBUG(D_INODE, "update lsm_obj %p of "DFID"\n", lli->lli_lsm_obj,
1798 PFID(ll_inode2fid(inode)));
1800 /* update default LMV */
1801 if (md->def_lsm_obj)
1802 ll_update_default_lsm_md(inode, md);
1804 /* after dir migration/restripe, a stripe may be turned into a
1805 * directory, in this case, zero out its lli_pfid.
1807 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1808 fid_zero(&lli->lli_pfid);
1811 * no striped information from request, lustre_md from req does not
1812 * include stripeEA, see ll_md_setattr()
1818 * normally dir layout doesn't change, only take read lock to check
1819 * that to avoid blocking other MD operations.
1821 down_read(&lli->lli_lsm_sem);
1823 /* some current lookup initialized lsm, and unchanged */
1824 if (lli->lli_lsm_obj && lsm_md_eq(lli->lli_lsm_obj, lsm_obj)) {
1825 up_read(&lli->lli_lsm_sem);
1829 up_read(&lli->lli_lsm_sem);
1830 down_write(&lli->lli_lsm_sem);
1832 /* check again in case of a race */
1833 if (lli->lli_lsm_obj && lsm_md_eq(lli->lli_lsm_obj, lsm_obj))
1834 GOTO(unlock, rc = 0);
1836 /* if dir layout doesn't match, check whether version is increased,
1837 * which means layout is changed, this happens in dir split/merge and
1840 * foreign LMV should not change.
1842 if (lli->lli_lsm_obj && lmv_dir_striped(lli->lli_lsm_obj) &&
1843 lsm_obj->lso_lsm.lsm_md_layout_version <=
1844 lli->lli_lsm_obj->lso_lsm.lsm_md_layout_version) {
1845 CERROR("%s: "DFID" dir layout mismatch:\n",
1846 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1847 lmv_stripe_object_dump(D_ERROR, lli->lli_lsm_obj);
1848 lmv_stripe_object_dump(D_ERROR, lsm_obj);
1849 GOTO(unlock, rc = -EINVAL);
1852 /* clear existing lsm */
1853 lmv_stripe_object_put(&lli->lli_lsm_obj);
1855 rc = ll_init_lsm_md(inode, md);
1859 if (!lmv_dir_striped(lli->lli_lsm_obj))
1860 GOTO(unlock, rc = 0);
1862 lsm_obj = lmv_stripe_object_get(lli->lli_lsm_obj);
1863 up_write(&lli->lli_lsm_sem);
1865 OBD_ALLOC_PTR(attr);
1867 GOTO(err, rc = -ENOMEM);
1869 /* validate the lsm */
1870 rc = md_merge_attr(ll_i2mdexp(inode), lsm_obj, attr,
1871 ll_md_blocking_ast);
1873 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1874 md->body->mbo_nlink = attr->cat_nlink;
1875 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1876 md->body->mbo_size = attr->cat_size;
1877 if (md->body->mbo_valid & OBD_MD_FLATIME)
1878 md->body->mbo_atime = attr->cat_atime;
1879 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1880 md->body->mbo_ctime = attr->cat_ctime;
1881 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1882 md->body->mbo_mtime = attr->cat_mtime;
1888 lmv_stripe_object_put(&lsm_obj);
1891 up_write(&lli->lli_lsm_sem);
1895 void ll_clear_inode(struct inode *inode)
1897 struct ll_inode_info *lli = ll_i2info(inode);
1898 struct ll_sb_info *sbi = ll_i2sbi(inode);
1902 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1903 PFID(ll_inode2fid(inode)), inode);
1905 if (S_ISDIR(inode->i_mode)) {
1906 /* these should have been cleared in ll_file_release */
1907 LASSERT(lli->lli_opendir_key == NULL);
1908 LASSERT(lli->lli_sai == NULL);
1909 LASSERT(lli->lli_opendir_pid == 0);
1911 pcc_inode_free(inode);
1914 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1916 LASSERT(!lli->lli_open_fd_write_count);
1917 LASSERT(!lli->lli_open_fd_read_count);
1918 LASSERT(!lli->lli_open_fd_exec_count);
1920 if (lli->lli_mds_write_och)
1921 ll_md_real_close(inode, FMODE_WRITE);
1922 if (lli->lli_mds_exec_och)
1923 ll_md_real_close(inode, FMODE_EXEC);
1924 if (lli->lli_mds_read_och)
1925 ll_md_real_close(inode, FMODE_READ);
1927 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1928 OBD_FREE(lli->lli_symlink_name,
1929 strlen(lli->lli_symlink_name) + 1);
1930 lli->lli_symlink_name = NULL;
1933 ll_xattr_cache_destroy(inode);
1935 forget_all_cached_acls(inode);
1937 lli->lli_inode_magic = LLI_INODE_DEAD;
1939 if (S_ISDIR(inode->i_mode))
1940 ll_dir_clear_lsm_md(inode);
1941 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1942 LASSERT(list_empty(&lli->lli_agl_list));
1945 * XXX This has to be done before lsm is freed below, because
1946 * cl_object still uses inode lsm.
1948 cl_inode_fini(inode);
1950 llcrypt_put_encryption_info(inode);
1955 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1957 struct lustre_md md;
1958 struct inode *inode = dentry->d_inode;
1959 struct ll_sb_info *sbi = ll_i2sbi(inode);
1960 struct ptlrpc_request *request = NULL;
1965 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1966 LUSTRE_OPC_ANY, NULL);
1967 if (IS_ERR(op_data))
1968 RETURN(PTR_ERR(op_data));
1970 /* If this is a chgrp of a regular file, we want to reserve enough
1971 * quota to cover the entire file size.
1973 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1974 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1975 from_kgid(&init_user_ns, inode->i_gid)) {
1976 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1977 op_data->op_attr_blocks = inode->i_blocks;
1981 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1983 ptlrpc_req_finished(request);
1984 if (rc == -ENOENT) {
1986 /* Unlinked special device node? Or just a race?
1987 * Pretend we done everything. */
1988 if (!S_ISREG(inode->i_mode) &&
1989 !S_ISDIR(inode->i_mode)) {
1990 ia_valid = op_data->op_attr.ia_valid;
1991 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1992 rc = simple_setattr(&nop_mnt_idmap, dentry,
1994 op_data->op_attr.ia_valid = ia_valid;
1996 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1997 CERROR("md_setattr fails: rc = %d\n", rc);
2002 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
2003 sbi->ll_md_exp, &md);
2005 ptlrpc_req_finished(request);
2009 ia_valid = op_data->op_attr.ia_valid;
2010 /* inode size will be in ll_setattr_ost, can't do it now since dirty
2011 * cache is not cleared yet. */
2012 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
2013 if (S_ISREG(inode->i_mode))
2014 ll_inode_lock(inode);
2015 rc = simple_setattr(&nop_mnt_idmap, dentry, &op_data->op_attr);
2016 if (S_ISREG(inode->i_mode))
2017 ll_inode_unlock(inode);
2018 op_data->op_attr.ia_valid = ia_valid;
2020 rc = ll_update_inode(inode, &md);
2021 ptlrpc_req_finished(request);
2022 md_put_lustre_md(sbi->ll_md_exp, &md);
2028 * Zero portion of page that is part of @inode.
2029 * This implies, if necessary:
2030 * - taking cl_lock on range corresponding to concerned page
2031 * - grabbing vm page
2032 * - associating cl_page
2033 * - proceeding to clio read
2034 * - zeroing range in page
2035 * - proceeding to cl_page flush
2036 * - releasing cl_lock
2038 * \param[in] inode inode
2039 * \param[in] index page index
2040 * \param[in] offset offset in page to start zero from
2041 * \param[in] len len to zero
2043 * \retval 0 on success
2044 * \retval negative errno on failure
2046 static int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
2049 struct ll_inode_info *lli = ll_i2info(inode);
2050 struct cl_object *clob = lli->lli_clob;
2052 struct lu_env *env = NULL;
2053 struct cl_io *io = NULL;
2054 struct cl_page *clpage = NULL;
2055 struct page *vmpage = NULL;
2056 unsigned from = index << PAGE_SHIFT;
2057 struct cl_lock *lock = NULL;
2058 struct cl_lock_descr *descr = NULL;
2059 struct cl_2queue *queue = NULL;
2060 struct cl_sync_io *anchor = NULL;
2061 bool holdinglock = false;
2066 env = cl_env_get(&refcheck);
2068 RETURN(PTR_ERR(env));
2070 io = vvp_env_thread_io(env);
2072 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2076 lock = vvp_env_lock(env);
2077 descr = &lock->cll_descr;
2078 descr->cld_obj = io->ci_obj;
2079 descr->cld_start = from >> PAGE_SHIFT;
2080 descr->cld_end = (from + PAGE_SIZE - 1) >> PAGE_SHIFT;
2081 descr->cld_mode = CLM_WRITE;
2082 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2084 /* request lock for page */
2085 rc = cl_lock_request(env, io, lock);
2086 /* -ECANCELED indicates a matching lock with a different extent
2087 * was already present, and -EEXIST indicates a matching lock
2088 * on exactly the same extent was already present.
2089 * In both cases it means we are covered.
2091 if (rc == -ECANCELED || rc == -EEXIST)
2099 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2101 GOTO(rellock, rc = -EOPNOTSUPP);
2103 if (!PageDirty(vmpage)) {
2104 /* associate cl_page */
2105 clpage = cl_page_find(env, clob, vmpage->index,
2106 vmpage, CPT_CACHEABLE);
2108 GOTO(pagefini, rc = PTR_ERR(clpage));
2110 cl_page_assume(env, io, clpage);
2113 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2114 !PageWriteback(vmpage)) {
2116 /* Set PagePrivate2 to detect special case of empty page
2117 * in osc_brw_fini_request().
2118 * It is also used to tell ll_io_read_page() that we do not
2119 * want the vmpage to be unlocked.
2121 SetPagePrivate2(vmpage);
2122 rc = ll_io_read_page(env, io, clpage, NULL);
2123 if (!PagePrivate2(vmpage)) {
2124 /* PagePrivate2 was cleared in osc_brw_fini_request()
2125 * meaning we read an empty page. In this case, in order
2126 * to avoid allocating unnecessary block in truncated
2127 * file, we must not zero and write as below. Subsequent
2128 * server-side truncate will handle things correctly.
2130 cl_page_unassume(env, io, clpage);
2131 GOTO(clpfini, rc = 0);
2133 ClearPagePrivate2(vmpage);
2138 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2139 * the vmpage, so we are good to proceed and zero range in page.
2141 zero_user(vmpage, offset, len);
2143 if (holdinglock && clpage) {
2144 /* explicitly write newly modified page */
2145 queue = &io->ci_queue;
2146 cl_2queue_init(queue);
2147 anchor = &vvp_env_info(env)->vti_anchor;
2148 cl_sync_io_init(anchor, 1);
2149 clpage->cp_sync_io = anchor;
2150 cl_page_list_add(&queue->c2_qin, clpage, true);
2151 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2153 GOTO(queuefini1, rc);
2154 rc = cl_sync_io_wait(env, anchor, 0);
2156 GOTO(queuefini2, rc);
2157 cl_page_assume(env, io, clpage);
2160 cl_2queue_discard(env, io, queue);
2162 cl_2queue_disown(env, queue);
2163 cl_2queue_fini(env, queue);
2168 cl_page_put(env, clpage);
2170 unlock_page(vmpage);
2174 cl_lock_release(env, lock);
2176 cl_io_fini(env, io);
2179 cl_env_put(env, &refcheck);
2185 * Get reference file from volatile file name.
2186 * Volatile file name may look like:
2187 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2188 * where fd is opened descriptor of reference file.
2190 * \param[in] volatile_name volatile file name
2191 * \param[in] volatile_len volatile file name length
2192 * \param[out] ref_file pointer to struct file of reference file
2194 * \retval 0 on success
2195 * \retval negative errno on failure
2197 int volatile_ref_file(const char *volatile_name, int volatile_len,
2198 struct file **ref_file)
2200 char *p, *q, *fd_str;
2203 p = strnstr(volatile_name, ":fd=", volatile_len);
2204 if (!p || strlen(p + 4) == 0)
2207 q = strchrnul(p + 4, ':');
2208 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2211 rc = kstrtouint(fd_str, 10, &fd);
2216 *ref_file = fget(fd);
2222 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2223 * object(s) determine the file size and mtime. Otherwise, the MDS will
2224 * keep these values until such a time that objects are allocated for it.
2225 * We do the MDS operations first, as it is checking permissions for us.
2226 * We don't to the MDS RPC if there is nothing that we want to store there,
2227 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2228 * going to do an RPC anyways.
2230 * If we are doing a truncate, we will send the mtime and ctime updates
2231 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2232 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2235 * In case of HSMimport, we only set attr on MDS.
2237 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2238 enum op_xvalid xvalid, bool hsm_import)
2240 struct inode *inode = dentry->d_inode;
2241 struct ll_inode_info *lli = ll_i2info(inode);
2242 struct md_op_data *op_data = NULL;
2243 ktime_t kstart = ktime_get();
2248 /* VFS has locked the inode before calling this */
2249 ll_set_inode_lock_owner(inode);
2251 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2252 "valid %x, hsm_import %d\n",
2253 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2254 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2257 if (attr->ia_valid & ATTR_SIZE) {
2258 /* Check new size against VFS/VM file size limit and rlimit */
2259 rc = inode_newsize_ok(inode, attr->ia_size);
2263 /* The maximum Lustre file size is variable, based on the
2264 * OST maximum object size and number of stripes. This
2265 * needs another check in addition to the VFS check above. */
2266 if (attr->ia_size > ll_file_maxbytes(inode)) {
2267 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2268 PFID(&lli->lli_fid), attr->ia_size,
2269 ll_file_maxbytes(inode));
2270 GOTO(clear, rc = -EFBIG);
2273 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2276 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2277 if (attr->ia_valid & TIMES_SET_FLAGS) {
2278 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2279 !capable(CAP_FOWNER))
2280 GOTO(clear, rc = -EPERM);
2283 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2284 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2285 (attr->ia_valid & ATTR_CTIME)) {
2286 attr->ia_ctime = current_time(inode);
2287 xvalid |= OP_XVALID_CTIME_SET;
2289 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2290 (attr->ia_valid & ATTR_ATIME)) {
2291 attr->ia_atime = current_time(inode);
2292 attr->ia_valid |= ATTR_ATIME_SET;
2294 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2295 (attr->ia_valid & ATTR_MTIME)) {
2296 attr->ia_mtime = current_time(inode);
2297 attr->ia_valid |= ATTR_MTIME_SET;
2300 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2301 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2302 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2303 ktime_get_real_seconds());
2305 if (S_ISREG(inode->i_mode))
2306 ll_inode_unlock(inode);
2308 /* We always do an MDS RPC, even if we're only changing the size;
2309 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2311 OBD_ALLOC_PTR(op_data);
2312 if (op_data == NULL)
2313 GOTO(out, rc = -ENOMEM);
2315 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2316 /* If we are changing file size, file content is
2317 * modified, flag it.
2319 xvalid |= OP_XVALID_OWNEROVERRIDE;
2320 op_data->op_bias |= MDS_DATA_MODIFIED;
2321 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2324 if (attr->ia_valid & ATTR_FILE) {
2325 struct ll_file_data *fd = attr->ia_file->private_data;
2327 if (fd->fd_lease_och)
2328 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2331 op_data->op_attr = *attr;
2332 op_data->op_xvalid = xvalid;
2334 rc = ll_md_setattr(dentry, op_data);
2337 lli->lli_synced_to_mds = false;
2339 if (!S_ISREG(inode->i_mode) || hsm_import)
2342 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2343 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2344 xvalid & OP_XVALID_CTIME_SET) {
2345 bool cached = false;
2347 rc = pcc_inode_setattr(inode, attr, &cached);
2350 CERROR("%s: PCC inode "DFID" setattr failed: "
2352 ll_i2sbi(inode)->ll_fsname,
2353 PFID(&lli->lli_fid), rc);
2357 unsigned int flags = 0;
2359 /* For truncate and utimes sending attributes to OSTs,
2360 * setting mtime/atime to the past will be performed
2361 * under PW [0:EOF] extent lock (new_size:EOF for
2362 * truncate). It may seem excessive to send mtime/atime
2363 * updates to OSTs when not setting times to past, but
2364 * it is necessary due to possible time
2365 * de-synchronization between MDT inode and OST objects
2367 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2368 xvalid |= OP_XVALID_FLAGS;
2369 flags = LUSTRE_ENCRYPT_FL;
2370 /* Call to ll_io_zero_page is not necessary if
2371 * truncating on PAGE_SIZE boundary, because
2372 * whole pages will be wiped.
2374 * an exception is when working with the
2375 * raw ciphertext - in that case, we need to
2376 * encrypt those zeroes
2378 if (attr->ia_valid & ATTR_SIZE &&
2379 attr->ia_size & ~PAGE_MASK &&
2380 !(attr->ia_valid & ATTR_FILE &&
2381 attr->ia_file->f_flags & O_CIPHERTEXT)) {
2383 attr->ia_size & (PAGE_SIZE - 1);
2385 rc = ll_io_zero_page(inode,
2386 attr->ia_size >> PAGE_SHIFT,
2387 offset, PAGE_SIZE - offset);
2391 /* If encrypted volatile file without the key,
2392 * we need to fetch size from reference file,
2393 * and set it on OST objects. This happens when
2394 * migrating or extending an encrypted file
2397 if (filename_is_volatile(dentry->d_name.name,
2400 llcrypt_require_key(inode) == -ENOKEY) {
2401 struct file *ref_file;
2402 struct inode *ref_inode;
2403 struct ll_inode_info *ref_lli;
2404 struct cl_object *ref_obj;
2405 struct cl_attr ref_attr = { 0 };
2409 rc = volatile_ref_file(
2410 dentry->d_name.name,
2416 ref_inode = file_inode(ref_file);
2419 GOTO(out, rc = -EINVAL);
2422 env = cl_env_get(&refcheck);
2424 GOTO(out, rc = PTR_ERR(env));
2426 ref_lli = ll_i2info(ref_inode);
2427 ref_obj = ref_lli->lli_clob;
2428 cl_object_attr_lock(ref_obj);
2429 rc = cl_object_attr_get(env, ref_obj,
2431 cl_object_attr_unlock(ref_obj);
2432 cl_env_put(env, &refcheck);
2437 attr->ia_valid |= ATTR_SIZE;
2438 attr->ia_size = ref_attr.cat_size;
2441 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2445 /* If the file was restored, it needs to set dirty flag.
2447 * We've already sent MDS_DATA_MODIFIED flag in
2448 * ll_md_setattr() for truncate. However, the MDT refuses to
2449 * set the HS_DIRTY flag on released files, so we have to set
2450 * it again if the file has been restored. Please check how
2451 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2453 * Please notice that if the file is not released, the previous
2454 * MDS_DATA_MODIFIED has taken effect and usually
2455 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2456 * This way we can save an RPC for common open + trunc
2458 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2459 struct hsm_state_set hss = {
2460 .hss_valid = HSS_SETMASK,
2461 .hss_setmask = HS_DIRTY,
2465 rc2 = ll_hsm_state_set(inode, &hss);
2466 /* truncate and write can happen at the same time, so that
2467 * the file can be set modified even though the file is not
2468 * restored from released state, and ll_hsm_state_set() is
2469 * not applicable for the file, and rc2 < 0 is normal in this
2472 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2473 PFID(ll_inode2fid(inode)), rc2);
2478 if (op_data != NULL)
2479 ll_finish_md_op_data(op_data);
2481 if (S_ISREG(inode->i_mode)) {
2482 ll_inode_lock(inode);
2483 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2484 inode_dio_wait(inode);
2485 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2486 * flag. ll_update_inode (called from ll_md_setattr), clears
2487 * inode flags, so there is a gap where S_NOSEC is not set.
2488 * This can cause a writer to take the i_mutex unnecessarily,
2489 * but this is safe to do and should be rare. */
2490 inode_has_no_xattr(inode);
2494 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2495 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2496 ktime_us_delta(ktime_get(), kstart));
2498 ll_clear_inode_lock_owner(inode);
2503 int ll_setattr(struct mnt_idmap *map, struct dentry *de, struct iattr *attr)
2505 int mode = de->d_inode->i_mode;
2506 enum op_xvalid xvalid = 0;
2509 rc = setattr_prepare(map, de, attr);
2513 rc = llcrypt_prepare_setattr(de, attr);
2517 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2518 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2519 xvalid |= OP_XVALID_OWNEROVERRIDE;
2521 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2522 (ATTR_SIZE|ATTR_MODE)) &&
2523 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2524 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2525 !(attr->ia_mode & S_ISGID))))
2526 attr->ia_valid |= ATTR_FORCE;
2528 if ((attr->ia_valid & ATTR_MODE) &&
2530 !(attr->ia_mode & S_ISUID) &&
2531 !(attr->ia_valid & ATTR_KILL_SUID))
2532 attr->ia_valid |= ATTR_KILL_SUID;
2534 if ((attr->ia_valid & ATTR_MODE) &&
2535 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2536 !(attr->ia_mode & S_ISGID) &&
2537 !(attr->ia_valid & ATTR_KILL_SGID))
2538 attr->ia_valid |= ATTR_KILL_SGID;
2540 return ll_setattr_raw(de, attr, xvalid, false);
2543 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2546 struct obd_statfs obd_osfs = { 0 };
2551 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2553 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2554 flags |= OBD_STATFS_NODELAY;
2556 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2560 osfs->os_type = LL_SUPER_MAGIC;
2562 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2563 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2565 if (osfs->os_state & OS_STATFS_SUM)
2568 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2569 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2572 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2573 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2576 osfs->os_bsize = obd_osfs.os_bsize;
2577 osfs->os_blocks = obd_osfs.os_blocks;
2578 osfs->os_bfree = obd_osfs.os_bfree;
2579 osfs->os_bavail = obd_osfs.os_bavail;
2581 /* If we have _some_ OSTs, but don't have as many free objects on the
2582 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2583 * to compensate, so that the "inodes in use" number is correct.
2584 * This should be kept in sync with lod_statfs() behaviour.
2586 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2587 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2589 osfs->os_ffree = obd_osfs.os_ffree;
2596 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2598 struct if_quotactl qctl = {
2599 .qc_cmd = LUSTRE_Q_GETQUOTA,
2600 .qc_type = PRJQUOTA,
2601 .qc_valid = QC_GENERAL,
2603 u64 limit, curblock;
2606 qctl.qc_id = ll_i2info(inode)->lli_projid;
2607 ret = quotactl_ioctl(inode->i_sb, &qctl);
2609 /* ignore errors if project ID does not have
2610 * a quota limit or feature unsupported.
2612 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2617 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2618 qctl.qc_dqblk.dqb_bsoftlimit :
2619 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2620 if (limit && sfs->f_blocks > limit) {
2621 curblock = (qctl.qc_dqblk.dqb_curspace +
2622 sfs->f_bsize - 1) / sfs->f_bsize;
2623 sfs->f_blocks = limit;
2624 sfs->f_bfree = sfs->f_bavail =
2625 (sfs->f_blocks > curblock) ?
2626 (sfs->f_blocks - curblock) : 0;
2629 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2630 qctl.qc_dqblk.dqb_isoftlimit :
2631 qctl.qc_dqblk.dqb_ihardlimit;
2632 if (limit && sfs->f_files > limit) {
2633 sfs->f_files = limit;
2634 sfs->f_ffree = (sfs->f_files >
2635 qctl.qc_dqblk.dqb_curinodes) ?
2636 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2642 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2644 struct super_block *sb = de->d_sb;
2645 struct ll_sb_info *sbi = ll_s2sbi(sb);
2646 struct obd_statfs osfs;
2647 __u64 fsid = huge_encode_dev(sb->s_dev);
2648 ktime_t kstart = ktime_get();
2651 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2653 /* Some amount of caching on the client is allowed */
2654 rc = ll_statfs_internal(sbi, &osfs, OBD_STATFS_SUM);
2658 statfs_unpack(sfs, &osfs);
2660 /* We need to downshift for all 32-bit kernels, because we can't
2661 * tell if the kernel is being called via sys_statfs64() or not.
2662 * Stop before overflowing f_bsize - in which case it is better
2663 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2664 if (sizeof(long) < 8) {
2665 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2668 osfs.os_blocks >>= 1;
2669 osfs.os_bfree >>= 1;
2670 osfs.os_bavail >>= 1;
2674 sfs->f_blocks = osfs.os_blocks;
2675 sfs->f_bfree = osfs.os_bfree;
2676 sfs->f_bavail = osfs.os_bavail;
2677 sfs->f_fsid.val[0] = (__u32)fsid;
2678 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2679 if (ll_i2info(de->d_inode)->lli_projid &&
2680 test_bit(LL_SBI_STATFS_PROJECT, sbi->ll_flags) &&
2681 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2682 return ll_statfs_project(de->d_inode, sfs);
2684 ll_stats_ops_tally(sbi, LPROC_LL_STATFS,
2685 ktime_us_delta(ktime_get(), kstart));
2690 void ll_inode_size_lock(struct inode *inode)
2692 struct ll_inode_info *lli;
2694 LASSERT(!S_ISDIR(inode->i_mode));
2696 lli = ll_i2info(inode);
2697 mutex_lock(&lli->lli_size_mutex);
2698 lli->lli_size_lock_owner = current;
2701 void ll_inode_size_unlock(struct inode *inode)
2703 struct ll_inode_info *lli;
2705 lli = ll_i2info(inode);
2706 lli->lli_size_lock_owner = NULL;
2707 mutex_unlock(&lli->lli_size_mutex);
2710 int ll_inode_size_trylock(struct inode *inode)
2712 struct ll_inode_info *lli;
2714 LASSERT(!S_ISDIR(inode->i_mode));
2716 lli = ll_i2info(inode);
2717 return mutex_trylock(&lli->lli_size_mutex);
2720 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2722 /* do not clear encryption flag */
2723 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2724 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2725 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2726 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2728 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2731 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2733 struct ll_inode_info *lli = ll_i2info(inode);
2734 struct mdt_body *body = md->body;
2735 struct ll_sb_info *sbi = ll_i2sbi(inode);
2739 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2740 rc = cl_file_inode_init(inode, md);
2745 if (S_ISDIR(inode->i_mode)) {
2746 rc = ll_update_lsm_md(inode, md);
2751 if (body->mbo_valid & OBD_MD_FLACL)
2752 lli_replace_acl(lli, md);
2754 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2755 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2756 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2758 if (body->mbo_valid & OBD_MD_FLATIME) {
2759 if (body->mbo_atime > inode->i_atime.tv_sec)
2760 inode->i_atime.tv_sec = body->mbo_atime;
2761 lli->lli_atime = body->mbo_atime;
2764 if (body->mbo_valid & OBD_MD_FLMTIME) {
2765 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2767 "setting ino %lu mtime from %lld to %llu\n",
2768 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2770 inode->i_mtime.tv_sec = body->mbo_mtime;
2772 lli->lli_mtime = body->mbo_mtime;
2775 if (body->mbo_valid & OBD_MD_FLCTIME) {
2776 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2777 inode->i_ctime.tv_sec = body->mbo_ctime;
2778 lli->lli_ctime = body->mbo_ctime;
2781 if (body->mbo_valid & OBD_MD_FLBTIME)
2782 lli->lli_btime = body->mbo_btime;
2784 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2785 if (body->mbo_valid & OBD_MD_FLFLAGS)
2786 ll_update_inode_flags(inode, body->mbo_flags);
2787 if (body->mbo_valid & OBD_MD_FLMODE)
2788 inode->i_mode = (inode->i_mode & S_IFMT) |
2789 (body->mbo_mode & ~S_IFMT);
2791 if (body->mbo_valid & OBD_MD_FLTYPE)
2792 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2793 (body->mbo_mode & S_IFMT);
2795 LASSERT(inode->i_mode != 0);
2796 if (body->mbo_valid & OBD_MD_FLUID)
2797 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2798 if (body->mbo_valid & OBD_MD_FLGID)
2799 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2800 if (body->mbo_valid & OBD_MD_FLPROJID)
2801 lli->lli_projid = body->mbo_projid;
2802 if (body->mbo_valid & OBD_MD_FLNLINK) {
2803 spin_lock(&inode->i_lock);
2804 set_nlink(inode, body->mbo_nlink);
2805 spin_unlock(&inode->i_lock);
2807 if (body->mbo_valid & OBD_MD_FLRDEV)
2808 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2810 if (body->mbo_valid & OBD_MD_FLID) {
2811 /* FID shouldn't be changed! */
2812 if (fid_is_sane(&lli->lli_fid)) {
2813 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2814 "Trying to change FID "DFID
2815 " to the "DFID", inode "DFID"(%p)\n",
2816 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2817 PFID(ll_inode2fid(inode)), inode);
2819 lli->lli_fid = body->mbo_fid1;
2823 LASSERT(fid_seq(&lli->lli_fid) != 0);
2825 /* In case of encrypted file without the key, please do not lose
2826 * clear text size stored into lli_lazysize in ll_merge_attr(),
2827 * we will need it in ll_prepare_close().
2829 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2830 llcrypt_require_key(inode) == -ENOKEY)
2831 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2833 lli->lli_attr_valid = body->mbo_valid;
2834 if (body->mbo_valid & OBD_MD_FLSIZE) {
2835 i_size_write(inode, body->mbo_size);
2837 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2838 PFID(ll_inode2fid(inode)),
2839 (unsigned long long)body->mbo_size);
2841 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2842 inode->i_blocks = body->mbo_blocks;
2844 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2845 lli->lli_lazysize = body->mbo_size;
2846 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2847 lli->lli_lazyblocks = body->mbo_blocks;
2850 if (body->mbo_valid & OBD_MD_TSTATE) {
2851 /* Set LLIF_FILE_RESTORING if restore ongoing and
2852 * clear it when done to ensure to start again
2853 * glimpsing updated attrs
2855 if (body->mbo_t_state & MS_RESTORE)
2856 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2858 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2864 /* child default LMV is inherited from parent */
2865 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2866 struct lmv_stripe_md *cdmv)
2871 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2872 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2873 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2874 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2877 if (cdmv->lsm_md_max_inherit !=
2878 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2881 if (cdmv->lsm_md_max_inherit_rr !=
2882 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2888 /* if default LMV is implicitly inherited, subdir default LMV is maintained on
2891 static int ll_dir_default_lmv_inherit(struct inode *dir, struct inode *inode)
2893 struct ll_inode_info *plli = ll_i2info(dir);
2894 struct ll_inode_info *lli = ll_i2info(inode);
2895 struct lmv_stripe_object *plsm_obj;
2896 struct lmv_stripe_object *lsm_obj;
2901 /* ROOT default LMV is not inherited */
2902 if (is_root_inode(dir) ||
2903 !(exp_connect_flags2(ll_i2mdexp(dir)) &
2904 OBD_CONNECT2_DMV_IMP_INHERIT))
2907 /* nothing to do if no default LMV on both */
2908 if (!plli->lli_def_lsm_obj && !lli->lli_def_lsm_obj)
2911 /* subdir default LMV comes from disk */
2912 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set)
2915 /* delete subdir default LMV if parent's is deleted or becomes
2918 down_read(&plli->lli_lsm_sem);
2919 plsm_obj = plli->lli_def_lsm_obj;
2921 !lmv_is_inheritable(plsm_obj->lso_lsm.lsm_md_max_inherit)) {
2922 if (lli->lli_def_lsm_obj && !lli->lli_def_lsm_obj_set) {
2923 down_write(&lli->lli_lsm_sem);
2924 if (!lli->lli_def_lsm_obj_set) {
2925 lmv_stripe_object_put(&lli->lli_def_lsm_obj);
2926 lli->lli_inherit_depth = 0;
2928 up_write(&lli->lli_lsm_sem);
2930 GOTO(unlock_parent, rc = 0);
2933 /* do nothing if inherited LMV is unchanged */
2934 if (lli->lli_def_lsm_obj) {
2936 down_read(&lli->lli_lsm_sem);
2937 if (!lli->lli_def_lsm_obj_set)
2938 rc = lmv_object_inherited(plsm_obj,
2939 lli->lli_def_lsm_obj);
2940 up_read(&lli->lli_lsm_sem);
2942 GOTO(unlock_parent, rc = 0);
2945 /* inherit default LMV */
2946 down_write(&lli->lli_lsm_sem);
2947 if (lli->lli_def_lsm_obj) {
2948 /* checked above, but in case of race, check again with lock */
2949 if (lli->lli_def_lsm_obj_set)
2950 GOTO(unlock_child, rc = 0);
2951 /* always update subdir default LMV in case parent's changed */
2952 lsm_obj = lli->lli_def_lsm_obj;
2954 lsm_obj = lmv_stripe_object_alloc(LMV_USER_MAGIC, NULL, 0);
2955 if (IS_ERR(lsm_obj))
2956 GOTO(unlock_child, rc = PTR_ERR(lsm_obj));
2957 lli->lli_def_lsm_obj = lsm_obj;
2960 lsm_obj->lso_lsm = plsm_obj->lso_lsm;
2961 lsm_obj->lso_lsm.lsm_md_max_inherit =
2962 lmv_inherit_next(plsm_obj->lso_lsm.lsm_md_max_inherit);
2963 lsm_obj->lso_lsm.lsm_md_max_inherit_rr =
2964 lmv_inherit_rr_next(plsm_obj->lso_lsm.lsm_md_max_inherit_rr);
2965 lli->lli_inherit_depth = plli->lli_inherit_depth + 1;
2967 lmv_stripe_object_dump(D_INODE, lsm_obj);
2971 up_write(&lli->lli_lsm_sem);
2973 up_read(&plli->lli_lsm_sem);
2978 enum lsm_sem_class {
2984 * Update directory depth and default LMV
2986 * Update directory depth to ROOT and inherit default LMV from parent if
2987 * parent's default LMV is inheritable. The default LMV set with command
2988 * "lfs setdirstripe -D ..." is stored on MDT, while the inherited default LMV
2989 * is generated at runtime on client side.
2991 * \param[in] dir parent directory inode
2992 * \param[in] de dentry
2994 void ll_update_dir_depth_dmv(struct inode *dir, struct dentry *de)
2996 struct inode *inode = de->d_inode;
2997 struct ll_inode_info *plli;
2998 struct ll_inode_info *lli;
3000 LASSERT(S_ISDIR(inode->i_mode));
3004 plli = ll_i2info(dir);
3005 lli = ll_i2info(inode);
3006 lli->lli_dir_depth = plli->lli_dir_depth + 1;
3007 if (lli->lli_def_lsm_obj && lli->lli_def_lsm_obj_set) {
3008 if (plli->lli_def_lsm_obj) {
3009 down_read_nested(&plli->lli_lsm_sem, LSM_SEM_PARENT);
3010 down_read_nested(&lli->lli_lsm_sem, LSM_SEM_CHILD);
3011 if (lmv_object_inherited(plli->lli_def_lsm_obj,
3012 lli->lli_def_lsm_obj))
3013 lli->lli_inherit_depth =
3014 plli->lli_inherit_depth + 1;
3016 /* in case parent default LMV changed */
3017 lli->lli_inherit_depth = 0;
3018 up_read(&lli->lli_lsm_sem);
3019 up_read(&plli->lli_lsm_sem);
3021 /* in case parent default LMV deleted */
3022 lli->lli_inherit_depth = 0;
3025 ll_dir_default_lmv_inherit(dir, inode);
3028 if (lli->lli_def_lsm_obj)
3030 "%s "DFID" depth %hu %s default LMV inherit depth %hu\n",
3031 de->d_name.name, PFID(&lli->lli_fid), lli->lli_dir_depth,
3032 lli->lli_def_lsm_obj_set ? "server" : "client",
3033 lli->lli_inherit_depth);
3036 void ll_truncate_inode_pages_final(struct inode *inode)
3038 struct address_space *mapping = &inode->i_data;
3039 unsigned long nrpages;
3040 unsigned long flags;
3042 LASSERTF((inode->i_state & I_FREEING) || inode_is_locked(inode),
3043 DFID ":inode %p state %#lx, lli_flags %#lx\n",
3044 PFID(ll_inode2fid(inode)), inode, inode->i_state,
3045 ll_i2info(inode)->lli_flags);
3047 truncate_inode_pages_final(mapping);
3049 /* Workaround for LU-118: Note nrpages may not be totally updated when
3050 * truncate_inode_pages() returns, as there can be a page in the process
3051 * of deletion (inside __delete_from_page_cache()) in the specified
3052 * range. Thus mapping->nrpages can be non-zero when this function
3053 * returns even after truncation of the whole mapping. Only do this if
3054 * npages isn't already zero.
3056 nrpages = mapping->nrpages;
3058 ll_xa_lock_irqsave(&mapping->i_pages, flags);
3059 nrpages = mapping->nrpages;
3060 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
3061 } /* Workaround end */
3063 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu "
3064 "state %#lx, lli_flags %#lx, "
3065 "see https://jira.whamcloud.com/browse/LU-118\n",
3066 ll_i2sbi(inode)->ll_fsname,
3067 PFID(ll_inode2fid(inode)), inode, nrpages,
3068 inode->i_state, ll_i2info(inode)->lli_flags);
3071 int ll_read_inode2(struct inode *inode, void *opaque)
3073 struct lustre_md *md = opaque;
3074 struct ll_inode_info *lli = ll_i2info(inode);
3078 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
3079 PFID(&lli->lli_fid), inode);
3081 /* Core attributes from the MDS first. This is a new inode, and
3082 * the VFS doesn't zero times in the core inode so we have to do
3083 * it ourselves. They will be overwritten by either MDS or OST
3084 * attributes - we just need to make sure they aren't newer.
3086 inode->i_mtime.tv_sec = 0;
3087 inode->i_atime.tv_sec = 0;
3088 inode->i_ctime.tv_sec = 0;
3090 rc = ll_update_inode(inode, md);
3094 /* OIDEBUG(inode); */
3096 #ifdef HAVE_BACKING_DEV_INFO
3097 /* initializing backing dev info. */
3098 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
3100 if (S_ISREG(inode->i_mode)) {
3101 struct ll_sb_info *sbi = ll_i2sbi(inode);
3102 inode->i_op = &ll_file_inode_operations;
3103 inode->i_fop = sbi->ll_fop;
3104 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
3106 } else if (S_ISDIR(inode->i_mode)) {
3107 inode->i_op = &ll_dir_inode_operations;
3108 inode->i_fop = &ll_dir_operations;
3110 } else if (S_ISLNK(inode->i_mode)) {
3111 inode->i_op = &ll_fast_symlink_inode_operations;
3114 inode->i_op = &ll_special_inode_operations;
3116 init_special_inode(inode, inode->i_mode,
3125 void ll_delete_inode(struct inode *inode)
3127 struct ll_inode_info *lli = ll_i2info(inode);
3130 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
3131 /* It is last chance to write out dirty pages,
3132 * otherwise we may lose data while umount.
3134 * If i_nlink is 0 then just discard data. This is safe because
3135 * local inode gets i_nlink 0 from server only for the last
3136 * unlink, so that file is not opened somewhere else
3138 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
3139 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
3142 ll_truncate_inode_pages_final(inode);
3143 ll_clear_inode(inode);
3149 static int fileattr_get(struct inode *inode, int *flags,
3153 struct ll_sb_info *sbi = ll_i2sbi(inode);
3154 struct ptlrpc_request *req = NULL;
3155 struct md_op_data *op_data;
3156 struct mdt_body *body;
3160 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
3161 0, 0, LUSTRE_OPC_ANY,
3163 if (IS_ERR(op_data))
3164 RETURN(PTR_ERR(op_data));
3166 op_data->op_valid = OBD_MD_FLFLAGS;
3167 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
3168 ll_finish_md_op_data(op_data);
3170 CERROR("%s: failure inode "DFID": rc = %d\n",
3171 sbi->ll_md_exp->exp_obd->obd_name,
3172 PFID(ll_inode2fid(inode)), rc);
3176 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3178 *flags = body->mbo_flags;
3179 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
3180 * ext4 equivalent to please lsattr and other e2fsprogs tools
3182 if (*flags & LUSTRE_ENCRYPT_FL)
3183 *flags |= STATX_ATTR_ENCRYPTED;
3185 ptlrpc_req_finished(req);
3187 *xflags = ll_inode_flags_to_xflags(inode->i_flags);
3188 if (test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags))
3189 *xflags |= FS_XFLAG_PROJINHERIT;
3190 *projid = ll_i2info(inode)->lli_projid;
3195 static int fileattr_set(struct inode *inode, int flags)
3197 struct ll_sb_info *sbi = ll_i2sbi(inode);
3198 struct ptlrpc_request *req = NULL;
3199 struct md_op_data *op_data;
3200 struct cl_object *obj;
3201 struct fsxattr fa = { 0 };
3206 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3207 if (flags & LUSTRE_PROJINHERIT_FL)
3208 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3210 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3215 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3216 LUSTRE_OPC_ANY, NULL);
3217 if (IS_ERR(op_data))
3218 RETURN(PTR_ERR(op_data));
3220 op_data->op_attr_flags = flags;
3221 op_data->op_xvalid |= OP_XVALID_FLAGS;
3222 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3223 ll_finish_md_op_data(op_data);
3224 ptlrpc_req_finished(req);
3228 ll_update_inode_flags(inode, flags);
3230 obj = ll_i2info(inode)->lli_clob;
3234 OBD_ALLOC_PTR(attr);
3238 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3244 #ifdef HAVE_FILEATTR_GET
3245 int ll_fileattr_get(struct dentry *dentry, struct fileattr *fa)
3247 return fileattr_get(d_inode(dentry), &fa->flags,
3248 &fa->fsx_xflags, &fa->fsx_projid);
3251 int ll_fileattr_set(struct mnt_idmap *mnt_userns,
3252 struct dentry *dentry, struct fileattr *fa)
3255 return ll_set_project(d_inode(dentry), fa->fsx_xflags,
3258 return fileattr_set(d_inode(dentry), fa->flags);
3260 #endif /* HAVE_FILEATTR_GET */
3262 /* ioctl commands shared between files and directories */
3263 int ll_iocontrol(struct inode *inode, struct file *file,
3264 unsigned int cmd, void __user *uarg)
3271 RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
3272 case LL_IOC_GETVERSION:
3273 case FS_IOC_GETVERSION:
3274 RETURN(put_user(inode->i_generation, (int __user *)uarg));
3276 #ifndef HAVE_FILEATTR_GET
3277 case FS_IOC_GETFLAGS: {
3278 u32 xflags = 0, projid = 0;
3281 if (!ll_access_ok(uarg, sizeof(int)))
3283 rc = fileattr_get(file->f_inode, &flags, &xflags, &projid);
3287 RETURN(put_user(flags, (int __user *)uarg));
3289 case FS_IOC_SETFLAGS: {
3292 if (get_user(flags, (int __user *)uarg))
3295 RETURN(fileattr_set(file->f_inode, flags));
3297 case FS_IOC_FSGETXATTR:
3298 RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
3299 case FS_IOC_FSSETXATTR:
3300 RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
3301 #endif /* HAVE_FILEATTR_GET */
3302 case LL_IOC_PROJECT:
3303 RETURN(ll_ioctl_project(file, cmd, uarg));
3304 case IOC_OBD_STATFS:
3305 RETURN(ll_obd_statfs(inode, uarg));
3306 case LL_IOC_GET_MDTIDX: {
3307 if (!ll_access_ok(uarg, sizeof(rc)))
3310 rc = ll_get_mdt_idx(inode);
3314 if (put_user(rc, (int __user *)uarg))
3319 case LL_IOC_FLUSHCTX:
3320 RETURN(ll_flush_ctx(inode));
3321 #ifdef HAVE_LUSTRE_CRYPTO
3322 case LL_IOC_ADD_ENCRYPTION_KEY:
3323 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3325 rc = llcrypt_ioctl_add_key(file, uarg);
3326 #ifdef CONFIG_LL_ENCRYPTION
3327 if (!rc && S_ISDIR(inode->i_mode))
3328 sptlrpc_enc_pool_add_user();
3331 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
3332 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3334 RETURN(llcrypt_ioctl_get_key_status(file, uarg));
3335 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
3336 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3338 RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
3339 case LL_IOC_SET_ENCRYPTION_POLICY:
3340 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3342 RETURN(llcrypt_ioctl_set_policy(file, uarg));
3343 case LL_IOC_REMOVE_ENCRYPTION_KEY:
3344 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3346 RETURN(llcrypt_ioctl_remove_key(file, uarg));
3347 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
3348 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3350 RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
3352 case LL_IOC_GETPARENT:
3353 RETURN(ll_getparent(file, uarg));
3354 case LL_IOC_PATH2FID:
3355 if (copy_to_user(uarg, ll_inode2fid(inode),
3356 sizeof(struct lu_fid)))
3359 case LL_IOC_UNLOCK_FOREIGN: {
3360 struct dentry *dentry = file_dentry(file);
3362 /* if not a foreign symlink do nothing */
3363 if (ll_foreign_is_removable(dentry, true)) {
3365 "prevent unlink of non-foreign file ("DFID")\n",
3366 PFID(ll_inode2fid(inode)));
3367 RETURN(-EOPNOTSUPP);
3371 case OBD_IOC_FID2PATH:
3372 RETURN(ll_fid2path(inode, uarg));
3373 #ifdef OBD_IOC_GETNAME_OLD
3374 case_OBD_IOC_DEPRECATED_FT(OBD_IOC_GETNAME_OLD,
3375 ll_i2sbi(inode)->ll_md_exp->exp_obd->obd_name,
3378 case OBD_IOC_GETDTNAME:
3379 case OBD_IOC_GETMDNAME:
3380 RETURN(ll_get_obd_name(inode, cmd, uarg));
3388 int ll_flush_ctx(struct inode *inode)
3390 struct ll_sb_info *sbi = ll_i2sbi(inode);
3392 CDEBUG(D_SEC, "flush context for user %d\n",
3393 from_kuid(&init_user_ns, current_uid()));
3395 obd_set_info_async(NULL, sbi->ll_md_exp,
3396 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3398 obd_set_info_async(NULL, sbi->ll_dt_exp,
3399 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3404 /* umount -f client means force down, don't save state */
3405 void ll_umount_begin(struct super_block *sb)
3407 struct ll_sb_info *sbi = ll_s2sbi(sb);
3408 struct obd_device *obd;
3409 struct obd_ioctl_data *ioc_data;
3413 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3414 sb->s_count, atomic_read(&sb->s_active));
3416 obd = class_exp2obd(sbi->ll_md_exp);
3418 CERROR("Invalid MDC connection handle %#llx\n",
3419 sbi->ll_md_exp->exp_handle.h_cookie);
3425 obd = class_exp2obd(sbi->ll_dt_exp);
3427 CERROR("Invalid LOV connection handle %#llx\n",
3428 sbi->ll_dt_exp->exp_handle.h_cookie);
3434 OBD_ALLOC_PTR(ioc_data);
3436 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_md_exp,
3437 sizeof *ioc_data, ioc_data, NULL);
3439 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_dt_exp,
3440 sizeof *ioc_data, ioc_data, NULL);
3442 OBD_FREE_PTR(ioc_data);
3445 /* Really, we'd like to wait until there are no requests outstanding,
3446 * and then continue. For now, we just periodically checking for vfs
3447 * to decrement mnt_cnt and hope to finish it within 10sec.
3451 !may_umount(sbi->ll_mnt.mnt)) {
3459 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3461 struct ll_sb_info *sbi = ll_s2sbi(sb);
3462 char *profilenm = get_profile_name(sb);
3466 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3467 read_only = *flags & MS_RDONLY;
3468 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3469 sizeof(KEY_READ_ONLY),
3470 KEY_READ_ONLY, sizeof(read_only),
3473 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3474 profilenm, read_only ?
3475 "read-only" : "read-write", err);
3480 sb->s_flags |= SB_RDONLY;
3482 sb->s_flags &= ~SB_RDONLY;
3484 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3485 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3486 read_only ? "read-only" : "read-write");
3492 * Cleanup the open handle that is cached on MDT-side.
3494 * For open case, the client side open handling thread may hit error
3495 * after the MDT grant the open. Under such case, the client should
3496 * send close RPC to the MDT as cleanup; otherwise, the open handle
3497 * on the MDT will be leaked there until the client umount or evicted.
3499 * In further, if someone unlinked the file, because the open handle
3500 * holds the reference on such file/object, then it will block the
3501 * subsequent threads that want to locate such object via FID.
3503 * \param[in] sb super block for this file-system
3504 * \param[in] open_req pointer to the original open request
3506 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3508 struct mdt_body *body;
3509 struct md_op_data *op_data;
3510 struct ptlrpc_request *close_req = NULL;
3511 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3514 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3515 OBD_ALLOC_PTR(op_data);
3516 if (op_data == NULL) {
3517 CWARN("%s: cannot allocate op_data to release open handle for "
3518 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3523 op_data->op_fid1 = body->mbo_fid1;
3524 op_data->op_open_handle = body->mbo_open_handle;
3525 op_data->op_mod_time = ktime_get_real_seconds();
3526 md_close(exp, op_data, NULL, &close_req);
3527 ptlrpc_req_finished(close_req);
3528 ll_finish_md_op_data(op_data);
3533 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3534 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3535 struct lustre_md *md)
3537 struct ll_sb_info *sbi = ll_i2sbi(inode);
3538 struct ptlrpc_request *req = NULL;
3539 union lmv_mds_md *lmm = NULL;
3543 LASSERT(is_root_inode(inode));
3544 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3545 LASSERT(!md->def_lsm_obj);
3547 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3549 GET_DEFAULT_LAYOUT_ROOT);
3550 if (rc && rc != -ENODATA)
3555 rc = md_stripe_object_create(sbi->ll_md_exp, &md->def_lsm_obj,
3565 ptlrpc_req_finished(req);
3569 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3570 struct super_block *sb, struct lookup_intent *it)
3572 struct ll_sb_info *sbi = NULL;
3573 struct lustre_md md = { NULL };
3574 bool default_lmv_deleted = false;
3579 LASSERT(*inode || sb);
3580 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3581 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3582 sbi->ll_md_exp, &md);
3587 * clear default_lmv only if intent_getattr reply doesn't contain it.
3588 * but it needs to be done after iget, check this early because
3589 * ll_update_lsm_md() may change md.
3591 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3592 S_ISDIR(md.body->mbo_mode) && !md.def_lsm_obj) {
3593 if (unlikely(*inode && is_root_inode(*inode) &&
3594 !fid_is_root(&sbi->ll_root_fid))) {
3595 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3600 if (!md.def_lsm_obj)
3601 default_lmv_deleted = true;
3605 rc = ll_update_inode(*inode, &md);
3609 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3610 struct lu_fid *fid1 = &md.body->mbo_fid1;
3612 LASSERT(sb != NULL);
3615 * At this point server returns to client's same fid as client
3616 * generated for creating. So using ->fid1 is okay here.
3618 if (!fid_is_sane(fid1)) {
3619 CERROR("%s: Fid is insane "DFID"\n",
3620 sbi->ll_fsname, PFID(fid1));
3621 GOTO(out, rc = -EINVAL);
3624 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3625 if (IS_ERR(*inode)) {
3627 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3629 CERROR("new_inode -fatal: rc %d\n", rc);
3634 /* Handling piggyback layout lock.
3635 * Layout lock can be piggybacked by getattr and open request.
3636 * The lsm can be applied to inode only if it comes with a layout lock
3637 * otherwise correct layout may be overwritten, for example:
3638 * 1. proc1: mdt returns a lsm but not granting layout
3639 * 2. layout was changed by another client
3640 * 3. proc2: refresh layout and layout lock granted
3641 * 4. proc1: to apply a stale layout */
3642 if (it != NULL && it->it_lock_mode != 0) {
3643 struct lustre_handle lockh;
3644 struct ldlm_lock *lock;
3646 lockh.cookie = it->it_lock_handle;
3647 lock = ldlm_handle2lock(&lockh);
3648 LASSERT(lock != NULL);
3649 if (ldlm_has_layout(lock)) {
3650 struct cl_object_conf conf;
3652 memset(&conf, 0, sizeof(conf));
3653 conf.coc_opc = OBJECT_CONF_SET;
3654 conf.coc_inode = *inode;
3655 conf.coc_lock = lock;
3656 conf.coc_try = false;
3657 conf.u.coc_layout = md.layout;
3658 (void)ll_layout_conf(*inode, &conf);
3660 LDLM_LOCK_PUT(lock);
3663 if (default_lmv_deleted)
3664 ll_update_default_lsm_md(*inode, &md);
3666 /* we may want to apply some policy for foreign file/dir */
3667 if (ll_sbi_has_foreign_symlink(sbi)) {
3668 rc = ll_manage_foreign(*inode, &md);
3676 /* cleanup will be done if necessary */
3677 md_put_lustre_md(sbi->ll_md_exp, &md);
3679 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3680 ll_intent_drop_lock(it);
3681 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3687 int ll_obd_statfs(struct inode *inode, void __user *uarg)
3689 struct ll_sb_info *sbi = NULL;
3690 struct obd_export *exp;
3691 struct obd_ioctl_data *data = NULL;
3696 sbi = ll_i2sbi(inode);
3698 GOTO(out_statfs, rc = -EINVAL);
3700 rc = obd_ioctl_getdata(&data, &len, uarg);
3702 GOTO(out_statfs, rc);
3704 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3705 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3706 GOTO(out_statfs, rc = -EINVAL);
3708 if (data->ioc_inllen1 != sizeof(__u32) ||
3709 data->ioc_inllen2 != sizeof(__u32) ||
3710 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3711 data->ioc_plen2 != sizeof(struct obd_uuid))
3712 GOTO(out_statfs, rc = -EINVAL);
3714 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3715 if (type & LL_STATFS_LMV)
3716 exp = sbi->ll_md_exp;
3717 else if (type & LL_STATFS_LOV)
3718 exp = sbi->ll_dt_exp;
3720 GOTO(out_statfs, rc = -ENODEV);
3722 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3724 GOTO(out_statfs, rc);
3726 OBD_FREE_LARGE(data, len);
3731 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3732 * be called early to avoid deadlock.
3734 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3736 lmv_stripe_object_put(&op_data->op_lso2);
3737 lmv_stripe_object_put(&op_data->op_lso1);
3738 lmv_stripe_object_put(&op_data->op_default_lso1);
3741 /* this function prepares md_op_data hint for passing it down to MD stack. */
3742 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3743 struct inode *i1, struct inode *i2,
3744 const char *name, size_t namelen,
3745 __u32 mode, enum md_op_code opc,
3748 struct llcrypt_name fname = { 0 };
3751 LASSERT(i1 != NULL);
3754 /* Do not reuse namelen for something else. */
3756 return ERR_PTR(-EINVAL);
3758 if ((!IS_ENCRYPTED(i1) ||
3759 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3760 namelen > ll_i2sbi(i1)->ll_namelen)
3761 return ERR_PTR(-ENAMETOOLONG);
3763 /* "/" is not valid name, but it's allowed */
3764 if (!lu_name_is_valid_2(name, namelen) &&
3765 strncmp("/", name, namelen) != 0)
3766 return ERR_PTR(-EINVAL);
3769 if (op_data == NULL)
3770 OBD_ALLOC_PTR(op_data);
3772 if (op_data == NULL)
3773 return ERR_PTR(-ENOMEM);
3775 ll_i2gids(op_data->op_suppgids, i1, i2);
3776 /* If the client is using a subdir mount and looks at what it sees as
3777 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3779 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3780 !fid_is_root(ll_inode2fid(i1)) &&
3781 name && namelen == strlen(dot_fscrypt_name) &&
3782 strncmp(name, dot_fscrypt_name, namelen) == 0))
3783 lu_root_fid(&op_data->op_fid1);
3785 op_data->op_fid1 = *ll_inode2fid(i1);
3787 if (S_ISDIR(i1->i_mode)) {
3788 down_read(&ll_i2info(i1)->lli_lsm_sem);
3790 lmv_stripe_object_get(ll_i2info(i1)->lli_lsm_obj);
3791 op_data->op_default_lso1 =
3792 lmv_stripe_object_get(ll_i2info(i1)->lli_def_lsm_obj);
3793 up_read(&ll_i2info(i1)->lli_lsm_sem);
3797 op_data->op_fid2 = *ll_inode2fid(i2);
3798 if (S_ISDIR(i2->i_mode)) {
3799 down_read(&ll_i2info(i2)->lli_lsm_sem);
3801 lmv_stripe_object_get(ll_i2info(i2)->lli_lsm_obj);
3802 up_read(&ll_i2info(i2)->lli_lsm_sem);
3805 fid_zero(&op_data->op_fid2);
3808 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3809 op_data->op_cli_flags |= CLI_HASH64;
3811 if (ll_need_32bit_api(ll_i2sbi(i1)))
3812 op_data->op_cli_flags |= CLI_API32;
3814 if ((i2 && is_root_inode(i2)) ||
3815 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3816 /* In case of lookup, ll_setup_filename() has already been
3817 * called in ll_lookup_it(), so just take provided name.
3818 * Also take provided name if we are dealing with root inode.
3820 fname.disk_name.name = (unsigned char *)name;
3821 fname.disk_name.len = namelen;
3822 } else if (name && namelen) {
3823 struct qstr dname = QSTR_INIT(name, namelen);
3825 struct lu_fid *pfid = NULL;
3829 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3830 /* special case when called from ll_link() */
3835 lookup = (int)(opc == LUSTRE_OPC_ANY);
3837 if (opc == LUSTRE_OPC_ANY && lookup)
3839 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3841 ll_finish_md_op_data(op_data);
3844 if (pfid && !fid_is_zero(pfid)) {
3846 op_data->op_fid2 = fid;
3847 op_data->op_bias = MDS_FID_OP;
3849 if (fname.disk_name.name &&
3850 fname.disk_name.name != (unsigned char *)name) {
3851 /* op_data->op_name must be freed after use */
3852 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3856 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3857 * are LUSTRE_OPC_ANY
3859 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3860 op_data->op_code = LUSTRE_OPC_ANY;
3862 op_data->op_code = opc;
3863 op_data->op_name = fname.disk_name.name;
3864 op_data->op_namelen = fname.disk_name.len;
3865 op_data->op_mode = mode;
3866 op_data->op_mod_time = ktime_get_real_seconds();
3867 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3868 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3869 op_data->op_cap = current_cap();
3870 op_data->op_mds = 0;
3871 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3872 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3873 op_data->op_bias |= MDS_CREATE_VOLATILE;
3875 op_data->op_data = data;
3880 void ll_finish_md_op_data(struct md_op_data *op_data)
3882 ll_unlock_md_op_lsm(op_data);
3883 ll_security_release_secctx(op_data->op_file_secctx,
3884 op_data->op_file_secctx_size,
3885 op_data->op_file_secctx_slot);
3886 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3887 /* allocated via ll_setup_filename called
3888 * from ll_prep_md_op_data
3890 kfree(op_data->op_name);
3891 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3892 OBD_FREE_PTR(op_data);
3895 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3897 struct ll_sb_info *sbi;
3900 LASSERT(seq && dentry);
3901 sbi = ll_s2sbi(dentry->d_sb);
3903 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3904 seq_puts(seq, "nolock");
3906 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3907 /* match_table in some cases has patterns for both enabled and
3908 * disabled cases. Ignore 'no'xxx versions if bit is set.
3910 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3911 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3912 if (ll_sbi_flags_name[i].token ==
3913 LL_SBI_FOREIGN_SYMLINK) {
3914 seq_show_option(seq, "foreign_symlink",
3915 sbi->ll_foreign_symlink_prefix);
3917 seq_printf(seq, ",%s",
3918 ll_sbi_flags_name[i].pattern);
3921 /* You can have either localflock or flock but not
3922 * both. If localflock is set don't print flock or
3925 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3927 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3928 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3929 seq_printf(seq, ",%s",
3930 ll_sbi_flags_name[i].pattern);
3934 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3940 * Get obd name by cmd, and copy out to user space
3942 int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg)
3944 struct ll_sb_info *sbi = ll_i2sbi(inode);
3945 struct obd_device *obd;
3948 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3949 obd = class_exp2obd(sbi->ll_dt_exp);
3950 else if (cmd == OBD_IOC_GETMDNAME)
3951 obd = class_exp2obd(sbi->ll_md_exp);
3958 if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1))
3965 struct work_struct db_work;
3966 struct dentry *db_dentry;
3967 /* Let's hope the path is not too long, 32 bytes for the work struct
3970 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3973 static void ll_dput_later(struct work_struct *work)
3975 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3977 dput(db->db_dentry);
3978 free_page((unsigned long)db);
3981 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3988 p.mnt = current->fs->root.mnt;
3990 path = d_path(&p, buf, bufsize);
3995 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3997 struct dname_buf *db;
3999 struct dentry *dentry = NULL;
4001 /* this can be called inside spin lock so use GFP_ATOMIC. */
4002 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
4005 dentry = d_find_alias(inode);
4007 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
4010 /* The below message is checked in recovery-small.sh test_24b */
4012 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
4013 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
4014 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
4015 PFID(ll_inode2fid(inode)),
4016 (path && !IS_ERR(path)) ? path : "", ioret);
4018 if (dentry != NULL) {
4019 /* We cannot dput here since if we happen to be the last holder
4020 * then we can end up waiting for page evictions that
4021 * in turn wait for RPCs that need this instance of ptlrpcd
4022 * (callng brw_interpret->*page_completion*->vmpage_error->here)
4025 INIT_WORK(&db->db_work, ll_dput_later);
4026 db->db_dentry = dentry;
4027 schedule_work(&db->db_work);
4030 free_page((unsigned long)db);
4034 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
4035 struct lov_user_md **kbuf)
4037 struct lov_user_md lum;
4041 if (copy_from_user(&lum, md, sizeof(lum)))
4044 lum_size = ll_lov_user_md_size(&lum);
4048 OBD_ALLOC_LARGE(*kbuf, lum_size);
4052 if (copy_from_user(*kbuf, md, lum_size) != 0) {
4053 OBD_FREE_LARGE(*kbuf, lum_size);
4061 * Compute llite root squash state after a change of root squash
4062 * configuration setting or add/remove of a lnet nid
4064 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
4066 struct root_squash_info *squash = &sbi->ll_squash;
4069 struct lnet_processid id;
4071 /* Update norootsquash flag */
4072 spin_lock(&squash->rsi_lock);
4073 if (list_empty(&squash->rsi_nosquash_nids))
4074 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4076 /* Do not apply root squash as soon as one of our NIDs is
4077 * in the nosquash_nids list */
4080 while (LNetGetId(i++, &id, false) != -ENOENT) {
4081 if (nid_is_lo0(&id.nid))
4083 if (cfs_match_nid(&id.nid,
4084 &squash->rsi_nosquash_nids)) {
4090 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4092 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4094 spin_unlock(&squash->rsi_lock);
4098 * Parse linkea content to extract information about a given hardlink
4100 * \param[in] ldata - Initialized linkea data
4101 * \param[in] linkno - Link identifier
4102 * \param[out] parent_fid - The entry's parent FID
4103 * \param[out] ln - Entry name destination buffer
4105 * \retval 0 on success
4106 * \retval Appropriate negative error code on failure
4108 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
4109 struct lu_fid *parent_fid, struct lu_name *ln)
4115 rc = linkea_init_with_rec(ldata);
4119 if (linkno >= ldata->ld_leh->leh_reccount)
4120 /* beyond last link */
4123 linkea_first_entry(ldata);
4124 for (idx = 0; ldata->ld_lee != NULL; idx++) {
4125 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
4130 linkea_next_entry(ldata);
4140 * Get parent FID and name of an identified link. Operation is performed for
4141 * a given link number, letting the caller iterate over linkno to list one or
4142 * all links of an entry.
4144 * \param[in] file - File descriptor against which to perform the operation
4145 * \param[in,out] arg - User-filled structure containing the linkno to operate
4146 * on and the available size. It is eventually filled with
4147 * the requested information or left untouched on error
4149 * \retval - 0 on success
4150 * \retval - Appropriate negative error code on failure
4152 int ll_getparent(struct file *file, struct getparent __user *arg)
4154 struct inode *inode = file_inode(file);
4155 struct linkea_data *ldata;
4156 struct lu_buf buf = LU_BUF_NULL;
4158 struct lu_fid parent_fid;
4165 if (!capable(CAP_DAC_READ_SEARCH) &&
4166 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
4169 if (get_user(name_size, &arg->gp_name_size))
4172 if (get_user(linkno, &arg->gp_linkno))
4175 if (name_size > PATH_MAX)
4178 OBD_ALLOC(ldata, sizeof(*ldata));
4182 rc = linkea_data_new(ldata, &buf);
4184 GOTO(ldata_free, rc);
4186 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
4187 buf.lb_len, OBD_MD_FLXATTR);
4191 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
4195 if (ln.ln_namelen >= name_size)
4196 GOTO(lb_free, rc = -EOVERFLOW);
4198 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
4199 GOTO(lb_free, rc = -EFAULT);
4201 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
4202 GOTO(lb_free, rc = -EFAULT);
4204 if (put_user('\0', arg->gp_name + ln.ln_namelen))
4205 GOTO(lb_free, rc = -EFAULT);
4210 OBD_FREE(ldata, sizeof(*ldata));