1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Directory code for lustre client.
6 * Copyright (C) 2002--2007 Cluster File Systems, Inc.
8 * This file is part of the Lustre file system, http://www.lustre.org
9 * Lustre is a trademark of Cluster File Systems, Inc.
11 * You may have signed or agreed to another license before downloading
12 * this software. If so, you are bound by the terms and conditions
13 * of that agreement, and the following does not apply to you. See the
14 * LICENSE file included with this distribution for more information.
16 * If you did not agree to a different license, then this copy of Lustre
17 * is open source software; you can redistribute it and/or modify it
18 * under the terms of version 2 of the GNU General Public License as
19 * published by the Free Software Foundation.
21 * In either case, Lustre is distributed in the hope that it will be
22 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
23 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * license text for more details.
29 #include <linux/pagemap.h>
31 #include <linux/version.h>
32 #include <linux/smp_lock.h>
33 #include <asm/uaccess.h>
34 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
35 # include <linux/locks.h> // for wait_on_buffer
37 # include <linux/buffer_head.h> // for wait_on_buffer
40 #define DEBUG_SUBSYSTEM S_LLITE
42 #include <obd_support.h>
43 #include <obd_class.h>
44 #include <lustre_lib.h>
45 #include <lustre/lustre_idl.h>
46 #include <lustre_lite.h>
47 #include <lustre_dlm.h>
48 #include "llite_internal.h"
50 #ifndef HAVE_PAGE_CHECKED
51 #ifdef HAVE_PG_FS_MISC
52 #define PageChecked(page) test_bit(PG_fs_misc, &(page)->flags)
53 #define SetPageChecked(page) set_bit(PG_fs_misc, &(page)->flags)
55 #error PageChecked or PageFsMisc not defined in kernel
59 /* returns the page unlocked, but with a reference */
60 static int ll_dir_readpage(struct file *file, struct page *page)
62 struct inode *inode = page->mapping->host;
63 struct ll_fid mdc_fid;
65 struct ptlrpc_request *request;
66 struct mds_body *body;
70 offset = (__u64)page->index << CFS_PAGE_SHIFT;
71 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) off "LPU64"\n",
72 inode->i_ino, inode->i_generation, inode, offset);
74 mdc_pack_fid(&mdc_fid, inode->i_ino, inode->i_generation, S_IFDIR);
76 rc = mdc_readpage(ll_i2sbi(inode)->ll_mdc_exp, &mdc_fid,
77 offset, page, &request);
79 body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF,
81 LASSERT(body != NULL); /* checked by mdc_readpage() */
82 /* swabbed by mdc_readpage() */
83 LASSERT(lustre_rep_swabbed(request, REPLY_REC_OFF));
85 if (body->size != i_size_read(inode)) {
86 ll_inode_size_lock(inode, 0);
87 i_size_write(inode, body->size);
88 ll_inode_size_unlock(inode, 0);
91 SetPageUptodate(page);
93 ptlrpc_req_finished(request);
100 struct address_space_operations ll_dir_aops = {
101 .readpage = ll_dir_readpage,
104 static inline unsigned ll_dir_page_mask(struct inode *inode)
106 return ~(inode->i_sb->s_blocksize - 1);
110 * Check consistency of a single entry.
112 static int ll_dir_check_entry(struct inode *dir, struct ll_dir_entry *ent,
113 unsigned offset, unsigned rec_len, pgoff_t index)
118 * Consider adding more checks.
121 if (unlikely(rec_len < ll_dir_rec_len(1)))
122 msg = "entry is too short";
123 else if (unlikely(rec_len & 3))
124 msg = "wrong alignment";
125 else if (unlikely(rec_len < ll_dir_rec_len(ent->lde_name_len)))
126 msg = "rec_len doesn't match name_len";
127 else if (unlikely(((offset + rec_len - 1) ^ offset) &
128 ll_dir_page_mask(dir)))
129 msg = "directory entry across blocks";
132 CERROR("%s: bad entry in directory %lu/%u: %s - "
133 "offset=%lu+%u, inode=%lu, rec_len=%d,"
134 " name_len=%d\n", ll_i2mdcexp(dir)->exp_obd->obd_name,
135 dir->i_ino, dir->i_generation, msg,
136 index << CFS_PAGE_SHIFT,
137 offset, (unsigned long)le32_to_cpu(ent->lde_inode),
138 rec_len, ent->lde_name_len);
142 static void ll_dir_check_page(struct inode *dir, struct page *page)
145 unsigned size = dir->i_sb->s_blocksize;
146 char *addr = page_address(page);
151 struct ll_dir_entry *ent;
154 if ((i_size_read(dir) >> CFS_PAGE_SHIFT) == (__u64)page->index) {
158 limit = i_size_read(dir) & ~CFS_PAGE_MASK;
159 if (limit & (size - 1)) {
160 CERROR("%s: dir %lu/%u size %llu doesn't match %u\n",
161 ll_i2mdcexp(dir)->exp_obd->obd_name, dir->i_ino,
162 dir->i_generation, i_size_read(dir), size);
166 * Place dummy forwarding entries to streamline
169 for (off = limit; off < CFS_PAGE_SIZE; off += size) {
170 ent = ll_entry_at(addr, off);
171 ent->lde_rec_len = cpu_to_le16(size);
172 ent->lde_name_len = 0;
177 limit = CFS_PAGE_SIZE;
180 !err && off <= limit - ll_dir_rec_len(1); off += reclen) {
181 ent = ll_entry_at(addr, off);
182 reclen = le16_to_cpu(ent->lde_rec_len);
183 err = ll_dir_check_entry(dir, ent, off, reclen, page->index);
186 if (!err && off != limit) {
187 ent = ll_entry_at(addr, off);
188 CERROR("%s: entry in directory %lu/%u spans the page boundary "
189 "offset="LPU64"+%u, inode=%lu\n",
190 ll_i2mdcexp(dir)->exp_obd->obd_name,
191 dir->i_ino, dir->i_generation,
192 (__u64)page->index << CFS_PAGE_SHIFT,
193 off, (unsigned long)le32_to_cpu(ent->lde_inode));
198 SetPageChecked(page);
201 struct page *ll_get_dir_page(struct inode *dir, unsigned long n)
203 struct ldlm_res_id res_id =
204 { .name = { dir->i_ino, (__u64)dir->i_generation} };
205 struct lustre_handle lockh;
206 struct obd_device *obddev = class_exp2obd(ll_i2sbi(dir)->ll_mdc_exp);
207 struct address_space *mapping = dir->i_mapping;
209 ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_UPDATE} };
212 rc = ldlm_lock_match(obddev->obd_namespace, LDLM_FL_BLOCK_GRANTED,
213 &res_id, LDLM_IBITS, &policy, LCK_CR, &lockh);
215 struct lookup_intent it = { .it_op = IT_READDIR };
216 struct ldlm_enqueue_info einfo = { LDLM_IBITS, LCK_CR,
217 ll_mdc_blocking_ast, ldlm_completion_ast, NULL, dir };
218 struct ptlrpc_request *request;
219 struct mdc_op_data data;
221 ll_prepare_mdc_op_data(&data, dir, NULL, NULL, 0, 0, NULL);
223 rc = mdc_enqueue(ll_i2sbi(dir)->ll_mdc_exp, &einfo, &it,
224 &data, &lockh, NULL, 0, 0);
226 request = (struct ptlrpc_request *)it.d.lustre.it_data;
228 ptlrpc_req_finished(request);
230 CERROR("lock enqueue: rc: %d\n", rc);
234 ldlm_lock_dump_handle(D_OTHER, &lockh);
236 page = read_cache_page(mapping, n,
237 (filler_t*)mapping->a_ops->readpage, NULL);
239 GOTO(out_unlock, page);
243 if (!PageUptodate(page))
245 if (!PageChecked(page))
246 ll_dir_check_page(dir, page);
251 ldlm_lock_decref(&lockh, LCK_CR);
256 page = ERR_PTR(-EIO);
260 static inline unsigned ll_dir_validate_entry(char *base, unsigned offset,
263 struct ll_dir_entry *de = ll_entry_at(base, offset);
264 struct ll_dir_entry *p = ll_entry_at(base, offset & mask);
265 while (p < de && p->lde_rec_len > 0)
266 p = ll_dir_next_entry(p);
267 return (char *)p - base;
271 * File type constants. The same as in ext2 for compatibility.
286 static unsigned char ll_dir_filetype_table[LL_DIR_FT_MAX] = {
287 [LL_DIR_FT_UNKNOWN] = DT_UNKNOWN,
288 [LL_DIR_FT_REG_FILE] = DT_REG,
289 [LL_DIR_FT_DIR] = DT_DIR,
290 [LL_DIR_FT_CHRDEV] = DT_CHR,
291 [LL_DIR_FT_BLKDEV] = DT_BLK,
292 [LL_DIR_FT_FIFO] = DT_FIFO,
293 [LL_DIR_FT_SOCK] = DT_SOCK,
294 [LL_DIR_FT_SYMLINK] = DT_LNK,
298 * Process one page. Returns:
300 * -ve: filldir commands readdir to stop.
301 * +ve: number of entries submitted to filldir.
302 * 0: no live entries on this page.
305 int ll_readdir_page(char *addr, __u64 base, unsigned *offset,
306 filldir_t filldir, void *cookie)
308 struct ll_dir_entry *de;
312 de = ll_entry_at(addr, *offset);
313 end = addr + CFS_PAGE_SIZE - ll_dir_rec_len(1);
314 for (nr = 0 ;(char*)de <= end; de = ll_dir_next_entry(de)) {
315 if (de->lde_inode != 0) {
317 *offset = (char *)de - addr;
318 if (filldir(cookie, de->lde_name, de->lde_name_len,
319 base | *offset, le32_to_cpu(de->lde_inode),
320 ll_dir_filetype_table[de->lde_file_type &
321 (LL_DIR_FT_MAX - 1)]))
328 int ll_readdir(struct file *filp, void *dirent, filldir_t filldir)
330 struct inode *inode = filp->f_dentry->d_inode;
331 loff_t pos = filp->f_pos;
332 unsigned offset = pos & ~CFS_PAGE_MASK;
333 pgoff_t idx = pos >> CFS_PAGE_SHIFT;
334 pgoff_t npages = dir_pages(inode);
335 unsigned chunk_mask = ll_dir_page_mask(inode);
336 int need_revalidate = (filp->f_version != inode->i_version);
338 int done; /* when this becomes negative --- stop iterating */
342 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %llu/%llu\n",
343 inode->i_ino, inode->i_generation, inode,
344 pos, i_size_read(inode));
347 * Checking ->i_size without the lock. Should be harmless, as server
350 if (pos > i_size_read(inode) - ll_dir_rec_len(1))
353 for (done = 0; idx < npages; idx++, offset = 0) {
355 * We can assume that all blocks on this page are filled with
356 * entries, because ll_dir_check_page() placed special dummy
363 CDEBUG(D_EXT2,"read %lu of dir %lu/%u page %lu/%lu "
365 CFS_PAGE_SIZE, inode->i_ino, inode->i_generation,
366 idx, npages, i_size_read(inode));
367 page = ll_get_dir_page(inode, idx);
369 /* size might have been updated by mdc_readpage */
370 npages = dir_pages(inode);
374 CERROR("error reading dir %lu/%u page %lu: rc %d\n",
375 inode->i_ino, inode->i_generation, idx, rc);
379 kaddr = page_address(page);
380 if (need_revalidate) {
382 * File offset was changed by lseek() and possibly
383 * points in the middle of an entry. Re-scan from the
384 * beginning of the chunk.
386 offset = ll_dir_validate_entry(kaddr, offset,
390 done = ll_readdir_page(kaddr, idx << CFS_PAGE_SHIFT,
391 &offset, filldir, dirent);
395 * Some entries were sent to the user space, return
401 * filldir is satisfied.
406 filp->f_pos = (idx << CFS_PAGE_SHIFT) | offset;
407 filp->f_version = inode->i_version;
408 touch_atime(filp->f_vfsmnt, filp->f_dentry);
413 #define QCTL_COPY(out, in) \
415 Q_COPY(out, in, qc_cmd); \
416 Q_COPY(out, in, qc_type); \
417 Q_COPY(out, in, qc_id); \
418 Q_COPY(out, in, qc_stat); \
419 Q_COPY(out, in, qc_dqinfo); \
420 Q_COPY(out, in, qc_dqblk); \
423 int ll_send_mgc_param(struct obd_export *mgc, char *string)
425 struct mgs_send_param *msp;
432 strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN);
433 rc = obd_set_info_async(mgc, strlen(KEY_SET_INFO), KEY_SET_INFO,
434 sizeof(struct mgs_send_param), msp, NULL);
436 CERROR("Failed to set parameter: %d\n", rc);
442 char *ll_get_fsname(struct inode *inode)
444 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
448 OBD_ALLOC(fsname, MGS_PARAM_MAXLEN);
449 len = strlen(lsi->lsi_lmd->lmd_profile);
450 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
451 if (ptr && (strcmp(ptr, "-client") == 0))
453 strncpy(fsname, lsi->lsi_lmd->lmd_profile, len);
459 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
462 struct ll_sb_info *sbi = ll_i2sbi(inode);
463 struct mdc_op_data data;
464 struct ptlrpc_request *req = NULL;
465 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
466 struct obd_device *mgc = lsi->lsi_mgc;
467 char *fsname = NULL, *param = NULL;
469 struct iattr attr = { 0 };
473 * This is coming from userspace, so should be in
474 * local endian. But the MDS would like it in little
475 * endian, so we swab it before we send it.
477 if (lump->lmm_magic != LOV_USER_MAGIC)
480 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC))
481 lustre_swab_lov_user_md(lump);
483 ll_prepare_mdc_op_data(&data, inode, NULL, NULL, 0, 0, NULL);
485 /* swabbing is done in lov_setstripe() on server side */
486 rc = mdc_setattr(sbi->ll_mdc_exp, &data,
487 &attr, lump, sizeof(*lump), NULL, 0, &req);
489 ptlrpc_req_finished(req);
490 if (rc != -EPERM && rc != -EACCES)
491 CERROR("mdc_setattr fails: rc = %d\n", rc);
494 ptlrpc_req_finished(req);
496 if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
497 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
499 /* Get fsname and assume devname to be -MDT0000. */
500 fsname = ll_get_fsname(inode);
501 /* Set root stripesize */
502 sprintf(param, "%s-MDT0000.lov.stripesize=%u", fsname,
503 lump->lmm_stripe_size);
504 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
508 /* Set root stripecount */
509 sprintf(param, "%s-MDT0000.lov.stripecount=%u", fsname,
510 lump->lmm_stripe_count);
511 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
515 /* Set root stripeoffset */
516 sprintf(param, "%s-MDT0000.lov.stripeoffset=%u", fsname,
517 lump->lmm_stripe_offset);
518 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
523 OBD_FREE(fsname, MGS_PARAM_MAXLEN);
525 OBD_FREE(param, MGS_PARAM_MAXLEN);
530 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
531 int *lmm_size, struct ptlrpc_request **request)
533 struct ll_sb_info *sbi = ll_i2sbi(inode);
535 struct mds_body *body;
536 struct lov_mds_md *lmm = NULL;
537 struct ptlrpc_request *req = NULL;
540 ll_inode2fid(&fid, inode);
542 rc = ll_get_max_mdsize(sbi, &lmmsize);
546 rc = mdc_getattr(sbi->ll_mdc_exp, &fid,
547 OBD_MD_FLEASIZE|OBD_MD_FLDIREA,
550 CDEBUG(D_INFO, "mdc_getattr failed on inode "
551 "%lu/%u: rc %d\n", inode->i_ino,
552 inode->i_generation, rc);
555 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
557 LASSERT(body != NULL); /* checked by mdc_getattr_name */
558 /* swabbed by mdc_getattr_name */
559 LASSERT(lustre_rep_swabbed(req, REPLY_REC_OFF));
561 lmmsize = body->eadatasize;
563 if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
565 GOTO(out, rc = -ENODATA);
568 lmm = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, lmmsize);
569 LASSERT(lmm != NULL);
570 LASSERT(lustre_rep_swabbed(req, REPLY_REC_OFF + 1));
573 * This is coming from the MDS, so is probably in
574 * little endian. We convert it to host endian before
575 * passing it to userspace.
577 if ((LOV_MAGIC != cpu_to_le32(LOV_MAGIC)) &&
578 (cpu_to_le32(LOV_MAGIC) == lmm->lmm_magic))
579 lustre_swab_lov_user_md((struct lov_user_md *)lmm);
587 static int ll_dir_ioctl(struct inode *inode, struct file *file,
588 unsigned int cmd, unsigned long arg)
590 struct ll_sb_info *sbi = ll_i2sbi(inode);
591 struct obd_ioctl_data *data;
594 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), cmd=%#x\n",
595 inode->i_ino, inode->i_generation, inode, cmd);
597 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
598 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
601 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
603 case EXT3_IOC_GETFLAGS:
604 case EXT3_IOC_SETFLAGS:
605 RETURN(ll_iocontrol(inode, file, cmd, arg));
606 case EXT3_IOC_GETVERSION_OLD:
607 case EXT3_IOC_GETVERSION:
608 RETURN(put_user(inode->i_generation, (int *)arg));
609 /* We need to special case any other ioctls we want to handle,
610 * to send them to the MDS/OST as appropriate and to properly
611 * network encode the arg field.
612 case EXT3_IOC_SETVERSION_OLD:
613 case EXT3_IOC_SETVERSION:
615 case IOC_MDC_LOOKUP: {
616 struct ptlrpc_request *request = NULL;
620 int namelen, rc, len = 0;
622 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
627 filename = data->ioc_inlbuf1;
628 namelen = data->ioc_inllen1;
631 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
632 GOTO(out, rc = -EINVAL);
635 ll_inode2fid(&fid, inode);
636 rc = mdc_getattr_name(sbi->ll_mdc_exp, &fid, filename, namelen,
637 OBD_MD_FLID, 0, &request);
639 CDEBUG(D_INFO, "mdc_getattr_name: %d\n", rc);
643 ptlrpc_req_finished(request);
647 obd_ioctl_freedata(buf, len);
650 case LL_IOC_LOV_SETSTRIPE: {
651 struct lov_user_md lum, *lump = (struct lov_user_md *)arg;
655 LASSERT(sizeof(lum) == sizeof(*lump));
656 LASSERT(sizeof(lum.lmm_objects[0]) ==
657 sizeof(lump->lmm_objects[0]));
658 rc = copy_from_user(&lum, lump, sizeof(lum));
662 if (inode->i_sb->s_root == file->f_dentry)
665 rc = ll_dir_setstripe(inode, &lum, set_default);
669 case LL_IOC_OBD_STATFS:
670 RETURN(ll_obd_statfs(inode, (void *)arg));
671 case LL_IOC_LOV_GETSTRIPE:
672 case LL_IOC_MDC_GETINFO:
673 case IOC_MDC_GETFILEINFO:
674 case IOC_MDC_GETFILESTRIPE: {
675 struct ptlrpc_request *request = NULL;
676 struct mds_body *body;
677 struct lov_user_md *lump;
678 struct lov_mds_md *lmm = NULL;
679 char *filename = NULL;
682 if (cmd == IOC_MDC_GETFILEINFO ||
683 cmd == IOC_MDC_GETFILESTRIPE) {
684 filename = getname((const char *)arg);
685 if (IS_ERR(filename))
686 RETURN(PTR_ERR(filename));
688 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
691 rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
695 body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF,
697 LASSERT(body != NULL); /* checked by mdc_getattr_name */
698 /* swabbed by mdc_getattr_name */
699 LASSERT(lustre_rep_swabbed(request, REPLY_REC_OFF));
705 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
706 cmd == LL_IOC_MDC_GETINFO))
707 GOTO(skip_lmm, rc = 0);
712 if (cmd == IOC_MDC_GETFILESTRIPE ||
713 cmd == LL_IOC_LOV_GETSTRIPE) {
714 lump = (struct lov_user_md *)arg;
716 struct lov_user_mds_data *lmdp;
717 lmdp = (struct lov_user_mds_data *)arg;
718 lump = &lmdp->lmd_lmm;
720 rc = copy_to_user(lump, lmm, lmmsize);
722 GOTO(out_lmm, rc = -EFAULT);
724 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
725 struct lov_user_mds_data *lmdp;
728 st.st_dev = inode->i_sb->s_dev;
729 st.st_mode = body->mode;
730 st.st_nlink = body->nlink;
731 st.st_uid = body->uid;
732 st.st_gid = body->gid;
733 st.st_rdev = body->rdev;
734 st.st_size = body->size;
735 st.st_blksize = CFS_PAGE_SIZE;
736 st.st_blocks = body->blocks;
737 st.st_atime = body->atime;
738 st.st_mtime = body->mtime;
739 st.st_ctime = body->ctime;
740 st.st_ino = body->ino;
742 lmdp = (struct lov_user_mds_data *)arg;
743 rc = copy_to_user(&lmdp->lmd_st, &st, sizeof(st));
745 GOTO(out_lmm, rc = -EFAULT);
750 if (lmm && lmm->lmm_magic == LOV_MAGIC_JOIN)
751 OBD_FREE(lmm, lmmsize);
753 ptlrpc_req_finished(request);
758 case IOC_LOV_GETINFO: {
759 struct lov_user_mds_data *lumd;
760 struct lov_stripe_md *lsm;
761 struct lov_user_md *lum;
762 struct lov_mds_md *lmm;
767 lumd = (struct lov_user_mds_data *)arg;
768 lum = &lumd->lmd_lmm;
770 rc = ll_get_max_mdsize(sbi, &lmmsize);
774 OBD_ALLOC(lmm, lmmsize);
775 rc = copy_from_user(lmm, lum, lmmsize);
777 GOTO(free_lmm, rc = -EFAULT);
779 if (lmm->lmm_magic != LOV_USER_MAGIC)
780 GOTO(free_lmm, rc = -EINVAL);
782 if (LOV_USER_MAGIC != cpu_to_le32(LOV_USER_MAGIC) &&
783 cpu_to_le32(LOV_USER_MAGIC) == cpu_to_le32(lmm->lmm_magic)) {
784 lustre_swab_lov_user_md_objects((struct lov_user_md *)lmm);
785 lustre_swab_lov_user_md((struct lov_user_md *)lmm);
788 rc = obd_unpackmd(sbi->ll_osc_exp, &lsm, lmm, lmmsize);
790 GOTO(free_lmm, rc = -ENOMEM);
792 rc = obd_checkmd(sbi->ll_osc_exp, sbi->ll_mdc_exp, lsm);
796 /* Perform glimpse_size operation. */
797 memset(&st, 0, sizeof(st));
799 rc = ll_glimpse_ioctl(sbi, lsm, &st);
803 rc = copy_to_user(&lumd->lmd_st, &st, sizeof(st));
805 GOTO(free_lsm, rc = -EFAULT);
809 obd_free_memmd(sbi->ll_osc_exp, &lsm);
811 OBD_FREE(lmm, lmmsize);
814 case OBD_IOC_LLOG_CATINFO: {
815 struct ptlrpc_request *req = NULL;
818 char *bufs[3] = { NULL }, *str;
819 int lens[3] = { sizeof(struct ptlrpc_body) };
820 int size[2] = { sizeof(struct ptlrpc_body) };
822 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
827 if (!data->ioc_inlbuf1) {
828 obd_ioctl_freedata(buf, len);
832 lens[REQ_REC_OFF] = data->ioc_inllen1;
833 bufs[REQ_REC_OFF] = data->ioc_inlbuf1;
834 if (data->ioc_inllen2) {
835 lens[REQ_REC_OFF + 1] = data->ioc_inllen2;
836 bufs[REQ_REC_OFF + 1] = data->ioc_inlbuf2;
838 lens[REQ_REC_OFF + 1] = 0;
839 bufs[REQ_REC_OFF + 1] = NULL;
842 req = ptlrpc_prep_req(sbi2mdc(sbi)->cl_import,
843 LUSTRE_LOG_VERSION, LLOG_CATINFO, 3, lens,
846 GOTO(out_catinfo, rc = -ENOMEM);
848 size[REPLY_REC_OFF] = data->ioc_plen1;
849 ptlrpc_req_set_repsize(req, 2, size);
851 rc = ptlrpc_queue_wait(req);
852 str = lustre_msg_string(req->rq_repmsg, REPLY_REC_OFF,
855 rc = copy_to_user(data->ioc_pbuf1, str,data->ioc_plen1);
856 ptlrpc_req_finished(req);
858 obd_ioctl_freedata(buf, len);
861 case OBD_IOC_QUOTACHECK: {
862 struct obd_quotactl *oqctl;
865 if (!capable(CAP_SYS_ADMIN))
868 OBD_ALLOC_PTR(oqctl);
871 oqctl->qc_type = arg;
872 rc = obd_quotacheck(sbi->ll_mdc_exp, oqctl);
874 CDEBUG(D_INFO, "mdc_quotacheck failed: rc %d\n", rc);
878 rc = obd_quotacheck(sbi->ll_osc_exp, oqctl);
880 CDEBUG(D_INFO, "osc_quotacheck failed: rc %d\n", rc);
885 case OBD_IOC_POLL_QUOTACHECK: {
886 struct if_quotacheck *check;
889 if (!capable(CAP_SYS_ADMIN))
892 OBD_ALLOC_PTR(check);
896 rc = obd_iocontrol(cmd, sbi->ll_mdc_exp, 0, (void *)check,
899 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
900 if (copy_to_user((void *)arg, check, sizeof(*check)))
905 rc = obd_iocontrol(cmd, sbi->ll_osc_exp, 0, (void *)check,
908 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
909 if (copy_to_user((void *)arg, check, sizeof(*check)))
917 #ifdef HAVE_QUOTA_SUPPORT
918 case OBD_IOC_QUOTACTL: {
919 struct if_quotactl *qctl;
920 struct obd_quotactl *oqctl;
922 int cmd, type, id, rc = 0;
928 OBD_ALLOC_PTR(oqctl);
933 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
934 GOTO(out_quotactl, rc = -EFAULT);
937 type = qctl->qc_type;
940 case LUSTRE_Q_INVALIDATE:
945 if (!capable(CAP_SYS_ADMIN))
946 GOTO(out_quotactl, rc = -EPERM);
949 if (((type == USRQUOTA && current->euid != id) ||
950 (type == GRPQUOTA && !in_egroup_p(id))) &&
951 !capable(CAP_SYS_ADMIN))
952 GOTO(out_quotactl, rc = -EPERM);
954 /* XXX: dqb_valid is borrowed as a flag to mark that
955 * only mds quota is wanted */
956 if (qctl->qc_dqblk.dqb_valid) {
957 qctl->obd_uuid = sbi->ll_mdc_exp->exp_obd->
958 u.cli.cl_target_uuid;
959 qctl->qc_dqblk.dqb_valid = 0;
966 CERROR("unsupported quotactl op: %#x\n", cmd);
967 GOTO(out_quotactl, -ENOTTY);
970 QCTL_COPY(oqctl, qctl);
972 if (qctl->obd_uuid.uuid[0]) {
973 struct obd_device *obd;
974 struct obd_uuid *uuid = &qctl->obd_uuid;
976 obd = class_find_client_notype(uuid,
977 &sbi->ll_osc_exp->exp_obd->obd_uuid);
979 GOTO(out_quotactl, rc = -ENOENT);
981 if (cmd == Q_GETINFO)
982 oqctl->qc_cmd = Q_GETOINFO;
983 else if (cmd == Q_GETQUOTA)
984 oqctl->qc_cmd = Q_GETOQUOTA;
986 GOTO(out_quotactl, rc = -EINVAL);
988 if (sbi->ll_mdc_exp->exp_obd == obd) {
989 rc = obd_quotactl(sbi->ll_mdc_exp, oqctl);
992 struct obd_export *exp;
993 struct lov_obd *lov = &sbi->ll_osc_exp->
996 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
997 if (!lov->lov_tgts[i] ||
998 !lov->lov_tgts[i]->ltd_active)
1000 exp = lov->lov_tgts[i]->ltd_exp;
1001 if (exp->exp_obd == obd) {
1002 rc = obd_quotactl(exp, oqctl);
1008 oqctl->qc_cmd = cmd;
1009 QCTL_COPY(qctl, oqctl);
1011 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1014 GOTO(out_quotactl, rc);
1017 rc = obd_quotactl(sbi->ll_mdc_exp, oqctl);
1018 if (rc && rc != -EBUSY && cmd == Q_QUOTAON) {
1019 oqctl->qc_cmd = Q_QUOTAOFF;
1020 obd_quotactl(sbi->ll_mdc_exp, oqctl);
1023 QCTL_COPY(qctl, oqctl);
1025 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1029 OBD_FREE_PTR(oqctl);
1032 #endif /* HAVE_QUOTA_SUPPORT */
1033 case OBD_IOC_GETNAME_OLD:
1034 case OBD_IOC_GETNAME: {
1035 struct obd_device *obd = class_exp2obd(sbi->ll_osc_exp);
1038 if (copy_to_user((void *)arg, obd->obd_name,
1039 strlen(obd->obd_name) + 1))
1044 RETURN(obd_iocontrol(cmd, sbi->ll_osc_exp,0,NULL,(void *)arg));
1048 struct file_operations ll_dir_operations = {
1049 .open = ll_file_open,
1050 .release = ll_file_release,
1051 .read = generic_read_dir,
1052 .readdir = ll_readdir,
1053 .ioctl = ll_dir_ioctl