1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
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 <linux/smp_lock.h>
46 #include <asm/uaccess.h>
47 #include <linux/buffer_head.h> // for wait_on_buffer
49 #define DEBUG_SUBSYSTEM S_LLITE
51 #include <obd_support.h>
52 #include <obd_class.h>
53 #include <lustre_lib.h>
54 #include <lustre/lustre_idl.h>
55 #include <lustre_lite.h>
56 #include <lustre_dlm.h>
57 #include <lustre_fid.h>
58 #include "llite_internal.h"
60 #ifndef HAVE_PAGE_CHECKED
61 #ifdef HAVE_PG_FS_MISC
62 #define PageChecked(page) test_bit(PG_fs_misc, &(page)->flags)
63 #define SetPageChecked(page) set_bit(PG_fs_misc, &(page)->flags)
65 #error PageChecked or PageFsMisc not defined in kernel
70 * (new) readdir implementation overview.
72 * Original lustre readdir implementation cached exact copy of raw directory
73 * pages on the client. These pages were indexed in client page cache by
74 * logical offset in the directory file. This design, while very simple and
75 * intuitive had some inherent problems:
77 * . it implies that byte offset to the directory entry serves as a
78 * telldir(3)/seekdir(3) cookie, but that offset is not stable: in
79 * ext3/htree directory entries may move due to splits, and more
82 * . it is incompatible with the design of split directories for cmd3,
83 * that assumes that names are distributed across nodes based on their
84 * hash, and so readdir should be done in hash order.
86 * New readdir implementation does readdir in hash order, and uses hash of a
87 * file name as a telldir/seekdir cookie. This led to number of complications:
89 * . hash is not unique, so it cannot be used to index cached directory
90 * pages on the client (note, that it requires a whole pageful of hash
91 * collided entries to cause two pages to have identical hashes);
93 * . hash is not unique, so it cannot, strictly speaking, be used as an
94 * entry cookie. ext3/htree has the same problem and lustre implementation
95 * mimics their solution: seekdir(hash) positions directory at the first
96 * entry with the given hash.
102 * Client caches directory pages using hash of the first entry as an index. As
103 * noted above hash is not unique, so this solution doesn't work as is:
104 * special processing is needed for "page hash chains" (i.e., sequences of
105 * pages filled with entries all having the same hash value).
107 * First, such chains have to be detected. To this end, server returns to the
108 * client the hash of the first entry on the page next to one returned. When
109 * client detects that this hash is the same as hash of the first entry on the
110 * returned page, page hash collision has to be handled. Pages in the
111 * hash chain, except first one, are termed "overflow pages".
113 * Solution to index uniqueness problem is to not cache overflow
114 * pages. Instead, when page hash collision is detected, all overflow pages
115 * from emerging chain are immediately requested from the server and placed in
116 * a special data structure (struct ll_dir_chain). This data structure is used
117 * by ll_readdir() to process entries from overflow pages. When readdir
118 * invocation finishes, overflow pages are discarded. If page hash collision
119 * chain weren't completely processed, next call to readdir will again detect
120 * page hash collision, again read overflow pages in, process next portion of
121 * entries and again discard the pages. This is not as wasteful as it looks,
122 * because, given reasonable hash, page hash collisions are extremely rare.
124 * 1. directory positioning
126 * When seekdir(hash) is called, original
137 * identification of and access to overflow pages
147 /* returns the page unlocked, but with a reference */
148 static int ll_dir_readpage(struct file *file, struct page *page)
150 struct inode *inode = page->mapping->host;
151 struct ptlrpc_request *request;
152 struct mdt_body *body;
158 hash = (__u64)hash_x_index(page->index);
159 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) off %lu\n",
160 inode->i_ino, inode->i_generation, inode, (unsigned long)hash);
162 oc = ll_mdscapa_get(inode);
163 rc = md_readpage(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode),
164 oc, hash, page, &request);
167 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
168 /* Checked by mdc_readpage() */
169 LASSERT(body != NULL);
171 if (body->valid & OBD_MD_FLSIZE)
172 cl_isize_write(inode, body->size);
173 SetPageUptodate(page);
175 ptlrpc_req_finished(request);
182 struct address_space_operations ll_dir_aops = {
183 .readpage = ll_dir_readpage,
186 static void ll_check_page(struct inode *dir, struct page *page)
188 /* XXX: check page format later */
189 SetPageChecked(page);
192 static void ll_release_page(struct page *page, __u64 hash,
193 __u64 start, __u64 end)
197 if (likely(page->mapping != NULL)) {
198 ll_truncate_complete_page(page);
202 CWARN("NULL mapping page %p, truncated by others: "
203 "hash("LPX64") | start("LPX64") | end("LPX64")\n",
204 page, hash, start, end);
206 page_cache_release(page);
210 * Find, kmap and return page that contains given hash.
212 static struct page *ll_dir_page_locate(struct inode *dir, __u64 hash,
213 __u64 *start, __u64 *end)
215 struct address_space *mapping = dir->i_mapping;
217 * Complement of hash is used as an index so that
218 * radix_tree_gang_lookup() can be used to find a page with starting
219 * hash _smaller_ than one we are looking for.
221 unsigned long offset = hash_x_index((unsigned long)hash);
225 TREE_READ_LOCK_IRQ(mapping);
226 found = radix_tree_gang_lookup(&mapping->page_tree,
227 (void **)&page, offset, 1);
229 struct lu_dirpage *dp;
231 page_cache_get(page);
232 TREE_READ_UNLOCK_IRQ(mapping);
234 * In contrast to find_lock_page() we are sure that directory
235 * page cannot be truncated (while DLM lock is held) and,
236 * hence, can avoid restart.
238 * In fact, page cannot be locked here at all, because
239 * ll_dir_readpage() does synchronous io.
242 if (PageUptodate(page)) {
244 *start = le64_to_cpu(dp->ldp_hash_start);
245 *end = le64_to_cpu(dp->ldp_hash_end);
246 LASSERT(*start <= hash);
247 if (hash > *end || (*end != *start && hash == *end)) {
248 ll_release_page(page, hash, *start, *end);
252 page_cache_release(page);
253 page = ERR_PTR(-EIO);
257 TREE_READ_UNLOCK_IRQ(mapping);
263 struct page *ll_get_dir_page(struct inode *dir, __u64 hash, int exact,
264 struct ll_dir_chain *chain)
266 ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_UPDATE} };
267 struct address_space *mapping = dir->i_mapping;
268 struct lustre_handle lockh;
269 struct lu_dirpage *dp;
277 rc = md_lock_match(ll_i2sbi(dir)->ll_md_exp, LDLM_FL_BLOCK_GRANTED,
278 ll_inode2fid(dir), LDLM_IBITS, &policy, mode, &lockh);
280 struct ldlm_enqueue_info einfo = { LDLM_IBITS, mode,
281 ll_md_blocking_ast, ldlm_completion_ast,
283 struct lookup_intent it = { .it_op = IT_READDIR };
284 struct ptlrpc_request *request;
285 struct md_op_data *op_data;
287 op_data = ll_prep_md_op_data(NULL, dir, NULL, NULL, 0, 0,
288 LUSTRE_OPC_ANY, NULL);
290 return (void *)op_data;
292 rc = md_enqueue(ll_i2sbi(dir)->ll_md_exp, &einfo, &it,
293 op_data, &lockh, NULL, 0, NULL, 0);
295 ll_finish_md_op_data(op_data);
297 request = (struct ptlrpc_request *)it.d.lustre.it_data;
299 ptlrpc_req_finished(request);
301 CERROR("lock enqueue: "DFID" at "LPU64": rc %d\n",
302 PFID(ll_inode2fid(dir)), hash, rc);
306 /* for cross-ref object, l_ast_data of the lock may not be set,
307 * we reset it here */
308 md_set_lock_data(ll_i2sbi(dir)->ll_md_exp, &lockh.cookie,
311 ldlm_lock_dump_handle(D_OTHER, &lockh);
313 page = ll_dir_page_locate(dir, hash, &start, &end);
315 CERROR("dir page locate: "DFID" at "LPU64": rc %ld\n",
316 PFID(ll_inode2fid(dir)), hash, PTR_ERR(page));
317 GOTO(out_unlock, page);
322 * XXX nikita: not entirely correct handling of a corner case:
323 * suppose hash chain of entries with hash value HASH crosses
324 * border between pages P0 and P1. First both P0 and P1 are
325 * cached, seekdir() is called for some entry from the P0 part
326 * of the chain. Later P0 goes out of cache. telldir(HASH)
327 * happens and finds P1, as it starts with matching hash
328 * value. Remaining entries from P0 part of the chain are
329 * skipped. (Is that really a bug?)
331 * Possible solutions: 0. don't cache P1 is such case, handle
332 * it as an "overflow" page. 1. invalidate all pages at
333 * once. 2. use HASH|1 as an index for P1.
335 if (exact && hash != start) {
337 * readdir asked for a page starting _exactly_ from
338 * given hash, but cache contains stale page, with
339 * entries with smaller hash values. Stale page should
340 * be invalidated, and new one fetched.
342 CDEBUG(D_OTHER, "Stale readpage page %p: "LPX64" != "LPX64"\n",
344 ll_release_page(page, hash, start, end);
346 GOTO(hash_collision, page);
350 page = read_cache_page(mapping, hash_x_index((unsigned long)hash),
351 (filler_t*)mapping->a_ops->readpage, NULL);
353 CERROR("read cache page: "DFID" at "LPU64": rc %ld\n",
354 PFID(ll_inode2fid(dir)), hash, PTR_ERR(page));
355 GOTO(out_unlock, page);
360 if (!PageUptodate(page)) {
361 CERROR("page not updated: "DFID" at "LPU64": rc %d\n",
362 PFID(ll_inode2fid(dir)), hash, -5);
365 if (!PageChecked(page))
366 ll_check_page(dir, page);
367 if (PageError(page)) {
368 CERROR("page error: "DFID" at "LPU64": rc %d\n",
369 PFID(ll_inode2fid(dir)), hash, -5);
373 dp = page_address(page);
375 start = le64_to_cpu(dp->ldp_hash_start);
376 end = le64_to_cpu(dp->ldp_hash_end);
378 LASSERT(start == hash);
379 CWARN("Page-wide hash collision: %#lx\n", (unsigned long)end);
381 * Fetch whole overflow chain...
388 ldlm_lock_decref(&lockh, mode);
393 page = ERR_PTR(-EIO);
397 int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
399 struct inode *inode = filp->f_dentry->d_inode;
400 struct ll_inode_info *info = ll_i2info(inode);
401 __u64 pos = filp->f_pos;
403 struct ll_dir_chain chain;
410 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %lu/%llu\n",
411 inode->i_ino, inode->i_generation, inode,
412 (unsigned long)pos, i_size_read(inode));
414 if (pos == DIR_END_OFF)
423 ll_dir_chain_init(&chain);
425 page = ll_get_dir_page(inode, pos, 0, &chain);
427 while (rc == 0 && !done) {
428 struct lu_dirpage *dp;
429 struct lu_dirent *ent;
433 * If page is empty (end of directory is reached),
436 __u64 hash = DIR_END_OFF;
439 dp = page_address(page);
440 for (ent = lu_dirent_start(dp); ent != NULL && !done;
441 ent = lu_dirent_next(ent)) {
448 * XXX: implement correct swabbing here.
451 hash = le64_to_cpu(ent->lde_hash);
452 namelen = le16_to_cpu(ent->lde_namelen);
456 * Skip until we find target hash
468 name = ent->lde_name;
469 fid_le_to_cpu(&fid, &fid);
470 ino = cl_fid_build_ino(&fid);
471 type = ll_dirent_type_get(ent);
472 done = filldir(cookie, name, namelen,
473 (loff_t)hash, ino, type);
475 next = le64_to_cpu(dp->ldp_hash_end);
479 if (pos == DIR_END_OFF)
481 * End of directory reached.
484 else if (1 /* chain is exhausted*/)
486 * Normal case: continue to the next
489 page = ll_get_dir_page(inode, pos, 1,
493 * go into overflow page.
500 CERROR("error reading dir "DFID" at %lu: rc %d\n",
501 PFID(&info->lli_fid), (unsigned long)pos, rc);
505 filp->f_pos = (loff_t)pos;
506 filp->f_version = inode->i_version;
507 touch_atime(filp->f_vfsmnt, filp->f_dentry);
509 ll_dir_chain_fini(&chain);
514 int ll_send_mgc_param(struct obd_export *mgc, char *string)
516 struct mgs_send_param *msp;
523 strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN);
524 rc = obd_set_info_async(mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
525 sizeof(struct mgs_send_param), msp, NULL);
527 CERROR("Failed to set parameter: %d\n", rc);
533 char *ll_get_fsname(struct inode *inode)
535 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
539 OBD_ALLOC(fsname, MGS_PARAM_MAXLEN);
540 len = strlen(lsi->lsi_lmd->lmd_profile);
541 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
542 if (ptr && (strcmp(ptr, "-client") == 0))
544 strncpy(fsname, lsi->lsi_lmd->lmd_profile, len);
550 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
553 struct ll_sb_info *sbi = ll_i2sbi(inode);
554 struct md_op_data *op_data;
555 struct ptlrpc_request *req = NULL;
557 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
558 struct obd_device *mgc = lsi->lsi_mgc;
559 char *fsname = NULL, *param = NULL;
563 * This is coming from userspace, so should be in
564 * local endian. But the MDS would like it in little
565 * endian, so we swab it before we send it.
567 switch (lump->lmm_magic) {
568 case LOV_USER_MAGIC_V1: {
569 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V1))
570 lustre_swab_lov_user_md_v1(lump);
571 lum_size = sizeof(struct lov_user_md_v1);
574 case LOV_USER_MAGIC_V3: {
575 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V3))
576 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lump);
577 lum_size = sizeof(struct lov_user_md_v3);
581 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
582 " %#08x != %#08x nor %#08x\n",
583 lump->lmm_magic, LOV_USER_MAGIC_V1,
589 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
590 LUSTRE_OPC_ANY, NULL);
592 RETURN(PTR_ERR(op_data));
594 /* swabbing is done in lov_setstripe() on server side */
595 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size,
596 NULL, 0, &req, NULL);
597 ll_finish_md_op_data(op_data);
598 ptlrpc_req_finished(req);
600 if (rc != -EPERM && rc != -EACCES)
601 CERROR("mdc_setattr fails: rc = %d\n", rc);
604 /* In the following we use the fact that LOV_USER_MAGIC_V1 and
605 LOV_USER_MAGIC_V3 have the same initial fields so we do not
606 need the make the distiction between the 2 versions */
607 if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
608 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
610 /* Get fsname and assume devname to be -MDT0000. */
611 fsname = ll_get_fsname(inode);
612 /* Set root stripesize */
613 sprintf(param, "%s-MDT0000.lov.stripesize=%u", fsname,
614 lump->lmm_stripe_size);
615 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
619 /* Set root stripecount */
620 sprintf(param, "%s-MDT0000.lov.stripecount=%hd", fsname,
621 lump->lmm_stripe_count);
622 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
626 /* Set root stripeoffset */
627 sprintf(param, "%s-MDT0000.lov.stripeoffset=%hd", fsname,
628 lump->lmm_stripe_offset);
629 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
634 OBD_FREE(fsname, MGS_PARAM_MAXLEN);
636 OBD_FREE(param, MGS_PARAM_MAXLEN);
641 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
642 int *lmm_size, struct ptlrpc_request **request)
644 struct ll_sb_info *sbi = ll_i2sbi(inode);
645 struct mdt_body *body;
646 struct lov_mds_md *lmm = NULL;
647 struct ptlrpc_request *req = NULL;
649 struct md_op_data *op_data;
651 rc = ll_get_max_mdsize(sbi, &lmmsize);
655 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
656 0, lmmsize, LUSTRE_OPC_ANY,
661 op_data->op_valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
662 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
663 ll_finish_md_op_data(op_data);
665 CDEBUG(D_INFO, "md_getattr failed on inode "
666 "%lu/%u: rc %d\n", inode->i_ino,
667 inode->i_generation, rc);
671 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
672 LASSERT(body != NULL);
674 lmmsize = body->eadatasize;
676 if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
678 GOTO(out, rc = -ENODATA);
681 lmm = req_capsule_server_sized_get(&req->rq_pill,
682 &RMF_MDT_MD, lmmsize);
683 LASSERT(lmm != NULL);
686 * This is coming from the MDS, so is probably in
687 * little endian. We convert it to host endian before
688 * passing it to userspace.
690 /* We don't swab objects for directories */
691 switch (le32_to_cpu(lmm->lmm_magic)) {
693 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
694 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
697 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
698 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
701 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
712 * Get MDT index for the inode.
714 int ll_get_mdt_idx(struct inode *inode)
716 struct ll_sb_info *sbi = ll_i2sbi(inode);
717 struct md_op_data *op_data;
721 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0,
722 0, LUSTRE_OPC_ANY, NULL);
726 op_data->op_valid |= OBD_MD_MDTIDX;
727 rc = md_getattr(sbi->ll_md_exp, op_data, NULL);
728 mdtidx = op_data->op_mds;
729 ll_finish_md_op_data(op_data);
731 CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
737 static int ll_dir_ioctl(struct inode *inode, struct file *file,
738 unsigned int cmd, unsigned long arg)
740 struct ll_sb_info *sbi = ll_i2sbi(inode);
741 struct obd_ioctl_data *data;
744 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), cmd=%#x\n",
745 inode->i_ino, inode->i_generation, inode, cmd);
747 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
748 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
751 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
753 case FSFILT_IOC_GETFLAGS:
754 case FSFILT_IOC_SETFLAGS:
755 RETURN(ll_iocontrol(inode, file, cmd, arg));
756 case FSFILT_IOC_GETVERSION_OLD:
757 case FSFILT_IOC_GETVERSION:
758 RETURN(put_user(inode->i_generation, (int *)arg));
759 /* We need to special case any other ioctls we want to handle,
760 * to send them to the MDS/OST as appropriate and to properly
761 * network encode the arg field.
762 case FSFILT_IOC_SETVERSION_OLD:
763 case FSFILT_IOC_SETVERSION:
765 case LL_IOC_GET_MDTIDX: {
768 mdtidx = ll_get_mdt_idx(inode);
772 if (put_user((int)mdtidx, (int*)arg))
777 case IOC_MDC_LOOKUP: {
778 struct ptlrpc_request *request = NULL;
779 int namelen, rc, len = 0;
782 struct md_op_data *op_data;
784 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
789 filename = data->ioc_inlbuf1;
790 namelen = strlen(filename);
793 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
794 GOTO(out_free, rc = -EINVAL);
797 op_data = ll_prep_md_op_data(NULL, inode, NULL, filename, namelen,
798 0, LUSTRE_OPC_ANY, NULL);
800 GOTO(out_free, rc = -ENOMEM);
802 op_data->op_valid = OBD_MD_FLID;
803 rc = md_getattr_name(sbi->ll_md_exp, op_data, &request);
804 ll_finish_md_op_data(op_data);
806 CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
809 ptlrpc_req_finished(request);
812 obd_ioctl_freedata(buf, len);
815 case LL_IOC_LOV_SETSTRIPE: {
816 struct lov_user_md_v3 lumv3;
817 struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
818 struct lov_user_md_v1 *lumv1p = (struct lov_user_md_v1 *)arg;
819 struct lov_user_md_v3 *lumv3p = (struct lov_user_md_v3 *)arg;
824 LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
825 LASSERT(sizeof(lumv3.lmm_objects[0]) ==
826 sizeof(lumv3p->lmm_objects[0]));
827 /* first try with v1 which is smaller than v3 */
828 if (cfs_copy_from_user(lumv1, lumv1p, sizeof(*lumv1)))
831 if (lumv1->lmm_magic == LOV_USER_MAGIC_V3) {
832 if (cfs_copy_from_user(&lumv3, lumv3p, sizeof(lumv3)))
836 if (inode->i_sb->s_root == file->f_dentry)
839 /* in v1 and v3 cases lumv1 points to data */
840 rc = ll_dir_setstripe(inode, lumv1, set_default);
844 case LL_IOC_OBD_STATFS:
845 RETURN(ll_obd_statfs(inode, (void *)arg));
846 case LL_IOC_LOV_GETSTRIPE:
847 case LL_IOC_MDC_GETINFO:
848 case IOC_MDC_GETFILEINFO:
849 case IOC_MDC_GETFILESTRIPE: {
850 struct ptlrpc_request *request = NULL;
851 struct lov_user_md *lump;
852 struct lov_mds_md *lmm = NULL;
853 struct mdt_body *body;
854 char *filename = NULL;
857 if (cmd == IOC_MDC_GETFILEINFO ||
858 cmd == IOC_MDC_GETFILESTRIPE) {
859 filename = getname((const char *)arg);
860 if (IS_ERR(filename))
861 RETURN(PTR_ERR(filename));
863 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
866 rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
870 body = req_capsule_server_get(&request->rq_pill,
872 LASSERT(body != NULL);
878 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
879 cmd == LL_IOC_MDC_GETINFO))
880 GOTO(skip_lmm, rc = 0);
885 if (cmd == IOC_MDC_GETFILESTRIPE ||
886 cmd == LL_IOC_LOV_GETSTRIPE) {
887 lump = (struct lov_user_md *)arg;
889 struct lov_user_mds_data *lmdp;
890 lmdp = (struct lov_user_mds_data *)arg;
891 lump = &lmdp->lmd_lmm;
893 if (cfs_copy_to_user(lump, lmm, lmmsize))
894 GOTO(out_req, rc = -EFAULT);
896 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
897 struct lov_user_mds_data *lmdp;
900 st.st_dev = inode->i_sb->s_dev;
901 st.st_mode = body->mode;
902 st.st_nlink = body->nlink;
903 st.st_uid = body->uid;
904 st.st_gid = body->gid;
905 st.st_rdev = body->rdev;
906 st.st_size = body->size;
907 st.st_blksize = CFS_PAGE_SIZE;
908 st.st_blocks = body->blocks;
909 st.st_atime = body->atime;
910 st.st_mtime = body->mtime;
911 st.st_ctime = body->ctime;
912 st.st_ino = inode->i_ino;
914 lmdp = (struct lov_user_mds_data *)arg;
915 if (cfs_copy_to_user(&lmdp->lmd_st, &st, sizeof(st)))
916 GOTO(out_req, rc = -EFAULT);
921 ptlrpc_req_finished(request);
926 case IOC_LOV_GETINFO: {
927 struct lov_user_mds_data *lumd;
928 struct lov_stripe_md *lsm;
929 struct lov_user_md *lum;
930 struct lov_mds_md *lmm;
935 lumd = (struct lov_user_mds_data *)arg;
936 lum = &lumd->lmd_lmm;
938 rc = ll_get_max_mdsize(sbi, &lmmsize);
942 OBD_ALLOC(lmm, lmmsize);
943 if (cfs_copy_from_user(lmm, lum, lmmsize))
944 GOTO(free_lmm, rc = -EFAULT);
946 switch (lmm->lmm_magic) {
947 case LOV_USER_MAGIC_V1:
948 if (LOV_USER_MAGIC_V1 == cpu_to_le32(LOV_USER_MAGIC_V1))
950 /* swab objects first so that stripes num will be sane */
951 lustre_swab_lov_user_md_objects(
952 ((struct lov_user_md_v1 *)lmm)->lmm_objects,
953 ((struct lov_user_md_v1 *)lmm)->lmm_stripe_count);
954 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
956 case LOV_USER_MAGIC_V3:
957 if (LOV_USER_MAGIC_V3 == cpu_to_le32(LOV_USER_MAGIC_V3))
959 /* swab objects first so that stripes num will be sane */
960 lustre_swab_lov_user_md_objects(
961 ((struct lov_user_md_v3 *)lmm)->lmm_objects,
962 ((struct lov_user_md_v3 *)lmm)->lmm_stripe_count);
963 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
966 GOTO(free_lmm, rc = -EINVAL);
969 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
971 GOTO(free_lmm, rc = -ENOMEM);
973 /* Perform glimpse_size operation. */
974 memset(&st, 0, sizeof(st));
976 rc = ll_glimpse_ioctl(sbi, lsm, &st);
980 if (cfs_copy_to_user(&lumd->lmd_st, &st, sizeof(st)))
981 GOTO(free_lsm, rc = -EFAULT);
985 obd_free_memmd(sbi->ll_dt_exp, &lsm);
987 OBD_FREE(lmm, lmmsize);
990 case OBD_IOC_LLOG_CATINFO: {
991 struct ptlrpc_request *req = NULL;
997 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
1002 if (!data->ioc_inlbuf1) {
1003 obd_ioctl_freedata(buf, len);
1007 req = ptlrpc_request_alloc(sbi2mdc(sbi)->cl_import,
1010 GOTO(out_catinfo, rc = -ENOMEM);
1012 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
1014 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_CLIENT,
1017 rc = ptlrpc_request_pack(req, LUSTRE_LOG_VERSION, LLOG_CATINFO);
1019 ptlrpc_request_free(req);
1020 GOTO(out_catinfo, rc);
1023 str = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
1024 memcpy(str, data->ioc_inlbuf1, data->ioc_inllen1);
1025 if (data->ioc_inllen2) {
1026 str = req_capsule_client_get(&req->rq_pill,
1028 memcpy(str, data->ioc_inlbuf2, data->ioc_inllen2);
1031 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_SERVER,
1033 ptlrpc_request_set_replen(req);
1035 rc = ptlrpc_queue_wait(req);
1037 str = req_capsule_server_get(&req->rq_pill,
1039 if (cfs_copy_to_user(data->ioc_pbuf1, str,
1043 ptlrpc_req_finished(req);
1045 obd_ioctl_freedata(buf, len);
1048 case OBD_IOC_QUOTACHECK: {
1049 struct obd_quotactl *oqctl;
1052 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1053 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1056 OBD_ALLOC_PTR(oqctl);
1059 oqctl->qc_type = arg;
1060 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
1062 CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
1066 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
1068 CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
1070 OBD_FREE_PTR(oqctl);
1073 case OBD_IOC_POLL_QUOTACHECK: {
1074 struct if_quotacheck *check;
1077 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1078 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1081 OBD_ALLOC_PTR(check);
1085 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
1088 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
1089 if (cfs_copy_to_user((void *)arg, check,
1095 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
1098 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
1099 if (cfs_copy_to_user((void *)arg, check,
1105 OBD_FREE_PTR(check);
1108 case OBD_IOC_QUOTACTL: {
1109 struct if_quotactl *qctl;
1110 int cmd, type, id, valid, rc = 0;
1112 OBD_ALLOC_PTR(qctl);
1116 if (cfs_copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
1117 GOTO(out_quotactl, rc = -EFAULT);
1120 type = qctl->qc_type;
1122 valid = qctl->qc_valid;
1125 case LUSTRE_Q_INVALIDATE:
1126 case LUSTRE_Q_FINVALIDATE:
1131 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1132 sbi->ll_flags & LL_SBI_RMT_CLIENT)
1133 GOTO(out_quotactl, rc = -EPERM);
1136 if (((type == USRQUOTA && cfs_curproc_euid() != id) ||
1137 (type == GRPQUOTA && !in_egroup_p(id))) &&
1138 (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1139 sbi->ll_flags & LL_SBI_RMT_CLIENT))
1140 GOTO(out_quotactl, rc = -EPERM);
1145 CERROR("unsupported quotactl op: %#x\n", cmd);
1146 GOTO(out_quotactl, rc = -ENOTTY);
1149 if (valid != QC_GENERAL) {
1150 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
1151 GOTO(out_quotactl, rc = -EOPNOTSUPP);
1153 if (cmd == Q_GETINFO)
1154 qctl->qc_cmd = Q_GETOINFO;
1155 else if (cmd == Q_GETQUOTA)
1156 qctl->qc_cmd = Q_GETOQUOTA;
1158 GOTO(out_quotactl, rc = -EINVAL);
1162 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1164 sizeof(*qctl), qctl, NULL);
1167 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1169 sizeof(*qctl), qctl, NULL);
1172 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1174 sizeof(*qctl), qctl, NULL);
1176 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1178 sizeof(*qctl), qctl,
1187 GOTO(out_quotactl, rc);
1191 struct obd_quotactl *oqctl;
1193 OBD_ALLOC_PTR(oqctl);
1195 GOTO(out_quotactl, rc = -ENOMEM);
1197 QCTL_COPY(oqctl, qctl);
1198 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1200 if (rc != -EALREADY && cmd == Q_QUOTAON) {
1201 oqctl->qc_cmd = Q_QUOTAOFF;
1202 obd_quotactl(sbi->ll_md_exp, oqctl);
1204 OBD_FREE_PTR(oqctl);
1205 GOTO(out_quotactl, rc);
1207 QCTL_COPY(qctl, oqctl);
1208 OBD_FREE_PTR(oqctl);
1212 if (cfs_copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1219 case OBD_IOC_GETNAME: {
1220 struct obd_device *obd = class_exp2obd(sbi->ll_dt_exp);
1223 if (cfs_copy_to_user((void *)arg, obd->obd_name,
1224 strlen(obd->obd_name) + 1))
1228 case LL_IOC_FLUSHCTX:
1229 RETURN(ll_flush_ctx(inode));
1230 #ifdef CONFIG_FS_POSIX_ACL
1231 case LL_IOC_RMTACL: {
1232 if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
1233 inode == inode->i_sb->s_root->d_inode) {
1234 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1237 LASSERT(fd != NULL);
1238 rc = rct_add(&sbi->ll_rct, cfs_curproc_pid(), arg);
1240 fd->fd_flags |= LL_FILE_RMTACL;
1246 case LL_IOC_GETOBDCOUNT: {
1249 if (cfs_copy_from_user(&count, (int *)arg, sizeof(int)))
1254 struct lov_obd *lov = &sbi->ll_dt_exp->exp_obd->u.lov;
1255 count = lov->desc.ld_tgt_count;
1258 struct lmv_obd *lmv = &sbi->ll_md_exp->exp_obd->u.lmv;
1259 count = lmv->desc.ld_tgt_count;
1262 if (cfs_copy_to_user((int *)arg, &count, sizeof(int)))
1267 case LL_IOC_PATH2FID:
1268 if (cfs_copy_to_user((void *)arg, ll_inode2fid(inode),
1269 sizeof(struct lu_fid)))
1272 case OBD_IOC_CHANGELOG_CLEAR: {
1273 struct ioc_changelog_clear *icc;
1279 if (cfs_copy_from_user(icc, (void *)arg, sizeof(*icc)))
1280 GOTO(icc_free, rc = -EFAULT);
1282 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(*icc), icc,NULL);
1288 case OBD_IOC_FID2PATH:
1289 RETURN(ll_fid2path(ll_i2mdexp(inode), (void *)arg));
1292 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp,0,NULL,(void *)arg));
1296 int ll_dir_open(struct inode *inode, struct file *file)
1299 RETURN(ll_file_open(inode, file));
1302 int ll_dir_release(struct inode *inode, struct file *file)
1305 RETURN(ll_file_release(inode, file));
1308 struct file_operations ll_dir_operations = {
1309 .open = ll_dir_open,
1310 .release = ll_dir_release,
1311 .read = generic_read_dir,
1312 .readdir = ll_readdir,
1313 .ioctl = ll_dir_ioctl