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, hash_type=%x\n",
473 PFID(ll_inode2fid(parent)), parent, dirname,
474 (int)lump->lum_stripe_offset, lump->lum_stripe_count,
475 lump->lum_hash_type);
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 (CFS_FAIL_CHECK(OBD_FAIL_LMV_UNKNOWN_STRIPE)) {
497 lump->lum_hash_type = cfs_fail_val;
498 } else if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_CRUSH)) {
499 enum lmv_hash_type type = lump->lum_hash_type &
502 if (type >= LMV_HASH_TYPE_CRUSH ||
503 type == LMV_HASH_TYPE_UNKNOWN)
504 lump->lum_hash_type = (lump->lum_hash_type ^ type) |
505 LMV_HASH_TYPE_FNV_1A_64;
508 hash_flags = lump->lum_hash_type & ~LMV_HASH_TYPE_MASK;
509 if (hash_flags & ~LMV_HASH_FLAG_KNOWN)
512 if (unlikely(!lmv_user_magic_supported(cpu_to_le32(lump->lum_magic))))
513 lustre_swab_lmv_user_md(lump);
515 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
516 mode &= ~current_umask();
517 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
518 op_data = ll_prep_md_op_data(NULL, parent, NULL, dirname,
519 strlen(dirname), mode, LUSTRE_OPC_MKDIR,
522 RETURN(PTR_ERR(op_data));
524 op_data->op_dir_depth = ll_i2info(parent)->lli_inherit_depth ?:
525 ll_i2info(parent)->lli_dir_depth;
527 if (ll_sbi_has_encrypt(sbi) &&
528 (IS_ENCRYPTED(parent) ||
529 unlikely(ll_sb_has_test_dummy_encryption(parent->i_sb)))) {
530 err = llcrypt_get_encryption_info(parent);
532 GOTO(out_op_data, err);
533 if (!llcrypt_has_encryption_key(parent))
534 GOTO(out_op_data, err = -ENOKEY);
538 if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
539 /* selinux_dentry_init_security() uses dentry->d_parent and name
540 * to determine the security context for the file. So our fake
541 * dentry should be real enough for this purpose. */
542 err = ll_dentry_init_security(&dentry, mode, &dentry.d_name,
543 &op_data->op_file_secctx_name,
544 &op_data->op_file_secctx,
545 &op_data->op_file_secctx_size);
547 GOTO(out_op_data, err);
551 err = llcrypt_inherit_context(parent, NULL, op_data, false);
553 GOTO(out_op_data, err);
556 op_data->op_cli_flags |= CLI_SET_MEA;
558 op_data->op_bias |= MDS_SETSTRIPE_CREATE;
560 err = md_create(sbi->ll_md_exp, op_data, lump, len, mode,
561 from_kuid(&init_user_ns, current_fsuid()),
562 from_kgid(&init_user_ns, current_fsgid()),
563 current_cap(), 0, &request);
565 GOTO(out_request, err);
567 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_SETDIRSTRIPE_PAUSE, cfs_fail_val);
569 err = ll_prep_inode(&inode, &request->rq_pill, parent->i_sb, NULL);
571 GOTO(out_inode, err);
573 dentry.d_inode = inode;
575 if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
576 /* no need to protect selinux_inode_setsecurity() by
577 * inode_lock. Taking it would lead to a client deadlock
580 err = security_inode_notifysecctx(inode,
581 op_data->op_file_secctx,
582 op_data->op_file_secctx_size);
584 err = ll_inode_init_security(&dentry, inode, parent);
587 GOTO(out_inode, err);
590 err = ll_set_encflags(inode, op_data->op_file_encctx,
591 op_data->op_file_encctx_size, false);
593 GOTO(out_inode, err);
599 ptlrpc_req_finished(request);
601 ll_finish_md_op_data(op_data);
606 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
609 struct ll_sb_info *sbi = ll_i2sbi(inode);
610 struct md_op_data *op_data;
611 struct ptlrpc_request *req = NULL;
617 switch (lump->lmm_magic) {
618 case LOV_USER_MAGIC_V1:
619 lum_size = sizeof(struct lov_user_md_v1);
621 case LOV_USER_MAGIC_V3:
622 lum_size = sizeof(struct lov_user_md_v3);
624 case LOV_USER_MAGIC_COMP_V1:
625 lum_size = ((struct lov_comp_md_v1 *)lump)->lcm_size;
627 case LMV_USER_MAGIC: {
628 struct lmv_user_md *lmv = (struct lmv_user_md *)lump;
630 /* MDS < 2.14 doesn't support 'crush' hash type, and
631 * cannot handle unknown hash if client doesn't set a
632 * valid one. switch to fnv_1a_64.
634 if (!(exp_connect_flags2(sbi->ll_md_exp) &
635 OBD_CONNECT2_CRUSH)) {
636 enum lmv_hash_type type = lmv->lum_hash_type &
639 if (type >= LMV_HASH_TYPE_CRUSH ||
640 type == LMV_HASH_TYPE_UNKNOWN)
642 (lmv->lum_hash_type ^ type) |
643 LMV_HASH_TYPE_FNV_1A_64;
645 if (lmv->lum_magic != cpu_to_le32(LMV_USER_MAGIC))
646 lustre_swab_lmv_user_md(lmv);
647 lum_size = sizeof(*lmv);
650 case LOV_USER_MAGIC_SPECIFIC: {
651 struct lov_user_md_v3 *v3 =
652 (struct lov_user_md_v3 *)lump;
653 if (v3->lmm_stripe_count > LOV_MAX_STRIPE_COUNT)
655 lum_size = lov_user_md_size(v3->lmm_stripe_count,
656 LOV_USER_MAGIC_SPECIFIC);
660 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
661 " %#08x != %#08x nor %#08x\n",
662 lump->lmm_magic, LOV_USER_MAGIC_V1,
668 * This is coming from userspace, so should be in
669 * local endian. But the MDS would like it in little
670 * endian, so we swab it before we send it.
672 if ((__swab32(lump->lmm_magic) & le32_to_cpu(LOV_MAGIC_MASK)) ==
673 le32_to_cpu(LOV_MAGIC_MAGIC))
674 lustre_swab_lov_user_md(lump, 0);
676 lum_size = sizeof(struct lov_user_md_v1);
679 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
680 LUSTRE_OPC_ANY, NULL);
682 RETURN(PTR_ERR(op_data));
684 /* swabbing is done in lov_setstripe() on server side */
685 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size, &req);
686 ll_finish_md_op_data(op_data);
687 ptlrpc_req_finished(req);
694 int ll_dir_get_default_layout(struct inode *inode, void **plmm, int *plmm_size,
695 struct ptlrpc_request **request, u64 valid,
696 enum get_default_layout_type type)
698 struct ll_sb_info *sbi = ll_i2sbi(inode);
699 struct mdt_body *body;
700 struct lov_mds_md *lmm = NULL;
701 struct ptlrpc_request *req = NULL;
702 int lmm_size = OBD_MAX_DEFAULT_EA_SIZE;
703 struct md_op_data *op_data;
709 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, lmm_size,
710 LUSTRE_OPC_ANY, NULL);
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);
1266 struct obd_quotactl *oqctl;
1267 int oqctl_len = sizeof(*oqctl);
1269 if (LUSTRE_Q_CMD_IS_POOL(cmd))
1270 oqctl_len += LOV_MAXPOOLNAME + 1;
1272 OBD_ALLOC(oqctl, oqctl_len);
1276 QCTL_COPY(oqctl, qctl);
1277 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1279 OBD_FREE(oqctl, oqctl_len);
1282 /* If QIF_SPACE is not set, client should collect the
1283 * space usage from OSSs by itself */
1284 if ((cmd == Q_GETQUOTA || cmd == LUSTRE_Q_GETQUOTAPOOL) &&
1285 !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
1286 !oqctl->qc_dqblk.dqb_curspace) {
1287 struct obd_quotactl *oqctl_tmp;
1288 int qctl_len = sizeof(*oqctl_tmp) + LOV_MAXPOOLNAME + 1;
1290 OBD_ALLOC(oqctl_tmp, qctl_len);
1291 if (oqctl_tmp == NULL)
1292 GOTO(out, rc = -ENOMEM);
1294 if (cmd == LUSTRE_Q_GETQUOTAPOOL) {
1295 oqctl_tmp->qc_cmd = LUSTRE_Q_GETQUOTAPOOL;
1296 memcpy(oqctl_tmp->qc_poolname,
1298 LOV_MAXPOOLNAME + 1);
1300 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1302 oqctl_tmp->qc_id = oqctl->qc_id;
1303 oqctl_tmp->qc_type = oqctl->qc_type;
1305 /* collect space usage from OSTs */
1306 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1307 rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
1308 if (!rc || rc == -EREMOTEIO) {
1309 oqctl->qc_dqblk.dqb_curspace =
1310 oqctl_tmp->qc_dqblk.dqb_curspace;
1311 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
1314 /* collect space & inode usage from MDTs */
1315 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1316 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1317 oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
1318 rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
1319 if (!rc || rc == -EREMOTEIO) {
1320 oqctl->qc_dqblk.dqb_curspace +=
1321 oqctl_tmp->qc_dqblk.dqb_curspace;
1322 oqctl->qc_dqblk.dqb_curinodes =
1323 oqctl_tmp->qc_dqblk.dqb_curinodes;
1324 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
1326 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
1329 OBD_FREE(oqctl_tmp, qctl_len);
1332 QCTL_COPY(qctl, oqctl);
1333 OBD_FREE(oqctl, oqctl_len);
1339 int ll_rmfid(struct file *file, void __user *arg)
1341 const struct fid_array __user *ufa = arg;
1342 struct inode *inode = file_inode(file);
1343 struct fid_array *lfa = NULL;
1346 int i, rc, *rcs = NULL;
1349 if (!capable(CAP_DAC_READ_SEARCH) &&
1350 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
1352 /* Only need to get the buflen */
1353 if (get_user(nr, &ufa->fa_nr))
1355 /* DoS protection */
1356 if (nr > OBD_MAX_FIDS_IN_ARRAY)
1359 size = offsetof(struct fid_array, fa_fids[nr]);
1360 OBD_ALLOC(lfa, size);
1363 OBD_ALLOC_PTR_ARRAY(rcs, nr);
1365 GOTO(free_lfa, rc = -ENOMEM);
1367 if (copy_from_user(lfa, arg, size))
1368 GOTO(free_rcs, rc = -EFAULT);
1370 /* Call mdc_iocontrol */
1371 rc = md_rmfid(ll_i2mdexp(file_inode(file)), lfa, rcs, NULL);
1373 for (i = 0; i < nr; i++)
1375 lfa->fa_fids[i].f_ver = rcs[i];
1376 if (copy_to_user(arg, lfa, size))
1381 OBD_FREE_PTR_ARRAY(rcs, nr);
1383 OBD_FREE(lfa, size);
1388 /* This function tries to get a single name component,
1389 * to send to the server. No actual path traversal involved,
1390 * so we limit to NAME_MAX */
1391 static char *ll_getname(const char __user *filename)
1396 OBD_ALLOC(tmp, NAME_MAX + 1);
1399 return ERR_PTR(-ENOMEM);
1401 len = strncpy_from_user(tmp, filename, NAME_MAX + 1);
1404 else if (len > NAME_MAX)
1405 ret = -ENAMETOOLONG;
1408 OBD_FREE(tmp, NAME_MAX + 1);
1414 #define ll_putname(filename) OBD_FREE(filename, NAME_MAX + 1);
1416 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1418 struct dentry *dentry = file_dentry(file);
1419 struct inode *inode = file_inode(file);
1420 struct ll_sb_info *sbi = ll_i2sbi(inode);
1421 struct obd_ioctl_data *data = NULL;
1425 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%#x\n",
1426 PFID(ll_inode2fid(inode)), inode, cmd);
1428 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
1429 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
1432 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
1434 case FS_IOC_GETFLAGS:
1435 case FS_IOC_SETFLAGS:
1436 RETURN(ll_iocontrol(inode, file, cmd, arg));
1437 case FSFILT_IOC_GETVERSION:
1438 case FS_IOC_GETVERSION:
1439 RETURN(put_user(inode->i_generation, (int __user *)arg));
1440 /* We need to special case any other ioctls we want to handle,
1441 * to send them to the MDS/OST as appropriate and to properly
1442 * network encode the arg field. */
1443 case FS_IOC_SETVERSION:
1446 case LL_IOC_GET_MDTIDX: {
1449 mdtidx = ll_get_mdt_idx(inode);
1453 if (put_user((int)mdtidx, (int __user *)arg))
1458 case IOC_MDC_LOOKUP: {
1459 int namelen, len = 0;
1462 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
1466 filename = data->ioc_inlbuf1;
1467 namelen = strlen(filename);
1469 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1470 GOTO(out_free, rc = -EINVAL);
1473 rc = ll_get_fid_by_name(inode, filename, namelen, NULL, NULL);
1475 CERROR("%s: lookup %.*s failed: rc = %d\n",
1476 sbi->ll_fsname, namelen, filename, rc);
1480 OBD_FREE_LARGE(data, len);
1483 case LL_IOC_LMV_SETSTRIPE: {
1484 struct lmv_user_md *lum;
1489 bool createonly = false;
1493 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
1497 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1498 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1499 GOTO(lmv_out_free, rc = -EINVAL);
1501 filename = data->ioc_inlbuf1;
1502 namelen = data->ioc_inllen1;
1505 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1506 GOTO(lmv_out_free, rc = -EINVAL);
1508 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1509 lumlen = data->ioc_inllen2;
1511 if (!lmv_user_magic_supported(lum->lum_magic)) {
1512 CERROR("%s: wrong lum magic %x : rc = %d\n", filename,
1513 lum->lum_magic, -EINVAL);
1514 GOTO(lmv_out_free, rc = -EINVAL);
1517 if ((lum->lum_magic == LMV_USER_MAGIC ||
1518 lum->lum_magic == LMV_USER_MAGIC_SPECIFIC) &&
1519 lumlen < sizeof(*lum)) {
1520 CERROR("%s: wrong lum size %d for magic %x : rc = %d\n",
1521 filename, lumlen, lum->lum_magic, -EINVAL);
1522 GOTO(lmv_out_free, rc = -EINVAL);
1525 if (lum->lum_magic == LMV_MAGIC_FOREIGN &&
1526 lumlen < sizeof(struct lmv_foreign_md)) {
1527 CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1528 filename, lum->lum_magic, lumlen, -EFAULT);
1529 GOTO(lmv_out_free, rc = -EINVAL);
1532 mode = data->ioc_type;
1533 createonly = data->ioc_obdo1.o_flags & OBD_FL_OBDMDEXISTS;
1534 rc = ll_dir_setdirstripe(dentry, lum, lumlen, filename, mode,
1537 OBD_FREE_LARGE(data, len);
1541 case LL_IOC_LMV_SET_DEFAULT_STRIPE: {
1542 struct lmv_user_md lum;
1543 struct lmv_user_md __user *ulump =
1544 (struct lmv_user_md __user *)arg;
1547 if (copy_from_user(&lum, ulump, sizeof(lum)))
1550 if (lum.lum_magic != LMV_USER_MAGIC)
1553 rc = ll_dir_setstripe(inode, (struct lov_user_md *)&lum, 0);
1557 case LL_IOC_LOV_SETSTRIPE_NEW:
1558 case LL_IOC_LOV_SETSTRIPE: {
1559 struct lov_user_md_v3 *lumv3 = NULL;
1560 struct lov_user_md_v1 lumv1;
1561 struct lov_user_md_v1 *lumv1_ptr = &lumv1;
1562 struct lov_user_md_v1 __user *lumv1p =
1563 (struct lov_user_md_v1 __user *)arg;
1564 struct lov_user_md_v3 __user *lumv3p =
1565 (struct lov_user_md_v3 __user *)arg;
1568 int set_default = 0;
1570 BUILD_BUG_ON(sizeof(struct lov_user_md_v3) <=
1571 sizeof(struct lov_comp_md_v1));
1572 BUILD_BUG_ON(sizeof(*lumv3) != sizeof(*lumv3p));
1573 /* first try with v1 which is smaller than v3 */
1574 if (copy_from_user(&lumv1, lumv1p, sizeof(lumv1)))
1577 if (is_root_inode(inode))
1580 switch (lumv1.lmm_magic) {
1581 case LOV_USER_MAGIC_V3:
1582 case LOV_USER_MAGIC_SPECIFIC:
1583 lum_size = ll_lov_user_md_size(&lumv1);
1586 OBD_ALLOC(lumv3, lum_size);
1589 if (copy_from_user(lumv3, lumv3p, lum_size))
1590 GOTO(out, rc = -EFAULT);
1591 lumv1_ptr = (struct lov_user_md_v1 *)lumv3;
1593 case LOV_USER_MAGIC_V1:
1596 GOTO(out, rc = -ENOTSUPP);
1599 /* in v1 and v3 cases lumv1 points to data */
1600 rc = ll_dir_setstripe(inode, lumv1_ptr, set_default);
1603 OBD_FREE(lumv3, lum_size);
1606 case LL_IOC_LMV_GETSTRIPE: {
1607 struct lmv_user_md __user *ulmv =
1608 (struct lmv_user_md __user *)arg;
1609 struct lmv_user_md lum;
1610 struct ptlrpc_request *request = NULL;
1611 struct ptlrpc_request *root_request = NULL;
1612 union lmv_mds_md *lmm = NULL;
1615 struct lmv_user_md *tmp = NULL;
1619 int max_stripe_count;
1623 if (copy_from_user(&lum, ulmv, sizeof(*ulmv)))
1626 max_stripe_count = lum.lum_stripe_count;
1627 /* lum_magic will indicate which stripe the ioctl will like
1628 * to get, LMV_MAGIC_V1 is for normal LMV stripe, LMV_USER_MAGIC
1629 * is for default LMV stripe */
1630 if (lum.lum_magic == LMV_MAGIC_V1)
1631 valid |= OBD_MD_MEA;
1632 else if (lum.lum_magic == LMV_USER_MAGIC)
1633 valid |= OBD_MD_DEFAULT_MEA;
1637 rc = ll_dir_getstripe_default(inode, (void **)&lmm, &lmmsize,
1638 &request, &root_request, valid);
1640 GOTO(finish_req, rc);
1642 /* Get default LMV EA */
1643 if (lum.lum_magic == LMV_USER_MAGIC) {
1644 if (lmmsize > sizeof(*ulmv))
1645 GOTO(finish_req, rc = -EINVAL);
1647 if (root_request != NULL) {
1648 struct lmv_user_md *lum;
1649 struct ll_inode_info *lli;
1651 lum = (struct lmv_user_md *)lmm;
1652 lli = ll_i2info(inode);
1653 if (lum->lum_max_inherit !=
1654 LMV_INHERIT_UNLIMITED) {
1655 if (lum->lum_max_inherit ==
1657 lum->lum_max_inherit <
1659 lum->lum_max_inherit >
1661 lum->lum_max_inherit <
1663 GOTO(finish_req, rc = -ENODATA);
1665 if (lum->lum_max_inherit ==
1666 lli->lli_dir_depth) {
1667 lum->lum_max_inherit =
1669 lum->lum_max_inherit_rr =
1670 LMV_INHERIT_RR_NONE;
1674 lum->lum_max_inherit -=
1678 if (lum->lum_max_inherit_rr !=
1679 LMV_INHERIT_RR_UNLIMITED) {
1680 if (lum->lum_max_inherit_rr ==
1682 lum->lum_max_inherit_rr <
1683 LMV_INHERIT_RR_END ||
1684 lum->lum_max_inherit_rr >
1685 LMV_INHERIT_RR_MAX ||
1686 lum->lum_max_inherit_rr <=
1687 lli->lli_dir_depth) {
1688 lum->lum_max_inherit_rr =
1689 LMV_INHERIT_RR_NONE;
1693 if (lum->lum_max_inherit_rr >
1695 lum->lum_max_inherit_rr -=
1700 if (copy_to_user(ulmv, lmm, lmmsize))
1701 GOTO(finish_req, rc = -EFAULT);
1703 GOTO(finish_req, rc);
1706 /* if foreign LMV case, fake stripes number */
1707 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1708 struct lmv_foreign_md *lfm;
1710 lfm = (struct lmv_foreign_md *)lmm;
1711 if (lfm->lfm_length < XATTR_SIZE_MAX -
1712 offsetof(typeof(*lfm), lfm_value)) {
1713 __u32 size = lfm->lfm_length +
1714 offsetof(typeof(*lfm), lfm_value);
1716 stripe_count = lmv_foreign_to_md_stripes(size);
1718 CERROR("invalid %d foreign size returned\n",
1723 stripe_count = lmv_mds_md_stripe_count_get(lmm);
1725 if (max_stripe_count < stripe_count) {
1726 lum.lum_stripe_count = stripe_count;
1727 if (copy_to_user(ulmv, &lum, sizeof(lum)))
1728 GOTO(finish_req, rc = -EFAULT);
1729 GOTO(finish_req, rc = -E2BIG);
1732 /* enough room on user side and foreign case */
1733 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1734 struct lmv_foreign_md *lfm;
1737 lfm = (struct lmv_foreign_md *)lmm;
1738 size = lfm->lfm_length +
1739 offsetof(struct lmv_foreign_md, lfm_value);
1740 if (copy_to_user(ulmv, lfm, size))
1741 GOTO(finish_req, rc = -EFAULT);
1742 GOTO(finish_req, rc);
1745 lum_size = lmv_user_md_size(stripe_count,
1746 LMV_USER_MAGIC_SPECIFIC);
1747 OBD_ALLOC(tmp, lum_size);
1749 GOTO(finish_req, rc = -ENOMEM);
1751 mdt_index = ll_get_mdt_idx(inode);
1753 GOTO(out_tmp, rc = -ENOMEM);
1755 tmp->lum_magic = LMV_MAGIC_V1;
1756 tmp->lum_stripe_count = 0;
1757 tmp->lum_stripe_offset = mdt_index;
1758 tmp->lum_hash_type = lmv_mds_md_hash_type_get(lmm);
1759 for (i = 0; i < stripe_count; i++) {
1762 fid_le_to_cpu(&fid, &lmm->lmv_md_v1.lmv_stripe_fids[i]);
1763 if (fid_is_sane(&fid)) {
1764 mdt_index = ll_get_mdt_idx_by_fid(sbi, &fid);
1766 GOTO(out_tmp, rc = mdt_index);
1768 tmp->lum_objects[i].lum_mds = mdt_index;
1769 tmp->lum_objects[i].lum_fid = fid;
1772 tmp->lum_stripe_count++;
1775 if (copy_to_user(ulmv, tmp, lum_size))
1776 GOTO(out_tmp, rc = -EFAULT);
1778 OBD_FREE(tmp, lum_size);
1780 ptlrpc_req_finished(request);
1781 ptlrpc_req_finished(root_request);
1785 case LL_IOC_UNLOCK_FOREIGN:
1786 /* if not a foreign symlink do nothing */
1787 if (ll_foreign_is_removable(dentry, true)) {
1789 "prevent rmdir of non-foreign dir ("DFID")\n",
1790 PFID(ll_inode2fid(inode)));
1791 RETURN(-EOPNOTSUPP);
1795 case LL_IOC_REMOVE_ENTRY: {
1796 char *filename = NULL;
1800 /* Here is a little hack to avoid sending REINT_RMENTRY to
1801 * unsupported server, which might crash the server(LU-2730),
1802 * Because both LVB_TYPE and REINT_RMENTRY will be supported
1803 * on 2.4, we use OBD_CONNECT_LVB_TYPE to detect whether the
1804 * server will support REINT_RMENTRY XXX*/
1805 if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE))
1808 filename = ll_getname((const char __user *)arg);
1809 if (IS_ERR(filename))
1810 RETURN(PTR_ERR(filename));
1812 namelen = strlen(filename);
1814 GOTO(out_rmdir, rc = -EINVAL);
1816 rc = ll_rmdir_entry(inode, filename, namelen);
1819 ll_putname(filename);
1823 RETURN(ll_rmfid(file, (void __user *)arg));
1824 case LL_IOC_LOV_SWAP_LAYOUTS:
1826 case IOC_OBD_STATFS:
1827 RETURN(ll_obd_statfs(inode, (void __user *)arg));
1828 case LL_IOC_LOV_GETSTRIPE:
1829 case LL_IOC_LOV_GETSTRIPE_NEW:
1830 case LL_IOC_MDC_GETINFO_V1:
1831 case LL_IOC_MDC_GETINFO_V2:
1832 case IOC_MDC_GETFILEINFO_V1:
1833 case IOC_MDC_GETFILEINFO_V2:
1834 case IOC_MDC_GETFILESTRIPE: {
1835 struct ptlrpc_request *request = NULL;
1836 struct ptlrpc_request *root_request = NULL;
1837 struct lov_user_md __user *lump;
1838 struct lov_mds_md *lmm = NULL;
1839 struct mdt_body *body;
1840 char *filename = NULL;
1841 lstat_t __user *statp = NULL;
1842 lstatx_t __user *stxp = NULL;
1843 __u64 __user *flagsp = NULL;
1844 __u32 __user *lmmsizep = NULL;
1845 struct lu_fid __user *fidp = NULL;
1849 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1850 cmd == IOC_MDC_GETFILEINFO_V2 ||
1851 cmd == IOC_MDC_GETFILESTRIPE) {
1852 filename = ll_getname((const char __user *)arg);
1853 if (IS_ERR(filename))
1854 RETURN(PTR_ERR(filename));
1856 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1857 &lmmsize, &request);
1859 rc = ll_dir_getstripe_default(inode, (void **)&lmm,
1865 body = req_capsule_server_get(&request->rq_pill,
1867 LASSERT(body != NULL);
1872 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO_V1 ||
1873 cmd == LL_IOC_MDC_GETINFO_V1 ||
1874 cmd == IOC_MDC_GETFILEINFO_V2 ||
1875 cmd == LL_IOC_MDC_GETINFO_V2)) {
1883 if (cmd == IOC_MDC_GETFILESTRIPE ||
1884 cmd == LL_IOC_LOV_GETSTRIPE ||
1885 cmd == LL_IOC_LOV_GETSTRIPE_NEW) {
1886 lump = (struct lov_user_md __user *)arg;
1887 } else if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1888 cmd == LL_IOC_MDC_GETINFO_V1){
1889 struct lov_user_mds_data_v1 __user *lmdp;
1891 lmdp = (struct lov_user_mds_data_v1 __user *)arg;
1892 statp = &lmdp->lmd_st;
1893 lump = &lmdp->lmd_lmm;
1895 struct lov_user_mds_data __user *lmdp;
1897 lmdp = (struct lov_user_mds_data __user *)arg;
1898 fidp = &lmdp->lmd_fid;
1899 stxp = &lmdp->lmd_stx;
1900 flagsp = &lmdp->lmd_flags;
1901 lmmsizep = &lmdp->lmd_lmmsize;
1902 lump = &lmdp->lmd_lmm;
1906 /* If the file has no striping then zero out *lump so
1907 * that the caller isn't confused by garbage. */
1908 if (clear_user(lump, sizeof(*lump)))
1909 GOTO(out_req, rc = -EFAULT);
1910 } else if (copy_to_user(lump, lmm, lmmsize)) {
1911 if (copy_to_user(lump, lmm, sizeof(*lump)))
1912 GOTO(out_req, rc = -EFAULT);
1915 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
1917 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1918 cmd == LL_IOC_MDC_GETINFO_V1) {
1921 st.st_dev = inode->i_sb->s_dev;
1922 st.st_mode = body->mbo_mode;
1923 st.st_nlink = body->mbo_nlink;
1924 st.st_uid = body->mbo_uid;
1925 st.st_gid = body->mbo_gid;
1926 st.st_rdev = body->mbo_rdev;
1927 if (llcrypt_require_key(inode) == -ENOKEY)
1928 st.st_size = round_up(st.st_size,
1929 LUSTRE_ENCRYPTION_UNIT_SIZE);
1931 st.st_size = body->mbo_size;
1932 st.st_blksize = PAGE_SIZE;
1933 st.st_blocks = body->mbo_blocks;
1934 st.st_atime = body->mbo_atime;
1935 st.st_mtime = body->mbo_mtime;
1936 st.st_ctime = body->mbo_ctime;
1937 st.st_ino = cl_fid_build_ino(&body->mbo_fid1,
1940 if (copy_to_user(statp, &st, sizeof(st)))
1941 GOTO(out_req, rc = -EFAULT);
1942 } else if (cmd == IOC_MDC_GETFILEINFO_V2 ||
1943 cmd == LL_IOC_MDC_GETINFO_V2) {
1944 lstatx_t stx = { 0 };
1945 __u64 valid = body->mbo_valid;
1947 stx.stx_blksize = PAGE_SIZE;
1948 stx.stx_nlink = body->mbo_nlink;
1949 stx.stx_uid = body->mbo_uid;
1950 stx.stx_gid = body->mbo_gid;
1951 stx.stx_mode = body->mbo_mode;
1952 stx.stx_ino = cl_fid_build_ino(&body->mbo_fid1,
1954 if (llcrypt_require_key(inode) == -ENOKEY)
1955 stx.stx_size = round_up(stx.stx_size,
1956 LUSTRE_ENCRYPTION_UNIT_SIZE);
1958 stx.stx_size = body->mbo_size;
1959 stx.stx_blocks = body->mbo_blocks;
1960 stx.stx_atime.tv_sec = body->mbo_atime;
1961 stx.stx_ctime.tv_sec = body->mbo_ctime;
1962 stx.stx_mtime.tv_sec = body->mbo_mtime;
1963 stx.stx_btime.tv_sec = body->mbo_btime;
1964 stx.stx_rdev_major = MAJOR(body->mbo_rdev);
1965 stx.stx_rdev_minor = MINOR(body->mbo_rdev);
1966 stx.stx_dev_major = MAJOR(inode->i_sb->s_dev);
1967 stx.stx_dev_minor = MINOR(inode->i_sb->s_dev);
1968 stx.stx_mask |= STATX_BASIC_STATS | STATX_BTIME;
1971 * For a striped directory, the size and blocks returned
1972 * from MDT is not correct.
1973 * The size and blocks are aggregated by client across
1975 * Thus for a striped directory, do not return the valid
1976 * FLSIZE and FLBLOCKS flags to the caller.
1977 * However, this whould be better decided by the MDS
1978 * instead of the client.
1980 if (cmd == LL_IOC_MDC_GETINFO_V2 &&
1981 ll_i2info(inode)->lli_lsm_md != NULL)
1982 valid &= ~(OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
1984 if (flagsp && copy_to_user(flagsp, &valid,
1986 GOTO(out_req, rc = -EFAULT);
1988 if (fidp && copy_to_user(fidp, &body->mbo_fid1,
1990 GOTO(out_req, rc = -EFAULT);
1992 if (!(valid & OBD_MD_FLSIZE))
1993 stx.stx_mask &= ~STATX_SIZE;
1994 if (!(valid & OBD_MD_FLBLOCKS))
1995 stx.stx_mask &= ~STATX_BLOCKS;
1997 if (stxp && copy_to_user(stxp, &stx, sizeof(stx)))
1998 GOTO(out_req, rc = -EFAULT);
2000 if (lmmsizep && copy_to_user(lmmsizep, &lmmsize,
2002 GOTO(out_req, rc = -EFAULT);
2007 ptlrpc_req_finished(request);
2008 ptlrpc_req_finished(root_request);
2010 ll_putname(filename);
2013 case OBD_IOC_QUOTACTL: {
2014 struct if_quotactl *qctl;
2015 int qctl_len = sizeof(*qctl) + LOV_MAXPOOLNAME + 1;
2017 OBD_ALLOC(qctl, qctl_len);
2021 if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl)))
2022 GOTO(out_quotactl, rc = -EFAULT);
2024 if (LUSTRE_Q_CMD_IS_POOL(qctl->qc_cmd)) {
2025 char __user *from = (char __user *)arg +
2026 offsetof(typeof(*qctl), qc_poolname);
2027 if (copy_from_user(qctl->qc_poolname, from,
2028 LOV_MAXPOOLNAME + 1))
2029 GOTO(out_quotactl, rc = -EFAULT);
2032 rc = quotactl_ioctl(inode->i_sb, qctl);
2033 if ((rc == 0 || rc == -ENODATA) &&
2034 copy_to_user((void __user *)arg, qctl, sizeof(*qctl)))
2038 OBD_FREE(qctl, qctl_len);
2041 case OBD_IOC_GETNAME_OLD:
2042 case OBD_IOC_GETDTNAME:
2043 case OBD_IOC_GETMDNAME:
2044 RETURN(ll_get_obd_name(inode, cmd, arg));
2045 case LL_IOC_FLUSHCTX:
2046 RETURN(ll_flush_ctx(inode));
2047 case LL_IOC_GETOBDCOUNT: {
2049 struct obd_export *exp;
2051 if (copy_from_user(&count, (int __user *)arg, sizeof(int)))
2054 /* get ost count when count is zero, get mdt count otherwise */
2055 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
2056 vallen = sizeof(count);
2057 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
2058 KEY_TGT_COUNT, &vallen, &count);
2060 CERROR("get target count failed: %d\n", rc);
2064 if (copy_to_user((int __user *)arg, &count, sizeof(int)))
2069 case LL_IOC_PATH2FID:
2070 if (copy_to_user((void __user *)arg, ll_inode2fid(inode),
2071 sizeof(struct lu_fid)))
2074 case LL_IOC_GET_CONNECT_FLAGS: {
2075 RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL,
2076 (void __user *)arg));
2078 case OBD_IOC_FID2PATH:
2079 RETURN(ll_fid2path(inode, (void __user *)arg));
2080 case LL_IOC_GETPARENT:
2081 RETURN(ll_getparent(file, (void __user *)arg));
2082 case LL_IOC_FID2MDTIDX: {
2083 struct obd_export *exp = ll_i2mdexp(inode);
2087 if (copy_from_user(&fid, (const struct lu_fid __user *)arg,
2091 /* Call mdc_iocontrol */
2092 rc = obd_iocontrol(LL_IOC_FID2MDTIDX, exp, sizeof(fid), &fid,
2093 (__u32 __user *)&index);
2099 case LL_IOC_HSM_REQUEST: {
2100 struct hsm_user_request *hur;
2107 /* We don't know the true size yet; copy the fixed-size part */
2108 if (copy_from_user(hur, (void __user *)arg, sizeof(*hur))) {
2113 /* Compute the whole struct size */
2114 totalsize = hur_len(hur);
2119 /* Final size will be more than double totalsize */
2120 if (totalsize >= MDS_MAXREQSIZE / 3)
2123 OBD_ALLOC_LARGE(hur, totalsize);
2127 /* Copy the whole struct */
2128 if (copy_from_user(hur, (void __user *)arg, totalsize))
2129 GOTO(out_hur, rc = -EFAULT);
2131 if (hur->hur_request.hr_action == HUA_RELEASE) {
2132 const struct lu_fid *fid;
2136 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
2137 fid = &hur->hur_user_item[i].hui_fid;
2138 f = search_inode_for_lustre(inode->i_sb, fid);
2144 rc = ll_hsm_release(f);
2150 rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
2155 OBD_FREE_LARGE(hur, totalsize);
2159 case LL_IOC_HSM_PROGRESS: {
2160 struct hsm_progress_kernel hpk;
2161 struct hsm_progress hp;
2163 if (copy_from_user(&hp, (void __user *)arg, sizeof(hp)))
2166 hpk.hpk_fid = hp.hp_fid;
2167 hpk.hpk_cookie = hp.hp_cookie;
2168 hpk.hpk_extent = hp.hp_extent;
2169 hpk.hpk_flags = hp.hp_flags;
2170 hpk.hpk_errval = hp.hp_errval;
2171 hpk.hpk_data_version = 0;
2173 /* File may not exist in Lustre; all progress
2174 * reported to Lustre root */
2175 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
2179 case LL_IOC_HSM_CT_START:
2180 if (!capable(CAP_SYS_ADMIN))
2183 rc = copy_and_ct_start(cmd, sbi->ll_md_exp,
2184 (struct lustre_kernelcomm __user *)arg);
2187 case LL_IOC_HSM_COPY_START: {
2188 struct hsm_copy *copy;
2191 OBD_ALLOC_PTR(copy);
2194 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
2199 rc = ll_ioc_copy_start(inode->i_sb, copy);
2200 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
2206 case LL_IOC_HSM_COPY_END: {
2207 struct hsm_copy *copy;
2210 OBD_ALLOC_PTR(copy);
2213 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
2218 rc = ll_ioc_copy_end(inode->i_sb, copy);
2219 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
2225 case LL_IOC_MIGRATE: {
2226 struct lmv_user_md *lum;
2233 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
2237 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
2238 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
2239 GOTO(migrate_free, rc = -EINVAL);
2241 filename = data->ioc_inlbuf1;
2242 namelen = data->ioc_inllen1;
2243 flags = data->ioc_type;
2245 if (namelen < 1 || namelen != strlen(filename) + 1) {
2246 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
2247 GOTO(migrate_free, rc = -EINVAL);
2250 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
2251 if (lum->lum_magic != LMV_USER_MAGIC &&
2252 lum->lum_magic != LMV_USER_MAGIC_SPECIFIC) {
2254 CERROR("%s: wrong lum magic %x: rc = %d\n",
2255 filename, lum->lum_magic, rc);
2256 GOTO(migrate_free, rc);
2259 rc = ll_migrate(inode, file, lum, filename, flags);
2261 OBD_FREE_LARGE(data, len);
2265 case FS_IOC_FSGETXATTR:
2266 RETURN(ll_ioctl_fsgetxattr(inode, cmd, arg));
2267 case FS_IOC_FSSETXATTR:
2268 RETURN(ll_ioctl_fssetxattr(inode, cmd, arg));
2269 case LL_IOC_PROJECT:
2270 RETURN(ll_ioctl_project(file, cmd, arg));
2271 case LL_IOC_PCC_DETACH_BY_FID: {
2272 struct lu_pcc_detach_fid *detach;
2274 struct inode *inode2;
2277 OBD_ALLOC_PTR(detach);
2281 if (copy_from_user(detach,
2282 (const struct lu_pcc_detach_fid __user *)arg,
2284 GOTO(out_detach, rc = -EFAULT);
2286 fid = &detach->pccd_fid;
2287 ino = cl_fid_build_ino(fid, ll_need_32bit_api(sbi));
2288 inode2 = ilookup5(inode->i_sb, ino, ll_test_inode_by_fid, fid);
2290 /* Target inode is not in inode cache, and PCC file
2291 * has aleady released, return immdiately.
2293 GOTO(out_detach, rc = 0);
2295 if (!S_ISREG(inode2->i_mode))
2296 GOTO(out_iput, rc = -EINVAL);
2298 if (!inode_owner_or_capable(&init_user_ns, inode2))
2299 GOTO(out_iput, rc = -EPERM);
2301 rc = pcc_ioctl_detach(inode2, detach->pccd_opt);
2305 OBD_FREE_PTR(detach);
2308 #ifdef HAVE_LUSTRE_CRYPTO
2309 case LL_IOC_SET_ENCRYPTION_POLICY:
2310 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2312 return llcrypt_ioctl_set_policy(file, (const void __user *)arg);
2313 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
2314 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2316 return llcrypt_ioctl_get_policy_ex(file, (void __user *)arg);
2317 case LL_IOC_ADD_ENCRYPTION_KEY:
2318 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2320 return llcrypt_ioctl_add_key(file, (void __user *)arg);
2321 case LL_IOC_REMOVE_ENCRYPTION_KEY:
2322 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2324 return llcrypt_ioctl_remove_key(file, (void __user *)arg);
2325 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
2326 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2328 return llcrypt_ioctl_remove_key_all_users(file,
2329 (void __user *)arg);
2330 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
2331 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2333 return llcrypt_ioctl_get_key_status(file, (void __user *)arg);
2336 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL,
2337 (void __user *)arg));
2341 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
2343 struct inode *inode = file->f_mapping->host;
2344 struct ll_file_data *fd = file->private_data;
2345 struct ll_sb_info *sbi = ll_i2sbi(inode);
2346 int api32 = ll_need_32bit_api(sbi);
2347 loff_t ret = -EINVAL;
2355 offset += file->f_pos;
2361 offset += LL_DIR_END_OFF_32BIT;
2363 offset += LL_DIR_END_OFF;
2370 ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
2371 (!api32 && offset <= LL_DIR_END_OFF))) {
2372 if (offset != file->f_pos) {
2375 hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
2376 if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
2377 (!api32 && offset == LL_DIR_END_OFF))
2378 fd->lfd_pos = MDS_DIR_END_OFF;
2379 else if (api32 && hash64)
2380 fd->lfd_pos = offset << 32;
2382 fd->lfd_pos = offset;
2383 file->f_pos = offset;
2384 file->f_version = 0;
2391 inode_unlock(inode);
2395 static int ll_dir_open(struct inode *inode, struct file *file)
2398 RETURN(ll_file_open(inode, file));
2401 static int ll_dir_release(struct inode *inode, struct file *file)
2404 RETURN(ll_file_release(inode, file));
2407 /* notify error if partially read striped directory */
2408 static int ll_dir_flush(struct file *file, fl_owner_t id)
2410 struct ll_file_data *lfd = file->private_data;
2411 int rc = lfd->fd_partial_readdir_rc;
2413 lfd->fd_partial_readdir_rc = 0;
2418 const struct file_operations ll_dir_operations = {
2419 .llseek = ll_dir_seek,
2420 .open = ll_dir_open,
2421 .release = ll_dir_release,
2422 .read = generic_read_dir,
2423 #ifdef HAVE_DIR_CONTEXT
2424 .iterate_shared = ll_iterate,
2426 .readdir = ll_readdir,
2428 .unlocked_ioctl = ll_dir_ioctl,
2430 .flush = ll_dir_flush,