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) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
33 * Directory code for lustre client.
37 #include <linux/pagemap.h>
39 #include <linux/version.h>
40 #include <linux/security.h>
41 #include <linux/user_namespace.h>
42 #include <linux/uidgid.h>
43 #include <linux/uaccess.h>
44 #include <linux/buffer_head.h> // for wait_on_buffer
45 #include <linux/pagevec.h>
47 #define DEBUG_SUBSYSTEM S_LLITE
49 #include <obd_support.h>
50 #include <obd_class.h>
51 #include <uapi/linux/lustre/lustre_ioctl.h>
52 #include <lustre_lib.h>
53 #include <lustre_dlm.h>
54 #include <lustre_compat.h>
55 #include <lustre_fid.h>
56 #include <lustre_kernelcomm.h>
57 #include <lustre_swab.h>
58 #include <libcfs/libcfs_crypto.h>
60 #include "llite_internal.h"
63 * (new) readdir implementation overview.
65 * Original lustre readdir implementation cached exact copy of raw directory
66 * pages on the client. These pages were indexed in client page cache by
67 * logical offset in the directory file. This design, while very simple and
68 * intuitive had some inherent problems:
70 * . it implies that byte offset to the directory entry serves as a
71 * telldir(3)/seekdir(3) cookie, but that offset is not stable: in
72 * ext3/htree directory entries may move due to splits, and more
75 * . it is incompatible with the design of split directories for cmd3,
76 * that assumes that names are distributed across nodes based on their
77 * hash, and so readdir should be done in hash order.
79 * New readdir implementation does readdir in hash order, and uses hash of a
80 * file name as a telldir/seekdir cookie. This led to number of complications:
82 * . hash is not unique, so it cannot be used to index cached directory
83 * pages on the client (note, that it requires a whole pageful of hash
84 * collided entries to cause two pages to have identical hashes);
86 * . hash is not unique, so it cannot, strictly speaking, be used as an
87 * entry cookie. ext3/htree has the same problem and lustre implementation
88 * mimics their solution: seekdir(hash) positions directory at the first
89 * entry with the given hash.
95 * Client caches directory pages using hash of the first entry as an index. As
96 * noted above hash is not unique, so this solution doesn't work as is:
97 * special processing is needed for "page hash chains" (i.e., sequences of
98 * pages filled with entries all having the same hash value).
100 * First, such chains have to be detected. To this end, server returns to the
101 * client the hash of the first entry on the page next to one returned. When
102 * client detects that this hash is the same as hash of the first entry on the
103 * returned page, page hash collision has to be handled. Pages in the
104 * hash chain, except first one, are termed "overflow pages".
106 * Proposed (unimplimented) solution to index uniqueness problem is to
107 * not cache overflow pages. Instead, when page hash collision is
108 * detected, all overflow pages from emerging chain should be
109 * immediately requested from the server and placed in a special data
110 * structure. This data structure can be used by ll_readdir() to
111 * process entries from overflow pages. When readdir invocation
112 * finishes, overflow pages are discarded. If page hash collision chain
113 * weren't completely processed, next call to readdir will again detect
114 * page hash collision, again read overflow pages in, process next
115 * portion of entries and again discard the pages. This is not as
116 * wasteful as it looks, because, given reasonable hash, page hash
117 * collisions are extremely rare.
119 * 1. directory positioning
121 * When seekdir(hash) is called, original
132 * identification of and access to overflow pages
136 * Page in MDS_READPAGE RPC is packed in LU_PAGE_SIZE, and each page contains
137 * a header lu_dirpage which describes the start/end hash, and whether this
138 * page is empty (contains no dir entry) or hash collide with next page.
139 * After client receives reply, several pages will be integrated into dir page
140 * in PAGE_SIZE (if PAGE_SIZE greater than LU_PAGE_SIZE), and the
141 * lu_dirpage for this integrated page will be adjusted. See
142 * mdc_adjust_dirpages().
145 struct page *ll_get_dir_page(struct inode *dir, struct md_op_data *op_data,
146 __u64 offset, int *partial_readdir_rc)
148 struct md_readdir_info mrinfo = {
149 .mr_blocking_ast = ll_md_blocking_ast };
153 rc = md_read_page(ll_i2mdexp(dir), op_data, &mrinfo, offset, &page);
157 if (partial_readdir_rc && mrinfo.mr_partial_readdir_rc)
158 *partial_readdir_rc = mrinfo.mr_partial_readdir_rc;
163 void ll_release_page(struct inode *inode, struct page *page,
168 /* Always remove the page for striped dir, because the page is
169 * built from temporarily in LMV layer */
170 if (inode && S_ISDIR(inode->i_mode) &&
171 lmv_dir_striped(ll_i2info(inode)->lli_lsm_md)) {
178 if (likely(page->mapping != NULL))
179 cfs_delete_from_page_cache(page);
185 #ifdef HAVE_DIR_CONTEXT
186 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
187 struct dir_context *ctx, int *partial_readdir_rc)
190 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
191 void *cookie, filldir_t filldir, int *partial_readdir_rc)
194 struct ll_sb_info *sbi = ll_i2sbi(inode);
196 bool is_api32 = ll_need_32bit_api(sbi);
197 bool is_hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
200 struct llcrypt_str lltr = LLTR_INIT(NULL, 0);
204 if (IS_ENCRYPTED(inode)) {
205 rc = llcrypt_fname_alloc_buffer(inode, NAME_MAX, &lltr);
210 page = ll_get_dir_page(inode, op_data, pos, partial_readdir_rc);
212 while (rc == 0 && !done) {
213 struct lu_dirpage *dp;
214 struct lu_dirent *ent;
223 hash = MDS_DIR_END_OFF;
224 dp = page_address(page);
225 for (ent = lu_dirent_start(dp); ent != NULL && !done;
226 ent = lu_dirent_next(ent)) {
233 hash = le64_to_cpu(ent->lde_hash);
234 if (hash < pos) /* Skip until we find target hash */
237 namelen = le16_to_cpu(ent->lde_namelen);
238 if (namelen == 0) /* Skip dummy record */
241 if (is_api32 && is_hash64)
245 fid_le_to_cpu(&fid, &ent->lde_fid);
246 ino = cl_fid_build_ino(&fid, is_api32);
247 type = S_DT(lu_dirent_type_get(ent));
248 /* For ll_nfs_get_name_filldir(), it will try to access
249 * 'ent' through 'lde_name', so the parameter 'name'
250 * for 'filldir()' must be part of the 'ent'. */
251 #ifdef HAVE_DIR_CONTEXT
253 if (!IS_ENCRYPTED(inode)) {
254 done = !dir_emit(ctx, ent->lde_name, namelen,
257 /* Directory is encrypted */
258 int save_len = lltr.len;
259 struct llcrypt_str de_name =
260 LLTR_INIT(ent->lde_name, namelen);
262 rc = ll_fname_disk_to_usr(inode, 0, 0, &de_name,
270 done = !dir_emit(ctx, de_name.name, de_name.len,
274 /* HAVE_DIR_CONTEXT is defined from kernel 3.11, whereas
275 * IS_ENCRYPTED is brought by kernel 4.14.
276 * So there is no need to handle encryption case here.
278 done = filldir(cookie, ent->lde_name, namelen, lhash,
285 ll_release_page(inode, page, false);
289 next = le64_to_cpu(dp->ldp_hash_end);
291 if (pos == MDS_DIR_END_OFF) {
293 * End of directory reached.
296 ll_release_page(inode, page, false);
299 * Normal case: continue to the next
302 ll_release_page(inode, page,
303 le32_to_cpu(dp->ldp_flags) &
306 page = ll_get_dir_page(inode, op_data, pos,
310 #ifdef HAVE_DIR_CONTEXT
315 llcrypt_fname_free_buffer(&lltr);
319 #ifdef HAVE_DIR_CONTEXT
320 static int ll_iterate(struct file *filp, struct dir_context *ctx)
322 static int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
325 struct inode *inode = file_inode(filp);
326 struct ll_file_data *lfd = filp->private_data;
327 struct ll_sb_info *sbi = ll_i2sbi(inode);
328 bool hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
329 int api32 = ll_need_32bit_api(sbi);
330 struct md_op_data *op_data;
331 struct lu_fid pfid = { 0 };
332 ktime_t kstart = ktime_get();
333 /* result of possible partial readdir */
334 int partial_readdir_rc = 0;
340 LASSERT(lfd != NULL);
344 "VFS Op:inode="DFID"(%p) pos/size%lu/%llu 32bit_api %d\n",
345 PFID(ll_inode2fid(inode)),
346 inode, (unsigned long)pos, i_size_read(inode), api32);
348 if (IS_ENCRYPTED(inode)) {
349 rc = llcrypt_prepare_readdir(inode);
350 if (rc && rc != -ENOKEY)
354 if (pos == MDS_DIR_END_OFF)
360 if (unlikely(ll_dir_striped(inode))) {
362 * This is only needed for striped dir to fill ..,
363 * see lmv_read_page()
365 if (file_dentry(filp)->d_parent != NULL &&
366 file_dentry(filp)->d_parent->d_inode != NULL) {
367 __u64 ibits = MDS_INODELOCK_LOOKUP;
368 struct inode *parent =
369 file_dentry(filp)->d_parent->d_inode;
371 if (ll_have_md_lock(ll_i2mdexp(parent), parent, &ibits,
373 pfid = *ll_inode2fid(parent);
376 /* If it can not find in cache, do lookup .. on the master
378 if (fid_is_zero(&pfid)) {
379 rc = ll_dir_get_parent_fid(inode, &pfid);
385 op_data = ll_prep_md_op_data(NULL, inode, inode, NULL, 0, 0,
386 LUSTRE_OPC_ANY, inode);
388 GOTO(out, rc = PTR_ERR(op_data));
390 /* foreign dirs are browsed out of Lustre */
391 if (unlikely(op_data->op_mea1 != NULL &&
392 op_data->op_mea1->lsm_md_magic == LMV_MAGIC_FOREIGN)) {
393 ll_finish_md_op_data(op_data);
397 op_data->op_fid3 = pfid;
399 #ifdef HAVE_DIR_CONTEXT
401 rc = ll_dir_read(inode, &pos, op_data, ctx, &partial_readdir_rc);
404 rc = ll_dir_read(inode, &pos, op_data, cookie, filldir,
405 &partial_readdir_rc);
408 if (!lfd->fd_partial_readdir_rc)
409 lfd->fd_partial_readdir_rc = partial_readdir_rc;
411 if (pos == MDS_DIR_END_OFF) {
413 pos = LL_DIR_END_OFF_32BIT;
415 pos = LL_DIR_END_OFF;
420 #ifdef HAVE_DIR_CONTEXT
425 ll_finish_md_op_data(op_data);
429 ll_stats_ops_tally(sbi, LPROC_LL_READDIR,
430 ktime_us_delta(ktime_get(), kstart));
436 * Create striped directory with specified stripe(@lump)
438 * \param[in] dparent the parent of the directory.
439 * \param[in] lump the specified stripes.
440 * \param[in] dirname the name of the directory.
441 * \param[in] mode the specified mode of the directory.
443 * \retval =0 if striped directory is being created successfully.
444 * <0 if the creation is failed.
446 static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
447 size_t len, const char *dirname, umode_t mode,
450 struct inode *parent = dparent->d_inode;
451 struct ptlrpc_request *request = NULL;
452 struct md_op_data *op_data;
453 struct ll_sb_info *sbi = ll_i2sbi(parent);
454 struct inode *inode = NULL;
455 struct dentry dentry = {
459 .len = strlen(dirname),
460 .hash = ll_full_name_hash(dparent, dirname,
463 .d_sb = dparent->d_sb,
465 bool encrypt = false;
470 if (unlikely(!lmv_user_magic_supported(lump->lum_magic)))
473 if (lump->lum_magic != LMV_MAGIC_FOREIGN) {
475 "VFS Op:inode="DFID"(%p) name=%s stripe_offset=%d stripe_count=%u, hash_type=%x\n",
476 PFID(ll_inode2fid(parent)), parent, dirname,
477 (int)lump->lum_stripe_offset, lump->lum_stripe_count,
478 lump->lum_hash_type);
480 struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)lump;
483 "VFS Op:inode="DFID"(%p) name %s foreign, length %u, value '%.*s'\n",
484 PFID(ll_inode2fid(parent)), parent, dirname,
485 lfm->lfm_length, lfm->lfm_length, lfm->lfm_value);
488 if (lump->lum_stripe_count > 1 &&
489 !(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_DIR_STRIPE))
492 if (IS_DEADDIR(parent) &&
493 !OBD_FAIL_CHECK(OBD_FAIL_LLITE_NO_CHECK_DEAD))
496 /* MDS < 2.14 doesn't support 'crush' hash type, and cannot handle
497 * unknown hash if client doesn't set a valid one. switch to fnv_1a_64.
499 if (CFS_FAIL_CHECK(OBD_FAIL_LMV_UNKNOWN_STRIPE)) {
500 lump->lum_hash_type = cfs_fail_val;
501 } else if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_CRUSH)) {
502 enum lmv_hash_type type = lump->lum_hash_type &
505 if (type >= LMV_HASH_TYPE_CRUSH ||
506 type == LMV_HASH_TYPE_UNKNOWN)
507 lump->lum_hash_type = (lump->lum_hash_type ^ type) |
508 LMV_HASH_TYPE_FNV_1A_64;
511 hash_flags = lump->lum_hash_type & ~LMV_HASH_TYPE_MASK;
512 if (hash_flags & ~LMV_HASH_FLAG_KNOWN)
515 if (unlikely(!lmv_user_magic_supported(cpu_to_le32(lump->lum_magic))))
516 lustre_swab_lmv_user_md(lump);
518 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
519 mode &= ~current_umask();
520 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
521 op_data = ll_prep_md_op_data(NULL, parent, NULL, dirname,
522 strlen(dirname), mode, LUSTRE_OPC_MKDIR,
525 RETURN(PTR_ERR(op_data));
527 op_data->op_dir_depth = ll_i2info(parent)->lli_inherit_depth ?:
528 ll_i2info(parent)->lli_dir_depth;
530 if (ll_sbi_has_encrypt(sbi) &&
531 (IS_ENCRYPTED(parent) ||
532 unlikely(ll_sb_has_test_dummy_encryption(parent->i_sb)))) {
533 err = llcrypt_prepare_readdir(parent);
535 GOTO(out_op_data, err);
536 if (!llcrypt_has_encryption_key(parent))
537 GOTO(out_op_data, err = -ENOKEY);
541 if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
542 /* selinux_dentry_init_security() uses dentry->d_parent and name
543 * to determine the security context for the file. So our fake
544 * dentry should be real enough for this purpose. */
545 err = ll_dentry_init_security(&dentry, mode, &dentry.d_name,
546 &op_data->op_file_secctx_name,
547 &op_data->op_file_secctx_name_size,
548 &op_data->op_file_secctx,
549 &op_data->op_file_secctx_size);
551 GOTO(out_op_data, err);
555 err = llcrypt_inherit_context(parent, NULL, op_data, false);
557 GOTO(out_op_data, err);
560 op_data->op_cli_flags |= CLI_SET_MEA;
562 op_data->op_bias |= MDS_SETSTRIPE_CREATE;
564 err = md_create(sbi->ll_md_exp, op_data, lump, len, mode,
565 from_kuid(&init_user_ns, current_fsuid()),
566 from_kgid(&init_user_ns, current_fsgid()),
567 current_cap(), 0, &request);
569 GOTO(out_request, err);
571 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_SETDIRSTRIPE_PAUSE, cfs_fail_val);
573 err = ll_prep_inode(&inode, &request->rq_pill, parent->i_sb, NULL);
575 GOTO(out_inode, err);
577 dentry.d_inode = inode;
579 if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags))
580 err = ll_inode_notifysecctx(inode, op_data->op_file_secctx,
581 op_data->op_file_secctx_size);
583 err = ll_inode_init_security(&dentry, inode, parent);
586 GOTO(out_inode, err);
589 err = ll_set_encflags(inode, op_data->op_file_encctx,
590 op_data->op_file_encctx_size, false);
592 GOTO(out_inode, err);
598 ptlrpc_req_finished(request);
600 ll_finish_md_op_data(op_data);
605 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
608 struct ll_sb_info *sbi = ll_i2sbi(inode);
609 struct md_op_data *op_data;
610 struct ptlrpc_request *req = NULL;
616 switch (lump->lmm_magic) {
617 case LOV_USER_MAGIC_V1:
618 lum_size = sizeof(struct lov_user_md_v1);
620 case LOV_USER_MAGIC_V3:
621 lum_size = sizeof(struct lov_user_md_v3);
623 case LOV_USER_MAGIC_COMP_V1:
624 lum_size = ((struct lov_comp_md_v1 *)lump)->lcm_size;
626 case LMV_USER_MAGIC: {
627 struct lmv_user_md *lmv = (struct lmv_user_md *)lump;
629 /* MDS < 2.14 doesn't support 'crush' hash type, and
630 * cannot handle unknown hash if client doesn't set a
631 * valid one. switch to fnv_1a_64.
633 if (!(exp_connect_flags2(sbi->ll_md_exp) &
634 OBD_CONNECT2_CRUSH)) {
635 enum lmv_hash_type type = lmv->lum_hash_type &
638 if (type >= LMV_HASH_TYPE_CRUSH ||
639 type == LMV_HASH_TYPE_UNKNOWN)
641 (lmv->lum_hash_type ^ type) |
642 LMV_HASH_TYPE_FNV_1A_64;
644 if (lmv->lum_magic != cpu_to_le32(LMV_USER_MAGIC))
645 lustre_swab_lmv_user_md(lmv);
646 lum_size = sizeof(*lmv);
649 case LOV_USER_MAGIC_SPECIFIC: {
650 struct lov_user_md_v3 *v3 =
651 (struct lov_user_md_v3 *)lump;
652 if (v3->lmm_stripe_count > LOV_MAX_STRIPE_COUNT)
654 lum_size = lov_user_md_size(v3->lmm_stripe_count,
655 LOV_USER_MAGIC_SPECIFIC);
659 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
660 " %#08x != %#08x nor %#08x\n",
661 lump->lmm_magic, LOV_USER_MAGIC_V1,
667 * This is coming from userspace, so should be in
668 * local endian. But the MDS would like it in little
669 * endian, so we swab it before we send it.
671 if ((__swab32(lump->lmm_magic) & le32_to_cpu(LOV_MAGIC_MASK)) ==
672 le32_to_cpu(LOV_MAGIC_MAGIC))
673 lustre_swab_lov_user_md(lump, 0);
675 lum_size = sizeof(struct lov_user_md_v1);
678 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
679 LUSTRE_OPC_ANY, NULL);
681 RETURN(PTR_ERR(op_data));
683 /* swabbing is done in lov_setstripe() on server side */
684 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size, &req);
685 ll_finish_md_op_data(op_data);
686 ptlrpc_req_finished(req);
693 int ll_dir_get_default_layout(struct inode *inode, void **plmm, int *plmm_size,
694 struct ptlrpc_request **request, u64 valid,
695 enum get_default_layout_type type)
697 struct ll_sb_info *sbi = ll_i2sbi(inode);
698 struct mdt_body *body;
699 struct lov_mds_md *lmm = NULL;
700 struct ptlrpc_request *req = NULL;
701 int lmm_size = OBD_MAX_DEFAULT_EA_SIZE;
702 struct md_op_data *op_data;
708 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, lmm_size,
709 LUSTRE_OPC_ANY, NULL);
711 RETURN(PTR_ERR(op_data));
713 op_data->op_valid = valid | OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
715 if (type == GET_DEFAULT_LAYOUT_ROOT) {
716 lu_root_fid(&op_data->op_fid1);
717 fid = op_data->op_fid1;
719 fid = *ll_inode2fid(inode);
722 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
723 ll_finish_md_op_data(op_data);
725 CDEBUG(D_INFO, "md_getattr failed on inode "DFID": rc %d\n",
730 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
731 LASSERT(body != NULL);
733 lmm_size = body->mbo_eadatasize;
735 if (!(body->mbo_valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
737 GOTO(out, rc = -ENODATA);
740 lmm = req_capsule_server_sized_get(&req->rq_pill,
741 &RMF_MDT_MD, lmm_size);
742 LASSERT(lmm != NULL);
745 * This is coming from the MDS, so is probably in
746 * little endian. We convert it to host endian before
747 * passing it to userspace.
749 /* We don't swab objects for directories */
750 switch (le32_to_cpu(lmm->lmm_magic)) {
753 case LOV_MAGIC_COMP_V1:
754 case LOV_USER_MAGIC_SPECIFIC:
755 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
756 lustre_swab_lov_user_md((struct lov_user_md *)lmm, 0);
759 if (LMV_MAGIC != cpu_to_le32(LMV_MAGIC))
760 lustre_swab_lmv_mds_md((union lmv_mds_md *)lmm);
763 if (LMV_USER_MAGIC != cpu_to_le32(LMV_USER_MAGIC))
764 lustre_swab_lmv_user_md((struct lmv_user_md *)lmm);
766 case LMV_MAGIC_FOREIGN: {
767 struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)lmm;
769 if (LMV_MAGIC_FOREIGN != cpu_to_le32(LMV_MAGIC_FOREIGN)) {
770 __swab32s(&lfm->lfm_magic);
771 __swab32s(&lfm->lfm_length);
772 __swab32s(&lfm->lfm_type);
773 __swab32s(&lfm->lfm_flags);
778 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
783 *plmm_size = lmm_size;
789 * This function will be used to get default LOV/LMV/Default LMV
790 * @valid will be used to indicate which stripe it will retrieve.
791 * If the directory does not have its own default layout, then the
792 * function will request the default layout from root FID.
793 * OBD_MD_MEA LMV stripe EA
794 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
795 * otherwise Default LOV EA.
796 * Each time, it can only retrieve 1 stripe EA
798 int ll_dir_getstripe_default(struct inode *inode, void **plmm, int *plmm_size,
799 struct ptlrpc_request **request,
800 struct ptlrpc_request **root_request,
803 struct ptlrpc_request *req = NULL;
804 struct ptlrpc_request *root_req = NULL;
805 struct lov_mds_md *lmm = NULL;
810 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
812 if (rc == -ENODATA && !fid_is_root(ll_inode2fid(inode)) &&
813 !(valid & OBD_MD_MEA) && root_request != NULL) {
814 int rc2 = ll_dir_get_default_layout(inode, (void **)&lmm,
815 &lmm_size, &root_req, valid,
816 GET_DEFAULT_LAYOUT_ROOT);
822 *plmm_size = lmm_size;
824 if (root_request != NULL)
825 *root_request = root_req;
831 * This function will be used to get default LOV/LMV/Default LMV
832 * @valid will be used to indicate which stripe it will retrieve
833 * OBD_MD_MEA LMV stripe EA
834 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
835 * otherwise Default LOV EA.
836 * Each time, it can only retrieve 1 stripe EA
838 int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
839 struct ptlrpc_request **request, u64 valid)
841 struct ptlrpc_request *req = NULL;
842 struct lov_mds_md *lmm = NULL;
847 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
851 *plmm_size = lmm_size;
857 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid)
859 struct md_op_data *op_data;
864 OBD_ALLOC_PTR(op_data);
868 op_data->op_flags |= MF_GET_MDT_IDX;
869 op_data->op_fid1 = *fid;
870 rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
871 mdt_index = op_data->op_mds;
872 OBD_FREE_PTR(op_data);
880 * Get MDT index for the inode.
882 int ll_get_mdt_idx(struct inode *inode)
884 return ll_get_mdt_idx_by_fid(ll_i2sbi(inode), ll_inode2fid(inode));
888 * Generic handler to do any pre-copy work.
890 * It sends a first hsm_progress (with extent length == 0) to coordinator as a
891 * first information for it that real work has started.
893 * Moreover, for a ARCHIVE request, it will sample the file data version and
894 * store it in \a copy.
896 * \return 0 on success.
898 static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
900 struct ll_sb_info *sbi = ll_s2sbi(sb);
901 struct hsm_progress_kernel hpk;
906 /* Forge a hsm_progress based on data from copy. */
907 hpk.hpk_fid = copy->hc_hai.hai_fid;
908 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
909 hpk.hpk_extent.offset = copy->hc_hai.hai_extent.offset;
910 hpk.hpk_extent.length = 0;
913 hpk.hpk_data_version = 0;
916 /* For archive request, we need to read the current file version. */
917 if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
919 __u64 data_version = 0;
921 /* Get inode for this fid */
922 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
924 hpk.hpk_flags |= HP_FLAG_RETRY;
925 /* hpk_errval is >= 0 */
926 hpk.hpk_errval = -PTR_ERR(inode);
927 GOTO(progress, rc = PTR_ERR(inode));
930 /* Read current file data version */
931 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
934 CDEBUG(D_HSM, "Could not read file data version of "
935 DFID" (rc = %d). Archive request ("
936 "%#llx) could not be done.\n",
937 PFID(©->hc_hai.hai_fid), rc,
938 copy->hc_hai.hai_cookie);
939 hpk.hpk_flags |= HP_FLAG_RETRY;
940 /* hpk_errval must be >= 0 */
941 hpk.hpk_errval = -rc;
945 /* Store in the hsm_copy for later copytool use.
946 * Always modified even if no lsm. */
947 copy->hc_data_version = data_version;
951 /* On error, the request should be considered as completed */
952 if (hpk.hpk_errval > 0)
953 hpk.hpk_flags |= HP_FLAG_COMPLETED;
955 rc2 = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
958 /* Return first error */
959 RETURN(rc != 0 ? rc : rc2);
963 * Generic handler to do any post-copy work.
965 * It will send the last hsm_progress update to coordinator to inform it
966 * that copy is finished and whether it was successful or not.
969 * - for ARCHIVE request, it will sample the file data version and compare it
970 * with the version saved in ll_ioc_copy_start(). If they do not match, copy
971 * will be considered as failed.
972 * - for RESTORE request, it will sample the file data version and send it to
973 * coordinator which is useful if the file was imported as 'released'.
975 * \return 0 on success.
977 static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
979 struct ll_sb_info *sbi = ll_s2sbi(sb);
980 struct hsm_progress_kernel hpk;
985 /* If you modify the logic here, also check llapi_hsm_copy_end(). */
986 /* Take care: copy->hc_hai.hai_action, len, gid and data are not
987 * initialized if copy_end was called with copy == NULL.
990 /* Forge a hsm_progress based on data from copy. */
991 hpk.hpk_fid = copy->hc_hai.hai_fid;
992 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
993 hpk.hpk_extent = copy->hc_hai.hai_extent;
994 hpk.hpk_flags = copy->hc_flags | HP_FLAG_COMPLETED;
995 hpk.hpk_errval = copy->hc_errval;
996 hpk.hpk_data_version = 0;
998 /* For archive request, we need to check the file data was not changed.
1000 * For restore request, we need to send the file data version, this is
1001 * useful when the file was created using hsm_import.
1003 if (((copy->hc_hai.hai_action == HSMA_ARCHIVE) ||
1004 (copy->hc_hai.hai_action == HSMA_RESTORE)) &&
1005 (copy->hc_errval == 0)) {
1006 struct inode *inode;
1007 __u64 data_version = 0;
1009 /* Get lsm for this fid */
1010 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
1011 if (IS_ERR(inode)) {
1012 hpk.hpk_flags |= HP_FLAG_RETRY;
1013 /* hpk_errval must be >= 0 */
1014 hpk.hpk_errval = -PTR_ERR(inode);
1015 GOTO(progress, rc = PTR_ERR(inode));
1018 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
1021 CDEBUG(D_HSM, "Could not read file data version. "
1022 "Request could not be confirmed.\n");
1023 if (hpk.hpk_errval == 0)
1024 hpk.hpk_errval = -rc;
1028 /* Store in the hsm_copy for later copytool use.
1029 * Always modified even if no lsm. */
1030 hpk.hpk_data_version = data_version;
1032 /* File could have been stripped during archiving, so we need
1033 * to check anyway. */
1034 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
1035 (copy->hc_data_version != data_version)) {
1036 CDEBUG(D_HSM, "File data version mismatched. "
1037 "File content was changed during archiving. "
1038 DFID", start:%#llx current:%#llx\n",
1039 PFID(©->hc_hai.hai_fid),
1040 copy->hc_data_version, data_version);
1041 /* File was changed, send error to cdt. Do not ask for
1042 * retry because if a file is modified frequently,
1043 * the cdt will loop on retried archive requests.
1044 * The policy engine will ask for a new archive later
1045 * when the file will not be modified for some tunable
1047 hpk.hpk_flags &= ~HP_FLAG_RETRY;
1049 /* hpk_errval must be >= 0 */
1050 hpk.hpk_errval = -rc;
1057 rc2 = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
1060 /* Return first error */
1061 RETURN(rc != 0 ? rc : rc2);
1065 static int copy_and_ct_start(int cmd, struct obd_export *exp,
1066 const struct lustre_kernelcomm __user *data)
1068 struct lustre_kernelcomm *lk;
1069 struct lustre_kernelcomm *tmp;
1070 size_t size = sizeof(*lk);
1075 /* copy data from userspace to get numbers of archive_id */
1076 OBD_ALLOC(lk, size);
1080 if (copy_from_user(lk, data, size))
1081 GOTO(out_lk, rc = -EFAULT);
1083 if (lk->lk_flags & LK_FLG_STOP)
1086 if (!(lk->lk_flags & LK_FLG_DATANR)) {
1087 __u32 archive_mask = lk->lk_data_count;
1090 /* old hsm agent to old MDS */
1091 if (!exp_connect_archive_id_array(exp))
1094 /* old hsm agent to new MDS */
1095 lk->lk_flags |= LK_FLG_DATANR;
1097 if (archive_mask == 0)
1100 count = hweight32(archive_mask);
1101 new_size = offsetof(struct lustre_kernelcomm, lk_data[count]);
1102 OBD_ALLOC(tmp, new_size);
1104 GOTO(out_lk, rc = -ENOMEM);
1106 memcpy(tmp, lk, size);
1107 tmp->lk_data_count = count;
1113 for (i = 0; i < sizeof(archive_mask) * 8; i++) {
1114 if (BIT(i) & archive_mask) {
1115 lk->lk_data[count] = i + 1;
1122 /* new hsm agent to new mds */
1123 if (lk->lk_data_count > 0) {
1124 new_size = offsetof(struct lustre_kernelcomm,
1125 lk_data[lk->lk_data_count]);
1126 OBD_ALLOC(tmp, new_size);
1128 GOTO(out_lk, rc = -ENOMEM);
1134 if (copy_from_user(lk, data, size))
1135 GOTO(out_lk, rc = -EFAULT);
1138 /* new hsm agent to old MDS */
1139 if (!exp_connect_archive_id_array(exp)) {
1142 if (lk->lk_data_count > LL_HSM_ORIGIN_MAX_ARCHIVE)
1143 GOTO(out_lk, rc = -EINVAL);
1145 for (i = 0; i < lk->lk_data_count; i++) {
1146 if (lk->lk_data[i] > LL_HSM_ORIGIN_MAX_ARCHIVE) {
1148 CERROR("%s: archive id %d requested but only "
1149 "[0 - %zu] supported: rc = %d\n",
1150 exp->exp_obd->obd_name, lk->lk_data[i],
1151 LL_HSM_ORIGIN_MAX_ARCHIVE, rc);
1155 if (lk->lk_data[i] == 0) {
1160 archives |= (1 << (lk->lk_data[i] - 1));
1162 lk->lk_flags &= ~LK_FLG_DATANR;
1163 lk->lk_data_count = archives;
1166 rc = obd_iocontrol(cmd, exp, size, lk, NULL);
1172 static int check_owner(int type, int id)
1176 if (!uid_eq(current_euid(), make_kuid(&init_user_ns, id)))
1180 if (!in_egroup_p(make_kgid(&init_user_ns, id)))
1189 int quotactl_ioctl(struct super_block *sb, struct if_quotactl *qctl)
1191 struct ll_sb_info *sbi = ll_s2sbi(sb);
1192 int cmd = qctl->qc_cmd;
1193 int type = qctl->qc_type;
1194 int id = qctl->qc_id;
1195 int valid = qctl->qc_valid;
1203 case LUSTRE_Q_SETDEFAULT:
1204 case LUSTRE_Q_SETQUOTAPOOL:
1205 case LUSTRE_Q_SETINFOPOOL:
1206 case LUSTRE_Q_SETDEFAULT_POOL:
1207 case LUSTRE_Q_DELETEQID:
1208 case LUSTRE_Q_RESETQID:
1209 if (!capable(CAP_SYS_ADMIN))
1212 if (sb->s_flags & SB_RDONLY)
1216 case LUSTRE_Q_GETDEFAULT:
1217 case LUSTRE_Q_GETQUOTAPOOL:
1218 case LUSTRE_Q_GETDEFAULT_POOL:
1219 if (check_owner(type, id) &&
1220 (!capable(CAP_SYS_ADMIN)))
1224 case LUSTRE_Q_GETINFOPOOL:
1227 CERROR("unsupported quotactl op: %#x\n", cmd);
1231 if (valid != QC_GENERAL) {
1232 if (cmd == Q_GETINFO)
1233 qctl->qc_cmd = Q_GETOINFO;
1234 else if (cmd == Q_GETQUOTA ||
1235 cmd == LUSTRE_Q_GETQUOTAPOOL)
1236 qctl->qc_cmd = Q_GETOQUOTA;
1242 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
1243 sizeof(*qctl), qctl, NULL);
1246 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
1247 sizeof(*qctl), qctl, NULL);
1250 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
1251 sizeof(*qctl), qctl, NULL);
1253 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1255 sizeof(*qctl), qctl, NULL);
1266 struct obd_quotactl *oqctl;
1267 int oqctl_len = sizeof(*oqctl);
1269 if (LUSTRE_Q_CMD_IS_POOL(cmd))
1270 oqctl_len += LOV_MAXPOOLNAME + 1;
1272 OBD_ALLOC(oqctl, oqctl_len);
1276 QCTL_COPY(oqctl, qctl);
1277 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1279 OBD_FREE(oqctl, oqctl_len);
1282 /* If QIF_SPACE is not set, client should collect the
1283 * space usage from OSSs by itself */
1284 if ((cmd == Q_GETQUOTA || cmd == LUSTRE_Q_GETQUOTAPOOL) &&
1285 !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
1286 !oqctl->qc_dqblk.dqb_curspace) {
1287 struct obd_quotactl *oqctl_tmp;
1288 int qctl_len = sizeof(*oqctl_tmp) + LOV_MAXPOOLNAME + 1;
1290 OBD_ALLOC(oqctl_tmp, qctl_len);
1291 if (oqctl_tmp == NULL)
1292 GOTO(out, rc = -ENOMEM);
1294 if (cmd == LUSTRE_Q_GETQUOTAPOOL) {
1295 oqctl_tmp->qc_cmd = LUSTRE_Q_GETQUOTAPOOL;
1296 memcpy(oqctl_tmp->qc_poolname,
1298 LOV_MAXPOOLNAME + 1);
1300 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1302 oqctl_tmp->qc_id = oqctl->qc_id;
1303 oqctl_tmp->qc_type = oqctl->qc_type;
1305 /* collect space usage from OSTs */
1306 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1307 rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
1308 if (!rc || rc == -EREMOTEIO) {
1309 oqctl->qc_dqblk.dqb_curspace =
1310 oqctl_tmp->qc_dqblk.dqb_curspace;
1311 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
1314 /* collect space & inode usage from MDTs */
1315 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1316 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1317 oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
1318 rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
1319 if (!rc || rc == -EREMOTEIO) {
1320 oqctl->qc_dqblk.dqb_curspace +=
1321 oqctl_tmp->qc_dqblk.dqb_curspace;
1322 oqctl->qc_dqblk.dqb_curinodes =
1323 oqctl_tmp->qc_dqblk.dqb_curinodes;
1324 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
1326 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
1329 OBD_FREE(oqctl_tmp, qctl_len);
1332 QCTL_COPY(qctl, oqctl);
1333 OBD_FREE(oqctl, oqctl_len);
1339 int ll_rmfid(struct file *file, void __user *arg)
1341 const struct fid_array __user *ufa = arg;
1342 struct inode *inode = file_inode(file);
1343 struct ll_sb_info *sbi = ll_i2sbi(inode);
1344 struct fid_array *lfa = NULL;
1347 int i, rc, *rcs = NULL;
1350 if (!capable(CAP_DAC_READ_SEARCH) &&
1351 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
1353 /* Only need to get the buflen */
1354 if (get_user(nr, &ufa->fa_nr))
1356 /* DoS protection */
1357 if (nr > OBD_MAX_FIDS_IN_ARRAY)
1360 size = offsetof(struct fid_array, fa_fids[nr]);
1361 OBD_ALLOC(lfa, size);
1364 OBD_ALLOC_PTR_ARRAY(rcs, nr);
1366 GOTO(free_lfa, rc = -ENOMEM);
1368 if (copy_from_user(lfa, arg, size))
1369 GOTO(free_rcs, rc = -EFAULT);
1371 /* In case of subdirectory mount, we need to make sure all the files
1372 * for which we want to remove FID are visible in the namespace.
1374 if (!fid_is_root(&sbi->ll_root_fid)) {
1375 struct fid_array *lfa_new = NULL;
1376 int path_len = PATH_MAX, linkno;
1377 struct getinfo_fid2path *gf;
1378 int idx, last_idx = nr - 1;
1380 OBD_ALLOC(lfa_new, size);
1382 GOTO(free_rcs, rc = -ENOMEM);
1385 gf = kmalloc(sizeof(*gf) + path_len + 1, GFP_NOFS);
1387 GOTO(free_rcs, rc = -ENOMEM);
1389 for (idx = 0; idx < nr; idx++) {
1392 memset(gf, 0, sizeof(*gf) + path_len + 1);
1393 gf->gf_fid = lfa->fa_fids[idx];
1394 gf->gf_pathlen = path_len;
1395 gf->gf_linkno = linkno;
1396 rc = __ll_fid2path(inode, gf,
1397 sizeof(*gf) + gf->gf_pathlen,
1399 if (rc == -ENAMETOOLONG) {
1400 struct getinfo_fid2path *tmpgf;
1402 path_len += PATH_MAX;
1403 tmpgf = krealloc(gf,
1404 sizeof(*gf) + path_len + 1,
1408 OBD_FREE(lfa_new, size);
1409 GOTO(free_rcs, rc = -ENOMEM);
1416 if (gf->gf_linkno == linkno)
1418 linkno = gf->gf_linkno;
1422 /* All the links for this fid are visible in the
1423 * mounted subdir. So add it to the list of fids
1426 lfa_new->fa_fids[lfa_new->fa_nr++] =
1429 /* At least one link for this fid is not visible
1430 * in the mounted subdir. So add it at the end
1431 * of the list that will be hidden to lower
1432 * layers, and set -ENOENT as ret code.
1434 lfa_new->fa_fids[last_idx] = lfa->fa_fids[idx];
1435 rcs[last_idx--] = rc;
1439 OBD_FREE(lfa, size);
1443 if (lfa->fa_nr == 0)
1444 GOTO(free_rcs, rc = rcs[nr - 1]);
1446 /* Call mdc_iocontrol */
1447 rc = md_rmfid(ll_i2mdexp(file_inode(file)), lfa, rcs, NULL);
1450 for (i = 0; i < nr; i++)
1452 lfa->fa_fids[i].f_ver = rcs[i];
1453 if (copy_to_user(arg, lfa, size))
1458 OBD_FREE_PTR_ARRAY(rcs, nr);
1460 OBD_FREE(lfa, size);
1465 /* This function tries to get a single name component,
1466 * to send to the server. No actual path traversal involved,
1467 * so we limit to NAME_MAX */
1468 static char *ll_getname(const char __user *filename)
1473 OBD_ALLOC(tmp, NAME_MAX + 1);
1476 return ERR_PTR(-ENOMEM);
1478 len = strncpy_from_user(tmp, filename, NAME_MAX + 1);
1481 else if (len > NAME_MAX)
1482 ret = -ENAMETOOLONG;
1485 OBD_FREE(tmp, NAME_MAX + 1);
1491 #define ll_putname(filename) OBD_FREE(filename, NAME_MAX + 1);
1493 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1495 struct dentry *dentry = file_dentry(file);
1496 struct inode *inode = file_inode(file);
1497 struct ll_sb_info *sbi = ll_i2sbi(inode);
1498 struct obd_ioctl_data *data = NULL;
1499 void __user *uarg = (void __user *)arg;
1503 CDEBUG(D_VFSTRACE|D_IOCTL, "VFS Op:inode="DFID"(%pK) cmd=%x arg=%lx\n",
1504 PFID(ll_inode2fid(inode)), inode, cmd, arg);
1506 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
1507 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
1510 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
1512 case IOC_MDC_LOOKUP: {
1513 int namelen, len = 0;
1516 rc = obd_ioctl_getdata(&data, &len, uarg);
1520 filename = data->ioc_inlbuf1;
1521 namelen = strlen(filename);
1523 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1524 GOTO(out_free, rc = -EINVAL);
1527 rc = ll_get_fid_by_name(inode, filename, namelen, NULL, NULL);
1529 CERROR("%s: lookup %.*s failed: rc = %d\n",
1530 sbi->ll_fsname, namelen, filename, rc);
1534 OBD_FREE_LARGE(data, len);
1537 case LL_IOC_LMV_SETSTRIPE: {
1538 struct lmv_user_md *lum;
1543 bool createonly = false;
1547 rc = obd_ioctl_getdata(&data, &len, uarg);
1551 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1552 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1553 GOTO(lmv_out_free, rc = -EINVAL);
1555 filename = data->ioc_inlbuf1;
1556 namelen = data->ioc_inllen1;
1559 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1560 GOTO(lmv_out_free, rc = -EINVAL);
1562 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1563 lumlen = data->ioc_inllen2;
1565 if (!lmv_user_magic_supported(lum->lum_magic)) {
1566 CERROR("%s: wrong lum magic %x : rc = %d\n", filename,
1567 lum->lum_magic, -EINVAL);
1568 GOTO(lmv_out_free, rc = -EINVAL);
1571 if ((lum->lum_magic == LMV_USER_MAGIC ||
1572 lum->lum_magic == LMV_USER_MAGIC_SPECIFIC) &&
1573 lumlen < sizeof(*lum)) {
1574 CERROR("%s: wrong lum size %d for magic %x : rc = %d\n",
1575 filename, lumlen, lum->lum_magic, -EINVAL);
1576 GOTO(lmv_out_free, rc = -EINVAL);
1579 if (lum->lum_magic == LMV_MAGIC_FOREIGN &&
1580 lumlen < sizeof(struct lmv_foreign_md)) {
1581 CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1582 filename, lum->lum_magic, lumlen, -EFAULT);
1583 GOTO(lmv_out_free, rc = -EINVAL);
1586 mode = data->ioc_type;
1587 createonly = data->ioc_obdo1.o_flags & OBD_FL_OBDMDEXISTS;
1588 rc = ll_dir_setdirstripe(dentry, lum, lumlen, filename, mode,
1591 OBD_FREE_LARGE(data, len);
1595 case LL_IOC_LMV_SET_DEFAULT_STRIPE: {
1596 struct lmv_user_md lum;
1597 struct lmv_user_md __user *ulump = uarg;
1600 if (copy_from_user(&lum, ulump, sizeof(lum)))
1603 if (lum.lum_magic != LMV_USER_MAGIC)
1606 rc = ll_dir_setstripe(inode, (struct lov_user_md *)&lum, 0);
1610 case LL_IOC_LOV_SETSTRIPE_NEW:
1611 case LL_IOC_LOV_SETSTRIPE: {
1612 struct lov_user_md_v3 *lumv3 = NULL;
1613 struct lov_user_md_v1 lumv1;
1614 struct lov_user_md_v1 *lumv1_ptr = &lumv1;
1615 struct lov_user_md_v1 __user *lumv1p = uarg;
1616 struct lov_user_md_v3 __user *lumv3p = uarg;
1618 int set_default = 0;
1620 BUILD_BUG_ON(sizeof(struct lov_user_md_v3) <=
1621 sizeof(struct lov_comp_md_v1));
1622 BUILD_BUG_ON(sizeof(*lumv3) != sizeof(*lumv3p));
1623 /* first try with v1 which is smaller than v3 */
1624 if (copy_from_user(&lumv1, lumv1p, sizeof(lumv1)))
1627 if (is_root_inode(inode))
1630 switch (lumv1.lmm_magic) {
1631 case LOV_USER_MAGIC_V3:
1632 case LOV_USER_MAGIC_SPECIFIC:
1633 lum_size = ll_lov_user_md_size(&lumv1);
1636 OBD_ALLOC(lumv3, lum_size);
1639 if (copy_from_user(lumv3, lumv3p, lum_size))
1640 GOTO(out, rc = -EFAULT);
1641 lumv1_ptr = (struct lov_user_md_v1 *)lumv3;
1643 case LOV_USER_MAGIC_V1:
1646 GOTO(out, rc = -ENOTSUPP);
1649 /* in v1 and v3 cases lumv1 points to data */
1650 rc = ll_dir_setstripe(inode, lumv1_ptr, set_default);
1653 OBD_FREE(lumv3, lum_size);
1656 case LL_IOC_LMV_GETSTRIPE: {
1657 struct lmv_user_md __user *ulmv = uarg;
1658 struct lmv_user_md lum;
1659 struct ptlrpc_request *request = NULL;
1660 struct ptlrpc_request *root_request = NULL;
1661 union lmv_mds_md *lmm = NULL;
1664 struct lmv_user_md *tmp = NULL;
1668 int max_stripe_count;
1672 if (copy_from_user(&lum, ulmv, sizeof(*ulmv)))
1675 max_stripe_count = lum.lum_stripe_count;
1676 /* lum_magic will indicate which stripe the ioctl will like
1677 * to get, LMV_MAGIC_V1 is for normal LMV stripe, LMV_USER_MAGIC
1678 * is for default LMV stripe */
1679 if (lum.lum_magic == LMV_MAGIC_V1)
1680 valid |= OBD_MD_MEA;
1681 else if (lum.lum_magic == LMV_USER_MAGIC)
1682 valid |= OBD_MD_DEFAULT_MEA;
1686 rc = ll_dir_getstripe_default(inode, (void **)&lmm, &lmmsize,
1687 &request, &root_request, valid);
1689 GOTO(finish_req, rc);
1691 /* Get default LMV EA */
1692 if (lum.lum_magic == LMV_USER_MAGIC) {
1693 struct lmv_user_md *lum;
1694 struct ll_inode_info *lli;
1696 if (lmmsize > sizeof(*ulmv))
1697 GOTO(finish_req, rc = -EINVAL);
1699 lum = (struct lmv_user_md *)lmm;
1700 if (lum->lum_max_inherit == LMV_INHERIT_NONE)
1701 GOTO(finish_req, rc = -ENODATA);
1703 if (root_request != NULL) {
1704 lli = ll_i2info(inode);
1705 if (lum->lum_max_inherit !=
1706 LMV_INHERIT_UNLIMITED) {
1707 if (lum->lum_max_inherit <
1709 lum->lum_max_inherit >
1711 lum->lum_max_inherit <=
1713 GOTO(finish_req, rc = -ENODATA);
1715 lum->lum_max_inherit -=
1719 if (lum->lum_max_inherit_rr !=
1720 LMV_INHERIT_RR_UNLIMITED) {
1721 if (lum->lum_max_inherit_rr ==
1723 lum->lum_max_inherit_rr <
1724 LMV_INHERIT_RR_END ||
1725 lum->lum_max_inherit_rr >
1726 LMV_INHERIT_RR_MAX ||
1727 lum->lum_max_inherit_rr <=
1728 lli->lli_dir_depth) {
1729 lum->lum_max_inherit_rr =
1730 LMV_INHERIT_RR_NONE;
1734 lum->lum_max_inherit_rr -=
1739 if (copy_to_user(ulmv, lmm, lmmsize))
1740 GOTO(finish_req, rc = -EFAULT);
1742 GOTO(finish_req, rc);
1745 /* if foreign LMV case, fake stripes number */
1746 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1747 struct lmv_foreign_md *lfm;
1749 lfm = (struct lmv_foreign_md *)lmm;
1750 if (lfm->lfm_length < XATTR_SIZE_MAX -
1751 offsetof(typeof(*lfm), lfm_value)) {
1752 __u32 size = lfm->lfm_length +
1753 offsetof(typeof(*lfm), lfm_value);
1755 stripe_count = lmv_foreign_to_md_stripes(size);
1757 CERROR("invalid %d foreign size returned\n",
1762 stripe_count = lmv_mds_md_stripe_count_get(lmm);
1764 if (max_stripe_count < stripe_count) {
1765 lum.lum_stripe_count = stripe_count;
1766 if (copy_to_user(ulmv, &lum, sizeof(lum)))
1767 GOTO(finish_req, rc = -EFAULT);
1768 GOTO(finish_req, rc = -E2BIG);
1771 /* enough room on user side and foreign case */
1772 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1773 struct lmv_foreign_md *lfm;
1776 lfm = (struct lmv_foreign_md *)lmm;
1777 size = lfm->lfm_length +
1778 offsetof(struct lmv_foreign_md, lfm_value);
1779 if (copy_to_user(ulmv, lfm, size))
1780 GOTO(finish_req, rc = -EFAULT);
1781 GOTO(finish_req, rc);
1784 lum_size = lmv_user_md_size(stripe_count,
1785 LMV_USER_MAGIC_SPECIFIC);
1786 OBD_ALLOC(tmp, lum_size);
1788 GOTO(finish_req, rc = -ENOMEM);
1790 mdt_index = ll_get_mdt_idx(inode);
1792 GOTO(out_tmp, rc = -ENOMEM);
1794 tmp->lum_magic = LMV_MAGIC_V1;
1795 tmp->lum_stripe_count = 0;
1796 tmp->lum_stripe_offset = mdt_index;
1797 tmp->lum_hash_type = lmv_mds_md_hash_type_get(lmm);
1798 for (i = 0; i < stripe_count; i++) {
1801 fid_le_to_cpu(&fid, &lmm->lmv_md_v1.lmv_stripe_fids[i]);
1802 if (fid_is_sane(&fid)) {
1803 mdt_index = ll_get_mdt_idx_by_fid(sbi, &fid);
1805 GOTO(out_tmp, rc = mdt_index);
1807 tmp->lum_objects[i].lum_mds = mdt_index;
1808 tmp->lum_objects[i].lum_fid = fid;
1811 tmp->lum_stripe_count++;
1814 if (copy_to_user(ulmv, tmp, lum_size))
1815 GOTO(out_tmp, rc = -EFAULT);
1817 OBD_FREE(tmp, lum_size);
1819 ptlrpc_req_finished(request);
1820 ptlrpc_req_finished(root_request);
1823 case LL_IOC_REMOVE_ENTRY: {
1824 char *filename = NULL;
1828 /* Here is a little hack to avoid sending REINT_RMENTRY to
1829 * unsupported server, which might crash the server(LU-2730),
1830 * Because both LVB_TYPE and REINT_RMENTRY will be supported
1831 * on 2.4, we use OBD_CONNECT_LVB_TYPE to detect whether the
1832 * server will support REINT_RMENTRY XXX*/
1833 if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE))
1836 filename = ll_getname(uarg);
1837 if (IS_ERR(filename))
1838 RETURN(PTR_ERR(filename));
1840 namelen = strlen(filename);
1842 GOTO(out_rmdir, rc = -EINVAL);
1844 rc = ll_rmdir_entry(inode, filename, namelen);
1847 ll_putname(filename);
1851 RETURN(ll_rmfid(file, uarg));
1852 case LL_IOC_LOV_SWAP_LAYOUTS:
1854 case LL_IOC_LOV_GETSTRIPE:
1855 case LL_IOC_LOV_GETSTRIPE_NEW:
1856 case LL_IOC_MDC_GETINFO_V1:
1857 case LL_IOC_MDC_GETINFO_V2:
1858 case IOC_MDC_GETFILEINFO_V1:
1859 case IOC_MDC_GETFILEINFO_V2:
1860 case IOC_MDC_GETFILESTRIPE: {
1861 struct ptlrpc_request *request = NULL;
1862 struct ptlrpc_request *root_request = NULL;
1863 struct lov_user_md __user *lump;
1864 struct lov_mds_md *lmm = NULL;
1865 struct mdt_body *body;
1866 char *filename = NULL;
1867 lstat_t __user *statp = NULL;
1868 lstatx_t __user *stxp = NULL;
1869 __u64 __user *flagsp = NULL;
1870 __u32 __user *lmmsizep = NULL;
1871 struct lu_fid __user *fidp = NULL;
1875 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1876 cmd == IOC_MDC_GETFILEINFO_V2 ||
1877 cmd == IOC_MDC_GETFILESTRIPE) {
1878 filename = ll_getname(uarg);
1879 if (IS_ERR(filename))
1880 RETURN(PTR_ERR(filename));
1882 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1883 &lmmsize, &request);
1885 rc = ll_dir_getstripe_default(inode, (void **)&lmm,
1891 body = req_capsule_server_get(&request->rq_pill,
1893 LASSERT(body != NULL);
1898 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO_V1 ||
1899 cmd == LL_IOC_MDC_GETINFO_V1 ||
1900 cmd == IOC_MDC_GETFILEINFO_V2 ||
1901 cmd == LL_IOC_MDC_GETINFO_V2)) {
1909 if (cmd == IOC_MDC_GETFILESTRIPE ||
1910 cmd == LL_IOC_LOV_GETSTRIPE ||
1911 cmd == LL_IOC_LOV_GETSTRIPE_NEW) {
1913 } else if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1914 cmd == LL_IOC_MDC_GETINFO_V1){
1915 struct lov_user_mds_data_v1 __user *lmdp;
1918 statp = &lmdp->lmd_st;
1919 lump = &lmdp->lmd_lmm;
1921 struct lov_user_mds_data __user *lmdp;
1924 fidp = &lmdp->lmd_fid;
1925 stxp = &lmdp->lmd_stx;
1926 flagsp = &lmdp->lmd_flags;
1927 lmmsizep = &lmdp->lmd_lmmsize;
1928 lump = &lmdp->lmd_lmm;
1932 /* If the file has no striping then zero out *lump so
1933 * that the caller isn't confused by garbage. */
1934 if (clear_user(lump, sizeof(*lump)))
1935 GOTO(out_req, rc = -EFAULT);
1936 } else if (copy_to_user(lump, lmm, lmmsize)) {
1937 if (copy_to_user(lump, lmm, sizeof(*lump)))
1938 GOTO(out_req, rc = -EFAULT);
1941 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
1943 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1944 cmd == LL_IOC_MDC_GETINFO_V1) {
1947 st.st_dev = inode->i_sb->s_dev;
1948 st.st_mode = body->mbo_mode;
1949 st.st_nlink = body->mbo_nlink;
1950 st.st_uid = body->mbo_uid;
1951 st.st_gid = body->mbo_gid;
1952 st.st_rdev = body->mbo_rdev;
1953 if (llcrypt_require_key(inode) == -ENOKEY)
1954 st.st_size = round_up(st.st_size,
1955 LUSTRE_ENCRYPTION_UNIT_SIZE);
1957 st.st_size = body->mbo_size;
1958 st.st_blksize = PAGE_SIZE;
1959 st.st_blocks = body->mbo_blocks;
1960 st.st_atime = body->mbo_atime;
1961 st.st_mtime = body->mbo_mtime;
1962 st.st_ctime = body->mbo_ctime;
1963 st.st_ino = cl_fid_build_ino(&body->mbo_fid1,
1966 if (copy_to_user(statp, &st, sizeof(st)))
1967 GOTO(out_req, rc = -EFAULT);
1968 } else if (cmd == IOC_MDC_GETFILEINFO_V2 ||
1969 cmd == LL_IOC_MDC_GETINFO_V2) {
1970 lstatx_t stx = { 0 };
1971 __u64 valid = body->mbo_valid;
1973 stx.stx_blksize = PAGE_SIZE;
1974 stx.stx_nlink = body->mbo_nlink;
1975 stx.stx_uid = body->mbo_uid;
1976 stx.stx_gid = body->mbo_gid;
1977 stx.stx_mode = body->mbo_mode;
1978 stx.stx_ino = cl_fid_build_ino(&body->mbo_fid1,
1980 if (llcrypt_require_key(inode) == -ENOKEY)
1981 stx.stx_size = round_up(stx.stx_size,
1982 LUSTRE_ENCRYPTION_UNIT_SIZE);
1984 stx.stx_size = body->mbo_size;
1985 stx.stx_blocks = body->mbo_blocks;
1986 stx.stx_atime.tv_sec = body->mbo_atime;
1987 stx.stx_ctime.tv_sec = body->mbo_ctime;
1988 stx.stx_mtime.tv_sec = body->mbo_mtime;
1989 stx.stx_btime.tv_sec = body->mbo_btime;
1990 stx.stx_rdev_major = MAJOR(body->mbo_rdev);
1991 stx.stx_rdev_minor = MINOR(body->mbo_rdev);
1992 stx.stx_dev_major = MAJOR(inode->i_sb->s_dev);
1993 stx.stx_dev_minor = MINOR(inode->i_sb->s_dev);
1994 stx.stx_mask |= STATX_BASIC_STATS | STATX_BTIME;
1997 * For a striped directory, the size and blocks returned
1998 * from MDT is not correct.
1999 * The size and blocks are aggregated by client across
2001 * Thus for a striped directory, do not return the valid
2002 * FLSIZE and FLBLOCKS flags to the caller.
2003 * However, this whould be better decided by the MDS
2004 * instead of the client.
2006 if (cmd == LL_IOC_MDC_GETINFO_V2 &&
2007 ll_i2info(inode)->lli_lsm_md != NULL)
2008 valid &= ~(OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
2010 if (flagsp && copy_to_user(flagsp, &valid,
2012 GOTO(out_req, rc = -EFAULT);
2014 if (fidp && copy_to_user(fidp, &body->mbo_fid1,
2016 GOTO(out_req, rc = -EFAULT);
2018 if (!(valid & OBD_MD_FLSIZE))
2019 stx.stx_mask &= ~STATX_SIZE;
2020 if (!(valid & OBD_MD_FLBLOCKS))
2021 stx.stx_mask &= ~STATX_BLOCKS;
2023 if (stxp && copy_to_user(stxp, &stx, sizeof(stx)))
2024 GOTO(out_req, rc = -EFAULT);
2026 if (lmmsizep && copy_to_user(lmmsizep, &lmmsize,
2028 GOTO(out_req, rc = -EFAULT);
2033 ptlrpc_req_finished(request);
2034 ptlrpc_req_finished(root_request);
2036 ll_putname(filename);
2039 case OBD_IOC_QUOTACTL: {
2040 struct if_quotactl *qctl;
2041 int qctl_len = sizeof(*qctl) + LOV_MAXPOOLNAME + 1;
2043 OBD_ALLOC(qctl, qctl_len);
2047 if (copy_from_user(qctl, uarg, sizeof(*qctl)))
2048 GOTO(out_quotactl, rc = -EFAULT);
2050 if (LUSTRE_Q_CMD_IS_POOL(qctl->qc_cmd)) {
2051 char __user *from = uarg +
2052 offsetof(typeof(*qctl), qc_poolname);
2053 if (copy_from_user(qctl->qc_poolname, from,
2054 LOV_MAXPOOLNAME + 1))
2055 GOTO(out_quotactl, rc = -EFAULT);
2058 rc = quotactl_ioctl(inode->i_sb, qctl);
2059 if ((rc == 0 || rc == -ENODATA) &&
2060 copy_to_user(uarg, qctl, sizeof(*qctl)))
2063 OBD_FREE(qctl, qctl_len);
2066 case LL_IOC_GETOBDCOUNT: {
2068 struct obd_export *exp;
2070 if (copy_from_user(&count, uarg, sizeof(count)))
2073 /* get ost count when count is zero, get mdt count otherwise */
2074 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
2075 vallen = sizeof(count);
2076 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
2077 KEY_TGT_COUNT, &vallen, &count);
2079 CERROR("%s: get target count failed: rc = %d\n",
2080 sbi->ll_fsname, rc);
2084 if (copy_to_user(uarg, &count, sizeof(count)))
2089 case LL_IOC_GET_CONNECT_FLAGS:
2090 RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL, uarg));
2091 case LL_IOC_FID2MDTIDX: {
2092 struct obd_export *exp = ll_i2mdexp(inode);
2096 if (copy_from_user(&fid, uarg, sizeof(fid)))
2099 /* Call mdc_iocontrol */
2100 rc = obd_iocontrol(LL_IOC_FID2MDTIDX, exp, sizeof(fid), &fid,
2101 (__u32 __user *)&index);
2107 case LL_IOC_HSM_REQUEST: {
2108 struct hsm_user_request *hur;
2115 /* We don't know the true size yet; copy the fixed-size part */
2116 if (copy_from_user(hur, uarg, sizeof(*hur))) {
2121 /* Compute the whole struct size */
2122 totalsize = hur_len(hur);
2127 /* Final size will be more than double totalsize */
2128 if (totalsize >= MDS_MAXREQSIZE / 3)
2131 OBD_ALLOC_LARGE(hur, totalsize);
2135 /* Copy the whole struct */
2136 if (copy_from_user(hur, uarg, totalsize))
2137 GOTO(out_hur, rc = -EFAULT);
2139 if (hur->hur_request.hr_action == HUA_RELEASE) {
2140 const struct lu_fid *fid;
2144 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
2145 fid = &hur->hur_user_item[i].hui_fid;
2146 f = search_inode_for_lustre(inode->i_sb, fid);
2152 rc = ll_hsm_release(f);
2158 rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
2162 OBD_FREE_LARGE(hur, totalsize);
2166 case LL_IOC_HSM_PROGRESS: {
2167 struct hsm_progress_kernel hpk;
2168 struct hsm_progress hp;
2170 if (copy_from_user(&hp, uarg, sizeof(hp)))
2173 hpk.hpk_fid = hp.hp_fid;
2174 hpk.hpk_cookie = hp.hp_cookie;
2175 hpk.hpk_extent = hp.hp_extent;
2176 hpk.hpk_flags = hp.hp_flags;
2177 hpk.hpk_errval = hp.hp_errval;
2178 hpk.hpk_data_version = 0;
2180 /* File may not exist in Lustre; all progress
2181 * reported to Lustre root */
2182 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
2186 case LL_IOC_HSM_CT_START:
2187 if (!capable(CAP_SYS_ADMIN))
2190 rc = copy_and_ct_start(cmd, sbi->ll_md_exp, uarg);
2193 case LL_IOC_HSM_COPY_START: {
2194 struct hsm_copy *copy;
2197 OBD_ALLOC_PTR(copy);
2200 if (copy_from_user(copy, uarg, sizeof(*copy))) {
2205 rc = ll_ioc_copy_start(inode->i_sb, copy);
2206 if (copy_to_user(uarg, copy, sizeof(*copy)))
2212 case LL_IOC_HSM_COPY_END: {
2213 struct hsm_copy *copy;
2216 OBD_ALLOC_PTR(copy);
2219 if (copy_from_user(copy, uarg, sizeof(*copy))) {
2224 rc = ll_ioc_copy_end(inode->i_sb, copy);
2225 if (copy_to_user(uarg, copy, sizeof(*copy)))
2231 case LL_IOC_MIGRATE: {
2232 struct lmv_user_md *lum;
2239 rc = obd_ioctl_getdata(&data, &len, uarg);
2243 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
2244 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
2245 GOTO(migrate_free, rc = -EINVAL);
2247 filename = data->ioc_inlbuf1;
2248 namelen = data->ioc_inllen1;
2249 flags = data->ioc_type;
2251 if (namelen < 1 || namelen != strlen(filename) + 1) {
2252 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
2253 GOTO(migrate_free, rc = -EINVAL);
2256 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
2257 if (lum->lum_magic != LMV_USER_MAGIC &&
2258 lum->lum_magic != LMV_USER_MAGIC_SPECIFIC) {
2260 CERROR("%s: wrong lum magic %x: rc = %d\n",
2261 filename, lum->lum_magic, rc);
2262 GOTO(migrate_free, rc);
2265 rc = ll_migrate(inode, file, lum, filename, flags);
2267 OBD_FREE_LARGE(data, len);
2271 case LL_IOC_PCC_DETACH_BY_FID: {
2272 struct lu_pcc_detach_fid *detach;
2274 struct inode *inode2;
2277 OBD_ALLOC_PTR(detach);
2281 if (copy_from_user(detach, uarg, sizeof(*detach)))
2282 GOTO(out_detach, rc = -EFAULT);
2284 fid = &detach->pccd_fid;
2285 ino = cl_fid_build_ino(fid, ll_need_32bit_api(sbi));
2286 inode2 = ilookup5(inode->i_sb, ino, ll_test_inode_by_fid, fid);
2288 /* Target inode is not in inode cache, and PCC file
2289 * has aleady released, return immdiately.
2291 GOTO(out_detach, rc = 0);
2293 if (!S_ISREG(inode2->i_mode))
2294 GOTO(out_iput, rc = -EINVAL);
2296 if (!inode_owner_or_capable(&init_user_ns, inode2))
2297 GOTO(out_iput, rc = -EPERM);
2299 rc = pcc_ioctl_detach(inode2, detach->pccd_opt);
2303 OBD_FREE_PTR(detach);
2307 rc = ll_iocontrol(inode, file, cmd, uarg);
2310 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL, uarg));
2314 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
2316 struct inode *inode = file->f_mapping->host;
2317 struct ll_file_data *fd = file->private_data;
2318 struct ll_sb_info *sbi = ll_i2sbi(inode);
2319 int api32 = ll_need_32bit_api(sbi);
2320 loff_t ret = -EINVAL;
2328 offset += file->f_pos;
2334 offset += LL_DIR_END_OFF_32BIT;
2336 offset += LL_DIR_END_OFF;
2343 ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
2344 (!api32 && offset <= LL_DIR_END_OFF))) {
2345 if (offset != file->f_pos) {
2348 hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
2349 if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
2350 (!api32 && offset == LL_DIR_END_OFF))
2351 fd->lfd_pos = MDS_DIR_END_OFF;
2352 else if (api32 && hash64)
2353 fd->lfd_pos = offset << 32;
2355 fd->lfd_pos = offset;
2356 file->f_pos = offset;
2357 file->f_version = 0;
2364 inode_unlock(inode);
2368 static int ll_dir_open(struct inode *inode, struct file *file)
2371 RETURN(ll_file_open(inode, file));
2374 static int ll_dir_release(struct inode *inode, struct file *file)
2377 RETURN(ll_file_release(inode, file));
2380 /* notify error if partially read striped directory */
2381 static int ll_dir_flush(struct file *file, fl_owner_t id)
2383 struct ll_file_data *lfd = file->private_data;
2384 int rc = lfd->fd_partial_readdir_rc;
2386 lfd->fd_partial_readdir_rc = 0;
2391 const struct file_operations ll_dir_operations = {
2392 .llseek = ll_dir_seek,
2393 .open = ll_dir_open,
2394 .release = ll_dir_release,
2395 .read = generic_read_dir,
2396 #ifdef HAVE_DIR_CONTEXT
2397 .iterate_shared = ll_iterate,
2399 .readdir = ll_readdir,
2401 .unlocked_ioctl = ll_dir_ioctl,
2403 .flush = ll_dir_flush,