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>
53 #ifndef HAVE_CPUS_READ_LOCK
54 #include <libcfs/linux/linux-cpu.h>
56 #include <uapi/linux/lustre/lustre_ioctl.h>
57 #ifdef HAVE_UAPI_LINUX_MOUNT_H
58 #include <uapi/linux/mount.h>
61 #include <lustre_ha.h>
62 #include <lustre_dlm.h>
63 #include <lprocfs_status.h>
64 #include <lustre_disk.h>
65 #include <uapi/linux/lustre/lustre_param.h>
66 #include <lustre_log.h>
67 #include <cl_object.h>
68 #include <obd_cksum.h>
69 #include "llite_internal.h"
71 struct kmem_cache *ll_file_data_slab;
74 #define log2(n) ffz(~(n))
78 * If there is only one number of core visible to Lustre,
79 * async readahead will be disabled, to avoid massive over
80 * subscription, we use 1/2 of active cores as default max
81 * async readahead requests.
83 static inline unsigned int ll_get_ra_async_max_active(void)
85 return cfs_cpt_weight(cfs_cpt_tab, CFS_CPT_ANY) >> 1;
88 static struct ll_sb_info *ll_init_sbi(void)
90 struct ll_sb_info *sbi = NULL;
92 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 sbi->ll_ra_info.ra_max_pages_per_file = min(pages / 32,
132 SBI_DEFAULT_READ_AHEAD_MAX);
133 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
134 sbi->ll_ra_info.ra_max_pages_per_file;
135 sbi->ll_ra_info.ra_max_pages = sbi->ll_ra_info.ra_max_pages_per_file;
136 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
137 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
139 sbi->ll_flags |= LL_SBI_VERBOSE;
140 #ifdef ENABLE_CHECKSUM
141 sbi->ll_flags |= LL_SBI_CHECKSUM;
144 sbi->ll_flags |= LL_SBI_FLOCK;
147 #ifdef HAVE_LRU_RESIZE_SUPPORT
148 sbi->ll_flags |= LL_SBI_LRU_RESIZE;
150 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
152 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
153 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
155 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
159 /* metadata statahead is enabled by default */
160 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
161 sbi->ll_sa_max = LL_SA_RPC_DEF;
162 atomic_set(&sbi->ll_sa_total, 0);
163 atomic_set(&sbi->ll_sa_wrong, 0);
164 atomic_set(&sbi->ll_sa_running, 0);
165 atomic_set(&sbi->ll_agl_total, 0);
166 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
167 sbi->ll_flags |= LL_SBI_FAST_READ;
168 sbi->ll_flags |= LL_SBI_TINY_WRITE;
169 ll_sbi_set_encrypt(sbi, true);
172 sbi->ll_squash.rsi_uid = 0;
173 sbi->ll_squash.rsi_gid = 0;
174 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
175 spin_lock_init(&sbi->ll_squash.rsi_lock);
177 /* Per-filesystem file heat */
178 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
179 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
182 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
184 pcc_super_fini(&sbi->ll_pcc_super);
190 static void ll_free_sbi(struct super_block *sb)
192 struct ll_sb_info *sbi = ll_s2sbi(sb);
196 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
197 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
198 if (sbi->ll_ra_info.ll_readahead_wq)
199 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
200 if (sbi->ll_cache != NULL) {
201 cl_cache_decref(sbi->ll_cache);
202 sbi->ll_cache = NULL;
204 pcc_super_fini(&sbi->ll_pcc_super);
205 OBD_FREE(sbi, sizeof(*sbi));
210 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
212 struct inode *root = NULL;
213 struct ll_sb_info *sbi = ll_s2sbi(sb);
214 struct obd_statfs *osfs = NULL;
215 struct ptlrpc_request *request = NULL;
216 struct obd_connect_data *data = NULL;
217 struct obd_uuid *uuid;
218 struct md_op_data *op_data;
219 struct lustre_md lmd;
221 int size, err, checksum;
224 sbi->ll_md_obd = class_name2obd(md);
225 if (!sbi->ll_md_obd) {
226 CERROR("MD %s: not setup or attached\n", md);
240 /* pass client page size via ocd_grant_blkbits, the server should report
241 * back its backend blocksize for grant calculation purpose */
242 data->ocd_grant_blkbits = PAGE_SHIFT;
244 /* indicate MDT features supported by this client */
245 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
246 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
247 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
248 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
249 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
250 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
251 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
252 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
253 OBD_CONNECT_64BITHASH |
254 OBD_CONNECT_EINPROGRESS |
255 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
256 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
257 OBD_CONNECT_MAX_EASIZE |
258 OBD_CONNECT_FLOCK_DEAD |
259 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
260 OBD_CONNECT_OPEN_BY_FID |
261 OBD_CONNECT_DIR_STRIPE |
262 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
263 OBD_CONNECT_SUBTREE |
264 OBD_CONNECT_MULTIMODRPCS |
265 OBD_CONNECT_GRANT_PARAM |
266 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
268 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
269 OBD_CONNECT2_SUM_STATFS |
270 OBD_CONNECT2_OVERSTRIPING |
272 OBD_CONNECT2_LOCK_CONVERT |
273 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
274 OBD_CONNECT2_INC_XID |
276 OBD_CONNECT2_ASYNC_DISCARD |
280 #ifdef HAVE_LRU_RESIZE_SUPPORT
281 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
282 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
284 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
285 data->ocd_connect_flags |= OBD_CONNECT_ACL | OBD_CONNECT_UMASK |
286 OBD_CONNECT_LARGE_ACL;
289 data->ocd_cksum_types = obd_cksum_types_supported_client();
291 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
292 /* flag mdc connection as lightweight, only used for test
293 * purpose, use with care */
294 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
296 data->ocd_ibits_known = MDS_INODELOCK_FULL;
297 data->ocd_version = LUSTRE_VERSION_CODE;
299 if (sb->s_flags & SB_RDONLY)
300 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
301 if (sbi->ll_flags & LL_SBI_USER_XATTR)
302 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
305 /* Setting this indicates we correctly support S_NOSEC (See kernel
306 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
308 sb->s_flags |= SB_NOSEC;
311 if (sbi->ll_flags & LL_SBI_FLOCK)
312 sbi->ll_fop = &ll_file_operations_flock;
313 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
314 sbi->ll_fop = &ll_file_operations;
316 sbi->ll_fop = &ll_file_operations_noflock;
318 /* always ping even if server suppress_pings */
319 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
320 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
322 obd_connect_set_secctx(data);
324 #if defined(CONFIG_SECURITY)
325 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
328 data->ocd_brw_size = MD_MAX_BRW_SIZE;
330 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
331 &sbi->ll_sb_uuid, data, sbi->ll_cache);
333 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
334 "recovery, of which this client is not a "
335 "part. Please wait for recovery to complete,"
336 " abort, or time out.\n", md);
339 CERROR("cannot connect to %s: rc = %d\n", md, err);
343 sbi->ll_md_exp->exp_connect_data = *data;
345 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
346 LUSTRE_SEQ_METADATA);
348 CERROR("%s: Can't init metadata layer FID infrastructure, "
349 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
353 /* For mount, we only need fs info from MDT0, and also in DNE, it
354 * can make sure the client can be mounted as long as MDT0 is
356 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
357 ktime_get_seconds() - sbi->ll_statfs_max_age,
358 OBD_STATFS_FOR_MDT0);
360 GOTO(out_md_fid, err);
362 /* This needs to be after statfs to ensure connect has finished.
363 * Note that "data" does NOT contain the valid connect reply.
364 * If connecting to a 1.8 server there will be no LMV device, so
365 * we can access the MDC export directly and exp_connect_flags will
366 * be non-zero, but if accessing an upgraded 2.1 server it will
367 * have the correct flags filled in.
368 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
369 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
370 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
371 valid != CLIENT_CONNECT_MDT_REQD) {
374 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
375 obd_connect_flags2str(buf, PAGE_SIZE,
376 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
377 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
378 "feature(s) needed for correct operation "
379 "of this client (%s). Please upgrade "
380 "server or downgrade client.\n",
381 sbi->ll_md_exp->exp_obd->obd_name, buf);
382 OBD_FREE(buf, PAGE_SIZE);
383 GOTO(out_md_fid, err = -EPROTO);
386 size = sizeof(*data);
387 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
388 KEY_CONN_DATA, &size, data);
390 CERROR("%s: Get connect data failed: rc = %d\n",
391 sbi->ll_md_exp->exp_obd->obd_name, err);
392 GOTO(out_md_fid, err);
395 LASSERT(osfs->os_bsize);
396 sb->s_blocksize = osfs->os_bsize;
397 sb->s_blocksize_bits = log2(osfs->os_bsize);
398 sb->s_magic = LL_SUPER_MAGIC;
399 sb->s_maxbytes = MAX_LFS_FILESIZE;
400 sbi->ll_namelen = osfs->os_namelen;
401 sbi->ll_mnt.mnt = current->fs->root.mnt;
403 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
404 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
405 LCONSOLE_INFO("Disabling user_xattr feature because "
406 "it is not supported on the server\n");
407 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
410 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
412 sb->s_flags |= SB_POSIXACL;
414 sbi->ll_flags |= LL_SBI_ACL;
416 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
418 sb->s_flags &= ~SB_POSIXACL;
420 sbi->ll_flags &= ~LL_SBI_ACL;
423 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
424 sbi->ll_flags |= LL_SBI_64BIT_HASH;
426 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
427 sbi->ll_flags |= LL_SBI_LAYOUT_LOCK;
429 if (obd_connect_has_secctx(data))
430 sbi->ll_flags |= LL_SBI_FILE_SECCTX;
432 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
433 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
434 LCONSOLE_INFO("%s: disabling xattr cache due to "
435 "unknown maximum xattr size.\n", dt);
436 } else if (!sbi->ll_xattr_cache_set) {
437 /* If xattr_cache is already set (no matter 0 or 1)
438 * during processing llog, it won't be enabled here. */
439 sbi->ll_flags |= LL_SBI_XATTR_CACHE;
440 sbi->ll_xattr_cache_enabled = 1;
444 sbi->ll_dt_obd = class_name2obd(dt);
445 if (!sbi->ll_dt_obd) {
446 CERROR("DT %s: not setup or attached\n", dt);
447 GOTO(out_md_fid, err = -ENODEV);
450 /* pass client page size via ocd_grant_blkbits, the server should report
451 * back its backend blocksize for grant calculation purpose */
452 data->ocd_grant_blkbits = PAGE_SHIFT;
454 /* indicate OST features supported by this client */
455 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
456 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
457 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
458 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
459 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
460 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
461 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
462 OBD_CONNECT_EINPROGRESS |
463 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
464 OBD_CONNECT_LAYOUTLOCK |
465 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
466 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
467 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
468 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
469 OBD_CONNECT2_INC_XID;
471 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
472 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
474 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
475 * disabled by default, because it can still be enabled on the
476 * fly via /sys. As a consequence, we still need to come to an
477 * agreement on the supported algorithms at connect time
479 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
481 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
482 data->ocd_cksum_types = OBD_CKSUM_ADLER;
484 data->ocd_cksum_types = obd_cksum_types_supported_client();
486 #ifdef HAVE_LRU_RESIZE_SUPPORT
487 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
489 /* always ping even if server suppress_pings */
490 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
491 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
493 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
494 "ocd_grant: %d\n", data->ocd_connect_flags,
495 data->ocd_version, data->ocd_grant);
497 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
498 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
500 data->ocd_brw_size = DT_MAX_BRW_SIZE;
502 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
503 &sbi->ll_sb_uuid, data, sbi->ll_cache);
505 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
506 "recovery, of which this client is not a "
507 "part. Please wait for recovery to "
508 "complete, abort, or time out.\n", dt);
511 CERROR("%s: Cannot connect to %s: rc = %d\n",
512 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
516 sbi->ll_dt_exp->exp_connect_data = *data;
518 /* Don't change value if it was specified in the config log */
519 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
520 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
521 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
522 (data->ocd_brw_size >> PAGE_SHIFT));
523 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
524 sbi->ll_ra_info.ra_max_pages_per_file)
525 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
526 sbi->ll_ra_info.ra_max_pages_per_file;
529 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
530 LUSTRE_SEQ_METADATA);
532 CERROR("%s: Can't init data layer FID infrastructure, "
533 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
537 mutex_lock(&sbi->ll_lco.lco_lock);
538 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
539 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
540 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
541 mutex_unlock(&sbi->ll_lco.lco_lock);
543 fid_zero(&sbi->ll_root_fid);
544 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
547 CERROR("cannot mds_connect: rc = %d\n", err);
548 GOTO(out_lock_cn_cb, err);
550 if (!fid_is_sane(&sbi->ll_root_fid)) {
551 CERROR("%s: Invalid root fid "DFID" during mount\n",
552 sbi->ll_md_exp->exp_obd->obd_name,
553 PFID(&sbi->ll_root_fid));
554 GOTO(out_lock_cn_cb, err = -EINVAL);
556 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
558 sb->s_op = &lustre_super_operations;
559 sb->s_xattr = ll_xattr_handlers;
560 #if THREAD_SIZE >= 8192 /*b=17630*/
561 sb->s_export_op = &lustre_export_operations;
563 #ifdef HAVE_LUSTRE_CRYPTO
564 llcrypt_set_ops(sb, &lustre_cryptops);
568 * XXX: move this to after cbd setup? */
569 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
570 if (sbi->ll_flags & LL_SBI_ACL)
571 valid |= OBD_MD_FLACL;
573 OBD_ALLOC_PTR(op_data);
575 GOTO(out_lock_cn_cb, err = -ENOMEM);
577 op_data->op_fid1 = sbi->ll_root_fid;
578 op_data->op_mode = 0;
579 op_data->op_valid = valid;
581 err = md_getattr(sbi->ll_md_exp, op_data, &request);
583 OBD_FREE_PTR(op_data);
585 CERROR("%s: md_getattr failed for root: rc = %d\n",
586 sbi->ll_md_exp->exp_obd->obd_name, err);
587 GOTO(out_lock_cn_cb, err);
590 err = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
591 sbi->ll_md_exp, &lmd);
593 CERROR("failed to understand root inode md: rc = %d\n", err);
594 ptlrpc_req_finished(request);
595 GOTO(out_lock_cn_cb, err);
598 LASSERT(fid_is_sane(&sbi->ll_root_fid));
599 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid,
600 sbi->ll_flags & LL_SBI_32BIT_API),
602 md_free_lustre_md(sbi->ll_md_exp, &lmd);
603 ptlrpc_req_finished(request);
606 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
608 posix_acl_release(lmd.posix_acl);
609 lmd.posix_acl = NULL;
612 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
614 CERROR("%s: bad ll_iget() for root: rc = %d\n",
615 sbi->ll_fsname, err);
619 checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
620 if (sbi->ll_checksum_set) {
621 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
622 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
623 sizeof(checksum), &checksum, NULL);
625 CERROR("%s: Set checksum failed: rc = %d\n",
626 sbi->ll_dt_exp->exp_obd->obd_name, err);
632 sb->s_root = d_make_root(root);
633 if (sb->s_root == NULL) {
635 CERROR("%s: can't make root dentry: rc = %d\n",
636 sbi->ll_fsname, err);
640 sbi->ll_sdev_orig = sb->s_dev;
642 /* We set sb->s_dev equal on all lustre clients in order to support
643 * NFS export clustering. NFSD requires that the FSID be the same
645 /* s_dev is also used in lt_compare() to compare two fs, but that is
646 * only a node-local comparison. */
647 uuid = obd_get_uuid(sbi->ll_md_exp);
649 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
656 if (sbi->ll_dt_obd) {
657 err = sysfs_create_link(&sbi->ll_kset.kobj,
658 &sbi->ll_dt_obd->obd_kset.kobj,
659 sbi->ll_dt_obd->obd_type->typ_name);
661 CERROR("%s: could not register %s in llite: rc = %d\n",
662 dt, sbi->ll_fsname, err);
667 if (sbi->ll_md_obd) {
668 err = sysfs_create_link(&sbi->ll_kset.kobj,
669 &sbi->ll_md_obd->obd_kset.kobj,
670 sbi->ll_md_obd->obd_type->typ_name);
672 CERROR("%s: could not register %s in llite: rc = %d\n",
673 md, sbi->ll_fsname, err);
683 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
685 obd_disconnect(sbi->ll_dt_exp);
686 sbi->ll_dt_exp = NULL;
687 sbi->ll_dt_obd = NULL;
689 obd_fid_fini(sbi->ll_md_exp->exp_obd);
691 obd_disconnect(sbi->ll_md_exp);
692 sbi->ll_md_exp = NULL;
693 sbi->ll_md_obd = NULL;
702 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
706 size = sizeof(*lmmsize);
707 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
708 KEY_MAX_EASIZE, &size, lmmsize);
710 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
711 sbi->ll_dt_exp->exp_obd->obd_name, rc);
715 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
718 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
719 KEY_MAX_EASIZE, &size, lmmsize);
721 CERROR("Get max mdsize error rc %d\n", rc);
723 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
729 * Get the value of the default_easize parameter.
731 * \see client_obd::cl_default_mds_easize
733 * \param[in] sbi superblock info for this filesystem
734 * \param[out] lmmsize pointer to storage location for value
736 * \retval 0 on success
737 * \retval negative negated errno on failure
739 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
744 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
745 KEY_DEFAULT_EASIZE, &size, lmmsize);
747 CERROR("Get default mdsize error rc %d\n", rc);
753 * Set the default_easize parameter to the given value.
755 * \see client_obd::cl_default_mds_easize
757 * \param[in] sbi superblock info for this filesystem
758 * \param[in] lmmsize the size to set
760 * \retval 0 on success
761 * \retval negative negated errno on failure
763 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
767 if (lmmsize < sizeof(struct lov_mds_md) ||
768 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
771 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
772 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
773 sizeof(int), &lmmsize, NULL);
778 static void client_common_put_super(struct super_block *sb)
780 struct ll_sb_info *sbi = ll_s2sbi(sb);
785 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
786 obd_disconnect(sbi->ll_dt_exp);
787 sbi->ll_dt_exp = NULL;
789 ll_debugfs_unregister_super(sb);
791 obd_fid_fini(sbi->ll_md_exp->exp_obd);
792 obd_disconnect(sbi->ll_md_exp);
793 sbi->ll_md_exp = NULL;
798 void ll_kill_super(struct super_block *sb)
800 struct ll_sb_info *sbi;
804 if (!(sb->s_flags & SB_ACTIVE))
808 /* we need restore s_dev from changed for clustred NFS before put_super
809 * because new kernels have cached s_dev and change sb->s_dev in
810 * put_super not affected real removing devices */
812 sb->s_dev = sbi->ll_sdev_orig;
814 /* wait running statahead threads to quit */
815 while (atomic_read(&sbi->ll_sa_running) > 0)
816 schedule_timeout_uninterruptible(
817 cfs_time_seconds(1) >> 3);
823 static inline int ll_set_opt(const char *opt, char *data, int fl)
825 if (strncmp(opt, data, strlen(opt)) != 0)
831 /* non-client-specific mount options are parsed in lmd_parse */
832 static int ll_options(char *options, struct ll_sb_info *sbi)
835 char *s1 = options, *s2;
836 int *flags = &sbi->ll_flags;
842 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
845 CDEBUG(D_SUPER, "next opt=%s\n", s1);
846 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
851 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
853 *flags = (*flags & ~LL_SBI_LOCALFLOCK) | tmp;
856 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
858 *flags = (*flags & ~LL_SBI_FLOCK) | tmp;
861 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
866 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
871 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
876 tmp = ll_set_opt("context", s1, 1);
879 tmp = ll_set_opt("fscontext", s1, 1);
882 tmp = ll_set_opt("defcontext", s1, 1);
885 tmp = ll_set_opt("rootcontext", s1, 1);
888 tmp = ll_set_opt("user_fid2path", s1, LL_SBI_USER_FID2PATH);
893 tmp = ll_set_opt("nouser_fid2path", s1, LL_SBI_USER_FID2PATH);
899 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
902 sbi->ll_checksum_set = 1;
905 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
908 sbi->ll_checksum_set = 1;
911 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
916 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
921 tmp = ll_set_opt("lazystatfs", s1, LL_SBI_LAZYSTATFS);
926 tmp = ll_set_opt("nolazystatfs", s1, LL_SBI_LAZYSTATFS);
931 tmp = ll_set_opt("32bitapi", s1, LL_SBI_32BIT_API);
936 tmp = ll_set_opt("verbose", s1, LL_SBI_VERBOSE);
941 tmp = ll_set_opt("noverbose", s1, LL_SBI_VERBOSE);
946 tmp = ll_set_opt("always_ping", s1, LL_SBI_ALWAYS_PING);
951 tmp = ll_set_opt("test_dummy_encryption", s1,
952 LL_SBI_TEST_DUMMY_ENCRYPTION);
954 #ifdef HAVE_LUSTRE_CRYPTO
957 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
961 tmp = ll_set_opt("noencrypt", s1, LL_SBI_ENCRYPT);
963 #ifdef HAVE_LUSTRE_CRYPTO
966 LCONSOLE_WARN("noencrypt mount option ignored: encryption not supported\n");
970 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
976 s2 = strchr(s1, ',');
984 void ll_lli_init(struct ll_inode_info *lli)
986 lli->lli_inode_magic = LLI_INODE_MAGIC;
988 spin_lock_init(&lli->lli_lock);
989 lli->lli_posix_acl = NULL;
990 /* Do not set lli_fid, it has been initialized already. */
991 fid_zero(&lli->lli_pfid);
992 lli->lli_mds_read_och = NULL;
993 lli->lli_mds_write_och = NULL;
994 lli->lli_mds_exec_och = NULL;
995 lli->lli_open_fd_read_count = 0;
996 lli->lli_open_fd_write_count = 0;
997 lli->lli_open_fd_exec_count = 0;
998 mutex_init(&lli->lli_och_mutex);
999 spin_lock_init(&lli->lli_agl_lock);
1000 spin_lock_init(&lli->lli_layout_lock);
1001 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1002 lli->lli_clob = NULL;
1004 init_rwsem(&lli->lli_xattrs_list_rwsem);
1005 mutex_init(&lli->lli_xattrs_enq_lock);
1007 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1008 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1009 lli->lli_opendir_key = NULL;
1010 lli->lli_sai = NULL;
1011 spin_lock_init(&lli->lli_sa_lock);
1012 lli->lli_opendir_pid = 0;
1013 lli->lli_sa_enabled = 0;
1014 init_rwsem(&lli->lli_lsm_sem);
1016 mutex_init(&lli->lli_size_mutex);
1017 lli->lli_symlink_name = NULL;
1018 ll_trunc_sem_init(&lli->lli_trunc_sem);
1019 range_lock_tree_init(&lli->lli_write_tree);
1020 init_rwsem(&lli->lli_glimpse_sem);
1021 lli->lli_glimpse_time = ktime_set(0, 0);
1022 INIT_LIST_HEAD(&lli->lli_agl_list);
1023 lli->lli_agl_index = 0;
1024 lli->lli_async_rc = 0;
1025 spin_lock_init(&lli->lli_heat_lock);
1026 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1027 lli->lli_heat_flags = 0;
1028 mutex_init(&lli->lli_pcc_lock);
1029 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1030 lli->lli_pcc_inode = NULL;
1031 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1032 lli->lli_pcc_generation = 0;
1033 mutex_init(&lli->lli_group_mutex);
1034 lli->lli_group_users = 0;
1035 lli->lli_group_gid = 0;
1037 mutex_init(&lli->lli_layout_mutex);
1038 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1041 #define MAX_STRING_SIZE 128
1043 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1045 #define LSI_BDI_INITIALIZED 0x00400000
1047 #ifndef HAVE_BDI_CAP_MAP_COPY
1048 # define BDI_CAP_MAP_COPY 0
1051 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1053 struct lustre_sb_info *lsi = s2lsi(sb);
1054 char buf[MAX_STRING_SIZE];
1058 err = bdi_init(&lsi->lsi_bdi);
1062 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1063 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1064 lsi->lsi_bdi.name = "lustre";
1065 va_start(args, fmt);
1066 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1068 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1071 sb->s_bdi = &lsi->lsi_bdi;
1075 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1077 int ll_fill_super(struct super_block *sb)
1079 struct lustre_profile *lprof = NULL;
1080 struct lustre_sb_info *lsi = s2lsi(sb);
1081 struct ll_sb_info *sbi = NULL;
1082 char *dt = NULL, *md = NULL;
1083 char *profilenm = get_profile_name(sb);
1084 struct config_llog_instance *cfg;
1085 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1086 const int instlen = LUSTRE_MAXINSTANCE + 2;
1087 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1088 char name[MAX_STRING_SIZE];
1097 /* for ASLR, to map between cfg_instance and hashed ptr */
1098 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1099 profilenm, cfg_instance, sb);
1103 GOTO(out_free_cfg, err = -ENOMEM);
1105 /* client additional sb info */
1106 lsi->lsi_llsbi = sbi = ll_init_sbi();
1108 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1110 err = ll_options(lsi->lsi_lmd->lmd_opts, sbi);
1112 GOTO(out_free_cfg, err);
1114 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1115 sb->s_d_op = &ll_d_ops;
1118 generate_random_uuid(uuid.b);
1119 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1121 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1124 len = strlen(profilenm);
1125 ptr = strrchr(profilenm, '-');
1126 if (ptr && (strcmp(ptr, "-client") == 0))
1129 if (len > LUSTRE_MAXFSNAME) {
1130 if (unlikely(len >= MAX_STRING_SIZE))
1131 len = MAX_STRING_SIZE - 1;
1132 strncpy(name, profilenm, len);
1134 err = -ENAMETOOLONG;
1135 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1136 name, LUSTRE_MAXFSNAME, err);
1137 GOTO(out_free_cfg, err);
1139 strncpy(sbi->ll_fsname, profilenm, len);
1140 sbi->ll_fsname[len] = '\0';
1143 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1144 profilenm, cfg_instance);
1146 err = super_setup_bdi_name(sb, "%s", name);
1148 GOTO(out_free_cfg, err);
1150 /* Call ll_debugfs_register_super() before lustre_process_log()
1151 * so that "llite.*.*" params can be processed correctly.
1153 err = ll_debugfs_register_super(sb, name);
1155 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1156 sbi->ll_fsname, err);
1160 /* The cfg_instance is a value unique to this super, in case some
1161 * joker tries to mount the same fs at two mount points.
1163 cfg->cfg_instance = cfg_instance;
1164 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1165 cfg->cfg_callback = class_config_llog_handler;
1166 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1167 /* set up client obds */
1168 err = lustre_process_log(sb, profilenm, cfg);
1170 GOTO(out_debugfs, err);
1172 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1173 lprof = class_get_profile(profilenm);
1174 if (lprof == NULL) {
1175 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1176 " read from the MGS. Does that filesystem "
1177 "exist?\n", profilenm);
1178 GOTO(out_debugfs, err = -EINVAL);
1180 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1181 lprof->lp_md, lprof->lp_dt);
1183 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1184 OBD_ALLOC(dt, dt_len);
1186 GOTO(out_profile, err = -ENOMEM);
1187 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1189 md_len = strlen(lprof->lp_md) + instlen + 2;
1190 OBD_ALLOC(md, md_len);
1192 GOTO(out_free_dt, err = -ENOMEM);
1193 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1195 /* connections, registrations, sb setup */
1196 err = client_common_fill_super(sb, md, dt);
1198 GOTO(out_free_md, err);
1200 sbi->ll_client_common_fill_super_succeeded = 1;
1204 OBD_FREE(md, md_len);
1207 OBD_FREE(dt, dt_len);
1210 class_put_profile(lprof);
1213 ll_debugfs_unregister_super(sb);
1220 else if (sbi->ll_flags & LL_SBI_VERBOSE)
1221 LCONSOLE_WARN("Mounted %s\n", profilenm);
1223 } /* ll_fill_super */
1225 void ll_put_super(struct super_block *sb)
1227 struct config_llog_instance cfg, params_cfg;
1228 struct obd_device *obd;
1229 struct lustre_sb_info *lsi = s2lsi(sb);
1230 struct ll_sb_info *sbi = ll_s2sbi(sb);
1231 char *profilenm = get_profile_name(sb);
1232 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1234 int next, force = 1, rc = 0;
1238 GOTO(out_no_sbi, 0);
1240 /* Should replace instance_id with something better for ASLR */
1241 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1242 profilenm, cfg_instance, sb);
1244 cfg.cfg_instance = cfg_instance;
1245 lustre_end_log(sb, profilenm, &cfg);
1247 params_cfg.cfg_instance = cfg_instance;
1248 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1250 if (sbi->ll_md_exp) {
1251 obd = class_exp2obd(sbi->ll_md_exp);
1253 force = obd->obd_force;
1256 /* Wait for unstable pages to be committed to stable storage */
1258 rc = l_wait_event_abortable(
1259 sbi->ll_cache->ccc_unstable_waitq,
1260 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1263 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1264 if (force == 0 && rc != -ERESTARTSYS)
1265 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1267 /* We need to set force before the lov_disconnect in
1268 * lustre_common_put_super, since l_d cleans up osc's as well.
1272 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1274 obd->obd_force = force;
1278 if (sbi->ll_client_common_fill_super_succeeded) {
1279 /* Only if client_common_fill_super succeeded */
1280 client_common_put_super(sb);
1284 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1285 class_manual_cleanup(obd);
1287 if (sbi->ll_flags & LL_SBI_VERBOSE)
1288 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1291 class_del_profile(profilenm);
1293 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1294 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1295 bdi_destroy(&lsi->lsi_bdi);
1296 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1301 lsi->lsi_llsbi = NULL;
1303 lustre_common_put_super(sb);
1305 cl_env_cache_purge(~0);
1307 module_put(THIS_MODULE);
1310 } /* client_put_super */
1312 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1314 struct inode *inode = NULL;
1316 /* NOTE: we depend on atomic igrab() -bzzz */
1317 lock_res_and_lock(lock);
1318 if (lock->l_resource->lr_lvb_inode) {
1319 struct ll_inode_info * lli;
1320 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1321 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1322 inode = igrab(lock->l_resource->lr_lvb_inode);
1324 inode = lock->l_resource->lr_lvb_inode;
1325 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1326 D_WARNING, lock, "lr_lvb_inode %p is "
1327 "bogus: magic %08x",
1328 lock->l_resource->lr_lvb_inode,
1329 lli->lli_inode_magic);
1333 unlock_res_and_lock(lock);
1337 void ll_dir_clear_lsm_md(struct inode *inode)
1339 struct ll_inode_info *lli = ll_i2info(inode);
1341 LASSERT(S_ISDIR(inode->i_mode));
1343 if (lli->lli_lsm_md) {
1344 lmv_free_memmd(lli->lli_lsm_md);
1345 lli->lli_lsm_md = NULL;
1348 if (lli->lli_default_lsm_md) {
1349 lmv_free_memmd(lli->lli_default_lsm_md);
1350 lli->lli_default_lsm_md = NULL;
1354 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1355 const struct lu_fid *fid,
1356 struct lustre_md *md)
1358 struct ll_sb_info *sbi = ll_s2sbi(sb);
1359 struct mdt_body *body = md->body;
1360 struct inode *inode;
1364 ino = cl_fid_build_ino(fid, sbi->ll_flags & LL_SBI_32BIT_API);
1365 inode = iget_locked(sb, ino);
1366 if (inode == NULL) {
1367 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1368 sbi->ll_fsname, PFID(fid));
1369 RETURN(ERR_PTR(-ENOENT));
1372 if (inode->i_state & I_NEW) {
1373 struct ll_inode_info *lli = ll_i2info(inode);
1374 struct lmv_stripe_md *lsm = md->lmv;
1376 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1377 (body->mbo_mode & S_IFMT);
1378 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1381 inode->i_mtime.tv_sec = 0;
1382 inode->i_atime.tv_sec = 0;
1383 inode->i_ctime.tv_sec = 0;
1386 #ifdef HAVE_BACKING_DEV_INFO
1387 /* initializing backing dev info. */
1388 inode->i_mapping->backing_dev_info =
1389 &s2lsi(inode->i_sb)->lsi_bdi;
1391 inode->i_op = &ll_dir_inode_operations;
1392 inode->i_fop = &ll_dir_operations;
1393 lli->lli_fid = *fid;
1396 LASSERT(lsm != NULL);
1397 /* master object FID */
1398 lli->lli_pfid = body->mbo_fid1;
1399 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1400 lli, PFID(fid), PFID(&lli->lli_pfid));
1401 unlock_new_inode(inode);
1407 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1410 struct lmv_stripe_md *lsm = md->lmv;
1411 struct ll_inode_info *lli = ll_i2info(inode);
1414 LASSERT(lsm != NULL);
1416 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1417 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1418 lsm_md_dump(D_INODE, lsm);
1420 if (!lmv_dir_striped(lsm))
1423 /* XXX sigh, this lsm_root initialization should be in
1424 * LMV layer, but it needs ll_iget right now, so we
1425 * put this here right now. */
1426 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1427 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1428 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1430 if (!fid_is_sane(fid))
1433 /* Unfortunately ll_iget will call ll_update_inode,
1434 * where the initialization of slave inode is slightly
1435 * different, so it reset lsm_md to NULL to avoid
1436 * initializing lsm for slave inode. */
1437 lsm->lsm_md_oinfo[i].lmo_root =
1438 ll_iget_anon_dir(inode->i_sb, fid, md);
1439 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1440 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1442 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1444 iput(lsm->lsm_md_oinfo[i].lmo_root);
1445 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1451 lli->lli_lsm_md = lsm;
1456 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1458 struct ll_inode_info *lli = ll_i2info(inode);
1460 if (!md->default_lmv) {
1461 /* clear default lsm */
1462 if (lli->lli_default_lsm_md) {
1463 down_write(&lli->lli_lsm_sem);
1464 if (lli->lli_default_lsm_md) {
1465 lmv_free_memmd(lli->lli_default_lsm_md);
1466 lli->lli_default_lsm_md = NULL;
1468 up_write(&lli->lli_lsm_sem);
1470 } else if (lli->lli_default_lsm_md) {
1471 /* update default lsm if it changes */
1472 down_read(&lli->lli_lsm_sem);
1473 if (lli->lli_default_lsm_md &&
1474 !lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1475 up_read(&lli->lli_lsm_sem);
1476 down_write(&lli->lli_lsm_sem);
1477 if (lli->lli_default_lsm_md)
1478 lmv_free_memmd(lli->lli_default_lsm_md);
1479 lli->lli_default_lsm_md = md->default_lmv;
1480 lsm_md_dump(D_INODE, md->default_lmv);
1481 md->default_lmv = NULL;
1482 up_write(&lli->lli_lsm_sem);
1484 up_read(&lli->lli_lsm_sem);
1487 /* init default lsm */
1488 down_write(&lli->lli_lsm_sem);
1489 lli->lli_default_lsm_md = md->default_lmv;
1490 lsm_md_dump(D_INODE, md->default_lmv);
1491 md->default_lmv = NULL;
1492 up_write(&lli->lli_lsm_sem);
1496 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1498 struct ll_inode_info *lli = ll_i2info(inode);
1499 struct lmv_stripe_md *lsm = md->lmv;
1500 struct cl_attr *attr;
1505 LASSERT(S_ISDIR(inode->i_mode));
1506 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1507 PFID(ll_inode2fid(inode)));
1509 /* update default LMV */
1510 if (md->default_lmv)
1511 ll_update_default_lsm_md(inode, md);
1514 * no striped information from request, lustre_md from req does not
1515 * include stripeEA, see ll_md_setattr()
1521 * normally dir layout doesn't change, only take read lock to check
1522 * that to avoid blocking other MD operations.
1524 down_read(&lli->lli_lsm_sem);
1526 /* some current lookup initialized lsm, and unchanged */
1527 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1528 GOTO(unlock, rc = 0);
1530 /* if dir layout doesn't match, check whether version is increased,
1531 * which means layout is changed, this happens in dir split/merge and
1534 * foreign LMV should not change.
1536 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1537 lsm->lsm_md_layout_version <=
1538 lli->lli_lsm_md->lsm_md_layout_version) {
1539 CERROR("%s: "DFID" dir layout mismatch:\n",
1540 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1541 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1542 lsm_md_dump(D_ERROR, lsm);
1543 GOTO(unlock, rc = -EINVAL);
1546 up_read(&lli->lli_lsm_sem);
1547 down_write(&lli->lli_lsm_sem);
1548 /* clear existing lsm */
1549 if (lli->lli_lsm_md) {
1550 lmv_free_memmd(lli->lli_lsm_md);
1551 lli->lli_lsm_md = NULL;
1554 rc = ll_init_lsm_md(inode, md);
1555 up_write(&lli->lli_lsm_sem);
1560 /* set md->lmv to NULL, so the following free lustre_md will not free
1565 /* md_merge_attr() may take long, since lsm is already set, switch to
1568 down_read(&lli->lli_lsm_sem);
1570 if (!lmv_dir_striped(lli->lli_lsm_md))
1571 GOTO(unlock, rc = 0);
1573 OBD_ALLOC_PTR(attr);
1575 GOTO(unlock, rc = -ENOMEM);
1577 /* validate the lsm */
1578 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1579 ll_md_blocking_ast);
1581 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1582 md->body->mbo_nlink = attr->cat_nlink;
1583 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1584 md->body->mbo_size = attr->cat_size;
1585 if (md->body->mbo_valid & OBD_MD_FLATIME)
1586 md->body->mbo_atime = attr->cat_atime;
1587 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1588 md->body->mbo_ctime = attr->cat_ctime;
1589 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1590 md->body->mbo_mtime = attr->cat_mtime;
1596 up_read(&lli->lli_lsm_sem);
1601 void ll_clear_inode(struct inode *inode)
1603 struct ll_inode_info *lli = ll_i2info(inode);
1604 struct ll_sb_info *sbi = ll_i2sbi(inode);
1608 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1609 PFID(ll_inode2fid(inode)), inode);
1611 if (S_ISDIR(inode->i_mode)) {
1612 /* these should have been cleared in ll_file_release */
1613 LASSERT(lli->lli_opendir_key == NULL);
1614 LASSERT(lli->lli_sai == NULL);
1615 LASSERT(lli->lli_opendir_pid == 0);
1617 pcc_inode_free(inode);
1620 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1622 LASSERT(!lli->lli_open_fd_write_count);
1623 LASSERT(!lli->lli_open_fd_read_count);
1624 LASSERT(!lli->lli_open_fd_exec_count);
1626 if (lli->lli_mds_write_och)
1627 ll_md_real_close(inode, FMODE_WRITE);
1628 if (lli->lli_mds_exec_och)
1629 ll_md_real_close(inode, FMODE_EXEC);
1630 if (lli->lli_mds_read_och)
1631 ll_md_real_close(inode, FMODE_READ);
1633 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1634 OBD_FREE(lli->lli_symlink_name,
1635 strlen(lli->lli_symlink_name) + 1);
1636 lli->lli_symlink_name = NULL;
1639 ll_xattr_cache_destroy(inode);
1641 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
1642 forget_all_cached_acls(inode);
1643 if (lli->lli_posix_acl) {
1644 posix_acl_release(lli->lli_posix_acl);
1645 lli->lli_posix_acl = NULL;
1648 lli->lli_inode_magic = LLI_INODE_DEAD;
1650 if (S_ISDIR(inode->i_mode))
1651 ll_dir_clear_lsm_md(inode);
1652 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1653 LASSERT(list_empty(&lli->lli_agl_list));
1656 * XXX This has to be done before lsm is freed below, because
1657 * cl_object still uses inode lsm.
1659 cl_inode_fini(inode);
1661 llcrypt_put_encryption_info(inode);
1666 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1668 struct lustre_md md;
1669 struct inode *inode = dentry->d_inode;
1670 struct ll_sb_info *sbi = ll_i2sbi(inode);
1671 struct ptlrpc_request *request = NULL;
1675 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1676 LUSTRE_OPC_ANY, NULL);
1677 if (IS_ERR(op_data))
1678 RETURN(PTR_ERR(op_data));
1680 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1682 ptlrpc_req_finished(request);
1683 if (rc == -ENOENT) {
1685 /* Unlinked special device node? Or just a race?
1686 * Pretend we done everything. */
1687 if (!S_ISREG(inode->i_mode) &&
1688 !S_ISDIR(inode->i_mode)) {
1689 ia_valid = op_data->op_attr.ia_valid;
1690 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1691 rc = simple_setattr(dentry, &op_data->op_attr);
1692 op_data->op_attr.ia_valid = ia_valid;
1694 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1695 CERROR("md_setattr fails: rc = %d\n", rc);
1700 rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
1701 sbi->ll_md_exp, &md);
1703 ptlrpc_req_finished(request);
1707 ia_valid = op_data->op_attr.ia_valid;
1708 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1709 * cache is not cleared yet. */
1710 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1711 if (S_ISREG(inode->i_mode))
1713 rc = simple_setattr(dentry, &op_data->op_attr);
1714 if (S_ISREG(inode->i_mode))
1715 inode_unlock(inode);
1716 op_data->op_attr.ia_valid = ia_valid;
1718 rc = ll_update_inode(inode, &md);
1719 ptlrpc_req_finished(request);
1724 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1725 * object(s) determine the file size and mtime. Otherwise, the MDS will
1726 * keep these values until such a time that objects are allocated for it.
1727 * We do the MDS operations first, as it is checking permissions for us.
1728 * We don't to the MDS RPC if there is nothing that we want to store there,
1729 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1730 * going to do an RPC anyways.
1732 * If we are doing a truncate, we will send the mtime and ctime updates
1733 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1734 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1737 * In case of HSMimport, we only set attr on MDS.
1739 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
1740 enum op_xvalid xvalid, bool hsm_import)
1742 struct inode *inode = dentry->d_inode;
1743 struct ll_inode_info *lli = ll_i2info(inode);
1744 struct md_op_data *op_data = NULL;
1745 ktime_t kstart = ktime_get();
1750 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
1751 "valid %x, hsm_import %d\n",
1752 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
1753 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
1756 if (attr->ia_valid & ATTR_SIZE) {
1757 /* Check new size against VFS/VM file size limit and rlimit */
1758 rc = inode_newsize_ok(inode, attr->ia_size);
1762 /* The maximum Lustre file size is variable, based on the
1763 * OST maximum object size and number of stripes. This
1764 * needs another check in addition to the VFS check above. */
1765 if (attr->ia_size > ll_file_maxbytes(inode)) {
1766 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
1767 PFID(&lli->lli_fid), attr->ia_size,
1768 ll_file_maxbytes(inode));
1772 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1775 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1776 if (attr->ia_valid & TIMES_SET_FLAGS) {
1777 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
1778 !cfs_capable(CFS_CAP_FOWNER))
1782 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1783 if (!(xvalid & OP_XVALID_CTIME_SET) &&
1784 (attr->ia_valid & ATTR_CTIME)) {
1785 attr->ia_ctime = current_time(inode);
1786 xvalid |= OP_XVALID_CTIME_SET;
1788 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
1789 (attr->ia_valid & ATTR_ATIME)) {
1790 attr->ia_atime = current_time(inode);
1791 attr->ia_valid |= ATTR_ATIME_SET;
1793 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
1794 (attr->ia_valid & ATTR_MTIME)) {
1795 attr->ia_mtime = current_time(inode);
1796 attr->ia_valid |= ATTR_MTIME_SET;
1799 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1800 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
1801 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
1802 ktime_get_real_seconds());
1804 if (S_ISREG(inode->i_mode))
1805 inode_unlock(inode);
1807 /* We always do an MDS RPC, even if we're only changing the size;
1808 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
1810 OBD_ALLOC_PTR(op_data);
1811 if (op_data == NULL)
1812 GOTO(out, rc = -ENOMEM);
1814 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
1815 /* If we are changing file size, file content is
1816 * modified, flag it.
1818 xvalid |= OP_XVALID_OWNEROVERRIDE;
1819 op_data->op_bias |= MDS_DATA_MODIFIED;
1820 ll_file_clear_flag(lli, LLIF_DATA_MODIFIED);
1823 if (attr->ia_valid & ATTR_FILE) {
1824 struct ll_file_data *fd = attr->ia_file->private_data;
1826 if (fd->fd_lease_och)
1827 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
1830 op_data->op_attr = *attr;
1831 op_data->op_xvalid = xvalid;
1833 rc = ll_md_setattr(dentry, op_data);
1837 if (!S_ISREG(inode->i_mode) || hsm_import)
1840 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
1841 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
1842 xvalid & OP_XVALID_CTIME_SET) {
1843 bool cached = false;
1845 rc = pcc_inode_setattr(inode, attr, &cached);
1848 CERROR("%s: PCC inode "DFID" setattr failed: "
1850 ll_i2sbi(inode)->ll_fsname,
1851 PFID(&lli->lli_fid), rc);
1855 /* For truncate and utimes sending attributes to OSTs,
1856 * setting mtime/atime to the past will be performed
1857 * under PW [0:EOF] extent lock (new_size:EOF for
1858 * truncate). It may seem excessive to send mtime/atime
1859 * updates to OSTs when not setting times to past, but
1860 * it is necessary due to possible time
1861 * de-synchronization between MDT inode and OST objects
1863 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, 0);
1867 /* If the file was restored, it needs to set dirty flag.
1869 * We've already sent MDS_DATA_MODIFIED flag in
1870 * ll_md_setattr() for truncate. However, the MDT refuses to
1871 * set the HS_DIRTY flag on released files, so we have to set
1872 * it again if the file has been restored. Please check how
1873 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
1875 * Please notice that if the file is not released, the previous
1876 * MDS_DATA_MODIFIED has taken effect and usually
1877 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
1878 * This way we can save an RPC for common open + trunc
1880 if (ll_file_test_and_clear_flag(lli, LLIF_DATA_MODIFIED)) {
1881 struct hsm_state_set hss = {
1882 .hss_valid = HSS_SETMASK,
1883 .hss_setmask = HS_DIRTY,
1887 rc2 = ll_hsm_state_set(inode, &hss);
1888 /* truncate and write can happen at the same time, so that
1889 * the file can be set modified even though the file is not
1890 * restored from released state, and ll_hsm_state_set() is
1891 * not applicable for the file, and rc2 < 0 is normal in this
1894 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
1895 PFID(ll_inode2fid(inode)), rc2);
1900 if (op_data != NULL)
1901 ll_finish_md_op_data(op_data);
1903 if (S_ISREG(inode->i_mode)) {
1905 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
1906 inode_dio_wait(inode);
1907 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
1908 * flag. ll_update_inode (called from ll_md_setattr), clears
1909 * inode flags, so there is a gap where S_NOSEC is not set.
1910 * This can cause a writer to take the i_mutex unnecessarily,
1911 * but this is safe to do and should be rare. */
1912 inode_has_no_xattr(inode);
1916 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
1917 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
1918 ktime_us_delta(ktime_get(), kstart));
1923 int ll_setattr(struct dentry *de, struct iattr *attr)
1925 int mode = de->d_inode->i_mode;
1926 enum op_xvalid xvalid = 0;
1928 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1929 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1930 xvalid |= OP_XVALID_OWNEROVERRIDE;
1932 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
1933 (ATTR_SIZE|ATTR_MODE)) &&
1934 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
1935 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
1936 !(attr->ia_mode & S_ISGID))))
1937 attr->ia_valid |= ATTR_FORCE;
1939 if ((attr->ia_valid & ATTR_MODE) &&
1941 !(attr->ia_mode & S_ISUID) &&
1942 !(attr->ia_valid & ATTR_KILL_SUID))
1943 attr->ia_valid |= ATTR_KILL_SUID;
1945 if ((attr->ia_valid & ATTR_MODE) &&
1946 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
1947 !(attr->ia_mode & S_ISGID) &&
1948 !(attr->ia_valid & ATTR_KILL_SGID))
1949 attr->ia_valid |= ATTR_KILL_SGID;
1951 return ll_setattr_raw(de, attr, xvalid, false);
1954 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
1957 struct obd_statfs obd_osfs = { 0 };
1962 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
1964 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
1965 flags |= OBD_STATFS_NODELAY;
1967 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
1971 osfs->os_type = LL_SUPER_MAGIC;
1973 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
1974 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
1976 if (osfs->os_state & OS_STATE_SUM)
1979 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
1980 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
1983 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
1984 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1987 osfs->os_bsize = obd_osfs.os_bsize;
1988 osfs->os_blocks = obd_osfs.os_blocks;
1989 osfs->os_bfree = obd_osfs.os_bfree;
1990 osfs->os_bavail = obd_osfs.os_bavail;
1992 /* If we have _some_ OSTs, but don't have as many free objects on the
1993 * OSTs as inodes on the MDTs, reduce the reported number of inodes
1994 * to compensate, so that the "inodes in use" number is correct.
1995 * This should be kept in sync with lod_statfs() behaviour.
1997 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
1998 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2000 osfs->os_ffree = obd_osfs.os_ffree;
2007 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2009 struct super_block *sb = de->d_sb;
2010 struct obd_statfs osfs;
2011 __u64 fsid = huge_encode_dev(sb->s_dev);
2012 ktime_t kstart = ktime_get();
2015 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2017 /* Some amount of caching on the client is allowed */
2018 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2022 statfs_unpack(sfs, &osfs);
2024 /* We need to downshift for all 32-bit kernels, because we can't
2025 * tell if the kernel is being called via sys_statfs64() or not.
2026 * Stop before overflowing f_bsize - in which case it is better
2027 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2028 if (sizeof(long) < 8) {
2029 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2032 osfs.os_blocks >>= 1;
2033 osfs.os_bfree >>= 1;
2034 osfs.os_bavail >>= 1;
2038 sfs->f_blocks = osfs.os_blocks;
2039 sfs->f_bfree = osfs.os_bfree;
2040 sfs->f_bavail = osfs.os_bavail;
2041 sfs->f_fsid.val[0] = (__u32)fsid;
2042 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2044 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2045 ktime_us_delta(ktime_get(), kstart));
2050 void ll_inode_size_lock(struct inode *inode)
2052 struct ll_inode_info *lli;
2054 LASSERT(!S_ISDIR(inode->i_mode));
2056 lli = ll_i2info(inode);
2057 mutex_lock(&lli->lli_size_mutex);
2060 void ll_inode_size_unlock(struct inode *inode)
2062 struct ll_inode_info *lli;
2064 lli = ll_i2info(inode);
2065 mutex_unlock(&lli->lli_size_mutex);
2068 void ll_update_inode_flags(struct inode *inode, int ext_flags)
2070 /* do not clear encryption flag */
2071 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2072 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2073 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2074 ll_file_set_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
2076 ll_file_clear_flag(ll_i2info(inode), LLIF_PROJECT_INHERIT);
2079 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2081 struct ll_inode_info *lli = ll_i2info(inode);
2082 struct mdt_body *body = md->body;
2083 struct ll_sb_info *sbi = ll_i2sbi(inode);
2086 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2087 rc = cl_file_inode_init(inode, md);
2092 if (S_ISDIR(inode->i_mode)) {
2093 rc = ll_update_lsm_md(inode, md);
2098 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
2099 if (body->mbo_valid & OBD_MD_FLACL) {
2100 spin_lock(&lli->lli_lock);
2101 if (lli->lli_posix_acl)
2102 posix_acl_release(lli->lli_posix_acl);
2103 lli->lli_posix_acl = md->posix_acl;
2104 spin_unlock(&lli->lli_lock);
2107 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1,
2108 sbi->ll_flags & LL_SBI_32BIT_API);
2109 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2111 if (body->mbo_valid & OBD_MD_FLATIME) {
2112 if (body->mbo_atime > inode->i_atime.tv_sec)
2113 inode->i_atime.tv_sec = body->mbo_atime;
2114 lli->lli_atime = body->mbo_atime;
2117 if (body->mbo_valid & OBD_MD_FLMTIME) {
2118 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2120 "setting ino %lu mtime from %lld to %llu\n",
2121 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2123 inode->i_mtime.tv_sec = body->mbo_mtime;
2125 lli->lli_mtime = body->mbo_mtime;
2128 if (body->mbo_valid & OBD_MD_FLCTIME) {
2129 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2130 inode->i_ctime.tv_sec = body->mbo_ctime;
2131 lli->lli_ctime = body->mbo_ctime;
2134 if (body->mbo_valid & OBD_MD_FLBTIME)
2135 lli->lli_btime = body->mbo_btime;
2137 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2138 if (body->mbo_valid & OBD_MD_FLFLAGS)
2139 ll_update_inode_flags(inode, body->mbo_flags);
2140 if (body->mbo_valid & OBD_MD_FLMODE)
2141 inode->i_mode = (inode->i_mode & S_IFMT) |
2142 (body->mbo_mode & ~S_IFMT);
2144 if (body->mbo_valid & OBD_MD_FLTYPE)
2145 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2146 (body->mbo_mode & S_IFMT);
2148 LASSERT(inode->i_mode != 0);
2149 if (body->mbo_valid & OBD_MD_FLUID)
2150 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2151 if (body->mbo_valid & OBD_MD_FLGID)
2152 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2153 if (body->mbo_valid & OBD_MD_FLPROJID)
2154 lli->lli_projid = body->mbo_projid;
2155 if (body->mbo_valid & OBD_MD_FLNLINK)
2156 set_nlink(inode, body->mbo_nlink);
2157 if (body->mbo_valid & OBD_MD_FLRDEV)
2158 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2160 if (body->mbo_valid & OBD_MD_FLID) {
2161 /* FID shouldn't be changed! */
2162 if (fid_is_sane(&lli->lli_fid)) {
2163 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2164 "Trying to change FID "DFID
2165 " to the "DFID", inode "DFID"(%p)\n",
2166 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2167 PFID(ll_inode2fid(inode)), inode);
2169 lli->lli_fid = body->mbo_fid1;
2173 LASSERT(fid_seq(&lli->lli_fid) != 0);
2175 lli->lli_attr_valid = body->mbo_valid;
2176 if (body->mbo_valid & OBD_MD_FLSIZE) {
2177 i_size_write(inode, body->mbo_size);
2179 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2180 PFID(ll_inode2fid(inode)),
2181 (unsigned long long)body->mbo_size);
2183 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2184 inode->i_blocks = body->mbo_blocks;
2186 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2187 lli->lli_lazysize = body->mbo_size;
2188 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2189 lli->lli_lazyblocks = body->mbo_blocks;
2192 if (body->mbo_valid & OBD_MD_TSTATE) {
2193 /* Set LLIF_FILE_RESTORING if restore ongoing and
2194 * clear it when done to ensure to start again
2195 * glimpsing updated attrs
2197 if (body->mbo_t_state & MS_RESTORE)
2198 ll_file_set_flag(lli, LLIF_FILE_RESTORING);
2200 ll_file_clear_flag(lli, LLIF_FILE_RESTORING);
2206 int ll_read_inode2(struct inode *inode, void *opaque)
2208 struct lustre_md *md = opaque;
2209 struct ll_inode_info *lli = ll_i2info(inode);
2213 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2214 PFID(&lli->lli_fid), inode);
2216 /* Core attributes from the MDS first. This is a new inode, and
2217 * the VFS doesn't zero times in the core inode so we have to do
2218 * it ourselves. They will be overwritten by either MDS or OST
2219 * attributes - we just need to make sure they aren't newer.
2221 inode->i_mtime.tv_sec = 0;
2222 inode->i_atime.tv_sec = 0;
2223 inode->i_ctime.tv_sec = 0;
2225 rc = ll_update_inode(inode, md);
2229 /* OIDEBUG(inode); */
2231 #ifdef HAVE_BACKING_DEV_INFO
2232 /* initializing backing dev info. */
2233 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2235 if (S_ISREG(inode->i_mode)) {
2236 struct ll_sb_info *sbi = ll_i2sbi(inode);
2237 inode->i_op = &ll_file_inode_operations;
2238 inode->i_fop = sbi->ll_fop;
2239 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2241 } else if (S_ISDIR(inode->i_mode)) {
2242 inode->i_op = &ll_dir_inode_operations;
2243 inode->i_fop = &ll_dir_operations;
2245 } else if (S_ISLNK(inode->i_mode)) {
2246 inode->i_op = &ll_fast_symlink_inode_operations;
2249 inode->i_op = &ll_special_inode_operations;
2251 init_special_inode(inode, inode->i_mode,
2260 void ll_delete_inode(struct inode *inode)
2262 struct ll_inode_info *lli = ll_i2info(inode);
2263 struct address_space *mapping = &inode->i_data;
2264 unsigned long nrpages;
2265 unsigned long flags;
2269 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2270 /* It is last chance to write out dirty pages,
2271 * otherwise we may lose data while umount.
2273 * If i_nlink is 0 then just discard data. This is safe because
2274 * local inode gets i_nlink 0 from server only for the last
2275 * unlink, so that file is not opened somewhere else
2277 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2278 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2280 truncate_inode_pages_final(mapping);
2282 /* Workaround for LU-118: Note nrpages may not be totally updated when
2283 * truncate_inode_pages() returns, as there can be a page in the process
2284 * of deletion (inside __delete_from_page_cache()) in the specified
2285 * range. Thus mapping->nrpages can be non-zero when this function
2286 * returns even after truncation of the whole mapping. Only do this if
2287 * npages isn't already zero.
2289 nrpages = mapping->nrpages;
2291 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2292 nrpages = mapping->nrpages;
2293 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2294 } /* Workaround end */
2296 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, "
2297 "see https://jira.whamcloud.com/browse/LU-118\n",
2298 ll_i2sbi(inode)->ll_fsname,
2299 PFID(ll_inode2fid(inode)), inode, nrpages);
2301 ll_clear_inode(inode);
2307 int ll_iocontrol(struct inode *inode, struct file *file,
2308 unsigned int cmd, unsigned long arg)
2310 struct ll_sb_info *sbi = ll_i2sbi(inode);
2311 struct ptlrpc_request *req = NULL;
2316 case FS_IOC_GETFLAGS: {
2317 struct mdt_body *body;
2318 struct md_op_data *op_data;
2320 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2321 0, 0, LUSTRE_OPC_ANY,
2323 if (IS_ERR(op_data))
2324 RETURN(PTR_ERR(op_data));
2326 op_data->op_valid = OBD_MD_FLFLAGS;
2327 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2328 ll_finish_md_op_data(op_data);
2330 CERROR("%s: failure inode "DFID": rc = %d\n",
2331 sbi->ll_md_exp->exp_obd->obd_name,
2332 PFID(ll_inode2fid(inode)), rc);
2336 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2338 flags = body->mbo_flags;
2340 ptlrpc_req_finished(req);
2342 RETURN(put_user(flags, (int __user *)arg));
2344 case FS_IOC_SETFLAGS: {
2346 struct md_op_data *op_data;
2347 struct cl_object *obj;
2348 struct fsxattr fa = { 0 };
2350 if (get_user(flags, (int __user *)arg))
2353 fa.fsx_projid = ll_i2info(inode)->lli_projid;
2354 if (flags & LUSTRE_PROJINHERIT_FL)
2355 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
2357 rc = ll_ioctl_check_project(inode, &fa);
2361 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
2362 LUSTRE_OPC_ANY, NULL);
2363 if (IS_ERR(op_data))
2364 RETURN(PTR_ERR(op_data));
2366 op_data->op_attr_flags = flags;
2367 op_data->op_xvalid |= OP_XVALID_FLAGS;
2368 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
2369 ll_finish_md_op_data(op_data);
2370 ptlrpc_req_finished(req);
2374 ll_update_inode_flags(inode, flags);
2376 obj = ll_i2info(inode)->lli_clob;
2380 OBD_ALLOC_PTR(attr);
2384 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
2396 int ll_flush_ctx(struct inode *inode)
2398 struct ll_sb_info *sbi = ll_i2sbi(inode);
2400 CDEBUG(D_SEC, "flush context for user %d\n",
2401 from_kuid(&init_user_ns, current_uid()));
2403 obd_set_info_async(NULL, sbi->ll_md_exp,
2404 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2406 obd_set_info_async(NULL, sbi->ll_dt_exp,
2407 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2412 /* umount -f client means force down, don't save state */
2413 void ll_umount_begin(struct super_block *sb)
2415 struct ll_sb_info *sbi = ll_s2sbi(sb);
2416 struct obd_device *obd;
2417 struct obd_ioctl_data *ioc_data;
2421 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2422 sb->s_count, atomic_read(&sb->s_active));
2424 obd = class_exp2obd(sbi->ll_md_exp);
2426 CERROR("Invalid MDC connection handle %#llx\n",
2427 sbi->ll_md_exp->exp_handle.h_cookie);
2433 obd = class_exp2obd(sbi->ll_dt_exp);
2435 CERROR("Invalid LOV connection handle %#llx\n",
2436 sbi->ll_dt_exp->exp_handle.h_cookie);
2442 OBD_ALLOC_PTR(ioc_data);
2444 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2445 sizeof *ioc_data, ioc_data, NULL);
2447 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2448 sizeof *ioc_data, ioc_data, NULL);
2450 OBD_FREE_PTR(ioc_data);
2453 /* Really, we'd like to wait until there are no requests outstanding,
2454 * and then continue. For now, we just periodically checking for vfs
2455 * to decrement mnt_cnt and hope to finish it within 10sec.
2459 !may_umount(sbi->ll_mnt.mnt)) {
2467 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2469 struct ll_sb_info *sbi = ll_s2sbi(sb);
2470 char *profilenm = get_profile_name(sb);
2474 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
2475 read_only = *flags & MS_RDONLY;
2476 err = obd_set_info_async(NULL, sbi->ll_md_exp,
2477 sizeof(KEY_READ_ONLY),
2478 KEY_READ_ONLY, sizeof(read_only),
2481 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2482 profilenm, read_only ?
2483 "read-only" : "read-write", err);
2488 sb->s_flags |= SB_RDONLY;
2490 sb->s_flags &= ~SB_RDONLY;
2492 if (sbi->ll_flags & LL_SBI_VERBOSE)
2493 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
2494 read_only ? "read-only" : "read-write");
2500 * Cleanup the open handle that is cached on MDT-side.
2502 * For open case, the client side open handling thread may hit error
2503 * after the MDT grant the open. Under such case, the client should
2504 * send close RPC to the MDT as cleanup; otherwise, the open handle
2505 * on the MDT will be leaked there until the client umount or evicted.
2507 * In further, if someone unlinked the file, because the open handle
2508 * holds the reference on such file/object, then it will block the
2509 * subsequent threads that want to locate such object via FID.
2511 * \param[in] sb super block for this file-system
2512 * \param[in] open_req pointer to the original open request
2514 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
2516 struct mdt_body *body;
2517 struct md_op_data *op_data;
2518 struct ptlrpc_request *close_req = NULL;
2519 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
2522 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
2523 OBD_ALLOC_PTR(op_data);
2524 if (op_data == NULL) {
2525 CWARN("%s: cannot allocate op_data to release open handle for "
2526 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
2531 op_data->op_fid1 = body->mbo_fid1;
2532 op_data->op_open_handle = body->mbo_open_handle;
2533 op_data->op_mod_time = ktime_get_real_seconds();
2534 md_close(exp, op_data, NULL, &close_req);
2535 ptlrpc_req_finished(close_req);
2536 ll_finish_md_op_data(op_data);
2541 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
2542 struct super_block *sb, struct lookup_intent *it)
2544 struct ll_sb_info *sbi = NULL;
2545 struct lustre_md md = { NULL };
2546 bool default_lmv_deleted = false;
2551 LASSERT(*inode || sb);
2552 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2553 rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
2554 sbi->ll_md_exp, &md);
2559 * clear default_lmv only if intent_getattr reply doesn't contain it.
2560 * but it needs to be done after iget, check this early because
2561 * ll_update_lsm_md() may change md.
2563 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
2564 S_ISDIR(md.body->mbo_mode) && !md.default_lmv)
2565 default_lmv_deleted = true;
2568 rc = ll_update_inode(*inode, &md);
2572 LASSERT(sb != NULL);
2575 * At this point server returns to client's same fid as client
2576 * generated for creating. So using ->fid1 is okay here.
2578 if (!fid_is_sane(&md.body->mbo_fid1)) {
2579 CERROR("%s: Fid is insane "DFID"\n",
2581 PFID(&md.body->mbo_fid1));
2582 GOTO(out, rc = -EINVAL);
2585 *inode = ll_iget(sb, cl_fid_build_ino(&md.body->mbo_fid1,
2586 sbi->ll_flags & LL_SBI_32BIT_API),
2588 if (IS_ERR(*inode)) {
2589 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
2591 posix_acl_release(md.posix_acl);
2592 md.posix_acl = NULL;
2595 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
2597 CERROR("new_inode -fatal: rc %d\n", rc);
2602 /* Handling piggyback layout lock.
2603 * Layout lock can be piggybacked by getattr and open request.
2604 * The lsm can be applied to inode only if it comes with a layout lock
2605 * otherwise correct layout may be overwritten, for example:
2606 * 1. proc1: mdt returns a lsm but not granting layout
2607 * 2. layout was changed by another client
2608 * 3. proc2: refresh layout and layout lock granted
2609 * 4. proc1: to apply a stale layout */
2610 if (it != NULL && it->it_lock_mode != 0) {
2611 struct lustre_handle lockh;
2612 struct ldlm_lock *lock;
2614 lockh.cookie = it->it_lock_handle;
2615 lock = ldlm_handle2lock(&lockh);
2616 LASSERT(lock != NULL);
2617 if (ldlm_has_layout(lock)) {
2618 struct cl_object_conf conf;
2620 memset(&conf, 0, sizeof(conf));
2621 conf.coc_opc = OBJECT_CONF_SET;
2622 conf.coc_inode = *inode;
2623 conf.coc_lock = lock;
2624 conf.u.coc_layout = md.layout;
2625 (void)ll_layout_conf(*inode, &conf);
2627 LDLM_LOCK_PUT(lock);
2630 if (default_lmv_deleted)
2631 ll_update_default_lsm_md(*inode, &md);
2636 /* cleanup will be done if necessary */
2637 md_free_lustre_md(sbi->ll_md_exp, &md);
2639 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
2640 ll_intent_drop_lock(it);
2641 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, req);
2647 int ll_obd_statfs(struct inode *inode, void __user *arg)
2649 struct ll_sb_info *sbi = NULL;
2650 struct obd_export *exp;
2652 struct obd_ioctl_data *data = NULL;
2656 if (!inode || !(sbi = ll_i2sbi(inode)))
2657 GOTO(out_statfs, rc = -EINVAL);
2659 rc = obd_ioctl_getdata(&buf, &len, arg);
2661 GOTO(out_statfs, rc);
2664 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2665 !data->ioc_pbuf1 || !data->ioc_pbuf2)
2666 GOTO(out_statfs, rc = -EINVAL);
2668 if (data->ioc_inllen1 != sizeof(__u32) ||
2669 data->ioc_inllen2 != sizeof(__u32) ||
2670 data->ioc_plen1 != sizeof(struct obd_statfs) ||
2671 data->ioc_plen2 != sizeof(struct obd_uuid))
2672 GOTO(out_statfs, rc = -EINVAL);
2674 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2675 if (type & LL_STATFS_LMV)
2676 exp = sbi->ll_md_exp;
2677 else if (type & LL_STATFS_LOV)
2678 exp = sbi->ll_dt_exp;
2680 GOTO(out_statfs, rc = -ENODEV);
2682 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL);
2684 GOTO(out_statfs, rc);
2686 OBD_FREE_LARGE(buf, len);
2691 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
2692 * be called early to avoid deadlock.
2694 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
2696 if (op_data->op_mea2_sem) {
2697 up_read(op_data->op_mea2_sem);
2698 op_data->op_mea2_sem = NULL;
2701 if (op_data->op_mea1_sem) {
2702 up_read(op_data->op_mea1_sem);
2703 op_data->op_mea1_sem = NULL;
2707 /* this function prepares md_op_data hint for passing it down to MD stack. */
2708 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
2709 struct inode *i1, struct inode *i2,
2710 const char *name, size_t namelen,
2711 __u32 mode, enum md_op_code opc,
2714 LASSERT(i1 != NULL);
2717 /* Do not reuse namelen for something else. */
2719 return ERR_PTR(-EINVAL);
2721 if (namelen > ll_i2sbi(i1)->ll_namelen)
2722 return ERR_PTR(-ENAMETOOLONG);
2724 if (!lu_name_is_valid_2(name, namelen))
2725 return ERR_PTR(-EINVAL);
2728 if (op_data == NULL)
2729 OBD_ALLOC_PTR(op_data);
2731 if (op_data == NULL)
2732 return ERR_PTR(-ENOMEM);
2734 ll_i2gids(op_data->op_suppgids, i1, i2);
2735 op_data->op_fid1 = *ll_inode2fid(i1);
2736 op_data->op_code = opc;
2738 if (S_ISDIR(i1->i_mode)) {
2739 down_read(&ll_i2info(i1)->lli_lsm_sem);
2740 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
2741 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
2742 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
2746 op_data->op_fid2 = *ll_inode2fid(i2);
2747 if (S_ISDIR(i2->i_mode)) {
2749 down_read(&ll_i2info(i2)->lli_lsm_sem);
2750 op_data->op_mea2_sem =
2751 &ll_i2info(i2)->lli_lsm_sem;
2753 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
2756 fid_zero(&op_data->op_fid2);
2759 if (ll_i2sbi(i1)->ll_flags & LL_SBI_64BIT_HASH)
2760 op_data->op_cli_flags |= CLI_HASH64;
2762 if (ll_need_32bit_api(ll_i2sbi(i1)))
2763 op_data->op_cli_flags |= CLI_API32;
2765 op_data->op_name = name;
2766 op_data->op_namelen = namelen;
2767 op_data->op_mode = mode;
2768 op_data->op_mod_time = ktime_get_real_seconds();
2769 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2770 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2771 op_data->op_cap = cfs_curproc_cap_pack();
2772 op_data->op_mds = 0;
2773 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
2774 filename_is_volatile(name, namelen, &op_data->op_mds)) {
2775 op_data->op_bias |= MDS_CREATE_VOLATILE;
2777 op_data->op_data = data;
2782 void ll_finish_md_op_data(struct md_op_data *op_data)
2784 ll_unlock_md_op_lsm(op_data);
2785 security_release_secctx(op_data->op_file_secctx,
2786 op_data->op_file_secctx_size);
2787 OBD_FREE_PTR(op_data);
2790 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
2792 struct ll_sb_info *sbi;
2794 LASSERT(seq && dentry);
2795 sbi = ll_s2sbi(dentry->d_sb);
2797 if (sbi->ll_flags & LL_SBI_NOLCK)
2798 seq_puts(seq, ",nolock");
2800 /* "flock" is the default since 2.13, but it wasn't for many years,
2801 * so it is still useful to print this to show it is enabled.
2802 * Start to print "noflock" so it is now clear when flock is disabled.
2804 if (sbi->ll_flags & LL_SBI_FLOCK)
2805 seq_puts(seq, ",flock");
2806 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
2807 seq_puts(seq, ",localflock");
2809 seq_puts(seq, ",noflock");
2811 if (sbi->ll_flags & LL_SBI_USER_XATTR)
2812 seq_puts(seq, ",user_xattr");
2814 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
2815 seq_puts(seq, ",lazystatfs");
2817 if (sbi->ll_flags & LL_SBI_USER_FID2PATH)
2818 seq_puts(seq, ",user_fid2path");
2820 if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
2821 seq_puts(seq, ",always_ping");
2823 if (ll_sbi_has_test_dummy_encryption(sbi))
2824 seq_puts(seq, ",test_dummy_encryption");
2826 if (ll_sbi_has_encrypt(sbi))
2827 seq_puts(seq, ",encrypt");
2829 seq_puts(seq, ",noencrypt");
2835 * Get obd name by cmd, and copy out to user space
2837 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
2839 struct ll_sb_info *sbi = ll_i2sbi(inode);
2840 struct obd_device *obd;
2843 if (cmd == OBD_IOC_GETDTNAME)
2844 obd = class_exp2obd(sbi->ll_dt_exp);
2845 else if (cmd == OBD_IOC_GETMDNAME)
2846 obd = class_exp2obd(sbi->ll_md_exp);
2853 if (copy_to_user((void __user *)arg, obd->obd_name,
2854 strlen(obd->obd_name) + 1))
2860 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
2867 p.mnt = current->fs->root.mnt;
2869 path = d_path(&p, buf, bufsize);
2874 void ll_dirty_page_discard_warn(struct page *page, int ioret)
2876 char *buf, *path = NULL;
2877 struct dentry *dentry = NULL;
2878 struct inode *inode = page->mapping->host;
2880 /* this can be called inside spin lock so use GFP_ATOMIC. */
2881 buf = (char *)__get_free_page(GFP_ATOMIC);
2883 dentry = d_find_alias(page->mapping->host);
2885 path = ll_d_path(dentry, buf, PAGE_SIZE);
2888 /* The below message is checked in recovery-small.sh test_24b */
2890 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
2891 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
2892 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
2893 PFID(ll_inode2fid(inode)),
2894 (path && !IS_ERR(path)) ? path : "", ioret);
2900 free_page((unsigned long)buf);
2903 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
2904 struct lov_user_md **kbuf)
2906 struct lov_user_md lum;
2910 if (copy_from_user(&lum, md, sizeof(lum)))
2913 lum_size = ll_lov_user_md_size(&lum);
2917 OBD_ALLOC_LARGE(*kbuf, lum_size);
2921 if (copy_from_user(*kbuf, md, lum_size) != 0) {
2922 OBD_FREE_LARGE(*kbuf, lum_size);
2930 * Compute llite root squash state after a change of root squash
2931 * configuration setting or add/remove of a lnet nid
2933 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
2935 struct root_squash_info *squash = &sbi->ll_squash;
2938 struct lnet_process_id id;
2940 /* Update norootsquash flag */
2941 spin_lock(&squash->rsi_lock);
2942 if (list_empty(&squash->rsi_nosquash_nids))
2943 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
2945 /* Do not apply root squash as soon as one of our NIDs is
2946 * in the nosquash_nids list */
2949 while (LNetGetId(i++, &id) != -ENOENT) {
2950 if (id.nid == LNET_NID_LO_0)
2952 if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) {
2958 sbi->ll_flags |= LL_SBI_NOROOTSQUASH;
2960 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
2962 spin_unlock(&squash->rsi_lock);
2966 * Parse linkea content to extract information about a given hardlink
2968 * \param[in] ldata - Initialized linkea data
2969 * \param[in] linkno - Link identifier
2970 * \param[out] parent_fid - The entry's parent FID
2971 * \param[out] ln - Entry name destination buffer
2973 * \retval 0 on success
2974 * \retval Appropriate negative error code on failure
2976 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
2977 struct lu_fid *parent_fid, struct lu_name *ln)
2983 rc = linkea_init_with_rec(ldata);
2987 if (linkno >= ldata->ld_leh->leh_reccount)
2988 /* beyond last link */
2991 linkea_first_entry(ldata);
2992 for (idx = 0; ldata->ld_lee != NULL; idx++) {
2993 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
2998 linkea_next_entry(ldata);
3008 * Get parent FID and name of an identified link. Operation is performed for
3009 * a given link number, letting the caller iterate over linkno to list one or
3010 * all links of an entry.
3012 * \param[in] file - File descriptor against which to perform the operation
3013 * \param[in,out] arg - User-filled structure containing the linkno to operate
3014 * on and the available size. It is eventually filled with
3015 * the requested information or left untouched on error
3017 * \retval - 0 on success
3018 * \retval - Appropriate negative error code on failure
3020 int ll_getparent(struct file *file, struct getparent __user *arg)
3022 struct inode *inode = file_inode(file);
3023 struct linkea_data *ldata;
3024 struct lu_buf buf = LU_BUF_NULL;
3026 struct lu_fid parent_fid;
3033 if (!cfs_capable(CFS_CAP_DAC_READ_SEARCH) &&
3034 !(ll_i2sbi(inode)->ll_flags & LL_SBI_USER_FID2PATH))
3037 if (get_user(name_size, &arg->gp_name_size))
3040 if (get_user(linkno, &arg->gp_linkno))
3043 if (name_size > PATH_MAX)
3046 OBD_ALLOC(ldata, sizeof(*ldata));
3050 rc = linkea_data_new(ldata, &buf);
3052 GOTO(ldata_free, rc);
3054 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3055 buf.lb_len, OBD_MD_FLXATTR);
3059 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3063 if (ln.ln_namelen >= name_size)
3064 GOTO(lb_free, rc = -EOVERFLOW);
3066 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3067 GOTO(lb_free, rc = -EFAULT);
3069 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3070 GOTO(lb_free, rc = -EFAULT);
3072 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3073 GOTO(lb_free, rc = -EFAULT);
3078 OBD_FREE(ldata, sizeof(*ldata));