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 <uapi/linux/llcrypt.h>
53 #include <lustre_lib.h>
54 #include <lustre_dlm.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 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_get_encryption_info(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(parent, &ibits, LCK_MINMODE))
372 pfid = *ll_inode2fid(parent);
375 /* If it can not find in cache, do lookup .. on the master
377 if (fid_is_zero(&pfid)) {
378 rc = ll_dir_get_parent_fid(inode, &pfid);
384 op_data = ll_prep_md_op_data(NULL, inode, inode, NULL, 0, 0,
385 LUSTRE_OPC_ANY, inode);
387 GOTO(out, rc = PTR_ERR(op_data));
389 /* foreign dirs are browsed out of Lustre */
390 if (unlikely(op_data->op_mea1 != NULL &&
391 op_data->op_mea1->lsm_md_magic == LMV_MAGIC_FOREIGN)) {
392 ll_finish_md_op_data(op_data);
396 op_data->op_fid3 = pfid;
398 #ifdef HAVE_DIR_CONTEXT
400 rc = ll_dir_read(inode, &pos, op_data, ctx, &partial_readdir_rc);
403 rc = ll_dir_read(inode, &pos, op_data, cookie, filldir,
404 &partial_readdir_rc);
407 if (!lfd->fd_partial_readdir_rc)
408 lfd->fd_partial_readdir_rc = partial_readdir_rc;
410 if (pos == MDS_DIR_END_OFF) {
412 pos = LL_DIR_END_OFF_32BIT;
414 pos = LL_DIR_END_OFF;
419 #ifdef HAVE_DIR_CONTEXT
424 ll_finish_md_op_data(op_data);
428 ll_stats_ops_tally(sbi, LPROC_LL_READDIR,
429 ktime_us_delta(ktime_get(), kstart));
435 * Create striped directory with specified stripe(@lump)
437 * \param[in] dparent the parent of the directory.
438 * \param[in] lump the specified stripes.
439 * \param[in] dirname the name of the directory.
440 * \param[in] mode the specified mode of the directory.
442 * \retval =0 if striped directory is being created successfully.
443 * <0 if the creation is failed.
445 static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
446 size_t len, const char *dirname, umode_t mode,
449 struct inode *parent = dparent->d_inode;
450 struct ptlrpc_request *request = NULL;
451 struct md_op_data *op_data;
452 struct ll_sb_info *sbi = ll_i2sbi(parent);
453 struct inode *inode = NULL;
454 struct dentry dentry = {
458 .len = strlen(dirname),
459 .hash = ll_full_name_hash(dparent, dirname,
463 bool encrypt = false;
468 if (unlikely(!lmv_user_magic_supported(lump->lum_magic)))
471 if (lump->lum_magic != LMV_MAGIC_FOREIGN) {
473 "VFS Op:inode="DFID"(%p) name %s stripe_offset %d, stripe_count: %u\n",
474 PFID(ll_inode2fid(parent)), parent, dirname,
475 (int)lump->lum_stripe_offset, lump->lum_stripe_count);
477 struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)lump;
480 "VFS Op:inode="DFID"(%p) name %s foreign, length %u, value '%.*s'\n",
481 PFID(ll_inode2fid(parent)), parent, dirname,
482 lfm->lfm_length, lfm->lfm_length, lfm->lfm_value);
485 if (lump->lum_stripe_count > 1 &&
486 !(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_DIR_STRIPE))
489 if (IS_DEADDIR(parent) &&
490 !OBD_FAIL_CHECK(OBD_FAIL_LLITE_NO_CHECK_DEAD))
493 /* MDS < 2.14 doesn't support 'crush' hash type, and cannot handle
494 * unknown hash if client doesn't set a valid one. switch to fnv_1a_64.
496 if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_CRUSH)) {
497 enum lmv_hash_type type = lump->lum_hash_type &
500 if (type >= LMV_HASH_TYPE_CRUSH ||
501 type == LMV_HASH_TYPE_UNKNOWN)
502 lump->lum_hash_type = (lump->lum_hash_type ^ type) |
503 LMV_HASH_TYPE_FNV_1A_64;
506 hash_flags = lump->lum_hash_type & ~LMV_HASH_TYPE_MASK;
507 if (hash_flags & ~LMV_HASH_FLAG_KNOWN)
510 if (unlikely(!lmv_user_magic_supported(cpu_to_le32(lump->lum_magic))))
511 lustre_swab_lmv_user_md(lump);
513 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
514 mode &= ~current_umask();
515 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
516 op_data = ll_prep_md_op_data(NULL, parent, NULL, dirname,
517 strlen(dirname), mode, LUSTRE_OPC_MKDIR,
520 RETURN(PTR_ERR(op_data));
522 op_data->op_dir_depth = ll_i2info(parent)->lli_dir_depth;
524 if (ll_sbi_has_encrypt(sbi) &&
525 (IS_ENCRYPTED(parent) ||
526 unlikely(llcrypt_dummy_context_enabled(parent)))) {
527 err = llcrypt_get_encryption_info(parent);
529 GOTO(out_op_data, err);
530 if (!llcrypt_has_encryption_key(parent))
531 GOTO(out_op_data, err = -ENOKEY);
535 if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
536 /* selinux_dentry_init_security() uses dentry->d_parent and name
537 * to determine the security context for the file. So our fake
538 * dentry should be real enough for this purpose. */
539 err = ll_dentry_init_security(&dentry, mode, &dentry.d_name,
540 &op_data->op_file_secctx_name,
541 &op_data->op_file_secctx,
542 &op_data->op_file_secctx_size);
544 GOTO(out_op_data, err);
548 err = llcrypt_inherit_context(parent, NULL, op_data, false);
550 GOTO(out_op_data, err);
553 op_data->op_cli_flags |= CLI_SET_MEA;
555 op_data->op_bias |= MDS_SETSTRIPE_CREATE;
557 err = md_create(sbi->ll_md_exp, op_data, lump, len, mode,
558 from_kuid(&init_user_ns, current_fsuid()),
559 from_kgid(&init_user_ns, current_fsgid()),
560 current_cap(), 0, &request);
562 GOTO(out_request, err);
564 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_SETDIRSTRIPE_PAUSE, cfs_fail_val);
566 err = ll_prep_inode(&inode, &request->rq_pill, parent->i_sb, NULL);
568 GOTO(out_inode, err);
570 dentry.d_inode = inode;
572 if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
573 /* no need to protect selinux_inode_setsecurity() by
574 * inode_lock. Taking it would lead to a client deadlock
577 err = security_inode_notifysecctx(inode,
578 op_data->op_file_secctx,
579 op_data->op_file_secctx_size);
581 err = ll_inode_init_security(&dentry, inode, parent);
584 GOTO(out_inode, err);
587 err = ll_set_encflags(inode, op_data->op_file_encctx,
588 op_data->op_file_encctx_size, false);
590 GOTO(out_inode, err);
596 ptlrpc_req_finished(request);
598 ll_finish_md_op_data(op_data);
603 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
606 struct ll_sb_info *sbi = ll_i2sbi(inode);
607 struct md_op_data *op_data;
608 struct ptlrpc_request *req = NULL;
614 switch (lump->lmm_magic) {
615 case LOV_USER_MAGIC_V1:
616 lum_size = sizeof(struct lov_user_md_v1);
618 case LOV_USER_MAGIC_V3:
619 lum_size = sizeof(struct lov_user_md_v3);
621 case LOV_USER_MAGIC_COMP_V1:
622 lum_size = ((struct lov_comp_md_v1 *)lump)->lcm_size;
624 case LMV_USER_MAGIC: {
625 struct lmv_user_md *lmv = (struct lmv_user_md *)lump;
627 /* MDS < 2.14 doesn't support 'crush' hash type, and
628 * cannot handle unknown hash if client doesn't set a
629 * valid one. switch to fnv_1a_64.
631 if (!(exp_connect_flags2(sbi->ll_md_exp) &
632 OBD_CONNECT2_CRUSH)) {
633 enum lmv_hash_type type = lmv->lum_hash_type &
636 if (type >= LMV_HASH_TYPE_CRUSH ||
637 type == LMV_HASH_TYPE_UNKNOWN)
639 (lmv->lum_hash_type ^ type) |
640 LMV_HASH_TYPE_FNV_1A_64;
642 if (lmv->lum_magic != cpu_to_le32(LMV_USER_MAGIC))
643 lustre_swab_lmv_user_md(lmv);
644 lum_size = sizeof(*lmv);
647 case LOV_USER_MAGIC_SPECIFIC: {
648 struct lov_user_md_v3 *v3 =
649 (struct lov_user_md_v3 *)lump;
650 if (v3->lmm_stripe_count > LOV_MAX_STRIPE_COUNT)
652 lum_size = lov_user_md_size(v3->lmm_stripe_count,
653 LOV_USER_MAGIC_SPECIFIC);
657 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
658 " %#08x != %#08x nor %#08x\n",
659 lump->lmm_magic, LOV_USER_MAGIC_V1,
665 * This is coming from userspace, so should be in
666 * local endian. But the MDS would like it in little
667 * endian, so we swab it before we send it.
669 if ((__swab32(lump->lmm_magic) & le32_to_cpu(LOV_MAGIC_MASK)) ==
670 le32_to_cpu(LOV_MAGIC_MAGIC))
671 lustre_swab_lov_user_md(lump, 0);
673 lum_size = sizeof(struct lov_user_md_v1);
676 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
677 LUSTRE_OPC_ANY, NULL);
679 RETURN(PTR_ERR(op_data));
681 /* swabbing is done in lov_setstripe() on server side */
682 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size, &req);
683 ll_finish_md_op_data(op_data);
684 ptlrpc_req_finished(req);
691 static int ll_dir_get_default_layout(struct inode *inode, void **plmm,
693 struct ptlrpc_request **request, u64 valid,
694 enum get_default_layout_type type)
696 struct ll_sb_info *sbi = ll_i2sbi(inode);
697 struct mdt_body *body;
698 struct lov_mds_md *lmm = NULL;
699 struct ptlrpc_request *req = NULL;
701 struct md_op_data *op_data;
705 rc = ll_get_default_mdsize(sbi, &lmm_size);
709 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
710 0, lmm_size, LUSTRE_OPC_ANY,
713 RETURN(PTR_ERR(op_data));
715 op_data->op_valid = valid | OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
717 if (type == GET_DEFAULT_LAYOUT_ROOT) {
718 lu_root_fid(&op_data->op_fid1);
719 fid = op_data->op_fid1;
721 fid = *ll_inode2fid(inode);
724 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
725 ll_finish_md_op_data(op_data);
727 CDEBUG(D_INFO, "md_getattr failed on inode "DFID": rc %d\n",
732 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
733 LASSERT(body != NULL);
735 lmm_size = body->mbo_eadatasize;
737 if (!(body->mbo_valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
739 GOTO(out, rc = -ENODATA);
742 lmm = req_capsule_server_sized_get(&req->rq_pill,
743 &RMF_MDT_MD, lmm_size);
744 LASSERT(lmm != NULL);
747 * This is coming from the MDS, so is probably in
748 * little endian. We convert it to host endian before
749 * passing it to userspace.
751 /* We don't swab objects for directories */
752 switch (le32_to_cpu(lmm->lmm_magic)) {
755 case LOV_MAGIC_COMP_V1:
756 case LOV_USER_MAGIC_SPECIFIC:
757 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
758 lustre_swab_lov_user_md((struct lov_user_md *)lmm, 0);
761 if (LMV_MAGIC != cpu_to_le32(LMV_MAGIC))
762 lustre_swab_lmv_mds_md((union lmv_mds_md *)lmm);
765 if (LMV_USER_MAGIC != cpu_to_le32(LMV_USER_MAGIC))
766 lustre_swab_lmv_user_md((struct lmv_user_md *)lmm);
768 case LMV_MAGIC_FOREIGN: {
769 struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)lmm;
771 if (LMV_MAGIC_FOREIGN != cpu_to_le32(LMV_MAGIC_FOREIGN)) {
772 __swab32s(&lfm->lfm_magic);
773 __swab32s(&lfm->lfm_length);
774 __swab32s(&lfm->lfm_type);
775 __swab32s(&lfm->lfm_flags);
780 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
785 *plmm_size = lmm_size;
791 * This function will be used to get default LOV/LMV/Default LMV
792 * @valid will be used to indicate which stripe it will retrieve.
793 * If the directory does not have its own default layout, then the
794 * function will request the default layout from root FID.
795 * OBD_MD_MEA LMV stripe EA
796 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
797 * otherwise Default LOV EA.
798 * Each time, it can only retrieve 1 stripe EA
800 int ll_dir_getstripe_default(struct inode *inode, void **plmm, int *plmm_size,
801 struct ptlrpc_request **request,
802 struct ptlrpc_request **root_request,
805 struct ptlrpc_request *req = NULL;
806 struct ptlrpc_request *root_req = NULL;
807 struct lov_mds_md *lmm = NULL;
812 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
814 if (rc == -ENODATA && !fid_is_root(ll_inode2fid(inode)) &&
815 !(valid & OBD_MD_MEA) && root_request != NULL) {
816 int rc2 = ll_dir_get_default_layout(inode, (void **)&lmm,
817 &lmm_size, &root_req, valid,
818 GET_DEFAULT_LAYOUT_ROOT);
824 *plmm_size = lmm_size;
826 if (root_request != NULL)
827 *root_request = root_req;
833 * This function will be used to get default LOV/LMV/Default LMV
834 * @valid will be used to indicate which stripe it will retrieve
835 * OBD_MD_MEA LMV stripe EA
836 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
837 * otherwise Default LOV EA.
838 * Each time, it can only retrieve 1 stripe EA
840 int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
841 struct ptlrpc_request **request, u64 valid)
843 struct ptlrpc_request *req = NULL;
844 struct lov_mds_md *lmm = NULL;
849 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
853 *plmm_size = lmm_size;
859 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid)
861 struct md_op_data *op_data;
866 OBD_ALLOC_PTR(op_data);
870 op_data->op_flags |= MF_GET_MDT_IDX;
871 op_data->op_fid1 = *fid;
872 rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
873 mdt_index = op_data->op_mds;
874 OBD_FREE_PTR(op_data);
882 * Get MDT index for the inode.
884 int ll_get_mdt_idx(struct inode *inode)
886 return ll_get_mdt_idx_by_fid(ll_i2sbi(inode), ll_inode2fid(inode));
890 * Generic handler to do any pre-copy work.
892 * It sends a first hsm_progress (with extent length == 0) to coordinator as a
893 * first information for it that real work has started.
895 * Moreover, for a ARCHIVE request, it will sample the file data version and
896 * store it in \a copy.
898 * \return 0 on success.
900 static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
902 struct ll_sb_info *sbi = ll_s2sbi(sb);
903 struct hsm_progress_kernel hpk;
908 /* Forge a hsm_progress based on data from copy. */
909 hpk.hpk_fid = copy->hc_hai.hai_fid;
910 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
911 hpk.hpk_extent.offset = copy->hc_hai.hai_extent.offset;
912 hpk.hpk_extent.length = 0;
915 hpk.hpk_data_version = 0;
918 /* For archive request, we need to read the current file version. */
919 if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
921 __u64 data_version = 0;
923 /* Get inode for this fid */
924 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
926 hpk.hpk_flags |= HP_FLAG_RETRY;
927 /* hpk_errval is >= 0 */
928 hpk.hpk_errval = -PTR_ERR(inode);
929 GOTO(progress, rc = PTR_ERR(inode));
932 /* Read current file data version */
933 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
936 CDEBUG(D_HSM, "Could not read file data version of "
937 DFID" (rc = %d). Archive request ("
938 "%#llx) could not be done.\n",
939 PFID(©->hc_hai.hai_fid), rc,
940 copy->hc_hai.hai_cookie);
941 hpk.hpk_flags |= HP_FLAG_RETRY;
942 /* hpk_errval must be >= 0 */
943 hpk.hpk_errval = -rc;
947 /* Store in the hsm_copy for later copytool use.
948 * Always modified even if no lsm. */
949 copy->hc_data_version = data_version;
953 /* On error, the request should be considered as completed */
954 if (hpk.hpk_errval > 0)
955 hpk.hpk_flags |= HP_FLAG_COMPLETED;
957 rc2 = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
960 /* Return first error */
961 RETURN(rc != 0 ? rc : rc2);
965 * Generic handler to do any post-copy work.
967 * It will send the last hsm_progress update to coordinator to inform it
968 * that copy is finished and whether it was successful or not.
971 * - for ARCHIVE request, it will sample the file data version and compare it
972 * with the version saved in ll_ioc_copy_start(). If they do not match, copy
973 * will be considered as failed.
974 * - for RESTORE request, it will sample the file data version and send it to
975 * coordinator which is useful if the file was imported as 'released'.
977 * \return 0 on success.
979 static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
981 struct ll_sb_info *sbi = ll_s2sbi(sb);
982 struct hsm_progress_kernel hpk;
987 /* If you modify the logic here, also check llapi_hsm_copy_end(). */
988 /* Take care: copy->hc_hai.hai_action, len, gid and data are not
989 * initialized if copy_end was called with copy == NULL.
992 /* Forge a hsm_progress based on data from copy. */
993 hpk.hpk_fid = copy->hc_hai.hai_fid;
994 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
995 hpk.hpk_extent = copy->hc_hai.hai_extent;
996 hpk.hpk_flags = copy->hc_flags | HP_FLAG_COMPLETED;
997 hpk.hpk_errval = copy->hc_errval;
998 hpk.hpk_data_version = 0;
1000 /* For archive request, we need to check the file data was not changed.
1002 * For restore request, we need to send the file data version, this is
1003 * useful when the file was created using hsm_import.
1005 if (((copy->hc_hai.hai_action == HSMA_ARCHIVE) ||
1006 (copy->hc_hai.hai_action == HSMA_RESTORE)) &&
1007 (copy->hc_errval == 0)) {
1008 struct inode *inode;
1009 __u64 data_version = 0;
1011 /* Get lsm for this fid */
1012 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
1013 if (IS_ERR(inode)) {
1014 hpk.hpk_flags |= HP_FLAG_RETRY;
1015 /* hpk_errval must be >= 0 */
1016 hpk.hpk_errval = -PTR_ERR(inode);
1017 GOTO(progress, rc = PTR_ERR(inode));
1020 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
1023 CDEBUG(D_HSM, "Could not read file data version. "
1024 "Request could not be confirmed.\n");
1025 if (hpk.hpk_errval == 0)
1026 hpk.hpk_errval = -rc;
1030 /* Store in the hsm_copy for later copytool use.
1031 * Always modified even if no lsm. */
1032 hpk.hpk_data_version = data_version;
1034 /* File could have been stripped during archiving, so we need
1035 * to check anyway. */
1036 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
1037 (copy->hc_data_version != data_version)) {
1038 CDEBUG(D_HSM, "File data version mismatched. "
1039 "File content was changed during archiving. "
1040 DFID", start:%#llx current:%#llx\n",
1041 PFID(©->hc_hai.hai_fid),
1042 copy->hc_data_version, data_version);
1043 /* File was changed, send error to cdt. Do not ask for
1044 * retry because if a file is modified frequently,
1045 * the cdt will loop on retried archive requests.
1046 * The policy engine will ask for a new archive later
1047 * when the file will not be modified for some tunable
1049 hpk.hpk_flags &= ~HP_FLAG_RETRY;
1051 /* hpk_errval must be >= 0 */
1052 hpk.hpk_errval = -rc;
1059 rc2 = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
1062 /* Return first error */
1063 RETURN(rc != 0 ? rc : rc2);
1067 static int copy_and_ct_start(int cmd, struct obd_export *exp,
1068 const struct lustre_kernelcomm __user *data)
1070 struct lustre_kernelcomm *lk;
1071 struct lustre_kernelcomm *tmp;
1072 size_t size = sizeof(*lk);
1077 /* copy data from userspace to get numbers of archive_id */
1078 OBD_ALLOC(lk, size);
1082 if (copy_from_user(lk, data, size))
1083 GOTO(out_lk, rc = -EFAULT);
1085 if (lk->lk_flags & LK_FLG_STOP)
1088 if (!(lk->lk_flags & LK_FLG_DATANR)) {
1089 __u32 archive_mask = lk->lk_data_count;
1092 /* old hsm agent to old MDS */
1093 if (!exp_connect_archive_id_array(exp))
1096 /* old hsm agent to new MDS */
1097 lk->lk_flags |= LK_FLG_DATANR;
1099 if (archive_mask == 0)
1102 count = hweight32(archive_mask);
1103 new_size = offsetof(struct lustre_kernelcomm, lk_data[count]);
1104 OBD_ALLOC(tmp, new_size);
1106 GOTO(out_lk, rc = -ENOMEM);
1108 memcpy(tmp, lk, size);
1109 tmp->lk_data_count = count;
1115 for (i = 0; i < sizeof(archive_mask) * 8; i++) {
1116 if (BIT(i) & archive_mask) {
1117 lk->lk_data[count] = i + 1;
1124 /* new hsm agent to new mds */
1125 if (lk->lk_data_count > 0) {
1126 new_size = offsetof(struct lustre_kernelcomm,
1127 lk_data[lk->lk_data_count]);
1128 OBD_ALLOC(tmp, new_size);
1130 GOTO(out_lk, rc = -ENOMEM);
1136 if (copy_from_user(lk, data, size))
1137 GOTO(out_lk, rc = -EFAULT);
1140 /* new hsm agent to old MDS */
1141 if (!exp_connect_archive_id_array(exp)) {
1144 if (lk->lk_data_count > LL_HSM_ORIGIN_MAX_ARCHIVE)
1145 GOTO(out_lk, rc = -EINVAL);
1147 for (i = 0; i < lk->lk_data_count; i++) {
1148 if (lk->lk_data[i] > LL_HSM_ORIGIN_MAX_ARCHIVE) {
1150 CERROR("%s: archive id %d requested but only "
1151 "[0 - %zu] supported: rc = %d\n",
1152 exp->exp_obd->obd_name, lk->lk_data[i],
1153 LL_HSM_ORIGIN_MAX_ARCHIVE, rc);
1157 if (lk->lk_data[i] == 0) {
1162 archives |= (1 << (lk->lk_data[i] - 1));
1164 lk->lk_flags &= ~LK_FLG_DATANR;
1165 lk->lk_data_count = archives;
1168 rc = obd_iocontrol(cmd, exp, size, lk, NULL);
1174 static int check_owner(int type, int id)
1178 if (!uid_eq(current_euid(), make_kuid(&init_user_ns, id)))
1182 if (!in_egroup_p(make_kgid(&init_user_ns, id)))
1191 int quotactl_ioctl(struct super_block *sb, struct if_quotactl *qctl)
1193 struct ll_sb_info *sbi = ll_s2sbi(sb);
1194 int cmd = qctl->qc_cmd;
1195 int type = qctl->qc_type;
1196 int id = qctl->qc_id;
1197 int valid = qctl->qc_valid;
1205 case LUSTRE_Q_SETDEFAULT:
1206 case LUSTRE_Q_SETQUOTAPOOL:
1207 case LUSTRE_Q_SETINFOPOOL:
1208 case LUSTRE_Q_SETDEFAULT_POOL:
1209 case LUSTRE_Q_DELETEQID:
1210 if (!capable(CAP_SYS_ADMIN))
1213 if (sb->s_flags & SB_RDONLY)
1217 case LUSTRE_Q_GETDEFAULT:
1218 case LUSTRE_Q_GETQUOTAPOOL:
1219 case LUSTRE_Q_GETDEFAULT_POOL:
1220 if (check_owner(type, id) &&
1221 (!capable(CAP_SYS_ADMIN)))
1225 case LUSTRE_Q_GETINFOPOOL:
1228 CERROR("unsupported quotactl op: %#x\n", cmd);
1232 if (valid != QC_GENERAL) {
1233 if (cmd == Q_GETINFO)
1234 qctl->qc_cmd = Q_GETOINFO;
1235 else if (cmd == Q_GETQUOTA ||
1236 cmd == LUSTRE_Q_GETQUOTAPOOL)
1237 qctl->qc_cmd = Q_GETOQUOTA;
1243 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
1244 sizeof(*qctl), qctl, NULL);
1247 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
1248 sizeof(*qctl), qctl, NULL);
1251 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
1252 sizeof(*qctl), qctl, NULL);
1254 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1256 sizeof(*qctl), qctl, NULL);
1268 struct obd_quotactl *oqctl;
1269 int oqctl_len = sizeof(*oqctl);
1271 if (LUSTRE_Q_CMD_IS_POOL(cmd))
1272 oqctl_len += LOV_MAXPOOLNAME + 1;
1274 OBD_ALLOC(oqctl, oqctl_len);
1278 QCTL_COPY(oqctl, qctl);
1279 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1281 OBD_FREE(oqctl, oqctl_len);
1284 /* If QIF_SPACE is not set, client should collect the
1285 * space usage from OSSs by itself */
1286 if ((cmd == Q_GETQUOTA || cmd == LUSTRE_Q_GETQUOTAPOOL) &&
1287 !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
1288 !oqctl->qc_dqblk.dqb_curspace) {
1289 struct obd_quotactl *oqctl_tmp;
1290 int qctl_len = sizeof(*oqctl_tmp) + LOV_MAXPOOLNAME + 1;
1292 OBD_ALLOC(oqctl_tmp, qctl_len);
1293 if (oqctl_tmp == NULL)
1294 GOTO(out, rc = -ENOMEM);
1296 if (cmd == LUSTRE_Q_GETQUOTAPOOL) {
1297 oqctl_tmp->qc_cmd = LUSTRE_Q_GETQUOTAPOOL;
1298 memcpy(oqctl_tmp->qc_poolname,
1300 LOV_MAXPOOLNAME + 1);
1302 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1304 oqctl_tmp->qc_id = oqctl->qc_id;
1305 oqctl_tmp->qc_type = oqctl->qc_type;
1307 /* collect space usage from OSTs */
1308 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1309 rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
1310 if (!rc || rc == -EREMOTEIO) {
1311 oqctl->qc_dqblk.dqb_curspace =
1312 oqctl_tmp->qc_dqblk.dqb_curspace;
1313 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
1316 /* collect space & inode usage from MDTs */
1317 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1318 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1319 oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
1320 rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
1321 if (!rc || rc == -EREMOTEIO) {
1322 oqctl->qc_dqblk.dqb_curspace +=
1323 oqctl_tmp->qc_dqblk.dqb_curspace;
1324 oqctl->qc_dqblk.dqb_curinodes =
1325 oqctl_tmp->qc_dqblk.dqb_curinodes;
1326 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
1328 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
1331 OBD_FREE(oqctl_tmp, qctl_len);
1334 QCTL_COPY(qctl, oqctl);
1335 OBD_FREE(oqctl, oqctl_len);
1341 int ll_rmfid(struct file *file, void __user *arg)
1343 const struct fid_array __user *ufa = arg;
1344 struct inode *inode = file_inode(file);
1345 struct fid_array *lfa = NULL;
1348 int i, rc, *rcs = NULL;
1351 if (!capable(CAP_DAC_READ_SEARCH) &&
1352 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
1354 /* Only need to get the buflen */
1355 if (get_user(nr, &ufa->fa_nr))
1357 /* DoS protection */
1358 if (nr > OBD_MAX_FIDS_IN_ARRAY)
1361 size = offsetof(struct fid_array, fa_fids[nr]);
1362 OBD_ALLOC(lfa, size);
1365 OBD_ALLOC_PTR_ARRAY(rcs, nr);
1367 GOTO(free_lfa, rc = -ENOMEM);
1369 if (copy_from_user(lfa, arg, size))
1370 GOTO(free_rcs, rc = -EFAULT);
1372 /* Call mdc_iocontrol */
1373 rc = md_rmfid(ll_i2mdexp(file_inode(file)), lfa, rcs, NULL);
1375 for (i = 0; i < nr; i++)
1377 lfa->fa_fids[i].f_ver = rcs[i];
1378 if (copy_to_user(arg, lfa, size))
1383 OBD_FREE_PTR_ARRAY(rcs, nr);
1385 OBD_FREE(lfa, size);
1390 /* This function tries to get a single name component,
1391 * to send to the server. No actual path traversal involved,
1392 * so we limit to NAME_MAX */
1393 static char *ll_getname(const char __user *filename)
1398 OBD_ALLOC(tmp, NAME_MAX + 1);
1401 return ERR_PTR(-ENOMEM);
1403 len = strncpy_from_user(tmp, filename, NAME_MAX + 1);
1406 else if (len > NAME_MAX)
1407 ret = -ENAMETOOLONG;
1410 OBD_FREE(tmp, NAME_MAX + 1);
1416 #define ll_putname(filename) OBD_FREE(filename, NAME_MAX + 1);
1418 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1420 struct dentry *dentry = file_dentry(file);
1421 struct inode *inode = file_inode(file);
1422 struct ll_sb_info *sbi = ll_i2sbi(inode);
1423 struct obd_ioctl_data *data = NULL;
1427 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%#x\n",
1428 PFID(ll_inode2fid(inode)), inode, cmd);
1430 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
1431 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
1434 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
1436 case FS_IOC_GETFLAGS:
1437 case FS_IOC_SETFLAGS:
1438 RETURN(ll_iocontrol(inode, file, cmd, arg));
1439 case FSFILT_IOC_GETVERSION:
1440 case FS_IOC_GETVERSION:
1441 RETURN(put_user(inode->i_generation, (int __user *)arg));
1442 /* We need to special case any other ioctls we want to handle,
1443 * to send them to the MDS/OST as appropriate and to properly
1444 * network encode the arg field. */
1445 case FS_IOC_SETVERSION:
1448 case LL_IOC_GET_MDTIDX: {
1451 mdtidx = ll_get_mdt_idx(inode);
1455 if (put_user((int)mdtidx, (int __user *)arg))
1460 case IOC_MDC_LOOKUP: {
1461 int namelen, len = 0;
1464 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
1468 filename = data->ioc_inlbuf1;
1469 namelen = strlen(filename);
1471 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1472 GOTO(out_free, rc = -EINVAL);
1475 rc = ll_get_fid_by_name(inode, filename, namelen, NULL, NULL);
1477 CERROR("%s: lookup %.*s failed: rc = %d\n",
1478 sbi->ll_fsname, namelen, filename, rc);
1482 OBD_FREE_LARGE(data, len);
1485 case LL_IOC_LMV_SETSTRIPE: {
1486 struct lmv_user_md *lum;
1491 bool createonly = false;
1495 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
1499 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1500 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1501 GOTO(lmv_out_free, rc = -EINVAL);
1503 filename = data->ioc_inlbuf1;
1504 namelen = data->ioc_inllen1;
1507 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1508 GOTO(lmv_out_free, rc = -EINVAL);
1510 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1511 lumlen = data->ioc_inllen2;
1513 if (!lmv_user_magic_supported(lum->lum_magic)) {
1514 CERROR("%s: wrong lum magic %x : rc = %d\n", filename,
1515 lum->lum_magic, -EINVAL);
1516 GOTO(lmv_out_free, rc = -EINVAL);
1519 if ((lum->lum_magic == LMV_USER_MAGIC ||
1520 lum->lum_magic == LMV_USER_MAGIC_SPECIFIC) &&
1521 lumlen < sizeof(*lum)) {
1522 CERROR("%s: wrong lum size %d for magic %x : rc = %d\n",
1523 filename, lumlen, lum->lum_magic, -EINVAL);
1524 GOTO(lmv_out_free, rc = -EINVAL);
1527 if (lum->lum_magic == LMV_MAGIC_FOREIGN &&
1528 lumlen < sizeof(struct lmv_foreign_md)) {
1529 CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1530 filename, lum->lum_magic, lumlen, -EFAULT);
1531 GOTO(lmv_out_free, rc = -EINVAL);
1534 mode = data->ioc_type;
1535 createonly = data->ioc_obdo1.o_flags & OBD_FL_OBDMDEXISTS;
1536 rc = ll_dir_setdirstripe(dentry, lum, lumlen, filename, mode,
1539 OBD_FREE_LARGE(data, len);
1543 case LL_IOC_LMV_SET_DEFAULT_STRIPE: {
1544 struct lmv_user_md lum;
1545 struct lmv_user_md __user *ulump =
1546 (struct lmv_user_md __user *)arg;
1549 if (copy_from_user(&lum, ulump, sizeof(lum)))
1552 if (lum.lum_magic != LMV_USER_MAGIC)
1555 rc = ll_dir_setstripe(inode, (struct lov_user_md *)&lum, 0);
1559 case LL_IOC_LOV_SETSTRIPE_NEW:
1560 case LL_IOC_LOV_SETSTRIPE: {
1561 struct lov_user_md_v3 *lumv3 = NULL;
1562 struct lov_user_md_v1 lumv1;
1563 struct lov_user_md_v1 *lumv1_ptr = &lumv1;
1564 struct lov_user_md_v1 __user *lumv1p =
1565 (struct lov_user_md_v1 __user *)arg;
1566 struct lov_user_md_v3 __user *lumv3p =
1567 (struct lov_user_md_v3 __user *)arg;
1570 int set_default = 0;
1572 BUILD_BUG_ON(sizeof(struct lov_user_md_v3) <=
1573 sizeof(struct lov_comp_md_v1));
1574 BUILD_BUG_ON(sizeof(*lumv3) != sizeof(*lumv3p));
1575 /* first try with v1 which is smaller than v3 */
1576 if (copy_from_user(&lumv1, lumv1p, sizeof(lumv1)))
1579 if (is_root_inode(inode))
1582 switch (lumv1.lmm_magic) {
1583 case LOV_USER_MAGIC_V3:
1584 case LOV_USER_MAGIC_SPECIFIC:
1585 lum_size = ll_lov_user_md_size(&lumv1);
1588 OBD_ALLOC(lumv3, lum_size);
1591 if (copy_from_user(lumv3, lumv3p, lum_size))
1592 GOTO(out, rc = -EFAULT);
1593 lumv1_ptr = (struct lov_user_md_v1 *)lumv3;
1595 case LOV_USER_MAGIC_V1:
1598 GOTO(out, rc = -ENOTSUPP);
1601 /* in v1 and v3 cases lumv1 points to data */
1602 rc = ll_dir_setstripe(inode, lumv1_ptr, set_default);
1605 OBD_FREE(lumv3, lum_size);
1608 case LL_IOC_LMV_GETSTRIPE: {
1609 struct lmv_user_md __user *ulmv =
1610 (struct lmv_user_md __user *)arg;
1611 struct lmv_user_md lum;
1612 struct ptlrpc_request *request = NULL;
1613 struct ptlrpc_request *root_request = NULL;
1614 union lmv_mds_md *lmm = NULL;
1617 struct lmv_user_md *tmp = NULL;
1621 int max_stripe_count;
1625 if (copy_from_user(&lum, ulmv, sizeof(*ulmv)))
1628 max_stripe_count = lum.lum_stripe_count;
1629 /* lum_magic will indicate which stripe the ioctl will like
1630 * to get, LMV_MAGIC_V1 is for normal LMV stripe, LMV_USER_MAGIC
1631 * is for default LMV stripe */
1632 if (lum.lum_magic == LMV_MAGIC_V1)
1633 valid |= OBD_MD_MEA;
1634 else if (lum.lum_magic == LMV_USER_MAGIC)
1635 valid |= OBD_MD_DEFAULT_MEA;
1639 rc = ll_dir_getstripe_default(inode, (void **)&lmm, &lmmsize,
1640 &request, &root_request, valid);
1642 GOTO(finish_req, rc);
1644 /* Get default LMV EA */
1645 if (lum.lum_magic == LMV_USER_MAGIC) {
1646 if (lmmsize > sizeof(*ulmv))
1647 GOTO(finish_req, rc = -EINVAL);
1649 if (root_request != NULL) {
1650 struct lmv_user_md *lum;
1651 struct ll_inode_info *lli;
1653 lum = (struct lmv_user_md *)lmm;
1654 lli = ll_i2info(inode);
1655 if (lum->lum_max_inherit == LMV_INHERIT_NONE ||
1656 (lum->lum_max_inherit > 0 &&
1657 lum->lum_max_inherit < lli->lli_dir_depth))
1658 GOTO(finish_req, rc = -ENODATA);
1660 if (lum->lum_max_inherit ==
1661 lli->lli_dir_depth) {
1662 lum->lum_max_inherit = LMV_INHERIT_NONE;
1663 lum->lum_max_inherit_rr =
1664 LMV_INHERIT_RR_NONE;
1667 if (lum->lum_max_inherit > lli->lli_dir_depth &&
1668 lum->lum_max_inherit <= LMV_INHERIT_MAX)
1669 lum->lum_max_inherit -=
1672 if (lum->lum_max_inherit_rr >
1673 lli->lli_dir_depth &&
1674 lum->lum_max_inherit_rr <=
1676 lum->lum_max_inherit_rr -=
1678 else if (lum->lum_max_inherit_rr ==
1680 lum->lum_max_inherit_rr =
1681 LMV_INHERIT_RR_NONE;
1684 if (copy_to_user(ulmv, lmm, lmmsize))
1685 GOTO(finish_req, rc = -EFAULT);
1687 GOTO(finish_req, rc);
1690 /* if foreign LMV case, fake stripes number */
1691 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1692 struct lmv_foreign_md *lfm;
1694 lfm = (struct lmv_foreign_md *)lmm;
1695 if (lfm->lfm_length < XATTR_SIZE_MAX -
1696 offsetof(typeof(*lfm), lfm_value)) {
1697 __u32 size = lfm->lfm_length +
1698 offsetof(typeof(*lfm), lfm_value);
1700 stripe_count = lmv_foreign_to_md_stripes(size);
1702 CERROR("invalid %d foreign size returned\n",
1707 stripe_count = lmv_mds_md_stripe_count_get(lmm);
1709 if (max_stripe_count < stripe_count) {
1710 lum.lum_stripe_count = stripe_count;
1711 if (copy_to_user(ulmv, &lum, sizeof(lum)))
1712 GOTO(finish_req, rc = -EFAULT);
1713 GOTO(finish_req, rc = -E2BIG);
1716 /* enough room on user side and foreign case */
1717 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1718 struct lmv_foreign_md *lfm;
1721 lfm = (struct lmv_foreign_md *)lmm;
1722 size = lfm->lfm_length +
1723 offsetof(struct lmv_foreign_md, lfm_value);
1724 if (copy_to_user(ulmv, lfm, size))
1725 GOTO(finish_req, rc = -EFAULT);
1726 GOTO(finish_req, rc);
1729 lum_size = lmv_user_md_size(stripe_count,
1730 LMV_USER_MAGIC_SPECIFIC);
1731 OBD_ALLOC(tmp, lum_size);
1733 GOTO(finish_req, rc = -ENOMEM);
1735 mdt_index = ll_get_mdt_idx(inode);
1737 GOTO(out_tmp, rc = -ENOMEM);
1739 tmp->lum_magic = LMV_MAGIC_V1;
1740 tmp->lum_stripe_count = 0;
1741 tmp->lum_stripe_offset = mdt_index;
1742 tmp->lum_hash_type = lmv_mds_md_hash_type_get(lmm);
1743 for (i = 0; i < stripe_count; i++) {
1746 fid_le_to_cpu(&fid, &lmm->lmv_md_v1.lmv_stripe_fids[i]);
1747 if (fid_is_sane(&fid)) {
1748 mdt_index = ll_get_mdt_idx_by_fid(sbi, &fid);
1750 GOTO(out_tmp, rc = mdt_index);
1752 tmp->lum_objects[i].lum_mds = mdt_index;
1753 tmp->lum_objects[i].lum_fid = fid;
1756 tmp->lum_stripe_count++;
1759 if (copy_to_user(ulmv, tmp, lum_size))
1760 GOTO(out_tmp, rc = -EFAULT);
1762 OBD_FREE(tmp, lum_size);
1764 ptlrpc_req_finished(request);
1765 ptlrpc_req_finished(root_request);
1769 case LL_IOC_UNLOCK_FOREIGN:
1770 /* if not a foreign symlink do nothing */
1771 if (ll_foreign_is_removable(dentry, true)) {
1773 "prevent rmdir of non-foreign dir ("DFID")\n",
1774 PFID(ll_inode2fid(inode)));
1775 RETURN(-EOPNOTSUPP);
1779 case LL_IOC_REMOVE_ENTRY: {
1780 char *filename = NULL;
1784 /* Here is a little hack to avoid sending REINT_RMENTRY to
1785 * unsupported server, which might crash the server(LU-2730),
1786 * Because both LVB_TYPE and REINT_RMENTRY will be supported
1787 * on 2.4, we use OBD_CONNECT_LVB_TYPE to detect whether the
1788 * server will support REINT_RMENTRY XXX*/
1789 if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE))
1792 filename = ll_getname((const char __user *)arg);
1793 if (IS_ERR(filename))
1794 RETURN(PTR_ERR(filename));
1796 namelen = strlen(filename);
1798 GOTO(out_rmdir, rc = -EINVAL);
1800 rc = ll_rmdir_entry(inode, filename, namelen);
1803 ll_putname(filename);
1807 RETURN(ll_rmfid(file, (void __user *)arg));
1808 case LL_IOC_LOV_SWAP_LAYOUTS:
1810 case IOC_OBD_STATFS:
1811 RETURN(ll_obd_statfs(inode, (void __user *)arg));
1812 case LL_IOC_LOV_GETSTRIPE:
1813 case LL_IOC_LOV_GETSTRIPE_NEW:
1814 case LL_IOC_MDC_GETINFO_V1:
1815 case LL_IOC_MDC_GETINFO_V2:
1816 case IOC_MDC_GETFILEINFO_V1:
1817 case IOC_MDC_GETFILEINFO_V2:
1818 case IOC_MDC_GETFILESTRIPE: {
1819 struct ptlrpc_request *request = NULL;
1820 struct ptlrpc_request *root_request = NULL;
1821 struct lov_user_md __user *lump;
1822 struct lov_mds_md *lmm = NULL;
1823 struct mdt_body *body;
1824 char *filename = NULL;
1825 lstat_t __user *statp = NULL;
1826 lstatx_t __user *stxp = NULL;
1827 __u64 __user *flagsp = NULL;
1828 __u32 __user *lmmsizep = NULL;
1829 struct lu_fid __user *fidp = NULL;
1833 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1834 cmd == IOC_MDC_GETFILEINFO_V2 ||
1835 cmd == IOC_MDC_GETFILESTRIPE) {
1836 filename = ll_getname((const char __user *)arg);
1837 if (IS_ERR(filename))
1838 RETURN(PTR_ERR(filename));
1840 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1841 &lmmsize, &request);
1843 rc = ll_dir_getstripe_default(inode, (void **)&lmm,
1849 body = req_capsule_server_get(&request->rq_pill,
1851 LASSERT(body != NULL);
1856 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO_V1 ||
1857 cmd == LL_IOC_MDC_GETINFO_V1 ||
1858 cmd == IOC_MDC_GETFILEINFO_V2 ||
1859 cmd == LL_IOC_MDC_GETINFO_V2)) {
1867 if (cmd == IOC_MDC_GETFILESTRIPE ||
1868 cmd == LL_IOC_LOV_GETSTRIPE ||
1869 cmd == LL_IOC_LOV_GETSTRIPE_NEW) {
1870 lump = (struct lov_user_md __user *)arg;
1871 } else if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1872 cmd == LL_IOC_MDC_GETINFO_V1){
1873 struct lov_user_mds_data_v1 __user *lmdp;
1875 lmdp = (struct lov_user_mds_data_v1 __user *)arg;
1876 statp = &lmdp->lmd_st;
1877 lump = &lmdp->lmd_lmm;
1879 struct lov_user_mds_data __user *lmdp;
1881 lmdp = (struct lov_user_mds_data __user *)arg;
1882 fidp = &lmdp->lmd_fid;
1883 stxp = &lmdp->lmd_stx;
1884 flagsp = &lmdp->lmd_flags;
1885 lmmsizep = &lmdp->lmd_lmmsize;
1886 lump = &lmdp->lmd_lmm;
1890 /* If the file has no striping then zero out *lump so
1891 * that the caller isn't confused by garbage. */
1892 if (clear_user(lump, sizeof(*lump)))
1893 GOTO(out_req, rc = -EFAULT);
1894 } else if (copy_to_user(lump, lmm, lmmsize)) {
1895 if (copy_to_user(lump, lmm, sizeof(*lump)))
1896 GOTO(out_req, rc = -EFAULT);
1899 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
1901 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1902 cmd == LL_IOC_MDC_GETINFO_V1) {
1905 st.st_dev = inode->i_sb->s_dev;
1906 st.st_mode = body->mbo_mode;
1907 st.st_nlink = body->mbo_nlink;
1908 st.st_uid = body->mbo_uid;
1909 st.st_gid = body->mbo_gid;
1910 st.st_rdev = body->mbo_rdev;
1911 if (llcrypt_require_key(inode) == -ENOKEY)
1912 st.st_size = round_up(st.st_size,
1913 LUSTRE_ENCRYPTION_UNIT_SIZE);
1915 st.st_size = body->mbo_size;
1916 st.st_blksize = PAGE_SIZE;
1917 st.st_blocks = body->mbo_blocks;
1918 st.st_atime = body->mbo_atime;
1919 st.st_mtime = body->mbo_mtime;
1920 st.st_ctime = body->mbo_ctime;
1921 st.st_ino = cl_fid_build_ino(&body->mbo_fid1,
1924 if (copy_to_user(statp, &st, sizeof(st)))
1925 GOTO(out_req, rc = -EFAULT);
1926 } else if (cmd == IOC_MDC_GETFILEINFO_V2 ||
1927 cmd == LL_IOC_MDC_GETINFO_V2) {
1928 lstatx_t stx = { 0 };
1929 __u64 valid = body->mbo_valid;
1931 stx.stx_blksize = PAGE_SIZE;
1932 stx.stx_nlink = body->mbo_nlink;
1933 stx.stx_uid = body->mbo_uid;
1934 stx.stx_gid = body->mbo_gid;
1935 stx.stx_mode = body->mbo_mode;
1936 stx.stx_ino = cl_fid_build_ino(&body->mbo_fid1,
1938 if (llcrypt_require_key(inode) == -ENOKEY)
1939 stx.stx_size = round_up(stx.stx_size,
1940 LUSTRE_ENCRYPTION_UNIT_SIZE);
1942 stx.stx_size = body->mbo_size;
1943 stx.stx_blocks = body->mbo_blocks;
1944 stx.stx_atime.tv_sec = body->mbo_atime;
1945 stx.stx_ctime.tv_sec = body->mbo_ctime;
1946 stx.stx_mtime.tv_sec = body->mbo_mtime;
1947 stx.stx_btime.tv_sec = body->mbo_btime;
1948 stx.stx_rdev_major = MAJOR(body->mbo_rdev);
1949 stx.stx_rdev_minor = MINOR(body->mbo_rdev);
1950 stx.stx_dev_major = MAJOR(inode->i_sb->s_dev);
1951 stx.stx_dev_minor = MINOR(inode->i_sb->s_dev);
1952 stx.stx_mask |= STATX_BASIC_STATS | STATX_BTIME;
1955 * For a striped directory, the size and blocks returned
1956 * from MDT is not correct.
1957 * The size and blocks are aggregated by client across
1959 * Thus for a striped directory, do not return the valid
1960 * FLSIZE and FLBLOCKS flags to the caller.
1961 * However, this whould be better decided by the MDS
1962 * instead of the client.
1964 if (cmd == LL_IOC_MDC_GETINFO_V2 &&
1965 ll_i2info(inode)->lli_lsm_md != NULL)
1966 valid &= ~(OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
1968 if (flagsp && copy_to_user(flagsp, &valid,
1970 GOTO(out_req, rc = -EFAULT);
1972 if (fidp && copy_to_user(fidp, &body->mbo_fid1,
1974 GOTO(out_req, rc = -EFAULT);
1976 if (!(valid & OBD_MD_FLSIZE))
1977 stx.stx_mask &= ~STATX_SIZE;
1978 if (!(valid & OBD_MD_FLBLOCKS))
1979 stx.stx_mask &= ~STATX_BLOCKS;
1981 if (stxp && copy_to_user(stxp, &stx, sizeof(stx)))
1982 GOTO(out_req, rc = -EFAULT);
1984 if (lmmsizep && copy_to_user(lmmsizep, &lmmsize,
1986 GOTO(out_req, rc = -EFAULT);
1991 ptlrpc_req_finished(request);
1992 ptlrpc_req_finished(root_request);
1994 ll_putname(filename);
1997 case OBD_IOC_QUOTACTL: {
1998 struct if_quotactl *qctl;
1999 int qctl_len = sizeof(*qctl) + LOV_MAXPOOLNAME + 1;
2001 OBD_ALLOC(qctl, qctl_len);
2005 if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl)))
2006 GOTO(out_quotactl, rc = -EFAULT);
2008 if (LUSTRE_Q_CMD_IS_POOL(qctl->qc_cmd)) {
2009 char __user *from = (char __user *)arg +
2010 offsetof(typeof(*qctl), qc_poolname);
2011 if (copy_from_user(qctl->qc_poolname, from,
2012 LOV_MAXPOOLNAME + 1))
2013 GOTO(out_quotactl, rc = -EFAULT);
2016 rc = quotactl_ioctl(inode->i_sb, qctl);
2018 copy_to_user((void __user *)arg, qctl, sizeof(*qctl)))
2022 OBD_FREE(qctl, qctl_len);
2025 case OBD_IOC_GETNAME_OLD:
2026 case OBD_IOC_GETDTNAME:
2027 case OBD_IOC_GETMDNAME:
2028 RETURN(ll_get_obd_name(inode, cmd, arg));
2029 case LL_IOC_FLUSHCTX:
2030 RETURN(ll_flush_ctx(inode));
2031 case LL_IOC_GETOBDCOUNT: {
2033 struct obd_export *exp;
2035 if (copy_from_user(&count, (int __user *)arg, sizeof(int)))
2038 /* get ost count when count is zero, get mdt count otherwise */
2039 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
2040 vallen = sizeof(count);
2041 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
2042 KEY_TGT_COUNT, &vallen, &count);
2044 CERROR("get target count failed: %d\n", rc);
2048 if (copy_to_user((int __user *)arg, &count, sizeof(int)))
2053 case LL_IOC_PATH2FID:
2054 if (copy_to_user((void __user *)arg, ll_inode2fid(inode),
2055 sizeof(struct lu_fid)))
2058 case LL_IOC_GET_CONNECT_FLAGS: {
2059 RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL,
2060 (void __user *)arg));
2062 case OBD_IOC_FID2PATH:
2063 RETURN(ll_fid2path(inode, (void __user *)arg));
2064 case LL_IOC_GETPARENT:
2065 RETURN(ll_getparent(file, (void __user *)arg));
2066 case LL_IOC_FID2MDTIDX: {
2067 struct obd_export *exp = ll_i2mdexp(inode);
2071 if (copy_from_user(&fid, (const struct lu_fid __user *)arg,
2075 /* Call mdc_iocontrol */
2076 rc = obd_iocontrol(LL_IOC_FID2MDTIDX, exp, sizeof(fid), &fid,
2077 (__u32 __user *)&index);
2083 case LL_IOC_HSM_REQUEST: {
2084 struct hsm_user_request *hur;
2091 /* We don't know the true size yet; copy the fixed-size part */
2092 if (copy_from_user(hur, (void __user *)arg, sizeof(*hur))) {
2097 /* Compute the whole struct size */
2098 totalsize = hur_len(hur);
2103 /* Final size will be more than double totalsize */
2104 if (totalsize >= MDS_MAXREQSIZE / 3)
2107 OBD_ALLOC_LARGE(hur, totalsize);
2111 /* Copy the whole struct */
2112 if (copy_from_user(hur, (void __user *)arg, totalsize))
2113 GOTO(out_hur, rc = -EFAULT);
2115 if (hur->hur_request.hr_action == HUA_RELEASE) {
2116 const struct lu_fid *fid;
2120 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
2121 fid = &hur->hur_user_item[i].hui_fid;
2122 f = search_inode_for_lustre(inode->i_sb, fid);
2128 rc = ll_hsm_release(f);
2134 rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
2139 OBD_FREE_LARGE(hur, totalsize);
2143 case LL_IOC_HSM_PROGRESS: {
2144 struct hsm_progress_kernel hpk;
2145 struct hsm_progress hp;
2147 if (copy_from_user(&hp, (void __user *)arg, sizeof(hp)))
2150 hpk.hpk_fid = hp.hp_fid;
2151 hpk.hpk_cookie = hp.hp_cookie;
2152 hpk.hpk_extent = hp.hp_extent;
2153 hpk.hpk_flags = hp.hp_flags;
2154 hpk.hpk_errval = hp.hp_errval;
2155 hpk.hpk_data_version = 0;
2157 /* File may not exist in Lustre; all progress
2158 * reported to Lustre root */
2159 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
2163 case LL_IOC_HSM_CT_START:
2164 if (!capable(CAP_SYS_ADMIN))
2167 rc = copy_and_ct_start(cmd, sbi->ll_md_exp,
2168 (struct lustre_kernelcomm __user *)arg);
2171 case LL_IOC_HSM_COPY_START: {
2172 struct hsm_copy *copy;
2175 OBD_ALLOC_PTR(copy);
2178 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
2183 rc = ll_ioc_copy_start(inode->i_sb, copy);
2184 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
2190 case LL_IOC_HSM_COPY_END: {
2191 struct hsm_copy *copy;
2194 OBD_ALLOC_PTR(copy);
2197 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
2202 rc = ll_ioc_copy_end(inode->i_sb, copy);
2203 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
2209 case LL_IOC_MIGRATE: {
2210 struct lmv_user_md *lum;
2217 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
2221 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
2222 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
2223 GOTO(migrate_free, rc = -EINVAL);
2225 filename = data->ioc_inlbuf1;
2226 namelen = data->ioc_inllen1;
2227 flags = data->ioc_type;
2229 if (namelen < 1 || namelen != strlen(filename) + 1) {
2230 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
2231 GOTO(migrate_free, rc = -EINVAL);
2234 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
2235 if (lum->lum_magic != LMV_USER_MAGIC &&
2236 lum->lum_magic != LMV_USER_MAGIC_SPECIFIC) {
2238 CERROR("%s: wrong lum magic %x: rc = %d\n",
2239 filename, lum->lum_magic, rc);
2240 GOTO(migrate_free, rc);
2243 rc = ll_migrate(inode, file, lum, filename, flags);
2245 OBD_FREE_LARGE(data, len);
2249 case FS_IOC_FSGETXATTR:
2250 RETURN(ll_ioctl_fsgetxattr(inode, cmd, arg));
2251 case FS_IOC_FSSETXATTR:
2252 RETURN(ll_ioctl_fssetxattr(inode, cmd, arg));
2253 case LL_IOC_PROJECT:
2254 RETURN(ll_ioctl_project(file, cmd, arg));
2255 case LL_IOC_PCC_DETACH_BY_FID: {
2256 struct lu_pcc_detach_fid *detach;
2258 struct inode *inode2;
2261 OBD_ALLOC_PTR(detach);
2265 if (copy_from_user(detach,
2266 (const struct lu_pcc_detach_fid __user *)arg,
2268 GOTO(out_detach, rc = -EFAULT);
2270 fid = &detach->pccd_fid;
2271 ino = cl_fid_build_ino(fid, ll_need_32bit_api(sbi));
2272 inode2 = ilookup5(inode->i_sb, ino, ll_test_inode_by_fid, fid);
2274 /* Target inode is not in inode cache, and PCC file
2275 * has aleady released, return immdiately.
2277 GOTO(out_detach, rc = 0);
2279 if (!S_ISREG(inode2->i_mode))
2280 GOTO(out_iput, rc = -EINVAL);
2282 if (!inode_owner_or_capable(&init_user_ns, inode2))
2283 GOTO(out_iput, rc = -EPERM);
2285 rc = pcc_ioctl_detach(inode2, detach->pccd_opt);
2289 OBD_FREE_PTR(detach);
2292 #ifdef HAVE_LUSTRE_CRYPTO
2293 case LL_IOC_SET_ENCRYPTION_POLICY:
2294 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2296 return llcrypt_ioctl_set_policy(file, (const void __user *)arg);
2297 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
2298 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2300 return llcrypt_ioctl_get_policy_ex(file, (void __user *)arg);
2301 case LL_IOC_ADD_ENCRYPTION_KEY:
2302 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2304 return llcrypt_ioctl_add_key(file, (void __user *)arg);
2305 case LL_IOC_REMOVE_ENCRYPTION_KEY:
2306 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2308 return llcrypt_ioctl_remove_key(file, (void __user *)arg);
2309 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
2310 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2312 return llcrypt_ioctl_remove_key_all_users(file,
2313 (void __user *)arg);
2314 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
2315 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2317 return llcrypt_ioctl_get_key_status(file, (void __user *)arg);
2320 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL,
2321 (void __user *)arg));
2325 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
2327 struct inode *inode = file->f_mapping->host;
2328 struct ll_file_data *fd = file->private_data;
2329 struct ll_sb_info *sbi = ll_i2sbi(inode);
2330 int api32 = ll_need_32bit_api(sbi);
2331 loff_t ret = -EINVAL;
2339 offset += file->f_pos;
2345 offset += LL_DIR_END_OFF_32BIT;
2347 offset += LL_DIR_END_OFF;
2354 ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
2355 (!api32 && offset <= LL_DIR_END_OFF))) {
2356 if (offset != file->f_pos) {
2359 hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
2360 if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
2361 (!api32 && offset == LL_DIR_END_OFF))
2362 fd->lfd_pos = MDS_DIR_END_OFF;
2363 else if (api32 && hash64)
2364 fd->lfd_pos = offset << 32;
2366 fd->lfd_pos = offset;
2367 file->f_pos = offset;
2368 file->f_version = 0;
2375 inode_unlock(inode);
2379 static int ll_dir_open(struct inode *inode, struct file *file)
2382 RETURN(ll_file_open(inode, file));
2385 static int ll_dir_release(struct inode *inode, struct file *file)
2388 RETURN(ll_file_release(inode, file));
2391 /* notify error if partially read striped directory */
2392 static int ll_dir_flush(struct file *file, fl_owner_t id)
2394 struct ll_file_data *lfd = file->private_data;
2395 int rc = lfd->fd_partial_readdir_rc;
2397 lfd->fd_partial_readdir_rc = 0;
2402 const struct file_operations ll_dir_operations = {
2403 .llseek = ll_dir_seek,
2404 .open = ll_dir_open,
2405 .release = ll_dir_release,
2406 .read = generic_read_dir,
2407 #ifdef HAVE_DIR_CONTEXT
2408 .iterate_shared = ll_iterate,
2410 .readdir = ll_readdir,
2412 .unlocked_ioctl = ll_dir_ioctl,
2414 .flush = ll_dir_flush,