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, 2015, 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/uaccess.h>
45 #include <linux/buffer_head.h> /* for wait_on_buffer */
46 #include <linux/pagevec.h>
47 #include <linux/prefetch.h>
49 #define DEBUG_SUBSYSTEM S_LLITE
51 #include "../include/obd_support.h"
52 #include "../include/obd_class.h"
53 #include "../include/lustre_lib.h"
54 #include "../include/lustre/lustre_idl.h"
55 #include "../include/lustre_lite.h"
56 #include "../include/lustre_dlm.h"
57 #include "../include/lustre_fid.h"
58 #include "../include/lustre_kernelcomm.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_SIZE (if PAGE_SIZE greater than LU_PAGE_SIZE), and the lu_dirpage
138 * for this integrated page will be adjusted. See lmv_adjust_dirpages().
142 /* returns the page unlocked, but with a reference */
143 static int ll_dir_filler(void *_hash, struct page *page0)
145 struct inode *inode = page0->mapping->host;
146 int hash64 = ll_i2sbi(inode)->ll_flags & LL_SBI_64BIT_HASH;
147 struct obd_export *exp = ll_i2sbi(inode)->ll_md_exp;
148 struct ptlrpc_request *request;
149 struct mdt_body *body;
150 struct md_op_data *op_data;
151 __u64 hash = *((__u64 *)_hash);
152 struct page **page_pool;
154 struct lu_dirpage *dp;
155 int max_pages = ll_i2sbi(inode)->ll_md_brw_size >> PAGE_SHIFT;
156 int nrdpgs = 0; /* number of pages read actually */
161 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) hash %llu\n",
162 PFID(ll_inode2fid(inode)), inode, hash);
164 LASSERT(max_pages > 0 && max_pages <= MD_MAX_BRW_PAGES);
166 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
167 LUSTRE_OPC_ANY, NULL);
169 return PTR_ERR(op_data);
171 page_pool = kcalloc(max_pages, sizeof(page), GFP_NOFS);
173 page_pool[0] = page0;
178 for (npages = 1; npages < max_pages; npages++) {
179 page = page_cache_alloc_cold(inode->i_mapping);
182 page_pool[npages] = page;
185 op_data->op_npages = npages;
186 op_data->op_offset = hash;
187 rc = md_readpage(exp, op_data, page_pool, &request);
188 ll_finish_md_op_data(op_data);
190 /* page0 is special, which was added into page cache early */
191 delete_from_page_cache(page0);
192 } else if (rc == 0) {
193 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
194 /* Checked by mdc_readpage() */
195 if (body->valid & OBD_MD_FLSIZE)
196 i_size_write(inode, body->size);
198 nrdpgs = (request->rq_bulk->bd_nob_transferred+PAGE_SIZE-1)
200 SetPageUptodate(page0);
203 ptlrpc_req_finished(request);
205 CDEBUG(D_VFSTRACE, "read %d/%d pages\n", nrdpgs, npages);
207 for (i = 1; i < npages; i++) {
208 unsigned long offset;
213 if (rc < 0 || i >= nrdpgs) {
218 SetPageUptodate(page);
221 hash = le64_to_cpu(dp->ldp_hash_start);
224 offset = hash_x_index(hash, hash64);
226 prefetchw(&page->flags);
227 ret = add_to_page_cache_lru(page, inode->i_mapping, offset,
232 CDEBUG(D_VFSTRACE, "page %lu add to page cache failed: %d\n",
238 if (page_pool != &page0)
243 void ll_release_page(struct page *page, int remove)
248 if (likely(page->mapping))
249 truncate_complete_page(page->mapping, page);
256 * Find, kmap and return page that contains given hash.
258 static struct page *ll_dir_page_locate(struct inode *dir, __u64 *hash,
259 __u64 *start, __u64 *end)
261 int hash64 = ll_i2sbi(dir)->ll_flags & LL_SBI_64BIT_HASH;
262 struct address_space *mapping = dir->i_mapping;
264 * Complement of hash is used as an index so that
265 * radix_tree_gang_lookup() can be used to find a page with starting
266 * hash _smaller_ than one we are looking for.
268 unsigned long offset = hash_x_index(*hash, hash64);
272 spin_lock_irq(&mapping->tree_lock);
273 found = radix_tree_gang_lookup(&mapping->page_tree,
274 (void **)&page, offset, 1);
275 if (found > 0 && !radix_tree_exceptional_entry(page)) {
276 struct lu_dirpage *dp;
279 spin_unlock_irq(&mapping->tree_lock);
281 * In contrast to find_lock_page() we are sure that directory
282 * page cannot be truncated (while DLM lock is held) and,
283 * hence, can avoid restart.
285 * In fact, page cannot be locked here at all, because
286 * ll_dir_filler() does synchronous io.
288 wait_on_page_locked(page);
289 if (PageUptodate(page)) {
291 if (BITS_PER_LONG == 32 && hash64) {
292 *start = le64_to_cpu(dp->ldp_hash_start) >> 32;
293 *end = le64_to_cpu(dp->ldp_hash_end) >> 32;
296 *start = le64_to_cpu(dp->ldp_hash_start);
297 *end = le64_to_cpu(dp->ldp_hash_end);
299 LASSERTF(*start <= *hash, "start = %#llx,end = %#llx,hash = %#llx\n",
300 *start, *end, *hash);
301 CDEBUG(D_VFSTRACE, "page %lu [%llu %llu], hash %llu\n",
302 offset, *start, *end, *hash);
304 ll_release_page(page, 0);
306 } else if (*end != *start && *hash == *end) {
308 * upon hash collision, remove this page,
309 * otherwise put page reference, and
310 * ll_get_dir_page() will issue RPC to fetch
313 ll_release_page(page,
314 le32_to_cpu(dp->ldp_flags) & LDF_COLLIDE);
319 page = ERR_PTR(-EIO);
323 spin_unlock_irq(&mapping->tree_lock);
329 struct page *ll_get_dir_page(struct inode *dir, __u64 hash,
330 struct ll_dir_chain *chain)
332 ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_UPDATE} };
333 struct address_space *mapping = dir->i_mapping;
334 struct lustre_handle lockh;
335 struct lu_dirpage *dp;
342 struct ll_inode_info *lli = ll_i2info(dir);
343 int hash64 = ll_i2sbi(dir)->ll_flags & LL_SBI_64BIT_HASH;
346 rc = md_lock_match(ll_i2sbi(dir)->ll_md_exp, LDLM_FL_BLOCK_GRANTED,
347 ll_inode2fid(dir), LDLM_IBITS, &policy, mode, &lockh);
349 struct ldlm_enqueue_info einfo = {
350 .ei_type = LDLM_IBITS,
352 .ei_cb_bl = ll_md_blocking_ast,
353 .ei_cb_cp = ldlm_completion_ast,
355 struct lookup_intent it = { .it_op = IT_READDIR };
356 struct ptlrpc_request *request;
357 struct md_op_data *op_data;
359 op_data = ll_prep_md_op_data(NULL, dir, dir, NULL, 0, 0,
360 LUSTRE_OPC_ANY, NULL);
362 return (void *)op_data;
364 rc = md_enqueue(ll_i2sbi(dir)->ll_md_exp, &einfo, &it,
365 op_data, &lockh, NULL, 0, NULL, 0);
367 ll_finish_md_op_data(op_data);
369 request = (struct ptlrpc_request *)it.d.lustre.it_data;
371 ptlrpc_req_finished(request);
373 CERROR("lock enqueue: " DFID " at %llu: rc %d\n",
374 PFID(ll_inode2fid(dir)), hash, rc);
378 CDEBUG(D_INODE, "setting lr_lvb_inode to inode "DFID"(%p)\n",
379 PFID(ll_inode2fid(dir)), dir);
380 md_set_lock_data(ll_i2sbi(dir)->ll_md_exp,
381 &it.d.lustre.it_lock_handle, dir, NULL);
383 /* for cross-ref object, l_ast_data of the lock may not be set,
386 md_set_lock_data(ll_i2sbi(dir)->ll_md_exp, &lockh.cookie,
389 ldlm_lock_dump_handle(D_OTHER, &lockh);
391 mutex_lock(&lli->lli_readdir_mutex);
392 page = ll_dir_page_locate(dir, &lhash, &start, &end);
394 CERROR("dir page locate: "DFID" at %llu: rc %ld\n",
395 PFID(ll_inode2fid(dir)), lhash, PTR_ERR(page));
399 * XXX nikita: not entirely correct handling of a corner case:
400 * suppose hash chain of entries with hash value HASH crosses
401 * border between pages P0 and P1. First both P0 and P1 are
402 * cached, seekdir() is called for some entry from the P0 part
403 * of the chain. Later P0 goes out of cache. telldir(HASH)
404 * happens and finds P1, as it starts with matching hash
405 * value. Remaining entries from P0 part of the chain are
406 * skipped. (Is that really a bug?)
408 * Possible solutions: 0. don't cache P1 is such case, handle
409 * it as an "overflow" page. 1. invalidate all pages at
410 * once. 2. use HASH|1 as an index for P1.
415 page = read_cache_page(mapping, hash_x_index(hash, hash64),
416 ll_dir_filler, &lhash);
418 CERROR("read cache page: "DFID" at %llu: rc %ld\n",
419 PFID(ll_inode2fid(dir)), hash, PTR_ERR(page));
423 wait_on_page_locked(page);
425 if (!PageUptodate(page)) {
426 CERROR("page not updated: "DFID" at %llu: rc %d\n",
427 PFID(ll_inode2fid(dir)), hash, -5);
430 if (!PageChecked(page))
431 /* XXX: check page format later */
432 SetPageChecked(page);
433 if (PageError(page)) {
434 CERROR("page error: "DFID" at %llu: rc %d\n",
435 PFID(ll_inode2fid(dir)), hash, -5);
439 dp = page_address(page);
440 if (BITS_PER_LONG == 32 && hash64) {
441 start = le64_to_cpu(dp->ldp_hash_start) >> 32;
442 end = le64_to_cpu(dp->ldp_hash_end) >> 32;
445 start = le64_to_cpu(dp->ldp_hash_start);
446 end = le64_to_cpu(dp->ldp_hash_end);
450 LASSERT(start == lhash);
451 CWARN("Page-wide hash collision: %llu\n", end);
452 if (BITS_PER_LONG == 32 && hash64)
453 CWARN("Real page-wide hash collision at [%llu %llu] with hash %llu\n",
454 le64_to_cpu(dp->ldp_hash_start),
455 le64_to_cpu(dp->ldp_hash_end), hash);
457 * Fetch whole overflow chain...
464 mutex_unlock(&lli->lli_readdir_mutex);
465 ldlm_lock_decref(&lockh, mode);
469 ll_release_page(page, 1);
470 page = ERR_PTR(-EIO);
475 * return IF_* type for given lu_dirent entry.
476 * IF_* flag shld be converted to particular OS file type in
477 * platform llite module.
479 static __u16 ll_dirent_type_get(struct lu_dirent *ent)
482 struct luda_type *lt;
485 if (le32_to_cpu(ent->lde_attrs) & LUDA_TYPE) {
486 const unsigned int align = sizeof(struct luda_type) - 1;
488 len = le16_to_cpu(ent->lde_namelen);
489 len = (len + align) & ~align;
490 lt = (void *)ent->lde_name + len;
491 type = IFTODT(le16_to_cpu(lt->lt_type));
496 int ll_dir_read(struct inode *inode, struct dir_context *ctx)
498 struct ll_inode_info *info = ll_i2info(inode);
499 struct ll_sb_info *sbi = ll_i2sbi(inode);
500 __u64 pos = ctx->pos;
501 int api32 = ll_need_32bit_api(sbi);
502 int hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
504 struct ll_dir_chain chain;
508 ll_dir_chain_init(&chain);
510 page = ll_get_dir_page(inode, pos, &chain);
512 while (rc == 0 && !done) {
513 struct lu_dirpage *dp;
514 struct lu_dirent *ent;
518 * If page is empty (end of directory is reached),
521 __u64 hash = MDS_DIR_END_OFF;
524 dp = page_address(page);
525 for (ent = lu_dirent_start(dp); ent && !done;
526 ent = lu_dirent_next(ent)) {
534 * XXX: implement correct swabbing here.
537 hash = le64_to_cpu(ent->lde_hash);
540 * Skip until we find target hash
545 namelen = le16_to_cpu(ent->lde_namelen);
556 fid_le_to_cpu(&fid, &ent->lde_fid);
557 ino = cl_fid_build_ino(&fid, api32);
558 type = ll_dirent_type_get(ent);
560 /* For 'll_nfs_get_name_filldir()', it will try
561 * to access the 'ent' through its 'lde_name',
562 * so the parameter 'name' for 'ctx->actor()'
563 * must be part of the 'ent'.
565 done = !dir_emit(ctx, ent->lde_name,
568 next = le64_to_cpu(dp->ldp_hash_end);
571 if (pos == MDS_DIR_END_OFF) {
573 * End of directory reached.
576 ll_release_page(page, 0);
577 } else if (1 /* chain is exhausted*/) {
579 * Normal case: continue to the next
582 ll_release_page(page,
583 le32_to_cpu(dp->ldp_flags) &
586 page = ll_get_dir_page(inode, pos,
590 * go into overflow page.
592 LASSERT(le32_to_cpu(dp->ldp_flags) &
594 ll_release_page(page, 1);
598 ll_release_page(page, 0);
602 CERROR("error reading dir "DFID" at %lu: rc %d\n",
603 PFID(&info->lli_fid), (unsigned long)pos, rc);
608 ll_dir_chain_fini(&chain);
612 static int ll_readdir(struct file *filp, struct dir_context *ctx)
614 struct inode *inode = file_inode(filp);
615 struct ll_file_data *lfd = LUSTRE_FPRIVATE(filp);
616 struct ll_sb_info *sbi = ll_i2sbi(inode);
617 __u64 pos = lfd ? lfd->lfd_pos : 0;
618 int hash64 = sbi->ll_flags & LL_SBI_64BIT_HASH;
619 int api32 = ll_need_32bit_api(sbi);
622 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p) pos %lu/%llu 32bit_api %d\n",
623 PFID(ll_inode2fid(inode)), inode, (unsigned long)pos,
624 i_size_read(inode), api32);
626 if (pos == MDS_DIR_END_OFF) {
635 rc = ll_dir_read(inode, ctx);
637 lfd->lfd_pos = ctx->pos;
638 if (ctx->pos == MDS_DIR_END_OFF) {
640 ctx->pos = LL_DIR_END_OFF_32BIT;
642 ctx->pos = LL_DIR_END_OFF;
647 filp->f_version = inode->i_version;
651 ll_stats_ops_tally(sbi, LPROC_LL_READDIR, 1);
656 static int ll_send_mgc_param(struct obd_export *mgc, char *string)
658 struct mgs_send_param *msp;
661 msp = kzalloc(sizeof(*msp), GFP_NOFS);
665 strlcpy(msp->mgs_param, string, sizeof(msp->mgs_param));
666 rc = obd_set_info_async(NULL, mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
667 sizeof(struct mgs_send_param), msp, NULL);
669 CERROR("Failed to set parameter: %d\n", rc);
675 static int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
678 struct ptlrpc_request *request = NULL;
679 struct md_op_data *op_data;
680 struct ll_sb_info *sbi = ll_i2sbi(dir);
684 mode = (~current_umask() & 0755) | S_IFDIR;
685 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
686 strlen(filename), mode, LUSTRE_OPC_MKDIR,
688 if (IS_ERR(op_data)) {
689 err = PTR_ERR(op_data);
693 op_data->op_cli_flags |= CLI_SET_MEA;
694 err = md_create(sbi->ll_md_exp, op_data, lump, sizeof(*lump), mode,
695 from_kuid(&init_user_ns, current_fsuid()),
696 from_kgid(&init_user_ns, current_fsgid()),
697 cfs_curproc_cap_pack(), 0, &request);
698 ll_finish_md_op_data(op_data);
702 ptlrpc_req_finished(request);
706 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
709 struct ll_sb_info *sbi = ll_i2sbi(inode);
710 struct md_op_data *op_data;
711 struct ptlrpc_request *req = NULL;
713 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
714 struct obd_device *mgc = lsi->lsi_mgc;
719 * This is coming from userspace, so should be in
720 * local endian. But the MDS would like it in little
721 * endian, so we swab it before we send it.
723 switch (lump->lmm_magic) {
724 case LOV_USER_MAGIC_V1: {
725 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V1))
726 lustre_swab_lov_user_md_v1(lump);
727 lum_size = sizeof(struct lov_user_md_v1);
730 case LOV_USER_MAGIC_V3: {
731 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V3))
732 lustre_swab_lov_user_md_v3(
733 (struct lov_user_md_v3 *)lump);
734 lum_size = sizeof(struct lov_user_md_v3);
738 CDEBUG(D_IOCTL, "bad userland LOV MAGIC: %#08x != %#08x nor %#08x\n",
739 lump->lmm_magic, LOV_USER_MAGIC_V1,
745 lum_size = sizeof(struct lov_user_md_v1);
748 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
749 LUSTRE_OPC_ANY, NULL);
751 return PTR_ERR(op_data);
753 if (lump && lump->lmm_magic == cpu_to_le32(LMV_USER_MAGIC))
754 op_data->op_cli_flags |= CLI_SET_MEA;
756 /* swabbing is done in lov_setstripe() on server side */
757 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size,
758 NULL, 0, &req, NULL);
759 ll_finish_md_op_data(op_data);
760 ptlrpc_req_finished(req);
762 if (rc != -EPERM && rc != -EACCES)
763 CERROR("mdc_setattr fails: rc = %d\n", rc);
766 /* In the following we use the fact that LOV_USER_MAGIC_V1 and
767 * LOV_USER_MAGIC_V3 have the same initial fields so we do not
768 * need to make the distinction between the 2 versions
770 if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
774 param = kzalloc(MGS_PARAM_MAXLEN, GFP_NOFS);
779 /* Get fsname and assume devname to be -MDT0000. */
780 ll_get_fsname(inode->i_sb, buf, MTI_NAME_MAXLEN);
781 strcat(buf, "-MDT0000.lov");
784 /* Set root stripesize */
785 sprintf(buf, ".stripesize=%u",
786 lump ? le32_to_cpu(lump->lmm_stripe_size) : 0);
787 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
791 /* Set root stripecount */
792 sprintf(buf, ".stripecount=%hd",
793 lump ? le16_to_cpu(lump->lmm_stripe_count) : 0);
794 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
798 /* Set root stripeoffset */
799 sprintf(buf, ".stripeoffset=%hd",
800 lump ? le16_to_cpu(lump->lmm_stripe_offset) :
801 (typeof(lump->lmm_stripe_offset))(-1));
802 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
810 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
811 int *lmm_size, struct ptlrpc_request **request)
813 struct ll_sb_info *sbi = ll_i2sbi(inode);
814 struct mdt_body *body;
815 struct lov_mds_md *lmm = NULL;
816 struct ptlrpc_request *req = NULL;
818 struct md_op_data *op_data;
820 rc = ll_get_default_mdsize(sbi, &lmmsize);
824 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
825 0, lmmsize, LUSTRE_OPC_ANY,
828 return PTR_ERR(op_data);
830 op_data->op_valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
831 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
832 ll_finish_md_op_data(op_data);
834 CDEBUG(D_INFO, "md_getattr failed on inode "DFID": rc %d\n",
835 PFID(ll_inode2fid(inode)), rc);
839 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
841 lmmsize = body->eadatasize;
843 if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
849 lmm = req_capsule_server_sized_get(&req->rq_pill,
850 &RMF_MDT_MD, lmmsize);
853 * This is coming from the MDS, so is probably in
854 * little endian. We convert it to host endian before
855 * passing it to userspace.
857 /* We don't swab objects for directories */
858 switch (le32_to_cpu(lmm->lmm_magic)) {
860 if (cpu_to_le32(LOV_MAGIC) != LOV_MAGIC)
861 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
864 if (cpu_to_le32(LOV_MAGIC) != LOV_MAGIC)
865 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
868 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
879 * Get MDT index for the inode.
881 int ll_get_mdt_idx(struct inode *inode)
883 struct ll_sb_info *sbi = ll_i2sbi(inode);
884 struct md_op_data *op_data;
887 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0,
888 0, LUSTRE_OPC_ANY, NULL);
890 return PTR_ERR(op_data);
892 op_data->op_flags |= MF_GET_MDT_IDX;
893 rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
894 mdtidx = op_data->op_mds;
895 ll_finish_md_op_data(op_data);
897 CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
904 * Generic handler to do any pre-copy work.
906 * It sends a first hsm_progress (with extent length == 0) to coordinator as a
907 * first information for it that real work has started.
909 * Moreover, for a ARCHIVE request, it will sample the file data version and
910 * store it in \a copy.
912 * \return 0 on success.
914 static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
916 struct ll_sb_info *sbi = ll_s2sbi(sb);
917 struct hsm_progress_kernel hpk;
920 /* Forge a hsm_progress based on data from copy. */
921 hpk.hpk_fid = copy->hc_hai.hai_fid;
922 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
923 hpk.hpk_extent.offset = copy->hc_hai.hai_extent.offset;
924 hpk.hpk_extent.length = 0;
927 hpk.hpk_data_version = 0;
929 /* For archive request, we need to read the current file version. */
930 if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
932 __u64 data_version = 0;
934 /* Get inode for this fid */
935 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
937 hpk.hpk_flags |= HP_FLAG_RETRY;
938 /* hpk_errval is >= 0 */
939 hpk.hpk_errval = -PTR_ERR(inode);
944 /* Read current file data version */
945 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
948 CDEBUG(D_HSM, "Could not read file data version of "
949 DFID" (rc = %d). Archive request (%#llx) could not be done.\n",
950 PFID(©->hc_hai.hai_fid), rc,
951 copy->hc_hai.hai_cookie);
952 hpk.hpk_flags |= HP_FLAG_RETRY;
953 /* hpk_errval must be >= 0 */
954 hpk.hpk_errval = -rc;
958 /* Store in the hsm_copy for later copytool use.
959 * Always modified even if no lsm.
961 copy->hc_data_version = data_version;
965 /* On error, the request should be considered as completed */
966 if (hpk.hpk_errval > 0)
967 hpk.hpk_flags |= HP_FLAG_COMPLETED;
968 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
975 * Generic handler to do any post-copy work.
977 * It will send the last hsm_progress update to coordinator to inform it
978 * that copy is finished and whether it was successful or not.
981 * - for ARCHIVE request, it will sample the file data version and compare it
982 * with the version saved in ll_ioc_copy_start(). If they do not match, copy
983 * will be considered as failed.
984 * - for RESTORE request, it will sample the file data version and send it to
985 * coordinator which is useful if the file was imported as 'released'.
987 * \return 0 on success.
989 static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
991 struct ll_sb_info *sbi = ll_s2sbi(sb);
992 struct hsm_progress_kernel hpk;
995 /* If you modify the logic here, also check llapi_hsm_copy_end(). */
996 /* Take care: copy->hc_hai.hai_action, len, gid and data are not
997 * initialized if copy_end was called with copy == NULL.
1000 /* Forge a hsm_progress based on data from copy. */
1001 hpk.hpk_fid = copy->hc_hai.hai_fid;
1002 hpk.hpk_cookie = copy->hc_hai.hai_cookie;
1003 hpk.hpk_extent = copy->hc_hai.hai_extent;
1004 hpk.hpk_flags = copy->hc_flags | HP_FLAG_COMPLETED;
1005 hpk.hpk_errval = copy->hc_errval;
1006 hpk.hpk_data_version = 0;
1008 /* For archive request, we need to check the file data was not changed.
1010 * For restore request, we need to send the file data version, this is
1011 * useful when the file was created using hsm_import.
1013 if (((copy->hc_hai.hai_action == HSMA_ARCHIVE) ||
1014 (copy->hc_hai.hai_action == HSMA_RESTORE)) &&
1015 (copy->hc_errval == 0)) {
1016 struct inode *inode;
1017 __u64 data_version = 0;
1019 /* Get lsm for this fid */
1020 inode = search_inode_for_lustre(sb, ©->hc_hai.hai_fid);
1021 if (IS_ERR(inode)) {
1022 hpk.hpk_flags |= HP_FLAG_RETRY;
1023 /* hpk_errval must be >= 0 */
1024 hpk.hpk_errval = -PTR_ERR(inode);
1025 rc = PTR_ERR(inode);
1029 rc = ll_data_version(inode, &data_version, LL_DV_RD_FLUSH);
1032 CDEBUG(D_HSM, "Could not read file data version. Request could not be confirmed.\n");
1033 if (hpk.hpk_errval == 0)
1034 hpk.hpk_errval = -rc;
1038 /* Store in the hsm_copy for later copytool use.
1039 * Always modified even if no lsm.
1041 hpk.hpk_data_version = data_version;
1043 /* File could have been stripped during archiving, so we need
1046 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
1047 (copy->hc_data_version != data_version)) {
1048 CDEBUG(D_HSM, "File data version mismatched. File content was changed during archiving. "
1049 DFID", start:%#llx current:%#llx\n",
1050 PFID(©->hc_hai.hai_fid),
1051 copy->hc_data_version, data_version);
1052 /* File was changed, send error to cdt. Do not ask for
1053 * retry because if a file is modified frequently,
1054 * the cdt will loop on retried archive requests.
1055 * The policy engine will ask for a new archive later
1056 * when the file will not be modified for some tunable
1059 /* we do not notify caller */
1060 hpk.hpk_flags &= ~HP_FLAG_RETRY;
1061 /* hpk_errval must be >= 0 */
1062 hpk.hpk_errval = EBUSY;
1067 rc = obd_iocontrol(LL_IOC_HSM_PROGRESS, sbi->ll_md_exp, sizeof(hpk),
1073 static int copy_and_ioctl(int cmd, struct obd_export *exp,
1074 const void __user *data, size_t size)
1079 copy = kzalloc(size, GFP_NOFS);
1083 if (copy_from_user(copy, data, size)) {
1088 rc = obd_iocontrol(cmd, exp, size, copy, NULL);
1095 static int quotactl_ioctl(struct ll_sb_info *sbi, struct if_quotactl *qctl)
1097 int cmd = qctl->qc_cmd;
1098 int type = qctl->qc_type;
1099 int id = qctl->qc_id;
1100 int valid = qctl->qc_valid;
1104 case LUSTRE_Q_INVALIDATE:
1105 case LUSTRE_Q_FINVALIDATE:
1110 if (!capable(CFS_CAP_SYS_ADMIN) ||
1111 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1115 if (((type == USRQUOTA &&
1116 !uid_eq(current_euid(), make_kuid(&init_user_ns, id))) ||
1117 (type == GRPQUOTA &&
1118 !in_egroup_p(make_kgid(&init_user_ns, id)))) &&
1119 (!capable(CFS_CAP_SYS_ADMIN) ||
1120 sbi->ll_flags & LL_SBI_RMT_CLIENT))
1126 CERROR("unsupported quotactl op: %#x\n", cmd);
1130 if (valid != QC_GENERAL) {
1131 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
1134 if (cmd == Q_GETINFO)
1135 qctl->qc_cmd = Q_GETOINFO;
1136 else if (cmd == Q_GETQUOTA)
1137 qctl->qc_cmd = Q_GETOQUOTA;
1143 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
1144 sizeof(*qctl), qctl, NULL);
1147 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_dt_exp,
1148 sizeof(*qctl), qctl, NULL);
1151 rc = obd_iocontrol(OBD_IOC_QUOTACTL, sbi->ll_md_exp,
1152 sizeof(*qctl), qctl, NULL);
1154 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1156 sizeof(*qctl), qctl, NULL);
1168 struct obd_quotactl *oqctl;
1170 oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS);
1174 QCTL_COPY(oqctl, qctl);
1175 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1177 if (rc != -EALREADY && cmd == Q_QUOTAON) {
1178 oqctl->qc_cmd = Q_QUOTAOFF;
1179 obd_quotactl(sbi->ll_md_exp, oqctl);
1184 /* If QIF_SPACE is not set, client should collect the
1185 * space usage from OSSs by itself
1187 if (cmd == Q_GETQUOTA &&
1188 !(oqctl->qc_dqblk.dqb_valid & QIF_SPACE) &&
1189 !oqctl->qc_dqblk.dqb_curspace) {
1190 struct obd_quotactl *oqctl_tmp;
1192 oqctl_tmp = kzalloc(sizeof(*oqctl_tmp), GFP_NOFS);
1198 oqctl_tmp->qc_cmd = Q_GETOQUOTA;
1199 oqctl_tmp->qc_id = oqctl->qc_id;
1200 oqctl_tmp->qc_type = oqctl->qc_type;
1202 /* collect space usage from OSTs */
1203 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1204 rc = obd_quotactl(sbi->ll_dt_exp, oqctl_tmp);
1205 if (!rc || rc == -EREMOTEIO) {
1206 oqctl->qc_dqblk.dqb_curspace =
1207 oqctl_tmp->qc_dqblk.dqb_curspace;
1208 oqctl->qc_dqblk.dqb_valid |= QIF_SPACE;
1211 /* collect space & inode usage from MDTs */
1212 oqctl_tmp->qc_dqblk.dqb_curspace = 0;
1213 oqctl_tmp->qc_dqblk.dqb_curinodes = 0;
1214 rc = obd_quotactl(sbi->ll_md_exp, oqctl_tmp);
1215 if (!rc || rc == -EREMOTEIO) {
1216 oqctl->qc_dqblk.dqb_curspace +=
1217 oqctl_tmp->qc_dqblk.dqb_curspace;
1218 oqctl->qc_dqblk.dqb_curinodes =
1219 oqctl_tmp->qc_dqblk.dqb_curinodes;
1220 oqctl->qc_dqblk.dqb_valid |= QIF_INODES;
1222 oqctl->qc_dqblk.dqb_valid &= ~QIF_SPACE;
1228 QCTL_COPY(qctl, oqctl);
1235 /* This function tries to get a single name component,
1236 * to send to the server. No actual path traversal involved,
1237 * so we limit to NAME_MAX
1239 static char *ll_getname(const char __user *filename)
1244 tmp = kzalloc(NAME_MAX + 1, GFP_KERNEL);
1246 return ERR_PTR(-ENOMEM);
1248 len = strncpy_from_user(tmp, filename, NAME_MAX + 1);
1253 else if (len > NAME_MAX && tmp[NAME_MAX] != 0)
1254 ret = -ENAMETOOLONG;
1263 #define ll_putname(filename) kfree(filename)
1265 static long ll_dir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1267 struct inode *inode = file_inode(file);
1268 struct ll_sb_info *sbi = ll_i2sbi(inode);
1269 struct obd_ioctl_data *data;
1272 CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p), cmd=%#x\n",
1273 PFID(ll_inode2fid(inode)), inode, cmd);
1275 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
1276 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
1279 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
1281 case FSFILT_IOC_GETFLAGS:
1282 case FSFILT_IOC_SETFLAGS:
1283 return ll_iocontrol(inode, file, cmd, arg);
1284 case FSFILT_IOC_GETVERSION_OLD:
1285 case FSFILT_IOC_GETVERSION:
1286 return put_user(inode->i_generation, (int __user *)arg);
1287 /* We need to special case any other ioctls we want to handle,
1288 * to send them to the MDS/OST as appropriate and to properly
1289 * network encode the arg field.
1290 case FSFILT_IOC_SETVERSION_OLD:
1291 case FSFILT_IOC_SETVERSION:
1293 case LL_IOC_GET_MDTIDX: {
1296 mdtidx = ll_get_mdt_idx(inode);
1300 if (put_user((int)mdtidx, (int __user *)arg))
1305 case IOC_MDC_LOOKUP: {
1306 struct ptlrpc_request *request = NULL;
1307 int namelen, len = 0;
1310 struct md_op_data *op_data;
1312 rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
1317 filename = data->ioc_inlbuf1;
1318 namelen = strlen(filename);
1321 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1326 op_data = ll_prep_md_op_data(NULL, inode, NULL, filename, namelen,
1327 0, LUSTRE_OPC_ANY, NULL);
1328 if (IS_ERR(op_data)) {
1329 rc = PTR_ERR(op_data);
1333 op_data->op_valid = OBD_MD_FLID;
1334 rc = md_getattr_name(sbi->ll_md_exp, op_data, &request);
1335 ll_finish_md_op_data(op_data);
1337 CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
1340 ptlrpc_req_finished(request);
1342 obd_ioctl_freedata(buf, len);
1345 case LL_IOC_LMV_SETSTRIPE: {
1346 struct lmv_user_md *lum;
1354 rc = obd_ioctl_getdata(&buf, &len, (void __user *)arg);
1359 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
1360 data->ioc_inllen1 == 0 || data->ioc_inllen2 == 0) {
1365 filename = data->ioc_inlbuf1;
1366 namelen = data->ioc_inllen1;
1369 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
1373 lum = (struct lmv_user_md *)data->ioc_inlbuf2;
1374 lumlen = data->ioc_inllen2;
1376 if (lum->lum_magic != LMV_USER_MAGIC ||
1377 lumlen != sizeof(*lum)) {
1378 CERROR("%s: wrong lum magic %x or size %d: rc = %d\n",
1379 filename, lum->lum_magic, lumlen, -EFAULT);
1385 * ll_dir_setdirstripe will be used to set dir stripe
1386 * mdc_create--->mdt_reint_create (with dirstripe)
1388 rc = ll_dir_setdirstripe(inode, lum, filename);
1390 obd_ioctl_freedata(buf, len);
1393 case LL_IOC_LOV_SETSTRIPE: {
1394 struct lov_user_md_v3 lumv3;
1395 struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
1396 struct lov_user_md_v1 __user *lumv1p = (void __user *)arg;
1397 struct lov_user_md_v3 __user *lumv3p = (void __user *)arg;
1399 int set_default = 0;
1401 LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
1402 LASSERT(sizeof(lumv3.lmm_objects[0]) ==
1403 sizeof(lumv3p->lmm_objects[0]));
1404 /* first try with v1 which is smaller than v3 */
1405 if (copy_from_user(lumv1, lumv1p, sizeof(*lumv1)))
1408 if (lumv1->lmm_magic == LOV_USER_MAGIC_V3) {
1409 if (copy_from_user(&lumv3, lumv3p, sizeof(lumv3)))
1413 if (is_root_inode(inode))
1416 /* in v1 and v3 cases lumv1 points to data */
1417 rc = ll_dir_setstripe(inode, lumv1, set_default);
1421 case LL_IOC_LMV_GETSTRIPE: {
1422 struct lmv_user_md __user *lump = (void __user *)arg;
1423 struct lmv_user_md lum;
1424 struct lmv_user_md *tmp;
1429 if (copy_from_user(&lum, lump, sizeof(struct lmv_user_md)))
1432 if (lum.lum_magic != LMV_MAGIC_V1)
1435 lum_size = lmv_user_md_size(1, LMV_MAGIC_V1);
1436 tmp = kzalloc(lum_size, GFP_NOFS);
1443 tmp->lum_type = LMV_STRIPE_TYPE;
1444 tmp->lum_stripe_count = 1;
1445 mdtindex = ll_get_mdt_idx(inode);
1451 tmp->lum_stripe_offset = mdtindex;
1452 tmp->lum_objects[0].lum_mds = mdtindex;
1453 memcpy(&tmp->lum_objects[0].lum_fid, ll_inode2fid(inode),
1454 sizeof(struct lu_fid));
1455 if (copy_to_user((void __user *)arg, tmp, lum_size)) {
1463 case LL_IOC_LOV_SWAP_LAYOUTS:
1465 case LL_IOC_OBD_STATFS:
1466 return ll_obd_statfs(inode, (void __user *)arg);
1467 case LL_IOC_LOV_GETSTRIPE:
1468 case LL_IOC_MDC_GETINFO:
1469 case IOC_MDC_GETFILEINFO:
1470 case IOC_MDC_GETFILESTRIPE: {
1471 struct ptlrpc_request *request = NULL;
1472 struct lov_user_md __user *lump;
1473 struct lov_mds_md *lmm = NULL;
1474 struct mdt_body *body;
1475 char *filename = NULL;
1478 if (cmd == IOC_MDC_GETFILEINFO ||
1479 cmd == IOC_MDC_GETFILESTRIPE) {
1480 filename = ll_getname((const char __user *)arg);
1481 if (IS_ERR(filename))
1482 return PTR_ERR(filename);
1484 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
1485 &lmmsize, &request);
1487 rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
1491 body = req_capsule_server_get(&request->rq_pill,
1499 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
1500 cmd == LL_IOC_MDC_GETINFO)) {
1508 if (cmd == IOC_MDC_GETFILESTRIPE ||
1509 cmd == LL_IOC_LOV_GETSTRIPE) {
1510 lump = (struct lov_user_md __user *)arg;
1512 struct lov_user_mds_data __user *lmdp;
1514 lmdp = (struct lov_user_mds_data __user *)arg;
1515 lump = &lmdp->lmd_lmm;
1517 if (copy_to_user(lump, lmm, lmmsize)) {
1518 if (copy_to_user(lump, lmm, sizeof(*lump))) {
1525 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
1526 struct lov_user_mds_data __user *lmdp;
1529 st.st_dev = inode->i_sb->s_dev;
1530 st.st_mode = body->mode;
1531 st.st_nlink = body->nlink;
1532 st.st_uid = body->uid;
1533 st.st_gid = body->gid;
1534 st.st_rdev = body->rdev;
1535 st.st_size = body->size;
1536 st.st_blksize = PAGE_SIZE;
1537 st.st_blocks = body->blocks;
1538 st.st_atime = body->atime;
1539 st.st_mtime = body->mtime;
1540 st.st_ctime = body->ctime;
1541 st.st_ino = inode->i_ino;
1543 lmdp = (struct lov_user_mds_data __user *)arg;
1544 if (copy_to_user(&lmdp->lmd_st, &st, sizeof(st))) {
1551 ptlrpc_req_finished(request);
1553 ll_putname(filename);
1556 case IOC_LOV_GETINFO: {
1557 struct lov_user_mds_data __user *lumd;
1558 struct lov_stripe_md *lsm;
1559 struct lov_user_md __user *lum;
1560 struct lov_mds_md *lmm;
1564 lumd = (struct lov_user_mds_data __user *)arg;
1565 lum = &lumd->lmd_lmm;
1567 rc = ll_get_max_mdsize(sbi, &lmmsize);
1571 lmm = libcfs_kvzalloc(lmmsize, GFP_NOFS);
1574 if (copy_from_user(lmm, lum, lmmsize)) {
1579 switch (lmm->lmm_magic) {
1580 case LOV_USER_MAGIC_V1:
1581 if (cpu_to_le32(LOV_USER_MAGIC_V1) == LOV_USER_MAGIC_V1)
1583 /* swab objects first so that stripes num will be sane */
1584 lustre_swab_lov_user_md_objects(
1585 ((struct lov_user_md_v1 *)lmm)->lmm_objects,
1586 ((struct lov_user_md_v1 *)lmm)->lmm_stripe_count);
1587 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
1589 case LOV_USER_MAGIC_V3:
1590 if (cpu_to_le32(LOV_USER_MAGIC_V3) == LOV_USER_MAGIC_V3)
1592 /* swab objects first so that stripes num will be sane */
1593 lustre_swab_lov_user_md_objects(
1594 ((struct lov_user_md_v3 *)lmm)->lmm_objects,
1595 ((struct lov_user_md_v3 *)lmm)->lmm_stripe_count);
1596 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
1603 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
1609 /* Perform glimpse_size operation. */
1610 memset(&st, 0, sizeof(st));
1612 rc = ll_glimpse_ioctl(sbi, lsm, &st);
1616 if (copy_to_user(&lumd->lmd_st, &st, sizeof(st))) {
1622 obd_free_memmd(sbi->ll_dt_exp, &lsm);
1627 case OBD_IOC_LLOG_CATINFO: {
1630 case OBD_IOC_QUOTACHECK: {
1631 struct obd_quotactl *oqctl;
1634 if (!capable(CFS_CAP_SYS_ADMIN) ||
1635 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1638 oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS);
1641 oqctl->qc_type = arg;
1642 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
1644 CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
1648 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
1650 CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
1655 case OBD_IOC_POLL_QUOTACHECK: {
1656 struct if_quotacheck *check;
1658 if (!capable(CFS_CAP_SYS_ADMIN) ||
1659 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1662 check = kzalloc(sizeof(*check), GFP_NOFS);
1666 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
1669 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
1670 if (copy_to_user((void __user *)arg, check,
1672 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1676 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
1679 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
1680 if (copy_to_user((void __user *)arg, check,
1682 CDEBUG(D_QUOTA, "copy_to_user failed\n");
1689 case LL_IOC_QUOTACTL: {
1690 struct if_quotactl *qctl;
1692 qctl = kzalloc(sizeof(*qctl), GFP_NOFS);
1696 if (copy_from_user(qctl, (void __user *)arg, sizeof(*qctl))) {
1701 rc = quotactl_ioctl(sbi, qctl);
1703 if (rc == 0 && copy_to_user((void __user *)arg, qctl,
1711 case OBD_IOC_GETDTNAME:
1712 case OBD_IOC_GETMDNAME:
1713 return ll_get_obd_name(inode, cmd, arg);
1714 case LL_IOC_FLUSHCTX:
1715 return ll_flush_ctx(inode);
1716 #ifdef CONFIG_FS_POSIX_ACL
1717 case LL_IOC_RMTACL: {
1718 if (sbi->ll_flags & LL_SBI_RMT_CLIENT && is_root_inode(inode)) {
1719 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1721 rc = rct_add(&sbi->ll_rct, current_pid(), arg);
1723 fd->fd_flags |= LL_FILE_RMTACL;
1730 case LL_IOC_GETOBDCOUNT: {
1732 struct obd_export *exp;
1734 if (copy_from_user(&count, (int __user *)arg, sizeof(int)))
1737 /* get ost count when count is zero, get mdt count otherwise */
1738 exp = count ? sbi->ll_md_exp : sbi->ll_dt_exp;
1739 vallen = sizeof(count);
1740 rc = obd_get_info(NULL, exp, sizeof(KEY_TGT_COUNT),
1741 KEY_TGT_COUNT, &vallen, &count, NULL);
1743 CERROR("get target count failed: %d\n", rc);
1747 if (copy_to_user((int __user *)arg, &count, sizeof(int)))
1752 case LL_IOC_PATH2FID:
1753 if (copy_to_user((void __user *)arg, ll_inode2fid(inode),
1754 sizeof(struct lu_fid)))
1757 case LL_IOC_GET_CONNECT_FLAGS: {
1758 return obd_iocontrol(cmd, sbi->ll_md_exp, 0, NULL,
1759 (void __user *)arg);
1761 case OBD_IOC_CHANGELOG_SEND:
1762 case OBD_IOC_CHANGELOG_CLEAR:
1763 if (!capable(CFS_CAP_SYS_ADMIN))
1766 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void __user *)arg,
1767 sizeof(struct ioc_changelog));
1769 case OBD_IOC_FID2PATH:
1770 return ll_fid2path(inode, (void __user *)arg);
1771 case LL_IOC_HSM_REQUEST: {
1772 struct hsm_user_request *hur;
1775 hur = memdup_user((void __user *)arg, sizeof(*hur));
1777 return PTR_ERR(hur);
1779 /* Compute the whole struct size */
1780 totalsize = hur_len(hur);
1785 /* Final size will be more than double totalsize */
1786 if (totalsize >= MDS_MAXREQSIZE / 3)
1789 hur = libcfs_kvzalloc(totalsize, GFP_NOFS);
1793 /* Copy the whole struct */
1794 if (copy_from_user(hur, (void __user *)arg, totalsize)) {
1799 if (hur->hur_request.hr_action == HUA_RELEASE) {
1800 const struct lu_fid *fid;
1804 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
1805 fid = &hur->hur_user_item[i].hui_fid;
1806 f = search_inode_for_lustre(inode->i_sb, fid);
1812 rc = ll_hsm_release(f);
1818 rc = obd_iocontrol(cmd, ll_i2mdexp(inode), totalsize,
1826 case LL_IOC_HSM_PROGRESS: {
1827 struct hsm_progress_kernel hpk;
1828 struct hsm_progress hp;
1830 if (copy_from_user(&hp, (void __user *)arg, sizeof(hp)))
1833 hpk.hpk_fid = hp.hp_fid;
1834 hpk.hpk_cookie = hp.hp_cookie;
1835 hpk.hpk_extent = hp.hp_extent;
1836 hpk.hpk_flags = hp.hp_flags;
1837 hpk.hpk_errval = hp.hp_errval;
1838 hpk.hpk_data_version = 0;
1840 /* File may not exist in Lustre; all progress
1841 * reported to Lustre root
1843 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(hpk), &hpk,
1847 case LL_IOC_HSM_CT_START:
1848 if (!capable(CFS_CAP_SYS_ADMIN))
1851 rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void __user *)arg,
1852 sizeof(struct lustre_kernelcomm));
1855 case LL_IOC_HSM_COPY_START: {
1856 struct hsm_copy *copy;
1859 copy = memdup_user((char __user *)arg, sizeof(*copy));
1861 return PTR_ERR(copy);
1863 rc = ll_ioc_copy_start(inode->i_sb, copy);
1864 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
1870 case LL_IOC_HSM_COPY_END: {
1871 struct hsm_copy *copy;
1874 copy = memdup_user((char __user *)arg, sizeof(*copy));
1876 return PTR_ERR(copy);
1878 rc = ll_ioc_copy_end(inode->i_sb, copy);
1879 if (copy_to_user((char __user *)arg, copy, sizeof(*copy)))
1886 return obd_iocontrol(cmd, sbi->ll_dt_exp, 0, NULL,
1887 (void __user *)arg);
1891 static loff_t ll_dir_seek(struct file *file, loff_t offset, int origin)
1893 struct inode *inode = file->f_mapping->host;
1894 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1895 struct ll_sb_info *sbi = ll_i2sbi(inode);
1896 int api32 = ll_need_32bit_api(sbi);
1897 loff_t ret = -EINVAL;
1903 offset += file->f_pos;
1909 offset += LL_DIR_END_OFF_32BIT;
1911 offset += LL_DIR_END_OFF;
1918 ((api32 && offset <= LL_DIR_END_OFF_32BIT) ||
1919 (!api32 && offset <= LL_DIR_END_OFF))) {
1920 if (offset != file->f_pos) {
1921 if ((api32 && offset == LL_DIR_END_OFF_32BIT) ||
1922 (!api32 && offset == LL_DIR_END_OFF))
1923 fd->lfd_pos = MDS_DIR_END_OFF;
1924 else if (api32 && sbi->ll_flags & LL_SBI_64BIT_HASH)
1925 fd->lfd_pos = offset << 32;
1927 fd->lfd_pos = offset;
1928 file->f_pos = offset;
1929 file->f_version = 0;
1939 static int ll_dir_open(struct inode *inode, struct file *file)
1941 return ll_file_open(inode, file);
1944 static int ll_dir_release(struct inode *inode, struct file *file)
1946 return ll_file_release(inode, file);
1949 const struct file_operations ll_dir_operations = {
1950 .llseek = ll_dir_seek,
1951 .open = ll_dir_open,
1952 .release = ll_dir_release,
1953 .read = generic_read_dir,
1954 .iterate_shared = ll_readdir,
1955 .unlocked_ioctl = ll_dir_ioctl,