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/ext2_fs.h>
31 #include <linux/pagemap.h>
33 #include <linux/version.h>
34 #include <linux/smp_lock.h>
35 #include <asm/uaccess.h>
36 #include <linux/buffer_head.h> // for wait_on_buffer
38 #define DEBUG_SUBSYSTEM S_LLITE
40 #include <obd_support.h>
41 #include <obd_class.h>
42 #include <lustre_lib.h>
43 #include <lustre/lustre_idl.h>
44 #include <lustre_lite.h>
45 #include <lustre_dlm.h>
46 #include <lustre_fid.h>
47 #include "llite_internal.h"
49 #ifndef HAVE_PAGE_CHECKED
50 #ifdef HAVE_PG_FS_MISC
51 #define PageChecked(page) test_bit(PG_fs_misc, &(page)->flags)
52 #define SetPageChecked(page) set_bit(PG_fs_misc, &(page)->flags)
54 #error PageChecked or PageFsMisc not defined in kernel
59 * (new) readdir implementation overview.
61 * Original lustre readdir implementation cached exact copy of raw directory
62 * pages on the client. These pages were indexed in client page cache by
63 * logical offset in the directory file. This design, while very simple and
64 * intuitive had some inherent problems:
66 * . it implies that byte offset to the directory entry serves as a
67 * telldir(3)/seekdir(3) cookie, but that offset is not stable: in
68 * ext3/htree directory entries may move due to splits, and more
71 * . it is incompatible with the design of split directories for cmd3,
72 * that assumes that names are distributed across nodes based on their
73 * hash, and so readdir should be done in hash order.
75 * New readdir implementation does readdir in hash order, and uses hash of a
76 * file name as a telldir/seekdir cookie. This led to number of complications:
78 * . hash is not unique, so it cannot be used to index cached directory
79 * pages on the client (note, that it requires a whole pageful of hash
80 * collided entries to cause two pages to have identical hashes);
82 * . hash is not unique, so it cannot, strictly speaking, be used as an
83 * entry cookie. ext3/htree has the same problem and lustre implementation
84 * mimics their solution: seekdir(hash) positions directory at the first
85 * entry with the given hash.
91 * Client caches directory pages using hash of the first entry as an index. As
92 * noted above hash is not unique, so this solution doesn't work as is:
93 * special processing is needed for "page hash chains" (i.e., sequences of
94 * pages filled with entries all having the same hash value).
96 * First, such chains have to be detected. To this end, server returns to the
97 * client the hash of the first entry on the page next to one returned. When
98 * client detects that this hash is the same as hash of the first entry on the
99 * returned page, page hash collision has to be handled. Pages in the
100 * hash chain, except first one, are termed "overflow pages".
102 * Solution to index uniqueness problem is to not cache overflow
103 * pages. Instead, when page hash collision is detected, all overflow pages
104 * from emerging chain are immediately requested from the server and placed in
105 * a special data structure (struct ll_dir_chain). This data structure is used
106 * by ll_readdir() to process entries from overflow pages. When readdir
107 * invocation finishes, overflow pages are discarded. If page hash collision
108 * chain weren't completely processed, next call to readdir will again detect
109 * page hash collision, again read overflow pages in, process next portion of
110 * entries and again discard the pages. This is not as wasteful as it looks,
111 * because, given reasonable hash, page hash collisions are extremely rare.
113 * 1. directory positioning
115 * When seekdir(hash) is called, original
126 * identification of and access to overflow pages
136 /* returns the page unlocked, but with a reference */
137 static int ll_dir_readpage(struct file *file, struct page *page)
139 struct inode *inode = page->mapping->host;
140 struct ptlrpc_request *request;
141 struct mdt_body *body;
147 hash = hash_x_index(page->index);
148 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) off %lu\n",
149 inode->i_ino, inode->i_generation, inode, (unsigned long)hash);
151 oc = ll_mdscapa_get(inode);
152 rc = md_readpage(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode),
153 oc, hash, page, &request);
156 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
157 /* Checked by mdc_readpage() */
158 LASSERT(body != NULL);
160 if (body->valid & OBD_MD_FLSIZE) {
161 ll_inode_size_lock(inode, 0);
162 i_size_write(inode, body->size);
163 ll_inode_size_unlock(inode, 0);
165 SetPageUptodate(page);
167 ptlrpc_req_finished(request);
174 struct address_space_operations ll_dir_aops = {
175 .readpage = ll_dir_readpage,
178 static inline unsigned long dir_pages(struct inode *inode)
180 return (i_size_read(inode) + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
183 static inline unsigned ll_chunk_size(struct inode *inode)
185 return inode->i_sb->s_blocksize;
188 static void ll_check_page(struct inode *dir, struct page *page)
190 /* XXX: check page format later */
191 SetPageChecked(page);
194 static inline void ll_put_page(struct page *page)
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, unsigned long 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(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)) {
241 ll_truncate_complete_page(page);
243 page_cache_release(page);
247 page_cache_release(page);
248 page = ERR_PTR(-EIO);
252 TREE_READ_UNLOCK_IRQ(mapping);
258 static struct page *ll_get_dir_page(struct inode *dir, __u64 hash, int exact,
259 struct ll_dir_chain *chain)
261 ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_UPDATE} };
262 struct address_space *mapping = dir->i_mapping;
263 struct lustre_handle lockh;
264 struct lu_dirpage *dp;
272 rc = md_lock_match(ll_i2sbi(dir)->ll_md_exp, LDLM_FL_BLOCK_GRANTED,
273 ll_inode2fid(dir), LDLM_IBITS, &policy, mode, &lockh);
275 struct ldlm_enqueue_info einfo = { LDLM_IBITS, mode,
276 ll_md_blocking_ast, ldlm_completion_ast, NULL, dir };
277 struct lookup_intent it = { .it_op = IT_READDIR };
278 struct ptlrpc_request *request;
279 struct md_op_data *op_data;
281 op_data = ll_prep_md_op_data(NULL, dir, NULL, NULL, 0, 0,
282 LUSTRE_OPC_ANY, NULL);
284 return (void *)op_data;
286 rc = md_enqueue(ll_i2sbi(dir)->ll_md_exp, &einfo, &it,
287 op_data, &lockh, NULL, 0, 0);
289 ll_finish_md_op_data(op_data);
291 request = (struct ptlrpc_request *)it.d.lustre.it_data;
293 ptlrpc_req_finished(request);
295 CERROR("lock enqueue: rc: %d\n", rc);
299 /* for cross-ref object, l_ast_data of the lock may not be set,
300 * we reset it here */
301 md_set_lock_data(ll_i2sbi(dir)->ll_md_exp, &lockh.cookie, dir);
303 ldlm_lock_dump_handle(D_OTHER, &lockh);
305 page = ll_dir_page_locate(dir, hash, &start, &end);
307 GOTO(out_unlock, page);
311 * XXX nikita: not entirely correct handling of a corner case:
312 * suppose hash chain of entries with hash value HASH crosses
313 * border between pages P0 and P1. First both P0 and P1 are
314 * cached, seekdir() is called for some entry from the P0 part
315 * of the chain. Later P0 goes out of cache. telldir(HASH)
316 * happens and finds P1, as it starts with matching hash
317 * value. Remaining entries from P0 part of the chain are
318 * skipped. (Is that really a bug?)
320 * Possible solutions: 0. don't cache P1 is such case, handle
321 * it as an "overflow" page. 1. invalidate all pages at
322 * once. 2. use HASH|1 as an index for P1.
324 if (exact && hash != start) {
326 * readdir asked for a page starting _exactly_ from
327 * given hash, but cache contains stale page, with
328 * entries with smaller hash values. Stale page should
329 * be invalidated, and new one fetched.
331 CWARN("Stale readpage page %p: %#lx != %#lx\n", page,
332 (unsigned long)hash, (unsigned long)start);
334 ll_truncate_complete_page(page);
336 page_cache_release(page);
338 GOTO(hash_collision, page);
341 page = read_cache_page(mapping, hash_x_index(hash),
342 (filler_t*)mapping->a_ops->readpage, NULL);
344 GOTO(out_unlock, page);
348 if (!PageUptodate(page))
350 if (!PageChecked(page))
351 ll_check_page(dir, page);
355 dp = page_address(page);
357 start = le64_to_cpu(dp->ldp_hash_start);
358 end = le64_to_cpu(dp->ldp_hash_end);
360 LASSERT(start == hash);
361 CWARN("Page-wide hash collision: %#lx\n", (unsigned long)end);
363 * Fetch whole overflow chain...
370 ldlm_lock_decref(&lockh, mode);
375 page = ERR_PTR(-EIO);
379 int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
381 struct inode *inode = filp->f_dentry->d_inode;
382 struct ll_inode_info *info = ll_i2info(inode);
383 struct ll_sb_info *sbi = ll_i2sbi(inode);
384 __u64 pos = filp->f_pos;
386 struct ll_dir_chain chain;
392 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %lu/%llu\n",
393 inode->i_ino, inode->i_generation, inode,
394 (unsigned long)pos, i_size_read(inode));
396 if (pos == DIR_END_OFF)
405 ll_dir_chain_init(&chain);
407 page = ll_get_dir_page(inode, pos, 0, &chain);
409 while (rc == 0 && !done) {
410 struct lu_dirpage *dp;
411 struct lu_dirent *ent;
415 * If page is empty (end of directoryis reached),
418 __u64 hash = DIR_END_OFF;
421 dp = page_address(page);
422 for (ent = lu_dirent_start(dp); ent != NULL && !done;
423 ent = lu_dirent_next(ent)) {
430 * XXX: implement correct swabbing here.
433 hash = le64_to_cpu(ent->lde_hash);
434 namelen = le16_to_cpu(ent->lde_namelen);
438 * Skip until we find target hash
450 name = ent->lde_name;
451 fid_le_to_cpu(&fid, &fid);
452 ino = ll_fid_build_ino(sbi, &fid);
454 done = filldir(cookie, name, namelen,
455 (loff_t)hash, ino, DT_UNKNOWN);
457 next = le64_to_cpu(dp->ldp_hash_end);
461 if (pos == DIR_END_OFF)
463 * End of directory reached.
466 else if (1 /* chain is exhausted*/)
468 * Normal case: continue to the next
471 page = ll_get_dir_page(inode, pos, 1,
475 * go into overflow page.
482 CERROR("error reading dir "DFID" at %lu: rc %d\n",
483 PFID(&info->lli_fid), (unsigned long)pos, rc);
487 filp->f_pos = (loff_t)(__s32)pos;
488 filp->f_version = inode->i_version;
489 touch_atime(filp->f_vfsmnt, filp->f_dentry);
491 ll_dir_chain_fini(&chain);
496 #define QCTL_COPY(out, in) \
498 Q_COPY(out, in, qc_cmd); \
499 Q_COPY(out, in, qc_type); \
500 Q_COPY(out, in, qc_id); \
501 Q_COPY(out, in, qc_stat); \
502 Q_COPY(out, in, qc_dqinfo); \
503 Q_COPY(out, in, qc_dqblk); \
506 int ll_send_mgc_param(struct obd_export *mgc, char *string)
508 struct mgs_send_param *msp;
515 strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN);
516 rc = obd_set_info_async(mgc, strlen(KEY_SET_INFO), KEY_SET_INFO,
517 sizeof(struct mgs_send_param), msp, NULL);
519 CERROR("Failed to set parameter: %d\n", rc);
525 char *ll_get_fsname(struct inode *inode)
527 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
531 OBD_ALLOC(fsname, MGS_PARAM_MAXLEN);
532 len = strlen(lsi->lsi_lmd->lmd_profile);
533 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
534 if (ptr && (strcmp(ptr, "-client") == 0))
536 strncpy(fsname, lsi->lsi_lmd->lmd_profile, len);
542 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
545 struct ll_sb_info *sbi = ll_i2sbi(inode);
546 struct md_op_data *op_data;
547 struct ptlrpc_request *req = NULL;
549 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
550 struct obd_device *mgc = lsi->lsi_mgc;
551 char *fsname = NULL, *param = NULL;
554 * This is coming from userspace, so should be in
555 * local endian. But the MDS would like it in little
556 * endian, so we swab it before we send it.
558 if (lump->lmm_magic != LOV_USER_MAGIC)
561 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC))
562 lustre_swab_lov_user_md(lump);
564 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
565 LUSTRE_OPC_ANY, NULL);
567 RETURN(PTR_ERR(op_data));
569 /* swabbing is done in lov_setstripe() on server side */
570 rc = md_setattr(sbi->ll_md_exp, op_data, lump, sizeof(*lump),
571 NULL, 0, &req, NULL);
572 ll_finish_md_op_data(op_data);
573 ptlrpc_req_finished(req);
575 if (rc != -EPERM && rc != -EACCES)
576 CERROR("mdc_setattr fails: rc = %d\n", rc);
579 if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
580 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
582 /* Get fsname and assume devname to be -MDT0000. */
583 fsname = ll_get_fsname(inode);
584 /* Set root stripesize */
585 sprintf(param, "%s-MDT0000.lov.stripesize=%u", fsname,
586 lump->lmm_stripe_size);
587 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
591 /* Set root stripecount */
592 sprintf(param, "%s-MDT0000.lov.stripecount=%u", fsname,
593 lump->lmm_stripe_count);
594 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
598 /* Set root stripeoffset */
599 sprintf(param, "%s-MDT0000.lov.stripeoffset=%u", fsname,
600 lump->lmm_stripe_offset);
601 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
606 OBD_FREE(fsname, MGS_PARAM_MAXLEN);
608 OBD_FREE(param, MGS_PARAM_MAXLEN);
613 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
614 int *lmm_size, struct ptlrpc_request **request)
616 struct ll_sb_info *sbi = ll_i2sbi(inode);
617 struct mdt_body *body;
618 struct lov_mds_md *lmm = NULL;
619 struct ptlrpc_request *req = NULL;
623 rc = ll_get_max_mdsize(sbi, &lmmsize);
627 oc = ll_mdscapa_get(inode);
628 rc = md_getattr(sbi->ll_md_exp, ll_inode2fid(inode),
629 oc, OBD_MD_FLEASIZE | OBD_MD_FLDIREA,
633 CDEBUG(D_INFO, "md_getattr failed on inode "
634 "%lu/%u: rc %d\n", inode->i_ino,
635 inode->i_generation, rc);
639 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
640 LASSERT(body != NULL);
642 lmmsize = body->eadatasize;
644 if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
646 GOTO(out, rc = -ENODATA);
649 lmm = req_capsule_server_sized_get(&req->rq_pill,
650 &RMF_MDT_MD, lmmsize);
651 LASSERT(lmm != NULL);
654 * This is coming from the MDS, so is probably in
655 * little endian. We convert it to host endian before
656 * passing it to userspace.
658 if (lmm->lmm_magic == __swab32(LOV_MAGIC)) {
659 lustre_swab_lov_user_md((struct lov_user_md *)lmm);
668 static int ll_dir_ioctl(struct inode *inode, struct file *file,
669 unsigned int cmd, unsigned long arg)
671 struct ll_sb_info *sbi = ll_i2sbi(inode);
672 struct obd_ioctl_data *data;
675 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), cmd=%#x\n",
676 inode->i_ino, inode->i_generation, inode, cmd);
678 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
679 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
682 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
684 case EXT3_IOC_GETFLAGS:
685 case EXT3_IOC_SETFLAGS:
686 RETURN(ll_iocontrol(inode, file, cmd, arg));
687 case EXT3_IOC_GETVERSION_OLD:
688 case EXT3_IOC_GETVERSION:
689 RETURN(put_user(inode->i_generation, (int *)arg));
690 /* We need to special case any other ioctls we want to handle,
691 * to send them to the MDS/OST as appropriate and to properly
692 * network encode the arg field.
693 case EXT3_IOC_SETVERSION_OLD:
694 case EXT3_IOC_SETVERSION:
696 case IOC_MDC_LOOKUP: {
697 struct ptlrpc_request *request = NULL;
698 int namelen, rc, len = 0;
703 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
708 filename = data->ioc_inlbuf1;
709 namelen = data->ioc_inllen1;
712 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
713 GOTO(out, rc = -EINVAL);
716 oc = ll_mdscapa_get(inode);
717 rc = md_getattr_name(sbi->ll_md_exp, ll_inode2fid(inode), oc,
718 filename, namelen, OBD_MD_FLID, 0,
719 ll_i2suppgid(inode), &request);
722 CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
726 ptlrpc_req_finished(request);
730 obd_ioctl_freedata(buf, len);
733 case LL_IOC_LOV_SETSTRIPE: {
734 struct lov_user_md lum, *lump = (struct lov_user_md *)arg;
738 LASSERT(sizeof(lum) == sizeof(*lump));
739 LASSERT(sizeof(lum.lmm_objects[0]) ==
740 sizeof(lump->lmm_objects[0]));
741 rc = copy_from_user(&lum, lump, sizeof(lum));
745 if (inode->i_sb->s_root == file->f_dentry)
748 rc = ll_dir_setstripe(inode, &lum, set_default);
752 case LL_IOC_OBD_STATFS:
753 RETURN(ll_obd_statfs(inode, (void *)arg));
754 case LL_IOC_LOV_GETSTRIPE:
755 case LL_IOC_MDC_GETINFO:
756 case IOC_MDC_GETFILEINFO:
757 case IOC_MDC_GETFILESTRIPE: {
758 struct ptlrpc_request *request = NULL;
759 struct lov_user_md *lump;
760 struct lov_mds_md *lmm = NULL;
761 struct mdt_body *body;
762 char *filename = NULL;
765 if (cmd == IOC_MDC_GETFILEINFO ||
766 cmd == IOC_MDC_GETFILESTRIPE) {
767 filename = getname((const char *)arg);
768 if (IS_ERR(filename))
769 RETURN(PTR_ERR(filename));
771 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
774 rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
778 body = req_capsule_server_get(&request->rq_pill,
780 LASSERT(body != NULL);
786 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
787 cmd == LL_IOC_MDC_GETINFO))
788 GOTO(skip_lmm, rc = 0);
793 if (cmd == IOC_MDC_GETFILESTRIPE ||
794 cmd == LL_IOC_LOV_GETSTRIPE) {
795 lump = (struct lov_user_md *)arg;
797 struct lov_user_mds_data *lmdp;
798 lmdp = (struct lov_user_mds_data *)arg;
799 lump = &lmdp->lmd_lmm;
801 rc = copy_to_user(lump, lmm, lmmsize);
803 GOTO(out_lmm, rc = -EFAULT);
805 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
806 struct lov_user_mds_data *lmdp;
809 st.st_dev = inode->i_sb->s_dev;
810 st.st_mode = body->mode;
811 st.st_nlink = body->nlink;
812 st.st_uid = body->uid;
813 st.st_gid = body->gid;
814 st.st_rdev = body->rdev;
815 st.st_size = body->size;
816 st.st_blksize = CFS_PAGE_SIZE;
817 st.st_blocks = body->blocks;
818 st.st_atime = body->atime;
819 st.st_mtime = body->mtime;
820 st.st_ctime = body->ctime;
821 st.st_ino = inode->i_ino;
823 lmdp = (struct lov_user_mds_data *)arg;
824 rc = copy_to_user(&lmdp->lmd_st, &st, sizeof(st));
826 GOTO(out_lmm, rc = -EFAULT);
831 if (lmm && lmm->lmm_magic == LOV_MAGIC_JOIN)
832 OBD_FREE(lmm, lmmsize);
834 ptlrpc_req_finished(request);
839 case IOC_LOV_GETINFO: {
840 struct lov_user_mds_data *lumd;
841 struct lov_stripe_md *lsm;
842 struct lov_user_md *lum;
843 struct lov_mds_md *lmm;
848 lumd = (struct lov_user_mds_data *)arg;
849 lum = &lumd->lmd_lmm;
851 rc = ll_get_max_mdsize(sbi, &lmmsize);
855 OBD_ALLOC(lmm, lmmsize);
856 rc = copy_from_user(lmm, lum, lmmsize);
858 GOTO(free_lmm, rc = -EFAULT);
860 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
862 GOTO(free_lmm, rc = -ENOMEM);
864 rc = obd_checkmd(sbi->ll_dt_exp, sbi->ll_md_exp, lsm);
868 /* Perform glimpse_size operation. */
869 memset(&st, 0, sizeof(st));
871 rc = ll_glimpse_ioctl(sbi, lsm, &st);
875 rc = copy_to_user(&lumd->lmd_st, &st, sizeof(st));
877 GOTO(free_lsm, rc = -EFAULT);
881 obd_free_memmd(sbi->ll_dt_exp, &lsm);
883 OBD_FREE(lmm, lmmsize);
886 case OBD_IOC_LLOG_CATINFO: {
887 struct ptlrpc_request *req = NULL;
893 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
898 if (!data->ioc_inlbuf1) {
899 obd_ioctl_freedata(buf, len);
903 req = ptlrpc_request_alloc(sbi2mdc(sbi)->cl_import,
906 GOTO(out_catinfo, rc = -ENOMEM);
908 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
910 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_CLIENT,
913 rc = ptlrpc_request_pack(req, LUSTRE_LOG_VERSION, LLOG_CATINFO);
915 ptlrpc_request_free(req);
916 GOTO(out_catinfo, rc);
919 str = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
920 memcpy(str, data->ioc_inlbuf1, data->ioc_inllen1);
921 if (data->ioc_inllen2) {
922 str = req_capsule_client_get(&req->rq_pill,
924 memcpy(str, data->ioc_inlbuf2, data->ioc_inllen2);
927 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_SERVER,
929 ptlrpc_request_set_replen(req);
931 rc = ptlrpc_queue_wait(req);
933 str = req_capsule_server_get(&req->rq_pill,
935 rc = copy_to_user(data->ioc_pbuf1, str, data->ioc_plen1);
937 ptlrpc_req_finished(req);
939 obd_ioctl_freedata(buf, len);
942 case OBD_IOC_QUOTACHECK: {
943 struct obd_quotactl *oqctl;
946 if (!capable(CAP_SYS_ADMIN))
949 OBD_ALLOC_PTR(oqctl);
952 oqctl->qc_type = arg;
953 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
955 CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
959 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
961 CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
966 case OBD_IOC_POLL_QUOTACHECK: {
967 struct if_quotacheck *check;
970 if (!capable(CAP_SYS_ADMIN))
973 OBD_ALLOC_PTR(check);
977 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
980 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
981 if (copy_to_user((void *)arg, check, sizeof(*check)))
986 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
989 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
990 if (copy_to_user((void *)arg, check, sizeof(*check)))
998 #ifdef HAVE_QUOTA_SUPPORT
999 case OBD_IOC_QUOTACTL: {
1000 struct if_quotactl *qctl;
1001 struct obd_quotactl *oqctl;
1003 int cmd, type, id, rc = 0;
1005 OBD_ALLOC_PTR(qctl);
1009 OBD_ALLOC_PTR(oqctl);
1014 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
1015 GOTO(out_quotactl, rc = -EFAULT);
1018 type = qctl->qc_type;
1025 if (!capable(CAP_SYS_ADMIN))
1026 GOTO(out_quotactl, rc = -EPERM);
1029 if (((type == USRQUOTA && current->euid != id) ||
1030 (type == GRPQUOTA && !in_egroup_p(id))) &&
1031 !capable(CAP_SYS_ADMIN))
1032 GOTO(out_quotactl, rc = -EPERM);
1034 /* XXX: dqb_valid is borrowed as a flag to mark that
1035 * only mds quota is wanted */
1036 if (qctl->qc_dqblk.dqb_valid)
1037 qctl->obd_uuid = sbi->ll_md_exp->exp_obd->
1038 u.cli.cl_target_uuid;
1043 CERROR("unsupported quotactl op: %#x\n", cmd);
1044 GOTO(out_quotactl, rc = -ENOTTY);
1047 QCTL_COPY(oqctl, qctl);
1049 if (qctl->obd_uuid.uuid[0]) {
1050 struct obd_device *obd;
1051 struct obd_uuid *uuid = &qctl->obd_uuid;
1053 obd = class_find_client_notype(uuid,
1054 &sbi->ll_dt_exp->exp_obd->obd_uuid);
1056 GOTO(out_quotactl, rc = -ENOENT);
1058 if (cmd == Q_GETINFO)
1059 oqctl->qc_cmd = Q_GETOINFO;
1060 else if (cmd == Q_GETQUOTA)
1061 oqctl->qc_cmd = Q_GETOQUOTA;
1063 GOTO(out_quotactl, rc = -EINVAL);
1065 if (sbi->ll_md_exp->exp_obd == obd) {
1066 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1069 struct obd_export *exp;
1070 struct lov_obd *lov = &sbi->ll_dt_exp->
1073 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1074 if (!lov->lov_tgts[i] ||
1075 !lov->lov_tgts[i]->ltd_active)
1077 exp = lov->lov_tgts[i]->ltd_exp;
1078 if (exp->exp_obd == obd) {
1079 rc = obd_quotactl(exp, oqctl);
1085 oqctl->qc_cmd = cmd;
1086 QCTL_COPY(qctl, oqctl);
1088 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1091 GOTO(out_quotactl, rc);
1094 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1095 if (rc && rc != -EBUSY && cmd == Q_QUOTAON) {
1096 oqctl->qc_cmd = Q_QUOTAOFF;
1097 obd_quotactl(sbi->ll_md_exp, oqctl);
1100 QCTL_COPY(qctl, oqctl);
1102 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1106 OBD_FREE_PTR(oqctl);
1109 #endif /* HAVE_QUOTA_SUPPORT */
1110 case OBD_IOC_GETNAME: {
1111 struct obd_device *obd = class_exp2obd(sbi->ll_dt_exp);
1114 if (copy_to_user((void *)arg, obd->obd_name,
1115 strlen(obd->obd_name) + 1))
1119 case LL_IOC_FLUSHCTX:
1120 RETURN(ll_flush_ctx(inode));
1121 #ifdef CONFIG_FS_POSIX_ACL
1122 case LL_IOC_RMTACL: {
1123 if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
1124 inode == inode->i_sb->s_root->d_inode) {
1125 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1128 LASSERT(fd != NULL);
1129 rc = rct_add(&sbi->ll_rct, cfs_curproc_pid(), arg);
1131 fd->fd_flags |= LL_FILE_RMTACL;
1138 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp,0,NULL,(void *)arg));
1142 int ll_dir_open(struct inode *inode, struct file *file)
1145 RETURN(ll_file_open(inode, file));
1148 int ll_dir_release(struct inode *inode, struct file *file)
1151 RETURN(ll_file_release(inode, file));
1154 struct file_operations ll_dir_operations = {
1155 .open = ll_dir_open,
1156 .release = ll_dir_release,
1157 .read = generic_read_dir,
1158 .readdir = ll_readdir,
1159 .ioctl = ll_dir_ioctl