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, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/llite/llite_lib.c
34 * Lustre Light Super operations
37 #define DEBUG_SUBSYSTEM S_LLITE
39 #include <linux/module.h>
40 #include <linux/statfs.h>
41 #include <linux/types.h>
44 #include "../include/lustre/lustre_ioctl.h"
45 #include "../include/lustre_ha.h"
46 #include "../include/lustre_dlm.h"
47 #include "../include/lprocfs_status.h"
48 #include "../include/lustre_disk.h"
49 #include "../include/lustre_param.h"
50 #include "../include/lustre_log.h"
51 #include "../include/cl_object.h"
52 #include "../include/obd_cksum.h"
53 #include "llite_internal.h"
55 struct kmem_cache *ll_file_data_slab;
56 struct dentry *llite_root;
57 struct kset *llite_kset;
60 #define log2(n) ffz(~(n))
63 static struct ll_sb_info *ll_init_sbi(struct super_block *sb)
65 struct ll_sb_info *sbi = NULL;
67 unsigned long lru_page_max;
72 sbi = kzalloc(sizeof(*sbi), GFP_NOFS);
76 spin_lock_init(&sbi->ll_lock);
77 mutex_init(&sbi->ll_lco.lco_lock);
78 spin_lock_init(&sbi->ll_pp_extent_lock);
79 spin_lock_init(&sbi->ll_process_lock);
80 sbi->ll_rw_stats_on = 0;
83 pages = si.totalram - si.totalhigh;
84 lru_page_max = pages / 2;
86 sbi->ll_cache = cl_cache_init(lru_page_max);
92 sbi->ll_ra_info.ra_max_pages_per_file = min(pages / 32,
93 SBI_DEFAULT_READAHEAD_MAX);
94 sbi->ll_ra_info.ra_max_pages = sbi->ll_ra_info.ra_max_pages_per_file;
95 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
96 SBI_DEFAULT_READAHEAD_WHOLE_MAX;
98 ll_generate_random_uuid(uuid);
99 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
100 CDEBUG(D_CONFIG, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
102 sbi->ll_flags |= LL_SBI_VERBOSE;
103 sbi->ll_flags |= LL_SBI_CHECKSUM;
105 sbi->ll_flags |= LL_SBI_LRU_RESIZE;
107 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
108 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
110 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
114 /* metadata statahead is enabled by default */
115 sbi->ll_sa_max = LL_SA_RPC_DEF;
116 atomic_set(&sbi->ll_sa_total, 0);
117 atomic_set(&sbi->ll_sa_wrong, 0);
118 atomic_set(&sbi->ll_sa_running, 0);
119 atomic_set(&sbi->ll_agl_total, 0);
120 sbi->ll_flags |= LL_SBI_AGL_ENABLED;
123 sbi->ll_squash.rsi_uid = 0;
124 sbi->ll_squash.rsi_gid = 0;
125 INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
126 init_rwsem(&sbi->ll_squash.rsi_sem);
133 static void ll_free_sbi(struct super_block *sb)
135 struct ll_sb_info *sbi = ll_s2sbi(sb);
138 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
139 cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
140 cl_cache_decref(sbi->ll_cache);
141 sbi->ll_cache = NULL;
147 static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
148 struct vfsmount *mnt)
150 struct inode *root = NULL;
151 struct ll_sb_info *sbi = ll_s2sbi(sb);
152 struct obd_device *obd;
153 struct obd_statfs *osfs = NULL;
154 struct ptlrpc_request *request = NULL;
155 struct obd_connect_data *data = NULL;
156 struct obd_uuid *uuid;
157 struct md_op_data *op_data;
158 struct lustre_md lmd;
160 int size, err, checksum;
162 obd = class_name2obd(md);
164 CERROR("MD %s: not setup or attached\n", md);
168 data = kzalloc(sizeof(*data), GFP_NOFS);
172 osfs = kzalloc(sizeof(*osfs), GFP_NOFS);
178 /* indicate the features supported by this client */
179 data->ocd_connect_flags = OBD_CONNECT_IBITS | OBD_CONNECT_NODEVOH |
180 OBD_CONNECT_ATTRFID |
181 OBD_CONNECT_VERSION | OBD_CONNECT_BRW_SIZE |
182 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
183 OBD_CONNECT_AT | OBD_CONNECT_LOV_V3 |
184 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
185 OBD_CONNECT_64BITHASH |
186 OBD_CONNECT_EINPROGRESS |
187 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
188 OBD_CONNECT_LAYOUTLOCK |
189 OBD_CONNECT_PINGLESS |
190 OBD_CONNECT_MAX_EASIZE |
191 OBD_CONNECT_FLOCK_DEAD |
192 OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
193 OBD_CONNECT_OPEN_BY_FID |
194 OBD_CONNECT_DIR_STRIPE;
196 if (sbi->ll_flags & LL_SBI_SOM_PREVIEW)
197 data->ocd_connect_flags |= OBD_CONNECT_SOM;
199 if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
200 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
201 #ifdef CONFIG_FS_POSIX_ACL
202 data->ocd_connect_flags |= OBD_CONNECT_ACL | OBD_CONNECT_UMASK;
205 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
206 /* flag mdc connection as lightweight, only used for test
207 * purpose, use with care
209 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
211 data->ocd_ibits_known = MDS_INODELOCK_FULL;
212 data->ocd_version = LUSTRE_VERSION_CODE;
214 if (sb->s_flags & MS_RDONLY)
215 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
216 if (sbi->ll_flags & LL_SBI_USER_XATTR)
217 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
219 if (sbi->ll_flags & LL_SBI_FLOCK)
220 sbi->ll_fop = &ll_file_operations_flock;
221 else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
222 sbi->ll_fop = &ll_file_operations;
224 sbi->ll_fop = &ll_file_operations_noflock;
227 data->ocd_connect_flags |= OBD_CONNECT_REAL;
229 data->ocd_brw_size = MD_MAX_BRW_SIZE;
231 err = obd_connect(NULL, &sbi->ll_md_exp, obd, &sbi->ll_sb_uuid,
234 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing recovery, of which this client is not a part. Please wait for recovery to complete, abort, or time out.\n",
238 CERROR("cannot connect to %s: rc = %d\n", md, err);
242 sbi->ll_md_exp->exp_connect_data = *data;
244 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
245 LUSTRE_SEQ_METADATA);
247 CERROR("%s: Can't init metadata layer FID infrastructure, rc = %d\n",
248 sbi->ll_md_exp->exp_obd->obd_name, err);
252 /* For mount, we only need fs info from MDT0, and also in DNE, it
253 * can make sure the client can be mounted as long as MDT0 is
256 err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
257 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
258 OBD_STATFS_FOR_MDT0);
262 /* This needs to be after statfs to ensure connect has finished.
263 * Note that "data" does NOT contain the valid connect reply.
264 * If connecting to a 1.8 server there will be no LMV device, so
265 * we can access the MDC export directly and exp_connect_flags will
266 * be non-zero, but if accessing an upgraded 2.1 server it will
267 * have the correct flags filled in.
268 * XXX: fill in the LMV exp_connect_flags from MDC(s).
270 valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
271 if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
272 valid != CLIENT_CONNECT_MDT_REQD) {
275 buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
280 obd_connect_flags2str(buf, PAGE_SIZE,
281 valid ^ CLIENT_CONNECT_MDT_REQD, ",");
282 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support feature(s) needed for correct operation of this client (%s). Please upgrade server or downgrade client.\n",
283 sbi->ll_md_exp->exp_obd->obd_name, buf);
289 size = sizeof(*data);
290 err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
291 KEY_CONN_DATA, &size, data, NULL);
293 CERROR("%s: Get connect data failed: rc = %d\n",
294 sbi->ll_md_exp->exp_obd->obd_name, err);
298 LASSERT(osfs->os_bsize);
299 sb->s_blocksize = osfs->os_bsize;
300 sb->s_blocksize_bits = log2(osfs->os_bsize);
301 sb->s_magic = LL_SUPER_MAGIC;
302 sb->s_maxbytes = MAX_LFS_FILESIZE;
303 sbi->ll_namelen = osfs->os_namelen;
305 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
306 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
307 LCONSOLE_INFO("Disabling user_xattr feature because it is not supported on the server\n");
308 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
311 if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
312 sb->s_flags |= MS_POSIXACL;
313 sbi->ll_flags |= LL_SBI_ACL;
315 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
316 sb->s_flags &= ~MS_POSIXACL;
317 sbi->ll_flags &= ~LL_SBI_ACL;
320 if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
321 sbi->ll_flags |= LL_SBI_64BIT_HASH;
323 if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE)
324 sbi->ll_md_brw_pages = data->ocd_brw_size >> PAGE_SHIFT;
326 sbi->ll_md_brw_pages = 1;
328 if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
329 sbi->ll_flags |= LL_SBI_LAYOUT_LOCK;
331 if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
332 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
334 "%s: disabling xattr cache due to unknown maximum xattr size.\n",
337 sbi->ll_flags |= LL_SBI_XATTR_CACHE;
338 sbi->ll_xattr_cache_enabled = 1;
342 obd = class_name2obd(dt);
344 CERROR("DT %s: not setup or attached\n", dt);
349 data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
350 OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
351 OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
352 OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
353 OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
354 OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
355 OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
356 OBD_CONNECT_EINPROGRESS |
357 OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
358 OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS;
360 if (sbi->ll_flags & LL_SBI_SOM_PREVIEW)
361 data->ocd_connect_flags |= OBD_CONNECT_SOM;
363 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_CKSUM)) {
364 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
365 * disabled by default, because it can still be enabled on the
366 * fly via /sys. As a consequence, we still need to come to an
367 * agreement on the supported algorithms at connect time
369 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
371 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
372 data->ocd_cksum_types = OBD_CKSUM_ADLER;
374 data->ocd_cksum_types = cksum_types_supported_client();
377 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
379 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d ocd_grant: %d\n",
380 data->ocd_connect_flags,
381 data->ocd_version, data->ocd_grant);
383 obd->obd_upcall.onu_owner = &sbi->ll_lco;
384 obd->obd_upcall.onu_upcall = cl_ocd_update;
386 data->ocd_brw_size = DT_MAX_BRW_SIZE;
388 err = obd_connect(NULL, &sbi->ll_dt_exp, obd, &sbi->ll_sb_uuid, data,
391 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing recovery, of which this client is not a part. Please wait for recovery to complete, abort, or time out.\n",
395 CERROR("%s: Cannot connect to %s: rc = %d\n",
396 sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
400 sbi->ll_dt_exp->exp_connect_data = *data;
402 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
403 LUSTRE_SEQ_METADATA);
405 CERROR("%s: Can't init data layer FID infrastructure, rc = %d\n",
406 sbi->ll_dt_exp->exp_obd->obd_name, err);
410 mutex_lock(&sbi->ll_lco.lco_lock);
411 sbi->ll_lco.lco_flags = data->ocd_connect_flags;
412 sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
413 sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
414 mutex_unlock(&sbi->ll_lco.lco_lock);
416 fid_zero(&sbi->ll_root_fid);
417 err = md_getstatus(sbi->ll_md_exp, &sbi->ll_root_fid);
419 CERROR("cannot mds_connect: rc = %d\n", err);
422 if (!fid_is_sane(&sbi->ll_root_fid)) {
423 CERROR("%s: Invalid root fid "DFID" during mount\n",
424 sbi->ll_md_exp->exp_obd->obd_name,
425 PFID(&sbi->ll_root_fid));
429 CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
431 sb->s_op = &lustre_super_operations;
432 sb->s_xattr = ll_xattr_handlers;
433 #if THREAD_SIZE >= 8192 /*b=17630*/
434 sb->s_export_op = &lustre_export_operations;
438 * XXX: move this to after cbd setup?
440 valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
441 if (sbi->ll_flags & LL_SBI_ACL)
442 valid |= OBD_MD_FLACL;
444 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
450 op_data->op_fid1 = sbi->ll_root_fid;
451 op_data->op_mode = 0;
452 op_data->op_valid = valid;
454 err = md_getattr(sbi->ll_md_exp, op_data, &request);
457 CERROR("%s: md_getattr failed for root: rc = %d\n",
458 sbi->ll_md_exp->exp_obd->obd_name, err);
462 err = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
463 sbi->ll_md_exp, &lmd);
465 CERROR("failed to understand root inode md: rc = %d\n", err);
466 ptlrpc_req_finished(request);
470 LASSERT(fid_is_sane(&sbi->ll_root_fid));
471 root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid,
472 sbi->ll_flags & LL_SBI_32BIT_API),
474 md_free_lustre_md(sbi->ll_md_exp, &lmd);
475 ptlrpc_req_finished(request);
479 obd_free_memmd(sbi->ll_dt_exp, &lmd.lsm);
480 #ifdef CONFIG_FS_POSIX_ACL
482 posix_acl_release(lmd.posix_acl);
483 lmd.posix_acl = NULL;
487 CERROR("lustre_lite: bad iget4 for root\n");
491 err = ll_close_thread_start(&sbi->ll_lcq);
493 CERROR("cannot start close thread: rc %d\n", err);
497 checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
498 err = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
499 KEY_CHECKSUM, sizeof(checksum), &checksum,
502 CERROR("%s: Set checksum failed: rc = %d\n",
503 sbi->ll_dt_exp->exp_obd->obd_name, err);
508 err = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CACHE_SET),
509 KEY_CACHE_SET, sizeof(*sbi->ll_cache),
510 sbi->ll_cache, NULL);
512 CERROR("%s: Set cache_set failed: rc = %d\n",
513 sbi->ll_dt_exp->exp_obd->obd_name, err);
517 sb->s_root = d_make_root(root);
519 CERROR("%s: can't make root dentry\n",
520 ll_get_fsname(sb, NULL, 0));
525 sbi->ll_sdev_orig = sb->s_dev;
527 /* We set sb->s_dev equal on all lustre clients in order to support
528 * NFS export clustering. NFSD requires that the FSID be the same
531 /* s_dev is also used in lt_compare() to compare two fs, but that is
532 * only a node-local comparison.
534 uuid = obd_get_uuid(sbi->ll_md_exp);
536 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
537 get_uuid2fsid(uuid->uuid, strlen(uuid->uuid), &sbi->ll_fsid);
544 err = ldebugfs_register_mountpoint(llite_root, sb, dt, md);
546 CERROR("%s: could not register mount in debugfs: "
547 "rc = %d\n", ll_get_fsname(sb, NULL, 0), err);
556 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
558 obd_disconnect(sbi->ll_dt_exp);
559 sbi->ll_dt_exp = NULL;
561 obd_fid_fini(sbi->ll_md_exp->exp_obd);
563 obd_disconnect(sbi->ll_md_exp);
564 sbi->ll_md_exp = NULL;
571 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
575 *lmmsize = obd_size_diskmd(sbi->ll_dt_exp, NULL);
577 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
578 KEY_MAX_EASIZE, &size, lmmsize, NULL);
580 CERROR("Get max mdsize error rc %d\n", rc);
586 * Get the value of the default_easize parameter.
588 * \see client_obd::cl_default_mds_easize
590 * \param[in] sbi superblock info for this filesystem
591 * \param[out] lmmsize pointer to storage location for value
593 * \retval 0 on success
594 * \retval negative negated errno on failure
596 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
601 rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
602 KEY_DEFAULT_EASIZE, &size, lmmsize, NULL);
604 CERROR("Get default mdsize error rc %d\n", rc);
610 * Set the default_easize parameter to the given value.
612 * \see client_obd::cl_default_mds_easize
614 * \param[in] sbi superblock info for this filesystem
615 * \param[in] lmmsize the size to set
617 * \retval 0 on success
618 * \retval negative negated errno on failure
620 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
622 if (lmmsize < sizeof(struct lov_mds_md) ||
623 lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
626 return obd_set_info_async(NULL, sbi->ll_md_exp,
627 sizeof(KEY_DEFAULT_EASIZE),
629 sizeof(int), &lmmsize, NULL);
632 static void client_common_put_super(struct super_block *sb)
634 struct ll_sb_info *sbi = ll_s2sbi(sb);
636 ll_close_thread_shutdown(sbi->ll_lcq);
640 obd_fid_fini(sbi->ll_dt_exp->exp_obd);
641 obd_disconnect(sbi->ll_dt_exp);
642 sbi->ll_dt_exp = NULL;
644 ldebugfs_unregister_mountpoint(sbi);
646 obd_fid_fini(sbi->ll_md_exp->exp_obd);
647 obd_disconnect(sbi->ll_md_exp);
648 sbi->ll_md_exp = NULL;
651 void ll_kill_super(struct super_block *sb)
653 struct ll_sb_info *sbi;
656 if (!(sb->s_flags & MS_ACTIVE))
660 /* we need to restore s_dev from changed for clustered NFS before
661 * put_super because new kernels have cached s_dev and change sb->s_dev
662 * in put_super not affected real removing devices
665 sb->s_dev = sbi->ll_sdev_orig;
666 sbi->ll_umounting = 1;
668 /* wait running statahead threads to quit */
669 while (atomic_read(&sbi->ll_sa_running) > 0) {
670 set_current_state(TASK_UNINTERRUPTIBLE);
671 schedule_timeout(msecs_to_jiffies(MSEC_PER_SEC >> 3));
676 static inline int ll_set_opt(const char *opt, char *data, int fl)
678 if (strncmp(opt, data, strlen(opt)) != 0)
684 /* non-client-specific mount options are parsed in lmd_parse */
685 static int ll_options(char *options, int *flags)
688 char *s1 = options, *s2;
693 CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
696 CDEBUG(D_SUPER, "next opt=%s\n", s1);
697 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
702 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
707 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
712 tmp = ll_set_opt("noflock", s1,
713 LL_SBI_FLOCK | LL_SBI_LOCALFLOCK);
718 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
723 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
728 tmp = ll_set_opt("user_fid2path", s1, LL_SBI_USER_FID2PATH);
733 tmp = ll_set_opt("nouser_fid2path", s1, LL_SBI_USER_FID2PATH);
739 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
744 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
749 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
754 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
759 tmp = ll_set_opt("lazystatfs", s1, LL_SBI_LAZYSTATFS);
764 tmp = ll_set_opt("nolazystatfs", s1, LL_SBI_LAZYSTATFS);
769 tmp = ll_set_opt("som_preview", s1, LL_SBI_SOM_PREVIEW);
774 tmp = ll_set_opt("32bitapi", s1, LL_SBI_32BIT_API);
779 tmp = ll_set_opt("verbose", s1, LL_SBI_VERBOSE);
784 tmp = ll_set_opt("noverbose", s1, LL_SBI_VERBOSE);
789 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
795 s2 = strchr(s1, ',');
803 void ll_lli_init(struct ll_inode_info *lli)
805 lli->lli_inode_magic = LLI_INODE_MAGIC;
807 lli->lli_ioepoch = 0;
808 lli->lli_maxbytes = MAX_LFS_FILESIZE;
809 spin_lock_init(&lli->lli_lock);
810 lli->lli_posix_acl = NULL;
811 /* Do not set lli_fid, it has been initialized already. */
812 fid_zero(&lli->lli_pfid);
813 INIT_LIST_HEAD(&lli->lli_close_list);
814 lli->lli_pending_och = NULL;
815 lli->lli_mds_read_och = NULL;
816 lli->lli_mds_write_och = NULL;
817 lli->lli_mds_exec_och = NULL;
818 lli->lli_open_fd_read_count = 0;
819 lli->lli_open_fd_write_count = 0;
820 lli->lli_open_fd_exec_count = 0;
821 mutex_init(&lli->lli_och_mutex);
822 spin_lock_init(&lli->lli_agl_lock);
823 lli->lli_has_smd = false;
824 spin_lock_init(&lli->lli_layout_lock);
825 ll_layout_version_set(lli, LL_LAYOUT_GEN_NONE);
826 lli->lli_clob = NULL;
828 init_rwsem(&lli->lli_xattrs_list_rwsem);
829 mutex_init(&lli->lli_xattrs_enq_lock);
831 LASSERT(lli->lli_vfs_inode.i_mode != 0);
832 if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
833 mutex_init(&lli->lli_readdir_mutex);
834 lli->lli_opendir_key = NULL;
836 spin_lock_init(&lli->lli_sa_lock);
837 lli->lli_opendir_pid = 0;
838 lli->lli_sa_enabled = 0;
839 lli->lli_def_stripe_offset = -1;
841 mutex_init(&lli->lli_size_mutex);
842 lli->lli_symlink_name = NULL;
843 init_rwsem(&lli->lli_trunc_sem);
844 range_lock_tree_init(&lli->lli_write_tree);
845 init_rwsem(&lli->lli_glimpse_sem);
846 lli->lli_glimpse_time = 0;
847 INIT_LIST_HEAD(&lli->lli_agl_list);
848 lli->lli_agl_index = 0;
849 lli->lli_async_rc = 0;
851 mutex_init(&lli->lli_layout_mutex);
854 static inline int ll_bdi_register(struct backing_dev_info *bdi)
856 static atomic_t ll_bdi_num = ATOMIC_INIT(0);
858 bdi->name = "lustre";
859 return bdi_register(bdi, NULL, "lustre-%d",
860 atomic_inc_return(&ll_bdi_num));
863 int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
865 struct lustre_profile *lprof = NULL;
866 struct lustre_sb_info *lsi = s2lsi(sb);
867 struct ll_sb_info *sbi;
868 char *dt = NULL, *md = NULL;
869 char *profilenm = get_profile_name(sb);
870 struct config_llog_instance *cfg;
873 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
875 cfg = kzalloc(sizeof(*cfg), GFP_NOFS);
879 try_module_get(THIS_MODULE);
881 /* client additional sb info */
882 sbi = ll_init_sbi(sb);
883 lsi->lsi_llsbi = sbi;
885 module_put(THIS_MODULE);
890 err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
894 err = bdi_init(&lsi->lsi_bdi);
897 lsi->lsi_flags |= LSI_BDI_INITIALIZED;
898 lsi->lsi_bdi.capabilities = 0;
899 err = ll_bdi_register(&lsi->lsi_bdi);
903 sb->s_bdi = &lsi->lsi_bdi;
904 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
905 sb->s_d_op = &ll_d_ops;
907 /* Generate a string unique to this super, in case some joker tries
908 * to mount the same fs at two mount points.
909 * Use the address of the super itself.
911 cfg->cfg_instance = sb;
912 cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
913 cfg->cfg_callback = class_config_llog_handler;
914 /* set up client obds */
915 err = lustre_process_log(sb, profilenm, cfg);
919 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
920 lprof = class_get_profile(profilenm);
922 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be read from the MGS. Does that filesystem exist?\n",
927 CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
928 lprof->lp_md, lprof->lp_dt);
930 dt = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
936 md = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_md, cfg->cfg_instance);
942 /* connections, registrations, sb setup */
943 err = client_common_fill_super(sb, md, dt, mnt);
950 else if (sbi->ll_flags & LL_SBI_VERBOSE)
951 LCONSOLE_WARN("Mounted %s\n", profilenm);
955 } /* ll_fill_super */
957 void ll_put_super(struct super_block *sb)
959 struct config_llog_instance cfg, params_cfg;
960 struct obd_device *obd;
961 struct lustre_sb_info *lsi = s2lsi(sb);
962 struct ll_sb_info *sbi = ll_s2sbi(sb);
963 char *profilenm = get_profile_name(sb);
964 int next, force = 1, rc = 0;
967 CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
969 cfg.cfg_instance = sb;
970 lustre_end_log(sb, profilenm, &cfg);
972 params_cfg.cfg_instance = sb;
973 lustre_end_log(sb, PARAMS_FILENAME, ¶ms_cfg);
975 if (sbi->ll_md_exp) {
976 obd = class_exp2obd(sbi->ll_md_exp);
978 force = obd->obd_force;
981 /* Wait for unstable pages to be committed to stable storage */
983 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
985 rc = l_wait_event(sbi->ll_cache->ccc_unstable_waitq,
986 !atomic_long_read(&sbi->ll_cache->ccc_unstable_nr),
990 ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
991 if (!force && rc != -EINTR)
992 LASSERTF(!ccc_count, "count: %li\n", ccc_count);
994 /* We need to set force before the lov_disconnect in
995 * lustre_common_put_super, since l_d cleans up osc's as well.
999 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1001 obd->obd_force = force;
1006 /* Only if client_common_fill_super succeeded */
1007 client_common_put_super(sb);
1011 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1012 class_manual_cleanup(obd);
1014 if (sbi->ll_flags & LL_SBI_VERBOSE)
1015 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1018 class_del_profile(profilenm);
1020 if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1021 bdi_destroy(&lsi->lsi_bdi);
1022 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1026 lsi->lsi_llsbi = NULL;
1028 lustre_common_put_super(sb);
1030 cl_env_cache_purge(~0);
1032 module_put(THIS_MODULE);
1033 } /* client_put_super */
1035 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1037 struct inode *inode = NULL;
1039 /* NOTE: we depend on atomic igrab() -bzzz */
1040 lock_res_and_lock(lock);
1041 if (lock->l_resource->lr_lvb_inode) {
1042 struct ll_inode_info *lli;
1044 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1045 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1046 inode = igrab(lock->l_resource->lr_lvb_inode);
1048 inode = lock->l_resource->lr_lvb_inode;
1049 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1050 D_WARNING, lock, "lr_lvb_inode %p is bogus: magic %08x",
1051 lock->l_resource->lr_lvb_inode,
1052 lli->lli_inode_magic);
1056 unlock_res_and_lock(lock);
1060 static void ll_dir_clear_lsm_md(struct inode *inode)
1062 struct ll_inode_info *lli = ll_i2info(inode);
1064 LASSERT(S_ISDIR(inode->i_mode));
1066 if (lli->lli_lsm_md) {
1067 lmv_free_memmd(lli->lli_lsm_md);
1068 lli->lli_lsm_md = NULL;
1072 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1073 const struct lu_fid *fid,
1074 struct lustre_md *md)
1076 struct ll_sb_info *sbi = ll_s2sbi(sb);
1077 struct mdt_body *body = md->body;
1078 struct inode *inode;
1081 ino = cl_fid_build_ino(fid, sbi->ll_flags & LL_SBI_32BIT_API);
1082 inode = iget_locked(sb, ino);
1084 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1085 ll_get_fsname(sb, NULL, 0), PFID(fid));
1086 return ERR_PTR(-ENOENT);
1089 if (inode->i_state & I_NEW) {
1090 struct ll_inode_info *lli = ll_i2info(inode);
1091 struct lmv_stripe_md *lsm = md->lmv;
1093 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1094 (body->mbo_mode & S_IFMT);
1095 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1098 LTIME_S(inode->i_mtime) = 0;
1099 LTIME_S(inode->i_atime) = 0;
1100 LTIME_S(inode->i_ctime) = 0;
1103 inode->i_op = &ll_dir_inode_operations;
1104 inode->i_fop = &ll_dir_operations;
1105 lli->lli_fid = *fid;
1109 /* master object FID */
1110 lli->lli_pfid = body->mbo_fid1;
1111 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1112 lli, PFID(fid), PFID(&lli->lli_pfid));
1113 unlock_new_inode(inode);
1119 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1121 struct lmv_stripe_md *lsm = md->lmv;
1127 * XXX sigh, this lsm_root initialization should be in
1128 * LMV layer, but it needs ll_iget right now, so we
1129 * put this here right now.
1131 for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1132 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1133 LASSERT(!lsm->lsm_md_oinfo[i].lmo_root);
1134 /* Unfortunately ll_iget will call ll_update_inode,
1135 * where the initialization of slave inode is slightly
1136 * different, so it reset lsm_md to NULL to avoid
1137 * initializing lsm for slave inode.
1139 /* For migrating inode, master stripe and master object will
1140 * be same, so we only need assign this inode
1142 if (lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION && !i)
1143 lsm->lsm_md_oinfo[i].lmo_root = inode;
1145 lsm->lsm_md_oinfo[i].lmo_root =
1146 ll_iget_anon_dir(inode->i_sb, fid, md);
1147 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1148 int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1150 lsm->lsm_md_oinfo[i].lmo_root = NULL;
1158 static inline int lli_lsm_md_eq(const struct lmv_stripe_md *lsm_md1,
1159 const struct lmv_stripe_md *lsm_md2)
1161 return lsm_md1->lsm_md_magic == lsm_md2->lsm_md_magic &&
1162 lsm_md1->lsm_md_stripe_count == lsm_md2->lsm_md_stripe_count &&
1163 lsm_md1->lsm_md_master_mdt_index ==
1164 lsm_md2->lsm_md_master_mdt_index &&
1165 lsm_md1->lsm_md_hash_type == lsm_md2->lsm_md_hash_type &&
1166 lsm_md1->lsm_md_layout_version ==
1167 lsm_md2->lsm_md_layout_version &&
1168 !strcmp(lsm_md1->lsm_md_pool_name,
1169 lsm_md2->lsm_md_pool_name);
1172 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1174 struct ll_inode_info *lli = ll_i2info(inode);
1175 struct lmv_stripe_md *lsm = md->lmv;
1178 LASSERT(S_ISDIR(inode->i_mode));
1179 CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1180 PFID(ll_inode2fid(inode)));
1182 /* no striped information from request. */
1184 if (!lli->lli_lsm_md) {
1186 } else if (lli->lli_lsm_md->lsm_md_hash_type &
1187 LMV_HASH_FLAG_MIGRATION) {
1189 * migration is done, the temporay MIGRATE layout has
1192 CDEBUG(D_INODE, DFID" finish migration.\n",
1193 PFID(ll_inode2fid(inode)));
1194 lmv_free_memmd(lli->lli_lsm_md);
1195 lli->lli_lsm_md = NULL;
1199 * The lustre_md from req does not include stripeEA,
1206 /* set the directory layout */
1207 if (!lli->lli_lsm_md) {
1208 rc = ll_init_lsm_md(inode, md);
1212 lli->lli_lsm_md = lsm;
1214 * set lsm_md to NULL, so the following free lustre_md
1215 * will not free this lsm
1218 CDEBUG(D_INODE, "Set lsm %p magic %x to "DFID"\n", lsm,
1219 lsm->lsm_md_magic, PFID(ll_inode2fid(inode)));
1223 /* Compare the old and new stripe information */
1224 if (!lsm_md_eq(lli->lli_lsm_md, lsm)) {
1225 struct lmv_stripe_md *old_lsm = lli->lli_lsm_md;
1228 CERROR("%s: inode "DFID"(%p)'s lmv layout mismatch (%p)/(%p) magic:0x%x/0x%x stripe count: %d/%d master_mdt: %d/%d hash_type:0x%x/0x%x layout: 0x%x/0x%x pool:%s/%s\n",
1229 ll_get_fsname(inode->i_sb, NULL, 0), PFID(&lli->lli_fid),
1230 inode, lsm, old_lsm,
1231 lsm->lsm_md_magic, old_lsm->lsm_md_magic,
1232 lsm->lsm_md_stripe_count,
1233 old_lsm->lsm_md_stripe_count,
1234 lsm->lsm_md_master_mdt_index,
1235 old_lsm->lsm_md_master_mdt_index,
1236 lsm->lsm_md_hash_type, old_lsm->lsm_md_hash_type,
1237 lsm->lsm_md_layout_version,
1238 old_lsm->lsm_md_layout_version,
1239 lsm->lsm_md_pool_name,
1240 old_lsm->lsm_md_pool_name);
1242 for (idx = 0; idx < old_lsm->lsm_md_stripe_count; idx++) {
1243 CERROR("%s: sub FIDs in old lsm idx %d, old: "DFID"\n",
1244 ll_get_fsname(inode->i_sb, NULL, 0), idx,
1245 PFID(&old_lsm->lsm_md_oinfo[idx].lmo_fid));
1248 for (idx = 0; idx < lsm->lsm_md_stripe_count; idx++) {
1249 CERROR("%s: sub FIDs in new lsm idx %d, new: "DFID"\n",
1250 ll_get_fsname(inode->i_sb, NULL, 0), idx,
1251 PFID(&lsm->lsm_md_oinfo[idx].lmo_fid));
1260 void ll_clear_inode(struct inode *inode)
1262 struct ll_inode_info *lli = ll_i2info(inode);
1263 struct ll_sb_info *sbi = ll_i2sbi(inode);
1265 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1266 PFID(ll_inode2fid(inode)), inode);
1268 if (S_ISDIR(inode->i_mode)) {
1269 /* these should have been cleared in ll_file_release */
1270 LASSERT(!lli->lli_opendir_key);
1271 LASSERT(!lli->lli_sai);
1272 LASSERT(lli->lli_opendir_pid == 0);
1275 spin_lock(&lli->lli_lock);
1276 ll_i2info(inode)->lli_flags &= ~LLIF_MDS_SIZE_LOCK;
1277 spin_unlock(&lli->lli_lock);
1278 md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1280 LASSERT(!lli->lli_open_fd_write_count);
1281 LASSERT(!lli->lli_open_fd_read_count);
1282 LASSERT(!lli->lli_open_fd_exec_count);
1284 if (lli->lli_mds_write_och)
1285 ll_md_real_close(inode, FMODE_WRITE);
1286 if (lli->lli_mds_exec_och)
1287 ll_md_real_close(inode, FMODE_EXEC);
1288 if (lli->lli_mds_read_och)
1289 ll_md_real_close(inode, FMODE_READ);
1291 if (S_ISLNK(inode->i_mode)) {
1292 kfree(lli->lli_symlink_name);
1293 lli->lli_symlink_name = NULL;
1296 ll_xattr_cache_destroy(inode);
1298 #ifdef CONFIG_FS_POSIX_ACL
1299 if (lli->lli_posix_acl) {
1300 posix_acl_release(lli->lli_posix_acl);
1301 lli->lli_posix_acl = NULL;
1304 lli->lli_inode_magic = LLI_INODE_DEAD;
1306 if (S_ISDIR(inode->i_mode))
1307 ll_dir_clear_lsm_md(inode);
1308 if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1309 LASSERT(list_empty(&lli->lli_agl_list));
1312 * XXX This has to be done before lsm is freed below, because
1313 * cl_object still uses inode lsm.
1315 cl_inode_fini(inode);
1316 lli->lli_has_smd = false;
1319 #define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
1321 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data,
1322 struct md_open_data **mod)
1324 struct lustre_md md;
1325 struct inode *inode = d_inode(dentry);
1326 struct ll_sb_info *sbi = ll_i2sbi(inode);
1327 struct ptlrpc_request *request = NULL;
1330 op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1331 LUSTRE_OPC_ANY, NULL);
1332 if (IS_ERR(op_data))
1333 return PTR_ERR(op_data);
1335 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, NULL, 0,
1338 ptlrpc_req_finished(request);
1339 if (rc == -ENOENT) {
1341 /* Unlinked special device node? Or just a race?
1342 * Pretend we did everything.
1344 if (!S_ISREG(inode->i_mode) &&
1345 !S_ISDIR(inode->i_mode)) {
1346 ia_valid = op_data->op_attr.ia_valid;
1347 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1348 rc = simple_setattr(dentry, &op_data->op_attr);
1349 op_data->op_attr.ia_valid = ia_valid;
1351 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1352 CERROR("md_setattr fails: rc = %d\n", rc);
1357 rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
1358 sbi->ll_md_exp, &md);
1360 ptlrpc_req_finished(request);
1364 ia_valid = op_data->op_attr.ia_valid;
1365 /* inode size will be in cl_setattr_ost, can't do it now since dirty
1366 * cache is not cleared yet.
1368 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1369 rc = simple_setattr(dentry, &op_data->op_attr);
1370 op_data->op_attr.ia_valid = ia_valid;
1372 /* Extract epoch data if obtained. */
1373 op_data->op_handle = md.body->mbo_handle;
1374 op_data->op_ioepoch = md.body->mbo_ioepoch;
1376 rc = ll_update_inode(inode, &md);
1377 ptlrpc_req_finished(request);
1382 /* Close IO epoch and send Size-on-MDS attribute update. */
1383 static int ll_setattr_done_writing(struct inode *inode,
1384 struct md_op_data *op_data,
1385 struct md_open_data *mod)
1387 struct ll_inode_info *lli = ll_i2info(inode);
1390 if (!S_ISREG(inode->i_mode))
1393 CDEBUG(D_INODE, "Epoch %llu closed on "DFID" for truncate\n",
1394 op_data->op_ioepoch, PFID(&lli->lli_fid));
1396 op_data->op_flags = MF_EPOCH_CLOSE;
1397 ll_done_writing_attr(inode, op_data);
1398 ll_pack_inode2opdata(inode, op_data, NULL);
1400 rc = md_done_writing(ll_i2sbi(inode)->ll_md_exp, op_data, mod);
1402 /* MDS has instructed us to obtain Size-on-MDS attribute
1403 * from OSTs and send setattr to back to MDS.
1405 rc = ll_som_update(inode, op_data);
1407 CERROR("%s: inode "DFID" mdc truncate failed: rc = %d\n",
1408 ll_i2sbi(inode)->ll_md_exp->exp_obd->obd_name,
1409 PFID(ll_inode2fid(inode)), rc);
1414 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1415 * object(s) determine the file size and mtime. Otherwise, the MDS will
1416 * keep these values until such a time that objects are allocated for it.
1417 * We do the MDS operations first, as it is checking permissions for us.
1418 * We don't to the MDS RPC if there is nothing that we want to store there,
1419 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1420 * going to do an RPC anyways.
1422 * If we are doing a truncate, we will send the mtime and ctime updates
1423 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1424 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1427 * In case of HSMimport, we only set attr on MDS.
1429 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
1431 struct inode *inode = d_inode(dentry);
1432 struct ll_inode_info *lli = ll_i2info(inode);
1433 struct md_op_data *op_data = NULL;
1434 struct md_open_data *mod = NULL;
1435 bool file_is_released = false;
1436 int rc = 0, rc1 = 0;
1438 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, valid %x, hsm_import %d\n",
1439 ll_get_fsname(inode->i_sb, NULL, 0), PFID(&lli->lli_fid), inode,
1440 i_size_read(inode), attr->ia_size, attr->ia_valid, hsm_import);
1442 if (attr->ia_valid & ATTR_SIZE) {
1443 /* Check new size against VFS/VM file size limit and rlimit */
1444 rc = inode_newsize_ok(inode, attr->ia_size);
1448 /* The maximum Lustre file size is variable, based on the
1449 * OST maximum object size and number of stripes. This
1450 * needs another check in addition to the VFS check above.
1452 if (attr->ia_size > ll_file_maxbytes(inode)) {
1453 CDEBUG(D_INODE, "file "DFID" too large %llu > %llu\n",
1454 PFID(&lli->lli_fid), attr->ia_size,
1455 ll_file_maxbytes(inode));
1459 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1462 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1463 if (attr->ia_valid & TIMES_SET_FLAGS) {
1464 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
1465 !capable(CFS_CAP_FOWNER))
1469 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1470 if (attr->ia_valid & ATTR_CTIME) {
1471 attr->ia_ctime = CURRENT_TIME;
1472 attr->ia_valid |= ATTR_CTIME_SET;
1474 if (!(attr->ia_valid & ATTR_ATIME_SET) &&
1475 (attr->ia_valid & ATTR_ATIME)) {
1476 attr->ia_atime = CURRENT_TIME;
1477 attr->ia_valid |= ATTR_ATIME_SET;
1479 if (!(attr->ia_valid & ATTR_MTIME_SET) &&
1480 (attr->ia_valid & ATTR_MTIME)) {
1481 attr->ia_mtime = CURRENT_TIME;
1482 attr->ia_valid |= ATTR_MTIME_SET;
1485 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1486 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %llu\n",
1487 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1488 (s64)ktime_get_real_seconds());
1490 /* We always do an MDS RPC, even if we're only changing the size;
1491 * only the MDS knows whether truncate() should fail with -ETXTBUSY
1494 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
1498 if (!S_ISDIR(inode->i_mode))
1499 inode_unlock(inode);
1501 /* truncate on a released file must failed with -ENODATA,
1502 * so size must not be set on MDS for released file
1503 * but other attributes must be set
1505 if (S_ISREG(inode->i_mode)) {
1506 struct lov_stripe_md *lsm;
1509 ll_layout_refresh(inode, &gen);
1510 lsm = ccc_inode_lsm_get(inode);
1511 if (lsm && lsm->lsm_pattern & LOV_PATTERN_F_RELEASED)
1512 file_is_released = true;
1513 ccc_inode_lsm_put(inode, lsm);
1515 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
1516 if (file_is_released) {
1517 rc = ll_layout_restore(inode, 0, attr->ia_size);
1521 file_is_released = false;
1522 ll_layout_refresh(inode, &gen);
1526 * If we are changing file size, file content is
1527 * modified, flag it.
1529 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1530 spin_lock(&lli->lli_lock);
1531 lli->lli_flags |= LLIF_DATA_MODIFIED;
1532 spin_unlock(&lli->lli_lock);
1533 op_data->op_bias |= MDS_DATA_MODIFIED;
1537 memcpy(&op_data->op_attr, attr, sizeof(*attr));
1539 /* Open epoch for truncate. */
1540 if (exp_connect_som(ll_i2mdexp(inode)) && !hsm_import &&
1541 (attr->ia_valid & (ATTR_SIZE | ATTR_MTIME | ATTR_MTIME_SET)))
1542 op_data->op_flags = MF_EPOCH_OPEN;
1544 rc = ll_md_setattr(dentry, op_data, &mod);
1548 /* RPC to MDT is sent, cancel data modification flag */
1549 if (op_data->op_bias & MDS_DATA_MODIFIED) {
1550 spin_lock(&lli->lli_lock);
1551 lli->lli_flags &= ~LLIF_DATA_MODIFIED;
1552 spin_unlock(&lli->lli_lock);
1555 ll_ioepoch_open(lli, op_data->op_ioepoch);
1556 if (!S_ISREG(inode->i_mode) || file_is_released) {
1561 if (attr->ia_valid & (ATTR_SIZE |
1562 ATTR_ATIME | ATTR_ATIME_SET |
1563 ATTR_MTIME | ATTR_MTIME_SET)) {
1564 /* For truncate and utimes sending attributes to OSTs, setting
1565 * mtime/atime to the past will be performed under PW [0:EOF]
1566 * extent lock (new_size:EOF for truncate). It may seem
1567 * excessive to send mtime/atime updates to OSTs when not
1568 * setting times to past, but it is necessary due to possible
1569 * time de-synchronization between MDT inode and OST objects
1571 if (attr->ia_valid & ATTR_SIZE)
1572 down_write(&lli->lli_trunc_sem);
1573 rc = cl_setattr_ost(inode, attr);
1574 if (attr->ia_valid & ATTR_SIZE)
1575 up_write(&lli->lli_trunc_sem);
1578 if (op_data->op_ioepoch) {
1579 rc1 = ll_setattr_done_writing(inode, op_data, mod);
1583 ll_finish_md_op_data(op_data);
1585 if (!S_ISDIR(inode->i_mode)) {
1587 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
1588 inode_dio_wait(inode);
1591 ll_stats_ops_tally(ll_i2sbi(inode), (attr->ia_valid & ATTR_SIZE) ?
1592 LPROC_LL_TRUNC : LPROC_LL_SETATTR, 1);
1597 int ll_setattr(struct dentry *de, struct iattr *attr)
1599 int mode = d_inode(de)->i_mode;
1601 if ((attr->ia_valid & (ATTR_CTIME | ATTR_SIZE | ATTR_MODE)) ==
1602 (ATTR_CTIME | ATTR_SIZE | ATTR_MODE))
1603 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1605 if (((attr->ia_valid & (ATTR_MODE | ATTR_FORCE | ATTR_SIZE)) ==
1606 (ATTR_SIZE | ATTR_MODE)) &&
1607 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
1608 (((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) &&
1609 !(attr->ia_mode & S_ISGID))))
1610 attr->ia_valid |= ATTR_FORCE;
1612 if ((attr->ia_valid & ATTR_MODE) &&
1614 !(attr->ia_mode & S_ISUID) &&
1615 !(attr->ia_valid & ATTR_KILL_SUID))
1616 attr->ia_valid |= ATTR_KILL_SUID;
1618 if ((attr->ia_valid & ATTR_MODE) &&
1619 ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) &&
1620 !(attr->ia_mode & S_ISGID) &&
1621 !(attr->ia_valid & ATTR_KILL_SGID))
1622 attr->ia_valid |= ATTR_KILL_SGID;
1624 return ll_setattr_raw(de, attr, false);
1627 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1628 __u64 max_age, __u32 flags)
1630 struct ll_sb_info *sbi = ll_s2sbi(sb);
1631 struct obd_statfs obd_osfs;
1634 rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
1636 CERROR("md_statfs fails: rc = %d\n", rc);
1640 osfs->os_type = sb->s_magic;
1642 CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
1643 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,
1646 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
1647 flags |= OBD_STATFS_NODELAY;
1649 rc = obd_statfs_rqset(sbi->ll_dt_exp, &obd_osfs, max_age, flags);
1651 CERROR("obd_statfs fails: rc = %d\n", rc);
1655 CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
1656 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1659 osfs->os_bsize = obd_osfs.os_bsize;
1660 osfs->os_blocks = obd_osfs.os_blocks;
1661 osfs->os_bfree = obd_osfs.os_bfree;
1662 osfs->os_bavail = obd_osfs.os_bavail;
1664 /* If we don't have as many objects free on the OST as inodes
1665 * on the MDS, we reduce the total number of inodes to
1666 * compensate, so that the "inodes in use" number is correct.
1668 if (obd_osfs.os_ffree < osfs->os_ffree) {
1669 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1671 osfs->os_ffree = obd_osfs.os_ffree;
1677 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1679 struct super_block *sb = de->d_sb;
1680 struct obd_statfs osfs;
1683 CDEBUG(D_VFSTRACE, "VFS Op: at %llu jiffies\n", get_jiffies_64());
1684 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1);
1686 /* Some amount of caching on the client is allowed */
1687 rc = ll_statfs_internal(sb, &osfs,
1688 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1693 statfs_unpack(sfs, &osfs);
1695 /* We need to downshift for all 32-bit kernels, because we can't
1696 * tell if the kernel is being called via sys_statfs64() or not.
1697 * Stop before overflowing f_bsize - in which case it is better
1698 * to just risk EOVERFLOW if caller is using old sys_statfs().
1700 if (sizeof(long) < 8) {
1701 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1704 osfs.os_blocks >>= 1;
1705 osfs.os_bfree >>= 1;
1706 osfs.os_bavail >>= 1;
1710 sfs->f_blocks = osfs.os_blocks;
1711 sfs->f_bfree = osfs.os_bfree;
1712 sfs->f_bavail = osfs.os_bavail;
1713 sfs->f_fsid = ll_s2sbi(sb)->ll_fsid;
1717 void ll_inode_size_lock(struct inode *inode)
1719 struct ll_inode_info *lli;
1721 LASSERT(!S_ISDIR(inode->i_mode));
1723 lli = ll_i2info(inode);
1724 mutex_lock(&lli->lli_size_mutex);
1727 void ll_inode_size_unlock(struct inode *inode)
1729 struct ll_inode_info *lli;
1731 lli = ll_i2info(inode);
1732 mutex_unlock(&lli->lli_size_mutex);
1735 int ll_update_inode(struct inode *inode, struct lustre_md *md)
1737 struct ll_inode_info *lli = ll_i2info(inode);
1738 struct mdt_body *body = md->body;
1739 struct lov_stripe_md *lsm = md->lsm;
1740 struct ll_sb_info *sbi = ll_i2sbi(inode);
1742 LASSERT((lsm != NULL) == ((body->mbo_valid & OBD_MD_FLEASIZE) != 0));
1744 if (!lli->lli_has_smd &&
1745 !(sbi->ll_flags & LL_SBI_LAYOUT_LOCK))
1746 cl_file_inode_init(inode, md);
1748 lli->lli_maxbytes = lsm->lsm_maxbytes;
1749 if (lli->lli_maxbytes > MAX_LFS_FILESIZE)
1750 lli->lli_maxbytes = MAX_LFS_FILESIZE;
1753 if (S_ISDIR(inode->i_mode)) {
1756 rc = ll_update_lsm_md(inode, md);
1761 #ifdef CONFIG_FS_POSIX_ACL
1762 if (body->mbo_valid & OBD_MD_FLACL) {
1763 spin_lock(&lli->lli_lock);
1764 if (lli->lli_posix_acl)
1765 posix_acl_release(lli->lli_posix_acl);
1766 lli->lli_posix_acl = md->posix_acl;
1767 spin_unlock(&lli->lli_lock);
1770 inode->i_ino = cl_fid_build_ino(&body->mbo_fid1,
1771 sbi->ll_flags & LL_SBI_32BIT_API);
1772 inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
1774 if (body->mbo_valid & OBD_MD_FLATIME) {
1775 if (body->mbo_atime > LTIME_S(inode->i_atime))
1776 LTIME_S(inode->i_atime) = body->mbo_atime;
1777 lli->lli_atime = body->mbo_atime;
1779 if (body->mbo_valid & OBD_MD_FLMTIME) {
1780 if (body->mbo_mtime > LTIME_S(inode->i_mtime)) {
1781 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %llu\n",
1782 inode->i_ino, LTIME_S(inode->i_mtime),
1784 LTIME_S(inode->i_mtime) = body->mbo_mtime;
1786 lli->lli_mtime = body->mbo_mtime;
1788 if (body->mbo_valid & OBD_MD_FLCTIME) {
1789 if (body->mbo_ctime > LTIME_S(inode->i_ctime))
1790 LTIME_S(inode->i_ctime) = body->mbo_ctime;
1791 lli->lli_ctime = body->mbo_ctime;
1793 if (body->mbo_valid & OBD_MD_FLMODE)
1794 inode->i_mode = (inode->i_mode & S_IFMT) |
1795 (body->mbo_mode & ~S_IFMT);
1796 if (body->mbo_valid & OBD_MD_FLTYPE)
1797 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1798 (body->mbo_mode & S_IFMT);
1799 LASSERT(inode->i_mode != 0);
1800 if (S_ISREG(inode->i_mode))
1801 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS + 1,
1802 LL_MAX_BLKSIZE_BITS);
1804 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
1805 if (body->mbo_valid & OBD_MD_FLUID)
1806 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
1807 if (body->mbo_valid & OBD_MD_FLGID)
1808 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
1809 if (body->mbo_valid & OBD_MD_FLFLAGS)
1810 inode->i_flags = ll_ext_to_inode_flags(body->mbo_flags);
1811 if (body->mbo_valid & OBD_MD_FLNLINK)
1812 set_nlink(inode, body->mbo_nlink);
1813 if (body->mbo_valid & OBD_MD_FLRDEV)
1814 inode->i_rdev = old_decode_dev(body->mbo_rdev);
1816 if (body->mbo_valid & OBD_MD_FLID) {
1817 /* FID shouldn't be changed! */
1818 if (fid_is_sane(&lli->lli_fid)) {
1819 LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
1820 "Trying to change FID "DFID" to the "DFID", inode "DFID"(%p)\n",
1821 PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
1822 PFID(ll_inode2fid(inode)), inode);
1824 lli->lli_fid = body->mbo_fid1;
1828 LASSERT(fid_seq(&lli->lli_fid) != 0);
1830 if (body->mbo_valid & OBD_MD_FLSIZE) {
1831 if (exp_connect_som(ll_i2mdexp(inode)) &&
1832 S_ISREG(inode->i_mode)) {
1833 struct lustre_handle lockh;
1834 enum ldlm_mode mode;
1836 /* As it is possible a blocking ast has been processed
1837 * by this time, we need to check there is an UPDATE
1838 * lock on the client and set LLIF_MDS_SIZE_LOCK holding
1841 mode = ll_take_md_lock(inode, MDS_INODELOCK_UPDATE,
1842 &lockh, LDLM_FL_CBPENDING,
1846 if (lli->lli_flags & (LLIF_DONE_WRITING |
1847 LLIF_EPOCH_PENDING |
1849 CERROR("%s: inode "DFID" flags %u still has size authority! do not trust the size got from MDS\n",
1850 sbi->ll_md_exp->exp_obd->obd_name,
1851 PFID(ll_inode2fid(inode)),
1854 /* Use old size assignment to avoid
1855 * deadlock bz14138 & bz14326
1857 i_size_write(inode, body->mbo_size);
1858 spin_lock(&lli->lli_lock);
1859 lli->lli_flags |= LLIF_MDS_SIZE_LOCK;
1860 spin_unlock(&lli->lli_lock);
1862 ldlm_lock_decref(&lockh, mode);
1865 /* Use old size assignment to avoid
1866 * deadlock bz14138 & bz14326
1868 i_size_write(inode, body->mbo_size);
1870 CDEBUG(D_VFSTRACE, "inode=%lu, updating i_size %llu\n",
1871 inode->i_ino, (unsigned long long)body->mbo_size);
1874 if (body->mbo_valid & OBD_MD_FLBLOCKS)
1875 inode->i_blocks = body->mbo_blocks;
1878 if (body->mbo_valid & OBD_MD_TSTATE) {
1879 if (body->mbo_t_state & MS_RESTORE)
1880 lli->lli_flags |= LLIF_FILE_RESTORING;
1886 int ll_read_inode2(struct inode *inode, void *opaque)
1888 struct lustre_md *md = opaque;
1889 struct ll_inode_info *lli = ll_i2info(inode);
1892 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1893 PFID(&lli->lli_fid), inode);
1895 LASSERT(!lli->lli_has_smd);
1897 /* Core attributes from the MDS first. This is a new inode, and
1898 * the VFS doesn't zero times in the core inode so we have to do
1899 * it ourselves. They will be overwritten by either MDS or OST
1900 * attributes - we just need to make sure they aren't newer.
1902 LTIME_S(inode->i_mtime) = 0;
1903 LTIME_S(inode->i_atime) = 0;
1904 LTIME_S(inode->i_ctime) = 0;
1906 rc = ll_update_inode(inode, md);
1910 /* OIDEBUG(inode); */
1912 if (S_ISREG(inode->i_mode)) {
1913 struct ll_sb_info *sbi = ll_i2sbi(inode);
1915 inode->i_op = &ll_file_inode_operations;
1916 inode->i_fop = sbi->ll_fop;
1917 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
1918 } else if (S_ISDIR(inode->i_mode)) {
1919 inode->i_op = &ll_dir_inode_operations;
1920 inode->i_fop = &ll_dir_operations;
1921 } else if (S_ISLNK(inode->i_mode)) {
1922 inode->i_op = &ll_fast_symlink_inode_operations;
1924 inode->i_op = &ll_special_inode_operations;
1926 init_special_inode(inode, inode->i_mode,
1933 void ll_delete_inode(struct inode *inode)
1935 struct ll_inode_info *lli = ll_i2info(inode);
1937 if (S_ISREG(inode->i_mode) && lli->lli_clob)
1938 /* discard all dirty pages before truncating them, required by
1939 * osc_extent implementation at LU-1030.
1941 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF,
1944 truncate_inode_pages_final(&inode->i_data);
1946 LASSERTF(!inode->i_data.nrpages,
1947 "inode=" DFID "(%p) nrpages=%lu, see http://jira.whamcloud.com/browse/LU-118\n",
1948 PFID(ll_inode2fid(inode)), inode, inode->i_data.nrpages);
1950 ll_clear_inode(inode);
1954 int ll_iocontrol(struct inode *inode, struct file *file,
1955 unsigned int cmd, unsigned long arg)
1957 struct ll_sb_info *sbi = ll_i2sbi(inode);
1958 struct ptlrpc_request *req = NULL;
1962 case FSFILT_IOC_GETFLAGS: {
1963 struct mdt_body *body;
1964 struct md_op_data *op_data;
1966 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
1967 0, 0, LUSTRE_OPC_ANY,
1969 if (IS_ERR(op_data))
1970 return PTR_ERR(op_data);
1972 op_data->op_valid = OBD_MD_FLFLAGS;
1973 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
1974 ll_finish_md_op_data(op_data);
1976 CERROR("%s: failure inode "DFID": rc = %d\n",
1977 sbi->ll_md_exp->exp_obd->obd_name,
1978 PFID(ll_inode2fid(inode)), rc);
1982 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1984 flags = body->mbo_flags;
1986 ptlrpc_req_finished(req);
1988 return put_user(flags, (int __user *)arg);
1990 case FSFILT_IOC_SETFLAGS: {
1991 struct lov_stripe_md *lsm;
1992 struct obd_info oinfo = { };
1993 struct md_op_data *op_data;
1995 if (get_user(flags, (int __user *)arg))
1998 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
1999 LUSTRE_OPC_ANY, NULL);
2000 if (IS_ERR(op_data))
2001 return PTR_ERR(op_data);
2003 op_data->op_attr_flags = flags;
2004 op_data->op_attr.ia_valid |= ATTR_ATTR_FLAG;
2005 rc = md_setattr(sbi->ll_md_exp, op_data,
2006 NULL, 0, NULL, 0, &req, NULL);
2007 ll_finish_md_op_data(op_data);
2008 ptlrpc_req_finished(req);
2012 inode->i_flags = ll_ext_to_inode_flags(flags);
2014 lsm = ccc_inode_lsm_get(inode);
2015 if (!lsm_has_objects(lsm)) {
2016 ccc_inode_lsm_put(inode, lsm);
2020 oinfo.oi_oa = kmem_cache_zalloc(obdo_cachep, GFP_NOFS);
2022 ccc_inode_lsm_put(inode, lsm);
2026 oinfo.oi_oa->o_oi = lsm->lsm_oi;
2027 oinfo.oi_oa->o_flags = flags;
2028 oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS |
2030 obdo_set_parent_fid(oinfo.oi_oa, &ll_i2info(inode)->lli_fid);
2031 rc = obd_setattr_rqset(sbi->ll_dt_exp, &oinfo, NULL);
2032 kmem_cache_free(obdo_cachep, oinfo.oi_oa);
2033 ccc_inode_lsm_put(inode, lsm);
2035 if (rc && rc != -EPERM && rc != -EACCES)
2036 CERROR("osc_setattr_async fails: rc = %d\n", rc);
2047 int ll_flush_ctx(struct inode *inode)
2049 struct ll_sb_info *sbi = ll_i2sbi(inode);
2051 CDEBUG(D_SEC, "flush context for user %d\n",
2052 from_kuid(&init_user_ns, current_uid()));
2054 obd_set_info_async(NULL, sbi->ll_md_exp,
2055 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2057 obd_set_info_async(NULL, sbi->ll_dt_exp,
2058 sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2063 /* umount -f client means force down, don't save state */
2064 void ll_umount_begin(struct super_block *sb)
2066 struct ll_sb_info *sbi = ll_s2sbi(sb);
2067 struct obd_device *obd;
2068 struct obd_ioctl_data *ioc_data;
2070 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2071 sb->s_count, atomic_read(&sb->s_active));
2073 obd = class_exp2obd(sbi->ll_md_exp);
2075 CERROR("Invalid MDC connection handle %#llx\n",
2076 sbi->ll_md_exp->exp_handle.h_cookie);
2081 obd = class_exp2obd(sbi->ll_dt_exp);
2083 CERROR("Invalid LOV connection handle %#llx\n",
2084 sbi->ll_dt_exp->exp_handle.h_cookie);
2089 ioc_data = kzalloc(sizeof(*ioc_data), GFP_NOFS);
2091 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2092 sizeof(*ioc_data), ioc_data, NULL);
2094 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2095 sizeof(*ioc_data), ioc_data, NULL);
2100 /* Really, we'd like to wait until there are no requests outstanding,
2101 * and then continue. For now, we just invalidate the requests,
2102 * schedule() and sleep one second if needed, and hope.
2107 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2109 struct ll_sb_info *sbi = ll_s2sbi(sb);
2110 char *profilenm = get_profile_name(sb);
2114 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
2115 read_only = *flags & MS_RDONLY;
2116 err = obd_set_info_async(NULL, sbi->ll_md_exp,
2117 sizeof(KEY_READ_ONLY),
2118 KEY_READ_ONLY, sizeof(read_only),
2121 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2122 profilenm, read_only ?
2123 "read-only" : "read-write", err);
2128 sb->s_flags |= MS_RDONLY;
2130 sb->s_flags &= ~MS_RDONLY;
2132 if (sbi->ll_flags & LL_SBI_VERBOSE)
2133 LCONSOLE_WARN("Remounted %s %s\n", profilenm,
2134 read_only ? "read-only" : "read-write");
2140 * Cleanup the open handle that is cached on MDT-side.
2142 * For open case, the client side open handling thread may hit error
2143 * after the MDT grant the open. Under such case, the client should
2144 * send close RPC to the MDT as cleanup; otherwise, the open handle
2145 * on the MDT will be leaked there until the client umount or evicted.
2147 * In further, if someone unlinked the file, because the open handle
2148 * holds the reference on such file/object, then it will block the
2149 * subsequent threads that want to locate such object via FID.
2151 * \param[in] sb super block for this file-system
2152 * \param[in] open_req pointer to the original open request
2154 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
2156 struct mdt_body *body;
2157 struct md_op_data *op_data;
2158 struct ptlrpc_request *close_req = NULL;
2159 struct obd_export *exp = ll_s2sbi(sb)->ll_md_exp;
2161 body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
2162 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
2166 op_data->op_fid1 = body->mbo_fid1;
2167 op_data->op_ioepoch = body->mbo_ioepoch;
2168 op_data->op_handle = body->mbo_handle;
2169 op_data->op_mod_time = get_seconds();
2170 md_close(exp, op_data, NULL, &close_req);
2171 ptlrpc_req_finished(close_req);
2172 ll_finish_md_op_data(op_data);
2175 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
2176 struct super_block *sb, struct lookup_intent *it)
2178 struct ll_sb_info *sbi = NULL;
2179 struct lustre_md md = { NULL };
2182 LASSERT(*inode || sb);
2183 sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2184 rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
2185 sbi->ll_md_exp, &md);
2190 rc = ll_update_inode(*inode, &md);
2197 * At this point server returns to client's same fid as client
2198 * generated for creating. So using ->fid1 is okay here.
2200 if (!fid_is_sane(&md.body->mbo_fid1)) {
2201 CERROR("%s: Fid is insane " DFID "\n",
2202 ll_get_fsname(sb, NULL, 0),
2203 PFID(&md.body->mbo_fid1));
2208 *inode = ll_iget(sb, cl_fid_build_ino(&md.body->mbo_fid1,
2209 sbi->ll_flags & LL_SBI_32BIT_API),
2211 if (IS_ERR(*inode)) {
2212 #ifdef CONFIG_FS_POSIX_ACL
2214 posix_acl_release(md.posix_acl);
2215 md.posix_acl = NULL;
2219 CERROR("new_inode -fatal: rc %d\n", rc);
2224 /* Handling piggyback layout lock.
2225 * Layout lock can be piggybacked by getattr and open request.
2226 * The lsm can be applied to inode only if it comes with a layout lock
2227 * otherwise correct layout may be overwritten, for example:
2228 * 1. proc1: mdt returns a lsm but not granting layout
2229 * 2. layout was changed by another client
2230 * 3. proc2: refresh layout and layout lock granted
2231 * 4. proc1: to apply a stale layout
2233 if (it && it->it_lock_mode != 0) {
2234 struct lustre_handle lockh;
2235 struct ldlm_lock *lock;
2237 lockh.cookie = it->it_lock_handle;
2238 lock = ldlm_handle2lock(&lockh);
2240 if (ldlm_has_layout(lock)) {
2241 struct cl_object_conf conf;
2243 memset(&conf, 0, sizeof(conf));
2244 conf.coc_opc = OBJECT_CONF_SET;
2245 conf.coc_inode = *inode;
2246 conf.coc_lock = lock;
2247 conf.u.coc_md = &md;
2248 (void)ll_layout_conf(*inode, &conf);
2250 LDLM_LOCK_PUT(lock);
2255 obd_free_memmd(sbi->ll_dt_exp, &md.lsm);
2256 md_free_lustre_md(sbi->ll_md_exp, &md);
2259 if (rc != 0 && it && it->it_op & IT_OPEN)
2260 ll_open_cleanup(sb ? sb : (*inode)->i_sb, req);
2265 int ll_obd_statfs(struct inode *inode, void __user *arg)
2267 struct ll_sb_info *sbi = NULL;
2268 struct obd_export *exp;
2270 struct obd_ioctl_data *data = NULL;
2279 sbi = ll_i2sbi(inode);
2285 rc = obd_ioctl_getdata(&buf, &len, arg);
2290 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2291 !data->ioc_pbuf1 || !data->ioc_pbuf2) {
2296 if (data->ioc_inllen1 != sizeof(__u32) ||
2297 data->ioc_inllen2 != sizeof(__u32) ||
2298 data->ioc_plen1 != sizeof(struct obd_statfs) ||
2299 data->ioc_plen2 != sizeof(struct obd_uuid)) {
2304 memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2305 if (type & LL_STATFS_LMV) {
2306 exp = sbi->ll_md_exp;
2307 } else if (type & LL_STATFS_LOV) {
2308 exp = sbi->ll_dt_exp;
2314 rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL);
2319 obd_ioctl_freedata(buf, len);
2323 int ll_process_config(struct lustre_cfg *lcfg)
2327 struct lprocfs_static_vars lvars;
2331 lprocfs_llite_init_vars(&lvars);
2333 /* The instance name contains the sb: lustre-client-aacfe000 */
2334 ptr = strrchr(lustre_cfg_string(lcfg, 0), '-');
2335 if (!ptr || !*(++ptr))
2337 rc = kstrtoul(ptr, 16, &x);
2341 /* This better be a real Lustre superblock! */
2342 LASSERT(s2lsi((struct super_block *)sb)->lsi_lmd->lmd_magic == LMD_MAGIC);
2344 /* Note we have not called client_common_fill_super yet, so
2345 * proc fns must be able to handle that!
2347 rc = class_process_proc_param(PARAM_LLITE, lvars.obd_vars,
2354 /* this function prepares md_op_data hint for passing ot down to MD stack. */
2355 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
2356 struct inode *i1, struct inode *i2,
2357 const char *name, size_t namelen,
2358 u32 mode, __u32 opc, void *data)
2361 /* Do not reuse namelen for something else. */
2363 return ERR_PTR(-EINVAL);
2365 if (namelen > ll_i2sbi(i1)->ll_namelen)
2366 return ERR_PTR(-ENAMETOOLONG);
2368 if (!lu_name_is_valid_2(name, namelen))
2369 return ERR_PTR(-EINVAL);
2373 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
2376 return ERR_PTR(-ENOMEM);
2378 ll_i2gids(op_data->op_suppgids, i1, i2);
2379 op_data->op_fid1 = *ll_inode2fid(i1);
2380 op_data->op_default_stripe_offset = -1;
2381 if (S_ISDIR(i1->i_mode)) {
2382 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
2383 op_data->op_default_stripe_offset =
2384 ll_i2info(i1)->lli_def_stripe_offset;
2388 op_data->op_fid2 = *ll_inode2fid(i2);
2389 if (S_ISDIR(i2->i_mode))
2390 op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
2392 fid_zero(&op_data->op_fid2);
2395 if (ll_i2sbi(i1)->ll_flags & LL_SBI_64BIT_HASH)
2396 op_data->op_cli_flags |= CLI_HASH64;
2398 if (ll_need_32bit_api(ll_i2sbi(i1)))
2399 op_data->op_cli_flags |= CLI_API32;
2401 op_data->op_name = name;
2402 op_data->op_namelen = namelen;
2403 op_data->op_mode = mode;
2404 op_data->op_mod_time = ktime_get_real_seconds();
2405 op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2406 op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2407 op_data->op_cap = cfs_curproc_cap_pack();
2408 op_data->op_bias = 0;
2409 op_data->op_cli_flags = 0;
2410 if ((opc == LUSTRE_OPC_CREATE) && name &&
2411 filename_is_volatile(name, namelen, &op_data->op_mds))
2412 op_data->op_bias |= MDS_CREATE_VOLATILE;
2414 op_data->op_mds = 0;
2415 op_data->op_data = data;
2417 /* When called by ll_setattr_raw, file is i1. */
2418 if (ll_i2info(i1)->lli_flags & LLIF_DATA_MODIFIED)
2419 op_data->op_bias |= MDS_DATA_MODIFIED;
2424 void ll_finish_md_op_data(struct md_op_data *op_data)
2429 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
2431 struct ll_sb_info *sbi;
2433 LASSERT(seq && dentry);
2434 sbi = ll_s2sbi(dentry->d_sb);
2436 if (sbi->ll_flags & LL_SBI_NOLCK)
2437 seq_puts(seq, ",nolock");
2439 if (sbi->ll_flags & LL_SBI_FLOCK)
2440 seq_puts(seq, ",flock");
2442 if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
2443 seq_puts(seq, ",localflock");
2445 if (sbi->ll_flags & LL_SBI_USER_XATTR)
2446 seq_puts(seq, ",user_xattr");
2448 if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
2449 seq_puts(seq, ",lazystatfs");
2451 if (sbi->ll_flags & LL_SBI_USER_FID2PATH)
2452 seq_puts(seq, ",user_fid2path");
2458 * Get obd name by cmd, and copy out to user space
2460 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
2462 struct ll_sb_info *sbi = ll_i2sbi(inode);
2463 struct obd_device *obd;
2465 if (cmd == OBD_IOC_GETDTNAME)
2466 obd = class_exp2obd(sbi->ll_dt_exp);
2467 else if (cmd == OBD_IOC_GETMDNAME)
2468 obd = class_exp2obd(sbi->ll_md_exp);
2475 if (copy_to_user((void __user *)arg, obd->obd_name,
2476 strlen(obd->obd_name) + 1))
2483 * Get lustre file system name by \a sbi. If \a buf is provided(non-NULL), the
2484 * fsname will be returned in this buffer; otherwise, a static buffer will be
2485 * used to store the fsname and returned to caller.
2487 char *ll_get_fsname(struct super_block *sb, char *buf, int buflen)
2489 static char fsname_static[MTI_NAME_MAXLEN];
2490 struct lustre_sb_info *lsi = s2lsi(sb);
2495 /* this means the caller wants to use static buffer
2496 * and it doesn't care about race. Usually this is
2497 * in error reporting path
2499 buf = fsname_static;
2500 buflen = sizeof(fsname_static);
2503 len = strlen(lsi->lsi_lmd->lmd_profile);
2504 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
2505 if (ptr && (strcmp(ptr, "-client") == 0))
2508 if (unlikely(len >= buflen))
2510 strncpy(buf, lsi->lsi_lmd->lmd_profile, len);
2516 void ll_dirty_page_discard_warn(struct page *page, int ioret)
2518 char *buf, *path = NULL;
2519 struct dentry *dentry = NULL;
2520 struct vvp_object *obj = cl_inode2vvp(page->mapping->host);
2522 /* this can be called inside spin lock so use GFP_ATOMIC. */
2523 buf = (char *)__get_free_page(GFP_ATOMIC);
2525 dentry = d_find_alias(page->mapping->host);
2527 path = dentry_path_raw(dentry, buf, PAGE_SIZE);
2531 "%s: dirty page discard: %s/fid: " DFID "/%s may get corrupted (rc %d)\n",
2532 ll_get_fsname(page->mapping->host->i_sb, NULL, 0),
2533 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
2534 PFID(&obj->vob_header.coh_lu.loh_fid),
2535 (path && !IS_ERR(path)) ? path : "", ioret);
2541 free_page((unsigned long)buf);
2544 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
2545 struct lov_user_md **kbuf)
2547 struct lov_user_md lum;
2550 if (copy_from_user(&lum, md, sizeof(lum))) {
2555 lum_size = ll_lov_user_md_size(&lum);
2559 *kbuf = kzalloc(lum_size, GFP_NOFS);
2565 if (copy_from_user(*kbuf, md, lum_size) != 0) {
2575 * Compute llite root squash state after a change of root squash
2576 * configuration setting or add/remove of a lnet nid
2578 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
2580 struct root_squash_info *squash = &sbi->ll_squash;
2581 lnet_process_id_t id;
2585 /* Update norootsquash flag */
2586 down_write(&squash->rsi_sem);
2587 if (list_empty(&squash->rsi_nosquash_nids)) {
2588 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
2591 * Do not apply root squash as soon as one of our NIDs is
2592 * in the nosquash_nids list
2597 while (LNetGetId(i++, &id) != -ENOENT) {
2598 if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
2600 if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) {
2606 sbi->ll_flags |= LL_SBI_NOROOTSQUASH;
2608 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
2610 up_write(&squash->rsi_sem);
2614 * Parse linkea content to extract information about a given hardlink
2616 * \param[in] ldata - Initialized linkea data
2617 * \param[in] linkno - Link identifier
2618 * \param[out] parent_fid - The entry's parent FID
2619 * \param[in] size - Entry name destination buffer
2621 * \retval 0 on success
2622 * \retval Appropriate negative error code on failure
2624 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
2625 struct lu_fid *parent_fid, struct lu_name *ln)
2630 rc = linkea_init(ldata);
2634 if (linkno >= ldata->ld_leh->leh_reccount)
2635 /* beyond last link */
2638 linkea_first_entry(ldata);
2639 for (idx = 0; ldata->ld_lee; idx++) {
2640 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
2645 linkea_next_entry(ldata);
2655 * Get parent FID and name of an identified link. Operation is performed for
2656 * a given link number, letting the caller iterate over linkno to list one or
2657 * all links of an entry.
2659 * \param[in] file - File descriptor against which to perform the operation
2660 * \param[in,out] arg - User-filled structure containing the linkno to operate
2661 * on and the available size. It is eventually filled with
2662 * the requested information or left untouched on error
2664 * \retval - 0 on success
2665 * \retval - Appropriate negative error code on failure
2667 int ll_getparent(struct file *file, struct getparent __user *arg)
2669 struct inode *inode = file_inode(file);
2670 struct linkea_data *ldata;
2671 struct lu_fid parent_fid;
2672 struct lu_buf buf = {
2681 if (!capable(CFS_CAP_DAC_READ_SEARCH) &&
2682 !(ll_i2sbi(inode)->ll_flags & LL_SBI_USER_FID2PATH))
2685 if (get_user(name_size, &arg->gp_name_size))
2688 if (get_user(linkno, &arg->gp_linkno))
2691 if (name_size > PATH_MAX)
2694 ldata = kzalloc(sizeof(*ldata), GFP_NOFS);
2698 rc = linkea_data_new(ldata, &buf);
2702 rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
2703 buf.lb_len, OBD_MD_FLXATTR);
2707 rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
2711 if (ln.ln_namelen >= name_size) {
2716 if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid))) {
2721 if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen)) {
2726 if (put_user('\0', arg->gp_name + ln.ln_namelen)) {