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/module.h>
40 #include <linux/random.h>
41 #include <linux/statfs.h>
42 #include <linux/time.h>
43 #include <linux/file.h>
44 #include <linux/types.h>
45 #include <libcfs/linux/linux-uuid.h>
46 #include <linux/version.h>
48 #include <linux/user_namespace.h>
49 #include <linux/delay.h>
50 #include <linux/uidgid.h>
51 #include <linux/fs_struct.h>
53 #ifndef HAVE_CPUS_READ_LOCK
54 #include <libcfs/linux/linux-cpu.h>
56 #include <libcfs/linux/linux-misc.h>
57 #include <uapi/linux/lustre/lustre_ioctl.h>
58 #ifdef HAVE_UAPI_LINUX_MOUNT_H
59 #include <uapi/linux/mount.h>
62 #include <lustre_ha.h>
63 #include <lustre_dlm.h>
64 #include <lprocfs_status.h>
65 #include <lustre_disk.h>
66 #include <uapi/linux/lustre/lustre_param.h>
67 #include <lustre_log.h>
68 #include <cl_object.h>
69 #include <obd_cksum.h>
70 #include "llite_internal.h"
72 struct kmem_cache *ll_file_data_slab;
75 #define log2(n) ffz(~(n))
79 * If there is only one number of core visible to Lustre,
80 * async readahead will be disabled, to avoid massive over
81 * subscription, we use 1/2 of active cores as default max
82 * async readahead requests.
84 static inline unsigned int ll_get_ra_async_max_active(void)
86 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
89 static struct ll_sb_info *ll_init_sbi(void)
91 struct ll_sb_info *sbi = NULL;
93 unsigned long lru_page_max;
101 RETURN(ERR_PTR(-ENOMEM));
103 rc = pcc_super_init(&sbi->ll_pcc_super);
107 spin_lock_init(&sbi->ll_lock);
108 mutex_init(&sbi->ll_lco.lco_lock);
109 spin_lock_init(&sbi->ll_pp_extent_lock);
110 spin_lock_init(&sbi->ll_process_lock);
111 sbi->ll_rw_stats_on = 0;
112 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
115 pages = si.totalram - si.totalhigh;
116 lru_page_max = pages / 2;
118 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
119 sbi->ll_ra_info.ll_readahead_wq =
120 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
122 sbi->ll_ra_info.ra_async_max_active);
123 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
124 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
126 /* initialize ll_cache data */
127 sbi->ll_cache = cl_cache_init(lru_page_max);
128 if (sbi->ll_cache == NULL)
129 GOTO(out_destroy_ra, rc = -ENOMEM);
131 /* initialize foreign symlink prefix path */
132 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
133 if (sbi->ll_foreign_symlink_prefix == NULL)
134 GOTO(out_destroy_ra, rc = -ENOMEM);
135 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
136 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
138 /* initialize foreign symlink upcall path, none by default */
139 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
140 if (sbi->ll_foreign_symlink_upcall == NULL)
141 GOTO(out_destroy_ra, rc = -ENOMEM);
142 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
143 sbi->ll_foreign_symlink_upcall_items = NULL;
144 sbi->ll_foreign_symlink_upcall_nb_items = 0;
145 init_rwsem(&sbi->ll_foreign_symlink_sem);
146 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
147 * not enabled by default
150 sbi->ll_ra_info.ra_max_pages =
151 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
152 sbi->ll_ra_info.ra_max_pages_per_file =
153 min(sbi->ll_ra_info.ra_max_pages / 4,
154 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
155 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
156 sbi->ll_ra_info.ra_max_pages_per_file;
157 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
158 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
159 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
161 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
162 #ifdef ENABLE_CHECKSUM
163 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
166 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
169 #ifdef HAVE_LRU_RESIZE_SUPPORT
170 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
172 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
174 /* metadata statahead is enabled by default */
175 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
176 sbi->ll_sa_max = LL_SA_RPC_DEF;
177 atomic_set(&sbi->ll_sa_total, 0);
178 atomic_set(&sbi->ll_sa_wrong, 0);
179 atomic_set(&sbi->ll_sa_running, 0);
180 atomic_set(&sbi->ll_agl_total, 0);
181 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
182 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
183 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
184 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
185 ll_sbi_set_encrypt(sbi, true);
188 sbi->ll_squash.rsi_uid = 0;
189 sbi->ll_squash.rsi_gid = 0;
190 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
191 spin_lock_init(&sbi->ll_squash.rsi_lock);
193 /* Per-filesystem file heat */
194 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
195 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
197 /* Per-fs open heat level before requesting open lock */
198 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
199 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
200 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
203 if (sbi->ll_foreign_symlink_prefix)
204 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
206 cl_cache_decref(sbi->ll_cache);
207 sbi->ll_cache = NULL;
209 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
211 pcc_super_fini(&sbi->ll_pcc_super);
217 static void ll_free_sbi(struct super_block *sb)
219 struct ll_sb_info *sbi = ll_s2sbi(sb);
223 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
224 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
225 if (sbi->ll_ra_info.ll_readahead_wq)
226 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
227 if (sbi->ll_cache != NULL) {
228 cl_cache_decref(sbi->ll_cache);
229 sbi->ll_cache = NULL;
231 if (sbi->ll_foreign_symlink_prefix) {
232 OBD_FREE(sbi->ll_foreign_symlink_prefix,
233 sbi->ll_foreign_symlink_prefix_size);
234 sbi->ll_foreign_symlink_prefix = NULL;
236 if (sbi->ll_foreign_symlink_upcall) {
237 OBD_FREE(sbi->ll_foreign_symlink_upcall,
238 strlen(sbi->ll_foreign_symlink_upcall) +
240 sbi->ll_foreign_symlink_upcall = NULL;
242 if (sbi->ll_foreign_symlink_upcall_items) {
244 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
245 struct ll_foreign_symlink_upcall_item *items =
246 sbi->ll_foreign_symlink_upcall_items;
248 for (i = 0 ; i < nb_items; i++)
249 if (items[i].type == STRING_TYPE)
250 OBD_FREE(items[i].string,
253 OBD_FREE_LARGE(items, nb_items *
254 sizeof(struct ll_foreign_symlink_upcall_item));
255 sbi->ll_foreign_symlink_upcall_items = NULL;
257 ll_free_rw_stats_info(sbi);
258 pcc_super_fini(&sbi->ll_pcc_super);
259 OBD_FREE(sbi, sizeof(*sbi));
264 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
266 struct inode *root = NULL;
267 struct ll_sb_info *sbi = ll_s2sbi(sb);
268 struct obd_statfs *osfs = NULL;
269 struct ptlrpc_request *request = NULL;
270 struct obd_connect_data *data = NULL;
271 struct obd_uuid *uuid;
272 struct md_op_data *op_data;
273 struct lustre_md lmd;
275 int size, err, checksum;
281 sbi->ll_md_obd = class_name2obd(md);
282 if (!sbi->ll_md_obd) {
283 CERROR("MD %s: not setup or attached\n", md);
297 /* pass client page size via ocd_grant_blkbits, the server should report
298 * back its backend blocksize for grant calculation purpose */
299 data->ocd_grant_blkbits = PAGE_SHIFT;
301 /* indicate MDT features supported by this client */
302 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
303 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
304 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
305 OBD_CONNECT_SRVLOCK |
306 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
307 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
308 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
309 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
310 OBD_CONNECT_64BITHASH |
311 OBD_CONNECT_EINPROGRESS |
312 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
313 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
314 OBD_CONNECT_MAX_EASIZE |
315 OBD_CONNECT_FLOCK_DEAD |
316 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
317 OBD_CONNECT_OPEN_BY_FID |
318 OBD_CONNECT_DIR_STRIPE |
319 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
320 OBD_CONNECT_SUBTREE |
321 OBD_CONNECT_MULTIMODRPCS |
322 OBD_CONNECT_GRANT_PARAM |
323 OBD_CONNECT_GRANT_SHRINK |
324 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
326 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
327 OBD_CONNECT2_SUM_STATFS |
328 OBD_CONNECT2_OVERSTRIPING |
330 OBD_CONNECT2_LOCK_CONVERT |
331 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
332 OBD_CONNECT2_INC_XID |
334 OBD_CONNECT2_ASYNC_DISCARD |
336 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
337 OBD_CONNECT2_GETATTR_PFID |
338 OBD_CONNECT2_DOM_LVB |
339 OBD_CONNECT2_REP_MBITS |
340 OBD_CONNECT2_ATOMIC_OPEN_LOCK;
342 #ifdef HAVE_LRU_RESIZE_SUPPORT
343 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
344 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
346 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
348 data->ocd_cksum_types = obd_cksum_types_supported_client();
350 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
351 /* flag mdc connection as lightweight, only used for test
352 * purpose, use with care */
353 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
355 data->ocd_ibits_known = MDS_INODELOCK_FULL;
356 data->ocd_version = LUSTRE_VERSION_CODE;
358 if (sb->s_flags & SB_RDONLY)
359 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
360 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
361 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
364 /* Setting this indicates we correctly support S_NOSEC (See kernel
365 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
367 sb->s_flags |= SB_NOSEC;
369 sbi->ll_fop = ll_select_file_operations(sbi);
371 /* always ping even if server suppress_pings */
372 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
373 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
375 obd_connect_set_secctx(data);
376 if (ll_sbi_has_encrypt(sbi))
377 obd_connect_set_enc(data);
379 #if defined(CONFIG_SECURITY)
380 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
383 data->ocd_brw_size = MD_MAX_BRW_SIZE;
385 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
386 &sbi->ll_sb_uuid, data, sbi->ll_cache);
388 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
389 "recovery, of which this client is not a "
390 "part. Please wait for recovery to complete,"
391 " abort, or time out.\n", md);
394 CERROR("cannot connect to %s: rc = %d\n", md, err);
398 sbi->ll_md_exp->exp_connect_data = *data;
400 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
401 LUSTRE_SEQ_METADATA);
403 CERROR("%s: Can't init metadata layer FID infrastructure, "
404 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
408 /* For mount, we only need fs info from MDT0, and also in DNE, it
409 * can make sure the client can be mounted as long as MDT0 is
411 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
412 ktime_get_seconds() - sbi->ll_statfs_max_age,
413 OBD_STATFS_FOR_MDT0);
415 GOTO(out_md_fid, err);
417 /* This needs to be after statfs to ensure connect has finished.
418 * Note that "data" does NOT contain the valid connect reply.
419 * If connecting to a 1.8 server there will be no LMV device, so
420 * we can access the MDC export directly and exp_connect_flags will
421 * be non-zero, but if accessing an upgraded 2.1 server it will
422 * have the correct flags filled in.
423 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
424 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
425 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
426 valid != CLIENT_CONNECT_MDT_REQD) {
429 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
430 obd_connect_flags2str(buf, PAGE_SIZE,
431 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
432 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
433 "feature(s) needed for correct operation "
434 "of this client (%s). Please upgrade "
435 "server or downgrade client.\n",
436 sbi->ll_md_exp->exp_obd->obd_name, buf);
437 OBD_FREE(buf, PAGE_SIZE);
438 GOTO(out_md_fid, err = -EPROTO);
441 size = sizeof(*data);
442 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
443 KEY_CONN_DATA, &size, data);
445 CERROR("%s: Get connect data failed: rc = %d\n",
446 sbi->ll_md_exp->exp_obd->obd_name, err);
447 GOTO(out_md_fid, err);
450 LASSERT(osfs->os_bsize);
451 sb->s_blocksize = osfs->os_bsize;
452 sb->s_blocksize_bits = log2(osfs->os_bsize);
453 sb->s_magic = LL_SUPER_MAGIC;
454 sb->s_maxbytes = MAX_LFS_FILESIZE;
455 sbi->ll_inode_cache_enabled = 1;
456 sbi->ll_namelen = osfs->os_namelen;
457 sbi->ll_mnt.mnt = current->fs->root.mnt;
458 sbi->ll_mnt_ns = current->nsproxy->mnt_ns;
460 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
461 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
462 LCONSOLE_INFO("Disabling user_xattr feature because "
463 "it is not supported on the server\n");
464 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
467 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
469 sb->s_flags |= SB_POSIXACL;
471 set_bit(LL_SBI_ACL, sbi->ll_flags);
473 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
475 sb->s_flags &= ~SB_POSIXACL;
477 clear_bit(LL_SBI_ACL, sbi->ll_flags);
480 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
481 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
483 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
484 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
486 if (obd_connect_has_secctx(data))
487 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
489 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
490 if (ll_sb_has_test_dummy_encryption(sb))
491 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
493 sbi->ll_md_exp->exp_obd->obd_name);
494 ll_sbi_set_encrypt(sbi, false);
497 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
498 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
499 LCONSOLE_INFO("%s: disabling xattr cache due to "
500 "unknown maximum xattr size.\n", dt);
501 } else if (!sbi->ll_xattr_cache_set) {
502 /* If xattr_cache is already set (no matter 0 or 1)
503 * during processing llog, it won't be enabled here. */
504 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
505 sbi->ll_xattr_cache_enabled = 1;
509 sbi->ll_dt_obd = class_name2obd(dt);
510 if (!sbi->ll_dt_obd) {
511 CERROR("DT %s: not setup or attached\n", dt);
512 GOTO(out_md_fid, err = -ENODEV);
515 /* pass client page size via ocd_grant_blkbits, the server should report
516 * back its backend blocksize for grant calculation purpose */
517 data->ocd_grant_blkbits = PAGE_SHIFT;
519 /* indicate OST features supported by this client */
520 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
521 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
522 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
523 OBD_CONNECT_SRVLOCK |
524 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
525 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
526 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
527 OBD_CONNECT_EINPROGRESS |
528 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
529 OBD_CONNECT_LAYOUTLOCK |
530 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
531 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
532 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
533 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
534 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
535 OBD_CONNECT2_REP_MBITS;
537 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
538 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
540 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
541 * disabled by default, because it can still be enabled on the
542 * fly via /sys. As a consequence, we still need to come to an
543 * agreement on the supported algorithms at connect time
545 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
547 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
548 data->ocd_cksum_types = OBD_CKSUM_ADLER;
550 data->ocd_cksum_types = obd_cksum_types_supported_client();
552 #ifdef HAVE_LRU_RESIZE_SUPPORT
553 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
555 /* always ping even if server suppress_pings */
556 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
557 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
559 if (ll_sbi_has_encrypt(sbi))
560 obd_connect_set_enc(data);
562 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
563 "ocd_grant: %d\n", data->ocd_connect_flags,
564 data->ocd_version, data->ocd_grant);
566 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
567 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
569 data->ocd_brw_size = DT_MAX_BRW_SIZE;
571 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
572 &sbi->ll_sb_uuid, data, sbi->ll_cache);
574 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
575 "recovery, of which this client is not a "
576 "part. Please wait for recovery to "
577 "complete, abort, or time out.\n", dt);
580 CERROR("%s: Cannot connect to %s: rc = %d\n",
581 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
585 if (ll_sbi_has_encrypt(sbi) &&
586 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
587 if (ll_sb_has_test_dummy_encryption(sb))
588 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
590 ll_sbi_set_encrypt(sbi, false);
591 } else if (ll_sb_has_test_dummy_encryption(sb)) {
592 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
595 sbi->ll_dt_exp->exp_connect_data = *data;
597 /* Don't change value if it was specified in the config log */
598 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
599 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
600 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
601 (data->ocd_brw_size >> PAGE_SHIFT));
602 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
603 sbi->ll_ra_info.ra_max_pages_per_file)
604 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
605 sbi->ll_ra_info.ra_max_pages_per_file;
608 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
609 LUSTRE_SEQ_METADATA);
611 CERROR("%s: Can't init data layer FID infrastructure, "
612 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
616 mutex_lock(&sbi->ll_lco.lco_lock);
617 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
618 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
619 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
620 mutex_unlock(&sbi->ll_lco.lco_lock);
622 fid_zero(&sbi->ll_root_fid);
623 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
626 CERROR("cannot mds_connect: rc = %d\n", err);
627 GOTO(out_lock_cn_cb, err);
629 if (!fid_is_sane(&sbi->ll_root_fid)) {
630 CERROR("%s: Invalid root fid "DFID" during mount\n",
631 sbi->ll_md_exp->exp_obd->obd_name,
632 PFID(&sbi->ll_root_fid));
633 GOTO(out_lock_cn_cb, err = -EINVAL);
635 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
637 sb->s_op = &lustre_super_operations;
638 sb->s_xattr = ll_xattr_handlers;
639 #if THREAD_SIZE >= 8192 /*b=17630*/
640 sb->s_export_op = &lustre_export_operations;
642 #ifdef HAVE_LUSTRE_CRYPTO
643 llcrypt_set_ops(sb, &lustre_cryptops);
647 * XXX: move this to after cbd setup? */
648 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE |
650 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
651 valid |= OBD_MD_FLACL;
653 OBD_ALLOC_PTR(op_data);
655 GOTO(out_lock_cn_cb, err = -ENOMEM);
657 op_data->op_fid1 = sbi->ll_root_fid;
658 op_data->op_mode = 0;
659 op_data->op_valid = valid;
661 err = md_getattr(sbi->ll_md_exp, op_data, &request);
663 /* We need enc ctx info, so reset it in op_data to
664 * prevent it from being freed.
666 encctx = op_data->op_file_encctx;
667 encctxlen = op_data->op_file_encctx_size;
668 op_data->op_file_encctx = NULL;
669 op_data->op_file_encctx_size = 0;
670 OBD_FREE_PTR(op_data);
672 CERROR("%s: md_getattr failed for root: rc = %d\n",
673 sbi->ll_md_exp->exp_obd->obd_name, err);
674 GOTO(out_lock_cn_cb, err);
677 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
678 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
680 CERROR("failed to understand root inode md: rc = %d\n", err);
681 ptlrpc_req_finished(request);
682 GOTO(out_lock_cn_cb, err);
685 LASSERT(fid_is_sane(&sbi->ll_root_fid));
686 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
687 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
688 md_free_lustre_md(sbi->ll_md_exp, &lmd);
692 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
694 CERROR("%s: bad ll_iget() for root: rc = %d\n",
695 sbi->ll_fsname, err);
696 ptlrpc_req_finished(request);
702 "server returned encryption ctx for root inode "DFID"\n",
703 PFID(&sbi->ll_root_fid));
704 err = ll_set_encflags(root, encctx, encctxlen, true);
706 CWARN("%s: cannot set enc ctx for "DFID": rc = %d\n",
708 PFID(&sbi->ll_root_fid), err);
710 ptlrpc_req_finished(request);
712 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
713 if (sbi->ll_checksum_set) {
714 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
715 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
716 sizeof(checksum), &checksum, NULL);
718 CERROR("%s: Set checksum failed: rc = %d\n",
719 sbi->ll_dt_exp->exp_obd->obd_name, err);
725 sb->s_root = d_make_root(root);
726 if (sb->s_root == NULL) {
728 CERROR("%s: can't make root dentry: rc = %d\n",
729 sbi->ll_fsname, err);
733 sbi->ll_sdev_orig = sb->s_dev;
735 /* We set sb->s_dev equal on all lustre clients in order to support
736 * NFS export clustering. NFSD requires that the FSID be the same
738 /* s_dev is also used in lt_compare() to compare two fs, but that is
739 * only a node-local comparison. */
740 uuid = obd_get_uuid(sbi->ll_md_exp);
742 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
749 if (sbi->ll_dt_obd) {
750 err = sysfs_create_link(&sbi->ll_kset.kobj,
751 &sbi->ll_dt_obd->obd_kset.kobj,
752 sbi->ll_dt_obd->obd_type->typ_name);
754 CERROR("%s: could not register %s in llite: rc = %d\n",
755 dt, sbi->ll_fsname, err);
760 if (sbi->ll_md_obd) {
761 err = sysfs_create_link(&sbi->ll_kset.kobj,
762 &sbi->ll_md_obd->obd_kset.kobj,
763 sbi->ll_md_obd->obd_type->typ_name);
765 CERROR("%s: could not register %s in llite: rc = %d\n",
766 md, sbi->ll_fsname, err);
775 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
777 obd_disconnect(sbi->ll_dt_exp);
778 sbi->ll_dt_exp = NULL;
779 sbi->ll_dt_obd = NULL;
781 obd_fid_fini(sbi->ll_md_exp->exp_obd);
783 obd_disconnect(sbi->ll_md_exp);
784 sbi->ll_md_exp = NULL;
785 sbi->ll_md_obd = NULL;
794 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
798 size = sizeof(*lmmsize);
799 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
800 KEY_MAX_EASIZE, &size, lmmsize);
802 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
803 sbi->ll_dt_exp->exp_obd->obd_name, rc);
807 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
810 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
811 KEY_MAX_EASIZE, &size, lmmsize);
813 CERROR("Get max mdsize error rc %d\n", rc);
815 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
821 * Get the value of the default_easize parameter.
823 * \see client_obd::cl_default_mds_easize
825 * \param[in] sbi superblock info for this filesystem
826 * \param[out] lmmsize pointer to storage location for value
828 * \retval 0 on success
829 * \retval negative negated errno on failure
831 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
836 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
837 KEY_DEFAULT_EASIZE, &size, lmmsize);
839 CERROR("Get default mdsize error rc %d\n", rc);
845 * Set the default_easize parameter to the given value.
847 * \see client_obd::cl_default_mds_easize
849 * \param[in] sbi superblock info for this filesystem
850 * \param[in] lmmsize the size to set
852 * \retval 0 on success
853 * \retval negative negated errno on failure
855 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
859 if (lmmsize < sizeof(struct lov_mds_md) ||
860 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
863 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
864 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
865 sizeof(int), &lmmsize, NULL);
870 static void client_common_put_super(struct super_block *sb)
872 struct ll_sb_info *sbi = ll_s2sbi(sb);
877 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
878 obd_disconnect(sbi->ll_dt_exp);
879 sbi->ll_dt_exp = NULL;
881 ll_debugfs_unregister_super(sb);
883 obd_fid_fini(sbi->ll_md_exp->exp_obd);
884 obd_disconnect(sbi->ll_md_exp);
885 sbi->ll_md_exp = NULL;
890 void ll_kill_super(struct super_block *sb)
892 struct ll_sb_info *sbi;
896 if (!(sb->s_flags & SB_ACTIVE))
900 /* we need restore s_dev from changed for clustred NFS before put_super
901 * because new kernels have cached s_dev and change sb->s_dev in
902 * put_super not affected real removing devices */
904 sb->s_dev = sbi->ll_sdev_orig;
906 /* wait running statahead threads to quit */
907 while (atomic_read(&sbi->ll_sa_running) > 0)
908 schedule_timeout_uninterruptible(
909 cfs_time_seconds(1) >> 3);
915 /* Since we use this table for ll_sbi_flags_seq_show make
916 * sure what you want displayed for a specific token that
917 * is listed more than once below be listed first. For
918 * example we want "checksum" displayed, not "nochecksum"
921 static const match_table_t ll_sbi_flags_name = {
922 {LL_SBI_NOLCK, "nolock"},
923 {LL_SBI_CHECKSUM, "checksum"},
924 {LL_SBI_CHECKSUM, "nochecksum"},
925 {LL_SBI_LOCALFLOCK, "localflock"},
926 {LL_SBI_FLOCK, "flock"},
927 {LL_SBI_FLOCK, "noflock"},
928 {LL_SBI_USER_XATTR, "user_xattr"},
929 {LL_SBI_USER_XATTR, "nouser_xattr"},
930 {LL_SBI_LRU_RESIZE, "lruresize"},
931 {LL_SBI_LRU_RESIZE, "nolruresize"},
932 {LL_SBI_LAZYSTATFS, "lazystatfs"},
933 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
934 {LL_SBI_32BIT_API, "32bitapi"},
935 {LL_SBI_USER_FID2PATH, "user_fid2path"},
936 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
937 {LL_SBI_VERBOSE, "verbose"},
938 {LL_SBI_VERBOSE, "noverbose"},
939 {LL_SBI_ALWAYS_PING, "always_ping"},
940 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption=%s"},
941 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
942 {LL_SBI_ENCRYPT, "encrypt"},
943 {LL_SBI_ENCRYPT, "noencrypt"},
944 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
945 {LL_SBI_NUM_MOUNT_OPT, NULL},
948 {LL_SBI_AGL_ENABLED, "agl"},
949 {LL_SBI_64BIT_HASH, "64bit_hash"},
950 {LL_SBI_LAYOUT_LOCK, "layout"},
951 {LL_SBI_XATTR_CACHE, "xattr_cache"},
952 {LL_SBI_NOROOTSQUASH, "norootsquash"},
953 {LL_SBI_FAST_READ, "fast_read"},
954 {LL_SBI_FILE_SECCTX, "file_secctx"},
955 {LL_SBI_TINY_WRITE, "tiny_write"},
956 {LL_SBI_FILE_HEAT, "file_heat"},
957 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
960 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
962 struct super_block *sb = m->private;
965 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
968 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
971 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
972 if (ll_sbi_flags_name[j].token == i &&
973 ll_sbi_flags_name[j].pattern) {
975 ll_sbi_flags_name[j].pattern);
984 /* non-client-specific mount options are parsed in lmd_parse */
985 static int ll_options(char *options, struct super_block *sb)
987 struct ll_sb_info *sbi = ll_s2sbi(sb);
988 char *s2, *s1, *opts;
995 /* Don't stomp on lmd_opts */
996 opts = kstrdup(options, GFP_KERNEL);
1002 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
1004 while ((s1 = strsep(&opts, ",")) != NULL) {
1005 substring_t args[MAX_OPT_ARGS];
1006 bool turn_off = false;
1012 CDEBUG(D_SUPER, "next opt=%s\n", s1);
1014 if (strncmp(s1, "no", 2) == 0)
1018 * Initialize args struct so we know whether arg was
1019 * found; some options take optional arguments.
1022 args[0].from = NULL;
1023 token = match_token(s1, ll_sbi_flags_name, args);
1024 if (token == LL_SBI_NUM_MOUNT_OPT) {
1025 if (match_wildcard("context", s1) ||
1026 match_wildcard("fscontext", s1) ||
1027 match_wildcard("defcontext", s1) ||
1028 match_wildcard("rootcontext",s1))
1031 LCONSOLE_ERROR_MSG(0x152,
1032 "Unknown option '%s', won't mount.\n",
1039 case LL_SBI_32BIT_API:
1040 case LL_SBI_64BIT_HASH:
1041 case LL_SBI_ALWAYS_PING:
1042 set_bit(token, sbi->ll_flags);
1046 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1048 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1050 set_bit(token, sbi->ll_flags);
1053 case LL_SBI_LOCALFLOCK:
1054 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1055 set_bit(token, sbi->ll_flags);
1058 case LL_SBI_CHECKSUM:
1059 sbi->ll_checksum_set = 1;
1061 case LL_SBI_USER_XATTR:
1062 case LL_SBI_USER_FID2PATH:
1063 case LL_SBI_LRU_RESIZE:
1064 case LL_SBI_LAZYSTATFS:
1065 case LL_SBI_VERBOSE:
1067 clear_bit(token, sbi->ll_flags);
1069 set_bit(token, sbi->ll_flags);
1071 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1072 #ifdef HAVE_LUSTRE_CRYPTO
1073 #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED
1074 set_bit(token, sbi->ll_flags);
1076 struct lustre_sb_info *lsi = s2lsi(sb);
1078 err = llcrypt_set_test_dummy_encryption(sb, &args[0],
1079 &lsi->lsi_dummy_enc_ctx);
1085 "Can't change test_dummy_encryption");
1086 else if (err == -EINVAL)
1088 "Value of option \"%s\" unrecognized",
1092 "Error processing option \"%s\" [%d]",
1097 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1101 case LL_SBI_ENCRYPT:
1102 #ifdef HAVE_LUSTRE_CRYPTO
1104 clear_bit(token, sbi->ll_flags);
1106 set_bit(token, sbi->ll_flags);
1108 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1111 case LL_SBI_FOREIGN_SYMLINK:
1112 /* non-default prefix provided ? */
1117 /* path must be absolute */
1118 if (args->from[0] != '/') {
1119 LCONSOLE_ERROR_MSG(0x152,
1120 "foreign prefix '%s' must be an absolute path\n",
1125 old_len = sbi->ll_foreign_symlink_prefix_size;
1126 old = sbi->ll_foreign_symlink_prefix;
1127 /* alloc for path length and '\0' */
1128 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1129 if (!sbi->ll_foreign_symlink_prefix) {
1130 /* restore previous */
1131 sbi->ll_foreign_symlink_prefix = old;
1132 sbi->ll_foreign_symlink_prefix_size =
1136 sbi->ll_foreign_symlink_prefix_size =
1137 args->to - args->from + 1;
1138 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1139 sbi->ll_foreign_symlink_prefix_size,
1142 OBD_FREE(old, old_len);
1144 /* enable foreign symlink support */
1145 set_bit(token, sbi->ll_flags);
1147 LCONSOLE_ERROR_MSG(0x152,
1148 "invalid %s option\n", s1);
1159 void ll_lli_init(struct ll_inode_info *lli)
1161 lli->lli_inode_magic = LLI_INODE_MAGIC;
1163 rwlock_init(&lli->lli_lock);
1164 lli->lli_posix_acl = NULL;
1165 /* Do not set lli_fid, it has been initialized already. */
1166 fid_zero(&lli->lli_pfid);
1167 lli->lli_mds_read_och = NULL;
1168 lli->lli_mds_write_och = NULL;
1169 lli->lli_mds_exec_och = NULL;
1170 lli->lli_open_fd_read_count = 0;
1171 lli->lli_open_fd_write_count = 0;
1172 lli->lli_open_fd_exec_count = 0;
1173 mutex_init(&lli->lli_och_mutex);
1174 spin_lock_init(&lli->lli_agl_lock);
1175 spin_lock_init(&lli->lli_layout_lock);
1176 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1177 lli->lli_clob = NULL;
1179 init_rwsem(&lli->lli_xattrs_list_rwsem);
1180 mutex_init(&lli->lli_xattrs_enq_lock);
1182 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1183 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1184 lli->lli_opendir_key = NULL;
1185 lli->lli_sai = NULL;
1186 spin_lock_init(&lli->lli_sa_lock);
1187 lli->lli_opendir_pid = 0;
1188 lli->lli_sa_enabled = 0;
1189 init_rwsem(&lli->lli_lsm_sem);
1191 mutex_init(&lli->lli_size_mutex);
1192 mutex_init(&lli->lli_setattr_mutex);
1193 lli->lli_symlink_name = NULL;
1194 ll_trunc_sem_init(&lli->lli_trunc_sem);
1195 range_lock_tree_init(&lli->lli_write_tree);
1196 init_rwsem(&lli->lli_glimpse_sem);
1197 lli->lli_glimpse_time = ktime_set(0, 0);
1198 INIT_LIST_HEAD(&lli->lli_agl_list);
1199 lli->lli_agl_index = 0;
1200 lli->lli_async_rc = 0;
1201 spin_lock_init(&lli->lli_heat_lock);
1202 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1203 lli->lli_heat_flags = 0;
1204 mutex_init(&lli->lli_pcc_lock);
1205 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1206 lli->lli_pcc_inode = NULL;
1207 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1208 lli->lli_pcc_generation = 0;
1209 mutex_init(&lli->lli_group_mutex);
1210 lli->lli_group_users = 0;
1211 lli->lli_group_gid = 0;
1213 mutex_init(&lli->lli_layout_mutex);
1214 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1215 /* ll_cl_context initialize */
1216 INIT_LIST_HEAD(&lli->lli_lccs);
1219 #define MAX_STRING_SIZE 128
1221 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1222 #ifndef HAVE_BDI_CAP_MAP_COPY
1223 # define BDI_CAP_MAP_COPY 0
1226 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1228 struct lustre_sb_info *lsi = s2lsi(sb);
1229 char buf[MAX_STRING_SIZE];
1233 err = bdi_init(&lsi->lsi_bdi);
1237 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1238 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1239 lsi->lsi_bdi.name = "lustre";
1240 va_start(args, fmt);
1241 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1243 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1246 sb->s_bdi = &lsi->lsi_bdi;
1250 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1252 int ll_fill_super(struct super_block *sb)
1254 struct lustre_profile *lprof = NULL;
1255 struct lustre_sb_info *lsi = s2lsi(sb);
1256 struct ll_sb_info *sbi = NULL;
1257 char *dt = NULL, *md = NULL;
1258 char *profilenm = get_profile_name(sb);
1259 struct config_llog_instance *cfg;
1260 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1261 const int instlen = LUSTRE_MAXINSTANCE + 2;
1262 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1263 char name[MAX_STRING_SIZE];
1272 /* for ASLR, to map between cfg_instance and hashed ptr */
1273 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1274 profilenm, cfg_instance, sb);
1276 OBD_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1280 GOTO(out_free_cfg, err = -ENOMEM);
1282 /* client additional sb info */
1283 lsi->lsi_llsbi = sbi = ll_init_sbi();
1285 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1287 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1289 GOTO(out_free_cfg, err);
1291 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1292 sb->s_d_op = &ll_d_ops;
1295 generate_random_uuid(uuid.b);
1296 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1298 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1301 len = strlen(profilenm);
1302 ptr = strrchr(profilenm, '-');
1303 if (ptr && (strcmp(ptr, "-client") == 0))
1306 if (len > LUSTRE_MAXFSNAME) {
1307 if (unlikely(len >= MAX_STRING_SIZE))
1308 len = MAX_STRING_SIZE - 1;
1309 strncpy(name, profilenm, len);
1311 err = -ENAMETOOLONG;
1312 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1313 name, LUSTRE_MAXFSNAME, err);
1314 GOTO(out_free_cfg, err);
1316 strncpy(sbi->ll_fsname, profilenm, len);
1317 sbi->ll_fsname[len] = '\0';
1320 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1321 profilenm, cfg_instance);
1323 err = super_setup_bdi_name(sb, "%s", name);
1325 GOTO(out_free_cfg, err);
1327 /* disable kernel readahead */
1328 sb->s_bdi->ra_pages = 0;
1330 /* Call ll_debugfs_register_super() before lustre_process_log()
1331 * so that "llite.*.*" params can be processed correctly.
1333 err = ll_debugfs_register_super(sb, name);
1335 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1336 sbi->ll_fsname, err);
1340 /* The cfg_instance is a value unique to this super, in case some
1341 * joker tries to mount the same fs at two mount points.
1343 cfg->cfg_instance = cfg_instance;
1344 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1345 cfg->cfg_callback = class_config_llog_handler;
1346 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1347 /* set up client obds */
1348 err = lustre_process_log(sb, profilenm, cfg);
1350 GOTO(out_debugfs, err);
1352 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1353 lprof = class_get_profile(profilenm);
1354 if (lprof == NULL) {
1355 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1356 " read from the MGS. Does that filesystem "
1357 "exist?\n", profilenm);
1358 GOTO(out_debugfs, err = -EINVAL);
1360 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1361 lprof->lp_md, lprof->lp_dt);
1363 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1364 OBD_ALLOC(dt, dt_len);
1366 GOTO(out_profile, err = -ENOMEM);
1367 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1369 md_len = strlen(lprof->lp_md) + instlen + 2;
1370 OBD_ALLOC(md, md_len);
1372 GOTO(out_free_dt, err = -ENOMEM);
1373 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1375 /* connections, registrations, sb setup */
1376 err = client_common_fill_super(sb, md, dt);
1378 GOTO(out_free_md, err);
1380 sbi->ll_client_common_fill_super_succeeded = 1;
1384 OBD_FREE(md, md_len);
1387 OBD_FREE(dt, dt_len);
1390 class_put_profile(lprof);
1393 ll_debugfs_unregister_super(sb);
1400 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1401 LCONSOLE_WARN("Mounted %s\n", profilenm);
1403 } /* ll_fill_super */
1405 void ll_put_super(struct super_block *sb)
1407 struct config_llog_instance cfg, params_cfg;
1408 struct obd_device *obd;
1409 struct lustre_sb_info *lsi = s2lsi(sb);
1410 struct ll_sb_info *sbi = ll_s2sbi(sb);
1411 char *profilenm = get_profile_name(sb);
1412 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1414 int next, force = 1, rc = 0;
1418 GOTO(out_no_sbi, 0);
1420 /* Should replace instance_id with something better for ASLR */
1421 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1422 profilenm, cfg_instance, sb);
1424 cfg.cfg_instance = cfg_instance;
1425 lustre_end_log(sb, profilenm, &cfg);
1427 params_cfg.cfg_instance = cfg_instance;
1428 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1430 if (sbi->ll_md_exp) {
1431 obd = class_exp2obd(sbi->ll_md_exp);
1433 force = obd->obd_force;
1436 /* Wait for unstable pages to be committed to stable storage */
1438 rc = l_wait_event_abortable(
1439 sbi->ll_cache->ccc_unstable_waitq,
1440 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1443 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1444 if (force == 0 && rc != -ERESTARTSYS)
1445 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1447 /* We need to set force before the lov_disconnect in
1448 * lustre_common_put_super, since l_d cleans up osc's as well.
1452 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1454 obd->obd_force = force;
1458 if (sbi->ll_client_common_fill_super_succeeded) {
1459 /* Only if client_common_fill_super succeeded */
1460 client_common_put_super(sb);
1464 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1465 class_manual_cleanup(obd);
1467 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1468 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1471 class_del_profile(profilenm);
1473 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1474 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1475 bdi_destroy(&lsi->lsi_bdi);
1476 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1480 llcrypt_free_dummy_context(&lsi->lsi_dummy_enc_ctx);
1482 lsi->lsi_llsbi = NULL;
1484 lustre_common_put_super(sb);
1486 cl_env_cache_purge(~0);
1489 } /* client_put_super */
1491 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1493 struct inode *inode = NULL;
1495 /* NOTE: we depend on atomic igrab() -bzzz */
1496 lock_res_and_lock(lock);
1497 if (lock->l_resource->lr_lvb_inode) {
1498 struct ll_inode_info * lli;
1499 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1500 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1501 inode = igrab(lock->l_resource->lr_lvb_inode);
1503 inode = lock->l_resource->lr_lvb_inode;
1504 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1505 D_WARNING, lock, "lr_lvb_inode %p is "
1506 "bogus: magic %08x",
1507 lock->l_resource->lr_lvb_inode,
1508 lli->lli_inode_magic);
1512 unlock_res_and_lock(lock);
1516 void ll_dir_clear_lsm_md(struct inode *inode)
1518 struct ll_inode_info *lli = ll_i2info(inode);
1520 LASSERT(S_ISDIR(inode->i_mode));
1522 if (lli->lli_lsm_md) {
1523 lmv_free_memmd(lli->lli_lsm_md);
1524 lli->lli_lsm_md = NULL;
1527 if (lli->lli_default_lsm_md) {
1528 lmv_free_memmd(lli->lli_default_lsm_md);
1529 lli->lli_default_lsm_md = NULL;
1533 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1534 const struct lu_fid *fid,
1535 struct lustre_md *md)
1537 struct ll_sb_info *sbi = ll_s2sbi(sb);
1538 struct ll_inode_info *lli;
1539 struct mdt_body *body = md->body;
1540 struct inode *inode;
1546 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1547 inode = iget_locked(sb, ino);
1548 if (inode == NULL) {
1549 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1550 sbi->ll_fsname, PFID(fid));
1551 RETURN(ERR_PTR(-ENOENT));
1554 lli = ll_i2info(inode);
1555 if (inode->i_state & I_NEW) {
1556 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1557 (body->mbo_mode & S_IFMT);
1558 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1561 inode->i_mtime.tv_sec = 0;
1562 inode->i_atime.tv_sec = 0;
1563 inode->i_ctime.tv_sec = 0;
1566 #ifdef HAVE_BACKING_DEV_INFO
1567 /* initializing backing dev info. */
1568 inode->i_mapping->backing_dev_info =
1569 &s2lsi(inode->i_sb)->lsi_bdi;
1571 inode->i_op = &ll_dir_inode_operations;
1572 inode->i_fop = &ll_dir_operations;
1573 lli->lli_fid = *fid;
1576 /* master object FID */
1577 lli->lli_pfid = body->mbo_fid1;
1578 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1579 lli, PFID(fid), PFID(&lli->lli_pfid));
1580 unlock_new_inode(inode);
1582 /* in directory restripe/auto-split, a directory will be
1583 * transformed to a stripe if it's plain, set its pfid here,
1584 * otherwise ll_lock_cancel_bits() can't find the master inode.
1586 lli->lli_pfid = body->mbo_fid1;
1592 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1595 struct lmv_stripe_md *lsm = md->lmv;
1596 struct ll_inode_info *lli = ll_i2info(inode);
1599 LASSERT(lsm != NULL);
1601 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1602 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1603 lsm_md_dump(D_INODE, lsm);
1605 if (!lmv_dir_striped(lsm))
1608 /* XXX sigh, this lsm_root initialization should be in
1609 * LMV layer, but it needs ll_iget right now, so we
1610 * put this here right now. */
1611 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1612 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1613 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1615 if (!fid_is_sane(fid))
1618 /* Unfortunately ll_iget will call ll_update_inode,
1619 * where the initialization of slave inode is slightly
1620 * different, so it reset lsm_md to NULL to avoid
1621 * initializing lsm for slave inode. */
1622 lsm->lsm_md_oinfo[i].lmo_root =
1623 ll_iget_anon_dir(inode->i_sb, fid, md);
1624 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1625 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1627 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1629 iput(lsm->lsm_md_oinfo[i].lmo_root);
1630 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1636 lli->lli_lsm_md = lsm;
1641 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1643 struct ll_inode_info *lli = ll_i2info(inode);
1647 if (!md->default_lmv) {
1648 /* clear default lsm */
1649 if (lli->lli_default_lsm_md) {
1650 down_write(&lli->lli_lsm_sem);
1651 if (lli->lli_default_lsm_md) {
1652 lmv_free_memmd(lli->lli_default_lsm_md);
1653 lli->lli_default_lsm_md = NULL;
1655 up_write(&lli->lli_lsm_sem);
1660 if (lli->lli_default_lsm_md) {
1661 /* do nonthing if default lsm isn't changed */
1662 down_read(&lli->lli_lsm_sem);
1663 if (lli->lli_default_lsm_md &&
1664 lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1665 up_read(&lli->lli_lsm_sem);
1668 up_read(&lli->lli_lsm_sem);
1671 down_write(&lli->lli_lsm_sem);
1672 if (lli->lli_default_lsm_md)
1673 lmv_free_memmd(lli->lli_default_lsm_md);
1674 lli->lli_default_lsm_md = md->default_lmv;
1675 lsm_md_dump(D_INODE, md->default_lmv);
1676 md->default_lmv = NULL;
1677 up_write(&lli->lli_lsm_sem);
1681 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1683 struct ll_inode_info *lli = ll_i2info(inode);
1684 struct lmv_stripe_md *lsm = md->lmv;
1685 struct cl_attr *attr;
1690 LASSERT(S_ISDIR(inode->i_mode));
1691 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1692 PFID(ll_inode2fid(inode)));
1694 /* update default LMV */
1695 if (md->default_lmv)
1696 ll_update_default_lsm_md(inode, md);
1698 /* after dir migration/restripe, a stripe may be turned into a
1699 * directory, in this case, zero out its lli_pfid.
1701 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1702 fid_zero(&lli->lli_pfid);
1705 * no striped information from request, lustre_md from req does not
1706 * include stripeEA, see ll_md_setattr()
1712 * normally dir layout doesn't change, only take read lock to check
1713 * that to avoid blocking other MD operations.
1715 down_read(&lli->lli_lsm_sem);
1717 /* some current lookup initialized lsm, and unchanged */
1718 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1719 GOTO(unlock, rc = 0);
1721 /* if dir layout doesn't match, check whether version is increased,
1722 * which means layout is changed, this happens in dir split/merge and
1725 * foreign LMV should not change.
1727 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1728 lsm->lsm_md_layout_version <=
1729 lli->lli_lsm_md->lsm_md_layout_version) {
1730 CERROR("%s: "DFID" dir layout mismatch:\n",
1731 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1732 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1733 lsm_md_dump(D_ERROR, lsm);
1734 GOTO(unlock, rc = -EINVAL);
1737 up_read(&lli->lli_lsm_sem);
1738 down_write(&lli->lli_lsm_sem);
1739 /* clear existing lsm */
1740 if (lli->lli_lsm_md) {
1741 lmv_free_memmd(lli->lli_lsm_md);
1742 lli->lli_lsm_md = NULL;
1745 rc = ll_init_lsm_md(inode, md);
1747 up_write(&lli->lli_lsm_sem);
1751 /* md_merge_attr() may take long, since lsm is already set, switch to
1754 downgrade_write(&lli->lli_lsm_sem);
1756 /* set md->lmv to NULL, so the following free lustre_md will not free
1761 if (!lmv_dir_striped(lli->lli_lsm_md))
1762 GOTO(unlock, rc = 0);
1764 OBD_ALLOC_PTR(attr);
1766 GOTO(unlock, rc = -ENOMEM);
1768 /* validate the lsm */
1769 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1770 ll_md_blocking_ast);
1772 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1773 md->body->mbo_nlink = attr->cat_nlink;
1774 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1775 md->body->mbo_size = attr->cat_size;
1776 if (md->body->mbo_valid & OBD_MD_FLATIME)
1777 md->body->mbo_atime = attr->cat_atime;
1778 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1779 md->body->mbo_ctime = attr->cat_ctime;
1780 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1781 md->body->mbo_mtime = attr->cat_mtime;
1787 up_read(&lli->lli_lsm_sem);
1792 void ll_clear_inode(struct inode *inode)
1794 struct ll_inode_info *lli = ll_i2info(inode);
1795 struct ll_sb_info *sbi = ll_i2sbi(inode);
1799 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1800 PFID(ll_inode2fid(inode)), inode);
1802 if (S_ISDIR(inode->i_mode)) {
1803 /* these should have been cleared in ll_file_release */
1804 LASSERT(lli->lli_opendir_key == NULL);
1805 LASSERT(lli->lli_sai == NULL);
1806 LASSERT(lli->lli_opendir_pid == 0);
1808 pcc_inode_free(inode);
1811 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1813 LASSERT(!lli->lli_open_fd_write_count);
1814 LASSERT(!lli->lli_open_fd_read_count);
1815 LASSERT(!lli->lli_open_fd_exec_count);
1817 if (lli->lli_mds_write_och)
1818 ll_md_real_close(inode, FMODE_WRITE);
1819 if (lli->lli_mds_exec_och)
1820 ll_md_real_close(inode, FMODE_EXEC);
1821 if (lli->lli_mds_read_och)
1822 ll_md_real_close(inode, FMODE_READ);
1824 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1825 OBD_FREE(lli->lli_symlink_name,
1826 strlen(lli->lli_symlink_name) + 1);
1827 lli->lli_symlink_name = NULL;
1830 ll_xattr_cache_destroy(inode);
1832 forget_all_cached_acls(inode);
1834 lli->lli_inode_magic = LLI_INODE_DEAD;
1836 if (S_ISDIR(inode->i_mode))
1837 ll_dir_clear_lsm_md(inode);
1838 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1839 LASSERT(list_empty(&lli->lli_agl_list));
1842 * XXX This has to be done before lsm is freed below, because
1843 * cl_object still uses inode lsm.
1845 cl_inode_fini(inode);
1847 llcrypt_put_encryption_info(inode);
1852 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1854 struct lustre_md md;
1855 struct inode *inode = dentry->d_inode;
1856 struct ll_sb_info *sbi = ll_i2sbi(inode);
1857 struct ptlrpc_request *request = NULL;
1862 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1863 LUSTRE_OPC_ANY, NULL);
1864 if (IS_ERR(op_data))
1865 RETURN(PTR_ERR(op_data));
1867 /* If this is a chgrp of a regular file, we want to reserve enough
1868 * quota to cover the entire file size.
1870 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1871 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1872 from_kgid(&init_user_ns, inode->i_gid)) {
1873 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1874 op_data->op_attr_blocks = inode->i_blocks;
1878 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1880 ptlrpc_req_finished(request);
1881 if (rc == -ENOENT) {
1883 /* Unlinked special device node? Or just a race?
1884 * Pretend we done everything. */
1885 if (!S_ISREG(inode->i_mode) &&
1886 !S_ISDIR(inode->i_mode)) {
1887 ia_valid = op_data->op_attr.ia_valid;
1888 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1889 rc = simple_setattr(&init_user_ns, dentry,
1891 op_data->op_attr.ia_valid = ia_valid;
1893 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1894 CERROR("md_setattr fails: rc = %d\n", rc);
1899 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1900 sbi->ll_md_exp, &md);
1902 ptlrpc_req_finished(request);
1906 ia_valid = op_data->op_attr.ia_valid;
1907 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1908 * cache is not cleared yet. */
1909 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1910 if (S_ISREG(inode->i_mode))
1912 rc = simple_setattr(&init_user_ns, dentry, &op_data->op_attr);
1913 if (S_ISREG(inode->i_mode))
1914 inode_unlock(inode);
1915 op_data->op_attr.ia_valid = ia_valid;
1917 rc = ll_update_inode(inode, &md);
1918 ptlrpc_req_finished(request);
1924 * Zero portion of page that is part of @inode.
1925 * This implies, if necessary:
1926 * - taking cl_lock on range corresponding to concerned page
1927 * - grabbing vm page
1928 * - associating cl_page
1929 * - proceeding to clio read
1930 * - zeroing range in page
1931 * - proceeding to cl_page flush
1932 * - releasing cl_lock
1934 * \param[in] inode inode
1935 * \param[in] index page index
1936 * \param[in] offset offset in page to start zero from
1937 * \param[in] len len to zero
1939 * \retval 0 on success
1940 * \retval negative errno on failure
1942 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
1945 struct ll_inode_info *lli = ll_i2info(inode);
1946 struct cl_object *clob = lli->lli_clob;
1948 struct lu_env *env = NULL;
1949 struct cl_io *io = NULL;
1950 struct cl_page *clpage = NULL;
1951 struct page *vmpage = NULL;
1952 unsigned from = index << PAGE_SHIFT;
1953 struct cl_lock *lock = NULL;
1954 struct cl_lock_descr *descr = NULL;
1955 struct cl_2queue *queue = NULL;
1956 struct cl_sync_io *anchor = NULL;
1957 bool holdinglock = false;
1962 env = cl_env_get(&refcheck);
1964 RETURN(PTR_ERR(env));
1966 io = vvp_env_thread_io(env);
1968 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
1972 lock = vvp_env_lock(env);
1973 descr = &lock->cll_descr;
1974 descr->cld_obj = io->ci_obj;
1975 descr->cld_start = cl_index(io->ci_obj, from);
1976 descr->cld_end = cl_index(io->ci_obj, from + PAGE_SIZE - 1);
1977 descr->cld_mode = CLM_WRITE;
1978 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
1980 /* request lock for page */
1981 rc = cl_lock_request(env, io, lock);
1982 /* -ECANCELED indicates a matching lock with a different extent
1983 * was already present, and -EEXIST indicates a matching lock
1984 * on exactly the same extent was already present.
1985 * In both cases it means we are covered.
1987 if (rc == -ECANCELED || rc == -EEXIST)
1995 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
1997 GOTO(rellock, rc = -EOPNOTSUPP);
1999 if (!PageDirty(vmpage)) {
2000 /* associate cl_page */
2001 clpage = cl_page_find(env, clob, vmpage->index,
2002 vmpage, CPT_CACHEABLE);
2004 GOTO(pagefini, rc = PTR_ERR(clpage));
2006 cl_page_assume(env, io, clpage);
2009 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
2010 !PageWriteback(vmpage)) {
2012 /* Set PagePrivate2 to detect special case of empty page
2013 * in osc_brw_fini_request().
2014 * It is also used to tell ll_io_read_page() that we do not
2015 * want the vmpage to be unlocked.
2017 SetPagePrivate2(vmpage);
2018 rc = ll_io_read_page(env, io, clpage, NULL);
2019 if (!PagePrivate2(vmpage)) {
2020 /* PagePrivate2 was cleared in osc_brw_fini_request()
2021 * meaning we read an empty page. In this case, in order
2022 * to avoid allocating unnecessary block in truncated
2023 * file, we must not zero and write as below. Subsequent
2024 * server-side truncate will handle things correctly.
2026 cl_page_unassume(env, io, clpage);
2027 GOTO(clpfini, rc = 0);
2029 ClearPagePrivate2(vmpage);
2034 /* Thanks to PagePrivate2 flag, ll_io_read_page() did not unlock
2035 * the vmpage, so we are good to proceed and zero range in page.
2037 zero_user(vmpage, offset, len);
2039 if (holdinglock && clpage) {
2040 /* explicitly write newly modified page */
2041 queue = &io->ci_queue;
2042 cl_2queue_init(queue);
2043 anchor = &vvp_env_info(env)->vti_anchor;
2044 cl_sync_io_init(anchor, 1);
2045 clpage->cp_sync_io = anchor;
2046 cl_2queue_add(queue, clpage, true);
2047 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
2049 GOTO(queuefini1, rc);
2050 rc = cl_sync_io_wait(env, anchor, 0);
2052 GOTO(queuefini2, rc);
2053 cl_page_assume(env, io, clpage);
2056 cl_2queue_discard(env, io, queue);
2058 cl_2queue_disown(env, io, queue);
2059 cl_2queue_fini(env, queue);
2064 cl_page_put(env, clpage);
2066 unlock_page(vmpage);
2070 cl_lock_release(env, lock);
2072 cl_io_fini(env, io);
2075 cl_env_put(env, &refcheck);
2081 * Get reference file from volatile file name.
2082 * Volatile file name may look like:
2083 * <parent>/LUSTRE_VOLATILE_HDR:<mdt_index>:<random>:fd=<fd>
2084 * where fd is opened descriptor of reference file.
2086 * \param[in] volatile_name volatile file name
2087 * \param[in] volatile_len volatile file name length
2088 * \param[out] ref_file pointer to struct file of reference file
2090 * \retval 0 on success
2091 * \retval negative errno on failure
2093 int volatile_ref_file(const char *volatile_name, int volatile_len,
2094 struct file **ref_file)
2096 char *p, *q, *fd_str;
2099 p = strnstr(volatile_name, ":fd=", volatile_len);
2100 if (!p || strlen(p + 4) == 0)
2103 q = strchrnul(p + 4, ':');
2104 fd_str = kstrndup(p + 4, q - p - 4, GFP_NOFS);
2107 rc = kstrtouint(fd_str, 10, &fd);
2112 *ref_file = fget(fd);
2118 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2119 * object(s) determine the file size and mtime. Otherwise, the MDS will
2120 * keep these values until such a time that objects are allocated for it.
2121 * We do the MDS operations first, as it is checking permissions for us.
2122 * We don't to the MDS RPC if there is nothing that we want to store there,
2123 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2124 * going to do an RPC anyways.
2126 * If we are doing a truncate, we will send the mtime and ctime updates
2127 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2128 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2131 * In case of HSMimport, we only set attr on MDS.
2133 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2134 enum op_xvalid xvalid, bool hsm_import)
2136 struct inode *inode = dentry->d_inode;
2137 struct ll_inode_info *lli = ll_i2info(inode);
2138 struct md_op_data *op_data = NULL;
2139 ktime_t kstart = ktime_get();
2144 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2145 "valid %x, hsm_import %d\n",
2146 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2147 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2150 if (attr->ia_valid & ATTR_SIZE) {
2151 /* Check new size against VFS/VM file size limit and rlimit */
2152 rc = inode_newsize_ok(inode, attr->ia_size);
2156 /* The maximum Lustre file size is variable, based on the
2157 * OST maximum object size and number of stripes. This
2158 * needs another check in addition to the VFS check above. */
2159 if (attr->ia_size > ll_file_maxbytes(inode)) {
2160 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2161 PFID(&lli->lli_fid), attr->ia_size,
2162 ll_file_maxbytes(inode));
2166 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2169 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2170 if (attr->ia_valid & TIMES_SET_FLAGS) {
2171 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2172 !capable(CAP_FOWNER))
2176 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2177 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2178 (attr->ia_valid & ATTR_CTIME)) {
2179 attr->ia_ctime = current_time(inode);
2180 xvalid |= OP_XVALID_CTIME_SET;
2182 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2183 (attr->ia_valid & ATTR_ATIME)) {
2184 attr->ia_atime = current_time(inode);
2185 attr->ia_valid |= ATTR_ATIME_SET;
2187 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2188 (attr->ia_valid & ATTR_MTIME)) {
2189 attr->ia_mtime = current_time(inode);
2190 attr->ia_valid |= ATTR_MTIME_SET;
2193 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2194 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2195 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2196 ktime_get_real_seconds());
2198 if (S_ISREG(inode->i_mode))
2199 inode_unlock(inode);
2201 /* We always do an MDS RPC, even if we're only changing the size;
2202 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2204 OBD_ALLOC_PTR(op_data);
2205 if (op_data == NULL)
2206 GOTO(out, rc = -ENOMEM);
2208 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2209 /* If we are changing file size, file content is
2210 * modified, flag it.
2212 xvalid |= OP_XVALID_OWNEROVERRIDE;
2213 op_data->op_bias |= MDS_DATA_MODIFIED;
2214 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2217 if (attr->ia_valid & ATTR_FILE) {
2218 struct ll_file_data *fd = attr->ia_file->private_data;
2220 if (fd->fd_lease_och)
2221 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2224 op_data->op_attr = *attr;
2225 op_data->op_xvalid = xvalid;
2227 rc = ll_md_setattr(dentry, op_data);
2231 if (!S_ISREG(inode->i_mode) || hsm_import)
2234 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2235 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2236 xvalid & OP_XVALID_CTIME_SET) {
2237 bool cached = false;
2239 rc = pcc_inode_setattr(inode, attr, &cached);
2242 CERROR("%s: PCC inode "DFID" setattr failed: "
2244 ll_i2sbi(inode)->ll_fsname,
2245 PFID(&lli->lli_fid), rc);
2249 unsigned int flags = 0;
2251 /* For truncate and utimes sending attributes to OSTs,
2252 * setting mtime/atime to the past will be performed
2253 * under PW [0:EOF] extent lock (new_size:EOF for
2254 * truncate). It may seem excessive to send mtime/atime
2255 * updates to OSTs when not setting times to past, but
2256 * it is necessary due to possible time
2257 * de-synchronization between MDT inode and OST objects
2259 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2260 xvalid |= OP_XVALID_FLAGS;
2261 flags = LUSTRE_ENCRYPT_FL;
2262 /* Call to ll_io_zero_page is not necessary if
2263 * truncating on PAGE_SIZE boundary, because
2264 * whole pages will be wiped.
2265 * In case of Direct IO, all we need is to set
2268 if (attr->ia_valid & ATTR_SIZE &&
2269 attr->ia_size & ~PAGE_MASK &&
2270 !(attr->ia_valid & ATTR_FILE &&
2271 attr->ia_file->f_flags & O_DIRECT)) {
2273 attr->ia_size & (PAGE_SIZE - 1);
2275 rc = ll_io_zero_page(inode,
2276 attr->ia_size >> PAGE_SHIFT,
2277 offset, PAGE_SIZE - offset);
2281 /* If encrypted volatile file without the key,
2282 * we need to fetch size from reference file,
2283 * and set it on OST objects. This happens when
2284 * migrating or extending an encrypted file
2287 if (filename_is_volatile(dentry->d_name.name,
2290 llcrypt_require_key(inode) == -ENOKEY) {
2291 struct file *ref_file;
2292 struct inode *ref_inode;
2293 struct ll_inode_info *ref_lli;
2294 struct cl_object *ref_obj;
2295 struct cl_attr ref_attr = { 0 };
2299 rc = volatile_ref_file(
2300 dentry->d_name.name,
2306 ref_inode = file_inode(ref_file);
2309 GOTO(out, rc = -EINVAL);
2312 env = cl_env_get(&refcheck);
2314 GOTO(out, rc = PTR_ERR(env));
2316 ref_lli = ll_i2info(ref_inode);
2317 ref_obj = ref_lli->lli_clob;
2318 cl_object_attr_lock(ref_obj);
2319 rc = cl_object_attr_get(env, ref_obj,
2321 cl_object_attr_unlock(ref_obj);
2322 cl_env_put(env, &refcheck);
2327 attr->ia_valid |= ATTR_SIZE;
2328 attr->ia_size = ref_attr.cat_size;
2331 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2335 /* If the file was restored, it needs to set dirty flag.
2337 * We've already sent MDS_DATA_MODIFIED flag in
2338 * ll_md_setattr() for truncate. However, the MDT refuses to
2339 * set the HS_DIRTY flag on released files, so we have to set
2340 * it again if the file has been restored. Please check how
2341 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2343 * Please notice that if the file is not released, the previous
2344 * MDS_DATA_MODIFIED has taken effect and usually
2345 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2346 * This way we can save an RPC for common open + trunc
2348 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2349 struct hsm_state_set hss = {
2350 .hss_valid = HSS_SETMASK,
2351 .hss_setmask = HS_DIRTY,
2355 rc2 = ll_hsm_state_set(inode, &hss);
2356 /* truncate and write can happen at the same time, so that
2357 * the file can be set modified even though the file is not
2358 * restored from released state, and ll_hsm_state_set() is
2359 * not applicable for the file, and rc2 < 0 is normal in this
2362 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2363 PFID(ll_inode2fid(inode)), rc2);
2368 if (op_data != NULL)
2369 ll_finish_md_op_data(op_data);
2371 if (S_ISREG(inode->i_mode)) {
2373 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2374 inode_dio_wait(inode);
2375 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2376 * flag. ll_update_inode (called from ll_md_setattr), clears
2377 * inode flags, so there is a gap where S_NOSEC is not set.
2378 * This can cause a writer to take the i_mutex unnecessarily,
2379 * but this is safe to do and should be rare. */
2380 inode_has_no_xattr(inode);
2384 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2385 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2386 ktime_us_delta(ktime_get(), kstart));
2391 int ll_setattr(struct user_namespace *mnt_userns, struct dentry *de,
2394 int mode = de->d_inode->i_mode;
2395 enum op_xvalid xvalid = 0;
2398 rc = llcrypt_prepare_setattr(de, attr);
2402 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2403 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2404 xvalid |= OP_XVALID_OWNEROVERRIDE;
2406 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2407 (ATTR_SIZE|ATTR_MODE)) &&
2408 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2409 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2410 !(attr->ia_mode & S_ISGID))))
2411 attr->ia_valid |= ATTR_FORCE;
2413 if ((attr->ia_valid & ATTR_MODE) &&
2415 !(attr->ia_mode & S_ISUID) &&
2416 !(attr->ia_valid & ATTR_KILL_SUID))
2417 attr->ia_valid |= ATTR_KILL_SUID;
2419 if ((attr->ia_valid & ATTR_MODE) &&
2420 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2421 !(attr->ia_mode & S_ISGID) &&
2422 !(attr->ia_valid & ATTR_KILL_SGID))
2423 attr->ia_valid |= ATTR_KILL_SGID;
2425 return ll_setattr_raw(de, attr, xvalid, false);
2428 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2431 struct obd_statfs obd_osfs = { 0 };
2436 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2438 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2439 flags |= OBD_STATFS_NODELAY;
2441 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2445 osfs->os_type = LL_SUPER_MAGIC;
2447 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2448 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2450 if (osfs->os_state & OS_STATFS_SUM)
2453 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2454 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2457 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2458 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2461 osfs->os_bsize = obd_osfs.os_bsize;
2462 osfs->os_blocks = obd_osfs.os_blocks;
2463 osfs->os_bfree = obd_osfs.os_bfree;
2464 osfs->os_bavail = obd_osfs.os_bavail;
2466 /* If we have _some_ OSTs, but don't have as many free objects on the
2467 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2468 * to compensate, so that the "inodes in use" number is correct.
2469 * This should be kept in sync with lod_statfs() behaviour.
2471 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2472 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2474 osfs->os_ffree = obd_osfs.os_ffree;
2481 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2483 struct if_quotactl qctl = {
2484 .qc_cmd = LUSTRE_Q_GETQUOTA,
2485 .qc_type = PRJQUOTA,
2486 .qc_valid = QC_GENERAL,
2488 u64 limit, curblock;
2491 qctl.qc_id = ll_i2info(inode)->lli_projid;
2492 ret = quotactl_ioctl(inode->i_sb, &qctl);
2494 /* ignore errors if project ID does not have
2495 * a quota limit or feature unsupported.
2497 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2502 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2503 qctl.qc_dqblk.dqb_bsoftlimit :
2504 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2505 if (limit && sfs->f_blocks > limit) {
2506 curblock = (qctl.qc_dqblk.dqb_curspace +
2507 sfs->f_bsize - 1) / sfs->f_bsize;
2508 sfs->f_blocks = limit;
2509 sfs->f_bfree = sfs->f_bavail =
2510 (sfs->f_blocks > curblock) ?
2511 (sfs->f_blocks - curblock) : 0;
2514 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2515 qctl.qc_dqblk.dqb_isoftlimit :
2516 qctl.qc_dqblk.dqb_ihardlimit;
2517 if (limit && sfs->f_files > limit) {
2518 sfs->f_files = limit;
2519 sfs->f_ffree = (sfs->f_files >
2520 qctl.qc_dqblk.dqb_curinodes) ?
2521 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2527 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2529 struct super_block *sb = de->d_sb;
2530 struct obd_statfs osfs;
2531 __u64 fsid = huge_encode_dev(sb->s_dev);
2532 ktime_t kstart = ktime_get();
2535 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2537 /* Some amount of caching on the client is allowed */
2538 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2542 statfs_unpack(sfs, &osfs);
2544 /* We need to downshift for all 32-bit kernels, because we can't
2545 * tell if the kernel is being called via sys_statfs64() or not.
2546 * Stop before overflowing f_bsize - in which case it is better
2547 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2548 if (sizeof(long) < 8) {
2549 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2552 osfs.os_blocks >>= 1;
2553 osfs.os_bfree >>= 1;
2554 osfs.os_bavail >>= 1;
2558 sfs->f_blocks = osfs.os_blocks;
2559 sfs->f_bfree = osfs.os_bfree;
2560 sfs->f_bavail = osfs.os_bavail;
2561 sfs->f_fsid.val[0] = (__u32)fsid;
2562 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2563 if (ll_i2info(de->d_inode)->lli_projid)
2564 return ll_statfs_project(de->d_inode, sfs);
2566 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2567 ktime_us_delta(ktime_get(), kstart));
2572 void ll_inode_size_lock(struct inode *inode)
2574 struct ll_inode_info *lli;
2576 LASSERT(!S_ISDIR(inode->i_mode));
2578 lli = ll_i2info(inode);
2579 mutex_lock(&lli->lli_size_mutex);
2582 void ll_inode_size_unlock(struct inode *inode)
2584 struct ll_inode_info *lli;
2586 lli = ll_i2info(inode);
2587 mutex_unlock(&lli->lli_size_mutex);
2590 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2592 /* do not clear encryption flag */
2593 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2594 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2595 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2596 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2598 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2601 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2603 struct ll_inode_info *lli = ll_i2info(inode);
2604 struct mdt_body *body = md->body;
2605 struct ll_sb_info *sbi = ll_i2sbi(inode);
2609 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2610 rc = cl_file_inode_init(inode, md);
2615 if (S_ISDIR(inode->i_mode)) {
2616 rc = ll_update_lsm_md(inode, md);
2621 if (body->mbo_valid & OBD_MD_FLACL)
2622 lli_replace_acl(lli, md);
2624 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2625 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2626 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2628 if (body->mbo_valid & OBD_MD_FLATIME) {
2629 if (body->mbo_atime > inode->i_atime.tv_sec)
2630 inode->i_atime.tv_sec = body->mbo_atime;
2631 lli->lli_atime = body->mbo_atime;
2634 if (body->mbo_valid & OBD_MD_FLMTIME) {
2635 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2637 "setting ino %lu mtime from %lld to %llu\n",
2638 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2640 inode->i_mtime.tv_sec = body->mbo_mtime;
2642 lli->lli_mtime = body->mbo_mtime;
2645 if (body->mbo_valid & OBD_MD_FLCTIME) {
2646 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2647 inode->i_ctime.tv_sec = body->mbo_ctime;
2648 lli->lli_ctime = body->mbo_ctime;
2651 if (body->mbo_valid & OBD_MD_FLBTIME)
2652 lli->lli_btime = body->mbo_btime;
2654 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2655 if (body->mbo_valid & OBD_MD_FLFLAGS)
2656 ll_update_inode_flags(inode, body->mbo_flags);
2657 if (body->mbo_valid & OBD_MD_FLMODE)
2658 inode->i_mode = (inode->i_mode & S_IFMT) |
2659 (body->mbo_mode & ~S_IFMT);
2661 if (body->mbo_valid & OBD_MD_FLTYPE)
2662 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2663 (body->mbo_mode & S_IFMT);
2665 LASSERT(inode->i_mode != 0);
2666 if (body->mbo_valid & OBD_MD_FLUID)
2667 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2668 if (body->mbo_valid & OBD_MD_FLGID)
2669 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2670 if (body->mbo_valid & OBD_MD_FLPROJID)
2671 lli->lli_projid = body->mbo_projid;
2672 if (body->mbo_valid & OBD_MD_FLNLINK) {
2673 spin_lock(&inode->i_lock);
2674 set_nlink(inode, body->mbo_nlink);
2675 spin_unlock(&inode->i_lock);
2677 if (body->mbo_valid & OBD_MD_FLRDEV)
2678 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2680 if (body->mbo_valid & OBD_MD_FLID) {
2681 /* FID shouldn't be changed! */
2682 if (fid_is_sane(&lli->lli_fid)) {
2683 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2684 "Trying to change FID "DFID
2685 " to the "DFID", inode "DFID"(%p)\n",
2686 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2687 PFID(ll_inode2fid(inode)), inode);
2689 lli->lli_fid = body->mbo_fid1;
2693 LASSERT(fid_seq(&lli->lli_fid) != 0);
2695 /* In case of encrypted file without the key, please do not lose
2696 * clear text size stored into lli_lazysize in ll_merge_attr(),
2697 * we will need it in ll_prepare_close().
2699 if (lli->lli_attr_valid & OBD_MD_FLLAZYSIZE && lli->lli_lazysize &&
2700 llcrypt_require_key(inode) == -ENOKEY)
2701 lli->lli_attr_valid = body->mbo_valid | OBD_MD_FLLAZYSIZE;
2703 lli->lli_attr_valid = body->mbo_valid;
2704 if (body->mbo_valid & OBD_MD_FLSIZE) {
2705 i_size_write(inode, body->mbo_size);
2707 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2708 PFID(ll_inode2fid(inode)),
2709 (unsigned long long)body->mbo_size);
2711 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2712 inode->i_blocks = body->mbo_blocks;
2714 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2715 lli->lli_lazysize = body->mbo_size;
2716 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2717 lli->lli_lazyblocks = body->mbo_blocks;
2720 if (body->mbo_valid & OBD_MD_TSTATE) {
2721 /* Set LLIF_FILE_RESTORING if restore ongoing and
2722 * clear it when done to ensure to start again
2723 * glimpsing updated attrs
2725 if (body->mbo_t_state & MS_RESTORE)
2726 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2728 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2734 /* update directory depth to ROOT, called after LOOKUP lock is fetched. */
2735 void ll_update_dir_depth(struct inode *dir, struct inode *inode)
2737 struct ll_inode_info *lli;
2739 if (!S_ISDIR(inode->i_mode))
2745 lli = ll_i2info(inode);
2746 lli->lli_dir_depth = ll_i2info(dir)->lli_dir_depth + 1;
2747 CDEBUG(D_INODE, DFID" depth %hu\n",
2748 PFID(&lli->lli_fid), lli->lli_dir_depth);
2751 void ll_truncate_inode_pages_final(struct inode *inode)
2753 struct address_space *mapping = &inode->i_data;
2754 unsigned long nrpages;
2755 unsigned long flags;
2757 truncate_inode_pages_final(mapping);
2759 /* Workaround for LU-118: Note nrpages may not be totally updated when
2760 * truncate_inode_pages() returns, as there can be a page in the process
2761 * of deletion (inside __delete_from_page_cache()) in the specified
2762 * range. Thus mapping->nrpages can be non-zero when this function
2763 * returns even after truncation of the whole mapping. Only do this if
2764 * npages isn't already zero.
2766 nrpages = mapping->nrpages;
2768 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2769 nrpages = mapping->nrpages;
2770 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2771 } /* Workaround end */
2773 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, "
2774 "see https://jira.whamcloud.com/browse/LU-118\n",
2775 ll_i2sbi(inode)->ll_fsname,
2776 PFID(ll_inode2fid(inode)), inode, nrpages);
2779 int ll_read_inode2(struct inode *inode, void *opaque)
2781 struct lustre_md *md = opaque;
2782 struct ll_inode_info *lli = ll_i2info(inode);
2786 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2787 PFID(&lli->lli_fid), inode);
2789 /* Core attributes from the MDS first. This is a new inode, and
2790 * the VFS doesn't zero times in the core inode so we have to do
2791 * it ourselves. They will be overwritten by either MDS or OST
2792 * attributes - we just need to make sure they aren't newer.
2794 inode->i_mtime.tv_sec = 0;
2795 inode->i_atime.tv_sec = 0;
2796 inode->i_ctime.tv_sec = 0;
2798 rc = ll_update_inode(inode, md);
2802 /* OIDEBUG(inode); */
2804 #ifdef HAVE_BACKING_DEV_INFO
2805 /* initializing backing dev info. */
2806 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2808 if (S_ISREG(inode->i_mode)) {
2809 struct ll_sb_info *sbi = ll_i2sbi(inode);
2810 inode->i_op = &ll_file_inode_operations;
2811 inode->i_fop = sbi->ll_fop;
2812 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2814 } else if (S_ISDIR(inode->i_mode)) {
2815 inode->i_op = &ll_dir_inode_operations;
2816 inode->i_fop = &ll_dir_operations;
2818 } else if (S_ISLNK(inode->i_mode)) {
2819 inode->i_op = &ll_fast_symlink_inode_operations;
2822 inode->i_op = &ll_special_inode_operations;
2824 init_special_inode(inode, inode->i_mode,
2833 void ll_delete_inode(struct inode *inode)
2835 struct ll_inode_info *lli = ll_i2info(inode);
2838 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2839 /* It is last chance to write out dirty pages,
2840 * otherwise we may lose data while umount.
2842 * If i_nlink is 0 then just discard data. This is safe because
2843 * local inode gets i_nlink 0 from server only for the last
2844 * unlink, so that file is not opened somewhere else
2846 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2847 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2850 ll_truncate_inode_pages_final(inode);
2851 ll_clear_inode(inode);
2857 int ll_iocontrol(struct inode *inode, struct file *file,
2858 unsigned int cmd, unsigned long arg)
2860 struct ll_sb_info *sbi = ll_i2sbi(inode);
2861 struct ptlrpc_request *req = NULL;
2866 case FS_IOC_GETFLAGS: {
2867 struct mdt_body *body;
2868 struct md_op_data *op_data;
2870 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2871 0, 0, LUSTRE_OPC_ANY,
2873 if (IS_ERR(op_data))
2874 RETURN(PTR_ERR(op_data));
2876 op_data->op_valid = OBD_MD_FLFLAGS;
2877 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2878 ll_finish_md_op_data(op_data);
2880 CERROR("%s: failure inode "DFID": rc = %d\n",
2881 sbi->ll_md_exp->exp_obd->obd_name,
2882 PFID(ll_inode2fid(inode)), rc);
2886 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2888 flags = body->mbo_flags;
2890 ptlrpc_req_finished(req);
2892 RETURN(put_user(flags, (int __user *)arg));
2894 case FS_IOC_SETFLAGS: {
2896 struct md_op_data *op_data;
2897 struct cl_object *obj;
2898 struct fsxattr fa = { 0 };
2900 if (get_user(flags, (int __user *)arg))
2903 fa.fsx_projid = ll_i2info(inode)->lli_projid;
2904 if (flags & LUSTRE_PROJINHERIT_FL)
2905 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
2907 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
2912 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
2913 LUSTRE_OPC_ANY, NULL);
2914 if (IS_ERR(op_data))
2915 RETURN(PTR_ERR(op_data));
2917 op_data->op_attr_flags = flags;
2918 op_data->op_xvalid |= OP_XVALID_FLAGS;
2919 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
2920 ll_finish_md_op_data(op_data);
2921 ptlrpc_req_finished(req);
2925 ll_update_inode_flags(inode, flags);
2927 obj = ll_i2info(inode)->lli_clob;
2931 OBD_ALLOC_PTR(attr);
2935 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
2947 int ll_flush_ctx(struct inode *inode)
2949 struct ll_sb_info *sbi = ll_i2sbi(inode);
2951 CDEBUG(D_SEC, "flush context for user %d\n",
2952 from_kuid(&init_user_ns, current_uid()));
2954 obd_set_info_async(NULL, sbi->ll_md_exp,
2955 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2957 obd_set_info_async(NULL, sbi->ll_dt_exp,
2958 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2963 /* umount -f client means force down, don't save state */
2964 void ll_umount_begin(struct super_block *sb)
2966 struct ll_sb_info *sbi = ll_s2sbi(sb);
2967 struct obd_device *obd;
2968 struct obd_ioctl_data *ioc_data;
2972 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2973 sb->s_count, atomic_read(&sb->s_active));
2975 obd = class_exp2obd(sbi->ll_md_exp);
2977 CERROR("Invalid MDC connection handle %#llx\n",
2978 sbi->ll_md_exp->exp_handle.h_cookie);
2984 obd = class_exp2obd(sbi->ll_dt_exp);
2986 CERROR("Invalid LOV connection handle %#llx\n",
2987 sbi->ll_dt_exp->exp_handle.h_cookie);
2993 OBD_ALLOC_PTR(ioc_data);
2995 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2996 sizeof *ioc_data, ioc_data, NULL);
2998 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2999 sizeof *ioc_data, ioc_data, NULL);
3001 OBD_FREE_PTR(ioc_data);
3004 /* Really, we'd like to wait until there are no requests outstanding,
3005 * and then continue. For now, we just periodically checking for vfs
3006 * to decrement mnt_cnt and hope to finish it within 10sec.
3010 !may_umount(sbi->ll_mnt.mnt)) {
3018 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
3020 struct ll_sb_info *sbi = ll_s2sbi(sb);
3021 char *profilenm = get_profile_name(sb);
3025 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
3026 read_only = *flags & MS_RDONLY;
3027 err = obd_set_info_async(NULL, sbi->ll_md_exp,
3028 sizeof(KEY_READ_ONLY),
3029 KEY_READ_ONLY, sizeof(read_only),
3032 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
3033 profilenm, read_only ?
3034 "read-only" : "read-write", err);
3039 sb->s_flags |= SB_RDONLY;
3041 sb->s_flags &= ~SB_RDONLY;
3043 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
3044 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
3045 read_only ? "read-only" : "read-write");
3051 * Cleanup the open handle that is cached on MDT-side.
3053 * For open case, the client side open handling thread may hit error
3054 * after the MDT grant the open. Under such case, the client should
3055 * send close RPC to the MDT as cleanup; otherwise, the open handle
3056 * on the MDT will be leaked there until the client umount or evicted.
3058 * In further, if someone unlinked the file, because the open handle
3059 * holds the reference on such file/object, then it will block the
3060 * subsequent threads that want to locate such object via FID.
3062 * \param[in] sb super block for this file-system
3063 * \param[in] open_req pointer to the original open request
3065 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
3067 struct mdt_body *body;
3068 struct md_op_data *op_data;
3069 struct ptlrpc_request *close_req = NULL;
3070 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
3073 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
3074 OBD_ALLOC_PTR(op_data);
3075 if (op_data == NULL) {
3076 CWARN("%s: cannot allocate op_data to release open handle for "
3077 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
3082 op_data->op_fid1 = body->mbo_fid1;
3083 op_data->op_open_handle = body->mbo_open_handle;
3084 op_data->op_mod_time = ktime_get_real_seconds();
3085 md_close(exp, op_data, NULL, &close_req);
3086 ptlrpc_req_finished(close_req);
3087 ll_finish_md_op_data(op_data);
3092 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
3093 struct super_block *sb, struct lookup_intent *it)
3095 struct ll_sb_info *sbi = NULL;
3096 struct lustre_md md = { NULL };
3097 bool default_lmv_deleted = false;
3102 LASSERT(*inode || sb);
3103 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
3104 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
3105 sbi->ll_md_exp, &md);
3110 * clear default_lmv only if intent_getattr reply doesn't contain it.
3111 * but it needs to be done after iget, check this early because
3112 * ll_update_lsm_md() may change md.
3114 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
3115 S_ISDIR(md.body->mbo_mode) && !md.default_lmv)
3116 default_lmv_deleted = true;
3119 rc = ll_update_inode(*inode, &md);
3123 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
3124 struct lu_fid *fid1 = &md.body->mbo_fid1;
3126 LASSERT(sb != NULL);
3129 * At this point server returns to client's same fid as client
3130 * generated for creating. So using ->fid1 is okay here.
3132 if (!fid_is_sane(fid1)) {
3133 CERROR("%s: Fid is insane "DFID"\n",
3134 sbi->ll_fsname, PFID(fid1));
3135 GOTO(out, rc = -EINVAL);
3138 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
3139 if (IS_ERR(*inode)) {
3141 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
3143 CERROR("new_inode -fatal: rc %d\n", rc);
3148 /* Handling piggyback layout lock.
3149 * Layout lock can be piggybacked by getattr and open request.
3150 * The lsm can be applied to inode only if it comes with a layout lock
3151 * otherwise correct layout may be overwritten, for example:
3152 * 1. proc1: mdt returns a lsm but not granting layout
3153 * 2. layout was changed by another client
3154 * 3. proc2: refresh layout and layout lock granted
3155 * 4. proc1: to apply a stale layout */
3156 if (it != NULL && it->it_lock_mode != 0) {
3157 struct lustre_handle lockh;
3158 struct ldlm_lock *lock;
3160 lockh.cookie = it->it_lock_handle;
3161 lock = ldlm_handle2lock(&lockh);
3162 LASSERT(lock != NULL);
3163 if (ldlm_has_layout(lock)) {
3164 struct cl_object_conf conf;
3166 memset(&conf, 0, sizeof(conf));
3167 conf.coc_opc = OBJECT_CONF_SET;
3168 conf.coc_inode = *inode;
3169 conf.coc_lock = lock;
3170 conf.u.coc_layout = md.layout;
3171 (void)ll_layout_conf(*inode, &conf);
3173 LDLM_LOCK_PUT(lock);
3176 if (default_lmv_deleted)
3177 ll_update_default_lsm_md(*inode, &md);
3179 /* we may want to apply some policy for foreign file/dir */
3180 if (ll_sbi_has_foreign_symlink(sbi)) {
3181 rc = ll_manage_foreign(*inode, &md);
3189 /* cleanup will be done if necessary */
3190 md_free_lustre_md(sbi->ll_md_exp, &md);
3192 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3193 ll_intent_drop_lock(it);
3194 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3200 int ll_obd_statfs(struct inode *inode, void __user *arg)
3202 struct ll_sb_info *sbi = NULL;
3203 struct obd_export *exp;
3204 struct obd_ioctl_data *data = NULL;
3209 sbi = ll_i2sbi(inode);
3211 GOTO(out_statfs, rc = -EINVAL);
3213 rc = obd_ioctl_getdata(&data, &len, arg);
3215 GOTO(out_statfs, rc);
3217 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3218 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3219 GOTO(out_statfs, rc = -EINVAL);
3221 if (data->ioc_inllen1 != sizeof(__u32) ||
3222 data->ioc_inllen2 != sizeof(__u32) ||
3223 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3224 data->ioc_plen2 != sizeof(struct obd_uuid))
3225 GOTO(out_statfs, rc = -EINVAL);
3227 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3228 if (type & LL_STATFS_LMV)
3229 exp = sbi->ll_md_exp;
3230 else if (type & LL_STATFS_LOV)
3231 exp = sbi->ll_dt_exp;
3233 GOTO(out_statfs, rc = -ENODEV);
3235 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3237 GOTO(out_statfs, rc);
3239 OBD_FREE_LARGE(data, len);
3244 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3245 * be called early to avoid deadlock.
3247 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3249 if (op_data->op_mea2_sem) {
3250 up_read_non_owner(op_data->op_mea2_sem);
3251 op_data->op_mea2_sem = NULL;
3254 if (op_data->op_mea1_sem) {
3255 up_read_non_owner(op_data->op_mea1_sem);
3256 op_data->op_mea1_sem = NULL;
3260 /* this function prepares md_op_data hint for passing it down to MD stack. */
3261 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3262 struct inode *i1, struct inode *i2,
3263 const char *name, size_t namelen,
3264 __u32 mode, enum md_op_code opc,
3267 struct llcrypt_name fname = { 0 };
3270 LASSERT(i1 != NULL);
3273 /* Do not reuse namelen for something else. */
3275 return ERR_PTR(-EINVAL);
3277 if ((!IS_ENCRYPTED(i1) ||
3278 (opc != LUSTRE_OPC_LOOKUP && opc != LUSTRE_OPC_CREATE)) &&
3279 namelen > ll_i2sbi(i1)->ll_namelen)
3280 return ERR_PTR(-ENAMETOOLONG);
3282 /* "/" is not valid name, but it's allowed */
3283 if (!lu_name_is_valid_2(name, namelen) &&
3284 strncmp("/", name, namelen) != 0)
3285 return ERR_PTR(-EINVAL);
3288 if (op_data == NULL)
3289 OBD_ALLOC_PTR(op_data);
3291 if (op_data == NULL)
3292 return ERR_PTR(-ENOMEM);
3294 ll_i2gids(op_data->op_suppgids, i1, i2);
3295 /* If the client is using a subdir mount and looks at what it sees as
3296 * /.fscrypt, interpret it as the .fscrypt dir at the root of the fs.
3298 if (unlikely(i1->i_sb && i1->i_sb->s_root && is_root_inode(i1) &&
3299 !fid_is_root(ll_inode2fid(i1)) &&
3300 name && namelen == strlen(dot_fscrypt_name) &&
3301 strncmp(name, dot_fscrypt_name, namelen) == 0))
3302 lu_root_fid(&op_data->op_fid1);
3304 op_data->op_fid1 = *ll_inode2fid(i1);
3306 if (S_ISDIR(i1->i_mode)) {
3307 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3308 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3309 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3310 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3314 op_data->op_fid2 = *ll_inode2fid(i2);
3315 if (S_ISDIR(i2->i_mode)) {
3317 /* i2 is typically a child of i1, and MUST be
3318 * further from the root to avoid deadlocks.
3320 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3321 op_data->op_mea2_sem =
3322 &ll_i2info(i2)->lli_lsm_sem;
3324 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3327 fid_zero(&op_data->op_fid2);
3330 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3331 op_data->op_cli_flags |= CLI_HASH64;
3333 if (ll_need_32bit_api(ll_i2sbi(i1)))
3334 op_data->op_cli_flags |= CLI_API32;
3336 if ((i2 && is_root_inode(i2)) ||
3337 opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3338 /* In case of lookup, ll_setup_filename() has already been
3339 * called in ll_lookup_it(), so just take provided name.
3340 * Also take provided name if we are dealing with root inode.
3342 fname.disk_name.name = (unsigned char *)name;
3343 fname.disk_name.len = namelen;
3344 } else if (name && namelen) {
3345 struct qstr dname = QSTR_INIT(name, namelen);
3347 struct lu_fid *pfid = NULL;
3351 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3352 /* special case when called from ll_link() */
3357 lookup = (int)(opc == LUSTRE_OPC_ANY);
3359 if (opc == LUSTRE_OPC_ANY && lookup)
3361 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3363 ll_finish_md_op_data(op_data);
3366 if (pfid && !fid_is_zero(pfid)) {
3368 op_data->op_fid2 = fid;
3369 op_data->op_bias = MDS_FID_OP;
3371 if (fname.disk_name.name &&
3372 fname.disk_name.name != (unsigned char *)name) {
3373 /* op_data->op_name must be freed after use */
3374 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3378 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN
3379 * are LUSTRE_OPC_ANY
3381 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN)
3382 op_data->op_code = LUSTRE_OPC_ANY;
3384 op_data->op_code = opc;
3385 op_data->op_name = fname.disk_name.name;
3386 op_data->op_namelen = fname.disk_name.len;
3387 op_data->op_mode = mode;
3388 op_data->op_mod_time = ktime_get_real_seconds();
3389 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3390 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3391 op_data->op_cap = current_cap();
3392 op_data->op_mds = 0;
3393 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3394 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3395 op_data->op_bias |= MDS_CREATE_VOLATILE;
3397 op_data->op_data = data;
3402 void ll_finish_md_op_data(struct md_op_data *op_data)
3404 ll_unlock_md_op_lsm(op_data);
3405 ll_security_release_secctx(op_data->op_file_secctx,
3406 op_data->op_file_secctx_size);
3407 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3408 /* allocated via ll_setup_filename called
3409 * from ll_prep_md_op_data
3411 kfree(op_data->op_name);
3412 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3413 OBD_FREE_PTR(op_data);
3416 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3418 struct ll_sb_info *sbi;
3421 LASSERT(seq && dentry);
3422 sbi = ll_s2sbi(dentry->d_sb);
3424 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3425 seq_puts(seq, "nolock");
3427 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3428 /* match_table in some cases has patterns for both enabled and
3429 * disabled cases. Ignore 'no'xxx versions if bit is set.
3431 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3432 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3433 if (ll_sbi_flags_name[i].token ==
3434 LL_SBI_FOREIGN_SYMLINK) {
3435 seq_show_option(seq, "foreign_symlink",
3436 sbi->ll_foreign_symlink_prefix);
3438 seq_printf(seq, ",%s",
3439 ll_sbi_flags_name[i].pattern);
3442 /* You can have either localflock or flock but not
3443 * both. If localflock is set don't print flock or
3446 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3448 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3449 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3450 seq_printf(seq, ",%s",
3451 ll_sbi_flags_name[i].pattern);
3455 llcrypt_show_test_dummy_encryption(seq, ',', dentry->d_sb);
3461 * Get obd name by cmd, and copy out to user space
3463 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
3465 struct ll_sb_info *sbi = ll_i2sbi(inode);
3466 struct obd_device *obd;
3469 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3470 obd = class_exp2obd(sbi->ll_dt_exp);
3471 else if (cmd == OBD_IOC_GETMDNAME)
3472 obd = class_exp2obd(sbi->ll_md_exp);
3479 if (copy_to_user((void __user *)arg, obd->obd_name,
3480 strlen(obd->obd_name) + 1))
3487 struct work_struct db_work;
3488 struct dentry *db_dentry;
3489 /* Let's hope the path is not too long, 32 bytes for the work struct
3492 char buf[PAGE_SIZE - sizeof(struct work_struct) - sizeof(void *)];
3495 static void ll_dput_later(struct work_struct *work)
3497 struct dname_buf *db = container_of(work, struct dname_buf, db_work);
3499 dput(db->db_dentry);
3500 free_page((unsigned long)db);
3503 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3510 p.mnt = current->fs->root.mnt;
3512 path = d_path(&p, buf, bufsize);
3517 void ll_dirty_page_discard_warn(struct inode *inode, int ioret)
3519 struct dname_buf *db;
3521 struct dentry *dentry = NULL;
3523 /* this can be called inside spin lock so use GFP_ATOMIC. */
3524 db = (struct dname_buf *)__get_free_page(GFP_ATOMIC);
3527 dentry = d_find_alias(inode);
3529 path = ll_d_path(dentry, db->buf, sizeof(db->buf));
3532 /* The below message is checked in recovery-small.sh test_24b */
3534 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3535 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3536 s2lsi(inode->i_sb)->lsi_lmd->lmd_dev,
3537 PFID(ll_inode2fid(inode)),
3538 (path && !IS_ERR(path)) ? path : "", ioret);
3540 if (dentry != NULL) {
3541 /* We cannot dput here since if we happen to be the last holder
3542 * then we can end up waiting for page evictions that
3543 * in turn wait for RPCs that need this instance of ptlrpcd
3544 * (callng brw_interpret->*page_completion*->vmpage_error->here)
3547 INIT_WORK(&db->db_work, ll_dput_later);
3548 db->db_dentry = dentry;
3549 schedule_work(&db->db_work);
3552 free_page((unsigned long)db);
3556 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3557 struct lov_user_md **kbuf)
3559 struct lov_user_md lum;
3563 if (copy_from_user(&lum, md, sizeof(lum)))
3566 lum_size = ll_lov_user_md_size(&lum);
3570 OBD_ALLOC_LARGE(*kbuf, lum_size);
3574 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3575 OBD_FREE_LARGE(*kbuf, lum_size);
3583 * Compute llite root squash state after a change of root squash
3584 * configuration setting or add/remove of a lnet nid
3586 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3588 struct root_squash_info *squash = &sbi->ll_squash;
3591 struct lnet_processid id;
3593 /* Update norootsquash flag */
3594 spin_lock(&squash->rsi_lock);
3595 if (list_empty(&squash->rsi_nosquash_nids))
3596 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3598 /* Do not apply root squash as soon as one of our NIDs is
3599 * in the nosquash_nids list */
3602 while (LNetGetId(i++, &id) != -ENOENT) {
3603 if (nid_is_lo0(&id.nid))
3605 if (cfs_match_nid(lnet_nid_to_nid4(&id.nid),
3606 &squash->rsi_nosquash_nids)) {
3612 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3614 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3616 spin_unlock(&squash->rsi_lock);
3620 * Parse linkea content to extract information about a given hardlink
3622 * \param[in] ldata - Initialized linkea data
3623 * \param[in] linkno - Link identifier
3624 * \param[out] parent_fid - The entry's parent FID
3625 * \param[out] ln - Entry name destination buffer
3627 * \retval 0 on success
3628 * \retval Appropriate negative error code on failure
3630 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3631 struct lu_fid *parent_fid, struct lu_name *ln)
3637 rc = linkea_init_with_rec(ldata);
3641 if (linkno >= ldata->ld_leh->leh_reccount)
3642 /* beyond last link */
3645 linkea_first_entry(ldata);
3646 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3647 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3652 linkea_next_entry(ldata);
3662 * Get parent FID and name of an identified link. Operation is performed for
3663 * a given link number, letting the caller iterate over linkno to list one or
3664 * all links of an entry.
3666 * \param[in] file - File descriptor against which to perform the operation
3667 * \param[in,out] arg - User-filled structure containing the linkno to operate
3668 * on and the available size. It is eventually filled with
3669 * the requested information or left untouched on error
3671 * \retval - 0 on success
3672 * \retval - Appropriate negative error code on failure
3674 int ll_getparent(struct file *file, struct getparent __user *arg)
3676 struct inode *inode = file_inode(file);
3677 struct linkea_data *ldata;
3678 struct lu_buf buf = LU_BUF_NULL;
3680 struct lu_fid parent_fid;
3687 if (!capable(CAP_DAC_READ_SEARCH) &&
3688 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
3691 if (get_user(name_size, &arg->gp_name_size))
3694 if (get_user(linkno, &arg->gp_linkno))
3697 if (name_size > PATH_MAX)
3700 OBD_ALLOC(ldata, sizeof(*ldata));
3704 rc = linkea_data_new(ldata, &buf);
3706 GOTO(ldata_free, rc);
3708 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3709 buf.lb_len, OBD_MD_FLXATTR);
3713 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3717 if (ln.ln_namelen >= name_size)
3718 GOTO(lb_free, rc = -EOVERFLOW);
3720 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3721 GOTO(lb_free, rc = -EFAULT);
3723 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3724 GOTO(lb_free, rc = -EFAULT);
3726 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3727 GOTO(lb_free, rc = -EFAULT);
3732 OBD_FREE(ldata, sizeof(*ldata));