Whamcloud - gitweb
Land first part of new dcache handling (bug 16654).
[fs/lustre-release.git] / lustre / llite / dir.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/llite/dir.c
37  *
38  * Directory code for lustre client.
39  */
40
41 #include <linux/fs.h>
42 #include <linux/pagemap.h>
43 #include <linux/mm.h>
44 #include <linux/version.h>
45 #include <linux/smp_lock.h>
46 #include <asm/uaccess.h>
47 #include <linux/buffer_head.h>   // for wait_on_buffer
48
49 #define DEBUG_SUBSYSTEM S_LLITE
50
51 #include <obd_support.h>
52 #include <obd_class.h>
53 #include <lustre_lib.h>
54 #include <lustre/lustre_idl.h>
55 #include <lustre_lite.h>
56 #include <lustre_dlm.h>
57 #include <lustre_fid.h>
58 #include "llite_internal.h"
59
60 #ifndef HAVE_PAGE_CHECKED
61 #ifdef HAVE_PG_FS_MISC
62 #define PageChecked(page)        test_bit(PG_fs_misc, &(page)->flags)
63 #define SetPageChecked(page)     set_bit(PG_fs_misc, &(page)->flags)
64 #else
65 #error PageChecked or PageFsMisc not defined in kernel
66 #endif
67 #endif
68
69 /*
70  * (new) readdir implementation overview.
71  *
72  * Original lustre readdir implementation cached exact copy of raw directory
73  * pages on the client. These pages were indexed in client page cache by
74  * logical offset in the directory file. This design, while very simple and
75  * intuitive had some inherent problems:
76  *
77  *     . it implies that byte offset to the directory entry serves as a
78  *     telldir(3)/seekdir(3) cookie, but that offset is not stable: in
79  *     ext3/htree directory entries may move due to splits, and more
80  *     importantly,
81  *
82  *     . it is incompatible with the design of split directories for cmd3,
83  *     that assumes that names are distributed across nodes based on their
84  *     hash, and so readdir should be done in hash order.
85  *
86  * New readdir implementation does readdir in hash order, and uses hash of a
87  * file name as a telldir/seekdir cookie. This led to number of complications:
88  *
89  *     . hash is not unique, so it cannot be used to index cached directory
90  *     pages on the client (note, that it requires a whole pageful of hash
91  *     collided entries to cause two pages to have identical hashes);
92  *
93  *     . hash is not unique, so it cannot, strictly speaking, be used as an
94  *     entry cookie. ext3/htree has the same problem and lustre implementation
95  *     mimics their solution: seekdir(hash) positions directory at the first
96  *     entry with the given hash.
97  *
98  * Client side.
99  *
100  * 0. caching
101  *
102  * Client caches directory pages using hash of the first entry as an index. As
103  * noted above hash is not unique, so this solution doesn't work as is:
104  * special processing is needed for "page hash chains" (i.e., sequences of
105  * pages filled with entries all having the same hash value).
106  *
107  * First, such chains have to be detected. To this end, server returns to the
108  * client the hash of the first entry on the page next to one returned. When
109  * client detects that this hash is the same as hash of the first entry on the
110  * returned page, page hash collision has to be handled. Pages in the
111  * hash chain, except first one, are termed "overflow pages".
112  *
113  * Solution to index uniqueness problem is to not cache overflow
114  * pages. Instead, when page hash collision is detected, all overflow pages
115  * from emerging chain are immediately requested from the server and placed in
116  * a special data structure (struct ll_dir_chain). This data structure is used
117  * by ll_readdir() to process entries from overflow pages. When readdir
118  * invocation finishes, overflow pages are discarded. If page hash collision
119  * chain weren't completely processed, next call to readdir will again detect
120  * page hash collision, again read overflow pages in, process next portion of
121  * entries and again discard the pages. This is not as wasteful as it looks,
122  * because, given reasonable hash, page hash collisions are extremely rare.
123  *
124  * 1. directory positioning
125  *
126  * When seekdir(hash) is called, original
127  *
128  *
129  *
130  *
131  *
132  *
133  *
134  *
135  * Server.
136  *
137  * identification of and access to overflow pages
138  *
139  * page format
140  *
141  *
142  *
143  *
144  *
145  */
146
147 /* returns the page unlocked, but with a reference */
148 static int ll_dir_readpage(struct file *file, struct page *page)
149 {
150         struct inode *inode = page->mapping->host;
151         struct ptlrpc_request *request;
152         struct mdt_body *body;
153         struct obd_capa *oc;
154         __u64 hash;
155         int rc;
156         ENTRY;
157
158         hash = (__u64)hash_x_index(page->index);
159         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) off %lu\n",
160                inode->i_ino, inode->i_generation, inode, (unsigned long)hash);
161
162         oc = ll_mdscapa_get(inode);
163         rc = md_readpage(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode),
164                          oc, hash, page, &request);
165         capa_put(oc);
166         if (!rc) {
167                 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
168                 /* Checked by mdc_readpage() */
169                 LASSERT(body != NULL);
170
171                 if (body->valid & OBD_MD_FLSIZE) {
172                         ll_inode_size_lock(inode, 0);
173                         i_size_write(inode, body->size);
174                         ll_inode_size_unlock(inode, 0);
175                 }
176                 SetPageUptodate(page);
177         }
178         ptlrpc_req_finished(request);
179
180         unlock_page(page);
181         EXIT;
182         return rc;
183 }
184
185 struct address_space_operations ll_dir_aops = {
186         .readpage  = ll_dir_readpage,
187 };
188
189 static void ll_check_page(struct inode *dir, struct page *page)
190 {
191         /* XXX: check page format later */
192         SetPageChecked(page);
193 }
194
195 static void ll_release_page(struct page *page, __u64 hash,
196                             __u64 start, __u64 end)
197 {
198         kunmap(page);
199         lock_page(page);
200         if (likely(page->mapping != NULL)) {
201                 ll_truncate_complete_page(page);
202                 unlock_page(page);
203         } else {
204                 unlock_page(page);
205                 CWARN("NULL mapping page %p, truncated by others: "
206                       "hash("LPX64") | start("LPX64") | end("LPX64")\n",
207                       page, hash, start, end);
208         }
209         page_cache_release(page);
210 }
211
212 /*
213  * Find, kmap and return page that contains given hash.
214  */
215 static struct page *ll_dir_page_locate(struct inode *dir, __u64 hash,
216                                        __u64 *start, __u64 *end)
217 {
218         struct address_space *mapping = dir->i_mapping;
219         /*
220          * Complement of hash is used as an index so that
221          * radix_tree_gang_lookup() can be used to find a page with starting
222          * hash _smaller_ than one we are looking for.
223          */
224         unsigned long offset = hash_x_index((unsigned long)hash);
225         struct page *page;
226         int found;
227
228         TREE_READ_LOCK_IRQ(mapping);
229         found = radix_tree_gang_lookup(&mapping->page_tree,
230                                        (void **)&page, offset, 1);
231         if (found > 0) {
232                 struct lu_dirpage *dp;
233
234                 page_cache_get(page);
235                 TREE_READ_UNLOCK_IRQ(mapping);
236                 /*
237                  * In contrast to find_lock_page() we are sure that directory
238                  * page cannot be truncated (while DLM lock is held) and,
239                  * hence, can avoid restart.
240                  *
241                  * In fact, page cannot be locked here at all, because
242                  * ll_dir_readpage() does synchronous io.
243                  */
244                 wait_on_page(page);
245                 if (PageUptodate(page)) {
246                         dp = kmap(page);
247                         *start = le64_to_cpu(dp->ldp_hash_start);
248                         *end   = le64_to_cpu(dp->ldp_hash_end);
249                         LASSERT(*start <= hash);
250                         if (hash > *end || (*end != *start && hash == *end)) {
251                                 ll_release_page(page, hash, *start, *end);
252                                 page = NULL;
253                         }
254                 } else {
255                         page_cache_release(page);
256                         page = ERR_PTR(-EIO);
257                 }
258
259         } else {
260                 TREE_READ_UNLOCK_IRQ(mapping);
261                 page = NULL;
262         }
263         return page;
264 }
265
266 struct page *ll_get_dir_page(struct inode *dir, __u64 hash, int exact,
267                              struct ll_dir_chain *chain)
268 {
269         ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_UPDATE} };
270         struct address_space *mapping = dir->i_mapping;
271         struct lustre_handle lockh;
272         struct lu_dirpage *dp;
273         struct page *page;
274         ldlm_mode_t mode;
275         int rc;
276         __u64 start = 0;
277         __u64 end = 0;
278
279         mode = LCK_PR;
280         rc = md_lock_match(ll_i2sbi(dir)->ll_md_exp, LDLM_FL_BLOCK_GRANTED,
281                            ll_inode2fid(dir), LDLM_IBITS, &policy, mode, &lockh);
282         if (!rc) {
283                 struct ldlm_enqueue_info einfo = { LDLM_IBITS, mode,
284                        ll_md_blocking_ast, ldlm_completion_ast,
285                        NULL, NULL, dir };
286                 struct lookup_intent it = { .it_op = IT_READDIR };
287                 struct ptlrpc_request *request;
288                 struct md_op_data *op_data;
289
290                 op_data = ll_prep_md_op_data(NULL, dir, NULL, NULL, 0, 0,
291                                              LUSTRE_OPC_ANY, NULL);
292                 if (IS_ERR(op_data))
293                         return (void *)op_data;
294
295                 rc = md_enqueue(ll_i2sbi(dir)->ll_md_exp, &einfo, &it,
296                                 op_data, &lockh, NULL, 0, NULL, 0);
297
298                 ll_finish_md_op_data(op_data);
299
300                 request = (struct ptlrpc_request *)it.d.lustre.it_data;
301                 if (request)
302                         ptlrpc_req_finished(request);
303                 if (rc < 0) {
304                         CERROR("lock enqueue: rc: %d\n", rc);
305                         return ERR_PTR(rc);
306                 }
307         } else {
308                 /* for cross-ref object, l_ast_data of the lock may not be set,
309                  * we reset it here */
310                 md_set_lock_data(ll_i2sbi(dir)->ll_md_exp, &lockh.cookie,
311                                  dir, NULL);
312         }
313         ldlm_lock_dump_handle(D_OTHER, &lockh);
314
315         page = ll_dir_page_locate(dir, hash, &start, &end);
316         if (IS_ERR(page))
317                 GOTO(out_unlock, page);
318
319         if (page != NULL) {
320                 /*
321                  * XXX nikita: not entirely correct handling of a corner case:
322                  * suppose hash chain of entries with hash value HASH crosses
323                  * border between pages P0 and P1. First both P0 and P1 are
324                  * cached, seekdir() is called for some entry from the P0 part
325                  * of the chain. Later P0 goes out of cache. telldir(HASH)
326                  * happens and finds P1, as it starts with matching hash
327                  * value. Remaining entries from P0 part of the chain are
328                  * skipped. (Is that really a bug?)
329                  *
330                  * Possible solutions: 0. don't cache P1 is such case, handle
331                  * it as an "overflow" page. 1. invalidate all pages at
332                  * once. 2. use HASH|1 as an index for P1.
333                  */
334                 if (exact && hash != start) {
335                         /*
336                          * readdir asked for a page starting _exactly_ from
337                          * given hash, but cache contains stale page, with
338                          * entries with smaller hash values. Stale page should
339                          * be invalidated, and new one fetched.
340                          */
341                         CWARN("Stale readpage page %p: "LPX64" != "LPX64"\n",
342                               page, hash, start);
343                         ll_release_page(page, hash, start, end);
344                 } else {
345                         GOTO(hash_collision, page);
346                 }
347         }
348
349         page = read_cache_page(mapping, hash_x_index((unsigned long)hash),
350                                (filler_t*)mapping->a_ops->readpage, NULL);
351         if (IS_ERR(page))
352                 GOTO(out_unlock, page);
353
354         wait_on_page(page);
355         (void)kmap(page);
356         if (!PageUptodate(page))
357                 goto fail;
358         if (!PageChecked(page))
359                 ll_check_page(dir, page);
360         if (PageError(page))
361                 goto fail;
362 hash_collision:
363         dp = page_address(page);
364
365         start = le64_to_cpu(dp->ldp_hash_start);
366         end   = le64_to_cpu(dp->ldp_hash_end);
367         if (end == start) {
368                 LASSERT(start == hash);
369                 CWARN("Page-wide hash collision: %#lx\n", (unsigned long)end);
370                 /*
371                  * Fetch whole overflow chain...
372                  *
373                  * XXX not yet.
374                  */
375                 goto fail;
376         }
377 out_unlock:
378         ldlm_lock_decref(&lockh, mode);
379         return page;
380
381 fail:
382         ll_put_page(page);
383         page = ERR_PTR(-EIO);
384         goto out_unlock;
385 }
386
387 int ll_readdir(struct file *filp, void *cookie, filldir_t filldir)
388 {
389         struct inode         *inode = filp->f_dentry->d_inode;
390         struct ll_inode_info *info  = ll_i2info(inode);
391         struct ll_sb_info    *sbi   = ll_i2sbi(inode);
392         __u64                 pos   = filp->f_pos;
393         struct page          *page;
394         struct ll_dir_chain   chain;
395         int rc;
396         int done;
397         int shift;
398         __u16 type;
399         ENTRY;
400
401         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %lu/%llu\n",
402                inode->i_ino, inode->i_generation, inode,
403                (unsigned long)pos, i_size_read(inode));
404
405         if (pos == DIR_END_OFF)
406                 /*
407                  * end-of-file.
408                  */
409                 RETURN(0);
410
411         rc    = 0;
412         done  = 0;
413         shift = 0;
414         ll_dir_chain_init(&chain);
415
416         page = ll_get_dir_page(inode, pos, 0, &chain);
417
418         while (rc == 0 && !done) {
419                 struct lu_dirpage *dp;
420                 struct lu_dirent  *ent;
421
422                 if (!IS_ERR(page)) {
423                         /*
424                          * If page is empty (end of directory is reached),
425                          * use this value.
426                          */
427                         __u64 hash = DIR_END_OFF;
428                         __u64 next;
429
430                         dp = page_address(page);
431                         for (ent = lu_dirent_start(dp); ent != NULL && !done;
432                              ent = lu_dirent_next(ent)) {
433                                 char          *name;
434                                 int            namelen;
435                                 struct lu_fid  fid;
436                                 ino_t          ino;
437
438                                 /*
439                                  * XXX: implement correct swabbing here.
440                                  */
441
442                                 hash    = le64_to_cpu(ent->lde_hash);
443                                 namelen = le16_to_cpu(ent->lde_namelen);
444
445                                 if (hash < pos)
446                                         /*
447                                          * Skip until we find target hash
448                                          * value.
449                                          */
450                                         continue;
451
452                                 if (namelen == 0)
453                                         /*
454                                          * Skip dummy record.
455                                          */
456                                         continue;
457
458                                 fid  = ent->lde_fid;
459                                 name = ent->lde_name;
460                                 fid_le_to_cpu(&fid, &fid);
461                                 ino  = ll_fid_build_ino(sbi, &fid);
462                                 type = ll_dirent_type_get(ent);
463                                 done = filldir(cookie, name, namelen,
464                                                (loff_t)hash, ino, type);
465                         }
466                         next = le64_to_cpu(dp->ldp_hash_end);
467                         ll_put_page(page);
468                         if (!done) {
469                                 pos = next;
470                                 if (pos == DIR_END_OFF)
471                                         /*
472                                          * End of directory reached.
473                                          */
474                                         done = 1;
475                                 else if (1 /* chain is exhausted*/)
476                                         /*
477                                          * Normal case: continue to the next
478                                          * page.
479                                          */
480                                         page = ll_get_dir_page(inode, pos, 1,
481                                                                &chain);
482                                 else {
483                                         /*
484                                          * go into overflow page.
485                                          */
486                                 }
487                         } else
488                                 pos = hash;
489                 } else {
490                         rc = PTR_ERR(page);
491                         CERROR("error reading dir "DFID" at %lu: rc %d\n",
492                                PFID(&info->lli_fid), (unsigned long)pos, rc);
493                 }
494         }
495
496         filp->f_pos = (loff_t)pos;
497         filp->f_version = inode->i_version;
498         touch_atime(filp->f_vfsmnt, filp->f_dentry);
499
500         ll_dir_chain_fini(&chain);
501
502         RETURN(rc);
503 }
504
505 int ll_send_mgc_param(struct obd_export *mgc, char *string)
506 {
507         struct mgs_send_param *msp;
508         int rc = 0;
509
510         OBD_ALLOC_PTR(msp);
511         if (!msp)
512                 return -ENOMEM;
513
514         strncpy(msp->mgs_param, string, MGS_PARAM_MAXLEN);
515         rc = obd_set_info_async(mgc, sizeof(KEY_SET_INFO), KEY_SET_INFO,
516                                 sizeof(struct mgs_send_param), msp, NULL);
517         if (rc)
518                 CERROR("Failed to set parameter: %d\n", rc);
519         OBD_FREE_PTR(msp);
520
521         return rc;
522 }
523
524 char *ll_get_fsname(struct inode *inode)
525 {
526         struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
527         char *ptr, *fsname;
528         int len;
529
530         OBD_ALLOC(fsname, MGS_PARAM_MAXLEN);
531         len = strlen(lsi->lsi_lmd->lmd_profile);
532         ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
533         if (ptr && (strcmp(ptr, "-client") == 0))
534                 len -= 7;
535         strncpy(fsname, lsi->lsi_lmd->lmd_profile, len);
536         fsname[len] = '\0';
537
538         return fsname;
539 }
540
541 int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
542                      int set_default)
543 {
544         struct ll_sb_info *sbi = ll_i2sbi(inode);
545         struct md_op_data *op_data;
546         struct ptlrpc_request *req = NULL;
547         int rc = 0;
548         struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
549         struct obd_device *mgc = lsi->lsi_mgc;
550         char *fsname = NULL, *param = NULL;
551         int lum_size;
552
553         /*
554          * This is coming from userspace, so should be in
555          * local endian.  But the MDS would like it in little
556          * endian, so we swab it before we send it.
557          */
558         switch (lump->lmm_magic) {
559         case LOV_USER_MAGIC_V1: {
560                 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V1))
561                         lustre_swab_lov_user_md_v1(lump);
562                 lum_size = sizeof(struct lov_user_md_v1);
563                 break;
564                 }
565         case LOV_USER_MAGIC_V3: {
566                 if (lump->lmm_magic != cpu_to_le32(LOV_USER_MAGIC_V3))
567                         lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lump);
568                 lum_size = sizeof(struct lov_user_md_v3);
569                 break;
570                 }
571         default: {
572                 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:"
573                                 " %#08x != %#08x nor %#08x\n",
574                                 lump->lmm_magic, LOV_USER_MAGIC_V1,
575                                 LOV_USER_MAGIC_V3);
576                 RETURN(-EINVAL);
577                 }
578         }
579
580         op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
581                                      LUSTRE_OPC_ANY, NULL);
582         if (IS_ERR(op_data))
583                 RETURN(PTR_ERR(op_data));
584
585         /* swabbing is done in lov_setstripe() on server side */
586         rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size,
587                         NULL, 0, &req, NULL);
588         ll_finish_md_op_data(op_data);
589         ptlrpc_req_finished(req);
590         if (rc) {
591                 if (rc != -EPERM && rc != -EACCES)
592                         CERROR("mdc_setattr fails: rc = %d\n", rc);
593         }
594
595         /* In the following we use the fact that LOV_USER_MAGIC_V1 and
596          LOV_USER_MAGIC_V3 have the same initial fields so we do not
597          need the make the distiction between the 2 versions */
598         if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
599                 OBD_ALLOC(param, MGS_PARAM_MAXLEN);
600
601                 /* Get fsname and assume devname to be -MDT0000. */
602                 fsname = ll_get_fsname(inode);
603                 /* Set root stripesize */
604                 sprintf(param, "%s-MDT0000.lov.stripesize=%u", fsname,
605                         lump->lmm_stripe_size);
606                 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
607                 if (rc)
608                         goto end;
609
610                 /* Set root stripecount */
611                 sprintf(param, "%s-MDT0000.lov.stripecount=%hd", fsname,
612                         lump->lmm_stripe_count);
613                 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
614                 if (rc)
615                         goto end;
616
617                 /* Set root stripeoffset */
618                 sprintf(param, "%s-MDT0000.lov.stripeoffset=%hd", fsname,
619                         lump->lmm_stripe_offset);
620                 rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
621                 if (rc)
622                         goto end;
623 end:
624                 if (fsname)
625                         OBD_FREE(fsname, MGS_PARAM_MAXLEN);
626                 if (param)
627                         OBD_FREE(param, MGS_PARAM_MAXLEN);
628         }
629         return rc;
630 }
631
632 int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
633                      int *lmm_size, struct ptlrpc_request **request)
634 {
635         struct ll_sb_info *sbi = ll_i2sbi(inode);
636         struct mdt_body   *body;
637         struct lov_mds_md *lmm = NULL;
638         struct ptlrpc_request *req = NULL;
639         int rc, lmmsize;
640         struct obd_capa *oc;
641
642         rc = ll_get_max_mdsize(sbi, &lmmsize);
643         if (rc)
644                 RETURN(rc);
645
646         oc = ll_mdscapa_get(inode);
647         rc = md_getattr(sbi->ll_md_exp, ll_inode2fid(inode),
648                         oc, OBD_MD_FLEASIZE | OBD_MD_FLDIREA,
649                         lmmsize, &req);
650         capa_put(oc);
651         if (rc < 0) {
652                 CDEBUG(D_INFO, "md_getattr failed on inode "
653                        "%lu/%u: rc %d\n", inode->i_ino,
654                        inode->i_generation, rc);
655                 GOTO(out, rc);
656         }
657
658         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
659         LASSERT(body != NULL);
660
661         lmmsize = body->eadatasize;
662
663         if (!(body->valid & (OBD_MD_FLEASIZE | OBD_MD_FLDIREA)) ||
664             lmmsize == 0) {
665                 GOTO(out, rc = -ENODATA);
666         }
667
668         lmm = req_capsule_server_sized_get(&req->rq_pill,
669                                            &RMF_MDT_MD, lmmsize);
670         LASSERT(lmm != NULL);
671
672         /*
673          * This is coming from the MDS, so is probably in
674          * little endian.  We convert it to host endian before
675          * passing it to userspace.
676          */
677         /* We don't swab objects for directories */
678         switch (le32_to_cpu(lmm->lmm_magic)) {
679         case LOV_MAGIC_V1:
680                 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
681                         lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
682                 break;
683         case LOV_MAGIC_V3:
684                 if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
685                         lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
686                 break;
687         default:
688                 CERROR("unknown magic: %lX\n", (unsigned long)lmm->lmm_magic);
689                 rc = -EPROTO;
690         }
691 out:
692         *lmmp = lmm;
693         *lmm_size = lmmsize;
694         *request = req;
695         return rc;
696 }
697
698 static int ll_dir_ioctl(struct inode *inode, struct file *file,
699                         unsigned int cmd, unsigned long arg)
700 {
701         struct ll_sb_info *sbi = ll_i2sbi(inode);
702         struct obd_ioctl_data *data;
703         ENTRY;
704
705         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), cmd=%#x\n",
706                inode->i_ino, inode->i_generation, inode, cmd);
707
708         /* asm-ppc{,64} declares TCGETS, et. al. as type 't' not 'T' */
709         if (_IOC_TYPE(cmd) == 'T' || _IOC_TYPE(cmd) == 't') /* tty ioctls */
710                 return -ENOTTY;
711
712         ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_IOCTL, 1);
713         switch(cmd) {
714         case EXT3_IOC_GETFLAGS:
715         case EXT3_IOC_SETFLAGS:
716                 RETURN(ll_iocontrol(inode, file, cmd, arg));
717         case EXT3_IOC_GETVERSION_OLD:
718         case EXT3_IOC_GETVERSION:
719                 RETURN(put_user(inode->i_generation, (int *)arg));
720         /* We need to special case any other ioctls we want to handle,
721          * to send them to the MDS/OST as appropriate and to properly
722          * network encode the arg field.
723         case EXT3_IOC_SETVERSION_OLD:
724         case EXT3_IOC_SETVERSION:
725         */
726         case IOC_MDC_LOOKUP: {
727                 struct ptlrpc_request *request = NULL;
728                 int namelen, rc, len = 0;
729                 char *buf = NULL;
730                 char *filename;
731                 struct obd_capa *oc;
732
733                 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
734                 if (rc)
735                         RETURN(rc);
736                 data = (void *)buf;
737
738                 filename = data->ioc_inlbuf1;
739                 namelen = data->ioc_inllen1;
740
741                 if (namelen < 1) {
742                         CDEBUG(D_INFO, "IOC_MDC_LOOKUP missing filename\n");
743                         GOTO(out, rc = -EINVAL);
744                 }
745
746                 oc = ll_mdscapa_get(inode);
747                 rc = md_getattr_name(sbi->ll_md_exp, ll_inode2fid(inode), oc,
748                                      filename, namelen, OBD_MD_FLID, 0,
749                                      ll_i2suppgid(inode), &request);
750                 capa_put(oc);
751                 if (rc < 0) {
752                         CDEBUG(D_INFO, "md_getattr_name: %d\n", rc);
753                         GOTO(out, rc);
754                 }
755
756                 ptlrpc_req_finished(request);
757
758                 EXIT;
759         out:
760                 obd_ioctl_freedata(buf, len);
761                 return rc;
762         }
763         case LL_IOC_LOV_SETSTRIPE: {
764                 struct lov_user_md_v3 lumv3;
765                 struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
766                 struct lov_user_md_v1 *lumv1p = (struct lov_user_md_v1 *)arg;
767                 struct lov_user_md_v3 *lumv3p = (struct lov_user_md_v3 *)arg;
768
769                 int rc = 0;
770                 int set_default = 0;
771
772                 LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
773                 LASSERT(sizeof(lumv3.lmm_objects[0]) ==
774                         sizeof(lumv3p->lmm_objects[0]));
775                 /* first try with v1 which is smaller than v3 */
776                 if (copy_from_user(lumv1, lumv1p, sizeof(*lumv1)))
777                         RETURN(-EFAULT);
778
779                 if (lumv1->lmm_magic == LOV_USER_MAGIC_V3) {
780                         if (copy_from_user(&lumv3, lumv3p, sizeof(lumv3)))
781                                 RETURN(-EFAULT);
782                 }
783
784                 if (inode->i_sb->s_root == file->f_dentry)
785                         set_default = 1;
786
787                 /* in v1 and v3 cases lumv1 points to data */
788                 rc = ll_dir_setstripe(inode, lumv1, set_default);
789
790                 RETURN(rc);
791         }
792         case LL_IOC_OBD_STATFS:
793                 RETURN(ll_obd_statfs(inode, (void *)arg));
794         case LL_IOC_LOV_GETSTRIPE:
795         case LL_IOC_MDC_GETINFO:
796         case IOC_MDC_GETFILEINFO:
797         case IOC_MDC_GETFILESTRIPE: {
798                 struct ptlrpc_request *request = NULL;
799                 struct lov_user_md *lump;
800                 struct lov_mds_md *lmm = NULL;
801                 struct mdt_body *body;
802                 char *filename = NULL;
803                 int rc, lmmsize;
804
805                 if (cmd == IOC_MDC_GETFILEINFO ||
806                     cmd == IOC_MDC_GETFILESTRIPE) {
807                         filename = getname((const char *)arg);
808                         if (IS_ERR(filename))
809                                 RETURN(PTR_ERR(filename));
810
811                         rc = ll_lov_getstripe_ea_info(inode, filename, &lmm,
812                                                       &lmmsize, &request);
813                 } else {
814                         rc = ll_dir_getstripe(inode, &lmm, &lmmsize, &request);
815                 }
816
817                 if (request) {
818                         body = req_capsule_server_get(&request->rq_pill,
819                                                       &RMF_MDT_BODY);
820                         LASSERT(body != NULL);
821                 } else {
822                         GOTO(out_req, rc);
823                 }
824
825                 if (rc < 0) {
826                         if (rc == -ENODATA && (cmd == IOC_MDC_GETFILEINFO ||
827                                                cmd == LL_IOC_MDC_GETINFO))
828                                 GOTO(skip_lmm, rc = 0);
829                         else
830                                 GOTO(out_req, rc);
831                 }
832
833                 if (cmd == IOC_MDC_GETFILESTRIPE ||
834                     cmd == LL_IOC_LOV_GETSTRIPE) {
835                         lump = (struct lov_user_md *)arg;
836                 } else {
837                         struct lov_user_mds_data *lmdp;
838                         lmdp = (struct lov_user_mds_data *)arg;
839                         lump = &lmdp->lmd_lmm;
840                 }
841                 if (copy_to_user(lump, lmm, lmmsize))
842                         GOTO(out_lmm, rc = -EFAULT);
843         skip_lmm:
844                 if (cmd == IOC_MDC_GETFILEINFO || cmd == LL_IOC_MDC_GETINFO) {
845                         struct lov_user_mds_data *lmdp;
846                         lstat_t st = { 0 };
847
848                         st.st_dev     = inode->i_sb->s_dev;
849                         st.st_mode    = body->mode;
850                         st.st_nlink   = body->nlink;
851                         st.st_uid     = body->uid;
852                         st.st_gid     = body->gid;
853                         st.st_rdev    = body->rdev;
854                         st.st_size    = body->size;
855                         st.st_blksize = CFS_PAGE_SIZE;
856                         st.st_blocks  = body->blocks;
857                         st.st_atime   = body->atime;
858                         st.st_mtime   = body->mtime;
859                         st.st_ctime   = body->ctime;
860                         st.st_ino     = inode->i_ino;
861
862                         lmdp = (struct lov_user_mds_data *)arg;
863                         if (copy_to_user(&lmdp->lmd_st, &st, sizeof(st)))
864                                 GOTO(out_lmm, rc = -EFAULT);
865                 }
866
867                 EXIT;
868         out_lmm:
869                 if (lmm && lmm->lmm_magic == LOV_MAGIC_JOIN)
870                         OBD_FREE(lmm, lmmsize);
871         out_req:
872                 ptlrpc_req_finished(request);
873                 if (filename)
874                         putname(filename);
875                 return rc;
876         }
877         case IOC_LOV_GETINFO: {
878                 struct lov_user_mds_data *lumd;
879                 struct lov_stripe_md *lsm;
880                 struct lov_user_md *lum;
881                 struct lov_mds_md *lmm;
882                 int lmmsize;
883                 lstat_t st;
884                 int rc;
885
886                 lumd = (struct lov_user_mds_data *)arg;
887                 lum = &lumd->lmd_lmm;
888
889                 rc = ll_get_max_mdsize(sbi, &lmmsize);
890                 if (rc)
891                         RETURN(rc);
892
893                 OBD_ALLOC(lmm, lmmsize);
894                 if (copy_from_user(lmm, lum, lmmsize))
895                         GOTO(free_lmm, rc = -EFAULT);
896
897                 switch (lmm->lmm_magic) {
898                 case LOV_USER_MAGIC_V1:
899                         if (LOV_USER_MAGIC_V1 == cpu_to_le32(LOV_USER_MAGIC_V1))
900                                 break;
901                         /* swab objects first so that stripes num will be sane */
902                         lustre_swab_lov_user_md_objects(
903                                 ((struct lov_user_md_v1 *)lmm)->lmm_objects,
904                                 ((struct lov_user_md_v1 *)lmm)->lmm_stripe_count);
905                         lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
906                         break;
907                 case LOV_USER_MAGIC_V3:
908                         if (LOV_USER_MAGIC_V3 == cpu_to_le32(LOV_USER_MAGIC_V3))
909                                 break;
910                         /* swab objects first so that stripes num will be sane */
911                         lustre_swab_lov_user_md_objects(
912                                 ((struct lov_user_md_v3 *)lmm)->lmm_objects,
913                                 ((struct lov_user_md_v3 *)lmm)->lmm_stripe_count);
914                         lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
915                         break;
916                 default:
917                         GOTO(free_lmm, rc = -EINVAL);
918                 }
919
920                 rc = obd_unpackmd(sbi->ll_dt_exp, &lsm, lmm, lmmsize);
921                 if (rc < 0)
922                         GOTO(free_lmm, rc = -ENOMEM);
923
924                 rc = obd_checkmd(sbi->ll_dt_exp, sbi->ll_md_exp, lsm);
925                 if (rc)
926                         GOTO(free_lsm, rc);
927
928                 /* Perform glimpse_size operation. */
929                 memset(&st, 0, sizeof(st));
930
931                 rc = ll_glimpse_ioctl(sbi, lsm, &st);
932                 if (rc)
933                         GOTO(free_lsm, rc);
934
935                 if (copy_to_user(&lumd->lmd_st, &st, sizeof(st)))
936                         GOTO(free_lsm, rc = -EFAULT);
937
938                 EXIT;
939         free_lsm:
940                 obd_free_memmd(sbi->ll_dt_exp, &lsm);
941         free_lmm:
942                 OBD_FREE(lmm, lmmsize);
943                 return rc;
944         }
945         case OBD_IOC_LLOG_CATINFO: {
946                 struct ptlrpc_request *req = NULL;
947                 char                  *buf = NULL;
948                 char                  *str;
949                 int                    len = 0;
950                 int                    rc;
951
952                 rc = obd_ioctl_getdata(&buf, &len, (void *)arg);
953                 if (rc)
954                         RETURN(rc);
955                 data = (void *)buf;
956
957                 if (!data->ioc_inlbuf1) {
958                         obd_ioctl_freedata(buf, len);
959                         RETURN(-EINVAL);
960                 }
961
962                 req = ptlrpc_request_alloc(sbi2mdc(sbi)->cl_import,
963                                            &RQF_LLOG_CATINFO);
964                 if (req == NULL)
965                         GOTO(out_catinfo, rc = -ENOMEM);
966
967                 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
968                                      data->ioc_inllen1);
969                 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_CLIENT,
970                                      data->ioc_inllen2);
971
972                 rc = ptlrpc_request_pack(req, LUSTRE_LOG_VERSION, LLOG_CATINFO);
973                 if (rc) {
974                         ptlrpc_request_free(req);
975                         GOTO(out_catinfo, rc);
976                 }
977
978                 str = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
979                 memcpy(str, data->ioc_inlbuf1, data->ioc_inllen1);
980                 if (data->ioc_inllen2) {
981                         str = req_capsule_client_get(&req->rq_pill,
982                                                      &RMF_STRING);
983                         memcpy(str, data->ioc_inlbuf2, data->ioc_inllen2);
984                 }
985
986                 req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_SERVER,
987                                      data->ioc_plen1);
988                 ptlrpc_request_set_replen(req);
989
990                 rc = ptlrpc_queue_wait(req);
991                 if (!rc) {
992                         str = req_capsule_server_get(&req->rq_pill,
993                                                      &RMF_STRING);
994                         if (copy_to_user(data->ioc_pbuf1, str, data->ioc_plen1))
995                                 rc = -EFAULT;
996                 }
997                 ptlrpc_req_finished(req);
998         out_catinfo:
999                 obd_ioctl_freedata(buf, len);
1000                 RETURN(rc);
1001         }
1002         case OBD_IOC_QUOTACHECK: {
1003                 struct obd_quotactl *oqctl;
1004                 int rc, error = 0;
1005
1006                 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1007                     sbi->ll_flags & LL_SBI_RMT_CLIENT)
1008                         RETURN(-EPERM);
1009
1010                 OBD_ALLOC_PTR(oqctl);
1011                 if (!oqctl)
1012                         RETURN(-ENOMEM);
1013                 oqctl->qc_type = arg;
1014                 rc = obd_quotacheck(sbi->ll_md_exp, oqctl);
1015                 if (rc < 0) {
1016                         CDEBUG(D_INFO, "md_quotacheck failed: rc %d\n", rc);
1017                         error = rc;
1018                 }
1019
1020                 rc = obd_quotacheck(sbi->ll_dt_exp, oqctl);
1021                 if (rc < 0)
1022                         CDEBUG(D_INFO, "obd_quotacheck failed: rc %d\n", rc);
1023
1024                 OBD_FREE_PTR(oqctl);
1025                 return error ?: rc;
1026         }
1027         case OBD_IOC_POLL_QUOTACHECK: {
1028                 struct if_quotacheck *check;
1029                 int rc;
1030
1031                 if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1032                     sbi->ll_flags & LL_SBI_RMT_CLIENT)
1033                         RETURN(-EPERM);
1034
1035                 OBD_ALLOC_PTR(check);
1036                 if (!check)
1037                         RETURN(-ENOMEM);
1038
1039                 rc = obd_iocontrol(cmd, sbi->ll_md_exp, 0, (void *)check,
1040                                    NULL);
1041                 if (rc) {
1042                         CDEBUG(D_QUOTA, "mdc ioctl %d failed: %d\n", cmd, rc);
1043                         if (copy_to_user((void *)arg, check, sizeof(*check)))
1044                                 rc = -EFAULT;
1045                         GOTO(out_poll, rc);
1046                 }
1047
1048                 rc = obd_iocontrol(cmd, sbi->ll_dt_exp, 0, (void *)check,
1049                                    NULL);
1050                 if (rc) {
1051                         CDEBUG(D_QUOTA, "osc ioctl %d failed: %d\n", cmd, rc);
1052                         if (copy_to_user((void *)arg, check, sizeof(*check)))
1053                                 rc = -EFAULT;
1054                         GOTO(out_poll, rc);
1055                 }
1056         out_poll:
1057                 OBD_FREE_PTR(check);
1058                 RETURN(rc);
1059         }
1060         case OBD_IOC_QUOTACTL: {
1061                 struct if_quotactl *qctl;
1062                 int cmd, type, id, valid, rc = 0;
1063
1064                 OBD_ALLOC_PTR(qctl);
1065                 if (!qctl)
1066                         RETURN(-ENOMEM);
1067
1068                 if (copy_from_user(qctl, (void *)arg, sizeof(*qctl)))
1069                         GOTO(out_quotactl, rc = -EFAULT);
1070
1071                 cmd = qctl->qc_cmd;
1072                 type = qctl->qc_type;
1073                 id = qctl->qc_id;
1074                 valid = qctl->qc_valid;
1075
1076                 switch (cmd) {
1077                 case LUSTRE_Q_INVALIDATE:
1078                 case LUSTRE_Q_FINVALIDATE:
1079                 case Q_QUOTAON:
1080                 case Q_QUOTAOFF:
1081                 case Q_SETQUOTA:
1082                 case Q_SETINFO:
1083                         if (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1084                             sbi->ll_flags & LL_SBI_RMT_CLIENT)
1085                                 GOTO(out_quotactl, rc = -EPERM);
1086                         break;
1087                 case Q_GETQUOTA:
1088                         if (((type == USRQUOTA && current->euid != id) ||
1089                              (type == GRPQUOTA && !in_egroup_p(id))) &&
1090                             (!cfs_capable(CFS_CAP_SYS_ADMIN) ||
1091                              sbi->ll_flags & LL_SBI_RMT_CLIENT))
1092                                 GOTO(out_quotactl, rc = -EPERM);
1093                         break;
1094                 case Q_GETINFO:
1095                         break;
1096                 default:
1097                         CERROR("unsupported quotactl op: %#x\n", cmd);
1098                         GOTO(out_quotactl, rc = -ENOTTY);
1099                 }
1100
1101                 if (valid != QC_GENERAL) {
1102                         if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
1103                                 GOTO(out_quotactl, rc = -EOPNOTSUPP);
1104
1105                         if (cmd == Q_GETINFO)
1106                                 qctl->qc_cmd = Q_GETOINFO;
1107                         else if (cmd == Q_GETQUOTA)
1108                                 qctl->qc_cmd = Q_GETOQUOTA;
1109                         else
1110                                 GOTO(out_quotactl, rc = -EINVAL);
1111
1112                         switch (valid) {
1113                         case QC_MDTIDX:
1114                                 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1115                                                    sbi->ll_md_exp,
1116                                                    sizeof(*qctl), qctl, NULL);
1117                                 break;
1118                         case QC_OSTIDX:
1119                                 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1120                                                    sbi->ll_dt_exp,
1121                                                    sizeof(*qctl), qctl, NULL);
1122                                 break;
1123                         case QC_UUID:
1124                                 rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1125                                                    sbi->ll_md_exp,
1126                                                    sizeof(*qctl), qctl, NULL);
1127                                 if (rc == -EAGAIN)
1128                                         rc = obd_iocontrol(OBD_IOC_QUOTACTL,
1129                                                            sbi->ll_dt_exp,
1130                                                            sizeof(*qctl), qctl,
1131                                                            NULL);
1132                                 break;
1133                         default:
1134                                 rc = -EINVAL;
1135                                 break;
1136                         }
1137
1138                         if (rc)
1139                                 GOTO(out_quotactl, rc);
1140                         else
1141                                 qctl->qc_cmd = cmd;
1142                 } else {
1143                         struct obd_quotactl *oqctl;
1144
1145                         OBD_ALLOC_PTR(oqctl);
1146                         if (!oqctl)
1147                                 GOTO(out_quotactl, rc = -ENOMEM);
1148
1149                         QCTL_COPY(oqctl, qctl);
1150                         rc = obd_quotactl(sbi->ll_md_exp, oqctl);
1151                         if (rc) {
1152                                 if (rc != -EBUSY && cmd == Q_QUOTAON) {
1153                                         oqctl->qc_cmd = Q_QUOTAOFF;
1154                                         obd_quotactl(sbi->ll_md_exp, oqctl);
1155                                 }
1156                                 OBD_FREE_PTR(oqctl);
1157                                 GOTO(out_quotactl, rc);
1158                         } else {
1159                                 QCTL_COPY(qctl, oqctl);
1160                                 OBD_FREE_PTR(oqctl);
1161                         }
1162                 }
1163
1164                 if (copy_to_user((void *)arg, qctl, sizeof(*qctl)))
1165                         rc = -EFAULT;
1166
1167         out_quotactl:
1168                 OBD_FREE_PTR(qctl);
1169                 RETURN(rc);
1170         }
1171         case OBD_IOC_GETNAME: {
1172                 struct obd_device *obd = class_exp2obd(sbi->ll_dt_exp);
1173                 if (!obd)
1174                         RETURN(-EFAULT);
1175                 if (copy_to_user((void *)arg, obd->obd_name,
1176                                 strlen(obd->obd_name) + 1))
1177                         RETURN (-EFAULT);
1178                 RETURN(0);
1179         }
1180         case LL_IOC_FLUSHCTX:
1181                 RETURN(ll_flush_ctx(inode));
1182 #ifdef CONFIG_FS_POSIX_ACL
1183         case LL_IOC_RMTACL: {
1184             if (sbi->ll_flags & LL_SBI_RMT_CLIENT &&
1185                 inode == inode->i_sb->s_root->d_inode) {
1186                 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1187                 int rc;
1188
1189                 LASSERT(fd != NULL);
1190                 rc = rct_add(&sbi->ll_rct, cfs_curproc_pid(), arg);
1191                 if (!rc)
1192                         fd->fd_flags |= LL_FILE_RMTACL;
1193                 RETURN(rc);
1194             } else
1195                 RETURN(0);
1196         }
1197 #endif
1198         case LL_IOC_GETOBDCOUNT: {
1199                 int count;
1200
1201                 if (copy_from_user(&count, (int *)arg, sizeof(int)))
1202                         RETURN(-EFAULT);
1203
1204                 if (!count) {
1205                         /* get ost count */
1206                         struct lov_obd *lov = &sbi->ll_dt_exp->exp_obd->u.lov;
1207                         count = lov->desc.ld_tgt_count;
1208                 } else {
1209                         /* get mdt count */
1210                         struct lmv_obd *lmv = &sbi->ll_md_exp->exp_obd->u.lmv;
1211                         count = lmv->desc.ld_tgt_count;
1212                 }
1213
1214                 if (copy_to_user((int *)arg, &count, sizeof(int)))
1215                         RETURN(-EFAULT);
1216
1217                 RETURN(0);
1218         }
1219         case LL_IOC_PATH2FID:
1220                 if (copy_to_user((void *)arg, &ll_i2info(inode)->lli_fid,
1221                                  sizeof(struct lu_fid)))
1222                         RETURN(-EFAULT);
1223                 RETURN(0);
1224         case OBD_IOC_CHANGELOG_CLEAR: {
1225                 struct ioc_changelog_clear *icc;
1226                 int rc;
1227
1228                 OBD_ALLOC_PTR(icc);
1229                 if (icc == NULL)
1230                         RETURN(-ENOMEM);
1231                 if (copy_from_user(icc, (void *)arg, sizeof(*icc)))
1232                         GOTO(icc_free, rc = -EFAULT);
1233
1234                 rc = obd_iocontrol(cmd, sbi->ll_md_exp, sizeof(*icc), icc,NULL);
1235
1236 icc_free:
1237                 OBD_FREE_PTR(icc);
1238                 RETURN(rc);
1239         }
1240         case OBD_IOC_FID2PATH:
1241                 RETURN(ll_fid2path(ll_i2mdexp(inode), (void *)arg));
1242
1243         default:
1244                 RETURN(obd_iocontrol(cmd, sbi->ll_dt_exp,0,NULL,(void *)arg));
1245         }
1246 }
1247
1248 int ll_dir_open(struct inode *inode, struct file *file)
1249 {
1250         ENTRY;
1251         RETURN(ll_file_open(inode, file));
1252 }
1253
1254 int ll_dir_release(struct inode *inode, struct file *file)
1255 {
1256         ENTRY;
1257         RETURN(ll_file_release(inode, file));
1258 }
1259
1260 struct file_operations ll_dir_operations = {
1261         .open     = ll_dir_open,
1262         .release  = ll_dir_release,
1263         .read     = generic_read_dir,
1264         .readdir  = ll_readdir,
1265         .ioctl    = ll_dir_ioctl
1266 };