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_fid.h>
55 #include <lustre_kernelcomm.h>
56 #include <lustre_swab.h>
57 #include <libcfs/libcfs_crypto.h>
59 #include "llite_internal.h"
62 * (new) readdir implementation overview.
64 * Original lustre readdir implementation cached exact copy of raw directory
65 * pages on the client. These pages were indexed in client page cache by
66 * logical offset in the directory file. This design, while very simple and
67 * intuitive had some inherent problems:
69 * . it implies that byte offset to the directory entry serves as a
70 * telldir(3)/seekdir(3) cookie, but that offset is not stable: in
71 * ext3/htree directory entries may move due to splits, and more
74 * . it is incompatible with the design of split directories for cmd3,
75 * that assumes that names are distributed across nodes based on their
76 * hash, and so readdir should be done in hash order.
78 * New readdir implementation does readdir in hash order, and uses hash of a
79 * file name as a telldir/seekdir cookie. This led to number of complications:
81 * . hash is not unique, so it cannot be used to index cached directory
82 * pages on the client (note, that it requires a whole pageful of hash
83 * collided entries to cause two pages to have identical hashes);
85 * . hash is not unique, so it cannot, strictly speaking, be used as an
86 * entry cookie. ext3/htree has the same problem and lustre implementation
87 * mimics their solution: seekdir(hash) positions directory at the first
88 * entry with the given hash.
94 * Client caches directory pages using hash of the first entry as an index. As
95 * noted above hash is not unique, so this solution doesn't work as is:
96 * special processing is needed for "page hash chains" (i.e., sequences of
97 * pages filled with entries all having the same hash value).
99 * First, such chains have to be detected. To this end, server returns to the
100 * client the hash of the first entry on the page next to one returned. When
101 * client detects that this hash is the same as hash of the first entry on the
102 * returned page, page hash collision has to be handled. Pages in the
103 * hash chain, except first one, are termed "overflow pages".
105 * Proposed (unimplimented) solution to index uniqueness problem is to
106 * not cache overflow pages. Instead, when page hash collision is
107 * detected, all overflow pages from emerging chain should be
108 * immediately requested from the server and placed in a special data
109 * structure. This data structure can be used by ll_readdir() to
110 * process entries from overflow pages. When readdir invocation
111 * finishes, overflow pages are discarded. If page hash collision chain
112 * weren't completely processed, next call to readdir will again detect
113 * page hash collision, again read overflow pages in, process next
114 * portion of entries and again discard the pages. This is not as
115 * wasteful as it looks, because, given reasonable hash, page hash
116 * collisions are extremely rare.
118 * 1. directory positioning
120 * When seekdir(hash) is called, original
131 * identification of and access to overflow pages
135 * Page in MDS_READPAGE RPC is packed in LU_PAGE_SIZE, and each page contains
136 * a header lu_dirpage which describes the start/end hash, and whether this
137 * page is empty (contains no dir entry) or hash collide with next page.
138 * After client receives reply, several pages will be integrated into dir page
139 * in PAGE_SIZE (if PAGE_SIZE greater than LU_PAGE_SIZE), and the
140 * lu_dirpage for this integrated page will be adjusted. See
141 * mdc_adjust_dirpages().
144 struct page *ll_get_dir_page(struct inode *dir, struct md_op_data *op_data,
145 __u64 offset, int *partial_readdir_rc)
147 struct md_readdir_info mrinfo = {
148 .mr_blocking_ast = ll_md_blocking_ast };
152 rc = md_read_page(ll_i2mdexp(dir), op_data, &mrinfo, offset, &page);
156 if (partial_readdir_rc && mrinfo.mr_partial_readdir_rc)
157 *partial_readdir_rc = mrinfo.mr_partial_readdir_rc;
162 void ll_release_page(struct inode *inode, struct page *page,
167 /* Always remove the page for striped dir, because the page is
168 * built from temporarily in LMV layer */
169 if (inode && S_ISDIR(inode->i_mode) &&
170 lmv_dir_striped(ll_i2info(inode)->lli_lsm_md)) {
177 if (likely(page->mapping != NULL))
178 delete_from_page_cache(page);
184 #ifdef HAVE_DIR_CONTEXT
185 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
186 struct dir_context *ctx, int *partial_readdir_rc)
189 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
190 void *cookie, filldir_t filldir, int *partial_readdir_rc)
193 struct ll_sb_info *sbi = ll_i2sbi(inode);
195 bool is_api32 = ll_need_32bit_api(sbi);
196 bool is_hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
199 struct llcrypt_str lltr = LLTR_INIT(NULL, 0);
203 if (IS_ENCRYPTED(inode)) {
204 rc = llcrypt_fname_alloc_buffer(inode, NAME_MAX, &lltr);
209 page = ll_get_dir_page(inode, op_data, pos, partial_readdir_rc);
211 while (rc == 0 && !done) {
212 struct lu_dirpage *dp;
213 struct lu_dirent *ent;
222 hash = MDS_DIR_END_OFF;
223 dp = page_address(page);
224 for (ent = lu_dirent_start(dp); ent != NULL && !done;
225 ent = lu_dirent_next(ent)) {
232 hash = le64_to_cpu(ent->lde_hash);
233 if (hash < pos) /* Skip until we find target hash */
236 namelen = le16_to_cpu(ent->lde_namelen);
237 if (namelen == 0) /* Skip dummy record */
240 if (is_api32 && is_hash64)
244 fid_le_to_cpu(&fid, &ent->lde_fid);
245 ino = cl_fid_build_ino(&fid, is_api32);
246 type = S_DT(lu_dirent_type_get(ent));
247 /* For ll_nfs_get_name_filldir(), it will try to access
248 * 'ent' through 'lde_name', so the parameter 'name'
249 * for 'filldir()' must be part of the 'ent'. */
250 #ifdef HAVE_DIR_CONTEXT
252 if (!IS_ENCRYPTED(inode)) {
253 done = !dir_emit(ctx, ent->lde_name, namelen,
256 /* Directory is encrypted */
257 int save_len = lltr.len;
258 struct llcrypt_str de_name =
259 LLTR_INIT(ent->lde_name, namelen);
261 rc = ll_fname_disk_to_usr(inode, 0, 0, &de_name,
269 done = !dir_emit(ctx, de_name.name, de_name.len,
273 /* HAVE_DIR_CONTEXT is defined from kernel 3.11, whereas
274 * IS_ENCRYPTED is brought by kernel 4.14.
275 * So there is no need to handle encryption case here.
277 done = filldir(cookie, ent->lde_name, namelen, lhash,
284 ll_release_page(inode, page, false);
288 next = le64_to_cpu(dp->ldp_hash_end);
290 if (pos == MDS_DIR_END_OFF) {
292 * End of directory reached.
295 ll_release_page(inode, page, false);
298 * Normal case: continue to the next
301 ll_release_page(inode, page,
302 le32_to_cpu(dp->ldp_flags) &
305 page = ll_get_dir_page(inode, op_data, pos,
309 #ifdef HAVE_DIR_CONTEXT
314 llcrypt_fname_free_buffer(&lltr);
318 #ifdef HAVE_DIR_CONTEXT
319 static int ll_iterate(struct file *filp, struct dir_context *ctx)
321 static int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
324 struct inode *inode = file_inode(filp);
325 struct ll_file_data *lfd = filp->private_data;
326 struct ll_sb_info *sbi = ll_i2sbi(inode);
327 bool hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
328 int api32 = ll_need_32bit_api(sbi);
329 struct md_op_data *op_data;
330 struct lu_fid pfid = { 0 };
331 ktime_t kstart = ktime_get();
332 /* result of possible partial readdir */
333 int partial_readdir_rc = 0;
339 LASSERT(lfd != NULL);
343 "VFS Op:inode="DFID"(%p) pos/size%lu/%llu 32bit_api %d\n",
344 PFID(ll_inode2fid(inode)),
345 inode, (unsigned long)pos, i_size_read(inode), api32);
347 if (IS_ENCRYPTED(inode)) {
348 rc = llcrypt_get_encryption_info(inode);
349 if (rc && rc != -ENOKEY)
353 if (pos == MDS_DIR_END_OFF)
359 if (unlikely(ll_dir_striped(inode))) {
361 * This is only needed for striped dir to fill ..,
362 * see lmv_read_page()
364 if (file_dentry(filp)->d_parent != NULL &&
365 file_dentry(filp)->d_parent->d_inode != NULL) {
366 __u64 ibits = MDS_INODELOCK_LOOKUP;
367 struct inode *parent =
368 file_dentry(filp)->d_parent->d_inode;
370 if (ll_have_md_lock(parent, &ibits, LCK_MINMODE))
371 pfid = *ll_inode2fid(parent);
374 /* If it can not find in cache, do lookup .. on the master
376 if (fid_is_zero(&pfid)) {
377 rc = ll_dir_get_parent_fid(inode, &pfid);
383 op_data = ll_prep_md_op_data(NULL, inode, inode, NULL, 0, 0,
384 LUSTRE_OPC_ANY, inode);
386 GOTO(out, rc = PTR_ERR(op_data));
388 /* foreign dirs are browsed out of Lustre */
389 if (unlikely(op_data->op_mea1 != NULL &&
390 op_data->op_mea1->lsm_md_magic == LMV_MAGIC_FOREIGN)) {
391 ll_finish_md_op_data(op_data);
395 op_data->op_fid3 = pfid;
397 #ifdef HAVE_DIR_CONTEXT
399 rc = ll_dir_read(inode, &pos, op_data, ctx, &partial_readdir_rc);
402 rc = ll_dir_read(inode, &pos, op_data, cookie, filldir,
403 &partial_readdir_rc);
406 if (!lfd->fd_partial_readdir_rc)
407 lfd->fd_partial_readdir_rc = partial_readdir_rc;
409 if (pos == MDS_DIR_END_OFF) {
411 pos = LL_DIR_END_OFF_32BIT;
413 pos = LL_DIR_END_OFF;
418 #ifdef HAVE_DIR_CONTEXT
423 ll_finish_md_op_data(op_data);
427 ll_stats_ops_tally(sbi, LPROC_LL_READDIR,
428 ktime_us_delta(ktime_get(), kstart));
434 * Create striped directory with specified stripe(@lump)
436 * \param[in] dparent the parent of the directory.
437 * \param[in] lump the specified stripes.
438 * \param[in] dirname the name of the directory.
439 * \param[in] mode the specified mode of the directory.
441 * \retval =0 if striped directory is being created successfully.
442 * <0 if the creation is failed.
444 static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
445 size_t len, const char *dirname, umode_t mode,
448 struct inode *parent = dparent->d_inode;
449 struct ptlrpc_request *request = NULL;
450 struct md_op_data *op_data;
451 struct ll_sb_info *sbi = ll_i2sbi(parent);
452 struct inode *inode = NULL;
453 struct dentry dentry = {
457 .len = strlen(dirname),
458 .hash = ll_full_name_hash(dparent, dirname,
462 bool encrypt = false;
467 if (unlikely(!lmv_user_magic_supported(lump->lum_magic)))
470 if (lump->lum_magic != LMV_MAGIC_FOREIGN) {
472 "VFS Op:inode="DFID"(%p) name %s stripe_offset %d, stripe_count: %u\n",
473 PFID(ll_inode2fid(parent)), parent, dirname,
474 (int)lump->lum_stripe_offset, lump->lum_stripe_count);
476 struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)lump;
479 "VFS Op:inode="DFID"(%p) name %s foreign, length %u, value '%.*s'\n",
480 PFID(ll_inode2fid(parent)), parent, dirname,
481 lfm->lfm_length, lfm->lfm_length, lfm->lfm_value);
484 if (lump->lum_stripe_count > 1 &&
485 !(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_DIR_STRIPE))
488 if (IS_DEADDIR(parent) &&
489 !OBD_FAIL_CHECK(OBD_FAIL_LLITE_NO_CHECK_DEAD))
492 /* MDS < 2.14 doesn't support 'crush' hash type, and cannot handle
493 * unknown hash if client doesn't set a valid one. switch to fnv_1a_64.
495 if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_CRUSH)) {
496 enum lmv_hash_type type = lump->lum_hash_type &
499 if (type >= LMV_HASH_TYPE_CRUSH ||
500 type == LMV_HASH_TYPE_UNKNOWN)
501 lump->lum_hash_type = (lump->lum_hash_type ^ type) |
502 LMV_HASH_TYPE_FNV_1A_64;
505 hash_flags = lump->lum_hash_type & ~LMV_HASH_TYPE_MASK;
506 if (hash_flags & ~LMV_HASH_FLAG_KNOWN)
509 if (unlikely(!lmv_user_magic_supported(cpu_to_le32(lump->lum_magic))))
510 lustre_swab_lmv_user_md(lump);
512 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
513 mode &= ~current_umask();
514 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
515 op_data = ll_prep_md_op_data(NULL, parent, NULL, dirname,
516 strlen(dirname), mode, LUSTRE_OPC_MKDIR,
519 RETURN(PTR_ERR(op_data));
521 op_data->op_dir_depth = ll_i2info(parent)->lli_dir_depth;
523 if (ll_sbi_has_encrypt(sbi) &&
524 (IS_ENCRYPTED(parent) ||
525 unlikely(ll_sb_has_test_dummy_encryption(parent->i_sb)))) {
526 err = llcrypt_get_encryption_info(parent);
528 GOTO(out_op_data, err);
529 if (!llcrypt_has_encryption_key(parent))
530 GOTO(out_op_data, err = -ENOKEY);
534 if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
535 /* selinux_dentry_init_security() uses dentry->d_parent and name
536 * to determine the security context for the file. So our fake
537 * dentry should be real enough for this purpose. */
538 err = ll_dentry_init_security(&dentry, mode, &dentry.d_name,
539 &op_data->op_file_secctx_name,
540 &op_data->op_file_secctx,
541 &op_data->op_file_secctx_size);
543 GOTO(out_op_data, err);
547 err = llcrypt_inherit_context(parent, NULL, op_data, false);
549 GOTO(out_op_data, err);
552 op_data->op_cli_flags |= CLI_SET_MEA;
554 op_data->op_bias |= MDS_SETSTRIPE_CREATE;
556 err = md_create(sbi->ll_md_exp, op_data, lump, len, mode,
557 from_kuid(&init_user_ns, current_fsuid()),
558 from_kgid(&init_user_ns, current_fsgid()),
559 current_cap(), 0, &request);
561 GOTO(out_request, err);
563 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_SETDIRSTRIPE_PAUSE, cfs_fail_val);
565 err = ll_prep_inode(&inode, &request->rq_pill, parent->i_sb, NULL);
567 GOTO(out_inode, err);
569 dentry.d_inode = inode;
571 if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
572 /* no need to protect selinux_inode_setsecurity() by
573 * inode_lock. Taking it would lead to a client deadlock
576 err = security_inode_notifysecctx(inode,
577 op_data->op_file_secctx,
578 op_data->op_file_secctx_size);
580 err = ll_inode_init_security(&dentry, inode, parent);
583 GOTO(out_inode, err);
586 err = ll_set_encflags(inode, op_data->op_file_encctx,
587 op_data->op_file_encctx_size, false);
589 GOTO(out_inode, err);
595 ptlrpc_req_finished(request);
597 ll_finish_md_op_data(op_data);
602 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
605 struct ll_sb_info *sbi = ll_i2sbi(inode);
606 struct md_op_data *op_data;
607 struct ptlrpc_request *req = NULL;
613 switch (lump->lmm_magic) {
614 case LOV_USER_MAGIC_V1:
615 lum_size = sizeof(struct lov_user_md_v1);
617 case LOV_USER_MAGIC_V3:
618 lum_size = sizeof(struct lov_user_md_v3);
620 case LOV_USER_MAGIC_COMP_V1:
621 lum_size = ((struct lov_comp_md_v1 *)lump)->lcm_size;
623 case LMV_USER_MAGIC: {
624 struct lmv_user_md *lmv = (struct lmv_user_md *)lump;
626 /* MDS < 2.14 doesn't support 'crush' hash type, and
627 * cannot handle unknown hash if client doesn't set a
628 * valid one. switch to fnv_1a_64.
630 if (!(exp_connect_flags2(sbi->ll_md_exp) &
631 OBD_CONNECT2_CRUSH)) {
632 enum lmv_hash_type type = lmv->lum_hash_type &
635 if (type >= LMV_HASH_TYPE_CRUSH ||
636 type == LMV_HASH_TYPE_UNKNOWN)
638 (lmv->lum_hash_type ^ type) |
639 LMV_HASH_TYPE_FNV_1A_64;
641 if (lmv->lum_magic != cpu_to_le32(LMV_USER_MAGIC))
642 lustre_swab_lmv_user_md(lmv);
643 lum_size = sizeof(*lmv);
646 case LOV_USER_MAGIC_SPECIFIC: {
647 struct lov_user_md_v3 *v3 =
648 (struct lov_user_md_v3 *)lump;
649 if (v3->lmm_stripe_count > LOV_MAX_STRIPE_COUNT)
651 lum_size = lov_user_md_size(v3->lmm_stripe_count,
652 LOV_USER_MAGIC_SPECIFIC);
656 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
657 " %#08x != %#08x nor %#08x\n",
658 lump->lmm_magic, LOV_USER_MAGIC_V1,
664 * This is coming from userspace, so should be in
665 * local endian. But the MDS would like it in little
666 * endian, so we swab it before we send it.
668 if ((__swab32(lump->lmm_magic) & le32_to_cpu(LOV_MAGIC_MASK)) ==
669 le32_to_cpu(LOV_MAGIC_MAGIC))
670 lustre_swab_lov_user_md(lump, 0);
672 lum_size = sizeof(struct lov_user_md_v1);
675 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
676 LUSTRE_OPC_ANY, NULL);
678 RETURN(PTR_ERR(op_data));
680 /* swabbing is done in lov_setstripe() on server side */
681 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size, &req);
682 ll_finish_md_op_data(op_data);
683 ptlrpc_req_finished(req);
690 static int ll_dir_get_default_layout(struct inode *inode, void **plmm,
692 struct ptlrpc_request **request, u64 valid,
693 enum get_default_layout_type type)
695 struct ll_sb_info *sbi = ll_i2sbi(inode);
696 struct mdt_body *body;
697 struct lov_mds_md *lmm = NULL;
698 struct ptlrpc_request *req = NULL;
700 struct md_op_data *op_data;
704 rc = ll_get_default_mdsize(sbi, &lmm_size);
708 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
709 0, lmm_size, LUSTRE_OPC_ANY,
712 RETURN(PTR_ERR(op_data));
714 op_data->op_valid = valid | OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
716 if (type == GET_DEFAULT_LAYOUT_ROOT) {
717 lu_root_fid(&op_data->op_fid1);
718 fid = op_data->op_fid1;
720 fid = *ll_inode2fid(inode);
723 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
724 ll_finish_md_op_data(op_data);
726 CDEBUG(D_INFO, "md_getattr failed on inode "DFID": rc %d\n",
731 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
732 LASSERT(body != NULL);
734 lmm_size = body->mbo_eadatasize;
736 if (!(body->mbo_valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
738 GOTO(out, rc = -ENODATA);
741 lmm = req_capsule_server_sized_get(&req->rq_pill,
742 &RMF_MDT_MD, lmm_size);
743 LASSERT(lmm != NULL);
746 * This is coming from the MDS, so is probably in
747 * little endian. We convert it to host endian before
748 * passing it to userspace.
750 /* We don't swab objects for directories */
751 switch (le32_to_cpu(lmm->lmm_magic)) {
754 case LOV_MAGIC_COMP_V1:
755 case LOV_USER_MAGIC_SPECIFIC:
756 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
757 lustre_swab_lov_user_md((struct lov_user_md *)lmm, 0);
760 if (LMV_MAGIC != cpu_to_le32(LMV_MAGIC))
761 lustre_swab_lmv_mds_md((union lmv_mds_md *)lmm);
764 if (LMV_USER_MAGIC != cpu_to_le32(LMV_USER_MAGIC))
765 lustre_swab_lmv_user_md((struct lmv_user_md *)lmm);
767 case LMV_MAGIC_FOREIGN: {
768 struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)lmm;
770 if (LMV_MAGIC_FOREIGN != cpu_to_le32(LMV_MAGIC_FOREIGN)) {
771 __swab32s(&lfm->lfm_magic);
772 __swab32s(&lfm->lfm_length);
773 __swab32s(&lfm->lfm_type);
774 __swab32s(&lfm->lfm_flags);
779 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
784 *plmm_size = lmm_size;
790 * This function will be used to get default LOV/LMV/Default LMV
791 * @valid will be used to indicate which stripe it will retrieve.
792 * If the directory does not have its own default layout, then the
793 * function will request the default layout from root FID.
794 * OBD_MD_MEA LMV stripe EA
795 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
796 * otherwise Default LOV EA.
797 * Each time, it can only retrieve 1 stripe EA
799 int ll_dir_getstripe_default(struct inode *inode, void **plmm, int *plmm_size,
800 struct ptlrpc_request **request,
801 struct ptlrpc_request **root_request,
804 struct ptlrpc_request *req = NULL;
805 struct ptlrpc_request *root_req = NULL;
806 struct lov_mds_md *lmm = NULL;
811 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
813 if (rc == -ENODATA && !fid_is_root(ll_inode2fid(inode)) &&
814 !(valid & OBD_MD_MEA) && root_request != NULL) {
815 int rc2 = ll_dir_get_default_layout(inode, (void **)&lmm,
816 &lmm_size, &root_req, valid,
817 GET_DEFAULT_LAYOUT_ROOT);
823 *plmm_size = lmm_size;
825 if (root_request != NULL)
826 *root_request = root_req;
832 * This function will be used to get default LOV/LMV/Default LMV
833 * @valid will be used to indicate which stripe it will retrieve
834 * OBD_MD_MEA LMV stripe EA
835 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
836 * otherwise Default LOV EA.
837 * Each time, it can only retrieve 1 stripe EA
839 int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
840 struct ptlrpc_request **request, u64 valid)
842 struct ptlrpc_request *req = NULL;
843 struct lov_mds_md *lmm = NULL;
848 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
852 *plmm_size = lmm_size;
858 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid)
860 struct md_op_data *op_data;
865 OBD_ALLOC_PTR(op_data);
869 op_data->op_flags |= MF_GET_MDT_IDX;
870 op_data->op_fid1 = *fid;
871 rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
872 mdt_index = op_data->op_mds;
873 OBD_FREE_PTR(op_data);
881 * Get MDT index for the inode.
883 int ll_get_mdt_idx(struct inode *inode)
885 return ll_get_mdt_idx_by_fid(ll_i2sbi(inode), ll_inode2fid(inode));
889 * Generic handler to do any pre-copy work.
891 * It sends a first hsm_progress (with extent length == 0) to coordinator as a
892 * first information for it that real work has started.
894 * Moreover, for a ARCHIVE request, it will sample the file data version and
895 * store it in \a copy.
897 * \return 0 on success.
899 static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
901 struct ll_sb_info *sbi = ll_s2sbi(sb);
902 struct hsm_progress_kernel hpk;
907 /* Forge a hsm_progress based on data from copy. */
908 hpk.hpk_fid = copy->hc_hai.hai_fid;
909 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
910 hpk.hpk_extent.offset = copy->hc_hai.hai_extent.offset;
911 hpk.hpk_extent.length = 0;
914 hpk.hpk_data_version = 0;
917 /* For archive request, we need to read the current file version. */
918 if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
920 __u64 data_version = 0;
922 /* Get inode for this fid */
923 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
925 hpk.hpk_flags |= HP_FLAG_RETRY;
926 /* hpk_errval is >= 0 */
927 hpk.hpk_errval = -PTR_ERR(inode);
928 GOTO(progress, rc = PTR_ERR(inode));
931 /* Read current file data version */
932 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
935 CDEBUG(D_HSM, "Could not read file data version of "
936 DFID" (rc = %d). Archive request ("
937 "%#llx) could not be done.\n",
938 PFID(©->hc_hai.hai_fid), rc,
939 copy->hc_hai.hai_cookie);
940 hpk.hpk_flags |= HP_FLAG_RETRY;
941 /* hpk_errval must be >= 0 */
942 hpk.hpk_errval = -rc;
946 /* Store in the hsm_copy for later copytool use.
947 * Always modified even if no lsm. */
948 copy->hc_data_version = data_version;
952 /* On error, the request should be considered as completed */
953 if (hpk.hpk_errval > 0)
954 hpk.hpk_flags |= HP_FLAG_COMPLETED;
956 rc2 = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
959 /* Return first error */
960 RETURN(rc != 0 ? rc : rc2);
964 * Generic handler to do any post-copy work.
966 * It will send the last hsm_progress update to coordinator to inform it
967 * that copy is finished and whether it was successful or not.
970 * - for ARCHIVE request, it will sample the file data version and compare it
971 * with the version saved in ll_ioc_copy_start(). If they do not match, copy
972 * will be considered as failed.
973 * - for RESTORE request, it will sample the file data version and send it to
974 * coordinator which is useful if the file was imported as 'released'.
976 * \return 0 on success.
978 static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
980 struct ll_sb_info *sbi = ll_s2sbi(sb);
981 struct hsm_progress_kernel hpk;
986 /* If you modify the logic here, also check llapi_hsm_copy_end(). */
987 /* Take care: copy->hc_hai.hai_action, len, gid and data are not
988 * initialized if copy_end was called with copy == NULL.
991 /* Forge a hsm_progress based on data from copy. */
992 hpk.hpk_fid = copy->hc_hai.hai_fid;
993 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
994 hpk.hpk_extent = copy->hc_hai.hai_extent;
995 hpk.hpk_flags = copy->hc_flags | HP_FLAG_COMPLETED;
996 hpk.hpk_errval = copy->hc_errval;
997 hpk.hpk_data_version = 0;
999 /* For archive request, we need to check the file data was not changed.
1001 * For restore request, we need to send the file data version, this is
1002 * useful when the file was created using hsm_import.
1004 if (((copy->hc_hai.hai_action == HSMA_ARCHIVE) ||
1005 (copy->hc_hai.hai_action == HSMA_RESTORE)) &&
1006 (copy->hc_errval == 0)) {
1007 struct inode *inode;
1008 __u64 data_version = 0;
1010 /* Get lsm for this fid */
1011 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
1012 if (IS_ERR(inode)) {
1013 hpk.hpk_flags |= HP_FLAG_RETRY;
1014 /* hpk_errval must be >= 0 */
1015 hpk.hpk_errval = -PTR_ERR(inode);
1016 GOTO(progress, rc = PTR_ERR(inode));
1019 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
1022 CDEBUG(D_HSM, "Could not read file data version. "
1023 "Request could not be confirmed.\n");
1024 if (hpk.hpk_errval == 0)
1025 hpk.hpk_errval = -rc;
1029 /* Store in the hsm_copy for later copytool use.
1030 * Always modified even if no lsm. */
1031 hpk.hpk_data_version = data_version;
1033 /* File could have been stripped during archiving, so we need
1034 * to check anyway. */
1035 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
1036 (copy->hc_data_version != data_version)) {
1037 CDEBUG(D_HSM, "File data version mismatched. "
1038 "File content was changed during archiving. "
1039 DFID", start:%#llx current:%#llx\n",
1040 PFID(©->hc_hai.hai_fid),
1041 copy->hc_data_version, data_version);
1042 /* File was changed, send error to cdt. Do not ask for
1043 * retry because if a file is modified frequently,
1044 * the cdt will loop on retried archive requests.
1045 * The policy engine will ask for a new archive later
1046 * when the file will not be modified for some tunable
1048 hpk.hpk_flags &= ~HP_FLAG_RETRY;
1050 /* hpk_errval must be >= 0 */
1051 hpk.hpk_errval = -rc;
1058 rc2 = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
1061 /* Return first error */
1062 RETURN(rc != 0 ? rc : rc2);
1066 static int copy_and_ct_start(int cmd, struct obd_export *exp,
1067 const struct lustre_kernelcomm __user *data)
1069 struct lustre_kernelcomm *lk;
1070 struct lustre_kernelcomm *tmp;
1071 size_t size = sizeof(*lk);
1076 /* copy data from userspace to get numbers of archive_id */
1077 OBD_ALLOC(lk, size);
1081 if (copy_from_user(lk, data, size))
1082 GOTO(out_lk, rc = -EFAULT);
1084 if (lk->lk_flags & LK_FLG_STOP)
1087 if (!(lk->lk_flags & LK_FLG_DATANR)) {
1088 __u32 archive_mask = lk->lk_data_count;
1091 /* old hsm agent to old MDS */
1092 if (!exp_connect_archive_id_array(exp))
1095 /* old hsm agent to new MDS */
1096 lk->lk_flags |= LK_FLG_DATANR;
1098 if (archive_mask == 0)
1101 count = hweight32(archive_mask);
1102 new_size = offsetof(struct lustre_kernelcomm, lk_data[count]);
1103 OBD_ALLOC(tmp, new_size);
1105 GOTO(out_lk, rc = -ENOMEM);
1107 memcpy(tmp, lk, size);
1108 tmp->lk_data_count = count;
1114 for (i = 0; i < sizeof(archive_mask) * 8; i++) {
1115 if (BIT(i) & archive_mask) {
1116 lk->lk_data[count] = i + 1;
1123 /* new hsm agent to new mds */
1124 if (lk->lk_data_count > 0) {
1125 new_size = offsetof(struct lustre_kernelcomm,
1126 lk_data[lk->lk_data_count]);
1127 OBD_ALLOC(tmp, new_size);
1129 GOTO(out_lk, rc = -ENOMEM);
1135 if (copy_from_user(lk, data, size))
1136 GOTO(out_lk, rc = -EFAULT);
1139 /* new hsm agent to old MDS */
1140 if (!exp_connect_archive_id_array(exp)) {
1143 if (lk->lk_data_count > LL_HSM_ORIGIN_MAX_ARCHIVE)
1144 GOTO(out_lk, rc = -EINVAL);
1146 for (i = 0; i < lk->lk_data_count; i++) {
1147 if (lk->lk_data[i] > LL_HSM_ORIGIN_MAX_ARCHIVE) {
1149 CERROR("%s: archive id %d requested but only "
1150 "[0 - %zu] supported: rc = %d\n",
1151 exp->exp_obd->obd_name, lk->lk_data[i],
1152 LL_HSM_ORIGIN_MAX_ARCHIVE, rc);
1156 if (lk->lk_data[i] == 0) {
1161 archives |= (1 << (lk->lk_data[i] - 1));
1163 lk->lk_flags &= ~LK_FLG_DATANR;
1164 lk->lk_data_count = archives;
1167 rc = obd_iocontrol(cmd, exp, size, lk, NULL);
1173 static int check_owner(int type, int id)
1177 if (!uid_eq(current_euid(), make_kuid(&init_user_ns, id)))
1181 if (!in_egroup_p(make_kgid(&init_user_ns, id)))
1190 int quotactl_ioctl(struct super_block *sb, struct if_quotactl *qctl)
1192 struct ll_sb_info *sbi = ll_s2sbi(sb);
1193 int cmd = qctl->qc_cmd;
1194 int type = qctl->qc_type;
1195 int id = qctl->qc_id;
1196 int valid = qctl->qc_valid;
1204 case LUSTRE_Q_SETDEFAULT:
1205 case LUSTRE_Q_SETQUOTAPOOL:
1206 case LUSTRE_Q_SETINFOPOOL:
1207 case LUSTRE_Q_SETDEFAULT_POOL:
1208 case LUSTRE_Q_DELETEQID:
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);
1267 struct obd_quotactl *oqctl;
1268 int oqctl_len = sizeof(*oqctl);
1270 if (LUSTRE_Q_CMD_IS_POOL(cmd))
1271 oqctl_len += LOV_MAXPOOLNAME + 1;
1273 OBD_ALLOC(oqctl, oqctl_len);
1277 QCTL_COPY(oqctl, qctl);
1278 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1280 OBD_FREE(oqctl, oqctl_len);
1283 /* If QIF_SPACE is not set, client should collect the
1284 * space usage from OSSs by itself */
1285 if ((cmd == Q_GETQUOTA || cmd == LUSTRE_Q_GETQUOTAPOOL) &&
1286 !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
1287 !oqctl->qc_dqblk.dqb_curspace) {
1288 struct obd_quotactl *oqctl_tmp;
1289 int qctl_len = sizeof(*oqctl_tmp) + LOV_MAXPOOLNAME + 1;
1291 OBD_ALLOC(oqctl_tmp, qctl_len);
1292 if (oqctl_tmp == NULL)
1293 GOTO(out, rc = -ENOMEM);
1295 if (cmd == LUSTRE_Q_GETQUOTAPOOL) {
1296 oqctl_tmp->qc_cmd = LUSTRE_Q_GETQUOTAPOOL;
1297 memcpy(oqctl_tmp->qc_poolname,
1299 LOV_MAXPOOLNAME + 1);
1301 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1303 oqctl_tmp->qc_id = oqctl->qc_id;
1304 oqctl_tmp->qc_type = oqctl->qc_type;
1306 /* collect space usage from OSTs */
1307 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1308 rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
1309 if (!rc || rc == -EREMOTEIO) {
1310 oqctl->qc_dqblk.dqb_curspace =
1311 oqctl_tmp->qc_dqblk.dqb_curspace;
1312 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
1315 /* collect space & inode usage from MDTs */
1316 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1317 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1318 oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
1319 rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
1320 if (!rc || rc == -EREMOTEIO) {
1321 oqctl->qc_dqblk.dqb_curspace +=
1322 oqctl_tmp->qc_dqblk.dqb_curspace;
1323 oqctl->qc_dqblk.dqb_curinodes =
1324 oqctl_tmp->qc_dqblk.dqb_curinodes;
1325 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
1327 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
1330 OBD_FREE(oqctl_tmp, qctl_len);
1333 QCTL_COPY(qctl, oqctl);
1334 OBD_FREE(oqctl, oqctl_len);
1340 int ll_rmfid(struct file *file, void __user *arg)
1342 const struct fid_array __user *ufa = arg;
1343 struct inode *inode = file_inode(file);
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 /* Call mdc_iocontrol */
1372 rc = md_rmfid(ll_i2mdexp(file_inode(file)), lfa, rcs, NULL);
1374 for (i = 0; i < nr; i++)
1376 lfa->fa_fids[i].f_ver = rcs[i];
1377 if (copy_to_user(arg, lfa, size))
1382 OBD_FREE_PTR_ARRAY(rcs, nr);
1384 OBD_FREE(lfa, size);
1389 /* This function tries to get a single name component,
1390 * to send to the server. No actual path traversal involved,
1391 * so we limit to NAME_MAX */
1392 static char *ll_getname(const char __user *filename)
1397 OBD_ALLOC(tmp, NAME_MAX + 1);
1400 return ERR_PTR(-ENOMEM);
1402 len = strncpy_from_user(tmp, filename, NAME_MAX + 1);
1405 else if (len > NAME_MAX)
1406 ret = -ENAMETOOLONG;
1409 OBD_FREE(tmp, NAME_MAX + 1);
1415 #define ll_putname(filename) OBD_FREE(filename, NAME_MAX + 1);
1417 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1419 struct dentry *dentry = file_dentry(file);
1420 struct inode *inode = file_inode(file);
1421 struct ll_sb_info *sbi = ll_i2sbi(inode);
1422 struct obd_ioctl_data *data = NULL;
1426 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%#x\n",
1427 PFID(ll_inode2fid(inode)), inode, cmd);
1429 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
1430 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
1433 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
1435 case FS_IOC_GETFLAGS:
1436 case FS_IOC_SETFLAGS:
1437 RETURN(ll_iocontrol(inode, file, cmd, arg));
1438 case FSFILT_IOC_GETVERSION:
1439 case FS_IOC_GETVERSION:
1440 RETURN(put_user(inode->i_generation, (int __user *)arg));
1441 /* We need to special case any other ioctls we want to handle,
1442 * to send them to the MDS/OST as appropriate and to properly
1443 * network encode the arg field. */
1444 case FS_IOC_SETVERSION:
1447 case LL_IOC_GET_MDTIDX: {
1450 mdtidx = ll_get_mdt_idx(inode);
1454 if (put_user((int)mdtidx, (int __user *)arg))
1459 case IOC_MDC_LOOKUP: {
1460 int namelen, len = 0;
1463 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
1467 filename = data->ioc_inlbuf1;
1468 namelen = strlen(filename);
1470 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1471 GOTO(out_free, rc = -EINVAL);
1474 rc = ll_get_fid_by_name(inode, filename, namelen, NULL, NULL);
1476 CERROR("%s: lookup %.*s failed: rc = %d\n",
1477 sbi->ll_fsname, namelen, filename, rc);
1481 OBD_FREE_LARGE(data, len);
1484 case LL_IOC_LMV_SETSTRIPE: {
1485 struct lmv_user_md *lum;
1490 bool createonly = false;
1494 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
1498 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1499 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1500 GOTO(lmv_out_free, rc = -EINVAL);
1502 filename = data->ioc_inlbuf1;
1503 namelen = data->ioc_inllen1;
1506 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1507 GOTO(lmv_out_free, rc = -EINVAL);
1509 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1510 lumlen = data->ioc_inllen2;
1512 if (!lmv_user_magic_supported(lum->lum_magic)) {
1513 CERROR("%s: wrong lum magic %x : rc = %d\n", filename,
1514 lum->lum_magic, -EINVAL);
1515 GOTO(lmv_out_free, rc = -EINVAL);
1518 if ((lum->lum_magic == LMV_USER_MAGIC ||
1519 lum->lum_magic == LMV_USER_MAGIC_SPECIFIC) &&
1520 lumlen < sizeof(*lum)) {
1521 CERROR("%s: wrong lum size %d for magic %x : rc = %d\n",
1522 filename, lumlen, lum->lum_magic, -EINVAL);
1523 GOTO(lmv_out_free, rc = -EINVAL);
1526 if (lum->lum_magic == LMV_MAGIC_FOREIGN &&
1527 lumlen < sizeof(struct lmv_foreign_md)) {
1528 CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1529 filename, lum->lum_magic, lumlen, -EFAULT);
1530 GOTO(lmv_out_free, rc = -EINVAL);
1533 mode = data->ioc_type;
1534 createonly = data->ioc_obdo1.o_flags & OBD_FL_OBDMDEXISTS;
1535 rc = ll_dir_setdirstripe(dentry, lum, lumlen, filename, mode,
1538 OBD_FREE_LARGE(data, len);
1542 case LL_IOC_LMV_SET_DEFAULT_STRIPE: {
1543 struct lmv_user_md lum;
1544 struct lmv_user_md __user *ulump =
1545 (struct lmv_user_md __user *)arg;
1548 if (copy_from_user(&lum, ulump, sizeof(lum)))
1551 if (lum.lum_magic != LMV_USER_MAGIC)
1554 rc = ll_dir_setstripe(inode, (struct lov_user_md *)&lum, 0);
1558 case LL_IOC_LOV_SETSTRIPE_NEW:
1559 case LL_IOC_LOV_SETSTRIPE: {
1560 struct lov_user_md_v3 *lumv3 = NULL;
1561 struct lov_user_md_v1 lumv1;
1562 struct lov_user_md_v1 *lumv1_ptr = &lumv1;
1563 struct lov_user_md_v1 __user *lumv1p =
1564 (struct lov_user_md_v1 __user *)arg;
1565 struct lov_user_md_v3 __user *lumv3p =
1566 (struct lov_user_md_v3 __user *)arg;
1569 int set_default = 0;
1571 BUILD_BUG_ON(sizeof(struct lov_user_md_v3) <=
1572 sizeof(struct lov_comp_md_v1));
1573 BUILD_BUG_ON(sizeof(*lumv3) != sizeof(*lumv3p));
1574 /* first try with v1 which is smaller than v3 */
1575 if (copy_from_user(&lumv1, lumv1p, sizeof(lumv1)))
1578 if (is_root_inode(inode))
1581 switch (lumv1.lmm_magic) {
1582 case LOV_USER_MAGIC_V3:
1583 case LOV_USER_MAGIC_SPECIFIC:
1584 lum_size = ll_lov_user_md_size(&lumv1);
1587 OBD_ALLOC(lumv3, lum_size);
1590 if (copy_from_user(lumv3, lumv3p, lum_size))
1591 GOTO(out, rc = -EFAULT);
1592 lumv1_ptr = (struct lov_user_md_v1 *)lumv3;
1594 case LOV_USER_MAGIC_V1:
1597 GOTO(out, rc = -ENOTSUPP);
1600 /* in v1 and v3 cases lumv1 points to data */
1601 rc = ll_dir_setstripe(inode, lumv1_ptr, set_default);
1604 OBD_FREE(lumv3, lum_size);
1607 case LL_IOC_LMV_GETSTRIPE: {
1608 struct lmv_user_md __user *ulmv =
1609 (struct lmv_user_md __user *)arg;
1610 struct lmv_user_md lum;
1611 struct ptlrpc_request *request = NULL;
1612 struct ptlrpc_request *root_request = NULL;
1613 union lmv_mds_md *lmm = NULL;
1616 struct lmv_user_md *tmp = NULL;
1620 int max_stripe_count;
1624 if (copy_from_user(&lum, ulmv, sizeof(*ulmv)))
1627 max_stripe_count = lum.lum_stripe_count;
1628 /* lum_magic will indicate which stripe the ioctl will like
1629 * to get, LMV_MAGIC_V1 is for normal LMV stripe, LMV_USER_MAGIC
1630 * is for default LMV stripe */
1631 if (lum.lum_magic == LMV_MAGIC_V1)
1632 valid |= OBD_MD_MEA;
1633 else if (lum.lum_magic == LMV_USER_MAGIC)
1634 valid |= OBD_MD_DEFAULT_MEA;
1638 rc = ll_dir_getstripe_default(inode, (void **)&lmm, &lmmsize,
1639 &request, &root_request, valid);
1641 GOTO(finish_req, rc);
1643 /* Get default LMV EA */
1644 if (lum.lum_magic == LMV_USER_MAGIC) {
1645 if (lmmsize > sizeof(*ulmv))
1646 GOTO(finish_req, rc = -EINVAL);
1648 if (root_request != NULL) {
1649 struct lmv_user_md *lum;
1650 struct ll_inode_info *lli;
1652 lum = (struct lmv_user_md *)lmm;
1653 lli = ll_i2info(inode);
1654 if (lum->lum_max_inherit == LMV_INHERIT_NONE ||
1655 (lum->lum_max_inherit > 0 &&
1656 lum->lum_max_inherit < lli->lli_dir_depth))
1657 GOTO(finish_req, rc = -ENODATA);
1659 if (lum->lum_max_inherit ==
1660 lli->lli_dir_depth) {
1661 lum->lum_max_inherit = LMV_INHERIT_NONE;
1662 lum->lum_max_inherit_rr =
1663 LMV_INHERIT_RR_NONE;
1666 if (lum->lum_max_inherit > lli->lli_dir_depth &&
1667 lum->lum_max_inherit <= LMV_INHERIT_MAX)
1668 lum->lum_max_inherit -=
1671 if (lum->lum_max_inherit_rr >
1672 lli->lli_dir_depth &&
1673 lum->lum_max_inherit_rr <=
1675 lum->lum_max_inherit_rr -=
1677 else if (lum->lum_max_inherit_rr ==
1679 lum->lum_max_inherit_rr =
1680 LMV_INHERIT_RR_NONE;
1683 if (copy_to_user(ulmv, lmm, lmmsize))
1684 GOTO(finish_req, rc = -EFAULT);
1686 GOTO(finish_req, rc);
1689 /* if foreign LMV case, fake stripes number */
1690 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1691 struct lmv_foreign_md *lfm;
1693 lfm = (struct lmv_foreign_md *)lmm;
1694 if (lfm->lfm_length < XATTR_SIZE_MAX -
1695 offsetof(typeof(*lfm), lfm_value)) {
1696 __u32 size = lfm->lfm_length +
1697 offsetof(typeof(*lfm), lfm_value);
1699 stripe_count = lmv_foreign_to_md_stripes(size);
1701 CERROR("invalid %d foreign size returned\n",
1706 stripe_count = lmv_mds_md_stripe_count_get(lmm);
1708 if (max_stripe_count < stripe_count) {
1709 lum.lum_stripe_count = stripe_count;
1710 if (copy_to_user(ulmv, &lum, sizeof(lum)))
1711 GOTO(finish_req, rc = -EFAULT);
1712 GOTO(finish_req, rc = -E2BIG);
1715 /* enough room on user side and foreign case */
1716 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1717 struct lmv_foreign_md *lfm;
1720 lfm = (struct lmv_foreign_md *)lmm;
1721 size = lfm->lfm_length +
1722 offsetof(struct lmv_foreign_md, lfm_value);
1723 if (copy_to_user(ulmv, lfm, size))
1724 GOTO(finish_req, rc = -EFAULT);
1725 GOTO(finish_req, rc);
1728 lum_size = lmv_user_md_size(stripe_count,
1729 LMV_USER_MAGIC_SPECIFIC);
1730 OBD_ALLOC(tmp, lum_size);
1732 GOTO(finish_req, rc = -ENOMEM);
1734 mdt_index = ll_get_mdt_idx(inode);
1736 GOTO(out_tmp, rc = -ENOMEM);
1738 tmp->lum_magic = LMV_MAGIC_V1;
1739 tmp->lum_stripe_count = 0;
1740 tmp->lum_stripe_offset = mdt_index;
1741 tmp->lum_hash_type = lmv_mds_md_hash_type_get(lmm);
1742 for (i = 0; i < stripe_count; i++) {
1745 fid_le_to_cpu(&fid, &lmm->lmv_md_v1.lmv_stripe_fids[i]);
1746 if (fid_is_sane(&fid)) {
1747 mdt_index = ll_get_mdt_idx_by_fid(sbi, &fid);
1749 GOTO(out_tmp, rc = mdt_index);
1751 tmp->lum_objects[i].lum_mds = mdt_index;
1752 tmp->lum_objects[i].lum_fid = fid;
1755 tmp->lum_stripe_count++;
1758 if (copy_to_user(ulmv, tmp, lum_size))
1759 GOTO(out_tmp, rc = -EFAULT);
1761 OBD_FREE(tmp, lum_size);
1763 ptlrpc_req_finished(request);
1764 ptlrpc_req_finished(root_request);
1768 case LL_IOC_UNLOCK_FOREIGN:
1769 /* if not a foreign symlink do nothing */
1770 if (ll_foreign_is_removable(dentry, true)) {
1772 "prevent rmdir of non-foreign dir ("DFID")\n",
1773 PFID(ll_inode2fid(inode)));
1774 RETURN(-EOPNOTSUPP);
1778 case LL_IOC_REMOVE_ENTRY: {
1779 char *filename = NULL;
1783 /* Here is a little hack to avoid sending REINT_RMENTRY to
1784 * unsupported server, which might crash the server(LU-2730),
1785 * Because both LVB_TYPE and REINT_RMENTRY will be supported
1786 * on 2.4, we use OBD_CONNECT_LVB_TYPE to detect whether the
1787 * server will support REINT_RMENTRY XXX*/
1788 if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE))
1791 filename = ll_getname((const char __user *)arg);
1792 if (IS_ERR(filename))
1793 RETURN(PTR_ERR(filename));
1795 namelen = strlen(filename);
1797 GOTO(out_rmdir, rc = -EINVAL);
1799 rc = ll_rmdir_entry(inode, filename, namelen);
1802 ll_putname(filename);
1806 RETURN(ll_rmfid(file, (void __user *)arg));
1807 case LL_IOC_LOV_SWAP_LAYOUTS:
1809 case IOC_OBD_STATFS:
1810 RETURN(ll_obd_statfs(inode, (void __user *)arg));
1811 case LL_IOC_LOV_GETSTRIPE:
1812 case LL_IOC_LOV_GETSTRIPE_NEW:
1813 case LL_IOC_MDC_GETINFO_V1:
1814 case LL_IOC_MDC_GETINFO_V2:
1815 case IOC_MDC_GETFILEINFO_V1:
1816 case IOC_MDC_GETFILEINFO_V2:
1817 case IOC_MDC_GETFILESTRIPE: {
1818 struct ptlrpc_request *request = NULL;
1819 struct ptlrpc_request *root_request = NULL;
1820 struct lov_user_md __user *lump;
1821 struct lov_mds_md *lmm = NULL;
1822 struct mdt_body *body;
1823 char *filename = NULL;
1824 lstat_t __user *statp = NULL;
1825 lstatx_t __user *stxp = NULL;
1826 __u64 __user *flagsp = NULL;
1827 __u32 __user *lmmsizep = NULL;
1828 struct lu_fid __user *fidp = NULL;
1832 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1833 cmd == IOC_MDC_GETFILEINFO_V2 ||
1834 cmd == IOC_MDC_GETFILESTRIPE) {
1835 filename = ll_getname((const char __user *)arg);
1836 if (IS_ERR(filename))
1837 RETURN(PTR_ERR(filename));
1839 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1840 &lmmsize, &request);
1842 rc = ll_dir_getstripe_default(inode, (void **)&lmm,
1848 body = req_capsule_server_get(&request->rq_pill,
1850 LASSERT(body != NULL);
1855 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO_V1 ||
1856 cmd == LL_IOC_MDC_GETINFO_V1 ||
1857 cmd == IOC_MDC_GETFILEINFO_V2 ||
1858 cmd == LL_IOC_MDC_GETINFO_V2)) {
1866 if (cmd == IOC_MDC_GETFILESTRIPE ||
1867 cmd == LL_IOC_LOV_GETSTRIPE ||
1868 cmd == LL_IOC_LOV_GETSTRIPE_NEW) {
1869 lump = (struct lov_user_md __user *)arg;
1870 } else if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1871 cmd == LL_IOC_MDC_GETINFO_V1){
1872 struct lov_user_mds_data_v1 __user *lmdp;
1874 lmdp = (struct lov_user_mds_data_v1 __user *)arg;
1875 statp = &lmdp->lmd_st;
1876 lump = &lmdp->lmd_lmm;
1878 struct lov_user_mds_data __user *lmdp;
1880 lmdp = (struct lov_user_mds_data __user *)arg;
1881 fidp = &lmdp->lmd_fid;
1882 stxp = &lmdp->lmd_stx;
1883 flagsp = &lmdp->lmd_flags;
1884 lmmsizep = &lmdp->lmd_lmmsize;
1885 lump = &lmdp->lmd_lmm;
1889 /* If the file has no striping then zero out *lump so
1890 * that the caller isn't confused by garbage. */
1891 if (clear_user(lump, sizeof(*lump)))
1892 GOTO(out_req, rc = -EFAULT);
1893 } else if (copy_to_user(lump, lmm, lmmsize)) {
1894 if (copy_to_user(lump, lmm, sizeof(*lump)))
1895 GOTO(out_req, rc = -EFAULT);
1898 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
1900 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1901 cmd == LL_IOC_MDC_GETINFO_V1) {
1904 st.st_dev = inode->i_sb->s_dev;
1905 st.st_mode = body->mbo_mode;
1906 st.st_nlink = body->mbo_nlink;
1907 st.st_uid = body->mbo_uid;
1908 st.st_gid = body->mbo_gid;
1909 st.st_rdev = body->mbo_rdev;
1910 if (llcrypt_require_key(inode) == -ENOKEY)
1911 st.st_size = round_up(st.st_size,
1912 LUSTRE_ENCRYPTION_UNIT_SIZE);
1914 st.st_size = body->mbo_size;
1915 st.st_blksize = PAGE_SIZE;
1916 st.st_blocks = body->mbo_blocks;
1917 st.st_atime = body->mbo_atime;
1918 st.st_mtime = body->mbo_mtime;
1919 st.st_ctime = body->mbo_ctime;
1920 st.st_ino = cl_fid_build_ino(&body->mbo_fid1,
1923 if (copy_to_user(statp, &st, sizeof(st)))
1924 GOTO(out_req, rc = -EFAULT);
1925 } else if (cmd == IOC_MDC_GETFILEINFO_V2 ||
1926 cmd == LL_IOC_MDC_GETINFO_V2) {
1927 lstatx_t stx = { 0 };
1928 __u64 valid = body->mbo_valid;
1930 stx.stx_blksize = PAGE_SIZE;
1931 stx.stx_nlink = body->mbo_nlink;
1932 stx.stx_uid = body->mbo_uid;
1933 stx.stx_gid = body->mbo_gid;
1934 stx.stx_mode = body->mbo_mode;
1935 stx.stx_ino = cl_fid_build_ino(&body->mbo_fid1,
1937 if (llcrypt_require_key(inode) == -ENOKEY)
1938 stx.stx_size = round_up(stx.stx_size,
1939 LUSTRE_ENCRYPTION_UNIT_SIZE);
1941 stx.stx_size = body->mbo_size;
1942 stx.stx_blocks = body->mbo_blocks;
1943 stx.stx_atime.tv_sec = body->mbo_atime;
1944 stx.stx_ctime.tv_sec = body->mbo_ctime;
1945 stx.stx_mtime.tv_sec = body->mbo_mtime;
1946 stx.stx_btime.tv_sec = body->mbo_btime;
1947 stx.stx_rdev_major = MAJOR(body->mbo_rdev);
1948 stx.stx_rdev_minor = MINOR(body->mbo_rdev);
1949 stx.stx_dev_major = MAJOR(inode->i_sb->s_dev);
1950 stx.stx_dev_minor = MINOR(inode->i_sb->s_dev);
1951 stx.stx_mask |= STATX_BASIC_STATS | STATX_BTIME;
1954 * For a striped directory, the size and blocks returned
1955 * from MDT is not correct.
1956 * The size and blocks are aggregated by client across
1958 * Thus for a striped directory, do not return the valid
1959 * FLSIZE and FLBLOCKS flags to the caller.
1960 * However, this whould be better decided by the MDS
1961 * instead of the client.
1963 if (cmd == LL_IOC_MDC_GETINFO_V2 &&
1964 ll_i2info(inode)->lli_lsm_md != NULL)
1965 valid &= ~(OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
1967 if (flagsp && copy_to_user(flagsp, &valid,
1969 GOTO(out_req, rc = -EFAULT);
1971 if (fidp && copy_to_user(fidp, &body->mbo_fid1,
1973 GOTO(out_req, rc = -EFAULT);
1975 if (!(valid & OBD_MD_FLSIZE))
1976 stx.stx_mask &= ~STATX_SIZE;
1977 if (!(valid & OBD_MD_FLBLOCKS))
1978 stx.stx_mask &= ~STATX_BLOCKS;
1980 if (stxp && copy_to_user(stxp, &stx, sizeof(stx)))
1981 GOTO(out_req, rc = -EFAULT);
1983 if (lmmsizep && copy_to_user(lmmsizep, &lmmsize,
1985 GOTO(out_req, rc = -EFAULT);
1990 ptlrpc_req_finished(request);
1991 ptlrpc_req_finished(root_request);
1993 ll_putname(filename);
1996 case OBD_IOC_QUOTACTL: {
1997 struct if_quotactl *qctl;
1998 int qctl_len = sizeof(*qctl) + LOV_MAXPOOLNAME + 1;
2000 OBD_ALLOC(qctl, qctl_len);
2004 if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl)))
2005 GOTO(out_quotactl, rc = -EFAULT);
2007 if (LUSTRE_Q_CMD_IS_POOL(qctl->qc_cmd)) {
2008 char __user *from = (char __user *)arg +
2009 offsetof(typeof(*qctl), qc_poolname);
2010 if (copy_from_user(qctl->qc_poolname, from,
2011 LOV_MAXPOOLNAME + 1))
2012 GOTO(out_quotactl, rc = -EFAULT);
2015 rc = quotactl_ioctl(inode->i_sb, qctl);
2017 copy_to_user((void __user *)arg, qctl, sizeof(*qctl)))
2021 OBD_FREE(qctl, qctl_len);
2024 case OBD_IOC_GETNAME_OLD:
2025 case OBD_IOC_GETDTNAME:
2026 case OBD_IOC_GETMDNAME:
2027 RETURN(ll_get_obd_name(inode, cmd, arg));
2028 case LL_IOC_FLUSHCTX:
2029 RETURN(ll_flush_ctx(inode));
2030 case LL_IOC_GETOBDCOUNT: {
2032 struct obd_export *exp;
2034 if (copy_from_user(&count, (int __user *)arg, sizeof(int)))
2037 /* get ost count when count is zero, get mdt count otherwise */
2038 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
2039 vallen = sizeof(count);
2040 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
2041 KEY_TGT_COUNT, &vallen, &count);
2043 CERROR("get target count failed: %d\n", rc);
2047 if (copy_to_user((int __user *)arg, &count, sizeof(int)))
2052 case LL_IOC_PATH2FID:
2053 if (copy_to_user((void __user *)arg, ll_inode2fid(inode),
2054 sizeof(struct lu_fid)))
2057 case LL_IOC_GET_CONNECT_FLAGS: {
2058 RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL,
2059 (void __user *)arg));
2061 case OBD_IOC_FID2PATH:
2062 RETURN(ll_fid2path(inode, (void __user *)arg));
2063 case LL_IOC_GETPARENT:
2064 RETURN(ll_getparent(file, (void __user *)arg));
2065 case LL_IOC_FID2MDTIDX: {
2066 struct obd_export *exp = ll_i2mdexp(inode);
2070 if (copy_from_user(&fid, (const struct lu_fid __user *)arg,
2074 /* Call mdc_iocontrol */
2075 rc = obd_iocontrol(LL_IOC_FID2MDTIDX, exp, sizeof(fid), &fid,
2076 (__u32 __user *)&index);
2082 case LL_IOC_HSM_REQUEST: {
2083 struct hsm_user_request *hur;
2090 /* We don't know the true size yet; copy the fixed-size part */
2091 if (copy_from_user(hur, (void __user *)arg, sizeof(*hur))) {
2096 /* Compute the whole struct size */
2097 totalsize = hur_len(hur);
2102 /* Final size will be more than double totalsize */
2103 if (totalsize >= MDS_MAXREQSIZE / 3)
2106 OBD_ALLOC_LARGE(hur, totalsize);
2110 /* Copy the whole struct */
2111 if (copy_from_user(hur, (void __user *)arg, totalsize))
2112 GOTO(out_hur, rc = -EFAULT);
2114 if (hur->hur_request.hr_action == HUA_RELEASE) {
2115 const struct lu_fid *fid;
2119 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
2120 fid = &hur->hur_user_item[i].hui_fid;
2121 f = search_inode_for_lustre(inode->i_sb, fid);
2127 rc = ll_hsm_release(f);
2133 rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
2138 OBD_FREE_LARGE(hur, totalsize);
2142 case LL_IOC_HSM_PROGRESS: {
2143 struct hsm_progress_kernel hpk;
2144 struct hsm_progress hp;
2146 if (copy_from_user(&hp, (void __user *)arg, sizeof(hp)))
2149 hpk.hpk_fid = hp.hp_fid;
2150 hpk.hpk_cookie = hp.hp_cookie;
2151 hpk.hpk_extent = hp.hp_extent;
2152 hpk.hpk_flags = hp.hp_flags;
2153 hpk.hpk_errval = hp.hp_errval;
2154 hpk.hpk_data_version = 0;
2156 /* File may not exist in Lustre; all progress
2157 * reported to Lustre root */
2158 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
2162 case LL_IOC_HSM_CT_START:
2163 if (!capable(CAP_SYS_ADMIN))
2166 rc = copy_and_ct_start(cmd, sbi->ll_md_exp,
2167 (struct lustre_kernelcomm __user *)arg);
2170 case LL_IOC_HSM_COPY_START: {
2171 struct hsm_copy *copy;
2174 OBD_ALLOC_PTR(copy);
2177 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
2182 rc = ll_ioc_copy_start(inode->i_sb, copy);
2183 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
2189 case LL_IOC_HSM_COPY_END: {
2190 struct hsm_copy *copy;
2193 OBD_ALLOC_PTR(copy);
2196 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
2201 rc = ll_ioc_copy_end(inode->i_sb, copy);
2202 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
2208 case LL_IOC_MIGRATE: {
2209 struct lmv_user_md *lum;
2216 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
2220 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
2221 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
2222 GOTO(migrate_free, rc = -EINVAL);
2224 filename = data->ioc_inlbuf1;
2225 namelen = data->ioc_inllen1;
2226 flags = data->ioc_type;
2228 if (namelen < 1 || namelen != strlen(filename) + 1) {
2229 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
2230 GOTO(migrate_free, rc = -EINVAL);
2233 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
2234 if (lum->lum_magic != LMV_USER_MAGIC &&
2235 lum->lum_magic != LMV_USER_MAGIC_SPECIFIC) {
2237 CERROR("%s: wrong lum magic %x: rc = %d\n",
2238 filename, lum->lum_magic, rc);
2239 GOTO(migrate_free, rc);
2242 rc = ll_migrate(inode, file, lum, filename, flags);
2244 OBD_FREE_LARGE(data, len);
2248 case FS_IOC_FSGETXATTR:
2249 RETURN(ll_ioctl_fsgetxattr(inode, cmd, arg));
2250 case FS_IOC_FSSETXATTR:
2251 RETURN(ll_ioctl_fssetxattr(inode, cmd, arg));
2252 case LL_IOC_PROJECT:
2253 RETURN(ll_ioctl_project(file, cmd, arg));
2254 case LL_IOC_PCC_DETACH_BY_FID: {
2255 struct lu_pcc_detach_fid *detach;
2257 struct inode *inode2;
2260 OBD_ALLOC_PTR(detach);
2264 if (copy_from_user(detach,
2265 (const struct lu_pcc_detach_fid __user *)arg,
2267 GOTO(out_detach, rc = -EFAULT);
2269 fid = &detach->pccd_fid;
2270 ino = cl_fid_build_ino(fid, ll_need_32bit_api(sbi));
2271 inode2 = ilookup5(inode->i_sb, ino, ll_test_inode_by_fid, fid);
2273 /* Target inode is not in inode cache, and PCC file
2274 * has aleady released, return immdiately.
2276 GOTO(out_detach, rc = 0);
2278 if (!S_ISREG(inode2->i_mode))
2279 GOTO(out_iput, rc = -EINVAL);
2281 if (!inode_owner_or_capable(&init_user_ns, inode2))
2282 GOTO(out_iput, rc = -EPERM);
2284 rc = pcc_ioctl_detach(inode2, detach->pccd_opt);
2288 OBD_FREE_PTR(detach);
2291 #ifdef HAVE_LUSTRE_CRYPTO
2292 case LL_IOC_SET_ENCRYPTION_POLICY:
2293 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2295 return llcrypt_ioctl_set_policy(file, (const void __user *)arg);
2296 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
2297 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2299 return llcrypt_ioctl_get_policy_ex(file, (void __user *)arg);
2300 case LL_IOC_ADD_ENCRYPTION_KEY:
2301 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2303 return llcrypt_ioctl_add_key(file, (void __user *)arg);
2304 case LL_IOC_REMOVE_ENCRYPTION_KEY:
2305 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2307 return llcrypt_ioctl_remove_key(file, (void __user *)arg);
2308 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
2309 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2311 return llcrypt_ioctl_remove_key_all_users(file,
2312 (void __user *)arg);
2313 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
2314 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2316 return llcrypt_ioctl_get_key_status(file, (void __user *)arg);
2319 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL,
2320 (void __user *)arg));
2324 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
2326 struct inode *inode = file->f_mapping->host;
2327 struct ll_file_data *fd = file->private_data;
2328 struct ll_sb_info *sbi = ll_i2sbi(inode);
2329 int api32 = ll_need_32bit_api(sbi);
2330 loff_t ret = -EINVAL;
2338 offset += file->f_pos;
2344 offset += LL_DIR_END_OFF_32BIT;
2346 offset += LL_DIR_END_OFF;
2353 ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
2354 (!api32 && offset <= LL_DIR_END_OFF))) {
2355 if (offset != file->f_pos) {
2358 hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
2359 if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
2360 (!api32 && offset == LL_DIR_END_OFF))
2361 fd->lfd_pos = MDS_DIR_END_OFF;
2362 else if (api32 && hash64)
2363 fd->lfd_pos = offset << 32;
2365 fd->lfd_pos = offset;
2366 file->f_pos = offset;
2367 file->f_version = 0;
2374 inode_unlock(inode);
2378 static int ll_dir_open(struct inode *inode, struct file *file)
2381 RETURN(ll_file_open(inode, file));
2384 static int ll_dir_release(struct inode *inode, struct file *file)
2387 RETURN(ll_file_release(inode, file));
2390 /* notify error if partially read striped directory */
2391 static int ll_dir_flush(struct file *file, fl_owner_t id)
2393 struct ll_file_data *lfd = file->private_data;
2394 int rc = lfd->fd_partial_readdir_rc;
2396 lfd->fd_partial_readdir_rc = 0;
2401 const struct file_operations ll_dir_operations = {
2402 .llseek = ll_dir_seek,
2403 .open = ll_dir_open,
2404 .release = ll_dir_release,
2405 .read = generic_read_dir,
2406 #ifdef HAVE_DIR_CONTEXT
2407 .iterate_shared = ll_iterate,
2409 .readdir = ll_readdir,
2411 .unlocked_ioctl = ll_dir_ioctl,
2413 .flush = ll_dir_flush,