1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
11 * linux/fs/minix/dir.c
14 * Copyright (C) 1991, 1992 Linus Torvalds
16 * ext2 directory handling functions
18 * Big-endian to little-endian byte-swapping/bitmaps by
19 * David S. Miller (davem@caip.rutgers.edu), 1995
21 * All code that works with directory layout had been switched to pagecache
24 * Adapted for Lustre Light
25 * Copyright (C) 2002-2003, Cluster File Systems, Inc.
30 #include <linux/pagemap.h>
32 #include <linux/version.h>
33 #include <linux/smp_lock.h>
34 #include <asm/uaccess.h>
35 #include <linux/buffer_head.h> // for wait_on_buffer
37 #define DEBUG_SUBSYSTEM S_LLITE
39 #include <obd_support.h>
40 #include <obd_class.h>
41 #include <lustre_lib.h>
42 #include <lustre/lustre_idl.h>
43 #include <lustre_lite.h>
44 #include <lustre_dlm.h>
45 #include <lustre_fid.h>
46 #include "llite_internal.h"
48 #ifndef HAVE_PAGE_CHECKED
49 #ifdef HAVE_PG_FS_MISC
50 #define PageChecked(page) test_bit(PG_fs_misc, &(page)->flags)
51 #define SetPageChecked(page) set_bit(PG_fs_misc, &(page)->flags)
53 #error PageChecked or PageFsMisc not defined in kernel
58 * (new) readdir implementation overview.
60 * Original lustre readdir implementation cached exact copy of raw directory
61 * pages on the client. These pages were indexed in client page cache by
62 * logical offset in the directory file. This design, while very simple and
63 * intuitive had some inherent problems:
65 * . it implies that byte offset to the directory entry serves as a
66 * telldir(3)/seekdir(3) cookie, but that offset is not stable: in
67 * ext3/htree directory entries may move due to splits, and more
70 * . it is incompatible with the design of split directories for cmd3,
71 * that assumes that names are distributed across nodes based on their
72 * hash, and so readdir should be done in hash order.
74 * New readdir implementation does readdir in hash order, and uses hash of a
75 * file name as a telldir/seekdir cookie. This led to number of complications:
77 * . hash is not unique, so it cannot be used to index cached directory
78 * pages on the client (note, that it requires a whole pageful of hash
79 * collided entries to cause two pages to have identical hashes);
81 * . hash is not unique, so it cannot, strictly speaking, be used as an
82 * entry cookie. ext3/htree has the same problem and lustre implementation
83 * mimics their solution: seekdir(hash) positions directory at the first
84 * entry with the given hash.
90 * Client caches directory pages using hash of the first entry as an index. As
91 * noted above hash is not unique, so this solution doesn't work as is:
92 * special processing is needed for "page hash chains" (i.e., sequences of
93 * pages filled with entries all having the same hash value).
95 * First, such chains have to be detected. To this end, server returns to the
96 * client the hash of the first entry on the page next to one returned. When
97 * client detects that this hash is the same as hash of the first entry on the
98 * returned page, page hash collision has to be handled. Pages in the
99 * hash chain, except first one, are termed "overflow pages".
101 * Solution to index uniqueness problem is to not cache overflow
102 * pages. Instead, when page hash collision is detected, all overflow pages
103 * from emerging chain are immediately requested from the server and placed in
104 * a special data structure (struct ll_dir_chain). This data structure is used
105 * by ll_readdir() to process entries from overflow pages. When readdir
106 * invocation finishes, overflow pages are discarded. If page hash collision
107 * chain weren't completely processed, next call to readdir will again detect
108 * page hash collision, again read overflow pages in, process next portion of
109 * entries and again discard the pages. This is not as wasteful as it looks,
110 * because, given reasonable hash, page hash collisions are extremely rare.
112 * 1. directory positioning
114 * When seekdir(hash) is called, original
125 * identification of and access to overflow pages
135 /* returns the page unlocked, but with a reference */
136 static int ll_dir_readpage(struct file *file, struct page *page)
138 struct inode *inode = page->mapping->host;
139 struct ptlrpc_request *request;
140 struct mdt_body *body;
146 hash = (__u64)hash_x_index(page->index);
147 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) off %lu\n",
148 inode->i_ino, inode->i_generation, inode, (unsigned long)hash);
150 oc = ll_mdscapa_get(inode);
151 rc = md_readpage(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode),
152 oc, hash, page, &request);
155 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
156 /* Checked by mdc_readpage() */
157 LASSERT(body != NULL);
159 if (body->valid & OBD_MD_FLSIZE) {
160 ll_inode_size_lock(inode, 0);
161 i_size_write(inode, body->size);
162 ll_inode_size_unlock(inode, 0);
164 SetPageUptodate(page);
166 ptlrpc_req_finished(request);
173 struct address_space_operations ll_dir_aops = {
174 .readpage = ll_dir_readpage,
177 static void ll_check_page(struct inode *dir, struct page *page)
179 /* XXX: check page format later */
180 SetPageChecked(page);
183 static void ll_release_page(struct page *page, __u64 hash,
184 __u64 start, __u64 end)
188 if (likely(page->mapping != NULL)) {
189 ll_truncate_complete_page(page);
193 CWARN("NULL mapping page %p, truncated by others: "
194 "hash(%#llx) | start(%#llx) | end(%#llx)\n",
195 page, hash, start, end);
197 page_cache_release(page);
201 * Find, kmap and return page that contains given hash.
203 static struct page *ll_dir_page_locate(struct inode *dir, __u64 hash,
204 __u64 *start, __u64 *end)
206 struct address_space *mapping = dir->i_mapping;
208 * Complement of hash is used as an index so that
209 * radix_tree_gang_lookup() can be used to find a page with starting
210 * hash _smaller_ than one we are looking for.
212 unsigned long offset = hash_x_index((__u32)hash);
216 TREE_READ_LOCK_IRQ(mapping);
217 found = radix_tree_gang_lookup(&mapping->page_tree,
218 (void **)&page, offset, 1);
220 struct lu_dirpage *dp;
222 page_cache_get(page);
223 TREE_READ_UNLOCK_IRQ(mapping);
225 * In contrast to find_lock_page() we are sure that directory
226 * page cannot be truncated (while DLM lock is held) and,
227 * hence, can avoid restart.
229 * In fact, page cannot be locked here at all, because
230 * ll_dir_readpage() does synchronous io.
233 if (PageUptodate(page)) {
235 *start = le64_to_cpu(dp->ldp_hash_start);
236 *end = le64_to_cpu(dp->ldp_hash_end);
237 LASSERT(*start <= hash);
238 if (hash > *end || (*end != *start && hash == *end)) {
239 ll_release_page(page, hash, *start, *end);
243 page_cache_release(page);
244 page = ERR_PTR(-EIO);
248 TREE_READ_UNLOCK_IRQ(mapping);
254 struct page *ll_get_dir_page(struct inode *dir, __u64 hash, int exact,
255 struct ll_dir_chain *chain)
257 ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_UPDATE} };
258 struct address_space *mapping = dir->i_mapping;
259 struct lustre_handle lockh;
260 struct lu_dirpage *dp;
268 rc = md_lock_match(ll_i2sbi(dir)->ll_md_exp, LDLM_FL_BLOCK_GRANTED,
269 ll_inode2fid(dir), LDLM_IBITS, &policy, mode, &lockh);
271 struct ldlm_enqueue_info einfo = { LDLM_IBITS, mode,
272 ll_md_blocking_ast, ldlm_completion_ast, NULL, dir };
273 struct lookup_intent it = { .it_op = IT_READDIR };
274 struct ptlrpc_request *request;
275 struct md_op_data *op_data;
277 op_data = ll_prep_md_op_data(NULL, dir, NULL, NULL, 0, 0,
278 LUSTRE_OPC_ANY, NULL);
280 return (void *)op_data;
282 rc = md_enqueue(ll_i2sbi(dir)->ll_md_exp, &einfo, &it,
283 op_data, &lockh, NULL, 0, 0);
285 ll_finish_md_op_data(op_data);
287 request = (struct ptlrpc_request *)it.d.lustre.it_data;
289 ptlrpc_req_finished(request);
291 CERROR("lock enqueue: rc: %d\n", rc);
295 /* for cross-ref object, l_ast_data of the lock may not be set,
296 * we reset it here */
297 md_set_lock_data(ll_i2sbi(dir)->ll_md_exp, &lockh.cookie, dir);
299 ldlm_lock_dump_handle(D_OTHER, &lockh);
301 page = ll_dir_page_locate(dir, hash, &start, &end);
303 GOTO(out_unlock, page);
307 * XXX nikita: not entirely correct handling of a corner case:
308 * suppose hash chain of entries with hash value HASH crosses
309 * border between pages P0 and P1. First both P0 and P1 are
310 * cached, seekdir() is called for some entry from the P0 part
311 * of the chain. Later P0 goes out of cache. telldir(HASH)
312 * happens and finds P1, as it starts with matching hash
313 * value. Remaining entries from P0 part of the chain are
314 * skipped. (Is that really a bug?)
316 * Possible solutions: 0. don't cache P1 is such case, handle
317 * it as an "overflow" page. 1. invalidate all pages at
318 * once. 2. use HASH|1 as an index for P1.
320 if (exact && hash != start) {
322 * readdir asked for a page starting _exactly_ from
323 * given hash, but cache contains stale page, with
324 * entries with smaller hash values. Stale page should
325 * be invalidated, and new one fetched.
327 CWARN("Stale readpage page %p: %#llx != %#llx\n",
329 ll_release_page(page, hash, start, end);
331 GOTO(hash_collision, page);
335 page = read_cache_page(mapping, hash_x_index((__u32)hash),
336 (filler_t*)mapping->a_ops->readpage, NULL);
338 GOTO(out_unlock, page);
342 if (!PageUptodate(page))
344 if (!PageChecked(page))
345 ll_check_page(dir, page);
349 dp = page_address(page);
351 start = le64_to_cpu(dp->ldp_hash_start);
352 end = le64_to_cpu(dp->ldp_hash_end);
354 LASSERT(start == hash);
355 CWARN("Page-wide hash collision: %#lx\n", (unsigned long)end);
357 * Fetch whole overflow chain...
364 ldlm_lock_decref(&lockh, mode);
369 page = ERR_PTR(-EIO);
373 int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
375 struct inode *inode = filp->f_dentry->d_inode;
376 struct ll_inode_info *info = ll_i2info(inode);
377 struct ll_sb_info *sbi = ll_i2sbi(inode);
378 __u64 pos = filp->f_pos;
380 struct ll_dir_chain chain;
386 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %lu/%llu\n",
387 inode->i_ino, inode->i_generation, inode,
388 (unsigned long)pos, i_size_read(inode));
390 if (pos == DIR_END_OFF)
399 ll_dir_chain_init(&chain);
401 page = ll_get_dir_page(inode, pos, 0, &chain);
403 while (rc == 0 && !done) {
404 struct lu_dirpage *dp;
405 struct lu_dirent *ent;
409 * If page is empty (end of directoryis reached),
412 __u64 hash = DIR_END_OFF;
415 dp = page_address(page);
416 for (ent = lu_dirent_start(dp); ent != NULL && !done;
417 ent = lu_dirent_next(ent)) {
424 * XXX: implement correct swabbing here.
427 hash = le64_to_cpu(ent->lde_hash);
428 namelen = le16_to_cpu(ent->lde_namelen);
432 * Skip until we find target hash
444 name = ent->lde_name;
445 fid_le_to_cpu(&fid, &fid);
446 ino = ll_fid_build_ino(sbi, &fid);
448 done = filldir(cookie, name, namelen,
449 (loff_t)hash, ino, DT_UNKNOWN);
451 next = le64_to_cpu(dp->ldp_hash_end);
455 if (pos == DIR_END_OFF)
457 * End of directory reached.
460 else if (1 /* chain is exhausted*/)
462 * Normal case: continue to the next
465 page = ll_get_dir_page(inode, pos, 1,
469 * go into overflow page.
476 CERROR("error reading dir "DFID" at %lu: rc %d\n",
477 PFID(&info->lli_fid), (unsigned long)pos, rc);
481 filp->f_pos = (loff_t)(__s32)pos;
482 filp->f_version = inode->i_version;
483 touch_atime(filp->f_vfsmnt, filp->f_dentry);
485 ll_dir_chain_fini(&chain);
490 #define QCTL_COPY(out, in) \
492 Q_COPY(out, in, qc_cmd); \
493 Q_COPY(out, in, qc_type); \
494 Q_COPY(out, in, qc_id); \
495 Q_COPY(out, in, qc_stat); \
496 Q_COPY(out, in, qc_dqinfo); \
497 Q_COPY(out, in, qc_dqblk); \
500 int ll_send_mgc_param(struct obd_export *mgc, char *string)
502 struct mgs_send_param *msp;
509 strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN);
510 rc = obd_set_info_async(mgc, strlen(KEY_SET_INFO), KEY_SET_INFO,
511 sizeof(struct mgs_send_param), msp, NULL);
513 CERROR("Failed to set parameter: %d\n", rc);
519 char *ll_get_fsname(struct inode *inode)
521 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
525 OBD_ALLOC(fsname, MGS_PARAM_MAXLEN);
526 len = strlen(lsi->lsi_lmd->lmd_profile);
527 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
528 if (ptr && (strcmp(ptr, "-client") == 0))
530 strncpy(fsname, lsi->lsi_lmd->lmd_profile, len);
536 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
539 struct ll_sb_info *sbi = ll_i2sbi(inode);
540 struct md_op_data *op_data;
541 struct ptlrpc_request *req = NULL;
543 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
544 struct obd_device *mgc = lsi->lsi_mgc;
545 char *fsname = NULL, *param = NULL;
548 * This is coming from userspace, so should be in
549 * local endian. But the MDS would like it in little
550 * endian, so we swab it before we send it.
552 if (lump->lmm_magic != LOV_USER_MAGIC)
555 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC))
556 lustre_swab_lov_user_md(lump);
558 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
559 LUSTRE_OPC_ANY, NULL);
561 RETURN(PTR_ERR(op_data));
563 /* swabbing is done in lov_setstripe() on server side */
564 rc = md_setattr(sbi->ll_md_exp, op_data, lump, sizeof(*lump),
565 NULL, 0, &req, NULL);
566 ll_finish_md_op_data(op_data);
567 ptlrpc_req_finished(req);
569 if (rc != -EPERM && rc != -EACCES)
570 CERROR("mdc_setattr fails: rc = %d\n", rc);
573 if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
574 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
576 /* Get fsname and assume devname to be -MDT0000. */
577 fsname = ll_get_fsname(inode);
578 /* Set root stripesize */
579 sprintf(param, "%s-MDT0000.lov.stripesize=%u", fsname,
580 lump->lmm_stripe_size);
581 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
585 /* Set root stripecount */
586 sprintf(param, "%s-MDT0000.lov.stripecount=%u", fsname,
587 lump->lmm_stripe_count);
588 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
592 /* Set root stripeoffset */
593 sprintf(param, "%s-MDT0000.lov.stripeoffset=%u", fsname,
594 lump->lmm_stripe_offset);
595 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
600 OBD_FREE(fsname, MGS_PARAM_MAXLEN);
602 OBD_FREE(param, MGS_PARAM_MAXLEN);
607 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
608 int *lmm_size, struct ptlrpc_request **request)
610 struct ll_sb_info *sbi = ll_i2sbi(inode);
611 struct mdt_body *body;
612 struct lov_mds_md *lmm = NULL;
613 struct ptlrpc_request *req = NULL;
617 rc = ll_get_max_mdsize(sbi, &lmmsize);
621 oc = ll_mdscapa_get(inode);
622 rc = md_getattr(sbi->ll_md_exp, ll_inode2fid(inode),
623 oc, OBD_MD_FLEASIZE | OBD_MD_FLDIREA,
627 CDEBUG(D_INFO, "md_getattr failed on inode "
628 "%lu/%u: rc %d\n", inode->i_ino,
629 inode->i_generation, rc);
633 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
634 LASSERT(body != NULL);
636 lmmsize = body->eadatasize;
638 if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
640 GOTO(out, rc = -ENODATA);
643 lmm = req_capsule_server_sized_get(&req->rq_pill,
644 &RMF_MDT_MD, lmmsize);
645 LASSERT(lmm != NULL);
648 * This is coming from the MDS, so is probably in
649 * little endian. We convert it to host endian before
650 * passing it to userspace.
652 if (lmm->lmm_magic == __swab32(LOV_MAGIC)) {
653 lustre_swab_lov_user_md((struct lov_user_md *)lmm);
662 static int ll_dir_ioctl(struct inode *inode, struct file *file,
663 unsigned int cmd, unsigned long arg)
665 struct ll_sb_info *sbi = ll_i2sbi(inode);
666 struct obd_ioctl_data *data;
669 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), cmd=%#x\n",
670 inode->i_ino, inode->i_generation, inode, cmd);
672 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
673 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
676 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
678 case EXT3_IOC_GETFLAGS:
679 case EXT3_IOC_SETFLAGS:
680 RETURN(ll_iocontrol(inode, file, cmd, arg));
681 case EXT3_IOC_GETVERSION_OLD:
682 case EXT3_IOC_GETVERSION:
683 RETURN(put_user(inode->i_generation, (int *)arg));
684 /* We need to special case any other ioctls we want to handle,
685 * to send them to the MDS/OST as appropriate and to properly
686 * network encode the arg field.
687 case EXT3_IOC_SETVERSION_OLD:
688 case EXT3_IOC_SETVERSION:
690 case IOC_MDC_LOOKUP: {
691 struct ptlrpc_request *request = NULL;
692 int namelen, rc, len = 0;
697 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
702 filename = data->ioc_inlbuf1;
703 namelen = data->ioc_inllen1;
706 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
707 GOTO(out, rc = -EINVAL);
710 oc = ll_mdscapa_get(inode);
711 rc = md_getattr_name(sbi->ll_md_exp, ll_inode2fid(inode), oc,
712 filename, namelen, OBD_MD_FLID, 0,
713 ll_i2suppgid(inode), &request);
716 CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
720 ptlrpc_req_finished(request);
724 obd_ioctl_freedata(buf, len);
727 case LL_IOC_LOV_SETSTRIPE: {
728 struct lov_user_md lum, *lump = (struct lov_user_md *)arg;
732 LASSERT(sizeof(lum) == sizeof(*lump));
733 LASSERT(sizeof(lum.lmm_objects[0]) ==
734 sizeof(lump->lmm_objects[0]));
735 rc = copy_from_user(&lum, lump, sizeof(lum));
739 if (inode->i_sb->s_root == file->f_dentry)
742 rc = ll_dir_setstripe(inode, &lum, set_default);
746 case LL_IOC_OBD_STATFS:
747 RETURN(ll_obd_statfs(inode, (void *)arg));
748 case LL_IOC_LOV_GETSTRIPE:
749 case LL_IOC_MDC_GETINFO:
750 case IOC_MDC_GETFILEINFO:
751 case IOC_MDC_GETFILESTRIPE: {
752 struct ptlrpc_request *request = NULL;
753 struct lov_user_md *lump;
754 struct lov_mds_md *lmm = NULL;
755 struct mdt_body *body;
756 char *filename = NULL;
759 if (cmd == IOC_MDC_GETFILEINFO ||
760 cmd == IOC_MDC_GETFILESTRIPE) {
761 filename = getname((const char *)arg);
762 if (IS_ERR(filename))
763 RETURN(PTR_ERR(filename));
765 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
768 rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
772 body = req_capsule_server_get(&request->rq_pill,
774 LASSERT(body != NULL);
780 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
781 cmd == LL_IOC_MDC_GETINFO))
782 GOTO(skip_lmm, rc = 0);
787 if (cmd == IOC_MDC_GETFILESTRIPE ||
788 cmd == LL_IOC_LOV_GETSTRIPE) {
789 lump = (struct lov_user_md *)arg;
791 struct lov_user_mds_data *lmdp;
792 lmdp = (struct lov_user_mds_data *)arg;
793 lump = &lmdp->lmd_lmm;
795 rc = copy_to_user(lump, lmm, lmmsize);
797 GOTO(out_lmm, rc = -EFAULT);
799 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
800 struct lov_user_mds_data *lmdp;
803 st.st_dev = inode->i_sb->s_dev;
804 st.st_mode = body->mode;
805 st.st_nlink = body->nlink;
806 st.st_uid = body->uid;
807 st.st_gid = body->gid;
808 st.st_rdev = body->rdev;
809 st.st_size = body->size;
810 st.st_blksize = CFS_PAGE_SIZE;
811 st.st_blocks = body->blocks;
812 st.st_atime = body->atime;
813 st.st_mtime = body->mtime;
814 st.st_ctime = body->ctime;
815 st.st_ino = inode->i_ino;
817 lmdp = (struct lov_user_mds_data *)arg;
818 rc = copy_to_user(&lmdp->lmd_st, &st, sizeof(st));
820 GOTO(out_lmm, rc = -EFAULT);
825 if (lmm && lmm->lmm_magic == LOV_MAGIC_JOIN)
826 OBD_FREE(lmm, lmmsize);
828 ptlrpc_req_finished(request);
833 case IOC_LOV_GETINFO: {
834 struct lov_user_mds_data *lumd;
835 struct lov_stripe_md *lsm;
836 struct lov_user_md *lum;
837 struct lov_mds_md *lmm;
842 lumd = (struct lov_user_mds_data *)arg;
843 lum = &lumd->lmd_lmm;
845 rc = ll_get_max_mdsize(sbi, &lmmsize);
849 OBD_ALLOC(lmm, lmmsize);
850 rc = copy_from_user(lmm, lum, lmmsize);
852 GOTO(free_lmm, rc = -EFAULT);
854 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
856 GOTO(free_lmm, rc = -ENOMEM);
858 rc = obd_checkmd(sbi->ll_dt_exp, sbi->ll_md_exp, lsm);
862 /* Perform glimpse_size operation. */
863 memset(&st, 0, sizeof(st));
865 rc = ll_glimpse_ioctl(sbi, lsm, &st);
869 rc = copy_to_user(&lumd->lmd_st, &st, sizeof(st));
871 GOTO(free_lsm, rc = -EFAULT);
875 obd_free_memmd(sbi->ll_dt_exp, &lsm);
877 OBD_FREE(lmm, lmmsize);
880 case OBD_IOC_LLOG_CATINFO: {
881 struct ptlrpc_request *req = NULL;
887 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
892 if (!data->ioc_inlbuf1) {
893 obd_ioctl_freedata(buf, len);
897 req = ptlrpc_request_alloc(sbi2mdc(sbi)->cl_import,
900 GOTO(out_catinfo, rc = -ENOMEM);
902 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
904 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_CLIENT,
907 rc = ptlrpc_request_pack(req, LUSTRE_LOG_VERSION, LLOG_CATINFO);
909 ptlrpc_request_free(req);
910 GOTO(out_catinfo, rc);
913 str = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
914 memcpy(str, data->ioc_inlbuf1, data->ioc_inllen1);
915 if (data->ioc_inllen2) {
916 str = req_capsule_client_get(&req->rq_pill,
918 memcpy(str, data->ioc_inlbuf2, data->ioc_inllen2);
921 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_SERVER,
923 ptlrpc_request_set_replen(req);
925 rc = ptlrpc_queue_wait(req);
927 str = req_capsule_server_get(&req->rq_pill,
929 rc = copy_to_user(data->ioc_pbuf1, str, data->ioc_plen1);
931 ptlrpc_req_finished(req);
933 obd_ioctl_freedata(buf, len);
936 case OBD_IOC_QUOTACHECK: {
937 struct obd_quotactl *oqctl;
940 if (!capable(CAP_SYS_ADMIN))
943 OBD_ALLOC_PTR(oqctl);
946 oqctl->qc_type = arg;
947 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
949 CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
953 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
955 CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
960 case OBD_IOC_POLL_QUOTACHECK: {
961 struct if_quotacheck *check;
964 if (!capable(CAP_SYS_ADMIN))
967 OBD_ALLOC_PTR(check);
971 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
974 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
975 if (copy_to_user((void *)arg, check, sizeof(*check)))
980 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
983 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
984 if (copy_to_user((void *)arg, check, sizeof(*check)))
992 #ifdef HAVE_QUOTA_SUPPORT
993 case OBD_IOC_QUOTACTL: {
994 struct if_quotactl *qctl;
995 struct obd_quotactl *oqctl;
997 int cmd, type, id, rc = 0;
1003 OBD_ALLOC_PTR(oqctl);
1008 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
1009 GOTO(out_quotactl, rc = -EFAULT);
1012 type = qctl->qc_type;
1019 if (!capable(CAP_SYS_ADMIN))
1020 GOTO(out_quotactl, rc = -EPERM);
1023 if (((type == USRQUOTA && current->euid != id) ||
1024 (type == GRPQUOTA && !in_egroup_p(id))) &&
1025 !capable(CAP_SYS_ADMIN))
1026 GOTO(out_quotactl, rc = -EPERM);
1028 /* XXX: dqb_valid is borrowed as a flag to mark that
1029 * only mds quota is wanted */
1030 if (qctl->qc_dqblk.dqb_valid)
1031 qctl->obd_uuid = sbi->ll_md_exp->exp_obd->
1032 u.cli.cl_target_uuid;
1037 CERROR("unsupported quotactl op: %#x\n", cmd);
1038 GOTO(out_quotactl, rc = -ENOTTY);
1041 QCTL_COPY(oqctl, qctl);
1043 if (qctl->obd_uuid.uuid[0]) {
1044 struct obd_device *obd;
1045 struct obd_uuid *uuid = &qctl->obd_uuid;
1047 obd = class_find_client_notype(uuid,
1048 &sbi->ll_dt_exp->exp_obd->obd_uuid);
1050 GOTO(out_quotactl, rc = -ENOENT);
1052 if (cmd == Q_GETINFO)
1053 oqctl->qc_cmd = Q_GETOINFO;
1054 else if (cmd == Q_GETQUOTA)
1055 oqctl->qc_cmd = Q_GETOQUOTA;
1057 GOTO(out_quotactl, rc = -EINVAL);
1059 if (sbi->ll_md_exp->exp_obd == obd) {
1060 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1063 struct obd_export *exp;
1064 struct lov_obd *lov = &sbi->ll_dt_exp->
1067 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1068 if (!lov->lov_tgts[i] ||
1069 !lov->lov_tgts[i]->ltd_active)
1071 exp = lov->lov_tgts[i]->ltd_exp;
1072 if (exp->exp_obd == obd) {
1073 rc = obd_quotactl(exp, oqctl);
1079 oqctl->qc_cmd = cmd;
1080 QCTL_COPY(qctl, oqctl);
1082 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1085 GOTO(out_quotactl, rc);
1088 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1089 if (rc && rc != -EBUSY && cmd == Q_QUOTAON) {
1090 oqctl->qc_cmd = Q_QUOTAOFF;
1091 obd_quotactl(sbi->ll_md_exp, oqctl);
1094 QCTL_COPY(qctl, oqctl);
1096 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1100 OBD_FREE_PTR(oqctl);
1103 #endif /* HAVE_QUOTA_SUPPORT */
1104 case OBD_IOC_GETNAME: {
1105 struct obd_device *obd = class_exp2obd(sbi->ll_dt_exp);
1108 if (copy_to_user((void *)arg, obd->obd_name,
1109 strlen(obd->obd_name) + 1))
1113 case LL_IOC_FLUSHCTX:
1114 RETURN(ll_flush_ctx(inode));
1115 #ifdef CONFIG_FS_POSIX_ACL
1116 case LL_IOC_RMTACL: {
1117 if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
1118 inode == inode->i_sb->s_root->d_inode) {
1119 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1122 LASSERT(fd != NULL);
1123 rc = rct_add(&sbi->ll_rct, cfs_curproc_pid(), arg);
1125 fd->fd_flags |= LL_FILE_RMTACL;
1132 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp,0,NULL,(void *)arg));
1136 int ll_dir_open(struct inode *inode, struct file *file)
1139 RETURN(ll_file_open(inode, file));
1142 int ll_dir_release(struct inode *inode, struct file *file)
1145 RETURN(ll_file_release(inode, file));
1148 struct file_operations ll_dir_operations = {
1149 .open = ll_dir_open,
1150 .release = ll_dir_release,
1151 .read = generic_read_dir,
1152 .readdir = ll_readdir,
1153 .ioctl = ll_dir_ioctl