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_lib.h>
55 #include <lustre/lustre_idl.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)
164 struct lu_dirent *entry;
165 struct md_callback cb_op;
168 cb_op.md_blocking_ast = ll_md_blocking_ast;
169 rc = md_read_entry(ll_i2mdexp(dir), op_data, &cb_op, &entry);
175 struct lu_dirent *ll_dir_entry_next(struct inode *dir,
176 struct md_op_data *op_data,
177 struct lu_dirent *ent)
179 struct lu_dirent *entry;
180 struct md_callback cb_op;
183 cb_op.md_blocking_ast = ll_md_blocking_ast;
184 op_data->op_hash_offset = le64_to_cpu(ent->lde_hash);
185 rc = md_read_entry(ll_i2mdexp(dir), op_data, &cb_op, &entry);
191 void ll_dir_entry_end(struct inode *dir, struct md_op_data *op_data,
192 struct lu_dirent *ent)
194 struct lu_dirent *entry;
195 struct md_callback cb_op;
197 cb_op.md_blocking_ast = ll_md_blocking_ast;
198 op_data->op_cli_flags = CLI_READENT_END;
199 md_read_entry(ll_i2mdexp(dir), op_data, &cb_op, &entry);
203 int ll_dir_read(struct inode *inode, struct md_op_data *op_data,
204 void *cookie, filldir_t filldir)
206 struct ll_sb_info *sbi = ll_i2sbi(inode);
207 struct ll_dir_chain chain;
208 struct lu_dirent *ent;
209 int api32 = ll_need_32bit_api(sbi);
210 int hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
213 __u64 hash = MDS_DIR_END_OFF;
214 __u64 last_hash = MDS_DIR_END_OFF;
217 ll_dir_chain_init(&chain);
218 for (ent = ll_dir_entry_start(inode, op_data);
219 ent != NULL && !IS_ERR(ent) && !done;
220 ent = ll_dir_entry_next(inode, op_data, ent)) {
227 hash = le64_to_cpu(ent->lde_hash);
228 if (hash < op_data->op_hash_offset)
230 * Skip until we find target hash
234 namelen = le16_to_cpu(ent->lde_namelen);
245 fid_le_to_cpu(&fid, &ent->lde_fid);
246 ino = cl_fid_build_ino(&fid, api32);
247 type = ll_dirent_type_get(ent);
248 /* For 'll_nfs_get_name_filldir()', it will try
249 * to access the 'ent' through its 'lde_name',
250 * so the parameter 'name' for 'filldir()' must
251 * be part of the 'ent'. */
252 done = filldir(cookie, ent->lde_name, namelen, lhash,
255 if (op_data->op_hash_offset != MDS_DIR_END_OFF)
256 op_data->op_hash_offset = last_hash;
265 else if (ent != NULL)
266 ll_dir_entry_end(inode, op_data, ent);
268 ll_dir_chain_fini(&chain);
272 static int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
274 struct inode *inode = filp->f_dentry->d_inode;
275 struct ll_file_data *lfd = LUSTRE_FPRIVATE(filp);
276 struct ll_sb_info *sbi = ll_i2sbi(inode);
277 __u64 pos = lfd->lfd_pos;
278 int hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
279 int api32 = ll_need_32bit_api(sbi);
280 struct md_op_data *op_data;
282 #ifdef HAVE_TOUCH_ATIME_1ARG
292 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) pos/size"
293 "%lu/%llu 32bit_api %d\n", PFID(ll_inode2fid(inode)),
294 inode, (unsigned long)pos, i_size_read(inode), api32);
296 if (pos == MDS_DIR_END_OFF)
302 op_data = ll_prep_md_op_data(NULL, inode, inode, NULL, 0, 0,
303 LUSTRE_OPC_ANY, inode);
305 GOTO(out, rc = PTR_ERR(op_data));
307 op_data->op_hash_offset = pos;
308 op_data->op_max_pages = sbi->ll_md_brw_size >> PAGE_CACHE_SHIFT;
309 rc = ll_dir_read(inode, op_data, cookie, filldir);
311 lfd->lfd_pos = op_data->op_hash_offset;
313 if (pos == MDS_DIR_END_OFF) {
315 filp->f_pos = LL_DIR_END_OFF_32BIT;
317 filp->f_pos = LL_DIR_END_OFF;
320 filp->f_pos = op_data->op_hash_offset >> 32;
322 filp->f_pos = op_data->op_hash_offset;
325 ll_finish_md_op_data(op_data);
326 filp->f_version = inode->i_version;
327 #ifdef HAVE_TOUCH_ATIME_1ARG
328 #ifdef HAVE_F_PATH_MNT
329 path.mnt = filp->f_path.mnt;
331 path.mnt = filp->f_vfsmnt;
333 path.dentry = filp->f_dentry;
336 touch_atime(filp->f_vfsmnt, filp->f_dentry);
341 ll_stats_ops_tally(sbi, LPROC_LL_READDIR, 1);
346 int ll_send_mgc_param(struct obd_export *mgc, char *string)
348 struct mgs_send_param *msp;
355 strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN);
356 rc = obd_set_info_async(NULL, mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
357 sizeof(struct mgs_send_param), msp, NULL);
359 CERROR("Failed to set parameter: %d\n", rc);
365 int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
368 struct ptlrpc_request *request = NULL;
369 struct md_op_data *op_data;
370 struct ll_sb_info *sbi = ll_i2sbi(dir);
376 mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
377 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
378 strlen(filename), mode, LUSTRE_OPC_MKDIR,
381 GOTO(err_exit, err = PTR_ERR(op_data));
383 op_data->op_cli_flags |= CLI_SET_MEA;
384 err = md_create(sbi->ll_md_exp, op_data, lump, sizeof(*lump), mode,
385 current_fsuid(), current_fsgid(),
386 cfs_curproc_cap_pack(), 0, &request);
387 ll_finish_md_op_data(op_data);
391 ptlrpc_req_finished(request);
395 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
398 struct ll_sb_info *sbi = ll_i2sbi(inode);
399 struct md_op_data *op_data;
400 struct ptlrpc_request *req = NULL;
402 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
403 struct obd_device *mgc = lsi->lsi_mgc;
409 * This is coming from userspace, so should be in
410 * local endian. But the MDS would like it in little
411 * endian, so we swab it before we send it.
413 switch (lump->lmm_magic) {
414 case LOV_USER_MAGIC_V1: {
415 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V1))
416 lustre_swab_lov_user_md_v1(lump);
417 lum_size = sizeof(struct lov_user_md_v1);
420 case LOV_USER_MAGIC_V3: {
421 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V3))
422 lustre_swab_lov_user_md_v3(
423 (struct lov_user_md_v3 *)lump);
424 lum_size = sizeof(struct lov_user_md_v3);
428 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
429 " %#08x != %#08x nor %#08x\n",
430 lump->lmm_magic, LOV_USER_MAGIC_V1,
436 lum_size = sizeof(struct lov_user_md_v1);
439 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
440 LUSTRE_OPC_ANY, NULL);
442 RETURN(PTR_ERR(op_data));
444 if (lump != NULL && lump->lmm_magic == cpu_to_le32(LMV_USER_MAGIC))
445 op_data->op_cli_flags |= CLI_SET_MEA;
447 /* swabbing is done in lov_setstripe() on server side */
448 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size,
449 NULL, 0, &req, NULL);
450 ll_finish_md_op_data(op_data);
451 ptlrpc_req_finished(req);
453 if (rc != -EPERM && rc != -EACCES)
454 CERROR("mdc_setattr fails: rc = %d\n", rc);
457 /* In the following we use the fact that LOV_USER_MAGIC_V1 and
458 LOV_USER_MAGIC_V3 have the same initial fields so we do not
459 need the make the distiction between the 2 versions */
460 if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
464 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
466 GOTO(end, rc = -ENOMEM);
469 /* Get fsname and assume devname to be -MDT0000. */
470 ll_get_fsname(inode->i_sb, buf, MTI_NAME_MAXLEN);
471 strcat(buf, "-MDT0000.lov");
474 /* Set root stripesize */
475 sprintf(buf, ".stripesize=%u",
476 lump ? le32_to_cpu(lump->lmm_stripe_size) : 0);
477 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
481 /* Set root stripecount */
482 sprintf(buf, ".stripecount=%hd",
483 lump ? le16_to_cpu(lump->lmm_stripe_count) : 0);
484 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
488 /* Set root stripeoffset */
489 sprintf(buf, ".stripeoffset=%hd",
490 lump ? le16_to_cpu(lump->lmm_stripe_offset) :
491 (typeof(lump->lmm_stripe_offset))(-1));
492 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
496 OBD_FREE(param, MGS_PARAM_MAXLEN);
501 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
502 int *lmm_size, struct ptlrpc_request **request)
504 struct ll_sb_info *sbi = ll_i2sbi(inode);
505 struct mdt_body *body;
506 struct lov_mds_md *lmm = NULL;
507 struct ptlrpc_request *req = NULL;
509 struct md_op_data *op_data;
511 rc = ll_get_max_mdsize(sbi, &lmmsize);
515 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
516 0, lmmsize, LUSTRE_OPC_ANY,
519 RETURN(PTR_ERR(op_data));
521 op_data->op_valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
522 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
523 ll_finish_md_op_data(op_data);
525 CDEBUG(D_INFO, "md_getattr failed on inode "
526 DFID": rc %d\n", PFID(ll_inode2fid(inode)), rc);
530 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
531 LASSERT(body != NULL);
533 lmmsize = body->eadatasize;
535 if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
537 GOTO(out, rc = -ENODATA);
540 lmm = req_capsule_server_sized_get(&req->rq_pill,
541 &RMF_MDT_MD, lmmsize);
542 LASSERT(lmm != NULL);
545 * This is coming from the MDS, so is probably in
546 * little endian. We convert it to host endian before
547 * passing it to userspace.
549 /* We don't swab objects for directories */
550 switch (le32_to_cpu(lmm->lmm_magic)) {
552 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
553 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
556 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
557 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
560 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
571 * Get MDT index for the inode.
573 int ll_get_mdt_idx(struct inode *inode)
575 struct ll_sb_info *sbi = ll_i2sbi(inode);
576 struct md_op_data *op_data;
580 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0,
581 0, LUSTRE_OPC_ANY, NULL);
583 RETURN(PTR_ERR(op_data));
585 op_data->op_flags |= MF_GET_MDT_IDX;
586 rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
587 mdtidx = op_data->op_mds;
588 ll_finish_md_op_data(op_data);
590 CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
597 * Generic handler to do any pre-copy work.
599 * It send a first hsm_progress (with extent length == 0) to coordinator as a
600 * first information for it that real work has started.
602 * Moreover, for a ARCHIVE request, it will sample the file data version and
603 * store it in \a copy.
605 * \return 0 on success.
607 static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
609 struct ll_sb_info *sbi = ll_s2sbi(sb);
610 struct hsm_progress_kernel hpk;
614 /* Forge a hsm_progress based on data from copy. */
615 hpk.hpk_fid = copy->hc_hai.hai_fid;
616 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
617 hpk.hpk_extent.offset = copy->hc_hai.hai_extent.offset;
618 hpk.hpk_extent.length = 0;
621 hpk.hpk_data_version = 0;
624 /* For archive request, we need to read the current file version. */
625 if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
627 __u64 data_version = 0;
629 /* Get inode for this fid */
630 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
632 hpk.hpk_flags |= HP_FLAG_RETRY;
633 /* hpk_errval is >= 0 */
634 hpk.hpk_errval = -PTR_ERR(inode);
635 GOTO(progress, rc = PTR_ERR(inode));
638 /* Read current file data version */
639 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
642 CDEBUG(D_HSM, "Could not read file data version of "
643 DFID" (rc = %d). Archive request ("
644 LPX64") could not be done.\n",
645 PFID(©->hc_hai.hai_fid), rc,
646 copy->hc_hai.hai_cookie);
647 hpk.hpk_flags |= HP_FLAG_RETRY;
648 /* hpk_errval must be >= 0 */
649 hpk.hpk_errval = -rc;
653 /* Store it the hsm_copy for later copytool use.
654 * Always modified even if no lsm. */
655 copy->hc_data_version = data_version;
659 /* On error, the request should be considered as completed */
660 if (hpk.hpk_errval > 0)
661 hpk.hpk_flags |= HP_FLAG_COMPLETED;
662 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
669 * Generic handler to do any post-copy work.
671 * It will send the last hsm_progress update to coordinator to inform it
672 * that copy is finished and whether it was successful or not.
675 * - for ARCHIVE request, it will sample the file data version and compare it
676 * with the version saved in ll_ioc_copy_start(). If they do not match, copy
677 * will be considered as failed.
678 * - for RESTORE request, it will sample the file data version and send it to
679 * coordinator which is useful if the file was imported as 'released'.
681 * \return 0 on success.
683 static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
685 struct ll_sb_info *sbi = ll_s2sbi(sb);
686 struct hsm_progress_kernel hpk;
690 /* If you modify the logic here, also check llapi_hsm_copy_end(). */
691 /* Take care: copy->hc_hai.hai_action, len, gid and data are not
692 * initialized if copy_end was called with copy == NULL.
695 /* Forge a hsm_progress based on data from copy. */
696 hpk.hpk_fid = copy->hc_hai.hai_fid;
697 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
698 hpk.hpk_extent = copy->hc_hai.hai_extent;
699 hpk.hpk_flags = copy->hc_flags | HP_FLAG_COMPLETED;
700 hpk.hpk_errval = copy->hc_errval;
701 hpk.hpk_data_version = 0;
703 /* For archive request, we need to check the file data was not changed.
705 * For restore request, we need to send the file data version, this is
706 * useful when the file was created using hsm_import.
708 if (((copy->hc_hai.hai_action == HSMA_ARCHIVE) ||
709 (copy->hc_hai.hai_action == HSMA_RESTORE)) &&
710 (copy->hc_errval == 0)) {
712 __u64 data_version = 0;
714 /* Get lsm for this fid */
715 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
717 hpk.hpk_flags |= HP_FLAG_RETRY;
718 /* hpk_errval must be >= 0 */
719 hpk.hpk_errval = -PTR_ERR(inode);
720 GOTO(progress, rc = PTR_ERR(inode));
723 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
726 CDEBUG(D_HSM, "Could not read file data version. "
727 "Request could not be confirmed.\n");
728 if (hpk.hpk_errval == 0)
729 hpk.hpk_errval = -rc;
733 /* Store it the hsm_copy for later copytool use.
734 * Always modified even if no lsm. */
735 hpk.hpk_data_version = data_version;
737 /* File could have been stripped during archiving, so we need
738 * to check anyway. */
739 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
740 (copy->hc_data_version != data_version)) {
741 CDEBUG(D_HSM, "File data version mismatched. "
742 "File content was changed during archiving. "
743 DFID", start:"LPX64" current:"LPX64"\n",
744 PFID(©->hc_hai.hai_fid),
745 copy->hc_data_version, data_version);
746 /* File was changed, send error to cdt. Do not ask for
747 * retry because if a file is modified frequently,
748 * the cdt will loop on retried archive requests.
749 * The policy engine will ask for a new archive later
750 * when the file will not be modified for some tunable
752 /* we do not notify caller */
753 hpk.hpk_flags &= ~HP_FLAG_RETRY;
754 /* hpk_errval must be >= 0 */
755 hpk.hpk_errval = EBUSY;
761 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
768 static int copy_and_ioctl(int cmd, struct obd_export *exp,
769 const void __user *data, size_t size)
774 OBD_ALLOC(copy, size);
778 if (copy_from_user(copy, data, size)) {
783 rc = obd_iocontrol(cmd, exp, size, copy, NULL);
785 OBD_FREE(copy, size);
790 static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
792 int cmd = qctl->qc_cmd;
793 int type = qctl->qc_type;
794 int id = qctl->qc_id;
795 int valid = qctl->qc_valid;
800 case LUSTRE_Q_INVALIDATE:
801 case LUSTRE_Q_FINVALIDATE:
806 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
807 sbi->ll_flags & LL_SBI_RMT_CLIENT)
811 if (((type == USRQUOTA && current_euid() != id) ||
812 (type == GRPQUOTA && !in_egroup_p(id))) &&
813 (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
814 sbi->ll_flags & LL_SBI_RMT_CLIENT))
820 CERROR("unsupported quotactl op: %#x\n", cmd);
824 if (valid != QC_GENERAL) {
825 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
828 if (cmd == Q_GETINFO)
829 qctl->qc_cmd = Q_GETOINFO;
830 else if (cmd == Q_GETQUOTA)
831 qctl->qc_cmd = Q_GETOQUOTA;
837 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
838 sizeof(*qctl), qctl, NULL);
841 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
842 sizeof(*qctl), qctl, NULL);
845 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
846 sizeof(*qctl), qctl, NULL);
848 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
850 sizeof(*qctl), qctl, NULL);
862 struct obd_quotactl *oqctl;
864 OBD_ALLOC_PTR(oqctl);
868 QCTL_COPY(oqctl, qctl);
869 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
871 if (rc != -EALREADY && cmd == Q_QUOTAON) {
872 oqctl->qc_cmd = Q_QUOTAOFF;
873 obd_quotactl(sbi->ll_md_exp, oqctl);
878 /* If QIF_SPACE is not set, client should collect the
879 * space usage from OSSs by itself */
880 if (cmd == Q_GETQUOTA &&
881 !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
882 !oqctl->qc_dqblk.dqb_curspace) {
883 struct obd_quotactl *oqctl_tmp;
885 OBD_ALLOC_PTR(oqctl_tmp);
886 if (oqctl_tmp == NULL)
887 GOTO(out, rc = -ENOMEM);
889 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
890 oqctl_tmp->qc_id = oqctl->qc_id;
891 oqctl_tmp->qc_type = oqctl->qc_type;
893 /* collect space usage from OSTs */
894 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
895 rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
896 if (!rc || rc == -EREMOTEIO) {
897 oqctl->qc_dqblk.dqb_curspace =
898 oqctl_tmp->qc_dqblk.dqb_curspace;
899 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
902 /* collect space & inode usage from MDTs */
903 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
904 oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
905 rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
906 if (!rc || rc == -EREMOTEIO) {
907 oqctl->qc_dqblk.dqb_curspace +=
908 oqctl_tmp->qc_dqblk.dqb_curspace;
909 oqctl->qc_dqblk.dqb_curinodes =
910 oqctl_tmp->qc_dqblk.dqb_curinodes;
911 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
913 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
916 OBD_FREE_PTR(oqctl_tmp);
919 QCTL_COPY(qctl, oqctl);
927 ll_getname(const char __user *filename)
930 char *tmp = __getname();
933 return ERR_PTR(-ENOMEM);
935 len = strncpy_from_user(tmp, filename, PATH_MAX);
938 else if (len > PATH_MAX)
948 #define ll_putname(filename) __putname(filename)
950 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
952 struct inode *inode = file->f_dentry->d_inode;
953 struct ll_sb_info *sbi = ll_i2sbi(inode);
954 struct obd_ioctl_data *data;
958 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%#x\n",
959 PFID(ll_inode2fid(inode)), inode, cmd);
961 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
962 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
965 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
967 case FSFILT_IOC_GETFLAGS:
968 case FSFILT_IOC_SETFLAGS:
969 RETURN(ll_iocontrol(inode, file, cmd, arg));
970 case FSFILT_IOC_GETVERSION_OLD:
971 case FSFILT_IOC_GETVERSION:
972 RETURN(put_user(inode->i_generation, (int *)arg));
973 /* We need to special case any other ioctls we want to handle,
974 * to send them to the MDS/OST as appropriate and to properly
975 * network encode the arg field.
976 case FSFILT_IOC_SETVERSION_OLD:
977 case FSFILT_IOC_SETVERSION:
979 case LL_IOC_GET_MDTIDX: {
982 mdtidx = ll_get_mdt_idx(inode);
986 if (put_user((int)mdtidx, (int*)arg))
991 case IOC_MDC_LOOKUP: {
992 struct ptlrpc_request *request = NULL;
993 int namelen, len = 0;
996 struct md_op_data *op_data;
998 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
1003 filename = data->ioc_inlbuf1;
1004 namelen = strlen(filename);
1007 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1008 GOTO(out_free, rc = -EINVAL);
1011 op_data = ll_prep_md_op_data(NULL, inode, NULL, filename, namelen,
1012 0, LUSTRE_OPC_ANY, NULL);
1013 if (IS_ERR(op_data))
1014 GOTO(out_free, rc = PTR_ERR(op_data));
1016 op_data->op_valid = OBD_MD_FLID;
1017 rc = md_getattr_name(sbi->ll_md_exp, op_data, &request);
1018 ll_finish_md_op_data(op_data);
1020 CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
1023 ptlrpc_req_finished(request);
1026 obd_ioctl_freedata(buf, len);
1029 case LL_IOC_LMV_SETSTRIPE: {
1030 struct lmv_user_md *lum;
1038 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
1043 if (data->ioc_inlbuf1 == NULL || data->ioc_inlbuf2 == NULL ||
1044 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0)
1045 GOTO(lmv_out_free, rc = -EINVAL);
1047 filename = data->ioc_inlbuf1;
1048 namelen = data->ioc_inllen1;
1051 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1052 GOTO(lmv_out_free, rc = -EINVAL);
1054 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1055 lumlen = data->ioc_inllen2;
1057 if (lum->lum_magic != LMV_USER_MAGIC ||
1058 lumlen != sizeof(*lum)) {
1059 CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1060 filename, lum->lum_magic, lumlen, -EFAULT);
1061 GOTO(lmv_out_free, rc = -EINVAL);
1065 * ll_dir_setdirstripe will be used to set dir stripe
1066 * mdc_create--->mdt_reint_create (with dirstripe)
1068 rc = ll_dir_setdirstripe(inode, lum, filename);
1070 obd_ioctl_freedata(buf, len);
1074 case LL_IOC_LOV_SETSTRIPE: {
1075 struct lov_user_md_v3 lumv3;
1076 struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
1077 struct lov_user_md_v1 *lumv1p = (struct lov_user_md_v1 *)arg;
1078 struct lov_user_md_v3 *lumv3p = (struct lov_user_md_v3 *)arg;
1080 int set_default = 0;
1082 LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
1083 LASSERT(sizeof(lumv3.lmm_objects[0]) ==
1084 sizeof(lumv3p->lmm_objects[0]));
1085 /* first try with v1 which is smaller than v3 */
1086 if (copy_from_user(lumv1, lumv1p, sizeof(*lumv1)))
1089 if ((lumv1->lmm_magic == LOV_USER_MAGIC_V3) ) {
1090 if (copy_from_user(&lumv3, lumv3p, sizeof(lumv3)))
1094 if (inode->i_sb->s_root == file->f_dentry)
1097 /* in v1 and v3 cases lumv1 points to data */
1098 rc = ll_dir_setstripe(inode, lumv1, set_default);
1102 case LL_IOC_LMV_GETSTRIPE: {
1103 struct lmv_user_md *lump = (struct lmv_user_md *)arg;
1104 struct lmv_user_md lum;
1105 struct lmv_user_md *tmp;
1110 if (copy_from_user(&lum, lump, sizeof(struct lmv_user_md)))
1113 if (lum.lum_magic != LMV_MAGIC_V1)
1116 lum_size = lmv_user_md_size(1, LMV_MAGIC_V1);
1117 OBD_ALLOC(tmp, lum_size);
1119 GOTO(free_lmv, rc = -ENOMEM);
1121 memcpy(tmp, &lum, sizeof(lum));
1122 tmp->lum_type = LMV_STRIPE_TYPE;
1123 tmp->lum_stripe_count = 1;
1124 mdtindex = ll_get_mdt_idx(inode);
1126 GOTO(free_lmv, rc = -ENOMEM);
1128 tmp->lum_stripe_offset = mdtindex;
1129 tmp->lum_objects[0].lum_mds = mdtindex;
1130 memcpy(&tmp->lum_objects[0].lum_fid, ll_inode2fid(inode),
1131 sizeof(struct lu_fid));
1132 if (copy_to_user((void *)arg, tmp, lum_size))
1133 GOTO(free_lmv, rc = -EFAULT);
1136 OBD_FREE(tmp, lum_size);
1139 case LL_IOC_REMOVE_ENTRY: {
1140 char *filename = NULL;
1144 /* Here is a little hack to avoid sending REINT_RMENTRY to
1145 * unsupported server, which might crash the server(LU-2730),
1146 * Because both LVB_TYPE and REINT_RMENTRY will be supported
1147 * on 2.4, we use OBD_CONNECT_LVB_TYPE to detect whether the
1148 * server will support REINT_RMENTRY XXX*/
1149 if (!(exp_connect_flags(sbi->ll_md_exp) & OBD_CONNECT_LVB_TYPE))
1152 filename = ll_getname((const char *)arg);
1153 if (IS_ERR(filename))
1154 RETURN(PTR_ERR(filename));
1156 namelen = strlen(filename);
1158 GOTO(out_rmdir, rc = -EINVAL);
1160 rc = ll_rmdir_entry(inode, filename, namelen);
1163 ll_putname(filename);
1166 case LL_IOC_LOV_SWAP_LAYOUTS:
1168 case LL_IOC_OBD_STATFS:
1169 RETURN(ll_obd_statfs(inode, (void *)arg));
1170 case LL_IOC_LOV_GETSTRIPE:
1171 case LL_IOC_MDC_GETINFO:
1172 case IOC_MDC_GETFILEINFO:
1173 case IOC_MDC_GETFILESTRIPE: {
1174 struct ptlrpc_request *request = NULL;
1175 struct lov_user_md *lump;
1176 struct lov_mds_md *lmm = NULL;
1177 struct mdt_body *body;
1178 char *filename = NULL;
1181 if (cmd == IOC_MDC_GETFILEINFO ||
1182 cmd == IOC_MDC_GETFILESTRIPE) {
1183 filename = ll_getname((const char *)arg);
1184 if (IS_ERR(filename))
1185 RETURN(PTR_ERR(filename));
1187 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1188 &lmmsize, &request);
1190 rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
1194 body = req_capsule_server_get(&request->rq_pill,
1196 LASSERT(body != NULL);
1202 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
1203 cmd == LL_IOC_MDC_GETINFO))
1204 GOTO(skip_lmm, rc = 0);
1209 if (cmd == IOC_MDC_GETFILESTRIPE ||
1210 cmd == LL_IOC_LOV_GETSTRIPE) {
1211 lump = (struct lov_user_md *)arg;
1213 struct lov_user_mds_data *lmdp;
1214 lmdp = (struct lov_user_mds_data *)arg;
1215 lump = &lmdp->lmd_lmm;
1217 if (copy_to_user(lump, lmm, lmmsize)) {
1218 if (copy_to_user(lump, lmm, sizeof(*lump)))
1219 GOTO(out_req, rc = -EFAULT);
1223 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
1224 struct lov_user_mds_data *lmdp;
1227 st.st_dev = inode->i_sb->s_dev;
1228 st.st_mode = body->mode;
1229 st.st_nlink = body->nlink;
1230 st.st_uid = body->uid;
1231 st.st_gid = body->gid;
1232 st.st_rdev = body->rdev;
1233 st.st_size = body->size;
1234 st.st_blksize = PAGE_CACHE_SIZE;
1235 st.st_blocks = body->blocks;
1236 st.st_atime = body->atime;
1237 st.st_mtime = body->mtime;
1238 st.st_ctime = body->ctime;
1239 st.st_ino = inode->i_ino;
1241 lmdp = (struct lov_user_mds_data *)arg;
1242 if (copy_to_user(&lmdp->lmd_st, &st, sizeof(st)))
1243 GOTO(out_req, rc = -EFAULT);
1248 ptlrpc_req_finished(request);
1250 ll_putname(filename);
1253 case IOC_LOV_GETINFO: {
1254 struct lov_user_mds_data *lumd;
1255 struct lov_stripe_md *lsm;
1256 struct lov_user_md *lum;
1257 struct lov_mds_md *lmm;
1261 lumd = (struct lov_user_mds_data *)arg;
1262 lum = &lumd->lmd_lmm;
1264 rc = ll_get_max_mdsize(sbi, &lmmsize);
1268 OBD_ALLOC_LARGE(lmm, lmmsize);
1272 if (copy_from_user(lmm, lum, lmmsize))
1273 GOTO(free_lmm, rc = -EFAULT);
1275 switch (lmm->lmm_magic) {
1276 case LOV_USER_MAGIC_V1:
1277 if (LOV_USER_MAGIC_V1 == cpu_to_le32(LOV_USER_MAGIC_V1))
1279 /* swab objects first so that stripes num will be sane */
1280 lustre_swab_lov_user_md_objects(
1281 ((struct lov_user_md_v1 *)lmm)->lmm_objects,
1282 ((struct lov_user_md_v1 *)lmm)->lmm_stripe_count);
1283 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
1285 case LOV_USER_MAGIC_V3:
1286 if (LOV_USER_MAGIC_V3 == cpu_to_le32(LOV_USER_MAGIC_V3))
1288 /* swab objects first so that stripes num will be sane */
1289 lustre_swab_lov_user_md_objects(
1290 ((struct lov_user_md_v3 *)lmm)->lmm_objects,
1291 ((struct lov_user_md_v3 *)lmm)->lmm_stripe_count);
1292 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
1295 GOTO(free_lmm, rc = -EINVAL);
1298 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
1300 GOTO(free_lmm, rc = -ENOMEM);
1302 /* Perform glimpse_size operation. */
1303 memset(&st, 0, sizeof(st));
1305 rc = ll_glimpse_ioctl(sbi, lsm, &st);
1309 if (copy_to_user(&lumd->lmd_st, &st, sizeof(st)))
1310 GOTO(free_lsm, rc = -EFAULT);
1314 obd_free_memmd(sbi->ll_dt_exp, &lsm);
1316 OBD_FREE_LARGE(lmm, lmmsize);
1319 case OBD_IOC_LLOG_CATINFO: {
1320 RETURN(-EOPNOTSUPP);
1322 case OBD_IOC_QUOTACHECK: {
1323 struct obd_quotactl *oqctl;
1326 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1327 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1330 OBD_ALLOC_PTR(oqctl);
1333 oqctl->qc_type = arg;
1334 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
1336 CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
1340 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
1342 CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
1344 OBD_FREE_PTR(oqctl);
1347 case OBD_IOC_POLL_QUOTACHECK: {
1348 struct if_quotacheck *check;
1350 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1351 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1354 OBD_ALLOC_PTR(check);
1358 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
1361 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
1362 if (copy_to_user((void *)arg, check,
1364 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1368 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
1371 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
1372 if (copy_to_user((void *)arg, check,
1374 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1378 OBD_FREE_PTR(check);
1381 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
1382 case LL_IOC_QUOTACTL_18: {
1383 /* copy the old 1.x quota struct for internal use, then copy
1384 * back into old format struct. For 1.8 compatibility. */
1385 struct if_quotactl_18 *qctl_18;
1386 struct if_quotactl *qctl_20;
1388 OBD_ALLOC_PTR(qctl_18);
1392 OBD_ALLOC_PTR(qctl_20);
1394 GOTO(out_quotactl_18, rc = -ENOMEM);
1396 if (copy_from_user(qctl_18, (void *)arg, sizeof(*qctl_18)))
1397 GOTO(out_quotactl_20, rc = -ENOMEM);
1399 QCTL_COPY(qctl_20, qctl_18);
1400 qctl_20->qc_idx = 0;
1402 /* XXX: dqb_valid was borrowed as a flag to mark that
1403 * only mds quota is wanted */
1404 if (qctl_18->qc_cmd == Q_GETQUOTA &&
1405 qctl_18->qc_dqblk.dqb_valid) {
1406 qctl_20->qc_valid = QC_MDTIDX;
1407 qctl_20->qc_dqblk.dqb_valid = 0;
1408 } else if (qctl_18->obd_uuid.uuid[0] != '\0') {
1409 qctl_20->qc_valid = QC_UUID;
1410 qctl_20->obd_uuid = qctl_18->obd_uuid;
1412 qctl_20->qc_valid = QC_GENERAL;
1415 rc = quotactl_ioctl(sbi, qctl_20);
1418 QCTL_COPY(qctl_18, qctl_20);
1419 qctl_18->obd_uuid = qctl_20->obd_uuid;
1421 if (copy_to_user((void *)arg, qctl_18,
1427 OBD_FREE_PTR(qctl_20);
1429 OBD_FREE_PTR(qctl_18);
1433 #warning "remove old LL_IOC_QUOTACTL_18 compatibility code"
1434 #endif /* LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0) */
1435 case LL_IOC_QUOTACTL: {
1436 struct if_quotactl *qctl;
1438 OBD_ALLOC_PTR(qctl);
1442 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
1443 GOTO(out_quotactl, rc = -EFAULT);
1445 rc = quotactl_ioctl(sbi, qctl);
1447 if (rc == 0 && copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1454 case OBD_IOC_GETDTNAME:
1455 case OBD_IOC_GETMDNAME:
1456 RETURN(ll_get_obd_name(inode, cmd, arg));
1457 case LL_IOC_FLUSHCTX:
1458 RETURN(ll_flush_ctx(inode));
1459 #ifdef CONFIG_FS_POSIX_ACL
1460 case LL_IOC_RMTACL: {
1461 if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
1462 inode == inode->i_sb->s_root->d_inode) {
1463 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1465 LASSERT(fd != NULL);
1466 rc = rct_add(&sbi->ll_rct, current_pid(), arg);
1468 fd->fd_flags |= LL_FILE_RMTACL;
1474 case LL_IOC_GETOBDCOUNT: {
1476 struct obd_export *exp;
1478 if (copy_from_user(&count, (int *)arg, sizeof(int)))
1481 /* get ost count when count is zero, get mdt count otherwise */
1482 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
1483 vallen = sizeof(count);
1484 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
1485 KEY_TGT_COUNT, &vallen, &count, NULL);
1487 CERROR("get target count failed: %d\n", rc);
1491 if (copy_to_user((int *)arg, &count, sizeof(int)))
1496 case LL_IOC_PATH2FID:
1497 if (copy_to_user((void *)arg, ll_inode2fid(inode),
1498 sizeof(struct lu_fid)))
1501 case LL_IOC_GET_CONNECT_FLAGS: {
1502 RETURN(obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL, (void*)arg));
1504 case OBD_IOC_CHANGELOG_SEND:
1505 case OBD_IOC_CHANGELOG_CLEAR:
1506 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void *)arg,
1507 sizeof(struct ioc_changelog));
1509 case OBD_IOC_FID2PATH:
1510 RETURN(ll_fid2path(inode, (void *)arg));
1511 case LL_IOC_HSM_REQUEST: {
1512 struct hsm_user_request *hur;
1519 /* We don't know the true size yet; copy the fixed-size part */
1520 if (copy_from_user(hur, (void *)arg, sizeof(*hur))) {
1525 /* Compute the whole struct size */
1526 totalsize = hur_len(hur);
1529 /* Make sure the size is reasonable */
1530 if (totalsize >= MDS_MAXREQSIZE)
1533 OBD_ALLOC_LARGE(hur, totalsize);
1537 /* Copy the whole struct */
1538 if (copy_from_user(hur, (void *)arg, totalsize)) {
1539 OBD_FREE_LARGE(hur, totalsize);
1543 if (hur->hur_request.hr_action == HUA_RELEASE) {
1544 const struct lu_fid *fid;
1548 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
1549 fid = &hur->hur_user_item[i].hui_fid;
1550 f = search_inode_for_lustre(inode->i_sb, fid);
1556 rc = ll_hsm_release(f);
1562 rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
1566 OBD_FREE_LARGE(hur, totalsize);
1570 case LL_IOC_HSM_PROGRESS: {
1571 struct hsm_progress_kernel hpk;
1572 struct hsm_progress hp;
1574 if (copy_from_user(&hp, (void *)arg, sizeof(hp)))
1577 hpk.hpk_fid = hp.hp_fid;
1578 hpk.hpk_cookie = hp.hp_cookie;
1579 hpk.hpk_extent = hp.hp_extent;
1580 hpk.hpk_flags = hp.hp_flags;
1581 hpk.hpk_errval = hp.hp_errval;
1582 hpk.hpk_data_version = 0;
1584 /* File may not exist in Lustre; all progress
1585 * reported to Lustre root */
1586 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
1590 case LL_IOC_HSM_CT_START:
1591 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
1594 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void *)arg,
1595 sizeof(struct lustre_kernelcomm));
1598 case LL_IOC_HSM_COPY_START: {
1599 struct hsm_copy *copy;
1602 OBD_ALLOC_PTR(copy);
1605 if (copy_from_user(copy, (char *)arg, sizeof(*copy))) {
1610 rc = ll_ioc_copy_start(inode->i_sb, copy);
1611 if (copy_to_user((char *)arg, copy, sizeof(*copy)))
1617 case LL_IOC_HSM_COPY_END: {
1618 struct hsm_copy *copy;
1621 OBD_ALLOC_PTR(copy);
1624 if (copy_from_user(copy, (char *)arg, sizeof(*copy))) {
1629 rc = ll_ioc_copy_end(inode->i_sb, copy);
1630 if (copy_to_user((char *)arg, copy, sizeof(*copy)))
1637 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL,
1642 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
1644 struct inode *inode = file->f_mapping->host;
1645 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1646 struct ll_sb_info *sbi = ll_i2sbi(inode);
1647 int api32 = ll_need_32bit_api(sbi);
1648 loff_t ret = -EINVAL;
1651 mutex_lock(&inode->i_mutex);
1656 offset += file->f_pos;
1662 offset += LL_DIR_END_OFF_32BIT;
1664 offset += LL_DIR_END_OFF;
1671 ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
1672 (!api32 && offset <= LL_DIR_END_OFF))) {
1673 if (offset != file->f_pos) {
1674 if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
1675 (!api32 && offset == LL_DIR_END_OFF))
1676 fd->lfd_pos = MDS_DIR_END_OFF;
1677 else if (api32 && sbi->ll_flags & LL_SBI_64BIT_HASH)
1678 fd->lfd_pos = offset << 32;
1680 fd->lfd_pos = offset;
1681 file->f_pos = offset;
1682 file->f_version = 0;
1689 mutex_unlock(&inode->i_mutex);
1693 int ll_dir_open(struct inode *inode, struct file *file)
1696 RETURN(ll_file_open(inode, file));
1699 int ll_dir_release(struct inode *inode, struct file *file)
1702 RETURN(ll_file_release(inode, file));
1705 struct file_operations ll_dir_operations = {
1706 .llseek = ll_dir_seek,
1707 .open = ll_dir_open,
1708 .release = ll_dir_release,
1709 .read = generic_read_dir,
1710 .readdir = ll_readdir,
1711 .unlocked_ioctl = ll_dir_ioctl,