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 <linux/obd_support.h>
45 #include <linux/obd_class.h>
46 #include <linux/lustre_lib.h>
47 #include <linux/lustre_idl.h>
48 #include <linux/lustre_mdc.h>
49 #include <linux/lustre_lite.h>
50 #include <linux/lustre_dlm.h>
51 #include "llite_internal.h"
53 typedef struct ext2_dir_entry_2 ext2_dirent;
55 #define PageChecked(page) test_bit(PG_checked, &(page)->flags)
56 #define SetPageChecked(page) set_bit(PG_checked, &(page)->flags)
58 /* returns the page unlocked, but with a reference */
59 static int ll_dir_readpage(struct file *file, struct page *page)
61 struct inode *inode = page->mapping->host;
64 struct ptlrpc_request *request;
65 struct mdt_body *body;
69 offset = (__u64)page->index << PAGE_SHIFT;
70 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) off "LPU64"\n",
71 inode->i_ino, inode->i_generation, inode, offset);
73 ll_inode2fid(&fid, inode);
75 rc = mdc_readpage(ll_i2sbi(inode)->ll_mdc_exp, &fid,
76 offset, page, &request);
78 body = lustre_msg_buf(request->rq_repmsg, 0, sizeof (*body));
79 LASSERT (body != NULL); /* checked by mdc_readpage() */
80 LASSERT_REPSWABBED (request, 0); /* swabbed by mdc_readpage() */
82 inode->i_size = body->size;
83 SetPageUptodate(page);
85 ptlrpc_req_finished(request);
92 struct address_space_operations ll_dir_aops = {
93 .readpage = ll_dir_readpage,
97 * ext2 uses block-sized chunks. Arguably, sector-sized ones would be
98 * more robust, but we have what we have
100 static inline unsigned ext2_chunk_size(struct inode *inode)
102 return inode->i_sb->s_blocksize;
105 static inline void ext2_put_page(struct page *page)
108 page_cache_release(page);
111 static inline unsigned long dir_pages(struct inode *inode)
113 return (inode->i_size+PAGE_CACHE_SIZE-1)>>PAGE_CACHE_SHIFT;
117 static void ext2_check_page(struct page *page)
119 struct inode *dir = page->mapping->host;
120 unsigned chunk_size = ext2_chunk_size(dir);
121 char *kaddr = page_address(page);
122 // u32 max_inumber = le32_to_cpu(sb->u.ext2_sb.s_es->s_inodes_count);
123 unsigned offs, rec_len;
124 unsigned limit = PAGE_CACHE_SIZE;
128 if ((dir->i_size >> PAGE_CACHE_SHIFT) == page->index) {
129 limit = dir->i_size & ~PAGE_CACHE_MASK;
130 if (limit & (chunk_size - 1)) {
131 CERROR("limit %d dir size %lld index %ld\n",
132 limit, dir->i_size, page->index);
135 for (offs = limit; offs<PAGE_CACHE_SIZE; offs += chunk_size) {
136 ext2_dirent *p = (ext2_dirent*)(kaddr + offs);
137 p->rec_len = cpu_to_le16(chunk_size);
144 for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
145 p = (ext2_dirent *)(kaddr + offs);
146 rec_len = le16_to_cpu(p->rec_len);
148 if (rec_len < EXT2_DIR_REC_LEN(1))
152 if (rec_len < EXT2_DIR_REC_LEN(p->name_len))
154 if (((offs + rec_len - 1) ^ offs) & ~(chunk_size-1))
156 // if (le32_to_cpu(p->inode) > max_inumber)
162 SetPageChecked(page);
165 /* Too bad, we had an error */
168 CERROR("ext2_check_page"
169 "size of directory #%lu is not a multiple of chunk size\n",
174 error = "rec_len is smaller than minimal";
177 error = "unaligned directory entry";
180 error = "rec_len is too small for name_len";
183 error = "directory entry across blocks";
186 // error = "inode out of bounds";
188 CERROR("ext2_check_page: bad entry in directory #%lu: %s - "
189 "offset=%lu+%u, inode=%lu, rec_len=%d, name_len=%d",
190 dir->i_ino, error, (page->index<<PAGE_CACHE_SHIFT), offs,
191 (unsigned long) le32_to_cpu(p->inode),
192 rec_len, p->name_len);
195 p = (ext2_dirent *)(kaddr + offs);
196 CERROR("ext2_check_page"
197 "entry in directory #%lu spans the page boundary"
198 "offset=%lu, inode=%lu",
199 dir->i_ino, (page->index<<PAGE_CACHE_SHIFT)+offs,
200 (unsigned long) le32_to_cpu(p->inode));
202 SetPageChecked(page);
206 static struct page *ll_get_dir_page(struct inode *dir, unsigned long n)
208 struct ldlm_res_id res_id =
209 { .name = { dir->i_ino, (__u64)dir->i_generation} };
210 struct lustre_handle lockh;
211 struct obd_device *obddev = class_exp2obd(ll_i2sbi(dir)->ll_mdc_exp);
212 struct address_space *mapping = dir->i_mapping;
214 ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_UPDATE} };
217 rc = ldlm_lock_match(obddev->obd_namespace, LDLM_FL_BLOCK_GRANTED,
218 &res_id, LDLM_IBITS, &policy, LCK_CR, &lockh);
220 struct lookup_intent it = { .it_op = IT_READDIR };
221 struct ptlrpc_request *request;
222 struct mdc_op_data data;
224 ll_prepare_mdc_op_data(&data, dir, NULL, NULL, 0, 0);
226 rc = mdc_enqueue(ll_i2sbi(dir)->ll_mdc_exp, LDLM_IBITS, &it,
227 LCK_CR, &data, &lockh, NULL, 0,
228 ldlm_completion_ast, ll_mdc_blocking_ast, dir,
231 request = (struct ptlrpc_request *)it.d.lustre.it_data;
233 ptlrpc_req_finished(request);
235 CERROR("lock enqueue: rc: %d\n", rc);
239 ldlm_lock_dump_handle(D_OTHER, &lockh);
241 page = read_cache_page(mapping, n,
242 (filler_t*)mapping->a_ops->readpage, NULL);
246 if (!PageUptodate(page))
248 if (!PageChecked(page))
249 ext2_check_page(page);
255 ldlm_lock_decref(&lockh, LCK_CR);
260 page = ERR_PTR(-EIO);
265 * p is at least 6 bytes before the end of page
267 static inline ext2_dirent *ext2_next_entry(ext2_dirent *p)
269 return (ext2_dirent *)((char*)p + le16_to_cpu(p->rec_len));
272 static inline unsigned
273 ext2_validate_entry(char *base, unsigned offset, unsigned mask)
275 ext2_dirent *de = (ext2_dirent*)(base + offset);
276 ext2_dirent *p = (ext2_dirent*)(base + (offset&mask));
277 while ((char*)p < (char*)de)
278 p = ext2_next_entry(p);
279 return (char *)p - base;
282 static unsigned char ext2_filetype_table[EXT2_FT_MAX] = {
283 [EXT2_FT_UNKNOWN] DT_UNKNOWN,
284 [EXT2_FT_REG_FILE] DT_REG,
285 [EXT2_FT_DIR] DT_DIR,
286 [EXT2_FT_CHRDEV] DT_CHR,
287 [EXT2_FT_BLKDEV] DT_BLK,
288 [EXT2_FT_FIFO] DT_FIFO,
289 [EXT2_FT_SOCK] DT_SOCK,
290 [EXT2_FT_SYMLINK] DT_LNK,
294 int ll_readdir(struct file * filp, void * dirent, filldir_t filldir)
296 struct inode *inode = filp->f_dentry->d_inode;
297 loff_t pos = filp->f_pos;
298 // XXX struct super_block *sb = inode->i_sb;
299 unsigned offset = pos & ~PAGE_CACHE_MASK;
300 unsigned long n = pos >> PAGE_CACHE_SHIFT;
301 unsigned long npages = dir_pages(inode);
302 unsigned chunk_mask = ~(ext2_chunk_size(inode)-1);
303 unsigned char *types = ext2_filetype_table;
304 int need_revalidate = (filp->f_version != inode->i_version);
308 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %llu/%llu\n",
309 inode->i_ino, inode->i_generation, inode, pos, inode->i_size);
311 if (pos > inode->i_size - EXT2_DIR_REC_LEN(1))
314 for ( ; n < npages; n++, offset = 0) {
319 CDEBUG(D_EXT2,"read %lu of dir %lu/%u page %lu/%lu size %llu\n",
320 PAGE_CACHE_SIZE, inode->i_ino, inode->i_generation,
321 n, npages, inode->i_size);
322 page = ll_get_dir_page(inode, n);
324 /* size might have been updated by mdc_readpage */
325 npages = dir_pages(inode);
329 CERROR("error reading dir %lu/%u page %lu: rc %d\n",
330 inode->i_ino, inode->i_generation, n, rc);
334 kaddr = page_address(page);
335 if (need_revalidate) {
336 offset = ext2_validate_entry(kaddr, offset, chunk_mask);
339 de = (ext2_dirent *)(kaddr+offset);
340 limit = kaddr + PAGE_CACHE_SIZE - EXT2_DIR_REC_LEN(1);
341 for ( ;(char*)de <= limit; de = ext2_next_entry(de)) {
345 rc = 0; /* no error if we return something */
347 offset = (char *)de - kaddr;
348 over = filldir(dirent, de->name, de->name_len,
349 (n<<PAGE_CACHE_SHIFT) | offset,
350 le32_to_cpu(de->inode),
351 types[de->file_type &
363 filp->f_pos = (n << PAGE_CACHE_SHIFT) | offset;
364 filp->f_version = inode->i_version;
369 #define QCTL_COPY(out, in) \
371 Q_COPY(out, in, qc_cmd); \
372 Q_COPY(out, in, qc_type); \
373 Q_COPY(out, in, qc_id); \
374 Q_COPY(out, in, qc_stat); \
375 Q_COPY(out, in, qc_dqinfo); \
376 Q_COPY(out, in, qc_dqblk); \
379 static int ll_dir_ioctl(struct inode *inode, struct file *file,
380 unsigned int cmd, unsigned long arg)
382 struct ll_sb_info *sbi = ll_i2sbi(inode);
383 struct obd_ioctl_data *data;
386 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), cmd=%#x\n",
387 inode->i_ino, inode->i_generation, inode, cmd);
389 /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
390 if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
393 lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_IOCTL);
395 case EXT3_IOC_GETFLAGS:
396 case EXT3_IOC_SETFLAGS:
397 RETURN(ll_iocontrol(inode, file, cmd, arg));
398 case EXT3_IOC_GETVERSION_OLD:
399 case EXT3_IOC_GETVERSION:
400 RETURN(put_user(inode->i_generation, (int *)arg));
401 /* We need to special case any other ioctls we want to handle,
402 * to send them to the MDS/OST as appropriate and to properly
403 * network encode the arg field.
404 case EXT3_IOC_SETVERSION_OLD:
405 case EXT3_IOC_SETVERSION:
407 case IOC_MDC_LOOKUP: {
408 struct ptlrpc_request *request = NULL;
412 int namelen, rc, len = 0;
414 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
419 filename = data->ioc_inlbuf1;
420 namelen = data->ioc_inllen1;
423 CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
424 GOTO(out, rc = -EINVAL);
427 ll_inode2fid(&fid, inode);
428 rc = mdc_getattr_name(sbi->ll_mdc_exp, &fid, filename, namelen,
429 OBD_MD_FLID, 0, &request);
431 CDEBUG(D_INFO, "mdc_getattr_name: %d\n", rc);
435 ptlrpc_req_finished(request);
439 obd_ioctl_freedata(buf, len);
442 case LL_IOC_LOV_SETSTRIPE: {
443 struct ptlrpc_request *request = NULL;
444 struct mdc_op_data op_data;
445 struct iattr attr = { 0 };
446 struct lov_user_md lum, *lump = (struct lov_user_md *)arg;
449 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
451 LASSERT(sizeof(lum) == sizeof(*lump));
452 LASSERT(sizeof(lum.lmm_objects[0]) ==
453 sizeof(lump->lmm_objects[0]));
454 rc = copy_from_user(&lum, lump, sizeof(lum));
459 * This is coming from userspace, so should be in
460 * local endian. But the MDS would like it in little
461 * endian, so we swab it before we send it.
463 if (lum.lmm_magic != LOV_USER_MAGIC)
466 if (lum.lmm_magic != cpu_to_le32(LOV_USER_MAGIC))
467 lustre_swab_lov_user_md(&lum);
469 /* swabbing is done in lov_setstripe() on server side */
470 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
471 &attr, &lum, sizeof(lum), NULL, 0, &request);
473 ptlrpc_req_finished(request);
474 if (rc != -EPERM && rc != -EACCES)
475 CERROR("mdc_setattr fails: rc = %d\n", rc);
478 ptlrpc_req_finished(request);
482 case LL_IOC_LOV_GETSTRIPE: {
483 struct ptlrpc_request *request = NULL;
484 struct lov_user_md *lump = (struct lov_user_md *)arg;
485 struct lov_mds_md *lmm;
487 struct mdt_body *body;
490 ll_inode2fid(&fid, inode);
492 rc = ll_get_max_mdsize(sbi, &lmmsize);
496 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, OBD_MD_FLDIREA,
499 CDEBUG(D_INFO, "mdc_getattr failed: rc = %d\n", rc);
503 body = lustre_msg_buf(request->rq_repmsg, 0, sizeof(*body));
504 LASSERT(body != NULL); /* checked by mdc_getattr_name */
505 LASSERT_REPSWABBED(request, 0);/* swabbed by mdc_getattr_name */
507 lmmsize = body->eadatasize;
509 GOTO(out_get, rc = -ENODATA);
511 lmm = lustre_msg_buf(request->rq_repmsg, 1, lmmsize);
512 LASSERT(lmm != NULL);
513 LASSERT_REPSWABBED(request, 1);
516 * This is coming from the MDS, so is probably in
517 * little endian. We convert it to host endian before
518 * passing it to userspace.
520 if (lmm->lmm_magic == __swab32(LOV_MAGIC)) {
521 lustre_swab_lov_user_md((struct lov_user_md *)lmm);
522 lustre_swab_lov_user_md_objects((struct lov_user_md *)lmm);
525 rc = copy_to_user(lump, lmm, lmmsize);
527 GOTO(out_get, rc = -EFAULT);
531 ptlrpc_req_finished(request);
534 case LL_IOC_OBD_STATFS:
535 RETURN(ll_obd_statfs(inode, (void *)arg));
536 case IOC_MDC_GETFILEINFO:
537 case IOC_MDC_GETSTRIPE: {
538 struct ptlrpc_request *request = NULL;
540 struct mdt_body *body;
541 struct lov_user_md *lump;
542 struct lov_mds_md *lmm;
546 filename = getname((const char *)arg);
547 if (IS_ERR(filename))
548 RETURN(PTR_ERR(filename));
550 ll_inode2fid(&fid, inode);
552 rc = ll_get_max_mdsize(sbi, &lmmsize);
556 rc = mdc_getattr_name(sbi->ll_mdc_exp, &fid, filename,
557 strlen(filename) + 1, OBD_MD_FLEASIZE,
560 CDEBUG(D_INFO, "mdc_getattr_name failed on %s: rc %d\n",
565 body = lustre_msg_buf(request->rq_repmsg, 0, sizeof (*body));
566 LASSERT(body != NULL); /* checked by mdc_getattr_name */
567 LASSERT_REPSWABBED(request, 0);/* swabbed by mdc_getattr_name */
569 lmmsize = body->eadatasize;
571 if (!(body->valid & OBD_MD_FLEASIZE) || lmmsize == 0)
572 GOTO(out_req, rc = -ENODATA);
575 GOTO(out_req, rc = -EFBIG);
577 lmm = lustre_msg_buf(request->rq_repmsg, 1, lmmsize);
578 LASSERT(lmm != NULL);
579 LASSERT_REPSWABBED(request, 1);
582 * This is coming from the MDS, so is probably in
583 * little endian. We convert it to host endian before
584 * passing it to userspace.
586 if (lmm->lmm_magic == __swab32(LOV_MAGIC)) {
587 lustre_swab_lov_user_md((struct lov_user_md *)lmm);
588 lustre_swab_lov_user_md_objects((struct lov_user_md *)lmm);
589 } else if (lmm->lmm_magic == __swab32(LOV_MAGIC_JOIN)) {
590 lustre_swab_lov_user_md_join((struct lov_user_md_join *)lmm);
592 if (lmm->lmm_magic == LOV_MAGIC_JOIN) {
593 struct lov_stripe_md *lsm;
594 struct lov_user_md_join *lmj;
595 int lmj_size, i, aindex = 0, rc;
597 rc = obd_unpackmd(sbi->ll_osc_exp, &lsm, lmm, lmmsize);
599 GOTO(out_req, rc = -ENOMEM);
600 rc = obd_checkmd(sbi->ll_osc_exp, sbi->ll_mdc_exp, lsm);
602 GOTO(out_free_memmd, rc);
604 lmj_size = sizeof(struct lov_user_md_join) +
605 lsm->lsm_stripe_count *
606 sizeof(struct lov_user_ost_data_join);
607 OBD_ALLOC(lmj, lmj_size);
609 GOTO(out_free_memmd, rc = -ENOMEM);
611 memcpy(lmj, lmm, sizeof(struct lov_user_md_join));
612 for(i = 0; i < lsm->lsm_stripe_count; i++) {
613 struct lov_array_info *lai = lsm->lsm_array;
614 if ((lai->lai_ext_array[aindex].le_loi_idx +
615 lai->lai_ext_array[aindex].le_stripe_count)<=i){
618 CDEBUG(D_INFO, "aindex %d i %d l_extent_start"LPU64""
619 "len %d \n", aindex, i,
620 lai->lai_ext_array[aindex].le_start,
621 (int)lai->lai_ext_array[aindex].le_len);
622 lmj->lmm_objects[i].l_extent_start =
623 lai->lai_ext_array[aindex].le_start;
625 if ((int)lai->lai_ext_array[aindex].le_len == -1) {
626 lmj->lmm_objects[i].l_extent_end = -1;
628 lmj->lmm_objects[i].l_extent_end =
629 lai->lai_ext_array[aindex].le_start +
630 lai->lai_ext_array[aindex].le_len;
632 lmj->lmm_objects[i].l_object_id =
633 lsm->lsm_oinfo[i].loi_id;
634 lmj->lmm_objects[i].l_object_gr =
635 lsm->lsm_oinfo[i].loi_gr;
636 lmj->lmm_objects[i].l_ost_gen =
637 lsm->lsm_oinfo[i].loi_ost_gen;
638 lmj->lmm_objects[i].l_ost_idx =
639 lsm->lsm_oinfo[i].loi_ost_idx;
641 lmm = (struct lov_mds_md *)lmj;
644 obd_free_memmd(sbi->ll_osc_exp, &lsm);
648 if (cmd == IOC_MDC_GETFILEINFO) {
649 struct lov_user_mds_data *lmdp;
653 st.st_mode = body->mode;
654 st.st_nlink = body->nlink;
655 st.st_uid = body->uid;
656 st.st_gid = body->gid;
657 st.st_rdev = body->rdev;
658 st.st_size = body->size;
659 st.st_blksize = PAGE_SIZE;
660 st.st_blocks = body->blocks;
661 st.st_atime = body->atime;
662 st.st_mtime = body->mtime;
663 st.st_ctime = body->ctime;
664 st.st_ino = body->ino;
666 lmdp = (struct lov_user_mds_data *)arg;
667 rc = copy_to_user(&lmdp->lmd_st, &st, sizeof(st));
669 GOTO(out_req, rc = -EFAULT);
670 lump = &lmdp->lmd_lmm;
672 lump = (struct lov_user_md *)arg;
675 rc = copy_to_user(lump, lmm, lmmsize);
676 if (lmm->lmm_magic == LOV_MAGIC_JOIN)
677 OBD_FREE(lmm, lmmsize);
679 GOTO(out_req, rc = -EFAULT);
683 ptlrpc_req_finished(request);
688 case OBD_IOC_LLOG_CATINFO: {
689 struct ptlrpc_request *req = NULL;
695 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
700 if (!data->ioc_inlbuf1) {
701 obd_ioctl_freedata(buf, len);
705 lens[0] = data->ioc_inllen1;
706 bufs[0] = data->ioc_inlbuf1;
707 if (data->ioc_inllen2) {
708 lens[1] = data->ioc_inllen2;
709 bufs[1] = data->ioc_inlbuf2;
714 size = data->ioc_plen1;
715 req = ptlrpc_prep_req(sbi2mdc(sbi)->cl_import,
716 LUSTRE_LOG_VERSION, LLOG_CATINFO,
719 GOTO(out_catinfo, rc = -ENOMEM);
720 req->rq_replen = lustre_msg_size(1, &size);
722 rc = ptlrpc_queue_wait(req);
723 str = lustre_msg_string(req->rq_repmsg, 0, data->ioc_plen1);
725 rc = copy_to_user(data->ioc_pbuf1, str,
727 ptlrpc_req_finished(req);
729 obd_ioctl_freedata(buf, len);
732 case OBD_IOC_QUOTACHECK: {
733 struct obd_quotactl *oqctl;
736 if (!capable(CAP_SYS_ADMIN))
739 OBD_ALLOC_PTR(oqctl);
742 oqctl->qc_type = arg;
743 rc = obd_quotacheck(sbi->ll_mdc_exp, oqctl);
745 CDEBUG(D_INFO, "mdc_quotacheck failed: rc %d\n", rc);
749 rc = obd_quotacheck(sbi->ll_osc_exp, oqctl);
751 CDEBUG(D_INFO, "osc_quotacheck failed: rc %d\n", rc);
756 case OBD_IOC_POLL_QUOTACHECK: {
757 struct if_quotacheck *check;
760 if (!capable(CAP_SYS_ADMIN))
763 OBD_ALLOC_PTR(check);
767 rc = obd_iocontrol(cmd, sbi->ll_mdc_exp, 0, (void *)check,
770 CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
771 if (copy_to_user((void *)arg, check, sizeof(*check)))
776 rc = obd_iocontrol(cmd, sbi->ll_osc_exp, 0, (void *)check,
779 CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
780 if (copy_to_user((void *)arg, check, sizeof(*check)))
788 #if HAVE_QUOTA_SUPPORT
789 case OBD_IOC_QUOTACTL: {
790 struct if_quotactl *qctl;
791 struct obd_quotactl *oqctl;
793 int cmd, type, id, rc = 0;
799 OBD_ALLOC_PTR(oqctl);
804 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
805 GOTO(out_quotactl, rc = -EFAULT);
808 type = qctl->qc_type;
815 if (!capable(CAP_SYS_ADMIN))
816 GOTO(out_quotactl, rc = -EPERM);
819 if (((type == USRQUOTA && current->euid != id) ||
820 (type == GRPQUOTA && !in_egroup_p(id))) &&
821 !capable(CAP_SYS_ADMIN))
822 GOTO(out_quotactl, rc = -EPERM);
824 /* XXX: dqb_valid is borrowed as a flag to mark that
825 * only mds quota is wanted */
826 if (qctl->qc_dqblk.dqb_valid)
828 sbi->ll_mdc_exp->exp_obd->u.cli.
829 cl_import->imp_target_uuid;
834 CERROR("unsupported quotactl op: %#x\n", cmd);
835 GOTO(out_quotactl, -ENOTTY);
838 QCTL_COPY(oqctl, qctl);
840 if (qctl->obd_uuid.uuid[0]) {
841 struct obd_device *obd;
842 struct obd_uuid *uuid = &qctl->obd_uuid;
844 obd = class_find_client_notype(uuid,
845 &sbi->ll_osc_exp->exp_obd->obd_uuid);
847 GOTO(out_quotactl, rc = -ENOENT);
849 if (cmd == Q_GETINFO)
850 oqctl->qc_cmd = Q_GETOINFO;
851 else if (cmd == Q_GETQUOTA)
852 oqctl->qc_cmd = Q_GETOQUOTA;
854 GOTO(out_quotactl, rc = -EINVAL);
856 if (sbi->ll_mdc_exp->exp_obd == obd) {
857 rc = obd_quotactl(sbi->ll_mdc_exp, oqctl);
860 struct obd_export *exp;
861 struct lov_obd *lov = &sbi->ll_osc_exp->
864 for (i = 0; i < lov->desc.ld_tgt_count; i++) {
865 exp = lov->tgts[i].ltd_exp;
867 if (!lov->tgts[i].active)
870 if (exp->exp_obd == obd) {
871 rc = obd_quotactl(exp, oqctl);
878 QCTL_COPY(qctl, oqctl);
880 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
883 GOTO(out_quotactl, rc);
886 rc = obd_quotactl(sbi->ll_mdc_exp, oqctl);
887 if (rc && rc != -EBUSY && cmd == Q_QUOTAON) {
888 oqctl->qc_cmd = Q_QUOTAOFF;
889 obd_quotactl(sbi->ll_mdc_exp, oqctl);
892 QCTL_COPY(qctl, oqctl);
894 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
901 #endif /* HAVE_QUOTA_SUPPORT */
902 case OBD_IOC_GETNAME: {
903 struct obd_device *obd = class_exp2obd(sbi->ll_osc_exp);
906 if (copy_to_user((void *)arg, obd->obd_name,
907 strlen(obd->obd_name) + 1))
912 RETURN(obd_iocontrol(cmd, sbi->ll_osc_exp,0,NULL,(void *)arg));
916 int ll_dir_open(struct inode *inode, struct file *file)
919 RETURN(ll_file_open(inode, file));
922 int ll_dir_release(struct inode *inode, struct file *file)
925 RETURN(ll_file_release(inode, file));
928 struct file_operations ll_dir_operations = {
930 .release = ll_dir_release,
931 .read = generic_read_dir,
932 .readdir = ll_readdir,
933 .ioctl = ll_dir_ioctl