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 ll_inode_size_lock(inode, 0);
173 i_size_write(inode, body->size);
174 ll_inode_size_unlock(inode, 0);
176 SetPageUptodate(page);
178 ptlrpc_req_finished(request);
185 struct address_space_operations ll_dir_aops = {
186 .readpage = ll_dir_readpage,
189 static void ll_check_page(struct inode *dir, struct page *page)
191 /* XXX: check page format later */
192 SetPageChecked(page);
195 static void ll_release_page(struct page *page, __u64 hash,
196 __u64 start, __u64 end)
200 if (likely(page->mapping != NULL)) {
201 ll_truncate_complete_page(page);
205 CWARN("NULL mapping page %p, truncated by others: "
206 "hash("LPX64") | start("LPX64") | end("LPX64")\n",
207 page, hash, start, end);
209 page_cache_release(page);
213 * Find, kmap and return page that contains given hash.
215 static struct page *ll_dir_page_locate(struct inode *dir, __u64 hash,
216 __u64 *start, __u64 *end)
218 struct address_space *mapping = dir->i_mapping;
220 * Complement of hash is used as an index so that
221 * radix_tree_gang_lookup() can be used to find a page with starting
222 * hash _smaller_ than one we are looking for.
224 unsigned long offset = hash_x_index((__u32)hash);
228 TREE_READ_LOCK_IRQ(mapping);
229 found = radix_tree_gang_lookup(&mapping->page_tree,
230 (void **)&page, offset, 1);
232 struct lu_dirpage *dp;
234 page_cache_get(page);
235 TREE_READ_UNLOCK_IRQ(mapping);
237 * In contrast to find_lock_page() we are sure that directory
238 * page cannot be truncated (while DLM lock is held) and,
239 * hence, can avoid restart.
241 * In fact, page cannot be locked here at all, because
242 * ll_dir_readpage() does synchronous io.
245 if (PageUptodate(page)) {
247 *start = le64_to_cpu(dp->ldp_hash_start);
248 *end = le64_to_cpu(dp->ldp_hash_end);
249 LASSERT(*start <= hash);
250 if (hash > *end || (*end != *start && hash == *end)) {
251 ll_release_page(page, hash, *start, *end);
255 page_cache_release(page);
256 page = ERR_PTR(-EIO);
260 TREE_READ_UNLOCK_IRQ(mapping);
266 struct page *ll_get_dir_page(struct inode *dir, __u64 hash, int exact,
267 struct ll_dir_chain *chain)
269 ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_UPDATE} };
270 struct address_space *mapping = dir->i_mapping;
271 struct lustre_handle lockh;
272 struct lu_dirpage *dp;
280 rc = md_lock_match(ll_i2sbi(dir)->ll_md_exp, LDLM_FL_BLOCK_GRANTED,
281 ll_inode2fid(dir), LDLM_IBITS, &policy, mode, &lockh);
283 struct ldlm_enqueue_info einfo = { LDLM_IBITS, mode,
284 ll_md_blocking_ast, ldlm_completion_ast, NULL, dir };
285 struct lookup_intent it = { .it_op = IT_READDIR };
286 struct ptlrpc_request *request;
287 struct md_op_data *op_data;
289 op_data = ll_prep_md_op_data(NULL, dir, NULL, NULL, 0, 0,
290 LUSTRE_OPC_ANY, NULL);
292 return (void *)op_data;
294 rc = md_enqueue(ll_i2sbi(dir)->ll_md_exp, &einfo, &it,
295 op_data, &lockh, NULL, 0, NULL, 0);
297 ll_finish_md_op_data(op_data);
299 request = (struct ptlrpc_request *)it.d.lustre.it_data;
301 ptlrpc_req_finished(request);
303 CERROR("lock enqueue: rc: %d\n", rc);
307 /* for cross-ref object, l_ast_data of the lock may not be set,
308 * we reset it here */
309 md_set_lock_data(ll_i2sbi(dir)->ll_md_exp, &lockh.cookie, dir);
311 ldlm_lock_dump_handle(D_OTHER, &lockh);
313 page = ll_dir_page_locate(dir, hash, &start, &end);
315 GOTO(out_unlock, page);
319 * XXX nikita: not entirely correct handling of a corner case:
320 * suppose hash chain of entries with hash value HASH crosses
321 * border between pages P0 and P1. First both P0 and P1 are
322 * cached, seekdir() is called for some entry from the P0 part
323 * of the chain. Later P0 goes out of cache. telldir(HASH)
324 * happens and finds P1, as it starts with matching hash
325 * value. Remaining entries from P0 part of the chain are
326 * skipped. (Is that really a bug?)
328 * Possible solutions: 0. don't cache P1 is such case, handle
329 * it as an "overflow" page. 1. invalidate all pages at
330 * once. 2. use HASH|1 as an index for P1.
332 if (exact && hash != start) {
334 * readdir asked for a page starting _exactly_ from
335 * given hash, but cache contains stale page, with
336 * entries with smaller hash values. Stale page should
337 * be invalidated, and new one fetched.
339 CWARN("Stale readpage page %p: "LPX64" != "LPX64"\n",
341 ll_release_page(page, hash, start, end);
343 GOTO(hash_collision, page);
347 page = read_cache_page(mapping, hash_x_index((__u32)hash),
348 (filler_t*)mapping->a_ops->readpage, NULL);
350 GOTO(out_unlock, page);
354 if (!PageUptodate(page))
356 if (!PageChecked(page))
357 ll_check_page(dir, page);
361 dp = page_address(page);
363 start = le64_to_cpu(dp->ldp_hash_start);
364 end = le64_to_cpu(dp->ldp_hash_end);
366 LASSERT(start == hash);
367 CWARN("Page-wide hash collision: %#lx\n", (unsigned long)end);
369 * Fetch whole overflow chain...
376 ldlm_lock_decref(&lockh, mode);
381 page = ERR_PTR(-EIO);
385 int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
387 struct inode *inode = filp->f_dentry->d_inode;
388 struct ll_inode_info *info = ll_i2info(inode);
389 struct ll_sb_info *sbi = ll_i2sbi(inode);
390 __u64 pos = filp->f_pos;
392 struct ll_dir_chain chain;
398 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %lu/%llu\n",
399 inode->i_ino, inode->i_generation, inode,
400 (unsigned long)pos, i_size_read(inode));
402 if (pos == DIR_END_OFF)
411 ll_dir_chain_init(&chain);
413 page = ll_get_dir_page(inode, pos, 0, &chain);
415 while (rc == 0 && !done) {
416 struct lu_dirpage *dp;
417 struct lu_dirent *ent;
421 * If page is empty (end of directoryis reached),
424 __u64 hash = DIR_END_OFF;
427 dp = page_address(page);
428 for (ent = lu_dirent_start(dp); ent != NULL && !done;
429 ent = lu_dirent_next(ent)) {
436 * XXX: implement correct swabbing here.
439 hash = le64_to_cpu(ent->lde_hash);
440 namelen = le16_to_cpu(ent->lde_namelen);
444 * Skip until we find target hash
456 name = ent->lde_name;
457 fid_le_to_cpu(&fid, &fid);
458 ino = ll_fid_build_ino(sbi, &fid);
460 done = filldir(cookie, name, namelen,
461 (loff_t)hash, ino, DT_UNKNOWN);
463 next = le64_to_cpu(dp->ldp_hash_end);
467 if (pos == DIR_END_OFF)
469 * End of directory reached.
472 else if (1 /* chain is exhausted*/)
474 * Normal case: continue to the next
477 page = ll_get_dir_page(inode, pos, 1,
481 * go into overflow page.
488 CERROR("error reading dir "DFID" at %lu: rc %d\n",
489 PFID(&info->lli_fid), (unsigned long)pos, rc);
493 filp->f_pos = (loff_t)(__s32)pos;
494 filp->f_version = inode->i_version;
495 touch_atime(filp->f_vfsmnt, filp->f_dentry);
497 ll_dir_chain_fini(&chain);
502 #define QCTL_COPY(out, in) \
504 Q_COPY(out, in, qc_cmd); \
505 Q_COPY(out, in, qc_type); \
506 Q_COPY(out, in, qc_id); \
507 Q_COPY(out, in, qc_stat); \
508 Q_COPY(out, in, qc_dqinfo); \
509 Q_COPY(out, in, qc_dqblk); \
512 int ll_send_mgc_param(struct obd_export *mgc, char *string)
514 struct mgs_send_param *msp;
521 strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN);
522 rc = obd_set_info_async(mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
523 sizeof(struct mgs_send_param), msp, NULL);
525 CERROR("Failed to set parameter: %d\n", rc);
531 char *ll_get_fsname(struct inode *inode)
533 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
537 OBD_ALLOC(fsname, MGS_PARAM_MAXLEN);
538 len = strlen(lsi->lsi_lmd->lmd_profile);
539 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
540 if (ptr && (strcmp(ptr, "-client") == 0))
542 strncpy(fsname, lsi->lsi_lmd->lmd_profile, len);
548 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
551 struct ll_sb_info *sbi = ll_i2sbi(inode);
552 struct md_op_data *op_data;
553 struct ptlrpc_request *req = NULL;
555 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
556 struct obd_device *mgc = lsi->lsi_mgc;
557 char *fsname = NULL, *param = NULL;
561 * This is coming from userspace, so should be in
562 * local endian. But the MDS would like it in little
563 * endian, so we swab it before we send it.
565 switch (lump->lmm_magic) {
566 case LOV_USER_MAGIC_V1: {
567 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V1))
568 lustre_swab_lov_user_md_v1(lump);
569 lum_size = sizeof(struct lov_user_md_v1);
572 case LOV_USER_MAGIC_V3: {
573 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V3))
574 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lump);
575 lum_size = sizeof(struct lov_user_md_v3);
579 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
580 " %#08x != %#08x nor %#08x\n",
581 lump->lmm_magic, LOV_USER_MAGIC_V1,
587 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
588 LUSTRE_OPC_ANY, NULL);
590 RETURN(PTR_ERR(op_data));
592 /* swabbing is done in lov_setstripe() on server side */
593 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size,
594 NULL, 0, &req, NULL);
595 ll_finish_md_op_data(op_data);
596 ptlrpc_req_finished(req);
598 if (rc != -EPERM && rc != -EACCES)
599 CERROR("mdc_setattr fails: rc = %d\n", rc);
602 /* In the following we use the fact that LOV_USER_MAGIC_V1 and
603 LOV_USER_MAGIC_V3 have the same initial fields so we do not
604 need the make the distiction between the 2 versions */
605 if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
606 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
608 /* Get fsname and assume devname to be -MDT0000. */
609 fsname = ll_get_fsname(inode);
610 /* Set root stripesize */
611 sprintf(param, "%s-MDT0000.lov.stripesize=%u", fsname,
612 lump->lmm_stripe_size);
613 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
617 /* Set root stripecount */
618 sprintf(param, "%s-MDT0000.lov.stripecount=%u", fsname,
619 lump->lmm_stripe_count);
620 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
624 /* Set root stripeoffset */
625 sprintf(param, "%s-MDT0000.lov.stripeoffset=%u", fsname,
626 lump->lmm_stripe_offset);
627 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
632 OBD_FREE(fsname, MGS_PARAM_MAXLEN);
634 OBD_FREE(param, MGS_PARAM_MAXLEN);
639 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
640 int *lmm_size, struct ptlrpc_request **request)
642 struct ll_sb_info *sbi = ll_i2sbi(inode);
643 struct mdt_body *body;
644 struct lov_mds_md *lmm = NULL;
645 struct ptlrpc_request *req = NULL;
649 rc = ll_get_max_mdsize(sbi, &lmmsize);
653 oc = ll_mdscapa_get(inode);
654 rc = md_getattr(sbi->ll_md_exp, ll_inode2fid(inode),
655 oc, OBD_MD_FLEASIZE | OBD_MD_FLDIREA,
659 CDEBUG(D_INFO, "md_getattr failed on inode "
660 "%lu/%u: rc %d\n", inode->i_ino,
661 inode->i_generation, rc);
665 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
666 LASSERT(body != NULL);
668 lmmsize = body->eadatasize;
670 if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
672 GOTO(out, rc = -ENODATA);
675 lmm = req_capsule_server_sized_get(&req->rq_pill,
676 &RMF_MDT_MD, lmmsize);
677 LASSERT(lmm != NULL);
680 * This is coming from the MDS, so is probably in
681 * little endian. We convert it to host endian before
682 * passing it to userspace.
684 /* We don't swab objects for directories */
685 switch (le32_to_cpu(lmm->lmm_magic)) {
687 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
688 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
691 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
692 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
695 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
705 static int ll_dir_ioctl(struct inode *inode, struct file *file,
706 unsigned int cmd, unsigned long arg)
708 struct ll_sb_info *sbi = ll_i2sbi(inode);
709 struct obd_ioctl_data *data;
712 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), cmd=%#x\n",
713 inode->i_ino, inode->i_generation, inode, cmd);
715 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
716 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
719 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
721 case EXT3_IOC_GETFLAGS:
722 case EXT3_IOC_SETFLAGS:
723 RETURN(ll_iocontrol(inode, file, cmd, arg));
724 case EXT3_IOC_GETVERSION_OLD:
725 case EXT3_IOC_GETVERSION:
726 RETURN(put_user(inode->i_generation, (int *)arg));
727 /* We need to special case any other ioctls we want to handle,
728 * to send them to the MDS/OST as appropriate and to properly
729 * network encode the arg field.
730 case EXT3_IOC_SETVERSION_OLD:
731 case EXT3_IOC_SETVERSION:
733 case IOC_MDC_LOOKUP: {
734 struct ptlrpc_request *request = NULL;
735 int namelen, rc, len = 0;
740 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
745 filename = data->ioc_inlbuf1;
746 namelen = data->ioc_inllen1;
749 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
750 GOTO(out, rc = -EINVAL);
753 oc = ll_mdscapa_get(inode);
754 rc = md_getattr_name(sbi->ll_md_exp, ll_inode2fid(inode), oc,
755 filename, namelen, OBD_MD_FLID, 0,
756 ll_i2suppgid(inode), &request);
759 CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
763 ptlrpc_req_finished(request);
767 obd_ioctl_freedata(buf, len);
770 case LL_IOC_LOV_SETSTRIPE: {
771 struct lov_user_md_v3 lumv3;
772 struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
773 struct lov_user_md_v1 *lumv1p = (struct lov_user_md_v1 *)arg;
774 struct lov_user_md_v3 *lumv3p = (struct lov_user_md_v3 *)arg;
779 LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
780 LASSERT(sizeof(lumv3.lmm_objects[0]) ==
781 sizeof(lumv3p->lmm_objects[0]));
782 /* first try with v1 which is smaller than v3 */
783 rc = copy_from_user(lumv1, lumv1p, sizeof(*lumv1));
787 if (lumv1->lmm_magic == LOV_USER_MAGIC_V3) {
788 rc = copy_from_user(&lumv3, lumv3p, sizeof(lumv3));
793 if (inode->i_sb->s_root == file->f_dentry)
796 /* in v1 and v3 cases lumv1 points to data */
797 rc = ll_dir_setstripe(inode, lumv1, set_default);
801 case LL_IOC_OBD_STATFS:
802 RETURN(ll_obd_statfs(inode, (void *)arg));
803 case LL_IOC_LOV_GETSTRIPE:
804 case LL_IOC_MDC_GETINFO:
805 case IOC_MDC_GETFILEINFO:
806 case IOC_MDC_GETFILESTRIPE: {
807 struct ptlrpc_request *request = NULL;
808 struct lov_user_md *lump;
809 struct lov_mds_md *lmm = NULL;
810 struct mdt_body *body;
811 char *filename = NULL;
814 if (cmd == IOC_MDC_GETFILEINFO ||
815 cmd == IOC_MDC_GETFILESTRIPE) {
816 filename = getname((const char *)arg);
817 if (IS_ERR(filename))
818 RETURN(PTR_ERR(filename));
820 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
823 rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
827 body = req_capsule_server_get(&request->rq_pill,
829 LASSERT(body != NULL);
835 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
836 cmd == LL_IOC_MDC_GETINFO))
837 GOTO(skip_lmm, rc = 0);
842 if (cmd == IOC_MDC_GETFILESTRIPE ||
843 cmd == LL_IOC_LOV_GETSTRIPE) {
844 lump = (struct lov_user_md *)arg;
846 struct lov_user_mds_data *lmdp;
847 lmdp = (struct lov_user_mds_data *)arg;
848 lump = &lmdp->lmd_lmm;
850 rc = copy_to_user(lump, lmm, lmmsize);
852 GOTO(out_lmm, rc = -EFAULT);
854 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
855 struct lov_user_mds_data *lmdp;
858 st.st_dev = inode->i_sb->s_dev;
859 st.st_mode = body->mode;
860 st.st_nlink = body->nlink;
861 st.st_uid = body->uid;
862 st.st_gid = body->gid;
863 st.st_rdev = body->rdev;
864 st.st_size = body->size;
865 st.st_blksize = CFS_PAGE_SIZE;
866 st.st_blocks = body->blocks;
867 st.st_atime = body->atime;
868 st.st_mtime = body->mtime;
869 st.st_ctime = body->ctime;
870 st.st_ino = inode->i_ino;
872 lmdp = (struct lov_user_mds_data *)arg;
873 rc = copy_to_user(&lmdp->lmd_st, &st, sizeof(st));
875 GOTO(out_lmm, rc = -EFAULT);
880 if (lmm && lmm->lmm_magic == LOV_MAGIC_JOIN)
881 OBD_FREE(lmm, lmmsize);
883 ptlrpc_req_finished(request);
888 case IOC_LOV_GETINFO: {
889 struct lov_user_mds_data *lumd;
890 struct lov_stripe_md *lsm;
891 struct lov_user_md *lum;
892 struct lov_mds_md *lmm;
897 lumd = (struct lov_user_mds_data *)arg;
898 lum = &lumd->lmd_lmm;
900 rc = ll_get_max_mdsize(sbi, &lmmsize);
904 OBD_ALLOC(lmm, lmmsize);
905 rc = copy_from_user(lmm, lum, lmmsize);
907 GOTO(free_lmm, rc = -EFAULT);
909 switch (lmm->lmm_magic) {
910 case LOV_USER_MAGIC_V1:
911 if (LOV_USER_MAGIC_V1 == cpu_to_le32(LOV_USER_MAGIC_V1))
913 /* swab objects first so that stripes num will be sane */
914 lustre_swab_lov_user_md_objects(
915 ((struct lov_user_md_v1 *)lmm)->lmm_objects,
916 ((struct lov_user_md_v1 *)lmm)->lmm_stripe_count);
917 lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
919 case LOV_USER_MAGIC_V3:
920 if (LOV_USER_MAGIC_V3 == cpu_to_le32(LOV_USER_MAGIC_V3))
922 /* swab objects first so that stripes num will be sane */
923 lustre_swab_lov_user_md_objects(
924 ((struct lov_user_md_v3 *)lmm)->lmm_objects,
925 ((struct lov_user_md_v3 *)lmm)->lmm_stripe_count);
926 lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
929 GOTO(free_lmm, rc = -EINVAL);
932 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
934 GOTO(free_lmm, rc = -ENOMEM);
936 rc = obd_checkmd(sbi->ll_dt_exp, sbi->ll_md_exp, lsm);
940 /* Perform glimpse_size operation. */
941 memset(&st, 0, sizeof(st));
943 rc = ll_glimpse_ioctl(sbi, lsm, &st);
947 rc = copy_to_user(&lumd->lmd_st, &st, sizeof(st));
949 GOTO(free_lsm, rc = -EFAULT);
953 obd_free_memmd(sbi->ll_dt_exp, &lsm);
955 OBD_FREE(lmm, lmmsize);
958 case OBD_IOC_LLOG_CATINFO: {
959 struct ptlrpc_request *req = NULL;
965 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
970 if (!data->ioc_inlbuf1) {
971 obd_ioctl_freedata(buf, len);
975 req = ptlrpc_request_alloc(sbi2mdc(sbi)->cl_import,
978 GOTO(out_catinfo, rc = -ENOMEM);
980 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
982 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_CLIENT,
985 rc = ptlrpc_request_pack(req, LUSTRE_LOG_VERSION, LLOG_CATINFO);
987 ptlrpc_request_free(req);
988 GOTO(out_catinfo, rc);
991 str = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
992 memcpy(str, data->ioc_inlbuf1, data->ioc_inllen1);
993 if (data->ioc_inllen2) {
994 str = req_capsule_client_get(&req->rq_pill,
996 memcpy(str, data->ioc_inlbuf2, data->ioc_inllen2);
999 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_SERVER,
1001 ptlrpc_request_set_replen(req);
1003 rc = ptlrpc_queue_wait(req);
1005 str = req_capsule_server_get(&req->rq_pill,
1007 rc = copy_to_user(data->ioc_pbuf1, str, data->ioc_plen1);
1009 ptlrpc_req_finished(req);
1011 obd_ioctl_freedata(buf, len);
1014 case OBD_IOC_QUOTACHECK: {
1015 struct obd_quotactl *oqctl;
1018 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
1021 OBD_ALLOC_PTR(oqctl);
1024 oqctl->qc_type = arg;
1025 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
1027 CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
1031 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
1033 CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
1035 OBD_FREE_PTR(oqctl);
1038 case OBD_IOC_POLL_QUOTACHECK: {
1039 struct if_quotacheck *check;
1042 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
1045 OBD_ALLOC_PTR(check);
1049 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
1052 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
1053 if (copy_to_user((void *)arg, check, sizeof(*check)))
1058 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
1061 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
1062 if (copy_to_user((void *)arg, check, sizeof(*check)))
1067 OBD_FREE_PTR(check);
1070 #ifdef HAVE_QUOTA_SUPPORT
1071 case OBD_IOC_QUOTACTL: {
1072 struct if_quotactl *qctl;
1073 struct obd_quotactl *oqctl;
1075 int cmd, type, id, rc = 0;
1077 OBD_ALLOC_PTR(qctl);
1081 OBD_ALLOC_PTR(oqctl);
1086 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
1087 GOTO(out_quotactl, rc = -EFAULT);
1090 type = qctl->qc_type;
1097 if (!cfs_capable(CFS_CAP_SYS_ADMIN))
1098 GOTO(out_quotactl, rc = -EPERM);
1101 if (((type == USRQUOTA && current->euid != id) ||
1102 (type == GRPQUOTA && !in_egroup_p(id))) &&
1103 !cfs_capable(CFS_CAP_SYS_ADMIN))
1104 GOTO(out_quotactl, rc = -EPERM);
1106 /* XXX: dqb_valid is borrowed as a flag to mark that
1107 * only mds quota is wanted */
1108 if (qctl->qc_dqblk.dqb_valid)
1109 qctl->obd_uuid = sbi->ll_md_exp->exp_obd->
1110 u.cli.cl_target_uuid;
1115 CERROR("unsupported quotactl op: %#x\n", cmd);
1116 GOTO(out_quotactl, rc = -ENOTTY);
1119 QCTL_COPY(oqctl, qctl);
1121 if (qctl->obd_uuid.uuid[0]) {
1122 struct obd_device *obd;
1123 struct obd_uuid *uuid = &qctl->obd_uuid;
1125 obd = class_find_client_notype(uuid,
1126 &sbi->ll_dt_exp->exp_obd->obd_uuid);
1128 GOTO(out_quotactl, rc = -ENOENT);
1130 if (cmd == Q_GETINFO)
1131 oqctl->qc_cmd = Q_GETOINFO;
1132 else if (cmd == Q_GETQUOTA)
1133 oqctl->qc_cmd = Q_GETOQUOTA;
1135 GOTO(out_quotactl, rc = -EINVAL);
1137 if (sbi->ll_md_exp->exp_obd == obd) {
1138 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1141 struct obd_export *exp;
1142 struct lov_obd *lov = &sbi->ll_dt_exp->
1145 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1146 if (!lov->lov_tgts[i] ||
1147 !lov->lov_tgts[i]->ltd_active)
1149 exp = lov->lov_tgts[i]->ltd_exp;
1150 if (exp->exp_obd == obd) {
1151 rc = obd_quotactl(exp, oqctl);
1157 oqctl->qc_cmd = cmd;
1158 QCTL_COPY(qctl, oqctl);
1160 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1163 GOTO(out_quotactl, rc);
1166 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1167 if (rc && rc != -EBUSY && cmd == Q_QUOTAON) {
1168 oqctl->qc_cmd = Q_QUOTAOFF;
1169 obd_quotactl(sbi->ll_md_exp, oqctl);
1172 QCTL_COPY(qctl, oqctl);
1174 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1178 OBD_FREE_PTR(oqctl);
1181 #endif /* HAVE_QUOTA_SUPPORT */
1182 case OBD_IOC_GETNAME: {
1183 struct obd_device *obd = class_exp2obd(sbi->ll_dt_exp);
1186 if (copy_to_user((void *)arg, obd->obd_name,
1187 strlen(obd->obd_name) + 1))
1191 case LL_IOC_FLUSHCTX:
1192 RETURN(ll_flush_ctx(inode));
1193 #ifdef CONFIG_FS_POSIX_ACL
1194 case LL_IOC_RMTACL: {
1195 if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
1196 inode == inode->i_sb->s_root->d_inode) {
1197 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1200 LASSERT(fd != NULL);
1201 rc = rct_add(&sbi->ll_rct, cfs_curproc_pid(), arg);
1203 fd->fd_flags |= LL_FILE_RMTACL;
1210 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp,0,NULL,(void *)arg));
1214 int ll_dir_open(struct inode *inode, struct file *file)
1217 RETURN(ll_file_open(inode, file));
1220 int ll_dir_release(struct inode *inode, struct file *file)
1223 RETURN(ll_file_release(inode, file));
1226 struct file_operations ll_dir_operations = {
1227 .open = ll_dir_open,
1228 .release = ll_dir_release,
1229 .read = generic_read_dir,
1230 .readdir = ll_readdir,
1231 .ioctl = ll_dir_ioctl