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 * lmv_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 done = filldir(cookie, ent->lde_name, namelen, lhash,
255 ll_release_page(inode, page, false);
259 next = le64_to_cpu(dp->ldp_hash_end);
261 if (pos == MDS_DIR_END_OFF) {
263 * End of directory reached.
266 ll_release_page(inode, page, false);
269 * Normal case: continue to the next
272 ll_release_page(inode, page,
273 le32_to_cpu(dp->ldp_flags) &
276 page = ll_get_dir_page(inode, op_data, pos,
282 ll_dir_chain_fini(&chain);
286 #ifdef HAVE_DIR_CONTEXT
287 static int ll_iterate(struct file *filp, struct dir_context *ctx)
289 static int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
292 struct inode *inode = filp->f_dentry->d_inode;
293 struct ll_file_data *lfd = LUSTRE_FPRIVATE(filp);
294 struct ll_sb_info *sbi = ll_i2sbi(inode);
295 int hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
296 int api32 = ll_need_32bit_api(sbi);
297 struct md_op_data *op_data;
307 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) pos/size"
308 "%lu/%llu 32bit_api %d\n", PFID(ll_inode2fid(inode)),
309 inode, (unsigned long)pos, i_size_read(inode), api32);
311 if (pos == MDS_DIR_END_OFF)
317 op_data = ll_prep_md_op_data(NULL, inode, inode, NULL, 0, 0,
318 LUSTRE_OPC_ANY, inode);
320 GOTO(out, rc = PTR_ERR(op_data));
322 if (unlikely(op_data->op_mea1 != NULL)) {
323 /* This is only needed for striped dir to fill ..,
324 * see lmv_read_entry */
325 if (filp->f_dentry->d_parent != NULL &&
326 filp->f_dentry->d_parent->d_inode != NULL) {
327 __u64 ibits = MDS_INODELOCK_UPDATE;
328 struct inode *parent =
329 filp->f_dentry->d_parent->d_inode;
331 if (ll_have_md_lock(parent, &ibits, LCK_MINMODE))
332 op_data->op_fid3 = *ll_inode2fid(parent);
335 /* If it can not find in cache, do lookup .. on the master
337 if (fid_is_zero(&op_data->op_fid3)) {
338 rc = ll_dir_get_parent_fid(inode, &op_data->op_fid3);
340 ll_finish_md_op_data(op_data);
345 op_data->op_max_pages = sbi->ll_md_brw_pages;
346 #ifdef HAVE_DIR_CONTEXT
348 rc = ll_dir_read(inode, &pos, op_data, ctx);
351 rc = ll_dir_read(inode, &pos, op_data, cookie, filldir);
356 if (pos == MDS_DIR_END_OFF) {
358 pos = LL_DIR_END_OFF_32BIT;
360 pos = LL_DIR_END_OFF;
365 #ifdef HAVE_DIR_CONTEXT
370 ll_finish_md_op_data(op_data);
371 filp->f_version = inode->i_version;
375 ll_stats_ops_tally(sbi, LPROC_LL_READDIR, 1);
380 static int ll_send_mgc_param(struct obd_export *mgc, char *string)
382 struct mgs_send_param *msp;
389 strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN);
390 rc = obd_set_info_async(NULL, mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
391 sizeof(struct mgs_send_param), msp, NULL);
393 CERROR("Failed to set parameter: %d\n", rc);
400 * Create striped directory with specified stripe(@lump)
402 * param[in]parent the parent of the directory.
403 * param[in]lump the specified stripes.
404 * param[in]dirname the name of the directory.
405 * param[in]mode the specified mode of the directory.
407 * retval =0 if striped directory is being created successfully.
408 * <0 if the creation is failed.
410 static int ll_dir_setdirstripe(struct inode *parent, struct lmv_user_md *lump,
411 const char *dirname, umode_t mode)
413 struct ptlrpc_request *request = NULL;
414 struct md_op_data *op_data;
415 struct ll_sb_info *sbi = ll_i2sbi(parent);
419 if (unlikely(lump->lum_magic != LMV_USER_MAGIC))
422 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) name %s"
423 "stripe_offset %d, stripe_count: %u\n",
424 PFID(ll_inode2fid(parent)), parent, dirname,
425 (int)lump->lum_stripe_offset, lump->lum_stripe_count);
427 if (lump->lum_magic != cpu_to_le32(LMV_USER_MAGIC))
428 lustre_swab_lmv_user_md(lump);
430 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
431 mode &= ~current_umask();
432 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
433 op_data = ll_prep_md_op_data(NULL, parent, NULL, dirname,
434 strlen(dirname), mode, LUSTRE_OPC_MKDIR,
437 GOTO(err_exit, err = PTR_ERR(op_data));
439 op_data->op_cli_flags |= CLI_SET_MEA;
440 err = md_create(sbi->ll_md_exp, op_data, lump, sizeof(*lump), mode,
441 from_kuid(&init_user_ns, current_fsuid()),
442 from_kgid(&init_user_ns, current_fsgid()),
443 cfs_curproc_cap_pack(), 0, &request);
444 ll_finish_md_op_data(op_data);
448 ptlrpc_req_finished(request);
452 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
455 struct ll_sb_info *sbi = ll_i2sbi(inode);
456 struct md_op_data *op_data;
457 struct ptlrpc_request *req = NULL;
459 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
460 struct obd_device *mgc = lsi->lsi_mgc;
466 * This is coming from userspace, so should be in
467 * local endian. But the MDS would like it in little
468 * endian, so we swab it before we send it.
470 switch (lump->lmm_magic) {
471 case LOV_USER_MAGIC_V1: {
472 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V1))
473 lustre_swab_lov_user_md_v1(lump);
474 lum_size = sizeof(struct lov_user_md_v1);
477 case LOV_USER_MAGIC_V3: {
478 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V3))
479 lustre_swab_lov_user_md_v3(
480 (struct lov_user_md_v3 *)lump);
481 lum_size = sizeof(struct lov_user_md_v3);
484 case LMV_USER_MAGIC: {
485 if (lump->lmm_magic != cpu_to_le32(LMV_USER_MAGIC))
486 lustre_swab_lmv_user_md(
487 (struct lmv_user_md *)lump);
488 lum_size = sizeof(struct lmv_user_md);
492 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
493 " %#08x != %#08x nor %#08x\n",
494 lump->lmm_magic, LOV_USER_MAGIC_V1,
500 lum_size = sizeof(struct lov_user_md_v1);
503 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
504 LUSTRE_OPC_ANY, NULL);
506 RETURN(PTR_ERR(op_data));
508 /* swabbing is done in lov_setstripe() on server side */
509 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size,
510 NULL, 0, &req, NULL);
511 ll_finish_md_op_data(op_data);
512 ptlrpc_req_finished(req);
514 if (rc != -EPERM && rc != -EACCES)
515 CERROR("mdc_setattr fails: rc = %d\n", rc);
518 /* In the following we use the fact that LOV_USER_MAGIC_V1 and
519 LOV_USER_MAGIC_V3 have the same initial fields so we do not
520 need the make the distiction between the 2 versions */
521 if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
525 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
527 GOTO(end, rc = -ENOMEM);
530 /* Get fsname and assume devname to be -MDT0000. */
531 ll_get_fsname(inode->i_sb, buf, MTI_NAME_MAXLEN);
532 strcat(buf, "-MDT0000.lov");
535 /* Set root stripesize */
536 sprintf(buf, ".stripesize=%u",
537 lump ? le32_to_cpu(lump->lmm_stripe_size) : 0);
538 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
542 /* Set root stripecount */
543 sprintf(buf, ".stripecount=%hd",
544 lump ? le16_to_cpu(lump->lmm_stripe_count) : 0);
545 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
549 /* Set root stripeoffset */
550 sprintf(buf, ".stripeoffset=%hd",
551 lump ? le16_to_cpu(lump->lmm_stripe_offset) :
552 (typeof(lump->lmm_stripe_offset))(-1));
553 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
557 OBD_FREE(param, MGS_PARAM_MAXLEN);
563 * This function will be used to get default LOV/LMV/Default LMV
564 * @valid will be used to indicate which stripe it will retrieve
565 * OBD_MD_MEA LMV stripe EA
566 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
567 * otherwise Default LOV EA.
568 * Each time, it can only retrieve 1 stripe EA
570 int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
571 struct ptlrpc_request **request, obd_valid valid)
573 struct ll_sb_info *sbi = ll_i2sbi(inode);
574 struct mdt_body *body;
575 struct lov_mds_md *lmm = NULL;
576 struct ptlrpc_request *req = NULL;
578 struct md_op_data *op_data;
581 rc = ll_get_default_mdsize(sbi, &lmm_size);
585 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
586 0, lmm_size, LUSTRE_OPC_ANY,
589 RETURN(PTR_ERR(op_data));
591 op_data->op_valid = valid | OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
592 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
593 ll_finish_md_op_data(op_data);
595 CDEBUG(D_INFO, "md_getattr failed on inode "
596 DFID": rc %d\n", PFID(ll_inode2fid(inode)), rc);
600 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
601 LASSERT(body != NULL);
603 lmm_size = body->mbo_eadatasize;
605 if (!(body->mbo_valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
607 GOTO(out, rc = -ENODATA);
610 lmm = req_capsule_server_sized_get(&req->rq_pill,
611 &RMF_MDT_MD, lmm_size);
612 LASSERT(lmm != NULL);
615 * This is coming from the MDS, so is probably in
616 * little endian. We convert it to host endian before
617 * passing it to userspace.
619 /* We don't swab objects for directories */
620 switch (le32_to_cpu(lmm->lmm_magic)) {
622 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
623 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
626 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
627 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
630 if (LMV_MAGIC != cpu_to_le32(LMV_MAGIC))
631 lustre_swab_lmv_mds_md((union lmv_mds_md *)lmm);
634 if (LMV_USER_MAGIC != cpu_to_le32(LMV_USER_MAGIC))
635 lustre_swab_lmv_user_md((struct lmv_user_md *)lmm);
638 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
643 *plmm_size = lmm_size;
648 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid)
650 struct md_op_data *op_data;
655 OBD_ALLOC_PTR(op_data);
659 op_data->op_flags |= MF_GET_MDT_IDX;
660 op_data->op_fid1 = *fid;
661 rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
662 mdt_index = op_data->op_mds;
663 OBD_FREE_PTR(op_data);
671 * Get MDT index for the inode.
673 int ll_get_mdt_idx(struct inode *inode)
675 return ll_get_mdt_idx_by_fid(ll_i2sbi(inode), ll_inode2fid(inode));
679 * Generic handler to do any pre-copy work.
681 * It send a first hsm_progress (with extent length == 0) to coordinator as a
682 * first information for it that real work has started.
684 * Moreover, for a ARCHIVE request, it will sample the file data version and
685 * store it in \a copy.
687 * \return 0 on success.
689 static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
691 struct ll_sb_info *sbi = ll_s2sbi(sb);
692 struct hsm_progress_kernel hpk;
696 /* Forge a hsm_progress based on data from copy. */
697 hpk.hpk_fid = copy->hc_hai.hai_fid;
698 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
699 hpk.hpk_extent.offset = copy->hc_hai.hai_extent.offset;
700 hpk.hpk_extent.length = 0;
703 hpk.hpk_data_version = 0;
706 /* For archive request, we need to read the current file version. */
707 if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
709 __u64 data_version = 0;
711 /* Get inode for this fid */
712 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
714 hpk.hpk_flags |= HP_FLAG_RETRY;
715 /* hpk_errval is >= 0 */
716 hpk.hpk_errval = -PTR_ERR(inode);
717 GOTO(progress, rc = PTR_ERR(inode));
720 /* Read current file data version */
721 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
724 CDEBUG(D_HSM, "Could not read file data version of "
725 DFID" (rc = %d). Archive request ("
726 LPX64") could not be done.\n",
727 PFID(©->hc_hai.hai_fid), rc,
728 copy->hc_hai.hai_cookie);
729 hpk.hpk_flags |= HP_FLAG_RETRY;
730 /* hpk_errval must be >= 0 */
731 hpk.hpk_errval = -rc;
735 /* Store it the hsm_copy for later copytool use.
736 * Always modified even if no lsm. */
737 copy->hc_data_version = data_version;
741 /* On error, the request should be considered as completed */
742 if (hpk.hpk_errval > 0)
743 hpk.hpk_flags |= HP_FLAG_COMPLETED;
744 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
751 * Generic handler to do any post-copy work.
753 * It will send the last hsm_progress update to coordinator to inform it
754 * that copy is finished and whether it was successful or not.
757 * - for ARCHIVE request, it will sample the file data version and compare it
758 * with the version saved in ll_ioc_copy_start(). If they do not match, copy
759 * will be considered as failed.
760 * - for RESTORE request, it will sample the file data version and send it to
761 * coordinator which is useful if the file was imported as 'released'.
763 * \return 0 on success.
765 static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
767 struct ll_sb_info *sbi = ll_s2sbi(sb);
768 struct hsm_progress_kernel hpk;
772 /* If you modify the logic here, also check llapi_hsm_copy_end(). */
773 /* Take care: copy->hc_hai.hai_action, len, gid and data are not
774 * initialized if copy_end was called with copy == NULL.
777 /* Forge a hsm_progress based on data from copy. */
778 hpk.hpk_fid = copy->hc_hai.hai_fid;
779 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
780 hpk.hpk_extent = copy->hc_hai.hai_extent;
781 hpk.hpk_flags = copy->hc_flags | HP_FLAG_COMPLETED;
782 hpk.hpk_errval = copy->hc_errval;
783 hpk.hpk_data_version = 0;
785 /* For archive request, we need to check the file data was not changed.
787 * For restore request, we need to send the file data version, this is
788 * useful when the file was created using hsm_import.
790 if (((copy->hc_hai.hai_action == HSMA_ARCHIVE) ||
791 (copy->hc_hai.hai_action == HSMA_RESTORE)) &&
792 (copy->hc_errval == 0)) {
794 __u64 data_version = 0;
796 /* Get lsm for this fid */
797 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
799 hpk.hpk_flags |= HP_FLAG_RETRY;
800 /* hpk_errval must be >= 0 */
801 hpk.hpk_errval = -PTR_ERR(inode);
802 GOTO(progress, rc = PTR_ERR(inode));
805 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
808 CDEBUG(D_HSM, "Could not read file data version. "
809 "Request could not be confirmed.\n");
810 if (hpk.hpk_errval == 0)
811 hpk.hpk_errval = -rc;
815 /* Store it the hsm_copy for later copytool use.
816 * Always modified even if no lsm. */
817 hpk.hpk_data_version = data_version;
819 /* File could have been stripped during archiving, so we need
820 * to check anyway. */
821 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
822 (copy->hc_data_version != data_version)) {
823 CDEBUG(D_HSM, "File data version mismatched. "
824 "File content was changed during archiving. "
825 DFID", start:"LPX64" current:"LPX64"\n",
826 PFID(©->hc_hai.hai_fid),
827 copy->hc_data_version, data_version);
828 /* File was changed, send error to cdt. Do not ask for
829 * retry because if a file is modified frequently,
830 * the cdt will loop on retried archive requests.
831 * The policy engine will ask for a new archive later
832 * when the file will not be modified for some tunable
834 /* we do not notify caller */
835 hpk.hpk_flags &= ~HP_FLAG_RETRY;
836 /* hpk_errval must be >= 0 */
837 hpk.hpk_errval = EBUSY;
843 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
850 static int copy_and_ioctl(int cmd, struct obd_export *exp,
851 const void __user *data, size_t size)
856 OBD_ALLOC(copy, size);
860 if (copy_from_user(copy, data, size)) {
865 rc = obd_iocontrol(cmd, exp, size, copy, NULL);
867 OBD_FREE(copy, size);
872 static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
874 int cmd = qctl->qc_cmd;
875 int type = qctl->qc_type;
876 int id = qctl->qc_id;
877 int valid = qctl->qc_valid;
882 case LUSTRE_Q_INVALIDATE:
883 case LUSTRE_Q_FINVALIDATE:
888 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
889 sbi->ll_flags & LL_SBI_RMT_CLIENT)
893 if (((type == USRQUOTA &&
894 !uid_eq(current_euid(), make_kuid(&init_user_ns, id))) ||
896 !in_egroup_p(make_kgid(&init_user_ns, id)))) &&
897 (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
898 sbi->ll_flags & LL_SBI_RMT_CLIENT))
904 CERROR("unsupported quotactl op: %#x\n", cmd);
908 if (valid != QC_GENERAL) {
909 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
912 if (cmd == Q_GETINFO)
913 qctl->qc_cmd = Q_GETOINFO;
914 else if (cmd == Q_GETQUOTA)
915 qctl->qc_cmd = Q_GETOQUOTA;
921 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
922 sizeof(*qctl), qctl, NULL);
925 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
926 sizeof(*qctl), qctl, NULL);
929 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
930 sizeof(*qctl), qctl, NULL);
932 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
934 sizeof(*qctl), qctl, NULL);
946 struct obd_quotactl *oqctl;
948 OBD_ALLOC_PTR(oqctl);
952 QCTL_COPY(oqctl, qctl);
953 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
955 if (rc != -EALREADY && cmd == Q_QUOTAON) {
956 oqctl->qc_cmd = Q_QUOTAOFF;
957 obd_quotactl(sbi->ll_md_exp, oqctl);
962 /* If QIF_SPACE is not set, client should collect the
963 * space usage from OSSs by itself */
964 if (cmd == Q_GETQUOTA &&
965 !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
966 !oqctl->qc_dqblk.dqb_curspace) {
967 struct obd_quotactl *oqctl_tmp;
969 OBD_ALLOC_PTR(oqctl_tmp);
970 if (oqctl_tmp == NULL)
971 GOTO(out, rc = -ENOMEM);
973 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
974 oqctl_tmp->qc_id = oqctl->qc_id;
975 oqctl_tmp->qc_type = oqctl->qc_type;
977 /* collect space usage from OSTs */
978 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
979 rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
980 if (!rc || rc == -EREMOTEIO) {
981 oqctl->qc_dqblk.dqb_curspace =
982 oqctl_tmp->qc_dqblk.dqb_curspace;
983 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
986 /* collect space & inode usage from MDTs */
987 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
988 oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
989 rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
990 if (!rc || rc == -EREMOTEIO) {
991 oqctl->qc_dqblk.dqb_curspace +=
992 oqctl_tmp->qc_dqblk.dqb_curspace;
993 oqctl->qc_dqblk.dqb_curinodes =
994 oqctl_tmp->qc_dqblk.dqb_curinodes;
995 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
997 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
1000 OBD_FREE_PTR(oqctl_tmp);
1003 QCTL_COPY(qctl, oqctl);
1004 OBD_FREE_PTR(oqctl);
1011 ll_getname(const char __user *filename)
1014 char *tmp = __getname();
1017 return ERR_PTR(-ENOMEM);
1019 len = strncpy_from_user(tmp, filename, PATH_MAX);
1022 else if (len > PATH_MAX)
1023 ret = -ENAMETOOLONG;
1032 #define ll_putname(filename) __putname(filename)
1034 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1036 struct inode *inode = file->f_dentry->d_inode;
1037 struct ll_sb_info *sbi = ll_i2sbi(inode);
1038 struct obd_ioctl_data *data;
1042 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%#x\n",
1043 PFID(ll_inode2fid(inode)), inode, cmd);
1045 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
1046 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
1049 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
1051 case FSFILT_IOC_GETFLAGS:
1052 case FSFILT_IOC_SETFLAGS:
1053 RETURN(ll_iocontrol(inode, file, cmd, arg));
1054 case FSFILT_IOC_GETVERSION_OLD:
1055 case FSFILT_IOC_GETVERSION:
1056 RETURN(put_user(inode->i_generation, (int *)arg));
1057 /* We need to special case any other ioctls we want to handle,
1058 * to send them to the MDS/OST as appropriate and to properly
1059 * network encode the arg field.
1060 case FSFILT_IOC_SETVERSION_OLD:
1061 case FSFILT_IOC_SETVERSION:
1063 case LL_IOC_GET_MDTIDX: {
1066 mdtidx = ll_get_mdt_idx(inode);
1070 if (put_user((int)mdtidx, (int*)arg))
1075 case IOC_MDC_LOOKUP: {
1076 int namelen, len = 0;
1080 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
1085 filename = data->ioc_inlbuf1;
1086 namelen = strlen(filename);
1088 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1089 GOTO(out_free, rc = -EINVAL);
1092 rc = ll_get_fid_by_name(inode, filename, namelen, NULL);
1094 CERROR("%s: lookup %.*s failed: rc = %d\n",
1095 ll_get_fsname(inode->i_sb, NULL, 0), namelen,
1100 obd_ioctl_freedata(buf, len);
1103 case LL_IOC_LMV_SETSTRIPE: {
1104 struct lmv_user_md *lum;
1113 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
1118 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1119 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1120 GOTO(lmv_out_free, rc = -EINVAL);
1122 filename = data->ioc_inlbuf1;
1123 namelen = data->ioc_inllen1;
1126 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1127 GOTO(lmv_out_free, rc = -EINVAL);
1129 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1130 lumlen = data->ioc_inllen2;
1132 if (lum->lum_magic != LMV_USER_MAGIC ||
1133 lumlen != sizeof(*lum)) {
1134 CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1135 filename, lum->lum_magic, lumlen, -EFAULT);
1136 GOTO(lmv_out_free, rc = -EINVAL);
1139 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 50, 0)
1140 mode = data->ioc_type != 0 ? data->ioc_type : S_IRWXUGO;
1142 mode = data->ioc_type;
1144 rc = ll_dir_setdirstripe(inode, lum, filename, mode);
1146 obd_ioctl_freedata(buf, len);
1150 case LL_IOC_LMV_SET_DEFAULT_STRIPE: {
1151 struct lmv_user_md lum;
1152 struct lmv_user_md __user *ulump =
1153 (struct lmv_user_md __user *)arg;
1156 if (copy_from_user(&lum, ulump, sizeof(lum)))
1159 if (lum.lum_magic != LMV_USER_MAGIC)
1162 rc = ll_dir_setstripe(inode, (struct lov_user_md *)&lum, 0);
1166 case LL_IOC_LOV_SETSTRIPE: {
1167 struct lov_user_md_v3 lumv3;
1168 struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
1169 struct lov_user_md_v1 *lumv1p = (struct lov_user_md_v1 *)arg;
1170 struct lov_user_md_v3 *lumv3p = (struct lov_user_md_v3 *)arg;
1172 int set_default = 0;
1174 LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
1175 LASSERT(sizeof(lumv3.lmm_objects[0]) ==
1176 sizeof(lumv3p->lmm_objects[0]));
1177 /* first try with v1 which is smaller than v3 */
1178 if (copy_from_user(lumv1, lumv1p, sizeof(*lumv1)))
1181 if ((lumv1->lmm_magic == LOV_USER_MAGIC_V3) ) {
1182 if (copy_from_user(&lumv3, lumv3p, sizeof(lumv3)))
1186 if (inode->i_sb->s_root == file->f_dentry)
1189 /* in v1 and v3 cases lumv1 points to data */
1190 rc = ll_dir_setstripe(inode, lumv1, set_default);
1194 case LL_IOC_LMV_GETSTRIPE: {
1195 struct lmv_user_md __user *ulmv =
1196 (struct lmv_user_md __user *)arg;
1197 struct lmv_user_md lum;
1198 struct ptlrpc_request *request = NULL;
1199 union lmv_mds_md *lmm = NULL;
1201 obd_valid valid = 0;
1202 struct lmv_user_md *tmp = NULL;
1209 if (copy_from_user(&lum, ulmv, sizeof(*ulmv)))
1212 /* lum_magic will indicate which stripe the ioctl will like
1213 * to get, LMV_MAGIC_V1 is for normal LMV stripe, LMV_USER_MAGIC
1214 * is for default LMV stripe */
1215 if (lum.lum_magic == LMV_MAGIC_V1)
1216 valid |= OBD_MD_MEA;
1217 else if (lum.lum_magic == LMV_USER_MAGIC)
1218 valid |= OBD_MD_DEFAULT_MEA;
1222 rc = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize, &request,
1225 GOTO(finish_req, rc);
1227 /* Get default LMV EA */
1228 if (lum.lum_magic == LMV_USER_MAGIC) {
1230 GOTO(finish_req, rc);
1232 if (lmmsize > sizeof(*ulmv))
1233 GOTO(finish_req, rc = -EINVAL);
1235 if (copy_to_user(ulmv, lmm, lmmsize))
1236 GOTO(finish_req, rc = -EFAULT);
1238 GOTO(finish_req, rc);
1241 stripe_count = lmv_mds_md_stripe_count_get(lmm);
1242 lum_size = lmv_user_md_size(stripe_count, LMV_MAGIC_V1);
1243 OBD_ALLOC(tmp, lum_size);
1245 GOTO(finish_req, rc = -ENOMEM);
1247 mdt_index = ll_get_mdt_idx(inode);
1249 GOTO(out_tmp, rc = -ENOMEM);
1251 tmp->lum_magic = LMV_MAGIC_V1;
1252 tmp->lum_stripe_count = 0;
1253 tmp->lum_stripe_offset = mdt_index;
1254 for (i = 0; i < stripe_count; i++) {
1257 fid = &lmm->lmv_md_v1.lmv_stripe_fids[i];
1258 mdt_index = ll_get_mdt_idx_by_fid(sbi, fid);
1260 GOTO(out_tmp, rc = mdt_index);
1262 tmp->lum_objects[i].lum_mds = mdt_index;
1263 tmp->lum_objects[i].lum_fid = *fid;
1264 tmp->lum_stripe_count++;
1267 if (copy_to_user(ulmv, tmp, lum_size))
1268 GOTO(out_tmp, rc = -EFAULT);
1270 OBD_FREE(tmp, lum_size);
1272 ptlrpc_req_finished(request);
1276 case LL_IOC_REMOVE_ENTRY: {
1277 char *filename = NULL;
1281 /* Here is a little hack to avoid sending REINT_RMENTRY to
1282 * unsupported server, which might crash the server(LU-2730),
1283 * Because both LVB_TYPE and REINT_RMENTRY will be supported
1284 * on 2.4, we use OBD_CONNECT_LVB_TYPE to detect whether the
1285 * server will support REINT_RMENTRY XXX*/
1286 if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE))
1289 filename = ll_getname((const char *)arg);
1290 if (IS_ERR(filename))
1291 RETURN(PTR_ERR(filename));
1293 namelen = strlen(filename);
1295 GOTO(out_rmdir, rc = -EINVAL);
1297 rc = ll_rmdir_entry(inode, filename, namelen);
1300 ll_putname(filename);
1303 case LL_IOC_LOV_SWAP_LAYOUTS:
1305 case IOC_OBD_STATFS:
1306 RETURN(ll_obd_statfs(inode, (void *)arg));
1307 case LL_IOC_LOV_GETSTRIPE:
1308 case LL_IOC_MDC_GETINFO:
1309 case IOC_MDC_GETFILEINFO:
1310 case IOC_MDC_GETFILESTRIPE: {
1311 struct ptlrpc_request *request = NULL;
1312 struct lov_user_md *lump;
1313 struct lov_mds_md *lmm = NULL;
1314 struct mdt_body *body;
1315 char *filename = NULL;
1318 if (cmd == IOC_MDC_GETFILEINFO ||
1319 cmd == IOC_MDC_GETFILESTRIPE) {
1320 filename = ll_getname((const char *)arg);
1321 if (IS_ERR(filename))
1322 RETURN(PTR_ERR(filename));
1324 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1325 &lmmsize, &request);
1327 rc = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize,
1332 body = req_capsule_server_get(&request->rq_pill,
1334 LASSERT(body != NULL);
1340 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
1341 cmd == LL_IOC_MDC_GETINFO))
1342 GOTO(skip_lmm, rc = 0);
1347 if (cmd == IOC_MDC_GETFILESTRIPE ||
1348 cmd == LL_IOC_LOV_GETSTRIPE) {
1349 lump = (struct lov_user_md *)arg;
1351 struct lov_user_mds_data *lmdp;
1352 lmdp = (struct lov_user_mds_data *)arg;
1353 lump = &lmdp->lmd_lmm;
1355 if (copy_to_user(lump, lmm, lmmsize)) {
1356 if (copy_to_user(lump, lmm, sizeof(*lump)))
1357 GOTO(out_req, rc = -EFAULT);
1361 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
1362 struct lov_user_mds_data *lmdp;
1365 st.st_dev = inode->i_sb->s_dev;
1366 st.st_mode = body->mbo_mode;
1367 st.st_nlink = body->mbo_nlink;
1368 st.st_uid = body->mbo_uid;
1369 st.st_gid = body->mbo_gid;
1370 st.st_rdev = body->mbo_rdev;
1371 st.st_size = body->mbo_size;
1372 st.st_blksize = PAGE_CACHE_SIZE;
1373 st.st_blocks = body->mbo_blocks;
1374 st.st_atime = body->mbo_atime;
1375 st.st_mtime = body->mbo_mtime;
1376 st.st_ctime = body->mbo_ctime;
1377 st.st_ino = inode->i_ino;
1379 lmdp = (struct lov_user_mds_data *)arg;
1380 if (copy_to_user(&lmdp->lmd_st, &st, sizeof(st)))
1381 GOTO(out_req, rc = -EFAULT);
1386 ptlrpc_req_finished(request);
1388 ll_putname(filename);
1391 case IOC_LOV_GETINFO: {
1392 struct lov_user_mds_data *lumd;
1393 struct lov_stripe_md *lsm;
1394 struct lov_user_md *lum;
1395 struct lov_mds_md *lmm;
1399 lumd = (struct lov_user_mds_data *)arg;
1400 lum = &lumd->lmd_lmm;
1402 rc = ll_get_max_mdsize(sbi, &lmmsize);
1406 OBD_ALLOC_LARGE(lmm, lmmsize);
1410 if (copy_from_user(lmm, lum, lmmsize))
1411 GOTO(free_lmm, rc = -EFAULT);
1413 switch (lmm->lmm_magic) {
1414 case LOV_USER_MAGIC_V1:
1415 if (LOV_USER_MAGIC_V1 == cpu_to_le32(LOV_USER_MAGIC_V1))
1417 /* swab objects first so that stripes num will be sane */
1418 lustre_swab_lov_user_md_objects(
1419 ((struct lov_user_md_v1 *)lmm)->lmm_objects,
1420 ((struct lov_user_md_v1 *)lmm)->lmm_stripe_count);
1421 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
1423 case LOV_USER_MAGIC_V3:
1424 if (LOV_USER_MAGIC_V3 == cpu_to_le32(LOV_USER_MAGIC_V3))
1426 /* swab objects first so that stripes num will be sane */
1427 lustre_swab_lov_user_md_objects(
1428 ((struct lov_user_md_v3 *)lmm)->lmm_objects,
1429 ((struct lov_user_md_v3 *)lmm)->lmm_stripe_count);
1430 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
1433 GOTO(free_lmm, rc = -EINVAL);
1436 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
1438 GOTO(free_lmm, rc = -ENOMEM);
1440 /* Perform glimpse_size operation. */
1441 memset(&st, 0, sizeof(st));
1443 rc = ll_glimpse_ioctl(sbi, lsm, &st);
1447 if (copy_to_user(&lumd->lmd_st, &st, sizeof(st)))
1448 GOTO(free_lsm, rc = -EFAULT);
1452 obd_free_memmd(sbi->ll_dt_exp, &lsm);
1454 OBD_FREE_LARGE(lmm, lmmsize);
1457 case OBD_IOC_QUOTACHECK: {
1458 struct obd_quotactl *oqctl;
1461 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1462 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1465 OBD_ALLOC_PTR(oqctl);
1468 oqctl->qc_type = arg;
1469 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
1471 CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
1475 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
1477 CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
1479 OBD_FREE_PTR(oqctl);
1482 case OBD_IOC_POLL_QUOTACHECK: {
1483 struct if_quotacheck *check;
1485 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1486 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1489 OBD_ALLOC_PTR(check);
1493 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
1496 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
1497 if (copy_to_user((void *)arg, check,
1499 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1503 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
1506 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
1507 if (copy_to_user((void *)arg, check,
1509 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1513 OBD_FREE_PTR(check);
1516 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
1517 case LL_IOC_QUOTACTL_18: {
1518 /* copy the old 1.x quota struct for internal use, then copy
1519 * back into old format struct. For 1.8 compatibility. */
1520 struct if_quotactl_18 *qctl_18;
1521 struct if_quotactl *qctl_20;
1523 OBD_ALLOC_PTR(qctl_18);
1527 OBD_ALLOC_PTR(qctl_20);
1529 GOTO(out_quotactl_18, rc = -ENOMEM);
1531 if (copy_from_user(qctl_18, (void *)arg, sizeof(*qctl_18)))
1532 GOTO(out_quotactl_20, rc = -ENOMEM);
1534 QCTL_COPY(qctl_20, qctl_18);
1535 qctl_20->qc_idx = 0;
1537 /* XXX: dqb_valid was borrowed as a flag to mark that
1538 * only mds quota is wanted */
1539 if (qctl_18->qc_cmd == Q_GETQUOTA &&
1540 qctl_18->qc_dqblk.dqb_valid) {
1541 qctl_20->qc_valid = QC_MDTIDX;
1542 qctl_20->qc_dqblk.dqb_valid = 0;
1543 } else if (qctl_18->obd_uuid.uuid[0] != '\0') {
1544 qctl_20->qc_valid = QC_UUID;
1545 qctl_20->obd_uuid = qctl_18->obd_uuid;
1547 qctl_20->qc_valid = QC_GENERAL;
1550 rc = quotactl_ioctl(sbi, qctl_20);
1553 QCTL_COPY(qctl_18, qctl_20);
1554 qctl_18->obd_uuid = qctl_20->obd_uuid;
1556 if (copy_to_user((void *)arg, qctl_18,
1562 OBD_FREE_PTR(qctl_20);
1564 OBD_FREE_PTR(qctl_18);
1568 #warning "remove old LL_IOC_QUOTACTL_18 compatibility code"
1569 #endif /* LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0) */
1570 case OBD_IOC_QUOTACTL: {
1571 struct if_quotactl *qctl;
1573 OBD_ALLOC_PTR(qctl);
1577 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
1578 GOTO(out_quotactl, rc = -EFAULT);
1580 rc = quotactl_ioctl(sbi, qctl);
1582 if (rc == 0 && copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1589 case OBD_IOC_GETDTNAME:
1590 case OBD_IOC_GETMDNAME:
1591 RETURN(ll_get_obd_name(inode, cmd, arg));
1592 case LL_IOC_FLUSHCTX:
1593 RETURN(ll_flush_ctx(inode));
1594 #ifdef CONFIG_FS_POSIX_ACL
1595 case LL_IOC_RMTACL: {
1596 if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
1597 inode == inode->i_sb->s_root->d_inode) {
1598 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1600 LASSERT(fd != NULL);
1601 rc = rct_add(&sbi->ll_rct, current_pid(), arg);
1603 fd->fd_flags |= LL_FILE_RMTACL;
1609 case LL_IOC_GETOBDCOUNT: {
1611 struct obd_export *exp;
1613 if (copy_from_user(&count, (int *)arg, sizeof(int)))
1616 /* get ost count when count is zero, get mdt count otherwise */
1617 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
1618 vallen = sizeof(count);
1619 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
1620 KEY_TGT_COUNT, &vallen, &count, NULL);
1622 CERROR("get target count failed: %d\n", rc);
1626 if (copy_to_user((int *)arg, &count, sizeof(int)))
1631 case LL_IOC_PATH2FID:
1632 if (copy_to_user((void *)arg, ll_inode2fid(inode),
1633 sizeof(struct lu_fid)))
1636 case LL_IOC_GET_CONNECT_FLAGS: {
1637 RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL, (void*)arg));
1639 case OBD_IOC_CHANGELOG_SEND:
1640 case OBD_IOC_CHANGELOG_CLEAR:
1641 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void *)arg,
1642 sizeof(struct ioc_changelog));
1644 case OBD_IOC_FID2PATH:
1645 RETURN(ll_fid2path(inode, (void *)arg));
1646 case LL_IOC_HSM_REQUEST: {
1647 struct hsm_user_request *hur;
1654 /* We don't know the true size yet; copy the fixed-size part */
1655 if (copy_from_user(hur, (void *)arg, sizeof(*hur))) {
1660 /* Compute the whole struct size */
1661 totalsize = hur_len(hur);
1664 /* Final size will be more than double totalsize */
1665 if (totalsize >= MDS_MAXREQSIZE / 3)
1668 OBD_ALLOC_LARGE(hur, totalsize);
1672 /* Copy the whole struct */
1673 if (copy_from_user(hur, (void *)arg, totalsize)) {
1674 OBD_FREE_LARGE(hur, totalsize);
1678 if (hur->hur_request.hr_action == HUA_RELEASE) {
1679 const struct lu_fid *fid;
1683 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
1684 fid = &hur->hur_user_item[i].hui_fid;
1685 f = search_inode_for_lustre(inode->i_sb, fid);
1691 rc = ll_hsm_release(f);
1697 rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
1701 OBD_FREE_LARGE(hur, totalsize);
1705 case LL_IOC_HSM_PROGRESS: {
1706 struct hsm_progress_kernel hpk;
1707 struct hsm_progress hp;
1709 if (copy_from_user(&hp, (void *)arg, sizeof(hp)))
1712 hpk.hpk_fid = hp.hp_fid;
1713 hpk.hpk_cookie = hp.hp_cookie;
1714 hpk.hpk_extent = hp.hp_extent;
1715 hpk.hpk_flags = hp.hp_flags;
1716 hpk.hpk_errval = hp.hp_errval;
1717 hpk.hpk_data_version = 0;
1719 /* File may not exist in Lustre; all progress
1720 * reported to Lustre root */
1721 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
1725 case LL_IOC_HSM_CT_START:
1726 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
1729 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void *)arg,
1730 sizeof(struct lustre_kernelcomm));
1733 case LL_IOC_HSM_COPY_START: {
1734 struct hsm_copy *copy;
1737 OBD_ALLOC_PTR(copy);
1740 if (copy_from_user(copy, (char *)arg, sizeof(*copy))) {
1745 rc = ll_ioc_copy_start(inode->i_sb, copy);
1746 if (copy_to_user((char *)arg, copy, sizeof(*copy)))
1752 case LL_IOC_HSM_COPY_END: {
1753 struct hsm_copy *copy;
1756 OBD_ALLOC_PTR(copy);
1759 if (copy_from_user(copy, (char *)arg, sizeof(*copy))) {
1764 rc = ll_ioc_copy_end(inode->i_sb, copy);
1765 if (copy_to_user((char *)arg, copy, sizeof(*copy)))
1771 case LL_IOC_MIGRATE: {
1773 const char *filename;
1779 rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
1783 data = (struct obd_ioctl_data *)buf;
1784 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1785 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1786 GOTO(migrate_free, rc = -EINVAL);
1788 filename = data->ioc_inlbuf1;
1789 namelen = data->ioc_inllen1;
1790 /* \0 is packed at the end of filename */
1791 if (namelen < 1 || namelen != strlen(filename) + 1)
1792 GOTO(migrate_free, rc = -EINVAL);
1794 if (data->ioc_inllen2 != sizeof(mdtidx))
1795 GOTO(migrate_free, rc = -EINVAL);
1796 mdtidx = *(int *)data->ioc_inlbuf2;
1798 rc = ll_migrate(inode, file, mdtidx, filename, namelen - 1);
1800 obd_ioctl_freedata(buf, len);
1805 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL,
1810 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
1812 struct inode *inode = file->f_mapping->host;
1813 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1814 struct ll_sb_info *sbi = ll_i2sbi(inode);
1815 int api32 = ll_need_32bit_api(sbi);
1816 loff_t ret = -EINVAL;
1819 mutex_lock(&inode->i_mutex);
1824 offset += file->f_pos;
1830 offset += LL_DIR_END_OFF_32BIT;
1832 offset += LL_DIR_END_OFF;
1839 ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
1840 (!api32 && offset <= LL_DIR_END_OFF))) {
1841 if (offset != file->f_pos) {
1842 if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
1843 (!api32 && offset == LL_DIR_END_OFF))
1844 fd->lfd_pos = MDS_DIR_END_OFF;
1845 else if (api32 && sbi->ll_flags & LL_SBI_64BIT_HASH)
1846 fd->lfd_pos = offset << 32;
1848 fd->lfd_pos = offset;
1849 file->f_pos = offset;
1850 file->f_version = 0;
1857 mutex_unlock(&inode->i_mutex);
1861 static int ll_dir_open(struct inode *inode, struct file *file)
1864 RETURN(ll_file_open(inode, file));
1867 static int ll_dir_release(struct inode *inode, struct file *file)
1870 RETURN(ll_file_release(inode, file));
1873 const struct file_operations ll_dir_operations = {
1874 .llseek = ll_dir_seek,
1875 .open = ll_dir_open,
1876 .release = ll_dir_release,
1877 .read = generic_read_dir,
1878 #ifdef HAVE_DIR_CONTEXT
1879 .iterate = ll_iterate,
1881 .readdir = ll_readdir,
1883 .unlocked_ioctl = ll_dir_ioctl,