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().
143 * The following three APIs will be used by llite to iterate directory
144 * entries from MDC dir page caches.
146 * ll_dir_entry_start(next) will lookup(return) entry by op_hash_offset.
147 * To avoid extra memory allocation, the @entry will be pointed to
148 * the dir entries in MDC page directly, so these pages can not be released
149 * until the entry has been accessed in ll_readdir(or statahead).
151 * The iterate process will be
153 * ll_dir_entry_start: locate the page in MDC, and return the first entry.
156 * ll_dir_entry_next: return the next entry in the current page, if it reaches
157 * to the end, release current page.
159 * ll_dir_entry_end: release the last page.
161 struct lu_dirent *ll_dir_entry_start(struct inode *dir,
162 struct md_op_data *op_data,
165 struct lu_dirent *entry;
166 struct md_callback cb_op;
169 LASSERT(*ppage == NULL);
170 cb_op.md_blocking_ast = ll_md_blocking_ast;
171 rc = md_read_entry(ll_i2mdexp(dir), op_data, &cb_op, &entry, ppage);
177 struct lu_dirent *ll_dir_entry_next(struct inode *dir,
178 struct md_op_data *op_data,
179 struct lu_dirent *ent,
182 struct lu_dirent *entry;
183 struct md_callback cb_op;
186 LASSERT(*ppage != NULL);
187 cb_op.md_blocking_ast = ll_md_blocking_ast;
188 op_data->op_hash_offset = le64_to_cpu(ent->lde_hash);
190 page_cache_release(*ppage);
192 rc = md_read_entry(ll_i2mdexp(dir), op_data, &cb_op, &entry, ppage);
198 #ifdef HAVE_DIR_CONTEXT
199 int ll_dir_read(struct inode *inode, struct md_op_data *op_data,
200 struct dir_context *ctx)
203 int ll_dir_read(struct inode *inode, struct md_op_data *op_data,
204 void *cookie, filldir_t filldir)
207 struct ll_sb_info *sbi = ll_i2sbi(inode);
208 struct ll_dir_chain chain;
209 struct lu_dirent *ent;
210 int api32 = ll_need_32bit_api(sbi);
211 int hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
214 __u64 hash = MDS_DIR_END_OFF;
215 __u64 last_hash = MDS_DIR_END_OFF;
216 struct page *page = NULL;
219 ll_dir_chain_init(&chain);
220 for (ent = ll_dir_entry_start(inode, op_data, &page);
221 ent != NULL && !IS_ERR(ent) && !done;
222 ent = ll_dir_entry_next(inode, op_data, ent, &page)) {
229 hash = le64_to_cpu(ent->lde_hash);
230 if (hash < op_data->op_hash_offset)
232 * Skip until we find target hash
236 namelen = le16_to_cpu(ent->lde_namelen);
247 fid_le_to_cpu(&fid, &ent->lde_fid);
248 ino = cl_fid_build_ino(&fid, api32);
249 type = ll_dirent_type_get(ent);
251 #ifdef HAVE_DIR_CONTEXT
252 /* For 'll_nfs_get_name_filldir()', it will try
253 * to access the 'ent' through its 'lde_name',
254 * so the parameter 'name' for 'filldir()' must
255 * be part of the 'ent'. */
256 done = !dir_emit(ctx, ent->lde_name, namelen, ino, type);
258 done = filldir(cookie, ent->lde_name, namelen, lhash,
262 if (op_data->op_hash_offset != MDS_DIR_END_OFF)
263 op_data->op_hash_offset = last_hash;
275 page_cache_release(page);
278 ll_dir_chain_fini(&chain);
282 #ifdef HAVE_DIR_CONTEXT
283 static int ll_iterate(struct file *filp, struct dir_context *ctx)
285 static int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
288 struct inode *inode = filp->f_dentry->d_inode;
289 struct ll_file_data *lfd = LUSTRE_FPRIVATE(filp);
290 struct ll_sb_info *sbi = ll_i2sbi(inode);
291 int hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
292 int api32 = ll_need_32bit_api(sbi);
293 struct md_op_data *op_data;
303 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) pos/size"
304 "%lu/%llu 32bit_api %d\n", PFID(ll_inode2fid(inode)),
305 inode, (unsigned long)pos, i_size_read(inode), api32);
307 if (pos == MDS_DIR_END_OFF)
313 op_data = ll_prep_md_op_data(NULL, inode, inode, NULL, 0, 0,
314 LUSTRE_OPC_ANY, inode);
316 GOTO(out, rc = PTR_ERR(op_data));
318 op_data->op_hash_offset = pos;
319 op_data->op_max_pages = sbi->ll_md_brw_pages;
320 #ifdef HAVE_DIR_CONTEXT
322 rc = ll_dir_read(inode, op_data, ctx);
325 rc = ll_dir_read(inode, op_data, cookie, filldir);
328 lfd->lfd_pos = op_data->op_hash_offset;
330 if (pos == MDS_DIR_END_OFF) {
332 pos = LL_DIR_END_OFF_32BIT;
334 pos = LL_DIR_END_OFF;
337 pos = op_data->op_hash_offset >> 32;
339 pos = op_data->op_hash_offset;
341 #ifdef HAVE_DIR_CONTEXT
346 ll_finish_md_op_data(op_data);
347 filp->f_version = inode->i_version;
351 ll_stats_ops_tally(sbi, LPROC_LL_READDIR, 1);
356 static int ll_send_mgc_param(struct obd_export *mgc, char *string)
358 struct mgs_send_param *msp;
365 strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN);
366 rc = obd_set_info_async(NULL, mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
367 sizeof(struct mgs_send_param), msp, NULL);
369 CERROR("Failed to set parameter: %d\n", rc);
375 static int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
376 const char *filename)
378 struct ptlrpc_request *request = NULL;
379 struct md_op_data *op_data;
380 struct ll_sb_info *sbi = ll_i2sbi(dir);
385 if (unlikely(lump->lum_magic != LMV_USER_MAGIC))
388 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) name %s"
389 "stripe_offset %d, stripe_count: %u\n",
390 PFID(ll_inode2fid(dir)), dir, filename,
391 (int)lump->lum_stripe_offset, lump->lum_stripe_count);
393 if (lump->lum_magic != cpu_to_le32(LMV_USER_MAGIC))
394 lustre_swab_lmv_user_md(lump);
396 mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
397 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
398 strlen(filename), mode, LUSTRE_OPC_MKDIR,
401 GOTO(err_exit, err = PTR_ERR(op_data));
403 op_data->op_cli_flags |= CLI_SET_MEA;
404 err = md_create(sbi->ll_md_exp, op_data, lump, sizeof(*lump), mode,
405 from_kuid(&init_user_ns, current_fsuid()),
406 from_kgid(&init_user_ns, current_fsgid()),
407 cfs_curproc_cap_pack(), 0, &request);
408 ll_finish_md_op_data(op_data);
412 ptlrpc_req_finished(request);
416 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
419 struct ll_sb_info *sbi = ll_i2sbi(inode);
420 struct md_op_data *op_data;
421 struct ptlrpc_request *req = NULL;
423 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
424 struct obd_device *mgc = lsi->lsi_mgc;
430 * This is coming from userspace, so should be in
431 * local endian. But the MDS would like it in little
432 * endian, so we swab it before we send it.
434 switch (lump->lmm_magic) {
435 case LOV_USER_MAGIC_V1: {
436 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V1))
437 lustre_swab_lov_user_md_v1(lump);
438 lum_size = sizeof(struct lov_user_md_v1);
441 case LOV_USER_MAGIC_V3: {
442 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V3))
443 lustre_swab_lov_user_md_v3(
444 (struct lov_user_md_v3 *)lump);
445 lum_size = sizeof(struct lov_user_md_v3);
448 case LMV_USER_MAGIC: {
449 if (lump->lmm_magic != cpu_to_le32(LMV_USER_MAGIC))
450 lustre_swab_lmv_user_md(
451 (struct lmv_user_md *)lump);
452 lum_size = sizeof(struct lmv_user_md);
456 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
457 " %#08x != %#08x nor %#08x\n",
458 lump->lmm_magic, LOV_USER_MAGIC_V1,
464 lum_size = sizeof(struct lov_user_md_v1);
467 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
468 LUSTRE_OPC_ANY, NULL);
470 RETURN(PTR_ERR(op_data));
472 /* swabbing is done in lov_setstripe() on server side */
473 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size,
474 NULL, 0, &req, NULL);
475 ll_finish_md_op_data(op_data);
476 ptlrpc_req_finished(req);
478 if (rc != -EPERM && rc != -EACCES)
479 CERROR("mdc_setattr fails: rc = %d\n", rc);
482 /* In the following we use the fact that LOV_USER_MAGIC_V1 and
483 LOV_USER_MAGIC_V3 have the same initial fields so we do not
484 need the make the distiction between the 2 versions */
485 if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
489 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
491 GOTO(end, rc = -ENOMEM);
494 /* Get fsname and assume devname to be -MDT0000. */
495 ll_get_fsname(inode->i_sb, buf, MTI_NAME_MAXLEN);
496 strcat(buf, "-MDT0000.lov");
499 /* Set root stripesize */
500 sprintf(buf, ".stripesize=%u",
501 lump ? le32_to_cpu(lump->lmm_stripe_size) : 0);
502 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
506 /* Set root stripecount */
507 sprintf(buf, ".stripecount=%hd",
508 lump ? le16_to_cpu(lump->lmm_stripe_count) : 0);
509 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
513 /* Set root stripeoffset */
514 sprintf(buf, ".stripeoffset=%hd",
515 lump ? le16_to_cpu(lump->lmm_stripe_offset) :
516 (typeof(lump->lmm_stripe_offset))(-1));
517 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
521 OBD_FREE(param, MGS_PARAM_MAXLEN);
527 * This function will be used to get default LOV/LMV/Default LMV
528 * @valid will be used to indicate which stripe it will retrieve
529 * OBD_MD_MEA LMV stripe EA
530 * OBD_MD_DEFAULT_MEA Default LMV stripe EA
531 * otherwise Default LOV EA.
532 * Each time, it can only retrieve 1 stripe EA
534 int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
535 struct ptlrpc_request **request, obd_valid valid)
537 struct ll_sb_info *sbi = ll_i2sbi(inode);
538 struct mdt_body *body;
539 struct lov_mds_md *lmm = NULL;
540 struct ptlrpc_request *req = NULL;
542 struct md_op_data *op_data;
545 rc = ll_get_default_mdsize(sbi, &lmm_size);
549 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
550 0, lmm_size, LUSTRE_OPC_ANY,
553 RETURN(PTR_ERR(op_data));
555 op_data->op_valid = valid | OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
556 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
557 ll_finish_md_op_data(op_data);
559 CDEBUG(D_INFO, "md_getattr failed on inode "
560 DFID": rc %d\n", PFID(ll_inode2fid(inode)), rc);
564 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
565 LASSERT(body != NULL);
567 lmm_size = body->eadatasize;
569 if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
571 GOTO(out, rc = -ENODATA);
574 lmm = req_capsule_server_sized_get(&req->rq_pill,
575 &RMF_MDT_MD, lmm_size);
576 LASSERT(lmm != NULL);
579 * This is coming from the MDS, so is probably in
580 * little endian. We convert it to host endian before
581 * passing it to userspace.
583 /* We don't swab objects for directories */
584 switch (le32_to_cpu(lmm->lmm_magic)) {
586 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
587 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
590 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
591 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
594 if (LMV_MAGIC != cpu_to_le32(LMV_MAGIC))
595 lustre_swab_lmv_mds_md((union lmv_mds_md *)lmm);
598 if (LMV_USER_MAGIC != cpu_to_le32(LMV_USER_MAGIC))
599 lustre_swab_lmv_user_md((struct lmv_user_md *)lmm);
602 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
607 *plmm_size = lmm_size;
612 int ll_get_mdt_idx_by_fid(struct ll_sb_info *sbi, const struct lu_fid *fid)
614 struct md_op_data *op_data;
619 OBD_ALLOC_PTR(op_data);
623 op_data->op_flags |= MF_GET_MDT_IDX;
624 op_data->op_fid1 = *fid;
625 rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
626 mdt_index = op_data->op_mds;
627 OBD_FREE_PTR(op_data);
635 * Get MDT index for the inode.
637 int ll_get_mdt_idx(struct inode *inode)
639 return ll_get_mdt_idx_by_fid(ll_i2sbi(inode), ll_inode2fid(inode));
643 * Generic handler to do any pre-copy work.
645 * It send a first hsm_progress (with extent length == 0) to coordinator as a
646 * first information for it that real work has started.
648 * Moreover, for a ARCHIVE request, it will sample the file data version and
649 * store it in \a copy.
651 * \return 0 on success.
653 static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
655 struct ll_sb_info *sbi = ll_s2sbi(sb);
656 struct hsm_progress_kernel hpk;
660 /* Forge a hsm_progress based on data from copy. */
661 hpk.hpk_fid = copy->hc_hai.hai_fid;
662 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
663 hpk.hpk_extent.offset = copy->hc_hai.hai_extent.offset;
664 hpk.hpk_extent.length = 0;
667 hpk.hpk_data_version = 0;
670 /* For archive request, we need to read the current file version. */
671 if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
673 __u64 data_version = 0;
675 /* Get inode for this fid */
676 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
678 hpk.hpk_flags |= HP_FLAG_RETRY;
679 /* hpk_errval is >= 0 */
680 hpk.hpk_errval = -PTR_ERR(inode);
681 GOTO(progress, rc = PTR_ERR(inode));
684 /* Read current file data version */
685 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
688 CDEBUG(D_HSM, "Could not read file data version of "
689 DFID" (rc = %d). Archive request ("
690 LPX64") could not be done.\n",
691 PFID(©->hc_hai.hai_fid), rc,
692 copy->hc_hai.hai_cookie);
693 hpk.hpk_flags |= HP_FLAG_RETRY;
694 /* hpk_errval must be >= 0 */
695 hpk.hpk_errval = -rc;
699 /* Store it the hsm_copy for later copytool use.
700 * Always modified even if no lsm. */
701 copy->hc_data_version = data_version;
705 /* On error, the request should be considered as completed */
706 if (hpk.hpk_errval > 0)
707 hpk.hpk_flags |= HP_FLAG_COMPLETED;
708 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
715 * Generic handler to do any post-copy work.
717 * It will send the last hsm_progress update to coordinator to inform it
718 * that copy is finished and whether it was successful or not.
721 * - for ARCHIVE request, it will sample the file data version and compare it
722 * with the version saved in ll_ioc_copy_start(). If they do not match, copy
723 * will be considered as failed.
724 * - for RESTORE request, it will sample the file data version and send it to
725 * coordinator which is useful if the file was imported as 'released'.
727 * \return 0 on success.
729 static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
731 struct ll_sb_info *sbi = ll_s2sbi(sb);
732 struct hsm_progress_kernel hpk;
736 /* If you modify the logic here, also check llapi_hsm_copy_end(). */
737 /* Take care: copy->hc_hai.hai_action, len, gid and data are not
738 * initialized if copy_end was called with copy == NULL.
741 /* Forge a hsm_progress based on data from copy. */
742 hpk.hpk_fid = copy->hc_hai.hai_fid;
743 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
744 hpk.hpk_extent = copy->hc_hai.hai_extent;
745 hpk.hpk_flags = copy->hc_flags | HP_FLAG_COMPLETED;
746 hpk.hpk_errval = copy->hc_errval;
747 hpk.hpk_data_version = 0;
749 /* For archive request, we need to check the file data was not changed.
751 * For restore request, we need to send the file data version, this is
752 * useful when the file was created using hsm_import.
754 if (((copy->hc_hai.hai_action == HSMA_ARCHIVE) ||
755 (copy->hc_hai.hai_action == HSMA_RESTORE)) &&
756 (copy->hc_errval == 0)) {
758 __u64 data_version = 0;
760 /* Get lsm for this fid */
761 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
763 hpk.hpk_flags |= HP_FLAG_RETRY;
764 /* hpk_errval must be >= 0 */
765 hpk.hpk_errval = -PTR_ERR(inode);
766 GOTO(progress, rc = PTR_ERR(inode));
769 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
772 CDEBUG(D_HSM, "Could not read file data version. "
773 "Request could not be confirmed.\n");
774 if (hpk.hpk_errval == 0)
775 hpk.hpk_errval = -rc;
779 /* Store it the hsm_copy for later copytool use.
780 * Always modified even if no lsm. */
781 hpk.hpk_data_version = data_version;
783 /* File could have been stripped during archiving, so we need
784 * to check anyway. */
785 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
786 (copy->hc_data_version != data_version)) {
787 CDEBUG(D_HSM, "File data version mismatched. "
788 "File content was changed during archiving. "
789 DFID", start:"LPX64" current:"LPX64"\n",
790 PFID(©->hc_hai.hai_fid),
791 copy->hc_data_version, data_version);
792 /* File was changed, send error to cdt. Do not ask for
793 * retry because if a file is modified frequently,
794 * the cdt will loop on retried archive requests.
795 * The policy engine will ask for a new archive later
796 * when the file will not be modified for some tunable
798 /* we do not notify caller */
799 hpk.hpk_flags &= ~HP_FLAG_RETRY;
800 /* hpk_errval must be >= 0 */
801 hpk.hpk_errval = EBUSY;
807 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
814 static int copy_and_ioctl(int cmd, struct obd_export *exp,
815 const void __user *data, size_t size)
820 OBD_ALLOC(copy, size);
824 if (copy_from_user(copy, data, size)) {
829 rc = obd_iocontrol(cmd, exp, size, copy, NULL);
831 OBD_FREE(copy, size);
836 static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
838 int cmd = qctl->qc_cmd;
839 int type = qctl->qc_type;
840 int id = qctl->qc_id;
841 int valid = qctl->qc_valid;
846 case LUSTRE_Q_INVALIDATE:
847 case LUSTRE_Q_FINVALIDATE:
852 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
853 sbi->ll_flags & LL_SBI_RMT_CLIENT)
857 if (((type == USRQUOTA &&
858 !uid_eq(current_euid(), make_kuid(&init_user_ns, id))) ||
860 !in_egroup_p(make_kgid(&init_user_ns, id)))) &&
861 (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
862 sbi->ll_flags & LL_SBI_RMT_CLIENT))
868 CERROR("unsupported quotactl op: %#x\n", cmd);
872 if (valid != QC_GENERAL) {
873 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
876 if (cmd == Q_GETINFO)
877 qctl->qc_cmd = Q_GETOINFO;
878 else if (cmd == Q_GETQUOTA)
879 qctl->qc_cmd = Q_GETOQUOTA;
885 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
886 sizeof(*qctl), qctl, NULL);
889 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
890 sizeof(*qctl), qctl, NULL);
893 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
894 sizeof(*qctl), qctl, NULL);
896 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
898 sizeof(*qctl), qctl, NULL);
910 struct obd_quotactl *oqctl;
912 OBD_ALLOC_PTR(oqctl);
916 QCTL_COPY(oqctl, qctl);
917 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
919 if (rc != -EALREADY && cmd == Q_QUOTAON) {
920 oqctl->qc_cmd = Q_QUOTAOFF;
921 obd_quotactl(sbi->ll_md_exp, oqctl);
926 /* If QIF_SPACE is not set, client should collect the
927 * space usage from OSSs by itself */
928 if (cmd == Q_GETQUOTA &&
929 !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
930 !oqctl->qc_dqblk.dqb_curspace) {
931 struct obd_quotactl *oqctl_tmp;
933 OBD_ALLOC_PTR(oqctl_tmp);
934 if (oqctl_tmp == NULL)
935 GOTO(out, rc = -ENOMEM);
937 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
938 oqctl_tmp->qc_id = oqctl->qc_id;
939 oqctl_tmp->qc_type = oqctl->qc_type;
941 /* collect space usage from OSTs */
942 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
943 rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
944 if (!rc || rc == -EREMOTEIO) {
945 oqctl->qc_dqblk.dqb_curspace =
946 oqctl_tmp->qc_dqblk.dqb_curspace;
947 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
950 /* collect space & inode usage from MDTs */
951 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
952 oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
953 rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
954 if (!rc || rc == -EREMOTEIO) {
955 oqctl->qc_dqblk.dqb_curspace +=
956 oqctl_tmp->qc_dqblk.dqb_curspace;
957 oqctl->qc_dqblk.dqb_curinodes =
958 oqctl_tmp->qc_dqblk.dqb_curinodes;
959 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
961 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
964 OBD_FREE_PTR(oqctl_tmp);
967 QCTL_COPY(qctl, oqctl);
975 ll_getname(const char __user *filename)
978 char *tmp = __getname();
981 return ERR_PTR(-ENOMEM);
983 len = strncpy_from_user(tmp, filename, PATH_MAX);
986 else if (len > PATH_MAX)
996 #define ll_putname(filename) __putname(filename)
998 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1000 struct inode *inode = file->f_dentry->d_inode;
1001 struct ll_sb_info *sbi = ll_i2sbi(inode);
1002 struct obd_ioctl_data *data;
1006 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%#x\n",
1007 PFID(ll_inode2fid(inode)), inode, cmd);
1009 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
1010 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
1013 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
1015 case FSFILT_IOC_GETFLAGS:
1016 case FSFILT_IOC_SETFLAGS:
1017 RETURN(ll_iocontrol(inode, file, cmd, arg));
1018 case FSFILT_IOC_GETVERSION_OLD:
1019 case FSFILT_IOC_GETVERSION:
1020 RETURN(put_user(inode->i_generation, (int *)arg));
1021 /* We need to special case any other ioctls we want to handle,
1022 * to send them to the MDS/OST as appropriate and to properly
1023 * network encode the arg field.
1024 case FSFILT_IOC_SETVERSION_OLD:
1025 case FSFILT_IOC_SETVERSION:
1027 case LL_IOC_GET_MDTIDX: {
1030 mdtidx = ll_get_mdt_idx(inode);
1034 if (put_user((int)mdtidx, (int*)arg))
1039 case IOC_MDC_LOOKUP: {
1040 int namelen, len = 0;
1044 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
1049 filename = data->ioc_inlbuf1;
1050 namelen = strlen(filename);
1052 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1053 GOTO(out_free, rc = -EINVAL);
1056 rc = ll_get_fid_by_name(inode, filename, namelen, NULL);
1058 CERROR("%s: lookup %.*s failed: rc = %d\n",
1059 ll_get_fsname(inode->i_sb, NULL, 0), namelen,
1064 obd_ioctl_freedata(buf, len);
1067 case LL_IOC_LMV_SETSTRIPE: {
1068 struct lmv_user_md *lum;
1076 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
1081 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1082 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1083 GOTO(lmv_out_free, rc = -EINVAL);
1085 filename = data->ioc_inlbuf1;
1086 namelen = data->ioc_inllen1;
1089 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1090 GOTO(lmv_out_free, rc = -EINVAL);
1092 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1093 lumlen = data->ioc_inllen2;
1095 if (lum->lum_magic != LMV_USER_MAGIC ||
1096 lumlen != sizeof(*lum)) {
1097 CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1098 filename, lum->lum_magic, lumlen, -EFAULT);
1099 GOTO(lmv_out_free, rc = -EINVAL);
1103 * ll_dir_setdirstripe will be used to set dir stripe
1104 * mdc_create--->mdt_reint_create (with dirstripe)
1106 rc = ll_dir_setdirstripe(inode, lum, filename);
1108 obd_ioctl_freedata(buf, len);
1112 case LL_IOC_LMV_SET_DEFAULT_STRIPE: {
1113 struct lmv_user_md lum;
1114 struct lmv_user_md __user *ulump =
1115 (struct lmv_user_md __user *)arg;
1118 if (copy_from_user(&lum, ulump, sizeof(lum)))
1121 if (lum.lum_magic != LMV_USER_MAGIC)
1124 rc = ll_dir_setstripe(inode, (struct lov_user_md *)&lum, 0);
1128 case LL_IOC_LOV_SETSTRIPE: {
1129 struct lov_user_md_v3 lumv3;
1130 struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
1131 struct lov_user_md_v1 *lumv1p = (struct lov_user_md_v1 *)arg;
1132 struct lov_user_md_v3 *lumv3p = (struct lov_user_md_v3 *)arg;
1134 int set_default = 0;
1136 LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
1137 LASSERT(sizeof(lumv3.lmm_objects[0]) ==
1138 sizeof(lumv3p->lmm_objects[0]));
1139 /* first try with v1 which is smaller than v3 */
1140 if (copy_from_user(lumv1, lumv1p, sizeof(*lumv1)))
1143 if ((lumv1->lmm_magic == LOV_USER_MAGIC_V3) ) {
1144 if (copy_from_user(&lumv3, lumv3p, sizeof(lumv3)))
1148 if (inode->i_sb->s_root == file->f_dentry)
1151 /* in v1 and v3 cases lumv1 points to data */
1152 rc = ll_dir_setstripe(inode, lumv1, set_default);
1156 case LL_IOC_LMV_GETSTRIPE: {
1157 struct lmv_user_md __user *ulmv =
1158 (struct lmv_user_md __user *)arg;
1159 struct lmv_user_md lum;
1160 struct ptlrpc_request *request = NULL;
1161 union lmv_mds_md *lmm = NULL;
1163 obd_valid valid = 0;
1164 struct lmv_user_md *tmp = NULL;
1171 if (copy_from_user(&lum, ulmv, sizeof(*ulmv)))
1174 /* lum_magic will indicate which stripe the ioctl will like
1175 * to get, LMV_MAGIC_V1 is for normal LMV stripe, LMV_USER_MAGIC
1176 * is for default LMV stripe */
1177 if (lum.lum_magic == LMV_MAGIC_V1)
1178 valid |= OBD_MD_MEA;
1179 else if (lum.lum_magic == LMV_USER_MAGIC)
1180 valid |= OBD_MD_DEFAULT_MEA;
1184 rc = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize, &request,
1187 GOTO(finish_req, rc);
1189 /* Get default LMV EA */
1190 if (lum.lum_magic == LMV_USER_MAGIC) {
1192 GOTO(finish_req, rc);
1194 if (lmmsize > sizeof(*ulmv))
1195 GOTO(finish_req, rc = -EINVAL);
1197 if (copy_to_user(ulmv, lmm, lmmsize))
1198 GOTO(finish_req, rc = -EFAULT);
1200 GOTO(finish_req, rc);
1203 stripe_count = lmv_mds_md_stripe_count_get(lmm);
1204 lum_size = lmv_user_md_size(stripe_count, LMV_MAGIC_V1);
1205 OBD_ALLOC(tmp, lum_size);
1207 GOTO(finish_req, rc = -ENOMEM);
1209 mdt_index = ll_get_mdt_idx(inode);
1211 GOTO(out_tmp, rc = -ENOMEM);
1213 tmp->lum_magic = LMV_MAGIC_V1;
1214 tmp->lum_stripe_count = 0;
1215 tmp->lum_stripe_offset = mdt_index;
1216 for (i = 0; i < stripe_count; i++) {
1219 fid = &lmm->lmv_md_v1.lmv_stripe_fids[i];
1220 mdt_index = ll_get_mdt_idx_by_fid(sbi, fid);
1222 GOTO(out_tmp, rc = mdt_index);
1224 tmp->lum_objects[i].lum_mds = mdt_index;
1225 tmp->lum_objects[i].lum_fid = *fid;
1226 tmp->lum_stripe_count++;
1229 if (copy_to_user(ulmv, tmp, lum_size))
1230 GOTO(out_tmp, rc = -EFAULT);
1232 OBD_FREE(tmp, lum_size);
1234 ptlrpc_req_finished(request);
1238 case LL_IOC_REMOVE_ENTRY: {
1239 char *filename = NULL;
1243 /* Here is a little hack to avoid sending REINT_RMENTRY to
1244 * unsupported server, which might crash the server(LU-2730),
1245 * Because both LVB_TYPE and REINT_RMENTRY will be supported
1246 * on 2.4, we use OBD_CONNECT_LVB_TYPE to detect whether the
1247 * server will support REINT_RMENTRY XXX*/
1248 if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE))
1251 filename = ll_getname((const char *)arg);
1252 if (IS_ERR(filename))
1253 RETURN(PTR_ERR(filename));
1255 namelen = strlen(filename);
1257 GOTO(out_rmdir, rc = -EINVAL);
1259 rc = ll_rmdir_entry(inode, filename, namelen);
1262 ll_putname(filename);
1265 case LL_IOC_LOV_SWAP_LAYOUTS:
1267 case IOC_OBD_STATFS:
1268 RETURN(ll_obd_statfs(inode, (void *)arg));
1269 case LL_IOC_LOV_GETSTRIPE:
1270 case LL_IOC_MDC_GETINFO:
1271 case IOC_MDC_GETFILEINFO:
1272 case IOC_MDC_GETFILESTRIPE: {
1273 struct ptlrpc_request *request = NULL;
1274 struct lov_user_md *lump;
1275 struct lov_mds_md *lmm = NULL;
1276 struct mdt_body *body;
1277 char *filename = NULL;
1280 if (cmd == IOC_MDC_GETFILEINFO ||
1281 cmd == IOC_MDC_GETFILESTRIPE) {
1282 filename = ll_getname((const char *)arg);
1283 if (IS_ERR(filename))
1284 RETURN(PTR_ERR(filename));
1286 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1287 &lmmsize, &request);
1289 rc = ll_dir_getstripe(inode, (void **)&lmm, &lmmsize,
1294 body = req_capsule_server_get(&request->rq_pill,
1296 LASSERT(body != NULL);
1302 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
1303 cmd == LL_IOC_MDC_GETINFO))
1304 GOTO(skip_lmm, rc = 0);
1309 if (cmd == IOC_MDC_GETFILESTRIPE ||
1310 cmd == LL_IOC_LOV_GETSTRIPE) {
1311 lump = (struct lov_user_md *)arg;
1313 struct lov_user_mds_data *lmdp;
1314 lmdp = (struct lov_user_mds_data *)arg;
1315 lump = &lmdp->lmd_lmm;
1317 if (copy_to_user(lump, lmm, lmmsize)) {
1318 if (copy_to_user(lump, lmm, sizeof(*lump)))
1319 GOTO(out_req, rc = -EFAULT);
1323 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
1324 struct lov_user_mds_data *lmdp;
1327 st.st_dev = inode->i_sb->s_dev;
1328 st.st_mode = body->mode;
1329 st.st_nlink = body->nlink;
1330 st.st_uid = body->uid;
1331 st.st_gid = body->gid;
1332 st.st_rdev = body->rdev;
1333 st.st_size = body->size;
1334 st.st_blksize = PAGE_CACHE_SIZE;
1335 st.st_blocks = body->blocks;
1336 st.st_atime = body->atime;
1337 st.st_mtime = body->mtime;
1338 st.st_ctime = body->ctime;
1339 st.st_ino = inode->i_ino;
1341 lmdp = (struct lov_user_mds_data *)arg;
1342 if (copy_to_user(&lmdp->lmd_st, &st, sizeof(st)))
1343 GOTO(out_req, rc = -EFAULT);
1348 ptlrpc_req_finished(request);
1350 ll_putname(filename);
1353 case IOC_LOV_GETINFO: {
1354 struct lov_user_mds_data *lumd;
1355 struct lov_stripe_md *lsm;
1356 struct lov_user_md *lum;
1357 struct lov_mds_md *lmm;
1361 lumd = (struct lov_user_mds_data *)arg;
1362 lum = &lumd->lmd_lmm;
1364 rc = ll_get_max_mdsize(sbi, &lmmsize);
1368 OBD_ALLOC_LARGE(lmm, lmmsize);
1372 if (copy_from_user(lmm, lum, lmmsize))
1373 GOTO(free_lmm, rc = -EFAULT);
1375 switch (lmm->lmm_magic) {
1376 case LOV_USER_MAGIC_V1:
1377 if (LOV_USER_MAGIC_V1 == cpu_to_le32(LOV_USER_MAGIC_V1))
1379 /* swab objects first so that stripes num will be sane */
1380 lustre_swab_lov_user_md_objects(
1381 ((struct lov_user_md_v1 *)lmm)->lmm_objects,
1382 ((struct lov_user_md_v1 *)lmm)->lmm_stripe_count);
1383 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
1385 case LOV_USER_MAGIC_V3:
1386 if (LOV_USER_MAGIC_V3 == cpu_to_le32(LOV_USER_MAGIC_V3))
1388 /* swab objects first so that stripes num will be sane */
1389 lustre_swab_lov_user_md_objects(
1390 ((struct lov_user_md_v3 *)lmm)->lmm_objects,
1391 ((struct lov_user_md_v3 *)lmm)->lmm_stripe_count);
1392 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
1395 GOTO(free_lmm, rc = -EINVAL);
1398 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
1400 GOTO(free_lmm, rc = -ENOMEM);
1402 /* Perform glimpse_size operation. */
1403 memset(&st, 0, sizeof(st));
1405 rc = ll_glimpse_ioctl(sbi, lsm, &st);
1409 if (copy_to_user(&lumd->lmd_st, &st, sizeof(st)))
1410 GOTO(free_lsm, rc = -EFAULT);
1414 obd_free_memmd(sbi->ll_dt_exp, &lsm);
1416 OBD_FREE_LARGE(lmm, lmmsize);
1419 case OBD_IOC_QUOTACHECK: {
1420 struct obd_quotactl *oqctl;
1423 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1424 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1427 OBD_ALLOC_PTR(oqctl);
1430 oqctl->qc_type = arg;
1431 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
1433 CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
1437 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
1439 CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
1441 OBD_FREE_PTR(oqctl);
1444 case OBD_IOC_POLL_QUOTACHECK: {
1445 struct if_quotacheck *check;
1447 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1448 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1451 OBD_ALLOC_PTR(check);
1455 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
1458 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
1459 if (copy_to_user((void *)arg, check,
1461 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1465 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
1468 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
1469 if (copy_to_user((void *)arg, check,
1471 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1475 OBD_FREE_PTR(check);
1478 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
1479 case LL_IOC_QUOTACTL_18: {
1480 /* copy the old 1.x quota struct for internal use, then copy
1481 * back into old format struct. For 1.8 compatibility. */
1482 struct if_quotactl_18 *qctl_18;
1483 struct if_quotactl *qctl_20;
1485 OBD_ALLOC_PTR(qctl_18);
1489 OBD_ALLOC_PTR(qctl_20);
1491 GOTO(out_quotactl_18, rc = -ENOMEM);
1493 if (copy_from_user(qctl_18, (void *)arg, sizeof(*qctl_18)))
1494 GOTO(out_quotactl_20, rc = -ENOMEM);
1496 QCTL_COPY(qctl_20, qctl_18);
1497 qctl_20->qc_idx = 0;
1499 /* XXX: dqb_valid was borrowed as a flag to mark that
1500 * only mds quota is wanted */
1501 if (qctl_18->qc_cmd == Q_GETQUOTA &&
1502 qctl_18->qc_dqblk.dqb_valid) {
1503 qctl_20->qc_valid = QC_MDTIDX;
1504 qctl_20->qc_dqblk.dqb_valid = 0;
1505 } else if (qctl_18->obd_uuid.uuid[0] != '\0') {
1506 qctl_20->qc_valid = QC_UUID;
1507 qctl_20->obd_uuid = qctl_18->obd_uuid;
1509 qctl_20->qc_valid = QC_GENERAL;
1512 rc = quotactl_ioctl(sbi, qctl_20);
1515 QCTL_COPY(qctl_18, qctl_20);
1516 qctl_18->obd_uuid = qctl_20->obd_uuid;
1518 if (copy_to_user((void *)arg, qctl_18,
1524 OBD_FREE_PTR(qctl_20);
1526 OBD_FREE_PTR(qctl_18);
1530 #warning "remove old LL_IOC_QUOTACTL_18 compatibility code"
1531 #endif /* LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0) */
1532 case OBD_IOC_QUOTACTL: {
1533 struct if_quotactl *qctl;
1535 OBD_ALLOC_PTR(qctl);
1539 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
1540 GOTO(out_quotactl, rc = -EFAULT);
1542 rc = quotactl_ioctl(sbi, qctl);
1544 if (rc == 0 && copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1551 case OBD_IOC_GETDTNAME:
1552 case OBD_IOC_GETMDNAME:
1553 RETURN(ll_get_obd_name(inode, cmd, arg));
1554 case LL_IOC_FLUSHCTX:
1555 RETURN(ll_flush_ctx(inode));
1556 #ifdef CONFIG_FS_POSIX_ACL
1557 case LL_IOC_RMTACL: {
1558 if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
1559 inode == inode->i_sb->s_root->d_inode) {
1560 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1562 LASSERT(fd != NULL);
1563 rc = rct_add(&sbi->ll_rct, current_pid(), arg);
1565 fd->fd_flags |= LL_FILE_RMTACL;
1571 case LL_IOC_GETOBDCOUNT: {
1573 struct obd_export *exp;
1575 if (copy_from_user(&count, (int *)arg, sizeof(int)))
1578 /* get ost count when count is zero, get mdt count otherwise */
1579 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
1580 vallen = sizeof(count);
1581 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
1582 KEY_TGT_COUNT, &vallen, &count, NULL);
1584 CERROR("get target count failed: %d\n", rc);
1588 if (copy_to_user((int *)arg, &count, sizeof(int)))
1593 case LL_IOC_PATH2FID:
1594 if (copy_to_user((void *)arg, ll_inode2fid(inode),
1595 sizeof(struct lu_fid)))
1598 case LL_IOC_GET_CONNECT_FLAGS: {
1599 RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL, (void*)arg));
1601 case OBD_IOC_CHANGELOG_SEND:
1602 case OBD_IOC_CHANGELOG_CLEAR:
1603 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void *)arg,
1604 sizeof(struct ioc_changelog));
1606 case OBD_IOC_FID2PATH:
1607 RETURN(ll_fid2path(inode, (void *)arg));
1608 case LL_IOC_HSM_REQUEST: {
1609 struct hsm_user_request *hur;
1616 /* We don't know the true size yet; copy the fixed-size part */
1617 if (copy_from_user(hur, (void *)arg, sizeof(*hur))) {
1622 /* Compute the whole struct size */
1623 totalsize = hur_len(hur);
1626 /* Final size will be more than double totalsize */
1627 if (totalsize >= MDS_MAXREQSIZE / 3)
1630 OBD_ALLOC_LARGE(hur, totalsize);
1634 /* Copy the whole struct */
1635 if (copy_from_user(hur, (void *)arg, totalsize)) {
1636 OBD_FREE_LARGE(hur, totalsize);
1640 if (hur->hur_request.hr_action == HUA_RELEASE) {
1641 const struct lu_fid *fid;
1645 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
1646 fid = &hur->hur_user_item[i].hui_fid;
1647 f = search_inode_for_lustre(inode->i_sb, fid);
1653 rc = ll_hsm_release(f);
1659 rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
1663 OBD_FREE_LARGE(hur, totalsize);
1667 case LL_IOC_HSM_PROGRESS: {
1668 struct hsm_progress_kernel hpk;
1669 struct hsm_progress hp;
1671 if (copy_from_user(&hp, (void *)arg, sizeof(hp)))
1674 hpk.hpk_fid = hp.hp_fid;
1675 hpk.hpk_cookie = hp.hp_cookie;
1676 hpk.hpk_extent = hp.hp_extent;
1677 hpk.hpk_flags = hp.hp_flags;
1678 hpk.hpk_errval = hp.hp_errval;
1679 hpk.hpk_data_version = 0;
1681 /* File may not exist in Lustre; all progress
1682 * reported to Lustre root */
1683 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
1687 case LL_IOC_HSM_CT_START:
1688 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
1691 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void *)arg,
1692 sizeof(struct lustre_kernelcomm));
1695 case LL_IOC_HSM_COPY_START: {
1696 struct hsm_copy *copy;
1699 OBD_ALLOC_PTR(copy);
1702 if (copy_from_user(copy, (char *)arg, sizeof(*copy))) {
1707 rc = ll_ioc_copy_start(inode->i_sb, copy);
1708 if (copy_to_user((char *)arg, copy, sizeof(*copy)))
1714 case LL_IOC_HSM_COPY_END: {
1715 struct hsm_copy *copy;
1718 OBD_ALLOC_PTR(copy);
1721 if (copy_from_user(copy, (char *)arg, sizeof(*copy))) {
1726 rc = ll_ioc_copy_end(inode->i_sb, copy);
1727 if (copy_to_user((char *)arg, copy, sizeof(*copy)))
1733 case LL_IOC_MIGRATE: {
1735 const char *filename;
1741 rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
1745 data = (struct obd_ioctl_data *)buf;
1746 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1747 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1748 GOTO(migrate_free, rc = -EINVAL);
1750 filename = data->ioc_inlbuf1;
1751 namelen = data->ioc_inllen1;
1752 /* \0 is packed at the end of filename */
1753 if (namelen < 1 || namelen != strlen(filename) + 1)
1754 GOTO(migrate_free, rc = -EINVAL);
1756 if (data->ioc_inllen2 != sizeof(mdtidx))
1757 GOTO(migrate_free, rc = -EINVAL);
1758 mdtidx = *(int *)data->ioc_inlbuf2;
1760 rc = ll_migrate(inode, file, mdtidx, filename, namelen - 1);
1762 obd_ioctl_freedata(buf, len);
1767 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL,
1772 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
1774 struct inode *inode = file->f_mapping->host;
1775 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1776 struct ll_sb_info *sbi = ll_i2sbi(inode);
1777 int api32 = ll_need_32bit_api(sbi);
1778 loff_t ret = -EINVAL;
1781 mutex_lock(&inode->i_mutex);
1786 offset += file->f_pos;
1792 offset += LL_DIR_END_OFF_32BIT;
1794 offset += LL_DIR_END_OFF;
1801 ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
1802 (!api32 && offset <= LL_DIR_END_OFF))) {
1803 if (offset != file->f_pos) {
1804 if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
1805 (!api32 && offset == LL_DIR_END_OFF))
1806 fd->lfd_pos = MDS_DIR_END_OFF;
1807 else if (api32 && sbi->ll_flags & LL_SBI_64BIT_HASH)
1808 fd->lfd_pos = offset << 32;
1810 fd->lfd_pos = offset;
1811 file->f_pos = offset;
1812 file->f_version = 0;
1819 mutex_unlock(&inode->i_mutex);
1823 static int ll_dir_open(struct inode *inode, struct file *file)
1826 RETURN(ll_file_open(inode, file));
1829 static int ll_dir_release(struct inode *inode, struct file *file)
1832 RETURN(ll_file_release(inode, file));
1835 const struct file_operations ll_dir_operations = {
1836 .llseek = ll_dir_seek,
1837 .open = ll_dir_open,
1838 .release = ll_dir_release,
1839 .read = generic_read_dir,
1840 #ifdef HAVE_DIR_CONTEXT
1841 .iterate = ll_iterate,
1843 .readdir = ll_readdir,
1845 .unlocked_ioctl = ll_dir_ioctl,