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);
1277 lli->lli_inode_lock_owner = NULL;
1280 #define MAX_STRING_SIZE 128
1282 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1283 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1285 struct lustre_sb_info *lsi = s2lsi(sb);
1286 char buf[MAX_STRING_SIZE];
1290 err = bdi_init(&lsi->lsi_bdi);
1294 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1295 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1296 lsi->lsi_bdi.name = "lustre";
1297 va_start(args, fmt);
1298 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1300 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1303 sb->s_bdi = &lsi->lsi_bdi;
1307 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1309 int ll_fill_super(struct super_block *sb)
1311 struct lustre_profile *lprof = NULL;
1312 struct lustre_sb_info *lsi = s2lsi(sb);
1313 struct ll_sb_info *sbi = NULL;
1314 char *dt = NULL, *md = NULL;
1315 char *profilenm = get_profile_name(sb);
1316 struct config_llog_instance *cfg;
1317 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1318 const int instlen = LUSTRE_MAXINSTANCE + 2;
1319 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1320 char name[MAX_STRING_SIZE];
1329 /* for ASLR, to map between cfg_instance and hashed ptr */
1330 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1331 profilenm, cfg_instance, sb);
1333 CFS_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1337 GOTO(out_free_cfg, err = -ENOMEM);
1339 /* client additional sb info */
1340 lsi->lsi_llsbi = sbi = ll_init_sbi(lsi);
1342 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1344 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1346 GOTO(out_free_cfg, err);
1348 /* LSI_FILENAME_ENC is only used by embedded llcrypt */
1349 #ifdef CONFIG_LL_ENCRYPTION
1350 if (ll_sb_has_test_dummy_encryption(sb))
1351 /* enable filename encryption by default for dummy enc mode */
1352 lsi->lsi_flags |= LSI_FILENAME_ENC;
1354 /* filename encryption is disabled by default */
1355 lsi->lsi_flags &= ~LSI_FILENAME_ENC;
1358 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1359 sb->s_d_op = &ll_d_ops;
1362 generate_random_uuid(uuid.b);
1363 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1365 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1368 len = strlen(profilenm);
1369 ptr = strrchr(profilenm, '-');
1370 if (ptr && (strcmp(ptr, "-client") == 0))
1373 if (len > LUSTRE_MAXFSNAME) {
1374 if (unlikely(len >= MAX_STRING_SIZE))
1375 len = MAX_STRING_SIZE - 1;
1376 strncpy(name, profilenm, len);
1378 err = -ENAMETOOLONG;
1379 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1380 name, LUSTRE_MAXFSNAME, err);
1381 GOTO(out_free_cfg, err);
1383 strncpy(sbi->ll_fsname, profilenm, len);
1384 sbi->ll_fsname[len] = '\0';
1387 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1388 profilenm, cfg_instance);
1390 err = super_setup_bdi_name(sb, "%s", name);
1392 GOTO(out_free_cfg, err);
1394 /* disable kernel readahead */
1395 sb->s_bdi->ra_pages = 0;
1396 #ifdef HAVE_BDI_IO_PAGES
1397 sb->s_bdi->io_pages = 0;
1399 sb->s_bdi->capabilities |= LL_BDI_CAP_FLAGS;
1400 #ifdef SB_I_CGROUPWB
1401 sb->s_iflags |= SB_I_CGROUPWB;
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))
1994 ll_inode_lock(inode);
1995 rc = simple_setattr(&init_user_ns, dentry, &op_data->op_attr);
1996 if (S_ISREG(inode->i_mode))
1997 ll_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 static 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 /* VFS has locked the inode before calling this */
2228 ll_set_inode_lock_owner(inode);
2230 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2231 "valid %x, hsm_import %d\n",
2232 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2233 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2236 if (attr->ia_valid & ATTR_SIZE) {
2237 /* Check new size against VFS/VM file size limit and rlimit */
2238 rc = inode_newsize_ok(inode, attr->ia_size);
2242 /* The maximum Lustre file size is variable, based on the
2243 * OST maximum object size and number of stripes. This
2244 * needs another check in addition to the VFS check above. */
2245 if (attr->ia_size > ll_file_maxbytes(inode)) {
2246 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2247 PFID(&lli->lli_fid), attr->ia_size,
2248 ll_file_maxbytes(inode));
2249 GOTO(clear, rc = -EFBIG);
2252 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2255 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2256 if (attr->ia_valid & TIMES_SET_FLAGS) {
2257 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2258 !capable(CAP_FOWNER))
2259 GOTO(clear, rc = -EPERM);
2262 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2263 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2264 (attr->ia_valid & ATTR_CTIME)) {
2265 attr->ia_ctime = current_time(inode);
2266 xvalid |= OP_XVALID_CTIME_SET;
2268 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2269 (attr->ia_valid & ATTR_ATIME)) {
2270 attr->ia_atime = current_time(inode);
2271 attr->ia_valid |= ATTR_ATIME_SET;
2273 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2274 (attr->ia_valid & ATTR_MTIME)) {
2275 attr->ia_mtime = current_time(inode);
2276 attr->ia_valid |= ATTR_MTIME_SET;
2279 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2280 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2281 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2282 ktime_get_real_seconds());
2284 if (S_ISREG(inode->i_mode))
2285 ll_inode_unlock(inode);
2287 /* We always do an MDS RPC, even if we're only changing the size;
2288 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2290 OBD_ALLOC_PTR(op_data);
2291 if (op_data == NULL)
2292 GOTO(out, rc = -ENOMEM);
2294 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2295 /* If we are changing file size, file content is
2296 * modified, flag it.
2298 xvalid |= OP_XVALID_OWNEROVERRIDE;
2299 op_data->op_bias |= MDS_DATA_MODIFIED;
2300 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2303 if (attr->ia_valid & ATTR_FILE) {
2304 struct ll_file_data *fd = attr->ia_file->private_data;
2306 if (fd->fd_lease_och)
2307 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2310 op_data->op_attr = *attr;
2311 op_data->op_xvalid = xvalid;
2313 rc = ll_md_setattr(dentry, op_data);
2316 lli->lli_synced_to_mds = false;
2318 if (!S_ISREG(inode->i_mode) || hsm_import)
2321 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2322 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2323 xvalid & OP_XVALID_CTIME_SET) {
2324 bool cached = false;
2326 rc = pcc_inode_setattr(inode, attr, &cached);
2329 CERROR("%s: PCC inode "DFID" setattr failed: "
2331 ll_i2sbi(inode)->ll_fsname,
2332 PFID(&lli->lli_fid), rc);
2336 unsigned int flags = 0;
2338 /* For truncate and utimes sending attributes to OSTs,
2339 * setting mtime/atime to the past will be performed
2340 * under PW [0:EOF] extent lock (new_size:EOF for
2341 * truncate). It may seem excessive to send mtime/atime
2342 * updates to OSTs when not setting times to past, but
2343 * it is necessary due to possible time
2344 * de-synchronization between MDT inode and OST objects
2346 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2347 xvalid |= OP_XVALID_FLAGS;
2348 flags = LUSTRE_ENCRYPT_FL;
2349 /* Call to ll_io_zero_page is not necessary if
2350 * truncating on PAGE_SIZE boundary, because
2351 * whole pages will be wiped.
2352 * In case of Direct IO, all we need is to set
2355 if (attr->ia_valid & ATTR_SIZE &&
2356 attr->ia_size & ~PAGE_MASK &&
2357 !(attr->ia_valid & ATTR_FILE &&
2358 attr->ia_file->f_flags & O_DIRECT)) {
2360 attr->ia_size & (PAGE_SIZE - 1);
2362 rc = ll_io_zero_page(inode,
2363 attr->ia_size >> PAGE_SHIFT,
2364 offset, PAGE_SIZE - offset);
2368 /* If encrypted volatile file without the key,
2369 * we need to fetch size from reference file,
2370 * and set it on OST objects. This happens when
2371 * migrating or extending an encrypted file
2374 if (filename_is_volatile(dentry->d_name.name,
2377 llcrypt_require_key(inode) == -ENOKEY) {
2378 struct file *ref_file;
2379 struct inode *ref_inode;
2380 struct ll_inode_info *ref_lli;
2381 struct cl_object *ref_obj;
2382 struct cl_attr ref_attr = { 0 };
2386 rc = volatile_ref_file(
2387 dentry->d_name.name,
2393 ref_inode = file_inode(ref_file);
2396 GOTO(out, rc = -EINVAL);
2399 env = cl_env_get(&refcheck);
2401 GOTO(out, rc = PTR_ERR(env));
2403 ref_lli = ll_i2info(ref_inode);
2404 ref_obj = ref_lli->lli_clob;
2405 cl_object_attr_lock(ref_obj);
2406 rc = cl_object_attr_get(env, ref_obj,
2408 cl_object_attr_unlock(ref_obj);
2409 cl_env_put(env, &refcheck);
2414 attr->ia_valid |= ATTR_SIZE;
2415 attr->ia_size = ref_attr.cat_size;
2418 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2422 /* If the file was restored, it needs to set dirty flag.
2424 * We've already sent MDS_DATA_MODIFIED flag in
2425 * ll_md_setattr() for truncate. However, the MDT refuses to
2426 * set the HS_DIRTY flag on released files, so we have to set
2427 * it again if the file has been restored. Please check how
2428 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2430 * Please notice that if the file is not released, the previous
2431 * MDS_DATA_MODIFIED has taken effect and usually
2432 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2433 * This way we can save an RPC for common open + trunc
2435 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2436 struct hsm_state_set hss = {
2437 .hss_valid = HSS_SETMASK,
2438 .hss_setmask = HS_DIRTY,
2442 rc2 = ll_hsm_state_set(inode, &hss);
2443 /* truncate and write can happen at the same time, so that
2444 * the file can be set modified even though the file is not
2445 * restored from released state, and ll_hsm_state_set() is
2446 * not applicable for the file, and rc2 < 0 is normal in this
2449 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2450 PFID(ll_inode2fid(inode)), rc2);
2455 if (op_data != NULL)
2456 ll_finish_md_op_data(op_data);
2458 if (S_ISREG(inode->i_mode)) {
2459 ll_inode_lock(inode);
2460 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2461 inode_dio_wait(inode);
2462 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2463 * flag. ll_update_inode (called from ll_md_setattr), clears
2464 * inode flags, so there is a gap where S_NOSEC is not set.
2465 * This can cause a writer to take the i_mutex unnecessarily,
2466 * but this is safe to do and should be rare. */
2467 inode_has_no_xattr(inode);
2471 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2472 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2473 ktime_us_delta(ktime_get(), kstart));
2475 ll_clear_inode_lock_owner(inode);
2480 int ll_setattr(struct user_namespace *mnt_userns, struct dentry *de,
2483 int mode = de->d_inode->i_mode;
2484 enum op_xvalid xvalid = 0;
2487 rc = llcrypt_prepare_setattr(de, attr);
2491 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2492 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2493 xvalid |= OP_XVALID_OWNEROVERRIDE;
2495 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2496 (ATTR_SIZE|ATTR_MODE)) &&
2497 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2498 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2499 !(attr->ia_mode & S_ISGID))))
2500 attr->ia_valid |= ATTR_FORCE;
2502 if ((attr->ia_valid & ATTR_MODE) &&
2504 !(attr->ia_mode & S_ISUID) &&
2505 !(attr->ia_valid & ATTR_KILL_SUID))
2506 attr->ia_valid |= ATTR_KILL_SUID;
2508 if ((attr->ia_valid & ATTR_MODE) &&
2509 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2510 !(attr->ia_mode & S_ISGID) &&
2511 !(attr->ia_valid & ATTR_KILL_SGID))
2512 attr->ia_valid |= ATTR_KILL_SGID;
2514 return ll_setattr_raw(de, attr, xvalid, false);
2517 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2520 struct obd_statfs obd_osfs = { 0 };
2525 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2527 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2528 flags |= OBD_STATFS_NODELAY;
2530 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2534 osfs->os_type = LL_SUPER_MAGIC;
2536 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2537 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2539 if (osfs->os_state & OS_STATFS_SUM)
2542 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2543 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2546 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2547 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2550 osfs->os_bsize = obd_osfs.os_bsize;
2551 osfs->os_blocks = obd_osfs.os_blocks;
2552 osfs->os_bfree = obd_osfs.os_bfree;
2553 osfs->os_bavail = obd_osfs.os_bavail;
2555 /* If we have _some_ OSTs, but don't have as many free objects on the
2556 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2557 * to compensate, so that the "inodes in use" number is correct.
2558 * This should be kept in sync with lod_statfs() behaviour.
2560 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2561 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2563 osfs->os_ffree = obd_osfs.os_ffree;
2570 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2572 struct if_quotactl qctl = {
2573 .qc_cmd = LUSTRE_Q_GETQUOTA,
2574 .qc_type = PRJQUOTA,
2575 .qc_valid = QC_GENERAL,
2577 u64 limit, curblock;
2580 qctl.qc_id = ll_i2info(inode)->lli_projid;
2581 ret = quotactl_ioctl(inode->i_sb, &qctl);
2583 /* ignore errors if project ID does not have
2584 * a quota limit or feature unsupported.
2586 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2591 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2592 qctl.qc_dqblk.dqb_bsoftlimit :
2593 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2594 if (limit && sfs->f_blocks > limit) {
2595 curblock = (qctl.qc_dqblk.dqb_curspace +
2596 sfs->f_bsize - 1) / sfs->f_bsize;
2597 sfs->f_blocks = limit;
2598 sfs->f_bfree = sfs->f_bavail =
2599 (sfs->f_blocks > curblock) ?
2600 (sfs->f_blocks - curblock) : 0;
2603 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2604 qctl.qc_dqblk.dqb_isoftlimit :
2605 qctl.qc_dqblk.dqb_ihardlimit;
2606 if (limit && sfs->f_files > limit) {
2607 sfs->f_files = limit;
2608 sfs->f_ffree = (sfs->f_files >
2609 qctl.qc_dqblk.dqb_curinodes) ?
2610 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2616 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2618 struct super_block *sb = de->d_sb;
2619 struct obd_statfs osfs;
2620 __u64 fsid = huge_encode_dev(sb->s_dev);
2621 ktime_t kstart = ktime_get();
2624 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2626 /* Some amount of caching on the client is allowed */
2627 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2631 statfs_unpack(sfs, &osfs);
2633 /* We need to downshift for all 32-bit kernels, because we can't
2634 * tell if the kernel is being called via sys_statfs64() or not.
2635 * Stop before overflowing f_bsize - in which case it is better
2636 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2637 if (sizeof(long) < 8) {
2638 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2641 osfs.os_blocks >>= 1;
2642 osfs.os_bfree >>= 1;
2643 osfs.os_bavail >>= 1;
2647 sfs->f_blocks = osfs.os_blocks;
2648 sfs->f_bfree = osfs.os_bfree;
2649 sfs->f_bavail = osfs.os_bavail;
2650 sfs->f_fsid.val[0] = (__u32)fsid;
2651 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2652 if (ll_i2info(de->d_inode)->lli_projid &&
2653 test_bit(LLIF_PROJECT_INHERIT, &ll_i2info(de->d_inode)->lli_flags))
2654 return ll_statfs_project(de->d_inode, sfs);
2656 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2657 ktime_us_delta(ktime_get(), kstart));
2662 void ll_inode_size_lock(struct inode *inode)
2664 struct ll_inode_info *lli;
2666 LASSERT(!S_ISDIR(inode->i_mode));
2668 lli = ll_i2info(inode);
2669 mutex_lock(&lli->lli_size_mutex);
2670 lli->lli_size_lock_owner = current;
2673 void ll_inode_size_unlock(struct inode *inode)
2675 struct ll_inode_info *lli;
2677 lli = ll_i2info(inode);
2678 lli->lli_size_lock_owner = NULL;
2679 mutex_unlock(&lli->lli_size_mutex);
2682 int ll_inode_size_trylock(struct inode *inode)
2684 struct ll_inode_info *lli;
2686 LASSERT(!S_ISDIR(inode->i_mode));
2688 lli = ll_i2info(inode);
2689 return mutex_trylock(&lli->lli_size_mutex);
2692 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2694 /* do not clear encryption flag */
2695 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2696 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2697 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2698 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2700 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2703 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2705 struct ll_inode_info *lli = ll_i2info(inode);
2706 struct mdt_body *body = md->body;
2707 struct ll_sb_info *sbi = ll_i2sbi(inode);
2711 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2712 rc = cl_file_inode_init(inode, md);
2717 if (S_ISDIR(inode->i_mode)) {
2718 rc = ll_update_lsm_md(inode, md);
2723 if (body->mbo_valid & OBD_MD_FLACL)
2724 lli_replace_acl(lli, md);
2726 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2727 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2728 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2730 if (body->mbo_valid & OBD_MD_FLATIME) {
2731 if (body->mbo_atime > inode->i_atime.tv_sec)
2732 inode->i_atime.tv_sec = body->mbo_atime;
2733 lli->lli_atime = body->mbo_atime;
2736 if (body->mbo_valid & OBD_MD_FLMTIME) {
2737 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2739 "setting ino %lu mtime from %lld to %llu\n",
2740 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2742 inode->i_mtime.tv_sec = body->mbo_mtime;
2744 lli->lli_mtime = body->mbo_mtime;
2747 if (body->mbo_valid & OBD_MD_FLCTIME) {
2748 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2749 inode->i_ctime.tv_sec = body->mbo_ctime;
2750 lli->lli_ctime = body->mbo_ctime;
2753 if (body->mbo_valid & OBD_MD_FLBTIME)
2754 lli->lli_btime = body->mbo_btime;
2756 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2757 if (body->mbo_valid & OBD_MD_FLFLAGS)
2758 ll_update_inode_flags(inode, body->mbo_flags);
2759 if (body->mbo_valid & OBD_MD_FLMODE)
2760 inode->i_mode = (inode->i_mode & S_IFMT) |
2761 (body->mbo_mode & ~S_IFMT);
2763 if (body->mbo_valid & OBD_MD_FLTYPE)
2764 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2765 (body->mbo_mode & S_IFMT);
2767 LASSERT(inode->i_mode != 0);
2768 if (body->mbo_valid & OBD_MD_FLUID)
2769 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2770 if (body->mbo_valid & OBD_MD_FLGID)
2771 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2772 if (body->mbo_valid & OBD_MD_FLPROJID)
2773 lli->lli_projid = body->mbo_projid;
2774 if (body->mbo_valid & OBD_MD_FLNLINK) {
2775 spin_lock(&inode->i_lock);
2776 set_nlink(inode, body->mbo_nlink);
2777 spin_unlock(&inode->i_lock);
2779 if (body->mbo_valid & OBD_MD_FLRDEV)
2780 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2782 if (body->mbo_valid & OBD_MD_FLID) {
2783 /* FID shouldn't be changed! */
2784 if (fid_is_sane(&lli->lli_fid)) {
2785 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2786 "Trying to change FID "DFID
2787 " to the "DFID", inode "DFID"(%p)\n",
2788 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2789 PFID(ll_inode2fid(inode)), inode);
2791 lli->lli_fid = body->mbo_fid1;
2795 LASSERT(fid_seq(&lli->lli_fid) != 0);
2797 /* In case of encrypted file without the key, please do not lose
2798 * clear text size stored into lli_lazysize in ll_merge_attr(),
2799 * we will need it in ll_prepare_close().
2801 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2802 llcrypt_require_key(inode) == -ENOKEY)
2803 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2805 lli->lli_attr_valid = body->mbo_valid;
2806 if (body->mbo_valid & OBD_MD_FLSIZE) {
2807 i_size_write(inode, body->mbo_size);
2809 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2810 PFID(ll_inode2fid(inode)),
2811 (unsigned long long)body->mbo_size);
2813 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2814 inode->i_blocks = body->mbo_blocks;
2816 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2817 lli->lli_lazysize = body->mbo_size;
2818 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2819 lli->lli_lazyblocks = body->mbo_blocks;
2822 if (body->mbo_valid & OBD_MD_TSTATE) {
2823 /* Set LLIF_FILE_RESTORING if restore ongoing and
2824 * clear it when done to ensure to start again
2825 * glimpsing updated attrs
2827 if (body->mbo_t_state & MS_RESTORE)
2828 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2830 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2836 /* child default LMV is inherited from parent */
2837 static inline bool ll_default_lmv_inherited(struct lmv_stripe_md *pdmv,
2838 struct lmv_stripe_md *cdmv)
2843 if (pdmv->lsm_md_magic != cdmv->lsm_md_magic ||
2844 pdmv->lsm_md_stripe_count != cdmv->lsm_md_stripe_count ||
2845 pdmv->lsm_md_master_mdt_index != cdmv->lsm_md_master_mdt_index ||
2846 pdmv->lsm_md_hash_type != cdmv->lsm_md_hash_type)
2849 if (cdmv->lsm_md_max_inherit !=
2850 lmv_inherit_next(pdmv->lsm_md_max_inherit))
2853 if (cdmv->lsm_md_max_inherit_rr !=
2854 lmv_inherit_rr_next(pdmv->lsm_md_max_inherit_rr))
2860 /* if default LMV is implicitly inherited, subdir default LMV is maintained on
2863 static int ll_dir_default_lmv_inherit(struct inode *dir, struct inode *inode)
2865 struct ll_inode_info *plli = ll_i2info(dir);
2866 struct ll_inode_info *lli = ll_i2info(inode);
2867 struct lmv_stripe_md *plsm;
2868 struct lmv_stripe_md *lsm;
2873 /* ROOT default LMV is not inherited */
2874 if (is_root_inode(dir) ||
2875 !(exp_connect_flags2(ll_i2mdexp(dir)) &
2876 OBD_CONNECT2_DMV_IMP_INHERIT))
2879 /* nothing to do if no default LMV on both */
2880 if (!plli->lli_default_lsm_md && !lli->lli_default_lsm_md)
2883 /* subdir default LMV comes from disk */
2884 if (lli->lli_default_lsm_md && lli->lli_default_lmv_set)
2887 /* delete subdir default LMV if parent's is deleted or becomes
2890 down_read(&plli->lli_lsm_sem);
2891 plsm = plli->lli_default_lsm_md;
2892 if (!plsm || !lmv_is_inheritable(plsm->lsm_md_max_inherit)) {
2893 if (lli->lli_default_lsm_md && !lli->lli_default_lmv_set) {
2894 down_write(&lli->lli_lsm_sem);
2895 if (lli->lli_default_lsm_md &&
2896 !lli->lli_default_lmv_set) {
2897 lmv_free_memmd(lli->lli_default_lsm_md);
2898 lli->lli_default_lsm_md = NULL;
2899 lli->lli_inherit_depth = 0;
2901 up_write(&lli->lli_lsm_sem);
2903 GOTO(unlock_parent, rc = 0);
2906 /* do nothing if inherited LMV is unchanged */
2907 if (lli->lli_default_lsm_md) {
2909 down_read(&lli->lli_lsm_sem);
2910 if (!lli->lli_default_lmv_set)
2911 rc = lsm_md_inherited(plsm, lli->lli_default_lsm_md);
2912 up_read(&lli->lli_lsm_sem);
2914 GOTO(unlock_parent, rc = 0);
2917 /* inherit default LMV */
2918 down_write(&lli->lli_lsm_sem);
2919 if (lli->lli_default_lsm_md) {
2920 /* checked above, but in case of race, check again with lock */
2921 if (lli->lli_default_lmv_set)
2922 GOTO(unlock_child, rc = 0);
2923 /* always update subdir default LMV in case parent's changed */
2924 lsm = lli->lli_default_lsm_md;
2928 GOTO(unlock_child, rc = -ENOMEM);
2929 lli->lli_default_lsm_md = lsm;
2933 lsm->lsm_md_max_inherit = lmv_inherit_next(plsm->lsm_md_max_inherit);
2934 lsm->lsm_md_max_inherit_rr =
2935 lmv_inherit_rr_next(plsm->lsm_md_max_inherit_rr);
2936 lli->lli_inherit_depth = plli->lli_inherit_depth + 1;
2938 lsm_md_dump(D_INODE, lsm);
2942 up_write(&lli->lli_lsm_sem);
2944 up_read(&plli->lli_lsm_sem);
2949 enum lsm_sem_class {
2955 * Update directory depth and default LMV
2957 * Update directory depth to ROOT and inherit default LMV from parent if
2958 * parent's default LMV is inheritable. The default LMV set with command
2959 * "lfs setdirstripe -D ..." is stored on MDT, while the inherited default LMV
2960 * is generated at runtime on client side.
2962 * \param[in] dir parent directory inode
2963 * \param[in] de dentry
2965 void ll_update_dir_depth_dmv(struct inode *dir, struct dentry *de)
2967 struct inode *inode = de->d_inode;
2968 struct ll_inode_info *plli;
2969 struct ll_inode_info *lli;
2971 LASSERT(S_ISDIR(inode->i_mode));
2975 plli = ll_i2info(dir);
2976 lli = ll_i2info(inode);
2977 lli->lli_dir_depth = plli->lli_dir_depth + 1;
2978 if (lli->lli_default_lsm_md && lli->lli_default_lmv_set) {
2979 if (plli->lli_default_lsm_md) {
2980 down_read_nested(&plli->lli_lsm_sem, LSM_SEM_PARENT);
2981 down_read_nested(&lli->lli_lsm_sem, LSM_SEM_CHILD);
2982 if (lsm_md_inherited(plli->lli_default_lsm_md,
2983 lli->lli_default_lsm_md))
2984 lli->lli_inherit_depth =
2985 plli->lli_inherit_depth + 1;
2987 /* in case parent default LMV changed */
2988 lli->lli_inherit_depth = 0;
2989 up_read(&lli->lli_lsm_sem);
2990 up_read(&plli->lli_lsm_sem);
2992 /* in case parent default LMV deleted */
2993 lli->lli_inherit_depth = 0;
2996 ll_dir_default_lmv_inherit(dir, inode);
2999 if (lli->lli_default_lsm_md)
3001 "%s "DFID" depth %hu %s default LMV inherit depth %hu\n",
3002 de->d_name.name, PFID(&lli->lli_fid), lli->lli_dir_depth,
3003 lli->lli_default_lmv_set ? "server" : "client",
3004 lli->lli_inherit_depth);
3007 void ll_truncate_inode_pages_final(struct inode *inode)
3009 struct address_space *mapping = &inode->i_data;
3010 unsigned long nrpages;
3011 unsigned long flags;
3013 LASSERTF((inode->i_state & I_FREEING) || inode_is_locked(inode),
3014 DFID ":inode %p state %#lx, lli_flags %#lx\n",
3015 PFID(ll_inode2fid(inode)), inode, inode->i_state,
3016 ll_i2info(inode)->lli_flags);
3018 truncate_inode_pages_final(mapping);
3020 /* Workaround for LU-118: Note nrpages may not be totally updated when
3021 * truncate_inode_pages() returns, as there can be a page in the process
3022 * of deletion (inside __delete_from_page_cache()) in the specified
3023 * range. Thus mapping->nrpages can be non-zero when this function
3024 * returns even after truncation of the whole mapping. Only do this if
3025 * npages isn't already zero.
3027 nrpages = mapping->nrpages;
3029 ll_xa_lock_irqsave(&mapping->i_pages, flags);
3030 nrpages = mapping->nrpages;
3031 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
3032 } /* Workaround end */
3034 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu "
3035 "state %#lx, lli_flags %#lx, "
3036 "see https://jira.whamcloud.com/browse/LU-118\n",
3037 ll_i2sbi(inode)->ll_fsname,
3038 PFID(ll_inode2fid(inode)), inode, nrpages,
3039 inode->i_state, ll_i2info(inode)->lli_flags);
3042 int ll_read_inode2(struct inode *inode, void *opaque)
3044 struct lustre_md *md = opaque;
3045 struct ll_inode_info *lli = ll_i2info(inode);
3049 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
3050 PFID(&lli->lli_fid), inode);
3052 /* Core attributes from the MDS first. This is a new inode, and
3053 * the VFS doesn't zero times in the core inode so we have to do
3054 * it ourselves. They will be overwritten by either MDS or OST
3055 * attributes - we just need to make sure they aren't newer.
3057 inode->i_mtime.tv_sec = 0;
3058 inode->i_atime.tv_sec = 0;
3059 inode->i_ctime.tv_sec = 0;
3061 rc = ll_update_inode(inode, md);
3065 /* OIDEBUG(inode); */
3067 #ifdef HAVE_BACKING_DEV_INFO
3068 /* initializing backing dev info. */
3069 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
3071 if (S_ISREG(inode->i_mode)) {
3072 struct ll_sb_info *sbi = ll_i2sbi(inode);
3073 inode->i_op = &ll_file_inode_operations;
3074 inode->i_fop = sbi->ll_fop;
3075 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
3077 } else if (S_ISDIR(inode->i_mode)) {
3078 inode->i_op = &ll_dir_inode_operations;
3079 inode->i_fop = &ll_dir_operations;
3081 } else if (S_ISLNK(inode->i_mode)) {
3082 inode->i_op = &ll_fast_symlink_inode_operations;
3085 inode->i_op = &ll_special_inode_operations;
3087 init_special_inode(inode, inode->i_mode,
3096 void ll_delete_inode(struct inode *inode)
3098 struct ll_inode_info *lli = ll_i2info(inode);
3101 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
3102 /* It is last chance to write out dirty pages,
3103 * otherwise we may lose data while umount.
3105 * If i_nlink is 0 then just discard data. This is safe because
3106 * local inode gets i_nlink 0 from server only for the last
3107 * unlink, so that file is not opened somewhere else
3109 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
3110 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
3113 ll_truncate_inode_pages_final(inode);
3114 ll_clear_inode(inode);
3120 /* ioctl commands shared between files and directories */
3121 int ll_iocontrol(struct inode *inode, struct file *file,
3122 unsigned int cmd, void __user *uarg)
3124 struct ll_sb_info *sbi = ll_i2sbi(inode);
3125 struct ptlrpc_request *req = NULL;
3131 RETURN(put_user(PAGE_SIZE, (int __user *)uarg));
3132 case LL_IOC_GETVERSION:
3133 case FS_IOC_GETVERSION:
3134 RETURN(put_user(inode->i_generation, (int __user *)uarg));
3135 case FS_IOC_GETFLAGS: {
3136 struct mdt_body *body;
3137 struct md_op_data *op_data;
3139 if (!ll_access_ok(uarg, sizeof(int)))
3142 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3143 LUSTRE_OPC_ANY, NULL);
3144 if (IS_ERR(op_data))
3145 RETURN(PTR_ERR(op_data));
3147 op_data->op_valid = OBD_MD_FLFLAGS;
3148 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
3149 ll_finish_md_op_data(op_data);
3151 CERROR("%s: failure inode "DFID": rc = %d\n",
3152 sbi->ll_md_exp->exp_obd->obd_name,
3153 PFID(ll_inode2fid(inode)), rc);
3157 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
3159 flags = body->mbo_flags;
3160 /* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
3161 * ext4 equivalent to please lsattr and other e2fsprogs tools
3163 if (flags & LUSTRE_ENCRYPT_FL)
3164 flags |= STATX_ATTR_ENCRYPTED;
3166 ptlrpc_req_finished(req);
3168 RETURN(put_user(flags, (int __user *)uarg));
3170 case FS_IOC_SETFLAGS: {
3172 struct md_op_data *op_data;
3173 struct cl_object *obj;
3174 struct fsxattr fa = { 0 };
3176 if (get_user(flags, (int __user *)uarg))
3179 fa.fsx_projid = ll_i2info(inode)->lli_projid;
3180 if (flags & LUSTRE_PROJINHERIT_FL)
3181 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
3183 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
3188 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
3189 LUSTRE_OPC_ANY, NULL);
3190 if (IS_ERR(op_data))
3191 RETURN(PTR_ERR(op_data));
3193 op_data->op_attr_flags = flags;
3194 op_data->op_xvalid |= OP_XVALID_FLAGS;
3195 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
3196 ll_finish_md_op_data(op_data);
3197 ptlrpc_req_finished(req);
3201 ll_update_inode_flags(inode, flags);
3203 obj = ll_i2info(inode)->lli_clob;
3207 OBD_ALLOC_PTR(attr);
3211 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
3216 case FS_IOC_FSGETXATTR:
3217 RETURN(ll_ioctl_fsgetxattr(inode, cmd, uarg));
3218 case FS_IOC_FSSETXATTR:
3219 RETURN(ll_ioctl_fssetxattr(inode, cmd, uarg));
3220 case LL_IOC_PROJECT:
3221 RETURN(ll_ioctl_project(file, cmd, uarg));
3222 case IOC_OBD_STATFS:
3223 RETURN(ll_obd_statfs(inode, uarg));
3224 case LL_IOC_GET_MDTIDX: {
3225 if (!ll_access_ok(uarg, sizeof(rc)))
3228 rc = ll_get_mdt_idx(inode);
3232 if (put_user(rc, (int __user *)uarg))
3237 case LL_IOC_FLUSHCTX:
3238 RETURN(ll_flush_ctx(inode));
3239 #ifdef HAVE_LUSTRE_CRYPTO
3240 case LL_IOC_ADD_ENCRYPTION_KEY:
3241 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3243 rc = llcrypt_ioctl_add_key(file, uarg);
3244 #ifdef CONFIG_LL_ENCRYPTION
3245 if (!rc && S_ISDIR(inode->i_mode))
3246 sptlrpc_enc_pool_add_user();
3249 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
3250 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3252 RETURN(llcrypt_ioctl_get_key_status(file, uarg));
3253 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
3254 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3256 RETURN(llcrypt_ioctl_get_policy_ex(file, uarg));
3257 case LL_IOC_SET_ENCRYPTION_POLICY:
3258 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3260 RETURN(llcrypt_ioctl_set_policy(file, uarg));
3261 case LL_IOC_REMOVE_ENCRYPTION_KEY:
3262 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3264 RETURN(llcrypt_ioctl_remove_key(file, uarg));
3265 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
3266 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
3268 RETURN(llcrypt_ioctl_remove_key_all_users(file, uarg));
3270 case LL_IOC_GETPARENT:
3271 RETURN(ll_getparent(file, uarg));
3272 case LL_IOC_PATH2FID:
3273 if (copy_to_user(uarg, ll_inode2fid(inode),
3274 sizeof(struct lu_fid)))
3277 case LL_IOC_UNLOCK_FOREIGN: {
3278 struct dentry *dentry = file_dentry(file);
3280 /* if not a foreign symlink do nothing */
3281 if (ll_foreign_is_removable(dentry, true)) {
3283 "prevent unlink of non-foreign file ("DFID")\n",
3284 PFID(ll_inode2fid(inode)));
3285 RETURN(-EOPNOTSUPP);
3289 case OBD_IOC_FID2PATH:
3290 RETURN(ll_fid2path(inode, uarg));
3291 #ifdef OBD_IOC_GETNAME_OLD
3292 case_OBD_IOC_DEPRECATED_FT(OBD_IOC_GETNAME_OLD,
3293 sbi->ll_md_exp->exp_obd->obd_name, 2, 16);
3295 case OBD_IOC_GETDTNAME:
3296 case OBD_IOC_GETMDNAME:
3297 RETURN(ll_get_obd_name(inode, cmd, uarg));
3305 int ll_flush_ctx(struct inode *inode)
3307 struct ll_sb_info *sbi = ll_i2sbi(inode);
3309 CDEBUG(D_SEC, "flush context for user %d\n",
3310 from_kuid(&init_user_ns, current_uid()));
3312 obd_set_info_async(NULL, sbi->ll_md_exp,
3313 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3315 obd_set_info_async(NULL, sbi->ll_dt_exp,
3316 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
3321 /* umount -f client means force down, don't save state */
3322 void ll_umount_begin(struct super_block *sb)
3324 struct ll_sb_info *sbi = ll_s2sbi(sb);
3325 struct obd_device *obd;
3326 struct obd_ioctl_data *ioc_data;
3330 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
3331 sb->s_count, atomic_read(&sb->s_active));
3333 obd = class_exp2obd(sbi->ll_md_exp);
3335 CERROR("Invalid MDC connection handle %#llx\n",
3336 sbi->ll_md_exp->exp_handle.h_cookie);
3342 obd = class_exp2obd(sbi->ll_dt_exp);
3344 CERROR("Invalid LOV connection handle %#llx\n",
3345 sbi->ll_dt_exp->exp_handle.h_cookie);
3351 OBD_ALLOC_PTR(ioc_data);
3353 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_md_exp,
3354 sizeof *ioc_data, ioc_data, NULL);
3356 obd_iocontrol(OBD_IOC_SET_ACTIVE, sbi->ll_dt_exp,
3357 sizeof *ioc_data, ioc_data, NULL);
3359 OBD_FREE_PTR(ioc_data);
3362 /* Really, we'd like to wait until there are no requests outstanding,
3363 * and then continue. For now, we just periodically checking for vfs
3364 * to decrement mnt_cnt and hope to finish it within 10sec.
3368 !may_umount(sbi->ll_mnt.mnt)) {
3376 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3378 struct ll_sb_info *sbi = ll_s2sbi(sb);
3379 char *profilenm = get_profile_name(sb);
3383 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3384 read_only = *flags & MS_RDONLY;
3385 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3386 sizeof(KEY_READ_ONLY),
3387 KEY_READ_ONLY, sizeof(read_only),
3390 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3391 profilenm, read_only ?
3392 "read-only" : "read-write", err);
3397 sb->s_flags |= SB_RDONLY;
3399 sb->s_flags &= ~SB_RDONLY;
3401 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3402 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3403 read_only ? "read-only" : "read-write");
3409 * Cleanup the open handle that is cached on MDT-side.
3411 * For open case, the client side open handling thread may hit error
3412 * after the MDT grant the open. Under such case, the client should
3413 * send close RPC to the MDT as cleanup; otherwise, the open handle
3414 * on the MDT will be leaked there until the client umount or evicted.
3416 * In further, if someone unlinked the file, because the open handle
3417 * holds the reference on such file/object, then it will block the
3418 * subsequent threads that want to locate such object via FID.
3420 * \param[in] sb super block for this file-system
3421 * \param[in] open_req pointer to the original open request
3423 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3425 struct mdt_body *body;
3426 struct md_op_data *op_data;
3427 struct ptlrpc_request *close_req = NULL;
3428 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3431 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3432 OBD_ALLOC_PTR(op_data);
3433 if (op_data == NULL) {
3434 CWARN("%s: cannot allocate op_data to release open handle for "
3435 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3440 op_data->op_fid1 = body->mbo_fid1;
3441 op_data->op_open_handle = body->mbo_open_handle;
3442 op_data->op_mod_time = ktime_get_real_seconds();
3443 md_close(exp, op_data, NULL, &close_req);
3444 ptlrpc_req_finished(close_req);
3445 ll_finish_md_op_data(op_data);
3450 /* set filesystem-wide default LMV for subdir mount if it's enabled on ROOT. */
3451 static int ll_fileset_default_lmv_fixup(struct inode *inode,
3452 struct lustre_md *md)
3454 struct ll_sb_info *sbi = ll_i2sbi(inode);
3455 struct ptlrpc_request *req = NULL;
3456 union lmv_mds_md *lmm = NULL;
3460 LASSERT(is_root_inode(inode));
3461 LASSERT(!fid_is_root(&sbi->ll_root_fid));
3462 LASSERT(!md->default_lmv);
3464 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &size, &req,
3466 GET_DEFAULT_LAYOUT_ROOT);
3467 if (rc && rc != -ENODATA)
3472 rc = md_unpackmd(sbi->ll_md_exp, &md->default_lmv, lmm, size);
3481 ptlrpc_req_finished(req);
3485 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3486 struct super_block *sb, struct lookup_intent *it)
3488 struct ll_sb_info *sbi = NULL;
3489 struct lustre_md md = { NULL };
3490 bool default_lmv_deleted = false;
3495 LASSERT(*inode || sb);
3496 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3497 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3498 sbi->ll_md_exp, &md);
3503 * clear default_lmv only if intent_getattr reply doesn't contain it.
3504 * but it needs to be done after iget, check this early because
3505 * ll_update_lsm_md() may change md.
3507 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3508 S_ISDIR(md.body->mbo_mode) && !md.default_lmv) {
3509 if (unlikely(*inode && is_root_inode(*inode) &&
3510 !fid_is_root(&sbi->ll_root_fid))) {
3511 rc = ll_fileset_default_lmv_fixup(*inode, &md);
3516 if (!md.default_lmv)
3517 default_lmv_deleted = true;
3521 rc = ll_update_inode(*inode, &md);
3525 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3526 struct lu_fid *fid1 = &md.body->mbo_fid1;
3528 LASSERT(sb != NULL);
3531 * At this point server returns to client's same fid as client
3532 * generated for creating. So using ->fid1 is okay here.
3534 if (!fid_is_sane(fid1)) {
3535 CERROR("%s: Fid is insane "DFID"\n",
3536 sbi->ll_fsname, PFID(fid1));
3537 GOTO(out, rc = -EINVAL);
3540 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3541 if (IS_ERR(*inode)) {
3543 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3545 CERROR("new_inode -fatal: rc %d\n", rc);
3550 /* Handling piggyback layout lock.
3551 * Layout lock can be piggybacked by getattr and open request.
3552 * The lsm can be applied to inode only if it comes with a layout lock
3553 * otherwise correct layout may be overwritten, for example:
3554 * 1. proc1: mdt returns a lsm but not granting layout
3555 * 2. layout was changed by another client
3556 * 3. proc2: refresh layout and layout lock granted
3557 * 4. proc1: to apply a stale layout */
3558 if (it != NULL && it->it_lock_mode != 0) {
3559 struct lustre_handle lockh;
3560 struct ldlm_lock *lock;
3562 lockh.cookie = it->it_lock_handle;
3563 lock = ldlm_handle2lock(&lockh);
3564 LASSERT(lock != NULL);
3565 if (ldlm_has_layout(lock)) {
3566 struct cl_object_conf conf;
3568 memset(&conf, 0, sizeof(conf));
3569 conf.coc_opc = OBJECT_CONF_SET;
3570 conf.coc_inode = *inode;
3571 conf.coc_lock = lock;
3572 conf.u.coc_layout = md.layout;
3573 (void)ll_layout_conf(*inode, &conf);
3575 LDLM_LOCK_PUT(lock);
3578 if (default_lmv_deleted)
3579 ll_update_default_lsm_md(*inode, &md);
3581 /* we may want to apply some policy for foreign file/dir */
3582 if (ll_sbi_has_foreign_symlink(sbi)) {
3583 rc = ll_manage_foreign(*inode, &md);
3591 /* cleanup will be done if necessary */
3592 md_free_lustre_md(sbi->ll_md_exp, &md);
3594 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3595 ll_intent_drop_lock(it);
3596 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3602 int ll_obd_statfs(struct inode *inode, void __user *uarg)
3604 struct ll_sb_info *sbi = NULL;
3605 struct obd_export *exp;
3606 struct obd_ioctl_data *data = NULL;
3611 sbi = ll_i2sbi(inode);
3613 GOTO(out_statfs, rc = -EINVAL);
3615 rc = obd_ioctl_getdata(&data, &len, uarg);
3617 GOTO(out_statfs, rc);
3619 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3620 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3621 GOTO(out_statfs, rc = -EINVAL);
3623 if (data->ioc_inllen1 != sizeof(__u32) ||
3624 data->ioc_inllen2 != sizeof(__u32) ||
3625 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3626 data->ioc_plen2 != sizeof(struct obd_uuid))
3627 GOTO(out_statfs, rc = -EINVAL);
3629 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3630 if (type & LL_STATFS_LMV)
3631 exp = sbi->ll_md_exp;
3632 else if (type & LL_STATFS_LOV)
3633 exp = sbi->ll_dt_exp;
3635 GOTO(out_statfs, rc = -ENODEV);
3637 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3639 GOTO(out_statfs, rc);
3641 OBD_FREE_LARGE(data, len);
3646 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3647 * be called early to avoid deadlock.
3649 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3651 if (op_data->op_mea2_sem) {
3652 up_read_non_owner(op_data->op_mea2_sem);
3653 op_data->op_mea2_sem = NULL;
3656 if (op_data->op_mea1_sem) {
3657 up_read_non_owner(op_data->op_mea1_sem);
3658 op_data->op_mea1_sem = NULL;
3662 /* this function prepares md_op_data hint for passing it down to MD stack. */
3663 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3664 struct inode *i1, struct inode *i2,
3665 const char *name, size_t namelen,
3666 __u32 mode, enum md_op_code opc,
3669 struct llcrypt_name fname = { 0 };
3672 LASSERT(i1 != NULL);
3675 /* Do not reuse namelen for something else. */
3677 return ERR_PTR(-EINVAL);
3679 if ((!IS_ENCRYPTED(i1) ||
3680 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3681 namelen > ll_i2sbi(i1)->ll_namelen)
3682 return ERR_PTR(-ENAMETOOLONG);
3684 /* "/" is not valid name, but it's allowed */
3685 if (!lu_name_is_valid_2(name, namelen) &&
3686 strncmp("/", name, namelen) != 0)
3687 return ERR_PTR(-EINVAL);
3690 if (op_data == NULL)
3691 OBD_ALLOC_PTR(op_data);
3693 if (op_data == NULL)
3694 return ERR_PTR(-ENOMEM);
3696 ll_i2gids(op_data->op_suppgids, i1, i2);
3697 /* If the client is using a subdir mount and looks at what it sees as
3698 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3700 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3701 !fid_is_root(ll_inode2fid(i1)) &&
3702 name && namelen == strlen(dot_fscrypt_name) &&
3703 strncmp(name, dot_fscrypt_name, namelen) == 0))
3704 lu_root_fid(&op_data->op_fid1);
3706 op_data->op_fid1 = *ll_inode2fid(i1);
3708 if (S_ISDIR(i1->i_mode)) {
3709 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3710 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3711 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3712 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3716 op_data->op_fid2 = *ll_inode2fid(i2);
3717 if (S_ISDIR(i2->i_mode)) {
3719 /* i2 is typically a child of i1, and MUST be
3720 * further from the root to avoid deadlocks.
3722 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3723 op_data->op_mea2_sem =
3724 &ll_i2info(i2)->lli_lsm_sem;
3726 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3729 fid_zero(&op_data->op_fid2);
3732 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3733 op_data->op_cli_flags |= CLI_HASH64;
3735 if (ll_need_32bit_api(ll_i2sbi(i1)))
3736 op_data->op_cli_flags |= CLI_API32;
3738 if ((i2 && is_root_inode(i2)) ||
3739 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3740 /* In case of lookup, ll_setup_filename() has already been
3741 * called in ll_lookup_it(), so just take provided name.
3742 * Also take provided name if we are dealing with root inode.
3744 fname.disk_name.name = (unsigned char *)name;
3745 fname.disk_name.len = namelen;
3746 } else if (name && namelen) {
3747 struct qstr dname = QSTR_INIT(name, namelen);
3749 struct lu_fid *pfid = NULL;
3753 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3754 /* special case when called from ll_link() */
3759 lookup = (int)(opc == LUSTRE_OPC_ANY);
3761 if (opc == LUSTRE_OPC_ANY && lookup)
3763 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3765 ll_finish_md_op_data(op_data);
3768 if (pfid && !fid_is_zero(pfid)) {
3770 op_data->op_fid2 = fid;
3771 op_data->op_bias = MDS_FID_OP;
3773 if (fname.disk_name.name &&
3774 fname.disk_name.name != (unsigned char *)name) {
3775 /* op_data->op_name must be freed after use */
3776 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3780 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3781 * are LUSTRE_OPC_ANY
3783 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3784 op_data->op_code = LUSTRE_OPC_ANY;
3786 op_data->op_code = opc;
3787 op_data->op_name = fname.disk_name.name;
3788 op_data->op_namelen = fname.disk_name.len;
3789 op_data->op_mode = mode;
3790 op_data->op_mod_time = ktime_get_real_seconds();
3791 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3792 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3793 op_data->op_cap = current_cap();
3794 op_data->op_mds = 0;
3795 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3796 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3797 op_data->op_bias |= MDS_CREATE_VOLATILE;
3799 op_data->op_data = data;
3804 void ll_finish_md_op_data(struct md_op_data *op_data)
3806 ll_unlock_md_op_lsm(op_data);
3807 ll_security_release_secctx(op_data->op_file_secctx,
3808 op_data->op_file_secctx_size,
3809 op_data->op_file_secctx_slot);
3810 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3811 /* allocated via ll_setup_filename called
3812 * from ll_prep_md_op_data
3814 kfree(op_data->op_name);
3815 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3816 OBD_FREE_PTR(op_data);
3819 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3821 struct ll_sb_info *sbi;
3824 LASSERT(seq && dentry);
3825 sbi = ll_s2sbi(dentry->d_sb);
3827 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3828 seq_puts(seq, "nolock");
3830 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3831 /* match_table in some cases has patterns for both enabled and
3832 * disabled cases. Ignore 'no'xxx versions if bit is set.
3834 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3835 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3836 if (ll_sbi_flags_name[i].token ==
3837 LL_SBI_FOREIGN_SYMLINK) {
3838 seq_show_option(seq, "foreign_symlink",
3839 sbi->ll_foreign_symlink_prefix);
3841 seq_printf(seq, ",%s",
3842 ll_sbi_flags_name[i].pattern);
3845 /* You can have either localflock or flock but not
3846 * both. If localflock is set don't print flock or
3849 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3851 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3852 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3853 seq_printf(seq, ",%s",
3854 ll_sbi_flags_name[i].pattern);
3858 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3864 * Get obd name by cmd, and copy out to user space
3866 int ll_get_obd_name(struct inode *inode, unsigned int cmd, void __user *uarg)
3868 struct ll_sb_info *sbi = ll_i2sbi(inode);
3869 struct obd_device *obd;
3872 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3873 obd = class_exp2obd(sbi->ll_dt_exp);
3874 else if (cmd == OBD_IOC_GETMDNAME)
3875 obd = class_exp2obd(sbi->ll_md_exp);
3882 if (copy_to_user(uarg, obd->obd_name, strlen(obd->obd_name) + 1))
3889 struct work_struct db_work;
3890 struct dentry *db_dentry;
3891 /* Let's hope the path is not too long, 32 bytes for the work struct
3894 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3897 static void ll_dput_later(struct work_struct *work)
3899 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3901 dput(db->db_dentry);
3902 free_page((unsigned long)db);
3905 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3912 p.mnt = current->fs->root.mnt;
3914 path = d_path(&p, buf, bufsize);
3919 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3921 struct dname_buf *db;
3923 struct dentry *dentry = NULL;
3925 /* this can be called inside spin lock so use GFP_ATOMIC. */
3926 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3929 dentry = d_find_alias(inode);
3931 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3934 /* The below message is checked in recovery-small.sh test_24b */
3936 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3937 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3938 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3939 PFID(ll_inode2fid(inode)),
3940 (path && !IS_ERR(path)) ? path : "", ioret);
3942 if (dentry != NULL) {
3943 /* We cannot dput here since if we happen to be the last holder
3944 * then we can end up waiting for page evictions that
3945 * in turn wait for RPCs that need this instance of ptlrpcd
3946 * (callng brw_interpret->*page_completion*->vmpage_error->here)
3949 INIT_WORK(&db->db_work, ll_dput_later);
3950 db->db_dentry = dentry;
3951 schedule_work(&db->db_work);
3954 free_page((unsigned long)db);
3958 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3959 struct lov_user_md **kbuf)
3961 struct lov_user_md lum;
3965 if (copy_from_user(&lum, md, sizeof(lum)))
3968 lum_size = ll_lov_user_md_size(&lum);
3972 OBD_ALLOC_LARGE(*kbuf, lum_size);
3976 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3977 OBD_FREE_LARGE(*kbuf, lum_size);
3985 * Compute llite root squash state after a change of root squash
3986 * configuration setting or add/remove of a lnet nid
3988 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3990 struct root_squash_info *squash = &sbi->ll_squash;
3993 struct lnet_processid id;
3995 /* Update norootsquash flag */
3996 spin_lock(&squash->rsi_lock);
3997 if (list_empty(&squash->rsi_nosquash_nids))
3998 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4000 /* Do not apply root squash as soon as one of our NIDs is
4001 * in the nosquash_nids list */
4004 while (LNetGetId(i++, &id) != -ENOENT) {
4005 if (nid_is_lo0(&id.nid))
4007 if (cfs_match_nid(&id.nid,
4008 &squash->rsi_nosquash_nids)) {
4014 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4016 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
4018 spin_unlock(&squash->rsi_lock);
4022 * Parse linkea content to extract information about a given hardlink
4024 * \param[in] ldata - Initialized linkea data
4025 * \param[in] linkno - Link identifier
4026 * \param[out] parent_fid - The entry's parent FID
4027 * \param[out] ln - Entry name destination buffer
4029 * \retval 0 on success
4030 * \retval Appropriate negative error code on failure
4032 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
4033 struct lu_fid *parent_fid, struct lu_name *ln)
4039 rc = linkea_init_with_rec(ldata);
4043 if (linkno >= ldata->ld_leh->leh_reccount)
4044 /* beyond last link */
4047 linkea_first_entry(ldata);
4048 for (idx = 0; ldata->ld_lee != NULL; idx++) {
4049 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
4054 linkea_next_entry(ldata);
4064 * Get parent FID and name of an identified link. Operation is performed for
4065 * a given link number, letting the caller iterate over linkno to list one or
4066 * all links of an entry.
4068 * \param[in] file - File descriptor against which to perform the operation
4069 * \param[in,out] arg - User-filled structure containing the linkno to operate
4070 * on and the available size. It is eventually filled with
4071 * the requested information or left untouched on error
4073 * \retval - 0 on success
4074 * \retval - Appropriate negative error code on failure
4076 int ll_getparent(struct file *file, struct getparent __user *arg)
4078 struct inode *inode = file_inode(file);
4079 struct linkea_data *ldata;
4080 struct lu_buf buf = LU_BUF_NULL;
4082 struct lu_fid parent_fid;
4089 if (!capable(CAP_DAC_READ_SEARCH) &&
4090 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
4093 if (get_user(name_size, &arg->gp_name_size))
4096 if (get_user(linkno, &arg->gp_linkno))
4099 if (name_size > PATH_MAX)
4102 OBD_ALLOC(ldata, sizeof(*ldata));
4106 rc = linkea_data_new(ldata, &buf);
4108 GOTO(ldata_free, rc);
4110 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
4111 buf.lb_len, OBD_MD_FLXATTR);
4115 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
4119 if (ln.ln_namelen >= name_size)
4120 GOTO(lb_free, rc = -EOVERFLOW);
4122 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
4123 GOTO(lb_free, rc = -EFAULT);
4125 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
4126 GOTO(lb_free, rc = -EFAULT);
4128 if (put_user('\0', arg->gp_name + ln.ln_namelen))
4129 GOTO(lb_free, rc = -EFAULT);
4134 OBD_FREE(ldata, sizeof(*ldata));