4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/llite/llite_lib.c
33 * Lustre Light Super operations
36 #define DEBUG_SUBSYSTEM S_LLITE
38 #include <linux/cpu.h>
39 #include <linux/module.h>
40 #include <linux/random.h>
41 #include <linux/statfs.h>
42 #include <linux/time.h>
43 #include <linux/types.h>
44 #include <libcfs/linux/linux-uuid.h>
45 #include <linux/version.h>
47 #include <linux/user_namespace.h>
48 #include <linux/delay.h>
49 #include <linux/uidgid.h>
50 #include <linux/fs_struct.h>
52 #ifndef HAVE_CPUS_READ_LOCK
53 #include <libcfs/linux/linux-cpu.h>
55 #include <libcfs/linux/linux-misc.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;
100 RETURN(ERR_PTR(-ENOMEM));
102 rc = pcc_super_init(&sbi->ll_pcc_super);
106 spin_lock_init(&sbi->ll_lock);
107 mutex_init(&sbi->ll_lco.lco_lock);
108 spin_lock_init(&sbi->ll_pp_extent_lock);
109 spin_lock_init(&sbi->ll_process_lock);
110 sbi->ll_rw_stats_on = 0;
111 sbi->ll_statfs_max_age = OBD_STATFS_CACHE_SECONDS;
114 pages = si.totalram - si.totalhigh;
115 lru_page_max = pages / 2;
117 sbi->ll_ra_info.ra_async_max_active = ll_get_ra_async_max_active();
118 sbi->ll_ra_info.ll_readahead_wq =
119 cfs_cpt_bind_workqueue("ll-readahead-wq", cfs_cpt_tab,
121 sbi->ll_ra_info.ra_async_max_active);
122 if (IS_ERR(sbi->ll_ra_info.ll_readahead_wq))
123 GOTO(out_pcc, rc = PTR_ERR(sbi->ll_ra_info.ll_readahead_wq));
125 /* initialize ll_cache data */
126 sbi->ll_cache = cl_cache_init(lru_page_max);
127 if (sbi->ll_cache == NULL)
128 GOTO(out_destroy_ra, rc = -ENOMEM);
130 /* initialize foreign symlink prefix path */
131 OBD_ALLOC(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
132 if (sbi->ll_foreign_symlink_prefix == NULL)
133 GOTO(out_destroy_ra, rc = -ENOMEM);
134 memcpy(sbi->ll_foreign_symlink_prefix, "/mnt/", sizeof("/mnt/"));
135 sbi->ll_foreign_symlink_prefix_size = sizeof("/mnt/");
137 /* initialize foreign symlink upcall path, none by default */
138 OBD_ALLOC(sbi->ll_foreign_symlink_upcall, sizeof("none"));
139 if (sbi->ll_foreign_symlink_upcall == NULL)
140 GOTO(out_destroy_ra, rc = -ENOMEM);
141 memcpy(sbi->ll_foreign_symlink_upcall, "none", sizeof("none"));
142 sbi->ll_foreign_symlink_upcall_items = NULL;
143 sbi->ll_foreign_symlink_upcall_nb_items = 0;
144 init_rwsem(&sbi->ll_foreign_symlink_sem);
145 /* foreign symlink support (LL_SBI_FOREIGN_SYMLINK in ll_flags)
146 * not enabled by default
149 sbi->ll_ra_info.ra_max_pages =
150 min(pages / 32, SBI_DEFAULT_READ_AHEAD_MAX);
151 sbi->ll_ra_info.ra_max_pages_per_file =
152 min(sbi->ll_ra_info.ra_max_pages / 4,
153 SBI_DEFAULT_READ_AHEAD_PER_FILE_MAX);
154 sbi->ll_ra_info.ra_async_pages_per_file_threshold =
155 sbi->ll_ra_info.ra_max_pages_per_file;
156 sbi->ll_ra_info.ra_range_pages = SBI_DEFAULT_RA_RANGE_PAGES;
157 sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
158 atomic_set(&sbi->ll_ra_info.ra_async_inflight, 0);
160 set_bit(LL_SBI_VERBOSE, sbi->ll_flags);
161 #ifdef ENABLE_CHECKSUM
162 set_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
165 set_bit(LL_SBI_FLOCK, sbi->ll_flags);
168 #ifdef HAVE_LRU_RESIZE_SUPPORT
169 set_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags);
171 set_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags);
173 /* metadata statahead is enabled by default */
174 sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
175 sbi->ll_sa_max = LL_SA_RPC_DEF;
176 atomic_set(&sbi->ll_sa_total, 0);
177 atomic_set(&sbi->ll_sa_wrong, 0);
178 atomic_set(&sbi->ll_sa_running, 0);
179 atomic_set(&sbi->ll_agl_total, 0);
180 set_bit(LL_SBI_AGL_ENABLED, sbi->ll_flags);
181 set_bit(LL_SBI_FAST_READ, sbi->ll_flags);
182 set_bit(LL_SBI_TINY_WRITE, sbi->ll_flags);
183 set_bit(LL_SBI_PARALLEL_DIO, sbi->ll_flags);
184 ll_sbi_set_encrypt(sbi, true);
187 sbi->ll_squash.rsi_uid = 0;
188 sbi->ll_squash.rsi_gid = 0;
189 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
190 spin_lock_init(&sbi->ll_squash.rsi_lock);
192 /* Per-filesystem file heat */
193 sbi->ll_heat_decay_weight = SBI_DEFAULT_HEAT_DECAY_WEIGHT;
194 sbi->ll_heat_period_second = SBI_DEFAULT_HEAT_PERIOD_SECOND;
196 /* Per-fs open heat level before requesting open lock */
197 sbi->ll_oc_thrsh_count = SBI_DEFAULT_OPENCACHE_THRESHOLD_COUNT;
198 sbi->ll_oc_max_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MAX_MS;
199 sbi->ll_oc_thrsh_ms = SBI_DEFAULT_OPENCACHE_THRESHOLD_MS;
202 if (sbi->ll_foreign_symlink_prefix)
203 OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/"));
205 cl_cache_decref(sbi->ll_cache);
206 sbi->ll_cache = NULL;
208 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
210 pcc_super_fini(&sbi->ll_pcc_super);
216 static void ll_free_sbi(struct super_block *sb)
218 struct ll_sb_info *sbi = ll_s2sbi(sb);
222 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
223 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
224 if (sbi->ll_ra_info.ll_readahead_wq)
225 destroy_workqueue(sbi->ll_ra_info.ll_readahead_wq);
226 if (sbi->ll_cache != NULL) {
227 cl_cache_decref(sbi->ll_cache);
228 sbi->ll_cache = NULL;
230 if (sbi->ll_foreign_symlink_prefix) {
231 OBD_FREE(sbi->ll_foreign_symlink_prefix,
232 sbi->ll_foreign_symlink_prefix_size);
233 sbi->ll_foreign_symlink_prefix = NULL;
235 if (sbi->ll_foreign_symlink_upcall) {
236 OBD_FREE(sbi->ll_foreign_symlink_upcall,
237 strlen(sbi->ll_foreign_symlink_upcall) +
239 sbi->ll_foreign_symlink_upcall = NULL;
241 if (sbi->ll_foreign_symlink_upcall_items) {
243 int nb_items = sbi->ll_foreign_symlink_upcall_nb_items;
244 struct ll_foreign_symlink_upcall_item *items =
245 sbi->ll_foreign_symlink_upcall_items;
247 for (i = 0 ; i < nb_items; i++)
248 if (items[i].type == STRING_TYPE)
249 OBD_FREE(items[i].string,
252 OBD_FREE_LARGE(items, nb_items *
253 sizeof(struct ll_foreign_symlink_upcall_item));
254 sbi->ll_foreign_symlink_upcall_items = NULL;
256 ll_free_rw_stats_info(sbi);
257 pcc_super_fini(&sbi->ll_pcc_super);
258 OBD_FREE(sbi, sizeof(*sbi));
263 static int client_common_fill_super(struct super_block *sb, char *md, char *dt)
265 struct inode *root = NULL;
266 struct ll_sb_info *sbi = ll_s2sbi(sb);
267 struct obd_statfs *osfs = NULL;
268 struct ptlrpc_request *request = NULL;
269 struct obd_connect_data *data = NULL;
270 struct obd_uuid *uuid;
271 struct md_op_data *op_data;
272 struct lustre_md lmd;
274 int size, err, checksum;
278 sbi->ll_md_obd = class_name2obd(md);
279 if (!sbi->ll_md_obd) {
280 CERROR("MD %s: not setup or attached\n", md);
294 /* pass client page size via ocd_grant_blkbits, the server should report
295 * back its backend blocksize for grant calculation purpose */
296 data->ocd_grant_blkbits = PAGE_SHIFT;
298 /* indicate MDT features supported by this client */
299 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
300 OBD_CONNECT_ATTRFID | OBD_CONNECT_GRANT |
301 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
302 OBD_CONNECT_SRVLOCK |
303 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
304 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
305 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
306 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
307 OBD_CONNECT_64BITHASH |
308 OBD_CONNECT_EINPROGRESS |
309 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
310 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
311 OBD_CONNECT_MAX_EASIZE |
312 OBD_CONNECT_FLOCK_DEAD |
313 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
314 OBD_CONNECT_OPEN_BY_FID |
315 OBD_CONNECT_DIR_STRIPE |
316 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_CKSUM |
317 OBD_CONNECT_SUBTREE |
318 OBD_CONNECT_MULTIMODRPCS |
319 OBD_CONNECT_GRANT_PARAM |
320 OBD_CONNECT_GRANT_SHRINK |
321 OBD_CONNECT_SHORTIO | OBD_CONNECT_FLAGS2;
323 data->ocd_connect_flags2 = OBD_CONNECT2_DIR_MIGRATE |
324 OBD_CONNECT2_SUM_STATFS |
325 OBD_CONNECT2_OVERSTRIPING |
327 OBD_CONNECT2_LOCK_CONVERT |
328 OBD_CONNECT2_ARCHIVE_ID_ARRAY |
329 OBD_CONNECT2_INC_XID |
331 OBD_CONNECT2_ASYNC_DISCARD |
333 OBD_CONNECT2_CRUSH | OBD_CONNECT2_LSEEK |
334 OBD_CONNECT2_GETATTR_PFID |
335 OBD_CONNECT2_DOM_LVB |
336 OBD_CONNECT2_REP_MBITS |
337 OBD_CONNECT2_ATOMIC_OPEN_LOCK;
339 #ifdef HAVE_LRU_RESIZE_SUPPORT
340 if (test_bit(LL_SBI_LRU_RESIZE, sbi->ll_flags))
341 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
343 data->ocd_connect_flags |= OBD_CONNECT_ACL_FLAGS;
345 data->ocd_cksum_types = obd_cksum_types_supported_client();
347 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
348 /* flag mdc connection as lightweight, only used for test
349 * purpose, use with care */
350 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
352 data->ocd_ibits_known = MDS_INODELOCK_FULL;
353 data->ocd_version = LUSTRE_VERSION_CODE;
355 if (sb->s_flags & SB_RDONLY)
356 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
357 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags))
358 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
361 /* Setting this indicates we correctly support S_NOSEC (See kernel
362 * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
364 sb->s_flags |= SB_NOSEC;
366 sbi->ll_fop = ll_select_file_operations(sbi);
368 /* always ping even if server suppress_pings */
369 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
370 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
372 obd_connect_set_secctx(data);
373 if (ll_sbi_has_encrypt(sbi))
374 obd_connect_set_enc(data);
376 #if defined(CONFIG_SECURITY)
377 data->ocd_connect_flags2 |= OBD_CONNECT2_SELINUX_POLICY;
380 data->ocd_brw_size = MD_MAX_BRW_SIZE;
382 err = obd_connect(NULL, &sbi->ll_md_exp, sbi->ll_md_obd,
383 &sbi->ll_sb_uuid, data, sbi->ll_cache);
385 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
386 "recovery, of which this client is not a "
387 "part. Please wait for recovery to complete,"
388 " abort, or time out.\n", md);
391 CERROR("cannot connect to %s: rc = %d\n", md, err);
395 sbi->ll_md_exp->exp_connect_data = *data;
397 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
398 LUSTRE_SEQ_METADATA);
400 CERROR("%s: Can't init metadata layer FID infrastructure, "
401 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
405 /* For mount, we only need fs info from MDT0, and also in DNE, it
406 * can make sure the client can be mounted as long as MDT0 is
408 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
409 ktime_get_seconds() - sbi->ll_statfs_max_age,
410 OBD_STATFS_FOR_MDT0);
412 GOTO(out_md_fid, err);
414 /* This needs to be after statfs to ensure connect has finished.
415 * Note that "data" does NOT contain the valid connect reply.
416 * If connecting to a 1.8 server there will be no LMV device, so
417 * we can access the MDC export directly and exp_connect_flags will
418 * be non-zero, but if accessing an upgraded 2.1 server it will
419 * have the correct flags filled in.
420 * XXX: fill in the LMV exp_connect_flags from MDC(s). */
421 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
422 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
423 valid != CLIENT_CONNECT_MDT_REQD) {
426 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
427 obd_connect_flags2str(buf, PAGE_SIZE,
428 valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
429 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
430 "feature(s) needed for correct operation "
431 "of this client (%s). Please upgrade "
432 "server or downgrade client.\n",
433 sbi->ll_md_exp->exp_obd->obd_name, buf);
434 OBD_FREE(buf, PAGE_SIZE);
435 GOTO(out_md_fid, err = -EPROTO);
438 size = sizeof(*data);
439 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
440 KEY_CONN_DATA, &size, data);
442 CERROR("%s: Get connect data failed: rc = %d\n",
443 sbi->ll_md_exp->exp_obd->obd_name, err);
444 GOTO(out_md_fid, err);
447 LASSERT(osfs->os_bsize);
448 sb->s_blocksize = osfs->os_bsize;
449 sb->s_blocksize_bits = log2(osfs->os_bsize);
450 sb->s_magic = LL_SUPER_MAGIC;
451 sb->s_maxbytes = MAX_LFS_FILESIZE;
452 sbi->ll_namelen = osfs->os_namelen;
453 sbi->ll_mnt.mnt = current->fs->root.mnt;
455 if (test_bit(LL_SBI_USER_XATTR, sbi->ll_flags) &&
456 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
457 LCONSOLE_INFO("Disabling user_xattr feature because "
458 "it is not supported on the server\n");
459 clear_bit(LL_SBI_USER_XATTR, sbi->ll_flags);
462 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
464 sb->s_flags |= SB_POSIXACL;
466 set_bit(LL_SBI_ACL, sbi->ll_flags);
468 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
470 sb->s_flags &= ~SB_POSIXACL;
472 clear_bit(LL_SBI_ACL, sbi->ll_flags);
475 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
476 set_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
478 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
479 set_bit(LL_SBI_LAYOUT_LOCK, sbi->ll_flags);
481 if (obd_connect_has_secctx(data))
482 set_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags);
484 if (ll_sbi_has_encrypt(sbi) && !obd_connect_has_enc(data)) {
485 if (ll_sbi_has_test_dummy_encryption(sbi))
486 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
488 sbi->ll_md_exp->exp_obd->obd_name);
489 ll_sbi_set_encrypt(sbi, false);
492 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
493 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
494 LCONSOLE_INFO("%s: disabling xattr cache due to "
495 "unknown maximum xattr size.\n", dt);
496 } else if (!sbi->ll_xattr_cache_set) {
497 /* If xattr_cache is already set (no matter 0 or 1)
498 * during processing llog, it won't be enabled here. */
499 set_bit(LL_SBI_XATTR_CACHE, sbi->ll_flags);
500 sbi->ll_xattr_cache_enabled = 1;
504 sbi->ll_dt_obd = class_name2obd(dt);
505 if (!sbi->ll_dt_obd) {
506 CERROR("DT %s: not setup or attached\n", dt);
507 GOTO(out_md_fid, err = -ENODEV);
510 /* pass client page size via ocd_grant_blkbits, the server should report
511 * back its backend blocksize for grant calculation purpose */
512 data->ocd_grant_blkbits = PAGE_SHIFT;
514 /* indicate OST features supported by this client */
515 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
516 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
517 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
518 OBD_CONNECT_SRVLOCK |
519 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
520 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
521 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
522 OBD_CONNECT_EINPROGRESS |
523 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
524 OBD_CONNECT_LAYOUTLOCK |
525 OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
526 OBD_CONNECT_BULK_MBITS | OBD_CONNECT_SHORTIO |
527 OBD_CONNECT_FLAGS2 | OBD_CONNECT_GRANT_SHRINK;
528 data->ocd_connect_flags2 = OBD_CONNECT2_LOCKAHEAD |
529 OBD_CONNECT2_INC_XID | OBD_CONNECT2_LSEEK |
530 OBD_CONNECT2_REP_MBITS;
532 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
533 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
535 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
536 * disabled by default, because it can still be enabled on the
537 * fly via /sys. As a consequence, we still need to come to an
538 * agreement on the supported algorithms at connect time
540 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
542 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
543 data->ocd_cksum_types = OBD_CKSUM_ADLER;
545 data->ocd_cksum_types = obd_cksum_types_supported_client();
547 #ifdef HAVE_LRU_RESIZE_SUPPORT
548 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
550 /* always ping even if server suppress_pings */
551 if (test_bit(LL_SBI_ALWAYS_PING, sbi->ll_flags))
552 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
554 if (ll_sbi_has_encrypt(sbi))
555 obd_connect_set_enc(data);
557 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
558 "ocd_grant: %d\n", data->ocd_connect_flags,
559 data->ocd_version, data->ocd_grant);
561 sbi->ll_dt_obd->obd_upcall.onu_owner = &sbi->ll_lco;
562 sbi->ll_dt_obd->obd_upcall.onu_upcall = cl_ocd_update;
564 data->ocd_brw_size = DT_MAX_BRW_SIZE;
566 err = obd_connect(NULL, &sbi->ll_dt_exp, sbi->ll_dt_obd,
567 &sbi->ll_sb_uuid, data, sbi->ll_cache);
569 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
570 "recovery, of which this client is not a "
571 "part. Please wait for recovery to "
572 "complete, abort, or time out.\n", dt);
575 CERROR("%s: Cannot connect to %s: rc = %d\n",
576 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
580 if (ll_sbi_has_encrypt(sbi) &&
581 !obd_connect_has_enc(&sbi->ll_dt_obd->u.lov.lov_ocd)) {
582 if (ll_sbi_has_test_dummy_encryption(sbi))
583 LCONSOLE_WARN("%s: server %s does not support encryption feature, encryption deactivated.\n",
585 ll_sbi_set_encrypt(sbi, false);
586 } else if (ll_sbi_has_test_dummy_encryption(sbi)) {
587 LCONSOLE_WARN("Test dummy encryption mode enabled\n");
590 sbi->ll_dt_exp->exp_connect_data = *data;
592 /* Don't change value if it was specified in the config log */
593 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1) {
594 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
595 max_t(unsigned long, SBI_DEFAULT_READ_AHEAD_WHOLE_MAX,
596 (data->ocd_brw_size >> PAGE_SHIFT));
597 if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages >
598 sbi->ll_ra_info.ra_max_pages_per_file)
599 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
600 sbi->ll_ra_info.ra_max_pages_per_file;
603 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
604 LUSTRE_SEQ_METADATA);
606 CERROR("%s: Can't init data layer FID infrastructure, "
607 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
611 mutex_lock(&sbi->ll_lco.lco_lock);
612 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
613 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
614 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
615 mutex_unlock(&sbi->ll_lco.lco_lock);
617 fid_zero(&sbi->ll_root_fid);
618 err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
621 CERROR("cannot mds_connect: rc = %d\n", err);
622 GOTO(out_lock_cn_cb, err);
624 if (!fid_is_sane(&sbi->ll_root_fid)) {
625 CERROR("%s: Invalid root fid "DFID" during mount\n",
626 sbi->ll_md_exp->exp_obd->obd_name,
627 PFID(&sbi->ll_root_fid));
628 GOTO(out_lock_cn_cb, err = -EINVAL);
630 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
632 sb->s_op = &lustre_super_operations;
633 sb->s_xattr = ll_xattr_handlers;
634 #if THREAD_SIZE >= 8192 /*b=17630*/
635 sb->s_export_op = &lustre_export_operations;
637 #ifdef HAVE_LUSTRE_CRYPTO
638 llcrypt_set_ops(sb, &lustre_cryptops);
642 * XXX: move this to after cbd setup? */
643 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
644 if (test_bit(LL_SBI_ACL, sbi->ll_flags))
645 valid |= OBD_MD_FLACL;
647 OBD_ALLOC_PTR(op_data);
649 GOTO(out_lock_cn_cb, err = -ENOMEM);
651 op_data->op_fid1 = sbi->ll_root_fid;
652 op_data->op_mode = 0;
653 op_data->op_valid = valid;
655 err = md_getattr(sbi->ll_md_exp, op_data, &request);
657 OBD_FREE_PTR(op_data);
659 CERROR("%s: md_getattr failed for root: rc = %d\n",
660 sbi->ll_md_exp->exp_obd->obd_name, err);
661 GOTO(out_lock_cn_cb, err);
664 err = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill,
665 sbi->ll_dt_exp, sbi->ll_md_exp, &lmd);
667 CERROR("failed to understand root inode md: rc = %d\n", err);
668 ptlrpc_req_finished(request);
669 GOTO(out_lock_cn_cb, err);
672 LASSERT(fid_is_sane(&sbi->ll_root_fid));
673 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
674 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid, api32), &lmd);
675 md_free_lustre_md(sbi->ll_md_exp, &lmd);
676 ptlrpc_req_finished(request);
680 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
682 CERROR("%s: bad ll_iget() for root: rc = %d\n",
683 sbi->ll_fsname, err);
687 checksum = test_bit(LL_SBI_CHECKSUM, sbi->ll_flags);
688 if (sbi->ll_checksum_set) {
689 err = obd_set_info_async(NULL, sbi->ll_dt_exp,
690 sizeof(KEY_CHECKSUM), KEY_CHECKSUM,
691 sizeof(checksum), &checksum, NULL);
693 CERROR("%s: Set checksum failed: rc = %d\n",
694 sbi->ll_dt_exp->exp_obd->obd_name, err);
700 sb->s_root = d_make_root(root);
701 if (sb->s_root == NULL) {
703 CERROR("%s: can't make root dentry: rc = %d\n",
704 sbi->ll_fsname, err);
708 sbi->ll_sdev_orig = sb->s_dev;
710 /* We set sb->s_dev equal on all lustre clients in order to support
711 * NFS export clustering. NFSD requires that the FSID be the same
713 /* s_dev is also used in lt_compare() to compare two fs, but that is
714 * only a node-local comparison. */
715 uuid = obd_get_uuid(sbi->ll_md_exp);
717 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
724 if (sbi->ll_dt_obd) {
725 err = sysfs_create_link(&sbi->ll_kset.kobj,
726 &sbi->ll_dt_obd->obd_kset.kobj,
727 sbi->ll_dt_obd->obd_type->typ_name);
729 CERROR("%s: could not register %s in llite: rc = %d\n",
730 dt, sbi->ll_fsname, err);
735 if (sbi->ll_md_obd) {
736 err = sysfs_create_link(&sbi->ll_kset.kobj,
737 &sbi->ll_md_obd->obd_kset.kobj,
738 sbi->ll_md_obd->obd_type->typ_name);
740 CERROR("%s: could not register %s in llite: rc = %d\n",
741 md, sbi->ll_fsname, err);
750 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
752 obd_disconnect(sbi->ll_dt_exp);
753 sbi->ll_dt_exp = NULL;
754 sbi->ll_dt_obd = NULL;
756 obd_fid_fini(sbi->ll_md_exp->exp_obd);
758 obd_disconnect(sbi->ll_md_exp);
759 sbi->ll_md_exp = NULL;
760 sbi->ll_md_obd = NULL;
769 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
773 size = sizeof(*lmmsize);
774 rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
775 KEY_MAX_EASIZE, &size, lmmsize);
777 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
778 sbi->ll_dt_exp->exp_obd->obd_name, rc);
782 CDEBUG(D_INFO, "max LOV ea size: %d\n", *lmmsize);
785 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
786 KEY_MAX_EASIZE, &size, lmmsize);
788 CERROR("Get max mdsize error rc %d\n", rc);
790 CDEBUG(D_INFO, "max LMV ea size: %d\n", *lmmsize);
796 * Get the value of the default_easize parameter.
798 * \see client_obd::cl_default_mds_easize
800 * \param[in] sbi superblock info for this filesystem
801 * \param[out] lmmsize pointer to storage location for value
803 * \retval 0 on success
804 * \retval negative negated errno on failure
806 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
811 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
812 KEY_DEFAULT_EASIZE, &size, lmmsize);
814 CERROR("Get default mdsize error rc %d\n", rc);
820 * Set the default_easize parameter to the given value.
822 * \see client_obd::cl_default_mds_easize
824 * \param[in] sbi superblock info for this filesystem
825 * \param[in] lmmsize the size to set
827 * \retval 0 on success
828 * \retval negative negated errno on failure
830 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
834 if (lmmsize < sizeof(struct lov_mds_md) ||
835 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
838 rc = obd_set_info_async(NULL, sbi->ll_md_exp,
839 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
840 sizeof(int), &lmmsize, NULL);
845 static void client_common_put_super(struct super_block *sb)
847 struct ll_sb_info *sbi = ll_s2sbi(sb);
852 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
853 obd_disconnect(sbi->ll_dt_exp);
854 sbi->ll_dt_exp = NULL;
856 ll_debugfs_unregister_super(sb);
858 obd_fid_fini(sbi->ll_md_exp->exp_obd);
859 obd_disconnect(sbi->ll_md_exp);
860 sbi->ll_md_exp = NULL;
865 void ll_kill_super(struct super_block *sb)
867 struct ll_sb_info *sbi;
871 if (!(sb->s_flags & SB_ACTIVE))
875 /* we need restore s_dev from changed for clustred NFS before put_super
876 * because new kernels have cached s_dev and change sb->s_dev in
877 * put_super not affected real removing devices */
879 sb->s_dev = sbi->ll_sdev_orig;
881 /* wait running statahead threads to quit */
882 while (atomic_read(&sbi->ll_sa_running) > 0)
883 schedule_timeout_uninterruptible(
884 cfs_time_seconds(1) >> 3);
890 /* Since we use this table for ll_sbi_flags_seq_show make
891 * sure what you want displayed for a specific token that
892 * is listed more than once below be listed first. For
893 * example we want "checksum" displayed, not "nochecksum"
896 static const match_table_t ll_sbi_flags_name = {
897 {LL_SBI_NOLCK, "nolock"},
898 {LL_SBI_CHECKSUM, "checksum"},
899 {LL_SBI_CHECKSUM, "nochecksum"},
900 {LL_SBI_LOCALFLOCK, "localflock"},
901 {LL_SBI_FLOCK, "flock"},
902 {LL_SBI_FLOCK, "noflock"},
903 {LL_SBI_USER_XATTR, "user_xattr"},
904 {LL_SBI_USER_XATTR, "nouser_xattr"},
905 {LL_SBI_LRU_RESIZE, "lruresize"},
906 {LL_SBI_LRU_RESIZE, "nolruresize"},
907 {LL_SBI_LAZYSTATFS, "lazystatfs"},
908 {LL_SBI_LAZYSTATFS, "nolazystatfs"},
909 {LL_SBI_32BIT_API, "32bitapi"},
910 {LL_SBI_USER_FID2PATH, "user_fid2path"},
911 {LL_SBI_USER_FID2PATH, "nouser_fid2path"},
912 {LL_SBI_VERBOSE, "verbose"},
913 {LL_SBI_VERBOSE, "noverbose"},
914 {LL_SBI_ALWAYS_PING, "always_ping"},
915 {LL_SBI_TEST_DUMMY_ENCRYPTION, "test_dummy_encryption"},
916 {LL_SBI_ENCRYPT, "encrypt"},
917 {LL_SBI_ENCRYPT, "noencrypt"},
918 {LL_SBI_FOREIGN_SYMLINK, "foreign_symlink=%s"},
919 {LL_SBI_NUM_MOUNT_OPT, NULL},
922 {LL_SBI_AGL_ENABLED, "agl"},
923 {LL_SBI_64BIT_HASH, "64bit_hash"},
924 {LL_SBI_LAYOUT_LOCK, "layout"},
925 {LL_SBI_XATTR_CACHE, "xattr_cache"},
926 {LL_SBI_NOROOTSQUASH, "norootsquash"},
927 {LL_SBI_FAST_READ, "fast_read"},
928 {LL_SBI_FILE_SECCTX, "file_secctx"},
929 {LL_SBI_TINY_WRITE, "tiny_write"},
930 {LL_SBI_FILE_HEAT, "file_heat"},
931 {LL_SBI_PARALLEL_DIO, "parallel_dio"},
934 int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
936 struct super_block *sb = m->private;
939 for (i = 0; i < LL_SBI_NUM_FLAGS; i++) {
942 if (!test_bit(i, ll_s2sbi(sb)->ll_flags))
945 for (j = 0; j < ARRAY_SIZE(ll_sbi_flags_name); j++) {
946 if (ll_sbi_flags_name[j].token == i &&
947 ll_sbi_flags_name[j].pattern) {
949 ll_sbi_flags_name[j].pattern);
958 /* non-client-specific mount options are parsed in lmd_parse */
959 static int ll_options(char *options, struct super_block *sb)
961 struct ll_sb_info *sbi = ll_s2sbi(sb);
962 char *s2, *s1, *opts;
968 /* Don't stomp on lmd_opts */
969 opts = kstrdup(options, GFP_KERNEL);
975 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
977 while ((s1 = strsep(&opts, ",")) != NULL) {
978 substring_t args[MAX_OPT_ARGS];
979 bool turn_off = false;
985 CDEBUG(D_SUPER, "next opt=%s\n", s1);
987 if (strncmp(s1, "no", 2) == 0)
991 * Initialize args struct so we know whether arg was
992 * found; some options take optional arguments.
996 token = match_token(s1, ll_sbi_flags_name, args);
997 if (token == LL_SBI_NUM_MOUNT_OPT) {
998 if (match_wildcard("context", s1) ||
999 match_wildcard("fscontext", s1) ||
1000 match_wildcard("defcontext", s1) ||
1001 match_wildcard("rootcontext",s1))
1004 LCONSOLE_ERROR_MSG(0x152,
1005 "Unknown option '%s', won't mount.\n",
1012 case LL_SBI_32BIT_API:
1013 case LL_SBI_64BIT_HASH:
1014 case LL_SBI_ALWAYS_PING:
1015 set_bit(token, sbi->ll_flags);
1019 clear_bit(LL_SBI_LOCALFLOCK, sbi->ll_flags);
1021 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1023 set_bit(token, sbi->ll_flags);
1026 case LL_SBI_LOCALFLOCK:
1027 clear_bit(LL_SBI_FLOCK, sbi->ll_flags);
1028 set_bit(token, sbi->ll_flags);
1031 case LL_SBI_CHECKSUM:
1032 sbi->ll_checksum_set = 1;
1034 case LL_SBI_USER_XATTR:
1035 case LL_SBI_USER_FID2PATH:
1036 case LL_SBI_LRU_RESIZE:
1037 case LL_SBI_LAZYSTATFS:
1038 case LL_SBI_VERBOSE:
1040 clear_bit(token, sbi->ll_flags);
1042 set_bit(token, sbi->ll_flags);
1044 case LL_SBI_TEST_DUMMY_ENCRYPTION: {
1045 #ifdef HAVE_LUSTRE_CRYPTO
1046 set_bit(token, sbi->ll_flags);
1048 LCONSOLE_WARN("Test dummy encryption mount option ignored: encryption not supported\n");
1052 case LL_SBI_ENCRYPT:
1053 #ifdef HAVE_LUSTRE_CRYPTO
1055 clear_bit(token, sbi->ll_flags);
1057 set_bit(token, sbi->ll_flags);
1059 LCONSOLE_WARN("noencrypt or encrypt mount option ignored: encryption not supported\n");
1062 case LL_SBI_FOREIGN_SYMLINK:
1063 /* non-default prefix provided ? */
1068 /* path must be absolute */
1069 if (args->from[0] != '/') {
1070 LCONSOLE_ERROR_MSG(0x152,
1071 "foreign prefix '%s' must be an absolute path\n",
1076 old_len = sbi->ll_foreign_symlink_prefix_size;
1077 old = sbi->ll_foreign_symlink_prefix;
1078 /* alloc for path length and '\0' */
1079 sbi->ll_foreign_symlink_prefix = match_strdup(args);
1080 if (!sbi->ll_foreign_symlink_prefix) {
1081 /* restore previous */
1082 sbi->ll_foreign_symlink_prefix = old;
1083 sbi->ll_foreign_symlink_prefix_size =
1087 sbi->ll_foreign_symlink_prefix_size =
1088 args->to - args->from + 1;
1089 OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix,
1090 sbi->ll_foreign_symlink_prefix_size,
1093 OBD_FREE(old, old_len);
1095 /* enable foreign symlink support */
1096 set_bit(token, sbi->ll_flags);
1098 LCONSOLE_ERROR_MSG(0x152,
1099 "invalid %s option\n", s1);
1110 void ll_lli_init(struct ll_inode_info *lli)
1112 lli->lli_inode_magic = LLI_INODE_MAGIC;
1114 rwlock_init(&lli->lli_lock);
1115 lli->lli_posix_acl = NULL;
1116 /* Do not set lli_fid, it has been initialized already. */
1117 fid_zero(&lli->lli_pfid);
1118 lli->lli_mds_read_och = NULL;
1119 lli->lli_mds_write_och = NULL;
1120 lli->lli_mds_exec_och = NULL;
1121 lli->lli_open_fd_read_count = 0;
1122 lli->lli_open_fd_write_count = 0;
1123 lli->lli_open_fd_exec_count = 0;
1124 mutex_init(&lli->lli_och_mutex);
1125 spin_lock_init(&lli->lli_agl_lock);
1126 spin_lock_init(&lli->lli_layout_lock);
1127 ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
1128 lli->lli_clob = NULL;
1130 init_rwsem(&lli->lli_xattrs_list_rwsem);
1131 mutex_init(&lli->lli_xattrs_enq_lock);
1133 LASSERT(lli->lli_vfs_inode.i_mode != 0);
1134 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
1135 lli->lli_opendir_key = NULL;
1136 lli->lli_sai = NULL;
1137 spin_lock_init(&lli->lli_sa_lock);
1138 lli->lli_opendir_pid = 0;
1139 lli->lli_sa_enabled = 0;
1140 init_rwsem(&lli->lli_lsm_sem);
1142 mutex_init(&lli->lli_size_mutex);
1143 mutex_init(&lli->lli_setattr_mutex);
1144 lli->lli_symlink_name = NULL;
1145 ll_trunc_sem_init(&lli->lli_trunc_sem);
1146 range_lock_tree_init(&lli->lli_write_tree);
1147 init_rwsem(&lli->lli_glimpse_sem);
1148 lli->lli_glimpse_time = ktime_set(0, 0);
1149 INIT_LIST_HEAD(&lli->lli_agl_list);
1150 lli->lli_agl_index = 0;
1151 lli->lli_async_rc = 0;
1152 spin_lock_init(&lli->lli_heat_lock);
1153 obd_heat_clear(lli->lli_heat_instances, OBD_HEAT_COUNT);
1154 lli->lli_heat_flags = 0;
1155 mutex_init(&lli->lli_pcc_lock);
1156 lli->lli_pcc_state = PCC_STATE_FL_NONE;
1157 lli->lli_pcc_inode = NULL;
1158 lli->lli_pcc_dsflags = PCC_DATASET_INVALID;
1159 lli->lli_pcc_generation = 0;
1160 mutex_init(&lli->lli_group_mutex);
1161 lli->lli_group_users = 0;
1162 lli->lli_group_gid = 0;
1164 mutex_init(&lli->lli_layout_mutex);
1165 memset(lli->lli_jobid, 0, sizeof(lli->lli_jobid));
1166 /* ll_cl_context initialize */
1167 INIT_LIST_HEAD(&lli->lli_lccs);
1170 #define MAX_STRING_SIZE 128
1172 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1174 #define LSI_BDI_INITIALIZED 0x00400000
1176 #ifndef HAVE_BDI_CAP_MAP_COPY
1177 # define BDI_CAP_MAP_COPY 0
1180 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
1182 struct lustre_sb_info *lsi = s2lsi(sb);
1183 char buf[MAX_STRING_SIZE];
1187 err = bdi_init(&lsi->lsi_bdi);
1191 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
1192 lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
1193 lsi->lsi_bdi.name = "lustre";
1194 va_start(args, fmt);
1195 vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
1197 err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
1200 sb->s_bdi = &lsi->lsi_bdi;
1204 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
1206 int ll_fill_super(struct super_block *sb)
1208 struct lustre_profile *lprof = NULL;
1209 struct lustre_sb_info *lsi = s2lsi(sb);
1210 struct ll_sb_info *sbi = NULL;
1211 char *dt = NULL, *md = NULL;
1212 char *profilenm = get_profile_name(sb);
1213 struct config_llog_instance *cfg;
1214 /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
1215 const int instlen = LUSTRE_MAXINSTANCE + 2;
1216 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1217 char name[MAX_STRING_SIZE];
1226 /* for ASLR, to map between cfg_instance and hashed ptr */
1227 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1228 profilenm, cfg_instance, sb);
1230 OBD_RACE(OBD_FAIL_LLITE_RACE_MOUNT);
1234 GOTO(out_free_cfg, err = -ENOMEM);
1236 /* client additional sb info */
1237 lsi->lsi_llsbi = sbi = ll_init_sbi();
1239 GOTO(out_free_cfg, err = PTR_ERR(sbi));
1241 err = ll_options(lsi->lsi_lmd->lmd_opts, sb);
1243 GOTO(out_free_cfg, err);
1245 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1246 sb->s_d_op = &ll_d_ops;
1249 generate_random_uuid(uuid.b);
1250 snprintf(sbi->ll_sb_uuid.uuid, sizeof(sbi->ll_sb_uuid), "%pU", uuid.b);
1252 CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid);
1255 len = strlen(profilenm);
1256 ptr = strrchr(profilenm, '-');
1257 if (ptr && (strcmp(ptr, "-client") == 0))
1260 if (len > LUSTRE_MAXFSNAME) {
1261 if (unlikely(len >= MAX_STRING_SIZE))
1262 len = MAX_STRING_SIZE - 1;
1263 strncpy(name, profilenm, len);
1265 err = -ENAMETOOLONG;
1266 CERROR("%s: fsname longer than %u characters: rc = %d\n",
1267 name, LUSTRE_MAXFSNAME, err);
1268 GOTO(out_free_cfg, err);
1270 strncpy(sbi->ll_fsname, profilenm, len);
1271 sbi->ll_fsname[len] = '\0';
1274 snprintf(name, sizeof(name), "%.*s-%016lx", len,
1275 profilenm, cfg_instance);
1277 err = super_setup_bdi_name(sb, "%s", name);
1279 GOTO(out_free_cfg, err);
1281 /* Call ll_debugfs_register_super() before lustre_process_log()
1282 * so that "llite.*.*" params can be processed correctly.
1284 err = ll_debugfs_register_super(sb, name);
1286 CERROR("%s: could not register mountpoint in llite: rc = %d\n",
1287 sbi->ll_fsname, err);
1291 /* The cfg_instance is a value unique to this super, in case some
1292 * joker tries to mount the same fs at two mount points.
1294 cfg->cfg_instance = cfg_instance;
1295 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1296 cfg->cfg_callback = class_config_llog_handler;
1297 cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1298 /* set up client obds */
1299 err = lustre_process_log(sb, profilenm, cfg);
1301 GOTO(out_debugfs, err);
1303 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1304 lprof = class_get_profile(profilenm);
1305 if (lprof == NULL) {
1306 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1307 " read from the MGS. Does that filesystem "
1308 "exist?\n", profilenm);
1309 GOTO(out_debugfs, err = -EINVAL);
1311 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1312 lprof->lp_md, lprof->lp_dt);
1314 dt_len = strlen(lprof->lp_dt) + instlen + 2;
1315 OBD_ALLOC(dt, dt_len);
1317 GOTO(out_profile, err = -ENOMEM);
1318 snprintf(dt, dt_len - 1, "%s-%016lx", lprof->lp_dt, cfg_instance);
1320 md_len = strlen(lprof->lp_md) + instlen + 2;
1321 OBD_ALLOC(md, md_len);
1323 GOTO(out_free_dt, err = -ENOMEM);
1324 snprintf(md, md_len - 1, "%s-%016lx", lprof->lp_md, cfg_instance);
1326 /* connections, registrations, sb setup */
1327 err = client_common_fill_super(sb, md, dt);
1329 GOTO(out_free_md, err);
1331 sbi->ll_client_common_fill_super_succeeded = 1;
1335 OBD_FREE(md, md_len);
1338 OBD_FREE(dt, dt_len);
1341 class_put_profile(lprof);
1344 ll_debugfs_unregister_super(sb);
1351 else if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1352 LCONSOLE_WARN("Mounted %s\n", profilenm);
1354 } /* ll_fill_super */
1356 void ll_put_super(struct super_block *sb)
1358 struct config_llog_instance cfg, params_cfg;
1359 struct obd_device *obd;
1360 struct lustre_sb_info *lsi = s2lsi(sb);
1361 struct ll_sb_info *sbi = ll_s2sbi(sb);
1362 char *profilenm = get_profile_name(sb);
1363 unsigned long cfg_instance = ll_get_cfg_instance(sb);
1365 int next, force = 1, rc = 0;
1369 GOTO(out_no_sbi, 0);
1371 /* Should replace instance_id with something better for ASLR */
1372 CDEBUG(D_VFSTRACE, "VFS Op: cfg_instance %s-%016lx (sb %p)\n",
1373 profilenm, cfg_instance, sb);
1375 cfg.cfg_instance = cfg_instance;
1376 lustre_end_log(sb, profilenm, &cfg);
1378 params_cfg.cfg_instance = cfg_instance;
1379 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
1381 if (sbi->ll_md_exp) {
1382 obd = class_exp2obd(sbi->ll_md_exp);
1384 force = obd->obd_force;
1387 /* Wait for unstable pages to be committed to stable storage */
1389 rc = l_wait_event_abortable(
1390 sbi->ll_cache->ccc_unstable_waitq,
1391 atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0);
1394 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1395 if (force == 0 && rc != -ERESTARTSYS)
1396 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1398 /* We need to set force before the lov_disconnect in
1399 * lustre_common_put_super, since l_d cleans up osc's as well.
1403 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1405 obd->obd_force = force;
1409 if (sbi->ll_client_common_fill_super_succeeded) {
1410 /* Only if client_common_fill_super succeeded */
1411 client_common_put_super(sb);
1415 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1416 class_manual_cleanup(obd);
1418 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
1419 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1422 class_del_profile(profilenm);
1424 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1425 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1426 bdi_destroy(&lsi->lsi_bdi);
1427 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1432 lsi->lsi_llsbi = NULL;
1434 lustre_common_put_super(sb);
1436 cl_env_cache_purge(~0);
1439 } /* client_put_super */
1441 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1443 struct inode *inode = NULL;
1445 /* NOTE: we depend on atomic igrab() -bzzz */
1446 lock_res_and_lock(lock);
1447 if (lock->l_resource->lr_lvb_inode) {
1448 struct ll_inode_info * lli;
1449 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1450 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1451 inode = igrab(lock->l_resource->lr_lvb_inode);
1453 inode = lock->l_resource->lr_lvb_inode;
1454 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1455 D_WARNING, lock, "lr_lvb_inode %p is "
1456 "bogus: magic %08x",
1457 lock->l_resource->lr_lvb_inode,
1458 lli->lli_inode_magic);
1462 unlock_res_and_lock(lock);
1466 void ll_dir_clear_lsm_md(struct inode *inode)
1468 struct ll_inode_info *lli = ll_i2info(inode);
1470 LASSERT(S_ISDIR(inode->i_mode));
1472 if (lli->lli_lsm_md) {
1473 lmv_free_memmd(lli->lli_lsm_md);
1474 lli->lli_lsm_md = NULL;
1477 if (lli->lli_default_lsm_md) {
1478 lmv_free_memmd(lli->lli_default_lsm_md);
1479 lli->lli_default_lsm_md = NULL;
1483 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1484 const struct lu_fid *fid,
1485 struct lustre_md *md)
1487 struct ll_sb_info *sbi = ll_s2sbi(sb);
1488 struct ll_inode_info *lli;
1489 struct mdt_body *body = md->body;
1490 struct inode *inode;
1496 ino = cl_fid_build_ino(fid, test_bit(LL_SBI_32BIT_API, sbi->ll_flags));
1497 inode = iget_locked(sb, ino);
1498 if (inode == NULL) {
1499 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1500 sbi->ll_fsname, PFID(fid));
1501 RETURN(ERR_PTR(-ENOENT));
1504 lli = ll_i2info(inode);
1505 if (inode->i_state & I_NEW) {
1506 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1507 (body->mbo_mode & S_IFMT);
1508 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1511 inode->i_mtime.tv_sec = 0;
1512 inode->i_atime.tv_sec = 0;
1513 inode->i_ctime.tv_sec = 0;
1516 #ifdef HAVE_BACKING_DEV_INFO
1517 /* initializing backing dev info. */
1518 inode->i_mapping->backing_dev_info =
1519 &s2lsi(inode->i_sb)->lsi_bdi;
1521 inode->i_op = &ll_dir_inode_operations;
1522 inode->i_fop = &ll_dir_operations;
1523 lli->lli_fid = *fid;
1526 /* master object FID */
1527 lli->lli_pfid = body->mbo_fid1;
1528 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1529 lli, PFID(fid), PFID(&lli->lli_pfid));
1530 unlock_new_inode(inode);
1532 /* in directory restripe/auto-split, a directory will be
1533 * transformed to a stripe if it's plain, set its pfid here,
1534 * otherwise ll_lock_cancel_bits() can't find the master inode.
1536 lli->lli_pfid = body->mbo_fid1;
1542 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1545 struct lmv_stripe_md *lsm = md->lmv;
1546 struct ll_inode_info *lli = ll_i2info(inode);
1549 LASSERT(lsm != NULL);
1551 CDEBUG(D_INODE, "%s: "DFID" set dir layout:\n",
1552 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1553 lsm_md_dump(D_INODE, lsm);
1555 if (!lmv_dir_striped(lsm))
1558 /* XXX sigh, this lsm_root initialization should be in
1559 * LMV layer, but it needs ll_iget right now, so we
1560 * put this here right now. */
1561 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1562 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1563 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1565 if (!fid_is_sane(fid))
1568 /* Unfortunately ll_iget will call ll_update_inode,
1569 * where the initialization of slave inode is slightly
1570 * different, so it reset lsm_md to NULL to avoid
1571 * initializing lsm for slave inode. */
1572 lsm->lsm_md_oinfo[i].lmo_root =
1573 ll_iget_anon_dir(inode->i_sb, fid, md);
1574 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1575 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1577 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1579 iput(lsm->lsm_md_oinfo[i].lmo_root);
1580 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1586 lli->lli_lsm_md = lsm;
1591 static void ll_update_default_lsm_md(struct inode *inode, struct lustre_md *md)
1593 struct ll_inode_info *lli = ll_i2info(inode);
1597 if (!md->default_lmv) {
1598 /* clear default lsm */
1599 if (lli->lli_default_lsm_md) {
1600 down_write(&lli->lli_lsm_sem);
1601 if (lli->lli_default_lsm_md) {
1602 lmv_free_memmd(lli->lli_default_lsm_md);
1603 lli->lli_default_lsm_md = NULL;
1605 up_write(&lli->lli_lsm_sem);
1610 if (lli->lli_default_lsm_md) {
1611 /* do nonthing if default lsm isn't changed */
1612 down_read(&lli->lli_lsm_sem);
1613 if (lli->lli_default_lsm_md &&
1614 lsm_md_eq(lli->lli_default_lsm_md, md->default_lmv)) {
1615 up_read(&lli->lli_lsm_sem);
1618 up_read(&lli->lli_lsm_sem);
1621 down_write(&lli->lli_lsm_sem);
1622 if (lli->lli_default_lsm_md)
1623 lmv_free_memmd(lli->lli_default_lsm_md);
1624 lli->lli_default_lsm_md = md->default_lmv;
1625 lsm_md_dump(D_INODE, md->default_lmv);
1626 md->default_lmv = NULL;
1627 up_write(&lli->lli_lsm_sem);
1631 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1633 struct ll_inode_info *lli = ll_i2info(inode);
1634 struct lmv_stripe_md *lsm = md->lmv;
1635 struct cl_attr *attr;
1640 LASSERT(S_ISDIR(inode->i_mode));
1641 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1642 PFID(ll_inode2fid(inode)));
1644 /* update default LMV */
1645 if (md->default_lmv)
1646 ll_update_default_lsm_md(inode, md);
1648 /* after dir migration/restripe, a stripe may be turned into a
1649 * directory, in this case, zero out its lli_pfid.
1651 if (unlikely(fid_is_norm(&lli->lli_pfid)))
1652 fid_zero(&lli->lli_pfid);
1655 * no striped information from request, lustre_md from req does not
1656 * include stripeEA, see ll_md_setattr()
1662 * normally dir layout doesn't change, only take read lock to check
1663 * that to avoid blocking other MD operations.
1665 down_read(&lli->lli_lsm_sem);
1667 /* some current lookup initialized lsm, and unchanged */
1668 if (lli->lli_lsm_md && lsm_md_eq(lli->lli_lsm_md, lsm))
1669 GOTO(unlock, rc = 0);
1671 /* if dir layout doesn't match, check whether version is increased,
1672 * which means layout is changed, this happens in dir split/merge and
1675 * foreign LMV should not change.
1677 if (lli->lli_lsm_md && lmv_dir_striped(lli->lli_lsm_md) &&
1678 lsm->lsm_md_layout_version <=
1679 lli->lli_lsm_md->lsm_md_layout_version) {
1680 CERROR("%s: "DFID" dir layout mismatch:\n",
1681 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid));
1682 lsm_md_dump(D_ERROR, lli->lli_lsm_md);
1683 lsm_md_dump(D_ERROR, lsm);
1684 GOTO(unlock, rc = -EINVAL);
1687 up_read(&lli->lli_lsm_sem);
1688 down_write(&lli->lli_lsm_sem);
1689 /* clear existing lsm */
1690 if (lli->lli_lsm_md) {
1691 lmv_free_memmd(lli->lli_lsm_md);
1692 lli->lli_lsm_md = NULL;
1695 rc = ll_init_lsm_md(inode, md);
1696 up_write(&lli->lli_lsm_sem);
1701 /* set md->lmv to NULL, so the following free lustre_md will not free
1706 /* md_merge_attr() may take long, since lsm is already set, switch to
1709 down_read(&lli->lli_lsm_sem);
1711 if (!lmv_dir_striped(lli->lli_lsm_md))
1712 GOTO(unlock, rc = 0);
1714 OBD_ALLOC_PTR(attr);
1716 GOTO(unlock, rc = -ENOMEM);
1718 /* validate the lsm */
1719 rc = md_merge_attr(ll_i2mdexp(inode), lli->lli_lsm_md, attr,
1720 ll_md_blocking_ast);
1722 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1723 md->body->mbo_nlink = attr->cat_nlink;
1724 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1725 md->body->mbo_size = attr->cat_size;
1726 if (md->body->mbo_valid & OBD_MD_FLATIME)
1727 md->body->mbo_atime = attr->cat_atime;
1728 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1729 md->body->mbo_ctime = attr->cat_ctime;
1730 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1731 md->body->mbo_mtime = attr->cat_mtime;
1737 up_read(&lli->lli_lsm_sem);
1742 void ll_clear_inode(struct inode *inode)
1744 struct ll_inode_info *lli = ll_i2info(inode);
1745 struct ll_sb_info *sbi = ll_i2sbi(inode);
1749 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1750 PFID(ll_inode2fid(inode)), inode);
1752 if (S_ISDIR(inode->i_mode)) {
1753 /* these should have been cleared in ll_file_release */
1754 LASSERT(lli->lli_opendir_key == NULL);
1755 LASSERT(lli->lli_sai == NULL);
1756 LASSERT(lli->lli_opendir_pid == 0);
1758 pcc_inode_free(inode);
1761 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1763 LASSERT(!lli->lli_open_fd_write_count);
1764 LASSERT(!lli->lli_open_fd_read_count);
1765 LASSERT(!lli->lli_open_fd_exec_count);
1767 if (lli->lli_mds_write_och)
1768 ll_md_real_close(inode, FMODE_WRITE);
1769 if (lli->lli_mds_exec_och)
1770 ll_md_real_close(inode, FMODE_EXEC);
1771 if (lli->lli_mds_read_och)
1772 ll_md_real_close(inode, FMODE_READ);
1774 if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1775 OBD_FREE(lli->lli_symlink_name,
1776 strlen(lli->lli_symlink_name) + 1);
1777 lli->lli_symlink_name = NULL;
1780 ll_xattr_cache_destroy(inode);
1782 forget_all_cached_acls(inode);
1784 lli->lli_inode_magic = LLI_INODE_DEAD;
1786 if (S_ISDIR(inode->i_mode))
1787 ll_dir_clear_lsm_md(inode);
1788 else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1789 LASSERT(list_empty(&lli->lli_agl_list));
1792 * XXX This has to be done before lsm is freed below, because
1793 * cl_object still uses inode lsm.
1795 cl_inode_fini(inode);
1797 llcrypt_put_encryption_info(inode);
1802 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1804 struct lustre_md md;
1805 struct inode *inode = dentry->d_inode;
1806 struct ll_sb_info *sbi = ll_i2sbi(inode);
1807 struct ptlrpc_request *request = NULL;
1812 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1813 LUSTRE_OPC_ANY, NULL);
1814 if (IS_ERR(op_data))
1815 RETURN(PTR_ERR(op_data));
1817 /* If this is a chgrp of a regular file, we want to reserve enough
1818 * quota to cover the entire file size.
1820 if (S_ISREG(inode->i_mode) && op_data->op_attr.ia_valid & ATTR_GID &&
1821 from_kgid(&init_user_ns, op_data->op_attr.ia_gid) !=
1822 from_kgid(&init_user_ns, inode->i_gid)) {
1823 op_data->op_xvalid |= OP_XVALID_BLOCKS;
1824 op_data->op_attr_blocks = inode->i_blocks;
1828 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1830 ptlrpc_req_finished(request);
1831 if (rc == -ENOENT) {
1833 /* Unlinked special device node? Or just a race?
1834 * Pretend we done everything. */
1835 if (!S_ISREG(inode->i_mode) &&
1836 !S_ISDIR(inode->i_mode)) {
1837 ia_valid = op_data->op_attr.ia_valid;
1838 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1839 rc = simple_setattr(dentry, &op_data->op_attr);
1840 op_data->op_attr.ia_valid = ia_valid;
1842 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1843 CERROR("md_setattr fails: rc = %d\n", rc);
1848 rc = md_get_lustre_md(sbi->ll_md_exp, &request->rq_pill, sbi->ll_dt_exp,
1849 sbi->ll_md_exp, &md);
1851 ptlrpc_req_finished(request);
1855 ia_valid = op_data->op_attr.ia_valid;
1856 /* inode size will be in ll_setattr_ost, can't do it now since dirty
1857 * cache is not cleared yet. */
1858 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1859 if (S_ISREG(inode->i_mode))
1861 rc = simple_setattr(dentry, &op_data->op_attr);
1862 if (S_ISREG(inode->i_mode))
1863 inode_unlock(inode);
1864 op_data->op_attr.ia_valid = ia_valid;
1866 rc = ll_update_inode(inode, &md);
1867 ptlrpc_req_finished(request);
1873 * Zero portion of page that is part of @inode.
1874 * This implies, if necessary:
1875 * - taking cl_lock on range corresponding to concerned page
1876 * - grabbing vm page
1877 * - associating cl_page
1878 * - proceeding to clio read
1879 * - zeroing range in page
1880 * - proceeding to cl_page flush
1881 * - releasing cl_lock
1883 * \param[in] inode inode
1884 * \param[in] index page index
1885 * \param[in] offset offset in page to start zero from
1886 * \param[in] len len to zero
1888 * \retval 0 on success
1889 * \retval negative errno on failure
1891 int ll_io_zero_page(struct inode *inode, pgoff_t index, pgoff_t offset,
1894 struct ll_inode_info *lli = ll_i2info(inode);
1895 struct cl_object *clob = lli->lli_clob;
1897 struct lu_env *env = NULL;
1898 struct cl_io *io = NULL;
1899 struct cl_page *clpage = NULL;
1900 struct page *vmpage = NULL;
1901 unsigned from = index << PAGE_SHIFT;
1902 struct cl_lock *lock = NULL;
1903 struct cl_lock_descr *descr = NULL;
1904 struct cl_2queue *queue = NULL;
1905 struct cl_sync_io *anchor = NULL;
1906 bool holdinglock = false;
1907 bool lockedbymyself = true;
1912 env = cl_env_get(&refcheck);
1914 RETURN(PTR_ERR(env));
1916 io = vvp_env_thread_io(env);
1918 rc = cl_io_rw_init(env, io, CIT_WRITE, from, PAGE_SIZE);
1922 lock = vvp_env_lock(env);
1923 descr = &lock->cll_descr;
1924 descr->cld_obj = io->ci_obj;
1925 descr->cld_start = cl_index(io->ci_obj, from);
1926 descr->cld_end = cl_index(io->ci_obj, from + PAGE_SIZE - 1);
1927 descr->cld_mode = CLM_WRITE;
1928 descr->cld_enq_flags = CEF_MUST | CEF_NONBLOCK;
1930 /* request lock for page */
1931 rc = cl_lock_request(env, io, lock);
1932 /* -ECANCELED indicates a matching lock with a different extent
1933 * was already present, and -EEXIST indicates a matching lock
1934 * on exactly the same extent was already present.
1935 * In both cases it means we are covered.
1937 if (rc == -ECANCELED || rc == -EEXIST)
1945 vmpage = grab_cache_page_nowait(inode->i_mapping, index);
1947 GOTO(rellock, rc = -EOPNOTSUPP);
1949 if (!PageDirty(vmpage)) {
1950 /* associate cl_page */
1951 clpage = cl_page_find(env, clob, vmpage->index,
1952 vmpage, CPT_CACHEABLE);
1954 GOTO(pagefini, rc = PTR_ERR(clpage));
1956 cl_page_assume(env, io, clpage);
1959 if (!PageUptodate(vmpage) && !PageDirty(vmpage) &&
1960 !PageWriteback(vmpage)) {
1962 /* set PagePrivate2 to detect special case of empty page
1963 * in osc_brw_fini_request()
1965 SetPagePrivate2(vmpage);
1966 rc = ll_io_read_page(env, io, clpage, NULL);
1967 if (!PagePrivate2(vmpage))
1968 /* PagePrivate2 was cleared in osc_brw_fini_request()
1969 * meaning we read an empty page. In this case, in order
1970 * to avoid allocating unnecessary block in truncated
1971 * file, we must not zero and write as below. Subsequent
1972 * server-side truncate will handle things correctly.
1974 GOTO(clpfini, rc = 0);
1975 ClearPagePrivate2(vmpage);
1978 lockedbymyself = trylock_page(vmpage);
1979 cl_page_assume(env, io, clpage);
1982 /* zero range in page */
1983 zero_user(vmpage, offset, len);
1985 if (holdinglock && clpage) {
1986 /* explicitly write newly modified page */
1987 queue = &io->ci_queue;
1988 cl_2queue_init(queue);
1989 anchor = &vvp_env_info(env)->vti_anchor;
1990 cl_sync_io_init(anchor, 1);
1991 clpage->cp_sync_io = anchor;
1992 cl_2queue_add(queue, clpage, true);
1993 rc = cl_io_submit_rw(env, io, CRT_WRITE, queue);
1995 GOTO(queuefini1, rc);
1996 rc = cl_sync_io_wait(env, anchor, 0);
1998 GOTO(queuefini2, rc);
1999 cl_page_assume(env, io, clpage);
2002 cl_2queue_discard(env, io, queue);
2004 cl_2queue_disown(env, io, queue);
2005 cl_2queue_fini(env, queue);
2010 cl_page_put(env, clpage);
2012 if (lockedbymyself) {
2013 unlock_page(vmpage);
2018 cl_lock_release(env, lock);
2020 cl_io_fini(env, io);
2023 cl_env_put(env, &refcheck);
2028 /* If this inode has objects allocated to it (lsm != NULL), then the OST
2029 * object(s) determine the file size and mtime. Otherwise, the MDS will
2030 * keep these values until such a time that objects are allocated for it.
2031 * We do the MDS operations first, as it is checking permissions for us.
2032 * We don't to the MDS RPC if there is nothing that we want to store there,
2033 * otherwise there is no harm in updating mtime/atime on the MDS if we are
2034 * going to do an RPC anyways.
2036 * If we are doing a truncate, we will send the mtime and ctime updates
2037 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
2038 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
2041 * In case of HSMimport, we only set attr on MDS.
2043 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr,
2044 enum op_xvalid xvalid, bool hsm_import)
2046 struct inode *inode = dentry->d_inode;
2047 struct ll_inode_info *lli = ll_i2info(inode);
2048 struct md_op_data *op_data = NULL;
2049 ktime_t kstart = ktime_get();
2054 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
2055 "valid %x, hsm_import %d\n",
2056 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
2057 inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
2060 if (attr->ia_valid & ATTR_SIZE) {
2061 /* Check new size against VFS/VM file size limit and rlimit */
2062 rc = inode_newsize_ok(inode, attr->ia_size);
2066 /* The maximum Lustre file size is variable, based on the
2067 * OST maximum object size and number of stripes. This
2068 * needs another check in addition to the VFS check above. */
2069 if (attr->ia_size > ll_file_maxbytes(inode)) {
2070 CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
2071 PFID(&lli->lli_fid), attr->ia_size,
2072 ll_file_maxbytes(inode));
2076 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
2079 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
2080 if (attr->ia_valid & TIMES_SET_FLAGS) {
2081 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
2082 !capable(CAP_FOWNER))
2086 /* We mark all of the fields "set" so MDS/OST does not re-set them */
2087 if (!(xvalid & OP_XVALID_CTIME_SET) &&
2088 (attr->ia_valid & ATTR_CTIME)) {
2089 attr->ia_ctime = current_time(inode);
2090 xvalid |= OP_XVALID_CTIME_SET;
2092 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
2093 (attr->ia_valid & ATTR_ATIME)) {
2094 attr->ia_atime = current_time(inode);
2095 attr->ia_valid |= ATTR_ATIME_SET;
2097 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
2098 (attr->ia_valid & ATTR_MTIME)) {
2099 attr->ia_mtime = current_time(inode);
2100 attr->ia_valid |= ATTR_MTIME_SET;
2103 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
2104 CDEBUG(D_INODE, "setting mtime %lld, ctime %lld, now = %lld\n",
2105 (s64)attr->ia_mtime.tv_sec, (s64)attr->ia_ctime.tv_sec,
2106 ktime_get_real_seconds());
2108 if (S_ISREG(inode->i_mode))
2109 inode_unlock(inode);
2111 /* We always do an MDS RPC, even if we're only changing the size;
2112 * only the MDS knows whether truncate() should fail with -ETXTBUSY */
2114 OBD_ALLOC_PTR(op_data);
2115 if (op_data == NULL)
2116 GOTO(out, rc = -ENOMEM);
2118 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
2119 /* If we are changing file size, file content is
2120 * modified, flag it.
2122 xvalid |= OP_XVALID_OWNEROVERRIDE;
2123 op_data->op_bias |= MDS_DATA_MODIFIED;
2124 clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags);
2127 if (attr->ia_valid & ATTR_FILE) {
2128 struct ll_file_data *fd = attr->ia_file->private_data;
2130 if (fd->fd_lease_och)
2131 op_data->op_bias |= MDS_TRUNC_KEEP_LEASE;
2134 op_data->op_attr = *attr;
2135 op_data->op_xvalid = xvalid;
2137 rc = ll_md_setattr(dentry, op_data);
2141 if (!S_ISREG(inode->i_mode) || hsm_import)
2144 if (attr->ia_valid & (ATTR_SIZE | ATTR_ATIME | ATTR_ATIME_SET |
2145 ATTR_MTIME | ATTR_MTIME_SET | ATTR_CTIME) ||
2146 xvalid & OP_XVALID_CTIME_SET) {
2147 bool cached = false;
2149 rc = pcc_inode_setattr(inode, attr, &cached);
2152 CERROR("%s: PCC inode "DFID" setattr failed: "
2154 ll_i2sbi(inode)->ll_fsname,
2155 PFID(&lli->lli_fid), rc);
2159 unsigned int flags = 0;
2161 /* For truncate and utimes sending attributes to OSTs,
2162 * setting mtime/atime to the past will be performed
2163 * under PW [0:EOF] extent lock (new_size:EOF for
2164 * truncate). It may seem excessive to send mtime/atime
2165 * updates to OSTs when not setting times to past, but
2166 * it is necessary due to possible time
2167 * de-synchronization between MDT inode and OST objects
2169 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
2170 xvalid |= OP_XVALID_FLAGS;
2171 flags = LUSTRE_ENCRYPT_FL;
2172 /* Call to ll_io_zero_page is not necessary if
2173 * truncating on PAGE_SIZE boundary, because
2174 * whole pages will be wiped.
2175 * In case of Direct IO, all we need is to set
2178 if (attr->ia_valid & ATTR_SIZE &&
2179 attr->ia_size & ~PAGE_MASK &&
2180 !(attr->ia_valid & ATTR_FILE &&
2181 attr->ia_file->f_flags & O_DIRECT)) {
2183 attr->ia_size & (PAGE_SIZE - 1);
2185 rc = ll_io_zero_page(inode,
2186 attr->ia_size >> PAGE_SHIFT,
2187 offset, PAGE_SIZE - offset);
2192 rc = cl_setattr_ost(lli->lli_clob, attr, xvalid, flags);
2196 /* If the file was restored, it needs to set dirty flag.
2198 * We've already sent MDS_DATA_MODIFIED flag in
2199 * ll_md_setattr() for truncate. However, the MDT refuses to
2200 * set the HS_DIRTY flag on released files, so we have to set
2201 * it again if the file has been restored. Please check how
2202 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
2204 * Please notice that if the file is not released, the previous
2205 * MDS_DATA_MODIFIED has taken effect and usually
2206 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
2207 * This way we can save an RPC for common open + trunc
2209 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
2210 struct hsm_state_set hss = {
2211 .hss_valid = HSS_SETMASK,
2212 .hss_setmask = HS_DIRTY,
2216 rc2 = ll_hsm_state_set(inode, &hss);
2217 /* truncate and write can happen at the same time, so that
2218 * the file can be set modified even though the file is not
2219 * restored from released state, and ll_hsm_state_set() is
2220 * not applicable for the file, and rc2 < 0 is normal in this
2223 CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
2224 PFID(ll_inode2fid(inode)), rc2);
2229 if (op_data != NULL)
2230 ll_finish_md_op_data(op_data);
2232 if (S_ISREG(inode->i_mode)) {
2234 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
2235 inode_dio_wait(inode);
2236 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
2237 * flag. ll_update_inode (called from ll_md_setattr), clears
2238 * inode flags, so there is a gap where S_NOSEC is not set.
2239 * This can cause a writer to take the i_mutex unnecessarily,
2240 * but this is safe to do and should be rare. */
2241 inode_has_no_xattr(inode);
2245 ll_stats_ops_tally(ll_i2sbi(inode), attr->ia_valid & ATTR_SIZE ?
2246 LPROC_LL_TRUNC : LPROC_LL_SETATTR,
2247 ktime_us_delta(ktime_get(), kstart));
2252 int ll_setattr(struct dentry *de, struct iattr *attr)
2254 int mode = de->d_inode->i_mode;
2255 enum op_xvalid xvalid = 0;
2258 rc = llcrypt_prepare_setattr(de, attr);
2262 if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
2263 (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
2264 xvalid |= OP_XVALID_OWNEROVERRIDE;
2266 if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
2267 (ATTR_SIZE|ATTR_MODE)) &&
2268 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
2269 (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2270 !(attr->ia_mode & S_ISGID))))
2271 attr->ia_valid |= ATTR_FORCE;
2273 if ((attr->ia_valid & ATTR_MODE) &&
2275 !(attr->ia_mode & S_ISUID) &&
2276 !(attr->ia_valid & ATTR_KILL_SUID))
2277 attr->ia_valid |= ATTR_KILL_SUID;
2279 if ((attr->ia_valid & ATTR_MODE) &&
2280 ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
2281 !(attr->ia_mode & S_ISGID) &&
2282 !(attr->ia_valid & ATTR_KILL_SGID))
2283 attr->ia_valid |= ATTR_KILL_SGID;
2285 return ll_setattr_raw(de, attr, xvalid, false);
2288 int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
2291 struct obd_statfs obd_osfs = { 0 };
2296 max_age = ktime_get_seconds() - sbi->ll_statfs_max_age;
2298 if (test_bit(LL_SBI_LAZYSTATFS, sbi->ll_flags))
2299 flags |= OBD_STATFS_NODELAY;
2301 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
2305 osfs->os_type = LL_SUPER_MAGIC;
2307 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
2308 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree, osfs->os_files);
2310 if (osfs->os_state & OS_STATFS_SUM)
2313 rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
2314 if (rc) /* Possibly a filesystem with no OSTs. Report MDT totals. */
2317 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
2318 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
2321 osfs->os_bsize = obd_osfs.os_bsize;
2322 osfs->os_blocks = obd_osfs.os_blocks;
2323 osfs->os_bfree = obd_osfs.os_bfree;
2324 osfs->os_bavail = obd_osfs.os_bavail;
2326 /* If we have _some_ OSTs, but don't have as many free objects on the
2327 * OSTs as inodes on the MDTs, reduce the reported number of inodes
2328 * to compensate, so that the "inodes in use" number is correct.
2329 * This should be kept in sync with lod_statfs() behaviour.
2331 if (obd_osfs.os_files && obd_osfs.os_ffree < osfs->os_ffree) {
2332 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
2334 osfs->os_ffree = obd_osfs.os_ffree;
2341 static int ll_statfs_project(struct inode *inode, struct kstatfs *sfs)
2343 struct if_quotactl qctl = {
2344 .qc_cmd = LUSTRE_Q_GETQUOTA,
2345 .qc_type = PRJQUOTA,
2346 .qc_valid = QC_GENERAL,
2348 u64 limit, curblock;
2351 qctl.qc_id = ll_i2info(inode)->lli_projid;
2352 ret = quotactl_ioctl(inode->i_sb, &qctl);
2354 /* ignore errors if project ID does not have
2355 * a quota limit or feature unsupported.
2357 if (ret == -ESRCH || ret == -EOPNOTSUPP)
2362 limit = ((qctl.qc_dqblk.dqb_bsoftlimit ?
2363 qctl.qc_dqblk.dqb_bsoftlimit :
2364 qctl.qc_dqblk.dqb_bhardlimit) * 1024) / sfs->f_bsize;
2365 if (limit && sfs->f_blocks > limit) {
2366 curblock = (qctl.qc_dqblk.dqb_curspace +
2367 sfs->f_bsize - 1) / sfs->f_bsize;
2368 sfs->f_blocks = limit;
2369 sfs->f_bfree = sfs->f_bavail =
2370 (sfs->f_blocks > curblock) ?
2371 (sfs->f_blocks - curblock) : 0;
2374 limit = qctl.qc_dqblk.dqb_isoftlimit ?
2375 qctl.qc_dqblk.dqb_isoftlimit :
2376 qctl.qc_dqblk.dqb_ihardlimit;
2377 if (limit && sfs->f_files > limit) {
2378 sfs->f_files = limit;
2379 sfs->f_ffree = (sfs->f_files >
2380 qctl.qc_dqblk.dqb_curinodes) ?
2381 (sfs->f_files - qctl.qc_dqblk.dqb_curinodes) : 0;
2387 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
2389 struct super_block *sb = de->d_sb;
2390 struct obd_statfs osfs;
2391 __u64 fsid = huge_encode_dev(sb->s_dev);
2392 ktime_t kstart = ktime_get();
2395 CDEBUG(D_VFSTRACE, "VFS Op:sb=%s (%p)\n", sb->s_id, sb);
2397 /* Some amount of caching on the client is allowed */
2398 rc = ll_statfs_internal(ll_s2sbi(sb), &osfs, OBD_STATFS_SUM);
2402 statfs_unpack(sfs, &osfs);
2404 /* We need to downshift for all 32-bit kernels, because we can't
2405 * tell if the kernel is being called via sys_statfs64() or not.
2406 * Stop before overflowing f_bsize - in which case it is better
2407 * to just risk EOVERFLOW if caller is using old sys_statfs(). */
2408 if (sizeof(long) < 8) {
2409 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
2412 osfs.os_blocks >>= 1;
2413 osfs.os_bfree >>= 1;
2414 osfs.os_bavail >>= 1;
2418 sfs->f_blocks = osfs.os_blocks;
2419 sfs->f_bfree = osfs.os_bfree;
2420 sfs->f_bavail = osfs.os_bavail;
2421 sfs->f_fsid.val[0] = (__u32)fsid;
2422 sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
2423 if (ll_i2info(de->d_inode)->lli_projid)
2424 return ll_statfs_project(de->d_inode, sfs);
2426 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STATFS,
2427 ktime_us_delta(ktime_get(), kstart));
2432 void ll_inode_size_lock(struct inode *inode)
2434 struct ll_inode_info *lli;
2436 LASSERT(!S_ISDIR(inode->i_mode));
2438 lli = ll_i2info(inode);
2439 mutex_lock(&lli->lli_size_mutex);
2442 void ll_inode_size_unlock(struct inode *inode)
2444 struct ll_inode_info *lli;
2446 lli = ll_i2info(inode);
2447 mutex_unlock(&lli->lli_size_mutex);
2450 void ll_update_inode_flags(struct inode *inode, unsigned int ext_flags)
2452 /* do not clear encryption flag */
2453 ext_flags |= ll_inode_to_ext_flags(inode->i_flags) & LUSTRE_ENCRYPT_FL;
2454 inode->i_flags = ll_ext_to_inode_flags(ext_flags);
2455 if (ext_flags & LUSTRE_PROJINHERIT_FL)
2456 set_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2458 clear_bit(LLIF_PROJECT_INHERIT, &ll_i2info(inode)->lli_flags);
2461 int ll_update_inode(struct inode *inode, struct lustre_md *md)
2463 struct ll_inode_info *lli = ll_i2info(inode);
2464 struct mdt_body *body = md->body;
2465 struct ll_sb_info *sbi = ll_i2sbi(inode);
2469 if (body->mbo_valid & OBD_MD_FLEASIZE) {
2470 rc = cl_file_inode_init(inode, md);
2475 if (S_ISDIR(inode->i_mode)) {
2476 rc = ll_update_lsm_md(inode, md);
2481 if (body->mbo_valid & OBD_MD_FLACL)
2482 lli_replace_acl(lli, md);
2484 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2485 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1, api32);
2486 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
2488 if (body->mbo_valid & OBD_MD_FLATIME) {
2489 if (body->mbo_atime > inode->i_atime.tv_sec)
2490 inode->i_atime.tv_sec = body->mbo_atime;
2491 lli->lli_atime = body->mbo_atime;
2494 if (body->mbo_valid & OBD_MD_FLMTIME) {
2495 if (body->mbo_mtime > inode->i_mtime.tv_sec) {
2497 "setting ino %lu mtime from %lld to %llu\n",
2498 inode->i_ino, (s64)inode->i_mtime.tv_sec,
2500 inode->i_mtime.tv_sec = body->mbo_mtime;
2502 lli->lli_mtime = body->mbo_mtime;
2505 if (body->mbo_valid & OBD_MD_FLCTIME) {
2506 if (body->mbo_ctime > inode->i_ctime.tv_sec)
2507 inode->i_ctime.tv_sec = body->mbo_ctime;
2508 lli->lli_ctime = body->mbo_ctime;
2511 if (body->mbo_valid & OBD_MD_FLBTIME)
2512 lli->lli_btime = body->mbo_btime;
2514 /* Clear i_flags to remove S_NOSEC before permissions are updated */
2515 if (body->mbo_valid & OBD_MD_FLFLAGS)
2516 ll_update_inode_flags(inode, body->mbo_flags);
2517 if (body->mbo_valid & OBD_MD_FLMODE)
2518 inode->i_mode = (inode->i_mode & S_IFMT) |
2519 (body->mbo_mode & ~S_IFMT);
2521 if (body->mbo_valid & OBD_MD_FLTYPE)
2522 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2523 (body->mbo_mode & S_IFMT);
2525 LASSERT(inode->i_mode != 0);
2526 if (body->mbo_valid & OBD_MD_FLUID)
2527 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
2528 if (body->mbo_valid & OBD_MD_FLGID)
2529 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
2530 if (body->mbo_valid & OBD_MD_FLPROJID)
2531 lli->lli_projid = body->mbo_projid;
2532 if (body->mbo_valid & OBD_MD_FLNLINK) {
2533 spin_lock(&inode->i_lock);
2534 set_nlink(inode, body->mbo_nlink);
2535 spin_unlock(&inode->i_lock);
2537 if (body->mbo_valid & OBD_MD_FLRDEV)
2538 inode->i_rdev = old_decode_dev(body->mbo_rdev);
2540 if (body->mbo_valid & OBD_MD_FLID) {
2541 /* FID shouldn't be changed! */
2542 if (fid_is_sane(&lli->lli_fid)) {
2543 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
2544 "Trying to change FID "DFID
2545 " to the "DFID", inode "DFID"(%p)\n",
2546 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
2547 PFID(ll_inode2fid(inode)), inode);
2549 lli->lli_fid = body->mbo_fid1;
2553 LASSERT(fid_seq(&lli->lli_fid) != 0);
2555 lli->lli_attr_valid = body->mbo_valid;
2556 if (body->mbo_valid & OBD_MD_FLSIZE) {
2557 i_size_write(inode, body->mbo_size);
2559 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
2560 PFID(ll_inode2fid(inode)),
2561 (unsigned long long)body->mbo_size);
2563 if (body->mbo_valid & OBD_MD_FLBLOCKS)
2564 inode->i_blocks = body->mbo_blocks;
2566 if (body->mbo_valid & OBD_MD_FLLAZYSIZE)
2567 lli->lli_lazysize = body->mbo_size;
2568 if (body->mbo_valid & OBD_MD_FLLAZYBLOCKS)
2569 lli->lli_lazyblocks = body->mbo_blocks;
2572 if (body->mbo_valid & OBD_MD_TSTATE) {
2573 /* Set LLIF_FILE_RESTORING if restore ongoing and
2574 * clear it when done to ensure to start again
2575 * glimpsing updated attrs
2577 if (body->mbo_t_state & MS_RESTORE)
2578 set_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2580 clear_bit(LLIF_FILE_RESTORING, &lli->lli_flags);
2586 /* update directory depth to ROOT, called after LOOKUP lock is fetched. */
2587 void ll_update_dir_depth(struct inode *dir, struct inode *inode)
2589 struct ll_inode_info *lli;
2591 if (!S_ISDIR(inode->i_mode))
2597 lli = ll_i2info(inode);
2598 lli->lli_depth = ll_i2info(dir)->lli_depth + 1;
2599 CDEBUG(D_INODE, DFID" depth %hu\n", PFID(&lli->lli_fid), lli->lli_depth);
2602 void ll_truncate_inode_pages_final(struct inode *inode)
2604 struct address_space *mapping = &inode->i_data;
2605 unsigned long nrpages;
2606 unsigned long flags;
2608 truncate_inode_pages_final(mapping);
2610 /* Workaround for LU-118: Note nrpages may not be totally updated when
2611 * truncate_inode_pages() returns, as there can be a page in the process
2612 * of deletion (inside __delete_from_page_cache()) in the specified
2613 * range. Thus mapping->nrpages can be non-zero when this function
2614 * returns even after truncation of the whole mapping. Only do this if
2615 * npages isn't already zero.
2617 nrpages = mapping->nrpages;
2619 ll_xa_lock_irqsave(&mapping->i_pages, flags);
2620 nrpages = mapping->nrpages;
2621 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
2622 } /* Workaround end */
2624 LASSERTF(nrpages == 0, "%s: inode="DFID"(%p) nrpages=%lu, "
2625 "see https://jira.whamcloud.com/browse/LU-118\n",
2626 ll_i2sbi(inode)->ll_fsname,
2627 PFID(ll_inode2fid(inode)), inode, nrpages);
2630 int ll_read_inode2(struct inode *inode, void *opaque)
2632 struct lustre_md *md = opaque;
2633 struct ll_inode_info *lli = ll_i2info(inode);
2637 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
2638 PFID(&lli->lli_fid), inode);
2640 /* Core attributes from the MDS first. This is a new inode, and
2641 * the VFS doesn't zero times in the core inode so we have to do
2642 * it ourselves. They will be overwritten by either MDS or OST
2643 * attributes - we just need to make sure they aren't newer.
2645 inode->i_mtime.tv_sec = 0;
2646 inode->i_atime.tv_sec = 0;
2647 inode->i_ctime.tv_sec = 0;
2649 rc = ll_update_inode(inode, md);
2653 /* OIDEBUG(inode); */
2655 #ifdef HAVE_BACKING_DEV_INFO
2656 /* initializing backing dev info. */
2657 inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2659 if (S_ISREG(inode->i_mode)) {
2660 struct ll_sb_info *sbi = ll_i2sbi(inode);
2661 inode->i_op = &ll_file_inode_operations;
2662 inode->i_fop = sbi->ll_fop;
2663 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2665 } else if (S_ISDIR(inode->i_mode)) {
2666 inode->i_op = &ll_dir_inode_operations;
2667 inode->i_fop = &ll_dir_operations;
2669 } else if (S_ISLNK(inode->i_mode)) {
2670 inode->i_op = &ll_fast_symlink_inode_operations;
2673 inode->i_op = &ll_special_inode_operations;
2675 init_special_inode(inode, inode->i_mode,
2684 void ll_delete_inode(struct inode *inode)
2686 struct ll_inode_info *lli = ll_i2info(inode);
2689 if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL) {
2690 /* It is last chance to write out dirty pages,
2691 * otherwise we may lose data while umount.
2693 * If i_nlink is 0 then just discard data. This is safe because
2694 * local inode gets i_nlink 0 from server only for the last
2695 * unlink, so that file is not opened somewhere else
2697 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, inode->i_nlink ?
2698 CL_FSYNC_LOCAL : CL_FSYNC_DISCARD, 1);
2701 ll_truncate_inode_pages_final(inode);
2702 ll_clear_inode(inode);
2708 int ll_iocontrol(struct inode *inode, struct file *file,
2709 unsigned int cmd, unsigned long arg)
2711 struct ll_sb_info *sbi = ll_i2sbi(inode);
2712 struct ptlrpc_request *req = NULL;
2717 case FS_IOC_GETFLAGS: {
2718 struct mdt_body *body;
2719 struct md_op_data *op_data;
2721 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2722 0, 0, LUSTRE_OPC_ANY,
2724 if (IS_ERR(op_data))
2725 RETURN(PTR_ERR(op_data));
2727 op_data->op_valid = OBD_MD_FLFLAGS;
2728 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2729 ll_finish_md_op_data(op_data);
2731 CERROR("%s: failure inode "DFID": rc = %d\n",
2732 sbi->ll_md_exp->exp_obd->obd_name,
2733 PFID(ll_inode2fid(inode)), rc);
2737 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2739 flags = body->mbo_flags;
2741 ptlrpc_req_finished(req);
2743 RETURN(put_user(flags, (int __user *)arg));
2745 case FS_IOC_SETFLAGS: {
2747 struct md_op_data *op_data;
2748 struct cl_object *obj;
2749 struct fsxattr fa = { 0 };
2751 if (get_user(flags, (int __user *)arg))
2754 fa.fsx_projid = ll_i2info(inode)->lli_projid;
2755 if (flags & LUSTRE_PROJINHERIT_FL)
2756 fa.fsx_xflags = FS_XFLAG_PROJINHERIT;
2758 rc = ll_ioctl_check_project(inode, fa.fsx_xflags,
2763 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
2764 LUSTRE_OPC_ANY, NULL);
2765 if (IS_ERR(op_data))
2766 RETURN(PTR_ERR(op_data));
2768 op_data->op_attr_flags = flags;
2769 op_data->op_xvalid |= OP_XVALID_FLAGS;
2770 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
2771 ll_finish_md_op_data(op_data);
2772 ptlrpc_req_finished(req);
2776 ll_update_inode_flags(inode, flags);
2778 obj = ll_i2info(inode)->lli_clob;
2782 OBD_ALLOC_PTR(attr);
2786 rc = cl_setattr_ost(obj, attr, OP_XVALID_FLAGS, flags);
2798 int ll_flush_ctx(struct inode *inode)
2800 struct ll_sb_info *sbi = ll_i2sbi(inode);
2802 CDEBUG(D_SEC, "flush context for user %d\n",
2803 from_kuid(&init_user_ns, current_uid()));
2805 obd_set_info_async(NULL, sbi->ll_md_exp,
2806 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2808 obd_set_info_async(NULL, sbi->ll_dt_exp,
2809 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2814 /* umount -f client means force down, don't save state */
2815 void ll_umount_begin(struct super_block *sb)
2817 struct ll_sb_info *sbi = ll_s2sbi(sb);
2818 struct obd_device *obd;
2819 struct obd_ioctl_data *ioc_data;
2823 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2824 sb->s_count, atomic_read(&sb->s_active));
2826 obd = class_exp2obd(sbi->ll_md_exp);
2828 CERROR("Invalid MDC connection handle %#llx\n",
2829 sbi->ll_md_exp->exp_handle.h_cookie);
2835 obd = class_exp2obd(sbi->ll_dt_exp);
2837 CERROR("Invalid LOV connection handle %#llx\n",
2838 sbi->ll_dt_exp->exp_handle.h_cookie);
2844 OBD_ALLOC_PTR(ioc_data);
2846 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2847 sizeof *ioc_data, ioc_data, NULL);
2849 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2850 sizeof *ioc_data, ioc_data, NULL);
2852 OBD_FREE_PTR(ioc_data);
2855 /* Really, we'd like to wait until there are no requests outstanding,
2856 * and then continue. For now, we just periodically checking for vfs
2857 * to decrement mnt_cnt and hope to finish it within 10sec.
2861 !may_umount(sbi->ll_mnt.mnt)) {
2869 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2871 struct ll_sb_info *sbi = ll_s2sbi(sb);
2872 char *profilenm = get_profile_name(sb);
2876 if ((*flags & MS_RDONLY) != (sb->s_flags & SB_RDONLY)) {
2877 read_only = *flags & MS_RDONLY;
2878 err = obd_set_info_async(NULL, sbi->ll_md_exp,
2879 sizeof(KEY_READ_ONLY),
2880 KEY_READ_ONLY, sizeof(read_only),
2883 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2884 profilenm, read_only ?
2885 "read-only" : "read-write", err);
2890 sb->s_flags |= SB_RDONLY;
2892 sb->s_flags &= ~SB_RDONLY;
2894 if (test_bit(LL_SBI_VERBOSE, sbi->ll_flags))
2895 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
2896 read_only ? "read-only" : "read-write");
2902 * Cleanup the open handle that is cached on MDT-side.
2904 * For open case, the client side open handling thread may hit error
2905 * after the MDT grant the open. Under such case, the client should
2906 * send close RPC to the MDT as cleanup; otherwise, the open handle
2907 * on the MDT will be leaked there until the client umount or evicted.
2909 * In further, if someone unlinked the file, because the open handle
2910 * holds the reference on such file/object, then it will block the
2911 * subsequent threads that want to locate such object via FID.
2913 * \param[in] sb super block for this file-system
2914 * \param[in] open_req pointer to the original open request
2916 void ll_open_cleanup(struct super_block *sb, struct req_capsule *pill)
2918 struct mdt_body *body;
2919 struct md_op_data *op_data;
2920 struct ptlrpc_request *close_req = NULL;
2921 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
2924 body = req_capsule_server_get(pill, &RMF_MDT_BODY);
2925 OBD_ALLOC_PTR(op_data);
2926 if (op_data == NULL) {
2927 CWARN("%s: cannot allocate op_data to release open handle for "
2928 DFID"\n", ll_s2sbi(sb)->ll_fsname, PFID(&body->mbo_fid1));
2933 op_data->op_fid1 = body->mbo_fid1;
2934 op_data->op_open_handle = body->mbo_open_handle;
2935 op_data->op_mod_time = ktime_get_real_seconds();
2936 md_close(exp, op_data, NULL, &close_req);
2937 ptlrpc_req_finished(close_req);
2938 ll_finish_md_op_data(op_data);
2943 int ll_prep_inode(struct inode **inode, struct req_capsule *pill,
2944 struct super_block *sb, struct lookup_intent *it)
2946 struct ll_sb_info *sbi = NULL;
2947 struct lustre_md md = { NULL };
2948 bool default_lmv_deleted = false;
2953 LASSERT(*inode || sb);
2954 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2955 rc = md_get_lustre_md(sbi->ll_md_exp, pill, sbi->ll_dt_exp,
2956 sbi->ll_md_exp, &md);
2961 * clear default_lmv only if intent_getattr reply doesn't contain it.
2962 * but it needs to be done after iget, check this early because
2963 * ll_update_lsm_md() may change md.
2965 if (it && (it->it_op & (IT_LOOKUP | IT_GETATTR)) &&
2966 S_ISDIR(md.body->mbo_mode) && !md.default_lmv)
2967 default_lmv_deleted = true;
2970 rc = ll_update_inode(*inode, &md);
2974 bool api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
2975 struct lu_fid *fid1 = &md.body->mbo_fid1;
2977 LASSERT(sb != NULL);
2980 * At this point server returns to client's same fid as client
2981 * generated for creating. So using ->fid1 is okay here.
2983 if (!fid_is_sane(fid1)) {
2984 CERROR("%s: Fid is insane "DFID"\n",
2985 sbi->ll_fsname, PFID(fid1));
2986 GOTO(out, rc = -EINVAL);
2989 *inode = ll_iget(sb, cl_fid_build_ino(fid1, api32), &md);
2990 if (IS_ERR(*inode)) {
2992 rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
2994 CERROR("new_inode -fatal: rc %d\n", rc);
2999 /* Handling piggyback layout lock.
3000 * Layout lock can be piggybacked by getattr and open request.
3001 * The lsm can be applied to inode only if it comes with a layout lock
3002 * otherwise correct layout may be overwritten, for example:
3003 * 1. proc1: mdt returns a lsm but not granting layout
3004 * 2. layout was changed by another client
3005 * 3. proc2: refresh layout and layout lock granted
3006 * 4. proc1: to apply a stale layout */
3007 if (it != NULL && it->it_lock_mode != 0) {
3008 struct lustre_handle lockh;
3009 struct ldlm_lock *lock;
3011 lockh.cookie = it->it_lock_handle;
3012 lock = ldlm_handle2lock(&lockh);
3013 LASSERT(lock != NULL);
3014 if (ldlm_has_layout(lock)) {
3015 struct cl_object_conf conf;
3017 memset(&conf, 0, sizeof(conf));
3018 conf.coc_opc = OBJECT_CONF_SET;
3019 conf.coc_inode = *inode;
3020 conf.coc_lock = lock;
3021 conf.u.coc_layout = md.layout;
3022 (void)ll_layout_conf(*inode, &conf);
3024 LDLM_LOCK_PUT(lock);
3027 if (default_lmv_deleted)
3028 ll_update_default_lsm_md(*inode, &md);
3030 /* we may want to apply some policy for foreign file/dir */
3031 if (ll_sbi_has_foreign_symlink(sbi)) {
3032 rc = ll_manage_foreign(*inode, &md);
3040 /* cleanup will be done if necessary */
3041 md_free_lustre_md(sbi->ll_md_exp, &md);
3043 if (rc != 0 && it != NULL && it->it_op & IT_OPEN) {
3044 ll_intent_drop_lock(it);
3045 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, pill);
3051 int ll_obd_statfs(struct inode *inode, void __user *arg)
3053 struct ll_sb_info *sbi = NULL;
3054 struct obd_export *exp;
3055 struct obd_ioctl_data *data = NULL;
3060 sbi = ll_i2sbi(inode);
3062 GOTO(out_statfs, rc = -EINVAL);
3064 rc = obd_ioctl_getdata(&data, &len, arg);
3066 GOTO(out_statfs, rc);
3068 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
3069 !data->ioc_pbuf1 || !data->ioc_pbuf2)
3070 GOTO(out_statfs, rc = -EINVAL);
3072 if (data->ioc_inllen1 != sizeof(__u32) ||
3073 data->ioc_inllen2 != sizeof(__u32) ||
3074 data->ioc_plen1 != sizeof(struct obd_statfs) ||
3075 data->ioc_plen2 != sizeof(struct obd_uuid))
3076 GOTO(out_statfs, rc = -EINVAL);
3078 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
3079 if (type & LL_STATFS_LMV)
3080 exp = sbi->ll_md_exp;
3081 else if (type & LL_STATFS_LOV)
3082 exp = sbi->ll_dt_exp;
3084 GOTO(out_statfs, rc = -ENODEV);
3086 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, data, NULL);
3088 GOTO(out_statfs, rc);
3090 OBD_FREE_LARGE(data, len);
3095 * this is normally called in ll_fini_md_op_data(), but sometimes it needs to
3096 * be called early to avoid deadlock.
3098 void ll_unlock_md_op_lsm(struct md_op_data *op_data)
3100 if (op_data->op_mea2_sem) {
3101 up_read_non_owner(op_data->op_mea2_sem);
3102 op_data->op_mea2_sem = NULL;
3105 if (op_data->op_mea1_sem) {
3106 up_read_non_owner(op_data->op_mea1_sem);
3107 op_data->op_mea1_sem = NULL;
3111 /* this function prepares md_op_data hint for passing it down to MD stack. */
3112 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
3113 struct inode *i1, struct inode *i2,
3114 const char *name, size_t namelen,
3115 __u32 mode, enum md_op_code opc,
3118 struct llcrypt_name fname = { 0 };
3121 LASSERT(i1 != NULL);
3124 /* Do not reuse namelen for something else. */
3126 return ERR_PTR(-EINVAL);
3128 if (namelen > ll_i2sbi(i1)->ll_namelen)
3129 return ERR_PTR(-ENAMETOOLONG);
3131 /* "/" is not valid name, but it's allowed */
3132 if (!lu_name_is_valid_2(name, namelen) &&
3133 strncmp("/", name, namelen) != 0)
3134 return ERR_PTR(-EINVAL);
3137 if (op_data == NULL)
3138 OBD_ALLOC_PTR(op_data);
3140 if (op_data == NULL)
3141 return ERR_PTR(-ENOMEM);
3143 ll_i2gids(op_data->op_suppgids, i1, i2);
3144 op_data->op_fid1 = *ll_inode2fid(i1);
3146 if (S_ISDIR(i1->i_mode)) {
3147 down_read_non_owner(&ll_i2info(i1)->lli_lsm_sem);
3148 op_data->op_mea1_sem = &ll_i2info(i1)->lli_lsm_sem;
3149 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
3150 op_data->op_default_mea1 = ll_i2info(i1)->lli_default_lsm_md;
3154 op_data->op_fid2 = *ll_inode2fid(i2);
3155 if (S_ISDIR(i2->i_mode)) {
3157 /* i2 is typically a child of i1, and MUST be
3158 * further from the root to avoid deadlocks.
3160 down_read_non_owner(&ll_i2info(i2)->lli_lsm_sem);
3161 op_data->op_mea2_sem =
3162 &ll_i2info(i2)->lli_lsm_sem;
3164 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
3167 fid_zero(&op_data->op_fid2);
3170 if (test_bit(LL_SBI_64BIT_HASH, ll_i2sbi(i1)->ll_flags))
3171 op_data->op_cli_flags |= CLI_HASH64;
3173 if (ll_need_32bit_api(ll_i2sbi(i1)))
3174 op_data->op_cli_flags |= CLI_API32;
3176 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_CREATE) {
3177 /* In case of lookup, ll_setup_filename() has already been
3178 * called in ll_lookup_it(), so just take provided name.
3180 fname.disk_name.name = (unsigned char *)name;
3181 fname.disk_name.len = namelen;
3182 } else if (name && namelen) {
3183 struct qstr dname = QSTR_INIT(name, namelen);
3185 struct lu_fid *pfid = NULL;
3189 if (!S_ISDIR(i1->i_mode) && i2 && S_ISDIR(i2->i_mode)) {
3190 /* special case when called from ll_link() */
3195 lookup = (int)(opc == LUSTRE_OPC_ANY);
3197 if (opc == LUSTRE_OPC_ANY && lookup)
3199 rc = ll_setup_filename(dir, &dname, lookup, &fname, pfid);
3201 ll_finish_md_op_data(op_data);
3204 if (pfid && !fid_is_zero(pfid)) {
3206 op_data->op_fid2 = fid;
3207 op_data->op_bias = MDS_FID_OP;
3209 if (fname.disk_name.name &&
3210 fname.disk_name.name != (unsigned char *)name)
3211 /* op_data->op_name must be freed after use */
3212 op_data->op_flags |= MF_OPNAME_KMALLOCED;
3215 /* In fact LUSTRE_OPC_LOOKUP, LUSTRE_OPC_OPEN, LUSTRE_OPC_MIGR
3216 * are LUSTRE_OPC_ANY
3218 if (opc == LUSTRE_OPC_LOOKUP || opc == LUSTRE_OPC_OPEN ||
3219 opc == LUSTRE_OPC_MIGR)
3220 op_data->op_code = LUSTRE_OPC_ANY;
3222 op_data->op_code = opc;
3223 op_data->op_name = fname.disk_name.name;
3224 op_data->op_namelen = fname.disk_name.len;
3225 op_data->op_mode = mode;
3226 op_data->op_mod_time = ktime_get_real_seconds();
3227 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
3228 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
3229 op_data->op_cap = current_cap();
3230 op_data->op_mds = 0;
3231 if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
3232 filename_is_volatile(name, namelen, &op_data->op_mds)) {
3233 op_data->op_bias |= MDS_CREATE_VOLATILE;
3235 op_data->op_data = data;
3240 void ll_finish_md_op_data(struct md_op_data *op_data)
3242 ll_unlock_md_op_lsm(op_data);
3243 ll_security_release_secctx(op_data->op_file_secctx,
3244 op_data->op_file_secctx_size);
3245 if (op_data->op_flags & MF_OPNAME_KMALLOCED)
3246 /* allocated via ll_setup_filename called
3247 * from ll_prep_md_op_data
3249 kfree(op_data->op_name);
3250 llcrypt_free_ctx(op_data->op_file_encctx, op_data->op_file_encctx_size);
3251 OBD_FREE_PTR(op_data);
3254 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
3256 struct ll_sb_info *sbi;
3259 LASSERT(seq && dentry);
3260 sbi = ll_s2sbi(dentry->d_sb);
3262 if (test_bit(LL_SBI_NOLCK, sbi->ll_flags))
3263 seq_puts(seq, "nolock");
3265 for (i = 1; ll_sbi_flags_name[i].token != LL_SBI_NUM_MOUNT_OPT; i++) {
3266 /* match_table in some cases has patterns for both enabled and
3267 * disabled cases. Ignore 'no'xxx versions if bit is set.
3269 if (test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3270 strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3271 if (ll_sbi_flags_name[i].token ==
3272 LL_SBI_FOREIGN_SYMLINK) {
3273 seq_show_option(seq, "foreign_symlink",
3274 sbi->ll_foreign_symlink_prefix);
3276 seq_printf(seq, ",%s",
3277 ll_sbi_flags_name[i].pattern);
3280 /* You can have either localflock or flock but not
3281 * both. If localflock is set don't print flock or
3284 if (ll_sbi_flags_name[i].token == LL_SBI_LOCALFLOCK)
3286 } else if (!test_bit(ll_sbi_flags_name[i].token, sbi->ll_flags) &&
3287 !strncmp(ll_sbi_flags_name[i].pattern, "no", 2)) {
3288 seq_printf(seq, ",%s",
3289 ll_sbi_flags_name[i].pattern);
3297 * Get obd name by cmd, and copy out to user space
3299 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
3301 struct ll_sb_info *sbi = ll_i2sbi(inode);
3302 struct obd_device *obd;
3305 if (cmd == OBD_IOC_GETNAME_OLD || cmd == OBD_IOC_GETDTNAME)
3306 obd = class_exp2obd(sbi->ll_dt_exp);
3307 else if (cmd == OBD_IOC_GETMDNAME)
3308 obd = class_exp2obd(sbi->ll_md_exp);
3315 if (copy_to_user((void __user *)arg, obd->obd_name,
3316 strlen(obd->obd_name) + 1))
3322 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
3329 p.mnt = current->fs->root.mnt;
3331 path = d_path(&p, buf, bufsize);
3336 void ll_dirty_page_discard_warn(struct page *page, int ioret)
3338 char *buf, *path = NULL;
3339 struct dentry *dentry = NULL;
3340 struct inode *inode = page->mapping->host;
3342 /* this can be called inside spin lock so use GFP_ATOMIC. */
3343 buf = (char *)__get_free_page(GFP_ATOMIC);
3345 dentry = d_find_alias(page->mapping->host);
3347 path = ll_d_path(dentry, buf, PAGE_SIZE);
3350 /* The below message is checked in recovery-small.sh test_24b */
3352 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
3353 "(rc %d)\n", ll_i2sbi(inode)->ll_fsname,
3354 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
3355 PFID(ll_inode2fid(inode)),
3356 (path && !IS_ERR(path)) ? path : "", ioret);
3362 free_page((unsigned long)buf);
3365 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
3366 struct lov_user_md **kbuf)
3368 struct lov_user_md lum;
3372 if (copy_from_user(&lum, md, sizeof(lum)))
3375 lum_size = ll_lov_user_md_size(&lum);
3379 OBD_ALLOC_LARGE(*kbuf, lum_size);
3383 if (copy_from_user(*kbuf, md, lum_size) != 0) {
3384 OBD_FREE_LARGE(*kbuf, lum_size);
3392 * Compute llite root squash state after a change of root squash
3393 * configuration setting or add/remove of a lnet nid
3395 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
3397 struct root_squash_info *squash = &sbi->ll_squash;
3400 struct lnet_process_id id;
3402 /* Update norootsquash flag */
3403 spin_lock(&squash->rsi_lock);
3404 if (list_empty(&squash->rsi_nosquash_nids))
3405 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3407 /* Do not apply root squash as soon as one of our NIDs is
3408 * in the nosquash_nids list */
3411 while (LNetGetId(i++, &id) != -ENOENT) {
3412 if (id.nid == LNET_NID_LO_0)
3414 if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) {
3420 set_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3422 clear_bit(LL_SBI_NOROOTSQUASH, sbi->ll_flags);
3424 spin_unlock(&squash->rsi_lock);
3428 * Parse linkea content to extract information about a given hardlink
3430 * \param[in] ldata - Initialized linkea data
3431 * \param[in] linkno - Link identifier
3432 * \param[out] parent_fid - The entry's parent FID
3433 * \param[out] ln - Entry name destination buffer
3435 * \retval 0 on success
3436 * \retval Appropriate negative error code on failure
3438 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
3439 struct lu_fid *parent_fid, struct lu_name *ln)
3445 rc = linkea_init_with_rec(ldata);
3449 if (linkno >= ldata->ld_leh->leh_reccount)
3450 /* beyond last link */
3453 linkea_first_entry(ldata);
3454 for (idx = 0; ldata->ld_lee != NULL; idx++) {
3455 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
3460 linkea_next_entry(ldata);
3470 * Get parent FID and name of an identified link. Operation is performed for
3471 * a given link number, letting the caller iterate over linkno to list one or
3472 * all links of an entry.
3474 * \param[in] file - File descriptor against which to perform the operation
3475 * \param[in,out] arg - User-filled structure containing the linkno to operate
3476 * on and the available size. It is eventually filled with
3477 * the requested information or left untouched on error
3479 * \retval - 0 on success
3480 * \retval - Appropriate negative error code on failure
3482 int ll_getparent(struct file *file, struct getparent __user *arg)
3484 struct inode *inode = file_inode(file);
3485 struct linkea_data *ldata;
3486 struct lu_buf buf = LU_BUF_NULL;
3488 struct lu_fid parent_fid;
3495 if (!capable(CAP_DAC_READ_SEARCH) &&
3496 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
3499 if (get_user(name_size, &arg->gp_name_size))
3502 if (get_user(linkno, &arg->gp_linkno))
3505 if (name_size > PATH_MAX)
3508 OBD_ALLOC(ldata, sizeof(*ldata));
3512 rc = linkea_data_new(ldata, &buf);
3514 GOTO(ldata_free, rc);
3516 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
3517 buf.lb_len, OBD_MD_FLXATTR);
3521 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
3525 if (ln.ln_namelen >= name_size)
3526 GOTO(lb_free, rc = -EOVERFLOW);
3528 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
3529 GOTO(lb_free, rc = -EFAULT);
3531 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
3532 GOTO(lb_free, rc = -EFAULT);
3534 if (put_user('\0', arg->gp_name + ln.ln_namelen))
3535 GOTO(lb_free, rc = -EFAULT);
3540 OBD_FREE(ldata, sizeof(*ldata));