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_lite.h>
57 #include <lustre_dlm.h>
58 #include <lustre_fid.h>
59 #include "llite_internal.h"
62 * (new) readdir implementation overview.
64 * Original lustre readdir implementation cached exact copy of raw directory
65 * pages on the client. These pages were indexed in client page cache by
66 * logical offset in the directory file. This design, while very simple and
67 * intuitive had some inherent problems:
69 * . it implies that byte offset to the directory entry serves as a
70 * telldir(3)/seekdir(3) cookie, but that offset is not stable: in
71 * ext3/htree directory entries may move due to splits, and more
74 * . it is incompatible with the design of split directories for cmd3,
75 * that assumes that names are distributed across nodes based on their
76 * hash, and so readdir should be done in hash order.
78 * New readdir implementation does readdir in hash order, and uses hash of a
79 * file name as a telldir/seekdir cookie. This led to number of complications:
81 * . hash is not unique, so it cannot be used to index cached directory
82 * pages on the client (note, that it requires a whole pageful of hash
83 * collided entries to cause two pages to have identical hashes);
85 * . hash is not unique, so it cannot, strictly speaking, be used as an
86 * entry cookie. ext3/htree has the same problem and lustre implementation
87 * mimics their solution: seekdir(hash) positions directory at the first
88 * entry with the given hash.
94 * Client caches directory pages using hash of the first entry as an index. As
95 * noted above hash is not unique, so this solution doesn't work as is:
96 * special processing is needed for "page hash chains" (i.e., sequences of
97 * pages filled with entries all having the same hash value).
99 * First, such chains have to be detected. To this end, server returns to the
100 * client the hash of the first entry on the page next to one returned. When
101 * client detects that this hash is the same as hash of the first entry on the
102 * returned page, page hash collision has to be handled. Pages in the
103 * hash chain, except first one, are termed "overflow pages".
105 * Solution to index uniqueness problem is to not cache overflow
106 * pages. Instead, when page hash collision is detected, all overflow pages
107 * from emerging chain are immediately requested from the server and placed in
108 * a special data structure (struct ll_dir_chain). This data structure is used
109 * by ll_readdir() to process entries from overflow pages. When readdir
110 * invocation finishes, overflow pages are discarded. If page hash collision
111 * chain weren't completely processed, next call to readdir will again detect
112 * page hash collision, again read overflow pages in, process next portion of
113 * entries and again discard the pages. This is not as wasteful as it looks,
114 * because, given reasonable hash, page hash collisions are extremely rare.
116 * 1. directory positioning
118 * When seekdir(hash) is called, original
129 * identification of and access to overflow pages
133 * Page in MDS_READPAGE RPC is packed in LU_PAGE_SIZE, and each page contains
134 * a header lu_dirpage which describes the start/end hash, and whether this
135 * page is empty (contains no dir entry) or hash collide with next page.
136 * After client receives reply, several pages will be integrated into dir page
137 * in PAGE_CACHE_SIZE (if PAGE_CACHE_SIZE greater than LU_PAGE_SIZE), and the
138 * lu_dirpage for this integrated page will be adjusted. See
139 * mdc_adjust_dirpages().
142 struct page *ll_get_dir_page(struct inode *dir, struct md_op_data *op_data,
143 __u64 offset, struct ll_dir_chain *chain)
145 struct md_callback cb_op;
149 cb_op.md_blocking_ast = ll_md_blocking_ast;
150 rc = md_read_page(ll_i2mdexp(dir), op_data, &cb_op, offset, &page);
157 void ll_release_page(struct inode *inode, struct page *page,
162 /* Always remove the page for striped dir, because the page is
163 * built from temporarily in LMV layer */
164 if (inode != NULL && S_ISDIR(inode->i_mode) &&
165 ll_i2info(inode)->lli_lsm_md != NULL) {
172 if (likely(page->mapping != NULL))
173 truncate_complete_page(page->mapping, page);
176 page_cache_release(page);
179 #ifdef HAVE_DIR_CONTEXT
180 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
181 struct dir_context *ctx)
184 int ll_dir_read(struct inode *inode, __u64 *ppos, struct md_op_data *op_data,
185 void *cookie, filldir_t filldir)
188 struct ll_sb_info *sbi = ll_i2sbi(inode);
190 bool is_api32 = ll_need_32bit_api(sbi);
191 bool is_hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
193 struct ll_dir_chain chain;
198 ll_dir_chain_init(&chain);
200 page = ll_get_dir_page(inode, op_data, pos, &chain);
202 while (rc == 0 && !done) {
203 struct lu_dirpage *dp;
204 struct lu_dirent *ent;
213 hash = MDS_DIR_END_OFF;
214 dp = page_address(page);
215 for (ent = lu_dirent_start(dp); ent != NULL && !done;
216 ent = lu_dirent_next(ent)) {
223 hash = le64_to_cpu(ent->lde_hash);
226 * Skip until we find target hash
231 namelen = le16_to_cpu(ent->lde_namelen);
238 if (is_api32 && is_hash64)
242 fid_le_to_cpu(&fid, &ent->lde_fid);
243 ino = cl_fid_build_ino(&fid, is_api32);
244 type = ll_dirent_type_get(ent);
245 /* For 'll_nfs_get_name_filldir()', it will try
246 * to access the 'ent' through its 'lde_name',
247 * so the parameter 'name' for 'filldir()' must
248 * be part of the 'ent'. */
249 #ifdef HAVE_DIR_CONTEXT
251 done = !dir_emit(ctx, ent->lde_name, namelen, ino,
254 done = filldir(cookie, ent->lde_name, namelen, lhash,
261 ll_release_page(inode, page, false);
265 next = le64_to_cpu(dp->ldp_hash_end);
267 if (pos == MDS_DIR_END_OFF) {
269 * End of directory reached.
272 ll_release_page(inode, page, false);
275 * Normal case: continue to the next
278 ll_release_page(inode, page,
279 le32_to_cpu(dp->ldp_flags) &
282 page = ll_get_dir_page(inode, op_data, pos,
286 #ifdef HAVE_DIR_CONTEXT
291 ll_dir_chain_fini(&chain);
295 #ifdef HAVE_DIR_CONTEXT
296 static int ll_iterate(struct file *filp, struct dir_context *ctx)
298 static int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
301 struct inode *inode = filp->f_dentry->d_inode;
302 struct ll_file_data *lfd = LUSTRE_FPRIVATE(filp);
303 struct ll_sb_info *sbi = ll_i2sbi(inode);
304 int hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
305 int api32 = ll_need_32bit_api(sbi);
306 struct md_op_data *op_data;
316 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) pos/size"
317 "%lu/%llu 32bit_api %d\n", PFID(ll_inode2fid(inode)),
318 inode, (unsigned long)pos, i_size_read(inode), api32);
320 if (pos == MDS_DIR_END_OFF)
326 op_data = ll_prep_md_op_data(NULL, inode, inode, NULL, 0, 0,
327 LUSTRE_OPC_ANY, inode);
329 GOTO(out, rc = PTR_ERR(op_data));
331 if (unlikely(op_data->op_mea1 != NULL)) {
332 /* This is only needed for striped dir to fill ..,
333 * see lmv_read_entry */
334 if (filp->f_dentry->d_parent != NULL &&
335 filp->f_dentry->d_parent->d_inode != NULL) {
336 __u64 ibits = MDS_INODELOCK_UPDATE;
337 struct inode *parent =
338 filp->f_dentry->d_parent->d_inode;
340 if (ll_have_md_lock(parent, &ibits, LCK_MINMODE))
341 op_data->op_fid3 = *ll_inode2fid(parent);
344 /* If it can not find in cache, do lookup .. on the master
346 if (fid_is_zero(&op_data->op_fid3)) {
347 rc = ll_dir_get_parent_fid(inode, &op_data->op_fid3);
349 ll_finish_md_op_data(op_data);
354 op_data->op_max_pages = sbi->ll_md_brw_pages;
355 #ifdef HAVE_DIR_CONTEXT
357 rc = ll_dir_read(inode, &pos, op_data, ctx);
360 rc = ll_dir_read(inode, &pos, op_data, cookie, filldir);
365 if (pos == MDS_DIR_END_OFF) {
367 pos = LL_DIR_END_OFF_32BIT;
369 pos = LL_DIR_END_OFF;
374 #ifdef HAVE_DIR_CONTEXT
379 ll_finish_md_op_data(op_data);
380 filp->f_version = inode->i_version;
384 ll_stats_ops_tally(sbi, LPROC_LL_READDIR, 1);
389 static int ll_send_mgc_param(struct obd_export *mgc, char *string)
391 struct mgs_send_param *msp;
398 strlcpy(msp->mgs_param, string, sizeof(msp->mgs_param));
399 rc = obd_set_info_async(NULL, mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
400 sizeof(struct mgs_send_param), msp, NULL);
402 CERROR("Failed to set parameter: %d\n", rc);
409 * Create striped directory with specified stripe(@lump)
411 * param[in]parent the parent of the directory.
412 * param[in]lump the specified stripes.
413 * param[in]dirname the name of the directory.
414 * param[in]mode the specified mode of the directory.
416 * retval =0 if striped directory is being created successfully.
417 * <0 if the creation is failed.
419 static int ll_dir_setdirstripe(struct inode *parent, struct lmv_user_md *lump,
420 const char *dirname, umode_t mode)
422 struct ptlrpc_request *request = NULL;
423 struct md_op_data *op_data;
424 struct ll_sb_info *sbi = ll_i2sbi(parent);
428 if (unlikely(lump->lum_magic != LMV_USER_MAGIC))
431 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) name %s"
432 "stripe_offset %d, stripe_count: %u\n",
433 PFID(ll_inode2fid(parent)), parent, dirname,
434 (int)lump->lum_stripe_offset, lump->lum_stripe_count);
436 if (lump->lum_magic != cpu_to_le32(LMV_USER_MAGIC))
437 lustre_swab_lmv_user_md(lump);
439 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
440 mode &= ~current_umask();
441 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
442 op_data = ll_prep_md_op_data(NULL, parent, NULL, dirname,
443 strlen(dirname), mode, LUSTRE_OPC_MKDIR,
446 GOTO(err_exit, err = PTR_ERR(op_data));
448 op_data->op_cli_flags |= CLI_SET_MEA;
449 err = md_create(sbi->ll_md_exp, op_data, lump, sizeof(*lump), mode,
450 from_kuid(&init_user_ns, current_fsuid()),
451 from_kgid(&init_user_ns, current_fsgid()),
452 cfs_curproc_cap_pack(), 0, &request);
453 ll_finish_md_op_data(op_data);
457 ptlrpc_req_finished(request);
461 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
464 struct ll_sb_info *sbi = ll_i2sbi(inode);
465 struct md_op_data *op_data;
466 struct ptlrpc_request *req = NULL;
468 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
469 struct obd_device *mgc = lsi->lsi_mgc;
475 * This is coming from userspace, so should be in
476 * local endian. But the MDS would like it in little
477 * endian, so we swab it before we send it.
479 switch (lump->lmm_magic) {
480 case LOV_USER_MAGIC_V1: {
481 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V1))
482 lustre_swab_lov_user_md_v1(lump);
483 lum_size = sizeof(struct lov_user_md_v1);
486 case LOV_USER_MAGIC_V3: {
487 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V3))
488 lustre_swab_lov_user_md_v3(
489 (struct lov_user_md_v3 *)lump);
490 lum_size = sizeof(struct lov_user_md_v3);
493 case LMV_USER_MAGIC: {
494 if (lump->lmm_magic != cpu_to_le32(LMV_USER_MAGIC))
495 lustre_swab_lmv_user_md(
496 (struct lmv_user_md *)lump);
497 lum_size = sizeof(struct lmv_user_md);
501 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
502 " %#08x != %#08x nor %#08x\n",
503 lump->lmm_magic, LOV_USER_MAGIC_V1,
509 lum_size = sizeof(struct lov_user_md_v1);
512 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
513 LUSTRE_OPC_ANY, NULL);
515 RETURN(PTR_ERR(op_data));
517 /* swabbing is done in lov_setstripe() on server side */
518 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size,
519 NULL, 0, &req, NULL);
520 ll_finish_md_op_data(op_data);
521 ptlrpc_req_finished(req);
523 if (rc != -EPERM && rc != -EACCES)
524 CERROR("mdc_setattr fails: rc = %d\n", rc);
527 /* In the following we use the fact that LOV_USER_MAGIC_V1 and
528 LOV_USER_MAGIC_V3 have the same initial fields so we do not
529 need the make the distiction between the 2 versions */
530 if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
534 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
536 GOTO(end, rc = -ENOMEM);
539 /* Get fsname and assume devname to be -MDT0000. */
540 ll_get_fsname(inode->i_sb, buf, MTI_NAME_MAXLEN);
541 strcat(buf, "-MDT0000.lov");
544 /* Set root stripesize */
545 sprintf(buf, ".stripesize=%u",
546 lump ? le32_to_cpu(lump->lmm_stripe_size) : 0);
547 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
551 /* Set root stripecount */
552 sprintf(buf, ".stripecount=%hd",
553 lump ? le16_to_cpu(lump->lmm_stripe_count) : 0);
554 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
558 /* Set root stripeoffset */
559 sprintf(buf, ".stripeoffset=%hd",
560 lump ? le16_to_cpu(lump->lmm_stripe_offset) :
561 (typeof(lump->lmm_stripe_offset))(-1));
562 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
566 OBD_FREE(param, MGS_PARAM_MAXLEN);
572 * This function will be used to get default LOV/LMV/Default LMV
573 * @valid will be used to indicate which stripe it will retrieve
574 * OBD_MD_MEA LMV stripe EA
575 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
576 * otherwise Default LOV EA.
577 * Each time, it can only retrieve 1 stripe EA
579 int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
580 struct ptlrpc_request **request, obd_valid valid)
582 struct ll_sb_info *sbi = ll_i2sbi(inode);
583 struct mdt_body *body;
584 struct lov_mds_md *lmm = NULL;
585 struct ptlrpc_request *req = NULL;
587 struct md_op_data *op_data;
590 rc = ll_get_default_mdsize(sbi, &lmm_size);
594 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
595 0, lmm_size, LUSTRE_OPC_ANY,
598 RETURN(PTR_ERR(op_data));
600 op_data->op_valid = valid | OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
601 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
602 ll_finish_md_op_data(op_data);
604 CDEBUG(D_INFO, "md_getattr failed on inode "
605 DFID": rc %d\n", PFID(ll_inode2fid(inode)), rc);
609 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
610 LASSERT(body != NULL);
612 lmm_size = body->mbo_eadatasize;
614 if (!(body->mbo_valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
616 GOTO(out, rc = -ENODATA);
619 lmm = req_capsule_server_sized_get(&req->rq_pill,
620 &RMF_MDT_MD, lmm_size);
621 LASSERT(lmm != NULL);
624 * This is coming from the MDS, so is probably in
625 * little endian. We convert it to host endian before
626 * passing it to userspace.
628 /* We don't swab objects for directories */
629 switch (le32_to_cpu(lmm->lmm_magic)) {
631 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
632 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
635 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
636 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
639 if (LMV_MAGIC != cpu_to_le32(LMV_MAGIC))
640 lustre_swab_lmv_mds_md((union lmv_mds_md *)lmm);
643 if (LMV_USER_MAGIC != cpu_to_le32(LMV_USER_MAGIC))
644 lustre_swab_lmv_user_md((struct lmv_user_md *)lmm);
647 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
652 *plmm_size = lmm_size;
657 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid)
659 struct md_op_data *op_data;
664 OBD_ALLOC_PTR(op_data);
668 op_data->op_flags |= MF_GET_MDT_IDX;
669 op_data->op_fid1 = *fid;
670 rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
671 mdt_index = op_data->op_mds;
672 OBD_FREE_PTR(op_data);
680 * Get MDT index for the inode.
682 int ll_get_mdt_idx(struct inode *inode)
684 return ll_get_mdt_idx_by_fid(ll_i2sbi(inode), ll_inode2fid(inode));
688 * Generic handler to do any pre-copy work.
690 * It send a first hsm_progress (with extent length == 0) to coordinator as a
691 * first information for it that real work has started.
693 * Moreover, for a ARCHIVE request, it will sample the file data version and
694 * store it in \a copy.
696 * \return 0 on success.
698 static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
700 struct ll_sb_info *sbi = ll_s2sbi(sb);
701 struct hsm_progress_kernel hpk;
705 /* Forge a hsm_progress based on data from copy. */
706 hpk.hpk_fid = copy->hc_hai.hai_fid;
707 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
708 hpk.hpk_extent.offset = copy->hc_hai.hai_extent.offset;
709 hpk.hpk_extent.length = 0;
712 hpk.hpk_data_version = 0;
715 /* For archive request, we need to read the current file version. */
716 if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
718 __u64 data_version = 0;
720 /* Get inode for this fid */
721 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
723 hpk.hpk_flags |= HP_FLAG_RETRY;
724 /* hpk_errval is >= 0 */
725 hpk.hpk_errval = -PTR_ERR(inode);
726 GOTO(progress, rc = PTR_ERR(inode));
729 /* Read current file data version */
730 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
733 CDEBUG(D_HSM, "Could not read file data version of "
734 DFID" (rc = %d). Archive request ("
735 LPX64") could not be done.\n",
736 PFID(©->hc_hai.hai_fid), rc,
737 copy->hc_hai.hai_cookie);
738 hpk.hpk_flags |= HP_FLAG_RETRY;
739 /* hpk_errval must be >= 0 */
740 hpk.hpk_errval = -rc;
744 /* Store it the hsm_copy for later copytool use.
745 * Always modified even if no lsm. */
746 copy->hc_data_version = data_version;
750 /* On error, the request should be considered as completed */
751 if (hpk.hpk_errval > 0)
752 hpk.hpk_flags |= HP_FLAG_COMPLETED;
753 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
760 * Generic handler to do any post-copy work.
762 * It will send the last hsm_progress update to coordinator to inform it
763 * that copy is finished and whether it was successful or not.
766 * - for ARCHIVE request, it will sample the file data version and compare it
767 * with the version saved in ll_ioc_copy_start(). If they do not match, copy
768 * will be considered as failed.
769 * - for RESTORE request, it will sample the file data version and send it to
770 * coordinator which is useful if the file was imported as 'released'.
772 * \return 0 on success.
774 static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
776 struct ll_sb_info *sbi = ll_s2sbi(sb);
777 struct hsm_progress_kernel hpk;
781 /* If you modify the logic here, also check llapi_hsm_copy_end(). */
782 /* Take care: copy->hc_hai.hai_action, len, gid and data are not
783 * initialized if copy_end was called with copy == NULL.
786 /* Forge a hsm_progress based on data from copy. */
787 hpk.hpk_fid = copy->hc_hai.hai_fid;
788 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
789 hpk.hpk_extent = copy->hc_hai.hai_extent;
790 hpk.hpk_flags = copy->hc_flags | HP_FLAG_COMPLETED;
791 hpk.hpk_errval = copy->hc_errval;
792 hpk.hpk_data_version = 0;
794 /* For archive request, we need to check the file data was not changed.
796 * For restore request, we need to send the file data version, this is
797 * useful when the file was created using hsm_import.
799 if (((copy->hc_hai.hai_action == HSMA_ARCHIVE) ||
800 (copy->hc_hai.hai_action == HSMA_RESTORE)) &&
801 (copy->hc_errval == 0)) {
803 __u64 data_version = 0;
805 /* Get lsm for this fid */
806 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
808 hpk.hpk_flags |= HP_FLAG_RETRY;
809 /* hpk_errval must be >= 0 */
810 hpk.hpk_errval = -PTR_ERR(inode);
811 GOTO(progress, rc = PTR_ERR(inode));
814 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
817 CDEBUG(D_HSM, "Could not read file data version. "
818 "Request could not be confirmed.\n");
819 if (hpk.hpk_errval == 0)
820 hpk.hpk_errval = -rc;
824 /* Store it the hsm_copy for later copytool use.
825 * Always modified even if no lsm. */
826 hpk.hpk_data_version = data_version;
828 /* File could have been stripped during archiving, so we need
829 * to check anyway. */
830 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
831 (copy->hc_data_version != data_version)) {
832 CDEBUG(D_HSM, "File data version mismatched. "
833 "File content was changed during archiving. "
834 DFID", start:"LPX64" current:"LPX64"\n",
835 PFID(©->hc_hai.hai_fid),
836 copy->hc_data_version, data_version);
837 /* File was changed, send error to cdt. Do not ask for
838 * retry because if a file is modified frequently,
839 * the cdt will loop on retried archive requests.
840 * The policy engine will ask for a new archive later
841 * when the file will not be modified for some tunable
843 /* we do not notify caller */
844 hpk.hpk_flags &= ~HP_FLAG_RETRY;
845 /* hpk_errval must be >= 0 */
846 hpk.hpk_errval = EBUSY;
852 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
859 static int copy_and_ioctl(int cmd, struct obd_export *exp,
860 const void __user *data, size_t size)
865 OBD_ALLOC(copy, size);
869 if (copy_from_user(copy, data, size)) {
874 rc = obd_iocontrol(cmd, exp, size, copy, NULL);
876 OBD_FREE(copy, size);
881 static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
883 int cmd = qctl->qc_cmd;
884 int type = qctl->qc_type;
885 int id = qctl->qc_id;
886 int valid = qctl->qc_valid;
891 case LUSTRE_Q_INVALIDATE:
892 case LUSTRE_Q_FINVALIDATE:
897 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
898 sbi->ll_flags & LL_SBI_RMT_CLIENT)
902 if (((type == USRQUOTA &&
903 !uid_eq(current_euid(), make_kuid(&init_user_ns, id))) ||
905 !in_egroup_p(make_kgid(&init_user_ns, id)))) &&
906 (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
907 sbi->ll_flags & LL_SBI_RMT_CLIENT))
913 CERROR("unsupported quotactl op: %#x\n", cmd);
917 if (valid != QC_GENERAL) {
918 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
921 if (cmd == Q_GETINFO)
922 qctl->qc_cmd = Q_GETOINFO;
923 else if (cmd == Q_GETQUOTA)
924 qctl->qc_cmd = Q_GETOQUOTA;
930 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
931 sizeof(*qctl), qctl, NULL);
934 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
935 sizeof(*qctl), qctl, NULL);
938 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
939 sizeof(*qctl), qctl, NULL);
941 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
943 sizeof(*qctl), qctl, NULL);
955 struct obd_quotactl *oqctl;
957 OBD_ALLOC_PTR(oqctl);
961 QCTL_COPY(oqctl, qctl);
962 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
964 if (rc != -EALREADY && cmd == Q_QUOTAON) {
965 oqctl->qc_cmd = Q_QUOTAOFF;
966 obd_quotactl(sbi->ll_md_exp, oqctl);
971 /* If QIF_SPACE is not set, client should collect the
972 * space usage from OSSs by itself */
973 if (cmd == Q_GETQUOTA &&
974 !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
975 !oqctl->qc_dqblk.dqb_curspace) {
976 struct obd_quotactl *oqctl_tmp;
978 OBD_ALLOC_PTR(oqctl_tmp);
979 if (oqctl_tmp == NULL)
980 GOTO(out, rc = -ENOMEM);
982 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
983 oqctl_tmp->qc_id = oqctl->qc_id;
984 oqctl_tmp->qc_type = oqctl->qc_type;
986 /* collect space usage from OSTs */
987 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
988 rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
989 if (!rc || rc == -EREMOTEIO) {
990 oqctl->qc_dqblk.dqb_curspace =
991 oqctl_tmp->qc_dqblk.dqb_curspace;
992 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
995 /* collect space & inode usage from MDTs */
996 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
997 oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
998 rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
999 if (!rc || rc == -EREMOTEIO) {
1000 oqctl->qc_dqblk.dqb_curspace +=
1001 oqctl_tmp->qc_dqblk.dqb_curspace;
1002 oqctl->qc_dqblk.dqb_curinodes =
1003 oqctl_tmp->qc_dqblk.dqb_curinodes;
1004 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
1006 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
1009 OBD_FREE_PTR(oqctl_tmp);
1012 QCTL_COPY(qctl, oqctl);
1013 OBD_FREE_PTR(oqctl);
1020 ll_getname(const char __user *filename)
1023 char *tmp = __getname();
1026 return ERR_PTR(-ENOMEM);
1028 len = strncpy_from_user(tmp, filename, PATH_MAX);
1031 else if (len > PATH_MAX)
1032 ret = -ENAMETOOLONG;
1041 #define ll_putname(filename) __putname(filename)
1043 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1045 struct inode *inode = file->f_dentry->d_inode;
1046 struct ll_sb_info *sbi = ll_i2sbi(inode);
1047 struct obd_ioctl_data *data;
1051 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%#x\n",
1052 PFID(ll_inode2fid(inode)), inode, cmd);
1054 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
1055 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
1058 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
1060 case FSFILT_IOC_GETFLAGS:
1061 case FSFILT_IOC_SETFLAGS:
1062 RETURN(ll_iocontrol(inode, file, cmd, arg));
1063 case FSFILT_IOC_GETVERSION_OLD:
1064 case FSFILT_IOC_GETVERSION:
1065 RETURN(put_user(inode->i_generation, (int *)arg));
1066 /* We need to special case any other ioctls we want to handle,
1067 * to send them to the MDS/OST as appropriate and to properly
1068 * network encode the arg field.
1069 case FSFILT_IOC_SETVERSION_OLD:
1070 case FSFILT_IOC_SETVERSION:
1072 case LL_IOC_GET_MDTIDX: {
1075 mdtidx = ll_get_mdt_idx(inode);
1079 if (put_user((int)mdtidx, (int*)arg))
1084 case IOC_MDC_LOOKUP: {
1085 int namelen, len = 0;
1089 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
1094 filename = data->ioc_inlbuf1;
1095 namelen = strlen(filename);
1097 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1098 GOTO(out_free, rc = -EINVAL);
1101 rc = ll_get_fid_by_name(inode, filename, namelen, NULL);
1103 CERROR("%s: lookup %.*s failed: rc = %d\n",
1104 ll_get_fsname(inode->i_sb, NULL, 0), namelen,
1109 obd_ioctl_freedata(buf, len);
1112 case LL_IOC_LMV_SETSTRIPE: {
1113 struct lmv_user_md *lum;
1122 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
1127 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1128 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1129 GOTO(lmv_out_free, rc = -EINVAL);
1131 filename = data->ioc_inlbuf1;
1132 namelen = data->ioc_inllen1;
1135 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1136 GOTO(lmv_out_free, rc = -EINVAL);
1138 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1139 lumlen = data->ioc_inllen2;
1141 if (lum->lum_magic != LMV_USER_MAGIC ||
1142 lumlen != sizeof(*lum)) {
1143 CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1144 filename, lum->lum_magic, lumlen, -EFAULT);
1145 GOTO(lmv_out_free, rc = -EINVAL);
1148 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 50, 0)
1149 mode = data->ioc_type != 0 ? data->ioc_type : S_IRWXUGO;
1151 mode = data->ioc_type;
1153 rc = ll_dir_setdirstripe(inode, lum, filename, mode);
1155 obd_ioctl_freedata(buf, len);
1159 case LL_IOC_LMV_SET_DEFAULT_STRIPE: {
1160 struct lmv_user_md lum;
1161 struct lmv_user_md __user *ulump =
1162 (struct lmv_user_md __user *)arg;
1165 if (copy_from_user(&lum, ulump, sizeof(lum)))
1168 if (lum.lum_magic != LMV_USER_MAGIC)
1171 rc = ll_dir_setstripe(inode, (struct lov_user_md *)&lum, 0);
1175 case LL_IOC_LOV_SETSTRIPE: {
1176 struct lov_user_md_v3 lumv3;
1177 struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
1178 struct lov_user_md_v1 *lumv1p = (struct lov_user_md_v1 *)arg;
1179 struct lov_user_md_v3 *lumv3p = (struct lov_user_md_v3 *)arg;
1181 int set_default = 0;
1183 LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
1184 LASSERT(sizeof(lumv3.lmm_objects[0]) ==
1185 sizeof(lumv3p->lmm_objects[0]));
1186 /* first try with v1 which is smaller than v3 */
1187 if (copy_from_user(lumv1, lumv1p, sizeof(*lumv1)))
1190 if ((lumv1->lmm_magic == LOV_USER_MAGIC_V3) ) {
1191 if (copy_from_user(&lumv3, lumv3p, sizeof(lumv3)))
1195 if (inode->i_sb->s_root == file->f_dentry)
1198 /* in v1 and v3 cases lumv1 points to data */
1199 rc = ll_dir_setstripe(inode, lumv1, set_default);
1203 case LL_IOC_LMV_GETSTRIPE: {
1204 struct lmv_user_md __user *ulmv =
1205 (struct lmv_user_md __user *)arg;
1206 struct lmv_user_md lum;
1207 struct ptlrpc_request *request = NULL;
1208 union lmv_mds_md *lmm = NULL;
1210 obd_valid valid = 0;
1211 struct lmv_user_md *tmp = NULL;
1218 if (copy_from_user(&lum, ulmv, sizeof(*ulmv)))
1221 /* lum_magic will indicate which stripe the ioctl will like
1222 * to get, LMV_MAGIC_V1 is for normal LMV stripe, LMV_USER_MAGIC
1223 * is for default LMV stripe */
1224 if (lum.lum_magic == LMV_MAGIC_V1)
1225 valid |= OBD_MD_MEA;
1226 else if (lum.lum_magic == LMV_USER_MAGIC)
1227 valid |= OBD_MD_DEFAULT_MEA;
1231 rc = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize, &request,
1234 GOTO(finish_req, rc);
1236 /* Get default LMV EA */
1237 if (lum.lum_magic == LMV_USER_MAGIC) {
1239 GOTO(finish_req, rc);
1241 if (lmmsize > sizeof(*ulmv))
1242 GOTO(finish_req, rc = -EINVAL);
1244 if (copy_to_user(ulmv, lmm, lmmsize))
1245 GOTO(finish_req, rc = -EFAULT);
1247 GOTO(finish_req, rc);
1250 stripe_count = lmv_mds_md_stripe_count_get(lmm);
1251 lum_size = lmv_user_md_size(stripe_count, LMV_MAGIC_V1);
1252 OBD_ALLOC(tmp, lum_size);
1254 GOTO(finish_req, rc = -ENOMEM);
1256 mdt_index = ll_get_mdt_idx(inode);
1258 GOTO(out_tmp, rc = -ENOMEM);
1260 tmp->lum_magic = LMV_MAGIC_V1;
1261 tmp->lum_stripe_count = 0;
1262 tmp->lum_stripe_offset = mdt_index;
1263 for (i = 0; i < stripe_count; i++) {
1266 fid = &lmm->lmv_md_v1.lmv_stripe_fids[i];
1267 mdt_index = ll_get_mdt_idx_by_fid(sbi, fid);
1269 GOTO(out_tmp, rc = mdt_index);
1271 tmp->lum_objects[i].lum_mds = mdt_index;
1272 tmp->lum_objects[i].lum_fid = *fid;
1273 tmp->lum_stripe_count++;
1276 if (copy_to_user(ulmv, tmp, lum_size))
1277 GOTO(out_tmp, rc = -EFAULT);
1279 OBD_FREE(tmp, lum_size);
1281 ptlrpc_req_finished(request);
1285 case LL_IOC_REMOVE_ENTRY: {
1286 char *filename = NULL;
1290 /* Here is a little hack to avoid sending REINT_RMENTRY to
1291 * unsupported server, which might crash the server(LU-2730),
1292 * Because both LVB_TYPE and REINT_RMENTRY will be supported
1293 * on 2.4, we use OBD_CONNECT_LVB_TYPE to detect whether the
1294 * server will support REINT_RMENTRY XXX*/
1295 if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE))
1298 filename = ll_getname((const char *)arg);
1299 if (IS_ERR(filename))
1300 RETURN(PTR_ERR(filename));
1302 namelen = strlen(filename);
1304 GOTO(out_rmdir, rc = -EINVAL);
1306 rc = ll_rmdir_entry(inode, filename, namelen);
1309 ll_putname(filename);
1312 case LL_IOC_LOV_SWAP_LAYOUTS:
1314 case IOC_OBD_STATFS:
1315 RETURN(ll_obd_statfs(inode, (void *)arg));
1316 case LL_IOC_LOV_GETSTRIPE:
1317 case LL_IOC_MDC_GETINFO:
1318 case IOC_MDC_GETFILEINFO:
1319 case IOC_MDC_GETFILESTRIPE: {
1320 struct ptlrpc_request *request = NULL;
1321 struct lov_user_md *lump;
1322 struct lov_mds_md *lmm = NULL;
1323 struct mdt_body *body;
1324 char *filename = NULL;
1327 if (cmd == IOC_MDC_GETFILEINFO ||
1328 cmd == IOC_MDC_GETFILESTRIPE) {
1329 filename = ll_getname((const char *)arg);
1330 if (IS_ERR(filename))
1331 RETURN(PTR_ERR(filename));
1333 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1334 &lmmsize, &request);
1336 rc = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize,
1341 body = req_capsule_server_get(&request->rq_pill,
1343 LASSERT(body != NULL);
1349 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
1350 cmd == LL_IOC_MDC_GETINFO))
1351 GOTO(skip_lmm, rc = 0);
1356 if (cmd == IOC_MDC_GETFILESTRIPE ||
1357 cmd == LL_IOC_LOV_GETSTRIPE) {
1358 lump = (struct lov_user_md *)arg;
1360 struct lov_user_mds_data *lmdp;
1361 lmdp = (struct lov_user_mds_data *)arg;
1362 lump = &lmdp->lmd_lmm;
1364 if (copy_to_user(lump, lmm, lmmsize)) {
1365 if (copy_to_user(lump, lmm, sizeof(*lump)))
1366 GOTO(out_req, rc = -EFAULT);
1370 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
1371 struct lov_user_mds_data *lmdp;
1374 st.st_dev = inode->i_sb->s_dev;
1375 st.st_mode = body->mbo_mode;
1376 st.st_nlink = body->mbo_nlink;
1377 st.st_uid = body->mbo_uid;
1378 st.st_gid = body->mbo_gid;
1379 st.st_rdev = body->mbo_rdev;
1380 st.st_size = body->mbo_size;
1381 st.st_blksize = PAGE_CACHE_SIZE;
1382 st.st_blocks = body->mbo_blocks;
1383 st.st_atime = body->mbo_atime;
1384 st.st_mtime = body->mbo_mtime;
1385 st.st_ctime = body->mbo_ctime;
1386 st.st_ino = inode->i_ino;
1388 lmdp = (struct lov_user_mds_data *)arg;
1389 if (copy_to_user(&lmdp->lmd_st, &st, sizeof(st)))
1390 GOTO(out_req, rc = -EFAULT);
1395 ptlrpc_req_finished(request);
1397 ll_putname(filename);
1400 case IOC_LOV_GETINFO: {
1401 struct lov_user_mds_data *lumd;
1402 struct lov_stripe_md *lsm;
1403 struct lov_user_md *lum;
1404 struct lov_mds_md *lmm;
1408 lumd = (struct lov_user_mds_data *)arg;
1409 lum = &lumd->lmd_lmm;
1411 rc = ll_get_max_mdsize(sbi, &lmmsize);
1415 OBD_ALLOC_LARGE(lmm, lmmsize);
1419 if (copy_from_user(lmm, lum, lmmsize))
1420 GOTO(free_lmm, rc = -EFAULT);
1422 switch (lmm->lmm_magic) {
1423 case LOV_USER_MAGIC_V1:
1424 if (LOV_USER_MAGIC_V1 == cpu_to_le32(LOV_USER_MAGIC_V1))
1426 /* swab objects first so that stripes num will be sane */
1427 lustre_swab_lov_user_md_objects(
1428 ((struct lov_user_md_v1 *)lmm)->lmm_objects,
1429 ((struct lov_user_md_v1 *)lmm)->lmm_stripe_count);
1430 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
1432 case LOV_USER_MAGIC_V3:
1433 if (LOV_USER_MAGIC_V3 == cpu_to_le32(LOV_USER_MAGIC_V3))
1435 /* swab objects first so that stripes num will be sane */
1436 lustre_swab_lov_user_md_objects(
1437 ((struct lov_user_md_v3 *)lmm)->lmm_objects,
1438 ((struct lov_user_md_v3 *)lmm)->lmm_stripe_count);
1439 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
1442 GOTO(free_lmm, rc = -EINVAL);
1445 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
1447 GOTO(free_lmm, rc = -ENOMEM);
1449 /* Perform glimpse_size operation. */
1450 memset(&st, 0, sizeof(st));
1452 rc = ll_glimpse_ioctl(sbi, lsm, &st);
1456 if (copy_to_user(&lumd->lmd_st, &st, sizeof(st)))
1457 GOTO(free_lsm, rc = -EFAULT);
1461 obd_free_memmd(sbi->ll_dt_exp, &lsm);
1463 OBD_FREE_LARGE(lmm, lmmsize);
1466 case OBD_IOC_QUOTACHECK: {
1467 struct obd_quotactl *oqctl;
1470 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1471 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1474 OBD_ALLOC_PTR(oqctl);
1477 oqctl->qc_type = arg;
1478 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
1480 CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
1484 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
1486 CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
1488 OBD_FREE_PTR(oqctl);
1491 case OBD_IOC_POLL_QUOTACHECK: {
1492 struct if_quotacheck *check;
1494 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1495 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1498 OBD_ALLOC_PTR(check);
1502 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
1505 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
1506 if (copy_to_user((void *)arg, check,
1508 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1512 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
1515 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
1516 if (copy_to_user((void *)arg, check,
1518 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1522 OBD_FREE_PTR(check);
1525 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
1526 case LL_IOC_QUOTACTL_18: {
1527 /* copy the old 1.x quota struct for internal use, then copy
1528 * back into old format struct. For 1.8 compatibility. */
1529 struct if_quotactl_18 *qctl_18;
1530 struct if_quotactl *qctl_20;
1532 OBD_ALLOC_PTR(qctl_18);
1536 OBD_ALLOC_PTR(qctl_20);
1538 GOTO(out_quotactl_18, rc = -ENOMEM);
1540 if (copy_from_user(qctl_18, (void *)arg, sizeof(*qctl_18)))
1541 GOTO(out_quotactl_20, rc = -ENOMEM);
1543 QCTL_COPY(qctl_20, qctl_18);
1544 qctl_20->qc_idx = 0;
1546 /* XXX: dqb_valid was borrowed as a flag to mark that
1547 * only mds quota is wanted */
1548 if (qctl_18->qc_cmd == Q_GETQUOTA &&
1549 qctl_18->qc_dqblk.dqb_valid) {
1550 qctl_20->qc_valid = QC_MDTIDX;
1551 qctl_20->qc_dqblk.dqb_valid = 0;
1552 } else if (qctl_18->obd_uuid.uuid[0] != '\0') {
1553 qctl_20->qc_valid = QC_UUID;
1554 qctl_20->obd_uuid = qctl_18->obd_uuid;
1556 qctl_20->qc_valid = QC_GENERAL;
1559 rc = quotactl_ioctl(sbi, qctl_20);
1562 QCTL_COPY(qctl_18, qctl_20);
1563 qctl_18->obd_uuid = qctl_20->obd_uuid;
1565 if (copy_to_user((void *)arg, qctl_18,
1571 OBD_FREE_PTR(qctl_20);
1573 OBD_FREE_PTR(qctl_18);
1577 #warning "remove old LL_IOC_QUOTACTL_18 compatibility code"
1578 #endif /* LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0) */
1579 case OBD_IOC_QUOTACTL: {
1580 struct if_quotactl *qctl;
1582 OBD_ALLOC_PTR(qctl);
1586 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
1587 GOTO(out_quotactl, rc = -EFAULT);
1589 rc = quotactl_ioctl(sbi, qctl);
1591 if (rc == 0 && copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1598 case OBD_IOC_GETDTNAME:
1599 case OBD_IOC_GETMDNAME:
1600 RETURN(ll_get_obd_name(inode, cmd, arg));
1601 case LL_IOC_FLUSHCTX:
1602 RETURN(ll_flush_ctx(inode));
1603 #ifdef CONFIG_FS_POSIX_ACL
1604 case LL_IOC_RMTACL: {
1605 if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
1606 inode == inode->i_sb->s_root->d_inode) {
1607 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1609 LASSERT(fd != NULL);
1610 rc = rct_add(&sbi->ll_rct, current_pid(), arg);
1612 fd->fd_flags |= LL_FILE_RMTACL;
1618 case LL_IOC_GETOBDCOUNT: {
1620 struct obd_export *exp;
1622 if (copy_from_user(&count, (int *)arg, sizeof(int)))
1625 /* get ost count when count is zero, get mdt count otherwise */
1626 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
1627 vallen = sizeof(count);
1628 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
1629 KEY_TGT_COUNT, &vallen, &count, NULL);
1631 CERROR("get target count failed: %d\n", rc);
1635 if (copy_to_user((int *)arg, &count, sizeof(int)))
1640 case LL_IOC_PATH2FID:
1641 if (copy_to_user((void *)arg, ll_inode2fid(inode),
1642 sizeof(struct lu_fid)))
1645 case LL_IOC_GET_CONNECT_FLAGS: {
1646 RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL, (void*)arg));
1648 case OBD_IOC_CHANGELOG_SEND:
1649 case OBD_IOC_CHANGELOG_CLEAR:
1650 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void *)arg,
1651 sizeof(struct ioc_changelog));
1653 case OBD_IOC_FID2PATH:
1654 RETURN(ll_fid2path(inode, (void *)arg));
1655 case LL_IOC_FID2MDTIDX: {
1656 struct obd_export *exp = ll_i2mdexp(inode);
1660 if (copy_from_user(&fid, (const struct lu_fid __user *)arg,
1664 /* Call mdc_iocontrol */
1665 rc = obd_iocontrol(LL_IOC_FID2MDTIDX, exp, sizeof(fid), &fid,
1672 case LL_IOC_HSM_REQUEST: {
1673 struct hsm_user_request *hur;
1680 /* We don't know the true size yet; copy the fixed-size part */
1681 if (copy_from_user(hur, (void *)arg, sizeof(*hur))) {
1686 /* Compute the whole struct size */
1687 totalsize = hur_len(hur);
1692 /* Final size will be more than double totalsize */
1693 if (totalsize >= MDS_MAXREQSIZE / 3)
1696 OBD_ALLOC_LARGE(hur, totalsize);
1700 /* Copy the whole struct */
1701 if (copy_from_user(hur, (void *)arg, totalsize)) {
1702 OBD_FREE_LARGE(hur, totalsize);
1706 if (hur->hur_request.hr_action == HUA_RELEASE) {
1707 const struct lu_fid *fid;
1711 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
1712 fid = &hur->hur_user_item[i].hui_fid;
1713 f = search_inode_for_lustre(inode->i_sb, fid);
1719 rc = ll_hsm_release(f);
1725 rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
1729 OBD_FREE_LARGE(hur, totalsize);
1733 case LL_IOC_HSM_PROGRESS: {
1734 struct hsm_progress_kernel hpk;
1735 struct hsm_progress hp;
1737 if (copy_from_user(&hp, (void *)arg, sizeof(hp)))
1740 hpk.hpk_fid = hp.hp_fid;
1741 hpk.hpk_cookie = hp.hp_cookie;
1742 hpk.hpk_extent = hp.hp_extent;
1743 hpk.hpk_flags = hp.hp_flags;
1744 hpk.hpk_errval = hp.hp_errval;
1745 hpk.hpk_data_version = 0;
1747 /* File may not exist in Lustre; all progress
1748 * reported to Lustre root */
1749 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
1753 case LL_IOC_HSM_CT_START:
1754 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
1757 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void *)arg,
1758 sizeof(struct lustre_kernelcomm));
1761 case LL_IOC_HSM_COPY_START: {
1762 struct hsm_copy *copy;
1765 OBD_ALLOC_PTR(copy);
1768 if (copy_from_user(copy, (char *)arg, sizeof(*copy))) {
1773 rc = ll_ioc_copy_start(inode->i_sb, copy);
1774 if (copy_to_user((char *)arg, copy, sizeof(*copy)))
1780 case LL_IOC_HSM_COPY_END: {
1781 struct hsm_copy *copy;
1784 OBD_ALLOC_PTR(copy);
1787 if (copy_from_user(copy, (char *)arg, sizeof(*copy))) {
1792 rc = ll_ioc_copy_end(inode->i_sb, copy);
1793 if (copy_to_user((char *)arg, copy, sizeof(*copy)))
1799 case LL_IOC_MIGRATE: {
1801 const char *filename;
1807 rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
1811 data = (struct obd_ioctl_data *)buf;
1812 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1813 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1814 GOTO(migrate_free, rc = -EINVAL);
1816 filename = data->ioc_inlbuf1;
1817 namelen = data->ioc_inllen1;
1818 /* \0 is packed at the end of filename */
1819 if (namelen < 1 || namelen != strlen(filename) + 1)
1820 GOTO(migrate_free, rc = -EINVAL);
1822 if (data->ioc_inllen2 != sizeof(mdtidx))
1823 GOTO(migrate_free, rc = -EINVAL);
1824 mdtidx = *(int *)data->ioc_inlbuf2;
1826 rc = ll_migrate(inode, file, mdtidx, filename, namelen - 1);
1828 obd_ioctl_freedata(buf, len);
1833 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL,
1838 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
1840 struct inode *inode = file->f_mapping->host;
1841 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1842 struct ll_sb_info *sbi = ll_i2sbi(inode);
1843 int api32 = ll_need_32bit_api(sbi);
1844 loff_t ret = -EINVAL;
1847 mutex_lock(&inode->i_mutex);
1852 offset += file->f_pos;
1858 offset += LL_DIR_END_OFF_32BIT;
1860 offset += LL_DIR_END_OFF;
1867 ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
1868 (!api32 && offset <= LL_DIR_END_OFF))) {
1869 if (offset != file->f_pos) {
1870 if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
1871 (!api32 && offset == LL_DIR_END_OFF))
1872 fd->lfd_pos = MDS_DIR_END_OFF;
1873 else if (api32 && sbi->ll_flags & LL_SBI_64BIT_HASH)
1874 fd->lfd_pos = offset << 32;
1876 fd->lfd_pos = offset;
1877 file->f_pos = offset;
1878 file->f_version = 0;
1885 mutex_unlock(&inode->i_mutex);
1889 static int ll_dir_open(struct inode *inode, struct file *file)
1892 RETURN(ll_file_open(inode, file));
1895 static int ll_dir_release(struct inode *inode, struct file *file)
1898 RETURN(ll_file_release(inode, file));
1901 const struct file_operations ll_dir_operations = {
1902 .llseek = ll_dir_seek,
1903 .open = ll_dir_open,
1904 .release = ll_dir_release,
1905 .read = generic_read_dir,
1906 #ifdef HAVE_DIR_CONTEXT
1907 .iterate = ll_iterate,
1909 .readdir = ll_readdir,
1911 .unlocked_ioctl = ll_dir_ioctl,