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>
54 #ifndef HAVE_CPUS_READ_LOCK
55 #include <libcfs/linux/linux-cpu.h>
57 #include <libcfs/linux/linux-misc.h>
58 #include <uapi/linux/lustre/lustre_ioctl.h>
59 #include <lustre_ioctl_old.h>
60 #ifdef HAVE_UAPI_LINUX_MOUNT_H
61 #include <uapi/linux/mount.h>
64 #include <lustre_ha.h>
65 #include <lustre_dlm.h>
66 #include <lprocfs_status.h>
67 #include <lustre_disk.h>
68 #include <uapi/linux/lustre/lustre_param.h>
69 #include <lustre_log.h>
70 #include <cl_object.h>
71 #include <obd_cksum.h>
72 #include "llite_internal.h"
74 struct kmem_cache *ll_file_data_slab;
77 #define log2(n) ffz(~(n))
81 * If there is only one number of core visible to Lustre,
82 * async readahead will be disabled, to avoid massive over
83 * subscription, we use 1/2 of active cores as default max
84 * async readahead requests.
86 static inline unsigned int ll_get_ra_async_max_active(void)
88 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
91 static struct ll_sb_info *ll_init_sbi(struct lustre_sb_info *lsi)
93 struct ll_sb_info *sbi = NULL;
95 unsigned long lru_page_max;
103 RETURN(ERR_PTR(-ENOMEM));
105 rc = pcc_super_init(&sbi->ll_pcc_super);
109 spin_lock_init(&sbi->ll_lock);
110 mutex_init(&sbi->ll_lco.lco_lock);
111 spin_lock_init(&sbi->ll_pp_extent_lock);
112 spin_lock_init(&sbi->ll_process_lock);
114 sbi->ll_rw_stats_on = 0;
115 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
118 pages = si.totalram - si.totalhigh;
119 lru_page_max = pages / 2;
121 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
122 sbi->ll_ra_info.ll_readahead_wq =
123 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
125 sbi->ll_ra_info.ra_async_max_active);
126 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
127 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
129 /* initialize ll_cache data */
130 sbi->ll_cache = cl_cache_init(lru_page_max);
131 if (sbi->ll_cache == NULL)
132 GOTO(out_destroy_ra, rc = -ENOMEM);
134 /* initialize foreign symlink prefix path */
135 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
136 if (sbi->ll_foreign_symlink_prefix == NULL)
137 GOTO(out_destroy_ra, rc = -ENOMEM);
138 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
139 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
141 /* initialize foreign symlink upcall path, none by default */
142 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
143 if (sbi->ll_foreign_symlink_upcall == NULL)
144 GOTO(out_destroy_ra, rc = -ENOMEM);
145 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
146 sbi->ll_foreign_symlink_upcall_items = NULL;
147 sbi->ll_foreign_symlink_upcall_nb_items = 0;
148 init_rwsem(&sbi->ll_foreign_symlink_sem);
149 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
150 * not enabled by default
153 sbi->ll_secctx_name = NULL;
154 sbi->ll_secctx_name_size = 0;
156 sbi->ll_ra_info.ra_max_pages =
157 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
158 sbi->ll_ra_info.ra_max_pages_per_file =
159 min(sbi->ll_ra_info.ra_max_pages / 4,
160 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
161 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
162 sbi->ll_ra_info.ra_max_pages_per_file;
163 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
164 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
165 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
167 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
168 #ifdef CONFIG_ENABLE_CHECKSUM
169 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
171 #ifdef CONFIG_ENABLE_FLOCK
172 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
175 #ifdef HAVE_LRU_RESIZE_SUPPORT
176 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
178 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
180 /* metadata statahead is enabled by default */
181 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
182 sbi->ll_sa_batch_max = LL_SA_BATCH_DEF;
183 sbi->ll_sa_max = LL_SA_RPC_DEF;
184 atomic_set(&sbi->ll_sa_total, 0);
185 atomic_set(&sbi->ll_sa_wrong, 0);
186 atomic_set(&sbi->ll_sa_running, 0);
187 atomic_set(&sbi->ll_agl_total, 0);
188 atomic_set(&sbi->ll_sa_hit_total, 0);
189 atomic_set(&sbi->ll_sa_miss_total, 0);
190 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
191 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
192 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
193 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
194 ll_sbi_set_encrypt(sbi, true);
195 ll_sbi_set_name_encrypt(sbi, true);
198 sbi->ll_squash.rsi_uid = 0;
199 sbi->ll_squash.rsi_gid = 0;
200 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
201 spin_lock_init(&sbi->ll_squash.rsi_lock);
203 /* Per-filesystem file heat */
204 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
205 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
207 /* Per-fs open heat level before requesting open lock */
208 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
209 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
210 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
213 if (sbi->ll_foreign_symlink_prefix)
214 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
216 cl_cache_decref(sbi->ll_cache);
217 sbi->ll_cache = NULL;
219 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
221 pcc_super_fini(&sbi->ll_pcc_super);
227 static void ll_free_sbi(struct super_block *sb)
229 struct ll_sb_info *sbi = ll_s2sbi(sb);
233 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
234 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
235 if (sbi->ll_ra_info.ll_readahead_wq)
236 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
237 if (sbi->ll_cache != NULL) {
238 cl_cache_decref(sbi->ll_cache);
239 sbi->ll_cache = NULL;
241 if (sbi->ll_foreign_symlink_prefix) {
242 OBD_FREE(sbi->ll_foreign_symlink_prefix,
243 sbi->ll_foreign_symlink_prefix_size);
244 sbi->ll_foreign_symlink_prefix = NULL;
246 if (sbi->ll_foreign_symlink_upcall) {
247 OBD_FREE(sbi->ll_foreign_symlink_upcall,
248 strlen(sbi->ll_foreign_symlink_upcall) +
250 sbi->ll_foreign_symlink_upcall = NULL;
252 if (sbi->ll_foreign_symlink_upcall_items) {
254 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
255 struct ll_foreign_symlink_upcall_item *items =
256 sbi->ll_foreign_symlink_upcall_items;
258 for (i = 0 ; i < nb_items; i++)
259 if (items[i].type == STRING_TYPE)
260 OBD_FREE(items[i].string,
263 OBD_FREE_LARGE(items, nb_items *
264 sizeof(struct ll_foreign_symlink_upcall_item));
265 sbi->ll_foreign_symlink_upcall_items = NULL;
267 if (sbi->ll_secctx_name)
268 ll_secctx_name_free(sbi);
270 ll_free_rw_stats_info(sbi);
271 pcc_super_fini(&sbi->ll_pcc_super);
272 OBD_FREE(sbi, sizeof(*sbi));
277 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
279 struct inode *root = NULL;
280 struct ll_sb_info *sbi = ll_s2sbi(sb);
281 struct obd_statfs *osfs = NULL;
282 struct ptlrpc_request *request = NULL;
283 struct obd_connect_data *data = NULL;
284 struct obd_uuid *uuid;
285 struct md_op_data *op_data;
286 struct lustre_md lmd;
288 int size, err, checksum;
294 sbi->ll_md_obd = class_name2obd(md);
295 if (!sbi->ll_md_obd) {
296 CERROR("MD %s: not setup or attached\n", md);
310 /* pass client page size via ocd_grant_blkbits, the server should report
311 * back its backend blocksize for grant calculation purpose */
312 data->ocd_grant_blkbits = PAGE_SHIFT;
314 /* indicate MDT features supported by this client */
315 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
316 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
317 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
318 OBD_CONNECT_SRVLOCK |
319 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
320 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
321 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
322 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
323 OBD_CONNECT_64BITHASH |
324 OBD_CONNECT_EINPROGRESS |
325 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
326 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
327 OBD_CONNECT_MAX_EASIZE |
328 OBD_CONNECT_FLOCK_DEAD |
329 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
330 OBD_CONNECT_OPEN_BY_FID |
331 OBD_CONNECT_DIR_STRIPE |
332 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
333 OBD_CONNECT_SUBTREE |
334 OBD_CONNECT_MULTIMODRPCS |
335 OBD_CONNECT_GRANT_PARAM |
336 OBD_CONNECT_GRANT_SHRINK |
337 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
339 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
340 OBD_CONNECT2_SUM_STATFS |
341 OBD_CONNECT2_OVERSTRIPING |
343 OBD_CONNECT2_LOCK_CONVERT |
344 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
345 OBD_CONNECT2_INC_XID |
347 OBD_CONNECT2_ASYNC_DISCARD |
349 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
350 OBD_CONNECT2_GETATTR_PFID |
351 OBD_CONNECT2_DOM_LVB |
352 OBD_CONNECT2_REP_MBITS |
353 OBD_CONNECT2_ATOMIC_OPEN_LOCK |
354 OBD_CONNECT2_BATCH_RPC |
355 OBD_CONNECT2_DMV_IMP_INHERIT;
357 #ifdef HAVE_LRU_RESIZE_SUPPORT
358 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
359 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
361 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
363 data->ocd_cksum_types = obd_cksum_types_supported_client();
365 if (CFS_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
366 /* flag mdc connection as lightweight, only used for test
367 * purpose, use with care */
368 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
370 data->ocd_ibits_known = MDS_INODELOCK_FULL;
371 data->ocd_version = LUSTRE_VERSION_CODE;
373 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
374 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
377 /* Setting this indicates we correctly support S_NOSEC (See kernel
378 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
380 sb->s_flags |= SB_NOSEC;
382 sbi->ll_fop = ll_select_file_operations(sbi);
384 /* always ping even if server suppress_pings */
385 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
386 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
388 obd_connect_set_secctx(data);
389 if (ll_sbi_has_encrypt(sbi)) {
390 obd_connect_set_enc_fid2path(data);
391 obd_connect_set_name_enc(data);
392 obd_connect_set_enc(data);
395 #if defined(CONFIG_SECURITY)
396 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
399 data->ocd_brw_size = MD_MAX_BRW_SIZE;
402 if (sb->s_flags & SB_RDONLY)
403 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
404 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
405 &sbi->ll_sb_uuid, data, sbi->ll_cache);
407 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
408 "recovery, of which this client is not a "
409 "part. Please wait for recovery to complete,"
410 " abort, or time out.\n", md);
413 CERROR("cannot connect to %s: rc = %d\n", md, err);
417 sbi->ll_md_exp->exp_connect_data = *data;
419 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
420 LUSTRE_SEQ_METADATA);
422 CERROR("%s: Can't init metadata layer FID infrastructure, "
423 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
427 /* For mount, we only need fs info from MDT0, and also in DNE, it
428 * can make sure the client can be mounted as long as MDT0 is
430 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
431 ktime_get_seconds() - sbi->ll_statfs_max_age,
432 OBD_STATFS_FOR_MDT0);
433 if (err == -EROFS && !(sb->s_flags & SB_RDONLY)) {
434 /* We got -EROFS from the server, maybe it is imposing
435 * read-only mount. So just retry like this.
437 cfs_tty_write_msg("Forcing read-only mount.\n\r");
438 CERROR("%s: mount failed with %d, forcing read-only mount.\n",
439 sbi->ll_md_exp->exp_obd->obd_name, err);
440 sb->s_flags |= SB_RDONLY;
441 obd_fid_fini(sbi->ll_md_exp->exp_obd);
442 obd_disconnect(sbi->ll_md_exp);
443 GOTO(retry_connect, err);
445 GOTO(out_md_fid, err);
448 /* This needs to be after statfs to ensure connect has finished.
449 * Note that "data" does NOT contain the valid connect reply.
450 * If connecting to a 1.8 server there will be no LMV device, so
451 * we can access the MDC export directly and exp_connect_flags will
452 * be non-zero, but if accessing an upgraded 2.1 server it will
453 * have the correct flags filled in.
454 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
455 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
456 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
457 valid != CLIENT_CONNECT_MDT_REQD) {
460 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
461 obd_connect_flags2str(buf, PAGE_SIZE,
462 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
463 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
464 "feature(s) needed for correct operation "
465 "of this client (%s). Please upgrade "
466 "server or downgrade client.\n",
467 sbi->ll_md_exp->exp_obd->obd_name, buf);
468 OBD_FREE(buf, PAGE_SIZE);
469 GOTO(out_md_fid, err = -EPROTO);
472 size = sizeof(*data);
473 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
474 KEY_CONN_DATA, &size, data);
476 CERROR("%s: Get connect data failed: rc = %d\n",
477 sbi->ll_md_exp->exp_obd->obd_name, err);
478 GOTO(out_md_fid, err);
481 LASSERT(osfs->os_bsize);
482 sb->s_blocksize = osfs->os_bsize;
483 sb->s_blocksize_bits = log2(osfs->os_bsize);
484 sb->s_magic = LL_SUPER_MAGIC;
485 sb->s_maxbytes = MAX_LFS_FILESIZE;
486 sbi->ll_inode_cache_enabled = 1;
487 sbi->ll_namelen = osfs->os_namelen;
488 sbi->ll_mnt.mnt = current->fs->root.mnt;
489 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
491 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
492 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
493 LCONSOLE_INFO("Disabling user_xattr feature because "
494 "it is not supported on the server\n");
495 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
498 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
500 sb->s_flags |= SB_POSIXACL;
502 set_bit(LL_SBI_ACL, sbi->ll_flags);
504 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
506 sb->s_flags &= ~SB_POSIXACL;
508 clear_bit(LL_SBI_ACL, sbi->ll_flags);
511 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
512 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
514 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
515 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
517 if (obd_connect_has_secctx(data))
518 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
520 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
521 if (ll_sb_has_test_dummy_encryption(sb))
522 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
524 sbi->ll_md_exp->exp_obd->obd_name);
525 ll_sbi_set_encrypt(sbi, false);
528 if (ll_sbi_has_name_encrypt(sbi) && !obd_connect_has_name_enc(data)) {
529 struct lustre_sb_info *lsi = s2lsi(sb);
531 if (ll_sb_has_test_dummy_encryption(sb))
532 LCONSOLE_WARN("%s: server %s does not support name encryption, not using it.\n",
534 sbi->ll_md_exp->exp_obd->obd_name);
535 #ifdef CONFIG_LL_ENCRYPTION
536 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
538 lsi->lsi_flags &= ~LSI_FILENAME_ENC_B64_OLD_CLI;
539 ll_sbi_set_name_encrypt(sbi, false);
542 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
543 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
544 LCONSOLE_INFO("%s: disabling xattr cache due to "
545 "unknown maximum xattr size.\n", dt);
546 } else if (!sbi->ll_xattr_cache_set) {
547 /* If xattr_cache is already set (no matter 0 or 1)
548 * during processing llog, it won't be enabled here. */
549 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
550 sbi->ll_xattr_cache_enabled = 1;
554 sbi->ll_dt_obd = class_name2obd(dt);
555 if (!sbi->ll_dt_obd) {
556 CERROR("DT %s: not setup or attached\n", dt);
557 GOTO(out_md_fid, err = -ENODEV);
560 /* pass client page size via ocd_grant_blkbits, the server should report
561 * back its backend blocksize for grant calculation purpose */
562 data->ocd_grant_blkbits = PAGE_SHIFT;
564 /* indicate OST features supported by this client */
565 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
566 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
567 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
568 OBD_CONNECT_SRVLOCK |
569 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
570 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
571 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
572 OBD_CONNECT_EINPROGRESS |
573 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
574 OBD_CONNECT_LAYOUTLOCK |
575 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
576 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
577 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
578 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
579 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
580 OBD_CONNECT2_REP_MBITS;
582 if (!CFS_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
583 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
585 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
586 * disabled by default, because it can still be enabled on the
587 * fly via /sys. As a consequence, we still need to come to an
588 * agreement on the supported algorithms at connect time
590 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
592 if (CFS_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
593 data->ocd_cksum_types = OBD_CKSUM_ADLER;
595 data->ocd_cksum_types = obd_cksum_types_supported_client();
597 #ifdef HAVE_LRU_RESIZE_SUPPORT
598 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
600 /* always ping even if server suppress_pings */
601 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
602 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
604 if (ll_sbi_has_encrypt(sbi))
605 obd_connect_set_enc(data);
607 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
608 "ocd_grant: %d\n", data->ocd_connect_flags,
609 data->ocd_version, data->ocd_grant);
611 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
612 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
614 data->ocd_brw_size = DT_MAX_BRW_SIZE;
616 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
617 &sbi->ll_sb_uuid, data, sbi->ll_cache);
619 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
620 "recovery, of which this client is not a "
621 "part. Please wait for recovery to "
622 "complete, abort, or time out.\n", dt);
625 CERROR("%s: Cannot connect to %s: rc = %d\n",
626 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
630 if (ll_sbi_has_encrypt(sbi) &&
631 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
632 if (ll_sb_has_test_dummy_encryption(sb))
633 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
635 ll_sbi_set_encrypt(sbi, false);
636 } else if (ll_sb_has_test_dummy_encryption(sb)) {
637 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
640 sbi->ll_dt_exp->exp_connect_data = *data;
642 /* Don't change value if it was specified in the config log */
643 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
644 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
645 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
646 (data->ocd_brw_size >> PAGE_SHIFT));
647 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
648 sbi->ll_ra_info.ra_max_pages_per_file)
649 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
650 sbi->ll_ra_info.ra_max_pages_per_file;
653 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
654 LUSTRE_SEQ_METADATA);
656 CERROR("%s: Can't init data layer FID infrastructure, "
657 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
661 mutex_lock(&sbi->ll_lco.lco_lock);
662 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
663 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
664 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
665 mutex_unlock(&sbi->ll_lco.lco_lock);
667 fid_zero(&sbi->ll_root_fid);
668 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
671 CERROR("cannot mds_connect: rc = %d\n", err);
672 GOTO(out_lock_cn_cb, err);
674 if (!fid_is_sane(&sbi->ll_root_fid)) {
675 CERROR("%s: Invalid root fid "DFID" during mount\n",
676 sbi->ll_md_exp->exp_obd->obd_name,
677 PFID(&sbi->ll_root_fid));
678 GOTO(out_lock_cn_cb, err = -EINVAL);
680 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
682 sb->s_op = &lustre_super_operations;
683 sb->s_xattr = ll_xattr_handlers;
684 #if THREAD_SIZE >= 8192 /*b=17630*/
685 sb->s_export_op = &lustre_export_operations;
687 #ifdef HAVE_LUSTRE_CRYPTO
688 llcrypt_set_ops(sb, &lustre_cryptops);
692 * XXX: move this to after cbd setup? */
693 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
695 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
696 valid |= OBD_MD_FLACL;
698 OBD_ALLOC_PTR(op_data);
700 GOTO(out_lock_cn_cb, err = -ENOMEM);
702 op_data->op_fid1 = sbi->ll_root_fid;
703 op_data->op_mode = 0;
704 op_data->op_valid = valid;
706 err = md_getattr(sbi->ll_md_exp, op_data, &request);
708 /* We need enc ctx info, so reset it in op_data to
709 * prevent it from being freed.
711 encctx = op_data->op_file_encctx;
712 encctxlen = op_data->op_file_encctx_size;
713 op_data->op_file_encctx = NULL;
714 op_data->op_file_encctx_size = 0;
715 OBD_FREE_PTR(op_data);
717 CERROR("%s: md_getattr failed for root: rc = %d\n",
718 sbi->ll_md_exp->exp_obd->obd_name, err);
719 GOTO(out_lock_cn_cb, err);
722 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
723 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
725 CERROR("failed to understand root inode md: rc = %d\n", err);
726 ptlrpc_req_finished(request);
727 GOTO(out_lock_cn_cb, err);
730 LASSERT(fid_is_sane(&sbi->ll_root_fid));
731 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
732 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
733 md_free_lustre_md(sbi->ll_md_exp, &lmd);
737 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
739 CERROR("%s: bad ll_iget() for root: rc = %d\n",
740 sbi->ll_fsname, err);
741 ptlrpc_req_finished(request);
745 err = ll_secctx_name_store(root);
746 if (err < 0 && ll_security_xattr_wanted(root))
747 CWARN("%s: file security contextes not supported: rc = %d\n",
748 sbi->ll_fsname, err);
753 "server returned encryption ctx for root inode "DFID"\n",
754 PFID(&sbi->ll_root_fid));
755 err = ll_set_encflags(root, encctx, encctxlen, true);
757 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
759 PFID(&sbi->ll_root_fid), err);
761 ptlrpc_req_finished(request);
763 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
764 if (sbi->ll_checksum_set) {
765 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
766 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
767 sizeof(checksum), &checksum, NULL);
769 CERROR("%s: Set checksum failed: rc = %d\n",
770 sbi->ll_dt_exp->exp_obd->obd_name, err);
776 sb->s_root = d_make_root(root);
777 if (sb->s_root == NULL) {
779 CERROR("%s: can't make root dentry: rc = %d\n",
780 sbi->ll_fsname, err);
784 sbi->ll_sdev_orig = sb->s_dev;
786 /* We set sb->s_dev equal on all lustre clients in order to support
787 * NFS export clustering. NFSD requires that the FSID be the same
789 /* s_dev is also used in lt_compare() to compare two fs, but that is
790 * only a node-local comparison. */
791 uuid = obd_get_uuid(sbi->ll_md_exp);
793 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
800 if (sbi->ll_dt_obd) {
801 err = sysfs_create_link(&sbi->ll_kset.kobj,
802 &sbi->ll_dt_obd->obd_kset.kobj,
803 sbi->ll_dt_obd->obd_type->typ_name);
805 CERROR("%s: could not register %s in llite: rc = %d\n",
806 dt, sbi->ll_fsname, err);
811 if (sbi->ll_md_obd) {
812 err = sysfs_create_link(&sbi->ll_kset.kobj,
813 &sbi->ll_md_obd->obd_kset.kobj,
814 sbi->ll_md_obd->obd_type->typ_name);
816 CERROR("%s: could not register %s in llite: rc = %d\n",
817 md, sbi->ll_fsname, err);
826 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
828 obd_disconnect(sbi->ll_dt_exp);
829 sbi->ll_dt_exp = NULL;
830 sbi->ll_dt_obd = NULL;
832 obd_fid_fini(sbi->ll_md_exp->exp_obd);
834 obd_disconnect(sbi->ll_md_exp);
835 sbi->ll_md_exp = NULL;
836 sbi->ll_md_obd = NULL;
845 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
849 size = sizeof(*lmmsize);
850 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
851 KEY_MAX_EASIZE, &size, lmmsize);
853 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
854 sbi->ll_dt_exp->exp_obd->obd_name, rc);
858 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
861 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
862 KEY_MAX_EASIZE, &size, lmmsize);
864 CERROR("Get max mdsize error rc %d\n", rc);
866 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
872 * Get the value of the default_easize parameter.
874 * \see client_obd::cl_default_mds_easize
876 * \param[in] sbi superblock info for this filesystem
877 * \param[out] lmmsize pointer to storage location for value
879 * \retval 0 on success
880 * \retval negative negated errno on failure
882 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
887 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
888 KEY_DEFAULT_EASIZE, &size, lmmsize);
890 CERROR("Get default mdsize error rc %d\n", rc);
896 * Set the default_easize parameter to the given value.
898 * \see client_obd::cl_default_mds_easize
900 * \param[in] sbi superblock info for this filesystem
901 * \param[in] lmmsize the size to set
903 * \retval 0 on success
904 * \retval negative negated errno on failure
906 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
910 if (lmmsize < sizeof(struct lov_mds_md) ||
911 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
914 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
915 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
916 sizeof(int), &lmmsize, NULL);
921 static void client_common_put_super(struct super_block *sb)
923 struct ll_sb_info *sbi = ll_s2sbi(sb);
928 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
929 obd_disconnect(sbi->ll_dt_exp);
930 sbi->ll_dt_exp = NULL;
932 ll_debugfs_unregister_super(sb);
934 obd_fid_fini(sbi->ll_md_exp->exp_obd);
935 obd_disconnect(sbi->ll_md_exp);
936 sbi->ll_md_exp = NULL;
941 void ll_kill_super(struct super_block *sb)
943 struct ll_sb_info *sbi;
947 if (!(sb->s_flags & SB_ACTIVE))
951 /* we need restore s_dev from changed for clustred NFS before put_super
952 * because new kernels have cached s_dev and change sb->s_dev in
953 * put_super not affected real removing devices */
955 sb->s_dev = sbi->ll_sdev_orig;
957 /* wait running statahead threads to quit */
958 while (atomic_read(&sbi->ll_sa_running) > 0)
959 schedule_timeout_uninterruptible(
960 cfs_time_seconds(1) >> 3);
966 /* Since we use this table for ll_sbi_flags_seq_show make
967 * sure what you want displayed for a specific token that
968 * is listed more than once below be listed first. For
969 * example we want "checksum" displayed, not "nochecksum"
972 static const match_table_t ll_sbi_flags_name = {
973 {LL_SBI_NOLCK, "nolock"},
974 {LL_SBI_CHECKSUM, "checksum"},
975 {LL_SBI_CHECKSUM, "nochecksum"},
976 {LL_SBI_LOCALFLOCK, "localflock"},
977 {LL_SBI_FLOCK, "flock"},
978 {LL_SBI_FLOCK, "noflock"},
979 {LL_SBI_USER_XATTR, "user_xattr"},
980 {LL_SBI_USER_XATTR, "nouser_xattr"},
981 {LL_SBI_LRU_RESIZE, "lruresize"},
982 {LL_SBI_LRU_RESIZE, "nolruresize"},
983 {LL_SBI_LAZYSTATFS, "lazystatfs"},
984 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
985 {LL_SBI_32BIT_API, "32bitapi"},
986 {LL_SBI_USER_FID2PATH, "user_fid2path"},
987 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
988 {LL_SBI_VERBOSE, "verbose"},
989 {LL_SBI_VERBOSE, "noverbose"},
990 {LL_SBI_ALWAYS_PING, "always_ping"},
991 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
992 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
993 {LL_SBI_ENCRYPT, "encrypt"},
994 {LL_SBI_ENCRYPT, "noencrypt"},
995 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
996 {LL_SBI_NUM_MOUNT_OPT, NULL},
999 {LL_SBI_AGL_ENABLED, "agl"},
1000 {LL_SBI_64BIT_HASH, "64bit_hash"},
1001 {LL_SBI_LAYOUT_LOCK, "layout"},
1002 {LL_SBI_XATTR_CACHE, "xattr_cache"},
1003 {LL_SBI_NOROOTSQUASH, "norootsquash"},
1004 {LL_SBI_FAST_READ, "fast_read"},
1005 {LL_SBI_FILE_SECCTX, "file_secctx"},
1006 {LL_SBI_TINY_WRITE, "tiny_write"},
1007 {LL_SBI_FILE_HEAT, "file_heat"},
1008 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
1009 {LL_SBI_ENCRYPT_NAME, "name_encrypt"},
1012 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
1014 struct super_block *sb = m->private;
1017 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
1020 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
1023 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
1024 if (ll_sbi_flags_name[j].token == i &&
1025 ll_sbi_flags_name[j].pattern) {
1026 seq_printf(m, "%s ",
1027 ll_sbi_flags_name[j].pattern);
1032 seq_puts(m, "\b\n");
1036 /* non-client-specific mount options are parsed in lmd_parse */
1037 static int ll_options(char *options, struct super_block *sb)
1039 struct ll_sb_info *sbi = ll_s2sbi(sb);
1040 char *s2, *s1, *opts;
1047 /* Don't stomp on lmd_opts */
1048 opts = kstrdup(options, GFP_KERNEL);
1054 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1056 while ((s1 = strsep(&opts, ",")) != NULL) {
1057 substring_t args[MAX_OPT_ARGS];
1058 bool turn_off = false;
1064 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1066 if (strncmp(s1, "no", 2) == 0)
1070 * Initialize args struct so we know whether arg was
1071 * found; some options take optional arguments.
1074 args[0].from = NULL;
1075 token = match_token(s1, ll_sbi_flags_name, args);
1076 if (token == LL_SBI_NUM_MOUNT_OPT) {
1077 if (match_wildcard("context", s1) ||
1078 match_wildcard("fscontext", s1) ||
1079 match_wildcard("defcontext", s1) ||
1080 match_wildcard("rootcontext",s1))
1083 LCONSOLE_ERROR_MSG(0x152,
1084 "Unknown option '%s', won't mount.\n",
1091 case LL_SBI_32BIT_API:
1092 case LL_SBI_64BIT_HASH:
1093 case LL_SBI_ALWAYS_PING:
1094 set_bit(token, sbi->ll_flags);
1098 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1100 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1102 set_bit(token, sbi->ll_flags);
1105 case LL_SBI_LOCALFLOCK:
1106 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1107 set_bit(token, sbi->ll_flags);
1110 case LL_SBI_CHECKSUM:
1111 sbi->ll_checksum_set = 1;
1113 case LL_SBI_USER_XATTR:
1114 case LL_SBI_USER_FID2PATH:
1115 case LL_SBI_LRU_RESIZE:
1116 case LL_SBI_LAZYSTATFS:
1117 case LL_SBI_VERBOSE:
1119 clear_bit(token, sbi->ll_flags);
1121 set_bit(token, sbi->ll_flags);
1123 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1124 #ifdef HAVE_LUSTRE_CRYPTO
1125 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1126 set_bit(token, sbi->ll_flags);
1128 struct lustre_sb_info *lsi = s2lsi(sb);
1130 err = llcrypt_set_test_dummy_encryption(sb,
1131 #ifdef HAVE_FSCRYPT_SET_TEST_DUMMY_ENC_CHAR_ARG
1136 &lsi->lsi_dummy_enc_policy);
1142 "Can't change test_dummy_encryption");
1143 else if (err == -EINVAL)
1145 "Value of option \"%s\" unrecognized",
1149 "Error processing option \"%s\" [%d]",
1154 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1158 case LL_SBI_ENCRYPT:
1159 #ifdef HAVE_LUSTRE_CRYPTO
1161 clear_bit(token, sbi->ll_flags);
1163 set_bit(token, sbi->ll_flags);
1165 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1168 case LL_SBI_FOREIGN_SYMLINK:
1169 /* non-default prefix provided ? */
1174 /* path must be absolute */
1175 if (args->from[0] != '/') {
1176 LCONSOLE_ERROR_MSG(0x152,
1177 "foreign prefix '%s' must be an absolute path\n",
1182 old_len = sbi->ll_foreign_symlink_prefix_size;
1183 old = sbi->ll_foreign_symlink_prefix;
1184 /* alloc for path length and '\0' */
1185 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1186 if (!sbi->ll_foreign_symlink_prefix) {
1187 /* restore previous */
1188 sbi->ll_foreign_symlink_prefix = old;
1189 sbi->ll_foreign_symlink_prefix_size =
1193 sbi->ll_foreign_symlink_prefix_size =
1194 args->to - args->from + 1;
1195 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1196 sbi->ll_foreign_symlink_prefix_size,
1199 OBD_FREE(old, old_len);
1201 /* enable foreign symlink support */
1202 set_bit(token, sbi->ll_flags);
1204 LCONSOLE_ERROR_MSG(0x152,
1205 "invalid %s option\n", s1);
1216 void ll_lli_init(struct ll_inode_info *lli)
1218 lli->lli_inode_magic = LLI_INODE_MAGIC;
1220 rwlock_init(&lli->lli_lock);
1221 lli->lli_posix_acl = NULL;
1222 /* Do not set lli_fid, it has been initialized already. */
1223 fid_zero(&lli->lli_pfid);
1224 lli->lli_mds_read_och = NULL;
1225 lli->lli_mds_write_och = NULL;
1226 lli->lli_mds_exec_och = NULL;
1227 lli->lli_open_fd_read_count = 0;
1228 lli->lli_open_fd_write_count = 0;
1229 lli->lli_open_fd_exec_count = 0;
1230 mutex_init(&lli->lli_och_mutex);
1231 spin_lock_init(&lli->lli_agl_lock);
1232 spin_lock_init(&lli->lli_layout_lock);
1233 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1234 lli->lli_clob = NULL;
1236 init_rwsem(&lli->lli_xattrs_list_rwsem);
1237 mutex_init(&lli->lli_xattrs_enq_lock);
1239 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1240 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1241 lli->lli_opendir_key = NULL;
1242 lli->lli_sai = NULL;
1243 spin_lock_init(&lli->lli_sa_lock);
1244 lli->lli_opendir_pid = 0;
1245 lli->lli_sa_enabled = 0;
1246 init_rwsem(&lli->lli_lsm_sem);
1248 mutex_init(&lli->lli_size_mutex);
1249 mutex_init(&lli->lli_setattr_mutex);
1250 lli->lli_symlink_name = NULL;
1251 ll_trunc_sem_init(&lli->lli_trunc_sem);
1252 range_lock_tree_init(&lli->lli_write_tree);
1253 init_rwsem(&lli->lli_glimpse_sem);
1254 lli->lli_glimpse_time = ktime_set(0, 0);
1255 INIT_LIST_HEAD(&lli->lli_agl_list);
1256 lli->lli_agl_index = 0;
1257 lli->lli_async_rc = 0;
1258 spin_lock_init(&lli->lli_heat_lock);
1259 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1260 lli->lli_heat_flags = 0;
1261 mutex_init(&lli->lli_pcc_lock);
1262 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1263 lli->lli_pcc_inode = NULL;
1264 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1265 lli->lli_pcc_generation = 0;
1266 mutex_init(&lli->lli_group_mutex);
1267 lli->lli_group_users = 0;
1268 lli->lli_group_gid = 0;
1269 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1270 lli->lli_uid = (__u32) -1;
1271 lli->lli_gid = (__u32) -1;
1273 mutex_init(&lli->lli_layout_mutex);
1274 /* ll_cl_context initialize */
1275 INIT_LIST_HEAD(&lli->lli_lccs);
1276 seqlock_init(&lli->lli_page_inv_lock);
1279 #define MAX_STRING_SIZE 128
1281 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1282 #ifndef HAVE_BDI_CAP_MAP_COPY
1283 # define BDI_CAP_MAP_COPY 0
1286 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1288 struct lustre_sb_info *lsi = s2lsi(sb);
1289 char buf[MAX_STRING_SIZE];
1293 err = bdi_init(&lsi->lsi_bdi);
1297 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1298 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1299 lsi->lsi_bdi.name = "lustre";
1300 va_start(args, fmt);
1301 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1303 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1306 sb->s_bdi = &lsi->lsi_bdi;
1310 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1312 int ll_fill_super(struct super_block *sb)
1314 struct lustre_profile *lprof = NULL;
1315 struct lustre_sb_info *lsi = s2lsi(sb);
1316 struct ll_sb_info *sbi = NULL;
1317 char *dt = NULL, *md = NULL;
1318 char *profilenm = get_profile_name(sb);
1319 struct config_llog_instance *cfg;
1320 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1321 const int instlen = LUSTRE_MAXINSTANCE + 2;
1322 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1323 char name[MAX_STRING_SIZE];
1332 /* for ASLR, to map between cfg_instance and hashed ptr */
1333 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1334 profilenm, cfg_instance, sb);
1336 CFS_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1340 GOTO(out_free_cfg, err = -ENOMEM);
1342 /* client additional sb info */
1343 lsi->lsi_llsbi = sbi = ll_init_sbi(lsi);
1345 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1347 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1349 GOTO(out_free_cfg, err);
1351 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1352 #ifdef CONFIG_LL_ENCRYPTION
1353 if (ll_sb_has_test_dummy_encryption(sb))
1354 /* enable filename encryption by default for dummy enc mode */
1355 lsi->lsi_flags |= LSI_FILENAME_ENC;
1357 /* filename encryption is disabled by default */
1358 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1361 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1362 sb->s_d_op = &ll_d_ops;
1365 generate_random_uuid(uuid.b);
1366 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1368 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1371 len = strlen(profilenm);
1372 ptr = strrchr(profilenm, '-');
1373 if (ptr && (strcmp(ptr, "-client") == 0))
1376 if (len > LUSTRE_MAXFSNAME) {
1377 if (unlikely(len >= MAX_STRING_SIZE))
1378 len = MAX_STRING_SIZE - 1;
1379 strncpy(name, profilenm, len);
1381 err = -ENAMETOOLONG;
1382 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1383 name, LUSTRE_MAXFSNAME, err);
1384 GOTO(out_free_cfg, err);
1386 strncpy(sbi->ll_fsname, profilenm, len);
1387 sbi->ll_fsname[len] = '\0';
1390 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1391 profilenm, cfg_instance);
1393 err = super_setup_bdi_name(sb, "%s", name);
1395 GOTO(out_free_cfg, err);
1397 /* disable kernel readahead */
1398 sb->s_bdi->ra_pages = 0;
1399 #ifdef HAVE_BDI_IO_PAGES
1400 sb->s_bdi->io_pages = 0;
1403 /* Call ll_debugfs_register_super() before lustre_process_log()
1404 * so that "llite.*.*" params can be processed correctly.
1406 err = ll_debugfs_register_super(sb, name);
1408 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1409 sbi->ll_fsname, err);
1413 /* The cfg_instance is a value unique to this super, in case some
1414 * joker tries to mount the same fs at two mount points.
1416 cfg->cfg_instance = cfg_instance;
1417 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1418 cfg->cfg_callback = class_config_llog_handler;
1419 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1420 /* set up client obds */
1421 err = lustre_process_log(sb, profilenm, cfg);
1423 GOTO(out_debugfs, err);
1425 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1426 lprof = class_get_profile(profilenm);
1427 if (lprof == NULL) {
1428 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1429 " read from the MGS. Does that filesystem "
1430 "exist?\n", profilenm);
1431 GOTO(out_debugfs, err = -EINVAL);
1433 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1434 lprof->lp_md, lprof->lp_dt);
1436 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1437 OBD_ALLOC(dt, dt_len);
1439 GOTO(out_profile, err = -ENOMEM);
1440 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1442 md_len = strlen(lprof->lp_md) + instlen + 2;
1443 OBD_ALLOC(md, md_len);
1445 GOTO(out_free_dt, err = -ENOMEM);
1446 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1448 /* connections, registrations, sb setup */
1449 err = client_common_fill_super(sb, md, dt);
1451 GOTO(out_free_md, err);
1453 sbi->ll_client_common_fill_super_succeeded = 1;
1457 OBD_FREE(md, md_len);
1460 OBD_FREE(dt, dt_len);
1463 class_put_profile(lprof);
1466 ll_debugfs_unregister_super(sb);
1473 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1474 LCONSOLE_WARN("Mounted %s%s\n", profilenm,
1475 sb->s_flags & SB_RDONLY ? " read-only" : "");
1477 } /* ll_fill_super */
1479 void ll_put_super(struct super_block *sb)
1481 struct config_llog_instance cfg, params_cfg;
1482 struct obd_device *obd;
1483 struct lustre_sb_info *lsi = s2lsi(sb);
1484 struct ll_sb_info *sbi = ll_s2sbi(sb);
1485 char *profilenm = get_profile_name(sb);
1486 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1488 int next, force = 1, rc = 0;
1492 GOTO(out_no_sbi, 0);
1494 /* Should replace instance_id with something better for ASLR */
1495 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1496 profilenm, cfg_instance, sb);
1498 cfg.cfg_instance = cfg_instance;
1499 lustre_end_log(sb, profilenm, &cfg);
1501 params_cfg.cfg_instance = cfg_instance;
1502 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1504 if (sbi->ll_md_exp) {
1505 obd = class_exp2obd(sbi->ll_md_exp);
1507 force = obd->obd_force;
1510 /* Wait for unstable pages to be committed to stable storage */
1512 rc = l_wait_event_abortable(
1513 sbi->ll_cache->ccc_unstable_waitq,
1514 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1517 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1518 if (force == 0 && rc != -ERESTARTSYS)
1519 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1521 /* We need to set force before the lov_disconnect in
1522 * lustre_common_put_super, since l_d cleans up osc's as well.
1526 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1528 obd->obd_force = force;
1532 if (sbi->ll_client_common_fill_super_succeeded) {
1533 /* Only if client_common_fill_super succeeded */
1534 client_common_put_super(sb);
1537 /* imitate failed cleanup */
1538 if (CFS_FAIL_CHECK(OBD_FAIL_OBD_CLEANUP))
1542 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1543 class_manual_cleanup(obd);
1546 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1547 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1550 class_del_profile(profilenm);
1552 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1553 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1554 bdi_destroy(&lsi->lsi_bdi);
1555 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1559 llcrypt_free_dummy_policy(&lsi->lsi_dummy_enc_policy);
1561 lsi->lsi_llsbi = NULL;
1563 lustre_common_put_super(sb);
1565 cl_env_cache_purge(~0);
1568 } /* client_put_super */
1570 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1572 struct inode *inode = NULL;
1574 /* NOTE: we depend on atomic igrab() -bzzz */
1575 lock_res_and_lock(lock);
1576 if (lock->l_resource->lr_lvb_inode) {
1577 struct ll_inode_info * lli;
1578 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1579 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1580 inode = igrab(lock->l_resource->lr_lvb_inode);
1582 inode = lock->l_resource->lr_lvb_inode;
1583 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1584 D_WARNING, lock, "lr_lvb_inode %p is "
1585 "bogus: magic %08x",
1586 lock->l_resource->lr_lvb_inode,
1587 lli->lli_inode_magic);
1591 unlock_res_and_lock(lock);
1595 void ll_dir_clear_lsm_md(struct inode *inode)
1597 struct ll_inode_info *lli = ll_i2info(inode);
1599 LASSERT(S_ISDIR(inode->i_mode));
1601 if (lli->lli_lsm_md) {
1602 lmv_free_memmd(lli->lli_lsm_md);
1603 lli->lli_lsm_md = NULL;
1606 if (lli->lli_default_lsm_md) {
1607 lmv_free_memmd(lli->lli_default_lsm_md);
1608 lli->lli_default_lsm_md = NULL;
1612 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1613 const struct lu_fid *fid,
1614 struct lustre_md *md)
1616 struct ll_sb_info *sbi = ll_s2sbi(sb);
1617 struct ll_inode_info *lli;
1618 struct mdt_body *body = md->body;
1619 struct inode *inode;
1625 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1626 inode = iget_locked(sb, ino);
1627 if (inode == NULL) {
1628 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1629 sbi->ll_fsname, PFID(fid));
1630 RETURN(ERR_PTR(-ENOENT));
1633 lli = ll_i2info(inode);
1634 if (inode->i_state & I_NEW) {
1635 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1636 (body->mbo_mode & S_IFMT);
1637 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1640 inode->i_mtime.tv_sec = 0;
1641 inode->i_atime.tv_sec = 0;
1642 inode->i_ctime.tv_sec = 0;
1645 #ifdef HAVE_BACKING_DEV_INFO
1646 /* initializing backing dev info. */
1647 inode->i_mapping->backing_dev_info =
1648 &s2lsi(inode->i_sb)->lsi_bdi;
1650 inode->i_op = &ll_dir_inode_operations;
1651 inode->i_fop = &ll_dir_operations;
1652 lli->lli_fid = *fid;
1655 /* master object FID */
1656 lli->lli_pfid = body->mbo_fid1;
1657 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1658 lli, PFID(fid), PFID(&lli->lli_pfid));
1659 unlock_new_inode(inode);
1661 /* in directory restripe/auto-split, a directory will be
1662 * transformed to a stripe if it's plain, set its pfid here,
1663 * otherwise ll_lock_cancel_bits() can't find the master inode.
1665 lli->lli_pfid = body->mbo_fid1;
1671 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1674 struct lmv_stripe_md *lsm = md->lmv;
1675 struct ll_inode_info *lli = ll_i2info(inode);
1678 LASSERT(lsm != NULL);
1680 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1681 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1682 lsm_md_dump(D_INODE, lsm);
1684 if (!lmv_dir_striped(lsm))
1687 /* XXX sigh, this lsm_root initialization should be in
1688 * LMV layer, but it needs ll_iget right now, so we
1689 * put this here right now. */
1690 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1691 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1692 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1694 if (!fid_is_sane(fid))
1697 /* Unfortunately ll_iget will call ll_update_inode,
1698 * where the initialization of slave inode is slightly
1699 * different, so it reset lsm_md to NULL to avoid
1700 * initializing lsm for slave inode. */
1701 lsm->lsm_md_oinfo[i].lmo_root =
1702 ll_iget_anon_dir(inode->i_sb, fid, md);
1703 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1704 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1706 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1708 iput(lsm->lsm_md_oinfo[i].lmo_root);
1709 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1715 lli->lli_lsm_md = lsm;
1720 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1722 struct ll_inode_info *lli = ll_i2info(inode);
1726 if (!md->default_lmv) {
1727 /* clear default lsm */
1728 if (lli->lli_default_lsm_md && lli->lli_default_lmv_set) {
1729 down_write(&lli->lli_lsm_sem);
1730 if (lli->lli_default_lsm_md &&
1731 lli->lli_default_lmv_set) {
1732 lmv_free_memmd(lli->lli_default_lsm_md);
1733 lli->lli_default_lsm_md = NULL;
1734 lli->lli_inherit_depth = 0;
1735 lli->lli_default_lmv_set = 0;
1737 up_write(&lli->lli_lsm_sem);
1742 if (lli->lli_default_lsm_md) {
1743 /* do nonthing if default lsm isn't changed */
1744 down_read(&lli->lli_lsm_sem);
1745 if (lli->lli_default_lsm_md &&
1746 lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1747 up_read(&lli->lli_lsm_sem);
1750 up_read(&lli->lli_lsm_sem);
1753 down_write(&lli->lli_lsm_sem);
1754 if (lli->lli_default_lsm_md)
1755 lmv_free_memmd(lli->lli_default_lsm_md);
1756 lli->lli_default_lsm_md = md->default_lmv;
1757 lli->lli_default_lmv_set = 1;
1758 lsm_md_dump(D_INODE, md->default_lmv);
1759 md->default_lmv = NULL;
1760 up_write(&lli->lli_lsm_sem);
1764 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1766 struct ll_inode_info *lli = ll_i2info(inode);
1767 struct lmv_stripe_md *lsm = md->lmv;
1768 struct cl_attr *attr;
1773 LASSERT(S_ISDIR(inode->i_mode));
1774 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1775 PFID(ll_inode2fid(inode)));
1777 /* update default LMV */
1778 if (md->default_lmv)
1779 ll_update_default_lsm_md(inode, md);
1781 /* after dir migration/restripe, a stripe may be turned into a
1782 * directory, in this case, zero out its lli_pfid.
1784 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1785 fid_zero(&lli->lli_pfid);
1788 * no striped information from request, lustre_md from req does not
1789 * include stripeEA, see ll_md_setattr()
1795 * normally dir layout doesn't change, only take read lock to check
1796 * that to avoid blocking other MD operations.
1798 down_read(&lli->lli_lsm_sem);
1800 /* some current lookup initialized lsm, and unchanged */
1801 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1802 GOTO(unlock, rc = 0);
1804 /* if dir layout doesn't match, check whether version is increased,
1805 * which means layout is changed, this happens in dir split/merge and
1808 * foreign LMV should not change.
1810 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1811 lsm->lsm_md_layout_version <=
1812 lli->lli_lsm_md->lsm_md_layout_version) {
1813 CERROR("%s: "DFID" dir layout mismatch:\n",
1814 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1815 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1816 lsm_md_dump(D_ERROR, lsm);
1817 GOTO(unlock, rc = -EINVAL);
1820 up_read(&lli->lli_lsm_sem);
1821 down_write(&lli->lli_lsm_sem);
1822 /* clear existing lsm */
1823 if (lli->lli_lsm_md) {
1824 lmv_free_memmd(lli->lli_lsm_md);
1825 lli->lli_lsm_md = NULL;
1828 rc = ll_init_lsm_md(inode, md);
1830 up_write(&lli->lli_lsm_sem);
1834 /* md_merge_attr() may take long, since lsm is already set, switch to
1837 downgrade_write(&lli->lli_lsm_sem);
1839 /* set md->lmv to NULL, so the following free lustre_md will not free
1844 if (!lmv_dir_striped(lli->lli_lsm_md))
1845 GOTO(unlock, rc = 0);
1847 OBD_ALLOC_PTR(attr);
1849 GOTO(unlock, rc = -ENOMEM);
1851 /* validate the lsm */
1852 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1853 ll_md_blocking_ast);
1855 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1856 md->body->mbo_nlink = attr->cat_nlink;
1857 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1858 md->body->mbo_size = attr->cat_size;
1859 if (md->body->mbo_valid & OBD_MD_FLATIME)
1860 md->body->mbo_atime = attr->cat_atime;
1861 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1862 md->body->mbo_ctime = attr->cat_ctime;
1863 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1864 md->body->mbo_mtime = attr->cat_mtime;
1870 up_read(&lli->lli_lsm_sem);
1875 void ll_clear_inode(struct inode *inode)
1877 struct ll_inode_info *lli = ll_i2info(inode);
1878 struct ll_sb_info *sbi = ll_i2sbi(inode);
1882 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1883 PFID(ll_inode2fid(inode)), inode);
1885 if (S_ISDIR(inode->i_mode)) {
1886 /* these should have been cleared in ll_file_release */
1887 LASSERT(lli->lli_opendir_key == NULL);
1888 LASSERT(lli->lli_sai == NULL);
1889 LASSERT(lli->lli_opendir_pid == 0);
1891 pcc_inode_free(inode);
1894 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1896 LASSERT(!lli->lli_open_fd_write_count);
1897 LASSERT(!lli->lli_open_fd_read_count);
1898 LASSERT(!lli->lli_open_fd_exec_count);
1900 if (lli->lli_mds_write_och)
1901 ll_md_real_close(inode, FMODE_WRITE);
1902 if (lli->lli_mds_exec_och)
1903 ll_md_real_close(inode, FMODE_EXEC);
1904 if (lli->lli_mds_read_och)
1905 ll_md_real_close(inode, FMODE_READ);
1907 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1908 OBD_FREE(lli->lli_symlink_name,
1909 strlen(lli->lli_symlink_name) + 1);
1910 lli->lli_symlink_name = NULL;
1913 ll_xattr_cache_destroy(inode);
1915 forget_all_cached_acls(inode);
1917 lli->lli_inode_magic = LLI_INODE_DEAD;
1919 if (S_ISDIR(inode->i_mode))
1920 ll_dir_clear_lsm_md(inode);
1921 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1922 LASSERT(list_empty(&lli->lli_agl_list));
1925 * XXX This has to be done before lsm is freed below, because
1926 * cl_object still uses inode lsm.
1928 cl_inode_fini(inode);
1930 llcrypt_put_encryption_info(inode);
1935 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1937 struct lustre_md md;
1938 struct inode *inode = dentry->d_inode;
1939 struct ll_sb_info *sbi = ll_i2sbi(inode);
1940 struct ptlrpc_request *request = NULL;
1945 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1946 LUSTRE_OPC_ANY, NULL);
1947 if (IS_ERR(op_data))
1948 RETURN(PTR_ERR(op_data));
1950 /* If this is a chgrp of a regular file, we want to reserve enough
1951 * quota to cover the entire file size.
1953 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1954 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1955 from_kgid(&init_user_ns, inode->i_gid)) {
1956 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1957 op_data->op_attr_blocks = inode->i_blocks;
1961 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1963 ptlrpc_req_finished(request);
1964 if (rc == -ENOENT) {
1966 /* Unlinked special device node? Or just a race?
1967 * Pretend we done everything. */
1968 if (!S_ISREG(inode->i_mode) &&
1969 !S_ISDIR(inode->i_mode)) {
1970 ia_valid = op_data->op_attr.ia_valid;
1971 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1972 rc = simple_setattr(&init_user_ns, dentry,
1974 op_data->op_attr.ia_valid = ia_valid;
1976 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1977 CERROR("md_setattr fails: rc = %d\n", rc);
1982 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1983 sbi->ll_md_exp, &md);
1985 ptlrpc_req_finished(request);
1989 ia_valid = op_data->op_attr.ia_valid;
1990 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1991 * cache is not cleared yet. */
1992 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1993 if (S_ISREG(inode->i_mode))
1995 rc = simple_setattr(&init_user_ns, dentry, &op_data->op_attr);
1996 if (S_ISREG(inode->i_mode))
1997 inode_unlock(inode);
1998 op_data->op_attr.ia_valid = ia_valid;
2000 rc = ll_update_inode(inode, &md);
2001 ptlrpc_req_finished(request);
2007 * Zero portion of page that is part of @inode.
2008 * This implies, if necessary:
2009 * - taking cl_lock on range corresponding to concerned page
2010 * - grabbing vm page
2011 * - associating cl_page
2012 * - proceeding to clio read
2013 * - zeroing range in page
2014 * - proceeding to cl_page flush
2015 * - releasing cl_lock
2017 * \param[in] inode inode
2018 * \param[in] index page index
2019 * \param[in] offset offset in page to start zero from
2020 * \param[in] len len to zero
2022 * \retval 0 on success
2023 * \retval negative errno on failure
2025 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
2028 struct ll_inode_info *lli = ll_i2info(inode);
2029 struct cl_object *clob = lli->lli_clob;
2031 struct lu_env *env = NULL;
2032 struct cl_io *io = NULL;
2033 struct cl_page *clpage = NULL;
2034 struct page *vmpage = NULL;
2035 unsigned from = index << PAGE_SHIFT;
2036 struct cl_lock *lock = NULL;
2037 struct cl_lock_descr *descr = NULL;
2038 struct cl_2queue *queue = NULL;
2039 struct cl_sync_io *anchor = NULL;
2040 bool holdinglock = false;
2045 env = cl_env_get(&refcheck);
2047 RETURN(PTR_ERR(env));
2049 io = vvp_env_thread_io(env);
2051 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
2055 lock = vvp_env_lock(env);
2056 descr = &lock->cll_descr;
2057 descr->cld_obj = io->ci_obj;
2058 descr->cld_start = from >> PAGE_SHIFT;
2059 descr->cld_end = (from + PAGE_SIZE - 1) >> PAGE_SHIFT;
2060 descr->cld_mode = CLM_WRITE;
2061 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
2063 /* request lock for page */
2064 rc = cl_lock_request(env, io, lock);
2065 /* -ECANCELED indicates a matching lock with a different extent
2066 * was already present, and -EEXIST indicates a matching lock
2067 * on exactly the same extent was already present.
2068 * In both cases it means we are covered.
2070 if (rc == -ECANCELED || rc == -EEXIST)
2078 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
2080 GOTO(rellock, rc = -EOPNOTSUPP);
2082 if (!PageDirty(vmpage)) {
2083 /* associate cl_page */
2084 clpage = cl_page_find(env, clob, vmpage->index,
2085 vmpage, CPT_CACHEABLE);
2087 GOTO(pagefini, rc = PTR_ERR(clpage));
2089 cl_page_assume(env, io, clpage);
2092 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2093 !PageWriteback(vmpage)) {
2095 /* Set PagePrivate2 to detect special case of empty page
2096 * in osc_brw_fini_request().
2097 * It is also used to tell ll_io_read_page() that we do not
2098 * want the vmpage to be unlocked.
2100 SetPagePrivate2(vmpage);
2101 rc = ll_io_read_page(env, io, clpage, NULL);
2102 if (!PagePrivate2(vmpage)) {
2103 /* PagePrivate2 was cleared in osc_brw_fini_request()
2104 * meaning we read an empty page. In this case, in order
2105 * to avoid allocating unnecessary block in truncated
2106 * file, we must not zero and write as below. Subsequent
2107 * server-side truncate will handle things correctly.
2109 cl_page_unassume(env, io, clpage);
2110 GOTO(clpfini, rc = 0);
2112 ClearPagePrivate2(vmpage);
2117 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2118 * the vmpage, so we are good to proceed and zero range in page.
2120 zero_user(vmpage, offset, len);
2122 if (holdinglock && clpage) {
2123 /* explicitly write newly modified page */
2124 queue = &io->ci_queue;
2125 cl_2queue_init(queue);
2126 anchor = &vvp_env_info(env)->vti_anchor;
2127 cl_sync_io_init(anchor, 1);
2128 clpage->cp_sync_io = anchor;
2129 cl_page_list_add(&queue->c2_qin, clpage, true);
2130 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2132 GOTO(queuefini1, rc);
2133 rc = cl_sync_io_wait(env, anchor, 0);
2135 GOTO(queuefini2, rc);
2136 cl_page_assume(env, io, clpage);
2139 cl_2queue_discard(env, io, queue);
2141 cl_2queue_disown(env, queue);
2142 cl_2queue_fini(env, queue);
2147 cl_page_put(env, clpage);
2149 unlock_page(vmpage);
2153 cl_lock_release(env, lock);
2155 cl_io_fini(env, io);
2158 cl_env_put(env, &refcheck);
2164 * Get reference file from volatile file name.
2165 * Volatile file name may look like:
2166 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2167 * where fd is opened descriptor of reference file.
2169 * \param[in] volatile_name volatile file name
2170 * \param[in] volatile_len volatile file name length
2171 * \param[out] ref_file pointer to struct file of reference file
2173 * \retval 0 on success
2174 * \retval negative errno on failure
2176 int volatile_ref_file(const char *volatile_name, int volatile_len,
2177 struct file **ref_file)
2179 char *p, *q, *fd_str;
2182 p = strnstr(volatile_name, ":fd=", volatile_len);
2183 if (!p || strlen(p + 4) == 0)
2186 q = strchrnul(p + 4, ':');
2187 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2190 rc = kstrtouint(fd_str, 10, &fd);
2195 *ref_file = fget(fd);
2201 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2202 * object(s) determine the file size and mtime. Otherwise, the MDS will
2203 * keep these values until such a time that objects are allocated for it.
2204 * We do the MDS operations first, as it is checking permissions for us.
2205 * We don't to the MDS RPC if there is nothing that we want to store there,
2206 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2207 * going to do an RPC anyways.
2209 * If we are doing a truncate, we will send the mtime and ctime updates
2210 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2211 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2214 * In case of HSMimport, we only set attr on MDS.
2216 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2217 enum op_xvalid xvalid, bool hsm_import)
2219 struct inode *inode = dentry->d_inode;
2220 struct ll_inode_info *lli = ll_i2info(inode);
2221 struct md_op_data *op_data = NULL;
2222 ktime_t kstart = ktime_get();
2227 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2228 "valid %x, hsm_import %d\n",
2229 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2230 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2233 if (attr->ia_valid & ATTR_SIZE) {
2234 /* Check new size against VFS/VM file size limit and rlimit */
2235 rc = inode_newsize_ok(inode, attr->ia_size);
2239 /* The maximum Lustre file size is variable, based on the
2240 * OST maximum object size and number of stripes. This
2241 * needs another check in addition to the VFS check above. */
2242 if (attr->ia_size > ll_file_maxbytes(inode)) {
2243 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2244 PFID(&lli->lli_fid), attr->ia_size,
2245 ll_file_maxbytes(inode));
2249 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2252 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2253 if (attr->ia_valid & TIMES_SET_FLAGS) {
2254 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2255 !capable(CAP_FOWNER))
2259 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2260 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2261 (attr->ia_valid & ATTR_CTIME)) {
2262 attr->ia_ctime = current_time(inode);
2263 xvalid |= OP_XVALID_CTIME_SET;
2265 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2266 (attr->ia_valid & ATTR_ATIME)) {
2267 attr->ia_atime = current_time(inode);
2268 attr->ia_valid |= ATTR_ATIME_SET;
2270 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2271 (attr->ia_valid & ATTR_MTIME)) {
2272 attr->ia_mtime = current_time(inode);
2273 attr->ia_valid |= ATTR_MTIME_SET;
2276 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2277 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2278 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2279 ktime_get_real_seconds());
2281 if (S_ISREG(inode->i_mode))
2282 inode_unlock(inode);
2284 /* We always do an MDS RPC, even if we're only changing the size;
2285 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2287 OBD_ALLOC_PTR(op_data);
2288 if (op_data == NULL)
2289 GOTO(out, rc = -ENOMEM);
2291 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2292 /* If we are changing file size, file content is
2293 * modified, flag it.
2295 xvalid |= OP_XVALID_OWNEROVERRIDE;
2296 op_data->op_bias |= MDS_DATA_MODIFIED;
2297 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2300 if (attr->ia_valid & ATTR_FILE) {
2301 struct ll_file_data *fd = attr->ia_file->private_data;
2303 if (fd->fd_lease_och)
2304 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2307 op_data->op_attr = *attr;
2308 op_data->op_xvalid = xvalid;
2310 rc = ll_md_setattr(dentry, op_data);
2313 lli->lli_synced_to_mds = false;
2315 if (!S_ISREG(inode->i_mode) || hsm_import)
2318 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2319 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2320 xvalid & OP_XVALID_CTIME_SET) {
2321 bool cached = false;
2323 rc = pcc_inode_setattr(inode, attr, &cached);
2326 CERROR("%s: PCC inode "DFID" setattr failed: "
2328 ll_i2sbi(inode)->ll_fsname,
2329 PFID(&lli->lli_fid), rc);
2333 unsigned int flags = 0;
2335 /* For truncate and utimes sending attributes to OSTs,
2336 * setting mtime/atime to the past will be performed
2337 * under PW [0:EOF] extent lock (new_size:EOF for
2338 * truncate). It may seem excessive to send mtime/atime
2339 * updates to OSTs when not setting times to past, but
2340 * it is necessary due to possible time
2341 * de-synchronization between MDT inode and OST objects
2343 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2344 xvalid |= OP_XVALID_FLAGS;
2345 flags = LUSTRE_ENCRYPT_FL;
2346 /* Call to ll_io_zero_page is not necessary if
2347 * truncating on PAGE_SIZE boundary, because
2348 * whole pages will be wiped.
2349 * In case of Direct IO, all we need is to set
2352 if (attr->ia_valid & ATTR_SIZE &&
2353 attr->ia_size & ~PAGE_MASK &&
2354 !(attr->ia_valid & ATTR_FILE &&
2355 attr->ia_file->f_flags & O_DIRECT)) {
2357 attr->ia_size & (PAGE_SIZE - 1);
2359 rc = ll_io_zero_page(inode,
2360 attr->ia_size >> PAGE_SHIFT,
2361 offset, PAGE_SIZE - offset);
2365 /* If encrypted volatile file without the key,
2366 * we need to fetch size from reference file,
2367 * and set it on OST objects. This happens when
2368 * migrating or extending an encrypted file
2371 if (filename_is_volatile(dentry->d_name.name,
2374 llcrypt_require_key(inode) == -ENOKEY) {
2375 struct file *ref_file;
2376 struct inode *ref_inode;
2377 struct ll_inode_info *ref_lli;
2378 struct cl_object *ref_obj;
2379 struct cl_attr ref_attr = { 0 };
2383 rc = volatile_ref_file(
2384 dentry->d_name.name,
2390 ref_inode = file_inode(ref_file);
2393 GOTO(out, rc = -EINVAL);
2396 env = cl_env_get(&refcheck);
2398 GOTO(out, rc = PTR_ERR(env));
2400 ref_lli = ll_i2info(ref_inode);
2401 ref_obj = ref_lli->lli_clob;
2402 cl_object_attr_lock(ref_obj);
2403 rc = cl_object_attr_get(env, ref_obj,
2405 cl_object_attr_unlock(ref_obj);
2406 cl_env_put(env, &refcheck);
2411 attr->ia_valid |= ATTR_SIZE;
2412 attr->ia_size = ref_attr.cat_size;
2415 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2419 /* If the file was restored, it needs to set dirty flag.
2421 * We've already sent MDS_DATA_MODIFIED flag in
2422 * ll_md_setattr() for truncate. However, the MDT refuses to
2423 * set the HS_DIRTY flag on released files, so we have to set
2424 * it again if the file has been restored. Please check how
2425 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2427 * Please notice that if the file is not released, the previous
2428 * MDS_DATA_MODIFIED has taken effect and usually
2429 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2430 * This way we can save an RPC for common open + trunc
2432 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2433 struct hsm_state_set hss = {
2434 .hss_valid = HSS_SETMASK,
2435 .hss_setmask = HS_DIRTY,
2439 rc2 = ll_hsm_state_set(inode, &hss);
2440 /* truncate and write can happen at the same time, so that
2441 * the file can be set modified even though the file is not
2442 * restored from released state, and ll_hsm_state_set() is
2443 * not applicable for the file, and rc2 < 0 is normal in this
2446 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2447 PFID(ll_inode2fid(inode)), rc2);
2452 if (op_data != NULL)
2453 ll_finish_md_op_data(op_data);
2455 if (S_ISREG(inode->i_mode)) {
2457 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2458 inode_dio_wait(inode);
2459 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2460 * flag. ll_update_inode (called from ll_md_setattr), clears
2461 * inode flags, so there is a gap where S_NOSEC is not set.
2462 * This can cause a writer to take the i_mutex unnecessarily,
2463 * but this is safe to do and should be rare. */
2464 inode_has_no_xattr(inode);
2468 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2469 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2470 ktime_us_delta(ktime_get(), kstart));
2475 int ll_setattr(struct user_namespace *mnt_userns, struct dentry *de,
2478 int mode = de->d_inode->i_mode;
2479 enum op_xvalid xvalid = 0;
2482 rc = llcrypt_prepare_setattr(de, attr);
2486 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2487 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2488 xvalid |= OP_XVALID_OWNEROVERRIDE;
2490 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2491 (ATTR_SIZE|ATTR_MODE)) &&
2492 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2493 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2494 !(attr->ia_mode & S_ISGID))))
2495 attr->ia_valid |= ATTR_FORCE;
2497 if ((attr->ia_valid & ATTR_MODE) &&
2499 !(attr->ia_mode & S_ISUID) &&
2500 !(attr->ia_valid & ATTR_KILL_SUID))
2501 attr->ia_valid |= ATTR_KILL_SUID;
2503 if ((attr->ia_valid & ATTR_MODE) &&
2504 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2505 !(attr->ia_mode & S_ISGID) &&
2506 !(attr->ia_valid & ATTR_KILL_SGID))
2507 attr->ia_valid |= ATTR_KILL_SGID;
2509 return ll_setattr_raw(de, attr, xvalid, false);
2512 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2515 struct obd_statfs obd_osfs = { 0 };
2520 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2522 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2523 flags |= OBD_STATFS_NODELAY;
2525 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2529 osfs->os_type = LL_SUPER_MAGIC;
2531 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2532 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2534 if (osfs->os_state & OS_STATFS_SUM)
2537 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2538 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2541 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2542 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2545 osfs->os_bsize = obd_osfs.os_bsize;
2546 osfs->os_blocks = obd_osfs.os_blocks;
2547 osfs->os_bfree = obd_osfs.os_bfree;
2548 osfs->os_bavail = obd_osfs.os_bavail;
2550 /* If we have _some_ OSTs, but don't have as many free objects on the
2551 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2552 * to compensate, so that the "inodes in use" number is correct.
2553 * This should be kept in sync with lod_statfs() behaviour.
2555 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2556 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2558 osfs->os_ffree = obd_osfs.os_ffree;
2565 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2567 struct if_quotactl qctl = {
2568 .qc_cmd = LUSTRE_Q_GETQUOTA,
2569 .qc_type = PRJQUOTA,
2570 .qc_valid = QC_GENERAL,
2572 u64 limit, curblock;
2575 qctl.qc_id = ll_i2info(inode)->lli_projid;
2576 ret = quotactl_ioctl(inode->i_sb, &qctl);
2578 /* ignore errors if project ID does not have
2579 * a quota limit or feature unsupported.
2581 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2586 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2587 qctl.qc_dqblk.dqb_bsoftlimit :
2588 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2589 if (limit && sfs->f_blocks > limit) {
2590 curblock = (qctl.qc_dqblk.dqb_curspace +
2591 sfs->f_bsize - 1) / sfs->f_bsize;
2592 sfs->f_blocks = limit;
2593 sfs->f_bfree = sfs->f_bavail =
2594 (sfs->f_blocks > curblock) ?
2595 (sfs->f_blocks - curblock) : 0;
2598 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2599 qctl.qc_dqblk.dqb_isoftlimit :
2600 qctl.qc_dqblk.dqb_ihardlimit;
2601 if (limit && sfs->f_files > limit) {
2602 sfs->f_files = limit;
2603 sfs->f_ffree = (sfs->f_files >
2604 qctl.qc_dqblk.dqb_curinodes) ?
2605 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2611 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2613 struct super_block *sb = de->d_sb;
2614 struct obd_statfs osfs;
2615 __u64 fsid = huge_encode_dev(sb->s_dev);
2616 ktime_t kstart = ktime_get();
2619 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2621 /* Some amount of caching on the client is allowed */
2622 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2626 statfs_unpack(sfs, &osfs);
2628 /* We need to downshift for all 32-bit kernels, because we can't
2629 * tell if the kernel is being called via sys_statfs64() or not.
2630 * Stop before overflowing f_bsize - in which case it is better
2631 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2632 if (sizeof(long) < 8) {
2633 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2636 osfs.os_blocks >>= 1;
2637 osfs.os_bfree >>= 1;
2638 osfs.os_bavail >>= 1;
2642 sfs->f_blocks = osfs.os_blocks;
2643 sfs->f_bfree = osfs.os_bfree;
2644 sfs->f_bavail = osfs.os_bavail;
2645 sfs->f_fsid.val[0] = (__u32)fsid;
2646 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2647 if (ll_i2info(de->d_inode)->lli_projid &&
2648 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2649 return ll_statfs_project(de->d_inode, sfs);
2651 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2652 ktime_us_delta(ktime_get(), kstart));
2657 void ll_inode_size_lock(struct inode *inode)
2659 struct ll_inode_info *lli;
2661 LASSERT(!S_ISDIR(inode->i_mode));
2663 lli = ll_i2info(inode);
2664 mutex_lock(&lli->lli_size_mutex);
2667 void ll_inode_size_unlock(struct inode *inode)
2669 struct ll_inode_info *lli;
2671 lli = ll_i2info(inode);
2672 mutex_unlock(&lli->lli_size_mutex);
2675 int ll_inode_size_trylock(struct inode *inode)
2677 struct ll_inode_info *lli;
2679 LASSERT(!S_ISDIR(inode->i_mode));
2681 lli = ll_i2info(inode);
2682 return mutex_trylock(&lli->lli_size_mutex);
2685 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2687 /* do not clear encryption flag */
2688 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2689 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2690 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2691 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2693 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2696 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2698 struct ll_inode_info *lli = ll_i2info(inode);
2699 struct mdt_body *body = md->body;
2700 struct ll_sb_info *sbi = ll_i2sbi(inode);
2704 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2705 rc = cl_file_inode_init(inode, md);
2710 if (S_ISDIR(inode->i_mode)) {
2711 rc = ll_update_lsm_md(inode, md);
2716 if (body->mbo_valid & OBD_MD_FLACL)
2717 lli_replace_acl(lli, md);
2719 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2720 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2721 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2723 if (body->mbo_valid & OBD_MD_FLATIME) {
2724 if (body->mbo_atime > inode->i_atime.tv_sec)
2725 inode->i_atime.tv_sec = body->mbo_atime;
2726 lli->lli_atime = body->mbo_atime;
2729 if (body->mbo_valid & OBD_MD_FLMTIME) {
2730 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2732 "setting ino %lu mtime from %lld to %llu\n",
2733 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2735 inode->i_mtime.tv_sec = body->mbo_mtime;
2737 lli->lli_mtime = body->mbo_mtime;
2740 if (body->mbo_valid & OBD_MD_FLCTIME) {
2741 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2742 inode->i_ctime.tv_sec = body->mbo_ctime;
2743 lli->lli_ctime = body->mbo_ctime;
2746 if (body->mbo_valid & OBD_MD_FLBTIME)
2747 lli->lli_btime = body->mbo_btime;
2749 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2750 if (body->mbo_valid & OBD_MD_FLFLAGS)
2751 ll_update_inode_flags(inode, body->mbo_flags);
2752 if (body->mbo_valid & OBD_MD_FLMODE)
2753 inode->i_mode = (inode->i_mode & S_IFMT) |
2754 (body->mbo_mode & ~S_IFMT);
2756 if (body->mbo_valid & OBD_MD_FLTYPE)
2757 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2758 (body->mbo_mode & S_IFMT);
2760 LASSERT(inode->i_mode != 0);
2761 if (body->mbo_valid & OBD_MD_FLUID)
2762 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2763 if (body->mbo_valid & OBD_MD_FLGID)
2764 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2765 if (body->mbo_valid & OBD_MD_FLPROJID)
2766 lli->lli_projid = body->mbo_projid;
2767 if (body->mbo_valid & OBD_MD_FLNLINK) {
2768 spin_lock(&inode->i_lock);
2769 set_nlink(inode, body->mbo_nlink);
2770 spin_unlock(&inode->i_lock);
2772 if (body->mbo_valid & OBD_MD_FLRDEV)
2773 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2775 if (body->mbo_valid & OBD_MD_FLID) {
2776 /* FID shouldn't be changed! */
2777 if (fid_is_sane(&lli->lli_fid)) {
2778 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2779 "Trying to change FID "DFID
2780 " to the "DFID", inode "DFID"(%p)\n",
2781 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2782 PFID(ll_inode2fid(inode)), inode);
2784 lli->lli_fid = body->mbo_fid1;
2788 LASSERT(fid_seq(&lli->lli_fid) != 0);
2790 /* In case of encrypted file without the key, please do not lose
2791 * clear text size stored into lli_lazysize in ll_merge_attr(),
2792 * we will need it in ll_prepare_close().
2794 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2795 llcrypt_require_key(inode) == -ENOKEY)
2796 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2798 lli->lli_attr_valid = body->mbo_valid;
2799 if (body->mbo_valid & OBD_MD_FLSIZE) {
2800 i_size_write(inode, body->mbo_size);
2802 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2803 PFID(ll_inode2fid(inode)),
2804 (unsigned long long)body->mbo_size);
2806 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2807 inode->i_blocks = body->mbo_blocks;
2809 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2810 lli->lli_lazysize = body->mbo_size;
2811 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2812 lli->lli_lazyblocks = body->mbo_blocks;
2815 if (body->mbo_valid & OBD_MD_TSTATE) {
2816 /* Set LLIF_FILE_RESTORING if restore ongoing and
2817 * clear it when done to ensure to start again
2818 * glimpsing updated attrs
2820 if (body->mbo_t_state & MS_RESTORE)
2821 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2823 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2829 /* child default LMV is inherited from parent */
2830 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2831 struct lmv_stripe_md *cdmv)
2836 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2837 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2838 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2839 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2842 if (cdmv->lsm_md_max_inherit !=
2843 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2846 if (cdmv->lsm_md_max_inherit_rr !=
2847 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2853 /* if default LMV is implicitly inherited, subdir default LMV is maintained on
2856 int ll_dir_default_lmv_inherit(struct inode *dir, struct inode *inode)
2858 struct ll_inode_info *plli = ll_i2info(dir);
2859 struct ll_inode_info *lli = ll_i2info(inode);
2860 struct lmv_stripe_md *plsm;
2861 struct lmv_stripe_md *lsm;
2866 /* ROOT default LMV is not inherited */
2867 if (is_root_inode(dir) ||
2868 !(exp_connect_flags2(ll_i2mdexp(dir)) &
2869 OBD_CONNECT2_DMV_IMP_INHERIT))
2872 /* nothing to do if no default LMV on both */
2873 if (!plli->lli_default_lsm_md && !lli->lli_default_lsm_md)
2876 /* subdir default LMV comes from disk */
2877 if (lli->lli_default_lsm_md && lli->lli_default_lmv_set)
2880 /* delete subdir default LMV if parent's is deleted or becomes
2883 down_read(&plli->lli_lsm_sem);
2884 plsm = plli->lli_default_lsm_md;
2885 if (!plsm || !lmv_is_inheritable(plsm->lsm_md_max_inherit)) {
2886 if (lli->lli_default_lsm_md && !lli->lli_default_lmv_set) {
2887 down_write(&lli->lli_lsm_sem);
2888 if (lli->lli_default_lsm_md &&
2889 !lli->lli_default_lmv_set) {
2890 lmv_free_memmd(lli->lli_default_lsm_md);
2891 lli->lli_default_lsm_md = NULL;
2892 lli->lli_inherit_depth = 0;
2894 up_write(&lli->lli_lsm_sem);
2896 GOTO(unlock_parent, rc = 0);
2899 /* do nothing if inherited LMV is unchanged */
2900 if (lli->lli_default_lsm_md) {
2902 down_read(&lli->lli_lsm_sem);
2903 if (!lli->lli_default_lmv_set)
2904 rc = lsm_md_inherited(plsm, lli->lli_default_lsm_md);
2905 up_read(&lli->lli_lsm_sem);
2907 GOTO(unlock_parent, rc = 0);
2910 /* inherit default LMV */
2911 down_write(&lli->lli_lsm_sem);
2912 if (lli->lli_default_lsm_md) {
2913 /* checked above, but in case of race, check again with lock */
2914 if (lli->lli_default_lmv_set)
2915 GOTO(unlock_child, rc = 0);
2916 /* always update subdir default LMV in case parent's changed */
2917 lsm = lli->lli_default_lsm_md;
2921 GOTO(unlock_child, rc = -ENOMEM);
2922 lli->lli_default_lsm_md = lsm;
2926 lsm->lsm_md_max_inherit = lmv_inherit_next(plsm->lsm_md_max_inherit);
2927 lsm->lsm_md_max_inherit_rr =
2928 lmv_inherit_rr_next(plsm->lsm_md_max_inherit_rr);
2929 lli->lli_inherit_depth = plli->lli_inherit_depth + 1;
2931 lsm_md_dump(D_INODE, lsm);
2935 up_write(&lli->lli_lsm_sem);
2937 up_read(&plli->lli_lsm_sem);
2943 * Update directory depth and default LMV
2945 * Update directory depth to ROOT and inherit default LMV from parent if
2946 * parent's default LMV is inheritable. The default LMV set with command
2947 * "lfs setdirstripe -D ..." is stored on MDT, while the inherited default LMV
2948 * is generated at runtime on client side.
2950 * \param[in] dir parent directory inode
2951 * \param[in] de dentry
2953 void ll_update_dir_depth_dmv(struct inode *dir, struct dentry *de)
2955 struct inode *inode = de->d_inode;
2956 struct ll_inode_info *plli;
2957 struct ll_inode_info *lli;
2959 LASSERT(S_ISDIR(inode->i_mode));
2963 plli = ll_i2info(dir);
2964 lli = ll_i2info(inode);
2965 lli->lli_dir_depth = plli->lli_dir_depth + 1;
2966 if (lli->lli_default_lsm_md && lli->lli_default_lmv_set) {
2967 if (plli->lli_default_lsm_md) {
2968 down_read(&plli->lli_lsm_sem);
2969 down_read(&lli->lli_lsm_sem);
2970 if (lsm_md_inherited(plli->lli_default_lsm_md,
2971 lli->lli_default_lsm_md))
2972 lli->lli_inherit_depth =
2973 plli->lli_inherit_depth + 1;
2975 /* in case parent default LMV changed */
2976 lli->lli_inherit_depth = 0;
2977 up_read(&lli->lli_lsm_sem);
2978 up_read(&plli->lli_lsm_sem);
2980 /* in case parent default LMV deleted */
2981 lli->lli_inherit_depth = 0;
2984 ll_dir_default_lmv_inherit(dir, inode);
2987 if (lli->lli_default_lsm_md)
2989 "%s "DFID" depth %hu %s default LMV inherit depth %hu\n",
2990 de->d_name.name, PFID(&lli->lli_fid), lli->lli_dir_depth,
2991 lli->lli_default_lmv_set ? "server" : "client",
2992 lli->lli_inherit_depth);
2995 void ll_truncate_inode_pages_final(struct inode *inode, struct cl_io *io)
2997 struct address_space *mapping = &inode->i_data;
2998 unsigned long nrpages;
2999 unsigned long flags;
3001 LASSERTF(io == NULL || inode_is_locked(inode), "io %p (type %d)\n",
3002 io, io ? io->ci_type : 0);
3004 truncate_inode_pages_final(mapping);
3006 /* Workaround for LU-118: Note nrpages may not be totally updated when
3007 * truncate_inode_pages() returns, as there can be a page in the process
3008 * of deletion (inside __delete_from_page_cache()) in the specified
3009 * range. Thus mapping->nrpages can be non-zero when this function
3010 * returns even after truncation of the whole mapping. Only do this if
3011 * npages isn't already zero.
3013 nrpages = mapping->nrpages;
3015 ll_xa_lock_irqsave(&mapping->i_pages, flags);
3016 nrpages = mapping->nrpages;
3017 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
3018 } /* Workaround end */
3020 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu "
3021 "io %p (io_type %d), "
3022 "see https://jira.whamcloud.com/browse/LU-118\n",
3023 ll_i2sbi(inode)->ll_fsname,
3024 PFID(ll_inode2fid(inode)), inode, nrpages,
3025 io, io ? io->ci_type : 0);
3028 int ll_read_inode2(struct inode *inode, void *opaque)
3030 struct lustre_md *md = opaque;
3031 struct ll_inode_info *lli = ll_i2info(inode);
3035 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
3036 PFID(&lli->lli_fid), inode);
3038 /* Core attributes from the MDS first. This is a new inode, and
3039 * the VFS doesn't zero times in the core inode so we have to do
3040 * it ourselves. They will be overwritten by either MDS or OST
3041 * attributes - we just need to make sure they aren't newer.
3043 inode->i_mtime.tv_sec = 0;
3044 inode->i_atime.tv_sec = 0;
3045 inode->i_ctime.tv_sec = 0;
3047 rc = ll_update_inode(inode, md);
3051 /* OIDEBUG(inode); */
3053 #ifdef HAVE_BACKING_DEV_INFO
3054 /* initializing backing dev info. */
3055 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
3057 if (S_ISREG(inode->i_mode)) {
3058 struct ll_sb_info *sbi = ll_i2sbi(inode);
3059 inode->i_op = &ll_file_inode_operations;
3060 inode->i_fop = sbi->ll_fop;
3061 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
3063 } else if (S_ISDIR(inode->i_mode)) {
3064 inode->i_op = &ll_dir_inode_operations;
3065 inode->i_fop = &ll_dir_operations;
3067 } else if (S_ISLNK(inode->i_mode)) {
3068 inode->i_op = &ll_fast_symlink_inode_operations;
3071 inode->i_op = &ll_special_inode_operations;
3073 init_special_inode(inode, inode->i_mode,
3082 void ll_delete_inode(struct inode *inode)
3084 struct ll_inode_info *lli = ll_i2info(inode);
3087 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
3088 /* It is last chance to write out dirty pages,
3089 * otherwise we may lose data while umount.
3091 * If i_nlink is 0 then just discard data. This is safe because
3092 * local inode gets i_nlink 0 from server only for the last
3093 * unlink, so that file is not opened somewhere else
3095 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
3096 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
3099 ll_truncate_inode_pages_final(inode, NULL);
3100 ll_clear_inode(inode);
3106 /* ioctl commands shared between files and directories */
3107 int ll_iocontrol(struct inode *inode, struct file *file,
3108 unsigned int cmd, void __user *uarg)
3110 struct ll_sb_info *sbi = ll_i2sbi(inode);
3111 struct ptlrpc_request *req = NULL;
3117 RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
3118 case LL_IOC_GETVERSION:
3119 case FS_IOC_GETVERSION:
3120 RETURN(put_user(inode->i_generation, (int __user *)uarg));
3121 case FS_IOC_GETFLAGS: {
3122 struct mdt_body *body;
3123 struct md_op_data *op_data;
3125 if (!ll_access_ok(uarg, sizeof(int)))
3128 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3129 LUSTRE_OPC_ANY, NULL);
3130 if (IS_ERR(op_data))
3131 RETURN(PTR_ERR(op_data));
3133 op_data->op_valid = OBD_MD_FLFLAGS;
3134 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
3135 ll_finish_md_op_data(op_data);
3137 CERROR("%s: failure inode "DFID": rc = %d\n",
3138 sbi->ll_md_exp->exp_obd->obd_name,
3139 PFID(ll_inode2fid(inode)), rc);
3143 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3145 flags = body->mbo_flags;
3146 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
3147 * ext4 equivalent to please lsattr and other e2fsprogs tools
3149 if (flags & LUSTRE_ENCRYPT_FL)
3150 flags |= STATX_ATTR_ENCRYPTED;
3152 ptlrpc_req_finished(req);
3154 RETURN(put_user(flags, (int __user *)uarg));
3156 case FS_IOC_SETFLAGS: {
3158 struct md_op_data *op_data;
3159 struct cl_object *obj;
3160 struct fsxattr fa = { 0 };
3162 if (get_user(flags, (int __user *)uarg))
3165 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3166 if (flags & LUSTRE_PROJINHERIT_FL)
3167 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3169 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3174 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3175 LUSTRE_OPC_ANY, NULL);
3176 if (IS_ERR(op_data))
3177 RETURN(PTR_ERR(op_data));
3179 op_data->op_attr_flags = flags;
3180 op_data->op_xvalid |= OP_XVALID_FLAGS;
3181 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3182 ll_finish_md_op_data(op_data);
3183 ptlrpc_req_finished(req);
3187 ll_update_inode_flags(inode, flags);
3189 obj = ll_i2info(inode)->lli_clob;
3193 OBD_ALLOC_PTR(attr);
3197 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3202 case FS_IOC_FSGETXATTR:
3203 RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
3204 case FS_IOC_FSSETXATTR:
3205 RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
3206 case LL_IOC_PROJECT:
3207 RETURN(ll_ioctl_project(file, cmd, uarg));
3208 case IOC_OBD_STATFS:
3209 RETURN(ll_obd_statfs(inode, uarg));
3210 case LL_IOC_GET_MDTIDX: {
3211 if (!ll_access_ok(uarg, sizeof(rc)))
3214 rc = ll_get_mdt_idx(inode);
3218 if (put_user(rc, (int __user *)uarg))
3223 case LL_IOC_FLUSHCTX:
3224 RETURN(ll_flush_ctx(inode));
3225 #ifdef HAVE_LUSTRE_CRYPTO
3226 case LL_IOC_ADD_ENCRYPTION_KEY:
3227 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3229 rc = llcrypt_ioctl_add_key(file, uarg);
3230 #ifdef CONFIG_LL_ENCRYPTION
3231 if (!rc && S_ISDIR(inode->i_mode))
3232 sptlrpc_enc_pool_add_user();
3235 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
3236 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3238 RETURN(llcrypt_ioctl_get_key_status(file, uarg));
3239 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
3240 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3242 RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
3243 case LL_IOC_SET_ENCRYPTION_POLICY:
3244 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3246 RETURN(llcrypt_ioctl_set_policy(file, uarg));
3247 case LL_IOC_REMOVE_ENCRYPTION_KEY:
3248 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3250 RETURN(llcrypt_ioctl_remove_key(file, uarg));
3251 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
3252 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3254 RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
3256 case LL_IOC_GETPARENT:
3257 RETURN(ll_getparent(file, uarg));
3258 case LL_IOC_PATH2FID:
3259 if (copy_to_user(uarg, ll_inode2fid(inode),
3260 sizeof(struct lu_fid)))
3263 case LL_IOC_UNLOCK_FOREIGN: {
3264 struct dentry *dentry = file_dentry(file);
3266 /* if not a foreign symlink do nothing */
3267 if (ll_foreign_is_removable(dentry, true)) {
3269 "prevent unlink of non-foreign file ("DFID")\n",
3270 PFID(ll_inode2fid(inode)));
3271 RETURN(-EOPNOTSUPP);
3275 case OBD_IOC_FID2PATH:
3276 RETURN(ll_fid2path(inode, uarg));
3277 #ifdef OBD_IOC_GETNAME_OLD
3278 case_OBD_IOC_DEPRECATED_FT(OBD_IOC_GETNAME_OLD,
3279 sbi->ll_md_exp->exp_obd->obd_name, 2, 16);
3281 case OBD_IOC_GETDTNAME:
3282 case OBD_IOC_GETMDNAME:
3283 RETURN(ll_get_obd_name(inode, cmd, uarg));
3291 int ll_flush_ctx(struct inode *inode)
3293 struct ll_sb_info *sbi = ll_i2sbi(inode);
3295 CDEBUG(D_SEC, "flush context for user %d\n",
3296 from_kuid(&init_user_ns, current_uid()));
3298 obd_set_info_async(NULL, sbi->ll_md_exp,
3299 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3301 obd_set_info_async(NULL, sbi->ll_dt_exp,
3302 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3307 /* umount -f client means force down, don't save state */
3308 void ll_umount_begin(struct super_block *sb)
3310 struct ll_sb_info *sbi = ll_s2sbi(sb);
3311 struct obd_device *obd;
3312 struct obd_ioctl_data *ioc_data;
3316 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3317 sb->s_count, atomic_read(&sb->s_active));
3319 obd = class_exp2obd(sbi->ll_md_exp);
3321 CERROR("Invalid MDC connection handle %#llx\n",
3322 sbi->ll_md_exp->exp_handle.h_cookie);
3328 obd = class_exp2obd(sbi->ll_dt_exp);
3330 CERROR("Invalid LOV connection handle %#llx\n",
3331 sbi->ll_dt_exp->exp_handle.h_cookie);
3337 OBD_ALLOC_PTR(ioc_data);
3339 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_md_exp,
3340 sizeof *ioc_data, ioc_data, NULL);
3342 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_dt_exp,
3343 sizeof *ioc_data, ioc_data, NULL);
3345 OBD_FREE_PTR(ioc_data);
3348 /* Really, we'd like to wait until there are no requests outstanding,
3349 * and then continue. For now, we just periodically checking for vfs
3350 * to decrement mnt_cnt and hope to finish it within 10sec.
3354 !may_umount(sbi->ll_mnt.mnt)) {
3362 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3364 struct ll_sb_info *sbi = ll_s2sbi(sb);
3365 char *profilenm = get_profile_name(sb);
3369 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3370 read_only = *flags & MS_RDONLY;
3371 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3372 sizeof(KEY_READ_ONLY),
3373 KEY_READ_ONLY, sizeof(read_only),
3376 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3377 profilenm, read_only ?
3378 "read-only" : "read-write", err);
3383 sb->s_flags |= SB_RDONLY;
3385 sb->s_flags &= ~SB_RDONLY;
3387 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3388 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3389 read_only ? "read-only" : "read-write");
3395 * Cleanup the open handle that is cached on MDT-side.
3397 * For open case, the client side open handling thread may hit error
3398 * after the MDT grant the open. Under such case, the client should
3399 * send close RPC to the MDT as cleanup; otherwise, the open handle
3400 * on the MDT will be leaked there until the client umount or evicted.
3402 * In further, if someone unlinked the file, because the open handle
3403 * holds the reference on such file/object, then it will block the
3404 * subsequent threads that want to locate such object via FID.
3406 * \param[in] sb super block for this file-system
3407 * \param[in] open_req pointer to the original open request
3409 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3411 struct mdt_body *body;
3412 struct md_op_data *op_data;
3413 struct ptlrpc_request *close_req = NULL;
3414 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3417 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3418 OBD_ALLOC_PTR(op_data);
3419 if (op_data == NULL) {
3420 CWARN("%s: cannot allocate op_data to release open handle for "
3421 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3426 op_data->op_fid1 = body->mbo_fid1;
3427 op_data->op_open_handle = body->mbo_open_handle;
3428 op_data->op_mod_time = ktime_get_real_seconds();
3429 md_close(exp, op_data, NULL, &close_req);
3430 ptlrpc_req_finished(close_req);
3431 ll_finish_md_op_data(op_data);
3436 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3437 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3438 struct lustre_md *md)
3440 struct ll_sb_info *sbi = ll_i2sbi(inode);
3441 struct ptlrpc_request *req = NULL;
3442 union lmv_mds_md *lmm = NULL;
3446 LASSERT(is_root_inode(inode));
3447 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3448 LASSERT(!md->default_lmv);
3450 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3452 GET_DEFAULT_LAYOUT_ROOT);
3453 if (rc && rc != -ENODATA)
3458 rc = md_unpackmd(sbi->ll_md_exp, &md->default_lmv, lmm, size);
3467 ptlrpc_req_finished(req);
3471 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3472 struct super_block *sb, struct lookup_intent *it)
3474 struct ll_sb_info *sbi = NULL;
3475 struct lustre_md md = { NULL };
3476 bool default_lmv_deleted = false;
3481 LASSERT(*inode || sb);
3482 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3483 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3484 sbi->ll_md_exp, &md);
3489 * clear default_lmv only if intent_getattr reply doesn't contain it.
3490 * but it needs to be done after iget, check this early because
3491 * ll_update_lsm_md() may change md.
3493 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3494 S_ISDIR(md.body->mbo_mode) && !md.default_lmv) {
3495 if (unlikely(*inode && is_root_inode(*inode) &&
3496 !fid_is_root(&sbi->ll_root_fid))) {
3497 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3502 if (!md.default_lmv)
3503 default_lmv_deleted = true;
3507 rc = ll_update_inode(*inode, &md);
3511 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3512 struct lu_fid *fid1 = &md.body->mbo_fid1;
3514 LASSERT(sb != NULL);
3517 * At this point server returns to client's same fid as client
3518 * generated for creating. So using ->fid1 is okay here.
3520 if (!fid_is_sane(fid1)) {
3521 CERROR("%s: Fid is insane "DFID"\n",
3522 sbi->ll_fsname, PFID(fid1));
3523 GOTO(out, rc = -EINVAL);
3526 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3527 if (IS_ERR(*inode)) {
3529 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3531 CERROR("new_inode -fatal: rc %d\n", rc);
3536 /* Handling piggyback layout lock.
3537 * Layout lock can be piggybacked by getattr and open request.
3538 * The lsm can be applied to inode only if it comes with a layout lock
3539 * otherwise correct layout may be overwritten, for example:
3540 * 1. proc1: mdt returns a lsm but not granting layout
3541 * 2. layout was changed by another client
3542 * 3. proc2: refresh layout and layout lock granted
3543 * 4. proc1: to apply a stale layout */
3544 if (it != NULL && it->it_lock_mode != 0) {
3545 struct lustre_handle lockh;
3546 struct ldlm_lock *lock;
3548 lockh.cookie = it->it_lock_handle;
3549 lock = ldlm_handle2lock(&lockh);
3550 LASSERT(lock != NULL);
3551 if (ldlm_has_layout(lock)) {
3552 struct cl_object_conf conf;
3554 memset(&conf, 0, sizeof(conf));
3555 conf.coc_opc = OBJECT_CONF_SET;
3556 conf.coc_inode = *inode;
3557 conf.coc_lock = lock;
3558 conf.u.coc_layout = md.layout;
3559 (void)ll_layout_conf(*inode, &conf);
3561 LDLM_LOCK_PUT(lock);
3564 if (default_lmv_deleted)
3565 ll_update_default_lsm_md(*inode, &md);
3567 /* we may want to apply some policy for foreign file/dir */
3568 if (ll_sbi_has_foreign_symlink(sbi)) {
3569 rc = ll_manage_foreign(*inode, &md);
3577 /* cleanup will be done if necessary */
3578 md_free_lustre_md(sbi->ll_md_exp, &md);
3580 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3581 ll_intent_drop_lock(it);
3582 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3588 int ll_obd_statfs(struct inode *inode, void __user *uarg)
3590 struct ll_sb_info *sbi = NULL;
3591 struct obd_export *exp;
3592 struct obd_ioctl_data *data = NULL;
3597 sbi = ll_i2sbi(inode);
3599 GOTO(out_statfs, rc = -EINVAL);
3601 rc = obd_ioctl_getdata(&data, &len, uarg);
3603 GOTO(out_statfs, rc);
3605 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3606 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3607 GOTO(out_statfs, rc = -EINVAL);
3609 if (data->ioc_inllen1 != sizeof(__u32) ||
3610 data->ioc_inllen2 != sizeof(__u32) ||
3611 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3612 data->ioc_plen2 != sizeof(struct obd_uuid))
3613 GOTO(out_statfs, rc = -EINVAL);
3615 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3616 if (type & LL_STATFS_LMV)
3617 exp = sbi->ll_md_exp;
3618 else if (type & LL_STATFS_LOV)
3619 exp = sbi->ll_dt_exp;
3621 GOTO(out_statfs, rc = -ENODEV);
3623 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3625 GOTO(out_statfs, rc);
3627 OBD_FREE_LARGE(data, len);
3632 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3633 * be called early to avoid deadlock.
3635 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3637 if (op_data->op_mea2_sem) {
3638 up_read_non_owner(op_data->op_mea2_sem);
3639 op_data->op_mea2_sem = NULL;
3642 if (op_data->op_mea1_sem) {
3643 up_read_non_owner(op_data->op_mea1_sem);
3644 op_data->op_mea1_sem = NULL;
3648 /* this function prepares md_op_data hint for passing it down to MD stack. */
3649 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3650 struct inode *i1, struct inode *i2,
3651 const char *name, size_t namelen,
3652 __u32 mode, enum md_op_code opc,
3655 struct llcrypt_name fname = { 0 };
3658 LASSERT(i1 != NULL);
3661 /* Do not reuse namelen for something else. */
3663 return ERR_PTR(-EINVAL);
3665 if ((!IS_ENCRYPTED(i1) ||
3666 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3667 namelen > ll_i2sbi(i1)->ll_namelen)
3668 return ERR_PTR(-ENAMETOOLONG);
3670 /* "/" is not valid name, but it's allowed */
3671 if (!lu_name_is_valid_2(name, namelen) &&
3672 strncmp("/", name, namelen) != 0)
3673 return ERR_PTR(-EINVAL);
3676 if (op_data == NULL)
3677 OBD_ALLOC_PTR(op_data);
3679 if (op_data == NULL)
3680 return ERR_PTR(-ENOMEM);
3682 ll_i2gids(op_data->op_suppgids, i1, i2);
3683 /* If the client is using a subdir mount and looks at what it sees as
3684 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3686 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3687 !fid_is_root(ll_inode2fid(i1)) &&
3688 name && namelen == strlen(dot_fscrypt_name) &&
3689 strncmp(name, dot_fscrypt_name, namelen) == 0))
3690 lu_root_fid(&op_data->op_fid1);
3692 op_data->op_fid1 = *ll_inode2fid(i1);
3694 if (S_ISDIR(i1->i_mode)) {
3695 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3696 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3697 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3698 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3702 op_data->op_fid2 = *ll_inode2fid(i2);
3703 if (S_ISDIR(i2->i_mode)) {
3705 /* i2 is typically a child of i1, and MUST be
3706 * further from the root to avoid deadlocks.
3708 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3709 op_data->op_mea2_sem =
3710 &ll_i2info(i2)->lli_lsm_sem;
3712 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3715 fid_zero(&op_data->op_fid2);
3718 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3719 op_data->op_cli_flags |= CLI_HASH64;
3721 if (ll_need_32bit_api(ll_i2sbi(i1)))
3722 op_data->op_cli_flags |= CLI_API32;
3724 if ((i2 && is_root_inode(i2)) ||
3725 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3726 /* In case of lookup, ll_setup_filename() has already been
3727 * called in ll_lookup_it(), so just take provided name.
3728 * Also take provided name if we are dealing with root inode.
3730 fname.disk_name.name = (unsigned char *)name;
3731 fname.disk_name.len = namelen;
3732 } else if (name && namelen) {
3733 struct qstr dname = QSTR_INIT(name, namelen);
3735 struct lu_fid *pfid = NULL;
3739 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3740 /* special case when called from ll_link() */
3745 lookup = (int)(opc == LUSTRE_OPC_ANY);
3747 if (opc == LUSTRE_OPC_ANY && lookup)
3749 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3751 ll_finish_md_op_data(op_data);
3754 if (pfid && !fid_is_zero(pfid)) {
3756 op_data->op_fid2 = fid;
3757 op_data->op_bias = MDS_FID_OP;
3759 if (fname.disk_name.name &&
3760 fname.disk_name.name != (unsigned char *)name) {
3761 /* op_data->op_name must be freed after use */
3762 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3766 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3767 * are LUSTRE_OPC_ANY
3769 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3770 op_data->op_code = LUSTRE_OPC_ANY;
3772 op_data->op_code = opc;
3773 op_data->op_name = fname.disk_name.name;
3774 op_data->op_namelen = fname.disk_name.len;
3775 op_data->op_mode = mode;
3776 op_data->op_mod_time = ktime_get_real_seconds();
3777 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3778 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3779 op_data->op_cap = current_cap();
3780 op_data->op_mds = 0;
3781 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3782 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3783 op_data->op_bias |= MDS_CREATE_VOLATILE;
3785 op_data->op_data = data;
3790 void ll_finish_md_op_data(struct md_op_data *op_data)
3792 ll_unlock_md_op_lsm(op_data);
3793 ll_security_release_secctx(op_data->op_file_secctx,
3794 op_data->op_file_secctx_size,
3795 op_data->op_file_secctx_slot);
3796 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3797 /* allocated via ll_setup_filename called
3798 * from ll_prep_md_op_data
3800 kfree(op_data->op_name);
3801 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3802 OBD_FREE_PTR(op_data);
3805 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3807 struct ll_sb_info *sbi;
3810 LASSERT(seq && dentry);
3811 sbi = ll_s2sbi(dentry->d_sb);
3813 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3814 seq_puts(seq, "nolock");
3816 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3817 /* match_table in some cases has patterns for both enabled and
3818 * disabled cases. Ignore 'no'xxx versions if bit is set.
3820 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3821 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3822 if (ll_sbi_flags_name[i].token ==
3823 LL_SBI_FOREIGN_SYMLINK) {
3824 seq_show_option(seq, "foreign_symlink",
3825 sbi->ll_foreign_symlink_prefix);
3827 seq_printf(seq, ",%s",
3828 ll_sbi_flags_name[i].pattern);
3831 /* You can have either localflock or flock but not
3832 * both. If localflock is set don't print flock or
3835 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3837 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3838 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3839 seq_printf(seq, ",%s",
3840 ll_sbi_flags_name[i].pattern);
3844 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3850 * Get obd name by cmd, and copy out to user space
3852 int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg)
3854 struct ll_sb_info *sbi = ll_i2sbi(inode);
3855 struct obd_device *obd;
3858 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3859 obd = class_exp2obd(sbi->ll_dt_exp);
3860 else if (cmd == OBD_IOC_GETMDNAME)
3861 obd = class_exp2obd(sbi->ll_md_exp);
3868 if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1))
3875 struct work_struct db_work;
3876 struct dentry *db_dentry;
3877 /* Let's hope the path is not too long, 32 bytes for the work struct
3880 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3883 static void ll_dput_later(struct work_struct *work)
3885 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3887 dput(db->db_dentry);
3888 free_page((unsigned long)db);
3891 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3898 p.mnt = current->fs->root.mnt;
3900 path = d_path(&p, buf, bufsize);
3905 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3907 struct dname_buf *db;
3909 struct dentry *dentry = NULL;
3911 /* this can be called inside spin lock so use GFP_ATOMIC. */
3912 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3915 dentry = d_find_alias(inode);
3917 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3920 /* The below message is checked in recovery-small.sh test_24b */
3922 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3923 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3924 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3925 PFID(ll_inode2fid(inode)),
3926 (path && !IS_ERR(path)) ? path : "", ioret);
3928 if (dentry != NULL) {
3929 /* We cannot dput here since if we happen to be the last holder
3930 * then we can end up waiting for page evictions that
3931 * in turn wait for RPCs that need this instance of ptlrpcd
3932 * (callng brw_interpret->*page_completion*->vmpage_error->here)
3935 INIT_WORK(&db->db_work, ll_dput_later);
3936 db->db_dentry = dentry;
3937 schedule_work(&db->db_work);
3940 free_page((unsigned long)db);
3944 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3945 struct lov_user_md **kbuf)
3947 struct lov_user_md lum;
3951 if (copy_from_user(&lum, md, sizeof(lum)))
3954 lum_size = ll_lov_user_md_size(&lum);
3958 OBD_ALLOC_LARGE(*kbuf, lum_size);
3962 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3963 OBD_FREE_LARGE(*kbuf, lum_size);
3971 * Compute llite root squash state after a change of root squash
3972 * configuration setting or add/remove of a lnet nid
3974 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3976 struct root_squash_info *squash = &sbi->ll_squash;
3979 struct lnet_processid id;
3981 /* Update norootsquash flag */
3982 spin_lock(&squash->rsi_lock);
3983 if (list_empty(&squash->rsi_nosquash_nids))
3984 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3986 /* Do not apply root squash as soon as one of our NIDs is
3987 * in the nosquash_nids list */
3990 while (LNetGetId(i++, &id) != -ENOENT) {
3991 if (nid_is_lo0(&id.nid))
3993 if (cfs_match_nid(&id.nid,
3994 &squash->rsi_nosquash_nids)) {
4000 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4002 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4004 spin_unlock(&squash->rsi_lock);
4008 * Parse linkea content to extract information about a given hardlink
4010 * \param[in] ldata - Initialized linkea data
4011 * \param[in] linkno - Link identifier
4012 * \param[out] parent_fid - The entry's parent FID
4013 * \param[out] ln - Entry name destination buffer
4015 * \retval 0 on success
4016 * \retval Appropriate negative error code on failure
4018 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
4019 struct lu_fid *parent_fid, struct lu_name *ln)
4025 rc = linkea_init_with_rec(ldata);
4029 if (linkno >= ldata->ld_leh->leh_reccount)
4030 /* beyond last link */
4033 linkea_first_entry(ldata);
4034 for (idx = 0; ldata->ld_lee != NULL; idx++) {
4035 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
4040 linkea_next_entry(ldata);
4050 * Get parent FID and name of an identified link. Operation is performed for
4051 * a given link number, letting the caller iterate over linkno to list one or
4052 * all links of an entry.
4054 * \param[in] file - File descriptor against which to perform the operation
4055 * \param[in,out] arg - User-filled structure containing the linkno to operate
4056 * on and the available size. It is eventually filled with
4057 * the requested information or left untouched on error
4059 * \retval - 0 on success
4060 * \retval - Appropriate negative error code on failure
4062 int ll_getparent(struct file *file, struct getparent __user *arg)
4064 struct inode *inode = file_inode(file);
4065 struct linkea_data *ldata;
4066 struct lu_buf buf = LU_BUF_NULL;
4068 struct lu_fid parent_fid;
4075 if (!capable(CAP_DAC_READ_SEARCH) &&
4076 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
4079 if (get_user(name_size, &arg->gp_name_size))
4082 if (get_user(linkno, &arg->gp_linkno))
4085 if (name_size > PATH_MAX)
4088 OBD_ALLOC(ldata, sizeof(*ldata));
4092 rc = linkea_data_new(ldata, &buf);
4094 GOTO(ldata_free, rc);
4096 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
4097 buf.lb_len, OBD_MD_FLXATTR);
4101 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
4105 if (ln.ln_namelen >= name_size)
4106 GOTO(lb_free, rc = -EOVERFLOW);
4108 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
4109 GOTO(lb_free, rc = -EFAULT);
4111 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
4112 GOTO(lb_free, rc = -EFAULT);
4114 if (put_user('\0', arg->gp_name + ln.ln_namelen))
4115 GOTO(lb_free, rc = -EFAULT);
4120 OBD_FREE(ldata, sizeof(*ldata));