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 !CFS_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,
550 &op_data->op_file_secctx_slot);
552 GOTO(out_op_data, err);
556 err = llcrypt_inherit_context(parent, NULL, op_data, false);
558 GOTO(out_op_data, err);
561 op_data->op_cli_flags |= CLI_SET_MEA;
563 op_data->op_bias |= MDS_SETSTRIPE_CREATE;
565 err = md_create(sbi->ll_md_exp, op_data, lump, len, mode,
566 from_kuid(&init_user_ns, current_fsuid()),
567 from_kgid(&init_user_ns, current_fsgid()),
568 current_cap(), 0, &request);
570 GOTO(out_request, err);
572 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_SETDIRSTRIPE_PAUSE, cfs_fail_val);
574 err = ll_prep_inode(&inode, &request->rq_pill, parent->i_sb, NULL);
576 GOTO(out_inode, err);
578 dentry.d_inode = inode;
580 if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags))
581 err = ll_inode_notifysecctx(inode, op_data->op_file_secctx,
582 op_data->op_file_secctx_size);
584 err = ll_inode_init_security(&dentry, inode, parent);
587 GOTO(out_inode, err);
590 err = ll_set_encflags(inode, op_data->op_file_encctx,
591 op_data->op_file_encctx_size, false);
593 GOTO(out_inode, err);
599 ptlrpc_req_finished(request);
601 ll_finish_md_op_data(op_data);
606 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
609 struct ll_sb_info *sbi = ll_i2sbi(inode);
610 struct md_op_data *op_data;
611 struct ptlrpc_request *req = NULL;
617 switch (lump->lmm_magic) {
618 case LOV_USER_MAGIC_V1:
619 lum_size = sizeof(struct lov_user_md_v1);
621 case LOV_USER_MAGIC_V3:
622 lum_size = sizeof(struct lov_user_md_v3);
624 case LOV_USER_MAGIC_COMP_V1:
625 lum_size = ((struct lov_comp_md_v1 *)lump)->lcm_size;
627 case LMV_USER_MAGIC: {
628 struct lmv_user_md *lmv = (struct lmv_user_md *)lump;
630 /* MDS < 2.14 doesn't support 'crush' hash type, and
631 * cannot handle unknown hash if client doesn't set a
632 * valid one. switch to fnv_1a_64.
634 if (!(exp_connect_flags2(sbi->ll_md_exp) &
635 OBD_CONNECT2_CRUSH)) {
636 enum lmv_hash_type type = lmv->lum_hash_type &
639 if (type >= LMV_HASH_TYPE_CRUSH ||
640 type == LMV_HASH_TYPE_UNKNOWN)
642 (lmv->lum_hash_type ^ type) |
643 LMV_HASH_TYPE_FNV_1A_64;
645 if (lmv->lum_magic != cpu_to_le32(LMV_USER_MAGIC))
646 lustre_swab_lmv_user_md(lmv);
647 lum_size = sizeof(*lmv);
650 case LOV_USER_MAGIC_SPECIFIC: {
651 struct lov_user_md_v3 *v3 =
652 (struct lov_user_md_v3 *)lump;
653 if (v3->lmm_stripe_count > LOV_MAX_STRIPE_COUNT)
655 lum_size = lov_user_md_size(v3->lmm_stripe_count,
656 LOV_USER_MAGIC_SPECIFIC);
660 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
661 " %#08x != %#08x nor %#08x\n",
662 lump->lmm_magic, LOV_USER_MAGIC_V1,
668 * This is coming from userspace, so should be in
669 * local endian. But the MDS would like it in little
670 * endian, so we swab it before we send it.
672 if ((__swab32(lump->lmm_magic) & le32_to_cpu(LOV_MAGIC_MASK)) ==
673 le32_to_cpu(LOV_MAGIC_MAGIC))
674 lustre_swab_lov_user_md(lump, 0);
676 lum_size = sizeof(struct lov_user_md_v1);
679 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
680 LUSTRE_OPC_ANY, NULL);
682 RETURN(PTR_ERR(op_data));
684 /* swabbing is done in lov_setstripe() on server side */
685 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size, &req);
686 ll_finish_md_op_data(op_data);
687 ptlrpc_req_finished(req);
694 /* get default LMV from client cache */
695 static int ll_dir_get_default_lmv(struct inode *inode, struct lmv_user_md *lum)
697 struct ll_inode_info *lli = ll_i2info(inode);
698 const struct lmv_stripe_md *lsm;
699 bool fs_dmv_got = false;
704 if (lli->lli_default_lsm_md) {
705 down_read(&lli->lli_lsm_sem);
706 lsm = lli->lli_default_lsm_md;
708 lum->lum_magic = lsm->lsm_md_magic;
709 lum->lum_stripe_count = lsm->lsm_md_stripe_count;
710 lum->lum_stripe_offset = lsm->lsm_md_master_mdt_index;
711 lum->lum_hash_type = lsm->lsm_md_hash_type;
712 lum->lum_max_inherit = lsm->lsm_md_max_inherit;
713 lum->lum_max_inherit_rr = lsm->lsm_md_max_inherit_rr;
716 up_read(&lli->lli_lsm_sem);
719 if (rc == -ENODATA && !is_root_inode(inode) && !fs_dmv_got) {
720 lli = ll_i2info(inode->i_sb->s_root->d_inode);
725 if (!rc && fs_dmv_got) {
726 lli = ll_i2info(inode);
727 if (lum->lum_max_inherit != LMV_INHERIT_UNLIMITED) {
728 if (lum->lum_max_inherit == LMV_INHERIT_NONE ||
729 lum->lum_max_inherit < LMV_INHERIT_END ||
730 lum->lum_max_inherit > LMV_INHERIT_MAX ||
731 lum->lum_max_inherit <= lli->lli_dir_depth)
732 GOTO(out, rc = -ENODATA);
734 lum->lum_max_inherit -= lli->lli_dir_depth;
737 if (lum->lum_max_inherit_rr != LMV_INHERIT_RR_UNLIMITED) {
738 if (lum->lum_max_inherit_rr == LMV_INHERIT_NONE ||
739 lum->lum_max_inherit_rr < LMV_INHERIT_RR_END ||
740 lum->lum_max_inherit_rr > LMV_INHERIT_RR_MAX ||
741 lum->lum_max_inherit_rr <= lli->lli_dir_depth)
742 lum->lum_max_inherit_rr = LMV_INHERIT_RR_NONE;
744 if (lum->lum_max_inherit_rr > lli->lli_dir_depth)
745 lum->lum_max_inherit_rr -= lli->lli_dir_depth;
752 int ll_dir_get_default_layout(struct inode *inode, void **plmm, int *plmm_size,
753 struct ptlrpc_request **request, u64 valid,
754 enum get_default_layout_type type)
756 struct ll_sb_info *sbi = ll_i2sbi(inode);
757 struct mdt_body *body;
758 struct lov_mds_md *lmm = NULL;
759 struct ptlrpc_request *req = NULL;
760 int lmm_size = OBD_MAX_DEFAULT_EA_SIZE;
761 struct md_op_data *op_data;
767 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, lmm_size,
768 LUSTRE_OPC_ANY, NULL);
770 RETURN(PTR_ERR(op_data));
772 op_data->op_valid = valid | OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
774 if (type == GET_DEFAULT_LAYOUT_ROOT) {
775 lu_root_fid(&op_data->op_fid1);
776 fid = op_data->op_fid1;
778 fid = *ll_inode2fid(inode);
781 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
782 ll_finish_md_op_data(op_data);
784 CDEBUG(D_INFO, "md_getattr failed on inode "DFID": rc %d\n",
789 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
790 LASSERT(body != NULL);
792 lmm_size = body->mbo_eadatasize;
794 if (!(body->mbo_valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
796 GOTO(out, rc = -ENODATA);
799 lmm = req_capsule_server_sized_get(&req->rq_pill,
800 &RMF_MDT_MD, lmm_size);
801 LASSERT(lmm != NULL);
804 * This is coming from the MDS, so is probably in
805 * little endian. We convert it to host endian before
806 * passing it to userspace.
808 /* We don't swab objects for directories */
809 switch (le32_to_cpu(lmm->lmm_magic)) {
812 case LOV_MAGIC_COMP_V1:
813 case LOV_USER_MAGIC_SPECIFIC:
814 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
815 lustre_swab_lov_user_md((struct lov_user_md *)lmm, 0);
818 if (LMV_MAGIC != cpu_to_le32(LMV_MAGIC))
819 lustre_swab_lmv_mds_md((union lmv_mds_md *)lmm);
822 if (LMV_USER_MAGIC != cpu_to_le32(LMV_USER_MAGIC))
823 lustre_swab_lmv_user_md((struct lmv_user_md *)lmm);
825 case LMV_MAGIC_FOREIGN: {
826 struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)lmm;
828 if (LMV_MAGIC_FOREIGN != cpu_to_le32(LMV_MAGIC_FOREIGN)) {
829 __swab32s(&lfm->lfm_magic);
830 __swab32s(&lfm->lfm_length);
831 __swab32s(&lfm->lfm_type);
832 __swab32s(&lfm->lfm_flags);
837 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
842 *plmm_size = lmm_size;
848 * This function will be used to get default LOV/LMV/Default LMV
849 * @valid will be used to indicate which stripe it will retrieve.
850 * If the directory does not have its own default layout, then the
851 * function will request the default layout from root FID.
852 * OBD_MD_MEA LMV stripe EA
853 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
854 * otherwise Default LOV EA.
855 * Each time, it can only retrieve 1 stripe EA
857 int ll_dir_getstripe_default(struct inode *inode, void **plmm, int *plmm_size,
858 struct ptlrpc_request **request,
859 struct ptlrpc_request **root_request,
862 struct ptlrpc_request *req = NULL;
863 struct ptlrpc_request *root_req = NULL;
864 struct lov_mds_md *lmm = NULL;
869 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
871 if (rc == -ENODATA && !fid_is_root(ll_inode2fid(inode)) &&
872 !(valid & OBD_MD_MEA) && root_request != NULL) {
873 int rc2 = ll_dir_get_default_layout(inode, (void **)&lmm,
874 &lmm_size, &root_req, valid,
875 GET_DEFAULT_LAYOUT_ROOT);
881 *plmm_size = lmm_size;
883 if (root_request != NULL)
884 *root_request = root_req;
890 * This function will be used to get default LOV/LMV/Default LMV
891 * @valid will be used to indicate which stripe it will retrieve
892 * OBD_MD_MEA LMV stripe EA
893 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
894 * otherwise Default LOV EA.
895 * Each time, it can only retrieve 1 stripe EA
897 int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
898 struct ptlrpc_request **request, u64 valid)
900 struct ptlrpc_request *req = NULL;
901 struct lov_mds_md *lmm = NULL;
906 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
910 *plmm_size = lmm_size;
916 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid)
918 struct md_op_data *op_data;
923 OBD_ALLOC_PTR(op_data);
927 op_data->op_flags |= MF_GET_MDT_IDX;
928 op_data->op_fid1 = *fid;
929 rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
930 mdt_index = op_data->op_mds;
931 OBD_FREE_PTR(op_data);
939 * Get MDT index for the inode.
941 int ll_get_mdt_idx(struct inode *inode)
943 return ll_get_mdt_idx_by_fid(ll_i2sbi(inode), ll_inode2fid(inode));
947 * Generic handler to do any pre-copy work.
949 * It sends a first hsm_progress (with extent length == 0) to coordinator as a
950 * first information for it that real work has started.
952 * Moreover, for a ARCHIVE request, it will sample the file data version and
953 * store it in \a copy.
955 * \return 0 on success.
957 static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
959 struct ll_sb_info *sbi = ll_s2sbi(sb);
960 struct hsm_progress_kernel hpk;
965 /* Forge a hsm_progress based on data from copy. */
966 hpk.hpk_fid = copy->hc_hai.hai_fid;
967 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
968 hpk.hpk_extent.offset = copy->hc_hai.hai_extent.offset;
969 hpk.hpk_extent.length = 0;
972 hpk.hpk_data_version = 0;
975 /* For archive request, we need to read the current file version. */
976 if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
978 __u64 data_version = 0;
980 /* Get inode for this fid */
981 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
983 hpk.hpk_flags |= HP_FLAG_RETRY;
984 /* hpk_errval is >= 0 */
985 hpk.hpk_errval = -PTR_ERR(inode);
986 GOTO(progress, rc = PTR_ERR(inode));
989 /* Read current file data version */
990 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
993 CDEBUG(D_HSM, "Could not read file data version of "
994 DFID" (rc = %d). Archive request ("
995 "%#llx) could not be done.\n",
996 PFID(©->hc_hai.hai_fid), rc,
997 copy->hc_hai.hai_cookie);
998 hpk.hpk_flags |= HP_FLAG_RETRY;
999 /* hpk_errval must be >= 0 */
1000 hpk.hpk_errval = -rc;
1004 /* Store in the hsm_copy for later copytool use.
1005 * Always modified even if no lsm. */
1006 copy->hc_data_version = data_version;
1010 /* On error, the request should be considered as completed */
1011 if (hpk.hpk_errval > 0)
1012 hpk.hpk_flags |= HP_FLAG_COMPLETED;
1014 rc2 = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
1017 /* Return first error */
1018 RETURN(rc != 0 ? rc : rc2);
1022 * Generic handler to do any post-copy work.
1024 * It will send the last hsm_progress update to coordinator to inform it
1025 * that copy is finished and whether it was successful or not.
1028 * - for ARCHIVE request, it will sample the file data version and compare it
1029 * with the version saved in ll_ioc_copy_start(). If they do not match, copy
1030 * will be considered as failed.
1031 * - for RESTORE request, it will sample the file data version and send it to
1032 * coordinator which is useful if the file was imported as 'released'.
1034 * \return 0 on success.
1036 static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
1038 struct ll_sb_info *sbi = ll_s2sbi(sb);
1039 struct hsm_progress_kernel hpk;
1044 /* If you modify the logic here, also check llapi_hsm_copy_end(). */
1045 /* Take care: copy->hc_hai.hai_action, len, gid and data are not
1046 * initialized if copy_end was called with copy == NULL.
1049 /* Forge a hsm_progress based on data from copy. */
1050 hpk.hpk_fid = copy->hc_hai.hai_fid;
1051 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
1052 hpk.hpk_extent = copy->hc_hai.hai_extent;
1053 hpk.hpk_flags = copy->hc_flags | HP_FLAG_COMPLETED;
1054 hpk.hpk_errval = copy->hc_errval;
1055 hpk.hpk_data_version = 0;
1057 /* For archive request, we need to check the file data was not changed.
1059 * For restore request, we need to send the file data version, this is
1060 * useful when the file was created using hsm_import.
1062 if (((copy->hc_hai.hai_action == HSMA_ARCHIVE) ||
1063 (copy->hc_hai.hai_action == HSMA_RESTORE)) &&
1064 (copy->hc_errval == 0)) {
1065 struct inode *inode;
1066 __u64 data_version = 0;
1068 /* Get lsm for this fid */
1069 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
1070 if (IS_ERR(inode)) {
1071 hpk.hpk_flags |= HP_FLAG_RETRY;
1072 /* hpk_errval must be >= 0 */
1073 hpk.hpk_errval = -PTR_ERR(inode);
1074 GOTO(progress, rc = PTR_ERR(inode));
1077 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
1080 CDEBUG(D_HSM, "Could not read file data version. "
1081 "Request could not be confirmed.\n");
1082 if (hpk.hpk_errval == 0)
1083 hpk.hpk_errval = -rc;
1087 /* Store in the hsm_copy for later copytool use.
1088 * Always modified even if no lsm. */
1089 hpk.hpk_data_version = data_version;
1091 /* File could have been stripped during archiving, so we need
1092 * to check anyway. */
1093 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
1094 (copy->hc_data_version != data_version)) {
1095 CDEBUG(D_HSM, "File data version mismatched. "
1096 "File content was changed during archiving. "
1097 DFID", start:%#llx current:%#llx\n",
1098 PFID(©->hc_hai.hai_fid),
1099 copy->hc_data_version, data_version);
1100 /* File was changed, send error to cdt. Do not ask for
1101 * retry because if a file is modified frequently,
1102 * the cdt will loop on retried archive requests.
1103 * The policy engine will ask for a new archive later
1104 * when the file will not be modified for some tunable
1106 hpk.hpk_flags &= ~HP_FLAG_RETRY;
1108 /* hpk_errval must be >= 0 */
1109 hpk.hpk_errval = -rc;
1116 rc2 = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
1119 /* Return first error */
1120 RETURN(rc != 0 ? rc : rc2);
1124 static int copy_and_ct_start(int cmd, struct obd_export *exp,
1125 const struct lustre_kernelcomm __user *data)
1127 struct lustre_kernelcomm *lk;
1128 struct lustre_kernelcomm *tmp;
1129 size_t size = sizeof(*lk);
1134 /* copy data from userspace to get numbers of archive_id */
1135 OBD_ALLOC(lk, size);
1139 if (copy_from_user(lk, data, size))
1140 GOTO(out_lk, rc = -EFAULT);
1142 if (lk->lk_flags & LK_FLG_STOP)
1145 if (!(lk->lk_flags & LK_FLG_DATANR)) {
1146 __u32 archive_mask = lk->lk_data_count;
1149 /* old hsm agent to old MDS */
1150 if (!exp_connect_archive_id_array(exp))
1153 /* old hsm agent to new MDS */
1154 lk->lk_flags |= LK_FLG_DATANR;
1156 if (archive_mask == 0)
1159 count = hweight32(archive_mask);
1160 new_size = offsetof(struct lustre_kernelcomm, lk_data[count]);
1161 OBD_ALLOC(tmp, new_size);
1163 GOTO(out_lk, rc = -ENOMEM);
1165 memcpy(tmp, lk, size);
1166 tmp->lk_data_count = count;
1172 for (i = 0; i < sizeof(archive_mask) * 8; i++) {
1173 if (BIT(i) & archive_mask) {
1174 lk->lk_data[count] = i + 1;
1181 /* new hsm agent to new mds */
1182 if (lk->lk_data_count > 0) {
1183 new_size = offsetof(struct lustre_kernelcomm,
1184 lk_data[lk->lk_data_count]);
1185 OBD_ALLOC(tmp, new_size);
1187 GOTO(out_lk, rc = -ENOMEM);
1193 if (copy_from_user(lk, data, size))
1194 GOTO(out_lk, rc = -EFAULT);
1197 /* new hsm agent to old MDS */
1198 if (!exp_connect_archive_id_array(exp)) {
1201 if (lk->lk_data_count > LL_HSM_ORIGIN_MAX_ARCHIVE)
1202 GOTO(out_lk, rc = -EINVAL);
1204 for (i = 0; i < lk->lk_data_count; i++) {
1205 if (lk->lk_data[i] > LL_HSM_ORIGIN_MAX_ARCHIVE) {
1207 CERROR("%s: archive id %d requested but only "
1208 "[0 - %zu] supported: rc = %d\n",
1209 exp->exp_obd->obd_name, lk->lk_data[i],
1210 LL_HSM_ORIGIN_MAX_ARCHIVE, rc);
1214 if (lk->lk_data[i] == 0) {
1219 archives |= (1 << (lk->lk_data[i] - 1));
1221 lk->lk_flags &= ~LK_FLG_DATANR;
1222 lk->lk_data_count = archives;
1225 rc = obd_iocontrol(cmd, exp, size, lk, NULL);
1231 static int check_owner(int type, int id)
1235 if (!uid_eq(current_euid(), make_kuid(&init_user_ns, id)))
1239 if (!in_egroup_p(make_kgid(&init_user_ns, id)))
1248 int quotactl_ioctl(struct super_block *sb, struct if_quotactl *qctl)
1250 struct ll_sb_info *sbi = ll_s2sbi(sb);
1251 int cmd = qctl->qc_cmd;
1252 int type = qctl->qc_type;
1253 int id = qctl->qc_id;
1254 int valid = qctl->qc_valid;
1262 case LUSTRE_Q_SETDEFAULT:
1263 case LUSTRE_Q_SETQUOTAPOOL:
1264 case LUSTRE_Q_SETINFOPOOL:
1265 case LUSTRE_Q_SETDEFAULT_POOL:
1266 case LUSTRE_Q_DELETEQID:
1267 case LUSTRE_Q_RESETQID:
1268 if (!capable(CAP_SYS_ADMIN))
1271 if (sb->s_flags & SB_RDONLY)
1275 case LUSTRE_Q_GETDEFAULT:
1276 case LUSTRE_Q_GETQUOTAPOOL:
1277 case LUSTRE_Q_GETDEFAULT_POOL:
1278 if (check_owner(type, id) &&
1279 (!capable(CAP_SYS_ADMIN)))
1283 case LUSTRE_Q_GETINFOPOOL:
1286 CERROR("unsupported quotactl op: %#x\n", cmd);
1290 if (valid != QC_GENERAL) {
1291 if (cmd == Q_GETINFO)
1292 qctl->qc_cmd = Q_GETOINFO;
1293 else if (cmd == Q_GETQUOTA ||
1294 cmd == LUSTRE_Q_GETQUOTAPOOL)
1295 qctl->qc_cmd = Q_GETOQUOTA;
1301 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
1302 sizeof(*qctl), qctl, NULL);
1305 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
1306 sizeof(*qctl), qctl, NULL);
1309 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
1310 sizeof(*qctl), qctl, NULL);
1312 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1314 sizeof(*qctl), qctl, NULL);
1325 struct obd_quotactl *oqctl;
1326 int oqctl_len = sizeof(*oqctl);
1328 if (LUSTRE_Q_CMD_IS_POOL(cmd))
1329 oqctl_len += LOV_MAXPOOLNAME + 1;
1331 OBD_ALLOC(oqctl, oqctl_len);
1335 QCTL_COPY(oqctl, qctl);
1336 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1338 OBD_FREE(oqctl, oqctl_len);
1341 /* If QIF_SPACE is not set, client should collect the
1342 * space usage from OSSs by itself */
1343 if ((cmd == Q_GETQUOTA || cmd == LUSTRE_Q_GETQUOTAPOOL) &&
1344 !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
1345 !oqctl->qc_dqblk.dqb_curspace) {
1346 struct obd_quotactl *oqctl_tmp;
1347 int qctl_len = sizeof(*oqctl_tmp) + LOV_MAXPOOLNAME + 1;
1349 OBD_ALLOC(oqctl_tmp, qctl_len);
1350 if (oqctl_tmp == NULL)
1351 GOTO(out, rc = -ENOMEM);
1353 if (cmd == LUSTRE_Q_GETQUOTAPOOL) {
1354 oqctl_tmp->qc_cmd = LUSTRE_Q_GETQUOTAPOOL;
1355 memcpy(oqctl_tmp->qc_poolname,
1357 LOV_MAXPOOLNAME + 1);
1359 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1361 oqctl_tmp->qc_id = oqctl->qc_id;
1362 oqctl_tmp->qc_type = oqctl->qc_type;
1364 /* collect space usage from OSTs */
1365 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1366 rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
1367 if (!rc || rc == -EREMOTEIO) {
1368 oqctl->qc_dqblk.dqb_curspace =
1369 oqctl_tmp->qc_dqblk.dqb_curspace;
1370 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
1373 /* collect space & inode usage from MDTs */
1374 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1375 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1376 oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
1377 rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
1378 if (!rc || rc == -EREMOTEIO) {
1379 oqctl->qc_dqblk.dqb_curspace +=
1380 oqctl_tmp->qc_dqblk.dqb_curspace;
1381 oqctl->qc_dqblk.dqb_curinodes =
1382 oqctl_tmp->qc_dqblk.dqb_curinodes;
1383 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
1385 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
1388 OBD_FREE(oqctl_tmp, qctl_len);
1391 QCTL_COPY(qctl, oqctl);
1392 OBD_FREE(oqctl, oqctl_len);
1398 int ll_rmfid(struct file *file, void __user *arg)
1400 const struct fid_array __user *ufa = arg;
1401 struct inode *inode = file_inode(file);
1402 struct ll_sb_info *sbi = ll_i2sbi(inode);
1403 struct fid_array *lfa = NULL;
1406 int i, rc, *rcs = NULL;
1409 if (!capable(CAP_DAC_READ_SEARCH) &&
1410 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
1412 /* Only need to get the buflen */
1413 if (get_user(nr, &ufa->fa_nr))
1415 /* DoS protection */
1416 if (nr > OBD_MAX_FIDS_IN_ARRAY)
1419 size = offsetof(struct fid_array, fa_fids[nr]);
1420 OBD_ALLOC(lfa, size);
1423 OBD_ALLOC_PTR_ARRAY(rcs, nr);
1425 GOTO(free_lfa, rc = -ENOMEM);
1427 if (copy_from_user(lfa, arg, size))
1428 GOTO(free_rcs, rc = -EFAULT);
1430 /* In case of subdirectory mount, we need to make sure all the files
1431 * for which we want to remove FID are visible in the namespace.
1433 if (!fid_is_root(&sbi->ll_root_fid)) {
1434 struct fid_array *lfa_new = NULL;
1435 int path_len = PATH_MAX, linkno;
1436 struct getinfo_fid2path *gf;
1437 int idx, last_idx = nr - 1;
1439 OBD_ALLOC(lfa_new, size);
1441 GOTO(free_rcs, rc = -ENOMEM);
1444 gf = kmalloc(sizeof(*gf) + path_len + 1, GFP_NOFS);
1446 GOTO(free_rcs, rc = -ENOMEM);
1448 for (idx = 0; idx < nr; idx++) {
1451 memset(gf, 0, sizeof(*gf) + path_len + 1);
1452 gf->gf_fid = lfa->fa_fids[idx];
1453 gf->gf_pathlen = path_len;
1454 gf->gf_linkno = linkno;
1455 rc = __ll_fid2path(inode, gf,
1456 sizeof(*gf) + gf->gf_pathlen,
1458 if (rc == -ENAMETOOLONG) {
1459 struct getinfo_fid2path *tmpgf;
1461 path_len += PATH_MAX;
1462 tmpgf = krealloc(gf,
1463 sizeof(*gf) + path_len + 1,
1467 OBD_FREE(lfa_new, size);
1468 GOTO(free_rcs, rc = -ENOMEM);
1475 if (gf->gf_linkno == linkno)
1477 linkno = gf->gf_linkno;
1481 /* All the links for this fid are visible in the
1482 * mounted subdir. So add it to the list of fids
1485 lfa_new->fa_fids[lfa_new->fa_nr++] =
1488 /* At least one link for this fid is not visible
1489 * in the mounted subdir. So add it at the end
1490 * of the list that will be hidden to lower
1491 * layers, and set -ENOENT as ret code.
1493 lfa_new->fa_fids[last_idx] = lfa->fa_fids[idx];
1494 rcs[last_idx--] = rc;
1498 OBD_FREE(lfa, size);
1502 if (lfa->fa_nr == 0)
1503 GOTO(free_rcs, rc = rcs[nr - 1]);
1505 /* Call mdc_iocontrol */
1506 rc = md_rmfid(ll_i2mdexp(file_inode(file)), lfa, rcs, NULL);
1509 for (i = 0; i < nr; i++)
1511 lfa->fa_fids[i].f_ver = rcs[i];
1512 if (copy_to_user(arg, lfa, size))
1517 OBD_FREE_PTR_ARRAY(rcs, nr);
1519 OBD_FREE(lfa, size);
1524 /* This function tries to get a single name component,
1525 * to send to the server. No actual path traversal involved,
1526 * so we limit to NAME_MAX */
1527 static char *ll_getname(const char __user *filename)
1532 OBD_ALLOC(tmp, NAME_MAX + 1);
1535 return ERR_PTR(-ENOMEM);
1537 len = strncpy_from_user(tmp, filename, NAME_MAX + 1);
1540 else if (len > NAME_MAX)
1541 ret = -ENAMETOOLONG;
1544 OBD_FREE(tmp, NAME_MAX + 1);
1550 #define ll_putname(filename) OBD_FREE(filename, NAME_MAX + 1);
1552 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1554 struct dentry *dentry = file_dentry(file);
1555 struct inode *inode = file_inode(file);
1556 struct ll_sb_info *sbi = ll_i2sbi(inode);
1557 struct obd_ioctl_data *data = NULL;
1558 void __user *uarg = (void __user *)arg;
1562 CDEBUG(D_VFSTRACE|D_IOCTL, "VFS Op:inode="DFID"(%pK) cmd=%x arg=%lx\n",
1563 PFID(ll_inode2fid(inode)), inode, cmd, arg);
1565 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
1566 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
1569 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
1571 case IOC_MDC_LOOKUP: {
1572 int namelen, len = 0;
1575 rc = obd_ioctl_getdata(&data, &len, uarg);
1579 filename = data->ioc_inlbuf1;
1580 namelen = strlen(filename);
1582 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1583 GOTO(out_free, rc = -EINVAL);
1586 rc = ll_get_fid_by_name(inode, filename, namelen, NULL, NULL);
1588 CERROR("%s: lookup %.*s failed: rc = %d\n",
1589 sbi->ll_fsname, namelen, filename, rc);
1593 OBD_FREE_LARGE(data, len);
1596 case LL_IOC_LMV_SETSTRIPE: {
1597 struct lmv_user_md *lum;
1602 bool createonly = false;
1606 rc = obd_ioctl_getdata(&data, &len, uarg);
1610 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1611 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1612 GOTO(lmv_out_free, rc = -EINVAL);
1614 filename = data->ioc_inlbuf1;
1615 namelen = data->ioc_inllen1;
1618 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1619 GOTO(lmv_out_free, rc = -EINVAL);
1621 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1622 lumlen = data->ioc_inllen2;
1624 if (!lmv_user_magic_supported(lum->lum_magic)) {
1625 CERROR("%s: wrong lum magic %x : rc = %d\n", filename,
1626 lum->lum_magic, -EINVAL);
1627 GOTO(lmv_out_free, rc = -EINVAL);
1630 if ((lum->lum_magic == LMV_USER_MAGIC ||
1631 lum->lum_magic == LMV_USER_MAGIC_SPECIFIC) &&
1632 lumlen < sizeof(*lum)) {
1633 CERROR("%s: wrong lum size %d for magic %x : rc = %d\n",
1634 filename, lumlen, lum->lum_magic, -EINVAL);
1635 GOTO(lmv_out_free, rc = -EINVAL);
1638 if (lum->lum_magic == LMV_MAGIC_FOREIGN &&
1639 lumlen < sizeof(struct lmv_foreign_md)) {
1640 CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1641 filename, lum->lum_magic, lumlen, -EFAULT);
1642 GOTO(lmv_out_free, rc = -EINVAL);
1645 mode = data->ioc_type;
1646 createonly = data->ioc_obdo1.o_flags & OBD_FL_OBDMDEXISTS;
1647 rc = ll_dir_setdirstripe(dentry, lum, lumlen, filename, mode,
1650 OBD_FREE_LARGE(data, len);
1654 case LL_IOC_LMV_SET_DEFAULT_STRIPE: {
1655 struct lmv_user_md lum;
1656 struct lmv_user_md __user *ulump = uarg;
1659 if (copy_from_user(&lum, ulump, sizeof(lum)))
1662 if (lum.lum_magic != LMV_USER_MAGIC)
1665 rc = ll_dir_setstripe(inode, (struct lov_user_md *)&lum, 0);
1669 case LL_IOC_LOV_SETSTRIPE_NEW:
1670 case LL_IOC_LOV_SETSTRIPE: {
1671 struct lov_user_md_v3 *lumv3 = NULL;
1672 struct lov_user_md_v1 lumv1;
1673 struct lov_user_md_v1 *lumv1_ptr = &lumv1;
1674 struct lov_user_md_v1 __user *lumv1p = uarg;
1675 struct lov_user_md_v3 __user *lumv3p = uarg;
1677 int set_default = 0;
1679 BUILD_BUG_ON(sizeof(struct lov_user_md_v3) <=
1680 sizeof(struct lov_comp_md_v1));
1681 BUILD_BUG_ON(sizeof(*lumv3) != sizeof(*lumv3p));
1682 /* first try with v1 which is smaller than v3 */
1683 if (copy_from_user(&lumv1, lumv1p, sizeof(lumv1)))
1686 if (is_root_inode(inode))
1689 switch (lumv1.lmm_magic) {
1690 case LOV_USER_MAGIC_V3:
1691 case LOV_USER_MAGIC_SPECIFIC:
1692 lum_size = ll_lov_user_md_size(&lumv1);
1695 OBD_ALLOC(lumv3, lum_size);
1698 if (copy_from_user(lumv3, lumv3p, lum_size))
1699 GOTO(out, rc = -EFAULT);
1700 lumv1_ptr = (struct lov_user_md_v1 *)lumv3;
1702 case LOV_USER_MAGIC_V1:
1705 GOTO(out, rc = -ENOTSUPP);
1708 /* in v1 and v3 cases lumv1 points to data */
1709 rc = ll_dir_setstripe(inode, lumv1_ptr, set_default);
1712 OBD_FREE(lumv3, lum_size);
1715 case LL_IOC_LMV_GETSTRIPE: {
1716 struct lmv_user_md __user *ulmv = uarg;
1717 struct lmv_user_md lum;
1718 struct ptlrpc_request *request = NULL;
1719 union lmv_mds_md *lmm = NULL;
1722 struct lmv_user_md *tmp = NULL;
1726 int max_stripe_count;
1730 if (copy_from_user(&lum, ulmv, sizeof(*ulmv)))
1733 /* get default LMV */
1734 if (lum.lum_magic == LMV_USER_MAGIC &&
1735 lum.lum_type != LMV_TYPE_RAW) {
1736 rc = ll_dir_get_default_lmv(inode, &lum);
1740 if (copy_to_user(ulmv, &lum, sizeof(lum)))
1746 max_stripe_count = lum.lum_stripe_count;
1747 /* lum_magic will indicate which stripe the ioctl will like
1748 * to get, LMV_MAGIC_V1 is for normal LMV stripe, LMV_USER_MAGIC
1749 * is for default LMV stripe */
1750 if (lum.lum_magic == LMV_MAGIC_V1)
1751 valid |= OBD_MD_MEA;
1752 else if (lum.lum_magic == LMV_USER_MAGIC)
1753 valid |= OBD_MD_DEFAULT_MEA;
1757 rc = ll_dir_getstripe_default(inode, (void **)&lmm, &lmmsize,
1758 &request, NULL, valid);
1760 GOTO(finish_req, rc);
1762 /* get default LMV in raw mode */
1763 if (lum.lum_magic == LMV_USER_MAGIC) {
1764 if (copy_to_user(ulmv, lmm, lmmsize))
1765 GOTO(finish_req, rc = -EFAULT);
1766 GOTO(finish_req, rc);
1769 /* if foreign LMV case, fake stripes number */
1770 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1771 struct lmv_foreign_md *lfm;
1773 lfm = (struct lmv_foreign_md *)lmm;
1774 if (lfm->lfm_length < XATTR_SIZE_MAX -
1775 offsetof(typeof(*lfm), lfm_value)) {
1776 __u32 size = lfm->lfm_length +
1777 offsetof(typeof(*lfm), lfm_value);
1779 stripe_count = lmv_foreign_to_md_stripes(size);
1781 CERROR("invalid %d foreign size returned\n",
1786 stripe_count = lmv_mds_md_stripe_count_get(lmm);
1788 if (max_stripe_count < stripe_count) {
1789 lum.lum_stripe_count = stripe_count;
1790 if (copy_to_user(ulmv, &lum, sizeof(lum)))
1791 GOTO(finish_req, rc = -EFAULT);
1792 GOTO(finish_req, rc = -E2BIG);
1795 /* enough room on user side and foreign case */
1796 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1797 struct lmv_foreign_md *lfm;
1800 lfm = (struct lmv_foreign_md *)lmm;
1801 size = lfm->lfm_length +
1802 offsetof(struct lmv_foreign_md, lfm_value);
1803 if (copy_to_user(ulmv, lfm, size))
1804 GOTO(finish_req, rc = -EFAULT);
1805 GOTO(finish_req, rc);
1808 lum_size = lmv_user_md_size(stripe_count,
1809 LMV_USER_MAGIC_SPECIFIC);
1810 OBD_ALLOC(tmp, lum_size);
1812 GOTO(finish_req, rc = -ENOMEM);
1814 mdt_index = ll_get_mdt_idx(inode);
1816 GOTO(out_tmp, rc = -ENOMEM);
1818 tmp->lum_magic = LMV_MAGIC_V1;
1819 tmp->lum_stripe_count = 0;
1820 tmp->lum_stripe_offset = mdt_index;
1821 tmp->lum_hash_type = lmv_mds_md_hash_type_get(lmm);
1822 for (i = 0; i < stripe_count; i++) {
1825 fid_le_to_cpu(&fid, &lmm->lmv_md_v1.lmv_stripe_fids[i]);
1826 if (fid_is_sane(&fid)) {
1827 mdt_index = ll_get_mdt_idx_by_fid(sbi, &fid);
1829 GOTO(out_tmp, rc = mdt_index);
1831 tmp->lum_objects[i].lum_mds = mdt_index;
1832 tmp->lum_objects[i].lum_fid = fid;
1835 tmp->lum_stripe_count++;
1838 if (copy_to_user(ulmv, tmp, lum_size))
1839 GOTO(out_tmp, rc = -EFAULT);
1841 OBD_FREE(tmp, lum_size);
1843 ptlrpc_req_finished(request);
1846 case LL_IOC_REMOVE_ENTRY: {
1847 char *filename = NULL;
1851 /* Here is a little hack to avoid sending REINT_RMENTRY to
1852 * unsupported server, which might crash the server(LU-2730),
1853 * Because both LVB_TYPE and REINT_RMENTRY will be supported
1854 * on 2.4, we use OBD_CONNECT_LVB_TYPE to detect whether the
1855 * server will support REINT_RMENTRY XXX*/
1856 if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE))
1859 filename = ll_getname(uarg);
1860 if (IS_ERR(filename))
1861 RETURN(PTR_ERR(filename));
1863 namelen = strlen(filename);
1865 GOTO(out_rmdir, rc = -EINVAL);
1867 rc = ll_rmdir_entry(inode, filename, namelen);
1870 ll_putname(filename);
1874 RETURN(ll_rmfid(file, uarg));
1875 case LL_IOC_LOV_SWAP_LAYOUTS:
1877 case LL_IOC_LOV_GETSTRIPE:
1878 case LL_IOC_LOV_GETSTRIPE_NEW:
1879 case LL_IOC_MDC_GETINFO_V1:
1880 case LL_IOC_MDC_GETINFO_V2:
1881 case IOC_MDC_GETFILEINFO_V1:
1882 case IOC_MDC_GETFILEINFO_V2:
1883 case IOC_MDC_GETFILESTRIPE: {
1884 struct ptlrpc_request *request = NULL;
1885 struct ptlrpc_request *root_request = NULL;
1886 struct lov_user_md __user *lump;
1887 struct lov_mds_md *lmm = NULL;
1888 struct mdt_body *body;
1889 char *filename = NULL;
1890 lstat_t __user *statp = NULL;
1891 lstatx_t __user *stxp = NULL;
1892 __u64 __user *flagsp = NULL;
1893 __u32 __user *lmmsizep = NULL;
1894 struct lu_fid __user *fidp = NULL;
1898 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1899 cmd == IOC_MDC_GETFILEINFO_V2 ||
1900 cmd == IOC_MDC_GETFILESTRIPE) {
1901 filename = ll_getname(uarg);
1902 if (IS_ERR(filename))
1903 RETURN(PTR_ERR(filename));
1905 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1906 &lmmsize, &request);
1908 rc = ll_dir_getstripe_default(inode, (void **)&lmm,
1914 body = req_capsule_server_get(&request->rq_pill,
1916 LASSERT(body != NULL);
1921 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO_V1 ||
1922 cmd == LL_IOC_MDC_GETINFO_V1 ||
1923 cmd == IOC_MDC_GETFILEINFO_V2 ||
1924 cmd == LL_IOC_MDC_GETINFO_V2)) {
1932 if (cmd == IOC_MDC_GETFILESTRIPE ||
1933 cmd == LL_IOC_LOV_GETSTRIPE ||
1934 cmd == LL_IOC_LOV_GETSTRIPE_NEW) {
1936 } else if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1937 cmd == LL_IOC_MDC_GETINFO_V1){
1938 struct lov_user_mds_data_v1 __user *lmdp;
1941 statp = &lmdp->lmd_st;
1942 lump = &lmdp->lmd_lmm;
1944 struct lov_user_mds_data __user *lmdp;
1947 fidp = &lmdp->lmd_fid;
1948 stxp = &lmdp->lmd_stx;
1949 flagsp = &lmdp->lmd_flags;
1950 lmmsizep = &lmdp->lmd_lmmsize;
1951 lump = &lmdp->lmd_lmm;
1955 /* If the file has no striping then zero out *lump so
1956 * that the caller isn't confused by garbage. */
1957 if (clear_user(lump, sizeof(*lump)))
1958 GOTO(out_req, rc = -EFAULT);
1959 } else if (copy_to_user(lump, lmm, lmmsize)) {
1960 if (copy_to_user(lump, lmm, sizeof(*lump)))
1961 GOTO(out_req, rc = -EFAULT);
1964 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
1966 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1967 cmd == LL_IOC_MDC_GETINFO_V1) {
1970 st.st_dev = inode->i_sb->s_dev;
1971 st.st_mode = body->mbo_mode;
1972 st.st_nlink = body->mbo_nlink;
1973 st.st_uid = body->mbo_uid;
1974 st.st_gid = body->mbo_gid;
1975 st.st_rdev = body->mbo_rdev;
1976 if (llcrypt_require_key(inode) == -ENOKEY)
1977 st.st_size = round_up(st.st_size,
1978 LUSTRE_ENCRYPTION_UNIT_SIZE);
1980 st.st_size = body->mbo_size;
1981 st.st_blksize = PAGE_SIZE;
1982 st.st_blocks = body->mbo_blocks;
1983 st.st_atime = body->mbo_atime;
1984 st.st_mtime = body->mbo_mtime;
1985 st.st_ctime = body->mbo_ctime;
1986 st.st_ino = cl_fid_build_ino(&body->mbo_fid1,
1989 if (copy_to_user(statp, &st, sizeof(st)))
1990 GOTO(out_req, rc = -EFAULT);
1991 } else if (cmd == IOC_MDC_GETFILEINFO_V2 ||
1992 cmd == LL_IOC_MDC_GETINFO_V2) {
1993 lstatx_t stx = { 0 };
1994 __u64 valid = body->mbo_valid;
1996 stx.stx_blksize = PAGE_SIZE;
1997 stx.stx_nlink = body->mbo_nlink;
1998 stx.stx_uid = body->mbo_uid;
1999 stx.stx_gid = body->mbo_gid;
2000 stx.stx_mode = body->mbo_mode;
2001 stx.stx_ino = cl_fid_build_ino(&body->mbo_fid1,
2003 if (llcrypt_require_key(inode) == -ENOKEY)
2004 stx.stx_size = round_up(stx.stx_size,
2005 LUSTRE_ENCRYPTION_UNIT_SIZE);
2007 stx.stx_size = body->mbo_size;
2008 stx.stx_blocks = body->mbo_blocks;
2009 stx.stx_atime.tv_sec = body->mbo_atime;
2010 stx.stx_ctime.tv_sec = body->mbo_ctime;
2011 stx.stx_mtime.tv_sec = body->mbo_mtime;
2012 stx.stx_btime.tv_sec = body->mbo_btime;
2013 stx.stx_rdev_major = MAJOR(body->mbo_rdev);
2014 stx.stx_rdev_minor = MINOR(body->mbo_rdev);
2015 stx.stx_dev_major = MAJOR(inode->i_sb->s_dev);
2016 stx.stx_dev_minor = MINOR(inode->i_sb->s_dev);
2017 stx.stx_mask |= STATX_BASIC_STATS | STATX_BTIME;
2020 * For a striped directory, the size and blocks returned
2021 * from MDT is not correct.
2022 * The size and blocks are aggregated by client across
2024 * Thus for a striped directory, do not return the valid
2025 * FLSIZE and FLBLOCKS flags to the caller.
2026 * However, this whould be better decided by the MDS
2027 * instead of the client.
2029 if (cmd == LL_IOC_MDC_GETINFO_V2 &&
2030 ll_i2info(inode)->lli_lsm_md != NULL)
2031 valid &= ~(OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
2033 if (flagsp && copy_to_user(flagsp, &valid,
2035 GOTO(out_req, rc = -EFAULT);
2037 if (fidp && copy_to_user(fidp, &body->mbo_fid1,
2039 GOTO(out_req, rc = -EFAULT);
2041 if (!(valid & OBD_MD_FLSIZE))
2042 stx.stx_mask &= ~STATX_SIZE;
2043 if (!(valid & OBD_MD_FLBLOCKS))
2044 stx.stx_mask &= ~STATX_BLOCKS;
2046 if (stxp && copy_to_user(stxp, &stx, sizeof(stx)))
2047 GOTO(out_req, rc = -EFAULT);
2049 if (lmmsizep && copy_to_user(lmmsizep, &lmmsize,
2051 GOTO(out_req, rc = -EFAULT);
2056 ptlrpc_req_finished(request);
2057 ptlrpc_req_finished(root_request);
2059 ll_putname(filename);
2062 case OBD_IOC_QUOTACTL: {
2063 struct if_quotactl *qctl;
2064 int qctl_len = sizeof(*qctl) + LOV_MAXPOOLNAME + 1;
2066 OBD_ALLOC(qctl, qctl_len);
2070 if (copy_from_user(qctl, uarg, sizeof(*qctl)))
2071 GOTO(out_quotactl, rc = -EFAULT);
2073 if (LUSTRE_Q_CMD_IS_POOL(qctl->qc_cmd)) {
2074 char __user *from = uarg +
2075 offsetof(typeof(*qctl), qc_poolname);
2076 if (copy_from_user(qctl->qc_poolname, from,
2077 LOV_MAXPOOLNAME + 1))
2078 GOTO(out_quotactl, rc = -EFAULT);
2081 rc = quotactl_ioctl(inode->i_sb, qctl);
2082 if ((rc == 0 || rc == -ENODATA) &&
2083 copy_to_user(uarg, qctl, sizeof(*qctl)))
2086 OBD_FREE(qctl, qctl_len);
2089 case LL_IOC_GETOBDCOUNT: {
2091 struct obd_export *exp;
2093 if (copy_from_user(&count, uarg, sizeof(count)))
2096 /* get ost count when count is zero, get mdt count otherwise */
2097 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
2098 vallen = sizeof(count);
2099 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
2100 KEY_TGT_COUNT, &vallen, &count);
2102 CERROR("%s: get target count failed: rc = %d\n",
2103 sbi->ll_fsname, rc);
2107 if (copy_to_user(uarg, &count, sizeof(count)))
2112 case LL_IOC_GET_CONNECT_FLAGS:
2113 RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL, uarg));
2114 case LL_IOC_FID2MDTIDX: {
2115 struct obd_export *exp = ll_i2mdexp(inode);
2119 if (copy_from_user(&fid, uarg, sizeof(fid)))
2122 /* Call mdc_iocontrol */
2123 rc = obd_iocontrol(LL_IOC_FID2MDTIDX, exp, sizeof(fid), &fid,
2124 (__u32 __user *)&index);
2130 case LL_IOC_HSM_REQUEST: {
2131 struct hsm_user_request *hur;
2138 /* We don't know the true size yet; copy the fixed-size part */
2139 if (copy_from_user(hur, uarg, sizeof(*hur))) {
2144 /* Compute the whole struct size */
2145 totalsize = hur_len(hur);
2150 /* Final size will be more than double totalsize */
2151 if (totalsize >= MDS_MAXREQSIZE / 3)
2154 OBD_ALLOC_LARGE(hur, totalsize);
2158 /* Copy the whole struct */
2159 if (copy_from_user(hur, uarg, totalsize))
2160 GOTO(out_hur, rc = -EFAULT);
2162 if (hur->hur_request.hr_action == HUA_RELEASE) {
2163 const struct lu_fid *fid;
2167 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
2168 fid = &hur->hur_user_item[i].hui_fid;
2169 f = search_inode_for_lustre(inode->i_sb, fid);
2175 rc = ll_hsm_release(f);
2181 rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
2185 OBD_FREE_LARGE(hur, totalsize);
2189 case LL_IOC_HSM_PROGRESS: {
2190 struct hsm_progress_kernel hpk;
2191 struct hsm_progress hp;
2193 if (copy_from_user(&hp, uarg, sizeof(hp)))
2196 hpk.hpk_fid = hp.hp_fid;
2197 hpk.hpk_cookie = hp.hp_cookie;
2198 hpk.hpk_extent = hp.hp_extent;
2199 hpk.hpk_flags = hp.hp_flags;
2200 hpk.hpk_errval = hp.hp_errval;
2201 hpk.hpk_data_version = 0;
2203 /* File may not exist in Lustre; all progress
2204 * reported to Lustre root */
2205 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
2209 case LL_IOC_HSM_CT_START:
2210 if (!capable(CAP_SYS_ADMIN))
2213 rc = copy_and_ct_start(cmd, sbi->ll_md_exp, uarg);
2216 case LL_IOC_HSM_COPY_START: {
2217 struct hsm_copy *copy;
2220 OBD_ALLOC_PTR(copy);
2223 if (copy_from_user(copy, uarg, sizeof(*copy))) {
2228 rc = ll_ioc_copy_start(inode->i_sb, copy);
2229 if (copy_to_user(uarg, copy, sizeof(*copy)))
2235 case LL_IOC_HSM_COPY_END: {
2236 struct hsm_copy *copy;
2239 OBD_ALLOC_PTR(copy);
2242 if (copy_from_user(copy, uarg, sizeof(*copy))) {
2247 rc = ll_ioc_copy_end(inode->i_sb, copy);
2248 if (copy_to_user(uarg, copy, sizeof(*copy)))
2254 case LL_IOC_MIGRATE: {
2255 struct lmv_user_md *lum;
2262 rc = obd_ioctl_getdata(&data, &len, uarg);
2266 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
2267 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
2268 GOTO(migrate_free, rc = -EINVAL);
2270 filename = data->ioc_inlbuf1;
2271 namelen = data->ioc_inllen1;
2272 flags = data->ioc_type;
2274 if (namelen < 1 || namelen != strlen(filename) + 1) {
2275 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
2276 GOTO(migrate_free, rc = -EINVAL);
2279 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
2280 if (lum->lum_magic != LMV_USER_MAGIC &&
2281 lum->lum_magic != LMV_USER_MAGIC_SPECIFIC) {
2283 CERROR("%s: wrong lum magic %x: rc = %d\n",
2284 filename, lum->lum_magic, rc);
2285 GOTO(migrate_free, rc);
2288 rc = ll_migrate(inode, file, lum, filename, flags);
2290 OBD_FREE_LARGE(data, len);
2294 case LL_IOC_PCC_DETACH_BY_FID: {
2295 struct lu_pcc_detach_fid *detach;
2297 struct inode *inode2;
2300 OBD_ALLOC_PTR(detach);
2304 if (copy_from_user(detach, uarg, sizeof(*detach)))
2305 GOTO(out_detach, rc = -EFAULT);
2307 fid = &detach->pccd_fid;
2308 ino = cl_fid_build_ino(fid, ll_need_32bit_api(sbi));
2309 inode2 = ilookup5(inode->i_sb, ino, ll_test_inode_by_fid, fid);
2311 /* Target inode is not in inode cache, and PCC file
2312 * has aleady released, return immdiately.
2314 GOTO(out_detach, rc = 0);
2316 if (!S_ISREG(inode2->i_mode))
2317 GOTO(out_iput, rc = -EINVAL);
2319 if (!inode_owner_or_capable(&init_user_ns, inode2))
2320 GOTO(out_iput, rc = -EPERM);
2322 rc = pcc_ioctl_detach(inode2, detach->pccd_opt);
2326 OBD_FREE_PTR(detach);
2330 rc = ll_iocontrol(inode, file, cmd, uarg);
2333 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL, uarg));
2337 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
2339 struct inode *inode = file->f_mapping->host;
2340 struct ll_file_data *fd = file->private_data;
2341 struct ll_sb_info *sbi = ll_i2sbi(inode);
2342 int api32 = ll_need_32bit_api(sbi);
2343 loff_t ret = -EINVAL;
2351 offset += file->f_pos;
2357 offset += LL_DIR_END_OFF_32BIT;
2359 offset += LL_DIR_END_OFF;
2366 ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
2367 (!api32 && offset <= LL_DIR_END_OFF))) {
2368 if (offset != file->f_pos) {
2371 hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
2372 if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
2373 (!api32 && offset == LL_DIR_END_OFF))
2374 fd->lfd_pos = MDS_DIR_END_OFF;
2375 else if (api32 && hash64)
2376 fd->lfd_pos = offset << 32;
2378 fd->lfd_pos = offset;
2379 file->f_pos = offset;
2380 file->f_version = 0;
2387 inode_unlock(inode);
2391 static int ll_dir_open(struct inode *inode, struct file *file)
2394 RETURN(ll_file_open(inode, file));
2397 static int ll_dir_release(struct inode *inode, struct file *file)
2400 RETURN(ll_file_release(inode, file));
2403 /* notify error if partially read striped directory */
2404 static int ll_dir_flush(struct file *file, fl_owner_t id)
2406 struct ll_file_data *lfd = file->private_data;
2407 int rc = lfd->fd_partial_readdir_rc;
2409 lfd->fd_partial_readdir_rc = 0;
2414 const struct file_operations ll_dir_operations = {
2415 .llseek = ll_dir_seek,
2416 .open = ll_dir_open,
2417 .release = ll_dir_release,
2418 .read = generic_read_dir,
2419 #ifdef HAVE_DIR_CONTEXT
2420 .iterate_shared = ll_iterate,
2422 .readdir = ll_readdir,
2424 .unlocked_ioctl = ll_dir_ioctl,
2426 .flush = ll_dir_flush,