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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/llite/llite_lib.c
34 * Lustre Light Super operations
37 #define DEBUG_SUBSYSTEM S_LLITE
39 #include <linux/cpu.h>
40 #include <linux/module.h>
41 #include <linux/random.h>
42 #include <linux/statfs.h>
43 #include <linux/time.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/security.h>
52 #include <linux/fs_struct.h>
54 #ifndef HAVE_CPUS_READ_LOCK
55 #include <libcfs/linux/linux-cpu.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;
102 RETURN(ERR_PTR(-ENOMEM));
104 rc = pcc_super_init(&sbi->ll_pcc_super);
108 spin_lock_init(&sbi->ll_lock);
109 mutex_init(&sbi->ll_lco.lco_lock);
110 spin_lock_init(&sbi->ll_pp_extent_lock);
111 spin_lock_init(&sbi->ll_process_lock);
112 sbi->ll_rw_stats_on = 0;
113 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
116 pages = si.totalram - si.totalhigh;
117 lru_page_max = pages / 2;
119 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
120 sbi->ll_ra_info.ll_readahead_wq =
121 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
123 sbi->ll_ra_info.ra_async_max_active);
124 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
125 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
127 /* initialize ll_cache data */
128 sbi->ll_cache = cl_cache_init(lru_page_max);
129 if (sbi->ll_cache == NULL)
130 GOTO(out_destroy_ra, rc = -ENOMEM);
132 sbi->ll_ra_info.ra_max_pages =
133 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
134 sbi->ll_ra_info.ra_max_pages_per_file =
135 min(sbi->ll_ra_info.ra_max_pages / 4,
136 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
137 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
138 sbi->ll_ra_info.ra_max_pages_per_file;
139 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
140 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
141 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
143 sbi->ll_flags |= LL_SBI_VERBOSE;
144 #ifdef ENABLE_CHECKSUM
145 sbi->ll_flags |= LL_SBI_CHECKSUM;
148 sbi->ll_flags |= LL_SBI_FLOCK;
151 #ifdef HAVE_LRU_RESIZE_SUPPORT
152 sbi->ll_flags |= LL_SBI_LRU_RESIZE;
154 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
156 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
157 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
159 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
163 /* metadata statahead is enabled by default */
164 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
165 sbi->ll_sa_max = LL_SA_RPC_DEF;
166 atomic_set(&sbi->ll_sa_total, 0);
167 atomic_set(&sbi->ll_sa_wrong, 0);
168 atomic_set(&sbi->ll_sa_running, 0);
169 atomic_set(&sbi->ll_agl_total, 0);
170 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
171 sbi->ll_flags |= LL_SBI_FAST_READ;
172 sbi->ll_flags |= LL_SBI_TINY_WRITE;
173 ll_sbi_set_encrypt(sbi, true);
176 sbi->ll_squash.rsi_uid = 0;
177 sbi->ll_squash.rsi_gid = 0;
178 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
179 spin_lock_init(&sbi->ll_squash.rsi_lock);
181 /* Per-filesystem file heat */
182 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
183 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
186 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
188 pcc_super_fini(&sbi->ll_pcc_super);
194 static void ll_free_sbi(struct super_block *sb)
196 struct ll_sb_info *sbi = ll_s2sbi(sb);
200 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
201 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
202 if (sbi->ll_ra_info.ll_readahead_wq)
203 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
204 if (sbi->ll_cache != NULL) {
205 cl_cache_decref(sbi->ll_cache);
206 sbi->ll_cache = NULL;
208 pcc_super_fini(&sbi->ll_pcc_super);
209 OBD_FREE(sbi, sizeof(*sbi));
214 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
216 struct inode *root = NULL;
217 struct ll_sb_info *sbi = ll_s2sbi(sb);
218 struct obd_statfs *osfs = NULL;
219 struct ptlrpc_request *request = NULL;
220 struct obd_connect_data *data = NULL;
221 struct obd_uuid *uuid;
222 struct md_op_data *op_data;
223 struct lustre_md lmd;
225 int size, err, checksum;
228 sbi->ll_md_obd = class_name2obd(md);
229 if (!sbi->ll_md_obd) {
230 CERROR("MD %s: not setup or attached\n", md);
244 /* pass client page size via ocd_grant_blkbits, the server should report
245 * back its backend blocksize for grant calculation purpose */
246 data->ocd_grant_blkbits = PAGE_SHIFT;
248 /* indicate MDT features supported by this client */
249 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
250 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
251 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
252 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
253 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
254 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
255 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
256 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
257 OBD_CONNECT_64BITHASH |
258 OBD_CONNECT_EINPROGRESS |
259 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
260 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
261 OBD_CONNECT_MAX_EASIZE |
262 OBD_CONNECT_FLOCK_DEAD |
263 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
264 OBD_CONNECT_OPEN_BY_FID |
265 OBD_CONNECT_DIR_STRIPE |
266 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
267 OBD_CONNECT_SUBTREE |
268 OBD_CONNECT_MULTIMODRPCS |
269 OBD_CONNECT_GRANT_PARAM |
270 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
272 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
273 OBD_CONNECT2_SUM_STATFS |
274 OBD_CONNECT2_OVERSTRIPING |
276 OBD_CONNECT2_LOCK_CONVERT |
277 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
278 OBD_CONNECT2_INC_XID |
280 OBD_CONNECT2_ASYNC_DISCARD |
282 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
283 OBD_CONNECT2_GETATTR_PFID |
284 OBD_CONNECT2_DOM_LVB;
286 #ifdef HAVE_LRU_RESIZE_SUPPORT
287 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
288 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
290 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
292 data->ocd_cksum_types = obd_cksum_types_supported_client();
294 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
295 /* flag mdc connection as lightweight, only used for test
296 * purpose, use with care */
297 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
299 data->ocd_ibits_known = MDS_INODELOCK_FULL;
300 data->ocd_version = LUSTRE_VERSION_CODE;
302 if (sb->s_flags & SB_RDONLY)
303 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
304 if (sbi->ll_flags & LL_SBI_USER_XATTR)
305 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
308 /* Setting this indicates we correctly support S_NOSEC (See kernel
309 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
311 sb->s_flags |= SB_NOSEC;
314 if (sbi->ll_flags & LL_SBI_FLOCK)
315 sbi->ll_fop = &ll_file_operations_flock;
316 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
317 sbi->ll_fop = &ll_file_operations;
319 sbi->ll_fop = &ll_file_operations_noflock;
321 /* always ping even if server suppress_pings */
322 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
323 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
325 obd_connect_set_secctx(data);
326 if (ll_sbi_has_encrypt(sbi))
327 obd_connect_set_enc(data);
329 #if defined(CONFIG_SECURITY)
330 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
333 data->ocd_brw_size = MD_MAX_BRW_SIZE;
335 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
336 &sbi->ll_sb_uuid, data, sbi->ll_cache);
338 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
339 "recovery, of which this client is not a "
340 "part. Please wait for recovery to complete,"
341 " abort, or time out.\n", md);
344 CERROR("cannot connect to %s: rc = %d\n", md, err);
348 sbi->ll_md_exp->exp_connect_data = *data;
350 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
351 LUSTRE_SEQ_METADATA);
353 CERROR("%s: Can't init metadata layer FID infrastructure, "
354 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
358 /* For mount, we only need fs info from MDT0, and also in DNE, it
359 * can make sure the client can be mounted as long as MDT0 is
361 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
362 ktime_get_seconds() - sbi->ll_statfs_max_age,
363 OBD_STATFS_FOR_MDT0);
365 GOTO(out_md_fid, err);
367 /* This needs to be after statfs to ensure connect has finished.
368 * Note that "data" does NOT contain the valid connect reply.
369 * If connecting to a 1.8 server there will be no LMV device, so
370 * we can access the MDC export directly and exp_connect_flags will
371 * be non-zero, but if accessing an upgraded 2.1 server it will
372 * have the correct flags filled in.
373 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
374 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
375 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
376 valid != CLIENT_CONNECT_MDT_REQD) {
379 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
380 obd_connect_flags2str(buf, PAGE_SIZE,
381 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
382 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
383 "feature(s) needed for correct operation "
384 "of this client (%s). Please upgrade "
385 "server or downgrade client.\n",
386 sbi->ll_md_exp->exp_obd->obd_name, buf);
387 OBD_FREE(buf, PAGE_SIZE);
388 GOTO(out_md_fid, err = -EPROTO);
391 size = sizeof(*data);
392 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
393 KEY_CONN_DATA, &size, data);
395 CERROR("%s: Get connect data failed: rc = %d\n",
396 sbi->ll_md_exp->exp_obd->obd_name, err);
397 GOTO(out_md_fid, err);
400 LASSERT(osfs->os_bsize);
401 sb->s_blocksize = osfs->os_bsize;
402 sb->s_blocksize_bits = log2(osfs->os_bsize);
403 sb->s_magic = LL_SUPER_MAGIC;
404 sb->s_maxbytes = MAX_LFS_FILESIZE;
405 sbi->ll_namelen = osfs->os_namelen;
406 sbi->ll_mnt.mnt = current->fs->root.mnt;
408 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
409 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
410 LCONSOLE_INFO("Disabling user_xattr feature because "
411 "it is not supported on the server\n");
412 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
415 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
417 sb->s_flags |= SB_POSIXACL;
419 sbi->ll_flags |= LL_SBI_ACL;
421 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
423 sb->s_flags &= ~SB_POSIXACL;
425 sbi->ll_flags &= ~LL_SBI_ACL;
428 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
429 sbi->ll_flags |= LL_SBI_64BIT_HASH;
431 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
432 sbi->ll_flags |= LL_SBI_LAYOUT_LOCK;
434 if (obd_connect_has_secctx(data))
435 sbi->ll_flags |= LL_SBI_FILE_SECCTX;
437 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
438 if (ll_sbi_has_test_dummy_encryption(sbi))
439 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
441 sbi->ll_md_exp->exp_obd->obd_name);
442 ll_sbi_set_encrypt(sbi, false);
445 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
446 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
447 LCONSOLE_INFO("%s: disabling xattr cache due to "
448 "unknown maximum xattr size.\n", dt);
449 } else if (!sbi->ll_xattr_cache_set) {
450 /* If xattr_cache is already set (no matter 0 or 1)
451 * during processing llog, it won't be enabled here. */
452 sbi->ll_flags |= LL_SBI_XATTR_CACHE;
453 sbi->ll_xattr_cache_enabled = 1;
457 sbi->ll_dt_obd = class_name2obd(dt);
458 if (!sbi->ll_dt_obd) {
459 CERROR("DT %s: not setup or attached\n", dt);
460 GOTO(out_md_fid, err = -ENODEV);
463 /* pass client page size via ocd_grant_blkbits, the server should report
464 * back its backend blocksize for grant calculation purpose */
465 data->ocd_grant_blkbits = PAGE_SHIFT;
467 /* indicate OST features supported by this client */
468 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
469 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
470 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
471 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
472 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
473 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
474 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
475 OBD_CONNECT_EINPROGRESS |
476 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
477 OBD_CONNECT_LAYOUTLOCK |
478 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
479 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
480 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
481 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
482 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK;
484 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
485 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
487 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
488 * disabled by default, because it can still be enabled on the
489 * fly via /sys. As a consequence, we still need to come to an
490 * agreement on the supported algorithms at connect time
492 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
494 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
495 data->ocd_cksum_types = OBD_CKSUM_ADLER;
497 data->ocd_cksum_types = obd_cksum_types_supported_client();
499 #ifdef HAVE_LRU_RESIZE_SUPPORT
500 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
502 /* always ping even if server suppress_pings */
503 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
504 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
506 if (ll_sbi_has_encrypt(sbi))
507 obd_connect_set_enc(data);
509 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
510 "ocd_grant: %d\n", data->ocd_connect_flags,
511 data->ocd_version, data->ocd_grant);
513 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
514 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
516 data->ocd_brw_size = DT_MAX_BRW_SIZE;
518 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
519 &sbi->ll_sb_uuid, data, sbi->ll_cache);
521 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
522 "recovery, of which this client is not a "
523 "part. Please wait for recovery to "
524 "complete, abort, or time out.\n", dt);
527 CERROR("%s: Cannot connect to %s: rc = %d\n",
528 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
532 if (ll_sbi_has_encrypt(sbi) &&
533 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
534 if (ll_sbi_has_test_dummy_encryption(sbi))
535 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
537 ll_sbi_set_encrypt(sbi, false);
538 } else if (ll_sbi_has_test_dummy_encryption(sbi)) {
539 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
542 sbi->ll_dt_exp->exp_connect_data = *data;
544 /* Don't change value if it was specified in the config log */
545 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
546 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
547 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
548 (data->ocd_brw_size >> PAGE_SHIFT));
549 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
550 sbi->ll_ra_info.ra_max_pages_per_file)
551 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
552 sbi->ll_ra_info.ra_max_pages_per_file;
555 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
556 LUSTRE_SEQ_METADATA);
558 CERROR("%s: Can't init data layer FID infrastructure, "
559 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
563 mutex_lock(&sbi->ll_lco.lco_lock);
564 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
565 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
566 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
567 mutex_unlock(&sbi->ll_lco.lco_lock);
569 fid_zero(&sbi->ll_root_fid);
570 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
573 CERROR("cannot mds_connect: rc = %d\n", err);
574 GOTO(out_lock_cn_cb, err);
576 if (!fid_is_sane(&sbi->ll_root_fid)) {
577 CERROR("%s: Invalid root fid "DFID" during mount\n",
578 sbi->ll_md_exp->exp_obd->obd_name,
579 PFID(&sbi->ll_root_fid));
580 GOTO(out_lock_cn_cb, err = -EINVAL);
582 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
584 sb->s_op = &lustre_super_operations;
585 sb->s_xattr = ll_xattr_handlers;
586 #if THREAD_SIZE >= 8192 /*b=17630*/
587 sb->s_export_op = &lustre_export_operations;
589 #ifdef HAVE_LUSTRE_CRYPTO
590 llcrypt_set_ops(sb, &lustre_cryptops);
594 * XXX: move this to after cbd setup? */
595 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
596 if (sbi->ll_flags & LL_SBI_ACL)
597 valid |= OBD_MD_FLACL;
599 OBD_ALLOC_PTR(op_data);
601 GOTO(out_lock_cn_cb, err = -ENOMEM);
603 op_data->op_fid1 = sbi->ll_root_fid;
604 op_data->op_mode = 0;
605 op_data->op_valid = valid;
607 err = md_getattr(sbi->ll_md_exp, op_data, &request);
609 OBD_FREE_PTR(op_data);
611 CERROR("%s: md_getattr failed for root: rc = %d\n",
612 sbi->ll_md_exp->exp_obd->obd_name, err);
613 GOTO(out_lock_cn_cb, err);
616 err = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
617 sbi->ll_md_exp, &lmd);
619 CERROR("failed to understand root inode md: rc = %d\n", err);
620 ptlrpc_req_finished(request);
621 GOTO(out_lock_cn_cb, err);
624 LASSERT(fid_is_sane(&sbi->ll_root_fid));
625 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid,
626 sbi->ll_flags & LL_SBI_32BIT_API),
628 md_free_lustre_md(sbi->ll_md_exp, &lmd);
629 ptlrpc_req_finished(request);
633 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
635 CERROR("%s: bad ll_iget() for root: rc = %d\n",
636 sbi->ll_fsname, err);
640 checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
641 if (sbi->ll_checksum_set) {
642 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
643 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
644 sizeof(checksum), &checksum, NULL);
646 CERROR("%s: Set checksum failed: rc = %d\n",
647 sbi->ll_dt_exp->exp_obd->obd_name, err);
653 sb->s_root = d_make_root(root);
654 if (sb->s_root == NULL) {
656 CERROR("%s: can't make root dentry: rc = %d\n",
657 sbi->ll_fsname, err);
661 sbi->ll_sdev_orig = sb->s_dev;
663 /* We set sb->s_dev equal on all lustre clients in order to support
664 * NFS export clustering. NFSD requires that the FSID be the same
666 /* s_dev is also used in lt_compare() to compare two fs, but that is
667 * only a node-local comparison. */
668 uuid = obd_get_uuid(sbi->ll_md_exp);
670 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
677 if (sbi->ll_dt_obd) {
678 err = sysfs_create_link(&sbi->ll_kset.kobj,
679 &sbi->ll_dt_obd->obd_kset.kobj,
680 sbi->ll_dt_obd->obd_type->typ_name);
682 CERROR("%s: could not register %s in llite: rc = %d\n",
683 dt, sbi->ll_fsname, err);
688 if (sbi->ll_md_obd) {
689 err = sysfs_create_link(&sbi->ll_kset.kobj,
690 &sbi->ll_md_obd->obd_kset.kobj,
691 sbi->ll_md_obd->obd_type->typ_name);
693 CERROR("%s: could not register %s in llite: rc = %d\n",
694 md, sbi->ll_fsname, err);
704 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
706 obd_disconnect(sbi->ll_dt_exp);
707 sbi->ll_dt_exp = NULL;
708 sbi->ll_dt_obd = NULL;
710 obd_fid_fini(sbi->ll_md_exp->exp_obd);
712 obd_disconnect(sbi->ll_md_exp);
713 sbi->ll_md_exp = NULL;
714 sbi->ll_md_obd = NULL;
723 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
727 size = sizeof(*lmmsize);
728 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
729 KEY_MAX_EASIZE, &size, lmmsize);
731 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
732 sbi->ll_dt_exp->exp_obd->obd_name, rc);
736 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
739 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
740 KEY_MAX_EASIZE, &size, lmmsize);
742 CERROR("Get max mdsize error rc %d\n", rc);
744 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
750 * Get the value of the default_easize parameter.
752 * \see client_obd::cl_default_mds_easize
754 * \param[in] sbi superblock info for this filesystem
755 * \param[out] lmmsize pointer to storage location for value
757 * \retval 0 on success
758 * \retval negative negated errno on failure
760 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
765 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
766 KEY_DEFAULT_EASIZE, &size, lmmsize);
768 CERROR("Get default mdsize error rc %d\n", rc);
774 * Set the default_easize parameter to the given value.
776 * \see client_obd::cl_default_mds_easize
778 * \param[in] sbi superblock info for this filesystem
779 * \param[in] lmmsize the size to set
781 * \retval 0 on success
782 * \retval negative negated errno on failure
784 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
788 if (lmmsize < sizeof(struct lov_mds_md) ||
789 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
792 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
793 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
794 sizeof(int), &lmmsize, NULL);
799 static void client_common_put_super(struct super_block *sb)
801 struct ll_sb_info *sbi = ll_s2sbi(sb);
806 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
807 obd_disconnect(sbi->ll_dt_exp);
808 sbi->ll_dt_exp = NULL;
810 ll_debugfs_unregister_super(sb);
812 obd_fid_fini(sbi->ll_md_exp->exp_obd);
813 obd_disconnect(sbi->ll_md_exp);
814 sbi->ll_md_exp = NULL;
819 void ll_kill_super(struct super_block *sb)
821 struct ll_sb_info *sbi;
825 if (!(sb->s_flags & SB_ACTIVE))
829 /* we need restore s_dev from changed for clustred NFS before put_super
830 * because new kernels have cached s_dev and change sb->s_dev in
831 * put_super not affected real removing devices */
833 sb->s_dev = sbi->ll_sdev_orig;
835 /* wait running statahead threads to quit */
836 while (atomic_read(&sbi->ll_sa_running) > 0)
837 schedule_timeout_uninterruptible(
838 cfs_time_seconds(1) >> 3);
844 static inline int ll_set_opt(const char *opt, char *data, int fl)
846 if (strncmp(opt, data, strlen(opt)) != 0)
852 /* non-client-specific mount options are parsed in lmd_parse */
853 static int ll_options(char *options, struct ll_sb_info *sbi)
856 char *s1 = options, *s2;
857 int *flags = &sbi->ll_flags;
863 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
866 CDEBUG(D_SUPER, "next opt=%s\n", s1);
867 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
872 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
874 *flags = (*flags & ~LL_SBI_LOCALFLOCK) | tmp;
877 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
879 *flags = (*flags & ~LL_SBI_FLOCK) | tmp;
882 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
887 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
892 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
897 tmp = ll_set_opt("context", s1, 1);
900 tmp = ll_set_opt("fscontext", s1, 1);
903 tmp = ll_set_opt("defcontext", s1, 1);
906 tmp = ll_set_opt("rootcontext", s1, 1);
909 tmp = ll_set_opt("user_fid2path", s1, LL_SBI_USER_FID2PATH);
914 tmp = ll_set_opt("nouser_fid2path", s1, LL_SBI_USER_FID2PATH);
920 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
923 sbi->ll_checksum_set = 1;
926 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
929 sbi->ll_checksum_set = 1;
932 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
937 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
942 tmp = ll_set_opt("lazystatfs", s1, LL_SBI_LAZYSTATFS);
947 tmp = ll_set_opt("nolazystatfs", s1, LL_SBI_LAZYSTATFS);
952 tmp = ll_set_opt("32bitapi", s1, LL_SBI_32BIT_API);
957 tmp = ll_set_opt("verbose", s1, LL_SBI_VERBOSE);
962 tmp = ll_set_opt("noverbose", s1, LL_SBI_VERBOSE);
967 tmp = ll_set_opt("always_ping", s1, LL_SBI_ALWAYS_PING);
972 tmp = ll_set_opt("test_dummy_encryption", s1,
973 LL_SBI_TEST_DUMMY_ENCRYPTION);
975 #ifdef HAVE_LUSTRE_CRYPTO
978 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
982 tmp = ll_set_opt("noencrypt", s1, LL_SBI_ENCRYPT);
984 #ifdef HAVE_LUSTRE_CRYPTO
987 LCONSOLE_WARN("noencrypt mount option ignored: encryption not supported\n");
991 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
997 s2 = strchr(s1, ',');
1005 void ll_lli_init(struct ll_inode_info *lli)
1007 lli->lli_inode_magic = LLI_INODE_MAGIC;
1009 spin_lock_init(&lli->lli_lock);
1010 lli->lli_posix_acl = NULL;
1011 /* Do not set lli_fid, it has been initialized already. */
1012 fid_zero(&lli->lli_pfid);
1013 lli->lli_mds_read_och = NULL;
1014 lli->lli_mds_write_och = NULL;
1015 lli->lli_mds_exec_och = NULL;
1016 lli->lli_open_fd_read_count = 0;
1017 lli->lli_open_fd_write_count = 0;
1018 lli->lli_open_fd_exec_count = 0;
1019 mutex_init(&lli->lli_och_mutex);
1020 spin_lock_init(&lli->lli_agl_lock);
1021 spin_lock_init(&lli->lli_layout_lock);
1022 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1023 lli->lli_clob = NULL;
1025 init_rwsem(&lli->lli_xattrs_list_rwsem);
1026 mutex_init(&lli->lli_xattrs_enq_lock);
1028 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1029 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1030 lli->lli_opendir_key = NULL;
1031 lli->lli_sai = NULL;
1032 spin_lock_init(&lli->lli_sa_lock);
1033 lli->lli_opendir_pid = 0;
1034 lli->lli_sa_enabled = 0;
1035 init_rwsem(&lli->lli_lsm_sem);
1037 mutex_init(&lli->lli_size_mutex);
1038 mutex_init(&lli->lli_setattr_mutex);
1039 lli->lli_symlink_name = NULL;
1040 ll_trunc_sem_init(&lli->lli_trunc_sem);
1041 range_lock_tree_init(&lli->lli_write_tree);
1042 init_rwsem(&lli->lli_glimpse_sem);
1043 lli->lli_glimpse_time = ktime_set(0, 0);
1044 INIT_LIST_HEAD(&lli->lli_agl_list);
1045 lli->lli_agl_index = 0;
1046 lli->lli_async_rc = 0;
1047 spin_lock_init(&lli->lli_heat_lock);
1048 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1049 lli->lli_heat_flags = 0;
1050 mutex_init(&lli->lli_pcc_lock);
1051 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1052 lli->lli_pcc_inode = NULL;
1053 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1054 lli->lli_pcc_generation = 0;
1055 mutex_init(&lli->lli_group_mutex);
1056 lli->lli_group_users = 0;
1057 lli->lli_group_gid = 0;
1059 mutex_init(&lli->lli_layout_mutex);
1060 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1063 #define MAX_STRING_SIZE 128
1065 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1067 #define LSI_BDI_INITIALIZED 0x00400000
1069 #ifndef HAVE_BDI_CAP_MAP_COPY
1070 # define BDI_CAP_MAP_COPY 0
1073 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1075 struct lustre_sb_info *lsi = s2lsi(sb);
1076 char buf[MAX_STRING_SIZE];
1080 err = bdi_init(&lsi->lsi_bdi);
1084 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1085 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1086 lsi->lsi_bdi.name = "lustre";
1087 va_start(args, fmt);
1088 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1090 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1093 sb->s_bdi = &lsi->lsi_bdi;
1097 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1099 int ll_fill_super(struct super_block *sb)
1101 struct lustre_profile *lprof = NULL;
1102 struct lustre_sb_info *lsi = s2lsi(sb);
1103 struct ll_sb_info *sbi = NULL;
1104 char *dt = NULL, *md = NULL;
1105 char *profilenm = get_profile_name(sb);
1106 struct config_llog_instance *cfg;
1107 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1108 const int instlen = LUSTRE_MAXINSTANCE + 2;
1109 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1110 char name[MAX_STRING_SIZE];
1119 /* for ASLR, to map between cfg_instance and hashed ptr */
1120 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1121 profilenm, cfg_instance, sb);
1125 GOTO(out_free_cfg, err = -ENOMEM);
1127 /* client additional sb info */
1128 lsi->lsi_llsbi = sbi = ll_init_sbi();
1130 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1132 err = ll_options(lsi->lsi_lmd->lmd_opts, sbi);
1134 GOTO(out_free_cfg, err);
1136 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1137 sb->s_d_op = &ll_d_ops;
1140 generate_random_uuid(uuid.b);
1141 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1143 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1146 len = strlen(profilenm);
1147 ptr = strrchr(profilenm, '-');
1148 if (ptr && (strcmp(ptr, "-client") == 0))
1151 if (len > LUSTRE_MAXFSNAME) {
1152 if (unlikely(len >= MAX_STRING_SIZE))
1153 len = MAX_STRING_SIZE - 1;
1154 strncpy(name, profilenm, len);
1156 err = -ENAMETOOLONG;
1157 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1158 name, LUSTRE_MAXFSNAME, err);
1159 GOTO(out_free_cfg, err);
1161 strncpy(sbi->ll_fsname, profilenm, len);
1162 sbi->ll_fsname[len] = '\0';
1165 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1166 profilenm, cfg_instance);
1168 err = super_setup_bdi_name(sb, "%s", name);
1170 GOTO(out_free_cfg, err);
1172 /* Call ll_debugfs_register_super() before lustre_process_log()
1173 * so that "llite.*.*" params can be processed correctly.
1175 err = ll_debugfs_register_super(sb, name);
1177 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1178 sbi->ll_fsname, err);
1182 /* The cfg_instance is a value unique to this super, in case some
1183 * joker tries to mount the same fs at two mount points.
1185 cfg->cfg_instance = cfg_instance;
1186 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1187 cfg->cfg_callback = class_config_llog_handler;
1188 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1189 /* set up client obds */
1190 err = lustre_process_log(sb, profilenm, cfg);
1192 GOTO(out_debugfs, err);
1194 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1195 lprof = class_get_profile(profilenm);
1196 if (lprof == NULL) {
1197 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1198 " read from the MGS. Does that filesystem "
1199 "exist?\n", profilenm);
1200 GOTO(out_debugfs, err = -EINVAL);
1202 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1203 lprof->lp_md, lprof->lp_dt);
1205 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1206 OBD_ALLOC(dt, dt_len);
1208 GOTO(out_profile, err = -ENOMEM);
1209 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1211 md_len = strlen(lprof->lp_md) + instlen + 2;
1212 OBD_ALLOC(md, md_len);
1214 GOTO(out_free_dt, err = -ENOMEM);
1215 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1217 /* connections, registrations, sb setup */
1218 err = client_common_fill_super(sb, md, dt);
1220 GOTO(out_free_md, err);
1222 sbi->ll_client_common_fill_super_succeeded = 1;
1226 OBD_FREE(md, md_len);
1229 OBD_FREE(dt, dt_len);
1232 class_put_profile(lprof);
1235 ll_debugfs_unregister_super(sb);
1242 else if (sbi->ll_flags & LL_SBI_VERBOSE)
1243 LCONSOLE_WARN("Mounted %s\n", profilenm);
1245 } /* ll_fill_super */
1247 void ll_put_super(struct super_block *sb)
1249 struct config_llog_instance cfg, params_cfg;
1250 struct obd_device *obd;
1251 struct lustre_sb_info *lsi = s2lsi(sb);
1252 struct ll_sb_info *sbi = ll_s2sbi(sb);
1253 char *profilenm = get_profile_name(sb);
1254 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1256 int next, force = 1, rc = 0;
1260 GOTO(out_no_sbi, 0);
1262 /* Should replace instance_id with something better for ASLR */
1263 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1264 profilenm, cfg_instance, sb);
1266 cfg.cfg_instance = cfg_instance;
1267 lustre_end_log(sb, profilenm, &cfg);
1269 params_cfg.cfg_instance = cfg_instance;
1270 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1272 if (sbi->ll_md_exp) {
1273 obd = class_exp2obd(sbi->ll_md_exp);
1275 force = obd->obd_force;
1278 /* Wait for unstable pages to be committed to stable storage */
1280 rc = l_wait_event_abortable(
1281 sbi->ll_cache->ccc_unstable_waitq,
1282 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1285 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1286 if (force == 0 && rc != -ERESTARTSYS)
1287 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1289 /* We need to set force before the lov_disconnect in
1290 * lustre_common_put_super, since l_d cleans up osc's as well.
1294 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1296 obd->obd_force = force;
1300 if (sbi->ll_client_common_fill_super_succeeded) {
1301 /* Only if client_common_fill_super succeeded */
1302 client_common_put_super(sb);
1306 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1307 class_manual_cleanup(obd);
1309 if (sbi->ll_flags & LL_SBI_VERBOSE)
1310 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1313 class_del_profile(profilenm);
1315 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1316 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1317 bdi_destroy(&lsi->lsi_bdi);
1318 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1323 lsi->lsi_llsbi = NULL;
1325 lustre_common_put_super(sb);
1327 cl_env_cache_purge(~0);
1329 module_put(THIS_MODULE);
1332 } /* client_put_super */
1334 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1336 struct inode *inode = NULL;
1338 /* NOTE: we depend on atomic igrab() -bzzz */
1339 lock_res_and_lock(lock);
1340 if (lock->l_resource->lr_lvb_inode) {
1341 struct ll_inode_info * lli;
1342 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1343 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1344 inode = igrab(lock->l_resource->lr_lvb_inode);
1346 inode = lock->l_resource->lr_lvb_inode;
1347 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1348 D_WARNING, lock, "lr_lvb_inode %p is "
1349 "bogus: magic %08x",
1350 lock->l_resource->lr_lvb_inode,
1351 lli->lli_inode_magic);
1355 unlock_res_and_lock(lock);
1359 void ll_dir_clear_lsm_md(struct inode *inode)
1361 struct ll_inode_info *lli = ll_i2info(inode);
1363 LASSERT(S_ISDIR(inode->i_mode));
1365 if (lli->lli_lsm_md) {
1366 lmv_free_memmd(lli->lli_lsm_md);
1367 lli->lli_lsm_md = NULL;
1370 if (lli->lli_default_lsm_md) {
1371 lmv_free_memmd(lli->lli_default_lsm_md);
1372 lli->lli_default_lsm_md = NULL;
1376 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1377 const struct lu_fid *fid,
1378 struct lustre_md *md)
1380 struct ll_sb_info *sbi = ll_s2sbi(sb);
1381 struct mdt_body *body = md->body;
1382 struct inode *inode;
1386 ino = cl_fid_build_ino(fid, sbi->ll_flags & LL_SBI_32BIT_API);
1387 inode = iget_locked(sb, ino);
1388 if (inode == NULL) {
1389 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1390 sbi->ll_fsname, PFID(fid));
1391 RETURN(ERR_PTR(-ENOENT));
1394 if (inode->i_state & I_NEW) {
1395 struct ll_inode_info *lli = ll_i2info(inode);
1396 struct lmv_stripe_md *lsm = md->lmv;
1398 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1399 (body->mbo_mode & S_IFMT);
1400 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1403 inode->i_mtime.tv_sec = 0;
1404 inode->i_atime.tv_sec = 0;
1405 inode->i_ctime.tv_sec = 0;
1408 #ifdef HAVE_BACKING_DEV_INFO
1409 /* initializing backing dev info. */
1410 inode->i_mapping->backing_dev_info =
1411 &s2lsi(inode->i_sb)->lsi_bdi;
1413 inode->i_op = &ll_dir_inode_operations;
1414 inode->i_fop = &ll_dir_operations;
1415 lli->lli_fid = *fid;
1418 LASSERT(lsm != NULL);
1419 /* master object FID */
1420 lli->lli_pfid = body->mbo_fid1;
1421 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1422 lli, PFID(fid), PFID(&lli->lli_pfid));
1423 unlock_new_inode(inode);
1429 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1432 struct lmv_stripe_md *lsm = md->lmv;
1433 struct ll_inode_info *lli = ll_i2info(inode);
1436 LASSERT(lsm != NULL);
1438 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1439 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1440 lsm_md_dump(D_INODE, lsm);
1442 if (!lmv_dir_striped(lsm))
1445 /* XXX sigh, this lsm_root initialization should be in
1446 * LMV layer, but it needs ll_iget right now, so we
1447 * put this here right now. */
1448 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1449 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1450 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1452 if (!fid_is_sane(fid))
1455 /* Unfortunately ll_iget will call ll_update_inode,
1456 * where the initialization of slave inode is slightly
1457 * different, so it reset lsm_md to NULL to avoid
1458 * initializing lsm for slave inode. */
1459 lsm->lsm_md_oinfo[i].lmo_root =
1460 ll_iget_anon_dir(inode->i_sb, fid, md);
1461 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1462 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1464 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1466 iput(lsm->lsm_md_oinfo[i].lmo_root);
1467 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1473 lli->lli_lsm_md = lsm;
1478 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1480 struct ll_inode_info *lli = ll_i2info(inode);
1482 if (!md->default_lmv) {
1483 /* clear default lsm */
1484 if (lli->lli_default_lsm_md) {
1485 down_write(&lli->lli_lsm_sem);
1486 if (lli->lli_default_lsm_md) {
1487 lmv_free_memmd(lli->lli_default_lsm_md);
1488 lli->lli_default_lsm_md = NULL;
1490 up_write(&lli->lli_lsm_sem);
1492 } else if (lli->lli_default_lsm_md) {
1493 /* update default lsm if it changes */
1494 down_read(&lli->lli_lsm_sem);
1495 if (lli->lli_default_lsm_md &&
1496 !lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1497 up_read(&lli->lli_lsm_sem);
1498 down_write(&lli->lli_lsm_sem);
1499 if (lli->lli_default_lsm_md)
1500 lmv_free_memmd(lli->lli_default_lsm_md);
1501 lli->lli_default_lsm_md = md->default_lmv;
1502 lsm_md_dump(D_INODE, md->default_lmv);
1503 md->default_lmv = NULL;
1504 up_write(&lli->lli_lsm_sem);
1506 up_read(&lli->lli_lsm_sem);
1509 /* init default lsm */
1510 down_write(&lli->lli_lsm_sem);
1511 lli->lli_default_lsm_md = md->default_lmv;
1512 lsm_md_dump(D_INODE, md->default_lmv);
1513 md->default_lmv = NULL;
1514 up_write(&lli->lli_lsm_sem);
1518 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1520 struct ll_inode_info *lli = ll_i2info(inode);
1521 struct lmv_stripe_md *lsm = md->lmv;
1522 struct cl_attr *attr;
1527 LASSERT(S_ISDIR(inode->i_mode));
1528 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1529 PFID(ll_inode2fid(inode)));
1531 /* update default LMV */
1532 if (md->default_lmv)
1533 ll_update_default_lsm_md(inode, md);
1536 * no striped information from request, lustre_md from req does not
1537 * include stripeEA, see ll_md_setattr()
1543 * normally dir layout doesn't change, only take read lock to check
1544 * that to avoid blocking other MD operations.
1546 down_read(&lli->lli_lsm_sem);
1548 /* some current lookup initialized lsm, and unchanged */
1549 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1550 GOTO(unlock, rc = 0);
1552 /* if dir layout doesn't match, check whether version is increased,
1553 * which means layout is changed, this happens in dir split/merge and
1556 * foreign LMV should not change.
1558 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1559 lsm->lsm_md_layout_version <=
1560 lli->lli_lsm_md->lsm_md_layout_version) {
1561 CERROR("%s: "DFID" dir layout mismatch:\n",
1562 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1563 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1564 lsm_md_dump(D_ERROR, lsm);
1565 GOTO(unlock, rc = -EINVAL);
1568 up_read(&lli->lli_lsm_sem);
1569 down_write(&lli->lli_lsm_sem);
1570 /* clear existing lsm */
1571 if (lli->lli_lsm_md) {
1572 lmv_free_memmd(lli->lli_lsm_md);
1573 lli->lli_lsm_md = NULL;
1576 rc = ll_init_lsm_md(inode, md);
1577 up_write(&lli->lli_lsm_sem);
1582 /* set md->lmv to NULL, so the following free lustre_md will not free
1587 /* md_merge_attr() may take long, since lsm is already set, switch to
1590 down_read(&lli->lli_lsm_sem);
1592 if (!lmv_dir_striped(lli->lli_lsm_md))
1593 GOTO(unlock, rc = 0);
1595 OBD_ALLOC_PTR(attr);
1597 GOTO(unlock, rc = -ENOMEM);
1599 /* validate the lsm */
1600 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1601 ll_md_blocking_ast);
1603 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1604 md->body->mbo_nlink = attr->cat_nlink;
1605 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1606 md->body->mbo_size = attr->cat_size;
1607 if (md->body->mbo_valid & OBD_MD_FLATIME)
1608 md->body->mbo_atime = attr->cat_atime;
1609 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1610 md->body->mbo_ctime = attr->cat_ctime;
1611 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1612 md->body->mbo_mtime = attr->cat_mtime;
1618 up_read(&lli->lli_lsm_sem);
1623 void ll_clear_inode(struct inode *inode)
1625 struct ll_inode_info *lli = ll_i2info(inode);
1626 struct ll_sb_info *sbi = ll_i2sbi(inode);
1630 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1631 PFID(ll_inode2fid(inode)), inode);
1633 if (S_ISDIR(inode->i_mode)) {
1634 /* these should have been cleared in ll_file_release */
1635 LASSERT(lli->lli_opendir_key == NULL);
1636 LASSERT(lli->lli_sai == NULL);
1637 LASSERT(lli->lli_opendir_pid == 0);
1639 pcc_inode_free(inode);
1642 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1644 LASSERT(!lli->lli_open_fd_write_count);
1645 LASSERT(!lli->lli_open_fd_read_count);
1646 LASSERT(!lli->lli_open_fd_exec_count);
1648 if (lli->lli_mds_write_och)
1649 ll_md_real_close(inode, FMODE_WRITE);
1650 if (lli->lli_mds_exec_och)
1651 ll_md_real_close(inode, FMODE_EXEC);
1652 if (lli->lli_mds_read_och)
1653 ll_md_real_close(inode, FMODE_READ);
1655 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1656 OBD_FREE(lli->lli_symlink_name,
1657 strlen(lli->lli_symlink_name) + 1);
1658 lli->lli_symlink_name = NULL;
1661 ll_xattr_cache_destroy(inode);
1663 forget_all_cached_acls(inode);
1665 lli->lli_inode_magic = LLI_INODE_DEAD;
1667 if (S_ISDIR(inode->i_mode))
1668 ll_dir_clear_lsm_md(inode);
1669 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1670 LASSERT(list_empty(&lli->lli_agl_list));
1673 * XXX This has to be done before lsm is freed below, because
1674 * cl_object still uses inode lsm.
1676 cl_inode_fini(inode);
1678 llcrypt_put_encryption_info(inode);
1683 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1685 struct lustre_md md;
1686 struct inode *inode = dentry->d_inode;
1687 struct ll_sb_info *sbi = ll_i2sbi(inode);
1688 struct ptlrpc_request *request = NULL;
1692 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1693 LUSTRE_OPC_ANY, NULL);
1694 if (IS_ERR(op_data))
1695 RETURN(PTR_ERR(op_data));
1697 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1699 ptlrpc_req_finished(request);
1700 if (rc == -ENOENT) {
1702 /* Unlinked special device node? Or just a race?
1703 * Pretend we done everything. */
1704 if (!S_ISREG(inode->i_mode) &&
1705 !S_ISDIR(inode->i_mode)) {
1706 ia_valid = op_data->op_attr.ia_valid;
1707 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1708 rc = simple_setattr(dentry, &op_data->op_attr);
1709 op_data->op_attr.ia_valid = ia_valid;
1711 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1712 CERROR("md_setattr fails: rc = %d\n", rc);
1717 rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
1718 sbi->ll_md_exp, &md);
1720 ptlrpc_req_finished(request);
1724 ia_valid = op_data->op_attr.ia_valid;
1725 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1726 * cache is not cleared yet. */
1727 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1728 if (S_ISREG(inode->i_mode))
1730 rc = simple_setattr(dentry, &op_data->op_attr);
1731 if (S_ISREG(inode->i_mode))
1732 inode_unlock(inode);
1733 op_data->op_attr.ia_valid = ia_valid;
1735 rc = ll_update_inode(inode, &md);
1736 ptlrpc_req_finished(request);
1742 * Zero portion of page that is part of @inode.
1743 * This implies, if necessary:
1744 * - taking cl_lock on range corresponding to concerned page
1745 * - grabbing vm page
1746 * - associating cl_page
1747 * - proceeding to clio read
1748 * - zeroing range in page
1749 * - proceeding to cl_page flush
1750 * - releasing cl_lock
1752 * \param[in] inode inode
1753 * \param[in] index page index
1754 * \param[in] offset offset in page to start zero from
1755 * \param[in] len len to zero
1757 * \retval 0 on success
1758 * \retval negative errno on failure
1760 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
1763 struct ll_inode_info *lli = ll_i2info(inode);
1764 struct cl_object *clob = lli->lli_clob;
1766 struct lu_env *env = NULL;
1767 struct cl_io *io = NULL;
1768 struct cl_page *clpage = NULL;
1769 struct page *vmpage = NULL;
1770 unsigned from = index << PAGE_SHIFT;
1771 struct cl_lock *lock = NULL;
1772 struct cl_lock_descr *descr = NULL;
1773 struct cl_2queue *queue = NULL;
1774 struct cl_sync_io *anchor = NULL;
1775 bool holdinglock = false;
1776 bool lockedbymyself = true;
1781 env = cl_env_get(&refcheck);
1783 RETURN(PTR_ERR(env));
1785 io = vvp_env_thread_io(env);
1787 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
1791 lock = vvp_env_lock(env);
1792 descr = &lock->cll_descr;
1793 descr->cld_obj = io->ci_obj;
1794 descr->cld_start = cl_index(io->ci_obj, from);
1795 descr->cld_end = cl_index(io->ci_obj, from + PAGE_SIZE - 1);
1796 descr->cld_mode = CLM_WRITE;
1797 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
1799 /* request lock for page */
1800 rc = cl_lock_request(env, io, lock);
1801 /* -ECANCELED indicates a matching lock with a different extent
1802 * was already present, and -EEXIST indicates a matching lock
1803 * on exactly the same extent was already present.
1804 * In both cases it means we are covered.
1806 if (rc == -ECANCELED || rc == -EEXIST)
1814 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
1816 GOTO(rellock, rc = -EOPNOTSUPP);
1818 if (!PageDirty(vmpage)) {
1819 /* associate cl_page */
1820 clpage = cl_page_find(env, clob, vmpage->index,
1821 vmpage, CPT_CACHEABLE);
1823 GOTO(pagefini, rc = PTR_ERR(clpage));
1825 cl_page_assume(env, io, clpage);
1828 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
1829 !PageWriteback(vmpage)) {
1831 /* set PagePrivate2 to detect special case of empty page
1832 * in osc_brw_fini_request()
1834 SetPagePrivate2(vmpage);
1835 rc = ll_io_read_page(env, io, clpage, NULL);
1836 if (!PagePrivate2(vmpage))
1837 /* PagePrivate2 was cleared in osc_brw_fini_request()
1838 * meaning we read an empty page. In this case, in order
1839 * to avoid allocating unnecessary block in truncated
1840 * file, we must not zero and write as below. Subsequent
1841 * server-side truncate will handle things correctly.
1843 GOTO(clpfini, rc = 0);
1844 ClearPagePrivate2(vmpage);
1847 lockedbymyself = trylock_page(vmpage);
1848 cl_page_assume(env, io, clpage);
1851 /* zero range in page */
1852 zero_user(vmpage, offset, len);
1854 if (holdinglock && clpage) {
1855 /* explicitly write newly modified page */
1856 queue = &io->ci_queue;
1857 cl_2queue_init(queue);
1858 anchor = &vvp_env_info(env)->vti_anchor;
1859 cl_sync_io_init(anchor, 1);
1860 clpage->cp_sync_io = anchor;
1861 cl_2queue_add(queue, clpage);
1862 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
1864 GOTO(queuefini1, rc);
1865 rc = cl_sync_io_wait(env, anchor, 0);
1867 GOTO(queuefini2, rc);
1868 cl_page_assume(env, io, clpage);
1871 cl_2queue_discard(env, io, queue);
1873 cl_2queue_disown(env, io, queue);
1874 cl_2queue_fini(env, queue);
1879 cl_page_put(env, clpage);
1881 if (lockedbymyself) {
1882 unlock_page(vmpage);
1887 cl_lock_release(env, lock);
1889 cl_io_fini(env, io);
1892 cl_env_put(env, &refcheck);
1897 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1898 * object(s) determine the file size and mtime. Otherwise, the MDS will
1899 * keep these values until such a time that objects are allocated for it.
1900 * We do the MDS operations first, as it is checking permissions for us.
1901 * We don't to the MDS RPC if there is nothing that we want to store there,
1902 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1903 * going to do an RPC anyways.
1905 * If we are doing a truncate, we will send the mtime and ctime updates
1906 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1907 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1910 * In case of HSMimport, we only set attr on MDS.
1912 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
1913 enum op_xvalid xvalid, bool hsm_import)
1915 struct inode *inode = dentry->d_inode;
1916 struct ll_inode_info *lli = ll_i2info(inode);
1917 struct md_op_data *op_data = NULL;
1918 ktime_t kstart = ktime_get();
1923 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
1924 "valid %x, hsm_import %d\n",
1925 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
1926 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
1929 if (attr->ia_valid & ATTR_SIZE) {
1930 /* Check new size against VFS/VM file size limit and rlimit */
1931 rc = inode_newsize_ok(inode, attr->ia_size);
1935 /* The maximum Lustre file size is variable, based on the
1936 * OST maximum object size and number of stripes. This
1937 * needs another check in addition to the VFS check above. */
1938 if (attr->ia_size > ll_file_maxbytes(inode)) {
1939 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
1940 PFID(&lli->lli_fid), attr->ia_size,
1941 ll_file_maxbytes(inode));
1945 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1948 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1949 if (attr->ia_valid & TIMES_SET_FLAGS) {
1950 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
1951 !cfs_capable(CFS_CAP_FOWNER))
1955 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1956 if (!(xvalid & OP_XVALID_CTIME_SET) &&
1957 (attr->ia_valid & ATTR_CTIME)) {
1958 attr->ia_ctime = current_time(inode);
1959 xvalid |= OP_XVALID_CTIME_SET;
1961 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
1962 (attr->ia_valid & ATTR_ATIME)) {
1963 attr->ia_atime = current_time(inode);
1964 attr->ia_valid |= ATTR_ATIME_SET;
1966 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
1967 (attr->ia_valid & ATTR_MTIME)) {
1968 attr->ia_mtime = current_time(inode);
1969 attr->ia_valid |= ATTR_MTIME_SET;
1972 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1973 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
1974 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
1975 ktime_get_real_seconds());
1977 if (S_ISREG(inode->i_mode))
1978 inode_unlock(inode);
1980 /* We always do an MDS RPC, even if we're only changing the size;
1981 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
1983 OBD_ALLOC_PTR(op_data);
1984 if (op_data == NULL)
1985 GOTO(out, rc = -ENOMEM);
1987 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
1988 /* If we are changing file size, file content is
1989 * modified, flag it.
1991 xvalid |= OP_XVALID_OWNEROVERRIDE;
1992 op_data->op_bias |= MDS_DATA_MODIFIED;
1993 ll_file_clear_flag(lli, LLIF_DATA_MODIFIED);
1996 if (attr->ia_valid & ATTR_FILE) {
1997 struct ll_file_data *fd = attr->ia_file->private_data;
1999 if (fd->fd_lease_och)
2000 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2003 op_data->op_attr = *attr;
2004 op_data->op_xvalid = xvalid;
2006 rc = ll_md_setattr(dentry, op_data);
2010 if (!S_ISREG(inode->i_mode) || hsm_import)
2013 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2014 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2015 xvalid & OP_XVALID_CTIME_SET) {
2016 bool cached = false;
2018 rc = pcc_inode_setattr(inode, attr, &cached);
2021 CERROR("%s: PCC inode "DFID" setattr failed: "
2023 ll_i2sbi(inode)->ll_fsname,
2024 PFID(&lli->lli_fid), rc);
2028 unsigned int flags = 0;
2030 /* For truncate and utimes sending attributes to OSTs,
2031 * setting mtime/atime to the past will be performed
2032 * under PW [0:EOF] extent lock (new_size:EOF for
2033 * truncate). It may seem excessive to send mtime/atime
2034 * updates to OSTs when not setting times to past, but
2035 * it is necessary due to possible time
2036 * de-synchronization between MDT inode and OST objects
2038 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode) &&
2039 attr->ia_valid & ATTR_SIZE) {
2040 xvalid |= OP_XVALID_FLAGS;
2041 flags = LUSTRE_ENCRYPT_FL;
2042 /* Call to ll_io_zero_page is not necessary if
2043 * truncating on PAGE_SIZE boundary, because
2044 * whole pages will be wiped.
2045 * In case of Direct IO, all we need is to set
2048 if (attr->ia_size & ~PAGE_MASK &&
2049 !(attr->ia_valid & ATTR_FILE &&
2050 attr->ia_file->f_flags & O_DIRECT)) {
2052 attr->ia_size & (PAGE_SIZE - 1);
2054 rc = ll_io_zero_page(inode,
2055 attr->ia_size >> PAGE_SHIFT,
2056 offset, PAGE_SIZE - offset);
2061 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2065 /* If the file was restored, it needs to set dirty flag.
2067 * We've already sent MDS_DATA_MODIFIED flag in
2068 * ll_md_setattr() for truncate. However, the MDT refuses to
2069 * set the HS_DIRTY flag on released files, so we have to set
2070 * it again if the file has been restored. Please check how
2071 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2073 * Please notice that if the file is not released, the previous
2074 * MDS_DATA_MODIFIED has taken effect and usually
2075 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2076 * This way we can save an RPC for common open + trunc
2078 if (ll_file_test_and_clear_flag(lli, LLIF_DATA_MODIFIED)) {
2079 struct hsm_state_set hss = {
2080 .hss_valid = HSS_SETMASK,
2081 .hss_setmask = HS_DIRTY,
2085 rc2 = ll_hsm_state_set(inode, &hss);
2086 /* truncate and write can happen at the same time, so that
2087 * the file can be set modified even though the file is not
2088 * restored from released state, and ll_hsm_state_set() is
2089 * not applicable for the file, and rc2 < 0 is normal in this
2092 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2093 PFID(ll_inode2fid(inode)), rc2);
2098 if (op_data != NULL)
2099 ll_finish_md_op_data(op_data);
2101 if (S_ISREG(inode->i_mode)) {
2103 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2104 inode_dio_wait(inode);
2105 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2106 * flag. ll_update_inode (called from ll_md_setattr), clears
2107 * inode flags, so there is a gap where S_NOSEC is not set.
2108 * This can cause a writer to take the i_mutex unnecessarily,
2109 * but this is safe to do and should be rare. */
2110 inode_has_no_xattr(inode);
2114 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2115 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2116 ktime_us_delta(ktime_get(), kstart));
2121 int ll_setattr(struct dentry *de, struct iattr *attr)
2123 int mode = de->d_inode->i_mode;
2124 enum op_xvalid xvalid = 0;
2127 rc = llcrypt_prepare_setattr(de, attr);
2131 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2132 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2133 xvalid |= OP_XVALID_OWNEROVERRIDE;
2135 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2136 (ATTR_SIZE|ATTR_MODE)) &&
2137 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2138 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2139 !(attr->ia_mode & S_ISGID))))
2140 attr->ia_valid |= ATTR_FORCE;
2142 if ((attr->ia_valid & ATTR_MODE) &&
2144 !(attr->ia_mode & S_ISUID) &&
2145 !(attr->ia_valid & ATTR_KILL_SUID))
2146 attr->ia_valid |= ATTR_KILL_SUID;
2148 if ((attr->ia_valid & ATTR_MODE) &&
2149 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2150 !(attr->ia_mode & S_ISGID) &&
2151 !(attr->ia_valid & ATTR_KILL_SGID))
2152 attr->ia_valid |= ATTR_KILL_SGID;
2154 return ll_setattr_raw(de, attr, xvalid, false);
2157 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2160 struct obd_statfs obd_osfs = { 0 };
2165 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2167 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
2168 flags |= OBD_STATFS_NODELAY;
2170 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2174 osfs->os_type = LL_SUPER_MAGIC;
2176 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2177 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2179 if (osfs->os_state & OS_STATFS_SUM)
2182 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2183 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2186 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2187 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2190 osfs->os_bsize = obd_osfs.os_bsize;
2191 osfs->os_blocks = obd_osfs.os_blocks;
2192 osfs->os_bfree = obd_osfs.os_bfree;
2193 osfs->os_bavail = obd_osfs.os_bavail;
2195 /* If we have _some_ OSTs, but don't have as many free objects on the
2196 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2197 * to compensate, so that the "inodes in use" number is correct.
2198 * This should be kept in sync with lod_statfs() behaviour.
2200 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2201 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2203 osfs->os_ffree = obd_osfs.os_ffree;
2210 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2212 struct if_quotactl qctl = {
2213 .qc_cmd = LUSTRE_Q_GETQUOTA,
2214 .qc_type = PRJQUOTA,
2215 .qc_valid = QC_GENERAL,
2217 u64 limit, curblock;
2220 qctl.qc_id = ll_i2info(inode)->lli_projid;
2221 ret = quotactl_ioctl(ll_i2sbi(inode), &qctl);
2223 /* ignore errors if project ID does not have
2224 * a quota limit or feature unsupported.
2226 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2231 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2232 qctl.qc_dqblk.dqb_bsoftlimit :
2233 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2234 if (limit && sfs->f_blocks > limit) {
2235 curblock = (qctl.qc_dqblk.dqb_curspace +
2236 sfs->f_bsize - 1) / sfs->f_bsize;
2237 sfs->f_blocks = limit;
2238 sfs->f_bfree = sfs->f_bavail =
2239 (sfs->f_blocks > curblock) ?
2240 (sfs->f_blocks - curblock) : 0;
2243 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2244 qctl.qc_dqblk.dqb_isoftlimit :
2245 qctl.qc_dqblk.dqb_ihardlimit;
2246 if (limit && sfs->f_files > limit) {
2247 sfs->f_files = limit;
2248 sfs->f_ffree = (sfs->f_files >
2249 qctl.qc_dqblk.dqb_curinodes) ?
2250 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2256 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2258 struct super_block *sb = de->d_sb;
2259 struct obd_statfs osfs;
2260 __u64 fsid = huge_encode_dev(sb->s_dev);
2261 ktime_t kstart = ktime_get();
2264 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2266 /* Some amount of caching on the client is allowed */
2267 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2271 statfs_unpack(sfs, &osfs);
2273 /* We need to downshift for all 32-bit kernels, because we can't
2274 * tell if the kernel is being called via sys_statfs64() or not.
2275 * Stop before overflowing f_bsize - in which case it is better
2276 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2277 if (sizeof(long) < 8) {
2278 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2281 osfs.os_blocks >>= 1;
2282 osfs.os_bfree >>= 1;
2283 osfs.os_bavail >>= 1;
2287 sfs->f_blocks = osfs.os_blocks;
2288 sfs->f_bfree = osfs.os_bfree;
2289 sfs->f_bavail = osfs.os_bavail;
2290 sfs->f_fsid.val[0] = (__u32)fsid;
2291 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2292 if (ll_i2info(de->d_inode)->lli_projid)
2293 return ll_statfs_project(de->d_inode, sfs);
2295 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2296 ktime_us_delta(ktime_get(), kstart));
2301 void ll_inode_size_lock(struct inode *inode)
2303 struct ll_inode_info *lli;
2305 LASSERT(!S_ISDIR(inode->i_mode));
2307 lli = ll_i2info(inode);
2308 mutex_lock(&lli->lli_size_mutex);
2311 void ll_inode_size_unlock(struct inode *inode)
2313 struct ll_inode_info *lli;
2315 lli = ll_i2info(inode);
2316 mutex_unlock(&lli->lli_size_mutex);
2319 void ll_update_inode_flags(struct inode *inode, int ext_flags)
2321 /* do not clear encryption flag */
2322 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2323 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2324 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2325 ll_file_set_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
2327 ll_file_clear_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
2330 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2332 struct ll_inode_info *lli = ll_i2info(inode);
2333 struct mdt_body *body = md->body;
2334 struct ll_sb_info *sbi = ll_i2sbi(inode);
2337 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2338 rc = cl_file_inode_init(inode, md);
2343 if (S_ISDIR(inode->i_mode)) {
2344 rc = ll_update_lsm_md(inode, md);
2349 if (body->mbo_valid & OBD_MD_FLACL)
2350 lli_replace_acl(lli, md);
2352 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1,
2353 sbi->ll_flags & LL_SBI_32BIT_API);
2354 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2356 if (body->mbo_valid & OBD_MD_FLATIME) {
2357 if (body->mbo_atime > inode->i_atime.tv_sec)
2358 inode->i_atime.tv_sec = body->mbo_atime;
2359 lli->lli_atime = body->mbo_atime;
2362 if (body->mbo_valid & OBD_MD_FLMTIME) {
2363 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2365 "setting ino %lu mtime from %lld to %llu\n",
2366 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2368 inode->i_mtime.tv_sec = body->mbo_mtime;
2370 lli->lli_mtime = body->mbo_mtime;
2373 if (body->mbo_valid & OBD_MD_FLCTIME) {
2374 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2375 inode->i_ctime.tv_sec = body->mbo_ctime;
2376 lli->lli_ctime = body->mbo_ctime;
2379 if (body->mbo_valid & OBD_MD_FLBTIME)
2380 lli->lli_btime = body->mbo_btime;
2382 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2383 if (body->mbo_valid & OBD_MD_FLFLAGS)
2384 ll_update_inode_flags(inode, body->mbo_flags);
2385 if (body->mbo_valid & OBD_MD_FLMODE)
2386 inode->i_mode = (inode->i_mode & S_IFMT) |
2387 (body->mbo_mode & ~S_IFMT);
2389 if (body->mbo_valid & OBD_MD_FLTYPE)
2390 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2391 (body->mbo_mode & S_IFMT);
2393 LASSERT(inode->i_mode != 0);
2394 if (body->mbo_valid & OBD_MD_FLUID)
2395 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2396 if (body->mbo_valid & OBD_MD_FLGID)
2397 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2398 if (body->mbo_valid & OBD_MD_FLPROJID)
2399 lli->lli_projid = body->mbo_projid;
2400 if (body->mbo_valid & OBD_MD_FLNLINK)
2401 set_nlink(inode, body->mbo_nlink);
2402 if (body->mbo_valid & OBD_MD_FLRDEV)
2403 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2405 if (body->mbo_valid & OBD_MD_FLID) {
2406 /* FID shouldn't be changed! */
2407 if (fid_is_sane(&lli->lli_fid)) {
2408 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2409 "Trying to change FID "DFID
2410 " to the "DFID", inode "DFID"(%p)\n",
2411 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2412 PFID(ll_inode2fid(inode)), inode);
2414 lli->lli_fid = body->mbo_fid1;
2418 LASSERT(fid_seq(&lli->lli_fid) != 0);
2420 lli->lli_attr_valid = body->mbo_valid;
2421 if (body->mbo_valid & OBD_MD_FLSIZE) {
2422 i_size_write(inode, body->mbo_size);
2424 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2425 PFID(ll_inode2fid(inode)),
2426 (unsigned long long)body->mbo_size);
2428 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2429 inode->i_blocks = body->mbo_blocks;
2431 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2432 lli->lli_lazysize = body->mbo_size;
2433 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2434 lli->lli_lazyblocks = body->mbo_blocks;
2437 if (body->mbo_valid & OBD_MD_TSTATE) {
2438 /* Set LLIF_FILE_RESTORING if restore ongoing and
2439 * clear it when done to ensure to start again
2440 * glimpsing updated attrs
2442 if (body->mbo_t_state & MS_RESTORE)
2443 ll_file_set_flag(lli, LLIF_FILE_RESTORING);
2445 ll_file_clear_flag(lli, LLIF_FILE_RESTORING);
2451 int ll_read_inode2(struct inode *inode, void *opaque)
2453 struct lustre_md *md = opaque;
2454 struct ll_inode_info *lli = ll_i2info(inode);
2458 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2459 PFID(&lli->lli_fid), inode);
2461 /* Core attributes from the MDS first. This is a new inode, and
2462 * the VFS doesn't zero times in the core inode so we have to do
2463 * it ourselves. They will be overwritten by either MDS or OST
2464 * attributes - we just need to make sure they aren't newer.
2466 inode->i_mtime.tv_sec = 0;
2467 inode->i_atime.tv_sec = 0;
2468 inode->i_ctime.tv_sec = 0;
2470 rc = ll_update_inode(inode, md);
2474 /* OIDEBUG(inode); */
2476 #ifdef HAVE_BACKING_DEV_INFO
2477 /* initializing backing dev info. */
2478 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2480 if (S_ISREG(inode->i_mode)) {
2481 struct ll_sb_info *sbi = ll_i2sbi(inode);
2482 inode->i_op = &ll_file_inode_operations;
2483 inode->i_fop = sbi->ll_fop;
2484 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2486 } else if (S_ISDIR(inode->i_mode)) {
2487 inode->i_op = &ll_dir_inode_operations;
2488 inode->i_fop = &ll_dir_operations;
2490 } else if (S_ISLNK(inode->i_mode)) {
2491 inode->i_op = &ll_fast_symlink_inode_operations;
2494 inode->i_op = &ll_special_inode_operations;
2496 init_special_inode(inode, inode->i_mode,
2505 void ll_delete_inode(struct inode *inode)
2507 struct ll_inode_info *lli = ll_i2info(inode);
2508 struct address_space *mapping = &inode->i_data;
2509 unsigned long nrpages;
2510 unsigned long flags;
2514 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2515 /* It is last chance to write out dirty pages,
2516 * otherwise we may lose data while umount.
2518 * If i_nlink is 0 then just discard data. This is safe because
2519 * local inode gets i_nlink 0 from server only for the last
2520 * unlink, so that file is not opened somewhere else
2522 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2523 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2525 truncate_inode_pages_final(mapping);
2527 /* Workaround for LU-118: Note nrpages may not be totally updated when
2528 * truncate_inode_pages() returns, as there can be a page in the process
2529 * of deletion (inside __delete_from_page_cache()) in the specified
2530 * range. Thus mapping->nrpages can be non-zero when this function
2531 * returns even after truncation of the whole mapping. Only do this if
2532 * npages isn't already zero.
2534 nrpages = mapping->nrpages;
2536 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2537 nrpages = mapping->nrpages;
2538 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2539 } /* Workaround end */
2541 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, "
2542 "see https://jira.whamcloud.com/browse/LU-118\n",
2543 ll_i2sbi(inode)->ll_fsname,
2544 PFID(ll_inode2fid(inode)), inode, nrpages);
2546 ll_clear_inode(inode);
2552 int ll_iocontrol(struct inode *inode, struct file *file,
2553 unsigned int cmd, unsigned long arg)
2555 struct ll_sb_info *sbi = ll_i2sbi(inode);
2556 struct ptlrpc_request *req = NULL;
2561 case FS_IOC_GETFLAGS: {
2562 struct mdt_body *body;
2563 struct md_op_data *op_data;
2565 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2566 0, 0, LUSTRE_OPC_ANY,
2568 if (IS_ERR(op_data))
2569 RETURN(PTR_ERR(op_data));
2571 op_data->op_valid = OBD_MD_FLFLAGS;
2572 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2573 ll_finish_md_op_data(op_data);
2575 CERROR("%s: failure inode "DFID": rc = %d\n",
2576 sbi->ll_md_exp->exp_obd->obd_name,
2577 PFID(ll_inode2fid(inode)), rc);
2581 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2583 flags = body->mbo_flags;
2585 ptlrpc_req_finished(req);
2587 RETURN(put_user(flags, (int __user *)arg));
2589 case FS_IOC_SETFLAGS: {
2591 struct md_op_data *op_data;
2592 struct cl_object *obj;
2593 struct fsxattr fa = { 0 };
2595 if (get_user(flags, (int __user *)arg))
2598 fa.fsx_projid = ll_i2info(inode)->lli_projid;
2599 if (flags & LUSTRE_PROJINHERIT_FL)
2600 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
2602 rc = ll_ioctl_check_project(inode, &fa);
2606 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
2607 LUSTRE_OPC_ANY, NULL);
2608 if (IS_ERR(op_data))
2609 RETURN(PTR_ERR(op_data));
2611 op_data->op_attr_flags = flags;
2612 op_data->op_xvalid |= OP_XVALID_FLAGS;
2613 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
2614 ll_finish_md_op_data(op_data);
2615 ptlrpc_req_finished(req);
2619 ll_update_inode_flags(inode, flags);
2621 obj = ll_i2info(inode)->lli_clob;
2625 OBD_ALLOC_PTR(attr);
2629 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
2641 int ll_flush_ctx(struct inode *inode)
2643 struct ll_sb_info *sbi = ll_i2sbi(inode);
2645 CDEBUG(D_SEC, "flush context for user %d\n",
2646 from_kuid(&init_user_ns, current_uid()));
2648 obd_set_info_async(NULL, sbi->ll_md_exp,
2649 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2651 obd_set_info_async(NULL, sbi->ll_dt_exp,
2652 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2657 /* umount -f client means force down, don't save state */
2658 void ll_umount_begin(struct super_block *sb)
2660 struct ll_sb_info *sbi = ll_s2sbi(sb);
2661 struct obd_device *obd;
2662 struct obd_ioctl_data *ioc_data;
2666 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2667 sb->s_count, atomic_read(&sb->s_active));
2669 obd = class_exp2obd(sbi->ll_md_exp);
2671 CERROR("Invalid MDC connection handle %#llx\n",
2672 sbi->ll_md_exp->exp_handle.h_cookie);
2678 obd = class_exp2obd(sbi->ll_dt_exp);
2680 CERROR("Invalid LOV connection handle %#llx\n",
2681 sbi->ll_dt_exp->exp_handle.h_cookie);
2687 OBD_ALLOC_PTR(ioc_data);
2689 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2690 sizeof *ioc_data, ioc_data, NULL);
2692 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2693 sizeof *ioc_data, ioc_data, NULL);
2695 OBD_FREE_PTR(ioc_data);
2698 /* Really, we'd like to wait until there are no requests outstanding,
2699 * and then continue. For now, we just periodically checking for vfs
2700 * to decrement mnt_cnt and hope to finish it within 10sec.
2704 !may_umount(sbi->ll_mnt.mnt)) {
2712 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2714 struct ll_sb_info *sbi = ll_s2sbi(sb);
2715 char *profilenm = get_profile_name(sb);
2719 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
2720 read_only = *flags & MS_RDONLY;
2721 err = obd_set_info_async(NULL, sbi->ll_md_exp,
2722 sizeof(KEY_READ_ONLY),
2723 KEY_READ_ONLY, sizeof(read_only),
2726 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2727 profilenm, read_only ?
2728 "read-only" : "read-write", err);
2733 sb->s_flags |= SB_RDONLY;
2735 sb->s_flags &= ~SB_RDONLY;
2737 if (sbi->ll_flags & LL_SBI_VERBOSE)
2738 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
2739 read_only ? "read-only" : "read-write");
2745 * Cleanup the open handle that is cached on MDT-side.
2747 * For open case, the client side open handling thread may hit error
2748 * after the MDT grant the open. Under such case, the client should
2749 * send close RPC to the MDT as cleanup; otherwise, the open handle
2750 * on the MDT will be leaked there until the client umount or evicted.
2752 * In further, if someone unlinked the file, because the open handle
2753 * holds the reference on such file/object, then it will block the
2754 * subsequent threads that want to locate such object via FID.
2756 * \param[in] sb super block for this file-system
2757 * \param[in] open_req pointer to the original open request
2759 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
2761 struct mdt_body *body;
2762 struct md_op_data *op_data;
2763 struct ptlrpc_request *close_req = NULL;
2764 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
2767 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
2768 OBD_ALLOC_PTR(op_data);
2769 if (op_data == NULL) {
2770 CWARN("%s: cannot allocate op_data to release open handle for "
2771 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
2776 op_data->op_fid1 = body->mbo_fid1;
2777 op_data->op_open_handle = body->mbo_open_handle;
2778 op_data->op_mod_time = ktime_get_real_seconds();
2779 md_close(exp, op_data, NULL, &close_req);
2780 ptlrpc_req_finished(close_req);
2781 ll_finish_md_op_data(op_data);
2786 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
2787 struct super_block *sb, struct lookup_intent *it)
2789 struct ll_sb_info *sbi = NULL;
2790 struct lustre_md md = { NULL };
2791 bool default_lmv_deleted = false;
2796 LASSERT(*inode || sb);
2797 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2798 rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
2799 sbi->ll_md_exp, &md);
2804 * clear default_lmv only if intent_getattr reply doesn't contain it.
2805 * but it needs to be done after iget, check this early because
2806 * ll_update_lsm_md() may change md.
2808 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
2809 S_ISDIR(md.body->mbo_mode) && !md.default_lmv)
2810 default_lmv_deleted = true;
2813 rc = ll_update_inode(*inode, &md);
2817 LASSERT(sb != NULL);
2820 * At this point server returns to client's same fid as client
2821 * generated for creating. So using ->fid1 is okay here.
2823 if (!fid_is_sane(&md.body->mbo_fid1)) {
2824 CERROR("%s: Fid is insane "DFID"\n",
2826 PFID(&md.body->mbo_fid1));
2827 GOTO(out, rc = -EINVAL);
2830 *inode = ll_iget(sb, cl_fid_build_ino(&md.body->mbo_fid1,
2831 sbi->ll_flags & LL_SBI_32BIT_API),
2833 if (IS_ERR(*inode)) {
2835 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
2837 CERROR("new_inode -fatal: rc %d\n", rc);
2842 /* Handling piggyback layout lock.
2843 * Layout lock can be piggybacked by getattr and open request.
2844 * The lsm can be applied to inode only if it comes with a layout lock
2845 * otherwise correct layout may be overwritten, for example:
2846 * 1. proc1: mdt returns a lsm but not granting layout
2847 * 2. layout was changed by another client
2848 * 3. proc2: refresh layout and layout lock granted
2849 * 4. proc1: to apply a stale layout */
2850 if (it != NULL && it->it_lock_mode != 0) {
2851 struct lustre_handle lockh;
2852 struct ldlm_lock *lock;
2854 lockh.cookie = it->it_lock_handle;
2855 lock = ldlm_handle2lock(&lockh);
2856 LASSERT(lock != NULL);
2857 if (ldlm_has_layout(lock)) {
2858 struct cl_object_conf conf;
2860 memset(&conf, 0, sizeof(conf));
2861 conf.coc_opc = OBJECT_CONF_SET;
2862 conf.coc_inode = *inode;
2863 conf.coc_lock = lock;
2864 conf.u.coc_layout = md.layout;
2865 (void)ll_layout_conf(*inode, &conf);
2867 LDLM_LOCK_PUT(lock);
2870 if (default_lmv_deleted)
2871 ll_update_default_lsm_md(*inode, &md);
2876 /* cleanup will be done if necessary */
2877 md_free_lustre_md(sbi->ll_md_exp, &md);
2879 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
2880 ll_intent_drop_lock(it);
2881 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, req);
2887 int ll_obd_statfs(struct inode *inode, void __user *arg)
2889 struct ll_sb_info *sbi = NULL;
2890 struct obd_export *exp;
2892 struct obd_ioctl_data *data = NULL;
2896 if (!inode || !(sbi = ll_i2sbi(inode)))
2897 GOTO(out_statfs, rc = -EINVAL);
2899 rc = obd_ioctl_getdata(&buf, &len, arg);
2901 GOTO(out_statfs, rc);
2904 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2905 !data->ioc_pbuf1 || !data->ioc_pbuf2)
2906 GOTO(out_statfs, rc = -EINVAL);
2908 if (data->ioc_inllen1 != sizeof(__u32) ||
2909 data->ioc_inllen2 != sizeof(__u32) ||
2910 data->ioc_plen1 != sizeof(struct obd_statfs) ||
2911 data->ioc_plen2 != sizeof(struct obd_uuid))
2912 GOTO(out_statfs, rc = -EINVAL);
2914 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2915 if (type & LL_STATFS_LMV)
2916 exp = sbi->ll_md_exp;
2917 else if (type & LL_STATFS_LOV)
2918 exp = sbi->ll_dt_exp;
2920 GOTO(out_statfs, rc = -ENODEV);
2922 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL);
2924 GOTO(out_statfs, rc);
2926 OBD_FREE_LARGE(buf, len);
2931 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
2932 * be called early to avoid deadlock.
2934 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
2936 if (op_data->op_mea2_sem) {
2937 up_read_non_owner(op_data->op_mea2_sem);
2938 op_data->op_mea2_sem = NULL;
2941 if (op_data->op_mea1_sem) {
2942 up_read_non_owner(op_data->op_mea1_sem);
2943 op_data->op_mea1_sem = NULL;
2947 /* this function prepares md_op_data hint for passing it down to MD stack. */
2948 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
2949 struct inode *i1, struct inode *i2,
2950 const char *name, size_t namelen,
2951 __u32 mode, enum md_op_code opc,
2954 LASSERT(i1 != NULL);
2957 /* Do not reuse namelen for something else. */
2959 return ERR_PTR(-EINVAL);
2961 if (namelen > ll_i2sbi(i1)->ll_namelen)
2962 return ERR_PTR(-ENAMETOOLONG);
2964 /* "/" is not valid name, but it's allowed */
2965 if (!lu_name_is_valid_2(name, namelen) &&
2966 strncmp("/", name, namelen) != 0)
2967 return ERR_PTR(-EINVAL);
2970 if (op_data == NULL)
2971 OBD_ALLOC_PTR(op_data);
2973 if (op_data == NULL)
2974 return ERR_PTR(-ENOMEM);
2976 ll_i2gids(op_data->op_suppgids, i1, i2);
2977 op_data->op_fid1 = *ll_inode2fid(i1);
2978 op_data->op_code = opc;
2980 if (S_ISDIR(i1->i_mode)) {
2981 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
2982 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
2983 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
2984 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
2988 op_data->op_fid2 = *ll_inode2fid(i2);
2989 if (S_ISDIR(i2->i_mode)) {
2991 /* i2 is typically a child of i1, and MUST be
2992 * further from the root to avoid deadlocks.
2994 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
2995 op_data->op_mea2_sem =
2996 &ll_i2info(i2)->lli_lsm_sem;
2998 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3001 fid_zero(&op_data->op_fid2);
3004 if (ll_i2sbi(i1)->ll_flags & LL_SBI_64BIT_HASH)
3005 op_data->op_cli_flags |= CLI_HASH64;
3007 if (ll_need_32bit_api(ll_i2sbi(i1)))
3008 op_data->op_cli_flags |= CLI_API32;
3010 op_data->op_name = name;
3011 op_data->op_namelen = namelen;
3012 op_data->op_mode = mode;
3013 op_data->op_mod_time = ktime_get_real_seconds();
3014 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3015 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3016 op_data->op_cap = cfs_curproc_cap_pack();
3017 op_data->op_mds = 0;
3018 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3019 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3020 op_data->op_bias |= MDS_CREATE_VOLATILE;
3022 op_data->op_data = data;
3027 void ll_finish_md_op_data(struct md_op_data *op_data)
3029 ll_unlock_md_op_lsm(op_data);
3030 security_release_secctx(op_data->op_file_secctx,
3031 op_data->op_file_secctx_size);
3032 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3033 OBD_FREE_PTR(op_data);
3036 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3038 struct ll_sb_info *sbi;
3040 LASSERT(seq && dentry);
3041 sbi = ll_s2sbi(dentry->d_sb);
3043 if (sbi->ll_flags & LL_SBI_NOLCK)
3044 seq_puts(seq, ",nolock");
3046 /* "flock" is the default since 2.13, but it wasn't for many years,
3047 * so it is still useful to print this to show it is enabled.
3048 * Start to print "noflock" so it is now clear when flock is disabled.
3050 if (sbi->ll_flags & LL_SBI_FLOCK)
3051 seq_puts(seq, ",flock");
3052 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
3053 seq_puts(seq, ",localflock");
3055 seq_puts(seq, ",noflock");
3057 if (sbi->ll_flags & LL_SBI_USER_XATTR)
3058 seq_puts(seq, ",user_xattr");
3060 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
3061 seq_puts(seq, ",lazystatfs");
3063 if (sbi->ll_flags & LL_SBI_USER_FID2PATH)
3064 seq_puts(seq, ",user_fid2path");
3066 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
3067 seq_puts(seq, ",always_ping");
3069 if (ll_sbi_has_test_dummy_encryption(sbi))
3070 seq_puts(seq, ",test_dummy_encryption");
3072 if (ll_sbi_has_encrypt(sbi))
3073 seq_puts(seq, ",encrypt");
3075 seq_puts(seq, ",noencrypt");
3081 * Get obd name by cmd, and copy out to user space
3083 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
3085 struct ll_sb_info *sbi = ll_i2sbi(inode);
3086 struct obd_device *obd;
3089 if (cmd == OBD_IOC_GETDTNAME)
3090 obd = class_exp2obd(sbi->ll_dt_exp);
3091 else if (cmd == OBD_IOC_GETMDNAME)
3092 obd = class_exp2obd(sbi->ll_md_exp);
3099 if (copy_to_user((void __user *)arg, obd->obd_name,
3100 strlen(obd->obd_name) + 1))
3106 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3113 p.mnt = current->fs->root.mnt;
3115 path = d_path(&p, buf, bufsize);
3120 void ll_dirty_page_discard_warn(struct page *page, int ioret)
3122 char *buf, *path = NULL;
3123 struct dentry *dentry = NULL;
3124 struct inode *inode = page->mapping->host;
3126 /* this can be called inside spin lock so use GFP_ATOMIC. */
3127 buf = (char *)__get_free_page(GFP_ATOMIC);
3129 dentry = d_find_alias(page->mapping->host);
3131 path = ll_d_path(dentry, buf, PAGE_SIZE);
3134 /* The below message is checked in recovery-small.sh test_24b */
3136 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3137 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3138 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
3139 PFID(ll_inode2fid(inode)),
3140 (path && !IS_ERR(path)) ? path : "", ioret);
3146 free_page((unsigned long)buf);
3149 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3150 struct lov_user_md **kbuf)
3152 struct lov_user_md lum;
3156 if (copy_from_user(&lum, md, sizeof(lum)))
3159 lum_size = ll_lov_user_md_size(&lum);
3163 OBD_ALLOC_LARGE(*kbuf, lum_size);
3167 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3168 OBD_FREE_LARGE(*kbuf, lum_size);
3176 * Compute llite root squash state after a change of root squash
3177 * configuration setting or add/remove of a lnet nid
3179 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3181 struct root_squash_info *squash = &sbi->ll_squash;
3184 struct lnet_process_id id;
3186 /* Update norootsquash flag */
3187 spin_lock(&squash->rsi_lock);
3188 if (list_empty(&squash->rsi_nosquash_nids))
3189 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
3191 /* Do not apply root squash as soon as one of our NIDs is
3192 * in the nosquash_nids list */
3195 while (LNetGetId(i++, &id) != -ENOENT) {
3196 if (id.nid == LNET_NID_LO_0)
3198 if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) {
3204 sbi->ll_flags |= LL_SBI_NOROOTSQUASH;
3206 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
3208 spin_unlock(&squash->rsi_lock);
3212 * Parse linkea content to extract information about a given hardlink
3214 * \param[in] ldata - Initialized linkea data
3215 * \param[in] linkno - Link identifier
3216 * \param[out] parent_fid - The entry's parent FID
3217 * \param[out] ln - Entry name destination buffer
3219 * \retval 0 on success
3220 * \retval Appropriate negative error code on failure
3222 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3223 struct lu_fid *parent_fid, struct lu_name *ln)
3229 rc = linkea_init_with_rec(ldata);
3233 if (linkno >= ldata->ld_leh->leh_reccount)
3234 /* beyond last link */
3237 linkea_first_entry(ldata);
3238 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3239 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3244 linkea_next_entry(ldata);
3254 * Get parent FID and name of an identified link. Operation is performed for
3255 * a given link number, letting the caller iterate over linkno to list one or
3256 * all links of an entry.
3258 * \param[in] file - File descriptor against which to perform the operation
3259 * \param[in,out] arg - User-filled structure containing the linkno to operate
3260 * on and the available size. It is eventually filled with
3261 * the requested information or left untouched on error
3263 * \retval - 0 on success
3264 * \retval - Appropriate negative error code on failure
3266 int ll_getparent(struct file *file, struct getparent __user *arg)
3268 struct inode *inode = file_inode(file);
3269 struct linkea_data *ldata;
3270 struct lu_buf buf = LU_BUF_NULL;
3272 struct lu_fid parent_fid;
3279 if (!cfs_capable(CFS_CAP_DAC_READ_SEARCH) &&
3280 !(ll_i2sbi(inode)->ll_flags & LL_SBI_USER_FID2PATH))
3283 if (get_user(name_size, &arg->gp_name_size))
3286 if (get_user(linkno, &arg->gp_linkno))
3289 if (name_size > PATH_MAX)
3292 OBD_ALLOC(ldata, sizeof(*ldata));
3296 rc = linkea_data_new(ldata, &buf);
3298 GOTO(ldata_free, rc);
3300 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3301 buf.lb_len, OBD_MD_FLXATTR);
3305 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3309 if (ln.ln_namelen >= name_size)
3310 GOTO(lb_free, rc = -EOVERFLOW);
3312 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3313 GOTO(lb_free, rc = -EFAULT);
3315 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3316 GOTO(lb_free, rc = -EFAULT);
3318 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3319 GOTO(lb_free, rc = -EFAULT);
3324 OBD_FREE(ldata, sizeof(*ldata));