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 "llite_internal.h"
52 typedef struct ext2_dir_entry_2 ext2_dirent;
54 #ifdef HAVE_PG_FS_MISC
55 #define PageChecked(page) test_bit(PG_fs_misc, &(page)->flags)
56 #define SetPageChecked(page) set_bit(PG_fs_misc, &(page)->flags)
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_REPSWABBED(request, REPLY_REC_OFF);
85 inode->i_size = body->size;
86 SetPageUptodate(page);
88 ptlrpc_req_finished(request);
95 struct address_space_operations ll_dir_aops = {
96 .readpage = ll_dir_readpage,
100 * ext2 uses block-sized chunks. Arguably, sector-sized ones would be
101 * more robust, but we have what we have
103 static inline unsigned ext2_chunk_size(struct inode *inode)
105 return inode->i_sb->s_blocksize;
108 static inline void ext2_put_page(struct page *page)
111 page_cache_release(page);
114 static inline unsigned long dir_pages(struct inode *inode)
116 return (inode->i_size+CFS_PAGE_SIZE-1) >> CFS_PAGE_SHIFT;
120 static void ext2_check_page(struct inode *dir, struct page *page)
122 unsigned chunk_size = ext2_chunk_size(dir);
123 char *kaddr = page_address(page);
124 // u32 max_inumber = le32_to_cpu(sb->u.ext2_sb.s_es->s_inodes_count);
126 __u64 offs, limit = CFS_PAGE_SIZE;
130 if ((dir->i_size >> CFS_PAGE_SHIFT) == (__u64)page->index) {
131 limit = dir->i_size & ~CFS_PAGE_MASK;
132 if (limit & (chunk_size - 1)) {
133 CERROR("limit "LPU64" dir size %lld index "LPU64"\n",
134 limit, dir->i_size, (__u64)page->index);
137 for (offs = limit; offs < CFS_PAGE_SIZE; offs += chunk_size) {
138 ext2_dirent *p = (ext2_dirent*)(kaddr + offs);
139 p->rec_len = cpu_to_le16(chunk_size);
146 for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
147 p = (ext2_dirent *)(kaddr + offs);
148 rec_len = le16_to_cpu(p->rec_len);
150 if (rec_len < EXT2_DIR_REC_LEN(1))
154 if (rec_len < EXT2_DIR_REC_LEN(p->name_len))
156 if (((offs + rec_len - 1) ^ offs) & ~(chunk_size-1))
158 // if (le32_to_cpu(p->inode) > max_inumber)
164 SetPageChecked(page);
167 /* Too bad, we had an error */
170 CERROR("%s: directory %lu/%u size %llu is not a multiple of %u\n",
171 ll_i2mdcexp(dir)->exp_obd->obd_name, dir->i_ino,
172 dir->i_generation, dir->i_size, chunk_size);
175 error = "rec_len is smaller than minimal";
178 error = "unaligned directory entry";
181 error = "rec_len is too small for name_len";
184 error = "directory entry across blocks";
187 // error = "inode out of bounds";
189 CERROR("%s: bad entry in directory %lu/%u: %s - "
190 "offset="LPU64"+"LPU64", inode=%lu, rec_len=%d, name_len=%d\n",
191 ll_i2mdcexp(dir)->exp_obd->obd_name, dir->i_ino,
192 dir->i_generation, error, (__u64)page->index << CFS_PAGE_SHIFT,
193 offs, (unsigned long)le32_to_cpu(p->inode),
194 rec_len, p->name_len);
197 p = (ext2_dirent *)(kaddr + offs);
198 CERROR("%s: entry in directory %lu/%u spans the page boundary "
199 "offset="LPU64"+"LPU64", inode=%lu\n",ll_i2mdcexp(dir)->exp_obd->obd_name,
200 dir->i_ino, dir->i_generation,
201 (__u64)page->index << CFS_PAGE_SHIFT,
202 offs, (unsigned long)le32_to_cpu(p->inode));
204 SetPageChecked(page);
208 static struct page *ll_get_dir_page(struct inode *dir, unsigned long n)
210 struct ldlm_res_id res_id =
211 { .name = { dir->i_ino, (__u64)dir->i_generation} };
212 struct lustre_handle lockh;
213 struct obd_device *obddev = class_exp2obd(ll_i2sbi(dir)->ll_mdc_exp);
214 struct address_space *mapping = dir->i_mapping;
216 ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_UPDATE} };
219 rc = ldlm_lock_match(obddev->obd_namespace, LDLM_FL_BLOCK_GRANTED,
220 &res_id, LDLM_IBITS, &policy, LCK_CR, &lockh);
222 struct lookup_intent it = { .it_op = IT_READDIR };
223 struct ptlrpc_request *request;
224 struct mdc_op_data data;
226 ll_prepare_mdc_op_data(&data, dir, NULL, NULL, 0, 0);
228 rc = mdc_enqueue(ll_i2sbi(dir)->ll_mdc_exp, LDLM_IBITS, &it,
229 LCK_CR, &data, &lockh, NULL, 0,
230 ldlm_completion_ast, ll_mdc_blocking_ast, dir,
233 request = (struct ptlrpc_request *)it.d.lustre.it_data;
235 ptlrpc_req_finished(request);
237 CERROR("lock enqueue: rc: %d\n", rc);
241 ldlm_lock_dump_handle(D_OTHER, &lockh);
243 page = read_cache_page(mapping, n,
244 (filler_t*)mapping->a_ops->readpage, NULL);
246 GOTO(out_unlock, page);
250 if (!PageUptodate(page))
252 if (!PageChecked(page))
253 ext2_check_page(dir, page);
258 ldlm_lock_decref(&lockh, LCK_CR);
263 page = ERR_PTR(-EIO);
268 * p is at least 6 bytes before the end of page
270 static inline ext2_dirent *ext2_next_entry(ext2_dirent *p)
272 return (ext2_dirent *)((char*)p + le16_to_cpu(p->rec_len));
275 static inline unsigned
276 ext2_validate_entry(char *base, unsigned offset, unsigned mask)
278 ext2_dirent *de = (ext2_dirent*)(base + offset);
279 ext2_dirent *p = (ext2_dirent*)(base + (offset&mask));
280 while ((char*)p < (char*)de)
281 p = ext2_next_entry(p);
282 return (char *)p - base;
285 static unsigned char ext2_filetype_table[EXT2_FT_MAX] = {
286 [EXT2_FT_UNKNOWN] DT_UNKNOWN,
287 [EXT2_FT_REG_FILE] DT_REG,
288 [EXT2_FT_DIR] DT_DIR,
289 [EXT2_FT_CHRDEV] DT_CHR,
290 [EXT2_FT_BLKDEV] DT_BLK,
291 [EXT2_FT_FIFO] DT_FIFO,
292 [EXT2_FT_SOCK] DT_SOCK,
293 [EXT2_FT_SYMLINK] DT_LNK,
297 int ll_readdir(struct file *filp, void *dirent, filldir_t filldir)
299 struct inode *inode = filp->f_dentry->d_inode;
300 loff_t pos = filp->f_pos;
301 // XXX struct super_block *sb = inode->i_sb;
302 __u64 offset = pos & ~CFS_PAGE_MASK;
303 __u64 n = pos >> CFS_PAGE_SHIFT;
304 unsigned long npages = dir_pages(inode);
305 unsigned chunk_mask = ~(ext2_chunk_size(inode)-1);
306 unsigned char *types = ext2_filetype_table;
307 int need_revalidate = (filp->f_version != inode->i_version);
311 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %llu/%llu\n",
312 inode->i_ino, inode->i_generation, inode, pos, inode->i_size);
314 if (pos > inode->i_size - EXT2_DIR_REC_LEN(1))
317 for ( ; n < npages; n++, offset = 0) {
322 CDEBUG(D_EXT2,"read %lu of dir %lu/%u page "LPU64"/%lu "
324 CFS_PAGE_SIZE, inode->i_ino, inode->i_generation,
325 n, npages, inode->i_size);
326 page = ll_get_dir_page(inode, n);
328 /* size might have been updated by mdc_readpage */
329 npages = dir_pages(inode);
333 CERROR("error reading dir %lu/%u page "LPU64": rc %d\n",
334 inode->i_ino, inode->i_generation, n, rc);
338 kaddr = page_address(page);
339 if (need_revalidate) {
340 /* page already checked from ll_get_dir_page() */
341 offset = ext2_validate_entry(kaddr, offset, chunk_mask);
344 de = (ext2_dirent *)(kaddr+offset);
345 limit = kaddr + CFS_PAGE_SIZE - EXT2_DIR_REC_LEN(1);
346 for ( ;(char*)de <= limit; de = ext2_next_entry(de)) {
350 rc = 0; /* no error if we return something */
352 offset = (char *)de - kaddr;
353 over = filldir(dirent, de->name, de->name_len,
354 (n << CFS_PAGE_SHIFT) | offset,
355 le32_to_cpu(de->inode),
356 types[de->file_type &
368 filp->f_pos = (n << CFS_PAGE_SHIFT) | offset;
369 filp->f_version = inode->i_version;
370 touch_atime(filp->f_vfsmnt, filp->f_dentry);
375 #define QCTL_COPY(out, in) \
377 Q_COPY(out, in, qc_cmd); \
378 Q_COPY(out, in, qc_type); \
379 Q_COPY(out, in, qc_id); \
380 Q_COPY(out, in, qc_stat); \
381 Q_COPY(out, in, qc_dqinfo); \
382 Q_COPY(out, in, qc_dqblk); \
385 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump)
387 struct ll_sb_info *sbi = ll_i2sbi(inode);
388 struct mdc_op_data data;
389 struct ptlrpc_request *req = NULL;
391 struct iattr attr = { 0 };
395 * This is coming from userspace, so should be in
396 * local endian. But the MDS would like it in little
397 * endian, so we swab it before we send it.
399 if (lump->lmm_magic != LOV_USER_MAGIC)
402 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC))
403 lustre_swab_lov_user_md(lump);
405 ll_prepare_mdc_op_data(&data, inode, NULL, NULL, 0, 0);
407 /* swabbing is done in lov_setstripe() on server side */
408 rc = mdc_setattr(sbi->ll_mdc_exp, &data,
409 &attr, lump, sizeof(*lump), NULL, 0, &req);
411 ptlrpc_req_finished(req);
412 if (rc != -EPERM && rc != -EACCES)
413 CERROR("mdc_setattr fails: rc = %d\n", rc);
416 ptlrpc_req_finished(req);
422 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
423 int *lmm_size, struct ptlrpc_request **request)
425 struct ll_sb_info *sbi = ll_i2sbi(inode);
427 struct mds_body *body;
428 struct lov_mds_md *lmm = NULL;
429 struct ptlrpc_request *req = NULL;
432 ll_inode2fid(&fid, inode);
434 rc = ll_get_max_mdsize(sbi, &lmmsize);
438 rc = mdc_getattr(sbi->ll_mdc_exp, &fid,
439 OBD_MD_FLEASIZE|OBD_MD_FLDIREA,
442 CDEBUG(D_INFO, "mdc_getattr failed on inode "
443 "%lu/%u: rc %d\n", inode->i_ino,
444 inode->i_generation, rc);
447 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
449 LASSERT(body != NULL); /* checked by mdc_getattr_name */
450 /* swabbed by mdc_getattr_name */
451 LASSERT_REPSWABBED(req, REPLY_REC_OFF);
453 lmmsize = body->eadatasize;
455 if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
457 GOTO(out, rc = -ENODATA);
460 lmm = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, lmmsize);
461 LASSERT(lmm != NULL);
462 LASSERT_REPSWABBED(req, REPLY_REC_OFF + 1);
465 * This is coming from the MDS, so is probably in
466 * little endian. We convert it to host endian before
467 * passing it to userspace.
469 if (lmm->lmm_magic == __swab32(LOV_MAGIC)) {
470 lustre_swab_lov_user_md((struct lov_user_md *)lmm);
471 lustre_swab_lov_user_md_objects((struct lov_user_md *)lmm);
480 static int ll_dir_ioctl(struct inode *inode, struct file *file,
481 unsigned int cmd, unsigned long arg)
483 struct ll_sb_info *sbi = ll_i2sbi(inode);
484 struct obd_ioctl_data *data;
487 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), cmd=%#x\n",
488 inode->i_ino, inode->i_generation, inode, cmd);
490 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
491 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
494 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
496 case EXT3_IOC_GETFLAGS:
497 case EXT3_IOC_SETFLAGS:
498 RETURN(ll_iocontrol(inode, file, cmd, arg));
499 case EXT3_IOC_GETVERSION_OLD:
500 case EXT3_IOC_GETVERSION:
501 RETURN(put_user(inode->i_generation, (int *)arg));
502 /* We need to special case any other ioctls we want to handle,
503 * to send them to the MDS/OST as appropriate and to properly
504 * network encode the arg field.
505 case EXT3_IOC_SETVERSION_OLD:
506 case EXT3_IOC_SETVERSION:
508 case IOC_MDC_LOOKUP: {
509 struct ptlrpc_request *request = NULL;
513 int namelen, rc, len = 0;
515 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
520 filename = data->ioc_inlbuf1;
521 namelen = data->ioc_inllen1;
524 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
525 GOTO(out, rc = -EINVAL);
528 ll_inode2fid(&fid, inode);
529 rc = mdc_getattr_name(sbi->ll_mdc_exp, &fid, filename, namelen,
530 OBD_MD_FLID, 0, &request);
532 CDEBUG(D_INFO, "mdc_getattr_name: %d\n", rc);
536 ptlrpc_req_finished(request);
540 obd_ioctl_freedata(buf, len);
543 case LL_IOC_LOV_SETSTRIPE: {
544 struct lov_user_md lum, *lump = (struct lov_user_md *)arg;
547 LASSERT(sizeof(lum) == sizeof(*lump));
548 LASSERT(sizeof(lum.lmm_objects[0]) ==
549 sizeof(lump->lmm_objects[0]));
550 rc = copy_from_user(&lum, lump, sizeof(lum));
554 rc = ll_dir_setstripe(inode, &lum);
558 case LL_IOC_OBD_STATFS:
559 RETURN(ll_obd_statfs(inode, (void *)arg));
560 case LL_IOC_LOV_GETSTRIPE:
561 case LL_IOC_MDC_GETINFO:
562 case IOC_MDC_GETFILEINFO:
563 case IOC_MDC_GETFILESTRIPE: {
564 struct ptlrpc_request *request = NULL;
565 struct mds_body *body;
566 struct lov_user_md *lump;
567 struct lov_mds_md *lmm = NULL;
568 char *filename = NULL;
571 if (cmd == IOC_MDC_GETFILEINFO ||
572 cmd == IOC_MDC_GETFILESTRIPE) {
573 filename = getname((const char *)arg);
574 if (IS_ERR(filename))
575 RETURN(PTR_ERR(filename));
577 rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
580 rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
584 body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF,
586 LASSERT(body != NULL); /* checked by mdc_getattr_name */
587 /* swabbed by mdc_getattr_name */
588 LASSERT_REPSWABBED(request, REPLY_REC_OFF);
594 if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
595 cmd == LL_IOC_MDC_GETINFO))
596 GOTO(skip_lmm, rc = 0);
601 if (cmd == IOC_MDC_GETFILESTRIPE ||
602 cmd == LL_IOC_LOV_GETSTRIPE) {
603 lump = (struct lov_user_md *)arg;
605 struct lov_user_mds_data *lmdp;
606 lmdp = (struct lov_user_mds_data *)arg;
607 lump = &lmdp->lmd_lmm;
609 rc = copy_to_user(lump, lmm, lmmsize);
611 GOTO(out_lmm, rc = -EFAULT);
613 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
614 struct lov_user_mds_data *lmdp;
617 st.st_dev = inode->i_sb->s_dev;
618 st.st_mode = body->mode;
619 st.st_nlink = body->nlink;
620 st.st_uid = body->uid;
621 st.st_gid = body->gid;
622 st.st_rdev = body->rdev;
623 st.st_size = body->size;
624 st.st_blksize = CFS_PAGE_SIZE;
625 st.st_blocks = body->blocks;
626 st.st_atime = body->atime;
627 st.st_mtime = body->mtime;
628 st.st_ctime = body->ctime;
629 st.st_ino = body->ino;
631 lmdp = (struct lov_user_mds_data *)arg;
632 rc = copy_to_user(&lmdp->lmd_st, &st, sizeof(st));
634 GOTO(out_lmm, rc = -EFAULT);
639 if (lmm && lmm->lmm_magic == LOV_MAGIC_JOIN)
640 OBD_FREE(lmm, lmmsize);
642 ptlrpc_req_finished(request);
647 case IOC_LOV_GETINFO: {
648 struct lov_user_mds_data *lumd;
649 struct lov_stripe_md *lsm;
650 struct lov_user_md *lum;
651 struct lov_mds_md *lmm;
656 lumd = (struct lov_user_mds_data *)arg;
657 lum = &lumd->lmd_lmm;
659 rc = ll_get_max_mdsize(sbi, &lmmsize);
663 OBD_ALLOC(lmm, lmmsize);
664 rc = copy_from_user(lmm, lum, lmmsize);
666 GOTO(free_lmm, rc = -EFAULT);
668 rc = obd_unpackmd(sbi->ll_osc_exp, &lsm, lmm, lmmsize);
670 GOTO(free_lmm, rc = -ENOMEM);
672 rc = obd_checkmd(sbi->ll_osc_exp, sbi->ll_mdc_exp, lsm);
676 /* Perform glimpse_size operation. */
677 memset(&st, 0, sizeof(st));
679 rc = ll_glimpse_ioctl(sbi, lsm, &st);
683 rc = copy_to_user(&lumd->lmd_st, &st, sizeof(st));
685 GOTO(free_lsm, rc = -EFAULT);
689 obd_free_memmd(sbi->ll_osc_exp, &lsm);
691 OBD_FREE(lmm, lmmsize);
694 case OBD_IOC_LLOG_CATINFO: {
695 struct ptlrpc_request *req = NULL;
698 char *bufs[3] = { NULL }, *str;
699 int lens[3] = { sizeof(struct ptlrpc_body) };
700 int size[2] = { sizeof(struct ptlrpc_body) };
702 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
707 if (!data->ioc_inlbuf1) {
708 obd_ioctl_freedata(buf, len);
712 lens[REQ_REC_OFF] = data->ioc_inllen1;
713 bufs[REQ_REC_OFF] = data->ioc_inlbuf1;
714 if (data->ioc_inllen2) {
715 lens[REQ_REC_OFF + 1] = data->ioc_inllen2;
716 bufs[REQ_REC_OFF + 1] = data->ioc_inlbuf2;
718 lens[REQ_REC_OFF + 1] = 0;
719 bufs[REQ_REC_OFF + 1] = NULL;
722 req = ptlrpc_prep_req(sbi2mdc(sbi)->cl_import,
723 LUSTRE_LOG_VERSION, LLOG_CATINFO, 3, lens,
726 GOTO(out_catinfo, rc = -ENOMEM);
728 size[REPLY_REC_OFF] = data->ioc_plen1;
729 ptlrpc_req_set_repsize(req, 2, size);
731 rc = ptlrpc_queue_wait(req);
732 str = lustre_msg_string(req->rq_repmsg, REPLY_REC_OFF,
735 rc = copy_to_user(data->ioc_pbuf1, str,data->ioc_plen1);
736 ptlrpc_req_finished(req);
738 obd_ioctl_freedata(buf, len);
741 case OBD_IOC_QUOTACHECK: {
742 struct obd_quotactl *oqctl;
745 if (!capable(CAP_SYS_ADMIN))
748 OBD_ALLOC_PTR(oqctl);
751 oqctl->qc_type = arg;
752 rc = obd_quotacheck(sbi->ll_mdc_exp, oqctl);
754 CDEBUG(D_INFO, "mdc_quotacheck failed: rc %d\n", rc);
758 rc = obd_quotacheck(sbi->ll_osc_exp, oqctl);
760 CDEBUG(D_INFO, "osc_quotacheck failed: rc %d\n", rc);
765 case OBD_IOC_POLL_QUOTACHECK: {
766 struct if_quotacheck *check;
769 if (!capable(CAP_SYS_ADMIN))
772 OBD_ALLOC_PTR(check);
776 rc = obd_iocontrol(cmd, sbi->ll_mdc_exp, 0, (void *)check,
779 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
780 if (copy_to_user((void *)arg, check, sizeof(*check)))
785 rc = obd_iocontrol(cmd, sbi->ll_osc_exp, 0, (void *)check,
788 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
789 if (copy_to_user((void *)arg, check, sizeof(*check)))
797 #ifdef HAVE_QUOTA_SUPPORT
798 case OBD_IOC_QUOTACTL: {
799 struct if_quotactl *qctl;
800 struct obd_quotactl *oqctl;
802 int cmd, type, id, rc = 0;
808 OBD_ALLOC_PTR(oqctl);
813 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
814 GOTO(out_quotactl, rc = -EFAULT);
817 type = qctl->qc_type;
824 if (!capable(CAP_SYS_ADMIN))
825 GOTO(out_quotactl, rc = -EPERM);
828 if (((type == USRQUOTA && current->euid != id) ||
829 (type == GRPQUOTA && !in_egroup_p(id))) &&
830 !capable(CAP_SYS_ADMIN))
831 GOTO(out_quotactl, rc = -EPERM);
833 /* XXX: dqb_valid is borrowed as a flag to mark that
834 * only mds quota is wanted */
835 if (qctl->qc_dqblk.dqb_valid)
836 qctl->obd_uuid = sbi->ll_mdc_exp->exp_obd->
837 u.cli.cl_target_uuid;
842 CERROR("unsupported quotactl op: %#x\n", cmd);
843 GOTO(out_quotactl, -ENOTTY);
846 QCTL_COPY(oqctl, qctl);
848 if (qctl->obd_uuid.uuid[0]) {
849 struct obd_device *obd;
850 struct obd_uuid *uuid = &qctl->obd_uuid;
852 obd = class_find_client_notype(uuid,
853 &sbi->ll_osc_exp->exp_obd->obd_uuid);
855 GOTO(out_quotactl, rc = -ENOENT);
857 if (cmd == Q_GETINFO)
858 oqctl->qc_cmd = Q_GETOINFO;
859 else if (cmd == Q_GETQUOTA)
860 oqctl->qc_cmd = Q_GETOQUOTA;
862 GOTO(out_quotactl, rc = -EINVAL);
864 if (sbi->ll_mdc_exp->exp_obd == obd) {
865 rc = obd_quotactl(sbi->ll_mdc_exp, oqctl);
868 struct obd_export *exp;
869 struct lov_obd *lov = &sbi->ll_osc_exp->
872 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
873 if (!lov->lov_tgts[i] ||
874 !lov->lov_tgts[i]->ltd_active)
876 exp = lov->lov_tgts[i]->ltd_exp;
877 if (exp->exp_obd == obd) {
878 rc = obd_quotactl(exp, oqctl);
885 QCTL_COPY(qctl, oqctl);
887 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
890 GOTO(out_quotactl, rc);
893 rc = obd_quotactl(sbi->ll_mdc_exp, oqctl);
894 if (rc && rc != -EBUSY && cmd == Q_QUOTAON) {
895 oqctl->qc_cmd = Q_QUOTAOFF;
896 obd_quotactl(sbi->ll_mdc_exp, oqctl);
899 QCTL_COPY(qctl, oqctl);
901 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
908 #endif /* HAVE_QUOTA_SUPPORT */
909 case OBD_IOC_GETNAME: {
910 struct obd_device *obd = class_exp2obd(sbi->ll_osc_exp);
913 if (copy_to_user((void *)arg, obd->obd_name,
914 strlen(obd->obd_name) + 1))
919 RETURN(obd_iocontrol(cmd, sbi->ll_osc_exp,0,NULL,(void *)arg));
923 int ll_dir_open(struct inode *inode, struct file *file)
926 RETURN(ll_file_open(inode, file));
929 int ll_dir_release(struct inode *inode, struct file *file)
932 RETURN(ll_file_release(inode, file));
935 struct file_operations ll_dir_operations = {
937 .release = ll_dir_release,
938 .read = generic_read_dir,
939 .readdir = ll_readdir,
940 .ioctl = ll_dir_ioctl