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 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
37 # include <linux/locks.h> // for wait_on_buffer
39 # include <linux/buffer_head.h> // for wait_on_buffer
42 #define DEBUG_SUBSYSTEM S_LLITE
44 #include <obd_support.h>
45 #include <obd_class.h>
46 #include <lustre_lib.h>
47 #include <lustre/lustre_idl.h>
48 #include <lustre_lite.h>
49 #include <lustre_dlm.h>
50 #include <lustre_fid.h>
51 #include "llite_internal.h"
53 #ifdef HAVE_PG_FS_MISC
54 #define PageChecked(page) test_bit(PG_fs_misc, &(page)->flags)
55 #define SetPageChecked(page) set_bit(PG_fs_misc, &(page)->flags)
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 static __u32 hash_x_index(__u32 value)
138 return ((__u32)~0) - value;
140 #ifdef HAVE_PG_FS_MISC
141 #define PageChecked(page) test_bit(PG_fs_misc, &(page)->flags)
142 #define SetPageChecked(page) set_bit(PG_fs_misc, &(page)->flags)
145 /* returns the page unlocked, but with a reference */
146 static int ll_dir_readpage(struct file *file, struct page *page)
148 struct inode *inode = page->mapping->host;
149 struct ptlrpc_request *request;
150 struct mdt_body *body;
156 hash = hash_x_index(page->index);
157 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) off %lu\n",
158 inode->i_ino, inode->i_generation, inode, (unsigned long)hash);
160 oc = ll_mdscapa_get(inode);
161 rc = md_readpage(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode),
162 oc, hash, page, &request);
165 body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF,
167 /* Checked by mdc_readpage() */
168 LASSERT(body != NULL);
170 /* Swabbed by mdc_readpage() */
171 LASSERT_REPSWABBED(request, REPLY_REC_OFF);
173 if (body->valid & OBD_MD_FLSIZE)
174 inode->i_size = body->size;
175 SetPageUptodate(page);
177 ptlrpc_req_finished(request);
184 struct address_space_operations ll_dir_aops = {
185 .readpage = ll_dir_readpage,
188 static inline unsigned long dir_pages(struct inode *inode)
190 return (inode->i_size + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
193 static inline unsigned ll_chunk_size(struct inode *inode)
195 return inode->i_sb->s_blocksize;
198 static void ll_check_page(struct inode *dir, struct page *page)
200 /* XXX: check page format later */
201 SetPageChecked(page);
204 static inline void ll_put_page(struct page *page)
207 page_cache_release(page);
211 * Find, kmap and return page that contains given hash.
213 static struct page *ll_dir_page_locate(struct inode *dir, unsigned long hash,
214 __u32 *start, __u32 *end)
216 struct address_space *mapping = dir->i_mapping;
218 * Complement of hash is used as an index so that
219 * radix_tree_gang_lookup() can be used to find a page with starting
220 * hash _smaller_ than one we are looking for.
222 unsigned long offset = hash_x_index(hash);
226 spin_lock_irq(&mapping->tree_lock);
227 found = radix_tree_gang_lookup(&mapping->page_tree,
228 (void **)&page, offset, 1);
230 struct lu_dirpage *dp;
232 page_cache_get(page);
233 spin_unlock_irq(&mapping->tree_lock);
235 * In contrast to find_lock_page() we are sure that directory
236 * page cannot be truncated (while DLM lock is held) and,
237 * hence, can avoid restart.
239 * In fact, page cannot be locked here at all, because
240 * ll_dir_readpage() does synchronous io.
243 if (PageUptodate(page)) {
245 *start = le32_to_cpu(dp->ldp_hash_start);
246 *end = le32_to_cpu(dp->ldp_hash_end);
247 LASSERT(*start <= hash);
248 if (hash > *end || (*end != *start && hash == *end)) {
251 ll_truncate_complete_page(page);
253 page_cache_release(page);
257 page_cache_release(page);
258 page = ERR_PTR(-EIO);
262 spin_unlock_irq(&mapping->tree_lock);
269 * Chain of hash overflow pages.
271 struct ll_dir_chain {
272 /* XXX something. Later */
275 static void ll_dir_chain_init(struct ll_dir_chain *chain)
279 static void ll_dir_chain_fini(struct ll_dir_chain *chain)
283 static struct page *ll_get_dir_page(struct inode *dir, __u32 hash, int exact,
284 struct ll_dir_chain *chain)
286 ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_UPDATE} };
287 struct address_space *mapping = dir->i_mapping;
288 struct lustre_handle lockh;
289 struct lu_dirpage *dp;
297 rc = md_lock_match(ll_i2sbi(dir)->ll_md_exp, LDLM_FL_BLOCK_GRANTED,
298 ll_inode2fid(dir), LDLM_IBITS, &policy, mode, &lockh);
300 struct lookup_intent it = { .it_op = IT_READDIR };
301 struct ptlrpc_request *request;
302 struct md_op_data *op_data;
304 op_data = ll_prep_md_op_data(NULL, dir, NULL, NULL, 0, 0,
305 LUSTRE_OPC_ANY, NULL);
307 return (void *)op_data;
309 rc = md_enqueue(ll_i2sbi(dir)->ll_md_exp, LDLM_IBITS, &it,
310 mode, op_data, &lockh, NULL, 0,
311 ldlm_completion_ast, ll_md_blocking_ast, dir,
314 ll_finish_md_op_data(op_data);
316 request = (struct ptlrpc_request *)it.d.lustre.it_data;
318 ptlrpc_req_finished(request);
320 CERROR("lock enqueue: rc: %d\n", rc);
324 /* for cross-ref object, l_ast_data of the lock may not be set,
325 * we reset it here */
326 md_set_lock_data(ll_i2sbi(dir)->ll_md_exp, &lockh.cookie, dir);
328 ldlm_lock_dump_handle(D_OTHER, &lockh);
330 page = ll_dir_page_locate(dir, hash, &start, &end);
332 GOTO(out_unlock, page);
336 * XXX nikita: not entirely correct handling of a corner case:
337 * suppose hash chain of entries with hash value HASH crosses
338 * border between pages P0 and P1. First both P0 and P1 are
339 * cached, seekdir() is called for some entry from the P0 part
340 * of the chain. Later P0 goes out of cache. telldir(HASH)
341 * happens and finds P1, as it starts with matching hash
342 * value. Remaining entries from P0 part of the chain are
343 * skipped. (Is that really a bug?)
345 * Possible solutions: 0. don't cache P1 is such case, handle
346 * it as an "overflow" page. 1. invalidate all pages at
347 * once. 2. use HASH|1 as an index for P1.
349 if (exact && hash != start) {
351 * readdir asked for a page starting _exactly_ from
352 * given hash, but cache contains stale page, with
353 * entries with smaller hash values. Stale page should
354 * be invalidated, and new one fetched.
356 CWARN("Stale readpage page %p: %#lx != %#lx\n", page,
357 (unsigned long)hash, (unsigned long)start);
359 ll_truncate_complete_page(page);
361 page_cache_release(page);
363 GOTO(hash_collision, page);
366 page = read_cache_page(mapping, hash_x_index(hash),
367 (filler_t*)mapping->a_ops->readpage, NULL);
369 GOTO(out_unlock, page);
373 if (!PageUptodate(page))
375 if (!PageChecked(page))
376 ll_check_page(dir, page);
380 dp = page_address(page);
382 start = le32_to_cpu(dp->ldp_hash_start);
383 end = le32_to_cpu(dp->ldp_hash_end);
385 LASSERT(start == hash);
386 CWARN("Page-wide hash collision: %#lx\n", (unsigned long)end);
388 * Fetch whole overflow chain...
395 ldlm_lock_decref(&lockh, mode);
400 page = ERR_PTR(-EIO);
404 int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
406 struct inode *inode = filp->f_dentry->d_inode;
407 struct ll_inode_info *info = ll_i2info(inode);
408 struct ll_sb_info *sbi = ll_i2sbi(inode);
409 __u32 pos = filp->f_pos;
411 struct ll_dir_chain chain;
417 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %lu/%llu\n",
418 inode->i_ino, inode->i_generation, inode,
419 (unsigned long)pos, inode->i_size);
421 if (pos == DIR_END_OFF)
430 ll_dir_chain_init(&chain);
432 page = ll_get_dir_page(inode, pos, 0, &chain);
434 while (rc == 0 && !done) {
435 struct lu_dirpage *dp;
436 struct lu_dirent *ent;
440 * If page is empty (end of directoryis reached),
443 __u32 hash = DIR_END_OFF;
446 dp = page_address(page);
447 for (ent = lu_dirent_start(dp); ent != NULL && !done;
448 ent = lu_dirent_next(ent)) {
455 * XXX: implement correct swabbing here.
458 hash = le32_to_cpu(ent->lde_hash);
459 namelen = le16_to_cpu(ent->lde_namelen);
463 * Skip until we find target hash
475 name = ent->lde_name;
476 fid_le_to_cpu(&fid, &fid);
477 ino = ll_fid_build_ino(sbi, &fid);
479 done = filldir(cookie, name, namelen,
480 (loff_t)hash, ino, DT_UNKNOWN);
482 next = le32_to_cpu(dp->ldp_hash_end);
486 if (pos == DIR_END_OFF)
488 * End of directory reached.
491 else if (1 /* chain is exhausted*/)
493 * Normal case: continue to the next
496 page = ll_get_dir_page(inode, pos, 1,
500 * go into overflow page.
507 CERROR("error reading dir "DFID" at %lu: rc %d\n",
508 PFID(&info->lli_fid), (unsigned long)pos, rc);
512 filp->f_pos = (loff_t)(__s32)pos;
513 filp->f_version = inode->i_version;
514 touch_atime(filp->f_vfsmnt, filp->f_dentry);
516 ll_dir_chain_fini(&chain);
521 #define QCTL_COPY(out, in) \
523 Q_COPY(out, in, qc_cmd); \
524 Q_COPY(out, in, qc_type); \
525 Q_COPY(out, in, qc_id); \
526 Q_COPY(out, in, qc_stat); \
527 Q_COPY(out, in, qc_dqinfo); \
528 Q_COPY(out, in, qc_dqblk); \
531 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump)
533 struct ll_sb_info *sbi = ll_i2sbi(inode);
534 struct md_op_data *op_data;
535 struct ptlrpc_request *req = NULL;
539 * This is coming from userspace, so should be in
540 * local endian. But the MDS would like it in little
541 * endian, so we swab it before we send it.
543 if (lump->lmm_magic != LOV_USER_MAGIC)
546 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC))
547 lustre_swab_lov_user_md(lump);
549 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
550 LUSTRE_OPC_ANY, NULL);
552 RETURN(PTR_ERR(op_data));
554 /* swabbing is done in lov_setstripe() on server side */
555 rc = md_setattr(sbi->ll_md_exp, op_data, lump, sizeof(*lump),
557 ll_finish_md_op_data(op_data);
558 ptlrpc_req_finished(req);
560 if (rc != -EPERM && rc != -EACCES)
561 CERROR("mdc_setattr fails: rc = %d\n", rc);
567 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
568 int *lmm_size, struct ptlrpc_request **request)
570 struct ll_sb_info *sbi = ll_i2sbi(inode);
571 struct mdt_body *body;
572 struct lov_mds_md *lmm = NULL;
573 struct ptlrpc_request *req = NULL;
577 rc = ll_get_max_mdsize(sbi, &lmmsize);
581 oc = ll_mdscapa_get(inode);
582 rc = md_getattr(sbi->ll_md_exp, ll_inode2fid(inode),
583 oc, OBD_MD_FLEASIZE | OBD_MD_FLDIREA,
587 CDEBUG(D_INFO, "md_getattr failed on inode "
588 "%lu/%u: rc %d\n", inode->i_ino,
589 inode->i_generation, rc);
593 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*body));
594 LASSERT(body != NULL); /* checked by md_getattr_name */
595 /* swabbed by mdc_getattr_name */
596 LASSERT_REPSWABBED(req, REPLY_REC_OFF);
598 lmmsize = body->eadatasize;
600 if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
602 GOTO(out, rc = -ENODATA);
605 lmm = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, lmmsize);
606 LASSERT(lmm != NULL);
607 LASSERT_REPSWABBED(req, REPLY_REC_OFF + 1);
610 * This is coming from the MDS, so is probably in
611 * little endian. We convert it to host endian before
612 * passing it to userspace.
614 if (lmm->lmm_magic == __swab32(LOV_MAGIC)) {
615 lustre_swab_lov_user_md((struct lov_user_md *)lmm);
616 lustre_swab_lov_user_md_objects((struct lov_user_md *)lmm);
625 static int ll_dir_ioctl(struct inode *inode, struct file *file,
626 unsigned int cmd, unsigned long arg)
628 struct ll_sb_info *sbi = ll_i2sbi(inode);
629 struct obd_ioctl_data *data;
632 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), cmd=%#x\n",
633 inode->i_ino, inode->i_generation, inode, cmd);
635 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
636 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
639 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
641 case EXT3_IOC_GETFLAGS:
642 case EXT3_IOC_SETFLAGS:
643 RETURN(ll_iocontrol(inode, file, cmd, arg));
644 case EXT3_IOC_GETVERSION_OLD:
645 case EXT3_IOC_GETVERSION:
646 RETURN(put_user(inode->i_generation, (int *)arg));
647 /* We need to special case any other ioctls we want to handle,
648 * to send them to the MDS/OST as appropriate and to properly
649 * network encode the arg field.
650 case EXT3_IOC_SETVERSION_OLD:
651 case EXT3_IOC_SETVERSION:
653 case IOC_MDC_LOOKUP: {
654 struct ptlrpc_request *request = NULL;
655 int namelen, rc, len = 0;
660 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
665 filename = data->ioc_inlbuf1;
666 namelen = data->ioc_inllen1;
669 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
670 GOTO(out, rc = -EINVAL);
673 oc = ll_mdscapa_get(inode);
674 rc = md_getattr_name(sbi->ll_md_exp, ll_inode2fid(inode), oc,
675 filename, namelen, OBD_MD_FLID, 0,
679 CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
683 ptlrpc_req_finished(request);
687 obd_ioctl_freedata(buf, len);
690 case LL_IOC_LOV_SETSTRIPE: {
691 struct lov_user_md lum, *lump = (struct lov_user_md *)arg;
694 LASSERT(sizeof(lum) == sizeof(*lump));
695 LASSERT(sizeof(lum.lmm_objects[0]) ==
696 sizeof(lump->lmm_objects[0]));
697 rc = copy_from_user(&lum, lump, sizeof(lum));
701 rc = ll_dir_setstripe(inode, &lum);
705 case LL_IOC_OBD_STATFS:
706 RETURN(ll_obd_statfs(inode, (void *)arg));
707 case LL_IOC_LOV_GETSTRIPE:
708 case LL_IOC_MDC_GETINFO:
709 case IOC_MDC_GETFILEINFO:
710 case IOC_MDC_GETFILESTRIPE: {
711 struct ptlrpc_request *request = NULL;
712 struct lov_user_md *lump;
713 struct lov_mds_md *lmm = NULL;
714 struct mdt_body *body;
715 char *filename = NULL;
718 if (cmd == IOC_MDC_GETFILEINFO ||
719 cmd == IOC_MDC_GETFILESTRIPE) {
720 filename = getname((const char *)arg);
721 if (IS_ERR(filename))
722 RETURN(PTR_ERR(filename));
724 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
727 rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
731 body = lustre_msg_buf(request->rq_repmsg,
732 REPLY_REC_OFF, sizeof(*body));
733 LASSERT(body != NULL); /* checked by md_getattr_name */
734 /* swabbed by md_getattr_name */
735 LASSERT_REPSWABBED(request, REPLY_REC_OFF);
741 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
742 cmd == LL_IOC_MDC_GETINFO))
743 GOTO(skip_lmm, rc = 0);
748 if (cmd == IOC_MDC_GETFILESTRIPE ||
749 cmd == LL_IOC_LOV_GETSTRIPE) {
750 lump = (struct lov_user_md *)arg;
752 struct lov_user_mds_data *lmdp;
753 lmdp = (struct lov_user_mds_data *)arg;
754 lump = &lmdp->lmd_lmm;
756 rc = copy_to_user(lump, lmm, lmmsize);
758 GOTO(out_lmm, rc = -EFAULT);
760 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
761 struct lov_user_mds_data *lmdp;
764 st.st_dev = inode->i_sb->s_dev;
765 st.st_mode = body->mode;
766 st.st_nlink = body->nlink;
767 st.st_uid = body->uid;
768 st.st_gid = body->gid;
769 st.st_rdev = body->rdev;
770 st.st_size = body->size;
771 st.st_blksize = CFS_PAGE_SIZE;
772 st.st_blocks = body->blocks;
773 st.st_atime = body->atime;
774 st.st_mtime = body->mtime;
775 st.st_ctime = body->ctime;
776 st.st_ino = inode->i_ino;
778 lmdp = (struct lov_user_mds_data *)arg;
779 rc = copy_to_user(&lmdp->lmd_st, &st, sizeof(st));
781 GOTO(out_lmm, rc = -EFAULT);
786 if (lmm && lmm->lmm_magic == LOV_MAGIC_JOIN)
787 OBD_FREE(lmm, lmmsize);
789 ptlrpc_req_finished(request);
794 case IOC_LOV_GETINFO: {
795 struct lov_user_mds_data *lumd;
796 struct lov_stripe_md *lsm;
797 struct lov_user_md *lum;
798 struct lov_mds_md *lmm;
803 lumd = (struct lov_user_mds_data *)arg;
804 lum = &lumd->lmd_lmm;
806 rc = ll_get_max_mdsize(sbi, &lmmsize);
810 OBD_ALLOC(lmm, lmmsize);
811 rc = copy_from_user(lmm, lum, lmmsize);
813 GOTO(free_lmm, rc = -EFAULT);
815 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
817 GOTO(free_lmm, rc = -ENOMEM);
819 rc = obd_checkmd(sbi->ll_dt_exp, sbi->ll_md_exp, lsm);
823 /* Perform glimpse_size operation. */
824 memset(&st, 0, sizeof(st));
826 rc = ll_glimpse_ioctl(sbi, lsm, &st);
830 rc = copy_to_user(&lumd->lmd_st, &st, sizeof(st));
832 GOTO(free_lsm, rc = -EFAULT);
836 obd_free_memmd(sbi->ll_dt_exp, &lsm);
838 OBD_FREE(lmm, lmmsize);
841 case OBD_IOC_LLOG_CATINFO: {
842 struct ptlrpc_request *req = NULL;
845 char *bufs[3] = { NULL }, *str;
846 int lens[3] = { sizeof(struct ptlrpc_body) };
847 int size[2] = { sizeof(struct ptlrpc_body) };
849 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
854 if (!data->ioc_inlbuf1) {
855 obd_ioctl_freedata(buf, len);
859 lens[REQ_REC_OFF] = data->ioc_inllen1;
860 bufs[REQ_REC_OFF] = data->ioc_inlbuf1;
861 if (data->ioc_inllen2) {
862 lens[REQ_REC_OFF + 1] = data->ioc_inllen2;
863 bufs[REQ_REC_OFF + 1] = data->ioc_inlbuf2;
865 lens[REQ_REC_OFF + 1] = 0;
866 bufs[REQ_REC_OFF + 1] = NULL;
869 req = ptlrpc_prep_req(sbi2mdc(sbi)->cl_import,
870 LUSTRE_LOG_VERSION, LLOG_CATINFO, 3, lens,
873 GOTO(out_catinfo, rc = -ENOMEM);
875 size[REPLY_REC_OFF] = data->ioc_plen1;
876 ptlrpc_req_set_repsize(req, 2, size);
878 rc = ptlrpc_queue_wait(req);
880 str = lustre_msg_string(req->rq_repmsg, REPLY_REC_OFF,
882 rc = copy_to_user(data->ioc_pbuf1, str, data->ioc_plen1);
884 ptlrpc_req_finished(req);
886 obd_ioctl_freedata(buf, len);
889 case OBD_IOC_QUOTACHECK: {
890 struct obd_quotactl *oqctl;
893 if (!capable(CAP_SYS_ADMIN))
896 OBD_ALLOC_PTR(oqctl);
899 oqctl->qc_type = arg;
900 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
902 CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
906 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
908 CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
913 case OBD_IOC_POLL_QUOTACHECK: {
914 struct if_quotacheck *check;
917 if (!capable(CAP_SYS_ADMIN))
920 OBD_ALLOC_PTR(check);
924 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
927 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
928 if (copy_to_user((void *)arg, check, sizeof(*check)))
933 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
936 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
937 if (copy_to_user((void *)arg, check, sizeof(*check)))
945 #ifdef HAVE_QUOTA_SUPPORT
946 case OBD_IOC_QUOTACTL: {
947 struct if_quotactl *qctl;
948 struct obd_quotactl *oqctl;
950 int cmd, type, id, rc = 0;
956 OBD_ALLOC_PTR(oqctl);
961 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
962 GOTO(out_quotactl, rc = -EFAULT);
965 type = qctl->qc_type;
972 if (!capable(CAP_SYS_ADMIN))
973 GOTO(out_quotactl, rc = -EPERM);
976 if (((type == USRQUOTA && current->euid != id) ||
977 (type == GRPQUOTA && !in_egroup_p(id))) &&
978 !capable(CAP_SYS_ADMIN))
979 GOTO(out_quotactl, rc = -EPERM);
981 /* XXX: dqb_valid is borrowed as a flag to mark that
982 * only mds quota is wanted */
983 if (qctl->qc_dqblk.dqb_valid)
984 qctl->obd_uuid = sbi->ll_md_exp->exp_obd->
985 u.cli.cl_target_uuid;
990 CERROR("unsupported quotactl op: %#x\n", cmd);
991 GOTO(out_quotactl, rc = -ENOTTY);
994 QCTL_COPY(oqctl, qctl);
996 if (qctl->obd_uuid.uuid[0]) {
997 struct obd_device *obd;
998 struct obd_uuid *uuid = &qctl->obd_uuid;
1000 obd = class_find_client_notype(uuid,
1001 &sbi->ll_dt_exp->exp_obd->obd_uuid);
1003 GOTO(out_quotactl, rc = -ENOENT);
1005 if (cmd == Q_GETINFO)
1006 oqctl->qc_cmd = Q_GETOINFO;
1007 else if (cmd == Q_GETQUOTA)
1008 oqctl->qc_cmd = Q_GETOQUOTA;
1010 GOTO(out_quotactl, rc = -EINVAL);
1012 if (sbi->ll_md_exp->exp_obd == obd) {
1013 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1016 struct obd_export *exp;
1017 struct lov_obd *lov = &sbi->ll_dt_exp->
1020 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1021 if (!lov->lov_tgts[i] ||
1022 !lov->lov_tgts[i]->ltd_active)
1024 exp = lov->lov_tgts[i]->ltd_exp;
1025 if (exp->exp_obd == obd) {
1026 rc = obd_quotactl(exp, oqctl);
1032 oqctl->qc_cmd = cmd;
1033 QCTL_COPY(qctl, oqctl);
1035 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1038 GOTO(out_quotactl, rc);
1041 rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1042 if (rc && rc != -EBUSY && cmd == Q_QUOTAON) {
1043 oqctl->qc_cmd = Q_QUOTAOFF;
1044 obd_quotactl(sbi->ll_md_exp, oqctl);
1047 QCTL_COPY(qctl, oqctl);
1049 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1053 OBD_FREE_PTR(oqctl);
1056 #endif /* HAVE_QUOTA_SUPPORT */
1057 case OBD_IOC_GETNAME: {
1058 struct obd_device *obd = class_exp2obd(sbi->ll_dt_exp);
1061 if (copy_to_user((void *)arg, obd->obd_name,
1062 strlen(obd->obd_name) + 1))
1066 case LL_IOC_FLUSHCTX:
1067 RETURN(ll_flush_ctx(inode));
1068 case LL_IOC_GETFACL: {
1069 struct rmtacl_ioctl_data ioc;
1071 if (copy_from_user(&ioc, (void *)arg, sizeof(ioc)))
1074 RETURN(ll_ioctl_getfacl(inode, &ioc));
1076 case LL_IOC_SETFACL: {
1077 struct rmtacl_ioctl_data ioc;
1079 if (copy_from_user(&ioc, (void *)arg, sizeof(ioc)))
1082 RETURN(ll_ioctl_setfacl(inode, &ioc));
1085 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp,0,NULL,(void *)arg));
1089 int ll_dir_open(struct inode *inode, struct file *file)
1092 RETURN(ll_file_open(inode, file));
1095 int ll_dir_release(struct inode *inode, struct file *file)
1098 RETURN(ll_file_release(inode, file));
1101 struct file_operations ll_dir_operations = {
1102 .open = ll_dir_open,
1103 .release = ll_dir_release,
1104 .read = generic_read_dir,
1105 .readdir = ll_readdir,
1106 .ioctl = ll_dir_ioctl