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 && ll_dir_striped(inode)) {
177 if (likely(page->mapping != NULL))
178 delete_from_page_cache(page);
184 #ifdef HAVE_DIR_CONTEXT
185 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
186 struct dir_context *ctx, int *partial_readdir_rc)
189 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
190 void *cookie, filldir_t filldir, int *partial_readdir_rc)
193 struct ll_sb_info *sbi = ll_i2sbi(inode);
195 bool is_api32 = ll_need_32bit_api(sbi);
196 bool is_hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
199 struct llcrypt_str lltr = LLTR_INIT(NULL, 0);
203 if (IS_ENCRYPTED(inode)) {
204 rc = llcrypt_fname_alloc_buffer(inode, NAME_MAX, &lltr);
209 page = ll_get_dir_page(inode, op_data, pos, partial_readdir_rc);
211 while (rc == 0 && !done) {
212 struct lu_dirpage *dp;
213 struct lu_dirent *ent;
222 hash = MDS_DIR_END_OFF;
223 dp = page_address(page);
224 for (ent = lu_dirent_start(dp); ent != NULL && !done;
225 ent = lu_dirent_next(ent)) {
232 hash = le64_to_cpu(ent->lde_hash);
233 if (hash < pos) /* Skip until we find target hash */
236 namelen = le16_to_cpu(ent->lde_namelen);
237 if (namelen == 0) /* Skip dummy record */
240 if (is_api32 && is_hash64)
244 fid_le_to_cpu(&fid, &ent->lde_fid);
245 ino = cl_fid_build_ino(&fid, is_api32);
246 type = S_DT(lu_dirent_type_get(ent));
247 /* For ll_nfs_get_name_filldir(), it will try to access
248 * 'ent' through 'lde_name', so the parameter 'name'
249 * for 'filldir()' must be part of the 'ent'. */
250 #ifdef HAVE_DIR_CONTEXT
252 if (!IS_ENCRYPTED(inode)) {
253 done = !dir_emit(ctx, ent->lde_name, namelen,
256 /* Directory is encrypted */
257 int save_len = lltr.len;
258 struct llcrypt_str de_name =
259 LLTR_INIT(ent->lde_name, namelen);
261 rc = ll_fname_disk_to_usr(inode, 0, 0, &de_name,
269 done = !dir_emit(ctx, de_name.name, de_name.len,
273 /* HAVE_DIR_CONTEXT is defined from kernel 3.11, whereas
274 * IS_ENCRYPTED is brought by kernel 4.14.
275 * So there is no need to handle encryption case here.
277 done = filldir(cookie, ent->lde_name, namelen, lhash,
284 ll_release_page(inode, page, false);
288 next = le64_to_cpu(dp->ldp_hash_end);
290 if (pos == MDS_DIR_END_OFF) {
292 * End of directory reached.
295 ll_release_page(inode, page, false);
298 * Normal case: continue to the next
301 ll_release_page(inode, page,
302 le32_to_cpu(dp->ldp_flags) &
305 page = ll_get_dir_page(inode, op_data, pos,
309 #ifdef HAVE_DIR_CONTEXT
314 llcrypt_fname_free_buffer(&lltr);
318 #ifdef HAVE_DIR_CONTEXT
319 static int ll_iterate(struct file *filp, struct dir_context *ctx)
321 static int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
324 struct inode *inode = file_inode(filp);
325 struct ll_file_data *lfd = filp->private_data;
326 struct ll_sb_info *sbi = ll_i2sbi(inode);
327 bool hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
328 int api32 = ll_need_32bit_api(sbi);
329 struct md_op_data *op_data;
330 struct lu_fid pfid = { 0 };
331 ktime_t kstart = ktime_get();
332 /* result of possible partial readdir */
333 int partial_readdir_rc = 0;
339 LASSERT(lfd != NULL);
343 "VFS Op:inode="DFID"(%p) pos/size%lu/%llu 32bit_api %d\n",
344 PFID(ll_inode2fid(inode)),
345 inode, (unsigned long)pos, i_size_read(inode), api32);
347 if (IS_ENCRYPTED(inode)) {
348 rc = llcrypt_get_encryption_info(inode);
349 if (rc && rc != -ENOKEY)
353 if (pos == MDS_DIR_END_OFF)
359 if (unlikely(ll_dir_striped(inode))) {
361 * This is only needed for striped dir to fill ..,
362 * see lmv_read_page()
364 if (file_dentry(filp)->d_parent != NULL &&
365 file_dentry(filp)->d_parent->d_inode != NULL) {
366 __u64 ibits = MDS_INODELOCK_LOOKUP;
367 struct inode *parent =
368 file_dentry(filp)->d_parent->d_inode;
370 if (ll_have_md_lock(parent, &ibits, LCK_MINMODE))
371 pfid = *ll_inode2fid(parent);
374 /* If it can not find in cache, do lookup .. on the master
376 if (fid_is_zero(&pfid)) {
377 rc = ll_dir_get_parent_fid(inode, &pfid);
383 op_data = ll_prep_md_op_data(NULL, inode, inode, NULL, 0, 0,
384 LUSTRE_OPC_ANY, inode);
386 GOTO(out, rc = PTR_ERR(op_data));
388 /* foreign dirs are browsed out of Lustre */
389 if (unlikely(op_data->op_mea1 != NULL &&
390 op_data->op_mea1->lsm_md_magic == LMV_MAGIC_FOREIGN)) {
391 ll_finish_md_op_data(op_data);
395 op_data->op_fid3 = pfid;
397 #ifdef HAVE_DIR_CONTEXT
399 rc = ll_dir_read(inode, &pos, op_data, ctx, &partial_readdir_rc);
402 rc = ll_dir_read(inode, &pos, op_data, cookie, filldir,
403 &partial_readdir_rc);
406 if (!lfd->fd_partial_readdir_rc)
407 lfd->fd_partial_readdir_rc = partial_readdir_rc;
409 if (pos == MDS_DIR_END_OFF) {
411 pos = LL_DIR_END_OFF_32BIT;
413 pos = LL_DIR_END_OFF;
418 #ifdef HAVE_DIR_CONTEXT
423 ll_finish_md_op_data(op_data);
427 ll_stats_ops_tally(sbi, LPROC_LL_READDIR,
428 ktime_us_delta(ktime_get(), kstart));
434 * Create striped directory with specified stripe(@lump)
436 * \param[in] dparent the parent of the directory.
437 * \param[in] lump the specified stripes.
438 * \param[in] dirname the name of the directory.
439 * \param[in] mode the specified mode of the directory.
441 * \retval =0 if striped directory is being created successfully.
442 * <0 if the creation is failed.
444 static int ll_dir_setdirstripe(struct dentry *dparent, struct lmv_user_md *lump,
445 size_t len, const char *dirname, umode_t mode,
448 struct inode *parent = dparent->d_inode;
449 struct ptlrpc_request *request = NULL;
450 struct md_op_data *op_data;
451 struct ll_sb_info *sbi = ll_i2sbi(parent);
452 struct inode *inode = NULL;
453 struct dentry dentry = {
457 .len = strlen(dirname),
458 .hash = ll_full_name_hash(dparent, dirname,
462 bool encrypt = false;
467 if (unlikely(!lmv_user_magic_supported(lump->lum_magic)))
470 if (lump->lum_magic != LMV_MAGIC_FOREIGN) {
472 "VFS Op:inode="DFID"(%p) name %s stripe_offset %d, stripe_count: %u\n",
473 PFID(ll_inode2fid(parent)), parent, dirname,
474 (int)lump->lum_stripe_offset, lump->lum_stripe_count);
476 struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)lump;
479 "VFS Op:inode="DFID"(%p) name %s foreign, length %u, value '%.*s'\n",
480 PFID(ll_inode2fid(parent)), parent, dirname,
481 lfm->lfm_length, lfm->lfm_length, lfm->lfm_value);
484 if (lump->lum_stripe_count > 1 &&
485 !(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_DIR_STRIPE))
488 if (IS_DEADDIR(parent) &&
489 !OBD_FAIL_CHECK(OBD_FAIL_LLITE_NO_CHECK_DEAD))
492 /* MDS < 2.14 doesn't support 'crush' hash type, and cannot handle
493 * unknown hash if client doesn't set a valid one. switch to fnv_1a_64.
495 if (!(exp_connect_flags2(sbi->ll_md_exp) & OBD_CONNECT2_CRUSH)) {
496 enum lmv_hash_type type = lump->lum_hash_type &
499 if (type == LMV_HASH_TYPE_CRUSH ||
500 type == LMV_HASH_TYPE_UNKNOWN)
501 lump->lum_hash_type = (lump->lum_hash_type ^ type) |
502 LMV_HASH_TYPE_FNV_1A_64;
505 hash_flags = lump->lum_hash_type & ~LMV_HASH_TYPE_MASK;
506 if (hash_flags & ~LMV_HASH_FLAG_KNOWN)
509 if (unlikely(!lmv_user_magic_supported(cpu_to_le32(lump->lum_magic))))
510 lustre_swab_lmv_user_md(lump);
512 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
513 mode &= ~current_umask();
514 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
515 op_data = ll_prep_md_op_data(NULL, parent, NULL, dirname,
516 strlen(dirname), mode, LUSTRE_OPC_MKDIR,
519 RETURN(PTR_ERR(op_data));
521 op_data->op_dir_depth = ll_i2info(parent)->lli_dir_depth;
523 if (ll_sbi_has_encrypt(sbi) &&
524 (IS_ENCRYPTED(parent) ||
525 unlikely(llcrypt_dummy_context_enabled(parent)))) {
526 err = llcrypt_get_encryption_info(parent);
528 GOTO(out_op_data, err);
529 if (!llcrypt_has_encryption_key(parent))
530 GOTO(out_op_data, err = -ENOKEY);
534 if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
535 /* selinux_dentry_init_security() uses dentry->d_parent and name
536 * to determine the security context for the file. So our fake
537 * dentry should be real enough for this purpose. */
538 err = ll_dentry_init_security(&dentry, mode, &dentry.d_name,
539 &op_data->op_file_secctx_name,
540 &op_data->op_file_secctx,
541 &op_data->op_file_secctx_size);
543 GOTO(out_op_data, err);
547 err = llcrypt_inherit_context(parent, NULL, op_data, false);
549 GOTO(out_op_data, err);
552 op_data->op_cli_flags |= CLI_SET_MEA;
554 op_data->op_bias |= MDS_SETSTRIPE_CREATE;
556 err = md_create(sbi->ll_md_exp, op_data, lump, len, mode,
557 from_kuid(&init_user_ns, current_fsuid()),
558 from_kgid(&init_user_ns, current_fsgid()),
559 current_cap(), 0, &request);
561 GOTO(out_request, err);
563 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_SETDIRSTRIPE_PAUSE, cfs_fail_val);
565 err = ll_prep_inode(&inode, &request->rq_pill, parent->i_sb, NULL);
567 GOTO(out_inode, err);
569 dentry.d_inode = inode;
571 if (test_bit(LL_SBI_FILE_SECCTX, sbi->ll_flags)) {
572 /* no need to protect selinux_inode_setsecurity() by
573 * inode_lock. Taking it would lead to a client deadlock
576 err = security_inode_notifysecctx(inode,
577 op_data->op_file_secctx,
578 op_data->op_file_secctx_size);
580 err = ll_inode_init_security(&dentry, inode, parent);
583 GOTO(out_inode, err);
586 err = ll_set_encflags(inode, op_data->op_file_encctx,
587 op_data->op_file_encctx_size, false);
589 GOTO(out_inode, err);
595 ptlrpc_req_finished(request);
597 ll_finish_md_op_data(op_data);
602 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
605 struct ll_sb_info *sbi = ll_i2sbi(inode);
606 struct md_op_data *op_data;
607 struct ptlrpc_request *req = NULL;
613 switch (lump->lmm_magic) {
614 case LOV_USER_MAGIC_V1:
615 lum_size = sizeof(struct lov_user_md_v1);
617 case LOV_USER_MAGIC_V3:
618 lum_size = sizeof(struct lov_user_md_v3);
620 case LOV_USER_MAGIC_COMP_V1:
621 lum_size = ((struct lov_comp_md_v1 *)lump)->lcm_size;
624 if (lump->lmm_magic != cpu_to_le32(LMV_USER_MAGIC))
625 lustre_swab_lmv_user_md(
626 (struct lmv_user_md *)lump);
627 lum_size = sizeof(struct lmv_user_md);
629 case LOV_USER_MAGIC_SPECIFIC: {
630 struct lov_user_md_v3 *v3 =
631 (struct lov_user_md_v3 *)lump;
632 if (v3->lmm_stripe_count > LOV_MAX_STRIPE_COUNT)
634 lum_size = lov_user_md_size(v3->lmm_stripe_count,
635 LOV_USER_MAGIC_SPECIFIC);
639 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
640 " %#08x != %#08x nor %#08x\n",
641 lump->lmm_magic, LOV_USER_MAGIC_V1,
647 * This is coming from userspace, so should be in
648 * local endian. But the MDS would like it in little
649 * endian, so we swab it before we send it.
651 if ((__swab32(lump->lmm_magic) & le32_to_cpu(LOV_MAGIC_MASK)) ==
652 le32_to_cpu(LOV_MAGIC_MAGIC))
653 lustre_swab_lov_user_md(lump, 0);
655 lum_size = sizeof(struct lov_user_md_v1);
658 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
659 LUSTRE_OPC_ANY, NULL);
661 RETURN(PTR_ERR(op_data));
663 /* swabbing is done in lov_setstripe() on server side */
664 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size, &req);
665 ll_finish_md_op_data(op_data);
666 ptlrpc_req_finished(req);
673 static int ll_dir_get_default_layout(struct inode *inode, void **plmm,
675 struct ptlrpc_request **request, u64 valid,
676 enum get_default_layout_type type)
678 struct ll_sb_info *sbi = ll_i2sbi(inode);
679 struct mdt_body *body;
680 struct lov_mds_md *lmm = NULL;
681 struct ptlrpc_request *req = NULL;
683 struct md_op_data *op_data;
687 rc = ll_get_default_mdsize(sbi, &lmm_size);
691 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
692 0, lmm_size, LUSTRE_OPC_ANY,
695 RETURN(PTR_ERR(op_data));
697 op_data->op_valid = valid | OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
699 if (type == GET_DEFAULT_LAYOUT_ROOT) {
700 lu_root_fid(&op_data->op_fid1);
701 fid = op_data->op_fid1;
703 fid = *ll_inode2fid(inode);
706 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
707 ll_finish_md_op_data(op_data);
709 CDEBUG(D_INFO, "md_getattr failed on inode "DFID": rc %d\n",
714 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
715 LASSERT(body != NULL);
717 lmm_size = body->mbo_eadatasize;
719 if (!(body->mbo_valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
721 GOTO(out, rc = -ENODATA);
724 lmm = req_capsule_server_sized_get(&req->rq_pill,
725 &RMF_MDT_MD, lmm_size);
726 LASSERT(lmm != NULL);
729 * This is coming from the MDS, so is probably in
730 * little endian. We convert it to host endian before
731 * passing it to userspace.
733 /* We don't swab objects for directories */
734 switch (le32_to_cpu(lmm->lmm_magic)) {
737 case LOV_MAGIC_COMP_V1:
738 case LOV_USER_MAGIC_SPECIFIC:
739 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
740 lustre_swab_lov_user_md((struct lov_user_md *)lmm, 0);
743 if (LMV_MAGIC != cpu_to_le32(LMV_MAGIC))
744 lustre_swab_lmv_mds_md((union lmv_mds_md *)lmm);
747 if (LMV_USER_MAGIC != cpu_to_le32(LMV_USER_MAGIC))
748 lustre_swab_lmv_user_md((struct lmv_user_md *)lmm);
750 case LMV_MAGIC_FOREIGN: {
751 struct lmv_foreign_md *lfm = (struct lmv_foreign_md *)lmm;
753 if (LMV_MAGIC_FOREIGN != cpu_to_le32(LMV_MAGIC_FOREIGN)) {
754 __swab32s(&lfm->lfm_magic);
755 __swab32s(&lfm->lfm_length);
756 __swab32s(&lfm->lfm_type);
757 __swab32s(&lfm->lfm_flags);
762 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
767 *plmm_size = lmm_size;
773 * This function will be used to get default LOV/LMV/Default LMV
774 * @valid will be used to indicate which stripe it will retrieve.
775 * If the directory does not have its own default layout, then the
776 * function will request the default layout from root FID.
777 * OBD_MD_MEA LMV stripe EA
778 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
779 * otherwise Default LOV EA.
780 * Each time, it can only retrieve 1 stripe EA
782 int ll_dir_getstripe_default(struct inode *inode, void **plmm, int *plmm_size,
783 struct ptlrpc_request **request,
784 struct ptlrpc_request **root_request,
787 struct ptlrpc_request *req = NULL;
788 struct ptlrpc_request *root_req = NULL;
789 struct lov_mds_md *lmm = NULL;
794 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
796 if (rc == -ENODATA && !fid_is_root(ll_inode2fid(inode)) &&
797 !(valid & OBD_MD_MEA) && root_request != NULL) {
798 int rc2 = ll_dir_get_default_layout(inode, (void **)&lmm,
799 &lmm_size, &root_req, valid,
800 GET_DEFAULT_LAYOUT_ROOT);
806 *plmm_size = lmm_size;
808 if (root_request != NULL)
809 *root_request = root_req;
815 * This function will be used to get default LOV/LMV/Default LMV
816 * @valid will be used to indicate which stripe it will retrieve
817 * OBD_MD_MEA LMV stripe EA
818 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
819 * otherwise Default LOV EA.
820 * Each time, it can only retrieve 1 stripe EA
822 int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
823 struct ptlrpc_request **request, u64 valid)
825 struct ptlrpc_request *req = NULL;
826 struct lov_mds_md *lmm = NULL;
831 rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
835 *plmm_size = lmm_size;
841 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid)
843 struct md_op_data *op_data;
848 OBD_ALLOC_PTR(op_data);
852 op_data->op_flags |= MF_GET_MDT_IDX;
853 op_data->op_fid1 = *fid;
854 rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
855 mdt_index = op_data->op_mds;
856 OBD_FREE_PTR(op_data);
864 * Get MDT index for the inode.
866 int ll_get_mdt_idx(struct inode *inode)
868 return ll_get_mdt_idx_by_fid(ll_i2sbi(inode), ll_inode2fid(inode));
872 * Generic handler to do any pre-copy work.
874 * It sends a first hsm_progress (with extent length == 0) to coordinator as a
875 * first information for it that real work has started.
877 * Moreover, for a ARCHIVE request, it will sample the file data version and
878 * store it in \a copy.
880 * \return 0 on success.
882 static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
884 struct ll_sb_info *sbi = ll_s2sbi(sb);
885 struct hsm_progress_kernel hpk;
890 /* Forge a hsm_progress based on data from copy. */
891 hpk.hpk_fid = copy->hc_hai.hai_fid;
892 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
893 hpk.hpk_extent.offset = copy->hc_hai.hai_extent.offset;
894 hpk.hpk_extent.length = 0;
897 hpk.hpk_data_version = 0;
900 /* For archive request, we need to read the current file version. */
901 if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
903 __u64 data_version = 0;
905 /* Get inode for this fid */
906 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
908 hpk.hpk_flags |= HP_FLAG_RETRY;
909 /* hpk_errval is >= 0 */
910 hpk.hpk_errval = -PTR_ERR(inode);
911 GOTO(progress, rc = PTR_ERR(inode));
914 /* Read current file data version */
915 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
918 CDEBUG(D_HSM, "Could not read file data version of "
919 DFID" (rc = %d). Archive request ("
920 "%#llx) could not be done.\n",
921 PFID(©->hc_hai.hai_fid), rc,
922 copy->hc_hai.hai_cookie);
923 hpk.hpk_flags |= HP_FLAG_RETRY;
924 /* hpk_errval must be >= 0 */
925 hpk.hpk_errval = -rc;
929 /* Store in the hsm_copy for later copytool use.
930 * Always modified even if no lsm. */
931 copy->hc_data_version = data_version;
935 /* On error, the request should be considered as completed */
936 if (hpk.hpk_errval > 0)
937 hpk.hpk_flags |= HP_FLAG_COMPLETED;
939 rc2 = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
942 /* Return first error */
943 RETURN(rc != 0 ? rc : rc2);
947 * Generic handler to do any post-copy work.
949 * It will send the last hsm_progress update to coordinator to inform it
950 * that copy is finished and whether it was successful or not.
953 * - for ARCHIVE request, it will sample the file data version and compare it
954 * with the version saved in ll_ioc_copy_start(). If they do not match, copy
955 * will be considered as failed.
956 * - for RESTORE request, it will sample the file data version and send it to
957 * coordinator which is useful if the file was imported as 'released'.
959 * \return 0 on success.
961 static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
963 struct ll_sb_info *sbi = ll_s2sbi(sb);
964 struct hsm_progress_kernel hpk;
969 /* If you modify the logic here, also check llapi_hsm_copy_end(). */
970 /* Take care: copy->hc_hai.hai_action, len, gid and data are not
971 * initialized if copy_end was called with copy == NULL.
974 /* Forge a hsm_progress based on data from copy. */
975 hpk.hpk_fid = copy->hc_hai.hai_fid;
976 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
977 hpk.hpk_extent = copy->hc_hai.hai_extent;
978 hpk.hpk_flags = copy->hc_flags | HP_FLAG_COMPLETED;
979 hpk.hpk_errval = copy->hc_errval;
980 hpk.hpk_data_version = 0;
982 /* For archive request, we need to check the file data was not changed.
984 * For restore request, we need to send the file data version, this is
985 * useful when the file was created using hsm_import.
987 if (((copy->hc_hai.hai_action == HSMA_ARCHIVE) ||
988 (copy->hc_hai.hai_action == HSMA_RESTORE)) &&
989 (copy->hc_errval == 0)) {
991 __u64 data_version = 0;
993 /* Get lsm for this fid */
994 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
996 hpk.hpk_flags |= HP_FLAG_RETRY;
997 /* hpk_errval must be >= 0 */
998 hpk.hpk_errval = -PTR_ERR(inode);
999 GOTO(progress, rc = PTR_ERR(inode));
1002 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
1005 CDEBUG(D_HSM, "Could not read file data version. "
1006 "Request could not be confirmed.\n");
1007 if (hpk.hpk_errval == 0)
1008 hpk.hpk_errval = -rc;
1012 /* Store in the hsm_copy for later copytool use.
1013 * Always modified even if no lsm. */
1014 hpk.hpk_data_version = data_version;
1016 /* File could have been stripped during archiving, so we need
1017 * to check anyway. */
1018 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
1019 (copy->hc_data_version != data_version)) {
1020 CDEBUG(D_HSM, "File data version mismatched. "
1021 "File content was changed during archiving. "
1022 DFID", start:%#llx current:%#llx\n",
1023 PFID(©->hc_hai.hai_fid),
1024 copy->hc_data_version, data_version);
1025 /* File was changed, send error to cdt. Do not ask for
1026 * retry because if a file is modified frequently,
1027 * the cdt will loop on retried archive requests.
1028 * The policy engine will ask for a new archive later
1029 * when the file will not be modified for some tunable
1031 hpk.hpk_flags &= ~HP_FLAG_RETRY;
1033 /* hpk_errval must be >= 0 */
1034 hpk.hpk_errval = -rc;
1041 rc2 = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
1044 /* Return first error */
1045 RETURN(rc != 0 ? rc : rc2);
1049 static int copy_and_ct_start(int cmd, struct obd_export *exp,
1050 const struct lustre_kernelcomm __user *data)
1052 struct lustre_kernelcomm *lk;
1053 struct lustre_kernelcomm *tmp;
1054 size_t size = sizeof(*lk);
1059 /* copy data from userspace to get numbers of archive_id */
1060 OBD_ALLOC(lk, size);
1064 if (copy_from_user(lk, data, size))
1065 GOTO(out_lk, rc = -EFAULT);
1067 if (lk->lk_flags & LK_FLG_STOP)
1070 if (!(lk->lk_flags & LK_FLG_DATANR)) {
1071 __u32 archive_mask = lk->lk_data_count;
1074 /* old hsm agent to old MDS */
1075 if (!exp_connect_archive_id_array(exp))
1078 /* old hsm agent to new MDS */
1079 lk->lk_flags |= LK_FLG_DATANR;
1081 if (archive_mask == 0)
1084 count = hweight32(archive_mask);
1085 new_size = offsetof(struct lustre_kernelcomm, lk_data[count]);
1086 OBD_ALLOC(tmp, new_size);
1088 GOTO(out_lk, rc = -ENOMEM);
1090 memcpy(tmp, lk, size);
1091 tmp->lk_data_count = count;
1097 for (i = 0; i < sizeof(archive_mask) * 8; i++) {
1098 if (BIT(i) & archive_mask) {
1099 lk->lk_data[count] = i + 1;
1106 /* new hsm agent to new mds */
1107 if (lk->lk_data_count > 0) {
1108 new_size = offsetof(struct lustre_kernelcomm,
1109 lk_data[lk->lk_data_count]);
1110 OBD_ALLOC(tmp, new_size);
1112 GOTO(out_lk, rc = -ENOMEM);
1118 if (copy_from_user(lk, data, size))
1119 GOTO(out_lk, rc = -EFAULT);
1122 /* new hsm agent to old MDS */
1123 if (!exp_connect_archive_id_array(exp)) {
1126 if (lk->lk_data_count > LL_HSM_ORIGIN_MAX_ARCHIVE)
1127 GOTO(out_lk, rc = -EINVAL);
1129 for (i = 0; i < lk->lk_data_count; i++) {
1130 if (lk->lk_data[i] > LL_HSM_ORIGIN_MAX_ARCHIVE) {
1132 CERROR("%s: archive id %d requested but only "
1133 "[0 - %zu] supported: rc = %d\n",
1134 exp->exp_obd->obd_name, lk->lk_data[i],
1135 LL_HSM_ORIGIN_MAX_ARCHIVE, rc);
1139 if (lk->lk_data[i] == 0) {
1144 archives |= (1 << (lk->lk_data[i] - 1));
1146 lk->lk_flags &= ~LK_FLG_DATANR;
1147 lk->lk_data_count = archives;
1150 rc = obd_iocontrol(cmd, exp, size, lk, NULL);
1156 static int check_owner(int type, int id)
1160 if (!uid_eq(current_euid(), make_kuid(&init_user_ns, id)))
1164 if (!in_egroup_p(make_kgid(&init_user_ns, id)))
1173 int quotactl_ioctl(struct super_block *sb, struct if_quotactl *qctl)
1175 struct ll_sb_info *sbi = ll_s2sbi(sb);
1176 int cmd = qctl->qc_cmd;
1177 int type = qctl->qc_type;
1178 int id = qctl->qc_id;
1179 int valid = qctl->qc_valid;
1187 case LUSTRE_Q_SETDEFAULT:
1188 case LUSTRE_Q_SETQUOTAPOOL:
1189 case LUSTRE_Q_SETINFOPOOL:
1190 case LUSTRE_Q_SETDEFAULT_POOL:
1191 if (!capable(CAP_SYS_ADMIN))
1194 if (sb->s_flags & SB_RDONLY)
1198 case LUSTRE_Q_GETDEFAULT:
1199 case LUSTRE_Q_GETQUOTAPOOL:
1200 case LUSTRE_Q_GETDEFAULT_POOL:
1201 if (check_owner(type, id) &&
1202 (!capable(CAP_SYS_ADMIN)))
1206 case LUSTRE_Q_GETINFOPOOL:
1209 CERROR("unsupported quotactl op: %#x\n", cmd);
1213 if (valid != QC_GENERAL) {
1214 if (cmd == Q_GETINFO)
1215 qctl->qc_cmd = Q_GETOINFO;
1216 else if (cmd == Q_GETQUOTA ||
1217 cmd == LUSTRE_Q_GETQUOTAPOOL)
1218 qctl->qc_cmd = Q_GETOQUOTA;
1224 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
1225 sizeof(*qctl), qctl, NULL);
1228 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
1229 sizeof(*qctl), qctl, NULL);
1232 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
1233 sizeof(*qctl), qctl, NULL);
1235 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1237 sizeof(*qctl), qctl, NULL);
1249 struct obd_quotactl *oqctl;
1250 int oqctl_len = sizeof(*oqctl);
1252 if (LUSTRE_Q_CMD_IS_POOL(cmd))
1253 oqctl_len += LOV_MAXPOOLNAME + 1;
1255 OBD_ALLOC(oqctl, oqctl_len);
1259 QCTL_COPY(oqctl, qctl);
1260 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1262 OBD_FREE(oqctl, oqctl_len);
1265 /* If QIF_SPACE is not set, client should collect the
1266 * space usage from OSSs by itself */
1267 if ((cmd == Q_GETQUOTA || cmd == LUSTRE_Q_GETQUOTAPOOL) &&
1268 !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
1269 !oqctl->qc_dqblk.dqb_curspace) {
1270 struct obd_quotactl *oqctl_tmp;
1271 int qctl_len = sizeof(*oqctl_tmp) + LOV_MAXPOOLNAME + 1;
1273 OBD_ALLOC(oqctl_tmp, qctl_len);
1274 if (oqctl_tmp == NULL)
1275 GOTO(out, rc = -ENOMEM);
1277 if (cmd == LUSTRE_Q_GETQUOTAPOOL) {
1278 oqctl_tmp->qc_cmd = LUSTRE_Q_GETQUOTAPOOL;
1279 memcpy(oqctl_tmp->qc_poolname,
1281 LOV_MAXPOOLNAME + 1);
1283 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1285 oqctl_tmp->qc_id = oqctl->qc_id;
1286 oqctl_tmp->qc_type = oqctl->qc_type;
1288 /* collect space usage from OSTs */
1289 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1290 rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
1291 if (!rc || rc == -EREMOTEIO) {
1292 oqctl->qc_dqblk.dqb_curspace =
1293 oqctl_tmp->qc_dqblk.dqb_curspace;
1294 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
1297 /* collect space & inode usage from MDTs */
1298 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1299 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1300 oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
1301 rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
1302 if (!rc || rc == -EREMOTEIO) {
1303 oqctl->qc_dqblk.dqb_curspace +=
1304 oqctl_tmp->qc_dqblk.dqb_curspace;
1305 oqctl->qc_dqblk.dqb_curinodes =
1306 oqctl_tmp->qc_dqblk.dqb_curinodes;
1307 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
1309 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
1312 OBD_FREE(oqctl_tmp, qctl_len);
1315 QCTL_COPY(qctl, oqctl);
1316 OBD_FREE(oqctl, oqctl_len);
1322 int ll_rmfid(struct file *file, void __user *arg)
1324 const struct fid_array __user *ufa = arg;
1325 struct inode *inode = file_inode(file);
1326 struct fid_array *lfa = NULL;
1329 int i, rc, *rcs = NULL;
1332 if (!capable(CAP_DAC_READ_SEARCH) &&
1333 !test_bit(LL_SBI_USER_FID2PATH, ll_i2sbi(inode)->ll_flags))
1335 /* Only need to get the buflen */
1336 if (get_user(nr, &ufa->fa_nr))
1338 /* DoS protection */
1339 if (nr > OBD_MAX_FIDS_IN_ARRAY)
1342 size = offsetof(struct fid_array, fa_fids[nr]);
1343 OBD_ALLOC(lfa, size);
1346 OBD_ALLOC_PTR_ARRAY(rcs, nr);
1348 GOTO(free_lfa, rc = -ENOMEM);
1350 if (copy_from_user(lfa, arg, size))
1351 GOTO(free_rcs, rc = -EFAULT);
1353 /* Call mdc_iocontrol */
1354 rc = md_rmfid(ll_i2mdexp(file_inode(file)), lfa, rcs, NULL);
1356 for (i = 0; i < nr; i++)
1358 lfa->fa_fids[i].f_ver = rcs[i];
1359 if (copy_to_user(arg, lfa, size))
1364 OBD_FREE_PTR_ARRAY(rcs, nr);
1366 OBD_FREE(lfa, size);
1371 /* This function tries to get a single name component,
1372 * to send to the server. No actual path traversal involved,
1373 * so we limit to NAME_MAX */
1374 static char *ll_getname(const char __user *filename)
1379 OBD_ALLOC(tmp, NAME_MAX + 1);
1382 return ERR_PTR(-ENOMEM);
1384 len = strncpy_from_user(tmp, filename, NAME_MAX + 1);
1387 else if (len > NAME_MAX)
1388 ret = -ENAMETOOLONG;
1391 OBD_FREE(tmp, NAME_MAX + 1);
1397 #define ll_putname(filename) OBD_FREE(filename, NAME_MAX + 1);
1399 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1401 struct dentry *dentry = file_dentry(file);
1402 struct inode *inode = file_inode(file);
1403 struct ll_sb_info *sbi = ll_i2sbi(inode);
1404 struct obd_ioctl_data *data = NULL;
1408 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%#x\n",
1409 PFID(ll_inode2fid(inode)), inode, cmd);
1411 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
1412 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
1415 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
1417 case FS_IOC_GETFLAGS:
1418 case FS_IOC_SETFLAGS:
1419 RETURN(ll_iocontrol(inode, file, cmd, arg));
1420 case FSFILT_IOC_GETVERSION:
1421 case FS_IOC_GETVERSION:
1422 RETURN(put_user(inode->i_generation, (int __user *)arg));
1423 /* We need to special case any other ioctls we want to handle,
1424 * to send them to the MDS/OST as appropriate and to properly
1425 * network encode the arg field. */
1426 case FS_IOC_SETVERSION:
1429 case LL_IOC_GET_MDTIDX: {
1432 mdtidx = ll_get_mdt_idx(inode);
1436 if (put_user((int)mdtidx, (int __user *)arg))
1441 case IOC_MDC_LOOKUP: {
1442 int namelen, len = 0;
1445 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
1449 filename = data->ioc_inlbuf1;
1450 namelen = strlen(filename);
1452 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1453 GOTO(out_free, rc = -EINVAL);
1456 rc = ll_get_fid_by_name(inode, filename, namelen, NULL, NULL);
1458 CERROR("%s: lookup %.*s failed: rc = %d\n",
1459 sbi->ll_fsname, namelen, filename, rc);
1463 OBD_FREE_LARGE(data, len);
1466 case LL_IOC_LMV_SETSTRIPE: {
1467 struct lmv_user_md *lum;
1472 bool createonly = false;
1476 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
1480 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1481 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1482 GOTO(lmv_out_free, rc = -EINVAL);
1484 filename = data->ioc_inlbuf1;
1485 namelen = data->ioc_inllen1;
1488 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1489 GOTO(lmv_out_free, rc = -EINVAL);
1491 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1492 lumlen = data->ioc_inllen2;
1494 if (!lmv_user_magic_supported(lum->lum_magic)) {
1495 CERROR("%s: wrong lum magic %x : rc = %d\n", filename,
1496 lum->lum_magic, -EINVAL);
1497 GOTO(lmv_out_free, rc = -EINVAL);
1500 if ((lum->lum_magic == LMV_USER_MAGIC ||
1501 lum->lum_magic == LMV_USER_MAGIC_SPECIFIC) &&
1502 lumlen < sizeof(*lum)) {
1503 CERROR("%s: wrong lum size %d for magic %x : rc = %d\n",
1504 filename, lumlen, lum->lum_magic, -EINVAL);
1505 GOTO(lmv_out_free, rc = -EINVAL);
1508 if (lum->lum_magic == LMV_MAGIC_FOREIGN &&
1509 lumlen < sizeof(struct lmv_foreign_md)) {
1510 CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1511 filename, lum->lum_magic, lumlen, -EFAULT);
1512 GOTO(lmv_out_free, rc = -EINVAL);
1515 mode = data->ioc_type;
1516 createonly = data->ioc_obdo1.o_flags & OBD_FL_OBDMDEXISTS;
1517 rc = ll_dir_setdirstripe(dentry, lum, lumlen, filename, mode,
1520 OBD_FREE_LARGE(data, len);
1524 case LL_IOC_LMV_SET_DEFAULT_STRIPE: {
1525 struct lmv_user_md lum;
1526 struct lmv_user_md __user *ulump =
1527 (struct lmv_user_md __user *)arg;
1530 if (copy_from_user(&lum, ulump, sizeof(lum)))
1533 if (lum.lum_magic != LMV_USER_MAGIC)
1536 rc = ll_dir_setstripe(inode, (struct lov_user_md *)&lum, 0);
1540 case LL_IOC_LOV_SETSTRIPE_NEW:
1541 case LL_IOC_LOV_SETSTRIPE: {
1542 struct lov_user_md_v3 *lumv3 = NULL;
1543 struct lov_user_md_v1 lumv1;
1544 struct lov_user_md_v1 *lumv1_ptr = &lumv1;
1545 struct lov_user_md_v1 __user *lumv1p =
1546 (struct lov_user_md_v1 __user *)arg;
1547 struct lov_user_md_v3 __user *lumv3p =
1548 (struct lov_user_md_v3 __user *)arg;
1551 int set_default = 0;
1553 BUILD_BUG_ON(sizeof(struct lov_user_md_v3) <=
1554 sizeof(struct lov_comp_md_v1));
1555 BUILD_BUG_ON(sizeof(*lumv3) != sizeof(*lumv3p));
1556 /* first try with v1 which is smaller than v3 */
1557 if (copy_from_user(&lumv1, lumv1p, sizeof(lumv1)))
1560 if (is_root_inode(inode))
1563 switch (lumv1.lmm_magic) {
1564 case LOV_USER_MAGIC_V3:
1565 case LOV_USER_MAGIC_SPECIFIC:
1566 lum_size = ll_lov_user_md_size(&lumv1);
1569 OBD_ALLOC(lumv3, lum_size);
1572 if (copy_from_user(lumv3, lumv3p, lum_size))
1573 GOTO(out, rc = -EFAULT);
1574 lumv1_ptr = (struct lov_user_md_v1 *)lumv3;
1576 case LOV_USER_MAGIC_V1:
1579 GOTO(out, rc = -ENOTSUPP);
1582 /* in v1 and v3 cases lumv1 points to data */
1583 rc = ll_dir_setstripe(inode, lumv1_ptr, set_default);
1586 OBD_FREE(lumv3, lum_size);
1589 case LL_IOC_LMV_GETSTRIPE: {
1590 struct lmv_user_md __user *ulmv =
1591 (struct lmv_user_md __user *)arg;
1592 struct lmv_user_md lum;
1593 struct ptlrpc_request *request = NULL;
1594 struct ptlrpc_request *root_request = NULL;
1595 union lmv_mds_md *lmm = NULL;
1598 struct lmv_user_md *tmp = NULL;
1602 int max_stripe_count;
1606 if (copy_from_user(&lum, ulmv, sizeof(*ulmv)))
1609 max_stripe_count = lum.lum_stripe_count;
1610 /* lum_magic will indicate which stripe the ioctl will like
1611 * to get, LMV_MAGIC_V1 is for normal LMV stripe, LMV_USER_MAGIC
1612 * is for default LMV stripe */
1613 if (lum.lum_magic == LMV_MAGIC_V1)
1614 valid |= OBD_MD_MEA;
1615 else if (lum.lum_magic == LMV_USER_MAGIC)
1616 valid |= OBD_MD_DEFAULT_MEA;
1620 rc = ll_dir_getstripe_default(inode, (void **)&lmm, &lmmsize,
1621 &request, &root_request, valid);
1623 GOTO(finish_req, rc);
1625 /* Get default LMV EA */
1626 if (lum.lum_magic == LMV_USER_MAGIC) {
1627 if (lmmsize > sizeof(*ulmv))
1628 GOTO(finish_req, rc = -EINVAL);
1630 if (root_request != NULL) {
1631 struct lmv_user_md *lum;
1632 struct ll_inode_info *lli;
1634 lum = (struct lmv_user_md *)lmm;
1635 lli = ll_i2info(inode);
1636 if (lum->lum_max_inherit == LMV_INHERIT_NONE ||
1637 (lum->lum_max_inherit > 0 &&
1638 lum->lum_max_inherit < lli->lli_dir_depth))
1639 GOTO(finish_req, rc = -ENODATA);
1641 if (lum->lum_max_inherit ==
1642 lli->lli_dir_depth) {
1643 lum->lum_max_inherit = LMV_INHERIT_NONE;
1644 lum->lum_max_inherit_rr =
1645 LMV_INHERIT_RR_NONE;
1648 if (lum->lum_max_inherit > lli->lli_dir_depth &&
1649 lum->lum_max_inherit <= LMV_INHERIT_MAX)
1650 lum->lum_max_inherit -=
1653 if (lum->lum_max_inherit_rr >
1654 lli->lli_dir_depth &&
1655 lum->lum_max_inherit_rr <=
1657 lum->lum_max_inherit_rr -=
1659 else if (lum->lum_max_inherit_rr ==
1661 lum->lum_max_inherit_rr =
1662 LMV_INHERIT_RR_NONE;
1665 if (copy_to_user(ulmv, lmm, lmmsize))
1666 GOTO(finish_req, rc = -EFAULT);
1668 GOTO(finish_req, rc);
1671 /* if foreign LMV case, fake stripes number */
1672 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1673 struct lmv_foreign_md *lfm;
1675 lfm = (struct lmv_foreign_md *)lmm;
1676 if (lfm->lfm_length < XATTR_SIZE_MAX -
1677 offsetof(typeof(*lfm), lfm_value)) {
1678 __u32 size = lfm->lfm_length +
1679 offsetof(typeof(*lfm), lfm_value);
1681 stripe_count = lmv_foreign_to_md_stripes(size);
1683 CERROR("invalid %d foreign size returned\n",
1688 stripe_count = lmv_mds_md_stripe_count_get(lmm);
1690 if (max_stripe_count < stripe_count) {
1691 lum.lum_stripe_count = stripe_count;
1692 if (copy_to_user(ulmv, &lum, sizeof(lum)))
1693 GOTO(finish_req, rc = -EFAULT);
1694 GOTO(finish_req, rc = -E2BIG);
1697 /* enough room on user side and foreign case */
1698 if (lmm->lmv_magic == LMV_MAGIC_FOREIGN) {
1699 struct lmv_foreign_md *lfm;
1702 lfm = (struct lmv_foreign_md *)lmm;
1703 size = lfm->lfm_length +
1704 offsetof(struct lmv_foreign_md, lfm_value);
1705 if (copy_to_user(ulmv, lfm, size))
1706 GOTO(finish_req, rc = -EFAULT);
1707 GOTO(finish_req, rc);
1710 lum_size = lmv_user_md_size(stripe_count,
1711 LMV_USER_MAGIC_SPECIFIC);
1712 OBD_ALLOC(tmp, lum_size);
1714 GOTO(finish_req, rc = -ENOMEM);
1716 mdt_index = ll_get_mdt_idx(inode);
1718 GOTO(out_tmp, rc = -ENOMEM);
1720 tmp->lum_magic = LMV_MAGIC_V1;
1721 tmp->lum_stripe_count = 0;
1722 tmp->lum_stripe_offset = mdt_index;
1723 tmp->lum_hash_type = lmv_mds_md_hash_type_get(lmm);
1724 for (i = 0; i < stripe_count; i++) {
1727 fid_le_to_cpu(&fid, &lmm->lmv_md_v1.lmv_stripe_fids[i]);
1728 if (fid_is_sane(&fid)) {
1729 mdt_index = ll_get_mdt_idx_by_fid(sbi, &fid);
1731 GOTO(out_tmp, rc = mdt_index);
1733 tmp->lum_objects[i].lum_mds = mdt_index;
1734 tmp->lum_objects[i].lum_fid = fid;
1737 tmp->lum_stripe_count++;
1740 if (copy_to_user(ulmv, tmp, lum_size))
1741 GOTO(out_tmp, rc = -EFAULT);
1743 OBD_FREE(tmp, lum_size);
1745 ptlrpc_req_finished(request);
1746 ptlrpc_req_finished(root_request);
1750 case LL_IOC_UNLOCK_FOREIGN:
1751 /* if not a foreign symlink do nothing */
1752 if (ll_foreign_is_removable(dentry, true)) {
1754 "prevent rmdir of non-foreign dir ("DFID")\n",
1755 PFID(ll_inode2fid(inode)));
1756 RETURN(-EOPNOTSUPP);
1760 case LL_IOC_REMOVE_ENTRY: {
1761 char *filename = NULL;
1765 /* Here is a little hack to avoid sending REINT_RMENTRY to
1766 * unsupported server, which might crash the server(LU-2730),
1767 * Because both LVB_TYPE and REINT_RMENTRY will be supported
1768 * on 2.4, we use OBD_CONNECT_LVB_TYPE to detect whether the
1769 * server will support REINT_RMENTRY XXX*/
1770 if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE))
1773 filename = ll_getname((const char __user *)arg);
1774 if (IS_ERR(filename))
1775 RETURN(PTR_ERR(filename));
1777 namelen = strlen(filename);
1779 GOTO(out_rmdir, rc = -EINVAL);
1781 rc = ll_rmdir_entry(inode, filename, namelen);
1784 ll_putname(filename);
1788 RETURN(ll_rmfid(file, (void __user *)arg));
1789 case LL_IOC_LOV_SWAP_LAYOUTS:
1791 case IOC_OBD_STATFS:
1792 RETURN(ll_obd_statfs(inode, (void __user *)arg));
1793 case LL_IOC_LOV_GETSTRIPE:
1794 case LL_IOC_LOV_GETSTRIPE_NEW:
1795 case LL_IOC_MDC_GETINFO_V1:
1796 case LL_IOC_MDC_GETINFO_V2:
1797 case IOC_MDC_GETFILEINFO_V1:
1798 case IOC_MDC_GETFILEINFO_V2:
1799 case IOC_MDC_GETFILESTRIPE: {
1800 struct ptlrpc_request *request = NULL;
1801 struct ptlrpc_request *root_request = NULL;
1802 struct lov_user_md __user *lump;
1803 struct lov_mds_md *lmm = NULL;
1804 struct mdt_body *body;
1805 char *filename = NULL;
1806 lstat_t __user *statp = NULL;
1807 lstatx_t __user *stxp = NULL;
1808 __u64 __user *flagsp = NULL;
1809 __u32 __user *lmmsizep = NULL;
1810 struct lu_fid __user *fidp = NULL;
1814 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1815 cmd == IOC_MDC_GETFILEINFO_V2 ||
1816 cmd == IOC_MDC_GETFILESTRIPE) {
1817 filename = ll_getname((const char __user *)arg);
1818 if (IS_ERR(filename))
1819 RETURN(PTR_ERR(filename));
1821 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1822 &lmmsize, &request);
1824 rc = ll_dir_getstripe_default(inode, (void **)&lmm,
1830 body = req_capsule_server_get(&request->rq_pill,
1832 LASSERT(body != NULL);
1837 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO_V1 ||
1838 cmd == LL_IOC_MDC_GETINFO_V1 ||
1839 cmd == IOC_MDC_GETFILEINFO_V2 ||
1840 cmd == LL_IOC_MDC_GETINFO_V2)) {
1848 if (cmd == IOC_MDC_GETFILESTRIPE ||
1849 cmd == LL_IOC_LOV_GETSTRIPE ||
1850 cmd == LL_IOC_LOV_GETSTRIPE_NEW) {
1851 lump = (struct lov_user_md __user *)arg;
1852 } else if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1853 cmd == LL_IOC_MDC_GETINFO_V1){
1854 struct lov_user_mds_data_v1 __user *lmdp;
1856 lmdp = (struct lov_user_mds_data_v1 __user *)arg;
1857 statp = &lmdp->lmd_st;
1858 lump = &lmdp->lmd_lmm;
1860 struct lov_user_mds_data __user *lmdp;
1862 lmdp = (struct lov_user_mds_data __user *)arg;
1863 fidp = &lmdp->lmd_fid;
1864 stxp = &lmdp->lmd_stx;
1865 flagsp = &lmdp->lmd_flags;
1866 lmmsizep = &lmdp->lmd_lmmsize;
1867 lump = &lmdp->lmd_lmm;
1871 /* If the file has no striping then zero out *lump so
1872 * that the caller isn't confused by garbage. */
1873 if (clear_user(lump, sizeof(*lump)))
1874 GOTO(out_req, rc = -EFAULT);
1875 } else if (copy_to_user(lump, lmm, lmmsize)) {
1876 if (copy_to_user(lump, lmm, sizeof(*lump)))
1877 GOTO(out_req, rc = -EFAULT);
1880 api32 = test_bit(LL_SBI_32BIT_API, sbi->ll_flags);
1882 if (cmd == IOC_MDC_GETFILEINFO_V1 ||
1883 cmd == LL_IOC_MDC_GETINFO_V1) {
1886 st.st_dev = inode->i_sb->s_dev;
1887 st.st_mode = body->mbo_mode;
1888 st.st_nlink = body->mbo_nlink;
1889 st.st_uid = body->mbo_uid;
1890 st.st_gid = body->mbo_gid;
1891 st.st_rdev = body->mbo_rdev;
1892 if (llcrypt_require_key(inode) == -ENOKEY)
1893 st.st_size = round_up(st.st_size,
1894 LUSTRE_ENCRYPTION_UNIT_SIZE);
1896 st.st_size = body->mbo_size;
1897 st.st_blksize = PAGE_SIZE;
1898 st.st_blocks = body->mbo_blocks;
1899 st.st_atime = body->mbo_atime;
1900 st.st_mtime = body->mbo_mtime;
1901 st.st_ctime = body->mbo_ctime;
1902 st.st_ino = cl_fid_build_ino(&body->mbo_fid1,
1905 if (copy_to_user(statp, &st, sizeof(st)))
1906 GOTO(out_req, rc = -EFAULT);
1907 } else if (cmd == IOC_MDC_GETFILEINFO_V2 ||
1908 cmd == LL_IOC_MDC_GETINFO_V2) {
1909 lstatx_t stx = { 0 };
1910 __u64 valid = body->mbo_valid;
1912 stx.stx_blksize = PAGE_SIZE;
1913 stx.stx_nlink = body->mbo_nlink;
1914 stx.stx_uid = body->mbo_uid;
1915 stx.stx_gid = body->mbo_gid;
1916 stx.stx_mode = body->mbo_mode;
1917 stx.stx_ino = cl_fid_build_ino(&body->mbo_fid1,
1919 if (llcrypt_require_key(inode) == -ENOKEY)
1920 stx.stx_size = round_up(stx.stx_size,
1921 LUSTRE_ENCRYPTION_UNIT_SIZE);
1923 stx.stx_size = body->mbo_size;
1924 stx.stx_blocks = body->mbo_blocks;
1925 stx.stx_atime.tv_sec = body->mbo_atime;
1926 stx.stx_ctime.tv_sec = body->mbo_ctime;
1927 stx.stx_mtime.tv_sec = body->mbo_mtime;
1928 stx.stx_btime.tv_sec = body->mbo_btime;
1929 stx.stx_rdev_major = MAJOR(body->mbo_rdev);
1930 stx.stx_rdev_minor = MINOR(body->mbo_rdev);
1931 stx.stx_dev_major = MAJOR(inode->i_sb->s_dev);
1932 stx.stx_dev_minor = MINOR(inode->i_sb->s_dev);
1933 stx.stx_mask |= STATX_BASIC_STATS | STATX_BTIME;
1936 * For a striped directory, the size and blocks returned
1937 * from MDT is not correct.
1938 * The size and blocks are aggregated by client across
1940 * Thus for a striped directory, do not return the valid
1941 * FLSIZE and FLBLOCKS flags to the caller.
1942 * However, this whould be better decided by the MDS
1943 * instead of the client.
1945 if (cmd == LL_IOC_MDC_GETINFO_V2 &&
1946 ll_i2info(inode)->lli_lsm_md != NULL)
1947 valid &= ~(OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
1949 if (flagsp && copy_to_user(flagsp, &valid,
1951 GOTO(out_req, rc = -EFAULT);
1953 if (fidp && copy_to_user(fidp, &body->mbo_fid1,
1955 GOTO(out_req, rc = -EFAULT);
1957 if (!(valid & OBD_MD_FLSIZE))
1958 stx.stx_mask &= ~STATX_SIZE;
1959 if (!(valid & OBD_MD_FLBLOCKS))
1960 stx.stx_mask &= ~STATX_BLOCKS;
1962 if (stxp && copy_to_user(stxp, &stx, sizeof(stx)))
1963 GOTO(out_req, rc = -EFAULT);
1965 if (lmmsizep && copy_to_user(lmmsizep, &lmmsize,
1967 GOTO(out_req, rc = -EFAULT);
1972 ptlrpc_req_finished(request);
1973 ptlrpc_req_finished(root_request);
1975 ll_putname(filename);
1978 case OBD_IOC_QUOTACTL: {
1979 struct if_quotactl *qctl;
1980 int qctl_len = sizeof(*qctl) + LOV_MAXPOOLNAME + 1;
1982 OBD_ALLOC(qctl, qctl_len);
1986 if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl)))
1987 GOTO(out_quotactl, rc = -EFAULT);
1989 if (LUSTRE_Q_CMD_IS_POOL(qctl->qc_cmd)) {
1990 char __user *from = (char __user *)arg +
1991 offsetof(typeof(*qctl), qc_poolname);
1992 if (copy_from_user(qctl->qc_poolname, from,
1993 LOV_MAXPOOLNAME + 1))
1994 GOTO(out_quotactl, rc = -EFAULT);
1997 rc = quotactl_ioctl(inode->i_sb, qctl);
1999 copy_to_user((void __user *)arg, qctl, sizeof(*qctl)))
2003 OBD_FREE(qctl, qctl_len);
2006 case OBD_IOC_GETNAME_OLD:
2008 case OBD_IOC_GETDTNAME:
2010 case OBD_IOC_GETMDNAME:
2011 RETURN(ll_get_obd_name(inode, cmd, arg));
2012 case LL_IOC_FLUSHCTX:
2013 RETURN(ll_flush_ctx(inode));
2014 case LL_IOC_GETOBDCOUNT: {
2016 struct obd_export *exp;
2018 if (copy_from_user(&count, (int __user *)arg, sizeof(int)))
2021 /* get ost count when count is zero, get mdt count otherwise */
2022 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
2023 vallen = sizeof(count);
2024 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
2025 KEY_TGT_COUNT, &vallen, &count);
2027 CERROR("get target count failed: %d\n", rc);
2031 if (copy_to_user((int __user *)arg, &count, sizeof(int)))
2036 case LL_IOC_PATH2FID:
2037 if (copy_to_user((void __user *)arg, ll_inode2fid(inode),
2038 sizeof(struct lu_fid)))
2041 case LL_IOC_GET_CONNECT_FLAGS: {
2042 RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL,
2043 (void __user *)arg));
2045 case OBD_IOC_FID2PATH:
2046 RETURN(ll_fid2path(inode, (void __user *)arg));
2047 case LL_IOC_GETPARENT:
2048 RETURN(ll_getparent(file, (void __user *)arg));
2049 case LL_IOC_FID2MDTIDX: {
2050 struct obd_export *exp = ll_i2mdexp(inode);
2054 if (copy_from_user(&fid, (const struct lu_fid __user *)arg,
2058 /* Call mdc_iocontrol */
2059 rc = obd_iocontrol(LL_IOC_FID2MDTIDX, exp, sizeof(fid), &fid,
2060 (__u32 __user *)&index);
2066 case LL_IOC_HSM_REQUEST: {
2067 struct hsm_user_request *hur;
2074 /* We don't know the true size yet; copy the fixed-size part */
2075 if (copy_from_user(hur, (void __user *)arg, sizeof(*hur))) {
2080 /* Compute the whole struct size */
2081 totalsize = hur_len(hur);
2086 /* Final size will be more than double totalsize */
2087 if (totalsize >= MDS_MAXREQSIZE / 3)
2090 OBD_ALLOC_LARGE(hur, totalsize);
2094 /* Copy the whole struct */
2095 if (copy_from_user(hur, (void __user *)arg, totalsize))
2096 GOTO(out_hur, rc = -EFAULT);
2098 if (hur->hur_request.hr_action == HUA_RELEASE) {
2099 const struct lu_fid *fid;
2103 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
2104 fid = &hur->hur_user_item[i].hui_fid;
2105 f = search_inode_for_lustre(inode->i_sb, fid);
2111 rc = ll_hsm_release(f);
2117 rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
2122 OBD_FREE_LARGE(hur, totalsize);
2126 case LL_IOC_HSM_PROGRESS: {
2127 struct hsm_progress_kernel hpk;
2128 struct hsm_progress hp;
2130 if (copy_from_user(&hp, (void __user *)arg, sizeof(hp)))
2133 hpk.hpk_fid = hp.hp_fid;
2134 hpk.hpk_cookie = hp.hp_cookie;
2135 hpk.hpk_extent = hp.hp_extent;
2136 hpk.hpk_flags = hp.hp_flags;
2137 hpk.hpk_errval = hp.hp_errval;
2138 hpk.hpk_data_version = 0;
2140 /* File may not exist in Lustre; all progress
2141 * reported to Lustre root */
2142 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
2146 case LL_IOC_HSM_CT_START:
2147 if (!capable(CAP_SYS_ADMIN))
2150 rc = copy_and_ct_start(cmd, sbi->ll_md_exp,
2151 (struct lustre_kernelcomm __user *)arg);
2154 case LL_IOC_HSM_COPY_START: {
2155 struct hsm_copy *copy;
2158 OBD_ALLOC_PTR(copy);
2161 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
2166 rc = ll_ioc_copy_start(inode->i_sb, copy);
2167 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
2173 case LL_IOC_HSM_COPY_END: {
2174 struct hsm_copy *copy;
2177 OBD_ALLOC_PTR(copy);
2180 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
2185 rc = ll_ioc_copy_end(inode->i_sb, copy);
2186 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
2192 case LL_IOC_MIGRATE: {
2193 struct lmv_user_md *lum;
2200 rc = obd_ioctl_getdata(&data, &len, (void __user *)arg);
2204 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
2205 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
2206 GOTO(migrate_free, rc = -EINVAL);
2208 filename = data->ioc_inlbuf1;
2209 namelen = data->ioc_inllen1;
2210 flags = data->ioc_type;
2212 if (namelen < 1 || namelen != strlen(filename) + 1) {
2213 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
2214 GOTO(migrate_free, rc = -EINVAL);
2217 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
2218 if (lum->lum_magic != LMV_USER_MAGIC &&
2219 lum->lum_magic != LMV_USER_MAGIC_SPECIFIC) {
2221 CERROR("%s: wrong lum magic %x: rc = %d\n",
2222 filename, lum->lum_magic, rc);
2223 GOTO(migrate_free, rc);
2226 rc = ll_migrate(inode, file, lum, filename, flags);
2228 OBD_FREE_LARGE(data, len);
2232 case FS_IOC_FSGETXATTR:
2233 RETURN(ll_ioctl_fsgetxattr(inode, cmd, arg));
2234 case FS_IOC_FSSETXATTR:
2235 RETURN(ll_ioctl_fssetxattr(inode, cmd, arg));
2236 case LL_IOC_PROJECT:
2237 RETURN(ll_ioctl_project(file, cmd, arg));
2238 case LL_IOC_PCC_DETACH_BY_FID: {
2239 struct lu_pcc_detach_fid *detach;
2241 struct inode *inode2;
2244 OBD_ALLOC_PTR(detach);
2248 if (copy_from_user(detach,
2249 (const struct lu_pcc_detach_fid __user *)arg,
2251 GOTO(out_detach, rc = -EFAULT);
2253 fid = &detach->pccd_fid;
2254 ino = cl_fid_build_ino(fid, ll_need_32bit_api(sbi));
2255 inode2 = ilookup5(inode->i_sb, ino, ll_test_inode_by_fid, fid);
2257 /* Target inode is not in inode cache, and PCC file
2258 * has aleady released, return immdiately.
2260 GOTO(out_detach, rc = 0);
2262 if (!S_ISREG(inode2->i_mode))
2263 GOTO(out_iput, rc = -EINVAL);
2265 if (!inode_owner_or_capable(&init_user_ns, inode2))
2266 GOTO(out_iput, rc = -EPERM);
2268 rc = pcc_ioctl_detach(inode2, detach->pccd_opt);
2272 OBD_FREE_PTR(detach);
2275 #ifdef HAVE_LUSTRE_CRYPTO
2276 case LL_IOC_SET_ENCRYPTION_POLICY:
2277 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2279 return llcrypt_ioctl_set_policy(file, (const void __user *)arg);
2280 case LL_IOC_GET_ENCRYPTION_POLICY_EX:
2281 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2283 return llcrypt_ioctl_get_policy_ex(file, (void __user *)arg);
2284 case LL_IOC_ADD_ENCRYPTION_KEY:
2285 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2287 return llcrypt_ioctl_add_key(file, (void __user *)arg);
2288 case LL_IOC_REMOVE_ENCRYPTION_KEY:
2289 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2291 return llcrypt_ioctl_remove_key(file, (void __user *)arg);
2292 case LL_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS:
2293 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2295 return llcrypt_ioctl_remove_key_all_users(file,
2296 (void __user *)arg);
2297 case LL_IOC_GET_ENCRYPTION_KEY_STATUS:
2298 if (!ll_sbi_has_encrypt(ll_i2sbi(inode)))
2300 return llcrypt_ioctl_get_key_status(file, (void __user *)arg);
2303 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL,
2304 (void __user *)arg));
2308 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
2310 struct inode *inode = file->f_mapping->host;
2311 struct ll_file_data *fd = file->private_data;
2312 struct ll_sb_info *sbi = ll_i2sbi(inode);
2313 int api32 = ll_need_32bit_api(sbi);
2314 loff_t ret = -EINVAL;
2322 offset += file->f_pos;
2328 offset += LL_DIR_END_OFF_32BIT;
2330 offset += LL_DIR_END_OFF;
2337 ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
2338 (!api32 && offset <= LL_DIR_END_OFF))) {
2339 if (offset != file->f_pos) {
2342 hash64 = test_bit(LL_SBI_64BIT_HASH, sbi->ll_flags);
2343 if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
2344 (!api32 && offset == LL_DIR_END_OFF))
2345 fd->lfd_pos = MDS_DIR_END_OFF;
2346 else if (api32 && hash64)
2347 fd->lfd_pos = offset << 32;
2349 fd->lfd_pos = offset;
2350 file->f_pos = offset;
2351 file->f_version = 0;
2358 inode_unlock(inode);
2362 static int ll_dir_open(struct inode *inode, struct file *file)
2365 RETURN(ll_file_open(inode, file));
2368 static int ll_dir_release(struct inode *inode, struct file *file)
2371 RETURN(ll_file_release(inode, file));
2374 /* notify error if partially read striped directory */
2375 static int ll_dir_flush(struct file *file, fl_owner_t id)
2377 struct ll_file_data *lfd = file->private_data;
2378 int rc = lfd->fd_partial_readdir_rc;
2380 lfd->fd_partial_readdir_rc = 0;
2385 const struct file_operations ll_dir_operations = {
2386 .llseek = ll_dir_seek,
2387 .open = ll_dir_open,
2388 .release = ll_dir_release,
2389 .read = generic_read_dir,
2390 #ifdef HAVE_DIR_CONTEXT
2391 .iterate_shared = ll_iterate,
2393 .readdir = ll_readdir,
2395 .unlocked_ioctl = ll_dir_ioctl,
2397 .flush = ll_dir_flush,