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"
51 * Directory entries are currently in the same format as ext2/ext3, but will
52 * be changed in the future to accomodate FIDs
54 #define LL_DIR_NAME_LEN (255)
56 static const int LL_DIR_PAD = 4;
59 /* number of inode, referenced by this entry */
61 /* total record length, multiple of LL_DIR_PAD */
65 /* file type: regular, directory, device, etc. */
67 /* name. NOT NUL-terminated */
68 char lde_name[LL_DIR_NAME_LEN];
71 static inline unsigned ll_dir_rec_len(unsigned name_len)
73 return (name_len + 8 + LL_DIR_PAD - 1) & ~(LL_DIR_PAD - 1);
76 #ifndef HAVE_PAGE_CHECKED
77 #ifdef HAVE_PG_FS_MISC
78 #define PageChecked(page) test_bit(PG_fs_misc, &(page)->flags)
79 #define SetPageChecked(page) set_bit(PG_fs_misc, &(page)->flags)
81 #error PageChecked or PageFsMisc not defined in kernel
85 /* returns the page unlocked, but with a reference */
86 static int ll_dir_readpage(struct file *file, struct page *page)
88 struct inode *inode = page->mapping->host;
89 struct ll_fid mdc_fid;
91 struct ptlrpc_request *request;
92 struct mds_body *body;
96 offset = (__u64)page->index << CFS_PAGE_SHIFT;
97 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) off "LPU64"\n",
98 inode->i_ino, inode->i_generation, inode, offset);
100 mdc_pack_fid(&mdc_fid, inode->i_ino, inode->i_generation, S_IFDIR);
102 rc = mdc_readpage(ll_i2sbi(inode)->ll_mdc_exp, &mdc_fid,
103 offset, page, &request);
105 body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF,
107 LASSERT(body != NULL); /* checked by mdc_readpage() */
108 /* swabbed by mdc_readpage() */
109 LASSERT(lustre_rep_swabbed(request, REPLY_REC_OFF));
111 if (body->size != i_size_read(inode)) {
112 ll_inode_size_lock(inode, 0);
113 i_size_write(inode, body->size);
114 ll_inode_size_unlock(inode, 0);
117 SetPageUptodate(page);
119 ptlrpc_req_finished(request);
126 struct address_space_operations ll_dir_aops = {
127 .readpage = ll_dir_readpage,
130 static inline unsigned ll_dir_page_mask(struct inode *inode)
132 return ~(inode->i_sb->s_blocksize - 1);
136 * Check consistency of a single entry.
138 static int ll_dir_check_entry(struct inode *dir, struct ll_dir_entry *ent,
139 unsigned offset, unsigned rec_len, pgoff_t index)
144 * Consider adding more checks.
147 if (unlikely(rec_len < ll_dir_rec_len(1)))
148 msg = "entry is too short";
149 else if (unlikely(rec_len & 3))
150 msg = "wrong alignment";
151 else if (unlikely(rec_len < ll_dir_rec_len(ent->lde_name_len)))
152 msg = "rec_len doesn't match name_len";
153 else if (unlikely(((offset + rec_len - 1) ^ offset) &
154 ll_dir_page_mask(dir)))
155 msg = "directory entry across blocks";
158 CERROR("%s: bad entry in directory %lu/%u: %s - "
159 "offset=%lu+%u, inode=%lu, rec_len=%d,"
160 " name_len=%d\n", ll_i2mdcexp(dir)->exp_obd->obd_name,
161 dir->i_ino, dir->i_generation, msg,
162 index << CFS_PAGE_SHIFT,
163 offset, (unsigned long)le32_to_cpu(ent->lde_inode),
164 rec_len, ent->lde_name_len);
168 static inline struct ll_dir_entry *ll_entry_at(void *base, unsigned offset)
170 return (struct ll_dir_entry *)(base + offset);
173 static void ll_dir_check_page(struct inode *dir, struct page *page)
176 unsigned size = dir->i_sb->s_blocksize;
177 char *addr = page_address(page);
182 struct ll_dir_entry *ent;
185 if ((i_size_read(dir) >> CFS_PAGE_SHIFT) == (__u64)page->index) {
189 limit = i_size_read(dir) & ~CFS_PAGE_MASK;
190 if (limit & (size - 1)) {
191 CERROR("%s: dir %lu/%u size %llu doesn't match %u\n",
192 ll_i2mdcexp(dir)->exp_obd->obd_name, dir->i_ino,
193 dir->i_generation, i_size_read(dir), size);
197 * Place dummy forwarding entries to streamline
200 for (off = limit; off < CFS_PAGE_SIZE; off += size) {
201 ent = ll_entry_at(addr, off);
202 ent->lde_rec_len = cpu_to_le16(size);
203 ent->lde_name_len = 0;
208 limit = CFS_PAGE_SIZE;
211 !err && off <= limit - ll_dir_rec_len(1); off += reclen) {
212 ent = ll_entry_at(addr, off);
213 reclen = le16_to_cpu(ent->lde_rec_len);
214 err = ll_dir_check_entry(dir, ent, off, reclen, page->index);
217 if (!err && off != limit) {
218 ent = ll_entry_at(addr, off);
219 CERROR("%s: entry in directory %lu/%u spans the page boundary "
220 "offset="LPU64"+%u, inode=%lu\n",
221 ll_i2mdcexp(dir)->exp_obd->obd_name,
222 dir->i_ino, dir->i_generation,
223 (__u64)page->index << CFS_PAGE_SHIFT,
224 off, (unsigned long)le32_to_cpu(ent->lde_inode));
229 SetPageChecked(page);
232 struct page *ll_get_dir_page(struct inode *dir, unsigned long n)
234 struct ldlm_res_id res_id =
235 { .name = { dir->i_ino, (__u64)dir->i_generation} };
236 struct lustre_handle lockh;
237 struct obd_device *obddev = class_exp2obd(ll_i2sbi(dir)->ll_mdc_exp);
238 struct address_space *mapping = dir->i_mapping;
240 ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_UPDATE} };
243 rc = ldlm_lock_match(obddev->obd_namespace, LDLM_FL_BLOCK_GRANTED,
244 &res_id, LDLM_IBITS, &policy, LCK_CR, &lockh);
246 struct lookup_intent it = { .it_op = IT_READDIR };
247 struct ldlm_enqueue_info einfo = { LDLM_IBITS, LCK_CR,
248 ll_mdc_blocking_ast, ldlm_completion_ast, NULL, dir };
249 struct ptlrpc_request *request;
250 struct mdc_op_data data;
252 ll_prepare_mdc_op_data(&data, dir, NULL, NULL, 0, 0, NULL);
254 rc = mdc_enqueue(ll_i2sbi(dir)->ll_mdc_exp, &einfo, &it,
255 &data, &lockh, NULL, 0, 0);
257 request = (struct ptlrpc_request *)it.d.lustre.it_data;
259 ptlrpc_req_finished(request);
261 CERROR("lock enqueue: rc: %d\n", rc);
265 ldlm_lock_dump_handle(D_OTHER, &lockh);
267 page = read_cache_page(mapping, n,
268 (filler_t*)mapping->a_ops->readpage, NULL);
270 GOTO(out_unlock, page);
274 if (!PageUptodate(page))
276 if (!PageChecked(page))
277 ll_dir_check_page(dir, page);
282 ldlm_lock_decref(&lockh, LCK_CR);
287 page_cache_release(page);
288 page = ERR_PTR(-EIO);
293 * p is at least 6 bytes before the end of page
295 static inline struct ll_dir_entry *ll_dir_next_entry(struct ll_dir_entry *p)
297 return ll_entry_at(p, le16_to_cpu(p->lde_rec_len));
300 static inline unsigned ll_dir_validate_entry(char *base, unsigned offset,
303 struct ll_dir_entry *de = ll_entry_at(base, offset);
304 struct ll_dir_entry *p = ll_entry_at(base, offset & mask);
305 while (p < de && p->lde_rec_len > 0)
306 p = ll_dir_next_entry(p);
307 return (char *)p - base;
311 * File type constants. The same as in ext2 for compatibility.
326 static unsigned char ll_dir_filetype_table[LL_DIR_FT_MAX] = {
327 [LL_DIR_FT_UNKNOWN] = DT_UNKNOWN,
328 [LL_DIR_FT_REG_FILE] = DT_REG,
329 [LL_DIR_FT_DIR] = DT_DIR,
330 [LL_DIR_FT_CHRDEV] = DT_CHR,
331 [LL_DIR_FT_BLKDEV] = DT_BLK,
332 [LL_DIR_FT_FIFO] = DT_FIFO,
333 [LL_DIR_FT_SOCK] = DT_SOCK,
334 [LL_DIR_FT_SYMLINK] = DT_LNK,
338 * Process one page. Returns:
340 * -ve: filldir commands readdir to stop.
341 * +ve: number of entries submitted to filldir.
342 * 0: no live entries on this page.
345 int ll_readdir_page(char *addr, __u64 base, unsigned *offset,
346 filldir_t filldir, void *cookie)
348 struct ll_dir_entry *de;
352 de = ll_entry_at(addr, *offset);
353 end = addr + CFS_PAGE_SIZE - ll_dir_rec_len(1);
354 for (nr = 0 ;(char*)de <= end; de = ll_dir_next_entry(de)) {
355 if (de->lde_inode != 0) {
357 *offset = (char *)de - addr;
358 if (filldir(cookie, de->lde_name, de->lde_name_len,
359 base | *offset, le32_to_cpu(de->lde_inode),
360 ll_dir_filetype_table[de->lde_file_type &
361 (LL_DIR_FT_MAX - 1)]))
368 int ll_readdir(struct file *filp, void *dirent, filldir_t filldir)
370 struct inode *inode = filp->f_dentry->d_inode;
371 loff_t pos = filp->f_pos;
372 unsigned offset = pos & ~CFS_PAGE_MASK;
373 pgoff_t idx = pos >> CFS_PAGE_SHIFT;
374 pgoff_t npages = dir_pages(inode);
375 unsigned chunk_mask = ll_dir_page_mask(inode);
376 int need_revalidate = (filp->f_version != inode->i_version);
378 int done; /* when this becomes negative --- stop iterating */
382 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %llu/%llu\n",
383 inode->i_ino, inode->i_generation, inode,
384 pos, i_size_read(inode));
387 * Checking ->i_size without the lock. Should be harmless, as server
390 if (pos > i_size_read(inode) - ll_dir_rec_len(1))
393 for (done = 0; idx < npages; idx++, offset = 0) {
395 * We can assume that all blocks on this page are filled with
396 * entries, because ll_dir_check_page() placed special dummy
403 CDEBUG(D_EXT2,"read %lu of dir %lu/%u page %lu/%lu "
405 CFS_PAGE_SIZE, inode->i_ino, inode->i_generation,
406 idx, npages, i_size_read(inode));
407 page = ll_get_dir_page(inode, idx);
409 /* size might have been updated by mdc_readpage */
410 npages = dir_pages(inode);
414 CERROR("error reading dir %lu/%u page %lu: rc %d\n",
415 inode->i_ino, inode->i_generation, idx, rc);
419 kaddr = page_address(page);
420 if (need_revalidate) {
422 * File offset was changed by lseek() and possibly
423 * points in the middle of an entry. Re-scan from the
424 * beginning of the chunk.
426 offset = ll_dir_validate_entry(kaddr, offset,
430 done = ll_readdir_page(kaddr, idx << CFS_PAGE_SHIFT,
431 &offset, filldir, dirent);
433 page_cache_release(page);
436 * Some entries were sent to the user space, return
442 * filldir is satisfied.
447 filp->f_pos = (idx << CFS_PAGE_SHIFT) | offset;
448 filp->f_version = inode->i_version;
449 touch_atime(filp->f_vfsmnt, filp->f_dentry);
454 #define QCTL_COPY(out, in) \
456 Q_COPY(out, in, qc_cmd); \
457 Q_COPY(out, in, qc_type); \
458 Q_COPY(out, in, qc_id); \
459 Q_COPY(out, in, qc_stat); \
460 Q_COPY(out, in, qc_dqinfo); \
461 Q_COPY(out, in, qc_dqblk); \
464 int ll_send_mgc_param(struct obd_export *mgc, char *string)
466 struct mgs_send_param *msp;
473 strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN);
474 rc = obd_set_info_async(mgc, strlen(KEY_SET_INFO), KEY_SET_INFO,
475 sizeof(struct mgs_send_param), msp, NULL);
477 CERROR("Failed to set parameter: %d\n", rc);
483 char *ll_get_fsname(struct inode *inode)
485 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
489 OBD_ALLOC(fsname, MGS_PARAM_MAXLEN);
490 len = strlen(lsi->lsi_lmd->lmd_profile);
491 ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
492 if (ptr && (strcmp(ptr, "-client") == 0))
494 strncpy(fsname, lsi->lsi_lmd->lmd_profile, len);
500 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
503 struct ll_sb_info *sbi = ll_i2sbi(inode);
504 struct mdc_op_data data;
505 struct ptlrpc_request *req = NULL;
506 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
507 struct obd_device *mgc = lsi->lsi_mgc;
508 char *fsname = NULL, *param = NULL;
510 struct iattr attr = { 0 };
514 * This is coming from userspace, so should be in
515 * local endian. But the MDS would like it in little
516 * endian, so we swab it before we send it.
518 if (lump->lmm_magic != LOV_USER_MAGIC)
521 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC))
522 lustre_swab_lov_user_md(lump);
524 ll_prepare_mdc_op_data(&data, inode, NULL, NULL, 0, 0, NULL);
526 /* swabbing is done in lov_setstripe() on server side */
527 rc = mdc_setattr(sbi->ll_mdc_exp, &data,
528 &attr, lump, sizeof(*lump), NULL, 0, &req);
530 ptlrpc_req_finished(req);
531 if (rc != -EPERM && rc != -EACCES)
532 CERROR("mdc_setattr fails: rc = %d\n", rc);
535 ptlrpc_req_finished(req);
537 if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
538 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
540 /* Get fsname and assume devname to be -MDT0000. */
541 fsname = ll_get_fsname(inode);
542 /* Set root stripesize */
543 sprintf(param, "%s-MDT0000.lov.stripesize=%u", fsname,
544 lump->lmm_stripe_size);
545 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
549 /* Set root stripecount */
550 sprintf(param, "%s-MDT0000.lov.stripecount=%u", fsname,
551 lump->lmm_stripe_count);
552 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
556 /* Set root stripeoffset */
557 sprintf(param, "%s-MDT0000.lov.stripeoffset=%u", fsname,
558 lump->lmm_stripe_offset);
559 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
564 OBD_FREE(fsname, MGS_PARAM_MAXLEN);
566 OBD_FREE(param, MGS_PARAM_MAXLEN);
571 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
572 int *lmm_size, struct ptlrpc_request **request)
574 struct ll_sb_info *sbi = ll_i2sbi(inode);
576 struct mds_body *body;
577 struct lov_mds_md *lmm = NULL;
578 struct ptlrpc_request *req = NULL;
581 ll_inode2fid(&fid, inode);
583 rc = ll_get_max_mdsize(sbi, &lmmsize);
587 rc = mdc_getattr(sbi->ll_mdc_exp, &fid,
588 OBD_MD_FLEASIZE|OBD_MD_FLDIREA,
591 CDEBUG(D_INFO, "mdc_getattr failed on inode "
592 "%lu/%u: rc %d\n", inode->i_ino,
593 inode->i_generation, rc);
596 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
598 LASSERT(body != NULL); /* checked by mdc_getattr_name */
599 /* swabbed by mdc_getattr_name */
600 LASSERT(lustre_rep_swabbed(req, REPLY_REC_OFF));
602 lmmsize = body->eadatasize;
604 if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
606 GOTO(out, rc = -ENODATA);
609 lmm = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, lmmsize);
610 LASSERT(lmm != NULL);
611 LASSERT(lustre_rep_swabbed(req, REPLY_REC_OFF + 1));
614 * This is coming from the MDS, so is probably in
615 * little endian. We convert it to host endian before
616 * passing it to userspace.
618 if (lmm->lmm_magic == __swab32(LOV_MAGIC)) {
619 lustre_swab_lov_user_md((struct lov_user_md *)lmm);
628 static int ll_dir_ioctl(struct inode *inode, struct file *file,
629 unsigned int cmd, unsigned long arg)
631 struct ll_sb_info *sbi = ll_i2sbi(inode);
632 struct obd_ioctl_data *data;
635 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), cmd=%#x\n",
636 inode->i_ino, inode->i_generation, inode, cmd);
638 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
639 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
642 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
644 case EXT3_IOC_GETFLAGS:
645 case EXT3_IOC_SETFLAGS:
646 RETURN(ll_iocontrol(inode, file, cmd, arg));
647 case EXT3_IOC_GETVERSION_OLD:
648 case EXT3_IOC_GETVERSION:
649 RETURN(put_user(inode->i_generation, (int *)arg));
650 /* We need to special case any other ioctls we want to handle,
651 * to send them to the MDS/OST as appropriate and to properly
652 * network encode the arg field.
653 case EXT3_IOC_SETVERSION_OLD:
654 case EXT3_IOC_SETVERSION:
656 case IOC_MDC_LOOKUP: {
657 struct ptlrpc_request *request = NULL;
661 int namelen, rc, len = 0;
663 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
668 filename = data->ioc_inlbuf1;
669 namelen = data->ioc_inllen1;
672 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
673 GOTO(out, rc = -EINVAL);
676 ll_inode2fid(&fid, inode);
677 rc = mdc_getattr_name(sbi->ll_mdc_exp, &fid, filename, namelen,
678 OBD_MD_FLID, 0, &request);
680 CDEBUG(D_INFO, "mdc_getattr_name: %d\n", rc);
684 ptlrpc_req_finished(request);
688 obd_ioctl_freedata(buf, len);
691 case LL_IOC_LOV_SETSTRIPE: {
692 struct lov_user_md lum, *lump = (struct lov_user_md *)arg;
696 LASSERT(sizeof(lum) == sizeof(*lump));
697 LASSERT(sizeof(lum.lmm_objects[0]) ==
698 sizeof(lump->lmm_objects[0]));
699 rc = copy_from_user(&lum, lump, sizeof(lum));
703 if (inode->i_sb->s_root == file->f_dentry)
706 rc = ll_dir_setstripe(inode, &lum, set_default);
710 case LL_IOC_OBD_STATFS:
711 RETURN(ll_obd_statfs(inode, (void *)arg));
712 case LL_IOC_LOV_GETSTRIPE:
713 case LL_IOC_MDC_GETINFO:
714 case IOC_MDC_GETFILEINFO:
715 case IOC_MDC_GETFILESTRIPE: {
716 struct ptlrpc_request *request = NULL;
717 struct mds_body *body;
718 struct lov_user_md *lump;
719 struct lov_mds_md *lmm = NULL;
720 char *filename = NULL;
723 if (cmd == IOC_MDC_GETFILEINFO ||
724 cmd == IOC_MDC_GETFILESTRIPE) {
725 filename = getname((const char *)arg);
726 if (IS_ERR(filename))
727 RETURN(PTR_ERR(filename));
729 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
732 rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
736 body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF,
738 LASSERT(body != NULL); /* checked by mdc_getattr_name */
739 /* swabbed by mdc_getattr_name */
740 LASSERT(lustre_rep_swabbed(request, REPLY_REC_OFF));
746 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
747 cmd == LL_IOC_MDC_GETINFO))
748 GOTO(skip_lmm, rc = 0);
753 if (cmd == IOC_MDC_GETFILESTRIPE ||
754 cmd == LL_IOC_LOV_GETSTRIPE) {
755 lump = (struct lov_user_md *)arg;
757 struct lov_user_mds_data *lmdp;
758 lmdp = (struct lov_user_mds_data *)arg;
759 lump = &lmdp->lmd_lmm;
761 rc = copy_to_user(lump, lmm, lmmsize);
763 GOTO(out_lmm, rc = -EFAULT);
765 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
766 struct lov_user_mds_data *lmdp;
769 st.st_dev = inode->i_sb->s_dev;
770 st.st_mode = body->mode;
771 st.st_nlink = body->nlink;
772 st.st_uid = body->uid;
773 st.st_gid = body->gid;
774 st.st_rdev = body->rdev;
775 st.st_size = body->size;
776 st.st_blksize = CFS_PAGE_SIZE;
777 st.st_blocks = body->blocks;
778 st.st_atime = body->atime;
779 st.st_mtime = body->mtime;
780 st.st_ctime = body->ctime;
781 st.st_ino = body->ino;
783 lmdp = (struct lov_user_mds_data *)arg;
784 rc = copy_to_user(&lmdp->lmd_st, &st, sizeof(st));
786 GOTO(out_lmm, rc = -EFAULT);
791 if (lmm && lmm->lmm_magic == LOV_MAGIC_JOIN)
792 OBD_FREE(lmm, lmmsize);
794 ptlrpc_req_finished(request);
799 case IOC_LOV_GETINFO: {
800 struct lov_user_mds_data *lumd;
801 struct lov_stripe_md *lsm;
802 struct lov_user_md *lum;
803 struct lov_mds_md *lmm;
808 lumd = (struct lov_user_mds_data *)arg;
809 lum = &lumd->lmd_lmm;
811 rc = ll_get_max_mdsize(sbi, &lmmsize);
815 OBD_ALLOC(lmm, lmmsize);
816 rc = copy_from_user(lmm, lum, lmmsize);
818 GOTO(free_lmm, rc = -EFAULT);
820 rc = obd_unpackmd(sbi->ll_osc_exp, &lsm, lmm, lmmsize);
822 GOTO(free_lmm, rc = -ENOMEM);
824 rc = obd_checkmd(sbi->ll_osc_exp, sbi->ll_mdc_exp, lsm);
828 /* Perform glimpse_size operation. */
829 memset(&st, 0, sizeof(st));
831 rc = ll_glimpse_ioctl(sbi, lsm, &st);
835 rc = copy_to_user(&lumd->lmd_st, &st, sizeof(st));
837 GOTO(free_lsm, rc = -EFAULT);
841 obd_free_memmd(sbi->ll_osc_exp, &lsm);
843 OBD_FREE(lmm, lmmsize);
846 case OBD_IOC_LLOG_CATINFO: {
847 struct ptlrpc_request *req = NULL;
850 char *bufs[3] = { NULL }, *str;
851 int lens[3] = { sizeof(struct ptlrpc_body) };
852 int size[2] = { sizeof(struct ptlrpc_body) };
854 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
859 if (!data->ioc_inlbuf1) {
860 obd_ioctl_freedata(buf, len);
864 lens[REQ_REC_OFF] = data->ioc_inllen1;
865 bufs[REQ_REC_OFF] = data->ioc_inlbuf1;
866 if (data->ioc_inllen2) {
867 lens[REQ_REC_OFF + 1] = data->ioc_inllen2;
868 bufs[REQ_REC_OFF + 1] = data->ioc_inlbuf2;
870 lens[REQ_REC_OFF + 1] = 0;
871 bufs[REQ_REC_OFF + 1] = NULL;
874 req = ptlrpc_prep_req(sbi2mdc(sbi)->cl_import,
875 LUSTRE_LOG_VERSION, LLOG_CATINFO, 3, lens,
878 GOTO(out_catinfo, rc = -ENOMEM);
880 size[REPLY_REC_OFF] = data->ioc_plen1;
881 ptlrpc_req_set_repsize(req, 2, size);
883 rc = ptlrpc_queue_wait(req);
884 str = lustre_msg_string(req->rq_repmsg, REPLY_REC_OFF,
887 rc = copy_to_user(data->ioc_pbuf1, str,data->ioc_plen1);
888 ptlrpc_req_finished(req);
890 obd_ioctl_freedata(buf, len);
893 case OBD_IOC_QUOTACHECK: {
894 struct obd_quotactl *oqctl;
897 if (!capable(CAP_SYS_ADMIN))
900 OBD_ALLOC_PTR(oqctl);
903 oqctl->qc_type = arg;
904 rc = obd_quotacheck(sbi->ll_mdc_exp, oqctl);
906 CDEBUG(D_INFO, "mdc_quotacheck failed: rc %d\n", rc);
910 rc = obd_quotacheck(sbi->ll_osc_exp, oqctl);
912 CDEBUG(D_INFO, "osc_quotacheck failed: rc %d\n", rc);
917 case OBD_IOC_POLL_QUOTACHECK: {
918 struct if_quotacheck *check;
921 if (!capable(CAP_SYS_ADMIN))
924 OBD_ALLOC_PTR(check);
928 rc = obd_iocontrol(cmd, sbi->ll_mdc_exp, 0, (void *)check,
931 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
932 if (copy_to_user((void *)arg, check, sizeof(*check)))
937 rc = obd_iocontrol(cmd, sbi->ll_osc_exp, 0, (void *)check,
940 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
941 if (copy_to_user((void *)arg, check, sizeof(*check)))
949 #ifdef HAVE_QUOTA_SUPPORT
950 case OBD_IOC_QUOTACTL: {
951 struct if_quotactl *qctl;
952 struct obd_quotactl *oqctl;
954 int cmd, type, id, rc = 0;
960 OBD_ALLOC_PTR(oqctl);
965 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
966 GOTO(out_quotactl, rc = -EFAULT);
969 type = qctl->qc_type;
972 case LUSTRE_Q_INVALIDATE:
977 if (!capable(CAP_SYS_ADMIN))
978 GOTO(out_quotactl, rc = -EPERM);
981 if (((type == USRQUOTA && current->euid != id) ||
982 (type == GRPQUOTA && !in_egroup_p(id))) &&
983 !capable(CAP_SYS_ADMIN))
984 GOTO(out_quotactl, rc = -EPERM);
986 /* XXX: dqb_valid is borrowed as a flag to mark that
987 * only mds quota is wanted */
988 if (qctl->qc_dqblk.dqb_valid) {
989 qctl->obd_uuid = sbi->ll_mdc_exp->exp_obd->
990 u.cli.cl_target_uuid;
991 qctl->qc_dqblk.dqb_valid = 0;
998 CERROR("unsupported quotactl op: %#x\n", cmd);
999 GOTO(out_quotactl, -ENOTTY);
1002 QCTL_COPY(oqctl, qctl);
1004 if (qctl->obd_uuid.uuid[0]) {
1005 struct obd_device *obd;
1006 struct obd_uuid *uuid = &qctl->obd_uuid;
1008 obd = class_find_client_notype(uuid,
1009 &sbi->ll_osc_exp->exp_obd->obd_uuid);
1011 GOTO(out_quotactl, rc = -ENOENT);
1013 if (cmd == Q_GETINFO)
1014 oqctl->qc_cmd = Q_GETOINFO;
1015 else if (cmd == Q_GETQUOTA)
1016 oqctl->qc_cmd = Q_GETOQUOTA;
1018 GOTO(out_quotactl, rc = -EINVAL);
1020 if (sbi->ll_mdc_exp->exp_obd == obd) {
1021 rc = obd_quotactl(sbi->ll_mdc_exp, oqctl);
1024 struct obd_export *exp;
1025 struct lov_obd *lov = &sbi->ll_osc_exp->
1028 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
1029 if (!lov->lov_tgts[i] ||
1030 !lov->lov_tgts[i]->ltd_active)
1032 exp = lov->lov_tgts[i]->ltd_exp;
1033 if (exp->exp_obd == obd) {
1034 rc = obd_quotactl(exp, oqctl);
1040 oqctl->qc_cmd = cmd;
1041 QCTL_COPY(qctl, oqctl);
1043 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1046 GOTO(out_quotactl, rc);
1049 rc = obd_quotactl(sbi->ll_mdc_exp, oqctl);
1050 if (rc && rc != -EBUSY && cmd == Q_QUOTAON) {
1051 oqctl->qc_cmd = Q_QUOTAOFF;
1052 obd_quotactl(sbi->ll_mdc_exp, oqctl);
1055 QCTL_COPY(qctl, oqctl);
1057 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1061 OBD_FREE_PTR(oqctl);
1064 #endif /* HAVE_QUOTA_SUPPORT */
1065 case OBD_IOC_GETNAME_OLD:
1066 case OBD_IOC_GETNAME: {
1067 struct obd_device *obd = class_exp2obd(sbi->ll_osc_exp);
1070 if (copy_to_user((void *)arg, obd->obd_name,
1071 strlen(obd->obd_name) + 1))
1076 RETURN(obd_iocontrol(cmd, sbi->ll_osc_exp,0,NULL,(void *)arg));
1080 struct file_operations ll_dir_operations = {
1081 .open = ll_file_open,
1082 .release = ll_file_release,
1083 .read = generic_read_dir,
1084 .readdir = ll_readdir,
1085 .ioctl = ll_dir_ioctl