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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 * Directory code for lustre client.
42 #include <linux/pagemap.h>
44 #include <linux/version.h>
45 #include <asm/uaccess.h>
46 #include <linux/buffer_head.h> // for wait_on_buffer
47 #include <linux/pagevec.h>
49 #define DEBUG_SUBSYSTEM S_LLITE
51 #include <lustre/lustre_idl.h>
52 #include <obd_support.h>
53 #include <obd_class.h>
54 #include <lustre_ioctl.h>
55 #include <lustre_lib.h>
56 #include <lustre_dlm.h>
57 #include <lustre_fid.h>
58 #include "llite_internal.h"
61 * (new) readdir implementation overview.
63 * Original lustre readdir implementation cached exact copy of raw directory
64 * pages on the client. These pages were indexed in client page cache by
65 * logical offset in the directory file. This design, while very simple and
66 * intuitive had some inherent problems:
68 * . it implies that byte offset to the directory entry serves as a
69 * telldir(3)/seekdir(3) cookie, but that offset is not stable: in
70 * ext3/htree directory entries may move due to splits, and more
73 * . it is incompatible with the design of split directories for cmd3,
74 * that assumes that names are distributed across nodes based on their
75 * hash, and so readdir should be done in hash order.
77 * New readdir implementation does readdir in hash order, and uses hash of a
78 * file name as a telldir/seekdir cookie. This led to number of complications:
80 * . hash is not unique, so it cannot be used to index cached directory
81 * pages on the client (note, that it requires a whole pageful of hash
82 * collided entries to cause two pages to have identical hashes);
84 * . hash is not unique, so it cannot, strictly speaking, be used as an
85 * entry cookie. ext3/htree has the same problem and lustre implementation
86 * mimics their solution: seekdir(hash) positions directory at the first
87 * entry with the given hash.
93 * Client caches directory pages using hash of the first entry as an index. As
94 * noted above hash is not unique, so this solution doesn't work as is:
95 * special processing is needed for "page hash chains" (i.e., sequences of
96 * pages filled with entries all having the same hash value).
98 * First, such chains have to be detected. To this end, server returns to the
99 * client the hash of the first entry on the page next to one returned. When
100 * client detects that this hash is the same as hash of the first entry on the
101 * returned page, page hash collision has to be handled. Pages in the
102 * hash chain, except first one, are termed "overflow pages".
104 * Solution to index uniqueness problem is to not cache overflow
105 * pages. Instead, when page hash collision is detected, all overflow pages
106 * from emerging chain are immediately requested from the server and placed in
107 * a special data structure (struct ll_dir_chain). This data structure is used
108 * by ll_readdir() to process entries from overflow pages. When readdir
109 * invocation finishes, overflow pages are discarded. If page hash collision
110 * chain weren't completely processed, next call to readdir will again detect
111 * page hash collision, again read overflow pages in, process next portion of
112 * entries and again discard the pages. This is not as wasteful as it looks,
113 * because, given reasonable hash, page hash collisions are extremely rare.
115 * 1. directory positioning
117 * When seekdir(hash) is called, original
128 * identification of and access to overflow pages
132 * Page in MDS_READPAGE RPC is packed in LU_PAGE_SIZE, and each page contains
133 * a header lu_dirpage which describes the start/end hash, and whether this
134 * page is empty (contains no dir entry) or hash collide with next page.
135 * After client receives reply, several pages will be integrated into dir page
136 * in PAGE_CACHE_SIZE (if PAGE_CACHE_SIZE greater than LU_PAGE_SIZE), and the
137 * lu_dirpage for this integrated page will be adjusted. See
138 * mdc_adjust_dirpages().
141 struct page *ll_get_dir_page(struct inode *dir, struct md_op_data *op_data,
142 __u64 offset, struct ll_dir_chain *chain)
144 struct md_callback cb_op;
148 cb_op.md_blocking_ast = ll_md_blocking_ast;
149 rc = md_read_page(ll_i2mdexp(dir), op_data, &cb_op, offset, &page);
156 void ll_release_page(struct inode *inode, struct page *page,
161 /* Always remove the page for striped dir, because the page is
162 * built from temporarily in LMV layer */
163 if (inode != NULL && S_ISDIR(inode->i_mode) &&
164 ll_i2info(inode)->lli_lsm_md != NULL) {
171 if (likely(page->mapping != NULL))
172 truncate_complete_page(page->mapping, page);
175 page_cache_release(page);
179 * return IF_* type for given lu_dirent entry.
180 * IF_* flag shld be converted to particular OS file type in
181 * platform llite module.
183 static u16 ll_dirent_type_get(struct lu_dirent *ent)
186 struct luda_type *lt;
189 if (le32_to_cpu(ent->lde_attrs) & LUDA_TYPE) {
190 const unsigned align = sizeof(struct luda_type) - 1;
192 len = le16_to_cpu(ent->lde_namelen);
193 len = (len + align) & ~align;
194 lt = (void *)ent->lde_name + len;
195 type = IFTODT(le16_to_cpu(lt->lt_type));
201 #ifdef HAVE_DIR_CONTEXT
202 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
203 struct dir_context *ctx)
206 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
207 void *cookie, filldir_t filldir)
210 struct ll_sb_info *sbi = ll_i2sbi(inode);
212 bool is_api32 = ll_need_32bit_api(sbi);
213 bool is_hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
215 struct ll_dir_chain chain;
220 ll_dir_chain_init(&chain);
222 page = ll_get_dir_page(inode, op_data, pos, &chain);
224 while (rc == 0 && !done) {
225 struct lu_dirpage *dp;
226 struct lu_dirent *ent;
235 hash = MDS_DIR_END_OFF;
236 dp = page_address(page);
237 for (ent = lu_dirent_start(dp); ent != NULL && !done;
238 ent = lu_dirent_next(ent)) {
245 hash = le64_to_cpu(ent->lde_hash);
248 * Skip until we find target hash
253 namelen = le16_to_cpu(ent->lde_namelen);
260 if (is_api32 && is_hash64)
264 fid_le_to_cpu(&fid, &ent->lde_fid);
265 ino = cl_fid_build_ino(&fid, is_api32);
266 type = ll_dirent_type_get(ent);
267 /* For 'll_nfs_get_name_filldir()', it will try
268 * to access the 'ent' through its 'lde_name',
269 * so the parameter 'name' for 'filldir()' must
270 * be part of the 'ent'. */
271 #ifdef HAVE_DIR_CONTEXT
273 done = !dir_emit(ctx, ent->lde_name, namelen, ino,
276 done = filldir(cookie, ent->lde_name, namelen, lhash,
283 ll_release_page(inode, page, false);
287 next = le64_to_cpu(dp->ldp_hash_end);
289 if (pos == MDS_DIR_END_OFF) {
291 * End of directory reached.
294 ll_release_page(inode, page, false);
297 * Normal case: continue to the next
300 ll_release_page(inode, page,
301 le32_to_cpu(dp->ldp_flags) &
304 page = ll_get_dir_page(inode, op_data, pos,
308 #ifdef HAVE_DIR_CONTEXT
313 ll_dir_chain_fini(&chain);
317 #ifdef HAVE_DIR_CONTEXT
318 static int ll_iterate(struct file *filp, struct dir_context *ctx)
320 static int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
323 struct inode *inode = filp->f_dentry->d_inode;
324 struct ll_file_data *lfd = LUSTRE_FPRIVATE(filp);
325 struct ll_sb_info *sbi = ll_i2sbi(inode);
326 int hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
327 int api32 = ll_need_32bit_api(sbi);
328 struct md_op_data *op_data;
338 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) pos/size"
339 "%lu/%llu 32bit_api %d\n", PFID(ll_inode2fid(inode)),
340 inode, (unsigned long)pos, i_size_read(inode), api32);
342 if (pos == MDS_DIR_END_OFF)
348 op_data = ll_prep_md_op_data(NULL, inode, inode, NULL, 0, 0,
349 LUSTRE_OPC_ANY, inode);
351 GOTO(out, rc = PTR_ERR(op_data));
353 if (unlikely(op_data->op_mea1 != NULL)) {
354 /* This is only needed for striped dir to fill ..,
355 * see lmv_read_entry */
356 if (filp->f_dentry->d_parent != NULL &&
357 filp->f_dentry->d_parent->d_inode != NULL) {
358 __u64 ibits = MDS_INODELOCK_UPDATE;
359 struct inode *parent =
360 filp->f_dentry->d_parent->d_inode;
362 if (ll_have_md_lock(parent, &ibits, LCK_MINMODE))
363 op_data->op_fid3 = *ll_inode2fid(parent);
366 /* If it can not find in cache, do lookup .. on the master
368 if (fid_is_zero(&op_data->op_fid3)) {
369 rc = ll_dir_get_parent_fid(inode, &op_data->op_fid3);
371 ll_finish_md_op_data(op_data);
376 op_data->op_max_pages = sbi->ll_md_brw_pages;
377 #ifdef HAVE_DIR_CONTEXT
379 rc = ll_dir_read(inode, &pos, op_data, ctx);
382 rc = ll_dir_read(inode, &pos, op_data, cookie, filldir);
387 if (pos == MDS_DIR_END_OFF) {
389 pos = LL_DIR_END_OFF_32BIT;
391 pos = LL_DIR_END_OFF;
396 #ifdef HAVE_DIR_CONTEXT
401 ll_finish_md_op_data(op_data);
402 filp->f_version = inode->i_version;
406 ll_stats_ops_tally(sbi, LPROC_LL_READDIR, 1);
411 static int ll_send_mgc_param(struct obd_export *mgc, char *string)
413 struct mgs_send_param *msp;
420 strlcpy(msp->mgs_param, string, sizeof(msp->mgs_param));
421 rc = obd_set_info_async(NULL, mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
422 sizeof(struct mgs_send_param), msp, NULL);
424 CERROR("Failed to set parameter: %d\n", rc);
431 * Create striped directory with specified stripe(@lump)
433 * param[in]parent the parent of the directory.
434 * param[in]lump the specified stripes.
435 * param[in]dirname the name of the directory.
436 * param[in]mode the specified mode of the directory.
438 * retval =0 if striped directory is being created successfully.
439 * <0 if the creation is failed.
441 static int ll_dir_setdirstripe(struct inode *parent, struct lmv_user_md *lump,
442 const char *dirname, umode_t mode)
444 struct ptlrpc_request *request = NULL;
445 struct md_op_data *op_data;
446 struct ll_sb_info *sbi = ll_i2sbi(parent);
450 if (unlikely(lump->lum_magic != LMV_USER_MAGIC))
453 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) name %s"
454 "stripe_offset %d, stripe_count: %u\n",
455 PFID(ll_inode2fid(parent)), parent, dirname,
456 (int)lump->lum_stripe_offset, lump->lum_stripe_count);
458 if (lump->lum_magic != cpu_to_le32(LMV_USER_MAGIC))
459 lustre_swab_lmv_user_md(lump);
461 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
462 mode &= ~current_umask();
463 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
464 op_data = ll_prep_md_op_data(NULL, parent, NULL, dirname,
465 strlen(dirname), mode, LUSTRE_OPC_MKDIR,
468 GOTO(err_exit, err = PTR_ERR(op_data));
470 op_data->op_cli_flags |= CLI_SET_MEA;
471 err = md_create(sbi->ll_md_exp, op_data, lump, sizeof(*lump), mode,
472 from_kuid(&init_user_ns, current_fsuid()),
473 from_kgid(&init_user_ns, current_fsgid()),
474 cfs_curproc_cap_pack(), 0, &request);
475 ll_finish_md_op_data(op_data);
479 ptlrpc_req_finished(request);
483 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
486 struct ll_sb_info *sbi = ll_i2sbi(inode);
487 struct md_op_data *op_data;
488 struct ptlrpc_request *req = NULL;
490 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
491 struct obd_device *mgc = lsi->lsi_mgc;
497 * This is coming from userspace, so should be in
498 * local endian. But the MDS would like it in little
499 * endian, so we swab it before we send it.
501 switch (lump->lmm_magic) {
502 case LOV_USER_MAGIC_V1: {
503 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V1))
504 lustre_swab_lov_user_md_v1(lump);
505 lum_size = sizeof(struct lov_user_md_v1);
508 case LOV_USER_MAGIC_V3: {
509 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V3))
510 lustre_swab_lov_user_md_v3(
511 (struct lov_user_md_v3 *)lump);
512 lum_size = sizeof(struct lov_user_md_v3);
515 case LMV_USER_MAGIC: {
516 if (lump->lmm_magic != cpu_to_le32(LMV_USER_MAGIC))
517 lustre_swab_lmv_user_md(
518 (struct lmv_user_md *)lump);
519 lum_size = sizeof(struct lmv_user_md);
523 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
524 " %#08x != %#08x nor %#08x\n",
525 lump->lmm_magic, LOV_USER_MAGIC_V1,
531 lum_size = sizeof(struct lov_user_md_v1);
534 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
535 LUSTRE_OPC_ANY, NULL);
537 RETURN(PTR_ERR(op_data));
539 /* swabbing is done in lov_setstripe() on server side */
540 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size, &req);
541 ll_finish_md_op_data(op_data);
542 ptlrpc_req_finished(req);
544 if (rc != -EPERM && rc != -EACCES)
545 CERROR("mdc_setattr fails: rc = %d\n", rc);
548 /* In the following we use the fact that LOV_USER_MAGIC_V1 and
549 LOV_USER_MAGIC_V3 have the same initial fields so we do not
550 need the make the distiction between the 2 versions */
551 if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
555 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
557 GOTO(end, rc = -ENOMEM);
560 /* Get fsname and assume devname to be -MDT0000. */
561 ll_get_fsname(inode->i_sb, buf, MTI_NAME_MAXLEN);
562 strcat(buf, "-MDT0000.lov");
565 /* Set root stripesize */
566 sprintf(buf, ".stripesize=%u",
567 lump ? le32_to_cpu(lump->lmm_stripe_size) : 0);
568 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
572 /* Set root stripecount */
573 sprintf(buf, ".stripecount=%hd",
574 lump ? le16_to_cpu(lump->lmm_stripe_count) : 0);
575 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
579 /* Set root stripeoffset */
580 sprintf(buf, ".stripeoffset=%hd",
581 lump ? le16_to_cpu(lump->lmm_stripe_offset) :
582 (typeof(lump->lmm_stripe_offset))(-1));
583 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
587 OBD_FREE(param, MGS_PARAM_MAXLEN);
593 * This function will be used to get default LOV/LMV/Default LMV
594 * @valid will be used to indicate which stripe it will retrieve
595 * OBD_MD_MEA LMV stripe EA
596 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
597 * otherwise Default LOV EA.
598 * Each time, it can only retrieve 1 stripe EA
600 int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
601 struct ptlrpc_request **request, u64 valid)
603 struct ll_sb_info *sbi = ll_i2sbi(inode);
604 struct mdt_body *body;
605 struct lov_mds_md *lmm = NULL;
606 struct ptlrpc_request *req = NULL;
608 struct md_op_data *op_data;
611 rc = ll_get_default_mdsize(sbi, &lmm_size);
615 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
616 0, lmm_size, LUSTRE_OPC_ANY,
619 RETURN(PTR_ERR(op_data));
621 op_data->op_valid = valid | OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
622 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
623 ll_finish_md_op_data(op_data);
625 CDEBUG(D_INFO, "md_getattr failed on inode "
626 DFID": rc %d\n", PFID(ll_inode2fid(inode)), rc);
630 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
631 LASSERT(body != NULL);
633 lmm_size = body->mbo_eadatasize;
635 if (!(body->mbo_valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
637 GOTO(out, rc = -ENODATA);
640 lmm = req_capsule_server_sized_get(&req->rq_pill,
641 &RMF_MDT_MD, lmm_size);
642 LASSERT(lmm != NULL);
645 * This is coming from the MDS, so is probably in
646 * little endian. We convert it to host endian before
647 * passing it to userspace.
649 /* We don't swab objects for directories */
650 switch (le32_to_cpu(lmm->lmm_magic)) {
652 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
653 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
656 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
657 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
660 if (LMV_MAGIC != cpu_to_le32(LMV_MAGIC))
661 lustre_swab_lmv_mds_md((union lmv_mds_md *)lmm);
664 if (LMV_USER_MAGIC != cpu_to_le32(LMV_USER_MAGIC))
665 lustre_swab_lmv_user_md((struct lmv_user_md *)lmm);
668 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
673 *plmm_size = lmm_size;
678 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid)
680 struct md_op_data *op_data;
685 OBD_ALLOC_PTR(op_data);
689 op_data->op_flags |= MF_GET_MDT_IDX;
690 op_data->op_fid1 = *fid;
691 rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
692 mdt_index = op_data->op_mds;
693 OBD_FREE_PTR(op_data);
701 * Get MDT index for the inode.
703 int ll_get_mdt_idx(struct inode *inode)
705 return ll_get_mdt_idx_by_fid(ll_i2sbi(inode), ll_inode2fid(inode));
709 * Generic handler to do any pre-copy work.
711 * It sends a first hsm_progress (with extent length == 0) to coordinator as a
712 * first information for it that real work has started.
714 * Moreover, for a ARCHIVE request, it will sample the file data version and
715 * store it in \a copy.
717 * \return 0 on success.
719 static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
721 struct ll_sb_info *sbi = ll_s2sbi(sb);
722 struct hsm_progress_kernel hpk;
726 /* Forge a hsm_progress based on data from copy. */
727 hpk.hpk_fid = copy->hc_hai.hai_fid;
728 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
729 hpk.hpk_extent.offset = copy->hc_hai.hai_extent.offset;
730 hpk.hpk_extent.length = 0;
733 hpk.hpk_data_version = 0;
736 /* For archive request, we need to read the current file version. */
737 if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
739 __u64 data_version = 0;
741 /* Get inode for this fid */
742 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
744 hpk.hpk_flags |= HP_FLAG_RETRY;
745 /* hpk_errval is >= 0 */
746 hpk.hpk_errval = -PTR_ERR(inode);
747 GOTO(progress, rc = PTR_ERR(inode));
750 /* Read current file data version */
751 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
754 CDEBUG(D_HSM, "Could not read file data version of "
755 DFID" (rc = %d). Archive request ("
756 LPX64") could not be done.\n",
757 PFID(©->hc_hai.hai_fid), rc,
758 copy->hc_hai.hai_cookie);
759 hpk.hpk_flags |= HP_FLAG_RETRY;
760 /* hpk_errval must be >= 0 */
761 hpk.hpk_errval = -rc;
765 /* Store in the hsm_copy for later copytool use.
766 * Always modified even if no lsm. */
767 copy->hc_data_version = data_version;
771 /* On error, the request should be considered as completed */
772 if (hpk.hpk_errval > 0)
773 hpk.hpk_flags |= HP_FLAG_COMPLETED;
774 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
781 * Generic handler to do any post-copy work.
783 * It will send the last hsm_progress update to coordinator to inform it
784 * that copy is finished and whether it was successful or not.
787 * - for ARCHIVE request, it will sample the file data version and compare it
788 * with the version saved in ll_ioc_copy_start(). If they do not match, copy
789 * will be considered as failed.
790 * - for RESTORE request, it will sample the file data version and send it to
791 * coordinator which is useful if the file was imported as 'released'.
793 * \return 0 on success.
795 static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
797 struct ll_sb_info *sbi = ll_s2sbi(sb);
798 struct hsm_progress_kernel hpk;
802 /* If you modify the logic here, also check llapi_hsm_copy_end(). */
803 /* Take care: copy->hc_hai.hai_action, len, gid and data are not
804 * initialized if copy_end was called with copy == NULL.
807 /* Forge a hsm_progress based on data from copy. */
808 hpk.hpk_fid = copy->hc_hai.hai_fid;
809 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
810 hpk.hpk_extent = copy->hc_hai.hai_extent;
811 hpk.hpk_flags = copy->hc_flags | HP_FLAG_COMPLETED;
812 hpk.hpk_errval = copy->hc_errval;
813 hpk.hpk_data_version = 0;
815 /* For archive request, we need to check the file data was not changed.
817 * For restore request, we need to send the file data version, this is
818 * useful when the file was created using hsm_import.
820 if (((copy->hc_hai.hai_action == HSMA_ARCHIVE) ||
821 (copy->hc_hai.hai_action == HSMA_RESTORE)) &&
822 (copy->hc_errval == 0)) {
824 __u64 data_version = 0;
826 /* Get lsm for this fid */
827 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
829 hpk.hpk_flags |= HP_FLAG_RETRY;
830 /* hpk_errval must be >= 0 */
831 hpk.hpk_errval = -PTR_ERR(inode);
832 GOTO(progress, rc = PTR_ERR(inode));
835 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
838 CDEBUG(D_HSM, "Could not read file data version. "
839 "Request could not be confirmed.\n");
840 if (hpk.hpk_errval == 0)
841 hpk.hpk_errval = -rc;
845 /* Store in the hsm_copy for later copytool use.
846 * Always modified even if no lsm. */
847 hpk.hpk_data_version = data_version;
849 /* File could have been stripped during archiving, so we need
850 * to check anyway. */
851 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
852 (copy->hc_data_version != data_version)) {
853 CDEBUG(D_HSM, "File data version mismatched. "
854 "File content was changed during archiving. "
855 DFID", start:"LPX64" current:"LPX64"\n",
856 PFID(©->hc_hai.hai_fid),
857 copy->hc_data_version, data_version);
858 /* File was changed, send error to cdt. Do not ask for
859 * retry because if a file is modified frequently,
860 * the cdt will loop on retried archive requests.
861 * The policy engine will ask for a new archive later
862 * when the file will not be modified for some tunable
864 /* we do not notify caller */
865 hpk.hpk_flags &= ~HP_FLAG_RETRY;
866 /* hpk_errval must be >= 0 */
867 hpk.hpk_errval = EBUSY;
873 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
880 static int copy_and_ioctl(int cmd, struct obd_export *exp,
881 const void __user *data, size_t size)
886 OBD_ALLOC(copy, size);
890 if (copy_from_user(copy, data, size)) {
895 rc = obd_iocontrol(cmd, exp, size, copy, NULL);
897 OBD_FREE(copy, size);
902 static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
904 int cmd = qctl->qc_cmd;
905 int type = qctl->qc_type;
906 int id = qctl->qc_id;
907 int valid = qctl->qc_valid;
912 case LUSTRE_Q_INVALIDATE:
913 case LUSTRE_Q_FINVALIDATE:
918 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
919 sbi->ll_flags & LL_SBI_RMT_CLIENT)
923 if (((type == USRQUOTA &&
924 !uid_eq(current_euid(), make_kuid(&init_user_ns, id))) ||
926 !in_egroup_p(make_kgid(&init_user_ns, id)))) &&
927 (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
928 sbi->ll_flags & LL_SBI_RMT_CLIENT))
934 CERROR("unsupported quotactl op: %#x\n", cmd);
938 if (valid != QC_GENERAL) {
939 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
942 if (cmd == Q_GETINFO)
943 qctl->qc_cmd = Q_GETOINFO;
944 else if (cmd == Q_GETQUOTA)
945 qctl->qc_cmd = Q_GETOQUOTA;
951 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
952 sizeof(*qctl), qctl, NULL);
955 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
956 sizeof(*qctl), qctl, NULL);
959 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
960 sizeof(*qctl), qctl, NULL);
962 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
964 sizeof(*qctl), qctl, NULL);
976 struct obd_quotactl *oqctl;
978 OBD_ALLOC_PTR(oqctl);
982 QCTL_COPY(oqctl, qctl);
983 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
985 if (rc != -EALREADY && cmd == Q_QUOTAON) {
986 oqctl->qc_cmd = Q_QUOTAOFF;
987 obd_quotactl(sbi->ll_md_exp, oqctl);
992 /* If QIF_SPACE is not set, client should collect the
993 * space usage from OSSs by itself */
994 if (cmd == Q_GETQUOTA &&
995 !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
996 !oqctl->qc_dqblk.dqb_curspace) {
997 struct obd_quotactl *oqctl_tmp;
999 OBD_ALLOC_PTR(oqctl_tmp);
1000 if (oqctl_tmp == NULL)
1001 GOTO(out, rc = -ENOMEM);
1003 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1004 oqctl_tmp->qc_id = oqctl->qc_id;
1005 oqctl_tmp->qc_type = oqctl->qc_type;
1007 /* collect space usage from OSTs */
1008 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1009 rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
1010 if (!rc || rc == -EREMOTEIO) {
1011 oqctl->qc_dqblk.dqb_curspace =
1012 oqctl_tmp->qc_dqblk.dqb_curspace;
1013 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
1016 /* collect space & inode usage from MDTs */
1017 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1018 oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
1019 rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
1020 if (!rc || rc == -EREMOTEIO) {
1021 oqctl->qc_dqblk.dqb_curspace +=
1022 oqctl_tmp->qc_dqblk.dqb_curspace;
1023 oqctl->qc_dqblk.dqb_curinodes =
1024 oqctl_tmp->qc_dqblk.dqb_curinodes;
1025 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
1027 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
1030 OBD_FREE_PTR(oqctl_tmp);
1033 QCTL_COPY(qctl, oqctl);
1034 OBD_FREE_PTR(oqctl);
1041 ll_getname(const char __user *filename)
1044 char *tmp = __getname();
1047 return ERR_PTR(-ENOMEM);
1049 len = strncpy_from_user(tmp, filename, PATH_MAX);
1052 else if (len > PATH_MAX)
1053 ret = -ENAMETOOLONG;
1062 #define ll_putname(filename) __putname(filename)
1064 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1066 struct inode *inode = file->f_dentry->d_inode;
1067 struct ll_sb_info *sbi = ll_i2sbi(inode);
1068 struct obd_ioctl_data *data;
1072 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%#x\n",
1073 PFID(ll_inode2fid(inode)), inode, cmd);
1075 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
1076 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
1079 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
1081 case FSFILT_IOC_GETFLAGS:
1082 case FSFILT_IOC_SETFLAGS:
1083 RETURN(ll_iocontrol(inode, file, cmd, arg));
1084 case FSFILT_IOC_GETVERSION_OLD:
1085 case FSFILT_IOC_GETVERSION:
1086 RETURN(put_user(inode->i_generation, (int __user *)arg));
1087 /* We need to special case any other ioctls we want to handle,
1088 * to send them to the MDS/OST as appropriate and to properly
1089 * network encode the arg field.
1090 case FSFILT_IOC_SETVERSION_OLD:
1091 case FSFILT_IOC_SETVERSION:
1093 case LL_IOC_GET_MDTIDX: {
1096 mdtidx = ll_get_mdt_idx(inode);
1100 if (put_user((int)mdtidx, (int __user *)arg))
1105 case IOC_MDC_LOOKUP: {
1106 int namelen, len = 0;
1110 rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
1115 filename = data->ioc_inlbuf1;
1116 namelen = strlen(filename);
1118 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1119 GOTO(out_free, rc = -EINVAL);
1122 rc = ll_get_fid_by_name(inode, filename, namelen, NULL);
1124 CERROR("%s: lookup %.*s failed: rc = %d\n",
1125 ll_get_fsname(inode->i_sb, NULL, 0), namelen,
1130 obd_ioctl_freedata(buf, len);
1133 case LL_IOC_LMV_SETSTRIPE: {
1134 struct lmv_user_md *lum;
1143 rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
1148 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1149 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1150 GOTO(lmv_out_free, rc = -EINVAL);
1152 filename = data->ioc_inlbuf1;
1153 namelen = data->ioc_inllen1;
1156 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1157 GOTO(lmv_out_free, rc = -EINVAL);
1159 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1160 lumlen = data->ioc_inllen2;
1162 if (lum->lum_magic != LMV_USER_MAGIC ||
1163 lumlen != sizeof(*lum)) {
1164 CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1165 filename, lum->lum_magic, lumlen, -EFAULT);
1166 GOTO(lmv_out_free, rc = -EINVAL);
1169 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 50, 0)
1170 mode = data->ioc_type != 0 ? data->ioc_type : S_IRWXUGO;
1172 mode = data->ioc_type;
1174 rc = ll_dir_setdirstripe(inode, lum, filename, mode);
1176 obd_ioctl_freedata(buf, len);
1180 case LL_IOC_LMV_SET_DEFAULT_STRIPE: {
1181 struct lmv_user_md lum;
1182 struct lmv_user_md __user *ulump =
1183 (struct lmv_user_md __user *)arg;
1186 if (copy_from_user(&lum, ulump, sizeof(lum)))
1189 if (lum.lum_magic != LMV_USER_MAGIC)
1192 rc = ll_dir_setstripe(inode, (struct lov_user_md *)&lum, 0);
1196 case LL_IOC_LOV_SETSTRIPE: {
1197 struct lov_user_md_v3 lumv3;
1198 struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
1199 struct lov_user_md_v1 __user *lumv1p =
1200 (struct lov_user_md_v1 __user *)arg;
1201 struct lov_user_md_v3 __user *lumv3p =
1202 (struct lov_user_md_v3 __user *)arg;
1204 int set_default = 0;
1206 LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
1207 LASSERT(sizeof(lumv3.lmm_objects[0]) ==
1208 sizeof(lumv3p->lmm_objects[0]));
1209 /* first try with v1 which is smaller than v3 */
1210 if (copy_from_user(lumv1, lumv1p, sizeof(*lumv1)))
1213 if ((lumv1->lmm_magic == LOV_USER_MAGIC_V3) ) {
1214 if (copy_from_user(&lumv3, lumv3p, sizeof(lumv3)))
1218 if (inode->i_sb->s_root == file->f_dentry)
1221 /* in v1 and v3 cases lumv1 points to data */
1222 rc = ll_dir_setstripe(inode, lumv1, set_default);
1226 case LL_IOC_LMV_GETSTRIPE: {
1227 struct lmv_user_md __user *ulmv =
1228 (struct lmv_user_md __user *)arg;
1229 struct lmv_user_md lum;
1230 struct ptlrpc_request *request = NULL;
1231 union lmv_mds_md *lmm = NULL;
1234 struct lmv_user_md *tmp = NULL;
1241 if (copy_from_user(&lum, ulmv, sizeof(*ulmv)))
1244 /* lum_magic will indicate which stripe the ioctl will like
1245 * to get, LMV_MAGIC_V1 is for normal LMV stripe, LMV_USER_MAGIC
1246 * is for default LMV stripe */
1247 if (lum.lum_magic == LMV_MAGIC_V1)
1248 valid |= OBD_MD_MEA;
1249 else if (lum.lum_magic == LMV_USER_MAGIC)
1250 valid |= OBD_MD_DEFAULT_MEA;
1254 rc = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize, &request,
1257 GOTO(finish_req, rc);
1259 /* Get default LMV EA */
1260 if (lum.lum_magic == LMV_USER_MAGIC) {
1262 GOTO(finish_req, rc);
1264 if (lmmsize > sizeof(*ulmv))
1265 GOTO(finish_req, rc = -EINVAL);
1267 if (copy_to_user(ulmv, lmm, lmmsize))
1268 GOTO(finish_req, rc = -EFAULT);
1270 GOTO(finish_req, rc);
1273 stripe_count = lmv_mds_md_stripe_count_get(lmm);
1274 lum_size = lmv_user_md_size(stripe_count, LMV_MAGIC_V1);
1275 OBD_ALLOC(tmp, lum_size);
1277 GOTO(finish_req, rc = -ENOMEM);
1279 mdt_index = ll_get_mdt_idx(inode);
1281 GOTO(out_tmp, rc = -ENOMEM);
1283 tmp->lum_magic = LMV_MAGIC_V1;
1284 tmp->lum_stripe_count = 0;
1285 tmp->lum_stripe_offset = mdt_index;
1286 for (i = 0; i < stripe_count; i++) {
1289 fid_le_to_cpu(&fid, &lmm->lmv_md_v1.lmv_stripe_fids[i]);
1290 mdt_index = ll_get_mdt_idx_by_fid(sbi, &fid);
1292 GOTO(out_tmp, rc = mdt_index);
1294 tmp->lum_objects[i].lum_mds = mdt_index;
1295 tmp->lum_objects[i].lum_fid = fid;
1296 tmp->lum_stripe_count++;
1299 if (copy_to_user(ulmv, tmp, lum_size))
1300 GOTO(out_tmp, rc = -EFAULT);
1302 OBD_FREE(tmp, lum_size);
1304 ptlrpc_req_finished(request);
1308 case LL_IOC_REMOVE_ENTRY: {
1309 char *filename = NULL;
1313 /* Here is a little hack to avoid sending REINT_RMENTRY to
1314 * unsupported server, which might crash the server(LU-2730),
1315 * Because both LVB_TYPE and REINT_RMENTRY will be supported
1316 * on 2.4, we use OBD_CONNECT_LVB_TYPE to detect whether the
1317 * server will support REINT_RMENTRY XXX*/
1318 if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE))
1321 filename = ll_getname((const char __user *)arg);
1322 if (IS_ERR(filename))
1323 RETURN(PTR_ERR(filename));
1325 namelen = strlen(filename);
1327 GOTO(out_rmdir, rc = -EINVAL);
1329 rc = ll_rmdir_entry(inode, filename, namelen);
1332 ll_putname(filename);
1335 case LL_IOC_LOV_SWAP_LAYOUTS:
1337 case IOC_OBD_STATFS:
1338 RETURN(ll_obd_statfs(inode, (void __user *)arg));
1339 case LL_IOC_LOV_GETSTRIPE:
1340 case LL_IOC_MDC_GETINFO:
1341 case IOC_MDC_GETFILEINFO:
1342 case IOC_MDC_GETFILESTRIPE: {
1343 struct ptlrpc_request *request = NULL;
1344 struct lov_user_md __user *lump;
1345 struct lov_mds_md *lmm = NULL;
1346 struct mdt_body *body;
1347 char *filename = NULL;
1350 if (cmd == IOC_MDC_GETFILEINFO ||
1351 cmd == IOC_MDC_GETFILESTRIPE) {
1352 filename = ll_getname((const char __user *)arg);
1353 if (IS_ERR(filename))
1354 RETURN(PTR_ERR(filename));
1356 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1357 &lmmsize, &request);
1359 rc = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize,
1364 body = req_capsule_server_get(&request->rq_pill,
1366 LASSERT(body != NULL);
1372 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
1373 cmd == LL_IOC_MDC_GETINFO))
1374 GOTO(skip_lmm, rc = 0);
1379 if (cmd == IOC_MDC_GETFILESTRIPE ||
1380 cmd == LL_IOC_LOV_GETSTRIPE) {
1381 lump = (struct lov_user_md __user *)arg;
1383 struct lov_user_mds_data __user *lmdp;
1384 lmdp = (struct lov_user_mds_data __user *)arg;
1385 lump = &lmdp->lmd_lmm;
1387 if (copy_to_user(lump, lmm, lmmsize)) {
1388 if (copy_to_user(lump, lmm, sizeof(*lump)))
1389 GOTO(out_req, rc = -EFAULT);
1393 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
1394 struct lov_user_mds_data __user *lmdp;
1397 st.st_dev = inode->i_sb->s_dev;
1398 st.st_mode = body->mbo_mode;
1399 st.st_nlink = body->mbo_nlink;
1400 st.st_uid = body->mbo_uid;
1401 st.st_gid = body->mbo_gid;
1402 st.st_rdev = body->mbo_rdev;
1403 st.st_size = body->mbo_size;
1404 st.st_blksize = PAGE_CACHE_SIZE;
1405 st.st_blocks = body->mbo_blocks;
1406 st.st_atime = body->mbo_atime;
1407 st.st_mtime = body->mbo_mtime;
1408 st.st_ctime = body->mbo_ctime;
1409 st.st_ino = inode->i_ino;
1411 lmdp = (struct lov_user_mds_data __user *)arg;
1412 if (copy_to_user(&lmdp->lmd_st, &st, sizeof(st)))
1413 GOTO(out_req, rc = -EFAULT);
1418 ptlrpc_req_finished(request);
1420 ll_putname(filename);
1423 case OBD_IOC_QUOTACHECK: {
1424 struct obd_quotactl *oqctl;
1427 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1428 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1431 OBD_ALLOC_PTR(oqctl);
1434 oqctl->qc_type = arg;
1435 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
1437 CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
1441 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
1443 CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
1445 OBD_FREE_PTR(oqctl);
1448 case OBD_IOC_POLL_QUOTACHECK: {
1449 struct if_quotacheck *check;
1451 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1452 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1455 OBD_ALLOC_PTR(check);
1459 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
1462 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
1463 if (copy_to_user((void __user *)arg, check,
1465 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1469 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
1472 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
1473 if (copy_to_user((void __user *)arg, check,
1475 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1479 OBD_FREE_PTR(check);
1482 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 53, 0)
1483 case LL_IOC_QUOTACTL_18: {
1484 /* copy the old 1.x quota struct for internal use, then copy
1485 * back into old format struct. For 1.8 compatibility. */
1486 struct if_quotactl_18 *qctl_18;
1487 struct if_quotactl *qctl_20;
1489 OBD_ALLOC_PTR(qctl_18);
1493 OBD_ALLOC_PTR(qctl_20);
1495 GOTO(out_quotactl_18, rc = -ENOMEM);
1497 if (copy_from_user(qctl_18, (void __user *)arg,
1499 GOTO(out_quotactl_20, rc = -ENOMEM);
1501 QCTL_COPY(qctl_20, qctl_18);
1502 qctl_20->qc_idx = 0;
1504 /* XXX: dqb_valid was borrowed as a flag to mark that
1505 * only mds quota is wanted */
1506 if (qctl_18->qc_cmd == Q_GETQUOTA &&
1507 qctl_18->qc_dqblk.dqb_valid) {
1508 qctl_20->qc_valid = QC_MDTIDX;
1509 qctl_20->qc_dqblk.dqb_valid = 0;
1510 } else if (qctl_18->obd_uuid.uuid[0] != '\0') {
1511 qctl_20->qc_valid = QC_UUID;
1512 qctl_20->obd_uuid = qctl_18->obd_uuid;
1514 qctl_20->qc_valid = QC_GENERAL;
1517 rc = quotactl_ioctl(sbi, qctl_20);
1520 QCTL_COPY(qctl_18, qctl_20);
1521 qctl_18->obd_uuid = qctl_20->obd_uuid;
1523 if (copy_to_user((void __user *)arg, qctl_18,
1529 OBD_FREE_PTR(qctl_20);
1531 OBD_FREE_PTR(qctl_18);
1534 #endif /* LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 53, 0) */
1535 case OBD_IOC_QUOTACTL: {
1536 struct if_quotactl *qctl;
1538 OBD_ALLOC_PTR(qctl);
1542 if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl)))
1543 GOTO(out_quotactl, rc = -EFAULT);
1545 rc = quotactl_ioctl(sbi, qctl);
1548 copy_to_user((void __user *)arg, qctl, sizeof(*qctl)))
1555 case OBD_IOC_GETDTNAME:
1556 case OBD_IOC_GETMDNAME:
1557 RETURN(ll_get_obd_name(inode, cmd, arg));
1558 case LL_IOC_FLUSHCTX:
1559 RETURN(ll_flush_ctx(inode));
1560 #ifdef CONFIG_FS_POSIX_ACL
1561 case LL_IOC_RMTACL: {
1562 if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
1563 inode == inode->i_sb->s_root->d_inode) {
1564 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1566 LASSERT(fd != NULL);
1567 rc = rct_add(&sbi->ll_rct, current_pid(), arg);
1569 fd->fd_flags |= LL_FILE_RMTACL;
1575 case LL_IOC_GETOBDCOUNT: {
1577 struct obd_export *exp;
1579 if (copy_from_user(&count, (int __user *)arg, sizeof(int)))
1582 /* get ost count when count is zero, get mdt count otherwise */
1583 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
1584 vallen = sizeof(count);
1585 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
1586 KEY_TGT_COUNT, &vallen, &count, NULL);
1588 CERROR("get target count failed: %d\n", rc);
1592 if (copy_to_user((int __user *)arg, &count, sizeof(int)))
1597 case LL_IOC_PATH2FID:
1598 if (copy_to_user((void __user *)arg, ll_inode2fid(inode),
1599 sizeof(struct lu_fid)))
1602 case LL_IOC_GET_CONNECT_FLAGS: {
1603 RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL,
1604 (void __user *)arg));
1606 case OBD_IOC_CHANGELOG_SEND:
1607 case OBD_IOC_CHANGELOG_CLEAR:
1608 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void __user *)arg,
1609 sizeof(struct ioc_changelog));
1611 case OBD_IOC_FID2PATH:
1612 RETURN(ll_fid2path(inode, (void __user *)arg));
1613 case LL_IOC_GETPARENT:
1614 RETURN(ll_getparent(file, (void __user *)arg));
1615 case LL_IOC_FID2MDTIDX: {
1616 struct obd_export *exp = ll_i2mdexp(inode);
1620 if (copy_from_user(&fid, (const struct lu_fid __user *)arg,
1624 /* Call mdc_iocontrol */
1625 rc = obd_iocontrol(LL_IOC_FID2MDTIDX, exp, sizeof(fid), &fid,
1626 (__u32 __user *)&index);
1632 case LL_IOC_HSM_REQUEST: {
1633 struct hsm_user_request *hur;
1640 /* We don't know the true size yet; copy the fixed-size part */
1641 if (copy_from_user(hur, (void __user *)arg, sizeof(*hur))) {
1646 /* Compute the whole struct size */
1647 totalsize = hur_len(hur);
1652 /* Final size will be more than double totalsize */
1653 if (totalsize >= MDS_MAXREQSIZE / 3)
1656 OBD_ALLOC_LARGE(hur, totalsize);
1660 /* Copy the whole struct */
1661 if (copy_from_user(hur, (void __user *)arg, totalsize)) {
1662 OBD_FREE_LARGE(hur, totalsize);
1666 if (hur->hur_request.hr_action == HUA_RELEASE) {
1667 const struct lu_fid *fid;
1671 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
1672 fid = &hur->hur_user_item[i].hui_fid;
1673 f = search_inode_for_lustre(inode->i_sb, fid);
1679 rc = ll_hsm_release(f);
1685 rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
1689 OBD_FREE_LARGE(hur, totalsize);
1693 case LL_IOC_HSM_PROGRESS: {
1694 struct hsm_progress_kernel hpk;
1695 struct hsm_progress hp;
1697 if (copy_from_user(&hp, (void __user *)arg, sizeof(hp)))
1700 hpk.hpk_fid = hp.hp_fid;
1701 hpk.hpk_cookie = hp.hp_cookie;
1702 hpk.hpk_extent = hp.hp_extent;
1703 hpk.hpk_flags = hp.hp_flags;
1704 hpk.hpk_errval = hp.hp_errval;
1705 hpk.hpk_data_version = 0;
1707 /* File may not exist in Lustre; all progress
1708 * reported to Lustre root */
1709 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
1713 case LL_IOC_HSM_CT_START:
1714 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
1717 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void __user *)arg,
1718 sizeof(struct lustre_kernelcomm));
1721 case LL_IOC_HSM_COPY_START: {
1722 struct hsm_copy *copy;
1725 OBD_ALLOC_PTR(copy);
1728 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
1733 rc = ll_ioc_copy_start(inode->i_sb, copy);
1734 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
1740 case LL_IOC_HSM_COPY_END: {
1741 struct hsm_copy *copy;
1744 OBD_ALLOC_PTR(copy);
1747 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
1752 rc = ll_ioc_copy_end(inode->i_sb, copy);
1753 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
1759 case LL_IOC_MIGRATE: {
1761 const char *filename;
1767 rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
1771 data = (struct obd_ioctl_data *)buf;
1772 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1773 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1774 GOTO(migrate_free, rc = -EINVAL);
1776 filename = data->ioc_inlbuf1;
1777 namelen = data->ioc_inllen1;
1778 /* \0 is packed at the end of filename */
1779 if (namelen < 1 || namelen != strlen(filename) + 1)
1780 GOTO(migrate_free, rc = -EINVAL);
1782 if (data->ioc_inllen2 != sizeof(mdtidx))
1783 GOTO(migrate_free, rc = -EINVAL);
1784 mdtidx = *(int *)data->ioc_inlbuf2;
1786 rc = ll_migrate(inode, file, mdtidx, filename, namelen - 1);
1788 obd_ioctl_freedata(buf, len);
1793 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL,
1794 (void __user *)arg));
1798 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
1800 struct inode *inode = file->f_mapping->host;
1801 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1802 struct ll_sb_info *sbi = ll_i2sbi(inode);
1803 int api32 = ll_need_32bit_api(sbi);
1804 loff_t ret = -EINVAL;
1807 mutex_lock(&inode->i_mutex);
1812 offset += file->f_pos;
1818 offset += LL_DIR_END_OFF_32BIT;
1820 offset += LL_DIR_END_OFF;
1827 ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
1828 (!api32 && offset <= LL_DIR_END_OFF))) {
1829 if (offset != file->f_pos) {
1830 if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
1831 (!api32 && offset == LL_DIR_END_OFF))
1832 fd->lfd_pos = MDS_DIR_END_OFF;
1833 else if (api32 && sbi->ll_flags & LL_SBI_64BIT_HASH)
1834 fd->lfd_pos = offset << 32;
1836 fd->lfd_pos = offset;
1837 file->f_pos = offset;
1838 file->f_version = 0;
1845 mutex_unlock(&inode->i_mutex);
1849 static int ll_dir_open(struct inode *inode, struct file *file)
1852 RETURN(ll_file_open(inode, file));
1855 static int ll_dir_release(struct inode *inode, struct file *file)
1858 RETURN(ll_file_release(inode, file));
1861 const struct file_operations ll_dir_operations = {
1862 .llseek = ll_dir_seek,
1863 .open = ll_dir_open,
1864 .release = ll_dir_release,
1865 .read = generic_read_dir,
1866 #ifdef HAVE_DIR_CONTEXT
1867 .iterate = ll_iterate,
1869 .readdir = ll_readdir,
1871 .unlocked_ioctl = ll_dir_ioctl,