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
;
106 sbi
->ll_flags
|= LL_SBI_LAZYSTATFS
;
108 for (i
= 0; i
<= LL_PROCESS_HIST_MAX
; i
++) {
109 spin_lock_init(&sbi
->ll_rw_extents_info
.pp_extents
[i
].
111 spin_lock_init(&sbi
->ll_rw_extents_info
.pp_extents
[i
].
115 /* metadata statahead is enabled by default */
116 sbi
->ll_sa_max
= LL_SA_RPC_DEF
;
117 atomic_set(&sbi
->ll_sa_total
, 0);
118 atomic_set(&sbi
->ll_sa_wrong
, 0);
119 atomic_set(&sbi
->ll_sa_running
, 0);
120 atomic_set(&sbi
->ll_agl_total
, 0);
121 sbi
->ll_flags
|= LL_SBI_AGL_ENABLED
;
124 sbi
->ll_squash
.rsi_uid
= 0;
125 sbi
->ll_squash
.rsi_gid
= 0;
126 INIT_LIST_HEAD(&sbi
->ll_squash
.rsi_nosquash_nids
);
127 init_rwsem(&sbi
->ll_squash
.rsi_sem
);
134 static void ll_free_sbi(struct super_block
*sb
)
136 struct ll_sb_info
*sbi
= ll_s2sbi(sb
);
139 if (!list_empty(&sbi
->ll_squash
.rsi_nosquash_nids
))
140 cfs_free_nidlist(&sbi
->ll_squash
.rsi_nosquash_nids
);
141 cl_cache_decref(sbi
->ll_cache
);
142 sbi
->ll_cache
= NULL
;
148 static int client_common_fill_super(struct super_block
*sb
, char *md
, char *dt
,
149 struct vfsmount
*mnt
)
151 struct inode
*root
= NULL
;
152 struct ll_sb_info
*sbi
= ll_s2sbi(sb
);
153 struct obd_device
*obd
;
154 struct obd_statfs
*osfs
= NULL
;
155 struct ptlrpc_request
*request
= NULL
;
156 struct obd_connect_data
*data
= NULL
;
157 struct obd_uuid
*uuid
;
158 struct md_op_data
*op_data
;
159 struct lustre_md lmd
;
161 int size
, err
, checksum
;
163 obd
= class_name2obd(md
);
165 CERROR("MD %s: not setup or attached\n", md
);
169 data
= kzalloc(sizeof(*data
), GFP_NOFS
);
173 osfs
= kzalloc(sizeof(*osfs
), GFP_NOFS
);
179 /* indicate the features supported by this client */
180 data
->ocd_connect_flags
= OBD_CONNECT_IBITS
| OBD_CONNECT_NODEVOH
|
181 OBD_CONNECT_ATTRFID
|
182 OBD_CONNECT_VERSION
| OBD_CONNECT_BRW_SIZE
|
183 OBD_CONNECT_CANCELSET
| OBD_CONNECT_FID
|
184 OBD_CONNECT_AT
| OBD_CONNECT_LOV_V3
|
185 OBD_CONNECT_VBR
| OBD_CONNECT_FULL20
|
186 OBD_CONNECT_64BITHASH
|
187 OBD_CONNECT_EINPROGRESS
|
188 OBD_CONNECT_JOBSTATS
| OBD_CONNECT_LVB_TYPE
|
189 OBD_CONNECT_LAYOUTLOCK
|
190 OBD_CONNECT_PINGLESS
|
191 OBD_CONNECT_MAX_EASIZE
|
192 OBD_CONNECT_FLOCK_DEAD
|
193 OBD_CONNECT_DISP_STRIPE
| OBD_CONNECT_LFSCK
|
194 OBD_CONNECT_OPEN_BY_FID
|
195 OBD_CONNECT_DIR_STRIPE
|
196 OBD_CONNECT_BULK_MBITS
;
198 if (sbi
->ll_flags
& LL_SBI_LRU_RESIZE
)
199 data
->ocd_connect_flags
|= OBD_CONNECT_LRU_RESIZE
;
200 #ifdef CONFIG_FS_POSIX_ACL
201 data
->ocd_connect_flags
|= OBD_CONNECT_ACL
| OBD_CONNECT_UMASK
;
204 if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT
))
205 /* flag mdc connection as lightweight, only used for test
206 * purpose, use with care
208 data
->ocd_connect_flags
|= OBD_CONNECT_LIGHTWEIGHT
;
210 data
->ocd_ibits_known
= MDS_INODELOCK_FULL
;
211 data
->ocd_version
= LUSTRE_VERSION_CODE
;
213 if (sb
->s_flags
& MS_RDONLY
)
214 data
->ocd_connect_flags
|= OBD_CONNECT_RDONLY
;
215 if (sbi
->ll_flags
& LL_SBI_USER_XATTR
)
216 data
->ocd_connect_flags
|= OBD_CONNECT_XATTR
;
218 if (sbi
->ll_flags
& LL_SBI_FLOCK
)
219 sbi
->ll_fop
= &ll_file_operations_flock
;
220 else if (sbi
->ll_flags
& LL_SBI_LOCALFLOCK
)
221 sbi
->ll_fop
= &ll_file_operations
;
223 sbi
->ll_fop
= &ll_file_operations_noflock
;
226 data
->ocd_connect_flags
|= OBD_CONNECT_REAL
;
228 /* always ping even if server suppress_pings */
229 if (sbi
->ll_flags
& LL_SBI_ALWAYS_PING
)
230 data
->ocd_connect_flags
&= ~OBD_CONNECT_PINGLESS
;
232 data
->ocd_brw_size
= MD_MAX_BRW_SIZE
;
234 err
= obd_connect(NULL
, &sbi
->ll_md_exp
, obd
, &sbi
->ll_sb_uuid
,
237 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",
241 CERROR("cannot connect to %s: rc = %d\n", md
, err
);
245 sbi
->ll_md_exp
->exp_connect_data
= *data
;
247 err
= obd_fid_init(sbi
->ll_md_exp
->exp_obd
, sbi
->ll_md_exp
,
248 LUSTRE_SEQ_METADATA
);
250 CERROR("%s: Can't init metadata layer FID infrastructure, rc = %d\n",
251 sbi
->ll_md_exp
->exp_obd
->obd_name
, err
);
255 /* For mount, we only need fs info from MDT0, and also in DNE, it
256 * can make sure the client can be mounted as long as MDT0 is
259 err
= obd_statfs(NULL
, sbi
->ll_md_exp
, osfs
,
260 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
261 OBD_STATFS_FOR_MDT0
);
265 /* This needs to be after statfs to ensure connect has finished.
266 * Note that "data" does NOT contain the valid connect reply.
267 * If connecting to a 1.8 server there will be no LMV device, so
268 * we can access the MDC export directly and exp_connect_flags will
269 * be non-zero, but if accessing an upgraded 2.1 server it will
270 * have the correct flags filled in.
271 * XXX: fill in the LMV exp_connect_flags from MDC(s).
273 valid
= exp_connect_flags(sbi
->ll_md_exp
) & CLIENT_CONNECT_MDT_REQD
;
274 if (exp_connect_flags(sbi
->ll_md_exp
) != 0 &&
275 valid
!= CLIENT_CONNECT_MDT_REQD
) {
278 buf
= kzalloc(PAGE_SIZE
, GFP_KERNEL
);
283 obd_connect_flags2str(buf
, PAGE_SIZE
,
284 valid
^ CLIENT_CONNECT_MDT_REQD
, ",");
285 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",
286 sbi
->ll_md_exp
->exp_obd
->obd_name
, buf
);
292 size
= sizeof(*data
);
293 err
= obd_get_info(NULL
, sbi
->ll_md_exp
, sizeof(KEY_CONN_DATA
),
294 KEY_CONN_DATA
, &size
, data
);
296 CERROR("%s: Get connect data failed: rc = %d\n",
297 sbi
->ll_md_exp
->exp_obd
->obd_name
, err
);
301 LASSERT(osfs
->os_bsize
);
302 sb
->s_blocksize
= osfs
->os_bsize
;
303 sb
->s_blocksize_bits
= log2(osfs
->os_bsize
);
304 sb
->s_magic
= LL_SUPER_MAGIC
;
305 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
306 sbi
->ll_namelen
= osfs
->os_namelen
;
307 sbi
->ll_mnt
.mnt
= current
->fs
->root
.mnt
;
309 if ((sbi
->ll_flags
& LL_SBI_USER_XATTR
) &&
310 !(data
->ocd_connect_flags
& OBD_CONNECT_XATTR
)) {
311 LCONSOLE_INFO("Disabling user_xattr feature because it is not supported on the server\n");
312 sbi
->ll_flags
&= ~LL_SBI_USER_XATTR
;
315 if (data
->ocd_connect_flags
& OBD_CONNECT_ACL
) {
316 sb
->s_flags
|= MS_POSIXACL
;
317 sbi
->ll_flags
|= LL_SBI_ACL
;
319 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
320 sb
->s_flags
&= ~MS_POSIXACL
;
321 sbi
->ll_flags
&= ~LL_SBI_ACL
;
324 if (data
->ocd_connect_flags
& OBD_CONNECT_64BITHASH
)
325 sbi
->ll_flags
|= LL_SBI_64BIT_HASH
;
327 if (data
->ocd_connect_flags
& OBD_CONNECT_BRW_SIZE
)
328 sbi
->ll_md_brw_pages
= data
->ocd_brw_size
>> PAGE_SHIFT
;
330 sbi
->ll_md_brw_pages
= 1;
332 if (data
->ocd_connect_flags
& OBD_CONNECT_LAYOUTLOCK
)
333 sbi
->ll_flags
|= LL_SBI_LAYOUT_LOCK
;
335 if (data
->ocd_ibits_known
& MDS_INODELOCK_XATTR
) {
336 if (!(data
->ocd_connect_flags
& OBD_CONNECT_MAX_EASIZE
)) {
338 "%s: disabling xattr cache due to unknown maximum xattr size.\n",
341 sbi
->ll_flags
|= LL_SBI_XATTR_CACHE
;
342 sbi
->ll_xattr_cache_enabled
= 1;
346 obd
= class_name2obd(dt
);
348 CERROR("DT %s: not setup or attached\n", dt
);
353 data
->ocd_connect_flags
= OBD_CONNECT_GRANT
| OBD_CONNECT_VERSION
|
354 OBD_CONNECT_REQPORTAL
| OBD_CONNECT_BRW_SIZE
|
355 OBD_CONNECT_CANCELSET
| OBD_CONNECT_FID
|
356 OBD_CONNECT_SRVLOCK
| OBD_CONNECT_TRUNCLOCK
|
357 OBD_CONNECT_AT
| OBD_CONNECT_OSS_CAPA
|
358 OBD_CONNECT_VBR
| OBD_CONNECT_FULL20
|
359 OBD_CONNECT_64BITHASH
| OBD_CONNECT_MAXBYTES
|
360 OBD_CONNECT_EINPROGRESS
|
361 OBD_CONNECT_JOBSTATS
| OBD_CONNECT_LVB_TYPE
|
362 OBD_CONNECT_LAYOUTLOCK
|
363 OBD_CONNECT_PINGLESS
| OBD_CONNECT_LFSCK
|
364 OBD_CONNECT_BULK_MBITS
;
366 if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_CKSUM
)) {
367 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
368 * disabled by default, because it can still be enabled on the
369 * fly via /sys. As a consequence, we still need to come to an
370 * agreement on the supported algorithms at connect time
372 data
->ocd_connect_flags
|= OBD_CONNECT_CKSUM
;
374 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY
))
375 data
->ocd_cksum_types
= OBD_CKSUM_ADLER
;
377 data
->ocd_cksum_types
= cksum_types_supported_client();
380 data
->ocd_connect_flags
|= OBD_CONNECT_LRU_RESIZE
;
382 /* always ping even if server suppress_pings */
383 if (sbi
->ll_flags
& LL_SBI_ALWAYS_PING
)
384 data
->ocd_connect_flags
&= ~OBD_CONNECT_PINGLESS
;
386 CDEBUG(D_RPCTRACE
, "ocd_connect_flags: %#llx ocd_version: %d ocd_grant: %d\n",
387 data
->ocd_connect_flags
,
388 data
->ocd_version
, data
->ocd_grant
);
390 obd
->obd_upcall
.onu_owner
= &sbi
->ll_lco
;
391 obd
->obd_upcall
.onu_upcall
= cl_ocd_update
;
393 data
->ocd_brw_size
= DT_MAX_BRW_SIZE
;
395 err
= obd_connect(NULL
, &sbi
->ll_dt_exp
, obd
, &sbi
->ll_sb_uuid
, data
,
398 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",
402 CERROR("%s: Cannot connect to %s: rc = %d\n",
403 sbi
->ll_dt_exp
->exp_obd
->obd_name
, dt
, err
);
407 sbi
->ll_dt_exp
->exp_connect_data
= *data
;
409 err
= obd_fid_init(sbi
->ll_dt_exp
->exp_obd
, sbi
->ll_dt_exp
,
410 LUSTRE_SEQ_METADATA
);
412 CERROR("%s: Can't init data layer FID infrastructure, rc = %d\n",
413 sbi
->ll_dt_exp
->exp_obd
->obd_name
, err
);
417 mutex_lock(&sbi
->ll_lco
.lco_lock
);
418 sbi
->ll_lco
.lco_flags
= data
->ocd_connect_flags
;
419 sbi
->ll_lco
.lco_md_exp
= sbi
->ll_md_exp
;
420 sbi
->ll_lco
.lco_dt_exp
= sbi
->ll_dt_exp
;
421 mutex_unlock(&sbi
->ll_lco
.lco_lock
);
423 fid_zero(&sbi
->ll_root_fid
);
424 err
= md_getstatus(sbi
->ll_md_exp
, &sbi
->ll_root_fid
);
426 CERROR("cannot mds_connect: rc = %d\n", err
);
429 if (!fid_is_sane(&sbi
->ll_root_fid
)) {
430 CERROR("%s: Invalid root fid "DFID
" during mount\n",
431 sbi
->ll_md_exp
->exp_obd
->obd_name
,
432 PFID(&sbi
->ll_root_fid
));
436 CDEBUG(D_SUPER
, "rootfid "DFID
"\n", PFID(&sbi
->ll_root_fid
));
438 sb
->s_op
= &lustre_super_operations
;
439 sb
->s_xattr
= ll_xattr_handlers
;
440 #if THREAD_SIZE >= 8192 /*b=17630*/
441 sb
->s_export_op
= &lustre_export_operations
;
445 * XXX: move this to after cbd setup?
447 valid
= OBD_MD_FLGETATTR
| OBD_MD_FLBLOCKS
| OBD_MD_FLMODEASIZE
;
448 if (sbi
->ll_flags
& LL_SBI_ACL
)
449 valid
|= OBD_MD_FLACL
;
451 op_data
= kzalloc(sizeof(*op_data
), GFP_NOFS
);
457 op_data
->op_fid1
= sbi
->ll_root_fid
;
458 op_data
->op_mode
= 0;
459 op_data
->op_valid
= valid
;
461 err
= md_getattr(sbi
->ll_md_exp
, op_data
, &request
);
464 CERROR("%s: md_getattr failed for root: rc = %d\n",
465 sbi
->ll_md_exp
->exp_obd
->obd_name
, err
);
469 err
= md_get_lustre_md(sbi
->ll_md_exp
, request
, sbi
->ll_dt_exp
,
470 sbi
->ll_md_exp
, &lmd
);
472 CERROR("failed to understand root inode md: rc = %d\n", err
);
473 ptlrpc_req_finished(request
);
477 LASSERT(fid_is_sane(&sbi
->ll_root_fid
));
478 root
= ll_iget(sb
, cl_fid_build_ino(&sbi
->ll_root_fid
,
479 sbi
->ll_flags
& LL_SBI_32BIT_API
),
481 md_free_lustre_md(sbi
->ll_md_exp
, &lmd
);
482 ptlrpc_req_finished(request
);
485 #ifdef CONFIG_FS_POSIX_ACL
487 posix_acl_release(lmd
.posix_acl
);
488 lmd
.posix_acl
= NULL
;
492 CERROR("lustre_lite: bad iget4 for root\n");
496 checksum
= sbi
->ll_flags
& LL_SBI_CHECKSUM
;
497 err
= obd_set_info_async(NULL
, sbi
->ll_dt_exp
, sizeof(KEY_CHECKSUM
),
498 KEY_CHECKSUM
, sizeof(checksum
), &checksum
,
501 CERROR("%s: Set checksum failed: rc = %d\n",
502 sbi
->ll_dt_exp
->exp_obd
->obd_name
, err
);
507 err
= obd_set_info_async(NULL
, sbi
->ll_dt_exp
, sizeof(KEY_CACHE_SET
),
508 KEY_CACHE_SET
, sizeof(*sbi
->ll_cache
),
509 sbi
->ll_cache
, NULL
);
511 CERROR("%s: Set cache_set failed: rc = %d\n",
512 sbi
->ll_dt_exp
->exp_obd
->obd_name
, err
);
516 sb
->s_root
= d_make_root(root
);
518 CERROR("%s: can't make root dentry\n",
519 ll_get_fsname(sb
, NULL
, 0));
524 sbi
->ll_sdev_orig
= sb
->s_dev
;
526 /* We set sb->s_dev equal on all lustre clients in order to support
527 * NFS export clustering. NFSD requires that the FSID be the same
530 /* s_dev is also used in lt_compare() to compare two fs, but that is
531 * only a node-local comparison.
533 uuid
= obd_get_uuid(sbi
->ll_md_exp
);
535 sb
->s_dev
= get_uuid2int(uuid
->uuid
, strlen(uuid
->uuid
));
536 get_uuid2fsid(uuid
->uuid
, strlen(uuid
->uuid
), &sbi
->ll_fsid
);
543 err
= ldebugfs_register_mountpoint(llite_root
, sb
, dt
, md
);
545 CERROR("%s: could not register mount in debugfs: "
546 "rc = %d\n", ll_get_fsname(sb
, NULL
, 0), err
);
555 obd_fid_fini(sbi
->ll_dt_exp
->exp_obd
);
557 obd_disconnect(sbi
->ll_dt_exp
);
558 sbi
->ll_dt_exp
= NULL
;
560 obd_fid_fini(sbi
->ll_md_exp
->exp_obd
);
562 obd_disconnect(sbi
->ll_md_exp
);
563 sbi
->ll_md_exp
= NULL
;
570 int ll_get_max_mdsize(struct ll_sb_info
*sbi
, int *lmmsize
)
574 size
= sizeof(*lmmsize
);
575 rc
= obd_get_info(NULL
, sbi
->ll_dt_exp
, sizeof(KEY_MAX_EASIZE
),
576 KEY_MAX_EASIZE
, &size
, lmmsize
);
578 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
579 sbi
->ll_dt_exp
->exp_obd
->obd_name
, rc
);
584 rc
= obd_get_info(NULL
, sbi
->ll_md_exp
, sizeof(KEY_MAX_EASIZE
),
585 KEY_MAX_EASIZE
, &size
, lmmsize
);
587 CERROR("Get max mdsize error rc %d\n", rc
);
593 * Get the value of the default_easize parameter.
595 * \see client_obd::cl_default_mds_easize
597 * \param[in] sbi superblock info for this filesystem
598 * \param[out] lmmsize pointer to storage location for value
600 * \retval 0 on success
601 * \retval negative negated errno on failure
603 int ll_get_default_mdsize(struct ll_sb_info
*sbi
, int *lmmsize
)
608 rc
= obd_get_info(NULL
, sbi
->ll_md_exp
, sizeof(KEY_DEFAULT_EASIZE
),
609 KEY_DEFAULT_EASIZE
, &size
, lmmsize
);
611 CERROR("Get default mdsize error rc %d\n", rc
);
617 * Set the default_easize parameter to the given value.
619 * \see client_obd::cl_default_mds_easize
621 * \param[in] sbi superblock info for this filesystem
622 * \param[in] lmmsize the size to set
624 * \retval 0 on success
625 * \retval negative negated errno on failure
627 int ll_set_default_mdsize(struct ll_sb_info
*sbi
, int lmmsize
)
629 if (lmmsize
< sizeof(struct lov_mds_md
) ||
630 lmmsize
> OBD_MAX_DEFAULT_EA_SIZE
)
633 return obd_set_info_async(NULL
, sbi
->ll_md_exp
,
634 sizeof(KEY_DEFAULT_EASIZE
),
636 sizeof(int), &lmmsize
, NULL
);
639 static void client_common_put_super(struct super_block
*sb
)
641 struct ll_sb_info
*sbi
= ll_s2sbi(sb
);
645 obd_fid_fini(sbi
->ll_dt_exp
->exp_obd
);
646 obd_disconnect(sbi
->ll_dt_exp
);
647 sbi
->ll_dt_exp
= NULL
;
649 ldebugfs_unregister_mountpoint(sbi
);
651 obd_fid_fini(sbi
->ll_md_exp
->exp_obd
);
652 obd_disconnect(sbi
->ll_md_exp
);
653 sbi
->ll_md_exp
= NULL
;
656 void ll_kill_super(struct super_block
*sb
)
658 struct ll_sb_info
*sbi
;
661 if (!(sb
->s_flags
& MS_ACTIVE
))
665 /* we need to restore s_dev from changed for clustered NFS before
666 * put_super because new kernels have cached s_dev and change sb->s_dev
667 * in put_super not affected real removing devices
670 sb
->s_dev
= sbi
->ll_sdev_orig
;
671 sbi
->ll_umounting
= 1;
673 /* wait running statahead threads to quit */
674 while (atomic_read(&sbi
->ll_sa_running
) > 0) {
675 set_current_state(TASK_UNINTERRUPTIBLE
);
676 schedule_timeout(msecs_to_jiffies(MSEC_PER_SEC
>> 3));
681 static inline int ll_set_opt(const char *opt
, char *data
, int fl
)
683 if (strncmp(opt
, data
, strlen(opt
)) != 0)
689 /* non-client-specific mount options are parsed in lmd_parse */
690 static int ll_options(char *options
, int *flags
)
693 char *s1
= options
, *s2
;
698 CDEBUG(D_CONFIG
, "Parsing opts %s\n", options
);
701 CDEBUG(D_SUPER
, "next opt=%s\n", s1
);
702 tmp
= ll_set_opt("nolock", s1
, LL_SBI_NOLCK
);
707 tmp
= ll_set_opt("flock", s1
, LL_SBI_FLOCK
);
712 tmp
= ll_set_opt("localflock", s1
, LL_SBI_LOCALFLOCK
);
717 tmp
= ll_set_opt("noflock", s1
,
718 LL_SBI_FLOCK
| LL_SBI_LOCALFLOCK
);
723 tmp
= ll_set_opt("user_xattr", s1
, LL_SBI_USER_XATTR
);
728 tmp
= ll_set_opt("nouser_xattr", s1
, LL_SBI_USER_XATTR
);
733 tmp
= ll_set_opt("context", s1
, 1);
736 tmp
= ll_set_opt("fscontext", s1
, 1);
739 tmp
= ll_set_opt("defcontext", s1
, 1);
742 tmp
= ll_set_opt("rootcontext", s1
, 1);
745 tmp
= ll_set_opt("user_fid2path", s1
, LL_SBI_USER_FID2PATH
);
750 tmp
= ll_set_opt("nouser_fid2path", s1
, LL_SBI_USER_FID2PATH
);
756 tmp
= ll_set_opt("checksum", s1
, LL_SBI_CHECKSUM
);
761 tmp
= ll_set_opt("nochecksum", s1
, LL_SBI_CHECKSUM
);
766 tmp
= ll_set_opt("lruresize", s1
, LL_SBI_LRU_RESIZE
);
771 tmp
= ll_set_opt("nolruresize", s1
, LL_SBI_LRU_RESIZE
);
776 tmp
= ll_set_opt("lazystatfs", s1
, LL_SBI_LAZYSTATFS
);
781 tmp
= ll_set_opt("nolazystatfs", s1
, LL_SBI_LAZYSTATFS
);
786 tmp
= ll_set_opt("32bitapi", s1
, LL_SBI_32BIT_API
);
791 tmp
= ll_set_opt("verbose", s1
, LL_SBI_VERBOSE
);
796 tmp
= ll_set_opt("noverbose", s1
, LL_SBI_VERBOSE
);
801 tmp
= ll_set_opt("always_ping", s1
, LL_SBI_ALWAYS_PING
);
806 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
812 s2
= strchr(s1
, ',');
820 void ll_lli_init(struct ll_inode_info
*lli
)
822 lli
->lli_inode_magic
= LLI_INODE_MAGIC
;
824 spin_lock_init(&lli
->lli_lock
);
825 lli
->lli_posix_acl
= NULL
;
826 /* Do not set lli_fid, it has been initialized already. */
827 fid_zero(&lli
->lli_pfid
);
828 lli
->lli_mds_read_och
= NULL
;
829 lli
->lli_mds_write_och
= NULL
;
830 lli
->lli_mds_exec_och
= NULL
;
831 lli
->lli_open_fd_read_count
= 0;
832 lli
->lli_open_fd_write_count
= 0;
833 lli
->lli_open_fd_exec_count
= 0;
834 mutex_init(&lli
->lli_och_mutex
);
835 spin_lock_init(&lli
->lli_agl_lock
);
836 spin_lock_init(&lli
->lli_layout_lock
);
837 ll_layout_version_set(lli
, CL_LAYOUT_GEN_NONE
);
838 lli
->lli_clob
= NULL
;
840 init_rwsem(&lli
->lli_xattrs_list_rwsem
);
841 mutex_init(&lli
->lli_xattrs_enq_lock
);
843 LASSERT(lli
->lli_vfs_inode
.i_mode
!= 0);
844 if (S_ISDIR(lli
->lli_vfs_inode
.i_mode
)) {
845 mutex_init(&lli
->lli_readdir_mutex
);
846 lli
->lli_opendir_key
= NULL
;
848 spin_lock_init(&lli
->lli_sa_lock
);
849 lli
->lli_opendir_pid
= 0;
850 lli
->lli_sa_enabled
= 0;
851 lli
->lli_def_stripe_offset
= -1;
853 mutex_init(&lli
->lli_size_mutex
);
854 lli
->lli_symlink_name
= NULL
;
855 init_rwsem(&lli
->lli_trunc_sem
);
856 range_lock_tree_init(&lli
->lli_write_tree
);
857 init_rwsem(&lli
->lli_glimpse_sem
);
858 lli
->lli_glimpse_time
= 0;
859 INIT_LIST_HEAD(&lli
->lli_agl_list
);
860 lli
->lli_agl_index
= 0;
861 lli
->lli_async_rc
= 0;
863 mutex_init(&lli
->lli_layout_mutex
);
866 int ll_fill_super(struct super_block
*sb
, struct vfsmount
*mnt
)
868 struct lustre_profile
*lprof
= NULL
;
869 struct lustre_sb_info
*lsi
= s2lsi(sb
);
870 struct ll_sb_info
*sbi
;
871 char *dt
= NULL
, *md
= NULL
;
872 char *profilenm
= get_profile_name(sb
);
873 struct config_llog_instance
*cfg
;
875 static atomic_t ll_bdi_num
= ATOMIC_INIT(0);
877 CDEBUG(D_VFSTRACE
, "VFS Op: sb %p\n", sb
);
879 cfg
= kzalloc(sizeof(*cfg
), GFP_NOFS
);
883 try_module_get(THIS_MODULE
);
885 /* client additional sb info */
886 sbi
= ll_init_sbi(sb
);
887 lsi
->lsi_llsbi
= sbi
;
889 module_put(THIS_MODULE
);
894 err
= ll_options(lsi
->lsi_lmd
->lmd_opts
, &sbi
->ll_flags
);
898 err
= super_setup_bdi_name(sb
, "lustre-%d",
899 atomic_inc_return(&ll_bdi_num
));
903 /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
904 sb
->s_d_op
= &ll_d_ops
;
906 /* Generate a string unique to this super, in case some joker tries
907 * to mount the same fs at two mount points.
908 * Use the address of the super itself.
910 cfg
->cfg_instance
= sb
;
911 cfg
->cfg_uuid
= lsi
->lsi_llsbi
->ll_sb_uuid
;
912 cfg
->cfg_callback
= class_config_llog_handler
;
913 /* set up client obds */
914 err
= lustre_process_log(sb
, profilenm
, cfg
);
918 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
919 lprof
= class_get_profile(profilenm
);
921 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be read from the MGS. Does that filesystem exist?\n",
926 CDEBUG(D_CONFIG
, "Found profile %s: mdc=%s osc=%s\n", profilenm
,
927 lprof
->lp_md
, lprof
->lp_dt
);
929 dt
= kasprintf(GFP_NOFS
, "%s-%p", lprof
->lp_dt
, cfg
->cfg_instance
);
935 md
= kasprintf(GFP_NOFS
, "%s-%p", lprof
->lp_md
, cfg
->cfg_instance
);
941 /* connections, registrations, sb setup */
942 err
= client_common_fill_super(sb
, md
, dt
, mnt
);
944 sbi
->ll_client_common_fill_super_succeeded
= 1;
950 class_put_profile(lprof
);
953 else if (sbi
->ll_flags
& LL_SBI_VERBOSE
)
954 LCONSOLE_WARN("Mounted %s\n", profilenm
);
958 } /* ll_fill_super */
960 void ll_put_super(struct super_block
*sb
)
962 struct config_llog_instance cfg
, params_cfg
;
963 struct obd_device
*obd
;
964 struct lustre_sb_info
*lsi
= s2lsi(sb
);
965 struct ll_sb_info
*sbi
= ll_s2sbi(sb
);
966 char *profilenm
= get_profile_name(sb
);
967 int next
, force
= 1, rc
= 0;
970 CDEBUG(D_VFSTRACE
, "VFS Op: sb %p - %s\n", sb
, profilenm
);
972 cfg
.cfg_instance
= sb
;
973 lustre_end_log(sb
, profilenm
, &cfg
);
975 params_cfg
.cfg_instance
= sb
;
976 lustre_end_log(sb
, PARAMS_FILENAME
, ¶ms_cfg
);
978 if (sbi
->ll_md_exp
) {
979 obd
= class_exp2obd(sbi
->ll_md_exp
);
981 force
= obd
->obd_force
;
984 /* Wait for unstable pages to be committed to stable storage */
986 struct l_wait_info lwi
= LWI_INTR(LWI_ON_SIGNAL_NOOP
, NULL
);
988 rc
= l_wait_event(sbi
->ll_cache
->ccc_unstable_waitq
,
989 !atomic_long_read(&sbi
->ll_cache
->ccc_unstable_nr
),
993 ccc_count
= atomic_long_read(&sbi
->ll_cache
->ccc_unstable_nr
);
994 if (!force
&& rc
!= -EINTR
)
995 LASSERTF(!ccc_count
, "count: %li\n", ccc_count
);
997 /* We need to set force before the lov_disconnect in
998 * lustre_common_put_super, since l_d cleans up osc's as well.
1002 while ((obd
= class_devices_in_group(&sbi
->ll_sb_uuid
,
1004 obd
->obd_force
= force
;
1008 if (sbi
->ll_client_common_fill_super_succeeded
) {
1009 /* Only if client_common_fill_super succeeded */
1010 client_common_put_super(sb
);
1014 while ((obd
= class_devices_in_group(&sbi
->ll_sb_uuid
, &next
)))
1015 class_manual_cleanup(obd
);
1017 if (sbi
->ll_flags
& LL_SBI_VERBOSE
)
1018 LCONSOLE_WARN("Unmounted %s\n", profilenm
? profilenm
: "");
1021 class_del_profile(profilenm
);
1024 lsi
->lsi_llsbi
= NULL
;
1026 lustre_common_put_super(sb
);
1028 cl_env_cache_purge(~0);
1030 module_put(THIS_MODULE
);
1031 } /* client_put_super */
1033 struct inode
*ll_inode_from_resource_lock(struct ldlm_lock
*lock
)
1035 struct inode
*inode
= NULL
;
1037 /* NOTE: we depend on atomic igrab() -bzzz */
1038 lock_res_and_lock(lock
);
1039 if (lock
->l_resource
->lr_lvb_inode
) {
1040 struct ll_inode_info
*lli
;
1042 lli
= ll_i2info(lock
->l_resource
->lr_lvb_inode
);
1043 if (lli
->lli_inode_magic
== LLI_INODE_MAGIC
) {
1044 inode
= igrab(lock
->l_resource
->lr_lvb_inode
);
1046 inode
= lock
->l_resource
->lr_lvb_inode
;
1047 LDLM_DEBUG_LIMIT(inode
->i_state
& I_FREEING
? D_INFO
:
1048 D_WARNING
, lock
, "lr_lvb_inode %p is bogus: magic %08x",
1049 lock
->l_resource
->lr_lvb_inode
,
1050 lli
->lli_inode_magic
);
1054 unlock_res_and_lock(lock
);
1058 void ll_dir_clear_lsm_md(struct inode
*inode
)
1060 struct ll_inode_info
*lli
= ll_i2info(inode
);
1062 LASSERT(S_ISDIR(inode
->i_mode
));
1064 if (lli
->lli_lsm_md
) {
1065 lmv_free_memmd(lli
->lli_lsm_md
);
1066 lli
->lli_lsm_md
= NULL
;
1070 static struct inode
*ll_iget_anon_dir(struct super_block
*sb
,
1071 const struct lu_fid
*fid
,
1072 struct lustre_md
*md
)
1074 struct ll_sb_info
*sbi
= ll_s2sbi(sb
);
1075 struct mdt_body
*body
= md
->body
;
1076 struct inode
*inode
;
1079 ino
= cl_fid_build_ino(fid
, sbi
->ll_flags
& LL_SBI_32BIT_API
);
1080 inode
= iget_locked(sb
, ino
);
1082 CERROR("%s: failed get simple inode "DFID
": rc = -ENOENT\n",
1083 ll_get_fsname(sb
, NULL
, 0), PFID(fid
));
1084 return ERR_PTR(-ENOENT
);
1087 if (inode
->i_state
& I_NEW
) {
1088 struct ll_inode_info
*lli
= ll_i2info(inode
);
1089 struct lmv_stripe_md
*lsm
= md
->lmv
;
1091 inode
->i_mode
= (inode
->i_mode
& ~S_IFMT
) |
1092 (body
->mbo_mode
& S_IFMT
);
1093 LASSERTF(S_ISDIR(inode
->i_mode
), "Not slave inode "DFID
"\n",
1096 LTIME_S(inode
->i_mtime
) = 0;
1097 LTIME_S(inode
->i_atime
) = 0;
1098 LTIME_S(inode
->i_ctime
) = 0;
1101 inode
->i_op
= &ll_dir_inode_operations
;
1102 inode
->i_fop
= &ll_dir_operations
;
1103 lli
->lli_fid
= *fid
;
1107 /* master object FID */
1108 lli
->lli_pfid
= body
->mbo_fid1
;
1109 CDEBUG(D_INODE
, "lli %p slave "DFID
" master "DFID
"\n",
1110 lli
, PFID(fid
), PFID(&lli
->lli_pfid
));
1111 unlock_new_inode(inode
);
1117 static int ll_init_lsm_md(struct inode
*inode
, struct lustre_md
*md
)
1119 struct lmv_stripe_md
*lsm
= md
->lmv
;
1125 * XXX sigh, this lsm_root initialization should be in
1126 * LMV layer, but it needs ll_iget right now, so we
1127 * put this here right now.
1129 for (i
= 0; i
< lsm
->lsm_md_stripe_count
; i
++) {
1130 fid
= &lsm
->lsm_md_oinfo
[i
].lmo_fid
;
1131 LASSERT(!lsm
->lsm_md_oinfo
[i
].lmo_root
);
1132 /* Unfortunately ll_iget will call ll_update_inode,
1133 * where the initialization of slave inode is slightly
1134 * different, so it reset lsm_md to NULL to avoid
1135 * initializing lsm for slave inode.
1137 /* For migrating inode, master stripe and master object will
1138 * be same, so we only need assign this inode
1140 if (lsm
->lsm_md_hash_type
& LMV_HASH_FLAG_MIGRATION
&& !i
)
1141 lsm
->lsm_md_oinfo
[i
].lmo_root
= inode
;
1143 lsm
->lsm_md_oinfo
[i
].lmo_root
=
1144 ll_iget_anon_dir(inode
->i_sb
, fid
, md
);
1145 if (IS_ERR(lsm
->lsm_md_oinfo
[i
].lmo_root
)) {
1146 int rc
= PTR_ERR(lsm
->lsm_md_oinfo
[i
].lmo_root
);
1148 lsm
->lsm_md_oinfo
[i
].lmo_root
= NULL
;
1156 static inline int lli_lsm_md_eq(const struct lmv_stripe_md
*lsm_md1
,
1157 const struct lmv_stripe_md
*lsm_md2
)
1159 return lsm_md1
->lsm_md_magic
== lsm_md2
->lsm_md_magic
&&
1160 lsm_md1
->lsm_md_stripe_count
== lsm_md2
->lsm_md_stripe_count
&&
1161 lsm_md1
->lsm_md_master_mdt_index
==
1162 lsm_md2
->lsm_md_master_mdt_index
&&
1163 lsm_md1
->lsm_md_hash_type
== lsm_md2
->lsm_md_hash_type
&&
1164 lsm_md1
->lsm_md_layout_version
==
1165 lsm_md2
->lsm_md_layout_version
&&
1166 !strcmp(lsm_md1
->lsm_md_pool_name
,
1167 lsm_md2
->lsm_md_pool_name
);
1170 static int ll_update_lsm_md(struct inode
*inode
, struct lustre_md
*md
)
1172 struct ll_inode_info
*lli
= ll_i2info(inode
);
1173 struct lmv_stripe_md
*lsm
= md
->lmv
;
1176 LASSERT(S_ISDIR(inode
->i_mode
));
1177 CDEBUG(D_INODE
, "update lsm %p of "DFID
"\n", lli
->lli_lsm_md
,
1178 PFID(ll_inode2fid(inode
)));
1180 /* no striped information from request. */
1182 if (!lli
->lli_lsm_md
) {
1184 } else if (lli
->lli_lsm_md
->lsm_md_hash_type
&
1185 LMV_HASH_FLAG_MIGRATION
) {
1187 * migration is done, the temporay MIGRATE layout has
1190 CDEBUG(D_INODE
, DFID
" finish migration.\n",
1191 PFID(ll_inode2fid(inode
)));
1192 lmv_free_memmd(lli
->lli_lsm_md
);
1193 lli
->lli_lsm_md
= NULL
;
1197 * The lustre_md from req does not include stripeEA,
1204 /* set the directory layout */
1205 if (!lli
->lli_lsm_md
) {
1206 struct cl_attr
*attr
;
1208 rc
= ll_init_lsm_md(inode
, md
);
1213 * set lsm_md to NULL, so the following free lustre_md
1214 * will not free this lsm
1217 lli
->lli_lsm_md
= lsm
;
1219 attr
= kzalloc(sizeof(*attr
), GFP_NOFS
);
1223 /* validate the lsm */
1224 rc
= md_merge_attr(ll_i2mdexp(inode
), lsm
, attr
,
1225 ll_md_blocking_ast
);
1231 if (md
->body
->mbo_valid
& OBD_MD_FLNLINK
)
1232 md
->body
->mbo_nlink
= attr
->cat_nlink
;
1233 if (md
->body
->mbo_valid
& OBD_MD_FLSIZE
)
1234 md
->body
->mbo_size
= attr
->cat_size
;
1235 if (md
->body
->mbo_valid
& OBD_MD_FLATIME
)
1236 md
->body
->mbo_atime
= attr
->cat_atime
;
1237 if (md
->body
->mbo_valid
& OBD_MD_FLCTIME
)
1238 md
->body
->mbo_ctime
= attr
->cat_ctime
;
1239 if (md
->body
->mbo_valid
& OBD_MD_FLMTIME
)
1240 md
->body
->mbo_mtime
= attr
->cat_mtime
;
1244 CDEBUG(D_INODE
, "Set lsm %p magic %x to "DFID
"\n", lsm
,
1245 lsm
->lsm_md_magic
, PFID(ll_inode2fid(inode
)));
1249 /* Compare the old and new stripe information */
1250 if (!lsm_md_eq(lli
->lli_lsm_md
, lsm
)) {
1251 struct lmv_stripe_md
*old_lsm
= lli
->lli_lsm_md
;
1254 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",
1255 ll_get_fsname(inode
->i_sb
, NULL
, 0), PFID(&lli
->lli_fid
),
1256 inode
, lsm
, old_lsm
,
1257 lsm
->lsm_md_magic
, old_lsm
->lsm_md_magic
,
1258 lsm
->lsm_md_stripe_count
,
1259 old_lsm
->lsm_md_stripe_count
,
1260 lsm
->lsm_md_master_mdt_index
,
1261 old_lsm
->lsm_md_master_mdt_index
,
1262 lsm
->lsm_md_hash_type
, old_lsm
->lsm_md_hash_type
,
1263 lsm
->lsm_md_layout_version
,
1264 old_lsm
->lsm_md_layout_version
,
1265 lsm
->lsm_md_pool_name
,
1266 old_lsm
->lsm_md_pool_name
);
1268 for (idx
= 0; idx
< old_lsm
->lsm_md_stripe_count
; idx
++) {
1269 CERROR("%s: sub FIDs in old lsm idx %d, old: "DFID
"\n",
1270 ll_get_fsname(inode
->i_sb
, NULL
, 0), idx
,
1271 PFID(&old_lsm
->lsm_md_oinfo
[idx
].lmo_fid
));
1274 for (idx
= 0; idx
< lsm
->lsm_md_stripe_count
; idx
++) {
1275 CERROR("%s: sub FIDs in new lsm idx %d, new: "DFID
"\n",
1276 ll_get_fsname(inode
->i_sb
, NULL
, 0), idx
,
1277 PFID(&lsm
->lsm_md_oinfo
[idx
].lmo_fid
));
1286 void ll_clear_inode(struct inode
*inode
)
1288 struct ll_inode_info
*lli
= ll_i2info(inode
);
1289 struct ll_sb_info
*sbi
= ll_i2sbi(inode
);
1291 CDEBUG(D_VFSTRACE
, "VFS Op:inode="DFID
"(%p)\n",
1292 PFID(ll_inode2fid(inode
)), inode
);
1294 if (S_ISDIR(inode
->i_mode
)) {
1295 /* these should have been cleared in ll_file_release */
1296 LASSERT(!lli
->lli_opendir_key
);
1297 LASSERT(!lli
->lli_sai
);
1298 LASSERT(lli
->lli_opendir_pid
== 0);
1301 md_null_inode(sbi
->ll_md_exp
, ll_inode2fid(inode
));
1303 LASSERT(!lli
->lli_open_fd_write_count
);
1304 LASSERT(!lli
->lli_open_fd_read_count
);
1305 LASSERT(!lli
->lli_open_fd_exec_count
);
1307 if (lli
->lli_mds_write_och
)
1308 ll_md_real_close(inode
, FMODE_WRITE
);
1309 if (lli
->lli_mds_exec_och
)
1310 ll_md_real_close(inode
, FMODE_EXEC
);
1311 if (lli
->lli_mds_read_och
)
1312 ll_md_real_close(inode
, FMODE_READ
);
1314 if (S_ISLNK(inode
->i_mode
)) {
1315 kfree(lli
->lli_symlink_name
);
1316 lli
->lli_symlink_name
= NULL
;
1319 ll_xattr_cache_destroy(inode
);
1321 #ifdef CONFIG_FS_POSIX_ACL
1322 if (lli
->lli_posix_acl
) {
1323 posix_acl_release(lli
->lli_posix_acl
);
1324 lli
->lli_posix_acl
= NULL
;
1327 lli
->lli_inode_magic
= LLI_INODE_DEAD
;
1329 if (S_ISDIR(inode
->i_mode
))
1330 ll_dir_clear_lsm_md(inode
);
1331 if (S_ISREG(inode
->i_mode
) && !is_bad_inode(inode
))
1332 LASSERT(list_empty(&lli
->lli_agl_list
));
1335 * XXX This has to be done before lsm is freed below, because
1336 * cl_object still uses inode lsm.
1338 cl_inode_fini(inode
);
1341 #define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
1343 static int ll_md_setattr(struct dentry
*dentry
, struct md_op_data
*op_data
)
1345 struct lustre_md md
;
1346 struct inode
*inode
= d_inode(dentry
);
1347 struct ll_sb_info
*sbi
= ll_i2sbi(inode
);
1348 struct ptlrpc_request
*request
= NULL
;
1351 op_data
= ll_prep_md_op_data(op_data
, inode
, NULL
, NULL
, 0, 0,
1352 LUSTRE_OPC_ANY
, NULL
);
1353 if (IS_ERR(op_data
))
1354 return PTR_ERR(op_data
);
1356 rc
= md_setattr(sbi
->ll_md_exp
, op_data
, NULL
, 0, &request
);
1358 ptlrpc_req_finished(request
);
1359 if (rc
== -ENOENT
) {
1361 /* Unlinked special device node? Or just a race?
1362 * Pretend we did everything.
1364 if (!S_ISREG(inode
->i_mode
) &&
1365 !S_ISDIR(inode
->i_mode
)) {
1366 ia_valid
= op_data
->op_attr
.ia_valid
;
1367 op_data
->op_attr
.ia_valid
&= ~TIMES_SET_FLAGS
;
1368 rc
= simple_setattr(dentry
, &op_data
->op_attr
);
1369 op_data
->op_attr
.ia_valid
= ia_valid
;
1371 } else if (rc
!= -EPERM
&& rc
!= -EACCES
&& rc
!= -ETXTBSY
) {
1372 CERROR("md_setattr fails: rc = %d\n", rc
);
1377 rc
= md_get_lustre_md(sbi
->ll_md_exp
, request
, sbi
->ll_dt_exp
,
1378 sbi
->ll_md_exp
, &md
);
1380 ptlrpc_req_finished(request
);
1384 ia_valid
= op_data
->op_attr
.ia_valid
;
1385 /* inode size will be in cl_setattr_ost, can't do it now since dirty
1386 * cache is not cleared yet.
1388 op_data
->op_attr
.ia_valid
&= ~(TIMES_SET_FLAGS
| ATTR_SIZE
);
1389 if (S_ISREG(inode
->i_mode
))
1391 rc
= simple_setattr(dentry
, &op_data
->op_attr
);
1392 if (S_ISREG(inode
->i_mode
))
1393 inode_unlock(inode
);
1394 op_data
->op_attr
.ia_valid
= ia_valid
;
1396 rc
= ll_update_inode(inode
, &md
);
1397 ptlrpc_req_finished(request
);
1402 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1403 * object(s) determine the file size and mtime. Otherwise, the MDS will
1404 * keep these values until such a time that objects are allocated for it.
1405 * We do the MDS operations first, as it is checking permissions for us.
1406 * We don't to the MDS RPC if there is nothing that we want to store there,
1407 * otherwise there is no harm in updating mtime/atime on the MDS if we are
1408 * going to do an RPC anyways.
1410 * If we are doing a truncate, we will send the mtime and ctime updates
1411 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1412 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1415 * In case of HSMimport, we only set attr on MDS.
1417 int ll_setattr_raw(struct dentry
*dentry
, struct iattr
*attr
, bool hsm_import
)
1419 struct inode
*inode
= d_inode(dentry
);
1420 struct ll_inode_info
*lli
= ll_i2info(inode
);
1421 struct md_op_data
*op_data
= NULL
;
1424 CDEBUG(D_VFSTRACE
, "%s: setattr inode "DFID
"(%p) from %llu to %llu, valid %x, hsm_import %d\n",
1425 ll_get_fsname(inode
->i_sb
, NULL
, 0), PFID(&lli
->lli_fid
), inode
,
1426 i_size_read(inode
), attr
->ia_size
, attr
->ia_valid
, hsm_import
);
1428 if (attr
->ia_valid
& ATTR_SIZE
) {
1429 /* Check new size against VFS/VM file size limit and rlimit */
1430 rc
= inode_newsize_ok(inode
, attr
->ia_size
);
1434 /* The maximum Lustre file size is variable, based on the
1435 * OST maximum object size and number of stripes. This
1436 * needs another check in addition to the VFS check above.
1438 if (attr
->ia_size
> ll_file_maxbytes(inode
)) {
1439 CDEBUG(D_INODE
, "file "DFID
" too large %llu > %llu\n",
1440 PFID(&lli
->lli_fid
), attr
->ia_size
,
1441 ll_file_maxbytes(inode
));
1445 attr
->ia_valid
|= ATTR_MTIME
| ATTR_CTIME
;
1448 /* POSIX: check before ATTR_*TIME_SET set (from setattr_prepare) */
1449 if (attr
->ia_valid
& TIMES_SET_FLAGS
) {
1450 if ((!uid_eq(current_fsuid(), inode
->i_uid
)) &&
1451 !capable(CFS_CAP_FOWNER
))
1455 /* We mark all of the fields "set" so MDS/OST does not re-set them */
1456 if (attr
->ia_valid
& ATTR_CTIME
) {
1457 attr
->ia_ctime
= current_time(inode
);
1458 attr
->ia_valid
|= ATTR_CTIME_SET
;
1460 if (!(attr
->ia_valid
& ATTR_ATIME_SET
) &&
1461 (attr
->ia_valid
& ATTR_ATIME
)) {
1462 attr
->ia_atime
= current_time(inode
);
1463 attr
->ia_valid
|= ATTR_ATIME_SET
;
1465 if (!(attr
->ia_valid
& ATTR_MTIME_SET
) &&
1466 (attr
->ia_valid
& ATTR_MTIME
)) {
1467 attr
->ia_mtime
= current_time(inode
);
1468 attr
->ia_valid
|= ATTR_MTIME_SET
;
1471 if (attr
->ia_valid
& (ATTR_MTIME
| ATTR_CTIME
))
1472 CDEBUG(D_INODE
, "setting mtime %lu, ctime %lu, now = %llu\n",
1473 LTIME_S(attr
->ia_mtime
), LTIME_S(attr
->ia_ctime
),
1474 (s64
)ktime_get_real_seconds());
1476 if (S_ISREG(inode
->i_mode
))
1477 inode_unlock(inode
);
1480 * We always do an MDS RPC, even if we're only changing the size;
1481 * only the MDS knows whether truncate() should fail with -ETXTBUSY
1483 op_data
= kzalloc(sizeof(*op_data
), GFP_NOFS
);
1489 if (!hsm_import
&& attr
->ia_valid
& ATTR_SIZE
) {
1491 * If we are changing file size, file content is
1492 * modified, flag it.
1494 attr
->ia_valid
|= MDS_OPEN_OWNEROVERRIDE
;
1495 op_data
->op_bias
|= MDS_DATA_MODIFIED
;
1496 clear_bit(LLIF_DATA_MODIFIED
, &lli
->lli_flags
);
1499 op_data
->op_attr
= *attr
;
1501 rc
= ll_md_setattr(dentry
, op_data
);
1505 if (!S_ISREG(inode
->i_mode
) || hsm_import
) {
1510 if (attr
->ia_valid
& (ATTR_SIZE
|
1511 ATTR_ATIME
| ATTR_ATIME_SET
|
1512 ATTR_MTIME
| ATTR_MTIME_SET
)) {
1513 /* For truncate and utimes sending attributes to OSTs, setting
1514 * mtime/atime to the past will be performed under PW [0:EOF]
1515 * extent lock (new_size:EOF for truncate). It may seem
1516 * excessive to send mtime/atime updates to OSTs when not
1517 * setting times to past, but it is necessary due to possible
1518 * time de-synchronization between MDT inode and OST objects
1520 rc
= cl_setattr_ost(ll_i2info(inode
)->lli_clob
, attr
, 0);
1524 * If the file was restored, it needs to set dirty flag.
1526 * We've already sent MDS_DATA_MODIFIED flag in
1527 * ll_md_setattr() for truncate. However, the MDT refuses to
1528 * set the HS_DIRTY flag on released files, so we have to set
1529 * it again if the file has been restored. Please check how
1530 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
1532 * Please notice that if the file is not released, the previous
1533 * MDS_DATA_MODIFIED has taken effect and usually
1534 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
1535 * This way we can save an RPC for common open + trunc
1538 if (test_and_clear_bit(LLIF_DATA_MODIFIED
, &lli
->lli_flags
)) {
1539 struct hsm_state_set hss
= {
1540 .hss_valid
= HSS_SETMASK
,
1541 .hss_setmask
= HS_DIRTY
,
1545 rc2
= ll_hsm_state_set(inode
, &hss
);
1547 * truncate and write can happen at the same time, so that
1548 * the file can be set modified even though the file is not
1549 * restored from released state, and ll_hsm_state_set() is
1550 * not applicable for the file, and rc2 < 0 is normal in this
1554 CDEBUG(D_INFO
, DFID
"HSM set dirty failed: rc2 = %d\n",
1555 PFID(ll_inode2fid(inode
)), rc2
);
1560 ll_finish_md_op_data(op_data
);
1562 if (S_ISREG(inode
->i_mode
)) {
1564 if ((attr
->ia_valid
& ATTR_SIZE
) && !hsm_import
)
1565 inode_dio_wait(inode
);
1568 ll_stats_ops_tally(ll_i2sbi(inode
), (attr
->ia_valid
& ATTR_SIZE
) ?
1569 LPROC_LL_TRUNC
: LPROC_LL_SETATTR
, 1);
1574 int ll_setattr(struct dentry
*de
, struct iattr
*attr
)
1576 int mode
= d_inode(de
)->i_mode
;
1578 if ((attr
->ia_valid
& (ATTR_CTIME
| ATTR_SIZE
| ATTR_MODE
)) ==
1579 (ATTR_CTIME
| ATTR_SIZE
| ATTR_MODE
))
1580 attr
->ia_valid
|= MDS_OPEN_OWNEROVERRIDE
;
1582 if (((attr
->ia_valid
& (ATTR_MODE
| ATTR_FORCE
| ATTR_SIZE
)) ==
1583 (ATTR_SIZE
| ATTR_MODE
)) &&
1584 (((mode
& S_ISUID
) && !(attr
->ia_mode
& S_ISUID
)) ||
1585 (((mode
& (S_ISGID
| 0010)) == (S_ISGID
| 0010)) &&
1586 !(attr
->ia_mode
& S_ISGID
))))
1587 attr
->ia_valid
|= ATTR_FORCE
;
1589 if ((attr
->ia_valid
& ATTR_MODE
) &&
1591 !(attr
->ia_mode
& S_ISUID
) &&
1592 !(attr
->ia_valid
& ATTR_KILL_SUID
))
1593 attr
->ia_valid
|= ATTR_KILL_SUID
;
1595 if ((attr
->ia_valid
& ATTR_MODE
) &&
1596 ((mode
& (S_ISGID
| 0010)) == (S_ISGID
| 0010)) &&
1597 !(attr
->ia_mode
& S_ISGID
) &&
1598 !(attr
->ia_valid
& ATTR_KILL_SGID
))
1599 attr
->ia_valid
|= ATTR_KILL_SGID
;
1601 return ll_setattr_raw(de
, attr
, false);
1604 int ll_statfs_internal(struct super_block
*sb
, struct obd_statfs
*osfs
,
1605 __u64 max_age
, __u32 flags
)
1607 struct ll_sb_info
*sbi
= ll_s2sbi(sb
);
1608 struct obd_statfs obd_osfs
;
1611 rc
= obd_statfs(NULL
, sbi
->ll_md_exp
, osfs
, max_age
, flags
);
1613 CERROR("md_statfs fails: rc = %d\n", rc
);
1617 osfs
->os_type
= sb
->s_magic
;
1619 CDEBUG(D_SUPER
, "MDC blocks %llu/%llu objects %llu/%llu\n",
1620 osfs
->os_bavail
, osfs
->os_blocks
, osfs
->os_ffree
,
1623 if (sbi
->ll_flags
& LL_SBI_LAZYSTATFS
)
1624 flags
|= OBD_STATFS_NODELAY
;
1626 rc
= obd_statfs_rqset(sbi
->ll_dt_exp
, &obd_osfs
, max_age
, flags
);
1628 CERROR("obd_statfs fails: rc = %d\n", rc
);
1632 CDEBUG(D_SUPER
, "OSC blocks %llu/%llu objects %llu/%llu\n",
1633 obd_osfs
.os_bavail
, obd_osfs
.os_blocks
, obd_osfs
.os_ffree
,
1636 osfs
->os_bsize
= obd_osfs
.os_bsize
;
1637 osfs
->os_blocks
= obd_osfs
.os_blocks
;
1638 osfs
->os_bfree
= obd_osfs
.os_bfree
;
1639 osfs
->os_bavail
= obd_osfs
.os_bavail
;
1641 /* If we don't have as many objects free on the OST as inodes
1642 * on the MDS, we reduce the total number of inodes to
1643 * compensate, so that the "inodes in use" number is correct.
1645 if (obd_osfs
.os_ffree
< osfs
->os_ffree
) {
1646 osfs
->os_files
= (osfs
->os_files
- osfs
->os_ffree
) +
1648 osfs
->os_ffree
= obd_osfs
.os_ffree
;
1654 int ll_statfs(struct dentry
*de
, struct kstatfs
*sfs
)
1656 struct super_block
*sb
= de
->d_sb
;
1657 struct obd_statfs osfs
;
1660 CDEBUG(D_VFSTRACE
, "VFS Op: at %llu jiffies\n", get_jiffies_64());
1661 ll_stats_ops_tally(ll_s2sbi(sb
), LPROC_LL_STAFS
, 1);
1663 /* Some amount of caching on the client is allowed */
1664 rc
= ll_statfs_internal(sb
, &osfs
,
1665 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS
),
1670 statfs_unpack(sfs
, &osfs
);
1672 /* We need to downshift for all 32-bit kernels, because we can't
1673 * tell if the kernel is being called via sys_statfs64() or not.
1674 * Stop before overflowing f_bsize - in which case it is better
1675 * to just risk EOVERFLOW if caller is using old sys_statfs().
1677 if (sizeof(long) < 8) {
1678 while (osfs
.os_blocks
> ~0UL && sfs
->f_bsize
< 0x40000000) {
1681 osfs
.os_blocks
>>= 1;
1682 osfs
.os_bfree
>>= 1;
1683 osfs
.os_bavail
>>= 1;
1687 sfs
->f_blocks
= osfs
.os_blocks
;
1688 sfs
->f_bfree
= osfs
.os_bfree
;
1689 sfs
->f_bavail
= osfs
.os_bavail
;
1690 sfs
->f_fsid
= ll_s2sbi(sb
)->ll_fsid
;
1694 void ll_inode_size_lock(struct inode
*inode
)
1696 struct ll_inode_info
*lli
;
1698 LASSERT(!S_ISDIR(inode
->i_mode
));
1700 lli
= ll_i2info(inode
);
1701 mutex_lock(&lli
->lli_size_mutex
);
1704 void ll_inode_size_unlock(struct inode
*inode
)
1706 struct ll_inode_info
*lli
;
1708 lli
= ll_i2info(inode
);
1709 mutex_unlock(&lli
->lli_size_mutex
);
1712 int ll_update_inode(struct inode
*inode
, struct lustre_md
*md
)
1714 struct ll_inode_info
*lli
= ll_i2info(inode
);
1715 struct mdt_body
*body
= md
->body
;
1716 struct ll_sb_info
*sbi
= ll_i2sbi(inode
);
1718 if (body
->mbo_valid
& OBD_MD_FLEASIZE
)
1719 cl_file_inode_init(inode
, md
);
1721 if (S_ISDIR(inode
->i_mode
)) {
1724 rc
= ll_update_lsm_md(inode
, md
);
1729 #ifdef CONFIG_FS_POSIX_ACL
1730 if (body
->mbo_valid
& OBD_MD_FLACL
) {
1731 spin_lock(&lli
->lli_lock
);
1732 if (lli
->lli_posix_acl
)
1733 posix_acl_release(lli
->lli_posix_acl
);
1734 lli
->lli_posix_acl
= md
->posix_acl
;
1735 spin_unlock(&lli
->lli_lock
);
1738 inode
->i_ino
= cl_fid_build_ino(&body
->mbo_fid1
,
1739 sbi
->ll_flags
& LL_SBI_32BIT_API
);
1740 inode
->i_generation
= cl_fid_build_gen(&body
->mbo_fid1
);
1742 if (body
->mbo_valid
& OBD_MD_FLATIME
) {
1743 if (body
->mbo_atime
> LTIME_S(inode
->i_atime
))
1744 LTIME_S(inode
->i_atime
) = body
->mbo_atime
;
1745 lli
->lli_atime
= body
->mbo_atime
;
1747 if (body
->mbo_valid
& OBD_MD_FLMTIME
) {
1748 if (body
->mbo_mtime
> LTIME_S(inode
->i_mtime
)) {
1749 CDEBUG(D_INODE
, "setting ino %lu mtime from %lu to %llu\n",
1750 inode
->i_ino
, LTIME_S(inode
->i_mtime
),
1752 LTIME_S(inode
->i_mtime
) = body
->mbo_mtime
;
1754 lli
->lli_mtime
= body
->mbo_mtime
;
1756 if (body
->mbo_valid
& OBD_MD_FLCTIME
) {
1757 if (body
->mbo_ctime
> LTIME_S(inode
->i_ctime
))
1758 LTIME_S(inode
->i_ctime
) = body
->mbo_ctime
;
1759 lli
->lli_ctime
= body
->mbo_ctime
;
1761 if (body
->mbo_valid
& OBD_MD_FLMODE
)
1762 inode
->i_mode
= (inode
->i_mode
& S_IFMT
) |
1763 (body
->mbo_mode
& ~S_IFMT
);
1764 if (body
->mbo_valid
& OBD_MD_FLTYPE
)
1765 inode
->i_mode
= (inode
->i_mode
& ~S_IFMT
) |
1766 (body
->mbo_mode
& S_IFMT
);
1767 LASSERT(inode
->i_mode
!= 0);
1768 if (S_ISREG(inode
->i_mode
))
1769 inode
->i_blkbits
= min(PTLRPC_MAX_BRW_BITS
+ 1,
1770 LL_MAX_BLKSIZE_BITS
);
1772 inode
->i_blkbits
= inode
->i_sb
->s_blocksize_bits
;
1773 if (body
->mbo_valid
& OBD_MD_FLUID
)
1774 inode
->i_uid
= make_kuid(&init_user_ns
, body
->mbo_uid
);
1775 if (body
->mbo_valid
& OBD_MD_FLGID
)
1776 inode
->i_gid
= make_kgid(&init_user_ns
, body
->mbo_gid
);
1777 if (body
->mbo_valid
& OBD_MD_FLFLAGS
)
1778 inode
->i_flags
= ll_ext_to_inode_flags(body
->mbo_flags
);
1779 if (body
->mbo_valid
& OBD_MD_FLNLINK
)
1780 set_nlink(inode
, body
->mbo_nlink
);
1781 if (body
->mbo_valid
& OBD_MD_FLRDEV
)
1782 inode
->i_rdev
= old_decode_dev(body
->mbo_rdev
);
1784 if (body
->mbo_valid
& OBD_MD_FLID
) {
1785 /* FID shouldn't be changed! */
1786 if (fid_is_sane(&lli
->lli_fid
)) {
1787 LASSERTF(lu_fid_eq(&lli
->lli_fid
, &body
->mbo_fid1
),
1788 "Trying to change FID "DFID
" to the "DFID
", inode "DFID
"(%p)\n",
1789 PFID(&lli
->lli_fid
), PFID(&body
->mbo_fid1
),
1790 PFID(ll_inode2fid(inode
)), inode
);
1792 lli
->lli_fid
= body
->mbo_fid1
;
1796 LASSERT(fid_seq(&lli
->lli_fid
) != 0);
1798 if (body
->mbo_valid
& OBD_MD_FLSIZE
) {
1799 i_size_write(inode
, body
->mbo_size
);
1801 CDEBUG(D_VFSTRACE
, "inode=" DFID
", updating i_size %llu\n",
1802 PFID(ll_inode2fid(inode
)),
1803 (unsigned long long)body
->mbo_size
);
1805 if (body
->mbo_valid
& OBD_MD_FLBLOCKS
)
1806 inode
->i_blocks
= body
->mbo_blocks
;
1809 if (body
->mbo_valid
& OBD_MD_TSTATE
) {
1810 if (body
->mbo_t_state
& MS_RESTORE
)
1811 set_bit(LLIF_FILE_RESTORING
, &lli
->lli_flags
);
1817 int ll_read_inode2(struct inode
*inode
, void *opaque
)
1819 struct lustre_md
*md
= opaque
;
1820 struct ll_inode_info
*lli
= ll_i2info(inode
);
1823 CDEBUG(D_VFSTRACE
, "VFS Op:inode="DFID
"(%p)\n",
1824 PFID(&lli
->lli_fid
), inode
);
1826 /* Core attributes from the MDS first. This is a new inode, and
1827 * the VFS doesn't zero times in the core inode so we have to do
1828 * it ourselves. They will be overwritten by either MDS or OST
1829 * attributes - we just need to make sure they aren't newer.
1831 LTIME_S(inode
->i_mtime
) = 0;
1832 LTIME_S(inode
->i_atime
) = 0;
1833 LTIME_S(inode
->i_ctime
) = 0;
1835 rc
= ll_update_inode(inode
, md
);
1839 /* OIDEBUG(inode); */
1841 if (S_ISREG(inode
->i_mode
)) {
1842 struct ll_sb_info
*sbi
= ll_i2sbi(inode
);
1844 inode
->i_op
= &ll_file_inode_operations
;
1845 inode
->i_fop
= sbi
->ll_fop
;
1846 inode
->i_mapping
->a_ops
= (struct address_space_operations
*)&ll_aops
;
1847 } else if (S_ISDIR(inode
->i_mode
)) {
1848 inode
->i_op
= &ll_dir_inode_operations
;
1849 inode
->i_fop
= &ll_dir_operations
;
1850 } else if (S_ISLNK(inode
->i_mode
)) {
1851 inode
->i_op
= &ll_fast_symlink_inode_operations
;
1853 inode
->i_op
= &ll_special_inode_operations
;
1855 init_special_inode(inode
, inode
->i_mode
,
1862 void ll_delete_inode(struct inode
*inode
)
1864 struct ll_inode_info
*lli
= ll_i2info(inode
);
1866 if (S_ISREG(inode
->i_mode
) && lli
->lli_clob
)
1867 /* discard all dirty pages before truncating them, required by
1868 * osc_extent implementation at LU-1030.
1870 cl_sync_file_range(inode
, 0, OBD_OBJECT_EOF
,
1873 truncate_inode_pages_final(&inode
->i_data
);
1875 LASSERTF(!inode
->i_data
.nrpages
,
1876 "inode=" DFID
"(%p) nrpages=%lu, see http://jira.whamcloud.com/browse/LU-118\n",
1877 PFID(ll_inode2fid(inode
)), inode
, inode
->i_data
.nrpages
);
1879 ll_clear_inode(inode
);
1883 int ll_iocontrol(struct inode
*inode
, struct file
*file
,
1884 unsigned int cmd
, unsigned long arg
)
1886 struct ll_sb_info
*sbi
= ll_i2sbi(inode
);
1887 struct ptlrpc_request
*req
= NULL
;
1891 case FSFILT_IOC_GETFLAGS
: {
1892 struct mdt_body
*body
;
1893 struct md_op_data
*op_data
;
1895 op_data
= ll_prep_md_op_data(NULL
, inode
, NULL
, NULL
,
1896 0, 0, LUSTRE_OPC_ANY
,
1898 if (IS_ERR(op_data
))
1899 return PTR_ERR(op_data
);
1901 op_data
->op_valid
= OBD_MD_FLFLAGS
;
1902 rc
= md_getattr(sbi
->ll_md_exp
, op_data
, &req
);
1903 ll_finish_md_op_data(op_data
);
1905 CERROR("%s: failure inode "DFID
": rc = %d\n",
1906 sbi
->ll_md_exp
->exp_obd
->obd_name
,
1907 PFID(ll_inode2fid(inode
)), rc
);
1911 body
= req_capsule_server_get(&req
->rq_pill
, &RMF_MDT_BODY
);
1913 flags
= body
->mbo_flags
;
1915 ptlrpc_req_finished(req
);
1917 return put_user(flags
, (int __user
*)arg
);
1919 case FSFILT_IOC_SETFLAGS
: {
1920 struct md_op_data
*op_data
;
1921 struct cl_object
*obj
;
1924 if (get_user(flags
, (int __user
*)arg
))
1927 op_data
= ll_prep_md_op_data(NULL
, inode
, NULL
, NULL
, 0, 0,
1928 LUSTRE_OPC_ANY
, NULL
);
1929 if (IS_ERR(op_data
))
1930 return PTR_ERR(op_data
);
1932 op_data
->op_attr_flags
= flags
;
1933 op_data
->op_attr
.ia_valid
|= ATTR_ATTR_FLAG
;
1934 rc
= md_setattr(sbi
->ll_md_exp
, op_data
, NULL
, 0, &req
);
1935 ll_finish_md_op_data(op_data
);
1936 ptlrpc_req_finished(req
);
1940 inode
->i_flags
= ll_ext_to_inode_flags(flags
);
1942 obj
= ll_i2info(inode
)->lli_clob
;
1946 attr
= kzalloc(sizeof(*attr
), GFP_NOFS
);
1950 attr
->ia_valid
= ATTR_ATTR_FLAG
;
1951 rc
= cl_setattr_ost(obj
, attr
, flags
);
1962 int ll_flush_ctx(struct inode
*inode
)
1964 struct ll_sb_info
*sbi
= ll_i2sbi(inode
);
1966 CDEBUG(D_SEC
, "flush context for user %d\n",
1967 from_kuid(&init_user_ns
, current_uid()));
1969 obd_set_info_async(NULL
, sbi
->ll_md_exp
,
1970 sizeof(KEY_FLUSH_CTX
), KEY_FLUSH_CTX
,
1972 obd_set_info_async(NULL
, sbi
->ll_dt_exp
,
1973 sizeof(KEY_FLUSH_CTX
), KEY_FLUSH_CTX
,
1978 /* umount -f client means force down, don't save state */
1979 void ll_umount_begin(struct super_block
*sb
)
1981 struct ll_sb_info
*sbi
= ll_s2sbi(sb
);
1982 struct obd_device
*obd
;
1983 struct obd_ioctl_data
*ioc_data
;
1984 wait_queue_head_t waitq
;
1985 struct l_wait_info lwi
;
1987 CDEBUG(D_VFSTRACE
, "VFS Op: superblock %p count %d active %d\n", sb
,
1988 sb
->s_count
, atomic_read(&sb
->s_active
));
1990 obd
= class_exp2obd(sbi
->ll_md_exp
);
1992 CERROR("Invalid MDC connection handle %#llx\n",
1993 sbi
->ll_md_exp
->exp_handle
.h_cookie
);
1998 obd
= class_exp2obd(sbi
->ll_dt_exp
);
2000 CERROR("Invalid LOV connection handle %#llx\n",
2001 sbi
->ll_dt_exp
->exp_handle
.h_cookie
);
2006 ioc_data
= kzalloc(sizeof(*ioc_data
), GFP_NOFS
);
2008 obd_iocontrol(IOC_OSC_SET_ACTIVE
, sbi
->ll_md_exp
,
2009 sizeof(*ioc_data
), ioc_data
, NULL
);
2011 obd_iocontrol(IOC_OSC_SET_ACTIVE
, sbi
->ll_dt_exp
,
2012 sizeof(*ioc_data
), ioc_data
, NULL
);
2017 /* Really, we'd like to wait until there are no requests outstanding,
2018 * and then continue. For now, we just periodically checking for vfs
2019 * to decrement mnt_cnt and hope to finish it within 10sec.
2021 init_waitqueue_head(&waitq
);
2022 lwi
= LWI_TIMEOUT_INTERVAL(cfs_time_seconds(10),
2023 cfs_time_seconds(1), NULL
, NULL
);
2024 l_wait_event(waitq
, may_umount(sbi
->ll_mnt
.mnt
), &lwi
);
2029 int ll_remount_fs(struct super_block
*sb
, int *flags
, char *data
)
2031 struct ll_sb_info
*sbi
= ll_s2sbi(sb
);
2032 char *profilenm
= get_profile_name(sb
);
2036 if ((*flags
& MS_RDONLY
) != (sb
->s_flags
& MS_RDONLY
)) {
2037 read_only
= *flags
& MS_RDONLY
;
2038 err
= obd_set_info_async(NULL
, sbi
->ll_md_exp
,
2039 sizeof(KEY_READ_ONLY
),
2040 KEY_READ_ONLY
, sizeof(read_only
),
2043 LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2044 profilenm
, read_only
?
2045 "read-only" : "read-write", err
);
2050 sb
->s_flags
|= MS_RDONLY
;
2052 sb
->s_flags
&= ~MS_RDONLY
;
2054 if (sbi
->ll_flags
& LL_SBI_VERBOSE
)
2055 LCONSOLE_WARN("Remounted %s %s\n", profilenm
,
2056 read_only
? "read-only" : "read-write");
2062 * Cleanup the open handle that is cached on MDT-side.
2064 * For open case, the client side open handling thread may hit error
2065 * after the MDT grant the open. Under such case, the client should
2066 * send close RPC to the MDT as cleanup; otherwise, the open handle
2067 * on the MDT will be leaked there until the client umount or evicted.
2069 * In further, if someone unlinked the file, because the open handle
2070 * holds the reference on such file/object, then it will block the
2071 * subsequent threads that want to locate such object via FID.
2073 * \param[in] sb super block for this file-system
2074 * \param[in] open_req pointer to the original open request
2076 void ll_open_cleanup(struct super_block
*sb
, struct ptlrpc_request
*open_req
)
2078 struct mdt_body
*body
;
2079 struct md_op_data
*op_data
;
2080 struct ptlrpc_request
*close_req
= NULL
;
2081 struct obd_export
*exp
= ll_s2sbi(sb
)->ll_md_exp
;
2083 body
= req_capsule_server_get(&open_req
->rq_pill
, &RMF_MDT_BODY
);
2084 op_data
= kzalloc(sizeof(*op_data
), GFP_NOFS
);
2088 op_data
->op_fid1
= body
->mbo_fid1
;
2089 op_data
->op_handle
= body
->mbo_handle
;
2090 op_data
->op_mod_time
= get_seconds();
2091 md_close(exp
, op_data
, NULL
, &close_req
);
2092 ptlrpc_req_finished(close_req
);
2093 ll_finish_md_op_data(op_data
);
2096 int ll_prep_inode(struct inode
**inode
, struct ptlrpc_request
*req
,
2097 struct super_block
*sb
, struct lookup_intent
*it
)
2099 struct ll_sb_info
*sbi
= NULL
;
2100 struct lustre_md md
= { NULL
};
2103 LASSERT(*inode
|| sb
);
2104 sbi
= sb
? ll_s2sbi(sb
) : ll_i2sbi(*inode
);
2105 rc
= md_get_lustre_md(sbi
->ll_md_exp
, req
, sbi
->ll_dt_exp
,
2106 sbi
->ll_md_exp
, &md
);
2111 rc
= ll_update_inode(*inode
, &md
);
2118 * At this point server returns to client's same fid as client
2119 * generated for creating. So using ->fid1 is okay here.
2121 if (!fid_is_sane(&md
.body
->mbo_fid1
)) {
2122 CERROR("%s: Fid is insane " DFID
"\n",
2123 ll_get_fsname(sb
, NULL
, 0),
2124 PFID(&md
.body
->mbo_fid1
));
2129 *inode
= ll_iget(sb
, cl_fid_build_ino(&md
.body
->mbo_fid1
,
2130 sbi
->ll_flags
& LL_SBI_32BIT_API
),
2132 if (IS_ERR(*inode
)) {
2133 #ifdef CONFIG_FS_POSIX_ACL
2135 posix_acl_release(md
.posix_acl
);
2136 md
.posix_acl
= NULL
;
2140 CERROR("new_inode -fatal: rc %d\n", rc
);
2145 /* Handling piggyback layout lock.
2146 * Layout lock can be piggybacked by getattr and open request.
2147 * The lsm can be applied to inode only if it comes with a layout lock
2148 * otherwise correct layout may be overwritten, for example:
2149 * 1. proc1: mdt returns a lsm but not granting layout
2150 * 2. layout was changed by another client
2151 * 3. proc2: refresh layout and layout lock granted
2152 * 4. proc1: to apply a stale layout
2154 if (it
&& it
->it_lock_mode
!= 0) {
2155 struct lustre_handle lockh
;
2156 struct ldlm_lock
*lock
;
2158 lockh
.cookie
= it
->it_lock_handle
;
2159 lock
= ldlm_handle2lock(&lockh
);
2161 if (ldlm_has_layout(lock
)) {
2162 struct cl_object_conf conf
;
2164 memset(&conf
, 0, sizeof(conf
));
2165 conf
.coc_opc
= OBJECT_CONF_SET
;
2166 conf
.coc_inode
= *inode
;
2167 conf
.coc_lock
= lock
;
2168 conf
.u
.coc_layout
= md
.layout
;
2169 (void)ll_layout_conf(*inode
, &conf
);
2171 LDLM_LOCK_PUT(lock
);
2175 md_free_lustre_md(sbi
->ll_md_exp
, &md
);
2177 if (rc
!= 0 && it
&& it
->it_op
& IT_OPEN
)
2178 ll_open_cleanup(sb
? sb
: (*inode
)->i_sb
, req
);
2183 int ll_obd_statfs(struct inode
*inode
, void __user
*arg
)
2185 struct ll_sb_info
*sbi
= NULL
;
2186 struct obd_export
*exp
;
2188 struct obd_ioctl_data
*data
= NULL
;
2197 sbi
= ll_i2sbi(inode
);
2203 rc
= obd_ioctl_getdata(&buf
, &len
, arg
);
2208 if (!data
->ioc_inlbuf1
|| !data
->ioc_inlbuf2
||
2209 !data
->ioc_pbuf1
|| !data
->ioc_pbuf2
) {
2214 if (data
->ioc_inllen1
!= sizeof(__u32
) ||
2215 data
->ioc_inllen2
!= sizeof(__u32
) ||
2216 data
->ioc_plen1
!= sizeof(struct obd_statfs
) ||
2217 data
->ioc_plen2
!= sizeof(struct obd_uuid
)) {
2222 memcpy(&type
, data
->ioc_inlbuf1
, sizeof(__u32
));
2223 if (type
& LL_STATFS_LMV
) {
2224 exp
= sbi
->ll_md_exp
;
2225 } else if (type
& LL_STATFS_LOV
) {
2226 exp
= sbi
->ll_dt_exp
;
2232 rc
= obd_iocontrol(IOC_OBD_STATFS
, exp
, len
, buf
, NULL
);
2237 obd_ioctl_freedata(buf
, len
);
2241 int ll_process_config(struct lustre_cfg
*lcfg
)
2245 struct lprocfs_static_vars lvars
;
2249 lprocfs_llite_init_vars(&lvars
);
2251 /* The instance name contains the sb: lustre-client-aacfe000 */
2252 ptr
= strrchr(lustre_cfg_string(lcfg
, 0), '-');
2253 if (!ptr
|| !*(++ptr
))
2255 rc
= kstrtoul(ptr
, 16, &x
);
2259 /* This better be a real Lustre superblock! */
2260 LASSERT(s2lsi((struct super_block
*)sb
)->lsi_lmd
->lmd_magic
== LMD_MAGIC
);
2262 /* Note we have not called client_common_fill_super yet, so
2263 * proc fns must be able to handle that!
2265 rc
= class_process_proc_param(PARAM_LLITE
, lvars
.obd_vars
,
2272 /* this function prepares md_op_data hint for passing ot down to MD stack. */
2273 struct md_op_data
*ll_prep_md_op_data(struct md_op_data
*op_data
,
2274 struct inode
*i1
, struct inode
*i2
,
2275 const char *name
, size_t namelen
,
2276 u32 mode
, __u32 opc
, void *data
)
2279 /* Do not reuse namelen for something else. */
2281 return ERR_PTR(-EINVAL
);
2283 if (namelen
> ll_i2sbi(i1
)->ll_namelen
)
2284 return ERR_PTR(-ENAMETOOLONG
);
2286 if (!lu_name_is_valid_2(name
, namelen
))
2287 return ERR_PTR(-EINVAL
);
2291 op_data
= kzalloc(sizeof(*op_data
), GFP_NOFS
);
2294 return ERR_PTR(-ENOMEM
);
2296 ll_i2gids(op_data
->op_suppgids
, i1
, i2
);
2297 op_data
->op_fid1
= *ll_inode2fid(i1
);
2298 op_data
->op_default_stripe_offset
= -1;
2299 if (S_ISDIR(i1
->i_mode
)) {
2300 op_data
->op_mea1
= ll_i2info(i1
)->lli_lsm_md
;
2301 if (opc
== LUSTRE_OPC_MKDIR
)
2302 op_data
->op_default_stripe_offset
=
2303 ll_i2info(i1
)->lli_def_stripe_offset
;
2307 op_data
->op_fid2
= *ll_inode2fid(i2
);
2308 if (S_ISDIR(i2
->i_mode
))
2309 op_data
->op_mea2
= ll_i2info(i2
)->lli_lsm_md
;
2311 fid_zero(&op_data
->op_fid2
);
2314 if (ll_i2sbi(i1
)->ll_flags
& LL_SBI_64BIT_HASH
)
2315 op_data
->op_cli_flags
|= CLI_HASH64
;
2317 if (ll_need_32bit_api(ll_i2sbi(i1
)))
2318 op_data
->op_cli_flags
|= CLI_API32
;
2320 op_data
->op_name
= name
;
2321 op_data
->op_namelen
= namelen
;
2322 op_data
->op_mode
= mode
;
2323 op_data
->op_mod_time
= ktime_get_real_seconds();
2324 op_data
->op_fsuid
= from_kuid(&init_user_ns
, current_fsuid());
2325 op_data
->op_fsgid
= from_kgid(&init_user_ns
, current_fsgid());
2326 op_data
->op_cap
= cfs_curproc_cap_pack();
2327 if ((opc
== LUSTRE_OPC_CREATE
) && name
&&
2328 filename_is_volatile(name
, namelen
, &op_data
->op_mds
))
2329 op_data
->op_bias
|= MDS_CREATE_VOLATILE
;
2331 op_data
->op_mds
= 0;
2332 op_data
->op_data
= data
;
2337 void ll_finish_md_op_data(struct md_op_data
*op_data
)
2342 int ll_show_options(struct seq_file
*seq
, struct dentry
*dentry
)
2344 struct ll_sb_info
*sbi
;
2346 LASSERT(seq
&& dentry
);
2347 sbi
= ll_s2sbi(dentry
->d_sb
);
2349 if (sbi
->ll_flags
& LL_SBI_NOLCK
)
2350 seq_puts(seq
, ",nolock");
2352 if (sbi
->ll_flags
& LL_SBI_FLOCK
)
2353 seq_puts(seq
, ",flock");
2355 if (sbi
->ll_flags
& LL_SBI_LOCALFLOCK
)
2356 seq_puts(seq
, ",localflock");
2358 if (sbi
->ll_flags
& LL_SBI_USER_XATTR
)
2359 seq_puts(seq
, ",user_xattr");
2361 if (sbi
->ll_flags
& LL_SBI_LAZYSTATFS
)
2362 seq_puts(seq
, ",lazystatfs");
2364 if (sbi
->ll_flags
& LL_SBI_USER_FID2PATH
)
2365 seq_puts(seq
, ",user_fid2path");
2367 if (sbi
->ll_flags
& LL_SBI_ALWAYS_PING
)
2368 seq_puts(seq
, ",always_ping");
2374 * Get obd name by cmd, and copy out to user space
2376 int ll_get_obd_name(struct inode
*inode
, unsigned int cmd
, unsigned long arg
)
2378 struct ll_sb_info
*sbi
= ll_i2sbi(inode
);
2379 struct obd_device
*obd
;
2381 if (cmd
== OBD_IOC_GETDTNAME
)
2382 obd
= class_exp2obd(sbi
->ll_dt_exp
);
2383 else if (cmd
== OBD_IOC_GETMDNAME
)
2384 obd
= class_exp2obd(sbi
->ll_md_exp
);
2391 if (copy_to_user((void __user
*)arg
, obd
->obd_name
,
2392 strlen(obd
->obd_name
) + 1))
2399 * Get lustre file system name by \a sbi. If \a buf is provided(non-NULL), the
2400 * fsname will be returned in this buffer; otherwise, a static buffer will be
2401 * used to store the fsname and returned to caller.
2403 char *ll_get_fsname(struct super_block
*sb
, char *buf
, int buflen
)
2405 static char fsname_static
[MTI_NAME_MAXLEN
];
2406 struct lustre_sb_info
*lsi
= s2lsi(sb
);
2411 /* this means the caller wants to use static buffer
2412 * and it doesn't care about race. Usually this is
2413 * in error reporting path
2415 buf
= fsname_static
;
2416 buflen
= sizeof(fsname_static
);
2419 len
= strlen(lsi
->lsi_lmd
->lmd_profile
);
2420 ptr
= strrchr(lsi
->lsi_lmd
->lmd_profile
, '-');
2421 if (ptr
&& (strcmp(ptr
, "-client") == 0))
2424 if (unlikely(len
>= buflen
))
2426 strncpy(buf
, lsi
->lsi_lmd
->lmd_profile
, len
);
2432 void ll_dirty_page_discard_warn(struct page
*page
, int ioret
)
2434 char *buf
, *path
= NULL
;
2435 struct dentry
*dentry
= NULL
;
2436 struct vvp_object
*obj
= cl_inode2vvp(page
->mapping
->host
);
2438 /* this can be called inside spin lock so use GFP_ATOMIC. */
2439 buf
= (char *)__get_free_page(GFP_ATOMIC
);
2441 dentry
= d_find_alias(page
->mapping
->host
);
2443 path
= dentry_path_raw(dentry
, buf
, PAGE_SIZE
);
2447 "%s: dirty page discard: %s/fid: " DFID
"/%s may get corrupted (rc %d)\n",
2448 ll_get_fsname(page
->mapping
->host
->i_sb
, NULL
, 0),
2449 s2lsi(page
->mapping
->host
->i_sb
)->lsi_lmd
->lmd_dev
,
2450 PFID(&obj
->vob_header
.coh_lu
.loh_fid
),
2451 (path
&& !IS_ERR(path
)) ? path
: "", ioret
);
2457 free_page((unsigned long)buf
);
2460 ssize_t
ll_copy_user_md(const struct lov_user_md __user
*md
,
2461 struct lov_user_md
**kbuf
)
2463 struct lov_user_md lum
;
2466 if (copy_from_user(&lum
, md
, sizeof(lum
))) {
2471 lum_size
= ll_lov_user_md_size(&lum
);
2475 *kbuf
= kzalloc(lum_size
, GFP_NOFS
);
2481 if (copy_from_user(*kbuf
, md
, lum_size
) != 0) {
2491 * Compute llite root squash state after a change of root squash
2492 * configuration setting or add/remove of a lnet nid
2494 void ll_compute_rootsquash_state(struct ll_sb_info
*sbi
)
2496 struct root_squash_info
*squash
= &sbi
->ll_squash
;
2497 struct lnet_process_id id
;
2501 /* Update norootsquash flag */
2502 down_write(&squash
->rsi_sem
);
2503 if (list_empty(&squash
->rsi_nosquash_nids
)) {
2504 sbi
->ll_flags
&= ~LL_SBI_NOROOTSQUASH
;
2507 * Do not apply root squash as soon as one of our NIDs is
2508 * in the nosquash_nids list
2513 while (LNetGetId(i
++, &id
) != -ENOENT
) {
2514 if (LNET_NETTYP(LNET_NIDNET(id
.nid
)) == LOLND
)
2516 if (cfs_match_nid(id
.nid
, &squash
->rsi_nosquash_nids
)) {
2522 sbi
->ll_flags
|= LL_SBI_NOROOTSQUASH
;
2524 sbi
->ll_flags
&= ~LL_SBI_NOROOTSQUASH
;
2526 up_write(&squash
->rsi_sem
);
2530 * Parse linkea content to extract information about a given hardlink
2532 * \param[in] ldata - Initialized linkea data
2533 * \param[in] linkno - Link identifier
2534 * \param[out] parent_fid - The entry's parent FID
2535 * \param[in] size - Entry name destination buffer
2537 * \retval 0 on success
2538 * \retval Appropriate negative error code on failure
2540 static int ll_linkea_decode(struct linkea_data
*ldata
, unsigned int linkno
,
2541 struct lu_fid
*parent_fid
, struct lu_name
*ln
)
2546 rc
= linkea_init(ldata
);
2550 if (linkno
>= ldata
->ld_leh
->leh_reccount
)
2551 /* beyond last link */
2554 linkea_first_entry(ldata
);
2555 for (idx
= 0; ldata
->ld_lee
; idx
++) {
2556 linkea_entry_unpack(ldata
->ld_lee
, &ldata
->ld_reclen
, ln
,
2561 linkea_next_entry(ldata
);
2571 * Get parent FID and name of an identified link. Operation is performed for
2572 * a given link number, letting the caller iterate over linkno to list one or
2573 * all links of an entry.
2575 * \param[in] file - File descriptor against which to perform the operation
2576 * \param[in,out] arg - User-filled structure containing the linkno to operate
2577 * on and the available size. It is eventually filled with
2578 * the requested information or left untouched on error
2580 * \retval - 0 on success
2581 * \retval - Appropriate negative error code on failure
2583 int ll_getparent(struct file
*file
, struct getparent __user
*arg
)
2585 struct inode
*inode
= file_inode(file
);
2586 struct linkea_data
*ldata
;
2587 struct lu_fid parent_fid
;
2588 struct lu_buf buf
= {
2597 if (!capable(CFS_CAP_DAC_READ_SEARCH
) &&
2598 !(ll_i2sbi(inode
)->ll_flags
& LL_SBI_USER_FID2PATH
))
2601 if (get_user(name_size
, &arg
->gp_name_size
))
2604 if (get_user(linkno
, &arg
->gp_linkno
))
2607 if (name_size
> PATH_MAX
)
2610 ldata
= kzalloc(sizeof(*ldata
), GFP_NOFS
);
2614 rc
= linkea_data_new(ldata
, &buf
);
2618 rc
= ll_xattr_list(inode
, XATTR_NAME_LINK
, XATTR_TRUSTED_T
, buf
.lb_buf
,
2619 buf
.lb_len
, OBD_MD_FLXATTR
);
2623 rc
= ll_linkea_decode(ldata
, linkno
, &parent_fid
, &ln
);
2627 if (ln
.ln_namelen
>= name_size
) {
2632 if (copy_to_user(&arg
->gp_fid
, &parent_fid
, sizeof(arg
->gp_fid
))) {
2637 if (copy_to_user(&arg
->gp_name
, ln
.ln_name
, ln
.ln_namelen
)) {
2642 if (put_user('\0', arg
->gp_name
+ ln
.ln_namelen
)) {