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, 2013, 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);
178 #ifdef HAVE_DIR_CONTEXT
179 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
180 struct dir_context *ctx)
183 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
184 void *cookie, filldir_t filldir)
187 struct ll_sb_info *sbi = ll_i2sbi(inode);
189 bool is_api32 = ll_need_32bit_api(sbi);
190 bool is_hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
192 struct ll_dir_chain chain;
197 ll_dir_chain_init(&chain);
199 page = ll_get_dir_page(inode, op_data, pos, &chain);
201 while (rc == 0 && !done) {
202 struct lu_dirpage *dp;
203 struct lu_dirent *ent;
212 hash = MDS_DIR_END_OFF;
213 dp = page_address(page);
214 for (ent = lu_dirent_start(dp); ent != NULL && !done;
215 ent = lu_dirent_next(ent)) {
222 hash = le64_to_cpu(ent->lde_hash);
225 * Skip until we find target hash
230 namelen = le16_to_cpu(ent->lde_namelen);
237 if (is_api32 && is_hash64)
241 fid_le_to_cpu(&fid, &ent->lde_fid);
242 ino = cl_fid_build_ino(&fid, is_api32);
243 type = ll_dirent_type_get(ent);
244 /* For 'll_nfs_get_name_filldir()', it will try
245 * to access the 'ent' through its 'lde_name',
246 * so the parameter 'name' for 'filldir()' must
247 * be part of the 'ent'. */
248 #ifdef HAVE_DIR_CONTEXT
250 done = !dir_emit(ctx, ent->lde_name, namelen, ino,
253 done = filldir(cookie, ent->lde_name, namelen, lhash,
260 ll_release_page(inode, page, false);
264 next = le64_to_cpu(dp->ldp_hash_end);
266 if (pos == MDS_DIR_END_OFF) {
268 * End of directory reached.
271 ll_release_page(inode, page, false);
274 * Normal case: continue to the next
277 ll_release_page(inode, page,
278 le32_to_cpu(dp->ldp_flags) &
281 page = ll_get_dir_page(inode, op_data, pos,
285 #ifdef HAVE_DIR_CONTEXT
290 ll_dir_chain_fini(&chain);
294 #ifdef HAVE_DIR_CONTEXT
295 static int ll_iterate(struct file *filp, struct dir_context *ctx)
297 static int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
300 struct inode *inode = filp->f_dentry->d_inode;
301 struct ll_file_data *lfd = LUSTRE_FPRIVATE(filp);
302 struct ll_sb_info *sbi = ll_i2sbi(inode);
303 int hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
304 int api32 = ll_need_32bit_api(sbi);
305 struct md_op_data *op_data;
315 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) pos/size"
316 "%lu/%llu 32bit_api %d\n", PFID(ll_inode2fid(inode)),
317 inode, (unsigned long)pos, i_size_read(inode), api32);
319 if (pos == MDS_DIR_END_OFF)
325 op_data = ll_prep_md_op_data(NULL, inode, inode, NULL, 0, 0,
326 LUSTRE_OPC_ANY, inode);
328 GOTO(out, rc = PTR_ERR(op_data));
330 if (unlikely(op_data->op_mea1 != NULL)) {
331 /* This is only needed for striped dir to fill ..,
332 * see lmv_read_entry */
333 if (filp->f_dentry->d_parent != NULL &&
334 filp->f_dentry->d_parent->d_inode != NULL) {
335 __u64 ibits = MDS_INODELOCK_UPDATE;
336 struct inode *parent =
337 filp->f_dentry->d_parent->d_inode;
339 if (ll_have_md_lock(parent, &ibits, LCK_MINMODE))
340 op_data->op_fid3 = *ll_inode2fid(parent);
343 /* If it can not find in cache, do lookup .. on the master
345 if (fid_is_zero(&op_data->op_fid3)) {
346 rc = ll_dir_get_parent_fid(inode, &op_data->op_fid3);
348 ll_finish_md_op_data(op_data);
353 op_data->op_max_pages = sbi->ll_md_brw_pages;
354 #ifdef HAVE_DIR_CONTEXT
356 rc = ll_dir_read(inode, &pos, op_data, ctx);
359 rc = ll_dir_read(inode, &pos, op_data, cookie, filldir);
364 if (pos == MDS_DIR_END_OFF) {
366 pos = LL_DIR_END_OFF_32BIT;
368 pos = LL_DIR_END_OFF;
373 #ifdef HAVE_DIR_CONTEXT
378 ll_finish_md_op_data(op_data);
379 filp->f_version = inode->i_version;
383 ll_stats_ops_tally(sbi, LPROC_LL_READDIR, 1);
388 static int ll_send_mgc_param(struct obd_export *mgc, char *string)
390 struct mgs_send_param *msp;
397 strlcpy(msp->mgs_param, string, sizeof(msp->mgs_param));
398 rc = obd_set_info_async(NULL, mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
399 sizeof(struct mgs_send_param), msp, NULL);
401 CERROR("Failed to set parameter: %d\n", rc);
408 * Create striped directory with specified stripe(@lump)
410 * param[in]parent the parent of the directory.
411 * param[in]lump the specified stripes.
412 * param[in]dirname the name of the directory.
413 * param[in]mode the specified mode of the directory.
415 * retval =0 if striped directory is being created successfully.
416 * <0 if the creation is failed.
418 static int ll_dir_setdirstripe(struct inode *parent, struct lmv_user_md *lump,
419 const char *dirname, umode_t mode)
421 struct ptlrpc_request *request = NULL;
422 struct md_op_data *op_data;
423 struct ll_sb_info *sbi = ll_i2sbi(parent);
427 if (unlikely(lump->lum_magic != LMV_USER_MAGIC))
430 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) name %s"
431 "stripe_offset %d, stripe_count: %u\n",
432 PFID(ll_inode2fid(parent)), parent, dirname,
433 (int)lump->lum_stripe_offset, lump->lum_stripe_count);
435 if (lump->lum_magic != cpu_to_le32(LMV_USER_MAGIC))
436 lustre_swab_lmv_user_md(lump);
438 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
439 mode &= ~current_umask();
440 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
441 op_data = ll_prep_md_op_data(NULL, parent, NULL, dirname,
442 strlen(dirname), mode, LUSTRE_OPC_MKDIR,
445 GOTO(err_exit, err = PTR_ERR(op_data));
447 op_data->op_cli_flags |= CLI_SET_MEA;
448 err = md_create(sbi->ll_md_exp, op_data, lump, sizeof(*lump), mode,
449 from_kuid(&init_user_ns, current_fsuid()),
450 from_kgid(&init_user_ns, current_fsgid()),
451 cfs_curproc_cap_pack(), 0, &request);
452 ll_finish_md_op_data(op_data);
456 ptlrpc_req_finished(request);
460 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
463 struct ll_sb_info *sbi = ll_i2sbi(inode);
464 struct md_op_data *op_data;
465 struct ptlrpc_request *req = NULL;
467 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
468 struct obd_device *mgc = lsi->lsi_mgc;
474 * This is coming from userspace, so should be in
475 * local endian. But the MDS would like it in little
476 * endian, so we swab it before we send it.
478 switch (lump->lmm_magic) {
479 case LOV_USER_MAGIC_V1: {
480 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V1))
481 lustre_swab_lov_user_md_v1(lump);
482 lum_size = sizeof(struct lov_user_md_v1);
485 case LOV_USER_MAGIC_V3: {
486 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V3))
487 lustre_swab_lov_user_md_v3(
488 (struct lov_user_md_v3 *)lump);
489 lum_size = sizeof(struct lov_user_md_v3);
492 case LMV_USER_MAGIC: {
493 if (lump->lmm_magic != cpu_to_le32(LMV_USER_MAGIC))
494 lustre_swab_lmv_user_md(
495 (struct lmv_user_md *)lump);
496 lum_size = sizeof(struct lmv_user_md);
500 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
501 " %#08x != %#08x nor %#08x\n",
502 lump->lmm_magic, LOV_USER_MAGIC_V1,
508 lum_size = sizeof(struct lov_user_md_v1);
511 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
512 LUSTRE_OPC_ANY, NULL);
514 RETURN(PTR_ERR(op_data));
516 /* swabbing is done in lov_setstripe() on server side */
517 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size,
518 NULL, 0, &req, NULL);
519 ll_finish_md_op_data(op_data);
520 ptlrpc_req_finished(req);
522 if (rc != -EPERM && rc != -EACCES)
523 CERROR("mdc_setattr fails: rc = %d\n", rc);
526 /* In the following we use the fact that LOV_USER_MAGIC_V1 and
527 LOV_USER_MAGIC_V3 have the same initial fields so we do not
528 need the make the distiction between the 2 versions */
529 if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
533 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
535 GOTO(end, rc = -ENOMEM);
538 /* Get fsname and assume devname to be -MDT0000. */
539 ll_get_fsname(inode->i_sb, buf, MTI_NAME_MAXLEN);
540 strcat(buf, "-MDT0000.lov");
543 /* Set root stripesize */
544 sprintf(buf, ".stripesize=%u",
545 lump ? le32_to_cpu(lump->lmm_stripe_size) : 0);
546 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
550 /* Set root stripecount */
551 sprintf(buf, ".stripecount=%hd",
552 lump ? le16_to_cpu(lump->lmm_stripe_count) : 0);
553 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
557 /* Set root stripeoffset */
558 sprintf(buf, ".stripeoffset=%hd",
559 lump ? le16_to_cpu(lump->lmm_stripe_offset) :
560 (typeof(lump->lmm_stripe_offset))(-1));
561 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
565 OBD_FREE(param, MGS_PARAM_MAXLEN);
571 * This function will be used to get default LOV/LMV/Default LMV
572 * @valid will be used to indicate which stripe it will retrieve
573 * OBD_MD_MEA LMV stripe EA
574 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
575 * otherwise Default LOV EA.
576 * Each time, it can only retrieve 1 stripe EA
578 int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
579 struct ptlrpc_request **request, obd_valid valid)
581 struct ll_sb_info *sbi = ll_i2sbi(inode);
582 struct mdt_body *body;
583 struct lov_mds_md *lmm = NULL;
584 struct ptlrpc_request *req = NULL;
586 struct md_op_data *op_data;
589 rc = ll_get_default_mdsize(sbi, &lmm_size);
593 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
594 0, lmm_size, LUSTRE_OPC_ANY,
597 RETURN(PTR_ERR(op_data));
599 op_data->op_valid = valid | OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
600 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
601 ll_finish_md_op_data(op_data);
603 CDEBUG(D_INFO, "md_getattr failed on inode "
604 DFID": rc %d\n", PFID(ll_inode2fid(inode)), rc);
608 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
609 LASSERT(body != NULL);
611 lmm_size = body->mbo_eadatasize;
613 if (!(body->mbo_valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
615 GOTO(out, rc = -ENODATA);
618 lmm = req_capsule_server_sized_get(&req->rq_pill,
619 &RMF_MDT_MD, lmm_size);
620 LASSERT(lmm != NULL);
623 * This is coming from the MDS, so is probably in
624 * little endian. We convert it to host endian before
625 * passing it to userspace.
627 /* We don't swab objects for directories */
628 switch (le32_to_cpu(lmm->lmm_magic)) {
630 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
631 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
634 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
635 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
638 if (LMV_MAGIC != cpu_to_le32(LMV_MAGIC))
639 lustre_swab_lmv_mds_md((union lmv_mds_md *)lmm);
642 if (LMV_USER_MAGIC != cpu_to_le32(LMV_USER_MAGIC))
643 lustre_swab_lmv_user_md((struct lmv_user_md *)lmm);
646 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
651 *plmm_size = lmm_size;
656 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid)
658 struct md_op_data *op_data;
663 OBD_ALLOC_PTR(op_data);
667 op_data->op_flags |= MF_GET_MDT_IDX;
668 op_data->op_fid1 = *fid;
669 rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
670 mdt_index = op_data->op_mds;
671 OBD_FREE_PTR(op_data);
679 * Get MDT index for the inode.
681 int ll_get_mdt_idx(struct inode *inode)
683 return ll_get_mdt_idx_by_fid(ll_i2sbi(inode), ll_inode2fid(inode));
687 * Generic handler to do any pre-copy work.
689 * It send a first hsm_progress (with extent length == 0) to coordinator as a
690 * first information for it that real work has started.
692 * Moreover, for a ARCHIVE request, it will sample the file data version and
693 * store it in \a copy.
695 * \return 0 on success.
697 static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
699 struct ll_sb_info *sbi = ll_s2sbi(sb);
700 struct hsm_progress_kernel hpk;
704 /* Forge a hsm_progress based on data from copy. */
705 hpk.hpk_fid = copy->hc_hai.hai_fid;
706 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
707 hpk.hpk_extent.offset = copy->hc_hai.hai_extent.offset;
708 hpk.hpk_extent.length = 0;
711 hpk.hpk_data_version = 0;
714 /* For archive request, we need to read the current file version. */
715 if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
717 __u64 data_version = 0;
719 /* Get inode for this fid */
720 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
722 hpk.hpk_flags |= HP_FLAG_RETRY;
723 /* hpk_errval is >= 0 */
724 hpk.hpk_errval = -PTR_ERR(inode);
725 GOTO(progress, rc = PTR_ERR(inode));
728 /* Read current file data version */
729 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
732 CDEBUG(D_HSM, "Could not read file data version of "
733 DFID" (rc = %d). Archive request ("
734 LPX64") could not be done.\n",
735 PFID(©->hc_hai.hai_fid), rc,
736 copy->hc_hai.hai_cookie);
737 hpk.hpk_flags |= HP_FLAG_RETRY;
738 /* hpk_errval must be >= 0 */
739 hpk.hpk_errval = -rc;
743 /* Store it the hsm_copy for later copytool use.
744 * Always modified even if no lsm. */
745 copy->hc_data_version = data_version;
749 /* On error, the request should be considered as completed */
750 if (hpk.hpk_errval > 0)
751 hpk.hpk_flags |= HP_FLAG_COMPLETED;
752 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
759 * Generic handler to do any post-copy work.
761 * It will send the last hsm_progress update to coordinator to inform it
762 * that copy is finished and whether it was successful or not.
765 * - for ARCHIVE request, it will sample the file data version and compare it
766 * with the version saved in ll_ioc_copy_start(). If they do not match, copy
767 * will be considered as failed.
768 * - for RESTORE request, it will sample the file data version and send it to
769 * coordinator which is useful if the file was imported as 'released'.
771 * \return 0 on success.
773 static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
775 struct ll_sb_info *sbi = ll_s2sbi(sb);
776 struct hsm_progress_kernel hpk;
780 /* If you modify the logic here, also check llapi_hsm_copy_end(). */
781 /* Take care: copy->hc_hai.hai_action, len, gid and data are not
782 * initialized if copy_end was called with copy == NULL.
785 /* Forge a hsm_progress based on data from copy. */
786 hpk.hpk_fid = copy->hc_hai.hai_fid;
787 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
788 hpk.hpk_extent = copy->hc_hai.hai_extent;
789 hpk.hpk_flags = copy->hc_flags | HP_FLAG_COMPLETED;
790 hpk.hpk_errval = copy->hc_errval;
791 hpk.hpk_data_version = 0;
793 /* For archive request, we need to check the file data was not changed.
795 * For restore request, we need to send the file data version, this is
796 * useful when the file was created using hsm_import.
798 if (((copy->hc_hai.hai_action == HSMA_ARCHIVE) ||
799 (copy->hc_hai.hai_action == HSMA_RESTORE)) &&
800 (copy->hc_errval == 0)) {
802 __u64 data_version = 0;
804 /* Get lsm for this fid */
805 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
807 hpk.hpk_flags |= HP_FLAG_RETRY;
808 /* hpk_errval must be >= 0 */
809 hpk.hpk_errval = -PTR_ERR(inode);
810 GOTO(progress, rc = PTR_ERR(inode));
813 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
816 CDEBUG(D_HSM, "Could not read file data version. "
817 "Request could not be confirmed.\n");
818 if (hpk.hpk_errval == 0)
819 hpk.hpk_errval = -rc;
823 /* Store it the hsm_copy for later copytool use.
824 * Always modified even if no lsm. */
825 hpk.hpk_data_version = data_version;
827 /* File could have been stripped during archiving, so we need
828 * to check anyway. */
829 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
830 (copy->hc_data_version != data_version)) {
831 CDEBUG(D_HSM, "File data version mismatched. "
832 "File content was changed during archiving. "
833 DFID", start:"LPX64" current:"LPX64"\n",
834 PFID(©->hc_hai.hai_fid),
835 copy->hc_data_version, data_version);
836 /* File was changed, send error to cdt. Do not ask for
837 * retry because if a file is modified frequently,
838 * the cdt will loop on retried archive requests.
839 * The policy engine will ask for a new archive later
840 * when the file will not be modified for some tunable
842 /* we do not notify caller */
843 hpk.hpk_flags &= ~HP_FLAG_RETRY;
844 /* hpk_errval must be >= 0 */
845 hpk.hpk_errval = EBUSY;
851 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
858 static int copy_and_ioctl(int cmd, struct obd_export *exp,
859 const void __user *data, size_t size)
864 OBD_ALLOC(copy, size);
868 if (copy_from_user(copy, data, size)) {
873 rc = obd_iocontrol(cmd, exp, size, copy, NULL);
875 OBD_FREE(copy, size);
880 static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
882 int cmd = qctl->qc_cmd;
883 int type = qctl->qc_type;
884 int id = qctl->qc_id;
885 int valid = qctl->qc_valid;
890 case LUSTRE_Q_INVALIDATE:
891 case LUSTRE_Q_FINVALIDATE:
896 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
897 sbi->ll_flags & LL_SBI_RMT_CLIENT)
901 if (((type == USRQUOTA &&
902 !uid_eq(current_euid(), make_kuid(&init_user_ns, id))) ||
904 !in_egroup_p(make_kgid(&init_user_ns, id)))) &&
905 (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
906 sbi->ll_flags & LL_SBI_RMT_CLIENT))
912 CERROR("unsupported quotactl op: %#x\n", cmd);
916 if (valid != QC_GENERAL) {
917 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
920 if (cmd == Q_GETINFO)
921 qctl->qc_cmd = Q_GETOINFO;
922 else if (cmd == Q_GETQUOTA)
923 qctl->qc_cmd = Q_GETOQUOTA;
929 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
930 sizeof(*qctl), qctl, NULL);
933 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
934 sizeof(*qctl), qctl, NULL);
937 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
938 sizeof(*qctl), qctl, NULL);
940 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
942 sizeof(*qctl), qctl, NULL);
954 struct obd_quotactl *oqctl;
956 OBD_ALLOC_PTR(oqctl);
960 QCTL_COPY(oqctl, qctl);
961 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
963 if (rc != -EALREADY && cmd == Q_QUOTAON) {
964 oqctl->qc_cmd = Q_QUOTAOFF;
965 obd_quotactl(sbi->ll_md_exp, oqctl);
970 /* If QIF_SPACE is not set, client should collect the
971 * space usage from OSSs by itself */
972 if (cmd == Q_GETQUOTA &&
973 !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
974 !oqctl->qc_dqblk.dqb_curspace) {
975 struct obd_quotactl *oqctl_tmp;
977 OBD_ALLOC_PTR(oqctl_tmp);
978 if (oqctl_tmp == NULL)
979 GOTO(out, rc = -ENOMEM);
981 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
982 oqctl_tmp->qc_id = oqctl->qc_id;
983 oqctl_tmp->qc_type = oqctl->qc_type;
985 /* collect space usage from OSTs */
986 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
987 rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
988 if (!rc || rc == -EREMOTEIO) {
989 oqctl->qc_dqblk.dqb_curspace =
990 oqctl_tmp->qc_dqblk.dqb_curspace;
991 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
994 /* collect space & inode usage from MDTs */
995 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
996 oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
997 rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
998 if (!rc || rc == -EREMOTEIO) {
999 oqctl->qc_dqblk.dqb_curspace +=
1000 oqctl_tmp->qc_dqblk.dqb_curspace;
1001 oqctl->qc_dqblk.dqb_curinodes =
1002 oqctl_tmp->qc_dqblk.dqb_curinodes;
1003 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
1005 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
1008 OBD_FREE_PTR(oqctl_tmp);
1011 QCTL_COPY(qctl, oqctl);
1012 OBD_FREE_PTR(oqctl);
1019 ll_getname(const char __user *filename)
1022 char *tmp = __getname();
1025 return ERR_PTR(-ENOMEM);
1027 len = strncpy_from_user(tmp, filename, PATH_MAX);
1030 else if (len > PATH_MAX)
1031 ret = -ENAMETOOLONG;
1040 #define ll_putname(filename) __putname(filename)
1042 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1044 struct inode *inode = file->f_dentry->d_inode;
1045 struct ll_sb_info *sbi = ll_i2sbi(inode);
1046 struct obd_ioctl_data *data;
1050 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%#x\n",
1051 PFID(ll_inode2fid(inode)), inode, cmd);
1053 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
1054 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
1057 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
1059 case FSFILT_IOC_GETFLAGS:
1060 case FSFILT_IOC_SETFLAGS:
1061 RETURN(ll_iocontrol(inode, file, cmd, arg));
1062 case FSFILT_IOC_GETVERSION_OLD:
1063 case FSFILT_IOC_GETVERSION:
1064 RETURN(put_user(inode->i_generation, (int __user *)arg));
1065 /* We need to special case any other ioctls we want to handle,
1066 * to send them to the MDS/OST as appropriate and to properly
1067 * network encode the arg field.
1068 case FSFILT_IOC_SETVERSION_OLD:
1069 case FSFILT_IOC_SETVERSION:
1071 case LL_IOC_GET_MDTIDX: {
1074 mdtidx = ll_get_mdt_idx(inode);
1078 if (put_user((int)mdtidx, (int __user *)arg))
1083 case IOC_MDC_LOOKUP: {
1084 int namelen, len = 0;
1088 rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
1093 filename = data->ioc_inlbuf1;
1094 namelen = strlen(filename);
1096 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1097 GOTO(out_free, rc = -EINVAL);
1100 rc = ll_get_fid_by_name(inode, filename, namelen, NULL);
1102 CERROR("%s: lookup %.*s failed: rc = %d\n",
1103 ll_get_fsname(inode->i_sb, NULL, 0), namelen,
1108 obd_ioctl_freedata(buf, len);
1111 case LL_IOC_LMV_SETSTRIPE: {
1112 struct lmv_user_md *lum;
1121 rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
1126 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1127 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1128 GOTO(lmv_out_free, rc = -EINVAL);
1130 filename = data->ioc_inlbuf1;
1131 namelen = data->ioc_inllen1;
1134 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1135 GOTO(lmv_out_free, rc = -EINVAL);
1137 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1138 lumlen = data->ioc_inllen2;
1140 if (lum->lum_magic != LMV_USER_MAGIC ||
1141 lumlen != sizeof(*lum)) {
1142 CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1143 filename, lum->lum_magic, lumlen, -EFAULT);
1144 GOTO(lmv_out_free, rc = -EINVAL);
1147 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 50, 0)
1148 mode = data->ioc_type != 0 ? data->ioc_type : S_IRWXUGO;
1150 mode = data->ioc_type;
1152 rc = ll_dir_setdirstripe(inode, lum, filename, mode);
1154 obd_ioctl_freedata(buf, len);
1158 case LL_IOC_LMV_SET_DEFAULT_STRIPE: {
1159 struct lmv_user_md lum;
1160 struct lmv_user_md __user *ulump =
1161 (struct lmv_user_md __user *)arg;
1164 if (copy_from_user(&lum, ulump, sizeof(lum)))
1167 if (lum.lum_magic != LMV_USER_MAGIC)
1170 rc = ll_dir_setstripe(inode, (struct lov_user_md *)&lum, 0);
1174 case LL_IOC_LOV_SETSTRIPE: {
1175 struct lov_user_md_v3 lumv3;
1176 struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
1177 struct lov_user_md_v1 __user *lumv1p =
1178 (struct lov_user_md_v1 __user *)arg;
1179 struct lov_user_md_v3 __user *lumv3p =
1180 (struct lov_user_md_v3 __user *)arg;
1182 int set_default = 0;
1184 LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
1185 LASSERT(sizeof(lumv3.lmm_objects[0]) ==
1186 sizeof(lumv3p->lmm_objects[0]));
1187 /* first try with v1 which is smaller than v3 */
1188 if (copy_from_user(lumv1, lumv1p, sizeof(*lumv1)))
1191 if ((lumv1->lmm_magic == LOV_USER_MAGIC_V3) ) {
1192 if (copy_from_user(&lumv3, lumv3p, sizeof(lumv3)))
1196 if (inode->i_sb->s_root == file->f_dentry)
1199 /* in v1 and v3 cases lumv1 points to data */
1200 rc = ll_dir_setstripe(inode, lumv1, set_default);
1204 case LL_IOC_LMV_GETSTRIPE: {
1205 struct lmv_user_md __user *ulmv =
1206 (struct lmv_user_md __user *)arg;
1207 struct lmv_user_md lum;
1208 struct ptlrpc_request *request = NULL;
1209 union lmv_mds_md *lmm = NULL;
1211 obd_valid valid = 0;
1212 struct lmv_user_md *tmp = NULL;
1219 if (copy_from_user(&lum, ulmv, sizeof(*ulmv)))
1222 /* lum_magic will indicate which stripe the ioctl will like
1223 * to get, LMV_MAGIC_V1 is for normal LMV stripe, LMV_USER_MAGIC
1224 * is for default LMV stripe */
1225 if (lum.lum_magic == LMV_MAGIC_V1)
1226 valid |= OBD_MD_MEA;
1227 else if (lum.lum_magic == LMV_USER_MAGIC)
1228 valid |= OBD_MD_DEFAULT_MEA;
1232 rc = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize, &request,
1235 GOTO(finish_req, rc);
1237 /* Get default LMV EA */
1238 if (lum.lum_magic == LMV_USER_MAGIC) {
1240 GOTO(finish_req, rc);
1242 if (lmmsize > sizeof(*ulmv))
1243 GOTO(finish_req, rc = -EINVAL);
1245 if (copy_to_user(ulmv, lmm, lmmsize))
1246 GOTO(finish_req, rc = -EFAULT);
1248 GOTO(finish_req, rc);
1251 stripe_count = lmv_mds_md_stripe_count_get(lmm);
1252 lum_size = lmv_user_md_size(stripe_count, LMV_MAGIC_V1);
1253 OBD_ALLOC(tmp, lum_size);
1255 GOTO(finish_req, rc = -ENOMEM);
1257 mdt_index = ll_get_mdt_idx(inode);
1259 GOTO(out_tmp, rc = -ENOMEM);
1261 tmp->lum_magic = LMV_MAGIC_V1;
1262 tmp->lum_stripe_count = 0;
1263 tmp->lum_stripe_offset = mdt_index;
1264 for (i = 0; i < stripe_count; i++) {
1267 fid_le_to_cpu(&fid, &lmm->lmv_md_v1.lmv_stripe_fids[i]);
1268 mdt_index = ll_get_mdt_idx_by_fid(sbi, &fid);
1270 GOTO(out_tmp, rc = mdt_index);
1272 tmp->lum_objects[i].lum_mds = mdt_index;
1273 tmp->lum_objects[i].lum_fid = fid;
1274 tmp->lum_stripe_count++;
1277 if (copy_to_user(ulmv, tmp, lum_size))
1278 GOTO(out_tmp, rc = -EFAULT);
1280 OBD_FREE(tmp, lum_size);
1282 ptlrpc_req_finished(request);
1286 case LL_IOC_REMOVE_ENTRY: {
1287 char *filename = NULL;
1291 /* Here is a little hack to avoid sending REINT_RMENTRY to
1292 * unsupported server, which might crash the server(LU-2730),
1293 * Because both LVB_TYPE and REINT_RMENTRY will be supported
1294 * on 2.4, we use OBD_CONNECT_LVB_TYPE to detect whether the
1295 * server will support REINT_RMENTRY XXX*/
1296 if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE))
1299 filename = ll_getname((const char __user *)arg);
1300 if (IS_ERR(filename))
1301 RETURN(PTR_ERR(filename));
1303 namelen = strlen(filename);
1305 GOTO(out_rmdir, rc = -EINVAL);
1307 rc = ll_rmdir_entry(inode, filename, namelen);
1310 ll_putname(filename);
1313 case LL_IOC_LOV_SWAP_LAYOUTS:
1315 case IOC_OBD_STATFS:
1316 RETURN(ll_obd_statfs(inode, (void __user *)arg));
1317 case LL_IOC_LOV_GETSTRIPE:
1318 case LL_IOC_MDC_GETINFO:
1319 case IOC_MDC_GETFILEINFO:
1320 case IOC_MDC_GETFILESTRIPE: {
1321 struct ptlrpc_request *request = NULL;
1322 struct lov_user_md __user *lump;
1323 struct lov_mds_md *lmm = NULL;
1324 struct mdt_body *body;
1325 char *filename = NULL;
1328 if (cmd == IOC_MDC_GETFILEINFO ||
1329 cmd == IOC_MDC_GETFILESTRIPE) {
1330 filename = ll_getname((const char __user *)arg);
1331 if (IS_ERR(filename))
1332 RETURN(PTR_ERR(filename));
1334 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1335 &lmmsize, &request);
1337 rc = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize,
1342 body = req_capsule_server_get(&request->rq_pill,
1344 LASSERT(body != NULL);
1350 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
1351 cmd == LL_IOC_MDC_GETINFO))
1352 GOTO(skip_lmm, rc = 0);
1357 if (cmd == IOC_MDC_GETFILESTRIPE ||
1358 cmd == LL_IOC_LOV_GETSTRIPE) {
1359 lump = (struct lov_user_md __user *)arg;
1361 struct lov_user_mds_data __user *lmdp;
1362 lmdp = (struct lov_user_mds_data __user *)arg;
1363 lump = &lmdp->lmd_lmm;
1365 if (copy_to_user(lump, lmm, lmmsize)) {
1366 if (copy_to_user(lump, lmm, sizeof(*lump)))
1367 GOTO(out_req, rc = -EFAULT);
1371 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
1372 struct lov_user_mds_data __user *lmdp;
1375 st.st_dev = inode->i_sb->s_dev;
1376 st.st_mode = body->mbo_mode;
1377 st.st_nlink = body->mbo_nlink;
1378 st.st_uid = body->mbo_uid;
1379 st.st_gid = body->mbo_gid;
1380 st.st_rdev = body->mbo_rdev;
1381 st.st_size = body->mbo_size;
1382 st.st_blksize = PAGE_CACHE_SIZE;
1383 st.st_blocks = body->mbo_blocks;
1384 st.st_atime = body->mbo_atime;
1385 st.st_mtime = body->mbo_mtime;
1386 st.st_ctime = body->mbo_ctime;
1387 st.st_ino = inode->i_ino;
1389 lmdp = (struct lov_user_mds_data __user *)arg;
1390 if (copy_to_user(&lmdp->lmd_st, &st, sizeof(st)))
1391 GOTO(out_req, rc = -EFAULT);
1396 ptlrpc_req_finished(request);
1398 ll_putname(filename);
1401 case IOC_LOV_GETINFO: {
1402 struct lov_user_mds_data __user *lumd;
1403 struct lov_stripe_md *lsm;
1404 struct lov_user_md __user *lum;
1405 struct lov_mds_md *lmm;
1409 lumd = (struct lov_user_mds_data __user *)arg;
1410 lum = &lumd->lmd_lmm;
1412 rc = ll_get_max_mdsize(sbi, &lmmsize);
1416 OBD_ALLOC_LARGE(lmm, lmmsize);
1420 if (copy_from_user(lmm, lum, lmmsize))
1421 GOTO(free_lmm, rc = -EFAULT);
1423 switch (lmm->lmm_magic) {
1424 case LOV_USER_MAGIC_V1:
1425 if (LOV_USER_MAGIC_V1 == cpu_to_le32(LOV_USER_MAGIC_V1))
1427 /* swab objects first so that stripes num will be sane */
1428 lustre_swab_lov_user_md_objects(
1429 ((struct lov_user_md_v1 *)lmm)->lmm_objects,
1430 ((struct lov_user_md_v1 *)lmm)->lmm_stripe_count);
1431 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
1433 case LOV_USER_MAGIC_V3:
1434 if (LOV_USER_MAGIC_V3 == cpu_to_le32(LOV_USER_MAGIC_V3))
1436 /* swab objects first so that stripes num will be sane */
1437 lustre_swab_lov_user_md_objects(
1438 ((struct lov_user_md_v3 *)lmm)->lmm_objects,
1439 ((struct lov_user_md_v3 *)lmm)->lmm_stripe_count);
1440 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
1443 GOTO(free_lmm, rc = -EINVAL);
1446 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
1448 GOTO(free_lmm, rc = -ENOMEM);
1450 /* Perform glimpse_size operation. */
1451 memset(&st, 0, sizeof(st));
1453 rc = ll_glimpse_ioctl(sbi, lsm, &st);
1457 if (copy_to_user(&lumd->lmd_st, &st, sizeof(st)))
1458 GOTO(free_lsm, rc = -EFAULT);
1462 obd_free_memmd(sbi->ll_dt_exp, &lsm);
1464 OBD_FREE_LARGE(lmm, lmmsize);
1467 case OBD_IOC_QUOTACHECK: {
1468 struct obd_quotactl *oqctl;
1471 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1472 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1475 OBD_ALLOC_PTR(oqctl);
1478 oqctl->qc_type = arg;
1479 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
1481 CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
1485 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
1487 CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
1489 OBD_FREE_PTR(oqctl);
1492 case OBD_IOC_POLL_QUOTACHECK: {
1493 struct if_quotacheck *check;
1495 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1496 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1499 OBD_ALLOC_PTR(check);
1503 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
1506 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
1507 if (copy_to_user((void __user *)arg, check,
1509 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1513 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
1516 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
1517 if (copy_to_user((void __user *)arg, check,
1519 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1523 OBD_FREE_PTR(check);
1526 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 53, 0)
1527 case LL_IOC_QUOTACTL_18: {
1528 /* copy the old 1.x quota struct for internal use, then copy
1529 * back into old format struct. For 1.8 compatibility. */
1530 struct if_quotactl_18 *qctl_18;
1531 struct if_quotactl *qctl_20;
1533 OBD_ALLOC_PTR(qctl_18);
1537 OBD_ALLOC_PTR(qctl_20);
1539 GOTO(out_quotactl_18, rc = -ENOMEM);
1541 if (copy_from_user(qctl_18, (void __user *)arg,
1543 GOTO(out_quotactl_20, rc = -ENOMEM);
1545 QCTL_COPY(qctl_20, qctl_18);
1546 qctl_20->qc_idx = 0;
1548 /* XXX: dqb_valid was borrowed as a flag to mark that
1549 * only mds quota is wanted */
1550 if (qctl_18->qc_cmd == Q_GETQUOTA &&
1551 qctl_18->qc_dqblk.dqb_valid) {
1552 qctl_20->qc_valid = QC_MDTIDX;
1553 qctl_20->qc_dqblk.dqb_valid = 0;
1554 } else if (qctl_18->obd_uuid.uuid[0] != '\0') {
1555 qctl_20->qc_valid = QC_UUID;
1556 qctl_20->obd_uuid = qctl_18->obd_uuid;
1558 qctl_20->qc_valid = QC_GENERAL;
1561 rc = quotactl_ioctl(sbi, qctl_20);
1564 QCTL_COPY(qctl_18, qctl_20);
1565 qctl_18->obd_uuid = qctl_20->obd_uuid;
1567 if (copy_to_user((void __user *)arg, qctl_18,
1573 OBD_FREE_PTR(qctl_20);
1575 OBD_FREE_PTR(qctl_18);
1578 #endif /* LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 53, 0) */
1579 case OBD_IOC_QUOTACTL: {
1580 struct if_quotactl *qctl;
1582 OBD_ALLOC_PTR(qctl);
1586 if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl)))
1587 GOTO(out_quotactl, rc = -EFAULT);
1589 rc = quotactl_ioctl(sbi, qctl);
1592 copy_to_user((void __user *)arg, qctl, sizeof(*qctl)))
1599 case OBD_IOC_GETDTNAME:
1600 case OBD_IOC_GETMDNAME:
1601 RETURN(ll_get_obd_name(inode, cmd, arg));
1602 case LL_IOC_FLUSHCTX:
1603 RETURN(ll_flush_ctx(inode));
1604 #ifdef CONFIG_FS_POSIX_ACL
1605 case LL_IOC_RMTACL: {
1606 if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
1607 inode == inode->i_sb->s_root->d_inode) {
1608 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1610 LASSERT(fd != NULL);
1611 rc = rct_add(&sbi->ll_rct, current_pid(), arg);
1613 fd->fd_flags |= LL_FILE_RMTACL;
1619 case LL_IOC_GETOBDCOUNT: {
1621 struct obd_export *exp;
1623 if (copy_from_user(&count, (int __user *)arg, sizeof(int)))
1626 /* get ost count when count is zero, get mdt count otherwise */
1627 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
1628 vallen = sizeof(count);
1629 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
1630 KEY_TGT_COUNT, &vallen, &count, NULL);
1632 CERROR("get target count failed: %d\n", rc);
1636 if (copy_to_user((int __user *)arg, &count, sizeof(int)))
1641 case LL_IOC_PATH2FID:
1642 if (copy_to_user((void __user *)arg, ll_inode2fid(inode),
1643 sizeof(struct lu_fid)))
1646 case LL_IOC_GET_CONNECT_FLAGS: {
1647 RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL,
1648 (void __user *)arg));
1650 case OBD_IOC_CHANGELOG_SEND:
1651 case OBD_IOC_CHANGELOG_CLEAR:
1652 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void __user *)arg,
1653 sizeof(struct ioc_changelog));
1655 case OBD_IOC_FID2PATH:
1656 RETURN(ll_fid2path(inode, (void __user *)arg));
1657 case LL_IOC_FID2MDTIDX: {
1658 struct obd_export *exp = ll_i2mdexp(inode);
1662 if (copy_from_user(&fid, (const struct lu_fid __user *)arg,
1666 /* Call mdc_iocontrol */
1667 rc = obd_iocontrol(LL_IOC_FID2MDTIDX, exp, sizeof(fid), &fid,
1668 (__u32 __user *)&index);
1674 case LL_IOC_HSM_REQUEST: {
1675 struct hsm_user_request *hur;
1682 /* We don't know the true size yet; copy the fixed-size part */
1683 if (copy_from_user(hur, (void __user *)arg, sizeof(*hur))) {
1688 /* Compute the whole struct size */
1689 totalsize = hur_len(hur);
1694 /* Final size will be more than double totalsize */
1695 if (totalsize >= MDS_MAXREQSIZE / 3)
1698 OBD_ALLOC_LARGE(hur, totalsize);
1702 /* Copy the whole struct */
1703 if (copy_from_user(hur, (void __user *)arg, totalsize)) {
1704 OBD_FREE_LARGE(hur, totalsize);
1708 if (hur->hur_request.hr_action == HUA_RELEASE) {
1709 const struct lu_fid *fid;
1713 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
1714 fid = &hur->hur_user_item[i].hui_fid;
1715 f = search_inode_for_lustre(inode->i_sb, fid);
1721 rc = ll_hsm_release(f);
1727 rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
1731 OBD_FREE_LARGE(hur, totalsize);
1735 case LL_IOC_HSM_PROGRESS: {
1736 struct hsm_progress_kernel hpk;
1737 struct hsm_progress hp;
1739 if (copy_from_user(&hp, (void __user *)arg, sizeof(hp)))
1742 hpk.hpk_fid = hp.hp_fid;
1743 hpk.hpk_cookie = hp.hp_cookie;
1744 hpk.hpk_extent = hp.hp_extent;
1745 hpk.hpk_flags = hp.hp_flags;
1746 hpk.hpk_errval = hp.hp_errval;
1747 hpk.hpk_data_version = 0;
1749 /* File may not exist in Lustre; all progress
1750 * reported to Lustre root */
1751 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
1755 case LL_IOC_HSM_CT_START:
1756 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
1759 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void __user *)arg,
1760 sizeof(struct lustre_kernelcomm));
1763 case LL_IOC_HSM_COPY_START: {
1764 struct hsm_copy *copy;
1767 OBD_ALLOC_PTR(copy);
1770 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
1775 rc = ll_ioc_copy_start(inode->i_sb, copy);
1776 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
1782 case LL_IOC_HSM_COPY_END: {
1783 struct hsm_copy *copy;
1786 OBD_ALLOC_PTR(copy);
1789 if (copy_from_user(copy, (char __user *)arg, sizeof(*copy))) {
1794 rc = ll_ioc_copy_end(inode->i_sb, copy);
1795 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
1801 case LL_IOC_MIGRATE: {
1803 const char *filename;
1809 rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
1813 data = (struct obd_ioctl_data *)buf;
1814 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1815 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1816 GOTO(migrate_free, rc = -EINVAL);
1818 filename = data->ioc_inlbuf1;
1819 namelen = data->ioc_inllen1;
1820 /* \0 is packed at the end of filename */
1821 if (namelen < 1 || namelen != strlen(filename) + 1)
1822 GOTO(migrate_free, rc = -EINVAL);
1824 if (data->ioc_inllen2 != sizeof(mdtidx))
1825 GOTO(migrate_free, rc = -EINVAL);
1826 mdtidx = *(int *)data->ioc_inlbuf2;
1828 rc = ll_migrate(inode, file, mdtidx, filename, namelen - 1);
1830 obd_ioctl_freedata(buf, len);
1835 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL,
1836 (void __user *)arg));
1840 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
1842 struct inode *inode = file->f_mapping->host;
1843 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1844 struct ll_sb_info *sbi = ll_i2sbi(inode);
1845 int api32 = ll_need_32bit_api(sbi);
1846 loff_t ret = -EINVAL;
1849 mutex_lock(&inode->i_mutex);
1854 offset += file->f_pos;
1860 offset += LL_DIR_END_OFF_32BIT;
1862 offset += LL_DIR_END_OFF;
1869 ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
1870 (!api32 && offset <= LL_DIR_END_OFF))) {
1871 if (offset != file->f_pos) {
1872 if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
1873 (!api32 && offset == LL_DIR_END_OFF))
1874 fd->lfd_pos = MDS_DIR_END_OFF;
1875 else if (api32 && sbi->ll_flags & LL_SBI_64BIT_HASH)
1876 fd->lfd_pos = offset << 32;
1878 fd->lfd_pos = offset;
1879 file->f_pos = offset;
1880 file->f_version = 0;
1887 mutex_unlock(&inode->i_mutex);
1891 static int ll_dir_open(struct inode *inode, struct file *file)
1894 RETURN(ll_file_open(inode, file));
1897 static int ll_dir_release(struct inode *inode, struct file *file)
1900 RETURN(ll_file_release(inode, file));
1903 const struct file_operations ll_dir_operations = {
1904 .llseek = ll_dir_seek,
1905 .open = ll_dir_open,
1906 .release = ll_dir_release,
1907 .read = generic_read_dir,
1908 #ifdef HAVE_DIR_CONTEXT
1909 .iterate = ll_iterate,
1911 .readdir = ll_readdir,
1913 .unlocked_ioctl = ll_dir_ioctl,